lantiq: Use the BAR0 base address in the ath PCI fixup code
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-3.18 / 0026-dwc_otg-fiq_fsm-Base-commit-for-driver-rewrite.patch
1 From d434f75bc6411d2964fce7fee50fe0ce49dd02eb 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 026/114] 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 | 80 ++
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, 2991 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 @@ -701,11 +692,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,80 @@
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 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
2141 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
2142 @@ -45,9 +45,10 @@
2143
2144 #include "dwc_otg_hcd.h"
2145 #include "dwc_otg_regs.h"
2146 -#include "dwc_otg_mphi_fix.h"
2147 +#include "dwc_otg_fiq_fsm.h"
2148
2149 -extern bool microframe_schedule, nak_holdoff_enable;
2150 +extern bool microframe_schedule;
2151 +extern uint16_t fiq_fsm_mask, nak_holdoff;
2152
2153 //#define DEBUG_HOST_CHANNELS
2154 #ifdef DEBUG_HOST_CHANNELS
2155 @@ -57,12 +58,6 @@ static int last_sel_trans_num_avail_hc_a
2156 static int last_sel_trans_num_avail_hc_at_end = 0;
2157 #endif /* DEBUG_HOST_CHANNELS */
2158
2159 -extern int g_next_sched_frame, g_np_count, g_np_sent;
2160 -
2161 -extern haint_data_t haint_saved;
2162 -extern hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
2163 -extern hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
2164 -extern gintsts_data_t ginsts_saved;
2165
2166 dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
2167 {
2168 @@ -295,7 +290,7 @@ static int32_t dwc_otg_hcd_disconnect_cb
2169 */
2170 dwc_otg_hcd->flags.b.port_connect_status_change = 1;
2171 dwc_otg_hcd->flags.b.port_connect_status = 0;
2172 - if(fiq_fix_enable)
2173 + if(fiq_enable)
2174 local_fiq_disable();
2175 /*
2176 * Shutdown any transfers in process by clearing the Tx FIFO Empty
2177 @@ -392,20 +387,15 @@ static int32_t dwc_otg_hcd_disconnect_cb
2178 channel->qh = NULL;
2179 }
2180 }
2181 - if(fiq_split_enable) {
2182 + if(fiq_fsm_enable) {
2183 for(i=0; i < 128; i++) {
2184 dwc_otg_hcd->hub_port[i] = 0;
2185 }
2186 - haint_saved.d32 = 0;
2187 - for(i=0; i < MAX_EPS_CHANNELS; i++) {
2188 - hcint_saved[i].d32 = 0;
2189 - hcintmsk_saved[i].d32 = 0;
2190 - }
2191 }
2192
2193 }
2194
2195 - if(fiq_fix_enable)
2196 + if(fiq_enable)
2197 local_fiq_enable();
2198
2199 if (dwc_otg_hcd->fops->disconnect) {
2200 @@ -542,7 +532,7 @@ int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_
2201 }
2202 #endif
2203 intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
2204 - if(!intr_mask.b.sofintr) needs_scheduling = 1;
2205 + if(!intr_mask.b.sofintr || fiq_enable) needs_scheduling = 1;
2206 if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
2207 /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
2208 needs_scheduling = 0;
2209 @@ -613,6 +603,7 @@ int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_
2210 if (urb_qtd->in_process && qh->channel) {
2211 /* The QTD is in process (it has been assigned to a channel). */
2212 if (hcd->flags.b.port_connect_status) {
2213 + int n = qh->channel->hc_num;
2214 /*
2215 * If still connected (i.e. in host mode), halt the
2216 * channel so it can be used for other transfers. If
2217 @@ -620,10 +611,16 @@ int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_
2218 * written to halt the channel since the core is in
2219 * device mode.
2220 */
2221 - dwc_otg_hc_halt(hcd->core_if, qh->channel,
2222 - DWC_OTG_HC_XFER_URB_DEQUEUE);
2223 -
2224 - dwc_otg_hcd_release_port(hcd, qh);
2225 + /* In FIQ FSM mode, we need to shut down carefully.
2226 + * The FIQ may attempt to restart a disabled channel */
2227 + if (fiq_fsm_enable && (hcd->fiq_state->channel[n].fsm != FIQ_PASSTHROUGH)) {
2228 + qh->channel->halt_status = DWC_OTG_HC_XFER_URB_DEQUEUE;
2229 + qh->channel->halt_pending = 1;
2230 + hcd->fiq_state->channel[n].fsm = FIQ_DEQUEUE_ISSUED;
2231 + } else {
2232 + dwc_otg_hc_halt(hcd->core_if, qh->channel,
2233 + DWC_OTG_HC_XFER_URB_DEQUEUE);
2234 + }
2235 }
2236 }
2237
2238 @@ -759,7 +756,6 @@ static void completion_tasklet_func(void
2239
2240 usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
2241
2242 - fiq_print(FIQDBG_PORTHUB, "COMPLETE");
2243
2244 DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
2245 }
2246 @@ -854,6 +850,34 @@ void dwc_otg_hcd_power_up(void *ptr)
2247 cil_hcd_start(core_if);
2248 }
2249
2250 +void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num)
2251 +{
2252 + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
2253 + struct fiq_dma_blob *blob = hcd->fiq_dmab;
2254 + int i;
2255 +
2256 + st->fsm = FIQ_PASSTHROUGH;
2257 + st->hcchar_copy.d32 = 0;
2258 + st->hcsplt_copy.d32 = 0;
2259 + st->hcint_copy.d32 = 0;
2260 + st->hcintmsk_copy.d32 = 0;
2261 + st->hctsiz_copy.d32 = 0;
2262 + st->hcdma_copy.d32 = 0;
2263 + st->nr_errors = 0;
2264 + st->hub_addr = 0;
2265 + st->port_addr = 0;
2266 + st->expected_uframe = 0;
2267 + st->nrpackets = 0;
2268 + st->dma_info.index = 0;
2269 + for (i = 0; i < 6; i++)
2270 + st->dma_info.slot_len[i] = 255;
2271 + st->hs_isoc_info.index = 0;
2272 + st->hs_isoc_info.iso_desc = NULL;
2273 + st->hs_isoc_info.nrframes = 0;
2274 +
2275 + DWC_MEMSET(&blob->channel[num].index[0], 0x6b, 1128);
2276 +}
2277 +
2278 /**
2279 * Frees secondary storage associated with the dwc_otg_hcd structure contained
2280 * in the struct usb_hcd field.
2281 @@ -907,6 +931,7 @@ static void dwc_otg_hcd_free(dwc_otg_hcd
2282 DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
2283 DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
2284 DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
2285 + DWC_FREE(dwc_otg_hcd->fiq_state);
2286
2287 #ifdef DWC_DEV_SRPCAP
2288 if (dwc_otg_hcd->core_if->power_down == 2 &&
2289 @@ -984,6 +1009,59 @@ int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd
2290 channel);
2291 }
2292
2293 + if (fiq_enable) {
2294 + hcd->fiq_state = DWC_ALLOC(sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels));
2295 + if (!hcd->fiq_state) {
2296 + retval = -DWC_E_NO_MEMORY;
2297 + DWC_ERROR("%s: cannot allocate fiq_state structure\n", __func__);
2298 + dwc_otg_hcd_free(hcd);
2299 + goto out;
2300 + }
2301 + DWC_MEMSET(hcd->fiq_state, 0, (sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels)));
2302 +
2303 + for (i = 0; i < num_channels; i++) {
2304 + hcd->fiq_state->channel[i].fsm = FIQ_PASSTHROUGH;
2305 + }
2306 + hcd->fiq_state->dummy_send = DWC_ALLOC_ATOMIC(16);
2307 +
2308 + hcd->fiq_stack = DWC_ALLOC(sizeof(struct fiq_stack));
2309 + if (!hcd->fiq_stack) {
2310 + retval = -DWC_E_NO_MEMORY;
2311 + DWC_ERROR("%s: cannot allocate fiq_stack structure\n", __func__);
2312 + dwc_otg_hcd_free(hcd);
2313 + goto out;
2314 + }
2315 + hcd->fiq_stack->magic1 = 0xDEADBEEF;
2316 + hcd->fiq_stack->magic2 = 0xD00DFEED;
2317 + hcd->fiq_state->gintmsk_saved.d32 = ~0;
2318 + hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
2319 +
2320 + /* This bit is terrible and uses no API, but necessary. The FIQ has no concept of DMA pools
2321 + * (and if it did, would be a lot slower). This allocates a chunk of memory (~9kiB for 8 host channels)
2322 + * for use as transaction bounce buffers in a 2-D array. Our access into this chunk is done by some
2323 + * moderately readable array casts.
2324 + */
2325 + hcd->fiq_dmab = DWC_DMA_ALLOC((sizeof(struct fiq_dma_channel) * num_channels), &hcd->fiq_state->dma_base);
2326 + DWC_WARN("FIQ DMA bounce buffers: virt = 0x%08x dma = 0x%08x len=%d",
2327 + (unsigned int)hcd->fiq_dmab, (unsigned int)hcd->fiq_state->dma_base,
2328 + sizeof(struct fiq_dma_channel) * num_channels);
2329 +
2330 + DWC_MEMSET(hcd->fiq_dmab, 0x6b, 9024);
2331 +
2332 + /* pointer for debug in fiq_print */
2333 + hcd->fiq_state->fiq_dmab = hcd->fiq_dmab;
2334 + if (fiq_fsm_enable) {
2335 + int i;
2336 + for (i=0; i < hcd->core_if->core_params->host_channels; i++) {
2337 + dwc_otg_cleanup_fiq_channel(hcd, i);
2338 + }
2339 + DWC_PRINTF("FIQ FSM acceleration enabled for :\n%s%s%s",
2340 + (fiq_fsm_mask & 0x1) ? "Non-periodic Split Transactions\n" : "",
2341 + (fiq_fsm_mask & 0x2) ? "Periodic Split Transactions\n" : "",
2342 + (fiq_fsm_mask & 0x4) ? "High-Speed Isochronous Endpoints\n" : "");
2343 + }
2344 + }
2345 +
2346 /* Initialize the Connection timeout timer. */
2347 hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
2348 dwc_otg_hcd_connect_timeout, 0);
2349 @@ -1181,7 +1259,8 @@ static void assign_and_init_hc(dwc_otg_h
2350 hc->do_split = 1;
2351 hc->xact_pos = qtd->isoc_split_pos;
2352 /* We don't need to do complete splits anymore */
2353 - if(fiq_split_enable)
2354 +// if(fiq_fsm_enable)
2355 + if (0)
2356 hc->complete_split = qtd->complete_split = 0;
2357 else
2358 hc->complete_split = qtd->complete_split;
2359 @@ -1332,62 +1411,487 @@ static void assign_and_init_hc(dwc_otg_h
2360 hc->qh = qh;
2361 }
2362
2363 -/*
2364 -** Check the transaction to see if the port / hub has already been assigned for
2365 -** a split transaction
2366 -**
2367 -** Return 0 - Port is already in use
2368 -*/
2369 -int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
2370 +
2371 +/**
2372 + * fiq_fsm_transaction_suitable() - Test a QH for compatibility with the FIQ
2373 + * @qh: pointer to the endpoint's queue head
2374 + *
2375 + * Transaction start/end control flow is grafted onto the existing dwc_otg
2376 + * mechanisms, to avoid spaghettifying the functions more than they already are.
2377 + * This function's eligibility check is altered by debug parameter.
2378 + *
2379 + * Returns: 0 for unsuitable, 1 implies the FIQ can be enabled for this transaction.
2380 + */
2381 +
2382 +int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh)
2383 {
2384 - uint32_t hub_addr, port_addr;
2385 + if (qh->do_split) {
2386 + switch (qh->ep_type) {
2387 + case UE_CONTROL:
2388 + case UE_BULK:
2389 + if (fiq_fsm_mask & (1 << 0))
2390 + return 1;
2391 + break;
2392 + case UE_INTERRUPT:
2393 + case UE_ISOCHRONOUS:
2394 + if (fiq_fsm_mask & (1 << 1))
2395 + return 1;
2396 + break;
2397 + default:
2398 + break;
2399 + }
2400 + } else if (qh->ep_type == UE_ISOCHRONOUS) {
2401 + if (fiq_fsm_mask & (1 << 2)) {
2402 + /* HS ISOCH support. We test for compatibility:
2403 + * - DWORD aligned buffers
2404 + * - Must be at least 2 transfers (otherwise pointless to use the FIQ)
2405 + * If yes, then the fsm enqueue function will handle the state machine setup.
2406 + */
2407 + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
2408 + dwc_otg_hcd_urb_t *urb = qtd->urb;
2409 + struct dwc_otg_hcd_iso_packet_desc (*iso_descs)[0] = &urb->iso_descs;
2410 + int nr_iso_frames = urb->packet_count;
2411 + int i;
2412 + uint32_t ptr;
2413 +
2414 + if (nr_iso_frames < 2)
2415 + return 0;
2416 + for (i = 0; i < nr_iso_frames; i++) {
2417 + ptr = urb->dma + iso_descs[i]->offset;
2418 + if (ptr & 0x3) {
2419 + printk_ratelimited("%s: Non-Dword aligned isochronous frame offset."
2420 + " Cannot queue FIQ-accelerated transfer to device %d endpoint %d\n",
2421 + __FUNCTION__, qh->channel->dev_addr, qh->channel->ep_num);
2422 + return 0;
2423 + }
2424 + }
2425 + return 1;
2426 + }
2427 + }
2428 + return 0;
2429 +}
2430
2431 - if(!fiq_split_enable)
2432 - return 0;
2433 +/**
2434 + * fiq_fsm_setup_periodic_dma() - Set up DMA bounce buffers
2435 + * @hcd: Pointer to the dwc_otg_hcd struct
2436 + * @qh: Pointer to the endpoint's queue head
2437 + *
2438 + * Periodic split transactions are transmitted modulo 188 bytes.
2439 + * This necessitates slicing data up into buckets for isochronous out
2440 + * and fixing up the DMA address for all IN transfers.
2441 + *
2442 + * Returns 1 if the DMA bounce buffers have been used, 0 if the default
2443 + * HC buffer has been used.
2444 + */
2445 +int fiq_fsm_setup_periodic_dma(dwc_otg_hcd_t *hcd, struct fiq_channel_state *st, dwc_otg_qh_t *qh)
2446 + {
2447 + int frame_length, i = 0;
2448 + uint8_t *ptr = NULL;
2449 + dwc_hc_t *hc = qh->channel;
2450 + struct fiq_dma_blob *blob;
2451 + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
2452
2453 - hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
2454 + for (i = 0; i < 6; i++) {
2455 + st->dma_info.slot_len[i] = 255;
2456 + }
2457 + st->dma_info.index = 0;
2458 + i = 0;
2459 + if (hc->ep_is_in) {
2460 + /*
2461 + * Set dma_regs to bounce buffer. FIQ will update the
2462 + * state depending on transaction progress.
2463 + */
2464 + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
2465 + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
2466 + /* Calculate the max number of CSPLITS such that the FIQ can time out
2467 + * a transaction if it fails.
2468 + */
2469 + frame_length = st->hcchar_copy.b.mps;
2470 + do {
2471 + i++;
2472 + frame_length -= 188;
2473 + } while (frame_length >= 0);
2474 + st->nrpackets = i;
2475 + return 1;
2476 + } else {
2477 + if (qh->ep_type == UE_ISOCHRONOUS) {
2478
2479 - if(hcd->hub_port[hub_addr] & (1 << port_addr))
2480 - {
2481 - fiq_print(FIQDBG_PORTHUB, "H%dP%d:S%02d", hub_addr, port_addr, qh->skip_count);
2482 + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
2483
2484 - qh->skip_count++;
2485 + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
2486 + frame_length = frame_desc->length;
2487
2488 - if(qh->skip_count > 40000)
2489 - {
2490 - printk_once(KERN_ERR "Error: Having to skip port allocation");
2491 - local_fiq_disable();
2492 - BUG();
2493 + /* Virtual address for bounce buffers */
2494 + blob = hcd->fiq_dmab;
2495 +
2496 + ptr = qtd->urb->buf + frame_desc->offset;
2497 + if (frame_length == 0) {
2498 + /*
2499 + * for isochronous transactions, we must still transmit a packet
2500 + * even if the length is zero.
2501 + */
2502 + st->dma_info.slot_len[0] = 0;
2503 + st->nrpackets = 1;
2504 + } else {
2505 + do {
2506 + if (frame_length <= 188) {
2507 + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, frame_length);
2508 + st->dma_info.slot_len[i] = frame_length;
2509 + ptr += frame_length;
2510 + } else {
2511 + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, 188);
2512 + st->dma_info.slot_len[i] = 188;
2513 + ptr += 188;
2514 + }
2515 + i++;
2516 + frame_length -= 188;
2517 + } while (frame_length > 0);
2518 + st->nrpackets = i;
2519 + }
2520 + ptr = qtd->urb->buf + frame_desc->offset;
2521 + /* Point the HC at the DMA address of the bounce buffers */
2522 + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
2523 + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
2524 +
2525 + /* fixup xfersize to the actual packet size */
2526 + st->hctsiz_copy.b.pid = 0;
2527 + st->hctsiz_copy.b.xfersize = st->dma_info.slot_len[0];
2528 + return 1;
2529 + } else {
2530 + /* For interrupt, single OUT packet required, goes in the SSPLIT from hc_buff. */
2531 return 0;
2532 }
2533 - return 1;
2534 }
2535 - else
2536 - {
2537 - qh->skip_count = 0;
2538 - hcd->hub_port[hub_addr] |= 1 << port_addr;
2539 - fiq_print(FIQDBG_PORTHUB, "H%dP%d:A %d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
2540 -#ifdef FIQ_DEBUG
2541 - hcd->hub_port_alloc[hub_addr * 16 + port_addr] = dwc_otg_hcd_get_frame_number(hcd);
2542 -#endif
2543 +}
2544 +
2545 +/*
2546 + * Pushing a periodic request into the queue near the EOF1 point
2547 + * in a microframe causes erroneous behaviour (frmovrun) interrupt.
2548 + * Usually, the request goes out on the bus causing a transfer but
2549 + * the core does not transfer the data to memory.
2550 + * This guard interval (in number of 60MHz clocks) is required which
2551 + * must cater for CPU latency between reading the value and enabling
2552 + * the channel.
2553 + */
2554 +#define PERIODIC_FRREM_BACKOFF 1000
2555 +
2556 +int fiq_fsm_queue_isoc_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
2557 +{
2558 + dwc_hc_t *hc = qh->channel;
2559 + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
2560 + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
2561 + int frame;
2562 + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
2563 + int xfer_len, nrpackets;
2564 + hcdma_data_t hcdma;
2565 + hfnum_data_t hfnum;
2566 +
2567 + if (st->fsm != FIQ_PASSTHROUGH)
2568 return 0;
2569 +
2570 + st->nr_errors = 0;
2571 +
2572 + st->hcchar_copy.d32 = 0;
2573 + st->hcchar_copy.b.mps = hc->max_packet;
2574 + st->hcchar_copy.b.epdir = hc->ep_is_in;
2575 + st->hcchar_copy.b.devaddr = hc->dev_addr;
2576 + st->hcchar_copy.b.epnum = hc->ep_num;
2577 + st->hcchar_copy.b.eptype = hc->ep_type;
2578 +
2579 + st->hcintmsk_copy.b.chhltd = 1;
2580 +
2581 + frame = dwc_otg_hcd_get_frame_number(hcd);
2582 + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
2583 +
2584 + st->hcchar_copy.b.lspddev = 0;
2585 + /* Enable the channel later as a final register write. */
2586 +
2587 + st->hcsplt_copy.d32 = 0;
2588 +
2589 + st->hs_isoc_info.iso_desc = (struct dwc_otg_hcd_iso_packet_desc *) &qtd->urb->iso_descs;
2590 + st->hs_isoc_info.nrframes = qtd->urb->packet_count;
2591 + /* grab the next DMA address offset from the array */
2592 + st->hcdma_copy.d32 = qtd->urb->dma;
2593 + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[0].offset;
2594 +
2595 + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
2596 + * the core needs to be told to send the correct number. Caution: for IN transfers,
2597 + * this is always set to the maximum size of the endpoint. */
2598 + xfer_len = st->hs_isoc_info.iso_desc[0].length;
2599 + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
2600 + if (nrpackets == 0)
2601 + nrpackets = 1;
2602 + st->hcchar_copy.b.multicnt = nrpackets;
2603 + st->hctsiz_copy.b.pktcnt = nrpackets;
2604 +
2605 + /* Initial PID also needs to be set */
2606 + if (st->hcchar_copy.b.epdir == 0) {
2607 + st->hctsiz_copy.b.xfersize = xfer_len;
2608 + switch (st->hcchar_copy.b.multicnt) {
2609 + case 1:
2610 + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
2611 + break;
2612 + case 2:
2613 + case 3:
2614 + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
2615 + break;
2616 + }
2617 +
2618 + } else {
2619 + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
2620 + switch (st->hcchar_copy.b.multicnt) {
2621 + case 1:
2622 + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
2623 + break;
2624 + case 2:
2625 + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
2626 + break;
2627 + case 3:
2628 + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
2629 + break;
2630 + }
2631 }
2632 +
2633 + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d ", hc->hc_num);
2634 + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcchar_copy.d32);
2635 + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
2636 + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
2637 + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
2638 + local_fiq_disable();
2639 + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
2640 + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
2641 + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
2642 + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
2643 + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
2644 + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
2645 + /* Prevent queueing near EOF1. Bad things happen if a periodic
2646 + * split transaction is queued very close to EOF.
2647 + */
2648 + st->fsm = FIQ_HS_ISOC_SLEEPING;
2649 + } else {
2650 + st->fsm = FIQ_HS_ISOC_TURBO;
2651 + st->hcchar_copy.b.chen = 1;
2652 + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
2653 + }
2654 + mb();
2655 + st->hcchar_copy.b.chen = 0;
2656 + local_fiq_enable();
2657 + return 0;
2658 }
2659 -void dwc_otg_hcd_release_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
2660 +
2661 +
2662 +/**
2663 + * fiq_fsm_queue_split_transaction() - Set up a host channel and FIQ state
2664 + * @hcd: Pointer to the dwc_otg_hcd struct
2665 + * @qh: Pointer to the endpoint's queue head
2666 + *
2667 + * This overrides the dwc_otg driver's normal method of queueing a transaction.
2668 + * Called from dwc_otg_hcd_queue_transactions(), this performs specific setup
2669 + * for the nominated host channel.
2670 + *
2671 + * For periodic transfers, it also peeks at the FIQ state to see if an immediate
2672 + * start is possible. If not, then the FIQ is left to start the transfer.
2673 + */
2674 +int fiq_fsm_queue_split_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
2675 {
2676 - uint32_t hub_addr, port_addr;
2677 + int start_immediate = 1, i;
2678 + hfnum_data_t hfnum;
2679 + dwc_hc_t *hc = qh->channel;
2680 + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
2681 + /* Program HC registers, setup FIQ_state, examine FIQ if periodic, start transfer (not if uframe 5) */
2682 + int hub_addr, port_addr, frame, uframe;
2683 + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
2684
2685 - if(!fiq_split_enable)
2686 - return;
2687 + if (st->fsm != FIQ_PASSTHROUGH)
2688 + return 0;
2689 + st->nr_errors = 0;
2690
2691 - hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
2692 + st->hcchar_copy.d32 = 0;
2693 + st->hcchar_copy.b.mps = hc->max_packet;
2694 + st->hcchar_copy.b.epdir = hc->ep_is_in;
2695 + st->hcchar_copy.b.devaddr = hc->dev_addr;
2696 + st->hcchar_copy.b.epnum = hc->ep_num;
2697 + st->hcchar_copy.b.eptype = hc->ep_type;
2698 + if (hc->ep_type & 0x1) {
2699 + if (hc->ep_is_in)
2700 + st->hcchar_copy.b.multicnt = 3;
2701 + else
2702 + /* Docs say set this to 1, but driver sets to 0! */
2703 + st->hcchar_copy.b.multicnt = 0;
2704 + } else {
2705 + st->hcchar_copy.b.multicnt = 1;
2706 + st->hcchar_copy.b.oddfrm = 0;
2707 + }
2708 + st->hcchar_copy.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW) ? 1 : 0;
2709 + /* Enable the channel later as a final register write. */
2710
2711 - hcd->hub_port[hub_addr] &= ~(1 << port_addr);
2712 -#ifdef FIQ_DEBUG
2713 - hcd->hub_port_alloc[hub_addr * 16 + port_addr] = -1;
2714 -#endif
2715 - fiq_print(FIQDBG_PORTHUB, "H%dP%d:RO%d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
2716 + st->hcsplt_copy.d32 = 0;
2717 + if(qh->do_split) {
2718 + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
2719 + st->hcsplt_copy.b.compsplt = 0;
2720 + st->hcsplt_copy.b.spltena = 1;
2721 + // XACTPOS is for isoc-out only but needs initialising anyway.
2722 + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_ALL;
2723 + if((qh->ep_type == DWC_OTG_EP_TYPE_ISOC) && (!qh->ep_is_in)) {
2724 + /* For packetsize 0 < L < 188, ISOC_XACTPOS_ALL.
2725 + * for longer than this, ISOC_XACTPOS_BEGIN and the FIQ
2726 + * will update as necessary.
2727 + */
2728 + if (hc->xfer_len > 188) {
2729 + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_BEGIN;
2730 + }
2731 + }
2732 + st->hcsplt_copy.b.hubaddr = (uint8_t) hub_addr;
2733 + st->hcsplt_copy.b.prtaddr = (uint8_t) port_addr;
2734 + st->hub_addr = hub_addr;
2735 + st->port_addr = port_addr;
2736 + }
2737 +
2738 + st->hctsiz_copy.d32 = 0;
2739 + st->hctsiz_copy.b.dopng = 0;
2740 + st->hctsiz_copy.b.pid = hc->data_pid_start;
2741 +
2742 + if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
2743 + hc->xfer_len = hc->max_packet;
2744 + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
2745 + hc->xfer_len = 188;
2746 + }
2747 + st->hctsiz_copy.b.xfersize = hc->xfer_len;
2748 +
2749 + st->hctsiz_copy.b.pktcnt = 1;
2750
2751 + if (hc->ep_type & 0x1) {
2752 + /*
2753 + * For potentially multi-packet transfers, must use the DMA bounce buffers. For IN transfers,
2754 + * the DMA address is the address of the first 188byte slot buffer in the bounce buffer array.
2755 + * For multi-packet OUT transfers, we need to copy the data into the bounce buffer array so the FIQ can punt
2756 + * the right address out as necessary. hc->xfer_buff and hc->xfer_len have already been set
2757 + * in assign_and_init_hc(), but this is for the eventual transaction completion only. The FIQ
2758 + * must not touch internal driver state.
2759 + */
2760 + if(!fiq_fsm_setup_periodic_dma(hcd, st, qh)) {
2761 + if (hc->align_buff) {
2762 + st->hcdma_copy.d32 = hc->align_buff;
2763 + } else {
2764 + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
2765 + }
2766 + }
2767 + } else {
2768 + if (hc->align_buff) {
2769 + st->hcdma_copy.d32 = hc->align_buff;
2770 + } else {
2771 + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
2772 + }
2773 + }
2774 + /* The FIQ depends upon no other interrupts being enabled except channel halt.
2775 + * Fixup channel interrupt mask. */
2776 + st->hcintmsk_copy.d32 = 0;
2777 + st->hcintmsk_copy.b.chhltd = 1;
2778 + st->hcintmsk_copy.b.ahberr = 1;
2779 +
2780 + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
2781 + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
2782 + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
2783 + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
2784 + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
2785 +
2786 + local_fiq_disable();
2787 + mb();
2788 +
2789 + if (hc->ep_type & 0x1) {
2790 + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
2791 + frame = (hfnum.b.frnum & ~0x7) >> 3;
2792 + uframe = hfnum.b.frnum & 0x7;
2793 + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
2794 + /* Prevent queueing near EOF1. Bad things happen if a periodic
2795 + * split transaction is queued very close to EOF.
2796 + */
2797 + start_immediate = 0;
2798 + } else if (uframe == 5) {
2799 + start_immediate = 0;
2800 + } else if (hc->ep_type == UE_ISOCHRONOUS && !hc->ep_is_in) {
2801 + start_immediate = 0;
2802 + } else if (hc->ep_is_in && fiq_fsm_too_late(hcd->fiq_state, hc->hc_num)) {
2803 + start_immediate = 0;
2804 + } else {
2805 + /* Search through all host channels to determine if a transaction
2806 + * is currently in progress */
2807 + for (i = 0; i < hcd->core_if->core_params->host_channels; i++) {
2808 + if (i == hc->hc_num || hcd->fiq_state->channel[i].fsm == FIQ_PASSTHROUGH)
2809 + continue;
2810 + switch (hcd->fiq_state->channel[i].fsm) {
2811 + /* TT is reserved for channels that are in the middle of a periodic
2812 + * split transaction.
2813 + */
2814 + case FIQ_PER_SSPLIT_STARTED:
2815 + case FIQ_PER_CSPLIT_WAIT:
2816 + case FIQ_PER_CSPLIT_NYET1:
2817 + case FIQ_PER_CSPLIT_POLL:
2818 + case FIQ_PER_ISO_OUT_ACTIVE:
2819 + case FIQ_PER_ISO_OUT_LAST:
2820 + if (hcd->fiq_state->channel[i].hub_addr == hub_addr &&
2821 + hcd->fiq_state->channel[i].port_addr == port_addr) {
2822 + start_immediate = 0;
2823 + }
2824 + break;
2825 + default:
2826 + break;
2827 + }
2828 + if (!start_immediate)
2829 + break;
2830 + }
2831 + }
2832 + }
2833 + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d %01d", hc->hc_num, start_immediate);
2834 + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08d", hfnum.b.frrem);
2835 + //fiq_print(FIQDBG_INT, hcd->fiq_state, "H:%02dP:%02d", hub_addr, port_addr);
2836 + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
2837 + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
2838 + switch (hc->ep_type) {
2839 + case UE_CONTROL:
2840 + case UE_BULK:
2841 + st->fsm = FIQ_NP_SSPLIT_STARTED;
2842 + break;
2843 + case UE_ISOCHRONOUS:
2844 + if (hc->ep_is_in) {
2845 + if (start_immediate) {
2846 + st->fsm = FIQ_PER_SSPLIT_STARTED;
2847 + } else {
2848 + st->fsm = FIQ_PER_SSPLIT_QUEUED;
2849 + }
2850 + } else {
2851 + if (start_immediate) {
2852 + /* Single-isoc OUT packets don't require FIQ involvement */
2853 + if (st->nrpackets == 1) {
2854 + st->fsm = FIQ_PER_ISO_OUT_LAST;
2855 + } else {
2856 + st->fsm = FIQ_PER_ISO_OUT_ACTIVE;
2857 + }
2858 + } else {
2859 + st->fsm = FIQ_PER_ISO_OUT_PENDING;
2860 + }
2861 + }
2862 + break;
2863 + case UE_INTERRUPT:
2864 + if (start_immediate) {
2865 + st->fsm = FIQ_PER_SSPLIT_STARTED;
2866 + } else {
2867 + st->fsm = FIQ_PER_SSPLIT_QUEUED;
2868 + }
2869 + default:
2870 + break;
2871 + }
2872 + if (start_immediate) {
2873 + /* Set the oddfrm bit as close as possible to actual queueing */
2874 + frame = dwc_otg_hcd_get_frame_number(hcd);
2875 + st->expected_uframe = (frame + 1) & 0x3FFF;
2876 + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
2877 + st->hcchar_copy.b.chen = 1;
2878 + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
2879 + }
2880 + mb();
2881 + local_fiq_enable();
2882 + return 0;
2883 }
2884
2885
2886 @@ -1404,16 +1908,11 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
2887 {
2888 dwc_list_link_t *qh_ptr;
2889 dwc_otg_qh_t *qh;
2890 - dwc_otg_qtd_t *qtd;
2891 int num_channels;
2892 dwc_irqflags_t flags;
2893 dwc_spinlock_t *channel_lock = hcd->channel_lock;
2894 dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
2895
2896 -#ifdef DEBUG_SOF
2897 - DWC_DEBUGPL(DBG_HCD, " Select Transactions\n");
2898 -#endif
2899 -
2900 #ifdef DEBUG_HOST_CHANNELS
2901 last_sel_trans_num_per_scheduled = 0;
2902 last_sel_trans_num_nonper_scheduled = 0;
2903 @@ -1428,26 +1927,11 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
2904
2905 qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
2906
2907 - if(qh->do_split) {
2908 - qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
2909 - if(!(qh->ep_type == UE_ISOCHRONOUS &&
2910 - (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
2911 - qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END))) {
2912 - if(dwc_otg_hcd_allocate_port(hcd, qh))
2913 - {
2914 - qh_ptr = DWC_LIST_NEXT(qh_ptr);
2915 - g_next_sched_frame = dwc_frame_num_inc(dwc_otg_hcd_get_frame_number(hcd), 1);
2916 - continue;
2917 - }
2918 - }
2919 - }
2920 -
2921 if (microframe_schedule) {
2922 // Make sure we leave one channel for non periodic transactions.
2923 DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
2924 if (hcd->available_host_channels <= 1) {
2925 DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
2926 - if(qh->do_split) dwc_otg_hcd_release_port(hcd, qh);
2927 break;
2928 }
2929 hcd->available_host_channels--;
2930 @@ -1483,27 +1967,24 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
2931 !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
2932
2933 qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
2934 -
2935 /*
2936 * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
2937 * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
2938 * cheeky devices that just hold off using NAKs
2939 */
2940 - if (nak_holdoff_enable && qh->do_split) {
2941 - if (qh->nak_frame != 0xffff &&
2942 - dwc_full_frame_num(qh->nak_frame) ==
2943 - dwc_full_frame_num(dwc_otg_hcd_get_frame_number(hcd))) {
2944 - /*
2945 - * Revisit: Need to avoid trampling on periodic scheduling.
2946 - * Currently we are safe because g_np_count != g_np_sent whenever we hit this,
2947 - * but if this behaviour is changed then periodic endpoints will get a slower
2948 - * polling rate.
2949 - */
2950 - g_next_sched_frame = ((qh->nak_frame + 8) & ~7) & DWC_HFNUM_MAX_FRNUM;
2951 - qh_ptr = DWC_LIST_NEXT(qh_ptr);
2952 - continue;
2953 - } else {
2954 - qh->nak_frame = 0xffff;
2955 + if (nak_holdoff && qh->do_split) {
2956 + if (qh->nak_frame != 0xffff) {
2957 + uint16_t next_frame = dwc_frame_num_inc(qh->nak_frame, (qh->ep_type == UE_BULK) ? nak_holdoff : 8);
2958 + uint16_t frame = dwc_otg_hcd_get_frame_number(hcd);
2959 + if (dwc_frame_num_le(frame, next_frame)) {
2960 + if(dwc_frame_num_le(next_frame, hcd->fiq_state->next_sched_frame)) {
2961 + hcd->fiq_state->next_sched_frame = next_frame;
2962 + }
2963 + qh_ptr = DWC_LIST_NEXT(qh_ptr);
2964 + continue;
2965 + } else {
2966 + qh->nak_frame = 0xFFFF;
2967 + }
2968 }
2969 }
2970
2971 @@ -1532,12 +2013,31 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
2972 &qh->qh_list_entry);
2973 DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
2974
2975 - g_np_sent++;
2976
2977 if (!microframe_schedule)
2978 hcd->non_periodic_channels++;
2979 }
2980 -
2981 + /* we moved a non-periodic QH to the active schedule. If the inactive queue is empty,
2982 + * stop the FIQ from kicking us. We could potentially still have elements here if we
2983 + * ran out of host channels.
2984 + */
2985 + if (fiq_enable) {
2986 + if (DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive)) {
2987 + hcd->fiq_state->kick_np_queues = 0;
2988 + } else {
2989 + /* For each entry remaining in the NP inactive queue,
2990 + * if this a NAK'd retransmit then don't set the kick flag.
2991 + */
2992 + if(nak_holdoff) {
2993 + DWC_LIST_FOREACH(qh_ptr, &hcd->non_periodic_sched_inactive) {
2994 + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
2995 + if (qh->nak_frame == 0xFFFF) {
2996 + hcd->fiq_state->kick_np_queues = 1;
2997 + }
2998 + }
2999 + }
3000 + }
3001 + }
3002 if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
3003 ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
3004
3005 @@ -1582,6 +2082,12 @@ static int queue_transaction(dwc_otg_hcd
3006 hc->qh->ping_state = 0;
3007 }
3008 } else if (!hc->xfer_started) {
3009 + if (fiq_fsm_enable && hc->error_state) {
3010 + hcd->fiq_state->channel[hc->hc_num].nr_errors =
3011 + DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list)->error_count;
3012 + hcd->fiq_state->channel[hc->hc_num].fsm =
3013 + FIQ_PASSTHROUGH_ERRORSTATE;
3014 + }
3015 dwc_otg_hc_start_transfer(hcd->core_if, hc);
3016 hc->qh->ping_state = 0;
3017 }
3018 @@ -1634,7 +2140,7 @@ static void process_periodic_channels(dw
3019 hptxsts_data_t tx_status;
3020 dwc_list_link_t *qh_ptr;
3021 dwc_otg_qh_t *qh;
3022 - int status;
3023 + int status = 0;
3024 int no_queue_space = 0;
3025 int no_fifo_space = 0;
3026
3027 @@ -1663,27 +2169,34 @@ static void process_periodic_channels(dw
3028
3029 // Do not send a split start transaction any later than frame .6
3030 // Note, we have to schedule a periodic in .5 to make it go in .6
3031 - if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
3032 + if(fiq_fsm_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
3033 {
3034 qh_ptr = qh_ptr->next;
3035 - g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
3036 + hcd->fiq_state->next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
3037 continue;
3038 }
3039
3040 - /*
3041 - * Set a flag if we're queuing high-bandwidth in slave mode.
3042 - * The flag prevents any halts to get into the request queue in
3043 - * the middle of multiple high-bandwidth packets getting queued.
3044 - */
3045 - if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
3046 - hcd->core_if->queuing_high_bandwidth = 1;
3047 - }
3048 - status =
3049 - queue_transaction(hcd, qh->channel,
3050 - tx_status.b.ptxfspcavail);
3051 - if (status < 0) {
3052 - no_fifo_space = 1;
3053 - break;
3054 + if (fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
3055 + if (qh->do_split)
3056 + fiq_fsm_queue_split_transaction(hcd, qh);
3057 + else
3058 + fiq_fsm_queue_isoc_transaction(hcd, qh);
3059 + } else {
3060 +
3061 + /*
3062 + * Set a flag if we're queueing high-bandwidth in slave mode.
3063 + * The flag prevents any halts to get into the request queue in
3064 + * the middle of multiple high-bandwidth packets getting queued.
3065 + */
3066 + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
3067 + hcd->core_if->queuing_high_bandwidth = 1;
3068 + }
3069 + status = queue_transaction(hcd, qh->channel,
3070 + tx_status.b.ptxfspcavail);
3071 + if (status < 0) {
3072 + no_fifo_space = 1;
3073 + break;
3074 + }
3075 }
3076
3077 /*
3078 @@ -1800,25 +2313,19 @@ static void process_non_periodic_channel
3079 qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
3080 qh_list_entry);
3081
3082 - // Do not send a split start transaction any later than frame .5
3083 - // non periodic transactions will start immediately in this uframe
3084 - if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
3085 - {
3086 - g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
3087 - break;
3088 - }
3089 + if(fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
3090 + fiq_fsm_queue_split_transaction(hcd, qh);
3091 + } else {
3092 + status = queue_transaction(hcd, qh->channel,
3093 + tx_status.b.nptxfspcavail);
3094
3095 - status =
3096 - queue_transaction(hcd, qh->channel,
3097 - tx_status.b.nptxfspcavail);
3098 -
3099 - if (status > 0) {
3100 - more_to_do = 1;
3101 - } else if (status < 0) {
3102 - no_fifo_space = 1;
3103 - break;
3104 + if (status > 0) {
3105 + more_to_do = 1;
3106 + } else if (status < 0) {
3107 + no_fifo_space = 1;
3108 + break;
3109 + }
3110 }
3111 -
3112 /* Advance to next QH, skipping start-of-list entry. */
3113 hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
3114 if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
3115 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
3116 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
3117 @@ -40,6 +40,8 @@
3118 #include "dwc_otg_core_if.h"
3119 #include "dwc_list.h"
3120 #include "dwc_otg_cil.h"
3121 +#include "dwc_otg_fiq_fsm.h"
3122 +
3123
3124 /**
3125 * @file
3126 @@ -585,6 +587,12 @@ struct dwc_otg_hcd {
3127 /** Frame List DMA address */
3128 dma_addr_t frame_list_dma;
3129
3130 + struct fiq_stack *fiq_stack;
3131 + struct fiq_state *fiq_state;
3132 +
3133 + /** Virtual address for split transaction DMA bounce buffers */
3134 + struct fiq_dma_blob *fiq_dmab;
3135 +
3136 #ifdef DEBUG
3137 uint32_t frrem_samples;
3138 uint64_t frrem_accum;
3139 @@ -615,6 +623,9 @@ extern void dwc_otg_hcd_queue_transactio
3140 int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
3141 void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
3142
3143 +extern int fiq_fsm_queue_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
3144 +extern int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh);
3145 +extern void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num);
3146
3147 /** @} */
3148
3149 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
3150 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
3151 @@ -34,7 +34,6 @@
3152
3153 #include "dwc_otg_hcd.h"
3154 #include "dwc_otg_regs.h"
3155 -#include "dwc_otg_mphi_fix.h"
3156
3157 #include <linux/jiffies.h>
3158 #include <mach/hardware.h>
3159 @@ -47,33 +46,8 @@ extern bool microframe_schedule;
3160 * This file contains the implementation of the HCD Interrupt handlers.
3161 */
3162
3163 -/*
3164 - * Some globals to communicate between the FIQ and INTERRUPT
3165 - */
3166 -
3167 -void * dummy_send;
3168 -mphi_regs_t c_mphi_regs;
3169 -volatile void *dwc_regs_base;
3170 int fiq_done, int_done;
3171
3172 -gintsts_data_t gintsts_saved = {.d32 = 0};
3173 -hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
3174 -hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
3175 -int split_out_xfersize[MAX_EPS_CHANNELS];
3176 -haint_data_t haint_saved;
3177 -
3178 -int g_next_sched_frame, g_np_count, g_np_sent;
3179 -static int mphi_int_count = 0 ;
3180 -
3181 -hcchar_data_t nak_hcchar;
3182 -hctsiz_data_t nak_hctsiz;
3183 -hcsplt_data_t nak_hcsplt;
3184 -int nak_count;
3185 -
3186 -int complete_sched[MAX_EPS_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
3187 -int split_start_frame[MAX_EPS_CHANNELS];
3188 -int queued_port[MAX_EPS_CHANNELS];
3189 -
3190 #ifdef FIQ_DEBUG
3191 char buffer[1000*16];
3192 int wptr;
3193 @@ -83,12 +57,10 @@ void notrace _fiq_print(FIQDBG_T dbg_lvl
3194 va_list args;
3195 char text[17];
3196 hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
3197 - unsigned long flags;
3198
3199 - local_irq_save(flags);
3200 - local_fiq_disable();
3201 if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
3202 {
3203 + local_fiq_disable();
3204 snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
3205 va_start(args, fmt);
3206 vsnprintf(text+8, 9, fmt, args);
3207 @@ -96,410 +68,21 @@ void notrace _fiq_print(FIQDBG_T dbg_lvl
3208
3209 memcpy(buffer + wptr, text, 16);
3210 wptr = (wptr + 16) % sizeof(buffer);
3211 + local_fiq_enable();
3212 }
3213 - local_irq_restore(flags);
3214 }
3215 #endif
3216
3217 -void notrace fiq_queue_request(int channel, int odd_frame)
3218 -{
3219 - hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
3220 - hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
3221 - hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10) };
3222 -
3223 - if(hcsplt.b.spltena == 0)
3224 - {
3225 - fiq_print(FIQDBG_ERR, "SPLTENA ");
3226 - BUG();
3227 - }
3228 -
3229 - if(hcchar.b.epdir == 1)
3230 - {
3231 - fiq_print(FIQDBG_SCHED, "IN Ch %d", channel);
3232 - }
3233 - else
3234 - {
3235 - hctsiz.b.xfersize = 0;
3236 - fiq_print(FIQDBG_SCHED, "OUT Ch %d", channel);
3237 - }
3238 - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x10), hctsiz.d32);
3239 -
3240 - hcsplt.b.compsplt = 1;
3241 - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x4), hcsplt.d32);
3242 -
3243 - // Send the Split complete
3244 - hcchar.b.chen = 1;
3245 - hcchar.b.oddfrm = odd_frame ? 1 : 0;
3246 -
3247 - // Post this for transmit on the next frame for periodic or this frame for non-periodic
3248 - fiq_print(FIQDBG_SCHED, "SND_%s", odd_frame ? "ODD " : "EVEN");
3249 -
3250 - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x0), hcchar.d32);
3251 -}
3252 -
3253 -static int last_sof = -1;
3254 -
3255 -/*
3256 -** Function to handle the start of frame interrupt, choose whether we need to do anything and
3257 -** therefore trigger the main interrupt
3258 -**
3259 -** returns int != 0 - interrupt has been handled
3260 -*/
3261 -int diff;
3262 -
3263 -int notrace fiq_sof_handle(hfnum_data_t hfnum)
3264 -{
3265 - int handled = 0;
3266 - int i;
3267 -
3268 - // Just check that once we're running we don't miss a SOF
3269 - /*if(last_sof != -1 && (hfnum.b.frnum != ((last_sof + 1) & 0x3fff)))
3270 - {
3271 - fiq_print(FIQDBG_ERR, "LASTSOF ");
3272 - fiq_print(FIQDBG_ERR, "%4d%d ", last_sof / 8, last_sof & 7);
3273 - fiq_print(FIQDBG_ERR, "%4d%d ", hfnum.b.frnum / 8, hfnum.b.frnum & 7);
3274 - BUG();
3275 - }*/
3276 -
3277 - // Only start remembering the last sof when the interrupt has been
3278 - // enabled (we don't check the mask to come in here...)
3279 - if(last_sof != -1 || FIQ_READ(dwc_regs_base + 0x18) & (1<<3))
3280 - last_sof = hfnum.b.frnum;
3281 -
3282 - for(i = 0; i < MAX_EPS_CHANNELS; i++)
3283 - {
3284 - if(complete_sched[i] != -1)
3285 - {
3286 - if(complete_sched[i] <= hfnum.b.frnum || (complete_sched[i] > 0x3f00 && hfnum.b.frnum < 0xf0))
3287 - {
3288 - fiq_queue_request(i, hfnum.b.frnum & 1);
3289 - complete_sched[i] = -1;
3290 - }
3291 - }
3292 -
3293 - if(complete_sched[i] != -1)
3294 - {
3295 - // This is because we've seen a split complete occur with no start...
3296 - // most likely because missed the complete 0x3fff frames ago!
3297 -
3298 - diff = (hfnum.b.frnum + 0x3fff - complete_sched[i]) & 0x3fff ;
3299 - if(diff > 32 && diff < 0x3f00)
3300 - {
3301 - fiq_print(FIQDBG_ERR, "SPLTMISS");
3302 - BUG();
3303 - }
3304 - }
3305 - }
3306 -
3307 - if(g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
3308 - {
3309 - /*
3310 - * If np_count != np_sent that means we need to queue non-periodic (bulk) packets this packet
3311 - * g_next_sched_frame is the next frame we have periodic packets for
3312 - *
3313 - * if neither of these are required for this frame then just clear the interrupt
3314 - */
3315 - handled = 1;
3316 -
3317 - }
3318 -
3319 - return handled;
3320 -}
3321 -
3322 -int notrace port_id(hcsplt_data_t hcsplt)
3323 -{
3324 - return hcsplt.b.prtaddr + (hcsplt.b.hubaddr << 8);
3325 -}
3326 -
3327 -int notrace fiq_hcintr_handle(int channel, hfnum_data_t hfnum)
3328 -{
3329 - hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
3330 - hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
3331 - hcint_data_t hcint = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x8) };
3332 - hcintmsk_data_t hcintmsk = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0xc) };
3333 - hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10)};
3334 -
3335 - hcint_saved[channel].d32 |= hcint.d32;
3336 - hcintmsk_saved[channel].d32 = hcintmsk.d32;
3337 -
3338 - if(hcsplt.b.spltena)
3339 - {
3340 - fiq_print(FIQDBG_PORTHUB, "ph: %4x", port_id(hcsplt));
3341 - if(hcint.b.chhltd)
3342 - {
3343 - fiq_print(FIQDBG_SCHED, "CH HLT %d", channel);
3344 - fiq_print(FIQDBG_SCHED, "%08x", hcint_saved[channel]);
3345 - }
3346 - if(hcint.b.stall || hcint.b.xacterr || hcint.b.bblerr || hcint.b.frmovrun || hcint.b.datatglerr)
3347 - {
3348 - queued_port[channel] = 0;
3349 - fiq_print(FIQDBG_ERR, "CHAN ERR");
3350 - }
3351 - if(hcint.b.xfercomp)
3352 - {
3353 - // Clear the port allocation and transmit anything also on this port
3354 - queued_port[channel] = 0;
3355 - fiq_print(FIQDBG_SCHED, "XFERCOMP");
3356 - }
3357 - if(hcint.b.nak)
3358 - {
3359 - queued_port[channel] = 0;
3360 - fiq_print(FIQDBG_SCHED, "NAK");
3361 - }
3362 - if(hcint.b.ack && !hcsplt.b.compsplt)
3363 - {
3364 - int i;
3365 -
3366 - // Do not complete isochronous out transactions
3367 - if(hcchar.b.eptype == 1 && hcchar.b.epdir == 0)
3368 - {
3369 - queued_port[channel] = 0;
3370 - fiq_print(FIQDBG_SCHED, "ISOC_OUT");
3371 - }
3372 - else
3373 - {
3374 - // Make sure we check the port / hub combination that we sent this split on.
3375 - // Do not queue a second request to the same port
3376 - for(i = 0; i < MAX_EPS_CHANNELS; i++)
3377 - {
3378 - if(port_id(hcsplt) == queued_port[i])
3379 - {
3380 - fiq_print(FIQDBG_ERR, "PORTERR ");
3381 - //BUG();
3382 - }
3383 - }
3384 -
3385 - split_start_frame[channel] = (hfnum.b.frnum + 1) & ~7;
3386 -
3387 - // Note, the size of an OUT is in the start split phase, not
3388 - // the complete split
3389 - split_out_xfersize[channel] = hctsiz.b.xfersize;
3390 -
3391 - hcint_saved[channel].b.chhltd = 0;
3392 - hcint_saved[channel].b.ack = 0;
3393 -
3394 - queued_port[channel] = port_id(hcsplt);
3395 -
3396 - if(hcchar.b.eptype & 1)
3397 - {
3398 - // Send the periodic complete in the same oddness frame as the ACK went...
3399 - fiq_queue_request(channel, !(hfnum.b.frnum & 1));
3400 - // complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
3401 - }
3402 - else
3403 - {
3404 - // Schedule the split complete to occur later
3405 - complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 2);
3406 - fiq_print(FIQDBG_SCHED, "ACK%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
3407 - }
3408 - }
3409 - }
3410 - if(hcint.b.nyet)
3411 - {
3412 - fiq_print(FIQDBG_ERR, "NYETERR1");
3413 - //BUG();
3414 - // Can transmit a split complete up to uframe .0 of the next frame
3415 - if(hfnum.b.frnum <= dwc_frame_num_inc(split_start_frame[channel], 8))
3416 - {
3417 - // Send it next frame
3418 - if(hcchar.b.eptype & 1) // type 1 & 3 are interrupt & isoc
3419 - {
3420 - fiq_print(FIQDBG_SCHED, "NYT:SEND");
3421 - fiq_queue_request(channel, !(hfnum.b.frnum & 1));
3422 - }
3423 - else
3424 - {
3425 - // Schedule non-periodic access for next frame (the odd-even bit doesn't effect NP)
3426 - complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
3427 - fiq_print(FIQDBG_SCHED, "NYT%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
3428 - }
3429 - hcint_saved[channel].b.chhltd = 0;
3430 - hcint_saved[channel].b.nyet = 0;
3431 - }
3432 - else
3433 - {
3434 - queued_port[channel] = 0;
3435 - fiq_print(FIQDBG_ERR, "NYETERR2");
3436 - //BUG();
3437 - }
3438 - }
3439 - }
3440 - else
3441 - {
3442 - /*
3443 - * If we have any of NAK, ACK, Datatlgerr active on a
3444 - * non-split channel, the sole reason is to reset error
3445 - * counts for a previously broken transaction. The FIQ
3446 - * will thrash on NAK IN and ACK OUT in particular so
3447 - * handle it "once" and allow the IRQ to do the rest.
3448 - */
3449 - hcint.d32 &= hcintmsk.d32;
3450 - if(hcint.b.nak)
3451 - {
3452 - hcintmsk.b.nak = 0;
3453 - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0xc), hcintmsk.d32);
3454 - }
3455 - if (hcint.b.ack)
3456 - {
3457 - hcintmsk.b.ack = 0;
3458 - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0xc), hcintmsk.d32);
3459 - }
3460 - }
3461 -
3462 - // Clear the interrupt, this will also clear the HAINT bit
3463 - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x8), hcint.d32);
3464 - return hcint_saved[channel].d32 == 0;
3465 -}
3466 -
3467 -gintsts_data_t gintsts;
3468 -gintmsk_data_t gintmsk;
3469 -// triggered: The set of interrupts that were triggered
3470 -// handled: The set of interrupts that have been handled (no IRQ is
3471 -// required)
3472 -// keep: The set of interrupts we want to keep unmasked even though we
3473 -// want to trigger an IRQ to handle it (SOF and HCINTR)
3474 -gintsts_data_t triggered, handled, keep;
3475 -hfnum_data_t hfnum;
3476 -
3477 -void __attribute__ ((naked)) notrace dwc_otg_hcd_handle_fiq(void)
3478 -{
3479 -
3480 - /* entry takes care to store registers we will be treading on here */
3481 - asm __volatile__ (
3482 - "mov ip, sp ;"
3483 - /* stash FIQ and normal regs */
3484 - "stmdb sp!, {r0-r12, lr};"
3485 - /* !! THIS SETS THE FRAME, adjust to > sizeof locals */
3486 - "sub fp, ip, #512 ;"
3487 - );
3488 -
3489 - // Cannot put local variables at the beginning of the function
3490 - // because otherwise 'C' will play with the stack pointer. any locals
3491 - // need to be inside the following block
3492 - do
3493 - {
3494 - fiq_done++;
3495 - gintsts.d32 = FIQ_READ(dwc_regs_base + 0x14);
3496 - gintmsk.d32 = FIQ_READ(dwc_regs_base + 0x18);
3497 - hfnum.d32 = FIQ_READ(dwc_regs_base + 0x408);
3498 - triggered.d32 = gintsts.d32 & gintmsk.d32;
3499 - handled.d32 = 0;
3500 - keep.d32 = 0;
3501 - fiq_print(FIQDBG_INT, "FIQ ");
3502 - fiq_print(FIQDBG_INT, "%08x", gintsts.d32);
3503 - fiq_print(FIQDBG_INT, "%08x", gintmsk.d32);
3504 - if(gintsts.d32)
3505 - {
3506 - // If port enabled
3507 - if((FIQ_READ(dwc_regs_base + 0x440) & 0xf) == 0x5)
3508 - {
3509 - if(gintsts.b.sofintr)
3510 - {
3511 - if(fiq_sof_handle(hfnum))
3512 - {
3513 - handled.b.sofintr = 1; /* Handled in FIQ */
3514 - }
3515 - else
3516 - {
3517 - /* Keer interrupt unmasked */
3518 - keep.b.sofintr = 1;
3519 - }
3520 - {
3521 - // Need to make sure the read and clearing of the SOF interrupt is as close as possible to avoid the possibility of missing
3522 - // a start of frame interrupt
3523 - gintsts_data_t gintsts = { .b.sofintr = 1 };
3524 - FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
3525 - }
3526 - }
3527 -
3528 - if(fiq_split_enable && gintsts.b.hcintr)
3529 - {
3530 - int i;
3531 - haint_data_t haint;
3532 - haintmsk_data_t haintmsk;
3533 -
3534 - haint.d32 = FIQ_READ(dwc_regs_base + 0x414);
3535 - haintmsk.d32 = FIQ_READ(dwc_regs_base + 0x418);
3536 - haint.d32 &= haintmsk.d32;
3537 - haint_saved.d32 |= haint.d32;
3538 -
3539 - fiq_print(FIQDBG_INT, "hcintr");
3540 - fiq_print(FIQDBG_INT, "%08x", FIQ_READ(dwc_regs_base + 0x414));
3541 -
3542 - // Go through each channel that has an enabled interrupt
3543 - for(i = 0; i < 16; i++)
3544 - if((haint.d32 >> i) & 1)
3545 - if(fiq_hcintr_handle(i, hfnum))
3546 - haint_saved.d32 &= ~(1 << i); /* this was handled */
3547 -
3548 - /* If we've handled all host channel interrupts then don't trigger the interrupt */
3549 - if(haint_saved.d32 == 0)
3550 - {
3551 - handled.b.hcintr = 1;
3552 - }
3553 - else
3554 - {
3555 - /* Make sure we keep the channel interrupt unmasked when triggering the IRQ */
3556 - keep.b.hcintr = 1;
3557 - }
3558 -
3559 - {
3560 - gintsts_data_t gintsts = { .b.hcintr = 1 };
3561 -
3562 - // Always clear the channel interrupt
3563 - FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
3564 - }
3565 - }
3566 - }
3567 - else
3568 - {
3569 - last_sof = -1;
3570 - }
3571 - }
3572 -
3573 - // Mask out the interrupts triggered - those handled - don't mask out the ones we want to keep
3574 - gintmsk.d32 = keep.d32 | (gintmsk.d32 & ~(triggered.d32 & ~handled.d32));
3575 - // Save those that were triggered but not handled
3576 - gintsts_saved.d32 |= triggered.d32 & ~handled.d32;
3577 - FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
3578 -
3579 - // Clear and save any unhandled interrupts and trigger the interrupt
3580 - if(gintsts_saved.d32)
3581 - {
3582 - /* To enable the MPHI interrupt (INT 32)
3583 - */
3584 - FIQ_WRITE( c_mphi_regs.outdda, (int) dummy_send);
3585 - FIQ_WRITE( c_mphi_regs.outddb, (1 << 29));
3586 -
3587 - mphi_int_count++;
3588 - }
3589 - }
3590 - while(0);
3591 -
3592 - mb();
3593 -
3594 - /* exit back to normal mode restoring everything */
3595 - asm __volatile__ (
3596 - /* return FIQ regs back to pristine state
3597 - * and get normal regs back
3598 - */
3599 - "ldmia sp!, {r0-r12, lr};"
3600 -
3601 - /* return */
3602 - "subs pc, lr, #4;"
3603 - );
3604 -}
3605 -
3606 /** This function handles interrupts for the HCD. */
3607 int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
3608 {
3609 int retval = 0;
3610 static int last_time;
3611 -
3612 dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
3613 gintsts_data_t gintsts;
3614 gintmsk_data_t gintmsk;
3615 hfnum_data_t hfnum;
3616 + haintmsk_data_t haintmsk;
3617
3618 #ifdef DEBUG
3619 dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
3620 @@ -516,15 +99,29 @@ int32_t dwc_otg_hcd_handle_intr(dwc_otg_
3621 DWC_SPINLOCK(dwc_otg_hcd->lock);
3622 /* Check if HOST Mode */
3623 if (dwc_otg_is_host_mode(core_if)) {
3624 - local_fiq_disable();
3625 - gintmsk.d32 |= gintsts_saved.d32;
3626 - gintsts.d32 |= gintsts_saved.d32;
3627 - gintsts_saved.d32 = 0;
3628 - local_fiq_enable();
3629 + if (fiq_enable) {
3630 + local_fiq_disable();
3631 + /* Pull in from the FIQ's disabled mask */
3632 + gintmsk.d32 = gintmsk.d32 | ~(dwc_otg_hcd->fiq_state->gintmsk_saved.d32);
3633 + dwc_otg_hcd->fiq_state->gintmsk_saved.d32 = ~0;
3634 + }
3635 +
3636 + if (fiq_fsm_enable && ( 0x0000FFFF & ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint))) {
3637 + gintsts.b.hcintr = 1;
3638 + }
3639 +
3640 + /* Danger will robinson: fake a SOF if necessary */
3641 + if (fiq_fsm_enable && (dwc_otg_hcd->fiq_state->gintmsk_saved.b.sofintr == 1)) {
3642 + gintsts.b.sofintr = 1;
3643 + }
3644 + gintsts.d32 &= gintmsk.d32;
3645 +
3646 + if (fiq_enable)
3647 + local_fiq_enable();
3648 +
3649 if (!gintsts.d32) {
3650 goto exit_handler_routine;
3651 }
3652 - gintsts.d32 &= gintmsk.d32;
3653
3654 #ifdef DEBUG
3655 // We should be OK doing this because the common interrupts should already have been serviced
3656 @@ -544,12 +141,7 @@ int32_t dwc_otg_hcd_handle_intr(dwc_otg_
3657 gintsts.d32, core_if);
3658 #endif
3659 hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
3660 - if (gintsts.b.sofintr && g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
3661 - {
3662 - /* Note, we should never get here if the FIQ is doing it's job properly*/
3663 - retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
3664 - }
3665 - else if (gintsts.b.sofintr) {
3666 + if (gintsts.b.sofintr) {
3667 retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
3668 }
3669
3670 @@ -604,37 +196,43 @@ int32_t dwc_otg_hcd_handle_intr(dwc_otg_
3671 }
3672
3673 exit_handler_routine:
3674 -
3675 - if (fiq_fix_enable)
3676 - {
3677 + if (fiq_enable) {
3678 + gintmsk_data_t gintmsk_new;
3679 + haintmsk_data_t haintmsk_new;
3680 local_fiq_disable();
3681 - // Make sure that we don't clear the interrupt if we've still got pending work to do
3682 - if(gintsts_saved.d32 == 0)
3683 - {
3684 - /* Clear the MPHI interrupt */
3685 - DWC_WRITE_REG32(c_mphi_regs.intstat, (1<<16));
3686 - if (mphi_int_count >= 60)
3687 - {
3688 - DWC_WRITE_REG32(c_mphi_regs.ctrl, ((1<<31) + (1<<16)));
3689 - while(!(DWC_READ_REG32(c_mphi_regs.ctrl) & (1 << 17)))
3690 - ;
3691 - DWC_WRITE_REG32(c_mphi_regs.ctrl, (1<<31));
3692 - mphi_int_count = 0;
3693 - }
3694 - int_done++;
3695 - }
3696 -
3697 - // Unmask handled interrupts
3698 - FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
3699 - //DWC_MODIFY_REG32((uint32_t *)IO_ADDRESS(USB_BASE + 0x8), 0 , 1);
3700 + gintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->gintmsk_saved.d32;
3701 + if(fiq_fsm_enable)
3702 + haintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->haintmsk_saved.d32;
3703 + else
3704 + haintmsk_new.d32 = 0x0000FFFF;
3705
3706 + /* The FIQ could have sneaked another interrupt in. If so, don't clear MPHI */
3707 + if ((gintmsk_new.d32 == ~0) && (haintmsk_new.d32 == 0x0000FFFF)) {
3708 + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.intstat, (1<<16));
3709 + if (dwc_otg_hcd->fiq_state->mphi_int_count >= 50) {
3710 + fiq_print(FIQDBG_INT, dwc_otg_hcd->fiq_state, "MPHI CLR");
3711 + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, ((1<<31) + (1<<16)));
3712 + while (!(DWC_READ_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & (1 << 17)))
3713 + ;
3714 + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, (1<<31));
3715 + dwc_otg_hcd->fiq_state->mphi_int_count = 0;
3716 + }
3717 + int_done++;
3718 + }
3719 + haintmsk.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
3720 + /* Re-enable interrupts that the FIQ masked (first time round) */
3721 + FIQ_WRITE(dwc_otg_hcd->fiq_state->dwc_regs_base + GINTMSK, gintmsk.d32);
3722 local_fiq_enable();
3723
3724 - if((jiffies / HZ) > last_time)
3725 - {
3726 + if ((jiffies / HZ) > last_time) {
3727 + //dwc_otg_qh_t *qh;
3728 + //dwc_list_link_t *cur;
3729 /* Once a second output the fiq and irq numbers, useful for debug */
3730 last_time = jiffies / HZ;
3731 - DWC_DEBUGPL(DBG_USER, "int_done = %d fiq_done = %d\n", int_done, fiq_done);
3732 + // DWC_WARN("np_kick=%d AHC=%d sched_frame=%d cur_frame=%d int_done=%d fiq_done=%d",
3733 + // dwc_otg_hcd->fiq_state->kick_np_queues, dwc_otg_hcd->available_host_channels,
3734 + // dwc_otg_hcd->fiq_state->next_sched_frame, hfnum.b.frnum, int_done, dwc_otg_hcd->fiq_state->fiq_done);
3735 + //printk(KERN_WARNING "Periodic queues:\n");
3736 }
3737 }
3738
3739 @@ -686,6 +284,7 @@ static inline void track_missed_sofs(uin
3740 int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
3741 {
3742 hfnum_data_t hfnum;
3743 + gintsts_data_t gintsts = { .d32 = 0 };
3744 dwc_list_link_t *qh_entry;
3745 dwc_otg_qh_t *qh;
3746 dwc_otg_transaction_type_e tr_type;
3747 @@ -732,8 +331,8 @@ int32_t dwc_otg_hcd_handle_sof_intr(dwc_
3748 }
3749 }
3750 }
3751 -
3752 - g_next_sched_frame = next_sched_frame;
3753 + if (fiq_enable)
3754 + hcd->fiq_state->next_sched_frame = next_sched_frame;
3755
3756 tr_type = dwc_otg_hcd_select_transactions(hcd);
3757 if (tr_type != DWC_OTG_TRANSACTION_NONE) {
3758 @@ -741,10 +340,11 @@ int32_t dwc_otg_hcd_handle_sof_intr(dwc_
3759 did_something = 1;
3760 }
3761
3762 - /* Clear interrupt */
3763 - gintsts.b.sofintr = 1;
3764 - DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
3765 -
3766 + /* Clear interrupt - but do not trample on the FIQ sof */
3767 + if (!fiq_fsm_enable) {
3768 + gintsts.b.sofintr = 1;
3769 + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
3770 + }
3771 return 1;
3772 }
3773
3774 @@ -1020,19 +620,21 @@ int32_t dwc_otg_hcd_handle_hc_intr(dwc_o
3775 {
3776 int i;
3777 int retval = 0;
3778 - haint_data_t haint;
3779 + haint_data_t haint = { .d32 = 0 } ;
3780
3781 /* Clear appropriate bits in HCINTn to clear the interrupt bit in
3782 * GINTSTS */
3783
3784 - haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
3785 + if (!fiq_fsm_enable)
3786 + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
3787
3788 // Overwrite with saved interrupts from fiq handler
3789 - if(fiq_split_enable)
3790 + if(fiq_fsm_enable)
3791 {
3792 + /* check the mask? */
3793 local_fiq_disable();
3794 - haint.d32 = haint_saved.d32;
3795 - haint_saved.d32 = 0;
3796 + haint.b2.chint |= ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint);
3797 + dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
3798 local_fiq_enable();
3799 }
3800
3801 @@ -1076,9 +678,7 @@ static uint32_t get_actual_xfer_length(d
3802 *short_read = (hctsiz.b.xfersize != 0);
3803 }
3804 } else if (hc->qh->do_split) {
3805 - if(fiq_split_enable)
3806 - length = split_out_xfersize[hc->hc_num];
3807 - else
3808 + //length = split_out_xfersize[hc->hc_num];
3809 length = qtd->ssplit_out_xfer_count;
3810 } else {
3811 length = hc->xfer_len;
3812 @@ -1325,19 +925,17 @@ static void release_channel(dwc_otg_hcd_
3813 int free_qtd;
3814 dwc_irqflags_t flags;
3815 dwc_spinlock_t *channel_lock = hcd->channel_lock;
3816 -#ifdef FIQ_DEBUG
3817 - int endp = qtd->urb ? qtd->urb->pipe_info.ep_num : 0;
3818 -#endif
3819 +
3820 int hog_port = 0;
3821
3822 DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
3823 __func__, hc->hc_num, halt_status, hc->xfer_len);
3824
3825 - if(fiq_split_enable && hc->do_split) {
3826 + if(fiq_fsm_enable && hc->do_split) {
3827 if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
3828 if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
3829 hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
3830 - hog_port = 1;
3831 + hog_port = 0;
3832 }
3833 }
3834 }
3835 @@ -1394,6 +992,8 @@ cleanup:
3836 * function clears the channel interrupt enables and conditions, so
3837 * there's no need to clear the Channel Halted interrupt separately.
3838 */
3839 + if (fiq_fsm_enable && hcd->fiq_state->channel[hc->hc_num].fsm != FIQ_PASSTHROUGH)
3840 + dwc_otg_cleanup_fiq_channel(hcd, hc->hc_num);
3841 dwc_otg_hc_cleanup(hcd->core_if, hc);
3842 DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
3843
3844 @@ -1416,27 +1016,10 @@ cleanup:
3845
3846 DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
3847 hcd->available_host_channels++;
3848 - fiq_print(FIQDBG_PORTHUB, "AHC = %d ", hcd->available_host_channels);
3849 + fiq_print(FIQDBG_INT, hcd->fiq_state, "AHC = %d ", hcd->available_host_channels);
3850 DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
3851 }
3852
3853 - if(fiq_split_enable && hc->do_split)
3854 - {
3855 - if(!(hcd->hub_port[hc->hub_addr] & (1 << hc->port_addr)))
3856 - {
3857 - fiq_print(FIQDBG_ERR, "PRTNOTAL");
3858 - //BUG();
3859 - }
3860 - if(!hog_port && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC ||
3861 - hc->ep_type == DWC_OTG_EP_TYPE_INTR)) {
3862 - hcd->hub_port[hc->hub_addr] &= ~(1 << hc->port_addr);
3863 -#ifdef FIQ_DEBUG
3864 - hcd->hub_port_alloc[hc->hub_addr * 16 + hc->port_addr] = -1;
3865 -#endif
3866 - fiq_print(FIQDBG_PORTHUB, "H%dP%d:RR%d", hc->hub_addr, hc->port_addr, endp);
3867 - }
3868 - }
3869 -
3870 /* Try to queue more transfers now that there's a free channel. */
3871 tr_type = dwc_otg_hcd_select_transactions(hcd);
3872 if (tr_type != DWC_OTG_TRANSACTION_NONE) {
3873 @@ -1858,7 +1441,7 @@ static int32_t handle_hc_nak_intr(dwc_ot
3874 switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
3875 case UE_BULK:
3876 case UE_CONTROL:
3877 - if (nak_holdoff_enable)
3878 + if (nak_holdoff && qtd->qh->do_split)
3879 hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
3880 }
3881
3882 @@ -2074,7 +1657,7 @@ static int32_t handle_hc_nyet_intr(dwc_o
3883 // With the FIQ running we only ever see the failed NYET
3884 if (dwc_full_frame_num(frnum) !=
3885 dwc_full_frame_num(hc->qh->sched_frame) ||
3886 - fiq_split_enable) {
3887 + fiq_fsm_enable) {
3888 /*
3889 * No longer in the same full speed frame.
3890 * Treat this as a transaction error.
3891 @@ -2460,12 +2043,11 @@ static inline int halt_status_ok(dwc_otg
3892 static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
3893 dwc_hc_t * hc,
3894 dwc_otg_hc_regs_t * hc_regs,
3895 - dwc_otg_qtd_t * qtd,
3896 - hcint_data_t hcint,
3897 - hcintmsk_data_t hcintmsk)
3898 + dwc_otg_qtd_t * qtd)
3899 {
3900 int out_nak_enh = 0;
3901 -
3902 + hcint_data_t hcint;
3903 + hcintmsk_data_t hcintmsk;
3904 /* For core with OUT NAK enhancement, the flow for high-
3905 * speed CONTROL/BULK OUT is handled a little differently.
3906 */
3907 @@ -2495,11 +2077,9 @@ static void handle_hc_chhltd_intr_dma(dw
3908 }
3909
3910 /* Read the HCINTn register to determine the cause for the halt. */
3911 - if(!fiq_split_enable)
3912 - {
3913 - hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
3914 - hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
3915 - }
3916 +
3917 + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
3918 + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
3919
3920 if (hcint.b.xfercomp) {
3921 /** @todo This is here because of a possible hardware bug. Spec
3922 @@ -2624,15 +2204,13 @@ static void handle_hc_chhltd_intr_dma(dw
3923 static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
3924 dwc_hc_t * hc,
3925 dwc_otg_hc_regs_t * hc_regs,
3926 - dwc_otg_qtd_t * qtd,
3927 - hcint_data_t hcint,
3928 - hcintmsk_data_t hcintmsk)
3929 + dwc_otg_qtd_t * qtd)
3930 {
3931 DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
3932 "Channel Halted--\n", hc->hc_num);
3933
3934 if (hcd->core_if->dma_enable) {
3935 - handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd, hcint, hcintmsk);
3936 + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
3937 } else {
3938 #ifdef DEBUG
3939 if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
3940 @@ -2645,11 +2223,372 @@ static int32_t handle_hc_chhltd_intr(dwc
3941 return 1;
3942 }
3943
3944 +
3945 +/**
3946 + * dwc_otg_fiq_unmangle_isoc() - Update the iso_frame_desc structure on
3947 + * FIQ transfer completion
3948 + * @hcd: Pointer to dwc_otg_hcd struct
3949 + * @num: Host channel number
3950 + *
3951 + * 1. Un-mangle the status as recorded in each iso_frame_desc status
3952 + * 2. Copy it from the dwc_otg_urb into the real URB
3953 + */
3954 +void dwc_otg_fiq_unmangle_isoc(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
3955 +{
3956 + struct dwc_otg_hcd_urb *dwc_urb = qtd->urb;
3957 + int nr_frames = dwc_urb->packet_count;
3958 + int i;
3959 + hcint_data_t frame_hcint;
3960 +
3961 + for (i = 0; i < nr_frames; i++) {
3962 + frame_hcint.d32 = dwc_urb->iso_descs[i].status;
3963 + if (frame_hcint.b.xfercomp) {
3964 + dwc_urb->iso_descs[i].status = 0;
3965 + dwc_urb->actual_length += dwc_urb->iso_descs[i].actual_length;
3966 + } else if (frame_hcint.b.frmovrun) {
3967 + if (qh->ep_is_in)
3968 + dwc_urb->iso_descs[i].status = -DWC_E_NO_STREAM_RES;
3969 + else
3970 + dwc_urb->iso_descs[i].status = -DWC_E_COMMUNICATION;
3971 + dwc_urb->error_count++;
3972 + dwc_urb->iso_descs[i].actual_length = 0;
3973 + } else if (frame_hcint.b.xacterr) {
3974 + dwc_urb->iso_descs[i].status = -DWC_E_PROTOCOL;
3975 + dwc_urb->error_count++;
3976 + dwc_urb->iso_descs[i].actual_length = 0;
3977 + } else if (frame_hcint.b.bblerr) {
3978 + dwc_urb->iso_descs[i].status = -DWC_E_OVERFLOW;
3979 + dwc_urb->error_count++;
3980 + dwc_urb->iso_descs[i].actual_length = 0;
3981 + } else {
3982 + /* Something went wrong */
3983 + dwc_urb->iso_descs[i].status = -1;
3984 + dwc_urb->iso_descs[i].actual_length = 0;
3985 + dwc_urb->error_count++;
3986 + }
3987 + }
3988 + //printk_ratelimited(KERN_INFO "%s: HS isochronous of %d/%d frames with %d errors complete\n",
3989 + // __FUNCTION__, i, dwc_urb->packet_count, dwc_urb->error_count);
3990 + hcd->fops->complete(hcd, dwc_urb->priv, dwc_urb, 0);
3991 + release_channel(hcd, qh->channel, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
3992 +}
3993 +
3994 +/**
3995 + * dwc_otg_fiq_unsetup_per_dma() - Remove data from bounce buffers for split transactions
3996 + * @hcd: Pointer to dwc_otg_hcd struct
3997 + * @num: Host channel number
3998 + *
3999 + * Copies data from the FIQ bounce buffers into the URB's transfer buffer. Does not modify URB state.
4000 + * Returns total length of data or -1 if the buffers were not used.
4001 + *
4002 + */
4003 +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)
4004 +{
4005 + dwc_hc_t *hc = qh->channel;
4006 + struct fiq_dma_blob *blob = hcd->fiq_dmab;
4007 + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
4008 + uint8_t *ptr = NULL;
4009 + int index = 0, len = 0;
4010 + int i = 0;
4011 + if (hc->ep_is_in) {
4012 + /* Copy data out of the DMA bounce buffers to the URB's buffer.
4013 + * The align_buf is ignored as this is ignored on FSM enqueue. */
4014 + ptr = qtd->urb->buf;
4015 + if (qh->ep_type == UE_ISOCHRONOUS) {
4016 + /* Isoc IN transactions - grab the offset of the iso_frame_desc into the URB transfer buffer */
4017 + index = qtd->isoc_frame_index;
4018 + ptr += qtd->urb->iso_descs[index].offset;
4019 + } else {
4020 + /* Need to increment by actual_length for interrupt IN */
4021 + ptr += qtd->urb->actual_length;
4022 + }
4023 +
4024 + for (i = 0; i < st->dma_info.index; i++) {
4025 + len += st->dma_info.slot_len[i];
4026 + dwc_memcpy(ptr, &blob->channel[num].index[i].buf[0], st->dma_info.slot_len[i]);
4027 + ptr += st->dma_info.slot_len[i];
4028 + }
4029 + return len;
4030 + } else {
4031 + /* OUT endpoints - nothing to do. */
4032 + return -1;
4033 + }
4034 +
4035 +}
4036 +/**
4037 + * dwc_otg_hcd_handle_hc_fsm() - handle an unmasked channel interrupt
4038 + * from a channel handled in the FIQ
4039 + * @hcd: Pointer to dwc_otg_hcd struct
4040 + * @num: Host channel number
4041 + *
4042 + * If a host channel interrupt was received by the IRQ and this was a channel
4043 + * used by the FIQ, the execution flow for transfer completion is substantially
4044 + * different from the normal (messy) path. This function and its friends handles
4045 + * channel cleanup and transaction completion from a FIQ transaction.
4046 + */
4047 +int32_t dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd_t *hcd, uint32_t num)
4048 +{
4049 + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
4050 + dwc_hc_t *hc = hcd->hc_ptr_array[num];
4051 + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
4052 + dwc_otg_qh_t *qh = hc->qh;
4053 + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[num];
4054 + hcint_data_t hcint = hcd->fiq_state->channel[num].hcint_copy;
4055 + int hostchannels = 0;
4056 + int ret = 0;
4057 + fiq_print(FIQDBG_INT, hcd->fiq_state, "OUT %01d %01d ", num , st->fsm);
4058 +
4059 + hostchannels = hcd->available_host_channels;
4060 + switch (st->fsm) {
4061 + case FIQ_TEST:
4062 + break;
4063 +
4064 + case FIQ_DEQUEUE_ISSUED:
4065 + /* hc_halt was called. QTD no longer exists. */
4066 + /* TODO: for a nonperiodic split transaction, need to issue a
4067 + * CLEAR_TT_BUFFER hub command if we were in the start-split phase.
4068 + */
4069 + release_channel(hcd, hc, NULL, hc->halt_status);
4070 + ret = 1;
4071 + break;
4072 +
4073 + case FIQ_NP_SPLIT_DONE:
4074 + /* Nonperiodic transaction complete. */
4075 + if (!hc->ep_is_in) {
4076 + qtd->ssplit_out_xfer_count = hc->xfer_len;
4077 + }
4078 + if (hcint.b.xfercomp) {
4079 + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
4080 + } else if (hcint.b.nak) {
4081 + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
4082 + }
4083 + ret = 1;
4084 + break;
4085 +
4086 + case FIQ_NP_SPLIT_HS_ABORTED:
4087 + /* A HS abort is a 3-strikes on the HS bus at any point in the transaction.
4088 + * Normally a CLEAR_TT_BUFFER hub command would be required: we can't do that
4089 + * because there's no guarantee which order a non-periodic split happened in.
4090 + * We could end up clearing a perfectly good transaction out of the buffer.
4091 + */
4092 + if (hcint.b.xacterr) {
4093 + qtd->error_count += st->nr_errors;
4094 + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
4095 + } else if (hcint.b.ahberr) {
4096 + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
4097 + } else {
4098 + local_fiq_disable();
4099 + BUG();
4100 + }
4101 + break;
4102 +
4103 + case FIQ_NP_SPLIT_LS_ABORTED:
4104 + /* A few cases can cause this - either an unknown state on a SSPLIT or
4105 + * STALL/data toggle error response on a CSPLIT */
4106 + if (hcint.b.stall) {
4107 + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
4108 + } else if (hcint.b.datatglerr) {
4109 + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
4110 + } else if (hcint.b.bblerr) {
4111 + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
4112 + } else if (hcint.b.ahberr) {
4113 + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
4114 + } else {
4115 + local_fiq_disable();
4116 + BUG();
4117 + }
4118 + break;
4119 +
4120 + case FIQ_PER_SPLIT_DONE:
4121 + /* Isoc IN or Interrupt IN/OUT */
4122 +
4123 + /* Flow control here is different from the normal execution by the driver.
4124 + * We need to completely ignore most of the driver's method of handling
4125 + * split transactions and do it ourselves.
4126 + */
4127 + if (hc->ep_type == UE_INTERRUPT) {
4128 + if (hcint.b.nak) {
4129 + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
4130 + } else if (hc->ep_is_in) {
4131 + int len;
4132 + len = dwc_otg_fiq_unsetup_per_dma(hcd, hc->qh, qtd, num);
4133 + //printk(KERN_NOTICE "FIQ Transaction: hc=%d len=%d urb_len = %d\n", num, len, qtd->urb->length);
4134 + qtd->urb->actual_length += len;
4135 + if (qtd->urb->actual_length >= qtd->urb->length) {
4136 + qtd->urb->status = 0;
4137 + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
4138 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
4139 + } else {
4140 + /* Interrupt transfer not complete yet - is it a short read? */
4141 + if (len < hc->max_packet) {
4142 + /* Interrupt transaction complete */
4143 + qtd->urb->status = 0;
4144 + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
4145 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
4146 + } else {
4147 + /* Further transactions required */
4148 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
4149 + }
4150 + }
4151 + } else {
4152 + /* Interrupt OUT complete. */
4153 + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
4154 + qtd->urb->actual_length += hc->xfer_len;
4155 + if (qtd->urb->actual_length >= qtd->urb->length) {
4156 + qtd->urb->status = 0;
4157 + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
4158 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
4159 + } else {
4160 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
4161 + }
4162 + }
4163 + } else {
4164 + /* ISOC IN complete. */
4165 + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
4166 + int len = 0;
4167 + /* Record errors, update qtd. */
4168 + if (st->nr_errors) {
4169 + frame_desc->actual_length = 0;
4170 + frame_desc->status = -DWC_E_PROTOCOL;
4171 + } else {
4172 + frame_desc->status = 0;
4173 + /* Unswizzle dma */
4174 + len = dwc_otg_fiq_unsetup_per_dma(hcd, qh, qtd, num);
4175 + frame_desc->actual_length = len;
4176 + }
4177 + qtd->isoc_frame_index++;
4178 + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
4179 + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
4180 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
4181 + } else {
4182 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
4183 + }
4184 + }
4185 + break;
4186 +
4187 + case FIQ_PER_ISO_OUT_DONE: {
4188 + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
4189 + /* Record errors, update qtd. */
4190 + if (st->nr_errors) {
4191 + frame_desc->actual_length = 0;
4192 + frame_desc->status = -DWC_E_PROTOCOL;
4193 + } else {
4194 + frame_desc->status = 0;
4195 + frame_desc->actual_length = frame_desc->length;
4196 + }
4197 + qtd->isoc_frame_index++;
4198 + qtd->isoc_split_offset = 0;
4199 + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
4200 + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
4201 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
4202 + } else {
4203 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
4204 + }
4205 + }
4206 + break;
4207 +
4208 + case FIQ_PER_SPLIT_NYET_ABORTED:
4209 + /* Doh. lost the data. */
4210 + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
4211 + "- FIQ reported NYET. Data may have been lost.\n",
4212 + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
4213 + if (hc->ep_type == UE_ISOCHRONOUS) {
4214 + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
4215 + /* Record errors, update qtd. */
4216 + frame_desc->actual_length = 0;
4217 + frame_desc->status = -DWC_E_PROTOCOL;
4218 + qtd->isoc_frame_index++;
4219 + qtd->isoc_split_offset = 0;
4220 + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
4221 + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
4222 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
4223 + } else {
4224 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
4225 + }
4226 + } else {
4227 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
4228 + }
4229 + break;
4230 +
4231 + case FIQ_HS_ISOC_DONE:
4232 + /* The FIQ has performed a whole pile of isochronous transactions.
4233 + * The status is recorded as the interrupt state should the transaction
4234 + * fail.
4235 + */
4236 + dwc_otg_fiq_unmangle_isoc(hcd, qh, qtd, num);
4237 + break;
4238 +
4239 + case FIQ_PER_SPLIT_LS_ABORTED:
4240 + if (hcint.b.xacterr) {
4241 + /* Hub has responded with an ERR packet. Device
4242 + * has been unplugged or the port has been disabled.
4243 + * TODO: need to issue a reset to the hub port. */
4244 + qtd->error_count += 3;
4245 + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
4246 + } else if (hcint.b.stall) {
4247 + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
4248 + } else if (hcint.b.bblerr) {
4249 + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
4250 + } else {
4251 + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x failed "
4252 + "- FIQ reported FSM=%d. Data may have been lost.\n",
4253 + st->fsm, hc->dev_addr, hc->ep_num);
4254 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
4255 + }
4256 + break;
4257 +
4258 + case FIQ_PER_SPLIT_HS_ABORTED:
4259 + /* Either the SSPLIT phase suffered transaction errors or something
4260 + * unexpected happened.
4261 + */
4262 + qtd->error_count += 3;
4263 + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
4264 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
4265 + break;
4266 +
4267 + case FIQ_PER_SPLIT_TIMEOUT:
4268 + /* Couldn't complete in the nominated frame */
4269 + printk(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
4270 + "- FIQ timed out. Data may have been lost.\n",
4271 + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
4272 + if (hc->ep_type == UE_ISOCHRONOUS) {
4273 + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
4274 + /* Record errors, update qtd. */
4275 + frame_desc->actual_length = 0;
4276 + if (hc->ep_is_in) {
4277 + frame_desc->status = -DWC_E_NO_STREAM_RES;
4278 + } else {
4279 + frame_desc->status = -DWC_E_COMMUNICATION;
4280 + }
4281 + qtd->isoc_frame_index++;
4282 + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
4283 + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
4284 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
4285 + } else {
4286 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
4287 + }
4288 + } else {
4289 + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
4290 + }
4291 + break;
4292 +
4293 + default:
4294 + local_fiq_disable();
4295 + DWC_WARN("unexpected state received on hc=%d fsm=%d", hc->hc_num, st->fsm);
4296 + BUG();
4297 + }
4298 + //if (hostchannels != hcd->available_host_channels) {
4299 + /* should have incremented by now! */
4300 + // BUG();
4301 +// }
4302 + return ret;
4303 +}
4304 +
4305 /** Handles interrupt for a specific Host Channel */
4306 int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
4307 {
4308 int retval = 0;
4309 - hcint_data_t hcint, hcint_orig;
4310 + hcint_data_t hcint;
4311 hcintmsk_data_t hcintmsk;
4312 dwc_hc_t *hc;
4313 dwc_otg_hc_regs_t *hc_regs;
4314 @@ -2668,24 +2607,32 @@ int32_t dwc_otg_hcd_handle_hc_n_intr(dwc
4315 }
4316 qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
4317
4318 + /*
4319 + * FSM mode: Check to see if this is a HC interrupt from a channel handled by the FIQ.
4320 + * Execution path is fundamentally different for the channels after a FIQ has completed
4321 + * a split transaction.
4322 + */
4323 + if (fiq_fsm_enable) {
4324 + switch (dwc_otg_hcd->fiq_state->channel[num].fsm) {
4325 + case FIQ_PASSTHROUGH:
4326 + break;
4327 + case FIQ_PASSTHROUGH_ERRORSTATE:
4328 + /* Hook into the error count */
4329 + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "HCDERR%02d", num);
4330 + if (dwc_otg_hcd->fiq_state->channel[num].nr_errors) {
4331 + qtd->error_count = 0;
4332 + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "RESET ");
4333 + }
4334 + break;
4335 + default:
4336 + dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd, num);
4337 + return 1;
4338 + }
4339 + }
4340 +
4341 hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
4342 - hcint_orig = hcint;
4343 hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
4344 - DWC_DEBUGPL(DBG_HCDV,
4345 - " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
4346 - hcint.d32, hcintmsk.d32, (hcint.d32 & hcintmsk.d32));
4347 hcint.d32 = hcint.d32 & hcintmsk.d32;
4348 -
4349 - if(fiq_split_enable)
4350 - {
4351 - // replace with the saved interrupts from the fiq handler
4352 - local_fiq_disable();
4353 - hcint_orig.d32 = hcint_saved[num].d32;
4354 - hcint.d32 = hcint_orig.d32 & hcintmsk_saved[num].d32;
4355 - hcint_saved[num].d32 = 0;
4356 - local_fiq_enable();
4357 - }
4358 -
4359 if (!dwc_otg_hcd->core_if->dma_enable) {
4360 if (hcint.b.chhltd && hcint.d32 != 0x2) {
4361 hcint.b.chhltd = 0;
4362 @@ -2703,7 +2650,7 @@ int32_t dwc_otg_hcd_handle_hc_n_intr(dwc
4363 hcint.b.nyet = 0;
4364 }
4365 if (hcint.b.chhltd) {
4366 - retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd, hcint_orig, hcintmsk_saved[num]);
4367 + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
4368 }
4369 if (hcint.b.ahberr) {
4370 retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
4371 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
4372 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
4373 @@ -58,6 +58,7 @@
4374 #else
4375 #include <linux/usb/hcd.h>
4376 #endif
4377 +#include <asm/bug.h>
4378
4379 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
4380 #define USB_URB_EP_LINKING 1
4381 @@ -69,7 +70,8 @@
4382 #include "dwc_otg_dbg.h"
4383 #include "dwc_otg_driver.h"
4384 #include "dwc_otg_hcd.h"
4385 -#include "dwc_otg_mphi_fix.h"
4386 +
4387 +extern unsigned char _dwc_otg_fiq_stub, _dwc_otg_fiq_stub_end;
4388
4389 /**
4390 * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
4391 @@ -80,7 +82,7 @@
4392
4393 static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
4394
4395 -extern bool fiq_fix_enable;
4396 +extern bool fiq_enable;
4397
4398 /** @name Linux HC Driver API Functions */
4399 /** @{ */
4400 @@ -351,7 +353,6 @@ static int _complete(dwc_otg_hcd_t * hcd
4401 urb);
4402 }
4403 }
4404 -
4405 DWC_FREE(dwc_otg_urb);
4406 if (!new_entry) {
4407 DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
4408 @@ -395,13 +396,9 @@ static struct dwc_otg_hcd_function_ops h
4409 static struct fiq_handler fh = {
4410 .name = "usb_fiq",
4411 };
4412 -struct fiq_stack_s {
4413 - int magic1;
4414 - uint8_t stack[2048];
4415 - int magic2;
4416 -} fiq_stack;
4417
4418 -extern mphi_regs_t c_mphi_regs;
4419 +
4420 +
4421 /**
4422 * Initializes the HCD. This function allocates memory for and initializes the
4423 * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
4424 @@ -433,20 +430,6 @@ int hcd_init(dwc_bus_dev_t *_dev)
4425 pci_set_consistent_dma_mask(_dev, dmamask);
4426 #endif
4427
4428 - if (fiq_fix_enable)
4429 - {
4430 - // Set up fiq
4431 - claim_fiq(&fh);
4432 - set_fiq_handler(__FIQ_Branch, 4);
4433 - memset(&regs,0,sizeof(regs));
4434 - regs.ARM_r8 = (long)dwc_otg_hcd_handle_fiq;
4435 - regs.ARM_r9 = (long)0;
4436 - regs.ARM_sp = (long)fiq_stack.stack + sizeof(fiq_stack.stack) - 4;
4437 - set_fiq_regs(&regs);
4438 - fiq_stack.magic1 = 0xdeadbeef;
4439 - fiq_stack.magic2 = 0xaa995566;
4440 - }
4441 -
4442 /*
4443 * Allocate memory for the base HCD plus the DWC OTG HCD.
4444 * Initialize the base HCD.
4445 @@ -466,30 +449,7 @@ int hcd_init(dwc_bus_dev_t *_dev)
4446
4447 hcd->regs = otg_dev->os_dep.base;
4448
4449 - if (fiq_fix_enable)
4450 - {
4451 - volatile extern void *dwc_regs_base;
4452 -
4453 - //Set the mphi periph to the required registers
4454 - c_mphi_regs.base = otg_dev->os_dep.mphi_base;
4455 - c_mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
4456 - c_mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
4457 - c_mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
4458 - c_mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
4459 -
4460 - dwc_regs_base = otg_dev->os_dep.base;
4461
4462 - //Enable mphi peripheral
4463 - writel((1<<31),c_mphi_regs.ctrl);
4464 -#ifdef DEBUG
4465 - if (readl(c_mphi_regs.ctrl) & 0x80000000)
4466 - DWC_DEBUGPL(DBG_USER, "MPHI periph has been enabled\n");
4467 - else
4468 - DWC_DEBUGPL(DBG_USER, "MPHI periph has NOT been enabled\n");
4469 -#endif
4470 - // Enable FIQ interrupt from USB peripheral
4471 - enable_fiq(INTERRUPT_VC_USB);
4472 - }
4473 /* Initialize the DWC OTG HCD. */
4474 dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
4475 if (!dwc_otg_hcd) {
4476 @@ -503,6 +463,55 @@ int hcd_init(dwc_bus_dev_t *_dev)
4477 goto error2;
4478 }
4479
4480 + if (fiq_enable)
4481 + {
4482 + if (claim_fiq(&fh)) {
4483 + DWC_ERROR("Can't claim FIQ");
4484 + goto error2;
4485 + }
4486 +
4487 + DWC_WARN("FIQ at 0x%08x", (fiq_fsm_enable ? (int)&dwc_otg_fiq_fsm : (int)&dwc_otg_fiq_nop));
4488 + DWC_WARN("FIQ ASM at 0x%08x length %d", (int)&_dwc_otg_fiq_stub, (int)(&_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub));
4489 +
4490 + set_fiq_handler((void *) &_dwc_otg_fiq_stub, &_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub);
4491 + memset(&regs,0,sizeof(regs));
4492 +
4493 + regs.ARM_r8 = (long) dwc_otg_hcd->fiq_state;
4494 + if (fiq_fsm_enable) {
4495 + regs.ARM_r9 = dwc_otg_hcd->core_if->core_params->host_channels;
4496 + //regs.ARM_r10 = dwc_otg_hcd->dma;
4497 + regs.ARM_fp = (long) dwc_otg_fiq_fsm;
4498 + } else {
4499 + regs.ARM_fp = (long) dwc_otg_fiq_nop;
4500 + }
4501 +
4502 + regs.ARM_sp = (long) dwc_otg_hcd->fiq_stack + (sizeof(struct fiq_stack) - 4);
4503 +
4504 +// __show_regs(&regs);
4505 + set_fiq_regs(&regs);
4506 +
4507 + //Set the mphi periph to the required registers
4508 + dwc_otg_hcd->fiq_state->mphi_regs.base = otg_dev->os_dep.mphi_base;
4509 + dwc_otg_hcd->fiq_state->mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
4510 + dwc_otg_hcd->fiq_state->mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
4511 + dwc_otg_hcd->fiq_state->mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
4512 + dwc_otg_hcd->fiq_state->mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
4513 + dwc_otg_hcd->fiq_state->dwc_regs_base = otg_dev->os_dep.base;
4514 + DWC_WARN("MPHI regs_base at 0x%08x", (int)dwc_otg_hcd->fiq_state->mphi_regs.base);
4515 + //Enable mphi peripheral
4516 + writel((1<<31),dwc_otg_hcd->fiq_state->mphi_regs.ctrl);
4517 +#ifdef DEBUG
4518 + if (readl(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & 0x80000000)
4519 + DWC_WARN("MPHI periph has been enabled");
4520 + else
4521 + DWC_WARN("MPHI periph has NOT been enabled");
4522 +#endif
4523 + // Enable FIQ interrupt from USB peripheral
4524 + enable_fiq(INTERRUPT_VC_USB);
4525 + local_fiq_enable();
4526 + }
4527 +
4528 +
4529 otg_dev->hcd->otg_dev = otg_dev;
4530 hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
4531 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
4532 @@ -518,9 +527,9 @@ int hcd_init(dwc_bus_dev_t *_dev)
4533 * IRQ line, and calls hcd_start method.
4534 */
4535 #ifdef PLATFORM_INTERFACE
4536 - retval = usb_add_hcd(hcd, platform_get_irq(_dev, 0), IRQF_SHARED | IRQF_DISABLED);
4537 + retval = usb_add_hcd(hcd, platform_get_irq(_dev, fiq_enable ? 0 : 1), IRQF_SHARED | IRQF_DISABLED);
4538 #else
4539 - retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
4540 + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
4541 #endif
4542 if (retval < 0) {
4543 goto error2;
4544 @@ -617,9 +626,13 @@ void hcd_stop(struct usb_hcd *hcd)
4545 /** Returns the current frame number. */
4546 static int get_frame_number(struct usb_hcd *hcd)
4547 {
4548 + hprt0_data_t hprt0;
4549 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
4550 -
4551 - return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
4552 + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
4553 + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
4554 + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd) >> 3;
4555 + else
4556 + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
4557 }
4558
4559 #ifdef DEBUG
4560 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
4561 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
4562 @@ -41,7 +41,6 @@
4563
4564 #include "dwc_otg_hcd.h"
4565 #include "dwc_otg_regs.h"
4566 -#include "dwc_otg_mphi_fix.h"
4567
4568 extern bool microframe_schedule;
4569
4570 @@ -577,7 +576,6 @@ static int check_max_xfer_size(dwc_otg_h
4571 }
4572
4573
4574 -extern int g_next_sched_frame, g_np_count, g_np_sent;
4575
4576 /**
4577 * Schedules an interrupt or isochronous transfer in the periodic schedule.
4578 @@ -637,9 +635,9 @@ static int schedule_periodic(dwc_otg_hcd
4579 DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
4580 }
4581 else {
4582 - if(DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, g_next_sched_frame))
4583 + if(fiq_enable && (DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, hcd->fiq_state->next_sched_frame)))
4584 {
4585 - g_next_sched_frame = qh->sched_frame;
4586 + hcd->fiq_state->next_sched_frame = qh->sched_frame;
4587
4588 }
4589 /* Always start in the inactive schedule. */
4590 @@ -680,7 +678,7 @@ int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * h
4591 /* Always start in the inactive schedule. */
4592 DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
4593 &qh->qh_list_entry);
4594 - g_np_count++;
4595 + //hcd->fiq_state->kick_np_queues = 1;
4596 } else {
4597 status = schedule_periodic(hcd, qh);
4598 if ( !hcd->periodic_qh_count ) {
4599 @@ -740,13 +738,12 @@ void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t
4600 hcd->non_periodic_qh_ptr->next;
4601 }
4602 DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
4603 -
4604 - // If we've removed the last non-periodic entry then there are none left!
4605 - g_np_count = g_np_sent;
4606 + //if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive))
4607 + // hcd->fiq_state->kick_np_queues = 1;
4608 } else {
4609 deschedule_periodic(hcd, qh);
4610 hcd->periodic_qh_count--;
4611 - if( !hcd->periodic_qh_count ) {
4612 + if( !hcd->periodic_qh_count && !fiq_fsm_enable ) {
4613 intr_mask.b.sofintr = 1;
4614 DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
4615 intr_mask.d32, 0);
4616 @@ -771,28 +768,11 @@ void dwc_otg_hcd_qh_deactivate(dwc_otg_h
4617 int sched_next_periodic_split)
4618 {
4619 if (dwc_qh_is_non_per(qh)) {
4620 -
4621 - dwc_otg_qh_t *qh_tmp;
4622 - dwc_list_link_t *qh_list;
4623 - DWC_LIST_FOREACH(qh_list, &hcd->non_periodic_sched_inactive)
4624 - {
4625 - qh_tmp = DWC_LIST_ENTRY(qh_list, struct dwc_otg_qh, qh_list_entry);
4626 - if(qh_tmp == qh)
4627 - {
4628 - /*
4629 - * FIQ is being disabled because this one nevers gets a np_count increment
4630 - * This is still not absolutely correct, but it should fix itself with
4631 - * just an unnecessary extra interrupt
4632 - */
4633 - g_np_sent = g_np_count;
4634 - }
4635 - }
4636 -
4637 -
4638 dwc_otg_hcd_qh_remove(hcd, qh);
4639 if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
4640 /* Add back to inactive non-periodic schedule. */
4641 dwc_otg_hcd_qh_add(hcd, qh);
4642 + //hcd->fiq_state->kick_np_queues = 1;
4643 }
4644 } else {
4645 uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
4646 @@ -851,9 +831,9 @@ void dwc_otg_hcd_qh_deactivate(dwc_otg_h
4647 DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
4648 &qh->qh_list_entry);
4649 } else {
4650 - if(!dwc_frame_num_le(g_next_sched_frame, qh->sched_frame))
4651 + if(fiq_enable && !dwc_frame_num_le(hcd->fiq_state->next_sched_frame, qh->sched_frame))
4652 {
4653 - g_next_sched_frame = qh->sched_frame;
4654 + hcd->fiq_state->next_sched_frame = qh->sched_frame;
4655 }
4656
4657 DWC_LIST_MOVE_HEAD
4658 @@ -944,6 +924,9 @@ int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t *
4659 if (*qh == NULL) {
4660 retval = -DWC_E_NO_MEMORY;
4661 goto done;
4662 + } else {
4663 + if (fiq_enable)
4664 + hcd->fiq_state->kick_np_queues = 1;
4665 }
4666 }
4667 retval = dwc_otg_hcd_qh_add(hcd, *qh);
4668 --- a/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c
4669 +++ /dev/null
4670 @@ -1,113 +0,0 @@
4671 -#include "dwc_otg_regs.h"
4672 -#include "dwc_otg_dbg.h"
4673 -
4674 -void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name)
4675 -{
4676 - DWC_DEBUGPL(DBG_USER, "*** Debugging from within the %s function: ***\n"
4677 - "curmode: %1i Modemismatch: %1i otgintr: %1i sofintr: %1i\n"
4678 - "rxstsqlvl: %1i nptxfempty : %1i ginnakeff: %1i goutnakeff: %1i\n"
4679 - "ulpickint: %1i i2cintr: %1i erlysuspend:%1i usbsuspend: %1i\n"
4680 - "usbreset: %1i enumdone: %1i isooutdrop: %1i eopframe: %1i\n"
4681 - "restoredone: %1i epmismatch: %1i inepint: %1i outepintr: %1i\n"
4682 - "incomplisoin:%1i incomplisoout:%1i fetsusp: %1i resetdet: %1i\n"
4683 - "portintr: %1i hcintr: %1i ptxfempty: %1i lpmtranrcvd:%1i\n"
4684 - "conidstschng:%1i disconnect: %1i sessreqintr:%1i wkupintr: %1i\n",
4685 - function_name,
4686 - gintsts.b.curmode,
4687 - gintsts.b.modemismatch,
4688 - gintsts.b.otgintr,
4689 - gintsts.b.sofintr,
4690 - gintsts.b.rxstsqlvl,
4691 - gintsts.b.nptxfempty,
4692 - gintsts.b.ginnakeff,
4693 - gintsts.b.goutnakeff,
4694 - gintsts.b.ulpickint,
4695 - gintsts.b.i2cintr,
4696 - gintsts.b.erlysuspend,
4697 - gintsts.b.usbsuspend,
4698 - gintsts.b.usbreset,
4699 - gintsts.b.enumdone,
4700 - gintsts.b.isooutdrop,
4701 - gintsts.b.eopframe,
4702 - gintsts.b.restoredone,
4703 - gintsts.b.epmismatch,
4704 - gintsts.b.inepint,
4705 - gintsts.b.outepintr,
4706 - gintsts.b.incomplisoin,
4707 - gintsts.b.incomplisoout,
4708 - gintsts.b.fetsusp,
4709 - gintsts.b.resetdet,
4710 - gintsts.b.portintr,
4711 - gintsts.b.hcintr,
4712 - gintsts.b.ptxfempty,
4713 - gintsts.b.lpmtranrcvd,
4714 - gintsts.b.conidstschng,
4715 - gintsts.b.disconnect,
4716 - gintsts.b.sessreqintr,
4717 - gintsts.b.wkupintr);
4718 - return;
4719 -}
4720 -
4721 -void dwc_debug_core_int_mask(gintmsk_data_t gintmsk, const char* function_name)
4722 -{
4723 - DWC_DEBUGPL(DBG_USER, "Interrupt Mask status (called from %s) :\n"
4724 - "modemismatch: %1i otgintr: %1i sofintr: %1i rxstsqlvl: %1i\n"
4725 - "nptxfempty: %1i ginnakeff: %1i goutnakeff: %1i ulpickint: %1i\n"
4726 - "i2cintr: %1i erlysuspend:%1i usbsuspend: %1i usbreset: %1i\n"
4727 - "enumdone: %1i isooutdrop: %1i eopframe: %1i restoredone: %1i\n"
4728 - "epmismatch: %1i inepintr: %1i outepintr: %1i incomplisoin:%1i\n"
4729 - "incomplisoout:%1i fetsusp: %1i resetdet: %1i portintr: %1i\n"
4730 - "hcintr: %1i ptxfempty: %1i lpmtranrcvd:%1i conidstschng:%1i\n"
4731 - "disconnect: %1i sessreqintr:%1i wkupintr: %1i\n",
4732 - function_name,
4733 - gintmsk.b.modemismatch,
4734 - gintmsk.b.otgintr,
4735 - gintmsk.b.sofintr,
4736 - gintmsk.b.rxstsqlvl,
4737 - gintmsk.b.nptxfempty,
4738 - gintmsk.b.ginnakeff,
4739 - gintmsk.b.goutnakeff,
4740 - gintmsk.b.ulpickint,
4741 - gintmsk.b.i2cintr,
4742 - gintmsk.b.erlysuspend,
4743 - gintmsk.b.usbsuspend,
4744 - gintmsk.b.usbreset,
4745 - gintmsk.b.enumdone,
4746 - gintmsk.b.isooutdrop,
4747 - gintmsk.b.eopframe,
4748 - gintmsk.b.restoredone,
4749 - gintmsk.b.epmismatch,
4750 - gintmsk.b.inepintr,
4751 - gintmsk.b.outepintr,
4752 - gintmsk.b.incomplisoin,
4753 - gintmsk.b.incomplisoout,
4754 - gintmsk.b.fetsusp,
4755 - gintmsk.b.resetdet,
4756 - gintmsk.b.portintr,
4757 - gintmsk.b.hcintr,
4758 - gintmsk.b.ptxfempty,
4759 - gintmsk.b.lpmtranrcvd,
4760 - gintmsk.b.conidstschng,
4761 - gintmsk.b.disconnect,
4762 - gintmsk.b.sessreqintr,
4763 - gintmsk.b.wkupintr);
4764 - return;
4765 -}
4766 -
4767 -void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name)
4768 -{
4769 - DWC_DEBUGPL(DBG_USER, "otg int register (from %s function):\n"
4770 - "sesenddet:%1i sesreqsucstschung:%2i hstnegsucstschng:%1i\n"
4771 - "hstnegdet:%1i adevtoutchng: %2i debdone: %1i\n"
4772 - "mvic: %1i\n",
4773 - function_name,
4774 - gotgint.b.sesenddet,
4775 - gotgint.b.sesreqsucstschng,
4776 - gotgint.b.hstnegsucstschng,
4777 - gotgint.b.hstnegdet,
4778 - gotgint.b.adevtoutchng,
4779 - gotgint.b.debdone,
4780 - gotgint.b.mvic);
4781 -
4782 - return;
4783 -}
4784 --- a/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h
4785 +++ /dev/null
4786 @@ -1,48 +0,0 @@
4787 -#ifndef __DWC_OTG_MPHI_FIX_H__
4788 -#define __DWC_OTG_MPHI_FIX_H__
4789 -#define FIQ_WRITE(_addr_,_data_) (*(volatile uint32_t *) (_addr_) = (_data_))
4790 -#define FIQ_READ(_addr_) (*(volatile uint32_t *) (_addr_))
4791 -
4792 -typedef struct {
4793 - volatile void* base;
4794 - volatile void* ctrl;
4795 - volatile void* outdda;
4796 - volatile void* outddb;
4797 - volatile void* intstat;
4798 -} mphi_regs_t;
4799 -
4800 -void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name);
4801 -void dwc_debug_core_int_mask(gintsts_data_t gintmsk, const char* function_name);
4802 -void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name);
4803 -
4804 -extern gintsts_data_t gintsts_saved;
4805 -
4806 -#ifdef DEBUG
4807 -#define DWC_DBG_PRINT_CORE_INT(_arg_) dwc_debug_print_core_int_reg(_arg_,__func__)
4808 -#define DWC_DBG_PRINT_CORE_INT_MASK(_arg_) dwc_debug_core_int_mask(_arg_,__func__)
4809 -#define DWC_DBG_PRINT_OTG_INT(_arg_) dwc_debug_otg_int(_arg_,__func__)
4810 -
4811 -#else
4812 -#define DWC_DBG_PRINT_CORE_INT(_arg_)
4813 -#define DWC_DBG_PRINT_CORE_INT_MASK(_arg_)
4814 -#define DWC_DBG_PRINT_OTG_INT(_arg_)
4815 -
4816 -#endif
4817 -
4818 -typedef enum {
4819 - FIQDBG_SCHED = (1 << 0),
4820 - FIQDBG_INT = (1 << 1),
4821 - FIQDBG_ERR = (1 << 2),
4822 - FIQDBG_PORTHUB = (1 << 3),
4823 -} FIQDBG_T;
4824 -
4825 -void _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...);
4826 -#ifdef FIQ_DEBUG
4827 -#define fiq_print _fiq_print
4828 -#else
4829 -#define fiq_print(x, y, ...)
4830 -#endif
4831 -
4832 -extern bool fiq_fix_enable, nak_holdoff_enable, fiq_split_enable;
4833 -
4834 -#endif
4835 --- a/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
4836 +++ b/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
4837 @@ -59,6 +59,8 @@
4838 #include "dwc_otg_driver.h"
4839 #include "dwc_otg_dbg.h"
4840
4841 +extern bool fiq_enable;
4842 +
4843 static struct gadget_wrapper {
4844 dwc_otg_pcd_t *pcd;
4845
4846 @@ -1222,13 +1224,13 @@ int pcd_init(dwc_bus_dev_t *_dev)
4847 */
4848 #ifdef PLATFORM_INTERFACE
4849 DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
4850 - platform_get_irq(_dev, 0));
4851 - retval = request_irq(platform_get_irq(_dev, 0), dwc_otg_pcd_irq,
4852 + platform_get_irq(_dev, fiq_enable ? 0 : 1));
4853 + retval = request_irq(platform_get_irq(_dev, fiq_enable ? 0 : 1), dwc_otg_pcd_irq,
4854 IRQF_SHARED, gadget_wrapper->gadget.name,
4855 otg_dev->pcd);
4856 if (retval != 0) {
4857 DWC_ERROR("request of irq%d failed\n",
4858 - platform_get_irq(_dev, 0));
4859 + platform_get_irq(_dev, fiq_enable ? 0 : 1));
4860 free_wrapper(gadget_wrapper);
4861 return -EBUSY;
4862 }