iwlwifi: mvm: handle FRAME_RELEASE in MQ code
[cascardo/linux.git] / drivers / net / wireless / intel / iwlwifi / mvm / ops.c
index e80be9a..632b1dc 100644 (file)
@@ -33,6 +33,7 @@
  *
  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
+ * Copyright(c) 2016 Intel Deutschland GmbH
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -204,70 +205,107 @@ static void iwl_mvm_nic_config(struct iwl_op_mode *op_mode)
                                       ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
 }
 
+/**
+ * enum iwl_rx_handler_context context for Rx handler
+ * @RX_HANDLER_SYNC : this means that it will be called in the Rx path
+ *     which can't acquire mvm->mutex.
+ * @RX_HANDLER_ASYNC_LOCKED : If the handler needs to hold mvm->mutex
+ *     (and only in this case!), it should be set as ASYNC. In that case,
+ *     it will be called from a worker with mvm->mutex held.
+ * @RX_HANDLER_ASYNC_UNLOCKED : in case the handler needs to lock the
+ *     mutex itself, it will be called from a worker without mvm->mutex held.
+ */
+enum iwl_rx_handler_context {
+       RX_HANDLER_SYNC,
+       RX_HANDLER_ASYNC_LOCKED,
+       RX_HANDLER_ASYNC_UNLOCKED,
+};
+
+/**
+ * struct iwl_rx_handlers handler for FW notification
+ * @cmd_id: command id
+ * @context: see &iwl_rx_handler_context
+ * @fn: the function is called when notification is received
+ */
 struct iwl_rx_handlers {
        u16 cmd_id;
-       bool async;
+       enum iwl_rx_handler_context context;
        void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
 };
 
-#define RX_HANDLER(_cmd_id, _fn, _async)       \
-       { .cmd_id = _cmd_id , .fn = _fn , .async = _async }
-#define RX_HANDLER_GRP(_grp, _cmd, _fn, _async)        \
-       { .cmd_id = WIDE_ID(_grp, _cmd), .fn = _fn, .async = _async }
+#define RX_HANDLER(_cmd_id, _fn, _context)     \
+       { .cmd_id = _cmd_id, .fn = _fn, .context = _context }
+#define RX_HANDLER_GRP(_grp, _cmd, _fn, _context)      \
+       { .cmd_id = WIDE_ID(_grp, _cmd), .fn = _fn, .context = _context }
 
 /*
  * Handlers for fw notifications
  * Convention: RX_HANDLER(CMD_NAME, iwl_mvm_rx_CMD_NAME
  * This list should be in order of frequency for performance purposes.
  *
- * The handler can be SYNC - this means that it will be called in the Rx path
- * which can't acquire mvm->mutex. If the handler needs to hold mvm->mutex (and
- * only in this case!), it should be set as ASYNC. In that case, it will be
- * called from a worker with mvm->mutex held.
+ * The handler can be one from three contexts, see &iwl_rx_handler_context
  */
 static const struct iwl_rx_handlers iwl_mvm_rx_handlers[] = {
-       RX_HANDLER(TX_CMD, iwl_mvm_rx_tx_cmd, false),
-       RX_HANDLER(BA_NOTIF, iwl_mvm_rx_ba_notif, false),
-
-       RX_HANDLER(BT_PROFILE_NOTIFICATION, iwl_mvm_rx_bt_coex_notif, true),
-       RX_HANDLER(BEACON_NOTIFICATION, iwl_mvm_rx_beacon_notif, true),
-       RX_HANDLER(STATISTICS_NOTIFICATION, iwl_mvm_rx_statistics, true),
+       RX_HANDLER(TX_CMD, iwl_mvm_rx_tx_cmd, RX_HANDLER_SYNC),
+       RX_HANDLER(BA_NOTIF, iwl_mvm_rx_ba_notif, RX_HANDLER_SYNC),
+
+       RX_HANDLER(BT_PROFILE_NOTIFICATION, iwl_mvm_rx_bt_coex_notif,
+                  RX_HANDLER_ASYNC_LOCKED),
+       RX_HANDLER(BEACON_NOTIFICATION, iwl_mvm_rx_beacon_notif,
+                  RX_HANDLER_ASYNC_LOCKED),
+       RX_HANDLER(STATISTICS_NOTIFICATION, iwl_mvm_rx_statistics,
+                  RX_HANDLER_ASYNC_LOCKED),
        RX_HANDLER(ANTENNA_COUPLING_NOTIFICATION,
-                  iwl_mvm_rx_ant_coupling_notif, true),
+                  iwl_mvm_rx_ant_coupling_notif, RX_HANDLER_ASYNC_LOCKED),
+
+       RX_HANDLER(BA_WINDOW_STATUS_NOTIFICATION_ID,
+                  iwl_mvm_window_status_notif, RX_HANDLER_SYNC),
 
