aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host')
-rw-r--r--drivers/usb/host/ehci-hcd.c13
-rw-r--r--drivers/usb/host/ehci-hub.c26
-rw-r--r--drivers/usb/host/xhci-dbg.c6
-rw-r--r--drivers/usb/host/xhci-mem.c14
-rw-r--r--drivers/usb/host/xhci-pci.c5
-rw-r--r--drivers/usb/host/xhci-ring.c68
-rw-r--r--drivers/usb/host/xhci.c24
-rw-r--r--drivers/usb/host/xhci.h41
8 files changed, 98 insertions, 99 deletions
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 471142725ffe..81cda09b47e3 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -685,8 +685,15 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
685 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 685 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
686 u32 status, masked_status, pcd_status = 0, cmd; 686 u32 status, masked_status, pcd_status = 0, cmd;
687 int bh; 687 int bh;
688 unsigned long flags;
688 689
689 spin_lock (&ehci->lock); 690 /*
691 * For threadirqs option we use spin_lock_irqsave() variant to prevent
692 * deadlock with ehci hrtimer callback, because hrtimer callbacks run
693 * in interrupt context even when threadirqs is specified. We can go
694 * back to spin_lock() variant when hrtimer callbacks become threaded.
695 */
696 spin_lock_irqsave(&ehci->lock, flags);
690 697
691 status = ehci_readl(ehci, &ehci->regs->status); 698 status = ehci_readl(ehci, &ehci->regs->status);
692 699
@@ -704,7 +711,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
704 711
705 /* Shared IRQ? */ 712 /* Shared IRQ? */
706 if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) { 713 if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) {
707 spin_unlock(&ehci->lock); 714 spin_unlock_irqrestore(&ehci->lock, flags);
708 return IRQ_NONE; 715 return IRQ_NONE;
709 } 716 }
710 717
@@ -815,7 +822,7 @@ dead:
815 822
816 if (bh) 823 if (bh)
817 ehci_work (ehci); 824 ehci_work (ehci);
818 spin_unlock (&ehci->lock); 825 spin_unlock_irqrestore(&ehci->lock, flags);
819 if (pcd_status) 826 if (pcd_status)
820 usb_hcd_poll_rh_status(hcd); 827 usb_hcd_poll_rh_status(hcd);
821 return IRQ_HANDLED; 828 return IRQ_HANDLED;
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 47b858fc50b2..7ae0c4d51741 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -238,6 +238,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
238 int port; 238 int port;
239 int mask; 239 int mask;
240 int changed; 240 int changed;
241 bool fs_idle_delay;
241 242
242 ehci_dbg(ehci, "suspend root hub\n"); 243 ehci_dbg(ehci, "suspend root hub\n");
243 244
@@ -272,6 +273,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
272 ehci->bus_suspended = 0; 273 ehci->bus_suspended = 0;
273 ehci->owned_ports = 0; 274 ehci->owned_ports = 0;
274 changed = 0; 275 changed = 0;
276 fs_idle_delay = false;
275 port = HCS_N_PORTS(ehci->hcs_params); 277 port = HCS_N_PORTS(ehci->hcs_params);
276 while (port--) { 278 while (port--) {
277 u32 __iomem *reg = &ehci->regs->port_status [port]; 279 u32 __iomem *reg = &ehci->regs->port_status [port];
@@ -300,16 +302,32 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
300 } 302 }
301 303
302 if (t1 != t2) { 304 if (t1 != t2) {
305 /*
306 * On some controllers, Wake-On-Disconnect will
307 * generate false wakeup signals until the bus
308 * switches over to full-speed idle. For their
309 * sake, add a delay if we need one.
310 */
311 if ((t2 & PORT_WKDISC_E) &&
312 ehci_port_speed(ehci, t2) ==
313 USB_PORT_STAT_HIGH_SPEED)
314 fs_idle_delay = true;
303 ehci_writel(ehci, t2, reg); 315 ehci_writel(ehci, t2, reg);
304 changed = 1; 316 changed = 1;
305 } 317 }
306 } 318 }
319 spin_unlock_irq(&ehci->lock);
320
321 if ((changed && ehci->has_tdi_phy_lpm) || fs_idle_delay) {
322 /*
323 * Wait for HCD to enter low-power mode or for the bus
324 * to switch to full-speed idle.
325 */
326 usleep_range(5000, 5500);
327 }
307 328
308 if (changed && ehci->has_tdi_phy_lpm) { 329 if (changed && ehci->has_tdi_phy_lpm) {
309 spin_unlock_irq(&ehci->lock);
310 msleep(5); /* 5 ms for HCD to enter low-power mode */
311 spin_lock_irq(&ehci->lock); 330 spin_lock_irq(&ehci->lock);
312
313 port = HCS_N_PORTS(ehci->hcs_params); 331 port = HCS_N_PORTS(ehci->hcs_params);
314 while (port--) { 332 while (port--) {
315 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port]; 333 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
@@ -322,8 +340,8 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
322 port, (t3 & HOSTPC_PHCD) ? 340 port, (t3 & HOSTPC_PHCD) ?
323 "succeeded" : "failed"); 341 "succeeded" : "failed");
324 } 342 }
343 spin_unlock_irq(&ehci->lock);
325 } 344 }
326 spin_unlock_irq(&ehci->lock);
327 345
328 /* Apparently some devices need a >= 1-uframe delay here */ 346 /* Apparently some devices need a >= 1-uframe delay here */
329 if (ehci->bus_suspended) 347 if (ehci->bus_suspended)
diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
index b016d38199f2..eb009a457fb5 100644
--- a/drivers/usb/host/xhci-dbg.c
+++ b/drivers/usb/host/xhci-dbg.c
@@ -203,12 +203,12 @@ void xhci_print_ir_set(struct xhci_hcd *xhci, int set_num)
203 addr, (unsigned int)temp); 203 addr, (unsigned int)temp);
204 204
205 addr = &ir_set->erst_base; 205 addr = &ir_set->erst_base;
206 temp_64 = readq(addr); 206 temp_64 = xhci_read_64(xhci, addr);
207 xhci_dbg(xhci, " %p: ir_set.erst_base = @%08llx\n", 207 xhci_dbg(xhci, " %p: ir_set.erst_base = @%08llx\n",
208 addr, temp_64); 208 addr, temp_64);
209 209
210 addr = &ir_set->erst_dequeue; 210 addr = &ir_set->erst_dequeue;
211 temp_64 = readq(addr); 211 temp_64 = xhci_read_64(xhci, addr);
212 xhci_dbg(xhci, " %p: ir_set.erst_dequeue = @%08llx\n", 212 xhci_dbg(xhci, " %p: ir_set.erst_dequeue = @%08llx\n",
213 addr, temp_64); 213 addr, temp_64);
214} 214}
@@ -412,7 +412,7 @@ void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci)
412{ 412{
413 u64 val; 413 u64 val;
414 414
415 val = readq(&xhci->op_regs->cmd_ring); 415 val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
416 xhci_dbg(xhci, "// xHC command ring deq ptr low bits + flags = @%08x\n", 416 xhci_dbg(xhci, "// xHC command ring deq ptr low bits + flags = @%08x\n",
417 lower_32_bits(val)); 417 lower_32_bits(val));
418 xhci_dbg(xhci, "// xHC command ring deq ptr high bits = @%08x\n", 418 xhci_dbg(xhci, "// xHC command ring deq ptr high bits = @%08x\n",
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 873c272b3ef5..bce4391a0e7d 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1958,7 +1958,7 @@ static void xhci_set_hc_event_deq(struct xhci_hcd *xhci)
1958 xhci_warn(xhci, "WARN something wrong with SW event ring " 1958 xhci_warn(xhci, "WARN something wrong with SW event ring "
1959 "dequeue ptr.\n"); 1959 "dequeue ptr.\n");
1960 /* Update HC event ring dequeue pointer */ 1960 /* Update HC event ring dequeue pointer */
1961 temp = readq(&xhci->ir_set->erst_dequeue); 1961 temp = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
1962 temp &= ERST_PTR_MASK; 1962 temp &= ERST_PTR_MASK;
1963 /* Don't clear the EHB bit (which is RW1C) because 1963 /* Don't clear the EHB bit (which is RW1C) because
1964 * there might be more events to service. 1964 * there might be more events to service.
@@ -1967,7 +1967,7 @@ static void xhci_set_hc_event_deq(struct xhci_hcd *xhci)
1967 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 1967 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
1968 "// Write event ring dequeue pointer, " 1968 "// Write event ring dequeue pointer, "
1969 "preserving EHB bit"); 1969 "preserving EHB bit");
1970 writeq(((u64) deq & (u64) ~ERST_PTR_MASK) | temp, 1970 xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp,
1971 &xhci->ir_set->erst_dequeue); 1971 &xhci->ir_set->erst_dequeue);
1972} 1972}
1973 1973
@@ -2269,7 +2269,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2269 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2269 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2270 "// Device context base array address = 0x%llx (DMA), %p (virt)", 2270 "// Device context base array address = 0x%llx (DMA), %p (virt)",
2271 (unsigned long long)xhci->dcbaa->dma, xhci->dcbaa); 2271 (unsigned long long)xhci->dcbaa->dma, xhci->dcbaa);
2272 writeq(dma, &xhci->op_regs->dcbaa_ptr); 2272 xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr);
2273 2273
2274 /* 2274 /*
2275 * Initialize the ring segment pool. The ring must be a contiguous 2275 * Initialize the ring segment pool. The ring must be a contiguous
@@ -2312,13 +2312,13 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2312 (unsigned long long)xhci->cmd_ring->first_seg->dma); 2312 (unsigned long long)xhci->cmd_ring->first_seg->dma);
2313 2313
2314 /* Set the address in the Command Ring Control register */ 2314 /* Set the address in the Command Ring Control register */
2315 val_64 = readq(&xhci->op_regs->cmd_ring); 2315 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
2316 val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | 2316 val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) |
2317 (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) | 2317 (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) |
2318 xhci->cmd_ring->cycle_state; 2318 xhci->cmd_ring->cycle_state;
2319 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2319 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2320 "// Setting command ring address to 0x%x", val); 2320 "// Setting command ring address to 0x%x", val);
2321 writeq(val_64, &xhci->op_regs->cmd_ring); 2321 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring);
2322 xhci_dbg_cmd_ptrs(xhci); 2322 xhci_dbg_cmd_ptrs(xhci);
2323 2323
2324 xhci->lpm_command = xhci_alloc_command(xhci, true, true, flags); 2324 xhci->lpm_command = xhci_alloc_command(xhci, true, true, flags);
@@ -2396,10 +2396,10 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2396 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 2396 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2397 "// Set ERST base address for ir_set 0 = 0x%llx", 2397 "// Set ERST base address for ir_set 0 = 0x%llx",
2398 (unsigned long long)xhci->erst.erst_dma_addr); 2398 (unsigned long long)xhci->erst.erst_dma_addr);
2399 val_64 = readq(&xhci->ir_set->erst_base); 2399 val_64 = xhci_read_64(xhci, &xhci->ir_set->erst_base);
2400 val_64 &= ERST_PTR_MASK; 2400 val_64 &= ERST_PTR_MASK;
2401 val_64 |= (xhci->erst.erst_dma_addr & (u64) ~ERST_PTR_MASK); 2401 val_64 |= (xhci->erst.erst_dma_addr & (u64) ~ERST_PTR_MASK);
2402 writeq(val_64, &xhci->ir_set->erst_base); 2402 xhci_write_64(xhci, val_64, &xhci->ir_set->erst_base);
2403 2403
2404 /* Set the event ring dequeue address */ 2404 /* Set the event ring dequeue address */
2405 xhci_set_hc_event_deq(xhci); 2405 xhci_set_hc_event_deq(xhci);
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 3c898c12a06b..04f986d9234f 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -142,6 +142,11 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
142 "QUIRK: Resetting on resume"); 142 "QUIRK: Resetting on resume");
143 xhci->quirks |= XHCI_TRUST_TX_LENGTH; 143 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
144 } 144 }
145 if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
146 pdev->device == 0x0015 &&
147 pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG &&
148 pdev->subsystem_device == 0xc0cd)
149 xhci->quirks |= XHCI_RESET_ON_RESUME;
145 if (pdev->vendor == PCI_VENDOR_ID_VIA) 150 if (pdev->vendor == PCI_VENDOR_ID_VIA)
146 xhci->quirks |= XHCI_RESET_ON_RESUME; 151 xhci->quirks |= XHCI_RESET_ON_RESUME;
147} 152}
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index a0b248c34526..0ed64eb68e48 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -307,13 +307,14 @@ static int xhci_abort_cmd_ring(struct xhci_hcd *xhci)
307 return 0; 307 return 0;
308 } 308 }
309 309
310 temp_64 = readq(&xhci->op_regs->cmd_ring); 310 temp_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
311 if (!(temp_64 & CMD_RING_RUNNING)) { 311 if (!(temp_64 & CMD_RING_RUNNING)) {
312 xhci_dbg(xhci, "Command ring had been stopped\n"); 312 xhci_dbg(xhci, "Command ring had been stopped\n");
313 return 0; 313 return 0;
314 } 314 }
315 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; 315 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED;
316 writeq(temp_64 | CMD_RING_ABORT, &xhci->op_regs->cmd_ring); 316 xhci_write_64(xhci, temp_64 | CMD_RING_ABORT,
317 &xhci->op_regs->cmd_ring);
317 318
318 /* Section 4.6.1.2 of xHCI 1.0 spec says software should 319 /* Section 4.6.1.2 of xHCI 1.0 spec says software should
319 * time the completion od all xHCI commands, including 320 * time the completion od all xHCI commands, including
@@ -2864,8 +2865,9 @@ hw_died:
2864 /* Clear the event handler busy flag (RW1C); 2865 /* Clear the event handler busy flag (RW1C);
2865 * the event ring should be empty. 2866 * the event ring should be empty.
2866 */ 2867 */
2867 temp_64 = readq(&xhci->ir_set->erst_dequeue); 2868 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
2868 writeq(temp_64 | ERST_EHB, &xhci->ir_set->erst_dequeue); 2869 xhci_write_64(xhci, temp_64 | ERST_EHB,
2870 &xhci->ir_set->erst_dequeue);
2869 spin_unlock(&xhci->lock); 2871 spin_unlock(&xhci->lock);
2870 2872
2871 return IRQ_HANDLED; 2873 return IRQ_HANDLED;
@@ -2877,7 +2879,7 @@ hw_died:
2877 */ 2879 */
2878 while (xhci_handle_event(xhci) > 0) {} 2880 while (xhci_handle_event(xhci) > 0) {}
2879 2881
2880 temp_64 = readq(&xhci->ir_set->erst_dequeue); 2882 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
2881 /* If necessary, update the HW's version of the event ring deq ptr. */ 2883 /* If necessary, update the HW's version of the event ring deq ptr. */
2882 if (event_ring_deq != xhci->event_ring->dequeue) { 2884 if (event_ring_deq != xhci->event_ring->dequeue) {
2883 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, 2885 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg,
@@ -2892,7 +2894,7 @@ hw_died:
2892 2894
2893 /* Clear the event handler busy flag (RW1C); event ring is empty. */ 2895 /* Clear the event handler busy flag (RW1C); event ring is empty. */
2894 temp_64 |= ERST_EHB; 2896 temp_64 |= ERST_EHB;
2895 writeq(temp_64, &xhci->ir_set->erst_dequeue); 2897 xhci_write_64(xhci, temp_64, &xhci->ir_set->erst_dequeue);
2896 2898
2897 spin_unlock(&xhci->lock); 2899 spin_unlock(&xhci->lock);
2898 2900
@@ -2965,58 +2967,8 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
2965 } 2967 }
2966 2968
2967 while (1) { 2969 while (1) {
2968 if (room_on_ring(xhci, ep_ring, num_trbs)) { 2970 if (room_on_ring(xhci, ep_ring, num_trbs))
2969 union xhci_trb *trb = ep_ring->enqueue; 2971 break;
2970 unsigned int usable = ep_ring->enq_seg->trbs +
2971 TRBS_PER_SEGMENT - 1 - trb;
2972 u32 nop_cmd;
2973
2974 /*
2975 * Section 4.11.7.1 TD Fragments states that a link
2976 * TRB must only occur at the boundary between
2977 * data bursts (eg 512 bytes for 480M).
2978 * While it is possible to split a large fragment
2979 * we don't know the size yet.
2980 * Simplest solution is to fill the trb before the
2981 * LINK with nop commands.
2982 */
2983 if (num_trbs == 1 || num_trbs <= usable || usable == 0)
2984 break;
2985
2986 if (ep_ring->type != TYPE_BULK)
2987 /*
2988 * While isoc transfers might have a buffer that
2989 * crosses a 64k boundary it is unlikely.
2990 * Since we can't add NOPs without generating
2991 * gaps in the traffic just hope it never
2992 * happens at the end of the ring.
2993 * This could be fixed by writing a LINK TRB
2994 * instead of the first NOP - however the
2995 * TRB_TYPE_LINK_LE32() calls would all need
2996 * changing to check the ring length.
2997 */
2998 break;
2999
3000 if (num_trbs >= TRBS_PER_SEGMENT) {
3001 xhci_err(xhci, "Too many fragments %d, max %d\n",
3002 num_trbs, TRBS_PER_SEGMENT - 1);
3003 return -EINVAL;
3004 }
3005
3006 nop_cmd = cpu_to_le32(TRB_TYPE(TRB_TR_NOOP) |
3007 ep_ring->cycle_state);
3008 ep_ring->num_trbs_free -= usable;
3009 do {
3010 trb->generic.field[0] = 0;
3011 trb->generic.field[1] = 0;
3012 trb->generic.field[2] = 0;
3013 trb->generic.field[3] = nop_cmd;
3014 trb++;
3015 } while (--usable);
3016 ep_ring->enqueue = trb;
3017 if (room_on_ring(xhci, ep_ring, num_trbs))
3018 break;
3019 }
3020 2972
3021 if (ep_ring == xhci->cmd_ring) { 2973 if (ep_ring == xhci->cmd_ring) {
3022 xhci_err(xhci, "Do not support expand command ring\n"); 2974 xhci_err(xhci, "Do not support expand command ring\n");
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index ad364394885a..924a6ccdb622 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -611,7 +611,7 @@ int xhci_run(struct usb_hcd *hcd)
611 xhci_dbg(xhci, "Event ring:\n"); 611 xhci_dbg(xhci, "Event ring:\n");
612 xhci_debug_ring(xhci, xhci->event_ring); 612 xhci_debug_ring(xhci, xhci->event_ring);
613 xhci_dbg_ring_ptrs(xhci, xhci->event_ring); 613 xhci_dbg_ring_ptrs(xhci, xhci->event_ring);
614 temp_64 = readq(&xhci->ir_set->erst_dequeue); 614 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
615 temp_64 &= ~ERST_PTR_MASK; 615 temp_64 &= ~ERST_PTR_MASK;
616 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 616 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
617 "ERST deq = 64'h%0lx", (long unsigned int) temp_64); 617 "ERST deq = 64'h%0lx", (long unsigned int) temp_64);
@@ -756,11 +756,11 @@ static void xhci_save_registers(struct xhci_hcd *xhci)
756{ 756{
757 xhci->s3.command = readl(&xhci->op_regs->command); 757 xhci->s3.command = readl(&xhci->op_regs->command);
758 xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification); 758 xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification);
759 xhci->s3.dcbaa_ptr = readq(&xhci->op_regs->dcbaa_ptr); 759 xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr);
760 xhci->s3.config_reg = readl(&xhci->op_regs->config_reg); 760 xhci->s3.config_reg = readl(&xhci->op_regs->config_reg);
761 xhci->s3.erst_size = readl(&xhci->ir_set->erst_size); 761 xhci->s3.erst_size = readl(&xhci->ir_set->erst_size);
762 xhci->s3.erst_base = readq(&xhci->ir_set->erst_base); 762 xhci->s3.erst_base = xhci_read_64(xhci, &xhci->ir_set->erst_base);
763 xhci->s3.erst_dequeue = readq(&xhci->ir_set->erst_dequeue); 763 xhci->s3.erst_dequeue = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
764 xhci->s3.irq_pending = readl(&xhci->ir_set->irq_pending); 764 xhci->s3.irq_pending = readl(&xhci->ir_set->irq_pending);
765 xhci->s3.irq_control = readl(&xhci->ir_set->irq_control); 765 xhci->s3.irq_control = readl(&xhci->ir_set->irq_control);
766} 766}
@@ -769,11 +769,11 @@ static void xhci_restore_registers(struct xhci_hcd *xhci)
769{ 769{
770 writel(xhci->s3.command, &xhci->op_regs->command); 770 writel(xhci->s3.command, &xhci->op_regs->command);
771 writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification); 771 writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification);
772 writeq(xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); 772 xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr);
773 writel(xhci->s3.config_reg, &xhci->op_regs->config_reg); 773 writel(xhci->s3.config_reg, &xhci->op_regs->config_reg);
774 writel(xhci->s3.erst_size, &xhci->ir_set->erst_size); 774 writel(xhci->s3.erst_size, &xhci->ir_set->erst_size);
775 writeq(xhci->s3.erst_base, &xhci->ir_set->erst_base); 775 xhci_write_64(xhci, xhci->s3.erst_base, &xhci->ir_set->erst_base);
776 writeq(xhci->s3.erst_dequeue, &xhci->ir_set->erst_dequeue); 776 xhci_write_64(xhci, xhci->s3.erst_dequeue, &xhci->ir_set->erst_dequeue);
777 writel(xhci->s3.irq_pending, &xhci->ir_set->irq_pending); 777 writel(xhci->s3.irq_pending, &xhci->ir_set->irq_pending);
778 writel(xhci->s3.irq_control, &xhci->ir_set->irq_control); 778 writel(xhci->s3.irq_control, &xhci->ir_set->irq_control);
779} 779}
@@ -783,7 +783,7 @@ static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci)
783 u64 val_64; 783 u64 val_64;
784 784
785 /* step 2: initialize command ring buffer */ 785 /* step 2: initialize command ring buffer */
786 val_64 = readq(&xhci->op_regs->cmd_ring); 786 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
787 val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) | 787 val_64 = (val_64 & (u64) CMD_RING_RSVD_BITS) |
788 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, 788 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg,
789 xhci->cmd_ring->dequeue) & 789 xhci->cmd_ring->dequeue) &
@@ -792,7 +792,7 @@ static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci)
792 xhci_dbg_trace(xhci, trace_xhci_dbg_init, 792 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
793 "// Setting command ring address to 0x%llx", 793 "// Setting command ring address to 0x%llx",
794 (long unsigned long) val_64); 794 (long unsigned long) val_64);
795 writeq(val_64, &xhci->op_regs->cmd_ring); 795 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring);
796} 796}
797 797
798/* 798/*
@@ -3842,7 +3842,7 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,
3842 if (ret) { 3842 if (ret) {
3843 return ret; 3843 return ret;
3844 } 3844 }
3845 temp_64 = readq(&xhci->op_regs->dcbaa_ptr); 3845 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr);
3846 xhci_dbg_trace(xhci, trace_xhci_dbg_address, 3846 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
3847 "Op regs DCBAA ptr = %#016llx", temp_64); 3847 "Op regs DCBAA ptr = %#016llx", temp_64);
3848 xhci_dbg_trace(xhci, trace_xhci_dbg_address, 3848 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
@@ -4730,8 +4730,8 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
4730 struct device *dev = hcd->self.controller; 4730 struct device *dev = hcd->self.controller;
4731 int retval; 4731 int retval;
4732 4732
4733 /* Limit the block layer scatter-gather lists to half a segment. */ 4733 /* Accept arbitrarily long scatter-gather lists */
4734 hcd->self.sg_tablesize = TRBS_PER_SEGMENT / 2; 4734 hcd->self.sg_tablesize = ~0;
4735 4735
4736 /* support to build packet from discontinuous buffers */ 4736 /* support to build packet from discontinuous buffers */
4737 hcd->self.no_sg_constraint = 1; 4737 hcd->self.no_sg_constraint = 1;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index f8416639bf31..58ed9d088e63 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -28,17 +28,6 @@
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/usb/hcd.h> 29#include <linux/usb/hcd.h>
30 30
31/*
32 * Registers should always be accessed with double word or quad word accesses.
33 *
34 * Some xHCI implementations may support 64-bit address pointers. Registers
35 * with 64-bit address pointers should be written to with dword accesses by
36 * writing the low dword first (ptr[0]), then the high dword (ptr[1]) second.
37 * xHCI implementations that do not support 64-bit address pointers will ignore
38 * the high dword, and write order is irrelevant.
39 */
40#include <asm-generic/io-64-nonatomic-lo-hi.h>
41
42/* Code sharing between pci-quirks and xhci hcd */ 31/* Code sharing between pci-quirks and xhci hcd */
43#include "xhci-ext-caps.h" 32#include "xhci-ext-caps.h"
44#include "pci-quirks.h" 33#include "pci-quirks.h"
@@ -1279,7 +1268,7 @@ union xhci_trb {
1279 * since the command ring is 64-byte aligned. 1268 * since the command ring is 64-byte aligned.
1280 * It must also be greater than 16. 1269 * It must also be greater than 16.
1281 */ 1270 */
1282#define TRBS_PER_SEGMENT 256 1271#define TRBS_PER_SEGMENT 64
1283/* Allow two commands + a link TRB, along with any reserved command TRBs */ 1272/* Allow two commands + a link TRB, along with any reserved command TRBs */
1284#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3) 1273#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3)
1285#define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16) 1274#define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
@@ -1614,6 +1603,34 @@ static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci)
1614#define xhci_warn_ratelimited(xhci, fmt, args...) \ 1603#define xhci_warn_ratelimited(xhci, fmt, args...) \
1615 dev_warn_ratelimited(xhci_to_hcd(xhci)->self.controller , fmt , ## args) 1604 dev_warn_ratelimited(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1616 1605
1606/*
1607 * Registers should always be accessed with double word or quad word accesses.
1608 *
1609 * Some xHCI implementations may support 64-bit address pointers. Registers
1610 * with 64-bit address pointers should be written to with dword accesses by
1611 * writing the low dword first (ptr[0]), then the high dword (ptr[1]) second.
1612 * xHCI implementations that do not support 64-bit address pointers will ignore
1613 * the high dword, and write order is irrelevant.
1614 */
1615static inline u64 xhci_read_64(const struct xhci_hcd *xhci,
1616 __le64 __iomem *regs)
1617{
1618 __u32 __iomem *ptr = (__u32 __iomem *) regs;
1619 u64 val_lo = readl(ptr);
1620 u64 val_hi = readl(ptr + 1);
1621 return val_lo + (val_hi << 32);
1622}
1623static inline void xhci_write_64(struct xhci_hcd *xhci,
1624 const u64 val, __le64 __iomem *regs)
1625{
1626 __u32 __iomem *ptr = (__u32 __iomem *) regs;
1627 u32 val_lo = lower_32_bits(val);
1628 u32 val_hi = upper_32_bits(val);
1629
1630 writel(val_lo, ptr);
1631 writel(val_hi, ptr + 1);
1632}
1633
1617static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci) 1634static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci)
1618{ 1635{
1619 return xhci->quirks & XHCI_LINK_TRB_QUIRK; 1636 return xhci->quirks & XHCI_LINK_TRB_QUIRK;