wl12xx: Check for FW quirks as soon as the FW boots
[profile/ivi/kernel-x86-ivi.git] / drivers / net / wireless / wl12xx / main.c
index bc00e52..2c03b47 100644 (file)
@@ -311,6 +311,7 @@ static struct conf_drv_settings default_conf = {
                .min_dwell_time_active = 8,
                .max_dwell_time_active = 30,
                .dwell_time_passive    = 100,
+               .dwell_time_dfs        = 150,
                .num_probe_reqs        = 2,
                .rssi_threshold        = -90,
                .snr_threshold         = 0,
@@ -361,6 +362,12 @@ static struct conf_drv_settings default_conf = {
                .fm_disturbed_band_margin     = 0xff,       /* default */
                .swallow_clk_diff             = 0xff,       /* default */
        },
+       .rx_streaming = {
+               .duration                      = 150,
+               .queues                        = 0x1,
+               .interval                      = 20,
+               .always                        = 0,
+       },
        .hci_io_ds = HCI_IO_DS_6MA,
 };
 
@@ -387,6 +394,22 @@ static struct platform_device wl1271_device = {
 static DEFINE_MUTEX(wl_list_mutex);
 static LIST_HEAD(wl_list);
 
+static int wl1271_check_operstate(struct wl1271 *wl, unsigned char operstate)
+{
+       int ret;
+       if (operstate != IF_OPER_UP)
+               return 0;
+
+       if (test_and_set_bit(WL1271_FLAG_STA_STATE_SENT, &wl->flags))
+               return 0;
+
+       ret = wl1271_cmd_set_sta_state(wl);
+       if (ret < 0)
+               return ret;
+
+       wl1271_info("Association completed.");
+       return 0;
+}
 static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
                             void *arg)
 {
@@ -436,11 +459,7 @@ static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
        if (ret < 0)
                goto out;
 
-       if ((dev->operstate == IF_OPER_UP) &&
-           !test_and_set_bit(WL1271_FLAG_STA_STATE_SENT, &wl->flags)) {
-               wl1271_cmd_set_sta_state(wl);
-               wl1271_info("Association completed.");
-       }
+       wl1271_check_operstate(wl, dev->operstate);
 
        wl1271_ps_elp_sleep(wl);
 
@@ -472,6 +491,117 @@ static int wl1271_reg_notify(struct wiphy *wiphy,
        return 0;
 }
 
+static int wl1271_set_rx_streaming(struct wl1271 *wl, bool enable)
+{
+       int ret = 0;
+
+       /* we should hold wl->mutex */
+       ret = wl1271_acx_ps_rx_streaming(wl, enable);
+       if (ret < 0)
+               goto out;
+
+       if (enable)
+               set_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags);
+       else
+               clear_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags);
+out:
+       return ret;
+}
+
+/*
+ * this function is being called when the rx_streaming interval
+ * has beed changed or rx_streaming should be disabled
+ */
+int wl1271_recalc_rx_streaming(struct wl1271 *wl)
+{
+       int ret = 0;
+       int period = wl->conf.rx_streaming.interval;
+
+       /* don't reconfigure if rx_streaming is disabled */
+       if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags))
+               goto out;
+
+       /* reconfigure/disable according to new streaming_period */
+       if (period &&
+           test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) &&
+           (wl->conf.rx_streaming.always ||
+            test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
+               ret = wl1271_set_rx_streaming(wl, true);
+       else {
+               ret = wl1271_set_rx_streaming(wl, false);
+               /* don't cancel_work_sync since we might deadlock */
+               del_timer_sync(&wl->rx_streaming_timer);
+       }
+out:
+       return ret;
+}
+
+static void wl1271_rx_streaming_enable_work(struct work_struct *work)
+{
+       int ret;
+       struct wl1271 *wl =
+               container_of(work, struct wl1271, rx_streaming_enable_work);
+
+       mutex_lock(&wl->mutex);
+
+       if (test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags) ||
+           !test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) ||
+           (!wl->conf.rx_streaming.always &&
+            !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
+               goto out;
+
+       if (!wl->conf.rx_streaming.interval)
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_set_rx_streaming(wl, true);
+       if (ret < 0)
+               goto out_sleep;
+
+       /* stop it after some time of inactivity */
+       mod_timer(&wl->rx_streaming_timer,
+                 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration));
+
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+static void wl1271_rx_streaming_disable_work(struct work_struct *work)
+{
+       int ret;
+       struct wl1271 *wl =
+               container_of(work, struct wl1271, rx_streaming_disable_work);
+
+       mutex_lock(&wl->mutex);
+
+       if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags))
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_set_rx_streaming(wl, false);
+       if (ret)
+               goto out_sleep;
+
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+static void wl1271_rx_streaming_timer(unsigned long data)
+{
+       struct wl1271 *wl = (struct wl1271 *)data;
+       ieee80211_queue_work(wl->hw, &wl->rx_streaming_disable_work);
+}
+
 static void wl1271_conf_init(struct wl1271 *wl)
 {
 
@@ -740,7 +870,7 @@ static void wl1271_flush_deferred_work(struct wl1271 *wl)
 
        /* Return sent skbs to the network stack */
        while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
-               ieee80211_tx_status(wl->hw, skb);
+               ieee80211_tx_status_ni(wl->hw, skb);
 }
 
 static void wl1271_netstack_work(struct work_struct *work)
