diff options
author | Sarah Sharp <sarah.a.sharp@linux.intel.com> | 2009-07-27 15:03:15 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-07-28 17:31:11 -0400 |
commit | a1587d97ce3e53816c88b513a2038f6c5e5babd7 (patch) | |
tree | 3deb2b83974a9cfa61def8f8ab248cafbbb9809f /drivers/usb | |
parent | f9dc68fe7ad390428c6bc5d7ff582cdb5d92fcb8 (diff) |
USB: xhci: Deal with stalled endpoints.
When an endpoint on a device under an xHCI host controller stalls, the
host controller driver must let the hardware know that the USB core has
successfully cleared the halt condition. The HCD submits a Reset Endpoint
Command, which will clear the toggle bit for USB 2.0 devices, and set the
sequence number to zero for USB 3.0 devices.
The xHCI urb_enqueue will accept new URBs while the endpoint is halted,
and will queue them to the hardware rings. However, the endpoint doorbell
will not be rung until the Reset Endpoint Command completes.
Don't queue a reset endpoint command for root hubs. khubd clears halt
conditions on the roothub during the initialization process, but the roothub
isn't a real device, so the xHCI host controller doesn't need to know about the
cleared halt.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/host/xhci-hcd.c | 44 | ||||
-rw-r--r-- | drivers/usb/host/xhci-pci.c | 1 | ||||
-rw-r--r-- | drivers/usb/host/xhci-ring.c | 36 | ||||
-rw-r--r-- | drivers/usb/host/xhci.h | 8 |
4 files changed, 85 insertions, 4 deletions
diff --git a/drivers/usb/host/xhci-hcd.c b/drivers/usb/host/xhci-hcd.c index dba3e07ccd09..1c5901ad6eb8 100644 --- a/drivers/usb/host/xhci-hcd.c +++ b/drivers/usb/host/xhci-hcd.c | |||
@@ -787,8 +787,11 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, | |||
787 | int ret = 0; | 787 | int ret = 0; |
788 | 788 | ||
789 | ret = xhci_check_args(hcd, udev, ep, 1, __func__); | 789 | ret = xhci_check_args(hcd, udev, ep, 1, __func__); |
790 | if (ret <= 0) | 790 | if (ret <= 0) { |
791 | /* So we won't queue a reset ep command for a root hub */ | ||
792 | ep->hcpriv = NULL; | ||
791 | return ret; | 793 | return ret; |
794 | } | ||
792 | xhci = hcd_to_xhci(hcd); | 795 | xhci = hcd_to_xhci(hcd); |
793 | 796 | ||
794 | added_ctxs = xhci_get_endpoint_flag(&ep->desc); | 797 | added_ctxs = xhci_get_endpoint_flag(&ep->desc); |
@@ -851,6 +854,9 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, | |||
851 | } | 854 | } |
852 | new_slot_info = in_ctx->slot.dev_info; | 855 | new_slot_info = in_ctx->slot.dev_info; |
853 | 856 | ||
857 | /* Store the usb_device pointer for later use */ | ||
858 | ep->hcpriv = udev; | ||
859 | |||
854 | xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x, new slot info = %#x\n", | 860 | xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x, new slot info = %#x\n", |
855 | (unsigned int) ep->desc.bEndpointAddress, | 861 | (unsigned int) ep->desc.bEndpointAddress, |
856 | udev->slot_id, | 862 | udev->slot_id, |
@@ -1026,6 +1032,42 @@ void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) | |||
1026 | xhci_zero_in_ctx(virt_dev); | 1032 | xhci_zero_in_ctx(virt_dev); |
1027 | } | 1033 | } |
1028 | 1034 | ||
1035 | /* Deal with stalled endpoints. The core should have sent the control message | ||
1036 | * to clear the halt condition. However, we need to make the xHCI hardware | ||
1037 | * reset its sequence number, since a device will expect a sequence number of | ||
1038 | * zero after the halt condition is cleared. | ||
1039 | * Context: in_interrupt | ||
1040 | */ | ||
1041 | void xhci_endpoint_reset(struct usb_hcd *hcd, | ||
1042 | struct usb_host_endpoint *ep) | ||
1043 | { | ||
1044 | struct xhci_hcd *xhci; | ||
1045 | struct usb_device *udev; | ||
1046 | unsigned int ep_index; | ||
1047 | unsigned long flags; | ||
1048 | int ret; | ||
1049 | |||
1050 | xhci = hcd_to_xhci(hcd); | ||
1051 | udev = (struct usb_device *) ep->hcpriv; | ||
1052 | /* Called with a root hub endpoint (or an endpoint that wasn't added | ||
1053 | * with xhci_add_endpoint() | ||
1054 | */ | ||
1055 | if (!ep->hcpriv) | ||
1056 | return; | ||
1057 | ep_index = xhci_get_endpoint_index(&ep->desc); | ||
1058 | |||
1059 | xhci_dbg(xhci, "Queueing reset endpoint command\n"); | ||
1060 | spin_lock_irqsave(&xhci->lock, flags); | ||
1061 | ret = xhci_queue_reset_ep(xhci, udev->slot_id, ep_index); | ||
1062 | if (!ret) { | ||
1063 | xhci_ring_cmd_db(xhci); | ||
1064 | } | ||
1065 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
1066 | |||
1067 | if (ret) | ||
1068 | xhci_warn(xhci, "FIXME allocate a new ring segment\n"); | ||
1069 | } | ||
1070 | |||
1029 | /* | 1071 | /* |
1030 | * At this point, the struct usb_device is about to go away, the device has | 1072 | * At this point, the struct usb_device is about to go away, the device has |
1031 | * disconnected, and all traffic has been stopped and the endpoints have been | 1073 | * disconnected, and all traffic has been stopped and the endpoints have been |
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 1462709e26c0..592fe7e623f7 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c | |||
@@ -117,6 +117,7 @@ static const struct hc_driver xhci_pci_hc_driver = { | |||
117 | .free_dev = xhci_free_dev, | 117 | .free_dev = xhci_free_dev, |
118 | .add_endpoint = xhci_add_endpoint, | 118 | .add_endpoint = xhci_add_endpoint, |
119 | .drop_endpoint = xhci_drop_endpoint, | 119 | .drop_endpoint = xhci_drop_endpoint, |
120 | .endpoint_reset = xhci_endpoint_reset, | ||
120 | .check_bandwidth = xhci_check_bandwidth, | 121 | .check_bandwidth = xhci_check_bandwidth, |
121 | .reset_bandwidth = xhci_reset_bandwidth, | 122 | .reset_bandwidth = xhci_reset_bandwidth, |
122 | .address_device = xhci_address_device, | 123 | .address_device = xhci_address_device, |
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index d5b952997423..d672ba14ff80 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c | |||
@@ -279,7 +279,8 @@ static void ring_ep_doorbell(struct xhci_hcd *xhci, | |||
279 | /* Don't ring the doorbell for this endpoint if there are pending | 279 | /* Don't ring the doorbell for this endpoint if there are pending |
280 | * cancellations because the we don't want to interrupt processing. | 280 | * cancellations because the we don't want to interrupt processing. |
281 | */ | 281 | */ |
282 | if (!ep_ring->cancels_pending && !(ep_ring->state & SET_DEQ_PENDING)) { | 282 | if (!ep_ring->cancels_pending && !(ep_ring->state & SET_DEQ_PENDING) |
283 | && !(ep_ring->state & EP_HALTED)) { | ||
283 | field = xhci_readl(xhci, db_addr) & DB_MASK; | 284 | field = xhci_readl(xhci, db_addr) & DB_MASK; |
284 | xhci_writel(xhci, field | EPI_TO_DB(ep_index), db_addr); | 285 | xhci_writel(xhci, field | EPI_TO_DB(ep_index), db_addr); |
285 | /* Flush PCI posted writes - FIXME Matthew Wilcox says this | 286 | /* Flush PCI posted writes - FIXME Matthew Wilcox says this |
@@ -603,6 +604,25 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci, | |||
603 | ring_ep_doorbell(xhci, slot_id, ep_index); | 604 | ring_ep_doorbell(xhci, slot_id, ep_index); |
604 | } | 605 | } |
605 | 606 | ||
607 | static void handle_reset_ep_completion(struct xhci_hcd *xhci, | ||
608 | struct xhci_event_cmd *event, | ||
609 | union xhci_trb *trb) | ||
610 | { | ||
611 | int slot_id; | ||
612 | unsigned int ep_index; | ||
613 | |||
614 | slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); | ||
615 | ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); | ||
616 | /* This command will only fail if the endpoint wasn't halted, | ||
617 | * but we don't care. | ||
618 | */ | ||
619 | xhci_dbg(xhci, "Ignoring reset ep completion code of %u\n", | ||
620 | (unsigned int) GET_COMP_CODE(event->status)); | ||
621 | |||
622 | /* Clear our internal halted state and restart the ring */ | ||
623 | xhci->devs[slot_id]->ep_rings[ep_index]->state &= ~EP_HALTED; | ||
624 | ring_ep_doorbell(xhci, slot_id, ep_index); | ||
625 | } | ||
606 | 626 | ||
607 | static void handle_cmd_completion(struct xhci_hcd *xhci, | 627 | static void handle_cmd_completion(struct xhci_hcd *xhci, |
608 | struct xhci_event_cmd *event) | 628 | struct xhci_event_cmd *event) |
@@ -653,6 +673,9 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, | |||
653 | case TRB_TYPE(TRB_CMD_NOOP): | 673 | case TRB_TYPE(TRB_CMD_NOOP): |
654 | ++xhci->noops_handled; | 674 | ++xhci->noops_handled; |
655 | break; | 675 | break; |
676 | case TRB_TYPE(TRB_RESET_EP): | ||
677 | handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue); | ||
678 | break; | ||
656 | default: | 679 | default: |
657 | /* Skip over unknown commands on the event ring */ | 680 | /* Skip over unknown commands on the event ring */ |
658 | xhci->error_bitmask |= 1 << 6; | 681 | xhci->error_bitmask |= 1 << 6; |
@@ -823,6 +846,7 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
823 | break; | 846 | break; |
824 | case COMP_STALL: | 847 | case COMP_STALL: |
825 | xhci_warn(xhci, "WARN: Stalled endpoint\n"); | 848 | xhci_warn(xhci, "WARN: Stalled endpoint\n"); |
849 | ep_ring->state |= EP_HALTED; | ||
826 | status = -EPIPE; | 850 | status = -EPIPE; |
827 | break; | 851 | break; |
828 | case COMP_TRB_ERR: | 852 | case COMP_TRB_ERR: |
@@ -1656,3 +1680,13 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id, | |||
1656 | return queue_command(xhci, (u32) addr | cycle_state, 0, 0, | 1680 | return queue_command(xhci, (u32) addr | cycle_state, 0, 0, |
1657 | trb_slot_id | trb_ep_index | type); | 1681 | trb_slot_id | trb_ep_index | type); |
1658 | } | 1682 | } |
1683 | |||
1684 | int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, | ||
1685 | unsigned int ep_index) | ||
1686 | { | ||
1687 | u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); | ||
1688 | u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); | ||
1689 | u32 type = TRB_TYPE(TRB_RESET_EP); | ||
1690 | |||
1691 | return queue_command(xhci, 0, 0, 0, trb_slot_id | trb_ep_index | type); | ||
1692 | } | ||
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 8936eeb5588b..cde648a524f5 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h | |||
@@ -848,8 +848,8 @@ union xhci_trb { | |||
848 | #define TRB_CONFIG_EP 12 | 848 | #define TRB_CONFIG_EP 12 |
849 | /* Evaluate Context Command */ | 849 | /* Evaluate Context Command */ |
850 | #define TRB_EVAL_CONTEXT 13 | 850 | #define TRB_EVAL_CONTEXT 13 |
851 | /* Reset Transfer Ring Command */ | 851 | /* Reset Endpoint Command */ |
852 | #define TRB_RESET_RING 14 | 852 | #define TRB_RESET_EP 14 |
853 | /* Stop Transfer Ring Command */ | 853 | /* Stop Transfer Ring Command */ |
854 | #define TRB_STOP_RING 15 | 854 | #define TRB_STOP_RING 15 |
855 | /* Set Transfer Ring Dequeue Pointer Command */ | 855 | /* Set Transfer Ring Dequeue Pointer Command */ |
@@ -929,6 +929,7 @@ struct xhci_ring { | |||
929 | unsigned int cancels_pending; | 929 | unsigned int cancels_pending; |
930 | unsigned int state; | 930 | unsigned int state; |
931 | #define SET_DEQ_PENDING (1 << 0) | 931 | #define SET_DEQ_PENDING (1 << 0) |
932 | #define EP_HALTED (1 << 1) | ||
932 | /* The TRB that was last reported in a stopped endpoint ring */ | 933 | /* The TRB that was last reported in a stopped endpoint ring */ |
933 | union xhci_trb *stopped_trb; | 934 | union xhci_trb *stopped_trb; |
934 | struct xhci_td *stopped_td; | 935 | struct xhci_td *stopped_td; |
@@ -1128,6 +1129,7 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags); | |||
1128 | int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status); | 1129 | int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status); |
1129 | int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep); | 1130 | int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep); |
1130 | int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep); | 1131 | int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep); |
1132 | void xhci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep); | ||
1131 | int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev); | 1133 | int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev); |
1132 | void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev); | 1134 | void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev); |
1133 | 1135 | ||
@@ -1148,6 +1150,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, | |||
1148 | int slot_id, unsigned int ep_index); | 1150 | int slot_id, unsigned int ep_index); |
1149 | int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | 1151 | int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, |
1150 | u32 slot_id); | 1152 | u32 slot_id); |
1153 | int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, | ||
1154 | unsigned int ep_index); | ||
1151 | 1155 | ||
1152 | /* xHCI roothub code */ | 1156 | /* xHCI roothub code */ |
1153 | int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, | 1157 | int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, |