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: 13779920 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:48:54 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: 13779921 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.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 B3AD0126F1E for ; Tue, 27 Aug 2024 17:48:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724780941; cv=none; b=hh+mhpU2dxFazFklBX+I9SlP1PluL2G5oo5vCjF3K+FLsQyfVJfklaIe9eNfaCOpRb+htajhbIyzvnXCzncYonKVoXTlb//Nwbcwq6DJe4cZUmUsMhBkS3BEfWUsYFh/+41DOUSyXI1qFthCl99bAuFbNJG49eo6+9FXu2YiitI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724780941; c=relaxed/simple; bh=x3ki8z+PVqilgsQNpCC4AANZUy4kOiNPhlf3z8v+zMM=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hgECx8vob22pLmEj2XGjMRTihDE0ou8M1JtqWZg/CCVuRCtsU8f31K6i2xoeh9fqak1/7Ia2hYhzOpS0+aOxDpkoQmVvQn4n7MbAcpXzMIrH1mDh2yOiSoIrzXg3J5DDhX1K5D/OU0ezx+QkRvFNKUsNTKam1xtR+v+RQiYi8eU= 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=hBRrB0Vk; arc=none smtp.client-ip=209.85.167.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="hBRrB0Vk" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5334e41c30bso6305004e87.0 for ; Tue, 27 Aug 2024 10:48:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724780938; x=1725385738; 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=YjpxxAo35dHgSW7LwqUAtoBAZUT7VQh/LN/LjjD0fQw=; b=hBRrB0Vkt0jOh4Ugyv3egLh78X62bnyFghezN1DyqbZLJDBJZJKVSivN9mZjiX0bXu JE/4Qoh26pAPrNCfcamtwv1i7smwoMI1vec17oYjDNE4rsoNSSn44OrZY4w8+WQKBSwc WlU2OfwwCSKlTOdXjprborI6V9b5JQohsYUaYA9JGe5zOUP1Jnz0+fgs/7f1whQVXqKA KRECQpoatSkgLv2FrBuheSngrM5dL5JTVY/kxOxFlyC0m44tidD7gzAMy5o8ldbR4rnT gc4VCXztQFX/mPWeT9HNWiIAqRoT0OmCdxe7z9CHwRvsvsrPfSRwAi7rHWoUCVaZRLEW +2BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724780938; x=1725385738; 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=YjpxxAo35dHgSW7LwqUAtoBAZUT7VQh/LN/LjjD0fQw=; b=AzQN1f66fPOHrL5ucDiwTkoRmwHBN6YJgxTjrFN8wRVb82XXraoKLdDrzMiRJUNljU bqRBksN4sZ8JwA26qlBkyIBY1Lj2rzy04Lxs99Fnr/jSsIuyHnIS51/UcM/m1m3WOcvz QUkAjsJ35QBLDo5jewBXAuL6iVsqoV7As792dspTYWgaikmVWVjxSeleXC02tF4Tf3pD H15IToh65UOwQgGdtqKH4DDhJS+NCEasGeJYKJ+I8Q5W4ixnc1WbS1b0m9ENX7MJ4NIa AqR7LmGiPrHKZpRTsPhNPG0wJ1YPGlVJKOnJrKild/sQb7Q2Y42YuK7TduhSChnrhCnz ExQw== X-Gm-Message-State: AOJu0YxFkCKfT6GBwjKXpd0+FY/q9RsoKAIWvWqEcjAhspzNeh596sG0 A7UKRte85eTbqwJG8a0X1KFA9qNQBzr5iyogKpXVGXFSkixE39I+ X-Google-Smtp-Source: AGHT+IHsOgwirv9eiiFT3rlYWLZ6MEFmhaYcOnecePmCwHkwkoC6owALE9NJZPDq6HhbCz1l5Yrfbg== X-Received: by 2002:a05:6512:3c97:b0:530:e1f1:8dc9 with SMTP id 2adb3069b0e04-534387be5e5mr8898818e87.46.1724780937430; Tue, 27 Aug 2024 10:48:57 -0700 (PDT) Received: from foxbook (bgu35.neoplus.adsl.tpnet.pl. [83.28.84.35]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5334ea592a8sm1926757e87.137.2024.08.27.10.48.56 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 27 Aug 2024 10:48:57 -0700 (PDT) Date: Tue, 27 Aug 2024 19:48:54 +0200 From: Michal Pecio To: Mathias Nyman Cc: linux-usb@vger.kernel.org Subject: [PATCH 2/9] usb: xhci: Fix handling errors mid TD followed by other errors Message-ID: <20240827194854.089ddf0d@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 Some host controllers fail to produce the final completion event on an isochronous TD which experienced an error mid TD. We deal with it by flagging such TDs and checking if the next event points at the flagged TD or at the next one, and completing the flagged TD if the latter. This is not enough, because the next TD may be missed by the xHC. And we need to do the check early, or errors on the next TD may confuse us. If the next TD experiences a Missed Service Error, we will set the skip flag on the endpoint and then attempt skipping TDs when yet another event arrives. In such scenario, we ought to report the 'erorr mid TD' transfer as such rather than skip it. We also need to detect that it is there and in need of handling, despite never receiving a completion of the subsequent TD. For this purpose, add a check for ep->skip flag and move the whole error handling logic before the skipping logic. Note that when we see both td->error_mid_td and ep->skip, they surely must have been set in this order. Otherwise, skip flag would have been cleared when the error mid TD was being handled. Another problem case are Stopped Endpoint events. If we see one after an error mid TD, we naively assume that it's a Forced Stopped Event because it doesn't match the pending TD, even though it might actually be a Stopped Event on the next TD, which we fail to recognize. This is fixed similarly, by reordering erorr handling before FSE handling. Lastly, error mid TD handling is reordered with last_td_was_short. This is harmless, because these two cases are mutually exclusive - only one can happen in any given execution of handle_tx_event(). And if we are here, add a FIXME comment on the last_td_was_short thing because it's a wholly broken idea. Tested on the NEC host and a USB camera with flaky cable. Dynamic debug confirmed that Transaction Errors are sometimes seen, sometimes mid-TD, sometimes followed by Missed Service. In such cases, they were finished properly before skipping began. Signed-off-by: Michal Pecio --- drivers/usb/host/xhci-ring.c | 78 ++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index e960609dcf51..401c34ff2260 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2798,8 +2798,39 @@ static int handle_tx_event(struct xhci_hcd *xhci, /* Is this a TRB in the currently executing TD? */ ep_seg = trb_in_td(xhci, td, ep_trb_dma, false); + if (!ep_seg) { + /* + * xhci 4.10.2 states isoc endpoints should continue + * processing the next TD if there was an error mid TD. + * So host like NEC don't generate an event for the last + * isoc TRB even if the IOC flag is set. + * xhci 4.9.1 states that if there are errors in mult-TRB + * TDs xHC should generate an error for that TRB, and if xHC + * proceeds to the next TD it should genete an event for + * any TRB with IOC flag on the way. Other host follow this. + * So this event might be for the next TD. + */ + if (td->error_mid_td && + !list_is_last(&td->td_list, &ep_ring->td_list)) { + struct xhci_td *td_next = list_next_entry(td, td_list); + + /* Is this a TRB in the next queued TD? */ + /* *OR* did we miss some TDs meanwhile? */ + ep_seg = trb_in_td(xhci, td_next, ep_trb_dma, false); + if (ep_seg || ep->skip) { + /* give back previous TD, start handling new */ + xhci_dbg(xhci, "Missing TD completion event after mid TD error\n"); + ep_ring->dequeue = td->last_trb; + ep_ring->deq_seg = td->last_trb_seg; + inc_deq(xhci, ep_ring); + xhci_td_cleanup(xhci, td, ep_ring, td->status); + td = td_next; + } + } + } + if (!ep_seg) { if (ep->skip && usb_endpoint_xfer_isoc(&td->urb->ep->desc)) { skip_isoc_td(xhci, td, ep, status); @@ -2820,53 +2851,24 @@ static int handle_tx_event(struct xhci_hcd *xhci, /* * 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; } - /* - * xhci 4.10.2 states isoc endpoints should continue - * processing the next TD if there was an error mid TD. - * So host like NEC don't generate an event for the last - * isoc TRB even if the IOC flag is set. - * xhci 4.9.1 states that if there are errors in mult-TRB - * TDs xHC should generate an error for that TRB, and if xHC - * proceeds to the next TD it should genete an event for - * any TRB with IOC flag on the way. Other host follow this. - * So this event might be for the next TD. - */ - if (td->error_mid_td && - !list_is_last(&td->td_list, &ep_ring->td_list)) { - struct xhci_td *td_next = list_next_entry(td, td_list); - - ep_seg = trb_in_td(xhci, td_next, ep_trb_dma, false); - if (ep_seg) { - /* give back previous TD, start handling new */ - xhci_dbg(xhci, "Missing TD completion event after mid TD error\n"); - ep_ring->dequeue = td->last_trb; - ep_ring->deq_seg = td->last_trb_seg; - inc_deq(xhci, ep_ring); - xhci_td_cleanup(xhci, td, ep_ring, td->status); - td = td_next; - } - } - - if (!ep_seg) { - /* 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; - } + /* 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) { xhci_dbg(xhci, 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: 13779922 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:50:53 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: 13779923 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 4F2521CDA3C for ; Tue, 27 Aug 2024 17:50:59 +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=1724781061; cv=none; b=WlZzBdt30Dc0KhU/P4E8SPjv1Bn3/EcGgZkOeU++1O6oYf400AxemqMxZbWSkryrv854hRg8E3mnN2XQVak8Ye9L8FZMA5W9Hp7eEUyZMTbGWXRa7k7dydwCKpFtJa1BAK2TliKowkhXK2qMWY8JmwJv8CLBUfL3qINuJGl2Sqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724781061; c=relaxed/simple; bh=YCK56ta0CfLsO43jOU410kxlnlorAXMODs4yZCTF/vU=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GJBn3o3qXKZcjap/kX9ggyEwExZMXwj5Rldk5BMz2C2wKfkm2FThFeAFD9nAoCS1deHvjAwfCCX038WmBKo+fsS9ZfDdSh98I+7nPkVNb9SevvaosDyN82tQH8fn7q5rqEyEG/fkxQVJsMczzaBjnqaS4ktlRP7dfgBmigGRAKU= 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=EaA7cE3s; 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="EaA7cE3s" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-5334c4d6829so8110032e87.2 for ; Tue, 27 Aug 2024 10:50:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724781057; x=1725385857; 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=C0GlT7wq+kWJRxuNuJdkkcFinJAX6r3HFmUAqyEvvGk=; b=EaA7cE3sHonsehJyug3PMtsxnRANg+5crB+IsksH1fQ4X20fWRCJRISo5oPDWr84ms 1I6hsB72/nmqE/V6JVudtCuMySxFZd+5QCG0ZVTeR2CLZ4UfAPK9tl+m8KkOMPfFIyfz 9YOsfgtppEztlMuOxqtFhagi8OjLU0li6wAtRMmSUjwtr0VX7sd9xnugl27y4+KLQS6m 1ATk3e4pFoj2IKEZC00PkOw4uE8N580jDfhPgT/F1s3wcQTq2mvmb0dh5PLR0NVSVPqp DLsquRR5xT22jJrwNPTsz0ttfDEBLgkUQbeAL5Anq+8sxciSF43MJ8lTNyvXlFSiUHLb bA8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724781057; x=1725385857; 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=C0GlT7wq+kWJRxuNuJdkkcFinJAX6r3HFmUAqyEvvGk=; b=ukxPGuooGLmBEYzhGPqWxSqZU3X23h2hNicxjKEYMnpnh/FmCPGYRiWAh6sYeCN+gF Xe7/mi6jh7euXI0FN13/ZwOx+ouVJWbFfIH/MFQ9TrCzIxVb1q/VS3wm+7jtL/0w2G21 kWbO+3ai9hmCh7ycb0WMkhUPHM+sEgfx/6aX85YaPbNbCghpH1D08D8+diOeCR1+RYTT /086d6rpw+epPx6mSwqcUf+1omvXrlLf7gp2OchVh6jlpKZf2jqIxL35RYyqZdsig5WV SfISZFxpBndS19JJABQ7xd0ETOvHC2SA/FbkcApNPHuvPQU+0w1hcWMY2bRs/l3nQRy7 EM1w== X-Gm-Message-State: AOJu0YwIEdZUTy5pJJeAsnsUmFfpTELhrAzBbOoL0pMtqe8zgZzQ1TNt dROH4DXpb8p8s/pwJYpNiwn7eqiTek9aDN9rfEfNtOZmhR2PjmCe X-Google-Smtp-Source: AGHT+IFueuyJn289uVgeqDWxf+R8nBN6YkFa+hzK0meAFSKJCvhPmx6JuXB9DqMNTwRNOUMVVetFHQ== X-Received: by 2002:a05:6512:114e:b0:52e:fd75:f060 with SMTP id 2adb3069b0e04-5344e500ad8mr1986797e87.61.1724781057018; Tue, 27 Aug 2024 10:50:57 -0700 (PDT) Received: from foxbook (bgu35.neoplus.adsl.tpnet.pl. [83.28.84.35]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5343696592bsm1611650e87.128.2024.08.27.10.50.56 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 27 Aug 2024 10:50:56 -0700 (PDT) Date: Tue, 27 Aug 2024 19:50:53 +0200 From: Michal Pecio To: Mathias Nyman Cc: linux-usb@vger.kernel.org Subject: [PATCH 4/9] usb: xhci: Expedite processing missed isoch TDs on modern HCs Message-ID: <20240827195053.185f5a91@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 spec rev. 1.0 allowed the TRB pointer of Missed Service events to be NULL. In such case we have no idea which queued TD were missed and which are still waiting for execution (and the spec forbids us guessing based on frame numbers), so all we can do is set a flag on the endpoint and wait for a new event with a valid dequeue pointer. But hosts are also allowed to give us pointer to the last missed TRB and this became mandatory in spec rev. 1.1 and later. Use this pointer, if available, to immediately skip all missed TDs. This may be particularly helpful for applications which queue very few URBs/TDs for the sake of lowest possible latency. It also saves the day if the next event is an underrun/overrun and we will not get a valid dequeue pointer with it. If we then saw the skip flag, we would have no way of knowing how many TDs were missed and how many were queued after the host encountered ring underrun. Handle Missed Service Error events as "error mid TD", if applicable, because rev. 1.0 spec excplicitly says so in notes to 4.10.3.2. The notes are no longer present in later revs, but rules of 4.9.1 should apply universally. Note that handle_tx_event() can cope with a host reporting MSE on an early TRB of a TD and then failing to signal the final TRB. However, in such (hopefully rare) case latency is not improved by this patch. Tested on ASMedia ASM3142. This USB 3.1 host gives valid pointers in Missed Service events and the skipping loop works until it finds the last missed TRB indicated by the host. Then the skip flag is cleared and the TRB passed to process_isoc_td() like any other. Tested on NEC and VIA VL805. These USB 3.0 hosts give NULL pointers so the event handler sets the skip flag and returns, as expected. Change inspired by a recent discussion about realtime USB audio. Link: https://lore.kernel.org/linux-usb/76e1a191-020d-4a76-97f6-237f9bd0ede0@gmx.net/T/ Signed-off-by: Michal Pecio --- drivers/usb/host/xhci-ring.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index e65cc80cb285..cc0420021683 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2413,8 +2413,14 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, frame->status = -EOVERFLOW; if (ep_trb != td->last_trb) 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; + break; case COMP_INCOMPATIBLE_DEVICE_ERROR: case COMP_STALL_ERROR: frame->status = -EPROTO; break; @@ -2730,13 +2736,17 @@ static int handle_tx_event(struct xhci_hcd *xhci, * When encounter missed service error, one or more isoc tds * may be missed by xHC. * Set skip flag of the ep_ring; Complete the missed tds as * short transfer when process the ep_ring next time. + * If the xHC tells us the last missed TRB (ep_trb_dma != NULL) + * perform the skipping right away. */ ep->skip = true; xhci_dbg(xhci, - "Miss service interval error for slot %u ep %u, set skip flag\n", - slot_id, ep_index); + "Miss service interval error for slot %u ep %u, set skip flag, go ahead %d\n", + slot_id, ep_index, !!ep_trb_dma); + if (ep_trb_dma) + break; return 0; case COMP_NO_PING_RESPONSE_ERROR: ep->skip = true; xhci_dbg(xhci, 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: 13779924 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:52:24 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: 13779925 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 644ED64A for ; Tue, 27 Aug 2024 17:52:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724781152; cv=none; b=j4AAbgtZlBvJR+6mFZTjlPN/lYBs2MUTIMxwViHnSOkOHNnoq+gc0gBBQfE1gPkRzHVa0RShTd6lquhspXOS0yPU2StoO1HBWwv+rED8BqywVobA8YJEOJkbcws4zaxxYq2mCYrla4GDHF4MQJLEPOPLZL66LC08unnrl8Cfcso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724781152; c=relaxed/simple; bh=kf8HkXCqaw+F1v+PLnYSfXw0dV2Pbt7C8s9HdtNFX58=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mIl8iFip1mxq4C0CviLtdAgNvhOD/RwmwFYEXmapSoZs1dfeKegNgACdJPM+UJQIAyNcvmvyrR1ha/k10tt7/xT1Q5GHCdZyiIo2Nt2nRo126dFkL0ukbuFQV2JNt4nAcShCEWYZehHELHU94A2JECLrjAH7jRhLT86QjjeMAXg= 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=i6RDgSXX; arc=none smtp.client-ip=209.85.167.43 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="i6RDgSXX" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-5334fdabefbso5048451e87.1 for ; Tue, 27 Aug 2024 10:52:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724781148; x=1725385948; 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=BrBzCKt4N9BQ5EKcvX9GvFSkuSAxcwLEZXKVeR6c198=; b=i6RDgSXXU2N4vI1pKMtDj3oQ8WrAhX12k7OK7fP5dh/eNoe7MXQWXUsaSdygpywgev A5x1C9YVRpPQDW2jgxVak0abVdjlo0vrfHs3MWkcaPj0w8yvve1w3MS+QtYzJ1ENCNBO j+XPCPS6vRiru0RSQUvm8ihlrsu3CGP3wcta/Uu8AgDDZnATRWH+vWZTF3AHBMYsy0zt Z417OVEK+tIJZdk0ziwNAu0fJLF5j2YleEDRfTsf1RnjJ9MT5U7RhsU9wCaaLKZ5zwIq zdrOcCjdiYpxz+/HlaUFtIGPYrfdyWdDB9Xwog8T3uSY58BGDrqOJJCGcUVLPaetMMlF OvCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724781149; x=1725385949; 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=BrBzCKt4N9BQ5EKcvX9GvFSkuSAxcwLEZXKVeR6c198=; b=I4fs3U1CSx3Ek7KEbL7z5CG+4t5tbVzPJNWJRpbdEekp06/otgrnuFBQMyMRrl5+n1 VWX4Zg9X6NePHTK4JkPfFoDTNohNigwwzK8vKMd/xG8FVmrB/Pp/y2UNi7aOAG6im4tq lyM+egL9Uj02Epi1m4qxQSe9bNrFdwz5z1N+bHOh7mZ52kVr/C+W9oNJ8ELsoKQY7Df4 EEzN8niTWOcdTpBeodwulgF3zy/WEnd1axUNCdK69KwuyA93GS68C98Y7NBIjReRzCpB UWGlHikMLH/TmqopFOEmPNS+Ycyrcn+T8vgAWzBgc9rByCrDc9/AsmJAXaPhVncdaj24 /KxA== X-Gm-Message-State: AOJu0YwFC9gscexPscKSyU8oGJm+xTtstjgqhRwrbslrkYtiq5q/AalU N6QFFAp+Vjw6gqSmeEXikzI//HQqL8awUnr7hFz1xzaLN+VK32lj X-Google-Smtp-Source: AGHT+IGqJrejqmKAVXV5UIZP79vEwUlc8PyuNMtqBwpcqS79p0T0WdvlbqvS7+gI33g3lShHZrIe0g== X-Received: by 2002:a05:6512:398e:b0:52f:cf2d:a1a0 with SMTP id 2adb3069b0e04-53455235773mr886e87.26.1724781148207; Tue, 27 Aug 2024 10:52:28 -0700 (PDT) Received: from foxbook (bgu35.neoplus.adsl.tpnet.pl. [83.28.84.35]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5334ea5e4aasm1860712e87.240.2024.08.27.10.52.27 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 27 Aug 2024 10:52:27 -0700 (PDT) Date: Tue, 27 Aug 2024 19:52:24 +0200 From: Michal Pecio To: Mathias Nyman Cc: linux-usb@vger.kernel.org Subject: [PATCH 6/9] usb: xhci: Sanity check "spurious success" handling Message-ID: <20240827195224.02c32551@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's not spurious, it's expected, it's required by the spec since its final 1.0 revision 14 years ago, and it's handled incorrectly here. But until somebody puts some effort to get it all right, try at least not to do obviously wrong things here. This code claims to handle "spurious" Success events, but in reality it is ready and willing to silently swallow any kind of event, on most host controllers these days, after any short transfer. It got in my way while debugging genuinely incorrect events from the xHC, which this code thought were meant for it, because it has no way of knowing better, because it's utterly broken. Limit it at least to only accept Success and Short Packet completions so that rightful warnings will be printed in other cases. So far I found no instances of this change exposing previously hidden errors, besides the aforementioned case of a buggy xHC. The buggy xHC completely fails to acknowledge some TDs in any way. It proceeeds to the next TD, whose event then doesn't match the current TD, so if the prior TD got a short packet, the "spurious" code swallows the event. Signed-off-by: Michal Pecio --- drivers/usb/host/xhci-ring.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index c777cb897579..e19c8a17b59c 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2785,9 +2785,10 @@ static int handle_tx_event(struct xhci_hcd *xhci, */ if (!(trb_comp_code == COMP_STOPPED || trb_comp_code == COMP_STOPPED_LENGTH_INVALID || - ep_ring->last_td_was_short)) { + (trb_comp_code == COMP_SUCCESS && ep_ring->last_td_was_short) || + (trb_comp_code == COMP_SHORT_PACKET && ep_ring->last_td_was_short))) { xhci_warn(xhci, "WARN Event TRB for slot %u ep %d with no TDs queued?\n", slot_id, ep_index); } if (ep->skip) { @@ -2878,9 +2879,11 @@ static int handle_tx_event(struct xhci_hcd *xhci, * 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 && + (trb_comp_code == COMP_SUCCESS || + trb_comp_code == COMP_SHORT_PACKET)) { ep_ring->last_td_was_short = false; return 0; } 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: 13779926 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:54:14 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: 13779941 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 538BB1CFEBC for ; Tue, 27 Aug 2024 17:54:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724781260; cv=none; b=Flsn4+Eby1YGDHQI2LCBRlYXvfVCMouWa9W/kdpqdLurb82ocqJKoO+pMEYDX6zxRo49bgwrWDzoigryX6Izvw04PXT4IxoenAO3a971t+h0IUPoO+21bXHtcq0Btexvmv9vqHHY7aQx1HDhzxaNP6yhRN5vX/4GceC2aU3tCEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724781260; c=relaxed/simple; bh=lgA9DGxoPPKLn64ZG/9dGB7kFf1Wi67NHRBaC0D+st4=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uC7EV3mTYqcvNT7n/gYrgT8ZrfmZN7dQSNIPwLUAXQe3VI6IT8bBnztQ3mRXaLoTlYRpqdBcgV5zU2d6gju27ZVUAduP5ouRZUZ36pI/YYX2DFgsUbp34CnaXFyxqSD/xDv4BF0h/EtGdCq9+/cwILVdbotoefuul7AN4mrClfo= 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=bNrfi0Ut; arc=none smtp.client-ip=209.85.167.54 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="bNrfi0Ut" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-533521cd1c3so6682893e87.1 for ; Tue, 27 Aug 2024 10:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724781257; x=1725386057; 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=8FJnR96/FCs/s6YIt57QA4Eo8HE54w5Rgc1hfOw05tc=; b=bNrfi0Ut9uh6nGpX800eNcxNtBqM6I9n+r8TqTeDBeuG4YW74bKiA5QV6surOzZM0z g6GYP5CpMRcABZcw/bZPavAOEnyJXPMUEYURis7+JBxd/ihMA/ndXfDEVCUFiJ43R2Mm q7086X2jx6FnXosQ4C7qDhuyXBbHHc9h82j8A2CrFNeNKomLAkVyAhlHa+9eiL7wMR// oTk53rkfz3XW6cIYFavu0eQsHtrLXkSmfaYgImMI67kvniNWHlXpBcB54gbxLFXpAphn eA3eLVSmrZLB8mlkujd+UVvrGCpnIfKkhqY5xoEAaOatK3nQ/IDdb+tZWx94H3+crUyD Zs5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724781257; x=1725386057; 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=8FJnR96/FCs/s6YIt57QA4Eo8HE54w5Rgc1hfOw05tc=; b=XRJ6sNECKkUAcioC5aHGLaQ9HflT0fPhwAnVfncLEYflVrM6JbBv9D13b+oahlyI8W vNkL+d9FdifYsjDk2U+emeKg1LiG9W813cEGROAEsXoBlPBoCqCS5rkDzUfLaO5DHjDU EY9UkZLLKAt0HVwM0LQXT0pUMmgDviBg1n0IS0u7vUodTA4Qw24qCB7ulhlnjk41nfcu Wb22ZY3kx6ytyewg7bgg9+250xIoFHYOYbA/dPG0qCwZvVQLSc9PESD+FzjfWuU8Nohb 5whe094eyrWDM5qUrJFeJTb69pcoDniJr2LSl6WoMansZ+ooOHZqTVu3b6i3hz5kCAIS sPag== X-Gm-Message-State: AOJu0Yy3WC832LTqWgio9fbbhvjkSXXBfHkx8R3PDbFNkiZi6tu6cbUu VBb8aWZZMGcV5xWDuqSGnAUj3M0syqhxPkwh7RNaWxSwtsrWDeVn X-Google-Smtp-Source: AGHT+IF4gSUQCSpa8ixavG799n8aWyEjxSqai6C2JijMvc2iVifKk75LSM5kM0Lpe1ErPwD3FmpHBA== X-Received: by 2002:a05:6512:220f:b0:533:4676:c225 with SMTP id 2adb3069b0e04-5343887e15amr12849577e87.41.1724781257126; Tue, 27 Aug 2024 10:54:17 -0700 (PDT) Received: from foxbook (bgu35.neoplus.adsl.tpnet.pl. [83.28.84.35]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5334ea3630bsm1861104e87.68.2024.08.27.10.54.16 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 27 Aug 2024 10:54:16 -0700 (PDT) Date: Tue, 27 Aug 2024 19:54:14 +0200 From: Michal Pecio To: Mathias Nyman Cc: linux-usb@vger.kernel.org Subject: [PATCH 8/9] usb: xhci: Print completion code in the empty ring warning Message-ID: <20240827195414.057e09dd@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 gives a better picture of what was happening when the ring was found unexpectedly empty. Signed-off-by: Michal Pecio --- drivers/usb/host/xhci-ring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 58e6d0280e00..9d1af76955cd 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2789,10 +2789,10 @@ static int handle_tx_event(struct xhci_hcd *xhci, if (!(trb_comp_code == COMP_STOPPED || trb_comp_code == COMP_STOPPED_LENGTH_INVALID || (trb_comp_code == COMP_SUCCESS && ep_ring->last_td_was_short) || (trb_comp_code == COMP_SHORT_PACKET && ep_ring->last_td_was_short))) { - xhci_warn(xhci, "WARN Event TRB for slot %u ep %d with no TDs queued?\n", - slot_id, ep_index); + xhci_warn(xhci, "WARN Event TRB for slot %u ep %d comp_code %d with no TDs queued?\n", + slot_id, ep_index, trb_comp_code); } if (ep->skip) { ep->skip = false; xhci_dbg(xhci, "td_list is empty while skip flag set. Clear skip flag for slot %u ep %u.\n", 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: 13779942 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