-       RX_HANDLER(TIME_EVENT_NOTIFICATION, iwl_mvm_rx_time_event_notif, false),
-       RX_HANDLER(MCC_CHUB_UPDATE_CMD, iwl_mvm_rx_chub_update_mcc, true),
+       RX_HANDLER(TIME_EVENT_NOTIFICATION, iwl_mvm_rx_time_event_notif,
+                  RX_HANDLER_SYNC),
+       RX_HANDLER(MCC_CHUB_UPDATE_CMD, iwl_mvm_rx_chub_update_mcc,
+                  RX_HANDLER_ASYNC_LOCKED),
 
-       RX_HANDLER(EOSP_NOTIFICATION, iwl_mvm_rx_eosp_notif, false),
+       RX_HANDLER(EOSP_NOTIFICATION, iwl_mvm_rx_eosp_notif, RX_HANDLER_SYNC),
 
        RX_HANDLER(SCAN_ITERATION_COMPLETE,
-                  iwl_mvm_rx_lmac_scan_iter_complete_notif, false),
+                  iwl_mvm_rx_lmac_scan_iter_complete_notif, RX_HANDLER_SYNC),
        RX_HANDLER(SCAN_OFFLOAD_COMPLETE,
-                  iwl_mvm_rx_lmac_scan_complete_notif, true),
+                  iwl_mvm_rx_lmac_scan_complete_notif,
+                  RX_HANDLER_ASYNC_LOCKED),
        RX_HANDLER(MATCH_FOUND_NOTIFICATION, iwl_mvm_rx_scan_match_found,
-                  false),
+                  RX_HANDLER_SYNC),
        RX_HANDLER(SCAN_COMPLETE_UMAC, iwl_mvm_rx_umac_scan_complete_notif,
-                  true),
+                  RX_HANDLER_ASYNC_LOCKED),
        RX_HANDLER(SCAN_ITERATION_COMPLETE_UMAC,
-                  iwl_mvm_rx_umac_scan_iter_complete_notif, false),
+                  iwl_mvm_rx_umac_scan_iter_complete_notif, RX_HANDLER_SYNC),
 
-       RX_HANDLER(CARD_STATE_NOTIFICATION, iwl_mvm_rx_card_state_notif, false),
+       RX_HANDLER(CARD_STATE_NOTIFICATION, iwl_mvm_rx_card_state_notif,
+                  RX_HANDLER_SYNC),
 
        RX_HANDLER(MISSED_BEACONS_NOTIFICATION, iwl_mvm_rx_missed_beacons_notif,
-                  false),
+                  RX_HANDLER_SYNC),
 
-       RX_HANDLER(REPLY_ERROR, iwl_mvm_rx_fw_error, false),
+       RX_HANDLER(REPLY_ERROR, iwl_mvm_rx_fw_error, RX_HANDLER_SYNC),
        RX_HANDLER(PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION,
-                  iwl_mvm_power_uapsd_misbehaving_ap_notif, false),
-       RX_HANDLER(DTS_MEASUREMENT_NOTIFICATION, iwl_mvm_temp_notif, true),
+                  iwl_mvm_power_uapsd_misbehaving_ap_notif, RX_HANDLER_SYNC),
+       RX_HANDLER(DTS_MEASUREMENT_NOTIFICATION, iwl_mvm_temp_notif,
+                  RX_HANDLER_ASYNC_LOCKED),
        RX_HANDLER_GRP(PHY_OPS_GROUP, DTS_MEASUREMENT_NOTIF_WIDE,
-                      iwl_mvm_temp_notif, true),
+                      iwl_mvm_temp_notif, RX_HANDLER_ASYNC_UNLOCKED),
+       RX_HANDLER_GRP(PHY_OPS_GROUP, CT_KILL_NOTIFICATION,
+                      iwl_mvm_ct_kill_notif, RX_HANDLER_SYNC),
 
        RX_HANDLER(TDLS_CHANNEL_SWITCH_NOTIFICATION, iwl_mvm_rx_tdls_notif,
-                  true),
-       RX_HANDLER(MFUART_LOAD_NOTIFICATION, iwl_mvm_rx_mfuart_notif, false),
-       RX_HANDLER(TOF_NOTIFICATION, iwl_mvm_tof_resp_handler, true),
-
+                  RX_HANDLER_ASYNC_LOCKED),
+       RX_HANDLER(MFUART_LOAD_NOTIFICATION, iwl_mvm_rx_mfuart_notif,
+                  RX_HANDLER_SYNC),
+       RX_HANDLER(TOF_NOTIFICATION, iwl_mvm_tof_resp_handler,
+                  RX_HANDLER_ASYNC_LOCKED),
+       RX_HANDLER_GRP(PROT_OFFLOAD_GROUP, STORED_BEACON_NTF,
+                      iwl_mvm_rx_stored_beacon_notif, RX_HANDLER_SYNC),
+       RX_HANDLER_GRP(DATA_PATH_GROUP, MU_GROUP_MGMT_NOTIF,
+                      iwl_mvm_mu_mimo_grp_notif, RX_HANDLER_SYNC),
 };
 #undef RX_HANDLER
 #undef RX_HANDLER_GRP
@@ -289,6 +327,7 @@ static const struct iwl_hcmd_names iwl_mvm_legacy_names[] = {
        HCMD_NAME(SCAN_COMPLETE_UMAC),
        HCMD_NAME(TOF_CMD),
        HCMD_NAME(TOF_NOTIFICATION),
+       HCMD_NAME(BA_WINDOW_STATUS_NOTIFICATION_ID),
        HCMD_NAME(ADD_STA_KEY),
        HCMD_NAME(ADD_STA),
        HCMD_NAME(REMOVE_STA),
@@ -344,6 +383,7 @@ static const struct iwl_hcmd_names iwl_mvm_legacy_names[] = {
        HCMD_NAME(MAC_PM_POWER_TABLE),
        HCMD_NAME(TDLS_CHANNEL_SWITCH_NOTIFICATION),
        HCMD_NAME(MFUART_LOAD_NOTIFICATION),
+       HCMD_NAME(RSS_CONFIG_CMD),
        HCMD_NAME(SCAN_ITERATION_COMPLETE_UMAC),
        HCMD_NAME(REPLY_RX_PHY_CMD),
        HCMD_NAME(REPLY_RX_MPDU_CMD),
@@ -378,21 +418,60 @@ static const struct iwl_hcmd_names iwl_mvm_legacy_names[] = {
        HCMD_NAME(REPLY_DEBUG_CMD),
 };
 
+/* Please keep this array *SORTED* by hex value.
+ * Access is done through binary search
+ */
+static const struct iwl_hcmd_names iwl_mvm_system_names[] = {
+       HCMD_NAME(SHARED_MEM_CFG_CMD),
+};
+
+/* Please keep this array *SORTED* by hex value.
+ * Access is done through binary search
+ */
+static const struct iwl_hcmd_names iwl_mvm_mac_conf_names[] = {
+       HCMD_NAME(LINK_QUALITY_MEASUREMENT_CMD),
+       HCMD_NAME(LINK_QUALITY_MEASUREMENT_COMPLETE_NOTIF),
+       HCMD_NAME(CHANNEL_SWITCH_NOA_NOTIF),
+};
+
 /* Please keep this array *SORTED* by hex value.
  * Access is done through binary search
  */
 static const struct iwl_hcmd_names iwl_mvm_phy_names[] = {
        HCMD_NAME(CMD_DTS_MEASUREMENT_TRIGGER_WIDE),
+       HCMD_NAME(CTDP_CONFIG_CMD),
+       HCMD_NAME(TEMP_REPORTING_THRESHOLDS_CMD),
+       HCMD_NAME(CT_KILL_NOTIFICATION),
        HCMD_NAME(DTS_MEASUREMENT_NOTIF_WIDE),
 };
 
+/* Please keep this array *SORTED* by hex value.
+ * Access is done through binary search
+ */
+static const struct iwl_hcmd_names iwl_mvm_data_path_names[] = {
+       HCMD_NAME(UPDATE_MU_GROUPS_CMD),
+       HCMD_NAME(TRIGGER_RX_QUEUES_NOTIF_CMD),
+       HCMD_NAME(MU_GROUP_MGMT_NOTIF),
+       HCMD_NAME(RX_QUEUES_NOTIFICATION),
+};
+
+/* Please keep this array *SORTED* by hex value.
+ * Access is done through binary search
+ */
+static const struct iwl_hcmd_names iwl_mvm_prot_offload_names[] = {
+       HCMD_NAME(STORED_BEACON_NTF),
+};
+
 static const struct iwl_hcmd_arr iwl_mvm_groups[] = {
        [LEGACY_GROUP] = HCMD_ARR(iwl_mvm_legacy_names),
        [LONG_GROUP] = HCMD_ARR(iwl_mvm_legacy_names),
+       [SYSTEM_GROUP] = HCMD_ARR(iwl_mvm_system_names),
+       [MAC_CONF_GROUP] = HCMD_ARR(iwl_mvm_mac_conf_names),
        [PHY_OPS_GROUP] = HCMD_ARR(iwl_mvm_phy_names),
+       [DATA_PATH_GROUP] = HCMD_ARR(iwl_mvm_data_path_names),
+       [PROT_OFFLOAD_GROUP] = HCMD_ARR(iwl_mvm_prot_offload_names),
 };
 
-
 /* this forward declaration can avoid to export the function */
 static void iwl_mvm_async_handlers_wk(struct work_struct *wk);
 static void iwl_mvm_d0i3_exit_work(struct work_struct *wk);
@@ -416,6 +495,29 @@ static u32 calc_min_backoff(struct iwl_trans *trans, const struct iwl_cfg *cfg)
 
 static void iwl_mvm_fw_error_dump_wk(struct work_struct *work);
 
+static void iwl_mvm_tx_unblock_dwork(struct work_struct *work)
+{
+       struct iwl_mvm *mvm =
+               container_of(work, struct iwl_mvm, cs_tx_unblock_dwork.work);
+       struct ieee80211_vif *tx_blocked_vif;
+       struct iwl_mvm_vif *mvmvif;
+
+       mutex_lock(&mvm->mutex);
+
+       tx_blocked_vif =
+               rcu_dereference_protected(mvm->csa_tx_blocked_vif,
+                                         lockdep_is_held(&mvm->mutex));
+
+       if (!tx_blocked_vif)
+               goto unlock;
+
+       mvmvif = iwl_mvm_vif_from_mac80211(tx_blocked_vif);
+       iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false);
+       RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
+unlock:
+       mutex_unlock(&mvm->mutex);
+}
+
 static struct iwl_op_mode *
 iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
                      const struct iwl_fw *fw, struct dentry *dbgfs_dir)
