From: Tony Lindgren <tony@atomide.com>
To: linux-omap-open-source@linux.omap.com
Subject: [PATCH] musb_hdrc: Avoid host babble by checking tx fifo
Date: Thu, 3 May 2007 16:41:58 +0000 [thread overview]
Message-ID: <11782105232838-git-send-email-tony@atomide.com> (raw)
In-Reply-To: <117821052378-git-send-email-tony@atomide.com>
Running a tusb6010 system in host mode would fail with
testusb -a -t12 -c1 most of the time with BABBLE errors.
Turns out this was caused by incorrect handling of TX
FIFONOTEMPTY, where the code did not wait for it to clear.
This patch introduces musb_h_tx_flush_fifo(), and makes
musb_host.c to use it.
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
drivers/usb/musb/musb_host.c | 58 +++++++++++++++++++++++++++--------------
1 files changed, 38 insertions(+), 20 deletions(-)
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 440df48..82ece3b 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -108,6 +108,29 @@ static void musb_ep_program(struct musb *pThis, u8 bEnd,
u8 * pBuffer, u32 dwLength);
/*
+ * Clear TX fifo. Needed to avoid BABBLE errors.
+ */
+static inline void musb_h_tx_flush_fifo(struct musb_hw_ep *ep)
+{
+ void __iomem *epio = ep->regs;
+ u16 csr;
+ int retries = 1000;
+
+ csr = musb_readw(epio, MGC_O_HDRC_TXCSR);
+ while (csr & MGC_M_TXCSR_FIFONOTEMPTY) {
+ DBG(5, "Host TX FIFONOTEMPTY csr: %02x\n", csr);
+ csr |= MGC_M_TXCSR_FLUSHFIFO;
+ musb_writew(epio, MGC_O_HDRC_TXCSR, csr);
+ csr = musb_readw(epio, MGC_O_HDRC_TXCSR);
+ if (retries-- < 1) {
+ ERR("Could not flush host TX fifo: csr: %04x\n", csr);
+ return;
+ }
+ mdelay(1);
+ }
+}
+
+/*
* Start transmit. Caller is responsible for locking shared resources.
* pThis must be locked.
*/
@@ -570,14 +593,9 @@ musb_rx_reinit(struct musb *musb, struct musb_qh *qh, struct musb_hw_ep *ep)
if (ep->bIsSharedFifo) {
csr = musb_readw(ep->regs, MGC_O_HDRC_TXCSR);
if (csr & MGC_M_TXCSR_MODE) {
- if (csr & MGC_M_TXCSR_FIFONOTEMPTY) {
- /* this shouldn't happen; irq?? */
- ERR("shared fifo not empty?\n");
- musb_writew(ep->regs, MGC_O_HDRC_TXCSR,
- MGC_M_TXCSR_FLUSHFIFO);
- musb_writew(ep->regs, MGC_O_HDRC_TXCSR,
- MGC_M_TXCSR_FRCDATATOG);
- }
+ musb_h_tx_flush_fifo(ep);
+ musb_writew(ep->regs, MGC_O_HDRC_TXCSR,
+ MGC_M_TXCSR_FRCDATATOG);
}
/* clear mode (and everything else) to enable Rx */
musb_writew(ep->regs, MGC_O_HDRC_TXCSR, 0);
@@ -683,14 +701,12 @@ static void musb_ep_program(struct musb *pThis, u8 bEnd,
/* ASSERT: TXCSR_DMAENAB was already cleared */
/* flush all old state, set default */
- if (csr & MGC_M_TXCSR_FIFONOTEMPTY)
- csr |= MGC_M_TXCSR_FLUSHFIFO;
+ musb_h_tx_flush_fifo(pEnd);
csr &= ~(MGC_M_TXCSR_H_NAKTIMEOUT
| MGC_M_TXCSR_DMAMODE
| MGC_M_TXCSR_FRCDATATOG
| MGC_M_TXCSR_H_RXSTALL
| MGC_M_TXCSR_H_ERROR
- | MGC_M_TXCSR_FIFONOTEMPTY
| MGC_M_TXCSR_TXPKTRDY
);
csr |= MGC_M_TXCSR_MODE;
@@ -1229,11 +1245,8 @@ void musb_host_tx(struct musb *pThis, u8 bEnd)
/* do the proper sequence to abort the transfer in the
* usb core; the dma engine should already be stopped.
*/
-// SCRUB (TX)
- if (wTxCsrVal & MGC_M_TXCSR_FIFONOTEMPTY)
- wTxCsrVal |= MGC_M_TXCSR_FLUSHFIFO;
- wTxCsrVal &= ~(MGC_M_TXCSR_FIFONOTEMPTY
- | MGC_M_TXCSR_AUTOSET
+ musb_h_tx_flush_fifo(pEnd);
+ wTxCsrVal &= ~(MGC_M_TXCSR_AUTOSET
| MGC_M_TXCSR_DMAENAB
| MGC_M_TXCSR_H_ERROR
| MGC_M_TXCSR_H_RXSTALL
@@ -1949,16 +1962,13 @@ static int musb_cleanup_urb(struct urb *urb, struct musb_qh *qh, int is_in)
* clearing that status is platform-specific...
*/
} else {
-// SCRUB (TX)
+ musb_h_tx_flush_fifo(ep);
csr = musb_readw(epio, MGC_O_HDRC_TXCSR);
- if (csr & MGC_M_TXCSR_FIFONOTEMPTY)
- csr |= MGC_M_TXCSR_FLUSHFIFO;
csr &= ~( MGC_M_TXCSR_AUTOSET
| MGC_M_TXCSR_DMAENAB
| MGC_M_TXCSR_H_RXSTALL
| MGC_M_TXCSR_H_NAKTIMEOUT
| MGC_M_TXCSR_H_ERROR
- | MGC_M_TXCSR_FIFONOTEMPTY
);
musb_writew(epio, MGC_O_HDRC_TXCSR, csr);
/* REVISIT may need to clear FLUSHFIFO ... */
@@ -2002,6 +2012,14 @@ static int musb_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
}
}
spin_unlock(&urb->lock);
+
+ /* already completed */
+ if (!qh) {
+ status = 0;
+ goto done;
+ }
+
+ /* still queued but not found on the list */
if (status)
goto done;
--
1.4.4.2
next prev parent reply other threads:[~2007-05-03 16:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-03 16:41 [PATCH 0/7] musb/tusb6010 fixes for host mode Tony Lindgren
2007-05-03 16:41 ` [PATCH] MUSB_HDRC: Allow selecting OTG, peripheral or host mode via sysfs Tony Lindgren
2007-05-03 16:41 ` [PATCH] musb_hdrc: Enable host DMA for tusb6010 Tony Lindgren
2007-05-03 16:41 ` [PATCH] musb_hdrc: Allow tusb dma to transfer various data sizes Tony Lindgren
2007-05-03 16:41 ` [PATCH] musb_hdrc: Transfer remaining bytes with PIO Tony Lindgren
2007-05-03 16:41 ` [PATCH] musb_hdrc: DMA RX workaround for tusb6010 Tony Lindgren
2007-05-03 16:41 ` [PATCH] musb_hdrc: Stop host session on BABBLE Tony Lindgren
2007-05-03 16:41 ` Tony Lindgren [this message]
2007-05-03 18:43 ` [PATCH] musb_hdrc: Clean-up TUSB fifo access Tony Lindgren
2007-05-04 17:05 ` [PATCH] musb_hdrc: Enable host DMA for tusb6010 Tony Lindgren
2007-05-04 16:22 ` [PATCH 0/7] musb/tusb6010 fixes for host mode Kevin Hilman
2007-05-04 16:48 ` Tony Lindgren
2007-05-04 17:01 ` Tony Lindgren
2007-05-04 17:17 ` Kevin Hilman
2007-05-04 17:22 ` Tony Lindgren
2007-05-04 17:26 ` Tony Lindgren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11782105232838-git-send-email-tony@atomide.com \
--to=tony@atomide.com \
--cc=linux-omap-open-source@linux.omap.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox