From patchwork Wed Jun 26 12:48:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 807782 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 8E9E9181D0E for ; Wed, 26 Jun 2024 12:46:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406006; cv=none; b=F/0MM2y34hCcY6KI4druYUbv95a2NrDzEJfJL2eRcmOdN8Pg/4D8De0yCQ90nWj7J7Ed5pk+/KR9lK/HI/mQWPb2ljJba9dyNt0MKj/FZR3n/8GF4kAn7rPy50GrKKLUT1EjAvN/UI19pOcsLl0tTkCBYI/a4JfsYSFhtEpRzKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406006; c=relaxed/simple; bh=u39ZLQFVHadxLT8eot8yRJbsUgjzR6QW3AwD4UZL8RE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ja6vWwNJE0skKxMjLmbHjNqTnHGhspuP9KTO8gUKo9/gxvq6CJlPcClItsMnA6W/XZtOL5a0dgS0zZOWLUEo3mdV+k8kl3xiFEsX9HAOTkG5twIc09I3Nxc2YPIZYjo3lXUZuAkydPgAi69xbrkJhNsbWe561NnHzZh62cutLh8= 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=mAjfPhMo; arc=none smtp.client-ip=192.198.163.17 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="mAjfPhMo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719406005; x=1750942005; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=u39ZLQFVHadxLT8eot8yRJbsUgjzR6QW3AwD4UZL8RE=; b=mAjfPhMoqXrfm4MnPepIzejkw1ihuORqOpTICf8ltawML8xUDbkYaeXt tEVjpU0U+QllFETqRli0W37gbzWY1gr1LxuZSyK8byPJ14aQAcOPkY9Qp P4kC8x0t3Qlum/5u+AmYrQ4cK1rQubzTeKV5sX5dcP0TOSNJ7B0bwnlxk cvdHu2TCH9xAJw81mvjGGUA4+RPvgt4HVcVxq3DX0FATfxYwqa0Y8du+r TMOYOQYUCxMsPvtMAO0bIXS2Fdk8+bElvpbg9+ZbFu1g9Ql2TTMbZ8t3k c9XESAQ5ea9cnCjhDJ3/AFs4DOtdjUaR6mACKz5c1SZGkakUTuEH4scK+ w==; X-CSE-ConnectionGUID: MvWBPavqSpebl8JxquoAbA== X-CSE-MsgGUID: EoM1KkZoT7WclV0OT9Szrg== X-IronPort-AV: E=McAfee;i="6700,10204,11114"; a="16353363" X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="16353363" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2024 05:46:44 -0700 X-CSE-ConnectionGUID: BSKhjCujQqS6lU/myTgofw== X-CSE-MsgGUID: ArLqbhkcT/m+DK3qe/fmiA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="48442560" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa005.fm.intel.com with ESMTP; 26 Jun 2024 05:46:42 -0700 From: Mathias Nyman To: Cc: , niklas.neronin@linux.intel.com, Hector Martin , Mathias Nyman Subject: [PATCH 01/21] xhci: Remove dead code in xhci_move_dequeue_past_td() Date: Wed, 26 Jun 2024 15:48:15 +0300 Message-Id: <20240626124835.1023046-2-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240626124835.1023046-1-mathias.nyman@linux.intel.com> References: <20240626124835.1023046-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: Hector Martin This codepath is trivially dead, since the function is never called with a non-NULL td (the only callsite is immediately preceded by a NULL guard). [remove unused label 'deq_found' -Mathias] Signed-off-by: Hector Martin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index fd0cde3d1569..ffb3ebb72eaa 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -654,25 +654,6 @@ static int xhci_move_dequeue_past_td(struct xhci_hcd *xhci, stream_id); return -ENODEV; } - /* - * A cancelled TD can complete with a stall if HW cached the trb. - * In this case driver can't find td, but if the ring is empty we - * can move the dequeue pointer to the current enqueue position. - * We shouldn't hit this anymore as cached cancelled TRBs are given back - * after clearing the cache, but be on the safe side and keep it anyway - */ - if (!td) { - if (list_empty(&ep_ring->td_list)) { - new_seg = ep_ring->enq_seg; - new_deq = ep_ring->enqueue; - new_cycle = ep_ring->cycle_state; - xhci_dbg(xhci, "ep ring empty, Set new dequeue = enqueue"); - goto deq_found; - } else { - xhci_warn(xhci, "Can't find new dequeue state, missing td\n"); - return -EINVAL; - } - } hw_dequeue = xhci_get_hw_deq(xhci, dev, ep_index, stream_id); new_seg = ep_ring->deq_seg; @@ -709,8 +690,6 @@ static int xhci_move_dequeue_past_td(struct xhci_hcd *xhci, } while (!cycle_found || !td_last_trb_found); -deq_found: - /* Don't update the ring cycle state for the producer (us). */ addr = xhci_trb_virt_to_dma(new_seg, new_deq); if (addr == 0) { From patchwork Wed Jun 26 12:48:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 807781 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 DA1C61850A6 for ; Wed, 26 Jun 2024 12:46:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406008; cv=none; b=Ysmqd5C1lWvQb0mOCG0/48PvXIatQKSAYd2joTNPJMkSr1UoY8J33Mwo3XX5kLUga4pp9lsdlrfi18f8uTNQy51sNmVJ9sCNetnm4La3CFuoaj0eijqKUQimddMupiQn7E+0fq+8Gf/xDB11V4I5Xtul60C6VD5jh2PZPOaOwTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406008; c=relaxed/simple; bh=7+iTBEdlfrKFKbc7K7Nyq9pAL6VazWI42smRq6uBE7s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kpFogbtfJSnJ20/8RxQ4gnEu1293WeMZwa3oYCd7ybOewAMAL/QbS3Q/pGScvAlQXwNE/TCHBMN5pbk+EtOT23v+OZ10LsPT1GCoi14V4j2v5eeYn6+vKWN4RuY04ym6jiNl1uCvwHkI8wf+mfqCQK8BQZIzDcwypbRlLKbi0Tw= 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=TP0ISuf6; arc=none smtp.client-ip=192.198.163.17 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="TP0ISuf6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719406007; x=1750942007; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7+iTBEdlfrKFKbc7K7Nyq9pAL6VazWI42smRq6uBE7s=; b=TP0ISuf6rSKaJDAr+EZVwIf5MPuoBxpyXkMXjtDtaL21v3FK4HTtLith T7qkLnzAVs3ccUJw2sZzlNvuJbGynro1m2S/kvBN/ne5ef3UHbhNCsxcM mGHzjdjgqaI19vq6W2s4y9x/jywFdlyevRE3bR8ZE+O5m2sxGHUACVcpS PV3yXBfWCOXx3IninakvaPIdFolhwtQsPmhd3OvdMtnLr+RK854ety231 UqOuCwHXV/uAclyYflW3KHAHPYzI4+2KLhMvr0FJavAXDXuoRM4nIXrsN VHbByqRkEj+H/pgxDnG0Ifq1wVnoWr5Yehlg8ZgqEd02jYNNE6ipI3jSK Q==; X-CSE-ConnectionGUID: lvF36v6eQQ2cssyY8EINlQ== X-CSE-MsgGUID: nHXvZ3iYThqx5nx7WWfb+g== X-IronPort-AV: E=McAfee;i="6700,10204,11114"; a="16353370" X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="16353370" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2024 05:46:47 -0700 X-CSE-ConnectionGUID: +WkQiUtVQcK7SjGBHU/DVg== X-CSE-MsgGUID: uSSNAzIkTvaEVlyPdwejgg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="48442576" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa005.fm.intel.com with ESMTP; 26 Jun 2024 05:46:45 -0700 From: Mathias Nyman To: Cc: , niklas.neronin@linux.intel.com, Mathias Nyman Subject: [PATCH 03/21] xhci: Set correct transferred length for cancelled isoc transfers Date: Wed, 26 Jun 2024 15:48:17 +0300 Message-Id: <20240626124835.1023046-4-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240626124835.1023046-1-mathias.nyman@linux.intel.com> References: <20240626124835.1023046-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 The transferred length is incorrectly zeroed for cancelled isoc transfer TDs when the transfer ring stops on a cancelled TD with a 'Stop - Length Invalid' completion code. Length was always set to zero in these cases even if it should be set to the sum of the TRB transfer block lengths up to the TRB the ring stopped on, _excluding_ the one stopped on. No issues reported due to this isoc case. Found while inspecting related case in bulk transfer 'Stop - Length Invalid' handling. Change this so that 'Stop - Length Invalid' transfer completion cases always sum up TRB lengths instead of report a zero length. Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index ffb3ebb72eaa..a12009ed1b36 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2439,7 +2439,9 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, requested = remaining; break; case COMP_STOPPED_LENGTH_INVALID: - requested = 0; + /* exclude stopped trb with invalid length from length sum */ + sum_trbs_for_length = true; + ep_trb_len = 0; remaining = 0; break; default: From patchwork Wed Jun 26 12:48:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 807780 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 F25C31850B6 for ; Wed, 26 Jun 2024 12:46:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406012; cv=none; b=C1bes5oiYFCIrNPAjnwWMqtgzrm+X/3Xjbqy63c6SoUfO6jAvykXFw2Ixs1NbjJMGTpD2zowC9Ah7VLOkWpao0oUQ8uA3mCj5g+TFOS1bA8ipDExOYWHtssX6VLJhDe9Co6OTObNJtzbR1QECkDYTLN+0zz+GTOQKYUJBtR+57I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406012; c=relaxed/simple; bh=qnF1aabk6XmCDSWp1a9CS0xzmmTt7z/1KA1e+pqx+kc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CSg8xZ8EWWuXY6g3PGz233UWtkSeRFC8kew8vfjhScNMg2RPZHchNEpWGXF7LV9SOJ7nwtzAUMoqvxejrf7ajDXsYUWBkcwMOHkkTlh0H392hoTo20W5+ud1j9eT8jE4ShrBRvnBuvQlrwtTgLoat46T0x42twqat3WIxXcsXLo= 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=JlK9ysY+; arc=none smtp.client-ip=192.198.163.17 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="JlK9ysY+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719406011; x=1750942011; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qnF1aabk6XmCDSWp1a9CS0xzmmTt7z/1KA1e+pqx+kc=; b=JlK9ysY+vnwrxDxAK1IyzlOfHg+Qd+fcdwrUC/CRdJAN1BZMaQGTVBUd w76mngxoWEfXGCu9+F1VYjVhEiqZUYk6EZD3sXsphSuX6JbFPRHEO9Qy0 N4fxJJYcqtALfMmQzue3f7SdxB/kPIKsaFlKZ28vm/nilWv3D+OfiDSAW jRyDr5POwfEWVdXnqwUtwaViCzaBZ68EIXOX+9mt5Tvt7NN8h+/BMBnwt qgudyCGTUv81BFjo6FTWOsobB/S7nv586hvUF0KLUmepp5xQwIzckhNyz BOuvJd5TyA4V1kHycxGKrzMhXFFp5uxfm5s4MAzTC6TuGYzfXFswU2z59 Q==; X-CSE-ConnectionGUID: /O6tMqxOQf67b5hcahxCJg== X-CSE-MsgGUID: N+ta9O4WTCqWJMZq9Legkw== X-IronPort-AV: E=McAfee;i="6700,10204,11114"; a="16353376" X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="16353376" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2024 05:46:50 -0700 X-CSE-ConnectionGUID: lYhcuFpyR7KVIHzq4sZhMg== X-CSE-MsgGUID: DlawZkd2QqG7X6UkasMmPw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="48442610" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa005.fm.intel.com with ESMTP; 26 Jun 2024 05:46:49 -0700 From: Mathias Nyman To: Cc: , niklas.neronin@linux.intel.com, Mathias Nyman Subject: [PATCH 05/21] usb: xhci: remove 'num_trbs' from struct 'xhci_td' Date: Wed, 26 Jun 2024 15:48:19 +0300 Message-Id: <20240626124835.1023046-6-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240626124835.1023046-1-mathias.nyman@linux.intel.com> References: <20240626124835.1023046-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: Niklas Neronin Remove 'num_trbs' from 'xhci_td' as it's no longer used following the removal of 'num_trbs_free' tracking in commit 2710f8186f88 ("xhci: Stop unnecessary tracking of free trbs in a ring"). Tracking of 'num_trbs_free' is still performed in xhci DbC, but it does not utilize 'num_trbs'. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 4 ---- drivers/usb/host/xhci.h | 1 - 2 files changed, 5 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index a12009ed1b36..dfde9d3cca02 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3704,7 +3704,6 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, upper_32_bits(send_addr), length_field, field); - td->num_trbs++; addr += trb_buff_len; sent_len = trb_buff_len; @@ -3731,7 +3730,6 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, urb_priv->td[1].last_trb_seg = ring->enq_seg; field = TRB_TYPE(TRB_NORMAL) | ring->cycle_state | TRB_IOC; queue_trb(xhci, ring, 0, 0, 0, TRB_INTR_TARGET(0), field); - urb_priv->td[1].num_trbs++; } check_trb_math(urb, enqd_len); @@ -3782,7 +3780,6 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, urb_priv = urb->hcpriv; td = &urb_priv->td[0]; - td->num_trbs = num_trbs; /* * Don't give the first TRB to the hardware (by toggling the cycle bit) @@ -4103,7 +4100,6 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, goto cleanup; } td = &urb_priv->td[i]; - td->num_trbs = trbs_per_td; /* use SIA as default, if frame id is used overwrite it */ sia_frame_id = TRB_SIA; if (!(urb->transfer_flags & URB_ISO_ASAP) && diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 78d014c4d884..4298513f0f71 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1294,7 +1294,6 @@ struct xhci_td { /* actual_length of the URB has already been set */ bool urb_length_set; bool error_mid_td; - unsigned int num_trbs; }; /* From patchwork Wed Jun 26 12:48:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 807779 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 89EF4185E74 for ; Wed, 26 Jun 2024 12:46:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406014; cv=none; b=HBYoXQcaICGoOoNW9/mvHYChtTcZg48EAp+L9oCqrwaXzqle0znyYtFoeMEXgqLgbcHgV9rcwxhjC8lYyf9Rw/CTAOxtQAF5pP2tX6kuBSYXyk2M91J8/z+qsLbSWKYxj8UhZbWWyrmusk45G7yRpK1fhyKDTAyi+/nEw3JS1Z8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406014; c=relaxed/simple; bh=rfAAQGB5R2HBy5HOhB5HCGGepa7BJWw6hAipjm4DFS4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G8fqbb5VpjhYNBb5w5IEXBn2spLTyTlcef4yrAtEl4RUCxGLvPK6s3vgASTK2DtXPyjAWCT1984UW+QRzi+/6OUhGZHeKGuoLW1mzDlYVAIBosU/fYtSLU2ndG3YqDXpUsEbQOyX11VTRxiQUj80cg8lFq1Z6frzYuvaTtMLCxU= 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=Ux+e29sh; arc=none smtp.client-ip=192.198.163.17 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="Ux+e29sh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719406014; x=1750942014; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rfAAQGB5R2HBy5HOhB5HCGGepa7BJWw6hAipjm4DFS4=; b=Ux+e29sh66xyaTuLv8IQa5J20yTGnpFcbCAbEfO7Gp6iIjkMfmo1Hik0 16Xp37L5jKXmEnjeCZCoUwaKn2ME0ryEnzdWdmZtnYHa2CuzfY7zYavEj 0iDwdavvV60wxEMAzDHxxH8TKjkLvZfmd9zLzwmzZu/FBTpzW3zRvraa/ GPIVRTr0+7Vn9xdRwF2q1ora09jSwQxO7x8cBGM9eFNLtgTjQ4hmXs8uf 1mG4UFd+QVF07rRz9qoKiGNDBoEnsgjUl5PWgbVG9IjHt4c8XqSfPUdfy MU20NKKHkYRLEpbQEMSpcJgjpUGjlZbQ2dZhY2zdGdkAgLW15XgpJ5gVM w==; X-CSE-ConnectionGUID: dNWfaWcOS5mrhVnqvKUwwg== X-CSE-MsgGUID: ueQ6CdGmRcu3oXywR1dVrQ== X-IronPort-AV: E=McAfee;i="6700,10204,11114"; a="16353384" X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="16353384" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2024 05:46:53 -0700 X-CSE-ConnectionGUID: i2HpsXAVTpCJBPrAMDpR9Q== X-CSE-MsgGUID: UFugE2HrT2uIp3tS9elb0g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="48442626" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa005.fm.intel.com with ESMTP; 26 Jun 2024 05:46:52 -0700 From: Mathias Nyman To: Cc: , niklas.neronin@linux.intel.com, Mathias Nyman Subject: [PATCH 07/21] usb: xhci: remove unused argument from xhci_handle_cmd_config_ep() Date: Wed, 26 Jun 2024 15:48:21 +0300 Message-Id: <20240626124835.1023046-8-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240626124835.1023046-1-mathias.nyman@linux.intel.com> References: <20240626124835.1023046-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: Niklas Neronin Argument u32 'cmd_comp_code' is not used, and as a consequence is removed. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index c528dc97dd9a..c2605e89adb0 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1516,8 +1516,7 @@ static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id) xhci_free_device_endpoint_resources(xhci, virt_dev, true); } -static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id, - u32 cmd_comp_code) +static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id) { struct xhci_virt_device *virt_dev; struct xhci_input_control_ctx *ctrl_ctx; @@ -1766,7 +1765,7 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, break; case TRB_CONFIG_EP: if (!cmd->completion) - xhci_handle_cmd_config_ep(xhci, slot_id, cmd_comp_code); + xhci_handle_cmd_config_ep(xhci, slot_id); break; case TRB_EVAL_CONTEXT: break; From patchwork Wed Jun 26 12:48:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 807778 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 144B21822F7 for ; Wed, 26 Jun 2024 12:46:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406018; cv=none; b=QEk15PkGxVEC1JiGy0aYdQed6OyTMswAalu7eL11DI8QnZVQb/WRp3jdrkmXxCHNvedggs6lx2UT8epwpqp0rW7jGfyL46h1DxNUu1miX8eFN2M3RPAb2IsFCYaMu20B6BbYnPNh4VN7M2SDcNIZk5P6FiFYSZFdCr8pp3bi/Kg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406018; c=relaxed/simple; bh=YJk6v0xpGnY8jY3nTxxXSL+QxgXF22oqRT5S8JlFqkA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DVBtjmG4B/BQ2f79JWdklYwQleOcG7is26xFr1o84DWDmh7kTidufn00yRhtPG3f3PqNfHtzmz+ECL0gpdNMGJaHxPjiRyHqb2/KWg7XCs6y0pXsPY4Aq/qSgZOMPyTi12dWR2RKyQWxi/JZAwKTF8SyA+Ku3lU2KGwd0h4xrns= 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=avAkHPHW; arc=none smtp.client-ip=192.198.163.17 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="avAkHPHW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719406017; x=1750942017; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YJk6v0xpGnY8jY3nTxxXSL+QxgXF22oqRT5S8JlFqkA=; b=avAkHPHWELij6oZkPIITUMrrwiiQ1WlVWmb7t9RTR0HOZelew8StH0Ng aUdgKe3h78YfiVJBNGg+Y5OkFyHsIeUy3HASqvNsPN6BCDxQTFCnKHp3o ajIYd5sspYkInLB/fJuc66438W6taWcboJ1L4tMNZu+hijeJhUum4ITf/ 0WGo+761GPrqjg6oXZRJge9l7etS43hSUUONsSN4e466a9nTKXKDZdvRs eQYZNK0jhU6SmCnEZovEVZ8Qu7lOewcDSxx+p+XilzWBPcC45lD7bgwKE 4+7YXhu7U2AS0iJBys2kBP0GLNd3togTICKZCRp6lX7NJCn3jfHshfAMC A==; X-CSE-ConnectionGUID: L24eO/kjT5eZWsb6yqFvdQ== X-CSE-MsgGUID: SG0baQjfQECDrFEyWX/0Ag== X-IronPort-AV: E=McAfee;i="6700,10204,11114"; a="16353391" X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="16353391" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2024 05:46:56 -0700 X-CSE-ConnectionGUID: CUzDAhRARm6K4gh6xr/5Bg== X-CSE-MsgGUID: 8fBJgB98S4CmPMLBABjQuw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="48442642" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa005.fm.intel.com with ESMTP; 26 Jun 2024 05:46:55 -0700 From: Mathias Nyman To: Cc: , niklas.neronin@linux.intel.com, Mathias Nyman Subject: [PATCH 09/21] usb: xhci: move link chain bit quirk checks into one helper function. Date: Wed, 26 Jun 2024 15:48:23 +0300 Message-Id: <20240626124835.1023046-10-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240626124835.1023046-1-mathias.nyman@linux.intel.com> References: <20240626124835.1023046-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: Niklas Neronin Older 0.95 xHCI hosts and some other specific newer hosts require the chain bit to be set for Link TRBs even if the link TRB is not in the middle of a transfer descriptor (TD). move the checks for all those cases into one xhci_link_chain_quirk() function to clean up and avoid code duplication. No functional changes. [skip renaming chain_links flag, reword commit message -Mathias] Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 10 ++-------- drivers/usb/host/xhci-ring.c | 8 ++------ drivers/usb/host/xhci.h | 7 +++++-- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 3100219d6496..68994ce21933 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -136,10 +136,7 @@ static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *ring, if (!ring || !first || !last) return; - /* Set chain bit for 0.95 hosts, and for isoc rings on AMD 0.96 host */ - chain_links = !!(xhci_link_trb_quirk(xhci) || - (ring->type == TYPE_ISOC && - (xhci->quirks & XHCI_AMD_0x96_HOST))); + chain_links = xhci_link_chain_quirk(xhci, ring->type); next = ring->enq_seg->next; xhci_link_segments(ring->enq_seg, first, ring->type, chain_links); @@ -335,10 +332,7 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, struct xhci_segment *prev; bool chain_links; - /* Set chain bit for 0.95 hosts, and for isoc rings on AMD 0.96 host */ - chain_links = !!(xhci_link_trb_quirk(xhci) || - (type == TYPE_ISOC && - (xhci->quirks & XHCI_AMD_0x96_HOST))); + chain_links = xhci_link_chain_quirk(xhci, type); prev = xhci_segment_alloc(xhci, cycle_state, max_packet, num, flags); if (!prev) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index e9130c7c2c53..8502776d84d6 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -250,9 +250,7 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, * AMD 0.96 host, carry over the chain bit of the previous TRB * (which may mean the chain bit is cleared). */ - if (!(ring->type == TYPE_ISOC && - (xhci->quirks & XHCI_AMD_0x96_HOST)) && - !xhci_link_trb_quirk(xhci)) { + if (!xhci_link_chain_quirk(xhci, ring->type)) { next->link.control &= cpu_to_le32(~TRB_CHAIN); next->link.control |= cpu_to_le32(chain); } @@ -3250,9 +3248,7 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, /* If we're not dealing with 0.95 hardware or isoc rings * on AMD 0.96 host, clear the chain bit. */ - if (!xhci_link_trb_quirk(xhci) && - !(ep_ring->type == TYPE_ISOC && - (xhci->quirks & XHCI_AMD_0x96_HOST))) + if (!xhci_link_chain_quirk(xhci, ep_ring->type)) ep_ring->enqueue->link.control &= cpu_to_le32(~TRB_CHAIN); else diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 4298513f0f71..65c84185c7fd 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1748,9 +1748,12 @@ static inline void xhci_write_64(struct xhci_hcd *xhci, lo_hi_writeq(val, regs); } -static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci) + +/* Link TRB chain should always be set on 0.95 hosts, and AMD 0.96 ISOC rings */ +static inline bool xhci_link_chain_quirk(struct xhci_hcd *xhci, enum xhci_ring_type type) { - return xhci->quirks & XHCI_LINK_TRB_QUIRK; + return (xhci->quirks & XHCI_LINK_TRB_QUIRK) || + (type == TYPE_ISOC && (xhci->quirks & XHCI_AMD_0x96_HOST)); } /* xHCI debugging */ From patchwork Wed Jun 26 12:48:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 807777 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 949B81822F7 for ; Wed, 26 Jun 2024 12:46:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406021; cv=none; b=s4TE9uTdhSx0c+FFVnluFzN1ygOBbZrmTSzn1lFggKYU+/AelLlvOKitp8ztW9OCrz4jGayLvSINz/mBA5rAGxH4BPxN3BW0f5h1dgJpgQcEEhwxSr1B28mqozQLs4thKl6hojPlOy3niagwjtVk3qNqTA3D31rtJ+Yc1pAJHeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406021; c=relaxed/simple; bh=fZwTs67BnEpBaW6b3/gDKaY8dkiRQzJyHp+ZIyB5gf0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KCHxihUIlvalJu6xt78Ggu4tKoxHUxvzCcpxh1cKv0+uWfhdP2n4M8KU7tBVYU7W/ZRikeAq0qF8dz9PhSIUpvJm4HLrTECpmg0LUgQgSx0rP/ipY7JRoGD1Ny9GyKnL8hpveAt5dhpH1A/LmVKs2/uffqmQLjJUH1ZxlOemPU8= 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=d84aTcj7; arc=none smtp.client-ip=192.198.163.17 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="d84aTcj7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719406020; x=1750942020; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fZwTs67BnEpBaW6b3/gDKaY8dkiRQzJyHp+ZIyB5gf0=; b=d84aTcj7CITfnIRQfiUO1rGlpZ68oTlfvDpyHurZGpIMU+FvCA+giFL6 cM9nrdUtnyJq+T4W0dA/odRLyCVMx0AJbubQAq5xl2NY5x9BH+guXbPJc ykq2S9kC7MMT+KzfzqEoH34+i9wLnQ8sVtXYSEi1ywL++GJDFPwZIAgWE CR88kQcHvNguSFKrNCV0ot4rzgoRqET0/XhL+qgruMEWeIWZt0cbhvqld 0ZOeXiqfWwsG+KSnrZgqGleIhDKeApcCgu/LOJtcQPVdSPgx/R42Uw3zD fOjOiseI5pFrYoBPtlOf1lNDulhETctlwlqf8Y5E/gfot2ulp13qgRzxs Q==; X-CSE-ConnectionGUID: bG1Gbuw/TPGf24KP1BA2sg== X-CSE-MsgGUID: JDDmBbXITXqLOBhp3OXVMw== X-IronPort-AV: E=McAfee;i="6700,10204,11114"; a="16353398" X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="16353398" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2024 05:46:59 -0700 X-CSE-ConnectionGUID: 4cvR+9XjSt2t/4kwJwg52w== X-CSE-MsgGUID: t7w5xN1uSTiPWGfU6PrA8g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="48442655" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa005.fm.intel.com with ESMTP; 26 Jun 2024 05:46:58 -0700 From: Mathias Nyman To: Cc: , niklas.neronin@linux.intel.com, Mathias Nyman Subject: [PATCH 11/21] usb: xhci: move untargeted transfer event handling to a separate function Date: Wed, 26 Jun 2024 15:48:25 +0300 Message-Id: <20240626124835.1023046-12-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240626124835.1023046-1-mathias.nyman@linux.intel.com> References: <20240626124835.1023046-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: Niklas Neronin Move handling transfer events without a target transfer TRB into handle_transferless_tx_event(), this type of event does not utilize the rest of handle_tx_event() and as a result it's better to separate it into a dedicated function. Additionally, this change reduces handle_tx_event()'s size and makes it more readable. [Mathias: Simplify code to return helper function value directly. This removes the second xhci_err() message for untargeted and unexpected event completion types] Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 56 +++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 8502776d84d6..7f40be2a3885 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2562,6 +2562,33 @@ 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, + u32 trb_comp_code) +{ + switch (trb_comp_code) { + case COMP_STALL_ERROR: + case COMP_USB_TRANSACTION_ERROR: + case COMP_INVALID_STREAM_TYPE_ERROR: + case COMP_INVALID_STREAM_ID_ERROR: + xhci_dbg(xhci, "Stream transaction error ep %u no id\n", ep->ep_index); + if (ep->err_count++ > MAX_SOFT_RETRY) + 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, "ERROR Transfer event for unknown stream ring slot %u ep %u\n", + ep->vdev->slot_id, ep->ep_index); + return -ENODEV; + } + return 0; +} + /* * If this function returns an error condition, it means it got a Transfer * event with a corrupted Slot ID, Endpoint ID, or TRB DMA address. @@ -2605,33 +2632,8 @@ static int handle_tx_event(struct xhci_hcd *xhci, goto err_out; } - /* Some transfer events don't always point to a trb, see xhci 4.17.4 */ - if (!ep_ring) { - switch (trb_comp_code) { - case COMP_STALL_ERROR: - case COMP_USB_TRANSACTION_ERROR: - case COMP_INVALID_STREAM_TYPE_ERROR: - case COMP_INVALID_STREAM_ID_ERROR: - xhci_dbg(xhci, "Stream transaction error ep %u no id\n", - ep_index); - if (ep->err_count++ > MAX_SOFT_RETRY) - 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, "ERROR Transfer event for unknown stream ring slot %u ep %u\n", - slot_id, ep_index); - goto err_out; - } - return 0; - } + if (!ep_ring) + return handle_transferless_tx_event(xhci, ep, trb_comp_code); /* Count current td numbers if ep->skip is set */ if (ep->skip) From patchwork Wed Jun 26 12:48:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 807776 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 1395E1862A4 for ; Wed, 26 Jun 2024 12:47:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406024; cv=none; b=Ru3YhEaS6+gM+AV+MWNVEG49sJKxMJGTXfDAZr01M2hH+VRub7Hlj1We624Ix/+jJMrHdHj2E0oYCGS2jHY0Q9I6YtK7366mx5DmWuwTkDEhjK1pLoSwMs/t0JCY1pmVQhOtI7et/nXcWLmFHbO18R1D1J+hqiZF2RXtGrH6mu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406024; c=relaxed/simple; bh=XrZxLF1GsrrK3ggG/UOEThyva4VHGIqS1npY/wmHnHY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ceVIaalKD3jcr7QqA7gC1Kv6RvAvbcnnIKXwTmJXBKJxOCmcldZvybGHrvmZvM3Vy/88r6PM3ePA1hSKFsWxKqUkhdI1ACb+r9bpqJl907S9iciqgvPA9T7pIUVcbucnm6ecoBAyI3sRoOn8yGlxZyt8T1t2sUQ0FuTEzj1pyMU= 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=azki7HnW; arc=none smtp.client-ip=192.198.163.17 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="azki7HnW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719406023; x=1750942023; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XrZxLF1GsrrK3ggG/UOEThyva4VHGIqS1npY/wmHnHY=; b=azki7HnWKdvuxS7l4XweJ6J/kD9ffjCrETtFe0xi4AYrilhiN6v6IQ2Y 2fZLBoEHAQg4TuQ+aftIe5vStKdjXyWWC+BogdLyLaIC0uAzldwKyYgc0 XPf7Xg5Ldz5sF5r+Ts2Wsw7OWlsuyimGlHSqwEKrqdMy1PJ5pCLX0aymH RGaiFMXx0P+QKDkviA1kGinwE5UcTlO+86ua1dhuApTTX0zR2jziazdYj jMoEyadSxPkHl7/uIqBv1UT+wxouoCM6OpzEPr/2CtDmV4Wr29iUZFD4F ix0Zo3yKS/QVCNIAfUBSQvkI0KWO0UJoDZnW7D7O9WhPAgcFd4GcvXjk+ w==; X-CSE-ConnectionGUID: Z7b9I4lCSvSEAsH81WsrLQ== X-CSE-MsgGUID: rInFaToiSxWFkOpqX+zYQA== X-IronPort-AV: E=McAfee;i="6700,10204,11114"; a="16353404" X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="16353404" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2024 05:47:02 -0700 X-CSE-ConnectionGUID: ngMSNATARRqzJdHdy4eIrw== X-CSE-MsgGUID: cxGxdKALR2i/Cq7aG6iK2Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="48442673" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa005.fm.intel.com with ESMTP; 26 Jun 2024 05:47:01 -0700 From: Mathias Nyman To: Cc: , niklas.neronin@linux.intel.com, Mathias Nyman Subject: [PATCH 13/21] usb: xhci: remove obsolete sanity check debug messages Date: Wed, 26 Jun 2024 15:48:27 +0300 Message-Id: <20240626124835.1023046-14-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240626124835.1023046-1-mathias.nyman@linux.intel.com> References: <20240626124835.1023046-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: Niklas Neronin Remove debug messages that served as sanity checks during the initial implementation phase of underrun/overrun completion codes. These checks are now unnecessary. Instead, improve the default debug messages for underrun/overrun events, so that they are consistent with the reset of the completion codes. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index d4e4c1c71f90..900bf34174f9 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2719,18 +2719,12 @@ static int handle_tx_event(struct xhci_hcd *xhci, * a Ring Overrun Event for IN Isoch endpoint or Ring * Underrun Event for OUT Isoch endpoint. */ - xhci_dbg(xhci, "underrun event on endpoint\n"); - if (!list_empty(&ep_ring->td_list)) - xhci_dbg(xhci, "Underrun Event for slot %u ep %d still with TDs queued?\n", - slot_id, ep_index); + xhci_dbg(xhci, "Underrun event on slot %u ep %u\n", slot_id, ep_index); if (ep->skip) break; return 0; case COMP_RING_OVERRUN: - xhci_dbg(xhci, "overrun event on endpoint\n"); - if (!list_empty(&ep_ring->td_list)) - xhci_dbg(xhci, "Overrun Event for slot %u ep %d still with TDs queued?\n", - slot_id, ep_index); + xhci_dbg(xhci, "Overrun event on slot %u ep %u\n", slot_id, ep_index); if (ep->skip) break; return 0; From patchwork Wed Jun 26 12:48: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: 807775 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 E54B91822F3 for ; Wed, 26 Jun 2024 12:47:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406027; cv=none; b=OhcicmbkIdifHJqgqdSOYSLrdGlPSa9O6R3t0HHA4B7FSGVRjKNMZrhANUjlfSsarDiu3UyeOk8qTUmac9+grB5QWgU3JOb0ajcTnsAFoNhmy3mI42v62wOlBpOBY2NwQ3u4WdFtLcGJDnfevxedtIT/DSBmOOg+y7vDaTgz+yI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406027; c=relaxed/simple; bh=jmWZnCIqgkLd8OyOu0s6Mkzb6PVeEji6dumfz48P/Go=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=i3MJc1i3QQphPhLEiVob9bcOiGC//u7do1MSY3M93+Pl1207sochwt8essguN3IaII7Ulak5hDwm9sv+RQ4Mtqy2NsEknDFU8txtzWTf8TucLjDhfs1bsSOTe/UIhFVr4qXjpzwaWmjS9gklmlPCGng3m8Af3rhrn0Q3PqFohww= 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=XjVdpqf7; arc=none smtp.client-ip=192.198.163.17 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="XjVdpqf7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719406026; x=1750942026; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jmWZnCIqgkLd8OyOu0s6Mkzb6PVeEji6dumfz48P/Go=; b=XjVdpqf7B1E95IyEiycyvOsMQmN5kd0b8SYy2mr11qBMOXdLeYPqvCpI Ri4mRY9suH53eKnz6JqzGeDfmI+DVdBC1D8aBPOJaIFmukgyPBSMTiyA+ OO5ZACQi2fTw5tvkZjGZY6P8wSLAsTTp+WnDZNPnJtUX+TGFSnYLLVSYk 5g9B/Lu+SdJKavtbEQSlHFqafwndkqHX4Ar73jrFRRRThcSTYvl/LvDCX XqoHOXULJHiHeaWuSTT3dP8wbVjtc7Xu8KFea5donG7/cGohxUPaP+kFq a+RVPBJaGrDTMtrHx3+QmSw9Ivp2ZEgbS5Dg6ej0/iwi/SCswI2nGQLgV g==; X-CSE-ConnectionGUID: ELMlxjR6R3GDn16LUNkVmQ== X-CSE-MsgGUID: Oy8ApBI+QMKU1rU3GZ/DiA== X-IronPort-AV: E=McAfee;i="6700,10204,11114"; a="16353412" X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="16353412" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2024 05:47:06 -0700 X-CSE-ConnectionGUID: NEQCoS0kTcuzh60nmMdNSA== X-CSE-MsgGUID: xAS4TpsQT/G4UctCr9xAog== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="48442706" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa005.fm.intel.com with ESMTP; 26 Jun 2024 05:47:04 -0700 From: Mathias Nyman To: Cc: , niklas.neronin@linux.intel.com, Mathias Nyman Subject: [PATCH 15/21] usb: xhci: ensure skipped isoc TDs are returned when isoc ring is stopped Date: Wed, 26 Jun 2024 15:48:29 +0300 Message-Id: <20240626124835.1023046-16-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240626124835.1023046-1-mathias.nyman@linux.intel.com> References: <20240626124835.1023046-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: Niklas Neronin Missed service event tells the driver that the hardware wasn't able to process some queued isoc TDs in their right time slots, and some TDs will be skipped. The driver sets a 'skip' flag to indicate that the next transfer event after this event will point to some future TD instead of the next queued TD. Once the driver receives the next event, it will skip and give back all those hardware skipped TDs. However, should this subsequent event be a stop endpoint which does not point to the next pending TD, the driver fails to return the skipped TDs. Instead, it loops for a period before outputting an erroneous message. Fix this by repositioning the 'stop endpoint' check to follow the isoc skip check, ensuring the skipped TDs are properly returned. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 3479c9cb5d33..14898335d193 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2819,19 +2819,6 @@ 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); - /* - * Skip the Force Stopped Event. The event_trb(event_dma) 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 (!ep_seg && (trb_comp_code == COMP_STOPPED || - trb_comp_code == COMP_STOPPED_LENGTH_INVALID)) { - continue; - } - if (!ep_seg) { if (ep->skip && usb_endpoint_xfer_isoc(&td->urb->ep->desc)) { @@ -2839,6 +2826,18 @@ static int handle_tx_event(struct xhci_hcd *xhci, 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. From patchwork Wed Jun 26 12:48:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 807774 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 25F32186E24 for ; Wed, 26 Jun 2024 12:47:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406030; cv=none; b=fwj695g2K35kFHGbTQJ5hhJ3JbFyJUJPFBcsX4VdMEB4Q2A5fL7CmCdJOqnmAxJFq86mx/fkZgI60j5tMO48mG64UhWq87My+jN5JwpjvRwo9OIubENwkZ3lvHGV3woaNPtv4H9bVOcb5dJrV+HwHGiy19UWChAKJP8UGlgnI+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406030; c=relaxed/simple; bh=gyKO8IFwKr7MXu/XKILJaXKUfHQfFNfxpzzz0D0jN9M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RmM4yoYHT8tF2SvzL0vIhv7Dog9tzXK1Ngy0gcWKYNIG0Mhek9fIsoLEz/eNx7kcbG+0+0ftreJSo7gEo3B7dWSCM7/X5RMdzWNxEWqC24uDSRhdvC2Na4TzsHoDpPN5qhS/nkDXN+ACJRK3n+iV5/pUut4QsdNpPuJaRePgRtE= 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=bs+55l+W; arc=none smtp.client-ip=192.198.163.17 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="bs+55l+W" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719406029; x=1750942029; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gyKO8IFwKr7MXu/XKILJaXKUfHQfFNfxpzzz0D0jN9M=; b=bs+55l+WyLwPgp81byTzd8uUj+kCfyupPe/N7FTxLoaFzpW7SSYsORPG tMCdEQ9NgbuXzWFXjySxzQcnGg4mhbENdSJYSDA/W5KohgSF9N5cM7mNg M6p0EZ4bVwm5vzELiIkrHwIkXWqEAXyAJi7hqQuUmBJ4nqTx/aB3DoqHx t+rqr8y6B6hvuCBdks0FyrNvkvBm8JGhaZCSXVNfL5ZCHHhmFXfaKi6on JNizuZUPi2sAc796YDtMo8bZ+Lb5Rgo01uuK5XJI1+b/aeWjbHSjdWR1w DoHNKk0VoOMDSvpkInUienVXGEmNwWiZARkyw8yWCuqtJ3lbD3vsRd3xw Q==; X-CSE-ConnectionGUID: /1rf79BxQOGtt52mYL2Xtg== X-CSE-MsgGUID: h4mFc3fWR+6qdqb9k+M5mQ== X-IronPort-AV: E=McAfee;i="6700,10204,11114"; a="16353420" X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="16353420" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2024 05:47:09 -0700 X-CSE-ConnectionGUID: SA/TNRwgSeKhZQVd1Bw7GA== X-CSE-MsgGUID: XJvCFHs5Tyyr7MarGYHYvQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="48442745" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa005.fm.intel.com with ESMTP; 26 Jun 2024 05:47:07 -0700 From: Mathias Nyman To: Cc: , niklas.neronin@linux.intel.com, Mathias Nyman Subject: [PATCH 17/21] usb: xhci: remove infinite loop prevention Date: Wed, 26 Jun 2024 15:48:31 +0300 Message-Id: <20240626124835.1023046-18-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240626124835.1023046-1-mathias.nyman@linux.intel.com> References: <20240626124835.1023046-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: Niklas Neronin If a buggy HW reports some unpredicted event (for example, an overrun event following a MSE event while the EP ring is actually not empty), the driver will never find the TD, and it will loop until the TD list is empty. Before commits [1][2], the spin lock was released when giving back a URB in the do-while loop. This could cause more TD to be added to TD list, causing an infinite loop. Because of commits [1][2] the spin lock is not released any more, thus the infinite loop prevention is unnecessary and is removed. [1], commit 0c03d89d0c71 ("xhci: Giveback urb in finish_td directly") [2], commit 36dc01657b49 ("usb: host: xhci: Support running urb giveback in tasklet context") Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 8289f69a6978..7baa9dc706a1 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2611,7 +2611,6 @@ static int handle_tx_event(struct xhci_hcd *xhci, int status = -EINPROGRESS; struct xhci_ep_ctx *ep_ctx; u32 trb_comp_code; - int td_num = 0; slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); ep_index = TRB_TO_EP_ID(le32_to_cpu(event->flags)) - 1; @@ -2637,10 +2636,6 @@ static int handle_tx_event(struct xhci_hcd *xhci, if (!ep_ring) return handle_transferless_tx_event(xhci, ep, trb_comp_code); - /* Count current td numbers if ep->skip is set */ - if (ep->skip) - td_num += list_count_nodes(&ep_ring->td_list); - /* Look for common error cases */ switch (trb_comp_code) { /* Skip codes that require special handling depending on @@ -2799,18 +2794,8 @@ static int handle_tx_event(struct xhci_hcd *xhci, return 0; } - /* We've skipped all the TDs on the ep ring when ep->skip set */ - if (ep->skip && td_num == 0) { - ep->skip = false; - xhci_dbg(xhci, "All tds on the ep_ring skipped. Clear skip flag for slot %u ep %u.\n", - slot_id, ep_index); - return 0; - } - td = list_first_entry(&ep_ring->td_list, struct xhci_td, td_list); - if (ep->skip) - td_num--; /* Is this a TRB in the currently executing TD? */ ep_seg = trb_in_td(xhci, td, ep_trb_dma, false); From patchwork Wed Jun 26 12:48:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 807773 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 E566E1862BB for ; Wed, 26 Jun 2024 12:47:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406033; cv=none; b=N2GxFQqt8VTClRUDUu44TJV3WWZkjUOXqqR6bX0d0/dLT4Ft0kulePF06UsaihEAF7gxm7upmpuKRB0IuUyBXN+f/J4QEQHofy0Ha6qVyV+yGW1/XBDUz61efRDj6CR9eoHs+Se3SHTsOp0v9erNmvIk4ec+t3k0kH2aZw02+yA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406033; c=relaxed/simple; bh=hrd9w+sxQQLra8j3AHrj+5T3GehonSb9FUtvqUpbx+U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=u2WtVrWLiI/xK6WsEB4Bmdr+yEbN4OUviwDC/E3xidnR6YU545mOfRcRlQD5/GavAYznBu4kJNuywkkl6/HKUrtYN73BA30m78WXrYOdrqhzYjx2Kx8ZHltd7/IkIfu6YHkO+jtX3LuMlbSMnUrvX+4wMKFLZv13d1NVdIcz/vg= 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=CMb0S3UU; arc=none smtp.client-ip=192.198.163.17 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="CMb0S3UU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719406032; x=1750942032; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hrd9w+sxQQLra8j3AHrj+5T3GehonSb9FUtvqUpbx+U=; b=CMb0S3UUxGwbK6ci0Qa5dUDCrzJWiI6tfU+lTJBtsLEqpkR7CgVmqlPB 0qE7vvG9/hGJZSYgg5DflAy970oyYf9xciFLRmOyxoCQtN8U+ntfkORzf +/K/9/Ku3OyOKeaB4uFOMhQjKKzV8WJKD7sEqi94w9hGdWU9uWjru0k8O 4ciDPGr2L3NL+ddiEA6PVvZGzbgIjW+B7mFrSZMxEKnv9XLdESW2y9sH2 6/nxkyYcv0klTgY+2v8v5PAfE7JIjp9qomNq+5o/nURD/uMDu2t14jM6M EjAxWnxb3yYD8NXVaJwPmTQ9gKngxkuWCIhnKXwpN+jlrLQqeXfOM3apU Q==; X-CSE-ConnectionGUID: /Xsw8qFhQz6z3+3KbQ0Qrg== X-CSE-MsgGUID: KAn43+q3QguzSr0LzbLjPQ== X-IronPort-AV: E=McAfee;i="6700,10204,11114"; a="16353429" X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="16353429" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2024 05:47:12 -0700 X-CSE-ConnectionGUID: XVsWRc7nQ3+bFasuJALxgA== X-CSE-MsgGUID: MnRyrbpBS1eS5cjwigOKqQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="48442761" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa005.fm.intel.com with ESMTP; 26 Jun 2024 05:47:10 -0700 From: Mathias Nyman To: Cc: , niklas.neronin@linux.intel.com, Mathias Nyman Subject: [PATCH 19/21] usb: xhci: add 'goto' for halted endpoint check in handle_tx_event() Date: Wed, 26 Jun 2024 15:48:33 +0300 Message-Id: <20240626124835.1023046-20-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240626124835.1023046-1-mathias.nyman@linux.intel.com> References: <20240626124835.1023046-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: Niklas Neronin Add 'goto' statement for a halted endpoint, streamlining the error handling process. In future handle_tx_event() changes this 'goto' statement will have more uses. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index d037d3bbc767..49f8f980776b 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2788,10 +2788,9 @@ static int handle_tx_event(struct xhci_hcd *xhci, xhci_dbg(xhci, "td_list is empty while skip flag set. Clear skip flag for slot %u ep %u.\n", slot_id, ep_index); } - if (xhci_halted_host_endpoint(ep_ctx, trb_comp_code)) - xhci_handle_halted_endpoint(xhci, ep, NULL, EP_HARD_RESET); - return 0; + td = NULL; + goto check_endpoint_halted; } td = list_first_entry(&ep_ring->td_list, struct xhci_td, @@ -2899,20 +2898,22 @@ static int handle_tx_event(struct xhci_hcd *xhci, * indefinitely. */ - if (trb_is_noop(ep_trb)) { - if (xhci_halted_host_endpoint(ep_ctx, trb_comp_code)) - xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET); - } else { - td->status = status; + if (trb_is_noop(ep_trb)) + goto check_endpoint_halted; - /* update the urb's actual_length and give back to the core */ - if (usb_endpoint_xfer_control(&td->urb->ep->desc)) - process_ctrl_td(xhci, ep, ep_ring, td, ep_trb, event); - else if (usb_endpoint_xfer_isoc(&td->urb->ep->desc)) - process_isoc_td(xhci, ep, ep_ring, td, ep_trb, event); - else - process_bulk_intr_td(xhci, ep, ep_ring, td, ep_trb, event); - } + td->status = status; + + /* update the urb's actual_length and give back to the core */ + if (usb_endpoint_xfer_control(&td->urb->ep->desc)) + process_ctrl_td(xhci, ep, ep_ring, td, ep_trb, event); + else if (usb_endpoint_xfer_isoc(&td->urb->ep->desc)) + process_isoc_td(xhci, ep, ep_ring, td, ep_trb, event); + else + process_bulk_intr_td(xhci, ep, ep_ring, td, ep_trb, event); + +check_endpoint_halted: + if (xhci_halted_host_endpoint(ep_ctx, trb_comp_code)) + xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET); return 0; From patchwork Wed Jun 26 12:48:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 807772 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 9C315186E43 for ; Wed, 26 Jun 2024 12:47:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406037; cv=none; b=ozuFd+HR8Uipu1Q7jj87gDQOY/QtQ/WSRxAc96Pq/8Zm0Y/Qs3hBP1XIn8/B2e28Vv1pK+Sddyle8BmfiuwFAbSXf8b0B4Rvxn8LT+qbHGD93oyCNgKNiuQYvNfkO3Ci9FF7xwGREXMGZARLiIv8KU5oXui2m0CSwM07rUp0xOQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719406037; c=relaxed/simple; bh=vmBUWblzpmIXath72nBkIqVv4PUWSos71TXTYhsxET0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EeOCgMUdyCiclpxTbeo/nvlR0ROoitztLgHJFJbrf1o5nU+pJiEy2MqlCcjYI4zcUMl/q9K3sEH7tSdAiqPHRH++sFgOMoAd8HYY1419W8c/avY5B7erIA935vxd52t5O+2As322zgC6mTwMO9vWykyLr5qdQjZVFTCofofF2dU= 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=feqtQsRf; arc=none smtp.client-ip=192.198.163.17 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="feqtQsRf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719406036; x=1750942036; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vmBUWblzpmIXath72nBkIqVv4PUWSos71TXTYhsxET0=; b=feqtQsRfd69zYPFykg6AjhVkpjXyrZGgZ6ANi+1W+7RHmgMwcPIRNTkr cZWQt12XOBdtbgzQwsXYa8LHUM0QBuiNruf8UexSGi/A52Bx9WBivWvT0 UzQ+7Tp6uWchmrNTgi1rYBzI8DIJgCDv9rWi/dHxR+n7jqutxMAxeKffZ OC7ge9yCYtuBk8S+07+F/+2Ou9Dsq6C/EfW/osRgvvnHGaz8Yz3DsGJ0L WEmY71mmiI+vogqQgphbUTzS20dL/N5iWFxZtEu6wPRHDf3bxK3KWg0F/ cKgxTFxhb8mqrLXBFicGe17JmhXPS6UqkgShg4F6NzjeqJo71cY1gS+lO A==; X-CSE-ConnectionGUID: Mp8LjKlIRHe5uF4P+p+hpQ== X-CSE-MsgGUID: NNpfozK/SMSjjPI52tBABw== X-IronPort-AV: E=McAfee;i="6700,10204,11114"; a="16353440" X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="16353440" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2024 05:47:15 -0700 X-CSE-ConnectionGUID: VPEENAWRS4iTxtwXd7HdgQ== X-CSE-MsgGUID: ZJcsSEWOTEeQUL3mzP4FUQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,266,1712646000"; d="scan'208";a="48442776" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa005.fm.intel.com with ESMTP; 26 Jun 2024 05:47:13 -0700 From: Mathias Nyman To: Cc: , niklas.neronin@linux.intel.com, Mathias Nyman Subject: [PATCH 21/21] xhci: sort out TRB Endpoint ID bitfield macros Date: Wed, 26 Jun 2024 15:48:35 +0300 Message-Id: <20240626124835.1023046-22-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240626124835.1023046-1-mathias.nyman@linux.intel.com> References: <20240626124835.1023046-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 xhci macros that read and write endpoint ID bitfields of TRBs are mixing the 1-based Endpoint ID as described in the xHCI specification, and 0-based endpoint index used by driver as an array index. Sort this out by naming macros that deal with 1 based Endpoint ID fields to *_EP_ID_*, and 0 based endpoint index values to *_EP_INDEX_*. Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 6 +++--- drivers/usb/host/xhci.h | 33 ++++++++++++++------------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 49f8f980776b..b7517c3c8059 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -715,7 +715,7 @@ static int xhci_move_dequeue_past_td(struct xhci_hcd *xhci, lower_32_bits(addr) | trb_sct | new_cycle, upper_32_bits(addr), STREAM_ID_FOR_TRB(stream_id), SLOT_ID_FOR_TRB(slot_id) | - EP_ID_FOR_TRB(ep_index) | TRB_TYPE(TRB_SET_DEQ), false); + EP_INDEX_FOR_TRB(ep_index) | TRB_TYPE(TRB_SET_DEQ), false); if (ret < 0) { xhci_free_command(xhci, cmd); return ret; @@ -4379,7 +4379,7 @@ int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd, int slot_id, unsigned int ep_index, int suspend) { u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); - u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); + u32 trb_ep_index = EP_INDEX_FOR_TRB(ep_index); u32 type = TRB_TYPE(TRB_STOP_RING); u32 trb_suspend = SUSPEND_PORT_FOR_TRB(suspend); @@ -4392,7 +4392,7 @@ int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd, enum xhci_ep_reset_type reset_type) { u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); - u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); + u32 trb_ep_index = EP_INDEX_FOR_TRB(ep_index); u32 type = TRB_TYPE(TRB_RESET_EP); if (reset_type == EP_SOFT_RESET) diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 65c84185c7fd..9fa1b58121f0 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -805,13 +805,19 @@ struct xhci_transfer_event { __le32 flags; }; +/* Transfer event flags bitfield, also for select command completion events */ +#define TRB_TO_SLOT_ID(p) (((p) >> 24) & 0xff) +#define SLOT_ID_FOR_TRB(p) (((p) & 0xff) << 24) + +#define TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f) /* Endpoint ID 1 - 31 */ +#define EP_ID_FOR_TRB(p) (((p) & 0x1f) << 16) + +#define TRB_TO_EP_INDEX(p) (TRB_TO_EP_ID(p) - 1) /* Endpoint index 0 - 30 */ +#define EP_INDEX_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16) + /* Transfer event TRB length bit mask */ -/* bits 0:23 */ #define EVENT_TRB_LEN(p) ((p) & 0xffffff) -/** Transfer Event bit fields **/ -#define TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f) - /* Completion Code - only applicable for some types of TRBs */ #define COMP_CODE_MASK (0xff << 24) #define GET_COMP_CODE(p) (((p) & COMP_CODE_MASK) >> 24) @@ -950,8 +956,6 @@ struct xhci_event_cmd { __le32 flags; }; -/* flags bitmasks */ - /* Address device - disable SetAddress */ #define TRB_BSR (1<<9) @@ -987,13 +991,8 @@ enum xhci_setup_dev { /* bits 16:23 are the virtual function ID */ /* bits 24:31 are the slot ID */ -#define TRB_TO_SLOT_ID(p) (((p) & (0xff<<24)) >> 24) -#define SLOT_ID_FOR_TRB(p) (((p) & 0xff) << 24) /* Stop Endpoint TRB - ep_index to endpoint ID for this TRB */ -#define TRB_TO_EP_INDEX(p) ((((p) & (0x1f << 16)) >> 16) - 1) -#define EP_ID_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16) - #define SUSPEND_PORT_FOR_TRB(p) (((p) & 1) << 23) #define TRB_TO_SUSPEND_PORT(p) (((p) & (1 << 23)) >> 23) #define LAST_EP_INDEX 30 @@ -2023,8 +2022,7 @@ static inline const char *xhci_decode_trb(char *str, size_t size, field1, field0, xhci_trb_comp_code_string(GET_COMP_CODE(field2)), EVENT_TRB_LEN(field2), TRB_TO_SLOT_ID(field3), - /* Macro decrements 1, maybe it shouldn't?!? */ - TRB_TO_EP_INDEX(field3) + 1, + TRB_TO_EP_ID(field3), xhci_trb_type_string(type), field3 & EVENT_DATA ? 'E' : 'e', field3 & TRB_CYCLE ? 'C' : 'c'); @@ -2139,8 +2137,7 @@ static inline const char *xhci_decode_trb(char *str, size_t size, xhci_trb_type_string(type), field1, field0, TRB_TO_SLOT_ID(field3), - /* Macro decrements 1, maybe it shouldn't?!? */ - TRB_TO_EP_INDEX(field3) + 1, + TRB_TO_EP_ID(field3), field3 & TRB_TSP ? 'T' : 't', field3 & TRB_CYCLE ? 'C' : 'c'); break; @@ -2150,8 +2147,7 @@ static inline const char *xhci_decode_trb(char *str, size_t size, xhci_trb_type_string(type), TRB_TO_SLOT_ID(field3), TRB_TO_SUSPEND_PORT(field3), - /* Macro decrements 1, maybe it shouldn't?!? */ - TRB_TO_EP_INDEX(field3) + 1, + TRB_TO_EP_ID(field3), field3 & TRB_CYCLE ? 'C' : 'c'); break; case TRB_SET_DEQ: @@ -2161,8 +2157,7 @@ static inline const char *xhci_decode_trb(char *str, size_t size, field1, field0, TRB_TO_STREAM_ID(field2), TRB_TO_SLOT_ID(field3), - /* Macro decrements 1, maybe it shouldn't?!? */ - TRB_TO_EP_INDEX(field3) + 1, + TRB_TO_EP_ID(field3), field3 & TRB_CYCLE ? 'C' : 'c'); break; case TRB_RESET_DEV: