Staging: wilc1000: coreconfigurator: Remove trailing whitespace
[firefly-linux-kernel-4.4.55.git] / drivers / staging / wilc1000 / wilc_wlan.c
index ddb03a82b0f9a966d9c1aa24c25a50db839d9b9c..c0266574770521860aff9db94f70b882a66feb49 100644 (file)
@@ -8,7 +8,8 @@
 /* //////////////////////////////////////////////////////////////////////////// */
 
 #include "wilc_wlan_if.h"
-#include "wilc_wlan.h"
+#include "wilc_wfi_netdevice.h"
+#include "wilc_wlan_cfg.h"
 
 /********************************************
  *
  ********************************************/
 extern wilc_hif_func_t hif_sdio;
 extern wilc_hif_func_t hif_spi;
-extern wilc_cfg_func_t mac_cfg;
-extern void WILC_WFI_mgmt_rx(u8 *buff, u32 size);
 u32 wilc_get_chipid(u8 update);
-u16 Set_machw_change_vir_if(bool bValue);
 
 
 
@@ -30,61 +28,48 @@ typedef struct {
        /**
         *      input interface functions
         **/
-       wilc_wlan_os_func_t os_func;
        wilc_wlan_io_func_t io_func;
-       wilc_wlan_net_func_t net_func;
-       wilc_wlan_indicate_func_t indicate_func;
 
        /**
         *      host interface functions
         **/
        wilc_hif_func_t hif_func;
-       struct mutex *hif_lock;
 
        /**
         *      configuration interface functions
         **/
-       wilc_cfg_func_t cif_func;
        int cfg_frame_in_use;
        wilc_cfg_frame_t cfg_frame;
        u32 cfg_frame_offset;
        int cfg_seq_no;
-       void *cfg_wait;
 
        /**
         *      RX buffer
         **/
        #ifdef MEMORY_STATIC
-       u32 rx_buffer_size;
        u8 *rx_buffer;
        u32 rx_buffer_offset;
        #endif
        /**
         *      TX buffer
         **/
-       u32 tx_buffer_size;
        u8 *tx_buffer;
        u32 tx_buffer_offset;
 
        /**
         *      TX queue
         **/
-       void *txq_lock;
 
-       struct semaphore *txq_add_to_head_lock;
-       void *txq_spinlock;
        unsigned long txq_spinlock_flags;
 
        struct txq_entry_t *txq_head;
        struct txq_entry_t *txq_tail;
        int txq_entries;
-       void *txq_wait;
        int txq_exit;
 
        /**
         *      RX queue
         **/
-       struct mutex *rxq_lock;
        struct rxq_entry_t *rxq_head;
        struct rxq_entry_t *rxq_tail;
        int rxq_entries;
@@ -115,8 +100,7 @@ static void wilc_debug(u32 flag, char *fmt, ...)
                vsprintf(buf, fmt, args);
                va_end(args);
 
-               if (g_wlan.os_func.os_debug)
-                       g_wlan.os_func.os_debug(buf);
+               linux_wlan_dbg(buf);
        }
 }
 
@@ -128,7 +112,7 @@ static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
 static inline void acquire_bus(BUS_ACQUIRE_T acquire)
 {
 
-       mutex_lock(g_wlan.hif_lock);
+       mutex_lock(&g_linux_wlan->hif_cs);
        #ifndef WILC_OPTIMIZE_SLEEP_INT
        if (genuChipPSstate != CHIP_WAKEDUP)
        #endif
@@ -144,7 +128,7 @@ static inline void release_bus(BUS_RELEASE_T release)
        if (release == RELEASE_ALLOW_SLEEP)
                chip_allow_sleep();
        #endif
-       mutex_unlock(g_wlan.hif_lock);
+       mutex_unlock(&g_linux_wlan->hif_cs);
 }
 /********************************************
  *
@@ -155,8 +139,7 @@ static inline void release_bus(BUS_RELEASE_T release)
 static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
 {
 
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
-       /* unsigned long flags; */
+       wilc_wlan_dev_t *p = &g_wlan;
        if (tqe == p->txq_head) {
 
                p->txq_head = tqe->next;
@@ -179,16 +162,16 @@ static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
 static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
 {
        struct txq_entry_t *tqe;
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        unsigned long flags;
 
-       spin_lock_irqsave(p->txq_spinlock, flags);
+       spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
        if (p->txq_head) {
                tqe = p->txq_head;
                p->txq_head = tqe->next;
-               if (p->txq_head) {
+               if (p->txq_head)
                        p->txq_head->prev = NULL;
-               }
+
                p->txq_entries -= 1;
 
 
@@ -197,15 +180,15 @@ static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
        } else {
                tqe = NULL;
        }
-       spin_unlock_irqrestore(p->txq_spinlock, flags);
+       spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
        return tqe;
 }
 
 static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        unsigned long flags;
-       spin_lock_irqsave(p->txq_spinlock, flags);
+       spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
 
        if (p->txq_head == NULL) {
                tqe->next = NULL;
@@ -221,24 +204,25 @@ static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
        p->txq_entries += 1;
        PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
 
-       spin_unlock_irqrestore(p->txq_spinlock, flags);
+       spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
 
        /**
         *      wake up TX queue
         **/
        PRINT_D(TX_DBG, "Wake the txq_handling\n");
 
-       up(p->txq_wait);
+       up(&g_linux_wlan->txq_event);
 }
 
 static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        unsigned long flags;
-       if (p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT))
+       if (linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
+                                   CFG_PKTS_TIMEOUT))
                return -1;
 
-       spin_lock_irqsave(p->txq_spinlock, flags);
+       spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
 
        if (p->txq_head == NULL) {
                tqe->next = NULL;
@@ -254,14 +238,14 @@ static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
        p->txq_entries += 1;
        PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
 
-       spin_unlock_irqrestore(p->txq_spinlock, flags);
-       up(p->txq_add_to_head_lock);
+       spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
+       up(&g_linux_wlan->txq_add_to_head_cs);
 
 
        /**
         *      wake up TX queue
         **/
-       up(p->txq_wait);
+       up(&g_linux_wlan->txq_event);
        PRINT_D(TX_DBG, "Wake up the txq_handler\n");
 
        return 0;
@@ -292,9 +276,6 @@ typedef struct {
 struct Ack_session_info *Free_head;
 struct Ack_session_info *Alloc_head;
 
-#define TCP_FIN_MASK           (1 << 0)
-#define TCP_SYN_MASK           (1 << 1)
-#define TCP_Ack_MASK           (1 << 4)
 #define NOT_TCP_ACK                    (-1)
 
 #define MAX_TCP_SESSION                25
@@ -329,9 +310,8 @@ static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
 static inline int Update_TCP_track_session(u32 index, u32 Ack)
 {
 
-       if (Ack > Acks_keep_track_info[index].Bigger_Ack_num) {
+       if (Ack > Acks_keep_track_info[index].Bigger_Ack_num)
                Acks_keep_track_info[index].Bigger_Ack_num = Ack;
-       }
        return 0;
 
 }
@@ -352,26 +332,31 @@ static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_ent
 }
 static inline int remove_TCP_related(void)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        unsigned long flags;
 
-       spin_lock_irqsave(p->txq_spinlock, flags);
+       spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
 
-       spin_unlock_irqrestore(p->txq_spinlock, flags);
+       spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
        return 0;
 }
 
-static inline int tcp_process(struct txq_entry_t *tqe)
+static inline int tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
 {
        int ret;
        u8 *eth_hdr_ptr;
        u8 *buffer = tqe->buffer;
        unsigned short h_proto;
        int i;
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        unsigned long flags;
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
+
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
 
-       spin_lock_irqsave(p->txq_spinlock, flags);
+       spin_lock_irqsave(&wilc->txq_spinlock, flags);
 
        eth_hdr_ptr = &buffer[0];
        h_proto = ntohs(*((unsigned short *)&eth_hdr_ptr[12]));
@@ -405,9 +390,9 @@ static inline int tcp_process(struct txq_entry_t *tqe)
                                                break;
                                        }
                                }
-                               if (i == Opened_TCP_session) {
+                               if (i == Opened_TCP_session)
                                        add_TCP_track_session(0, 0, seq_no);
-                               }
+
                                add_TCP_Pending_Ack(Ack_no, i, tqe);
 
 
@@ -419,19 +404,23 @@ static inline int tcp_process(struct txq_entry_t *tqe)
        } else {
                ret = 0;
        }
-       spin_unlock_irqrestore(p->txq_spinlock, flags);
+       spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
        return ret;
 }
 
 
-static int wilc_wlan_txq_filter_dup_tcp_ack(void)
+static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
 {
-
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
        u32 i = 0;
        u32 Dropped = 0;
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
+
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
 
-       spin_lock_irqsave(p->txq_spinlock, p->txq_spinlock_flags);
+       spin_lock_irqsave(&wilc->txq_spinlock, p->txq_spinlock_flags);
        for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
                if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
                        struct txq_entry_t *tqe;
@@ -458,11 +447,11 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(void)
                PendingAcks_arrBase = 0;
 
 
-       spin_unlock_irqrestore(p->txq_spinlock, p->txq_spinlock_flags);
+       spin_unlock_irqrestore(&wilc->txq_spinlock, p->txq_spinlock_flags);
 
        while (Dropped > 0) {
                /*consume the semaphore count of the removed packet*/
-               p->os_func.os_wait(p->txq_wait, 1);
+               linux_wlan_lock_timeout(&wilc->txq_event, 1);
                Dropped--;
        }
 
@@ -484,13 +473,13 @@ bool is_TCP_ACK_Filter_Enabled(void)
 
 static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        struct txq_entry_t *tqe;
 
        PRINT_D(TX_DBG, "Adding config packet ...\n");
        if (p->quit) {
                PRINT_D(TX_DBG, "Return due to clear function\n");
-               up(p->cfg_wait);
+               up(&g_linux_wlan->cfg_event);
                return 0;
        }
 
@@ -518,9 +507,10 @@ static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
        return 1;
 }
 
-static int wilc_wlan_txq_add_net_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func)
+int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
+                             u32 buffer_size, wilc_tx_complete_func_t func)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        struct txq_entry_t *tqe;
 
        if (p->quit)
@@ -540,7 +530,7 @@ static int wilc_wlan_txq_add_net_pkt(void *priv, u8 *buffer, u32 buffer_size, wi
 #ifdef TCP_ACK_FILTER
        tqe->tcp_PendingAck_index = NOT_TCP_ACK;
        if (is_TCP_ACK_Filter_Enabled())
-               tcp_process(tqe);
+               tcp_process(dev, tqe);
 #endif
        wilc_wlan_txq_add_to_tail(tqe);
        /*return number of itemes in the queue*/
@@ -550,7 +540,7 @@ static int wilc_wlan_txq_add_net_pkt(void *priv, u8 *buffer, u32 buffer_size, wi
 int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func)
 {
 
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        struct txq_entry_t *tqe;
 
        if (p->quit)
@@ -575,41 +565,41 @@ int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_
 
 static struct txq_entry_t *wilc_wlan_txq_get_first(void)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        struct txq_entry_t *tqe;
        unsigned long flags;
 
-       spin_lock_irqsave(p->txq_spinlock, flags);
+       spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
 
        tqe = p->txq_head;
 
-       spin_unlock_irqrestore(p->txq_spinlock, flags);
+       spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
 
 
        return tqe;
 }
 
-static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
+static struct txq_entry_t *wilc_wlan_txq_get_next(struct wilc *wilc,
+                                                 struct txq_entry_t *tqe)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
        unsigned long flags;
-       spin_lock_irqsave(p->txq_spinlock, flags);
+       spin_lock_irqsave(&wilc->txq_spinlock, flags);
 
        tqe = tqe->next;
-       spin_unlock_irqrestore(p->txq_spinlock, flags);
+       spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
 
 
        return tqe;
 }
 
-static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
+static int wilc_wlan_rxq_add(struct wilc *wilc, struct rxq_entry_t *rqe)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
 
        if (p->quit)
                return 0;
 
-       mutex_lock(p->rxq_lock);
+       mutex_lock(&wilc->rxq_cs);
        if (p->rxq_head == NULL) {
                PRINT_D(RX_DBG, "Add to Queue head\n");
                rqe->next = NULL;
@@ -623,24 +613,24 @@ static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
        }
        p->rxq_entries += 1;
        PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
-       mutex_unlock(p->rxq_lock);
+       mutex_unlock(&wilc->rxq_cs);
        return p->rxq_entries;
 }
 
-static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
+static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
 
        PRINT_D(RX_DBG, "Getting rxQ element\n");
        if (p->rxq_head) {
                struct rxq_entry_t *rqe;
 
-               mutex_lock(p->rxq_lock);
+               mutex_lock(&wilc->rxq_cs);
                rqe = p->rxq_head;
                p->rxq_head = p->rxq_head->next;
                p->rxq_entries -= 1;
                PRINT_D(RX_DBG, "RXQ entries decreased\n");
-               mutex_unlock(p->rxq_lock);
+               mutex_unlock(&wilc->rxq_cs);
                return rqe;
        }
        PRINT_D(RX_DBG, "Nothing to get from Q\n");
@@ -665,7 +655,7 @@ static inline void chip_allow_sleep(void)
        /* Clear bit 1 */
        g_wlan.hif_func.hif_read_reg(0xf0, &reg);
 
-       g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
+       g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
 }
 
 static inline void chip_wakeup(void)
@@ -677,19 +667,19 @@ static inline void chip_wakeup(void)
                do {
                        g_wlan.hif_func.hif_read_reg(1, &reg);
                        /* Set bit 1 */
-                       g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
+                       g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
 
                        /* Clear bit 1*/
-                       g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
+                       g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
 
                        do {
                                /* Wait for the chip to stabilize*/
                                usleep_range(2 * 1000, 2 * 1000);
                                /* Make sure chip is awake. This is an extra step that can be removed */
                                /* later to avoid the bus access overhead */
-                               if ((wilc_get_chipid(true) == 0)) {
+                               if ((wilc_get_chipid(true) == 0))
                                        wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
-                               }
+
                        } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
 
                } while (wilc_get_chipid(true) == 0);
@@ -697,7 +687,7 @@ static inline void chip_wakeup(void)
                g_wlan.hif_func.hif_read_reg(0xf0, &reg);
                do {
                        /* Set bit 1 */
-                       g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
+                       g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
 
                        /* Check the clock status */
                        g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
@@ -713,14 +703,15 @@ static inline void chip_wakeup(void)
                                /* later to avoid the bus access overhead */
                                g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
 
-                               if ((clk_status_reg & 0x1) == 0) {
+                               if ((clk_status_reg & 0x1) == 0)
                                        wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
-                               }
+
                        }
                        /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
                        if ((clk_status_reg & 0x1) == 0) {
                                /* Reset bit 0 */
-                               g_wlan.hif_func.hif_write_reg(0xf0, reg & (~(1 << 0)));
+                               g_wlan.hif_func.hif_write_reg(0xf0, reg &
+                                                             (~BIT(0)));
                        }
                } while ((clk_status_reg & 0x1) == 0);
        }
@@ -728,7 +719,7 @@ static inline void chip_wakeup(void)
 
        if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
                g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
-               reg &= ~(1 << 0);
+               reg &= ~BIT(0);
                g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
 
                if (wilc_get_chipid(false) >= 0x1002b0) {
@@ -736,11 +727,11 @@ static inline void chip_wakeup(void)
                        u32 val32;
 
                        g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
-                       val32 |= (1 << 6);
+                       val32 |= BIT(6);
                        g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
 
                        g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
-                       val32 |= (1 << 6);
+                       val32 |= BIT(6);
                        g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
                }
        }
@@ -755,19 +746,19 @@ static inline void chip_wakeup(void)
                if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
                        g_wlan.hif_func.hif_read_reg(1, &reg);
                        /* Make sure bit 1 is 0 before we start. */
-                       g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
+                       g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
                        /* Set bit 1 */
-                       g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
+                       g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
                        /* Clear bit 1*/
-                       g_wlan.hif_func.hif_write_reg(1, reg  & ~(1 << 1));
+                       g_wlan.hif_func.hif_write_reg(1, reg  & ~BIT(1));
                } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO)   {
                        /* Make sure bit 0 is 0 before we start. */
                        g_wlan.hif_func.hif_read_reg(0xf0, &reg);
-                       g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
+                       g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
                        /* Set bit 1 */
-                       g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
+                       g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
                        /* Clear bit 1 */
-                       g_wlan.hif_func.hif_write_reg(0xf0, reg  & ~(1 << 0));
+                       g_wlan.hif_func.hif_write_reg(0xf0, reg  & ~BIT(0));
                }
 
                do {
@@ -776,16 +767,16 @@ static inline void chip_wakeup(void)
 
                        /* Make sure chip is awake. This is an extra step that can be removed */
                        /* later to avoid the bus access overhead */
-                       if ((wilc_get_chipid(true) == 0)) {
+                       if ((wilc_get_chipid(true) == 0))
                                wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
-                       }
+
                } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
 
        } while (wilc_get_chipid(true) == 0);
 
        if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
                g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
-               reg &= ~(1 << 0);
+               reg &= ~BIT(0);
                g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
 
                if (wilc_get_chipid(false) >= 0x1002b0) {
@@ -793,11 +784,11 @@ static inline void chip_wakeup(void)
                        u32 val32;
 
                        g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
-                       val32 |= (1 << 6);
+                       val32 |= BIT(6);
                        g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
 
                        g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
-                       val32 |= (1 << 6);
+                       val32 |= BIT(6);
                        g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
                }
        }
@@ -830,7 +821,7 @@ void chip_sleep_manually(u32 u32SleepTime)
  *      Tx, Rx queue handle functions
  *
  ********************************************/
-static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
+int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount)
 {
        wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
        int i, entries = 0;
@@ -844,15 +835,21 @@ static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
        int counter;
        int timeout;
        u32 vmm_table[WILC_VMM_TBL_SIZE];
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
+
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
 
        p->txq_exit = 0;
        do {
                if (p->quit)
                        break;
 
-               p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT);
+               linux_wlan_lock_timeout(&wilc->txq_add_to_head_cs,
+                                       CFG_PKTS_TIMEOUT);
 #ifdef TCP_ACK_FILTER
-               wilc_wlan_txq_filter_dup_tcp_ack();
+               wilc_wlan_txq_filter_dup_tcp_ack(dev);
 #endif
                /**
                 *      build the vmm list
@@ -862,33 +859,31 @@ static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
                i = 0;
                sum = 0;
                do {
-                       /* if ((tqe != NULL) && (i < (8)) && */
-                       /* if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE-1)) && */
                        if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
 
-                               if (tqe->type == WILC_CFG_PKT) {
+                               if (tqe->type == WILC_CFG_PKT)
                                        vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
-                               }
-                               else if (tqe->type == WILC_NET_PKT) {
+
+                               else if (tqe->type == WILC_NET_PKT)
                                        vmm_sz = ETH_ETHERNET_HDR_OFFSET;
-                               }
-                               else {
+
+                               else
                                        vmm_sz = HOST_HDR_OFFSET;
-                               }
+
                                vmm_sz += tqe->buffer_size;
                                PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
                                if (vmm_sz & 0x3) {                                                                                                     /* has to be word aligned */
                                        vmm_sz = (vmm_sz + 4) & ~0x3;
                                }
-                               if ((sum + vmm_sz) > p->tx_buffer_size) {
+                               if ((sum + vmm_sz) > LINUX_TX_SIZE)
                                        break;
-                               }
+
                                PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
                                vmm_table[i] = vmm_sz / 4;                                                                                /* table take the word size */
                                PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
 
                                if (tqe->type == WILC_CFG_PKT) {
-                                       vmm_table[i] |= (1 << 10);
+                                       vmm_table[i] |= BIT(10);
                                        PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
                                }
 #ifdef BIG_ENDIAN
@@ -898,7 +893,7 @@ static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
                                i++;
                                sum += vmm_sz;
                                PRINT_D(TX_DBG, "sum = %d\n", sum);
-                               tqe = wilc_wlan_txq_get_next(tqe);
+                               tqe = wilc_wlan_txq_get_next(wilc, tqe);
                        } else {
                                break;
                        }
@@ -945,9 +940,8 @@ static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
                        }
                } while (!p->quit);
 
-               if (!ret) {
+               if (!ret)
                        goto _end_;
-               }
 
                timeout = 200;
                do {
@@ -986,7 +980,6 @@ static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
                                         *      Get the entries
                                         **/
                                        entries = ((reg >> 3) & 0x3f);
-                                       /* entries = ((reg>>3)&0x2f); */
                                        break;
                                } else {
                                        release_bus(RELEASE_ALLOW_SLEEP);
@@ -1000,9 +993,8 @@ static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
                                break;
                        }
 
