* [PATCH v2 2/3] usb: chipidea: udc: improve dTD link logic
2024-09-20 9:40 [PATCH v2 1/3] usb: chipidea: udc: handle USB Error Interrupt if IOC not set Xu Yang
@ 2024-09-20 9:40 ` Xu Yang
2024-09-25 12:43 ` Peter Chen
2024-09-20 9:40 ` [PATCH v2 3/3] usb: chipidea: udc: improve error recovery for ISO transfer Xu Yang
2024-09-25 12:42 ` [PATCH v2 1/3] usb: chipidea: udc: handle USB Error Interrupt if IOC not set Peter Chen
2 siblings, 1 reply; 7+ messages in thread
From: Xu Yang @ 2024-09-20 9:40 UTC (permalink / raw)
To: peter.chen, gregkh; +Cc: linux-usb, imx, jun.li
Currently, ATDTW semaphore is used to safety link new dTD to dQH. But this
code has a bug when the endpoint is already in error before polling ATDTW
or just met error during polling ATDTW. In that cases, ATDTW will never
turn to 1 and the cpu will busy loop there.
When the endpoint met error, ENDPTSTAT will be cleared by HW. Therefore,
ENDPTSTAT should also be considered during this process. In case of
endpoint error, the current dTD should not be pushed to the head of dQH
since some dTDs may be still not executed. Therefore, the link logic is
also improved accordingly.
Fixes: 26c696c678c4 ("USB: Chipidea: rename struct ci13xxx variables from udc to ci")
Cc: stable@vger.kernel.org
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
Changes in v2:
- modify comments
- fix kernel test robot build warning by using cpu_to_le32
- add fix tag and cc stable
---
drivers/usb/chipidea/udc.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index e0092c735a75..c0b8745234c6 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -752,10 +752,17 @@ static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
do {
hw_write(ci, OP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW);
tmp_stat = hw_read(ci, OP_ENDPTSTAT, BIT(n));
- } while (!hw_read(ci, OP_USBCMD, USBCMD_ATDTW));
+ } while (!hw_read(ci, OP_USBCMD, USBCMD_ATDTW) && tmp_stat);
hw_write(ci, OP_USBCMD, USBCMD_ATDTW, 0);
if (tmp_stat)
goto done;
+
+ /* OP_ENDPTSTAT will be clear by HW when the endpoint met
+ * err. This dTD don't push to dQH if current dTD point is
+ * not the last one in previous request.
+ */
+ if (hwep->qh.ptr->curr != cpu_to_le32(prevlastnode->dma))
+ goto done;
}
/* QH configuration */
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2 2/3] usb: chipidea: udc: improve dTD link logic
2024-09-20 9:40 ` [PATCH v2 2/3] usb: chipidea: udc: improve dTD link logic Xu Yang
@ 2024-09-25 12:43 ` Peter Chen
0 siblings, 0 replies; 7+ messages in thread
From: Peter Chen @ 2024-09-25 12:43 UTC (permalink / raw)
To: Xu Yang; +Cc: gregkh, linux-usb, imx, jun.li
On 24-09-20 17:40:55, Xu Yang wrote:
> Currently, ATDTW semaphore is used to safety link new dTD to dQH. But this
> code has a bug when the endpoint is already in error before polling ATDTW
> or just met error during polling ATDTW. In that cases, ATDTW will never
> turn to 1 and the cpu will busy loop there.
>
> When the endpoint met error, ENDPTSTAT will be cleared by HW. Therefore,
> ENDPTSTAT should also be considered during this process. In case of
> endpoint error, the current dTD should not be pushed to the head of dQH
> since some dTDs may be still not executed. Therefore, the link logic is
> also improved accordingly.
>
> Fixes: 26c696c678c4 ("USB: Chipidea: rename struct ci13xxx variables from udc to ci")
> Cc: stable@vger.kernel.org
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
The same comment, do not cc stable tree, not sure if it will affect
others.
Peter
>
> ---
> Changes in v2:
> - modify comments
> - fix kernel test robot build warning by using cpu_to_le32
> - add fix tag and cc stable
> ---
> drivers/usb/chipidea/udc.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> index e0092c735a75..c0b8745234c6 100644
> --- a/drivers/usb/chipidea/udc.c
> +++ b/drivers/usb/chipidea/udc.c
> @@ -752,10 +752,17 @@ static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
> do {
> hw_write(ci, OP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW);
> tmp_stat = hw_read(ci, OP_ENDPTSTAT, BIT(n));
> - } while (!hw_read(ci, OP_USBCMD, USBCMD_ATDTW));
> + } while (!hw_read(ci, OP_USBCMD, USBCMD_ATDTW) && tmp_stat);
> hw_write(ci, OP_USBCMD, USBCMD_ATDTW, 0);
> if (tmp_stat)
> goto done;
> +
> + /* OP_ENDPTSTAT will be clear by HW when the endpoint met
> + * err. This dTD don't push to dQH if current dTD point is
> + * not the last one in previous request.
> + */
> + if (hwep->qh.ptr->curr != cpu_to_le32(prevlastnode->dma))
> + goto done;
> }
>
> /* QH configuration */
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 3/3] usb: chipidea: udc: improve error recovery for ISO transfer
2024-09-20 9:40 [PATCH v2 1/3] usb: chipidea: udc: handle USB Error Interrupt if IOC not set Xu Yang
2024-09-20 9:40 ` [PATCH v2 2/3] usb: chipidea: udc: improve dTD link logic Xu Yang
@ 2024-09-20 9:40 ` Xu Yang
2024-09-25 12:44 ` Peter Chen
2024-09-25 12:42 ` [PATCH v2 1/3] usb: chipidea: udc: handle USB Error Interrupt if IOC not set Peter Chen
2 siblings, 1 reply; 7+ messages in thread
From: Xu Yang @ 2024-09-20 9:40 UTC (permalink / raw)
To: peter.chen, gregkh; +Cc: linux-usb, imx, jun.li
Impove device mode ISO transfer error tolerant by reprime the corresponding
endpoint.
The recovery steps when error occurs:
- Delete the error dTD from dQH and giveback request to user.
- Do reprime if dQH is not empty.
- Do prime when new dTD is queued if dQH is empty
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
Changes in v2:
- modify commit message
- keep "hwreq->req.status = tmptoken & TD_STATUS"
- giveback status 0 to user for isoc error case
---
drivers/usb/chipidea/udc.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index c0b8745234c6..e1121db0aea0 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -823,6 +823,7 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
unsigned remaining_length;
unsigned actual = hwreq->req.length;
struct ci_hdrc *ci = hwep->ci;
+ bool is_isoc = hwep->type == USB_ENDPOINT_XFER_ISOC;
if (hwreq->req.status != -EALREADY)
return -EINVAL;
@@ -836,7 +837,7 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
int n = hw_ep_bit(hwep->num, hwep->dir);
if (ci->rev == CI_REVISION_24 ||
- ci->rev == CI_REVISION_22)
+ ci->rev == CI_REVISION_22 || is_isoc)
if (!hw_read(ci, OP_ENDPTSTAT, BIT(n)))
reprime_dtd(ci, hwep, node);
hwreq->req.status = -EALREADY;
@@ -855,11 +856,15 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
hwreq->req.status = -EPROTO;
break;
} else if ((TD_STATUS_TR_ERR & hwreq->req.status)) {
- hwreq->req.status = -EILSEQ;
- break;
+ if (is_isoc) {
+ hwreq->req.status = 0;
+ } else {
+ hwreq->req.status = -EILSEQ;
+ break;
+ }
}
- if (remaining_length) {
+ if (remaining_length && !is_isoc) {
if (hwep->dir == TX) {
hwreq->req.status = -EPROTO;
break;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2 3/3] usb: chipidea: udc: improve error recovery for ISO transfer
2024-09-20 9:40 ` [PATCH v2 3/3] usb: chipidea: udc: improve error recovery for ISO transfer Xu Yang
@ 2024-09-25 12:44 ` Peter Chen
0 siblings, 0 replies; 7+ messages in thread
From: Peter Chen @ 2024-09-25 12:44 UTC (permalink / raw)
To: Xu Yang; +Cc: gregkh, linux-usb, imx, jun.li
On 24-09-20 17:40:56, Xu Yang wrote:
> Impove device mode ISO transfer error tolerant by reprime the corresponding
> endpoint.
>
> The recovery steps when error occurs:
> - Delete the error dTD from dQH and giveback request to user.
> - Do reprime if dQH is not empty.
> - Do prime when new dTD is queued if dQH is empty
>
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
Acked-by: Peter Chen <peter.chen@kernel.org>
>
> ---
> Changes in v2:
> - modify commit message
> - keep "hwreq->req.status = tmptoken & TD_STATUS"
> - giveback status 0 to user for isoc error case
> ---
> drivers/usb/chipidea/udc.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> index c0b8745234c6..e1121db0aea0 100644
> --- a/drivers/usb/chipidea/udc.c
> +++ b/drivers/usb/chipidea/udc.c
> @@ -823,6 +823,7 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
> unsigned remaining_length;
> unsigned actual = hwreq->req.length;
> struct ci_hdrc *ci = hwep->ci;
> + bool is_isoc = hwep->type == USB_ENDPOINT_XFER_ISOC;
>
> if (hwreq->req.status != -EALREADY)
> return -EINVAL;
> @@ -836,7 +837,7 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
> int n = hw_ep_bit(hwep->num, hwep->dir);
>
> if (ci->rev == CI_REVISION_24 ||
> - ci->rev == CI_REVISION_22)
> + ci->rev == CI_REVISION_22 || is_isoc)
> if (!hw_read(ci, OP_ENDPTSTAT, BIT(n)))
> reprime_dtd(ci, hwep, node);
> hwreq->req.status = -EALREADY;
> @@ -855,11 +856,15 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
> hwreq->req.status = -EPROTO;
> break;
> } else if ((TD_STATUS_TR_ERR & hwreq->req.status)) {
> - hwreq->req.status = -EILSEQ;
> - break;
> + if (is_isoc) {
> + hwreq->req.status = 0;
> + } else {
> + hwreq->req.status = -EILSEQ;
> + break;
> + }
> }
>
> - if (remaining_length) {
> + if (remaining_length && !is_isoc) {
> if (hwep->dir == TX) {
> hwreq->req.status = -EPROTO;
> break;
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/3] usb: chipidea: udc: handle USB Error Interrupt if IOC not set
2024-09-20 9:40 [PATCH v2 1/3] usb: chipidea: udc: handle USB Error Interrupt if IOC not set Xu Yang
2024-09-20 9:40 ` [PATCH v2 2/3] usb: chipidea: udc: improve dTD link logic Xu Yang
2024-09-20 9:40 ` [PATCH v2 3/3] usb: chipidea: udc: improve error recovery for ISO transfer Xu Yang
@ 2024-09-25 12:42 ` Peter Chen
2024-09-26 2:11 ` Xu Yang
2 siblings, 1 reply; 7+ messages in thread
From: Peter Chen @ 2024-09-25 12:42 UTC (permalink / raw)
To: Xu Yang; +Cc: gregkh, linux-usb, imx, jun.li
On 24-09-20 17:40:54, Xu Yang wrote:
> As per USBSTS register description about UEI:
>
> When completion of a USB transaction results in an error condition, this
> bit is set by the Host/Device Controller. This bit is set along with the
> USBINT bit, if the TD on which the error interrupt occurred also had its
> interrupt on complete (IOC) bit set.
>
> UI is set only when IOC set. Add checking UEI to fix miss call
> isr_tr_complete_handler() when IOC have not set and transfer error happen.
>
> Fixes: 26c696c678c4 ("USB: Chipidea: rename struct ci13xxx variables from udc to ci")
> Cc: stable@vger.kernel.org
> Acked-by: Peter Chen <peter.chen@kernel.com>
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
Since this driver has used more than ten years for many vendors, I am
not sure if will affect others or not. Please do not CC stable tree, or
send it to stable tree when this patch at master more than half an year
without no one report issue.
Peter
>
> ---
> Changes in v2:
> - modify part commit message
> - add Ack-by tag
> - add fix tag and cc stable
> ---
> drivers/usb/chipidea/udc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> index 95b697f08a76..e0092c735a75 100644
> --- a/drivers/usb/chipidea/udc.c
> +++ b/drivers/usb/chipidea/udc.c
> @@ -2215,7 +2215,7 @@ static irqreturn_t udc_irq(struct ci_hdrc *ci)
> }
> }
>
> - if (USBi_UI & intr)
> + if ((USBi_UI | USBi_UEI) & intr)
> isr_tr_complete_handler(ci);
>
> if ((USBi_SLI & intr) && !(ci->suspended)) {
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2 1/3] usb: chipidea: udc: handle USB Error Interrupt if IOC not set
2024-09-25 12:42 ` [PATCH v2 1/3] usb: chipidea: udc: handle USB Error Interrupt if IOC not set Peter Chen
@ 2024-09-26 2:11 ` Xu Yang
0 siblings, 0 replies; 7+ messages in thread
From: Xu Yang @ 2024-09-26 2:11 UTC (permalink / raw)
To: Peter Chen; +Cc: gregkh, linux-usb, imx, jun.li
On Wed, Sep 25, 2024 at 08:42:00PM +0800, Peter Chen wrote:
> On 24-09-20 17:40:54, Xu Yang wrote:
> > As per USBSTS register description about UEI:
> >
> > When completion of a USB transaction results in an error condition, this
> > bit is set by the Host/Device Controller. This bit is set along with the
> > USBINT bit, if the TD on which the error interrupt occurred also had its
> > interrupt on complete (IOC) bit set.
> >
> > UI is set only when IOC set. Add checking UEI to fix miss call
> > isr_tr_complete_handler() when IOC have not set and transfer error happen.
> >
> > Fixes: 26c696c678c4 ("USB: Chipidea: rename struct ci13xxx variables from udc to ci")
> > Cc: stable@vger.kernel.org
> > Acked-by: Peter Chen <peter.chen@kernel.com>
> > Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
>
> Since this driver has used more than ten years for many vendors, I am
> not sure if will affect others or not. Please do not CC stable tree, or
> send it to stable tree when this patch at master more than half an year
> without no one report issue.
Okay. I'm going to remove fix tag and stable maillist in v3.
Thanks,
Xu Yang
^ permalink raw reply [flat|nested] 7+ messages in thread