From patchwork Wed Nov 6 10:14: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: 841355 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 064421D5CFA for ; Wed, 6 Nov 2024 10:12:47 +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=1730887969; cv=none; b=H1CrFAjgOtEAV/lJ0/QganJKZg0D5gAvAG026aEXGx8Rq06g7bpAV5EV4C1gXzmbjXDBPebRK383VcujnC77iexA6kpifY9JbRjhtiTZ95o8h/41P2ZEII/xdLHA4K0shco/M6SO8qa4g0YuSYJATemijYHHbqDCnT50Lr25ukQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887969; c=relaxed/simple; bh=b3kN85tiYxX17X3EwtdFsDL4rcqNRGlmb19y0lrOwgs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S+9FndHQcArFBZtn/MDyb5xz/ZXoMiJjppOMlcbLIWVfJkJKWQ5uK3ZKQOWRDBVCH+JzfAL8V7jPnFTLX/p7iSFhdvF0quHlUtglcz0lnQTc2aqMFj8SAG9oJxwCTrlVyeDaexS58mbQVKzLVX6P5F0IKhsEulVoGIMyKdL0/YQ= 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=UBQ2TNle; 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="UBQ2TNle" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887968; x=1762423968; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b3kN85tiYxX17X3EwtdFsDL4rcqNRGlmb19y0lrOwgs=; b=UBQ2TNlezynEfYNduFD+paaDkUJEFZSjfDoCjAGNCoUdjsH2HTTJ4wUr M3yM9tgF/088U66FzHAKWt41VpZKkjJjB5iHLsuZoCDKwLCJjVTEAOhuS tUbJp4v0/pWW3jc+EiGHsDIX8/SRMh9SZv/MCg4ZiTPBVpSyUbL6F7ctR FsLf4TGBwnEBqG4MBAxJe5bURTZNUh+Wxj4RGvfW7Bfzg00y5FWV48N1B GHUt55ms+KO8OxJpYXyOtM1jlhYigtWtPGj7SW9cZ0waVRXVw7Vx9KKvY nuKloDSnKC2gO7AYi9zxNtBvdpRT7k1yk+GtrBPcaRm+ueZGHp7PT2ff2 w==; X-CSE-ConnectionGUID: Beugch/BQ3u5OssWutHknw== X-CSE-MsgGUID: gR7xgtJVTCGBO5J6ZKXRWg== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059369" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059369" 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:47 -0800 X-CSE-ConnectionGUID: qjYJyucOQCOxU/iq85I7LA== X-CSE-MsgGUID: c8ehvUV/S0mkuxPjuSdoBg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84812912" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:12:46 -0800 From: Mathias Nyman To: Cc: , Mathias Nyman Subject: [PATCH 01/33] xhci: Add Isochronous TRB fields to TRB tracer Date: Wed, 6 Nov 2024 12:14:27 +0200 Message-Id: <20241106101459.775897-2-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 In addition to Normal TRB fields the Isoch TRBs have a SIA flag, Frame ID, TLBPC and TBC fields. Add these fields to tracing output Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.h | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 55a81073cf1e..7d81645c2c5d 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1023,9 +1023,6 @@ enum xhci_setup_dev { /* Interrupter Target - which MSI-X vector to target the completion event at */ #define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22) #define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff) -/* Total burst count field, Rsvdz on xhci 1.1 with Extended TBC enabled (ETE) */ -#define TRB_TBC(p) (((p) & 0x3) << 7) -#define TRB_TLBPC(p) (((p) & 0xf) << 16) /* Cycle bit - indicates TRB ownership by HC or HCD */ #define TRB_CYCLE (1<<0) @@ -1059,6 +1056,12 @@ enum xhci_setup_dev { /* Isochronous TRB specific fields */ #define TRB_SIA (1<<31) #define TRB_FRAME_ID(p) (((p) & 0x7ff) << 20) +#define GET_FRAME_ID(p) (((p) >> 20) & 0x7ff) +/* Total burst count field, Rsvdz on xhci 1.1 with Extended TBC enabled (ETE) */ +#define TRB_TBC(p) (((p) & 0x3) << 7) +#define GET_TBC(p) (((p) >> 7) & 0x3) +#define TRB_TLBPC(p) (((p) & 0xf) << 16) +#define GET_TLBPC(p) (((p) >> 16) & 0xf) /* TRB cache size for xHC with TRB cache */ #define TRB_CACHE_SIZE_HS 8 @@ -2072,7 +2075,6 @@ static inline const char *xhci_decode_trb(char *str, size_t size, field3 & TRB_CYCLE ? 'C' : 'c'); break; case TRB_NORMAL: - case TRB_ISOC: case TRB_EVENT_DATA: case TRB_TR_NOOP: snprintf(str, size, @@ -2089,7 +2091,25 @@ static inline const char *xhci_decode_trb(char *str, size_t size, field3 & TRB_ENT ? 'E' : 'e', field3 & TRB_CYCLE ? 'C' : 'c'); break; - + case TRB_ISOC: + snprintf(str, size, + "Buffer %08x%08x length %d TD size/TBC %d intr %d type '%s' TBC %u TLBPC %u frame_id %u flags %c:%c:%c:%c:%c:%c:%c:%c:%c", + field1, field0, TRB_LEN(field2), GET_TD_SIZE(field2), + GET_INTR_TARGET(field2), + xhci_trb_type_string(type), + GET_TBC(field3), + GET_TLBPC(field3), + GET_FRAME_ID(field3), + field3 & TRB_SIA ? 'S' : 's', + field3 & TRB_BEI ? 'B' : 'b', + field3 & TRB_IDT ? 'I' : 'i', + field3 & TRB_IOC ? 'I' : 'i', + field3 & TRB_CHAIN ? 'C' : 'c', + field3 & TRB_NO_SNOOP ? 'S' : 's', + field3 & TRB_ISP ? 'I' : 'i', + field3 & TRB_ENT ? 'E' : 'e', + field3 & TRB_CYCLE ? 'C' : 'c'); + break; case TRB_CMD_NOOP: case TRB_ENABLE_SLOT: snprintf(str, size, From patchwork Wed Nov 6 10:14:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842353 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 589411DD531 for ; Wed, 6 Nov 2024 10:12:49 +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=1730887971; cv=none; b=r1+cqq9UxekJsxNc/vBYw9sp5HpYHA3u8qaRuABvEfdWe1qVXJrmU/3PMm5hXoYcV9oAVF3JzYC3uUZ/z4KAfevAocMrmCkHzNuyGnb4VcGSMcHDMaaRBQixMG+c3zMJYeNEwAofzoQf9a5SuPI5Mgs3zh8b0y9TLgGNA7OmA3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887971; c=relaxed/simple; bh=22ZFcOSJb95wTMIMowmmrHcqZcVCP0h0ks/wawdpMVU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ju1lWU7r+U7r79t62D2rkLiPs1dRSUPcXd+jyr9xxEWUr82fr+QyZ3CfnGQqTIOCcXrYXFUKF7H2CZEPea4ulqNAKEadwS5KW04S8htC17G4hsIQjH9qhH4Jx+sb8G9q46Euei1+SCDqnK6o9TGc+ZvtBFNGESqzzEdxV9edYmA= 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=cZBwvlsn; 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="cZBwvlsn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887969; x=1762423969; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=22ZFcOSJb95wTMIMowmmrHcqZcVCP0h0ks/wawdpMVU=; b=cZBwvlsn///4bjxOjWujRBQqOGc5Fr7bcaCJhifwiM/bS9MZMBYEKW+i 4oa8jZV/FD7rWzwZ+YsrC5Ry4SLfqZ5MxMY5ZZ7WE4jItcePly766c+nr KajO17atQsHWBo1M3uJJftM0tmqjP42lV5Gg9gpKlhDAoLHgxiEPGFEse jHN6vJTxky7nxLqMeEnTFo4biL6tu7O1ze15bsjdGeNWIeK7CyW+sdpPR 8pP8g51lcOajAbB8mvPRNjQVFsKFP5BUQSwwmONOmF//EDjMT4sQ+NkvW xdEl7N9y6emhOK2WcTAL63nGlUC7Pt3axHFFqNyaxX/TgeACDz/dwxTd5 w==; X-CSE-ConnectionGUID: c0jXKY5sRsOaXV2hjYllWQ== X-CSE-MsgGUID: XPv8DXHIRAS4U7yK0XC4Lg== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059371" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059371" 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:49 -0800 X-CSE-ConnectionGUID: DMUtuaEqQjyfP5KUKTX0Xw== X-CSE-MsgGUID: //OzX9ujS36NBS0SK+V0iQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84812924" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:12:48 -0800 From: Mathias Nyman To: Cc: , Michal Pecio , Mathias Nyman Subject: [PATCH 02/33] usb: xhci: Remove unused parameters of next_trb() Date: Wed, 6 Nov 2024 12:14:28 +0200 Message-Id: <20241106101459.775897-3-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 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 Signed-off-by: Mathias Nyman --- 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 9f1e150a1c76..36ccf0dac7fa 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); } } @@ -2273,7 +2271,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 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) { From patchwork Wed Nov 6 10:14:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842352 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 4285F1DD531 for ; Wed, 6 Nov 2024 10:12:52 +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=1730887973; cv=none; b=bHn16d7cKzJpraTOclG8H6Rqc1RsQrJ5rZJlPLTcMc6+RXu8EES8F4PGka1kmqYtCzmPdm01m139Z2xS7Tj1kIbBudlyE2m0gcUCeMI1JaXgVsIYgl72+oW4acxZEb+KxPpsZdEPFw3rblRCmkez2BhlIDIXPGw8/5Pd+iYVkZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887973; c=relaxed/simple; bh=ugcV9trVXr0xSoK4Y+Bo2jHXVMHPVs76YmT75mcQFmQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aJdlxPozm71KXsGJ55f1vpguODKpKnR9SUokwlMMlhdsttA4bqokvR5TlS9Rel/OzsFWjzwNyfeRkYaCcrrzOSVLXTzlEuDFgcnPTC9L/aityZoyggeLGsE+YfP43Mi6zyvARCMw7UlcI0ddKrLC4UxvQS/QDsn0LxM3My5QDR4= 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=RsImwQUe; 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="RsImwQUe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887972; x=1762423972; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ugcV9trVXr0xSoK4Y+Bo2jHXVMHPVs76YmT75mcQFmQ=; b=RsImwQUeccZJOqy22jB2/+ciKLNJL4JAnkPrE4l/cHwUj3e1bb4lVWBu oG7B0FVylhTYoDd7tfwBdwd+hZhEjvUshIxdoTo1NPk8FvdHOnfTbgLhr XUV4ZFAJZusSVOOssKbOMtDUoUOTExGBnydeFF3fpET/g7EVnvgfcSgCQ 3vHGXAKhTRAnQZiHM9C4LVxKDeJKPnshz6k4nFWjbaM3P0vb6rmfh3+qK 0ilWHUYBUWULR2AHO1xmyRGrG0pf1WAspnSgE0k+4XbPu329bsA2/8d2K 5jE6bby2yQyT1jIshF1ztpXhjkzkiMgzO0cOCJe+rqfXg8Lp1oVCVydyx w==; X-CSE-ConnectionGUID: 2EsLOmM6T7edIo8G9x4OFQ== X-CSE-MsgGUID: jmD2WuVbR5SA0HvxIaNeVw== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059380" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059380" 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:52 -0800 X-CSE-ConnectionGUID: HnxxGNZRQNOx4FTC0xTFEw== X-CSE-MsgGUID: zfIkgSd5SQir2s3XfdwQmQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84812946" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:12:51 -0800 From: Mathias Nyman To: Cc: , Mathias Nyman , Andy Shevchenko Subject: [PATCH 04/33] xhci: Cleanup Candence controller PCI device and vendor ID usage Date: Wed, 6 Nov 2024 12:14:30 +0200 Message-Id: <20241106101459.775897-5-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 Use predefined PCI vendor ID constant for Cadence controller in pci_ids.h Rename the Candence device ID to match the pattern other PCI vendor and device IDs use Reported-by: Andy Shevchenko Closes: https://lore.kernel.org/linux-usb/ZuMOfHp9j_6_3-WC@surfacebook.localdomain Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-pci.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 8c4f3e7507ba..7803ff1f1c9f 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -82,8 +82,7 @@ #define PCI_DEVICE_ID_ASMEDIA_3042_XHCI 0x3042 #define PCI_DEVICE_ID_ASMEDIA_3242_XHCI 0x3242 -#define PCI_DEVICE_ID_CADENCE 0x17CD -#define PCI_DEVICE_ID_CADENCE_SSP 0x0200 +#define PCI_DEVICE_ID_CDNS_SSP 0x0200 static const char hcd_name[] = "xhci_hcd"; @@ -481,9 +480,8 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) if (pdev->device == 0x9203) xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH; } - - if (pdev->vendor == PCI_DEVICE_ID_CADENCE && - pdev->device == PCI_DEVICE_ID_CADENCE_SSP) + if (pdev->vendor == PCI_VENDOR_ID_CDNS && + pdev->device == PCI_DEVICE_ID_CDNS_SSP) xhci->quirks |= XHCI_CDNS_SCTX_QUIRK; /* xHC spec requires PCI devices to support D3hot and D3cold */ From patchwork Wed Nov 6 10:14: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: 841353 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 99B071D5CFA for ; Wed, 6 Nov 2024 10:12:53 +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=1730887975; cv=none; b=tDlEZPgJ6r+AuG5kDQt8cKptQ8bcI++48R4YsAbp6p8ubaEc/IIsZMUUrZAmTM4o/iv99I/cWO28E/wEudUTc2YTaN5zXRvbt2cUtbFkpp18F1usnOu3jCAYAWA7VLNFZUwJR1Urol8V47UEEMTbuZAq8iLm2yoCG5FmiJO/3aQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887975; c=relaxed/simple; bh=YwNTSmCBJIhCKRvabu2AlIea+OD0lW7NV+J3yN/BtBs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MX2AQCHC3o7wMvCDJpV1HTOVgce0yP6PGlTHCkv3VSLxH9wvR7E3shVaXIVnLszBAJ6moE+t0wf28jO8SzdEjjVCYe3B1uZevHa3C2IhRQQ3nZ1pVB+itGx0fjfC+9WTgcmqaT1Y9GeIEpKzJ9LBiel5QOpdt+UUd1YLBM5sGyQ= 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=mRq83RB5; 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="mRq83RB5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887973; x=1762423973; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YwNTSmCBJIhCKRvabu2AlIea+OD0lW7NV+J3yN/BtBs=; b=mRq83RB5VazYVgfqFZqKNHPiR1EwbTqeoB/Zya9OSlj9dOZYjU5jnIcJ Op4LzhOt0bchlOXPaw5twciwxQvhoua5ARmeh4FpFrFMJx5Twal48siC5 A7MtqEVSR2njuY1zkuhNcA3k02OFUmCbNFJ0sSrw/G3JZvxl7vYoeNtqs MwXLY1wkNJV/w3heMc6o6wNxjEsXBF+MICccsltyprVnnD8Vp+WHCjOPd 71PzTUyDTioRvUIYf/qm9uprYEtVcgjtcPxH3Yx4/sh+XLeKqXI5RumL0 nfH2lHnRK+s0bRbTXYRTmMDYfhC9uIYPvr91DJjVMBUAAy15iWwq3USls A==; X-CSE-ConnectionGUID: nWGK4roaQHSce3D/MzpTYw== X-CSE-MsgGUID: vSTSnYfqSRCpNGLJrYMkuQ== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059383" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059383" 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:53 -0800 X-CSE-ConnectionGUID: WbDlIzZQQD6QCul+r28TdA== X-CSE-MsgGUID: VXQC7AqiSOyITEFSKVHPAw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84812955" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:12:52 -0800 From: Mathias Nyman To: Cc: , Mathias Nyman Subject: [PATCH 05/33] xhci: show DMA address of TRB when tracing TRBs Date: Wed, 6 Nov 2024 12:14:31 +0200 Message-Id: <20241106101459.775897-6-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 The DMA address of a queued TRB is essential when looking at traces as both transfer events and command completion events refer to the command or transfer based on its DMA address. Previously the TRB address was figured out from xhci_inc_enq and xhci_inc_deq trace entries seen after queuing or handlong a TRB. Now that DMA address is shown in TRB tracing we can get rid of most of the xhci_inc_enq and xhci_inc_deq traces thus decreasing trace size. Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-dbgcap.c | 11 ++++++---- drivers/usb/host/xhci-ring.c | 11 ++++++---- drivers/usb/host/xhci-trace.h | 38 +++++++++++++++++++--------------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c index 241d7aa1fbc2..408082372be1 100644 --- a/drivers/usb/host/xhci-dbgcap.c +++ b/drivers/usb/host/xhci-dbgcap.c @@ -248,8 +248,9 @@ xhci_dbc_queue_trb(struct xhci_ring *ring, u32 field1, trb->generic.field[2] = cpu_to_le32(field3); trb->generic.field[3] = cpu_to_le32(field4); - trace_xhci_dbc_gadget_ep_queue(ring, &trb->generic); - + trace_xhci_dbc_gadget_ep_queue(ring, &trb->generic, + xhci_trb_virt_to_dma(ring->enq_seg, + ring->enqueue)); ring->num_trbs_free--; next = ++(ring->enqueue); if (TRB_TYPE_LINK_LE32(next->link.control)) { @@ -747,7 +748,7 @@ static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event) return; } - trace_xhci_dbc_handle_transfer(ring, &req->trb->generic); + trace_xhci_dbc_handle_transfer(ring, &req->trb->generic, req->trb_dma); switch (comp_code) { case COMP_SUCCESS: @@ -898,7 +899,9 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc) */ rmb(); - trace_xhci_dbc_handle_event(dbc->ring_evt, &evt->generic); + trace_xhci_dbc_handle_event(dbc->ring_evt, &evt->generic, + xhci_trb_virt_to_dma(dbc->ring_evt->deq_seg, + dbc->ring_evt->dequeue)); switch (le32_to_cpu(evt->event_cmd.flags) & TRB_TYPE_BITMASK) { case TRB_TYPE(TRB_PORT_STATUS): diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index f1176c270c43..3c19f58fcefd 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1714,7 +1714,7 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, cmd_dma = le64_to_cpu(event->cmd_trb); cmd_trb = xhci->cmd_ring->dequeue; - trace_xhci_handle_command(xhci->cmd_ring, &cmd_trb->generic); + trace_xhci_handle_command(xhci->cmd_ring, &cmd_trb->generic, cmd_dma); cmd_comp_code = GET_COMP_CODE(le32_to_cpu(event->status)); @@ -2886,7 +2886,7 @@ static int handle_tx_event(struct xhci_hcd *xhci, ep_ring->last_td_was_short = false; 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); + trace_xhci_handle_transfer(ep_ring, (struct xhci_generic_trb *) ep_trb, ep_trb_dma); /* * No-op TRB could trigger interrupts in a case where a URB was killed @@ -2936,7 +2936,9 @@ static int xhci_handle_event_trb(struct xhci_hcd *xhci, struct xhci_interrupter { u32 trb_type; - trace_xhci_handle_event(ir->event_ring, &event->generic); + trace_xhci_handle_event(ir->event_ring, &event->generic, + xhci_trb_virt_to_dma(ir->event_ring->deq_seg, + ir->event_ring->dequeue)); /* * Barrier between reading the TRB_CYCLE (valid) flag before, and any @@ -3159,7 +3161,8 @@ static void queue_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, wmb(); trb->field[3] = cpu_to_le32(field4); - trace_xhci_queue_trb(ring, trb); + trace_xhci_queue_trb(ring, trb, + xhci_trb_virt_to_dma(ring->enq_seg, ring->enqueue)); inc_enq(xhci, ring, more_trbs_coming); } diff --git a/drivers/usb/host/xhci-trace.h b/drivers/usb/host/xhci-trace.h index 24405315ffe6..cc916e58a329 100644 --- a/drivers/usb/host/xhci-trace.h +++ b/drivers/usb/host/xhci-trace.h @@ -108,9 +108,10 @@ DEFINE_EVENT(xhci_log_ctx, xhci_address_ctx, ); DECLARE_EVENT_CLASS(xhci_log_trb, - TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb), - TP_ARGS(ring, trb), + TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb, dma_addr_t dma), + TP_ARGS(ring, trb, dma), TP_STRUCT__entry( + __field(dma_addr_t, dma) __field(u32, type) __field(u32, field0) __field(u32, field1) @@ -118,51 +119,54 @@ DECLARE_EVENT_CLASS(xhci_log_trb, __field(u32, field3) ), TP_fast_assign( + __entry->dma = dma; __entry->type = ring->type; __entry->field0 = le32_to_cpu(trb->field[0]); __entry->field1 = le32_to_cpu(trb->field[1]); __entry->field2 = le32_to_cpu(trb->field[2]); __entry->field3 = le32_to_cpu(trb->field[3]); ), - TP_printk("%s: %s", xhci_ring_type_string(__entry->type), + TP_printk("%s: @%pad %s", + xhci_ring_type_string(__entry->type), &__entry->dma, xhci_decode_trb(__get_buf(XHCI_MSG_MAX), XHCI_MSG_MAX, __entry->field0, __entry->field1, __entry->field2, __entry->field3) ) ); DEFINE_EVENT(xhci_log_trb, xhci_handle_event, - TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb), - TP_ARGS(ring, trb) + TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb, dma_addr_t dma), + TP_ARGS(ring, trb, dma) ); DEFINE_EVENT(xhci_log_trb, xhci_handle_command, - TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb), - TP_ARGS(ring, trb) + TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb, dma_addr_t dma), + TP_ARGS(ring, trb, dma) ); DEFINE_EVENT(xhci_log_trb, xhci_handle_transfer, - TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb), - TP_ARGS(ring, trb) + TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb, dma_addr_t dma), + TP_ARGS(ring, trb, dma) ); DEFINE_EVENT(xhci_log_trb, xhci_queue_trb, - TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb), - TP_ARGS(ring, trb) + TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb, dma_addr_t dma), + TP_ARGS(ring, trb, dma) + ); DEFINE_EVENT(xhci_log_trb, xhci_dbc_handle_event, - TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb), - TP_ARGS(ring, trb) + TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb, dma_addr_t dma), + TP_ARGS(ring, trb, dma) ); DEFINE_EVENT(xhci_log_trb, xhci_dbc_handle_transfer, - TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb), - TP_ARGS(ring, trb) + TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb, dma_addr_t dma), + TP_ARGS(ring, trb, dma) ); DEFINE_EVENT(xhci_log_trb, xhci_dbc_gadget_ep_queue, - TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb), - TP_ARGS(ring, trb) + TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb, dma_addr_t dma), + TP_ARGS(ring, trb, dma) ); DECLARE_EVENT_CLASS(xhci_log_free_virt_dev, From patchwork Wed Nov 6 10:14:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842351 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 EA5E41DD0DB for ; Wed, 6 Nov 2024 10:12:54 +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=1730887976; cv=none; b=YqlMfsLoyMmkmJloTgfpsuyf78bZu4e/AU9ryFV9Tz9jx9xCrvZFgpHggcxXacACWBFCbOYHR8GWvwJlNgfs5YMiWg5/lLSOXaS4QZT+h7+qT4Ym95+w2gT3+Q0Fwce0FRue4uKyklL5QpRwjFfFHdPyakd8viSec+kd2QV6QHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887976; c=relaxed/simple; bh=JoQ1CBEaiqezRi7Pl4xsz42mS/3FJZnELzXTpLU1uDc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Gm5rloRivEXzNlvLfHJ5f+Yj4TZRCebMXzWix6LcKaFx6iVF8c4+eiZtlDIjqw/SyllvYd3+7hD6EiaiOnSUgC96NJRGpCqMUAmShrkDhN9R6B+UgeIzZABHfD3PLgIL3DAJa0IlcuLV+7dgQ9kvGL2ZoXfH9Fxb3wJ4D07bnJw= 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=LwH2CkfB; 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="LwH2CkfB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887975; x=1762423975; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JoQ1CBEaiqezRi7Pl4xsz42mS/3FJZnELzXTpLU1uDc=; b=LwH2CkfBptBLzlWFRCTcj69t0BBFjCBIJh33iX393TqFQVEczXKpwV2L Byb4WR7nDlG2NzrHZV4eQ3HaAXdQqoEupzxlBVO+mrQMxUUlSe/VAbJwS A9iMUtIa/9ZagOYAkrhoYY/GGL10yCFZC58R+d3QqNTGsQB2CwPp7S96z 2TEdqh09Marde4uXRG2FWS/roN8pufeJobTmLxqG/I2IuiEFLALlt/J1f hPsN30tzNSZy43Xlet29vay49XYsGVeDb26ny9c7HiJBgLMAMfcsm623z prT2lRYDGmAfADRuFhRuRhjJ3kl9w6alqusOD+PbGRWyQDh67kiZFln7R w==; X-CSE-ConnectionGUID: PykhPBP5QpCZAXQY8Ixcxg== X-CSE-MsgGUID: 42ZLOJXaSqSzAXAoGFdxIQ== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059385" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059385" 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:54 -0800 X-CSE-ConnectionGUID: i1huEtcjSHOBu0sEw1Zm0g== X-CSE-MsgGUID: 08FuPZ0ISmuhHcnGHGuTlg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84812979" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:12:54 -0800 From: Mathias Nyman To: Cc: , Mathias Nyman Subject: [PATCH 06/33] xhci: Don't trace ring at every enqueue or dequeue increase Date: Wed, 6 Nov 2024 12:14:32 +0200 Message-Id: <20241106101459.775897-7-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 Don't trace ring pointers every time driver increases enqueue pointer after queuing a TRB, or dequeue pointer after handling an event. These xhci_inc_deq: and xhci_inc_enq: trace entries fill up the trace and provides little useful info now that the TRB DMA address is printed with the TRB itself. Only trace ring during xhci_inc_enq() and xhci_inc_deq() in case we move to a new ring segment. Also don't show both segment and TRB addess in trace. Segment is just TRB with 0xfff masked off. Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 16 +++++++++------- drivers/usb/host/xhci-trace.h | 10 +++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 3c19f58fcefd..f7f7b0a818f8 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -167,13 +167,16 @@ void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring) if (ring->type == TYPE_EVENT) { if (!last_trb_on_seg(ring->deq_seg, ring->dequeue)) { ring->dequeue++; - goto out; + return; } if (last_trb_on_ring(ring, ring->deq_seg, ring->dequeue)) ring->cycle_state ^= 1; ring->deq_seg = ring->deq_seg->next; ring->dequeue = ring->deq_seg->trbs; - goto out; + + trace_xhci_inc_deq(ring); + + return; } /* All other rings have link trbs */ @@ -188,14 +191,13 @@ void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring) ring->deq_seg = ring->deq_seg->next; ring->dequeue = ring->deq_seg->trbs; + trace_xhci_inc_deq(ring); + if (link_trb_count++ > ring->num_segs) { xhci_warn(xhci, "Ring is an endless link TRB loop\n"); break; } } -out: - trace_xhci_inc_deq(ring); - return; } @@ -264,13 +266,13 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, ring->enqueue = ring->enq_seg->trbs; next = ring->enqueue; + trace_xhci_inc_enq(ring); + if (link_trb_count++ > ring->num_segs) { xhci_warn(xhci, "%s: Ring link TRB loop\n", __func__); break; } } - - trace_xhci_inc_enq(ring); } /* diff --git a/drivers/usb/host/xhci-trace.h b/drivers/usb/host/xhci-trace.h index cc916e58a329..57b8cb5a8d19 100644 --- a/drivers/usb/host/xhci-trace.h +++ b/drivers/usb/host/xhci-trace.h @@ -458,8 +458,6 @@ DECLARE_EVENT_CLASS(xhci_log_ring, __field(void *, ring) __field(dma_addr_t, enq) __field(dma_addr_t, deq) - __field(dma_addr_t, enq_seg) - __field(dma_addr_t, deq_seg) __field(unsigned int, num_segs) __field(unsigned int, stream_id) __field(unsigned int, cycle_state) @@ -470,17 +468,15 @@ DECLARE_EVENT_CLASS(xhci_log_ring, __entry->type = ring->type; __entry->num_segs = ring->num_segs; __entry->stream_id = ring->stream_id; - __entry->enq_seg = ring->enq_seg->dma; - __entry->deq_seg = ring->deq_seg->dma; __entry->cycle_state = ring->cycle_state; __entry->bounce_buf_len = ring->bounce_buf_len; __entry->enq = xhci_trb_virt_to_dma(ring->enq_seg, ring->enqueue); __entry->deq = xhci_trb_virt_to_dma(ring->deq_seg, ring->dequeue); ), - TP_printk("%s %p: enq %pad(%pad) deq %pad(%pad) segs %d stream %d bounce %d cycle %d", + TP_printk("%s %p: enq %pad deq %pad segs %d stream %d bounce %d cycle %d", xhci_ring_type_string(__entry->type), __entry->ring, - &__entry->enq, &__entry->enq_seg, - &__entry->deq, &__entry->deq_seg, + &__entry->enq, + &__entry->deq, __entry->num_segs, __entry->stream_id, __entry->bounce_buf_len, From patchwork Wed Nov 6 10:14: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: 841352 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 8F5201D5CFA for ; Wed, 6 Nov 2024 10:12:56 +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=1730887978; cv=none; b=BpKb+DWi6v/E5iaMM/+XLkgrBRZ5m6GKSSbm7O7feLANj3I8NIw+qe+pzs3yiEAhucs+JbF1Yj+GMu8F4wwrwdHOWdcACJiM4xlGP+c2EbDkaArOtQs3ctsc5TGoIZdHQ3cXC2UwN2hvbCCqbu9G0Vq5CCFZrlDYbFmw6IBBUrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887978; c=relaxed/simple; bh=ZjxwuchpkyrJ0+rosThp0q94ZW/u8yk0ApMkmTjeAHE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uiVYcP+0UKhAZKUyE2qrmTmEBdLZrayxZZL9y9lAYL8cJX3g1IztLLiYMy4UZI2oFhFOR6kLbTCOgxplmSXm8lQgRaoEgkrR4MJwTybNn00t7XRTwIxFxcXPIckjvdkznAll8ibvCC/afT41DD4G/rLi6HefPBpX9PHhVWP2VBU= 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=S4mR7UTB; 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="S4mR7UTB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887976; x=1762423976; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZjxwuchpkyrJ0+rosThp0q94ZW/u8yk0ApMkmTjeAHE=; b=S4mR7UTB1bctm4PftP8u0eN3CxghALMFVVWDCR7SupgFO0FTZFO1oPuM lf3wP2rNaW8QGOUyP+AJlwzYDucPN7ySLFfG307Q5wLoghxgK9FPMqZ3t AFajOFiYLQxJ2/QMRZNFL75o8hEDXj2gyuX12DQ3daIKud+Ke5TjuoRvv +93hahCebGAw9n50MQZzgnWEO0CKk+TMIiM5wk+jCXZi3czq7bOgN1q3i sgV89Kr1+kbrBM1Q7j3ohC1nZeezTZ28rEtbBJlD7jha5BZCfade3NCJR GDtSV9neTXeYvyuRXbHDYOYKmx0TjufbRnUnyv9Hj+4wGIQw69g3K2xbf A==; X-CSE-ConnectionGUID: OcRwd6TASA+o0+5H/QDGWw== X-CSE-MsgGUID: s1ZPVyb0SpaULht2QYAsVA== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059388" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059388" 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:56 -0800 X-CSE-ConnectionGUID: vLsHOjDeTR6kkwBBSJA0Qw== X-CSE-MsgGUID: XIsSwVkYSqatqdQOI+y2BQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84812996" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:12:55 -0800 From: Mathias Nyman To: Cc: , Mathias Nyman Subject: [PATCH 07/33] xhci: add stream context tracing Date: Wed, 6 Nov 2024 12:14:33 +0200 Message-Id: <20241106101459.775897-8-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 Show stream id, stream context type (SCT), ring dequeue pointer and the DMA address of the stream context during stream allocation Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 2 ++ drivers/usb/host/xhci-trace.h | 26 ++++++++++++++++++++++++++ drivers/usb/host/xhci.h | 1 + 3 files changed, 29 insertions(+) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index d2900197a49e..2952737ccf6c 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -658,6 +658,8 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci, xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n", cur_stream, addr); ret = xhci_update_stream_mapping(cur_ring, mem_flags); + + trace_xhci_alloc_stream_info_ctx(stream_info, cur_stream); if (ret) { xhci_ring_free(xhci, cur_ring); stream_info->stream_rings[cur_stream] = NULL; diff --git a/drivers/usb/host/xhci-trace.h b/drivers/usb/host/xhci-trace.h index 57b8cb5a8d19..56af9f62916a 100644 --- a/drivers/usb/host/xhci-trace.h +++ b/drivers/usb/host/xhci-trace.h @@ -314,6 +314,32 @@ DEFINE_EVENT(xhci_log_urb, xhci_urb_dequeue, TP_ARGS(urb) ); +DECLARE_EVENT_CLASS(xhci_log_stream_ctx, + TP_PROTO(struct xhci_stream_info *info, unsigned int stream_id), + TP_ARGS(info, stream_id), + TP_STRUCT__entry( + __field(unsigned int, stream_id) + __field(u64, stream_ring) + __field(dma_addr_t, ctx_array_dma) + + ), + TP_fast_assign( + __entry->stream_id = stream_id; + __entry->stream_ring = le64_to_cpu(info->stream_ctx_array[stream_id].stream_ring); + __entry->ctx_array_dma = info->ctx_array_dma + stream_id * 16; + + ), + TP_printk("stream %u ctx @%pad: SCT %llu deq %llx", __entry->stream_id, + &__entry->ctx_array_dma, CTX_TO_SCT(__entry->stream_ring), + __entry->stream_ring + ) +); + +DEFINE_EVENT(xhci_log_stream_ctx, xhci_alloc_stream_info_ctx, + TP_PROTO(struct xhci_stream_info *info, unsigned int stream_id), + TP_ARGS(info, stream_id) +); + DECLARE_EVENT_CLASS(xhci_log_ep_ctx, TP_PROTO(struct xhci_ep_ctx *ctx), TP_ARGS(ctx), diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 7d81645c2c5d..89337562440b 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -554,6 +554,7 @@ struct xhci_stream_ctx { /* Stream Context Types (section 6.4.1) - bits 3:1 of stream ctx deq ptr */ #define SCT_FOR_CTX(p) (((p) & 0x7) << 1) +#define CTX_TO_SCT(p) (((p) >> 1) & 0x7) /* Secondary stream array type, dequeue pointer is to a transfer ring */ #define SCT_SEC_TR 0 /* Primary stream array type, dequeue pointer is to a transfer ring */ From patchwork Wed Nov 6 10:14:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842350 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 E615C1DD0DB for ; Wed, 6 Nov 2024 10:12:57 +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=1730887979; cv=none; b=UrXuk5ULldcBh7eFFPbAo4wyU+bxXz1HlJTd2vUrgswTm8b6GaZn2bdsz1ePnZIm4amepP8LaiYYwk8Oe0gL4ijENtvWNrfXCotyxk3TUoLb4m4+7eLpqJS80fPk/5QkoNjGAtj1c4hCjuIe5tO0m6HuzM5UdVi0ef42K8K8zK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887979; c=relaxed/simple; bh=0HRU4ebVOzXiw313wa1hJ4NXWXbf/A89Ao6sD6Y9JZc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aR5iV39q17CzfQ31VsG7tqX130GFULWA3Q0TXgm5H0zc9IX/3CT77wSuRI7aThYCJ2jXl7aj+EmtFF2d4vA2JxnBWecrj/Prjnr+KnNLS1euMyhyALKeUl6MDoXO4dtD2Gfnbj89/g6PFEqwNHKJgcPLFaNNCpaIMq+UlH1K0zY= 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=YB6QnTUL; 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="YB6QnTUL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887978; x=1762423978; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0HRU4ebVOzXiw313wa1hJ4NXWXbf/A89Ao6sD6Y9JZc=; b=YB6QnTULz4cXxyTEin339JFHccqp0LeEfSJOOooB6Wrp072TOmtDL7KF oVbiPplxIAH3A5yX7qCQKWiWU05McbB6WzuW7JueVvHvdGCbK7mdmZsxc F76T85qRYLQdU/uZkvIUz64tKSIqeKJGZdFrw/GjS1IG/YyiQpLqUoioB qZYPngprkU/alv5L1BqLtISrAevcW/9DsmLDPuSvHp0g2phiGazd9b1Wg iYqqErAL068EPSXlyXdNPGwyHmidu8Z1Wmt3Y2eaNhYPOVMTRstMTj1Qk A8RIcpUC5U2rf65lLgP2yPoaD8aqaBA7eDMn20wgY1+EgJv7w+T2VG22k g==; X-CSE-ConnectionGUID: n9QZKmEdTEeGCKRYHULiow== X-CSE-MsgGUID: pQkLmxSvQDmtT3IcLussHg== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059390" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059390" 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:57 -0800 X-CSE-ConnectionGUID: NYA3FsnqRTu/0Ldm/5c1TA== X-CSE-MsgGUID: 50ySrZ25QNKh2Hp+w8ZIbg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813018" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:12:57 -0800 From: Mathias Nyman To: Cc: , Mathias Nyman Subject: [PATCH 08/33] xhci: trace stream context at Set TR Deq command completion Date: Wed, 6 Nov 2024 12:14:34 +0200 Message-Id: <20241106101459.775897-9-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 A successful 'Set TR Deq' command writes a new dequeue pointer to the stream context for stream rings, show the content of the stream ctx at command completion. Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 14 +++++++++----- drivers/usb/host/xhci-trace.h | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index f7f7b0a818f8..f62b243d0fc4 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1338,6 +1338,7 @@ static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, struct xhci_virt_ep *ep; struct xhci_ep_ctx *ep_ctx; struct xhci_slot_ctx *slot_ctx; + struct xhci_stream_ctx *stream_ctx; struct xhci_td *td, *tmp_td; bool deferred = false; @@ -1360,6 +1361,11 @@ static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, trace_xhci_handle_cmd_set_deq(slot_ctx); trace_xhci_handle_cmd_set_deq_ep(ep_ctx); + if (ep->ep_state & EP_HAS_STREAMS) { + stream_ctx = &ep->stream_info->stream_ctx_array[stream_id]; + trace_xhci_handle_cmd_set_deq_stream(ep->stream_info, stream_id); + } + if (cmd_comp_code != COMP_SUCCESS) { unsigned int ep_state; unsigned int slot_state; @@ -1396,9 +1402,7 @@ static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, u64 deq; /* 4.6.10 deq ptr is written to the stream ctx for streams */ if (ep->ep_state & EP_HAS_STREAMS) { - struct xhci_stream_ctx *ctx = - &ep->stream_info->stream_ctx_array[stream_id]; - deq = le64_to_cpu(ctx->stream_ring) & SCTX_DEQ_MASK; + deq = le64_to_cpu(stream_ctx->stream_ring) & SCTX_DEQ_MASK; /* * Cadence xHCI controllers store some endpoint state @@ -1410,8 +1414,8 @@ static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, * To fix this issue driver must clear Rsvd0 field. */ if (xhci->quirks & XHCI_CDNS_SCTX_QUIRK) { - ctx->reserved[0] = 0; - ctx->reserved[1] = 0; + stream_ctx->reserved[0] = 0; + stream_ctx->reserved[1] = 0; } } else { deq = le64_to_cpu(ep_ctx->deq) & ~EP_CTX_CYCLE_MASK; diff --git a/drivers/usb/host/xhci-trace.h b/drivers/usb/host/xhci-trace.h index 56af9f62916a..bfb5c5c17012 100644 --- a/drivers/usb/host/xhci-trace.h +++ b/drivers/usb/host/xhci-trace.h @@ -340,6 +340,11 @@ DEFINE_EVENT(xhci_log_stream_ctx, xhci_alloc_stream_info_ctx, TP_ARGS(info, stream_id) ); +DEFINE_EVENT(xhci_log_stream_ctx, xhci_handle_cmd_set_deq_stream, + TP_PROTO(struct xhci_stream_info *info, unsigned int stream_id), + TP_ARGS(info, stream_id) +); + DECLARE_EVENT_CLASS(xhci_log_ep_ctx, TP_PROTO(struct xhci_ep_ctx *ctx), TP_ARGS(ctx), From patchwork Wed Nov 6 10:14: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: 841351 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 6E6881DD0DB for ; Wed, 6 Nov 2024 10:13:00 +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=1730887981; cv=none; b=RrP/2yyVG/FCxbYE/mYuvYdfImW8VcB8nQ4oeGECFb0rHfrPkVkeGF9tVQNFaDBIoqa/q8VdaC/ayOLQuVnQYBgneGN6ANf1p+CMDjizB0w6XF6n4jQmqM6E+r+uZgZrcIM40VoG/OONVfNo2VlrQ21mgPAAqNym9jE6EbZQX5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887981; c=relaxed/simple; bh=2Z/Ahek/DrgotZ6pVoDttPtts1yWkjqZF/PbnwlMHNA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UtjBOGwlaLF6fqewaAGMPZ4v3CihRRoDHJBWjRgq0HCp4sDBL2NJ5W58Yu7+VDUYgUYCpNm0zkOq6aOePiJcuv17LiqCBu1zAqluSL0d8lMclOQAziRuiIq+8yuz31GyH2tf7FpXLRkyqCIgkLAbk/npcga/5TRIGXKQHL4hSys= 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=KJYUVk5E; 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="KJYUVk5E" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887980; x=1762423980; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2Z/Ahek/DrgotZ6pVoDttPtts1yWkjqZF/PbnwlMHNA=; b=KJYUVk5EL0YIRZ2kxfJ82zDddSdbcjTQ9TPpVBGE0NZopZXmVAksI5E7 G0sYdNeWFqno3r1ynEuVqUcd/n896BfTH6mGzQ3DoyYqlYc+8iQUTyB5s 7kI7dVB+EuNcKWb2pb81MQmdVMLophf93iowZ8WxQFOG+XbfeKvjIp/Au +t4YVXMPHs0dng/BFbGDWD1OEkpn9Q1NOBQiGdqsA8fSn5K+eIs/22LSZ dulMeM21C8D41+Pfx3lMAAeV34ScOAZv/SHwFMgaFnp3iXAcBEZGcJmtQ WenLDro4qfBzpq8UvchFDBxGM2sXqMik5OVFQ25qbAvzRWX8qfwJPwv/r Q==; X-CSE-ConnectionGUID: 8QLu/AEXR/aZEW0ZhoascQ== X-CSE-MsgGUID: wu+3jGE4R52NIbEG+I4P0g== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059392" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059392" 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:59 -0800 X-CSE-ConnectionGUID: T6U4wM4uQsq9SBqAbyFsMA== X-CSE-MsgGUID: Rv64L2I4TwWuFQeNYYjRhQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813048" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:12:58 -0800 From: Mathias Nyman To: Cc: , WangYuli , Xu Rao , Mathias Nyman Subject: [PATCH 09/33] xhci: debugfs: Add virt endpoint state to xhci debugfs Date: Wed, 6 Nov 2024 12:14:35 +0200 Message-Id: <20241106101459.775897-10-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: WangYuli The ring data structure of each xHCI endpoint might stop sending data due to the virt endpoint state. Show the virt endpoint state within the endpoint context via debugfs to facilitate debugging. Co-developed-by: Xu Rao Signed-off-by: Xu Rao Signed-off-by: WangYuli Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-debugfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c index f8ba15e7c225..35247cd50c74 100644 --- a/drivers/usb/host/xhci-debugfs.c +++ b/drivers/usb/host/xhci-debugfs.c @@ -291,12 +291,13 @@ static int xhci_endpoint_context_show(struct seq_file *s, void *unused) for (ep_index = 0; ep_index < 31; ep_index++) { ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); dma = dev->out_ctx->dma + (ep_index + 1) * CTX_SIZE(xhci->hcc_params); - seq_printf(s, "%pad: %s\n", &dma, + seq_printf(s, "%pad: %s, virt_state:%#x\n", &dma, xhci_decode_ep_context(str, le32_to_cpu(ep_ctx->ep_info), le32_to_cpu(ep_ctx->ep_info2), le64_to_cpu(ep_ctx->deq), - le32_to_cpu(ep_ctx->tx_info))); + le32_to_cpu(ep_ctx->tx_info)), + dev->eps[ep_index].ep_state); } return 0; From patchwork Wed Nov 6 10:14:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842349 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 042931DDA17 for ; Wed, 6 Nov 2024 10:13:01 +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=1730887983; cv=none; b=ONXq9D8JfRZe3/LwV8DSrigiRAJoSYADRRAZpO031j/sQZd+zp7EqiFOeMkR4IecscVJXrpAg6yADDujksxGGd5+4YUlrHbpLzJftgv+KbvINQs9b5nZuGfe9BWGECVlILPsW+lSR8jY1jHxyTlRNVbpCZczgnWpZ0quzAETyIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887983; c=relaxed/simple; bh=7FMZEg3rWBCfXHTP9nAeVFE261EGB/fafGgy/2IQiGo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MFqTjPYztBpYXWhJq5/kFPpTf3FX4IM/dk4q4q3oGJCTMhZRVP0SwvyuaGCT6tqKycLB2X56eibCIw4RdmYNps8qLb/e+aY1Hyub8kjqNjDZUJT47UKT7l8W31baPHTp6tumXXjpp9urbjllTl/79/5S+1yjkxBIoIBky0zdibE= 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=GLkBTL9b; 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="GLkBTL9b" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887982; x=1762423982; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7FMZEg3rWBCfXHTP9nAeVFE261EGB/fafGgy/2IQiGo=; b=GLkBTL9bnQ9p1Yd6voDSViy8jJVLe17IMUt0WzrlVD6FvQZzKzCa4kZ7 wDRcZQZZUm/7jN8W4BVbcEA2HYGlRnr+8ZCfH/4kRH4KKUkwXQJQGLP2l pboOOV3qSUfO0Qj2SpqjY2H2DfOqFqcE441T+dLD1CxlRtUpa5XgkyoBW IEAr6mnmPypfQS+acG+qC8ukAiOVVal4LnQARNqzCRv1IfBJYTT1ucWqt yyAmfROLxye/rab4Rzwzt4rPFK6GS86XOeyOjolNRnMnXiPSmntDmWqOR 88jWwM0rPt1wkxBEu29mATcs4busb/47aqG+rPJtfamsA1Rf1YRIfmthJ Q==; X-CSE-ConnectionGUID: D9t18XGJSCClnJLu4WVE5A== X-CSE-MsgGUID: 4sLacFaESo6wyg9hHhJW5g== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059396" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059396" 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:13:01 -0800 X-CSE-ConnectionGUID: rpJRtWNdSCe97A8v9svAOQ== X-CSE-MsgGUID: A9M8sLjpTmKUj+fbv6yKhg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813077" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:00 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Andy Shevchenko , Mathias Nyman Subject: [PATCH 10/33] usb: xhci: introduce macro for ring segment list iteration Date: Wed, 6 Nov 2024 12:14:36 +0200 Message-Id: <20241106101459.775897-11-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: Niklas Neronin Add macro to streamline and standardize the iteration over ring segment list. xhci_for_each_ring_seg(): Iterates over the entire ring segment list. The xhci_free_segments_for_ring() function's while loop has not been updated to use the new macro. This function has some underlying issues, and as a result, it will be handled separately in a future patch. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-debugfs.c | 5 +---- drivers/usb/host/xhci-mem.c | 24 +++++++----------------- drivers/usb/host/xhci.c | 20 ++++++++------------ drivers/usb/host/xhci.h | 3 +++ 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c index 35247cd50c74..4f0c1b96e208 100644 --- a/drivers/usb/host/xhci-debugfs.c +++ b/drivers/usb/host/xhci-debugfs.c @@ -214,14 +214,11 @@ static void xhci_ring_dump_segment(struct seq_file *s, static int xhci_ring_trb_show(struct seq_file *s, void *unused) { - int i; struct xhci_ring *ring = *(struct xhci_ring **)s->private; struct xhci_segment *seg = ring->first_seg; - for (i = 0; i < ring->num_segs; i++) { + xhci_for_each_ring_seg(ring->first_seg, seg) xhci_ring_dump_segment(s, seg); - seg = seg->next; - } return 0; } diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 2952737ccf6c..7aee76f846bc 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -224,7 +224,6 @@ static int xhci_update_stream_segment_mapping( struct radix_tree_root *trb_address_map, struct xhci_ring *ring, struct xhci_segment *first_seg, - struct xhci_segment *last_seg, gfp_t mem_flags) { struct xhci_segment *seg; @@ -234,28 +233,22 @@ static int xhci_update_stream_segment_mapping( if (WARN_ON_ONCE(trb_address_map == NULL)) return 0; - seg = first_seg; - do { + xhci_for_each_ring_seg(first_seg, seg) { ret = xhci_insert_segment_mapping(trb_address_map, ring, seg, mem_flags); if (ret) goto remove_streams; - if (seg == last_seg) - return 0; - seg = seg->next; - } while (seg != first_seg); + } return 0; remove_streams: failed_seg = seg; - seg = first_seg; - do { + xhci_for_each_ring_seg(first_seg, seg) { xhci_remove_segment_mapping(trb_address_map, seg); if (seg == failed_seg) return ret; - seg = seg->next; - } while (seg != first_seg); + } return ret; } @@ -267,17 +260,14 @@ static void xhci_remove_stream_mapping(struct xhci_ring *ring) if (WARN_ON_ONCE(ring->trb_address_map == NULL)) return; - seg = ring->first_seg; - do { + xhci_for_each_ring_seg(ring->first_seg, seg) xhci_remove_segment_mapping(ring->trb_address_map, seg); - seg = seg->next; - } while (seg != ring->first_seg); } static int xhci_update_stream_mapping(struct xhci_ring *ring, gfp_t mem_flags) { return xhci_update_stream_segment_mapping(ring->trb_address_map, ring, - ring->first_seg, ring->last_seg, mem_flags); + ring->first_seg, mem_flags); } /* XXX: Do we need the hcd structure in all these functions? */ @@ -438,7 +428,7 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring, if (ring->type == TYPE_STREAM) { ret = xhci_update_stream_segment_mapping(ring->trb_address_map, - ring, first, last, flags); + ring, first, flags); if (ret) goto free_segments; } diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index fdb1b71eeec2..44e4ae201048 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -40,15 +40,15 @@ MODULE_PARM_DESC(quirks, "Bit flags for quirks to be enabled as default"); static bool td_on_ring(struct xhci_td *td, struct xhci_ring *ring) { - struct xhci_segment *seg = ring->first_seg; + struct xhci_segment *seg; if (!td || !td->start_seg) return false; - do { + + xhci_for_each_ring_seg(ring->first_seg, seg) { if (seg == td->start_seg) return true; - seg = seg->next; - } while (seg && seg != ring->first_seg); + } return false; } @@ -785,14 +785,10 @@ static void xhci_clear_command_ring(struct xhci_hcd *xhci) struct xhci_segment *seg; ring = xhci->cmd_ring; - seg = ring->deq_seg; - do { - memset(seg->trbs, 0, - sizeof(union xhci_trb) * (TRBS_PER_SEGMENT - 1)); - seg->trbs[TRBS_PER_SEGMENT - 1].link.control &= - cpu_to_le32(~TRB_CYCLE); - seg = seg->next; - } while (seg != ring->deq_seg); + xhci_for_each_ring_seg(ring->deq_seg, seg) { + memset(seg->trbs, 0, sizeof(union xhci_trb) * (TRBS_PER_SEGMENT - 1)); + seg->trbs[TRBS_PER_SEGMENT - 1].link.control &= cpu_to_le32(~TRB_CYCLE); + } xhci_initialize_ring_info(ring, 1); /* diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 89337562440b..753d9343a4b1 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1263,6 +1263,9 @@ static inline const char *xhci_trb_type_string(u8 type) #define AVOID_BEI_INTERVAL_MIN 8 #define AVOID_BEI_INTERVAL_MAX 32 +#define xhci_for_each_ring_seg(head, seg) \ + for (seg = head; seg != NULL; seg = (seg->next != head ? seg->next : NULL)) + struct xhci_segment { union xhci_trb *trbs; /* private to HCD */ From patchwork Wed Nov 6 10:14:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 841350 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 49A7D1DD0DB for ; Wed, 6 Nov 2024 10:13:03 +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=1730887985; cv=none; b=L08Hd3H/cpY/eKrT+Xx5YsOkxJRW9XghWP8GfG7DLenqKlk4jOJQXcyG3wRr9UDUZOFTSSYErSCWBf5QSQAA1mtPh84GAeKVQcnf2ZFaeB29spAhePkwk35QN4l7L1kKgNVJeCXiu7XSfyxUFA9cR8lw0Ig7nNBfULEQhfjbwKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887985; c=relaxed/simple; bh=WC6/nf2BOGDDQjQsq4+ooBCWTTiErA2rmahR0Xf4ejg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Nll+hirTNbuhMq2YGGKsfBea4+HRMnAkucFOZwtQ8/FKUZEnMgb0KN/WYMIAox/CN6re8z0s4GNuRoYpgiVqJ26HqpcvmjA1VW2xD0PUrZH3G6qIkzF8TYBBSpOp+fNyM8xNnjY0vU5plB2gzi0c3U3IYoiKJXC4x2PQ44u83b8= 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=IZKfVfUR; 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="IZKfVfUR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887983; x=1762423983; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WC6/nf2BOGDDQjQsq4+ooBCWTTiErA2rmahR0Xf4ejg=; b=IZKfVfUR2/3rQDw+I3dVGNblqWC8zNIxTWkn2cF/Mc0I3fPK1ZWLAg9G MibUnN/5g3qEunZECoX+npzmWDiR+kF/kk7d8WTxyz8dq9Bzs0Cqob31p sjk+zP7SJFWP/cspTQOTJkIcgwMaqlTWUx2nTIdUBruWwSxrhIXDWDWQa PT4euOqp4JJUmROqeYTRigs9k2cIoCGt60S3aFNMCHaIrk73HTsTHPBVk MIyPhGAEENoAk4L9cG80m2ZrkiDOldcjOhgNk8CJMFqA9V5sssuAtlytM 0+8LZfGsweA6+koRbOF6bDh5vl/r3e9hrgLWZYTcwA2k5xyhmQFwq/WCx g==; X-CSE-ConnectionGUID: lEeRCUJ3RGKY4DTmU3Uf3g== X-CSE-MsgGUID: wZDmIvNrQnCf8Jdc/UfM+Q== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059398" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059398" 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:13:03 -0800 X-CSE-ConnectionGUID: H7gtMiElRZeHF/H/pWqS1g== X-CSE-MsgGUID: D5BwygplR+2SIUBtvyA+Jg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813101" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:02 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 11/33] usb: xhci: remove option to change a default ring's TRB cycle bit Date: Wed, 6 Nov 2024 12:14:37 +0200 Message-Id: <20241106101459.775897-12-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: Niklas Neronin The TRB cycle bit indicates TRB ownership by the Host Controller (HC) or Host Controller Driver (HCD). New rings are initialized with 'cycle_state' equal to one, and all its TRBs' cycle bits are set to zero. When handling ring expansion, set the source ring cycle bits to the same value as the destination ring. Move the cycle bit setting from xhci_segment_alloc() to xhci_link_rings(), and remove the 'cycle_state' argument from xhci_initialize_ring_info(). The xhci_segment_alloc() function uses kzalloc_node() to allocate segments, ensuring that all TRB cycle bits are initialized to zero. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-dbgcap.c | 2 +- drivers/usb/host/xhci-mem.c | 50 ++++++++++++++++------------------ drivers/usb/host/xhci.c | 2 +- drivers/usb/host/xhci.h | 6 ++-- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c index 408082372be1..227e513867dd 100644 --- a/drivers/usb/host/xhci-dbgcap.c +++ b/drivers/usb/host/xhci-dbgcap.c @@ -472,7 +472,7 @@ xhci_dbc_ring_alloc(struct device *dev, enum xhci_ring_type type, gfp_t flags) trb->link.control = cpu_to_le32(LINK_TOGGLE | TRB_TYPE(TRB_LINK)); } INIT_LIST_HEAD(&ring->td_list); - xhci_initialize_ring_info(ring, 1); + xhci_initialize_ring_info(ring); return ring; dma_fail: kfree(seg); diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 7aee76f846bc..164b22d0b475 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -27,14 +27,12 @@ * "All components of all Command and Transfer TRBs shall be initialized to '0'" */ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci, - unsigned int cycle_state, unsigned int max_packet, unsigned int num, gfp_t flags) { struct xhci_segment *seg; dma_addr_t dma; - int i; struct device *dev = xhci_to_hcd(xhci)->self.sysdev; seg = kzalloc_node(sizeof(*seg), flags, dev_to_node(dev)); @@ -56,11 +54,6 @@ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci, return NULL; } } - /* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */ - if (cycle_state == 0) { - for (i = 0; i < TRBS_PER_SEGMENT; i++) - seg->trbs[i].link.control = cpu_to_le32(TRB_CYCLE); - } seg->num = num; seg->dma = dma; seg->next = NULL; @@ -138,6 +131,14 @@ static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *ring, chain_links = xhci_link_chain_quirk(xhci, ring->type); + /* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */ + if (ring->cycle_state == 0) { + xhci_for_each_ring_seg(ring->first_seg, seg) { + for (int i = 0; i < TRBS_PER_SEGMENT; i++) + seg->trbs[i].link.control |= cpu_to_le32(TRB_CYCLE); + } + } + next = ring->enq_seg->next; xhci_link_segments(ring->enq_seg, first, ring->type, chain_links); xhci_link_segments(last, next, ring->type, chain_links); @@ -287,8 +288,7 @@ void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring) kfree(ring); } -void xhci_initialize_ring_info(struct xhci_ring *ring, - unsigned int cycle_state) +void xhci_initialize_ring_info(struct xhci_ring *ring) { /* The ring is empty, so the enqueue pointer == dequeue pointer */ ring->enqueue = ring->first_seg->trbs; @@ -302,7 +302,7 @@ void xhci_initialize_ring_info(struct xhci_ring *ring, * New rings are initialized with cycle state equal to 1; if we are * handling ring expansion, set the cycle state equal to the old ring. */ - ring->cycle_state = cycle_state; + ring->cycle_state = 1; /* * Each segment has a link TRB, and leave an extra TRB for SW @@ -317,7 +317,6 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, struct xhci_segment **first, struct xhci_segment **last, unsigned int num_segs, - unsigned int cycle_state, enum xhci_ring_type type, unsigned int max_packet, gfp_t flags) @@ -328,7 +327,7 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, chain_links = xhci_link_chain_quirk(xhci, type); - prev = xhci_segment_alloc(xhci, cycle_state, max_packet, num, flags); + prev = xhci_segment_alloc(xhci, max_packet, num, flags); if (!prev) return -ENOMEM; num++; @@ -337,8 +336,7 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, while (num < num_segs) { struct xhci_segment *next; - next = xhci_segment_alloc(xhci, cycle_state, max_packet, num, - flags); + next = xhci_segment_alloc(xhci, max_packet, num, flags); if (!next) goto free_segments; @@ -363,9 +361,8 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, * Set the end flag and the cycle toggle bit on the last segment. * See section 4.9.1 and figures 15 and 16. */ -struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, - unsigned int num_segs, unsigned int cycle_state, - enum xhci_ring_type type, unsigned int max_packet, gfp_t flags) +struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, unsigned int num_segs, + enum xhci_ring_type type, unsigned int max_packet, gfp_t flags) { struct xhci_ring *ring; int ret; @@ -383,7 +380,7 @@ struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, return ring; ret = xhci_alloc_segments_for_ring(xhci, &ring->first_seg, &ring->last_seg, num_segs, - cycle_state, type, max_packet, flags); + type, max_packet, flags); if (ret) goto fail; @@ -393,7 +390,7 @@ struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, ring->last_seg->trbs[TRBS_PER_SEGMENT - 1].link.control |= cpu_to_le32(LINK_TOGGLE); } - xhci_initialize_ring_info(ring, cycle_state); + xhci_initialize_ring_info(ring); trace_xhci_ring_alloc(ring); return ring; @@ -421,8 +418,8 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring, struct xhci_segment *last; int ret; - ret = xhci_alloc_segments_for_ring(xhci, &first, &last, num_new_segs, ring->cycle_state, - ring->type, ring->bounce_buf_len, flags); + ret = xhci_alloc_segments_for_ring(xhci, &first, &last, num_new_segs, ring->type, + ring->bounce_buf_len, flags); if (ret) return -ENOMEM; @@ -632,8 +629,7 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci, for (cur_stream = 1; cur_stream < num_streams; cur_stream++) { stream_info->stream_rings[cur_stream] = - xhci_ring_alloc(xhci, 2, 1, TYPE_STREAM, max_packet, - mem_flags); + xhci_ring_alloc(xhci, 2, TYPE_STREAM, max_packet, mem_flags); cur_ring = stream_info->stream_rings[cur_stream]; if (!cur_ring) goto cleanup_rings; @@ -976,7 +972,7 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, } /* Allocate endpoint 0 ring */ - dev->eps[0].ring = xhci_ring_alloc(xhci, 2, 1, TYPE_CTRL, 0, flags); + dev->eps[0].ring = xhci_ring_alloc(xhci, 2, TYPE_CTRL, 0, flags); if (!dev->eps[0].ring) goto fail; @@ -1453,7 +1449,7 @@ int xhci_endpoint_init(struct xhci_hcd *xhci, /* Set up the endpoint ring */ virt_dev->eps[ep_index].new_ring = - xhci_ring_alloc(xhci, 2, 1, ring_type, max_packet, mem_flags); + xhci_ring_alloc(xhci, 2, ring_type, max_packet, mem_flags); if (!virt_dev->eps[ep_index].new_ring) return -ENOMEM; @@ -2263,7 +2259,7 @@ xhci_alloc_interrupter(struct xhci_hcd *xhci, unsigned int segs, gfp_t flags) if (!ir) return NULL; - ir->event_ring = xhci_ring_alloc(xhci, segs, 1, TYPE_EVENT, 0, flags); + ir->event_ring = xhci_ring_alloc(xhci, segs, TYPE_EVENT, 0, flags); if (!ir->event_ring) { xhci_warn(xhci, "Failed to allocate interrupter event ring\n"); kfree(ir); @@ -2465,7 +2461,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) goto fail; /* Set up the command ring to have one segments for now. */ - xhci->cmd_ring = xhci_ring_alloc(xhci, 1, 1, TYPE_COMMAND, 0, flags); + xhci->cmd_ring = xhci_ring_alloc(xhci, 1, TYPE_COMMAND, 0, flags); if (!xhci->cmd_ring) goto fail; xhci_dbg_trace(xhci, trace_xhci_dbg_init, diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 44e4ae201048..aa8c877f47ac 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -790,7 +790,7 @@ static void xhci_clear_command_ring(struct xhci_hcd *xhci) seg->trbs[TRBS_PER_SEGMENT - 1].link.control &= cpu_to_le32(~TRB_CYCLE); } - xhci_initialize_ring_info(ring, 1); + xhci_initialize_ring_info(ring); /* * Reset the hardware dequeue pointer. * Yes, this will need to be re-written after resume, but we're paranoid diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 753d9343a4b1..d3b250c736b8 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1795,14 +1795,12 @@ void xhci_slot_copy(struct xhci_hcd *xhci, int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_device *udev, struct usb_host_endpoint *ep, gfp_t mem_flags); -struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, - unsigned int num_segs, unsigned int cycle_state, +struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, unsigned int num_segs, enum xhci_ring_type type, unsigned int max_packet, gfp_t flags); void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring); int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring, unsigned int num_trbs, gfp_t flags); -void xhci_initialize_ring_info(struct xhci_ring *ring, - unsigned int cycle_state); +void xhci_initialize_ring_info(struct xhci_ring *ring); void xhci_free_endpoint_ring(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, unsigned int ep_index); From patchwork Wed Nov 6 10:14:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842348 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 961911DBB35 for ; Wed, 6 Nov 2024 10:13:04 +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=1730887986; cv=none; b=qtENUzRtylpAi1tKJ1CVXvFlI9x5NbrX6x/qJfi4pc2kRYT6/nxrU6xeO0vqaAolAE6ZqqeI6XpxMN4WMFk7TT63/ooDSmaaNz5T8TjUZum8MrgItupdWJ7z1O4l4yRkvF+wal0zbHL4X0LwsxXJRAc87DL3kmzZlqGerfuJPrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887986; c=relaxed/simple; bh=CAKESkKwV0uSPOP1JMP4q3iJ8Ss44fXqvGf8KiDcKIU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jdTuAbNn9EjLReHyRtiu1qER2p2sPeRUyYy9/NF0Duq6qBpLOK+x+fd563y5lrPc8xUvBA3U9Rm+o4DoKVjeqTX6Gk5QwBtJ+1Hjbs6RpQpxHDLvDRPGtWCVlomxpJEOrHKTyHhqDRyLnBP3t+rjQSg+xyqHm6olgdhzd0dQWFU= 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=iZSYhzVQ; 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="iZSYhzVQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887984; x=1762423984; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CAKESkKwV0uSPOP1JMP4q3iJ8Ss44fXqvGf8KiDcKIU=; b=iZSYhzVQphMh8c+8UK6nzz6rRekY+rlU6bRFmXjgWsgZvG+XoROzQW+L XtCML+QHbMGgMeFIxu3IX8cqdAKXRXjhxxtbatZIcwKYoOmCkAu68OD5O 24zEK6KIP1BOBzfQifF2SlvdcjnIvfSVKYRo3KKG7hwSQlNKn6xA/TUk3 +nSsAjghNqo2Ku0/cnHXIkfutm91iwgv0BI3/oTPbzgMTnumq6wFeJAFw qNKKkJWHIfdpDLxuwwK27KCadQlIy1F3vT5rgaRCbcjO5bUjZ4ryF2Y8X UQ1CIUQZWMAjuFRNTihqzpDBDpydB1d3W2YNtCtz8ojfFq7jhFcVbu4ea w==; X-CSE-ConnectionGUID: P6eVJohYQG+5GOojx7Ku7A== X-CSE-MsgGUID: oxEHxiGKThGybvblCp1WVA== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059402" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059402" 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:13:04 -0800 X-CSE-ConnectionGUID: cjI0xJQcQzGuwpwy6E0EcQ== X-CSE-MsgGUID: qPY0anFxQUaYzebdEKVsUg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813116" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:03 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 12/33] usb: xhci: adjust xhci_alloc_segments_for_ring() arguments Date: Wed, 6 Nov 2024 12:14:38 +0200 Message-Id: <20241106101459.775897-13-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: Niklas Neronin The function xhci_alloc_segments_for_ring() currently takes 7 arguments, 5 of which are components of the 'xhci_ring' struct. Refactor the function to accept a pointer to the 'xhci_ring' struct instead of passing these components separately. The change reduces the number of arguments, making the function signature cleaner and easier to understand. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 48 ++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 164b22d0b475..fa77a15dfde6 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -313,44 +313,38 @@ void xhci_initialize_ring_info(struct xhci_ring *ring) EXPORT_SYMBOL_GPL(xhci_initialize_ring_info); /* Allocate segments and link them for a ring */ -static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, - struct xhci_segment **first, - struct xhci_segment **last, - unsigned int num_segs, - enum xhci_ring_type type, - unsigned int max_packet, - gfp_t flags) +static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, struct xhci_ring *ring, gfp_t flags) { struct xhci_segment *prev; unsigned int num = 0; bool chain_links; - chain_links = xhci_link_chain_quirk(xhci, type); + chain_links = xhci_link_chain_quirk(xhci, ring->type); - prev = xhci_segment_alloc(xhci, max_packet, num, flags); + prev = xhci_segment_alloc(xhci, ring->bounce_buf_len, num, flags); if (!prev) return -ENOMEM; num++; - *first = prev; - while (num < num_segs) { + ring->first_seg = prev; + while (num < ring->num_segs) { struct xhci_segment *next; - next = xhci_segment_alloc(xhci, max_packet, num, flags); + next = xhci_segment_alloc(xhci, ring->bounce_buf_len, num, flags); if (!next) goto free_segments; - xhci_link_segments(prev, next, type, chain_links); + xhci_link_segments(prev, next, ring->type, chain_links); prev = next; num++; } - xhci_link_segments(prev, *first, type, chain_links); - *last = prev; + xhci_link_segments(prev, ring->first_seg, ring->type, chain_links); + ring->last_seg = prev; return 0; free_segments: - xhci_free_segments_for_ring(xhci, *first); + xhci_free_segments_for_ring(xhci, ring->first_seg); return -ENOMEM; } @@ -379,8 +373,7 @@ struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, unsigned int num_segs, if (num_segs == 0) return ring; - ret = xhci_alloc_segments_for_ring(xhci, &ring->first_seg, &ring->last_seg, num_segs, - type, max_packet, flags); + ret = xhci_alloc_segments_for_ring(xhci, ring, flags); if (ret) goto fail; @@ -414,23 +407,24 @@ void xhci_free_endpoint_ring(struct xhci_hcd *xhci, int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring, unsigned int num_new_segs, gfp_t flags) { - struct xhci_segment *first; - struct xhci_segment *last; - int ret; + struct xhci_ring new_ring; + int ret; - ret = xhci_alloc_segments_for_ring(xhci, &first, &last, num_new_segs, ring->type, - ring->bounce_buf_len, flags); + new_ring.num_segs = num_new_segs; + new_ring.bounce_buf_len = ring->bounce_buf_len; + new_ring.type = ring->type; + ret = xhci_alloc_segments_for_ring(xhci, &new_ring, flags); if (ret) return -ENOMEM; if (ring->type == TYPE_STREAM) { - ret = xhci_update_stream_segment_mapping(ring->trb_address_map, - ring, first, flags); + ret = xhci_update_stream_segment_mapping(ring->trb_address_map, ring, + new_ring.first_seg, flags); if (ret) goto free_segments; } - xhci_link_rings(xhci, ring, first, last, num_new_segs); + xhci_link_rings(xhci, ring, new_ring.first_seg, new_ring.last_seg, num_new_segs); trace_xhci_ring_expansion(ring); xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion, "ring expansion succeed, now has %d segments", @@ -439,7 +433,7 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring, return 0; free_segments: - xhci_free_segments_for_ring(xhci, first); + xhci_free_segments_for_ring(xhci, new_ring.first_seg); return ret; } From patchwork Wed Nov 6 10:14:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 841349 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 278F81DE2BE for ; Wed, 6 Nov 2024 10:13:06 +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=1730887987; cv=none; b=jDa7JN7FlMXebqWtx4J0juKd0OOXN2BoYyr1VuXMcEmnI4FqMogovbPM5Qpst9DqsNqQv8l9x+rLFolQoAC1NU+N+ymRwc6HZaiTPLsV1M9rEEBeQZcMb0dKUfDRiQKcyElbeDUaOR/umtyYHmAZciyqrmW6+Afp5nwAb2Kl/fY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887987; c=relaxed/simple; bh=+y9R/qFelJ+85F4fjV7ozxcVNNVmzDsZZR0MCX7xqLs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XoznK6SrjLhPwLy6mCsdfsoSCR/Z9IrwxnzdzVGPZRRIpU3QYHk8VN/FFf/tKYd0rTTyWMrjALea8arsfq3WIX19OMcKDs7IkL1e6iw3TPiw/McFMLFTRNuP6F0NW4XVkIQd7djSXBNGzBn3o6qmL58a04Vq3ARfoXXEPtf59CI= 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=PUh3dJiG; 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="PUh3dJiG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887986; x=1762423986; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+y9R/qFelJ+85F4fjV7ozxcVNNVmzDsZZR0MCX7xqLs=; b=PUh3dJiGJVga8JVLU/EM8L1AxRl99BPUJhODyK5cB9DCz8+//+qd58js f8qzPMGtL1llBwyP27qkSXEZ1enkvzINdfDDsrG3W11/BUM9mPIYzkgoD q94clQeLbWjcsk6HrDFyv/b2fHxtHguYZwfbGNul22WtfY1u0p7wHMCzy CQxEfxhZJpnA68Lh8LgvKUzXThiMsG4YMDWblVWn8ED9M0y2nvZTbakSK 03vnbywBiMt9hbz7O44S/gZbjID3R6hhNsLZo+MNsL8qETuRIeznK/Cuu KnerDPa2W0DO6B63ee5rajD/gj5XX5vmGQwyZMFKitr+aBKvMgSEMVMGU g==; X-CSE-ConnectionGUID: ALrfO2KYSyelEiXGxRuj1w== X-CSE-MsgGUID: Im2htf8BQiSOIId9mox+qw== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059404" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059404" 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:13:06 -0800 X-CSE-ConnectionGUID: 8lRwI+4WQO67KwJoOahJUA== X-CSE-MsgGUID: qYISQAnkTTmPRrlkHGv7VA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813139" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:05 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 13/33] usb: xhci: rework xhci_free_segments_for_ring() Date: Wed, 6 Nov 2024 12:14:39 +0200 Message-Id: <20241106101459.775897-14-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: Niklas Neronin The segment list is only relevant within the context of the ring. Thus, it is more logical to pass the ring itself when freeing all segments from a ring, rather than passing the ring list. Rename the function to "xhci_ring_segments_free" to align with the naming convention of xhci_segment_free(). To make the freeing process more intuitive, free segments sequentially from start to end (i.e., 0, 1, 2, 3, ...) instead of freeing the first segment last (i.e., 1, 2, 3, ... 0). Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index fa77a15dfde6..e46be4c49b2f 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -71,18 +71,18 @@ static void xhci_segment_free(struct xhci_hcd *xhci, struct xhci_segment *seg) kfree(seg); } -static void xhci_free_segments_for_ring(struct xhci_hcd *xhci, - struct xhci_segment *first) +static void xhci_ring_segments_free(struct xhci_hcd *xhci, struct xhci_ring *ring) { - struct xhci_segment *seg; + struct xhci_segment *seg, *next; + + ring->last_seg->next = NULL; + seg = ring->first_seg; - seg = first->next; - while (seg && seg != first) { - struct xhci_segment *next = seg->next; + while (seg) { + next = seg->next; xhci_segment_free(xhci, seg); seg = next; } - xhci_segment_free(xhci, first); } /* @@ -282,7 +282,7 @@ void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring) if (ring->first_seg) { if (ring->type == TYPE_STREAM) xhci_remove_stream_mapping(ring); - xhci_free_segments_for_ring(xhci, ring->first_seg); + xhci_ring_segments_free(xhci, ring); } kfree(ring); @@ -344,7 +344,8 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, struct xhci_ring return 0; free_segments: - xhci_free_segments_for_ring(xhci, ring->first_seg); + ring->last_seg = prev; + xhci_ring_segments_free(xhci, ring); return -ENOMEM; } @@ -433,7 +434,7 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring, return 0; free_segments: - xhci_free_segments_for_ring(xhci, new_ring.first_seg); + xhci_ring_segments_free(xhci, &new_ring); return ret; } From patchwork Wed Nov 6 10:14:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842347 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 380531DE2CE for ; Wed, 6 Nov 2024 10:13:07 +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=1730887989; cv=none; b=PGbt1jvE3SXPBBeaDDWrwb7F7KJosLEYc3Qd1af9QUfl101Tro9jc1f3EdxMjSYkW8+TLModcB3194tpiqjHzYZO84UznYzfly/12XY+7tHxwB+UXAQUciKq/banG9wVUW3ixbyQefo9aMzYWGv6zJ7qZyL5C3oWjtA+Jd1rzkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887989; c=relaxed/simple; bh=eR9pmUpBhVx8M9XsTa01F8PlrKft7ELS7RikpxpVPL0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e9TFA+Oisc22m9H0YOm9MtdwkOYSZ6MZ8OOGCHETKu+R6i2sX6Hqp1Vb44ZdUXdk4I82eOMO4x1+QksOvlqea2NDgGBIRyRnvemKraJOP0st3EPiw0jie/op3dLsTkrOu4cfIkbRZ1cTut2p7B+xIWNjVEcuzBeocptiLZEXZPI= 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=Es7U3Mpp; 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="Es7U3Mpp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887988; x=1762423988; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eR9pmUpBhVx8M9XsTa01F8PlrKft7ELS7RikpxpVPL0=; b=Es7U3Mppbuzsu/alDtOYSSHHosczuda93QACUzkUNG3mMB2BcVwTWJR/ mJeBzqNFMcQrFBWqtyBnvxCWZ5fmanuMCWsf2nvGapBZOkp9ITiNSlJpW 3y2knVtjC9T12W2n47gkm++TJ2EqP0P5w6PUwD4+yKcHED4pCdhfeGdPR NkNWiQPL6bwmpRnON4B0fZBxWMs3wU5AsPuMREexbW/2ozRmWhwOFYsWZ 2icVo68YaMVcPavdj05Q5v/+SM1Gkg4j82/H8FfrZiHvZ4lg1dv7HTasI +1Hx47VMhp/CNURly0QoytRtBjNT3W4iGpSoCUDQueCpHbQEYo2SxsxUB g==; X-CSE-ConnectionGUID: S+lQsZngR5idzX2xwExLQg== X-CSE-MsgGUID: SdIE8KOuSHG83lvrA+GZSw== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059406" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059406" 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:13:07 -0800 X-CSE-ConnectionGUID: KhlALhZ4TwSSuirzPUBWAg== X-CSE-MsgGUID: xIJKpqFBQw2JEBhiU/CoUw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813155" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:06 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 14/33] usb: xhci: refactor xhci_link_rings() to use source and destination rings Date: Wed, 6 Nov 2024 12:14:40 +0200 Message-Id: <20241106101459.775897-15-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: Niklas Neronin Refactor the xhci_link_rings() function to accept two rings: a source ring and a destination ring. Previously, the function accepted a ring and a segment list as arguments, now the function splices the source ring segment list into the destination ring. This new approach reduces the number of arguments and simplifies the code, making it easier to follow. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index e46be4c49b2f..feeaafc59a39 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -116,45 +116,42 @@ static void xhci_link_segments(struct xhci_segment *prev, } /* - * Link the ring to the new segments. + * Link the src ring segments to the dst ring. * Set Toggle Cycle for the new ring if needed. */ -static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *ring, - struct xhci_segment *first, struct xhci_segment *last, - unsigned int num_segs) +static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *src, struct xhci_ring *dst) { - struct xhci_segment *next, *seg; + struct xhci_segment *seg; bool chain_links; - if (!ring || !first || !last) + if (!src || !dst) return; - chain_links = xhci_link_chain_quirk(xhci, ring->type); + chain_links = xhci_link_chain_quirk(xhci, dst->type); /* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */ - if (ring->cycle_state == 0) { - xhci_for_each_ring_seg(ring->first_seg, seg) { + if (dst->cycle_state == 0) { + xhci_for_each_ring_seg(src->first_seg, seg) { for (int i = 0; i < TRBS_PER_SEGMENT; i++) seg->trbs[i].link.control |= cpu_to_le32(TRB_CYCLE); } } - next = ring->enq_seg->next; - xhci_link_segments(ring->enq_seg, first, ring->type, chain_links); - xhci_link_segments(last, next, ring->type, chain_links); - ring->num_segs += num_segs; + xhci_link_segments(src->last_seg, dst->enq_seg->next, dst->type, chain_links); + xhci_link_segments(dst->enq_seg, src->first_seg, dst->type, chain_links); + dst->num_segs += src->num_segs; - if (ring->enq_seg == ring->last_seg) { - if (ring->type != TYPE_EVENT) { - ring->last_seg->trbs[TRBS_PER_SEGMENT-1].link.control + if (dst->enq_seg == dst->last_seg) { + if (dst->type != TYPE_EVENT) { + dst->last_seg->trbs[TRBS_PER_SEGMENT-1].link.control &= ~cpu_to_le32(LINK_TOGGLE); - last->trbs[TRBS_PER_SEGMENT-1].link.control + src->last_seg->trbs[TRBS_PER_SEGMENT-1].link.control |= cpu_to_le32(LINK_TOGGLE); } - ring->last_seg = last; + dst->last_seg = src->last_seg; } - for (seg = ring->enq_seg; seg != ring->last_seg; seg = seg->next) + for (seg = dst->enq_seg; seg != dst->last_seg; seg = seg->next) seg->next->num = seg->num + 1; } @@ -411,6 +408,9 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring, struct xhci_ring new_ring; int ret; + if (num_new_segs == 0) + return 0; + new_ring.num_segs = num_new_segs; new_ring.bounce_buf_len = ring->bounce_buf_len; new_ring.type = ring->type; @@ -425,7 +425,7 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring, goto free_segments; } - xhci_link_rings(xhci, ring, new_ring.first_seg, new_ring.last_seg, num_new_segs); + xhci_link_rings(xhci, ring, &new_ring); trace_xhci_ring_expansion(ring); xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion, "ring expansion succeed, now has %d segments", From patchwork Wed Nov 6 10:14:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 841348 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 3A5381DDC14 for ; Wed, 6 Nov 2024 10:13:09 +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=1730887990; cv=none; b=Kk7Ej4SjnV5yC/nwMBuggZbQUIiOGAQH1L+rI25K4H6dDhXSlwPgGDAys6V9gBe2X4cGAPqX6/OqOLs/rZi8i8qmPznvE5UZ+kmjhHO1OmkYG6mw0zmnBR18OR2aGC4Ve9YMhmr3OcC/BxKz6ewzofc2a6rxSuBa6YQ+X9MvoaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887990; c=relaxed/simple; bh=MWEbtlNk+V1RcX++gdHwtGcECRqEjmn9l8e1/UkhEeQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WrpamBOXo50SXakpNSViulVYu0E1/CURTfYBXgO/Ilh5Iz8MFKWKh1eW2yaQ7feNnCxhXXs63RnqG0lesOTnVrlcxnDakQfhkbFxJM5KRczAfdPw1XS48Yeu9tV9okK9Mjx2H43FEHgmFQHsCG9WLicoLSJNDzpzcytGkfL8XEA= 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=deLVDVYb; 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="deLVDVYb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887989; x=1762423989; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MWEbtlNk+V1RcX++gdHwtGcECRqEjmn9l8e1/UkhEeQ=; b=deLVDVYbA1Rre6eg5aqdIRpqp21L0mfzXwFlNUU4IlOWN6xQpZkqokup 5YmR2tdNS+QJvtllJZcSb0w1Wug3RJHPGm0Am3LjrOjH9jlgHkKsKmrfI nzmmemzpJTi+yXb6Bg0CGCvvRKyDwpevg/DK6ex/FEt9sze7XqlsBmX6a trOTZRXUdu0XXxgJPXXJ/OlK2G7ecoSPJpFQCag0wnff0SyT2oFwK7pem jqxtQErX2oEn6XauXBSVWAAhJz+Xg5DV2Zlj7iNMYU9tKEYPZIcMm/pCb dippNhi2lRr0zTTuiHoqQN56htO05s7SxliwgNnkf4PsTxeExzzPvc1Bb w==; X-CSE-ConnectionGUID: x2WPy/CHTHGpjUwPP7haiQ== X-CSE-MsgGUID: 1zsYDEGHSQ+59a4ntgG06w== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059410" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059410" 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:13:09 -0800 X-CSE-ConnectionGUID: jRzEHzSeRFW7ufpo4MwXUA== X-CSE-MsgGUID: P5YlzJieQEucnPgfdi7rfg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813185" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:08 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 15/33] usb: xhci: rework xhci_link_segments() Date: Wed, 6 Nov 2024 12:14:41 +0200 Message-Id: <20241106101459.775897-16-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: Niklas Neronin Prepare for splitting ring segments allocation and initialization by reworking the xhci_link_segments() function. Segment linking and ring type checks are moved out of xhci_link_segments(), and the function is renamed to "xhci_set_link_trb()". The goal is to keep ring linking within xhci_alloc_segments_for_ring() and move initialization into a separate function. Additionally, reorder and simplify xhci_set_link_trb() for better readability. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 54 ++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index feeaafc59a39..41a5e67e1c4f 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -86,33 +86,31 @@ static void xhci_ring_segments_free(struct xhci_hcd *xhci, struct xhci_ring *rin } /* - * Make the prev segment point to the next segment. + * Only for transfer and command rings where driver is the producer, not for + * event rings. * - * Change the last TRB in the prev segment to be a Link TRB which points to the + * Change the last TRB in the segment to be a Link TRB which points to the * DMA address of the next segment. The caller needs to set any Link TRB * related flags, such as End TRB, Toggle Cycle, and no snoop. */ -static void xhci_link_segments(struct xhci_segment *prev, - struct xhci_segment *next, - enum xhci_ring_type type, bool chain_links) +static void xhci_set_link_trb(struct xhci_segment *seg, bool chain_links) { + union xhci_trb *trb; u32 val; - if (!prev || !next) + if (!seg || !seg->next) return; - prev->next = next; - if (type != TYPE_EVENT) { - prev->trbs[TRBS_PER_SEGMENT-1].link.segment_ptr = - cpu_to_le64(next->dma); - /* Set the last TRB in the segment to have a TRB type ID of Link TRB */ - val = le32_to_cpu(prev->trbs[TRBS_PER_SEGMENT-1].link.control); - val &= ~TRB_TYPE_BITMASK; - val |= TRB_TYPE(TRB_LINK); - if (chain_links) - val |= TRB_CHAIN; - prev->trbs[TRBS_PER_SEGMENT-1].link.control = cpu_to_le32(val); - } + trb = &seg->trbs[TRBS_PER_SEGMENT - 1]; + + /* Set the last TRB in the segment to have a TRB type ID of Link TRB */ + val = le32_to_cpu(trb->link.control); + val &= ~TRB_TYPE_BITMASK; + val |= TRB_TYPE(TRB_LINK); + if (chain_links) + val |= TRB_CHAIN; + trb->link.control = cpu_to_le32(val); + trb->link.segment_ptr = cpu_to_le64(seg->next->dma); } /* @@ -127,8 +125,6 @@ static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *src, struct if (!src || !dst) return; - chain_links = xhci_link_chain_quirk(xhci, dst->type); - /* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */ if (dst->cycle_state == 0) { xhci_for_each_ring_seg(src->first_seg, seg) { @@ -137,8 +133,13 @@ static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *src, struct } } - xhci_link_segments(src->last_seg, dst->enq_seg->next, dst->type, chain_links); - xhci_link_segments(dst->enq_seg, src->first_seg, dst->type, chain_links); + src->last_seg->next = dst->enq_seg->next; + dst->enq_seg->next = src->first_seg; + if (dst->type != TYPE_EVENT) { + chain_links = xhci_link_chain_quirk(xhci, dst->type); + xhci_set_link_trb(dst->enq_seg, chain_links); + xhci_set_link_trb(src->last_seg, chain_links); + } dst->num_segs += src->num_segs; if (dst->enq_seg == dst->last_seg) { @@ -331,13 +332,18 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, struct xhci_ring if (!next) goto free_segments; - xhci_link_segments(prev, next, ring->type, chain_links); + prev->next = next; + if (ring->type != TYPE_EVENT) + xhci_set_link_trb(prev, chain_links); prev = next; num++; } - xhci_link_segments(prev, ring->first_seg, ring->type, chain_links); ring->last_seg = prev; + ring->last_seg->next = ring->first_seg; + if (ring->type != TYPE_EVENT) + xhci_set_link_trb(prev, chain_links); + return 0; free_segments: From patchwork Wed Nov 6 10:14:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842346 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 C0EC41DD537 for ; Wed, 6 Nov 2024 10:13:10 +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=1730887992; cv=none; b=kWfbj3RRFnortc7zhnGHqE17hy3PjxQ/y9mPbD8PlULEtG/qTvXHX98R6Fx6sUjKo3lgc8pC7y4Pf7cJweU72olidogjvMOHnPC1KOVTAq3C3daX68mEoqYxM2wmjxZ35D9vtNrjO7VeKu+s3lzzEiVR+wMFj7od1lDKKNdN3/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887992; c=relaxed/simple; bh=kkHWmyXJy0HdUsS/++nlJ0JmFvVwf5miCIM3dcybubk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZrrfnrOkRTenEKoMnd6USrgAfAKhQdr8IiL60sfijB5RSEkSsv/D7W3tJQL89G+hEsi2fr/oEGDubydLExQhpnLFI7tIrbPji1X7YZY8VKOGxN3dM2gSrRXlyj6ZaWr1gDKMtvbNWvsP0xEVIA2DwSc416ZWIYVhY45g2yCkO2I= 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=Um445cZB; 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="Um445cZB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887990; x=1762423990; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kkHWmyXJy0HdUsS/++nlJ0JmFvVwf5miCIM3dcybubk=; b=Um445cZBKm23LAfCZsI2C8donBNqXB4qXqXiwAb34iOQW7WIoqQDA9Fx WMS8FaykgxcIkVtfomjfwDPE3fz1zJel47SoCOZK/lkE9B3QhBhgVHIgD QcpHqUTNdYwUjZARTglD+3A+HxkbdtZoXLKnEv5D93UldXhxqg5K5rZ4C oLWGAO2xWMHuzK8HsR7anPWROw10XkcB1HKu5nSB+2jPJMR35/hJ/xQLj 2IJ1tzwKGtbF8fdbi8A5HwJKQKU8Gjt1mD0DVwC6ghkKVkf1N3PMgaoAr rloyt9TzNu5AQlSxTXdyc0t5Xu+94uGURS4qSb8dO52z2+/Mzx5qU1h3f Q==; X-CSE-ConnectionGUID: 7cSQ3wS/RCOjXZZeRo9b8g== X-CSE-MsgGUID: JNHl0439RP68FZQe879XJQ== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059414" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059414" 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:13:10 -0800 X-CSE-ConnectionGUID: 9OhLQKgoR1GJo69GE1NuWQ== X-CSE-MsgGUID: Hnj9PPuRSoCLG9TPepa7aA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813200" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:09 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 16/33] usb: xhci: add xhci_initialize_ring_segments() Date: Wed, 6 Nov 2024 12:14:42 +0200 Message-Id: <20241106101459.775897-17-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: Niklas Neronin A ring consists of a list of segments, each containing a specific number of TRBs. The xhci driver allocates and initializes ring segments and TRBs in the same functions. This combined allocation and initialization process leads to an issue where, after hibernation (S4 state), the xhci driver frees all its memory and re-creates the rings, segments, and TRBs from scratch. Move all default ring segment initialization into function xhci_initialize_ring_segments(). This function can be called to reinitialize a ring without freeing and reallocating it. Since xhci_alloc_segments_for_ring() no longer initializes segment TRBs, xhci_initialize_ring_segments() is added to xhci_ring_expansion(). This results in the last segment of the source ring having the 'LINK_TOGGLE' bit set. Therefore, if the last source ring segment is not the last in the destination ring, the 'LINK_TOGGLE' bit must be cleared. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 41 +++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 41a5e67e1c4f..4295e9a4de50 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -113,6 +113,22 @@ static void xhci_set_link_trb(struct xhci_segment *seg, bool chain_links) trb->link.segment_ptr = cpu_to_le64(seg->next->dma); } +static void xhci_initialize_ring_segments(struct xhci_hcd *xhci, struct xhci_ring *ring) +{ + struct xhci_segment *seg; + bool chain_links; + + if (ring->type == TYPE_EVENT) + return; + + chain_links = xhci_link_chain_quirk(xhci, ring->type); + xhci_for_each_ring_seg(ring->first_seg, seg) + xhci_set_link_trb(seg, chain_links); + + /* See section 4.9.2.1 and 6.4.4.1 */ + ring->last_seg->trbs[TRBS_PER_SEGMENT - 1].link.control |= cpu_to_le32(LINK_TOGGLE); +} + /* * Link the src ring segments to the dst ring. * Set Toggle Cycle for the new ring if needed. @@ -143,13 +159,13 @@ static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *src, struct dst->num_segs += src->num_segs; if (dst->enq_seg == dst->last_seg) { - if (dst->type != TYPE_EVENT) { + if (dst->type != TYPE_EVENT) dst->last_seg->trbs[TRBS_PER_SEGMENT-1].link.control &= ~cpu_to_le32(LINK_TOGGLE); - src->last_seg->trbs[TRBS_PER_SEGMENT-1].link.control - |= cpu_to_le32(LINK_TOGGLE); - } + dst->last_seg = src->last_seg; + } else if (dst->type != TYPE_EVENT) { + src->last_seg->trbs[TRBS_PER_SEGMENT-1].link.control &= ~cpu_to_le32(LINK_TOGGLE); } for (seg = dst->enq_seg; seg != dst->last_seg; seg = seg->next) @@ -315,9 +331,6 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, struct xhci_ring { struct xhci_segment *prev; unsigned int num = 0; - bool chain_links; - - chain_links = xhci_link_chain_quirk(xhci, ring->type); prev = xhci_segment_alloc(xhci, ring->bounce_buf_len, num, flags); if (!prev) @@ -333,17 +346,12 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, struct xhci_ring goto free_segments; prev->next = next; - if (ring->type != TYPE_EVENT) - xhci_set_link_trb(prev, chain_links); prev = next; num++; } ring->last_seg = prev; ring->last_seg->next = ring->first_seg; - if (ring->type != TYPE_EVENT) - xhci_set_link_trb(prev, chain_links); - return 0; free_segments: @@ -381,12 +389,7 @@ struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, unsigned int num_segs, if (ret) goto fail; - /* Only event ring does not use link TRB */ - if (type != TYPE_EVENT) { - /* See section 4.9.2.1 and 6.4.4.1 */ - ring->last_seg->trbs[TRBS_PER_SEGMENT - 1].link.control |= - cpu_to_le32(LINK_TOGGLE); - } + xhci_initialize_ring_segments(xhci, ring); xhci_initialize_ring_info(ring); trace_xhci_ring_alloc(ring); return ring; @@ -424,6 +427,8 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring, if (ret) return -ENOMEM; + xhci_initialize_ring_segments(xhci, &new_ring); + if (ring->type == TYPE_STREAM) { ret = xhci_update_stream_segment_mapping(ring->trb_address_map, ring, new_ring.first_seg, flags); From patchwork Wed Nov 6 10:14:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 841347 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 C34A61DE3AE; Wed, 6 Nov 2024 10:13:12 +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=1730887994; cv=none; b=p+GSUanuRM9yTl3FaIB+K0MercnYt17QsQTs8VhXozPzZJl/CxxffoUNQ6uxIYrhBJD2VIO7xINPMdPxHV5SMEyaJ8IZdcKDp5Z0TwBJkye+nzeQljIGadf0/qkc26FSR5YI7HydIzcP/b9DmM+kaNC5NSS3CcPceAOagB3ETT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887994; c=relaxed/simple; bh=eiWAtX+LR2y5YPx9QJM5LcvI9XMM/eNw/g1OXKd0iig=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uZJiCvIFjUtOt1yHOEqNlW9n9ilVBIivKXTrsGsp6Cnf2Y7EYp94If6xAkGEbdCqjFy3OzBE7ODU0bRPWi57VV3z0KrZfRZI5kMovVd7alKRqVidqsBOPHD8vtVIgk+nRHc/85IgeZ855k1EeorMujl9r7ALmURcJpDTM4s9qcU= 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=hqiXLC+6; 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="hqiXLC+6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887993; x=1762423993; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eiWAtX+LR2y5YPx9QJM5LcvI9XMM/eNw/g1OXKd0iig=; b=hqiXLC+6hFajf+yWwbvutSN1+WTvyZMgU3BJVxkVHGwEEGDK7fT7Mz1E lC9yoicpzGGmoebXSuyVyLgP21bDTZMFezffw5fQUEMkU+/Rjls7J/cGR oJdbfQJTNJg9AjXtZcNhuAs+5pT+7L0hQYzhAgauqKDAeLXT278D9/xIk W6cdBZhQ1UcITyvBKcQJOFK4gB0Sj5YjU/Z3ZgACc+wpoJV4r0kykekNp qo3gIEkM9rlVzJ7BHrI4MMFpbCxc7TvW7b58ClL8E4MJVJtcjDYhQIW0o u8cLKaF7pKo7eLCHAjT3bYQ27s7SvxSs4FrkIivbIOX+oYa/VSQskWBiI w==; X-CSE-ConnectionGUID: pRx6GauJQkezCM8QPH/P7Q== X-CSE-MsgGUID: z+20Qs1KQDibeObsP14IDQ== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059417" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059417" 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:13:12 -0800 X-CSE-ConnectionGUID: hZWE9wsDRyauQJ/7MpLLIg== X-CSE-MsgGUID: jPIVNyTZRk6oEXAkNopYoQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813213" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:11 -0800 From: Mathias Nyman To: Cc: , Kuangyi Chiang , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 17/33] xhci: Combine two if statements for Etron xHCI host Date: Wed, 6 Nov 2024 12:14:43 +0200 Message-Id: <20241106101459.775897-18-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: Kuangyi Chiang Combine two if statements, because these hosts have the same quirk flags applied. [Mathias: has stable tag because other fixes in series depend on this] Fixes: 91f7a1524a92 ("xhci: Apply broken streams quirk to Etron EJ188 xHCI host") Cc: Signed-off-by: Kuangyi Chiang Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-pci.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 7803ff1f1c9f..db3c7e738213 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -394,12 +394,8 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW; if (pdev->vendor == PCI_VENDOR_ID_ETRON && - pdev->device == PCI_DEVICE_ID_EJ168) { - xhci->quirks |= XHCI_RESET_ON_RESUME; - xhci->quirks |= XHCI_BROKEN_STREAMS; - } - if (pdev->vendor == PCI_VENDOR_ID_ETRON && - pdev->device == PCI_DEVICE_ID_EJ188) { + (pdev->device == PCI_DEVICE_ID_EJ168 || + pdev->device == PCI_DEVICE_ID_EJ188)) { xhci->quirks |= XHCI_RESET_ON_RESUME; xhci->quirks |= XHCI_BROKEN_STREAMS; } From patchwork Wed Nov 6 10:14:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842345 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 570D71DDC34; Wed, 6 Nov 2024 10:13:14 +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=1730887995; cv=none; b=MO6MwLK14PKiDOcF+Od8FKf4Buml4Homid3nz4Bq/XlsDNhCIJnWWtVvcT1/D2JjDe3tXiePloZyAd1+AuLt5/QoDJTuuxMsFen1B5y9XI308lsBERrzuU4K3rMYFuR0G9Yy0xvsEBdnkKVYbj9rsFRjpMqbcsEEfSBjJyWMtA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887995; c=relaxed/simple; bh=krBrUnrDXKOWS6KLWA1yXNW6r5YeI2/fZUDjEkKibr8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FbPOcmeAcHpwhHP3iHjuRnKK6IA/YHFDL3KkjVHDRNr5wO5wxrglTgZQvQuGkQ+mb9++FPa5fzGBrw7xVUJRxXE1+0fBxeV6VcvXwRkAp0RA7NOO64V8uzo6qiDVJTJcRysmsEoU5Mrc/Yd5/JytsxO9zI3JUQZ32zFWi0mDIvY= 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=GbNiTgMo; 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="GbNiTgMo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887994; x=1762423994; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=krBrUnrDXKOWS6KLWA1yXNW6r5YeI2/fZUDjEkKibr8=; b=GbNiTgMousA4Wi8jhc63Z4A5au5F+vF6oeN+UMGonZ14vwQGrtsGv1a6 7+G1aVoLCiQDINpc04cB8F5ER6mYKc/m+ZWBSsELyX1/V4WEtsa/+5z8n LEFTepRkx/ukmW+mm3fGorAqNeBSccNbqulYCrYsRFIrLKzUuuc4Uzyaj 2Zoy/6Wss6iCFgNUNBI6VjBqE1x/O9AlkCuMK6otTArwq6BDpKkKSdqx4 rz8i/ogfcfxJaulGRZzbu6pXXLTv/Ipzayu5V9mJPgm1WmtAxF6i5YyaH BOcL2dfgXWNpQAErPNAdoJ88dq8HnkiPG8AzcVN7cyqnkmpnAYqnidL15 g==; X-CSE-ConnectionGUID: Qjv2DgcXStGBZuR6MctZ6Q== X-CSE-MsgGUID: egKh/BCTQpad20j0JmU5dQ== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059423" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059423" 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:13:14 -0800 X-CSE-ConnectionGUID: vxkLHDEtTQOhBl8qqu/qHA== X-CSE-MsgGUID: xrBOZABrQ1uTqIin/oDkFg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813235" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:13 -0800 From: Mathias Nyman To: Cc: , Kuangyi Chiang , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 18/33] xhci: Don't issue Reset Device command to Etron xHCI host Date: Wed, 6 Nov 2024 12:14:44 +0200 Message-Id: <20241106101459.775897-19-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: Kuangyi Chiang Sometimes the hub driver does not recognize the USB device connected to the external USB2.0 hub when the system resumes from S4. After the SetPortFeature(PORT_RESET) request is completed, the hub driver calls the HCD reset_device callback, which will issue a Reset Device command and free all structures associated with endpoints that were disabled. This happens when the xHCI driver issue a Reset Device command to inform the Etron xHCI host that the USB device associated with a device slot has been reset. Seems that the Etron xHCI host can not perform this command correctly, affecting the USB device. To work around this, the xHCI driver should obtain a new device slot with reference to commit 651aaf36a7d7 ("usb: xhci: Handle USB transaction error on address command"), which is another way to inform the Etron xHCI host that the USB device has been reset. Add a new XHCI_ETRON_HOST quirk flag to invoke the workaround in xhci_discover_or_reset_device(). Fixes: 2a8f82c4ceaf ("USB: xhci: Notify the xHC when a device is reset.") Cc: Signed-off-by: Kuangyi Chiang Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-pci.c | 1 + drivers/usb/host/xhci.c | 19 +++++++++++++++++++ drivers/usb/host/xhci.h | 1 + 3 files changed, 21 insertions(+) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index db3c7e738213..4b8c93e59d6d 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -396,6 +396,7 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) if (pdev->vendor == PCI_VENDOR_ID_ETRON && (pdev->device == PCI_DEVICE_ID_EJ168 || pdev->device == PCI_DEVICE_ID_EJ188)) { + xhci->quirks |= XHCI_ETRON_HOST; xhci->quirks |= XHCI_RESET_ON_RESUME; xhci->quirks |= XHCI_BROKEN_STREAMS; } diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index aa8c877f47ac..ae16253b53fb 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -3733,6 +3733,8 @@ void xhci_free_device_endpoint_resources(struct xhci_hcd *xhci, xhci->num_active_eps); } +static void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev); + /* * This submits a Reset Device Command, which will set the device state to 0, * set the device address to 0, and disable all the endpoints except the default @@ -3803,6 +3805,23 @@ static int xhci_discover_or_reset_device(struct usb_hcd *hcd, SLOT_STATE_DISABLED) return 0; + if (xhci->quirks & XHCI_ETRON_HOST) { + /* + * Obtaining a new device slot to inform the xHCI host that + * the USB device has been reset. + */ + ret = xhci_disable_slot(xhci, udev->slot_id); + xhci_free_virt_device(xhci, udev->slot_id); + if (!ret) { + ret = xhci_alloc_dev(hcd, udev); + if (ret == 1) + ret = 0; + else + ret = -EINVAL; + } + return ret; + } + trace_xhci_discover_or_reset_device(slot_ctx); xhci_dbg(xhci, "Resetting device with slot ID %u\n", slot_id); diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index d3b250c736b8..a0204e10486d 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1631,6 +1631,7 @@ struct xhci_hcd { #define XHCI_ZHAOXIN_HOST BIT_ULL(46) #define XHCI_WRITE_64_HI_LO BIT_ULL(47) #define XHCI_CDNS_SCTX_QUIRK BIT_ULL(48) +#define XHCI_ETRON_HOST BIT_ULL(49) unsigned int num_active_eps; unsigned int limit_active_eps; From patchwork Wed Nov 6 10:14:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 841346 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 7FE6B1DE3CA; Wed, 6 Nov 2024 10:13:16 +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=1730887998; cv=none; b=or2fzkcjqjChXsxvJnhr3AMFDLvxuwU4W3iz0/jsOWxWt3D7A6Zu29sT4ApoZLYWHy0w3/lCPkIcdVw3sE0MDZmh5UH0FcUfprCv1fBRBM8Kx+ekXMs3EXNA6v65n0WPxDV2LWkEVZA1lw+S1V4Z4irNrQIJvga3blO8yazKcoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887998; c=relaxed/simple; bh=aKZ6V63J9JW78flvSmlum82Zf2Y5tv9KBNFKrzKjKno=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rnBqDh0MB+BjbCgq4NV3iwD9K6mvKktIjqTk2AuR9pL5MyBq24D+iZPVcqisMsiGaSbJH9r9NRZSfgTJfPCqwLghFdaObrDhAoYOAMIaAyuB+M9FkmN4IpMXM6aPYyWWp0K6FpHOtN0Lkd1e54MvBYDuRbYggrKL1Yu9BP7oS2U= 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=YwDbyymG; 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="YwDbyymG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887996; x=1762423996; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aKZ6V63J9JW78flvSmlum82Zf2Y5tv9KBNFKrzKjKno=; b=YwDbyymGTPupPBFhyk6EqdF6GnrPrhGMXYjBVzhJBdrnoPX2S3R0S5Pm MqSbefmSd0P7pKpz+tLGQ2rHrWQHRitUaEscuHn5a/BvbSSyK/n8u0veS GFdCVNV5S4kBDLDfBLB3APT0BgPyEjNCLh5aZ+q2ypzFEWo36TLvPRFFl EbdobboXoGLJk7FkQlOn6QYkU+19mkXAafH6ZNFTy8Edv8Di6pzPt0/8W sokjHXYwAQpO0zvVnF4iWv1XG8tBbEeVquV1EQLPOLtQf2FKqLynxR5ld 5+4bxbgHOCkAX6accPR0LVksBHMPQVS+BozUjpt3Yqzs6oiKEYG4cYTax A==; X-CSE-ConnectionGUID: M/uADl8oSy2p9N1sA0dFKg== X-CSE-MsgGUID: 8vdn2/JuQ1OTMPy6DG+kQA== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059428" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059428" 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:13:16 -0800 X-CSE-ConnectionGUID: OP/7ER/MQ7urgMszywnmeQ== X-CSE-MsgGUID: 7uBlzzTITsW05iiWjpX0kg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813255" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:14 -0800 From: Mathias Nyman To: Cc: , Kuangyi Chiang , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 19/33] xhci: Fix control transfer error on Etron xHCI host Date: Wed, 6 Nov 2024 12:14:45 +0200 Message-Id: <20241106101459.775897-20-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: Kuangyi Chiang Performing a stability stress test on a USB3.0 2.5G ethernet adapter results in errors like this: [ 91.441469] r8152 2-3:1.0 eth3: get_registers -71 [ 91.458659] r8152 2-3:1.0 eth3: get_registers -71 [ 91.475911] r8152 2-3:1.0 eth3: get_registers -71 [ 91.493203] r8152 2-3:1.0 eth3: get_registers -71 [ 91.510421] r8152 2-3:1.0 eth3: get_registers -71 The r8152 driver will periodically issue lots of control-IN requests to access the status of ethernet adapter hardware registers during the test. This happens when the xHCI driver enqueue a control TD (which cross over the Link TRB between two ring segments, as shown) in the endpoint zero's transfer ring. Seems the Etron xHCI host can not perform this TD correctly, causing the USB transfer error occurred, maybe the upper driver retry that control-IN request can solve problem, but not all drivers do this. | | ------- | TRB | Setup Stage ------- | TRB | Link ------- ------- | TRB | Data Stage ------- | TRB | Status Stage ------- | | To work around this, the xHCI driver should enqueue a No Op TRB if next available TRB is the Link TRB in the ring segment, this can prevent the Setup and Data Stage TRB to be breaked by the Link TRB. Check if the XHCI_ETRON_HOST quirk flag is set before invoking the workaround in xhci_queue_ctrl_tx(). Fixes: d0e96f5a71a0 ("USB: xhci: Control transfer support.") Cc: Signed-off-by: Kuangyi Chiang Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index f62b243d0fc4..517df97ef496 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3733,6 +3733,20 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, if (!urb->setup_packet) return -EINVAL; + if ((xhci->quirks & XHCI_ETRON_HOST) && + urb->dev->speed >= USB_SPEED_SUPER) { + /* + * If next available TRB is the Link TRB in the ring segment then + * enqueue a No Op TRB, this can prevent the Setup and Data Stage + * TRB to be breaked by the Link TRB. + */ + if (trb_is_link(ep_ring->enqueue + 1)) { + field = TRB_TYPE(TRB_TR_NOOP) | ep_ring->cycle_state; + queue_trb(xhci, ep_ring, false, 0, 0, + TRB_INTR_TARGET(0), field); + } + } + /* 1 TRB for setup, 1 for status */ num_trbs = 2; /* From patchwork Wed Nov 6 10:14:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842344 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 0E3771DE3D5; Wed, 6 Nov 2024 10:13:18 +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=1730887999; cv=none; b=iIyd6PkeKf4UZAHGQ4HmH63E0Q8LnAs1bFlgToBq0/gDNUKdiDFvcieIiD8iQ9A+kSlCEBa7LcOwPjtObgr2Cn4ubd+0SPOvRl2qgLei/CFVBbOdCQ0JnTw3P2/srG7Rt5WdWH8sWA46bNhwAKGeE2nMFYgau2gwxbKKYsWSvME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730887999; c=relaxed/simple; bh=VZZfAXWLhzUpGIEWB5aCTnkjLh25KfYAmGZfjfAoBuk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jYpzDOd2O9OdWyNx9PxzMiNR5v8GAHFolgBPxkH4lTRddv99+BwaAI4YSzHWEWyzAzOyxs+PqUuOnrj7HDbO3PdoJcfTOxZY3bmD5qK3G2At8KTIw6Akx5FXcWJySeYY0VSmq5S1nNrF7F8qcH1j3ViewUlHfkp7eF1Z93M2Yfc= 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=PyBwKEgd; 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="PyBwKEgd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887998; x=1762423998; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VZZfAXWLhzUpGIEWB5aCTnkjLh25KfYAmGZfjfAoBuk=; b=PyBwKEgdF2EWeHYBzb2sT8gqXR33ibsvC3FikgnKgzoZ/9U7TrUbZwWd LicwFv5W80tXFLog5yoLDlZ6Ya8CHQEEyvgdr3skvTSPv4r0W4ddJRp6M uc7gUSgP2k22a0n3A1C+4AlZmmq03TkYoi3VBef8abu5MWt3ITAAXuT+z dnFE3fKJUthW/GuIte7wZ9Nj1NjYxRjRldkq57Lo0tK0EOxrZf9mVA/Xl DUDxB1fRFcnD5rYvBGeFFrQUIFYq7iBsnwc2XGBttuLHwWLOz4UywDi4p RJikuHYFaFfWmZdFOcbYJY30vFkdYuEQndo94w8kgPb0XbQzdvlB40Mg1 w==; X-CSE-ConnectionGUID: Qy0sWWn/SeeWQgUjsfInaA== X-CSE-MsgGUID: 7Rt49zR7Qle3rEznEU9M5Q== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059433" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059433" 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:13:17 -0800 X-CSE-ConnectionGUID: iH3Q+aYpSEammDgYnTsC+g== X-CSE-MsgGUID: PkwTEmJNTr+59k7Rs2qaPQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813280" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:16 -0800 From: Mathias Nyman To: Cc: , Kuangyi Chiang , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 20/33] xhci: Don't perform Soft Retry for Etron xHCI host Date: Wed, 6 Nov 2024 12:14:46 +0200 Message-Id: <20241106101459.775897-21-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: Kuangyi Chiang Since commit f8f80be501aa ("xhci: Use soft retry to recover faster from transaction errors"), unplugging USB device while enumeration results in errors like this: [ 364.855321] xhci_hcd 0000:0b:00.0: ERROR Transfer event for disabled endpoint slot 5 ep 2 [ 364.864622] xhci_hcd 0000:0b:00.0: @0000002167656d70 67f03000 00000021 0c000000 05038001 [ 374.934793] xhci_hcd 0000:0b:00.0: Abort failed to stop command ring: -110 [ 374.958793] xhci_hcd 0000:0b:00.0: xHCI host controller not responding, assume dead [ 374.967590] xhci_hcd 0000:0b:00.0: HC died; cleaning up [ 374.973984] xhci_hcd 0000:0b:00.0: Timeout while waiting for configure endpoint command Seems that Etorn xHCI host can not perform Soft Retry correctly, apply XHCI_NO_SOFT_RETRY quirk to disable Soft Retry and then issue is gone. This patch depends on commit a4a251f8c235 ("usb: xhci: do not perform Soft Retry for some xHCI hosts"). Fixes: f8f80be501aa ("xhci: Use soft retry to recover faster from transaction errors") Cc: Signed-off-by: Kuangyi Chiang Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-pci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 4b8c93e59d6d..0d49d9c390c1 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -399,6 +399,7 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) xhci->quirks |= XHCI_ETRON_HOST; xhci->quirks |= XHCI_RESET_ON_RESUME; xhci->quirks |= XHCI_BROKEN_STREAMS; + xhci->quirks |= XHCI_NO_SOFT_RETRY; } if (pdev->vendor == PCI_VENDOR_ID_RENESAS && From patchwork Wed Nov 6 10:14:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 841345 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 539B71DE2A6 for ; Wed, 6 Nov 2024 10:13:19 +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=1730888000; cv=none; b=Vw8LDi2ode309oZ0Z7DRTzkvJQjGrlxko5goCHr/tQGFClv21WX4EEy/eKxlq/fM19DRBfZtm8XS3BNhLXxN8WHKKtfQ2dJJDh/GZ0utCErQh54D9waRoL/3+FtGfbIqhHQ/1VyTVNyfOM45Su/mamQBiYf/bFcc+5sdRytfmso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730888000; c=relaxed/simple; bh=pygn/q4V3e2cG8IeM9yyEYRr7LoxDHOYGo6K0xzJAfw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=TpkxYX/0a4yo9/PxTp8Nn4Gcj37OzgEFgvOQlh3EzIYYbnJCH6URGjyBTu9SGM99qKo9bSYbeKOoXCucbvsm0L09dpcclhkUtlqq97e7yJlW8lnFxvgkVlx0ItRmqApYOSc/+5BzhE6WtSLicsyqkcu//YBus21DMI6T1EuYFh8= 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=GcYCUCxJ; 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="GcYCUCxJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730887999; x=1762423999; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pygn/q4V3e2cG8IeM9yyEYRr7LoxDHOYGo6K0xzJAfw=; b=GcYCUCxJcV2tBtx143DrkJE3ASuViUZws9nk+YxtfsqXDSMnyefgaPQa Angogp9rzTL/MaceBdslx1Mh98Ob6QQiSAEueZX82+9aj7tM9AL980wgF aNwWNhaocQALuhOsDKgUnVKtU4U2/vQWcqKF3q7emU91I93MfvpIIgG0E UDEfGKzV8XKmSYFye0yYZm75Lmn1YRYL7t3zLXqBjI89Pk/cuNJtRk4us KDlg87CkiO79POG+iWOG3kLTVRYO1pWB+/3uqiOQeWSPCLMe0TK1WcMHT lqpznLuUF+WgvBpgOnK5qcADS1bUbqzrOfXONkpBKKWhX3H0pJd2ST6Y6 g==; X-CSE-ConnectionGUID: AJ0z4E/pTXWPZfdoF0QYOA== X-CSE-MsgGUID: zQTkypOlQ9KKdYKuER/SPQ== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059439" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059439" 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:13:19 -0800 X-CSE-ConnectionGUID: NrjU9XdDRZuzz05o6X4s1Q== X-CSE-MsgGUID: 0BXSviNdQi2jYb7bcsug/w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813303" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:18 -0800 From: Mathias Nyman To: Cc: , Andy Shevchenko , Mathias Nyman Subject: [PATCH 21/33] xhci: pci: Use standard pattern for device IDs Date: Wed, 6 Nov 2024 12:14:47 +0200 Message-Id: <20241106101459.775897-22-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: Andy Shevchenko The definitions of vendor IDs follow the pattern PCI_VENDOR_ID_#vendor, while device IDs — PCI_DEVICE_ID_#vendor_#device. Update the ETRON device IDs to follow the above mentioned pattern. Signed-off-by: Andy Shevchenko Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-pci.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 0d49d9c390c1..77f9fe7a7dcd 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -34,9 +34,9 @@ #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1100 0x1100 #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1400 0x1400 -#define PCI_VENDOR_ID_ETRON 0x1b6f -#define PCI_DEVICE_ID_EJ168 0x7023 -#define PCI_DEVICE_ID_EJ188 0x7052 +#define PCI_VENDOR_ID_ETRON 0x1b6f +#define PCI_DEVICE_ID_ETRON_EJ168 0x7023 +#define PCI_DEVICE_ID_ETRON_EJ188 0x7052 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 @@ -394,8 +394,8 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW; if (pdev->vendor == PCI_VENDOR_ID_ETRON && - (pdev->device == PCI_DEVICE_ID_EJ168 || - pdev->device == PCI_DEVICE_ID_EJ188)) { + (pdev->device == PCI_DEVICE_ID_ETRON_EJ168 || + pdev->device == PCI_DEVICE_ID_ETRON_EJ188)) { xhci->quirks |= XHCI_ETRON_HOST; xhci->quirks |= XHCI_RESET_ON_RESUME; xhci->quirks |= XHCI_BROKEN_STREAMS; From patchwork Wed Nov 6 10:14:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842343 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 A439D1DE3D5 for ; Wed, 6 Nov 2024 10:13:20 +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=1730888002; cv=none; b=EVTh4OnMcx13pdrYoWFU6GDcI0yiYmos09aHvuDoR5WvJzOtFLg1CiqZln2U4xiiQImO6SiDmD8HSDUQKewFHl0Jwo7S+K8ma6t+y1KKZ2lEy8IVtYmuOnuaypJvHQkHgftjcjQyb+Tk1z+r9DDqUj7taKvzVWEe9BU8Igk6q7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730888002; c=relaxed/simple; bh=aZ2KXzdd9Gc95HmwOlL086nrEzEE8sFdxs1AcH6PeGA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TNa0Aj/mRgn1+veGiS/wK/yL6xqr+pgd4aFAU8CkUe93n9JJhYxg57/bFEdRTjzxqLqZueNxl8N9wZSrHbl/Pv8CKw0shAwzpWozvmCH+T1rlYW5CfxmJcP6Xak8zR5RxNgoDNVSCxO7PP9NwSNqi2gzyrqUq8iI7JLoa/GpULs= 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=QN2T5QBj; 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="QN2T5QBj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730888000; x=1762424000; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aZ2KXzdd9Gc95HmwOlL086nrEzEE8sFdxs1AcH6PeGA=; b=QN2T5QBjriUBM7DoxV7NbB7S1WSf91Ru71bnn5lRwBqpbl7WVXops45R s7/4ggyIfVwr9p6vTUEopmj2rZX7nTglnWGDMNz+5WOtq/sFhTFn+dZJv /mQnPBM/04Q0ebfoYbvRLJjh0i0VQLlEVwhGzfYn5nmMDLmj8KhEf22tD iD0INOwZbaf4IaXEYlFrAGZ1OkQQdaSLXOf+8lOo/83r9n8cZB2OLbsGD wNQD+PUaemTttv/wrDw9M/vXzgPvQWffWE4KXntHrLxhTgEgztwkr73Co 9/CNWJKwW2G6dkbguGYki/hHVFNtpeIDBJ0JHK1LB2RkFGlactN9JGkMC Q==; X-CSE-ConnectionGUID: XHptCIjaSqWiMC2GBH7fhw== X-CSE-MsgGUID: 7Tm5XPieTaCB3/Bf73EKig== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059445" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059445" 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:13:20 -0800 X-CSE-ConnectionGUID: HLHQYCo5TACe7rCEuceEZQ== X-CSE-MsgGUID: CR1ne/g+Rs2atc9wnopzzA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813317" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:19 -0800 From: Mathias Nyman To: Cc: , Andy Shevchenko Subject: [PATCH 22/33] xhci: pci: Fix indentation in the PCI device ID definitions Date: Wed, 6 Nov 2024 12:14:48 +0200 Message-Id: <20241106101459.775897-23-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: Andy Shevchenko Some of the definitions are missing the one TAB, add it to them. Signed-off-by: Andy Shevchenko --- drivers/usb/host/xhci-pci.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 77f9fe7a7dcd..b1f4dd3f9eff 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -28,8 +28,8 @@ #define SPARSE_CNTL_ENABLE 0xC12C /* Device for a quirk */ -#define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73 -#define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000 +#define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73 +#define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000 #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1009 0x1009 #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1100 0x1100 #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1400 0x1400 @@ -38,8 +38,8 @@ #define PCI_DEVICE_ID_ETRON_EJ168 0x7023 #define PCI_DEVICE_ID_ETRON_EJ188 0x7052 -#define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31 -#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 +#define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31 +#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 #define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI 0x9cb1 #define PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI 0x22b5 #define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI 0xa12f From patchwork Wed Nov 6 10:14:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 841344 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 969E91DE4F8 for ; Wed, 6 Nov 2024 10:13:22 +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=1730888004; cv=none; b=sqDNMxRChWTh9MIMelTysvrnbq636bUMvP+oYREGKpX3Gqb9O7a9RNjfo7P2pNxmfvgthOSf9JKvOmBvUoCSex2aU+DMMcE/BPr2meSfGmopRGtFuVe+m3OFIHsZsWmaR8Kzyg9jkT6tY2CQn1+jaY8vWv7UCLSDFJWV2ca2Z+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730888004; c=relaxed/simple; bh=gONpo+NQLyP8LHQvHOxi5fG67GX5lX8ClVlcHb2k/jc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EX4FfEsPQIMoOe2u+0rb56sSWuAFcJqplNtwjFYo+kW6ahN16jQTnjXWiWowHNcpmFVeATZDkYW1b/S1MJuDWzhDoEaBEE9YXsXqIaa/lD7GyHBYkDloRkmGug6vYQDpKSO0rumgHPRNlaJGQiYrKfxOYYFRQywOEvcsJqwbdYQ= 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=D6uBclax; 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="D6uBclax" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730888002; x=1762424002; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gONpo+NQLyP8LHQvHOxi5fG67GX5lX8ClVlcHb2k/jc=; b=D6uBclaxLz3mbK1H/4foiKweFstyPm0rdiXs4SvUfJCqu3v1lUFewkqd 2Av6uD/dA4JgLfNRJ6djXBSgNh6ArjJdnoaFQFHZw7witCCemYcYhN9Fv h8iAnCxY3uvaIiuKZ1FHDxNGnw/kGQWndKzQE3xlgBIVpCw7oH2M7SXtn pDCDSQIlrkj2t89IqddGGGSp6u4kGq7Vg66pEqqUemY1P61jcopqMWrAu N+KwQIwjF+E+PJgYwo5MMvlyJspojqMm4luAjYAPhnqJwpoNVmCU2dN60 gd+w9mdh1FnUyy72dwCFoztOWQceyvzxX4qVYC1CoZBxl7cI3MmIPzvLE A==; X-CSE-ConnectionGUID: tvPvIGj+T3eVn0qgxHa8rQ== X-CSE-MsgGUID: znmPF91QRTOFU45DMJ594w== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059451" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059451" 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:13:22 -0800 X-CSE-ConnectionGUID: 17JZI5pdTH2VQGSghYdrMA== X-CSE-MsgGUID: AwP4/93URpC3JQh/yo1XZA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813328" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:21 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 23/33] usb: xhci: simplify TDs start and end naming scheme in struct 'xhci_td' Date: Wed, 6 Nov 2024 12:14:49 +0200 Message-Id: <20241106101459.775897-24-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: Niklas Neronin Old names: * start_seg - last_trb_seg * first_trb - last_trb New names: * start_seg - end_seg * start_trb - end_trb A Transfer Descriptor (TD) in the xhci driver is a data structure that represents a single transaction to be performed by the USB host controller. This transaction is defined by TRBs from 'start_trb' in 'start_seg' to 'end_trb' in 'end_seg'. The terms "start" and "end" were chosen over "first" and "last" for ease of searching within the codebase. The ring structure uses 'first_seg' and 'last_seg', while the TD structure uses 'start_seg' and 'end_seg'. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 68 ++++++++++++++++++------------------ drivers/usb/host/xhci.c | 2 +- drivers/usb/host/xhci.h | 6 ++-- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 517df97ef496..1b4c785c8dad 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -660,8 +660,8 @@ static int xhci_move_dequeue_past_td(struct xhci_hcd *xhci, /* * We want to find the pointer, segment and cycle state of the new trb - * (the one after current TD's last_trb). We know the cycle state at - * hw_dequeue, so walk the ring until both hw_dequeue and last_trb are + * (the one after current TD's end_trb). We know the cycle state at + * hw_dequeue, so walk the ring until both hw_dequeue and end_trb are * found. */ do { @@ -671,7 +671,7 @@ static int xhci_move_dequeue_past_td(struct xhci_hcd *xhci, if (td_last_trb_found) break; } - if (new_deq == td->last_trb) + if (new_deq == td->end_trb) td_last_trb_found = true; if (cycle_found && trb_is_link(new_deq) && @@ -744,16 +744,16 @@ static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, struct xhci_td *td, bool flip_cycle) { struct xhci_segment *seg = td->start_seg; - union xhci_trb *trb = td->first_trb; + union xhci_trb *trb = td->start_trb; while (1) { trb_to_noop(trb, TRB_TR_NOOP); /* flip cycle if asked to */ - if (flip_cycle && trb != td->first_trb && trb != td->last_trb) + if (flip_cycle && trb != td->start_trb && trb != td->end_trb) trb->generic.field[3] ^= cpu_to_le32(TRB_CYCLE); - if (trb == td->last_trb) + if (trb == td->end_trb) break; next_trb(&seg, &trb); @@ -978,7 +978,7 @@ static int xhci_invalidate_cancelled_tds(struct xhci_virt_ep *ep) xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, "Removing canceled TD starting at 0x%llx (dma) in stream %u URB %p", (unsigned long long)xhci_trb_virt_to_dma( - td->start_seg, td->first_trb), + td->start_seg, td->start_trb), td->urb->stream_id, td->urb); list_del_init(&td->td_list); ring = xhci_urb_to_transfer_ring(xhci, td->urb); @@ -2078,7 +2078,7 @@ struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, struct xhci_td *td, dma_ad dma_addr_t end_trb_dma; struct xhci_segment *cur_seg; - start_dma = xhci_trb_virt_to_dma(td->start_seg, td->first_trb); + start_dma = xhci_trb_virt_to_dma(td->start_seg, td->start_trb); cur_seg = td->start_seg; do { @@ -2088,7 +2088,7 @@ struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, struct xhci_td *td, dma_ad end_seg_dma = xhci_trb_virt_to_dma(cur_seg, &cur_seg->trbs[TRBS_PER_SEGMENT - 1]); /* If the end TRB isn't in this segment, this is set to 0 */ - end_trb_dma = xhci_trb_virt_to_dma(cur_seg, td->last_trb); + end_trb_dma = xhci_trb_virt_to_dma(cur_seg, td->end_trb); if (debug) xhci_warn(xhci, @@ -2230,7 +2230,7 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, !list_empty(&td->cancelled_td_list)) { xhci_dbg(xhci, "Already resolving halted ep for 0x%llx\n", (unsigned long long)xhci_trb_virt_to_dma( - td->start_seg, td->first_trb)); + td->start_seg, td->start_trb)); return 0; } /* endpoint not halted, don't reset it */ @@ -2262,8 +2262,8 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, } /* Update ring dequeue pointer */ - ep_ring->dequeue = td->last_trb; - ep_ring->deq_seg = td->last_trb_seg; + ep_ring->dequeue = td->end_trb; + ep_ring->deq_seg = td->end_seg; inc_deq(xhci, ep_ring); return xhci_td_cleanup(xhci, td, ep_ring, td->status); @@ -2273,7 +2273,7 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, static u32 sum_trb_lengths(struct xhci_td *td, union xhci_trb *stop_trb) { u32 sum; - union xhci_trb *trb = td->first_trb; + union xhci_trb *trb = td->start_trb; struct xhci_segment *seg = td->start_seg; for (sum = 0; trb != stop_trb; next_trb(&seg, &trb)) { @@ -2428,7 +2428,7 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, fallthrough; case COMP_ISOCH_BUFFER_OVERRUN: frame->status = -EOVERFLOW; - if (ep_trb != td->last_trb) + if (ep_trb != td->end_trb) td->error_mid_td = true; break; case COMP_INCOMPATIBLE_DEVICE_ERROR: @@ -2438,7 +2438,7 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, case COMP_USB_TRANSACTION_ERROR: frame->status = -EPROTO; sum_trbs_for_length = true; - if (ep_trb != td->last_trb) + if (ep_trb != td->end_trb) td->error_mid_td = true; break; case COMP_STOPPED: @@ -2474,7 +2474,7 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, finish_td: /* Don't give back TD yet if we encountered an error mid TD */ - if (td->error_mid_td && ep_trb != td->last_trb) { + if (td->error_mid_td && ep_trb != td->end_trb) { xhci_dbg(xhci, "Error mid isoc TD, wait for final completion event\n"); td->urb_length_set = true; return 0; @@ -2501,8 +2501,8 @@ static int skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, frame->actual_length = 0; /* Update ring dequeue pointer */ - ep->ring->dequeue = td->last_trb; - ep->ring->deq_seg = td->last_trb_seg; + ep->ring->dequeue = td->end_trb; + ep->ring->deq_seg = td->end_seg; inc_deq(xhci, ep->ring); return xhci_td_cleanup(xhci, td, ep->ring, status); @@ -2529,7 +2529,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, case COMP_SUCCESS: ep->err_count = 0; /* handle success with untransferred data as short packet */ - if (ep_trb != td->last_trb || remaining) { + if (ep_trb != td->end_trb || remaining) { xhci_warn(xhci, "WARN Successful completion on short TX\n"); xhci_dbg(xhci, "ep %#x - asked for %d bytes, %d bytes untransferred\n", td->urb->ep->desc.bEndpointAddress, @@ -2562,7 +2562,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, break; } - if (ep_trb == td->last_trb) + if (ep_trb == td->end_trb) td->urb->actual_length = requested - remaining; else td->urb->actual_length = @@ -2795,8 +2795,8 @@ static int handle_tx_event(struct xhci_hcd *xhci, if (td && td->error_mid_td && !trb_in_td(xhci, td, ep_trb_dma, false)) { 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; + ep_ring->dequeue = td->end_trb; + ep_ring->deq_seg = td->end_seg; inc_deq(xhci, ep_ring); xhci_td_cleanup(xhci, td, ep_ring, td->status); } @@ -3308,7 +3308,7 @@ static int prepare_transfer(struct xhci_hcd *xhci, /* Add this TD to the tail of the endpoint ring's TD list */ list_add_tail(&td->td_list, &ep_ring->td_list); td->start_seg = ep_ring->enq_seg; - td->first_trb = ep_ring->enqueue; + td->start_trb = ep_ring->enqueue; return 0; } @@ -3647,8 +3647,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, field &= ~TRB_CHAIN; field |= TRB_IOC; more_trbs_coming = false; - td->last_trb = ring->enqueue; - td->last_trb_seg = ring->enq_seg; + td->end_trb = ring->enqueue; + td->end_seg = ring->enq_seg; if (xhci_urb_suitable_for_idt(urb)) { memcpy(&send_addr, urb->transfer_buffer, trb_buff_len); @@ -3696,8 +3696,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index, urb->stream_id, 1, urb, 1, mem_flags); - urb_priv->td[1].last_trb = ring->enqueue; - urb_priv->td[1].last_trb_seg = ring->enq_seg; + urb_priv->td[1].end_trb = ring->enqueue; + urb_priv->td[1].end_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); } @@ -3835,8 +3835,8 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, } /* Save the DMA address of the last TRB in the TD */ - td->last_trb = ep_ring->enqueue; - td->last_trb_seg = ep_ring->enq_seg; + td->end_trb = ep_ring->enqueue; + td->end_seg = ep_ring->enq_seg; /* Queue status TRB - see Table 7 and sections 4.11.2.2 and 6.4.1.2.3 */ /* If the device sent data, the status stage is an OUT transfer */ @@ -4121,8 +4121,8 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, field |= TRB_CHAIN; } else { more_trbs_coming = false; - td->last_trb = ep_ring->enqueue; - td->last_trb_seg = ep_ring->enq_seg; + td->end_trb = ep_ring->enqueue; + td->end_seg = ep_ring->enq_seg; field |= TRB_IOC; if (trb_block_event_intr(xhci, num_tds, i, ir)) field |= TRB_BEI; @@ -4188,14 +4188,14 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, /* Use the first TD as a temporary variable to turn the TDs we've queued * into No-ops with a software-owned cycle bit. That way the hardware * won't accidentally start executing bogus TDs when we partially - * overwrite them. td->first_trb and td->start_seg are already set. + * overwrite them. td->start_trb and td->start_seg are already set. */ - urb_priv->td[0].last_trb = ep_ring->enqueue; + urb_priv->td[0].end_trb = ep_ring->enqueue; /* Every TRB except the first & last will have its cycle bit flipped. */ td_to_noop(xhci, ep_ring, &urb_priv->td[0], true); /* Reset the ring enqueue back to the first TRB and its cycle bit. */ - ep_ring->enqueue = urb_priv->td[0].first_trb; + ep_ring->enqueue = urb_priv->td[0].start_trb; ep_ring->enq_seg = urb_priv->td[0].start_seg; ep_ring->cycle_state = start_cycle; usb_hcd_unlink_urb_from_ep(bus_to_hcd(urb->dev->bus), urb); diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index ae16253b53fb..a5ac1e01f82d 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1752,7 +1752,7 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) urb->ep->desc.bEndpointAddress, (unsigned long long) xhci_trb_virt_to_dma( urb_priv->td[i].start_seg, - urb_priv->td[i].first_trb)); + urb_priv->td[i].start_trb)); for (; i < urb_priv->num_tds; i++) { td = &urb_priv->td[i]; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index a0204e10486d..a0e992c3db0d 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1294,9 +1294,9 @@ struct xhci_td { enum xhci_cancelled_td_status cancel_status; struct urb *urb; struct xhci_segment *start_seg; - union xhci_trb *first_trb; - union xhci_trb *last_trb; - struct xhci_segment *last_trb_seg; + union xhci_trb *start_trb; + struct xhci_segment *end_seg; + union xhci_trb *end_trb; struct xhci_segment *bounce_seg; /* actual_length of the URB has already been set */ bool urb_length_set; From patchwork Wed Nov 6 10:14:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842342 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 F10F71DDA3B for ; Wed, 6 Nov 2024 10:13:23 +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=1730888005; cv=none; b=Z9N4m6r0VhZRr9fZmGX3PoKD9psYIe9yzWLtss/kUu+bYJeJXSfO/duczd5nadEudsEQIKBr1fTuV4oplaj7g8CKgELcNmlKbg/zXtvgxJ5rBAdBH44KVBYsKMi6RLHevxJ8Sd06i9U9f2zcDyNeRBTnvJZX0a8M5Z1xxBo05e4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730888005; c=relaxed/simple; bh=ICMkl8q7QvlDa/ESydkdNUkoJGv3ehZ1PUrusOeBY6c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZtSIwixczoTww3NwqGaFPAE4vYv/l276F5E40CBaaluc8B5+IYjoqj6GCoCwXc53Jug5VSGPE3cFtCchsHQF5k8oqu5gGwYJoX/dhZ6nBSUu6AVCOj1kQDCeuDk3PkbbTewYQV/3wPi0oI+AyDnC+nREo4a8CkMHz9OC1onHJdg= 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=K1DsxPN7; 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="K1DsxPN7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730888004; x=1762424004; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ICMkl8q7QvlDa/ESydkdNUkoJGv3ehZ1PUrusOeBY6c=; b=K1DsxPN7W3JjC7Zck5T4aHL4iKvGO/laT4Bx+Pe/nWclZNf4RlVH1GEl tFl2JldsFvvTLpSnDuxv1Cym8QQQwIBT1XRabWNggrkeujEq3V017vQSd Z91j7SZ2frLSslyf+r+blT1AB8MHkKP7P+Se+pXWMj4aD7uoQE5nv1XwY 56MnsCxlzz9Xlyw8x/MW/SsYBVi8CYcsNGCuFLoXpM/s/Kox+cDqHS3Jr 0OKJM8rvGD/bv1Lqid30JT9/uluicKBCWjX9DOq8DbIHd8u2DxwBTwD8u zX19KoLpsiMHY8UTFmMzqA4JSlqohcAmdvLXKvrKOa2d2zxnQBQG8EzhZ w==; X-CSE-ConnectionGUID: Yt8i4wmfSxeXu0C6NbNvLg== X-CSE-MsgGUID: aLx9bIDlQNyMNOfx9VX5FA== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059454" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059454" 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:13:23 -0800 X-CSE-ConnectionGUID: 5DbZUJoiRYqPugyPONNkyg== X-CSE-MsgGUID: NJ6ndy5cQgaaaP0i3huJMQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813342" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:22 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 24/33] usb: xhci: move link TRB quirk to xhci_gen_setup() Date: Wed, 6 Nov 2024 12:14:50 +0200 Message-Id: <20241106101459.775897-25-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: Niklas Neronin This quirk is old and seldom seen, as a result the trace is changed to debug message and only printed when the quirk is set. Move it into xhci_gen_setup() where the majority of quirks are set. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index a5ac1e01f82d..e5719fd45a38 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -473,14 +473,7 @@ static int xhci_init(struct usb_hcd *hcd) xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_init"); spin_lock_init(&xhci->lock); - if (xhci->hci_version == 0x95 && link_quirk) { - xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, - "QUIRK: Not clearing Link TRB chain bits."); - xhci->quirks |= XHCI_LINK_TRB_QUIRK; - } else { - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "xHCI doesn't need link TRB QUIRK"); - } + retval = xhci_mem_init(xhci, GFP_KERNEL); xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished xhci_init"); @@ -5311,6 +5304,11 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks) if (xhci->hci_version > 0x96) xhci->quirks |= XHCI_SPURIOUS_SUCCESS; + if (xhci->hci_version == 0x95 && link_quirk) { + xhci_dbg(xhci, "QUIRK: Not clearing Link TRB chain bits"); + xhci->quirks |= XHCI_LINK_TRB_QUIRK; + } + /* Make sure the HC is halted. */ retval = xhci_halt(xhci); if (retval) From patchwork Wed Nov 6 10:14:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 841343 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 593191DE889 for ; Wed, 6 Nov 2024 10:13:25 +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=1730888006; cv=none; b=Q/YU8GwVGNpPUh9TKK4EQWW7qrH7Q2y2HyMCdef/3Nq5AdDRNCYb85M7BQOY0tAe1pWVTskZzqv8Fmd4e6HqvmkoYdiiKxVUs4W2CYuoHAl5e0Ksxsm3lerq4K6fPeTTf1a8WIOUvexUa+yqzR12pd5+uPx912Ra2caN3SI+yzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730888006; c=relaxed/simple; bh=rNjVof70rreHdzjKu0X5PBB0SfsBcqUjXht8B1JT1EQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J/7W4XgmgWahowDCUEt1kg7TfnYjyzhCMm875C/RVYfRFn6N1tueyXLOV359Ls8l+v+p1NZv9OKgmA7+WXsFoKPHHmOmfnyhln/+wbFRbPqAZzdLvFSulJQ4kUvYEcV5qVp8f5N1eNnpRCGazYWIW5L2nMhuFc3CR9wPtNQpR7E= 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=NIhROk7O; 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="NIhROk7O" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730888005; x=1762424005; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rNjVof70rreHdzjKu0X5PBB0SfsBcqUjXht8B1JT1EQ=; b=NIhROk7OldeVE6QcYME77PHtBtknyi4lfxiWkRatIZLyWJ1uVlvmdRcY PrRsiFA2gdZw4pEYdHyRDYW5j6zszFV8VtfQkKrGRM45p2Cefb1eg/wG9 9AE93ZVcVBNSATuIwOXBLrURQu/C3txa4SSdnVEdvl57dI9vpxzHeNGb4 kFxZ+8SkEfNyghjzAnqpaufHbiI9aqdxa0yyYpdnJSjjNQ3E4h/ID2QN9 mIPwya9wTb7jCh4Sg8TBcNz0JN3/skOiipM0v+v/wt8sLvRBwq2zGPuxS tREKIO4BjA+Y2fgUbvBW1xmtFMeNjsUr42G974NO3EZ/8gsSnMYAEy+JD g==; X-CSE-ConnectionGUID: D5C+i/KySoaicaczCMUBTQ== X-CSE-MsgGUID: Y/hGy0EERBWz1qsDXdeGmg== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059459" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059459" 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:13:25 -0800 X-CSE-ConnectionGUID: uEYEhz4ZS2aobLX4GTzdIQ== X-CSE-MsgGUID: bCTmTM19QOGBTDbHWvB6ig== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813354" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:24 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 25/33] usb: xhci: request MSI/-X according to requested amount Date: Wed, 6 Nov 2024 12:14:51 +0200 Message-Id: <20241106101459.775897-26-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: Niklas Neronin Variable 'max_interrupters' contains the maximum supported interrupters or the maximum interrupters the user has requested. Thus, it should be used instead of HCS_MAX_INTRS(). User set 'max_interrupters' value is validated in xhci_gen_setup(), otherwise 'max_interrupters' value is 'HCS_MAX_INTRS(xhci->hcs_params1)'. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-pci.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index b1f4dd3f9eff..47c4f70793e4 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -149,14 +149,11 @@ static int xhci_try_enable_msi(struct usb_hcd *hcd) hcd->irq = 0; /* - * calculate number of MSI-X vectors supported. - * - HCS_MAX_INTRS: the max number of interrupts the host can handle, - * with max number of interrupters based on the xhci HCSPARAMS1. - * - num_online_cpus: maximum MSI-X vectors per CPUs core. - * Add additional 1 vector to ensure always available interrupt. + * Calculate number of MSI/MSI-X vectors supported. + * - max_interrupters: the max number of interrupts requested, capped to xhci HCSPARAMS1. + * - num_online_cpus: one vector per CPUs core, with at least one overall. */ - xhci->nvecs = min(num_online_cpus() + 1, - HCS_MAX_INTRS(xhci->hcs_params1)); + xhci->nvecs = min(num_online_cpus() + 1, xhci->max_interrupters); /* TODO: Check with MSI Soc for sysdev */ xhci->nvecs = pci_alloc_irq_vectors(pdev, 1, xhci->nvecs, From patchwork Wed Nov 6 10:14:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842341 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 4FA6B1DE2BA for ; Wed, 6 Nov 2024 10:13:27 +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=1730888009; cv=none; b=lnVK0ILN3Be5LW+dcwQfLqUvssWRNalHFySCetSo9W0ZQdR6RbCjFpKAgz4UwbuXYspjg5oPrsDUmJr7gHhsxKPrPVoWhr12THHyV/fkAr5lvZYaplCdJGFDHBz0paadsTtF7iSQFwr3l7Qf4J/DabbU4sJkgiWW0ezoCGYtC0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730888009; c=relaxed/simple; bh=xPnncC2wTinnsqvRulyZjDNfjp1oi2Wkye5abU3hCPE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iAJuJXhbrrGCbZnmTXZ06WI0MA+64S7HuiG/D/O3V3sxy5pLJEqG6T8CB3HfDcjJx4UiPmbubJ/5ytKg1p2p8Q3w2uxxq+Dg1aZHzbA1QPVn8+0C5oH/7fG4As721xb5KbLovhdsdSwLnNw69aIm/5gJAxZ7QalvyK4ySYMPjmE= 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=ikmaFtrz; 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="ikmaFtrz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730888008; x=1762424008; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xPnncC2wTinnsqvRulyZjDNfjp1oi2Wkye5abU3hCPE=; b=ikmaFtrznzN6EQj2NyV33Q7guXiUdIUdkN0F9aJPr5So7MhMa/FLODHZ 6sbDhhDIDY89+Fz/eqzmWS63YxP2qTPcAr3q2r476FlOEzVzDFflntnt9 Meql2+lvQ7odwwFRAU45AqwBF/2mCm4cAzbo4V4NFoVlx7dTmjMc9UfTU lGe9Ax3Gstuo2StIr9v5as2JnJOCJI2i7+xUbnkX2uFEOHmZiTL4p2EMG RRvn1blvhdlYVqyPz/rIgRK+vTXJC4C9Q64+vovkyNxfES0ejXqQYiq7G 1yzhA9TKjxdpgoLEsuF+flWaGqs4o6wXunHsQtDAmHZitmbgqJdfF5AUn A==; X-CSE-ConnectionGUID: 9w8w3tBWQiKvG+IRHw9BCA== X-CSE-MsgGUID: amLOTmfYQhiWnhSFSDty7A== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059467" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059467" 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:13:26 -0800 X-CSE-ConnectionGUID: m3Dqe88JTaO27Dp8/n58hQ== X-CSE-MsgGUID: 39F/KqGrQSK0IRfDw/uTVA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813388" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:25 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 26/33] usb: xhci: improve xhci_clear_command_ring() Date: Wed, 6 Nov 2024 12:14:52 +0200 Message-Id: <20241106101459.775897-27-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: Niklas Neronin Remove redundant TRB cycle reset, the TRB cycle is already set to zero by the preceding memset(), making the explicit reset unnecessary. Clarify ring loop start point. Change the loop start from the dequeue segment to the start segment. Both approaches achieve the same result, but starting from the start segment makes it clearer that the entire ring is being zeroed out. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index e5719fd45a38..bc477cf99805 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -778,10 +778,8 @@ static void xhci_clear_command_ring(struct xhci_hcd *xhci) struct xhci_segment *seg; ring = xhci->cmd_ring; - xhci_for_each_ring_seg(ring->deq_seg, seg) { + xhci_for_each_ring_seg(ring->first_seg, seg) memset(seg->trbs, 0, sizeof(union xhci_trb) * (TRBS_PER_SEGMENT - 1)); - seg->trbs[TRBS_PER_SEGMENT - 1].link.control &= cpu_to_le32(~TRB_CYCLE); - } xhci_initialize_ring_info(ring); /* From patchwork Wed Nov 6 10:14:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 841342 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 97EED1DDC0A for ; Wed, 6 Nov 2024 10:13:28 +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=1730888010; cv=none; b=XyOsbUVRKBDsmp9oSOtPC+XSuVkKEl/m0aneiReo+uTeT51ANEHYsTR+4tnBO6DAURBkHpEQzmokD/usU+Ca6ZyoDmrR1z+xEdpnkOmnmPJfWqb669IZGk2NnFSri9dIMbf7FHhVYH7X+R+AqZZwQdU/6J5oggNPV8V0Vq21W9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730888010; c=relaxed/simple; bh=XttzDm5E0W6RN/87pwXVykI0SULiUFkL+YmK+Kl9mj4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uV1I1KybLUMkHQIC9H7XH0rzRbVgCX/eoNyI/GRIPro6XMEX3mq0ubdaz9ddkC0je6vzgIcID3jnX6U9ggzhPUQqEotjoeVWPw0EpAvcd13ryMngVbGx8djQJZ8fmBDj3BtLAGP+uo7OPKwwEiQKtix9sgKu4q5Wmha/p6cqTB4= 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=gwzdA8HD; 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="gwzdA8HD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730888008; x=1762424008; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XttzDm5E0W6RN/87pwXVykI0SULiUFkL+YmK+Kl9mj4=; b=gwzdA8HDHxlSlwCtBLaQnVCP2vgLAlf3tx8gorDhTz8YF5U/rF1qkt1r MBu7AXbYk1/dR6HkOGx3vWt7CuviDKtTsr089Ev3y++VqFe6oH02uPAyT 1+tUNJYzl1JA1baVQpmiQAP6kiKJMQtgsltxBUyuwzTjqdY+BDXFAIhFi xDt8K3/FiPGuxFM5bTFynMXIbSkFZCy2YraT75LWQ9N45IFyNWW4eualn 0kAhOIekEqcAMAXcaKI2DAzpr4PVCothHw1DgyVUDHbYCUKnm6pX4i+ZS WteJvVoXiB2qWgDQr/la2xjtJDK0Koxed5sMC3UnhSCRj0DZHOqdK5uDm A==; X-CSE-ConnectionGUID: wWan8mQAQo++b2Cm8BU2oA== X-CSE-MsgGUID: leyVeFReQ2iCuPGSPLmS8w== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059473" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059473" 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:13:28 -0800 X-CSE-ConnectionGUID: fr9hWpt8SSyKVk0J0co1fA== X-CSE-MsgGUID: RIy8/rjqQnG+8v87QEho7w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813409" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:27 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 27/33] usb: xhci: remove unused arguments from td_to_noop() Date: Wed, 6 Nov 2024 12:14:53 +0200 Message-Id: <20241106101459.775897-28-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: Niklas Neronin Function td_to_noop() does not utilize arguments 'xhci' and 'ep_ring'. These unused arguments are removed to clean up the code. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 1b4c785c8dad..5fb3d771c429 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -740,8 +740,7 @@ static int xhci_move_dequeue_past_td(struct xhci_hcd *xhci, * (The last TRB actually points to the ring enqueue pointer, which is not part * of this TD.) This is used to remove partially enqueued isoc TDs from a ring. */ -static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, - struct xhci_td *td, bool flip_cycle) +static void td_to_noop(struct xhci_td *td, bool flip_cycle) { struct xhci_segment *seg = td->start_seg; union xhci_trb *trb = td->start_trb; @@ -1020,16 +1019,16 @@ static int xhci_invalidate_cancelled_tds(struct xhci_virt_ep *ep) "Found multiple active URBs %p and %p in stream %u?\n", td->urb, cached_td->urb, td->urb->stream_id); - td_to_noop(xhci, ring, cached_td, false); + td_to_noop(cached_td, false); cached_td->cancel_status = TD_CLEARED; } - td_to_noop(xhci, ring, td, false); + td_to_noop(td, false); td->cancel_status = TD_CLEARING_CACHE; cached_td = td; break; } } else { - td_to_noop(xhci, ring, td, false); + td_to_noop(td, false); td->cancel_status = TD_CLEARED; } } @@ -1054,7 +1053,7 @@ static int xhci_invalidate_cancelled_tds(struct xhci_virt_ep *ep) continue; xhci_warn(xhci, "Failed to clear cancelled cached URB %p, mark clear anyway\n", td->urb); - td_to_noop(xhci, ring, td, false); + td_to_noop(td, false); td->cancel_status = TD_CLEARED; } } @@ -4192,7 +4191,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, */ urb_priv->td[0].end_trb = ep_ring->enqueue; /* Every TRB except the first & last will have its cycle bit flipped. */ - td_to_noop(xhci, ep_ring, &urb_priv->td[0], true); + td_to_noop(&urb_priv->td[0], true); /* Reset the ring enqueue back to the first TRB and its cycle bit. */ ep_ring->enqueue = urb_priv->td[0].start_trb; From patchwork Wed Nov 6 10:14:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842340 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 2AE0A1DE8AA for ; Wed, 6 Nov 2024 10:13:30 +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=1730888011; cv=none; b=JDqq7Qvqb0wtyvn2hIzMD7ugUgXQBilTbqqbcQ2owyzauLDHry+h/Mpl3rs9k9r1RY+PnwRwmNb+59jmvawff3Td6Pj3pNqYXVlGeF3+Ldc55lcYrV0fSYj9vdpjK5qoh3a9xYQ9QOeEkkrYqk4mRzdEMcgsBKkXtE2pGaZng6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730888011; c=relaxed/simple; bh=BsqcQoLz31NUGk4D30J66jxMbQhfN7Jun3SYK0RaRmg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gStVEibSo+YJ4yA00bYJDYatRr44HWnP55WmakP9SZsZKwYgXNetsFESr4AXbz49yzlYvc2M0seJEJqhb0SGPlylF2SYKjCQO+aeW5fWwhrHSomXKr0vaom18EvkvsqtAk2q7iHYlPX6l9mZ7JPNGhHLWG7MmnHYc+KdNdfWWcM= 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=gnIU3Xpt; 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="gnIU3Xpt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730888010; x=1762424010; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BsqcQoLz31NUGk4D30J66jxMbQhfN7Jun3SYK0RaRmg=; b=gnIU3XptlkzQwkzvJZ6c20Rqy8qJpj59IoZK6PQXs7FES93Zi/i1g6YT PnDiaQHqHjCeBL/Kl+iijnip6phbWbBaXExDGEa1cElRdGGW2M34Cc1NX jMGyfsSMCrbHRt25r6N79k9gea42QuOD9X2KbXqsK58isgq4OCje8hW8Z Ss+d7TmGtfouBt4kwplVgCy5mw7M4N08q+7orat5gIMSdFem1XBXe8FxD LLSKf/XJNu4x3lVDZlbXF5HeTd+QWOlym4J9zeq/NT4UHY5EHxALXq4/1 gNDutR6s4ArJ8IHOpXh4FbFhw8R9s6dFri3hc25rM3cfBrqeuG8s9hlrk w==; X-CSE-ConnectionGUID: 4c5Wz+/gR5qQcuAW2yYhZw== X-CSE-MsgGUID: a1TdEZyWSUC+TIxbN6RYCA== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059475" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059475" 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:13:30 -0800 X-CSE-ConnectionGUID: UvbTm1KlQNGF+EcY3uRYqg== X-CSE-MsgGUID: oBrppINQSUeg3efkk/ekmg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813443" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:29 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 28/33] usb: xhci: refactor xhci_td_cleanup() to return void Date: Wed, 6 Nov 2024 12:14:54 +0200 Message-Id: <20241106101459.775897-29-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: Niklas Neronin The function is modified to return 'void' instead of an integer since it invariably returns '0'. Additionally, multiple functions which only return xhci_td_cleanup() are also refactored to return void. This change eliminates the need for callers to handle a return value that does not convey meaningful information and improve code readability, as it becomes immediately clear that the function does not produce a significant output. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 59 +++++++++++++++++------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 5fb3d771c429..e48ee58fdb46 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -813,8 +813,8 @@ static void xhci_unmap_td_bounce_buffer(struct xhci_hcd *xhci, seg->bounce_offs = 0; } -static int xhci_td_cleanup(struct xhci_hcd *xhci, struct xhci_td *td, - struct xhci_ring *ep_ring, int status) +static void xhci_td_cleanup(struct xhci_hcd *xhci, struct xhci_td *td, + struct xhci_ring *ep_ring, int status) { struct urb *urb = NULL; @@ -857,8 +857,6 @@ static int xhci_td_cleanup(struct xhci_hcd *xhci, struct xhci_td *td, status = 0; xhci_giveback_urb_in_irq(xhci, td, status); } - - return 0; } @@ -2187,9 +2185,9 @@ int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code) return 0; } -static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, - struct xhci_ring *ep_ring, struct xhci_td *td, - u32 trb_comp_code) +static void finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, + struct xhci_ring *ep_ring, struct xhci_td *td, + u32 trb_comp_code) { struct xhci_ep_ctx *ep_ctx; @@ -2204,7 +2202,7 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, * stopped TDs. A stopped TD may be restarted, so don't update * the ring dequeue pointer or take this TD off any lists yet. */ - return 0; + return; case COMP_USB_TRANSACTION_ERROR: case COMP_BABBLE_DETECTED_ERROR: case COMP_SPLIT_TRANSACTION_ERROR: @@ -2230,7 +2228,7 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, xhci_dbg(xhci, "Already resolving halted ep for 0x%llx\n", (unsigned long long)xhci_trb_virt_to_dma( td->start_seg, td->start_trb)); - return 0; + return; } /* endpoint not halted, don't reset it */ break; @@ -2238,7 +2236,7 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, /* Almost same procedure as for STALL_ERROR below */ xhci_clear_hub_tt_buffer(xhci, td, ep); xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET); - return 0; + return; case COMP_STALL_ERROR: /* * xhci internal endpoint state will go to a "halt" state for @@ -2255,7 +2253,7 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET); - return 0; /* xhci_handle_halted_endpoint marked td cancelled */ + return; /* xhci_handle_halted_endpoint marked td cancelled */ default: break; } @@ -2265,7 +2263,7 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, ep_ring->deq_seg = td->end_seg; inc_deq(xhci, ep_ring); - return xhci_td_cleanup(xhci, td, ep_ring, td->status); + xhci_td_cleanup(xhci, td, ep_ring, td->status); } /* sum trb lengths from the first trb up to stop_trb, _excluding_ stop_trb */ @@ -2285,9 +2283,9 @@ static u32 sum_trb_lengths(struct xhci_td *td, union xhci_trb *stop_trb) /* * Process control tds, update urb status and actual_length. */ -static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, - struct xhci_ring *ep_ring, struct xhci_td *td, - union xhci_trb *ep_trb, struct xhci_transfer_event *event) +static void process_ctrl_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, + struct xhci_ring *ep_ring, struct xhci_td *td, + union xhci_trb *ep_trb, struct xhci_transfer_event *event) { struct xhci_ep_ctx *ep_ctx; u32 trb_comp_code; @@ -2366,7 +2364,7 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, td->urb_length_set = true; td->urb->actual_length = requested - remaining; xhci_dbg(xhci, "Waiting for status stage event\n"); - return 0; + return; } /* at status stage */ @@ -2374,15 +2372,15 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, td->urb->actual_length = requested; finish_td: - return finish_td(xhci, ep, ep_ring, td, trb_comp_code); + finish_td(xhci, ep, ep_ring, td, trb_comp_code); } /* * Process isochronous tds, update urb packet status and actual_length. */ -static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, - struct xhci_ring *ep_ring, struct xhci_td *td, - union xhci_trb *ep_trb, struct xhci_transfer_event *event) +static void process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, + struct xhci_ring *ep_ring, struct xhci_td *td, + union xhci_trb *ep_trb, struct xhci_transfer_event *event) { struct urb_priv *urb_priv; int idx; @@ -2476,14 +2474,13 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, if (td->error_mid_td && ep_trb != td->end_trb) { xhci_dbg(xhci, "Error mid isoc TD, wait for final completion event\n"); td->urb_length_set = true; - return 0; + return; } - - return finish_td(xhci, ep, ep_ring, td, trb_comp_code); + finish_td(xhci, ep, ep_ring, td, trb_comp_code); } -static int skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, - struct xhci_virt_ep *ep, int status) +static void skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, + struct xhci_virt_ep *ep, int status) { struct urb_priv *urb_priv; struct usb_iso_packet_descriptor *frame; @@ -2504,15 +2501,15 @@ static int skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, ep->ring->deq_seg = td->end_seg; inc_deq(xhci, ep->ring); - return xhci_td_cleanup(xhci, td, ep->ring, status); + xhci_td_cleanup(xhci, td, ep->ring, status); } /* * Process bulk and interrupt tds, update urb status and actual_length. */ -static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, - struct xhci_ring *ep_ring, struct xhci_td *td, - union xhci_trb *ep_trb, struct xhci_transfer_event *event) +static void process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, + struct xhci_ring *ep_ring, struct xhci_td *td, + union xhci_trb *ep_trb, struct xhci_transfer_event *event) { struct xhci_slot_ctx *slot_ctx; u32 trb_comp_code; @@ -2555,7 +2552,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, td->status = 0; xhci_handle_halted_endpoint(xhci, ep, td, EP_SOFT_RESET); - return 0; + return; default: /* do nothing */ break; @@ -2574,7 +2571,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, td->urb->actual_length = 0; } - return finish_td(xhci, ep, ep_ring, td, trb_comp_code); + 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 */ From patchwork Wed Nov 6 10:14:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 841341 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 A967A1DE2C6 for ; Wed, 6 Nov 2024 10:13:31 +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=1730888013; cv=none; b=G1fHkKau9Tm7Hemg8azytRT57KnLpXHJyBihkLz3lOhj8n/JDTHvVHteCf+0uNlfEhXXcGguY2BTTL9JqSJ0oYTiSzZZl3ZAHjJUYaXOD+yncVpV801njLZgA4pM/Ry8WoNIAxrpC/rioaleMQvMme0ME1QUpcq+bgH/oQO04nU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730888013; c=relaxed/simple; bh=gUZflQ5NspE5kw2dcAJ47lrITY3ywa95RGkw6sAvbjU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kbJZF/41i8wJTE+upaTaF1y1Fvva1y8FsyA5HDQ4XC8iyNWsbOaMS6M5qKI/eSwz+3/uing8eZ62SKUsftol0jj2W2gDNsYffx3s1ObdckysBUb70QuJ2LI+7QZc06zYMfInGi/ocNe3HeuA0C1P68sVmSJgLco30y6fYBD/RXA= 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=PpOMooQx; 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="PpOMooQx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730888011; x=1762424011; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gUZflQ5NspE5kw2dcAJ47lrITY3ywa95RGkw6sAvbjU=; b=PpOMooQx3v14WyXaqLg6qJFJcz4oG5arS0TfXYtE0Rq5pvV0obnh5tFI 7hVHo2ieUED1O7kfH8RL6bWLDzU+CPqtR5KxuTH+f6XWY3A0M6wVSOADE yoduh0qdSqCzfZNTz5Lz67S03sba1+BeP20dYangdG4LoVr9p3bN8rwtA kPSJqRS25OU1FZsy/dphOBF6HEcvE9RkzZVrrwIQFK6C2AnNOdPn0v8or bzgGe3ZXAnuUV0MNG8fsJ8Y6/Z5FQO0MIeVm2TYMb36FNon/LD7H6odKA d6fUbXw4ixbv4/3KifO1q4pvWieZHsu0KwMWAgzHHxpLGOhq6JjpFuuYg Q==; X-CSE-ConnectionGUID: b22OtKF6Seeu0XdtiuyrTg== X-CSE-MsgGUID: KqTd2zAYSiKKSDgVOXMCKQ== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059482" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059482" 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:13:31 -0800 X-CSE-ConnectionGUID: BW+VCDFiQaqsGIyLXBnhMw== X-CSE-MsgGUID: lFtLJMfaSwCZfNBnAnY8HA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813459" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:30 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 29/33] usb: xhci: add help function xhci_dequeue_td() Date: Wed, 6 Nov 2024 12:14:55 +0200 Message-Id: <20241106101459.775897-30-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: Niklas Neronin Add xhci_dequeue_td() helper function to reduce code duplication. Function xhci_dequeue_td() advances the dequeue pointer past the specified Transfer Descriptor (TD) and releases the TD. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index e48ee58fdb46..c9c0c4a7588a 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -859,6 +859,16 @@ static void xhci_td_cleanup(struct xhci_hcd *xhci, struct xhci_td *td, } } +/* Give back previous TD and move on to the next TD. */ +static void xhci_dequeue_td(struct xhci_hcd *xhci, struct xhci_td *td, struct xhci_ring *ring, + u32 status) +{ + ring->dequeue = td->end_trb; + ring->deq_seg = td->end_seg; + inc_deq(xhci, ring); + + xhci_td_cleanup(xhci, td, ring, status); +} /* Complete the cancelled URBs we unlinked from td_list. */ static void xhci_giveback_invalidated_tds(struct xhci_virt_ep *ep) @@ -2258,12 +2268,7 @@ static void finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, break; } - /* Update ring dequeue pointer */ - ep_ring->dequeue = td->end_trb; - ep_ring->deq_seg = td->end_seg; - inc_deq(xhci, ep_ring); - - xhci_td_cleanup(xhci, td, ep_ring, td->status); + xhci_dequeue_td(xhci, td, ep_ring, td->status); } /* sum trb lengths from the first trb up to stop_trb, _excluding_ stop_trb */ @@ -2496,12 +2501,7 @@ static void skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, /* calc actual length */ frame->actual_length = 0; - /* Update ring dequeue pointer */ - ep->ring->dequeue = td->end_trb; - ep->ring->deq_seg = td->end_seg; - inc_deq(xhci, ep->ring); - - xhci_td_cleanup(xhci, td, ep->ring, status); + xhci_dequeue_td(xhci, td, ep->ring, status); } /* @@ -2791,10 +2791,7 @@ static int handle_tx_event(struct xhci_hcd *xhci, if (td && td->error_mid_td && !trb_in_td(xhci, td, ep_trb_dma, false)) { xhci_dbg(xhci, "Missing TD completion event after mid TD error\n"); - ep_ring->dequeue = td->end_trb; - ep_ring->deq_seg = td->end_seg; - inc_deq(xhci, ep_ring); - xhci_td_cleanup(xhci, td, ep_ring, td->status); + xhci_dequeue_td(xhci, td, ep_ring, td->status); } if (list_empty(&ep_ring->td_list)) { From patchwork Wed Nov 6 10:14:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842339 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 35ED41DED40 for ; Wed, 6 Nov 2024 10:13:33 +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=1730888014; cv=none; b=Ubgr8h23uZ8HrY45vu7MNLtOabjp65HKJGGHIK58FQerRD04zc0h2J5RaVmOb7/n28Yv8BqBckGdMYsnawl+LVdqvNTTLaXPaKnz9TdZHxrGfjEi4tsC4lDiKcqFC6P6+KMwfPKDnESGArzZQLZ1WYPnCnWaE3RVujjFAMBWdCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730888014; c=relaxed/simple; bh=FBBNu4/OWSApVnM5u94pi6qXmTLcxl0YdT16OEpRW+k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R4t9Mo4KxTs0koTIv45hci/soyw24XdaU9Q+v2XuIVKHsEBuy9qcxBZ2xDKy0lAdnP7CgwKVKYYF+xiy5Vly7j9KH7yiTkNRzwOawYbSwwlpTgFU32CfFsJ/rVEyKDOQnO6d3pj4tBIs/VLwbFgF+9PwudL9RjG8C1PmZNBmt9E= 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=Bnc7czZ6; 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="Bnc7czZ6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730888013; x=1762424013; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FBBNu4/OWSApVnM5u94pi6qXmTLcxl0YdT16OEpRW+k=; b=Bnc7czZ6gFRe0HyPXaQoRqCObe3VSV/rzB74hAUOIgwEf3XCFMnMOAvv RSSfkoJbks5qmonLRbS5bOQ1YY6ImKUcvuXOBMgqU09ugpWaITIflh5oP sY0diMbeq+PIwIQ4h7Ra/sHLZ156K1f+A4g5Ev1auUobIK8C24lVmSv+t MC8KoHxBQTaKCc13S6uNTDWOBa0vN83udL08yr2SMoSFr8VbE5epbRSI4 B726UfDO974S9Y5DcoQQ+FBMwRHs1a2TpupW4g5KFEgzQIwmtKQnHrKkE o4k8uabe6c1yty8qL8jC90fx4usHxXzDhh5eMQEahoAyCyYj6/1LnALnD g==; X-CSE-ConnectionGUID: gv00IHM6T4S89uFiPf25BQ== X-CSE-MsgGUID: xdEsronBSjmFMNXqKZzdHw== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059485" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059485" 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:13:33 -0800 X-CSE-ConnectionGUID: uy5Jk7n+Qe6RamMDZPKYXg== X-CSE-MsgGUID: 1+lOTPJCQ9q89dgdu3C2oA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813465" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:32 -0800 From: Mathias Nyman To: Cc: , Niklas Neronin , Mathias Nyman Subject: [PATCH 30/33] usb: xhci: remove irrelevant comment Date: Wed, 6 Nov 2024 12:14:56 +0200 Message-Id: <20241106101459.775897-31-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: Niklas Neronin The code which it is referencing does not exist in the same function, or the file for that matter. Since it was added [1], the Interrupter Moderation Interval can be changed within xhci addon, e.g. PCI xhci_pci_setup(). [1], commit 0ebbab374223 ("USB: xhci: Ring allocation and initialization.") Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 4295e9a4de50..15db90c54a45 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2512,11 +2512,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) ir->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; - /* - * XXX: Might need to set the Interrupter Moderation Register to - * something other than the default (~1ms minimum between interrupts). - * See section 5.5.1.2. - */ for (i = 0; i < MAX_HC_SLOTS; i++) xhci->devs[i] = NULL; From patchwork Wed Nov 6 10:14:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 841340 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 4ACDC1DED4B; Wed, 6 Nov 2024 10:13:35 +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=1730888016; cv=none; b=GHiJHUlyPqOgzI/O8wGehr6Ze0+ZvONV1GkcjuhX31DAygtkz2H8i3FYxV3Ikjia82AktI5avLYNzYVMVvAJjKBxuIHAA/wmUjr20huSSz5SWcRw17EUgwKAM1fomx/QWF1W/HTZonKSID49ssU3r/HoNLIy2XVVjuOvM1tjaj8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730888016; c=relaxed/simple; bh=sr47Jg1ARBWRZFZAicQnKkNylUiP8ygX3xVGB/s1QeM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DLOdVGCcAwy6uXPW9ZpGIPJz6VRmxnH3VAmrjFCAuFaCYTyKItbFhvjEHHl2yEaxqS81vohGYvalhydYdfRKxvqELDOeaNaEIX0wzddQvk9HwrKldJwn7SZDCInsUxKQYRKY+TA4oKhbVhFf4dFhjzxgO4d4s/vVFqqUqKt/h/Y= 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=OkW4Bc6o; 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="OkW4Bc6o" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730888015; x=1762424015; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sr47Jg1ARBWRZFZAicQnKkNylUiP8ygX3xVGB/s1QeM=; b=OkW4Bc6ohotLE4xm77x3CP3XpLaOnVAlIDbEFc3TsTMivcSPF8b+SZq3 4XLViEjym2K0QXNO0sfvRfrOAP5XQiyQrqagt6FxZxjvEIys/Csiu6BIl NFqgIMCCHHUJZ6rfg6BJjE4iCLxvKXc8J5Tu1Sa6E0tCUTVq5QObrjk05 8jyDbAw+m/ffpvc8UkSIzwW6A71g7eLgTGf5c/l9j8sdTbYclRQeUKFLZ IjY7yrKde3F4cLXBKGM1oDzxXOnSVPQYsCBLGDvEWrclTL05GvkHvpf4R h7gnzSKmyQnvbqMhsMDraGtfIDb1UMTvoGsT/DZd2pOfjW2a1qr24DZpl Q==; X-CSE-ConnectionGUID: h+JdgrK/TVi3Z5KX9TvUIQ== X-CSE-MsgGUID: xW2r0lJqS8a5c+OPVG0aLQ== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059487" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059487" 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:13:34 -0800 X-CSE-ConnectionGUID: 6LLWRGRbQXyTr8B7Dl7NGw== X-CSE-MsgGUID: hGMMr3a6Q66j18noWcNQwg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813467" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:33 -0800 From: Mathias Nyman To: Cc: , Michal Pecio , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 31/33] usb: xhci: Limit Stop Endpoint retries Date: Wed, 6 Nov 2024 12:14:57 +0200 Message-Id: <20241106101459.775897-32-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 Some host controllers fail to atomically transition an endpoint to the Running state on a doorbell ring and enter a hidden "Restarting" state, which looks very much like Stopped, with the important difference that it will spontaneously transition to Running anytime soon. A Stop Endpoint command queued in the Restarting state typically fails with Context State Error and the completion handler sees the Endpoint Context State as either still Stopped or already Running. Even a case of Halted was observed, when an error occurred right after the restart. The Halted state is already recovered from by resetting the endpoint. The Running state is handled by retrying Stop Endpoint. The Stopped state was recognized as a problem on NEC controllers and worked around also by retrying, because the endpoint soon restarts and then stops for good. But there is a risk: the command may fail if the endpoint is "stopped for good" already, and retries will fail forever. The possibility of this was not realized at the time, but a number of cases were discovered later and reproduced. Some proved difficult to deal with, and it is outright impossible to predict if an endpoint may fail to ever start at all due to a hardware bug. One such bug (albeit on ASM3142, not on NEC) was found to be reliably triggered simply by toggling an AX88179 NIC up/down in a tight loop for a few seconds. An endless retries storm is quite nasty. Besides putting needless load on the xHC and CPU, it causes URBs never to be given back, paralyzing the device and connection/disconnection logic for the whole bus if the device is unplugged. User processes waiting for URBs become unkillable, drivers and kworker threads lock up and xhci_hcd cannot be reloaded. For peace of mind, impose a timeout on Stop Endpoint retries in this case. If they don't succeed in 100ms, consider the endpoint stopped permanently for some reason and just give back the unlinked URBs. This failure case is rare already and work is under way to make it rarer. Start this work today by also handling one simple case of race with Reset Endpoint, because it costs just two lines to implement. Fixes: fd9d55d190c0 ("xhci: retry Stop Endpoint on buggy NEC controllers") CC: stable@vger.kernel.org Signed-off-by: Michal Pecio Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 28 ++++++++++++++++++++++++---- drivers/usb/host/xhci.c | 2 ++ drivers/usb/host/xhci.h | 1 + 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index c9c0c4a7588a..dd23596ccd84 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -52,6 +52,7 @@ * endpoint rings; it generates events on the event ring for these. */ +#include #include #include #include @@ -1158,16 +1159,35 @@ static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id, return; case EP_STATE_STOPPED: /* - * NEC uPD720200 sometimes sets this state and fails with - * Context Error while continuing to process TRBs. - * Be conservative and trust EP_CTX_STATE on other chips. + * Per xHCI 4.6.9, Stop Endpoint command on a Stopped + * EP is a Context State Error, and EP stays Stopped. + * + * But maybe it failed on Halted, and somebody ran Reset + * Endpoint later. EP state is now Stopped and EP_HALTED + * still set because Reset EP handler will run after us. + */ + if (ep->ep_state & EP_HALTED) + break; + /* + * On some HCs EP state remains Stopped for some tens of + * us to a few ms or more after a doorbell ring, and any + * new Stop Endpoint fails without aborting the restart. + * This handler may run quickly enough to still see this + * Stopped state, but it will soon change to Running. + * + * Assume this bug on unexpected Stop Endpoint failures. + * Keep retrying until the EP starts and stops again, on + * chips where this is known to help. Wait for 100ms. */ if (!(xhci->quirks & XHCI_NEC_HOST)) break; + if (time_is_before_jiffies(ep->stop_time + msecs_to_jiffies(100))) + break; fallthrough; case EP_STATE_RUNNING: /* Race, HW handled stop ep cmd before ep was running */ - xhci_dbg(xhci, "Stop ep completion ctx error, ep is running\n"); + xhci_dbg(xhci, "Stop ep completion ctx error, ctx_state %d\n", + GET_EP_CTX_STATE(ep_ctx)); command = xhci_alloc_command(xhci, false, GFP_ATOMIC); if (!command) { diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index bc477cf99805..4977ada0a19e 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -8,6 +8,7 @@ * Some code borrowed from the Linux EHCI driver. */ +#include #include #include #include @@ -1764,6 +1765,7 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) ret = -ENOMEM; goto done; } + ep->stop_time = jiffies; ep->ep_state |= EP_STOP_CMD_PENDING; xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id, ep_index, 0); diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index a0e992c3db0d..6dd3138b2380 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -691,6 +691,7 @@ struct xhci_virt_ep { /* Bandwidth checking storage */ struct xhci_bw_info bw_info; struct list_head bw_endpoint_list; + unsigned long stop_time; /* Isoch Frame ID checking storage */ int next_frame_id; /* Use new Isoch TRB layout needed for extended TBC support */ From patchwork Wed Nov 6 10:14:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 842338 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 E8CDE1DDC1D; Wed, 6 Nov 2024 10:13:36 +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=1730888018; cv=none; b=YyyQYMEtSVBHBc7g0dMWAIf435a/YUw4M18Iy3M7CSeUp5wvQVa4cknTX1nzxOCKhLEKAvghww20RmKf1jkibJhrpZMqSDTuWbEcWL9q+B8Ln/xYsub7w4KB2Jx4qQVYDIGg7g7s5IDclJ40QLCix9WZS1spPl5hXs3lKGoCFLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730888018; c=relaxed/simple; bh=43ODk6I7RgobtDdGFTmHEg+YHk+2/hr1nIyRuX5jXpo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iB1eIXvSgrv+z/T4krYEwoxjIDAeEjzMHK2fhBH9iVwFji6GTN+yU0BiH0qBwNm+5OasKbObS2z5nI925MQS+PY3Xo2q65JZ1R/Af5PMxFrMEPjunsrspyrdBfIP6SjTNN1Hnj4pi/DdxqgncimTB24fVFZrUX+lDSaC6bTbHuI= 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=kIy5/hx5; 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="kIy5/hx5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730888017; x=1762424017; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=43ODk6I7RgobtDdGFTmHEg+YHk+2/hr1nIyRuX5jXpo=; b=kIy5/hx5bDBGka3h3ymU0YVOAx84v4v8p4Lp1c+35l8WCM6zPFj7ck/a bU27dOwoJxMtsM4484qR+Q2qh6qkT4dNzl4EKt4dU3eXPa+OVphoeI2ni 2+0fq5zqF43wk7q/FGxxO04h9eks37Y6t036BHTafNP5Njsp9E9fhqo0T oqjtXqYG1f95X42CYHecqMa9YfQHaEOX5huqUIZbjEfufy/abw4t5e7Xd YUgZ9staNoQrnJAFVTZQ8ioJirikIvwG1U0T5IjQuTtUczkOMAm5wnRvJ vPt3SHo29U7HGI0ccD3VgodiWrBk4OXs/1WZ0kDzZaEY1m+OuSL+ig7iF w==; X-CSE-ConnectionGUID: g8A0aWb9RiyDgayMaXIjXg== X-CSE-MsgGUID: buS3/TfcR4qYWpQ0Grl5kQ== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059491" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059491" 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:13:36 -0800 X-CSE-ConnectionGUID: E06k7VtNR6+rG8G5jgl/TQ== X-CSE-MsgGUID: RilclrP6Sjmbl8Zl83wVPg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813468" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:35 -0800 From: Mathias Nyman To: Cc: , Michal Pecio , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 32/33] usb: xhci: Fix TD invalidation under pending Set TR Dequeue Date: Wed, 6 Nov 2024 12:14:58 +0200 Message-Id: <20241106101459.775897-33-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 xhci_invalidate_cancelled_tds() may not work correctly if the hardware is modifying endpoint or stream contexts at the same time by executing a Set TR Dequeue command. And even if it worked, it would be unable to queue Set TR Dequeue for the next stream, failing to clear xHC cache. On stream endpoints, a chain of Set TR Dequeue commands may take some time to execute and we may want to cancel more TDs during this time. Currently this leads to Stop Endpoint completion handler calling this function without testing for SET_DEQ_PENDING, which will trigger the aforementioned problems when it happens. On all endpoints, a halt condition causes Reset Endpoint to be queued and an error status given to the class driver, which may unlink more URBs in response. Stop Endpoint is queued and its handler may execute concurrently with Set TR Dequeue queued by Reset Endpoint handler. (Reset Endpoint handler calls this function too, but there seems to be no possibility of it running concurrently with Set TR Dequeue). Fix xhci_invalidate_cancelled_tds() to work correctly under a pending Set TR Dequeue. Bail out of the function when SET_DEQ_PENDING is set, then make the completion handler call the function again and also call xhci_giveback_invalidated_tds(), which needs to be called next. This seems to fix another potential bug, where the handler would call xhci_invalidate_cancelled_tds(), which may clear some deferred TDs if a sanity check fails, and the TDs wouldn't be given back promptly. Said sanity check seems to be wrong and prone to false positives when the endpoint halts, but fixing it is beyond the scope of this change, besides ensuring that cleared TDs are given back properly. Fixes: 5ceac4402f5d ("xhci: Handle TD clearing for multiple streams case") CC: stable@vger.kernel.org Signed-off-by: Michal Pecio Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index dd23596ccd84..55be03be2374 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -980,6 +980,13 @@ static int xhci_invalidate_cancelled_tds(struct xhci_virt_ep *ep) unsigned int slot_id = ep->vdev->slot_id; int err; + /* + * This is not going to work if the hardware is changing its dequeue + * pointers as we look at them. Completion handler will call us later. + */ + if (ep->ep_state & SET_DEQ_PENDING) + return 0; + xhci = ep->xhci; list_for_each_entry_safe(td, tmp_td, &ep->cancelled_td_list, cancelled_td_list) { @@ -1367,7 +1374,6 @@ static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, struct xhci_slot_ctx *slot_ctx; struct xhci_stream_ctx *stream_ctx; struct xhci_td *td, *tmp_td; - bool deferred = false; ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); stream_id = TRB_TO_STREAM_ID(le32_to_cpu(trb->generic.field[2])); @@ -1471,8 +1477,6 @@ static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, xhci_dbg(ep->xhci, "%s: Giveback cancelled URB %p TD\n", __func__, td->urb); xhci_td_cleanup(ep->xhci, td, ep_ring, td->status); - } else if (td->cancel_status == TD_CLEARING_CACHE_DEFERRED) { - deferred = true; } else { xhci_dbg(ep->xhci, "%s: Keep cancelled URB %p TD as cancel_status is %d\n", __func__, td->urb, td->cancel_status); @@ -1483,11 +1487,15 @@ static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, ep->queued_deq_seg = NULL; ep->queued_deq_ptr = NULL; - if (deferred) { - /* We have more streams to clear */ + /* Check for deferred or newly cancelled TDs */ + if (!list_empty(&ep->cancelled_td_list)) { xhci_dbg(ep->xhci, "%s: Pending TDs to clear, continuing with invalidation\n", __func__); xhci_invalidate_cancelled_tds(ep); + /* Try to restart the endpoint if all is done */ + ring_doorbell_for_active_rings(xhci, slot_id, ep_index); + /* Start giving back any TDs invalidated above */ + xhci_giveback_invalidated_tds(ep); } else { /* Restart any rings with pending URBs */ xhci_dbg(ep->xhci, "%s: All TDs cleared, ring doorbell\n", __func__); From patchwork Wed Nov 6 10:14:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 841339 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 765AC1DE2DB; Wed, 6 Nov 2024 10:13:38 +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=1730888020; cv=none; b=tO04dW49attpXrngifVTR29UpFwYeXkiwNVjzap6JAkgArB/d3K+rW05r1A/yOfULteTsHKdGGB4qMN5TJFT2ZX/+LC20AwSHZAm42NEtWFfIwzz8Ru6zEi4gwZo9ZOFgIqiQ/HvpBOoORS/szAecCHLyCyYpUySmRggx15Hb8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730888020; c=relaxed/simple; bh=jbZkr8iZPbdlbgogmpITnZZXPnS0YJL38OY6BQSHpVc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LP0yBhbiwjbrtugu7pCnrIzYwmI6GaeejV7CBEJaxp+YNszwHvt0LV833LFNxaIyPHELIRgHBQMZGoRtcOahSsCt/GFk8y8AlZUYP8RC46euFxhGG4eai0Pf5MbyMGNHNdO08bHq6huhV4f3LOjAPNRAQeuwsYvGLATbVuxNPmQ= 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=LxbLwjMw; 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="LxbLwjMw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730888018; x=1762424018; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jbZkr8iZPbdlbgogmpITnZZXPnS0YJL38OY6BQSHpVc=; b=LxbLwjMwKESWIdizxGexoykzLyOTvsyi3fJnXY0RonuGuDswyad/BxEI FyGv9To2dKoUgQhKyh8yu9qQ4ivtWNh3IjbBihfEvIONSnODbeOBQDwz1 uwpeLN6ZXc5uP6ukRFMDEweMIU3KFr5sjkJicOUbQGimIsLAth4sdlUyb 0U3hh8LuzUrTm/6OsVEoDOkBNyF07/0Wm1B/bgOF+d60OA1WO7P/Rvhe/ hHVSRpFL0Kpo+9O8ixxc4oRSpWMm7JhlZIk5aE12MHyxROrhScjlhcc22 RBIOcbGeWY7jegkLOCGF+zWomEpKuYmW5eR0hwmITqc6F3roEroSMD/+i Q==; X-CSE-ConnectionGUID: ziuZ7ba6SseN7awJ1XJ0BQ== X-CSE-MsgGUID: aMKgGTTvQo6Jrw7JaUfDVw== X-IronPort-AV: E=McAfee;i="6700,10204,11247"; a="42059494" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42059494" 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:13:38 -0800 X-CSE-ConnectionGUID: nb2mc+XCTfWshh5dspQ1lw== X-CSE-MsgGUID: 6zE48ppbQ9+j4IHUjQ6sKQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84813470" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa010.fm.intel.com with ESMTP; 06 Nov 2024 02:13:37 -0800 From: Mathias Nyman To: Cc: , Michal Pecio , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 33/33] usb: xhci: Avoid queuing redundant Stop Endpoint commands Date: Wed, 6 Nov 2024 12:14:59 +0200 Message-Id: <20241106101459.775897-34-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 Stop Endpoint command on an already stopped endpoint fails and may be misinterpreted as a known hardware bug by the completion handler. This results in an unnecessary delay with repeated retries of the command. Avoid queuing this command when endpoint state flags indicate that it's stopped or halted and the command will fail. If commands are pending on the endpoint, their completion handlers will process cancelled TDs so it's done. In case of waiting for external operations like clearing TT buffer, the endpoint is stopped and cancelled TDs can be processed now. This eliminates practically all unnecessary retries because an endpoint with pending URBs is maintained in Running state by the driver, unless aforementioned commands or other operations are pending on it. This is guaranteed by xhci_ring_ep_doorbell() and by the fact that it is called every time any of those operations completes. The only known exceptions are hardware bugs (the endpoint never starts at all) and Stream Protocol errors not associated with any TRB, which cause an endpoint reset not followed by restart. Sounds like a bug. Generally, these retries are only expected to happen when the endpoint fails to start for unknown/no reason, which is a worse problem itself, and fixing the bug eliminates the retries too. All cases were tested and found to work as expected. SET_DEQ_PENDING was produced by patching uvcvideo to unlink URBs in 100us intervals, which then runs into this case very often. EP_HALTED was produced by restarting 'cat /dev/ttyUSB0' on a serial dongle with broken cable. EP_CLEARING_TT by the same, with the dongle on an external hub. Fixes: fd9d55d190c0 ("xhci: retry Stop Endpoint on buggy NEC controllers") CC: stable@vger.kernel.org Signed-off-by: Michal Pecio Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 13 +++++++++++++ drivers/usb/host/xhci.c | 19 +++++++++++++++---- drivers/usb/host/xhci.h | 1 + 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 55be03be2374..4cf5363875c7 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1076,6 +1076,19 @@ static int xhci_invalidate_cancelled_tds(struct xhci_virt_ep *ep) return 0; } +/* + * Erase queued TDs from transfer ring(s) and give back those the xHC didn't + * stop on. If necessary, queue commands to move the xHC off cancelled TDs it + * stopped on. Those will be given back later when the commands complete. + * + * Call under xhci->lock on a stopped endpoint. + */ +void xhci_process_cancelled_tds(struct xhci_virt_ep *ep) +{ + xhci_invalidate_cancelled_tds(ep); + xhci_giveback_invalidated_tds(ep); +} + /* * Returns the TD the endpoint ring halted on. * Only call for non-running rings without streams. diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 4977ada0a19e..5ebde8cae4fc 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1756,10 +1756,21 @@ static int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) } } - /* Queue a stop endpoint command, but only if this is - * the first cancellation to be handled. - */ - if (!(ep->ep_state & EP_STOP_CMD_PENDING)) { + /* These completion handlers will sort out cancelled TDs for us */ + if (ep->ep_state & (EP_STOP_CMD_PENDING | EP_HALTED | SET_DEQ_PENDING)) { + xhci_dbg(xhci, "Not queuing Stop Endpoint on slot %d ep %d in state 0x%x\n", + urb->dev->slot_id, ep_index, ep->ep_state); + goto done; + } + + /* In this case no commands are pending but the endpoint is stopped */ + if (ep->ep_state & EP_CLEARING_TT) { + /* and cancelled TDs can be given back right away */ + xhci_dbg(xhci, "Invalidating TDs instantly on slot %d ep %d in state 0x%x\n", + urb->dev->slot_id, ep_index, ep->ep_state); + xhci_process_cancelled_tds(ep); + } else { + /* Otherwise, queue a new Stop Endpoint command */ command = xhci_alloc_command(xhci, false, GFP_ATOMIC); if (!command) { ret = -ENOMEM; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 6dd3138b2380..4914f0a10cff 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1922,6 +1922,7 @@ void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring); unsigned int count_trbs(u64 addr, u64 len); int xhci_stop_endpoint_sync(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, int suspend, gfp_t gfp_flags); +void xhci_process_cancelled_tds(struct xhci_virt_ep *ep); /* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,