#ifndef __iwl_mld_sta_h__
#define __iwl_mld_sta_h__
#include <net/mac80211.h>
#include "mld.h"
#include "tx.h"
struct iwl_mld_rxq_dup_data {
__le16 last_seq[IWL_MAX_TID_COUNT + 1];
u8 last_sub_frame_idx[IWL_MAX_TID_COUNT + 1];
} ____cacheline_aligned_in_smp;
struct iwl_mld_link_sta {
struct_group(zeroed_on_hw_restart,
u32 last_rate_n_flags;
bool in_fw;
s8 signal_avg;
);
struct rcu_head rcu_head;
u32 fw_id;
};
#define iwl_mld_link_sta_dereference_check(mld_sta, link_id) \
rcu_dereference_check((mld_sta)->link[link_id], \
lockdep_is_held(&mld_sta->mld->wiphy->mtx))
#define for_each_mld_link_sta(mld_sta, link_sta, link_id) \
for (link_id = 0; link_id < ARRAY_SIZE((mld_sta)->link); \
link_id++) \
if ((link_sta = \
iwl_mld_link_sta_dereference_check(mld_sta, link_id)))
#define IWL_NUM_DEFAULT_KEYS 4
struct iwl_mld_ptk_pn {
struct rcu_head rcu_head;
struct {
u8 pn[IWL_MAX_TID_COUNT][IEEE80211_CCMP_PN_LEN];
} ____cacheline_aligned_in_smp q[];
};
struct iwl_mld_per_link_mpdu_counter {
u32 tx;
u32 rx;
};
struct iwl_mld_per_q_mpdu_counter {
spinlock_t lock;
struct iwl_mld_per_link_mpdu_counter per_link[IWL_FW_MAX_LINK_ID + 1];
unsigned long window_start_time;
} ____cacheline_aligned_in_smp;
struct iwl_mld_sta {
struct_group(zeroed_on_hw_restart,
enum ieee80211_sta_state sta_state;
enum iwl_fw_sta_type sta_type;
);
struct iwl_mld *mld;
struct ieee80211_vif *vif;
struct iwl_mld_rxq_dup_data *dup_data;
u8 tid_to_baid[IWL_MAX_TID_COUNT];
u8 data_tx_ant;
struct iwl_mld_link_sta deflink;
struct iwl_mld_link_sta __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS];
struct iwl_mld_ptk_pn __rcu *ptk_pn[IWL_NUM_DEFAULT_KEYS];
struct iwl_mld_per_q_mpdu_counter *mpdu_counters;
};
static inline struct iwl_mld_sta *
iwl_mld_sta_from_mac80211(struct ieee80211_sta *sta)
{
return (void *)sta->drv_priv;
}
static inline void
iwl_mld_cleanup_sta(void *data, struct ieee80211_sta *sta)
{
struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta);
struct iwl_mld_link_sta *mld_link_sta;
u8 link_id;
for (int i = 0; i < ARRAY_SIZE(sta->txq); i++)
CLEANUP_STRUCT(iwl_mld_txq_from_mac80211(sta->txq[i]));
for_each_mld_link_sta(mld_sta, mld_link_sta, link_id) {
CLEANUP_STRUCT(mld_link_sta);
if (!ieee80211_vif_is_mld(mld_sta->vif)) {
WARN_ON(link_id);
continue;
}
if (mld_sta->vif->active_links & BIT(link_id))
continue;
WARN_ON(1);
RCU_INIT_POINTER(mld_sta->link[link_id], NULL);
RCU_INIT_POINTER(mld_sta->mld->fw_id_to_link_sta[mld_link_sta->fw_id],
NULL);
if (mld_link_sta != &mld_sta->deflink)
kfree_rcu(mld_link_sta, rcu_head);
}
CLEANUP_STRUCT(mld_sta);
}
static inline struct iwl_mld_link_sta *
iwl_mld_link_sta_from_mac80211(struct ieee80211_link_sta *link_sta)
{
struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(link_sta->sta);
return iwl_mld_link_sta_dereference_check(mld_sta, link_sta->link_id);
}
int iwl_mld_add_sta(struct iwl_mld *mld, struct ieee80211_sta *sta,
struct ieee80211_vif *vif, enum iwl_fw_sta_type type);
void iwl_mld_remove_sta(struct iwl_mld *mld, struct ieee80211_sta *sta);
int iwl_mld_fw_sta_id_from_link_sta(struct iwl_mld *mld,
struct ieee80211_link_sta *link_sta);
u32 iwl_mld_fw_sta_id_mask(struct iwl_mld *mld, struct ieee80211_sta *sta);
int iwl_mld_update_all_link_stations(struct iwl_mld *mld,
struct ieee80211_sta *sta);
void iwl_mld_flush_sta_txqs(struct iwl_mld *mld, struct ieee80211_sta *sta);
void iwl_mld_wait_sta_txqs_empty(struct iwl_mld *mld,
struct ieee80211_sta *sta);
void iwl_mld_count_mpdu_rx(struct ieee80211_link_sta *link_sta, int queue,
u32 count);
void iwl_mld_count_mpdu_tx(struct ieee80211_link_sta *link_sta, u32 count);
struct iwl_mld_int_sta {
u8 sta_id;
u32 queue_id;
enum iwl_fw_sta_type sta_type;
};
static inline void
iwl_mld_init_internal_sta(struct iwl_mld_int_sta *internal_sta)
{
internal_sta->sta_id = IWL_INVALID_STA;
internal_sta->queue_id = IWL_MLD_INVALID_QUEUE;
}
static inline void
iwl_mld_free_internal_sta(struct iwl_mld *mld,
struct iwl_mld_int_sta *internal_sta)
{
if (WARN_ON(internal_sta->sta_id == IWL_INVALID_STA))
return;
RCU_INIT_POINTER(mld->fw_id_to_link_sta[internal_sta->sta_id], NULL);
iwl_mld_init_internal_sta(internal_sta);
}
int iwl_mld_add_bcast_sta(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link);
int iwl_mld_add_mcast_sta(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link);
int iwl_mld_add_aux_sta(struct iwl_mld *mld,
struct iwl_mld_int_sta *internal_sta);
int iwl_mld_add_mon_sta(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link);
void iwl_mld_remove_bcast_sta(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link);
void iwl_mld_remove_mcast_sta(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link);
void iwl_mld_remove_aux_sta(struct iwl_mld *mld,
struct ieee80211_vif *vif);
void iwl_mld_remove_mon_sta(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_bss_conf *link);
int iwl_mld_update_link_stas(struct iwl_mld *mld,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
u16 old_links, u16 new_links);
#endif