All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>, Lukas Wunner <lukas@wunner.de>,
	Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [PATCH 06/19] xhci: Adjust segment numbers after ring expansion
Date: Thu, 19 Oct 2023 13:29:11 +0300	[thread overview]
Message-ID: <20231019102924.2797346-7-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20231019102924.2797346-1-mathias.nyman@linux.intel.com>

From: Lukas Wunner <lukas@wunner.de>

Initial xhci_ring allocation has just been amended to assign a
monotonically increasing number to each ring segment.

However rings may be expanded after initial allocation.

So number newly inserted segments starting from the preceding segment in
the ring and renumber all segments succeeding the newly inserted ones.

This is not a fix because ring expansion currently isn't done on the
Event Ring and that's the only ring type using the segment number.
It's just in preparation for when either Event Ring expansion is added
or when other ring types start making use of the segment number.

Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-mem.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index a8a8fc2cc4a5..1c0f5263cf81 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -130,7 +130,7 @@ 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)
 {
-	struct xhci_segment *next;
+	struct xhci_segment *next, *seg;
 	bool chain_links;
 
 	if (!ring || !first || !last)
@@ -153,6 +153,9 @@ static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *ring,
 			|= cpu_to_le32(LINK_TOGGLE);
 		ring->last_seg = last;
 	}
+
+	for (seg = last; seg != ring->last_seg; seg = seg->next)
+		seg->next->num = seg->num + 1;
 }
 
 /*
@@ -322,11 +325,11 @@ void xhci_initialize_ring_info(struct xhci_ring *ring,
 /* 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, unsigned int cycle_state,
-		enum xhci_ring_type type, unsigned int max_packet, gfp_t flags)
+		unsigned int num_segs, unsigned int num,
+		unsigned int cycle_state, enum xhci_ring_type type,
+		unsigned int max_packet, gfp_t flags)
 {
 	struct xhci_segment *prev;
-	unsigned int num = 0;
 	bool chain_links;
 
 	/* Set chain bit for 0.95 hosts, and for isoc rings on AMD 0.96 host */
@@ -392,7 +395,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,
+			&ring->last_seg, num_segs, 0, cycle_state, type,
 			max_packet, flags);
 	if (ret)
 		goto fail;
@@ -432,7 +435,8 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring,
 	int			ret;
 
 	ret = xhci_alloc_segments_for_ring(xhci, &first, &last,
-			num_new_segs, ring->cycle_state, ring->type,
+			num_new_segs, ring->enq_seg->num + 1,
+			ring->cycle_state, ring->type,
 			ring->bounce_buf_len, flags);
 	if (ret)
 		return -ENOMEM;
-- 
2.25.1


  parent reply	other threads:[~2023-10-19 10:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-19 10:29 [PATCH 00/19] xhci features for usb-next Mathias Nyman
2023-10-19 10:29 ` [PATCH 01/19] xhci: pass port structure to tracing instead of port number Mathias Nyman
2023-10-19 10:29 ` [PATCH 02/19] xhci: Add busnumber to port tracing Mathias Nyman
2023-10-19 10:29 ` [PATCH 03/19] xhci: expand next_trb() helper to support more ring types Mathias Nyman
2023-10-19 10:29 ` [PATCH 04/19] xhci: Set DESI bits in ERDP register correctly Mathias Nyman
2023-10-19 10:29 ` [PATCH 05/19] xhci: Use more than one Event Ring segment Mathias Nyman
2023-10-19 10:29 ` Mathias Nyman [this message]
2023-10-19 10:29 ` [PATCH 07/19] xhci: Update last segment pointer after Event Ring expansion Mathias Nyman
2023-10-19 10:29 ` [PATCH 08/19] xhci: Expose segment numbers in debugfs Mathias Nyman
2023-10-19 10:29 ` [PATCH 09/19] xhci: Clean up ERST_PTR_MASK inversion Mathias Nyman
2023-10-19 10:29 ` [PATCH 10/19] xhci: Clean up stale comment on ERST_SIZE macro Mathias Nyman
2023-10-19 10:29 ` [PATCH 11/19] xhci: Clean up xhci_{alloc,free}_erst() declarations Mathias Nyman
2023-10-19 10:29 ` [PATCH 12/19] xhci: simplify event ring dequeue tracking for transfer events Mathias Nyman
2023-10-19 10:29 ` [PATCH 13/19] xhci: Simplify event ring dequeue pointer update for port change events Mathias Nyman
2023-10-19 10:29 ` [PATCH 14/19] xhci: Loosen RPM as default policy to cover for AMD xHC 1.1 Mathias Nyman
2023-10-19 10:29 ` [PATCH 15/19] xhci: Enable RPM on controllers that support low-power states Mathias Nyman
2023-10-19 10:29 ` [PATCH 16/19] xhci: split free interrupter into separate remove and free parts Mathias Nyman
2023-10-19 10:29 ` [PATCH 17/19] usb: xhci: Implement xhci_handshake_check_state() helper Mathias Nyman
2023-10-19 10:29 ` [PATCH 18/19] usb: host: xhci-plat: fix possible kernel oops while resuming Mathias Nyman
2023-10-19 10:29 ` [PATCH 19/19] usb: host: xhci: Avoid XHCI resume delay if SSUSB device is not present Mathias Nyman

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=20231019102924.2797346-7-mathias.nyman@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lukas@wunner.de \
    /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.