From patchwork Tue Aug 27 17:47:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Pecio?= X-Patchwork-Id: 823018 Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (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 D9745126F1E for ; Tue, 27 Aug 2024 17:47:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724780874; cv=none; b=oy8j0Acp8iAl2JrCueu/bwxyGbS4YQFsiXFR30bUbj3tHk8Xn6hrZJWgQjt45bwbN9pHwlNHH5kkLDtOOrb21rchKlR3XiG6bwSKsN6IEoMW8estkqgbfqJVgt9VnssodOyXoWXiyly6KxPjEL0l7DPV3s7AM6tEQBsBf6ANepQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724780874; c=relaxed/simple; bh=R9VtU7sUrvULGTa/fT9R1zipBdrOY2kn7d26z1twkO4=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IgWMbThheZ3NIxRZgeIppkEybrE6mKaJik/Rhbgc9qCDXe2rOpjsElKW7U2XtawN9ZCl1l1mw4h61ir0Y9ZL5Fwx7BqKD8jPVg4xh667xc0sK80/AQ2mxKZTfXMQLrRCo9ngz+voxj5dHc6nK1HD3C0UYA248OxITkH5Mh4PPn4= 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=bftXrIaq; arc=none smtp.client-ip=209.85.208.180 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="bftXrIaq" Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2f50966c448so33242991fa.2 for ; Tue, 27 Aug 2024 10:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724780871; x=1725385671; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=hcK2DE6OvHJg2Aa3M6TjPuN4vHu2Shd9E4BSp/NGuwY=; b=bftXrIaq0BhU5kz2V2Gi7lsR1Z5dlNQXY3/7gSPu1pHH7aJDXYmyIKlmZvvrDmxBDv 7CY6vzXRRXECZ4tLy0ETkBkoTmY5WncQ9Gd1CguK7uwBJiyovHLTRs5XPRlPyQ72Gvz2 tv0GfxyB6kQie87CBPPRLJZLqkm3Y0H9u5pPU1fyKWqFE5RyWGgNeetki5OjLDqly0+D x7cjBkLFC1/FNhZLGBAVdRwuNOVW7OhDwiG6ncK6nM48mJkpIT5kYsmGtiScl+QBkhR7 VeQ79IcLmF60k0OEnMAvtIpMWflVsg3+Gg87KUFQ+lA5rTLJPBhvAhPkFf/TG87ffE/w Xc3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724780871; x=1725385671; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hcK2DE6OvHJg2Aa3M6TjPuN4vHu2Shd9E4BSp/NGuwY=; b=YTNWD6gBoyX6Tgr2JbKlch56IaEdy2fEGLOwtEjdCzI+DJpzuMuex50X0sVLD2DKtf wqAusxtTATXRDeNjjBt/8HM3aUEWCKXOjTZ1stbx2oaX2ykvnJ9hzUcDRy3blIXuVt8p FTooq9QeR11bo6FFvsnu9wcjp9uVT2Cs8DIQAXRvPo7HOkqACQ6Dw8BFo9Aw1XmgKW4W HU/Ql6/iM4Fhx97bJkkBi1XPMpKs0u9jFzE/GTDRTvXG2oVEhBUXqY6nw/PglKXk1yJe wNaopHunuPHRtJKyg/Bl2SqE4ZxLGGjzr5G8g80BSO/RqLnmu1X8I6a55ASoHxe+hKbQ oGEQ== X-Gm-Message-State: AOJu0YywhaAjC9ReQljl1rxmwSKm3YbM/yaT8i23N1X01l6cqHNdPpaW H7NhLXd4c4vYCgKtZR2J+ESjYnTzJpkpiEDVqbDF8RBnOqhlzjyi X-Google-Smtp-Source: AGHT+IFHX5AGo7DqA8jJH6SBKXHFlwrUFA0ovJYb5LLANHWzMJFgK9zGyRA4Di9PDrG9K0u9M03dOg== X-Received: by 2002:a05:651c:198d:b0:2f0:1a8f:4cd2 with SMTP id 38308e7fff4ca-2f514b92e5cmr34992831fa.33.1724780870679; Tue, 27 Aug 2024 10:47:50 -0700 (PDT) Received: from foxbook (bgu35.neoplus.adsl.tpnet.pl. [83.28.84.35]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2f4047c6741sm16633421fa.50.2024.08.27.10.47.49 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 27 Aug 2024 10:47:50 -0700 (PDT) Date: Tue, 27 Aug 2024 19:47:47 +0200 From: Michal Pecio To: Mathias Nyman Cc: linux-usb@vger.kernel.org Subject: [PATCH 1/9] usb: xhci: Fix double newline in a debug message Message-ID: <20240827194747.42142227@foxbook> In-Reply-To: <20240827194625.61be5733@foxbook> References: <20240827194625.61be5733@foxbook> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 xhci_dbg_trace() appends a newline to the format string, don't call it with a newline terminated string. Signed-off-by: Michal Pecio --- drivers/usb/host/xhci-ring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 4ea2c3e072a9..e960609dcf51 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -723,9 +723,9 @@ static int xhci_move_dequeue_past_td(struct xhci_hcd *xhci, ep->queued_deq_seg = new_seg; ep->queued_deq_ptr = new_deq; xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, - "Set TR Deq ptr 0x%llx, cycle %u\n", addr, new_cycle); + "Set TR Deq ptr 0x%llx, cycle %u", addr, new_cycle); /* Stop the TD queueing code from ringing the doorbell until * this command completes. The HC won't set the dequeue pointer * if the ring is running, and ringing the doorbell starts the From patchwork Tue Aug 27 17:49:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Pecio?= X-Patchwork-Id: 823017 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 E3F5A1D1F6C for ; Tue, 27 Aug 2024 17:50:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724781004; cv=none; b=jFsuNiUfSCrnHlOLGlrWQVwoDXnek2P2Aj4hzu4RiHfLJh+VpddJdo1ASiM7+5aNeY930PxtUH8mla/rZ1ST5O5hEL/pbAd4Is6vnnfxisggELAfis9dwi7EJ0q5bnDgJmPTbs8ToDrpmypAADEEro4k0dFPAfVim2xl3yiOB2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724781004; c=relaxed/simple; bh=JJhIKTk9bf+E+DzZOnkbZp8yn1cw1DaSfrljsKvHLB0=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R5YTAyHopMVTq27OtzRZjjIwNvo+N1ZFzWXINxcBM+oTh7875wc9NgWJLm38IQXpJu4Z5vjzqCKFsWVKV+iyeu8AfOayw6KB9M5ybL2HnIImZf1Y7Sf6H5wZGYEQrn/sEAwCDW42L8h6sQTY5SMyh4YzTnHU23vf8n/9wj8EQQI= 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=jg6OPMVs; arc=none smtp.client-ip=209.85.208.179 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="jg6OPMVs" Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2f3eabcd293so66380871fa.2 for ; Tue, 27 Aug 2024 10:50:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724781001; x=1725385801; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=wW+0n8rzUwmHxcQrm9+AWLnjviY2qXp2A8UIezo+VJo=; b=jg6OPMVs7I1kIfyALQ5XQ9qZ6CXOzWdBI0CBskOlnpuaGDUhIP5mxx+fRFL8Sn3toP 7LrtKxuBi15UNIflqknOxNxWgZyt8DDNyoX/2n3JhgESeUqHmPC0XIettcUK2rplHCm1 mlzF37Sggy1kyi/PPtE/oT8KGZJdeWH0plRuZ+C8sw3RlbRIFEAtAUgdgJPO0jDCYPem niDqo4XfnwqZy9j/az2oo5P15vSewkA4vVoQLoesYtwr9euKGKFXU8ZqHfsQB5TvwzPs FuqV9V1zlZVOG04uZajS/2PFshs4gfHLsZ9yHg2N/Uow81UsUEgWvQTOEnkem3brsqFC DMrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724781001; x=1725385801; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wW+0n8rzUwmHxcQrm9+AWLnjviY2qXp2A8UIezo+VJo=; b=YXNKsFKeg/c0vOyOE3AAn8rkfQLTFFHM3ard+7N+e4hwrsh3A8xTNZVyN5v83QxCx6 dXXo0JWTpKQlP4edpN9NmrfKH7goN+vyjRgn5QCMwe2wFLZjM5ayQNRsq8l+gOijt3iE /ENhDIw+wiJwiHJZDHSkP+02qOEgn+xeKVFlF7Z1KpvTw01s8fohnuKiwX5yVBouPgwi kCwLAZg5syMamip9XwbTCSOFOAZplXZ37Hk9ljqrf7GSIrQ1SiXx4QDewukQ0JUGabaP ozPOJRBoyiVtOKlEhM9H+hYNnktppNVf/7WIBK8POq+8lKCs8WCSs+uxJoz/5aesqZje PZ5A== X-Gm-Message-State: AOJu0Yxz9AwFw3E3aCJUDjWKA05Sg/XoQXU1uJw0572E/ZWPZRNfcoup 4TgJZmo2f83zAGvNIEnM5qWHEH4QVi9IgnzmMYGMdRzKGJno34X3 X-Google-Smtp-Source: AGHT+IGlFWA/+3zPgLd70uVe8EaT4RUCN+jFRGqYozda1Dc2kKe+zRV6jazQu1IqoxSVUycLZizmpQ== X-Received: by 2002:a2e:f09:0:b0:2f0:20cd:35fc with SMTP id 38308e7fff4ca-2f4f573a316mr97934851fa.7.1724781000559; Tue, 27 Aug 2024 10:50:00 -0700 (PDT) Received: from foxbook (bgu35.neoplus.adsl.tpnet.pl. [83.28.84.35]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2f4048ae5dfsm16573061fa.140.2024.08.27.10.49.59 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 27 Aug 2024 10:49:59 -0700 (PDT) Date: Tue, 27 Aug 2024 19:49:56 +0200 From: Michal Pecio To: Mathias Nyman Cc: linux-usb@vger.kernel.org Subject: [PATCH 3/9] usb: xhci: Clean up the TD skipping loop Message-ID: <20240827194956.537b963a@foxbook> In-Reply-To: <20240827194625.61be5733@foxbook> References: <20240827194625.61be5733@foxbook> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Recent reworks left this loop ending with: if (ep->skip) ep->skip = false; while (ep->skip); which obviously cannot ever repeat. Repetition is only possible by a 'continue' statement earlier in the loop body. Move the "tail" which only executes once out of the loop body. Bring the cases of "Found TD" and "skip isoc td" closely together to consolidate the skipping logic in one place and improve clarity. Now this code properly controls the loop condition. Signed-off-by: Michal Pecio --- drivers/usb/host/xhci-ring.c | 102 ++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 401c34ff2260..e65cc80cb285 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2829,63 +2829,65 @@ static int handle_tx_event(struct xhci_hcd *xhci, } } } - if (!ep_seg) { - - if (ep->skip && usb_endpoint_xfer_isoc(&td->urb->ep->desc)) { - skip_isoc_td(xhci, td, ep, status); - continue; - } - - /* - * 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. Ignore it. - * FIXME xHCI 4.10.1.1: this should be freed now, not mid-TD - */ - if ((xhci->quirks & XHCI_SPURIOUS_SUCCESS) && - ep_ring->last_td_was_short) { - ep_ring->last_td_was_short = false; - return 0; - } - - /* HC is busted, give up! */ - xhci_err(xhci, - "ERROR Transfer event TRB DMA ptr not " - "part of current TD ep_index %d " - "comp_code %u\n", ep_index, - trb_comp_code); - trb_in_td(xhci, td, ep_trb_dma, true); - return -ESHUTDOWN; - } - + /* + * If ep->skip is set, it means there are missed tds on the + * endpoint ring need to take care of. + * Process them as short transfer until reach the td pointed by + * the event. + */ if (ep->skip) { - xhci_dbg(xhci, - "Found td. Clear skip flag for slot %u ep %u.\n", - slot_id, ep_index); - ep->skip = false; + if (ep_seg) { + xhci_dbg(xhci, + "Found td. Clear skip flag for slot %u ep %u.\n", + slot_id, ep_index); + ep->skip = false; + } else { + if (usb_endpoint_xfer_isoc(&td->urb->ep->desc)) + skip_isoc_td(xhci, td, ep, status); + else + break; + } } - /* - * If ep->skip is set, it means there are missed tds on the - * endpoint ring need to take care of. - * Process them as short transfer until reach the td pointed by - * the event. - */ } while (ep->skip); + if (!ep_seg) { + + /* + * 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. Ignore it. + * FIXME xHCI 4.10.1.1: this should be freed now, not mid-TD + */ + if ((xhci->quirks & XHCI_SPURIOUS_SUCCESS) && + ep_ring->last_td_was_short) { + ep_ring->last_td_was_short = false; + return 0; + } + + /* HC is busted, give up! */ + xhci_err(xhci, + "ERROR Transfer event TRB DMA ptr not " + "part of current TD ep_index %d " + "comp_code %u\n", ep_index, + trb_comp_code); + trb_in_td(xhci, td, ep_trb_dma, true); + return -ESHUTDOWN; + } + if (trb_comp_code == COMP_SHORT_PACKET) ep_ring->last_td_was_short = true; else ep_ring->last_td_was_short = false; From patchwork Tue Aug 27 17:51:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Pecio?= X-Patchwork-Id: 823016 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 9EB2464A for ; Tue, 27 Aug 2024 17:51:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724781104; cv=none; b=FfWccrFi1Y7oDDM0nLg57bJfdGV0bYSDKV1Hg2k8HoF/l9t0q3EQ9Ac/vry0uwsSftlFbYrAM57NMpTkd9JQSxk85iOAIdrZ1E57pgWmuS6tG4RoViI/Qy7h9IeBageSGT10T3fXA1iWb1D8jYW1otX52yHa4sebGzJ+MlXWaRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724781104; c=relaxed/simple; bh=DXzDBKtxPymdALo95TtDZg+Y0fTm4sl0XyGKbn2iFzY=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GZc+WzUErQ0fAuTcD3fAd03oitw12rXVPor/N0XOEswU7mjmxz8wgZQuxsGhSFUqSEVFwAxIi742N3wNvqlDjUnWQCjm8/OJTgXPkH69wgbB8YRtnrB5F1g8cO3U7H0OagUkZciGOKjixjUm97+XFBfnv5ENSqbbq05FqLF0jn0= 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=kOmcayY0; arc=none smtp.client-ip=209.85.167.42 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="kOmcayY0" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-533462b9428so9875358e87.3 for ; Tue, 27 Aug 2024 10:51:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724781101; x=1725385901; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=45HTGQJVSBp5kQg+4OTSk7U8sPIgi6UhdgMThKsrpN4=; b=kOmcayY0OWxIis8fTtjHjE1qVTBduaSw2TTtmg4uZaFwn8Aijh8qsxJ7aTFZ3yWP0/ w87XtJCs5Q34eA7uMBnysIs0Kq0dhWk+NwvBGO62h3dy5IJyfvw7qncGb5T0R4TUzAYH H15Cjw2t//2XkGrr3yGdts2O2vanwCXwn+CUiI3qyXT/HReSlobKpmZMXDtqBsDAmwQU qKVc6XebDdgMuBb8no/a+QuqSjiVnyMo2g+X0npDRYmHNy5WuL/I6h0CIqrskUrEZQ0V vX3zbcNuVJUFqHAZcqk4mFLlwSB1zDI4h07ZLLp8Q6pnggAOK942yvZ7VPSKDvxtDqwR eA+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724781101; x=1725385901; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=45HTGQJVSBp5kQg+4OTSk7U8sPIgi6UhdgMThKsrpN4=; b=vpXym5VduE4Zk/4Uw+zrlBmnPCcOuzZje9VplyRgtNvynDN5sCuzhmsdFfTGwJzpEv iBy1122IY1YqbkGoC8leZt3Th1tl0AqfYi5XvYsuwRJVT61gnuecpVCHWoM9HR9Ap8z8 STChZjFX5OirnXHCmi9kurTX5yU3Xd4eFs1RpF0OXB9NVtTV2sABATmNgJqdVu1mDr3o jnsDNZXhRr7nb6R+HH/r8MvBxNVCngV+YsVWO5ZLp2hv8pln4lSmH9hgrJXPrMmB3Mxw NaCE65YPh9klAUTqbHTIFOMO5/yI0hLoYFG1HHG32mk9gmCfeNyHlfT5CwI34LONc308 AYjg== X-Gm-Message-State: AOJu0YxpfnEV4NZr53GG+85mw6rCUOV7gkDzUUdSW/gETxYsM8ZZhyEU upBvzXWpJOYSNpnY2tu00mon6Q9Vbo1yLSZmp0RbyWdo4cVqT4Qp X-Google-Smtp-Source: AGHT+IHWHb2VlAKbSypOv/8AboV5MAF06nXdMOxKUy2dHv5XHUqXLKuogiqVjGkU0chjmfWlFoOEhg== X-Received: by 2002:a05:6512:308a:b0:530:b773:b4ce with SMTP id 2adb3069b0e04-53438851b52mr12526602e87.33.1724781100395; Tue, 27 Aug 2024 10:51:40 -0700 (PDT) Received: from foxbook (bgu35.neoplus.adsl.tpnet.pl. [83.28.84.35]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5334ea296c6sm1852890e87.56.2024.08.27.10.51.39 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 27 Aug 2024 10:51:40 -0700 (PDT) Date: Tue, 27 Aug 2024 19:51:36 +0200 From: Michal Pecio To: Mathias Nyman Cc: linux-usb@vger.kernel.org Subject: [PATCH 5/9] usb: xhci: Simplify error_mid_td marking Message-ID: <20240827195136.45ffd31e@foxbook> In-Reply-To: <20240827194625.61be5733@foxbook> References: <20240827194625.61be5733@foxbook> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 It doesn't matter whether we set this flag or not on the final TRB, because the TD is about to be immediately "finished" anyway. Without these checks the code looks cleaner and easier to follow. Signed-off-by: Michal Pecio --- drivers/usb/host/xhci-ring.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index cc0420021683..c777cb897579 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2410,26 +2410,23 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, sum_trbs_for_length = true; fallthrough; case COMP_ISOCH_BUFFER_OVERRUN: frame->status = -EOVERFLOW; - if (ep_trb != td->last_trb) - td->error_mid_td = true; + td->error_mid_td = true; break; case COMP_MISSED_SERVICE_ERROR: frame->status = -EXDEV; sum_trbs_for_length = true; - if (ep_trb != td->last_trb) - td->error_mid_td = true; + td->error_mid_td = true; break; case COMP_INCOMPATIBLE_DEVICE_ERROR: case COMP_STALL_ERROR: frame->status = -EPROTO; break; case COMP_USB_TRANSACTION_ERROR: frame->status = -EPROTO; sum_trbs_for_length = true; - if (ep_trb != td->last_trb) - td->error_mid_td = true; + td->error_mid_td = true; break; case COMP_STOPPED: sum_trbs_for_length = true; break; From patchwork Tue Aug 27 17:53:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Pecio?= X-Patchwork-Id: 823015 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 06A2C1DDF5 for ; Tue, 27 Aug 2024 17:53:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724781208; cv=none; b=GrCiHhlBHcCmldQUQSK65gzXuaIwQATwcugBBEoPKJDiusEtMQ3w+7/QJ714d9GPk0hVXETrUcWjd33t9A76ExD+smDcp961SwZB5ieJKWBcSCvo5FIJoCwKZ0sRI1irwDbD1G7x2o5dcZGZ/9SpXiS5GkjMP0V9nKP9URG2A1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724781208; c=relaxed/simple; bh=XgYzwOdqMOEe7LnOM0EEk37+DaRG0Yqxa9VbacFZhuU=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hZCaC5uMm60xosKUeiTIjTNJhQQ9Vi/rNp54/Jl6tTKfdSg3cnDp9oMIxd7sezbiNaLgPh3m8temkHVFNnNbXH/VZTW/UIEXM/CP6aCADosRJSf5Xgq6YtfFWkOxunv4Yp5Q9BsG2g28njF9OJ1zjbIVEDK13w2wYpbSRyujJbk= 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=jJ6IYi6t; arc=none smtp.client-ip=209.85.167.51 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="jJ6IYi6t" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-534366c194fso5084037e87.0 for ; Tue, 27 Aug 2024 10:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724781205; x=1725386005; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=UdIU7HOFVa+70h5icTT2C6f8W08/j5KcmpOrK1A2oqg=; b=jJ6IYi6tEr5VI6iI2jaog+yPngEQURAiqtT2+1YaXnIXyJ2x7B7swFzgHsxMli2ir4 XhDrmjgDwMV4xW+n6wUPXI2ybrwufCFhx46GKPMtW/HFZHbFhCXb5ixrSK8bC65B26UV L2CEtM1aY6owFOhvnq7Paak7k2X+or7ObrrZEsWJgJPiRKeFHnJzsVTnducAPQD/+Kr4 BJzlENLqyk5EMpaz8FVf7B4VL36fV8mod8d5h6K6LCBlyK9TngNdc08p55c2RPUweNDL Wpgj1B9NTbGnvZxtZKBqgu1X6trFgCVTTHq53ucHsuIHdxzS7soUQh/LIHjjY8007MdC VSrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724781205; x=1725386005; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UdIU7HOFVa+70h5icTT2C6f8W08/j5KcmpOrK1A2oqg=; b=K/dJQ5Gki8yAn/bGaAU6koFs5hG+t4aOM2btns2pYISfblujQX4Wg3sGcNmQRE4/b4 EHr0zqersyWU0zyboGDrwd+sbptJhcBDtkW8bSlFNluXQIpBy8IAJdzTGoLVZBLIdk3f cfM2q0DY1oZR4LtfeSu4rDWC8R+hwjrdHkl8JkQoleFX2oqCONZyN2SbEovKQXmf/Vwg SmVoAQSuDSnzePZXQ8K4n5P4/6Q2SfnzIR0+gasNTEo6aiDKE9PU3MGUVNekDIbGUkLE tF/4VPjaOgJtu4sbMoORsoNWYcohIsW72cpq7AQ9u9VCeEW73igjeKkA844lUO6VW6sj AWiw== X-Gm-Message-State: AOJu0YxKwyTY/ER7KFG8dVkM+ky739gO/FFMuIEKidRcCjsIQcRVeklY eWOZIVysHWWwASIBXFYSminSYGEFYv2rV+do1FxM+YOm4QmCZYggbFs1hw== X-Google-Smtp-Source: AGHT+IFwXWsvEJuzu+IQ4FEu8GKWPBu0drcBfDxd7rzwfs1UF2yVa2M9PiwaZ7l3sw6TFEKwyHxFzw== X-Received: by 2002:a05:6512:3a93:b0:52c:d9a3:58af with SMTP id 2adb3069b0e04-5344e4fb00fmr2479878e87.49.1724781204905; Tue, 27 Aug 2024 10:53:24 -0700 (PDT) Received: from foxbook (bgu35.neoplus.adsl.tpnet.pl. [83.28.84.35]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5334ea2930asm1866168e87.52.2024.08.27.10.53.24 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 27 Aug 2024 10:53:24 -0700 (PDT) Date: Tue, 27 Aug 2024 19:53:22 +0200 From: Michal Pecio To: Mathias Nyman Cc: linux-usb@vger.kernel.org Subject: [PATCH 7/9] usb: xhci: Don't lie about trb_comp_code in handle_tx_event() Message-ID: <20240827195322.558bba67@foxbook> In-Reply-To: <20240827194625.61be5733@foxbook> References: <20240827194625.61be5733@foxbook> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This variable normally is an endian-corrected copy of the completion code received from hardware, except for one case where it is changed in order to trick some later code into setting some flag. This can be confusing when analyzing or debugging the function and the false completion code is sometimes written to dmesg too. For even more confusion, functions called by handle_tx_event() also have same-named variables but they initialize them from scratch from the hardware event, undoing this change within their scope. Use a dedicated local variable instead of such machinations. Signed-off-by: Michal Pecio --- drivers/usb/host/xhci-ring.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index e19c8a17b59c..58e6d0280e00 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2613,8 +2613,9 @@ static int handle_tx_event(struct xhci_hcd *xhci, union xhci_trb *ep_trb; int status = -EINPROGRESS; struct xhci_ep_ctx *ep_ctx; u32 trb_comp_code; + bool short_packet = false; slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); ep_index = TRB_TO_EP_ID(le32_to_cpu(event->flags)) - 1; trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); @@ -2645,14 +2646,15 @@ static int handle_tx_event(struct xhci_hcd *xhci, * transfer type */ case COMP_SUCCESS: if (EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)) != 0) { - trb_comp_code = COMP_SHORT_PACKET; + short_packet = true; xhci_dbg(xhci, "Successful completion on short TX for slot %u ep %u with last td short %d\n", slot_id, ep_index, ep_ring->last_td_was_short); } break; case COMP_SHORT_PACKET: + short_packet = true; break; /* Completion codes for endpoint stopped state */ case COMP_STOPPED: xhci_dbg(xhci, "Stopped on Transfer TRB for slot %u ep %u\n", @@ -2896,12 +2898,9 @@ static int handle_tx_event(struct xhci_hcd *xhci, trb_in_td(xhci, td, ep_trb_dma, true); return -ESHUTDOWN; } - if (trb_comp_code == COMP_SHORT_PACKET) - ep_ring->last_td_was_short = true; - else - ep_ring->last_td_was_short = false; + ep_ring->last_td_was_short = short_packet; ep_trb = &ep_seg->trbs[(ep_trb_dma - ep_seg->dma) / sizeof(*ep_trb)]; trace_xhci_handle_transfer(ep_ring, (struct xhci_generic_trb *) ep_trb); From patchwork Tue Aug 27 17:55:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Pecio?= X-Patchwork-Id: 823014 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 B0814126F1E for ; Tue, 27 Aug 2024 17:55:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724781307; cv=none; b=gK9p0wjR7h+vRyaqEQXmEyUUcCcHnfQrlmUfWKQYHVzWdncsXIzZp+9GaV8ugKHXUoaxfTFrNWvrYEFsecFMd43aJRZJWveADAX6ozcwskc7Munw9sj1xg2wDcPXG9RKPcf8d88giOwmERK8M3DcNYtNwy8gwIK+QUjKwxa6Kdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724781307; c=relaxed/simple; bh=Ek+97aUzfUHnBjrTrfC1PaNgK7RQVXC3JXKgv+Q/D7s=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fc4+yFntKalHazkdu97yeZosTMi5aFkzvUXWXbbuvmMrIgzOL8hJS4dOy3gW1FnshU3CAxwmwCHqNgriblUSw1OwFVQ8umEpa1s83IXpDph/4TsgNXnfF/MCgfDwgOAXOuYOCyQhXgUYxm8ooDn+CQklhuAnLYfZZcHBVJpSWt4= 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=jnUbIOmU; arc=none smtp.client-ip=209.85.208.174 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="jnUbIOmU" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2f409c87b07so68567491fa.0 for ; Tue, 27 Aug 2024 10:55:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724781304; x=1725386104; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=mkWuFvU5thx26Cu4RL0ja4mxDjiRu1s7MuOQ4orjyZ4=; b=jnUbIOmU42Am3fyVGrhXvBbdoGQtG3xxvNuDvRTyVnkW14XatkVpqXbqgiI+i6xQ8b fFh2Cqyw2nO3ImbEAKQJvUGnNoQJSF8j4hSB8VItDX9puaYBSH4JaXavglKyIhVXaGCc 9JdRiR0JFXwJG6l1kj/IdxrxBLRK/Lqx5Zc8o5NwG1+7I+k033hv+kDr5fldWr3PTvbE wqSRAfuTEihXAYwmpbflQ+rpO8tEeXmzmppXTZXVhXg0QPbie8Txa5tmdLNHW1GaAJmp H7La7e36qjGmFj8cH7AlOAAUM1JORi5tE1A6MUnU6lm8325sy8yOy2MWmkcrtav+t4BZ gvxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724781304; x=1725386104; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mkWuFvU5thx26Cu4RL0ja4mxDjiRu1s7MuOQ4orjyZ4=; b=VMjd9hMVHb1354reV8kjEgUEp3IMkoDP6h6E4wzi/Du6FcjH9cVBi50n61+GHr/YJ3 F43t/ot7dHjOQT+WEsww4xtRuaSNSJbLjyUDGDxeKXXRlsKeJjEuTRfvow14Cfc5QSnv enbIWgYN9XlMbe8QZFMxBTh+/y9aC858e98AqN15Fpe6lg2RagZKsZGU1J0bto2fmjC2 0o2FhbU6VgpjDX01mCOEoLyu7+pEb047KkVhCwL9Au7G0lvN3Hs367+UR1BeiWW0ZTOP yT6ap2mQoL6BXPMI4ZSAH2o2tnOic+I/3mNsq02+h+Sasouec3PMs9hllYS3+s9Ad8PO YKCw== X-Gm-Message-State: AOJu0YwMZ/k4qiztVe+87yl1GPKEldnMfEZKTkMRW5lHT6FDAa3hqMVv hS11y1xrpYnMKAJ9DV41+9vtMEpOwVjh09J69ZxV5IJ5/VRhcFXY X-Google-Smtp-Source: AGHT+IFOlMfdE3tB+/xMb6p8CaeBQoIxQTREVJBgr2OsWwS2xbABE0+SViUpCb7Bp/hyQOS0hFAe6A== X-Received: by 2002:a2e:811:0:b0:2f3:ed84:9e66 with SMTP id 38308e7fff4ca-2f4f48eeebemr83346771fa.13.1724781303358; Tue, 27 Aug 2024 10:55:03 -0700 (PDT) Received: from foxbook (bgu35.neoplus.adsl.tpnet.pl. [83.28.84.35]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2f4047e0082sm16357921fa.70.2024.08.27.10.55.02 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 27 Aug 2024 10:55:03 -0700 (PDT) Date: Tue, 27 Aug 2024 19:55:00 +0200 From: Michal Pecio To: Mathias Nyman Cc: linux-usb@vger.kernel.org Subject: [PATCH 9/9] usb: xhci: Clean up and rename bad stream event handler Message-ID: <20240827195500.37f88120@foxbook> In-Reply-To: <20240827194625.61be5733@foxbook> References: <20240827194625.61be5733@foxbook> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Function handle_transferless_tx_event() pretends that it sometimes deals with certain isochronous events, but it really doesn't. All isochronous events are handled in the big switch statement of handle_tx_event(). The above function is never called on isoch EPs because xhci_dma_to_transfer_ring() never returns NULL on those. The only conceivable way we could end up there is if an isoch EP is marked EP_HAS_STREAMS or its ring pointer is NULL, or we get an X-run event on a non-isoch EP. Either way it's a blatant bug, so don't "handle" this with a no-op, but print the default warning. The actual meaningful work done by this function is cleaning up after various problems on streams in questionable state, so give it a more specific name and add a bit of comment. Signed-off-by: Michal Pecio --- drivers/usb/host/xhci-ring.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 9d1af76955cd..aebbdbfd8da8 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2566,10 +2566,14 @@ 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, +/* + * Transfer events which don't point to a transfer TRB, see xhci 4.17.4 + * Specifically, this deals with cases where the EP has streams and the event + * TRB pointer is NULL or otherwise doesn't point into any known stream ring. + */ +static int handle_bad_stream_event(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, u32 trb_comp_code) { switch (trb_comp_code) { case COMP_STALL_ERROR: @@ -2581,10 +2585,8 @@ static int handle_transferless_tx_event(struct xhci_hcd *xhci, struct xhci_virt_ 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, "Transfer event %u for unknown stream ring slot %u ep %u\n", @@ -2637,9 +2639,9 @@ static int handle_tx_event(struct xhci_hcd *xhci, goto err_out; } if (!ep_ring) - return handle_transferless_tx_event(xhci, ep, trb_comp_code); + return handle_bad_stream_event(xhci, ep, trb_comp_code); /* Look for common error cases */ switch (trb_comp_code) { /* Skip codes that require special handling depending on