Path: blob/main/sys/contrib/dev/iwlwifi/mvm/scan.c
48287 views
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause1/*2* Copyright (C) 2012-2014, 2018-2025 Intel Corporation3* Copyright (C) 2013-2015 Intel Mobile Communications GmbH4* Copyright (C) 2016-2017 Intel Deutschland GmbH5*/6#include <linux/etherdevice.h>7#include <net/mac80211.h>8#include <linux/crc32.h>910#include "mvm.h"11#include "fw/api/scan.h"12#include "iwl-io.h"13#include "iwl-utils.h"1415#define IWL_DENSE_EBS_SCAN_RATIO 516#define IWL_SPARSE_EBS_SCAN_RATIO 11718#define IWL_SCAN_DWELL_ACTIVE 1019#define IWL_SCAN_DWELL_PASSIVE 11020#define IWL_SCAN_DWELL_FRAGMENTED 4421#define IWL_SCAN_DWELL_EXTENDED 9022#define IWL_SCAN_NUM_OF_FRAGS 32324/* adaptive dwell max budget time [TU] for full scan */25#define IWL_SCAN_ADWELL_MAX_BUDGET_FULL_SCAN 30026/* adaptive dwell max budget time [TU] for directed scan */27#define IWL_SCAN_ADWELL_MAX_BUDGET_DIRECTED_SCAN 10028/* adaptive dwell default high band APs number */29#define IWL_SCAN_ADWELL_DEFAULT_HB_N_APS 830/* adaptive dwell default low band APs number */31#define IWL_SCAN_ADWELL_DEFAULT_LB_N_APS 232/* adaptive dwell default APs number in social channels (1, 6, 11) */33#define IWL_SCAN_ADWELL_DEFAULT_N_APS_SOCIAL 1034/* number of scan channels */35#define IWL_SCAN_NUM_CHANNELS 11236/* adaptive dwell number of APs override mask for p2p friendly GO */37#define IWL_SCAN_ADWELL_N_APS_GO_FRIENDLY_BIT BIT(20)38/* adaptive dwell number of APs override mask for social channels */39#define IWL_SCAN_ADWELL_N_APS_SOCIAL_CHS_BIT BIT(21)40/* adaptive dwell number of APs override for p2p friendly GO channels */41#define IWL_SCAN_ADWELL_N_APS_GO_FRIENDLY 1042/* adaptive dwell number of APs override for social channels */43#define IWL_SCAN_ADWELL_N_APS_SOCIAL_CHS 24445/* minimal number of 2GHz and 5GHz channels in the regular scan request */46#define IWL_MVM_6GHZ_PASSIVE_SCAN_MIN_CHANS 44748/* Number of iterations on the channel for mei filtered scan */49#define IWL_MEI_SCAN_NUM_ITER 5U5051#define WFA_TPC_IE_LEN 95253struct iwl_mvm_scan_timing_params {54u32 suspend_time;55u32 max_out_time;56};5758static struct iwl_mvm_scan_timing_params scan_timing[] = {59[IWL_SCAN_TYPE_UNASSOC] = {60.suspend_time = 0,61.max_out_time = 0,62},63[IWL_SCAN_TYPE_WILD] = {64.suspend_time = 30,65.max_out_time = 120,66},67[IWL_SCAN_TYPE_MILD] = {68.suspend_time = 120,69.max_out_time = 120,70},71[IWL_SCAN_TYPE_FRAGMENTED] = {72.suspend_time = 95,73.max_out_time = 44,74},75[IWL_SCAN_TYPE_FAST_BALANCE] = {76.suspend_time = 30,77.max_out_time = 37,78},79};8081struct iwl_mvm_scan_params {82/* For CDB this is low band scan type, for non-CDB - type. */83enum iwl_mvm_scan_type type;84enum iwl_mvm_scan_type hb_type;85u32 n_channels;86u16 delay;87int n_ssids;88struct cfg80211_ssid *ssids;89struct ieee80211_channel **channels;90u32 flags;91u8 *mac_addr;92u8 *mac_addr_mask;93bool no_cck;94bool pass_all;95int n_match_sets;96struct iwl_scan_probe_req preq;97struct cfg80211_match_set *match_sets;98int n_scan_plans;99struct cfg80211_sched_scan_plan *scan_plans;100bool iter_notif;101struct cfg80211_scan_6ghz_params *scan_6ghz_params;102u32 n_6ghz_params;103bool scan_6ghz;104bool enable_6ghz_passive;105bool respect_p2p_go, respect_p2p_go_hb;106s8 tsf_report_link_id;107u8 bssid[ETH_ALEN] __aligned(2);108};109110static inline void *iwl_mvm_get_scan_req_umac_data(struct iwl_mvm *mvm)111{112struct iwl_scan_req_umac *cmd = mvm->scan_cmd;113114if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm))115return (void *)&cmd->v8.data;116117if (iwl_mvm_is_adaptive_dwell_supported(mvm))118return (void *)&cmd->v7.data;119120if (iwl_mvm_cdb_scan_api(mvm))121return (void *)&cmd->v6.data;122123return (void *)&cmd->v1.data;124}125126static inline struct iwl_scan_umac_chan_param *127iwl_mvm_get_scan_req_umac_channel(struct iwl_mvm *mvm)128{129struct iwl_scan_req_umac *cmd = mvm->scan_cmd;130131if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm))132return &cmd->v8.channel;133134if (iwl_mvm_is_adaptive_dwell_supported(mvm))135return &cmd->v7.channel;136137if (iwl_mvm_cdb_scan_api(mvm))138return &cmd->v6.channel;139140return &cmd->v1.channel;141}142143static u8 iwl_mvm_scan_rx_ant(struct iwl_mvm *mvm)144{145if (mvm->scan_rx_ant != ANT_NONE)146return mvm->scan_rx_ant;147return iwl_mvm_get_valid_rx_ant(mvm);148}149150static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm)151{152u16 rx_chain;153u8 rx_ant;154155rx_ant = iwl_mvm_scan_rx_ant(mvm);156rx_chain = rx_ant << PHY_RX_CHAIN_VALID_POS;157rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_MIMO_SEL_POS;158rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_SEL_POS;159rx_chain |= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS;160return cpu_to_le16(rx_chain);161}162163static inline __le32164iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum nl80211_band band,165bool no_cck)166{167u32 tx_ant;168169iwl_mvm_toggle_tx_ant(mvm, &mvm->scan_last_antenna_idx);170tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS;171172if (band == NL80211_BAND_2GHZ && !no_cck)173return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK_V1 |174tx_ant);175else176return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant);177}178179static enum iwl_mvm_traffic_load iwl_mvm_get_traffic_load(struct iwl_mvm *mvm)180{181return mvm->tcm.result.global_load;182}183184static enum iwl_mvm_traffic_load185iwl_mvm_get_traffic_load_band(struct iwl_mvm *mvm, enum nl80211_band band)186{187return mvm->tcm.result.band_load[band];188}189190struct iwl_mvm_scan_iter_data {191u32 global_cnt;192struct ieee80211_vif *current_vif;193bool is_dcm_with_p2p_go;194};195196static void iwl_mvm_scan_iterator(void *_data, u8 *mac,197struct ieee80211_vif *vif)198{199struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);200struct iwl_mvm_scan_iter_data *data = _data;201struct iwl_mvm_vif *curr_mvmvif;202203if (vif->type != NL80211_IFTYPE_P2P_DEVICE &&204mvmvif->deflink.phy_ctxt &&205mvmvif->deflink.phy_ctxt->id < NUM_PHY_CTX)206data->global_cnt += 1;207208if (!data->current_vif || vif == data->current_vif)209return;210211curr_mvmvif = iwl_mvm_vif_from_mac80211(data->current_vif);212213if (ieee80211_vif_type_p2p(vif) == NL80211_IFTYPE_P2P_GO &&214mvmvif->deflink.phy_ctxt && curr_mvmvif->deflink.phy_ctxt &&215mvmvif->deflink.phy_ctxt->id != curr_mvmvif->deflink.phy_ctxt->id)216data->is_dcm_with_p2p_go = true;217}218219static enum220iwl_mvm_scan_type _iwl_mvm_get_scan_type(struct iwl_mvm *mvm,221struct ieee80211_vif *vif,222enum iwl_mvm_traffic_load load,223bool low_latency)224{225struct iwl_mvm_scan_iter_data data = {226.current_vif = vif,227.is_dcm_with_p2p_go = false,228.global_cnt = 0,229};230231/*232* A scanning AP interface probably wants to generate a survey to do233* ACS (automatic channel selection).234* Force a non-fragmented scan in that case.235*/236if (vif && ieee80211_vif_type_p2p(vif) == NL80211_IFTYPE_AP)237return IWL_SCAN_TYPE_WILD;238239ieee80211_iterate_active_interfaces_atomic(mvm->hw,240IEEE80211_IFACE_ITER_NORMAL,241iwl_mvm_scan_iterator,242&data);243244if (!data.global_cnt)245return IWL_SCAN_TYPE_UNASSOC;246247if (fw_has_api(&mvm->fw->ucode_capa,248IWL_UCODE_TLV_API_FRAGMENTED_SCAN)) {249if ((load == IWL_MVM_TRAFFIC_HIGH || low_latency) &&250(!vif || vif->type != NL80211_IFTYPE_P2P_DEVICE))251return IWL_SCAN_TYPE_FRAGMENTED;252253/*254* in case of DCM with P2P GO set all scan requests as255* fast-balance scan256*/257if (vif && vif->type == NL80211_IFTYPE_STATION &&258data.is_dcm_with_p2p_go)259return IWL_SCAN_TYPE_FAST_BALANCE;260}261262if (load >= IWL_MVM_TRAFFIC_MEDIUM || low_latency)263return IWL_SCAN_TYPE_MILD;264265return IWL_SCAN_TYPE_WILD;266}267268static enum269iwl_mvm_scan_type iwl_mvm_get_scan_type(struct iwl_mvm *mvm,270struct ieee80211_vif *vif)271{272enum iwl_mvm_traffic_load load;273bool low_latency;274275load = iwl_mvm_get_traffic_load(mvm);276low_latency = iwl_mvm_low_latency(mvm);277278return _iwl_mvm_get_scan_type(mvm, vif, load, low_latency);279}280281static enum282iwl_mvm_scan_type iwl_mvm_get_scan_type_band(struct iwl_mvm *mvm,283struct ieee80211_vif *vif,284enum nl80211_band band)285{286enum iwl_mvm_traffic_load load;287bool low_latency;288289load = iwl_mvm_get_traffic_load_band(mvm, band);290low_latency = iwl_mvm_low_latency_band(mvm, band);291292return _iwl_mvm_get_scan_type(mvm, vif, load, low_latency);293}294295static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm *mvm)296{297/* require rrm scan whenever the fw supports it */298return fw_has_capa(&mvm->fw->ucode_capa,299IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT);300}301302static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm *mvm)303{304int max_probe_len;305306max_probe_len = SCAN_OFFLOAD_PROBE_REQ_SIZE;307308/* we create the 802.11 header SSID element and WFA TPC element */309max_probe_len -= 24 + 2 + WFA_TPC_IE_LEN;310311/* DS parameter set element is added on 2.4GHZ band if required */312if (iwl_mvm_rrm_scan_needed(mvm))313max_probe_len -= 3;314315return max_probe_len;316}317318int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)319{320int max_ie_len = iwl_mvm_max_scan_ie_fw_cmd_room(mvm);321322/* TODO: [BUG] This function should return the maximum allowed size of323* scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs324* in the same command. So the correct implementation of this function325* is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan326* command has only 512 bytes and it would leave us with about 240327* bytes for scan IEs, which is clearly not enough. So meanwhile328* we will report an incorrect value. This may result in a failure to329* issue a scan in unified_scan_lmac and unified_sched_scan_lmac330* functions with -ENOBUFS, if a large enough probe will be provided.331*/332return max_ie_len;333}334335void iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm *mvm,336struct iwl_rx_cmd_buffer *rxb)337{338struct iwl_rx_packet *pkt = rxb_addr(rxb);339struct iwl_lmac_scan_complete_notif *notif = (void *)pkt->data;340341IWL_DEBUG_SCAN(mvm,342"Scan offload iteration complete: status=0x%x scanned channels=%d\n",343notif->status, notif->scanned_channels);344345if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_FOUND) {346IWL_DEBUG_SCAN(mvm, "Pass all scheduled scan results found\n");347ieee80211_sched_scan_results(mvm->hw);348mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_ENABLED;349}350}351352void iwl_mvm_rx_scan_match_found(struct iwl_mvm *mvm,353struct iwl_rx_cmd_buffer *rxb)354{355IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n");356ieee80211_sched_scan_results(mvm->hw);357}358359static const char *iwl_mvm_ebs_status_str(enum iwl_scan_ebs_status status)360{361switch (status) {362case IWL_SCAN_EBS_SUCCESS:363return "successful";364case IWL_SCAN_EBS_INACTIVE:365return "inactive";366case IWL_SCAN_EBS_FAILED:367case IWL_SCAN_EBS_CHAN_NOT_FOUND:368default:369return "failed";370}371}372373void iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm *mvm,374struct iwl_rx_cmd_buffer *rxb)375{376struct iwl_rx_packet *pkt = rxb_addr(rxb);377struct iwl_periodic_scan_complete *scan_notif = (void *)pkt->data;378bool aborted = (scan_notif->status == IWL_SCAN_OFFLOAD_ABORTED);379380/* If this happens, the firmware has mistakenly sent an LMAC381* notification during UMAC scans -- warn and ignore it.382*/383if (WARN_ON_ONCE(fw_has_capa(&mvm->fw->ucode_capa,384IWL_UCODE_TLV_CAPA_UMAC_SCAN)))385return;386387/* scan status must be locked for proper checking */388lockdep_assert_held(&mvm->mutex);389390/* We first check if we were stopping a scan, in which case we391* just clear the stopping flag. Then we check if it was a392* firmware initiated stop, in which case we need to inform393* mac80211.394* Note that we can have a stopping and a running scan395* simultaneously, but we can't have two different types of396* scans stopping or running at the same time (since LMAC397* doesn't support it).398*/399400if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_SCHED) {401WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR);402403IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s\n",404aborted ? "aborted" : "completed",405iwl_mvm_ebs_status_str(scan_notif->ebs_status));406IWL_DEBUG_SCAN(mvm,407"Last line %d, Last iteration %d, Time after last iteration %d\n",408scan_notif->last_schedule_line,409scan_notif->last_schedule_iteration,410__le32_to_cpu(scan_notif->time_after_last_iter));411412mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_SCHED;413} else if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR) {414IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s\n",415aborted ? "aborted" : "completed",416iwl_mvm_ebs_status_str(scan_notif->ebs_status));417418mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_REGULAR;419} else if (mvm->scan_status & IWL_MVM_SCAN_SCHED) {420WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_REGULAR);421422IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s\n",423aborted ? "aborted" : "completed",424iwl_mvm_ebs_status_str(scan_notif->ebs_status));425IWL_DEBUG_SCAN(mvm,426"Last line %d, Last iteration %d, Time after last iteration %d (FW)\n",427scan_notif->last_schedule_line,428scan_notif->last_schedule_iteration,429__le32_to_cpu(scan_notif->time_after_last_iter));430431mvm->scan_status &= ~IWL_MVM_SCAN_SCHED;432ieee80211_sched_scan_stopped(mvm->hw);433mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;434} else if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) {435struct cfg80211_scan_info info = {436.aborted = aborted,437};438439IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s (FW)\n",440aborted ? "aborted" : "completed",441iwl_mvm_ebs_status_str(scan_notif->ebs_status));442443mvm->scan_status &= ~IWL_MVM_SCAN_REGULAR;444ieee80211_scan_completed(mvm->hw, &info);445cancel_delayed_work(&mvm->scan_timeout_dwork);446iwl_mvm_resume_tcm(mvm);447} else {448IWL_ERR(mvm,449"got scan complete notification but no scan is running\n");450}451452mvm->last_ebs_successful =453scan_notif->ebs_status == IWL_SCAN_EBS_SUCCESS ||454scan_notif->ebs_status == IWL_SCAN_EBS_INACTIVE;455}456457static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list)458{459int i;460461for (i = 0; i < PROBE_OPTION_MAX; i++) {462if (!ssid_list[i].len)463break;464if (ssid_list[i].len == ssid_len &&465!memcmp(ssid_list[i].ssid, ssid, ssid_len))466return i;467}468return -1;469}470471/* We insert the SSIDs in an inverted order, because the FW will472* invert it back.473*/474static void iwl_scan_build_ssids(struct iwl_mvm_scan_params *params,475struct iwl_ssid_ie *ssids,476u32 *ssid_bitmap)477{478int i, j;479int index;480u32 tmp_bitmap = 0;481482/*483* copy SSIDs from match list.484* iwl_config_sched_scan_profiles() uses the order of these ssids to485* config match list.486*/487for (i = 0, j = params->n_match_sets - 1;488j >= 0 && i < PROBE_OPTION_MAX;489i++, j--) {490/* skip empty SSID matchsets */491if (!params->match_sets[j].ssid.ssid_len)492continue;493ssids[i].id = WLAN_EID_SSID;494ssids[i].len = params->match_sets[j].ssid.ssid_len;495memcpy(ssids[i].ssid, params->match_sets[j].ssid.ssid,496ssids[i].len);497}498499/* add SSIDs from scan SSID list */500for (j = params->n_ssids - 1;501j >= 0 && i < PROBE_OPTION_MAX;502i++, j--) {503index = iwl_ssid_exist(params->ssids[j].ssid,504params->ssids[j].ssid_len,505ssids);506if (index < 0) {507ssids[i].id = WLAN_EID_SSID;508ssids[i].len = params->ssids[j].ssid_len;509memcpy(ssids[i].ssid, params->ssids[j].ssid,510ssids[i].len);511tmp_bitmap |= BIT(i);512} else {513tmp_bitmap |= BIT(index);514}515}516if (ssid_bitmap)517*ssid_bitmap = tmp_bitmap;518}519520static int521iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm,522struct cfg80211_sched_scan_request *req)523{524struct iwl_scan_offload_profile *profile;525struct iwl_scan_offload_profile_cfg_v1 *profile_cfg_v1;526struct iwl_scan_offload_blocklist *blocklist;527struct iwl_scan_offload_profile_cfg_data *data;528int max_profiles = iwl_umac_scan_get_max_profiles(mvm->fw);529int profile_cfg_size = sizeof(*data) +530sizeof(*profile) * max_profiles;531struct iwl_host_cmd cmd = {532.id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD,533.len[1] = profile_cfg_size,534.dataflags[0] = IWL_HCMD_DFL_NOCOPY,535.dataflags[1] = IWL_HCMD_DFL_NOCOPY,536};537int blocklist_len;538int i;539int ret;540541if (WARN_ON(req->n_match_sets > max_profiles))542return -EIO;543544if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL)545blocklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN;546else547blocklist_len = IWL_SCAN_MAX_BLACKLIST_LEN;548549blocklist = kcalloc(blocklist_len, sizeof(*blocklist), GFP_KERNEL);550if (!blocklist)551return -ENOMEM;552553profile_cfg_v1 = kzalloc(profile_cfg_size, GFP_KERNEL);554if (!profile_cfg_v1) {555ret = -ENOMEM;556goto free_blocklist;557}558559cmd.data[0] = blocklist;560cmd.len[0] = sizeof(*blocklist) * blocklist_len;561cmd.data[1] = profile_cfg_v1;562563/* if max_profile is MAX_PROFILES_V2, we have the new API */564if (max_profiles == IWL_SCAN_MAX_PROFILES_V2) {565struct iwl_scan_offload_profile_cfg *profile_cfg =566(struct iwl_scan_offload_profile_cfg *)profile_cfg_v1;567568data = &profile_cfg->data;569} else {570data = &profile_cfg_v1->data;571}572573/* No blocklist configuration */574data->num_profiles = req->n_match_sets;575data->active_clients = SCAN_CLIENT_SCHED_SCAN;576data->pass_match = SCAN_CLIENT_SCHED_SCAN;577data->match_notify = SCAN_CLIENT_SCHED_SCAN;578579if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len)580data->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN;581582for (i = 0; i < req->n_match_sets; i++) {583profile = &profile_cfg_v1->profiles[i];584profile->ssid_index = i;585/* Support any cipher and auth algorithm */586profile->unicast_cipher = 0xff;587profile->auth_alg = IWL_AUTH_ALGO_UNSUPPORTED |588IWL_AUTH_ALGO_NONE | IWL_AUTH_ALGO_PSK | IWL_AUTH_ALGO_8021X |589IWL_AUTH_ALGO_SAE | IWL_AUTH_ALGO_8021X_SHA384 | IWL_AUTH_ALGO_OWE;590profile->network_type = IWL_NETWORK_TYPE_ANY;591profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY;592profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN;593}594595IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n");596597ret = iwl_mvm_send_cmd(mvm, &cmd);598kfree(profile_cfg_v1);599free_blocklist:600kfree(blocklist);601602return ret;603}604605static bool iwl_mvm_scan_pass_all(struct iwl_mvm *mvm,606struct cfg80211_sched_scan_request *req)607{608if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) {609IWL_DEBUG_SCAN(mvm,610"Sending scheduled scan with filtering, n_match_sets %d\n",611req->n_match_sets);612mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;613return false;614}615616IWL_DEBUG_SCAN(mvm, "Sending Scheduled scan without filtering\n");617618mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_ENABLED;619return true;620}621622static int iwl_mvm_lmac_scan_abort(struct iwl_mvm *mvm)623{624int ret;625struct iwl_host_cmd cmd = {626.id = SCAN_OFFLOAD_ABORT_CMD,627};628u32 status = CAN_ABORT_STATUS;629630ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status);631if (ret)632return ret;633634if (status != CAN_ABORT_STATUS) {635/*636* The scan abort will return 1 for success or637* 2 for "failure". A failure condition can be638* due to simply not being in an active scan which639* can occur if we send the scan abort before the640* microcode has notified us that a scan is completed.641*/642IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status);643ret = -ENOENT;644}645646return ret;647}648649static void iwl_mvm_scan_fill_tx_cmd(struct iwl_mvm *mvm,650struct iwl_scan_req_tx_cmd *tx_cmd,651bool no_cck)652{653tx_cmd[0].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |654TX_CMD_FLG_BT_DIS);655tx_cmd[0].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,656NL80211_BAND_2GHZ,657no_cck);658659if (!iwl_mvm_has_new_station_api(mvm->fw)) {660tx_cmd[0].sta_id = mvm->aux_sta.sta_id;661tx_cmd[1].sta_id = mvm->aux_sta.sta_id;662663/*664* Fw doesn't use this sta anymore, pending deprecation via HOST API665* change666*/667} else {668tx_cmd[0].sta_id = 0xff;669tx_cmd[1].sta_id = 0xff;670}671672tx_cmd[1].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |673TX_CMD_FLG_BT_DIS);674675tx_cmd[1].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,676NL80211_BAND_5GHZ,677no_cck);678}679680static void681iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm *mvm,682struct ieee80211_channel **channels,683int n_channels, u32 ssid_bitmap,684struct iwl_scan_req_lmac *cmd)685{686struct iwl_scan_channel_cfg_lmac *channel_cfg = (void *)&cmd->data;687int i;688689for (i = 0; i < n_channels; i++) {690channel_cfg[i].channel_num =691cpu_to_le16(channels[i]->hw_value);692channel_cfg[i].iter_count = cpu_to_le16(1);693channel_cfg[i].iter_interval = 0;694channel_cfg[i].flags =695cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL |696ssid_bitmap);697}698}699700static u8 *iwl_mvm_copy_and_insert_ds_elem(struct iwl_mvm *mvm, const u8 *ies,701size_t len, u8 *const pos)702{703static const u8 before_ds_params[] = {704WLAN_EID_SSID,705WLAN_EID_SUPP_RATES,706WLAN_EID_REQUEST,707WLAN_EID_EXT_SUPP_RATES,708};709size_t offs;710u8 *newpos = pos;711712if (!iwl_mvm_rrm_scan_needed(mvm)) {713memcpy(newpos, ies, len);714return newpos + len;715}716717offs = ieee80211_ie_split(ies, len,718before_ds_params,719ARRAY_SIZE(before_ds_params),7200);721722memcpy(newpos, ies, offs);723newpos += offs;724725/* Add a placeholder for DS Parameter Set element */726*newpos++ = WLAN_EID_DS_PARAMS;727*newpos++ = 1;728*newpos++ = 0;729730memcpy(newpos, ies + offs, len - offs);731newpos += len - offs;732733return newpos;734}735736static void iwl_mvm_add_tpc_report_ie(u8 *pos)737{738pos[0] = WLAN_EID_VENDOR_SPECIFIC;739pos[1] = WFA_TPC_IE_LEN - 2;740pos[2] = (WLAN_OUI_MICROSOFT >> 16) & 0xff;741pos[3] = (WLAN_OUI_MICROSOFT >> 8) & 0xff;742pos[4] = WLAN_OUI_MICROSOFT & 0xff;743pos[5] = WLAN_OUI_TYPE_MICROSOFT_TPC;744pos[6] = 0;745/* pos[7] - tx power will be inserted by the FW */746pos[7] = 0;747pos[8] = 0;748}749750static void751iwl_mvm_build_scan_probe(struct iwl_mvm *mvm, struct ieee80211_vif *vif,752struct ieee80211_scan_ies *ies,753struct iwl_mvm_scan_params *params)754{755struct ieee80211_mgmt *frame = (void *)params->preq.buf;756u8 *pos, *newpos;757const u8 *mac_addr = params->flags & NL80211_SCAN_FLAG_RANDOM_ADDR ?758params->mac_addr : NULL;759760/*761* Unfortunately, right now the offload scan doesn't support randomising762* within the firmware, so until the firmware API is ready we implement763* it in the driver. This means that the scan iterations won't really be764* random, only when it's restarted, but at least that helps a bit.765*/766if (mac_addr)767get_random_mask_addr(frame->sa, mac_addr,768params->mac_addr_mask);769else770memcpy(frame->sa, vif->addr, ETH_ALEN);771772frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);773eth_broadcast_addr(frame->da);774ether_addr_copy(frame->bssid, params->bssid);775frame->seq_ctrl = 0;776777pos = frame->u.probe_req.variable;778*pos++ = WLAN_EID_SSID;779*pos++ = 0;780781params->preq.mac_header.offset = 0;782params->preq.mac_header.len = cpu_to_le16(24 + 2);783784/* Insert ds parameter set element on 2.4 GHz band */785newpos = iwl_mvm_copy_and_insert_ds_elem(mvm,786ies->ies[NL80211_BAND_2GHZ],787ies->len[NL80211_BAND_2GHZ],788pos);789params->preq.band_data[0].offset = cpu_to_le16(pos - params->preq.buf);790params->preq.band_data[0].len = cpu_to_le16(newpos - pos);791pos = newpos;792793memcpy(pos, ies->ies[NL80211_BAND_5GHZ],794ies->len[NL80211_BAND_5GHZ]);795params->preq.band_data[1].offset = cpu_to_le16(pos - params->preq.buf);796params->preq.band_data[1].len =797cpu_to_le16(ies->len[NL80211_BAND_5GHZ]);798pos += ies->len[NL80211_BAND_5GHZ];799800memcpy(pos, ies->ies[NL80211_BAND_6GHZ],801ies->len[NL80211_BAND_6GHZ]);802params->preq.band_data[2].offset = cpu_to_le16(pos - params->preq.buf);803params->preq.band_data[2].len =804cpu_to_le16(ies->len[NL80211_BAND_6GHZ]);805pos += ies->len[NL80211_BAND_6GHZ];806memcpy(pos, ies->common_ies, ies->common_ie_len);807params->preq.common_data.offset = cpu_to_le16(pos - params->preq.buf);808809if (iwl_mvm_rrm_scan_needed(mvm) &&810!fw_has_capa(&mvm->fw->ucode_capa,811IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)) {812iwl_mvm_add_tpc_report_ie(pos + ies->common_ie_len);813params->preq.common_data.len = cpu_to_le16(ies->common_ie_len +814WFA_TPC_IE_LEN);815} else {816params->preq.common_data.len = cpu_to_le16(ies->common_ie_len);817}818}819820static void iwl_mvm_scan_lmac_dwell(struct iwl_mvm *mvm,821struct iwl_scan_req_lmac *cmd,822struct iwl_mvm_scan_params *params)823{824cmd->active_dwell = IWL_SCAN_DWELL_ACTIVE;825cmd->passive_dwell = IWL_SCAN_DWELL_PASSIVE;826cmd->fragmented_dwell = IWL_SCAN_DWELL_FRAGMENTED;827cmd->extended_dwell = IWL_SCAN_DWELL_EXTENDED;828cmd->max_out_time = cpu_to_le32(scan_timing[params->type].max_out_time);829cmd->suspend_time = cpu_to_le32(scan_timing[params->type].suspend_time);830cmd->scan_prio = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);831}832833static inline bool iwl_mvm_scan_fits(struct iwl_mvm *mvm, int n_ssids,834struct ieee80211_scan_ies *ies,835int n_channels)836{837return ((n_ssids <= PROBE_OPTION_MAX) &&838(n_channels <= mvm->fw->ucode_capa.n_scan_channels) &&839(ies->common_ie_len +840ies->len[NL80211_BAND_2GHZ] + ies->len[NL80211_BAND_5GHZ] +841ies->len[NL80211_BAND_6GHZ] <=842iwl_mvm_max_scan_ie_fw_cmd_room(mvm)));843}844845static inline bool iwl_mvm_scan_use_ebs(struct iwl_mvm *mvm,846struct ieee80211_vif *vif)847{848const struct iwl_ucode_capabilities *capa = &mvm->fw->ucode_capa;849bool low_latency;850851if (iwl_mvm_is_cdb_supported(mvm))852low_latency = iwl_mvm_low_latency_band(mvm, NL80211_BAND_5GHZ);853else854low_latency = iwl_mvm_low_latency(mvm);855856/* We can only use EBS if:857* 1. the feature is supported;858* 2. the last EBS was successful;859* 3. if only single scan, the single scan EBS API is supported;860* 4. it's not a p2p find operation.861* 5. we are not in low latency mode,862* or if fragmented ebs is supported by the FW863* 6. the VIF is not an AP interface (scan wants survey results)864*/865return ((capa->flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT) &&866mvm->last_ebs_successful && IWL_MVM_ENABLE_EBS &&867vif->type != NL80211_IFTYPE_P2P_DEVICE &&868(!low_latency || iwl_mvm_is_frag_ebs_supported(mvm)) &&869ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_AP);870}871872static inline bool iwl_mvm_is_regular_scan(struct iwl_mvm_scan_params *params)873{874return params->n_scan_plans == 1 &&875params->scan_plans[0].iterations == 1;876}877878static bool iwl_mvm_is_scan_fragmented(enum iwl_mvm_scan_type type)879{880return (type == IWL_SCAN_TYPE_FRAGMENTED ||881type == IWL_SCAN_TYPE_FAST_BALANCE);882}883884static int iwl_mvm_scan_lmac_flags(struct iwl_mvm *mvm,885struct iwl_mvm_scan_params *params,886struct ieee80211_vif *vif)887{888int flags = 0;889890if (params->n_ssids == 0)891flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;892893if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)894flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;895896if (iwl_mvm_is_scan_fragmented(params->type))897flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;898899if (iwl_mvm_rrm_scan_needed(mvm) &&900fw_has_capa(&mvm->fw->ucode_capa,901IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))902flags |= IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED;903904if (params->pass_all)905flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;906else907flags |= IWL_MVM_LMAC_SCAN_FLAG_MATCH;908909#ifdef CONFIG_IWLWIFI_DEBUGFS910if (mvm->scan_iter_notif_enabled)911flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;912#endif913914if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED)915flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;916917if (iwl_mvm_is_regular_scan(params) &&918vif->type != NL80211_IFTYPE_P2P_DEVICE &&919!iwl_mvm_is_scan_fragmented(params->type))920flags |= IWL_MVM_LMAC_SCAN_FLAG_EXTENDED_DWELL;921922return flags;923}924925static void926iwl_mvm_scan_set_legacy_probe_req(struct iwl_scan_probe_req_v1 *p_req,927struct iwl_scan_probe_req *src_p_req)928{929int i;930931p_req->mac_header = src_p_req->mac_header;932for (i = 0; i < SCAN_NUM_BAND_PROBE_DATA_V_1; i++)933p_req->band_data[i] = src_p_req->band_data[i];934p_req->common_data = src_p_req->common_data;935memcpy(p_req->buf, src_p_req->buf, sizeof(p_req->buf));936}937938static int iwl_mvm_scan_lmac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,939struct iwl_mvm_scan_params *params)940{941struct iwl_scan_req_lmac *cmd = mvm->scan_cmd;942struct iwl_scan_probe_req_v1 *preq =943(void *)(cmd->data + sizeof(struct iwl_scan_channel_cfg_lmac) *944mvm->fw->ucode_capa.n_scan_channels);945u32 ssid_bitmap = 0;946int i;947u8 band;948949if (WARN_ON(params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))950return -EINVAL;951952iwl_mvm_scan_lmac_dwell(mvm, cmd, params);953954cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm);955cmd->iter_num = cpu_to_le32(1);956cmd->n_channels = (u8)params->n_channels;957958cmd->delay = cpu_to_le32(params->delay);959960cmd->scan_flags = cpu_to_le32(iwl_mvm_scan_lmac_flags(mvm, params,961vif));962963band = iwl_mvm_phy_band_from_nl80211(params->channels[0]->band);964cmd->flags = cpu_to_le32(band);965cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |966MAC_FILTER_IN_BEACON);967iwl_mvm_scan_fill_tx_cmd(mvm, cmd->tx_cmd, params->no_cck);968iwl_scan_build_ssids(params, cmd->direct_scan, &ssid_bitmap);969970/* this API uses bits 1-20 instead of 0-19 */971ssid_bitmap <<= 1;972973for (i = 0; i < params->n_scan_plans; i++) {974struct cfg80211_sched_scan_plan *scan_plan =975¶ms->scan_plans[i];976977cmd->schedule[i].delay =978cpu_to_le16(scan_plan->interval);979cmd->schedule[i].iterations = scan_plan->iterations;980cmd->schedule[i].full_scan_mul = 1;981}982983/*984* If the number of iterations of the last scan plan is set to985* zero, it should run infinitely. However, this is not always the case.986* For example, when regular scan is requested the driver sets one scan987* plan with one iteration.988*/989if (!cmd->schedule[i - 1].iterations)990cmd->schedule[i - 1].iterations = 0xff;991992if (iwl_mvm_scan_use_ebs(mvm, vif)) {993cmd->channel_opt[0].flags =994cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |995IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |996IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);997cmd->channel_opt[0].non_ebs_ratio =998cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO);999cmd->channel_opt[1].flags =1000cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |1001IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |1002IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);1003cmd->channel_opt[1].non_ebs_ratio =1004cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO);1005}10061007iwl_mvm_lmac_scan_cfg_channels(mvm, params->channels,1008params->n_channels, ssid_bitmap, cmd);10091010iwl_mvm_scan_set_legacy_probe_req(preq, ¶ms->preq);10111012return 0;1013}10141015static int rate_to_scan_rate_flag(unsigned int rate)1016{1017static const int rate_to_scan_rate[IWL_RATE_COUNT] = {1018[IWL_RATE_1M_INDEX] = SCAN_CONFIG_RATE_1M,1019[IWL_RATE_2M_INDEX] = SCAN_CONFIG_RATE_2M,1020[IWL_RATE_5M_INDEX] = SCAN_CONFIG_RATE_5M,1021[IWL_RATE_11M_INDEX] = SCAN_CONFIG_RATE_11M,1022[IWL_RATE_6M_INDEX] = SCAN_CONFIG_RATE_6M,1023[IWL_RATE_9M_INDEX] = SCAN_CONFIG_RATE_9M,1024[IWL_RATE_12M_INDEX] = SCAN_CONFIG_RATE_12M,1025[IWL_RATE_18M_INDEX] = SCAN_CONFIG_RATE_18M,1026[IWL_RATE_24M_INDEX] = SCAN_CONFIG_RATE_24M,1027[IWL_RATE_36M_INDEX] = SCAN_CONFIG_RATE_36M,1028[IWL_RATE_48M_INDEX] = SCAN_CONFIG_RATE_48M,1029[IWL_RATE_54M_INDEX] = SCAN_CONFIG_RATE_54M,1030};10311032return rate_to_scan_rate[rate];1033}10341035static __le32 iwl_mvm_scan_config_rates(struct iwl_mvm *mvm)1036{1037struct ieee80211_supported_band *band;1038unsigned int rates = 0;1039int i;10401041band = &mvm->nvm_data->bands[NL80211_BAND_2GHZ];1042for (i = 0; i < band->n_bitrates; i++)1043rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);1044band = &mvm->nvm_data->bands[NL80211_BAND_5GHZ];1045for (i = 0; i < band->n_bitrates; i++)1046rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);10471048/* Set both basic rates and supported rates */1049rates |= SCAN_CONFIG_SUPPORTED_RATE(rates);10501051return cpu_to_le32(rates);1052}10531054static void iwl_mvm_fill_scan_dwell(struct iwl_mvm *mvm,1055struct iwl_scan_dwell *dwell)1056{1057dwell->active = IWL_SCAN_DWELL_ACTIVE;1058dwell->passive = IWL_SCAN_DWELL_PASSIVE;1059dwell->fragmented = IWL_SCAN_DWELL_FRAGMENTED;1060dwell->extended = IWL_SCAN_DWELL_EXTENDED;1061}10621063static void iwl_mvm_fill_channels(struct iwl_mvm *mvm, u8 *channels,1064u32 max_channels)1065{1066struct ieee80211_supported_band *band;1067int i, j = 0;10681069band = &mvm->nvm_data->bands[NL80211_BAND_2GHZ];1070for (i = 0; i < band->n_channels && j < max_channels; i++, j++)1071channels[j] = band->channels[i].hw_value;1072band = &mvm->nvm_data->bands[NL80211_BAND_5GHZ];1073for (i = 0; i < band->n_channels && j < max_channels; i++, j++)1074channels[j] = band->channels[i].hw_value;1075}10761077static void iwl_mvm_fill_scan_config_v1(struct iwl_mvm *mvm, void *config,1078u32 flags, u8 channel_flags,1079u32 max_channels)1080{1081enum iwl_mvm_scan_type type = iwl_mvm_get_scan_type(mvm, NULL);1082struct iwl_scan_config_v1 *cfg = config;10831084cfg->flags = cpu_to_le32(flags);1085cfg->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));1086cfg->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));1087cfg->legacy_rates = iwl_mvm_scan_config_rates(mvm);1088cfg->out_of_channel_time = cpu_to_le32(scan_timing[type].max_out_time);1089cfg->suspend_time = cpu_to_le32(scan_timing[type].suspend_time);10901091iwl_mvm_fill_scan_dwell(mvm, &cfg->dwell);10921093memcpy(&cfg->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);10941095/* This function should not be called when using ADD_STA ver >=12 */1096WARN_ON_ONCE(iwl_mvm_has_new_station_api(mvm->fw));10971098cfg->bcast_sta_id = mvm->aux_sta.sta_id;1099cfg->channel_flags = channel_flags;11001101iwl_mvm_fill_channels(mvm, cfg->channel_array, max_channels);1102}11031104static void iwl_mvm_fill_scan_config_v2(struct iwl_mvm *mvm, void *config,1105u32 flags, u8 channel_flags,1106u32 max_channels)1107{1108struct iwl_scan_config_v2 *cfg = config;11091110cfg->flags = cpu_to_le32(flags);1111cfg->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));1112cfg->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));1113cfg->legacy_rates = iwl_mvm_scan_config_rates(mvm);11141115if (iwl_mvm_is_cdb_supported(mvm)) {1116enum iwl_mvm_scan_type lb_type, hb_type;11171118lb_type = iwl_mvm_get_scan_type_band(mvm, NULL,1119NL80211_BAND_2GHZ);1120hb_type = iwl_mvm_get_scan_type_band(mvm, NULL,1121NL80211_BAND_5GHZ);11221123cfg->out_of_channel_time[SCAN_LB_LMAC_IDX] =1124cpu_to_le32(scan_timing[lb_type].max_out_time);1125cfg->suspend_time[SCAN_LB_LMAC_IDX] =1126cpu_to_le32(scan_timing[lb_type].suspend_time);11271128cfg->out_of_channel_time[SCAN_HB_LMAC_IDX] =1129cpu_to_le32(scan_timing[hb_type].max_out_time);1130cfg->suspend_time[SCAN_HB_LMAC_IDX] =1131cpu_to_le32(scan_timing[hb_type].suspend_time);1132} else {1133enum iwl_mvm_scan_type type =1134iwl_mvm_get_scan_type(mvm, NULL);11351136cfg->out_of_channel_time[SCAN_LB_LMAC_IDX] =1137cpu_to_le32(scan_timing[type].max_out_time);1138cfg->suspend_time[SCAN_LB_LMAC_IDX] =1139cpu_to_le32(scan_timing[type].suspend_time);1140}11411142iwl_mvm_fill_scan_dwell(mvm, &cfg->dwell);11431144memcpy(&cfg->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);11451146/* This function should not be called when using ADD_STA ver >=12 */1147WARN_ON_ONCE(iwl_mvm_has_new_station_api(mvm->fw));11481149cfg->bcast_sta_id = mvm->aux_sta.sta_id;1150cfg->channel_flags = channel_flags;11511152iwl_mvm_fill_channels(mvm, cfg->channel_array, max_channels);1153}11541155static int iwl_mvm_legacy_config_scan(struct iwl_mvm *mvm)1156{1157void *cfg;1158int ret, cmd_size;1159struct iwl_host_cmd cmd = {1160.id = WIDE_ID(IWL_ALWAYS_LONG_GROUP, SCAN_CFG_CMD),1161};1162enum iwl_mvm_scan_type type;1163enum iwl_mvm_scan_type hb_type = IWL_SCAN_TYPE_NOT_SET;1164int num_channels =1165mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels +1166mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels;1167u32 flags;1168u8 channel_flags;11691170if (WARN_ON(num_channels > mvm->fw->ucode_capa.n_scan_channels))1171num_channels = mvm->fw->ucode_capa.n_scan_channels;11721173if (iwl_mvm_is_cdb_supported(mvm)) {1174type = iwl_mvm_get_scan_type_band(mvm, NULL,1175NL80211_BAND_2GHZ);1176hb_type = iwl_mvm_get_scan_type_band(mvm, NULL,1177NL80211_BAND_5GHZ);1178if (type == mvm->scan_type && hb_type == mvm->hb_scan_type)1179return 0;1180} else {1181type = iwl_mvm_get_scan_type(mvm, NULL);1182if (type == mvm->scan_type)1183return 0;1184}11851186if (iwl_mvm_cdb_scan_api(mvm))1187cmd_size = sizeof(struct iwl_scan_config_v2);1188else1189cmd_size = sizeof(struct iwl_scan_config_v1);1190cmd_size += mvm->fw->ucode_capa.n_scan_channels;11911192cfg = kzalloc(cmd_size, GFP_KERNEL);1193if (!cfg)1194return -ENOMEM;11951196flags = SCAN_CONFIG_FLAG_ACTIVATE |1197SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS |1198SCAN_CONFIG_FLAG_SET_TX_CHAINS |1199SCAN_CONFIG_FLAG_SET_RX_CHAINS |1200SCAN_CONFIG_FLAG_SET_AUX_STA_ID |1201SCAN_CONFIG_FLAG_SET_ALL_TIMES |1202SCAN_CONFIG_FLAG_SET_LEGACY_RATES |1203SCAN_CONFIG_FLAG_SET_MAC_ADDR |1204SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS |1205SCAN_CONFIG_N_CHANNELS(num_channels) |1206(iwl_mvm_is_scan_fragmented(type) ?1207SCAN_CONFIG_FLAG_SET_FRAGMENTED :1208SCAN_CONFIG_FLAG_CLEAR_FRAGMENTED);12091210channel_flags = IWL_CHANNEL_FLAG_EBS |1211IWL_CHANNEL_FLAG_ACCURATE_EBS |1212IWL_CHANNEL_FLAG_EBS_ADD |1213IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE;12141215/*1216* Check for fragmented scan on LMAC2 - high band.1217* LMAC1 - low band is checked above.1218*/1219if (iwl_mvm_cdb_scan_api(mvm)) {1220if (iwl_mvm_is_cdb_supported(mvm))1221flags |= (iwl_mvm_is_scan_fragmented(hb_type)) ?1222SCAN_CONFIG_FLAG_SET_LMAC2_FRAGMENTED :1223SCAN_CONFIG_FLAG_CLEAR_LMAC2_FRAGMENTED;1224iwl_mvm_fill_scan_config_v2(mvm, cfg, flags, channel_flags,1225num_channels);1226} else {1227iwl_mvm_fill_scan_config_v1(mvm, cfg, flags, channel_flags,1228num_channels);1229}12301231cmd.data[0] = cfg;1232cmd.len[0] = cmd_size;1233cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;12341235IWL_DEBUG_SCAN(mvm, "Sending UMAC scan config\n");12361237ret = iwl_mvm_send_cmd(mvm, &cmd);1238if (!ret) {1239mvm->scan_type = type;1240mvm->hb_scan_type = hb_type;1241}12421243kfree(cfg);1244return ret;1245}12461247int iwl_mvm_config_scan(struct iwl_mvm *mvm)1248{1249struct iwl_scan_config cfg;1250struct iwl_host_cmd cmd = {1251.id = WIDE_ID(IWL_ALWAYS_LONG_GROUP, SCAN_CFG_CMD),1252.len[0] = sizeof(cfg),1253.data[0] = &cfg,1254.dataflags[0] = IWL_HCMD_DFL_NOCOPY,1255};12561257if (!iwl_mvm_is_reduced_config_scan_supported(mvm))1258return iwl_mvm_legacy_config_scan(mvm);12591260memset(&cfg, 0, sizeof(cfg));12611262if (!iwl_mvm_has_new_station_api(mvm->fw)) {1263cfg.bcast_sta_id = mvm->aux_sta.sta_id;1264} else if (iwl_fw_lookup_cmd_ver(mvm->fw, SCAN_CFG_CMD, 0) < 5) {1265/*1266* Fw doesn't use this sta anymore. Deprecated on SCAN_CFG_CMD1267* version 5.1268*/1269cfg.bcast_sta_id = 0xff;1270}12711272cfg.tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));1273cfg.rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));12741275IWL_DEBUG_SCAN(mvm, "Sending UMAC scan config\n");12761277return iwl_mvm_send_cmd(mvm, &cmd);1278}12791280static int iwl_mvm_scan_uid_by_status(struct iwl_mvm *mvm, int status)1281{1282int i;12831284for (i = 0; i < mvm->max_scans; i++)1285if (mvm->scan_uid_status[i] == status)1286return i;12871288return -ENOENT;1289}12901291static void iwl_mvm_scan_umac_dwell(struct iwl_mvm *mvm,1292struct iwl_scan_req_umac *cmd,1293struct iwl_mvm_scan_params *params)1294{1295struct iwl_mvm_scan_timing_params *timing, *hb_timing;1296u8 active_dwell, passive_dwell;12971298timing = &scan_timing[params->type];1299active_dwell = IWL_SCAN_DWELL_ACTIVE;1300passive_dwell = IWL_SCAN_DWELL_PASSIVE;13011302if (iwl_mvm_is_adaptive_dwell_supported(mvm)) {1303cmd->v7.adwell_default_n_aps_social =1304IWL_SCAN_ADWELL_DEFAULT_N_APS_SOCIAL;1305cmd->v7.adwell_default_n_aps =1306IWL_SCAN_ADWELL_DEFAULT_LB_N_APS;13071308if (iwl_mvm_is_adwell_hb_ap_num_supported(mvm))1309cmd->v9.adwell_default_hb_n_aps =1310IWL_SCAN_ADWELL_DEFAULT_HB_N_APS;13111312/* if custom max budget was configured with debugfs */1313if (IWL_MVM_ADWELL_MAX_BUDGET)1314cmd->v7.adwell_max_budget =1315cpu_to_le16(IWL_MVM_ADWELL_MAX_BUDGET);1316else if (params->n_ssids && params->ssids[0].ssid_len)1317cmd->v7.adwell_max_budget =1318cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_DIRECTED_SCAN);1319else1320cmd->v7.adwell_max_budget =1321cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_FULL_SCAN);13221323cmd->v7.scan_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);1324cmd->v7.max_out_time[SCAN_LB_LMAC_IDX] =1325cpu_to_le32(timing->max_out_time);1326cmd->v7.suspend_time[SCAN_LB_LMAC_IDX] =1327cpu_to_le32(timing->suspend_time);13281329if (iwl_mvm_is_cdb_supported(mvm)) {1330hb_timing = &scan_timing[params->hb_type];13311332cmd->v7.max_out_time[SCAN_HB_LMAC_IDX] =1333cpu_to_le32(hb_timing->max_out_time);1334cmd->v7.suspend_time[SCAN_HB_LMAC_IDX] =1335cpu_to_le32(hb_timing->suspend_time);1336}13371338if (!iwl_mvm_is_adaptive_dwell_v2_supported(mvm)) {1339cmd->v7.active_dwell = active_dwell;1340cmd->v7.passive_dwell = passive_dwell;1341cmd->v7.fragmented_dwell = IWL_SCAN_DWELL_FRAGMENTED;1342} else {1343cmd->v8.active_dwell[SCAN_LB_LMAC_IDX] = active_dwell;1344cmd->v8.passive_dwell[SCAN_LB_LMAC_IDX] = passive_dwell;1345if (iwl_mvm_is_cdb_supported(mvm)) {1346cmd->v8.active_dwell[SCAN_HB_LMAC_IDX] =1347active_dwell;1348cmd->v8.passive_dwell[SCAN_HB_LMAC_IDX] =1349passive_dwell;1350}1351}1352} else {1353cmd->v1.extended_dwell = IWL_SCAN_DWELL_EXTENDED;1354cmd->v1.active_dwell = active_dwell;1355cmd->v1.passive_dwell = passive_dwell;1356cmd->v1.fragmented_dwell = IWL_SCAN_DWELL_FRAGMENTED;13571358if (iwl_mvm_is_cdb_supported(mvm)) {1359hb_timing = &scan_timing[params->hb_type];13601361cmd->v6.max_out_time[SCAN_HB_LMAC_IDX] =1362cpu_to_le32(hb_timing->max_out_time);1363cmd->v6.suspend_time[SCAN_HB_LMAC_IDX] =1364cpu_to_le32(hb_timing->suspend_time);1365}13661367if (iwl_mvm_cdb_scan_api(mvm)) {1368cmd->v6.scan_priority =1369cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);1370cmd->v6.max_out_time[SCAN_LB_LMAC_IDX] =1371cpu_to_le32(timing->max_out_time);1372cmd->v6.suspend_time[SCAN_LB_LMAC_IDX] =1373cpu_to_le32(timing->suspend_time);1374} else {1375cmd->v1.scan_priority =1376cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);1377cmd->v1.max_out_time =1378cpu_to_le32(timing->max_out_time);1379cmd->v1.suspend_time =1380cpu_to_le32(timing->suspend_time);1381}1382}13831384if (iwl_mvm_is_regular_scan(params))1385cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);1386else1387cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_2);1388}13891390static u32 iwl_mvm_scan_umac_ooc_priority(int type)1391{1392if (type == IWL_MVM_SCAN_REGULAR)1393return IWL_SCAN_PRIORITY_EXT_6;1394if (type == IWL_MVM_SCAN_INT_MLO)1395return IWL_SCAN_PRIORITY_EXT_4;13961397return IWL_SCAN_PRIORITY_EXT_2;1398}13991400static void1401iwl_mvm_scan_umac_dwell_v11(struct iwl_mvm *mvm,1402struct iwl_scan_general_params_v11 *general_params,1403struct iwl_mvm_scan_params *params)1404{1405struct iwl_mvm_scan_timing_params *timing, *hb_timing;1406u8 active_dwell, passive_dwell;14071408timing = &scan_timing[params->type];1409active_dwell = IWL_SCAN_DWELL_ACTIVE;1410passive_dwell = IWL_SCAN_DWELL_PASSIVE;14111412general_params->adwell_default_social_chn =1413IWL_SCAN_ADWELL_DEFAULT_N_APS_SOCIAL;1414general_params->adwell_default_2g = IWL_SCAN_ADWELL_DEFAULT_LB_N_APS;1415general_params->adwell_default_5g = IWL_SCAN_ADWELL_DEFAULT_HB_N_APS;14161417/* if custom max budget was configured with debugfs */1418if (IWL_MVM_ADWELL_MAX_BUDGET)1419general_params->adwell_max_budget =1420cpu_to_le16(IWL_MVM_ADWELL_MAX_BUDGET);1421else if (params->n_ssids && params->ssids[0].ssid_len)1422general_params->adwell_max_budget =1423cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_DIRECTED_SCAN);1424else1425general_params->adwell_max_budget =1426cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_FULL_SCAN);14271428general_params->scan_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);1429general_params->max_out_of_time[SCAN_LB_LMAC_IDX] =1430cpu_to_le32(timing->max_out_time);1431general_params->suspend_time[SCAN_LB_LMAC_IDX] =1432cpu_to_le32(timing->suspend_time);14331434hb_timing = &scan_timing[params->hb_type];14351436general_params->max_out_of_time[SCAN_HB_LMAC_IDX] =1437cpu_to_le32(hb_timing->max_out_time);1438general_params->suspend_time[SCAN_HB_LMAC_IDX] =1439cpu_to_le32(hb_timing->suspend_time);14401441general_params->active_dwell[SCAN_LB_LMAC_IDX] = active_dwell;1442general_params->passive_dwell[SCAN_LB_LMAC_IDX] = passive_dwell;1443general_params->active_dwell[SCAN_HB_LMAC_IDX] = active_dwell;1444general_params->passive_dwell[SCAN_HB_LMAC_IDX] = passive_dwell;1445}14461447struct iwl_mvm_scan_channel_segment {1448u8 start_idx;1449u8 end_idx;1450u8 first_channel_id;1451u8 last_channel_id;1452u8 channel_spacing_shift;1453u8 band;1454};14551456static const struct iwl_mvm_scan_channel_segment scan_channel_segments[] = {1457{1458.start_idx = 0,1459.end_idx = 13,1460.first_channel_id = 1,1461.last_channel_id = 14,1462.channel_spacing_shift = 0,1463.band = PHY_BAND_241464},1465{1466.start_idx = 14,1467.end_idx = 41,1468.first_channel_id = 36,1469.last_channel_id = 144,1470.channel_spacing_shift = 2,1471.band = PHY_BAND_51472},1473{1474.start_idx = 42,1475.end_idx = 50,1476.first_channel_id = 149,1477.last_channel_id = 181,1478.channel_spacing_shift = 2,1479.band = PHY_BAND_51480},1481{1482.start_idx = 51,1483.end_idx = 111,1484.first_channel_id = 1,1485.last_channel_id = 241,1486.channel_spacing_shift = 2,1487.band = PHY_BAND_61488},1489};14901491static int iwl_mvm_scan_ch_and_band_to_idx(u8 channel_id, u8 band)1492{1493int i, index;14941495if (!channel_id)1496return -EINVAL;14971498for (i = 0; i < ARRAY_SIZE(scan_channel_segments); i++) {1499const struct iwl_mvm_scan_channel_segment *ch_segment =1500&scan_channel_segments[i];1501u32 ch_offset;15021503if (ch_segment->band != band ||1504ch_segment->first_channel_id > channel_id ||1505ch_segment->last_channel_id < channel_id)1506continue;15071508ch_offset = (channel_id - ch_segment->first_channel_id) >>1509ch_segment->channel_spacing_shift;15101511index = scan_channel_segments[i].start_idx + ch_offset;1512if (index < IWL_SCAN_NUM_CHANNELS)1513return index;15141515break;1516}15171518return -EINVAL;1519}15201521static const u8 p2p_go_friendly_chs[] = {152236, 40, 44, 48, 149, 153, 157, 161, 165,1523};15241525static const u8 social_chs[] = {15261, 6, 111527};15281529static void iwl_mvm_scan_ch_add_n_aps_override(enum nl80211_iftype vif_type,1530u8 ch_id, u8 band, u8 *ch_bitmap,1531size_t bitmap_n_entries)1532{1533int i;15341535if (vif_type != NL80211_IFTYPE_P2P_DEVICE)1536return;15371538for (i = 0; i < ARRAY_SIZE(p2p_go_friendly_chs); i++) {1539if (p2p_go_friendly_chs[i] == ch_id) {1540int ch_idx, bitmap_idx;15411542ch_idx = iwl_mvm_scan_ch_and_band_to_idx(ch_id, band);1543if (ch_idx < 0)1544return;15451546bitmap_idx = ch_idx / 8;1547if (bitmap_idx >= bitmap_n_entries)1548return;15491550ch_idx = ch_idx % 8;1551ch_bitmap[bitmap_idx] |= BIT(ch_idx);15521553return;1554}1555}1556}15571558static u32 iwl_mvm_scan_ch_n_aps_flag(enum nl80211_iftype vif_type, u8 ch_id)1559{1560int i;1561u32 flags = 0;15621563if (vif_type != NL80211_IFTYPE_P2P_DEVICE)1564goto out;15651566for (i = 0; i < ARRAY_SIZE(p2p_go_friendly_chs); i++) {1567if (p2p_go_friendly_chs[i] == ch_id) {1568flags |= IWL_SCAN_ADWELL_N_APS_GO_FRIENDLY_BIT;1569break;1570}1571}15721573if (flags)1574goto out;15751576for (i = 0; i < ARRAY_SIZE(social_chs); i++) {1577if (social_chs[i] == ch_id) {1578flags |= IWL_SCAN_ADWELL_N_APS_SOCIAL_CHS_BIT;1579break;1580}1581}15821583out:1584return flags;1585}15861587static void1588iwl_mvm_umac_scan_cfg_channels(struct iwl_mvm *mvm,1589struct ieee80211_channel **channels,1590int n_channels, u32 flags,1591struct iwl_scan_channel_cfg_umac *channel_cfg)1592{1593int i;15941595for (i = 0; i < n_channels; i++) {1596channel_cfg[i].flags = cpu_to_le32(flags);1597channel_cfg[i].channel_num = channels[i]->hw_value;1598if (iwl_mvm_is_scan_ext_chan_supported(mvm)) {1599enum nl80211_band band = channels[i]->band;16001601channel_cfg[i].v2.band =1602iwl_mvm_phy_band_from_nl80211(band);1603channel_cfg[i].v2.iter_count = 1;1604channel_cfg[i].v2.iter_interval = 0;1605} else {1606channel_cfg[i].v1.iter_count = 1;1607channel_cfg[i].v1.iter_interval = 0;1608}1609}1610}16111612static void1613iwl_mvm_umac_scan_cfg_channels_v4(struct iwl_mvm *mvm,1614struct ieee80211_channel **channels,1615struct iwl_scan_channel_params_v4 *cp,1616int n_channels, u32 flags,1617enum nl80211_iftype vif_type)1618{1619u8 *bitmap = cp->adwell_ch_override_bitmap;1620size_t bitmap_n_entries = ARRAY_SIZE(cp->adwell_ch_override_bitmap);1621int i;16221623for (i = 0; i < n_channels; i++) {1624enum nl80211_band band = channels[i]->band;1625struct iwl_scan_channel_cfg_umac *cfg =1626&cp->channel_config[i];16271628cfg->flags = cpu_to_le32(flags);1629cfg->channel_num = channels[i]->hw_value;1630cfg->v2.band = iwl_mvm_phy_band_from_nl80211(band);1631cfg->v2.iter_count = 1;1632cfg->v2.iter_interval = 0;16331634iwl_mvm_scan_ch_add_n_aps_override(vif_type,1635cfg->channel_num,1636cfg->v2.band, bitmap,1637bitmap_n_entries);1638}1639}16401641static void1642iwl_mvm_umac_scan_cfg_channels_v7(struct iwl_mvm *mvm,1643struct ieee80211_channel **channels,1644struct iwl_scan_channel_params_v7 *cp,1645int n_channels, u32 flags,1646enum nl80211_iftype vif_type, u32 version)1647{1648int i;16491650for (i = 0; i < n_channels; i++) {1651enum nl80211_band band = channels[i]->band;1652struct iwl_scan_channel_cfg_umac *cfg = &cp->channel_config[i];1653u32 n_aps_flag =1654iwl_mvm_scan_ch_n_aps_flag(vif_type,1655channels[i]->hw_value);1656u8 iwl_band = iwl_mvm_phy_band_from_nl80211(band);16571658cfg->flags = cpu_to_le32(flags | n_aps_flag);1659cfg->channel_num = channels[i]->hw_value;1660if (cfg80211_channel_is_psc(channels[i]))1661cfg->flags = 0;16621663if (band == NL80211_BAND_6GHZ) {1664/* 6 GHz channels should only appear in a scan request1665* that has scan_6ghz set. The only exception is MLO1666* scan, which has to be passive.1667*/1668WARN_ON_ONCE(cfg->flags != 0);1669cfg->flags =1670cpu_to_le32(IWL_UHB_CHAN_CFG_FLAG_FORCE_PASSIVE);1671}16721673cfg->v2.iter_count = 1;1674cfg->v2.iter_interval = 0;1675if (version < 17)1676cfg->v2.band = iwl_band;1677else1678cfg->flags |= cpu_to_le32((iwl_band <<1679IWL_CHAN_CFG_FLAGS_BAND_POS));1680}1681}16821683static void1684iwl_mvm_umac_scan_fill_6g_chan_list(struct iwl_mvm *mvm,1685struct iwl_mvm_scan_params *params,1686struct iwl_scan_probe_params_v4 *pp)1687{1688int j, idex_s = 0, idex_b = 0;1689struct cfg80211_scan_6ghz_params *scan_6ghz_params =1690params->scan_6ghz_params;1691bool hidden_supported = fw_has_capa(&mvm->fw->ucode_capa,1692IWL_UCODE_TLV_CAPA_HIDDEN_6GHZ_SCAN);16931694for (j = 0; j < params->n_ssids && idex_s < SCAN_SHORT_SSID_MAX_SIZE;1695j++) {1696if (!params->ssids[j].ssid_len)1697continue;16981699pp->short_ssid[idex_s] =1700cpu_to_le32(~crc32_le(~0, params->ssids[j].ssid,1701params->ssids[j].ssid_len));17021703if (hidden_supported) {1704pp->direct_scan[idex_s].id = WLAN_EID_SSID;1705pp->direct_scan[idex_s].len = params->ssids[j].ssid_len;1706memcpy(pp->direct_scan[idex_s].ssid, params->ssids[j].ssid,1707params->ssids[j].ssid_len);1708}1709idex_s++;1710}17111712/*1713* Populate the arrays of the short SSIDs and the BSSIDs using the 6GHz1714* collocated parameters. This might not be optimal, as this processing1715* does not (yet) correspond to the actual channels, so it is possible1716* that some entries would be left out.1717*1718* TODO: improve this logic.1719*/1720for (j = 0; j < params->n_6ghz_params; j++) {1721int k;17221723/* First, try to place the short SSID */1724if (scan_6ghz_params[j].short_ssid_valid) {1725for (k = 0; k < idex_s; k++) {1726if (pp->short_ssid[k] ==1727cpu_to_le32(scan_6ghz_params[j].short_ssid))1728break;1729}17301731if (k == idex_s && idex_s < SCAN_SHORT_SSID_MAX_SIZE) {1732pp->short_ssid[idex_s++] =1733cpu_to_le32(scan_6ghz_params[j].short_ssid);1734}1735}17361737/* try to place BSSID for the same entry */1738for (k = 0; k < idex_b; k++) {1739if (!memcmp(&pp->bssid_array[k],1740scan_6ghz_params[j].bssid, ETH_ALEN))1741break;1742}17431744if (k == idex_b && idex_b < SCAN_BSSID_MAX_SIZE &&1745!WARN_ONCE(!is_valid_ether_addr(scan_6ghz_params[j].bssid),1746"scan: invalid BSSID at index %u, index_b=%u\n",1747j, idex_b)) {1748memcpy(&pp->bssid_array[idex_b++],1749scan_6ghz_params[j].bssid, ETH_ALEN);1750}1751}17521753pp->short_ssid_num = idex_s;1754pp->bssid_num = idex_b;1755}17561757/* TODO: this function can be merged with iwl_mvm_scan_umac_fill_ch_p_v7 */1758static u321759iwl_mvm_umac_scan_cfg_channels_v7_6g(struct iwl_mvm *mvm,1760struct iwl_mvm_scan_params *params,1761u32 n_channels,1762struct iwl_scan_probe_params_v4 *pp,1763struct iwl_scan_channel_params_v7 *cp,1764enum nl80211_iftype vif_type,1765u32 version)1766{1767int i;1768struct cfg80211_scan_6ghz_params *scan_6ghz_params =1769params->scan_6ghz_params;1770u32 ch_cnt;17711772for (i = 0, ch_cnt = 0; i < params->n_channels; i++) {1773struct iwl_scan_channel_cfg_umac *cfg =1774&cp->channel_config[ch_cnt];17751776u32 s_ssid_bitmap = 0, bssid_bitmap = 0, flags = 0;1777u8 k, n_s_ssids = 0, n_bssids = 0;1778u8 max_s_ssids, max_bssids;1779bool force_passive = false, found = false, allow_passive = true,1780unsolicited_probe_on_chan = false, psc_no_listen = false;1781s8 psd_20 = IEEE80211_RNR_TBTT_PARAMS_PSD_RESERVED;17821783/*1784* Avoid performing passive scan on non PSC channels unless the1785* scan is specifically a passive scan, i.e., no SSIDs1786* configured in the scan command.1787*/1788if (!cfg80211_channel_is_psc(params->channels[i]) &&1789!params->n_6ghz_params && params->n_ssids)1790continue;17911792cfg->channel_num = params->channels[i]->hw_value;1793if (version < 17)1794cfg->v2.band = PHY_BAND_6;1795else1796cfg->flags |= cpu_to_le32(PHY_BAND_6 <<1797IWL_CHAN_CFG_FLAGS_BAND_POS);17981799cfg->v5.iter_count = 1;1800cfg->v5.iter_interval = 0;18011802for (u32 j = 0; j < params->n_6ghz_params; j++) {1803s8 tmp_psd_20;18041805if (!(scan_6ghz_params[j].channel_idx == i))1806continue;18071808unsolicited_probe_on_chan |=1809scan_6ghz_params[j].unsolicited_probe;18101811/* Use the highest PSD value allowed as advertised by1812* APs for this channel1813*/1814tmp_psd_20 = scan_6ghz_params[j].psd_20;1815if (tmp_psd_20 !=1816IEEE80211_RNR_TBTT_PARAMS_PSD_RESERVED &&1817(psd_20 ==1818IEEE80211_RNR_TBTT_PARAMS_PSD_RESERVED ||1819psd_20 < tmp_psd_20))1820psd_20 = tmp_psd_20;18211822psc_no_listen |= scan_6ghz_params[j].psc_no_listen;1823}18241825/*1826* In the following cases apply passive scan:1827* 1. Non fragmented scan:1828* - PSC channel with NO_LISTEN_FLAG on should be treated1829* like non PSC channel1830* - Non PSC channel with more than 3 short SSIDs or more1831* than 9 BSSIDs.1832* - Non PSC Channel with unsolicited probe response and1833* more than 2 short SSIDs or more than 6 BSSIDs.1834* - PSC channel with more than 2 short SSIDs or more than1835* 6 BSSIDs.1836* 3. Fragmented scan:1837* - PSC channel with more than 1 SSID or 3 BSSIDs.1838* - Non PSC channel with more than 2 SSIDs or 6 BSSIDs.1839* - Non PSC channel with unsolicited probe response and1840* more than 1 SSID or more than 3 BSSIDs.1841*/1842if (!iwl_mvm_is_scan_fragmented(params->type)) {1843if (!cfg80211_channel_is_psc(params->channels[i]) ||1844psc_no_listen) {1845if (unsolicited_probe_on_chan) {1846max_s_ssids = 2;1847max_bssids = 6;1848} else {1849max_s_ssids = 3;1850max_bssids = 9;1851}1852} else {1853max_s_ssids = 2;1854max_bssids = 6;1855}1856} else if (cfg80211_channel_is_psc(params->channels[i])) {1857max_s_ssids = 1;1858max_bssids = 3;1859} else {1860if (unsolicited_probe_on_chan) {1861max_s_ssids = 1;1862max_bssids = 3;1863} else {1864max_s_ssids = 2;1865max_bssids = 6;1866}1867}18681869/*1870* The optimize the scan time, i.e., reduce the scan dwell time1871* on each channel, the below logic tries to set 3 direct BSSID1872* probe requests for each broadcast probe request with a short1873* SSID.1874* TODO: improve this logic1875*/1876for (u32 j = 0; j < params->n_6ghz_params; j++) {1877if (!(scan_6ghz_params[j].channel_idx == i))1878continue;18791880found = false;18811882for (k = 0;1883k < pp->short_ssid_num && n_s_ssids < max_s_ssids;1884k++) {1885if (!scan_6ghz_params[j].unsolicited_probe &&1886le32_to_cpu(pp->short_ssid[k]) ==1887scan_6ghz_params[j].short_ssid) {1888/* Relevant short SSID bit set */1889if (s_ssid_bitmap & BIT(k)) {1890found = true;1891break;1892}18931894/*1895* Prefer creating BSSID entries unless1896* the short SSID probe can be done in1897* the same channel dwell iteration.1898*1899* We also need to create a short SSID1900* entry for any hidden AP.1901*/1902if (3 * n_s_ssids > n_bssids &&1903!pp->direct_scan[k].len)1904break;19051906/* Hidden AP, cannot do passive scan */1907if (pp->direct_scan[k].len)1908allow_passive = false;19091910s_ssid_bitmap |= BIT(k);1911n_s_ssids++;1912found = true;1913break;1914}1915}19161917if (found)1918continue;19191920for (k = 0; k < pp->bssid_num; k++) {1921if (!memcmp(&pp->bssid_array[k],1922scan_6ghz_params[j].bssid,1923ETH_ALEN)) {1924if (!(bssid_bitmap & BIT(k))) {1925if (n_bssids < max_bssids) {1926bssid_bitmap |= BIT(k);1927n_bssids++;1928} else {1929force_passive = TRUE;1930}1931}1932break;1933}1934}1935}19361937if (cfg80211_channel_is_psc(params->channels[i]) &&1938psc_no_listen)1939flags |= IWL_UHB_CHAN_CFG_FLAG_PSC_CHAN_NO_LISTEN;19401941if (unsolicited_probe_on_chan)1942flags |= IWL_UHB_CHAN_CFG_FLAG_UNSOLICITED_PROBE_RES;19431944if ((allow_passive && force_passive) ||1945(!(bssid_bitmap | s_ssid_bitmap) &&1946!cfg80211_channel_is_psc(params->channels[i])))1947flags |= IWL_UHB_CHAN_CFG_FLAG_FORCE_PASSIVE;1948else1949flags |= bssid_bitmap | (s_ssid_bitmap << 16);19501951cfg->flags |= cpu_to_le32(flags);1952if (version >= 17)1953cfg->v5.psd_20 = psd_20;19541955ch_cnt++;1956}19571958if (params->n_channels > ch_cnt)1959IWL_DEBUG_SCAN(mvm,1960"6GHz: reducing number channels: (%u->%u)\n",1961params->n_channels, ch_cnt);19621963return ch_cnt;1964}19651966static u8 iwl_mvm_scan_umac_chan_flags_v2(struct iwl_mvm *mvm,1967struct iwl_mvm_scan_params *params,1968struct ieee80211_vif *vif)1969{1970u8 flags = 0;19711972flags |= IWL_SCAN_CHANNEL_FLAG_ENABLE_CHAN_ORDER;19731974if (iwl_mvm_scan_use_ebs(mvm, vif))1975flags |= IWL_SCAN_CHANNEL_FLAG_EBS |1976IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |1977IWL_SCAN_CHANNEL_FLAG_CACHE_ADD;19781979/* set fragmented ebs for fragmented scan on HB channels */1980if ((!iwl_mvm_is_cdb_supported(mvm) &&1981iwl_mvm_is_scan_fragmented(params->type)) ||1982(iwl_mvm_is_cdb_supported(mvm) &&1983iwl_mvm_is_scan_fragmented(params->hb_type)))1984flags |= IWL_SCAN_CHANNEL_FLAG_EBS_FRAG;19851986/*1987* force EBS in case the scan is a fragmented and there is a need to take P2P1988* GO operation into consideration during scan operation.1989*/1990if ((!iwl_mvm_is_cdb_supported(mvm) &&1991iwl_mvm_is_scan_fragmented(params->type) && params->respect_p2p_go) ||1992(iwl_mvm_is_cdb_supported(mvm) &&1993iwl_mvm_is_scan_fragmented(params->hb_type) &&1994params->respect_p2p_go_hb)) {1995IWL_DEBUG_SCAN(mvm, "Respect P2P GO. Force EBS\n");1996flags |= IWL_SCAN_CHANNEL_FLAG_FORCE_EBS;1997}19981999return flags;2000}20012002static void iwl_mvm_scan_6ghz_passive_scan(struct iwl_mvm *mvm,2003struct iwl_mvm_scan_params *params,2004struct ieee80211_vif *vif)2005{2006struct ieee80211_supported_band *sband =2007&mvm->nvm_data->bands[NL80211_BAND_6GHZ];2008u32 n_disabled, i;20092010params->enable_6ghz_passive = false;20112012if (params->scan_6ghz)2013return;20142015if (!fw_has_capa(&mvm->fw->ucode_capa,2016IWL_UCODE_TLV_CAPA_PASSIVE_6GHZ_SCAN)) {2017IWL_DEBUG_SCAN(mvm,2018"6GHz passive scan: Not supported by FW\n");2019return;2020}20212022/* 6GHz passive scan allowed only on station interface */2023if (vif->type != NL80211_IFTYPE_STATION) {2024IWL_DEBUG_SCAN(mvm,2025"6GHz passive scan: not station interface\n");2026return;2027}20282029/*2030* 6GHz passive scan is allowed in a defined time interval following HW2031* reset or resume flow, or while not associated and a large interval2032* has passed since the last 6GHz passive scan.2033*/2034if ((vif->cfg.assoc ||2035time_after(mvm->last_6ghz_passive_scan_jiffies +2036(IWL_MVM_6GHZ_PASSIVE_SCAN_TIMEOUT * HZ), jiffies)) &&2037(time_before(mvm->last_reset_or_resume_time_jiffies +2038(IWL_MVM_6GHZ_PASSIVE_SCAN_ASSOC_TIMEOUT * HZ),2039jiffies))) {2040IWL_DEBUG_SCAN(mvm, "6GHz passive scan: %s\n",2041vif->cfg.assoc ? "associated" :2042"timeout did not expire");2043return;2044}20452046/* not enough channels in the regular scan request */2047if (params->n_channels < IWL_MVM_6GHZ_PASSIVE_SCAN_MIN_CHANS) {2048IWL_DEBUG_SCAN(mvm,2049"6GHz passive scan: not enough channels\n");2050return;2051}20522053for (i = 0; i < params->n_ssids; i++) {2054if (!params->ssids[i].ssid_len)2055break;2056}20572058/* not a wildcard scan, so cannot enable passive 6GHz scan */2059if (i == params->n_ssids) {2060IWL_DEBUG_SCAN(mvm,2061"6GHz passive scan: no wildcard SSID\n");2062return;2063}20642065if (!sband || !sband->n_channels) {2066IWL_DEBUG_SCAN(mvm,2067"6GHz passive scan: no 6GHz channels\n");2068return;2069}20702071for (i = 0, n_disabled = 0; i < sband->n_channels; i++) {2072if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED))2073n_disabled++;2074}20752076/*2077* Not all the 6GHz channels are disabled, so no need for 6GHz passive2078* scan2079*/2080if (n_disabled != sband->n_channels) {2081IWL_DEBUG_SCAN(mvm,2082"6GHz passive scan: 6GHz channels enabled\n");2083return;2084}20852086/* all conditions to enable 6ghz passive scan are satisfied */2087IWL_DEBUG_SCAN(mvm, "6GHz passive scan: can be enabled\n");2088params->enable_6ghz_passive = true;2089}20902091static u16 iwl_mvm_scan_umac_flags_v2(struct iwl_mvm *mvm,2092struct iwl_mvm_scan_params *params,2093struct ieee80211_vif *vif,2094int type)2095{2096u16 flags = 0;20972098/*2099* If no direct SSIDs are provided perform a passive scan. Otherwise,2100* if there is a single SSID which is not the broadcast SSID, assume2101* that the scan is intended for roaming purposes and thus enable Rx on2102* all chains to improve chances of hearing the beacons/probe responses.2103*/2104if (params->n_ssids == 0)2105flags |= IWL_UMAC_SCAN_GEN_FLAGS_V2_FORCE_PASSIVE;2106else if (params->n_ssids == 1 && params->ssids[0].ssid_len)2107flags |= IWL_UMAC_SCAN_GEN_FLAGS_V2_USE_ALL_RX_CHAINS;21082109if (iwl_mvm_is_scan_fragmented(params->type))2110flags |= IWL_UMAC_SCAN_GEN_FLAGS_V2_FRAGMENTED_LMAC1;21112112if (iwl_mvm_is_scan_fragmented(params->hb_type))2113flags |= IWL_UMAC_SCAN_GEN_FLAGS_V2_FRAGMENTED_LMAC2;21142115if (params->pass_all)2116flags |= IWL_UMAC_SCAN_GEN_FLAGS_V2_PASS_ALL;2117else2118flags |= IWL_UMAC_SCAN_GEN_FLAGS_V2_MATCH;21192120if (!iwl_mvm_is_regular_scan(params))2121flags |= IWL_UMAC_SCAN_GEN_FLAGS_V2_PERIODIC;21222123if (params->iter_notif ||2124mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED)2125flags |= IWL_UMAC_SCAN_GEN_FLAGS_V2_NTFY_ITER_COMPLETE;21262127if (IWL_MVM_ADWELL_ENABLE)2128flags |= IWL_UMAC_SCAN_GEN_FLAGS_V2_ADAPTIVE_DWELL;21292130if (type == IWL_MVM_SCAN_SCHED || type == IWL_MVM_SCAN_NETDETECT)2131flags |= IWL_UMAC_SCAN_GEN_FLAGS_V2_PREEMPTIVE;21322133if ((type == IWL_MVM_SCAN_SCHED || type == IWL_MVM_SCAN_NETDETECT) &&2134params->flags & NL80211_SCAN_FLAG_COLOCATED_6GHZ)2135flags |= IWL_UMAC_SCAN_GEN_FLAGS_V2_TRIGGER_UHB_SCAN;21362137if (params->enable_6ghz_passive)2138flags |= IWL_UMAC_SCAN_GEN_FLAGS_V2_6GHZ_PASSIVE_SCAN;21392140if (iwl_mvm_is_oce_supported(mvm) &&2141(params->flags & (NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP |2142NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE |2143NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME)))2144flags |= IWL_UMAC_SCAN_GEN_FLAGS_V2_OCE;21452146return flags;2147}21482149static u8 iwl_mvm_scan_umac_flags2(struct iwl_mvm *mvm,2150struct iwl_mvm_scan_params *params,2151struct ieee80211_vif *vif, int type,2152u16 gen_flags)2153{2154u8 flags = 0;21552156if (iwl_mvm_is_cdb_supported(mvm)) {2157if (params->respect_p2p_go)2158flags |= IWL_UMAC_SCAN_GEN_PARAMS_FLAGS2_RESPECT_P2P_GO_LB;2159if (params->respect_p2p_go_hb)2160flags |= IWL_UMAC_SCAN_GEN_PARAMS_FLAGS2_RESPECT_P2P_GO_HB;2161} else {2162if (params->respect_p2p_go)2163flags = IWL_UMAC_SCAN_GEN_PARAMS_FLAGS2_RESPECT_P2P_GO_LB |2164IWL_UMAC_SCAN_GEN_PARAMS_FLAGS2_RESPECT_P2P_GO_HB;2165}21662167if (params->scan_6ghz &&2168fw_has_capa(&mvm->fw->ucode_capa,2169IWL_UCODE_TLV_CAPA_SCAN_DONT_TOGGLE_ANT))2170flags |= IWL_UMAC_SCAN_GEN_PARAMS_FLAGS2_DONT_TOGGLE_ANT;21712172/* Passive and AP interface -> ACS (automatic channel selection) */2173if (gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_V2_FORCE_PASSIVE &&2174ieee80211_vif_type_p2p(vif) == NL80211_IFTYPE_AP &&2175iwl_fw_lookup_notif_ver(mvm->fw, SCAN_GROUP, CHANNEL_SURVEY_NOTIF,21760) >= 1)2177flags |= IWL_UMAC_SCAN_GEN_FLAGS2_COLLECT_CHANNEL_STATS;21782179return flags;2180}21812182static u16 iwl_mvm_scan_umac_flags(struct iwl_mvm *mvm,2183struct iwl_mvm_scan_params *params,2184struct ieee80211_vif *vif)2185{2186u16 flags = 0;21872188if (params->n_ssids == 0)2189flags = IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE;21902191if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)2192flags |= IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT;21932194if (iwl_mvm_is_scan_fragmented(params->type))2195flags |= IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED;21962197if (iwl_mvm_is_cdb_supported(mvm) &&2198iwl_mvm_is_scan_fragmented(params->hb_type))2199flags |= IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED;22002201if (iwl_mvm_rrm_scan_needed(mvm) &&2202fw_has_capa(&mvm->fw->ucode_capa,2203IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))2204flags |= IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED;22052206if (params->pass_all)2207flags |= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL;2208else2209flags |= IWL_UMAC_SCAN_GEN_FLAGS_MATCH;22102211if (!iwl_mvm_is_regular_scan(params))2212flags |= IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC;22132214if (params->iter_notif)2215flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;22162217#ifdef CONFIG_IWLWIFI_DEBUGFS2218if (mvm->scan_iter_notif_enabled)2219flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;2220#endif22212222if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED)2223flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;22242225if (iwl_mvm_is_adaptive_dwell_supported(mvm) && IWL_MVM_ADWELL_ENABLE)2226flags |= IWL_UMAC_SCAN_GEN_FLAGS_ADAPTIVE_DWELL;22272228/*2229* Extended dwell is relevant only for low band to start with, as it is2230* being used for social channles only (1, 6, 11), so we can check2231* only scan type on low band also for CDB.2232*/2233if (iwl_mvm_is_regular_scan(params) &&2234vif->type != NL80211_IFTYPE_P2P_DEVICE &&2235!iwl_mvm_is_scan_fragmented(params->type) &&2236!iwl_mvm_is_adaptive_dwell_supported(mvm) &&2237!iwl_mvm_is_oce_supported(mvm))2238flags |= IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL;22392240if (iwl_mvm_is_oce_supported(mvm)) {2241if ((params->flags &2242NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE))2243flags |= IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_HIGH_TX_RATE;2244/* Since IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL and2245* NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION shares2246* the same bit, we need to make sure that we use this bit here2247* only when IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL cannot be2248* used. */2249if ((params->flags &2250NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) &&2251!WARN_ON_ONCE(!iwl_mvm_is_adaptive_dwell_supported(mvm)))2252flags |= IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_DEFER_SUPP;2253if ((params->flags & NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME))2254flags |= IWL_UMAC_SCAN_GEN_FLAGS_MAX_CHNL_TIME;2255}22562257return flags;2258}22592260static int2261iwl_mvm_fill_scan_sched_params(struct iwl_mvm_scan_params *params,2262struct iwl_scan_umac_schedule *schedule,2263__le16 *delay)2264{2265int i;2266if (WARN_ON(!params->n_scan_plans ||2267params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))2268return -EINVAL;22692270for (i = 0; i < params->n_scan_plans; i++) {2271struct cfg80211_sched_scan_plan *scan_plan =2272¶ms->scan_plans[i];22732274schedule[i].iter_count = scan_plan->iterations;2275schedule[i].interval =2276cpu_to_le16(scan_plan->interval);2277}22782279/*2280* If the number of iterations of the last scan plan is set to2281* zero, it should run infinitely. However, this is not always the case.2282* For example, when regular scan is requested the driver sets one scan2283* plan with one iteration.2284*/2285if (!schedule[params->n_scan_plans - 1].iter_count)2286schedule[params->n_scan_plans - 1].iter_count = 0xff;22872288*delay = cpu_to_le16(params->delay);22892290return 0;2291}22922293static int iwl_mvm_scan_umac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,2294struct iwl_mvm_scan_params *params,2295int type, int uid)2296{2297struct iwl_scan_req_umac *cmd = mvm->scan_cmd;2298struct iwl_scan_umac_chan_param *chan_param;2299void *cmd_data = iwl_mvm_get_scan_req_umac_data(mvm);2300void *sec_part = (u8 *)cmd_data + sizeof(struct iwl_scan_channel_cfg_umac) *2301mvm->fw->ucode_capa.n_scan_channels;2302struct iwl_scan_req_umac_tail_v2 *tail_v2 =2303(struct iwl_scan_req_umac_tail_v2 *)sec_part;2304struct iwl_scan_req_umac_tail_v1 *tail_v1;2305struct iwl_ssid_ie *direct_scan;2306int ret = 0;2307u32 ssid_bitmap = 0;2308u8 channel_flags = 0;2309u16 gen_flags;2310struct iwl_mvm_vif *scan_vif = iwl_mvm_vif_from_mac80211(vif);23112312chan_param = iwl_mvm_get_scan_req_umac_channel(mvm);23132314iwl_mvm_scan_umac_dwell(mvm, cmd, params);23152316cmd->uid = cpu_to_le32(uid);2317gen_flags = iwl_mvm_scan_umac_flags(mvm, params, vif);2318cmd->general_flags = cpu_to_le16(gen_flags);2319if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm)) {2320if (gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED)2321cmd->v8.num_of_fragments[SCAN_LB_LMAC_IDX] =2322IWL_SCAN_NUM_OF_FRAGS;2323if (gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED)2324cmd->v8.num_of_fragments[SCAN_HB_LMAC_IDX] =2325IWL_SCAN_NUM_OF_FRAGS;23262327cmd->v8.general_flags2 =2328IWL_UMAC_SCAN_GEN_FLAGS2_ALLOW_CHNL_REORDER;2329}23302331cmd->scan_start_mac_id = scan_vif->id;23322333if (type == IWL_MVM_SCAN_SCHED || type == IWL_MVM_SCAN_NETDETECT)2334cmd->flags = cpu_to_le32(IWL_UMAC_SCAN_FLAG_PREEMPTIVE);23352336if (iwl_mvm_scan_use_ebs(mvm, vif)) {2337channel_flags = IWL_SCAN_CHANNEL_FLAG_EBS |2338IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |2339IWL_SCAN_CHANNEL_FLAG_CACHE_ADD;23402341/* set fragmented ebs for fragmented scan on HB channels */2342if (iwl_mvm_is_frag_ebs_supported(mvm)) {2343if (gen_flags &2344IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED ||2345(!iwl_mvm_is_cdb_supported(mvm) &&2346gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED))2347channel_flags |= IWL_SCAN_CHANNEL_FLAG_EBS_FRAG;2348}2349}23502351chan_param->flags = channel_flags;2352chan_param->count = params->n_channels;23532354ret = iwl_mvm_fill_scan_sched_params(params, tail_v2->schedule,2355&tail_v2->delay);2356if (ret)2357return ret;23582359if (iwl_mvm_is_scan_ext_chan_supported(mvm)) {2360tail_v2->preq = params->preq;2361direct_scan = tail_v2->direct_scan;2362} else {2363tail_v1 = (struct iwl_scan_req_umac_tail_v1 *)sec_part;2364iwl_mvm_scan_set_legacy_probe_req(&tail_v1->preq,2365¶ms->preq);2366direct_scan = tail_v1->direct_scan;2367}2368iwl_scan_build_ssids(params, direct_scan, &ssid_bitmap);2369iwl_mvm_umac_scan_cfg_channels(mvm, params->channels,2370params->n_channels, ssid_bitmap,2371cmd_data);2372return 0;2373}23742375static void2376iwl_mvm_scan_umac_fill_general_p_v12(struct iwl_mvm *mvm,2377struct iwl_mvm_scan_params *params,2378struct ieee80211_vif *vif,2379struct iwl_scan_general_params_v11 *gp,2380u16 gen_flags, u8 gen_flags2,2381u32 version)2382{2383struct iwl_mvm_vif *scan_vif = iwl_mvm_vif_from_mac80211(vif);23842385iwl_mvm_scan_umac_dwell_v11(mvm, gp, params);23862387IWL_DEBUG_SCAN(mvm, "General: flags=0x%x, flags2=0x%x\n",2388gen_flags, gen_flags2);23892390gp->flags = cpu_to_le16(gen_flags);2391gp->flags2 = gen_flags2;23922393if (gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_V2_FRAGMENTED_LMAC1)2394gp->num_of_fragments[SCAN_LB_LMAC_IDX] = IWL_SCAN_NUM_OF_FRAGS;2395if (gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_V2_FRAGMENTED_LMAC2)2396gp->num_of_fragments[SCAN_HB_LMAC_IDX] = IWL_SCAN_NUM_OF_FRAGS;23972398mvm->scan_link_id = 0;23992400if (version < 16) {2401gp->scan_start_mac_or_link_id = scan_vif->id;2402} else {2403struct iwl_mvm_vif_link_info *link_info =2404scan_vif->link[params->tsf_report_link_id];24052406mvm->scan_link_id = params->tsf_report_link_id;2407if (!WARN_ON(!link_info))2408gp->scan_start_mac_or_link_id = link_info->fw_link_id;2409}2410}24112412static void2413iwl_mvm_scan_umac_fill_probe_p_v3(struct iwl_mvm_scan_params *params,2414struct iwl_scan_probe_params_v3 *pp)2415{2416pp->preq = params->preq;2417pp->ssid_num = params->n_ssids;2418iwl_scan_build_ssids(params, pp->direct_scan, NULL);2419}24202421static void2422iwl_mvm_scan_umac_fill_probe_p_v4(struct iwl_mvm_scan_params *params,2423struct iwl_scan_probe_params_v4 *pp,2424u32 *bitmap_ssid)2425{2426pp->preq = params->preq;2427iwl_scan_build_ssids(params, pp->direct_scan, bitmap_ssid);2428}24292430static void2431iwl_mvm_scan_umac_fill_ch_p_v4(struct iwl_mvm *mvm,2432struct iwl_mvm_scan_params *params,2433struct ieee80211_vif *vif,2434struct iwl_scan_channel_params_v4 *cp,2435u32 channel_cfg_flags)2436{2437cp->flags = iwl_mvm_scan_umac_chan_flags_v2(mvm, params, vif);2438cp->count = params->n_channels;2439cp->num_of_aps_override = IWL_SCAN_ADWELL_N_APS_GO_FRIENDLY;24402441iwl_mvm_umac_scan_cfg_channels_v4(mvm, params->channels, cp,2442params->n_channels,2443channel_cfg_flags,2444vif->type);2445}24462447static void2448iwl_mvm_scan_umac_fill_ch_p_v7(struct iwl_mvm *mvm,2449struct iwl_mvm_scan_params *params,2450struct ieee80211_vif *vif,2451struct iwl_scan_channel_params_v7 *cp,2452u32 channel_cfg_flags,2453u32 version)2454{2455cp->flags = iwl_mvm_scan_umac_chan_flags_v2(mvm, params, vif);2456cp->count = params->n_channels;2457cp->n_aps_override[0] = IWL_SCAN_ADWELL_N_APS_GO_FRIENDLY;2458cp->n_aps_override[1] = IWL_SCAN_ADWELL_N_APS_SOCIAL_CHS;24592460iwl_mvm_umac_scan_cfg_channels_v7(mvm, params->channels, cp,2461params->n_channels,2462channel_cfg_flags,2463vif->type, version);24642465if (params->enable_6ghz_passive) {2466struct ieee80211_supported_band *sband =2467&mvm->nvm_data->bands[NL80211_BAND_6GHZ];2468u32 i;24692470for (i = 0; i < sband->n_channels; i++) {2471struct ieee80211_channel *channel =2472&sband->channels[i];24732474struct iwl_scan_channel_cfg_umac *cfg =2475&cp->channel_config[cp->count];24762477if (!cfg80211_channel_is_psc(channel))2478continue;24792480cfg->channel_num = channel->hw_value;2481cfg->v5.iter_count = 1;2482cfg->v5.iter_interval = 0;24832484if (version < 17) {2485cfg->flags = 0;2486cfg->v2.band = PHY_BAND_6;2487} else {2488cfg->flags = cpu_to_le32(PHY_BAND_6 <<2489IWL_CHAN_CFG_FLAGS_BAND_POS);2490cfg->v5.psd_20 =2491IEEE80211_RNR_TBTT_PARAMS_PSD_RESERVED;2492}2493cp->count++;2494}2495}2496}24972498static int iwl_mvm_scan_umac_v12(struct iwl_mvm *mvm, struct ieee80211_vif *vif,2499struct iwl_mvm_scan_params *params, int type,2500int uid)2501{2502struct iwl_scan_req_umac_v12 *cmd = mvm->scan_cmd;2503struct iwl_scan_req_params_v12 *scan_p = &cmd->scan_params;2504int ret;2505u16 gen_flags;25062507cmd->ooc_priority = cpu_to_le32(iwl_mvm_scan_umac_ooc_priority(type));2508cmd->uid = cpu_to_le32(uid);25092510gen_flags = iwl_mvm_scan_umac_flags_v2(mvm, params, vif, type);2511iwl_mvm_scan_umac_fill_general_p_v12(mvm, params, vif,2512&scan_p->general_params,2513gen_flags, 0, 12);25142515ret = iwl_mvm_fill_scan_sched_params(params,2516scan_p->periodic_params.schedule,2517&scan_p->periodic_params.delay);2518if (ret)2519return ret;25202521iwl_mvm_scan_umac_fill_probe_p_v3(params, &scan_p->probe_params);2522iwl_mvm_scan_umac_fill_ch_p_v4(mvm, params, vif,2523&scan_p->channel_params, 0);25242525return 0;2526}25272528static int iwl_mvm_scan_umac_v14_and_above(struct iwl_mvm *mvm,2529struct ieee80211_vif *vif,2530struct iwl_mvm_scan_params *params,2531int type, int uid, u32 version)2532{2533struct iwl_scan_req_umac_v17 *cmd = mvm->scan_cmd;2534struct iwl_scan_req_params_v17 *scan_p = &cmd->scan_params;2535struct iwl_scan_channel_params_v7 *cp = &scan_p->channel_params;2536struct iwl_scan_probe_params_v4 *pb = &scan_p->probe_params;2537int ret;2538u16 gen_flags;2539u8 gen_flags2;2540u32 bitmap_ssid = 0;25412542cmd->ooc_priority = cpu_to_le32(iwl_mvm_scan_umac_ooc_priority(type));2543cmd->uid = cpu_to_le32(uid);25442545gen_flags = iwl_mvm_scan_umac_flags_v2(mvm, params, vif, type);25462547if (version >= 15)2548gen_flags2 = iwl_mvm_scan_umac_flags2(mvm, params, vif, type,2549gen_flags);2550else2551gen_flags2 = 0;25522553iwl_mvm_scan_umac_fill_general_p_v12(mvm, params, vif,2554&scan_p->general_params,2555gen_flags, gen_flags2, version);25562557ret = iwl_mvm_fill_scan_sched_params(params,2558scan_p->periodic_params.schedule,2559&scan_p->periodic_params.delay);2560if (ret)2561return ret;25622563if (!params->scan_6ghz) {2564iwl_mvm_scan_umac_fill_probe_p_v4(params,2565&scan_p->probe_params,2566&bitmap_ssid);2567iwl_mvm_scan_umac_fill_ch_p_v7(mvm, params, vif,2568&scan_p->channel_params,2569bitmap_ssid,2570version);2571return 0;2572} else {2573pb->preq = params->preq;2574}25752576cp->flags = iwl_mvm_scan_umac_chan_flags_v2(mvm, params, vif);2577cp->n_aps_override[0] = IWL_SCAN_ADWELL_N_APS_GO_FRIENDLY;2578cp->n_aps_override[1] = IWL_SCAN_ADWELL_N_APS_SOCIAL_CHS;25792580iwl_mvm_umac_scan_fill_6g_chan_list(mvm, params, pb);25812582cp->count = iwl_mvm_umac_scan_cfg_channels_v7_6g(mvm, params,2583params->n_channels,2584pb, cp, vif->type,2585version);2586if (!cp->count)2587return -EINVAL;25882589if (!params->n_ssids ||2590(params->n_ssids == 1 && !params->ssids[0].ssid_len))2591cp->flags |= IWL_SCAN_CHANNEL_FLAG_6G_PSC_NO_FILTER;25922593return 0;2594}25952596static int iwl_mvm_scan_umac_v14(struct iwl_mvm *mvm, struct ieee80211_vif *vif,2597struct iwl_mvm_scan_params *params, int type,2598int uid)2599{2600return iwl_mvm_scan_umac_v14_and_above(mvm, vif, params, type, uid, 14);2601}26022603static int iwl_mvm_scan_umac_v15(struct iwl_mvm *mvm, struct ieee80211_vif *vif,2604struct iwl_mvm_scan_params *params, int type,2605int uid)2606{2607return iwl_mvm_scan_umac_v14_and_above(mvm, vif, params, type, uid, 15);2608}26092610static int iwl_mvm_scan_umac_v16(struct iwl_mvm *mvm, struct ieee80211_vif *vif,2611struct iwl_mvm_scan_params *params, int type,2612int uid)2613{2614return iwl_mvm_scan_umac_v14_and_above(mvm, vif, params, type, uid, 16);2615}26162617static int iwl_mvm_scan_umac_v17(struct iwl_mvm *mvm, struct ieee80211_vif *vif,2618struct iwl_mvm_scan_params *params, int type,2619int uid)2620{2621return iwl_mvm_scan_umac_v14_and_above(mvm, vif, params, type, uid, 17);2622}26232624static int iwl_mvm_num_scans(struct iwl_mvm *mvm)2625{2626return hweight32(mvm->scan_status & IWL_MVM_SCAN_MASK);2627}26282629static int iwl_mvm_check_running_scans(struct iwl_mvm *mvm, int type)2630{2631bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,2632IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);26332634/* This looks a bit arbitrary, but the idea is that if we run2635* out of possible simultaneous scans and the userspace is2636* trying to run a scan type that is already running, we2637* return -EBUSY. But if the userspace wants to start a2638* different type of scan, we stop the opposite type to make2639* space for the new request. The reason is backwards2640* compatibility with old wpa_supplicant that wouldn't stop a2641* scheduled scan before starting a normal scan.2642*/26432644/* FW supports only a single periodic scan */2645if ((type == IWL_MVM_SCAN_SCHED || type == IWL_MVM_SCAN_NETDETECT) &&2646mvm->scan_status & (IWL_MVM_SCAN_SCHED | IWL_MVM_SCAN_NETDETECT))2647return -EBUSY;26482649if (iwl_mvm_num_scans(mvm) < mvm->max_scans)2650return 0;26512652/* Use a switch, even though this is a bitmask, so that more2653* than one bits set will fall in default and we will warn.2654*/2655switch (type) {2656case IWL_MVM_SCAN_REGULAR:2657if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)2658return -EBUSY;2659return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);2660case IWL_MVM_SCAN_SCHED:2661if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)2662return -EBUSY;2663return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);2664case IWL_MVM_SCAN_NETDETECT:2665/* For non-unified images, there's no need to stop2666* anything for net-detect since the firmware is2667* restarted anyway. This way, any sched scans that2668* were running will be restarted when we resume.2669*/2670if (!unified_image)2671return 0;26722673/* If this is a unified image and we ran out of scans,2674* we need to stop something. Prefer stopping regular2675* scans, because the results are useless at this2676* point, and we should be able to keep running2677* another scheduled scan while suspended.2678*/2679if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)2680return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR,2681true);2682if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)2683return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED,2684true);2685/* Something is wrong if no scan was running but we2686* ran out of scans.2687*/2688fallthrough;2689default:2690WARN_ON(1);2691break;2692}26932694return -EIO;2695}26962697#define SCAN_TIMEOUT 3000026982699void iwl_mvm_scan_timeout_wk(struct work_struct *work)2700{2701struct delayed_work *delayed_work = to_delayed_work(work);2702struct iwl_mvm *mvm = container_of(delayed_work, struct iwl_mvm,2703scan_timeout_dwork);27042705IWL_ERR(mvm, "regular scan timed out\n");27062707iwl_force_nmi(mvm->trans);2708}27092710static void iwl_mvm_fill_scan_type(struct iwl_mvm *mvm,2711struct iwl_mvm_scan_params *params,2712struct ieee80211_vif *vif)2713{2714if (iwl_mvm_is_cdb_supported(mvm)) {2715params->type =2716iwl_mvm_get_scan_type_band(mvm, vif,2717NL80211_BAND_2GHZ);2718params->hb_type =2719iwl_mvm_get_scan_type_band(mvm, vif,2720NL80211_BAND_5GHZ);2721} else {2722params->type = iwl_mvm_get_scan_type(mvm, vif);2723}2724}27252726struct iwl_scan_umac_handler {2727u8 version;2728int (*handler)(struct iwl_mvm *mvm, struct ieee80211_vif *vif,2729struct iwl_mvm_scan_params *params, int type, int uid);2730};27312732#define IWL_SCAN_UMAC_HANDLER(_ver) { \2733.version = _ver, \2734.handler = iwl_mvm_scan_umac_v##_ver, \2735}27362737static const struct iwl_scan_umac_handler iwl_scan_umac_handlers[] = {2738/* set the newest version first to shorten the list traverse time */2739IWL_SCAN_UMAC_HANDLER(17),2740IWL_SCAN_UMAC_HANDLER(16),2741IWL_SCAN_UMAC_HANDLER(15),2742IWL_SCAN_UMAC_HANDLER(14),2743IWL_SCAN_UMAC_HANDLER(12),2744};27452746static void iwl_mvm_mei_scan_work(struct work_struct *wk)2747{2748struct iwl_mei_scan_filter *scan_filter =2749container_of(wk, struct iwl_mei_scan_filter, scan_work);2750struct iwl_mvm *mvm =2751container_of(scan_filter, struct iwl_mvm, mei_scan_filter);2752struct iwl_mvm_csme_conn_info *info;2753struct sk_buff *skb;2754u8 bssid[ETH_ALEN];27552756mutex_lock(&mvm->mutex);2757info = iwl_mvm_get_csme_conn_info(mvm);2758memcpy(bssid, info->conn_info.bssid, ETH_ALEN);2759mutex_unlock(&mvm->mutex);27602761while ((skb = skb_dequeue(&scan_filter->scan_res))) {2762struct ieee80211_mgmt *mgmt = (void *)skb->data;27632764if (!memcmp(mgmt->bssid, bssid, ETH_ALEN))2765ieee80211_rx_irqsafe(mvm->hw, skb);2766else2767kfree_skb(skb);2768}2769}27702771void iwl_mvm_mei_scan_filter_init(struct iwl_mei_scan_filter *mei_scan_filter)2772{2773skb_queue_head_init(&mei_scan_filter->scan_res);2774INIT_WORK(&mei_scan_filter->scan_work, iwl_mvm_mei_scan_work);2775}27762777/* In case CSME is connected and has link protection set, this function will2778* override the scan request to scan only the associated channel and only for2779* the associated SSID.2780*/2781static void iwl_mvm_mei_limited_scan(struct iwl_mvm *mvm,2782struct iwl_mvm_scan_params *params)2783{2784struct iwl_mvm_csme_conn_info *info = iwl_mvm_get_csme_conn_info(mvm);2785struct iwl_mei_conn_info *conn_info;2786struct ieee80211_channel *chan;2787int scan_iters, i;27882789if (!info) {2790IWL_DEBUG_SCAN(mvm, "mei_limited_scan: no connection info\n");2791return;2792}27932794conn_info = &info->conn_info;2795if (!info->conn_info.lp_state || !info->conn_info.ssid_len)2796return;27972798if (!params->n_channels || !params->n_ssids)2799return;28002801mvm->mei_scan_filter.is_mei_limited_scan = true;28022803chan = ieee80211_get_channel(mvm->hw->wiphy,2804ieee80211_channel_to_frequency(conn_info->channel,2805conn_info->band));2806if (!chan) {2807IWL_DEBUG_SCAN(mvm,2808"Failed to get CSME channel (chan=%u band=%u)\n",2809conn_info->channel, conn_info->band);2810return;2811}28122813/* The mei filtered scan must find the AP, otherwise CSME will2814* take the NIC ownership. Add several iterations on the channel to2815* make the scan more robust.2816*/2817scan_iters = min(IWL_MEI_SCAN_NUM_ITER, params->n_channels);2818params->n_channels = scan_iters;2819for (i = 0; i < scan_iters; i++)2820params->channels[i] = chan;28212822IWL_DEBUG_SCAN(mvm, "Mei scan: num iterations=%u\n", scan_iters);28232824params->n_ssids = 1;2825params->ssids[0].ssid_len = conn_info->ssid_len;2826memcpy(params->ssids[0].ssid, conn_info->ssid, conn_info->ssid_len);2827}28282829static int iwl_mvm_build_scan_cmd(struct iwl_mvm *mvm,2830struct ieee80211_vif *vif,2831struct iwl_host_cmd *hcmd,2832struct iwl_mvm_scan_params *params,2833int type)2834{2835int uid, i, err;2836u8 scan_ver;28372838lockdep_assert_held(&mvm->mutex);2839memset(mvm->scan_cmd, 0, mvm->scan_cmd_size);28402841iwl_mvm_mei_limited_scan(mvm, params);28422843if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {2844hcmd->id = SCAN_OFFLOAD_REQUEST_CMD;28452846return iwl_mvm_scan_lmac(mvm, vif, params);2847}28482849uid = iwl_mvm_scan_uid_by_status(mvm, 0);2850if (uid < 0)2851return uid;28522853hcmd->id = WIDE_ID(IWL_ALWAYS_LONG_GROUP, SCAN_REQ_UMAC);28542855scan_ver = iwl_fw_lookup_cmd_ver(mvm->fw, SCAN_REQ_UMAC,2856IWL_FW_CMD_VER_UNKNOWN);28572858for (i = 0; i < ARRAY_SIZE(iwl_scan_umac_handlers); i++) {2859const struct iwl_scan_umac_handler *ver_handler =2860&iwl_scan_umac_handlers[i];28612862if (ver_handler->version != scan_ver)2863continue;28642865err = ver_handler->handler(mvm, vif, params, type, uid);2866return err ? : uid;2867}28682869err = iwl_mvm_scan_umac(mvm, vif, params, type, uid);2870if (err)2871return err;28722873return uid;2874}28752876struct iwl_mvm_scan_respect_p2p_go_iter_data {2877struct ieee80211_vif *current_vif;2878bool p2p_go;2879enum nl80211_band band;2880};28812882static void iwl_mvm_scan_respect_p2p_go_iter(void *_data, u8 *mac,2883struct ieee80211_vif *vif)2884{2885struct iwl_mvm_scan_respect_p2p_go_iter_data *data = _data;2886struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);28872888/* exclude the given vif */2889if (vif == data->current_vif)2890return;28912892if (ieee80211_vif_type_p2p(vif) == NL80211_IFTYPE_P2P_GO) {2893u32 link_id;28942895for (link_id = 0;2896link_id < ARRAY_SIZE(mvmvif->link);2897link_id++) {2898struct iwl_mvm_vif_link_info *link =2899mvmvif->link[link_id];29002901if (link && link->phy_ctxt->id < NUM_PHY_CTX &&2902(data->band == NUM_NL80211_BANDS ||2903link->phy_ctxt->channel->band == data->band)) {2904data->p2p_go = true;2905break;2906}2907}2908}2909}29102911static bool _iwl_mvm_get_respect_p2p_go(struct iwl_mvm *mvm,2912struct ieee80211_vif *vif,2913bool low_latency,2914enum nl80211_band band)2915{2916struct iwl_mvm_scan_respect_p2p_go_iter_data data = {2917.current_vif = vif,2918.p2p_go = false,2919.band = band,2920};29212922if (!low_latency)2923return false;29242925ieee80211_iterate_active_interfaces_atomic(mvm->hw,2926IEEE80211_IFACE_ITER_NORMAL,2927iwl_mvm_scan_respect_p2p_go_iter,2928&data);29292930return data.p2p_go;2931}29322933static bool iwl_mvm_get_respect_p2p_go_band(struct iwl_mvm *mvm,2934struct ieee80211_vif *vif,2935enum nl80211_band band)2936{2937bool low_latency = iwl_mvm_low_latency_band(mvm, band);29382939return _iwl_mvm_get_respect_p2p_go(mvm, vif, low_latency, band);2940}29412942static bool iwl_mvm_get_respect_p2p_go(struct iwl_mvm *mvm,2943struct ieee80211_vif *vif)2944{2945bool low_latency = iwl_mvm_low_latency(mvm);29462947return _iwl_mvm_get_respect_p2p_go(mvm, vif, low_latency,2948NUM_NL80211_BANDS);2949}29502951static void iwl_mvm_fill_respect_p2p_go(struct iwl_mvm *mvm,2952struct iwl_mvm_scan_params *params,2953struct ieee80211_vif *vif)2954{2955if (iwl_mvm_is_cdb_supported(mvm)) {2956params->respect_p2p_go =2957iwl_mvm_get_respect_p2p_go_band(mvm, vif,2958NL80211_BAND_2GHZ);2959params->respect_p2p_go_hb =2960iwl_mvm_get_respect_p2p_go_band(mvm, vif,2961NL80211_BAND_5GHZ);2962} else {2963params->respect_p2p_go = iwl_mvm_get_respect_p2p_go(mvm, vif);2964}2965}29662967static int _iwl_mvm_single_scan_start(struct iwl_mvm *mvm,2968struct ieee80211_vif *vif,2969struct cfg80211_scan_request *req,2970struct ieee80211_scan_ies *ies,2971int type)2972{2973struct iwl_host_cmd hcmd = {2974.len = { iwl_mvm_scan_size(mvm), },2975.data = { mvm->scan_cmd, },2976.dataflags = { IWL_HCMD_DFL_NOCOPY, },2977};2978struct iwl_mvm_scan_params params = {};2979int ret, uid;2980struct cfg80211_sched_scan_plan scan_plan = { .iterations = 1 };29812982lockdep_assert_held(&mvm->mutex);29832984if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {2985IWL_ERR(mvm, "scan while LAR regdomain is not set\n");2986return -EBUSY;2987}29882989ret = iwl_mvm_check_running_scans(mvm, type);2990if (ret)2991return ret;29922993/* we should have failed registration if scan_cmd was NULL */2994if (WARN_ON(!mvm->scan_cmd))2995return -ENOMEM;29962997if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))2998return -ENOBUFS;29993000params.n_ssids = req->n_ssids;3001params.flags = req->flags;3002params.n_channels = req->n_channels;3003params.delay = 0;3004params.ssids = req->ssids;3005params.channels = req->channels;3006params.mac_addr = req->mac_addr;3007params.mac_addr_mask = req->mac_addr_mask;3008params.no_cck = req->no_cck;3009params.pass_all = true;3010params.n_match_sets = 0;3011params.match_sets = NULL;3012ether_addr_copy(params.bssid, req->bssid);30133014params.scan_plans = &scan_plan;3015params.n_scan_plans = 1;30163017params.n_6ghz_params = req->n_6ghz_params;3018params.scan_6ghz_params = req->scan_6ghz_params;3019params.scan_6ghz = req->scan_6ghz;3020iwl_mvm_fill_scan_type(mvm, ¶ms, vif);3021iwl_mvm_fill_respect_p2p_go(mvm, ¶ms, vif);30223023if (req->duration)3024params.iter_notif = true;30253026params.tsf_report_link_id = req->tsf_report_link_id;3027if (params.tsf_report_link_id < 0) {3028if (vif->active_links)3029params.tsf_report_link_id = __ffs(vif->active_links);3030else3031params.tsf_report_link_id = 0;3032}30333034iwl_mvm_build_scan_probe(mvm, vif, ies, ¶ms);30353036iwl_mvm_scan_6ghz_passive_scan(mvm, ¶ms, vif);30373038uid = iwl_mvm_build_scan_cmd(mvm, vif, &hcmd, ¶ms, type);30393040if (uid < 0)3041return uid;30423043iwl_mvm_pause_tcm(mvm, false);30443045ret = iwl_mvm_send_cmd(mvm, &hcmd);3046if (ret) {3047/* If the scan failed, it usually means that the FW was unable3048* to allocate the time events. Warn on it, but maybe we3049* should try to send the command again with different params.3050*/3051IWL_ERR(mvm, "Scan failed! ret %d\n", ret);3052iwl_mvm_resume_tcm(mvm);3053return ret;3054}30553056IWL_DEBUG_SCAN(mvm, "Scan request send success: type=%u, uid=%u\n",3057type, uid);30583059mvm->scan_uid_status[uid] = type;3060mvm->scan_status |= type;30613062if (type == IWL_MVM_SCAN_REGULAR) {3063mvm->scan_vif = iwl_mvm_vif_from_mac80211(vif);3064schedule_delayed_work(&mvm->scan_timeout_dwork,3065msecs_to_jiffies(SCAN_TIMEOUT));3066}30673068if (params.enable_6ghz_passive)3069mvm->last_6ghz_passive_scan_jiffies = jiffies;30703071return 0;3072}30733074int iwl_mvm_reg_scan_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,3075struct cfg80211_scan_request *req,3076struct ieee80211_scan_ies *ies)3077{3078return _iwl_mvm_single_scan_start(mvm, vif, req, ies,3079IWL_MVM_SCAN_REGULAR);3080}30813082int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,3083struct ieee80211_vif *vif,3084struct cfg80211_sched_scan_request *req,3085struct ieee80211_scan_ies *ies,3086int type)3087{3088struct iwl_host_cmd hcmd = {3089.len = { iwl_mvm_scan_size(mvm), },3090.data = { mvm->scan_cmd, },3091.dataflags = { IWL_HCMD_DFL_NOCOPY, },3092};3093struct iwl_mvm_scan_params params = {};3094int ret, uid;3095int i, j;3096bool non_psc_included = false;30973098lockdep_assert_held(&mvm->mutex);30993100if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {3101IWL_ERR(mvm, "sched-scan while LAR regdomain is not set\n");3102return -EBUSY;3103}31043105ret = iwl_mvm_check_running_scans(mvm, type);3106if (ret)3107return ret;31083109/* we should have failed registration if scan_cmd was NULL */3110if (WARN_ON(!mvm->scan_cmd))3111return -ENOMEM;311231133114params.n_ssids = req->n_ssids;3115params.flags = req->flags;3116params.n_channels = req->n_channels;3117params.ssids = req->ssids;3118params.channels = req->channels;3119params.mac_addr = req->mac_addr;3120params.mac_addr_mask = req->mac_addr_mask;3121params.no_cck = false;3122params.pass_all = iwl_mvm_scan_pass_all(mvm, req);3123params.n_match_sets = req->n_match_sets;3124params.match_sets = req->match_sets;3125eth_broadcast_addr(params.bssid);3126if (!req->n_scan_plans)3127return -EINVAL;31283129params.n_scan_plans = req->n_scan_plans;3130params.scan_plans = req->scan_plans;31313132iwl_mvm_fill_scan_type(mvm, ¶ms, vif);3133iwl_mvm_fill_respect_p2p_go(mvm, ¶ms, vif);31343135/* In theory, LMAC scans can handle a 32-bit delay, but since3136* waiting for over 18 hours to start the scan is a bit silly3137* and to keep it aligned with UMAC scans (which only support3138* 16-bit delays), trim it down to 16-bits.3139*/3140if (req->delay > U16_MAX) {3141IWL_DEBUG_SCAN(mvm,3142"delay value is > 16-bits, set to max possible\n");3143params.delay = U16_MAX;3144} else {3145params.delay = req->delay;3146}31473148ret = iwl_mvm_config_sched_scan_profiles(mvm, req);3149if (ret)3150return ret;31513152iwl_mvm_build_scan_probe(mvm, vif, ies, ¶ms);31533154/* for 6 GHZ band only PSC channels need to be added */3155for (i = 0; i < params.n_channels; i++) {3156struct ieee80211_channel *channel = params.channels[i];31573158if (channel->band == NL80211_BAND_6GHZ &&3159!cfg80211_channel_is_psc(channel)) {3160non_psc_included = true;3161break;3162}3163}31643165if (non_psc_included) {3166params.channels = kmemdup(params.channels,3167sizeof(params.channels[0]) *3168params.n_channels,3169GFP_KERNEL);3170if (!params.channels)3171return -ENOMEM;31723173for (i = j = 0; i < params.n_channels; i++) {3174if (params.channels[i]->band == NL80211_BAND_6GHZ &&3175!cfg80211_channel_is_psc(params.channels[i]))3176continue;3177params.channels[j++] = params.channels[i];3178}3179params.n_channels = j;3180}31813182if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, params.n_channels)) {3183ret = -ENOBUFS;3184goto out;3185}31863187uid = iwl_mvm_build_scan_cmd(mvm, vif, &hcmd, ¶ms, type);3188if (uid < 0) {3189ret = uid;3190goto out;3191}31923193ret = iwl_mvm_send_cmd(mvm, &hcmd);3194if (!ret) {3195IWL_DEBUG_SCAN(mvm,3196"Sched scan request send success: type=%u, uid=%u\n",3197type, uid);3198mvm->scan_uid_status[uid] = type;3199mvm->scan_status |= type;3200} else {3201/* If the scan failed, it usually means that the FW was unable3202* to allocate the time events. Warn on it, but maybe we3203* should try to send the command again with different params.3204*/3205IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret);3206mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;3207}32083209out:3210if (non_psc_included)3211kfree(params.channels);3212return ret;3213}32143215void iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,3216struct iwl_rx_cmd_buffer *rxb)3217{3218struct iwl_rx_packet *pkt = rxb_addr(rxb);3219struct iwl_umac_scan_complete *notif = (void *)pkt->data;3220u32 uid = __le32_to_cpu(notif->uid);3221bool aborted = (notif->status == IWL_SCAN_OFFLOAD_ABORTED);3222bool select_links = false;32233224mvm->mei_scan_filter.is_mei_limited_scan = false;32253226IWL_DEBUG_SCAN(mvm,3227"Scan completed: uid=%u type=%u, status=%s, EBS=%s\n",3228uid, mvm->scan_uid_status[uid],3229notif->status == IWL_SCAN_OFFLOAD_COMPLETED ?3230"completed" : "aborted",3231iwl_mvm_ebs_status_str(notif->ebs_status));32323233IWL_DEBUG_SCAN(mvm, "Scan completed: scan_status=0x%x\n",3234mvm->scan_status);32353236IWL_DEBUG_SCAN(mvm,3237"Scan completed: line=%u, iter=%u, elapsed time=%u\n",3238notif->last_schedule, notif->last_iter,3239__le32_to_cpu(notif->time_from_last_iter));32403241if (WARN_ON(!(mvm->scan_uid_status[uid] & mvm->scan_status)))3242return;32433244/* if the scan is already stopping, we don't need to notify mac80211 */3245if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_REGULAR) {3246struct cfg80211_scan_info info = {3247.aborted = aborted,3248.scan_start_tsf = mvm->scan_start,3249};3250struct iwl_mvm_vif *scan_vif = mvm->scan_vif;3251struct iwl_mvm_vif_link_info *link_info =3252scan_vif->link[mvm->scan_link_id];32533254/* It is possible that by the time the scan is complete the link3255* was already removed and is not valid.3256*/3257if (link_info)3258memcpy(info.tsf_bssid, link_info->bssid, ETH_ALEN);3259else3260IWL_DEBUG_SCAN(mvm, "Scan link is no longer valid\n");32613262ieee80211_scan_completed(mvm->hw, &info);3263mvm->scan_vif = NULL;3264cancel_delayed_work(&mvm->scan_timeout_dwork);3265iwl_mvm_resume_tcm(mvm);3266} else if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_SCHED) {3267ieee80211_sched_scan_stopped(mvm->hw);3268mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;3269} else if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_INT_MLO) {3270IWL_DEBUG_SCAN(mvm, "Internal MLO scan completed\n");3271/*3272* Other scan types won't necessarily scan for the MLD links channels.3273* Therefore, only select links after successful internal scan.3274*/3275select_links = notif->status == IWL_SCAN_OFFLOAD_COMPLETED;3276}32773278mvm->scan_status &= ~mvm->scan_uid_status[uid];32793280IWL_DEBUG_SCAN(mvm, "Scan completed: after update: scan_status=0x%x\n",3281mvm->scan_status);32823283if (notif->ebs_status != IWL_SCAN_EBS_SUCCESS &&3284notif->ebs_status != IWL_SCAN_EBS_INACTIVE)3285mvm->last_ebs_successful = false;32863287mvm->scan_uid_status[uid] = 0;32883289if (select_links)3290wiphy_work_queue(mvm->hw->wiphy, &mvm->trig_link_selection_wk);3291}32923293void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm,3294struct iwl_rx_cmd_buffer *rxb)3295{3296struct iwl_rx_packet *pkt = rxb_addr(rxb);3297struct iwl_umac_scan_iter_complete_notif *notif = (void *)pkt->data;32983299mvm->scan_start = le64_to_cpu(notif->start_tsf);33003301IWL_DEBUG_SCAN(mvm,3302"UMAC Scan iteration complete: status=0x%x scanned_channels=%d\n",3303notif->status, notif->scanned_channels);33043305if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_FOUND) {3306IWL_DEBUG_SCAN(mvm, "Pass all scheduled scan results found\n");3307ieee80211_sched_scan_results(mvm->hw);3308mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_ENABLED;3309}33103311IWL_DEBUG_SCAN(mvm,3312"UMAC Scan iteration complete: scan started at %llu (TSF)\n",3313mvm->scan_start);3314}33153316static int iwl_mvm_umac_scan_abort(struct iwl_mvm *mvm, int type, bool *wait)3317{3318struct iwl_umac_scan_abort abort_cmd = {};3319struct iwl_host_cmd cmd = {3320.id = WIDE_ID(IWL_ALWAYS_LONG_GROUP, SCAN_ABORT_UMAC),3321.len = { sizeof(abort_cmd), },3322.data = { &abort_cmd, },3323.flags = CMD_SEND_IN_RFKILL,3324};33253326int uid, ret;3327u32 status = IWL_UMAC_SCAN_ABORT_STATUS_NOT_FOUND;33283329lockdep_assert_held(&mvm->mutex);33303331*wait = true;33323333/* We should always get a valid index here, because we already3334* checked that this type of scan was running in the generic3335* code.3336*/3337uid = iwl_mvm_scan_uid_by_status(mvm, type);3338if (WARN_ON_ONCE(uid < 0))3339return uid;33403341abort_cmd.uid = cpu_to_le32(uid);33423343IWL_DEBUG_SCAN(mvm, "Sending scan abort, uid %u\n", uid);33443345ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status);33463347IWL_DEBUG_SCAN(mvm, "Scan abort: ret=%d, status=%u\n", ret, status);3348if (!ret)3349mvm->scan_uid_status[uid] = type << IWL_MVM_SCAN_STOPPING_SHIFT;33503351/* Handle the case that the FW is no longer familiar with the scan that3352* is to be stopped. In such a case, it is expected that the scan3353* complete notification was already received but not yet processed.3354* In such a case, there is no need to wait for a scan complete3355* notification and the flow should continue similar to the case that3356* the scan was really aborted.3357*/3358if (status == IWL_UMAC_SCAN_ABORT_STATUS_NOT_FOUND) {3359mvm->scan_uid_status[uid] = type << IWL_MVM_SCAN_STOPPING_SHIFT;3360*wait = false;3361}33623363return ret;3364}33653366static int iwl_mvm_scan_stop_wait(struct iwl_mvm *mvm, int type)3367{3368struct iwl_notification_wait wait_scan_done;3369static const u16 scan_done_notif[] = { SCAN_COMPLETE_UMAC,3370SCAN_OFFLOAD_COMPLETE, };3371int ret;3372bool wait = true;33733374lockdep_assert_held(&mvm->mutex);33753376iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,3377scan_done_notif,3378ARRAY_SIZE(scan_done_notif),3379NULL, NULL);33803381IWL_DEBUG_SCAN(mvm, "Preparing to stop scan, type %x\n", type);33823383if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))3384ret = iwl_mvm_umac_scan_abort(mvm, type, &wait);3385else3386ret = iwl_mvm_lmac_scan_abort(mvm);33873388if (ret) {3389IWL_DEBUG_SCAN(mvm, "couldn't stop scan type %d\n", type);3390iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);3391return ret;3392} else if (!wait) {3393IWL_DEBUG_SCAN(mvm, "no need to wait for scan type %d\n", type);3394iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);3395return 0;3396}33973398return iwl_wait_notification(&mvm->notif_wait, &wait_scan_done,33991 * HZ);3400}34013402static size_t iwl_scan_req_umac_get_size(u8 scan_ver)3403{3404switch (scan_ver) {3405case 12:3406return sizeof(struct iwl_scan_req_umac_v12);3407case 14:3408case 15:3409case 16:3410case 17:3411return sizeof(struct iwl_scan_req_umac_v17);3412}34133414return 0;3415}34163417size_t iwl_mvm_scan_size(struct iwl_mvm *mvm)3418{3419int base_size, tail_size;3420u8 scan_ver = iwl_fw_lookup_cmd_ver(mvm->fw, SCAN_REQ_UMAC,3421IWL_FW_CMD_VER_UNKNOWN);34223423base_size = iwl_scan_req_umac_get_size(scan_ver);3424if (base_size)3425return base_size;342634273428if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm))3429base_size = IWL_SCAN_REQ_UMAC_SIZE_V8;3430else if (iwl_mvm_is_adaptive_dwell_supported(mvm))3431base_size = IWL_SCAN_REQ_UMAC_SIZE_V7;3432else if (iwl_mvm_cdb_scan_api(mvm))3433base_size = IWL_SCAN_REQ_UMAC_SIZE_V6;3434else3435base_size = IWL_SCAN_REQ_UMAC_SIZE_V1;34363437if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {3438if (iwl_mvm_is_scan_ext_chan_supported(mvm))3439tail_size = sizeof(struct iwl_scan_req_umac_tail_v2);3440else3441tail_size = sizeof(struct iwl_scan_req_umac_tail_v1);34423443return base_size +3444sizeof(struct iwl_scan_channel_cfg_umac) *3445mvm->fw->ucode_capa.n_scan_channels +3446tail_size;3447}3448return sizeof(struct iwl_scan_req_lmac) +3449sizeof(struct iwl_scan_channel_cfg_lmac) *3450mvm->fw->ucode_capa.n_scan_channels +3451sizeof(struct iwl_scan_probe_req_v1);3452}34533454/*3455* This function is used in nic restart flow, to inform mac80211 about scans3456* that was aborted by restart flow or by an assert.3457*/3458void iwl_mvm_report_scan_aborted(struct iwl_mvm *mvm)3459{3460if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {3461int uid, i;34623463uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_REGULAR);3464if (uid >= 0) {3465struct cfg80211_scan_info info = {3466.aborted = true,3467};34683469cancel_delayed_work(&mvm->scan_timeout_dwork);34703471ieee80211_scan_completed(mvm->hw, &info);3472mvm->scan_uid_status[uid] = 0;3473}3474uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_SCHED);3475if (uid >= 0) {3476/* Sched scan will be restarted by mac80211 in3477* restart_hw, so do not report if FW is about to be3478* restarted.3479*/3480if (!iwlwifi_mod_params.fw_restart)3481ieee80211_sched_scan_stopped(mvm->hw);3482mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;3483mvm->scan_uid_status[uid] = 0;3484}3485uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_INT_MLO);3486if (uid >= 0) {3487IWL_DEBUG_SCAN(mvm, "Internal MLO scan aborted\n");3488mvm->scan_uid_status[uid] = 0;3489}34903491uid = iwl_mvm_scan_uid_by_status(mvm,3492IWL_MVM_SCAN_STOPPING_REGULAR);3493if (uid >= 0)3494mvm->scan_uid_status[uid] = 0;34953496uid = iwl_mvm_scan_uid_by_status(mvm,3497IWL_MVM_SCAN_STOPPING_SCHED);3498if (uid >= 0)3499mvm->scan_uid_status[uid] = 0;35003501uid = iwl_mvm_scan_uid_by_status(mvm,3502IWL_MVM_SCAN_STOPPING_INT_MLO);3503if (uid >= 0)3504mvm->scan_uid_status[uid] = 0;35053506/* We shouldn't have any UIDs still set. Loop over all the3507* UIDs to make sure there's nothing left there and warn if3508* any is found.3509*/3510for (i = 0; i < mvm->max_scans; i++) {3511if (WARN_ONCE(mvm->scan_uid_status[i],3512"UMAC scan UID %d status was not cleaned\n",3513i))3514mvm->scan_uid_status[i] = 0;3515}3516} else {3517if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) {3518struct cfg80211_scan_info info = {3519.aborted = true,3520};35213522cancel_delayed_work(&mvm->scan_timeout_dwork);3523ieee80211_scan_completed(mvm->hw, &info);3524}35253526/* Sched scan will be restarted by mac80211 in3527* restart_hw, so do not report if FW is about to be3528* restarted.3529*/3530if ((mvm->scan_status & IWL_MVM_SCAN_SCHED) &&3531!iwlwifi_mod_params.fw_restart) {3532ieee80211_sched_scan_stopped(mvm->hw);3533mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;3534}3535}3536}35373538int iwl_mvm_scan_stop(struct iwl_mvm *mvm, int type, bool notify)3539{3540int ret;35413542IWL_DEBUG_SCAN(mvm,3543"Request to stop scan: type=0x%x, status=0x%x\n",3544type, mvm->scan_status);35453546if (!(mvm->scan_status & type))3547return 0;35483549if (!iwl_trans_device_enabled(mvm->trans)) {3550ret = 0;3551goto out;3552}35533554ret = iwl_mvm_scan_stop_wait(mvm, type);3555if (!ret)3556mvm->scan_status |= type << IWL_MVM_SCAN_STOPPING_SHIFT;3557else3558IWL_DEBUG_SCAN(mvm, "Failed to stop scan\n");35593560out:3561/* Clear the scan status so the next scan requests will3562* succeed and mark the scan as stopping, so that the Rx3563* handler doesn't do anything, as the scan was stopped from3564* above.3565*/3566mvm->scan_status &= ~type;35673568if (type == IWL_MVM_SCAN_REGULAR) {3569cancel_delayed_work(&mvm->scan_timeout_dwork);3570if (notify) {3571struct cfg80211_scan_info info = {3572.aborted = true,3573};35743575ieee80211_scan_completed(mvm->hw, &info);3576}3577} else if (notify) {3578ieee80211_sched_scan_stopped(mvm->hw);3579mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;3580}35813582return ret;3583}35843585static int iwl_mvm_int_mlo_scan_start(struct iwl_mvm *mvm,3586struct ieee80211_vif *vif,3587struct ieee80211_channel **channels,3588size_t n_channels)3589{3590struct cfg80211_scan_request *req = NULL;3591struct ieee80211_scan_ies ies = {};3592size_t size, i;3593int ret;35943595lockdep_assert_held(&mvm->mutex);35963597IWL_DEBUG_SCAN(mvm, "Starting Internal MLO scan: n_channels=%zu\n",3598n_channels);35993600if (!vif->cfg.assoc || !ieee80211_vif_is_mld(vif) ||3601hweight16(vif->valid_links) == 1)3602return -EINVAL;36033604size = struct_size(req, channels, n_channels);3605req = kzalloc(size, GFP_KERNEL);3606if (!req)3607return -ENOMEM;36083609/* set the requested channels */3610for (i = 0; i < n_channels; i++)3611req->channels[i] = channels[i];36123613req->n_channels = n_channels;36143615/* set the rates */3616for (i = 0; i < NUM_NL80211_BANDS; i++)3617if (mvm->hw->wiphy->bands[i])3618req->rates[i] =3619(1 << mvm->hw->wiphy->bands[i]->n_bitrates) - 1;36203621req->wdev = ieee80211_vif_to_wdev(vif);3622req->wiphy = mvm->hw->wiphy;3623req->scan_start = jiffies;3624req->tsf_report_link_id = -1;36253626ret = _iwl_mvm_single_scan_start(mvm, vif, req, &ies,3627IWL_MVM_SCAN_INT_MLO);3628kfree(req);36293630IWL_DEBUG_SCAN(mvm, "Internal MLO scan: ret=%d\n", ret);3631return ret;3632}36333634int iwl_mvm_int_mlo_scan(struct iwl_mvm *mvm, struct ieee80211_vif *vif)3635{3636struct ieee80211_channel *channels[IEEE80211_MLD_MAX_NUM_LINKS];3637unsigned long usable_links = ieee80211_vif_usable_links(vif);3638size_t n_channels = 0;3639u8 link_id;36403641lockdep_assert_held(&mvm->mutex);36423643if (mvm->scan_status & IWL_MVM_SCAN_INT_MLO) {3644IWL_DEBUG_SCAN(mvm, "Internal MLO scan is already running\n");3645return -EBUSY;3646}36473648rcu_read_lock();36493650for_each_set_bit(link_id, &usable_links, IEEE80211_MLD_MAX_NUM_LINKS) {3651struct ieee80211_bss_conf *link_conf =3652rcu_dereference(vif->link_conf[link_id]);36533654if (WARN_ON_ONCE(!link_conf))3655continue;36563657channels[n_channels++] = link_conf->chanreq.oper.chan;3658}36593660rcu_read_unlock();36613662if (!n_channels)3663return -EINVAL;36643665return iwl_mvm_int_mlo_scan_start(mvm, vif, channels, n_channels);3666}36673668static int iwl_mvm_chanidx_from_phy(struct iwl_mvm *mvm,3669enum nl80211_band band,3670u16 phy_chan_num)3671{3672struct ieee80211_supported_band *sband = mvm->hw->wiphy->bands[band];3673int chan_idx;36743675if (WARN_ON_ONCE(!sband))3676return -EINVAL;36773678for (chan_idx = 0; chan_idx < sband->n_channels; chan_idx++) {3679struct ieee80211_channel *channel = &sband->channels[chan_idx];36803681if (channel->hw_value == phy_chan_num)3682return chan_idx;3683}36843685return -EINVAL;3686}36873688void iwl_mvm_rx_channel_survey_notif(struct iwl_mvm *mvm,3689struct iwl_rx_cmd_buffer *rxb)3690{3691struct iwl_rx_packet *pkt = rxb_addr(rxb);3692const struct iwl_umac_scan_channel_survey_notif *notif =3693(void *)pkt->data;3694struct iwl_mvm_acs_survey_channel *info;3695enum nl80211_band band;3696int chan_idx;36973698lockdep_assert_held(&mvm->mutex);36993700if (!mvm->acs_survey) {3701size_t n_channels = 0;37023703for (band = 0; band < NUM_NL80211_BANDS; band++) {3704if (!mvm->hw->wiphy->bands[band])3705continue;37063707n_channels += mvm->hw->wiphy->bands[band]->n_channels;3708}37093710mvm->acs_survey = kzalloc(struct_size(mvm->acs_survey,3711channels, n_channels),3712GFP_KERNEL);37133714if (!mvm->acs_survey)3715return;37163717mvm->acs_survey->n_channels = n_channels;3718n_channels = 0;3719for (band = 0; band < NUM_NL80211_BANDS; band++) {3720if (!mvm->hw->wiphy->bands[band])3721continue;37223723mvm->acs_survey->bands[band] =3724&mvm->acs_survey->channels[n_channels];3725n_channels += mvm->hw->wiphy->bands[band]->n_channels;3726}3727}37283729band = iwl_mvm_nl80211_band_from_phy(le32_to_cpu(notif->band));3730chan_idx = iwl_mvm_chanidx_from_phy(mvm, band,3731le32_to_cpu(notif->channel));3732if (WARN_ON_ONCE(chan_idx < 0))3733return;37343735IWL_DEBUG_SCAN(mvm, "channel survey received for freq %d\n",3736mvm->hw->wiphy->bands[band]->channels[chan_idx].center_freq);37373738info = &mvm->acs_survey->bands[band][chan_idx];37393740/* Times are all in ms */3741info->time = le32_to_cpu(notif->active_time);3742info->time_busy = le32_to_cpu(notif->busy_time);3743info->time_rx = le32_to_cpu(notif->rx_time);3744info->time_tx = le32_to_cpu(notif->tx_time);3745info->noise =3746iwl_average_neg_dbm(notif->noise, ARRAY_SIZE(notif->noise));3747}374837493750