]> Pileus Git - ~andy/linux/blobdiff - drivers/usb/host/xhci-ring.c
Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groec...
[~andy/linux] / drivers / usb / host / xhci-ring.c
index 940321b3ec68b477549a38d4016ee047fb7a72a7..b62037bff688c07c38f0ad06e22ab8cb964bf62f 100644 (file)
@@ -155,10 +155,6 @@ static void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer
        while (last_trb(xhci, ring, ring->deq_seg, next)) {
                if (consumer && last_trb_on_last_seg(xhci, ring, ring->deq_seg, next)) {
                        ring->cycle_state = (ring->cycle_state ? 0 : 1);
-                       if (!in_interrupt())
-                               xhci_dbg(xhci, "Toggle cycle state for ring %p = %i\n",
-                                               ring,
-                                               (unsigned int) ring->cycle_state);
                }
                ring->deq_seg = ring->deq_seg->next;
                ring->dequeue = ring->deq_seg->trbs;
@@ -231,10 +227,6 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring,
                        /* Toggle the cycle bit after the last ring segment. */
                        if (last_trb_on_last_seg(xhci, ring, ring->enq_seg, next)) {
                                ring->cycle_state = (ring->cycle_state ? 0 : 1);
-                               if (!in_interrupt())
-                                       xhci_dbg(xhci, "Toggle cycle state for ring %p = %i\n",
-                                                       ring,
-                                                       (unsigned int) ring->cycle_state);
                        }
                }
                ring->enq_seg = ring->enq_seg->next;
@@ -560,12 +552,9 @@ static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
                                        cpu_to_le32(TRB_CYCLE);
                        cur_trb->generic.field[3] |= cpu_to_le32(
                                TRB_TYPE(TRB_TR_NOOP));
-                       xhci_dbg(xhci, "Cancel TRB %p (0x%llx dma) "
-                                       "in seg %p (0x%llx dma)\n",
-                                       cur_trb,
-                                       (unsigned long long)xhci_trb_virt_to_dma(cur_seg, cur_trb),
-                                       cur_seg,
-                                       (unsigned long long)cur_seg->dma);
+                       xhci_dbg(xhci, "TRB to noop at offset 0x%llx\n",
+                                       (unsigned long long)
+                                       xhci_trb_virt_to_dma(cur_seg, cur_trb));
                }
                if (cur_trb == cur_td->last_trb)
                        break;
@@ -705,9 +694,9 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
         */
        list_for_each(entry, &ep->cancelled_td_list) {
                cur_td = list_entry(entry, struct xhci_td, cancelled_td_list);
-               xhci_dbg(xhci, "Cancelling TD starting at %p, 0x%llx (dma).\n",
-                               cur_td->first_trb,
-                               (unsigned long long)xhci_trb_virt_to_dma(cur_td->start_seg, cur_td->first_trb));
+               xhci_dbg(xhci, "Removing canceled TD starting at 0x%llx (dma).\n",
+                               (unsigned long long)xhci_trb_virt_to_dma(
+                                       cur_td->start_seg, cur_td->first_trb));
                ep_ring = xhci_urb_to_transfer_ring(xhci, cur_td->urb);
                if (!ep_ring) {
                        /* This shouldn't happen unless a driver is mucking
@@ -816,23 +805,24 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
        struct xhci_ring *ring;
        struct xhci_td *cur_td;
        int ret, i, j;
+       unsigned long flags;
 
        ep = (struct xhci_virt_ep *) arg;
        xhci = ep->xhci;
 
-       spin_lock(&xhci->lock);
+       spin_lock_irqsave(&xhci->lock, flags);
 
        ep->stop_cmds_pending--;
        if (xhci->xhc_state & XHCI_STATE_DYING) {
                xhci_dbg(xhci, "Stop EP timer ran, but another timer marked "
                                "xHCI as DYING, exiting.\n");
-               spin_unlock(&xhci->lock);
+               spin_unlock_irqrestore(&xhci->lock, flags);
                return;
        }
        if (!(ep->stop_cmds_pending == 0 && (ep->ep_state & EP_HALT_PENDING))) {
                xhci_dbg(xhci, "Stop EP timer ran, but no command pending, "
                                "exiting.\n");
-               spin_unlock(&xhci->lock);
+               spin_unlock_irqrestore(&xhci->lock, flags);
                return;
        }
 
@@ -844,11 +834,11 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
        xhci->xhc_state |= XHCI_STATE_DYING;
        /* Disable interrupts from the host controller and start halting it */
        xhci_quiesce(xhci);
-       spin_unlock(&xhci->lock);
+       spin_unlock_irqrestore(&xhci->lock, flags);
 
        ret = xhci_halt(xhci);
 
-       spin_lock(&xhci->lock);
+       spin_lock_irqsave(&xhci->lock, flags);
        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
@@ -896,7 +886,7 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
                        }
                }
        }
-       spin_unlock(&xhci->lock);
+       spin_unlock_irqrestore(&xhci->lock, flags);
        xhci_dbg(xhci, "Calling usb_hc_died()\n");
        usb_hc_died(xhci_to_hcd(xhci)->primary_hcd);
        xhci_dbg(xhci, "xHCI host controller is dead.\n");
@@ -1214,6 +1204,7 @@ static void handle_vendor_event(struct xhci_hcd *xhci,
  *
  * Returns a zero-based port number, which is suitable for indexing into each of
  * the split roothubs' port arrays and bus state arrays.
+ * Add one to it in order to call xhci_find_slot_id_by_port.
  */
 static unsigned int find_faked_portnum_from_hw_portnum(struct usb_hcd *hcd,
                struct xhci_hcd *xhci, u32 port_id)
@@ -1334,7 +1325,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
                        xhci_set_link_state(xhci, port_array, faked_port_index,
                                                XDEV_U0);
                        slot_id = xhci_find_slot_id_by_port(hcd, xhci,
-                                       faked_port_index);
+                                       faked_port_index + 1);
                        if (!slot_id) {
                                xhci_dbg(xhci, "slot_id is zero\n");
                                goto cleanup;
@@ -1626,7 +1617,6 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
        ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
        trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len));
 
-       xhci_debug_trb(xhci, xhci->event_ring->dequeue);
        switch (trb_comp_code) {
        case COMP_SUCCESS:
                if (event_trb == ep_ring->dequeue) {
@@ -1642,7 +1632,6 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
                }
                break;
        case COMP_SHORT_TX:
-               xhci_warn(xhci, "WARN: short transfer on control ep\n");
                if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
                        *status = -EREMOTEIO;
                else
@@ -1945,6 +1934,16 @@ static int handle_tx_event(struct xhci_hcd *xhci,
        xdev = xhci->devs[slot_id];
        if (!xdev) {
                xhci_err(xhci, "ERROR Transfer event pointed to bad slot\n");
+               xhci_err(xhci, "@%016llx %08x %08x %08x %08x\n",
+                        (unsigned long long) xhci_trb_virt_to_dma(
+                                xhci->event_ring->deq_seg,
+                                xhci->event_ring->dequeue),
+                        lower_32_bits(le64_to_cpu(event->buffer)),
+                        upper_32_bits(le64_to_cpu(event->buffer)),
+                        le32_to_cpu(event->transfer_len),
+                        le32_to_cpu(event->flags));
+               xhci_dbg(xhci, "Event ring:\n");
+               xhci_debug_segment(xhci, xhci->event_ring->deq_seg);
                return -ENODEV;
        }
 
@@ -1958,6 +1957,16 @@ static int handle_tx_event(struct xhci_hcd *xhci,
            EP_STATE_DISABLED) {
                xhci_err(xhci, "ERROR Transfer event for disabled endpoint "
                                "or incorrect stream ring\n");
+               xhci_err(xhci, "@%016llx %08x %08x %08x %08x\n",
+                        (unsigned long long) xhci_trb_virt_to_dma(
+                                xhci->event_ring->deq_seg,
+                                xhci->event_ring->dequeue),
+                        lower_32_bits(le64_to_cpu(event->buffer)),
+                        upper_32_bits(le64_to_cpu(event->buffer)),
+                        le32_to_cpu(event->transfer_len),
+                        le32_to_cpu(event->flags));
+               xhci_dbg(xhci, "Event ring:\n");
+               xhci_debug_segment(xhci, xhci->event_ring->deq_seg);
                return -ENODEV;
        }
 
@@ -1984,7 +1993,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
                xhci_dbg(xhci, "Stopped on No-op or Link TRB\n");
                break;
        case COMP_STALL:
-               xhci_warn(xhci, "WARN: Stalled endpoint\n");
+               xhci_dbg(xhci, "Stalled endpoint\n");
                ep->ep_state |= EP_HALTED;
                status = -EPIPE;
                break;
@@ -1994,11 +2003,11 @@ static int handle_tx_event(struct xhci_hcd *xhci,
                break;
        case COMP_SPLIT_ERR:
        case COMP_TX_ERR:
-               xhci_warn(xhci, "WARN: transfer error on endpoint\n");
+               xhci_dbg(xhci, "Transfer error on endpoint\n");
                status = -EPROTO;
                break;
        case COMP_BABBLE:
-               xhci_warn(xhci, "WARN: babble error on endpoint\n");
+               xhci_dbg(xhci, "Babble error on endpoint\n");
                status = -EOVERFLOW;
                break;
        case COMP_DB_ERR:
@@ -2389,17 +2398,7 @@ 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);
-
-       return ret;
+       return xhci_irq(hcd);
 }
 
 /****          Endpoint Ring Operations        ****/
@@ -2487,11 +2486,6 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
                        /* Toggle the cycle bit after the last ring segment. */
                        if (last_trb_on_last_seg(xhci, ring, ring->enq_seg, next)) {
                                ring->cycle_state = (ring->cycle_state ? 0 : 1);
-                               if (!in_interrupt()) {
-                                       xhci_dbg(xhci, "queue_trb: Toggle cycle "
-                                               "state for ring %p = %i\n",
-                                               ring, (unsigned int)ring->cycle_state);
-                               }
                        }
                        ring->enq_seg = ring->enq_seg->next;
                        ring->enqueue = ring->enq_seg->trbs;
@@ -2560,13 +2554,11 @@ static unsigned int count_sg_trbs_needed(struct xhci_hcd *xhci, struct urb *urb)
        struct scatterlist *sg;
 
        sg = NULL;
-       num_sgs = urb->num_sgs;
+       num_sgs = urb->num_mapped_sgs;
        temp = urb->transfer_buffer_length;
 
-       xhci_dbg(xhci, "count sg list trbs: \n");
        num_trbs = 0;
        for_each_sg(urb->sg, sg, num_sgs, i) {
-               unsigned int previous_total_trbs = num_trbs;
                unsigned int len = sg_dma_len(sg);
 
                /* Scatter gather list entries may cross 64KB boundaries */
@@ -2581,22 +2573,11 @@ static unsigned int count_sg_trbs_needed(struct xhci_hcd *xhci, struct urb *urb)
                        num_trbs++;
                        running_total += TRB_MAX_BUFF_SIZE;
                }
-               xhci_dbg(xhci, " sg #%d: dma = %#llx, len = %#x (%d), num_trbs = %d\n",
-                               i, (unsigned long long)sg_dma_address(sg),
-                               len, len, num_trbs - previous_total_trbs);
-
                len = min_t(int, len, temp);
                temp -= len;
                if (temp == 0)
                        break;
        }
