4545
4646#include "dwc_otg_hcd.h"
4747#include "dwc_otg_regs.h"
48+ #include "dwc_otg_mphi_fix.h"
4849
4950extern 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+
982991out :
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