From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>,
Niklas Neronin <niklas.neronin@linux.intel.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [PATCH 10/33] usb: xhci: introduce macro for ring segment list iteration
Date: Wed, 6 Nov 2024 12:14:36 +0200 [thread overview]
Message-ID: <20241106101459.775897-11-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20241106101459.775897-1-mathias.nyman@linux.intel.com>
From: Niklas Neronin <niklas.neronin@linux.intel.com>
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 <andriy.shevchenko@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
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 */
--
2.25.1
next prev parent reply other threads:[~2024-11-06 10:13 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-06 10:14 [PATCH 00/33] xhci features and fixes for usb-next Mathias Nyman
2024-11-06 10:14 ` [PATCH 01/33] xhci: Add Isochronous TRB fields to TRB tracer Mathias Nyman
2024-11-06 10:14 ` [PATCH 02/33] usb: xhci: Remove unused parameters of next_trb() Mathias Nyman
2024-11-06 10:14 ` [PATCH 03/33] usb: xhci: Fix sum_trb_lengths() Mathias Nyman
2024-11-06 10:14 ` [PATCH 04/33] xhci: Cleanup Candence controller PCI device and vendor ID usage Mathias Nyman
2024-11-06 10:14 ` [PATCH 05/33] xhci: show DMA address of TRB when tracing TRBs Mathias Nyman
2024-11-06 10:14 ` [PATCH 06/33] xhci: Don't trace ring at every enqueue or dequeue increase Mathias Nyman
2024-11-06 10:14 ` [PATCH 07/33] xhci: add stream context tracing Mathias Nyman
2024-11-06 10:14 ` [PATCH 08/33] xhci: trace stream context at Set TR Deq command completion Mathias Nyman
2024-11-06 10:14 ` [PATCH 09/33] xhci: debugfs: Add virt endpoint state to xhci debugfs Mathias Nyman
2024-11-06 10:14 ` Mathias Nyman [this message]
2024-11-06 10:14 ` [PATCH 11/33] usb: xhci: remove option to change a default ring's TRB cycle bit Mathias Nyman
2024-11-06 10:14 ` [PATCH 12/33] usb: xhci: adjust xhci_alloc_segments_for_ring() arguments Mathias Nyman
2024-11-06 10:14 ` [PATCH 13/33] usb: xhci: rework xhci_free_segments_for_ring() Mathias Nyman
2024-11-06 10:14 ` [PATCH 14/33] usb: xhci: refactor xhci_link_rings() to use source and destination rings Mathias Nyman
2024-11-06 10:14 ` [PATCH 15/33] usb: xhci: rework xhci_link_segments() Mathias Nyman
2024-11-06 10:14 ` [PATCH 16/33] usb: xhci: add xhci_initialize_ring_segments() Mathias Nyman
2024-11-06 10:14 ` [PATCH 17/33] xhci: Combine two if statements for Etron xHCI host Mathias Nyman
2024-11-06 10:14 ` [PATCH 18/33] xhci: Don't issue Reset Device command to " Mathias Nyman
2024-11-06 10:14 ` [PATCH 19/33] xhci: Fix control transfer error on " Mathias Nyman
2024-11-06 10:14 ` [PATCH 20/33] xhci: Don't perform Soft Retry for " Mathias Nyman
2024-11-06 10:14 ` [PATCH 21/33] xhci: pci: Use standard pattern for device IDs Mathias Nyman
2024-11-06 10:14 ` [PATCH 22/33] xhci: pci: Fix indentation in the PCI device ID definitions Mathias Nyman
2024-11-06 10:14 ` [PATCH 23/33] usb: xhci: simplify TDs start and end naming scheme in struct 'xhci_td' Mathias Nyman
2024-11-06 10:14 ` [PATCH 24/33] usb: xhci: move link TRB quirk to xhci_gen_setup() Mathias Nyman
2024-11-06 10:14 ` [PATCH 25/33] usb: xhci: request MSI/-X according to requested amount Mathias Nyman
2024-11-06 10:14 ` [PATCH 26/33] usb: xhci: improve xhci_clear_command_ring() Mathias Nyman
2024-11-06 10:14 ` [PATCH 27/33] usb: xhci: remove unused arguments from td_to_noop() Mathias Nyman
2024-11-06 10:14 ` [PATCH 28/33] usb: xhci: refactor xhci_td_cleanup() to return void Mathias Nyman
2024-11-06 10:14 ` [PATCH 29/33] usb: xhci: add help function xhci_dequeue_td() Mathias Nyman
2024-11-06 10:14 ` [PATCH 30/33] usb: xhci: remove irrelevant comment Mathias Nyman
2024-11-06 10:14 ` [PATCH 31/33] usb: xhci: Limit Stop Endpoint retries Mathias Nyman
2024-11-06 10:14 ` [PATCH 32/33] usb: xhci: Fix TD invalidation under pending Set TR Dequeue Mathias Nyman
2024-11-06 10:14 ` [PATCH 33/33] usb: xhci: Avoid queuing redundant Stop Endpoint commands 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=20241106101459.775897-11-mathias.nyman@linux.intel.com \
--to=mathias.nyman@linux.intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=niklas.neronin@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.