1919#define HS_BW_BOUNDARY 6144
2020/* usb2 spec section11.18.1: at most 188 FS bytes per microframe */
2121#define FS_PAYLOAD_MAX 188
22- /*
23- * max number of microframes for split transfer,
24- * for fs isoc in : 1 ss + 1 idle + 7 cs
25- */
26- #define TT_MICROFRAMES_MAX 9
2722
2823#define DBG_BUF_EN 64
2924
@@ -242,28 +237,17 @@ static void drop_tt(struct usb_device *udev)
242237
243238static struct mu3h_sch_ep_info *
244239create_sch_ep (struct xhci_hcd_mtk * mtk , struct usb_device * udev ,
245- struct usb_host_endpoint * ep , struct xhci_ep_ctx * ep_ctx )
240+ struct usb_host_endpoint * ep )
246241{
247242 struct mu3h_sch_ep_info * sch_ep ;
248243 struct mu3h_sch_bw_info * bw_info ;
249244 struct mu3h_sch_tt * tt = NULL ;
250- u32 len_bw_budget_table ;
251245
252246 bw_info = get_bw_info (mtk , udev , ep );
253247 if (!bw_info )
254248 return ERR_PTR (- ENODEV );
255249
256- if (is_fs_or_ls (udev -> speed ))
257- len_bw_budget_table = TT_MICROFRAMES_MAX ;
258- else if ((udev -> speed >= USB_SPEED_SUPER )
259- && usb_endpoint_xfer_isoc (& ep -> desc ))
260- len_bw_budget_table = get_esit (ep_ctx );
261- else
262- len_bw_budget_table = 1 ;
263-
264- sch_ep = kzalloc (struct_size (sch_ep , bw_budget_table ,
265- len_bw_budget_table ),
266- GFP_KERNEL );
250+ sch_ep = kzalloc (sizeof (* sch_ep ), GFP_KERNEL );
267251 if (!sch_ep )
268252 return ERR_PTR (- ENOMEM );
269253
@@ -295,8 +279,6 @@ static void setup_sch_info(struct xhci_ep_ctx *ep_ctx,
295279 u32 mult ;
296280 u32 esit_pkts ;
297281 u32 max_esit_payload ;
298- u32 * bwb_table = sch_ep -> bw_budget_table ;
299- int i ;
300282
301283 ep_type = CTX_TO_EP_TYPE (le32_to_cpu (ep_ctx -> ep_info2 ));
302284 maxpkt = MAX_PACKET_DECODED (le32_to_cpu (ep_ctx -> ep_info2 ));
@@ -332,7 +314,6 @@ static void setup_sch_info(struct xhci_ep_ctx *ep_ctx,
332314 */
333315 sch_ep -> pkts = max_burst + 1 ;
334316 sch_ep -> bw_cost_per_microframe = maxpkt * sch_ep -> pkts ;
335- bwb_table [0 ] = sch_ep -> bw_cost_per_microframe ;
336317 } else if (sch_ep -> speed >= USB_SPEED_SUPER ) {
337318 /* usb3_r1 spec section4.4.7 & 4.4.8 */
338319 sch_ep -> cs_count = 0 ;
@@ -349,7 +330,6 @@ static void setup_sch_info(struct xhci_ep_ctx *ep_ctx,
349330 if (ep_type == INT_IN_EP || ep_type == INT_OUT_EP ) {
350331 sch_ep -> pkts = esit_pkts ;
351332 sch_ep -> num_budget_microframes = 1 ;
352- bwb_table [0 ] = maxpkt * sch_ep -> pkts ;
353333 }
354334
355335 if (ep_type == ISOC_IN_EP || ep_type == ISOC_OUT_EP ) {
@@ -366,15 +346,8 @@ static void setup_sch_info(struct xhci_ep_ctx *ep_ctx,
366346 DIV_ROUND_UP (esit_pkts , sch_ep -> pkts );
367347
368348 sch_ep -> repeat = !!(sch_ep -> num_budget_microframes > 1 );
369- sch_ep -> bw_cost_per_microframe = maxpkt * sch_ep -> pkts ;
370-
371- for (i = 0 ; i < sch_ep -> num_budget_microframes - 1 ; i ++ )
372- bwb_table [i ] = sch_ep -> bw_cost_per_microframe ;
373-
374- /* last one <= bw_cost_per_microframe */
375- bwb_table [i ] = maxpkt * esit_pkts
376- - i * sch_ep -> bw_cost_per_microframe ;
377349 }
350+ sch_ep -> bw_cost_per_microframe = maxpkt * sch_ep -> pkts ;
378351 } else if (is_fs_or_ls (sch_ep -> speed )) {
379352 sch_ep -> pkts = 1 ; /* at most one packet for each microframe */
380353
@@ -384,28 +357,7 @@ static void setup_sch_info(struct xhci_ep_ctx *ep_ctx,
384357 */
385358 sch_ep -> cs_count = DIV_ROUND_UP (maxpkt , FS_PAYLOAD_MAX );
386359 sch_ep -> num_budget_microframes = sch_ep -> cs_count ;
387- sch_ep -> bw_cost_per_microframe =
388- (maxpkt < FS_PAYLOAD_MAX ) ? maxpkt : FS_PAYLOAD_MAX ;
389-
390- /* init budget table */
391- if (ep_type == ISOC_OUT_EP ) {
392- for (i = 0 ; i < sch_ep -> num_budget_microframes ; i ++ )
393- bwb_table [i ] = sch_ep -> bw_cost_per_microframe ;
394- } else if (ep_type == INT_OUT_EP ) {
395- /* only first one consumes bandwidth, others as zero */
396- bwb_table [0 ] = sch_ep -> bw_cost_per_microframe ;
397- } else { /* INT_IN_EP or ISOC_IN_EP */
398- bwb_table [0 ] = 0 ; /* start split */
399- bwb_table [1 ] = 0 ; /* idle */
400- /*
401- * due to cs_count will be updated according to cs
402- * position, assign all remainder budget array
403- * elements as @bw_cost_per_microframe, but only first
404- * @num_budget_microframes elements will be used later
405- */
406- for (i = 2 ; i < TT_MICROFRAMES_MAX ; i ++ )
407- bwb_table [i ] = sch_ep -> bw_cost_per_microframe ;
408- }
360+ sch_ep -> bw_cost_per_microframe = min_t (u32 , maxpkt , FS_PAYLOAD_MAX );
409361 }
410362}
411363
@@ -422,7 +374,7 @@ static u32 get_max_bw(struct mu3h_sch_bw_info *sch_bw,
422374
423375 for (j = 0 ; j < sch_ep -> num_budget_microframes ; j ++ ) {
424376 k = XHCI_MTK_BW_INDEX (base + j );
425- bw = sch_bw -> bus_bw [k ] + sch_ep -> bw_budget_table [ j ] ;
377+ bw = sch_bw -> bus_bw [k ] + sch_ep -> bw_cost_per_microframe ;
426378 if (bw > max_bw )
427379 max_bw = bw ;
428380 }
@@ -433,18 +385,16 @@ static u32 get_max_bw(struct mu3h_sch_bw_info *sch_bw,
433385static void update_bus_bw (struct mu3h_sch_bw_info * sch_bw ,
434386 struct mu3h_sch_ep_info * sch_ep , bool used )
435387{
388+ int bw_updated ;
436389 u32 base ;
437- int i , j , k ;
390+ int i , j ;
391+
392+ bw_updated = sch_ep -> bw_cost_per_microframe * (used ? 1 : -1 );
438393
439394 for (i = 0 ; i < sch_ep -> num_esit ; i ++ ) {
440395 base = sch_ep -> offset + i * sch_ep -> esit ;
441- for (j = 0 ; j < sch_ep -> num_budget_microframes ; j ++ ) {
442- k = XHCI_MTK_BW_INDEX (base + j );
443- if (used )
444- sch_bw -> bus_bw [k ] += sch_ep -> bw_budget_table [j ];
445- else
446- sch_bw -> bus_bw [k ] -= sch_ep -> bw_budget_table [j ];
447- }
396+ for (j = 0 ; j < sch_ep -> num_budget_microframes ; j ++ )
397+ sch_bw -> bus_bw [XHCI_MTK_BW_INDEX (base + j )] += bw_updated ;
448398 }
449399}
450400
@@ -464,7 +414,7 @@ static int check_fs_bus_bw(struct mu3h_sch_ep_info *sch_ep, int offset)
464414 */
465415 for (j = 0 ; j < sch_ep -> num_budget_microframes ; j ++ ) {
466416 k = XHCI_MTK_BW_INDEX (base + j );
467- tmp = tt -> fs_bus_bw [k ] + sch_ep -> bw_budget_table [ j ] ;
417+ tmp = tt -> fs_bus_bw [k ] + sch_ep -> bw_cost_per_microframe ;
468418 if (tmp > FS_PAYLOAD_MAX )
469419 return - ESCH_BW_OVERFLOW ;
470420 }
@@ -538,19 +488,17 @@ static int check_sch_tt(struct mu3h_sch_ep_info *sch_ep, u32 offset)
538488static void update_sch_tt (struct mu3h_sch_ep_info * sch_ep , bool used )
539489{
540490 struct mu3h_sch_tt * tt = sch_ep -> sch_tt ;
491+ int bw_updated ;
541492 u32 base ;
542- int i , j , k ;
493+ int i , j ;
494+
495+ bw_updated = sch_ep -> bw_cost_per_microframe * (used ? 1 : -1 );
543496
544497 for (i = 0 ; i < sch_ep -> num_esit ; i ++ ) {
545498 base = sch_ep -> offset + i * sch_ep -> esit ;
546499
547- for (j = 0 ; j < sch_ep -> num_budget_microframes ; j ++ ) {
548- k = XHCI_MTK_BW_INDEX (base + j );
549- if (used )
550- tt -> fs_bus_bw [k ] += sch_ep -> bw_budget_table [j ];
551- else
552- tt -> fs_bus_bw [k ] -= sch_ep -> bw_budget_table [j ];
553- }
500+ for (j = 0 ; j < sch_ep -> num_budget_microframes ; j ++ )
501+ tt -> fs_bus_bw [XHCI_MTK_BW_INDEX (base + j )] += bw_updated ;
554502 }
555503
556504 if (used )
@@ -710,7 +658,7 @@ static int add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
710658
711659 xhci_dbg (xhci , "%s %s\n" , __func__ , decode_ep (ep , udev -> speed ));
712660
713- sch_ep = create_sch_ep (mtk , udev , ep , ep_ctx );
661+ sch_ep = create_sch_ep (mtk , udev , ep );
714662 if (IS_ERR_OR_NULL (sch_ep ))
715663 return - ENOMEM ;
716664
0 commit comments