#ifndef __iwl_mld_h__
#define __iwl_mld_h__
#include <linux/leds.h>
#include <net/mac80211.h>
#include "iwl-trans.h"
#include "iwl-op-mode.h"
#include "fw/runtime.h"
#include "fw/notif-wait.h"
#include "fw/api/commands.h"
#include "fw/api/scan.h"
#include "fw/api/mac-cfg.h"
#include "fw/api/mac.h"
#include "fw/api/phy-ctxt.h"
#include "fw/api/datapath.h"
#include "fw/api/rx.h"
#include "fw/api/rs.h"
#include "fw/api/context.h"
#include "fw/api/coex.h"
#include "fw/api/location.h"
#include "fw/dbg.h"
#include "notif.h"
#include "scan.h"
#include "rx.h"
#include "thermal.h"
#include "low_latency.h"
#include "constants.h"
#include "ptp.h"
#include "time_sync.h"
#include "ftm-initiator.h"
#include "nan.h"
#define IWL_MLD_MAX_ADDRESSES 5
struct iwl_mld {
struct_group(zeroed_on_hw_restart,
struct ieee80211_bss_conf __rcu *fw_id_to_bss_conf[IWL_FW_MAX_LINK_ID + 1];
struct ieee80211_vif __rcu *fw_id_to_vif[NUM_MAC_INDEX_DRIVER];
struct ieee80211_txq __rcu *fw_id_to_txq[IWL_MAX_TVQM_QUEUES];
u8 used_phy_ids: NUM_PHY_CTX;
u8 num_igtks;
struct {
bool on;
u32 ampdu_ref;
bool ampdu_toggle;
u8 p80;
struct {
struct iwl_rx_phy_air_sniffer_ntfy data;
u8 valid:1, used:1;
} phy;
#ifdef CONFIG_IWLWIFI_DEBUGFS
__le16 cur_aid;
u8 cur_bssid[ETH_ALEN];
bool ptp_time;
#endif
} monitor;
#ifdef CONFIG_PM_SLEEP
bool netdetect;
#endif
struct ieee80211_vif *p2p_device_vif;
bool bt_is_active;
struct ieee80211_vif *nan_device_vif;
);
struct ieee80211_link_sta __rcu *fw_id_to_link_sta[IWL_STATION_COUNT_MAX];
struct device *dev;
struct iwl_trans *trans;
const struct iwl_rf_cfg *cfg;
const struct iwl_fw *fw;
struct ieee80211_hw *hw;
struct wiphy *wiphy;
struct wiphy_iftype_ext_capab ext_capab[IWL_MLD_EXT_CAPA_NUM_IFTYPES];
u8 sta_ext_capab[IWL_MLD_STA_EXT_CAPA_SIZE];
struct iwl_nvm_data *nvm_data;
struct iwl_fw_runtime fwrt;
struct dentry *debugfs_dir;
struct iwl_notif_wait_data notif_wait;
struct list_head async_handlers_list;
spinlock_t async_handlers_lock;
struct wiphy_work async_handlers_wk;
struct wiphy_delayed_work ct_kill_exit_wk;
struct {
u32 running:1,
do_not_dump_once:1,
#ifdef CONFIG_PM_SLEEP
in_d3:1,
resuming:1,
#endif
in_hw_restart:1;
} fw_status;
struct {
u32 hw:1,
ct:1;
} radio_kill;
u32 power_budget_mw;
struct mac_address addresses[IWL_MLD_MAX_ADDRESSES];
struct iwl_mld_scan scan;
struct iwl_mld_survey *channel_survey;
#ifdef CONFIG_PM_SLEEP
struct wiphy_wowlan_support wowlan;
u32 debug_max_sleep;
#endif
#ifdef CONFIG_IWLWIFI_LEDS
struct led_classdev led;
#endif
enum iwl_mcc_source mcc_src;
bool bios_enable_puncturing;
struct iwl_mld_baid_data __rcu *fw_id_to_ba[IWL_MAX_BAID];
u8 num_rx_ba_sessions;
struct iwl_mld_rx_queues_sync rxq_sync;
struct list_head txqs_to_add;
struct wiphy_work add_txqs_wk;
spinlock_t add_txqs_lock;
u8 *error_recovery_buf;
struct iwl_mcast_filter_cmd *mcast_filter_cmd;
u8 mgmt_tx_ant;
u8 set_tx_ant;
u8 set_rx_ant;
bool fw_rates_ver_3;
struct iwl_mld_low_latency low_latency;
bool ibss_manager;
#ifdef CONFIG_THERMAL
struct thermal_zone_device *tzone;
struct iwl_mld_cooling_device cooling_dev;
#endif
struct ptp_data ptp_data;
struct iwl_mld_time_sync_data __rcu *time_sync;
struct ftm_initiator_data ftm_initiator;
};
#define CLEANUP_STRUCT(_ptr) \
memset((void *)&(_ptr)->zeroed_on_hw_restart, 0, \
sizeof((_ptr)->zeroed_on_hw_restart))
static inline void
iwl_cleanup_mld(struct iwl_mld *mld)
{
CLEANUP_STRUCT(mld);
CLEANUP_STRUCT(&mld->scan);
#ifdef CONFIG_PM_SLEEP
mld->fw_status.in_d3 = false;
#endif
iwl_mld_low_latency_restart_cleanup(mld);
}
enum iwl_power_scheme {
IWL_POWER_SCHEME_CAM = 1,
IWL_POWER_SCHEME_BPS,
};
struct iwl_mld_mod_params {
int power_scheme;
};
extern struct iwl_mld_mod_params iwlmld_mod_params;
#define IWL_OP_MODE_GET_MLD(_iwl_op_mode) \
((struct iwl_mld *)(_iwl_op_mode)->op_mode_specific)
#define IWL_MAC80211_GET_MLD(_hw) \
IWL_OP_MODE_GET_MLD((struct iwl_op_mode *)((_hw)->priv))
#ifdef CONFIG_IWLWIFI_DEBUGFS
void
iwl_mld_add_debugfs_files(struct iwl_mld *mld, struct dentry *debugfs_dir);
#else
static inline void
iwl_mld_add_debugfs_files(struct iwl_mld *mld, struct dentry *debugfs_dir)
{}
#endif
int iwl_mld_load_fw(struct iwl_mld *mld);
void iwl_mld_stop_fw(struct iwl_mld *mld);
int iwl_mld_start_fw(struct iwl_mld *mld);
void iwl_mld_send_recovery_cmd(struct iwl_mld *mld, u32 flags);
static inline void iwl_mld_set_ctkill(struct iwl_mld *mld, bool state)
{
mld->radio_kill.ct = state;
wiphy_rfkill_set_hw_state(mld->wiphy,
mld->radio_kill.hw || mld->radio_kill.ct);
}
static inline void iwl_mld_set_hwkill(struct iwl_mld *mld, bool state)
{
mld->radio_kill.hw = state;
wiphy_rfkill_set_hw_state(mld->wiphy,
mld->radio_kill.hw || mld->radio_kill.ct);
}
static inline u8 iwl_mld_get_valid_tx_ant(const struct iwl_mld *mld)
{
u8 tx_ant = mld->fw->valid_tx_ant;
if (mld->nvm_data && mld->nvm_data->valid_tx_ant)
tx_ant &= mld->nvm_data->valid_tx_ant;
if (mld->set_tx_ant)
tx_ant &= mld->set_tx_ant;
return tx_ant;
}
static inline u8 iwl_mld_get_valid_rx_ant(const struct iwl_mld *mld)
{
u8 rx_ant = mld->fw->valid_rx_ant;
if (mld->nvm_data && mld->nvm_data->valid_rx_ant)
rx_ant &= mld->nvm_data->valid_rx_ant;
if (mld->set_rx_ant)
rx_ant &= mld->set_rx_ant;
return rx_ant;
}
static inline u8 iwl_mld_nl80211_band_to_fw(enum nl80211_band band)
{
switch (band) {
case NL80211_BAND_2GHZ:
return PHY_BAND_24;
case NL80211_BAND_5GHZ:
return PHY_BAND_5;
case NL80211_BAND_6GHZ:
return PHY_BAND_6;
default:
WARN_ONCE(1, "Unsupported band (%u)\n", band);
return PHY_BAND_5;
}
}
static inline u8 iwl_mld_phy_band_to_nl80211(u8 phy_band)
{
switch (phy_band) {
case PHY_BAND_24:
return NL80211_BAND_2GHZ;
case PHY_BAND_5:
return NL80211_BAND_5GHZ;
case PHY_BAND_6:
return NL80211_BAND_6GHZ;
default:
WARN_ONCE(1, "Unsupported phy band (%u)\n", phy_band);
return NL80211_BAND_5GHZ;
}
}
static inline int
iwl_mld_legacy_hw_idx_to_mac80211_idx(u32 rate_n_flags,
enum nl80211_band band)
{
int format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK;
int rate = rate_n_flags & RATE_LEGACY_RATE_MSK;
bool is_lb = band == NL80211_BAND_2GHZ;
if (format == RATE_MCS_MOD_TYPE_LEGACY_OFDM)
return is_lb ? rate + IWL_FIRST_OFDM_RATE : rate;
return is_lb ? rate : -1;
}
extern const struct ieee80211_ops iwl_mld_hw_ops;
enum iwl_rx_handler_context {
RX_HANDLER_SYNC,
RX_HANDLER_ASYNC,
};
struct iwl_rx_handler {
union {
bool (*val_fn)(struct iwl_mld *mld, struct iwl_rx_packet *pkt);
const struct iwl_notif_struct_size *sizes;
};
void (*fn)(struct iwl_mld *mld, struct iwl_rx_packet *pkt);
u16 cmd_id;
u8 n_sizes;
u8 context;
enum iwl_mld_object_type obj_type;
bool (*cancel)(struct iwl_mld *mld, struct iwl_rx_packet *pkt,
u32 obj_id);
};
struct iwl_notif_struct_size {
u32 size:24, ver:8;
};
#if IS_ENABLED(CONFIG_IWLWIFI_KUNIT_TESTS)
extern const struct iwl_hcmd_arr iwl_mld_groups[];
extern const unsigned int global_iwl_mld_goups_size;
extern const struct iwl_rx_handler iwl_mld_rx_handlers[];
extern const unsigned int iwl_mld_rx_handlers_num;
bool
iwl_mld_is_dup(struct iwl_mld *mld, struct ieee80211_sta *sta,
struct ieee80211_hdr *hdr,
const struct iwl_rx_mpdu_desc *mpdu_desc,
struct ieee80211_rx_status *rx_status, int queue);
void iwl_construct_mld(struct iwl_mld *mld, struct iwl_trans *trans,
const struct iwl_rf_cfg *cfg, const struct iwl_fw *fw,
struct ieee80211_hw *hw, struct dentry *dbgfs_dir);
#endif
#define IWL_MLD_INVALID_FW_ID 0xff
#define IWL_MLD_ALLOC_FN(_type, _mac80211_type) \
static int \
iwl_mld_allocate_##_type##_fw_id(struct iwl_mld *mld, \
u8 *fw_id, \
struct ieee80211_##_mac80211_type *mac80211_ptr) \
{ \
u8 rand = IWL_MLD_DIS_RANDOM_FW_ID ? 0 : get_random_u8(); \
u8 arr_sz = ARRAY_SIZE(mld->fw_id_to_##_mac80211_type); \
if (__builtin_types_compatible_p(typeof(*mac80211_ptr), \
struct ieee80211_link_sta)) \
arr_sz = mld->fw->ucode_capa.num_stations; \
if (__builtin_types_compatible_p(typeof(*mac80211_ptr), \
struct ieee80211_bss_conf)) \
arr_sz = mld->fw->ucode_capa.num_links; \
for (int i = 0; i < arr_sz; i++) { \
u8 idx = (i + rand) % arr_sz; \
if (rcu_access_pointer(mld->fw_id_to_##_mac80211_type[idx])) \
continue; \
IWL_DEBUG_INFO(mld, "Allocated at index %d / %d\n", idx, arr_sz); \
*fw_id = idx; \
rcu_assign_pointer(mld->fw_id_to_##_mac80211_type[idx], mac80211_ptr); \
return 0; \
} \
return -ENOSPC; \
}
static inline struct ieee80211_bss_conf *
iwl_mld_fw_id_to_link_conf(struct iwl_mld *mld, u8 fw_link_id)
{
if (IWL_FW_CHECK(mld, fw_link_id >= mld->fw->ucode_capa.num_links,
"Invalid fw_link_id: %d\n", fw_link_id))
return NULL;
return wiphy_dereference(mld->wiphy,
mld->fw_id_to_bss_conf[fw_link_id]);
}
#define MSEC_TO_TU(_msec) ((_msec) * 1000 / 1024)
void iwl_mld_add_vif_debugfs(struct ieee80211_hw *hw,
struct ieee80211_vif *vif);
void iwl_mld_add_link_debugfs(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link_conf,
struct dentry *dir);
void iwl_mld_add_link_sta_debugfs(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
struct ieee80211_link_sta *link_sta,
struct dentry *dir);
static inline u8 iwl_mld_mac80211_ac_to_fw_tx_fifo(enum ieee80211_ac_numbers ac)
{
static const u8 mac80211_ac_to_fw_tx_fifo[] = {
IWL_BZ_EDCA_TX_FIFO_VO,
IWL_BZ_EDCA_TX_FIFO_VI,
IWL_BZ_EDCA_TX_FIFO_BE,
IWL_BZ_EDCA_TX_FIFO_BK,
IWL_BZ_TRIG_TX_FIFO_VO,
IWL_BZ_TRIG_TX_FIFO_VI,
IWL_BZ_TRIG_TX_FIFO_BE,
IWL_BZ_TRIG_TX_FIFO_BK,
};
return mac80211_ac_to_fw_tx_fifo[ac];
}
static inline u32
iwl_mld_get_lmac_id(struct iwl_mld *mld, enum nl80211_band band)
{
if (!fw_has_capa(&mld->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_CDB_SUPPORT) ||
band == NL80211_BAND_2GHZ)
return IWL_LMAC_24G_INDEX;
return IWL_LMAC_5G_INDEX;
}
static inline bool iwl_mld_error_before_recovery(struct iwl_mld *mld)
{
return mld->fw_status.in_hw_restart &&
!iwl_trans_fw_running(mld->trans);
}
int iwl_mld_tdls_sta_count(struct iwl_mld *mld);
#endif