usb: chipidea: udc: handle USB Error Interrupt if IOC not set
PATCH v3 1/3 usb: chipidea: udc: handle USB Error Interrupt if IOC not set
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.
---
Changes in v2:
- modify part commit message
- add Ack-by tag
- add fix tag and cc stable
Changes in v3:
- remove fixes tag and stable maillist
--- drivers/usb/chipidea/udc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/chipidea/udc.c +1 -1
@@ -2063,7 +2063,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)) {
Signature · 1 line
2.34.1
PATCH v3 2/3 usb: chipidea: udc: improve dTD link logic
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.
---
Changes in v2:
- modify comments
- fix kernel test robot build warning by using cpu_to_le32
- add fix tag and cc stable
Changes in v3:
- remove fixes tag and stable maillist
--- drivers/usb/chipidea/udc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/usb/chipidea/udc.c +8 -1
@@ -612,10 +612,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 */
Signature · 1 line
2.34.1
Re: [PATCH v3 2/3] usb: chipidea: udc: improve dTD link logic
Quoted 5 lines · Xu Yang
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.
Quoted 7 lines
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.
Signed-off-by Xu Yang <[email protected]>
Quoted 38 lines
---
Changes in v2:
- modify comments
- fix kernel test robot build warning by usingcpu_to_le32
- add fix tag and cc stable
Changes in v3:
- remove fixes tag and stable maillist--- drivers/usb/chipidea/udc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/usb/chipidea/udc.c +8
-1@@ -612,10 +612,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 */ Signature · 1 line
2.34.1
PATCH v3 3/3 usb: chipidea: udc: improve error recovery for ISO transfer
In reply to Xu YangImpove 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
---
Changes in v2:
- modify commit message
- keep "hwreq->req.status = tmptoken & TD_STATUS"
- giveback status 0 to user for isoc error case
Changes in v3:
- add Acked-by tag
--- drivers/usb/chipidea/udc.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/usb/chipidea/udc.c +9 -4
@@ -683,6 +683,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 ;
@@ -696,7 +697,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 ;
@@ -715,11 +716,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 ;
Signature · 1 line
2.34.1