aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/host/xhci-hcd.c77
-rw-r--r--drivers/usb/host/xhci-pci.c13
-rw-r--r--drivers/usb/host/xhci-ring.c61
-rw-r--r--drivers/usb/host/xhci.h20
4 files changed, 148 insertions, 23 deletions
diff --git a/drivers/usb/host/xhci-hcd.c b/drivers/usb/host/xhci-hcd.c
index 4353c1c78935..1d4a1e3f9533 100644
--- a/drivers/usb/host/xhci-hcd.c
+++ b/drivers/usb/host/xhci-hcd.c
@@ -224,7 +224,7 @@ int xhci_init(struct usb_hcd *hcd)
224 xhci_dbg(xhci, "QUIRK: Not clearing Link TRB chain bits.\n"); 224 xhci_dbg(xhci, "QUIRK: Not clearing Link TRB chain bits.\n");
225 xhci->quirks |= XHCI_LINK_TRB_QUIRK; 225 xhci->quirks |= XHCI_LINK_TRB_QUIRK;
226 } else { 226 } else {
227 xhci_dbg(xhci, "xHCI has no QUIRKS\n"); 227 xhci_dbg(xhci, "xHCI doesn't need link TRB QUIRK\n");
228 } 228 }
229 retval = xhci_mem_init(xhci, GFP_KERNEL); 229 retval = xhci_mem_init(xhci, GFP_KERNEL);
230 xhci_dbg(xhci, "Finished xhci_init\n"); 230 xhci_dbg(xhci, "Finished xhci_init\n");
@@ -567,13 +567,22 @@ unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc)
567 return 1 << (xhci_get_endpoint_index(desc) + 1); 567 return 1 << (xhci_get_endpoint_index(desc) + 1);
568} 568}
569 569
570/* Find the flag for this endpoint (for use in the control context). Use the
571 * endpoint index to create a bitmask. The slot context is bit 0, endpoint 0 is
572 * bit 1, etc.
573 */
574unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index)
575{
576 return 1 << (ep_index + 1);
577}
578
570/* Compute the last valid endpoint context index. Basically, this is the 579/* Compute the last valid endpoint context index. Basically, this is the
571 * endpoint index plus one. For slot contexts with more than valid endpoint, 580 * endpoint index plus one. For slot contexts with more than valid endpoint,
572 * we find the most significant bit set in the added contexts flags. 581 * we find the most significant bit set in the added contexts flags.
573 * e.g. ep 1 IN (with epnum 0x81) => added_ctxs = 0b1000 582 * e.g. ep 1 IN (with epnum 0x81) => added_ctxs = 0b1000
574 * fls(0b1000) = 4, but the endpoint context index is 3, so subtract one. 583 * fls(0b1000) = 4, but the endpoint context index is 3, so subtract one.
575 */ 584 */
576static inline unsigned int xhci_last_valid_endpoint(u32 added_ctxs) 585unsigned int xhci_last_valid_endpoint(u32 added_ctxs)
577{ 586{
578 return fls(added_ctxs) - 1; 587 return fls(added_ctxs) - 1;
579} 588}
@@ -1230,8 +1239,44 @@ void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
1230 xhci_zero_in_ctx(xhci, virt_dev); 1239 xhci_zero_in_ctx(xhci, virt_dev);
1231} 1240}
1232 1241
1242void xhci_setup_input_ctx_for_quirk(struct xhci_hcd *xhci,
1243 unsigned int slot_id, unsigned int ep_index,
1244 struct xhci_dequeue_state *deq_state)
1245{
1246 struct xhci_container_ctx *in_ctx;
1247 struct xhci_input_control_ctx *ctrl_ctx;
1248 struct xhci_ep_ctx *ep_ctx;
1249 u32 added_ctxs;
1250 dma_addr_t addr;
1251
1252 xhci_endpoint_copy(xhci, xhci->devs[slot_id], ep_index);
1253 in_ctx = xhci->devs[slot_id]->in_ctx;
1254 ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index);
1255 addr = xhci_trb_virt_to_dma(deq_state->new_deq_seg,
1256 deq_state->new_deq_ptr);
1257 if (addr == 0) {
1258 xhci_warn(xhci, "WARN Cannot submit config ep after "
1259 "reset ep command\n");
1260 xhci_warn(xhci, "WARN deq seg = %p, deq ptr = %p\n",
1261 deq_state->new_deq_seg,
1262 deq_state->new_deq_ptr);
1263 return;
1264 }
1265 ep_ctx->deq = addr | deq_state->new_cycle_state;
1266
1267 xhci_slot_copy(xhci, xhci->devs[slot_id]);
1268
1269 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
1270 added_ctxs = xhci_get_endpoint_flag_from_index(ep_index);
1271 ctrl_ctx->add_flags = added_ctxs | SLOT_FLAG;
1272 ctrl_ctx->drop_flags = added_ctxs;
1273
1274 xhci_dbg(xhci, "Slot ID %d Input Context:\n", slot_id);
1275 xhci_dbg_ctx(xhci, in_ctx, ep_index);
1276}
1277
1233void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, 1278void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
1234 struct usb_device *udev, struct usb_host_endpoint *ep, 1279 struct usb_device *udev,
1235 unsigned int ep_index, struct xhci_ring *ep_ring) 1280 unsigned int ep_index, struct xhci_ring *ep_ring)
1236{ 1281{
1237 struct xhci_dequeue_state deq_state; 1282 struct xhci_dequeue_state deq_state;
@@ -1241,12 +1286,26 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
1241 * or it will attempt to resend it on the next doorbell ring. 1286 * or it will attempt to resend it on the next doorbell ring.
1242 */ 1287 */
1243 xhci_find_new_dequeue_state(xhci, udev->slot_id, 1288 xhci_find_new_dequeue_state(xhci, udev->slot_id,
1244 ep_index, ep_ring->stopped_td, &deq_state); 1289 ep_index, ep_ring->stopped_td,
1290 &deq_state);
1245 1291
1246 xhci_dbg(xhci, "Queueing new dequeue state\n"); 1292 /* HW with the reset endpoint quirk will use the saved dequeue state to
1247 xhci_queue_new_dequeue_state(xhci, ep_ring, 1293 * issue a configure endpoint command later.
1248 udev->slot_id, 1294 */
1249 ep_index, &deq_state); 1295 if (!(xhci->quirks & XHCI_RESET_EP_QUIRK)) {
1296 xhci_dbg(xhci, "Queueing new dequeue state\n");
1297 xhci_queue_new_dequeue_state(xhci, ep_ring,
1298 udev->slot_id,
1299 ep_index, &deq_state);
1300 } else {
1301 /* Better hope no one uses the input context between now and the
1302 * reset endpoint completion!
1303 */
1304 xhci_dbg(xhci, "Setting up input context for "
1305 "configure endpoint command\n");
1306 xhci_setup_input_ctx_for_quirk(xhci, udev->slot_id,
1307 ep_index, &deq_state);
1308 }
1250} 1309}
1251 1310
1252/* Deal with stalled endpoints. The core should have sent the control message 1311/* Deal with stalled endpoints. The core should have sent the control message
@@ -1293,7 +1352,7 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
1293 * command. Better hope that last command worked! 1352 * command. Better hope that last command worked!
1294 */ 1353 */
1295 if (!ret) { 1354 if (!ret) {
1296 xhci_cleanup_stalled_ring(xhci, udev, ep, ep_index, ep_ring); 1355 xhci_cleanup_stalled_ring(xhci, udev, ep_index, ep_ring);
1297 kfree(ep_ring->stopped_td); 1356 kfree(ep_ring->stopped_td);
1298 xhci_ring_cmd_db(xhci); 1357 xhci_ring_cmd_db(xhci);
1299 } 1358 }
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 592fe7e623f7..8fb308d43bc1 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -24,6 +24,10 @@
24 24
25#include "xhci.h" 25#include "xhci.h"
26 26
27/* Device for a quirk */
28#define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73
29#define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000
30
27static const char hcd_name[] = "xhci_hcd"; 31static const char hcd_name[] = "xhci_hcd";
28 32
29/* called after powerup, by probe or system-pm "wakeup" */ 33/* called after powerup, by probe or system-pm "wakeup" */
@@ -62,6 +66,15 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
62 xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hcc_params); 66 xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
63 xhci_print_registers(xhci); 67 xhci_print_registers(xhci);
64 68
69 /* Look for vendor-specific quirks */
70 if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
71 pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
72 pdev->revision == 0x0) {
73 xhci->quirks |= XHCI_RESET_EP_QUIRK;
74 xhci_dbg(xhci, "QUIRK: Fresco Logic xHC needs configure"
75 " endpoint cmd after reset endpoint\n");
76 }
77
65 /* Make sure the HC is halted. */ 78 /* Make sure the HC is halted. */
66 retval = xhci_halt(xhci); 79 retval = xhci_halt(xhci);
67 if (retval) 80 if (retval)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index c831194b0966..35374ddc31c1 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -469,7 +469,6 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
469 * ring running. 469 * ring running.
470 */ 470 */
471 ep_ring->state |= SET_DEQ_PENDING; 471 ep_ring->state |= SET_DEQ_PENDING;
472 xhci_ring_cmd_db(xhci);
473} 472}
474 473
475/* 474/*
@@ -538,6 +537,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
538 if (deq_state.new_deq_ptr && deq_state.new_deq_seg) { 537 if (deq_state.new_deq_ptr && deq_state.new_deq_seg) {
539 xhci_queue_new_dequeue_state(xhci, ep_ring, 538 xhci_queue_new_dequeue_state(xhci, ep_ring,
540 slot_id, ep_index, &deq_state); 539 slot_id, ep_index, &deq_state);
540 xhci_ring_cmd_db(xhci);
541 } else { 541 } else {
542 /* Otherwise just ring the doorbell to restart the ring */ 542 /* Otherwise just ring the doorbell to restart the ring */
543 ring_ep_doorbell(xhci, slot_id, ep_index); 543 ring_ep_doorbell(xhci, slot_id, ep_index);
@@ -651,18 +651,31 @@ static void handle_reset_ep_completion(struct xhci_hcd *xhci,
651{ 651{
652 int slot_id; 652 int slot_id;
653 unsigned int ep_index; 653 unsigned int ep_index;
654 struct xhci_ring *ep_ring;
654 655
655 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); 656 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]);
656 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); 657 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]);
658 ep_ring = xhci->devs[slot_id]->ep_rings[ep_index];
657 /* This command will only fail if the endpoint wasn't halted, 659 /* This command will only fail if the endpoint wasn't halted,
658 * but we don't care. 660 * but we don't care.
659 */ 661 */
660 xhci_dbg(xhci, "Ignoring reset ep completion code of %u\n", 662 xhci_dbg(xhci, "Ignoring reset ep completion code of %u\n",
661 (unsigned int) GET_COMP_CODE(event->status)); 663 (unsigned int) GET_COMP_CODE(event->status));
662 664
663 /* Clear our internal halted state and restart the ring */ 665 /* HW with the reset endpoint quirk needs to have a configure endpoint
664 xhci->devs[slot_id]->ep_rings[ep_index]->state &= ~EP_HALTED; 666 * command complete before the endpoint can be used. Queue that here
665 ring_ep_doorbell(xhci, slot_id, ep_index); 667 * because the HW can't handle two commands being queued in a row.
668 */
669 if (xhci->quirks & XHCI_RESET_EP_QUIRK) {
670 xhci_dbg(xhci, "Queueing configure endpoint command\n");
671 xhci_queue_configure_endpoint(xhci,
672 xhci->devs[slot_id]->in_ctx->dma, slot_id);
673 xhci_ring_cmd_db(xhci);
674 } else {
675 /* Clear our internal halted state and restart the ring */
676 ep_ring->state &= ~EP_HALTED;
677 ring_ep_doorbell(xhci, slot_id, ep_index);
678 }
666} 679}
667 680
668static void handle_cmd_completion(struct xhci_hcd *xhci, 681static void handle_cmd_completion(struct xhci_hcd *xhci,
@@ -671,6 +684,10 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
671 int slot_id = TRB_TO_SLOT_ID(event->flags); 684 int slot_id = TRB_TO_SLOT_ID(event->flags);
672 u64 cmd_dma; 685 u64 cmd_dma;
673 dma_addr_t cmd_dequeue_dma; 686 dma_addr_t cmd_dequeue_dma;
687 struct xhci_input_control_ctx *ctrl_ctx;
688 unsigned int ep_index;
689 struct xhci_ring *ep_ring;
690 unsigned int ep_state;
674 691
675 cmd_dma = event->cmd_trb; 692 cmd_dma = event->cmd_trb;
676 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, 693 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg,
@@ -698,8 +715,39 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
698 xhci_free_virt_device(xhci, slot_id); 715 xhci_free_virt_device(xhci, slot_id);
699 break; 716 break;
700 case TRB_TYPE(TRB_CONFIG_EP): 717 case TRB_TYPE(TRB_CONFIG_EP):
701 xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(event->status); 718 /*
702 complete(&xhci->devs[slot_id]->cmd_completion); 719 * Configure endpoint commands can come from the USB core
720 * configuration or alt setting changes, or because the HW
721 * needed an extra configure endpoint command after a reset
722 * endpoint command. In the latter case, the xHCI driver is
723 * not waiting on the configure endpoint command.
724 */
725 ctrl_ctx = xhci_get_input_control_ctx(xhci,
726 xhci->devs[slot_id]->in_ctx);
727 /* Input ctx add_flags are the endpoint index plus one */
728 ep_index = xhci_last_valid_endpoint(ctrl_ctx->add_flags) - 1;
729 ep_ring = xhci->devs[slot_id]->ep_rings[ep_index];
730 if (!ep_ring) {
731 /* This must have been an initial configure endpoint */
732 xhci->devs[slot_id]->cmd_status =
733 GET_COMP_CODE(event->status);
734 complete(&xhci->devs[slot_id]->cmd_completion);
735 break;
736 }
737 ep_state = ep_ring->state;
738 xhci_dbg(xhci, "Completed config ep cmd - last ep index = %d, "
739 "state = %d\n", ep_index, ep_state);
740 if (xhci->quirks & XHCI_RESET_EP_QUIRK &&
741 ep_state & EP_HALTED) {
742 /* Clear our internal halted state and restart ring */
743 xhci->devs[slot_id]->ep_rings[ep_index]->state &=
744 ~EP_HALTED;
745 ring_ep_doorbell(xhci, slot_id, ep_index);
746 } else {
747 xhci->devs[slot_id]->cmd_status =
748 GET_COMP_CODE(event->status);
749 complete(&xhci->devs[slot_id]->cmd_completion);
750 }
703 break; 751 break;
704 case TRB_TYPE(TRB_EVAL_CONTEXT): 752 case TRB_TYPE(TRB_EVAL_CONTEXT):
705 xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(event->status); 753 xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(event->status);
@@ -958,7 +1006,6 @@ static int handle_tx_event(struct xhci_hcd *xhci,
958 xhci_queue_reset_ep(xhci, slot_id, ep_index); 1006 xhci_queue_reset_ep(xhci, slot_id, ep_index);
959 xhci_cleanup_stalled_ring(xhci, 1007 xhci_cleanup_stalled_ring(xhci,
960 td->urb->dev, 1008 td->urb->dev,
961 td->urb->ep,
962 ep_index, ep_ring); 1009 ep_index, ep_ring);
963 xhci_ring_cmd_db(xhci); 1010 xhci_ring_cmd_db(xhci);
964 goto td_cleanup; 1011 goto td_cleanup;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index b1abaeb62b4c..bc64b500feb8 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -929,6 +929,12 @@ struct xhci_td {
929 union xhci_trb *last_trb; 929 union xhci_trb *last_trb;
930}; 930};
931 931
932struct xhci_dequeue_state {
933 struct xhci_segment *new_deq_seg;
934 union xhci_trb *new_deq_ptr;
935 int new_cycle_state;
936};
937
932struct xhci_ring { 938struct xhci_ring {
933 struct xhci_segment *first_seg; 939 struct xhci_segment *first_seg;
934 union xhci_trb *enqueue; 940 union xhci_trb *enqueue;
@@ -955,12 +961,6 @@ struct xhci_ring {
955 u32 cycle_state; 961 u32 cycle_state;
956}; 962};
957 963
958struct xhci_dequeue_state {
959 struct xhci_segment *new_deq_seg;
960 union xhci_trb *new_deq_ptr;
961 int new_cycle_state;
962};
963
964struct xhci_erst_entry { 964struct xhci_erst_entry {
965 /* 64-bit event ring segment address */ 965 /* 64-bit event ring segment address */
966 u64 seg_addr; 966 u64 seg_addr;
@@ -1063,6 +1063,7 @@ struct xhci_hcd {
1063 int error_bitmask; 1063 int error_bitmask;
1064 unsigned int quirks; 1064 unsigned int quirks;
1065#define XHCI_LINK_TRB_QUIRK (1 << 0) 1065#define XHCI_LINK_TRB_QUIRK (1 << 0)
1066#define XHCI_RESET_EP_QUIRK (1 << 1)
1066}; 1067};
1067 1068
1068/* For testing purposes */ 1069/* For testing purposes */
@@ -1170,6 +1171,8 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, struct usb_device
1170int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev); 1171int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev);
1171unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc); 1172unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc);
1172unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc); 1173unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc);
1174unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index);
1175unsigned int xhci_last_valid_endpoint(u32 added_ctxs);
1173void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep); 1176void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep);
1174void xhci_endpoint_copy(struct xhci_hcd *xhci, 1177void xhci_endpoint_copy(struct xhci_hcd *xhci,
1175 struct xhci_virt_device *vdev, unsigned int ep_index); 1178 struct xhci_virt_device *vdev, unsigned int ep_index);
@@ -1233,8 +1236,11 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
1233 struct xhci_ring *ep_ring, unsigned int slot_id, 1236 struct xhci_ring *ep_ring, unsigned int slot_id,
1234 unsigned int ep_index, struct xhci_dequeue_state *deq_state); 1237 unsigned int ep_index, struct xhci_dequeue_state *deq_state);
1235void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, 1238void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
1236 struct usb_device *udev, struct usb_host_endpoint *ep, 1239 struct usb_device *udev,
1237 unsigned int ep_index, struct xhci_ring *ep_ring); 1240 unsigned int ep_index, struct xhci_ring *ep_ring);
1241void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci,
1242 unsigned int slot_id, unsigned int ep_index,
1243 struct xhci_dequeue_state *deq_state);
1238 1244
1239/* xHCI roothub code */ 1245/* xHCI roothub code */
1240int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, 1246int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,