File Index
Files and directories
Sign in
FILE

mvm.h

File preview with syntax highlighting.

linux-6.19.14/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h C
   1/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
   2/*
   3 * Copyright (C) 2012-2014, 2018-2025 Intel Corporation
   4 * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
   5 * Copyright (C) 2016-2017 Intel Deutschland GmbH
   6 */
   7#ifndef __IWL_MVM_H__
   8#define __IWL_MVM_H__
   9
  10#include <linux/list.h>
  11#include <linux/spinlock.h>
  12#include <linux/cleanup.h>
  13#include <linux/leds.h>
  14#include <linux/in6.h>
  15
  16#ifdef CONFIG_THERMAL
  17#include <linux/thermal.h>
  18#endif
  19
  20#include <linux/ptp_clock_kernel.h>
  21
  22#include <linux/ktime.h>
  23
  24#include "iwl-op-mode.h"
  25#include "iwl-trans.h"
  26#include "fw/notif-wait.h"
  27#include "iwl-nvm-utils.h"
  28#include "fw/file.h"
  29#include "iwl-config.h"
  30#include "sta.h"
  31#include "fw-api.h"
  32#include "constants.h"
  33#include "fw/runtime.h"
  34#include "fw/dbg.h"
  35#include "fw/acpi.h"
  36#include "mei/iwl-mei.h"
  37#include "iwl-nvm-parse.h"
  38
  39#include <linux/average.h>
  40
  41#define IWL_MVM_MAX_ADDRESSES		5
  42/* RSSI offset for WkP */
  43#define IWL_RSSI_OFFSET 50
  44#define IWL_MVM_MISSED_BEACONS_SINCE_RX_THOLD 4
  45#define IWL_MVM_MISSED_BEACONS_THRESHOLD 8
  46#define IWL_MVM_MISSED_BEACONS_THRESHOLD_LONG 19
  47
  48/* A TimeUnit is 1024 microsecond */
  49#define MSEC_TO_TU(_msec)	(_msec*1000/1024)
  50
  51/* For GO, this value represents the number of TUs before CSA "beacon
  52 * 0" TBTT when the CSA time-event needs to be scheduled to start.  It
  53 * must be big enough to ensure that we switch in time.
  54 */
  55#define IWL_MVM_CHANNEL_SWITCH_TIME_GO		40
  56
  57/* For client, this value represents the number of TUs before CSA
  58 * "beacon 1" TBTT, instead.  This is because we don't know when the
  59 * GO/AP will be in the new channel, so we switch early enough.
  60 */
  61#define IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT	10
  62
  63/*
  64 * This value (in TUs) is used to fine tune the CSA NoA end time which should
  65 * be just before "beacon 0" TBTT.
  66 */
  67#define IWL_MVM_CHANNEL_SWITCH_MARGIN 4
  68
  69/*
  70 * Number of beacons to transmit on a new channel until we unblock tx to
  71 * the stations, even if we didn't identify them on a new channel
  72 */
  73#define IWL_MVM_CS_UNBLOCK_TX_TIMEOUT 3
  74
  75/* offchannel queue towards mac80211 */
  76#define IWL_MVM_OFFCHANNEL_QUEUE 0
  77
  78/* invalid value for FW link id */
  79#define IWL_MVM_FW_LINK_ID_INVALID 0xff
  80
  81extern const struct ieee80211_ops iwl_mvm_hw_ops;
  82extern const struct ieee80211_ops iwl_mvm_mld_hw_ops;
  83
  84/**
  85 * struct iwl_mvm_mod_params - module parameters for iwlmvm
  86 * @power_scheme: one of enum iwl_power_scheme
  87 */
  88struct iwl_mvm_mod_params {
  89	int power_scheme;
  90};
  91extern struct iwl_mvm_mod_params iwlmvm_mod_params;
  92
  93struct iwl_mvm_phy_ctxt {
  94	u16 id;
  95	u16 color;
  96	u32 ref;
  97
  98	enum nl80211_chan_width width;
  99
 100	struct ieee80211_channel *channel;
 101
 102	/* track for RLC config command */
 103	u32 center_freq1;
 104	bool rlc_disabled;
 105	u32 channel_load_by_us;
 106	u32 channel_load_not_by_us;
 107};
 108
 109struct iwl_mvm_time_event_data {
 110	struct ieee80211_vif *vif;
 111	struct list_head list;
 112	unsigned long end_jiffies;
 113	u32 duration;
 114	bool running;
 115	u32 uid;
 116
 117	/*
 118	 * The access to the 'id' field must be done when the
 119	 * mvm->time_event_lock is held, as it value is used to indicate
 120	 * if the te is in the time event list or not (when id == TE_MAX)
 121	 */
 122	u32 id;
 123	s8 link_id;
 124};
 125
 126 /* Power management */
 127
 128/**
 129 * enum iwl_power_scheme - iwl power schemes
 130 * @IWL_POWER_SCHEME_CAM: Continuously Active Mode
 131 * @IWL_POWER_SCHEME_BPS: Balanced Power Save (default)
 132 * @IWL_POWER_SCHEME_LP: Low Power
 133 */
 134enum iwl_power_scheme {
 135	IWL_POWER_SCHEME_CAM = 1,
 136	IWL_POWER_SCHEME_BPS,
 137	IWL_POWER_SCHEME_LP
 138};
 139
 140#define IWL_UAPSD_MAX_SP		IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL
 141
 142#ifdef CONFIG_IWLWIFI_DEBUGFS
 143enum iwl_dbgfs_pm_mask {
 144	MVM_DEBUGFS_PM_KEEP_ALIVE = BIT(0),
 145	MVM_DEBUGFS_PM_SKIP_OVER_DTIM = BIT(1),
 146	MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS = BIT(2),
 147	MVM_DEBUGFS_PM_RX_DATA_TIMEOUT = BIT(3),
 148	MVM_DEBUGFS_PM_TX_DATA_TIMEOUT = BIT(4),
 149	MVM_DEBUGFS_PM_LPRX_ENA = BIT(6),
 150	MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD = BIT(7),
 151	MVM_DEBUGFS_PM_SNOOZE_ENABLE = BIT(8),
 152	MVM_DEBUGFS_PM_UAPSD_MISBEHAVING = BIT(9),
 153	MVM_DEBUGFS_PM_USE_PS_POLL = BIT(10),
 154};
 155
 156struct iwl_dbgfs_pm {
 157	u16 keep_alive_seconds;
 158	u32 rx_data_timeout;
 159	u32 tx_data_timeout;
 160	bool skip_over_dtim;
 161	u8 skip_dtim_periods;
 162	bool lprx_ena;
 163	u32 lprx_rssi_threshold;
 164	bool snooze_ena;
 165	bool uapsd_misbehaving;
 166	bool use_ps_poll;
 167	int mask;
 168};
 169
 170/* beacon filtering */
 171
 172enum iwl_dbgfs_bf_mask {
 173	MVM_DEBUGFS_BF_ENERGY_DELTA = BIT(0),
 174	MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA = BIT(1),
 175	MVM_DEBUGFS_BF_ROAMING_STATE = BIT(2),
 176	MVM_DEBUGFS_BF_TEMP_THRESHOLD = BIT(3),
 177	MVM_DEBUGFS_BF_TEMP_FAST_FILTER = BIT(4),
 178	MVM_DEBUGFS_BF_TEMP_SLOW_FILTER = BIT(5),
 179	MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER = BIT(6),
 180	MVM_DEBUGFS_BF_DEBUG_FLAG = BIT(7),
 181	MVM_DEBUGFS_BF_ESCAPE_TIMER = BIT(8),
 182	MVM_DEBUGFS_BA_ESCAPE_TIMER = BIT(9),
 183	MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT = BIT(10),
 184};
 185
 186struct iwl_dbgfs_bf {
 187	u32 bf_energy_delta;
 188	u32 bf_roaming_energy_delta;
 189	u32 bf_roaming_state;
 190	u32 bf_temp_threshold;
 191	u32 bf_temp_fast_filter;
 192	u32 bf_temp_slow_filter;
 193	u32 bf_enable_beacon_filter;
 194	u32 bf_debug_flag;
 195	u32 bf_escape_timer;
 196	u32 ba_escape_timer;
 197	u32 ba_enable_beacon_abort;
 198	int mask;
 199};
 200#endif
 201
 202enum iwl_mvm_smps_type_request {
 203	IWL_MVM_SMPS_REQ_BT_COEX,
 204	IWL_MVM_SMPS_REQ_TT,
 205	IWL_MVM_SMPS_REQ_PROT,
 206	IWL_MVM_SMPS_REQ_FW,
 207	NUM_IWL_MVM_SMPS_REQ,
 208};
 209
 210enum iwl_bt_force_ant_mode {
 211	BT_FORCE_ANT_DIS = 0,
 212	BT_FORCE_ANT_AUTO,
 213	BT_FORCE_ANT_BT,
 214	BT_FORCE_ANT_WIFI,
 215
 216	BT_FORCE_ANT_MAX,
 217};
 218
 219/**
 220 * enum iwl_mvm_low_latency_force - low latency force mode set by debugfs
 221 * @LOW_LATENCY_FORCE_UNSET: unset force mode
 222 * @LOW_LATENCY_FORCE_ON: for low latency on
 223 * @LOW_LATENCY_FORCE_OFF: for low latency off
 224 * @NUM_LOW_LATENCY_FORCE: max num of modes
 225 */
 226enum iwl_mvm_low_latency_force {
 227	LOW_LATENCY_FORCE_UNSET,
 228	LOW_LATENCY_FORCE_ON,
 229	LOW_LATENCY_FORCE_OFF,
 230	NUM_LOW_LATENCY_FORCE
 231};
 232
 233/**
 234* enum iwl_mvm_low_latency_cause - low latency set causes
 235* @LOW_LATENCY_TRAFFIC: indicates low latency traffic was detected
 236* @LOW_LATENCY_DEBUGFS: low latency mode set from debugfs
 237* @LOW_LATENCY_VCMD: low latency mode set from vendor command
 238* @LOW_LATENCY_VIF_TYPE: low latency mode set because of vif type (ap)
 239* @LOW_LATENCY_DEBUGFS_FORCE_ENABLE: indicate that force mode is enabled
 240*	the actual set/unset is done with LOW_LATENCY_DEBUGFS_FORCE
 241* @LOW_LATENCY_DEBUGFS_FORCE: low latency force mode from debugfs
 242*	set this with LOW_LATENCY_DEBUGFS_FORCE_ENABLE flag
 243*	in low_latency.
 244*/
 245enum iwl_mvm_low_latency_cause {
 246	LOW_LATENCY_TRAFFIC = BIT(0),
 247	LOW_LATENCY_DEBUGFS = BIT(1),
 248	LOW_LATENCY_VCMD = BIT(2),
 249	LOW_LATENCY_VIF_TYPE = BIT(3),
 250	LOW_LATENCY_DEBUGFS_FORCE_ENABLE = BIT(4),
 251	LOW_LATENCY_DEBUGFS_FORCE = BIT(5),
 252};
 253
 254/**
 255* struct iwl_mvm_link_bf_data - beacon filtering related data
 256* @ave_beacon_signal: average beacon signal
 257* @last_cqm_event: rssi of the last cqm event
 258* @bt_coex_min_thold: minimum threshold for BT coex
 259* @bt_coex_max_thold: maximum threshold for BT coex
 260* @last_bt_coex_event: rssi of the last BT coex event
 261*/
 262struct iwl_mvm_link_bf_data {
 263	int ave_beacon_signal;
 264	int last_cqm_event;
 265	int bt_coex_min_thold;
 266	int bt_coex_max_thold;
 267	int last_bt_coex_event;
 268};
 269
 270/**
 271 * struct iwl_probe_resp_data - data for NoA/CSA updates
 272 * @rcu_head: used for freeing the data on update
 273 * @notif: notification data
 274 * @noa_len: length of NoA attribute, calculated from the notification
 275 */
 276struct iwl_probe_resp_data {
 277	struct rcu_head rcu_head;
 278	struct iwl_probe_resp_data_notif notif;
 279	int noa_len;
 280};
 281
 282/**
 283 * struct iwl_mvm_vif_link_info - per link data in Virtual Interface
 284 * @ap_sta_id: the sta_id of the AP - valid only if VIF type is STA
 285 * @fw_link_id: the id of the link according to the FW API
 286 * @bssid: BSSID for this (client) interface
 287 * @bcast_sta: station used for broadcast packets. Used by the following
 288 *	vifs: P2P_DEVICE, GO and AP.
 289 * @beacon_stats: beacon statistics, containing the # of received beacons,
 290 *	# of received beacons accumulated over FW restart, and the current
 291 *	average signal of beacons retrieved from the firmware
 292 * @smps_requests: the SMPS requests of different parts of the driver,
 293 *	combined on update to yield the overall request to mac80211.
 294 * @probe_resp_data: data from FW notification to store NOA and CSA related
 295 *	data to be inserted into probe response.
 296 * @he_ru_2mhz_block: 26-tone RU OFDMA transmissions should be blocked
 297 * @queue_params: QoS params for this MAC
 298 * @mgmt_queue: queue number for unbufferable management frames
 299 * @igtk: the current IGTK programmed into the firmware
 300 * @active: indicates the link is active in FW (for sanity checking)
 301 * @cab_queue: content-after-beacon (multicast) queue
 302 * @listen_lmac: indicates this link is allocated to the listen LMAC
 303 * @csa_block_tx: we got CSA with mode=1
 304 * @mcast_sta: multicast station
 305 * @phy_ctxt: phy context allocated to this link, if any
 306 * @bf_data: beacon filtering data
 307 * @average_beacon_energy: average beacon energy for beacons received during
 308 *	client connections
 309 */
 310struct iwl_mvm_vif_link_info {
 311	u8 bssid[ETH_ALEN];
 312	u8 ap_sta_id;
 313	u8 fw_link_id;
 314
 315	struct iwl_mvm_int_sta bcast_sta;
 316	struct iwl_mvm_int_sta mcast_sta;
 317
 318	struct {
 319		u32 num_beacons, accu_num_beacons;
 320		u8 avg_signal;
 321	} beacon_stats;
 322
 323	enum ieee80211_smps_mode smps_requests[NUM_IWL_MVM_SMPS_REQ];
 324	struct iwl_probe_resp_data __rcu *probe_resp_data;
 325
 326	struct ieee80211_key_conf *igtk;
 327
 328	bool he_ru_2mhz_block;
 329	bool active;
 330	bool listen_lmac;
 331	bool csa_block_tx;
 332
 333	u16 cab_queue;
 334	/* Assigned while mac80211 has the link in a channel context,
 335	 * or, for P2P Device, while it exists.
 336	 */
 337	struct iwl_mvm_phy_ctxt *phy_ctxt;
 338	/* QoS data from mac80211, need to store this here
 339	 * as mac80211 has a separate callback but we need
 340	 * to have the data for the MAC context
 341	 */
 342	struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS];
 343
 344	u16 mgmt_queue;
 345
 346	struct iwl_mvm_link_bf_data bf_data;
 347	u32 average_beacon_energy;
 348};
 349
 350/**
 351 * struct iwl_mvm_vif - data per Virtual Interface, it is a MAC context
 352 * @mvm: pointer back to the mvm struct
 353 * @id: between 0 and 3
 354 * @color: to solve races upon MAC addition and removal
 355 * @associated: indicates that we're currently associated, used only for
 356 *	managing the firmware state in iwl_mvm_bss_info_changed_station()
 357 * @ap_assoc_sta_count: count of stations associated to us - valid only
 358 *	if VIF type is AP
 359 * @uploaded: indicates the MAC context has been added to the device
 360 * @ap_ibss_active: indicates that AP/IBSS is configured and that the interface
 361 *	should get quota etc.
 362 * @pm_enabled - indicate if MAC power management is allowed
 363 * @monitor_active: indicates that monitor context is configured, and that the
 364 *	interface should get quota etc.
 365 * @low_latency: bit flags for low latency
 366 *	see enum &iwl_mvm_low_latency_cause for causes.
 367 * @low_latency_actual: boolean, indicates low latency is set,
 368 *	as a result from low_latency bit flags and takes force into account.
 369 * @authorized: indicates the AP station was set to authorized
 370 * @ps_disabled: indicates that this interface requires PS to be disabled
 371 * @csa_countdown: indicates that CSA countdown may be started
 372 * @csa_failed: CSA failed to schedule time event, report an error later
 373 * @csa_bcn_pending: indicates that we are waiting for a beacon on a new channel
 374 * @csa_blocks_tx: CSA is blocking TX
 375 * @features: hw features active for this vif
 376 * @max_tx_op: max TXOP in usecs for all ACs, zero for no limit.
 377 * @ap_beacon_time: AP beacon time for synchronisation (on older FW)
 378 * @bf_enabled: indicates if beacon filtering is enabled
 379 * @ba_enabled: indicated if beacon abort is enabled
 380 * @bcn_prot: beacon protection data (keys; FIXME: needs to be per link)
 381 * @deflink: default link data for use in non-MLO
 382 * @link: link data for each link in MLO
 383 * @esr_active: indicates eSR mode is active
 384 * @pm_enabled: indicates powersave is enabled
 385 * @link_selection_res: bitmap of active links as it was decided in the last
 386 *	link selection. Valid only for a MLO vif after assoc. 0 if there wasn't
 387 *	any link selection yet.
 388 * @link_selection_primary: primary link selected by link selection
 389 * @primary_link: primary link in eSR. Valid only for an associated MLD vif,
 390 *	and in eSR mode. Valid only for a STA.
 391 * @roc_activity: currently running ROC activity for this vif (or
 392 *	ROC_NUM_ACTIVITIES if no activity is running).
 393 * @session_prot_connection_loss: the connection was lost due to session
 394 *	protection ending without receiving a beacon, so we need to now
 395 *	protect the deauth separately
 396 * @ap_early_keys: The firmware cannot install keys before stations etc.,
 397 *	but higher layers work differently, so we store the keys here for
 398 *	later installation.
 399 * @ap_sta: pointer to the AP STA data structure
 400 * @csa_count: CSA counter (old CSA implementation w/o firmware)
 401 * @csa_misbehave: CSA AP misbehaviour flag (old implementation)
 402 * @csa_target_freq: CSA target channel frequency (old implementation)
 403 * @csa_work: CSA work (old implementation)
 404 * @dbgfs_bf: beamforming debugfs data
 405 * @dbgfs_dir: debugfs directory for this vif
 406 * @dbgfs_pm: power management debugfs data
 407 * @dbgfs_quota_min: debugfs value for minimal quota
 408 * @dbgfs_slink: debugfs symlink for this interface
 409 * @ftm_unprotected: unprotected FTM debugfs override
 410 * @hs_time_event_data: hotspot/AUX ROC time event data
 411 * @mac_pwr_cmd: debugfs override for MAC power command
 412 * @target_ipv6_addrs: IPv6 addresses on this interface for offload
 413 * @num_target_ipv6_addrs: number of @target_ipv6_addrs
 414 * @tentative_addrs: bitmap of tentative IPv6 addresses in @target_ipv6_addrs
 415 * @rekey_data: rekeying data for WoWLAN GTK rekey offload
 416 * @seqno: storage for seqno for older firmware D0/D3 transition
 417 * @seqno_valid: indicates @seqno is valid
 418 * @time_event_data: session protection time event data
 419 * @tsf_id: the TSF resource ID assigned in firmware (for firmware needing that)
 420 * @tx_key_idx: WEP transmit key index for D3
 421 * @uapsd_misbehaving_ap_addr: MLD address/BSSID of U-APSD misbehaving AP, to
 422 *	not use U-APSD on reconnection
 423 * @uapsd_nonagg_detected_wk: worker for handling detection of no aggregation
 424 *	in U-APSD
 425 */
 426struct iwl_mvm_vif {
 427	struct iwl_mvm *mvm;
 428	u16 id;
 429	u16 color;
 430
 431	bool associated;
 432	u8 ap_assoc_sta_count;
 433	bool uploaded;
 434	bool ap_ibss_active;
 435	bool pm_enabled;
 436	bool monitor_active;
 437	bool esr_active;
 438	bool session_prot_connection_loss;
 439
 440	u8 low_latency: 6;
 441	u8 low_latency_actual: 1;
 442
 443	u8 authorized:1;
 444	bool ps_disabled;
 445
 446	u32 ap_beacon_time;
 447	bool bf_enabled;
 448	bool ba_enabled;
 449
 450#ifdef CONFIG_PM_SLEEP
 451	/* WoWLAN GTK rekey data */
 452	struct {
 453		u8 kck[NL80211_KCK_EXT_LEN];
 454		u8 kek[NL80211_KEK_EXT_LEN];
 455		size_t kek_len;
 456		size_t kck_len;
 457		u32 akm;
 458		__le64 replay_ctr;
 459		bool valid;
 460	} rekey_data;
 461
 462	int tx_key_idx;
 463
 464	bool seqno_valid;
 465	u16 seqno;
 466#endif
 467
 468#if IS_ENABLED(CONFIG_IPV6)
 469	/* IPv6 addresses for WoWLAN */
 470	struct in6_addr target_ipv6_addrs[IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX];
 471	unsigned long tentative_addrs[BITS_TO_LONGS(IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX)];
 472	int num_target_ipv6_addrs;
 473#endif
 474
 475#ifdef CONFIG_IWLWIFI_DEBUGFS
 476	struct dentry *dbgfs_dir;
 477	struct dentry *dbgfs_slink;
 478	struct iwl_dbgfs_pm dbgfs_pm;
 479	struct iwl_dbgfs_bf dbgfs_bf;
 480	struct iwl_mac_power_cmd mac_pwr_cmd;
 481	int dbgfs_quota_min;
 482	bool ftm_unprotected;
 483#endif
 484
 485	/* FW identified misbehaving AP */
 486	u8 uapsd_misbehaving_ap_addr[ETH_ALEN] __aligned(2);
 487	struct delayed_work uapsd_nonagg_detected_wk;
 488
 489	bool csa_countdown;
 490	bool csa_failed;
 491	bool csa_bcn_pending;
 492	bool csa_blocks_tx;
 493	u16 csa_target_freq;
 494	u16 csa_count;
 495	u16 csa_misbehave;
 496	struct delayed_work csa_work;
 497
 498	enum iwl_tsf_id tsf_id;
 499
 500	struct iwl_mvm_time_event_data time_event_data;
 501	struct iwl_mvm_time_event_data hs_time_event_data;
 502	enum iwl_roc_activity roc_activity;
 503
 504	/* TCP Checksum Offload */
 505	netdev_features_t features;
 506
 507	struct ieee80211_sta *ap_sta;
 508
 509	/* we can only have 2 GTK + 2 IGTK active at a time */
 510	struct ieee80211_key_conf *ap_early_keys[4];
 511
 512	struct {
 513		struct ieee80211_key_conf __rcu *keys[2];
 514	} bcn_prot;
 515
 516	u16 max_tx_op;
 517
 518	u16 link_selection_res;
 519	u8 link_selection_primary;
 520	u8 primary_link;
 521
 522	struct iwl_mvm_vif_link_info deflink;
 523	struct iwl_mvm_vif_link_info *link[IEEE80211_MLD_MAX_NUM_LINKS];
 524};
 525
 526#define for_each_mvm_vif_valid_link(mvm_vif, link_id)			\
 527	for (link_id = 0;						\
 528	     link_id < ARRAY_SIZE((mvm_vif)->link);			\
 529	     link_id++)							\
 530		if ((mvm_vif)->link[link_id])
 531
 532static inline struct iwl_mvm_vif *
 533iwl_mvm_vif_from_mac80211(struct ieee80211_vif *vif)
 534{
 535	return (void *)vif->drv_priv;
 536}
 537
 538extern const u8 tid_to_mac80211_ac[];
 539
 540#define IWL_MVM_SCAN_STOPPING_SHIFT	8
 541
 542enum iwl_scan_status {
 543	IWL_MVM_SCAN_REGULAR		= BIT(0),
 544	IWL_MVM_SCAN_SCHED		= BIT(1),
 545	IWL_MVM_SCAN_NETDETECT		= BIT(2),
 546
 547	IWL_MVM_SCAN_STOPPING_REGULAR	= BIT(8),
 548	IWL_MVM_SCAN_STOPPING_SCHED	= BIT(9),
 549	IWL_MVM_SCAN_STOPPING_NETDETECT	= BIT(10),
 550	IWL_MVM_SCAN_STOPPING_INT_MLO	= BIT(11),
 551
 552	IWL_MVM_SCAN_REGULAR_MASK	= IWL_MVM_SCAN_REGULAR |
 553					  IWL_MVM_SCAN_STOPPING_REGULAR,
 554	IWL_MVM_SCAN_SCHED_MASK		= IWL_MVM_SCAN_SCHED |
 555					  IWL_MVM_SCAN_STOPPING_SCHED,
 556	IWL_MVM_SCAN_NETDETECT_MASK	= IWL_MVM_SCAN_NETDETECT |
 557					  IWL_MVM_SCAN_STOPPING_NETDETECT,
 558
 559	IWL_MVM_SCAN_STOPPING_MASK	= 0xff << IWL_MVM_SCAN_STOPPING_SHIFT,
 560	IWL_MVM_SCAN_MASK		= 0xff,
 561};
 562
 563enum iwl_mvm_scan_type {
 564	IWL_SCAN_TYPE_NOT_SET,
 565	IWL_SCAN_TYPE_UNASSOC,
 566	IWL_SCAN_TYPE_WILD,
 567	IWL_SCAN_TYPE_MILD,
 568	IWL_SCAN_TYPE_FRAGMENTED,
 569	IWL_SCAN_TYPE_FAST_BALANCE,
 570};
 571
 572enum iwl_mvm_sched_scan_pass_all_states {
 573	SCHED_SCAN_PASS_ALL_DISABLED,
 574	SCHED_SCAN_PASS_ALL_ENABLED,
 575	SCHED_SCAN_PASS_ALL_FOUND,
 576};
 577
 578/**
 579 * struct iwl_mvm_tt_mgmt - Thermal Throttling Management structure
 580 * @ct_kill_exit: worker to exit thermal kill
 581 * @dynamic_smps: Is thermal throttling enabled dynamic_smps?
 582 * @tx_backoff: The current thremal throttling tx backoff in uSec.
 583 * @min_backoff: The minimal tx backoff due to power restrictions
 584 * @params: Parameters to configure the thermal throttling algorithm.
 585 * @throttle: Is thermal throttling is active?
 586 * @power_budget_mw: maximum cTDP power budget as defined for this system and
 587 *	device
 588 */
 589struct iwl_mvm_tt_mgmt {
 590	struct delayed_work ct_kill_exit;
 591	bool dynamic_smps;
 592	u32 tx_backoff;
 593	u32 min_backoff;
 594	struct iwl_tt_params params;
 595	bool throttle;
 596
 597	u32 power_budget_mw;
 598};
 599
 600#ifdef CONFIG_THERMAL
 601/**
 602 * struct iwl_mvm_thermal_device - thermal zone related data
 603 * @trips: temperature thresholds for report
 604 * @tzone: thermal zone device data
 605*/
 606struct iwl_mvm_thermal_device {
 607	struct thermal_trip trips[IWL_MAX_DTS_TRIPS];
 608	struct thermal_zone_device *tzone;
 609};
 610
 611/*
 612 * struct iwl_mvm_cooling_device
 613 * @cur_state: current state
 614 * @cdev: struct thermal cooling device
 615 */
 616struct iwl_mvm_cooling_device {
 617	u32 cur_state;
 618	struct thermal_cooling_device *cdev;
 619};
 620#endif
 621
 622#define IWL_MVM_NUM_LAST_FRAMES_UCODE_RATES 8
 623
 624struct iwl_mvm_frame_stats {
 625	u32 legacy_frames;
 626	u32 ht_frames;
 627	u32 vht_frames;
 628	u32 bw_20_frames;
 629	u32 bw_40_frames;
 630	u32 bw_80_frames;
 631	u32 bw_160_frames;
 632	u32 sgi_frames;
 633	u32 ngi_frames;
 634	u32 siso_frames;
 635	u32 mimo2_frames;
 636	u32 agg_frames;
 637	u32 ampdu_count;
 638	u32 success_frames;
 639	u32 fail_frames;
 640	u32 last_rates[IWL_MVM_NUM_LAST_FRAMES_UCODE_RATES];
 641	int last_frame_idx;
 642};
 643
 644#define IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE 0xff
 645#define IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -100
 646#define IWL_MVM_DEBUG_SET_TEMPERATURE_MAX 200
 647
 648enum iwl_mvm_tdls_cs_state {
 649	IWL_MVM_TDLS_SW_IDLE = 0,
 650	IWL_MVM_TDLS_SW_REQ_SENT,
 651	IWL_MVM_TDLS_SW_RESP_RCVD,
 652	IWL_MVM_TDLS_SW_REQ_RCVD,
 653	IWL_MVM_TDLS_SW_ACTIVE,
 654};
 655
 656enum iwl_mvm_traffic_load {
 657	IWL_MVM_TRAFFIC_LOW,
 658	IWL_MVM_TRAFFIC_MEDIUM,
 659	IWL_MVM_TRAFFIC_HIGH,
 660};
 661
 662DECLARE_EWMA(rate, 16, 16)
 663
 664struct iwl_mvm_tcm_mac {
 665	struct {
 666		u32 pkts[IEEE80211_NUM_ACS];
 667		u32 airtime;
 668	} tx;
 669	struct {
 670		u32 pkts[IEEE80211_NUM_ACS];
 671		u32 airtime;
 672		u32 last_ampdu_ref;
 673	} rx;
 674	struct {
 675		/* track AP's transfer in client mode */
 676		u64 rx_bytes;
 677		struct ewma_rate rate;
 678		bool detected;
 679	} uapsd_nonagg_detect;
 680	bool opened_rx_ba_sessions;
 681};
 682
 683struct iwl_mvm_tcm {
 684	struct delayed_work work;
 685	spinlock_t lock; /* used when time elapsed */
 686	unsigned long ts; /* timestamp when period ends */
 687	unsigned long ll_ts;
 688	unsigned long uapsd_nonagg_ts;
 689	bool paused;
 690	struct iwl_mvm_tcm_mac data[NUM_MAC_INDEX_DRIVER];
 691	struct {
 692		u32 elapsed; /* milliseconds for this TCM period */
 693		u32 airtime[NUM_MAC_INDEX_DRIVER];
 694		enum iwl_mvm_traffic_load load[NUM_MAC_INDEX_DRIVER];
 695		enum iwl_mvm_traffic_load band_load[NUM_NL80211_BANDS];
 696		enum iwl_mvm_traffic_load global_load;
 697		bool low_latency[NUM_MAC_INDEX_DRIVER];
 698		bool change[NUM_MAC_INDEX_DRIVER];
 699	} result;
 700};
 701
 702/**
 703 * struct iwl_mvm_reorder_buffer - per ra/tid/queue reorder buffer
 704 * @head_sn: reorder window head sn
 705 * @num_stored: number of mpdus stored in the buffer
 706 * @queue: queue of this reorder buffer
 707 * @valid: reordering is valid for this queue
 708 * @lock: protect reorder buffer internal state
 709 */
 710struct iwl_mvm_reorder_buffer {
 711	u16 head_sn;
 712	u16 num_stored;
 713	int queue;
 714	bool valid;
 715	spinlock_t lock;
 716} ____cacheline_aligned_in_smp;
 717
 718/**
 719 * struct iwl_mvm_reorder_buf_entry - reorder buffer entry per-queue/per-seqno
 720 * @frames: list of skbs stored
 721 */
 722struct iwl_mvm_reorder_buf_entry {
 723	struct sk_buff_head frames;
 724}
 725#ifndef __CHECKER__
 726/* sparse doesn't like this construct: "bad integer constant expression" */
 727__aligned(roundup_pow_of_two(sizeof(struct sk_buff_head)))
 728#endif
 729;
 730
 731/**
 732 * struct iwl_mvm_baid_data - BA session data
 733 * @sta_mask: current station mask for the BAID
 734 * @tid: tid of the session
 735 * @baid: baid of the session
 736 * @timeout: the timeout set in the addba request
 737 * @buf_size: the reorder buffer size as set by the last addba request
 738 * @entries_per_queue: # of buffers per queue, this actually gets
 739 *	aligned up to avoid cache line sharing between queues
 740 * @last_rx: last rx jiffies, updated only if timeout passed from last update
 741 * @session_timer: timer to check if BA session expired, runs at 2 * timeout
 742 * @rcu_ptr: BA data RCU protected access
 743 * @rcu_head: RCU head for freeing this data
 744 * @mvm: mvm pointer, needed for timer context
 745 * @reorder_buf: reorder buffer, allocated per queue
 746 * @entries: data
 747 */
 748struct iwl_mvm_baid_data {
 749	struct rcu_head rcu_head;
 750	u32 sta_mask;
 751	u8 tid;
 752	u8 baid;
 753	u16 timeout;
 754	u16 buf_size;
 755	u16 entries_per_queue;
 756	unsigned long last_rx;
 757	struct timer_list session_timer;
 758	struct iwl_mvm_baid_data __rcu **rcu_ptr;
 759	struct iwl_mvm *mvm;
 760	struct iwl_mvm_reorder_buffer reorder_buf[IWL_MAX_RX_HW_QUEUES];
 761	struct iwl_mvm_reorder_buf_entry entries[] ____cacheline_aligned_in_smp;
 762};
 763
 764static inline struct iwl_mvm_baid_data *
 765iwl_mvm_baid_data_from_reorder_buf(struct iwl_mvm_reorder_buffer *buf)
 766{
 767	return (void *)((u8 *)buf -
 768			offsetof(struct iwl_mvm_baid_data, reorder_buf) -
 769			sizeof(*buf) * buf->queue);
 770}
 771
 772/*
 773 * enum iwl_mvm_queue_status - queue status
 774 * @IWL_MVM_QUEUE_FREE: the queue is not allocated nor reserved
 775 *	Basically, this means that this queue can be used for any purpose
 776 * @IWL_MVM_QUEUE_RESERVED: queue is reserved but not yet in use
 777 *	This is the state of a queue that has been dedicated for some RATID
 778 *	(agg'd or not), but that hasn't yet gone through the actual enablement
 779 *	of iwl_mvm_enable_txq(), and therefore no traffic can go through it yet.
 780 *	Note that in this state there is no requirement to already know what TID
 781 *	should be used with this queue, it is just marked as a queue that will
 782 *	be used, and shouldn't be allocated to anyone else.
 783 * @IWL_MVM_QUEUE_READY: queue is ready to be used
 784 *	This is the state of a queue that has been fully configured (including
 785 *	SCD pointers, etc), has a specific RA/TID assigned to it, and can be
 786 *	used to send traffic.
 787 * @IWL_MVM_QUEUE_SHARED: queue is shared, or in a process of becoming shared
 788 *	This is a state in which a single queue serves more than one TID, all of
 789 *	which are not aggregated. Note that the queue is only associated to one
 790 *	RA.
 791 */
 792enum iwl_mvm_queue_status {
 793	IWL_MVM_QUEUE_FREE,
 794	IWL_MVM_QUEUE_RESERVED,
 795	IWL_MVM_QUEUE_READY,
 796	IWL_MVM_QUEUE_SHARED,
 797};
 798
 799#define IWL_MVM_DQA_QUEUE_TIMEOUT	(5 * HZ)
 800#define IWL_MVM_INVALID_QUEUE		0xFFFF
 801
 802#define IWL_MVM_NUM_CIPHERS             10
 803
 804
 805struct iwl_mvm_txq {
 806	struct list_head list;
 807	u16 txq_id;
 808	atomic_t tx_request;
 809#define IWL_MVM_TXQ_STATE_READY		0
 810#define IWL_MVM_TXQ_STATE_STOP_FULL	1
 811#define IWL_MVM_TXQ_STATE_STOP_REDIRECT	2
 812#define IWL_MVM_TXQ_STATE_STOP_AP_CSA	3
 813	unsigned long state;
 814};
 815
 816static inline struct iwl_mvm_txq *
 817iwl_mvm_txq_from_mac80211(struct ieee80211_txq *txq)
 818{
 819	return (void *)txq->drv_priv;
 820}
 821
 822static inline struct iwl_mvm_txq *
 823iwl_mvm_txq_from_tid(struct ieee80211_sta *sta, u8 tid)
 824{
 825	if (tid == IWL_MAX_TID_COUNT)
 826		tid = IEEE80211_NUM_TIDS;
 827
 828	return (void *)sta->txq[tid]->drv_priv;
 829}
 830
 831/**
 832 * struct iwl_mvm_tvqm_txq_info - maps TVQM hw queue to tid
 833 *
 834 * @sta_id: sta id
 835 * @txq_tid: txq tid
 836 */
 837struct iwl_mvm_tvqm_txq_info {
 838	u8 sta_id;
 839	u8 txq_tid;
 840};
 841
 842struct iwl_mvm_dqa_txq_info {
 843	u8 ra_sta_id; /* The RA this queue is mapped to, if exists */
 844	bool reserved; /* Is this the TXQ reserved for a STA */
 845	u8 mac80211_ac; /* The mac80211 AC this queue is mapped to */
 846	u8 txq_tid; /* The TID "owner" of this queue*/
 847	u16 tid_bitmap; /* Bitmap of the TIDs mapped to this queue */
 848	/* Timestamp for inactivation per TID of this queue */
 849	unsigned long last_frame_time[IWL_MAX_TID_COUNT + 1];
 850	enum iwl_mvm_queue_status status;
 851};
 852
 853struct ptp_data {
 854	struct ptp_clock *ptp_clock;
 855	struct ptp_clock_info ptp_clock_info;
 856
 857	struct delayed_work dwork;
 858
 859	/* The last GP2 reading from the hw */
 860	u32 last_gp2;
 861
 862	/* number of wraparounds since scale_update_adj_time_ns */
 863	u32 wrap_counter;
 864
 865	/* GP2 time when the scale was last updated */
 866	u32 scale_update_gp2;
 867
 868	/* Adjusted time when the scale was last updated in nanoseconds */
 869	u64 scale_update_adj_time_ns;
 870
 871	/* clock frequency offset, scaled to 65536000000 */
 872	u64 scaled_freq;
 873
 874	/* Delta between hardware clock and ptp clock in nanoseconds */
 875	s64 delta;
 876};
 877
 878struct iwl_time_sync_data {
 879	struct sk_buff_head frame_list;
 880	u8 peer_addr[ETH_ALEN];
 881	bool active;
 882};
 883
 884struct iwl_mei_scan_filter {
 885	bool is_mei_limited_scan;
 886	struct sk_buff_head scan_res;
 887	struct work_struct scan_work;
 888};
 889
 890/**
 891 * struct iwl_mvm_acs_survey_channel - per-channel survey information
 892 *
 893 * Stripped down version of &struct survey_info.
 894 *
 895 * @time: time in ms the radio was on the channel
 896 * @time_busy: time in ms the channel was sensed busy
 897 * @time_tx: time in ms spent transmitting data
 898 * @time_rx: time in ms spent receiving data
 899 * @noise: channel noise in dBm
 900 */
 901struct iwl_mvm_acs_survey_channel {
 902	u32 time;
 903	u32 time_busy;
 904	u32 time_tx;
 905	u32 time_rx;
 906	s8 noise;
 907};
 908
 909struct iwl_mvm_acs_survey {
 910	struct iwl_mvm_acs_survey_channel *bands[NUM_NL80211_BANDS];
 911
 912	/* Overall number of channels */
 913	int n_channels;
 914
 915	/* Storage space for per-channel information follows */
 916	struct iwl_mvm_acs_survey_channel channels[] __counted_by(n_channels);
 917};
 918
 919struct iwl_mvm {
 920	/* for logger access */
 921	struct device *dev;
 922
 923	struct iwl_trans *trans;
 924	const struct iwl_fw *fw;
 925	const struct iwl_rf_cfg *cfg;
 926	struct iwl_phy_db *phy_db;
 927	struct ieee80211_hw *hw;
 928
 929	/* for protecting access to iwl_mvm */
 930	struct mutex mutex;
 931	struct list_head async_handlers_list;
 932	spinlock_t async_handlers_lock;
 933	struct work_struct async_handlers_wk;
 934
 935	/* For async rx handlers that require the wiphy lock */
 936	struct wiphy_work async_handlers_wiphy_wk;
 937
 938	struct work_struct roc_done_wk;
 939
 940	unsigned long init_status;
 941
 942	unsigned long status;
 943
 944	u32 queue_sync_cookie;
 945	unsigned long queue_sync_state;
 946	/*
 947	 * for beacon filtering -
 948	 * currently only one interface can be supported
 949	 */
 950	struct iwl_mvm_vif *bf_allowed_vif;
 951
 952	bool hw_registered;
 953	bool rfkill_safe_init_done;
 954
 955	u8 cca_40mhz_workaround;
 956
 957	u8 fw_rates_ver;
 958
 959	u32 ampdu_ref;
 960	bool ampdu_toggle;
 961
 962	struct iwl_notif_wait_data notif_wait;
 963
 964	union {
 965		struct mvm_statistics_rx_v3 rx_stats_v3;
 966		struct mvm_statistics_rx rx_stats;
 967	};
 968
 969	struct {
 970		u64 rx_time;
 971		u64 tx_time;
 972		u64 on_time_rf;
 973		u64 on_time_scan;
 974	} radio_stats, accu_radio_stats;
 975
 976	struct list_head add_stream_txqs;
 977	union {
 978		struct iwl_mvm_dqa_txq_info queue_info[IWL_MAX_HW_QUEUES];
 979		struct iwl_mvm_tvqm_txq_info tvqm_info[IWL_MAX_TVQM_QUEUES];
 980	};
 981	struct work_struct add_stream_wk; /* To add streams to queues */
 982	spinlock_t add_stream_lock;
 983
 984	const char *nvm_file_name;
 985	struct iwl_nvm_data *nvm_data;
 986	struct iwl_mei_nvm *mei_nvm_data;
 987	struct iwl_mvm_csme_conn_info __rcu *csme_conn_info;
 988	bool mei_rfkill_blocked;
 989	bool mei_registered;
 990	struct work_struct sap_connected_wk;
 991
 992	/*
 993	 * NVM built based on the SAP data but that we can't free even after
 994	 * we get ownership because it contains the cfg80211's channel.
 995	 */
 996	struct iwl_nvm_data *temp_nvm_data;
 997
 998	/* NVM sections */
 999	struct iwl_nvm_section nvm_sections[NVM_MAX_NUM_SECTIONS];
1000
1001	struct iwl_fw_runtime fwrt;
1002
1003	/* EEPROM MAC addresses */
1004	struct mac_address addresses[IWL_MVM_MAX_ADDRESSES];
1005
1006	/* data related to data path */
1007	struct iwl_rx_phy_info last_phy_info;
1008	struct ieee80211_sta __rcu *fw_id_to_mac_id[IWL_STATION_COUNT_MAX];
1009	/* note: fw_id_to_link_sta must be protected by wiphy and mvm mutexes */
1010	struct ieee80211_link_sta __rcu *fw_id_to_link_sta[IWL_STATION_COUNT_MAX];
1011	u8 rx_ba_sessions;
1012
1013	/* configured by mac80211 */
1014	u32 rts_threshold;
1015
1016	/* Scan status, cmd (pre-allocated) and auxiliary station */
1017	unsigned int scan_status;
1018	size_t scan_cmd_size;
1019	void *scan_cmd;
1020	struct iwl_mcast_filter_cmd *mcast_filter_cmd;
1021	/* For CDB this is low band scan type, for non-CDB - type. */
1022	enum iwl_mvm_scan_type scan_type;
1023	enum iwl_mvm_scan_type hb_scan_type;
1024
1025	enum iwl_mvm_sched_scan_pass_all_states sched_scan_pass_all;
1026	struct delayed_work scan_timeout_dwork;
1027
1028	/* max number of simultaneous scans the FW supports */
1029	unsigned int max_scans;
1030
1031	/* UMAC scan tracking */
1032	u32 scan_uid_status[IWL_MAX_UMAC_SCANS];
1033
1034	/* start time of last scan in TSF of the mac that requested the scan */
1035	u64 scan_start;
1036
1037	/* the vif that requested the current scan */
1038	struct iwl_mvm_vif *scan_vif;
1039	u8 scan_link_id;
1040
1041	/* rx chain antennas set through debugfs for the scan command */
1042	u8 scan_rx_ant;
1043
1044	/* Internal station */
1045	struct iwl_mvm_int_sta aux_sta;
1046	struct iwl_mvm_int_sta snif_sta;
1047
1048	bool last_ebs_successful;
1049
1050	u8 scan_last_antenna_idx; /* to toggle TX between antennas */
1051	u8 mgmt_last_antenna_idx;
1052
1053	u8 set_tx_ant;
1054	u8 set_rx_ant;
1055
1056	/* last smart fifo state that was successfully sent to firmware */
1057	enum iwl_sf_state sf_state;
1058
1059	/*
1060	 * Leave this pointer outside the ifdef below so that it can be
1061	 * assigned without ifdef in the source code.
1062	 */
1063	struct dentry *debugfs_dir;
1064#ifdef CONFIG_IWLWIFI_DEBUGFS
1065	u32 dbgfs_sram_offset, dbgfs_sram_len;
1066	u32 dbgfs_prph_reg_addr;
1067	bool disable_power_off;
1068	bool disable_power_off_d3;
1069	bool beacon_inject_active;
1070
1071	bool scan_iter_notif_enabled;
1072
1073	struct debugfs_blob_wrapper nvm_hw_blob;
1074	struct debugfs_blob_wrapper nvm_sw_blob;
1075	struct debugfs_blob_wrapper nvm_calib_blob;
1076	struct debugfs_blob_wrapper nvm_prod_blob;
1077	struct debugfs_blob_wrapper nvm_phy_sku_blob;
1078	struct debugfs_blob_wrapper nvm_reg_blob;
1079
1080	struct iwl_mvm_frame_stats drv_rx_stats;
1081	spinlock_t drv_stats_lock;
1082	u16 dbgfs_rx_phyinfo;
1083#endif
1084
1085	struct iwl_mvm_phy_ctxt phy_ctxts[NUM_PHY_CTX];
1086
1087	struct list_head time_event_list;
1088	spinlock_t time_event_lock;
1089
1090	/*
1091	 * A bitmap indicating the index of the key in use. The firmware
1092	 * can hold 16 keys at most. Reflect this fact.
1093	 */
1094	unsigned long fw_key_table[BITS_TO_LONGS(STA_KEY_MAX_NUM)];
1095	u8 fw_key_deleted[STA_KEY_MAX_NUM];
1096
1097	struct ieee80211_vif __rcu *vif_id_to_mac[NUM_MAC_INDEX_DRIVER];
1098
1099	u8 *error_recovery_buf;
1100
1101#ifdef CONFIG_IWLWIFI_LEDS
1102	struct led_classdev led;
1103#endif
1104
1105	struct ieee80211_vif *p2p_device_vif;
1106
1107#ifdef CONFIG_PM_SLEEP
1108	struct wiphy_wowlan_support wowlan;
1109	int gtk_ivlen, gtk_icvlen, ptk_ivlen, ptk_icvlen;
1110
1111	/* sched scan settings for net detect */
1112	struct ieee80211_scan_ies nd_ies;
1113	struct cfg80211_match_set *nd_match_sets;
1114	int n_nd_match_sets;
1115	struct ieee80211_channel **nd_channels;
1116	int n_nd_channels;
1117	bool net_detect;
1118	bool fast_resume;
1119	u8 offload_tid;
1120#ifdef CONFIG_IWLWIFI_DEBUGFS
1121	bool d3_wake_sysassert;
1122	u32 last_netdetect_scans; /* no. of scans in the last net-detect wake */
1123#endif
1124#endif
1125
1126	wait_queue_head_t rx_sync_waitq;
1127
1128	struct iwl_bt_coex_prof_old_notif last_bt_notif;
1129	struct iwl_bt_coex_ci_cmd last_bt_ci_cmd;
1130
1131	u8 bt_tx_prio;
1132	enum iwl_bt_force_ant_mode bt_force_ant_mode;
1133
1134	/* Aux ROC */
1135	struct list_head aux_roc_te_list;
1136
1137	/* Thermal Throttling and CTkill */
1138	struct iwl_mvm_tt_mgmt thermal_throttle;
1139#ifdef CONFIG_THERMAL
1140	struct iwl_mvm_thermal_device tz_device;
1141	struct iwl_mvm_cooling_device cooling_dev;
1142#endif
1143
1144	s32 temperature;	/* Celsius */
1145	/*
1146	 * Debug option to set the NIC temperature. This option makes the
1147	 * driver think this is the actual NIC temperature, and ignore the
1148	 * real temperature that is received from the fw
1149	 */
1150	bool temperature_test;  /* Debug test temperature is enabled */
1151
1152	bool fw_static_smps_request;
1153
1154	unsigned long bt_coex_last_tcm_ts;
1155	struct iwl_mvm_tcm tcm;
1156
1157	u8 uapsd_noagg_bssid_write_idx;
1158	struct mac_address uapsd_noagg_bssids[IWL_MVM_UAPSD_NOAGG_BSSIDS_NUM]
1159		__aligned(2);
1160
1161	struct iwl_time_quota_cmd last_quota_cmd;
1162
1163	/* Tx queues */
1164	u16 aux_queue;
1165	u16 snif_queue;
1166	u16 probe_queue;
1167	u16 p2p_dev_queue;
1168
1169	/* Indicate if device power save is allowed */
1170	u8 ps_disabled; /* u8 instead of bool to ease debugfs_create_* usage */
1171	/* Indicate if 32Khz external clock is valid */
1172	u32 ext_clock_valid;
1173
1174	/* This vif used by CSME to send / receive traffic */
1175	struct ieee80211_vif *csme_vif;
1176	struct ieee80211_vif __rcu *csa_vif;
1177	struct ieee80211_vif __rcu *csa_tx_blocked_vif;
1178	u8 csa_tx_block_bcn_timeout;
1179
1180	/* system time of last beacon (for AP/GO interface) */
1181	u32 ap_last_beacon_gp2;
1182
1183	/* indicates that we transmitted the last beacon */
1184	bool ibss_manager;
1185
1186	bool lar_regdom_set;
1187	enum iwl_mcc_source mcc_src;
1188
1189	/* TDLS channel switch data */
1190	struct {
1191		struct delayed_work dwork;
1192		enum iwl_mvm_tdls_cs_state state;
1193
1194		/*
1195		 * Current cs sta - might be different from periodic cs peer
1196		 * station. Value is meaningless when the cs-state is idle.
1197		 */
1198		u8 cur_sta_id;
1199
1200		/* TDLS periodic channel-switch peer */
1201		struct {
1202			u8 sta_id;
1203			u8 op_class;
1204			bool initiator; /* are we the link initiator */
1205			struct cfg80211_chan_def chandef;
1206			struct sk_buff *skb; /* ch sw template */
1207			u32 ch_sw_tm_ie;
1208
1209			/* timestamp of last ch-sw request sent (GP2 time) */
1210			u32 sent_timestamp;
1211		} peer;
1212	} tdls_cs;
1213
1214
1215	u32 ciphers[IWL_MVM_NUM_CIPHERS];
1216
1217	struct cfg80211_ftm_responder_stats ftm_resp_stats;
1218	struct {
1219		struct cfg80211_pmsr_request *req;
1220		struct wireless_dev *req_wdev;
1221		struct list_head loc_list;
1222		int responses[IWL_TOF_MAX_APS];
1223		struct {
1224			struct list_head resp;
1225		} smooth;
1226		struct list_head pasn_list;
1227	} ftm_initiator;
1228
1229	struct list_head resp_pasn_list;
1230
1231	struct ptp_data ptp_data;
1232
1233	struct {
1234		u8 range_resp;
1235	} cmd_ver;
1236
1237	struct iwl_mvm_baid_data __rcu *baid_map[IWL_MAX_BAID];
1238
1239	/*
1240	 * Drop beacons from other APs in AP mode when there are no connected
1241	 * clients.
1242	 */
1243	bool drop_bcn_ap_mode;
1244
1245	struct delayed_work cs_tx_unblock_dwork;
1246
1247	/* does a monitor vif exist (only one can exist hence bool) */
1248	bool monitor_on;
1249	/*
1250	 * primary channel position relative to he whole bandwidth,
1251	 * in steps of 80 MHz
1252	 */
1253	u8 monitor_p80;
1254
1255	/* sniffer data to include in radiotap */
1256	__le16 cur_aid;
1257	u8 cur_bssid[ETH_ALEN];
1258
1259	/* report rx timestamp in ptp clock time */
1260	bool rx_ts_ptp;
1261
1262	unsigned long last_6ghz_passive_scan_jiffies;
1263	unsigned long last_reset_or_resume_time_jiffies;
1264
1265	bool sta_remove_requires_queue_remove;
1266	bool mld_api_is_used;
1267
1268	/*
1269	 * Indicates that firmware will do a product reset (and then
1270	 * therefore fail to load) when we start it (due to OTP burn),
1271	 * if so don't dump errors etc. since this is expected.
1272	 */
1273	bool fw_product_reset;
1274
1275	struct iwl_time_sync_data time_sync;
1276
1277	struct iwl_mei_scan_filter mei_scan_filter;
1278
1279	struct iwl_mvm_acs_survey *acs_survey;
1280
1281	bool statistics_clear;
1282};
1283
1284/* Extract MVM priv from op_mode and _hw */
1285#define IWL_OP_MODE_GET_MVM(_iwl_op_mode)		\
1286	((struct iwl_mvm *)(_iwl_op_mode)->op_mode_specific)
1287
1288#define IWL_MAC80211_GET_MVM(_hw)			\
1289	IWL_OP_MODE_GET_MVM((struct iwl_op_mode *)((_hw)->priv))
1290
1291DEFINE_GUARD(mvm, struct iwl_mvm *, mutex_lock(&_T->mutex), mutex_unlock(&_T->mutex))
1292
1293/**
1294 * enum iwl_mvm_status - MVM status bits
1295 * @IWL_MVM_STATUS_HW_RFKILL: HW RF-kill is asserted
1296 * @IWL_MVM_STATUS_HW_CTKILL: CT-kill is active
1297 * @IWL_MVM_STATUS_ROC_P2P_RUNNING: remain-on-channel on P2P is running (when
1298 *	P2P is not over AUX)
1299 * @IWL_MVM_STATUS_HW_RESTART_REQUESTED: HW restart was requested
1300 * @IWL_MVM_STATUS_IN_HW_RESTART: HW restart is active
1301 * @IWL_MVM_STATUS_ROC_AUX_RUNNING: AUX remain-on-channel is running
1302 * @IWL_MVM_STATUS_FIRMWARE_RUNNING: firmware is running
1303 * @IWL_MVM_STATUS_IN_D3: in D3 (or at least about to go into it)
1304 * @IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE: suppress one error log
1305 *	if this is set, when intentionally triggered
1306 */
1307enum iwl_mvm_status {
1308	IWL_MVM_STATUS_HW_RFKILL,
1309	IWL_MVM_STATUS_HW_CTKILL,
1310	IWL_MVM_STATUS_ROC_P2P_RUNNING,
1311	IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1312	IWL_MVM_STATUS_IN_HW_RESTART,
1313	IWL_MVM_STATUS_ROC_AUX_RUNNING,
1314	IWL_MVM_STATUS_FIRMWARE_RUNNING,
1315	IWL_MVM_STATUS_IN_D3,
1316	IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE,
1317};
1318
1319struct iwl_mvm_csme_conn_info {
1320	struct rcu_head rcu_head;
1321	struct iwl_mei_conn_info conn_info;
1322};
1323
1324/* Keep track of completed init configuration */
1325enum iwl_mvm_init_status {
1326	IWL_MVM_INIT_STATUS_THERMAL_INIT_COMPLETE = BIT(0),
1327	IWL_MVM_INIT_STATUS_LEDS_INIT_COMPLETE = BIT(1),
1328};
1329
1330static inline bool iwl_mvm_is_radio_killed(struct iwl_mvm *mvm)
1331{
1332	return test_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status) ||
1333	       test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
1334}
1335
1336static inline bool iwl_mvm_is_radio_hw_killed(struct iwl_mvm *mvm)
1337{
1338	return test_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
1339}
1340
1341static inline bool iwl_mvm_firmware_running(struct iwl_mvm *mvm)
1342{
1343	return test_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1344}
1345
1346/* Must be called with rcu_read_lock() held and it can only be
1347 * released when mvmsta is not needed anymore.
1348 */
1349static inline struct iwl_mvm_sta *
1350iwl_mvm_sta_from_staid_rcu(struct iwl_mvm *mvm, u8 sta_id)
1351{
1352	struct ieee80211_sta *sta;
1353
1354	if (sta_id >= mvm->fw->ucode_capa.num_stations)
1355		return NULL;
1356
1357	sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1358
1359	/* This can happen if the station has been removed right now */
1360	if (IS_ERR_OR_NULL(sta))
1361		return NULL;
1362
1363	return iwl_mvm_sta_from_mac80211(sta);
1364}
1365
1366static inline struct iwl_mvm_sta *
1367iwl_mvm_sta_from_staid_protected(struct iwl_mvm *mvm, u8 sta_id)
1368{
1369	struct ieee80211_sta *sta;
1370
1371	if (sta_id >= mvm->fw->ucode_capa.num_stations)
1372		return NULL;
1373
1374	sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1375					lockdep_is_held(&mvm->mutex));
1376
1377	/* This can happen if the station has been removed right now */
1378	if (IS_ERR_OR_NULL(sta))
1379		return NULL;
1380
1381	return iwl_mvm_sta_from_mac80211(sta);
1382}
1383
1384static inline struct ieee80211_vif *
1385iwl_mvm_rcu_dereference_vif_id(struct iwl_mvm *mvm, u8 vif_id, bool rcu)
1386{
1387	if (WARN_ON(vif_id >= ARRAY_SIZE(mvm->vif_id_to_mac)))
1388		return NULL;
1389
1390	if (rcu)
1391		return rcu_dereference(mvm->vif_id_to_mac[vif_id]);
1392
1393	return rcu_dereference_protected(mvm->vif_id_to_mac[vif_id],
1394					 lockdep_is_held(&mvm->mutex));
1395}
1396
1397static inline bool iwl_mvm_is_adaptive_dwell_supported(struct iwl_mvm *mvm)
1398{
1399	return fw_has_api(&mvm->fw->ucode_capa,
1400			  IWL_UCODE_TLV_API_ADAPTIVE_DWELL);
1401}
1402
1403static inline bool iwl_mvm_is_adaptive_dwell_v2_supported(struct iwl_mvm *mvm)
1404{
1405	return fw_has_api(&mvm->fw->ucode_capa,
1406			  IWL_UCODE_TLV_API_ADAPTIVE_DWELL_V2);
1407}
1408
1409static inline bool iwl_mvm_is_adwell_hb_ap_num_supported(struct iwl_mvm *mvm)
1410{
1411	return fw_has_api(&mvm->fw->ucode_capa,
1412			  IWL_UCODE_TLV_API_ADWELL_HB_DEF_N_AP);
1413}
1414
1415static inline bool iwl_mvm_is_oce_supported(struct iwl_mvm *mvm)
1416{
1417	/* OCE should never be enabled for LMAC scan FWs */
1418	return fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_OCE);
1419}
1420
1421static inline bool iwl_mvm_is_frag_ebs_supported(struct iwl_mvm *mvm)
1422{
1423	return fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_FRAG_EBS);
1424}
1425
1426static inline bool iwl_mvm_is_short_beacon_notif_supported(struct iwl_mvm *mvm)
1427{
1428	return fw_has_api(&mvm->fw->ucode_capa,
1429			  IWL_UCODE_TLV_API_SHORT_BEACON_NOTIF);
1430}
1431
1432static inline bool iwl_mvm_is_dqa_data_queue(struct iwl_mvm *mvm, u8 queue)
1433{
1434	return (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE) &&
1435	       (queue <= IWL_MVM_DQA_MAX_DATA_QUEUE);
1436}
1437
1438static inline bool iwl_mvm_is_dqa_mgmt_queue(struct iwl_mvm *mvm, u8 queue)
1439{
1440	return (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE) &&
1441	       (queue <= IWL_MVM_DQA_MAX_MGMT_QUEUE);
1442}
1443
1444static inline bool iwl_mvm_is_lar_supported(struct iwl_mvm *mvm)
1445{
1446	bool nvm_lar = mvm->nvm_data->lar_enabled;
1447	bool tlv_lar = fw_has_capa(&mvm->fw->ucode_capa,
1448				   IWL_UCODE_TLV_CAPA_LAR_SUPPORT);
1449
1450	/*
1451	 * Enable LAR only if it is supported by the FW (TLV) &&
1452	 * enabled in the NVM
1453	 */
1454	if (mvm->trans->cfg->nvm_type == IWL_NVM_EXT)
1455		return nvm_lar && tlv_lar;
1456	else
1457		return tlv_lar;
1458}
1459
1460static inline bool iwl_mvm_is_wifi_mcc_supported(struct iwl_mvm *mvm)
1461{
1462	return fw_has_api(&mvm->fw->ucode_capa,
1463			  IWL_UCODE_TLV_API_WIFI_MCC_UPDATE) ||
1464	       fw_has_capa(&mvm->fw->ucode_capa,
1465			   IWL_UCODE_TLV_CAPA_LAR_MULTI_MCC);
1466}
1467
1468static inline bool iwl_mvm_bt_is_rrc_supported(struct iwl_mvm *mvm)
1469{
1470	return fw_has_capa(&mvm->fw->ucode_capa,
1471			   IWL_UCODE_TLV_CAPA_BT_COEX_RRC) &&
1472		IWL_MVM_BT_COEX_RRC;
1473}
1474
1475static inline bool iwl_mvm_is_csum_supported(struct iwl_mvm *mvm)
1476{
1477	return fw_has_capa(&mvm->fw->ucode_capa,
1478			   IWL_UCODE_TLV_CAPA_CSUM_SUPPORT);
1479}
1480
1481static inline bool iwl_mvm_is_mplut_supported(struct iwl_mvm *mvm)
1482{
1483	return fw_has_capa(&mvm->fw->ucode_capa,
1484			   IWL_UCODE_TLV_CAPA_BT_MPLUT_SUPPORT) &&
1485		IWL_MVM_BT_COEX_MPLUT;
1486}
1487
1488static inline
1489bool iwl_mvm_is_p2p_scm_uapsd_supported(struct iwl_mvm *mvm)
1490{
1491	return fw_has_capa(&mvm->fw->ucode_capa,
1492			   IWL_UCODE_TLV_CAPA_P2P_SCM_UAPSD) &&
1493		!(iwlwifi_mod_params.uapsd_disable &
1494		  IWL_DISABLE_UAPSD_P2P_CLIENT);
1495}
1496
1497static inline bool iwl_mvm_has_new_rx_api(struct iwl_mvm *mvm)
1498{
1499	return fw_has_capa(&mvm->fw->ucode_capa,
1500			   IWL_UCODE_TLV_CAPA_MULTI_QUEUE_RX_SUPPORT);
1501}
1502
1503static inline bool iwl_mvm_has_mld_api(const struct iwl_fw *fw)
1504{
1505	return fw_has_capa(&fw->ucode_capa,
1506			   IWL_UCODE_TLV_CAPA_MLD_API_SUPPORT);
1507}
1508
1509static inline bool iwl_mvm_has_new_station_api(const struct iwl_fw *fw)
1510{
1511	return iwl_mvm_has_mld_api(fw) ||
1512	       iwl_fw_lookup_cmd_ver(fw, ADD_STA, 0) >= 12;
1513}
1514
1515static inline bool iwl_mvm_has_new_tx_api(struct iwl_mvm *mvm)
1516{
1517	/* TODO - replace with TLV once defined */
1518	return mvm->trans->mac_cfg->gen2;
1519}
1520
1521static inline bool iwl_mvm_has_unified_ucode(struct iwl_mvm *mvm)
1522{
1523	/* TODO - better define this */
1524	return mvm->trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_22000;
1525}
1526
1527static inline bool iwl_mvm_is_cdb_supported(struct iwl_mvm *mvm)
1528{
1529	/*
1530	 * TODO:
1531	 * The issue of how to determine CDB APIs and usage is still not fully
1532	 * defined.
1533	 * There is a compilation for CDB and non-CDB FW, but there may
1534	 * be also runtime check.
1535	 * For now there is a TLV for checking compilation mode, but a
1536	 * runtime check will also have to be here - once defined.
1537	 */
1538	return fw_has_capa(&mvm->fw->ucode_capa,
1539			   IWL_UCODE_TLV_CAPA_CDB_SUPPORT);
1540}
1541
1542static inline bool iwl_mvm_cdb_scan_api(struct iwl_mvm *mvm)
1543{
1544	/*
1545	 * TODO: should this be the same as iwl_mvm_is_cdb_supported()?
1546	 * but then there's a little bit of code in scan that won't make
1547	 * any sense...
1548	 */
1549	return mvm->trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_22000;
1550}
1551
1552static inline bool iwl_mvm_is_scan_ext_chan_supported(struct iwl_mvm *mvm)
1553{
1554	return fw_has_api(&mvm->fw->ucode_capa,
1555			  IWL_UCODE_TLV_API_SCAN_EXT_CHAN_VER);
1556}
1557
1558
1559static inline bool iwl_mvm_is_reduced_config_scan_supported(struct iwl_mvm *mvm)
1560{
1561	return fw_has_api(&mvm->fw->ucode_capa,
1562			  IWL_UCODE_TLV_API_REDUCED_SCAN_CONFIG);
1563}
1564
1565static inline bool iwl_mvm_is_band_in_rx_supported(struct iwl_mvm *mvm)
1566{
1567	return fw_has_api(&mvm->fw->ucode_capa,
1568			   IWL_UCODE_TLV_API_BAND_IN_RX_DATA);
1569}
1570
1571static inline bool iwl_mvm_has_new_rx_stats_api(struct iwl_mvm *mvm)
1572{
1573	return fw_has_api(&mvm->fw->ucode_capa,
1574			  IWL_UCODE_TLV_API_NEW_RX_STATS);
1575}
1576
1577static inline bool iwl_mvm_has_quota_low_latency(struct iwl_mvm *mvm)
1578{
1579	return fw_has_api(&mvm->fw->ucode_capa,
1580			  IWL_UCODE_TLV_API_QUOTA_LOW_LATENCY);
1581}
1582
1583static inline bool iwl_mvm_has_no_host_disable_tx(struct iwl_mvm *mvm)
1584{
1585	return fw_has_api(&mvm->fw->ucode_capa,
1586			  IWL_UCODE_TLV_API_NO_HOST_DISABLE_TX);
1587}
1588
1589static inline bool iwl_mvm_has_tlc_offload(const struct iwl_mvm *mvm)
1590{
1591	return fw_has_capa(&mvm->fw->ucode_capa,
1592			   IWL_UCODE_TLV_CAPA_TLC_OFFLOAD);
1593}
1594
1595static inline struct agg_tx_status *
1596iwl_mvm_get_agg_status(struct iwl_mvm *mvm, void *tx_resp)
1597{
1598	if (iwl_mvm_has_new_tx_api(mvm))
1599		return &((struct iwl_tx_resp *)tx_resp)->status;
1600	else
1601		return ((struct iwl_tx_resp_v3 *)tx_resp)->status;
1602}
1603
1604static inline bool iwl_mvm_is_tt_in_fw(struct iwl_mvm *mvm)
1605{
1606	/* these two TLV are redundant since the responsibility to CT-kill by
1607	 * FW happens only after we send at least one command of
1608	 * temperature THs report.
1609	 */
1610	return fw_has_capa(&mvm->fw->ucode_capa,
1611			   IWL_UCODE_TLV_CAPA_CT_KILL_BY_FW) &&
1612	       fw_has_capa(&mvm->fw->ucode_capa,
1613			   IWL_UCODE_TLV_CAPA_TEMP_THS_REPORT_SUPPORT);
1614}
1615
1616static inline bool iwl_mvm_is_ctdp_supported(struct iwl_mvm *mvm)
1617{
1618	return fw_has_capa(&mvm->fw->ucode_capa,
1619			   IWL_UCODE_TLV_CAPA_CTDP_SUPPORT);
1620}
1621
1622static inline bool iwl_mvm_is_esr_supported(struct iwl_trans *trans)
1623{
1624	if (CSR_HW_RFID_IS_CDB(trans->info.hw_rf_id))
1625		return false;
1626
1627	switch (CSR_HW_RFID_TYPE(trans->info.hw_rf_id)) {
1628	case IWL_CFG_RF_TYPE_FM:
1629		/* Step A doesn't support eSR */
1630		return CSR_HW_RFID_STEP(trans->info.hw_rf_id);
1631	case IWL_CFG_RF_TYPE_WH:
1632	case IWL_CFG_RF_TYPE_PE:
1633		return true;
1634	default:
1635		return false;
1636	}
1637}
1638
1639static inline int iwl_mvm_max_active_links(struct iwl_mvm *mvm,
1640					   struct ieee80211_vif *vif)
1641{
1642	struct iwl_trans *trans = mvm->fwrt.trans;
1643
1644	if (vif->type == NL80211_IFTYPE_AP)
1645		return mvm->fw->ucode_capa.num_beacons;
1646
1647	/* Check if HW supports eSR or STR */
1648	if (iwl_mvm_is_esr_supported(trans) ||
1649	    (CSR_HW_RFID_TYPE(trans->info.hw_rf_id) == IWL_CFG_RF_TYPE_FM &&
1650	     CSR_HW_RFID_IS_CDB(trans->info.hw_rf_id)))
1651		return IWL_FW_MAX_ACTIVE_LINKS_NUM;
1652
1653	return 1;
1654}
1655
1656extern const u8 iwl_mvm_ac_to_tx_fifo[];
1657extern const u8 iwl_mvm_ac_to_gen2_tx_fifo[];
1658extern const u8 iwl_mvm_ac_to_bz_tx_fifo[];
1659
1660static inline u8 iwl_mvm_mac_ac_to_tx_fifo(struct iwl_mvm *mvm,
1661					   enum ieee80211_ac_numbers ac)
1662{
1663	if (mvm->trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ)
1664		return iwl_mvm_ac_to_bz_tx_fifo[ac];
1665	if (iwl_mvm_has_new_tx_api(mvm))
1666		return iwl_mvm_ac_to_gen2_tx_fifo[ac];
1667	return iwl_mvm_ac_to_tx_fifo[ac];
1668}
1669
1670static inline bool iwl_mvm_has_rlc_offload(struct iwl_mvm *mvm)
1671{
1672	return iwl_fw_lookup_cmd_ver(mvm->fw,
1673				     WIDE_ID(DATA_PATH_GROUP, RLC_CONFIG_CMD),
1674				     0) >= 3;
1675}
1676
1677struct iwl_rate_info {
1678	u8 plcp;	/* uCode API:  IWL_RATE_6M_PLCP, etc. */
1679	u8 plcp_siso;	/* uCode API:  IWL_RATE_SISO_6M_PLCP, etc. */
1680	u8 plcp_mimo2;	/* uCode API:  IWL_RATE_MIMO2_6M_PLCP, etc. */
1681	u8 plcp_mimo3;  /* uCode API:  IWL_RATE_MIMO3_6M_PLCP, etc. */
1682	u8 ieee;	/* MAC header:  IWL_RATE_6M_IEEE, etc. */
1683};
1684
1685void __iwl_mvm_mac_stop(struct iwl_mvm *mvm, bool suspend);
1686int __iwl_mvm_mac_start(struct iwl_mvm *mvm);
1687
1688/******************
1689 * MVM Methods
1690 ******************/
1691/* uCode */
1692int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm);
1693
1694/* Utils */
1695int iwl_mvm_legacy_hw_idx_to_mac80211_idx(u32 rate_n_flags,
1696					  enum nl80211_band band);
1697int iwl_mvm_legacy_rate_to_mac80211_idx(u32 rate_n_flags,
1698					enum nl80211_band band);
1699void iwl_mvm_hwrate_to_tx_rate(u32 rate_n_flags,
1700			       enum nl80211_band band,
1701			       struct ieee80211_tx_rate *r);
1702u8 iwl_mvm_mac80211_idx_to_hwrate(const struct iwl_fw *fw, int rate_idx);
1703u8 iwl_mvm_mac80211_ac_to_ucode_ac(enum ieee80211_ac_numbers ac);
1704bool iwl_mvm_is_nic_ack_enabled(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1705
1706static inline void iwl_mvm_dump_nic_error_log(struct iwl_mvm *mvm)
1707{
1708	iwl_fwrt_dump_error_logs(&mvm->fwrt);
1709}
1710
1711u8 first_antenna(u8 mask);
1712u8 iwl_mvm_next_antenna(struct iwl_mvm *mvm, u8 valid, u8 last_idx);
1713void iwl_mvm_get_sync_time(struct iwl_mvm *mvm, int clock_type, u32 *gp2,
1714			   u64 *boottime, ktime_t *realtime);
1715u32 iwl_mvm_get_systime(struct iwl_mvm *mvm);
1716
1717/* Tx / Host Commands */
1718int __must_check iwl_mvm_send_cmd(struct iwl_mvm *mvm,
1719				  struct iwl_host_cmd *cmd);
1720int __must_check iwl_mvm_send_cmd_pdu(struct iwl_mvm *mvm, u32 id,
1721				      u32 flags, u16 len, const void *data);
1722int __must_check iwl_mvm_send_cmd_status(struct iwl_mvm *mvm,
1723					 struct iwl_host_cmd *cmd,
1724					 u32 *status);
1725int __must_check iwl_mvm_send_cmd_pdu_status(struct iwl_mvm *mvm, u32 id,
1726					     u16 len, const void *data,
1727					     u32 *status);
1728int iwl_mvm_tx_skb_sta(struct iwl_mvm *mvm, struct sk_buff *skb,
1729		       struct ieee80211_sta *sta);
1730int iwl_mvm_tx_skb_non_sta(struct iwl_mvm *mvm, struct sk_buff *skb);
1731void iwl_mvm_set_tx_cmd(struct iwl_mvm *mvm, struct sk_buff *skb,
1732			struct iwl_tx_cmd_v6_params *tx_cmd_params,
1733			struct ieee80211_tx_info *info, u8 sta_id);
1734void iwl_mvm_set_tx_cmd_rate(struct iwl_mvm *mvm,
1735			     struct iwl_tx_cmd_v6_params *tx_cmd_params,
1736			     struct ieee80211_tx_info *info,
1737			     struct ieee80211_sta *sta, __le16 fc);
1738void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq);
1739unsigned int iwl_mvm_max_amsdu_size(struct iwl_mvm *mvm,
1740				    struct ieee80211_sta *sta,
1741				    unsigned int tid);
1742
1743#ifdef CONFIG_IWLWIFI_DEBUG
1744const char *iwl_mvm_get_tx_fail_reason(u32 status);
1745#else
1746static inline const char *iwl_mvm_get_tx_fail_reason(u32 status) { return ""; }
1747#endif
1748int iwl_mvm_flush_tx_path(struct iwl_mvm *mvm, u32 tfd_msk);
1749int iwl_mvm_flush_sta(struct iwl_mvm *mvm, u32 sta_id, u32 tfd_queue_mask);
1750int iwl_mvm_flush_sta_tids(struct iwl_mvm *mvm, u32 sta_id, u16 tids);
1751
1752/* Utils to extract sta related data */
1753__le32 iwl_mvm_get_sta_htc_flags(struct ieee80211_sta *sta,
1754				 struct ieee80211_link_sta *link_sta);
1755u8 iwl_mvm_get_sta_uapsd_acs(struct ieee80211_sta *sta);
1756u32 iwl_mvm_get_sta_ampdu_dens(struct ieee80211_link_sta *link_sta,
1757			       struct ieee80211_bss_conf *link_conf,
1758			       u32 *_agg_size);
1759int iwl_mvm_set_sta_pkt_ext(struct iwl_mvm *mvm,
1760			    struct ieee80211_link_sta *link_sta,
1761			    struct iwl_he_pkt_ext_v2 *pkt_ext);
1762
1763void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm);
1764
1765static inline void iwl_mvm_set_tx_cmd_ccmp(struct ieee80211_tx_info *info,
1766					   struct iwl_tx_cmd_v6_params *tx_cmd_params)
1767{
1768	struct ieee80211_key_conf *keyconf = info->control.hw_key;
1769
1770	tx_cmd_params->sec_ctl = TX_CMD_SEC_CCM;
1771	memcpy(tx_cmd_params->key, keyconf->key, keyconf->keylen);
1772}
1773
1774static inline void iwl_mvm_wait_for_async_handlers(struct iwl_mvm *mvm)
1775{
1776	flush_work(&mvm->async_handlers_wk);
1777}
1778
1779/* Statistics */
1780void iwl_mvm_handle_rx_system_oper_stats(struct iwl_mvm *mvm,
1781					 struct iwl_rx_cmd_buffer *rxb);
1782void iwl_mvm_handle_rx_system_oper_part1_stats(struct iwl_mvm *mvm,
1783					       struct iwl_rx_cmd_buffer *rxb);
1784static inline void
1785iwl_mvm_handle_rx_system_end_stats_notif(struct iwl_mvm *mvm,
1786					 struct iwl_rx_cmd_buffer *rxb)
1787{
1788}
1789
1790void iwl_mvm_handle_rx_statistics(struct iwl_mvm *mvm,
1791				  struct iwl_rx_packet *pkt);
1792void iwl_mvm_rx_statistics(struct iwl_mvm *mvm,
1793			   struct iwl_rx_cmd_buffer *rxb);
1794int iwl_mvm_request_statistics(struct iwl_mvm *mvm, bool clear);
1795int iwl_mvm_request_periodic_system_statistics(struct iwl_mvm *mvm,
1796					       bool enable);
1797void iwl_mvm_accu_radio_stats(struct iwl_mvm *mvm);
1798
1799/* NVM */
1800int iwl_nvm_init(struct iwl_mvm *mvm);
1801int iwl_mvm_load_nvm_to_nic(struct iwl_mvm *mvm);
1802
1803static inline u8 iwl_mvm_get_valid_tx_ant(struct iwl_mvm *mvm)
1804{
1805	u8 tx_ant = mvm->fw->valid_tx_ant;
1806
1807	if (mvm->nvm_data && mvm->nvm_data->valid_tx_ant)
1808		tx_ant &= mvm->nvm_data->valid_tx_ant;
1809
1810	if (mvm->set_tx_ant)
1811		tx_ant &= mvm->set_tx_ant;
1812
1813	return tx_ant;
1814}
1815
1816static inline u8 iwl_mvm_get_valid_rx_ant(struct iwl_mvm *mvm)
1817{
1818	u8 rx_ant = mvm->fw->valid_rx_ant;
1819
1820	if (mvm->nvm_data && mvm->nvm_data->valid_rx_ant)
1821		rx_ant &= mvm->nvm_data->valid_rx_ant;
1822
1823	if (mvm->set_rx_ant)
1824		rx_ant &= mvm->set_rx_ant;
1825
1826	return rx_ant;
1827
1828}
1829
1830static inline void iwl_mvm_toggle_tx_ant(struct iwl_mvm *mvm, u8 *ant)
1831{
1832	*ant = iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm), *ant);
1833}
1834
1835static inline u32 iwl_mvm_get_phy_config(struct iwl_mvm *mvm)
1836{
1837	u32 phy_config = ~(FW_PHY_CFG_TX_CHAIN |
1838			   FW_PHY_CFG_RX_CHAIN);
1839	u32 valid_rx_ant = iwl_mvm_get_valid_rx_ant(mvm);
1840	u32 valid_tx_ant = iwl_mvm_get_valid_tx_ant(mvm);
1841
1842	phy_config |= valid_tx_ant << FW_PHY_CFG_TX_CHAIN_POS |
1843		      valid_rx_ant << FW_PHY_CFG_RX_CHAIN_POS;
1844
1845	return mvm->fw->phy_config & phy_config;
1846}
1847
1848int iwl_mvm_up(struct iwl_mvm *mvm);
1849int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm);
1850
1851int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm);
1852
1853void iwl_mvm_mac_init_mvmvif(struct iwl_mvm *mvm, struct iwl_mvm_vif *mvmvif);
1854
1855/*
1856 * FW notifications / CMD responses handlers
1857 * Convention: iwl_mvm_rx_<NAME OF THE CMD>
1858 */
1859void iwl_mvm_rx_mq(struct iwl_op_mode *op_mode,
1860		   struct napi_struct *napi,
1861		   struct iwl_rx_cmd_buffer *rxb);
1862void iwl_mvm_rx_rx_phy_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1863void iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct napi_struct *napi,
1864			struct iwl_rx_cmd_buffer *rxb);
1865void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi,
1866			struct iwl_rx_cmd_buffer *rxb, int queue);
1867void iwl_mvm_rx_monitor_no_data(struct iwl_mvm *mvm, struct napi_struct *napi,
1868				struct iwl_rx_cmd_buffer *rxb, int queue);
1869void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
1870			      struct iwl_rx_cmd_buffer *rxb, int queue);
1871void iwl_mvm_rx_bar_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
1872				  struct iwl_rx_cmd_buffer *rxb, int queue);
1873void iwl_mvm_rx_queue_notif(struct iwl_mvm *mvm, struct napi_struct *napi,
1874			    struct iwl_rx_cmd_buffer *rxb, int queue);
1875void iwl_mvm_rx_tx_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1876void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm,
1877				   struct iwl_rx_cmd_buffer *rxb);
1878void iwl_mvm_send_recovery_cmd(struct iwl_mvm *mvm, u32 flags);
1879void iwl_mvm_rx_ba_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1880void iwl_mvm_rx_ant_coupling_notif(struct iwl_mvm *mvm,
1881				   struct iwl_rx_cmd_buffer *rxb);
1882void iwl_mvm_rx_fw_error(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1883void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
1884			     struct iwl_rx_cmd_buffer *rxb);
1885void iwl_mvm_rx_shared_mem_cfg_notif(struct iwl_mvm *mvm,
1886				     struct iwl_rx_cmd_buffer *rxb);
1887
1888/* MVM PHY */
1889struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm);
1890int iwl_mvm_phy_ctxt_add(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
1891			 const struct cfg80211_chan_def *chandef,
1892			 const struct cfg80211_chan_def *ap,
1893			 u8 chains_static, u8 chains_dynamic);
1894int iwl_mvm_phy_ctxt_changed(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
1895			     const struct cfg80211_chan_def *chandef,
1896			     const struct cfg80211_chan_def *ap,
1897			     u8 chains_static, u8 chains_dynamic);
1898void iwl_mvm_phy_ctxt_ref(struct iwl_mvm *mvm,
1899			  struct iwl_mvm_phy_ctxt *ctxt);
1900void iwl_mvm_phy_ctxt_unref(struct iwl_mvm *mvm,
1901			    struct iwl_mvm_phy_ctxt *ctxt);
1902int iwl_mvm_phy_ctx_count(struct iwl_mvm *mvm);
1903u8 iwl_mvm_get_channel_width(const struct cfg80211_chan_def *chandef);
1904u8 iwl_mvm_get_ctrl_pos(const struct cfg80211_chan_def *chandef);
1905int iwl_mvm_phy_send_rlc(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
1906			 u8 chains_static, u8 chains_dynamic);
1907
1908/* MAC (virtual interface) programming */
1909
1910void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1911				 struct ieee80211_vif *vif);
1912void iwl_mvm_set_fw_basic_rates(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1913				struct iwl_mvm_vif_link_info *link_info,
1914				__le32 *cck_rates, __le32 *ofdm_rates);
1915void iwl_mvm_set_fw_protection_flags(struct iwl_mvm *mvm,
1916				     struct ieee80211_vif *vif,
1917				     struct ieee80211_bss_conf *link_conf,
1918				     __le32 *protection_flags, u32 ht_flag,
1919				     u32 tgg_flag);
1920void iwl_mvm_set_fw_qos_params(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1921			       struct ieee80211_bss_conf *link_conf,
1922			       struct iwl_ac_qos *ac, __le32 *qos_flags);
1923bool iwl_mvm_set_fw_mu_edca_params(struct iwl_mvm *mvm,
1924				   const struct iwl_mvm_vif_link_info *link_info,
1925				   struct iwl_he_backoff_conf *trig_based_txf);
1926void iwl_mvm_set_fw_dtim_tbtt(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1927			      struct ieee80211_bss_conf *link_conf,
1928			      __le64 *dtim_tsf, __le32 *dtim_time,
1929			      __le32 *assoc_beacon_arrive_time);
1930__le32 iwl_mac_ctxt_p2p_dev_has_extended_disc(struct iwl_mvm *mvm,
1931					      struct ieee80211_vif *vif);
1932void iwl_mvm_mac_ctxt_cmd_ap_set_filter_flags(struct iwl_mvm *mvm,
1933					      struct iwl_mvm_vif *mvmvif,
1934					      __le32 *filter_flags,
1935					      int accept_probe_req_flag,
1936					      int accept_beacon_flag);
1937int iwl_mvm_get_mac_type(struct ieee80211_vif *vif);
1938__le32 iwl_mvm_mac_ctxt_cmd_p2p_sta_get_oppps_ctwin(struct iwl_mvm *mvm,
1939						    struct ieee80211_vif *vif);
1940u32 iwl_mvm_mac_ctxt_cmd_sta_get_twt_policy(struct iwl_mvm *mvm,
1941					    struct ieee80211_vif *vif);
1942int iwl_mvm_mld_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1943int iwl_mvm_mld_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1944				 bool force_assoc_off);
1945int iwl_mvm_mld_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1946int iwl_mvm_mac_ctxt_init(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1947int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1948int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1949			     bool force_assoc_off, const u8 *bssid_override);
1950int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1951int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm,
1952				    struct ieee80211_vif *vif,
1953				    struct ieee80211_bss_conf *link_conf);
1954int iwl_mvm_mac_ctxt_send_beacon_cmd(struct iwl_mvm *mvm,
1955				     struct sk_buff *beacon,
1956				     void *data, int len);
1957u8 iwl_mvm_mac_ctxt_get_beacon_rate(struct iwl_mvm *mvm,
1958				    struct ieee80211_tx_info *info,
1959				    struct ieee80211_vif *vif);
1960u8 iwl_mvm_mac_ctxt_get_lowest_rate(struct iwl_mvm *mvm,
1961				    struct ieee80211_tx_info *info,
1962				    struct ieee80211_vif *vif);
1963u16 iwl_mvm_mac_ctxt_get_beacon_flags(const struct iwl_fw *fw,
1964				      u8 rate_idx);
1965void iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm *mvm,
1966			      __le32 *tim_index, __le32 *tim_size,
1967			      u8 *beacon, u32 frame_size);
1968void iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
1969			     struct iwl_rx_cmd_buffer *rxb);
1970void iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm,
1971				     struct iwl_rx_cmd_buffer *rxb);
1972void iwl_mvm_rx_missed_beacons_notif_legacy(struct iwl_mvm *mvm,
1973					    struct iwl_rx_cmd_buffer *rxb);
1974void iwl_mvm_rx_stored_beacon_notif(struct iwl_mvm *mvm,
1975				    struct iwl_rx_cmd_buffer *rxb);
1976void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1977			       struct iwl_rx_cmd_buffer *rxb);
1978void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1979void iwl_mvm_window_status_notif(struct iwl_mvm *mvm,
1980				 struct iwl_rx_cmd_buffer *rxb);
1981void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm *mvm,
1982				    struct ieee80211_vif *vif);
1983void iwl_mvm_probe_resp_data_notif(struct iwl_mvm *mvm,
1984				   struct iwl_rx_cmd_buffer *rxb);
1985void iwl_mvm_channel_switch_start_notif(struct iwl_mvm *mvm,
1986					struct iwl_rx_cmd_buffer *rxb);
1987void iwl_mvm_channel_switch_error_notif(struct iwl_mvm *mvm,
1988					struct iwl_rx_cmd_buffer *rxb);
1989void iwl_mvm_rx_beacon_filter_notif(struct iwl_mvm *mvm,
1990				    struct iwl_rx_cmd_buffer *rxb);
1991
1992/* Bindings */
1993int iwl_mvm_binding_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1994int iwl_mvm_binding_remove_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1995u32 iwl_mvm_get_lmac_id(struct iwl_mvm *mvm, enum nl80211_band band);
1996
1997/* Links */
1998void iwl_mvm_init_link(struct iwl_mvm_vif_link_info *link);
1999void iwl_mvm_set_link_fw_id(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2000			    struct ieee80211_bss_conf *link_conf);
2001int iwl_mvm_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2002		     struct ieee80211_bss_conf *link_conf);
2003int iwl_mvm_link_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2004			 struct ieee80211_bss_conf *link_conf,
2005			 u32 changes, bool active);
2006int iwl_mvm_remove_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2007			struct ieee80211_bss_conf *link_conf);
2008int iwl_mvm_disable_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2009			 struct ieee80211_bss_conf *link_conf);
2010
2011u8 iwl_mvm_get_primary_link(struct ieee80211_vif *vif);
2012
2013struct iwl_mvm_link_sel_data {
2014	u8 link_id;
2015	const struct cfg80211_chan_def *chandef;
2016	s32 signal;
2017	u16 grade;
2018};
2019
2020#if IS_ENABLED(CONFIG_IWLWIFI_KUNIT_TESTS)
2021extern const struct iwl_hcmd_arr iwl_mvm_groups[];
2022extern const unsigned int iwl_mvm_groups_size;
2023#endif
2024
2025/* AP and IBSS */
2026bool iwl_mvm_start_ap_ibss_common(struct ieee80211_hw *hw,
2027				  struct ieee80211_vif *vif, int *ret);
2028void iwl_mvm_stop_ap_ibss_common(struct iwl_mvm *mvm,
2029				 struct ieee80211_vif *vif);
2030
2031/* BSS Info */
2032void iwl_mvm_bss_info_changed_station_common(struct iwl_mvm *mvm,
2033					     struct ieee80211_vif *vif,
2034					     struct ieee80211_bss_conf *link_conf,
2035					     u64 changes);
2036void iwl_mvm_bss_info_changed_station_assoc(struct iwl_mvm *mvm,
2037					    struct ieee80211_vif *vif,
2038					    u64 changes);
2039
2040/* ROC */
2041/**
2042 * struct iwl_mvm_roc_ops - callbacks for the remain_on_channel()
2043 *
2044 * Since the only difference between both MLD and
2045 * non-MLD versions of remain_on_channel() is these function calls,
2046 * each version will send its specific function calls to
2047 * %iwl_mvm_roc_common().
2048 *
2049 * @add_aux_sta_for_hs20: pointer to the function that adds an aux sta
2050 *	for Hot Spot 2.0
2051 * @link: For a P2P Device interface, pointer to a function that links the
2052 *      MAC/Link to the PHY context
2053 */
2054struct iwl_mvm_roc_ops {
2055	int (*add_aux_sta_for_hs20)(struct iwl_mvm *mvm, u32 lmac_id);
2056	int (*link)(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2057};
2058
2059int iwl_mvm_roc_common(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2060		       struct ieee80211_channel *channel, int duration,
2061		       enum ieee80211_roc_type type,
2062		       const struct iwl_mvm_roc_ops *ops);
2063int iwl_mvm_cancel_roc(struct ieee80211_hw *hw,
2064		       struct ieee80211_vif *vif);
2065/*Session Protection */
2066void iwl_mvm_protect_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2067			   u32 duration_override, unsigned int link_id);
2068
2069/* Quota management */
2070static inline size_t iwl_mvm_quota_cmd_size(struct iwl_mvm *mvm)
2071{
2072	return iwl_mvm_has_quota_low_latency(mvm) ?
2073		sizeof(struct iwl_time_quota_cmd) :
2074		sizeof(struct iwl_time_quota_cmd_v1);
2075}
2076
2077static inline struct iwl_time_quota_data
2078*iwl_mvm_quota_cmd_get_quota(struct iwl_mvm *mvm,
2079			     struct iwl_time_quota_cmd *cmd,
2080			     int i)
2081{
2082	struct iwl_time_quota_data_v1 *quotas;
2083
2084	if (iwl_mvm_has_quota_low_latency(mvm))
2085		return &cmd->quotas[i];
2086
2087	quotas = (struct iwl_time_quota_data_v1 *)cmd->quotas;
2088	return (struct iwl_time_quota_data *)&quotas[i];
2089}
2090
2091int iwl_mvm_update_quotas(struct iwl_mvm *mvm, bool force_upload,
2092			  struct ieee80211_vif *disabled_vif);
2093
2094/* Scanning */
2095int iwl_mvm_reg_scan_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2096			   struct cfg80211_scan_request *req,
2097			   struct ieee80211_scan_ies *ies);
2098size_t iwl_mvm_scan_size(struct iwl_mvm *mvm);
2099int iwl_mvm_scan_stop(struct iwl_mvm *mvm, int type, bool notify);
2100
2101int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm);
2102void iwl_mvm_report_scan_aborted(struct iwl_mvm *mvm);
2103void iwl_mvm_scan_timeout_wk(struct work_struct *work);
2104void iwl_mvm_rx_channel_survey_notif(struct iwl_mvm *mvm,
2105				     struct iwl_rx_cmd_buffer *rxb);
2106
2107/* Scheduled scan */
2108void iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm *mvm,
2109					 struct iwl_rx_cmd_buffer *rxb);
2110void iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm *mvm,
2111					      struct iwl_rx_cmd_buffer *rxb);
2112int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
2113			     struct ieee80211_vif *vif,
2114			     struct cfg80211_sched_scan_request *req,
2115			     struct ieee80211_scan_ies *ies,
2116			     int type);
2117void iwl_mvm_rx_scan_match_found(struct iwl_mvm *mvm,
2118				 struct iwl_rx_cmd_buffer *rxb);
2119
2120/* UMAC scan */
2121int iwl_mvm_config_scan(struct iwl_mvm *mvm);
2122void iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,
2123					 struct iwl_rx_cmd_buffer *rxb);
2124void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm,
2125					      struct iwl_rx_cmd_buffer *rxb);
2126
2127/* MVM debugfs */
2128#ifdef CONFIG_IWLWIFI_DEBUGFS
2129void iwl_mvm_dbgfs_register(struct iwl_mvm *mvm);
2130void iwl_mvm_vif_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
2131void iwl_mvm_vif_dbgfs_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2132void iwl_mvm_vif_dbgfs_rm_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2133#else
2134static inline void iwl_mvm_dbgfs_register(struct iwl_mvm *mvm)
2135{
2136}
2137static inline void
2138iwl_mvm_vif_dbgfs_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2139{
2140}
2141static inline void
2142iwl_mvm_vif_dbgfs_rm_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2143{
2144}
2145#endif /* CONFIG_IWLWIFI_DEBUGFS */
2146
2147/* rate scaling */
2148int iwl_mvm_send_lq_cmd(struct iwl_mvm *mvm, struct iwl_lq_cmd *lq);
2149void iwl_mvm_update_frame_stats(struct iwl_mvm *mvm, u32 rate, bool agg);
2150int rs_pretty_print_rate_v1(char *buf, int bufsz, const u32 rate);
2151void rs_update_last_rssi(struct iwl_mvm *mvm,
2152			 struct iwl_mvm_sta *mvmsta,
2153			 struct ieee80211_rx_status *rx_status);
2154
2155/* power management */
2156int iwl_mvm_power_update_device(struct iwl_mvm *mvm);
2157int iwl_mvm_power_update_mac(struct iwl_mvm *mvm);
2158int iwl_mvm_power_update_ps(struct iwl_mvm *mvm);
2159int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2160				 char *buf, int bufsz);
2161
2162void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2163void iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
2164					      struct iwl_rx_cmd_buffer *rxb);
2165
2166#ifdef CONFIG_IWLWIFI_LEDS
2167int iwl_mvm_leds_init(struct iwl_mvm *mvm);
2168void iwl_mvm_leds_exit(struct iwl_mvm *mvm);
2169void iwl_mvm_leds_sync(struct iwl_mvm *mvm);
2170#else
2171static inline int iwl_mvm_leds_init(struct iwl_mvm *mvm)
2172{
2173	return 0;
2174}
2175static inline void iwl_mvm_leds_exit(struct iwl_mvm *mvm)
2176{
2177}
2178static inline void iwl_mvm_leds_sync(struct iwl_mvm *mvm)
2179{
2180}
2181#endif
2182
2183/* D3 (WoWLAN, NetDetect) */
2184int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan);
2185int iwl_mvm_resume(struct ieee80211_hw *hw);
2186void iwl_mvm_set_wakeup(struct ieee80211_hw *hw, bool enabled);
2187void iwl_mvm_set_rekey_data(struct ieee80211_hw *hw,
2188			    struct ieee80211_vif *vif,
2189			    struct cfg80211_gtk_rekey_data *data);
2190void iwl_mvm_ipv6_addr_change(struct ieee80211_hw *hw,
2191			      struct ieee80211_vif *vif,
2192			      struct inet6_dev *idev);
2193void iwl_mvm_set_default_unicast_key(struct ieee80211_hw *hw,
2194				     struct ieee80211_vif *vif, int idx);
2195extern const struct file_operations iwl_dbgfs_d3_test_ops;
2196#ifdef CONFIG_PM_SLEEP
2197void iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm,
2198				 struct ieee80211_vif *vif);
2199void iwl_mvm_fast_suspend(struct iwl_mvm *mvm);
2200int iwl_mvm_fast_resume(struct iwl_mvm *mvm);
2201#else
2202static inline void
2203iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2204{
2205}
2206
2207static inline void iwl_mvm_fast_suspend(struct iwl_mvm *mvm)
2208{
2209}
2210
2211static inline int iwl_mvm_fast_resume(struct iwl_mvm *mvm)
2212{
2213	return 0;
2214}
2215#endif
2216void iwl_mvm_set_wowlan_qos_seq(struct iwl_mvm_sta *mvm_ap_sta,
2217				struct iwl_wowlan_config_cmd_v6 *cmd);
2218int iwl_mvm_send_proto_offload(struct iwl_mvm *mvm,
2219			       struct ieee80211_vif *vif,
2220			       bool disable_offloading,
2221			       bool offload_ns,
2222			       u32 cmd_flags,
2223			       u8 sta_id);
2224
2225/* BT Coex */
2226int iwl_mvm_send_bt_init_conf(struct iwl_mvm *mvm);
2227void iwl_mvm_rx_bt_coex_old_notif(struct iwl_mvm *mvm,
2228				  struct iwl_rx_cmd_buffer *rxb);
2229void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2230			   enum ieee80211_rssi_event_data);
2231void iwl_mvm_bt_coex_vif_change(struct iwl_mvm *mvm);
2232u16 iwl_mvm_coex_agg_time_limit(struct iwl_mvm *mvm,
2233				struct ieee80211_sta *sta);
2234bool iwl_mvm_bt_coex_is_mimo_allowed(struct iwl_mvm *mvm,
2235				     struct ieee80211_sta *sta);
2236bool iwl_mvm_bt_coex_is_ant_avail(struct iwl_mvm *mvm, u8 ant);
2237bool iwl_mvm_bt_coex_is_shared_ant_avail(struct iwl_mvm *mvm);
2238bool iwl_mvm_bt_coex_is_tpc_allowed(struct iwl_mvm *mvm,
2239				    enum nl80211_band band);
2240u8 iwl_mvm_bt_coex_get_single_ant_msk(struct iwl_mvm *mvm, u8 enabled_ants);
2241u8 iwl_mvm_bt_coex_tx_prio(struct iwl_mvm *mvm, struct ieee80211_hdr *hdr,
2242			   struct ieee80211_tx_info *info, u8 ac);
2243
2244/* beacon filtering */
2245#ifdef CONFIG_IWLWIFI_DEBUGFS
2246void
2247iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
2248					 struct iwl_beacon_filter_cmd *cmd);
2249#else
2250static inline void
2251iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
2252					 struct iwl_beacon_filter_cmd *cmd)
2253{}
2254#endif
2255int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
2256				 struct ieee80211_vif *vif);
2257int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
2258				  struct ieee80211_vif *vif);
2259/* SMPS */
2260void iwl_mvm_update_smps(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2261				enum iwl_mvm_smps_type_request req_type,
2262				enum ieee80211_smps_mode smps_request,
2263				unsigned int link_id);
2264void
2265iwl_mvm_update_smps_on_active_links(struct iwl_mvm *mvm,
2266				    struct ieee80211_vif *vif,
2267				    enum iwl_mvm_smps_type_request req_type,
2268				    enum ieee80211_smps_mode smps_request);
2269bool iwl_mvm_rx_diversity_allowed(struct iwl_mvm *mvm,
2270				  struct iwl_mvm_phy_ctxt *ctxt);
2271void iwl_mvm_update_link_smps(struct ieee80211_vif *vif,
2272			      struct ieee80211_bss_conf *link_conf);
2273
2274/* Low latency */
2275int iwl_mvm_update_low_latency(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2276			      bool low_latency,
2277			      enum iwl_mvm_low_latency_cause cause);
2278/* get SystemLowLatencyMode - only needed for beacon threshold? */
2279bool iwl_mvm_low_latency(struct iwl_mvm *mvm);
2280bool iwl_mvm_low_latency_band(struct iwl_mvm *mvm, enum nl80211_band band);
2281void iwl_mvm_send_low_latency_cmd(struct iwl_mvm *mvm, bool low_latency,
2282				  u16 mac_id);
2283
2284/* get VMACLowLatencyMode */
2285static inline bool iwl_mvm_vif_low_latency(struct iwl_mvm_vif *mvmvif)
2286{
2287	/*
2288	 * should this consider associated/active/... state?
2289	 *
2290	 * Normally low-latency should only be active on interfaces
2291	 * that are active, but at least with debugfs it can also be
2292	 * enabled on interfaces that aren't active. However, when
2293	 * interface aren't active then they aren't added into the
2294	 * binding, so this has no real impact. For now, just return
2295	 * the current desired low-latency state.
2296	 */
2297	return mvmvif->low_latency_actual;
2298}
2299
2300static inline
2301void iwl_mvm_vif_set_low_latency(struct iwl_mvm_vif *mvmvif, bool set,
2302				 enum iwl_mvm_low_latency_cause cause)
2303{
2304	u8 new_state;
2305
2306	if (set)
2307		mvmvif->low_latency |= cause;
2308	else
2309		mvmvif->low_latency &= ~cause;
2310
2311	/*
2312	 * if LOW_LATENCY_DEBUGFS_FORCE_ENABLE is enabled no changes are
2313	 * allowed to actual mode.
2314	 */
2315	if (mvmvif->low_latency & LOW_LATENCY_DEBUGFS_FORCE_ENABLE &&
2316	    cause != LOW_LATENCY_DEBUGFS_FORCE_ENABLE)
2317		return;
2318
2319	if (cause == LOW_LATENCY_DEBUGFS_FORCE_ENABLE && set)
2320		/*
2321		 * We enter force state
2322		 */
2323		new_state = !!(mvmvif->low_latency &
2324			       LOW_LATENCY_DEBUGFS_FORCE);
2325	else
2326		/*
2327		 * Check if any other one set low latency
2328		 */
2329		new_state = !!(mvmvif->low_latency &
2330				  ~(LOW_LATENCY_DEBUGFS_FORCE_ENABLE |
2331				    LOW_LATENCY_DEBUGFS_FORCE));
2332
2333	mvmvif->low_latency_actual = new_state;
2334}
2335
2336/* Return a bitmask with all the hw supported queues, except for the
2337 * command queue, which can't be flushed.
2338 */
2339static inline u32 iwl_mvm_flushable_queues(struct iwl_mvm *mvm)
2340{
2341	return ((BIT(mvm->trans->mac_cfg->base->num_of_queues) - 1) &
2342		~BIT(IWL_MVM_DQA_CMD_QUEUE));
2343}
2344
2345void iwl_mvm_stop_device(struct iwl_mvm *mvm);
2346
2347/* Thermal management and CT-kill */
2348void iwl_mvm_tt_tx_backoff(struct iwl_mvm *mvm, u32 backoff);
2349void iwl_mvm_temp_notif(struct iwl_mvm *mvm,
2350			struct iwl_rx_cmd_buffer *rxb);
2351void iwl_mvm_tt_handler(struct iwl_mvm *mvm);
2352void iwl_mvm_thermal_initialize(struct iwl_mvm *mvm, u32 min_backoff);
2353void iwl_mvm_thermal_exit(struct iwl_mvm *mvm);
2354void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state);
2355int iwl_mvm_get_temp(struct iwl_mvm *mvm, s32 *temp);
2356void iwl_mvm_ct_kill_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
2357void iwl_mvm_enter_ctkill(struct iwl_mvm *mvm);
2358int iwl_mvm_send_temp_report_ths_cmd(struct iwl_mvm *mvm);
2359int iwl_mvm_ctdp_command(struct iwl_mvm *mvm, u32 op, u32 budget);
2360
2361#if IS_ENABLED(CONFIG_IWLMEI)
2362
2363/* vendor commands */
2364void iwl_mvm_vendor_cmds_register(struct iwl_mvm *mvm);
2365
2366#else
2367
2368static inline void iwl_mvm_vendor_cmds_register(struct iwl_mvm *mvm) {}
2369
2370#endif
2371
2372/* Location Aware Regulatory */
2373struct iwl_mcc_update_resp_v8 *
2374iwl_mvm_update_mcc(struct iwl_mvm *mvm, const char *alpha2,
2375		   enum iwl_mcc_source src_id);
2376int iwl_mvm_init_mcc(struct iwl_mvm *mvm);
2377void iwl_mvm_rx_chub_update_mcc(struct iwl_mvm *mvm,
2378				struct iwl_rx_cmd_buffer *rxb);
2379struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
2380						  const char *alpha2,
2381						  enum iwl_mcc_source src_id,
2382						  bool *changed);
2383struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
2384							  bool *changed);
2385int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm, bool force_regd_sync);
2386void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm);
2387
2388/* smart fifo */
2389int iwl_mvm_sf_update(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2390		      bool added_vif);
2391
2392/* FTM responder */
2393int iwl_mvm_ftm_start_responder(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2394				struct ieee80211_bss_conf *bss_conf);
2395void iwl_mvm_ftm_restart_responder(struct iwl_mvm *mvm,
2396				   struct ieee80211_vif *vif,
2397				   struct ieee80211_bss_conf *bss_conf);
2398void iwl_mvm_ftm_responder_stats(struct iwl_mvm *mvm,
2399				 struct iwl_rx_cmd_buffer *rxb);
2400void iwl_mvm_ftm_responder_clear(struct iwl_mvm *mvm,
2401				 struct ieee80211_vif *vif);
2402
2403/* FTM initiator */
2404void iwl_mvm_ftm_restart(struct iwl_mvm *mvm);
2405void iwl_mvm_ftm_range_resp(struct iwl_mvm *mvm,
2406			    struct iwl_rx_cmd_buffer *rxb);
2407void iwl_mvm_ftm_lc_notif(struct iwl_mvm *mvm,
2408			  struct iwl_rx_cmd_buffer *rxb);
2409int iwl_mvm_ftm_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2410		      struct cfg80211_pmsr_request *request);
2411void iwl_mvm_ftm_abort(struct iwl_mvm *mvm, struct cfg80211_pmsr_request *req);
2412void iwl_mvm_ftm_initiator_smooth_config(struct iwl_mvm *mvm);
2413void iwl_mvm_ftm_initiator_smooth_stop(struct iwl_mvm *mvm);
2414
2415/* TDLS */
2416
2417/*
2418 * We use TID 4 (VI) as a FW-used-only TID when TDLS connections are present.
2419 * This TID is marked as used vs the AP and all connected TDLS peers.
2420 */
2421#define IWL_MVM_TDLS_FW_TID 4
2422
2423int iwl_mvm_tdls_sta_count(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2424void iwl_mvm_teardown_tdls_peers(struct iwl_mvm *mvm);
2425void iwl_mvm_recalc_tdls_state(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2426			       bool sta_added);
2427void iwl_mvm_mac_mgd_protect_tdls_discover(struct ieee80211_hw *hw,
2428					   struct ieee80211_vif *vif,
2429					   unsigned int link_id);
2430int iwl_mvm_tdls_channel_switch(struct ieee80211_hw *hw,
2431				struct ieee80211_vif *vif,
2432				struct ieee80211_sta *sta, u8 oper_class,
2433				struct cfg80211_chan_def *chandef,
2434				struct sk_buff *tmpl_skb, u32 ch_sw_tm_ie);
2435void iwl_mvm_tdls_recv_channel_switch(struct ieee80211_hw *hw,
2436				      struct ieee80211_vif *vif,
2437				      struct ieee80211_tdls_ch_sw_params *params);
2438void iwl_mvm_tdls_cancel_channel_switch(struct ieee80211_hw *hw,
2439					struct ieee80211_vif *vif,
2440					struct ieee80211_sta *sta);
2441void iwl_mvm_rx_tdls_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
2442void iwl_mvm_tdls_ch_switch_work(struct work_struct *work);
2443
2444void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
2445				     enum iwl_mvm_rxq_notif_type type,
2446				     bool sync,
2447				     const void *data, u32 size);
2448struct ieee80211_vif *iwl_mvm_get_bss_vif(struct iwl_mvm *mvm);
2449struct ieee80211_vif *iwl_mvm_get_vif_by_macid(struct iwl_mvm *mvm, u32 macid);
2450bool iwl_mvm_is_vif_assoc(struct iwl_mvm *mvm);
2451
2452#define MVM_TCM_PERIOD_MSEC 500
2453#define MVM_TCM_PERIOD (HZ * MVM_TCM_PERIOD_MSEC / 1000)
2454#define MVM_LL_PERIOD (10 * HZ)
2455void iwl_mvm_tcm_work(struct work_struct *work);
2456void iwl_mvm_recalc_tcm(struct iwl_mvm *mvm);
2457void iwl_mvm_pause_tcm(struct iwl_mvm *mvm, bool with_cancel);
2458void iwl_mvm_resume_tcm(struct iwl_mvm *mvm);
2459void iwl_mvm_tcm_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2460void iwl_mvm_tcm_rm_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2461u8 iwl_mvm_tcm_load_percentage(u32 airtime, u32 elapsed);
2462
2463unsigned int iwl_mvm_get_wd_timeout(struct iwl_mvm *mvm,
2464				    struct ieee80211_vif *vif);
2465void iwl_mvm_connection_loss(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2466			     const char *errmsg);
2467void iwl_mvm_event_frame_timeout_callback(struct iwl_mvm *mvm,
2468					  struct ieee80211_vif *vif,
2469					  const struct ieee80211_sta *sta,
2470					  u16 tid);
2471void iwl_mvm_mei_scan_filter_init(struct iwl_mei_scan_filter *mei_scan_filter);
2472
2473void iwl_mvm_ptp_init(struct iwl_mvm *mvm);
2474void iwl_mvm_ptp_remove(struct iwl_mvm *mvm);
2475u64 iwl_mvm_ptp_get_adj_time(struct iwl_mvm *mvm, u64 base_time);
2476int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b);
2477int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm);
2478int iwl_mvm_ppag_send_cmd(struct iwl_mvm *mvm);
2479void iwl_mvm_get_bios_tables(struct iwl_mvm *mvm);
2480#ifdef CONFIG_IWLWIFI_DEBUGFS
2481void iwl_mvm_link_sta_add_debugfs(struct ieee80211_hw *hw,
2482				  struct ieee80211_vif *vif,
2483				  struct ieee80211_link_sta *link_sta,
2484				  struct dentry *dir);
2485void iwl_mvm_link_add_debugfs(struct ieee80211_hw *hw,
2486			      struct ieee80211_vif *vif,
2487			      struct ieee80211_bss_conf *link_conf,
2488			      struct dentry *dir);
2489#endif
2490
2491/* new MLD related APIs */
2492int iwl_mvm_sec_key_add(struct iwl_mvm *mvm,
2493			struct ieee80211_vif *vif,
2494			struct ieee80211_sta *sta,
2495			struct ieee80211_key_conf *keyconf);
2496int iwl_mvm_sec_key_del(struct iwl_mvm *mvm,
2497			struct ieee80211_vif *vif,
2498			struct ieee80211_sta *sta,
2499			struct ieee80211_key_conf *keyconf);
2500int iwl_mvm_sec_key_del_pasn(struct iwl_mvm *mvm,
2501			     struct ieee80211_vif *vif,
2502			     u32 sta_mask,
2503			     struct ieee80211_key_conf *keyconf);
2504void iwl_mvm_sec_key_remove_ap(struct iwl_mvm *mvm,
2505			       struct ieee80211_vif *vif,
2506			       struct iwl_mvm_vif_link_info *link,
2507			       unsigned int link_id);
2508int iwl_mvm_mld_update_sta_keys(struct iwl_mvm *mvm,
2509				struct ieee80211_vif *vif,
2510				struct ieee80211_sta *sta,
2511				u32 old_sta_mask,
2512				u32 new_sta_mask);
2513int iwl_mvm_mld_send_key(struct iwl_mvm *mvm, u32 sta_mask, u32 key_flags,
2514			 struct ieee80211_key_conf *keyconf);
2515u32 iwl_mvm_get_sec_flags(struct iwl_mvm *mvm,
2516			  struct ieee80211_vif *vif,
2517			  struct ieee80211_sta *sta,
2518			  struct ieee80211_key_conf *keyconf);
2519
2520bool iwl_rfi_supported(struct iwl_mvm *mvm);
2521int iwl_rfi_send_config_cmd(struct iwl_mvm *mvm,
2522			    struct iwl_rfi_lut_entry *rfi_table);
2523struct iwl_rfi_freq_table_resp_cmd *iwl_rfi_get_freq_table(struct iwl_mvm *mvm);
2524void iwl_rfi_deactivate_notif_handler(struct iwl_mvm *mvm,
2525				      struct iwl_rx_cmd_buffer *rxb);
2526
2527static inline u8 iwl_mvm_phy_band_from_nl80211(enum nl80211_band band)
2528{
2529	switch (band) {
2530	case NL80211_BAND_2GHZ:
2531		return PHY_BAND_24;
2532	case NL80211_BAND_5GHZ:
2533		return PHY_BAND_5;
2534	case NL80211_BAND_6GHZ:
2535		return PHY_BAND_6;
2536	default:
2537		WARN_ONCE(1, "Unsupported band (%u)\n", band);
2538		return PHY_BAND_5;
2539	}
2540}
2541
2542static inline u8 iwl_mvm_nl80211_band_from_phy(u8 phy_band)
2543{
2544	switch (phy_band) {
2545	case PHY_BAND_24:
2546		return NL80211_BAND_2GHZ;
2547	case PHY_BAND_5:
2548		return NL80211_BAND_5GHZ;
2549	case PHY_BAND_6:
2550		return NL80211_BAND_6GHZ;
2551	default:
2552		WARN_ONCE(1, "Unsupported phy band (%u)\n", phy_band);
2553		return NL80211_BAND_5GHZ;
2554	}
2555}
2556
2557/* Channel Switch */
2558void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk);
2559int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
2560				struct ieee80211_vif *vif,
2561				struct ieee80211_bss_conf *link);
2562
2563/* Channel Context */
2564/**
2565 * struct iwl_mvm_switch_vif_chanctx_ops - callbacks for switch_vif_chanctx()
2566 *
2567 * Since the only difference between both MLD and
2568 * non-MLD versions of switch_vif_chanctx() is these function calls,
2569 * each version will send its specific function calls to
2570 * %iwl_mvm_switch_vif_chanctx_common().
2571 *
2572 * @__assign_vif_chanctx: pointer to the function that assigns a chanctx to
2573 *	a given vif
2574 * @__unassign_vif_chanctx: pointer to the function that unassigns a chanctx to
2575 *	a given vif
2576 */
2577struct iwl_mvm_switch_vif_chanctx_ops {
2578	int (*__assign_vif_chanctx)(struct iwl_mvm *mvm,
2579				    struct ieee80211_vif *vif,
2580				    struct ieee80211_bss_conf *link_conf,
2581				    struct ieee80211_chanctx_conf *ctx,
2582				    bool switching_chanctx);
2583	void (*__unassign_vif_chanctx)(struct iwl_mvm *mvm,
2584				       struct ieee80211_vif *vif,
2585				       struct ieee80211_bss_conf *link_conf,
2586				       struct ieee80211_chanctx_conf *ctx,
2587				       bool switching_chanctx);
2588};
2589
2590int
2591iwl_mvm_switch_vif_chanctx_common(struct ieee80211_hw *hw,
2592				  struct ieee80211_vif_chanctx_switch *vifs,
2593				  int n_vifs,
2594				  enum ieee80211_chanctx_switch_mode mode,
2595				  const struct iwl_mvm_switch_vif_chanctx_ops *ops);
2596
2597/* Channel info utils */
2598static inline bool iwl_mvm_has_ultra_hb_channel(struct iwl_mvm *mvm)
2599{
2600	return fw_has_capa(&mvm->fw->ucode_capa,
2601			   IWL_UCODE_TLV_CAPA_ULTRA_HB_CHANNELS);
2602}
2603
2604static inline void *iwl_mvm_chan_info_cmd_tail(struct iwl_mvm *mvm,
2605					       struct iwl_fw_channel_info *ci)
2606{
2607	return (u8 *)ci + (iwl_mvm_has_ultra_hb_channel(mvm) ?
2608			   sizeof(struct iwl_fw_channel_info) :
2609			   sizeof(struct iwl_fw_channel_info_v1));
2610}
2611
2612static inline size_t iwl_mvm_chan_info_padding(struct iwl_mvm *mvm)
2613{
2614	return iwl_mvm_has_ultra_hb_channel(mvm) ? 0 :
2615		sizeof(struct iwl_fw_channel_info) -
2616		sizeof(struct iwl_fw_channel_info_v1);
2617}
2618
2619static inline void iwl_mvm_set_chan_info(struct iwl_mvm *mvm,
2620					 struct iwl_fw_channel_info *ci,
2621					 u32 chan, u8 band, u8 width,
2622					 u8 ctrl_pos)
2623{
2624	if (iwl_mvm_has_ultra_hb_channel(mvm)) {
2625		ci->channel = cpu_to_le32(chan);
2626		ci->band = band;
2627		ci->width = width;
2628		ci->ctrl_pos = ctrl_pos;
2629	} else {
2630		struct iwl_fw_channel_info_v1 *ci_v1 =
2631					(struct iwl_fw_channel_info_v1 *)ci;
2632
2633		ci_v1->channel = chan;
2634		ci_v1->band = band;
2635		ci_v1->width = width;
2636		ci_v1->ctrl_pos = ctrl_pos;
2637	}
2638}
2639
2640static inline void
2641iwl_mvm_set_chan_info_chandef(struct iwl_mvm *mvm,
2642			      struct iwl_fw_channel_info *ci,
2643			      const struct cfg80211_chan_def *chandef)
2644{
2645	enum nl80211_band band = chandef->chan->band;
2646
2647	iwl_mvm_set_chan_info(mvm, ci, chandef->chan->hw_value,
2648			      iwl_mvm_phy_band_from_nl80211(band),
2649			      iwl_mvm_get_channel_width(chandef),
2650			      iwl_mvm_get_ctrl_pos(chandef));
2651}
2652
2653static inline int iwl_umac_scan_get_max_profiles(const struct iwl_fw *fw)
2654{
2655	u8 ver = iwl_fw_lookup_cmd_ver(fw, SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
2656				       IWL_FW_CMD_VER_UNKNOWN);
2657	return (ver == IWL_FW_CMD_VER_UNKNOWN || ver < 3) ?
2658		IWL_SCAN_MAX_PROFILES : IWL_SCAN_MAX_PROFILES_V2;
2659}
2660
2661static inline
2662enum iwl_location_cipher iwl_mvm_cipher_to_location_cipher(u32 cipher)
2663{
2664	switch (cipher) {
2665	case WLAN_CIPHER_SUITE_CCMP:
2666		return IWL_LOCATION_CIPHER_CCMP_128;
2667	case WLAN_CIPHER_SUITE_GCMP:
2668		return IWL_LOCATION_CIPHER_GCMP_128;
2669	case WLAN_CIPHER_SUITE_GCMP_256:
2670		return IWL_LOCATION_CIPHER_GCMP_256;
2671	default:
2672		return IWL_LOCATION_CIPHER_INVALID;
2673	}
2674}
2675
2676struct iwl_mvm_csme_conn_info *iwl_mvm_get_csme_conn_info(struct iwl_mvm *mvm);
2677static inline int iwl_mvm_mei_get_ownership(struct iwl_mvm *mvm)
2678{
2679	if (mvm->mei_registered)
2680		return iwl_mei_get_ownership();
2681	return 0;
2682}
2683
2684static inline void iwl_mvm_mei_tx_copy_to_csme(struct iwl_mvm *mvm,
2685					       struct sk_buff *skb,
2686					       unsigned int ivlen)
2687{
2688	if (mvm->mei_registered)
2689		iwl_mei_tx_copy_to_csme(skb, ivlen);
2690}
2691
2692static inline void iwl_mvm_mei_host_disassociated(struct iwl_mvm *mvm)
2693{
2694	if (mvm->mei_registered)
2695		iwl_mei_host_disassociated();
2696}
2697
2698static inline void iwl_mvm_mei_device_state(struct iwl_mvm *mvm, bool up)
2699{
2700	if (mvm->mei_registered)
2701		iwl_mei_device_state(up);
2702}
2703
2704static inline void iwl_mvm_mei_set_sw_rfkill_state(struct iwl_mvm *mvm)
2705{
2706	bool sw_rfkill =
2707		mvm->hw_registered ? rfkill_soft_blocked(mvm->hw->wiphy->rfkill) : false;
2708
2709	if (mvm->mei_registered)
2710		iwl_mei_set_rfkill_state(iwl_mvm_is_radio_killed(mvm),
2711					 sw_rfkill);
2712}
2713
2714static inline bool iwl_mvm_has_p2p_over_aux(struct iwl_mvm *mvm)
2715{
2716	u32 cmd_id = WIDE_ID(MAC_CONF_GROUP, ROC_CMD);
2717
2718	return iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 0) >= 4;
2719}
2720
2721static inline bool iwl_mvm_mei_filter_scan(struct iwl_mvm *mvm,
2722					   struct sk_buff *skb)
2723{
2724	struct ieee80211_mgmt *mgmt = (void *)skb->data;
2725
2726	if (mvm->mei_scan_filter.is_mei_limited_scan &&
2727	    (ieee80211_is_probe_resp(mgmt->frame_control) ||
2728	     ieee80211_is_beacon(mgmt->frame_control))) {
2729		skb_queue_tail(&mvm->mei_scan_filter.scan_res, skb);
2730		schedule_work(&mvm->mei_scan_filter.scan_work);
2731		return true;
2732	}
2733
2734	return false;
2735}
2736
2737void iwl_mvm_send_roaming_forbidden_event(struct iwl_mvm *mvm,
2738					  struct ieee80211_vif *vif,
2739					  bool forbidden);
2740
2741/* Callbacks for ieee80211_ops */
2742void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
2743		    struct ieee80211_tx_control *control, struct sk_buff *skb);
2744void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw,
2745			       struct ieee80211_txq *txq);
2746
2747int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
2748			     struct ieee80211_vif *vif,
2749			     struct ieee80211_ampdu_params *params);
2750int iwl_mvm_op_get_antenna(struct ieee80211_hw *hw, int radio_idx, u32 *tx_ant,
2751			   u32 *rx_ant);
2752int iwl_mvm_op_set_antenna(struct ieee80211_hw *hw, int radio_idx, u32 tx_ant,
2753			   u32 rx_ant);
2754int iwl_mvm_mac_start(struct ieee80211_hw *hw);
2755void iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
2756				   enum ieee80211_reconfig_type reconfig_type);
2757void iwl_mvm_mac_stop(struct ieee80211_hw *hw, bool suspend);
2758static inline int iwl_mvm_mac_config(struct ieee80211_hw *hw, int radio_idx,
2759				     u32 changed)
2760{
2761	return 0;
2762}
2763
2764u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
2765			      struct netdev_hw_addr_list *mc_list);
2766
2767void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
2768			      unsigned int changed_flags,
2769			      unsigned int *total_flags, u64 multicast);
2770int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2771			struct ieee80211_scan_request *hw_req);
2772void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2773				struct ieee80211_vif *vif);
2774void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2775				struct ieee80211_vif *vif,
2776				struct ieee80211_sta *sta);
2777void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2778			    enum sta_notify_cmd cmd,
2779			    struct ieee80211_sta *sta);
2780void
2781iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2782				  struct ieee80211_sta *sta, u16 tids,
2783				  int num_frames,
2784				  enum ieee80211_frame_release_type reason,
2785				  bool more_data);
2786void
2787iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2788				    struct ieee80211_sta *sta, u16 tids,
2789				    int num_frames,
2790				    enum ieee80211_frame_release_type reason,
2791				    bool more_data);
2792int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, int radio_idx,
2793				  u32 value);
2794void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2795			   struct ieee80211_link_sta *link_sta, u32 changed);
2796void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2797				struct ieee80211_vif *vif,
2798				struct ieee80211_prep_tx_info *info);
2799void iwl_mvm_mac_mgd_complete_tx(struct ieee80211_hw *hw,
2800				 struct ieee80211_vif *vif,
2801				 struct ieee80211_prep_tx_info *info);
2802void iwl_mvm_mac_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2803		       u32 queues, bool drop);
2804void iwl_mvm_mac_flush_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2805			   struct ieee80211_sta *sta);
2806int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2807				 struct ieee80211_vif *vif,
2808				 struct cfg80211_sched_scan_request *req,
2809				 struct ieee80211_scan_ies *ies);
2810int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2811				struct ieee80211_vif *vif);
2812int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2813			struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2814			struct ieee80211_key_conf *key);
2815void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2816				 struct ieee80211_vif *vif,
2817				 struct ieee80211_key_conf *keyconf,
2818				 struct ieee80211_sta *sta,
2819				 u32 iv32, u16 *phase1key);
2820int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2821			struct ieee80211_chanctx_conf *ctx);
2822void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2823			    struct ieee80211_chanctx_conf *ctx);
2824void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
2825			    struct ieee80211_chanctx_conf *ctx, u32 changed);
2826int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw);
2827void iwl_mvm_channel_switch(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2828			    struct ieee80211_channel_switch *chsw);
2829int iwl_mvm_mac_pre_channel_switch(struct ieee80211_hw *hw,
2830				   struct ieee80211_vif *vif,
2831				   struct ieee80211_channel_switch *chsw);
2832
2833void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw,
2834				  struct ieee80211_vif *vif,
2835				  struct ieee80211_bss_conf *link_conf);
2836void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw,
2837				      struct ieee80211_vif *vif,
2838				      struct ieee80211_channel_switch *chsw);
2839void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
2840				struct ieee80211_vif *vif,
2841				const struct ieee80211_event *event);
2842void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw);
2843int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
2844			     struct ieee80211_vif *vif,
2845			     void *data, int len);
2846int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
2847			   struct survey_info *survey);
2848void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
2849				struct ieee80211_vif *vif,
2850				struct ieee80211_sta *sta,
2851				struct station_info *sinfo);
2852int
2853iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw,
2854				    struct ieee80211_vif *vif,
2855				    struct cfg80211_ftm_responder_stats *stats);
2856int iwl_mvm_start_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2857		       struct cfg80211_pmsr_request *request);
2858void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2859			struct cfg80211_pmsr_request *request);
2860
2861bool iwl_mvm_have_links_same_channel(struct iwl_mvm_vif *vif1,
2862				     struct iwl_mvm_vif *vif2);
2863bool iwl_mvm_vif_is_active(struct iwl_mvm_vif *mvmvif);
2864int iwl_mvm_set_tx_power(struct iwl_mvm *mvm,
2865			 struct ieee80211_bss_conf *bss_conf,
2866			 s16 tx_power);
2867int iwl_mvm_set_hw_timestamp(struct ieee80211_hw *hw,
2868			     struct ieee80211_vif *vif,
2869			     struct cfg80211_set_hw_timestamp *hwts);
2870int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2871bool iwl_mvm_enable_fils(struct iwl_mvm *mvm,
2872			 struct ieee80211_vif *vif,
2873			 struct ieee80211_chanctx_conf *ctx);
2874
2875struct cfg80211_chan_def *
2876iwl_mvm_chanctx_def(struct iwl_mvm *mvm, struct ieee80211_chanctx_conf *ctx);
2877
2878void iwl_mvm_roc_duration_and_delay(struct ieee80211_vif *vif,
2879				    u32 duration_ms,
2880				    u32 *duration_tu,
2881				    u32 *delay);
2882int iwl_mvm_roc_add_cmd(struct iwl_mvm *mvm,
2883			struct ieee80211_channel *channel,
2884			struct ieee80211_vif *vif,
2885			int duration, enum iwl_roc_activity activity);
2886
2887/* EMLSR */
2888bool iwl_mvm_vif_has_esr_cap(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2889void
2890iwl_mvm_send_ap_tx_power_constraint_cmd(struct iwl_mvm *mvm,
2891					struct ieee80211_vif *vif,
2892					struct ieee80211_bss_conf *bss_conf,
2893					bool is_ap);
2894
2895void iwl_mvm_smps_workaround(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2896			     bool update);
2897
2898/* rate_n_flags conversion */
2899u32 iwl_mvm_v3_rate_from_fw(__le32 rate, u8 rate_ver);
2900__le32 iwl_mvm_v3_rate_to_fw(u32 rate, u8 rate_ver);
2901
2902#endif /* __IWL_MVM_H__ */
~/ Read-only file preview.