iwlwifi: mvm: change scan timeout to a delayed work
[cascardo/linux.git] / drivers / net / wireless / intel / iwlwifi / mvm / mac80211.c
index 4f5ec49..af1d266 100644 (file)
@@ -229,7 +229,11 @@ void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
 
        IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
        spin_lock_bh(&mvm->refs_lock);
-       WARN_ON(!mvm->refs[ref_type]--);
+       if (WARN_ON(!mvm->refs[ref_type])) {
+               spin_unlock_bh(&mvm->refs_lock);
+               return;
+       }
+       mvm->refs[ref_type]--;
        spin_unlock_bh(&mvm->refs_lock);
        iwl_trans_unref(mvm->trans);
 }
@@ -439,11 +443,19 @@ int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
        ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
        ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
        ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
+       if (iwl_mvm_has_new_rx_api(mvm))
+               ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
+
+       if (mvm->trans->num_rx_queues > 1)
+               ieee80211_hw_set(hw, USES_RSS);
 
        if (mvm->trans->max_skb_frags)
                hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
 
-       hw->queues = mvm->first_agg_queue;
+       if (!iwl_mvm_is_dqa_supported(mvm))
+               hw->queues = mvm->first_agg_queue;
+       else
+               hw->queues = IEEE80211_MAX_QUEUES;
        hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
        hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
                                    IEEE80211_RADIOTAP_MCS_HAVE_STBC;
@@ -550,18 +562,18 @@ int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
        else
                mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
 
-       if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
-               hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
-                       &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
-       if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) {
-               hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
-                       &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
+       if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
+               hw->wiphy->bands[NL80211_BAND_2GHZ] =
+                       &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
+       if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
+               hw->wiphy->bands[NL80211_BAND_5GHZ] =
+                       &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
 
                if (fw_has_capa(&mvm->fw->ucode_capa,
                                IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
                    fw_has_api(&mvm->fw->ucode_capa,
                               IWL_UCODE_TLV_API_LQ_SS_PARAMS))
-                       hw->wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap.cap |=
+                       hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
                                IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
        }
 
@@ -848,6 +860,7 @@ static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
        u16 *ssn = &params->ssn;
        u8 buf_size = params->buf_size;
        bool amsdu = params->amsdu;
+       u16 timeout = params->timeout;
 
        IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
                     sta->addr, tid, action);
@@ -888,10 +901,12 @@ static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
                        ret = -EINVAL;
                        break;
                }
-               ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size);
+               ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
+                                        timeout);
                break;
        case IEEE80211_AMPDU_RX_STOP:
-               ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size);
+               ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
+                                        timeout);
                break;
        case IEEE80211_AMPDU_TX_START:
                if (!iwl_enable_tx_ampdu(mvm->cfg)) {
@@ -1149,6 +1164,8 @@ void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
        /* the fw is stopped, the aux sta is dead: clean up driver state */
        iwl_mvm_del_aux_sta(mvm);
 
+       iwl_free_fw_paging(mvm);
+
        /*
         * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
         * won't be called in this case).
@@ -1182,6 +1199,8 @@ static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
        flush_work(&mvm->async_handlers_wk);
        flush_work(&mvm->add_stream_wk);
        cancel_delayed_work_sync(&mvm->fw_dump_wk);
+       cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
+       cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
        iwl_mvm_free_fw_dump_desc(mvm);
 
        mutex_lock(&mvm->mutex);
@@ -2343,7 +2362,7 @@ static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
        if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
                return;
 
-       if (vif->p2p && !iwl_mvm_is_p2p_standalone_uapsd_supported(mvm)) {
+       if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
                vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
                return;
        }
@@ -2911,7 +2930,7 @@ static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
                        cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
                .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
                /* Set the channel info data */
-               .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ?
+               .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
                        PHY_BAND_24 : PHY_BAND_5,
                .channel_info.channel = channel->hw_value,
                .channel_info.width = PHY_VHT_CHANNEL_MODE20,
@@ -3670,6 +3689,13 @@ static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
                        goto out_unlock;
                }
 
+               /* we still didn't unblock tx. prevent new CS meanwhile */
+               if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
+                                             lockdep_is_held(&mvm->mutex))) {
+                       ret = -EBUSY;
+                       goto out_unlock;
+               }
+
                rcu_assign_pointer(mvm->csa_vif, vif);
 
                if (WARN_ONCE(mvmvif->csa_countdown,
@@ -3678,6 +3704,8 @@ static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
                        goto out_unlock;
                }
 
+               mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
+
                break;
        case NL80211_IFTYPE_STATION:
                if (mvmvif->lqm_active)
@@ -4035,6 +4063,55 @@ static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
        }
 }
 
+void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
+                                    struct iwl_mvm_internal_rxq_notif *notif,
+                                    u32 size)
+{
+       DECLARE_WAIT_QUEUE_HEAD_ONSTACK(notif_waitq);
+       u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
+       int ret;
+
+       lockdep_assert_held(&mvm->mutex);
+
+       if (!iwl_mvm_has_new_rx_api(mvm))
+               return;
+
+       notif->cookie = mvm->queue_sync_cookie;
+
+       if (notif->sync)
+               atomic_set(&mvm->queue_sync_counter,
+                          mvm->trans->num_rx_queues);
+
+       ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
+       if (ret) {
+               IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
+               goto out;
+       }
+
+       if (notif->sync)
+               ret = wait_event_timeout(notif_waitq,
+                                        atomic_read(&mvm->queue_sync_counter) == 0,
+                                        HZ);
+       WARN_ON_ONCE(!ret);
+
+out:
+       atomic_set(&mvm->queue_sync_counter, 0);
+       mvm->queue_sync_cookie++;
+}
+
+static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
+{
+       struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
+       struct iwl_mvm_internal_rxq_notif data = {
+               .type = IWL_MVM_RXQ_EMPTY,
+               .sync = 1,
+       };
+
+       mutex_lock(&mvm->mutex);
+       iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
+       mutex_unlock(&mvm->mutex);
+}
+
 const struct ieee80211_ops iwl_mvm_hw_ops = {
        .tx = iwl_mvm_mac_tx,
        .ampdu_action = iwl_mvm_mac_ampdu_action,
@@ -4091,6 +4168,8 @@ const struct ieee80211_ops iwl_mvm_hw_ops = {
 
        .event_callback = iwl_mvm_mac_event_callback,
 
+       .sync_rx_queues = iwl_mvm_sync_rx_queues,
+
        CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
 
 #ifdef CONFIG_PM_SLEEP