Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 * Copyright (c) 2015 MediaTek Inc.
  3 * Author:
  4 *  Zhigang.Wei <zhigang.wei@mediatek.com>
  5 *  Chunfeng.Yun <chunfeng.yun@mediatek.com>
  6 *
  7 * This software is licensed under the terms of the GNU General Public
  8 * License version 2, as published by the Free Software Foundation, and
  9 * may be copied, distributed, and modified under those terms.
 10 *
 11 * This program is distributed in the hope that it will be useful,
 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 * GNU General Public License for more details.
 15 *
 16 */
 17
 18#include <linux/kernel.h>
 19#include <linux/module.h>
 20#include <linux/slab.h>
 21
 22#include "xhci.h"
 23#include "xhci-mtk.h"
 24
 
 25#define SS_BW_BOUNDARY	51000
 26/* table 5-5. High-speed Isoc Transaction Limits in usb_20 spec */
 27#define HS_BW_BOUNDARY	6144
 28/* usb2 spec section11.18.1: at most 188 FS bytes per microframe */
 29#define FS_PAYLOAD_MAX 188
 30
 
 
 
 
 
 
 
 
 
 31/* mtk scheduler bitmasks */
 32#define EP_BPKTS(p)	((p) & 0x3f)
 33#define EP_BCSCOUNT(p)	(((p) & 0x7) << 8)
 34#define EP_BBM(p)	((p) << 11)
 35#define EP_BOFFSET(p)	((p) & 0x3fff)
 36#define EP_BREPEAT(p)	(((p) & 0x7fff) << 16)
 37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 38static int is_fs_or_ls(enum usb_device_speed speed)
 39{
 40	return speed == USB_SPEED_FULL || speed == USB_SPEED_LOW;
 41}
 42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 43/*
 44* get the index of bandwidth domains array which @ep belongs to.
 45*
 46* the bandwidth domain array is saved to @sch_array of struct xhci_hcd_mtk,
 47* each HS root port is treated as a single bandwidth domain,
 48* but each SS root port is treated as two bandwidth domains, one for IN eps,
 49* one for OUT eps.
 50* @real_port value is defined as follow according to xHCI spec:
 51* 1 for SSport0, ..., N+1 for SSportN, N+2 for HSport0, N+3 for HSport1, etc
 52* so the bandwidth domain array is organized as follow for simplification:
 53* SSport0-OUT, SSport0-IN, ..., SSportX-OUT, SSportX-IN, HSport0, ..., HSportY
 54*/
 55static int get_bw_index(struct xhci_hcd *xhci, struct usb_device *udev,
 56	struct usb_host_endpoint *ep)
 
 57{
 
 58	struct xhci_virt_device *virt_dev;
 59	int bw_index;
 60
 61	virt_dev = xhci->devs[udev->slot_id];
 
 
 
 
 62
 63	if (udev->speed == USB_SPEED_SUPER) {
 64		if (usb_endpoint_dir_out(&ep->desc))
 65			bw_index = (virt_dev->real_port - 1) * 2;
 66		else
 67			bw_index = (virt_dev->real_port - 1) * 2 + 1;
 68	} else {
 69		/* add one more for each SS port */
 70		bw_index = virt_dev->real_port + xhci->num_usb3_ports - 1;
 71	}
 72
 73	return bw_index;
 74}
 75
 76static void setup_sch_info(struct usb_device *udev,
 77		struct xhci_ep_ctx *ep_ctx, struct mu3h_sch_ep_info *sch_ep)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 78{
 79	u32 ep_type;
 80	u32 ep_interval;
 81	u32 max_packet_size;
 82	u32 max_burst;
 83	u32 mult;
 84	u32 esit_pkts;
 
 85
 86	ep_type = CTX_TO_EP_TYPE(le32_to_cpu(ep_ctx->ep_info2));
 87	ep_interval = CTX_TO_EP_INTERVAL(le32_to_cpu(ep_ctx->ep_info));
 88	max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2));
 89	max_burst = CTX_TO_MAX_BURST(le32_to_cpu(ep_ctx->ep_info2));
 90	mult = CTX_TO_EP_MULT(le32_to_cpu(ep_ctx->ep_info));
 91
 92	sch_ep->esit = 1 << ep_interval;
 
 
 
 
 
 
 
 93	sch_ep->offset = 0;
 94	sch_ep->burst_mode = 0;
 
 95
 96	if (udev->speed == USB_SPEED_HIGH) {
 97		sch_ep->cs_count = 0;
 98
 99		/*
100		 * usb_20 spec section5.9
101		 * a single microframe is enough for HS synchromous endpoints
102		 * in a interval
103		 */
104		sch_ep->num_budget_microframes = 1;
105		sch_ep->repeat = 0;
106
107		/*
108		 * xHCI spec section6.2.3.4
109		 * @max_burst is the number of additional transactions
110		 * opportunities per microframe
111		 */
112		sch_ep->pkts = max_burst + 1;
113		sch_ep->bw_cost_per_microframe = max_packet_size * sch_ep->pkts;
114	} else if (udev->speed == USB_SPEED_SUPER) {
115		/* usb3_r1 spec section4.4.7 & 4.4.8 */
116		sch_ep->cs_count = 0;
117		esit_pkts = (mult + 1) * (max_burst + 1);
 
 
 
 
 
 
 
 
 
118		if (ep_type == INT_IN_EP || ep_type == INT_OUT_EP) {
119			sch_ep->pkts = esit_pkts;
120			sch_ep->num_budget_microframes = 1;
121			sch_ep->repeat = 0;
122		}
123
124		if (ep_type == ISOC_IN_EP || ep_type == ISOC_OUT_EP) {
125			if (esit_pkts <= sch_ep->esit)
 
 
 
126				sch_ep->pkts = 1;
127			else
128				sch_ep->pkts = roundup_pow_of_two(esit_pkts)
129					/ sch_ep->esit;
130
131			sch_ep->num_budget_microframes =
132				DIV_ROUND_UP(esit_pkts, sch_ep->pkts);
133
134			if (sch_ep->num_budget_microframes > 1)
135				sch_ep->repeat = 1;
136			else
137				sch_ep->repeat = 0;
138		}
139		sch_ep->bw_cost_per_microframe = max_packet_size * sch_ep->pkts;
140	} else if (is_fs_or_ls(udev->speed)) {
 
141
142		/*
143		 * usb_20 spec section11.18.4
144		 * assume worst cases
145		 */
146		sch_ep->repeat = 0;
147		sch_ep->pkts = 1; /* at most one packet for each microframe */
148		if (ep_type == INT_IN_EP || ep_type == INT_OUT_EP) {
149			sch_ep->cs_count = 3; /* at most need 3 CS*/
150			/* one for SS and one for budgeted transaction */
151			sch_ep->num_budget_microframes = sch_ep->cs_count + 2;
152			sch_ep->bw_cost_per_microframe = max_packet_size;
153		}
154		if (ep_type == ISOC_OUT_EP) {
155
156			/*
157			 * the best case FS budget assumes that 188 FS bytes
158			 * occur in each microframe
159			 */
160			sch_ep->num_budget_microframes = DIV_ROUND_UP(
161				max_packet_size, FS_PAYLOAD_MAX);
162			sch_ep->bw_cost_per_microframe = FS_PAYLOAD_MAX;
163			sch_ep->cs_count = sch_ep->num_budget_microframes;
164		}
165		if (ep_type == ISOC_IN_EP) {
166			/* at most need additional two CS. */
167			sch_ep->cs_count = DIV_ROUND_UP(
168				max_packet_size, FS_PAYLOAD_MAX) + 2;
169			sch_ep->num_budget_microframes = sch_ep->cs_count + 2;
170			sch_ep->bw_cost_per_microframe = FS_PAYLOAD_MAX;
171		}
172	}
173}
174
175/* Get maximum bandwidth when we schedule at offset slot. */
176static u32 get_max_bw(struct mu3h_sch_bw_info *sch_bw,
177	struct mu3h_sch_ep_info *sch_ep, u32 offset)
178{
179	u32 num_esit;
180	u32 max_bw = 0;
181	int i;
182	int j;
183
184	num_esit = XHCI_MTK_MAX_ESIT / sch_ep->esit;
185	for (i = 0; i < num_esit; i++) {
186		u32 base = offset + i * sch_ep->esit;
187
188		for (j = 0; j < sch_ep->num_budget_microframes; j++) {
189			if (sch_bw->bus_bw[base + j] > max_bw)
190				max_bw = sch_bw->bus_bw[base + j];
 
 
191		}
192	}
193	return max_bw;
194}
195
196static void update_bus_bw(struct mu3h_sch_bw_info *sch_bw,
197	struct mu3h_sch_ep_info *sch_ep, int bw_cost)
198{
199	u32 num_esit;
200	u32 base;
201	int i;
202	int j;
 
203
204	num_esit = XHCI_MTK_MAX_ESIT / sch_ep->esit;
205	for (i = 0; i < num_esit; i++) {
206		base = sch_ep->offset + i * sch_ep->esit;
207		for (j = 0; j < sch_ep->num_budget_microframes; j++)
208			sch_bw->bus_bw[base + j] += bw_cost;
209	}
210}
211
212static int check_sch_bw(struct usb_device *udev,
213	struct mu3h_sch_bw_info *sch_bw, struct mu3h_sch_ep_info *sch_ep)
214{
215	u32 offset;
216	u32 esit;
217	u32 num_budget_microframes;
218	u32 min_bw;
219	u32 min_index;
220	u32 worst_bw;
221	u32 bw_boundary;
 
 
 
 
 
 
 
 
 
 
 
 
222
223	if (sch_ep->esit > XHCI_MTK_MAX_ESIT)
224		sch_ep->esit = XHCI_MTK_MAX_ESIT;
225
226	esit = sch_ep->esit;
227	num_budget_microframes = sch_ep->num_budget_microframes;
 
 
228
229	/*
230	 * Search through all possible schedule microframes.
231	 * and find a microframe where its worst bandwidth is minimum.
232	 */
233	min_bw = ~0;
234	min_index = 0;
235	for (offset = 0; offset < esit; offset++) {
236		if ((offset + num_budget_microframes) > sch_ep->esit)
237			break;
 
 
 
 
 
 
 
 
238
239		/*
240		 * usb_20 spec section11.18:
241		 * must never schedule Start-Split in Y6
242		 */
243		if (is_fs_or_ls(udev->speed) && (offset % 8 == 6))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244			continue;
245
246		worst_bw = get_max_bw(sch_bw, sch_ep, offset);
 
 
 
247		if (min_bw > worst_bw) {
248			min_bw = worst_bw;
249			min_index = offset;
250		}
 
 
 
 
 
251		if (min_bw == 0)
252			break;
253	}
 
 
 
 
254	sch_ep->offset = min_index;
255
256	bw_boundary = (udev->speed == USB_SPEED_SUPER)
257				? SS_BW_BOUNDARY : HS_BW_BOUNDARY;
258
259	/* check bandwidth */
260	if (min_bw + sch_ep->bw_cost_per_microframe > bw_boundary)
261		return -ERANGE;
 
 
 
262
263	/* update bus bandwidth info */
264	update_bus_bw(sch_bw, sch_ep, sch_ep->bw_cost_per_microframe);
265
266	return 0;
 
 
267}
268
269static bool need_bw_sch(struct usb_host_endpoint *ep,
270	enum usb_device_speed speed, int has_tt)
271{
 
 
272	/* only for periodic endpoints */
273	if (usb_endpoint_xfer_control(&ep->desc)
274		|| usb_endpoint_xfer_bulk(&ep->desc))
275		return false;
276
277	/*
278	 * for LS & FS periodic endpoints which its device is not behind
279	 * a TT are also ignored, root-hub will schedule them directly,
280	 * but need set @bpkts field of endpoint context to 1.
281	 */
282	if (is_fs_or_ls(speed) && !has_tt)
 
 
 
 
283		return false;
284
285	return true;
286}
287
288int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk)
289{
 
290	struct mu3h_sch_bw_info *sch_array;
291	int num_usb_bus;
292	int i;
293
294	/* ss IN and OUT are separated */
295	num_usb_bus = mtk->num_u3_ports * 2 + mtk->num_u2_ports;
296
297	sch_array = kcalloc(num_usb_bus, sizeof(*sch_array), GFP_KERNEL);
298	if (sch_array == NULL)
299		return -ENOMEM;
300
301	for (i = 0; i < num_usb_bus; i++)
302		INIT_LIST_HEAD(&sch_array[i].bw_ep_list);
303
304	mtk->sch_array = sch_array;
305
 
 
 
306	return 0;
307}
308EXPORT_SYMBOL_GPL(xhci_mtk_sch_init);
309
310void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk)
311{
312	kfree(mtk->sch_array);
313}
314EXPORT_SYMBOL_GPL(xhci_mtk_sch_exit);
315
316int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
317		struct usb_host_endpoint *ep)
318{
319	struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
320	struct xhci_hcd *xhci;
321	struct xhci_ep_ctx *ep_ctx;
322	struct xhci_slot_ctx *slot_ctx;
323	struct xhci_virt_device *virt_dev;
324	struct mu3h_sch_bw_info *sch_bw;
325	struct mu3h_sch_ep_info *sch_ep;
326	struct mu3h_sch_bw_info *sch_array;
327	unsigned int ep_index;
328	int bw_index;
329	int ret = 0;
330
331	xhci = hcd_to_xhci(hcd);
332	virt_dev = xhci->devs[udev->slot_id];
333	ep_index = xhci_get_endpoint_index(&ep->desc);
334	slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
335	ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
336	sch_array = mtk->sch_array;
337
338	xhci_dbg(xhci, "%s() type:%d, speed:%d, mpkt:%d, dir:%d, ep:%p\n",
339		__func__, usb_endpoint_type(&ep->desc), udev->speed,
340		GET_MAX_PACKET(usb_endpoint_maxp(&ep->desc)),
341		usb_endpoint_dir_in(&ep->desc), ep);
342
343	if (!need_bw_sch(ep, udev->speed, slot_ctx->tt_info & TT_SLOT)) {
344		/*
345		 * set @bpkts to 1 if it is LS or FS periodic endpoint, and its
346		 * device does not connected through an external HS hub
347		 */
348		if (usb_endpoint_xfer_int(&ep->desc)
349			|| usb_endpoint_xfer_isoc(&ep->desc))
350			ep_ctx->reserved[0] |= cpu_to_le32(EP_BPKTS(1));
351
352		return 0;
353	}
354
355	bw_index = get_bw_index(xhci, udev, ep);
356	sch_bw = &sch_array[bw_index];
357
358	sch_ep = kzalloc(sizeof(struct mu3h_sch_ep_info), GFP_NOIO);
359	if (!sch_ep)
360		return -ENOMEM;
361
362	setup_sch_info(udev, ep_ctx, sch_ep);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
364	ret = check_sch_bw(udev, sch_bw, sch_ep);
365	if (ret) {
366		xhci_err(xhci, "Not enough bandwidth!\n");
367		kfree(sch_ep);
368		return -ENOSPC;
 
 
 
369	}
 
370
371	list_add_tail(&sch_ep->endpoint, &sch_bw->bw_ep_list);
372	sch_ep->ep = ep;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
374	ep_ctx->reserved[0] |= cpu_to_le32(EP_BPKTS(sch_ep->pkts)
375		| EP_BCSCOUNT(sch_ep->cs_count) | EP_BBM(sch_ep->burst_mode));
376	ep_ctx->reserved[1] |= cpu_to_le32(EP_BOFFSET(sch_ep->offset)
377		| EP_BREPEAT(sch_ep->repeat));
 
 
378
379	xhci_dbg(xhci, " PKTS:%x, CSCOUNT:%x, BM:%x, OFFSET:%x, REPEAT:%x\n",
380			sch_ep->pkts, sch_ep->cs_count, sch_ep->burst_mode,
381			sch_ep->offset, sch_ep->repeat);
 
382
383	return 0;
 
 
 
 
384}
385EXPORT_SYMBOL_GPL(xhci_mtk_add_ep_quirk);
386
387void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
388		struct usb_host_endpoint *ep)
389{
390	struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
391	struct xhci_hcd *xhci;
392	struct xhci_slot_ctx *slot_ctx;
393	struct xhci_virt_device *virt_dev;
394	struct mu3h_sch_bw_info *sch_array;
395	struct mu3h_sch_bw_info *sch_bw;
396	struct mu3h_sch_ep_info *sch_ep;
397	int bw_index;
398
399	xhci = hcd_to_xhci(hcd);
400	virt_dev = xhci->devs[udev->slot_id];
401	slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
402	sch_array = mtk->sch_array;
403
404	xhci_dbg(xhci, "%s() type:%d, speed:%d, mpks:%d, dir:%d, ep:%p\n",
405		__func__, usb_endpoint_type(&ep->desc), udev->speed,
406		GET_MAX_PACKET(usb_endpoint_maxp(&ep->desc)),
407		usb_endpoint_dir_in(&ep->desc), ep);
408
409	if (!need_bw_sch(ep, udev->speed, slot_ctx->tt_info & TT_SLOT))
410		return;
411
412	bw_index = get_bw_index(xhci, udev, ep);
413	sch_bw = &sch_array[bw_index];
 
 
414
415	list_for_each_entry(sch_ep, &sch_bw->bw_ep_list, endpoint) {
416		if (sch_ep->ep == ep) {
417			update_bus_bw(sch_bw, sch_ep,
418				-sch_ep->bw_cost_per_microframe);
419			list_del(&sch_ep->endpoint);
420			kfree(sch_ep);
421			break;
422		}
423	}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424}
425EXPORT_SYMBOL_GPL(xhci_mtk_drop_ep_quirk);
v6.2
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright (c) 2015 MediaTek Inc.
  4 * Author:
  5 *  Zhigang.Wei <zhigang.wei@mediatek.com>
  6 *  Chunfeng.Yun <chunfeng.yun@mediatek.com>
 
 
 
 
 
 
 
 
 
 
  7 */
  8
  9#include <linux/kernel.h>
 10#include <linux/module.h>
 11#include <linux/slab.h>
 12
 13#include "xhci.h"
 14#include "xhci-mtk.h"
 15
 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
 22
 23#define DBG_BUF_EN	64
 24
 25/* schedule error type */
 26#define ESCH_SS_Y6		1001
 27#define ESCH_SS_OVERLAP		1002
 28#define ESCH_CS_OVERFLOW	1003
 29#define ESCH_BW_OVERFLOW	1004
 30#define ESCH_FIXME		1005
 31
 32/* mtk scheduler bitmasks */
 33#define EP_BPKTS(p)	((p) & 0x7f)
 34#define EP_BCSCOUNT(p)	(((p) & 0x7) << 8)
 35#define EP_BBM(p)	((p) << 11)
 36#define EP_BOFFSET(p)	((p) & 0x3fff)
 37#define EP_BREPEAT(p)	(((p) & 0x7fff) << 16)
 38
 39static char *sch_error_string(int err_num)
 40{
 41	switch (err_num) {
 42	case ESCH_SS_Y6:
 43		return "Can't schedule Start-Split in Y6";
 44	case ESCH_SS_OVERLAP:
 45		return "Can't find a suitable Start-Split location";
 46	case ESCH_CS_OVERFLOW:
 47		return "The last Complete-Split is greater than 7";
 48	case ESCH_BW_OVERFLOW:
 49		return "Bandwidth exceeds the maximum limit";
 50	case ESCH_FIXME:
 51		return "FIXME, to be resolved";
 52	default:
 53		return "Unknown";
 54	}
 55}
 56
 57static int is_fs_or_ls(enum usb_device_speed speed)
 58{
 59	return speed == USB_SPEED_FULL || speed == USB_SPEED_LOW;
 60}
 61
 62static const char *
 63decode_ep(struct usb_host_endpoint *ep, enum usb_device_speed speed)
 64{
 65	static char buf[DBG_BUF_EN];
 66	struct usb_endpoint_descriptor *epd = &ep->desc;
 67	unsigned int interval;
 68	const char *unit;
 69
 70	interval = usb_decode_interval(epd, speed);
 71	if (interval % 1000) {
 72		unit = "us";
 73	} else {
 74		unit = "ms";
 75		interval /= 1000;
 76	}
 77
 78	snprintf(buf, DBG_BUF_EN, "%s ep%d%s %s, mpkt:%d, interval:%d/%d%s",
 79		 usb_speed_string(speed), usb_endpoint_num(epd),
 80		 usb_endpoint_dir_in(epd) ? "in" : "out",
 81		 usb_ep_type_string(usb_endpoint_type(epd)),
 82		 usb_endpoint_maxp(epd), epd->bInterval, interval, unit);
 83
 84	return buf;
 85}
 86
 87static u32 get_bw_boundary(enum usb_device_speed speed)
 88{
 89	u32 boundary;
 90
 91	switch (speed) {
 92	case USB_SPEED_SUPER_PLUS:
 93		boundary = SSP_BW_BOUNDARY;
 94		break;
 95	case USB_SPEED_SUPER:
 96		boundary = SS_BW_BOUNDARY;
 97		break;
 98	default:
 99		boundary = HS_BW_BOUNDARY;
100		break;
101	}
102
103	return boundary;
104}
105
106/*
107* get the bandwidth domain which @ep belongs to.
108*
109* the bandwidth domain array is saved to @sch_array of struct xhci_hcd_mtk,
110* each HS root port is treated as a single bandwidth domain,
111* but each SS root port is treated as two bandwidth domains, one for IN eps,
112* one for OUT eps.
113* @real_port value is defined as follow according to xHCI spec:
114* 1 for SSport0, ..., N+1 for SSportN, N+2 for HSport0, N+3 for HSport1, etc
115* so the bandwidth domain array is organized as follow for simplification:
116* SSport0-OUT, SSport0-IN, ..., SSportX-OUT, SSportX-IN, HSport0, ..., HSportY
117*/
118static struct mu3h_sch_bw_info *
119get_bw_info(struct xhci_hcd_mtk *mtk, struct usb_device *udev,
120	    struct usb_host_endpoint *ep)
121{
122	struct xhci_hcd *xhci = hcd_to_xhci(mtk->hcd);
123	struct xhci_virt_device *virt_dev;
124	int bw_index;
125
126	virt_dev = xhci->devs[udev->slot_id];
127	if (!virt_dev->real_port) {
128		WARN_ONCE(1, "%s invalid real_port\n", dev_name(&udev->dev));
129		return NULL;
130	}
131
132	if (udev->speed >= USB_SPEED_SUPER) {
133		if (usb_endpoint_dir_out(&ep->desc))
134			bw_index = (virt_dev->real_port - 1) * 2;
135		else
136			bw_index = (virt_dev->real_port - 1) * 2 + 1;
137	} else {
138		/* add one more for each SS port */
139		bw_index = virt_dev->real_port + xhci->usb3_rhub.num_ports - 1;
140	}
141
142	return &mtk->sch_array[bw_index];
143}
144
145static u32 get_esit(struct xhci_ep_ctx *ep_ctx)
146{
147	u32 esit;
148
149	esit = 1 << CTX_TO_EP_INTERVAL(le32_to_cpu(ep_ctx->ep_info));
150	if (esit > XHCI_MTK_MAX_ESIT)
151		esit = XHCI_MTK_MAX_ESIT;
152
153	return esit;
154}
155
156static struct mu3h_sch_tt *find_tt(struct usb_device *udev)
157{
158	struct usb_tt *utt = udev->tt;
159	struct mu3h_sch_tt *tt, **tt_index, **ptt;
160	bool allocated_index = false;
161
162	if (!utt)
163		return NULL;	/* Not below a TT */
164
165	/*
166	 * Find/create our data structure.
167	 * For hubs with a single TT, we get it directly.
168	 * For hubs with multiple TTs, there's an extra level of pointers.
169	 */
170	tt_index = NULL;
171	if (utt->multi) {
172		tt_index = utt->hcpriv;
173		if (!tt_index) {	/* Create the index array */
174			tt_index = kcalloc(utt->hub->maxchild,
175					sizeof(*tt_index), GFP_KERNEL);
176			if (!tt_index)
177				return ERR_PTR(-ENOMEM);
178			utt->hcpriv = tt_index;
179			allocated_index = true;
180		}
181		ptt = &tt_index[udev->ttport - 1];
182	} else {
183		ptt = (struct mu3h_sch_tt **) &utt->hcpriv;
184	}
185
186	tt = *ptt;
187	if (!tt) {	/* Create the mu3h_sch_tt */
188		tt = kzalloc(sizeof(*tt), GFP_KERNEL);
189		if (!tt) {
190			if (allocated_index) {
191				utt->hcpriv = NULL;
192				kfree(tt_index);
193			}
194			return ERR_PTR(-ENOMEM);
195		}
196		INIT_LIST_HEAD(&tt->ep_list);
197		*ptt = tt;
198	}
199
200	return tt;
201}
202
203/* Release the TT above udev, if it's not in use */
204static void drop_tt(struct usb_device *udev)
205{
206	struct usb_tt *utt = udev->tt;
207	struct mu3h_sch_tt *tt, **tt_index, **ptt;
208	int i, cnt;
209
210	if (!utt || !utt->hcpriv)
211		return;		/* Not below a TT, or never allocated */
212
213	cnt = 0;
214	if (utt->multi) {
215		tt_index = utt->hcpriv;
216		ptt = &tt_index[udev->ttport - 1];
217		/*  How many entries are left in tt_index? */
218		for (i = 0; i < utt->hub->maxchild; ++i)
219			cnt += !!tt_index[i];
220	} else {
221		tt_index = NULL;
222		ptt = (struct mu3h_sch_tt **)&utt->hcpriv;
223	}
224
225	tt = *ptt;
226	if (!tt || !list_empty(&tt->ep_list))
227		return;		/* never allocated , or still in use*/
228
229	*ptt = NULL;
230	kfree(tt);
231
232	if (cnt == 1) {
233		utt->hcpriv = NULL;
234		kfree(tt_index);
235	}
236}
237
238static struct mu3h_sch_ep_info *
239create_sch_ep(struct xhci_hcd_mtk *mtk, struct usb_device *udev,
240	      struct usb_host_endpoint *ep)
241{
242	struct mu3h_sch_ep_info *sch_ep;
243	struct mu3h_sch_bw_info *bw_info;
244	struct mu3h_sch_tt *tt = NULL;
245
246	bw_info = get_bw_info(mtk, udev, ep);
247	if (!bw_info)
248		return ERR_PTR(-ENODEV);
249
250	sch_ep = kzalloc(sizeof(*sch_ep), GFP_KERNEL);
251	if (!sch_ep)
252		return ERR_PTR(-ENOMEM);
253
254	if (is_fs_or_ls(udev->speed)) {
255		tt = find_tt(udev);
256		if (IS_ERR(tt)) {
257			kfree(sch_ep);
258			return ERR_PTR(-ENOMEM);
259		}
260	}
261
262	sch_ep->bw_info = bw_info;
263	sch_ep->sch_tt = tt;
264	sch_ep->ep = ep;
265	sch_ep->speed = udev->speed;
266	INIT_LIST_HEAD(&sch_ep->endpoint);
267	INIT_LIST_HEAD(&sch_ep->tt_endpoint);
268	INIT_HLIST_NODE(&sch_ep->hentry);
269
270	return sch_ep;
271}
272
273static void setup_sch_info(struct xhci_ep_ctx *ep_ctx,
274			   struct mu3h_sch_ep_info *sch_ep)
275{
276	u32 ep_type;
277	u32 maxpkt;
 
278	u32 max_burst;
279	u32 mult;
280	u32 esit_pkts;
281	u32 max_esit_payload;
282
283	ep_type = CTX_TO_EP_TYPE(le32_to_cpu(ep_ctx->ep_info2));
284	maxpkt = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2));
 
285	max_burst = CTX_TO_MAX_BURST(le32_to_cpu(ep_ctx->ep_info2));
286	mult = CTX_TO_EP_MULT(le32_to_cpu(ep_ctx->ep_info));
287	max_esit_payload =
288		(CTX_TO_MAX_ESIT_PAYLOAD_HI(
289			le32_to_cpu(ep_ctx->ep_info)) << 16) |
290		 CTX_TO_MAX_ESIT_PAYLOAD(le32_to_cpu(ep_ctx->tx_info));
291
292	sch_ep->esit = get_esit(ep_ctx);
293	sch_ep->num_esit = XHCI_MTK_MAX_ESIT / sch_ep->esit;
294	sch_ep->ep_type = ep_type;
295	sch_ep->maxpkt = maxpkt;
296	sch_ep->offset = 0;
297	sch_ep->burst_mode = 0;
298	sch_ep->repeat = 0;
299
300	if (sch_ep->speed == USB_SPEED_HIGH) {
301		sch_ep->cs_count = 0;
302
303		/*
304		 * usb_20 spec section5.9
305		 * a single microframe is enough for HS synchromous endpoints
306		 * in a interval
307		 */
308		sch_ep->num_budget_microframes = 1;
 
309
310		/*
311		 * xHCI spec section6.2.3.4
312		 * @max_burst is the number of additional transactions
313		 * opportunities per microframe
314		 */
315		sch_ep->pkts = max_burst + 1;
316		sch_ep->bw_cost_per_microframe = maxpkt * sch_ep->pkts;
317	} else if (sch_ep->speed >= USB_SPEED_SUPER) {
318		/* usb3_r1 spec section4.4.7 & 4.4.8 */
319		sch_ep->cs_count = 0;
320		sch_ep->burst_mode = 1;
321		/*
322		 * some device's (d)wBytesPerInterval is set as 0,
323		 * then max_esit_payload is 0, so evaluate esit_pkts from
324		 * mult and burst
325		 */
326		esit_pkts = DIV_ROUND_UP(max_esit_payload, maxpkt);
327		if (esit_pkts == 0)
328			esit_pkts = (mult + 1) * (max_burst + 1);
329
330		if (ep_type == INT_IN_EP || ep_type == INT_OUT_EP) {
331			sch_ep->pkts = esit_pkts;
332			sch_ep->num_budget_microframes = 1;
 
333		}
334
335		if (ep_type == ISOC_IN_EP || ep_type == ISOC_OUT_EP) {
336
337			if (sch_ep->esit == 1)
338				sch_ep->pkts = esit_pkts;
339			else if (esit_pkts <= sch_ep->esit)
340				sch_ep->pkts = 1;
341			else
342				sch_ep->pkts = roundup_pow_of_two(esit_pkts)
343					/ sch_ep->esit;
344
345			sch_ep->num_budget_microframes =
346				DIV_ROUND_UP(esit_pkts, sch_ep->pkts);
347
348			sch_ep->repeat = !!(sch_ep->num_budget_microframes > 1);
 
 
 
349		}
350		sch_ep->bw_cost_per_microframe = maxpkt * sch_ep->pkts;
351	} else if (is_fs_or_ls(sch_ep->speed)) {
352		sch_ep->pkts = 1; /* at most one packet for each microframe */
353
354		/*
355		 * num_budget_microframes and cs_count will be updated when
356		 * check TT for INT_OUT_EP, ISOC/INT_IN_EP type
357		 */
358		sch_ep->cs_count = DIV_ROUND_UP(maxpkt, FS_PAYLOAD_MAX);
359		sch_ep->num_budget_microframes = sch_ep->cs_count;
360		sch_ep->bw_cost_per_microframe = min_t(u32, maxpkt, FS_PAYLOAD_MAX);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361	}
362}
363
364/* Get maximum bandwidth when we schedule at offset slot. */
365static u32 get_max_bw(struct mu3h_sch_bw_info *sch_bw,
366	struct mu3h_sch_ep_info *sch_ep, u32 offset)
367{
 
368	u32 max_bw = 0;
369	u32 bw;
370	int i, j, k;
371
372	for (i = 0; i < sch_ep->num_esit; i++) {
 
373		u32 base = offset + i * sch_ep->esit;
374
375		for (j = 0; j < sch_ep->num_budget_microframes; j++) {
376			k = XHCI_MTK_BW_INDEX(base + j);
377			bw = sch_bw->bus_bw[k] + sch_ep->bw_cost_per_microframe;
378			if (bw > max_bw)
379				max_bw = bw;
380		}
381	}
382	return max_bw;
383}
384
385static void update_bus_bw(struct mu3h_sch_bw_info *sch_bw,
386	struct mu3h_sch_ep_info *sch_ep, bool used)
387{
388	int bw_updated;
389	u32 base;
390	int i, j;
391
392	bw_updated = sch_ep->bw_cost_per_microframe * (used ? 1 : -1);
393
394	for (i = 0; i < sch_ep->num_esit; i++) {
 
395		base = sch_ep->offset + i * sch_ep->esit;
396		for (j = 0; j < sch_ep->num_budget_microframes; j++)
397			sch_bw->bus_bw[XHCI_MTK_BW_INDEX(base + j)] += bw_updated;
398	}
399}
400
401static int check_fs_bus_bw(struct mu3h_sch_ep_info *sch_ep, int offset)
 
402{
403	struct mu3h_sch_tt *tt = sch_ep->sch_tt;
404	u32 tmp;
405	int base;
406	int i, j, k;
407
408	for (i = 0; i < sch_ep->num_esit; i++) {
409		base = offset + i * sch_ep->esit;
410
411		/*
412		 * Compared with hs bus, no matter what ep type,
413		 * the hub will always delay one uframe to send data
414		 */
415		for (j = 0; j < sch_ep->num_budget_microframes; j++) {
416			k = XHCI_MTK_BW_INDEX(base + j);
417			tmp = tt->fs_bus_bw[k] + sch_ep->bw_cost_per_microframe;
418			if (tmp > FS_PAYLOAD_MAX)
419				return -ESCH_BW_OVERFLOW;
420		}
421	}
422
423	return 0;
424}
425
426static int check_sch_tt(struct mu3h_sch_ep_info *sch_ep, u32 offset)
427{
428	u32 start_ss, last_ss;
429	u32 start_cs, last_cs;
430
431	if (!sch_ep->sch_tt)
432		return 0;
433
434	start_ss = offset % 8;
435
436	if (sch_ep->ep_type == ISOC_OUT_EP) {
437		last_ss = start_ss + sch_ep->cs_count - 1;
438
439		/*
440		 * usb_20 spec section11.18:
441		 * must never schedule Start-Split in Y6
442		 */
443		if (!(start_ss == 7 || last_ss < 6))
444			return -ESCH_SS_Y6;
445
446	} else {
447		u32 cs_count = DIV_ROUND_UP(sch_ep->maxpkt, FS_PAYLOAD_MAX);
448
449		/*
450		 * usb_20 spec section11.18:
451		 * must never schedule Start-Split in Y6
452		 */
453		if (start_ss == 6)
454			return -ESCH_SS_Y6;
455
456		/* one uframe for ss + one uframe for idle */
457		start_cs = (start_ss + 2) % 8;
458		last_cs = start_cs + cs_count - 1;
459
460		if (last_cs > 7)
461			return -ESCH_CS_OVERFLOW;
462
463		if (cs_count > 7)
464			cs_count = 7; /* HW limit */
465
466		sch_ep->cs_count = cs_count;
467		/* ss, idle are ignored */
468		sch_ep->num_budget_microframes = cs_count;
469
470		/*
471		 * if interval=1, maxp >752, num_budge_micoframe is larger
472		 * than sch_ep->esit, will overstep boundary
473		 */
474		if (sch_ep->num_budget_microframes > sch_ep->esit)
475			sch_ep->num_budget_microframes = sch_ep->esit;
476	}
477
478	return check_fs_bus_bw(sch_ep, offset);
479}
480
481static void update_sch_tt(struct mu3h_sch_ep_info *sch_ep, bool used)
482{
483	struct mu3h_sch_tt *tt = sch_ep->sch_tt;
484	int bw_updated;
485	u32 base;
486	int i, j;
487
488	bw_updated = sch_ep->bw_cost_per_microframe * (used ? 1 : -1);
489
490	for (i = 0; i < sch_ep->num_esit; i++) {
491		base = sch_ep->offset + i * sch_ep->esit;
492
493		for (j = 0; j < sch_ep->num_budget_microframes; j++)
494			tt->fs_bus_bw[XHCI_MTK_BW_INDEX(base + j)] += bw_updated;
495	}
496
497	if (used)
498		list_add_tail(&sch_ep->tt_endpoint, &tt->ep_list);
499	else
500		list_del(&sch_ep->tt_endpoint);
501}
502
503static int load_ep_bw(struct mu3h_sch_bw_info *sch_bw,
504		      struct mu3h_sch_ep_info *sch_ep, bool loaded)
505{
506	if (sch_ep->sch_tt)
507		update_sch_tt(sch_ep, loaded);
508
509	/* update bus bandwidth info */
510	update_bus_bw(sch_bw, sch_ep, loaded);
511	sch_ep->allocated = loaded;
512
513	return 0;
514}
515
516static int check_sch_bw(struct mu3h_sch_ep_info *sch_ep)
517{
518	struct mu3h_sch_bw_info *sch_bw = sch_ep->bw_info;
519	const u32 bw_boundary = get_bw_boundary(sch_ep->speed);
520	u32 offset;
521	u32 worst_bw;
522	u32 min_bw = ~0;
523	int min_index = -1;
524	int ret = 0;
525
526	/*
527	 * Search through all possible schedule microframes.
528	 * and find a microframe where its worst bandwidth is minimum.
529	 */
530	for (offset = 0; offset < sch_ep->esit; offset++) {
531		ret = check_sch_tt(sch_ep, offset);
532		if (ret)
533			continue;
534
535		worst_bw = get_max_bw(sch_bw, sch_ep, offset);
536		if (worst_bw > bw_boundary)
537			continue;
538
539		if (min_bw > worst_bw) {
540			min_bw = worst_bw;
541			min_index = offset;
542		}
543
544		/* use first-fit for LS/FS */
545		if (sch_ep->sch_tt && min_index >= 0)
546			break;
547
548		if (min_bw == 0)
549			break;
550	}
551
552	if (min_index < 0)
553		return ret ? ret : -ESCH_BW_OVERFLOW;
554
555	sch_ep->offset = min_index;
556
557	return load_ep_bw(sch_bw, sch_ep, true);
558}
559
560static void destroy_sch_ep(struct xhci_hcd_mtk *mtk, struct usb_device *udev,
561			   struct mu3h_sch_ep_info *sch_ep)
562{
563	/* only release ep bw check passed by check_sch_bw() */
564	if (sch_ep->allocated)
565		load_ep_bw(sch_ep->bw_info, sch_ep, false);
566
567	if (sch_ep->sch_tt)
568		drop_tt(udev);
569
570	list_del(&sch_ep->endpoint);
571	hlist_del(&sch_ep->hentry);
572	kfree(sch_ep);
573}
574
575static bool need_bw_sch(struct usb_device *udev,
576			struct usb_host_endpoint *ep)
577{
578	bool has_tt = udev->tt && udev->tt->hub->parent;
579
580	/* only for periodic endpoints */
581	if (usb_endpoint_xfer_control(&ep->desc)
582		|| usb_endpoint_xfer_bulk(&ep->desc))
583		return false;
584
585	/*
586	 * for LS & FS periodic endpoints which its device is not behind
587	 * a TT are also ignored, root-hub will schedule them directly,
588	 * but need set @bpkts field of endpoint context to 1.
589	 */
590	if (is_fs_or_ls(udev->speed) && !has_tt)
591		return false;
592
593	/* skip endpoint with zero maxpkt */
594	if (usb_endpoint_maxp(&ep->desc) == 0)
595		return false;
596
597	return true;
598}
599
600int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk)
601{
602	struct xhci_hcd *xhci = hcd_to_xhci(mtk->hcd);
603	struct mu3h_sch_bw_info *sch_array;
604	int num_usb_bus;
 
605
606	/* ss IN and OUT are separated */
607	num_usb_bus = xhci->usb3_rhub.num_ports * 2 + xhci->usb2_rhub.num_ports;
608
609	sch_array = kcalloc(num_usb_bus, sizeof(*sch_array), GFP_KERNEL);
610	if (sch_array == NULL)
611		return -ENOMEM;
612
 
 
 
613	mtk->sch_array = sch_array;
614
615	INIT_LIST_HEAD(&mtk->bw_ep_chk_list);
616	hash_init(mtk->sch_ep_hash);
617
618	return 0;
619}
 
