All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chunfeng Yun <chunfeng.yun@mediatek.com>
To: Ikjoon Jang <ikjn@chromium.org>
Cc: Zhanyong Wang <zhanyong.wang@mediatek.com>,
	Mathias Nyman <mathias.nyman@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Tianping Fang <tianping.fang@mediatek.com>,
	linux-mediatek@lists.infradead.org,
	Matthias Brugger <matthias.bgg@gmail.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v6] usb: xhci-mtk: fix unreleased bandwidth data
Date: Fri, 29 Jan 2021 17:18:23 +0800	[thread overview]
Message-ID: <1611911903.3905.25.camel@mhfsdcap03> (raw)
In-Reply-To: <20210113180444.v6.1.Id0d31b5f3ddf5e734d2ab11161ac5821921b1e1e@changeid>

Hi Ikjoon,

On Wed, 2021-01-13 at 18:05 +0800, Ikjoon Jang wrote:
> xhci-mtk needs XHCI_MTK_HOST quirk functions in add_endpoint() and
> drop_endpoint() to handle its own sw bandwidth management.
> 
> It stores bandwidth data into an internal table every time
> add_endpoint() is called, and drops those in drop_endpoint().
> But when bandwidth allocation fails at one endpoint, all earlier
> allocation from the same interface could still remain at the table.
> 
> This patch moves bandwidth management codes to check_bandwidth() and
> reset_bandwidth() path. To do so, this patch also adds those functions
> to xhci_driver_overrides and lets mtk-xhci to release all failed
> endpoints in reset_bandwidth() path.
> 
> Fixes: 08e469de87a2 ("usb: xhci-mtk: supports bandwidth scheduling with multi-TT")
> Signed-off-by: Ikjoon Jang <ikjn@chromium.org>
> 
> ---
> 
> Changes in v6:
> - use xhci overrides instead of quirk functions for
>   {check|reset}_bandwidth().
> 
> Changes in v5:
> - Fix a wrong commit id in Fixes tag
> 
> Changes in v4:
> - bugfix in v3, check_bandwidth() return uninitialized value
>   when no new endpoints were added.
> - change Fixes tag to keep dependency
> 
> Changes in v3:
> - drop unrelated code cleanups
> - change Fixes tag to keep dependency
> 
> Changes in v2:
> - fix a 0-day warning from unused variable
> - split one big patch into three patches
> - fix wrong offset in mediatek hw flags
> 
>  drivers/usb/host/xhci-mtk-sch.c | 123 ++++++++++++++++++++++----------
>  drivers/usb/host/xhci-mtk.c     |   2 +
>  drivers/usb/host/xhci-mtk.h     |  13 ++++
>  drivers/usb/host/xhci.c         |   8 ++-
>  drivers/usb/host/xhci.h         |   4 ++
>  5 files changed, 111 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-mtk-sch.c
> index 45c54d56ecbd..a313e75ff1c6 100644
> --- a/drivers/usb/host/xhci-mtk-sch.c
> +++ b/drivers/usb/host/xhci-mtk-sch.c
> @@ -200,6 +200,7 @@ static struct mu3h_sch_ep_info *create_sch_ep(struct usb_device *udev,
>  [...]
> +
> +int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
> +{
> +	struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
> +	struct xhci_hcd *xhci = hcd_to_xhci(hcd);
> +	struct xhci_virt_device *virt_dev = xhci->devs[udev->slot_id];
> +	struct mu3h_sch_bw_info *sch_bw;
> +	struct mu3h_sch_ep_info *sch_ep, *tmp;
> +	int bw_index, ret;
> +
> +	dev_dbg(&udev->dev, "%s\n", __func__);
> +
> +	list_for_each_entry(sch_ep, &mtk->bw_ep_list_new, endpoint) {
> +		bw_index = get_bw_index(xhci, udev, sch_ep->ep);
> +		sch_bw = &mtk->sch_array[bw_index];
> +
> +		ret = check_sch_bw(udev, sch_bw, sch_ep);
> +		if (ret) {
> +			xhci_err(xhci, "Not enough bandwidth!\n");
> +			return -ENOSPC;
> +		}
> +	}
> +
> +	list_for_each_entry_safe(sch_ep, tmp, &mtk->bw_ep_list_new, endpoint) {
> +		struct xhci_ep_ctx *ep_ctx;
> +		struct usb_host_endpoint *ep = sch_ep->ep;
> +		unsigned int ep_index = xhci_get_endpoint_index(&ep->desc);
> +
> +		bw_index = get_bw_index(xhci, udev, ep);
> +		sch_bw = &mtk->sch_array[bw_index];
> +
> +		list_move_tail(&sch_ep->endpoint, &sch_bw->bw_ep_list);
> +
> +		ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
> +		ep_ctx->reserved[0] |= cpu_to_le32(EP_BPKTS(sch_ep->pkts)
> +			| EP_BCSCOUNT(sch_ep->cs_count)
> +			| EP_BBM(sch_ep->burst_mode));
> +		ep_ctx->reserved[1] |= cpu_to_le32(EP_BOFFSET(sch_ep->offset)
> +			| EP_BREPEAT(sch_ep->repeat));
> +
> +		xhci_dbg(xhci, " PKTS:%x, CSCOUNT:%x, BM:%x, OFFSET:%x, REPEAT:%x\n",
> +			sch_ep->pkts, sch_ep->cs_count, sch_ep->burst_mode,
> +			sch_ep->offset, sch_ep->repeat);
> +	}
> +
> +	return xhci_check_bandwidth(hcd, udev);
> +}
> +EXPORT_SYMBOL_GPL(xhci_mtk_check_bandwidth);
> +
> +void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
> +{
> +	struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
> +	struct mu3h_sch_ep_info *sch_ep, *tmp;
> +
> +	dev_dbg(&udev->dev, "%s\n", __func__);
> +
> +	list_for_each_entry_safe(sch_ep, tmp, &mtk->bw_ep_list_new, endpoint) {
> +		xhci_mtk_drop_ep(mtk, udev, sch_ep);
This need skip endpoint not allocated bandwidth; e.g.
If add 3 eps, the second on is checked fail, only need drop first ep,
and skip second & third ones.
I'll send out a v7 patch, thanks

> +	}
> +
> +	xhci_reset_bandwidth(hcd, udev);
> +}
> +EXPORT_SYMBOL_GPL(xhci_mtk_reset_bandwidth);
[...]
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

WARNING: multiple messages have this Message-ID (diff)
From: Chunfeng Yun <chunfeng.yun@mediatek.com>
To: Ikjoon Jang <ikjn@chromium.org>
Cc: Zhanyong Wang <zhanyong.wang@mediatek.com>,
	Mathias Nyman <mathias.nyman@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Tianping Fang <tianping.fang@mediatek.com>,
	linux-mediatek@lists.infradead.org,
	Matthias Brugger <matthias.bgg@gmail.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v6] usb: xhci-mtk: fix unreleased bandwidth data
