Skip to content

Commit 1645eee

Browse files
Chunfeng Yungregkh
authored andcommitted
usb: xhci-mtk: remove bandwidth budget table
The bandwidth budget table is introduced to trace ideal bandwidth used by each INT/ISOC endpoint, but in fact the endpoint may consume more bandwidth and cause data transfer error, so it's better to leave some margin. Obviously it's difficult to find the best margin for all cases, instead take use of the worst-case scenario. Signed-off-by: Chunfeng Yun <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c237566 commit 1645eee

File tree

2 files changed

+12
-64
lines changed

2 files changed

+12
-64
lines changed

drivers/usb/host/xhci-mtk-sch.c

Lines changed: 12 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
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

243238
static struct mu3h_sch_ep_info *
244239
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)
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,
433385
static 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

@@ -708,7 +658,7 @@ static int add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
708658

709659
xhci_dbg(xhci, "%s %s\n", __func__, decode_ep(ep, udev->speed));
710660

711-
sch_ep = create_sch_ep(mtk, udev, ep, ep_ctx);
661+
sch_ep = create_sch_ep(mtk, udev, ep);
712662
if (IS_ERR_OR_NULL(sch_ep))
713663
return -ENOMEM;
714664

drivers/usb/host/xhci-mtk.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ struct mu3h_sch_bw_info {
8383
* times; 1: distribute the (bMaxBurst+1)*(Mult+1) packets
8484
* according to @pkts and @repeat. normal mode is used by
8585
* default
86-
* @bw_budget_table: table to record bandwidth budget per microframe
8786
*/
8887
struct mu3h_sch_ep_info {
8988
u32 esit;
@@ -109,7 +108,6 @@ struct mu3h_sch_ep_info {
109108
u32 pkts;
110109
u32 cs_count;
111110
u32 burst_mode;
112-
u32 bw_budget_table[];
113111
};
114112

115113
#define MU3C_U3_PORT_MAX 4

0 commit comments

Comments
 (0)