diff options
author | Mathias Nyman <mathias.nyman@linux.intel.com> | 2015-02-24 11:27:02 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-02-24 11:34:32 -0500 |
commit | 27082e2654dc148078b0abdfc3c8e5ccbde0ebfa (patch) | |
tree | d458d88a8453e889b21e4036a4c3d4add33529e8 | |
parent | 6596a926b0b6c80b730a1dd2fa91908e0a539c37 (diff) |
xhci: Clear the host side toggle manually when endpoint is 'soft reset'
Main benefit of this is to get xhci connected USB scanners to work.
Some devices use a clear endpoint halt request as a 'soft reset' even if
the endpoint is not halted. This will clear the toggle and sequence on the
device side. xHCI however refuses to reset a non-halted endpoint, so instead
we need to issue a configure endpoint command on xHCI to clear its host side
toggle and sequence, and get it in sync with the device side.
Tested-by: Mike Mammarella <mikem@crystalorb.net>
Cc: <stable@vger.kernel.org> # v3.18
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/usb/host/xhci-ring.c | 2 | ||||
-rw-r--r-- | drivers/usb/host/xhci.c | 100 | ||||
-rw-r--r-- | drivers/usb/host/xhci.h | 2 |
3 files changed, 94 insertions, 10 deletions
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 88da8d629820..b46b5b98a943 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c | |||
@@ -1729,7 +1729,7 @@ static void xhci_cleanup_halted_endpoint(struct xhci_hcd *xhci, | |||
1729 | if (!command) | 1729 | if (!command) |
1730 | return; | 1730 | return; |
1731 | 1731 | ||
1732 | ep->ep_state |= EP_HALTED; | 1732 | ep->ep_state |= EP_HALTED | EP_RECENTLY_HALTED; |
1733 | ep->stopped_stream = stream_id; | 1733 | ep->stopped_stream = stream_id; |
1734 | 1734 | ||
1735 | xhci_queue_reset_ep(xhci, command, slot_id, ep_index); | 1735 | xhci_queue_reset_ep(xhci, command, slot_id, ep_index); |
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index ec8ac1674854..b06d1a53652d 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c | |||
@@ -1338,6 +1338,12 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) | |||
1338 | goto exit; | 1338 | goto exit; |
1339 | } | 1339 | } |
1340 | 1340 | ||
1341 | /* Reject urb if endpoint is in soft reset, queue must stay empty */ | ||
1342 | if (xhci->devs[slot_id]->eps[ep_index].ep_state & EP_CONFIG_PENDING) { | ||
1343 | xhci_warn(xhci, "Can't enqueue URB while ep is in soft reset\n"); | ||
1344 | ret = -EINVAL; | ||
1345 | } | ||
1346 | |||
1341 | if (usb_endpoint_xfer_isoc(&urb->ep->desc)) | 1347 | if (usb_endpoint_xfer_isoc(&urb->ep->desc)) |
1342 | size = urb->number_of_packets; | 1348 | size = urb->number_of_packets; |
1343 | else | 1349 | else |
@@ -2948,23 +2954,36 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, | |||
2948 | } | 2954 | } |
2949 | } | 2955 | } |
2950 | 2956 | ||
2951 | /* Called when clearing halted device. The core should have sent the control | 2957 | /* Called after clearing a halted device. USB core should have sent the control |
2952 | * message to clear the device halt condition. The host side of the halt should | 2958 | * message to clear the device halt condition. The host side of the halt should |
2953 | * already be cleared with a reset endpoint command issued when the STALL tx | 2959 | * already be cleared with a reset endpoint command issued immediately when the |
2954 | * event was received. | 2960 | * STALL tx event was received. |
2955 | * | ||
2956 | * Context: in_interrupt | ||
2957 | */ | 2961 | */ |
2958 | 2962 | ||
2959 | void xhci_endpoint_reset(struct usb_hcd *hcd, | 2963 | void xhci_endpoint_reset(struct usb_hcd *hcd, |
2960 | struct usb_host_endpoint *ep) | 2964 | struct usb_host_endpoint *ep) |
2961 | { | 2965 | { |
2962 | struct xhci_hcd *xhci; | 2966 | struct xhci_hcd *xhci; |
2967 | struct usb_device *udev; | ||
2968 | struct xhci_virt_device *virt_dev; | ||
2969 | struct xhci_virt_ep *virt_ep; | ||
2970 | struct xhci_input_control_ctx *ctrl_ctx; | ||
2971 | struct xhci_command *command; | ||
2972 | unsigned int ep_index, ep_state; | ||
2973 | unsigned long flags; | ||
2974 | u32 ep_flag; | ||
2963 | 2975 | ||
2964 | xhci = hcd_to_xhci(hcd); | 2976 | xhci = hcd_to_xhci(hcd); |
2977 | udev = (struct usb_device *) ep->hcpriv; | ||
2978 | if (!ep->hcpriv) | ||
2979 | return; | ||
2980 | virt_dev = xhci->devs[udev->slot_id]; | ||
2981 | ep_index = xhci_get_endpoint_index(&ep->desc); | ||
2982 | virt_ep = &virt_dev->eps[ep_index]; | ||
2983 | ep_state = virt_ep->ep_state; | ||
2965 | 2984 | ||
2966 | /* | 2985 | /* |
2967 | * We might need to implement the config ep cmd in xhci 4.8.1 note: | 2986 | * Implement the config ep command in xhci 4.6.8 additional note: |
2968 | * The Reset Endpoint Command may only be issued to endpoints in the | 2987 | * The Reset Endpoint Command may only be issued to endpoints in the |
2969 | * Halted state. If software wishes reset the Data Toggle or Sequence | 2988 | * Halted state. If software wishes reset the Data Toggle or Sequence |
2970 | * Number of an endpoint that isn't in the Halted state, then software | 2989 | * Number of an endpoint that isn't in the Halted state, then software |
@@ -2972,9 +2991,72 @@ void xhci_endpoint_reset(struct usb_hcd *hcd, | |||
2972 | * for the target endpoint. that is in the Stopped state. | 2991 | * for the target endpoint. that is in the Stopped state. |
2973 | */ | 2992 | */ |
2974 | 2993 | ||
2975 | /* For now just print debug to follow the situation */ | 2994 | if (ep_state & SET_DEQ_PENDING || ep_state & EP_RECENTLY_HALTED) { |
2976 | xhci_dbg(xhci, "Endpoint 0x%x ep reset callback called\n", | 2995 | virt_ep->ep_state &= ~EP_RECENTLY_HALTED; |
2977 | ep->desc.bEndpointAddress); | 2996 | xhci_dbg(xhci, "ep recently halted, no toggle reset needed\n"); |
2997 | return; | ||
2998 | } | ||
2999 | |||
3000 | /* Only interrupt and bulk ep's use Data toggle, USB2 spec 5.5.4-> */ | ||
3001 | if (usb_endpoint_xfer_control(&ep->desc) || | ||
3002 | usb_endpoint_xfer_isoc(&ep->desc)) | ||
3003 | return; | ||
3004 | |||
3005 | ep_flag = xhci_get_endpoint_flag(&ep->desc); | ||
3006 | |||
3007 | if (ep_flag == SLOT_FLAG || ep_flag == EP0_FLAG) | ||
3008 | return; | ||
3009 | |||
3010 | command = xhci_alloc_command(xhci, true, true, GFP_NOWAIT); | ||
3011 | if (!command) { | ||
3012 | xhci_err(xhci, "Could not allocate xHCI command structure.\n"); | ||
3013 | return; | ||
3014 | } | ||
3015 | |||
3016 | spin_lock_irqsave(&xhci->lock, flags); | ||
3017 | |||
3018 | /* block ringing ep doorbell */ | ||
3019 | virt_ep->ep_state |= EP_CONFIG_PENDING; | ||
3020 | |||
3021 | /* | ||
3022 | * Make sure endpoint ring is empty before resetting the toggle/seq. | ||
3023 | * Driver is required to synchronously cancel all transfer request. | ||
3024 | * | ||
3025 | * xhci 4.6.6 says we can issue a configure endpoint command on a | ||
3026 | * running endpoint ring as long as it's idle (queue empty) | ||
3027 | */ | ||
3028 | |||
3029 | if (!list_empty(&virt_ep->ring->td_list)) { | ||
3030 | dev_err(&udev->dev, "EP not empty, refuse reset\n"); | ||
3031 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
3032 | goto cleanup; | ||
3033 | } | ||
3034 | |||
3035 | xhci_dbg(xhci, "Reset toggle/seq for slot %d, ep_index: %d\n", | ||
3036 | udev->slot_id, ep_index); | ||
3037 | |||
3038 | ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); | ||
3039 | if (!ctrl_ctx) { | ||
3040 | xhci_err(xhci, "Could not get input context, bad type. virt_dev: %p, in_ctx %p\n", | ||
3041 | virt_dev, virt_dev->in_ctx); | ||
3042 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
3043 | goto cleanup; | ||
3044 | } | ||
3045 | xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx, | ||
3046 | virt_dev->out_ctx, ctrl_ctx, | ||
3047 | ep_flag, ep_flag); | ||
3048 | xhci_endpoint_copy(xhci, command->in_ctx, virt_dev->out_ctx, ep_index); | ||
3049 | |||
3050 | xhci_queue_configure_endpoint(xhci, command, command->in_ctx->dma, | ||
3051 | udev->slot_id, false); | ||
3052 | xhci_ring_cmd_db(xhci); | ||
3053 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
3054 | |||
3055 | wait_for_completion(command->completion); | ||
3056 | |||
3057 | cleanup: | ||
3058 | virt_ep->ep_state &= ~EP_CONFIG_PENDING; | ||
3059 | xhci_free_command(xhci, command); | ||
2978 | } | 3060 | } |
2979 | 3061 | ||
2980 | static int xhci_check_streams_endpoint(struct xhci_hcd *xhci, | 3062 | static int xhci_check_streams_endpoint(struct xhci_hcd *xhci, |
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 68956b13b8d1..3b97f0582155 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h | |||
@@ -864,6 +864,8 @@ struct xhci_virt_ep { | |||
864 | #define EP_HAS_STREAMS (1 << 4) | 864 | #define EP_HAS_STREAMS (1 << 4) |
865 | /* Transitioning the endpoint to not using streams, don't enqueue URBs */ | 865 | /* Transitioning the endpoint to not using streams, don't enqueue URBs */ |
866 | #define EP_GETTING_NO_STREAMS (1 << 5) | 866 | #define EP_GETTING_NO_STREAMS (1 << 5) |
867 | #define EP_RECENTLY_HALTED (1 << 6) | ||
868 | #define EP_CONFIG_PENDING (1 << 7) | ||
867 | /* ---- Related to URB cancellation ---- */ | 869 | /* ---- Related to URB cancellation ---- */ |
868 | struct list_head cancelled_td_list; | 870 | struct list_head cancelled_td_list; |
869 | struct xhci_td *stopped_td; | 871 | struct xhci_td *stopped_td; |