usb: chipidea: udc: handle USB Error Interrupt if IOC not set
PATCH 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.
Currently, device controller will do nothing when endpoints met transfer error if IOC didn't set on that error dTD since UI didn't assert too. This will also handle UEI event as same as USBSTS.UI for such cases.
--- 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 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.
--- 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; + +/* In case of error, ENDPTSTAT will also turn into 0, then +* don't push this dTD to dQH head if current dTD pointer +* is not the last dTD in previous request. +*/ +if (hwep->qh.ptr->curr != prevlastnode->dma) + goto done; }/* QH configuration */
Signature · 1 line
2.34.1
Frank Li
maintainerRe: [PATCH 2/3] usb: chipidea: udc: improve dTD link logic
Quoted 4 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.
It should be bug fixes, add fixes tag and cc stable.
Quoted 20 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]>--- drivers/usb/chipidea/udc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/usb/chipidea/udc.c +0
-0@@ -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));
drivers/usb/chipidea/udc.c static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) · line 623
Quoted 10 lines
drivers/usb/chipidea/udc.c +6
-1- }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; + +/* In case of error, ENDPTSTAT will also turn into 0, then +* don't push this dTD to dQH head if current dTD pointer +* is not the last dTD in previous request. +*/
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.
Quoted 8 lines
drivers/usb/chipidea/udc.c +2
-1+if (hwep->qh.ptr->curr != prevlastnode->dma) + goto done; }/* QH configuration */ --2.34.1
Re: [PATCH 2/3] usb: chipidea: udc: improve dTD link logic
Quoted 7 lines · Frank Li
Quoted 4 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.
It should be bug fixes, add fixes tag and cc stable.
Okay.
Quoted 26 lines
Quoted 26 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]>--- drivers/usb/chipidea/udc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/usb/chipidea/udc.c +1
-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;
Quoted 8 lines
drivers/usb/chipidea/udc.c static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) · line 623
Quoted 5 lines
drivers/usb/chipidea/udc.c +5
-0+ +/* In case of error, ENDPTSTAT will also turn into 0, then +* don't push this dTD to dQH head if current dTD pointer +* is not the last dTD in previous request. +*/
OP_ENDPTSTATwill 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.
Okay, will replace with it.
Thanks,
Xu Yang
kernel test robot
build botRe: [PATCH 2/3] usb: chipidea: udc: improve dTD link logic
In reply to Xu Yangkernel test robot noticed the following build warnings:
Hi Xu,
kernel test robot noticed the following build warnings:
[auto build test WARNING on usb/usb-testing]
[also build test WARNING on usb/usb-next usb/usb-linus linus/master v6.11-rc7 next-20240912] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Xu-Yang/usb-chipidea-udc-improve-dTD-link-logic/20240912-113632 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing patch link: https://lore.kernel.org/r/20240912033551.910337-2-xu.yang_2%40nxp.com patch subject: [PATCH 2/3] usb: chipidea: udc: improve dTD link logic config: i386-randconfig-061-20240913 (https://download.01.org/0day-ci/archive/20240913/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240913/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> drivers/usb/chipidea/udc.c:624:33: sparse: sparse: restricted __le32 degrades to integer
vim +624 drivers/usb/chipidea/udc.c
542
543 /**
544 * _hardware_enqueue: configures a request at hardware level
545 * @hwep: endpoint
546 * @hwreq: request
547 *
548 * This function returns an error code
549 */
550 static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
551 {
552 struct ci_hdrc *ci = hwep->ci;
553 int ret = 0;
554 struct td_node *firstnode, *lastnode;
555
556 /* don't queue twice */
557 if (hwreq->req.status == -EALREADY)
558 return -EALREADY;
559
560 hwreq->req.status = -EALREADY;
561
562 ret = usb_gadget_map_request_by_dev(ci->dev->parent,
563 &hwreq->req, hwep->dir);
564 if (ret)
565 return ret;
566
567 if (hwreq->req.num_mapped_sgs)
568 ret = prepare_td_for_sg(hwep, hwreq);
569 else
570 ret = prepare_td_for_non_sg(hwep, hwreq);
571
572 if (ret)
573 return ret;
574
575 lastnode = list_entry(hwreq->tds.prev,
576 struct td_node, td);
577
578 lastnode->ptr->next = cpu_to_le32(TD_TERMINATE);
579 if (!hwreq->req.no_interrupt)
580 lastnode->ptr->token |= cpu_to_le32(TD_IOC);
581
582 list_for_each_entry_safe(firstnode, lastnode, &hwreq->tds, td)
583 trace_ci_prepare_td(hwep, hwreq, firstnode);
584
585 firstnode = list_first_entry(&hwreq->tds, struct td_node, td);
586
587 wmb();
588
589 hwreq->req.actual = 0;
590 if (!list_empty(&hwep->qh.queue)) {
591 struct ci_hw_req *hwreqprev;
592 int n = hw_ep_bit(hwep->num, hwep->dir);
593 int tmp_stat;
594 struct td_node *prevlastnode;
595 u32 next = firstnode->dma & TD_ADDR_MASK;
596
597 hwreqprev = list_entry(hwep->qh.queue.prev,
598 struct ci_hw_req, queue);
599 prevlastnode = list_entry(hwreqprev->tds.prev,
600 struct td_node, td);
601
602 prevlastnode->ptr->next = cpu_to_le32(next);
603 wmb();
604
605 if (ci->rev == CI_REVISION_22) {
606 if (!hw_read(ci, OP_ENDPTSTAT, BIT(n)))
607 reprime_dtd(ci, hwep, prevlastnode);
608 }
609
610 if (hw_read(ci, OP_ENDPTPRIME, BIT(n)))
611 goto done;
612 do {
613 hw_write(ci, OP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW);
614 tmp_stat = hw_read(ci, OP_ENDPTSTAT, BIT(n));
615 } while (!hw_read(ci, OP_USBCMD, USBCMD_ATDTW) && tmp_stat);
616 hw_write(ci, OP_USBCMD, USBCMD_ATDTW, 0);
617 if (tmp_stat)
618 goto done;
619
620 /* In case of error, ENDPTSTAT will also turn into 0, then
621 * don't push this dTD to dQH head if current dTD pointer
622 * is not the last dTD in previous request.
623 */
> 624 if (hwep->qh.ptr->curr != prevlastnode->dma)
625 goto done;
626 }
627
628 /* QH configuration */
629 hwep->qh.ptr->td.next = cpu_to_le32(firstnode->dma);
630 hwep->qh.ptr->td.token &=
631 cpu_to_le32(~(TD_STATUS_HALTED|TD_STATUS_ACTIVE));
632
633 if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == RX) {
634 u32 mul = hwreq->req.length / hwep->ep.maxpacket;
635
636 if (hwreq->req.length == 0
637 || hwreq->req.length % hwep->ep.maxpacket)
638 mul++;
639 hwep->qh.ptr->cap |= cpu_to_le32(mul << __ffs(QH_MULT));
640 }
641
642 ret = hw_ep_prime(ci, hwep->num, hwep->dir,
643 hwep->type == USB_ENDPOINT_XFER_CONTROL);
644 done:
645 return ret;
646 }
647
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 3/3 usb: chipidea: udc: make isoc endpoint a bit error tolerant
In reply to Xu YangWhen a endpoint met errors, the usb controller will firstly assert related error bit in status filed of dTD, then ENDPTCOMPLETE will be asserted. Finally, USBSTS.UEI will be set.
Due to isoc transfers are error-tolerant transfers, we can make isoc endpoint a bit error tolerant on device mode too. In case of error, it's possilbe to resume the endpoint by reprime the corresponding endpoint.
When error occurs, this will allow error dTD be deleted from dQH and giveback request to user. Then, a reprime/prime operation is executed depends on whether dQH is empty or not. If dQH is not empty, reprime will be done during dequeue process. If dQH is empty, prime will be done when new dTD is linked. In this way, isoc transfer can be recovered from a small number of errors.
--- drivers/usb/chipidea/udc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/usb/chipidea/udc.c +7 -5
@@ -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 ;
@@ -707,7 +708,6 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) remaining_length >>=__ffs (TD_TOTAL_BYTES ); actual -= remaining_length; - hwreq->req.status = tmptoken &TD_STATUS ;if ((TD_STATUS_HALTED & hwreq->req.status)) { hwreq->req.status = -EPIPE ;break ;
@@ -715,11 +715,13 @@ 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 = -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
Frank Li
maintainerRe: [PATCH 3/3] usb: chipidea: udc: make isoc endpoint a bit error tolerant
On Thu, Sep 12, 2024 at 11:35:51AM +0800, Xu Yang wrote:
usb: chipidea: udc: improve error recovery for ISO transfer
Quoted 3 lines
When a endpoint met errors, the usb controller will firstly assert related error bit in status filed of dTD, then ENDPTCOMPLETE will be asserted. Finally, USBSTS.UEI will be set.
Look like this information is not related with this patch.
Quoted 5 lines
Due to isoc transfers are error-tolerant transfers, we can make isoc endpoint a bit error tolerant on device mode too. In case of error, it's possilbe to resume the endpoint by reprime the corresponding endpoint.
Impove device mode ISO transfer error tolerant by reprime the corresponding endpont.
Quoted 7 lines
When error occurs, this will allow error dTD be deleted from dQH and giveback request to user. Then, a reprime/prime operation is executed depends on whether dQH is empty or not. If dQH is not empty, reprime will be done during dequeue process. If dQH is empty, prime will be done when new dTD is linked. In this way, isoc transfer can be recovered from a small number of errors.
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
Quoted 55 lines
Signed-off-by Xu Yang <[email protected]>--- drivers/usb/chipidea/udc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/usb/chipidea/udc.c +7
-6@@ -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 ;@@ -707,7 +708,6 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) remaining_length >>=__ffs (TD_TOTAL_BYTES ); actual -= remaining_length; - hwreq->req.status = tmptoken &TD_STATUS ;if ((TD_STATUS_HALTED & hwreq->req.status)) { hwreq->req.status = -EPIPE ;break ;@@ -715,11 +715,13 @@ 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 = -EILSEQ ; +break ; + } } -if (remaining_length) { +if (remaining_length && !is_isoc) {if (hwep->dir ==TX ) { hwreq->req.status = -EPROTO ;break ; --2.34.1
Re: [PATCH 3/3] usb: chipidea: udc: make isoc endpoint a bit error tolerant
Quoted 3 lines · Frank Li
On Thu, Sep 12, 2024 at 11:35:51AM +0800, Xu Yang wrote:
usb: chipidea: udc: improve error recovery for ISO transfer
Okay.
Quoted 6 lines
Quoted 4 lines
When a endpoint met errors, the usb controller will firstly assert related error bit in status filed of dTD, then ENDPTCOMPLETE will be asserted. Finally, USBSTS.UEI will be set.
Look like this information is not related with this patch.
I'll remove it.
Quoted 9 lines
Quoted 6 lines
Due to isoc transfers are error-tolerant transfers, we can make isoc endpoint a bit error tolerant on device mode too. In case of error, it's possilbe to resume the endpoint by reprime the corresponding endpoint.
Impove device mode ISO transfer error tolerant by reprime the corresponding endpont.
Okay.
Quoted 9 lines
Quoted 8 lines
When error occurs, this will allow error dTD be deleted from dQH and giveback request to user. Then, a reprime/prime operation is executed depends on whether dQH is empty or not. If dQH is not empty, reprime will be done during dequeue process. If dQH is empty, prime will be done when new dTD is linked. In this way, isoc transfer can be recovered from a small number of errors.
Quoted 4 lines
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
Okay.
Thanks,
Xu Yang
Quoted 56 lines
Quoted 56 lines
Signed-off-by Xu Yang <[email protected]>--- drivers/usb/chipidea/udc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/usb/chipidea/udc.c +7
-6@@ -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 ;@@ -707,7 +708,6 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) remaining_length >>=__ffs (TD_TOTAL_BYTES ); actual -= remaining_length; - hwreq->req.status = tmptoken &TD_STATUS ;if ((TD_STATUS_HALTED & hwreq->req.status)) { hwreq->req.status = -EPIPE ;break ;@@ -715,11 +715,13 @@ 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 = -EILSEQ ; +break ; + } } -if (remaining_length) { +if (remaining_length && !is_isoc) {if (hwep->dir ==TX ) { hwreq->req.status = -EPROTO ;break ; --2.34.1
Peter Chen
maintainerRe: [PATCH 3/3] usb: chipidea: udc: make isoc endpoint a bit error tolerant
In reply to Xu YangQuoted 43 lines · Xu Yang
When a endpoint met errors, the usb controller will firstly assert related error bit in status filed of dTD, then ENDPTCOMPLETE will be asserted. Finally, USBSTS.UEI will be set.
Due to isoc transfers are error-tolerant transfers, we can make isoc endpoint a bit error tolerant on device mode too. In case of error, it's possilbe to resume the endpoint by reprime the corresponding endpoint.
When error occurs, this will allow error dTD be deleted from dQH and giveback request to user. Then, a reprime/prime operation is executed depends on whether dQH is empty or not. If dQH is not empty, reprime will be done during dequeue process. If dQH is empty, prime will be done when new dTD is linked. In this way, isoc transfer can be recovered from a small number of errors.
Signed-off-by Xu Yang <[email protected]>--- drivers/usb/chipidea/udc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/usb/chipidea/udc.c +2
-1@@ -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 ;
drivers/usb/chipidea/udc.c static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) · line 710
Quoted 4 lines
drivers/usb/chipidea/udc.c +0
-1@@ -707,7 +708,6 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) remaining_length >>=__ffs (TD_TOTAL_BYTES ); actual -= remaining_length; - hwreq->req.status = tmptoken &TD_STATUS ;
Non-ISO dTD may need error status? You may refine code by ISO and non-ISOC.
Peter
Quoted 23 lines
drivers/usb/chipidea/udc.c +5
-3if ((TD_STATUS_HALTED & hwreq->req.status)) { hwreq->req.status = -EPIPE ;break ;@@ -715,11 +715,13 @@ 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 = -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
Re: [PATCH 3/3] usb: chipidea: udc: make isoc endpoint a bit error tolerant
Quoted 47 lines · Peter Chen
Quoted 46 lines · Xu Yang
When a endpoint met errors, the usb controller will firstly assert related error bit in status filed of dTD, then ENDPTCOMPLETE will be asserted. Finally, USBSTS.UEI will be set.
Due to isoc transfers are error-tolerant transfers, we can make isoc endpoint a bit error tolerant on device mode too. In case of error, it's possilbe to resume the endpoint by reprime the corresponding endpoint.
When error occurs, this will allow error dTD be deleted from dQH and giveback request to user. Then, a reprime/prime operation is executed depends on whether dQH is empty or not. If dQH is not empty, reprime will be done during dequeue process. If dQH is empty, prime will be done when new dTD is linked. In this way, isoc transfer can be recovered from a small number of errors.
Signed-off-by Xu Yang <[email protected]>--- drivers/usb/chipidea/udc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/usb/chipidea/udc.c +2
-1@@ -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 ;@@ -707,7 +708,6 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) remaining_length >>=__ffs (TD_TOTAL_BYTES ); actual -= remaining_length;
Quoted 4 lines
drivers/usb/chipidea/udc.c static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) · line 710
Quoted 1 line
drivers/usb/chipidea/udc.c +0
-1- hwreq->req.status = tmptoken &TD_STATUS ;Non-ISO dTD may need error status? You may refine code by ISO and non-ISOC.
Oh, I have checked this line again, I indeed wrongly remove it. I have no idea how to refine the code since they will go through almost same path, otherwise, the code may be a bit duplicated.
Thanks,
Xu Yang
Quoted 26 lines
Peter
Quoted 23 lines
drivers/usb/chipidea/udc.c +5
-3if ((TD_STATUS_HALTED & hwreq->req.status)) { hwreq->req.status = -EPIPE ;break ;@@ -715,11 +715,13 @@ 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 = -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
Frank Li
maintainerQuoted 10 lines · Xu Yang
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.
Currently, device controller will do nothing when endpoints met transfer error if IOC didn't set on that error dTD since UI didn't assert too. This will also handle UEI event as same as USBSTS.UI for such cases.
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.
If it is user visiable issue, add fix tag and cc stable.
Quoted 11 lines
Signed-off-by Xu Yang <[email protected]>--- drivers/usb/chipidea/udc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/chipidea/udc.c +0
-0
drivers/usb/chipidea/udc.c static irqreturn_t udc_irq(struct ci_hdrc *ci) · line 2066
Quoted 5 lines
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)
Does it work if check UEI only?
Frank
Quoted 6 lines
drivers/usb/chipidea/udc.c +0
-1isr_tr_complete_handler (ci);if ((USBi_SLI & intr) && !(ci->suspended)) { --2.34.1
Quoted 8 lines · Frank Li
Quoted 7 lines · Xu Yang
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.
Quoted 6 lines
Quoted 3 lines
Currently, device controller will do nothing when endpoints met transfer error if IOC didn't set on that error dTD since UI didn't assert too. This will also handle UEI event as same as USBSTS.UI for such cases.
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.
Okay.
Quoted 2 lines
If it is user visiable issue, add fix tag and cc stable.
Okay.
Quoted 15 lines
Quoted 15 lines
Signed-off-by Xu Yang <[email protected]>--- drivers/usb/chipidea/udc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/chipidea/udc.c +0
-0@@ -2063,7 +2063,7 @@ static irqreturn_t udc_irq(struct ci_hdrc *ci) } }
Quoted 4 lines
drivers/usb/chipidea/udc.c static irqreturn_t udc_irq(struct ci_hdrc *ci) · line 2066
Quoted 2 lines
drivers/usb/chipidea/udc.c +1
-1-if (USBi_UI & intr) +if ((USBi_UI | USBi_UEI) & intr)Does it work if check UEI only?
Not work, we will lost normal USB transaction complete event.
Thanks,
Xu Yang
Quoted 9 lines
Frank
Quoted 6 lines
drivers/usb/chipidea/udc.c +0
-1isr_tr_complete_handler (ci);if ((USBi_SLI & intr) && !(ci->suspended)) { --2.34.1
Quoted 7 lines · Xu Yang
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.
Quoted 5 lines
Currently, device controller will do nothing when endpoints met transfer error if IOC didn't set on that error dTD since UI didn't assert too. This will also handle UEI event as same as USBSTS.UI for such cases.
Signed-off-by Xu Yang <[email protected]>
Quoted 20 lines
--- 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