xhci: move and rename xhci_cleanup_halted_endpoint()
authorMathias Nyman <mathias.nyman@linux.intel.com>
Fri, 29 Jan 2021 13:00:37 +0000 (15:00 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 29 Jan 2021 13:16:51 +0000 (14:16 +0100)
Halted endpoints can be discoverd both when handling transfer events and
command completion events. Move code that handles halted endpoints before
both of those event handlers.

Rename the function to xhci_handle_halted_ep() to better describe
what it does. Try to reserve "cleanup" word in function names for last
stage cleanup activities.

No functional changes

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20210129130044.206855-21-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/host/xhci-ring.c

index 2101ec9..42639de 100644 (file)
@@ -817,6 +817,35 @@ done:
        return ret;
 }
 
+static void xhci_handle_halted_endpoint(struct xhci_hcd *xhci,
+                               struct xhci_virt_ep *ep, unsigned int stream_id,
+                               struct xhci_td *td,
+                               enum xhci_ep_reset_type reset_type)
+{
+       unsigned int slot_id = ep->vdev->slot_id;
+       int err;
+
+       /*
+        * Avoid resetting endpoint if link is inactive. Can cause host hang.
+        * Device will be reset soon to recover the link so don't do anything
+        */
+       if (ep->vdev->flags & VDEV_PORT_ERROR)
+               return;
+
+       ep->ep_state |= EP_HALTED;
+
+       err = xhci_reset_halted_ep(xhci, slot_id, ep->ep_index, reset_type);
+       if (err)
+               return;
+
+       if (reset_type == EP_HARD_RESET) {
+               ep->ep_state |= EP_HARD_CLEAR_TOGGLE;
+               xhci_cleanup_stalled_ring(xhci, slot_id, ep->ep_index, stream_id,
+                                         td);
+       }
+       xhci_ring_cmd_db(xhci);
+}
+
 /*
  * Fix up the ep ring first, so HW stops executing cancelled TDs.
  * We have the xHCI lock, so nothing can modify this list until we drop it.
@@ -1964,35 +1993,6 @@ static void xhci_clear_hub_tt_buffer(struct xhci_hcd *xhci, struct xhci_td *td,
        }
 }
 
-static void xhci_cleanup_halted_endpoint(struct xhci_hcd *xhci,
-                               struct xhci_virt_ep *ep, unsigned int stream_id,
-                               struct xhci_td *td,
-                               enum xhci_ep_reset_type reset_type)
-{
-       unsigned int slot_id = ep->vdev->slot_id;
-       int err;
-
-       /*
-        * Avoid resetting endpoint if link is inactive. Can cause host hang.
-        * Device will be reset soon to recover the link so don't do anything
-        */
-       if (ep->vdev->flags & VDEV_PORT_ERROR)
-               return;
-
-       ep->ep_state |= EP_HALTED;
-
-       err = xhci_reset_halted_ep(xhci, slot_id, ep->ep_index, reset_type);
-       if (err)
-               return;
-
-       if (reset_type == EP_HARD_RESET) {
-               ep->ep_state |= EP_HARD_CLEAR_TOGGLE;
-               xhci_cleanup_stalled_ring(xhci, slot_id, ep->ep_index, stream_id,
-                                         td);
-       }
-       xhci_ring_cmd_db(xhci);
-}
-
 /* Check if an error has halted the endpoint ring.  The class driver will
  * cleanup the halt for a non-default control endpoint if we indicate a stall.
  * However, a babble and other errors also halt the endpoint ring, and the class
@@ -2068,7 +2068,8 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_td *td,
                 */
                if ((ep->ep_index != 0) || (trb_comp_code != COMP_STALL_ERROR))
                        xhci_clear_hub_tt_buffer(xhci, td, ep);
-               xhci_cleanup_halted_endpoint(xhci, ep, ep_ring->stream_id, td,
+
+               xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td,
                                             EP_HARD_RESET);
        } else {
                /* Update ring dequeue pointer */
@@ -2354,8 +2355,9 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td,
                        break;
 
                td->status = 0;
-               xhci_cleanup_halted_endpoint(xhci, ep, ep_ring->stream_id, td,
-                                            EP_SOFT_RESET);
+
+               xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td,
+                                           EP_SOFT_RESET);
                return 0;
        default:
                /* do nothing */
@@ -2428,8 +2430,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,
                case COMP_USB_TRANSACTION_ERROR:
                case COMP_INVALID_STREAM_TYPE_ERROR:
                case COMP_INVALID_STREAM_ID_ERROR:
-                       xhci_cleanup_halted_endpoint(xhci, ep, 0, NULL,
-                                                    EP_SOFT_RESET);
+                       xhci_handle_halted_endpoint(xhci, ep, 0, NULL,
+                                                   EP_SOFT_RESET);
                        goto cleanup;
                case COMP_RING_UNDERRUN:
                case COMP_RING_OVERRUN:
@@ -2613,10 +2615,10 @@ static int handle_tx_event(struct xhci_hcd *xhci,
                        if (trb_comp_code == COMP_STALL_ERROR ||
                            xhci_requires_manual_halt_cleanup(xhci, ep_ctx,
                                                              trb_comp_code)) {
-                               xhci_cleanup_halted_endpoint(xhci, ep,
-                                                            ep_ring->stream_id,
-                                                            NULL,
-                                                            EP_HARD_RESET);
+                               xhci_handle_halted_endpoint(xhci, ep,
+                                                           ep_ring->stream_id,
+                                                           NULL,
+                                                           EP_HARD_RESET);
                        }
                        goto cleanup;
                }
@@ -2708,9 +2710,9 @@ static int handle_tx_event(struct xhci_hcd *xhci,
                        if (trb_comp_code == COMP_STALL_ERROR ||
                            xhci_requires_manual_halt_cleanup(xhci, ep_ctx,
                                                              trb_comp_code))
-                               xhci_cleanup_halted_endpoint(xhci, ep,
-                                                            ep_ring->stream_id,
-                                                            td, EP_HARD_RESET);
+                               xhci_handle_halted_endpoint(xhci, ep,
+                                                           ep_ring->stream_id,
+                                                           td, EP_HARD_RESET);
                        goto cleanup;
                }