if (frame->callback)
frame->callback(ring, frame, canceled);
}
+
+ wake_up(&ring->wait);
}
int __tb_ring_enqueue(struct tb_ring *ring, struct ring_frame *frame)
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;
}
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
* @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;
void (*start_poll)(void *data);
void *poll_data;
unsigned int interval_nsec;
+ wait_queue_head_t wait;
};
/* Leave ring interrupt enabled on suspend */
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);