2 #include "wilc_msgqueue.h"
3 #include <linux/spinlock.h>
4 #include "linux_wlan_common.h"
5 #include <linux/errno.h>
6 #include <linux/slab.h>
11 * @note copied from FLO glue implementatuion
14 int wilc_mq_create(struct message_queue *mq)
16 spin_lock_init(&mq->lock);
17 sema_init(&mq->sem, 0);
18 INIT_LIST_HEAD(&mq->msg_list);
27 * @note copied from FLO glue implementatuion
30 int wilc_mq_destroy(struct message_queue *mq)
36 /* Release any waiting receiver thread. */
37 while (mq->recv_count > 0) {
42 while (!list_empty(&mq->msg_list)) {
43 msg = list_first_entry(&mq->msg_list, struct message, list);
54 * @note copied from FLO glue implementatuion
57 int wilc_mq_send(struct message_queue *mq,
58 const void *send_buf, u32 send_buf_size)
61 struct message *new_msg = NULL;
63 if (!mq || (send_buf_size == 0) || !send_buf)
69 /* construct a new message */
70 new_msg = kmalloc(sizeof(*new_msg), GFP_ATOMIC);
74 new_msg->len = send_buf_size;
75 INIT_LIST_HEAD(&new_msg->list);
76 new_msg->buf = kmemdup(send_buf, send_buf_size, GFP_ATOMIC);
82 spin_lock_irqsave(&mq->lock, flags);
84 /* add it to the message queue */
85 list_add_tail(&new_msg->list, &mq->msg_list);
87 spin_unlock_irqrestore(&mq->lock, flags);
97 * @note copied from FLO glue implementatuion
100 int wilc_mq_recv(struct message_queue *mq,
101 void *recv_buf, u32 recv_buf_size, u32 *recv_len)
106 if (!mq || (recv_buf_size == 0) || !recv_buf || !recv_len)
112 spin_lock_irqsave(&mq->lock, flags);
114 spin_unlock_irqrestore(&mq->lock, flags);
117 spin_lock_irqsave(&mq->lock, flags);
119 if (list_empty(&mq->msg_list)) {
120 spin_unlock_irqrestore(&mq->lock, flags);
124 /* check buffer size */
125 msg = list_first_entry(&mq->msg_list, struct message, list);
126 if (recv_buf_size < msg->len) {
127 spin_unlock_irqrestore(&mq->lock, flags);
132 /* consume the message */
134 memcpy(recv_buf, msg->buf, msg->len);
135 *recv_len = msg->len;
137 list_del(&msg->list);
142 spin_unlock_irqrestore(&mq->lock, flags);