@@ -1073,9 +1203,13 @@ static int wl1271_chip_wakeup(struct wl1271 *wl)
                wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
                             wl->chip.id);
 
-               /* end-of-transaction flag should be set in wl127x AP mode */
+               /*
+                * 'end-of-transaction flag' and 'LPD mode flag'
+                * should be set in wl127x AP mode only
+                */
                if (wl->bss_type == BSS_TYPE_AP_BSS)
-                       wl->quirks |= WL12XX_QUIRK_END_OF_TRANSACTION;
+                       wl->quirks |= (WL12XX_QUIRK_END_OF_TRANSACTION |
+                                      WL12XX_QUIRK_LPD_MODE);
 
                ret = wl1271_setup(wl);
                if (ret < 0)
@@ -1088,6 +1222,7 @@ static int wl1271_chip_wakeup(struct wl1271 *wl)
                ret = wl1271_setup(wl);
                if (ret < 0)
                        goto out;
+
                if (wl1271_set_block_size(wl))
                        wl->quirks |= WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT;
                break;
@@ -1116,24 +1251,6 @@ out:
        return ret;
 }
 
-static unsigned int wl1271_get_fw_ver_quirks(struct wl1271 *wl)
-{
-       unsigned int quirks = 0;
-       unsigned int *fw_ver = wl->chip.fw_ver;
-
-       /* Only for wl127x */
-       if ((fw_ver[FW_VER_CHIP] == FW_VER_CHIP_WL127X) &&
-           /* Check STA version */
-           (((fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_STA) &&
-             (fw_ver[FW_VER_MINOR] < FW_VER_MINOR_1_SPARE_STA_MIN)) ||
-            /* Check AP version */
-            ((fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_AP) &&
-             (fw_ver[FW_VER_MINOR] < FW_VER_MINOR_1_SPARE_AP_MIN))))
-               quirks |= WL12XX_QUIRK_USE_2_SPARE_BLOCKS;
-
-       return quirks;
-}
-
 int wl1271_plt_start(struct wl1271 *wl)
 {
        int retries = WL1271_BOOT_RETRIES;
@@ -1170,8 +1287,6 @@ int wl1271_plt_start(struct wl1271 *wl)
                wl1271_notice("firmware booted in PLT mode (%s)",
                              wl->chip.fw_ver_str);
 
-               /* Check if any quirks are needed with older fw versions */
-               wl->quirks |= wl1271_get_fw_ver_quirks(wl);
                goto out;
 
 irq_disable:
@@ -1351,13 +1466,10 @@ static struct notifier_block wl1271_dev_notifier = {
 };
 
 #ifdef CONFIG_PM
-static int wl1271_configure_suspend(struct wl1271 *wl)
+static int wl1271_configure_suspend_sta(struct wl1271 *wl)
 {
        int ret;
 
-       if (wl->bss_type != BSS_TYPE_STA_BSS)
-               return 0;
-
        mutex_lock(&wl->mutex);
 
        ret = wl1271_ps_elp_wakeup(wl);
@@ -1402,11 +1514,41 @@ out:
 
 }
 
+static int wl1271_configure_suspend_ap(struct wl1271 *wl)
+{
+       int ret;
+
+       mutex_lock(&wl->mutex);
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out_unlock;
+
+       ret = wl1271_acx_set_ap_beacon_filter(wl, true);
+
+       wl1271_ps_elp_sleep(wl);
+out_unlock:
+       mutex_unlock(&wl->mutex);
+       return ret;
+
+}
+
+static int wl1271_configure_suspend(struct wl1271 *wl)
+{
+       if (wl->bss_type == BSS_TYPE_STA_BSS)
+               return wl1271_configure_suspend_sta(wl);
+       if (wl->bss_type == BSS_TYPE_AP_BSS)
+               return wl1271_configure_suspend_ap(wl);
+       return 0;
+}
+
 static void wl1271_configure_resume(struct wl1271 *wl)
 {
        int ret;
+       bool is_sta = wl->bss_type == BSS_TYPE_STA_BSS;
+       bool is_ap = wl->bss_type == BSS_TYPE_AP_BSS;
 
-       if (wl->bss_type != BSS_TYPE_STA_BSS)
+       if (!is_sta && !is_ap)
                return;
 
        mutex_lock(&wl->mutex);
@@ -1414,10 +1556,14 @@ static void wl1271_configure_resume(struct wl1271 *wl)
        if (ret < 0)
                goto out;
 
-       /* exit psm if it wasn't configured */
-       if (!test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags))
-               wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
-                                  wl->basic_rate, true);
+       if (is_sta) {
+               /* exit psm if it wasn't configured */
+               if (!test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags))
+                       wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
+                                          wl->basic_rate, true);
+       } else if (is_ap) {
+               wl1271_acx_set_ap_beacon_filter(wl, false);
+       }
 
        wl1271_ps_elp_sleep(wl);
 out:
