From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>,
niklas.neronin@linux.intel.com,
Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [PATCH 14/21] xhci: rework xhci internal endpoint halt state detection.
Date: Wed, 26 Jun 2024 15:48:28 +0300 [thread overview]
Message-ID: <20240626124835.1023046-15-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20240626124835.1023046-1-mathias.nyman@linux.intel.com>
When xhci_requires_manual_halt_cleanup() was written it wasn't clear
that the xhci internal endpoint halt state always needs to be cleared
with a reset endpoint command. Functional stall cases additionally halt
the device side endpoint which requires class driver to clear the device
side halt with a CLEAR_FEATURE(ENDPOINT_HALT) request as well.
Clean up, rename, and make sure the new function always return true
when internal endpoint state is halted, including stall cases.
Based on related cleanup suggestion code by Niklas Neronin
cc: Niklas Neronin <niklas.neronin@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
drivers/usb/host/xhci-ring.c | 56 +++++++++++++++++++-----------------
1 file changed, 29 insertions(+), 27 deletions(-)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 900bf34174f9..3479c9cb5d33 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2130,28 +2130,34 @@ static void xhci_clear_hub_tt_buffer(struct xhci_hcd *xhci, struct xhci_td *td,
}
}
-/* 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
- * driver won't clear the halt in that case, so we need to issue a Set Transfer
- * Ring Dequeue Pointer command manually.
+/*
+ * Check if xhci internal endpoint state has gone to a "halt" state due to an
+ * error or stall, including default control pipe protocol stall.
+ * The internal halt needs to be cleared with a reset endpoint command.
+ *
+ * External device side is also halted in functional stall cases. Class driver
+ * will clear the device halt with a CLEAR_FEATURE(ENDPOINT_HALT) request later.
*/
-static int xhci_requires_manual_halt_cleanup(struct xhci_ep_ctx *ep_ctx, unsigned int trb_comp_code)
+static bool xhci_halted_host_endpoint(struct xhci_ep_ctx *ep_ctx, unsigned int comp_code)
{
- /* TRB completion codes that may require a manual halt cleanup */
- if (trb_comp_code == COMP_USB_TRANSACTION_ERROR ||
- trb_comp_code == COMP_BABBLE_DETECTED_ERROR ||
- trb_comp_code == COMP_SPLIT_TRANSACTION_ERROR)
- /* The 0.95 spec says a babbling control endpoint
- * is not halted. The 0.96 spec says it is. Some HW
- * claims to be 0.95 compliant, but it halts the control
- * endpoint anyway. Check if a babble halted the
- * endpoint.
+ /* Stall halts both internal and device side endpoint */
+ if (comp_code == COMP_STALL_ERROR)
+ return true;
+
+ /* TRB completion codes that may require internal halt cleanup */
+ if (comp_code == COMP_USB_TRANSACTION_ERROR ||
+ comp_code == COMP_BABBLE_DETECTED_ERROR ||
+ comp_code == COMP_SPLIT_TRANSACTION_ERROR)
+ /*
+ * The 0.95 spec says a babbling control endpoint is not halted.
+ * The 0.96 spec says it is. Some HW claims to be 0.95
+ * compliant, but it halts the control endpoint anyway.
+ * Check endpoint context if endpoint is halted.
*/
if (GET_EP_CTX_STATE(ep_ctx) == EP_STATE_HALTED)
- return 1;
+ return true;
- return 0;
+ return false;
}
int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code)
@@ -2321,7 +2327,7 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep,
case COMP_STOPPED_LENGTH_INVALID:
goto finish_td;
default:
- if (!xhci_requires_manual_halt_cleanup(ep_ctx, trb_comp_code))
+ if (!xhci_halted_host_endpoint(ep_ctx, trb_comp_code))
break;
xhci_dbg(xhci, "TRB error %u, halted endpoint index = %u\n",
trb_comp_code, ep->ep_index);
@@ -2791,11 +2797,9 @@ static int handle_tx_event(struct xhci_hcd *xhci,
xhci_dbg(xhci, "td_list is empty while skip flag set. Clear skip flag for slot %u ep %u.\n",
slot_id, ep_index);
}
- if (trb_comp_code == COMP_STALL_ERROR ||
- xhci_requires_manual_halt_cleanup(ep_ctx, trb_comp_code)) {
- xhci_handle_halted_endpoint(xhci, ep, NULL,
- EP_HARD_RESET);
- }
+ if (xhci_halted_host_endpoint(ep_ctx, trb_comp_code))
+ xhci_handle_halted_endpoint(xhci, ep, NULL, EP_HARD_RESET);
+
return 0;
}
@@ -2911,10 +2915,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,
*/
if (trb_is_noop(ep_trb)) {
- if (trb_comp_code == COMP_STALL_ERROR ||
- xhci_requires_manual_halt_cleanup(ep_ctx, trb_comp_code))
- xhci_handle_halted_endpoint(xhci, ep, td,
- EP_HARD_RESET);
+ if (xhci_halted_host_endpoint(ep_ctx, trb_comp_code))
+ xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET);
} else {
td->status = status;
--
2.25.1
next prev parent reply other threads:[~2024-06-26 12:47 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-26 12:48 [PATCH 00/21] xhci features for usb-next Mathias Nyman
2024-06-26 12:48 ` [PATCH 01/21] xhci: Remove dead code in xhci_move_dequeue_past_td() Mathias Nyman
2024-06-26 12:48 ` [PATCH 02/21] xhci: show usb device name in xhci urb tracing Mathias Nyman
2024-06-26 12:48 ` [PATCH 03/21] xhci: Set correct transferred length for cancelled isoc transfers Mathias Nyman
2024-06-26 12:48 ` [PATCH 04/21] xhci: dbc: Allow users to modify DbC poll interval via sysfs Mathias Nyman
2024-06-26 12:48 ` [PATCH 05/21] usb: xhci: remove 'num_trbs' from struct 'xhci_td' Mathias Nyman
2024-06-26 12:48 ` [PATCH 06/21] usb: xhci: remove unused 'xhci' argument Mathias Nyman
2024-06-26 12:48 ` [PATCH 07/21] usb: xhci: remove unused argument from xhci_handle_cmd_config_ep() Mathias Nyman
2024-06-26 12:48 ` [PATCH 08/21] usb: xhci: remove unused argument from handle_port_status() Mathias Nyman
2024-06-26 12:48 ` [PATCH 09/21] usb: xhci: move link chain bit quirk checks into one helper function Mathias Nyman
2024-06-26 12:48 ` [PATCH 10/21] usb: xhci: move all segment re-numbering to xhci_link_rings() Mathias Nyman
2024-06-26 12:48 ` [PATCH 11/21] usb: xhci: move untargeted transfer event handling to a separate function Mathias Nyman
2024-06-26 12:48 ` [PATCH 12/21] usb: xhci: improve error message for targetless transfer event Mathias Nyman
2024-06-26 12:48 ` [PATCH 13/21] usb: xhci: remove obsolete sanity check debug messages Mathias Nyman
2024-06-26 12:48 ` Mathias Nyman [this message]
2024-06-26 12:48 ` [PATCH 15/21] usb: xhci: ensure skipped isoc TDs are returned when isoc ring is stopped Mathias Nyman
2024-06-26 12:48 ` [PATCH 16/21] usb: xhci: remove false xhci_giveback_urb_in_irq() header comment Mathias Nyman
2024-06-26 12:48 ` [PATCH 17/21] usb: xhci: remove infinite loop prevention Mathias Nyman
2024-06-26 12:48 ` [PATCH 18/21] usb: xhci: move process TD code out of the while loop Mathias Nyman
2024-06-26 12:48 ` [PATCH 19/21] usb: xhci: add 'goto' for halted endpoint check in handle_tx_event() Mathias Nyman
2024-08-02 9:21 ` Michał Pecio
2024-08-02 9:39 ` Neronin, Niklas
2024-06-26 12:48 ` [PATCH 20/21] xhci: Apply XHCI_RESET_TO_DEFAULT quirk to TGL Mathias Nyman
2024-06-26 12:48 ` [PATCH 21/21] xhci: sort out TRB Endpoint ID bitfield macros Mathias Nyman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240626124835.1023046-15-mathias.nyman@linux.intel.com \
--to=mathias.nyman@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=niklas.neronin@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.