Skip to content

Commit 271d438

Browse files
Gordon Hollingworthpopcornmix
authored andcommitted
USB fix using a FIQ to implement split transactions
This commit adds a FIQ implementaion that schedules the split transactions using a FIQ so we don't get held off by the interrupt latency of Linux
1 parent 1fe837e commit 271d438

10 files changed

Lines changed: 696 additions & 114 deletions

File tree

‎drivers/usb/host/dwc_common_port/dwc_common_linux.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,12 @@ void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value)
580580

581581
void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask)
582582
{
583+
unsigned long flags;
584+
585+
local_irq_save(flags);
586+
local_fiq_disable();
583587
writel((readl(reg) & ~clear_mask) | set_mask, reg);
588+
local_irq_restore(flags);
584589
}
585590

586591
#if 0
@@ -1301,7 +1306,7 @@ EXPORT_SYMBOL(DWC_EXCEPTION);
13011306
EXPORT_SYMBOL(__DWC_DEBUG);
13021307
#endif
13031308

1304-
EXPORT_SYMBOL(__DWC_DMA_ALLOC);
1309+
EXPORT_SYMBOL(__DWC_DMA_ALLOC);
13051310
EXPORT_SYMBOL(__DWC_DMA_ALLOC_ATOMIC);
13061311
EXPORT_SYMBOL(__DWC_DMA_FREE);
13071312
EXPORT_SYMBOL(__DWC_ALLOC);

‎drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c‎

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
#include "dwc_otg_hcd.h"
4848
#include "dwc_otg_mphi_fix.h"
4949

50-
extern bool fiq_fix_enable;
51-
5250
#ifdef DEBUG
5351
inline const char *op_state_str(dwc_otg_core_if_t * core_if)
5452
{
@@ -1321,7 +1319,7 @@ static int32_t dwc_otg_handle_lpm_intr(dwc_otg_core_if_t * core_if)
13211319
/**
13221320
* This function returns the Core Interrupt register.
13231321
*/
1324-
static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if)
1322+
static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if, gintmsk_data_t *reenable_gintmsk)
13251323
{
13261324
gahbcfg_data_t gahbcfg = {.d32 = 0 };
13271325
gintsts_data_t gintsts;
@@ -1338,19 +1336,33 @@ static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if)
13381336
gintmsk_common.b.lpmtranrcvd = 1;
13391337
#endif
13401338
gintmsk_common.b.restoredone = 1;
1341-
/** @todo: The port interrupt occurs while in device
1342-
* mode. Added code to CIL to clear the interrupt for now!
1343-
*/
1344-
gintmsk_common.b.portintr = 1;
1345-
1339+
if(dwc_otg_is_device_mode(core_if))
1340+
{
1341+
/** @todo: The port interrupt occurs while in device
1342+
* mode. Added code to CIL to clear the interrupt for now!
1343+
*/
1344+
gintmsk_common.b.portintr = 1;
1345+
}
13461346
gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
13471347
gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
1348+
{
1349+
unsigned long flags;
1350+
1351+
// Re-enable the saved interrupts
1352+
local_irq_save(flags);
1353+
local_fiq_disable();
1354+
gintmsk.d32 |= gintmsk_common.d32;
1355+
gintsts_saved.d32 &= ~gintmsk_common.d32;
1356+
reenable_gintmsk->d32 = gintmsk.d32;
1357+
local_irq_restore(flags);
1358+
}
1359+
13481360
gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
13491361

13501362
#ifdef DEBUG
13511363
/* if any common interrupts set */
13521364
if (gintsts.d32 & gintmsk_common.d32) {
1353-
DWC_DEBUGPL(DBG_ANY, "gintsts=%08x gintmsk=%08x\n",
1365+
DWC_DEBUGPL(DBG_ANY, "common_intr: gintsts=%08x gintmsk=%08x\n",
13541366
gintsts.d32, gintmsk.d32);
13551367
}
13561368
#endif
@@ -1394,6 +1406,7 @@ int32_t dwc_otg_handle_common_intr(void *dev)
13941406
{
13951407
int retval = 0;
13961408
gintsts_data_t gintsts;
1409+
gintmsk_data_t reenable_gintmsk;
13971410
gpwrdn_data_t gpwrdn = {.d32 = 0 };
13981411
dwc_otg_device_t *otg_dev = dev;
13991412
dwc_otg_core_if_t *core_if = otg_dev->core_if;
@@ -1415,7 +1428,7 @@ int32_t dwc_otg_handle_common_intr(void *dev)
14151428
}
14161429

14171430
if (core_if->hibernation_suspend <= 0) {
1418-
gintsts.d32 = dwc_otg_read_common_intr(core_if);
1431+
gintsts.d32 = dwc_otg_read_common_intr(core_if, &reenable_gintmsk);
14191432

14201433
if (gintsts.b.modemismatch) {
14211434
retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
@@ -1512,8 +1525,12 @@ int32_t dwc_otg_handle_common_intr(void *dev)
15121525
gintsts.b.portintr = 1;
15131526
DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
15141527
retval |= 1;
1528+
reenable_gintmsk.b.portintr = 1;
15151529

15161530
}
1531+
1532+
DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, reenable_gintmsk.d32);
1533+
15171534
} else {
15181535
DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
15191536

‎drivers/usb/host/dwc_otg/dwc_otg_driver.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ static struct dwc_otg_driver_module_params dwc_otg_module_params = {
242242

243243
//Global variable to switch the fiq fix on or off (declared in bcm2708.c)
244244
extern bool fiq_fix_enable;
245-
245+
// Global variable to enable the split transaction fix
246+
bool fiq_split_enable = true;
246247
//Global variable to switch the nak holdoff on or off
247248
bool nak_holdoff_enable = true;
248249

@@ -1090,6 +1091,7 @@ static int __init dwc_otg_driver_init(void)
10901091
}
10911092
printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_fix_enable ? "enabled":"disabled");
10921093
printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff_enable ? "enabled":"disabled");
1094+
printk(KERN_DEBUG "dwc_otg: FIQ split fix %s\n", fiq_split_enable ? "enabled":"disabled");
10931095

10941096
error = driver_create_file(drv, &driver_attr_version);
10951097
#ifdef DEBUG
@@ -1374,6 +1376,8 @@ module_param(fiq_fix_enable, bool, 0444);
13741376
MODULE_PARM_DESC(fiq_fix_enable, "Enable the fiq fix");
13751377
module_param(nak_holdoff_enable, bool, 0444);
13761378
MODULE_PARM_DESC(nak_holdoff_enable, "Enable the NAK holdoff");
1379+
module_param(fiq_split_enable, bool, 0444);
1380+
MODULE_PARM_DESC(fiq_split_enable, "Enable the FIQ fix on split transactions");
13771381

13781382
/** @page "Module Parameters"
13791383
*

‎drivers/usb/host/dwc_otg/dwc_otg_hcd.c‎

Lines changed: 116 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
#include "dwc_otg_hcd.h"
4747
#include "dwc_otg_regs.h"
48+
#include "dwc_otg_mphi_fix.h"
4849

4950
extern bool microframe_schedule, nak_holdoff_enable;
5051

@@ -581,6 +582,8 @@ int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * hcd,
581582
*/
582583
dwc_otg_hc_halt(hcd->core_if, qh->channel,
583584
DWC_OTG_HC_XFER_URB_DEQUEUE);
585+
586+
dwc_otg_hcd_release_port(hcd, qh);
584587
}
585588
}
586589

@@ -716,6 +719,8 @@ static void completion_tasklet_func(void *ptr)
716719

717720
usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
718721

722+
fiq_print(FIQDBG_PORTHUB, "COMPLETE");
723+
719724
DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
720725
}
721726
DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
@@ -979,6 +984,10 @@ int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
979984
hcd->frame_list = NULL;
980985
hcd->frame_list_dma = 0;
981986
hcd->periodic_qh_count = 0;
987+
988+
DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
989+
DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
990+
982991
out:
983992
return retval;
984993
}
@@ -1124,7 +1133,12 @@ static void assign_and_init_hc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
11241133
uint32_t hub_addr, port_addr;
11251134
hc->do_split = 1;
11261135
hc->xact_pos = qtd->isoc_split_pos;
1127-
hc->complete_split = qtd->complete_split;
1136+
/* We don't need to do complete splits anymore */
1137+
if(fiq_split_enable)
1138+
hc->complete_split = qtd->complete_split = 0;
1139+
else
1140+
hc->complete_split = qtd->complete_split;
1141+
11281142
hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &port_addr);
11291143
hc->hub_addr = (uint8_t) hub_addr;
11301144
hc->port_addr = (uint8_t) port_addr;
@@ -1271,6 +1285,62 @@ static void assign_and_init_hc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
12711285
hc->qh = qh;
12721286
}
12731287

1288+
/*
1289+
** Check the transaction to see if the port / hub has already been assigned for
1290+
** a split transaction
1291+
**
1292+
** Return 0 - Port is already in use
1293+
*/
1294+
int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
1295+
{
1296+
uint32_t hub_addr, port_addr;
1297+
1298+
if(!fiq_split_enable)
1299+
return 0;
1300+
1301+
hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
1302+
1303+
if(hcd->hub_port[hub_addr] & (1 << port_addr))
1304+
{
1305+
fiq_print(FIQDBG_PORTHUB, "H%dP%d:S%02d", hub_addr, port_addr, qh->skip_count);
1306+
1307+
qh->skip_count++;
1308+
1309+
if(qh->skip_count > 40000)
1310+
{
1311+
printk_once(KERN_ERR "Error: Having to skip port allocation");
1312+
local_fiq_disable();
1313+
BUG();
1314+
return 0;
1315+
}
1316+
return 1;
1317+
}
1318+
else
1319+
{
1320+
qh->skip_count = 0;
1321+
hcd->hub_port[hub_addr] |= 1 << port_addr;
1322+
fiq_print(FIQDBG_PORTHUB, "H%dP%d:A %d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
1323+
hcd->hub_port_alloc[hub_addr * 16 + port_addr] = dwc_otg_hcd_get_frame_number(hcd);
1324+
return 0;
1325+
}
1326+
}
1327+
void dwc_otg_hcd_release_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
1328+
{
1329+
uint32_t hub_addr, port_addr;
1330+
1331+
if(!fiq_split_enable)
1332+
return;
1333+
1334+
hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
1335+
1336+
hcd->hub_port[hub_addr] &= ~(1 << port_addr);
1337+
hcd->hub_port_alloc[hub_addr * 16 + port_addr] = -1;
1338+
1339+
fiq_print(FIQDBG_PORTHUB, "H%dP%d:RO%d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
1340+
1341+
}
1342+
1343+
12741344
/**
12751345
* This function selects transactions from the HCD transfer schedule and
12761346
* assigns them to available host channels. It is called from HCD interrupt
@@ -1304,11 +1374,22 @@ dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
13041374

13051375
while (qh_ptr != &hcd->periodic_sched_ready &&
13061376
!DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
1377+
1378+
qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
1379+
1380+
if(qh->do_split && dwc_otg_hcd_allocate_port(hcd, qh))
1381+
{
1382+
qh_ptr = DWC_LIST_NEXT(qh_ptr);
1383+
g_next_sched_frame = dwc_frame_num_inc(dwc_otg_hcd_get_frame_number(hcd), 1);
1384+
continue;
1385+
}
1386+
13071387
if (microframe_schedule) {
13081388
// Make sure we leave one channel for non periodic transactions.
13091389
DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
13101390
if (hcd->available_host_channels <= 1) {
13111391
DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
1392+
if(qh->do_split) dwc_otg_hcd_release_port(hcd, qh);
13121393
break;
13131394
}
13141395
hcd->available_host_channels--;
@@ -1329,8 +1410,6 @@ dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
13291410
DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
13301411
&qh->qh_list_entry);
13311412
DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
1332-
1333-
ret_val = DWC_OTG_TRANSACTION_PERIODIC;
13341413
}
13351414

13361415
/*
@@ -1369,10 +1448,19 @@ dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
13691448
qh->nak_frame = 0xffff;
13701449
}
13711450
}
1451+
1452+
if (qh->do_split && dwc_otg_hcd_allocate_port(hcd, qh))
1453+
{
1454+
g_next_sched_frame = dwc_frame_num_inc(dwc_otg_hcd_get_frame_number(hcd), 1);
1455+
qh_ptr = DWC_LIST_NEXT(qh_ptr);
1456+
continue;
1457+
}
1458+
13721459
if (microframe_schedule) {
13731460
DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
13741461
if (hcd->available_host_channels < 1) {
13751462
DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
1463+
if(qh->do_split) dwc_otg_hcd_release_port(hcd, qh);
13761464
break;
13771465
}
13781466
hcd->available_host_channels--;
@@ -1396,16 +1484,17 @@ dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
13961484

13971485
g_np_sent++;
13981486

1399-
if (ret_val == DWC_OTG_TRANSACTION_NONE) {
1400-
ret_val = DWC_OTG_TRANSACTION_NON_PERIODIC;
1401-
} else {
1402-
ret_val = DWC_OTG_TRANSACTION_ALL;
1403-
}
1404-
14051487
if (!microframe_schedule)
14061488
hcd->non_periodic_channels++;
14071489
}
14081490

1491+
if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
1492+
ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
1493+
1494+
if(!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active))
1495+
ret_val |= DWC_OTG_TRANSACTION_NON_PERIODIC;
1496+
1497+
14091498
#ifdef DEBUG_HOST_CHANNELS
14101499
last_sel_trans_num_avail_hc_at_end = hcd->available_host_channels;
14111500
#endif /* DEBUG_HOST_CHANNELS */
@@ -1522,6 +1611,15 @@ static void process_periodic_channels(dwc_otg_hcd_t * hcd)
15221611

15231612
qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
15241613

1614+
// Do not send a split start transaction any later than frame .6
1615+
// Note, we have to schedule a periodic in .5 to make it go in .6
1616+
if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
1617+
{
1618+
qh_ptr = qh_ptr->next;
1619+
g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
1620+
continue;
1621+
}
1622+
15251623
/*
15261624
* Set a flag if we're queuing high-bandwidth in slave mode.
15271625
* The flag prevents any halts to get into the request queue in
@@ -1651,6 +1749,15 @@ static void process_non_periodic_channels(dwc_otg_hcd_t * hcd)
16511749

16521750
qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
16531751
qh_list_entry);
1752+
1753+
// Do not send a split start transaction any later than frame .5
1754+
// non periodic transactions will start immediately in this uframe
1755+
if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
1756+
{
1757+
g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
1758+
break;
1759+
}
1760+
16541761
status =
16551762
queue_transaction(hcd, qh->channel,
16561763
tx_status.b.nptxfspcavail);

0 commit comments

Comments
 (0)