@@ -1428,69 +1574,69 @@ static int wl1271_op_suspend(struct ieee80211_hw *hw,
                            struct cfg80211_wowlan *wow)
 {
        struct wl1271 *wl = hw->priv;
+       int ret;
+
        wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
-       wl->wow_enabled = !!wow;
-       if (wl->wow_enabled) {
-               int ret;
-               ret = wl1271_configure_suspend(wl);
-               if (ret < 0) {
-                       wl1271_warning("couldn't prepare device to suspend");
-                       return ret;
-               }
-               /* flush any remaining work */
-               wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
-               flush_delayed_work(&wl->scan_complete_work);
+       WARN_ON(!wow || !wow->any);
 
-               /*
-                * disable and re-enable interrupts in order to flush
-                * the threaded_irq
-                */
-               wl1271_disable_interrupts(wl);
+       wl->wow_enabled = true;
+       ret = wl1271_configure_suspend(wl);
+       if (ret < 0) {
+               wl1271_warning("couldn't prepare device to suspend");
+               return ret;
+       }
+       /* flush any remaining work */
+       wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
+       flush_delayed_work(&wl->scan_complete_work);
 
-               /*
-                * set suspended flag to avoid triggering a new threaded_irq
-                * work. no need for spinlock as interrupts are disabled.
-                */
-               set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
+       /*
+        * disable and re-enable interrupts in order to flush
+        * the threaded_irq
+        */
+       wl1271_disable_interrupts(wl);
+
+       /*
+        * set suspended flag to avoid triggering a new threaded_irq
+        * work. no need for spinlock as interrupts are disabled.
+        */
+       set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
+
+       wl1271_enable_interrupts(wl);
+       flush_work(&wl->tx_work);
+       flush_delayed_work(&wl->pspoll_work);
+       flush_delayed_work(&wl->elp_work);
 
-               wl1271_enable_interrupts(wl);
-               flush_work(&wl->tx_work);
-               flush_delayed_work(&wl->pspoll_work);
-               flush_delayed_work(&wl->elp_work);
-       }
        return 0;
 }
 
 static int wl1271_op_resume(struct ieee80211_hw *hw)
 {
        struct wl1271 *wl = hw->priv;
+       unsigned long flags;
+       bool run_irq_work = false;
+
        wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
                     wl->wow_enabled);
+       WARN_ON(!wl->wow_enabled);
 
        /*
         * re-enable irq_work enqueuing, and call irq_work directly if
         * there is a pending work.
         */
-       if (wl->wow_enabled) {
-               struct wl1271 *wl = hw->priv;
-               unsigned long flags;
-               bool run_irq_work = false;
-
-               spin_lock_irqsave(&wl->wl_lock, flags);
-               clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
-               if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
-                       run_irq_work = true;
-               spin_unlock_irqrestore(&wl->wl_lock, flags);
-
-               if (run_irq_work) {
-                       wl1271_debug(DEBUG_MAC80211,
-                                    "run postponed irq_work directly");
-                       wl1271_irq(0, wl);
-                       wl1271_enable_interrupts(wl);
-               }
+       spin_lock_irqsave(&wl->wl_lock, flags);
+       clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
+       if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
+               run_irq_work = true;
+       spin_unlock_irqrestore(&wl->wl_lock, flags);
 
-               wl1271_configure_resume(wl);
+       if (run_irq_work) {
+               wl1271_debug(DEBUG_MAC80211,
+                            "run postponed irq_work directly");
+               wl1271_irq(0, wl);
+               wl1271_enable_interrupts(wl);
        }
+       wl1271_configure_resume(wl);
+       wl->wow_enabled = false;
 
        return 0;
 }
@@ -1628,9 +1774,6 @@ power_off:
        strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
                sizeof(wiphy->fw_version));
 
