staging: wilc1000: remove wrapper around spin_lock_init()
[firefly-linux-kernel-4.4.55.git] / drivers / staging / wilc1000 / linux_wlan.c
index b3cc9f5c7937c2834999dc172749c34ecc404ed1..dace77e046b2ad3b0598856defe6d6b4c5640487 100644 (file)
@@ -152,7 +152,6 @@ void linux_wlan_unlock(void *vp);
 extern void WILC_WFI_monitor_rx(uint8_t *buff, uint32_t size);
 extern void WILC_WFI_p2p_rx(struct net_device *dev, uint8_t *buff, uint32_t size);
 
-static void *internal_alloc(uint32_t size, uint32_t flag);
 static void linux_wlan_tx_complete(void *priv, int status);
 void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset);
 static int  mac_init_fn(struct net_device *ndev);
@@ -194,6 +193,7 @@ static char *ps8current = DebugBuffer;
 void printk_later(const char *format, ...)
 {
        va_list args;
+
        va_start(args, format);
        ps8current += vsprintf(ps8current, format, args);
        va_end(args);
@@ -402,11 +402,13 @@ static irqreturn_t isr_uh_routine(int irq, void *user_data)
 irqreturn_t isr_bh_routine(int irq, void *userdata)
 {
        linux_wlan_t *nic;
+
        nic = (linux_wlan_t *)userdata;
 #else
 static void isr_bh_routine(struct work_struct *work)
 {
        perInterface_wlan_t *nic;
+
        nic = (perInterface_wlan_t *)container_of(work, linux_wlan_t, rx_work_queue);
 #endif
 
@@ -531,53 +533,18 @@ static void linux_wlan_msleep(uint32_t msc)
 {
        if (msc <= 4000000) {
                u32 u32Temp = msc * 1000;
+
                usleep_range(u32Temp, u32Temp);
        } else {
                msleep(msc);
        }
 }
 
-static void linux_wlan_atomic_msleep(uint32_t msc)
-{
-       mdelay(msc);
-}
 static void linux_wlan_dbg(uint8_t *buff)
 {
        PRINT_D(INIT_DBG, "%d\n", *buff);
 }
 
-static void *linux_wlan_malloc_atomic(uint32_t sz)
-{
-       char *pntr = NULL;
-       pntr = kmalloc(sz, GFP_ATOMIC);
-       PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", sz, pntr);
-       return (void *)pntr;
-
-}
-static void *linux_wlan_malloc(uint32_t sz)
-{
-       char *pntr = NULL;
-       pntr = kmalloc(sz, GFP_KERNEL);
-       PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", sz, pntr);
-       return (void *)pntr;
-}
-
-void linux_wlan_free(void *vp)
-{
-       if (vp != NULL) {
-               PRINT_D(MEM_DBG, "Freeing %p\n", vp);
-               kfree(vp);
-       }
-}
-
-static void *internal_alloc(uint32_t size, uint32_t flag)
-{
-       char *pntr = NULL;
-       pntr = kmalloc(size, flag);
-       PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", size, pntr);
-       return (void *)pntr;
-}
-
 static void linux_wlan_init_lock(char *lockName, void *plock, int count)
 {
        sema_init((struct semaphore *)plock, count);
@@ -604,6 +571,7 @@ static void linux_wlan_lock(void *vp)
 static int linux_wlan_lock_timeout(void *vp, u32 timeout)
 {
        int error = -1;
+
        PRINT_D(LOCK_DBG, "Locking %p\n", vp);
        if (vp != NULL)
                error = down_timeout((struct semaphore *)vp, msecs_to_jiffies(timeout));
@@ -633,54 +601,10 @@ static void linux_wlan_deinit_mutex(void *plock)
        mutex_destroy((struct mutex *)plock);
 }
 
-static void linux_wlan_lock_mutex(void *vp)
-{
-       PRINT_D(LOCK_DBG, "Locking mutex %p\n", vp);
-       if (vp != NULL) {
-               /*
-                *      if(mutex_is_locked((struct mutex*)vp))
-                *      {
-                *              //PRINT_ER("Mutex already locked - %p \n",vp);
-                *      }
-                */
-               mutex_lock((struct mutex *)vp);
-
-       } else {
-               PRINT_ER("Failed, mutex is NULL\n");
-       }
-}
-
-static void linux_wlan_unlock_mutex(void *vp)
-{
-       PRINT_D(LOCK_DBG, "Unlocking mutex %p\n", vp);
-       if (vp != NULL) {
-
-               if (mutex_is_locked((struct mutex *)vp)) {
-                       mutex_unlock((struct mutex *)vp);
-               } else {
-                       /* PRINT_ER("Mutex already unlocked  - %p\n",vp); */
-               }
-
-       } else {
-               PRINT_ER("Failed, mutex is NULL\n");
-       }
-}
-
-/*Added by Amr - BugID_4720*/
-static void linux_wlan_init_spin_lock(char *lockName, void *plock, int count)
-{
-       spin_lock_init((spinlock_t *)plock);
-       PRINT_D(SPIN_DEBUG, "Initializing mutex [%s][%p]\n", lockName, plock);
-
-}
-
-static void linux_wlan_deinit_spin_lock(void *plock)
-{
-
-}
 static void linux_wlan_spin_lock(void *vp, unsigned long *flags)
 {
        unsigned long lflags;
+
        PRINT_D(SPIN_DEBUG, "Lock spin %p\n", vp);
        if (vp != NULL) {
                spin_lock_irqsave((spinlock_t *)vp, lflags);
@@ -692,6 +616,7 @@ static void linux_wlan_spin_lock(void *vp, unsigned long *flags)
 static void linux_wlan_spin_unlock(void *vp, unsigned long *flags)
 {
        unsigned long lflags = *flags;
+
        PRINT_D(SPIN_DEBUG, "Unlock spin %p\n", vp);
        if (vp != NULL) {
                spin_unlock_irqrestore((spinlock_t *)vp, lflags);
@@ -1052,7 +977,7 @@ static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_n
                goto _fail_;
        }
 
-       *(int *)c_val = (u32)pstrWFIDrv;
+       *(int *)c_val = 1;
 
        if (!g_linux_wlan->oup.wlan_cfg_set(1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0))
                goto _fail_;
@@ -1291,7 +1216,7 @@ static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_n
                goto _fail_;
 
        c_val[0] = 1; /* Enable N with immediate block ack. */
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, 1, (u32)pstrWFIDrv))
+       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, 1, 1))
                goto _fail_;
 
        return 0;
@@ -1327,9 +1252,9 @@ void wilc1000_wlan_deinit(linux_wlan_t *nic)
                  #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
 
                  #else
-               linux_wlan_lock_mutex((void *)&g_linux_wlan->hif_cs);
+               mutex_lock(&g_linux_wlan->hif_cs);
                disable_sdio_interrupt();
-               linux_wlan_unlock_mutex((void *)&g_linux_wlan->hif_cs);
+               mutex_unlock(&g_linux_wlan->hif_cs);
                  #endif
                #endif
 
@@ -1367,9 +1292,9 @@ void wilc1000_wlan_deinit(linux_wlan_t *nic)
   #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
                PRINT_D(INIT_DBG, "Disabling IRQ 2\n");
 
-               linux_wlan_lock_mutex((void *)&g_linux_wlan->hif_cs);
+               mutex_lock(&g_linux_wlan->hif_cs);
                disable_sdio_interrupt();
-               linux_wlan_unlock_mutex((void *)&g_linux_wlan->hif_cs);
+               mutex_unlock(&g_linux_wlan->hif_cs);
   #endif
 #endif
 
@@ -1398,7 +1323,7 @@ int wlan_init_locks(linux_wlan_t *p_nic)
        linux_wlan_init_mutex("txq_lock/txq_cs", &g_linux_wlan->txq_cs, 1);
 
        /*Added by Amr - BugID_4720*/
-       linux_wlan_init_spin_lock("txq_spin_lock/txq_cs", &g_linux_wlan->txq_spinlock, 1);
+       spin_lock_init(&g_linux_wlan->txq_spinlock);
 
        /*Added by Amr - BugID_4720*/
        linux_wlan_init_lock("txq_add_to_head_lock/txq_cs", &g_linux_wlan->txq_add_to_head_cs, 1);
@@ -1432,10 +1357,6 @@ static int wlan_deinit_locks(linux_wlan_t *nic)
        if (&g_linux_wlan->txq_cs != NULL)
                linux_wlan_deinit_mutex(&g_linux_wlan->txq_cs);
 
-       /*Added by Amr - BugID_4720*/
-       if (&g_linux_wlan->txq_spinlock != NULL)
-               linux_wlan_deinit_spin_lock(&g_linux_wlan->txq_spinlock);
-
        if (&g_linux_wlan->rxq_event != NULL)
                linux_wlan_deinit_lock(&g_linux_wlan->rxq_event);
 
@@ -1486,17 +1407,11 @@ void linux_to_wlan(wilc_wlan_inp_t *nwi, linux_wlan_t *nic)
        nwi->os_context.cfg_wait_event = (void *)&g_linux_wlan->cfg_event;
 
        nwi->os_func.os_sleep = linux_wlan_msleep;
-       nwi->os_func.os_atomic_sleep = linux_wlan_atomic_msleep;
        nwi->os_func.os_debug = linux_wlan_dbg;
-       nwi->os_func.os_malloc = linux_wlan_malloc;
-       nwi->os_func.os_malloc_atomic = linux_wlan_malloc_atomic;
-       nwi->os_func.os_free = linux_wlan_free;
        nwi->os_func.os_lock = linux_wlan_lock;
        nwi->os_func.os_unlock = linux_wlan_unlock;
        nwi->os_func.os_wait = linux_wlan_lock_timeout;
        nwi->os_func.os_signal = linux_wlan_unlock;
-       nwi->os_func.os_enter_cs = linux_wlan_lock_mutex;
-       nwi->os_func.os_leave_cs = linux_wlan_unlock_mutex;
 
        /*Added by Amr - BugID_4720*/
        nwi->os_func.os_spin_lock = linux_wlan_spin_lock;
@@ -1535,6 +1450,7 @@ int wlan_initialize_threads(perInterface_wlan_t *nic)
 {
 
        int ret = 0;
+
        PRINT_D(INIT_DBG, "Initializing Threads ...\n");
 
 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
@@ -1709,6 +1625,7 @@ extern void wilc_wlan_global_reset(void);
 uint8_t wilc1000_prepare_11b_core(wilc_wlan_inp_t *nwi,        wilc_wlan_oup_t *nwo, linux_wlan_t *nic)
 {
        uint8_t trials = 0;
+
        while ((core_11b_ready() && (READY_CHECK_THRESHOLD > (trials++)))) {
                PRINT_D(INIT_DBG, "11b core not ready yet: %u\n", trials);
                wilc_wlan_deinit(nic);
@@ -1743,6 +1660,7 @@ int repeat_power_cycle(perInterface_wlan_t *nic)
        int ret = 0;
        wilc_wlan_inp_t nwi;
        wilc_wlan_oup_t nwo;
+
        sdio_unregister_driver(&wilc_bus);
 
        linux_wlan_device_detection(0);
@@ -1880,6 +1798,7 @@ int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
                if (g_linux_wlan->oup.wlan_cfg_get(1, WID_FIRMWARE_VERSION, 1, 0)) {
                        int size;
                        char Firmware_ver[20];
+
                        size = g_linux_wlan->oup.wlan_cfg_get_value(
                                        WID_FIRMWARE_VERSION,
                                        Firmware_ver, sizeof(Firmware_ver));
@@ -1999,8 +1918,7 @@ int mac_open(struct net_device *ndev)
        Set_machw_change_vir_if(false);
 
        host_int_get_MacAddress(priv->hWILCWFIDrv, mac_add);
-       PRINT_D(INIT_DBG, "Mac address: %x:%x:%x:%x:%x:%x\n", mac_add[0], mac_add[1], mac_add[2],
-               mac_add[3], mac_add[4], mac_add[5]);
+       PRINT_D(INIT_DBG, "Mac address: %pM\n", mac_add);
 
        /* loop through the NUM of supported devices and set the MAC address */
        for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
@@ -2039,6 +1957,7 @@ int mac_open(struct net_device *ndev)
 {
 
        linux_wlan_t *nic;
+
        nic = netdev_priv(ndev);
 
        /*initialize platform*/
@@ -2069,6 +1988,7 @@ static void wilc_set_multicast_list(struct net_device *dev)
        struct WILC_WFI_priv *priv;
        tstrWILC_WFIDrv *pstrWFIDrv;
        int i = 0;
+
        priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
        pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
 
@@ -2120,13 +2040,14 @@ static void linux_wlan_tx_complete(void *priv, int status)
 {
 
        struct tx_complete_data *pv_data = (struct tx_complete_data *)priv;
+
        if (status == 1)
                PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
        else
                PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
        /* Free the SK Buffer, its work is done */
        dev_kfree_skb(pv_data->skb);
-       linux_wlan_free(pv_data);
+       kfree(pv_data);
 }
 
 int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
@@ -2137,6 +2058,7 @@ int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
        char *pu8UdpBuffer;
        struct iphdr *ih;
        struct ethhdr *eth_h;
+
        nic = netdev_priv(ndev);
 
        PRINT_D(INT_DBG, "\n========\n IntUH: %d - IntBH: %d - IntCld: %d\n========\n", int_rcvdU, int_rcvdB, int_clrd);
@@ -2148,7 +2070,7 @@ int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
                return 0;
        }
 
-       tx_data = (struct tx_complete_data *)internal_alloc(sizeof(struct tx_complete_data), GFP_ATOMIC);
+       tx_data = kmalloc(sizeof(struct tx_complete_data), GFP_ATOMIC);
        if (tx_data == NULL) {
                PRINT_ER("Failed to allocate memory for tx_data structure\n");
                dev_kfree_skb(skb);