@@ -463,8 +565,11 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
 
        if (iwl_mvm_has_new_rx_api(mvm)) {
                op_mode->ops = &iwl_mvm_ops_mq;
+               trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_desc);
        } else {
                op_mode->ops = &iwl_mvm_ops;
+               trans->rx_mpdu_cmd_hdr_size =
+                       sizeof(struct iwl_rx_mpdu_res_start);
 
                if (WARN_ON(trans->num_rx_queues > 1))
                        goto out_free;
@@ -473,14 +578,20 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
        mvm->restart_fw = iwlwifi_mod_params.restart_fw ? -1 : 0;
 
        mvm->aux_queue = 15;
-       mvm->first_agg_queue = 16;
-       mvm->last_agg_queue = mvm->cfg->base_params->num_of_queues - 1;
+       if (!iwl_mvm_is_dqa_supported(mvm)) {
+               mvm->first_agg_queue = 16;
+               mvm->last_agg_queue = mvm->cfg->base_params->num_of_queues - 1;
+       } else {
+               mvm->first_agg_queue = IWL_MVM_DQA_MIN_DATA_QUEUE;
+               mvm->last_agg_queue = IWL_MVM_DQA_MAX_DATA_QUEUE;
+       }
        if (mvm->cfg->base_params->num_of_queues == 16) {
                mvm->aux_queue = 11;
                mvm->first_agg_queue = 12;
        }
        mvm->sf_state = SF_UNINIT;
        mvm->cur_ucode = IWL_UCODE_INIT;
+       mvm->drop_bcn_ap_mode = true;
 
        mutex_init(&mvm->mutex);
        mutex_init(&mvm->d0i3_suspend_mutex);
@@ -497,14 +608,19 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
        INIT_WORK(&mvm->d0i3_exit_work, iwl_mvm_d0i3_exit_work);
        INIT_DELAYED_WORK(&mvm->fw_dump_wk, iwl_mvm_fw_error_dump_wk);
        INIT_DELAYED_WORK(&mvm->tdls_cs.dwork, iwl_mvm_tdls_ch_switch_work);
+       INIT_WORK(&mvm->add_stream_wk, iwl_mvm_add_new_dqa_stream_wk);
 
        spin_lock_init(&mvm->d0i3_tx_lock);
        spin_lock_init(&mvm->refs_lock);
        skb_queue_head_init(&mvm->d0i3_tx);
        init_waitqueue_head(&mvm->d0i3_exit_waitq);
 
+       atomic_set(&mvm->queue_sync_counter, 0);
+
        SET_IEEE80211_DEV(mvm->hw, mvm->trans->dev);
 
+       INIT_DELAYED_WORK(&mvm->cs_tx_unblock_dwork, iwl_mvm_tx_unblock_dwork);
+
        /*
         * Populate the state variables that the transport layer needs
         * to know about.
@@ -513,6 +629,7 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
        trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
        trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
        switch (iwlwifi_mod_params.amsdu_size) {
+       case IWL_AMSDU_DEF:
        case IWL_AMSDU_4K:
                trans_cfg.rx_buf_size = IWL_AMSDU_4K;
                break;
@@ -527,6 +644,10 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
                       iwlwifi_mod_params.amsdu_size);
                trans_cfg.rx_buf_size = IWL_AMSDU_4K;
        }
+
+       /* the hardware splits the A-MSDU */
+       if (mvm->cfg->mq_rx_supported)
+               trans_cfg.rx_buf_size = IWL_AMSDU_4K;
        trans_cfg.wide_cmd_header = fw_has_api(&mvm->fw->ucode_capa,
                                               IWL_UCODE_TLV_API_WIDE_CMD_HDR);
 
@@ -536,7 +657,10 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
        trans_cfg.command_groups = iwl_mvm_groups;
        trans_cfg.command_groups_size = ARRAY_SIZE(iwl_mvm_groups);
 
-       trans_cfg.cmd_queue = IWL_MVM_CMD_QUEUE;
+       if (iwl_mvm_is_dqa_supported(mvm))
+               trans_cfg.cmd_queue = IWL_MVM_DQA_CMD_QUEUE;
+       else
+               trans_cfg.cmd_queue = IWL_MVM_CMD_QUEUE;
        trans_cfg.cmd_fifo = IWL_MVM_TX_FIFO_CMD;
        trans_cfg.scd_set_active = true;
 
@@ -555,7 +679,6 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
        iwl_trans_configure(mvm->trans, &trans_cfg);
 
        trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
-       trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
        trans->dbg_dest_tlv = mvm->fw->dbg_dest_tlv;
        trans->dbg_dest_reg_num = mvm->fw->dbg_dest_reg_num;
        memcpy(trans->dbg_conf_tlv, mvm->fw->dbg_conf_tlv,
@@ -575,9 +698,6 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
        IWL_INFO(mvm, "Detected %s, REV=0x%X\n",
                 mvm->cfg->name, mvm->trans->hw_rev);
 
-       min_backoff = calc_min_backoff(trans, cfg);
-       iwl_mvm_tt_initialize(mvm, min_backoff);
-
        if (iwlwifi_mod_params.nvm_file)
                mvm->nvm_file_name = iwlwifi_mod_params.nvm_file;
        else
@@ -607,7 +727,7 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
                iwl_mvm_ref(mvm, IWL_MVM_REF_INIT_UCODE);
                err = iwl_run_init_mvm_ucode(mvm, true);
                if (!err || !iwlmvm_mod_params.init_dbg)
-                       iwl_trans_stop_device(trans);
+                       iwl_mvm_stop_device(mvm);
                iwl_mvm_unref(mvm, IWL_MVM_REF_INIT_UCODE);
                mutex_unlock(&mvm->mutex);
                /* returns 0 if successful, 1 if success but in rfkill */
@@ -630,22 +750,31 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
        if (err)
                goto out_free;
 
+       min_backoff = calc_min_backoff(trans, cfg);
+       iwl_mvm_thermal_initialize(mvm, min_backoff);
+
        err = iwl_mvm_dbgfs_register(mvm, dbgfs_dir);
        if (err)
                goto out_unregister;
 
        memset(&mvm->rx_stats, 0, sizeof(struct mvm_statistics_rx));
 
-       /* rpm starts with a taken reference, we can release it now */
-       iwl_trans_unref(mvm->trans);
+       /* The transport always starts with a taken reference, we can
+        * release it now if d0i3 is supported */
+       if (iwl_mvm_is_d0i3_supported(mvm))
+               iwl_trans_unref(mvm->trans);
 
        iwl_mvm_tof_init(mvm);
 
+       setup_timer(&mvm->scan_timer, iwl_mvm_scan_timeout,
+                   (unsigned long)mvm);
+
        return op_mode;
 
  out_unregister:
        ieee80211_unregister_hw(mvm->hw);
        iwl_mvm_leds_exit(mvm);
+       iwl_mvm_thermal_exit(mvm);
  out_free:
        flush_delayed_work(&mvm->fw_dump_wk);
        iwl_phy_db_free(mvm->phy_db);
@@ -661,9 +790,16 @@ static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode)
        struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
        int i;
 
+       /* If d0i3 is supported, we have released the reference that
+        * the transport started with, so we should take it back now
+        * that we are leaving.
+        */
+       if (iwl_mvm_is_d0i3_supported(mvm))
+               iwl_trans_ref(mvm->trans);
+
        iwl_mvm_leds_exit(mvm);
 
-       iwl_mvm_tt_exit(mvm);
+       iwl_mvm_thermal_exit(mvm);
 
        ieee80211_unregister_hw(mvm->hw);
 
@@ -684,16 +820,20 @@ static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode)
        for (i = 0; i < NVM_MAX_NUM_SECTIONS; i++)
                kfree(mvm->nvm_sections[i].data);
 
