From: Niklas Neronin <niklas.neronin@linux.intel.com>
To: mathias.nyman@linux.intel.com
Cc: linux-usb@vger.kernel.org,
Niklas Neronin <niklas.neronin@linux.intel.com>
Subject: [PATCH 3/7] usb: xhci: simplify prepare_ring()
Date: Tue, 1 Dec 2026 20:41:30 +0100 [thread overview]
Message-ID: <20261201194134.265480-4-niklas.neronin@linux.intel.com> (raw)
In-Reply-To: <20261201194134.265480-1-niklas.neronin@linux.intel.com>
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 <niklas.neronin@linux.intel.com>
---
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
next prev parent reply other threads:[~2026-12-01 19:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 19:41 [PATCH 0/7] usb: xhci: command queueing cleanups Niklas Neronin
2026-12-01 19:41 ` [PATCH 1/7] usb: xhci: simplify xhci_get_input_control_ctx() Niklas Neronin
2026-12-01 19:47 ` sashiko-bot
2026-12-01 19:41 ` [PATCH 2/7] usb: xhci: add xhci_queue_set_deq() helper Niklas Neronin
2026-12-01 19:41 ` Niklas Neronin [this message]
2026-12-01 19:41 ` [PATCH 4/7] usb: xhci: split Configure Endpoint and Evaluate Context handling Niklas Neronin
2026-12-01 19:41 ` [PATCH 5/7] usb: xhci: clear EP_GETTING_NO_STREAMS when freeing streams fails Niklas Neronin
2026-12-01 19:52 ` sashiko-bot
2026-12-01 19:41 ` [PATCH 6/7] usb: xhci: remove pre-allocated free streams command Niklas Neronin
2026-12-01 19:41 ` [PATCH 7/7] usb: xhci: remove command ring TRB reservation Niklas Neronin
2026-12-01 19:52 ` [PATCH 0/7] usb: xhci: command queueing cleanups sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201194134.265480-4-niklas.neronin@linux.intel.com \
--to=niklas.neronin@linux.intel.com \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.