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