iwlwifi: mvm: be more forgiving if num of channels is too big
authorShaul Triebitz <shaul.triebitz@intel.com>
Sun, 3 Feb 2019 08:59:08 +0000 (10:59 +0200)
committerLuca Coelho <luciano.coelho@intel.com>
Fri, 22 Mar 2019 10:59:40 +0000 (12:59 +0200)
If number of channels in the driver is greater than
number of scan channels given by firmware TLV, do not
fail scan config, but adjust to firmware's number of channels.
This is helpful for supporting in driver new channels before
it being supported by firmware scan.

Signed-off-by: Shaul Triebitz <shaul.triebitz@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
drivers/net/wireless/intel/iwlwifi/mvm/scan.c

index 78694bc38e76a0017601f9af4ffc397edd0b9c2e..d9ddf9ff6428e306f9899f7a8b69f6c197ce9387 100644 (file)
@@ -1082,21 +1082,23 @@ static void iwl_mvm_fill_scan_dwell(struct iwl_mvm *mvm,
        dwell->extended = IWL_SCAN_DWELL_EXTENDED;
 }
 
-static void iwl_mvm_fill_channels(struct iwl_mvm *mvm, u8 *channels)
+static void iwl_mvm_fill_channels(struct iwl_mvm *mvm, u8 *channels,
+                                 u32 max_channels)
 {
        struct ieee80211_supported_band *band;
        int i, j = 0;
 
        band = &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
-       for (i = 0; i < band->n_channels; i++, j++)
+       for (i = 0; i < band->n_channels && j < max_channels; i++, j++)
                channels[j] = band->channels[i].hw_value;
        band = &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
-       for (i = 0; i < band->n_channels; i++, j++)
+       for (i = 0; i < band->n_channels && j < max_channels; i++, j++)
                channels[j] = band->channels[i].hw_value;
 }
 
 static void iwl_mvm_fill_scan_config_v1(struct iwl_mvm *mvm, void *config,
-                                       u32 flags, u8 channel_flags)
+                                       u32 flags, u8 channel_flags,
+                                       u32 max_channels)
 {
        enum iwl_mvm_scan_type type = iwl_mvm_get_scan_type(mvm, NULL);
        struct iwl_scan_config_v1 *cfg = config;
@@ -1115,11 +1117,12 @@ static void iwl_mvm_fill_scan_config_v1(struct iwl_mvm *mvm, void *config,
        cfg->bcast_sta_id = mvm->aux_sta.sta_id;
        cfg->channel_flags = channel_flags;
 
-       iwl_mvm_fill_channels(mvm, cfg->channel_array);
+       iwl_mvm_fill_channels(mvm, cfg->channel_array, max_channels);
 }
 
 static void iwl_mvm_fill_scan_config(struct iwl_mvm *mvm, void *config,
-                                    u32 flags, u8 channel_flags)
+                                    u32 flags, u8 channel_flags,
+                                    u32 max_channels)
 {
        struct iwl_scan_config *cfg = config;
 
@@ -1162,7 +1165,7 @@ static void iwl_mvm_fill_scan_config(struct iwl_mvm *mvm, void *config,
        cfg->bcast_sta_id = mvm->aux_sta.sta_id;
        cfg->channel_flags = channel_flags;
 
-       iwl_mvm_fill_channels(mvm, cfg->channel_array);
+       iwl_mvm_fill_channels(mvm, cfg->channel_array, max_channels);
 }
 
 int iwl_mvm_config_scan(struct iwl_mvm *mvm)
@@ -1181,7 +1184,7 @@ int iwl_mvm_config_scan(struct iwl_mvm *mvm)
        u8 channel_flags;
 
        if (WARN_ON(num_channels > mvm->fw->ucode_capa.n_scan_channels))
-               return -ENOBUFS;
+               num_channels = mvm->fw->ucode_capa.n_scan_channels;
 
        if (iwl_mvm_is_cdb_supported(mvm)) {
                type = iwl_mvm_get_scan_type_band(mvm, NULL,
@@ -1234,9 +1237,11 @@ int iwl_mvm_config_scan(struct iwl_mvm *mvm)
                        flags |= (iwl_mvm_is_scan_fragmented(hb_type)) ?
                                 SCAN_CONFIG_FLAG_SET_LMAC2_FRAGMENTED :
                                 SCAN_CONFIG_FLAG_CLEAR_LMAC2_FRAGMENTED;
-               iwl_mvm_fill_scan_config(mvm, cfg, flags, channel_flags);
+               iwl_mvm_fill_scan_config(mvm, cfg, flags, channel_flags,
+                                        num_channels);
        } else {
-               iwl_mvm_fill_scan_config_v1(mvm, cfg, flags, channel_flags);
+               iwl_mvm_fill_scan_config_v1(mvm, cfg, flags, channel_flags,
+                                           num_channels);
        }
 
        cmd.data[0] = cfg;