Skip to contentSkip to conversation

USB DWC2 parity fix in isochronous mode

PATCH Superseded Scott Branden 4 participants 8 messages Aug 18, 2015 – Aug 26, 2015

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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.

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

 drivers/usb/dwc2/core.h   |  1 +
 drivers/usb/dwc2/gadget.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/usb/dwc2/hw.h     |  1 +
 3 files changed, 49 insertions(+), 1 deletion(-)
Signature · 1 line
2.4.6
#1 lore raw

PATCH 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 | 48 ++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/usb/dwc2/hw.h     |  1 +
 3 files changed, 49 insertions(+), 1 deletion(-)
drivers/usb/dwc2/core.h +1 -0
index 0ed87620..954d1cd 100644
@@ -150,6 +150,7 @@ struct s3c_hsotg_ep {
 	unsigned int            periodic:1;
 	unsigned int            isochronous:1;
 	unsigned int            send_zlp:1;
+	unsigned int            parity_set:1;
 
 	char                    name[10];
 };
drivers/usb/dwc2/gadget.c +47 -1

72 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.4.6
#2 lore raw

Re: [PATCH 1/1] usb: dwc2: gadget: parity fix in isochronous mode

Quoted 105 lines · Scott Branden

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 | 48 ++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/usb/dwc2/hw.h     |  1 +
 3 files changed, 49 insertions(+), 1 deletion(-)
drivers/usb/dwc2/core.h +1 -0
index 0ed87620..954d1cd 100644
@@ -150,6 +150,7 @@ struct s3c_hsotg_ep {
 	unsigned int            periodic:1;
 	unsigned int            isochronous:1;
 	unsigned int            send_zlp:1;
+	unsigned int            parity_set:1;
 
 	char                    name[10];
 };
