Skip to contentSkip to conversation

USB DWC2 parity fix in isochronous mode

PATCH In review Scott Branden 3 participants 11 messages Sep 11, 2015 – Sep 28, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover USB DWC2 parity fix in isochronous mode

This patch contains a fix for a real world interop problem found when using the Synopsis DWC2 USB controller with isochronous audio as detailed in the commit message.

Changes from v2:
- created s2c_hsotg_chage_ep_iso_parity function to call function in 3 places in code
- used hsotg->num_of_eps instead of MAX_EPS_CHANNELS

Changes from v1:
- Address code review comments as per previous responses:
- renamed parity_set to has_correct_parity and reorder some logic

Roman Bacik (1):
usb: dwc2: gadget: parity fix in isochronous mode

 drivers/usb/dwc2/core.h   |  1 +
 drivers/usb/dwc2/gadget.c | 58 ++++++++++++++++++++++++++++++++++++++++++-----
 drivers/usb/dwc2/hw.h     |  1 +
 3 files changed, 54 insertions(+), 6 deletions(-)
Signature · 1 line
2.5.0
#1 lore raw

PATCH v3 1/1 usb: dwc2: gadget: parity fix in isochronous mode

From: Roman Bacik <[email protected]>

USB OTG driver in isochronous mode has to set the parity of the receiving microframe. The parity is set to even by default. This causes problems for an audio gadget, if the host starts transmitting on odd microframes.

This fix uses Incomplete Periodic Transfer interrupt to toggle between even and odd parity until the Transfer Complete interrupt is received.

---
 drivers/usb/dwc2/core.h   |  1 +
 drivers/usb/dwc2/gadget.c | 58 ++++++++++++++++++++++++++++++++++++++++++-----
 drivers/usb/dwc2/hw.h     |  1 +
 3 files changed, 54 insertions(+), 6 deletions(-)
drivers/usb/dwc2/core.h +1 -0
index 0ed87620..a5634fd 100644
@@ -150,6 +150,7 @@ struct s3c_hsotg_ep {
 	unsigned int            periodic:1;
 	unsigned int            isochronous:1;
 	unsigned int            send_zlp:1;
+	unsigned int            has_correct_parity:1;
 
 	char                    name[10];
 };
drivers/usb/dwc2/gadget.c +52 -6

89 lines not on this page · raw message

drivers/usb/dwc2/hw.h +1 -0
index d0a5ed8..553f246 100644
@@ -142,6 +142,7 @@
 #define GINTSTS_RESETDET		(1 << 23)
 #define GINTSTS_FET_SUSP		(1 << 22)
 #define GINTSTS_INCOMPL_IP		(1 << 21)
+#define GINTSTS_INCOMPL_SOOUT		(1 << 21)
 #define GINTSTS_INCOMPL_SOIN		(1 << 20)
 #define GINTSTS_OEPINT			(1 << 19)
 #define GINTSTS_IEPINT			(1 << 18)
Signature · 1 line
2.5.0
#2 lore raw
In reply to Scott Branden

Hi John,

Could you please review the v3 Patch. I believe we have address all of your comments?

Quoted 21 lines · Scott Branden

This patch contains a fix for a real world interop problem found when using the Synopsis DWC2 USB controller with isochronous audio as detailed in the commit message.

Changes from v2:
- created s2c_hsotg_chage_ep_iso_parity function to call function in 3 places in code
- used hsotg->num_of_eps instead of MAX_EPS_CHANNELS

Changes from v1:
- Address code review comments as per previous responses:
- renamed parity_set to has_correct_parity and reorder some logic

Roman Bacik (1):
usb: dwc2: gadget: parity fix in isochronous mode

  drivers/usb/dwc2/core.h   |  1 +
  drivers/usb/dwc2/gadget.c | 58 ++++++++++++++++++++++++++++++++++++++++++-----
  drivers/usb/dwc2/hw.h     |  1 +
  3 files changed, 54 insertions(+), 6 deletions(-)
#3 lore raw
Quoted 5 lines · Scott Branden

Hi John,

Could you please review the v3 Patch. I believe we have address all of your comments?

