kernel: refresh patches
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-3.14 / 0029-dwc_otg-fiq_fsm-Base-commit-for-driver-rewrite.patch
1 From 07cbbba78cad9e0883daa2210a9b83ab803e28ab Mon Sep 17 00:00:00 2001
2 From: P33M <P33M@github.com>
3 Date: Wed, 19 Mar 2014 12:58:23 +0000
4 Subject: [PATCH 29/54] dwc_otg: fiq_fsm: Base commit for driver rewrite
5
6 This commit removes the previous FIQ fixes entirely and adds fiq_fsm.
7
8 This rewrite features much more complete support for split transactions
9 and takes into account several OTG hardware bugs. High-speed
10 isochronous transactions are also capable of being performed by fiq_fsm.
11
12 All driver options have been removed and replaced with:
13 - dwc_otg.fiq_enable (bool)
14 - dwc_otg.fiq_fsm_enable (bool)
15 - dwc_otg.fiq_fsm_mask (bitmask)
16 - dwc_otg.nak_holdoff (unsigned int)
17
18 Defaults are specified such that fiq_fsm behaves similarly to the
19 previously implemented FIQ fixes.
20
21 fiq_fsm: Push error recovery into the FIQ when fiq_fsm is used
22
23 If the transfer associated with a QTD failed due to a bus error, the HCD
24 would retry the transfer up to 3 times (implementing the USB2.0
25 three-strikes retry in software).
26
27 Due to the masking mechanism used by fiq_fsm, it is only possible to pass
28 a single interrupt through to the HCD per-transfer.
29
30 In this instance host channels would fall off the radar because the error
31 reset would function, but the subsequent channel halt would be lost.
32
33 Push the error count reset into the FIQ handler.
34
35 fiq_fsm: Implement timeout mechanism
36
37 For full-speed endpoints with a large packet size, interrupt latency
38 runs the risk of the FIQ starting a transaction too late in a full-speed
39 frame. If the device is still transmitting data when EOF2 for the
40 downstream frame occurs, the hub will disable the port. This change is
41 not reflected in the hub status endpoint and the device becomes
42 unresponsive.
43
44 Prevent high-bandwidth transactions from being started too late in a
45 frame. The mechanism is not guaranteed: a combination of bit stuffing
46 and hub latency may still result in a device overrunning.
47
48 fiq_fsm: fix bounce buffer utilisation for Isochronous OUT
49
50 Multi-packet isochronous OUT transactions were subject to a few bounday
51 bugs. Fix them.
52
53 Audio playback is now much more robust: however, an issue stands with
54 devices that have adaptive sinks - ALSA plays samples too fast.
55
56 dwc_otg: Return full-speed frame numbers in HS mode
57
58 The frame counter increments on every *microframe* in high-speed mode.
59 Most device drivers expect this number to be in full-speed frames - this
60 caused considerable confusion to e.g. snd_usb_audio which uses the
61 frame counter to estimate the number of samples played.
62
63 fiq_fsm: save PID on completion of interrupt OUT transfers
64
65 Also add edge case handling for interrupt transports.
66
67 Note that for periodic split IN, data toggles are unimplemented in the
68 OTG host hardware - it unconditionally accepts any PID.
69
70 fiq_fsm: add missing case for fiq_fsm_tt_in_use()
71
72 Certain combinations of bitrate and endpoint activity could
73 result in a periodic transaction erroneously getting started
74 while the previous Isochronous OUT was still active.
75
76 fiq_fsm: clear hcintmsk for aborted transactions
77
78 Prevents the FIQ from erroneously handling interrupts
79 on a timed out channel.
80
81 fiq_fsm: enable by default
82
83 fiq_fsm: fix dequeues for non-periodic split transactions
84
85 If a dequeue happened between the SSPLIT and CSPLIT phases of the
86 transaction, the HCD would never receive an interrupt.
87
88 fiq_fsm: Disable by default
89
90 fiq_fsm: Handle HC babble errors
91
92 The HCTSIZ transfer size field raises a babble interrupt if
93 the counter wraps. Handle the resulting interrupt in this case.
94
95 dwc_otg: fix interrupt registration for fiq_enable=0
96
97 Additionally make the module parameter conditional for wherever
98 hcd->fiq_state is touched.
99
100 fiq_fsm: Enable by default
101 ---
102 arch/arm/mach-bcm2708/bcm2708.c | 24 +-
103 drivers/usb/host/dwc_otg/Makefile | 3 +-
104 drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c | 47 +-
105 drivers/usb/host/dwc_otg/dwc_otg_driver.c | 51 +-
106 drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c | 1290 ++++++++++++++++++++++++++
107 drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h | 353 +++++++
108 drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S | 81 ++
109 drivers/usb/host/dwc_otg/dwc_otg_hcd.c | 775 +++++++++++++---
110 drivers/usb/host/dwc_otg/dwc_otg_hcd.h | 11 +
111 drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c | 999 ++++++++++----------
112 drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c | 113 ++-
113 drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c | 41 +-
114 drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c | 113 ---
115 drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h | 48 -
116 drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c | 8 +-
117 15 files changed, 2992 insertions(+), 965 deletions(-)
118 create mode 100644 drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
119 create mode 100644 drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
120 create mode 100644 drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S
121 delete mode 100755 drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c
122 delete mode 100755 drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h
123
124 --- a/arch/arm/mach-bcm2708/bcm2708.c
125 +++ b/arch/arm/mach-bcm2708/bcm2708.c
126 @@ -330,22 +330,13 @@ static struct resource bcm2708_usb_resou
127 .end = IRQ_HOSTPORT,
128 .flags = IORESOURCE_IRQ,
129 },
130 + [3] = {
131 + .start = IRQ_USB,
132 + .end = IRQ_USB,
133 + .flags = IORESOURCE_IRQ,
134 + },
135 };
136
137 -bool fiq_fix_enable = true;
138 -
139 -static struct resource bcm2708_usb_resources_no_fiq_fix[] = {
140 - [0] = {
141 - .start = USB_BASE,
142 - .end = USB_BASE + SZ_128K - 1,
143 - .flags = IORESOURCE_MEM,
144 - },
145 - [1] = {
146 - .start = IRQ_USB,
147 - .end = IRQ_USB,
148 - .flags = IORESOURCE_IRQ,
149 - },
150 -};
151
152 static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
153
154 @@ -729,11 +720,6 @@ void __init bcm2708_init(void)
155 #endif
156 bcm_register_device(&bcm2708_systemtimer_device);
157 bcm_register_device(&bcm2708_fb_device);
158 - if (!fiq_fix_enable)
159 - {
160 - bcm2708_usb_device.resource = bcm2708_usb_resources_no_fiq_fix;
161 - bcm2708_usb_device.num_resources = ARRAY_SIZE(bcm2708_usb_resources_no_fiq_fix);
162 - }
163 bcm_register_device(&bcm2708_usb_device);
164 bcm_register_device(&bcm2708_uart1_device);
165 bcm_register_device(&bcm2708_powerman_device);
166 --- a/drivers/usb/host/dwc_otg/Makefile
167 +++ b/drivers/usb/host/dwc_otg/Makefile
168 @@ -36,7 +36,8 @@ dwc_otg-objs += dwc_otg_cil.o dwc_otg_ci
169 dwc_otg-objs += dwc_otg_pcd_linux.o dwc_otg_pcd.o dwc_otg_pcd_intr.o
170 dwc_otg-objs += dwc_otg_hcd.o dwc_otg_hcd_linux.o dwc_otg_hcd_intr.o dwc_otg_hcd_queue.o dwc_otg_hcd_ddma.o
171 dwc_otg-objs += dwc_otg_adp.o
172 -dwc_otg-objs += dwc_otg_mphi_fix.o
173 +dwc_otg-objs += dwc_otg_fiq_fsm.o
174 +dwc_otg-objs += dwc_otg_fiq_stub.o
175 ifneq ($(CFI),)
176 dwc_otg-objs += dwc_otg_cfi.o
177 endif
178 --- a/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
179 +++ b/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
180 @@ -45,7 +45,6 @@
181 #include "dwc_otg_driver.h"
182 #include "dwc_otg_pcd.h"
183 #include "dwc_otg_hcd.h"
184 -#include "dwc_otg_mphi_fix.h"
185
186 #ifdef DEBUG
187 inline const char *op_state_str(dwc_otg_core_if_t * core_if)
188 @@ -1319,7 +1318,7 @@ static int32_t dwc_otg_handle_lpm_intr(d
189 /**
190 * This function returns the Core Interrupt register.
191 */
192 -static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if, gintmsk_data_t *reenable_gintmsk)
193 +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if, gintmsk_data_t *reenable_gintmsk, dwc_otg_hcd_t *hcd)
194 {
195 gahbcfg_data_t gahbcfg = {.d32 = 0 };
196 gintsts_data_t gintsts;
197 @@ -1345,16 +1344,15 @@ static inline uint32_t dwc_otg_read_comm
198 }
199 gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
200 gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
201 - {
202 - unsigned long flags;
203 -
204 - // Re-enable the saved interrupts
205 - local_irq_save(flags);
206 + if(fiq_enable) {
207 local_fiq_disable();
208 - gintmsk.d32 |= gintmsk_common.d32;
209 - gintsts_saved.d32 &= ~gintmsk_common.d32;
210 - reenable_gintmsk->d32 = gintmsk.d32;
211 - local_irq_restore(flags);
212 + /* Pull in the interrupts that the FIQ has masked */
213 + gintmsk.d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
214 + /* for the upstairs function to reenable - have to read it here in case FIQ triggers again */
215 + reenable_gintmsk->d32 |= gintmsk.d32;
216 + reenable_gintmsk->d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
217 + reenable_gintmsk->d32 &= gintmsk_common.d32;
218 + local_fiq_enable();
219 }
220
221 gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
222 @@ -1366,13 +1364,15 @@ static inline uint32_t dwc_otg_read_comm
223 gintsts.d32, gintmsk.d32);
224 }
225 #endif
226 - if (!fiq_fix_enable){
227 + if (!fiq_enable){
228 if (gahbcfg.b.glblintrmsk)
229 return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
230 else
231 return 0;
232 - }
233 - else {
234 + } else {
235 + /* Our IRQ kicker is no longer the USB hardware, it's the MPHI interface.
236 + * Can't trust the global interrupt mask bit in this case.
237 + */
238 return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
239 }
240
241 @@ -1406,7 +1406,7 @@ int32_t dwc_otg_handle_common_intr(void
242 {
243 int retval = 0;
244 gintsts_data_t gintsts;
245 - gintmsk_data_t reenable_gintmsk;
246 + gintmsk_data_t gintmsk_reenable = { .d32 = 0 };
247 gpwrdn_data_t gpwrdn = {.d32 = 0 };
248 dwc_otg_device_t *otg_dev = dev;
249 dwc_otg_core_if_t *core_if = otg_dev->core_if;
250 @@ -1428,7 +1428,10 @@ int32_t dwc_otg_handle_common_intr(void
251 }
252
253 if (core_if->hibernation_suspend <= 0) {
254 - gintsts.d32 = dwc_otg_read_common_intr(core_if, &reenable_gintmsk);
255 + /* read_common will have to poke the FIQ's saved mask. We must then clear this mask at the end
256 + * of this handler - god only knows why it's done like this
257 + */
258 + gintsts.d32 = dwc_otg_read_common_intr(core_if, &gintmsk_reenable, otg_dev->hcd);
259
260 if (gintsts.b.modemismatch) {
261 retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
262 @@ -1525,11 +1528,16 @@ int32_t dwc_otg_handle_common_intr(void
263 gintsts.b.portintr = 1;
264 DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
265 retval |= 1;
266 - reenable_gintmsk.b.portintr = 1;
267 + gintmsk_reenable.b.portintr = 1;
268
269 }
270 -
271 - DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, reenable_gintmsk.d32);
272 + /* Did we actually handle anything? if so, unmask the interrupt */
273 +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "CILOUT %1d", retval);
274 +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintsts.d32);
275 +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintmsk_reenable.d32);
276 + if (retval) {
277 + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_reenable.d32);
278 + }
279
280 } else {
281 DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
282 @@ -1583,6 +1591,5 @@ int32_t dwc_otg_handle_common_intr(void
283 }
284 if (core_if->lock)
285 DWC_SPINUNLOCK(core_if->lock);
286 -
287 return retval;
288 }
289 --- a/drivers/usb/host/dwc_otg/dwc_otg_driver.c
290 +++ b/drivers/usb/host/dwc_otg/dwc_otg_driver.c
291 @@ -56,6 +56,7 @@
292 #include "dwc_otg_core_if.h"
293 #include "dwc_otg_pcd_if.h"
294 #include "dwc_otg_hcd_if.h"
295 +#include "dwc_otg_fiq_fsm.h"
296
297 #define DWC_DRIVER_VERSION "3.00a 10-AUG-2012"
298 #define DWC_DRIVER_DESC "HS OTG USB Controller driver"
299 @@ -64,7 +65,6 @@ bool microframe_schedule=true;
300
301 static const char dwc_driver_name[] = "dwc_otg";
302
303 -extern void* dummy_send;
304
305 extern int pcd_init(
306 #ifdef LM_INTERFACE
307 @@ -240,13 +240,14 @@ static struct dwc_otg_driver_module_para
308 .adp_enable = -1,
309 };
310
311 -//Global variable to switch the fiq fix on or off (declared in bcm2708.c)
312 -extern bool fiq_fix_enable;
313 +//Global variable to switch the fiq fix on or off
314 +bool fiq_enable = 1;
315 // Global variable to enable the split transaction fix
316 -bool fiq_split_enable = true;
317 -//Global variable to switch the nak holdoff on or off
318 -bool nak_holdoff_enable = true;
319 +bool fiq_fsm_enable = true;
320 +//Bulk split-transaction NAK holdoff in microframes
321 +uint16_t nak_holdoff = 8;
322
323 +unsigned short fiq_fsm_mask = 0x07;
324
325 /**
326 * This function shows the Driver Version.
327 @@ -800,7 +801,7 @@ static int dwc_otg_driver_probe(
328 dwc_otg_device->os_dep.base = ioremap_nocache(_dev->resource[0].start,
329 _dev->resource[0].end -
330 _dev->resource[0].start+1);
331 - if (fiq_fix_enable)
332 + if (fiq_enable)
333 {
334 if (!request_mem_region(_dev->resource[1].start,
335 _dev->resource[1].end - _dev->resource[1].start + 1,
336 @@ -813,7 +814,6 @@ static int dwc_otg_driver_probe(
337 dwc_otg_device->os_dep.mphi_base = ioremap_nocache(_dev->resource[1].start,
338 _dev->resource[1].end -
339 _dev->resource[1].start + 1);
340 - dummy_send = (void *) kmalloc(16, GFP_ATOMIC);
341 }
342
343 #else
344 @@ -902,9 +902,9 @@ static int dwc_otg_driver_probe(
345 */
346
347 #if defined(PLATFORM_INTERFACE)
348 - devirq = platform_get_irq(_dev, 0);
349 + devirq = platform_get_irq(_dev, fiq_enable ? 0 : 1);
350 #else
351 - devirq = _dev->irq;
352 + devirq = _dev->irq;
353 #endif
354 DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
355 devirq);
356 @@ -1071,9 +1071,9 @@ static int __init dwc_otg_driver_init(vo
357 int error;
358 struct device_driver *drv;
359
360 - if(fiq_split_enable && !fiq_fix_enable) {
361 - printk(KERN_WARNING "dwc_otg: fiq_split_enable was set without fiq_fix_enable! Correcting.\n");
362 - fiq_fix_enable = 1;
363 + if(fiq_fsm_enable && !fiq_enable) {
364 + printk(KERN_WARNING "dwc_otg: fiq_fsm_enable was set without fiq_enable! Correcting.\n");
365 + fiq_enable = 1;
366 }
367
368 printk(KERN_INFO "%s: version %s (%s bus)\n", dwc_driver_name,
369 @@ -1095,9 +1095,9 @@ static int __init dwc_otg_driver_init(vo
370 printk(KERN_ERR "%s retval=%d\n", __func__, retval);
371 return retval;
372 }
373 - printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_fix_enable ? "enabled":"disabled");
374 - printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff_enable ? "enabled":"disabled");
375 - printk(KERN_DEBUG "dwc_otg: FIQ split fix %s\n", fiq_split_enable ? "enabled":"disabled");
376 + printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_enable ? "enabled":"disabled");
377 + printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff ? "enabled":"disabled");
378 + printk(KERN_DEBUG "dwc_otg: FIQ split-transaction FSM %s\n", fiq_fsm_enable ? "enabled":"disabled");
379
380 error = driver_create_file(drv, &driver_attr_version);
381 #ifdef DEBUG
382 @@ -1378,12 +1378,19 @@ MODULE_PARM_DESC(otg_ver, "OTG revision
383 module_param(microframe_schedule, bool, 0444);
384 MODULE_PARM_DESC(microframe_schedule, "Enable the microframe scheduler");
385
386 -module_param(fiq_fix_enable, bool, 0444);
387 -MODULE_PARM_DESC(fiq_fix_enable, "Enable the fiq fix");
388 -module_param(nak_holdoff_enable, bool, 0444);
389 -MODULE_PARM_DESC(nak_holdoff_enable, "Enable the NAK holdoff");
390 -module_param(fiq_split_enable, bool, 0444);
391 -MODULE_PARM_DESC(fiq_split_enable, "Enable the FIQ fix on split transactions");
392 +module_param(fiq_enable, bool, 0444);
393 +MODULE_PARM_DESC(fiq_enable, "Enable the FIQ");
394 +module_param(nak_holdoff, ushort, 0644);
395 +MODULE_PARM_DESC(nak_holdoff, "Throttle duration for bulk split-transaction endpoints on a NAK. Default 8");
396 +module_param(fiq_fsm_enable, bool, 0444);
397 +MODULE_PARM_DESC(fiq_fsm_enable, "Enable the FIQ to perform split transactions as defined by fiq_fsm_mask");
398 +module_param(fiq_fsm_mask, ushort, 0444);
399 +MODULE_PARM_DESC(fiq_fsm_mask, "Bitmask of transactions to perform in the FIQ.\n"
400 + "Bit 0 : Non-periodic split transactions\n"
401 + "Bit 1 : Periodic split transactions\n"
402 + "Bit 2 : High-speed multi-transfer isochronous\n"
403 + "All other bits should be set 0.");
404 +
405
406 /** @page "Module Parameters"
407 *
408 --- /dev/null
409 +++ b/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
410 @@ -0,0 +1,1290 @@
411 +/*
412 + * dwc_otg_fiq_fsm.c - The finite state machine FIQ
413 + *
414 + * Copyright (c) 2013 Raspberry Pi Foundation
415 + *
416 + * Author: Jonathan Bell <jonathan@raspberrypi.org>
417 + * All rights reserved.
418 + *
419 + * Redistribution and use in source and binary forms, with or without
420 + * modification, are permitted provided that the following conditions are met:
421 + * * Redistributions of source code must retain the above copyright
422 + * notice, this list of conditions and the following disclaimer.
423 + * * Redistributions in binary form must reproduce the above copyright
424 + * notice, this list of conditions and the following disclaimer in the
425 + * documentation and/or other materials provided with the distribution.
426 + * * Neither the name of Raspberry Pi nor the
427 + * names of its contributors may be used to endorse or promote products
428 + * derived from this software without specific prior written permission.
429 + *
430 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
431 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
432 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
433 + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
434 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
435 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
436 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
437 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
438 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
439 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
440 + *
441 + * This FIQ implements functionality that performs split transactions on
442 + * the dwc_otg hardware without any outside intervention. A split transaction
443 + * is "queued" by nominating a specific host channel to perform the entirety
444 + * of a split transaction. This FIQ will then perform the microframe-precise
445 + * scheduling required in each phase of the transaction until completion.
446 + *
447 + * The FIQ functionality is glued into the Synopsys driver via the entry point
448 + * in the FSM enqueue function, and at the exit point in handling a HC interrupt
449 + * for a FSM-enabled channel.
450 + *
451 + * NB: Large parts of this implementation have architecture-specific code.
452 + * For porting this functionality to other ARM machines, the minimum is required:
453 + * - An interrupt controller allowing the top-level dwc USB interrupt to be routed
454 + * to the FIQ
455 + * - A method of forcing a software generated interrupt from FIQ mode that then
456 + * triggers an IRQ entry (with the dwc USB handler called by this IRQ number)
457 + * - Guaranteed interrupt routing such that both the FIQ and SGI occur on the same
458 + * processor core - there is no locking between the FIQ and IRQ (aside from
459 + * local_fiq_disable)
460 + *
461 + */
462 +
463 +#include "dwc_otg_fiq_fsm.h"
464 +
465 +
466 +char buffer[1000*16];
467 +int wptr;
468 +void notrace _fiq_print(enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...)
469 +{
470 + enum fiq_debug_level dbg_lvl_req = FIQDBG_ERR;
471 + va_list args;
472 + char text[17];
473 + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + 0x408) };
474 +
475 + if((dbg_lvl & dbg_lvl_req) || dbg_lvl == FIQDBG_ERR)
476 + {
477 + snprintf(text, 9, " %4d:%1u ", hfnum.b.frnum/8, hfnum.b.frnum & 7);
478 + va_start(args, fmt);
479 + vsnprintf(text+8, 9, fmt, args);
480 + va_end(args);
481 +
482 + memcpy(buffer + wptr, text, 16);
483 + wptr = (wptr + 16) % sizeof(buffer);
484 + }
485 +}
486 +
487 +/**
488 + * fiq_fsm_restart_channel() - Poke channel enable bit for a split transaction
489 + * @channel: channel to re-enable
490 + */
491 +static void fiq_fsm_restart_channel(struct fiq_state *st, int n, int force)
492 +{
493 + hcchar_data_t hcchar = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR) };
494 +
495 + hcchar.b.chen = 0;
496 + if (st->channel[n].hcchar_copy.b.eptype & 0x1) {
497 + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
498 + /* Hardware bug workaround: update the ssplit index */
499 + if (st->channel[n].hcsplt_copy.b.spltena)
500 + st->channel[n].expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
501 +
502 + hcchar.b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
503 + }
504 +
505 + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
506 + hcchar.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
507 + hcchar.b.chen = 1;
508 +
509 + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
510 + fiq_print(FIQDBG_INT, st, "HCGO %01d %01d", n, force);
511 +}
512 +
513 +/**
514 + * fiq_fsm_setup_csplit() - Prepare a host channel for a CSplit transaction stage
515 + * @st: Pointer to the channel's state
516 + * @n : channel number
517 + *
518 + * Change host channel registers to perform a complete-split transaction. Being mindful of the
519 + * endpoint direction, set control regs up correctly.
520 + */
521 +static void notrace fiq_fsm_setup_csplit(struct fiq_state *st, int n)
522 +{
523 + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT) };
524 + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
525 +
526 + hcsplt.b.compsplt = 1;
527 + if (st->channel[n].hcchar_copy.b.epdir == 1) {
528 + // If IN, the CSPLIT result contains the data or a hub handshake. hctsiz = maxpacket.
529 + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
530 + } else {
531 + // If OUT, the CSPLIT result contains handshake only.
532 + hctsiz.b.xfersize = 0;
533 + }
534 + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
535 + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
536 + mb();
537 +}
538 +
539 +static inline int notrace fiq_get_xfer_len(struct fiq_state *st, int n)
540 +{
541 + /* The xfersize register is a bit wonky. For IN transfers, it decrements by the packet size. */
542 + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
543 +
544 + if (st->channel[n].hcchar_copy.b.epdir == 0) {
545 + return st->channel[n].hctsiz_copy.b.xfersize;
546 + } else {
547 + return st->channel[n].hctsiz_copy.b.xfersize - hctsiz.b.xfersize;
548 + }
549 +
550 +}
551 +
552 +
553 +/**
554 + * fiq_increment_dma_buf() - update DMA address for bounce buffers after a CSPLIT
555 + *
556 + * Of use only for IN periodic transfers.
557 + */
558 +static int notrace fiq_increment_dma_buf(struct fiq_state *st, int num_channels, int n)
559 +{
560 + hcdma_data_t hcdma;
561 + int i = st->channel[n].dma_info.index;
562 + int len;
563 + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
564 +
565 + len = fiq_get_xfer_len(st, n);
566 + fiq_print(FIQDBG_INT, st, "LEN: %03d", len);
567 + st->channel[n].dma_info.slot_len[i] = len;
568 + i++;
569 + if (i > 6)
570 + BUG();
571 +
572 + hcdma.d32 = (dma_addr_t) &blob->channel[n].index[i].buf[0];
573 + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
574 + st->channel[n].dma_info.index = i;
575 + return 0;
576 +}
577 +
578 +/**
579 + * fiq_reload_hctsiz() - for IN transactions, reset HCTSIZ
580 + */
581 +static void notrace fiq_fsm_reload_hctsiz(struct fiq_state *st, int n)
582 +{
583 + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
584 + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
585 + hctsiz.b.pktcnt = 1;
586 + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
587 +}
588 +
589 +/**
590 + * fiq_iso_out_advance() - update DMA address and split position bits
591 + * for isochronous OUT transactions.
592 + *
593 + * Returns 1 if this is the last packet queued, 0 otherwise. Split-ALL and
594 + * Split-BEGIN states are not handled - this is done when the transaction was queued.
595 + *
596 + * This function must only be called from the FIQ_ISO_OUT_ACTIVE state.
597 + */
598 +static int notrace fiq_iso_out_advance(struct fiq_state *st, int num_channels, int n)
599 +{
600 + hcsplt_data_t hcsplt;
601 + hctsiz_data_t hctsiz;
602 + hcdma_data_t hcdma;
603 + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
604 + int last = 0;
605 + int i = st->channel[n].dma_info.index;
606 +
607 + fiq_print(FIQDBG_INT, st, "ADV %01d %01d ", n, i);
608 + i++;
609 + if (i == 4)
610 + last = 1;
611 + if (st->channel[n].dma_info.slot_len[i+1] == 255)
612 + last = 1;
613 +
614 + /* New DMA address - address of bounce buffer referred to in index */
615 + hcdma.d32 = (uint32_t) &blob->channel[n].index[i].buf[0];
616 + //hcdma.d32 = FIQ_READ(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n));
617 + //hcdma.d32 += st->channel[n].dma_info.slot_len[i];
618 + fiq_print(FIQDBG_INT, st, "LAST: %01d ", last);
619 + fiq_print(FIQDBG_INT, st, "LEN: %03d", st->channel[n].dma_info.slot_len[i]);
620 + hcsplt.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT);
621 + hctsiz.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ);
622 + hcsplt.b.xactpos = (last) ? ISOC_XACTPOS_END : ISOC_XACTPOS_MID;
623 + /* Set up new packet length */
624 + hctsiz.b.pktcnt = 1;
625 + hctsiz.b.xfersize = st->channel[n].dma_info.slot_len[i];
626 + fiq_print(FIQDBG_INT, st, "%08x", hctsiz.d32);
627 +
628 + st->channel[n].dma_info.index++;
629 + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
630 + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
631 + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
632 + return last;
633 +}
634 +
635 +/**
636 + * fiq_fsm_tt_next_isoc() - queue next pending isochronous out start-split on a TT
637 + *
638 + * Despite the limitations of the DWC core, we can force a microframe pipeline of
639 + * isochronous OUT start-split transactions while waiting for a corresponding other-type
640 + * of endpoint to finish its CSPLITs. TTs have big periodic buffers therefore it
641 + * is very unlikely that filling the start-split FIFO will cause data loss.
642 + * This allows much better interleaving of transactions in an order-independent way-
643 + * there is no requirement to prioritise isochronous, just a state-space search has
644 + * to be performed on each periodic start-split complete interrupt.
645 + */
646 +static int notrace fiq_fsm_tt_next_isoc(struct fiq_state *st, int num_channels, int n)
647 +{
648 + int hub_addr = st->channel[n].hub_addr;
649 + int port_addr = st->channel[n].port_addr;
650 + int i, poked = 0;
651 + for (i = 0; i < num_channels; i++) {
652 + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
653 + continue;
654 + if (st->channel[i].hub_addr == hub_addr &&
655 + st->channel[i].port_addr == port_addr) {
656 + switch (st->channel[i].fsm) {
657 + case FIQ_PER_ISO_OUT_PENDING:
658 + if (st->channel[i].nrpackets == 1) {
659 + st->channel[i].fsm = FIQ_PER_ISO_OUT_LAST;
660 + } else {
661 + st->channel[i].fsm = FIQ_PER_ISO_OUT_ACTIVE;
662 + }
663 + fiq_fsm_restart_channel(st, i, 0);
664 + poked = 1;
665 + break;
666 +
667 + default:
668 + break;
669 + }
670 + }
671 + if (poked)
672 + break;
673 + }
674 + return poked;
675 +}
676 +
677 +/**
678 + * fiq_fsm_tt_in_use() - search for host channels using this TT
679 + * @n: Channel to use as reference
680 + *
681 + */
682 +int notrace noinline fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n)
683 +{
684 + int hub_addr = st->channel[n].hub_addr;
685 + int port_addr = st->channel[n].port_addr;
686 + int i, in_use = 0;
687 + for (i = 0; i < num_channels; i++) {
688 + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
689 + continue;
690 + switch (st->channel[i].fsm) {
691 + /* TT is reserved for channels that are in the middle of a periodic
692 + * split transaction.
693 + */
694 + case FIQ_PER_SSPLIT_STARTED:
695 + case FIQ_PER_CSPLIT_WAIT:
696 + case FIQ_PER_CSPLIT_NYET1:
697 + //case FIQ_PER_CSPLIT_POLL:
698 + case FIQ_PER_ISO_OUT_ACTIVE:
699 + case FIQ_PER_ISO_OUT_LAST:
700 + if (st->channel[i].hub_addr == hub_addr &&
701 + st->channel[i].port_addr == port_addr) {
702 + in_use = 1;
703 + }
704 + break;
705 + default:
706 + break;
707 + }
708 + if (in_use)
709 + break;
710 + }
711 + return in_use;
712 +}
713 +
714 +/**
715 + * fiq_fsm_more_csplits() - determine whether additional CSPLITs need
716 + * to be issued for this IN transaction.
717 + *
718 + * We cannot tell the inbound PID of a data packet due to hardware limitations.
719 + * we need to make an educated guess as to whether we need to queue another CSPLIT
720 + * or not. A no-brainer is when we have received enough data to fill the endpoint
721 + * size, but for endpoints that give variable-length data then we have to resort
722 + * to heuristics.
723 + *
724 + * We also return whether this is the last CSPLIT to be queued, again based on
725 + * heuristics. This is to allow a 1-uframe overlap of periodic split transactions.
726 + * Note: requires at least 1 CSPLIT to have been performed prior to being called.
727 + */
728 +
729 +/*
730 + * We need some way of guaranteeing if a returned periodic packet of size X
731 + * has a DATA0 PID.
732 + * The heuristic value of 144 bytes assumes that the received data has maximal
733 + * bit-stuffing and the clock frequency of the transmitting device is at the lowest
734 + * permissible limit. If the transfer length results in a final packet size
735 + * 144 < p <= 188, then an erroneous CSPLIT will be issued.
736 + * Also used to ensure that an endpoint will nominally only return a single
737 + * complete-split worth of data.
738 + */
739 +#define DATA0_PID_HEURISTIC 144
740 +
741 +static int notrace noinline fiq_fsm_more_csplits(struct fiq_state *state, int n, int *probably_last)
742 +{
743 +
744 + int i;
745 + int total_len = 0;
746 + int more_needed = 1;
747 + struct fiq_channel_state *st = &state->channel[n];
748 +
749 + for (i = 0; i < st->dma_info.index; i++) {
750 + total_len += st->dma_info.slot_len[i];
751 + }
752 +
753 + *probably_last = 0;
754 +
755 + if (st->hcchar_copy.b.eptype == 0x3) {
756 + /*
757 + * An interrupt endpoint will take max 2 CSPLITs. if we are receiving data
758 + * then this is definitely the last CSPLIT.
759 + */
760 + *probably_last = 1;
761 + } else {
762 + /* Isoc IN. This is a bit risky if we are the first transaction:
763 + * we may have been held off slightly. */
764 + if (i > 1 && st->dma_info.slot_len[st->dma_info.index-1] <= DATA0_PID_HEURISTIC) {
765 + more_needed = 0;
766 + }
767 + /* If in the next uframe we will receive enough data to fill the endpoint,
768 + * then only issue 1 more csplit.
769 + */
770 + if (st->hctsiz_copy.b.xfersize - total_len <= DATA0_PID_HEURISTIC)
771 + *probably_last = 1;
772 + }
773 +
774 + if (total_len >= st->hctsiz_copy.b.xfersize ||
775 + i == 6 || total_len == 0)
776 + /* Note: due to bit stuffing it is possible to have > 6 CSPLITs for
777 + * a single endpoint. Accepting more would completely break our scheduling mechanism though
778 + * - in these extreme cases we will pass through a truncated packet.
779 + */
780 + more_needed = 0;
781 +
782 + return more_needed;
783 +}
784 +
785 +/**
786 + * fiq_fsm_too_late() - Test transaction for lateness
787 + *
788 + * If a SSPLIT for a large IN transaction is issued too late in a frame,
789 + * the hub will disable the port to the device and respond with ERR handshakes.
790 + * The hub status endpoint will not reflect this change.
791 + * Returns 1 if we will issue a SSPLIT that will result in a device babble.
792 + */
793 +int notrace fiq_fsm_too_late(struct fiq_state *st, int n)
794 +{
795 + int uframe;
796 + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
797 + uframe = hfnum.b.frnum & 0x7;
798 + if ((uframe < 6) && (st->channel[n].nrpackets + 1 + uframe > 7)) {
799 + return 1;
800 + } else {
801 + return 0;
802 + }
803 +}
804 +
805 +
806 +/**
807 + * fiq_fsm_start_next_periodic() - A half-arsed attempt at a microframe pipeline
808 + *
809 + * Search pending transactions in the start-split pending state and queue them.
810 + * Don't queue packets in uframe .5 (comes out in .6) (USB2.0 11.18.4).
811 + * Note: we specifically don't do isochronous OUT transactions first because better
812 + * use of the TT's start-split fifo can be achieved by pipelining an IN before an OUT.
813 + */
814 +static void notrace noinline fiq_fsm_start_next_periodic(struct fiq_state *st, int num_channels)
815 +{
816 + int n;
817 + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
818 + if ((hfnum.b.frnum & 0x7) == 5)
819 + return;
820 + for (n = 0; n < num_channels; n++) {
821 + if (st->channel[n].fsm == FIQ_PER_SSPLIT_QUEUED) {
822 + /* Check to see if any other transactions are using this TT */
823 + if(!fiq_fsm_tt_in_use(st, num_channels, n)) {
824 + if (!fiq_fsm_too_late(st, n)) {
825 + st->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
826 + fiq_print(FIQDBG_INT, st, "NEXTPER ");
827 + fiq_fsm_restart_channel(st, n, 0);
828 + } else {
829 + st->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
830 + }
831 + break;
832 + }
833 + }
834 + }
835 + for (n = 0; n < num_channels; n++) {
836 + if (st->channel[n].fsm == FIQ_PER_ISO_OUT_PENDING) {
837 + if (!fiq_fsm_tt_in_use(st, num_channels, n)) {
838 + fiq_print(FIQDBG_INT, st, "NEXTISO ");
839 + st->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
840 + fiq_fsm_restart_channel(st, n, 0);
841 + break;
842 + }
843 + }
844 + }
845 +}
846 +
847 +/**
848 + * fiq_fsm_update_hs_isoc() - update isochronous frame and transfer data
849 + * @state: Pointer to fiq_state
850 + * @n: Channel transaction is active on
851 + * @hcint: Copy of host channel interrupt register
852 + *
853 + * Returns 0 if there are no more transactions for this HC to do, 1
854 + * otherwise.
855 + */
856 +static int notrace noinline fiq_fsm_update_hs_isoc(struct fiq_state *state, int n, hcint_data_t hcint)
857 +{
858 + struct fiq_channel_state *st = &state->channel[n];
859 + int xfer_len = 0, nrpackets = 0;
860 + hcdma_data_t hcdma;
861 + fiq_print(FIQDBG_INT, state, "HSISO %02d", n);
862 +
863 + xfer_len = fiq_get_xfer_len(state, n);
864 + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].actual_length = xfer_len;
865 +
866 + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].status = hcint.d32;
867 +
868 + st->hs_isoc_info.index++;
869 + if (st->hs_isoc_info.index == st->hs_isoc_info.nrframes) {
870 + return 0;
871 + }
872 +
873 + /* grab the next DMA address offset from the array */
874 + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].offset;
875 + FIQ_WRITE(state->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
876 +
877 + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
878 + * the core needs to be told to send the correct number. Caution: for IN transfers,
879 + * this is always set to the maximum size of the endpoint. */
880 + xfer_len = st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].length;
881 + /* Integer divide in a FIQ: fun. FIXME: make this not suck */
882 + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
883 + if (nrpackets == 0)
884 + nrpackets = 1;
885 + st->hcchar_copy.b.multicnt = nrpackets;
886 + st->hctsiz_copy.b.pktcnt = nrpackets;
887 +
888 + /* Initial PID also needs to be set */
889 + if (st->hcchar_copy.b.epdir == 0) {
890 + st->hctsiz_copy.b.xfersize = xfer_len;
891 + switch (st->hcchar_copy.b.multicnt) {
892 + case 1:
893 + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
894 + break;
895 + case 2:
896 + case 3:
897 + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
898 + break;
899 + }
900 +
901 + } else {
902 + switch (st->hcchar_copy.b.multicnt) {
903 + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
904 + case 1:
905 + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
906 + break;
907 + case 2:
908 + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
909 + break;
910 + case 3:
911 + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
912 + break;
913 + }
914 + }
915 + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, st->hctsiz_copy.d32);
916 + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, st->hcchar_copy.d32);
917 + /* Channel is enabled on hcint handler exit */
918 + fiq_print(FIQDBG_INT, state, "HSISOOUT");
919 + return 1;
920 +}
921 +
922 +
923 +/**
924 + * fiq_fsm_do_sof() - FSM start-of-frame interrupt handler
925 + * @state: Pointer to the state struct passed from banked FIQ mode registers.
926 + * @num_channels: set according to the DWC hardware configuration
927 + *
928 + * The SOF handler in FSM mode has two functions
929 + * 1. Hold off SOF from causing schedule advancement in IRQ context if there's
930 + * nothing to do
931 + * 2. Advance certain FSM states that require either a microframe delay, or a microframe
932 + * of holdoff.
933 + *
934 + * The second part is architecture-specific to mach-bcm2835 -
935 + * a sane interrupt controller would have a mask register for ARM interrupt sources
936 + * to be promoted to the nFIQ line, but it doesn't. Instead a single interrupt
937 + * number (USB) can be enabled. This means that certain parts of the USB specification
938 + * that require "wait a little while, then issue another packet" cannot be fulfilled with
939 + * the timing granularity required to achieve optimal throughout. The workaround is to use
940 + * the SOF "timer" (125uS) to perform this task.
941 + */
942 +static int notrace noinline fiq_fsm_do_sof(struct fiq_state *state, int num_channels)
943 +{
944 + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + HFNUM) };
945 + int n;
946 + int kick_irq = 0;
947 +
948 + if ((hfnum.b.frnum & 0x7) == 1) {
949 + /* We cannot issue csplits for transactions in the last frame past (n+1).1
950 + * Check to see if there are any transactions that are stale.
951 + * Boot them out.
952 + */
953 + for (n = 0; n < num_channels; n++) {
954 + switch (state->channel[n].fsm) {
955 + case FIQ_PER_CSPLIT_WAIT:
956 + case FIQ_PER_CSPLIT_NYET1:
957 + case FIQ_PER_CSPLIT_POLL:
958 + case FIQ_PER_CSPLIT_LAST:
959 + /* Check if we are no longer in the same full-speed frame. */
960 + if (((state->channel[n].expected_uframe & 0x3FFF) & ~0x7) <
961 + (hfnum.b.frnum & ~0x7))
962 + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
963 + break;
964 + default:
965 + break;
966 + }
967 + }
968 + }
969 +
970 + for (n = 0; n < num_channels; n++) {
971 + switch (state->channel[n].fsm) {
972 +
973 + case FIQ_NP_SSPLIT_RETRY:
974 + case FIQ_NP_IN_CSPLIT_RETRY:
975 + case FIQ_NP_OUT_CSPLIT_RETRY:
976 + fiq_fsm_restart_channel(state, n, 0);
977 + break;
978 +
979 + case FIQ_HS_ISOC_SLEEPING:
980 + state->channel[n].fsm = FIQ_HS_ISOC_TURBO;
981 + fiq_fsm_restart_channel(state, n, 0);
982 + break;
983 +
984 + case FIQ_PER_SSPLIT_QUEUED:
985 + if ((hfnum.b.frnum & 0x7) == 5)
986 + break;
987 + if(!fiq_fsm_tt_in_use(state, num_channels, n)) {
988 + if (!fiq_fsm_too_late(state, n)) {
989 + fiq_print(FIQDBG_INT, st, "SOF GO %01d", n);
990 + fiq_fsm_restart_channel(state, n, 0);
991 + state->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
992 + } else {
993 + /* Transaction cannot be started without risking a device babble error */
994 + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
995 + state->haintmsk_saved.b2.chint &= ~(1 << n);
996 + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, 0);
997 + kick_irq |= 1;
998 + }
999 + }
1000 + break;
1001 +
1002 + case FIQ_PER_ISO_OUT_PENDING:
1003 + /* Ordinarily, this should be poked after the SSPLIT
1004 + * complete interrupt for a competing transfer on the same
1005 + * TT. Doesn't happen for aborted transactions though.
1006 + */
1007 + if ((hfnum.b.frnum & 0x7) >= 5)
1008 + break;
1009 + if (!fiq_fsm_tt_in_use(state, num_channels, n)) {
1010 + /* Hardware bug. SOF can sometimes occur after the channel halt interrupt
1011 + * that caused this.
1012 + */
1013 + fiq_fsm_restart_channel(state, n, 0);
1014 + fiq_print(FIQDBG_INT, state, "SOF ISOC");
1015 + if (state->channel[n].nrpackets == 1) {
1016 + state->channel[n].fsm = FIQ_PER_ISO_OUT_LAST;
1017 + } else {
1018 + state->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
1019 + }
1020 + }
1021 + break;
1022 +
1023 + case FIQ_PER_CSPLIT_WAIT:
1024 + /* we are guaranteed to be in this state if and only if the SSPLIT interrupt
1025 + * occurred when the bus transaction occurred. The SOF interrupt reversal bug
1026 + * will utterly bugger this up though.
1027 + */
1028 + if (hfnum.b.frnum != state->channel[n].expected_uframe) {
1029 + fiq_print(FIQDBG_INT, state, "SOFCS %d ", n);
1030 + state->channel[n].fsm = FIQ_PER_CSPLIT_POLL;
1031 + fiq_fsm_restart_channel(state, n, 0);
1032 + fiq_fsm_start_next_periodic(state, num_channels);
1033 +
1034 + }
1035 + break;
1036 +
1037 + case FIQ_PER_SPLIT_TIMEOUT:
1038 + case FIQ_DEQUEUE_ISSUED:
1039 + /* Ugly: we have to force a HCD interrupt.
1040 + * Poke the mask for the channel in question.
1041 + * We will take a fake SOF because of this, but
1042 + * that's OK.
1043 + */
1044 + state->haintmsk_saved.b2.chint &= ~(1 << n);
1045 + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, 0);
1046 + kick_irq |= 1;
1047 + break;
1048 +
1049 + default:
1050 + break;
1051 + }
1052 + }
1053 +
1054 + if (state->kick_np_queues ||
1055 + dwc_frame_num_le(state->next_sched_frame, hfnum.b.frnum))
1056 + kick_irq |= 1;
1057 +
1058 + return !kick_irq;
1059 +}
1060 +
1061 +
1062 +/**
1063 + * fiq_fsm_do_hcintr() - FSM host channel interrupt handler
1064 + * @state: Pointer to the FIQ state struct
1065 + * @num_channels: Number of channels as per hardware config
1066 + * @n: channel for which HAINT(i) was raised
1067 + *
1068 + * An important property is that only the CHHLT interrupt is unmasked. Unfortunately, AHBerr is as well.
1069 + */
1070 +static int notrace noinline fiq_fsm_do_hcintr(struct fiq_state *state, int num_channels, int n)
1071 +{
1072 + hcint_data_t hcint;
1073 + hcintmsk_data_t hcintmsk;
1074 + hcint_data_t hcint_probe;
1075 + hcchar_data_t hcchar;
1076 + int handled = 0;
1077 + int restart = 0;
1078 + int last_csplit = 0;
1079 + int start_next_periodic = 0;
1080 + struct fiq_channel_state *st = &state->channel[n];
1081 + hfnum_data_t hfnum;
1082 +
1083 + hcint.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT);
1084 + hcintmsk.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK);
1085 + hcint_probe.d32 = hcint.d32 & hcintmsk.d32;
1086 +
1087 + if (st->fsm != FIQ_PASSTHROUGH) {
1088 + fiq_print(FIQDBG_INT, state, "HC%01d ST%02d", n, st->fsm);
1089 + fiq_print(FIQDBG_INT, state, "%08x", hcint.d32);
1090 + }
1091 +
1092 + switch (st->fsm) {
1093 +
1094 + case FIQ_PASSTHROUGH:
1095 + case FIQ_DEQUEUE_ISSUED:
1096 + /* doesn't belong to us, kick it upstairs */
1097 + break;
1098 +
1099 + case FIQ_PASSTHROUGH_ERRORSTATE:
1100 + /* We are here to emulate the error recovery mechanism of the dwc HCD.
1101 + * Several interrupts are unmasked if a previous transaction failed - it's
1102 + * death for the FIQ to attempt to handle them as the channel isn't halted.
1103 + * Emulate what the HCD does in this situation: mask and continue.
1104 + * The FSM has no other state setup so this has to be handled out-of-band.
1105 + */
1106 + fiq_print(FIQDBG_ERR, state, "ERRST %02d", n);
1107 + if (hcint_probe.b.nak || hcint_probe.b.ack || hcint_probe.b.datatglerr) {
1108 + fiq_print(FIQDBG_ERR, state, "RESET %02d", n);
1109 + st->nr_errors = 0;
1110 + hcintmsk.b.nak = 0;
1111 + hcintmsk.b.ack = 0;
1112 + hcintmsk.b.datatglerr = 0;
1113 + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, hcintmsk.d32);
1114 + return 1;
1115 + }
1116 + if (hcint_probe.b.chhltd) {
1117 + fiq_print(FIQDBG_ERR, state, "CHHLT %02d", n);
1118 + fiq_print(FIQDBG_ERR, state, "%08x", hcint.d32);
1119 + return 0;
1120 + }
1121 + break;
1122 +
1123 + /* Non-periodic state groups */
1124 + case FIQ_NP_SSPLIT_STARTED:
1125 + case FIQ_NP_SSPLIT_RETRY:
1126 + /* Got a HCINT for a NP SSPLIT. Expected ACK / NAK / fail */
1127 + if (hcint.b.ack) {
1128 + /* SSPLIT complete. For OUT, the data has been sent. For IN, the LS transaction
1129 + * will start shortly. SOF needs to kick the transaction to prevent a NYET flood.
1130 + */
1131 + if(st->hcchar_copy.b.epdir == 1)
1132 + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
1133 + else
1134 + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
1135 + st->nr_errors = 0;
1136 + handled = 1;
1137 + fiq_fsm_setup_csplit(state, n);
1138 + } else if (hcint.b.nak) {
1139 + // No buffer space in TT. Retry on a uframe boundary.
1140 + st->fsm = FIQ_NP_SSPLIT_RETRY;
1141 + handled = 1;
1142 + } else if (hcint.b.xacterr) {
1143 + // The only other one we care about is xacterr. This implies HS bus error - retry.
1144 + st->nr_errors++;
1145 + st->fsm = FIQ_NP_SSPLIT_RETRY;
1146 + if (st->nr_errors >= 3) {
1147 + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
1148 + } else {
1149 + handled = 1;
1150 + restart = 1;
1151 + }
1152 + } else {
1153 + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
1154 + handled = 0;
1155 + restart = 0;
1156 + }
1157 + break;
1158 +
1159 + case FIQ_NP_IN_CSPLIT_RETRY:
1160 + /* Received a CSPLIT done interrupt.
1161 + * Expected Data/NAK/STALL/NYET for IN.
1162 + */
1163 + if (hcint.b.xfercomp) {
1164 + /* For IN, data is present. */
1165 + st->fsm = FIQ_NP_SPLIT_DONE;
1166 + } else if (hcint.b.nak) {
1167 + /* no endpoint data. Punt it upstairs */
1168 + st->fsm = FIQ_NP_SPLIT_DONE;
1169 + } else if (hcint.b.nyet) {
1170 + /* CSPLIT NYET - retry on a uframe boundary. */
1171 + handled = 1;
1172 + st->nr_errors = 0;
1173 + } else if (hcint.b.datatglerr) {
1174 + /* data toggle errors do not set the xfercomp bit. */
1175 + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
1176 + } else if (hcint.b.xacterr) {
1177 + /* HS error. Retry immediate */
1178 + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
1179 + st->nr_errors++;
1180 + if (st->nr_errors >= 3) {
1181 + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
1182 + } else {
1183 + handled = 1;
1184 + restart = 1;
1185 + }
1186 + } else if (hcint.b.stall || hcint.b.bblerr) {
1187 + /* A STALL implies either a LS bus error or a genuine STALL. */
1188 + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
1189 + } else {
1190 + /* Hardware bug. It's possible in some cases to
1191 + * get a channel halt with nothing else set when
1192 + * the response was a NYET. Treat as local 3-strikes retry.
1193 + */
1194 + hcint_data_t hcint_test = hcint;
1195 + hcint_test.b.chhltd = 0;
1196 + if (!hcint_test.d32) {
1197 + st->nr_errors++;
1198 + if (st->nr_errors >= 3) {
1199 + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
1200 + } else {
1201 + handled = 1;
1202 + }
1203 + } else {
1204 + /* Bail out if something unexpected happened */
1205 + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
1206 + }
1207 + }
1208 + break;
1209 +
1210 + case FIQ_NP_OUT_CSPLIT_RETRY:
1211 + /* Received a CSPLIT done interrupt.
1212 + * Expected ACK/NAK/STALL/NYET/XFERCOMP for OUT.*/
1213 + if (hcint.b.xfercomp) {
1214 + st->fsm = FIQ_NP_SPLIT_DONE;
1215 + } else if (hcint.b.nak) {
1216 + // The HCD will implement the holdoff on frame boundaries.
1217 + st->fsm = FIQ_NP_SPLIT_DONE;
1218 + } else if (hcint.b.nyet) {
1219 + // Hub still processing.
1220 + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
1221 + handled = 1;
1222 + st->nr_errors = 0;
1223 + //restart = 1;
1224 + } else if (hcint.b.xacterr) {
1225 + /* HS error. retry immediate */
1226 + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
1227 + st->nr_errors++;
1228 + if (st->nr_errors >= 3) {
1229 + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
1230 + } else {
1231 + handled = 1;
1232 + restart = 1;
1233 + }
1234 + } else if (hcint.b.stall) {
1235 + /* LS bus error or genuine stall */
1236 + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
1237 + } else {
1238 + /*
1239 + * Hardware bug. It's possible in some cases to get a
1240 + * channel halt with nothing else set when the response was a NYET.
1241 + * Treat as local 3-strikes retry.
1242 + */
1243 + hcint_data_t hcint_test = hcint;
1244 + hcint_test.b.chhltd = 0;
1245 + if (!hcint_test.d32) {
1246 + st->nr_errors++;
1247 + if (st->nr_errors >= 3) {
1248 + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
1249 + } else {
1250 + handled = 1;
1251 + }
1252 + } else {
1253 + // Something unexpected happened. AHBerror or babble perhaps. Let the IRQ deal with it.
1254 + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
1255 + }
1256 + }
1257 + break;
1258 +
1259 + /* Periodic split states (except isoc out) */
1260 + case FIQ_PER_SSPLIT_STARTED:
1261 + /* Expect an ACK or failure for SSPLIT */
1262 + if (hcint.b.ack) {
1263 + /*
1264 + * SSPLIT transfer complete interrupt - the generation of this interrupt is fraught with bugs.
1265 + * For a packet queued in microframe n-3 to appear in n-2, if the channel is enabled near the EOF1
1266 + * point for microframe n-3, the packet will not appear on the bus until microframe n.
1267 + * Additionally, the generation of the actual interrupt is dodgy. For a packet appearing on the bus
1268 + * in microframe n, sometimes the interrupt is generated immediately. Sometimes, it appears in n+1
1269 + * coincident with SOF for n+1.
1270 + * SOF is also buggy. It can sometimes be raised AFTER the first bus transaction has taken place.
1271 + * These appear to be caused by timing/clock crossing bugs within the core itself.
1272 + * State machine workaround.
1273 + */
1274 + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
1275 + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
1276 + fiq_fsm_setup_csplit(state, n);
1277 + /* Poke the oddfrm bit. If we are equivalent, we received the interrupt at the correct
1278 + * time. If not, then we're in the next SOF.
1279 + */
1280 + if ((hfnum.b.frnum & 0x1) == hcchar.b.oddfrm) {
1281 + fiq_print(FIQDBG_INT, state, "CSWAIT %01d", n);
1282 + st->expected_uframe = hfnum.b.frnum;
1283 + st->fsm = FIQ_PER_CSPLIT_WAIT;
1284 + } else {
1285 + fiq_print(FIQDBG_INT, state, "CSPOL %01d", n);
1286 + /* For isochronous IN endpoints,
1287 + * we need to hold off if we are expecting a lot of data */
1288 + if (st->hcchar_copy.b.mps < DATA0_PID_HEURISTIC) {
1289 + start_next_periodic = 1;
1290 + }
1291 + /* Danger will robinson: we are in a broken state. If our first interrupt after
1292 + * this is a NYET, it will be delayed by 1 uframe and result in an unrecoverable
1293 + * lag. Unmask the NYET interrupt.
1294 + */
1295 + st->expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
1296 + st->fsm = FIQ_PER_CSPLIT_BROKEN_NYET1;
1297 + restart = 1;
1298 + }
1299 + handled = 1;
1300 + } else if (hcint.b.xacterr) {
1301 + /* 3-strikes retry is enabled, we have hit our max nr_errors */
1302 + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
1303 + start_next_periodic = 1;
1304 + } else {
1305 + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
1306 + start_next_periodic = 1;
1307 + }
1308 + /* We can now queue the next isochronous OUT transaction, if one is pending. */
1309 + if(fiq_fsm_tt_next_isoc(state, num_channels, n)) {
1310 + fiq_print(FIQDBG_INT, state, "NEXTISO ");
1311 + }
1312 + break;
1313 +
1314 + case FIQ_PER_CSPLIT_NYET1:
1315 + /* First CSPLIT attempt was a NYET. If we get a subsequent NYET,
1316 + * we are too late and the TT has dropped its CSPLIT fifo.
1317 + */
1318 + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
1319 + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
1320 + start_next_periodic = 1;
1321 + if (hcint.b.nak) {
1322 + st->fsm = FIQ_PER_SPLIT_DONE;
1323 + } else if (hcint.b.xfercomp) {
1324 + fiq_increment_dma_buf(state, num_channels, n);
1325 + st->fsm = FIQ_PER_CSPLIT_POLL;
1326 + st->nr_errors = 0;
1327 + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
1328 + handled = 1;
1329 + restart = 1;
1330 + if (!last_csplit)
1331 + start_next_periodic = 0;
1332 + } else {
1333 + st->fsm = FIQ_PER_SPLIT_DONE;
1334 + }
1335 + } else if (hcint.b.nyet) {
1336 + /* Doh. Data lost. */
1337 + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
1338 + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
1339 + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
1340 + } else {
1341 + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
1342 + }
1343 + break;
1344 +
1345 + case FIQ_PER_CSPLIT_BROKEN_NYET1:
1346 + /*
1347 + * we got here because our host channel is in the delayed-interrupt
1348 + * state and we cannot take a NYET interrupt any later than when it
1349 + * occurred. Disable then re-enable the channel if this happens to force
1350 + * CSPLITs to occur at the right time.
1351 + */
1352 + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
1353 + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
1354 + fiq_print(FIQDBG_INT, state, "BROK: %01d ", n);
1355 + if (hcint.b.nak) {
1356 + st->fsm = FIQ_PER_SPLIT_DONE;
1357 + start_next_periodic = 1;
1358 + } else if (hcint.b.xfercomp) {
1359 + fiq_increment_dma_buf(state, num_channels, n);
1360 + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
1361 + st->fsm = FIQ_PER_CSPLIT_POLL;
1362 + handled = 1;
1363 + restart = 1;
1364 + start_next_periodic = 1;
1365 + /* Reload HCTSIZ for the next transfer */
1366 + fiq_fsm_reload_hctsiz(state, n);
1367 + if (!last_csplit)
1368 + start_next_periodic = 0;
1369 + } else {
1370 + st->fsm = FIQ_PER_SPLIT_DONE;
1371 + }
1372 + } else if (hcint.b.nyet) {
1373 + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
1374 + start_next_periodic = 1;
1375 + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
1376 + /* Local 3-strikes retry is handled by the core. This is a ERR response.*/
1377 + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
1378 + } else {
1379 + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
1380 + }
1381 + break;
1382 +
1383 + case FIQ_PER_CSPLIT_POLL:
1384 + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
1385 + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
1386 + start_next_periodic = 1;
1387 + if (hcint.b.nak) {
1388 + st->fsm = FIQ_PER_SPLIT_DONE;
1389 + } else if (hcint.b.xfercomp) {
1390 + fiq_increment_dma_buf(state, num_channels, n);
1391 + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
1392 + handled = 1;
1393 + restart = 1;
1394 + /* Reload HCTSIZ for the next transfer */
1395 + fiq_fsm_reload_hctsiz(state, n);
1396 + if (!last_csplit)
1397 + start_next_periodic = 0;
1398 + } else {
1399 + st->fsm = FIQ_PER_SPLIT_DONE;
1400 + }
1401 + } else if (hcint.b.nyet) {
1402 + /* Are we a NYET after the first data packet? */
1403 + if (st->nrpackets == 0) {
1404 + st->fsm = FIQ_PER_CSPLIT_NYET1;
1405 + handled = 1;
1406 + restart = 1;
1407 + } else {
1408 + /* We got a NYET when polling CSPLITs. Can happen
1409 + * if our heuristic fails, or if someone disables us
1410 + * for any significant length of time.
1411 + */
1412 + if (st->nr_errors >= 3) {
1413 + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
1414 + } else {
1415 + st->fsm = FIQ_PER_SPLIT_DONE;
1416 + }
1417 + }
1418 + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
1419 + /* For xacterr, Local 3-strikes retry is handled by the core. This is a ERR response.*/
1420 + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
1421 + } else {
1422 + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
1423 + }
1424 + break;
1425 +
1426 + case FIQ_HS_ISOC_TURBO:
1427 + if (fiq_fsm_update_hs_isoc(state, n, hcint)) {
1428 + /* more transactions to come */
1429 + handled = 1;
1430 + restart = 1;
1431 + fiq_print(FIQDBG_INT, state, "HSISO M ");
1432 + } else {
1433 + st->fsm = FIQ_HS_ISOC_DONE;
1434 + fiq_print(FIQDBG_INT, state, "HSISO F ");
1435 + }
1436 + break;
1437 +
1438 + case FIQ_HS_ISOC_ABORTED:
1439 + /* This abort is called by the driver rewriting the state mid-transaction
1440 + * which allows the dequeue mechanism to work more effectively.
1441 + */
1442 + break;
1443 +
1444 + case FIQ_PER_ISO_OUT_ACTIVE:
1445 + if (hcint.b.ack) {
1446 + if(fiq_iso_out_advance(state, num_channels, n)) {
1447 + /* last OUT transfer */
1448 + st->fsm = FIQ_PER_ISO_OUT_LAST;
1449 + /*
1450 + * Assuming the periodic FIFO in the dwc core
1451 + * actually does its job properly, we can queue
1452 + * the next ssplit now and in theory, the wire
1453 + * transactions will be in-order.
1454 + */
1455 + // No it doesn't. It appears to process requests in host channel order.
1456 + //start_next_periodic = 1;
1457 + }
1458 + handled = 1;
1459 + restart = 1;
1460 + } else {
1461 + /*
1462 + * Isochronous transactions carry on regardless. Log the error
1463 + * and continue.
1464 + */
1465 + //explode += 1;
1466 + st->nr_errors++;
1467 + if(fiq_iso_out_advance(state, num_channels, n)) {
1468 + st->fsm = FIQ_PER_ISO_OUT_LAST;
1469 + //start_next_periodic = 1;
1470 + }
1471 + handled = 1;
1472 + restart = 1;
1473 + }
1474 + break;
1475 +
1476 + case FIQ_PER_ISO_OUT_LAST:
1477 + if (hcint.b.ack) {
1478 + /* All done here */
1479 + st->fsm = FIQ_PER_ISO_OUT_DONE;
1480 + } else {
1481 + st->fsm = FIQ_PER_ISO_OUT_DONE;
1482 + st->nr_errors++;
1483 + }
1484 + start_next_periodic = 1;
1485 + break;
1486 +
1487 + case FIQ_PER_SPLIT_TIMEOUT:
1488 + /* SOF kicked us because we overran. */
1489 + start_next_periodic = 1;
1490 + break;
1491 +
1492 + default:
1493 + break;
1494 + }
1495 +
1496 + if (handled) {
1497 + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT, hcint.d32);
1498 + } else {
1499 + /* Copy the regs into the state so the IRQ knows what to do */
1500 + st->hcint_copy.d32 = hcint.d32;
1501 + }
1502 +
1503 + if (restart) {
1504 + /* Restart always implies handled. */
1505 + if (restart == 2) {
1506 + /* For complete-split INs, the show must go on.
1507 + * Force a channel restart */
1508 + fiq_fsm_restart_channel(state, n, 1);
1509 + } else {
1510 + fiq_fsm_restart_channel(state, n, 0);
1511 + }
1512 + }
1513 + if (start_next_periodic) {
1514 + fiq_fsm_start_next_periodic(state, num_channels);
1515 + }
1516 + if (st->fsm != FIQ_PASSTHROUGH)
1517 + fiq_print(FIQDBG_INT, state, "FSMOUT%02d", st->fsm);
1518 +
1519 + return handled;
1520 +}
1521 +
1522 +
1523 +/**
1524 + * dwc_otg_fiq_fsm() - Flying State Machine (monster) FIQ
1525 + * @state: pointer to state struct passed from the banked FIQ mode registers.
1526 + * @num_channels: set according to the DWC hardware configuration
1527 + * @dma: pointer to DMA bounce buffers for split transaction slots
1528 + *
1529 + * The FSM FIQ performs the low-level tasks that normally would be performed by the microcode
1530 + * inside an EHCI or similar host controller regarding split transactions. The DWC core
1531 + * interrupts each and every time a split transaction packet is received or sent successfully.
1532 + * This results in either an interrupt storm when everything is working "properly", or
1533 + * the interrupt latency of the system in general breaks time-sensitive periodic split
1534 + * transactions. Pushing the low-level, but relatively easy state machine work into the FIQ
1535 + * solves these problems.
1536 + *
1537 + * Return: void
1538 + */
1539 +void notrace dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels)
1540 +{
1541 + gintsts_data_t gintsts, gintsts_handled;
1542 + gintmsk_data_t gintmsk;
1543 + //hfnum_data_t hfnum;
1544 + haint_data_t haint, haint_handled;
1545 + haintmsk_data_t haintmsk;
1546 + int kick_irq = 0;
1547 +
1548 + gintsts_handled.d32 = 0;
1549 + haint_handled.d32 = 0;
1550 +
1551 + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
1552 + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
1553 + gintsts.d32 &= gintmsk.d32;
1554 +
1555 + if (gintsts.b.sofintr) {
1556 + /* For FSM mode, SOF is required to keep the state machine advance for
1557 + * certain stages of the periodic pipeline. It's death to mask this
1558 + * interrupt in that case.
1559 + */
1560 +
1561 + if (!fiq_fsm_do_sof(state, num_channels)) {
1562 + /* Kick IRQ once. Queue advancement means that all pending transactions
1563 + * will get serviced when the IRQ finally executes.
1564 + */
1565 + if (state->gintmsk_saved.b.sofintr == 1)
1566 + kick_irq |= 1;
1567 + state->gintmsk_saved.b.sofintr = 0;
1568 + }
1569 + gintsts_handled.b.sofintr = 1;
1570 + }
1571 +
1572 + if (gintsts.b.hcintr) {
1573 + int i;
1574 + haint.d32 = FIQ_READ(state->dwc_regs_base + HAINT);
1575 + haintmsk.d32 = FIQ_READ(state->dwc_regs_base + HAINTMSK);
1576 + haint.d32 &= haintmsk.d32;
1577 + haint_handled.d32 = 0;
1578 + for (i=0; i<num_channels; i++) {
1579 + if (haint.b2.chint & (1 << i)) {
1580 + if(!fiq_fsm_do_hcintr(state, num_channels, i)) {
1581 + /* HCINT was not handled in FIQ
1582 + * HAINT is level-sensitive, leading to level-sensitive ginststs.b.hcint bit.
1583 + * Mask HAINT(i) but keep top-level hcint unmasked.
1584 + */
1585 + state->haintmsk_saved.b2.chint &= ~(1 << i);
1586 + } else {
1587 + /* do_hcintr cleaned up after itself, but clear haint */
1588 + haint_handled.b2.chint |= (1 << i);
1589 + }
1590 + }
1591 + }
1592 +
1593 + if (haint_handled.b2.chint) {
1594 + FIQ_WRITE(state->dwc_regs_base + HAINT, haint_handled.d32);
1595 + }
1596 +
1597 + if (haintmsk.d32 != (haintmsk.d32 & state->haintmsk_saved.d32)) {
1598 + /*
1599 + * This is necessary to avoid multiple retriggers of the MPHI in the case
1600 + * where interrupts are held off and HCINTs start to pile up.
1601 + * Only wake up the IRQ if a new interrupt came in, was not handled and was
1602 + * masked.
1603 + */
1604 + haintmsk.d32 &= state->haintmsk_saved.d32;
1605 + FIQ_WRITE(state->dwc_regs_base + HAINTMSK, haintmsk.d32);
1606 + kick_irq |= 1;
1607 + }
1608 + /* Top-Level interrupt - always handled because it's level-sensitive */
1609 + gintsts_handled.b.hcintr = 1;
1610 + }
1611 +
1612 +
1613 + /* Clear the bits in the saved register that were not handled but were triggered. */
1614 + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
1615 +
1616 + /* FIQ didn't handle something - mask has changed - write new mask */
1617 + if (gintmsk.d32 != (gintmsk.d32 & state->gintmsk_saved.d32)) {
1618 + gintmsk.d32 &= state->gintmsk_saved.d32;
1619 + gintmsk.b.sofintr = 1;
1620 + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
1621 +// fiq_print(FIQDBG_INT, state, "KICKGINT");
1622 +// fiq_print(FIQDBG_INT, state, "%08x", gintmsk.d32);
1623 +// fiq_print(FIQDBG_INT, state, "%08x", state->gintmsk_saved.d32);
1624 + kick_irq |= 1;
1625 + }
1626 +
1627 + if (gintsts_handled.d32) {
1628 + /* Only applies to edge-sensitive bits in GINTSTS */
1629 + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
1630 + }
1631 +
1632 + /* We got an interrupt, didn't handle it. */
1633 + if (kick_irq) {
1634 + state->mphi_int_count++;
1635 + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
1636 + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
1637 +
1638 + }
1639 + state->fiq_done++;
1640 + mb();
1641 +}
1642 +
1643 +
1644 +/**
1645 + * dwc_otg_fiq_nop() - FIQ "lite"
1646 + * @state: pointer to state struct passed from the banked FIQ mode registers.
1647 + *
1648 + * The "nop" handler does not intervene on any interrupts other than SOF.
1649 + * It is limited in scope to deciding at each SOF if the IRQ SOF handler (which deals
1650 + * with non-periodic/periodic queues) needs to be kicked.
1651 + *
1652 + * This is done to hold off the SOF interrupt, which occurs at a rate of 8000 per second.
1653 + *
1654 + * Return: void
1655 + */
1656 +void notrace dwc_otg_fiq_nop(struct fiq_state *state)
1657 +{
1658 + gintsts_data_t gintsts, gintsts_handled;
1659 + gintmsk_data_t gintmsk;
1660 + hfnum_data_t hfnum;
1661 +
1662 + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
1663 + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
1664 + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
1665 + gintsts.d32 &= gintmsk.d32;
1666 + gintsts_handled.d32 = 0;
1667 +
1668 + if (gintsts.b.sofintr) {
1669 + if (!state->kick_np_queues &&
1670 + dwc_frame_num_gt(state->next_sched_frame, hfnum.b.frnum)) {
1671 + /* SOF handled, no work to do, just ACK interrupt */
1672 + gintsts_handled.b.sofintr = 1;
1673 + } else {
1674 + /* Kick IRQ */
1675 + state->gintmsk_saved.b.sofintr = 0;
1676 + }
1677 + }
1678 +
1679 + /* Reset handled interrupts */
1680 + if(gintsts_handled.d32) {
1681 + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
1682 + }
1683 +
1684 + /* Clear the bits in the saved register that were not handled but were triggered. */
1685 + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
1686 +
1687 + /* We got an interrupt, didn't handle it and want to mask it */
1688 + if (~(state->gintmsk_saved.d32)) {
1689 + state->mphi_int_count++;
1690 + gintmsk.d32 &= state->gintmsk_saved.d32;
1691 + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
1692 + /* Force a clear before another dummy send */
1693 + FIQ_WRITE(state->mphi_regs.intstat, (1<<29));
1694 + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
1695 + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
1696 +
1697 + }
1698 + state->fiq_done++;
1699 + mb();
1700 +}
1701 --- /dev/null
1702 +++ b/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
1703 @@ -0,0 +1,353 @@
1704 +/*
1705 + * dwc_otg_fiq_fsm.h - Finite state machine FIQ header definitions
1706 + *
1707 + * Copyright (c) 2013 Raspberry Pi Foundation
1708 + *
1709 + * Author: Jonathan Bell <jonathan@raspberrypi.org>
1710 + * All rights reserved.
1711 + *
1712 + * Redistribution and use in source and binary forms, with or without
1713 + * modification, are permitted provided that the following conditions are met:
1714 + * * Redistributions of source code must retain the above copyright
1715 + * notice, this list of conditions and the following disclaimer.
1716 + * * Redistributions in binary form must reproduce the above copyright
1717 + * notice, this list of conditions and the following disclaimer in the
1718 + * documentation and/or other materials provided with the distribution.
1719 + * * Neither the name of Raspberry Pi nor the
1720 + * names of its contributors may be used to endorse or promote products
1721 + * derived from this software without specific prior written permission.
1722 + *
1723 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1724 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1725 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1726 + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
1727 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1728 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1729 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1730 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1731 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1732 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1733 + *
1734 + * This FIQ implements functionality that performs split transactions on
1735 + * the dwc_otg hardware without any outside intervention. A split transaction
1736 + * is "queued" by nominating a specific host channel to perform the entirety
1737 + * of a split transaction. This FIQ will then perform the microframe-precise
1738 + * scheduling required in each phase of the transaction until completion.
1739 + *
1740 + * The FIQ functionality has been surgically implanted into the Synopsys
1741 + * vendor-provided driver.
1742 + *
1743 + */
1744 +
1745 +#ifndef DWC_OTG_FIQ_FSM_H_
1746 +#define DWC_OTG_FIQ_FSM_H_
1747 +
1748 +#include "dwc_otg_regs.h"
1749 +#include "dwc_otg_cil.h"
1750 +#include "dwc_otg_hcd.h"
1751 +#include <linux/kernel.h>
1752 +#include <linux/irqflags.h>
1753 +#include <linux/string.h>
1754 +#include <asm/barrier.h>
1755 +
1756 +#if 0
1757 +#define FLAME_ON(x) \
1758 +do { \
1759 + int gpioreg; \
1760 + \
1761 + gpioreg = readl(__io_address(0x20200000+0x8)); \
1762 + gpioreg &= ~(7 << (x-20)*3); \
1763 + gpioreg |= 0x1 << (x-20)*3; \
1764 + writel(gpioreg, __io_address(0x20200000+0x8)); \
1765 + \
1766 + writel(1<<x, __io_address(0x20200000+(0x1C))); \
1767 +} while (0)
1768 +
1769 +#define FLAME_OFF(x) \
1770 +do { \
1771 + writel(1<<x, __io_address(0x20200000+(0x28))); \
1772 +} while (0)
1773 +#else
1774 +#define FLAME_ON(x) do { } while (0)
1775 +#define FLAME_OFF(X) do { } while (0)
1776 +#endif
1777 +
1778 +/* This is a quick-and-dirty arch-specific register read/write. We know that
1779 + * writes to a peripheral on BCM2835 will always arrive in-order, also that
1780 + * reads and writes are executed in-order therefore the need for memory barriers
1781 + * is obviated if we're only talking to USB.
1782 + */
1783 +#define FIQ_WRITE(_addr_,_data_) (*(volatile unsigned int *) (_addr_) = (_data_))
1784 +#define FIQ_READ(_addr_) (*(volatile unsigned int *) (_addr_))
1785 +
1786 +/* FIQ-ified register definitions. Offsets are from dwc_regs_base. */
1787 +#define GINTSTS 0x014
1788 +#define GINTMSK 0x018
1789 +/* Debug register. Poll the top of the received packets FIFO. */
1790 +#define GRXSTSR 0x01C
1791 +#define HFNUM 0x408
1792 +#define HAINT 0x414
1793 +#define HAINTMSK 0x418
1794 +#define HPRT0 0x440
1795 +
1796 +/* HC_regs start from an offset of 0x500 */
1797 +#define HC_START 0x500
1798 +#define HC_OFFSET 0x020
1799 +
1800 +#define HC_DMA 0x514
1801 +
1802 +#define HCCHAR 0x00
1803 +#define HCSPLT 0x04
1804 +#define HCINT 0x08
1805 +#define HCINTMSK 0x0C
1806 +#define HCTSIZ 0x10
1807 +
1808 +#define ISOC_XACTPOS_ALL 0b11
1809 +#define ISOC_XACTPOS_BEGIN 0b10
1810 +#define ISOC_XACTPOS_MID 0b00
1811 +#define ISOC_XACTPOS_END 0b01
1812 +
1813 +#define DWC_PID_DATA2 0b01
1814 +#define DWC_PID_MDATA 0b11
1815 +#define DWC_PID_DATA1 0b10
1816 +#define DWC_PID_DATA0 0b00
1817 +
1818 +typedef struct {
1819 + volatile void* base;
1820 + volatile void* ctrl;
1821 + volatile void* outdda;
1822 + volatile void* outddb;
1823 + volatile void* intstat;
1824 +} mphi_regs_t;
1825 +
1826 +
1827 +enum fiq_debug_level {
1828 + FIQDBG_SCHED = (1 << 0),
1829 + FIQDBG_INT = (1 << 1),
1830 + FIQDBG_ERR = (1 << 2),
1831 + FIQDBG_PORTHUB = (1 << 3),
1832 +};
1833 +
1834 +struct fiq_state;
1835 +
1836 +extern void _fiq_print (enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...);
1837 +#if 0
1838 +#define fiq_print _fiq_print
1839 +#else
1840 +#define fiq_print(x, y, ...)
1841 +#endif
1842 +
1843 +extern bool fiq_enable, fiq_fsm_enable;
1844 +extern ushort nak_holdoff;
1845 +
1846 +/**
1847 + * enum fiq_fsm_state - The FIQ FSM states.
1848 + *
1849 + * This is the "core" of the FIQ FSM. Broadly, the FSM states follow the
1850 + * USB2.0 specification for host responses to various transaction states.
1851 + * There are modifications to this host state machine because of a variety of
1852 + * quirks and limitations in the dwc_otg hardware.
1853 + *
1854 + * The fsm state is also used to communicate back to the driver on completion of
1855 + * a split transaction. The end states are used in conjunction with the interrupts
1856 + * raised by the final transaction.
1857 + */
1858 +enum fiq_fsm_state {
1859 + /* FIQ isn't enabled for this host channel */
1860 + FIQ_PASSTHROUGH = 0,
1861 + /* For the first interrupt received for this channel,
1862 + * the FIQ has to ack any interrupts indicating success. */
1863 + FIQ_PASSTHROUGH_ERRORSTATE = 31,
1864 + /* Nonperiodic state groups */
1865 + FIQ_NP_SSPLIT_STARTED = 1,
1866 + FIQ_NP_SSPLIT_RETRY = 2,
1867 + FIQ_NP_OUT_CSPLIT_RETRY = 3,
1868 + FIQ_NP_IN_CSPLIT_RETRY = 4,
1869 + FIQ_NP_SPLIT_DONE = 5,
1870 + FIQ_NP_SPLIT_LS_ABORTED = 6,
1871 + /* This differentiates a HS transaction error from a LS one
1872 + * (handling the hub state is different) */
1873 + FIQ_NP_SPLIT_HS_ABORTED = 7,
1874 +
1875 + /* Periodic state groups */
1876 + /* Periodic transactions are either started directly by the IRQ handler
1877 + * or deferred if the TT is already in use.
1878 + */
1879 + FIQ_PER_SSPLIT_QUEUED = 8,
1880 + FIQ_PER_SSPLIT_STARTED = 9,
1881 + FIQ_PER_SSPLIT_LAST = 10,
1882 +
1883 +
1884 + FIQ_PER_ISO_OUT_PENDING = 11,
1885 + FIQ_PER_ISO_OUT_ACTIVE = 12,
1886 + FIQ_PER_ISO_OUT_LAST = 13,
1887 + FIQ_PER_ISO_OUT_DONE = 27,
1888 +
1889 + FIQ_PER_CSPLIT_WAIT = 14,
1890 + FIQ_PER_CSPLIT_NYET1 = 15,
1891 + FIQ_PER_CSPLIT_BROKEN_NYET1 = 28,
1892 + FIQ_PER_CSPLIT_NYET_FAFF = 29,
1893 + /* For multiple CSPLITs (large isoc IN, or delayed interrupt) */
1894 + FIQ_PER_CSPLIT_POLL = 16,
1895 + /* The last CSPLIT for a transaction has been issued, differentiates
1896 + * for the state machine to queue the next packet.
1897 + */
1898 + FIQ_PER_CSPLIT_LAST = 17,
1899 +
1900 + FIQ_PER_SPLIT_DONE = 18,
1901 + FIQ_PER_SPLIT_LS_ABORTED = 19,
1902 + FIQ_PER_SPLIT_HS_ABORTED = 20,
1903 + FIQ_PER_SPLIT_NYET_ABORTED = 21,
1904 + /* Frame rollover has occurred without the transaction finishing. */
1905 + FIQ_PER_SPLIT_TIMEOUT = 22,
1906 +
1907 + /* FIQ-accelerated HS Isochronous state groups */
1908 + FIQ_HS_ISOC_TURBO = 23,
1909 + /* For interval > 1, SOF wakes up the isochronous FSM */
1910 + FIQ_HS_ISOC_SLEEPING = 24,
1911 + FIQ_HS_ISOC_DONE = 25,
1912 + FIQ_HS_ISOC_ABORTED = 26,
1913 + FIQ_DEQUEUE_ISSUED = 30,
1914 + FIQ_TEST = 32,
1915 +};
1916 +
1917 +struct fiq_stack {
1918 + int magic1;
1919 + uint8_t stack[2048];
1920 + int magic2;
1921 +};
1922 +
1923 +
1924 +/**
1925 + * struct fiq_dma_info - DMA bounce buffer utilisation information (per-channel)
1926 + * @index: Number of slots reported used for IN transactions / number of slots
1927 + * transmitted for an OUT transaction
1928 + * @slot_len[6]: Number of actual transfer bytes in each slot (255 if unused)
1929 + *
1930 + * Split transaction transfers can have variable length depending on other bus
1931 + * traffic. The OTG core DMA engine requires 4-byte aligned addresses therefore
1932 + * each transaction needs a guaranteed aligned address. A maximum of 6 split transfers
1933 + * can happen per-frame.
1934 + */
1935 +struct fiq_dma_info {
1936 + u8 index;
1937 + u8 slot_len[6];
1938 +};
1939 +
1940 +struct __attribute__((packed)) fiq_split_dma_slot {
1941 + u8 buf[188];
1942 +};
1943 +
1944 +struct fiq_dma_channel {
1945 + struct __attribute__((packed)) fiq_split_dma_slot index[6];
1946 +};
1947 +
1948 +struct fiq_dma_blob {
1949 + struct __attribute__((packed)) fiq_dma_channel channel[0];
1950 +};
1951 +
1952 +/**
1953 + * struct fiq_hs_isoc_info - USB2.0 isochronous data
1954 + * @iso_frame: Pointer to the array of OTG URB iso_frame_descs.
1955 + * @nrframes: Total length of iso_frame_desc array
1956 + * @index: Current index (FIQ-maintained)
1957 + *
1958 + */
1959 +struct fiq_hs_isoc_info {
1960 + struct dwc_otg_hcd_iso_packet_desc *iso_desc;
1961 + unsigned int nrframes;
1962 + unsigned int index;
1963 +};
1964 +
1965 +/**
1966 + * struct fiq_channel_state - FIQ state machine storage
1967 + * @fsm: Current state of the channel as understood by the FIQ
1968 + * @nr_errors: Number of transaction errors on this split-transaction
1969 + * @hub_addr: SSPLIT/CSPLIT destination hub
1970 + * @port_addr: SSPLIT/CSPLIT destination port - always 1 if single TT hub
1971 + * @nrpackets: For isoc OUT, the number of split-OUT packets to transmit. For
1972 + * split-IN, number of CSPLIT data packets that were received.
1973 + * @hcchar_copy:
1974 + * @hcsplt_copy:
1975 + * @hcintmsk_copy:
1976 + * @hctsiz_copy: Copies of the host channel registers.
1977 + * For use as scratch, or for returning state.
1978 + *
1979 + * The fiq_channel_state is state storage between interrupts for a host channel. The
1980 + * FSM state is stored here. Members of this structure must only be set up by the
1981 + * driver prior to enabling the FIQ for this host channel, and not touched until the FIQ
1982 + * has updated the state to either a COMPLETE state group or ABORT state group.
1983 + */
1984 +
1985 +struct fiq_channel_state {
1986 + enum fiq_fsm_state fsm;
1987 + unsigned int nr_errors;
1988 + unsigned int hub_addr;
1989 + unsigned int port_addr;
1990 + /* Hardware bug workaround: sometimes channel halt interrupts are
1991 + * delayed until the next SOF. Keep track of when we expected to get interrupted. */
1992 + unsigned int expected_uframe;
1993 + /* in/out for communicating number of dma buffers used, or number of ISOC to do */
1994 + unsigned int nrpackets;
1995 + struct fiq_dma_info dma_info;
1996 + struct fiq_hs_isoc_info hs_isoc_info;
1997 + /* Copies of HC registers - in/out communication from/to IRQ handler
1998 + * and for ease of channel setup. A bit of mungeing is performed - for
1999 + * example the hctsiz.b.maxp is _always_ the max packet size of the endpoint.
2000 + */
2001 + hcchar_data_t hcchar_copy;
2002 + hcsplt_data_t hcsplt_copy;
2003 + hcint_data_t hcint_copy;
2004 + hcintmsk_data_t hcintmsk_copy;
2005 + hctsiz_data_t hctsiz_copy;
2006 + hcdma_data_t hcdma_copy;
2007 +};
2008 +
2009 +/**
2010 + * struct fiq_state - top-level FIQ state machine storage
2011 + * @mphi_regs: virtual address of the MPHI peripheral register file
2012 + * @dwc_regs_base: virtual address of the base of the DWC core register file
2013 + * @dma_base: physical address for the base of the DMA bounce buffers
2014 + * @dummy_send: Scratch area for sending a fake message to the MPHI peripheral
2015 + * @gintmsk_saved: Top-level mask of interrupts that the FIQ has not handled.
2016 + * Used for determining which interrupts fired to set off the IRQ handler.
2017 + * @haintmsk_saved: Mask of interrupts from host channels that the FIQ did not handle internally.
2018 + * @np_count: Non-periodic transactions in the active queue
2019 + * @np_sent: Count of non-periodic transactions that have completed
2020 + * @next_sched_frame: For periodic transactions handled by the driver's SOF-driven queuing mechanism,
2021 + * this is the next frame on which a SOF interrupt is required. Used to hold off
2022 + * passing SOF through to the driver until necessary.
2023 + * @channel[n]: Per-channel FIQ state. Allocated during init depending on the number of host
2024 + * channels configured into the core logic.
2025 + *
2026 + * This is passed as the first argument to the dwc_otg_fiq_fsm top-level FIQ handler from the asm stub.
2027 + * It contains top-level state information.
2028 + */
2029 +struct fiq_state {
2030 + mphi_regs_t mphi_regs;
2031 + void *dwc_regs_base;
2032 + dma_addr_t dma_base;
2033 + struct fiq_dma_blob *fiq_dmab;
2034 + void *dummy_send;
2035 + gintmsk_data_t gintmsk_saved;
2036 + haintmsk_data_t haintmsk_saved;
2037 + int mphi_int_count;
2038 + unsigned int fiq_done;
2039 + unsigned int kick_np_queues;
2040 + unsigned int next_sched_frame;
2041 +#ifdef FIQ_DEBUG
2042 + char * buffer;
2043 + unsigned int bufsiz;
2044 +#endif
2045 + struct fiq_channel_state channel[0];
2046 +};
2047 +
2048 +extern int fiq_fsm_too_late(struct fiq_state *st, int n);
2049 +
2050 +extern int fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n);
2051 +
2052 +extern void dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels);
2053 +
2054 +extern void dwc_otg_fiq_nop(struct fiq_state *state);
2055 +
2056 +#endif /* DWC_OTG_FIQ_FSM_H_ */
2057 --- /dev/null
2058 +++ b/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S
2059 @@ -0,0 +1,81 @@
2060 +/*
2061 + * dwc_otg_fiq_fsm.S - assembly stub for the FSM FIQ
2062 + *
2063 + * Copyright (c) 2013 Raspberry Pi Foundation
2064 + *
2065 + * Author: Jonathan Bell <jonathan@raspberrypi.org>
2066 + * All rights reserved.
2067 + *
2068 + * Redistribution and use in source and binary forms, with or without
2069 + * modification, are permitted provided that the following conditions are met:
2070 + * * Redistributions of source code must retain the above copyright
2071 + * notice, this list of conditions and the following disclaimer.
2072 + * * Redistributions in binary form must reproduce the above copyright
2073 + * notice, this list of conditions and the following disclaimer in the
2074 + * documentation and/or other materials provided with the distribution.
2075 + * * Neither the name of Raspberry Pi nor the
2076 + * names of its contributors may be used to endorse or promote products
2077 + * derived from this software without specific prior written permission.
2078 + *
2079 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2080 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2081 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2082 + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
2083 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2084 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2085 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2086 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2087 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2088 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2089 + */
2090 +
2091 +
2092 +#include <asm/assembler.h>
2093 +#include <linux/linkage.h>
2094 +
2095 +
2096 +.text
2097 +
2098 +.global _dwc_otg_fiq_stub_end;
2099 +
2100 +/**
2101 + * _dwc_otg_fiq_stub() - entry copied to the FIQ vector page to allow
2102 + * a C-style function call with arguments from the FIQ banked registers.
2103 + * r0 = &hcd->fiq_state
2104 + * r1 = &hcd->num_channels
2105 + * r2 = &hcd->dma_buffers
2106 + * Tramples: r0, r1, r2, r4, fp, ip
2107 + */
2108 +
2109 +ENTRY(_dwc_otg_fiq_stub)
2110 + /* Stash unbanked regs - SP will have been set up for us */
2111 + mov ip, sp;
2112 + stmdb sp!, {r0-r12, lr};
2113 +#ifdef FIQ_DEBUG
2114 + // Cycle profiling - read cycle counter at start
2115 + mrc p15, 0, r5, c15, c12, 1;
2116 +#endif
2117 + /* r11 = fp, don't trample it */
2118 + mov r4, fp;
2119 + /* set EABI frame size */
2120 + sub fp, ip, #512;
2121 +
2122 + /* for fiq NOP mode - just need state */
2123 + mov r0, r8;
2124 + /* r9 = num_channels */
2125 + mov r1, r9;
2126 + /* r10 = struct *dma_bufs */
2127 +// mov r2, r10;
2128 +
2129 + /* r4 = &fiq_c_function */
2130 + blx r4;
2131 +#ifdef FIQ_DEBUG
2132 + mrc p15, 0, r4, c15, c12, 1;
2133 + subs r5, r5, r4;
2134 + // r5 is now the cycle count time for executing the FIQ. Store it somewhere?
2135 +#endif
2136 + ldmia sp!, {r0-r12, lr};
2137 + subs pc, lr, #4;
2138 +_dwc_otg_fiq_stub_end:
2139 +END(_dwc_otg_fiq_stub)
2140 +
2141 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
2142 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
2143 @@ -45,9 +45,10 @@
2144
2145 #include "dwc_otg_hcd.h"
2146 #include "dwc_otg_regs.h"
2147 -#include "dwc_otg_mphi_fix.h"
2148 +#include "dwc_otg_fiq_fsm.h"
2149
2150 -extern bool microframe_schedule, nak_holdoff_enable;
2151 +extern bool microframe_schedule;
2152 +extern uint16_t fiq_fsm_mask, nak_holdoff;
2153
2154 //#define DEBUG_HOST_CHANNELS
2155 #ifdef DEBUG_HOST_CHANNELS
2156 @@ -57,12 +58,6 @@ static int last_sel_trans_num_avail_hc_a
2157 static int last_sel_trans_num_avail_hc_at_end = 0;
2158 #endif /* DEBUG_HOST_CHANNELS */
2159
2160 -extern int g_next_sched_frame, g_np_count, g_np_sent;
2161 -
2162 -extern haint_data_t haint_saved;
2163 -extern hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
2164 -extern hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
2165 -extern gintsts_data_t ginsts_saved;
2166
2167 dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
2168 {
2169 @@ -295,7 +290,7 @@ static int32_t dwc_otg_hcd_disconnect_cb
2170 */
2171 dwc_otg_hcd->flags.b.port_connect_status_change = 1;
2172 dwc_otg_hcd->flags.b.port_connect_status = 0;
2173 - if(fiq_fix_enable)
2174 + if(fiq_enable)
2175 local_fiq_disable();
2176 /*
2177 * Shutdown any transfers in process by clearing the Tx FIFO Empty
2178 @@ -392,20 +387,15 @@ static int32_t dwc_otg_hcd_disconnect_cb
2179 channel->qh = NULL;
2180 }
2181 }
2182 - if(fiq_split_enable) {
2183 + if(fiq_fsm_enable) {
2184 for(i=0; i < 128; i++) {
2185 dwc_otg_hcd->hub_port[i] = 0;
2186 }
2187 - haint_saved.d32 = 0;
2188 - for(i=0; i < MAX_EPS_CHANNELS; i++) {
2189 - hcint_saved[i].d32 = 0;
2190 - hcintmsk_saved[i].d32 = 0;
2191 - }
2192 }
2193
2194 }
2195
2196 - if(fiq_fix_enable)
2197 + if(fiq_enable)
2198 local_fiq_enable();
2199
2200 if (dwc_otg_hcd->fops->disconnect) {
2201 @@ -542,7 +532,7 @@ int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_
2202 }
2203 #endif
2204 intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
2205 - if(!intr_mask.b.sofintr) needs_scheduling = 1;
2206 + if(!intr_mask.b.sofintr || fiq_enable) needs_scheduling = 1;
2207 if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
2208 /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
2209 needs_scheduling = 0;
2210 @@ -613,6 +603,7 @@ int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_
2211 if (urb_qtd->in_process && qh->channel) {
2212 /* The QTD is in process (it has been assigned to a channel). */
2213 if (hcd->flags.b.port_connect_status) {
2214 + int n = qh->channel->hc_num;
2215 /*
2216 * If still connected (i.e. in host mode), halt the
2217 * channel so it can be used for other transfers. If
2218 @@ -620,10 +611,16 @@ int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_
2219 * written to halt the channel since the core is in
2220 * device mode.
2221 */
2222 - dwc_otg_hc_halt(hcd->core_if, qh->channel,
2223 - DWC_OTG_HC_XFER_URB_DEQUEUE);
2224 -
2225 - dwc_otg_hcd_release_port(hcd, qh);
2226 + /* In FIQ FSM mode, we need to shut down carefully.
2227 + * The FIQ may attempt to restart a disabled channel */
2228 + if (fiq_fsm_enable && (hcd->fiq_state->channel[n].fsm != FIQ_PASSTHROUGH)) {
2229 + qh->channel->halt_status = DWC_OTG_HC_XFER_URB_DEQUEUE;
2230 + qh->channel->halt_pending = 1;
2231 + hcd->fiq_state->channel[n].fsm = FIQ_DEQUEUE_ISSUED;
2232 + } else {
2233 + dwc_otg_hc_halt(hcd->core_if, qh->channel,
2234 + DWC_OTG_HC_XFER_URB_DEQUEUE);
2235 + }
2236 }
2237 }
2238
2239 @@ -759,7 +756,6 @@ static void completion_tasklet_func(void
2240
2241 usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
2242
2243 - fiq_print(FIQDBG_PORTHUB, "COMPLETE");
2244
2245 DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
2246 }
2247 @@ -854,6 +850,34 @@ void dwc_otg_hcd_power_up(void *ptr)
2248 cil_hcd_start(core_if);
2249 }
2250
2251 +void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num)
2252 +{
2253 + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
2254 + struct fiq_dma_blob *blob = hcd->fiq_dmab;
2255 + int i;
2256 +
2257 + st->fsm = FIQ_PASSTHROUGH;
2258 + st->hcchar_copy.d32 = 0;
2259 + st->hcsplt_copy.d32 = 0;
2260 + st->hcint_copy.d32 = 0;
2261 + st->hcintmsk_copy.d32 = 0;
2262 + st->hctsiz_copy.d32 = 0;
2263 + st->hcdma_copy.d32 = 0;
2264 + st->nr_errors = 0;
2265 + st->hub_addr = 0;
2266 + st->port_addr = 0;
2267 + st->expected_uframe = 0;
2268 + st->nrpackets = 0;
2269 + st->dma_info.index = 0;
2270 + for (i = 0; i < 6; i++)
2271 + st->dma_info.slot_len[i] = 255;
2272 + st->hs_isoc_info.index = 0;
2273 + st->hs_isoc_info.iso_desc = NULL;
2274 + st->hs_isoc_info.nrframes = 0;
2275 +
2276 + DWC_MEMSET(&blob->channel[num].index[0], 0x6b, 1128);
2277 +}
2278 +
2279 /**
2280 * Frees secondary storage associated with the dwc_otg_hcd structure contained
2281 * in the struct usb_hcd field.
2282 @@ -907,6 +931,7 @@ static void dwc_otg_hcd_free(dwc_otg_hcd
2283 DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
2284 DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
2285 DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
2286 + DWC_FREE(dwc_otg_hcd->fiq_state);
2287
2288 #ifdef DWC_DEV_SRPCAP
2289 if (dwc_otg_hcd->core_if->power_down == 2 &&
2290 @@ -979,6 +1004,59 @@ int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd
2291 channel);
2292 }
2293
2294 + if (fiq_enable) {
2295 + hcd->fiq_state = DWC_ALLOC(sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels));
2296 + if (!hcd->fiq_state) {
2297 + retval = -DWC_E_NO_MEMORY;
2298 + DWC_ERROR("%s: cannot allocate fiq_state structure\n", __func__);
2299 + dwc_otg_hcd_free(hcd);
2300 + goto out;
2301 + }
2302 + DWC_MEMSET(hcd->fiq_state, 0, (sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels)));
2303 +
2304 + for (i = 0; i < num_channels; i++) {
2305 + hcd->fiq_state->channel[i].fsm = FIQ_PASSTHROUGH;
2306 + }
2307 + hcd->fiq_state->dummy_send = DWC_ALLOC_ATOMIC(16);
2308 +
2309 + hcd->fiq_stack = DWC_ALLOC(sizeof(struct fiq_stack));
2310 + if (!hcd->fiq_stack) {
2311 + retval = -DWC_E_NO_MEMORY;
2312 + DWC_ERROR("%s: cannot allocate fiq_stack structure\n", __func__);
2313 + dwc_otg_hcd_free(hcd);
2314 + goto out;
2315 + }
2316 + hcd->fiq_stack->magic1 = 0xDEADBEEF;
2317 + hcd->fiq_stack->magic2 = 0xD00DFEED;
2318 + hcd->fiq_state->gintmsk_saved.d32 = ~0;
2319 + hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
2320 +
2321 + /* This bit is terrible and uses no API, but necessary. The FIQ has no concept of DMA pools
2322 + * (and if it did, would be a lot slower). This allocates a chunk of memory (~9kiB for 8 host channels)
2323 + * for use as transaction bounce buffers in a 2-D array. Our access into this chunk is done by some
2324 + * moderately readable array casts.
2325 + */
2326 + hcd->fiq_dmab = DWC_DMA_ALLOC((sizeof(struct fiq_dma_channel) * num_channels), &hcd->fiq_state->dma_base);
2327 + DWC_WARN("FIQ DMA bounce buffers: virt = 0x%08x dma = 0x%08x len=%d",
2328 + (unsigned int)hcd->fiq_dmab, (unsigned int)hcd->fiq_state->dma_base,
2329 + sizeof(struct fiq_dma_channel) * num_channels);
2330 +
2331 + DWC_MEMSET(hcd->fiq_dmab, 0x6b, 9024);
2332 +
2333 + /* pointer for debug in fiq_print */
2334 + hcd->fiq_state->fiq_dmab = hcd->fiq_dmab;
2335 + if (fiq_fsm_enable) {
2336 + int i;
2337 + for (i=0; i < hcd->core_if->core_params->host_channels; i++) {
2338 + dwc_otg_cleanup_fiq_channel(hcd, i);
2339 + }
2340 + DWC_PRINTF("FIQ FSM acceleration enabled for :\n%s%s%s",
2341 + (fiq_fsm_mask & 0x1) ? "Non-periodic Split Transactions\n" : "",
2342 + (fiq_fsm_mask & 0x2) ? "Periodic Split Transactions\n" : "",
2343 + (fiq_fsm_mask & 0x4) ? "High-Speed Isochronous Endpoints\n" : "");
2344 + }
2345 + }
2346 +
2347 /* Initialize the Connection timeout timer. */
2348 hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
2349 dwc_otg_hcd_connect_timeout, 0);
2350 @@ -1176,7 +1254,8 @@ static void assign_and_init_hc(dwc_otg_h
2351 hc->do_split = 1;
2352 hc->xact_pos = qtd->isoc_split_pos;
2353 /* We don't need to do complete splits anymore */
2354 - if(fiq_split_enable)
2355 +// if(fiq_fsm_enable)
2356 + if (0)
2357 hc->complete_split = qtd->complete_split = 0;
2358 else
2359 hc->complete_split = qtd->complete_split;
2360 @@ -1327,62 +1406,487 @@ static void assign_and_init_hc(dwc_otg_h
2361 hc->qh = qh;
2362 }
2363
2364 -/*
2365 -** Check the transaction to see if the port / hub has already been assigned for
2366 -** a split transaction
2367 -**
2368 -** Return 0 - Port is already in use
2369 -*/
2370 -int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
2371 +
2372 +/**
2373 + * fiq_fsm_transaction_suitable() - Test a QH for compatibility with the FIQ
2374 + * @qh: pointer to the endpoint's queue head
2375 + *
2376 + * Transaction start/end control flow is grafted onto the existing dwc_otg
2377 + * mechanisms, to avoid spaghettifying the functions more than they already are.
2378 + * This function's eligibility check is altered by debug parameter.
2379 + *
2380 + * Returns: 0 for unsuitable, 1 implies the FIQ can be enabled for this transaction.
2381 + */
2382 +
2383 +int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh)
2384 {
2385 - uint32_t hub_addr, port_addr;
2386 + if (qh->do_split) {
2387 + switch (qh->ep_type) {
2388 + case UE_CONTROL:
2389 + case UE_BULK:
2390 + if (fiq_fsm_mask & (1 << 0))
2391 + return 1;
2392 + break;
2393 + case UE_INTERRUPT:
2394 + case UE_ISOCHRONOUS:
2395 + if (fiq_fsm_mask & (1 << 1))
2396 + return 1;
2397 + break;
2398 + default:
2399 + break;
2400 + }
2401 + } else if (qh->ep_type == UE_ISOCHRONOUS) {
2402 + if (fiq_fsm_mask & (1 << 2)) {
2403 + /* HS ISOCH support. We test for compatibility:
2404 + * - DWORD aligned buffers
2405 + * - Must be at least 2 transfers (otherwise pointless to use the FIQ)
2406 + * If yes, then the fsm enqueue function will handle the state machine setup.
2407 + */
2408 + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
2409 + dwc_otg_hcd_urb_t *urb = qtd->urb;
2410 + struct dwc_otg_hcd_iso_packet_desc (*iso_descs)[0] = &urb->iso_descs;
2411 + int nr_iso_frames = urb->packet_count;
2412 + int i;
2413 + uint32_t ptr;
2414
2415 - if(!fiq_split_enable)
2416 - return 0;
2417 + if (nr_iso_frames < 2)
2418 + return 0;
2419 + for (i = 0; i < nr_iso_frames; i++) {
2420 + ptr = urb->dma + iso_descs[i]->offset;
2421 + if (ptr & 0x3) {
2422 + printk_ratelimited("%s: Non-Dword aligned isochronous frame offset."
2423 + " Cannot queue FIQ-accelerated transfer to device %d endpoint %d\n",
2424 + __FUNCTION__, qh->channel->dev_addr, qh->channel->ep_num);
2425 + return 0;
2426 + }
2427 + }
2428 + return 1;
2429 + }
2430 + }
2431 + return 0;
2432 +}
2433
2434 - hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
2435 +/**
2436 + * fiq_fsm_setup_periodic_dma() - Set up DMA bounce buffers
2437 + * @hcd: Pointer to the dwc_otg_hcd struct
2438 + * @qh: Pointer to the endpoint's queue head
2439 + *
2440 + * Periodic split transactions are transmitted modulo 188 bytes.
2441 + * This necessitates slicing data up into buckets for isochronous out
2442 + * and fixing up the DMA address for all IN transfers.
2443 + *
2444 + * Returns 1 if the DMA bounce buffers have been used, 0 if the default
2445 + * HC buffer has been used.
2446 + */
2447 +int fiq_fsm_setup_periodic_dma(dwc_otg_hcd_t *hcd, struct fiq_channel_state *st, dwc_otg_qh_t *qh)
2448 + {
2449 + int frame_length, i = 0;
2450 + uint8_t *ptr = NULL;
2451 + dwc_hc_t *hc = qh->channel;
2452 + struct fiq_dma_blob *blob;
2453 + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
2454 +
2455 + for (i = 0; i < 6; i++) {
2456 + st->dma_info.slot_len[i] = 255;
2457 + }
2458 + st->dma_info.index = 0;
2459 + i = 0;
2460 + if (hc->ep_is_in) {
2461 + /*
2462 + * Set dma_regs to bounce buffer. FIQ will update the
2463 + * state depending on transaction progress.
2464 + */
2465 + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
2466 + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
2467 + /* Calculate the max number of CSPLITS such that the FIQ can time out
2468 + * a transaction if it fails.
2469 + */
2470 + frame_length = st->hcchar_copy.b.mps;
2471 + do {
2472 + i++;
2473 + frame_length -= 188;
2474 + } while (frame_length >= 0);
2475 + st->nrpackets = i;
2476 + return 1;
2477 + } else {
2478 + if (qh->ep_type == UE_ISOCHRONOUS) {
2479
2480 - if(hcd->hub_port[hub_addr] & (1 << port_addr))
2481 - {
2482 - fiq_print(FIQDBG_PORTHUB, "H%dP%d:S%02d", hub_addr, port_addr, qh->skip_count);
2483 + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
2484
2485 - qh->skip_count++;
2486 + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
2487 + frame_length = frame_desc->length;
2488
2489 - if(qh->skip_count > 40000)
2490 - {
2491 - printk_once(KERN_ERR "Error: Having to skip port allocation");
2492 - local_fiq_disable();
2493 - BUG();
2494 + /* Virtual address for bounce buffers */
2495 + blob = hcd->fiq_dmab;
2496 +
2497 + ptr = qtd->urb->buf + frame_desc->offset;
2498 + if (frame_length == 0) {
2499 + /*
2500 + * for isochronous transactions, we must still transmit a packet
2501 + * even if the length is zero.
2502 + */
2503 + st->dma_info.slot_len[0] = 0;
2504 + st->nrpackets = 1;
2505 + } else {
2506 + do {
2507 + if (frame_length <= 188) {
2508 + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, frame_length);
2509 + st->dma_info.slot_len[i] = frame_length;
2510 + ptr += frame_length;
2511 + } else {
2512 + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, 188);
2513 + st->dma_info.slot_len[i] = 188;
2514 + ptr += 188;
2515 + }
2516 + i++;
2517 + frame_length -= 188;
2518 + } while (frame_length > 0);
2519 + st->nrpackets = i;
2520 + }
2521 + ptr = qtd->urb->buf + frame_desc->offset;
2522 + /* Point the HC at the DMA address of the bounce buffers */
2523 + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
2524 + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
2525 +
2526 + /* fixup xfersize to the actual packet size */
2527 + st->hctsiz_copy.b.pid = 0;
2528 + st->hctsiz_copy.b.xfersize = st->dma_info.slot_len[0];
2529 + return 1;
2530 + } else {
2531 + /* For interrupt, single OUT packet required, goes in the SSPLIT from hc_buff. */
2532 return 0;
2533 }
2534 - return 1;
2535 }
2536 - else
2537 - {
2538 - qh->skip_count = 0;
2539 - hcd->hub_port[hub_addr] |= 1 << port_addr;
2540 - fiq_print(FIQDBG_PORTHUB, "H%dP%d:A %d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
2541 -#ifdef FIQ_DEBUG
2542 - hcd->hub_port_alloc[hub_addr * 16 + port_addr] = dwc_otg_hcd_get_frame_number(hcd);
2543 -#endif
2544 +}
2545 +
2546 +/*
2547 + * Pushing a periodic request into the queue near the EOF1 point
2548 + * in a microframe causes erroneous behaviour (frmovrun) interrupt.
2549 + * Usually, the request goes out on the bus causing a transfer but
2550 + * the core does not transfer the data to memory.
2551 + * This guard interval (in number of 60MHz clocks) is required which
2552 + * must cater for CPU latency between reading the value and enabling
2553 + * the channel.
2554 + */
2555 +#define PERIODIC_FRREM_BACKOFF 1000
2556 +
2557 +int fiq_fsm_queue_isoc_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
2558 +{
2559 + dwc_hc_t *hc = qh->channel;
2560 + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
2561 + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
2562 + int frame;
2563 + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
2564 + int xfer_len, nrpackets;
2565 + hcdma_data_t hcdma;
2566 + hfnum_data_t hfnum;
2567 +
2568 + if (st->fsm != FIQ_PASSTHROUGH)
2569 return 0;
2570 +
2571 + st->nr_errors = 0;
2572 +
2573 + st->hcchar_copy.d32 = 0;
2574 + st->hcchar_copy.b.mps = hc->max_packet;
2575 + st->hcchar_copy.b.epdir = hc->ep_is_in;
2576 + st->hcchar_copy.b.devaddr = hc->dev_addr;
2577 + st->hcchar_copy.b.epnum = hc->ep_num;
2578 + st->hcchar_copy.b.eptype = hc->ep_type;
2579 +
2580 + st->hcintmsk_copy.b.chhltd = 1;
2581 +
2582 + frame = dwc_otg_hcd_get_frame_number(hcd);
2583 + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
2584 +
2585 + st->hcchar_copy.b.lspddev = 0;
2586 + /* Enable the channel later as a final register write. */
2587 +
2588 + st->hcsplt_copy.d32 = 0;
2589 +
2590 + st->hs_isoc_info.iso_desc = (struct dwc_otg_hcd_iso_packet_desc *) &qtd->urb->iso_descs;
2591 + st->hs_isoc_info.nrframes = qtd->urb->packet_count;
2592 + /* grab the next DMA address offset from the array */
2593 + st->hcdma_copy.d32 = qtd->urb->dma;
2594 + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[0].offset;
2595 +
2596 + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
2597 + * the core needs to be told to send the correct number. Caution: for IN transfers,
2598 + * this is always set to the maximum size of the endpoint. */
2599 + xfer_len = st->hs_isoc_info.iso_desc[0].length;
2600 + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
2601 + if (nrpackets == 0)
2602 + nrpackets = 1;
2603 + st->hcchar_copy.b.multicnt = nrpackets;
2604 + st->hctsiz_copy.b.pktcnt = nrpackets;
2605 +
2606 + /* Initial PID also needs to be set */
2607 + if (st->hcchar_copy.b.epdir == 0) {
2608 + st->hctsiz_copy.b.xfersize = xfer_len;
2609 + switch (st->hcchar_copy.b.multicnt) {
2610 + case 1:
2611 + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
2612 + break;
2613 + case 2:
2614 + case 3:
2615 + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
2616 + break;
2617 + }
2618 +
2619 + } else {
2620 + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
2621 + switch (st->hcchar_copy.b.multicnt) {
2622 + case 1:
2623 + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
2624 + break;
2625 + case 2:
2626 + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
2627 + break;
2628 + case 3:
2629 + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
2630 + break;
2631 + }
2632 }
2633 +
2634 + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d ", hc->hc_num);
2635 + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcchar_copy.d32);
2636 + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
2637 + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
2638 + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
2639 + local_fiq_disable();
2640 + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
2641 + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
2642 + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
2643 + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
2644 + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
2645 + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
2646 + /* Prevent queueing near EOF1. Bad things happen if a periodic
2647 + * split transaction is queued very close to EOF.
2648 + */
2649 + st->fsm = FIQ_HS_ISOC_SLEEPING;
2650 + } else {
2651 + st->fsm = FIQ_HS_ISOC_TURBO;
2652 + st->hcchar_copy.b.chen = 1;
2653 + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
2654 + }
2655 + mb();
2656 + st->hcchar_copy.b.chen = 0;
2657 + local_fiq_enable();
2658 + return 0;
2659 }
2660 -void dwc_otg_hcd_release_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
2661 +
2662 +
2663 +/**
2664 + * fiq_fsm_queue_split_transaction() - Set up a host channel and FIQ state
2665 + * @hcd: Pointer to the dwc_otg_hcd struct
2666 + * @qh: Pointer to the endpoint's queue head
2667 + *
2668 + * This overrides the dwc_otg driver's normal method of queueing a transaction.
2669 + * Called from dwc_otg_hcd_queue_transactions(), this performs specific setup
2670 + * for the nominated host channel.
2671 + *
2672 + * For periodic transfers, it also peeks at the FIQ state to see if an immediate
2673 + * start is possible. If not, then the FIQ is left to start the transfer.
2674 + */
2675 +int fiq_fsm_queue_split_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
2676 {
2677 - uint32_t hub_addr, port_addr;
2678 + int start_immediate = 1, i;
2679 + hfnum_data_t hfnum;
2680 + dwc_hc_t *hc = qh->channel;
2681 + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
2682 + /* Program HC registers, setup FIQ_state, examine FIQ if periodic, start transfer (not if uframe 5) */
2683 + int hub_addr, port_addr, frame, uframe;
2684 + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
2685
2686 - if(!fiq_split_enable)
2687 - return;
2688 + if (st->fsm != FIQ_PASSTHROUGH)
2689 + return 0;
2690 + st->nr_errors = 0;
2691
2692 - hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
2693 + st->hcchar_copy.d32 = 0;
2694 + st->hcchar_copy.b.mps = hc->max_packet;
2695 + st->hcchar_copy.b.epdir = hc->ep_is_in;
2696 + st->hcchar_copy.b.devaddr = hc->dev_addr;
2697 + st->hcchar_copy.b.epnum = hc->ep_num;
2698 + st->hcchar_copy.b.eptype = hc->ep_type;
2699 + if (hc->ep_type & 0x1) {
2700 + if (hc->ep_is_in)
2701 + st->hcchar_copy.b.multicnt = 3;
2702 + else
2703 + /* Docs say set this to 1, but driver sets to 0! */
2704 + st->hcchar_copy.b.multicnt = 0;
2705 + } else {
2706 + st->hcchar_copy.b.multicnt = 1;
2707 + st->hcchar_copy.b.oddfrm = 0;
2708 + }
2709 + st->hcchar_copy.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW) ? 1 : 0;
2710 + /* Enable the channel later as a final register write. */
2711
2712 - hcd->hub_port[hub_addr] &= ~(1 << port_addr);
2713 -#ifdef FIQ_DEBUG
2714 - hcd->hub_port_alloc[hub_addr * 16 + port_addr] = -1;
2715 -#endif
2716 - fiq_print(FIQDBG_PORTHUB, "H%dP%d:RO%d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
2717 + st->hcsplt_copy.d32 = 0;
2718 + if(qh->do_split) {
2719 + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
2720 + st->hcsplt_copy.b.compsplt = 0;
2721 + st->hcsplt_copy.b.spltena = 1;
2722 + // XACTPOS is for isoc-out only but needs initialising anyway.
2723 + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_ALL;
2724 + if((qh->ep_type == DWC_OTG_EP_TYPE_ISOC) && (!qh->ep_is_in)) {
2725 + /* For packetsize 0 < L < 188, ISOC_XACTPOS_ALL.
2726 + * for longer than this, ISOC_XACTPOS_BEGIN and the FIQ
2727 + * will update as necessary.
2728 + */
2729 + if (hc->xfer_len > 188) {
2730 + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_BEGIN;
2731 + }
2732 + }
2733 + st->hcsplt_copy.b.hubaddr = (uint8_t) hub_addr;
2734 + st->hcsplt_copy.b.prtaddr = (uint8_t) port_addr;
2735 + st->hub_addr = hub_addr;
2736 + st->port_addr = port_addr;
2737 + }
2738 +
2739 + st->hctsiz_copy.d32 = 0;
2740 + st->hctsiz_copy.b.dopng = 0;
2741 + st->hctsiz_copy.b.pid = hc->data_pid_start;
2742 +
2743 + if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
2744 + hc->xfer_len = hc->max_packet;
2745 + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
2746 + hc->xfer_len = 188;
2747 + }
2748 + st->hctsiz_copy.b.xfersize = hc->xfer_len;
2749
2750 + st->hctsiz_copy.b.pktcnt = 1;
2751 +
2752 + if (hc->ep_type & 0x1) {
2753 + /*
2754 + * For potentially multi-packet transfers, must use the DMA bounce buffers. For IN transfers,
2755 + * the DMA address is the address of the first 188byte slot buffer in the bounce buffer array.
2756 + * For multi-packet OUT transfers, we need to copy the data into the bounce buffer array so the FIQ can punt
2757 + * the right address out as necessary. hc->xfer_buff and hc->xfer_len have already been set
2758 + * in assign_and_init_hc(), but this is for the eventual transaction completion only. The FIQ
2759 + * must not touch internal driver state.
2760 + */
2761 + if(!fiq_fsm_setup_periodic_dma(hcd, st, qh)) {
2762 + if (hc->align_buff) {
2763 + st->hcdma_copy.d32 = hc->align_buff;
2764 + } else {
2765 + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
2766 + }
2767 + }
2768 + } else {
2769 + if (hc->align_buff) {
2770 + st->hcdma_copy.d32 = hc->align_buff;
2771 + } else {
2772 + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
2773 + }
2774 + }
2775 + /* The FIQ depends upon no other interrupts being enabled except channel halt.
2776 + * Fixup channel interrupt mask. */
2777 + st->hcintmsk_copy.d32 = 0;
2778 + st->hcintmsk_copy.b.chhltd = 1;
2779 + st->hcintmsk_copy.b.ahberr = 1;
2780 +
2781 + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
2782 + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
2783 + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
2784 + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
2785 + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
2786 +
2787 + local_fiq_disable();
2788 + mb();
2789 +
2790 + if (hc->ep_type & 0x1) {
2791 + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
2792 + frame = (hfnum.b.frnum & ~0x7) >> 3;
2793 + uframe = hfnum.b.frnum & 0x7;
2794 + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
2795 + /* Prevent queueing near EOF1. Bad things happen if a periodic
2796 + * split transaction is queued very close to EOF.
2797 + */
2798 + start_immediate = 0;
2799 + } else if (uframe == 5) {
2800 + start_immediate = 0;
2801 + } else if (hc->ep_type == UE_ISOCHRONOUS && !hc->ep_is_in) {
2802 + start_immediate = 0;
2803 + } else if (hc->ep_is_in && fiq_fsm_too_late(hcd->fiq_state, hc->hc_num)) {
2804 + start_immediate = 0;
2805 + } else {
2806 + /* Search through all host channels to determine if a transaction
2807 + * is currently in progress */
2808 + for (i = 0; i < hcd->core_if->core_params->host_channels; i++) {
2809 + if (i == hc->hc_num || hcd->fiq_state->channel[i].fsm == FIQ_PASSTHROUGH)
2810 + continue;
2811 + switch (hcd->fiq_state->channel[i].fsm) {
2812 + /* TT is reserved for channels that are in the middle of a periodic
2813 + * split transaction.
2814 + */
2815 + case FIQ_PER_SSPLIT_STARTED:
2816 + case FIQ_PER_CSPLIT_WAIT:
2817 + case FIQ_PER_CSPLIT_NYET1:
2818 + case FIQ_PER_CSPLIT_POLL:
2819 + case FIQ_PER_ISO_OUT_ACTIVE:
2820 + case FIQ_PER_ISO_OUT_LAST:
2821 + if (hcd->fiq_state->channel[i].hub_addr == hub_addr &&
2822 + hcd->fiq_state->channel[i].port_addr == port_addr) {
2823 + start_immediate = 0;
2824 + }
2825 + break;
2826 + default:
2827 + break;
2828 + }
2829 + if (!start_immediate)
2830 + break;
2831 + }
2832 + }
2833 + }
2834 + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d %01d", hc->hc_num, start_immediate);
2835 + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08d", hfnum.b.frrem);
2836 + //fiq_print(FIQDBG_INT, hcd->fiq_state, "H:%02dP:%02d", hub_addr, port_addr);
2837 + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
2838 + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
2839 + switch (hc->ep_type) {
2840 + case UE_CONTROL:
2841 + case UE_BULK:
2842 + st->fsm = FIQ_NP_SSPLIT_STARTED;
2843 + break;
2844 + case UE_ISOCHRONOUS:
2845 + if (hc->ep_is_in) {
2846 + if (start_immediate) {
2847 + st->fsm = FIQ_PER_SSPLIT_STARTED;
2848 + } else {
2849 + st->fsm = FIQ_PER_SSPLIT_QUEUED;
2850 + }
2851 + } else {
2852 + if (start_immediate) {
2853 + /* Single-isoc OUT packets don't require FIQ involvement */
2854 + if (st->nrpackets == 1) {
2855 + st->fsm = FIQ_PER_ISO_OUT_LAST;
2856 + } else {
2857 + st->fsm = FIQ_PER_ISO_OUT_ACTIVE;
2858 + }
2859 + } else {
2860 + st->fsm = FIQ_PER_ISO_OUT_PENDING;
2861 + }
2862 + }
2863 + break;
2864 + case UE_INTERRUPT:
2865 + if (start_immediate) {
2866 + st->fsm = FIQ_PER_SSPLIT_STARTED;
2867 + } else {
2868 + st->fsm = FIQ_PER_SSPLIT_QUEUED;
2869 + }
2870 + default:
2871 + break;
2872 + }
2873 + if (start_immediate) {
2874 + /* Set the oddfrm bit as close as possible to actual queueing */
2875 + frame = dwc_otg_hcd_get_frame_number(hcd);
2876 + st->expected_uframe = (frame + 1) & 0x3FFF;
2877 + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
2878 + st->hcchar_copy.b.chen = 1;
2879 + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
2880 + }
2881 + mb();
2882 + local_fiq_enable();
2883 + return 0;
2884 }
2885
2886
2887 @@ -1399,16 +1903,11 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
2888 {
2889 dwc_list_link_t *qh_ptr;
2890 dwc_otg_qh_t *qh;
2891 - dwc_otg_qtd_t *qtd;
2892 int num_channels;
2893 dwc_irqflags_t flags;
2894 dwc_spinlock_t *channel_lock = hcd->channel_lock;
2895 dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
2896
2897 -#ifdef DEBUG_SOF
2898 - DWC_DEBUGPL(DBG_HCD, " Select Transactions\n");
2899 -#endif
2900 -
2901 #ifdef DEBUG_HOST_CHANNELS
2902 last_sel_trans_num_per_scheduled = 0;
2903 last_sel_trans_num_nonper_scheduled = 0;
2904 @@ -1423,26 +1922,11 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
2905
2906 qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
2907
2908 - if(qh->do_split) {
2909 - qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
2910 - if(!(qh->ep_type == UE_ISOCHRONOUS &&
2911 - (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
2912 - qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END))) {
2913 - if(dwc_otg_hcd_allocate_port(hcd, qh))
2914 - {
2915 - qh_ptr = DWC_LIST_NEXT(qh_ptr);
2916 - g_next_sched_frame = dwc_frame_num_inc(dwc_otg_hcd_get_frame_number(hcd), 1);
2917 - continue;
2918 - }
2919 - }
2920 - }
2921 -
2922 if (microframe_schedule) {
2923 // Make sure we leave one channel for non periodic transactions.
2924 DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
2925 if (hcd->available_host_channels <= 1) {
2926 DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
2927 - if(qh->do_split) dwc_otg_hcd_release_port(hcd, qh);
2928 break;
2929 }
2930 hcd->available_host_channels--;
2931 @@ -1478,27 +1962,24 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
2932 !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
2933
2934 qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
2935 -
2936 /*
2937 * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
2938 * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
2939 * cheeky devices that just hold off using NAKs
2940 */
2941 - if (nak_holdoff_enable && qh->do_split) {
2942 - if (qh->nak_frame != 0xffff &&
2943 - dwc_full_frame_num(qh->nak_frame) ==
2944 - dwc_full_frame_num(dwc_otg_hcd_get_frame_number(hcd))) {
2945 - /*
2946 - * Revisit: Need to avoid trampling on periodic scheduling.
2947 - * Currently we are safe because g_np_count != g_np_sent whenever we hit this,
2948 - * but if this behaviour is changed then periodic endpoints will get a slower
2949 - * polling rate.
2950 - */
2951 - g_next_sched_frame = ((qh->nak_frame + 8) & ~7) & DWC_HFNUM_MAX_FRNUM;
2952 - qh_ptr = DWC_LIST_NEXT(qh_ptr);
2953 - continue;
2954 - } else {
2955 - qh->nak_frame = 0xffff;
2956 + if (nak_holdoff && qh->do_split) {
2957 + if (qh->nak_frame != 0xffff) {
2958 + uint16_t next_frame = dwc_frame_num_inc(qh->nak_frame, (qh->ep_type == UE_BULK) ? nak_holdoff : 8);
2959 + uint16_t frame = dwc_otg_hcd_get_frame_number(hcd);
2960 + if (dwc_frame_num_le(frame, next_frame)) {
2961 + if(dwc_frame_num_le(next_frame, hcd->fiq_state->next_sched_frame)) {
2962 + hcd->fiq_state->next_sched_frame = next_frame;
2963 + }
2964 + qh_ptr = DWC_LIST_NEXT(qh_ptr);
2965 + continue;
2966 + } else {
2967 + qh->nak_frame = 0xFFFF;
2968 + }
2969 }
2970 }
2971
2972 @@ -1527,12 +2008,31 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
2973 &qh->qh_list_entry);
2974 DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
2975
2976 - g_np_sent++;
2977
2978 if (!microframe_schedule)
2979 hcd->non_periodic_channels++;
2980 }
2981 -
2982 + /* we moved a non-periodic QH to the active schedule. If the inactive queue is empty,
2983 + * stop the FIQ from kicking us. We could potentially still have elements here if we
2984 + * ran out of host channels.
2985 + */
2986 + if (fiq_enable) {
2987 + if (DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive)) {
2988 + hcd->fiq_state->kick_np_queues = 0;
2989 + } else {
2990 + /* For each entry remaining in the NP inactive queue,
2991 + * if this a NAK'd retransmit then don't set the kick flag.
2992 + */
2993 + if(nak_holdoff) {
2994 + DWC_LIST_FOREACH(qh_ptr, &hcd->non_periodic_sched_inactive) {
2995 + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
2996 + if (qh->nak_frame == 0xFFFF) {
2997 + hcd->fiq_state->kick_np_queues = 1;
2998 + }
2999 + }
3000 + }
3001 + }
3002 + }
3003 if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
3004 ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
3005
3006 @@ -1577,6 +2077,12 @@ static int queue_transaction(dwc_otg_hcd
3007 hc->qh->ping_state = 0;
3008 }
3009 } else if (!hc->xfer_started) {
3010 + if (fiq_fsm_enable && hc->error_state) {
3011 + hcd->fiq_state->channel[hc->hc_num].nr_errors =
3012 + DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list)->error_count;
3013 + hcd->fiq_state->channel[hc->hc_num].fsm =
3014 + FIQ_PASSTHROUGH_ERRORSTATE;
3015 + }
3016 dwc_otg_hc_start_transfer(hcd->core_if, hc);
3017 hc->qh->ping_state = 0;
3018 }
3019 @@ -1629,7 +2135,7 @@ static void process_periodic_channels(dw
3020 hptxsts_data_t tx_status;
3021 dwc_list_link_t *qh_ptr;
3022 dwc_otg_qh_t *qh;
3023 - int status;
3024 + int status = 0;
3025 int no_queue_space = 0;
3026 int no_fifo_space = 0;
3027
3028 @@ -1658,27 +2164,34 @@ static void process_periodic_channels(dw
3029
3030 // Do not send a split start transaction any later than frame .6
3031 // Note, we have to schedule a periodic in .5 to make it go in .6
3032 - if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
3033 + if(fiq_fsm_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
3034 {
3035 qh_ptr = qh_ptr->next;
3036 - g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
3037 + hcd->fiq_state->next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
3038 continue;
3039 }
3040
3041 - /*
3042 - * Set a flag if we're queuing high-bandwidth in slave mode.
3043 - * The flag prevents any halts to get into the request queue in
3044 - * the middle of multiple high-bandwidth packets getting queued.
3045 - */
3046 - if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
3047 - hcd->core_if->queuing_high_bandwidth = 1;
3048 - }
3049 - status =
3050 - queue_transaction(hcd, qh->channel,
3051 - tx_status.b.ptxfspcavail);
3052 - if (status < 0) {
3053 - no_fifo_space = 1;
3054 - break;
3055 + if (fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
3056 + if (qh->do_split)
3057 + fiq_fsm_queue_split_transaction(hcd, qh);
3058 + else
3059 + fiq_fsm_queue_isoc_transaction(hcd, qh);
3060 + } else {
3061 +
3062 + /*
3063 + * Set a flag if we're queueing high-bandwidth in slave mode.
3064 + * The flag prevents any halts to get into the request queue in
3065 + * the middle of multiple high-bandwidth packets getting queued.
3066 + */
3067 + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
3068 + hcd->core_if->queuing_high_bandwidth = 1;
3069 + }
3070 + status = queue_transaction(hcd, qh->channel,
3071 + tx_status.b.ptxfspcavail);
3072 + if (status < 0) {
3073 + no_fifo_space = 1;
3074 + break;
3075 + }
3076 }
3077
3078 /*
3079 @@ -1795,25 +2308,19 @@ static void process_non_periodic_channel
3080 qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
3081 qh_list_entry);
3082
3083 - // Do not send a split start transaction any later than frame .5
3084 - // non periodic transactions will start immediately in this uframe
3085 - if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
3086 - {
3087 - g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
3088 - break;
3089 - }
3090 -
3091 - status =
3092 - queue_transaction(hcd, qh->channel,
3093 - tx_status.b.nptxfspcavail);
3094 + if(fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
3095 + fiq_fsm_queue_split_transaction(hcd, qh);
3096 + } else {
3097 + status = queue_transaction(hcd, qh->channel,
3098 + tx_status.b.nptxfspcavail);
3099
3100 - if (status > 0) {
3101 - more_to_do = 1;
3102 - } else if (status < 0) {
3103 - no_fifo_space = 1;
3104 - break;
3105 + if (status > 0) {
3106 + more_to_do = 1;
3107 + } else if (status < 0) {
3108 + no_fifo_space = 1;
3109 + break;
3110 + }
3111 }
3112 -
3113 /* Advance to next QH, skipping start-of-list entry. */
3114 hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
3115 if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
3116 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
3117 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
3118 @@ -40,6 +40,8 @@
3119 #include "dwc_otg_core_if.h"
3120 #include "dwc_list.h"
3121 #include "dwc_otg_cil.h"
3122 +#include "dwc_otg_fiq_fsm.h"
3123 +
3124
3125 /**
3126 * @file
3127 @@ -585,6 +587,12 @@ struct dwc_otg_hcd {
3128 /** Frame List DMA address */
3129 dma_addr_t frame_list_dma;
3130
3131 + struct fiq_stack *fiq_stack;
3132 + struct fiq_state *fiq_state;
3133 +
3134 + /** Virtual address for split transaction DMA bounce buffers */
3135 + struct fiq_dma_blob *fiq_dmab;
3136 +
3137 #ifdef DEBUG
3138 uint32_t frrem_samples;
3139 uint64_t frrem_accum;
3140 @@ -615,6 +623,9 @@ extern void dwc_otg_hcd_queue_transactio
3141 int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
3142 void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
3143
3144 +extern int fiq_fsm_queue_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
3145 +extern int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh);
3146 +extern void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num);
3147
3148 /** @} */
3149
3150 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
3151 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
3152 @@ -34,7 +34,6 @@
3153
3154 #include "dwc_otg_hcd.h"
3155 #include "dwc_otg_regs.h"
3156 -#include "dwc_otg_mphi_fix.h"
3157
3158 #include <linux/jiffies.h>
3159 #include <mach/hardware.h>
3160 @@ -47,33 +46,8 @@ extern bool microframe_schedule;
3161 * This file contains the implementation of the HCD Interrupt handlers.
3162 */
3163
3164 -/*
3165 - * Some globals to communicate between the FIQ and INTERRUPT
3166 - */
3167 -
3168 -void * dummy_send;
3169 -mphi_regs_t c_mphi_regs;
3170 -volatile void *dwc_regs_base;
3171 int fiq_done, int_done;
3172
3173 -gintsts_data_t gintsts_saved = {.d32 = 0};
3174 -hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
3175 -hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
3176 -int split_out_xfersize[MAX_EPS_CHANNELS];
3177 -haint_data_t haint_saved;
3178 -
3179 -int g_next_sched_frame, g_np_count, g_np_sent;
3180 -static int mphi_int_count = 0 ;
3181 -
3182 -hcchar_data_t nak_hcchar;
3183 -hctsiz_data_t nak_hctsiz;
3184 -hcsplt_data_t nak_hcsplt;
3185 -int nak_count;
3186 -
3187 -int complete_sched[MAX_EPS_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
3188 -int split_start_frame[MAX_EPS_CHANNELS];
3189 -int queued_port[MAX_EPS_CHANNELS];
3190 -
3191 #ifdef FIQ_DEBUG
3192 char buffer[1000*16];
3193 int wptr;
3194 @@ -83,12 +57,10 @@ void notrace _fiq_print(FIQDBG_T dbg_lvl
3195 va_list args;
3196 char text[17];
3197 hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
3198 - unsigned long flags;
3199
3200 - local_irq_save(flags);
3201 - local_fiq_disable();
3202 if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
3203 {
3204 + local_fiq_disable();
3205 snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
3206 va_start(args, fmt);
3207 vsnprintf(text+8, 9, fmt, args);
3208 @@ -96,410 +68,21 @@ void notrace _fiq_print(FIQDBG_T dbg_lvl
3209
3210 memcpy(buffer + wptr, text, 16);
3211 wptr = (wptr + 16) % sizeof(buffer);
3212 + local_fiq_enable();
3213 }
3214 - local_irq_restore(flags);
3215 }
3216 #endif
3217
3218 -void notrace fiq_queue_request(int channel, int odd_frame)
3219 -{
3220 - hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
3221 - hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
3222 - hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10) };
3223 -
3224 - if(hcsplt.b.spltena == 0)
3225 - {
3226 - fiq_print(FIQDBG_ERR, "SPLTENA ");
3227 - BUG();
3228 - }
3229 -
3230 - if(hcchar.b.epdir == 1)
3231 - {
3232 - fiq_print(FIQDBG_SCHED, "IN Ch %d", channel);
3233 - }
3234 - else
3235 - {
3236 - hctsiz.b.xfersize = 0;
3237 - fiq_print(FIQDBG_SCHED, "OUT Ch %d", channel);
3238 - }
3239 - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x10), hctsiz.d32);
3240 -
3241 - hcsplt.b.compsplt = 1;
3242 - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x4), hcsplt.d32);
3243 -
3244 - // Send the Split complete
3245 - hcchar.b.chen = 1;
3246 - hcchar.b.oddfrm = odd_frame ? 1 : 0;
3247 -
3248 - // Post this for transmit on the next frame for periodic or this frame for non-periodic
3249 - fiq_print(FIQDBG_SCHED, "SND_%s", odd_frame ? "ODD " : "EVEN");
3250 -
3251 - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x0), hcchar.d32);
3252 -}
3253 -
3254 -static int last_sof = -1;
3255 -
3256 -/*
3257 -** Function to handle the start of frame interrupt, choose whether we need to do anything and
3258 -** therefore trigger the main interrupt
3259 -**
3260 -** returns int != 0 - interrupt has been handled
3261 -*/
3262 -int diff;
3263 -
3264 -int notrace fiq_sof_handle(hfnum_data_t hfnum)
3265 -{
3266 - int handled = 0;
3267 - int i;
3268 -
3269 - // Just check that once we're running we don't miss a SOF
3270 - /*if(last_sof != -1 && (hfnum.b.frnum != ((last_sof + 1) & 0x3fff)))
3271 - {
3272 - fiq_print(FIQDBG_ERR, "LASTSOF ");
3273 - fiq_print(FIQDBG_ERR, "%4d%d ", last_sof / 8, last_sof & 7);
3274 - fiq_print(FIQDBG_ERR, "%4d%d ", hfnum.b.frnum / 8, hfnum.b.frnum & 7);
3275 - BUG();
3276 - }*/
3277 -
3278 - // Only start remembering the last sof when the interrupt has been
3279 - // enabled (we don't check the mask to come in here...)
3280 - if(last_sof != -1 || FIQ_READ(dwc_regs_base + 0x18) & (1<<3))
3281 - last_sof = hfnum.b.frnum;
3282 -
3283 - for(i = 0; i < MAX_EPS_CHANNELS; i++)
3284 - {
3285 - if(complete_sched[i] != -1)
3286 - {
3287 - if(complete_sched[i] <= hfnum.b.frnum || (complete_sched[i] > 0x3f00 && hfnum.b.frnum < 0xf0))
3288 - {
3289 - fiq_queue_request(i, hfnum.b.frnum & 1);
3290 - complete_sched[i] = -1;
3291 - }
3292 - }
3293 -
3294 - if(complete_sched[i] != -1)
3295 - {
3296 - // This is because we've seen a split complete occur with no start...
3297 - // most likely because missed the complete 0x3fff frames ago!
3298 -
3299 - diff = (hfnum.b.frnum + 0x3fff - complete_sched[i]) & 0x3fff ;
3300 - if(diff > 32 && diff < 0x3f00)
3301 - {
3302 - fiq_print(FIQDBG_ERR, "SPLTMISS");
3303 - BUG();
3304 - }
3305 - }
3306 - }
3307 -
3308 - if(g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
3309 - {
3310 - /*
3311 - * If np_count != np_sent that means we need to queue non-periodic (bulk) packets this packet
3312 - * g_next_sched_frame is the next frame we have periodic packets for
3313 - *
3314 - * if neither of these are required for this frame then just clear the interrupt
3315 - */
3316 - handled = 1;
3317 -
3318 - }
3319 -
3320 - return handled;
3321 -}
3322 -
3323 -int notrace port_id(hcsplt_data_t hcsplt)
3324 -{
3325 - return hcsplt.b.prtaddr + (hcsplt.b.hubaddr << 8);
3326 -}
3327 -
3328 -int notrace fiq_hcintr_handle(int channel, hfnum_data_t hfnum)
3329 -{
3330 - hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
3331 - hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
3332 - hcint_data_t hcint = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x8) };
3333 - hcintmsk_data_t hcintmsk = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0xc) };
3334 - hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10)};
3335 -
3336 - hcint_saved[channel].d32 |= hcint.d32;
3337 - hcintmsk_saved[channel].d32 = hcintmsk.d32;
3338 -
3339 - if(hcsplt.b.spltena)
3340 - {
3341 - fiq_print(FIQDBG_PORTHUB, "ph: %4x", port_id(hcsplt));
3342 - if(hcint.b.chhltd)
3343 - {
3344 - fiq_print(FIQDBG_SCHED, "CH HLT %d", channel);
3345 - fiq_print(FIQDBG_SCHED, "%08x", hcint_saved[channel]);
3346 - }
3347 - if(hcint.b.stall || hcint.b.xacterr || hcint.b.bblerr || hcint.b.frmovrun || hcint.b.datatglerr)
3348 - {
3349 - queued_port[channel] = 0;
3350 - fiq_print(FIQDBG_ERR, "CHAN ERR");
3351 - }
3352 - if(hcint.b.xfercomp)
3353 - {
3354 - // Clear the port allocation and transmit anything also on this port
3355 - queued_port[channel] = 0;
3356 - fiq_print(FIQDBG_SCHED, "XFERCOMP");
3357 - }
3358 - if(hcint.b.nak)
3359 - {
3360 - queued_port[channel] = 0;
3361 - fiq_print(FIQDBG_SCHED, "NAK");
3362 - }
3363 - if(hcint.b.ack && !hcsplt.b.compsplt)
3364 - {
3365 - int i;
3366 -
3367 - // Do not complete isochronous out transactions
3368 - if(hcchar.b.eptype == 1 && hcchar.b.epdir == 0)
3369 - {
3370 - queued_port[channel] = 0;
3371 - fiq_print(FIQDBG_SCHED, "ISOC_OUT");
3372 - }
3373 - else
3374 - {
3375 - // Make sure we check the port / hub combination that we sent this split on.
3376 - // Do not queue a second request to the same port
3377 - for(i = 0; i < MAX_EPS_CHANNELS; i++)
3378 - {
3379 - if(port_id(hcsplt) == queued_port[i])
3380 - {
3381 - fiq_print(FIQDBG_ERR, "PORTERR ");
3382 - //BUG();
3383 - }
3384 - }
3385 -
3386 - split_start_frame[channel] = (hfnum.b.frnum + 1) & ~7;
3387 -
3388 - // Note, the size of an OUT is in the start split phase, not
3389 - // the complete split
3390 - split_out_xfersize[channel] = hctsiz.b.xfersize;
3391 -
3392 - hcint_saved[channel].b.chhltd = 0;
3393 - hcint_saved[channel].b.ack = 0;
3394 -
3395 - queued_port[channel] = port_id(hcsplt);
3396 -
3397 - if(hcchar.b.eptype & 1)
3398 - {
3399 - // Send the periodic complete in the same oddness frame as the ACK went...
3400 - fiq_queue_request(channel, !(hfnum.b.frnum & 1));
3401 - // complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
3402 - }
3403 - else
3404 - {
3405 - // Schedule the split complete to occur later
3406 - complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 2);
3407 - fiq_print(FIQDBG_SCHED, "ACK%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
3408 - }
3409 - }
3410 - }
3411 - if(hcint.b.nyet)
3412 - {
3413 - fiq_print(FIQDBG_ERR, "NYETERR1");
3414 - //BUG();
3415 - // Can transmit a split complete up to uframe .0 of the next frame
3416 - if(hfnum.b.frnum <= dwc_frame_num_inc(split_start_frame[channel], 8))
3417 - {
3418 - // Send it next frame
3419 - if(hcchar.b.eptype & 1) // type 1 & 3 are interrupt & isoc
3420 - {
3421 - fiq_print(FIQDBG_SCHED, "NYT:SEND");
3422 - fiq_queue_request(channel, !(hfnum.b.frnum & 1));
3423 - }
3424 - else
3425 - {
3426 - // Schedule non-periodic access for next frame (the odd-even bit doesn't effect NP)
3427 - complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
3428 - fiq_print(FIQDBG_SCHED, "NYT%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
3429 - }
3430 - hcint_saved[channel].b.chhltd = 0;
3431 - hcint_saved[channel].b.nyet = 0;
3432 - }
3433 - else
3434 - {
3435 - queued_port[channel] = 0;
3436 - fiq_print(FIQDBG_ERR, "NYETERR2");
3437 - //BUG();
3438 - }
3439 - }
3440 - }
3441 - else
3442 - {
3443 - /*
3444 - * If we have any of NAK, ACK, Datatlgerr active on a
3445 - * non-split channel, the sole reason is to reset error
3446 - * counts for a previously broken transaction. The FIQ
3447 - * will thrash on NAK IN and ACK OUT in particular so
3448 - * handle it "once" and allow the IRQ to do the rest.
3449 - */
3450 - hcint.d32 &= hcintmsk.d32;
3451 - if(hcint.b.nak)
3452 - {
3453 - hcintmsk.b.nak = 0;
3454 - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0xc), hcintmsk.d32);
3455 - }
3456 - if (hcint.b.ack)
3457 - {
3458 - hcintmsk.b.ack = 0;
3459 - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0xc), hcintmsk.d32);
3460 - }
3461 - }
3462 -
3463 - // Clear the interrupt, this will also clear the HAINT bit
3464 - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x8), hcint.d32);
3465 - return hcint_saved[channel].d32 == 0;
3466 -}
3467 -
3468 -gintsts_data_t gintsts;
3469 -gintmsk_data_t gintmsk;
3470 -// triggered: The set of interrupts that were triggered
3471 -// handled: The set of interrupts that have been handled (no IRQ is
3472 -// required)
3473 -// keep: The set of interrupts we want to keep unmasked even though we
3474 -// want to trigger an IRQ to handle it (SOF and HCINTR)
3475 -gintsts_data_t triggered, handled, keep;
3476 -hfnum_data_t hfnum;
3477 -
3478 -void __attribute__ ((naked)) notrace dwc_otg_hcd_handle_fiq(void)
3479 -{
3480 -
3481 - /* entry takes care to store registers we will be treading on here */
3482 - asm __volatile__ (
3483 - "mov ip, sp ;"
3484 - /* stash FIQ and normal regs */
3485 - "stmdb sp!, {r0-r12, lr};"
3486 - /* !! THIS SETS THE FRAME, adjust to > sizeof locals */
3487 - "sub fp, ip, #512 ;"
3488 - );
3489 -
3490 - // Cannot put local variables at the beginning of the function
3491 - // because otherwise 'C' will play with the stack pointer. any locals
3492 - // need to be inside the following block
3493 - do
3494 - {
3495 - fiq_done++;
3496 - gintsts.d32 = FIQ_READ(dwc_regs_base + 0x14);
3497 - gintmsk.d32 = FIQ_READ(dwc_regs_base + 0x18);
3498 - hfnum.d32 = FIQ_READ(dwc_regs_base + 0x408);
3499 - triggered.d32 = gintsts.d32 & gintmsk.d32;
3500 - handled.d32 = 0;
3501 - keep.d32 = 0;
3502 - fiq_print(FIQDBG_INT, "FIQ ");
3503 - fiq_print(FIQDBG_INT, "%08x", gintsts.d32);
3504 - fiq_print(FIQDBG_INT, "%08x", gintmsk.d32);
3505 - if(gintsts.d32)
3506 - {
3507 - // If port enabled
3508 - if((FIQ_READ(dwc_regs_base + 0x440) & 0xf) == 0x5)
3509 - {
3510 - if(gintsts.b.sofintr)
3511 - {
3512 - if(fiq_sof_handle(hfnum))
3513 - {
3514 - handled.b.sofintr = 1; /* Handled in FIQ */
3515 - }
3516 - else
3517 - {
3518 - /* Keer interrupt unmasked */
3519 - keep.b.sofintr = 1;
3520 - }
3521 - {
3522 - // Need to make sure the read and clearing of the SOF interrupt is as close as possible to avoid the possibility of missing
3523 - // a start of frame interrupt
3524 - gintsts_data_t gintsts = { .b.sofintr = 1 };
3525 - FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
3526 - }
3527 - }
3528 -
3529 - if(fiq_split_enable && gintsts.b.hcintr)
3530 - {
3531 - int i;
3532 - haint_data_t haint;
3533 - haintmsk_data_t haintmsk;
3534 -
3535 - haint.d32 = FIQ_READ(dwc_regs_base + 0x414);
3536 - haintmsk.d32 = FIQ_READ(dwc_regs_base + 0x418);
3537 - haint.d32 &= haintmsk.d32;
3538 - haint_saved.d32 |= haint.d32;
3539 -
3540 - fiq_print(FIQDBG_INT, "hcintr");
3541 - fiq_print(FIQDBG_INT, "%08x", FIQ_READ(dwc_regs_base + 0x414));
3542 -
3543 - // Go through each channel that has an enabled interrupt
3544 - for(i = 0; i < 16; i++)
3545 - if((haint.d32 >> i) & 1)
3546 - if(fiq_hcintr_handle(i, hfnum))
3547 - haint_saved.d32 &= ~(1 << i); /* this was handled */
3548 -
3549 - /* If we've handled all host channel interrupts then don't trigger the interrupt */
3550 - if(haint_saved.d32 == 0)
3551 - {
3552 - handled.b.hcintr = 1;
3553 - }
3554 - else
3555 - {
3556 - /* Make sure we keep the channel interrupt unmasked when triggering the IRQ */
3557 - keep.b.hcintr = 1;
3558 - }
3559 -
3560 - {
3561 - gintsts_data_t gintsts = { .b.hcintr = 1 };
3562 -
3563 - // Always clear the channel interrupt
3564 - FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
3565 - }
3566 - }
3567 - }
3568 - else
3569 - {
3570 - last_sof = -1;
3571 - }
3572 - }
3573 -
3574 - // Mask out the interrupts triggered - those handled - don't mask out the ones we want to keep
3575 - gintmsk.d32 = keep.d32 | (gintmsk.d32 & ~(triggered.d32 & ~handled.d32));
3576 - // Save those that were triggered but not handled
3577 - gintsts_saved.d32 |= triggered.d32 & ~handled.d32;
3578 - FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
3579 -
3580 - // Clear and save any unhandled interrupts and trigger the interrupt
3581 - if(gintsts_saved.d32)
3582 - {
3583 - /* To enable the MPHI interrupt (INT 32)
3584 - */
3585 - FIQ_WRITE( c_mphi_regs.outdda, (int) dummy_send);
3586 - FIQ_WRITE( c_mphi_regs.outddb, (1 << 29));
3587 -
3588 - mphi_int_count++;
3589 - }
3590 - }
3591 - while(0);
3592 -
3593 - mb();
3594 -
3595 - /* exit back to normal mode restoring everything */
3596 - asm __volatile__ (
3597 - /* return FIQ regs back to pristine state
3598 - * and get normal regs back
3599 - */
3600 - "ldmia sp!, {r0-r12, lr};"
3601 -
3602 - /* return */
3603 - "subs pc, lr, #4;"
3604 - );
3605 -}
3606 -
3607 /** This function handles interrupts for the HCD. */
3608 int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
3609 {
3610 int retval = 0;
3611 static int last_time;
3612 -
3613 dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
3614 gintsts_data_t gintsts;
3615 gintmsk_data_t gintmsk;
3616 hfnum_data_t hfnum;
3617 + haintmsk_data_t haintmsk;
3618
3619 #ifdef DEBUG
3620 dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
3621 @@ -516,15 +99,29 @@ int32_t dwc_otg_hcd_handle_intr(dwc_otg_
3622 DWC_SPINLOCK(dwc_otg_hcd->lock);
3623 /* Check if HOST Mode */
3624 if (dwc_otg_is_host_mode(core_if)) {
3625 - local_fiq_disable();
3626 - gintmsk.d32 |= gintsts_saved.d32;
3627 - gintsts.d32 |= gintsts_saved.d32;
3628 - gintsts_saved.d32 = 0;
3629 - local_fiq_enable();
3630 + if (fiq_enable) {
3631 + local_fiq_disable();
3632 + /* Pull in from the FIQ's disabled mask */
3633 + gintmsk.d32 = gintmsk.d32 | ~(dwc_otg_hcd->fiq_state->gintmsk_saved.d32);
3634 + dwc_otg_hcd->fiq_state->gintmsk_saved.d32 = ~0;
3635 + }
3636 +
3637 + if (fiq_fsm_enable && ( 0x0000FFFF & ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint))) {
3638 + gintsts.b.hcintr = 1;
3639 + }
3640 +
3641 + /* Danger will robinson: fake a SOF if necessary */
3642 + if (fiq_fsm_enable && (dwc_otg_hcd->fiq_state->gintmsk_saved.b.sofintr == 1)) {
3643 + gintsts.b.sofintr = 1;
3644 + }
3645 + gintsts.d32 &= gintmsk.d32;
3646 +
3647 + if (fiq_enable)
3648 + local_fiq_enable();
3649 +
3650 if (!gintsts.d32) {
3651 goto exit_handler_routine;
3652 }
3653 - gintsts.d32 &= gintmsk.d32;
3654
3655 #ifdef DEBUG
3656 // We should be OK doing this because the common interrupts should already have been serviced
3657 @@ -544,12 +141,7 @@ int32_t dwc_otg_hcd_handle_intr(dwc_otg_
3658 gintsts.d32, core_if);
3659 #endif
3660 hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
3661 - if (gintsts.b.sofintr && g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
3662 - {
3663 - /* Note, we should never get here if the FIQ is doing it's job properly*/
3664 - retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
3665 - }
3666 - else if (gintsts.b.sofintr) {
3667 + if (gintsts.b.sofintr) {
3668 retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
3669 }
3670
3671 @@ -604,37 +196,43 @@ int32_t dwc_otg_hcd_handle_intr(dwc_otg_
3672 }
3673
3674 exit_handler_routine:
3675 -
3676 - if (fiq_fix_enable)
3677 - {
3678 + if (fiq_enable) {
3679 + gintmsk_data_t gintmsk_new;
3680 + haintmsk_data_t haintmsk_new;
3681 local_fiq_disable();
3682 - // Make sure that we don't clear the interrupt if we've still got pending work to do
3683 - if(gintsts_saved.d32 == 0)
3684 - {
3685 - /* Clear the MPHI interrupt */
3686 - DWC_WRITE_REG32(c_mphi_regs.intstat, (1<<16));
3687 - if (mphi_int_count >= 60)
3688 - {
3689 - DWC_WRITE_REG32(c_mphi_regs.ctrl, ((1<<31) + (1<<16)));
3690 - while(!(DWC_READ_REG32(c_mphi_regs.ctrl) & (1 << 17)))
3691 - ;
3692 - DWC_WRITE_REG32(c_mphi_regs.ctrl, (1<<31));
3693 - mphi_int_count = 0;
3694 - }
3695 - int_done++;
3696 - }
3697 -
3698 - // Unmask handled interrupts
3699 - FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
3700 - //DWC_MODIFY_REG32((uint32_t *)IO_ADDRESS(USB_BASE + 0x8), 0 , 1);
3701 + gintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->gintmsk_saved.d32;
3702 + if(fiq_fsm_enable)
3703 + haintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->haintmsk_saved.d32;
3704 + else
3705 + haintmsk_new.d32 = 0x0000FFFF;
3706
3707 + /* The FIQ could have sneaked another interrupt in. If so, don't clear MPHI */
3708 + if ((gintmsk_new.d32 == ~0) && (haintmsk_new.d32 == 0x0000FFFF)) {
3709 + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.intstat, (1<<16));
3710 + if (dwc_otg_hcd->fiq_state->mphi_int_count >= 50) {
3711 + fiq_print(FIQDBG_INT, dwc_otg_hcd->fiq_state, "MPHI CLR");
3712 + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, ((1<<31) + (1<<16)));
3713 + while (!(DWC_READ_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & (1 << 17)))
3714 + ;
3715 + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, (1<<31));
3716 + dwc_otg_hcd->fiq_state->mphi_int_count = 0;
3717 + }
3718 + int_done++;
3719 + }
3720 + haintmsk.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
3721 + /* Re-enable interrupts that the FIQ masked (first time round) */
3722 + FIQ_WRITE(dwc_otg_hcd->fiq_state->dwc_regs_base + GINTMSK, gintmsk.d32);
3723 local_fiq_enable();
3724
3725 - if((jiffies / HZ) > last_time)
3726 - {
3727 + if ((jiffies / HZ) > last_time) {
3728 + //dwc_otg_qh_t *qh;
3729 + //dwc_list_link_t *cur;
3730 /* Once a second output the fiq and irq numbers, useful for debug */
3731 last_time = jiffies / HZ;
3732 - DWC_DEBUGPL(DBG_USER, "int_done = %d fiq_done = %d\n", int_done, fiq_done);
3733 + // DWC_WARN("np_kick=%d AHC=%d sched_frame=%d cur_frame=%d int_done=%d fiq_done=%d",
3734 + // dwc_otg_hcd->fiq_state->kick_np_queues, dwc_otg_hcd->available_host_channels,
3735 + // dwc_otg_hcd->fiq_state->next_sched_frame, hfnum.b.frnum, int_done, dwc_otg_hcd->fiq_state->fiq_done);
3736 + //printk(KERN_WARNING "Periodic queues:\n");
3737 }
3738 }
3739
3740 @@ -686,6 +284,7 @@ static inline void track_missed_sofs(uin
3741 int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
3742 {
3743 hfnum_data_t hfnum;
3744 + gintsts_data_t gintsts = { .d32 = 0 };
3745 dwc_list_link_t *qh_entry;
3746 dwc_otg_qh_t *qh;
3747 dwc_otg_transaction_type_e tr_type;
3748 @@ -732,8 +331,8 @@ int32_t dwc_otg_hcd_handle_sof_intr(dwc_
3749 }
3750 }
3751 }
3752 -
3753 - g_next_sched_frame = next_sched_frame;
3754 + if (fiq_enable)
3755 + hcd->fiq_state->next_sched_frame = next_sched_frame;
3756
3757 tr_type = dwc_otg_hcd_select_transactions(hcd);
3758 if (tr_type != DWC_OTG_TRANSACTION_NONE) {
3759 @@ -741,10 +340,11 @@ int32_t dwc_otg_hcd_handle_sof_intr(dwc_
3760 did_something = 1;
3761 }
3762
3763 - /* Clear interrupt */
3764 - gintsts.b.sofintr = 1;
3765 - DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
3766 -
3767 + /* Clear interrupt - but do not trample on the FIQ sof */
3768 + if (!fiq_fsm_enable) {
3769 + gintsts.b.sofintr = 1;
3770 + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
3771 + }
3772 return 1;
3773 }
3774
3775 @@ -1020,19 +620,21 @@ int32_t dwc_otg_hcd_handle_hc_intr(dwc_o
3776 {
3777 int i;
3778 int retval = 0;
3779 - haint_data_t haint;
3780 + haint_data_t haint = { .d32 = 0 } ;
3781
3782 /* Clear appropriate bits in HCINTn to clear the interrupt bit in
3783 * GINTSTS */
3784
3785 - haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
3786 + if (!fiq_fsm_enable)
3787 + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
3788
3789 // Overwrite with saved interrupts from fiq handler
3790 - if(fiq_split_enable)
3791 + if(fiq_fsm_enable)
3792 {
3793 + /* check the mask? */
3794 local_fiq_disable();
3795 - haint.d32 = haint_saved.d32;
3796 - haint_saved.d32 = 0;
3797 + haint.b2.chint |= ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint);
3798 + dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
3799 local_fiq_enable();
3800 }
3801
3802 @@ -1076,9 +678,7 @@ static uint32_t get_actual_xfer_length(d
3803 *short_read = (hctsiz.b.xfersize != 0);
3804 }
3805 } else if (hc->qh->do_split) {
3806 - if(fiq_split_enable)
3807 - length = split_out_xfersize[hc->hc_num];
3808 - else
3809 + //length = split_out_xfersize[hc->hc_num];
3810 length = qtd->ssplit_out_xfer_count;
3811 } else {
3812 length = hc->xfer_len;
3813 @@ -1325,19 +925,17 @@ static void release_channel(dwc_otg_hcd_
3814 int free_qtd;
3815 dwc_irqflags_t flags;
3816 dwc_spinlock_t *channel_lock = hcd->channel_lock;
3817 -#ifdef FIQ_DEBUG
3818 - int endp = qtd->urb ? qtd->urb->pipe_info.ep_num : 0;
3819 -#endif
3820 +
3821 int hog_port = 0;
3822
3823 DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
3824 __func__, hc->hc_num, halt_status, hc->xfer_len);
3825
3826 - if(fiq_split_enable && hc->do_split) {
3827 + if(fiq_fsm_enable && hc->do_split) {
3828 if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
3829 if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
3830 hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
3831 - hog_port = 1;
3832 + hog_port = 0;
3833 }
3834 }
3835 }
3836 @@ -1394,6 +992,8 @@ cleanup:
3837 * function clears the channel interrupt enables and conditions, so
3838 * there's no need to clear the Channel Halted interrupt separately.
3839 */
3840 + if (fiq_fsm_enable && hcd->fiq_state->channel[hc->hc_num].fsm != FIQ_PASSTHROUGH)
3841 + dwc_otg_cleanup_fiq_channel(hcd, hc->hc_num);
3842 dwc_otg_hc_cleanup(hcd->core_if, hc);
3843 DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
3844
3845 @@ -1416,27 +1016,10 @@ cleanup:
3846
3847 DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
3848 hcd->available_host_channels++;
3849 - fiq_print(FIQDBG_PORTHUB, "AHC = %d ", hcd->available_host_channels);
3850 + fiq_print(FIQDBG_INT, hcd->fiq_state, "AHC = %d ", hcd->available_host_channels);
3851 DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
3852 }
3853
3854 - if(fiq_split_enable && hc->do_split)
3855 - {
3856 - if(!(hcd->hub_port[hc->hub_addr] & (1 << hc->port_addr)))
3857 - {
3858 - fiq_print(FIQDBG_ERR, "PRTNOTAL");
3859 - //BUG();
3860 - }
3861 - if(!hog_port && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC ||
3862 - hc->ep_type == DWC_OTG_EP_TYPE_INTR)) {
3863 - hcd->hub_port[hc->hub_addr] &= ~(1 << hc->port_addr);
3864 -#ifdef FIQ_DEBUG
3865 - hcd->hub_port_alloc[hc->hub_addr * 16 + hc->port_addr] = -1;
3866 -#endif
3867 - fiq_print(FIQDBG_PORTHUB, "H%dP%d:RR%d", hc->hub_addr, hc->port_addr, endp);
3868 - }
3869 - }
3870 -
3871 /* Try to queue more transfers now that there's a free channel. */
3872 tr_type = dwc_otg_hcd_select_transactions(hcd);
3873 if (tr_type != DWC_OTG_TRANSACTION_NONE) {
3874 @@ -1858,7 +1441,7 @@ static int32_t handle_hc_nak_intr(dwc_ot
3875 switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
3876 case UE_BULK:
3877 case UE_CONTROL:
3878 - if (nak_holdoff_enable)
3879 + if (nak_holdoff && qtd->qh->do_split)
3880 hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
3881 }
3882
3883 @@ -2074,7 +1657,7 @@ static int32_t handle_hc_nyet_intr(dwc_o
3884 // With the FIQ running we only ever see the failed NYET
3885 if (dwc_full_frame_num(frnum) !=
3886 dwc_full_frame_num(hc->qh->sched_frame) ||
3887 - fiq_split_enable) {
3888 + fiq_fsm_enable) {
3889 /*
3890 * No longer in the same full speed frame.
3891 * Treat this as a transaction error.
3892 @@ -2460,12 +2043,11 @@ static inline int halt_status_ok(dwc_otg
3893 static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
3894 dwc_hc_t * hc,
3895 dwc_otg_hc_regs_t * hc_regs,
3896 - dwc_otg_qtd_t * qtd,
3897 - hcint_data_t hcint,
3898 - hcintmsk_data_t hcintmsk)
3899 + dwc_otg_qtd_t * qtd)
3900 {
3901 int out_nak_enh = 0;
3902 -
3903 + hcint_data_t hcint;
3904 + hcintmsk_data_t hcintmsk;
3905 /* For core with OUT NAK enhancement, the flow for high-
3906 * speed CONTROL/BULK OUT is handled a little differently.
3907 */
3908 @@ -2495,11 +2077,9 @@ static void handle_hc_chhltd_intr_dma(dw
3909 }
3910
3911 /* Read the HCINTn register to determine the cause for the halt. */
3912 - if(!fiq_split_enable)
3913 - {
3914 - hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
3915 - hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
3916 - }
3917 +
3918 + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
3919 + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
3920
3921 if (hcint.b.xfercomp) {
3922 /** @todo This is here because of a possible hardware bug. Spec
3923 @@ -2624,15 +2204,13 @@ static void handle_hc_chhltd_intr_dma(dw
3924 static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
3925 dwc_hc_t * hc,
3926 dwc_otg_hc_regs_t * hc_regs,
3927 - dwc_otg_qtd_t * qtd,
3928 - hcint_data_t hcint,
3929 - hcintmsk_data_t hcintmsk)
3930 + dwc_otg_qtd_t * qtd)
3931 {
3932 DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
3933 "Channel Halted--\n", hc->hc_num);
3934
3935 if (hcd->core_if->dma_enable) {
3936 - handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd, hcint, hcintmsk);
3937 + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
3938 } else {
3939 #ifdef DEBUG
3940 if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
3941 @@ -2645,11 +2223,372 @@ static int32_t handle_hc_chhltd_intr(dwc
3942 return 1;
3943 }
3944
3945 +
3946 +/**
3947 + * dwc_otg_fiq_unmangle_isoc() - Update the iso_frame_desc structure on
3948 + * FIQ transfer completion
3949 + * @hcd: Pointer to dwc_otg_hcd struct
3950 + * @num: Host channel number
3951 + *
3952 + * 1. Un-mangle the status as recorded in each iso_frame_desc status
3953 + * 2. Copy it from the dwc_otg_urb into the real URB
3954 + */
3955 +void dwc_otg_fiq_unmangle_isoc(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
3956 +{
3957 + struct dwc_otg_hcd_urb *dwc_urb = qtd->urb;
3958 + int nr_frames = dwc_urb->packet_count;
3959 + int i;
3960 + hcint_data_t frame_hcint;
3961 +
3962 + for (i = 0; i < nr_frames; i++) {
3963 + frame_hcint.d32 = dwc_urb->iso_descs[i].status;
3964 + if (frame_hcint.b.xfercomp) {
3965 + dwc_urb->iso_descs[i].status = 0;
3966 + dwc_urb->actual_length += dwc_urb->iso_descs[i].actual_length;
3967 + } else if (frame_hcint.b.frmovrun) {
3968 + if (qh->ep_is_in)
3969 + dwc_urb->iso_descs[i].status = -DWC_E_NO_STREAM_RES;
3970 + else
3971 + dwc_urb->iso_descs[i].status = -DWC_E_COMMUNICATION;
3972 + dwc_urb->error_count++;
3973 + dwc_urb->iso_descs[i].actual_length = 0;
3974 + } else if (frame_hcint.b.xacterr) {
3975 + dwc_urb->iso_descs[i].status = -DWC_E_PROTOCOL;
3976 + dwc_urb->error_count++;
3977 + dwc_urb->iso_descs[i].actual_length = 0;
3978 + } else if (frame_hcint.b.bblerr) {
3979 + dwc_urb->iso_descs[i].status = -DWC_E_OVERFLOW;
3980 + dwc_urb->error_count++;
3981 + dwc_urb->iso_descs[i].actual_length = 0;
3982 + } else {
3983 + /* Something went wrong */
3984 + dwc_urb->iso_descs[i].status = -1;
3985 + dwc_urb->iso_descs[i].actual_length = 0;
3986 + dwc_urb->error_count++;
3987 + }
3988 + }
3989 + //printk_ratelimited(KERN_INFO "%s: HS isochronous of %d/%d frames with %d errors complete\n",
3990 + // __FUNCTION__, i, dwc_urb->packet_count, dwc_urb->error_count);
3991 + hcd->fops->complete(hcd, dwc_urb->priv, dwc_urb, 0);
3992 + release_channel(hcd, qh->channel, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
3993 +}
3994 +
3995 +/**
3996 + * dwc_otg_fiq_unsetup_per_dma() - Remove data from bounce buffers for split transactions
3997 + * @hcd: Pointer to dwc_otg_hcd struct
3998 + * @num: Host channel number
3999 + *
4000 + * Copies data from the FIQ bounce buffers into the URB's transfer buffer. Does not modify URB state.
4001 + * Returns total length of data or -1 if the buffers were not used.
4002 + *
4003 + */
4004 +int dwc_otg_fiq_unsetup_per_dma(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
4005 +{
4006 + dwc_hc_t *hc = qh->channel;
4007 + struct fiq_dma_blob *blob = hcd->fiq_dmab;
4008 + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
4009 + uint8_t *ptr = NULL;
4010 + int index = 0, len = 0;
4011 + int i = 0;
4012 + if (hc->ep_is_in) {
4013 + /* Copy data out of the DMA bounce buffers to the URB's buffer.
4014 + * The align_buf is ignored as this is ignored on FSM enqueue. */
4015 + ptr = qtd->urb->buf;
4016 + if (qh->ep_type == UE_ISOCHRONOUS) {
4017 + /* Isoc IN transactions - grab the offset of the iso_frame_desc into the URB transfer buffer */
4018 + index = qtd->isoc_frame_index;
4019 + ptr += qtd->urb->iso_descs[index].offset;
4020 + } else {
4021 + /* Need to increment by actual_length for interrupt IN */
4022 + ptr += qtd->urb->actual_length;
4023 + }
4024 +
4025 + for (i = 0; i < st->dma_info.index; i++) {
4026 + len += st->dma_info.slot_len[i];
4027 + dwc_memcpy(ptr, &blob->channel[num].index[i].buf[0], st->dma_info.slot_len[i]);
4028 + ptr += st->dma_info.slot_len[i];
4029 + }
4030 + return len;
4031 + } else {
4032 + /* OUT endpoints - nothing to do. */
4033 + return -1;
4034 + }
4035 +
4036 +}
4037 +/**
4038 + * dwc_otg_hcd_handle_hc_fsm() - handle an unmasked channel interrupt
4039 + * from a channel handled in the FIQ
4040 + * @hcd: Pointer to dwc_otg_hcd struct
4041 + * @num: Host channel number
4042 + *
4043 + * If a host channel interrupt was received by the IRQ and this was a channel
4044 + * used by the FIQ, the execution flow for transfer completion is substantially
4045 + * different from the normal (messy) path. This function and its friends handles
4046 + * channel cleanup and transaction completion from a FIQ transaction.
4047 + */
4048 +int32_t dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd_t *hcd, uint32_t num)
4049 +{
4050 + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
4051 + dwc_hc_t *hc = hcd->hc_ptr_array[num];
4052 + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
4053 + dwc_otg_qh_t *qh = hc->qh;
4054 + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[num];
4055 + hcint_data_t hcint = hcd->fiq_state->channel[num].hcint_copy;
4056 + int hostchannels = 0;
4057 + int ret = 0;
4058 + fiq_print(FIQDBG_INT, hcd->fiq_state, "OUT %01d %01d ", num , st->fsm);
4059 +
4060 + hostchannels = hcd->available_host_channels;
4061 + switch (st->fsm) {
4062 + case FIQ_TEST:
4063 + break;
4064 +
4065 + case FIQ_DEQUEUE_ISSUED:
4066 + /* hc_halt was called. QTD no longer exists. */
4067 + /* TODO: for a nonperiodic split transaction, need to issue a
4068 + * CLEAR_TT_BUFFER hub command if we were in the start-split phase.
4069 + */
4070 + release_channel(hcd, hc, NULL, hc->halt_status);
4071 + ret = 1;
4072 + break;
4073 +
4074 + case FIQ_NP_SPLIT_DONE:
4075 + /* Nonperiodic transaction complete. */
4076 + if (!hc->ep_is_in) {
4077 + qtd->ssplit_out_xfer_count = hc->xfer_len;
4078 + }
4079 + if (hcint.b.xfercomp) {
4080 + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
4081 + } else if (hcint.b.nak) {
4082 + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
4083 + }
4084 + ret = 1;
4085 + break;
4086 +
4087 + case FIQ_NP_SPLIT_HS_ABORTED:
4088 + /* A HS abort is a 3-strikes on the HS bus at any point in the transaction.
4089 + * Normally a CLEAR_TT_BUFFER hub command would be required: we can't do that
4090 + * because there's no guarantee which order a non-periodic split happened in.
4091 + * We could end up clearing a perfectly good transaction out of the buffer.
4092 + */
4093 + if (hcint.b.xacterr) {
4094 + qtd->error_count += st->nr_errors;
4095 + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
4096 + } else if (hcint.b.ahberr) {
4097 + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
4098 + } else {
4099 + local_fiq_disable();
4100 + BUG();
4101 + }
4102 + break;
4103 +
4104 + case FIQ_NP_SPLIT_LS_ABORTED:
4105 + /* A few cases can cause this - either an unknown state on a SSPLIT or
4106 + * STALL/data toggle error response on a CSPLIT */
4107 + if (hcint.b.stall) {
4108 + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
4109 + } else if (hcint.b.datatglerr) {
4110 + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
4111 + } else if (hcint.b.bblerr) {
4112 + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
4113 + } else if (hcint.b.ahberr) {
4114 + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
4115 + } else {
4116 + local_fiq_disable();
4117 + BUG();
4118 + }
4119 + break;
4120 +
4121 + case FIQ_PER_SPLIT_DONE:
4122 + /* Isoc IN or Interrupt IN/OUT */
4123 +
4124 + /* Flow control here is different from the normal execution by the driver.
4125 + * We need to completely ignore most of the driver's method of handling
4126 + * split transactions and do it ourselves.
4127 + */
4128 + if (hc->ep_type == UE_INTERRUPT) {
4129 + if (hcint.b.nak) {
4130 + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
4131 + } else if (hc->ep_is_in) {
4132 + int len;
4133 + len = dwc_otg_fiq_unsetup_per_dma(hcd, hc->qh, qtd, num);
4134 + //printk(KERN_NOTICE "FIQ Transaction: hc=%d len=%d urb_len = %d\n", num, len, qtd->urb->length);
4135 + qtd->urb->actual_length += len;
4136 + if (qtd->urb->actual_length >= qtd->urb->length) {
4137 + qtd->urb->status = 0;
4138 + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
4139 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
4140 + } else {
4141 + /* Interrupt transfer not complete yet - is it a short read? */
4142 + if (len < hc->max_packet) {
4143 + /* Interrupt transaction complete */
4144 + qtd->urb->status = 0;
4145 + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
4146 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
4147 + } else {
4148 + /* Further transactions required */
4149 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
4150 + }
4151 + }
4152 + } else {
4153 + /* Interrupt OUT complete. */
4154 + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
4155 + qtd->urb->actual_length += hc->xfer_len;
4156 + if (qtd->urb->actual_length >= qtd->urb->length) {
4157 + qtd->urb->status = 0;
4158 + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
4159 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
4160 + } else {
4161 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
4162 + }
4163 + }
4164 + } else {
4165 + /* ISOC IN complete. */
4166 + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
4167 + int len = 0;
4168 + /* Record errors, update qtd. */
4169 + if (st->nr_errors) {
4170 + frame_desc->actual_length = 0;
4171 + frame_desc->status = -DWC_E_PROTOCOL;
4172 + } else {
4173 + frame_desc->status = 0;
4174 + /* Unswizzle dma */
4175 + len = dwc_otg_fiq_unsetup_per_dma(hcd, qh, qtd, num);
4176 + frame_desc->actual_length = len;
4177 + }
4178 + qtd->isoc_frame_index++;
4179 + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
4180 + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
4181 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
4182 + } else {
4183 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
4184 + }
4185 + }
4186 + break;
4187 +
4188 + case FIQ_PER_ISO_OUT_DONE: {
4189 + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
4190 + /* Record errors, update qtd. */
4191 + if (st->nr_errors) {
4192 + frame_desc->actual_length = 0;
4193 + frame_desc->status = -DWC_E_PROTOCOL;
4194 + } else {
4195 + frame_desc->status = 0;
4196 + frame_desc->actual_length = frame_desc->length;
4197 + }
4198 + qtd->isoc_frame_index++;
4199 + qtd->isoc_split_offset = 0;
4200 + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
4201 + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
4202 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
4203 + } else {
4204 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
4205 + }
4206 + }
4207 + break;
4208 +
4209 + case FIQ_PER_SPLIT_NYET_ABORTED:
4210 + /* Doh. lost the data. */
4211 + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
4212 + "- FIQ reported NYET. Data may have been lost.\n",
4213 + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
4214 + if (hc->ep_type == UE_ISOCHRONOUS) {
4215 + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
4216 + /* Record errors, update qtd. */
4217 + frame_desc->actual_length = 0;
4218 + frame_desc->status = -DWC_E_PROTOCOL;
4219 + qtd->isoc_frame_index++;
4220 + qtd->isoc_split_offset = 0;
4221 + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
4222 + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
4223 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
4224 + } else {
4225 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
4226 + }
4227 + } else {
4228 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
4229 + }
4230 + break;
4231 +
4232 + case FIQ_HS_ISOC_DONE:
4233 + /* The FIQ has performed a whole pile of isochronous transactions.
4234 + * The status is recorded as the interrupt state should the transaction
4235 + * fail.
4236 + */
4237 + dwc_otg_fiq_unmangle_isoc(hcd, qh, qtd, num);
4238 + break;
4239 +
4240 + case FIQ_PER_SPLIT_LS_ABORTED:
4241 + if (hcint.b.xacterr) {
4242 + /* Hub has responded with an ERR packet. Device
4243 + * has been unplugged or the port has been disabled.
4244 + * TODO: need to issue a reset to the hub port. */
4245 + qtd->error_count += 3;
4246 + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
4247 + } else if (hcint.b.stall) {
4248 + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
4249 + } else if (hcint.b.bblerr) {
4250 + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
4251 + } else {
4252 + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x failed "
4253 + "- FIQ reported FSM=%d. Data may have been lost.\n",
4254 + st->fsm, hc->dev_addr, hc->ep_num);
4255 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
4256 + }
4257 + break;
4258 +
4259 + case FIQ_PER_SPLIT_HS_ABORTED:
4260 + /* Either the SSPLIT phase suffered transaction errors or something
4261 + * unexpected happened.
4262 + */
4263 + qtd->error_count += 3;
4264 + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
4265 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
4266 + break;
4267 +
4268 + case FIQ_PER_SPLIT_TIMEOUT:
4269 + /* Couldn't complete in the nominated frame */
4270 + printk(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
4271 + "- FIQ timed out. Data may have been lost.\n",
4272 + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
4273 + if (hc->ep_type == UE_ISOCHRONOUS) {
4274 + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
4275 + /* Record errors, update qtd. */
4276 + frame_desc->actual_length = 0;
4277 + if (hc->ep_is_in) {
4278 + frame_desc->status = -DWC_E_NO_STREAM_RES;
4279 + } else {
4280 + frame_desc->status = -DWC_E_COMMUNICATION;
4281 + }
4282 + qtd->isoc_frame_index++;
4283 + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
4284 + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
4285 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
4286 + } else {
4287 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
4288 + }
4289 + } else {
4290 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
4291 + }
4292 + break;
4293 +
4294 + default:
4295 + local_fiq_disable();
4296 + DWC_WARN("unexpected state received on hc=%d fsm=%d", hc->hc_num, st->fsm);
4297 + BUG();
4298 + }
4299 + //if (hostchannels != hcd->available_host_channels) {
4300 + /* should have incremented by now! */
4301 + // BUG();
4302 +// }
4303 + return ret;
4304 +}
4305 +
4306 /** Handles interrupt for a specific Host Channel */
4307 int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
4308 {
4309 int retval = 0;
4310 - hcint_data_t hcint, hcint_orig;
4311 + hcint_data_t hcint;
4312 hcintmsk_data_t hcintmsk;
4313 dwc_hc_t *hc;
4314 dwc_otg_hc_regs_t *hc_regs;
4315 @@ -2668,24 +2607,32 @@ int32_t dwc_otg_hcd_handle_hc_n_intr(dwc
4316 }
4317 qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
4318
4319 + /*
4320 + * FSM mode: Check to see if this is a HC interrupt from a channel handled by the FIQ.
4321 + * Execution path is fundamentally different for the channels after a FIQ has completed
4322 + * a split transaction.
4323 + */
4324 + if (fiq_fsm_enable) {
4325 + switch (dwc_otg_hcd->fiq_state->channel[num].fsm) {
4326 + case FIQ_PASSTHROUGH:
4327 + break;
4328 + case FIQ_PASSTHROUGH_ERRORSTATE:
4329 + /* Hook into the error count */
4330 + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "HCDERR%02d", num);
4331 + if (dwc_otg_hcd->fiq_state->channel[num].nr_errors) {
4332 + qtd->error_count = 0;
4333 + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "RESET ");
4334 + }
4335 + break;
4336 + default:
4337 + dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd, num);
4338 + return 1;
4339 + }
4340 + }
4341 +
4342 hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
4343 - hcint_orig = hcint;
4344 hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
4345 - DWC_DEBUGPL(DBG_HCDV,
4346 - " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
4347 - hcint.d32, hcintmsk.d32, (hcint.d32 & hcintmsk.d32));
4348 hcint.d32 = hcint.d32 & hcintmsk.d32;
4349 -
4350 - if(fiq_split_enable)
4351 - {
4352 - // replace with the saved interrupts from the fiq handler
4353 - local_fiq_disable();
4354 - hcint_orig.d32 = hcint_saved[num].d32;
4355 - hcint.d32 = hcint_orig.d32 & hcintmsk_saved[num].d32;
4356 - hcint_saved[num].d32 = 0;
4357 - local_fiq_enable();
4358 - }
4359 -
4360 if (!dwc_otg_hcd->core_if->dma_enable) {
4361 if (hcint.b.chhltd && hcint.d32 != 0x2) {
4362 hcint.b.chhltd = 0;
4363 @@ -2703,7 +2650,7 @@ int32_t dwc_otg_hcd_handle_hc_n_intr(dwc
4364 hcint.b.nyet = 0;
4365 }
4366 if (hcint.b.chhltd) {
4367 - retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd, hcint_orig, hcintmsk_saved[num]);
4368 + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
4369 }
4370 if (hcint.b.ahberr) {
4371 retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
4372 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
4373 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
4374 @@ -58,6 +58,7 @@
4375 #else
4376 #include <linux/usb/hcd.h>
4377 #endif
4378 +#include <asm/bug.h>
4379
4380 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
4381 #define USB_URB_EP_LINKING 1
4382 @@ -69,7 +70,8 @@
4383 #include "dwc_otg_dbg.h"
4384 #include "dwc_otg_driver.h"
4385 #include "dwc_otg_hcd.h"
4386 -#include "dwc_otg_mphi_fix.h"
4387 +
4388 +extern unsigned char _dwc_otg_fiq_stub, _dwc_otg_fiq_stub_end;
4389
4390 /**
4391 * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
4392 @@ -80,7 +82,7 @@
4393
4394 static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
4395
4396 -extern bool fiq_fix_enable;
4397 +extern bool fiq_enable;
4398
4399 /** @name Linux HC Driver API Functions */
4400 /** @{ */
4401 @@ -351,7 +353,6 @@ static int _complete(dwc_otg_hcd_t * hcd
4402 urb);
4403 }
4404 }
4405 -
4406 DWC_FREE(dwc_otg_urb);
4407 if (!new_entry) {
4408 DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
4409 @@ -395,13 +396,9 @@ static struct dwc_otg_hcd_function_ops h
4410 static struct fiq_handler fh = {
4411 .name = "usb_fiq",
4412 };
4413 -struct fiq_stack_s {
4414 - int magic1;
4415 - uint8_t stack[2048];
4416 - int magic2;
4417 -} fiq_stack;
4418
4419 -extern mphi_regs_t c_mphi_regs;
4420 +
4421 +
4422 /**
4423 * Initializes the HCD. This function allocates memory for and initializes the
4424 * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
4425 @@ -433,20 +430,6 @@ int hcd_init(dwc_bus_dev_t *_dev)
4426 pci_set_consistent_dma_mask(_dev, dmamask);
4427 #endif
4428
4429 - if (fiq_fix_enable)
4430 - {
4431 - // Set up fiq
4432 - claim_fiq(&fh);
4433 - set_fiq_handler(__FIQ_Branch, 4);
4434 - memset(&regs,0,sizeof(regs));
4435 - regs.ARM_r8 = (long)dwc_otg_hcd_handle_fiq;
4436 - regs.ARM_r9 = (long)0;
4437 - regs.ARM_sp = (long)fiq_stack.stack + sizeof(fiq_stack.stack) - 4;
4438 - set_fiq_regs(&regs);
4439 - fiq_stack.magic1 = 0xdeadbeef;
4440 - fiq_stack.magic2 = 0xaa995566;
4441 - }
4442 -
4443 /*
4444 * Allocate memory for the base HCD plus the DWC OTG HCD.
4445 * Initialize the base HCD.
4446 @@ -466,30 +449,7 @@ int hcd_init(dwc_bus_dev_t *_dev)
4447
4448 hcd->regs = otg_dev->os_dep.base;
4449
4450 - if (fiq_fix_enable)
4451 - {
4452 - volatile extern void *dwc_regs_base;
4453 -
4454 - //Set the mphi periph to the required registers
4455 - c_mphi_regs.base = otg_dev->os_dep.mphi_base;
4456 - c_mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
4457 - c_mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
4458 - c_mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
4459 - c_mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
4460 -
4461 - dwc_regs_base = otg_dev->os_dep.base;
4462
4463 - //Enable mphi peripheral
4464 - writel((1<<31),c_mphi_regs.ctrl);
4465 -#ifdef DEBUG
4466 - if (readl(c_mphi_regs.ctrl) & 0x80000000)
4467 - DWC_DEBUGPL(DBG_USER, "MPHI periph has been enabled\n");
4468 - else
4469 - DWC_DEBUGPL(DBG_USER, "MPHI periph has NOT been enabled\n");
4470 -#endif
4471 - // Enable FIQ interrupt from USB peripheral
4472 - enable_fiq(INTERRUPT_VC_USB);
4473 - }
4474 /* Initialize the DWC OTG HCD. */
4475 dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
4476 if (!dwc_otg_hcd) {
4477 @@ -503,6 +463,55 @@ int hcd_init(dwc_bus_dev_t *_dev)
4478 goto error2;
4479 }
4480
4481 + if (fiq_enable)
4482 + {
4483 + if (claim_fiq(&fh)) {
4484 + DWC_ERROR("Can't claim FIQ");
4485 + goto error2;
4486 + }
4487 +
4488 + DWC_WARN("FIQ at 0x%08x", (fiq_fsm_enable ? (int)&dwc_otg_fiq_fsm : (int)&dwc_otg_fiq_nop));
4489 + DWC_WARN("FIQ ASM at 0x%08x length %d", (int)&_dwc_otg_fiq_stub, (int)(&_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub));
4490 +
4491 + set_fiq_handler((void *) &_dwc_otg_fiq_stub, &_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub);
4492 + memset(&regs,0,sizeof(regs));
4493 +
4494 + regs.ARM_r8 = (long) dwc_otg_hcd->fiq_state;
4495 + if (fiq_fsm_enable) {
4496 + regs.ARM_r9 = dwc_otg_hcd->core_if->core_params->host_channels;
4497 + //regs.ARM_r10 = dwc_otg_hcd->dma;
4498 + regs.ARM_fp = (long) dwc_otg_fiq_fsm;
4499 + } else {
4500 + regs.ARM_fp = (long) dwc_otg_fiq_nop;
4501 + }
4502 +
4503 + regs.ARM_sp = (long) dwc_otg_hcd->fiq_stack + (sizeof(struct fiq_stack) - 4);
4504 +
4505 +// __show_regs(&regs);
4506 + set_fiq_regs(&regs);
4507 +
4508 + //Set the mphi periph to the required registers
4509 + dwc_otg_hcd->fiq_state->mphi_regs.base = otg_dev->os_dep.mphi_base;
4510 + dwc_otg_hcd->fiq_state->mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
4511 + dwc_otg_hcd->fiq_state->mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
4512 + dwc_otg_hcd->fiq_state->mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
4513 + dwc_otg_hcd->fiq_state->mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
4514 + dwc_otg_hcd->fiq_state->dwc_regs_base = otg_dev->os_dep.base;
4515 + DWC_WARN("MPHI regs_base at 0x%08x", (int)dwc_otg_hcd->fiq_state->mphi_regs.base);
4516 + //Enable mphi peripheral
4517 + writel((1<<31),dwc_otg_hcd->fiq_state->mphi_regs.ctrl);
4518 +#ifdef DEBUG
4519 + if (readl(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & 0x80000000)
4520 + DWC_WARN("MPHI periph has been enabled");
4521 + else
4522 + DWC_WARN("MPHI periph has NOT been enabled");
4523 +#endif
4524 + // Enable FIQ interrupt from USB peripheral
4525 + enable_fiq(INTERRUPT_VC_USB);
4526 + local_fiq_enable();
4527 + }
4528 +
4529 +
4530 otg_dev->hcd->otg_dev = otg_dev;
4531 hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
4532 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
4533 @@ -518,9 +527,9 @@ int hcd_init(dwc_bus_dev_t *_dev)
4534 * IRQ line, and calls hcd_start method.
4535 */
4536 #ifdef PLATFORM_INTERFACE
4537 - retval = usb_add_hcd(hcd, platform_get_irq(_dev, 0), IRQF_SHARED | IRQF_DISABLED);
4538 + retval = usb_add_hcd(hcd, platform_get_irq(_dev, fiq_enable ? 0 : 1), IRQF_SHARED | IRQF_DISABLED);
4539 #else
4540 - retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
4541 + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
4542 #endif
4543 if (retval < 0) {
4544 goto error2;
4545 @@ -617,9 +626,13 @@ void hcd_stop(struct usb_hcd *hcd)
4546 /** Returns the current frame number. */
4547 static int get_frame_number(struct usb_hcd *hcd)
4548 {
4549 + hprt0_data_t hprt0;
4550 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
4551 -
4552 - return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
4553 + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
4554 + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
4555 + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd) >> 3;
4556 + else
4557 + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
4558 }
4559
4560 #ifdef DEBUG
4561 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
4562 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
4563 @@ -41,7 +41,6 @@
4564
4565 #include "dwc_otg_hcd.h"
4566 #include "dwc_otg_regs.h"
4567 -#include "dwc_otg_mphi_fix.h"
4568
4569 extern bool microframe_schedule;
4570
4571 @@ -576,7 +575,6 @@ static int check_max_xfer_size(dwc_otg_h
4572 }
4573
4574
4575 -extern int g_next_sched_frame, g_np_count, g_np_sent;
4576
4577 /**
4578 * Schedules an interrupt or isochronous transfer in the periodic schedule.
4579 @@ -636,9 +634,9 @@ static int schedule_periodic(dwc_otg_hcd
4580 DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
4581 }
4582 else {
4583 - if(DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, g_next_sched_frame))
4584 + if(fiq_enable && (DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, hcd->fiq_state->next_sched_frame)))
4585 {
4586 - g_next_sched_frame = qh->sched_frame;
4587 + hcd->fiq_state->next_sched_frame = qh->sched_frame;
4588
4589 }
4590 /* Always start in the inactive schedule. */
4591 @@ -679,7 +677,7 @@ int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * h
4592 /* Always start in the inactive schedule. */
4593 DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
4594 &qh->qh_list_entry);
4595 - g_np_count++;
4596 + //hcd->fiq_state->kick_np_queues = 1;
4597 } else {
4598 status = schedule_periodic(hcd, qh);
4599 if ( !hcd->periodic_qh_count ) {
4600 @@ -739,13 +737,12 @@ void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t
4601 hcd->non_periodic_qh_ptr->next;
4602 }
4603 DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
4604 -
4605 - // If we've removed the last non-periodic entry then there are none left!
4606 - g_np_count = g_np_sent;
4607 + //if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive))
4608 + // hcd->fiq_state->kick_np_queues = 1;
4609 } else {
4610 deschedule_periodic(hcd, qh);
4611 hcd->periodic_qh_count--;
4612 - if( !hcd->periodic_qh_count ) {
4613 + if( !hcd->periodic_qh_count && !fiq_fsm_enable ) {
4614 intr_mask.b.sofintr = 1;
4615 DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
4616 intr_mask.d32, 0);
4617 @@ -770,28 +767,11 @@ void dwc_otg_hcd_qh_deactivate(dwc_otg_h
4618 int sched_next_periodic_split)
4619 {
4620 if (dwc_qh_is_non_per(qh)) {
4621 -
4622 - dwc_otg_qh_t *qh_tmp;
4623 - dwc_list_link_t *qh_list;
4624 - DWC_LIST_FOREACH(qh_list, &hcd->non_periodic_sched_inactive)
4625 - {
4626 - qh_tmp = DWC_LIST_ENTRY(qh_list, struct dwc_otg_qh, qh_list_entry);
4627 - if(qh_tmp == qh)
4628 - {
4629 - /*
4630 - * FIQ is being disabled because this one nevers gets a np_count increment
4631 - * This is still not absolutely correct, but it should fix itself with
4632 - * just an unnecessary extra interrupt
4633 - */
4634 - g_np_sent = g_np_count;
4635 - }
4636 - }
4637 -
4638 -
4639 dwc_otg_hcd_qh_remove(hcd, qh);
4640 if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
4641 /* Add back to inactive non-periodic schedule. */
4642 dwc_otg_hcd_qh_add(hcd, qh);
4643 + //hcd->fiq_state->kick_np_queues = 1;
4644 }
4645 } else {
4646 uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
4647 @@ -850,9 +830,9 @@ void dwc_otg_hcd_qh_deactivate(dwc_otg_h
4648 DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
4649 &qh->qh_list_entry);
4650 } else {
4651 - if(!dwc_frame_num_le(g_next_sched_frame, qh->sched_frame))
4652 + if(fiq_enable && !dwc_frame_num_le(hcd->fiq_state->next_sched_frame, qh->sched_frame))
4653 {
4654 - g_next_sched_frame = qh->sched_frame;
4655 + hcd->fiq_state->next_sched_frame = qh->sched_frame;
4656 }
4657
4658 DWC_LIST_MOVE_HEAD
4659 @@ -943,6 +923,9 @@ int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t *
4660 if (*qh == NULL) {
4661 retval = -DWC_E_NO_MEMORY;
4662 goto done;
4663 + } else {
4664 + if (fiq_enable)
4665 + hcd->fiq_state->kick_np_queues = 1;
4666 }
4667 }
4668 retval = dwc_otg_hcd_qh_add(hcd, *qh);
4669 --- a/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c
4670 +++ /dev/null
4671 @@ -1,113 +0,0 @@
4672 -#include "dwc_otg_regs.h"
4673 -#include "dwc_otg_dbg.h"
4674 -
4675 -void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name)
4676 -{
4677 - DWC_DEBUGPL(DBG_USER, "*** Debugging from within the %s function: ***\n"
4678 - "curmode: %1i Modemismatch: %1i otgintr: %1i sofintr: %1i\n"
4679 - "rxstsqlvl: %1i nptxfempty : %1i ginnakeff: %1i goutnakeff: %1i\n"
4680 - "ulpickint: %1i i2cintr: %1i erlysuspend:%1i usbsuspend: %1i\n"
4681 - "usbreset: %1i enumdone: %1i isooutdrop: %1i eopframe: %1i\n"
4682 - "restoredone: %1i epmismatch: %1i inepint: %1i outepintr: %1i\n"
4683 - "incomplisoin:%1i incomplisoout:%1i fetsusp: %1i resetdet: %1i\n"
4684 - "portintr: %1i hcintr: %1i ptxfempty: %1i lpmtranrcvd:%1i\n"
4685 - "conidstschng:%1i disconnect: %1i sessreqintr:%1i wkupintr: %1i\n",
4686 - function_name,
4687 - gintsts.b.curmode,
4688 - gintsts.b.modemismatch,
4689 - gintsts.b.otgintr,
4690 - gintsts.b.sofintr,
4691 - gintsts.b.rxstsqlvl,
4692 - gintsts.b.nptxfempty,
4693 - gintsts.b.ginnakeff,
4694 - gintsts.b.goutnakeff,
4695 - gintsts.b.ulpickint,
4696 - gintsts.b.i2cintr,
4697 - gintsts.b.erlysuspend,
4698 - gintsts.b.usbsuspend,
4699 - gintsts.b.usbreset,
4700 - gintsts.b.enumdone,
4701 - gintsts.b.isooutdrop,
4702 - gintsts.b.eopframe,
4703 - gintsts.b.restoredone,
4704 - gintsts.b.epmismatch,
4705 - gintsts.b.inepint,
4706 - gintsts.b.outepintr,
4707 - gintsts.b.incomplisoin,
4708 - gintsts.b.incomplisoout,
4709 - gintsts.b.fetsusp,
4710 - gintsts.b.resetdet,
4711 - gintsts.b.portintr,
4712 - gintsts.b.hcintr,
4713 - gintsts.b.ptxfempty,
4714 - gintsts.b.lpmtranrcvd,
4715 - gintsts.b.conidstschng,
4716 - gintsts.b.disconnect,
4717 - gintsts.b.sessreqintr,
4718 - gintsts.b.wkupintr);
4719 - return;
4720 -}
4721 -
4722 -void dwc_debug_core_int_mask(gintmsk_data_t gintmsk, const char* function_name)
4723 -{
4724 - DWC_DEBUGPL(DBG_USER, "Interrupt Mask status (called from %s) :\n"
4725 - "modemismatch: %1i otgintr: %1i sofintr: %1i rxstsqlvl: %1i\n"
4726 - "nptxfempty: %1i ginnakeff: %1i goutnakeff: %1i ulpickint: %1i\n"
4727 - "i2cintr: %1i erlysuspend:%1i usbsuspend: %1i usbreset: %1i\n"
4728 - "enumdone: %1i isooutdrop: %1i eopframe: %1i restoredone: %1i\n"
4729 - "epmismatch: %1i inepintr: %1i outepintr: %1i incomplisoin:%1i\n"
4730 - "incomplisoout:%1i fetsusp: %1i resetdet: %1i portintr: %1i\n"
4731 - "hcintr: %1i ptxfempty: %1i lpmtranrcvd:%1i conidstschng:%1i\n"
4732 - "disconnect: %1i sessreqintr:%1i wkupintr: %1i\n",
4733 - function_name,
4734 - gintmsk.b.modemismatch,
4735 - gintmsk.b.otgintr,
4736 - gintmsk.b.sofintr,
4737 - gintmsk.b.rxstsqlvl,
4738 - gintmsk.b.nptxfempty,
4739 - gintmsk.b.ginnakeff,
4740 - gintmsk.b.goutnakeff,
4741 - gintmsk.b.ulpickint,
4742 - gintmsk.b.i2cintr,
4743 - gintmsk.b.erlysuspend,
4744 - gintmsk.b.usbsuspend,
4745 - gintmsk.b.usbreset,
4746 - gintmsk.b.enumdone,
4747 - gintmsk.b.isooutdrop,
4748 - gintmsk.b.eopframe,
4749 - gintmsk.b.restoredone,
4750 - gintmsk.b.epmismatch,
4751 - gintmsk.b.inepintr,
4752 - gintmsk.b.outepintr,
4753 - gintmsk.b.incomplisoin,
4754 - gintmsk.b.incomplisoout,
4755 - gintmsk.b.fetsusp,
4756 - gintmsk.b.resetdet,
4757 - gintmsk.b.portintr,
4758 - gintmsk.b.hcintr,
4759 - gintmsk.b.ptxfempty,
4760 - gintmsk.b.lpmtranrcvd,
4761 - gintmsk.b.conidstschng,
4762 - gintmsk.b.disconnect,
4763 - gintmsk.b.sessreqintr,
4764 - gintmsk.b.wkupintr);
4765 - return;
4766 -}
4767 -
4768 -void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name)
4769 -{
4770 - DWC_DEBUGPL(DBG_USER, "otg int register (from %s function):\n"
4771 - "sesenddet:%1i sesreqsucstschung:%2i hstnegsucstschng:%1i\n"
4772 - "hstnegdet:%1i adevtoutchng: %2i debdone: %1i\n"
4773 - "mvic: %1i\n",
4774 - function_name,
4775 - gotgint.b.sesenddet,
4776 - gotgint.b.sesreqsucstschng,
4777 - gotgint.b.hstnegsucstschng,
4778 - gotgint.b.hstnegdet,
4779 - gotgint.b.adevtoutchng,
4780 - gotgint.b.debdone,
4781 - gotgint.b.mvic);
4782 -
4783 - return;
4784 -}
4785 --- a/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h
4786 +++ /dev/null
4787 @@ -1,48 +0,0 @@
4788 -#ifndef __DWC_OTG_MPHI_FIX_H__
4789 -#define __DWC_OTG_MPHI_FIX_H__
4790 -#define FIQ_WRITE(_addr_,_data_) (*(volatile uint32_t *) (_addr_) = (_data_))
4791 -#define FIQ_READ(_addr_) (*(volatile uint32_t *) (_addr_))
4792 -
4793 -typedef struct {
4794 - volatile void* base;
4795 - volatile void* ctrl;
4796 - volatile void* outdda;
4797 - volatile void* outddb;
4798 - volatile void* intstat;
4799 -} mphi_regs_t;
4800 -
4801 -void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name);
4802 -void dwc_debug_core_int_mask(gintsts_data_t gintmsk, const char* function_name);
4803 -void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name);
4804 -
4805 -extern gintsts_data_t gintsts_saved;
4806 -
4807 -#ifdef DEBUG
4808 -#define DWC_DBG_PRINT_CORE_INT(_arg_) dwc_debug_print_core_int_reg(_arg_,__func__)
4809 -#define DWC_DBG_PRINT_CORE_INT_MASK(_arg_) dwc_debug_core_int_mask(_arg_,__func__)
4810 -#define DWC_DBG_PRINT_OTG_INT(_arg_) dwc_debug_otg_int(_arg_,__func__)
4811 -
4812 -#else
4813 -#define DWC_DBG_PRINT_CORE_INT(_arg_)
4814 -#define DWC_DBG_PRINT_CORE_INT_MASK(_arg_)
4815 -#define DWC_DBG_PRINT_OTG_INT(_arg_)
4816 -
4817 -#endif
4818 -
4819 -typedef enum {
4820 - FIQDBG_SCHED = (1 << 0),
4821 - FIQDBG_INT = (1 << 1),
4822 - FIQDBG_ERR = (1 << 2),
4823 - FIQDBG_PORTHUB = (1 << 3),
4824 -} FIQDBG_T;
4825 -
4826 -void _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...);
4827 -#ifdef FIQ_DEBUG
4828 -#define fiq_print _fiq_print
4829 -#else
4830 -#define fiq_print(x, y, ...)
4831 -#endif
4832 -
4833 -extern bool fiq_fix_enable, nak_holdoff_enable, fiq_split_enable;
4834 -
4835 -#endif
4836 --- a/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
4837 +++ b/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
4838 @@ -59,6 +59,8 @@
4839 #include "dwc_otg_driver.h"
4840 #include "dwc_otg_dbg.h"
4841
4842 +extern bool fiq_enable;
4843 +
4844 static struct gadget_wrapper {
4845 dwc_otg_pcd_t *pcd;
4846
4847 @@ -1222,13 +1224,13 @@ int pcd_init(dwc_bus_dev_t *_dev)
4848 */
4849 #ifdef PLATFORM_INTERFACE
4850 DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
4851 - platform_get_irq(_dev, 0));
4852 - retval = request_irq(platform_get_irq(_dev, 0), dwc_otg_pcd_irq,
4853 + platform_get_irq(_dev, fiq_enable ? 0 : 1));
4854 + retval = request_irq(platform_get_irq(_dev, fiq_enable ? 0 : 1), dwc_otg_pcd_irq,
4855 IRQF_SHARED, gadget_wrapper->gadget.name,
4856 otg_dev->pcd);
4857 if (retval != 0) {
4858 DWC_ERROR("request of irq%d failed\n",
4859 - platform_get_irq(_dev, 0));
4860 + platform_get_irq(_dev, fiq_enable ? 0 : 1));
4861 free_wrapper(gadget_wrapper);
4862 return -EBUSY;
4863 }