/** 
 *  @brief This function cleans module
 *  
 *  @return        n/a
 */
static void
wlan_cleanup_module(void)
{
    wlan_private *priv = wlanpriv;
    wlan_adapter *Adapter = NULL;

    ENTER();

    if (OS_ACQ_SEMAPHORE_BLOCK(&AddRemoveCardSem))
        goto exit_sem_err;

    if (!priv || !priv->adapter)
        goto exit;

    Adapter = priv->adapter;

    /* Exit deep sleep */
    wlan_exit_deep_sleep_timeout(priv);

    if (Adapter->MediaConnectStatus == WlanMediaStateConnected)
        wlan_disconnect(priv);

    wlan_prepare_cmd(priv, HostCmd_CMD_FUNC_SHUTDOWN,
                     0, HostCmd_OPTION_WAITFORRSP | HostCmd_OPTION_TIMEOUT,
                     0, NULL);

    /* Disable interrupts on the card */
    sbi_disable_host_int(priv);

  exit:
    OS_REL_SEMAPHORE(&AddRemoveCardSem);
  exit_sem_err:
    sbi_unregister();
    LEAVE();
}
예제 #2
0
/** 
 *  @brief This function downloads firmware image, gets
 *  HW spec from firmware and set basic parameters to
 *  firmware.
 *  
 *  @param priv    A pointer to wlan_private structure
 *  @return 	   WLAN_STATUS_SUCCESS or WLAN_STATUS_FAILURE
 */
int wlan_download_firmware(void)
{
	int ret = WLAN_STATUS_SUCCESS;
	
	sbi_disable_host_int();
    /* Download the helper */
    
    // ret= sbi_prog_firmware_image((u8*)helpgspibin, sizeof(helpgspibin));
	ret= sbi_prog_firmware_file("/helper.bin");
    if (ret) 
	{
        WlanDebug(WlanErr,"download helper failed!\n");
        ret = WLAN_STATUS_FAILURE;
        goto done;
    }

    /* Download firmware */
   	// if (sbi_download_wlan_fw_image((u8*)gspi8686bin, sizeof(gspi8686bin)))
    ret = sbi_download_wlan_fw_file("/fw.bin");
    if (ret)
	{
       WlanDebug(WlanErr,"download firmware failed\n");
       ret = WLAN_STATUS_FAILURE;
       goto done;
    }

   	/* check if the fimware is downloaded successfully or not */
   	if (sbi_verify_fw_download())
   	{
   		WlanDebug(WlanErr, "FW failed to be active in time!\n");
   		ret = WLAN_STATUS_FAILURE;
   		goto done;
   	}

    sbi_enable_host_int();
    ret = WLAN_STATUS_SUCCESS;

 done:
    return (ret);
}
예제 #3
0
파일: wlan_main.c 프로젝트: LucidOne/Rovio
/** 
 *  @brief This function removes the card.
 *  
 *  @param priv    A pointer to card
 *  @return 	   WLAN_STATUS_SUCCESS
 */
static int
wlan_remove_card(void *card)
{
    wlan_private *priv = &w99702_priv_data0;
    wlan_adapter *Adapter;
    //struct net_device *dev;
    struct cyg_netdevtab_entry *dev;
	struct eth_drv_sc *sc;
    union iwreq_data wrqu;

    ENTER();

    if (!priv) {
        LEAVE();
        return WLAN_STATUS_SUCCESS;
    }

    Adapter = priv->adapter;

    if (!Adapter) {
        LEAVE();
        return WLAN_STATUS_SUCCESS;
    }

    dev = priv->wlan_dev.netdev;
	sc = (struct eth_drv_sc *)dev->device_instance;
	
   // wake_up_interruptible(&Adapter->ds_awake_q);
   cyg_cond_broadcast(&Adapter->ds_cond_q);

    if (Adapter->CurCmd) {
        diag_printf("Wake up current cmdwait_q\n");
//        wake_up_interruptible(&Adapter->CurCmd->cmdwait_q);
		cyg_flag_setbits( &Adapter->CurCmd->cmdwait_flag_q, 3 );
    }

    Adapter->CurCmd = NULL;

    if (Adapter->PSMode == Wlan802_11PowerModeMAX_PSP) {
        Adapter->PSMode = Wlan802_11PowerModeCAM;
        PSWakeup(priv, HostCmd_OPTION_WAITFORRSP);
    }
    if (Adapter->IsDeepSleep == TRUE) {
        Adapter->IsDeepSleep = FALSE;
        sbi_exit_deep_sleep(priv);
    }

    memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN);
    wrqu.ap_addr.sa_family = ARPHRD_ETHER;
    wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL);

    /* Disable interrupts on the card as we cannot handle them after RESET */
    sbi_disable_host_int(priv);

    PrepareAndSendCommand(priv, HostCmd_CMD_802_11_RESET, 0, 0, 0, NULL);

    cyg_thread_delay(20);
    //udelay(200*1000);

#ifdef ENABLE_PM
    pm_unregister(wlan_pm_dev);
