2005-04-17 05:20:36 +07:00
|
|
|
/*
|
2005-05-08 03:21:50 +07:00
|
|
|
* Copyright (C) 2001-2004 by David Brownell
|
2006-08-31 04:50:06 +07:00
|
|
|
*
|
2005-04-17 05:20:36 +07:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* this file is part of ehci-hcd.c */
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* EHCI hardware queue manipulation ... the core. QH/QTD manipulation.
|
|
|
|
*
|
|
|
|
* Control, bulk, and interrupt traffic all use "qh" lists. They list "qtd"
|
|
|
|
* entries describing USB transactions, max 16-20kB/entry (with 4kB-aligned
|
|
|
|
* buffers needed for the larger number). We use one QH per endpoint, queue
|
|
|
|
* multiple urbs (all three types) per endpoint. URBs may need several qtds.
|
|
|
|
*
|
|
|
|
* ISO traffic uses "ISO TD" (itd, and sitd) records, and (along with
|
|
|
|
* interrupts) needs careful scheduling. Performance improvements can be
|
|
|
|
* an ongoing challenge. That's in "ehci-sched.c".
|
2006-08-31 04:50:06 +07:00
|
|
|
*
|
2005-04-17 05:20:36 +07:00
|
|
|
* USB 1.1 devices are handled (a) by "companion" OHCI or UHCI root hubs,
|
|
|
|
* or otherwise through transaction translators (TTs) in USB 2.0 hubs using
|
|
|
|
* (b) special fields in qh entries or (c) split iso entries. TTs will
|
|
|
|
* buffer low/full speed data so the host collects it at high speed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* fill a qtd, returning how much of the buffer we were able to queue up */
|
|
|
|
|
|
|
|
static int
|
2007-05-01 23:29:37 +07:00
|
|
|
qtd_fill(struct ehci_hcd *ehci, struct ehci_qtd *qtd, dma_addr_t buf,
|
|
|
|
size_t len, int token, int maxpacket)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
int i, count;
|
|
|
|
u64 addr = buf;
|
|
|
|
|
|
|
|
/* one buffer entry per 4K ... first might be short or unaligned */
|
2007-05-01 23:29:37 +07:00
|
|
|
qtd->hw_buf[0] = cpu_to_hc32(ehci, (u32)addr);
|
|
|
|
qtd->hw_buf_hi[0] = cpu_to_hc32(ehci, (u32)(addr >> 32));
|
2005-04-17 05:20:36 +07:00
|
|
|
count = 0x1000 - (buf & 0x0fff); /* rest of that page */
|
|
|
|
if (likely (len < count)) /* ... iff needed */
|
|
|
|
count = len;
|
|
|
|
else {
|
|
|
|
buf += 0x1000;
|
|
|
|
buf &= ~0x0fff;
|
|
|
|
|
|
|
|
/* per-qtd limit: from 16K to 20K (best alignment) */
|
|
|
|
for (i = 1; count < len && i < 5; i++) {
|
|
|
|
addr = buf;
|
2007-05-01 23:29:37 +07:00
|
|
|
qtd->hw_buf[i] = cpu_to_hc32(ehci, (u32)addr);
|
|
|
|
qtd->hw_buf_hi[i] = cpu_to_hc32(ehci,
|
|
|
|
(u32)(addr >> 32));
|
2005-04-17 05:20:36 +07:00
|
|
|
buf += 0x1000;
|
|
|
|
if ((count + 0x1000) < len)
|
|
|
|
count += 0x1000;
|
|
|
|
else
|
|
|
|
count = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* short packets may only terminate transfers */
|
|
|
|
if (count != len)
|
|
|
|
count -= (count % maxpacket);
|
|
|
|
}
|
2007-05-01 23:29:37 +07:00
|
|
|
qtd->hw_token = cpu_to_hc32(ehci, (count << 16) | token);
|
2005-04-17 05:20:36 +07:00
|
|
|
qtd->length = count;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd)
|
|
|
|
{
|
2009-07-14 06:23:29 +07:00
|
|
|
struct ehci_qh_hw *hw = qh->hw;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* writes to an active overlay are unsafe */
|
2013-03-23 00:30:43 +07:00
|
|
|
WARN_ON(qh->qh_state != QH_STATE_IDLE);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-07-14 06:23:29 +07:00
|
|
|
hw->hw_qtd_next = QTD_NEXT(ehci, qtd->qtd_dma);
|
|
|
|
hw->hw_alt_next = EHCI_LIST_END(ehci);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-06-12 01:56:22 +07:00
|
|
|
/* Except for control endpoints, we make hardware maintain data
|
|
|
|
* toggle (like OHCI) ... here (re)initialize the toggle in the QH,
|
|
|
|
* and set the pseudo-toggle in udev. Only usb_clear_halt() will
|
|
|
|
* ever clear it.
|
|
|
|
*/
|
2012-07-11 22:21:32 +07:00
|
|
|
if (!(hw->hw_info1 & cpu_to_hc32(ehci, QH_TOGGLE_CTL))) {
|
2009-06-12 01:56:22 +07:00
|
|
|
unsigned is_out, epnum;
|
|
|
|
|
2011-07-20 01:01:23 +07:00
|
|
|
is_out = qh->is_out;
|
2009-07-14 06:23:29 +07:00
|
|
|
epnum = (hc32_to_cpup(ehci, &hw->hw_info1) >> 8) & 0x0f;
|
2013-10-11 22:29:03 +07:00
|
|
|
if (unlikely(!usb_gettoggle(qh->ps.udev, epnum, is_out))) {
|
2009-07-14 06:23:29 +07:00
|
|
|
hw->hw_token &= ~cpu_to_hc32(ehci, QTD_TOGGLE);
|
2013-10-11 22:29:03 +07:00
|
|
|
usb_settoggle(qh->ps.udev, epnum, is_out, 1);
|
2009-06-12 01:56:22 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-14 06:23:29 +07:00
|
|
|
hw->hw_token &= cpu_to_hc32(ehci, QTD_TOGGLE | QTD_STS_PING);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if it weren't for a common silicon quirk (writing the dummy into the qh
|
|
|
|
* overlay, so qh->hw_token wrongly becomes inactive/halted), only fault
|
|
|
|
* recovery (including urb dequeue) would need software changes to a QH...
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh)
|
|
|
|
{
|
|
|
|
struct ehci_qtd *qtd;
|
|
|
|
|
2013-03-23 00:30:43 +07:00
|
|
|
qtd = list_entry(qh->qtd_list.next, struct ehci_qtd, qtd_list);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-03-23 00:30:43 +07:00
|
|
|
/*
|
|
|
|
* first qtd may already be partially processed.
|
|
|
|
* If we come here during unlink, the QH overlay region
|
|
|
|
* might have reference to the just unlinked qtd. The
|
|
|
|
* qtd is updated in qh_completions(). Update the QH
|
|
|
|
* overlay here.
|
|
|
|
*/
|
2015-11-21 01:53:58 +07:00
|
|
|
if (qh->hw->hw_token & ACTIVE_BIT(ehci)) {
|
2013-03-23 00:30:43 +07:00
|
|
|
qh->hw->hw_qtd_next = qtd->hw_next;
|
2015-11-21 01:53:58 +07:00
|
|
|
if (qh->should_be_inactive)
|
|
|
|
ehci_warn(ehci, "qh %p should be inactive!\n", qh);
|
|
|
|
} else {
|
2013-03-23 00:30:43 +07:00
|
|
|
qh_update(ehci, qh, qtd);
|
2015-11-21 01:53:58 +07:00
|
|
|
}
|
|
|
|
qh->should_be_inactive = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2009-06-29 21:47:30 +07:00
|
|
|
static void qh_link_async(struct ehci_hcd *ehci, struct ehci_qh *qh);
|
|
|
|
|
|
|
|
static void ehci_clear_tt_buffer_complete(struct usb_hcd *hcd,
|
|
|
|
struct usb_host_endpoint *ep)
|
|
|
|
{
|
|
|
|
struct ehci_hcd *ehci = hcd_to_ehci(hcd);
|
|
|
|
struct ehci_qh *qh = ep->hcpriv;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ehci->lock, flags);
|
|
|
|
qh->clearing_tt = 0;
|
|
|
|
if (qh->qh_state == QH_STATE_IDLE && !list_empty(&qh->qtd_list)
|
2011-08-19 03:31:30 +07:00
|
|
|
&& ehci->rh_state == EHCI_RH_RUNNING)
|
2009-06-29 21:47:30 +07:00
|
|
|
qh_link_async(ehci, qh);
|
|
|
|
spin_unlock_irqrestore(&ehci->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ehci_clear_tt_buffer(struct ehci_hcd *ehci, struct ehci_qh *qh,
|
|
|
|
struct urb *urb, u32 token)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* If an async split transaction gets an error or is unlinked,
|
|
|
|
* the TT buffer may be left in an indeterminate state. We
|
|
|
|
* have to clear the TT buffer.
|
|
|
|
*
|
|
|
|
* Note: this routine is never called for Isochronous transfers.
|
|
|
|
*/
|
|
|
|
if (urb->dev->tt && !usb_pipeint(urb->pipe) && !qh->clearing_tt) {
|
2013-11-18 19:23:16 +07:00
|
|
|
#ifdef CONFIG_DYNAMIC_DEBUG
|
2009-06-29 21:47:30 +07:00
|
|
|
struct usb_device *tt = urb->dev->tt->hub;
|
|
|
|
dev_dbg(&tt->dev,
|
|
|
|
"clear tt buffer port %d, a%d ep%d t%08x\n",
|
|
|
|
urb->dev->ttport, urb->dev->devnum,
|
|
|
|
usb_pipeendpoint(urb->pipe), token);
|
2013-11-18 19:23:16 +07:00
|
|
|
#endif /* CONFIG_DYNAMIC_DEBUG */
|
2009-06-29 21:47:30 +07:00
|
|
|
if (!ehci_is_TDI(ehci)
|
|
|
|
|| urb->dev->tt->hub !=
|
|
|
|
ehci_to_hcd(ehci)->self.root_hub) {
|
|
|
|
if (usb_hub_clear_tt_buffer(urb) == 0)
|
|
|
|
qh->clearing_tt = 1;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* REVISIT ARC-derived cores don't clear the root
|
|
|
|
* hub TT buffer in this way...
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-25 02:40:19 +07:00
|
|
|
static int qtd_copy_status (
|
2005-04-17 05:20:36 +07:00
|
|
|
struct ehci_hcd *ehci,
|
|
|
|
struct urb *urb,
|
|
|
|
size_t length,
|
|
|
|
u32 token
|
|
|
|
)
|
|
|
|
{
|
2007-08-25 02:40:19 +07:00
|
|
|
int status = -EINPROGRESS;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* count IN/OUT bytes, not SETUP (even short packets) */
|
|
|
|
if (likely (QTD_PID (token) != 2))
|
|
|
|
urb->actual_length += length - QTD_LENGTH (token);
|
|
|
|
|
|
|
|
/* don't modify error codes */
|
2007-08-22 02:40:36 +07:00
|
|
|
if (unlikely(urb->unlinked))
|
2007-08-25 02:40:19 +07:00
|
|
|
return status;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* force cleanup after short read; not always an error */
|
|
|
|
if (unlikely (IS_SHORT_READ (token)))
|
2007-08-25 02:40:19 +07:00
|
|
|
status = -EREMOTEIO;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* serious "can't proceed" faults reported by the hardware */
|
|
|
|
if (token & QTD_STS_HALT) {
|
|
|
|
if (token & QTD_STS_BABBLE) {
|
|
|
|
/* FIXME "must" disable babbling device's port too */
|
2007-08-25 02:40:19 +07:00
|
|
|
status = -EOVERFLOW;
|
2009-06-30 04:36:14 +07:00
|
|
|
/* CERR nonzero + halt --> stall */
|
|
|
|
} else if (QTD_CERR(token)) {
|
|
|
|
status = -EPIPE;
|
|
|
|
|
|
|
|
/* In theory, more than one of the following bits can be set
|
|
|
|
* since they are sticky and the transaction is retried.
|
|
|
|
* Which to test first is rather arbitrary.
|
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
} else if (token & QTD_STS_MMF) {
|
|
|
|
/* fs/ls interrupt xfer missed the complete-split */
|
2007-08-25 02:40:19 +07:00
|
|
|
status = -EPROTO;
|
2005-04-17 05:20:36 +07:00
|
|
|
} else if (token & QTD_STS_DBE) {
|
2007-08-25 02:40:19 +07:00
|
|
|
status = (QTD_PID (token) == 1) /* IN ? */
|
2005-04-17 05:20:36 +07:00
|
|
|
? -ENOSR /* hc couldn't read data */
|
|
|
|
: -ECOMM; /* hc couldn't write data */
|
|
|
|
} else if (token & QTD_STS_XACT) {
|
2009-06-30 04:36:14 +07:00
|
|
|
/* timeout, bad CRC, wrong PID, etc */
|
|
|
|
ehci_dbg(ehci, "devpath %s ep%d%s 3strikes\n",
|
|
|
|
urb->dev->devpath,
|
|
|
|
usb_pipeendpoint(urb->pipe),
|
|
|
|
usb_pipein(urb->pipe) ? "in" : "out");
|
2007-08-25 02:40:19 +07:00
|
|
|
status = -EPROTO;
|
2009-06-30 04:36:14 +07:00
|
|
|
} else { /* unknown */
|
|
|
|
status = -EPROTO;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2007-08-25 02:40:19 +07:00
|
|
|
|
|
|
|
return status;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-08-25 02:40:19 +07:00
|
|
|
ehci_urb_done(struct ehci_hcd *ehci, struct urb *urb, int status)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2012-11-08 22:17:01 +07:00
|
|
|
if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
|
|
|
|
/* ... update hc-wide periodic stats */
|
|
|
|
ehci_to_hcd(ehci)->self.bandwidth_int_reqs--;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-08-22 02:40:36 +07:00
|
|
|
if (unlikely(urb->unlinked)) {
|
|
|
|
COUNT(ehci->stats.unlink);
|
|
|
|
} else {
|
USB: ehci: qh_completions cleanup and bugfix
Simplify processing of completed qtds, and correct handling of short
reads, by removing two state variables:
- "qtd_status" wasn't needed. The current URB's status is either
OK (-EINPROGRESS) or some fault status. Once a fault appears,
the queue halts and any later QTDs are immediately removed, so
no temporary status is needed. (Or for typical short reads,
it's not treated as a fault, so no queue halt is needed.)
- "do_status" was erroneous. Because of how the queue is set up,
short control reads can (and should!) be treated like full size
reads, and cleaned up the usual way. The status stage will be
executed transparently, and usbcore handles the choice of whether
to report this status as unexected.
The "do_status" problem caused a rather perplexing timing-dependent
problem with usbtest case 10. Sometimes it would make the controller
skip a dozen transactions while (wrongly) trying to clean up after a
short transfer. Fortunately, removing a dcache contention issue made
this become trivial to reproduce (on one test rig), so enough clues
finally presented themselves ... I think this has been around for a
very long time, but was worsened by recent urb->status changes.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-04-12 22:32:05 +07:00
|
|
|
/* report non-error and short read status as zero */
|
|
|
|
if (status == -EINPROGRESS || status == -EREMOTEIO)
|
2007-08-25 02:40:19 +07:00
|
|
|
status = 0;
|
2007-08-22 02:40:36 +07:00
|
|
|
COUNT(ehci->stats.complete);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef EHCI_URB_TRACE
|
|
|
|
ehci_dbg (ehci,
|
|
|
|
"%s %s urb %p ep%d%s status %d len %d/%d\n",
|
2008-03-04 07:08:34 +07:00
|
|
|
__func__, urb->dev->devpath, urb,
|
2005-04-17 05:20:36 +07:00
|
|
|
usb_pipeendpoint (urb->pipe),
|
|
|
|
usb_pipein (urb->pipe) ? "in" : "out",
|
2007-08-25 02:40:19 +07:00
|
|
|
status,
|
2005-04-17 05:20:36 +07:00
|
|
|
urb->actual_length, urb->transfer_buffer_length);
|
|
|
|
#endif
|
|
|
|
|
2007-08-08 22:48:02 +07:00
|
|
|
usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
|
2007-08-25 02:42:24 +07:00
|
|
|
usb_hcd_giveback_urb(ehci_to_hcd(ehci), urb, status);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process and free completed qtds for a qh, returning URBs to drivers.
|
2013-03-23 00:30:56 +07:00
|
|
|
* Chases up to qh->hw_current. Returns nonzero if the caller should
|
|
|
|
* unlink qh.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
static unsigned
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 20:55:46 +07:00
|
|
|
qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2009-08-19 23:22:06 +07:00
|
|
|
struct ehci_qtd *last, *end = qh->dummy;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct list_head *entry, *tmp;
|
2009-08-19 23:22:06 +07:00
|
|
|
int last_status;
|
2005-04-17 05:20:36 +07:00
|
|
|
int stopped;
|
|
|
|
u8 state;
|
2009-07-14 06:23:29 +07:00
|
|
|
struct ehci_qh_hw *hw = qh->hw;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* completions (or tasks on other cpus) must never clobber HALT
|
|
|
|
* till we've gone through and cleaned everything up, even when
|
|
|
|
* they add urbs to this qh's queue or mark them for unlinking.
|
|
|
|
*
|
|
|
|
* NOTE: unlinking expects to be done in queue order.
|
2009-08-19 23:22:06 +07:00
|
|
|
*
|
|
|
|
* It's a bug for qh->qh_state to be anything other than
|
|
|
|
* QH_STATE_IDLE, unless our caller is scan_async() or
|
2012-07-11 22:23:00 +07:00
|
|
|
* scan_intr().
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
state = qh->qh_state;
|
|
|
|
qh->qh_state = QH_STATE_COMPLETING;
|
|
|
|
stopped = (state == QH_STATE_IDLE);
|
|
|
|
|
2009-08-19 23:22:06 +07:00
|
|
|
rescan:
|
|
|
|
last = NULL;
|
|
|
|
last_status = -EINPROGRESS;
|
2013-03-23 00:31:11 +07:00
|
|
|
qh->dequeue_during_giveback = 0;
|
2009-08-19 23:22:06 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* remove de-activated QTDs from front of queue.
|
|
|
|
* after faults (including short reads), cleanup this urb
|
|
|
|
* then let the queue advance.
|
|
|
|
* if queue is stopped, handles unlinks.
|
|
|
|
*/
|
|
|
|
list_for_each_safe (entry, tmp, &qh->qtd_list) {
|
|
|
|
struct ehci_qtd *qtd;
|
|
|
|
struct urb *urb;
|
|
|
|
u32 token = 0;
|
|
|
|
|
|
|
|
qtd = list_entry (entry, struct ehci_qtd, qtd_list);
|
|
|
|
urb = qtd->urb;
|
|
|
|
|
|
|
|
/* clean up any state from previous QTD ...*/
|
|
|
|
if (last) {
|
|
|
|
if (likely (last->urb != urb)) {
|
2007-08-25 02:40:19 +07:00
|
|
|
ehci_urb_done(ehci, last->urb, last_status);
|
2008-02-28 09:05:24 +07:00
|
|
|
last_status = -EINPROGRESS;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
ehci_qtd_free (ehci, last);
|
|
|
|
last = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ignore urbs submitted during completions we reported */
|
|
|
|
if (qtd == end)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* hardware copies qtd out of qh overlay */
|
|
|
|
rmb ();
|
2007-05-01 23:29:37 +07:00
|
|
|
token = hc32_to_cpu(ehci, qtd->hw_token);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* always clean up qtds the hc de-activated */
|
2009-02-10 22:16:58 +07:00
|
|
|
retry_xacterr:
|
2005-04-17 05:20:36 +07:00
|
|
|
if ((token & QTD_STS_ACTIVE) == 0) {
|
|
|
|
|
2011-10-31 02:55:09 +07:00
|
|
|
/* Report Data Buffer Error: non-fatal but useful */
|
|
|
|
if (token & QTD_STS_DBE)
|
|
|
|
ehci_dbg(ehci,
|
|
|
|
"detected DataBufferErr for urb %p ep%d%s len %d, qtd %p [qh %p]\n",
|
|
|
|
urb,
|
|
|
|
usb_endpoint_num(&urb->ep->desc),
|
|
|
|
usb_endpoint_dir_in(&urb->ep->desc) ? "in" : "out",
|
|
|
|
urb->transfer_buffer_length,
|
|
|
|
qtd,
|
|
|
|
qh);
|
|
|
|
|
2008-04-11 04:21:06 +07:00
|
|
|
/* on STALL, error, and short reads this urb must
|
|
|
|
* complete and all its qtds must be recycled.
|
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
if ((token & QTD_STS_HALT) != 0) {
|
2009-02-10 22:16:58 +07:00
|
|
|
|
|
|
|
/* retry transaction errors until we
|
|
|
|
* reach the software xacterr limit
|
|
|
|
*/
|
|
|
|
if ((token & QTD_STS_XACT) &&
|
|
|
|
QTD_CERR(token) == 0 &&
|
2009-07-31 21:41:40 +07:00
|
|
|
++qh->xacterrs < QH_XACTERR_MAX &&
|
2009-02-10 22:16:58 +07:00
|
|
|
!urb->unlinked) {
|
|
|
|
ehci_dbg(ehci,
|
2009-02-14 02:22:06 +07:00
|
|
|
"detected XactErr len %zu/%zu retry %d\n",
|
2009-07-31 21:41:40 +07:00
|
|
|
qtd->length - QTD_LENGTH(token), qtd->length, qh->xacterrs);
|
2009-02-10 22:16:58 +07:00
|
|
|
|
|
|
|
/* reset the token in the qtd and the
|
|
|
|
* qh overlay (which still contains
|
|
|
|
* the qtd) so that we pick up from
|
|
|
|
* where we left off
|
|
|
|
*/
|
|
|
|
token &= ~QTD_STS_HALT;
|
|
|
|
token |= QTD_STS_ACTIVE |
|
|
|
|
(EHCI_TUNE_CERR << 10);
|
|
|
|
qtd->hw_token = cpu_to_hc32(ehci,
|
|
|
|
token);
|
|
|
|
wmb();
|
2009-07-14 06:23:29 +07:00
|
|
|
hw->hw_token = cpu_to_hc32(ehci,
|
|
|
|
token);
|
2009-02-10 22:16:58 +07:00
|
|
|
goto retry_xacterr;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
stopped = 1;
|
2016-01-26 03:42:04 +07:00
|
|
|
qh->unlink_reason |= QH_UNLINK_HALTED;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* magic dummy for some short reads; qh won't advance.
|
|
|
|
* that silicon quirk can kick in with this dummy too.
|
2008-04-11 04:21:06 +07:00
|
|
|
*
|
|
|
|
* other short reads won't stop the queue, including
|
|
|
|
* control transfers (status stage handles that) or
|
|
|
|
* most other single-qtd reads ... the queue stops if
|
|
|
|
* URB_SHORT_NOT_OK was set so the driver submitting
|
|
|
|
* the urbs could clean it up.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
} else if (IS_SHORT_READ (token)
|
2007-05-01 23:29:37 +07:00
|
|
|
&& !(qtd->hw_alt_next
|
|
|
|
& EHCI_LIST_END(ehci))) {
|
2005-04-17 05:20:36 +07:00
|
|
|
stopped = 1;
|
2016-01-26 03:42:04 +07:00
|
|
|
qh->unlink_reason |= QH_UNLINK_SHORT_READ;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stop scanning when we reach qtds the hc is using */
|
|
|
|
} else if (likely (!stopped
|
2012-07-11 22:21:48 +07:00
|
|
|
&& ehci->rh_state >= EHCI_RH_RUNNING)) {
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
|
2008-04-11 04:21:06 +07:00
|
|
|
/* scan the whole queue for unlinks whenever it stops */
|
2005-04-17 05:20:36 +07:00
|
|
|
} else {
|
|
|
|
stopped = 1;
|
|
|
|
|
2008-04-11 04:21:06 +07:00
|
|
|
/* cancel everything if we halt, suspend, etc */
|
2016-01-26 03:42:04 +07:00
|
|
|
if (ehci->rh_state < EHCI_RH_RUNNING) {
|
2007-08-25 02:40:19 +07:00
|
|
|
last_status = -ESHUTDOWN;
|
2016-01-26 03:42:04 +07:00
|
|
|
qh->unlink_reason |= QH_UNLINK_SHUTDOWN;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-04-11 04:21:06 +07:00
|
|
|
/* this qtd is active; skip it unless a previous qtd
|
|
|
|
* for its urb faulted, or its urb was canceled.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2008-04-11 04:21:06 +07:00
|
|
|
else if (last_status == -EINPROGRESS && !urb->unlinked)
|
2005-04-17 05:20:36 +07:00
|
|
|
continue;
|
2006-08-31 04:50:06 +07:00
|
|
|
|
2013-03-01 22:51:15 +07:00
|
|
|
/*
|
|
|
|
* If this was the active qtd when the qh was unlinked
|
|
|
|
* and the overlay's token is active, then the overlay
|
|
|
|
* hasn't been written back to the qtd yet so use its
|
|
|
|
* token instead of the qtd's. After the qtd is
|
|
|
|
* processed and removed, the overlay won't be valid
|
|
|
|
* any more.
|
|
|
|
*/
|
|
|
|
if (state == QH_STATE_IDLE &&
|
|
|
|
qh->qtd_list.next == &qtd->qtd_list &&
|
|
|
|
(hw->hw_token & ACTIVE_BIT(ehci))) {
|
2009-07-14 06:23:29 +07:00
|
|
|
token = hc32_to_cpu(ehci, hw->hw_token);
|
2013-03-01 22:51:15 +07:00
|
|
|
hw->hw_token &= ~ACTIVE_BIT(ehci);
|
2015-11-21 01:53:58 +07:00
|
|
|
qh->should_be_inactive = 1;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-06-29 21:47:30 +07:00
|
|
|
/* An unlink may leave an incomplete
|
|
|
|
* async transaction in the TT buffer.
|
|
|
|
* We have to clear it.
|
|
|
|
*/
|
|
|
|
ehci_clear_tt_buffer(ehci, qh, urb, token);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2006-08-31 04:50:06 +07:00
|
|
|
|
USB: ehci: qh_completions cleanup and bugfix
Simplify processing of completed qtds, and correct handling of short
reads, by removing two state variables:
- "qtd_status" wasn't needed. The current URB's status is either
OK (-EINPROGRESS) or some fault status. Once a fault appears,
the queue halts and any later QTDs are immediately removed, so
no temporary status is needed. (Or for typical short reads,
it's not treated as a fault, so no queue halt is needed.)
- "do_status" was erroneous. Because of how the queue is set up,
short control reads can (and should!) be treated like full size
reads, and cleaned up the usual way. The status stage will be
executed transparently, and usbcore handles the choice of whether
to report this status as unexected.
The "do_status" problem caused a rather perplexing timing-dependent
problem with usbtest case 10. Sometimes it would make the controller
skip a dozen transactions while (wrongly) trying to clean up after a
short transfer. Fortunately, removing a dcache contention issue made
this become trivial to reproduce (on one test rig), so enough clues
finally presented themselves ... I think this has been around for a
very long time, but was worsened by recent urb->status changes.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-04-12 22:32:05 +07:00
|
|
|
/* unless we already know the urb's status, collect qtd status
|
|
|
|
* and update count of bytes transferred. in common short read
|
|
|
|
* cases with only one data qtd (including control transfers),
|
|
|
|
* queue processing won't halt. but with two or more qtds (for
|
|
|
|
* example, with a 32 KB transfer), when the first qtd gets a
|
|
|
|
* short read the second must be removed by hand.
|
|
|
|
*/
|
|
|
|
if (last_status == -EINPROGRESS) {
|
|
|
|
last_status = qtd_copy_status(ehci, urb,
|
|
|
|
qtd->length, token);
|
|
|
|
if (last_status == -EREMOTEIO
|
|
|
|
&& (qtd->hw_alt_next
|
|
|
|
& EHCI_LIST_END(ehci)))
|
|
|
|
last_status = -EINPROGRESS;
|
2009-06-29 21:47:30 +07:00
|
|
|
|
|
|
|
/* As part of low/full-speed endpoint-halt processing
|
|
|
|
* we must clear the TT buffer (11.17.5).
|
|
|
|
*/
|
|
|
|
if (unlikely(last_status != -EINPROGRESS &&
|
2009-11-18 23:37:15 +07:00
|
|
|
last_status != -EREMOTEIO)) {
|
|
|
|
/* The TT's in some hubs malfunction when they
|
|
|
|
* receive this request following a STALL (they
|
|
|
|
* stop sending isochronous packets). Since a
|
|
|
|
* STALL can't leave the TT buffer in a busy
|
|
|
|
* state (if you believe Figures 11-48 - 11-51
|
|
|
|
* in the USB 2.0 spec), we won't clear the TT
|
|
|
|
* buffer in this case. Strictly speaking this
|
|
|
|
* is a violation of the spec.
|
|
|
|
*/
|
|
|
|
if (last_status != -EPIPE)
|
|
|
|
ehci_clear_tt_buffer(ehci, qh, urb,
|
|
|
|
token);
|
|
|
|
}
|
2007-08-22 02:39:21 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-04-11 04:21:06 +07:00
|
|
|
/* if we're removing something not at the queue head,
|
|
|
|
* patch the hardware queue pointer.
|
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
if (stopped && qtd->qtd_list.prev != &qh->qtd_list) {
|
|
|
|
last = list_entry (qtd->qtd_list.prev,
|
|
|
|
struct ehci_qtd, qtd_list);
|
|
|
|
last->hw_next = qtd->hw_next;
|
|
|
|
}
|
2008-04-11 04:21:06 +07:00
|
|
|
|
|
|
|
/* remove qtd; it's recycled after possible urb completion */
|
2005-04-17 05:20:36 +07:00
|
|
|
list_del (&qtd->qtd_list);
|
|
|
|
last = qtd;
|
2009-02-10 22:16:58 +07:00
|
|
|
|
|
|
|
/* reinit the xacterr counter for the next qtd */
|
2009-07-31 21:41:40 +07:00
|
|
|
qh->xacterrs = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* last urb's completion might still need calling */
|
|
|
|
if (likely (last != NULL)) {
|
2007-08-25 02:40:19 +07:00
|
|
|
ehci_urb_done(ehci, last->urb, last_status);
|
2005-04-17 05:20:36 +07:00
|
|
|
ehci_qtd_free (ehci, last);
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:22:06 +07:00
|
|
|
/* Do we need to rescan for URBs dequeued during a giveback? */
|
2013-03-23 00:31:11 +07:00
|
|
|
if (unlikely(qh->dequeue_during_giveback)) {
|
2009-08-19 23:22:06 +07:00
|
|
|
/* If the QH is already unlinked, do the rescan now. */
|
|
|
|
if (state == QH_STATE_IDLE)
|
|
|
|
goto rescan;
|
|
|
|
|
2013-03-23 00:31:11 +07:00
|
|
|
/* Otherwise the caller must unlink the QH. */
|
2009-08-19 23:22:06 +07:00
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* restore original state; caller must unlink or relink */
|
|
|
|
qh->qh_state = state;
|
|
|
|
|
|
|
|
/* be sure the hardware's done with the qh before refreshing
|
|
|
|
* it after fault cleanup, or recovering from silicon wrongly
|
|
|
|
* overlaying the dummy qtd (which reduces DMA chatter).
|
2013-03-23 00:31:11 +07:00
|
|
|
*
|
|
|
|
* We won't refresh a QH that's linked (after the HC
|
|
|
|
* stopped the queue). That avoids a race:
|
|
|
|
* - HC reads first part of QH;
|
|
|
|
* - CPU updates that first part and the token;
|
|
|
|
* - HC reads rest of that QH, including token
|
|
|
|
* Result: HC gets an inconsistent image, and then
|
|
|
|
* DMAs to/from the wrong memory (corrupting it).
|
|
|
|
*
|
|
|
|
* That should be rare for interrupt transfers,
|
|
|
|
* except maybe high bandwidth ...
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2013-03-23 00:31:11 +07:00
|
|
|
if (stopped != 0 || hw->hw_qtd_next == EHCI_LIST_END(ehci))
|
2016-01-26 03:42:04 +07:00
|
|
|
qh->unlink_reason |= QH_UNLINK_DUMMY_OVERLAY;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-03-23 00:31:11 +07:00
|
|
|
/* Let the caller know if the QH needs to be unlinked. */
|
2016-01-26 03:42:04 +07:00
|
|
|
return qh->unlink_reason;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
// high bandwidth multiplier, as encoded in highspeed endpoint descriptors
|
|
|
|
#define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
|
|
|
|
// ... and packet size, for any kind of endpoint descriptor
|
|
|
|
#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* reverse of qh_urb_transaction: free a list of TDs.
|
|
|
|
* used for cleanup after errors, before HC sees an URB's TDs.
|
|
|
|
*/
|
|
|
|
static void qtd_list_free (
|
|
|
|
struct ehci_hcd *ehci,
|
|
|
|
struct urb *urb,
|
|
|
|
struct list_head *qtd_list
|
|
|
|
) {
|
|
|
|
struct list_head *entry, *temp;
|
|
|
|
|
|
|
|
list_for_each_safe (entry, temp, qtd_list) {
|
|
|
|
struct ehci_qtd *qtd;
|
|
|
|
|
|
|
|
qtd = list_entry (entry, struct ehci_qtd, qtd_list);
|
|
|
|
list_del (&qtd->qtd_list);
|
|
|
|
ehci_qtd_free (ehci, qtd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create a list of filled qtds for this URB; won't link into qh.
|
|
|
|
*/
|
|
|
|
static struct list_head *
|
|
|
|
qh_urb_transaction (
|
|
|
|
struct ehci_hcd *ehci,
|
|
|
|
struct urb *urb,
|
|
|
|
struct list_head *head,
|
2005-10-21 14:21:58 +07:00
|
|
|
gfp_t flags
|
2005-04-17 05:20:36 +07:00
|
|
|
) {
|
|
|
|
struct ehci_qtd *qtd, *qtd_prev;
|
|
|
|
dma_addr_t buf;
|
2009-11-07 00:29:40 +07:00
|
|
|
int len, this_sg_len, maxpacket;
|
2005-04-17 05:20:36 +07:00
|
|
|
int is_input;
|
|
|
|
u32 token;
|
2009-11-07 00:29:40 +07:00
|
|
|
int i;
|
|
|
|
struct scatterlist *sg;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* URBs map to sequences of QTDs: one logical transaction
|
|
|
|
*/
|
|
|
|
qtd = ehci_qtd_alloc (ehci, flags);
|
|
|
|
if (unlikely (!qtd))
|
|
|
|
return NULL;
|
|
|
|
list_add_tail (&qtd->qtd_list, head);
|
|
|
|
qtd->urb = urb;
|
|
|
|
|
|
|
|
token = QTD_STS_ACTIVE;
|
|
|
|
token |= (EHCI_TUNE_CERR << 10);
|
|
|
|
/* for split transactions, SplitXState initialized to zero */
|
|
|
|
|
|
|
|
len = urb->transfer_buffer_length;
|
|
|
|
is_input = usb_pipein (urb->pipe);
|
|
|
|
if (usb_pipecontrol (urb->pipe)) {
|
|
|
|
/* SETUP pid */
|
2007-05-01 23:29:37 +07:00
|
|
|
qtd_fill(ehci, qtd, urb->setup_dma,
|
|
|
|
sizeof (struct usb_ctrlrequest),
|
|
|
|
token | (2 /* "setup" */ << 8), 8);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* ... and always at least one more pid */
|
|
|
|
token ^= QTD_TOGGLE;
|
|
|
|
qtd_prev = qtd;
|
|
|
|
qtd = ehci_qtd_alloc (ehci, flags);
|
|
|
|
if (unlikely (!qtd))
|
|
|
|
goto cleanup;
|
|
|
|
qtd->urb = urb;
|
2007-05-01 23:29:37 +07:00
|
|
|
qtd_prev->hw_next = QTD_NEXT(ehci, qtd->qtd_dma);
|
2005-04-17 05:20:36 +07:00
|
|
|
list_add_tail (&qtd->qtd_list, head);
|
2005-11-03 23:44:49 +07:00
|
|
|
|
|
|
|
/* for zero length DATA stages, STATUS is always IN */
|
|
|
|
if (len == 0)
|
|
|
|
token |= (1 /* "in" */ << 8);
|
2006-08-31 04:50:06 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* data transfer stage: buffer setup
|
|
|
|
*/
|
2011-12-04 05:41:31 +07:00
|
|
|
i = urb->num_mapped_sgs;
|
2009-11-07 00:29:40 +07:00
|
|
|
if (len > 0 && i > 0) {
|
2010-05-02 01:20:01 +07:00
|
|
|
sg = urb->sg;
|
2009-11-07 00:29:40 +07:00
|
|
|
buf = sg_dma_address(sg);
|
|
|
|
|
|
|
|
/* urb->transfer_buffer_length may be smaller than the
|
|
|
|
* size of the scatterlist (or vice versa)
|
|
|
|
*/
|
|
|
|
this_sg_len = min_t(int, sg_dma_len(sg), len);
|
|
|
|
} else {
|
|
|
|
sg = NULL;
|
|
|
|
buf = urb->transfer_dma;
|
|
|
|
this_sg_len = len;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-11-03 23:44:49 +07:00
|
|
|
if (is_input)
|
2005-04-17 05:20:36 +07:00
|
|
|
token |= (1 /* "in" */ << 8);
|
|
|
|
/* else it's already initted to "out" pid (0 << 8) */
|
|
|
|
|
|
|
|
maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, !is_input));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* buffer gets wrapped in one or more qtds;
|
|
|
|
* last one may be "short" (including zero len)
|
|
|
|
* and may serve as a control status ack
|
|
|
|
*/
|
|
|
|
for (;;) {
|
|
|
|
int this_qtd_len;
|
|
|
|
|
2009-11-07 00:29:40 +07:00
|
|
|
this_qtd_len = qtd_fill(ehci, qtd, buf, this_sg_len, token,
|
|
|
|
maxpacket);
|
|
|
|
this_sg_len -= this_qtd_len;
|
2005-04-17 05:20:36 +07:00
|
|
|
len -= this_qtd_len;
|
|
|
|
buf += this_qtd_len;
|
2008-04-11 04:21:06 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* short reads advance to a "magic" dummy instead of the next
|
|
|
|
* qtd ... that forces the queue to stop, for manual cleanup.
|
|
|
|
* (this will usually be overridden later.)
|
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
if (is_input)
|
2009-07-14 06:23:29 +07:00
|
|
|
qtd->hw_alt_next = ehci->async->hw->hw_alt_next;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* qh makes control packets use qtd toggle; maybe switch it */
|
|
|
|
if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0)
|
|
|
|
token ^= QTD_TOGGLE;
|
|
|
|
|
2009-11-07 00:29:40 +07:00
|
|
|
if (likely(this_sg_len <= 0)) {
|
|
|
|
if (--i <= 0 || len <= 0)
|
|
|
|
break;
|
|
|
|
sg = sg_next(sg);
|
|
|
|
buf = sg_dma_address(sg);
|
|
|
|
this_sg_len = min_t(int, sg_dma_len(sg), len);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
qtd_prev = qtd;
|
|
|
|
qtd = ehci_qtd_alloc (ehci, flags);
|
|
|
|
if (unlikely (!qtd))
|
|
|
|
goto cleanup;
|
|
|
|
qtd->urb = urb;
|
2007-05-01 23:29:37 +07:00
|
|
|
qtd_prev->hw_next = QTD_NEXT(ehci, qtd->qtd_dma);
|
2005-04-17 05:20:36 +07:00
|
|
|
list_add_tail (&qtd->qtd_list, head);
|
|
|
|
}
|
|
|
|
|
2008-04-11 04:21:06 +07:00
|
|
|
/*
|
|
|
|
* unless the caller requires manual cleanup after short reads,
|
|
|
|
* have the alt_next mechanism keep the queue running after the
|
|
|
|
* last data qtd (the only one, for control and most other cases).
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
if (likely ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0
|
|
|
|
|| usb_pipecontrol (urb->pipe)))
|
2007-05-01 23:29:37 +07:00
|
|
|
qtd->hw_alt_next = EHCI_LIST_END(ehci);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* control requests may need a terminating data "status" ack;
|
2011-09-05 20:05:56 +07:00
|
|
|
* other OUT ones may need a terminating short packet
|
|
|
|
* (zero length).
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2005-11-03 23:44:49 +07:00
|
|
|
if (likely (urb->transfer_buffer_length != 0)) {
|
2005-04-17 05:20:36 +07:00
|
|
|
int one_more = 0;
|
|
|
|
|
|
|
|
if (usb_pipecontrol (urb->pipe)) {
|
|
|
|
one_more = 1;
|
|
|
|
token ^= 0x0100; /* "in" <--> "out" */
|
|
|
|
token |= QTD_TOGGLE; /* force DATA1 */
|
2011-09-05 20:05:56 +07:00
|
|
|
} else if (usb_pipeout(urb->pipe)
|
2005-04-17 05:20:36 +07:00
|
|
|
&& (urb->transfer_flags & URB_ZERO_PACKET)
|
|
|
|
&& !(urb->transfer_buffer_length % maxpacket)) {
|
|
|
|
one_more = 1;
|
|
|
|
}
|
|
|
|
if (one_more) {
|
|
|
|
qtd_prev = qtd;
|
|
|
|
qtd = ehci_qtd_alloc (ehci, flags);
|
|
|
|
if (unlikely (!qtd))
|
|
|
|
goto cleanup;
|
|
|
|
qtd->urb = urb;
|
2007-05-01 23:29:37 +07:00
|
|
|
qtd_prev->hw_next = QTD_NEXT(ehci, qtd->qtd_dma);
|
2005-04-17 05:20:36 +07:00
|
|
|
list_add_tail (&qtd->qtd_list, head);
|
|
|
|
|
|
|
|
/* never any data in such packets */
|
2007-05-01 23:29:37 +07:00
|
|
|
qtd_fill(ehci, qtd, 0, 0, token, 0);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* by default, enable interrupt on urb completion */
|
|
|
|
if (likely (!(urb->transfer_flags & URB_NO_INTERRUPT)))
|
2007-05-01 23:29:37 +07:00
|
|
|
qtd->hw_token |= cpu_to_hc32(ehci, QTD_IOC);
|
2005-04-17 05:20:36 +07:00
|
|
|
return head;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
qtd_list_free (ehci, urb, head);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
// Would be best to create all qh's from config descriptors,
|
|
|
|
// when each interface/altsetting is established. Unlink
|
|
|
|
// any previous qh and cancel its urbs first; endpoints are
|
|
|
|
// implicitly reset then (data toggle too).
|
|
|
|
// That'd mean updating how usbcore talks to HCDs. (2.7?)
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each QH holds a qtd list; a QH is used for everything except iso.
|
|
|
|
*
|
|
|
|
* For interrupt urbs, the scheduler must set the microframe scheduling
|
|
|
|
* mask(s) each time the QH gets scheduled. For highspeed, that's
|
|
|
|
* just one microframe in the s-mask. For split interrupt transactions
|
|
|
|
* there are additional complications: c-mask, maybe FSTNs.
|
|
|
|
*/
|
|
|
|
static struct ehci_qh *
|
|
|
|
qh_make (
|
|
|
|
struct ehci_hcd *ehci,
|
|
|
|
struct urb *urb,
|
2005-10-21 14:21:58 +07:00
|
|
|
gfp_t flags
|
2005-04-17 05:20:36 +07:00
|
|
|
) {
|
|
|
|
struct ehci_qh *qh = ehci_qh_alloc (ehci, flags);
|
|
|
|
u32 info1 = 0, info2 = 0;
|
|
|
|
int is_input, type;
|
|
|
|
int maxp = 0;
|
2007-12-20 02:30:39 +07:00
|
|
|
struct usb_tt *tt = urb->dev->tt;
|
2009-07-14 06:23:29 +07:00
|
|
|
struct ehci_qh_hw *hw;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (!qh)
|
|
|
|
return qh;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* init endpoint/device data for this QH
|
|
|
|
*/
|
|
|
|
info1 |= usb_pipeendpoint (urb->pipe) << 8;
|
|
|
|
info1 |= usb_pipedevice (urb->pipe) << 0;
|
|
|
|
|
|
|
|
is_input = usb_pipein (urb->pipe);
|
|
|
|
type = usb_pipetype (urb->pipe);
|
|
|
|
maxp = usb_maxpacket (urb->dev, urb->pipe, !is_input);
|
|
|
|
|
2008-02-09 06:08:44 +07:00
|
|
|
/* 1024 byte maxpacket is a hardware ceiling. High bandwidth
|
|
|
|
* acts like up to 3KB, but is built from smaller packets.
|
|
|
|
*/
|
|
|
|
if (max_packet(maxp) > 1024) {
|
|
|
|
ehci_dbg(ehci, "bogus qh maxpacket %d\n", max_packet(maxp));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Compute interrupt scheduling parameters just once, and save.
|
|
|
|
* - allowing for high bandwidth, how many nsec/uframe are used?
|
|
|
|
* - split transactions need a second CSPLIT uframe; same question
|
|
|
|
* - splits also need a schedule gap (for full/low speed I/O)
|
|
|
|
* - qh has a polling interval
|
|
|
|
*
|
|
|
|
* For control/bulk requests, the HC or TT handles these.
|
|
|
|
*/
|
|
|
|
if (type == PIPE_INTERRUPT) {
|
2013-10-11 22:29:13 +07:00
|
|
|
unsigned tmp;
|
|
|
|
|
2013-10-11 22:29:03 +07:00
|
|
|
qh->ps.usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH,
|
2007-12-20 02:30:39 +07:00
|
|
|
is_input, 0,
|
|
|
|
hb_mult(maxp) * max_packet(maxp)));
|
2013-10-11 22:29:03 +07:00
|
|
|
qh->ps.phase = NO_FRAME;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (urb->dev->speed == USB_SPEED_HIGH) {
|
2013-10-11 22:29:03 +07:00
|
|
|
qh->ps.c_usecs = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
qh->gap_uf = 0;
|
|
|
|
|
2013-10-11 22:29:03 +07:00
|
|
|
if (urb->interval > 1 && urb->interval < 8) {
|
2005-04-17 05:20:36 +07:00
|
|
|
/* NOTE interval 2 or 4 uframes could work.
|
|
|
|
* But interval 1 scheduling is simpler, and
|
|
|
|
* includes high bandwidth.
|
|
|
|
*/
|
2010-01-08 23:17:55 +07:00
|
|
|
urb->interval = 1;
|
2013-10-11 22:29:03 +07:00
|
|
|
} else if (urb->interval > ehci->periodic_size << 3) {
|
|
|
|
urb->interval = ehci->periodic_size << 3;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2013-10-11 22:29:03 +07:00
|
|
|
qh->ps.period = urb->interval >> 3;
|
2013-10-11 22:29:13 +07:00
|
|
|
|
|
|
|
/* period for bandwidth allocation */
|
|
|
|
tmp = min_t(unsigned, EHCI_BANDWIDTH_SIZE,
|
|
|
|
1 << (urb->ep->desc.bInterval - 1));
|
|
|
|
|
|
|
|
/* Allow urb->interval to override */
|
|
|
|
qh->ps.bw_uperiod = min_t(unsigned, tmp, urb->interval);
|
|
|
|
qh->ps.bw_period = qh->ps.bw_uperiod >> 3;
|
2005-04-17 05:20:36 +07:00
|
|
|
} else {
|
2005-08-14 08:44:58 +07:00
|
|
|
int think_time;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* gap is f(FS/LS transfer times) */
|
|
|
|
qh->gap_uf = 1 + usb_calc_bus_time (urb->dev->speed,
|
|
|
|
is_input, 0, maxp) / (125 * 1000);
|
|
|
|
|
|
|
|
/* FIXME this just approximates SPLIT/CSPLIT times */
|
|
|
|
if (is_input) { // SPLIT, gap, CSPLIT+DATA
|
2013-10-11 22:29:03 +07:00
|
|
|
qh->ps.c_usecs = qh->ps.usecs + HS_USECS(0);
|
|
|
|
qh->ps.usecs = HS_USECS(1);
|
2005-04-17 05:20:36 +07:00
|
|
|
} else { // SPLIT+DATA, gap, CSPLIT
|
2013-10-11 22:29:03 +07:00
|
|
|
qh->ps.usecs += HS_USECS(1);
|
|
|
|
qh->ps.c_usecs = HS_USECS(0);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2005-08-14 08:44:58 +07:00
|
|
|
think_time = tt ? tt->think_time : 0;
|
2013-10-11 22:29:03 +07:00
|
|
|
qh->ps.tt_usecs = NS_TO_US(think_time +
|
2005-08-14 08:44:58 +07:00
|
|
|
usb_calc_bus_time (urb->dev->speed,
|
|
|
|
is_input, 0, max_packet (maxp)));
|
2013-10-11 22:29:03 +07:00
|
|
|
if (urb->interval > ehci->periodic_size)
|
|
|
|
urb->interval = ehci->periodic_size;
|
|
|
|
qh->ps.period = urb->interval;
|
2013-10-11 22:29:13 +07:00
|
|
|
|
|
|
|
/* period for bandwidth allocation */
|
|
|
|
tmp = min_t(unsigned, EHCI_BANDWIDTH_FRAMES,
|
|
|
|
urb->ep->desc.bInterval);
|
|
|
|
tmp = rounddown_pow_of_two(tmp);
|
|
|
|
|
|
|
|
/* Allow urb->interval to override */
|
|
|
|
qh->ps.bw_period = min_t(unsigned, tmp, urb->interval);
|
|
|
|
qh->ps.bw_uperiod = qh->ps.bw_period << 3;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* support for tt scheduling, and access to toggles */
|
2013-10-11 22:29:03 +07:00
|
|
|
qh->ps.udev = urb->dev;
|
|
|
|
qh->ps.ep = urb->ep;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* using TT? */
|
|
|
|
switch (urb->dev->speed) {
|
|
|
|
case USB_SPEED_LOW:
|
2012-07-11 22:21:32 +07:00
|
|
|
info1 |= QH_LOW_SPEED;
|
2005-04-17 05:20:36 +07:00
|
|
|
/* FALL THROUGH */
|
|
|
|
|
|
|
|
case USB_SPEED_FULL:
|
|
|
|
/* EPS 0 means "full" */
|
|
|
|
if (type != PIPE_INTERRUPT)
|
|
|
|
info1 |= (EHCI_TUNE_RL_TT << 28);
|
|
|
|
if (type == PIPE_CONTROL) {
|
2012-07-11 22:21:32 +07:00
|
|
|
info1 |= QH_CONTROL_EP; /* for TT */
|
|
|
|
info1 |= QH_TOGGLE_CTL; /* toggle from qtd */
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
info1 |= maxp << 16;
|
|
|
|
|
|
|
|
info2 |= (EHCI_TUNE_MULT_TT << 30);
|
2006-01-21 04:57:52 +07:00
|
|
|
|
|
|
|
/* Some Freescale processors have an erratum in which the
|
|
|
|
* port number in the queue head was 0..N-1 instead of 1..N.
|
|
|
|
*/
|
|
|
|
if (ehci_has_fsl_portno_bug(ehci))
|
|
|
|
info2 |= (urb->dev->ttport-1) << 23;
|
|
|
|
else
|
|
|
|
info2 |= urb->dev->ttport << 23;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* set the address of the TT; for TDI's integrated
|
|
|
|
* root hub tt, leave it zeroed.
|
|
|
|
*/
|
2007-12-20 02:30:39 +07:00
|
|
|
if (tt && tt->hub != ehci_to_hcd(ehci)->self.root_hub)
|
|
|
|
info2 |= tt->hub->devnum << 16;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* NOTE: if (PIPE_INTERRUPT) { scheduler sets c-mask } */
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_SPEED_HIGH: /* no TT involved */
|
2012-07-11 22:21:32 +07:00
|
|
|
info1 |= QH_HIGH_SPEED;
|
2005-04-17 05:20:36 +07:00
|
|
|
if (type == PIPE_CONTROL) {
|
|
|
|
info1 |= (EHCI_TUNE_RL_HS << 28);
|
|
|
|
info1 |= 64 << 16; /* usb2 fixed maxpacket */
|
2012-07-11 22:21:32 +07:00
|
|
|
info1 |= QH_TOGGLE_CTL; /* toggle from qtd */
|
2005-04-17 05:20:36 +07:00
|
|
|
info2 |= (EHCI_TUNE_MULT_HS << 30);
|
|
|
|
} else if (type == PIPE_BULK) {
|
|
|
|
info1 |= (EHCI_TUNE_RL_HS << 28);
|
2008-02-09 06:08:44 +07:00
|
|
|
/* The USB spec says that high speed bulk endpoints
|
|
|
|
* always use 512 byte maxpacket. But some device
|
|
|
|
* vendors decided to ignore that, and MSFT is happy
|
|
|
|
* to help them do so. So now people expect to use
|
|
|
|
* such nonconformant devices with Linux too; sigh.
|
|
|
|
*/
|
|
|
|
info1 |= max_packet(maxp) << 16;
|
2005-04-17 05:20:36 +07:00
|
|
|
info2 |= (EHCI_TUNE_MULT_HS << 30);
|
|
|
|
} else { /* PIPE_INTERRUPT */
|
|
|
|
info1 |= max_packet (maxp) << 16;
|
|
|
|
info2 |= hb_mult (maxp) << 30;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2012-05-02 11:33:35 +07:00
|
|
|
ehci_dbg(ehci, "bogus dev %p speed %d\n", urb->dev,
|
|
|
|
urb->dev->speed);
|
2005-04-17 05:20:36 +07:00
|
|
|
done:
|
2012-07-11 22:21:25 +07:00
|
|
|
qh_destroy(ehci, qh);
|
2005-04-17 05:20:36 +07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE: if (PIPE_INTERRUPT) { scheduler sets s-mask } */
|
|
|
|
|
2013-03-23 00:30:43 +07:00
|
|
|
/* init as live, toggle clear */
|
2005-04-17 05:20:36 +07:00
|
|
|
qh->qh_state = QH_STATE_IDLE;
|
2009-07-14 06:23:29 +07:00
|
|
|
hw = qh->hw;
|
|
|
|
hw->hw_info1 = cpu_to_hc32(ehci, info1);
|
|
|
|
hw->hw_info2 = cpu_to_hc32(ehci, info2);
|
2011-07-20 01:01:23 +07:00
|
|
|
qh->is_out = !is_input;
|
2009-06-12 01:56:22 +07:00
|
|
|
usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1);
|
2005-04-17 05:20:36 +07:00
|
|
|
return qh;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2012-07-11 22:22:21 +07:00
|
|
|
static void enable_async(struct ehci_hcd *ehci)
|
|
|
|
{
|
|
|
|
if (ehci->async_count++)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Stop waiting to turn off the async schedule */
|
|
|
|
ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_DISABLE_ASYNC);
|
|
|
|
|
|
|
|
/* Don't start the schedule until ASS is 0 */
|
|
|
|
ehci_poll_ASS(ehci);
|
2012-07-11 22:23:04 +07:00
|
|
|
turn_on_io_watchdog(ehci);
|
2012-07-11 22:22:21 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void disable_async(struct ehci_hcd *ehci)
|
|
|
|
{
|
|
|
|
if (--ehci->async_count)
|
|
|
|
return;
|
|
|
|
|
2013-03-23 00:31:45 +07:00
|
|
|
/* The async schedule and unlink lists are supposed to be empty */
|
|
|
|
WARN_ON(ehci->async->qh_next.qh || !list_empty(&ehci->async_unlink) ||
|
2013-03-23 00:31:58 +07:00
|
|
|
!list_empty(&ehci->async_idle));
|
2012-07-11 22:22:21 +07:00
|
|
|
|
|
|
|
/* Don't turn off the schedule until ASS is 1 */
|
|
|
|
ehci_poll_ASS(ehci);
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* move qh (and its qtds) onto async queue; maybe enable queue. */
|
|
|
|
|
|
|
|
static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
|
|
|
|
{
|
2007-05-01 23:29:37 +07:00
|
|
|
__hc32 dma = QH_NEXT(ehci, qh->qh_dma);
|
2005-04-17 05:20:36 +07:00
|
|
|
struct ehci_qh *head;
|
|
|
|
|
2009-06-29 21:47:30 +07:00
|
|
|
/* Don't link a QH if there's a Clear-TT-Buffer pending */
|
|
|
|
if (unlikely(qh->clearing_tt))
|
|
|
|
return;
|
|
|
|
|
2009-08-19 23:22:06 +07:00
|
|
|
WARN_ON(qh->qh_state != QH_STATE_IDLE);
|
|
|
|
|
2009-06-12 01:56:22 +07:00
|
|
|
/* clear halt and/or toggle; and maybe recover from silicon quirk */
|
2009-08-19 23:22:06 +07:00
|
|
|
qh_refresh(ehci, qh);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* splice right after start */
|
2012-07-11 22:22:21 +07:00
|
|
|
head = ehci->async;
|
2005-04-17 05:20:36 +07:00
|
|
|
qh->qh_next = head->qh_next;
|
2009-07-14 06:23:29 +07:00
|
|
|
qh->hw->hw_next = head->hw->hw_next;
|
2005-04-17 05:20:36 +07:00
|
|
|
wmb ();
|
|
|
|
|
|
|
|
head->qh_next.qh = qh;
|
2009-07-14 06:23:29 +07:00
|
|
|
head->hw->hw_next = dma;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
qh->qh_state = QH_STATE_LINKED;
|
2013-03-23 00:31:11 +07:00
|
|
|
qh->xacterrs = 0;
|
2016-01-26 03:42:04 +07:00
|
|
|
qh->unlink_reason = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
/* qtd completions reported later by interrupt */
|
2012-07-11 22:22:21 +07:00
|
|
|
|
|
|
|
enable_async(ehci);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For control/bulk/interrupt, return QH with these TDs appended.
|
|
|
|
* Allocates and initializes the QH if necessary.
|
|
|
|
* Returns null if it can't allocate a QH it needs to.
|
|
|
|
* If the QH has TDs (urbs) already, that's great.
|
|
|
|
*/
|
|
|
|
static struct ehci_qh *qh_append_tds (
|
|
|
|
struct ehci_hcd *ehci,
|
|
|
|
struct urb *urb,
|
|
|
|
struct list_head *qtd_list,
|
|
|
|
int epnum,
|
|
|
|
void **ptr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct ehci_qh *qh = NULL;
|
2008-04-28 13:00:16 +07:00
|
|
|
__hc32 qh_addr_mask = cpu_to_hc32(ehci, 0x7f);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
qh = (struct ehci_qh *) *ptr;
|
|
|
|
if (unlikely (qh == NULL)) {
|
|
|
|
/* can't sleep here, we have ehci->lock... */
|
|
|
|
qh = qh_make (ehci, urb, GFP_ATOMIC);
|
|
|
|
*ptr = qh;
|
|
|
|
}
|
|
|
|
if (likely (qh != NULL)) {
|
|
|
|
struct ehci_qtd *qtd;
|
|
|
|
|
|
|
|
if (unlikely (list_empty (qtd_list)))
|
|
|
|
qtd = NULL;
|
|
|
|
else
|
|
|
|
qtd = list_entry (qtd_list->next, struct ehci_qtd,
|
|
|
|
qtd_list);
|
|
|
|
|
|
|
|
/* control qh may need patching ... */
|
|
|
|
if (unlikely (epnum == 0)) {
|
|
|
|
|
|
|
|
/* usb_reset_device() briefly reverts to address 0 */
|
|
|
|
if (usb_pipedevice (urb->pipe) == 0)
|
2009-07-14 06:23:29 +07:00
|
|
|
qh->hw->hw_info1 &= ~qh_addr_mask;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* just one way to queue requests: swap with the dummy qtd.
|
|
|
|
* only hc or qh_refresh() ever modify the overlay.
|
|
|
|
*/
|
|
|
|
if (likely (qtd != NULL)) {
|
|
|
|
struct ehci_qtd *dummy;
|
|
|
|
dma_addr_t dma;
|
2007-05-01 23:29:37 +07:00
|
|
|
__hc32 token;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* to avoid racing the HC, use the dummy td instead of
|
|
|
|
* the first td of our list (becomes new dummy). both
|
|
|
|
* tds stay deactivated until we're done, when the
|
|
|
|
* HC is allowed to fetch the old dummy (4.10.2).
|
|
|
|
*/
|
|
|
|
token = qtd->hw_token;
|
2007-05-01 23:29:37 +07:00
|
|
|
qtd->hw_token = HALT_BIT(ehci);
|
2011-09-05 20:05:58 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
dummy = qh->dummy;
|
|
|
|
|
|
|
|
dma = dummy->qtd_dma;
|
|
|
|
*dummy = *qtd;
|
|
|
|
dummy->qtd_dma = dma;
|
|
|
|
|
|
|
|
list_del (&qtd->qtd_list);
|
|
|
|
list_add (&dummy->qtd_list, qtd_list);
|
2008-08-07 05:21:26 +07:00
|
|
|
list_splice_tail(qtd_list, &qh->qtd_list);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-05-01 23:29:37 +07:00
|
|
|
ehci_qtd_init(ehci, qtd, qtd->qtd_dma);
|
2005-04-17 05:20:36 +07:00
|
|
|
qh->dummy = qtd;
|
|
|
|
|
|
|
|
/* hc must see the new dummy at list end */
|
|
|
|
dma = qtd->qtd_dma;
|
|
|
|
qtd = list_entry (qh->qtd_list.prev,
|
|
|
|
struct ehci_qtd, qtd_list);
|
2007-05-01 23:29:37 +07:00
|
|
|
qtd->hw_next = QTD_NEXT(ehci, dma);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* let the hc process these next qtds */
|
|
|
|
wmb ();
|
|
|
|
dummy->hw_token = token;
|
|
|
|
|
2012-07-11 22:21:25 +07:00
|
|
|
urb->hcpriv = qh;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return qh;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
submit_async (
|
|
|
|
struct ehci_hcd *ehci,
|
|
|
|
struct urb *urb,
|
|
|
|
struct list_head *qtd_list,
|
2005-10-21 14:21:58 +07:00
|
|
|
gfp_t mem_flags
|
2005-04-17 05:20:36 +07:00
|
|
|
) {
|
|
|
|
int epnum;
|
|
|
|
unsigned long flags;
|
|
|
|
struct ehci_qh *qh = NULL;
|
2007-08-08 22:48:02 +07:00
|
|
|
int rc;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-08-08 22:48:02 +07:00
|
|
|
epnum = urb->ep->desc.bEndpointAddress;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#ifdef EHCI_URB_TRACE
|
2011-01-26 00:59:36 +07:00
|
|
|
{
|
|
|
|
struct ehci_qtd *qtd;
|
|
|
|
qtd = list_entry(qtd_list->next, struct ehci_qtd, qtd_list);
|
|
|
|
ehci_dbg(ehci,
|
|
|
|
"%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n",
|
|
|
|
__func__, urb->dev->devpath, urb,
|
|
|
|
epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out",
|
|
|
|
urb->transfer_buffer_length,
|
|
|
|
qtd, urb->ep->hcpriv);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
spin_lock_irqsave (&ehci->lock, flags);
|
2010-06-23 03:39:10 +07:00
|
|
|
if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
|
[PATCH] USB: Fix USB suspend/resume crasher (#2)
This patch closes the IRQ race and makes various other OHCI & EHCI code
path safer vs. suspend/resume.
I've been able to (finally !) successfully suspend and resume various
Mac models, with or without USB mouse plugged, or plugging while asleep,
or unplugging while asleep etc... all without a crash.
Alan, please verify the UHCI bit I did, I only verified that it builds.
It's very simple so I wouldn't expect any issue there. If you aren't
confident, then just drop the hunks that change uhci-hcd.c
I also made the patch a little bit more "safer" by making sure the store
to the interrupt register that disables interrupts is not posted before
I set the flag and drop the spinlock.
Without this patch, you cannot reliably sleep/wakeup any recent Mac, and
I suspect PCs have some more sneaky issues too (they don't frankly crash
with machine checks because x86 tend to silently swallow PCI errors but
that won't last afaik, at least PCI Express will blow up in those
situations, but the USB code may still misbehave).
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2005-11-25 05:59:46 +07:00
|
|
|
rc = -ESHUTDOWN;
|
|
|
|
goto done;
|
|
|
|
}
|
2007-08-08 22:48:02 +07:00
|
|
|
rc = usb_hcd_link_urb_to_ep(ehci_to_hcd(ehci), urb);
|
|
|
|
if (unlikely(rc))
|
|
|
|
goto done;
|
[PATCH] USB: Fix USB suspend/resume crasher (#2)
This patch closes the IRQ race and makes various other OHCI & EHCI code
path safer vs. suspend/resume.
I've been able to (finally !) successfully suspend and resume various
Mac models, with or without USB mouse plugged, or plugging while asleep,
or unplugging while asleep etc... all without a crash.
Alan, please verify the UHCI bit I did, I only verified that it builds.
It's very simple so I wouldn't expect any issue there. If you aren't
confident, then just drop the hunks that change uhci-hcd.c
I also made the patch a little bit more "safer" by making sure the store
to the interrupt register that disables interrupts is not posted before
I set the flag and drop the spinlock.
Without this patch, you cannot reliably sleep/wakeup any recent Mac, and
I suspect PCs have some more sneaky issues too (they don't frankly crash
with machine checks because x86 tend to silently swallow PCI errors but
that won't last afaik, at least PCI Express will blow up in those
situations, but the USB code may still misbehave).
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2005-11-25 05:59:46 +07:00
|
|
|
|
2007-08-08 22:48:02 +07:00
|
|
|
qh = qh_append_tds(ehci, urb, qtd_list, epnum, &urb->ep->hcpriv);
|
[PATCH] USB: Fix USB suspend/resume crasher (#2)
This patch closes the IRQ race and makes various other OHCI & EHCI code
path safer vs. suspend/resume.
I've been able to (finally !) successfully suspend and resume various
Mac models, with or without USB mouse plugged, or plugging while asleep,
or unplugging while asleep etc... all without a crash.
Alan, please verify the UHCI bit I did, I only verified that it builds.
It's very simple so I wouldn't expect any issue there. If you aren't
confident, then just drop the hunks that change uhci-hcd.c
I also made the patch a little bit more "safer" by making sure the store
to the interrupt register that disables interrupts is not posted before
I set the flag and drop the spinlock.
Without this patch, you cannot reliably sleep/wakeup any recent Mac, and
I suspect PCs have some more sneaky issues too (they don't frankly crash
with machine checks because x86 tend to silently swallow PCI errors but
that won't last afaik, at least PCI Express will blow up in those
situations, but the USB code may still misbehave).
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2005-11-25 05:59:46 +07:00
|
|
|
if (unlikely(qh == NULL)) {
|
2007-08-08 22:48:02 +07:00
|
|
|
usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
|
[PATCH] USB: Fix USB suspend/resume crasher (#2)
This patch closes the IRQ race and makes various other OHCI & EHCI code
path safer vs. suspend/resume.
I've been able to (finally !) successfully suspend and resume various
Mac models, with or without USB mouse plugged, or plugging while asleep,
or unplugging while asleep etc... all without a crash.
Alan, please verify the UHCI bit I did, I only verified that it builds.
It's very simple so I wouldn't expect any issue there. If you aren't
confident, then just drop the hunks that change uhci-hcd.c
I also made the patch a little bit more "safer" by making sure the store
to the interrupt register that disables interrupts is not posted before
I set the flag and drop the spinlock.
Without this patch, you cannot reliably sleep/wakeup any recent Mac, and
I suspect PCs have some more sneaky issues too (they don't frankly crash
with machine checks because x86 tend to silently swallow PCI errors but
that won't last afaik, at least PCI Express will blow up in those
situations, but the USB code may still misbehave).
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2005-11-25 05:59:46 +07:00
|
|
|
rc = -ENOMEM;
|
|
|
|
goto done;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* Control/bulk operations through TTs don't need scheduling,
|
|
|
|
* the HC and TT handle it when the TT has a buffer ready.
|
|
|
|
*/
|
[PATCH] USB: Fix USB suspend/resume crasher (#2)
This patch closes the IRQ race and makes various other OHCI & EHCI code
path safer vs. suspend/resume.
I've been able to (finally !) successfully suspend and resume various
Mac models, with or without USB mouse plugged, or plugging while asleep,
or unplugging while asleep etc... all without a crash.
Alan, please verify the UHCI bit I did, I only verified that it builds.
It's very simple so I wouldn't expect any issue there. If you aren't
confident, then just drop the hunks that change uhci-hcd.c
I also made the patch a little bit more "safer" by making sure the store
to the interrupt register that disables interrupts is not posted before
I set the flag and drop the spinlock.
Without this patch, you cannot reliably sleep/wakeup any recent Mac, and
I suspect PCs have some more sneaky issues too (they don't frankly crash
with machine checks because x86 tend to silently swallow PCI errors but
that won't last afaik, at least PCI Express will blow up in those
situations, but the USB code may still misbehave).
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2005-11-25 05:59:46 +07:00
|
|
|
if (likely (qh->qh_state == QH_STATE_IDLE))
|
2009-07-31 21:40:22 +07:00
|
|
|
qh_link_async(ehci, qh);
|
[PATCH] USB: Fix USB suspend/resume crasher (#2)
This patch closes the IRQ race and makes various other OHCI & EHCI code
path safer vs. suspend/resume.
I've been able to (finally !) successfully suspend and resume various
Mac models, with or without USB mouse plugged, or plugging while asleep,
or unplugging while asleep etc... all without a crash.
Alan, please verify the UHCI bit I did, I only verified that it builds.
It's very simple so I wouldn't expect any issue there. If you aren't
confident, then just drop the hunks that change uhci-hcd.c
I also made the patch a little bit more "safer" by making sure the store
to the interrupt register that disables interrupts is not posted before
I set the flag and drop the spinlock.
Without this patch, you cannot reliably sleep/wakeup any recent Mac, and
I suspect PCs have some more sneaky issues too (they don't frankly crash
with machine checks because x86 tend to silently swallow PCI errors but
that won't last afaik, at least PCI Express will blow up in those
situations, but the USB code may still misbehave).
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2005-11-25 05:59:46 +07:00
|
|
|
done:
|
2005-04-17 05:20:36 +07:00
|
|
|
spin_unlock_irqrestore (&ehci->lock, flags);
|
[PATCH] USB: Fix USB suspend/resume crasher (#2)
This patch closes the IRQ race and makes various other OHCI & EHCI code
path safer vs. suspend/resume.
I've been able to (finally !) successfully suspend and resume various
Mac models, with or without USB mouse plugged, or plugging while asleep,
or unplugging while asleep etc... all without a crash.
Alan, please verify the UHCI bit I did, I only verified that it builds.
It's very simple so I wouldn't expect any issue there. If you aren't
confident, then just drop the hunks that change uhci-hcd.c
I also made the patch a little bit more "safer" by making sure the store
to the interrupt register that disables interrupts is not posted before
I set the flag and drop the spinlock.
Without this patch, you cannot reliably sleep/wakeup any recent Mac, and
I suspect PCs have some more sneaky issues too (they don't frankly crash
with machine checks because x86 tend to silently swallow PCI errors but
that won't last afaik, at least PCI Express will blow up in those
situations, but the USB code may still misbehave).
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2005-11-25 05:59:46 +07:00
|
|
|
if (unlikely (qh == NULL))
|
2005-04-17 05:20:36 +07:00
|
|
|
qtd_list_free (ehci, urb, qtd_list);
|
[PATCH] USB: Fix USB suspend/resume crasher (#2)
This patch closes the IRQ race and makes various other OHCI & EHCI code
path safer vs. suspend/resume.
I've been able to (finally !) successfully suspend and resume various
Mac models, with or without USB mouse plugged, or plugging while asleep,
or unplugging while asleep etc... all without a crash.
Alan, please verify the UHCI bit I did, I only verified that it builds.
It's very simple so I wouldn't expect any issue there. If you aren't
confident, then just drop the hunks that change uhci-hcd.c
I also made the patch a little bit more "safer" by making sure the store
to the interrupt register that disables interrupts is not posted before
I set the flag and drop the spinlock.
Without this patch, you cannot reliably sleep/wakeup any recent Mac, and
I suspect PCs have some more sneaky issues too (they don't frankly crash
with machine checks because x86 tend to silently swallow PCI errors but
that won't last afaik, at least PCI Express will blow up in those
situations, but the USB code may still misbehave).
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2005-11-25 05:59:46 +07:00
|
|
|
return rc;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
2013-08-14 03:40:13 +07:00
|
|
|
#ifdef CONFIG_USB_HCD_TEST_MODE
|
2013-08-09 06:49:24 +07:00
|
|
|
/*
|
|
|
|
* This function creates the qtds and submits them for the
|
|
|
|
* SINGLE_STEP_SET_FEATURE Test.
|
|
|
|
* This is done in two parts: first SETUP req for GetDesc is sent then
|
|
|
|
* 15 seconds later, the IN stage for GetDesc starts to req data from dev
|
|
|
|
*
|
|
|
|
* is_setup : i/p arguement decides which of the two stage needs to be
|
|
|
|
* performed; TRUE - SETUP and FALSE - IN+STATUS
|
|
|
|
* Returns 0 if success
|
|
|
|
*/
|
|
|
|
static int submit_single_step_set_feature(
|
|
|
|
struct usb_hcd *hcd,
|
|
|
|
struct urb *urb,
|
|
|
|
int is_setup
|
|
|
|
) {
|
|
|
|
struct ehci_hcd *ehci = hcd_to_ehci(hcd);
|
|
|
|
struct list_head qtd_list;
|
|
|
|
struct list_head *head;
|
|
|
|
|
|
|
|
struct ehci_qtd *qtd, *qtd_prev;
|
|
|
|
dma_addr_t buf;
|
|
|
|
int len, maxpacket;
|
|
|
|
u32 token;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&qtd_list);
|
|
|
|
head = &qtd_list;
|
|
|
|
|
|
|
|
/* URBs map to sequences of QTDs: one logical transaction */
|
|
|
|
qtd = ehci_qtd_alloc(ehci, GFP_KERNEL);
|
|
|
|
if (unlikely(!qtd))
|
|
|
|
return -1;
|
|
|
|
list_add_tail(&qtd->qtd_list, head);
|
|
|
|
qtd->urb = urb;
|
|
|
|
|
|
|
|
token = QTD_STS_ACTIVE;
|
|
|
|
token |= (EHCI_TUNE_CERR << 10);
|
|
|
|
|
|
|
|
len = urb->transfer_buffer_length;
|
|
|
|
/*
|
|
|
|
* Check if the request is to perform just the SETUP stage (getDesc)
|
|
|
|
* as in SINGLE_STEP_SET_FEATURE test, DATA stage (IN) happens
|
|
|
|
* 15 secs after the setup
|
|
|
|
*/
|
|
|
|
if (is_setup) {
|
|
|
|
/* SETUP pid */
|
|
|
|
qtd_fill(ehci, qtd, urb->setup_dma,
|
|
|
|
sizeof(struct usb_ctrlrequest),
|
|
|
|
token | (2 /* "setup" */ << 8), 8);
|
|
|
|
|
|
|
|
submit_async(ehci, urb, &qtd_list, GFP_ATOMIC);
|
|
|
|
return 0; /*Return now; we shall come back after 15 seconds*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IN: data transfer stage: buffer setup : start the IN txn phase for
|
|
|
|
* the get_Desc SETUP which was sent 15seconds back
|
|
|
|
*/
|
|
|
|
token ^= QTD_TOGGLE; /*We need to start IN with DATA-1 Pid-sequence*/
|
|
|
|
buf = urb->transfer_dma;
|
|
|
|
|
|
|
|
token |= (1 /* "in" */ << 8); /*This is IN stage*/
|
|
|
|
|
|
|
|
maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, 0));
|
|
|
|
|
|
|
|
qtd_fill(ehci, qtd, buf, len, token, maxpacket);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our IN phase shall always be a short read; so keep the queue running
|
|
|
|
* and let it advance to the next qtd which zero length OUT status
|
|
|
|
*/
|
|
|
|
qtd->hw_alt_next = EHCI_LIST_END(ehci);
|
|
|
|
|
|
|
|
/* STATUS stage for GetDesc control request */
|
|
|
|
token ^= 0x0100; /* "in" <--> "out" */
|
|
|
|
token |= QTD_TOGGLE; /* force DATA1 */
|
|
|
|
|
|
|
|
qtd_prev = qtd;
|
|
|
|
qtd = ehci_qtd_alloc(ehci, GFP_ATOMIC);
|
|
|
|
if (unlikely(!qtd))
|
|
|
|
goto cleanup;
|
|
|
|
qtd->urb = urb;
|
|
|
|
qtd_prev->hw_next = QTD_NEXT(ehci, qtd->qtd_dma);
|
|
|
|
list_add_tail(&qtd->qtd_list, head);
|
|
|
|
|
|
|
|
/* dont fill any data in such packets */
|
|
|
|
qtd_fill(ehci, qtd, 0, 0, token, 0);
|
|
|
|
|
|
|
|
/* by default, enable interrupt on urb completion */
|
|
|
|
if (likely(!(urb->transfer_flags & URB_NO_INTERRUPT)))
|
|
|
|
qtd->hw_token |= cpu_to_hc32(ehci, QTD_IOC);
|
|
|
|
|
|
|
|
submit_async(ehci, urb, &qtd_list, GFP_KERNEL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
qtd_list_free(ehci, urb, head);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-08-14 03:40:13 +07:00
|
|
|
#endif /* CONFIG_USB_HCD_TEST_MODE */
|
2013-08-09 06:49:24 +07:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-07-11 22:22:49 +07:00
|
|
|
static void single_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2012-07-11 22:22:49 +07:00
|
|
|
struct ehci_qh *prev;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-07-11 22:22:49 +07:00
|
|
|
/* Add to the end of the list of QHs waiting for the next IAAD */
|
2013-03-01 22:50:08 +07:00
|
|
|
qh->qh_state = QH_STATE_UNLINK_WAIT;
|
2013-03-23 00:31:45 +07:00
|
|
|
list_add_tail(&qh->unlink_node, &ehci->async_unlink);
|
2012-07-11 22:22:49 +07:00
|
|
|
|
|
|
|
/* Unlink it from the schedule */
|
|
|
|
prev = ehci->async;
|
|
|
|
while (prev->qh_next.qh != qh)
|
|
|
|
prev = prev->qh_next.qh;
|
|
|
|
|
|
|
|
prev->hw->hw_next = qh->hw->hw_next;
|
|
|
|
prev->qh_next = qh->qh_next;
|
|
|
|
if (ehci->qh_scan_next == qh)
|
|
|
|
ehci->qh_scan_next = qh->qh_next.qh;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-03-23 00:31:58 +07:00
|
|
|
static void start_iaa_cycle(struct ehci_hcd *ehci)
|
2012-07-11 22:22:49 +07:00
|
|
|
{
|
|
|
|
/* If the controller isn't running, we don't have to wait for it */
|
|
|
|
if (unlikely(ehci->rh_state < EHCI_RH_RUNNING)) {
|
2013-03-23 00:31:58 +07:00
|
|
|
end_unlink_async(ehci);
|
2012-07-11 22:22:21 +07:00
|
|
|
|
2016-01-26 03:44:16 +07:00
|
|
|
/* Otherwise start a new IAA cycle if one isn't already running */
|
|
|
|
} else if (ehci->rh_state == EHCI_RH_RUNNING &&
|
|
|
|
!ehci->iaa_in_progress) {
|
2013-01-26 04:54:22 +07:00
|
|
|
|
2012-07-11 22:22:49 +07:00
|
|
|
/* Make sure the unlinks are all visible to the hardware */
|
|
|
|
wmb();
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-07-11 22:22:49 +07:00
|
|
|
ehci_writel(ehci, ehci->command | CMD_IAAD,
|
|
|
|
&ehci->regs->command);
|
|
|
|
ehci_readl(ehci, &ehci->regs->command);
|
2016-01-26 03:44:16 +07:00
|
|
|
ehci->iaa_in_progress = true;
|
2012-07-11 22:22:49 +07:00
|
|
|
ehci_enable_event(ehci, EHCI_HRTIMER_IAA_WATCHDOG, true);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2012-07-11 22:22:49 +07:00
|
|
|
}
|
|
|
|
|
2016-01-26 03:44:16 +07:00
|
|
|
static void end_iaa_cycle(struct ehci_hcd *ehci)
|
2012-07-11 22:22:49 +07:00
|
|
|
{
|
2011-04-13 15:54:23 +07:00
|
|
|
if (ehci->has_synopsys_hc_bug)
|
|
|
|
ehci_writel(ehci, (u32) ehci->async->qh_dma,
|
|
|
|
&ehci->regs->async_next);
|
2012-07-11 22:22:49 +07:00
|
|
|
|
2013-03-23 00:31:58 +07:00
|
|
|
/* The current IAA cycle has ended */
|
|
|
|
ehci->iaa_in_progress = false;
|
|
|
|
|
2016-01-26 03:44:16 +07:00
|
|
|
end_unlink_async(ehci);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See if the async qh for the qtds being unlinked are now gone from the HC */
|
|
|
|
|
|
|
|
static void end_unlink_async(struct ehci_hcd *ehci)
|
|
|
|
{
|
|
|
|
struct ehci_qh *qh;
|
|
|
|
bool early_exit;
|
|
|
|
|
2013-03-23 00:31:58 +07:00
|
|
|
if (list_empty(&ehci->async_unlink))
|
|
|
|
return;
|
|
|
|
qh = list_first_entry(&ehci->async_unlink, struct ehci_qh,
|
|
|
|
unlink_node); /* QH whose IAA cycle just ended */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If async_unlinking is set then this routine is already running,
|
|
|
|
* either on the stack or on another CPU.
|
|
|
|
*/
|
|
|
|
early_exit = ehci->async_unlinking;
|
|
|
|
|
|
|
|
/* If the controller isn't running, process all the waiting QHs */
|
|
|
|
if (ehci->rh_state < EHCI_RH_RUNNING)
|
|
|
|
list_splice_tail_init(&ehci->async_unlink, &ehci->async_idle);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Intel (?) bug: The HC can write back the overlay region even
|
|
|
|
* after the IAA interrupt occurs. In self-defense, always go
|
|
|
|
* through two IAA cycles for each QH.
|
|
|
|
*/
|
USB: EHCI: add a delay when unlinking an active QH
Michael Reutman reports that an AMD/ATI EHCI host controller on one of
his computers does not stop transferring data when an active bulk QH
is unlinked from the async schedule. Apparently that host controller
fails to implement the IAA mechanism correctly when an active QH is
unlinked. This leads to data corruption, because the controller
continues to update the QH in memory when the driver doesn't expect
it. As a result, the next URB submitted for that QH can hang, because
the link pointers for the TD queue have been messed up. This
misbehavior is observed quite regularly.
To be fair, the EHCI spec (section 4.8.2) says that active QHs should
not be unlinked. It goes on to recommend a procedure that involves
waiting for the QH to go inactive before unlinking it. In the real
world this is impractical, not least because the QH may _never_ go
inactive. (What were they thinking?) Sometimes we have no choice but
to unlink an active QH.
In an attempt to avoid the problems that can ensue, this patch changes
how the driver decides when the unlink is complete. In addition to
waiting through two IAA cycles, in cases where the QH was not known to
be inactive beforehand we now wait until a 2-ms period has elapsed
with the host controller making no change to the QH data structure
(the hw_current and hw_token fields in particular). The intuition
here is that after such a long period, the endpoint must be NAKing and
hopefully the QH has been dropped from the host controller's internal
cache. There's no way to know if this reasoning is really valid --
the spec is no help in this regard -- but at least this approach fixes
Michael's problem.
The test for whether the QH is already known to be inactive involves
the reason for unlinking the QH originally. If it was unlinked
because it had halted, or it stopped in response to a short read, or
it overlaid a dummy TD (a silicon bug), then it certainly is inactive.
If it was unlinked because the TD queue was empty and no TDs have been
added to the queue in the meantime, then it must be inactive. Or if
the hardware status indicates that the QH is currently halted (even if
that wasn't the reason for unlinking it), then it is inactive.
Otherwise, if none of those checks apply, we go through the 2-ms
delay.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Reported-by: Michael Reutman <mreutman@epiqsolutions.com>
Tested-by: Michael Reutman <mreutman@epiqsolutions.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-01-26 03:45:25 +07:00
|
|
|
else if (qh->qh_state == QH_STATE_UNLINK) {
|
|
|
|
/*
|
|
|
|
* Second IAA cycle has finished. Process only the first
|
|
|
|
* waiting QH (NVIDIA (?) bug).
|
|
|
|
*/
|
|
|
|
list_move_tail(&qh->unlink_node, &ehci->async_idle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AMD/ATI (?) bug: The HC can continue to use an active QH long
|
|
|
|
* after the IAA interrupt occurs. To prevent problems, QHs that
|
|
|
|
* may still be active will wait until 2 ms have passed with no
|
|
|
|
* change to the hw_current and hw_token fields (this delay occurs
|
|
|
|
* between the two IAA cycles).
|
|
|
|
*
|
|
|
|
* The EHCI spec (4.8.2) says that active QHs must not be removed
|
|
|
|
* from the async schedule and recommends waiting until the QH
|
|
|
|
* goes inactive. This is ridiculous because the QH will _never_
|
|
|
|
* become inactive if the endpoint NAKs indefinitely.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Some reasons for unlinking guarantee the QH can't be active */
|
|
|
|
else if (qh->unlink_reason & (QH_UNLINK_HALTED |
|
|
|
|
QH_UNLINK_SHORT_READ | QH_UNLINK_DUMMY_OVERLAY))
|
|
|
|
goto DelayDone;
|
|
|
|
|
|
|
|
/* The QH can't be active if the queue was and still is empty... */
|
|
|
|
else if ((qh->unlink_reason & QH_UNLINK_QUEUE_EMPTY) &&
|
|
|
|
list_empty(&qh->qtd_list))
|
|
|
|
goto DelayDone;
|
|
|
|
|
|
|
|
/* ... or if the QH has halted */
|
|
|
|
else if (qh->hw->hw_token & cpu_to_hc32(ehci, QTD_STS_HALT))
|
|
|
|
goto DelayDone;
|
|
|
|
|
|
|
|
/* Otherwise we have to wait until the QH stops changing */
|
|
|
|
else {
|
|
|
|
__hc32 qh_current, qh_token;
|
|
|
|
|
|
|
|
qh_current = qh->hw->hw_current;
|
|
|
|
qh_token = qh->hw->hw_token;
|
|
|
|
if (qh_current != ehci->old_current ||
|
|
|
|
qh_token != ehci->old_token) {
|
|
|
|
ehci->old_current = qh_current;
|
|
|
|
ehci->old_token = qh_token;
|
|
|
|
ehci_enable_event(ehci,
|
|
|
|
EHCI_HRTIMER_ACTIVE_UNLINK, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DelayDone:
|
2013-03-23 00:31:58 +07:00
|
|
|
qh->qh_state = QH_STATE_UNLINK;
|
|
|
|
early_exit = true;
|
|
|
|
}
|
USB: EHCI: add a delay when unlinking an active QH
Michael Reutman reports that an AMD/ATI EHCI host controller on one of
his computers does not stop transferring data when an active bulk QH
is unlinked from the async schedule. Apparently that host controller
fails to implement the IAA mechanism correctly when an active QH is
unlinked. This leads to data corruption, because the controller
continues to update the QH in memory when the driver doesn't expect
it. As a result, the next URB submitted for that QH can hang, because
the link pointers for the TD queue have been messed up. This
misbehavior is observed quite regularly.
To be fair, the EHCI spec (section 4.8.2) says that active QHs should
not be unlinked. It goes on to recommend a procedure that involves
waiting for the QH to go inactive before unlinking it. In the real
world this is impractical, not least because the QH may _never_ go
inactive. (What were they thinking?) Sometimes we have no choice but
to unlink an active QH.
In an attempt to avoid the problems that can ensue, this patch changes
how the driver decides when the unlink is complete. In addition to
waiting through two IAA cycles, in cases where the QH was not known to
be inactive beforehand we now wait until a 2-ms period has elapsed
with the host controller making no change to the QH data structure
(the hw_current and hw_token fields in particular). The intuition
here is that after such a long period, the endpoint must be NAKing and
hopefully the QH has been dropped from the host controller's internal
cache. There's no way to know if this reasoning is really valid --
the spec is no help in this regard -- but at least this approach fixes
Michael's problem.
The test for whether the QH is already known to be inactive involves
the reason for unlinking the QH originally. If it was unlinked
because it had halted, or it stopped in response to a short read, or
it overlaid a dummy TD (a silicon bug), then it certainly is inactive.
If it was unlinked because the TD queue was empty and no TDs have been
added to the queue in the meantime, then it must be inactive. Or if
the hardware status indicates that the QH is currently halted (even if
that wasn't the reason for unlinking it), then it is inactive.
Otherwise, if none of those checks apply, we go through the 2-ms
delay.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Reported-by: Michael Reutman <mreutman@epiqsolutions.com>
Tested-by: Michael Reutman <mreutman@epiqsolutions.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-01-26 03:45:25 +07:00
|
|
|
ehci->old_current = ~0; /* Prepare for next QH */
|
2013-03-23 00:31:58 +07:00
|
|
|
|
|
|
|
/* Start a new IAA cycle if any QHs are waiting for it */
|
|
|
|
if (!list_empty(&ehci->async_unlink))
|
|
|
|
start_iaa_cycle(ehci);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't allow nesting or concurrent calls,
|
|
|
|
* or wait for the second IAA cycle for the next QH.
|
|
|
|
*/
|
|
|
|
if (early_exit)
|
|
|
|
return;
|
|
|
|
|
2012-07-11 22:22:49 +07:00
|
|
|
/* Process the idle QHs */
|
|
|
|
ehci->async_unlinking = true;
|
2013-03-23 00:31:58 +07:00
|
|
|
while (!list_empty(&ehci->async_idle)) {
|
|
|
|
qh = list_first_entry(&ehci->async_idle, struct ehci_qh,
|
2013-03-23 00:31:45 +07:00
|
|
|
unlink_node);
|
|
|
|
list_del(&qh->unlink_node);
|
2012-07-11 22:22:49 +07:00
|
|
|
|
|
|
|
qh->qh_state = QH_STATE_IDLE;
|
|
|
|
qh->qh_next.qh = NULL;
|
|
|
|
|
2013-03-23 00:30:56 +07:00
|
|
|
if (!list_empty(&qh->qtd_list))
|
|
|
|
qh_completions(ehci, qh);
|
2012-07-11 22:22:49 +07:00
|
|
|
if (!list_empty(&qh->qtd_list) &&
|
|
|
|
ehci->rh_state == EHCI_RH_RUNNING)
|
|
|
|
qh_link_async(ehci, qh);
|
|
|
|
disable_async(ehci);
|
|
|
|
}
|
|
|
|
ehci->async_unlinking = false;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2013-01-26 04:54:22 +07:00
|
|
|
static void start_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh);
|
|
|
|
|
2012-07-11 22:22:53 +07:00
|
|
|
static void unlink_empty_async(struct ehci_hcd *ehci)
|
|
|
|
{
|
2013-01-26 04:54:22 +07:00
|
|
|
struct ehci_qh *qh;
|
|
|
|
struct ehci_qh *qh_to_unlink = NULL;
|
|
|
|
int count = 0;
|
2012-07-11 22:22:53 +07:00
|
|
|
|
2013-01-26 04:54:22 +07:00
|
|
|
/* Find the last async QH which has been empty for a timer cycle */
|
|
|
|
for (qh = ehci->async->qh_next.qh; qh; qh = qh->qh_next.qh) {
|
2012-07-11 22:22:53 +07:00
|
|
|
if (list_empty(&qh->qtd_list) &&
|
|
|
|
qh->qh_state == QH_STATE_LINKED) {
|
2013-01-26 04:54:22 +07:00
|
|
|
++count;
|
2013-03-23 00:32:10 +07:00
|
|
|
if (qh->unlink_cycle != ehci->async_unlink_cycle)
|
2013-01-26 04:54:22 +07:00
|
|
|
qh_to_unlink = qh;
|
2012-07-11 22:22:53 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-26 04:54:22 +07:00
|
|
|
/* If nothing else is being unlinked, unlink the last empty QH */
|
2013-03-23 00:31:58 +07:00
|
|
|
if (list_empty(&ehci->async_unlink) && qh_to_unlink) {
|
2016-01-26 03:42:04 +07:00
|
|
|
qh_to_unlink->unlink_reason |= QH_UNLINK_QUEUE_EMPTY;
|
2013-01-26 04:54:22 +07:00
|
|
|
start_unlink_async(ehci, qh_to_unlink);
|
|
|
|
--count;
|
|
|
|
}
|
2012-07-11 22:22:53 +07:00
|
|
|
|
2013-01-26 04:54:22 +07:00
|
|
|
/* Other QHs will be handled later */
|
|
|
|
if (count > 0) {
|
2012-07-11 22:22:53 +07:00
|
|
|
ehci_enable_event(ehci, EHCI_HRTIMER_ASYNC_UNLINKS, true);
|
|
|
|
++ehci->async_unlink_cycle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-26 03:45:38 +07:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
2013-03-16 01:40:26 +07:00
|
|
|
/* The root hub is suspended; unlink all the async QHs */
|
2016-01-26 03:45:38 +07:00
|
|
|
static void unlink_empty_async_suspended(struct ehci_hcd *ehci)
|
2013-03-16 01:40:26 +07:00
|
|
|
{
|
|
|
|
struct ehci_qh *qh;
|
|
|
|
|
|
|
|
while (ehci->async->qh_next.qh) {
|
|
|
|
qh = ehci->async->qh_next.qh;
|
|
|
|
WARN_ON(!list_empty(&qh->qtd_list));
|
|
|
|
single_unlink_async(ehci, qh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-26 03:45:38 +07:00
|
|
|
#endif
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* makes sure the async qh will become idle */
|
|
|
|
/* caller must own ehci->lock */
|
|
|
|
|
2012-07-11 22:22:49 +07:00
|
|
|
static void start_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2013-03-23 00:31:11 +07:00
|
|
|
/* If the QH isn't linked then there's nothing we can do. */
|
|
|
|
if (qh->qh_state != QH_STATE_LINKED)
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
|
2012-07-11 22:22:49 +07:00
|
|
|
single_unlink_async(ehci, qh);
|
2013-03-23 00:31:58 +07:00
|
|
|
start_iaa_cycle(ehci);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 20:55:46 +07:00
|
|
|
static void scan_async (struct ehci_hcd *ehci)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct ehci_qh *qh;
|
2012-07-11 22:22:53 +07:00
|
|
|
bool check_unlinks_later = false;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
USB: EHCI: go back to using the system clock for QH unlinks
This patch (as1477) fixes a problem affecting a few types of EHCI
controller. Contrary to what one might expect, these controllers
automatically stop their internal frame counter when no ports are
enabled. Since ehci-hcd currently relies on the frame counter for
determining when it should unlink QHs from the async schedule, those
controllers run into trouble: The frame counter stops and the QHs
never get unlinked.
Some systems have also experienced other problems traced back to
commit b963801164618e25fbdc0cd452ce49c3628b46c8 (USB: ehci-hcd unlink
speedups), which made the original switch from using the system clock
to using the frame counter. It never became clear what the reason was
for these problems, but evidently it is related to use of the frame
counter.
To fix all these problems, this patch more or less reverts that commit
and goes back to using the system clock. But this can't be done
cleanly because other changes have since been made to the scan_async()
subroutine. One of these changes involved the tricky logic that tries
to avoid rescanning QHs that have already been seen when the scanning
loop is restarted, which happens whenever an URB is given back.
Switching back to clock-based unlinks would make this logic even more
complicated.
Therefore the new code doesn't rescan the entire async list whenever a
giveback occurs. Instead it rescans only the current QH and continues
on from there. This requires the use of a separate pointer to keep
track of the next QH to scan, since the current QH may be unlinked
while the scanning is in progress. That new pointer must be global,
so that it can be adjusted forward whenever the _next_ QH gets
unlinked. (uhci-hcd uses this same trick.)
Simplification of the scanning loop removes a level of indentation,
which accounts for the size of the patch. The amount of code changed
is relatively small, and it isn't exactly a reversion of the
b963801164 commit.
This fixes Bugzilla #32432.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
CC: <stable@kernel.org>
Tested-by: Matej Kenda <matejken@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-07-05 23:34:05 +07:00
|
|
|
ehci->qh_scan_next = ehci->async->qh_next.qh;
|
|
|
|
while (ehci->qh_scan_next) {
|
|
|
|
qh = ehci->qh_scan_next;
|
|
|
|
ehci->qh_scan_next = qh->qh_next.qh;
|
2013-03-23 00:30:56 +07:00
|
|
|
|
USB: EHCI: go back to using the system clock for QH unlinks
This patch (as1477) fixes a problem affecting a few types of EHCI
controller. Contrary to what one might expect, these controllers
automatically stop their internal frame counter when no ports are
enabled. Since ehci-hcd currently relies on the frame counter for
determining when it should unlink QHs from the async schedule, those
controllers run into trouble: The frame counter stops and the QHs
never get unlinked.
Some systems have also experienced other problems traced back to
commit b963801164618e25fbdc0cd452ce49c3628b46c8 (USB: ehci-hcd unlink
speedups), which made the original switch from using the system clock
to using the frame counter. It never became clear what the reason was
for these problems, but evidently it is related to use of the frame
counter.
To fix all these problems, this patch more or less reverts that commit
and goes back to using the system clock. But this can't be done
cleanly because other changes have since been made to the scan_async()
subroutine. One of these changes involved the tricky logic that tries
to avoid rescanning QHs that have already been seen when the scanning
loop is restarted, which happens whenever an URB is given back.
Switching back to clock-based unlinks would make this logic even more
complicated.
Therefore the new code doesn't rescan the entire async list whenever a
giveback occurs. Instead it rescans only the current QH and continues
on from there. This requires the use of a separate pointer to keep
track of the next QH to scan, since the current QH may be unlinked
while the scanning is in progress. That new pointer must be global,
so that it can be adjusted forward whenever the _next_ QH gets
unlinked. (uhci-hcd uses this same trick.)
Simplification of the scanning loop removes a level of indentation,
which accounts for the size of the patch. The amount of code changed
is relatively small, and it isn't exactly a reversion of the
b963801164 commit.
This fixes Bugzilla #32432.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
CC: <stable@kernel.org>
Tested-by: Matej Kenda <matejken@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-07-05 23:34:05 +07:00
|
|
|
/* clean any finished work for this qh */
|
|
|
|
if (!list_empty(&qh->qtd_list)) {
|
|
|
|
int temp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlinks could happen here; completion reporting
|
|
|
|
* drops the lock. That's why ehci->qh_scan_next
|
|
|
|
* always holds the next qh to scan; if the next qh
|
|
|
|
* gets unlinked then ehci->qh_scan_next is adjusted
|
2012-07-11 22:22:49 +07:00
|
|
|
* in single_unlink_async().
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
USB: EHCI: go back to using the system clock for QH unlinks
This patch (as1477) fixes a problem affecting a few types of EHCI
controller. Contrary to what one might expect, these controllers
automatically stop their internal frame counter when no ports are
enabled. Since ehci-hcd currently relies on the frame counter for
determining when it should unlink QHs from the async schedule, those
controllers run into trouble: The frame counter stops and the QHs
never get unlinked.
Some systems have also experienced other problems traced back to
commit b963801164618e25fbdc0cd452ce49c3628b46c8 (USB: ehci-hcd unlink
speedups), which made the original switch from using the system clock
to using the frame counter. It never became clear what the reason was
for these problems, but evidently it is related to use of the frame
counter.
To fix all these problems, this patch more or less reverts that commit
and goes back to using the system clock. But this can't be done
cleanly because other changes have since been made to the scan_async()
subroutine. One of these changes involved the tricky logic that tries
to avoid rescanning QHs that have already been seen when the scanning
loop is restarted, which happens whenever an URB is given back.
Switching back to clock-based unlinks would make this logic even more
complicated.
Therefore the new code doesn't rescan the entire async list whenever a
giveback occurs. Instead it rescans only the current QH and continues
on from there. This requires the use of a separate pointer to keep
track of the next QH to scan, since the current QH may be unlinked
while the scanning is in progress. That new pointer must be global,
so that it can be adjusted forward whenever the _next_ QH gets
unlinked. (uhci-hcd uses this same trick.)
Simplification of the scanning loop removes a level of indentation,
which accounts for the size of the patch. The amount of code changed
is relatively small, and it isn't exactly a reversion of the
b963801164 commit.
This fixes Bugzilla #32432.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
CC: <stable@kernel.org>
Tested-by: Matej Kenda <matejken@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-07-05 23:34:05 +07:00
|
|
|
temp = qh_completions(ehci, qh);
|
2013-03-23 00:30:56 +07:00
|
|
|
if (unlikely(temp)) {
|
2012-07-11 22:22:49 +07:00
|
|
|
start_unlink_async(ehci, qh);
|
2012-07-11 22:22:53 +07:00
|
|
|
} else if (list_empty(&qh->qtd_list)
|
|
|
|
&& qh->qh_state == QH_STATE_LINKED) {
|
|
|
|
qh->unlink_cycle = ehci->async_unlink_cycle;
|
|
|
|
check_unlinks_later = true;
|
2013-03-23 00:30:56 +07:00
|
|
|
}
|
USB: EHCI: go back to using the system clock for QH unlinks
This patch (as1477) fixes a problem affecting a few types of EHCI
controller. Contrary to what one might expect, these controllers
automatically stop their internal frame counter when no ports are
enabled. Since ehci-hcd currently relies on the frame counter for
determining when it should unlink QHs from the async schedule, those
controllers run into trouble: The frame counter stops and the QHs
never get unlinked.
Some systems have also experienced other problems traced back to
commit b963801164618e25fbdc0cd452ce49c3628b46c8 (USB: ehci-hcd unlink
speedups), which made the original switch from using the system clock
to using the frame counter. It never became clear what the reason was
for these problems, but evidently it is related to use of the frame
counter.
To fix all these problems, this patch more or less reverts that commit
and goes back to using the system clock. But this can't be done
cleanly because other changes have since been made to the scan_async()
subroutine. One of these changes involved the tricky logic that tries
to avoid rescanning QHs that have already been seen when the scanning
loop is restarted, which happens whenever an URB is given back.
Switching back to clock-based unlinks would make this logic even more
complicated.
Therefore the new code doesn't rescan the entire async list whenever a
giveback occurs. Instead it rescans only the current QH and continues
on from there. This requires the use of a separate pointer to keep
track of the next QH to scan, since the current QH may be unlinked
while the scanning is in progress. That new pointer must be global,
so that it can be adjusted forward whenever the _next_ QH gets
unlinked. (uhci-hcd uses this same trick.)
Simplification of the scanning loop removes a level of indentation,
which accounts for the size of the patch. The amount of code changed
is relatively small, and it isn't exactly a reversion of the
b963801164 commit.
This fixes Bugzilla #32432.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
CC: <stable@kernel.org>
Tested-by: Matej Kenda <matejken@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-07-05 23:34:05 +07:00
|
|
|
}
|
2012-07-11 22:22:53 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-07-11 22:22:53 +07:00
|
|
|
/*
|
|
|
|
* Unlink empty entries, reducing DMA usage as well
|
|
|
|
* as HCD schedule-scanning costs. Delay for any qh
|
|
|
|
* we just scanned, there's a not-unusual case that it
|
|
|
|
* doesn't stay idle for long.
|
|
|
|
*/
|
|
|
|
if (check_unlinks_later && ehci->rh_state == EHCI_RH_RUNNING &&
|
|
|
|
!(ehci->enabled_hrtimer_events &
|
|
|
|
BIT(EHCI_HRTIMER_ASYNC_UNLINKS))) {
|
|
|
|
ehci_enable_event(ehci, EHCI_HRTIMER_ASYNC_UNLINKS, true);
|
|
|
|
++ehci->async_unlink_cycle;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|