620
621void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk)
622{
623	kfree(mtk->sch_array);
624}
 
625
626static int add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
627			struct usb_host_endpoint *ep)
628{
629	struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
630	struct xhci_hcd *xhci = hcd_to_xhci(hcd);
631	struct xhci_ep_ctx *ep_ctx;
 
632	struct xhci_virt_device *virt_dev;
 
633	struct mu3h_sch_ep_info *sch_ep;
 
634	unsigned int ep_index;
 
 
635
 
636	virt_dev = xhci->devs[udev->slot_id];
637	ep_index = xhci_get_endpoint_index(&ep->desc);
 
638	ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
 
 
 
 
 
 
639
640	if (!need_bw_sch(udev, ep)) {
641		/*
642		 * set @bpkts to 1 if it is LS or FS periodic endpoint, and its
643		 * device does not connected through an external HS hub
644		 */
645		if (usb_endpoint_xfer_int(&ep->desc)
646			|| usb_endpoint_xfer_isoc(&ep->desc))
647			ep_ctx->reserved[0] = cpu_to_le32(EP_BPKTS(1));
648
649		return 0;
650	}
651
652	xhci_dbg(xhci, "%s %s\n", __func__, decode_ep(ep, udev->speed));
 
653
654	sch_ep = create_sch_ep(mtk, udev, ep);
655	if (IS_ERR_OR_NULL(sch_ep))
656		return -ENOMEM;
657
658	setup_sch_info(ep_ctx, sch_ep);
659
660	list_add_tail(&sch_ep->endpoint, &mtk->bw_ep_chk_list);
661	hash_add(mtk->sch_ep_hash, &sch_ep->hentry, (unsigned long)ep);
662
663	return 0;
664}
665
666static void drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev,
667			  struct usb_host_endpoint *ep)
668{
669	struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
670	struct xhci_hcd *xhci = hcd_to_xhci(hcd);
671	struct mu3h_sch_ep_info *sch_ep;
672	struct hlist_node *hn;
673
674	if (!need_bw_sch(udev, ep))
675		return;
676
677	xhci_dbg(xhci, "%s %s\n", __func__, decode_ep(ep, udev->speed));
678
679	hash_for_each_possible_safe(mtk->sch_ep_hash, sch_ep,
680				    hn, hentry, (unsigned long)ep) {
681		if (sch_ep->ep == ep) {
682			destroy_sch_ep(mtk, udev, sch_ep);
683			break;
684		}
685	}
686}
687
688int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
689{
690	struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
691	struct xhci_hcd *xhci = hcd_to_xhci(hcd);
692	struct xhci_virt_device *virt_dev = xhci->devs[udev->slot_id];
693	struct mu3h_sch_ep_info *sch_ep;
694	int ret;
695
696	xhci_dbg(xhci, "%s() udev %s\n", __func__, dev_name(&udev->dev));
697
698	list_for_each_entry(sch_ep, &mtk->bw_ep_chk_list, endpoint) {
699		struct xhci_ep_ctx *ep_ctx;
700		struct usb_host_endpoint *ep = sch_ep->ep;
701		unsigned int ep_index = xhci_get_endpoint_index(&ep->desc);
702
703		ret = check_sch_bw(sch_ep);
704		if (ret) {
705			xhci_err(xhci, "Not enough bandwidth! (%s)\n",
706				 sch_error_string(-ret));
707			return -ENOSPC;
708		}
709
710		ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
711		ep_ctx->reserved[0] = cpu_to_le32(EP_BPKTS(sch_ep->pkts)
712			| EP_BCSCOUNT(sch_ep->cs_count)
713			| EP_BBM(sch_ep->burst_mode));
714		ep_ctx->reserved[1] = cpu_to_le32(EP_BOFFSET(sch_ep->offset)
715			| EP_BREPEAT(sch_ep->repeat));
716
717		xhci_dbg(xhci, " PKTS:%x, CSCOUNT:%x, BM:%x, OFFSET:%x, REPEAT:%x\n",
718			sch_ep->pkts, sch_ep->cs_count, sch_ep->burst_mode,
719			sch_ep->offset, sch_ep->repeat);
720	}
721
722	ret = xhci_check_bandwidth(hcd, udev);
723	if (!ret)
724		list_del_init(&mtk->bw_ep_chk_list);
725
726	return ret;
727}
 
