From patchwork Tue Sep 10 14:02:12 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: 13798561 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 C150118FC65 for ; Tue, 10 Sep 2024 14:02:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725976940; cv=none; b=OO/cwy6WpGmHhpT/oSsbHihNzVBIM9/g0rly+gndluZ0uegk5Uj+2eW3AMZBvgZlisD5g3b3Okw0WmDnEBSLCLrvzze+Y3DrNQ43cPFf0lolxstQYujpxjWJdIbPkj7Qpd0N90lt9LBEOZ/a9n3R+cT4AH4mqTOJRBrnb7+stQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725976940; c=relaxed/simple; bh=HfBHGql09L3sdKiyTGj89SBaxXlmFzGAo6CDWYtRK7c=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ebnNDe6bmlhyB/SW8oza7PNxXjE7NSKA25Y/QpyTRGvyXyLyQrmBkd1UY9oOQdCip+xI52RT3Ym0B/bJWnkFTFCr2WOx/g4Z1wDuQ3FLfQYEXhs1EMadUKFbiT0hwueaG7FJqxdpNUlJdexaw0UoTgl+TubGx0A+T7b5QnQLxCg= 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=gnPGJY7G; arc=none smtp.client-ip=209.85.208.52 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="gnPGJY7G" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5c40aea5c40so121561a12.0 for ; Tue, 10 Sep 2024 07:02:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725976937; x=1726581737; 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=H8Qy9Srqaw4c6WC5pjZpQgN15Z3GqcYv2pbBfM9zQ5Q=; b=gnPGJY7GOdQI6Ynbt9j0Pe0wZIVPBkH9oKGPzXi08uS5iRAo6K366vg31b0slzgz40 E0sCqFuDiFVoY7u7EMXPLW8LOu3uOIylnN7kvPfA02QQZAzUQX7TlatD26E9gNIJVxLe LogToM/ul9kH8zC9SLUWFBoBOD3+7zCOYi4z5bALtXk3ECK5CPvoasBp8RdFMTzqiRT3 vlS5UInCCYlgI+zthV5jMY4a6yM0y2GnSNgyPGTKt05wovcumzJ49n4Fg/Zj0lvlDSAs 2LnAM2AfgkGpEshtbXFHr+RBdeP/0Ynzqs8QYbmR5dU4pQuvhktYbNz0WTenTPooVo6m M1rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725976937; x=1726581737; 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=H8Qy9Srqaw4c6WC5pjZpQgN15Z3GqcYv2pbBfM9zQ5Q=; b=C2CPd7ZKgsbu42f+4aO8Z9ggsp8FH6z87qHUJPyKXBS7qj/nZHfuP76WEoYStXxMXn Ljp+EtGlztPmyYSYgUk++juT7z0RD6Djvl1Sb+BQpWRO0YLlEvYKl2vMXumv2b9MSOFM T1nu0+j2Hqhk8y4DaHRnhIB9OtzK31MUuV0tGi6GIetZZJrVZw+W7CxUk5//lcTV5vZb Zm+Oagih9oIU78+bAhxjx/76+TxhIwPrE2ZDVaJZpSb07xxRTjgX+DmmzFuN3p0JzkNQ 8ESWvAujMhKDbBmUcX/QqffsCMe4gQ9fY/4wIvfD4RpIUNpsBxHwAvDtJvbMaCCZKfX0 gLBw== X-Gm-Message-State: AOJu0Yx7cbX53+dj08VYnyUQcH3u55qqq6vKK8+pPHzPSQJPN/mCuB9u jy+fFGUoXe82gPnpYnmccutg4hZvh6zWjD/T8tsElbWZlFcW8jLB X-Google-Smtp-Source: AGHT+IEUy1C9ZCHPHuPz2vNMCiGz+u51JxK6wcvzorMc6DRBAXz5o+J1ejjV0dmieVNvoS88UBXxaQ== X-Received: by 2002:a05:6402:84b:b0:5c3:ce35:d165 with SMTP id 4fb4d7f45d1cf-5c4015e753dmr4148246a12.12.1725976936492; Tue, 10 Sep 2024 07:02:16 -0700 (PDT) Received: from foxbook (bgv123.neoplus.adsl.tpnet.pl. [83.28.85.123]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd8cc33sm4324359a12.87.2024.09.10.07.02.15 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 10 Sep 2024 07:02:16 -0700 (PDT) Date: Tue, 10 Sep 2024 16:02:12 +0200 From: Michal Pecio To: Mathias Nyman Cc: linux-usb@vger.kernel.org Subject: [PATCH 1/2] usb: xhci: Remove unused parameters of next_trb() Message-ID: <20240910160212.6098854b@foxbook> In-Reply-To: <20240910160114.50b77a91@foxbook> References: <20240910160114.50b77a91@foxbook> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function has two parameters which it doesn't use and hasn't ever used. One caller even puts NULL there, knowing it will work anyway. Signed-off-by: Michal Pecio --- drivers/usb/host/xhci-ring.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 4ea2c3e072a9..a3ffadf8e400 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -145,10 +145,8 @@ static void trb_to_noop(union xhci_trb *trb, u32 noop_type) * TRB is in a new segment. This does not skip over link TRBs, and it does not * effect the ring dequeue or enqueue pointers. */ -static void next_trb(struct xhci_hcd *xhci, - struct xhci_ring *ring, - struct xhci_segment **seg, - union xhci_trb **trb) +static void next_trb(struct xhci_segment **seg, + union xhci_trb **trb) { if (trb_is_link(*trb) || last_trb_on_seg(*seg, *trb)) { *seg = (*seg)->next; @@ -446,9 +444,9 @@ static int xhci_abort_cmd_ring(struct xhci_hcd *xhci, unsigned long flags) * avoiding corrupting the command ring pointer in case the command ring * is stopped by the time the upper dword is written. */ - next_trb(xhci, NULL, &new_seg, &new_deq); + next_trb(&new_seg, &new_deq); if (trb_is_link(new_deq)) - next_trb(xhci, NULL, &new_seg, &new_deq); + next_trb(&new_seg, &new_deq); crcr = xhci_trb_virt_to_dma(new_seg, new_deq); xhci_write_64(xhci, crcr | CMD_RING_ABORT, &xhci->op_regs->cmd_ring); @@ -678,7 +676,7 @@ static int xhci_move_dequeue_past_td(struct xhci_hcd *xhci, link_trb_toggles_cycle(new_deq)) new_cycle ^= 0x1; - next_trb(xhci, ep_ring, &new_seg, &new_deq); + next_trb(&new_seg, &new_deq); /* Search wrapped around, bail out */ if (new_deq == ep->ring->dequeue) { @@ -756,7 +754,7 @@ static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, if (trb == td->last_trb) break; - next_trb(xhci, ep_ring, &seg, &trb); + next_trb(&seg, &trb); } } @@ -2259,7 +2257,7 @@ static int sum_trb_lengths(struct xhci_hcd *xhci, struct xhci_ring *ring, union xhci_trb *trb = ring->dequeue; struct xhci_segment *seg = ring->deq_seg; - for (sum = 0; trb != stop_trb; next_trb(xhci, ring, &seg, &trb)) { + for (sum = 0; trb != stop_trb; next_trb(&seg, &trb)) { if (!trb_is_noop(trb) && !trb_is_link(trb)) sum += TRB_LEN(le32_to_cpu(trb->generic.field[2])); } From patchwork Tue Sep 10 14:03:01 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: 13798562 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (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 09D2728389 for ; Tue, 10 Sep 2024 14:03:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725976988; cv=none; b=IR+64L0gIaBA9lM6iefO81I9cZGNfMP8wabqwM27i6uY3maPjoN7xSCNLPRYIA6zXUInVbhzk+ua/gt/x1CHfZn18T4pTIZwY8EhqY58M5f8cCy4yG4hX/2TXM3uuGihY8BbGXkcn/7t0xl+fTYelX96mxcRVsuRZWbfe9xsH3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725976988; c=relaxed/simple; bh=OmviRgppHGhq8YSAjyzxPpHL3eBFIaV8TfAAO9+0pF8=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gzoq9TAoDocWJBhaWRLZTY127HFC8bObkryYLbHbQKgnOulNzlwNCqXgS2ILUstPbuGSwQ7b2SkuRgw4c6FTZgbGHr/CBxMGWwZ8+ffwru5QA3dMiSjEdzGhAE3a6EHkKy9vadeBDLqLFSAlri5P+ZxxGgI1D7hEC2CneOvFEqc= 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=CU8AvWRL; arc=none smtp.client-ip=209.85.218.49 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="CU8AvWRL" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a8ce5db8668so640549666b.1 for ; Tue, 10 Sep 2024 07:03:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725976985; x=1726581785; 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=n3sdldMH+y5OeaRs0sQiUc69EoWGH2zYBCHPZqq8+kI=; b=CU8AvWRLee07c6F34bKdhe2zcI6CIVOemareHwed+sBdzWZ3b+gvoISiXPRGDvB57j W+8bVOyOBqtaaiY9Jw7DJfiERjQqC60W7+qTCmfwaDAr9YSsZHpJadkZBXcTB2PAn0SC 9v517mqQm0r38J2sl0fjbkgAMc+G1hM5bhZb1P9DU4+5GPbwUBZ98/6fM9HtbWrpRCq+ 7UukNugDFWC15Gyc9eDeSoBodCeFHxIDzIAn4zpoozPj6p/weKrJ1EvO4s3c3gvYlcWG zrX4ipFpttHp13O72sRPl5sCfDfm+Bm9sh/ZPVEVXPa27Eks3svreU/f+vvW7YlbUvlw KqBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725976985; x=1726581785; 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=n3sdldMH+y5OeaRs0sQiUc69EoWGH2zYBCHPZqq8+kI=; b=Z2WtmHRq1lX3agGd0921OMi3mU9uJUyV0TAoFdbDuqlSHZxInyTZE1o9P85bhwOWi3 gW+rftfVzdvzZcttLnQO3flAKsKtWdaGP0tSPTk3xQB16CVATk2ob3LpLj46JyjiRJSS 08nRr7NNB9OF4BAi80orwqSeKV6wxFnfD2wVaUzK+0IqezVDM8aG+ebP804u1gZjf+MG kzMmhtnZBCvxVClf2629D6rJBTT7aV8n4YEza67SvecUd+3EJU2yDlsPKEIEvsT3XHHM VmPkYIXWNuN0IWv2TR/9WEfNzrjggTbn5Hbgn+1DxdyA5HeHUymVABe5AW55Vap5AXAa fk0w== X-Gm-Message-State: AOJu0Yyb+EM1biLGTTb+JJEm3s/sZZyHfSR/70qFslsM93eGkoDTWJAF 7/Kccuyl0fnFNl/UBhfB+erkBZMwAFDaMbIfEUFuyvKFQ3btV9JqoDP3Ew== X-Google-Smtp-Source: AGHT+IFNWXjyRw1VP45UIj39XSSjWlNGii5CicDZrgTUjgdjBls7VjCTUeeKrYpzkmY9fx1jGOwTqQ== X-Received: by 2002:a17:907:7f0b:b0:a8a:ead3:851c with SMTP id a640c23a62f3a-a8ffab18544mr88088166b.15.1725976985020; Tue, 10 Sep 2024 07:03:05 -0700 (PDT) Received: from foxbook (bgv123.neoplus.adsl.tpnet.pl. [83.28.85.123]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25d5dc8csm485817266b.206.2024.09.10.07.03.04 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 10 Sep 2024 07:03:04 -0700 (PDT) Date: Tue, 10 Sep 2024 16:03:01 +0200 From: Michal Pecio To: Mathias Nyman Cc: linux-usb@vger.kernel.org Subject: [PATCH 2/2] usb: xhci: Fix sum_trb_lengths() Message-ID: <20240910160301.340571ef@foxbook> In-Reply-To: <20240910160114.50b77a91@foxbook> References: <20240910160114.50b77a91@foxbook> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This function is supposed to sum the lengths of all transfer TRBs in a TD up to a point, but it starts summing at the current dequeue since it only ever gets called on the first pending TD. This won't work when there are cancelled TDs at the beginning of the ring. The function tries to exclude No-Ops from the count, but not all cancelled TDs are No-Op'ed - not those the HW stopped on. The absolutely obvious fix is to start counting at the TD's first TRB. And remove the now-useless 'ring' parameter, and 'xhci' too. Signed-off-by: Michal Pecio --- drivers/usb/host/xhci-ring.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index a3ffadf8e400..e5c5cf4d38c6 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2249,13 +2249,12 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, return xhci_td_cleanup(xhci, td, ep_ring, td->status); } -/* sum trb lengths from ring dequeue up to stop_trb, _excluding_ stop_trb */ -static int sum_trb_lengths(struct xhci_hcd *xhci, struct xhci_ring *ring, - union xhci_trb *stop_trb) +/* sum trb lengths from the first trb up to stop_trb, _excluding_ stop_trb */ +static u32 sum_trb_lengths(struct xhci_td *td, union xhci_trb *stop_trb) { u32 sum; - union xhci_trb *trb = ring->dequeue; - struct xhci_segment *seg = ring->deq_seg; + union xhci_trb *trb = td->first_trb; + struct xhci_segment *seg = td->start_seg; for (sum = 0; trb != stop_trb; next_trb(&seg, &trb)) { if (!trb_is_noop(trb) && !trb_is_link(trb)) @@ -2446,7 +2445,7 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, goto finish_td; if (sum_trbs_for_length) - frame->actual_length = sum_trb_lengths(xhci, ep->ring, ep_trb) + + frame->actual_length = sum_trb_lengths(td, ep_trb) + ep_trb_len - remaining; else frame->actual_length = requested; @@ -2529,7 +2528,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, goto finish_td; case COMP_STOPPED_LENGTH_INVALID: /* stopped on ep trb with invalid length, exclude it */ - td->urb->actual_length = sum_trb_lengths(xhci, ep_ring, ep_trb); + td->urb->actual_length = sum_trb_lengths(td, ep_trb); goto finish_td; case COMP_USB_TRANSACTION_ERROR: if (xhci->quirks & XHCI_NO_SOFT_RETRY || @@ -2550,7 +2549,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, td->urb->actual_length = requested - remaining; else td->urb->actual_length = - sum_trb_lengths(xhci, ep_ring, ep_trb) + + sum_trb_lengths(td, ep_trb) + ep_trb_len - remaining; finish_td: if (remaining > requested) {