usb: ehci: add workaround for chipidea PORTSC.PEC bug
Subsystems (4)
PATCH v2 1/2 usb: ehci: add workaround for chipidea PORTSC.PEC bug
Some NXP processor using chipidea IP has a bug when frame babble is detected.
As per 4.15.1.1.1 Serial Bus Babble:
A babble condition also exists if IN transaction is in progress at
High-speed SOF2 point. This is called frame babble. The host controller must disable the port to which the frame babble is detected.
The USB controller has disabled the port (PE cleared) and has asserted USBERRINT when frame babble is detected, but PEC is not asserted. Therefore, the SW isn't aware that port has been disabled. Then the SW keeps sending packets to this port, but all of the transfers will fail.
This workaround will firstly assert PCD by SW when USBERRINT is detected and then judge whether port change has really occurred or not by polling roothub status. Because the PEC doesn't get asserted in our case, this patch will also assert it by SW when specific conditions are satisfied.
---
Changes in v2:
- fix typo in commit message
- Adjust the judgement logic in echi_irq() as suggested from Alan
--- drivers/usb/host/ehci-hcd.c | 8 ++++++-- drivers/usb/host/ehci-hub.c | 10 +++++++++- drivers/usb/host/ehci.h | 10 ++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-)
drivers/usb/host/ehci-hcd.c +6 -2
@@ -755,10 +755,14 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)/* normal [4.15.1.2] or error [4.15.1.1] completion */ if (likely ((status & (STS_INT |STS_ERR )) !=0 )) { -if (likely ((status &STS_ERR ) ==0 )) +if (likely ((status &STS_ERR ) ==0 )) {INCR (ehci->stats.normal); -else + }else { +/* Force to check port status */ +if (ehci->has_ci_pec_bug) + status |=STS_PCD ;INCR (ehci->stats.error); + } bh =1 ; }
drivers/usb/host/ehci-hub.c +9 -1
@@ -674,7 +674,8 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)if ((temp & mask) !=0 ||test_bit (i, &ehci->port_c_suspend) || (ehci->reset_done[i] &&time_after_eq ( - jiffies, ehci->reset_done[i]))) { + jiffies, ehci->reset_done[i])) + ||ehci_has_ci_pec_bug (ehci, temp)) {if (i <7 ) buf [0 ] |=1 << (i +1 );else
@@ -875,6 +876,13 @@ int ehci_hub_control(if (temp &PORT_PEC ) status |=USB_PORT_STAT_C_ENABLE <<16 ; +if (ehci_has_ci_pec_bug (ehci, temp)) { + status |=USB_PORT_STAT_C_ENABLE <<16 ; +ehci_info (ehci, +"PE is cleared by HW port:%d PORTSC:%08x\n" , + wIndex +1 , temp); + } +if ((temp &PORT_OCC ) && (!ignore_oc && !ehci->spurious_oc)){ status |=USB_PORT_STAT_C_OVERCURRENT <<16 ;
drivers/usb/host/ehci.h +10 -0
@@ -207,6 +207,7 @@ struct ehci_hcd { /* one per controller */ unsigned has_fsl_port_bug:1; /* FreeScale */ unsigned has_fsl_hs_errata:1; /* Freescale HS quirk */ unsigned has_fsl_susp_errata:1; /* NXP SUSP quirk */ + unsigned has_ci_pec_bug:1; /* ChipIdea PEC bug */ unsigned big_endian_mmio:1; unsigned big_endian_desc:1; unsigned big_endian_capbase:1;
@@ -707,6 +708,15 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)*/ #define ehci_has_fsl_susp_errata (e) ((e)->has_fsl_susp_errata) +/* +* Some Freescale/NXP processors using ChipIdea IP have a bug in which +* disabling the port (PE is cleared) does not cause PEC to be asserted +* when frame babble is detected. +*/ +#define ehci_has_ci_pec_bug (e, portsc) \ + ((e)->has_ci_pec_bug && ((e)->command & CMD_PSE) \ + && !(portsc & PORT_PEC) && !(portsc & PORT_PE)) +/* * While most USB host controllers implement their registers in * little-endian format, a minority (celleb companion chip) implement
Signature · 1 line
2.34.1
PATCH v2 2/2 usb: chipidea: add workaround for chipidea PEC bug
Some NXP processors using ChipIdea USB IP have a bug when frame babble is detected.
Issue description:
In USB camera test, our controller is host in HS mode. In ISOC IN, when device sends data across the micro frame, it causes the babble in host controller. This will clear the PE bit. In spec, it also requires to set the PEC bit and then set the PCI bit. Without the PCI interrupt, the software does not know the PE is cleared.
This will add a flag CI_HDRC_HAS_PORTSC_PEC_MISSED to some impacted platform datas. And the ehci host driver will assert PEC by SW when specific conditions are satisfied.
---
Changes in v2:
- no change
--- drivers/usb/chipidea/ci.h | 1 + drivers/usb/chipidea/ci_hdrc_imx.c | 4 +++- drivers/usb/chipidea/core.c | 2 ++ drivers/usb/chipidea/host.c | 1 + include/linux/usb/chipidea.h | 1 + 5 files changed, 8 insertions(+), 1 deletion(-)
drivers/usb/chipidea/ci.h +1 -0
@@ -257,6 +257,7 @@ struct ci_hdrc {bool id_event;bool b_sess_valid_event;bool imx28_write_fix; +bool has_portsc_pec_bug;bool supports_runtime_pm;bool in_lpm;bool wakeup_int;
drivers/usb/chipidea/ci_hdrc_imx.c +3 -1
@@ -68,11 +68,13 @@ static const struct ci_hdrc_imx_platform_flag imx7d_usb_data = {static const struct ci_hdrc_imx_platform_flag imx7ulp_usb_data = { .flags =CI_HDRC_SUPPORTS_RUNTIME_PM | +CI_HDRC_HAS_PORTSC_PEC_MISSED |CI_HDRC_PMQOS , };static const struct ci_hdrc_imx_platform_flag imx8ulp_usb_data = { - .flags =CI_HDRC_SUPPORTS_RUNTIME_PM , + .flags =CI_HDRC_SUPPORTS_RUNTIME_PM | +CI_HDRC_HAS_PORTSC_PEC_MISSED , };static const struct of_device_id ci_hdrc_imx_dt_ids[] = {
drivers/usb/chipidea/core.c +2 -0
@@ -1044,6 +1044,8 @@ static int ci_hdrc_probe(struct platform_device *pdev) CI_HDRC_IMX28_WRITE_FIX); ci->supports_runtime_pm = !!(ci->platdata->flags &CI_HDRC_SUPPORTS_RUNTIME_PM ); + ci->has_portsc_pec_bug = !!(ci->platdata->flags & +CI_HDRC_HAS_PORTSC_PEC_MISSED );platform_set_drvdata (pdev, ci); ret =hw_device_init (ci, base);
drivers/usb/chipidea/host.c +1 -0
@@ -151,6 +151,7 @@ static int host_start(struct ci_hdrc *ci) ehci->has_hostpc = ci->hw_bank.lpm; ehci->has_tdi_phy_lpm = ci->hw_bank.lpm; ehci->imx28_write_fix = ci->imx28_write_fix; + ehci->has_ci_pec_bug = ci->has_portsc_pec_bug; priv = (struct ehci_ci_priv *)ehci->priv; priv->reg_vbus =NULL ;
include/linux/usb/chipidea.h +1 -0
@@ -63,6 +63,7 @@ struct ci_hdrc_platform_data {#define CI_HDRC_IMX_IS_HSIC BIT(14)#define CI_HDRC_PMQOS BIT(15)#define CI_HDRC_PHY_VBUS_CONTROL BIT(16) +#define CI_HDRC_HAS_PORTSC_PEC_MISSED BIT(17)enum usb_dr_mode dr_mode;#define CI_HDRC_CONTROLLER_RESET_EVENT 0#define CI_HDRC_CONTROLLER_STOPPED_EVENT 1
Signature · 1 line
2.34.1
Re: [PATCH v2 2/2] usb: chipidea: add workaround for chipidea PEC bug
Quoted 11 lines · Xu Yang
Some NXP processors using ChipIdea USB IP have a bug when frame babble is detected.
Issue description:
In USB camera test, our controller is host in HS mode. In ISOC IN, when device sends data across the micro frame, it causes the babble in host controller. This will clear the PE bit. In spec, it also requires to set the PEC bit and then set the PCI bit. Without the PCI interrupt, the software does not know the PE is cleared.
Quoted 6 lines
This will add a flag
CI_HDRC_HAS_PORTSC_PEC_MISSEDto some impacted platform datas. And the ehci host driver will assert PEC by SW when specific conditions are satisfied.Signed-off-by Xu Yang <[email protected]>
Peter
Quoted 82 lines
---
Changes in v2:
- no change--- drivers/usb/chipidea/ci.h | 1 + drivers/usb/chipidea/ci_hdrc_imx.c | 4 +++- drivers/usb/chipidea/core.c | 2 ++ drivers/usb/chipidea/host.c | 1 + include/linux/usb/chipidea.h | 1 + 5 files changed, 8 insertions(+), 1 deletion(-)drivers/usb/chipidea/ci.h +1
-0@@ -257,6 +257,7 @@ struct ci_hdrc {bool id_event;bool b_sess_valid_event;bool imx28_write_fix; +bool has_portsc_pec_bug;bool supports_runtime_pm;bool in_lpm;bool wakeup_int;drivers/usb/chipidea/ci_hdrc_imx.c +3
-1@@ -68,11 +68,13 @@ static const struct ci_hdrc_imx_platform_flag imx7d_usb_data = {static const struct ci_hdrc_imx_platform_flag imx7ulp_usb_data = { .flags =CI_HDRC_SUPPORTS_RUNTIME_PM | +CI_HDRC_HAS_PORTSC_PEC_MISSED |CI_HDRC_PMQOS , };static const struct ci_hdrc_imx_platform_flag imx8ulp_usb_data = { - .flags =CI_HDRC_SUPPORTS_RUNTIME_PM , + .flags =CI_HDRC_SUPPORTS_RUNTIME_PM | +CI_HDRC_HAS_PORTSC_PEC_MISSED , };static const struct of_device_id ci_hdrc_imx_dt_ids[] = {drivers/usb/chipidea/core.c +2
-0@@ -1044,6 +1044,8 @@ static int ci_hdrc_probe(struct platform_device *pdev) CI_HDRC_IMX28_WRITE_FIX); ci->supports_runtime_pm = !!(ci->platdata->flags &CI_HDRC_SUPPORTS_RUNTIME_PM ); + ci->has_portsc_pec_bug = !!(ci->platdata->flags & +CI_HDRC_HAS_PORTSC_PEC_MISSED );platform_set_drvdata (pdev, ci); ret =hw_device_init (ci, base);drivers/usb/chipidea/host.c +1
-0@@ -151,6 +151,7 @@ static int host_start(struct ci_hdrc *ci) ehci->has_hostpc = ci->hw_bank.lpm; ehci->has_tdi_phy_lpm = ci->hw_bank.lpm; ehci->imx28_write_fix = ci->imx28_write_fix; + ehci->has_ci_pec_bug = ci->has_portsc_pec_bug; priv = (struct ehci_ci_priv *)ehci->priv; priv->reg_vbus =NULL ;include/linux/usb/chipidea.h +1
-1@@ -63,6 +63,7 @@ struct ci_hdrc_platform_data {#define CI_HDRC_IMX_IS_HSIC BIT(14)#define CI_HDRC_PMQOS BIT(15)#define CI_HDRC_PHY_VBUS_CONTROL BIT(16) +#define CI_HDRC_HAS_PORTSC_PEC_MISSED BIT(17)enum usb_dr_mode dr_mode;#define CI_HDRC_CONTROLLER_RESET_EVENT 0#define CI_HDRC_CONTROLLER_STOPPED_EVENT 1 --2.34.1
Quoted 15 lines · Xu Yang
Some NXP processor using chipidea IP has a bug when frame babble is detected.
As per 4.15.1.1.1 Serial Bus Babble:
A babble condition also exists if IN transaction is in progress at
High-speed SOF2 point. This is called frame babble. The host controller must disable the port to which the frame babble is detected.The USB controller has disabled the port (PE cleared) and has asserted USBERRINT when frame babble is detected, but PEC is not asserted. Therefore, the SW isn't aware that port has been disabled. Then the SW keeps sending packets to this port, but all of the transfers will fail.
Quoted 7 lines
This workaround will firstly assert PCD by SW when USBERRINT is detected and then judge whether port change has really occurred or not by polling roothub status. Because the PEC doesn't get asserted in our case, this patch will also assert it by SW when specific conditions are satisfied.
Signed-off-by Xu Yang <[email protected]>
Peter
Quoted 90 lines
---
Changes in v2:
- fix typo in commit message
- Adjust the judgement logic inechi_irq()as suggested from Alan--- drivers/usb/host/ehci-hcd.c | 8 ++++++-- drivers/usb/host/ehci-hub.c | 10 +++++++++- drivers/usb/host/ehci.h | 10 ++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-)drivers/usb/host/ehci-hcd.c +6
-2@@ -755,10 +755,14 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)/* normal [4.15.1.2] or error [4.15.1.1] completion */ if (likely ((status & (STS_INT |STS_ERR )) !=0 )) { -if (likely ((status &STS_ERR ) ==0 )) +if (likely ((status &STS_ERR ) ==0 )) {INCR (ehci->stats.normal); -else + }else { +/* Force to check port status */ +if (ehci->has_ci_pec_bug) + status |=STS_PCD ;INCR (ehci->stats.error); + } bh =1 ; }drivers/usb/host/ehci-hub.c +9
-1@@ -674,7 +674,8 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)if ((temp & mask) !=0 ||test_bit (i, &ehci->port_c_suspend) || (ehci->reset_done[i] &&time_after_eq ( - jiffies, ehci->reset_done[i]))) { + jiffies, ehci->reset_done[i])) + ||ehci_has_ci_pec_bug (ehci, temp)) {if (i <7 ) buf [0 ] |=1 << (i +1 );else @@ -875,6 +876,13 @@ int ehci_hub_control(if (temp &PORT_PEC ) status |=USB_PORT_STAT_C_ENABLE <<16 ; +if (ehci_has_ci_pec_bug (ehci, temp)) { + status |=USB_PORT_STAT_C_ENABLE <<16 ; +ehci_info (ehci, +"PE is cleared by HW port:%d PORTSC:%08x\n" , + wIndex +1 , temp); + } +if ((temp &PORT_OCC ) && (!ignore_oc && !ehci->spurious_oc)){ status |=USB_PORT_STAT_C_OVERCURRENT <<16 ;drivers/usb/host/ehci.h +10
-1@@ -207,6 +207,7 @@ struct ehci_hcd { /* one per controller */ unsigned has_fsl_port_bug:1; /* FreeScale */ unsigned has_fsl_hs_errata:1; /* Freescale HS quirk */ unsigned has_fsl_susp_errata:1; /* NXP SUSP quirk */ + unsigned has_ci_pec_bug:1; /* ChipIdea PEC bug */ unsigned big_endian_mmio:1; unsigned big_endian_desc:1; unsigned big_endian_capbase:1;@@ -707,6 +708,15 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)*/ #define ehci_has_fsl_susp_errata (e) ((e)->has_fsl_susp_errata) +/* +* Some Freescale/NXP processors using ChipIdea IP have a bug in which +* disabling the port (PE is cleared) does not cause PEC to be asserted +* when frame babble is detected. +*/ +#define ehci_has_ci_pec_bug (e, portsc) \ + ((e)->has_ci_pec_bug && ((e)->command & CMD_PSE) \ + && !(portsc & PORT_PEC) && !(portsc & PORT_PE)) +/* * While most USB host controllers implement their registers in * little-endian format, a minority (celleb companion chip) implement -- 2.34.1
Quoted 19 lines · Xu Yang
Some NXP processor using chipidea IP has a bug when frame babble is detected.
As per 4.15.1.1.1 Serial Bus Babble:
A babble condition also exists if IN transaction is in progress at
High-speed SOF2 point. This is called frame babble. The host controller must disable the port to which the frame babble is detected.The USB controller has disabled the port (PE cleared) and has asserted USBERRINT when frame babble is detected, but PEC is not asserted. Therefore, the SW isn't aware that port has been disabled. Then the SW keeps sending packets to this port, but all of the transfers will fail.
This workaround will firstly assert PCD by SW when USBERRINT is detected and then judge whether port change has really occurred or not by polling roothub status. Because the PEC doesn't get asserted in our case, this patch will also assert it by SW when specific conditions are satisfied.
Quoted 7 lines
Signed-off-by Xu Yang <[email protected]>---
Changes in v2:
- fix typo in commit message
- Adjust the judgement logic inechi_irq()as suggested from Alan
---