#endif

    /* Flush all the packets upto the OS before stopping */
   // wlan_send_rxskbQ(priv);
   eth_drv_dsr(0, 0, (cyg_addrword_t)sc);
    cleanup_txqueues(priv);
   // os_stop_queue(priv);
   // os_carrier_off(priv);

    Adapter->SurpriseRemoved = TRUE;

    /* Stop the thread servicing the interrupts */
    //wake_up_interruptible(&priv->MainThread.waitQ);
    cyg_flag_setbits( &priv->MainThread.waitQ_flag_q, 1 );

#ifdef REASSOCIATION
    //wake_up_interruptible(&priv->ReassocThread.waitQ);
    cyg_flag_setbits( &priv->ReassocThread.waitQ_flag_q, 1 );
#endif /* REASSOCIATION */

#ifdef PROC_DEBUG
    wlan_debug_remove(priv);
#endif
   // wlan_proc_remove(priv);

    diag_printf("unregester dev\n");
    sbi_unregister_dev(priv);

    diag_printf("Free Adapter\n");
    wlan_free_adapter(priv);

    /* Last reference is our one */
//    diag_printf("refcnt = %d\n", atomic_read(&dev->refcnt));

 //   diag_printf("netdev_finish_unregister: %s%s.\n", dev->name,
 //          (dev->features & NETIF_F_DYNALLOC) ? "" : ", old style");

 //   unregister_netdev(dev);

    diag_printf("Unregister finish\n");

    priv->wlan_dev.netdev = NULL;
    //free_netdev(dev);
    //wlanpriv = NULL;

    LEAVE();
    return WLAN_STATUS_SUCCESS;
}
예제 #4
0
/** 
 *  @brief This function initializes firmware
 *  
 *  @param priv    A pointer to wlan_private structure
 *  @return 	   WLAN_STATUS_SUCCESS or WLAN_STATUS_FAILURE
 */
int
wlan_init_fw(wlan_private * priv)
{
    int ret = WLAN_STATUS_SUCCESS;
    wlan_adapter *Adapter = priv->adapter;

    ENTER();

    sbi_disable_host_int(priv);

    /* Check if firmware is already running */
    if (sbi_check_fw_status(priv, 1) == WLAN_STATUS_SUCCESS) {
        PRINTM(MSG, "WLAN FW already running! Skip FW download\n");
    } else {
        if ((ret =
             request_firmware(&priv->fw_helper, helper_name,
                              priv->hotplug_device)) < 0) {
            PRINTM(FATAL,
                   "request_firmware() failed (helper), error code = %#x\n",
                   ret);
            goto done;
        }

        /* Download the helper */
        ret = sbi_prog_helper(priv);

        if (ret) {
            PRINTM(INFO,
                   "Bootloader in invalid state! Helper download failed!\n");
            ret = WLAN_STATUS_FAILURE;
            goto done;
        }

        if ((ret =
             request_firmware(&priv->firmware, fw_name,
                              priv->hotplug_device)) < 0) {
            PRINTM(FATAL, "request_firmware() failed, error code = %#x\n", ret);
            goto done;
        }

        /* Download the main firmware via the helper firmware */
        if (sbi_prog_fw_w_helper(priv)) {
            PRINTM(INFO, "Wlan FW download failed!\n");
            ret = WLAN_STATUS_FAILURE;
            goto done;
        }

        /* Check if the firmware is downloaded successfully or not */
        if (sbi_check_fw_status(priv, MAX_FIRMWARE_POLL_TRIES) ==
            WLAN_STATUS_FAILURE) {
            PRINTM(FATAL, "FW failed to be active in time!\n");
            ret = WLAN_STATUS_FAILURE;
            goto done;
        }
        PRINTM(MSG, "WLAN FW is active\n");
    }

#define RF_REG_OFFSET 0x07
#define RF_REG_VALUE  0xc8

    sbi_enable_host_int(priv);

#ifdef MFG_CMD_SUPPORT
    if (mfgmode == 0) {
#endif

        ret = wlan_prepare_cmd(priv, HostCmd_CMD_FUNC_INIT,
                               0,
                               HostCmd_OPTION_WAITFORRSP |
                               HostCmd_OPTION_TIMEOUT, 0, NULL);

        /* 
         * Read MAC address from HW
         */
        memset(Adapter->CurrentAddr, 0xff, ETH_ALEN);

        ret = wlan_prepare_cmd(priv, HostCmd_CMD_GET_HW_SPEC,
                               0,
                               HostCmd_OPTION_WAITFORRSP |
                               HostCmd_OPTION_TIMEOUT, 0, NULL);

        if (ret) {
            ret = WLAN_STATUS_FAILURE;
            goto done;
        }

        ret = wlan_prepare_cmd(priv,
                               HostCmd_CMD_MAC_CONTROL,
                               0,
                               HostCmd_OPTION_WAITFORRSP |
                               HostCmd_OPTION_TIMEOUT, 0,
                               &Adapter->CurrentPacketFilter);

        if (ret) {
            ret = WLAN_STATUS_FAILURE;
            goto done;
        }

        ret = wlan_prepare_cmd(priv,
                               HostCmd_CMD_802_11_RATE_ADAPT_RATESET,
                               HostCmd_ACT_GEN_GET,
                               HostCmd_OPTION_WAITFORRSP |
                               HostCmd_OPTION_TIMEOUT, 0, NULL);
        if (ret) {
            ret = WLAN_STATUS_FAILURE;
            goto done;
        }
        priv->adapter->DataRate = 0;

        ret = wlan_prepare_cmd(priv,
                               HostCmd_CMD_802_11_RF_TX_POWER,
                               HostCmd_ACT_GEN_GET,
                               HostCmd_OPTION_WAITFORRSP |
                               HostCmd_OPTION_TIMEOUT, 0, NULL);
        if (ret) {
            ret = WLAN_STATUS_FAILURE;
            goto done;
        }
#ifdef MFG_CMD_SUPPORT
    }
#endif

    Adapter->HardwareStatus = WlanHardwareStatusReady;
    ret = WLAN_STATUS_SUCCESS;
  done:
    if (priv->fw_helper)
        release_firmware(priv->fw_helper);
    if (priv->firmware)
        release_firmware(priv->firmware);

    if (ret != WLAN_STATUS_SUCCESS) {
        Adapter->HardwareStatus = WlanHardwareStatusNotReady;
        ret = WLAN_STATUS_FAILURE;
    }
    LEAVE();
    return ret;
}
예제 #5
0
/** 
 *  @brief This function downloads firmware image, gets
 *  HW spec from firmware and set basic parameters to
 *  firmware.
 *  
 *  @param priv    A pointer to wlan_private structure
 *  @return 	   WLAN_STATUS_SUCCESS or WLAN_STATUS_FAILURE
 */
