Skip to content

Commit c6bb38a

Browse files
Binoy Jayangregkh
Binoy Jayan
authored andcommitted
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 <[email protected]> Reviewed-by: Arnd Bergmann <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 77eebe8 commit c6bb38a

File tree

4 files changed

+162
-174
lines changed

4 files changed

+162
-174
lines changed

drivers/staging/wilc1000/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ ccflags-y += -DFIRMWARE_1002=\"atmel/wilc1002_firmware.bin\" \
66
ccflags-y += -I$(src)/ -DWILC_ASIC_A0 -DWILC_DEBUGFS
77

88
wilc1000-objs := wilc_wfi_cfgoperations.o linux_wlan.o linux_mon.o \
9-
wilc_msgqueue.o \
109
coreconfigurator.o host_interface.o \
1110
wilc_wlan_cfg.o wilc_debugfs.o \
1211
wilc_wlan.o

drivers/staging/wilc1000/host_interface.c

Lines changed: 162 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
#include <linux/kthread.h>
44
#include <linux/delay.h>
55
#include <linux/completion.h>
6+
#include <linux/list.h>
67
#include "host_interface.h"
8+
#include <linux/spinlock.h>
9+
#include <linux/errno.h>
710
#include "coreconfigurator.h"
811
#include "wilc_wlan.h"
912
#include "wilc_wlan_if.h"
10-
#include "wilc_msgqueue.h"
1113
#include <linux/etherdevice.h>
1214
#include "wilc_wfi_netdevice.h"
1315

@@ -57,6 +59,20 @@
5759
#define TCP_ACK_FILTER_LINK_SPEED_THRESH 54
5860
#define DEFAULT_LINK_SPEED 72
5961

