summaryrefslogtreecommitdiffstats
path: root/drivers/staging/wilc1000/host_interface.c
diff options
context:
space:
mode:
authorBinoy Jayan2016-06-23 07:41:50 +0200
committerGreg Kroah-Hartman2016-06-25 23:39:53 +0200
commitc6bb38a5e82a26c6556e05d2140c3a1b4176c2ab (patch)
tree18bd98398f1016eb480fb69e16bf6deb60dca6da /drivers/staging/wilc1000/host_interface.c
parentstaging: wilc1000: Remove semaphore close_exit_sync (diff)
downloadkernel-qcow2-linux-c6bb38a5e82a26c6556e05d2140c3a1b4176c2ab.tar.gz
kernel-qcow2-linux-c6bb38a5e82a26c6556e05d2140c3a1b4176c2ab.tar.xz
kernel-qcow2-linux-c6bb38a5e82a26c6556e05d2140c3a1b4176c2ab.zip
staging: wilc1000: message_queue: Move code to host interface
Move the contents of wilc_msgqueue.c and wilc_msgqueue.h into host_interface.c, remove 'wilc_msgqueue.c' and 'wilc_msgqueue.h'. This is done so as to restructure the implementation of the kthread 'hostIFthread' using a work queue. Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/wilc1000/host_interface.c')
-rw-r--r--drivers/staging/wilc1000/host_interface.c163
1 files changed, 162 insertions, 1 deletions
diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 5b2278b9a060..a34a1bbe0853 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -3,11 +3,13 @@
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/completion.h>
+#include <linux/list.h>
#include "host_interface.h"
+#include <linux/spinlock.h>
+#include <linux/errno.h>
#include "coreconfigurator.h"
#include "wilc_wlan.h"
#include "wilc_wlan_if.h"
-#include "wilc_msgqueue.h"
#include <linux/etherdevice.h>
#include "wilc_wfi_netdevice.h"
@@ -57,6 +59,20 @@
#define TCP_ACK_FILTER_LINK_SPEED_THRESH 54
#define DEFAULT_LINK_SPEED 72
+struct message {
+ void *buf;
+ u32 len;
+ struct list_head list;
+};
+
+struct message_queue {
+ struct semaphore sem;
+ spinlock_t lock;
+ bool exiting;
+ u32 recv_count;
+ struct list_head msg_list;
+};
+
struct host_if_wpa_attr {
u8 *key;
const u8 *mac_addr;
@@ -263,6 +279,151 @@ static struct wilc_vif *join_req_vif;
static void *host_int_ParseJoinBssParam(struct network_info *ptstrNetworkInfo);
static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
static s32 Handle_ScanDone(struct wilc_vif *vif, enum scan_event enuEvent);
+static int wilc_mq_create(struct message_queue *mq);
+static int wilc_mq_send(struct message_queue *mq,
+ const void *send_buf, u32 send_buf_size);
+static int wilc_mq_recv(struct message_queue *mq,
+ void *recv_buf, u32 recv_buf_size, u32 *recv_len);
+static int wilc_mq_destroy(struct message_queue *mq);
+
+/*!
+ * @author syounan
+ * @date 1 Sep 2010
+ * @note copied from FLO glue implementatuion
+ * @version 1.0
+ */
+static int wilc_mq_create(struct message_queue *mq)
+{
+ spin_lock_init(&mq->lock);
+ sema_init(&mq->sem, 0);
+ INIT_LIST_HEAD(&mq->msg_list);
+ mq->recv_count = 0;
+ mq->exiting = false;
+ return 0;
+}
+
+/*!
+ * @author syounan
+ * @date 1 Sep 2010
+ * @note copied from FLO glue implementatuion
+ * @version 1.0
+ */
+static int wilc_mq_destroy(struct message_queue *mq)
+{
+ struct message *msg;
+
+ mq->exiting = true;
+
+ /* Release any waiting receiver thread. */
+ while (mq->recv_count > 0) {
+ up(&mq->sem);
+ mq->recv_count--;
+ }
+
+ while (!list_empty(&mq->msg_list)) {
+ msg = list_first_entry(&mq->msg_list, struct message, list);
+ list_del(&msg->list);
+ kfree(msg->buf);
+ }
+
+ return 0;
+}
+
+/*!
+ * @author syounan
+ * @date 1 Sep 2010
+ * @note copied from FLO glue implementatuion
+ * @version 1.0
+ */
+static int wilc_mq_send(struct message_queue *mq,
+ const void *send_buf, u32 send_buf_size)
+{
+ unsigned long flags;
+ struct message *new_msg = NULL;
+
+ if (!mq || (send_buf_size == 0) || !send_buf)
+ return -EINVAL;
+
+ if (mq->exiting)
+ return -EFAULT;
+
+ /* construct a new message */
+ new_msg = kmalloc(sizeof(*new_msg), GFP_ATOMIC);
+ if (!new_msg)
+ return -ENOMEM;
+
+ new_msg->len = send_buf_size;
+ INIT_LIST_HEAD(&new_msg->list);
+ new_msg->buf = kmemdup(send_buf, send_buf_size, GFP_ATOMIC);
+ if (!new_msg->buf) {
+ kfree(new_msg);
+ return -ENOMEM;
+ }
+
+ spin_lock_irqsave(&mq->lock, flags);
+
+ /* add it to the message queue */
+ list_add_tail(&new_msg->list, &mq->msg_list);
+
+ spin_unlock_irqrestore(&mq->lock, flags);
+
+ up(&mq->sem);
+
+ return 0;
+}
+
+/*!
+ * @author syounan
+ * @date 1 Sep 2010
+ * @note copied from FLO glue implementatuion
+ * @version 1.0
+ */
+static int wilc_mq_recv(struct message_queue *mq,
+ void *recv_buf, u32 recv_buf_size, u32 *recv_len)
+{
+ struct message *msg;
+ unsigned long flags;
+
+ if (!mq || (recv_buf_size == 0) || !recv_buf || !recv_len)
+ return -EINVAL;
+
+ if (mq->exiting)
+ return -EFAULT;
+
+ spin_lock_irqsave(&mq->lock, flags);
+ mq->recv_count++;
+ spin_unlock_irqrestore(&mq->lock, flags);
+
+ down(&mq->sem);
+ spin_lock_irqsave(&mq->lock, flags);
+
+ if (list_empty(&mq->msg_list)) {
+ spin_unlock_irqrestore(&mq->lock, flags);
+ up(&mq->sem);
+ return -EFAULT;
+ }
+ /* check buffer size */
+ msg = list_first_entry(&mq->msg_list, struct message, list);
+ if (recv_buf_size < msg->len) {
+ spin_unlock_irqrestore(&mq->lock, flags);
+ up(&mq->sem);
+ return -EOVERFLOW;
+ }
+
+ /* consume the message */
+ mq->recv_count--;
+ memcpy(recv_buf, msg->buf, msg->len);
+ *recv_len = msg->len;
+
+ list_del(&msg->list);
+
+ kfree(msg->buf);
+ kfree(msg);
+
+ spin_unlock_irqrestore(&mq->lock, flags);
+
+ return 0;
+}
/* The u8IfIdx starts from 0 to NUM_CONCURRENT_IFC -1, but 0 index used as
* special purpose in wilc device, so we add 1 to the index to starts from 1.