int
wlan_setup_station_hw(wlan_private * priv)
{
    int ret = WLAN_STATUS_SUCCESS;
    wlan_adapter *adapter = priv->adapter;

    struct net_device *dev = priv->wlan_dev.netdev;

    ENTER();
    if (netif_running(dev))
        netif_device_detach(dev);

    sbi_disable_host_int(priv);

    /* Download the helper */
    ret = sbi_prog_helper(priv);

    if (ret) {
        PRINTM(INFO, "Bootloader in invalid state!\n");
        ret = WLAN_STATUS_FAILURE;
        goto done;
    }
    /* Download the main firmware via the helper firmware */
    if (sbi_prog_firmware_w_helper(priv)) {
        PRINTM(INFO, "Wlan FW download failed!\n");
        ret = WLAN_STATUS_FAILURE;
        goto done;
    }

    /* check if the fimware is downloaded successfully or not */
    if (sbi_verify_fw_download(priv)) {
        PRINTM(INFO, "FW failed to be active in time!\n");
        ret = WLAN_STATUS_FAILURE;
        goto done;
    }

    priv->adapter->fwstate = FW_STATE_READY;
    if (netif_running(dev))
        netif_device_attach(dev);
#define RF_REG_OFFSET 0x07
#define RF_REG_VALUE  0xc8

    sbi_enable_host_int(priv);

#ifdef MFG_CMD_SUPPORT
    if (mfgmode == 0) {
#endif

        /*
         * Read MAC address from HW
         */
        memset(adapter->CurrentAddr, 0xff, MRVDRV_ETH_ADDR_LEN);

        ret = PrepareAndSendCommand(priv, HostCmd_CMD_GET_HW_SPEC,
                                    0, HostCmd_OPTION_WAITFORRSP, 0, NULL);

        if (ret) {
            ret = WLAN_STATUS_FAILURE;
            goto done;
        }

        SetMacPacketFilter(priv);

        ret = PrepareAndSendCommand(priv,
                                    HostCmd_CMD_802_11_FW_WAKEUP_METHOD,
                                    HostCmd_ACT_GET,
                                    HostCmd_OPTION_WAITFORRSP, 0,
                                    &priv->adapter->fwWakeupMethod);

        if (ret) {
            ret = WLAN_STATUS_FAILURE;
            goto done;
        }
#ifdef MFG_CMD_SUPPORT
    }
#endif

#ifdef MFG_CMD_SUPPORT
    if (mfgmode == 0) {
#endif
        ret = PrepareAndSendCommand(priv,
                                    HostCmd_CMD_802_11_RATE_ADAPT_RATESET,
                                    HostCmd_ACT_GEN_GET,
                                    HostCmd_OPTION_WAITFORRSP, 0, NULL);
        if (ret) {
            ret = WLAN_STATUS_FAILURE;
            goto done;
        }
        priv->adapter->DataRate = 0;
        ret = PrepareAndSendCommand(priv,
                                    HostCmd_CMD_802_11_RF_TX_POWER,
                                    HostCmd_ACT_GEN_GET,
                                    HostCmd_OPTION_WAITFORRSP, 0, NULL);

        if (ret) {
            ret = WLAN_STATUS_FAILURE;
            goto done;
        }
#ifdef MFG_CMD_SUPPORT
    }
#endif

    ret = WLAN_STATUS_SUCCESS;
  done:

    LEAVE();

    return (ret);
}