-                       if (!ret) {
+                       if (!ret)
                                break;
-                       }
 
                        if (entries == 0) {
                                PRINT_WRN(GENERIC_DBG, "[wilc txq]: no more buffer in the chip (reg: %08x), retry later [[ %d, %x ]]\n", reg, i, vmm_table[i - 1]);
@@ -1013,7 +1005,7 @@ static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
                                        wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
                                        break;
                                }
-                               reg &= ~(1ul << 0);
+                               reg &= ~BIT(0);
                                ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
                                if (!ret) {
                                        wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
@@ -1025,9 +1017,9 @@ static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
                        }
                } while (1);
 
-               if (!ret) {
+               if (!ret)
                        goto _end_;
-               }
+
                if (entries == 0) {
                        ret = WILC_TX_ERR_NO_BUF;
                        goto _end_;
@@ -1054,9 +1046,9 @@ static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
                                vmm_sz *= 4;
                                header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
                                if (tqe->type == WILC_MGMT_PKT)
-                                       header |= (1 << 30);
+                                       header |= BIT(30);
                                else
-                                       header &= ~(1 << 30);
+                                       header &= ~BIT(30);
 
 #ifdef BIG_ENDIAN
                                header = BYTE_SWAP(header);
@@ -1083,9 +1075,8 @@ static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
                                if (tqe->tx_complete_func)
                                        tqe->tx_complete_func(tqe->priv, tqe->status);
                                #ifdef TCP_ACK_FILTER
-                               if (tqe->tcp_PendingAck_index != NOT_TCP_ACK) {
+                               if (tqe->tcp_PendingAck_index != NOT_TCP_ACK)
                                        Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
-                               }
                                #endif
                                kfree(tqe);
                        } else {
@@ -1119,7 +1110,7 @@ _end_:
                if (ret != 1)
                        break;
        } while (0);
-       up(p->txq_add_to_head_lock);
+       up(&wilc->txq_add_to_head_cs);
 
        p->txq_exit = 1;
        PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
@@ -1128,9 +1119,9 @@ _end_:
        return ret;
 }
 
-static void wilc_wlan_handle_rxq(void)
+static void wilc_wlan_handle_rxq(struct wilc *wilc)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        int offset = 0, size, has_packet = 0;
        u8 *buffer;
        struct rxq_entry_t *rqe;
@@ -1143,10 +1134,10 @@ static void wilc_wlan_handle_rxq(void)
        do {
                if (p->quit) {
                        PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
-                       up(p->cfg_wait);
+                       up(&wilc->cfg_event);
                        break;
                }
-               rqe = wilc_wlan_rxq_remove();
+               rqe = wilc_wlan_rxq_remove(wilc);
                if (rqe == NULL) {
                        PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
                        break;
@@ -1182,7 +1173,6 @@ static void wilc_wlan_handle_rxq(void)
                                break;
                        }
 
-/*bug 3887: [AP] Allow Management frames to be passed to the host*/
                        #define IS_MANAGMEMENT                          0x100
                        #define IS_MANAGMEMENT_CALLBACK                 0x080
                        #define IS_MGMT_STATUS_SUCCES                   0x040
@@ -1192,45 +1182,40 @@ static void wilc_wlan_handle_rxq(void)
                                /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
                                pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
 
-                               WILC_WFI_mgmt_rx(&buffer[offset + HOST_HDR_OFFSET], pkt_len);
+                               WILC_WFI_mgmt_rx(wilc, &buffer[offset + HOST_HDR_OFFSET], pkt_len);
                        }
-                       /* BUG4530 fix */
                        else
                        {
 
                                if (!is_cfg_packet) {
-
-                                       if (p->net_func.rx_indicate) {
-                                               if (pkt_len > 0) {
-                                                       p->net_func.rx_indicate(&buffer[offset], pkt_len, pkt_offset);
-                                                       has_packet = 1;
-                                               }
+                                       if (pkt_len > 0) {
+                                               frmw_to_linux(wilc,
+                                                             &buffer[offset],
+                                                             pkt_len,
+                                                             pkt_offset);
+                                               has_packet = 1;
                                        }
                                } else {
                                        wilc_cfg_rsp_t rsp;
 
 
 
-                                       p->cif_func.rx_indicate(&buffer[pkt_offset + offset], pkt_len, &rsp);
+                                       wilc_wlan_cfg_indicate_rx(&buffer[pkt_offset + offset], pkt_len, &rsp);
                                        if (rsp.type == WILC_CFG_RSP) {
                                                /**
                                                 *      wake up the waiting task...
                                                 **/
                                                PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
-                                               if (p->cfg_seq_no == rsp.seq_no) {
-                                                       up(p->cfg_wait);
-                                               }
+                                               if (p->cfg_seq_no == rsp.seq_no)
+                                                       up(&wilc->cfg_event);
                                        } else if (rsp.type == WILC_CFG_RSP_STATUS) {
                                                /**
                                                 *      Call back to indicate status...
                                                 **/
-                                               if (p->indicate_func.mac_indicate) {
-                                                       p->indicate_func.mac_indicate(WILC_MAC_INDICATE_STATUS);
-                                               }
+                                               linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_STATUS);
 
                                        } else if (rsp.type == WILC_CFG_RSP_SCAN) {
-                                               if (p->indicate_func.mac_indicate)
-                                                       p->indicate_func.mac_indicate(WILC_MAC_INDICATE_SCAN);
+                                               linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_SCAN);
                                        }
                                }
                        }
@@ -1245,10 +1230,9 @@ static void wilc_wlan_handle_rxq(void)
 #endif
                kfree(rqe);
 
-               if (has_packet) {
-                       if (p->net_func.rx_complete)
-                               p->net_func.rx_complete();
-               }
+               if (has_packet)
+                       linux_wlan_rx_complete();
+
        } while (1);
 
        p->rxq_exit = 1;
@@ -1289,9 +1273,9 @@ static void wilc_sleeptimer_isr_ext(u32 int_stats1)
 #endif
 }
 
-static void wilc_wlan_handle_isr_ext(u32 int_status)
+static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
 #ifdef MEMORY_STATIC
        u32 offset = p->rx_buffer_offset;
 #endif
@@ -1321,7 +1305,7 @@ static void wilc_wlan_handle_isr_ext(u32 int_status)
 
        if (size > 0) {
 #ifdef MEMORY_STATIC
-               if (p->rx_buffer_size - offset < size)
+               if (LINUX_RX_SIZE - offset < size)
                        offset = 0;
 
                if (p->rx_buffer)
@@ -1371,7 +1355,7 @@ _end_:
                                rqe->buffer = buffer;
                                rqe->buffer_size = size;
                                PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
-                               wilc_wlan_rxq_add(rqe);
+                               wilc_wlan_rxq_add(wilc, rqe);
                        }
                } else {
 #ifndef MEMORY_STATIC
@@ -1379,29 +1363,28 @@ _end_:
 #endif
                }
        }
-       wilc_wlan_handle_rxq();
+       wilc_wlan_handle_rxq(wilc);
 }
 
-void wilc_handle_isr(void)
+void wilc_handle_isr(void *wilc)
 {
        u32 int_status;
 
        acquire_bus(ACQUIRE_AND_WAKEUP);
        g_wlan.hif_func.hif_read_int(&int_status);
 
-       if (int_status & PLL_INT_EXT) {
+       if (int_status & PLL_INT_EXT)
                wilc_pllupdate_isr_ext(int_status);
-       }
+
        if (int_status & DATA_INT_EXT) {
-               wilc_wlan_handle_isr_ext(int_status);
+               wilc_wlan_handle_isr_ext(wilc, int_status);
        #ifndef WILC_OPTIMIZE_SLEEP_INT
                /* Chip is up and talking*/
                genuChipPSstate = CHIP_WAKEDUP;
        #endif
        }
-       if (int_status & SLEEP_INT_EXT) {
+       if (int_status & SLEEP_INT_EXT)
                wilc_sleeptimer_isr_ext(int_status);
-       }
 
        if (!(int_status & (ALL_INT_EXT))) {
 #ifdef WILC_SDIO
@@ -1417,15 +1400,15 @@ void wilc_handle_isr(void)
  *      Firmware download
  *
  ********************************************/
-static int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
+int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        u32 offset;
        u32 addr, size, size2, blksz;
        u8 *dma_buffer;
        int ret = 0;
 
-       blksz = (1ul << 12);
+       blksz = BIT(12);
        /* Allocate a DMA coherent  buffer. */
 
        dma_buffer = kmalloc(blksz, GFP_KERNEL);
@@ -1490,9 +1473,9 @@ _fail_1:
  *      Common
  *
  ********************************************/
-static int wilc_wlan_start(void)
+int wilc_wlan_start(void)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        u32 reg = 0;
        int ret;
        u32 chipid;
@@ -1500,25 +1483,9 @@ static int wilc_wlan_start(void)
        /**
         *      Set the host interface
         **/
-#ifdef OLD_FPGA_BITFILE
-       acquire_bus(ACQUIRE_ONLY);
-       ret = p->hif_func.hif_read_reg(WILC_VMM_CORE_CTL, &reg);
-       if (!ret) {
-               wilc_debug(N_ERR, "[wilc start]: fail read reg vmm_core_ctl...\n");
-               release_bus(RELEASE_ALLOW_SLEEP);
-               return ret;
-       }
-       reg |= (p->io_func.io_type << 2);
-       ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CTL, reg);
-       if (!ret) {
-               wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_ctl...\n");
-               release_bus(RELEASE_ONLY);
-               return ret;
-       }
-#else
        if (p->io_func.io_type == HIF_SDIO) {
                reg = 0;
-               reg |= (1 << 3); /* bug 4456 and 4557 */
+               reg |= BIT(3); /* bug 4456 and 4557 */
        } else if (p->io_func.io_type == HIF_SPI) {
                reg = 1;
        }
@@ -1572,8 +1539,6 @@ static int wilc_wlan_start(void)
                ret = -5;
                return ret;
        }
