Linux USB
 help / color / mirror / Atom feed
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 11/21] usb: xhci: move untargeted transfer event handling to a separate function
Date: Wed, 26 Jun 2024 15:48:25 +0300	[thread overview]
Message-ID: <20240626124835.1023046-12-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20240626124835.1023046-1-mathias.nyman@linux.intel.com>

From: Niklas Neronin <niklas.neronin@linux.intel.com>

Move handling transfer events without a target transfer TRB into
handle_transferless_tx_event(), this type of event does not utilize the
rest of handle_tx_event() and as a result it's better to separate it
into a dedicated function.

Additionally, this change reduces handle_tx_event()'s size and makes it
more readable.

[Mathias: Simplify code to return helper function value directly. This
removes the second xhci_err() message for untargeted and unexpected
event completion types]

Signed-off-by: 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 8502776d84d6..7f40be2a3885 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2562,6 +2562,33 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep,
 	return finish_td(xhci, ep, ep_ring, td, trb_comp_code);
 }
 
+/* Transfer events which don't point to a transfer TRB, see xhci 4.17.4 */
+static int handle_transferless_tx_event(struct xhci_hcd *xhci, struct xhci_virt_ep *ep,
+					u32 trb_comp_code)
+{
+	switch (trb_comp_code) {
+	case COMP_STALL_ERROR:
+	case COMP_USB_TRANSACTION_ERROR:
+	case COMP_INVALID_STREAM_TYPE_ERROR:
+	case COMP_INVALID_STREAM_ID_ERROR:
+		xhci_dbg(xhci, "Stream transaction error ep %u no id\n", ep->ep_index);
+		if (ep->err_count++ > MAX_SOFT_RETRY)
+			xhci_handle_halted_endpoint(xhci, ep, NULL, EP_HARD_RESET);
+		else
+			xhci_handle_halted_endpoint(xhci, ep, NULL, EP_SOFT_RESET);
+		break;
+	case COMP_RING_UNDERRUN:
+	case COMP_RING_OVERRUN:
+	case COMP_STOPPED_LENGTH_INVALID:
+		break;
+	default:
+		xhci_err(xhci, "ERROR Transfer event for unknown stream ring slot %u ep %u\n",
+			 ep->vdev->slot_id, ep->ep_index);
+		return -ENODEV;
+	}
+	return 0;
+}
+
 /*
  * If this function returns an error condition, it means it got a Transfer
  * event with a corrupted Slot ID, Endpoint ID, or TRB DMA address.
@@ -2605,33 +2632,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,
 		goto err_out;
 	}
 
-	/* Some transfer events don't always point to a trb, see xhci 4.17.4 */
-	if (!ep_ring) {
-		switch (trb_comp_code) {
-		case COMP_STALL_ERROR:
-		case COMP_USB_TRANSACTION_ERROR:
-		case COMP_INVALID_STREAM_TYPE_ERROR:
-		case COMP_INVALID_STREAM_ID_ERROR:
-			xhci_dbg(xhci, "Stream transaction error ep %u no id\n",
-				 ep_index);
-			if (ep->err_count++ > MAX_SOFT_RETRY)
-				xhci_handle_halted_endpoint(xhci, ep, NULL,
-							    EP_HARD_RESET);
-			else
-				xhci_handle_halted_endpoint(xhci, ep, NULL,
-							    EP_SOFT_RESET);
-			break;
-		case COMP_RING_UNDERRUN:
-		case COMP_RING_OVERRUN:
-		case COMP_STOPPED_LENGTH_INVALID:
-			break;
-		default:
-			xhci_err(xhci, "ERROR Transfer event for unknown stream ring slot %u ep %u\n",
-				 slot_id, ep_index);
-			goto err_out;
-		}
-		return 0;
-	}
+	if (!ep_ring)
+		return handle_transferless_tx_event(xhci, ep, trb_comp_code);
 
 	/* Count current td numbers if ep->skip is set */
 	if (ep->skip)
-- 
2.25.1


  parent reply	other threads:[~2024-06-26 12:46 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 ` Mathias Nyman [this message]
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 ` [PATCH 14/21] xhci: rework xhci internal endpoint halt state detection Mathias Nyman
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-12-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox