]> Pileus Git - ~andy/linux/blobdiff - drivers/usb/host/xhci-ring.c
Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab...
[~andy/linux] / drivers / usb / host / xhci-ring.c
index 3289bf4832c9acdca8d58a6edaa3d6dd7b2d43e1..7437386a9a50afeea3ad87bfd5b2f66f0a861947 100644 (file)
@@ -93,7 +93,7 @@ dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg,
 /* Does this link TRB point to the first segment in a ring,
  * or was the previous TRB the last TRB on the last segment in the ERST?
  */
-static inline bool last_trb_on_last_seg(struct xhci_hcd *xhci, struct xhci_ring *ring,
+static bool last_trb_on_last_seg(struct xhci_hcd *xhci, struct xhci_ring *ring,
                struct xhci_segment *seg, union xhci_trb *trb)
 {
        if (ring == xhci->event_ring)
@@ -107,7 +107,7 @@ static inline bool last_trb_on_last_seg(struct xhci_hcd *xhci, struct xhci_ring
  * segment?  I.e. would the updated event TRB pointer step off the end of the
  * event seg?
  */
-static inline int last_trb(struct xhci_hcd *xhci, struct xhci_ring *ring,
+static int last_trb(struct xhci_hcd *xhci, struct xhci_ring *ring,
                struct xhci_segment *seg, union xhci_trb *trb)
 {
        if (ring == xhci->event_ring)
@@ -116,7 +116,7 @@ static inline int last_trb(struct xhci_hcd *xhci, struct xhci_ring *ring,
                return (trb->link.control & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK);
 }
 
-static inline int enqueue_is_link_trb(struct xhci_ring *ring)
+static int enqueue_is_link_trb(struct xhci_ring *ring)
 {
        struct xhci_link_trb *link = &ring->enqueue->link;
        return ((link->control & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK));
@@ -380,10 +380,8 @@ static struct xhci_segment *find_trb_seg(
        while (cur_seg->trbs > trb ||
                        &cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) {
                generic_trb = &cur_seg->trbs[TRBS_PER_SEGMENT - 1].generic;
-               if ((generic_trb->field[3] & TRB_TYPE_BITMASK) ==
-                               TRB_TYPE(TRB_LINK) &&
-                               (generic_trb->field[3] & LINK_TOGGLE))
-                       *cycle_state = ~(*cycle_state) & 0x1;
+               if (generic_trb->field[3] & LINK_TOGGLE)
+                       *cycle_state ^= 0x1;
                cur_seg = cur_seg->next;
                if (cur_seg == start_seg)
                        /* Looped over the entire list.  Oops! */
@@ -497,18 +495,29 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
        trb = &state->new_deq_ptr->generic;
        if ((trb->field[3] & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK) &&
                                (trb->field[3] & LINK_TOGGLE))
-               state->new_cycle_state = ~(state->new_cycle_state) & 0x1;
+               state->new_cycle_state ^= 0x1;
        next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr);
 
+       /*
+        * If there is only one segment in a ring, find_trb_seg()'s while loop
+        * will not run, and it will return before it has a chance to see if it
+        * needs to toggle the cycle bit.  It can't tell if the stalled transfer
+        * ended just before the link TRB on a one-segment ring, or if the TD
+        * wrapped around the top of the ring, because it doesn't have the TD in
+        * question.  Look for the one-segment case where stalled TRB's address
+        * is greater than the new dequeue pointer address.
+        */
+       if (ep_ring->first_seg == ep_ring->first_seg->next &&
+                       state->new_deq_ptr < dev->eps[ep_index].stopped_trb)
+               state->new_cycle_state ^= 0x1;
+       xhci_dbg(xhci, "Cycle state = 0x%x\n", state->new_cycle_state);
+
        /* Don't update the ring cycle state for the producer (us). */
        xhci_dbg(xhci, "New dequeue segment = %p (virtual)\n",
                        state->new_deq_seg);
        addr = xhci_trb_virt_to_dma(state->new_deq_seg, state->new_deq_ptr);
        xhci_dbg(xhci, "New dequeue pointer = 0x%llx (DMA)\n",
                        (unsigned long long) addr);
-       xhci_dbg(xhci, "Setting dequeue pointer in internal ring state.\n");
-       ep_ring->dequeue = state->new_deq_ptr;
-       ep_ring->deq_seg = state->new_deq_seg;
 }
 
 static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
@@ -583,7 +592,7 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
        ep->ep_state |= SET_DEQ_PENDING;
 }
 
-static inline void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci,
+static void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci,
                struct xhci_virt_ep *ep)
 {
        ep->ep_state &= ~EP_HALT_PENDING;
@@ -599,16 +608,24 @@ static inline void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci,
 static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,
                struct xhci_td *cur_td, int status, char *adjective)
 {
-       struct usb_hcd *hcd = xhci_to_hcd(xhci);
+       struct usb_hcd *hcd;
        struct urb      *urb;
        struct urb_priv *urb_priv;
 
        urb = cur_td->urb;
        urb_priv = urb->hcpriv;
        urb_priv->td_cnt++;
+       hcd = bus_to_hcd(urb->dev->bus);
 
        /* Only giveback urb when this is the last td in urb */
        if (urb_priv->td_cnt == urb_priv->length) {
+               if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
+                       xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--;
+                       if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) {
+                               if (xhci->quirks & XHCI_AMD_PLL_FIX)
+                                       usb_amd_quirk_pll_enable();
+                       }
+               }
                usb_hcd_unlink_urb_from_ep(hcd, urb);
                xhci_dbg(xhci, "Giveback %s URB %p\n", adjective, urb);
 
@@ -824,8 +841,7 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
        if (ret < 0) {
                /* This is bad; the host is not responding to commands and it's
                 * not allowing itself to be halted.  At least interrupts are
-                * disabled, so we can set HC_STATE_HALT and notify the
-                * USB core.  But if we call usb_hc_died(), it will attempt to
+                * disabled. If we call usb_hc_died(), it will attempt to
                 * disconnect all device drivers under this host.  Those
                 * disconnect() methods will wait for all URBs to be unlinked,
                 * so we must complete them.
@@ -870,9 +886,8 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
                }
        }
        spin_unlock(&xhci->lock);
-       xhci_to_hcd(xhci)->state = HC_STATE_HALT;
        xhci_dbg(xhci, "Calling usb_hc_died()\n");
-       usb_hc_died(xhci_to_hcd(xhci));
+       usb_hc_died(xhci_to_hcd(xhci)->primary_hcd);
        xhci_dbg(xhci, "xHCI host controller is dead.\n");
 }
 
@@ -951,9 +966,26 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
        } else {
                xhci_dbg(xhci, "Successful Set TR Deq Ptr cmd, deq = @%08llx\n",
                                ep_ctx->deq);
+               if (xhci_trb_virt_to_dma(dev->eps[ep_index].queued_deq_seg,
+                                       dev->eps[ep_index].queued_deq_ptr) ==
+                               (ep_ctx->deq & ~(EP_CTX_CYCLE_MASK))) {
+                       /* Update the ring's dequeue segment and dequeue pointer
+                        * to reflect the new position.
+                        */
+                       ep_ring->deq_seg = dev->eps[ep_index].queued_deq_seg;
+                       ep_ring->dequeue = dev->eps[ep_index].queued_deq_ptr;
+               } else {
+                       xhci_warn(xhci, "Mismatch between completed Set TR Deq "
+                                       "Ptr command & xHCI internal state.\n");
+                       xhci_warn(xhci, "ep deq seg = %p, deq ptr = %p\n",
+                                       dev->eps[ep_index].queued_deq_seg,
+                                       dev->eps[ep_index].queued_deq_ptr);
+               }
        }
 
        dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING;
+       dev->eps[ep_index].queued_deq_seg = NULL;
+       dev->eps[ep_index].queued_deq_ptr = NULL;
        /* Restart any rings with pending URBs */
        ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
 }
@@ -1118,7 +1150,6 @@ bandwidth_change:
                handle_set_deq_completion(xhci, event, xhci->cmd_ring->dequeue);
                break;
        case TRB_TYPE(TRB_CMD_NOOP):
-               ++xhci->noops_handled;
                break;
        case TRB_TYPE(TRB_RESET_EP):
                handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue);
@@ -1162,15 +1193,56 @@ static void handle_vendor_event(struct xhci_hcd *xhci,
                handle_cmd_completion(xhci, &event->event_cmd);
 }
 
+/* @port_id: the one-based port ID from the hardware (indexed from array of all
+ * port registers -- USB 3.0 and USB 2.0).
+ *
+ * Returns a zero-based port number, which is suitable for indexing into each of
+ * the split roothubs' port arrays and bus state arrays.
+ */
+static unsigned int find_faked_portnum_from_hw_portnum(struct usb_hcd *hcd,
+               struct xhci_hcd *xhci, u32 port_id)
+{
+       unsigned int i;
+       unsigned int num_similar_speed_ports = 0;
+
+       /* port_id from the hardware is 1-based, but port_array[], usb3_ports[],
+        * and usb2_ports are 0-based indexes.  Count the number of similar
+        * speed ports, up to 1 port before this port.
+        */
+       for (i = 0; i < (port_id - 1); i++) {
+               u8 port_speed = xhci->port_array[i];
+
+               /*
+                * Skip ports that don't have known speeds, or have duplicate
+                * Extended Capabilities port speed entries.
+                */
+               if (port_speed == 0 || port_speed == DUPLICATE_ENTRY)
+                       continue;
+
+               /*
+                * USB 3.0 ports are always under a USB 3.0 hub.  USB 2.0 and
+                * 1.1 ports are under the USB 2.0 hub.  If the port speed
+                * matches the device speed, it's a similar speed port.
+                */
+               if ((port_speed == 0x03) == (hcd->speed == HCD_USB3))
+                       num_similar_speed_ports++;
+       }
+       return num_similar_speed_ports;
+}
+
 static void handle_port_status(struct xhci_hcd *xhci,
                union xhci_trb *event)
 {
-       struct usb_hcd *hcd = xhci_to_hcd(xhci);
+       struct usb_hcd *hcd;
        u32 port_id;
        u32 temp, temp1;
-       u32 __iomem *addr;
-       int ports;
+       int max_ports;
        int slot_id;
+       unsigned int faked_port_index;
+       u8 major_revision;
+       struct xhci_bus_state *bus_state;
+       u32 __iomem **port_array;
+       bool bogus_port_status = false;
 
        /* Port status change events always have a successful completion code */
        if (GET_COMP_CODE(event->generic.field[2]) != COMP_SUCCESS) {
@@ -1180,14 +1252,53 @@ static void handle_port_status(struct xhci_hcd *xhci,
        port_id = GET_PORT_ID(event->generic.field[0]);
        xhci_dbg(xhci, "Port Status Change Event for port %d\n", port_id);
 
-       ports = HCS_MAX_PORTS(xhci->hcs_params1);
-       if ((port_id <= 0) || (port_id > ports)) {
+       max_ports = HCS_MAX_PORTS(xhci->hcs_params1);
+       if ((port_id <= 0) || (port_id > max_ports)) {
                xhci_warn(xhci, "Invalid port id %d\n", port_id);
+               bogus_port_status = true;
                goto cleanup;
        }
 
-       addr = &xhci->op_regs->port_status_base + NUM_PORT_REGS * (port_id - 1);
-       temp = xhci_readl(xhci, addr);
+       /* Figure out which usb_hcd this port is attached to:
+        * is it a USB 3.0 port or a USB 2.0/1.1 port?
+        */
+       major_revision = xhci->port_array[port_id - 1];
+       if (major_revision == 0) {
+               xhci_warn(xhci, "Event for port %u not in "
+                               "Extended Capabilities, ignoring.\n",
+                               port_id);
+               bogus_port_status = true;
+               goto cleanup;
+       }
+       if (major_revision == DUPLICATE_ENTRY) {
+               xhci_warn(xhci, "Event for port %u duplicated in"
+                               "Extended Capabilities, ignoring.\n",
+                               port_id);
+               bogus_port_status = true;
+               goto cleanup;
+       }
+
+       /*
+        * Hardware port IDs reported by a Port Status Change Event include USB
+        * 3.0 and USB 2.0 ports.  We want to check if the port has reported a
+        * resume event, but we first need to translate the hardware port ID
+        * into the index into the ports on the correct split roothub, and the
+        * correct bus_state structure.
+        */
+       /* Find the right roothub. */
+       hcd = xhci_to_hcd(xhci);
+       if ((major_revision == 0x03) != (hcd->speed == HCD_USB3))
+               hcd = xhci->shared_hcd;
+       bus_state = &xhci->bus_state[hcd_index(hcd)];
+       if (hcd->speed == HCD_USB3)
+               port_array = xhci->usb3_ports;
+       else
+               port_array = xhci->usb2_ports;
+       /* Find the faked port hub number */
+       faked_port_index = find_faked_portnum_from_hw_portnum(hcd, xhci,
+                       port_id);
+
+       temp = xhci_readl(xhci, port_array[faked_port_index]);
        if (hcd->state == HC_STATE_SUSPENDED) {
                xhci_dbg(xhci, "resume root hub\n");
                usb_hcd_resume_root_hub(hcd);
@@ -1207,8 +1318,9 @@ static void handle_port_status(struct xhci_hcd *xhci,
                        temp = xhci_port_state_to_neutral(temp);
                        temp &= ~PORT_PLS_MASK;
                        temp |= PORT_LINK_STROBE | XDEV_U0;
-                       xhci_writel(xhci, temp, addr);
-                       slot_id = xhci_find_slot_id_by_port(xhci, port_id);
+                       xhci_writel(xhci, temp, port_array[faked_port_index]);
+                       slot_id = xhci_find_slot_id_by_port(hcd, xhci,
+                                       faked_port_index);
                        if (!slot_id) {
                                xhci_dbg(xhci, "slot_id is zero\n");
                                goto cleanup;
@@ -1216,16 +1328,16 @@ static void handle_port_status(struct xhci_hcd *xhci,
                        xhci_ring_device(xhci, slot_id);
                        xhci_dbg(xhci, "resume SS port %d finished\n", port_id);
                        /* Clear PORT_PLC */
-                       temp = xhci_readl(xhci, addr);
+                       temp = xhci_readl(xhci, port_array[faked_port_index]);
                        temp = xhci_port_state_to_neutral(temp);
                        temp |= PORT_PLC;
-                       xhci_writel(xhci, temp, addr);
+                       xhci_writel(xhci, temp, port_array[faked_port_index]);
                } else {
                        xhci_dbg(xhci, "resume HS port %d\n", port_id);
-                       xhci->resume_done[port_id - 1] = jiffies +
+                       bus_state->resume_done[faked_port_index] = jiffies +
                                msecs_to_jiffies(20);
                        mod_timer(&hcd->rh_timer,
-                                 xhci->resume_done[port_id - 1]);
+                                 bus_state->resume_done[faked_port_index]);
                        /* Do the rest in GetPortStatus */
                }
        }
@@ -1234,9 +1346,16 @@ cleanup:
        /* Update event ring dequeue pointer before dropping the lock */
        inc_deq(xhci, xhci->event_ring, true);
 
+       /* Don't make the USB core poll the roothub if we got a bad port status
+        * change event.  Besides, at that point we can't tell which roothub
+        * (USB 2.0 or USB 3.0) to kick.
+        */
+       if (bogus_port_status)
+               return;
+
        spin_unlock(&xhci->lock);
        /* Pass this up to the core */
-       usb_hcd_poll_rh_status(xhci_to_hcd(xhci));
+       usb_hcd_poll_rh_status(hcd);
        spin_lock(&xhci->lock);
 }
 
@@ -1453,8 +1572,17 @@ td_cleanup:
 
                urb_priv->td_cnt++;
                /* Giveback the urb when all the tds are completed */
-               if (urb_priv->td_cnt == urb_priv->length)
+               if (urb_priv->td_cnt == urb_priv->length) {
                        ret = 1;
+                       if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
+                               xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--;
+                               if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs
+                                       == 0) {
+                                       if (xhci->quirks & XHCI_AMD_PLL_FIX)
+                                               usb_amd_quirk_pll_enable();
+                               }
+                       }
+               }
        }
 
        return ret;
@@ -1574,71 +1702,52 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
        struct urb_priv *urb_priv;
        int idx;
        int len = 0;
-       int skip_td = 0;
        union xhci_trb *cur_trb;
        struct xhci_segment *cur_seg;
+       struct usb_iso_packet_descriptor *frame;
        u32 trb_comp_code;
+       bool skip_td = false;
 
        ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
        trb_comp_code = GET_COMP_CODE(event->transfer_len);
        urb_priv = td->urb->hcpriv;
        idx = urb_priv->td_cnt;
+       frame = &td->urb->iso_frame_desc[idx];
 
-       if (ep->skip) {
-               /* The transfer is partly done */
-               *status = -EXDEV;
-               td->urb->iso_frame_desc[idx].status = -EXDEV;
-       } else {
-               /* handle completion code */
-               switch (trb_comp_code) {
-               case COMP_SUCCESS:
-                       td->urb->iso_frame_desc[idx].status = 0;
-                       xhci_dbg(xhci, "Successful isoc transfer!\n");
-                       break;
-               case COMP_SHORT_TX:
-                       if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
-                               td->urb->iso_frame_desc[idx].status =
-                                        -EREMOTEIO;
-                       else
-                               td->urb->iso_frame_desc[idx].status = 0;
-                       break;
-               case COMP_BW_OVER:
-                       td->urb->iso_frame_desc[idx].status = -ECOMM;
-                       skip_td = 1;
-                       break;
-               case COMP_BUFF_OVER:
-               case COMP_BABBLE:
-                       td->urb->iso_frame_desc[idx].status = -EOVERFLOW;
-                       skip_td = 1;
-                       break;
-               case COMP_STALL:
-                       td->urb->iso_frame_desc[idx].status = -EPROTO;
-                       skip_td = 1;
-                       break;
-               case COMP_STOP:
-               case COMP_STOP_INVAL:
-                       break;
-               default:
-                       td->urb->iso_frame_desc[idx].status = -1;
-                       break;
-               }
-       }
-
-       /* calc actual length */
-       if (ep->skip) {
-               td->urb->iso_frame_desc[idx].actual_length = 0;
-               /* Update ring dequeue pointer */
-               while (ep_ring->dequeue != td->last_trb)
-                       inc_deq(xhci, ep_ring, false);
-               inc_deq(xhci, ep_ring, false);
-               return finish_td(xhci, td, event_trb, event, ep, status, true);
+       /* handle completion code */
+       switch (trb_comp_code) {
+       case COMP_SUCCESS:
+               frame->status = 0;
+               xhci_dbg(xhci, "Successful isoc transfer!\n");
+               break;
+       case COMP_SHORT_TX:
+               frame->status = td->urb->transfer_flags & URB_SHORT_NOT_OK ?
+                               -EREMOTEIO : 0;
+               break;
+       case COMP_BW_OVER:
+               frame->status = -ECOMM;
+               skip_td = true;
+               break;
+       case COMP_BUFF_OVER:
+       case COMP_BABBLE:
+               frame->status = -EOVERFLOW;
+               skip_td = true;
+               break;
+       case COMP_STALL:
+               frame->status = -EPROTO;
+               skip_td = true;
+               break;
+       case COMP_STOP:
+       case COMP_STOP_INVAL:
+               break;
+       default:
+               frame->status = -1;
+               break;
        }
 
-       if (trb_comp_code == COMP_SUCCESS || skip_td == 1) {
-               td->urb->iso_frame_desc[idx].actual_length =
-                       td->urb->iso_frame_desc[idx].length;
-               td->urb->actual_length +=
-                       td->urb->iso_frame_desc[idx].length;
+       if (trb_comp_code == COMP_SUCCESS || skip_td) {
+               frame->actual_length = frame->length;
+               td->urb->actual_length += frame->length;
        } else {
                for (cur_trb = ep_ring->dequeue,
                     cur_seg = ep_ring->deq_seg; cur_trb != event_trb;
@@ -1654,7 +1763,7 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
                        TRB_LEN(event->transfer_len);
 
                if (trb_comp_code != COMP_STOP_INVAL) {
-                       td->urb->iso_frame_desc[idx].actual_length = len;
+                       frame->actual_length = len;
                        td->urb->actual_length += len;
                }
        }
@@ -1665,6 +1774,35 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
        return finish_td(xhci, td, event_trb, event, ep, status, false);
 }
 
+static int skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
+                       struct xhci_transfer_event *event,
+                       struct xhci_virt_ep *ep, int *status)
+{
+       struct xhci_ring *ep_ring;
+       struct urb_priv *urb_priv;
+       struct usb_iso_packet_descriptor *frame;
+       int idx;
+
+       ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
+       urb_priv = td->urb->hcpriv;
+       idx = urb_priv->td_cnt;
+       frame = &td->urb->iso_frame_desc[idx];
+
+       /* The transfer is partly done */
+       *status = -EXDEV;
+       frame->status = -EXDEV;
+
+       /* calc actual length */
+       frame->actual_length = 0;
+
+       /* Update ring dequeue pointer */
+       while (ep_ring->dequeue != td->last_trb)
+               inc_deq(xhci, ep_ring, false);
+       inc_deq(xhci, ep_ring, false);
+
+       return finish_td(xhci, td, NULL, event, ep, status, true);
+}
+
 /*
  * Process bulk and interrupt tds, update urb status and actual_length.
  */
@@ -1923,36 +2061,42 @@ static int handle_tx_event(struct xhci_hcd *xhci,
                }
 
                td = list_entry(ep_ring->td_list.next, struct xhci_td, td_list);
+
                /* Is this a TRB in the currently executing TD? */
                event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue,
                                td->last_trb, event_dma);
-               if (event_seg && ep->skip) {
+               if (!event_seg) {
+                       if (!ep->skip ||
+                           !usb_endpoint_xfer_isoc(&td->urb->ep->desc)) {
+                               /* HC is busted, give up! */
+                               xhci_err(xhci,
+                                       "ERROR Transfer event TRB DMA ptr not "
+                                       "part of current TD\n");
+                               return -ESHUTDOWN;
+                       }
+
+                       ret = skip_isoc_td(xhci, td, event, ep, &status);
+                       goto cleanup;
+               }
+
+               if (ep->skip) {
                        xhci_dbg(xhci, "Found td. Clear skip flag.\n");
                        ep->skip = false;
                }
-               if (!event_seg &&
-                  (!ep->skip || !usb_endpoint_xfer_isoc(&td->urb->ep->desc))) {
-                       /* HC is busted, give up! */
-                       xhci_err(xhci, "ERROR Transfer event TRB DMA ptr not "
-                                       "part of current TD\n");
-                       return -ESHUTDOWN;
-               }
 
-               if (event_seg) {
-                       event_trb = &event_seg->trbs[(event_dma -
-                                        event_seg->dma) / sizeof(*event_trb)];
-                       /*
-                        * No-op TRB should not trigger interrupts.
-                        * If event_trb is a no-op TRB, it means the
-                        * corresponding TD has been cancelled. Just ignore
-                        * the TD.
-                        */
-                       if ((event_trb->generic.field[3] & TRB_TYPE_BITMASK)
-                                        == TRB_TYPE(TRB_TR_NOOP)) {
-                               xhci_dbg(xhci, "event_trb is a no-op TRB. "
-                                               "Skip it\n");
-                               goto cleanup;
-                       }
+               event_trb = &event_seg->trbs[(event_dma - event_seg->dma) /
+                                               sizeof(*event_trb)];
+               /*
+                * No-op TRB should not trigger interrupts.
+                * If event_trb is a no-op TRB, it means the
+                * corresponding TD has been cancelled. Just ignore
+                * the TD.
+                */
+               if ((event_trb->generic.field[3] & TRB_TYPE_BITMASK)
+                                == TRB_TYPE(TRB_TR_NOOP)) {
+                       xhci_dbg(xhci,
+                                "event_trb is a no-op TRB. Skip it\n");
+                       goto cleanup;
                }
 
                /* Now update the urb's actual_length and give back to
@@ -1990,12 +2134,12 @@ cleanup:
                                        trb_comp_code != COMP_BABBLE))
                                xhci_urb_free_priv(xhci, urb_priv);
 
-                       usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb);
+                       usb_hcd_unlink_urb_from_ep(bus_to_hcd(urb->dev->bus), urb);
                        xhci_dbg(xhci, "Giveback URB %p, len = %d, "
                                        "status = %d\n",
                                        urb, urb->actual_length, status);
                        spin_unlock(&xhci->lock);
-                       usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status);
+                       usb_hcd_giveback_urb(bus_to_hcd(urb->dev->bus), urb, status);
                        spin_lock(&xhci->lock);
                }
 
@@ -2119,7 +2263,6 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)
                xhci_warn(xhci, "WARNING: Host System Error\n");
                xhci_halt(xhci);
 hw_died:
-               xhci_to_hcd(xhci)->state = HC_STATE_HALT;
                spin_unlock(&xhci->lock);
                return -ESHUTDOWN;
        }
@@ -2187,8 +2330,12 @@ hw_died:
 irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd)
 {
        irqreturn_t ret;
+       struct xhci_hcd *xhci;
 
+       xhci = hcd_to_xhci(hcd);
        set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
+       if (xhci->shared_hcd)
+               set_bit(HCD_FLAG_SAW_IRQ, &xhci->shared_hcd->flags);
 
        ret = xhci_irq(hcd);
 
@@ -2332,7 +2479,7 @@ static int prepare_transfer(struct xhci_hcd *xhci,
        INIT_LIST_HEAD(&td->cancelled_td_list);
 
        if (td_index == 0) {
-               ret = usb_hcd_link_urb_to_ep(xhci_to_hcd(xhci), urb);
+               ret = usb_hcd_link_urb_to_ep(bus_to_hcd(urb->dev->bus), urb);
                if (unlikely(ret)) {
                        xhci_urb_free_priv(xhci, urb_priv);
                        urb->hcpriv = NULL;
@@ -3022,6 +3169,12 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
                }
        }
 
+       if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) {
+               if (xhci->quirks & XHCI_AMD_PLL_FIX)
+                       usb_amd_quirk_pll_disable();
+       }
+       xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs++;
+
        giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id,
                        start_cycle, start_trb);
        return 0;
@@ -3131,24 +3284,6 @@ static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2,
        return 0;
 }
 
-/* Queue a no-op command on the command ring */
-static int queue_cmd_noop(struct xhci_hcd *xhci)
-{
-       return queue_command(xhci, 0, 0, 0, TRB_TYPE(TRB_CMD_NOOP), false);
-}
-
-/*
- * Place a no-op command on the command ring to test the command and
- * event ring.
- */
-void *xhci_setup_one_noop(struct xhci_hcd *xhci)
-{
-       if (queue_cmd_noop(xhci) < 0)
-               return NULL;
-       xhci->noops_submitted++;
-       return xhci_ring_cmd_db;
-}
-
 /* Queue a slot enable or disable request on the command ring */
 int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id)
 {
@@ -3229,6 +3364,7 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id,
        u32 trb_ep_index = EP_ID_FOR_TRB(ep_index);
        u32 trb_stream_id = STREAM_ID_FOR_TRB(stream_id);
        u32 type = TRB_TYPE(TRB_SET_DEQ);
+       struct xhci_virt_ep *ep;
 
        addr = xhci_trb_virt_to_dma(deq_seg, deq_ptr);
        if (addr == 0) {
@@ -3237,6 +3373,14 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id,
                                deq_seg, deq_ptr);
                return 0;
        }
+       ep = &xhci->devs[slot_id]->eps[ep_index];
+       if ((ep->ep_state & SET_DEQ_PENDING)) {
+               xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n");
+               xhci_warn(xhci, "A Set TR Deq Ptr command is pending.\n");
+               return 0;
+       }
+       ep->queued_deq_seg = deq_seg;
+       ep->queued_deq_ptr = deq_ptr;
        return queue_command(xhci, lower_32_bits(addr) | cycle_state,
                        upper_32_bits(addr), trb_stream_id,
                        trb_slot_id | trb_ep_index | type, false);