-       iwl_free_fw_paging(mvm);
-
        iwl_mvm_tof_clean(mvm);
 
+       del_timer_sync(&mvm->scan_timer);
+
+       mutex_destroy(&mvm->mutex);
+       mutex_destroy(&mvm->d0i3_suspend_mutex);
+
        ieee80211_free_hw(mvm->hw);
 }
 
 struct iwl_async_handler_entry {
        struct list_head list;
        struct iwl_rx_cmd_buffer rxb;
+       enum iwl_rx_handler_context context;
        void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
 };
 
@@ -720,7 +860,6 @@ static void iwl_mvm_async_handlers_wk(struct work_struct *wk)
        INIT_LIST_HEAD(&local_list);
 
        /* Ensure that we are not in stop flow (check iwl_mvm_mac_stop) */
-       mutex_lock(&mvm->mutex);
 
        /*
         * Sync with Rx path with a lock. Remove all the entries from this list,
@@ -731,12 +870,15 @@ static void iwl_mvm_async_handlers_wk(struct work_struct *wk)
        spin_unlock_bh(&mvm->async_handlers_lock);
 
        list_for_each_entry_safe(entry, tmp, &local_list, list) {
+               if (entry->context == RX_HANDLER_ASYNC_LOCKED)
+                       mutex_lock(&mvm->mutex);
                entry->fn(mvm, &entry->rxb);
                iwl_free_rxb(&entry->rxb);
                list_del(&entry->list);
+               if (entry->context == RX_HANDLER_ASYNC_LOCKED)
+                       mutex_unlock(&mvm->mutex);
                kfree(entry);
        }
-       mutex_unlock(&mvm->mutex);
 }
 
 static inline void iwl_mvm_rx_check_trigger(struct iwl_mvm *mvm,
@@ -793,7 +935,7 @@ static void iwl_mvm_rx_common(struct iwl_mvm *mvm,
                if (rx_h->cmd_id != WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd))
                        continue;
 
-               if (!rx_h->async) {
+               if (rx_h->context == RX_HANDLER_SYNC) {
                        rx_h->fn(mvm, rxb);
                        return;
                }
@@ -807,6 +949,7 @@ static void iwl_mvm_rx_common(struct iwl_mvm *mvm,
                entry->rxb._offset = rxb->_offset;
                entry->rxb._rx_page_order = rxb->_rx_page_order;
                entry->fn = rx_h->fn;
+               entry->context = rx_h->context;
                spin_lock(&mvm->async_handlers_lock);
                list_add_tail(&entry->list, &mvm->async_handlers_list);
                spin_unlock(&mvm->async_handlers_lock);
@@ -824,8 +967,6 @@ static void iwl_mvm_rx(struct iwl_op_mode *op_mode,
 
        if (likely(pkt->hdr.cmd == REPLY_RX_MPDU_CMD))
                iwl_mvm_rx_rx_mpdu(mvm, napi, rxb);
-       else if (pkt->hdr.cmd == FRAME_RELEASE)
-               iwl_mvm_rx_frame_release(mvm, rxb, 0);
        else if (pkt->hdr.cmd == REPLY_RX_PHY_CMD)
                iwl_mvm_rx_rx_phy_cmd(mvm, rxb);
        else
@@ -841,30 +982,26 @@ static void iwl_mvm_rx_mq(struct iwl_op_mode *op_mode,
 
        if (likely(pkt->hdr.cmd == REPLY_RX_MPDU_CMD))
                iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, 0);
-       else if (pkt->hdr.cmd == REPLY_RX_PHY_CMD)
-               iwl_mvm_rx_phy_cmd_mq(mvm, rxb);
+       else if (unlikely(pkt->hdr.group_id == DATA_PATH_GROUP &&
+                         pkt->hdr.cmd == RX_QUEUES_NOTIFICATION))
+               iwl_mvm_rx_queue_notif(mvm, rxb, 0);
+       else if (pkt->hdr.cmd == FRAME_RELEASE)
+               iwl_mvm_rx_frame_release(mvm, napi, rxb, 0);
        else
                iwl_mvm_rx_common(mvm, rxb, pkt);
 }
 
-static void iwl_mvm_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
+void iwl_mvm_stop_mac_queues(struct iwl_mvm *mvm, unsigned long mq)
 {
-       struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
-       unsigned long mq;
        int q;
 
-       spin_lock_bh(&mvm->queue_info_lock);
-       mq = mvm->queue_info[queue].hw_queue_to_mac80211;
-       spin_unlock_bh(&mvm->queue_info_lock);
-
        if (WARN_ON_ONCE(!mq))
                return;
 
        for_each_set_bit(q, &mq, IEEE80211_MAX_QUEUES) {
                if (atomic_inc_return(&mvm->mac80211_queue_stop_count[q]) > 1) {
                        IWL_DEBUG_TX_QUEUES(mvm,
-                                           "queue %d (mac80211 %d) already stopped\n",
-                                           queue, q);
+                                           "mac80211 %d already stopped\n", q);
                        continue;
                }
 
@@ -884,24 +1021,29 @@ static void iwl_mvm_async_cb(struct iwl_op_mode *op_mode,
        iwl_trans_block_txq_ptrs(mvm->trans, false);
 }
 
-static void iwl_mvm_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
+static void iwl_mvm_stop_sw_queue(struct iwl_op_mode *op_mode, int hw_queue)
 {
        struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
        unsigned long mq;
-       int q;
 
        spin_lock_bh(&mvm->queue_info_lock);
-       mq = mvm->queue_info[queue].hw_queue_to_mac80211;
+       mq = mvm->queue_info[hw_queue].hw_queue_to_mac80211;
        spin_unlock_bh(&mvm->queue_info_lock);
 
+       iwl_mvm_stop_mac_queues(mvm, mq);
+}
+
+void iwl_mvm_start_mac_queues(struct iwl_mvm *mvm, unsigned long mq)
+{
+       int q;
+
        if (WARN_ON_ONCE(!mq))
                return;
 
        for_each_set_bit(q, &mq, IEEE80211_MAX_QUEUES) {
                if (atomic_dec_return(&mvm->mac80211_queue_stop_count[q]) > 0) {
                        IWL_DEBUG_TX_QUEUES(mvm,
-                                           "queue %d (mac80211 %d) still stopped\n",
-                                           queue, q);
+                                           "mac80211 %d still stopped\n", q);
                        continue;
                }
 
@@ -909,6 +1051,18 @@ static void iwl_mvm_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
        }
 }
 
+static void iwl_mvm_wake_sw_queue(struct iwl_op_mode *op_mode, int hw_queue)
+{
+       struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
+       unsigned long mq;
+
+       spin_lock_bh(&mvm->queue_info_lock);
+       mq = mvm->queue_info[hw_queue].hw_queue_to_mac80211;
+       spin_unlock_bh(&mvm->queue_info_lock);
+
+       iwl_mvm_start_mac_queues(mvm, mq);
+}
+
 void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state)
 {
        if (state)
@@ -1090,7 +1244,6 @@ static bool iwl_mvm_disallow_offloading(struct iwl_mvm *mvm,
                                        struct iwl_d0i3_iter_data *iter_data)
 {
        struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
-       struct ieee80211_sta *ap_sta;
        struct iwl_mvm_sta *mvmsta;
        u32 available_tids = 0;
        u8 tid;
@@ -1099,11 +1252,10 @@ static bool iwl_mvm_disallow_offloading(struct iwl_mvm *mvm,
                    mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT))
                return false;
 
-       ap_sta = rcu_dereference(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id]);
-       if (IS_ERR_OR_NULL(ap_sta))
+       mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id);
+       if (!mvmsta)
                return false;
 
-       mvmsta = iwl_mvm_sta_from_mac80211(ap_sta);
        spin_lock_bh(&mvmsta->lock);
        for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
                struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
@@ -1198,7 +1350,7 @@ static void iwl_mvm_set_wowlan_data(struct iwl_mvm *mvm,
        cmd->is_11n_connection = ap_sta->ht_cap.ht_supported;
        cmd->offloading_tid = iter_data->offloading_tid;
        cmd->flags = ENABLE_L3_FILTERING | ENABLE_NBNS_FILTERING |
-               ENABLE_DHCP_FILTERING;
+               ENABLE_DHCP_FILTERING | ENABLE_STORE_BEACON;
        /*
         * The d0i3 uCode takes care of the nonqos counters,
         * so configure only the qos seq ones.
@@ -1219,8 +1371,7 @@ int iwl_mvm_enter_d0i3(struct iwl_op_mode *op_mode)
        struct iwl_wowlan_config_cmd wowlan_config_cmd = {
                .wakeup_filter = cpu_to_le32(IWL_WOWLAN_WAKEUP_RX_FRAME |
                                             IWL_WOWLAN_WAKEUP_BEACON_MISS |
-                                            IWL_WOWLAN_WAKEUP_LINK_CHANGE |
-                                            IWL_WOWLAN_WAKEUP_BCN_FILTERING),
+                                            IWL_WOWLAN_WAKEUP_LINK_CHANGE),
        };
        struct iwl_d3_manager_config d3_cfg_cmd = {
                .min_sleep_time = cpu_to_le32(1000),
@@ -1270,6 +1421,12 @@ int iwl_mvm_enter_d0i3(struct iwl_op_mode *op_mode)
 
        /* configure wowlan configuration only if needed */
        if (mvm->d0i3_ap_sta_id != IWL_MVM_STATION_COUNT) {
+               /* wake on beacons only if beacon storing isn't supported */
+               if (!fw_has_capa(&mvm->fw->ucode_capa,
+                                IWL_UCODE_TLV_CAPA_BEACON_STORING))
+                       wowlan_config_cmd.wakeup_filter |=
+                               cpu_to_le32(IWL_WOWLAN_WAKEUP_BCN_FILTERING);
+
                iwl_mvm_wowlan_config_key_params(mvm,
                                                 d0i3_iter_data.connected_vif,
                                                 true, flags);
@@ -1509,7 +1666,10 @@ static void iwl_mvm_rx_mq_rss(struct iwl_op_mode *op_mode,
        struct iwl_rx_packet *pkt = rxb_addr(rxb);
 
        if (unlikely(pkt->hdr.cmd == FRAME_RELEASE))
-               iwl_mvm_rx_frame_release(mvm, rxb, queue);
+               iwl_mvm_rx_frame_release(mvm, napi, rxb, queue);
+       else if (unlikely(pkt->hdr.cmd == RX_QUEUES_NOTIFICATION &&
+                         pkt->hdr.group_id == DATA_PATH_GROUP))
+               iwl_mvm_rx_queue_notif(mvm, rxb, queue);
        else
                iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, queue);
 }