-       xhci_dbg(xhci, "\n");
-       if (!in_interrupt())
-               xhci_dbg(xhci, "ep %#x - urb len = %d, sglist used, "
-                               "num_trbs = %d\n",
-                               urb->ep->desc.bEndpointAddress,
-                               urb->transfer_buffer_length,
-                               num_trbs);
        return num_trbs;
 }
 
@@ -2744,7 +2725,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
                return -EINVAL;
 
        num_trbs = count_sg_trbs_needed(xhci, urb);
-       num_sgs = urb->num_sgs;
+       num_sgs = urb->num_mapped_sgs;
        total_packet_count = roundup(urb->transfer_buffer_length,
                        usb_endpoint_maxp(&urb->ep->desc));
 
@@ -2782,8 +2763,6 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
        trb_buff_len = min_t(int, trb_buff_len, this_sg_len);
        if (trb_buff_len > urb->transfer_buffer_length)
                trb_buff_len = urb->transfer_buffer_length;
-       xhci_dbg(xhci, "First length to xfer from 1st sglist entry = %u\n",
-                       trb_buff_len);
 
        first_trb = true;
        /* Queue the first TRB, even if it's zero-length */
@@ -2815,11 +2794,6 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
                if (usb_urb_dir_in(urb))
                        field |= TRB_ISP;
 
-               xhci_dbg(xhci, " sg entry: dma = %#x, len = %#x (%d), "
-                               "64KB boundary at %#x, end dma = %#x\n",
-                               (unsigned int) addr, trb_buff_len, trb_buff_len,
-                               (unsigned int) (addr + TRB_MAX_BUFF_SIZE) & ~(TRB_MAX_BUFF_SIZE - 1),
-                               (unsigned int) addr + trb_buff_len);
                if (TRB_MAX_BUFF_SIZE -
                                (addr & (TRB_MAX_BUFF_SIZE - 1)) < trb_buff_len) {
                        xhci_warn(xhci, "WARN: sg dma xfer crosses 64KB boundaries!\n");
@@ -2925,15 +2899,6 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
        }
        /* FIXME: this doesn't deal with URB_ZERO_PACKET - need one more */
 
-       if (!in_interrupt())
-               xhci_dbg(xhci, "ep %#x - urb len = %#x (%d), "
-                               "addr = %#llx, num_trbs = %d\n",
-                               urb->ep->desc.bEndpointAddress,
-                               urb->transfer_buffer_length,
-                               urb->transfer_buffer_length,
-                               (unsigned long long)urb->transfer_dma,
-                               num_trbs);
-
        ret = prepare_transfer(xhci, xhci->devs[slot_id],
                        ep_index, urb->stream_id,
                        num_trbs, urb, 0, false, mem_flags);
@@ -3054,9 +3019,6 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
        if (!urb->setup_packet)
                return -EINVAL;
 
-       if (!in_interrupt())
-               xhci_dbg(xhci, "Queueing ctrl tx for slot id %d, ep %d\n",
-                               slot_id, ep_index);
        /* 1 TRB for setup, 1 for status */
        num_trbs = 2;
        /*
@@ -3248,15 +3210,6 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
                return -EINVAL;
        }
 
-       if (!in_interrupt())
-               xhci_dbg(xhci, "ep %#x - urb len = %#x (%d),"
-                               " addr = %#llx, num_tds = %d\n",
-                               urb->ep->desc.bEndpointAddress,
-                               urb->transfer_buffer_length,
-                               urb->transfer_buffer_length,
-                               (unsigned long long)urb->transfer_dma,
-                               num_tds);
-
        start_addr = (u64) urb->transfer_dma;
        start_trb = &ep_ring->enqueue->generic;
        start_cycle = ep_ring->cycle_state;
@@ -3371,7 +3324,8 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
                /* Check TD length */
                if (running_total != td_len) {
                        xhci_err(xhci, "ISOC TD length unmatch\n");
-                       return -EINVAL;
+                       ret = -EINVAL;
+                       goto cleanup;
                }
        }