Commit 8c5bf7be authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

USB: EHCI: don't refcount iso_stream structures

This patch (as1580) makes ehci_iso_stream structures behave more like
QHs, in that they will remain allocated until their isochronous
endpoint is disabled.  This will come in useful in the future, when
periodic bandwidth gets allocated as an altsetting is installed rather
than on-the-fly.

For now, the change to the ehci_iso_stream lifetimes means that each
structure is always deallocated at exactly one spot in
ehci_endpoint_disable() and never used again.  As a result, it is no
longer necessary to use reference counting on these things, and the
patch removes it.
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 55934eb3
...@@ -1085,8 +1085,14 @@ ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep) ...@@ -1085,8 +1085,14 @@ ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
* accelerate iso completions ... so spin a while. * accelerate iso completions ... so spin a while.
*/ */
if (qh->hw == NULL) { if (qh->hw == NULL) {
ehci_vdbg (ehci, "iso delay\n"); struct ehci_iso_stream *stream = ep->hcpriv;
if (!list_empty(&stream->td_list))
goto idle_timeout; goto idle_timeout;
/* BUG_ON(!list_empty(&stream->free_list)); */
kfree(stream);
goto done;
} }
if (ehci->rh_state < EHCI_RH_RUNNING) if (ehci->rh_state < EHCI_RH_RUNNING)
...@@ -1127,8 +1133,8 @@ ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep) ...@@ -1127,8 +1133,8 @@ ehci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
list_empty (&qh->qtd_list) ? "" : "(has tds)"); list_empty (&qh->qtd_list) ? "" : "(has tds)");
break; break;
} }
done:
ep->hcpriv = NULL; ep->hcpriv = NULL;
done:
spin_unlock_irqrestore (&ehci->lock, flags); spin_unlock_irqrestore (&ehci->lock, flags);
} }
......
...@@ -934,7 +934,6 @@ iso_stream_alloc (gfp_t mem_flags) ...@@ -934,7 +934,6 @@ iso_stream_alloc (gfp_t mem_flags)
INIT_LIST_HEAD(&stream->td_list); INIT_LIST_HEAD(&stream->td_list);
INIT_LIST_HEAD(&stream->free_list); INIT_LIST_HEAD(&stream->free_list);
stream->next_uframe = -1; stream->next_uframe = -1;
stream->refcount = 1;
} }
return stream; return stream;
} }
...@@ -1034,32 +1033,6 @@ iso_stream_init ( ...@@ -1034,32 +1033,6 @@ iso_stream_init (
stream->maxp = maxp; stream->maxp = maxp;
} }
static void
iso_stream_put(struct ehci_hcd *ehci, struct ehci_iso_stream *stream)
{
stream->refcount--;
/* free whenever just a dev->ep reference remains.
* not like a QH -- no persistent state (toggle, halt)
*/
if (stream->refcount == 1) {
// BUG_ON (!list_empty(&stream->td_list));
if (stream->ep)
stream->ep->hcpriv = NULL;
kfree(stream);
}
}
static inline struct ehci_iso_stream *
iso_stream_get (struct ehci_iso_stream *stream)
{
if (likely (stream != NULL))
stream->refcount++;
return stream;
}
static struct ehci_iso_stream * static struct ehci_iso_stream *
iso_stream_find (struct ehci_hcd *ehci, struct urb *urb) iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
{ {
...@@ -1080,7 +1053,6 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb) ...@@ -1080,7 +1053,6 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
if (unlikely (stream == NULL)) { if (unlikely (stream == NULL)) {
stream = iso_stream_alloc(GFP_ATOMIC); stream = iso_stream_alloc(GFP_ATOMIC);
if (likely (stream != NULL)) { if (likely (stream != NULL)) {
/* dev->ep owns the initial refcount */
ep->hcpriv = stream; ep->hcpriv = stream;
stream->ep = ep; stream->ep = ep;
iso_stream_init(ehci, stream, urb->dev, urb->pipe, iso_stream_init(ehci, stream, urb->dev, urb->pipe,
...@@ -1095,9 +1067,6 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb) ...@@ -1095,9 +1067,6 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
stream = NULL; stream = NULL;
} }
/* caller guarantees an eventual matching iso_stream_put */
stream = iso_stream_get (stream);
spin_unlock_irqrestore (&ehci->lock, flags); spin_unlock_irqrestore (&ehci->lock, flags);
return stream; return stream;
} }
...@@ -1611,7 +1580,7 @@ static void itd_link_urb( ...@@ -1611,7 +1580,7 @@ static void itd_link_urb(
itd = list_entry (iso_sched->td_list.next, itd = list_entry (iso_sched->td_list.next,
struct ehci_itd, itd_list); struct ehci_itd, itd_list);
list_move_tail (&itd->itd_list, &stream->td_list); list_move_tail (&itd->itd_list, &stream->td_list);
itd->stream = iso_stream_get (stream); itd->stream = stream;
itd->urb = urb; itd->urb = urb;
itd_init (ehci, stream, itd); itd_init (ehci, stream, itd);
} }
...@@ -1735,7 +1704,6 @@ itd_complete ( ...@@ -1735,7 +1704,6 @@ itd_complete (
dev->devpath, stream->bEndpointAddress & 0x0f, dev->devpath, stream->bEndpointAddress & 0x0f,
(stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out");
} }
iso_stream_put (ehci, stream);
done: done:
itd->urb = NULL; itd->urb = NULL;
...@@ -1750,7 +1718,6 @@ itd_complete ( ...@@ -1750,7 +1718,6 @@ itd_complete (
start_free_itds(ehci); start_free_itds(ehci);
} }
iso_stream_put(ehci, stream);
return retval; return retval;
} }
...@@ -1807,12 +1774,9 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb, ...@@ -1807,12 +1774,9 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
else else
usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
done_not_linked: done_not_linked:
spin_unlock_irqrestore (&ehci->lock, flags); spin_unlock_irqrestore (&ehci->lock, flags);
done:
done:
if (unlikely (status < 0))
iso_stream_put (ehci, stream);
return status; return status;
} }
...@@ -2028,7 +1992,7 @@ static void sitd_link_urb( ...@@ -2028,7 +1992,7 @@ static void sitd_link_urb(
sitd = list_entry (sched->td_list.next, sitd = list_entry (sched->td_list.next,
struct ehci_sitd, sitd_list); struct ehci_sitd, sitd_list);
list_move_tail (&sitd->sitd_list, &stream->td_list); list_move_tail (&sitd->sitd_list, &stream->td_list);
sitd->stream = iso_stream_get (stream); sitd->stream = stream;
sitd->urb = urb; sitd->urb = urb;
sitd_patch(ehci, stream, sitd, sched, packet); sitd_patch(ehci, stream, sitd, sched, packet);
...@@ -2126,7 +2090,6 @@ sitd_complete ( ...@@ -2126,7 +2090,6 @@ sitd_complete (
dev->devpath, stream->bEndpointAddress & 0x0f, dev->devpath, stream->bEndpointAddress & 0x0f,
(stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out");
} }
iso_stream_put (ehci, stream);
done: done:
sitd->urb = NULL; sitd->urb = NULL;
...@@ -2141,7 +2104,6 @@ sitd_complete ( ...@@ -2141,7 +2104,6 @@ sitd_complete (
start_free_itds(ehci); start_free_itds(ehci);
} }
iso_stream_put(ehci, stream);
return retval; return retval;
} }
...@@ -2195,12 +2157,9 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb, ...@@ -2195,12 +2157,9 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
else else
usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
done_not_linked: done_not_linked:
spin_unlock_irqrestore (&ehci->lock, flags); spin_unlock_irqrestore (&ehci->lock, flags);
done:
done:
if (status < 0)
iso_stream_put (ehci, stream);
return status; return status;
} }
......
...@@ -386,7 +386,7 @@ struct ehci_qh_hw { ...@@ -386,7 +386,7 @@ struct ehci_qh_hw {
} __attribute__ ((aligned(32))); } __attribute__ ((aligned(32)));
struct ehci_qh { struct ehci_qh {
struct ehci_qh_hw *hw; struct ehci_qh_hw *hw; /* Must come first */
/* the rest is HCD-private */ /* the rest is HCD-private */
dma_addr_t qh_dma; /* address of qh */ dma_addr_t qh_dma; /* address of qh */
union ehci_shadow qh_next; /* ptr to qh; or periodic */ union ehci_shadow qh_next; /* ptr to qh; or periodic */
...@@ -453,7 +453,6 @@ struct ehci_iso_stream { ...@@ -453,7 +453,6 @@ struct ehci_iso_stream {
/* first field matches ehci_hq, but is NULL */ /* first field matches ehci_hq, but is NULL */
struct ehci_qh_hw *hw; struct ehci_qh_hw *hw;
u32 refcount;
u8 bEndpointAddress; u8 bEndpointAddress;
u8 highspeed; u8 highspeed;
struct list_head td_list; /* queued itds/sitds */ struct list_head td_list; /* queued itds/sitds */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment