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=1796154128; b=zoM3j4iByNKHdclfNis3974wV5NLOS1LqcQXXhHQOzzHQBwnSvHwnhMSW3XlZRuwXrvS 5UoakCo89vX89UgsnoCtKEK5uPJ9/uDG8W0iaVhgsLRKBdYdYkTQkCESTnIqFjYpTU4aV gQ8HQpr7+ijWk0UA2etcSFYWlQZfHcXP33eW4mmI4aYPNaiJYSClU42/fsAWVpSBZeuTJ gUVHjdGSmh6fgILMJq8rXkvPOHhCIsq8bbXDVbylxZIkQvplIfr9PoNkBeX85nQEDF7Fu b3pbq2hrGMUWGOQPIkByTubaG9fHu3nT4pEGciU9oWNoTREbati0ZamCquiNvBlaUDw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796154128; 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=b4AVHeBdj3YTe1MXDYChrarSfdhw75kl4MRTthL/f1s=; b=OJ+THozixBGW634uNnjPcYAgs+yrvAJ67ef2uvB+z0cuQNqYf1B0YXdwGn3OrzcueGqp PB76hTN32ALudoUQGv4Rvhfqtic8unSXah3ogbzbd9hJKUgZtCoEFxFuzO+Z+0CzAtsL2 2//8S+aP6njWvVVrAxNVP6Q4zQggwcHt+vp/3HqzFWtyndMf9pugAFFPkYfoRAcFfP+9/ /KtoxxY0b/smUTqoQbEZ6NThLV41B15sn9YKShbEivVUNCykgTIhfNbV9SjIbHXowKPs4 +b9XCFkNnyqFKW8THau7Hdd96hd0T/2lH5IZtAOeGx93vwTK3FLelzJla4DtvAuGcnA== 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=Qdxj0kmF; 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 24E38606A331 for ; Tue, 1 Dec 2026 19:42:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 24E38606A331 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=Qdxj0kmF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796154128; x=1827690128; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b4AVHeBdj3YTe1MXDYChrarSfdhw75kl4MRTthL/f1s=; b=Qdxj0kmFukTO8G31C7uzkdA4j2nMiGQhLz0/uTfr/lPiNplmvURAa4Xe /H+qBOELTucxbt5kYTbYoJbAo6eZAOh6KnUaKWHA4nw6vMj34dmkWL6vy 1znmwsVocjRNYWKCY57uyf3gh3NAkPvpTv7gD+gj9wcU3YXrYWE9LV/cT livexkBK6lxYrbPP/OSYRd6AoBWFMRQ2bSX254zOXIQvgqqRHgBkBkAUi F68SrGsUGg1zS4poE9nvm+H3qHH/oP50o/VCsfP7zXOfJIUHLkNtmLjAM a+AmXgxJ9rAsEoFAfXSskIxcFhz+Ffn0kFs/hls8q3wmP0NrGcd9wVOrw w==; X-CSE-ConnectionGUID: P2vgwShTS166EUqKoMauRw== X-CSE-MsgGUID: 43FHjoiMTly1P9q8k2ytBw== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5049045" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="5049045" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 11:42:07 -0800 X-CSE-ConnectionGUID: C2nwwlCBR5S6YGd0cANVtg== X-CSE-MsgGUID: fHjJCCDNQCevsG0Z4lVJRQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13818655" Received: from black.igk.intel.com ([10.91.253.5]) by fmviesa001.fm.intel.com with ESMTP; 01 Dec 2026 11:42:06 -0800 Received: by black.igk.intel.com (Postfix, from userid 1058) id 727DF9D; Tue, 01 Dec 2026 20:42:05 +0100 (CET) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 4/7] usb: xhci: split Configure Endpoint and Evaluate Context handling Date: Tue, 1 Dec 2026 20:41:31 +0100 Message-ID: <20261201194134.265480-5-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 xhci_configure_endpoint() handles both Configure Endpoint and Evaluate Context commands, selected through the 'ctx_change' parameter. While the two commands share some infrastructure, they have different requirements, queue different command TRBs, and handle different completion codes. As a result, xhci_configure_endpoint() contains command-specific branching throughout its setup and completion paths. The completion status handling is also split into separate helper functions. Separate the Evaluate Context path into a dedicated xhci_evaluate_context() helper and fold the command completion handling into the respective command submission functions. This removes the 'ctx_change' parameter, reduces command specific branching while making the Configure Endpoint and Evaluate Context flows easier to follow. Evaluate Context no longer goes through the XHCI_EP_LIMIT_QUIRK. Evaluate Context only modifies the Slot and EP0 contexts, which xhci_count_num_new_endpoints() and xhci_count_num_dropped_endpoints() ignore, so this accounting was always a no-op for it. Software bandwidth checking was already skipped for Evaluate Context. Add separate xhci_evaluate_context and xhci_evaluate_context_ctrl_ctx trace events, so that Evaluate Context commands are no longer traced as Configure Endpoint. The resulting code is smaller and more closely reflects the distinct semantics of the two xHCI commands. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-trace.h | 10 ++ drivers/usb/host/xhci.c | 262 ++++++++++++++++------------------ 2 files changed, 132 insertions(+), 140 deletions(-) diff --git a/drivers/usb/host/xhci-trace.h b/drivers/usb/host/xhci-trace.h index 724cba2dbb78..9b3f45743aa9 100644 --- a/drivers/usb/host/xhci-trace.h +++ b/drivers/usb/host/xhci-trace.h @@ -446,6 +446,11 @@ DEFINE_EVENT(xhci_log_slot_ctx, xhci_configure_endpoint, TP_ARGS(ctx) ); +DEFINE_EVENT(xhci_log_slot_ctx, xhci_evaluate_context, + TP_PROTO(struct xhci_slot_ctx *ctx), + TP_ARGS(ctx) +); + DECLARE_EVENT_CLASS(xhci_log_ctrl_ctx, TP_PROTO(struct xhci_input_control_ctx *ctrl_ctx), TP_ARGS(ctrl_ctx), @@ -471,6 +476,11 @@ DEFINE_EVENT(xhci_log_ctrl_ctx, xhci_configure_endpoint_ctrl_ctx, TP_ARGS(ctrl_ctx) ); +DEFINE_EVENT(xhci_log_ctrl_ctx, xhci_evaluate_context_ctrl_ctx, + TP_PROTO(struct xhci_input_control_ctx *ctrl_ctx), + TP_ARGS(ctrl_ctx) +); + DECLARE_EVENT_CLASS(xhci_log_ring, TP_PROTO(struct xhci_ring *ring), TP_ARGS(ring), diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 9688c5986a40..d2ca031cff70 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1535,9 +1535,8 @@ static int xhci_check_args(struct usb_hcd *hcd, struct usb_device *udev, return 1; } -static int xhci_configure_endpoint(struct xhci_hcd *xhci, - struct usb_device *udev, struct xhci_command *command, - bool ctx_change, bool must_succeed); +static int xhci_evaluate_context(struct xhci_hcd *xhci, struct usb_device *udev, + struct xhci_command *command, bool must_succeed); /* * Full speed devices may have a max packet size greater than 8 bytes, but the @@ -1592,8 +1591,7 @@ static int xhci_check_ep0_maxpacket(struct xhci_hcd *xhci, struct xhci_virt_devi ctrl_ctx->add_flags = cpu_to_le32(EP0_FLAG); ctrl_ctx->drop_flags = 0; - ret = xhci_configure_endpoint(xhci, vdev->udev, command, - true, false); + ret = xhci_evaluate_context(xhci, vdev->udev, command, false); /* Clean up the input context for later use by bandwidth functions */ ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); break; @@ -2096,106 +2094,6 @@ static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *vir } } -static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, - struct usb_device *udev, u32 *cmd_status) -{ - int ret; - - switch (*cmd_status) { - case COMP_COMMAND_ABORTED: - case COMP_COMMAND_RING_STOPPED: - xhci_warn(xhci, "Timeout while waiting for configure endpoint command\n"); - ret = -ETIME; - break; - case COMP_RESOURCE_ERROR: - dev_warn(&udev->dev, - "Not enough host controller resources for new device state.\n"); - ret = -ENOMEM; - /* FIXME: can we allocate more resources for the HC? */ - break; - case COMP_BANDWIDTH_ERROR: - case COMP_SECONDARY_BANDWIDTH_ERROR: - dev_warn(&udev->dev, - "Not enough bandwidth for new device state.\n"); - ret = -ENOSPC; - /* FIXME: can we go back to the old state? */ - break; - case COMP_TRB_ERROR: - /* the HCD set up something wrong */ - dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, " - "add flag = 1, " - "and endpoint is not disabled.\n"); - ret = -EINVAL; - break; - case COMP_INCOMPATIBLE_DEVICE_ERROR: - dev_warn(&udev->dev, - "ERROR: Incompatible device for endpoint configure command.\n"); - ret = -ENODEV; - break; - case COMP_SUCCESS: - xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, - "Successful Endpoint Configure command"); - ret = 0; - break; - default: - xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", - *cmd_status); - ret = -EINVAL; - break; - } - return ret; -} - -static int xhci_evaluate_context_result(struct xhci_hcd *xhci, - struct usb_device *udev, u32 *cmd_status) -{ - int ret; - - switch (*cmd_status) { - case COMP_COMMAND_ABORTED: - case COMP_COMMAND_RING_STOPPED: - xhci_warn(xhci, "Timeout while waiting for evaluate context command\n"); - ret = -ETIME; - break; - case COMP_PARAMETER_ERROR: - dev_warn(&udev->dev, - "WARN: xHCI driver setup invalid evaluate context command.\n"); - ret = -EINVAL; - break; - case COMP_SLOT_NOT_ENABLED_ERROR: - dev_warn(&udev->dev, - "WARN: slot not enabled for evaluate context command.\n"); - ret = -EINVAL; - break; - case COMP_CONTEXT_STATE_ERROR: - dev_warn(&udev->dev, - "WARN: invalid context state for evaluate context command.\n"); - ret = -EINVAL; - break; - case COMP_INCOMPATIBLE_DEVICE_ERROR: - dev_warn(&udev->dev, - "ERROR: Incompatible device for evaluate context command.\n"); - ret = -ENODEV; - break; - case COMP_MAX_EXIT_LATENCY_TOO_LARGE_ERROR: - /* Max Exit Latency too large error */ - dev_warn(&udev->dev, "WARN: Max Exit Latency too large\n"); - ret = -EINVAL; - break; - case COMP_SUCCESS: - xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, - "Successful evaluate context command"); - ret = 0; - break; - default: - xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", - *cmd_status); - ret = -EINVAL; - break; - } - return ret; -} - static u32 xhci_count_num_new_endpoints(struct xhci_hcd *xhci, struct xhci_input_control_ctx *ctrl_ctx) { @@ -2928,13 +2826,8 @@ int xhci_usb_endpoint_maxp(struct usb_device *udev, return usb_endpoint_maxp(&host_ep->desc); } -/* Issue a configure endpoint command or evaluate context command - * and wait for it to finish. - */ -static int xhci_configure_endpoint(struct xhci_hcd *xhci, - struct usb_device *udev, - struct xhci_command *command, - bool ctx_change, bool must_succeed) +static int xhci_configure_endpoint(struct xhci_hcd *xhci, struct usb_device *udev, + struct xhci_command *command, bool must_succeed) { int ret; unsigned long flags; @@ -2964,7 +2857,8 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, xhci->num_active_eps); return -ENOMEM; } - if ((xhci->quirks & XHCI_SW_BW_CHECKING) && !ctx_change && + + if ((xhci->quirks & XHCI_SW_BW_CHECKING) && xhci_reserve_bandwidth(xhci, virt_dev, command->in_ctx)) { if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) xhci_free_host_resources(xhci, ctrl_ctx); @@ -2978,14 +2872,8 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, trace_xhci_configure_endpoint_ctrl_ctx(ctrl_ctx); trace_xhci_configure_endpoint(slot_ctx); - if (!ctx_change) - ret = xhci_queue_configure_endpoint(xhci, command, - command->in_ctx->dma, - udev->slot_id, must_succeed); - else - ret = xhci_queue_evaluate_context(xhci, command, - command->in_ctx->dma, - udev->slot_id, must_succeed); + ret = xhci_queue_configure_endpoint(xhci, command, command->in_ctx->dma, + udev->slot_id, must_succeed); if (ret < 0) { if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) xhci_free_host_resources(xhci, ctrl_ctx); @@ -2994,18 +2882,47 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, "FIXME allocate a new ring segment"); return -ENOMEM; } + xhci_ring_cmd_db(xhci); spin_unlock_irqrestore(&xhci->lock, flags); /* Wait for the configure endpoint command to complete */ wait_for_completion(command->completion); - if (!ctx_change) - ret = xhci_configure_endpoint_result(xhci, udev, - &command->status); - else - ret = xhci_evaluate_context_result(xhci, udev, - &command->status); + switch (command->status) { + case COMP_COMMAND_ABORTED: + case COMP_COMMAND_RING_STOPPED: + xhci_warn(xhci, "Timeout while waiting for configure endpoint command\n"); + ret = -ETIME; + break; + case COMP_RESOURCE_ERROR: + dev_warn(&udev->dev, "Not enough host controller resources for new device state.\n"); + ret = -ENOMEM; + break; + case COMP_BANDWIDTH_ERROR: + case COMP_SECONDARY_BANDWIDTH_ERROR: + dev_warn(&udev->dev, "Not enough bandwidth for new device state.\n"); + ret = -ENOSPC; + /* FIXME: can we go back to the old state? */ + break; + case COMP_TRB_ERROR: + dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, add flag = 1, and endpoint is not disabled.\n"); + ret = -EINVAL; + break; + case COMP_INCOMPATIBLE_DEVICE_ERROR: + dev_warn(&udev->dev, "ERROR: Incompatible device for endpoint configure command.\n"); + ret = -ENODEV; + break; + case COMP_SUCCESS: + xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, + "Successful Endpoint Configure command"); + break; + default: + xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", + command->status); + ret = -EINVAL; + break; + } if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { spin_lock_irqsave(&xhci->lock, flags); @@ -3021,6 +2938,78 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, return ret; } +static int xhci_evaluate_context(struct xhci_hcd *xhci, struct usb_device *udev, + struct xhci_command *command, bool must_succeed) +{ + int ret; + unsigned long flags; + + if (!command) + return -EINVAL; + + spin_lock_irqsave(&xhci->lock, flags); + + if (xhci->xhc_state & XHCI_STATE_DYING) { + spin_unlock_irqrestore(&xhci->lock, flags); + return -ESHUTDOWN; + } + + trace_xhci_evaluate_context_ctrl_ctx(xhci_get_input_control_ctx(command->in_ctx)); + trace_xhci_evaluate_context(xhci_get_slot_ctx(xhci, command->in_ctx)); + + ret = xhci_queue_evaluate_context(xhci, command, command->in_ctx->dma, udev->slot_id, + must_succeed); + if (ret < 0) { + spin_unlock_irqrestore(&xhci->lock, flags); + return -ENOMEM; + } + + xhci_ring_cmd_db(xhci); + spin_unlock_irqrestore(&xhci->lock, flags); + + wait_for_completion(command->completion); + + switch (command->status) { + case COMP_COMMAND_ABORTED: + case COMP_COMMAND_RING_STOPPED: + xhci_warn(xhci, "Timeout while waiting for evaluate context command\n"); + ret = -ETIME; + break; + case COMP_PARAMETER_ERROR: + dev_warn(&udev->dev, "WARN: xHCI driver setup invalid evaluate context command.\n"); + ret = -EINVAL; + break; + case COMP_SLOT_NOT_ENABLED_ERROR: + dev_warn(&udev->dev, "WARN: slot not enabled for evaluate context command.\n"); + ret = -EINVAL; + break; + case COMP_CONTEXT_STATE_ERROR: + dev_warn(&udev->dev, "WARN: invalid context state for evaluate context command.\n"); + ret = -EINVAL; + break; + case COMP_INCOMPATIBLE_DEVICE_ERROR: + dev_warn(&udev->dev, "ERROR: Incompatible device for evaluate context command.\n"); + ret = -ENODEV; + break; + case COMP_MAX_EXIT_LATENCY_TOO_LARGE_ERROR: + /* Max Exit Latency too large error */ + dev_warn(&udev->dev, "WARN: Max Exit Latency too large\n"); + ret = -EINVAL; + break; + case COMP_SUCCESS: + xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, + "Successful evaluate context command"); + break; + default: + xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", + command->status); + ret = -EINVAL; + break; + } + + return ret; +} + static void xhci_check_bw_drop_ep_streams(struct xhci_hcd *xhci, struct xhci_virt_device *vdev, int i) { @@ -3097,8 +3086,7 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) } } - ret = xhci_configure_endpoint(xhci, udev, command, - false, false); + ret = xhci_configure_endpoint(xhci, udev, command, false); if (ret) /* Callee should call reset_bandwidth() */ goto command_cleanup; @@ -3677,8 +3665,7 @@ static int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev, changed_ep_bitmask, changed_ep_bitmask); /* Issue and wait for the configure endpoint command */ - ret = xhci_configure_endpoint(xhci, udev, config_cmd, - false, false); + ret = xhci_configure_endpoint(xhci, udev, config_cmd, false); /* xHC rejected the configure endpoint command for some reason, so we * leave the old ring intact and free our internal streams data @@ -3783,8 +3770,7 @@ static int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev, /* Issue and wait for the configure endpoint command, * which must succeed. */ - ret = xhci_configure_endpoint(xhci, udev, command, - false, true); + ret = xhci_configure_endpoint(xhci, udev, command, true); /* xHC rejected the configure endpoint command for some reason, so we * leave the streams rings intact. @@ -4522,9 +4508,7 @@ static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci, "Set up evaluate context for LPM MEL change."); /* Issue and wait for the evaluate context command. */ - ret = xhci_configure_endpoint(xhci, udev, command, - true, true); - + ret = xhci_evaluate_context(xhci, udev, command, true); if (!ret) { spin_lock_irqsave(&xhci->lock, flags); virt_dev->current_mel = max_exit_latency; @@ -5291,11 +5275,9 @@ int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev, * evaluate context command. */ if (xhci->hci_version > 0x95) - ret = xhci_configure_endpoint(xhci, hdev, config_cmd, - false, false); + ret = xhci_configure_endpoint(xhci, hdev, config_cmd, false); else - ret = xhci_configure_endpoint(xhci, hdev, config_cmd, - true, false); + ret = xhci_evaluate_context(xhci, hdev, config_cmd, false); xhci_free_command(xhci, config_cmd); return ret; -- 2.50.1