new file mode 100644
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * This file contains queue API.
+ *
+ * Copyright (C) [2022-2025] Renesas Electronics Corporation and/or its affiliates.
+ */
+
+#include <linux/sched.h>
+#include <linux/slab.h>
+
+#include "q.h"
+
+bool ra6w_q_empty(struct ra6w_q *q)
+{
+ unsigned long flags = 0;
+ bool empty = 0;
+
+ spin_lock_irqsave(&q->lock, flags);
+ empty = (CIRC_CNT(q->head, q->tail, q->max_count) == 0);
+ spin_unlock_irqrestore(&q->lock, flags);
+
+ return empty;
+}
+
+int ra6w_q_push(struct ra6w_q *q, void *buf)
+{
+ int ret = -ENOENT;
+ unsigned long head;
+ unsigned long tail;
+ unsigned long flags = 0;
+
+ spin_lock_irqsave(&q->lock, flags);
+
+ head = q->head;
+ tail = READ_ONCE(q->tail);
+
+ if (CIRC_SPACE(head, tail, q->max_count) >= 1) {
+ q->buf[head] = buf;
+ WRITE_ONCE(q->head, (head + 1) & (q->max_count - 1));
+ ret = 0;
+ }
+
+ spin_unlock_irqrestore(&q->lock, flags);
+
+ return ret;
+}
+
+void *ra6w_q_pop(struct ra6w_q *q)
+{
+ void *buf = NULL;
+ unsigned long head;
+ unsigned long tail;
+ unsigned long flags = 0;
+
+ spin_lock_irqsave(&q->lock, flags);
+
+ head = READ_ONCE(q->head);
+ tail = q->tail;
+
+ if (CIRC_CNT(head, tail, q->max_count) >= 1) {
+ buf = q->buf[tail];
+ WRITE_ONCE(q->tail, (tail + 1) & (q->max_count - 1));
+ }
+
+ spin_unlock_irqrestore(&q->lock, flags);
+
+ return buf;
+}
+
+bool ra6w_q_event_condition(const struct ra6w_q_event *event, int event_mask, int *ret_event)
+{
+ *ret_event = atomic_read(&event->condition);
+
+ return *ret_event & event_mask;
+}
+
+void ra6w_q_event_set(struct ra6w_q_event *event, int event_val)
+{
+ atomic_or(event_val, &event->condition);
+ wake_up_interruptible(&event->wait_queue);
+}
+
+int ra6w_q_wait(struct ra6w_q_event *event, int event_mask)
+{
+ int ret_event = 0;
+
+ wait_event_interruptible(event->wait_queue,
+ ra6w_q_event_condition(event, event_mask, &ret_event));
+
+ return ret_event;
+}
+
+int ra6w_q_wait_timeout(struct ra6w_q_event *event, int event_mask)
+{
+ int ret_event = 0;
+
+ wait_event_interruptible_timeout(event->wait_queue,
+ ra6w_q_event_condition(event, event_mask, &ret_event),
+ msecs_to_jiffies(event->timeout));
+
+ return ret_event;
+}
+
+int ra6w_q_init(struct ra6w_q *q, size_t max_count, size_t buf_size)
+{
+ q->head = 0;
+ q->tail = 0;
+ q->max_count = max_count;
+ spin_lock_init(&q->lock);
+
+ q->buf = kcalloc(max_count, buf_size, GFP_KERNEL);
+ if (!q->buf)
+ return -ENOMEM;
+
+ return 0;
+}
+
+static void ra6w_q_free(struct ra6w_q *q)
+{
+ void *buf = NULL;
+
+ while ((buf = ra6w_q_pop(q)))
+ kfree(buf);
+}
+
+void ra6w_q_deinit(struct ra6w_q *q)
+{
+ ra6w_q_free(q);
+ kfree(q->buf);
+ q->head = 0;
+ q->tail = 0;
+ q->max_count = 0;
+ q->buf = NULL;
+}