From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796154131; b=j5ZUg5j0eazmZ2Ds6d4TZHpeVnq1FGEC9pfrM3jlSWyEOPJX7d8r9YEgwydthZyeKG6k ui7pqym8/wrj9AfgnJNR5/8cIsS0wBqUuA/B1GttkAjeUFWdZU5bJAf5iQXJiqMKmY+L9 bZeGcCf0Vxdekyvm5gqtfSjtO9HaaV2mOBSw9fMxeDtEbEvC9bhmkSZfR7OQi30If5dO9 rWLRhwiV95S5SFyYpigOC65DpmB6V7C4+0SXMdggrat7GDwi1sJ9q5jTe3rYGxUzETe/y aSJGGSTBLM13542XcwovYEotKvgIgdodvaAwN27nzgfwk89spC3E6ENXhiGuDWGn3gQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796154131; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=WiQqHx4+YK89KdEke/b/Dl0BrSMUVenw2mQbC4ygONQ=; b=p7Aryth3MzK8w4otXtktzuXIIqaYitEaGHnOAAgPqTHodxYSVeVe8L1M9nR4o7EA1jwR /FbBIFNkuvLuW7Fz2EJaMHA0HcH2klb7KzwU9ZwhWdTM8oXO9A1YTDBOxUxozgnI7Psal ucvG/8P6fDdkOqmUrTPx2+XCdMrinVgmlcKp4HPRMunUt+0gRzw1Qx0adxHUfuTzYIPNt cKqgGFnnYLvwwUAtAfoiEU2FRBhu3DwyPphhLuosOLxn3+vI3OgPW9uCqkBoCY6/keoML +deACPvsEN5KcCHUrGefeNxb6xA+3YKl40lRT3siBFUynMjs019/A4lKkMrtY4WA10g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=AsFwDvpx; arc=none smtp.remote-ip=198.175.65.17 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0031606A327 for ; Tue, 1 Dec 2026 19:42:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C0031606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass 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.a=rsa-sha256 header.s=Intel header.b=AsFwDvpx DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796154127; x=1827690127; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WiQqHx4+YK89KdEke/b/Dl0BrSMUVenw2mQbC4ygONQ=; b=AsFwDvpxVrZXwHMNPEdEi4jpLmOYxl/0yEi4xgDDMF5QJ83Sn+wYc74z JFEWBY3lUdn6PSl0TjzIJd5lA7QsWyEcnzhgzgyVZVt7dtfDlis7MZOF9 lQTUyK1Q3jpcdQf/VUt+Dt5Oii1uShLa1Rvn5AWIwHjueNfKr+Xt6lxz6 75gTdGG21p9aRu53lQyhATBMRqGMU4d80qgu4xlDwBPnw+/+GhjYtb3+5 9r1rX64zJxmJ4Pu1MR1hPbySkTpqezGgIFlBD7BCfaqw/PCjA1VZG2vgx rNRB64CCreFTlt7bH2pmhoo+FvXoTuFe/cHDMA+3Mi2zQm9P1LYVhFG8G A==; X-CSE-ConnectionGUID: SYJCZaqPSu6rygQMG+23gQ== X-CSE-MsgGUID: P1HZopmwTyS4xBLrVrj/ow== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5049041" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="5049041" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 11:42:06 -0800 X-CSE-ConnectionGUID: cbLGv1B8SieCCbWZJMNiwA== X-CSE-MsgGUID: BDjZ8fNQQFS9mQtcgbJZ8w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13702928" Received: from black.igk.intel.com ([10.91.253.5]) by fmviesa009.fm.intel.com with ESMTP; 01 Dec 2026 11:42:05 -0800 Received: by black.igk.intel.com (Postfix, from userid 1058) id DED1A99; Tue, 01 Dec 2026 20:42:04 +0100 (CET) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 3/7] usb: xhci: simplify prepare_ring() Date: Tue, 1 Dec 2026 20:41:30 +0100 Message-ID: <20261201194134.265480-4-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261201194134.265480-1-niklas.neronin@linux.intel.com> References: <20261201194134.265480-1-niklas.neronin@linux.intel.com> X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Function prepare_ring() contains special handling for the command ring even though the only differences are that command rings cannot be expanded and use a different free space check. Move the command ring specific logic into queue_command() and simplify prepare_ring() to handle only endpoint rings. This makes prepare_ring() align with the existing documentation, comments, and error messages, which all describe endpoint ring handling. No functional change intended. Signed-off-by: Niklas Neronin --- 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 7f983e8d4697..15f7add6efe2 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3343,18 +3343,12 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, return -EINVAL; } - if (ep_ring != xhci->cmd_ring) { - new_segs = xhci_ring_expansion_needed(xhci, ep_ring, num_trbs); - } else if (xhci_num_trbs_free(ep_ring) <= num_trbs) { - xhci_err(xhci, "Do not support expand command ring\n"); - return -ENOMEM; - } - + new_segs = xhci_ring_expansion_needed(xhci, ep_ring, num_trbs); if (new_segs) { xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion, "ERROR no room on ep ring, try ring expansion"); if (xhci_ring_expansion(xhci, ep_ring, new_segs, mem_flags)) { - xhci_err(xhci, "Ring expansion failed\n"); + xhci_err(xhci, "Endpoint ring expansion failed\n"); return -ENOMEM; } } @@ -4399,7 +4393,6 @@ static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd, { int reserved_trbs = xhci->cmd_ring_reserved_trbs; struct usb_hcd *hcd = xhci_to_hcd(xhci); - int ret; if ((xhci->xhc_state & XHCI_STATE_DYING) || (xhci->xhc_state & XHCI_STATE_HALTED)) { @@ -4416,14 +4409,18 @@ static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd, if (!command_must_succeed) reserved_trbs++; - ret = prepare_ring(xhci, xhci->cmd_ring, EP_STATE_RUNNING, - reserved_trbs, GFP_ATOMIC); - if (ret < 0) { - xhci_err(xhci, "ERR: No room for command on command ring\n"); + if (xhci_num_trbs_free(xhci->cmd_ring) <= reserved_trbs) { + xhci_err(xhci, "No room for command on command ring\n"); if (command_must_succeed) - xhci_err(xhci, "ERR: Reserved TRB counting for " - "unfailable commands failed.\n"); - return ret; + xhci_err(xhci, "Reserved TRB counting for unfailable commands failed.\n"); + return -ENOMEM; + } + + if (trb_is_link(xhci->cmd_ring->enqueue)) + inc_enq_past_link(xhci, xhci->cmd_ring, 0); + if (last_trb_on_seg(xhci->cmd_ring->enq_seg, xhci->cmd_ring->enqueue)) { + xhci_warn(xhci, "Missing link TRB at end of ring segment\n"); + return -EINVAL; } cmd->command_trb = xhci->cmd_ring->enqueue; -- 2.50.1