-#endif
-
 
        /**
         *      Bus related
@@ -1595,13 +1560,13 @@ static int wilc_wlan_start(void)
 
 
        p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
-       if ((reg & (1ul << 10)) == (1ul << 10)) {
-               reg &= ~(1ul << 10);
+       if ((reg & BIT(10)) == BIT(10)) {
+               reg &= ~BIT(10);
                p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
                p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
        }
 
-       reg |= (1ul << 10);
+       reg |= BIT(10);
        ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
        p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
        release_bus(RELEASE_ONLY);
@@ -1612,15 +1577,15 @@ static int wilc_wlan_start(void)
 void wilc_wlan_global_reset(void)
 {
 
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
 
        acquire_bus(ACQUIRE_AND_WAKEUP);
        p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
        release_bus(RELEASE_ONLY);
 }
-static int wilc_wlan_stop(void)
+int wilc_wlan_stop(void)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        u32 reg = 0;
        int ret;
        u8 timeout = 10;
@@ -1636,7 +1601,7 @@ static int wilc_wlan_stop(void)
                return ret;
        }
 
-       reg &= ~(1 << 10);
+       reg &= ~BIT(10);
 
 
        ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
@@ -1657,9 +1622,9 @@ static int wilc_wlan_stop(void)
                }
                PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
                /*Workaround to ensure that the chip is actually reset*/
-               if ((reg & (1 << 10))) {
+               if ((reg & BIT(10))) {
                        PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
-                       reg &= ~(1 << 10);
+                       reg &= ~BIT(10);
                        ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
                        timeout--;
                } else {
@@ -1675,26 +1640,31 @@ static int wilc_wlan_stop(void)
                }
 
        } while (timeout);
-       reg = ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 8) | (1 << 9) | (1 << 26) | (1 << 29) | (1 << 30) | (1 << 31)); /**/
-       /**/
-       p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);                                 /**/
-       reg = ~(1 << 10);                                                                                               /**/
-       /**/
-       ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);                                 /**/
-/******************************************************************************/
+       reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
+              BIT(29) | BIT(30) | BIT(31));
+
+       p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
+       reg = (u32)~BIT(10);
+
+       ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
 
        release_bus(RELEASE_ALLOW_SLEEP);
 
        return ret;
 }
 
-static void wilc_wlan_cleanup(void)
+void wilc_wlan_cleanup(struct net_device *dev)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        struct txq_entry_t *tqe;
        struct rxq_entry_t *rqe;
        u32 reg = 0;
        int ret;
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
+
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
 
        p->quit = 1;
        do {
@@ -1707,7 +1677,7 @@ static void wilc_wlan_cleanup(void)
        } while (1);
 
        do {
-               rqe = wilc_wlan_rxq_remove();
+               rqe = wilc_wlan_rxq_remove(wilc);
                if (rqe == NULL)
                        break;
 #ifndef MEMORY_STATIC
@@ -1750,7 +1720,7 @@ static void wilc_wlan_cleanup(void)
 
 static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        wilc_cfg_frame_t *cfg = &p->cfg_frame;
        int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
        int seq_no = p->cfg_seq_no % 256;
@@ -1784,9 +1754,10 @@ static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
        return 0;
 }
 
-static int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size, int commit, u32 drvHandler)
+int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size,
+                     int commit, u32 drvHandler)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        u32 offset;
        int ret_size;
 
@@ -1798,7 +1769,8 @@ static int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size, in
                p->cfg_frame_offset = 0;
 
        offset = p->cfg_frame_offset;
-       ret_size = p->cif_func.cfg_wid_set(p->cfg_frame.frame, offset, (u16)wid, buffer, buffer_size);
+       ret_size = wilc_wlan_cfg_set_wid(p->cfg_frame.frame, offset, (u16)wid,
+                                        buffer, buffer_size);
        offset += ret_size;
        p->cfg_frame_offset = offset;
 
@@ -1810,7 +1782,8 @@ static int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size, in
                if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
                        ret_size = 0;
 
-               if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) {
+               if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
+                                           CFG_PKTS_TIMEOUT)) {
                        PRINT_D(TX_DBG, "Set Timed Out\n");
                        ret_size = 0;
                }
@@ -1822,9 +1795,9 @@ static int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size, in
 
        return ret_size;
 }
-static int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
+int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        u32 offset;
        int ret_size;
 
@@ -1836,7 +1809,7 @@ static int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
                p->cfg_frame_offset = 0;
 
        offset = p->cfg_frame_offset;
-       ret_size = p->cif_func.cfg_wid_get(p->cfg_frame.frame, offset, (u16)wid);
+       ret_size = wilc_wlan_cfg_get_wid(p->cfg_frame.frame, offset, (u16)wid);
        offset += ret_size;
        p->cfg_frame_offset = offset;
 
@@ -1847,7 +1820,8 @@ static int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
                        ret_size = 0;
 
 
-               if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) {
+               if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
+                                           CFG_PKTS_TIMEOUT)) {
                        PRINT_D(TX_DBG, "Get Timed Out\n");
                        ret_size = 0;
                }
@@ -1860,12 +1834,11 @@ static int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
        return ret_size;
 }
 
-static int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
+int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
        int ret;
 
-       ret = p->cif_func.cfg_wid_get_val((u16)wid, buffer, buffer_size);
+       ret = wilc_wlan_cfg_get_wid_value((u16)wid, buffer, buffer_size);
 
        return ret;
 }
@@ -1905,7 +1878,7 @@ u32 init_chip(void)
                        wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
                        return ret;
                }
