From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: linux-usb@vger.kernel.org
Cc: Yehezkel Bernat <YehezkelShB@gmail.com>,
Lukas Wunner <lukas@wunner.de>,
Andreas Noever <andreas.noever@gmail.com>,
Alan Borzeszkowski <alan.borzeszkowski@linux.intel.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org,
Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: [PATCH 7/9] thunderbolt: Add tb_ring_flush()
Date: Tue, 28 Apr 2026 09:22:07 +0200 [thread overview]
Message-ID: <20260428072209.3084930-8-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20260428072209.3084930-1-mika.westerberg@linux.intel.com>
This allows the caller to wait for the ring to be empty. We are going to
need this in the upcoming userspace tunneling support.
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
drivers/thunderbolt/nhi.c | 28 ++++++++++++++++++++++++++++
include/linux/thunderbolt.h | 3 +++
2 files changed, 31 insertions(+)
diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
index 13009246e617..a0a789bfb680 100644
--- a/drivers/thunderbolt/nhi.c
+++ b/drivers/thunderbolt/nhi.c
@@ -325,6 +325,8 @@ static void ring_work(struct work_struct *work)
if (frame->callback)
frame->callback(ring, frame, canceled);
}
+
+ wake_up(&ring->wait);
}
int __tb_ring_enqueue(struct tb_ring *ring, struct ring_frame *frame)
@@ -601,6 +603,7 @@ static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size,
INIT_LIST_HEAD(&ring->queue);
INIT_LIST_HEAD(&ring->in_flight);
INIT_WORK(&ring->work, ring_work);
+ init_waitqueue_head(&ring->wait);
ring->nhi = nhi;
ring->hop = hop;
@@ -760,6 +763,31 @@ void tb_ring_start(struct tb_ring *ring)
}
EXPORT_SYMBOL_GPL(tb_ring_start);
+static bool tb_ring_empty(struct tb_ring *ring)
+{
+ guard(spinlock_irqsave)(&ring->lock);
+ return list_empty(&ring->in_flight);
+}
+
+/**
+ * tb_ring_flush() - Waits for a ring to be empty
+ * @ring: Ring to wait
+ * @timeout_msec: Timeout in ms how long to wait.
+ *
+ * This can be called before stopping a ring to make sure all the frames
+ * submitted prior have been completed.
+ *
+ * Return: %true if the ring is empty now, %false otherwise.
+ */
+bool tb_ring_flush(struct tb_ring *ring, unsigned int timeout_msec)
+{
+ if (!wait_event_timeout(ring->wait, tb_ring_empty(ring),
+ msecs_to_jiffies(timeout_msec)))
+ return false;
+ return tb_ring_empty(ring);
+}
+EXPORT_SYMBOL_GPL(tb_ring_flush);
+
/**
* tb_ring_stop() - shutdown a ring
* @ring: Ring to stop
diff --git a/include/linux/thunderbolt.h b/include/linux/thunderbolt.h
index 9df8a356396f..9c5cb5e4f23d 100644
--- a/include/linux/thunderbolt.h
+++ b/include/linux/thunderbolt.h
@@ -556,6 +556,7 @@ struct tb_nhi {
* @poll_data: Data passed to @start_poll
* @interval_nsec: Interval counter if interrupt throttling is to be
* used with this ring (in ns)
+ * @wait: Used to signal that the ring may be empty now
*/
struct tb_ring {
spinlock_t lock;
@@ -580,6 +581,7 @@ struct tb_ring {
void (*start_poll)(void *data);
void *poll_data;
unsigned int interval_nsec;
+ wait_queue_head_t wait;
};
/* Leave ring interrupt enabled on suspend */
@@ -653,6 +655,7 @@ struct tb_ring *tb_ring_alloc_rx(struct tb_nhi *nhi, int hop, int size,
u16 sof_mask, u16 eof_mask,
void (*start_poll)(void *), void *poll_data);
void tb_ring_start(struct tb_ring *ring);
+bool tb_ring_flush(struct tb_ring *ring, unsigned int timeout_msec);
void tb_ring_stop(struct tb_ring *ring);
void tb_ring_free(struct tb_ring *ring);
--
2.50.1
next prev parent reply other threads:[~2026-04-28 7:22 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-28 7:22 [PATCH 0/9] thunderbolt: Introduce USB4STREAM Mika Westerberg
2026-04-28 7:22 ` [PATCH 1/9] thunderbolt: Add tb_property_merge_dir() Mika Westerberg
2026-04-28 7:22 ` [PATCH 2/9] thunderbolt: Add KUnit test for tb_property_merge_dir() Mika Westerberg
2026-04-28 7:22 ` [PATCH 3/9] thunderbolt: Allow service drivers to specify their own properties Mika Westerberg
2026-04-28 7:22 ` [PATCH 4/9] thunderbolt / net: Move ring_frame_size() to thunderbolt.h Mika Westerberg
2026-04-28 7:22 ` [PATCH 5/9] thunderbolt / net: Let the service drivers configure interrupt throttling Mika Westerberg
2026-04-28 14:59 ` Andrew Lunn
2026-04-28 17:26 ` Mika Westerberg
2026-04-28 18:10 ` Greg KH
2026-04-28 20:29 ` Alan Stern
2026-04-28 7:22 ` [PATCH 6/9] thunderbolt: Add helper to figure size of the ring Mika Westerberg
2026-04-28 7:22 ` Mika Westerberg [this message]
2026-04-28 7:22 ` [PATCH 8/9] thunderbolt: Add support for ConfigFS Mika Westerberg
2026-04-28 7:22 ` [PATCH 9/9] thunderbolt: Add support for USB4STREAM Mika Westerberg
2026-04-28 11:57 ` Greg KH
2026-04-28 12:03 ` Mika Westerberg
2026-04-28 13:54 ` Greg KH
2026-04-28 14:11 ` Mika Westerberg
2026-04-28 18:10 ` Greg KH
2026-04-29 7:05 ` Mika Westerberg
2026-04-28 15:08 ` Andrew Lunn
2026-04-28 15:13 ` Mika Westerberg
2026-04-28 16:45 ` Andrew Lunn
2026-04-28 17:24 ` Mika Westerberg
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=20260428072209.3084930-8-mika.westerberg@linux.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=YehezkelShB@gmail.com \
--cc=alan.borzeszkowski@linux.intel.com \
--cc=andreas.noever@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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.