drivers/usb/dwc2/gadget.c +46 -1
index 4d47b7c..28e4393 100644
@@ -1954,6 +1954,8 @@ static void s3c_hsotg_epint(struct dwc2_hsotg *hsotg, unsigned int idx,
 		ints &= ~DXEPINT_XFERCOMPL;
 
 	if (ints & DXEPINT_XFERCOMPL) {
+		if (hs_ep->isochronous && !hs_ep->parity_set)
+			hs_ep->parity_set = 1;
 		if (hs_ep->isochronous && hs_ep->interval == 1) {
 			if (ctrl & DXEPCTL_EOFRNUM)
 				ctrl |= DXEPCTL_SETEVENFR;
@@ -2316,7 +2318,8 @@ void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
 		GINTSTS_CONIDSTSCHNG | GINTSTS_USBRST |
 		GINTSTS_RESETDET | GINTSTS_ENUMDONE |
 		GINTSTS_OTGINT | GINTSTS_USBSUSP |
-		GINTSTS_WKUPINT,
+		GINTSTS_WKUPINT |
+		GINTSTS_INCOMPL_SOIN | GINTSTS_INCOMPL_SOOUT,
 		hsotg->regs + GINTMSK);
 
 	if (using_dma(hsotg))
@@ -2581,6 +2584,48 @@ irq_retry:
 		s3c_hsotg_dump(hsotg);
 	}
 
+	if (gintsts & GINTSTS_INCOMPL_SOIN) {
+		u32 idx;
+		struct s3c_hsotg_ep *hs_ep;
+
+		dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOIN\n", __func__);
+		for (idx = 1; idx < MAX_EPS_CHANNELS; idx++) {
+			hs_ep = hsotg->eps_in[idx];
+			if (hs_ep->isochronous && !hs_ep->parity_set) {
+				u32 epctl_reg = DIEPCTL(idx);
+				u32 ctrl = readl(hsotg->regs + epctl_reg);
+
+				if (ctrl & DXEPCTL_EOFRNUM)
+					ctrl |= DXEPCTL_SETEVENFR;
+				else
+					ctrl |= DXEPCTL_SETODDFR;
+				writel(ctrl, hsotg->regs + epctl_reg);
+			}
+		}
+		writel(GINTSTS_INCOMPL_SOIN, hsotg->regs + GINTSTS);
+	}
+
+	if (gintsts & GINTSTS_INCOMPL_SOOUT) {
+		u32 idx;
+		struct s3c_hsotg_ep *hs_ep;
+
+		dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOOUT\n", __func__);
+		for (idx = 1; idx < MAX_EPS_CHANNELS; idx++) {
+			hs_ep = hsotg->eps_out[idx];
+			if (hs_ep->isochronous && !hs_ep->parity_set) {
+				u32 epctl_reg = DOEPCTL(idx);
+				u32 ctrl = readl(hsotg->regs + epctl_reg);
+
+				if (ctrl & DXEPCTL_EOFRNUM)
+					ctrl |= DXEPCTL_SETEVENFR;
+				else
+					ctrl |= DXEPCTL_SETODDFR;
+				writel(ctrl, hsotg->regs + epctl_reg);
+			}
+		}
+		writel(GINTSTS_INCOMPL_SOOUT, hsotg->regs + GINTSTS);
+	}
+
 	/*
 	 * if we've had fifo events, we should try and go around the
 	 * loop again to see if there's any point in returning yet.

drivers/usb/dwc2/gadget.c static int s3c_hsotg_ep_enable(struct usb_ep *ep, · line 2715

Quoted 4 lines
drivers/usb/dwc2/gadget.c +1 -0
@@ -2667,6 +2712,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
 	hs_ep->periodic = 0;
 	hs_ep->halted = 0;
 	hs_ep->interval = desc->bInterval;
+	hs_ep->parity_set = 0;

I'm not quite sure what the parity_set flag does in this patch. Shouldn't you be able to just toggle the even/odd frame when you get the interrupt?

John

#3 lore raw

RE: [PATCH 1/1] usb: dwc2: gadget: parity fix in isochronous mode

Quoted 131 lines

-----Original Message-----
From: John Youn [mailto:[email protected]]
Sent: August-25-15 2:52 PM
To: Scott Branden; John Youn; Greg Kroah-Hartman; linux- [email protected]
Cc: [email protected]; bcm-kernel-feedback-list; Roman Bacik
Subject: Re: [PATCH 1/1] usb: dwc2: gadget: parity fix in isochronous mode

Quoted 5 lines · Scott Branden

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.

Quoted 4 lines

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

Quoted 8 lines
---
 drivers/usb/dwc2/core.h   |  1 +
 drivers/usb/dwc2/gadget.c | 48

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

drivers/usb/dwc2/gadget.c static void s3c_hsotg_epint(struct dwc2_hsotg

Quoted 20 lines
 drivers/usb/dwc2/hw.h     |  1 +
 3 files changed, 49 insertions(+), 1 deletion(-)
drivers/usb/dwc2/core.h index renamed from drivers/usb/dwc2/core.h +0 -0

0ed87620..954d1cd 100644

drivers/usb/dwc2/core.h +1 -0
@@ -150,6 +150,7 @@ struct s3c_hsotg_ep {
 	unsigned int            periodic:1;
 	unsigned int            isochronous:1;
 	unsigned int            send_zlp:1;
+	unsigned int            parity_set:1;
 
 	char                    name[10];
 };
drivers/usb/dwc2/gadget.c +0 -0
index 4d47b7c..28e4393 100644
@@ -1954,6 +1954,8 @@ static void s3c_hsotg_epint(struct dwc2_hsotg

*hsotg, unsigned int idx,

drivers/usb/dwc2/gadget.c void s3c_hsotg_core_init_disconnected(struct

Quoted 9 lines
drivers/usb/dwc2/gadget.c +2 -0
 		ints &= ~DXEPINT_XFERCOMPL;
 
 	if (ints & DXEPINT_XFERCOMPL) {
+		if (hs_ep->isochronous && !hs_ep->parity_set)
+			hs_ep->parity_set = 1;
 		if (hs_ep->isochronous && hs_ep->interval == 1) {
 			if (ctrl & DXEPCTL_EOFRNUM)
 				ctrl |= DXEPCTL_SETEVENFR;
@@ -2316,7 +2318,8 @@ void s3c_hsotg_core_init_disconnected(struct

dwc2_hsotg *hsotg,

Quoted 10 lines
drivers/usb/dwc2/gadget.c +2 -1
 		GINTSTS_CONIDSTSCHNG | GINTSTS_USBRST |
 		GINTSTS_RESETDET | GINTSTS_ENUMDONE |
 		GINTSTS_OTGINT | GINTSTS_USBSUSP |
-		GINTSTS_WKUPINT,
+		GINTSTS_WKUPINT |
+		GINTSTS_INCOMPL_SOIN | GINTSTS_INCOMPL_SOOUT,
 		hsotg->regs + GINTMSK);
 
 	if (using_dma(hsotg))

drivers/usb/dwc2/gadget.c irq_retry: · line 2591

Quoted 8 lines
drivers/usb/dwc2/gadget.c +5 -0
@@ -2581,6 +2584,48 @@ irq_retry:
 		s3c_hsotg_dump(hsotg);
 	}
 
+	if (gintsts & GINTSTS_INCOMPL_SOIN) {
+		u32 idx;
+		struct s3c_hsotg_ep *hs_ep;
+
+		dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOIN\n",

__func__);

Quoted 11 lines
drivers/usb/dwc2/gadget.c +11 -0
+		for (idx = 1; idx < MAX_EPS_CHANNELS; idx++) {
+			hs_ep = hsotg->eps_in[idx];
+			if (hs_ep->isochronous && !hs_ep->parity_set) {
+				u32 epctl_reg = DIEPCTL(idx);
+				u32 ctrl = readl(hsotg->regs + epctl_reg);
+
+				if (ctrl & DXEPCTL_EOFRNUM)
+					ctrl |= DXEPCTL_SETEVENFR;
+				else
+					ctrl |= DXEPCTL_SETODDFR;
+				writel(ctrl, hsotg->regs + epctl_reg);

drivers/usb/dwc2/gadget.c irq_retry:

Quoted 10 lines
drivers/usb/dwc2/gadget.c +10 -0
+			}
+		}
+		writel(GINTSTS_INCOMPL_SOIN, hsotg->regs + GINTSTS);
+	}
+
+	if (gintsts & GINTSTS_INCOMPL_SOOUT) {
+		u32 idx;
+		struct s3c_hsotg_ep *hs_ep;
+
+		dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOOUT\n",

__func__);

drivers/usb/dwc2/gadget.c static int s3c_hsotg_ep_enable(struct usb_ep

Quoted 20 lines
drivers/usb/dwc2/gadget.c +16 -0
+		for (idx = 1; idx < MAX_EPS_CHANNELS; idx++) {
+			hs_ep = hsotg->eps_out[idx];
+			if (hs_ep->isochronous && !hs_ep->parity_set) {
+				u32 epctl_reg = DOEPCTL(idx);
+				u32 ctrl = readl(hsotg->regs + epctl_reg);
+
+				if (ctrl & DXEPCTL_EOFRNUM)
+					ctrl |= DXEPCTL_SETEVENFR;
+				else
+					ctrl |= DXEPCTL_SETODDFR;
+				writel(ctrl, hsotg->regs + epctl_reg);
+			}
+		}
+		writel(GINTSTS_INCOMPL_SOOUT, hsotg->regs + GINTSTS);
+	}
+
 	/*
 	 * if we've had fifo events, we should try and go around the
 	 * loop again to see if there's any point in returning yet.
@@ -2667,6 +2712,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep

*ep,

drivers/usb/dwc2/gadget.c static int s3c_hsotg_ep_enable(struct usb_ep *ep, · line 2715

Quoted 4 lines
drivers/usb/dwc2/gadget.c +1 -0
 	hs_ep->periodic = 0;
 	hs_ep->halted = 0;
 	hs_ep->interval = desc->bInterval;
+	hs_ep->parity_set = 0;

I'm not quite sure what the parity_set flag does in this patch. Shouldn't you be able to just toggle the even/odd frame when you get the interrupt?

Quoted 2 lines

John

When Transfer Complete interrupt is received, we have the correct parity. Therefore we set the flag and we stop toggling. The parity_set flag indicates whether we have the correct parity set. Regards,

Roman

#4 lore raw

Re: [PATCH 1/1] usb: dwc2: gadget: parity fix in isochronous mode

Quoted 49 lines · Roman Bacik
Quoted 49 lines

-----Original Message-----
From: John Youn [mailto:[email protected]]
Sent: August-25-15 2:52 PM
To: Scott Branden; John Youn; Greg Kroah-Hartman; linux- [email protected]
Cc: [email protected]; bcm-kernel-feedback-list; Roman Bacik
Subject: Re: [PATCH 1/1] usb: dwc2: gadget: parity fix in isochronous mode

Quoted 5 lines · Scott Branden

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.

Quoted 4 lines

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

Quoted 8 lines
---
 drivers/usb/dwc2/core.h   |  1 +
 drivers/usb/dwc2/gadget.c | 48

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

drivers/usb/dwc2/gadget.c static void s3c_hsotg_epint(struct dwc2_hsotg

Quoted 20 lines
 drivers/usb/dwc2/hw.h     |  1 +
 3 files changed, 49 insertions(+), 1 deletion(-)
drivers/usb/dwc2/core.h index renamed from drivers/usb/dwc2/core.h +0 -0

0ed87620..954d1cd 100644

drivers/usb/dwc2/core.h +1 -0
@@ -150,6 +150,7 @@ struct s3c_hsotg_ep {
 	unsigned int            periodic:1;
 	unsigned int            isochronous:1;
 	unsigned int            send_zlp:1;
+	unsigned int            parity_set:1;
 
 	char                    name[10];
 };
drivers/usb/dwc2/gadget.c +0 -0
index 4d47b7c..28e4393 100644
@@ -1954,6 +1954,8 @@ static void s3c_hsotg_epint(struct dwc2_hsotg

*hsotg, unsigned int idx,

Quoted 5 lines
Quoted 5 lines

drivers/usb/dwc2/gadget.c static void s3c_hsotg_epint(struct dwc2_hsotg *hsotg, unsigned int idx, · line 1958

Quoted 5 lines
drivers/usb/dwc2/gadget.c +2 -0
 		ints &= ~DXEPINT_XFERCOMPL;
 
 	if (ints & DXEPINT_XFERCOMPL) {
+		if (hs_ep->isochronous && !hs_ep->parity_set)
+			hs_ep->parity_set = 1;

it shouldn't be a problem to set the flag which was already set, so this could be simplified to:

		hs_ep->has_correct_parity = !!hs_ep0>isochronous;
Quoted 11 lines
Quoted 11 lines

drivers/usb/dwc2/gadget.c void s3c_hsotg_core_init_disconnected(struct

Quoted 4 lines
drivers/usb/dwc2/gadget.c +0 -0
 		if (hs_ep->isochronous && hs_ep->interval == 1) {
 			if (ctrl & DXEPCTL_EOFRNUM)
 				ctrl |= DXEPCTL_SETEVENFR;
@@ -2316,7 +2318,8 @@ void s3c_hsotg_core_init_disconnected(struct

dwc2_hsotg *hsotg,

drivers/usb/dwc2/gadget.c void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg, · line 2322

Quoted 6 lines
drivers/usb/dwc2/gadget.c +2 -1
 		GINTSTS_CONIDSTSCHNG | GINTSTS_USBRST |
 		GINTSTS_RESETDET | GINTSTS_ENUMDONE |
 		GINTSTS_OTGINT | GINTSTS_USBSUSP |
-		GINTSTS_WKUPINT,
+		GINTSTS_WKUPINT |
+		GINTSTS_INCOMPL_SOIN | GINTSTS_INCOMPL_SOOUT,

why the two extra bits ? What are they doing ?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/usb/dwc2/gadget.c +0 -0
 		hsotg->regs + GINTMSK);
 
 	if (using_dma(hsotg))
@@ -2581,6 +2584,48 @@ irq_retry:
 		s3c_hsotg_dump(hsotg);
 	}
 
Quoted 7 lines
Quoted 7 lines

drivers/usb/dwc2/gadget.c irq_retry:

Quoted 5 lines
drivers/usb/dwc2/gadget.c +5 -0
+	if (gintsts & GINTSTS_INCOMPL_SOIN) {
+		u32 idx;
+		struct s3c_hsotg_ep *hs_ep;
+
+		dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOIN\n",

__func__);

drivers/usb/dwc2/gadget.c irq_retry: · line 2592

Quoted 1 line
drivers/usb/dwc2/gadget.c +1 -0
+		for (idx = 1; idx < MAX_EPS_CHANNELS; idx++) {
			u32 epctl_reg;
			u32 ctrl;
Quoted 1 line
Quoted 1 line

drivers/usb/dwc2/gadget.c irq_retry: · line 2593

Quoted 1 line
drivers/usb/dwc2/gadget.c +1 -0
+			hs_ep = hsotg->eps_in[idx];

you can decrease some indentation here:

			if (!hs_ep->isochronous)
				continue;

			if (hs_ep->has_correct_parity)
				continue;

			epctl_reg = DIEPCTL(idx);
			ctrl = readl(hsotg->regs + epctl_reg);

			if (ctrl & DXEPCTL_EOFRNUM)
				ctrl |= DXEPCTL_SETEVENFR;
			else
				ctrl |= DXEPCTL_SETODDFR;
			writel(ctrl, hsotg->regs + epctl_reg);

ditto to the other loop below

<snip>

Quoted 10 lines
Quoted 6 lines

I'm not quite sure what the parity_set flag does in this patch. Shouldn't you be able to just toggle the even/odd frame when you get the interrupt?

John

When Transfer Complete interrupt is received, we have the correct parity. Therefore we set the flag and we stop toggling. The parity_set flag indicates whether we have the correct parity set.

then how about calling it has_correct_parity instead ?

Signature · 1 line
balbi
#5 lore raw

RE: [PATCH 1/1] usb: dwc2: gadget: parity fix in isochronous mode

Quoted 66 lines

-----Original Message-----
From: Felipe Balbi [mailto:[email protected]]
Sent: August-25-15 3:36 PM
To: Roman Bacik
Cc: John Youn; Scott Branden; Greg Kroah-Hartman; linux- [email protected]; [email protected]; bcm-kernel-feedback- list
Subject: Re: [PATCH 1/1] usb: dwc2: gadget: parity fix in isochronous mode

Quoted 13 lines · Roman Bacik
Quoted 13 lines

-----Original Message-----
From: John Youn [mailto:[email protected]]
Sent: August-25-15 2:52 PM
To: Scott Branden; John Youn; Greg Kroah-Hartman; linux- [email protected]
Cc: [email protected]; bcm-kernel-feedback-list; Roman Bacik
Subject: Re: [PATCH 1/1] usb: dwc2: gadget: parity fix in isochronous mode

Quoted 2 lines · Scott Branden

From: Roman Bacik <[email protected]>

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

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.

Quoted 3 lines

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

received.

Quoted 34 lines
Quoted 34 lines
Quoted 9 lines
---
 drivers/usb/dwc2/core.h   |  1 +
 drivers/usb/dwc2/gadget.c | 48

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

Quoted 20 lines
 drivers/usb/dwc2/hw.h     |  1 +
 3 files changed, 49 insertions(+), 1 deletion(-)
drivers/usb/dwc2/core.h +1 -0
index 0ed87620..954d1cd 100644
@@ -150,6 +150,7 @@ struct s3c_hsotg_ep {
 	unsigned int            periodic:1;
 	unsigned int            isochronous:1;
 	unsigned int            send_zlp:1;
+	unsigned int            parity_set:1;
 
 	char                    name[10];
 };
drivers/usb/dwc2/gadget.c +0 -0
index 4d47b7c..28e4393 100644
@@ -1954,6 +1954,8 @@ static void s3c_hsotg_epint(struct
Quoted 1 line

dwc2_hsotg

*hsotg, unsigned int idx,

Quoted 2 lines

ints &= ~DXEPINT_XFERCOMPL;

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines

drivers/usb/dwc2/gadget.c static void s3c_hsotg_epint(struct dwc2_hsotg *hsotg, unsigned int idx, · line 1958

Quoted 3 lines
drivers/usb/dwc2/gadget.c +2 -0
 	if (ints & DXEPINT_XFERCOMPL) {
+		if (hs_ep->isochronous && !hs_ep->parity_set)
+			hs_ep->parity_set = 1;

it shouldn't be a problem to set the flag which was already set, so this could be simplified to:

		hs_ep->has_correct_parity = !!hs_ep0>isochronous;

It can be simplified to:

		hs_ep->has_correct_parity = 1;

I just thought that the original shows better what we are trying to do. I do not mind to simplify it and remove the condition.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/usb/dwc2/gadget.c void s3c_hsotg_core_init_disconnected(struct

Quoted 4 lines
drivers/usb/dwc2/gadget.c +0 -0
 		if (hs_ep->isochronous && hs_ep->interval == 1) {
 			if (ctrl & DXEPCTL_EOFRNUM)
 				ctrl |= DXEPCTL_SETEVENFR;
@@ -2316,7 +2318,8 @@ void s3c_hsotg_core_init_disconnected(struct

dwc2_hsotg *hsotg,

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

drivers/usb/dwc2/gadget.c void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg, · line 2322

Quoted 6 lines
drivers/usb/dwc2/gadget.c +2 -1
 		GINTSTS_CONIDSTSCHNG | GINTSTS_USBRST |
 		GINTSTS_RESETDET | GINTSTS_ENUMDONE |
 		GINTSTS_OTGINT | GINTSTS_USBSUSP |
-		GINTSTS_WKUPINT,
+		GINTSTS_WKUPINT |
+		GINTSTS_INCOMPL_SOIN | GINTSTS_INCOMPL_SOOUT,

why the two extra bits ? What are they doing ?

This fix uses Incomplete Periodic Transfer interrupt (GINTSTS_INCOMPL) to toggle between even and odd parity until the Transfer Complete interrupt is received. We also need to set correct parity on both IN and OUT endpoints.

Quoted 38 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/usb/dwc2/gadget.c +0 -0
 		hsotg->regs + GINTMSK);
 
 	if (using_dma(hsotg))
@@ -2581,6 +2584,48 @@ irq_retry:
 		s3c_hsotg_dump(hsotg);
 	}
 
Quoted 7 lines
Quoted 7 lines

drivers/usb/dwc2/gadget.c irq_retry:

Quoted 5 lines
drivers/usb/dwc2/gadget.c +5 -0
+	if (gintsts & GINTSTS_INCOMPL_SOIN) {
+		u32 idx;
+		struct s3c_hsotg_ep *hs_ep;
+
+		dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOIN\n",

__func__);

drivers/usb/dwc2/gadget.c irq_retry: · line 2592

Quoted 1 line
drivers/usb/dwc2/gadget.c +1 -0
+		for (idx = 1; idx < MAX_EPS_CHANNELS; idx++) {
			u32 epctl_reg;
			u32 ctrl;
Quoted 1 line
Quoted 1 line

drivers/usb/dwc2/gadget.c irq_retry: · line 2593

Quoted 1 line
drivers/usb/dwc2/gadget.c +1 -0
+			hs_ep = hsotg->eps_in[idx];

you can decrease some indentation here:

			if (!hs_ep->isochronous)
				continue;

			if (hs_ep->has_correct_parity)
				continue;

			epctl_reg = DIEPCTL(idx);
			ctrl = readl(hsotg->regs + epctl_reg);

			if (ctrl & DXEPCTL_EOFRNUM)
				ctrl |= DXEPCTL_SETEVENFR;
			else
				ctrl |= DXEPCTL_SETODDFR;
			writel(ctrl, hsotg->regs + epctl_reg);
Quoted 4 lines

ditto to the other loop below

<snip>

ok

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

I'm not quite sure what the parity_set flag does in this patch. Shouldn't you be able to just toggle the even/odd frame when you get the interrupt?

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

John

When Transfer Complete interrupt is received, we have the correct parity. Therefore we set the flag and we stop toggling. The parity_set flag indicates whether we have the correct parity set.

then how about calling it has_correct_parity instead ?

ok

Quoted 2 lines

--
balbi

Roman

#6 lore raw

Re: [PATCH 1/1] usb: dwc2: gadget: parity fix in isochronous mode

In reply to Roman Bacik
Quoted 131 lines · Roman Bacik
Quoted 131 lines

-----Original Message-----
From: John Youn [mailto:[email protected]]
Sent: August-25-15 2:52 PM
To: Scott Branden; John Youn; Greg Kroah-Hartman; linux- [email protected]
Cc: [email protected]; bcm-kernel-feedback-list; Roman Bacik
Subject: Re: [PATCH 1/1] usb: dwc2: gadget: parity fix in isochronous mode

Quoted 5 lines · Scott Branden

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.

Quoted 4 lines

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

Quoted 8 lines
---
 drivers/usb/dwc2/core.h   |  1 +
 drivers/usb/dwc2/gadget.c | 48

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

drivers/usb/dwc2/gadget.c static void s3c_hsotg_epint(struct dwc2_hsotg

Quoted 20 lines
 drivers/usb/dwc2/hw.h     |  1 +
 3 files changed, 49 insertions(+), 1 deletion(-)
drivers/usb/dwc2/core.h index renamed from drivers/usb/dwc2/core.h +0 -0

0ed87620..954d1cd 100644

drivers/usb/dwc2/core.h +1 -0
@@ -150,6 +150,7 @@ struct s3c_hsotg_ep {
 	unsigned int            periodic:1;
 	unsigned int            isochronous:1;
 	unsigned int            send_zlp:1;
+	unsigned int            parity_set:1;
 
 	char                    name[10];
 };
drivers/usb/dwc2/gadget.c +0 -0
index 4d47b7c..28e4393 100644
@@ -1954,6 +1954,8 @@ static void s3c_hsotg_epint(struct dwc2_hsotg

*hsotg, unsigned int idx,

drivers/usb/dwc2/gadget.c void s3c_hsotg_core_init_disconnected(struct

Quoted 9 lines
drivers/usb/dwc2/gadget.c +2 -0
 		ints &= ~DXEPINT_XFERCOMPL;
 
 	if (ints & DXEPINT_XFERCOMPL) {
+		if (hs_ep->isochronous && !hs_ep->parity_set)
+			hs_ep->parity_set = 1;
 		if (hs_ep->isochronous && hs_ep->interval == 1) {
 			if (ctrl & DXEPCTL_EOFRNUM)
 				ctrl |= DXEPCTL_SETEVENFR;
@@ -2316,7 +2318,8 @@ void s3c_hsotg_core_init_disconnected(struct

dwc2_hsotg *hsotg,

Quoted 10 lines
drivers/usb/dwc2/gadget.c +2 -1
 		GINTSTS_CONIDSTSCHNG | GINTSTS_USBRST |
 		GINTSTS_RESETDET | GINTSTS_ENUMDONE |
 		GINTSTS_OTGINT | GINTSTS_USBSUSP |
-		GINTSTS_WKUPINT,
+		GINTSTS_WKUPINT |
+		GINTSTS_INCOMPL_SOIN | GINTSTS_INCOMPL_SOOUT,
 		hsotg->regs + GINTMSK);
 
 	if (using_dma(hsotg))

drivers/usb/dwc2/gadget.c irq_retry: · line 2591

Quoted 8 lines
drivers/usb/dwc2/gadget.c +5 -0
@@ -2581,6 +2584,48 @@ irq_retry:
 		s3c_hsotg_dump(hsotg);
 	}
 
+	if (gintsts & GINTSTS_INCOMPL_SOIN) {
+		u32 idx;
+		struct s3c_hsotg_ep *hs_ep;
+
+		dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOIN\n",

__func__);

Quoted 11 lines
drivers/usb/dwc2/gadget.c +11 -0
+		for (idx = 1; idx < MAX_EPS_CHANNELS; idx++) {
+			hs_ep = hsotg->eps_in[idx];
+			if (hs_ep->isochronous && !hs_ep->parity_set) {
+				u32 epctl_reg = DIEPCTL(idx);
+				u32 ctrl = readl(hsotg->regs + epctl_reg);
+
+				if (ctrl & DXEPCTL_EOFRNUM)
+					ctrl |= DXEPCTL_SETEVENFR;
+				else
+					ctrl |= DXEPCTL_SETODDFR;
+				writel(ctrl, hsotg->regs + epctl_reg);

drivers/usb/dwc2/gadget.c irq_retry:

Quoted 10 lines
drivers/usb/dwc2/gadget.c +10 -0
+			}
+		}
+		writel(GINTSTS_INCOMPL_SOIN, hsotg->regs + GINTSTS);
+	}
+
+	if (gintsts & GINTSTS_INCOMPL_SOOUT) {
+		u32 idx;
+		struct s3c_hsotg_ep *hs_ep;
+
+		dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOOUT\n",

__func__);

drivers/usb/dwc2/gadget.c static int s3c_hsotg_ep_enable(struct usb_ep

Quoted 20 lines
drivers/usb/dwc2/gadget.c +16 -0
+		for (idx = 1; idx < MAX_EPS_CHANNELS; idx++) {
+			hs_ep = hsotg->eps_out[idx];
+			if (hs_ep->isochronous && !hs_ep->parity_set) {
+				u32 epctl_reg = DOEPCTL(idx);
+				u32 ctrl = readl(hsotg->regs + epctl_reg);
+
+				if (ctrl & DXEPCTL_EOFRNUM)
+					ctrl |= DXEPCTL_SETEVENFR;
+				else
+					ctrl |= DXEPCTL_SETODDFR;
+				writel(ctrl, hsotg->regs + epctl_reg);
+			}
+		}
+		writel(GINTSTS_INCOMPL_SOOUT, hsotg->regs + GINTSTS);
+	}
+
 	/*
 	 * if we've had fifo events, we should try and go around the
 	 * loop again to see if there's any point in returning yet.
@@ -2667,6 +2712,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep

*ep,

drivers/usb/dwc2/gadget.c static int s3c_hsotg_ep_enable(struct usb_ep *ep, · line 2715

Quoted 4 lines
drivers/usb/dwc2/gadget.c +1 -0
 	hs_ep->periodic = 0;
 	hs_ep->halted = 0;
 	hs_ep->interval = desc->bInterval;
+	hs_ep->parity_set = 0;

I'm not quite sure what the parity_set flag does in this patch. Shouldn't you be able to just toggle the even/odd frame when you get the interrupt?

Quoted 8 lines
Quoted 2 lines

John

When Transfer Complete interrupt is received, we have the correct parity. Therefore we set the flag and we stop toggling. The parity_set flag indicates whether we have the correct parity set. Regards,

Roman

I'm not sure that "parity" is the proper term in this context but I can't think of a more concise way to phrase it.

What if the host switches again some time after the first xfer complete?

What function or gadget driver are you using to test this? Did you test both the ISO IN and OUT case?

John

#7 lore raw

RE: [PATCH 1/1] usb: dwc2: gadget: parity fix in isochronous mode

Quoted 158 lines

-----Original Message-----
From: John Youn [mailto:[email protected]]
Sent: August-25-15 7:06 PM
To: Roman Bacik; John Youn; Scott Branden; Greg Kroah-Hartman; linux- [email protected]
Cc: [email protected]; bcm-kernel-feedback-list
Subject: Re: [PATCH 1/1] usb: dwc2: gadget: parity fix in isochronous mode

Quoted 13 lines · Roman Bacik
Quoted 13 lines

-----Original Message-----
From: John Youn [mailto:[email protected]]
Sent: August-25-15 2:52 PM
To: Scott Branden; John Youn; Greg Kroah-Hartman; linux- [email protected]
Cc: [email protected]; bcm-kernel-feedback-list; Roman Bacik
Subject: Re: [PATCH 1/1] usb: dwc2: gadget: parity fix in isochronous mode

Quoted 2 lines · Scott Branden

From: Roman Bacik <[email protected]>

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

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.

Quoted 3 lines

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

received.

Quoted 113 lines
Quoted 113 lines
Quoted 9 lines
---
 drivers/usb/dwc2/core.h   |  1 +
 drivers/usb/dwc2/gadget.c | 48

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

drivers/usb/dwc2/gadget.c static void s3c_hsotg_epint(struct dwc2_hsotg

Quoted 20 lines
 drivers/usb/dwc2/hw.h     |  1 +
 3 files changed, 49 insertions(+), 1 deletion(-)
drivers/usb/dwc2/core.h index renamed from drivers/usb/dwc2/core.h +0 -0

0ed87620..954d1cd 100644

drivers/usb/dwc2/core.h +1 -0
@@ -150,6 +150,7 @@ struct s3c_hsotg_ep {
 	unsigned int            periodic:1;
 	unsigned int            isochronous:1;
 	unsigned int            send_zlp:1;
+	unsigned int            parity_set:1;
 
 	char                    name[10];
 };
drivers/usb/dwc2/gadget.c +0 -0
index 4d47b7c..28e4393 100644
@@ -1954,6 +1954,8 @@ static void s3c_hsotg_epint(struct dwc2_hsotg

*hsotg, unsigned int idx,

drivers/usb/dwc2/gadget.c void s3c_hsotg_core_init_disconnected(struct

Quoted 9 lines
drivers/usb/dwc2/gadget.c +2 -0
 		ints &= ~DXEPINT_XFERCOMPL;
 
 	if (ints & DXEPINT_XFERCOMPL) {
+		if (hs_ep->isochronous && !hs_ep->parity_set)
+			hs_ep->parity_set = 1;
 		if (hs_ep->isochronous && hs_ep->interval == 1) {
 			if (ctrl & DXEPCTL_EOFRNUM)
 				ctrl |= DXEPCTL_SETEVENFR;
@@ -2316,7 +2318,8 @@ void s3c_hsotg_core_init_disconnected(struct

dwc2_hsotg *hsotg,

Quoted 10 lines
drivers/usb/dwc2/gadget.c +2 -1
 		GINTSTS_CONIDSTSCHNG | GINTSTS_USBRST |
 		GINTSTS_RESETDET | GINTSTS_ENUMDONE |
 		GINTSTS_OTGINT | GINTSTS_USBSUSP |
-		GINTSTS_WKUPINT,
+		GINTSTS_WKUPINT |
+		GINTSTS_INCOMPL_SOIN | GINTSTS_INCOMPL_SOOUT,
 		hsotg->regs + GINTMSK);
 
 	if (using_dma(hsotg))

drivers/usb/dwc2/gadget.c irq_retry: · line 2591

Quoted 8 lines
drivers/usb/dwc2/gadget.c +5 -0
@@ -2581,6 +2584,48 @@ irq_retry:
 		s3c_hsotg_dump(hsotg);
 	}
 
+	if (gintsts & GINTSTS_INCOMPL_SOIN) {
+		u32 idx;
+		struct s3c_hsotg_ep *hs_ep;
+
+		dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOIN\n",

__func__);

Quoted 11 lines
drivers/usb/dwc2/gadget.c +11 -0
+		for (idx = 1; idx < MAX_EPS_CHANNELS; idx++) {
+			hs_ep = hsotg->eps_in[idx];
+			if (hs_ep->isochronous && !hs_ep->parity_set) {
+				u32 epctl_reg = DIEPCTL(idx);
+				u32 ctrl = readl(hsotg->regs + epctl_reg);
+
+				if (ctrl & DXEPCTL_EOFRNUM)
+					ctrl |= DXEPCTL_SETEVENFR;
+				else
+					ctrl |= DXEPCTL_SETODDFR;
+				writel(ctrl, hsotg->regs + epctl_reg);

drivers/usb/dwc2/gadget.c irq_retry:

Quoted 10 lines
drivers/usb/dwc2/gadget.c +10 -0
+			}
+		}
+		writel(GINTSTS_INCOMPL_SOIN, hsotg->regs + GINTSTS);
+	}
+
+	if (gintsts & GINTSTS_INCOMPL_SOOUT) {
+		u32 idx;
+		struct s3c_hsotg_ep *hs_ep;
+
+		dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOOUT\n",

__func__);

drivers/usb/dwc2/gadget.c static int s3c_hsotg_ep_enable(struct usb_ep

Quoted 20 lines
drivers/usb/dwc2/gadget.c +16 -0
+		for (idx = 1; idx < MAX_EPS_CHANNELS; idx++) {
+			hs_ep = hsotg->eps_out[idx];
+			if (hs_ep->isochronous && !hs_ep->parity_set) {
+				u32 epctl_reg = DOEPCTL(idx);
+				u32 ctrl = readl(hsotg->regs + epctl_reg);
+
+				if (ctrl & DXEPCTL_EOFRNUM)
+					ctrl |= DXEPCTL_SETEVENFR;
+				else
+					ctrl |= DXEPCTL_SETODDFR;
+				writel(ctrl, hsotg->regs + epctl_reg);
+			}
+		}
+		writel(GINTSTS_INCOMPL_SOOUT, hsotg->regs + GINTSTS);
+	}
+
 	/*
 	 * if we've had fifo events, we should try and go around the
 	 * loop again to see if there's any point in returning yet.
@@ -2667,6 +2712,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep

*ep,

drivers/usb/dwc2/gadget.c static int s3c_hsotg_ep_enable(struct usb_ep *ep, · line 2715

Quoted 4 lines
drivers/usb/dwc2/gadget.c +1 -0
 	hs_ep->periodic = 0;
 	hs_ep->halted = 0;
 	hs_ep->interval = desc->bInterval;
+	hs_ep->parity_set = 0;

I'm not quite sure what the parity_set flag does in this patch. Shouldn't you be able to just toggle the even/odd frame when you get the interrupt?

Quoted 4 lines
Quoted 2 lines

John

When Transfer Complete interrupt is received, we have the correct parity.

Therefore we set the flag and we stop toggling. The parity_set flag indicates whether we have the correct parity set.

Quoted 4 lines

Regards,

Roman

I'm not sure that "parity" is the proper term in this context but I can't think of a more concise way to phrase it.

Quoted 8 lines

What if the host switches again some time after the first xfer complete?

What function or gadget driver are you using to test this? Did you test both the ISO IN and OUT case?

John

This patch is related to isochronous or periodic transfers. So server uses the same microframe number and hence parity for transfers. I tested both IN and OUT directions using audio gadget on Altera SocKit and Broadcom development boards.

Regards,

Roman