Yes I've been meaning to test it on our platforms. I should be able to get to it tomorrow.

Regards,
John

#4 lore raw
Quoted 10 lines · John Youn
Quoted 5 lines · Scott Branden

Hi John,

Could you please review the v3 Patch. I believe we have address all of your comments?

Yes I've been meaning to test it on our platforms. I should be able to get to it tomorrow.

Also if you could rebase off of Felipe's testing/next branch it would make it easier when it comes time to merge it in.

Regards,
John

#5 lore raw
Quoted 8 lines · John Youn
Quoted 7 lines · John Youn
Quoted 5 lines · Scott Branden

Hi John,

Could you please review the v3 Patch. I believe we have address all of your comments?

Quoted 6 lines
Quoted 3 lines

Yes I've been meaning to test it on our platforms. I should be able to get to it tomorrow.

Also if you could rebase off of Felipe's testing/next branch it would make it easier when it comes time to merge it in.

Could you point me at Felipe's git repo as I am unfamiliar with the location?

Thanks,
Scott

Quoted 4 lines

Regards,
John

#6 lore raw
Quoted 13 lines · Scott Branden
Quoted 12 lines · John Youn
Quoted 10 lines · John Youn
Quoted 5 lines · Scott Branden

Hi John,

Could you please review the v3 Patch. I believe we have address all of your comments?

Yes I've been meaning to test it on our platforms. I should be able to get to it tomorrow.

Quoted 6 lines
Quoted 2 lines

Also if you could rebase off of Felipe's testing/next branch it would make it easier when it comes time to merge it in.

Could you point me at Felipe's git repo as I am unfamiliar with the location?

git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git

Regards,
John

#7 lore raw
In reply to Scott Branden
Quoted 13 lines · Scott Branden

This patch contains a fix for a real world interop problem found when using the Synopsis DWC2 USB controller with isochronous audio as detailed in the commit message.

Changes from v2:
- created s2c_hsotg_chage_ep_iso_parity function to call function in 3 places in code
- used hsotg->num_of_eps instead of MAX_EPS_CHANNELS

Changes from v1:
- Address code review comments as per previous responses:
- renamed parity_set to has_correct_parity and reorder some logic

Quoted 8 lines

Roman Bacik (1):
usb: dwc2: gadget: parity fix in isochronous mode

 drivers/usb/dwc2/core.h   |  1 +
 drivers/usb/dwc2/gadget.c | 58 ++++++++++++++++++++++++++++++++++++++++++-----
 drivers/usb/dwc2/hw.h     |  1 +
 3 files changed, 54 insertions(+), 6 deletions(-)

This seems to break slave mode on my platform. It seems to be dropping a lot of packets. I tried bInterval=4,5,6, ISO OUT. I'll need to take a closer look to determine why. Probably later this week.

Are you able to run in slave mode on your platform? If so can you try it out?

Regards,
John

#8 lore raw
Quoted 33 lines

-----Original Message-----
From: John Youn [mailto:[email protected]]
Sent: September-23-15 9:21 PM
To: Scott Branden; John Youn; Greg Kroah-Hartman; linux- [email protected]; Roman Bacik
Cc: [email protected]; bcm-kernel-feedback-list
Subject: Re: [PATCH v3 0/1] USB DWC2 parity fix in isochronous mode

Quoted 14 lines · Scott Branden

This patch contains a fix for a real world interop problem found when using the Synopsis DWC2 USB controller with isochronous audio as detailed in the commit message.

Changes from v2:
- created s2c_hsotg_chage_ep_iso_parity function to call function in
3 places in code
- used hsotg->num_of_eps instead of MAX_EPS_CHANNELS

Changes from v1:
- Address code review comments as per previous responses:
- renamed parity_set to has_correct_parity and reorder some logic

Quoted 5 lines

Roman Bacik (1):
usb: dwc2: gadget: parity fix in isochronous mode

 drivers/usb/dwc2/core.h   |  1 +
 drivers/usb/dwc2/gadget.c | 58

++++++++++++++++++++++++++++++++++++++++++-----

