1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2015 MediaTek Inc.
5 * Zhigang.Wei <zhigang.wei@mediatek.com>
6 * Chunfeng.Yun <chunfeng.yun@mediatek.com>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/slab.h>
16 #define SSP_BW_BOUNDARY 130000
17 #define SS_BW_BOUNDARY 51000
18 /* table 5-5. High-speed Isoc Transaction Limits in usb_20 spec */
19 #define HS_BW_BOUNDARY 6144
20 /* usb2 spec section11.18.1: at most 188 FS bytes per microframe */
21 #define FS_PAYLOAD_MAX 188
23 * max number of microframes for split transfer,
24 * for fs isoc in : 1 ss + 1 idle + 7 cs
26 #define TT_MICROFRAMES_MAX 9
30 /* schedule error type */
31 #define ESCH_SS_Y6 1001
32 #define ESCH_SS_OVERLAP 1002
33 #define ESCH_CS_OVERFLOW 1003
34 #define ESCH_BW_OVERFLOW 1004
35 #define ESCH_FIXME 1005
37 /* mtk scheduler bitmasks */
38 #define EP_BPKTS(p) ((p) & 0x7f)
39 #define EP_BCSCOUNT(p) (((p) & 0x7) << 8)
40 #define EP_BBM(p) ((p) << 11)
41 #define EP_BOFFSET(p) ((p) & 0x3fff)
42 #define EP_BREPEAT(p) (((p) & 0x7fff) << 16)
44 static char *sch_error_string(int err_num)
48 return "Can't schedule Start-Split in Y6";
50 return "Can't find a suitable Start-Split location";
51 case ESCH_CS_OVERFLOW:
52 return "The last Complete-Split is greater than 7";
53 case ESCH_BW_OVERFLOW:
54 return "Bandwidth exceeds the maximum limit";
56 return "FIXME, to be resolved";
62 static int is_fs_or_ls(enum usb_device_speed speed)
64 return speed == USB_SPEED_FULL || speed == USB_SPEED_LOW;
68 decode_ep(struct usb_host_endpoint *ep, enum usb_device_speed speed)
70 static char buf[DBG_BUF_EN];
71 struct usb_endpoint_descriptor *epd = &ep->desc;
72 unsigned int interval;
75 interval = usb_decode_interval(epd, speed);
76 if (interval % 1000) {
83 snprintf(buf, DBG_BUF_EN, "%s ep%d%s %s, mpkt:%d, interval:%d/%d%s",
84 usb_speed_string(speed), usb_endpoint_num(epd),
85 usb_endpoint_dir_in(epd) ? "in" : "out",
86 usb_ep_type_string(usb_endpoint_type(epd)),
87 usb_endpoint_maxp(epd), epd->bInterval, interval, unit);
92 static u32 get_bw_boundary(enum usb_device_speed speed)
97 case USB_SPEED_SUPER_PLUS:
98 boundary = SSP_BW_BOUNDARY;
100 case USB_SPEED_SUPER:
101 boundary = SS_BW_BOUNDARY;
104 boundary = HS_BW_BOUNDARY;
112 * get the bandwidth domain which @ep belongs to.
114 * the bandwidth domain array is saved to @sch_array of struct xhci_hcd_mtk,
115 * each HS root port is treated as a single bandwidth domain,
116 * but each SS root port is treated as two bandwidth domains, one for IN eps,
118 * @real_port value is defined as follow according to xHCI spec:
119 * 1 for SSport0, ..., N+1 for SSportN, N+2 for HSport0, N+3 for HSport1, etc
120 * so the bandwidth domain array is organized as follow for simplification:
121 * SSport0-OUT, SSport0-IN, ..., SSportX-OUT, SSportX-IN, HSport0, ..., HSportY
123 static struct mu3h_sch_bw_info *
124 get_bw_info(struct xhci_hcd_mtk *mtk, struct usb_device *udev,
125 struct usb_host_endpoint *ep)
127 struct xhci_hcd *xhci = hcd_to_xhci(mtk->hcd);
128 struct xhci_virt_device *virt_dev;
131 virt_dev = xhci->devs[udev->slot_id];
132 if (WARN_ONCE(!virt_dev, "xhci-mtk: usb %s has no virt_dev\n",
133 dev_name(&udev->dev)))
135 if (WARN_ONCE(!virt_dev->real_port, "xhci-mtk: usb %s has invalid port number\n",
136 dev_name(&udev->dev)))
139 if (udev->speed >= USB_SPEED_SUPER) {
140 if (usb_endpoint_dir_out(&ep->desc))
141 bw_index = (virt_dev->real_port - 1) * 2;
143 bw_index = (virt_dev->real_port - 1) * 2 + 1;
145 /* add one more for each SS port */
146 bw_index = virt_dev->real_port + xhci->usb3_rhub.num_ports - 1;
149 return &mtk->sch_array[bw_index];
152 static u32 get_esit(struct xhci_ep_ctx *ep_ctx)
156 esit = 1 << CTX_TO_EP_INTERVAL(le32_to_cpu(ep_ctx->ep_info));
157 if (esit > XHCI_MTK_MAX_ESIT)
158 esit = XHCI_MTK_MAX_ESIT;
163 static struct mu3h_sch_tt *find_tt(struct usb_device *udev)
165 struct usb_tt *utt = udev->tt;
166 struct mu3h_sch_tt *tt, **tt_index, **ptt;
167 bool allocated_index = false;
170 return NULL; /* Not below a TT */
173 * Find/create our data structure.
174 * For hubs with a single TT, we get it directly.
175 * For hubs with multiple TTs, there's an extra level of pointers.
179 tt_index = utt->hcpriv;
180 if (!tt_index) { /* Create the index array */
181 tt_index = kcalloc(utt->hub->maxchild,
182 sizeof(*tt_index), GFP_KERNEL);
184 return ERR_PTR(-ENOMEM);
185 utt->hcpriv = tt_index;
186 allocated_index = true;
188 ptt = &tt_index[udev->ttport - 1];
190 ptt = (struct mu3h_sch_tt **) &utt->hcpriv;
194 if (!tt) { /* Create the mu3h_sch_tt */
195 tt = kzalloc(sizeof(*tt), GFP_KERNEL);
197 if (allocated_index) {
201 return ERR_PTR(-ENOMEM);
209 /* Release the TT above udev, if it's not in use */
210 static void drop_tt(struct usb_device *udev)
212 struct usb_tt *utt = udev->tt;
213 struct mu3h_sch_tt *tt, **tt_index, **ptt;
216 if (!utt || !utt->hcpriv)
217 return; /* Not below a TT, or never allocated */
221 tt_index = utt->hcpriv;
222 ptt = &tt_index[udev->ttport - 1];
223 /* How many entries are left in tt_index? */
224 for (i = 0; i < utt->hub->maxchild; ++i)
225 cnt += !!tt_index[i];
228 ptt = (struct mu3h_sch_tt **)&utt->hcpriv;
232 if (!tt || tt->nr_eps > 0)
233 return; /* never allocated , or still in use*/
244 static struct mu3h_sch_ep_info *create_sch_ep(struct xhci_hcd_mtk *mtk,
245 struct usb_device *udev, struct usb_host_endpoint *ep,
246 struct xhci_ep_ctx *ep_ctx)
248 struct mu3h_sch_ep_info *sch_ep;
249 struct mu3h_sch_tt *tt = NULL;
250 u32 len_bw_budget_table;
252 struct mu3h_sch_bw_info *bw_info;
254 bw_info = get_bw_info(mtk, udev, ep);
256 return ERR_PTR(-ENODEV);
258 if (is_fs_or_ls(udev->speed))
259 len_bw_budget_table = TT_MICROFRAMES_MAX;
260 else if ((udev->speed >= USB_SPEED_SUPER)
261 && usb_endpoint_xfer_isoc(&ep->desc))
262 len_bw_budget_table = get_esit(ep_ctx);
264 len_bw_budget_table = 1;
266 mem_size = sizeof(struct mu3h_sch_ep_info) +
267 len_bw_budget_table * sizeof(u32);
268 sch_ep = kzalloc(mem_size, GFP_KERNEL);
270 return ERR_PTR(-ENOMEM);
272 if (is_fs_or_ls(udev->speed)) {
276 return ERR_PTR(-ENOMEM);
280 sch_ep->bw_info = bw_info;
283 sch_ep->speed = udev->speed;
288 static void setup_sch_info(struct xhci_ep_ctx *ep_ctx,
289 struct mu3h_sch_ep_info *sch_ep)
296 u32 max_esit_payload;
297 u32 *bwb_table = sch_ep->bw_budget_table;
300 ep_type = CTX_TO_EP_TYPE(le32_to_cpu(ep_ctx->ep_info2));
301 maxpkt = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2));
302 max_burst = CTX_TO_MAX_BURST(le32_to_cpu(ep_ctx->ep_info2));
303 mult = CTX_TO_EP_MULT(le32_to_cpu(ep_ctx->ep_info));
305 (CTX_TO_MAX_ESIT_PAYLOAD_HI(
306 le32_to_cpu(ep_ctx->ep_info)) << 16) |
307 CTX_TO_MAX_ESIT_PAYLOAD(le32_to_cpu(ep_ctx->tx_info));
309 sch_ep->esit = get_esit(ep_ctx);
310 sch_ep->ep_type = ep_type;
311 sch_ep->maxpkt = maxpkt;
313 sch_ep->burst_mode = 0;
316 if (sch_ep->speed == USB_SPEED_HIGH) {
317 sch_ep->cs_count = 0;
320 * usb_20 spec section5.9
321 * a single microframe is enough for HS synchromous endpoints
324 sch_ep->num_budget_microframes = 1;
327 * xHCI spec section6.2.3.4
328 * @max_burst is the number of additional transactions
329 * opportunities per microframe
331 sch_ep->pkts = max_burst + 1;
332 sch_ep->bw_cost_per_microframe = maxpkt * sch_ep->pkts;
333 bwb_table[0] = sch_ep->bw_cost_per_microframe;
334 } else if (sch_ep->speed >= USB_SPEED_SUPER) {
335 /* usb3_r1 spec section4.4.7 & 4.4.8 */
336 sch_ep->cs_count = 0;
337 sch_ep->burst_mode = 1;
339 * some device's (d)wBytesPerInterval is set as 0,
340 * then max_esit_payload is 0, so evaluate esit_pkts from
343 esit_pkts = DIV_ROUND_UP(max_esit_payload, maxpkt);
345 esit_pkts = (mult + 1) * (max_burst + 1);
347 if (ep_type == INT_IN_EP || ep_type == INT_OUT_EP) {
348 sch_ep->pkts = esit_pkts;
349 sch_ep->num_budget_microframes = 1;
350 bwb_table[0] = maxpkt * sch_ep->pkts;
353 if (ep_type == ISOC_IN_EP || ep_type == ISOC_OUT_EP) {
355 if (sch_ep->esit == 1)
356 sch_ep->pkts = esit_pkts;
357 else if (esit_pkts <= sch_ep->esit)
360 sch_ep->pkts = roundup_pow_of_two(esit_pkts)
363 sch_ep->num_budget_microframes =
364 DIV_ROUND_UP(esit_pkts, sch_ep->pkts);
366 sch_ep->repeat = !!(sch_ep->num_budget_microframes > 1);
367 sch_ep->bw_cost_per_microframe = maxpkt * sch_ep->pkts;
369 for (i = 0; i < sch_ep->num_budget_microframes - 1; i++)
370 bwb_table[i] = sch_ep->bw_cost_per_microframe;
372 /* last one <= bw_cost_per_microframe */
373 bwb_table[i] = maxpkt * esit_pkts
374 - i * sch_ep->bw_cost_per_microframe;
376 } else if (is_fs_or_ls(sch_ep->speed)) {
377 sch_ep->pkts = 1; /* at most one packet for each microframe */
380 * num_budget_microframes and cs_count will be updated when
381 * check TT for INT_OUT_EP, ISOC/INT_IN_EP type
383 sch_ep->cs_count = DIV_ROUND_UP(maxpkt, FS_PAYLOAD_MAX);
384 sch_ep->num_budget_microframes = sch_ep->cs_count;
385 sch_ep->bw_cost_per_microframe =
386 (maxpkt < FS_PAYLOAD_MAX) ? maxpkt : FS_PAYLOAD_MAX;
388 /* init budget table */
389 if (ep_type == ISOC_OUT_EP) {
390 for (i = 0; i < sch_ep->num_budget_microframes; i++)
391 bwb_table[i] = sch_ep->bw_cost_per_microframe;
392 } else if (ep_type == INT_OUT_EP) {
393 /* only first one consumes bandwidth, others as zero */
394 bwb_table[0] = sch_ep->bw_cost_per_microframe;
395 } else { /* INT_IN_EP or ISOC_IN_EP */
396 bwb_table[0] = 0; /* start split */
397 bwb_table[1] = 0; /* idle */
399 * due to cs_count will be updated according to cs
400 * position, assign all remainder budget array
401 * elements as @bw_cost_per_microframe, but only first
402 * @num_budget_microframes elements will be used later
404 for (i = 2; i < TT_MICROFRAMES_MAX; i++)
405 bwb_table[i] = sch_ep->bw_cost_per_microframe;
410 /* Get maximum bandwidth when we schedule at offset slot. */
411 static u32 get_max_bw(struct mu3h_sch_bw_info *sch_bw,
412 struct mu3h_sch_ep_info *sch_ep, u32 offset)
420 num_esit = XHCI_MTK_MAX_ESIT / sch_ep->esit;
421 for (i = 0; i < num_esit; i++) {
422 u32 base = offset + i * sch_ep->esit;
424 for (j = 0; j < sch_ep->num_budget_microframes; j++) {
425 bw = sch_bw->bus_bw[base + j] +
426 sch_ep->bw_budget_table[j];
434 static void update_bus_bw(struct mu3h_sch_bw_info *sch_bw,
435 struct mu3h_sch_ep_info *sch_ep, bool used)
442 num_esit = XHCI_MTK_MAX_ESIT / sch_ep->esit;
443 for (i = 0; i < num_esit; i++) {
444 base = sch_ep->offset + i * sch_ep->esit;
445 for (j = 0; j < sch_ep->num_budget_microframes; j++) {
447 sch_bw->bus_bw[base + j] +=
448 sch_ep->bw_budget_table[j];
450 sch_bw->bus_bw[base + j] -=
451 sch_ep->bw_budget_table[j];
456 static int check_fs_bus_bw(struct mu3h_sch_ep_info *sch_ep, int offset)
458 struct mu3h_sch_tt *tt = sch_ep->sch_tt;
463 num_esit = XHCI_MTK_MAX_ESIT / sch_ep->esit;
464 for (i = 0; i < num_esit; i++) {
465 base = offset + i * sch_ep->esit;
468 * Compared with hs bus, no matter what ep type,
469 * the hub will always delay one uframe to send data
471 for (j = 0; j < sch_ep->cs_count; j++) {
472 tmp = tt->fs_bus_bw[base + j] + sch_ep->bw_cost_per_microframe;
473 if (tmp > FS_PAYLOAD_MAX)
474 return -ESCH_BW_OVERFLOW;
481 static int check_sch_tt(struct mu3h_sch_ep_info *sch_ep, u32 offset)
484 u32 start_ss, last_ss;
485 u32 start_cs, last_cs;
490 start_ss = offset % 8;
492 if (sch_ep->ep_type == ISOC_OUT_EP) {
493 last_ss = start_ss + sch_ep->cs_count - 1;
496 * usb_20 spec section11.18:
497 * must never schedule Start-Split in Y6
499 if (!(start_ss == 7 || last_ss < 6))
503 u32 cs_count = DIV_ROUND_UP(sch_ep->maxpkt, FS_PAYLOAD_MAX);
506 * usb_20 spec section11.18:
507 * must never schedule Start-Split in Y6
512 /* one uframe for ss + one uframe for idle */
513 start_cs = (start_ss + 2) % 8;
514 last_cs = start_cs + cs_count - 1;
517 return -ESCH_CS_OVERFLOW;
519 if (sch_ep->ep_type == ISOC_IN_EP)
520 extra_cs_count = (last_cs == 7) ? 1 : 2;
521 else /* ep_type : INTR IN / INTR OUT */
524 cs_count += extra_cs_count;
526 cs_count = 7; /* HW limit */
528 sch_ep->cs_count = cs_count;
529 /* one for ss, the other for idle */
530 sch_ep->num_budget_microframes = cs_count + 2;
533 * if interval=1, maxp >752, num_budge_micoframe is larger
534 * than sch_ep->esit, will overstep boundary
536 if (sch_ep->num_budget_microframes > sch_ep->esit)
537 sch_ep->num_budget_microframes = sch_ep->esit;
540 return check_fs_bus_bw(sch_ep, offset);
543 static void update_sch_tt(struct mu3h_sch_ep_info *sch_ep, bool used)
545 struct mu3h_sch_tt *tt = sch_ep->sch_tt;
550 num_esit = XHCI_MTK_MAX_ESIT / sch_ep->esit;
553 bw_updated = sch_ep->bw_cost_per_microframe;
555 bw_updated = -sch_ep->bw_cost_per_microframe;
557 for (i = 0; i < num_esit; i++) {
558 base = sch_ep->offset + i * sch_ep->esit;
560 for (j = 0; j < sch_ep->cs_count; j++)
561 tt->fs_bus_bw[base + j] += bw_updated;
566 else if (!WARN_ONCE(tt->nr_eps < 1, "unbalanced sch_tt's ep count"))
570 static int load_ep_bw(struct mu3h_sch_bw_info *sch_bw,
571 struct mu3h_sch_ep_info *sch_ep, bool loaded)
574 update_sch_tt(sch_ep, loaded);
576 /* update bus bandwidth info */
577 update_bus_bw(sch_bw, sch_ep, loaded);
578 sch_ep->allocated = loaded;
583 static u32 get_esit_boundary(struct mu3h_sch_ep_info *sch_ep)
585 u32 boundary = sch_ep->esit;
587 if (sch_ep->sch_tt) { /* LS/FS with TT */
589 if (sch_ep->ep_type != ISOC_OUT_EP)
591 else if (boundary > 1) /* normally esit >= 8 for FS/LS */
598 static int check_sch_bw(struct mu3h_sch_ep_info *sch_ep)
600 struct mu3h_sch_bw_info *sch_bw = sch_ep->bw_info;
601 const u32 esit_boundary = get_esit_boundary(sch_ep);
602 const u32 bw_boundary = get_bw_boundary(sch_ep->speed);
610 * Search through all possible schedule microframes.
611 * and find a microframe where its worst bandwidth is minimum.
613 for (offset = 0; offset < sch_ep->esit; offset++) {
614 ret = check_sch_tt(sch_ep, offset);
618 if ((offset + sch_ep->num_budget_microframes) > esit_boundary)
621 worst_bw = get_max_bw(sch_bw, sch_ep, offset);
622 if (worst_bw > bw_boundary)
625 if (min_bw > worst_bw) {
630 /* use first-fit for LS/FS */
631 if (sch_ep->sch_tt && min_index >= 0)
639 return ret ? ret : -ESCH_BW_OVERFLOW;
641 sch_ep->offset = min_index;
643 return load_ep_bw(sch_bw, sch_ep, true);
646 static const struct rhashtable_params sch_ep_table_param = {
647 .key_len = sizeof(struct usb_host_endpoint *),
648 .key_offset = offsetof(struct mu3h_sch_ep_info, ep),
649 .head_offset = offsetof(struct mu3h_sch_ep_info, ep_link),
652 static void destroy_sch_ep(struct xhci_hcd_mtk *mtk, struct usb_device *udev,
653 struct mu3h_sch_ep_info *sch_ep)
655 /* only release ep bw check passed by check_sch_bw() */
656 if (sch_ep->allocated)
657 load_ep_bw(sch_ep->bw_info, sch_ep, false);
662 list_del(&sch_ep->endpoint);
663 rhashtable_remove_fast(&mtk->sch_ep_table, &sch_ep->ep_link,
668 static bool need_bw_sch(struct usb_device *udev,
669 struct usb_host_endpoint *ep)
671 bool has_tt = udev->tt && udev->tt->hub->parent;
673 /* only for periodic endpoints */
674 if (usb_endpoint_xfer_control(&ep->desc)
675 || usb_endpoint_xfer_bulk(&ep->desc))
679 * for LS & FS periodic endpoints which its device is not behind
680 * a TT are also ignored, root-hub will schedule them directly,
681 * but need set @bpkts field of endpoint context to 1.
683 if (is_fs_or_ls(udev->speed) && !has_tt)
686 /* skip endpoint with zero maxpkt */
687 if (usb_endpoint_maxp(&ep->desc) == 0)
693 int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk)
695 struct xhci_hcd *xhci = hcd_to_xhci(mtk->hcd);
696 struct mu3h_sch_bw_info *sch_array;
700 /* mu3h_sch_ep_info table, 'usb_host_endpoint*' as a key */
701 ret = rhashtable_init(&mtk->sch_ep_table, &sch_ep_table_param);
705 /* ss IN and OUT are separated */
706 num_usb_bus = xhci->usb3_rhub.num_ports * 2 + xhci->usb2_rhub.num_ports;
708 sch_array = kcalloc(num_usb_bus, sizeof(*sch_array), GFP_KERNEL);
709 if (sch_array == NULL)
712 mtk->sch_array = sch_array;
714 INIT_LIST_HEAD(&mtk->bw_ep_chk_list);
719 void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk)
721 rhashtable_destroy(&mtk->sch_ep_table);
722 kfree(mtk->sch_array);
725 static int add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
726 struct usb_host_endpoint *ep)
728 struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
729 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
730 struct xhci_ep_ctx *ep_ctx;
731 struct xhci_virt_device *virt_dev;
732 struct mu3h_sch_ep_info *sch_ep;
733 unsigned int ep_index;
735 virt_dev = xhci->devs[udev->slot_id];
736 ep_index = xhci_get_endpoint_index(&ep->desc);
737 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
739 if (!need_bw_sch(udev, ep)) {
741 * set @bpkts to 1 if it is LS or FS periodic endpoint, and its
742 * device does not connected through an external HS hub
744 if (usb_endpoint_xfer_int(&ep->desc)
745 || usb_endpoint_xfer_isoc(&ep->desc))
746 ep_ctx->reserved[0] = cpu_to_le32(EP_BPKTS(1));
751 xhci_dbg(xhci, "%s %s\n", __func__, decode_ep(ep, udev->speed));
753 sch_ep = create_sch_ep(mtk, udev, ep, ep_ctx);
754 if (IS_ERR_OR_NULL(sch_ep))
757 if (rhashtable_insert_fast(&mtk->sch_ep_table, &sch_ep->ep_link,
761 setup_sch_info(ep_ctx, sch_ep);
763 list_add_tail(&sch_ep->endpoint, &mtk->bw_ep_chk_list);
765 xhci_dbg(xhci, "added sch_ep %p : %p\n", sch_ep, ep);
770 static void drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
771 struct usb_host_endpoint *ep)
773 struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
774 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
775 struct mu3h_sch_ep_info *sch_ep;
778 if (!need_bw_sch(udev, ep))
781 xhci_dbg(xhci, "%s %s\n", __func__, decode_ep(ep, udev->speed));
783 sch_ep = rhashtable_lookup_fast(&mtk->sch_ep_table, &key,
786 destroy_sch_ep(mtk, udev, sch_ep);
788 xhci_dbg(xhci, "ep %p is not on the bw table\n", ep);
791 int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
793 struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
794 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
795 struct xhci_virt_device *virt_dev = xhci->devs[udev->slot_id];
796 struct mu3h_sch_ep_info *sch_ep;
799 xhci_dbg(xhci, "%s() udev %s\n", __func__, dev_name(&udev->dev));
801 list_for_each_entry(sch_ep, &mtk->bw_ep_chk_list, endpoint) {
802 struct xhci_ep_ctx *ep_ctx;
803 struct usb_host_endpoint *ep = sch_ep->ep;
804 unsigned int ep_index = xhci_get_endpoint_index(&ep->desc);
806 ret = check_sch_bw(sch_ep);
808 xhci_err(xhci, "Not enough bandwidth! (%s)\n",
809 sch_error_string(-ret));
813 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
814 ep_ctx->reserved[0] = cpu_to_le32(EP_BPKTS(sch_ep->pkts)
815 | EP_BCSCOUNT(sch_ep->cs_count)
816 | EP_BBM(sch_ep->burst_mode));
817 ep_ctx->reserved[1] = cpu_to_le32(EP_BOFFSET(sch_ep->offset)
818 | EP_BREPEAT(sch_ep->repeat));
820 xhci_dbg(xhci, " PKTS:%x, CSCOUNT:%x, BM:%x, OFFSET:%x, REPEAT:%x\n",
821 sch_ep->pkts, sch_ep->cs_count, sch_ep->burst_mode,
822 sch_ep->offset, sch_ep->repeat);
825 ret = xhci_check_bandwidth(hcd, udev);
827 INIT_LIST_HEAD(&mtk->bw_ep_chk_list);
832 void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
834 struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
835 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
836 struct mu3h_sch_ep_info *sch_ep, *tmp;
838 xhci_dbg(xhci, "%s() udev %s\n", __func__, dev_name(&udev->dev));
840 list_for_each_entry_safe(sch_ep, tmp, &mtk->bw_ep_chk_list, endpoint)
841 destroy_sch_ep(mtk, udev, sch_ep);
843 xhci_reset_bandwidth(hcd, udev);
846 int xhci_mtk_add_ep(struct usb_hcd *hcd, struct usb_device *udev,
847 struct usb_host_endpoint *ep)
851 ret = xhci_add_endpoint(hcd, udev, ep);
856 ret = add_ep_quirk(hcd, udev, ep);
861 int xhci_mtk_drop_ep(struct usb_hcd *hcd, struct usb_device *udev,
862 struct usb_host_endpoint *ep)
866 ret = xhci_drop_endpoint(hcd, udev, ep);
870 drop_ep_quirk(hcd, udev, ep);