-       /* Check if any quirks are needed with older fw versions */
-       wl->quirks |= wl1271_get_fw_ver_quirks(wl);
-
        /*
         * Now we know if 11a is supported (info from the NVS), so disable
         * 11a channels if not supported
@@ -1693,6 +1836,9 @@ static void __wl1271_op_remove_interface(struct wl1271 *wl,
        cancel_delayed_work_sync(&wl->scan_complete_work);
        cancel_work_sync(&wl->netstack_work);
        cancel_work_sync(&wl->tx_work);
+       del_timer_sync(&wl->rx_streaming_timer);
+       cancel_work_sync(&wl->rx_streaming_enable_work);
+       cancel_work_sync(&wl->rx_streaming_disable_work);
        cancel_delayed_work_sync(&wl->pspoll_work);
        cancel_delayed_work_sync(&wl->elp_work);
 
@@ -2779,24 +2925,6 @@ static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
                }
        }
 
-       if (changed & BSS_CHANGED_IBSS) {
-               wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
-                            bss_conf->ibss_joined);
-
-               if (bss_conf->ibss_joined) {
-                       u32 rates = bss_conf->basic_rates;
-                       wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl,
-                                                                        rates);
-                       wl->basic_rate = wl1271_tx_min_rate_get(wl);
-
-                       /* by default, use 11b rates */
-                       wl->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
-                       ret = wl1271_acx_sta_rate_policies(wl);
-                       if (ret < 0)
-                               goto out;
-               }
-       }
-
        ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed);
        if (ret < 0)
                goto out;
@@ -3022,6 +3150,24 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
                }
        }
 
+       if (changed & BSS_CHANGED_IBSS) {
+               wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
+                            bss_conf->ibss_joined);
+
+               if (bss_conf->ibss_joined) {
+                       u32 rates = bss_conf->basic_rates;
+                       wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl,
+                                                                        rates);
+                       wl->basic_rate = wl1271_tx_min_rate_get(wl);
+
+                       /* by default, use 11b rates */
+                       wl->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
+                       ret = wl1271_acx_sta_rate_policies(wl);
+                       if (ret < 0)
+                               goto out;
+               }
+       }
+
        ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed);
        if (ret < 0)
                goto out;
@@ -3060,6 +3206,7 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
                        wl1271_warning("cmd join failed %d", ret);
                        goto out;
                }
+               wl1271_check_operstate(wl, ieee80211_get_operstate(vif));
        }
 
 out:
@@ -3353,9 +3500,12 @@ static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
        if (ret < 0)
                goto out;
 
+       wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d",
+                    tid, action);
+
        switch (action) {
        case IEEE80211_AMPDU_RX_START:
-               if (wl->ba_support) {
+               if ((wl->ba_support) && (wl->ba_allowed)) {
                        ret = wl1271_acx_set_ba_receiver_session(wl, tid, *ssn,
                                                                 true);
                        if (!ret)
@@ -3960,6 +4110,17 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
        INIT_WORK(&wl->tx_work, wl1271_tx_work);
        INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
        INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
+       INIT_WORK(&wl->rx_streaming_enable_work,
+                 wl1271_rx_streaming_enable_work);
+       INIT_WORK(&wl->rx_streaming_disable_work,
+                 wl1271_rx_streaming_disable_work);
+
+       wl->freezable_wq = create_freezable_workqueue("wl12xx_wq");
+       if (!wl->freezable_wq) {
+               ret = -ENOMEM;
+               goto err_hw;
+       }
+
        wl->channel = WL1271_DEFAULT_CHANNEL;
        wl->beacon_int = WL1271_DEFAULT_BEACON_INT;
        wl->default_key = 0;
@@ -3985,6 +4146,8 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
        wl->quirks = 0;
        wl->platform_quirks = 0;
        wl->sched_scanning = false;
+       setup_timer(&wl->rx_streaming_timer, wl1271_rx_streaming_timer,
+                   (unsigned long) wl);
 
        memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
        for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
@@ -4002,7 +4165,7 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
        wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
        if (!wl->aggr_buf) {
                ret = -ENOMEM;
-               goto err_hw;
+               goto err_wq;
        }
 
        wl->dummy_packet = wl12xx_alloc_dummy_packet(wl);
@@ -4047,6 +4210,9 @@ err_dummy_packet:
 err_aggr:
        free_pages((unsigned long)wl->aggr_buf, order);
 
+err_wq:
+       destroy_workqueue(wl->freezable_wq);
+
 err_hw:
        wl1271_debugfs_exit(wl);
        kfree(plat_dev);
@@ -4077,6 +4243,7 @@ int wl1271_free_hw(struct wl1271 *wl)
 
        kfree(wl->fw_status);
        kfree(wl->tx_res_if);
+       destroy_workqueue(wl->freezable_wq);
 
        ieee80211_free_hw(wl->hw);