19
19
#define HS_BW_BOUNDARY 6144
20
20
/* usb2 spec section11.18.1: at most 188 FS bytes per microframe */
21
21
#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
27
22
28
23
#define DBG_BUF_EN 64
29
24
@@ -242,28 +237,17 @@ static void drop_tt(struct usb_device *udev)
242
237
243
238
static struct mu3h_sch_ep_info *
244
239
create_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 )
246
241
{
247
242
struct mu3h_sch_ep_info * sch_ep ;
248
243
struct mu3h_sch_bw_info * bw_info ;
249
244
struct mu3h_sch_tt * tt = NULL ;
250
- u32 len_bw_budget_table ;
251
245
252
246
bw_info = get_bw_info (mtk , udev , ep );
253
247
if (!bw_info )
254
248
return ERR_PTR (- ENODEV );
255
249
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 );
267
251
if (!sch_ep )
268
252
return ERR_PTR (- ENOMEM );
269
253
@@ -295,8 +279,6 @@ static void setup_sch_info(struct xhci_ep_ctx *ep_ctx,
295
279
u32 mult ;
296
280
u32 esit_pkts ;
297
281
u32 max_esit_payload ;
298
- u32 * bwb_table = sch_ep -> bw_budget_table ;
299
- int i ;
300
282
301
283
ep_type = CTX_TO_EP_TYPE (le32_to_cpu (ep_ctx -> ep_info2 ));
302
284
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,
332
314
*/
333
315
sch_ep -> pkts = max_burst + 1 ;
334
316
sch_ep -> bw_cost_per_microframe = maxpkt * sch_ep -> pkts ;
335
- bwb_table [0 ] = sch_ep -> bw_cost_per_microframe ;
336
317
} else if (sch_ep -> speed >= USB_SPEED_SUPER ) {
337
318
/* usb3_r1 spec section4.4.7 & 4.4.8 */
338
319
sch_ep -> cs_count = 0 ;
@@ -349,7 +330,6 @@ static void setup_sch_info(struct xhci_ep_ctx *ep_ctx,
349
330
if (ep_type == INT_IN_EP || ep_type == INT_OUT_EP ) {
350
331
sch_ep -> pkts = esit_pkts ;
351
332
sch_ep -> num_budget_microframes = 1 ;
352
- bwb_table [0 ] = maxpkt * sch_ep -> pkts ;
353
333
}
354
334
355
335
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,
366
346
DIV_ROUND_UP (esit_pkts , sch_ep -> pkts );
367
347
368
348
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 ;
377
349
}
350
+ sch_ep -> bw_cost_per_microframe = maxpkt * sch_ep -> pkts ;
378
351
} else if (is_fs_or_ls (sch_ep -> speed )) {
379
352
sch_ep -> pkts = 1 ; /* at most one packet for each microframe */
380
353
@@ -384,28 +357,7 @@ static void setup_sch_info(struct xhci_ep_ctx *ep_ctx,
384
357
*/
385
358
sch_ep -> cs_count = DIV_ROUND_UP (maxpkt , FS_PAYLOAD_MAX );
386
359
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 );
409
361
}
410
362
}
411
363
@@ -422,7 +374,7 @@ static u32 get_max_bw(struct mu3h_sch_bw_info *sch_bw,
422
374
423
375
for (j = 0 ; j < sch_ep -> num_budget_microframes ; j ++ ) {
424
376
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 ;
426
378
if (bw > max_bw )
427
379
max_bw = bw ;
428
380
}
@@ -433,18 +385,16 @@ static u32 get_max_bw(struct mu3h_sch_bw_info *sch_bw,
433
385
static void update_bus_bw (struct mu3h_sch_bw_info * sch_bw ,
434
386
struct mu3h_sch_ep_info * sch_ep , bool used )
435
387
{
388
+ int bw_updated ;
436
389
u32 base ;
437
- int i , j , k ;
390
+ int i , j ;
391
+
392
+ bw_updated = sch_ep -> bw_cost_per_microframe * (used ? 1 : -1 );
438
393
439
394
for (i = 0 ; i < sch_ep -> num_esit ; i ++ ) {
440
395
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 ;
448
398
}
449
399
}
450
400
@@ -464,7 +414,7 @@ static int check_fs_bus_bw(struct mu3h_sch_ep_info *sch_ep, int offset)
464
414
*/
465
415
for (j = 0 ; j < sch_ep -> num_budget_microframes ; j ++ ) {
466
416
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 ;
468
418
if (tmp > FS_PAYLOAD_MAX )
469
419
return - ESCH_BW_OVERFLOW ;
470
420
}
@@ -538,19 +488,17 @@ static int check_sch_tt(struct mu3h_sch_ep_info *sch_ep, u32 offset)
538
488
static void update_sch_tt (struct mu3h_sch_ep_info * sch_ep , bool used )
539
489
{
540
490
struct mu3h_sch_tt * tt = sch_ep -> sch_tt ;
491
+ int bw_updated ;
541
492
u32 base ;
542
- int i , j , k ;
493
+ int i , j ;
494
+
495
+ bw_updated = sch_ep -> bw_cost_per_microframe * (used ? 1 : -1 );
543
496
544
497
for (i = 0 ; i < sch_ep -> num_esit ; i ++ ) {
545
498
base = sch_ep -> offset + i * sch_ep -> esit ;
546
499
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 ;
554
502
}
555
503
556
504
if (used )
@@ -710,7 +658,7 @@ static int add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
710
658
711
659
xhci_dbg (xhci , "%s %s\n" , __func__ , decode_ep (ep , udev -> speed ));
712
660
713
- sch_ep = create_sch_ep (mtk , udev , ep , ep_ctx );
661
+ sch_ep = create_sch_ep (mtk , udev , ep );
714
662
if (IS_ERR_OR_NULL (sch_ep ))
715
663
return - ENOMEM ;
716
664
0 commit comments