linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc2: gadget: Fix GOUTNAK flow for Slave mode.
@ 2021-07-12 10:22 Minas Harutyunyan
  2021-07-12 17:30 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Minas Harutyunyan @ 2021-07-12 10:22 UTC (permalink / raw)
  To: John Youn, Felipe Balbi, Greg Kroah-Hartman, Minas Harutyunyan,
	Vahram Aharonyan, linux-usb
  Cc: Minas Harutyunyan

Because of dwc2_hsotg_ep_stop_xfr() function uses poll
mode, first need to mask GINTSTS_GOUTNAKEFF interrupt.
In Slave mode GINTSTS_GOUTNAKEFF interrupt will be
aserted only after pop OUT NAK status packet from RxFIFO.

In dwc2_hsotg_ep_sethalt() function before setting
DCTL_SGOUTNAK need to unmask GOUTNAKEFF interrupt.

Tested by USBCV CH9 and MSC tests set in Slave, BDMA and DDMA.
All tests are passed.

Fixes: a4f827714539a ("usb: dwc2: gadget: Disable enabled HW endpoint in
dwc2_hsotg_ep_disable")
Fixes: 6070636c4918c ("usb: dwc2: Fix Stalling a Non-Isochronous OUT EP")

Signed-off-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
---
 drivers/usb/dwc2/gadget.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 7352f2720963..77d595738bdd 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3903,9 +3903,27 @@ static void dwc2_hsotg_ep_stop_xfr(struct dwc2_hsotg *hsotg,
 					 __func__);
 		}
 	} else {
+		/* Mask GINTSTS_GOUTNAKEFF interrupt */
+		dwc2_hsotg_disable_gsint(hsotg, GINTSTS_GOUTNAKEFF);
+
 		if (!(dwc2_readl(hsotg, GINTSTS) & GINTSTS_GOUTNAKEFF))
 			dwc2_set_bit(hsotg, DCTL, DCTL_SGOUTNAK);
 
+		if (!using_dma(hsotg)) {
+			/* Wait for GINTSTS_RXFLVL interrupt */
+			if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS,
+						    GINTSTS_RXFLVL, 100)) {
+				dev_warn(hsotg->dev, "%s: timeout GINTSTS.RXFLVL\n",
+					 __func__);
+			} else {
+				/*
+				 * Pop GLOBAL OUT NAK status packet from RxFIFO
+				 * to assert GOUTNAKEFF interrupt
+				 */
+				dwc2_readl(hsotg, GRXSTSP);
+			}
+		}
+
 		/* Wait for global nak to take effect */
 		if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS,
 					    GINTSTS_GOUTNAKEFF, 100))
@@ -4374,6 +4392,9 @@ static int dwc2_hsotg_ep_sethalt(struct usb_ep *ep, int value, bool now)
 		epctl = dwc2_readl(hs, epreg);
 
 		if (value) {
+			/* Unmask GOUTNAKEFF interrupt */
+			dwc2_hsotg_en_gsint(hs, GINTSTS_GOUTNAKEFF);
+
 			if (!(dwc2_readl(hs, GINTSTS) & GINTSTS_GOUTNAKEFF))
 				dwc2_set_bit(hs, DCTL, DCTL_SGOUTNAK);
 			// STALL bit will be set in GOUTNAKEFF interrupt handler

base-commit: 3143ea6b8eee08761709a6c2788216292be46a34
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: dwc2: gadget: Fix GOUTNAK flow for Slave mode.
  2021-07-12 10:22 [PATCH] usb: dwc2: gadget: Fix GOUTNAK flow for Slave mode Minas Harutyunyan
@ 2021-07-12 17:30 ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2021-07-12 17:30 UTC (permalink / raw)
  To: Minas Harutyunyan; +Cc: John Youn, Felipe Balbi, Vahram Aharonyan, linux-usb

On Mon, Jul 12, 2021 at 02:22:09PM +0400, Minas Harutyunyan wrote:
> Because of dwc2_hsotg_ep_stop_xfr() function uses poll
> mode, first need to mask GINTSTS_GOUTNAKEFF interrupt.
> In Slave mode GINTSTS_GOUTNAKEFF interrupt will be
> aserted only after pop OUT NAK status packet from RxFIFO.
> 
> In dwc2_hsotg_ep_sethalt() function before setting
> DCTL_SGOUTNAK need to unmask GOUTNAKEFF interrupt.
> 
> Tested by USBCV CH9 and MSC tests set in Slave, BDMA and DDMA.
> All tests are passed.
> 
> Fixes: a4f827714539a ("usb: dwc2: gadget: Disable enabled HW endpoint in
> dwc2_hsotg_ep_disable")

Please do not wrap this line.

> Fixes: 6070636c4918c ("usb: dwc2: Fix Stalling a Non-Isochronous OUT EP")
> 

No need for a blank line there please.

thanks,

gre gk-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-12 17:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-12 10:22 [PATCH] usb: dwc2: gadget: Fix GOUTNAK flow for Slave mode Minas Harutyunyan
2021-07-12 17:30 ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).