Date: Fri, 29 Jan 2021 17:18:23 +0800	[thread overview]
Message-ID: <1611911903.3905.25.camel@mhfsdcap03> (raw)
In-Reply-To: <20210113180444.v6.1.Id0d31b5f3ddf5e734d2ab11161ac5821921b1e1e@changeid>

Hi Ikjoon,

On Wed, 2021-01-13 at 18:05 +0800, Ikjoon Jang wrote:
> xhci-mtk needs XHCI_MTK_HOST quirk functions in add_endpoint() and
> drop_endpoint() to handle its own sw bandwidth management.
> 
> It stores bandwidth data into an internal table every time
> add_endpoint() is called, and drops those in drop_endpoint().
> But when bandwidth allocation fails at one endpoint, all earlier
> allocation from the same interface could still remain at the table.
> 
> This patch moves bandwidth management codes to check_bandwidth() and
> reset_bandwidth() path. To do so, this patch also adds those functions
> to xhci_driver_overrides and lets mtk-xhci to release all failed
> endpoints in reset_bandwidth() path.
> 
> Fixes: 08e469de87a2 ("usb: xhci-mtk: supports bandwidth scheduling with multi-TT")
> Signed-off-by: Ikjoon Jang <ikjn@chromium.org>
> 
> ---
> 
> Changes in v6:
> - use xhci overrides instead of quirk functions for
>   {check|reset}_bandwidth().
> 
> Changes in v5:
> - Fix a wrong commit id in Fixes tag
> 
> Changes in v4:
> - bugfix in v3, check_bandwidth() return uninitialized value
>   when no new endpoints were added.
> - change Fixes tag to keep dependency
> 
> Changes in v3:
> - drop unrelated code cleanups
> - change Fixes tag to keep dependency
> 
> Changes in v2:
> - fix a 0-day warning from unused variable
> - split one big patch into three patches
> - fix wrong offset in mediatek hw flags
> 
>  drivers/usb/host/xhci-mtk-sch.c | 123 ++++++++++++++++++++++----------
>  drivers/usb/host/xhci-mtk.c     |   2 +
>  drivers/usb/host/xhci-mtk.h     |  13 ++++
>  drivers/usb/host/xhci.c         |   8 ++-
>  drivers/usb/host/xhci.h         |   4 ++
>  5 files changed, 111 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-mtk-sch.c
> index 45c54d56ecbd..a313e75ff1c6 100644
> --- a/drivers/usb/host/xhci-mtk-sch.c
> +++ b/drivers/usb/host/xhci-mtk-sch.c
> @@ -200,6 +200,7 @@ static struct mu3h_sch_ep_info *create_sch_ep(struct usb_device *udev,
>  [...]
> +
> +int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
> +{
> +	struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
> +	struct xhci_hcd *xhci = hcd_to_xhci(hcd);
> +	struct xhci_virt_device *virt_dev = xhci->devs[udev->slot_id];
> +	struct mu3h_sch_bw_info *sch_bw;
> +	struct mu3h_sch_ep_info *sch_ep, *tmp;
> +	int bw_index, ret;
> +
> +	dev_dbg(&udev->dev, "%s\n", __func__);
> +
> +	list_for_each_entry(sch_ep, &mtk->bw_ep_list_new, endpoint) {
> +		bw_index = get_bw_index(xhci, udev, sch_ep->ep);
> +		sch_bw = &mtk->sch_array[bw_index];
> +
> +		ret = check_sch_bw(udev, sch_bw, sch_ep);
> +		if (ret) {
> +			xhci_err(xhci, "Not enough bandwidth!\n");
> +			return -ENOSPC;
> +		}
> +	}
> +
> +	list_for_each_entry_safe(sch_ep, tmp, &mtk->bw_ep_list_new, endpoint) {
> +		struct xhci_ep_ctx *ep_ctx;
> +		struct usb_host_endpoint *ep = sch_ep->ep;
> +		unsigned int ep_index = xhci_get_endpoint_index(&ep->desc);
> +
> +		bw_index = get_bw_index(xhci, udev, ep);
> +		sch_bw = &mtk->sch_array[bw_index];
> +
> +		list_move_tail(&sch_ep->endpoint, &sch_bw->bw_ep_list);
> +
> +		ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
> +		ep_ctx->reserved[0] |= cpu_to_le32(EP_BPKTS(sch_ep->pkts)
> +			| EP_BCSCOUNT(sch_ep->cs_count)
> +			| EP_BBM(sch_ep->burst_mode));
> +		ep_ctx->reserved[1] |= cpu_to_le32(EP_BOFFSET(sch_ep->offset)
> +			| EP_BREPEAT(sch_ep->repeat));
> +
> +		xhci_dbg(xhci, " PKTS:%x, CSCOUNT:%x, BM:%x, OFFSET:%x, REPEAT:%x\n",
> +			sch_ep->pkts, sch_ep->cs_count, sch_ep->burst_mode,
> +			sch_ep->offset, sch_ep->repeat);
> +	}
> +
> +	return xhci_check_bandwidth(hcd, udev);
> +}
> +EXPORT_SYMBOL_GPL(xhci_mtk_check_bandwidth);
> +
> +void xhci_mtk_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
> +{
> +	struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
> +	struct mu3h_sch_ep_info *sch_ep, *tmp;
> +
> +	dev_dbg(&udev->dev, "%s\n", __func__);
> +
> +	list_for_each_entry_safe(sch_ep, tmp, &mtk->bw_ep_list_new, endpoint) {
> +		xhci_mtk_drop_ep(mtk, udev, sch_ep);
This need skip endpoint not allocated bandwidth; e.g.
If add 3 eps, the second on is checked fail, only need drop first ep,
and skip second & third ones.
I'll send out a v7 patch, thanks

> +	}
> +
> +	xhci_reset_bandwidth(hcd, udev);
> +}
> +EXPORT_SYMBOL_GPL(xhci_mtk_reset_bandwidth);
[...]
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2021-01-29  9:38 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-13 10:05 [PATCH v6] usb: xhci-mtk: fix unreleased bandwidth data Ikjoon Jang
2021-01-13 10:05 ` Ikjoon Jang
2021-01-13 10:05 ` Ikjoon Jang
2021-01-26  6:02 ` Chunfeng Yun
2021-01-26  6:02   ` Chunfeng Yun
2021-01-26  6:02   ` Chunfeng Yun
2021-01-26 14:12   ` Greg Kroah-Hartman
2021-01-26 14:12     ` Greg Kroah-Hartman
2021-01-26 14:12     ` Greg Kroah-Hartman
2021-01-27  1:34     ` Chunfeng Yun
2021-01-27  1:34       ` Chunfeng Yun
2021-01-27  1:34       ` Chunfeng Yun
2021-01-26 14:13 ` Greg Kroah-Hartman
2021-01-26 14:13   ` Greg Kroah-Hartman
2021-01-26 14:13   ` Greg Kroah-Hartman
2021-01-26 14:27   ` Mathias Nyman
2021-01-26 14:27     ` Mathias Nyman
2021-01-26 14:27     ` Mathias Nyman
2021-01-27  2:14     ` Chunfeng Yun
2021-01-27  2:14       ` Chunfeng Yun
2021-01-27  2:14       ` Chunfeng Yun
2021-01-29  9:18 ` Chunfeng Yun [this message]
2021-01-29  9:18   ` Chunfeng Yun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1611911903.3905.25.camel@mhfsdcap03 \
    --to=chunfeng.yun@mediatek.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=ikjn@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=matthias.bgg@gmail.com \
    --cc=tianping.fang@mediatek.com \
    --cc=zhanyong.wang@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.