-               reg |= (1 << 0);
+               reg |= BIT(0);
                ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
                if (!ret) {
                        wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
@@ -1964,25 +1937,7 @@ _fail_:
        return chipid;
 }
 
-#ifdef COMPLEMENT_BOOT
-u8 core_11b_ready(void)
-{
-       u32 reg_val;
-
-       acquire_bus(ACQUIRE_ONLY);
-       g_wlan.hif_func.hif_write_reg(0x16082c, 1);
-       g_wlan.hif_func.hif_write_reg(0x161600, 0x90);
-       g_wlan.hif_func.hif_read_reg(0x161600, &reg_val);
-       release_bus(RELEASE_ONLY);
-
-       if (reg_val == 0x90)
-               return 0;
-       else
-               return 1;
-}
-#endif
-
-int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
+int wilc_wlan_init(wilc_wlan_inp_t *inp)
 {
 
        int ret = 0;
@@ -1994,24 +1949,7 @@ int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
        /**
         *      store the input
         **/
-       memcpy((void *)&g_wlan.os_func, (void *)&inp->os_func, sizeof(wilc_wlan_os_func_t));
        memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
-       memcpy((void *)&g_wlan.net_func, (void *)&inp->net_func, sizeof(wilc_wlan_net_func_t));
-       memcpy((void *)&g_wlan.indicate_func, (void *)&inp->indicate_func, sizeof(wilc_wlan_net_func_t));
-       g_wlan.hif_lock = inp->os_context.hif_critical_section;
-       g_wlan.txq_lock = inp->os_context.txq_critical_section;
-
-       g_wlan.txq_add_to_head_lock = inp->os_context.txq_add_to_head_critical_section;
-
-       g_wlan.txq_spinlock = inp->os_context.txq_spin_lock;
-
-       g_wlan.rxq_lock = inp->os_context.rxq_critical_section;
-       g_wlan.txq_wait = inp->os_context.txq_wait_event;
-       g_wlan.cfg_wait = inp->os_context.cfg_wait_event;
-       g_wlan.tx_buffer_size = inp->os_context.tx_buffer_size;
-#if defined (MEMORY_STATIC)
-       g_wlan.rx_buffer_size = inp->os_context.rx_buffer_size;
-#endif
        /***
         *      host interface init
         **/
@@ -2043,19 +1981,17 @@ int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
        /***
         *      mac interface init
         **/
-       if (!mac_cfg.cfg_init(wilc_debug)) {
+       if (!wilc_wlan_cfg_init(wilc_debug)) {
                /* ENOBUFS      105 */
                ret = -105;
                goto _fail_;
        }
-       memcpy((void *)&g_wlan.cif_func, &mac_cfg, sizeof(wilc_cfg_func_t));
-
 
        /**
         *      alloc tx, rx buffer
         **/
        if (g_wlan.tx_buffer == NULL)
-               g_wlan.tx_buffer = kmalloc(g_wlan.tx_buffer_size, GFP_KERNEL);
+               g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
        PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
 
        if (g_wlan.tx_buffer == NULL) {
@@ -2068,7 +2004,7 @@ int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
 /* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
 #if defined (MEMORY_STATIC)
        if (g_wlan.rx_buffer == NULL)
-               g_wlan.rx_buffer = kmalloc(g_wlan.rx_buffer_size, GFP_KERNEL);
+               g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
        PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
        if (g_wlan.rx_buffer == NULL) {
                /* ENOBUFS      105 */
@@ -2078,22 +2014,6 @@ int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
        }
 #endif
 
-       /**
-        *      export functions
-        **/
-       oup->wlan_firmware_download = wilc_wlan_firmware_download;
-       oup->wlan_start = wilc_wlan_start;
-       oup->wlan_stop = wilc_wlan_stop;
-       oup->wlan_add_to_tx_que = wilc_wlan_txq_add_net_pkt;
-       oup->wlan_handle_tx_que = wilc_wlan_handle_txq;
-       oup->wlan_handle_rx_isr = wilc_handle_isr;
-       oup->wlan_cleanup = wilc_wlan_cleanup;
-       oup->wlan_cfg_set = wilc_wlan_cfg_set;
-       oup->wlan_cfg_get = wilc_wlan_cfg_get;
-       oup->wlan_cfg_get_value = wilc_wlan_cfg_get_val;
-
-       oup->wlan_add_mgmt_to_tx_que = wilc_wlan_txq_add_mgmt_pkt;
-
        if (!init_chip()) {
                /* EIO  5 */
                ret = -5;
@@ -2118,17 +2038,21 @@ _fail_:
 
 }
 
-u16 Set_machw_change_vir_if(bool bValue)
+u16 Set_machw_change_vir_if(struct net_device *dev, bool bValue)
 {
        u16 ret;
        u32 reg;
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
+
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
 
        /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
-       mutex_lock((&g_wlan)->hif_lock);
+       mutex_lock(&wilc->hif_cs);
        ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
-       if (!ret) {
+       if (!ret)
                PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
-       }
 
        if (bValue)
                reg |= BIT(31);
@@ -2137,10 +2061,10 @@ u16 Set_machw_change_vir_if(bool bValue)
 
        ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
 
-       if (!ret) {
+       if (!ret)
                PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
-       }
-       mutex_unlock((&g_wlan)->hif_lock);
+
+       mutex_unlock(&wilc->hif_cs);
 
        return ret;
 }