From: Tova Mussai <tova.mus...@intel.com>

In the next patch, this code will be used from different places.
As preparation export this code into function.

Signed-off-by: Tova Mussai <tova.mus...@intel.com>
Signed-off-by: Luca Coelho <luciano.coe...@intel.com>
---
 drivers/net/wireless/intel/iwlwifi/mvm/scan.c | 61 ++++++++++++-------
 1 file changed, 38 insertions(+), 23 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/scan.c 
b/drivers/net/wireless/intel/iwlwifi/mvm/scan.c
index 2f92f6516415..538cd7b2018b 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/scan.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/scan.c
@@ -1485,6 +1485,39 @@ static u16 iwl_mvm_scan_umac_flags(struct iwl_mvm *mvm,
        return flags;
 }
 
+static int
+iwl_mvm_fill_scan_sched_params(struct iwl_mvm_scan_params *params,
+                              struct iwl_scan_umac_schedule *schedule,
+                              __le16 *delay)
+{
+       int i;
+       if (WARN_ON(!params->n_scan_plans ||
+                   params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))
+               return -EINVAL;
+
+       for (i = 0; i < params->n_scan_plans; i++) {
+               struct cfg80211_sched_scan_plan *scan_plan =
+                       &params->scan_plans[i];
+
+               schedule[i].iter_count = scan_plan->iterations;
+               schedule[i].interval =
+                       cpu_to_le16(scan_plan->interval);
+       }
+
+       /*
+        * If the number of iterations of the last scan plan is set to
+        * zero, it should run infinitely. However, this is not always the case.
+        * For example, when regular scan is requested the driver sets one scan
+        * plan with one iteration.
+        */
+       if (!schedule[params->n_scan_plans - 1].iter_count)
+               schedule[params->n_scan_plans - 1].iter_count = 0xff;
+
+       *delay = cpu_to_le16(params->delay);
+
+       return 0;
+}
+
 static int iwl_mvm_scan_umac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
                             struct iwl_mvm_scan_params *params,
                             int type)
@@ -1498,7 +1531,7 @@ static int iwl_mvm_scan_umac(struct iwl_mvm *mvm, struct 
ieee80211_vif *vif,
                (struct iwl_scan_req_umac_tail_v2 *)sec_part;
        struct iwl_scan_req_umac_tail_v1 *tail_v1;
        struct iwl_ssid_ie *direct_scan;
-       int uid, i;
+       int uid, ret = 0;
        u32 ssid_bitmap = 0;
        u8 channel_flags = 0;
        u16 gen_flags;
@@ -1508,9 +1541,6 @@ static int iwl_mvm_scan_umac(struct iwl_mvm *mvm, struct 
ieee80211_vif *vif,
 
        lockdep_assert_held(&mvm->mutex);
 
-       if (WARN_ON(params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))
-               return -EINVAL;
-
        uid = iwl_mvm_scan_uid_by_status(mvm, 0);
        if (uid < 0)
                return uid;
@@ -1559,25 +1589,10 @@ static int iwl_mvm_scan_umac(struct iwl_mvm *mvm, 
struct ieee80211_vif *vif,
        chan_param->flags = channel_flags;
        chan_param->count = params->n_channels;
 
-       for (i = 0; i < params->n_scan_plans; i++) {
-               struct cfg80211_sched_scan_plan *scan_plan =
-                       &params->scan_plans[i];
-
-               tail_v2->schedule[i].iter_count = scan_plan->iterations;
-               tail_v2->schedule[i].interval =
-                       cpu_to_le16(scan_plan->interval);
-       }
-
-       /*
-        * If the number of iterations of the last scan plan is set to
-        * zero, it should run infinitely. However, this is not always the case.
-        * For example, when regular scan is requested the driver sets one scan
-        * plan with one iteration.
-        */
-       if (!tail_v2->schedule[i - 1].iter_count)
-               tail_v2->schedule[i - 1].iter_count = 0xff;
-
-       tail_v2->delay = cpu_to_le16(params->delay);
+       ret = iwl_mvm_fill_scan_sched_params(params, tail_v2->schedule,
+                                            &tail_v2->delay);
+       if (ret)
+               return ret;
 
        if (iwl_mvm_is_scan_ext_chan_supported(mvm)) {
                tail_v2->preq = params->preq;
-- 
2.23.0

Reply via email to