From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E64E4570DE for ; Tue, 4 Aug 2026 10:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785837882; cv=none; b=X+GI4EUnYO4GwjGxxapK0UkbsdJMudTi6LsPGO2VklIyo2dCE5O7ljtqzvmutkwEyQAsWIAh3p4/Y+OPcXy8XvcN7URhXuc1Xm4kVOBLO3bt7/cJjrc6MnfXanbMo2LgzlW4GOFUWZAJPybzRY7771xwckkNrEj18wiG8L/S68M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785837882; c=relaxed/simple; bh=IqAhJCxRkb6lfpuaonAkPepeYUWJNOqAdbIiKh1yC5s=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OpGteY6C6IGtZI003m2Db1Fo9iAiQgVpgX7LIiUy9VkKz0UvBiOTFRDEyovvyss2mqIl4ZFsPoIonRS9U7+JetHce9+XnkFmlqIIB5n+aZPNu2e/plJTRFUXqTkm1XgZJ7DQDd6oPCQfgoXC4Xjt2d9Vu3doEvPkCPYBo2/tf4o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YW5zlJbD; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YW5zlJbD" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4980dc26022so20566145e9.1 for ; Tue, 04 Aug 2026 03:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785837879; x=1786442679; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=HpDn3hiVuA1sei69QrJvJ/J82fmpj8mowHCqmySopVY=; b=YW5zlJbDc2eYIYQ/8ROPIs28g9poWX4kbYFvtJUeLix7Zh9QNRlaX79EOYxbTvVUVY /zpPGuCI5Sn3htqr/ED0/8mxl6/bSwStaCXLZdiJ9Cqx3YJdKlLszXwyCZHT7OUa7yui 3n2zUaQAJZDpWtN0jQxxuAZBBnRZiQ2W1uQWkT5rbx4c3ULPBM7yZf5Pgv8Wm4UCMc7I gKNwGPaF6DLCzKw+o+1hIs7VSSD+ljuzHTbJ4QuXB/FRUcXkf6LSQuJllwsLzWN3g6gb rpJJzcZK1zpqlruOkhfcSJrnZSMoJYzXQbLVbnvm3J17n/Gw+L/T/mPZVH+/ckqOr1yJ vbcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785837879; x=1786442679; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=HpDn3hiVuA1sei69QrJvJ/J82fmpj8mowHCqmySopVY=; b=iMliXLkMPCM65IRyo1VHvlaXD6AnfdQOClhwGEzC3I5Ha6uDGJi3EaVtzyIjlXZqKP d9rGn3XtabqRAcetIOKOwrQ2QK5Lwf/EadascnwckBKiSnkJS6eUkRSrhgDd04hIKeEI 4UgckRSJaMxsilW5R2Rm2oLr0cDNKElVw0yp1A9yOpaRxavmvs9+BPRbLx4BYlMD2lxR kpmjAMpmGQEBp0s40LxFK+surtbQtlDrG8U6jzBo85IykCzCKhLkC1NSlFPfnMM8mOfJ ToHfgn8R8nYrvT2hsJCnLBshkZzJ/ygHa15DByjzlL4a0AEqyx6g4y7ODFu9iYgbUow+ DiUQ== X-Forwarded-Encrypted: i=1; AHgh+Rph2oVWSWNyDcMKAo0jvU4BEbYl6pDIHFMMqdaUgawokhhCzoAlaqiptV/xmEN58jhgPWC+GvYWhN6ixf0=@vger.kernel.org X-Gm-Message-State: AOJu0YzMALFBUWBbIisNrcFianUUB4eZ65JKB+AsB5TD9bWHbz57K6bw VPKT2R69rQz75MtIhl7y8l2r+rHBoOPyARRi5zEekHoiNI9o6yAbP66l X-Gm-Gg: AR+sD11WlRKiSm7DqmsCzbcTMI55bKnIln4r5j/RQqGB8XtXRQ2csNrsFyHmY60WLUO 97+SrLoZVFtUjYs+87zhXoqtp2cB//ditHtVEiKVbp2nYHKQXFKAhbGxRIjgy+fw2QETcg/pDsr NTrNQCjRW2IWDx+FNsrXY+aHcZvp9ss7pkHyQMOoXCLT1oMGDIPIEAuQynMrRye6zD7Dk1jbnpg XfiEdLEAH4XPMcRKZm81hcnbdIzlceh1jOV9tXkejOrXCsr50mu6YXHrwk2FZtJ0x/8vgKfbckB 5ejmviv4hhsg/Et4njvVAZAn3W/s1Vmu5qf4JENQ58s0qHHI3yZ4ssQmWINgTiUA9EJsyN4cE8o z0smf1o40qXfZhk2X66pIMREK5yM+5/YsDh/n0IG15KFBQvJDB1DSw3lnQTqRtYq/ZhHXpxE/P8 8ntICZbVt71l1GrqsYdM/ej2B2PWGEmJVHgGmAErSz3Smi9r7xuTdcDcG1UFW7/KokP4vp2Yd1 X-Received: by 2002:a05:600c:4444:b0:493:f6f0:d66b with SMTP id 5b1f17b1804b1-4980c6458aamr294474585e9.1.1785837879422; Tue, 04 Aug 2026 03:04:39 -0700 (PDT) Received: from foxbook (bgt135.neoplus.adsl.tpnet.pl. [83.28.83.135]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49949fcb46esm86659055e9.5.2026.08.04.03.04.38 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 04 Aug 2026 03:04:39 -0700 (PDT) Date: Tue, 4 Aug 2026 12:04:36 +0200 From: Michal Pecio To: Mathias Nyman , Greg Kroah-Hartman Cc: Bart Nagel , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] usb: xhci: Shorten the TD skipping loop Message-ID: <20260804120436.0832eea2.michal.pecio@gmail.com> In-Reply-To: <20260804120110.01bda0e2.michal.pecio@gmail.com> References: <20260804120110.01bda0e2.michal.pecio@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Half of this loop is code which only executes once to deal with cases where no TD matches the event and then it returns. This code needs not to be in any kind of loop, so get it out. Optimize conditionals remaining in the loop body. Signed-off-by: Michal Pecio --- drivers/usb/host/xhci-ring.c | 69 +++++++++++++++++------------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 8270c63ec3bf..1f0cb6a701c5 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2843,10 +2843,9 @@ static int handle_tx_event(struct xhci_hcd *xhci, td = list_first_entry(&ep_ring->td_list, struct xhci_td, td_list); - /* Is this TRB not part of the currently executing TD? */ - if (!trb_in_td(td, ep_trb_dma)) { + if (ep->skip) { - if (ep->skip) { + if (!trb_in_td(td, ep_trb_dma)) { /* this event is unlikely to match any TD, don't skip them all */ if (trb_comp_code == COMP_STOPPED_LENGTH_INVALID) return 0; @@ -2884,38 +2883,6 @@ static int handle_tx_event(struct xhci_hcd *xhci, goto check_endpoint_halted; } - /* TD was queued after xrun, maybe xrun was on a link, don't panic yet */ - if (ring_xrun_event) - return 0; - - /* - * Skip the Force Stopped Event. The 'ep_trb' of FSE is not in the current - * TD pointed by 'ep_ring->dequeue' because that the hardware dequeue - * pointer still at the previous TRB of the current TD. The previous TRB - * maybe a Link TD or the last TRB of the previous TD. The command - * completion handle will take care the rest. - */ - if (trb_comp_code == COMP_STOPPED || - trb_comp_code == COMP_STOPPED_LENGTH_INVALID) { - return 0; - } - - /* - * Some hosts give a spurious success event after a short - * transfer or error on last TRB. Ignore it. - */ - if (xhci_spurious_success_tx_event(xhci, ep_ring)) { - xhci_dbg(xhci, "Spurious event dma %pad, comp_code %u after %u\n", - &ep_trb_dma, trb_comp_code, ep_ring->old_trb_comp_code); - ep_ring->old_trb_comp_code = 0; - return 0; - } - - /* HC is busted, give up! */ - goto debug_finding_td; - } - - if (ep->skip) { xhci_dbg(xhci, "Found td. Clear skip flag for slot %u ep %u.\n", slot_id, ep_index); @@ -2932,10 +2899,40 @@ static int handle_tx_event(struct xhci_hcd *xhci, ep_ring->old_trb_comp_code = trb_comp_code; - /* Get out if a TD was queued at enqueue after the xrun occurred */ + /* + * Underrun handling ends here. Any TD pointed by the event was enqueued after the event + * occurred, so wait for its completion now. And it's not a bug if no such TD exists. + */ if (ring_xrun_event) return 0; + /* Handle events not referencing the current TD */ + if (!trb_in_td(td, ep_trb_dma)) { + /* + * Skip the Force Stopped Event. The 'ep_trb' of FSE is not in the current + * TD pointed by 'ep_ring->dequeue' because that the hardware dequeue + * pointer still at the previous TRB of the current TD. The previous TRB + * maybe a Link TD or the last TRB of the previous TD. The command + * completion handle will take care the rest. + */ + if (trb_comp_code == COMP_STOPPED || trb_comp_code == COMP_STOPPED_LENGTH_INVALID) + return 0; + + /* + * Some hosts give a spurious success event after a short + * transfer or error on last TRB. Ignore it. + */ + if (xhci_spurious_success_tx_event(xhci, ep_ring)) { + xhci_dbg(xhci, "Spurious event dma %pad, comp_code %u after %u\n", + &ep_trb_dma, trb_comp_code, ep_ring->old_trb_comp_code); + ep_ring->old_trb_comp_code = 0; + return 0; + } + + /* HC is busted, give up! */ + goto debug_finding_td; + } + trace_xhci_handle_transfer(ep_ring, (struct xhci_generic_trb *) ep_trb, ep_trb_dma); /* -- 2.48.1