From patchwork Wed Nov 6 10:14:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 841354 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9F1D1D5CFA for ; Wed, 6 Nov 2024 10:12:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887972; cv=none; b=j4WjYM6rCniyFnYRyf59gBHAg2kM+deuoPjHLoulJk4vxSPKBCc2G8ZhvX7K6OREXiwLCQW9kNp/FoKdyOV1v41jNnAfNLIa3yYPw3RSI0cnwQitooPK3jA6PnmlE72uCqkwtTsvkQutRVGcGo4jshJFh56U+mFyZkl/kroVGvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887972; c=relaxed/simple; bh=m8tRsBm2ShuUYbQQRRfFhFokYFuLuGqjyqMktQQXobo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Qg8A9G8b/2xSy4874ey1Nt8ADZW+lJRQWAmFgs9N2uvMSecabhFv2wS9y8pb0X5FjUM96gv6yeRhoR+ZIjBP193kZsd+1K4AckLi4L5AKnUPdJ/18yNvDdTxeYF6Dpp1gIOfCvtF7gIoDseIjFtkqqEoEbAkCfhO6RBp1Bks6ak= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ZtFs0T1K; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZtFs0T1K" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887971; x=1762423971; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m8tRsBm2ShuUYbQQRRfFhFokYFuLuGqjyqMktQQXobo=; b=ZtFs0T1KGGs+PtW/lZlB2xxtaOFKNfos/TcdqV6dxP/a2n6GdhT4G1lS cijFjMjGfdYm4RiSOfn6gZR+SVm/dR95W3mDVfU1A+IfTTAbY4Bsg7yTu GuVPu30UOw/NKbyKUTAKMeguXMb16/ZV4NF2DbhRAQ1eY+ybMYNU/+h7P PA0BT9QFLJAtUGTkgh1HiEGwywbA07+Zp33qkjGYL4w6jPtx/ApUpHO4r oFu7nqDzd7mz00W2vw09ZwUyyX+3Jnxz860XgtKR4HPuXPbb9P4TuIqdv QNQwCJ6K8VGMd8fZexm++T1FWAvV28gw3VzKvrSpWaVYPu5bmJdwSN3/A g==; X-CSE-ConnectionGUID: ehF+1xI8QAeyNAHBGXAD2g== X-CSE-MsgGUID: KOaax639R/iiMZBLn+CZBQ== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059375" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059375" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 02:12:50 -0800 X-CSE-ConnectionGUID: cfikA8H7QOGDGPDOFo6SZQ== X-CSE-MsgGUID: oACtqgEKS5+IlQJHsf9bGg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84812937" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:12:49 -0800 From: Mathias Nyman To: Cc: , Michal Pecio , Mathias Nyman Subject: [PATCH 03/33] usb: xhci: Fix sum_trb_lengths() Date: Wed, 6 Nov 2024 12:14:29 +0200 Message-Id: <20241106101459.775897-4-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241106101459.775897-1-mathias.nyman@linux.intel.com> References: <20241106101459.775897-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Michal Pecio 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 Signed-off-by: Mathias Nyman --- 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 36ccf0dac7fa..f1176c270c43 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2263,13 +2263,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)) @@ -2460,7 +2459,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; @@ -2540,7 +2539,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 || @@ -2561,7 +2560,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) {