728
729void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
 
730{
731	struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
732	struct xhci_hcd *xhci = hcd_to_xhci(hcd);
733	struct mu3h_sch_ep_info *sch_ep, *tmp;
 
 
 
 
 
734
735	xhci_dbg(xhci, "%s() udev %s\n", __func__, dev_name(&udev->dev));
 
 
 
736
737	list_for_each_entry_safe(sch_ep, tmp, &mtk->bw_ep_chk_list, endpoint)
738		destroy_sch_ep(mtk, udev, sch_ep);
 
 
739
740	xhci_reset_bandwidth(hcd, udev);
741}
742
743int xhci_mtk_add_ep(struct usb_hcd *hcd, struct usb_device *udev,
744		    struct usb_host_endpoint *ep)
745{
746	int ret;
747
748	ret = xhci_add_endpoint(hcd, udev, ep);
749	if (ret)
750		return ret;
751
752	if (ep->hcpriv)
753		ret = add_ep_quirk(hcd, udev, ep);
754
755	return ret;
756}
757
758int xhci_mtk_drop_ep(struct usb_hcd *hcd, struct usb_device *udev,
759		     struct usb_host_endpoint *ep)
760{
761	int ret;
762
763	ret = xhci_drop_endpoint(hcd, udev, ep);
764	if (ret)
765		return ret;
766
767	/* needn't check @ep->hcpriv, xhci_endpoint_disable set it NULL */
768	drop_ep_quirk(hcd, udev, ep);
769
770	return 0;
771}