Quoted 3 lines
 drivers/usb/dwc2/hw.h     |  1 +
 3 files changed, 54 insertions(+), 6 deletions(-)
Quoted 8 lines

This seems to break slave mode on my platform. It seems to be dropping a lot of packets. I tried bInterval=4,5,6, ISO OUT.
I'll need to take a closer look to determine why. Probably later this week.

Are you able to run in slave mode on your platform? If so can you try it out?

Regards,
John

Our current test procedure is as follows:

Build Linux kernel with:

Device Drivers
- Sound Card Support 'SOUND=y': ALSA 'SND=y'
- Generic sound devices: Dummy (/dev/null) soundcard 'SND_DUMMY=y'
- USB support 'USB_SUPPORT=y':
DesignWare USB2 DRD Core support 'USB_DWC2=y'
- Gadget only mode 'USB_DWC2_PERIPHERAL=y'
DWC2 Platform 'USB_DWC2_PLATFORM=y'
- USB Gadget Support 'USB_GADGET=y': Audio Gadget 'USB_AUDIO=y'
- PHY Subsystem: Broadcom Kona USB2 PHY Driver 'BCM_KONA_USB2_PHY=y'

If you have only even hosts, you can change the default micro frame parity to odd:

drivers/usb/dwc2/gadget.c +2 -2
index ad45b0b..80bde75 100644
@@ -2709,7 +2709,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
     switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
     case USB_ENDPOINT_XFER_ISOC:
         epctrl |= DXEPCTL_EPTYPE_ISO;
-        epctrl |= DXEPCTL_SETEVENFR;
+        epctrl |= DXEPCTL_SETODDFR;
         hs_ep->isochronous = 1;
         if (dir_in)
             hs_ep->periodic = 1;
@@ -2777,7 +2777,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
  
     /* for non control endpoints, set PID to D0 */
     if (index)
-        epctrl |= DXEPCTL_SETD0PID;
+        epctrl |= DXEPCTL_SETD1PID;
  
     dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n",
         __func__, epctrl);

To test OUT direction:
Host:
aplay -D plughw:2 -r 48000 -f S16_LE tone_48stereo.wav Device:
arecord -D plughw:0 -r 48000 -f S16_LE -c 1 /tmp/rec.pcm

To test IN direction:
Host:
arecord -D plughw:2 -r 48000 -f S16_LE -c 1 /tmp/rec.pcm Device:
aplay -D plughw:0 -r 48000 -f S16_LE /tmp/rec.pcm

If you would like, we can try to test your procedure provided you send us enough details. Regards,

Roman

#9 lore raw
Quoted 91 lines · Roman Bacik
Quoted 33 lines

-----Original Message-----
From: John Youn [mailto:[email protected]]
Sent: September-23-15 9:21 PM
To: Scott Branden; John Youn; Greg Kroah-Hartman; linux- [email protected]; Roman Bacik
Cc: [email protected]; bcm-kernel-feedback-list
Subject: Re: [PATCH v3 0/1] USB DWC2 parity fix in isochronous mode

Quoted 14 lines · Scott Branden

This patch contains a fix for a real world interop problem found when using the Synopsis DWC2 USB controller with isochronous audio as detailed in the commit message.

Changes from v2:
- created s2c_hsotg_chage_ep_iso_parity function to call function in
3 places in code
- used hsotg->num_of_eps instead of MAX_EPS_CHANNELS

Changes from v1:
- Address code review comments as per previous responses:
- renamed parity_set to has_correct_parity and reorder some logic

Quoted 5 lines

Roman Bacik (1):
usb: dwc2: gadget: parity fix in isochronous mode

 drivers/usb/dwc2/core.h   |  1 +
 drivers/usb/dwc2/gadget.c | 58

++++++++++++++++++++++++++++++++++++++++++-----

Quoted 3 lines
 drivers/usb/dwc2/hw.h     |  1 +
 3 files changed, 54 insertions(+), 6 deletions(-)
Quoted 8 lines

This seems to break slave mode on my platform. It seems to be dropping a lot of packets. I tried bInterval=4,5,6, ISO OUT.
I'll need to take a closer look to determine why. Probably later this week.

