wl12xx: Switch to a threaded interrupt handler
[deliverable/linux.git] / drivers / net / wireless / wl12xx / main.c
index 588e10ee282c9bbb4a0ae025ae143f3b2bee1922..f408c5a84cc912ff65784e0e6cbb6534499b05ca 100644 (file)
@@ -256,6 +256,7 @@ static struct conf_drv_settings default_conf = {
                .bet_enable                  = CONF_BET_MODE_ENABLE,
                .bet_max_consecutive         = 10,
                .psm_entry_retries           = 5,
+               .psm_exit_retries            = 255,
                .psm_entry_nullfunc_retries  = 3,
                .psm_entry_hangover_period   = 1,
                .keep_alive_interval         = 55000,
@@ -274,13 +275,13 @@ static struct conf_drv_settings default_conf = {
                .avg_weight_rssi_beacon       = 20,
                .avg_weight_rssi_data         = 10,
                .avg_weight_snr_beacon        = 20,
-               .avg_weight_snr_data          = 10
+               .avg_weight_snr_data          = 10,
        },
        .scan = {
                .min_dwell_time_active        = 7500,
                .max_dwell_time_active        = 30000,
-               .min_dwell_time_passive       = 30000,
-               .max_dwell_time_passive       = 60000,
+               .min_dwell_time_passive       = 100000,
+               .max_dwell_time_passive       = 100000,
                .num_probe_reqs               = 2,
        },
        .rf = {
@@ -293,6 +294,20 @@ static struct conf_drv_settings default_conf = {
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                },
        },
+       .ht = {
+               .tx_ba_win_size = 64,
+               .inactivity_timeout = 10000,
+       },
+       .mem = {
+               .num_stations                 = 1,
+               .ssid_profiles                = 1,
+               .rx_block_num                 = 70,
+               .tx_min_block_num             = 40,
+               .dynamic_memory               = 0,
+               .min_req_tx_blocks            = 104,
+               .min_req_rx_blocks            = 22,
+               .tx_min                       = 27,
+       }
 };
 
 static void __wl1271_op_remove_interface(struct wl1271 *wl);
@@ -359,7 +374,7 @@ static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
        if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
                goto out;
 
-       ret = wl1271_ps_elp_wakeup(wl, false);
+       ret = wl1271_ps_elp_wakeup(wl);
        if (ret < 0)
                goto out;
 
@@ -467,6 +482,10 @@ static int wl1271_plt_init(struct wl1271 *wl)
        if (ret < 0)
                goto out_free_memmap;
 
+       ret = wl1271_acx_sta_mem_cfg(wl);
+       if (ret < 0)
+               goto out_free_memmap;
+
        /* Default fragmentation threshold */
        ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold);
        if (ret < 0)
@@ -518,14 +537,71 @@ static int wl1271_plt_init(struct wl1271 *wl)
        return ret;
 }
 
+static void wl1271_irq_ps_regulate_link(struct wl1271 *wl, u8 hlid, u8 tx_blks)
+{
+       bool fw_ps;
+
+       /* only regulate station links */
+       if (hlid < WL1271_AP_STA_HLID_START)
+               return;
+
+       fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
+
+       /*
+        * Wake up from high level PS if the STA is asleep with too little
+        * blocks in FW or if the STA is awake.
+        */
+       if (!fw_ps || tx_blks < WL1271_PS_STA_MAX_BLOCKS)
+               wl1271_ps_link_end(wl, hlid);
+
+       /* Start high-level PS if the STA is asleep with enough blocks in FW */
+       else if (fw_ps && tx_blks >= WL1271_PS_STA_MAX_BLOCKS)
+               wl1271_ps_link_start(wl, hlid, true);
+}
+
+static void wl1271_irq_update_links_status(struct wl1271 *wl,
+                                      struct wl1271_fw_ap_status *status)
+{
+       u32 cur_fw_ps_map;
+       u8 hlid;
+
+       cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
+       if (wl->ap_fw_ps_map != cur_fw_ps_map) {
+               wl1271_debug(DEBUG_PSM,
+                            "link ps prev 0x%x cur 0x%x changed 0x%x",
+                            wl->ap_fw_ps_map, cur_fw_ps_map,
+                            wl->ap_fw_ps_map ^ cur_fw_ps_map);
+
+               wl->ap_fw_ps_map = cur_fw_ps_map;
+       }
+
+       for (hlid = WL1271_AP_STA_HLID_START; hlid < AP_MAX_LINKS; hlid++) {
+               u8 cnt = status->tx_lnk_free_blks[hlid] -
+                       wl->links[hlid].prev_freed_blks;
+
+               wl->links[hlid].prev_freed_blks =
+                       status->tx_lnk_free_blks[hlid];
+               wl->links[hlid].allocated_blks -= cnt;
+
+               wl1271_irq_ps_regulate_link(wl, hlid,
+                                           wl->links[hlid].allocated_blks);
+       }
+}
+
 static void wl1271_fw_status(struct wl1271 *wl,
-                            struct wl1271_fw_status *status)
+                            struct wl1271_fw_full_status *full_status)
 {
+       struct wl1271_fw_common_status *status = &full_status->common;
        struct timespec ts;
        u32 total = 0;
        int i;
 
-       wl1271_raw_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false);
+       if (wl->bss_type == BSS_TYPE_AP_BSS)
+               wl1271_raw_read(wl, FW_STATUS_ADDR, status,
+                               sizeof(struct wl1271_fw_ap_status), false);
+       else
+               wl1271_raw_read(wl, FW_STATUS_ADDR, status,
+                               sizeof(struct wl1271_fw_sta_status), false);
 
        wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
                     "drv_rx_counter = %d, tx_results_counter = %d)",
@@ -549,22 +625,49 @@ static void wl1271_fw_status(struct wl1271 *wl,
        if (total)
                clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
 
+       /* for AP update num of allocated TX blocks per link and ps status */
+       if (wl->bss_type == BSS_TYPE_AP_BSS)
+               wl1271_irq_update_links_status(wl, &full_status->ap);
+
        /* update the host-chipset time offset */
        getnstimeofday(&ts);
        wl->time_offset = (timespec_to_ns(&ts) >> 10) -
                (s64)le32_to_cpu(status->fw_localtime);
 }
 
-#define WL1271_IRQ_MAX_LOOPS 10
+static void wl1271_flush_deferred_work(struct wl1271 *wl)
+{
+       struct sk_buff *skb;
+
+       /* Pass all received frames to the network stack */
+       while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
+               ieee80211_rx_ni(wl->hw, skb);
+
+       /* Return sent skbs to the network stack */
+       while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
+               ieee80211_tx_status(wl->hw, skb);
+}
+
+static void wl1271_netstack_work(struct work_struct *work)
+{
+       struct wl1271 *wl =
+               container_of(work, struct wl1271, netstack_work);
+
+       do {
+               wl1271_flush_deferred_work(wl);
+       } while (skb_queue_len(&wl->deferred_rx_queue));
+}
+
+#define WL1271_IRQ_MAX_LOOPS 256
 
-static void wl1271_irq_work(struct work_struct *work)
+irqreturn_t wl1271_irq(int irq, void *cookie)
 {
        int ret;
        u32 intr;
        int loopcount = WL1271_IRQ_MAX_LOOPS;
-       unsigned long flags;
-       struct wl1271 *wl =
-               container_of(work, struct wl1271, irq_work);
+       struct wl1271 *wl = (struct wl1271 *)cookie;
+       bool done = false;
+       unsigned int defer_count;
 
        mutex_lock(&wl->mutex);
 
@@ -573,26 +676,27 @@ static void wl1271_irq_work(struct work_struct *work)
        if (unlikely(wl->state == WL1271_STATE_OFF))
                goto out;
 
-       ret = wl1271_ps_elp_wakeup(wl, true);
+       ret = wl1271_ps_elp_wakeup(wl);
        if (ret < 0)
                goto out;
 
-       spin_lock_irqsave(&wl->wl_lock, flags);
-       while (test_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags) && loopcount) {
-               clear_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags);
-               spin_unlock_irqrestore(&wl->wl_lock, flags);
-               loopcount--;
+       while (!done && loopcount--) {
+               /*
+                * In order to avoid a race with the hardirq, clear the flag
+                * before acknowledging the chip. Since the mutex is held,
+                * wl1271_ps_elp_wakeup cannot be called concurrently.
+                */
+               clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
+               smp_mb__after_clear_bit();
 
                wl1271_fw_status(wl, wl->fw_status);
-               intr = le32_to_cpu(wl->fw_status->intr);
+               intr = le32_to_cpu(wl->fw_status->common.intr);
+               intr &= WL1271_INTR_MASK;
                if (!intr) {
-                       wl1271_debug(DEBUG_IRQ, "Zero interrupt received.");
-                       spin_lock_irqsave(&wl->wl_lock, flags);
+                       done = true;
                        continue;
                }
 
-               intr &= WL1271_INTR_MASK;
-
                if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
                        wl1271_error("watchdog interrupt received! "
                                     "starting recovery.");
@@ -602,13 +706,10 @@ static void wl1271_irq_work(struct work_struct *work)
                        goto out;
                }
 
-               if (intr & WL1271_ACX_INTR_DATA) {
+               if (likely(intr & WL1271_ACX_INTR_DATA)) {
                        wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
 
-                       /* check for tx results */
-                       if (wl->fw_status->tx_results_counter !=
-                           (wl->tx_results_count & 0xff))
-                               wl1271_tx_complete(wl);
+                       wl1271_rx(wl, &wl->fw_status->common);
 
                        /* Check if any tx blocks were freed */
                        if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
@@ -620,7 +721,16 @@ static void wl1271_irq_work(struct work_struct *work)
                                wl1271_tx_work_locked(wl);
                        }
 
-                       wl1271_rx(wl, wl->fw_status);
+                       /* check for tx results */
+                       if (wl->fw_status->common.tx_results_counter !=
+                           (wl->tx_results_count & 0xff))
+                               wl1271_tx_complete(wl);
+
+                       /* Make sure the deferred queues don't get too long */
+                       defer_count = skb_queue_len(&wl->deferred_tx_queue) +
+                                     skb_queue_len(&wl->deferred_rx_queue);
+                       if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
+                               wl1271_flush_deferred_work(wl);
                }
 
                if (intr & WL1271_ACX_INTR_EVENT_A) {
@@ -639,21 +749,16 @@ static void wl1271_irq_work(struct work_struct *work)
 
                if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
                        wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
-
-               spin_lock_irqsave(&wl->wl_lock, flags);
        }
 
-       if (test_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags))
-               ieee80211_queue_work(wl->hw, &wl->irq_work);
-       else
-               clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
-       spin_unlock_irqrestore(&wl->wl_lock, flags);
-
        wl1271_ps_elp_sleep(wl);
 
 out:
        mutex_unlock(&wl->mutex);
+
+       return IRQ_HANDLED;
 }
+EXPORT_SYMBOL_GPL(wl1271_irq);
 
 static int wl1271_fetch_firmware(struct wl1271 *wl)
 {
@@ -890,11 +995,10 @@ int wl1271_plt_start(struct wl1271 *wl)
 
                wl->state = WL1271_STATE_PLT;
                wl1271_notice("firmware booted in PLT mode (%s)",
-                             wl->chip.fw_ver);
+                             wl->chip.fw_ver_str);
                goto out;
 
 irq_disable:
-               wl1271_disable_interrupts(wl);
                mutex_unlock(&wl->mutex);
                /* Unlocking the mutex in the middle of handling is
                   inherently unsafe. In this case we deem it safe to do,
@@ -903,7 +1007,9 @@ irq_disable:
                   work function will not do anything.) Also, any other
                   possible concurrent operations will fail due to the
                   current state, hence the wl1271 struct should be safe. */
-               cancel_work_sync(&wl->irq_work);
+               wl1271_disable_interrupts(wl);
+               wl1271_flush_deferred_work(wl);
+               cancel_work_sync(&wl->netstack_work);
                mutex_lock(&wl->mutex);
 power_off:
                wl1271_power_off(wl);
@@ -917,12 +1023,10 @@ out:
        return ret;
 }
 
-int wl1271_plt_stop(struct wl1271 *wl)
+int __wl1271_plt_stop(struct wl1271 *wl)
 {
        int ret = 0;
 
-       mutex_lock(&wl->mutex);
-
        wl1271_notice("power down");
 
        if (wl->state != WL1271_STATE_PLT) {
@@ -932,63 +1036,62 @@ int wl1271_plt_stop(struct wl1271 *wl)
                goto out;
        }
 
-       wl1271_disable_interrupts(wl);
        wl1271_power_off(wl);
 
        wl->state = WL1271_STATE_OFF;
        wl->rx_counter = 0;
 
-out:
        mutex_unlock(&wl->mutex);
-
-       cancel_work_sync(&wl->irq_work);
+       wl1271_disable_interrupts(wl);
+       wl1271_flush_deferred_work(wl);
+       cancel_work_sync(&wl->netstack_work);
        cancel_work_sync(&wl->recovery_work);
+       mutex_lock(&wl->mutex);
+out:
+       return ret;
+}
 
+int wl1271_plt_stop(struct wl1271 *wl)
+{
+       int ret;
+
+       mutex_lock(&wl->mutex);
+       ret = __wl1271_plt_stop(wl);
+       mutex_unlock(&wl->mutex);
        return ret;
 }
 
