thunderbolt: Add tb_ring_poll_pending()

This helper can be used to figure out whether tb_ring_poll() has a frame
to be returned. This can be used without the caller needing to take its
own lock.

Assisted-by: LLM
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
This commit is contained in:
Mika Westerberg 2026-09-07 16:40:45 +03:00
parent 4d84caebab
commit de9d89b408
2 changed files with 20 additions and 0 deletions

View File

@ -454,6 +454,25 @@ struct ring_frame *tb_ring_poll(struct tb_ring *ring)
}
EXPORT_SYMBOL_GPL(tb_ring_poll);
/**
* tb_ring_poll_pending() - Does the ring have completed frame
* @ring: Ring to check
*
* Can be used to check whether there is a completed frame in the ring
* that next call to tb_ring_poll() returns.
*
* Return: %true if a completed frame is waiting, %false otherwise.
*/
bool tb_ring_poll_pending(struct tb_ring *ring)
{
guard(spinlock_irqsave)(&ring->lock);
if (!ring->running || ring_empty(ring))
return false;
return !!(ring->descriptors[ring->tail].flags & RING_DESC_COMPLETED);
}
EXPORT_SYMBOL_GPL(tb_ring_poll_pending);
static void __ring_interrupt_mask(struct tb_ring *ring, bool mask)
{
int interrupt_index = ring_interrupt_index(ring);

View File

@ -754,6 +754,7 @@ static inline int tb_ring_tx_more(struct tb_ring *ring, struct ring_frame *frame
/* Used only when the ring is in polling mode */
struct ring_frame *tb_ring_poll(struct tb_ring *ring);
bool tb_ring_poll_pending(struct tb_ring *ring);
void tb_ring_poll_complete(struct tb_ring *ring);
int tb_ring_throttling(struct tb_ring *ring, unsigned int interval_nsec);