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