Are you able to run in slave mode on your platform? If so can you try it out?

Regards,
John

Our current test procedure is as follows:

Build Linux kernel with:

Device Drivers
- Sound Card Support 'SOUND=y': ALSA 'SND=y'
- Generic sound devices: Dummy (/dev/null) soundcard 'SND_DUMMY=y'
- USB support 'USB_SUPPORT=y':
DesignWare USB2 DRD Core support 'USB_DWC2=y'
- Gadget only mode 'USB_DWC2_PERIPHERAL=y'
DWC2 Platform 'USB_DWC2_PLATFORM=y'
- USB Gadget Support 'USB_GADGET=y': Audio Gadget 'USB_AUDIO=y'
- PHY Subsystem: Broadcom Kona USB2 PHY Driver 'BCM_KONA_USB2_PHY=y'

If you have only even hosts, you can change the default micro frame parity to odd:

drivers/usb/dwc2/gadget.c +2 -2
index ad45b0b..80bde75 100644
@@ -2709,7 +2709,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
     switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
     case USB_ENDPOINT_XFER_ISOC:
         epctrl |= DXEPCTL_EPTYPE_ISO;
-        epctrl |= DXEPCTL_SETEVENFR;
+        epctrl |= DXEPCTL_SETODDFR;
         hs_ep->isochronous = 1;
         if (dir_in)
             hs_ep->periodic = 1;
@@ -2777,7 +2777,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
 
     /* for non control endpoints, set PID to D0 */
     if (index)
-        epctrl |= DXEPCTL_SETD0PID;
+        epctrl |= DXEPCTL_SETD1PID;
 
     dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n",
         __func__, epctrl);

To test OUT direction:
Host:
aplay -D plughw:2 -r 48000 -f S16_LE tone_48stereo.wav Device:
arecord -D plughw:0 -r 48000 -f S16_LE -c 1 /tmp/rec.pcm

To test IN direction:
Host:
arecord -D plughw:2 -r 48000 -f S16_LE -c 1 /tmp/rec.pcm Device:
aplay -D plughw:0 -r 48000 -f S16_LE /tmp/rec.pcm

Quoted 6 lines

If you would like, we can try to test your procedure provided you send us enough details. Regards,

Roman

I looked at it a bit more and I think there are two issues.

In slave-mode, the xfercomplete interrupt is not used for OUT transfers, so the has_correct_parity flag is never set.

The other issue is that we occasionally get the incomplete interrupt twice in a microframe causing the parity to be set incorrectly for the next frame. Thus we will continuously miss until this occurs again, correcting it.

These two problems in combination cause dropped packets throughout operation.

If you give me some time I can see if I can fix up this patch to work with slave mode.

I've tried all our hosts here and they are all even hosts, so I tried flipping the default parity. The issue exists in either case.

Regards,
John

#10 lore raw
Quoted 126 lines

-----Original Message-----
From: John Youn [mailto:[email protected]]
Sent: September-24-15 8:16 PM
To: Roman Bacik; John Youn; Scott Branden; Greg Kroah-Hartman; linux- [email protected]
Cc: [email protected]; bcm-kernel-feedback-list
Subject: Re: [PATCH v3 0/1] USB DWC2 parity fix in isochronous mode

Quoted 34 lines · Roman Bacik
Quoted 34 lines

-----Original Message-----
From: John Youn [mailto:[email protected]]
Sent: September-23-15 9:21 PM
To: Scott Branden; John Youn; Greg Kroah-Hartman; linux- [email protected]; Roman Bacik
Cc: [email protected]; bcm-kernel-feedback-list
Subject: Re: [PATCH v3 0/1] USB DWC2 parity fix in isochronous mode

Quoted 15 lines · Scott Branden

This patch contains a fix for a real world interop problem found when using the Synopsis DWC2 USB controller with isochronous audio as detailed in the commit message.

Changes from v2:
- created s2c_hsotg_chage_ep_iso_parity function to call function
in
3 places in code
- used hsotg->num_of_eps instead of MAX_EPS_CHANNELS