-static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
+static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
 {
        struct wl1271 *wl = hw->priv;
-       struct ieee80211_conf *conf = &hw->conf;
-       struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb);
-       struct ieee80211_sta *sta = txinfo->control.sta;
        unsigned long flags;
        int q;
+       u8 hlid = 0;
+
+       spin_lock_irqsave(&wl->wl_lock, flags);
+       wl->tx_queue_count++;
 
        /*
-        * peek into the rates configured in the STA entry.
-        * The rates set after connection stage, The first block only BG sets:
-        * the compare is for bit 0-16 of sta_rate_set. The second block add
-        * HT rates in case of HT supported.
+        * The workqueue is slow to process the tx_queue and we need stop
+        * the queue here, otherwise the queue will get too long.
         */
-       spin_lock_irqsave(&wl->wl_lock, flags);
-       if (sta &&
-           (sta->supp_rates[conf->channel->band] !=
-           (wl->sta_rate_set & HW_BG_RATES_MASK)) &&
-               wl->bss_type != BSS_TYPE_AP_BSS) {
-               wl->sta_rate_set = sta->supp_rates[conf->channel->band];
-               set_bit(WL1271_FLAG_STA_RATES_CHANGED, &wl->flags);
+       if (wl->tx_queue_count >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
+               wl1271_debug(DEBUG_TX, "op_tx: stopping queues");
+               ieee80211_stop_queues(wl->hw);
+               set_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
        }
 
-#ifdef CONFIG_WL12XX_HT
-       if (sta &&
-           sta->ht_cap.ht_supported &&
-           ((wl->sta_rate_set >> HW_HT_RATES_OFFSET) !=
-             sta->ht_cap.mcs.rx_mask[0])) {
-               /* Clean MCS bits before setting them */
-               wl->sta_rate_set &= HW_BG_RATES_MASK;
-               wl->sta_rate_set |=
-                       (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
-               set_bit(WL1271_FLAG_STA_RATES_CHANGED, &wl->flags);
-       }
-#endif
-       wl->tx_queue_count++;
        spin_unlock_irqrestore(&wl->wl_lock, flags);
 
        /* queue the packet */
        q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
-       skb_queue_tail(&wl->tx_queue[q], skb);
+       if (wl->bss_type == BSS_TYPE_AP_BSS) {
+               hlid = wl1271_tx_get_hlid(skb);
+               wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q);
+               skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
+       } else {
+               skb_queue_tail(&wl->tx_queue[q], skb);
+       }
 
        /*
         * The chip specific setup must run before the first TX packet -
@@ -997,21 +1100,6 @@ static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
 
        if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
                ieee80211_queue_work(wl->hw, &wl->tx_work);
-
-       /*
-        * The workqueue is slow to process the tx_queue and we need stop
-        * the queue here, otherwise the queue will get too long.
-        */
-       if (wl->tx_queue_count >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
-               wl1271_debug(DEBUG_TX, "op_tx: stopping queues");
-
-               spin_lock_irqsave(&wl->wl_lock, flags);
-               ieee80211_stop_queues(wl->hw);
-               set_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
-               spin_unlock_irqrestore(&wl->wl_lock, flags);
-       }
-
-       return NETDEV_TX_OK;
 }
 
 static struct notifier_block wl1271_dev_notifier = {
@@ -1108,7 +1196,6 @@ static int wl1271_op_add_interface(struct ieee80211_hw *hw,
                break;
 
 irq_disable:
-               wl1271_disable_interrupts(wl);
                mutex_unlock(&wl->mutex);
                /* Unlocking the mutex in the middle of handling is
                   inherently unsafe. In this case we deem it safe to do,
@@ -1117,7 +1204,9 @@ irq_disable:
                   work function will not do anything.) Also, any other
                   possible concurrent operations will fail due to the
                   current state, hence the wl1271 struct should be safe. */
-               cancel_work_sync(&wl->irq_work);
+               wl1271_disable_interrupts(wl);
+               wl1271_flush_deferred_work(wl);
+               cancel_work_sync(&wl->netstack_work);
                mutex_lock(&wl->mutex);
 power_off:
                wl1271_power_off(wl);
@@ -1131,11 +1220,11 @@ power_off:
 
        wl->vif = vif;
        wl->state = WL1271_STATE_ON;
-       wl1271_info("firmware booted (%s)", wl->chip.fw_ver);
+       wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
 
        /* update hw/fw version info in wiphy struct */
        wiphy->hw_version = wl->chip.id;
-       strncpy(wiphy->fw_version, wl->chip.fw_ver,
+       strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
                sizeof(wiphy->fw_version));
 
        /*
@@ -1183,12 +1272,12 @@ static void __wl1271_op_remove_interface(struct wl1271 *wl)
 
        wl->state = WL1271_STATE_OFF;
 
-       wl1271_disable_interrupts(wl);
-
        mutex_unlock(&wl->mutex);
 
+       wl1271_disable_interrupts(wl);
+       wl1271_flush_deferred_work(wl);
        cancel_delayed_work_sync(&wl->scan_complete_work);
-       cancel_work_sync(&wl->irq_work);
+       cancel_work_sync(&wl->netstack_work);
        cancel_work_sync(&wl->tx_work);
        cancel_delayed_work_sync(&wl->pspoll_work);
        cancel_delayed_work_sync(&wl->elp_work);
@@ -1217,12 +1306,13 @@ static void __wl1271_op_remove_interface(struct wl1271 *wl)
        wl->time_offset = 0;
        wl->session_counter = 0;
        wl->rate_set = CONF_TX_RATE_MASK_BASIC;
-       wl->sta_rate_set = 0;
        wl->flags = 0;
        wl->vif = NULL;
        wl->filters = 0;
        wl1271_free_ap_keys(wl);
        memset(wl->ap_hlid_map, 0, sizeof(wl->ap_hlid_map));
+       wl->ap_fw_ps_map = 0;
+       wl->ap_ps_map = 0;
 
        for (i = 0; i < NUM_TX_QUEUES; i++)
                wl->tx_blocks_freed[i] = 0;
@@ -1404,7 +1494,6 @@ static int wl1271_sta_handle_idle(struct wl1271 *wl, bool idle)
                                goto out;
                }
                wl->rate_set = wl1271_tx_min_rate_get(wl);
-               wl->sta_rate_set = 0;
                ret = wl1271_acx_sta_rate_policies(wl);
                if (ret < 0)
                        goto out;
@@ -1464,7 +1553,7 @@ static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
 
        is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
 
-       ret = wl1271_ps_elp_wakeup(wl, false);
+       ret = wl1271_ps_elp_wakeup(wl);
        if (ret < 0)
                goto out;
 
@@ -1620,7 +1709,7 @@ static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
        if (unlikely(wl->state == WL1271_STATE_OFF))
                goto out;
 
-       ret = wl1271_ps_elp_wakeup(wl, false);
+       ret = wl1271_ps_elp_wakeup(wl);
        if (ret < 0)
                goto out;
 
@@ -1849,7 +1938,7 @@ static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
                goto out_unlock;
        }
 
-       ret = wl1271_ps_elp_wakeup(wl, false);
+       ret = wl1271_ps_elp_wakeup(wl);
        if (ret < 0)
                goto out_unlock;
 
@@ -1952,7 +2041,7 @@ static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
                goto out;
        }
 
-       ret = wl1271_ps_elp_wakeup(wl, false);
+       ret = wl1271_ps_elp_wakeup(wl);
        if (ret < 0)
                goto out;
 
@@ -1978,7 +2067,7 @@ static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
                goto out;
        }
 
-       ret = wl1271_ps_elp_wakeup(wl, false);
+       ret = wl1271_ps_elp_wakeup(wl);
        if (ret < 0)
                goto out;
 
@@ -2006,7 +2095,7 @@ static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
                goto out;
        }
 
-       ret = wl1271_ps_elp_wakeup(wl, false);
+       ret = wl1271_ps_elp_wakeup(wl);
        if (ret < 0)
                goto out;
 
@@ -2218,8 +2307,11 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
 {
        bool do_join = false, set_assoc = false;
        bool is_ibss = (wl->bss_type == BSS_TYPE_IBSS);
+       u32 sta_rate_set = 0;
        int ret;
-       struct ieee80211_sta *sta = ieee80211_find_sta(vif, bss_conf->bssid);
+       struct ieee80211_sta *sta;
+       bool sta_exists = false;
+       struct ieee80211_sta_ht_cap sta_ht_cap;
 
        if (is_ibss) {
                ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf,
@@ -2283,6 +2375,50 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
                }
        }
 
+       rcu_read_lock();
+       sta = ieee80211_find_sta(vif, bss_conf->bssid);
+       if (sta)  {
+               /* save the supp_rates of the ap */
+               sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
+               if (sta->ht_cap.ht_supported)
+                       sta_rate_set |=
+                           (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
+               sta_ht_cap = sta->ht_cap;
+               sta_exists = true;
+       }
+       rcu_read_unlock();
+
+       if (sta_exists) {
+               /* handle new association with HT and HT information change */
+               if ((changed & BSS_CHANGED_HT) &&
+                   (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
+                       ret = wl1271_acx_set_ht_capabilities(wl, &sta_ht_cap,
+                                                            true);
+                       if (ret < 0) {
+                               wl1271_warning("Set ht cap true failed %d",
+                                              ret);
+                               goto out;
+                       }
+                       ret = wl1271_acx_set_ht_information(wl,
+                                               bss_conf->ht_operation_mode);
+                       if (ret < 0) {
+                               wl1271_warning("Set ht information failed %d",
+                                              ret);
+                               goto out;
+                       }
+               }
+               /* handle new association without HT and disassociation */
+               else if (changed & BSS_CHANGED_ASSOC) {
+                       ret = wl1271_acx_set_ht_capabilities(wl, &sta_ht_cap,
+                                                            false);
+                       if (ret < 0) {
+                               wl1271_warning("Set ht cap false failed %d",
+                                              ret);
+                               goto out;
+                       }
+               }
+       }
+
        if ((changed & BSS_CHANGED_ASSOC)) {
                if (bss_conf->assoc) {
                        u32 rates;
@@ -2300,6 +2436,9 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
                        wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl,
                                                                         rates);
                        wl->basic_rate = wl1271_tx_min_rate_get(wl);
+                       if (sta_rate_set)
+                               wl->rate_set = wl1271_tx_enabled_rates_get(wl,
+                                                               sta_rate_set);
                        ret = wl1271_acx_sta_rate_policies(wl);
                        if (ret < 0)
                                goto out;
@@ -2378,37 +2517,6 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
        if (ret < 0)
                goto out;
 
-       /*
-        * Takes care of: New association with HT enable,
-        *                HT information change in beacon.
-        */
-       if (sta &&
-           (changed & BSS_CHANGED_HT) &&
-           (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
-               ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true);
-               if (ret < 0) {
-                       wl1271_warning("Set ht cap true failed %d", ret);
-                       goto out;
-               }
-                       ret = wl1271_acx_set_ht_information(wl,
-                               bss_conf->ht_operation_mode);
-               if (ret < 0) {
-                       wl1271_warning("Set ht information failed %d", ret);
-                       goto out;
-               }
-       }
-       /*
-        * Takes care of: New association without HT,
-        *                Disassociation.
-        */
-       else if (sta && (changed & BSS_CHANGED_ASSOC)) {
-               ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, false);
-               if (ret < 0) {
-                       wl1271_warning("Set ht cap false failed %d", ret);
-                       goto out;
-               }
-       }
-
        if (changed & BSS_CHANGED_ARP_FILTER) {
                __be32 addr = bss_conf->arp_addr_list[0];
                WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS);
@@ -2428,8 +2536,7 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
                        }
 
                        ret = wl1271_acx_arp_ip_filter(wl,
-                               (ACX_ARP_FILTER_ARP_FILTERING |
-                                ACX_ARP_FILTER_AUTO_ARP),
+                               ACX_ARP_FILTER_ARP_FILTERING,
                                addr);
                } else
                        ret = wl1271_acx_arp_ip_filter(wl, 0, addr);
@@ -2467,7 +2574,7 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
        if (unlikely(wl->state == WL1271_STATE_OFF))
                goto out;
 
-       ret = wl1271_ps_elp_wakeup(wl, false);
+       ret = wl1271_ps_elp_wakeup(wl);
        if (ret < 0)
                goto out;
 
@@ -2522,7 +2629,7 @@ static int wl1271_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
                conf_tid->apsd_conf[0] = 0;
                conf_tid->apsd_conf[1] = 0;
        } else {
-               ret = wl1271_ps_elp_wakeup(wl, false);
+               ret = wl1271_ps_elp_wakeup(wl);
                if (ret < 0)
                        goto out;
 
@@ -2568,7 +2675,7 @@ static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw)
        if (unlikely(wl->state == WL1271_STATE_OFF))
                goto out;
 
-       ret = wl1271_ps_elp_wakeup(wl, false);
+       ret = wl1271_ps_elp_wakeup(wl);
        if (ret < 0)
                goto out;
 
@@ -2600,7 +2707,7 @@ static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
        return 0;
 }
 
-static int wl1271_allocate_hlid(struct wl1271 *wl,
+static int wl1271_allocate_sta(struct wl1271 *wl,
                             struct ieee80211_sta *sta,
                             u8 *hlid)
 {
@@ -2614,18 +2721,25 @@ static int wl1271_allocate_hlid(struct wl1271 *wl,
        }
 
        wl_sta = (struct wl1271_station *)sta->drv_priv;
-
        __set_bit(id, wl->ap_hlid_map);
        wl_sta->hlid = WL1271_AP_STA_HLID_START + id;
        *hlid = wl_sta->hlid;
+       memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
        return 0;
 }
 
-static void wl1271_free_hlid(struct wl1271 *wl, u8 hlid)
+static void wl1271_free_sta(struct wl1271 *wl, u8 hlid)
 {
        int id = hlid - WL1271_AP_STA_HLID_START;
 
+       if (WARN_ON(!test_bit(id, wl->ap_hlid_map)))
+               return;
+
        __clear_bit(id, wl->ap_hlid_map);
+       memset(wl->links[hlid].addr, 0, ETH_ALEN);
+       wl1271_tx_reset_link_queues(wl, hlid);
+       __clear_bit(hlid, &wl->ap_ps_map);
+       __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
 }
 
 static int wl1271_op_sta_add(struct ieee80211_hw *hw,
@@ -2646,13 +2760,13 @@ static int wl1271_op_sta_add(struct ieee80211_hw *hw,
 
        wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
 
-       ret = wl1271_allocate_hlid(wl, sta, &hlid);
+       ret = wl1271_allocate_sta(wl, sta, &hlid);
        if (ret < 0)
                goto out;
 
-       ret = wl1271_ps_elp_wakeup(wl, false);
+       ret = wl1271_ps_elp_wakeup(wl);
        if (ret < 0)
-               goto out;
+               goto out_free_sta;
 
        ret = wl1271_cmd_add_sta(wl, sta, hlid);
        if (ret < 0)
@@ -2661,6 +2775,10 @@ static int wl1271_op_sta_add(struct ieee80211_hw *hw,
 out_sleep:
        wl1271_ps_elp_sleep(wl);
 
+out_free_sta:
+       if (ret < 0)
+               wl1271_free_sta(wl, hlid);
+
 out:
        mutex_unlock(&wl->mutex);
        return ret;
@@ -2689,7 +2807,7 @@ static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
        if (WARN_ON(!test_bit(id, wl->ap_hlid_map)))
                goto out;
 
-       ret = wl1271_ps_elp_wakeup(wl, false);
+       ret = wl1271_ps_elp_wakeup(wl);
        if (ret < 0)
                goto out;
 
@@ -2697,7 +2815,7 @@ static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
        if (ret < 0)
                goto out_sleep;
 
-       wl1271_free_hlid(wl, wl_sta->hlid);
+       wl1271_free_sta(wl, wl_sta->hlid);
 
 out_sleep:
        wl1271_ps_elp_sleep(wl);
@@ -2707,6 +2825,66 @@ out:
        return ret;
 }
 
+int wl1271_op_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+                          enum ieee80211_ampdu_mlme_action action,
+                          struct ieee80211_sta *sta, u16 tid, u16 *ssn,
+                          u8 buf_size)
+{
+       struct wl1271 *wl = hw->priv;
+       int ret;
+
+       mutex_lock(&wl->mutex);
+
+       if (unlikely(wl->state == WL1271_STATE_OFF)) {
+               ret = -EAGAIN;
+               goto out;
+       }
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       switch (action) {
+       case IEEE80211_AMPDU_RX_START:
+               if (wl->ba_support) {
+                       ret = wl1271_acx_set_ba_receiver_session(wl, tid, *ssn,
+                                                                true);
+                       if (!ret)
+                               wl->ba_rx_bitmap |= BIT(tid);
+               } else {
+                       ret = -ENOTSUPP;
+               }
+               break;
+
+       case IEEE80211_AMPDU_RX_STOP:
+               ret = wl1271_acx_set_ba_receiver_session(wl, tid, 0, false);
+               if (!ret)
+                       wl->ba_rx_bitmap &= ~BIT(tid);
+               break;
+
+       /*
+        * The BA initiator session management in FW independently.
+        * Falling break here on purpose for all TX APDU commands.
+        */
+       case IEEE80211_AMPDU_TX_START:
+       case IEEE80211_AMPDU_TX_STOP:
+       case IEEE80211_AMPDU_TX_OPERATIONAL:
+               ret = -EINVAL;
+               break;
+
+       default:
+               wl1271_error("Incorrect ampdu action id=%x\n", action);
+               ret = -EINVAL;
+       }
+
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
 /* can't be const, mac80211 writes to this */
 static struct ieee80211_rate wl1271_rates[] = {
        { .bitrate = 10,
@@ -2765,6 +2943,7 @@ static struct ieee80211_channel wl1271_channels[] = {
        { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
        { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
        { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
+       { .hw_value = 14, .center_freq = 2484, .max_power = 25 },
 };
 
 /* mapping to indexes for wl1271_rates */
@@ -2955,6 +3134,7 @@ static const struct ieee80211_ops wl1271_ops = {
        .get_survey = wl1271_op_get_survey,
        .sta_add = wl1271_op_sta_add,
        .sta_remove = wl1271_op_sta_remove,
+       .ampdu_action = wl1271_op_ampdu_action,
        CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
 };
 
@@ -3024,7 +3204,7 @@ static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
        if (wl->state == WL1271_STATE_OFF)
                goto out;
 
-       ret = wl1271_ps_elp_wakeup(wl, false);
+       ret = wl1271_ps_elp_wakeup(wl);
        if (ret < 0)
                goto out;
 
@@ -3103,6 +3283,9 @@ EXPORT_SYMBOL_GPL(wl1271_register_hw);
 
 void wl1271_unregister_hw(struct wl1271 *wl)
 {
+       if (wl->state == WL1271_STATE_PLT)
+               __wl1271_plt_stop(wl);
+
        unregister_netdevice_notifier(&wl1271_dev_notifier);
        ieee80211_unregister_hw(wl->hw);
        wl->mac80211_registered = false;
@@ -3135,7 +3318,9 @@ int wl1271_init_ieee80211(struct wl1271 *wl)
                IEEE80211_HW_SUPPORTS_UAPSD |
                IEEE80211_HW_HAS_RATE_CONTROL |
                IEEE80211_HW_CONNECTION_MONITOR |
-               IEEE80211_HW_SUPPORTS_CQM_RSSI;
+               IEEE80211_HW_SUPPORTS_CQM_RSSI |
+               IEEE80211_HW_REPORTS_TX_ACK_STATUS |
+               IEEE80211_HW_AP_LINK_PS;
 
        wl->hw->wiphy->cipher_suites = cipher_suites;
        wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
@@ -3174,6 +3359,8 @@ int wl1271_init_ieee80211(struct wl1271 *wl)
 
        wl->hw->sta_data_size = sizeof(struct wl1271_station);
 
+       wl->hw->max_rx_aggregation_subframes = 8;
+
        return 0;
 }
 EXPORT_SYMBOL_GPL(wl1271_init_ieee80211);
@@ -3185,7 +3372,7 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
        struct ieee80211_hw *hw;
        struct platform_device *plat_dev = NULL;
        struct wl1271 *wl;
-       int i, ret;
+       int i, j, ret;
        unsigned int order;
 
        hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
@@ -3213,9 +3400,16 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
        for (i = 0; i < NUM_TX_QUEUES; i++)
                skb_queue_head_init(&wl->tx_queue[i]);
 
+       for (i = 0; i < NUM_TX_QUEUES; i++)
+               for (j = 0; j < AP_MAX_LINKS; j++)
+                       skb_queue_head_init(&wl->links[j].tx_queue[i]);
+
+       skb_queue_head_init(&wl->deferred_rx_queue);
+       skb_queue_head_init(&wl->deferred_tx_queue);
+
        INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
        INIT_DELAYED_WORK(&wl->pspoll_work, wl1271_pspoll_work);
-       INIT_WORK(&wl->irq_work, wl1271_irq_work);
+       INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
        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);
@@ -3230,7 +3424,6 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
        wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
        wl->basic_rate = CONF_TX_RATE_MASK_BASIC;
        wl->rate_set = CONF_TX_RATE_MASK_BASIC;
-       wl->sta_rate_set = 0;
        wl->band = IEEE80211_BAND_2GHZ;
        wl->vif = NULL;
        wl->flags = 0;
@@ -3239,6 +3432,10 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
        wl->bss_type = MAX_BSS_TYPE;
        wl->set_bss_type = MAX_BSS_TYPE;
        wl->fw_bss_type = MAX_BSS_TYPE;
+       wl->last_tx_hlid = 0;
+       wl->ap_ps_map = 0;
+       wl->ap_fw_ps_map = 0;
+       wl->quirks = 0;
 
        memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
        for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
@@ -3328,11 +3525,11 @@ int wl1271_free_hw(struct wl1271 *wl)
 }
 EXPORT_SYMBOL_GPL(wl1271_free_hw);
 
-u32 wl12xx_debug_level;
+u32 wl12xx_debug_level = DEBUG_NONE;
 EXPORT_SYMBOL_GPL(wl12xx_debug_level);
-module_param_named(debug_level, wl12xx_debug_level, uint, DEBUG_NONE);
+module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR);
 MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
 
 MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
+MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
 MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
This page took 0.069266 seconds and 5 git commands to generate.