Re: [PATCH v6] usb: xhci-mtk: fix unreleased bandwidth data

2021-01-26 Thread Chunfeng Yun
On Tue, 2021-01-26 at 16:27 +0200, Mathias Nyman wrote:
> On 26.1.2021 16.13, Greg Kroah-Hartman wrote:
> > On Wed, Jan 13, 2021 at 06:05:11PM +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 
> > 
> > Mathias, any objection to me taking this patch, or do you have others
> > being queued up for 5.11-final?
> > 
> 
> No objections, haven't tried it out but it looks good to me.
> 
> If I finish some additional small fix for 5.11-final I can make it on top of 
> this
Please give me some time to test this patch, thank you

> 
> -Mathias 



Re: [PATCH v6] usb: xhci-mtk: fix unreleased bandwidth data

2021-01-26 Thread Chunfeng Yun
On Tue, 2021-01-26 at 15:12 +0100, Greg Kroah-Hartman wrote:
> On Tue, Jan 26, 2021 at 02:02:00PM +0800, Chunfeng Yun wrote:
> > Hi Ikjoon,
> > 
> > Can I put this patch into my patch series about bandwidth scheduler?
> > the series also include "[RFC PATCH v3 1/5] usb: xhci-mtk: improve
> > bandwidth scheduling with multi-TT", put them together will help to fix
> > dependence issue, meanwhile I try to build xhci-mtk-sch.c into
> > xhci-mtk.ko instead of xhci-hcd.ko.
> 
> This should probably be merged now, first, as it fixes an issue that
> showed up in 4.20 so this needs to be backported to older kernels.
> 
> Please rebase your future patches on top of this.
Ok

> 
> thanks,
> 
> greg k-h



Re: [PATCH v6] usb: xhci-mtk: fix unreleased bandwidth data

2021-01-26 Thread Chunfeng Yun
Hi Ikjoon,

Can I put this patch into my patch series about bandwidth scheduler?
the series also include "[RFC PATCH v3 1/5] usb: xhci-mtk: improve
bandwidth scheduling with multi-TT", put them together will help to fix
dependence issue, meanwhile I try to build xhci-mtk-sch.c into
xhci-mtk.ko instead of xhci-hcd.ko.

Thanks a lot


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 
> 
> ---
> 
> 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(-)




Re: [PATCH v6] usb: xhci-mtk: fix unreleased bandwidth data

2021-01-26 Thread Mathias Nyman
On 26.1.2021 16.13, Greg Kroah-Hartman wrote:
> On Wed, Jan 13, 2021 at 06:05:11PM +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 
> 
> Mathias, any objection to me taking this patch, or do you have others
> being queued up for 5.11-final?
> 

No objections, haven't tried it out but it looks good to me.

If I finish some additional small fix for 5.11-final I can make it on top of 
this

-Mathias 


Re: [PATCH v6] usb: xhci-mtk: fix unreleased bandwidth data

2021-01-26 Thread Greg Kroah-Hartman
On Wed, Jan 13, 2021 at 06:05:11PM +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 

Mathias, any objection to me taking this patch, or do you have others
being queued up for 5.11-final?

thanks,

greg k-h


Re: [PATCH v6] usb: xhci-mtk: fix unreleased bandwidth data

2021-01-26 Thread Greg Kroah-Hartman
On Tue, Jan 26, 2021 at 02:02:00PM +0800, Chunfeng Yun wrote:
> Hi Ikjoon,
> 
> Can I put this patch into my patch series about bandwidth scheduler?
> the series also include "[RFC PATCH v3 1/5] usb: xhci-mtk: improve
> bandwidth scheduling with multi-TT", put them together will help to fix
> dependence issue, meanwhile I try to build xhci-mtk-sch.c into
> xhci-mtk.ko instead of xhci-hcd.ko.

This should probably be merged now, first, as it fixes an issue that
showed up in 4.20 so this needs to be backported to older kernels.

Please rebase your future patches on top of this.

thanks,

greg k-h


[PATCH v6] usb: xhci-mtk: fix unreleased bandwidth data

2021-01-13 Thread Ikjoon Jang
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 

---

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,
 
sch_ep->sch_tt = tt;
sch_ep->ep = ep;
+   INIT_LIST_HEAD(&sch_ep->tt_endpoint);
 
return sch_ep;
 }
@@ -583,6 +584,8 @@ int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk)
 
mtk->sch_array = sch_array;
 
+   INIT_LIST_HEAD(&mtk->bw_ep_list_new);
+
return 0;
 }
 EXPORT_SYMBOL_GPL(xhci_mtk_sch_init);
@@ -601,19 +604,14 @@ int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, struct 
usb_device *udev,
struct xhci_ep_ctx *ep_ctx;
struct xhci_slot_ctx *slot_ctx;
struct xhci_virt_device *virt_dev;
-   struct mu3h_sch_bw_info *sch_bw;
struct mu3h_sch_ep_info *sch_ep;
-   struct mu3h_sch_bw_info *sch_array;
unsigned int ep_index;
-   int bw_index;
-   int ret = 0;
 
xhci = hcd_to_xhci(hcd);
virt_dev = xhci->devs[udev->slot_id];
ep_index = xhci_get_endpoint_index(&ep->desc);
slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
-   sch_array = mtk->sch_array;
 
xhci_dbg(xhci, "%s() type:%d, speed:%d, mpkt:%d, dir:%d, ep:%p\n",
__func__, usb_endpoint_type(&ep->desc), udev->speed,
@@ -632,39 +630,34 @@ int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, struct 
usb_device *udev,
return 0;
}
 
-   bw_index = get_bw_index(xhci, udev, ep);
-   sch_bw = &sch_array[bw_index];
-
sch_ep = create_sch_ep(udev, ep, ep_ctx);
if (IS_ERR_OR_NULL(sch_ep))
return -ENOMEM;
 
setup_sch_info(udev, ep_ctx, sch_ep);
 
-   ret = check_sch_bw(udev, sch_bw, sch_ep);
-   if (ret) {
-   xhci_err(xhci, "Not enough bandwidth!\n");
-   if (is_fs_or_ls(udev->speed))
-   drop_tt(udev);
-
-   kfree(sch_ep);
-   return -ENOSPC;
-   }
+   list_add_tail(&sch_ep->endpoint, &mtk->bw_ep_list_new);
 
-   list_add_tail(&sch_ep->endpoint, &sch_bw->bw_ep_list);
+   return 0;
+}
+EXPORT_SYMBOL_GPL(xhci_mtk_add_ep_quirk);
 
-   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));
+static void xhci_mtk_drop_ep(struct xhci_hcd_mtk *mtk, struct usb_device *udev,
+struct mu3h_sch_ep_info *sch_ep)
+{
+   struct xhci_hcd *xhci = hcd_to_xhci(mtk->hcd);
+   int bw_index = get_bw_index(xhci, udev, sch_ep->ep);
+   struct mu3h_sch_bw_info *sch_bw = &mtk->sch_array[bw_index];
 
-   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);
+   update_bus_bw(sch_bw, sch_ep, 0);
+   list_del(&sch_ep->endpoint);
 
-   return 0;
+   if (sch_ep->sch_tt) {
+   list_del(&sch_ep->tt_endpoint);
+   drop_tt(udev);
+   }
+   kfree(sch_ep);
 }
-EXPORT_SYMBOL_