Changes from v1:
- Address code review comments as per previous responses:
- renamed parity_set to has_correct_parity and reorder some logic

Quoted 5 lines

Roman Bacik (1):
usb: dwc2: gadget: parity fix in isochronous mode

 drivers/usb/dwc2/core.h   |  1 +
 drivers/usb/dwc2/gadget.c | 58

++++++++++++++++++++++++++++++++++++++++++-----

Quoted 3 lines
 drivers/usb/dwc2/hw.h     |  1 +
 3 files changed, 54 insertions(+), 6 deletions(-)
Quoted 5 lines
Quoted 5 lines

This seems to break slave mode on my platform. It seems to be dropping a lot of packets. I tried bInterval=4,5,6, ISO OUT. I'll need to take a closer look to determine why. Probably later this week.

Are you able to run in slave mode on your platform? If so can you try it

out?

Quoted 11 lines
Quoted 3 lines

Regards,
John

Our current test procedure is as follows:

Build Linux kernel with:

Device Drivers
- Sound Card Support 'SOUND=y': ALSA 'SND=y'
- Generic sound devices: Dummy (/dev/null) soundcard

'SND_DUMMY=y'

Quoted 6 lines

- USB support 'USB_SUPPORT=y':
DesignWare USB2 DRD Core support 'USB_DWC2=y'
- Gadget only mode 'USB_DWC2_PERIPHERAL=y'
DWC2 Platform 'USB_DWC2_PLATFORM=y'
- USB Gadget Support 'USB_GADGET=y': Audio Gadget 'USB_AUDIO=y'
- PHY Subsystem: Broadcom Kona USB2 PHY Driver

'BCM_KONA_USB2_PHY=y'

Quoted 2 lines

If you have only even hosts, you can change the default micro frame parity

to odd:

Quoted 29 lines
drivers/usb/dwc2/gadget.c +0 -0
index ad45b0b..80bde75 100644 @@ -2709,7 +2709,7 @@ static int

s3c_hsotg_ep_enable(struct usb_ep *ep,

     switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
     case USB_ENDPOINT_XFER_ISOC:
         epctrl |= DXEPCTL_EPTYPE_ISO;
drivers/usb/dwc2/gadget.c +2 -2
-        epctrl |= DXEPCTL_SETEVENFR;
+        epctrl |= DXEPCTL_SETODDFR;
         hs_ep->isochronous = 1;
         if (dir_in)
             hs_ep->periodic = 1;
@@ -2777,7 +2777,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep
 *ep,
 
     /* for non control endpoints, set PID to D0 */
     if (index)
-        epctrl |= DXEPCTL_SETD0PID;
+        epctrl |= DXEPCTL_SETD1PID;
 
     dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n",
         __func__, epctrl);

To test OUT direction:
Host:
aplay -D plughw:2 -r 48000 -f S16_LE tone_48stereo.wav Device:
arecord -D plughw:0 -r 48000 -f S16_LE -c 1 /tmp/rec.pcm

Quoted 7 lines

To test IN direction:
Host:
arecord -D plughw:2 -r 48000 -f S16_LE -c 1 /tmp/rec.pcm Device:
aplay -D plughw:0 -r 48000 -f S16_LE /tmp/rec.pcm

If you would like, we can try to test your procedure provided you send us

enough details.

Quoted 5 lines

Regards,

Roman

I looked at it a bit more and I think there are two issues.

In slave-mode, the xfercomplete interrupt is not used for OUT transfers, so the has_correct_parity flag is never set.

The other issue is that we occasionally get the incomplete interrupt twice in a microframe causing the parity to be set incorrectly for the next frame. Thus we will continuously miss until this occurs again, correcting it.

These two problems in combination cause dropped packets throughout operation.

Quoted 9 lines

If you give me some time I can see if I can fix up this patch to work with slave mode.

I've tried all our hosts here and they are all even hosts, so I tried flipping the default parity. The issue exists in either case.

Regards,
John

Is there a way to recognize we are in slave-mode that we would not flip parity in that case? Thanks,

Roman