62+
struct message {
63+
void *buf;
64+
u32 len;
65+
struct list_head list;
66+
};
67+
68+
struct message_queue {
69+
struct semaphore sem;
70+
spinlock_t lock;
71+
bool exiting;
72+
u32 recv_count;
73+
struct list_head msg_list;
74+
};
75+
6076
struct host_if_wpa_attr {
6177
u8 *key;
6278
const u8 *mac_addr;
@@ -263,6 +279,151 @@ static struct wilc_vif *join_req_vif;
263279
static void *host_int_ParseJoinBssParam(struct network_info *ptstrNetworkInfo);
264280
static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
265281
static s32 Handle_ScanDone(struct wilc_vif *vif, enum scan_event enuEvent);
282+
static int wilc_mq_create(struct message_queue *mq);
283+
static int wilc_mq_send(struct message_queue *mq,
284+
const void *send_buf, u32 send_buf_size);
285+
static int wilc_mq_recv(struct message_queue *mq,
286+
void *recv_buf, u32 recv_buf_size, u32 *recv_len);
287+
static int wilc_mq_destroy(struct message_queue *mq);
288+
289+
/*!
290+
* @author syounan
291+
* @date 1 Sep 2010
292+
* @note copied from FLO glue implementatuion
293+
* @version 1.0
294+
*/
295+
static int wilc_mq_create(struct message_queue *mq)
296+
{
297+
spin_lock_init(&mq->lock);
298+
sema_init(&mq->sem, 0);
299+
INIT_LIST_HEAD(&mq->msg_list);
300+
mq->recv_count = 0;
301+
mq->exiting = false;
302+
return 0;
303+
}
304+
305+
/*!
306+
* @author syounan
307+
* @date 1 Sep 2010
308+
* @note copied from FLO glue implementatuion
309+
* @version 1.0
310+
*/
311+
static int wilc_mq_destroy(struct message_queue *mq)
312+
{
313+
struct message *msg;
314+
315+
mq->exiting = true;
316+
317+
/* Release any waiting receiver thread. */
318+
while (mq->recv_count > 0) {
319+
up(&mq->sem);
320+
mq->recv_count--;
321+
}
322+
323+
while (!list_empty(&mq->msg_list)) {
324+
msg = list_first_entry(&mq->msg_list, struct message, list);
325+
list_del(&msg->list);
326+
kfree(msg->buf);
327+
}
328+
329+
return 0;
330+
}
331+
332+
/*!
333+
* @author syounan
334+
* @date 1 Sep 2010
335+
* @note copied from FLO glue implementatuion
336+
* @version 1.0
337+
*/
338+
static int wilc_mq_send(struct message_queue *mq,
339+
const void *send_buf, u32 send_buf_size)
340+
{
341+
unsigned long flags;
342+
struct message *new_msg = NULL;
343+
344+
if (!mq || (send_buf_size == 0) || !send_buf)
345+
return -EINVAL;
346+
347+
if (mq->exiting)
348+
return -EFAULT;
349+
350+
/* construct a new message */
351+
new_msg = kmalloc(sizeof(*new_msg), GFP_ATOMIC);
352+
if (!new_msg)
353+
return -ENOMEM;
354+
355+
new_msg->len = send_buf_size;
356+
INIT_LIST_HEAD(&new_msg->list);
357+
new_msg->buf = kmemdup(send_buf, send_buf_size, GFP_ATOMIC);
358+
if (!new_msg->buf) {
359+
kfree(new_msg);
360+
return -ENOMEM;
361+
}
362+
363+
spin_lock_irqsave(&mq->lock, flags);
364+
365+
/* add it to the message queue */
366+
list_add_tail(&new_msg->list, &mq->msg_list);
367+
368+
spin_unlock_irqrestore(&mq->lock, flags);
369+
370+
up(&mq->sem);
371+
372+
return 0;
373+
}
374+
375+
/*!
376+
* @author syounan
377+
* @date 1 Sep 2010
378+
* @note copied from FLO glue implementatuion
379+
* @version 1.0
380+
*/
381+
static int wilc_mq_recv(struct message_queue *mq,
382+
void *recv_buf, u32 recv_buf_size, u32 *recv_len)
383+
{
384+
struct message *msg;
385+
unsigned long flags;
386+
387+
if (!mq || (recv_buf_size == 0) || !recv_buf || !recv_len)
388+
return -EINVAL;
389+
390+
if (mq->exiting)
391+
return -EFAULT;
392+
393+
spin_lock_irqsave(&mq->lock, flags);
394+
mq->recv_count++;
395+
spin_unlock_irqrestore(&mq->lock, flags);
396+
397+
down(&mq->sem);
398+
spin_lock_irqsave(&mq->lock, flags);
399+
400+
if (list_empty(&mq->msg_list)) {
401+
spin_unlock_irqrestore(&mq->lock, flags);
402+
up(&mq->sem);
403+
return -EFAULT;
404+
}
405+
/* check buffer size */
406+
msg = list_first_entry(&mq->msg_list, struct message, list);
407+
if (recv_buf_size < msg->len) {
408+
spin_unlock_irqrestore(&mq->lock, flags);
409+
up(&mq->sem);
410+
return -EOVERFLOW;
411+
}
412+
413+
/* consume the message */
414+
mq->recv_count--;
415+
memcpy(recv_buf, msg->buf, msg->len);
416+
*recv_len = msg->len;
417+
418+
list_del(&msg->list);
419+
420+
kfree(msg->buf);
421+
kfree(msg);
422+
423+
spin_unlock_irqrestore(&mq->lock, flags);
424+
425+
return 0;
426+
}
266427

267428
/* The u8IfIdx starts from 0 to NUM_CONCURRENT_IFC -1, but 0 index used as
268429
* special purpose in wilc device, so we add 1 to the index to starts from 1.

drivers/staging/wilc1000/wilc_msgqueue.c

Lines changed: 0 additions & 144 deletions
This file was deleted.

drivers/staging/wilc1000/wilc_msgqueue.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)