wireless: cl8k driver for Celeno IEEE 802.11ax devices
RFC v2 87/96 cl8k: add utils.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/utils.h | 185 +++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/utils.h
drivers/net/wireless/celeno/cl8k/utils.h new file +185 -0
@@ -0,0 +1,185 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_UTILS_H +#define CL_UTILS_H + +#include "def.h" +#include "ieee80211_i.h" +#include "chip.h" + +/* +* GI_LTF field for common info +* 0 - 1x HE-LTF + 1.6 us GI +* 1 - 2x HE-LTF + 1.6 us GI +* 2 - 4x HE-LTF + 3.2 us GI +*/ +enum cl_he_ltf_gi { +HE_LTF_X1_GI_16 ,/* Not supported */ +HE_LTF_X2_GI_16 , +HE_LTF_X4_GI_32 , + +HE_LTF_MAX +}; + +#define CL_TF_GI_LTF_TO_GI (gi_ltf) \ + ((gi_ltf) == HE_LTF_X4_GI_32 ? WRS_GI_LONG : \ + ((gi_ltf) == HE_LTF_X2_GI_16 ? WRS_GI_SHORT : \ + ((gi_ltf) == HE_LTF_X1_GI_16 ? WRS_GI_SHORT : WRS_GI_LONG))) + +#define CL_TF_GI_TO_GI_LTF (gi) \ + ((gi) == WRS_GI_LONG ? HE_LTF_X4_GI_32 : \ + ((gi) == WRS_GI_SHORT ? HE_LTF_X2_GI_16 : \ + ((gi) == WRS_GI_VSHORT ? HE_LTF_X2_GI_16 : HE_LTF_X4_GI_32))) + +#define CL_TF_RU_ALLOC_MAX_TYPE_1 36 +#define CL_TF_RU_ALLOC_MAX_TYPE_2 52 +#define CL_TF_RU_ALLOC_MAX_TYPE_3 60 +#define CL_TF_RU_ALLOC_MAX_TYPE_4 64 +#define CL_TF_RU_ALLOC_MAX_TYPE_5 66 +#define CL_TF_RU_ALLOC_MAX_TYPE_6 67 +#define CL_TF_RU_ALLOC_MAX_TYPE_7 68 + +/* +*IEEE80211 G Rate provided by Hostapd in WLAN_EID_SUPP_RATES EID +*EID Rate = ieee802Rate/5 +*/ +#define CL_80211G_RATE_6MB 12 +#define CL_80211G_RATE_9MB 18 +#define CL_80211G_RATE_12MB 24 +#define CL_80211G_RATE_18MB 36 +#define CL_80211G_RATE_24MB 48 +#define CL_80211G_RATE_36MB 72 +#define CL_80211G_RATE_48MB 96 +#define CL_80211G_RATE_54MB 108 + +#define CL_SUPP_RATE_MASK 0x7F + +#define BAND_IS_5G_6G (cl_hw) \ + (cl_band_is_5g(cl_hw) || cl_band_is_6g(cl_hw)) + +static const u8 tid_to_ac[] = { +AC_BE ,AC_BK ,AC_BK ,AC_BE ,AC_VI ,AC_VI ,AC_VO ,AC_VO +}; + +static inline u16 cl_adc_to_mv (u16 adc) +{ +return (adc *1800 ) >>12 ; +} + +static inline struct ieee80211_vif *NETDEV_TO_VIF (struct net_device *dev) +{ +struct wireless_dev *wdev = dev->ieee80211_ptr; + +if (!wdev) +return NULL ; + +return wdev_to_ieee80211_vif (wdev); +} + +static inline struct cl_hw *NETDEV_TO_CL_HW (struct net_device *dev) +{ +struct ieee80211_hw *hw =wdev_priv (dev->ieee80211_ptr); + +return hw->priv; +} + +static inline struct cl_vif *NETDEV_TO_CL_VIF (struct net_device *dev) +{ +struct ieee80211_vif *vif =NETDEV_TO_VIF (dev); + +WARN_ON (!vif); + +if (unlikely (vif->type ==NL80211_IFTYPE_AP_VLAN )) { +struct cl_hw *cl_hw =NETDEV_TO_CL_HW (dev); + +return cl_vif_get_by_dev (cl_hw, dev); + } + +return (struct cl_vif *)vif->drv_priv; +} + +static inline struct cl_vif *TX_INFO_TO_CL_VIF (struct cl_hw *cl_hw, +struct ieee80211_tx_info *tx_info) +{ +struct ieee80211_vif *vif = tx_info->control.vif; + +WARN_ON (!vif); + +if (unlikely (vif->type ==NL80211_IFTYPE_AP_VLAN )) +return cl_vif_get_by_mac (cl_hw, vif->addr); + +return (struct cl_vif *)(vif->drv_priv); +} + +void cl_hex_dump (char *caption,u8 *buffer,u32 length,u32 offset,bool is_byte); +u8 cl_convert_gi_format_wrs_to_fw (u8 wrs_mode,u8 gi); +u8 cl_convert_gi_format_fw_to_wrs (u8 format_mode,u8 gi); +u8 cl_map_gi_to_ltf (u8 mode,u8 gi); +s8 cl_calc_noise_floor (struct cl_hw *cl_hw,const s8 *reg_noise_floor); +u8 cl_convert_signed_to_reg_value (s8 val); +u8 cl_width_to_bw (enum nl80211_chan_width width); +u8 cl_center_freq_offset (u8 bw); +u8 cl_max_bw_idx (u8 wrs_mode,bool is_24g); +bool cl_hw_mode_is_b_or_bg (struct cl_hw *cl_hw); +bool cl_is_eapol (struct sk_buff *skb); +u8 cl_ru_alloc_to_ru_type (u8 ru_alloc); +bool cl_is_valid_g_rates (const u8 *rate_ie); +enum cl_wireless_mode cl_recalc_wireless_mode (struct cl_hw *cl_hw, +bool ieee80211n, +bool ieee80211ac, +bool ieee80211ax); + +enum cl_mu_ofdma_ru_type { +CL_MU_OFDMA_RU_TYPE_NONE =0 , +CL_MU_OFDMA_RU_TYPE_26 ,/* 2.5MHz */ +CL_MU_OFDMA_RU_TYPE_52 ,/* 5MHz */ +CL_MU_OFDMA_RU_TYPE_106 ,/* 10MHz */ +CL_MU_OFDMA_RU_TYPE_242 ,/* 20MHz */ +CL_MU_OFDMA_RU_TYPE_484 ,/* 40MHz */ +CL_MU_OFDMA_RU_TYPE_996 ,/* 80MHz */ + CL_MU_OFDMA_RU_TYPE_2x996,/* 160MHz */ +CL_MU_OFDMA_RU_TYPE_MAX +}; + +enum nl80211_he_ru_alloc cl_ru_type_to_nl80211_he_ru_alloc (enum cl_mu_ofdma_ru_type ru_type); +u8 cl_mu_ofdma_grp_convert_ru_type_to_bw (struct cl_hw *cl_hw,u8 ru_type); +void cl_ieee802_11_parse_elems (const u8 *ies,size_t ies_len,struct ieee802_11_elems *elems); + +/* +* cl_file_open_and_read - Read the whole file into an allocated buffer. +* +* Allocates a buffer large enough to hold the contents of file at @filename and reads the +* contents of that file into that buffer. Upon success, the address of the allocated buffer +* is returned (which needs to be free later). Upon failure, returns NULL. +*/ +size_t cl_file_open_and_read (struct cl_chip *chip,const char *filename, +char **buf); + +/* Traffic analysis */ +/* Check if a packet has specific LLC fields e.g. DSAP, SSAP and Control */ +#define PKT_HAS_LLC_HDR (a) ((a[0] == 0xAA) && (a[1] == 0xAA) && (a[2] == 0x03)) + +/* Multiply by 4 because IHL is number of 32-bit words */ +#define IPV4_HDR_LEN (ihl) ((ihl) << 2) + +bool cl_set_network_header_if_proto (struct sk_buff *skb,u16 protocol); +bool cl_is_ipv4_packet (struct sk_buff *skb); +bool cl_is_ipv6_packet (struct sk_buff *skb); +bool cl_is_tcp_ack (struct sk_buff *skb,bool *syn_rst_push); + +/* Band helpers */ +bool cl_band_is_6g (struct cl_hw *cl_hw); +bool cl_band_is_5g (struct cl_hw *cl_hw); +bool cl_band_is_24g (struct cl_hw *cl_hw); +u8 cl_band_to_fw_idx (struct cl_hw *cl_hw); +u8 cl_band_from_fw_idx (u32 phy_band); + +static inline unsigned short cl_get_ether_type (int offset,unsigned char *src_buf) +{ +unsigned short type_len = *(unsigned short *)(src_buf + offset); + +return (unsigned short )be16_to_cpu (htons (type_len)); +} + +#endif /* CL_UTILS_H */
Signature · 1 line
2.36.1
RFC v2 88/96 cl8k: add version.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/version.c | 147 +++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/version.c
drivers/net/wireless/celeno/cl8k/version.c new file +147 -0
@@ -0,0 +1,147 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include "debug.h" +#include "chip.h" +#include "rfic.h" +#include "debug.h" +#include "version.h" + +static int cl_version_request (struct cl_hw *cl_hw) +{ +struct mm_version_cfm *cfm =NULL ; +struct cl_version_db *vd = &cl_hw->version_db; +int ret =0 ; + + ret =cl_msg_tx_version (cl_hw); +if (ret) +return ret; + + cfm = (struct mm_version_cfm *)cl_hw->msg_cfm_params[MM_VERSION_CFM ]; +if (!cfm) +return -ENOMSG ; + + vd->last_update = jiffies; + vd->dsp =le32_to_cpu (cfm->versions.dsp); + vd->rfic_sw =le32_to_cpu (cfm->versions.rfic_sw); + vd->rfic_hw =le32_to_cpu (cfm->versions.rfic_hw); + vd->agcram =le32_to_cpu (cfm->versions.agcram); + + cl_hw->rf_crystal_mhz = cfm->rf_crystal_mhz; + +strncpy (vd->fw, cfm->versions.fw,sizeof (vd->fw)); + vd->fw[sizeof (vd->fw) -1 ] ='\0' ; + +strncpy (vd->drv,CONFIG_CL8K_VERSION ,sizeof (vd->drv)); + vd->drv[sizeof (vd->drv) -1 ] ='\0' ; + +cl_msg_tx_free_cfm_params (cl_hw,MM_VERSION_CFM ); + +return ret; +} + +int cl_version_read (struct cl_hw *cl_hw,char *buf,ssize_t buf_size,ssize_t *total_len) +{ +struct cl_chip *chip = cl_hw->chip; +struct cl_version_db *vd = &cl_hw->version_db; +struct cl_agc_profile *agc_profile1 = &cl_hw->phy_data_info.data->agc_params.profile1; +struct cl_agc_profile *agc_profile2 = &cl_hw->phy_data_info.data->agc_params.profile2; +ssize_t len =0 ; +int ret =0 ; +u32 version_agcram =0 ; +u32 major =0 ; +u32 minor =0 ; +u32 internal =0 ; + +/* Request data if existing is not actual */ +if (!vd->last_update) { + ret =cl_version_request (cl_hw); +if (ret) +return ret; + } + +/* PHY components specifics */ + len +=scnprintf (buf + len, buf_size - len,"DRV VERSION: %s\n" , vd->drv); + len +=scnprintf (buf + len, buf_size - len,"FW VERSION: %s\n" , vd->fw); + len +=scnprintf (buf + len, buf_size - len,"DSP VERSION: 0x%-.8X\n" , vd->dsp); + len +=scnprintf (buf + len, buf_size - len,"RFIC SW VERSION: %u\n" , vd->rfic_sw); + len +=scnprintf (buf + len, buf_size - len,"RFIC HW VERSION: 0x%X\n" , vd->rfic_hw); + + version_agcram = vd->agcram; + major = (version_agcram >>16 ) &0xffff ; + minor = (version_agcram >>8 ) &0xff ; + internal = version_agcram &0xff ; + + len +=scnprintf (buf + len, buf_size - len, +"AGC RAM VERSION: B.%x.%x.%x\n" , major, minor, internal); + +if (agc_profile1) +cl_agc_params_dump_profile_id (buf, buf_size, &len, agc_profile1->id, +"AGC PARAMS PROFILE:" ); +if (agc_profile2) +cl_agc_params_dump_profile_id (buf, buf_size, &len, agc_profile2->id, +"AGC PARAMS PROFILE (Elastic):" ); + + len +=scnprintf (buf + len, buf_size - len, +"TX POWER VERSION: %u\n" , cl_hw->tx_power_version); + +switch (chip->conf->ci_phy_dev) { +case PHY_DEV_OLYMPUS : + len +=scnprintf (buf + len, buf_size - len,"RFIC TYPE: OLYMPUS\n" ); +break ; +case PHY_DEV_ATHOS : + len +=scnprintf (buf + len, buf_size - len,"RFIC TYPE: %s\n" , + (cl_hw->chip->rfic_version ==ATHOS_A_VER ) ?"ATHOS" :"ATHOS B" ); +break ; +case PHY_DEV_DUMMY : + len +=scnprintf (buf + len, buf_size - len,"RFIC TYPE: DUMMY\n" ); +break ; +case PHY_DEV_FRU : + len +=scnprintf (buf + len, buf_size - len,"RFIC TYPE: FRU\n" ); +break ; +case PHY_DEV_LOOPBACK : + len +=scnprintf (buf + len, buf_size - len,"RFIC TYPE: LOOPBACK\n" ); +break ; + } + + len +=scnprintf (buf + len, buf_size - len, +"RF CRYSTAL: %uMHz\n" , cl_hw->rf_crystal_mhz); + len +=scnprintf (buf + len, buf_size - len, +"CHIP ID: 0X%x\n" ,cl_chip_get_device_id (cl_hw->chip)); + *total_len = len; + +return 0 ; +} + +int cl_version_update (struct cl_hw *cl_hw) +{ +char *buf =NULL ; +ssize_t buf_size =PAGE_SIZE ; +ssize_t len =0 ; +int ret =0 ; + + buf =kzalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +/* Force logic to update versions */ + cl_hw->version_db.last_update =0 ; + + ret =cl_version_read (cl_hw, buf, buf_size, &len); + +if (ret ==0 ) { +pr_debug ("%s\n" , buf); +/* Share version info */ +cl_version_sync_wiphy (cl_hw, cl_hw->hw->wiphy); + } + +kfree (buf); + +return ret; +} + +void cl_version_sync_wiphy (struct cl_hw *cl_hw,struct wiphy *wiphy) +{ +strncpy (wiphy->fw_version, cl_hw->version_db.fw,sizeof (wiphy->fw_version)); +} +
Signature · 1 line
2.36.1
RFC v2 89/96 cl8k: add version.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/version.h | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/version.h
drivers/net/wireless/celeno/cl8k/version.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_VERSION_H +#define CL_VERSION_H + +#include "ipc_shared.h" + +struct cl_version_db { +u32 dsp; +u32 rfic_sw; +u32 rfic_hw; +u32 agcram; +char fw[CL_VERSION_STR_SIZE ]; +char drv[CL_VERSION_STR_SIZE ]; +unsigned long last_update; +}; + +int cl_version_read (struct cl_hw *cl_hw,char *buf,ssize_t buf_size,ssize_t *total_len); +int cl_version_update (struct cl_hw *cl_hw); +void cl_version_sync_wiphy (struct cl_hw *cl_hw,struct wiphy *wiphy); + +#endif /* CL_VERSION_H */
Signature · 1 line
2.36.1
RFC v2 90/96 cl8k: add vif.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/vif.c | 162 +++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/vif.c
drivers/net/wireless/celeno/cl8k/vif.c new file +162 -0
@@ -0,0 +1,162 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include <linux/list.h> + +#include "hw.h" +#include "mac_addr.h" +#include "vif.h" + +void cl_vif_init (struct cl_hw *cl_hw) +{ +rwlock_init (&cl_hw->vif_db.lock); +INIT_LIST_HEAD (&cl_hw->vif_db.head); +} + +void cl_vif_add (struct cl_hw *cl_hw,struct cl_vif *cl_vif) +{ +struct cl_vif_db *vif_db = &cl_hw->vif_db; + +write_lock_bh (&vif_db->lock); +list_add_tail (&cl_vif->list, &vif_db->head); + +if (cl_vif->vif->type !=NL80211_IFTYPE_STATION ) + vif_db->num_iface_bcn++; + +/* Multicast vif set */ + cl_hw->mc_vif = cl_vif; + +write_unlock_bh (&vif_db->lock); +} + +void cl_vif_remove (struct cl_hw *cl_hw,struct cl_vif *cl_vif) +{ +struct cl_vif_db *vif_db = &cl_hw->vif_db; + +write_lock_bh (&vif_db->lock); +/* Multicast vif unset */ +if (cl_hw->mc_vif == cl_vif) + cl_hw->mc_vif =cl_vif_get_next (cl_hw, cl_hw->mc_vif); + +list_del (&cl_vif->list); + +if (cl_vif->vif->type !=NL80211_IFTYPE_STATION ) + vif_db->num_iface_bcn--; +write_unlock_bh (&vif_db->lock); + +cl_bcmc_cfm_poll_empty_per_vif (cl_hw, cl_vif); +} + +struct cl_vif *cl_vif_get_next (struct cl_hw *cl_hw,struct cl_vif *cl_vif) +{ +if (list_is_last (&cl_vif->list, &cl_hw->vif_db.head)) +return list_first_entry_or_null (&cl_hw->vif_db.head, + struct cl_vif, list); +else +return list_next_entry (cl_vif, list); +} + +struct cl_vif *cl_vif_get_by_dev (struct cl_hw *cl_hw,struct net_device *dev) +{ +struct cl_vif *cl_vif =NULL , *cl_vif_ret =NULL ; + +read_lock_bh (&cl_hw->vif_db.lock); +list_for_each_entry (cl_vif, &cl_hw->vif_db.head, list) +if (cl_vif->dev == dev) { + cl_vif_ret = cl_vif; + goto unlock; + } + +unlock: +read_unlock_bh (&cl_hw->vif_db.lock); +return cl_vif_ret; +} + +struct cl_vif *cl_vif_get_by_mac (struct cl_hw *cl_hw,u8 *mac_addr) +{ +struct cl_vif *cl_vif, *cl_vif_ret =NULL ; + +read_lock (&cl_hw->vif_db.lock); +list_for_each_entry (cl_vif, &cl_hw->vif_db.head, list) +if (cl_mac_addr_compare (cl_vif->vif->addr, mac_addr)) { + cl_vif_ret = cl_vif; + goto unlock; + } + +unlock: +read_unlock (&cl_hw->vif_db.lock); +return cl_vif_ret; +} + +struct cl_vif *cl_vif_get_first (struct cl_hw *cl_hw) +{ + return list_first_entry_or_null(&cl_hw->vif_db.head, struct cl_vif, list); +} + +struct cl_vif *cl_vif_get_first_ap (struct cl_hw *cl_hw) +{ +struct cl_vif *cl_vif, *cl_vif_ret =NULL ; + +read_lock_bh (&cl_hw->vif_db.lock); +list_for_each_entry (cl_vif, &cl_hw->vif_db.head, list) +if (cl_vif->vif->type ==NL80211_IFTYPE_AP || + cl_vif->vif->type ==NL80211_IFTYPE_MESH_POINT || + cl_hw->conf->ce_listener_en) { + cl_vif_ret = cl_vif; + goto unlock; + } + +unlock: +read_unlock_bh (&cl_hw->vif_db.lock); +return cl_vif_ret; +} + +struct net_device *cl_vif_get_first_net_device (struct cl_hw *cl_hw) +{ +struct cl_vif *cl_vif =NULL ; +struct net_device *dev =NULL ; + +read_lock_bh (&cl_hw->vif_db.lock); + cl_vif = list_first_entry_or_null(&cl_hw->vif_db.head, struct cl_vif, list); +if (cl_vif) + dev = cl_vif->dev; +read_unlock_bh (&cl_hw->vif_db.lock); + +return dev; +} + +struct net_device *cl_vif_get_dev_by_index (struct cl_hw *cl_hw,u8 index) +{ +struct cl_vif *cl_vif =NULL ; +struct net_device *dev =NULL ; + +read_lock_bh (&cl_hw->vif_db.lock); +list_for_each_entry (cl_vif, &cl_hw->vif_db.head, list) +if (cl_vif->vif_index == index) { + dev = cl_vif->dev; + goto unlock; + } + +unlock: +read_unlock_bh (&cl_hw->vif_db.lock); +return dev; +} + +void cl_vif_ap_tx_enable (struct cl_hw *cl_hw,bool enable) +{ +struct cl_vif *cl_vif; +struct ieee80211_vif *vif; + +read_lock_bh (&cl_hw->vif_db.lock); +list_for_each_entry (cl_vif, &cl_hw->vif_db.head, list) { + vif = cl_vif->vif; + +if (vif->type !=NL80211_IFTYPE_AP ) +continue ; + + cl_vif->tx_en = enable; +cl_dbg_verbose (cl_hw,"Set tx_en=%u for vif_index=%u\n" , + enable, cl_vif->vif_index); + } +read_unlock_bh (&cl_hw->vif_db.lock); +}
Signature · 1 line
2.36.1
RFC v2 91/96 cl8k: add vif.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/vif.h | 81 ++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/vif.h
drivers/net/wireless/celeno/cl8k/vif.h new file +81 -0
@@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_VIF_H +#define CL_VIF_H + +#include <linux/netdevice.h> + +#include "wrs.h" + +struct cl_connection_data { +u32 max_client;/* MAX Clients of the SSID */ +u32 max_client_timestamp;/* MAX Clients Timestamp of the SSID */ +u32 watermark_threshold;/* Number of clients threshold for watermark */ +u32 watermark_reached_cnt;/* Number of times the watermark threshold was reached */ +}; + +struct cl_traffic_counters { +u64 tx_packets; +u64 tx_bytes; +u64 rx_packets; +u64 rx_bytes; +u32 tx_errors; +u32 rx_errors; +u32 tx_dropped; +u32 rx_dropped; +}; + +/* +* Structure used to save information relative to the managed interfaces. +* Will be used as the 'drv_priv' field of the "struct ieee80211_vif" structure. +* This is also linked within the cl_hw vifs list. +*/ +struct cl_vif { +struct list_head list; +struct cl_hw *cl_hw; +struct ieee80211_vif *vif; +struct net_device *dev; +struct list_head key_list_head; +struct cl_key_conf *key; +int key_idx_default; +u32 unicast_tx; +u32 unicast_rx; +u32 multicast_tx; +u32 multicast_rx; +u32 broadcast_tx; +u32 broadcast_rx; +u16 sequence_number; +u8 num_sta;/* Number of station connected per SSID */ +struct cl_connection_data *conn_data; +u8 vif_index; +bool tx_en; +/* Holds info for channel utilization stats */ +u32 chan_util_last_tx_bytes; +u32 chan_util; +struct mcast_table *mcast_table; +struct cl_wrs_rate_params fixed_params; +struct cl_traffic_counters trfc_cntrs[AC_MAX ]; +bool wmm_enabled; +u16 mesh_basic_rates; +}; + +struct cl_vif_db { +struct list_head head; +rwlock_t lock; +u8 num_iface_bcn; +}; + +void cl_vif_init (struct cl_hw *cl_hw); +void cl_vif_add (struct cl_hw *cl_hw,struct cl_vif *cl_vif); +void cl_vif_remove (struct cl_hw *cl_hw,struct cl_vif *cl_vif); +struct cl_vif *cl_vif_get_next (struct cl_hw *cl_hw,struct cl_vif *cl_vif); +struct cl_vif *cl_vif_get_by_dev (struct cl_hw *cl_hw,struct net_device *dev); +struct cl_vif *cl_vif_get_by_mac (struct cl_hw *cl_hw,u8 *mac_addr); +struct cl_vif *cl_vif_get_first (struct cl_hw *cl_hw); +struct cl_vif *cl_vif_get_first_ap (struct cl_hw *cl_hw); +struct net_device *cl_vif_get_first_net_device (struct cl_hw *cl_hw); +struct net_device *cl_vif_get_dev_by_index (struct cl_hw *cl_hw,u8 index); +void cl_vif_ap_tx_enable (struct cl_hw *cl_hw,bool enable); + +#endif /* CL_VIF_H */
Signature · 1 line
2.36.1
RFC v2 92/96 cl8k: add vns.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/vns.c | 354 +++++++++++++++++++++++++ 1 file changed, 354 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/vns.c
drivers/net/wireless/celeno/cl8k/vns.c new file +354 -0
@@ -0,0 +1,354 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include "maintenance.h" +#include "mac_addr.h" +#include "debug.h" +#include "vns.h" + +#define CL_VNS_HASH_IDX (ETH_ALEN - 2) +#define CL_VNS_MGMT_AGEOUT 200 + +#define vns_pr (...) \ + do { \ + if (unlikely(cl_hw->vns_db->dbg)) \ + pr_debug("[VNS]" __VA_ARGS__); \ + } while (0) + +#define vns_pr_pkt (...) \ + do { \ + if (unlikely(cl_hw->vns_db->dbg_per_packet)) \ + pr_debug("[VNS-pkt]" __VA_ARGS__); \ + } while (0) + +static void cl_vns_mgmt_list_add (struct cl_hw *cl_hw,u8 *addr,s8 strongset_rssi) +{ +/* Add entry to mgmt list */ +struct cl_vns_rssi_entry *entry =kzalloc (sizeof (*entry),GFP_ATOMIC ); + +if (!entry) +return ; + +/* Fill entry parameters */ +INIT_LIST_HEAD (&entry->list_all); +INIT_LIST_HEAD (&entry->list_addr); +cl_mac_addr_copy (entry->addr, addr); + entry->strongset_rssi = strongset_rssi; + entry->timestamp = jiffies; + +/* Add to list */ + cl_hw->vns_db->mgmt_db.num_entries++; +list_add (&entry->list_all, &cl_hw->vns_db->mgmt_db.list_all); +list_add (&entry->list_addr, &cl_hw->vns_db->mgmt_db.list_addr[addr[CL_VNS_HASH_IDX ]]); +} + +static void cl_vns_mgmt_list_remove (struct cl_hw *cl_hw,struct cl_vns_rssi_entry *entry) +{ +/* Remove entry from mgmt list */ + cl_hw->vns_db->mgmt_db.num_entries--; +list_del (&entry->list_all); +list_del (&entry->list_addr); +kfree (entry); +} + +static void cl_vns_mgmt_list_flush (struct cl_hw *cl_hw) +{ +/* Flush all mgmt list */ +if (cl_hw->vns_db->mgmt_db.num_entries >0 ) { +struct cl_vns_rssi_entry *entry =NULL , *tmp =NULL ; + +list_for_each_entry_safe (entry, tmp, &cl_hw->vns_db->mgmt_db.list_all, list_all) +cl_vns_mgmt_list_remove (cl_hw, entry); + } +} + +static struct cl_vns_rssi_entry *cl_vns_mgmt_list_find (struct cl_hw *cl_hw,u8 *addr) +{ +/* Search for entry in mgmt list */ +struct cl_vns_mgmt_db *mgmt_db = &cl_hw->vns_db->mgmt_db; + +if (mgmt_db->num_entries >0 ) { +struct cl_vns_rssi_entry *entry =NULL ; + +list_for_each_entry (entry, &mgmt_db->list_addr[addr[CL_VNS_HASH_IDX ]], list_addr) +if (ether_addr_equal (entry->addr, addr)) +return entry; + } + +return NULL ; +} + +static bool cl_vns_mgmt_list_find_and_remove (struct cl_hw *cl_hw,u8 *addr) +{ +/* +* Search for entry in mgmt list +* If entry found remove it and return true +*/ +struct cl_vns_rssi_entry *entry =cl_vns_mgmt_list_find (cl_hw, addr); + +if (entry) { +cl_vns_mgmt_list_remove (cl_hw, entry); +return true; + } + +return false; +} + +static void cl_vns_mgmt_list_ageout (struct cl_hw *cl_hw) +{ +/* Remove old entries from mgmt list */ +struct cl_vns_mgmt_db *mgmt_db = &cl_hw->vns_db->mgmt_db; + +if (mgmt_db->num_entries >0 ) { +struct cl_vns_rssi_entry *entry =NULL , *tmp =NULL ; +unsigned long delta_time; + +list_for_each_entry_safe (entry, tmp, &mgmt_db->list_all, list_all) { + delta_time =jiffies_to_msecs (jiffies - entry->timestamp); + +if (delta_time >CL_VNS_MGMT_AGEOUT ) { +vns_pr ("sta %pM removed from list because of ageout\n" , + entry->addr); +cl_vns_mgmt_list_remove (cl_hw, entry); + } + } + } +} + +static s8 cl_vns_get_strongest_rssi (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +struct cl_vns_sta_db *vns_db = &cl_sta->vns_db; +s32 rssi_samples = vns_db->rssi_samples; + +if (rssi_samples >0 ) { +u8 i; +s32 strongest_rssi =S32_MIN ; + +for (i =0 ; i < cl_hw->num_antennas; i++) +if (vns_db->rssi_sum[i] > strongest_rssi) + strongest_rssi = vns_db->rssi_sum[i]; + +/* Reset rssi for next time that cl_vns_get_strongest_rssi() will be called */ +memset (vns_db->rssi_sum,0 ,sizeof (vns_db->rssi_sum)); + vns_db->rssi_samples =0 ; + +return (s8)(strongest_rssi / rssi_samples); + } + +return 0 ; +} + +static void cl_vns_monitor_rssi (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +/* Monitor RSSI of associated stations and update state if necessary */ +struct cl_vns_sta_db *vns_db = &cl_sta->vns_db; +s8 strongset_rssi =cl_vns_get_strongest_rssi (cl_hw, cl_sta); +s8 rssi_thr =0 ; +bool is_vns = false; + +if (strongset_rssi ==0 ) +return ; + +/* +* Calculate RSSI threshold (take hystersis into +* consideration according to current state) +*/ +if (vns_db->is_very_near) + rssi_thr = cl_hw->conf->ci_vns_rssi_thr - cl_hw->conf->ci_vns_rssi_hys; +else + rssi_thr = cl_hw->conf->ci_vns_rssi_thr + cl_hw->conf->ci_vns_rssi_hys; + + is_vns = strongset_rssi > rssi_thr; +/* Avoid toggling of VNS state - require two consecutive same decisions */ +if (is_vns != vns_db->prev_decision) { + vns_db->prev_decision = is_vns; +return ; + } + +if (is_vns != vns_db->is_very_near) { +vns_pr ("sta %pM changed state, strongset_rssi = %d, is_vns = %s\n" , + cl_sta->addr, strongset_rssi, is_vns ?"TRUE" :"FALSE" ); + vns_db->is_very_near = is_vns; +cl_msg_tx_set_vns (cl_hw, cl_sta->sta_idx, is_vns); + } +} + +static void cl_vns_recovery_sta (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +if (cl_sta->vns_db.is_very_near) +cl_msg_tx_set_vns (cl_hw, cl_sta->sta_idx, true); +} + +int cl_vns_init (struct cl_hw *cl_hw) +{ +int i =0 ; +u8 vns_pwr_mode = cl_hw->conf->ci_vns_pwr_mode; + + cl_hw->vns_db =vzalloc (sizeof (*cl_hw->vns_db)); +if (!cl_hw->vns_db) +return -ENOMEM ; + +if (vns_pwr_mode ==VNS_MODE_DATA || vns_pwr_mode ==VNS_MODE_ALL ) + cl_hw->vns_db->enable = true; + +spin_lock_init (&cl_hw->vns_db->lock); + +INIT_LIST_HEAD (&cl_hw->vns_db->mgmt_db.list_all); + +for (i =0 ; i <STA_HASH_SIZE ; i++) +INIT_LIST_HEAD (&cl_hw->vns_db->mgmt_db.list_addr[i]); + +return 0 ; +} + +void cl_vns_close (struct cl_hw *cl_hw) +{ +if (cl_hw->vns_db->enable) { +spin_lock_bh (&cl_hw->vns_db->lock); +cl_vns_mgmt_list_flush (cl_hw); +spin_unlock_bh (&cl_hw->vns_db->lock); + + cl_hw->vns_db->enable = false; + } + +vfree (cl_hw->vns_db); + cl_hw->vns_db =NULL ; +} + +void cl_vns_maintenance (struct cl_hw *cl_hw) +{ +/* +* Maintenance: +* 1) Remove old entries from mgmt list +* 2) Update state for associated clients +*/ +if (!cl_hw->vns_db || !cl_hw->vns_db->enable) +return ; + + cl_hw->vns_db->interval_period +=CL_MAINTENANCE_PERIOD_SLOW_MS ; + +if (cl_hw->vns_db->interval_period < cl_hw->conf->ci_vns_maintenance_time) +return ; + + cl_hw->vns_db->interval_period =0 ; + +spin_lock_bh (&cl_hw->vns_db->lock); +cl_vns_mgmt_list_ageout (cl_hw); +spin_unlock_bh (&cl_hw->vns_db->lock); + +/* Check RSSI of associated stations */ +cl_sta_loop (cl_hw, cl_vns_monitor_rssi); +} + +void cl_vns_mgmt_handler (struct cl_hw *cl_hw,u8 *addr,s8 rssi[MAX_ANTENNAS ]) +{ +/* +* Handle management frames of non-associated stations, +* and save the very-near ones in the mgmt list +*/ +s8 strongset_rssi =0 ; +struct cl_vns_rssi_entry *entry =NULL ; + +if (!cl_hw->vns_db->enable) +return ; + + strongset_rssi =cl_rssi_get_strongest (cl_hw, rssi); + +spin_lock_bh (&cl_hw->vns_db->lock); + + entry =cl_vns_mgmt_list_find (cl_hw, addr); + +if (entry) { +if (strongset_rssi > cl_hw->conf->ci_vns_rssi_thr) { +/* Update exisiting entry */ + entry->strongset_rssi = strongset_rssi; + entry->timestamp = jiffies; +vns_pr ("sta %pM updated in list (rssi=%d)\n" , + addr, strongset_rssi); + }else { +/* Remove exisiting entry */ +cl_vns_mgmt_list_remove (cl_hw, entry); +vns_pr ("sta %pM removed from list (rssi=%d)\n" , + addr, strongset_rssi); + } + }else { +if (strongset_rssi > cl_hw->conf->ci_vns_rssi_thr) { +/* Add new entry */ +cl_vns_mgmt_list_add (cl_hw, addr, strongset_rssi); +vns_pr ("sta %pM added to list (rssi=%d)\n" , + addr, strongset_rssi); + } + } + +spin_unlock_bh (&cl_hw->vns_db->lock); +} + +bool cl_vns_is_very_near (struct cl_hw *cl_hw,struct cl_sta *cl_sta,struct sk_buff *skb) +{ +bool is_vns = false; +/* This function checks for every TX packet whether it's VNS or not */ +if (!cl_hw->vns_db->enable) +return false; + +if (unlikely (!cl_sta)) { +struct ieee80211_hdr *mac_hdr = (struct ieee80211_hdr *)skb->data; + +spin_lock_bh (&cl_hw->vns_db->lock); + is_vns =cl_vns_mgmt_list_find (cl_hw, mac_hdr->addr1); +spin_unlock_bh (&cl_hw->vns_db->lock); + +vns_pr_pkt ("mgmt-sta %pM, is_vns = %s\n" , + mac_hdr->addr1, is_vns ?"TRUE" :"FALSE" ); + +return is_vns; + } + is_vns = cl_sta->vns_db.is_very_near; + +vns_pr_pkt ("assoc-sta %pM, is_vns = %s\n" , + cl_sta->addr, is_vns ?"TRUE" :"FALSE" ); + +return is_vns; +} + +void cl_vns_sta_add (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +/* Update is_very_near according to mgmt list */ +bool is_vns = false; + +if (!cl_hw->vns_db->enable) +return ; + +spin_lock_bh (&cl_hw->vns_db->lock); + is_vns =cl_vns_mgmt_list_find_and_remove (cl_hw, cl_sta->addr); +spin_unlock_bh (&cl_hw->vns_db->lock); + +if (is_vns) { +vns_pr ("sta %pM connected - is_vns = TRUE\n" , cl_sta->addr); + cl_sta->vns_db.is_very_near = true; + cl_sta->vns_db.prev_decision = true; +cl_msg_tx_set_vns (cl_hw, cl_sta->sta_idx, true); + }else { +vns_pr ("sta %pM connected - is_vns = FALSE\n" , cl_sta->addr); + } +} + +void cl_vns_handle_rssi (struct cl_hw *cl_hw,struct cl_sta *cl_sta,s8 rssi[MAX_ANTENNAS ]) +{ +/* Collect rssi samples */ +int i; + +if (!cl_hw->vns_db->enable) +return ; + +for (i =0 ; i < cl_hw->num_antennas; i++) + cl_sta->vns_db.rssi_sum[i] += rssi[i]; + + cl_sta->vns_db.rssi_samples++; +} + +void cl_vns_recovery (struct cl_hw *cl_hw) +{ +vns_pr ("Recovery\n" ); +cl_sta_loop_bh (cl_hw, cl_vns_recovery_sta); +} +
Signature · 1 line
2.36.1
RFC v2 93/96 cl8k: add vns.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/vns.h | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/vns.h
drivers/net/wireless/celeno/cl8k/vns.h new file +65 -0
@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_VNS_H +#define CL_VNS_H + +#include "def.h" + +/** +* DOC: VNS (=Very Near STA) +* +* Feature is responsible for TX power adjustment regarding to the STA +* location. Near stations should get signal with lower power to avoid +* saturation. Power is contolled for both transmitted data (%VNS_MODE_DATA) +* and autoresponse frames (%VNS_AUTO_REPLY), including both cases for +* connected and not connected stations. +* +* In order to determine, whether a station is in VNS range, we rely on the +* RSSI values, received from the firmware for every RX frame. +*/ + +#define VNS_MODE_DATA 0x1 +#define VNS_MODE_AUTO_REPLY 0x2 +#define VNS_MODE_ALL (VNS_MODE_DATA | VNS_MODE_AUTO_REPLY) + +struct cl_vns_rssi_entry { +struct list_head list_all; +struct list_head list_addr; +unsigned long timestamp; +s8 strongset_rssi; +u8 addr[ETH_ALEN ]; +}; + +struct cl_vns_mgmt_db { +u32 num_entries; +struct list_head list_all; +struct list_head list_addr[STA_HASH_SIZE ]; +}; + +struct cl_vns_db { +bool enable; +bool dbg; +bool dbg_per_packet; +u16 interval_period; +spinlock_t lock; +struct cl_vns_mgmt_db mgmt_db; +}; + +struct cl_vns_sta_db { +bool is_very_near; +bool prev_decision; +s32 rssi_sum[MAX_ANTENNAS ]; +s32 rssi_samples; +}; + +int cl_vns_init (struct cl_hw *cl_hw); +void cl_vns_close (struct cl_hw *cl_hw); +void cl_vns_maintenance (struct cl_hw *cl_hw); +void cl_vns_mgmt_handler (struct cl_hw *cl_hw,u8 *addr,s8 rssi[MAX_ANTENNAS ]); +bool cl_vns_is_very_near (struct cl_hw *cl_hw,struct cl_sta *cl_sta,struct sk_buff *skb); +void cl_vns_sta_add (struct cl_hw *cl_hw,struct cl_sta *cl_sta); +void cl_vns_handle_rssi (struct cl_hw *cl_hw,struct cl_sta *cl_sta,s8 rssi[MAX_ANTENNAS ]); +void cl_vns_recovery (struct cl_hw *cl_hw); + +#endif /* CL_VNS_H */
Signature · 1 line
2.36.1
RFC v2 94/96 cl8k: add wrs.c
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/wrs.c | 3323 ++++++++++++++++++++++++ 1 file changed, 3323 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/wrs.c
drivers/net/wireless/celeno/cl8k/wrs.c new file +3323 -0
@@ -0,0 +1,3323 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#include <linux/kernel.h> + +#include "rates.h" +#include "chip.h" +#include "utils.h" +#include "hw.h" +#include "reg/reg_defs.h" +#include "debug.h" +#include "radio.h" +#include "wrs.h" + +#define wrs_pr (wrs_db, level, ...) \ + do { \ + if ((level) <= (wrs_db)->debug_level) \ + pr_debug("[WRS]" __VA_ARGS__); \ + } while (0) + +#define wrs_pr_verbose (wrs_db, ...) wrs_pr(wrs_db, DBG_LVL_VERBOSE, ##__VA_ARGS__) +#define wrs_pr_err (wrs_db, ...) wrs_pr(wrs_db, DBG_LVL_ERROR, ##__VA_ARGS__) +#define wrs_pr_warn (wrs_db, ...) wrs_pr(wrs_db, DBG_LVL_WARNING, ##__VA_ARGS__) +#define wrs_pr_trace (wrs_db, ...) wrs_pr(wrs_db, DBG_LVL_TRACE, ##__VA_ARGS__) +#define wrs_pr_info (wrs_db, ...) wrs_pr(wrs_db, DBG_LVL_INFO, ##__VA_ARGS__) + +#define WRS_LOGGER wrs_params->logger[wrs_params->logger_idx] + +static void cl_wrs_reset_params_cntrs (struct cl_wrs_params *wrs_params) +{ + wrs_params->frames_total =0 ; + wrs_params->fail_total =0 ; + wrs_params->ba_not_rcv_total =0 ; + wrs_params->epr_acc =0 ; + wrs_params->up_same_time_cnt =0 ; + wrs_params->down_time_cnt =0 ; +} + +static bool cl_wrs_down_epr_check (struct cl_wrs_db *wrs_db,struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params,u8 drop_factor, +enum cl_wrs_decision decision) +{ +u16 curr_rate_idx = wrs_params->rate_idx; +struct cl_wrs_table *curr_rate = &wrs_params->table[curr_rate_idx]; +u64 curr_epr_acc = curr_rate->epr_acc; +u32 curr_total = curr_rate->frames_total; +u16 down_rate_idx = curr_rate->rate_down.rate_idx; +struct cl_wrs_table *down_rate = &wrs_params->table[down_rate_idx]; +u64 down_epr_acc = down_rate->epr_acc; +u32 down_total = down_rate->frames_total; +u16 down_data_rate =0 ; +u64 condition1 =0 , condition2 =0 ; +bool down_decision = false, allow_penalty = true; + +if (wrs_params->calc_ba_not_rcv) { + curr_total += curr_rate->ba_not_rcv_total; + down_total += down_rate->ba_not_rcv_total; + } + +/* +* In the EPR of down candidate is better than or equal to current EPR => return true +* +* (1) curr_epr <= down_epr * factor(%) +* +* curr_epr_acc down_epr_acc factor +* (2) -------------- <= -------------- * -------- +* curr_total down_total 100 +* +* (3) curr_epr_acc * down_total * 100 <= down_epr_acc * curr_total * factor +* +* (4) conditation1 <= conditation2 +* down_epr_acc +* If (down_total == 0) we use down_data_rate instead of: -------------- +* down_total +*/ +if (down_total) { + condition1 = curr_epr_acc * down_total *100 ; + condition2 = down_epr_acc * curr_total * drop_factor; + }else { + down_data_rate =cl_data_rates_get_x10 (wrs_params->rate_params.mode, + down_rate->rate.bw, + down_rate->rate.nss, + down_rate->rate.mcs, + down_rate->rate.gi); + + condition1 = curr_epr_acc *100 ; + condition2 = (u64 )down_data_rate * curr_total * drop_factor; + allow_penalty = false; + } + + wrs_params->penalty_decision_dn = wrs_db->step_down; + +if (condition2 && condition1 <= condition2) { + down_decision = true; + +if (allow_penalty) { +/* +* The penalty is calculated as follow: +* +* penalty = MAX_STEP * penalty_factor +* epr_curr +* penalty = MAX_STEP * (100% - 100% * ----------) +* epr_down +* +* conditation1 +* penalty = MAX_STEP * (100% - 100% --------------) +* conditation2 +*/ + +u64 penalty_factor =100 -div64_u64 (condition1 *100 , condition2); +u16 max_step = wrs_db->time_th_max_up - wrs_db->step_down; + + wrs_params->penalty_decision_dn += +div64_u64 (max_step * penalty_factor,100 ); + } + +if (decision !=WRS_DECISION_SAME ) +wrs_pr_info (wrs_db, +"[%s] EPR check: sta = %u, pkt_curr = %u, " +"pkt_down = %u, epr_curr = %llu, epr_down * %u%% = %llu, " +"penalty = %u\n" , +WRS_TYPE_STR (wrs_params->type), + wrs_sta->sta_idx, + curr_total, + down_total, +div64_u64 (curr_epr_acc, curr_total *10 ), + drop_factor, + down_total ? +div64_u64 (down_epr_acc * drop_factor, down_total *1000 ) : + (down_data_rate /10 ), + wrs_params->penalty_decision_dn); + } + +if (wrs_params->is_logger_en && down_decision) { +WRS_LOGGER .curr_epr = (u16 )div64_u64 (curr_epr_acc,10 * curr_total); +WRS_LOGGER .down_epr = down_total ? + (u16 )div64_u64 (down_epr_acc, down_total *10 ) : (down_data_rate /10 ), +WRS_LOGGER .down_epr_factorized =WRS_LOGGER .down_epr * drop_factor /100 ; +WRS_LOGGER .penalty = wrs_params->penalty_decision_dn; + } + +return down_decision; +} + +static void cl_wrs_time_thr_max_handler (struct cl_wrs_db *wrs_db, +struct cl_wrs_table *table,u8 up_idx) +{ +/* +* Check if there are at least two UP rates, +* and all UP rates reached max time threshold +*/ +u8 i =0 ; +u8 time_th_max =0 ; + +for (i =0 ; i <WRS_TABLE_NODE_UP_MAX ; i++) { +if (table->rate_up[i].rate_idx ==WRS_INVALID_RATE ) +continue ; + +if (table->rate_up[i].time_th != wrs_db->time_th_max_up) +return ; + + time_th_max++; + } + +if (time_th_max <2 ) +return ; + +/* Find the next max rate, and decrease its time threshold by 1 */ + i =0 ; +while (i <WRS_TABLE_NODE_UP_MAX ) { + up_idx++; +if (up_idx ==WRS_TABLE_NODE_UP_MAX ) + up_idx =WRS_TABLE_NODE_UP_MCS ; + +if (table->rate_up[up_idx].rate_idx !=WRS_INVALID_RATE ) { +/* +* If all up rates reached max time threshold,the first up +* rate will always be selected. +* To overcome it, we decrease the time threshold of the next +* up rate by 1 (so it will be samller and selected next time) +*/ + table->rate_up[up_idx].time_th--; +break ; + } + + i++; + } +} + +static bool cl_wrs_find_up_candidate (struct cl_wrs_db *wrs_db,struct cl_wrs_params *wrs_params, +u16 *up_rate_idx,u32 *up_time_th) +{ +bool up_rate_valid = false; +u8 up_idx =0 ; +u8 up_candidate =0 ; +u16 rate_idx =0 ; +struct cl_wrs_table *table = &wrs_params->table[wrs_params->rate_idx]; + + *up_rate_idx =WRS_INVALID_RATE ; + *up_time_th =U32_MAX ; + +for (up_idx =0 ; up_idx <WRS_TABLE_NODE_UP_MAX ; up_idx++) { + rate_idx = table->rate_up[up_idx].rate_idx; + +if (rate_idx ==WRS_INVALID_RATE ) +continue ; + +if (wrs_db->quick_up_en && table->rate_up[up_idx].quick_up_check) { + *up_rate_idx = rate_idx; + *up_time_th = wrs_db->quick_up_interval; + up_rate_valid = true; + up_candidate = up_idx; +break ; + }else if (table->rate_up[up_idx].time_th < *up_time_th) { + *up_rate_idx = rate_idx; + *up_time_th = table->rate_up[up_idx].time_th; + up_rate_valid = true; + up_candidate = up_idx; + } + } + +if (wrs_db->time_th_max_up == *up_time_th) +cl_wrs_time_thr_max_handler (wrs_db, table, up_candidate); + +return up_rate_valid; +} + +static bool cl_wrs_epr_immeidate_down (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params, +u16 down_rate_idx) +{ +if (cl_wrs_down_epr_check (wrs_db, wrs_sta, wrs_params, + wrs_db->immediate_drop_epr_factor, +WRS_DECISION_DOWN_IMMEDIATE )) { +/* +* If there are several immediate drops in a row ignore them, +* because it is probably not realted to bad TX rate +*/ + wrs_params->immediate_drop_cntr++; + +if (wrs_params->immediate_drop_cntr > wrs_db->immediate_drop_max_in_row) { + wrs_params->immediate_drop_ignore++; + +cl_wrs_tables_reset (wrs_db, wrs_sta, wrs_params); +cl_wrs_reset_params_cntrs (wrs_params); + +wrs_pr_info (wrs_db, +"[%s] sta %u - ignore immediate down decision (cntr=%u)\n" , +WRS_TYPE_STR (wrs_params->type), wrs_sta->sta_idx, + wrs_params->immediate_drop_cntr); +return true; + } + +cl_wrs_decision_make (cl_hw, wrs_db, wrs_sta, wrs_params, +WRS_DECISION_DOWN_IMMEDIATE , down_rate_idx); +return true; + } + +return false; +} + +static void cl_wrs_decision_up (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params, +u16 up_rate_idx,u32 up_th) +{ +enum cl_wrs_decision up_decision = (up_th == wrs_db->quick_up_interval) ? +WRS_DECISION_UP_QUICK :WRS_DECISION_UP ; + +if (wrs_params->is_logger_en) +WRS_LOGGER .up_time = wrs_params->up_same_time_cnt; + +cl_wrs_decision_make (cl_hw, wrs_db, wrs_sta, wrs_params, up_decision, up_rate_idx); +} + +static void cl_wrs_decision_same (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params, +u16 rate_idx) +{ +cl_wrs_decision_make (cl_hw, wrs_db, wrs_sta, wrs_params,WRS_DECISION_SAME , rate_idx); +} + +static void cl_wrs_epr_decision (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params) +{ +u16 curr_rate_idx = wrs_params->rate_idx; +struct cl_wrs_table *table = &wrs_params->table[curr_rate_idx]; +u16 down_rate_idx = table->rate_down.rate_idx; +u16 up_rate_idx =0 ; +u16 down_th = table->rate_down.time_th; +u32 up_th =0 ; +bool up_rate_valid = false; + +/* Check if we transmitted enough frames for taking decision */ +if ((wrs_params->frames_total + wrs_params->ba_not_rcv_total) < + wrs_db->min_frames_for_decision) +return ; + +if (wrs_params->is_logger_en) { +WRS_LOGGER .timestamp =jiffies_to_msecs (jiffies); +WRS_LOGGER .rate_idx = wrs_params->rate_idx; +WRS_LOGGER .success = wrs_params->frames_total - wrs_params->fail_total; +WRS_LOGGER .fail = wrs_params->fail_total; +WRS_LOGGER .ba_not_rcv = wrs_params->ba_not_rcv_total; + } + + up_rate_valid =cl_wrs_find_up_candidate (wrs_db, wrs_params, &up_rate_idx, &up_th); + +/* RSSI protect */ +if (!WRS_TYPE_IS_TX_MU_MIMO (wrs_params) && wrs_db->rssi_protect_en) +if (cl_wrs_rssi_prot_decision (cl_hw, wrs_db, wrs_sta, wrs_params, + up_rate_valid, up_rate_idx, down_rate_idx)) +return ; + +if (down_rate_idx != curr_rate_idx) { +/* Down immediate */ +if (wrs_db->immediate_drop_en) +if (cl_wrs_epr_immeidate_down (cl_hw, wrs_db, wrs_sta, + wrs_params, down_rate_idx)) +return ; + +/* Down */ +if (wrs_params->down_time_cnt >= down_th) { +if (cl_wrs_down_epr_check (wrs_db, wrs_sta, wrs_params, + wrs_db->epr_factor,WRS_DECISION_DOWN )) { +cl_wrs_decision_make (cl_hw, wrs_db, wrs_sta, wrs_params, +WRS_DECISION_DOWN , down_rate_idx); +return ; + } + + wrs_params->down_time_cnt =0 ; + } + } + +/* Up-same */ +if (wrs_params->up_same_time_cnt >= up_th) { +if (up_rate_valid) +cl_wrs_decision_up (cl_hw, wrs_db, wrs_sta, wrs_params, up_rate_idx, up_th); +else +cl_wrs_decision_same (cl_hw, wrs_db, wrs_sta, wrs_params, curr_rate_idx); + +return ; + } + +/* +* If there is no valid UP rate and the EPR is more +* than EPR down threshold => make a same decision +*/ +if (!up_rate_valid && + !cl_wrs_down_epr_check (wrs_db, wrs_sta, wrs_params, + wrs_db->epr_factor,WRS_DECISION_SAME )) +cl_wrs_decision_same (cl_hw, wrs_db, wrs_sta, wrs_params, curr_rate_idx); +} + +static void cl_wrs_divide_weights_by_two (struct cl_wrs_table *table_node) +{ +u8 up_idx =0 ; +struct cl_wrs_table_node *rate_up; + +/* +* Converge weights - divide all weights by 2 +* (make sure they do not go below their init value) +*/ +if (table_node->rate_down.rate_idx !=WRS_INVALID_RATE ) + table_node->rate_down.time_th =max (table_node->rate_down.time_th >>1 , +WRS_INIT_MSEC_WEIGHT_DOWN ); + +for (up_idx =0 ; up_idx <WRS_TABLE_NODE_UP_MAX ; up_idx++) { + rate_up = &table_node->rate_up[up_idx]; + +if (rate_up->rate_idx !=WRS_INVALID_RATE ) + rate_up->time_th =max (rate_up->time_th >>1 ,WRS_INIT_MSEC_WEIGHT_UP ); + +if (rate_up->time_th ==WRS_INIT_MSEC_WEIGHT_UP ) + rate_up->quick_up_check = false; + } +} + +static void cl_wrs_converge_weights (struct cl_wrs_params *wrs_params) +{ +/* +* Converge weights - divide the weights by 2 (except for the current rate), +* and reset PER counters (except for current rate, down rate, and down-down rate). +*/ +u16 i; +u16 curr_idx = wrs_params->rate_idx; +u16 down_idx = wrs_params->table[curr_idx].rate_down.rate_idx; +u16 down2_idx = wrs_params->table[down_idx].rate_down.rate_idx; + +for (i =0 ; i < wrs_params->table_size; i++) { +if (i == curr_idx) +continue ; + +cl_wrs_divide_weights_by_two (&wrs_params->table[i]); + +if (i != down_idx && i != down2_idx) { + wrs_params->table[i].frames_total =0 ; + wrs_params->table[i].ba_not_rcv_total =0 ; + wrs_params->table[i].epr_acc =0 ; + } + } +} + +static void cl_wrs_converge_weights_idle_decision (struct cl_hw *cl_hw, +struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params) +{ +/* +* Continue normal converge (just like during traffic). +* After 6 seconds reset table, and select rate based on RSSI. +*/ +if (!wrs_db->converge_idle_en) +return ; + + wrs_params->converge_time_idle += wrs_db->interval; + +if (wrs_params->converge_mode ==WRS_CONVERGE_MODE_RESET ) { +if (wrs_params->converge_time_idle < wrs_db->converge_idle_interval_reset) { +cl_wrs_converge_weights (wrs_params); + }else { + wrs_params->converge_mode =WRS_CONVERGE_MODE_RSSI ; + wrs_params->converge_time_idle =0 ; + +wrs_pr_info (wrs_db,"[%s] Converge weights: sta %u - RSSI\n" , +WRS_TYPE_STR (wrs_params->type), wrs_sta->sta_idx); + +/* Reset table and choose new rate based on RSSI */ +cl_wrs_tables_reset (wrs_db, wrs_sta, wrs_params); + +if (!WRS_TYPE_IS_TX_MU_MIMO (wrs_params)) +cl_wrs_set_rate_idle (cl_hw, wrs_db, wrs_sta, wrs_params); + } + }else { +if (wrs_params->converge_time_idle < wrs_db->converge_idle_interval_rssi) +return ; + +/* Choose new rate */ +if (!WRS_TYPE_IS_TX_MU_MIMO (wrs_params)) { + wrs_params->converge_time_idle =0 ; +cl_wrs_set_rate_idle (cl_hw, wrs_db, wrs_sta, wrs_params); + } + } +} + +static void cl_wrs_converge_weights_idle_reset (struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params) +{ +/* There was traffic in last maintenance interval - reset converge parameteres */ + wrs_params->converge_time_idle =0 ; + +if (wrs_params->converge_mode !=WRS_CONVERGE_MODE_RESET ) { + wrs_params->converge_mode =WRS_CONVERGE_MODE_RESET ; +wrs_pr_info (wrs_db,"[%s] Converge weights: sta %u - RESET\n" , +WRS_TYPE_STR (wrs_params->type), wrs_sta->sta_idx); + } +} + +static void cl_wrs_converge_weights_trfc_decision (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_wrs_db *wrs_db, +struct cl_wrs_params *wrs_params) +{ +u32 converge_interval =0 ; + +if (!wrs_db->converge_trfc_en) +return ; + + converge_interval = wrs_db->converge_trfc_interval_static; + +if (!cl_motion_sense_is_static (cl_hw, cl_sta)) + converge_interval = wrs_db->converge_trfc_interval_motion; + + wrs_params->converge_time_trfc += wrs_db->interval; + +if (wrs_params->converge_time_trfc >= converge_interval) { + wrs_params->converge_time_trfc =0 ; +cl_wrs_converge_weights (wrs_params); + } +} + +static u32 cl_wrs_get_sync_attempts (struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params) +{ + struct cl_sta *cl_sta = container_of(wrs_sta, struct cl_sta, wrs_sta); +struct cl_wrs_info *wrs_info =cl_wrs_info_get (cl_sta, wrs_params->type); + +return wrs_info->sync_attempts; +} + +static void cl_wrs_sta_no_sync_handler (struct cl_hw *cl_hw, +struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params) +{ +unsigned long time_delta =jiffies_to_msecs (jiffies - wrs_params->no_sync_timestamp); + +if (time_delta < wrs_db->sync_timeout) +return ; + +if (cl_wrs_get_sync_attempts (wrs_sta, wrs_params) < wrs_db->sync_min_attempts) { +/* +* Rate not synced but there is also hardly no traffic - +* change mode to synced! +*/ + wrs_params->sync = true; + wrs_params->sync_timestamp = jiffies; + }else { +struct cl_wrs_table *wrs_table = &wrs_params->table[wrs_params->rate_idx]; +struct cl_wrs_rate *curr_rate = &wrs_table->rate; + +if (IS_REAL_PHY (cl_hw->chip)) +wrs_pr_warn (wrs_db, +"[%s] NO SYNC - sta = %u, bw = %u, nss = %u, mcs = %u, gi = %u\n" , +WRS_TYPE_STR (wrs_params->type), wrs_sta->sta_idx, curr_rate->bw, + curr_rate->nss, curr_rate->mcs, curr_rate->gi); + +if (WRS_IS_DECISION_UP (wrs_params->last_decision)) { +cl_wrs_decision_make (cl_hw, wrs_db, wrs_sta, wrs_params, +WRS_DECISION_DOWN_NO_SYNC , + wrs_table->rate_down.rate_idx); + }else { +/* If the last decision was DOWN - change state to SYNCED. */ + wrs_params->sync = true; + wrs_params->sync_timestamp = jiffies; + } + } +} + +static void cl_wrs_update_ba_not_rcv (struct cl_wrs_db *wrs_db,struct cl_wrs_params *wrs_params) +{ +unsigned long time_since_sync =jiffies_to_msecs (jiffies - wrs_params->sync_timestamp); + + wrs_params->calc_ba_not_rcv = (wrs_db->ba_not_rcv_force || + (time_since_sync < wrs_db->ba_not_rcv_time_since_sync)); +} + +static void _cl_wrs_cntrs_reset (struct cl_wrs_info *wrs_info) +{ + wrs_info->epr_acc =0 ; + wrs_info->success =0 ; + wrs_info->fail =0 ; + wrs_info->ba_not_rcv =0 ; + wrs_info->ba_not_rcv_consecutive_max =0 ; +} + +static void cl_wrs_cntrs_read (struct cl_wrs_sta *wrs_sta, +struct cl_wrs_cntrs *cntrs, +u8 type) +{ + struct cl_sta *cl_sta = container_of(wrs_sta, struct cl_sta, wrs_sta); +struct cl_wrs_info *wrs_info =cl_wrs_info_get (cl_sta, type); + + cntrs->epr_acc = wrs_info->epr_acc; + cntrs->total = wrs_info->success + wrs_info->fail; + cntrs->fail = wrs_info->fail; + cntrs->ba_not_rcv = wrs_info->ba_not_rcv; + cntrs->ba_not_rcv_consecutive = wrs_info->ba_not_rcv_consecutive_max; + +_cl_wrs_cntrs_reset (wrs_info); +} + +static void _cl_wrs_sta_maintenance (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_wrs_params *wrs_params) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; +struct cl_wrs_sta *wrs_sta = &cl_sta->wrs_sta; +struct cl_wrs_cntrs cntrs = {0 }; + +if (wrs_params->is_logger_en) +memset (&WRS_LOGGER ,0 ,sizeof (struct cl_wrs_logger )); + +if (!wrs_params->sync) { +cl_wrs_sta_no_sync_handler (cl_hw, wrs_db, wrs_sta, wrs_params); + goto end_logger; + } + +if (!WRS_TYPE_IS_RX (wrs_params)) +cl_wrs_update_ba_not_rcv (wrs_db, wrs_params); + +cl_wrs_cntrs_read (wrs_sta, &cntrs, wrs_params->type); + +if (wrs_params->is_fixed_rate) { +cl_wrs_stats_per_update (wrs_db, wrs_sta, wrs_params, &cntrs); + goto end_logger; + } + + wrs_params->down_time_cnt += wrs_db->interval; + wrs_params->up_same_time_cnt += wrs_db->interval; + +if ((cntrs.total + cntrs.ba_not_rcv) < wrs_db->converge_idle_packet_th) { +/* +* Very few frames were sent in last maintenance interval +* Check if weights should be converged +*/ +cl_wrs_converge_weights_idle_decision (cl_hw, wrs_db, wrs_sta, wrs_params); + +cl_wrs_stats_per_update (wrs_db, wrs_sta, wrs_params, &cntrs); + + goto end_logger; + }else { +/* There was traffic in last maintenance interval - reset converge parameteres */ +cl_wrs_converge_weights_idle_reset (wrs_db, wrs_sta, wrs_params); + } + +cl_wrs_stats_per_update (wrs_db, wrs_sta, wrs_params, &cntrs); + + wrs_params->quick_up_check = + (cntrs.ba_not_rcv_consecutive >= wrs_db->quick_up_ba_thr); +cl_wrs_epr_decision (cl_hw, wrs_db, wrs_sta, wrs_params); + +cl_wrs_converge_weights_trfc_decision (cl_hw, cl_sta, wrs_db, wrs_params); + +end_logger: +if (wrs_params->is_logger_en &&WRS_LOGGER .decision !=WRS_DECISION_NONE ) + wrs_params->logger_idx =WRS_INC_POW2 (wrs_params->logger_idx, + wrs_params->logger_size); +} + +static void cl_wrs_sta_maintenance (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +_cl_wrs_sta_maintenance (cl_hw, cl_sta, &cl_sta->wrs_sta.tx_su_params); + +if (cl_sta->wrs_sta.rx_params) +_cl_wrs_sta_maintenance (cl_hw, cl_sta, cl_sta->wrs_sta.rx_params); +} + +static void cl_wrs_cca_calc (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db,u8 max_bw) +{ +u32 cca_primary_new =mac_hw_edca_cca_busy_get (cl_hw); +u32 cca_sec80_new = (max_bw >CHNL_BW_80 ) ?mac_hw_add_cca_busy_sec_80_get (cl_hw) :0 ; +u32 cca_sec40_new = (max_bw >CHNL_BW_40 ) ?mac_hw_add_cca_busy_sec_40_get (cl_hw) :0 ; +u32 cca_sec20_new =mac_hw_add_cca_busy_sec_20_get (cl_hw); + +u32 cca_primary_diff = cca_primary_new - wrs_db->cca_primary; +u32 cca_sec80_diff = cca_sec80_new - wrs_db->cca_sec80; +u32 cca_sec40_diff = cca_sec40_new - wrs_db->cca_sec40; +u32 cca_sec20_diff = cca_sec20_new - wrs_db->cca_sec20; + + wrs_db->cca_primary = cca_primary_new; + wrs_db->cca_sec80 = cca_sec80_new; + wrs_db->cca_sec40 = cca_sec40_new; + wrs_db->cca_sec20 = cca_sec20_new; + wrs_db->cca_timestamp = jiffies; + +/* Increase by 25% */ + cca_primary_diff = cca_primary_diff *WRS_CCA_PRIMARY_FACTOR >>WRS_CCA_PRIMARY_SHIFT ; + +/* Adjacent interference - if secondary is higher than primary by 25%. */ + wrs_db->adjacent_interference80 = (cca_sec80_diff > cca_primary_diff); + wrs_db->adjacent_interference40 = (cca_sec40_diff > cca_primary_diff); + wrs_db->adjacent_interference20 = (cca_sec20_diff > cca_primary_diff); +} + +static void cl_wrs_cca_maintenance (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db) +{ +u8 max_bw = wrs_db->max_cap.bw; + +if (max_bw ==CHNL_BW_20 ) +return ; + +if (jiffies_to_msecs (jiffies - wrs_db->cca_timestamp) >WRS_CCA_PERIOD_MS ) +cl_wrs_cca_calc (cl_hw, wrs_db, max_bw); +} + +static void cl_wrs_maintenance (struct timer_list *t) +{ +struct cl_wrs_db *wrs_db =from_timer (wrs_db, t, timer_maintenance); + struct cl_hw *cl_hw = container_of(wrs_db, struct cl_hw, wrs_db); + +cl_wrs_cca_maintenance (cl_hw, wrs_db); + +cl_wrs_lock (wrs_db); +cl_sta_loop (cl_hw, cl_wrs_sta_maintenance); +cl_wrs_unlock (wrs_db); + +mod_timer (&wrs_db->timer_maintenance, jiffies +msecs_to_jiffies (wrs_db->interval)); +} + +static void cl_wrs_down_decision_weights_update (struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta, +u16 new_rate_idx, +struct cl_wrs_params *wrs_params) +{ +u16 old_rate_idx = wrs_params->rate_idx; +u8 up_idx =0 ; +u16 down_th_min = wrs_db->time_th_min; +u16 step = wrs_db->step_down; +u16 *th_down = &wrs_params->table[old_rate_idx].rate_down.time_th; +u16 *th_up =NULL ; +struct cl_wrs_table *table_node = &wrs_params->table[new_rate_idx]; + +/* Decrease the weight from old rate to new rate */ +if (*th_down > (down_th_min + step)) + *th_down -= step; +else + *th_down = down_th_min; + +/* Increase the weight from new rate to old rate */ +for (up_idx =0 ; up_idx <WRS_TABLE_NODE_UP_MAX ; up_idx++) { +if (old_rate_idx == table_node->rate_up[up_idx].rate_idx) { + th_up = &table_node->rate_up[up_idx].time_th; + table_node->rate_up[up_idx].quick_up_check = !!wrs_params->quick_up_check; + step = wrs_params->penalty_decision_dn; + *th_up =min_t (u16, *th_up + step, wrs_db->time_th_max_up); +break ; + } + } + +wrs_pr_info (wrs_db, +"[%s] Down update - sta = %u, " +"down weight [%u-->%u] = %u, up weight [%u-->%u] = %u\n" , +WRS_TYPE_STR (wrs_params->type), wrs_sta->sta_idx, old_rate_idx, new_rate_idx, + *th_down, new_rate_idx, old_rate_idx, th_up ? *th_up :0 ); +} + +static void cl_wrs_up_same_decision_weights_update (struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params) +{ +u16 curr_rate_idx = wrs_params->rate_idx; +u16 down_rate_idx = wrs_params->table[curr_rate_idx].rate_down.rate_idx; +u8 up_idx =0 ; +u16 up_th_min = wrs_db->time_th_min; +u16 step = wrs_db->step_up_same; +u16 *th_down = &wrs_params->table[curr_rate_idx].rate_down.time_th; +u16 *th_up =NULL ; +u16 th_down_orig = *th_down; +u16 th_up_orig =0 ; +struct cl_wrs_table *table_node = &wrs_params->table[down_rate_idx]; + +/* Increase the weight from current rate to down rate */ + *th_down =min_t (u16, *th_down + step, wrs_db->time_th_max_down); + +/* Decrease the weight from down rate to current rate */ +for (up_idx =0 ; up_idx <WRS_TABLE_NODE_UP_MAX ; up_idx++) { +if (curr_rate_idx == table_node->rate_up[up_idx].rate_idx) { + th_up = &table_node->rate_up[up_idx].time_th; + table_node->rate_up[up_idx].quick_up_check = false; + + th_up_orig = *th_up; + +if (*th_up > (up_th_min + step)) + *th_up -= step; +else + *th_up = up_th_min; +break ; + } + } + +if (th_up && (th_up_orig != *th_up || th_down_orig != *th_down)) +wrs_pr_info (wrs_db, +"[%s] Up/same update - sta = %u, " +"down weight [%u-->%u] = %u, up weight [%u-->%u] = %u\n" , +WRS_TYPE_STR (wrs_params->type), wrs_sta->sta_idx, curr_rate_idx, + down_rate_idx, *th_down, down_rate_idx, curr_rate_idx, *th_up); +} + +static bool cl_wrs_is_rate_params_valid (struct cl_wrs_rate *rate_params) +{ +return (*(u16 *)rate_params !=U16_MAX ); +} + +void cl_wrs_init (struct cl_hw *cl_hw) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; + +/* Default configuration */ + wrs_db->debug_level =DBG_LVL_ERROR ; + wrs_db->rssi_protect_en = true; + wrs_db->rssi_protect_mode =WRS_RSSI_PROT_MODE_RSSI ; + wrs_db->rssi_protect_up_thr =WRS_RSSI_PROTECT_UP_THR ; + wrs_db->rssi_protect_dn_thr =WRS_RSSI_PROTECT_DN_THR ; + wrs_db->min_frames_for_decision =WRS_MIN_FRAMES_FOR_DECISION ; + wrs_db->epr_factor =WRS_EPR_FACTOR ; + wrs_db->converge_idle_en = true; + wrs_db->converge_idle_interval_reset =WRS_CONVERGE_IDLE_INTERVAL_RESET ; + wrs_db->converge_idle_interval_rssi =WRS_CONVERGE_IDLE_INTERVAL_RSSI ; + wrs_db->converge_idle_packet_th =WRS_CONVERGE_IDLE_PACKET_TH ; + wrs_db->converge_trfc_en = true; + wrs_db->converge_trfc_interval_static =WRS_CONVERGE_TRFC_INTERVAL_STATIC ; + wrs_db->converge_trfc_interval_motion =WRS_CONVERGE_TRFC_INTERVAL_MOTION ; + wrs_db->immediate_drop_en = true; + wrs_db->immediate_drop_epr_factor =WRS_IMMEDIATE_DROP_EPR_FACTOR ; + wrs_db->immediate_drop_max_in_row =WRS_IMMEDIATE_DROP_MAX_IN_ROW ; + wrs_db->time_th_min =WRS_MSEC_WEIGHT_MIN ; + wrs_db->time_th_max_up =WRS_MSEC_WEIGHT_MAX_UP ; + wrs_db->time_th_max_down =WRS_MSEC_WEIGHT_MAX_DOWN ; + wrs_db->step_down =WRS_MSEC_STEP_DOWN ; + wrs_db->step_up_same =WRS_MSEC_STEP_UP_SAME ; + wrs_db->interval =msecs_round (WRS_MAINTENANCE_PERIOD_MS ); + wrs_db->conservative_mcs_noisy_env = false; + wrs_db->conservative_nss_noisy_env = false; + wrs_db->quick_up_en = true; + wrs_db->quick_up_ba_thr =WRS_QUICK_UP_BA_THR ; + wrs_db->quick_up_interval =msecs_round (WRS_QUICK_UP_INTERVAL_MS ); + wrs_db->quick_down_en = true; + wrs_db->quick_down_epr_factor =WRS_QUICK_DOWN_EPR_FACTOR ; + wrs_db->quick_down_agg_thr =WRS_QUICK_DOWN_AGG_THR ; + wrs_db->quick_down_pkt_thr =WRS_QUICK_DOWN_PKT_THR ; + wrs_db->ba_not_rcv_collision_filter = true; +/* Environment of 2.4 is much more noisy, so 'BA not received' are ignored. */ + wrs_db->ba_not_rcv_force =cl_band_is_24g (cl_hw) ? false : true; + wrs_db->ba_not_rcv_time_since_sync =WRS_BA_NOT_RCV_TIME_SINCE_SYNC ; + wrs_db->sync_timeout =WRS_SYNC_TIMEOUT ; + wrs_db->sync_min_attempts =WRS_SYNC_MIN_ATTEMPTS ; + +/* Init WRS periodic timer */ +timer_setup (&wrs_db->timer_maintenance, cl_wrs_maintenance,0 ); + +if (!cl_hw->chip->conf->ce_production_mode) { + wrs_db->cca_timestamp = jiffies; +mod_timer (&wrs_db->timer_maintenance, + jiffies +msecs_to_jiffies (wrs_db->interval)); + } + +spin_lock_init (&wrs_db->lock); + +if ((cl_hw->conf->ci_wrs_fixed_rate[WRS_FIXED_PARAM_MODE ] !=-1 ) && + (cl_hw->conf->ci_wrs_fixed_rate[WRS_FIXED_PARAM_BW ] !=-1 ) && + (cl_hw->conf->ci_wrs_fixed_rate[WRS_FIXED_PARAM_NSS ] !=-1 ) && + (cl_hw->conf->ci_wrs_fixed_rate[WRS_FIXED_PARAM_MCS ] !=-1 ) && + (cl_hw->conf->ci_wrs_fixed_rate[WRS_FIXED_PARAM_GI ] !=-1 )) + wrs_db->is_fixed_rate =WRS_FIXED_FALLBACK_DIS ; +} + +inline void cl_wrs_lock_bh (struct cl_wrs_db *wrs_db) +{ +spin_lock_bh (&wrs_db->lock); +} + +inline void cl_wrs_unlock_bh (struct cl_wrs_db *wrs_db) +{ +spin_unlock_bh (&wrs_db->lock); +} + +inline void cl_wrs_lock (struct cl_wrs_db *wrs_db) +{ +spin_lock (&wrs_db->lock); +} + +inline void cl_wrs_unlock (struct cl_wrs_db *wrs_db) +{ +spin_unlock (&wrs_db->lock); +} + +void cl_wrs_rate_param_sync (struct cl_wrs_db *wrs_db,struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params) +{ +if (wrs_params->sync) +return ; + +cl_wrs_cntrs_reset (wrs_sta, wrs_params); + +/* Reset counters */ +cl_wrs_reset_params_cntrs (wrs_params); + +/* Change state to SYNCED */ + wrs_params->sync = true; + wrs_params->sync_timestamp = jiffies; + +wrs_pr_trace (wrs_db,"[%s] Sync - timestamp = %u, sta = %u, rate_idx = %u\n" , +WRS_TYPE_STR (wrs_params->type), +jiffies_to_msecs (jiffies), + wrs_sta->sta_idx, + wrs_params->rate_idx); +} + +void cl_wrs_rate_params_update (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params, +u16 new_rate_idx,bool is_sync_required,bool mu_valid) +{ +struct cl_wrs_rate_params *rate_params = &wrs_params->rate_params; +struct cl_wrs_rate *rate = &wrs_params->table[new_rate_idx].rate; +u16 fallback_rate_idx = wrs_params->table[new_rate_idx].rate_down.rate_idx; +struct cl_wrs_rate *rate_fallback = &wrs_params->table[fallback_rate_idx].rate; +#ifdef CONFIG_CL8K_DYN_BCAST_RATE + +if (!WRS_TYPE_IS_RX (wrs_params)) { + struct cl_sta *cl_sta = container_of(wrs_sta, struct cl_sta, wrs_sta); + +cl_dyn_bcast_rate_change (cl_hw, cl_sta, rate_params->mcs, rate->mcs); + } +#endif /* CONFIG_CL8K_DYN_BCAST_RATE */ + + rate_params->bw = rate->bw; + rate_params->nss = rate->nss; + rate_params->mcs = rate->mcs; + rate_params->gi = rate->gi; + rate_params->mode = wrs_sta->mode; + rate_params->fallback_en = (wrs_params->is_fixed_rate !=WRS_FIXED_FALLBACK_DIS ); + +wrs_pr_trace (wrs_db, +"[%s] Rate params update - " +"sta = %u, rate_idx = %u, bw = %u, nss = %u, mcs = %u, gi = %u\n" , +WRS_TYPE_STR (wrs_params->type), wrs_sta->sta_idx, + new_rate_idx, rate_params->bw, rate_params->nss, + rate_params->mcs, rate_params->gi); + + wrs_params->rate_idx = new_rate_idx; + +/* Converge - restart the time for converging weights of all old rates */ + wrs_params->converge_time_trfc =0 ; + +cl_wrs_rate_param_set (cl_hw, wrs_sta, wrs_params, rate_params, + rate_fallback, mu_valid, true); + +if (is_sync_required) { + wrs_params->sync = false; + wrs_params->no_sync_timestamp = jiffies; + }else { + wrs_params->sync = true; + } + +/* Reset Counters */ +cl_wrs_reset_params_cntrs (wrs_params); +} + +void cl_wrs_decision_make (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params, +enum cl_wrs_decision decision,u16 new_rate_idx) +{ +if (WRS_IS_DECISION_DOWN (decision)) { +cl_wrs_down_decision_weights_update (wrs_db, wrs_sta, new_rate_idx, wrs_params); + }else if (WRS_IS_DECISION_UP (decision)) { +cl_wrs_up_same_decision_weights_update (wrs_db, wrs_sta, wrs_params); + +if (wrs_params->rate_idx != wrs_params->table[new_rate_idx].rate_down.rate_idx) { +/* +* In case the down rate is different from the previous rate, +* update down rate index and reset the thresholds +*/ +struct cl_wrs_table_node *rate_down = + &wrs_params->table[new_rate_idx].rate_down; + + rate_down->rate_idx = wrs_params->rate_idx; + rate_down->time_th =WRS_INIT_MSEC_WEIGHT_DOWN ; + } + }else if (decision ==WRS_DECISION_SAME ) { +cl_wrs_up_same_decision_weights_update (wrs_db, wrs_sta, wrs_params); + +/* Reset counters besides down_time_cnt */ + wrs_params->frames_total =0 ; + wrs_params->fail_total =0 ; + wrs_params->ba_not_rcv_total =0 ; + wrs_params->epr_acc =0 ; + wrs_params->up_same_time_cnt =0 ; + } + +cl_wrs_decision_update (wrs_db, wrs_sta, wrs_params, decision, new_rate_idx); + +if (WRS_IS_DECISION_DOWN (decision) ||WRS_IS_DECISION_UP (decision)) +cl_wrs_rate_params_update (cl_hw, wrs_db, wrs_sta, wrs_params, + new_rate_idx, true, wrs_params->is_mu_valid); +} + +void cl_wrs_decision_update (struct cl_wrs_db *wrs_db,struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params,enum cl_wrs_decision decision, +u16 new_rate_idx) +{ + wrs_params->last_decision = decision; + wrs_params->decision_cnt[decision]++; + +if (decision !=WRS_DECISION_DOWN_IMMEDIATE ) + wrs_params->immediate_drop_cntr =0 ; + +if (wrs_params->is_logger_en) { +WRS_LOGGER .decision = decision; +WRS_LOGGER .new_rate_idx = new_rate_idx; + } + +if (decision ==WRS_DECISION_SAME ) +return ; + +wrs_pr_trace (wrs_db, +"[%s] Decision update - timestamp [%u] sta [%u] decision [%s]\n" , +WRS_TYPE_STR (wrs_params->type), +jiffies_to_msecs (jiffies), + wrs_sta->sta_idx, +WRS_DECISION_STR (decision)); +} + +void cl_wrs_fixed_rate_set (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params, +u8 is_fixed_rate,u8 mode,u8 bw,u8 nss,u8 mcs,u8 gi,bool mu_valid) +{ +u16 rate_idx =0 ; +u8 type = wrs_params->type; + +if (!is_fixed_rate) { + wrs_params->is_fixed_rate =WRS_AUTO_RATE ; +wrs_pr_verbose (wrs_db,"[%s] Station %u was set to auto rate!\n" , +WRS_TYPE_STR (type), wrs_sta->sta_idx); +cl_wrs_set_rate_idle (cl_hw, wrs_db, wrs_sta, wrs_params); +return ; + } + +if (mode != wrs_sta->mode) { +/* Set fixed rate with a different format-mode */ +struct cl_wrs_rate_params *rate_params = &wrs_params->rate_params; + +if (cl_band_is_6g (cl_hw) && mode !=WRS_MODE_HE ) { +wrs_pr_verbose (wrs_db,"[%s] Invalid format mode [%u] for 6GHz band\n" , +WRS_TYPE_STR (type), mode); +return ; + } +#ifdef CONFIG_CL8K_DYN_BCAST_RATE + +if (!WRS_TYPE_IS_RX (wrs_params)) { + struct cl_sta *cl_sta = container_of(wrs_sta, struct cl_sta, wrs_sta); + +cl_dyn_bcast_rate_change (cl_hw, cl_sta, rate_params->mcs, mcs); + } +#endif /* CONFIG_CL8K_DYN_BCAST_RATE */ + + rate_params->bw = bw; + rate_params->nss = nss; + rate_params->mcs = mcs; + rate_params->gi = gi; + rate_params->mode = mode; + rate_params->fallback_en = (wrs_params->is_fixed_rate !=WRS_FIXED_FALLBACK_DIS ); + + wrs_params->is_fixed_rate = is_fixed_rate; + +cl_wrs_rate_param_set (cl_hw, wrs_sta, wrs_params, rate_params, +NULL , mu_valid, true); +wrs_pr_verbose (wrs_db, +"[%s] Station %u set to %s - " +"mode=%u, bw=%u, nss=%u, mcs=%u, gi=%u\n" , +WRS_TYPE_STR (type), wrs_sta->sta_idx,FIXED_RATE_STR (is_fixed_rate), + mode, bw, nss, mcs, gi); +return ; + } + + rate_idx =cl_wrs_tables_find_rate_idx (wrs_params, bw, nss, mcs, gi); + +if (rate_idx ==WRS_INVALID_RATE ) { +wrs_pr_err (wrs_db, +"[%s] Invalid fixed rate - mode=%u, bw=%u, nss=%u, mcs=%u, gi=%u\n" , +WRS_TYPE_STR (type), mode, bw, nss, mcs, gi); +return ; + } + + wrs_params->is_fixed_rate = is_fixed_rate; +cl_wrs_rate_params_update (cl_hw, wrs_db, wrs_sta, wrs_params, rate_idx, false, false); +wrs_pr_verbose (wrs_db, +"[%s] Station %u set to %s - mode=%u, bw=%u, nss=%u, mcs=%u, gi=%u\n" , +WRS_TYPE_STR (type), wrs_sta->sta_idx,FIXED_RATE_STR (is_fixed_rate), + mode, bw, nss, mcs, gi); +} + +void cl_wrs_quick_down_check (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params) +{ +struct cl_wrs_cntrs cntrs = {0 }; +struct cl_wrs_table *table =NULL ; +u16 curr_rate_idx =0 ; +u16 down_rate_idx =0 ; +u8 type = wrs_params->type; + +if (!wrs_params->sync || + wrs_params->is_fixed_rate || + !WRS_IS_DECISION_UP (wrs_params->last_decision)) +return ; + +if (!WRS_TYPE_IS_RX (wrs_params)) +cl_wrs_update_ba_not_rcv (wrs_db, wrs_params); + +cl_wrs_cntrs_read (wrs_sta, &cntrs, type); +cl_wrs_stats_per_update (wrs_db, wrs_sta, wrs_params, &cntrs); + + curr_rate_idx = wrs_params->rate_idx; + table = &wrs_params->table[curr_rate_idx]; + down_rate_idx = table->rate_down.rate_idx; + +/* Check if we transmitted enough frames for taking decision */ +if (wrs_params->frames_total < wrs_db->min_frames_for_decision) +return ; + +if (wrs_params->is_logger_en) { +memset (&WRS_LOGGER ,0 ,sizeof (struct cl_wrs_logger )); +WRS_LOGGER .timestamp =jiffies_to_msecs (jiffies); +WRS_LOGGER .rate_idx = curr_rate_idx; +WRS_LOGGER .success = wrs_params->frames_total - wrs_params->fail_total; +WRS_LOGGER .fail = wrs_params->fail_total; +WRS_LOGGER .ba_not_rcv = wrs_params->ba_not_rcv_total; + } + +/* Down decision check */ +if (down_rate_idx != curr_rate_idx && +cl_wrs_down_epr_check (wrs_db, wrs_sta, wrs_params, + wrs_db->quick_down_epr_factor,WRS_DECISION_DOWN_QUICK )) +cl_wrs_decision_make (cl_hw, wrs_db, wrs_sta, wrs_params, +WRS_DECISION_DOWN_QUICK , down_rate_idx); + +if (wrs_params->is_logger_en &&WRS_LOGGER .decision !=WRS_DECISION_NONE ) + wrs_params->logger_idx =WRS_INC_POW2 (wrs_params->logger_idx, + wrs_params->logger_size); +} + +bool cl_wrs_up_mcs1 (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params) +{ +/* +* In case of big packets (4300 in VHT and 5400 in HE) and low +* rate (BW 20, NSS 1, MCS 0), firmware will increase rate to MCS 1, +* and give an indication to driver (set rate_fix_mcs1 in cl_agg_tx_report). +* WRS should also move to MCS 1, and give the maximum time +* penalty time from MCS 0 toMCS 1. +*/ +u16 curr_rate_idx = wrs_params->rate_idx; +u16 up_rate_idx =0 ; +struct cl_wrs_table *table = &wrs_params->table[curr_rate_idx]; + +if (!table || wrs_params->is_fixed_rate) +return false; + +if (table->rate.bw !=CHNL_BW_20 || + table->rate.nss !=WRS_SS_1 || + table->rate.mcs !=WRS_MCS_0 ) +return false; + + up_rate_idx =cl_wrs_tables_find_rate_idx (wrs_params, +CHNL_BW_20 ,WRS_SS_1 ,WRS_MCS_1 , table->rate.gi); + +if (up_rate_idx ==WRS_INVALID_RATE ) +return false; + +if (wrs_params->is_logger_en) { +memset (&WRS_LOGGER ,0 ,sizeof (struct cl_wrs_logger )); +WRS_LOGGER .timestamp =jiffies_to_msecs (jiffies); +WRS_LOGGER .rate_idx = curr_rate_idx; + } + + wrs_params->table[up_rate_idx].rate_down.time_th = wrs_db->time_th_max_up; + +cl_wrs_cntrs_reset (wrs_sta, wrs_params); +cl_wrs_decision_update (wrs_db, wrs_sta, wrs_params,WRS_DECISION_UP_MCS1 , up_rate_idx); +cl_wrs_rate_params_update (cl_hw, wrs_db, wrs_sta, wrs_params, + up_rate_idx, true, wrs_params->is_mu_valid); + +if (wrs_params->is_logger_en) + wrs_params->logger_idx =WRS_INC_POW2 (wrs_params->logger_idx, + wrs_params->logger_size); + +return true; +} + +void cl_wrs_rate_param_set (struct cl_hw *cl_hw,struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params, +struct cl_wrs_rate_params *rate_params, +struct cl_wrs_rate *rate_fallback, +bool mu_mimo_valid,bool set_su) +{ + struct cl_sta *cl_sta = container_of(wrs_sta, struct cl_sta, wrs_sta); +struct cl_wrs_info *wrs_info =NULL ; +u8 op_mode =0 ; +u8 ltf =0 ; +u8 ltf_fallback =0 ; +u8 sta_idx = cl_sta->sta_idx; +union cl_rate_ctrl_info rate_ctrl; +union cl_rate_ctrl_info rate_ctrl_fallback; +union cl_rate_ctrl_info_he rate_ctrl_he; + + rate_ctrl_he.word =0 ; + wrs_info =cl_wrs_info_get (cl_sta, wrs_params->type); + + wrs_params->data_rate =cl_data_rates_get (rate_params->mode, + rate_params->bw, + rate_params->nss, + rate_params->mcs, + rate_params->gi); + +/* +* Trying to transmit MU-MIMO in bw < bw of sounding (which is STA's max bw) will fail, +* So we prevent it from being transmitted with MU. +*/ +if (rate_params->bw != cl_sta->sta->bandwidth) + mu_mimo_valid = false; + + rate_ctrl.word =cl_rate_ctrl_generate (cl_hw, cl_sta, rate_params->mode, + rate_params->bw, rate_params->nss, + rate_params->mcs, rate_params->gi, + rate_params->fallback_en, mu_mimo_valid); + +/* For fallback rate use same mode (if it is NULL use same rate). */ +if (rate_fallback) { + rate_ctrl_fallback.word =cl_rate_ctrl_generate (cl_hw, + cl_sta, + rate_params->mode, + rate_fallback->bw, + rate_fallback->nss, + rate_fallback->mcs, + rate_fallback->gi, + rate_params->fallback_en, + mu_mimo_valid); + ltf_fallback =cl_map_gi_to_ltf (rate_params->mode, rate_fallback->gi); + }else { + rate_ctrl_fallback.word = rate_ctrl.word; + } + +/* Save current BF state and SS for the fallback rate */ +if (WRS_TYPE_IS_TX_SU (wrs_params)) { +struct cl_bf_sta_db *bf_db = &cl_sta->bf_db; + + bf_db->is_on = rate_ctrl.field.tx_bf; + bf_db->is_on_fallback = rate_ctrl_fallback.field.tx_bf; + bf_db->num_ss = rate_params->nss; + bf_db->num_ss_fallback = rate_fallback ? rate_fallback->nss : rate_params->nss; + } + +/* Reset counters */ + wrs_info->success =0 ; + wrs_info->fail =0 ; + +/* Mark rate as unsynced */ + wrs_info->synced = false; + wrs_info->quick_rate_check = false; + wrs_info->sync_attempts =0 ; + ltf =cl_map_gi_to_ltf (rate_params->mode, rate_params->gi); + +if (rate_params->mode ==WRS_MODE_HE ) + rate_ctrl_he.field.spatial_conf =RATE_CNTRL_HE_SPATIAL_CONF_DEF ; + +/* Send new rate to firmware */ +if (set_su) { +if (WRS_TYPE_IS_TX_SU (wrs_params)) { + op_mode =RATE_OP_MODE_STA_SU ; +cl_msg_tx_update_rate_dl (cl_hw, sta_idx, rate_ctrl.word, + rate_ctrl_fallback.word, rate_params->bw, + op_mode, wrs_params->group_id, mu_mimo_valid, + ltf, ltf_fallback, rate_ctrl_he.word); + }else if (WRS_TYPE_IS_RX (wrs_params)) { +u8 ul_gi_ltf =CL_TF_GI_TO_GI_LTF (rate_params->gi); + +cl_msg_tx_update_rate_ul (cl_hw, sta_idx, rate_params->bw, + rate_params->nss, rate_params->mcs, ul_gi_ltf); + } + } +} + +s8 cl_wrs_rssi_eq_calc (struct cl_hw *cl_hw,struct cl_wrs_sta *wrs_sta, +bool read_clear,s8 *sorted_rssi) +{ + struct cl_sta *cl_sta = container_of(wrs_sta, struct cl_sta, wrs_sta); +struct cl_wrs_rssi *wrs_rssi = &cl_sta->wrs_rssi; +int i; + +if (wrs_rssi->cnt ==0 ) { +memcpy (sorted_rssi, cl_sta->last_rssi, cl_hw->num_antennas); + goto sort; + } + +for (i =0 ; i < cl_hw->num_antennas; i++) + sorted_rssi[i] = (s8)(wrs_rssi->sum[i] / wrs_rssi->cnt); + +if (read_clear) +memset (wrs_rssi,0 ,sizeof (struct cl_wrs_rssi )); + +sort: +/* Sort RSSI values in descending order */ +cl_rssi_sort_descending (sorted_rssi, cl_hw->num_antennas); + +/* Calc equivalent RSSI */ +return cl_rssi_calc_equivalent (cl_hw, sorted_rssi); +} + +void cl_wrs_cntrs_reset (struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params) +{ + struct cl_sta *cl_sta = container_of(wrs_sta, struct cl_sta, wrs_sta); +struct cl_wrs_info *wrs_info =cl_wrs_info_get (cl_sta, wrs_params->type); + +_cl_wrs_cntrs_reset (wrs_info); +} + +struct cl_wrs_info *cl_wrs_info_get (struct cl_sta *cl_sta,u8 type) +{ +if (type ==WRS_TYPE_TX_SU ) +return &cl_sta->wrs_info_tx_su; +else if (type ==WRS_TYPE_RX ) +return &cl_sta->wrs_info_rx; + +return NULL ; +} + +struct cl_wrs_params *cl_wrs_params_get (struct cl_wrs_sta *wrs_sta,u8 type) +{ +if (type ==WRS_TYPE_TX_SU ) +return &wrs_sta->tx_su_params; +else if (type ==WRS_TYPE_RX ) +return wrs_sta->rx_params; + +return NULL ; +} + +void cl_wrs_update_rx_rate (struct cl_hw *cl_hw,struct cl_sta *cl_sta,struct hw_rxhdr *rxhdr) +{ +struct cl_wrs_rate *rate_params =NULL ; + +if (!cl_sta || + !cl_sta->wrs_sta.rx_params || + rxhdr->format_mod ==FORMATMOD_HE_TRIG ) +return ; + + rate_params = &cl_sta->wrs_sta.rx_params->rx_rate_idle; + + rate_params->bw = rxhdr->ch_bw; + rate_params->nss = rxhdr->n_sts; + rate_params->mcs = rxhdr->mcs; + rate_params->gi = rxhdr->gi_type; +} + +bool cl_wrs_set_rate_idle (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params) +{ +struct cl_wrs_rate *rx_rate_idle = &wrs_params->rx_rate_idle; +s8 rssi_sort[MAX_ANTENNAS ] = {0 }; +u16 new_rate_idx =0 ; +u8 decision; + +if (WRS_TYPE_IS_RX (wrs_params) && +cl_wrs_is_rate_params_valid (rx_rate_idle)) { + decision =WRS_DECISION_RX_RATE ; +if (wrs_params->initial_rate_idx !=WRS_INVALID_RATE ) + new_rate_idx = wrs_params->initial_rate_idx; +else +/* Get rate from last data packet */ + new_rate_idx =cl_wrs_tables_find_rate_idx (wrs_params, + rx_rate_idle->bw, + rx_rate_idle->nss, + rx_rate_idle->mcs, + rx_rate_idle->gi); + +cl_wrs_rx_rate_idle_reset (wrs_params); + }else { +/* Get rate from rssi */ +cl_wrs_rssi_eq_calc (cl_hw, wrs_sta, true, rssi_sort); + new_rate_idx =cl_wrs_rssi_find_rate (cl_hw, wrs_db, wrs_sta, wrs_params, rssi_sort); + decision =WRS_DECISION_RSSI_MGMT ; + } + +if (new_rate_idx != wrs_params->rate_idx) { +if (wrs_params->is_logger_en) { +memset (&WRS_LOGGER ,0 ,sizeof (struct cl_wrs_logger )); +WRS_LOGGER .timestamp =jiffies_to_msecs (jiffies); +WRS_LOGGER .rate_idx = wrs_params->rate_idx; + } + +cl_wrs_decision_update (wrs_db, wrs_sta, wrs_params, decision, new_rate_idx); +cl_wrs_rate_params_update (cl_hw, wrs_db, wrs_sta, wrs_params, + new_rate_idx, false, false); + }else { + wrs_params->sync = true; + } + +return true; +} + +struct cl_wrs_rate_params *cl_wrs_rx_rate_get (struct cl_sta *cl_sta) +{ +struct cl_wrs_params *rx_params = cl_sta->wrs_sta.rx_params; + +if (rx_params) +return &rx_params->rate_params; + +return NULL ; +} + +void cl_wrs_rx_rate_idle_reset (struct cl_wrs_params *rx_params) +{ +struct cl_wrs_rate *rate_idle = &rx_params->rx_rate_idle; + + *(u16 *)rate_idle =U16_MAX ; +} + +static void cl_wrs_ap_set_bitmap (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db) +{ +u8 mcs, bw, nss, rate_idx; + +memset (wrs_db->ap_supported_rates,0 ,sizeof (wrs_db->ap_supported_rates)); + +for (bw = cl_hw->conf->ci_wrs_min_bw; bw <= wrs_db->max_cap.bw; bw++) +for (nss =0 ; nss <= wrs_db->max_cap.nss; nss++) +for (mcs =0 ; mcs <= wrs_db->max_cap.mcs; mcs++) { + rate_idx = mcs + (nss *WRS_MCS_MAX ); + wrs_db->ap_supported_rates[bw] |=BIT (rate_idx); + } +} + +void cl_wrs_ap_capab_set (struct cl_hw *cl_hw, +u8 bw, +u8 use_sgi) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; +struct cl_wrs_rate *max_cap = &wrs_db->max_cap; +u8 conf_nss = cl_hw->conf->ce_tx_nss -1 ; + +switch (cl_hw->wireless_mode) { +case WIRELESS_MODE_HE : +case WIRELESS_MODE_HT_VHT_HE : + wrs_db->mode =WRS_MODE_HE ; + max_cap->bw = bw; + max_cap->nss = conf_nss; + max_cap->mcs =WRS_MCS_11 ; + max_cap->gi = use_sgi ?WRS_GI_VSHORT :0 ; +break ; +case WIRELESS_MODE_HT_VHT : + wrs_db->mode =WRS_MODE_VHT ; + max_cap->bw = bw; + max_cap->nss = conf_nss; + max_cap->mcs =WRS_MCS_9 ; + max_cap->gi = use_sgi ?WRS_GI_SHORT :0 ; +break ; +case WIRELESS_MODE_HT : + wrs_db->mode =WRS_MODE_HT ; + max_cap->bw =min_t (u8, bw,CHNL_BW_80 ); + max_cap->nss = conf_nss; + max_cap->mcs =WRS_MCS_7 ; + max_cap->gi = use_sgi ?WRS_GI_SHORT :0 ; +break ; +case WIRELESS_MODE_LEGACY : +default : +if (cl_hw->hw_mode ==HW_MODE_B ) { + wrs_db->mode =WRS_MODE_CCK ; + max_cap->mcs =WRS_MCS_3 ; + }else { + wrs_db->mode =WRS_MODE_OFDM ; + max_cap->mcs =WRS_MCS_7 ; + } + + max_cap->bw =CHNL_BW_20 ; + max_cap->nss =0 ; + max_cap->gi =0 ; +break ; + } + +if (cl_hw->conf->ci_wrs_max_bw < max_cap->bw) { + max_cap->bw = cl_hw->conf->ci_wrs_max_bw; +wrs_pr_warn (wrs_db,"Max BW limited to %uMHz\n" ,BW_TO_MHZ (max_cap->bw)); + } + + wrs_db->coex_bw =max_t (u8, max_cap->bw,CHNL_BW_40 ); + +cl_wrs_ap_set_bitmap (cl_hw, wrs_db); +} + +void cl_wrs_ap_capab_modify_bw (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db,u8 max_bw) +{ + wrs_db->max_cap.bw = max_bw; + +cl_wrs_ap_set_bitmap (cl_hw, wrs_db); +} + +void cl_wrs_ap_capab_modify_gi (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db,u8 use_sgi) +{ +switch (cl_hw->wireless_mode) { +case WIRELESS_MODE_HE : +case WIRELESS_MODE_HT_VHT_HE : + wrs_db->max_cap.gi = use_sgi ?WRS_GI_VSHORT :0 ; +break ; +case WIRELESS_MODE_HT : +case WIRELESS_MODE_HT_VHT : + wrs_db->max_cap.gi = use_sgi ?WRS_GI_SHORT :0 ; +break ; +default : + wrs_db->max_cap.gi =0 ; + } + +cl_wrs_ap_set_bitmap (cl_hw, wrs_db); +} + +void cl_wrs_api_init (struct cl_hw *cl_hw) +{ +cl_wrs_init (cl_hw); +cl_wrs_ap_capab_set (cl_hw, cl_hw->conf->ci_cap_bandwidth, + cl_hw->conf->ci_short_guard_interval); +} + +void cl_wrs_api_close (struct cl_hw *cl_hw) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; + +del_timer_sync (&wrs_db->timer_maintenance); +} + +void cl_wrs_api_sta_add (struct cl_hw *cl_hw,struct ieee80211_sta *sta) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; + +cl_wrs_lock_bh (wrs_db); +cl_wrs_sta_add (cl_hw, sta); + +if (sta->he_cap.has_he && cl_hw->conf->ce_wrs_rx_en) +cl_wrs_sta_add_rx (cl_hw, sta); + +cl_wrs_unlock_bh (wrs_db); +} + +void cl_wrs_api_sta_remove (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; + +cl_wrs_lock_bh (wrs_db); +cl_wrs_sta_remove (cl_hw, wrs_db, cl_sta); +cl_wrs_unlock_bh (wrs_db); +} + +void cl_wrs_api_bss_set_bw (struct cl_hw *cl_hw,u8 bw) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; + +cl_wrs_lock_bh (wrs_db); +cl_wrs_ap_capab_modify_bw (cl_hw, wrs_db, bw); +cl_wrs_unlock_bh (wrs_db); +} + +void cl_wrs_api_bss_set_sgi (struct cl_hw *cl_hw,u8 use_sgi) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; + +cl_wrs_lock_bh (wrs_db); +cl_wrs_ap_capab_modify_gi (cl_hw, wrs_db, use_sgi); +cl_wrs_unlock_bh (wrs_db); +} + +bool cl_wrs_api_bss_is_sgi_en (struct cl_hw *cl_hw) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; +bool ret = false; + +cl_wrs_lock_bh (wrs_db); + ret = wrs_db->max_cap.gi !=0 ; +cl_wrs_unlock_bh (wrs_db); + +return ret; +} + +void cl_wrs_api_bss_capab_update (struct cl_hw *cl_hw,u8 bw,u8 use_sgi) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; + +cl_wrs_lock_bh (wrs_db); +cl_wrs_ap_capab_set (cl_hw, bw, use_sgi); +cl_wrs_unlock_bh (wrs_db); +} + +void cl_wrs_api_nss_or_bw_changed (struct cl_hw *cl_hw,struct ieee80211_sta *sta,u8 nss,u8 bw) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; +struct cl_sta *cl_sta =IEEE80211_STA_TO_CL_STA (sta); +struct cl_wrs_sta *wrs_sta = &cl_sta->wrs_sta; + +cl_wrs_lock_bh (wrs_db); + + wrs_sta->max_rate_cap.nss = nss; + wrs_sta->max_rate_cap.bw = bw; +cl_wrs_sta_capabilities_set (wrs_db, sta); +cl_wrs_tables_build (cl_hw, wrs_sta, &wrs_sta->tx_su_params); + +cl_wrs_unlock_bh (wrs_db); +} + +void cl_wrs_api_he_minrate_changed (struct cl_sta *cl_sta,u8 he_minrate) +{ +struct cl_hw *cl_hw = cl_sta->cl_vif->cl_hw; +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; +struct cl_wrs_sta *wrs_sta = &cl_sta->wrs_sta; +u8 mcs =0 , nss =0 , bw =0 ; +u16 data_rate_x10 =0 ; + +cl_wrs_lock_bh (wrs_db); + + wrs_sta->he_minrate = he_minrate; +cl_wrs_tables_build (cl_hw, wrs_sta, &wrs_sta->tx_su_params); + +cl_wrs_unlock_bh (wrs_db); + +for (bw =0 ; bw < wrs_sta->max_rate_cap.bw; bw++) { +for (nss =0 ; nss < wrs_sta->max_rate_cap.nss; nss++) { +for (mcs =0 ; mcs < wrs_sta->max_rate_cap.mcs; mcs++) { + data_rate_x10 =cl_data_rates_get_x10 (WRS_MODE_HE , bw, + nss, mcs, +WRS_GI_LONG ); +if (data_rate_x10 >= (he_minrate *10 )) { +cl_rate_ctrl_set_default_per_he_minrate (cl_hw, bw, + nss, mcs, +WRS_GI_LONG ); +return ; + } + } + } + } +} + +static void _cl_wrs_api_recovery (struct cl_hw *cl_hw,struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params) +{ +u16 fallback_rate_idx = wrs_params->table[wrs_params->rate_idx].rate_down.rate_idx; +struct cl_wrs_rate *rate_fallback = &wrs_params->table[fallback_rate_idx].rate; +struct cl_wrs_rate_params *rate_params = &wrs_params->rate_params; +bool is_mu_valid = wrs_params->is_mu_valid; + +cl_wrs_rate_param_set (cl_hw, wrs_sta, wrs_params, rate_params, + rate_fallback, is_mu_valid, true); +} + +void cl_wrs_api_recovery (struct cl_hw *cl_hw) +{ +struct cl_sta *cl_sta =NULL ; +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; +struct cl_wrs_sta *wrs_sta =NULL ; + +cl_wrs_lock_bh (wrs_db); +cl_sta_lock (cl_hw); + +list_for_each_entry (cl_sta, &cl_hw->cl_sta_db.head, list) { + wrs_sta = &cl_sta->wrs_sta; + +_cl_wrs_api_recovery (cl_hw, wrs_sta, &wrs_sta->tx_su_params); + +if (wrs_sta->rx_params) +_cl_wrs_api_recovery (cl_hw, wrs_sta, wrs_sta->rx_params); + } + +cl_sta_unlock (cl_hw); +cl_wrs_unlock_bh (wrs_db); +} + +void cl_wrs_api_beamforming_sync (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; +struct cl_wrs_params *wrs_params = &cl_sta->wrs_sta.tx_su_params; +u8 up_idx =0 ; +u16 rate_idx = wrs_params->rate_idx; + +cl_wrs_lock (wrs_db); + +for (up_idx =0 ; up_idx <WRS_TABLE_NODE_UP_MAX ; up_idx++) + wrs_params->table[rate_idx].rate_up[up_idx].time_th =WRS_INIT_MSEC_WEIGHT_UP ; + +cl_wrs_unlock (wrs_db); + +wrs_pr_info (wrs_db,"[%s] sta %u - beamforming sync\n" , +WRS_TYPE_STR (wrs_params->type), cl_sta->sta_idx); +} + +void cl_wrs_api_quick_down_check (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_wrs_params *wrs_params) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; + +cl_wrs_lock (wrs_db); +cl_wrs_quick_down_check (cl_hw, wrs_db, &cl_sta->wrs_sta, wrs_params); +cl_wrs_unlock (wrs_db); +} + +void cl_wrs_api_rate_sync (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_wrs_params *wrs_params) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; + +cl_wrs_lock (wrs_db); +cl_wrs_rate_param_sync (wrs_db, &cl_sta->wrs_sta, wrs_params); +cl_wrs_unlock (wrs_db); +} + +bool cl_wrs_api_up_mcs1 (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_wrs_params *wrs_params) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; +bool result = false; + +cl_wrs_lock (wrs_db); + result =cl_wrs_up_mcs1 (cl_hw, wrs_db, &cl_sta->wrs_sta, wrs_params); +cl_wrs_unlock (wrs_db); + +return result; +} + +void cl_wrs_api_set_smps_mode (struct cl_hw *cl_hw,struct ieee80211_sta *sta,const u8 bw) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; +struct cl_sta *cl_sta =IEEE80211_STA_TO_CL_STA (sta); +struct cl_wrs_sta *wrs_sta = &cl_sta->wrs_sta; +u8 min_bw; + +if (sta->smps_mode ==IEEE80211_SMPS_STATIC || + sta->smps_mode ==IEEE80211_SMPS_DYNAMIC ) { +/* If RTS is enabled, there is no need to go down to 1ss */ +if (cl_prot_mode_get (cl_hw) ==TXL_PROT_RTS_FW ) +return ; + + wrs_sta->smps_enable = true; + }else if (sta->smps_mode ==IEEE80211_SMPS_OFF && wrs_sta->smps_enable) { + wrs_sta->smps_enable = false; + } + +cl_wrs_lock_bh (wrs_db); + min_bw =min_t (u8, bw, wrs_db->max_cap.bw); + +if (wrs_sta->max_rate_cap.bw != min_bw) { + wrs_sta->max_rate_cap.bw = min_bw; +wrs_pr_trace (wrs_db,"[TX_SU] SMPS mode: sta %u, bw %u\n" , + wrs_sta->sta_idx, min_bw); +cl_wrs_tables_build (cl_hw, wrs_sta, &wrs_sta->tx_su_params); + } + +cl_wrs_unlock_bh (wrs_db); +} + +u16 cl_wrs_api_get_tx_sta_data_rate (struct cl_sta *cl_sta) +{ +return cl_sta->wrs_sta.tx_su_params.data_rate; +} + +static enum rate_info_bw cl_wrs_mode_to_nl80211_rateinfo_bw (u8 bw) +{ +switch (bw) { +case CHNL_BW_20 : +return RATE_INFO_BW_20 ; +case CHNL_BW_40 : +return RATE_INFO_BW_40 ; +case CHNL_BW_80 : +return RATE_INFO_BW_80 ; +case CHNL_BW_160 : +return RATE_INFO_BW_160 ; +default : +return RATE_INFO_BW_20 ; + } +} + +void cl_wrs_fill_sinfo_rates (struct rate_info *rate_info, +const struct cl_wrs_params *wrs_params, +const struct cl_sta *sta) +{ + rate_info->bw =cl_wrs_mode_to_nl80211_rateinfo_bw (wrs_params->rate_params.bw); + rate_info->mcs = wrs_params->rate_params.mcs; + rate_info->nss = wrs_params->rate_params.nss +1 ; + rate_info->he_gi = wrs_params->rate_params.gi; + + rate_info->flags =0 ; +/* GI = 0.4 us */ +if (wrs_params->rate_params.mode <WRS_MODE_HE && wrs_params->rate_params.gi ==1 ) + rate_info->flags |=RATE_INFO_FLAGS_SHORT_GI ; + +if (wrs_params->rate_params.mode ==WRS_MODE_HT ) + rate_info->flags |=RATE_INFO_FLAGS_MCS ; + +if (wrs_params->rate_params.mode ==WRS_MODE_VHT ) + rate_info->flags |=RATE_INFO_FLAGS_VHT_MCS ; + +if (wrs_params->rate_params.mode ==WRS_MODE_HE ) { +enum cl_mu_ofdma_ru_type ru_type = sta->rate_ctrl_he.field.ru_type; + + rate_info->flags |=RATE_INFO_FLAGS_HE_MCS ; +if (ru_type) { + rate_info->he_ru_alloc =cl_ru_type_to_nl80211_he_ru_alloc (ru_type); + rate_info->bw =RATE_INFO_BW_HE_RU ; + } + } +} + +/* +* Section #1: +* rate based on rssi. +*/ +static s8 rssi_threshold_he[WRS_MCS_MAX_HE ] = { +-35 ,-40 ,-45 ,-50 ,-55 ,-60 ,-65 ,-70 ,-75 ,-80 ,-85 ,-90 +}; + +static s8 rssi_threshold_vht[WRS_MCS_MAX_VHT ] = { +-36 ,-42 ,-48 ,-54 ,-60 ,-66 ,-72 ,-78 ,-84 ,-90 +}; + +static s8 rssi_threshold_ht[WRS_MCS_MAX_HT ] = { +-34 ,-42 ,-50 ,-58 ,-66 ,-74 ,-82 ,-90 +}; + +static s8 rssi_threshold_ofdm[WRS_MCS_MAX_OFDM ] = { +-34 ,-42 ,-50 ,-58 ,-66 ,-74 ,-82 ,-90 +}; + +static s8 rssi_threshold_cck[WRS_MCS_MAX_CCK ] = { +-45 ,-60 ,-75 ,-90 +}; + +static u16 cl_wrs_rssi_find_rate_ht_vht_he (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params, +s8 *rssi_sort, +s8 *thresholds) +{ +s8 max_ss = (s8 )wrs_sta->max_rate_cap.nss; +s8 nss =0 ; +u8 max_bw = wrs_sta->max_rate_cap.bw; +u8 bw =0 ; +u8 max_mcs = wrs_sta->max_rate_cap.mcs; +u8 mcs =0 ; +u8 gi =WRS_GI_LONG ; +u8 selected_mcs =0 ; +u8 selected_nss =0 ; +u8 selected_bw =0 ; +u8 i =0 ; +u16 rate_idx =0 ; +u16 data_rate =0 ; +u16 max_data_rate =0 ; + +if (max_bw > cl_hw->conf->ci_wrs_max_bw) + max_bw = cl_hw->conf->ci_wrs_max_bw; + +for (i =0 ; i <= max_mcs; i++) { + mcs = max_mcs - i; + +for (nss = max_ss; nss >=0 ; nss--) { +if (rssi_sort[nss] <= thresholds[i]) +continue ; + +/* In last level decrease BW */ + bw = ((i == max_mcs) && (max_bw >CHNL_BW_20 )) ? (max_bw -1 ) : max_bw; + +if (wrs_sta->mode ==WRS_MODE_HE ) { + data_rate = data_rate_he_x10[nss][bw][mcs][WRS_GI_LONG ]; + }else { +if (wrs_sta->mode ==WRS_MODE_VHT ) { +/* 160MHz in VHT is valid only for 1/2 SS */ +if (nss >=WRS_SS_3 && bw ==CHNL_BW_160 ) + bw =CHNL_BW_80 ; + +/* BW 80, 3 SS MCS 6 is invalid in VHT */ +if (bw ==CHNL_BW_80 && + nss ==WRS_SS_3 && + mcs ==WRS_MCS_6 ) +continue ; + } + + data_rate = data_rate_ht_vht_x10[bw][nss][mcs][gi]; + } + +if (data_rate > max_data_rate) { + selected_mcs = mcs; + selected_nss = nss; + selected_bw = bw; + max_data_rate = data_rate; + rate_idx =cl_wrs_tables_find_rate_idx (wrs_params, + bw, nss, mcs, gi); + } + +break ; + } + } + +return rate_idx; +} + +static u16 cl_wrs_rssi_find_rate_cck_ofdm (struct cl_wrs_sta *wrs_sta, +s8 *rssi_sort,s8 *thresholds) +{ +struct cl_wrs_params *wrs_params = &wrs_sta->tx_su_params; +u8 max_mcs = wrs_sta->max_rate_cap.mcs; +u8 mcs =0 ; +u8 i =0 ; + +for (i =0 ; i <= max_mcs; i++) { + mcs = max_mcs - i; + +if (rssi_sort[WRS_SS_1 ] > thresholds[i]) +return cl_wrs_tables_find_rate_idx (wrs_params, +CHNL_BW_20 ,WRS_SS_1 , mcs,WRS_GI_LONG ); + } + +return 0 ; +} + +u16 cl_wrs_rssi_find_rate (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params, +s8 *rssi_sort) +{ +u16 rate_idx =0 ; + +if (wrs_params->initial_rate_idx !=WRS_INVALID_RATE ) +return wrs_params->initial_rate_idx; + +switch (wrs_sta->mode) { +case WRS_MODE_HE : + rate_idx =cl_wrs_rssi_find_rate_ht_vht_he (cl_hw, wrs_db, wrs_sta, wrs_params, + rssi_sort, rssi_threshold_he); +break ; +case WRS_MODE_VHT : + rate_idx =cl_wrs_rssi_find_rate_ht_vht_he (cl_hw, wrs_db, wrs_sta, wrs_params, + rssi_sort, rssi_threshold_vht); +break ; +case WRS_MODE_HT : + rate_idx =cl_wrs_rssi_find_rate_ht_vht_he (cl_hw, wrs_db, wrs_sta, wrs_params, + rssi_sort, rssi_threshold_ht); +break ; +case WRS_MODE_OFDM : + rate_idx =cl_wrs_rssi_find_rate_cck_ofdm (wrs_sta, rssi_sort, + rssi_threshold_ofdm); +break ; +case WRS_MODE_CCK : + rate_idx =cl_wrs_rssi_find_rate_cck_ofdm (wrs_sta, rssi_sort, + rssi_threshold_cck); +break ; +default : +break ; + } + +if (rate_idx ==WRS_INVALID_RATE ) + rate_idx =0 ; + +wrs_pr_trace (wrs_db, +"[%s] Select rate based rssi - sta=%u, rssi [%d,%d,%d,%d], " +"rate_idx=%u, bw=%u, nss=%u, mcs=%u\n" , +WRS_TYPE_STR (wrs_params->type), + wrs_sta->sta_idx, + rssi_sort[0 ], + rssi_sort[1 ], + rssi_sort[2 ], + rssi_sort[3 ], + rate_idx, + wrs_params->table[rate_idx].rate.bw, + wrs_params->table[rate_idx].rate.nss, + wrs_params->table[rate_idx].rate.mcs); + +return rate_idx; +} + +/* +* Section #2: +* rssi protect. +*/ +static void cl_wrs_rssi_prot_set_avg (struct cl_wrs_sta *wrs_sta,s8 avg) +{ +struct cl_wrs_rssi_prot_db *rssi_prot_db = &wrs_sta->rssi_prot_db; + +memset (rssi_prot_db->samples_old, avg,WRS_RSSI_PROTECT_BUF_SZ_OLD ); +memset (rssi_prot_db->samples_new, avg,WRS_RSSI_PROTECT_BUF_SZ_NEW ); + rssi_prot_db->sum = avg <<WRS_RSSI_PROTECT_SHIFT ; +} + +static s8 cl_wrs_rssi_prot_add_smpl (struct cl_wrs_sta *wrs_sta,s8 rssi_eq) +{ +struct cl_wrs_rssi_prot_db *rssi_prot_db = &wrs_sta->rssi_prot_db; +u8 curr_idx_old = rssi_prot_db->curr_idx_old; +u8 curr_idx_new = rssi_prot_db->curr_idx_new; + + rssi_prot_db->sum += + rssi_prot_db->samples_new[curr_idx_new] - rssi_prot_db->samples_old[curr_idx_old]; + rssi_prot_db->samples_old[curr_idx_old] = rssi_prot_db->samples_new[curr_idx_new]; + rssi_prot_db->samples_new[curr_idx_new] = rssi_eq; + + rssi_prot_db->curr_idx_old = +WRS_INC_POW2 (rssi_prot_db->curr_idx_old,WRS_RSSI_PROTECT_BUF_SZ_OLD ); +WRS_INC (rssi_prot_db->curr_idx_new,WRS_RSSI_PROTECT_BUF_SZ_NEW ); + +return (s8)(wrs_sta->rssi_prot_db.sum >>WRS_RSSI_PROTECT_SHIFT ); +} + +static bool cl_wrs_rssi_prot_decision_up (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params, +s8 rssi_avg,s8 rssi_eq, +s8 *rssi_sort,u8 up_rate_idx) +{ +/* Decide UP only if all new samples are greater than old average */ +s8 *samples_new = wrs_sta->rssi_prot_db.samples_new; +s8 up_thr = rssi_avg + wrs_db->rssi_protect_up_thr; +u8 i =0 ; + +for (i =0 ; i <WRS_RSSI_PROTECT_BUF_SZ_NEW ; i++) +if (samples_new[i] <= up_thr) +return false; + +if (wrs_db->rssi_protect_mode ==WRS_RSSI_PROT_MODE_RSSI ) { +u16 rate_idx_old = wrs_params->rate_idx; +u16 rate_idx_new =cl_wrs_rssi_find_rate (cl_hw, wrs_db, wrs_sta, + wrs_params, rssi_sort); +struct cl_wrs_rate *rate_old = &wrs_params->table[rate_idx_old].rate; +struct cl_wrs_rate *rate_new = &wrs_params->table[rate_idx_new].rate; +u16 data_rate_old =cl_data_rates_get_x10 (wrs_sta->mode, rate_old->bw, + rate_old->nss, rate_old->mcs, + rate_old->gi); +u16 data_rate_new =cl_data_rates_get_x10 (wrs_sta->mode, rate_new->bw, + rate_new->nss, rate_new->mcs, + rate_new->gi); + +if (rate_idx_old == rate_idx_new || data_rate_old >= data_rate_new) + rate_idx_new = up_rate_idx; + +wrs_pr_info (wrs_db,"[%s] Increase rate based on RSSI - old [%u], new [%u]\n" , +WRS_TYPE_STR (wrs_params->type), rate_idx_old, rate_idx_new); +cl_wrs_decision_update (wrs_db, wrs_sta, wrs_params, +WRS_DECISION_UP_RSSI , rate_idx_new); +cl_wrs_rate_params_update (cl_hw, wrs_db, wrs_sta, + wrs_params, rate_idx_new, true, false); + }else { +cl_wrs_decision_make (cl_hw, wrs_db, wrs_sta, wrs_params, +WRS_DECISION_UP_RSSI , up_rate_idx); + } + +cl_wrs_tables_reset (wrs_db, wrs_sta, wrs_params); +cl_wrs_rssi_prot_set_avg (wrs_sta, rssi_eq); + +return true; +} + +static bool cl_wrs_rssi_prot_decision_down (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params, +s8 rssi_avg,s8 rssi_eq, +s8 *rssi_sort,u8 down_rate_idx) +{ +/* Decide DOWN only if all new samples are smaller than old average */ +s8 *samples_new = wrs_sta->rssi_prot_db.samples_new; +s8 dn_thr = rssi_avg - wrs_db->rssi_protect_dn_thr; +u8 i =0 ; + +if (wrs_params->rate_idx ==0 ) +return false; + +for (i =0 ; i <WRS_RSSI_PROTECT_BUF_SZ_NEW ; i++) +if (samples_new[i] >= dn_thr) +return false; + +if (wrs_db->rssi_protect_mode ==WRS_RSSI_PROT_MODE_RSSI ) { +u16 rate_idx_old = wrs_params->rate_idx; +u16 rate_idx_new =cl_wrs_rssi_find_rate (cl_hw, wrs_db, wrs_sta, + wrs_params, rssi_sort); +struct cl_wrs_rate *rate_old = &wrs_params->table[rate_idx_old].rate; +struct cl_wrs_rate *rate_new = &wrs_params->table[rate_idx_new].rate; +u16 data_rate_old =cl_data_rates_get_x10 (wrs_sta->mode, rate_old->bw, + rate_old->nss, rate_old->mcs, + rate_old->gi); +u16 data_rate_new =cl_data_rates_get_x10 (wrs_sta->mode, rate_new->bw, + rate_new->nss, rate_new->mcs, + rate_new->gi); + +if (rate_idx_old == rate_idx_new || data_rate_old <= data_rate_new) + rate_idx_new = down_rate_idx; + +wrs_pr_info (wrs_db,"[%s] Decrease rate based on RSSI - old [%u], new [%u]\n" , +WRS_TYPE_STR (wrs_params->type), rate_idx_old, rate_idx_new); +cl_wrs_decision_update (wrs_db, wrs_sta, wrs_params, +WRS_DECISION_DOWN_RSSI , rate_idx_new); +cl_wrs_rate_params_update (cl_hw, wrs_db, wrs_sta, wrs_params, + rate_idx_new, true, false); + }else { +cl_wrs_decision_make (cl_hw, wrs_db, wrs_sta, wrs_params, +WRS_DECISION_DOWN_RSSI , down_rate_idx); + } + +cl_wrs_tables_reset (wrs_db, wrs_sta, wrs_params); +cl_wrs_rssi_prot_set_avg (wrs_sta, rssi_eq); + +return true; +} + +void cl_wrs_rssi_prot_start (struct cl_hw *cl_hw,struct cl_sta *cl_sta) +{ +struct cl_wrs_sta *wrs_sta = &cl_sta->wrs_sta; +s8 rssi_sort[MAX_ANTENNAS ] = {0 }; +s8 rssi_eq =0 ; + +if (!cl_hw->wrs_db.rssi_protect_en) +return ; + + rssi_eq =cl_wrs_rssi_eq_calc (cl_hw, wrs_sta, false, rssi_sort); +cl_wrs_rssi_prot_set_avg (wrs_sta, rssi_eq); +} + +bool cl_wrs_rssi_prot_decision (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params, +bool up_rate_valid, +u8 up_rate_idx,u8 down_rate_idx) +{ +s8 rssi_avg =0 ; +s8 rssi_eq =0 ; +s8 rssi_sort[MAX_ANTENNAS ] = {0 }; + + rssi_eq =cl_wrs_rssi_eq_calc (cl_hw, wrs_sta, true, rssi_sort); + rssi_avg =cl_wrs_rssi_prot_add_smpl (wrs_sta, rssi_eq); + +if (up_rate_valid) +if (cl_wrs_rssi_prot_decision_up (cl_hw, wrs_db, wrs_sta, wrs_params, rssi_avg, + rssi_eq, rssi_sort, up_rate_idx)) +return true; + +return cl_wrs_rssi_prot_decision_down (cl_hw, wrs_db, wrs_sta, wrs_params, rssi_avg, + rssi_eq, rssi_sort, down_rate_idx); +} + +static void cl_wrs_sta_info_set_he (struct cl_wrs_sta *wrs_sta) +{ + wrs_sta->mode =WRS_MODE_HE ; + + wrs_sta->gi_cap[CHNL_BW_20 ] =WRS_GI_VSHORT ; + wrs_sta->gi_cap[CHNL_BW_40 ] =WRS_GI_VSHORT ; + wrs_sta->gi_cap[CHNL_BW_80 ] =WRS_GI_VSHORT ; + wrs_sta->gi_cap[CHNL_BW_160 ] =WRS_GI_VSHORT ; +} + +static void cl_wrs_sta_info_set_vht (struct cl_wrs_sta *wrs_sta, +struct ieee80211_sta_vht_cap *vht_cap, +struct ieee80211_sta_ht_cap *ht_cap) +{ + wrs_sta->mode =WRS_MODE_VHT ; + + wrs_sta->gi_cap[CHNL_BW_20 ] = + (ht_cap->cap &IEEE80211_HT_CAP_SGI_20 ) ?WRS_GI_SHORT :WRS_GI_LONG ; + wrs_sta->gi_cap[CHNL_BW_40 ] = + (ht_cap->cap &IEEE80211_HT_CAP_SGI_40 ) ?WRS_GI_SHORT :WRS_GI_LONG ; + wrs_sta->gi_cap[CHNL_BW_80 ] = + (vht_cap->cap &IEEE80211_VHT_CAP_SHORT_GI_80 ) ?WRS_GI_SHORT :WRS_GI_LONG ; + wrs_sta->gi_cap[CHNL_BW_160 ] = + (vht_cap->cap &IEEE80211_VHT_CAP_SHORT_GI_160 ) ?WRS_GI_SHORT :WRS_GI_LONG ; +} + +static void cl_wrs_sta_info_set_ht (struct cl_wrs_sta *wrs_sta, +struct ieee80211_sta_ht_cap *ht_cap) +{ + wrs_sta->mode =WRS_MODE_HT ; + + wrs_sta->gi_cap[CHNL_BW_20 ] = + (ht_cap->cap &IEEE80211_HT_CAP_SGI_20 ) ?WRS_GI_SHORT :WRS_GI_LONG ; + wrs_sta->gi_cap[CHNL_BW_40 ] = + (ht_cap->cap &IEEE80211_HT_CAP_SGI_40 ) ?WRS_GI_SHORT :WRS_GI_LONG ; +} + +static void cl_wrs_sta_info_set_legacy (struct cl_wrs_sta *wrs_sta, +struct ieee80211_sta *sta) +{ +if (sta->supp_rates[NL80211_BAND_5GHZ ] || + (sta->supp_rates[NL80211_BAND_2GHZ ] &0xFF0 )) + wrs_sta->mode =WRS_MODE_OFDM ; +else + wrs_sta->mode =WRS_MODE_CCK ; +} + +static void cl_wrs_sta_info_set (struct cl_hw *cl_hw,struct cl_wrs_sta *wrs_sta, +struct ieee80211_sta *sta) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; +struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; +struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap; +struct ieee80211_sta_he_cap *he_cap = &sta->he_cap; +u8 bw =min_t (u8, sta->bandwidth, wrs_db->max_cap.bw); + +if (he_cap->has_he) +cl_wrs_sta_info_set_he (wrs_sta); +else if (vht_cap->vht_supported && ht_cap->ht_supported) +cl_wrs_sta_info_set_vht (wrs_sta, vht_cap, ht_cap); +else if (ht_cap->ht_supported) +cl_wrs_sta_info_set_ht (wrs_sta, ht_cap); +else +cl_wrs_sta_info_set_legacy (wrs_sta, sta); + + wrs_sta->max_rate_cap.nss =min_t (u8, sta->rx_nss,WRS_SS_MAX ) -1 ; + +if (cl_band_is_24g (cl_hw)) + wrs_sta->max_rate_cap.bw =min (bw, wrs_db->coex_bw); +else + wrs_sta->max_rate_cap.bw = bw; + + wrs_sta->assoc_bw = bw; +} + +#define TWO_BITS_MASK 0x3 + +static u8 cl_wrs_calc_max_nss (u16 rx_mcs,u8 max_nss) +{ +u8 i, nss =0 ; + +for (i =0 ; i <= max_nss; i++) { +if (((rx_mcs >> (2 * i)) &TWO_BITS_MASK ) !=IEEE80211_HE_MCS_NOT_SUPPORTED ) + nss++; +else +break ; + } + +return nss; +} + +static void cl_supported_rates_he_cap (struct cl_wrs_db *wrs_db,struct ieee80211_sta *sta) +{ +struct cl_sta *cl_sta = (struct cl_sta *)sta->drv_priv; +struct cl_wrs_sta *wrs_sta = &cl_sta->wrs_sta; +struct ieee80211_he_mcs_nss_supp *mcs_nss = &sta->he_cap.he_mcs_nss_supp; +int mcs =0 ; +int supported_mcs =0 ; +u16 rx_mcs =0 ; +u8 max_nss = wrs_sta->max_rate_cap.nss; +u8 nss =0 , bw =0 ; +u8 max_nss_80, max_nss_160; + +for (bw =0 ; bw <= wrs_sta->max_rate_cap.bw; bw++) { +if (bw <CHNL_BW_160 ) { + rx_mcs =le16_to_cpu (mcs_nss->rx_mcs_80); + }else if (bw ==CHNL_BW_160 ) { + max_nss_80 =cl_wrs_calc_max_nss (le16_to_cpu (mcs_nss->rx_mcs_80), + max_nss) +1 ; + rx_mcs =le16_to_cpu (mcs_nss->rx_mcs_160); + max_nss_160 =cl_wrs_calc_max_nss (rx_mcs, max_nss) +1 ; + max_nss = max_nss * max_nss_160 / max_nss_80; + }else { +wrs_pr_err (wrs_db,"bw %u is not supported\n" , bw); + } + +for (nss =0 ; nss <= max_nss; nss++) { +switch ((rx_mcs >> (2 * nss)) &TWO_BITS_MASK ) { +case IEEE80211_HE_MCS_SUPPORT_0_7 : + supported_mcs =WRS_MCS_7 ; +break ; +case IEEE80211_HE_MCS_SUPPORT_0_9 : + supported_mcs =WRS_MCS_9 ; +break ; +case IEEE80211_HE_MCS_SUPPORT_0_11 : + supported_mcs =WRS_MCS_11 ; +break ; +case IEEE80211_HE_MCS_NOT_SUPPORTED : + supported_mcs =-1 ; +break ; + } + +for (mcs =0 ; mcs <= supported_mcs; mcs++) +cl_wrs_sta_set_supported_rate (wrs_sta, bw, nss, mcs); + } + } +} + +static void cl_supported_rates_vht_cap (struct ieee80211_sta *sta) +{ +struct cl_sta *cl_sta =IEEE80211_STA_TO_CL_STA (sta); +struct cl_wrs_sta *wrs_sta = &cl_sta->wrs_sta; +u16 mcs_map =le16_to_cpu (sta->vht_cap.vht_mcs.rx_mcs_map); +u8 bw =0 ; +u8 nss =0 ; +int mcs =0 ; +int supported_mcs =0 ; + +for (bw =0 ; bw <= wrs_sta->max_rate_cap.bw; bw++) { +for (nss =0 ; nss <= wrs_sta->max_rate_cap.nss; nss++) { +switch ((mcs_map >> (2 * nss)) &TWO_BITS_MASK ) { +case 0 : + supported_mcs =WRS_MCS_7 ; +break ; +case 1 : + supported_mcs =WRS_MCS_8 ; +break ; +case 2 : + supported_mcs =WRS_MCS_9 ; +break ; +case 3 : + supported_mcs =-1 ; +break ; + } + +for (mcs =0 ; mcs <= supported_mcs; mcs++) +cl_wrs_sta_set_supported_rate (wrs_sta, bw, nss, mcs); + } + } +} + +static void cl_supported_rates_ht_cap (struct ieee80211_sta *sta) +{ +struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; +struct cl_sta *cl_sta =IEEE80211_STA_TO_CL_STA (sta); +struct cl_wrs_sta *wrs_sta = &cl_sta->wrs_sta; +u8 bw =0 ; +u8 nss =0 ; +u8 mcs =0 ; + +for (mcs =0 ; mcs <=WRS_MCS_7 ; mcs++) { +for (nss =0 ; nss <= wrs_sta->max_rate_cap.nss; nss++) { +if ((ht_cap->mcs.rx_mask[nss] & (1 << mcs)) ==0 ) +continue ; + +for (bw =0 ; bw <= wrs_sta->max_rate_cap.bw; bw++) +cl_wrs_sta_set_supported_rate (wrs_sta, bw, nss, mcs); + } + } +} + +static void cl_supported_rates_legacy_cap (struct cl_hw *cl_hw, +struct ieee80211_sta *sta, +u8 max_mcs) +{ +struct cl_sta *cl_sta =IEEE80211_STA_TO_CL_STA (sta); +struct cl_wrs_sta *wrs_sta = &cl_sta->wrs_sta; +u8 mcs =0 ; + +for (mcs =0 ; mcs < max_mcs; mcs++) +if (rate_supported (sta, cl_hw->nl_band, mcs)) +cl_wrs_sta_set_supported_rate (wrs_sta,CHNL_BW_20 ,WRS_SS_1 , mcs); +} + +void cl_wrs_sta_add (struct cl_hw *cl_hw,struct ieee80211_sta *sta) +{ +struct cl_sta *cl_sta =IEEE80211_STA_TO_CL_STA (sta); +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; +struct cl_wrs_sta *wrs_sta = &cl_sta->wrs_sta; +struct cl_wrs_params *wrs_params = &wrs_sta->tx_su_params; + + wrs_params->type =WRS_TYPE_TX_SU ; + wrs_params->is_mu_valid = false; + wrs_params->rate_idx =WRS_INVALID_RATE ; + wrs_params->initial_rate_idx =WRS_INVALID_RATE ; + + wrs_sta->sta_idx = cl_sta->sta_idx; +cl_wrs_rssi_prot_start (cl_hw, cl_sta); +cl_wrs_stats_per_init (wrs_params); +cl_wrs_sta_info_set (cl_hw, wrs_sta, sta); +cl_wrs_sta_capabilities_set (wrs_db, sta); +cl_wrs_tables_build (cl_hw, wrs_sta, wrs_params); +cl_wrs_sta_select_first_rate (cl_hw, wrs_db, wrs_sta, wrs_params); + +wrs_pr_trace (wrs_db,"[%s] Add station %pM to database (sta_idx %u)\n" , +WRS_TYPE_STR (wrs_params->type), cl_sta->addr, cl_sta->sta_idx); +} + +void cl_wrs_sta_add_rx (struct cl_hw *cl_hw,struct ieee80211_sta *sta) +{ +struct cl_sta *cl_sta =IEEE80211_STA_TO_CL_STA (sta); +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; +struct cl_wrs_sta *wrs_sta = &cl_sta->wrs_sta; +struct cl_wrs_params *wrs_params; + +if (wrs_sta->rx_params) { +wrs_pr_warn (wrs_db,"[RX] Params already allocated (sta_idx %u)\n" , + wrs_sta->sta_idx); +return ; + } + + wrs_params =kzalloc (sizeof (*wrs_params),GFP_ATOMIC ); + +if (!wrs_params) +return ; + + wrs_sta->rx_params = wrs_params; + wrs_params->type =WRS_TYPE_RX ; + wrs_params->is_mu_valid = false; + wrs_params->rate_idx =WRS_INVALID_RATE ; + wrs_params->initial_rate_idx =WRS_INVALID_RATE ; + + wrs_sta->sta_idx = cl_sta->sta_idx; + +cl_wrs_rssi_prot_start (cl_hw, cl_sta); +cl_wrs_stats_per_init (wrs_params); +cl_wrs_sta_info_set (cl_hw, wrs_sta, sta); +cl_wrs_sta_capabilities_set (wrs_db, sta); +cl_wrs_tables_build (cl_hw, wrs_sta, wrs_params); +cl_wrs_sta_select_first_rate (cl_hw, wrs_db, wrs_sta, wrs_params); +cl_wrs_rx_rate_idle_reset (wrs_params); + +wrs_pr_trace (wrs_db,"[%s] Add station %pM to database (sta_idx %u)\n" , +WRS_TYPE_STR (wrs_params->type), cl_sta->addr, cl_sta->sta_idx); +} + +static void _cl_wrs_sta_remove (struct cl_wrs_params *wrs_params) +{ +if (wrs_params->is_logger_en) { +kfree (wrs_params->logger); + wrs_params->logger =NULL ; + } + +kfree (wrs_params->table); + wrs_params->table =NULL ; + +cl_wrs_stats_per_remove (wrs_params); +} + +static void cl_wrs_sta_remove_rx (struct cl_wrs_db *wrs_db,struct cl_wrs_sta *wrs_sta) +{ +struct cl_wrs_params *wrs_params = wrs_sta->rx_params; + +if (!wrs_params) { +wrs_pr_warn (wrs_db,"[RX] Params already removed (sta_idx %u)\n" , + wrs_sta->sta_idx); +return ; + } + +_cl_wrs_sta_remove (wrs_params); + +kfree (wrs_params); + wrs_sta->rx_params =NULL ; + +wrs_pr_err (wrs_db,"[RX] Remove params (sta_idx %u)\n" , wrs_sta->sta_idx); +} + +void cl_wrs_sta_remove (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db,struct cl_sta *cl_sta) +{ +struct cl_wrs_sta *wrs_sta = &cl_sta->wrs_sta; + +_cl_wrs_sta_remove (&wrs_sta->tx_su_params); + +if (wrs_sta->rx_params) +cl_wrs_sta_remove_rx (wrs_db, wrs_sta); +wrs_pr_trace (wrs_db,"Remove station %pM from database (sta_idx %u)\n" , + cl_sta->addr, cl_sta->sta_idx); +} + +struct cl_wrs_sta *cl_wrs_sta_get (struct cl_hw *cl_hw,u8 sta_idx) +{ +struct cl_sta *cl_sta =cl_sta_get (cl_hw, sta_idx); + +return cl_sta ? &cl_sta->wrs_sta :NULL ; +} + +void cl_wrs_sta_select_first_rate (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params) +{ +if (wrs_db->is_fixed_rate) { +s8 *fixed_rate = cl_hw->conf->ci_wrs_fixed_rate; + +cl_wrs_fixed_rate_set (cl_hw, wrs_db, wrs_sta, wrs_params, wrs_db->is_fixed_rate, + fixed_rate[WRS_FIXED_PARAM_MODE ], + fixed_rate[WRS_FIXED_PARAM_BW ], + fixed_rate[WRS_FIXED_PARAM_NSS ], + fixed_rate[WRS_FIXED_PARAM_MCS ], + fixed_rate[WRS_FIXED_PARAM_GI ],0 ); + }else { + struct cl_sta *cl_sta = container_of(wrs_sta, struct cl_sta, wrs_sta); +struct cl_wrs_rate_params *vif_fixed_params = &cl_sta->cl_vif->fixed_params; + +if (vif_fixed_params->is_fixed) +cl_wrs_fixed_rate_set (cl_hw, wrs_db, wrs_sta, wrs_params, +WRS_FIXED_FALLBACK_DIS , + vif_fixed_params->mode, + vif_fixed_params->bw, + vif_fixed_params->nss, + vif_fixed_params->mcs, + vif_fixed_params->gi,0 ); + } + +if (!wrs_params->is_fixed_rate) { +bool result =cl_wrs_set_rate_idle (cl_hw, wrs_db, wrs_sta, wrs_params); + +/* +* If new rate wasn't selected according to +* rssi (no samples) or data packets set rate to lowest possible +*/ +if (!result) +cl_wrs_rate_params_update (cl_hw, wrs_db, wrs_sta, + wrs_params,0 , false, false); + } +} + +void cl_wrs_sta_capabilities_set (struct cl_wrs_db *wrs_db,struct ieee80211_sta *sta) +{ +struct cl_sta *cl_sta =IEEE80211_STA_TO_CL_STA (sta); +enum cl_wrs_mode mode = cl_sta->wrs_sta.mode; + +if (mode ==WRS_MODE_HE ) { +cl_supported_rates_he_cap (wrs_db, sta); + }else if (mode ==WRS_MODE_VHT ) { +cl_supported_rates_vht_cap (sta); + }else if (mode ==WRS_MODE_HT ) { +cl_supported_rates_ht_cap (sta); + }else { +struct cl_hw *cl_hw = cl_sta->cl_vif->cl_hw; +u8 max_mcs = (mode ==WRS_MODE_OFDM ) ?WRS_MCS_MAX_OFDM :WRS_MCS_MAX_CCK ; + +cl_supported_rates_legacy_cap (cl_hw, sta, max_mcs); + } +} + +void cl_wrs_sta_set_supported_rate (struct cl_wrs_sta *wrs_sta,u8 bw,u8 nss,u8 mcs) +{ +u8 rate_idx = mcs + (nss *WRS_MCS_MAX ); + + wrs_sta->supported_rates[bw] |=BIT (rate_idx); +} + +static struct cl_wrs_per_stats *cl_wrs_stats_per_entry (struct cl_wrs_params *wrs_params) +{ +struct cl_wrs_per_stats *per_stats =NULL , *per_stats_new =NULL ; +struct cl_wrs_rate_params *rate_params = &wrs_params->rate_params; +struct list_head *list_rates = &wrs_params->list_rates; +u8 bw = rate_params->bw; +u8 nss = rate_params->nss; +u8 mcs = rate_params->mcs; +u8 gi = rate_params->gi; + +list_for_each_entry (per_stats, list_rates, list) { +if (per_stats->bw != bw || + per_stats->nss != nss || + per_stats->mcs != mcs || + per_stats->gi != gi) +continue ; + +/* +* Move the entry to the beginning of the list, so that it +* will be faster to find next time. +*/ + if (per_stats != list_entry(list_rates->next, struct cl_wrs_per_stats, list)) { +list_del (&per_stats->list); +list_add (&per_stats->list, list_rates); + } + +return per_stats; + } + +/* Entry not found - allocate new entry and add to list */ + per_stats_new =kzalloc (sizeof (*per_stats_new),GFP_ATOMIC ); + +if (!per_stats_new) +return NULL ; + + per_stats_new->bw = bw; + per_stats_new->nss = nss; + per_stats_new->mcs = mcs; + per_stats_new->gi = gi; + +list_add (&per_stats_new->list, &wrs_params->list_rates); + +return per_stats_new; +} + +void cl_wrs_stats_per_update (struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params, +struct cl_wrs_cntrs *cntrs) +{ +u16 curr_rate_idx = wrs_params->rate_idx; +struct cl_wrs_table *table_node = &wrs_params->table[curr_rate_idx]; +struct cl_wrs_per_stats *per_stats =cl_wrs_stats_per_entry (wrs_params); + +if (!per_stats) +return ; + + wrs_params->frames_total += cntrs->total; + wrs_params->fail_total += cntrs->fail; + wrs_params->ba_not_rcv_total += cntrs->ba_not_rcv; + wrs_params->epr_acc += cntrs->epr_acc; + + per_stats->frames_total += cntrs->total; + per_stats->frames_failed += cntrs->fail; + per_stats->epr_acc += cntrs->epr_acc; + +if (wrs_params->calc_ba_not_rcv) { + per_stats->frames_total += cntrs->ba_not_rcv; + per_stats->frames_failed += cntrs->ba_not_rcv; + } + + table_node->frames_total = wrs_params->frames_total; + table_node->ba_not_rcv_total = wrs_params->ba_not_rcv_total; + table_node->epr_acc = wrs_params->epr_acc; +} + +void cl_wrs_stats_per_init (struct cl_wrs_params *wrs_params) +{ +INIT_LIST_HEAD (&wrs_params->list_rates); +} + +void cl_wrs_stats_per_remove (struct cl_wrs_params *wrs_params) +{ +struct cl_wrs_per_stats *per_stats =NULL , *per_stats_next =NULL ; + +list_for_each_entry_safe (per_stats, per_stats_next, &wrs_params->list_rates, list) { +list_del (&per_stats->list); +kfree (per_stats); + } +} + +static struct cl_wrs_table + ap_rate_table_he[CHNL_BW_MAX ][WRS_SS_MAX ][WRS_MCS_MAX_HE ][WRS_GI_MAX_HE ]; +static struct cl_wrs_table + ap_rate_table_ht_vht[CHNL_BW_MAX ][WRS_SS_MAX ][WRS_MCS_MAX_VHT ][WRS_GI_MAX_VHT ]; + +/* Rate indexes sorted by data rate */ +static u16 rate_idx_sorted_by_data_rate_he[WRS_HE_RATE_TABLE_SIZE ] = {0 }; +static u16 rate_idx_sorted_by_data_rate_ht_vht[WRS_HT_VHT_RATE_TABLE_SIZE ] = {0 }; + +static void cl_wrs_extract_rate_idx_vht (u16 idx,u8 *bw,u8 *nss,u8 *mcs,u8 *gi) +{ + *gi = idx %WRS_GI_MAX_VHT ; + idx = (idx - *gi) /WRS_GI_MAX_VHT ; + *mcs = idx %WRS_MCS_MAX_VHT ; + idx = (idx - *mcs) /WRS_MCS_MAX_VHT ; + *nss = idx %WRS_SS_MAX ; + *bw = (idx - *nss) /CHNL_BW_MAX ; +} + +static void cl_wrs_extract_rate_idx_he (u16 idx,u8 *bw,u8 *nss,u8 *mcs,u8 *gi) +{ + *gi = idx %WRS_GI_MAX_HE ; + idx = (idx - *gi) /WRS_GI_MAX_HE ; + *mcs = idx %WRS_MCS_MAX_HE ; + idx = (idx - *mcs) /WRS_MCS_MAX_HE ; + *nss = idx %WRS_SS_MAX ; + *bw = (idx - *nss) /CHNL_BW_MAX ; +} + +static void cl_wrs_tables_build_sorted_ht_vht (void ) +{ +/* Sort according to HT/VHT data rate */ +u16 i, j; +u8 bw1, nss1, mcs1, gi1, bw2, nss2, mcs2, gi2; + +for (i =0 ; i <WRS_HT_VHT_RATE_TABLE_SIZE ; i++) + rate_idx_sorted_by_data_rate_ht_vht[i] = i; + +for (i =0 ; i <WRS_HT_VHT_RATE_TABLE_SIZE -1 ; i++) { +for (j =0 ; j <WRS_HT_VHT_RATE_TABLE_SIZE - i -1 ; j++) { +cl_wrs_extract_rate_idx_vht (rate_idx_sorted_by_data_rate_ht_vht[j], + &bw1, &nss1, &mcs1, &gi1); +cl_wrs_extract_rate_idx_vht (rate_idx_sorted_by_data_rate_ht_vht[j +1 ], + &bw2, &nss2, &mcs2, &gi2); + +if (data_rate_ht_vht_x10[bw1][nss1][mcs1][gi1] > + data_rate_ht_vht_x10[bw2][nss2][mcs2][gi2]) +swap (rate_idx_sorted_by_data_rate_ht_vht[j], + rate_idx_sorted_by_data_rate_ht_vht[j +1 ]); + } + } +} + +static void cl_wrs_tables_build_sorted_he (void ) +{ +/* Sort according to HE data rate */ +u16 i, j; +u8 bw1, nss1, mcs1, gi1, bw2, nss2, mcs2, gi2; + +for (i =0 ; i <WRS_HE_RATE_TABLE_SIZE ; i++) + rate_idx_sorted_by_data_rate_he[i] = i; + +for (i =0 ; i <WRS_HE_RATE_TABLE_SIZE -1 ; i++) { +for (j =0 ; j <WRS_HE_RATE_TABLE_SIZE - i -1 ; j++) { +cl_wrs_extract_rate_idx_he (rate_idx_sorted_by_data_rate_he[j], + &bw1, &nss1, &mcs1, &gi1); +cl_wrs_extract_rate_idx_he (rate_idx_sorted_by_data_rate_he[j +1 ], + &bw2, &nss2, &mcs2, &gi2); + +if (data_rate_he_x10[nss1][bw1][mcs1][gi1] > + data_rate_he_x10[nss2][bw2][mcs2][gi2]) +swap (rate_idx_sorted_by_data_rate_he[j], + rate_idx_sorted_by_data_rate_he[j +1 ]); + } + } +} + +static u16 idx_to_offt_ht_vht (u32 bw,u32 nss,u32 mcs,u32 gi) +{ +if (bw <CHNL_BW_MAX && + nss <WRS_SS_MAX && + mcs <WRS_MCS_MAX_VHT && + gi <WRS_GI_MAX_VHT ) +return (gi +WRS_GI_MAX_VHT * (mcs +WRS_MCS_MAX_VHT * (nss + bw *WRS_SS_MAX ))); +else +return -1 ; +} + +static u16 idx_to_offt_he (u32 bw,u32 nss,u32 mcs,u32 gi) +{ +if (bw <CHNL_BW_MAX && + nss <WRS_SS_MAX && + mcs <WRS_MCS_MAX_HE && + gi <WRS_GI_MAX_HE ) +return (gi +WRS_GI_MAX_HE * (mcs +WRS_MCS_MAX_HE * (nss + bw *WRS_SS_MAX ))); +else +return -1 ; +} + +static u16 find_down_rate_idx (u32 bw,u32 nss,u32 mcs,u32 gi,u16 *data_rates, +u16 (*idx_to_offt)(u32 bw,u32 nss,u32 mcs,u32 gi)) +{ +u16 idx; + +if (mcs >0 ) { + idx =idx_to_offt (bw, nss, mcs -1 , gi); +if (data_rates[idx]) +return idx; +if (mcs >1 ) +return idx_to_offt (bw, nss, mcs -2 , gi); + } + +if (bw >0 ) { + idx =idx_to_offt (bw -1 , nss, mcs, gi); +if (data_rates[idx]) +return idx; +if (bw >1 ) +return idx_to_offt (bw -2 , nss, mcs, gi); + } + +if (nss >0 ) { + idx =idx_to_offt (bw, nss -1 , mcs, gi); +if (data_rates[idx]) +return idx; +if (nss >1 ) { + idx =idx_to_offt (bw, nss -2 , mcs, gi); +if (data_rates[idx]) +return idx; + } + } + +if (gi >0 ) +return idx_to_offt (bw, nss, mcs, gi -1 ); + +return 0 ; +} + +static u16 find_up_mcs_rate_idx (u32 bw,u32 nss,u32 mcs,u32 gi,u16 *data_rates, +u16 (*idx_to_offt)(u32 bw,u32 nss,u32 mcs,u32 gi)) +{ +s16 idx =idx_to_offt (bw, nss, mcs +1 , gi); + +if (idx <0 || !data_rates[idx]) + idx =idx_to_offt (bw, nss, mcs +2 , gi); + +return (idx <0 ) ?WRS_INVALID_RATE : idx; +} + +static u16 find_up_bw_rate_idx (u32 bw,u32 nss,u32 mcs,u32 gi, +u16 *data_rates, +u16 (*idx_to_offt)(u32 bw,u32 nss,u32 mcs,u32 gi)) +{ +s16 cur_data_rate = data_rates[idx_to_offt (bw, nss, mcs, gi)]; +s16 min_idx =WRS_INVALID_RATE ; +s16 idx; +s32 min_rate_diff =S32_MAX ; +s32 rate_diff; + +for (idx =idx_to_offt (++bw, nss, mcs, gi); !(idx <0 ); + idx =idx_to_offt (bw, nss, --mcs, gi)) { +/* +* If data_rates[idx] == 0, the difference will be negative, +* so the condition below will not hold. +* Therefore, no need to check this possiblity specifically. +*/ + rate_diff = data_rates[idx] - cur_data_rate; +if (rate_diff >0 && + rate_diff < min_rate_diff && + (data_rates[idx] *100 ) > (cur_data_rate *WRS_EPR_FACTOR )) { + min_rate_diff = rate_diff; + min_idx = idx; + } + } + +return min_idx; +} + +static u16 find_up_nss_rate_idx (u32 bw,u32 nss,u32 mcs,u32 gi, +u16 *data_rates, +u16 (*idx_to_offt)(u32 bw,u32 nss,u32 mcs,u32 gi)) +{ +s16 cur_data_rate = data_rates[idx_to_offt (bw, nss, mcs, gi)]; +s16 min_idx =WRS_INVALID_RATE ; +s16 idx; +s32 min_rate_diff =S32_MAX ; +s32 rate_diff; + +for (idx =idx_to_offt (bw, ++nss, mcs, gi); !(idx <0 ); + idx =idx_to_offt (bw, nss, --mcs, gi)) { +/* +* If data_rates[idx] == 0, the difference will be negative, +* so the condition below will not hold. +* Therefore, no need to check this possiblity specifically. +*/ + rate_diff = data_rates[idx] - cur_data_rate; +if (rate_diff >0 && + rate_diff < min_rate_diff && + (data_rates[idx] *100 ) > (cur_data_rate *WRS_EPR_FACTOR )) { + min_rate_diff = rate_diff; + min_idx = idx; + } + } + +return min_idx; +} + +static u16 find_up_bf_rate_idx (u32 bw,u32 nss,u32 mcs,u32 gi, +u16 *data_rates, +u16 (*idx_to_offt)(u32 bw,u32 nss,u32 mcs,u32 gi)) +{ +s16 cur_data_rate = data_rates[idx_to_offt (bw, nss, mcs, gi)]; +s16 min_idx =WRS_INVALID_RATE ; +s16 idx; +s32 min_rate_diff =S32_MAX ; +s16 rate_diff; + +for (idx =idx_to_offt (bw, --nss, mcs, gi); !(idx <0 ); + idx =idx_to_offt (bw, nss, ++mcs, gi)) { +/* +* If data_rates[idx] == 0, the difference will be negative, +* so the condition below will not hold. +* Therefore, no need to check this possiblity specifically. +*/ + rate_diff = data_rates[idx] - cur_data_rate; +if (rate_diff >0 && + rate_diff < min_rate_diff && + (data_rates[idx] *100 ) > (cur_data_rate *WRS_EPR_FACTOR )) { + min_rate_diff = rate_diff; + min_idx = idx; + } + } + +return min_idx; +} + +static u16 find_up_gi_rate_idx (u32 bw,u32 nss,u32 mcs,u32 gi, +u16 (*idx_to_offt)(u32 bw,u32 nss,u32 mcs,u32 gi)) +{ +s16 idx =idx_to_offt (bw, nss, mcs, gi +1 ); + +return (idx <0 ) ?WRS_INVALID_RATE : idx; +} + +static void _cl_wrs_tables_init (struct cl_wrs_table *ap_rate_table, +u16 *data_rates, +u32 bw,u32 nss,u32 mcs,u32 gi, +u16 (*idx_to_offt)(u32 bw,u32 nss,u32 mcs,u32 gi)) +{ +struct cl_wrs_table *cur_entry =NULL ; +int i =0 ; +u16 offt =idx_to_offt (bw, nss, mcs, gi); + + cur_entry = &ap_rate_table[offt]; + cur_entry->rate.bw = bw; + cur_entry->rate.nss = nss; + cur_entry->rate.mcs = mcs; + cur_entry->rate.gi = gi; + +/* If current rate is invalid, mark it as such and skip it. */ +if (!data_rates[offt]) { + cur_entry->rate_down.rate_idx =WRS_INVALID_RATE ; + cur_entry->rate_down.time_th =WRS_MSEC_WEIGHT_MAX_DOWN ; + +for (i =0 ; i <WRS_TABLE_NODE_UP_MAX ; i++) { + cur_entry->rate_up[i].rate_idx =WRS_INVALID_RATE ; + cur_entry->rate_up[i].time_th =WRS_MSEC_WEIGHT_MAX_UP ; + } + +return ; + } + + cur_entry->rate_down.rate_idx = +find_down_rate_idx (bw, nss, mcs, gi, data_rates, idx_to_offt); + cur_entry->rate_up[WRS_TABLE_NODE_UP_MCS ].rate_idx = +find_up_mcs_rate_idx (bw, nss, mcs, gi, data_rates, idx_to_offt); + cur_entry->rate_up[WRS_TABLE_NODE_UP_BW ].rate_idx = +find_up_bw_rate_idx (bw, nss, mcs, gi, data_rates, idx_to_offt); + cur_entry->rate_up[WRS_TABLE_NODE_UP_NSS ].rate_idx = +find_up_nss_rate_idx (bw, nss, mcs, gi, data_rates, idx_to_offt); + cur_entry->rate_up[WRS_TABLE_NODE_UP_BF ].rate_idx = +find_up_bf_rate_idx (bw, nss, mcs, gi, data_rates, idx_to_offt); + cur_entry->rate_up[WRS_TABLE_NODE_UP_GI ].rate_idx = +find_up_gi_rate_idx (bw, nss, mcs, gi, idx_to_offt); + + cur_entry->rate_down.time_th =WRS_INIT_MSEC_WEIGHT_DOWN ; + +for (i =0 ; i <WRS_TABLE_NODE_UP_MAX ; i++) + cur_entry->rate_up[i].time_th = + (cur_entry->rate_up[i].rate_idx ==WRS_INVALID_RATE ) ? +WRS_MSEC_WEIGHT_MAX_UP :WRS_INIT_MSEC_WEIGHT_UP ; +} + +static void cl_wrs_tables_init (u8 mode) +{ +u32 bw, nss, mcs, gi; +u32 max_bw, max_nss, max_mcs, max_gi; +u16 (*idx_to_offt)(u32 bw,u32 nss,u32 mcs,u32 gi); +struct cl_wrs_table *ap_rate_table =NULL ; +u16 *data_rates =NULL ; + +if (mode ==WRS_MODE_HE ) { + idx_to_offt = idx_to_offt_he; + max_bw =CHNL_BW_MAX ; + max_nss =WRS_SS_MAX ; + max_mcs =WRS_MCS_MAX_HE ; + max_gi =WRS_GI_MAX_HE ; + ap_rate_table = (struct cl_wrs_table *)ap_rate_table_he; + data_rates = (u16 *)data_rate_he_x10; + }else if (mode ==WRS_MODE_VHT ) { + idx_to_offt = idx_to_offt_ht_vht; + max_bw =CHNL_BW_MAX ; + max_nss =WRS_SS_MAX ; + max_mcs =WRS_MCS_MAX_VHT ; + max_gi =WRS_GI_MAX_VHT ; + ap_rate_table = (struct cl_wrs_table *)ap_rate_table_ht_vht; + data_rates = (u16 *)data_rate_ht_vht_x10; + }else { +return ; + } + +for (bw =0 ; bw < max_bw; bw++) +for (nss =0 ; nss < max_nss; nss++) +for (mcs =0 ; mcs < max_mcs; mcs++) +for (gi =0 ; gi < max_gi; gi++) +_cl_wrs_tables_init (ap_rate_table, + data_rates, + bw, + nss, + mcs, + gi, + idx_to_offt); +} + +void cl_wrs_tables_global_build (void ) +{ +cl_wrs_tables_init (WRS_MODE_HE ); +cl_wrs_tables_init (WRS_MODE_VHT ); +cl_wrs_tables_build_sorted_he (); +cl_wrs_tables_build_sorted_ht_vht (); +} + +void cl_wrs_tables_reset (struct cl_wrs_db *wrs_db,struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params) +{ +struct cl_wrs_table_node *rate_up; +u16 rate_idx =0 ; +u8 up_idx =0 ; + +for (rate_idx =0 ; rate_idx < wrs_params->table_size; rate_idx++) { +if (wrs_params->table[rate_idx].rate_down.rate_idx !=WRS_INVALID_RATE ) + wrs_params->table[rate_idx].rate_down.time_th =WRS_INIT_MSEC_WEIGHT_DOWN ; +else + wrs_params->table[rate_idx].rate_down.time_th = wrs_db->time_th_max_down; + + wrs_params->table[rate_idx].rate_down.quick_up_check = false; + +for (up_idx =0 ; up_idx <WRS_TABLE_NODE_UP_MAX ; up_idx++) { + rate_up = &wrs_params->table[rate_idx].rate_up[up_idx]; + +if (rate_up->rate_idx !=WRS_INVALID_RATE ) + rate_up->time_th =WRS_INIT_MSEC_WEIGHT_UP ; +else + rate_up->time_th = wrs_db->time_th_max_up; + + rate_up->quick_up_check = false; + } + + wrs_params->table[rate_idx].frames_total =0 ; + wrs_params->table[rate_idx].ba_not_rcv_total =0 ; + wrs_params->table[rate_idx].epr_acc =0 ; + } +} + +static bool cl_wrs_is_rate_valid_he (struct cl_hw *cl_hw,struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params,u8 bw, +u8 nss,u8 mcs,u8 gi) +{ +/* Disable rates according to ce_he_mcs_nss_supp_tx */ +if ((cl_hw->conf->ce_he_mcs_nss_supp_tx[nss] +1 ) <= mcs) +return false; + +/* TB flow doesn't support 0.8us GI */ +if (WRS_TYPE_IS_RX (wrs_params) && gi ==WRS_GI_VSHORT ) +return false; + +if (data_rate_he_x10[nss][bw][mcs][gi] < (10 * wrs_sta->he_minrate)) +return false; + +return true; +} + +static bool cl_wrs_is_rate_valid_vht (struct cl_hw *cl_hw,u8 bw,u8 nss,u8 mcs) +{ +/* Disable BW160 */ +if (bw ==CHNL_BW_160 ) +return false; + +/* Disable VHT invalid rates (MCS9 20M 1SS, MCS9 20M 2SS, MCS6 80M 3SS, MCS9 20M 4SS) */ +if (bw ==CHNL_BW_20 && mcs ==WRS_MCS_9 ) +if (nss ==WRS_SS_1 || nss ==WRS_SS_2 || nss ==WRS_SS_4 ) +return false; + +if (bw ==CHNL_BW_80 && mcs ==WRS_MCS_6 && nss ==WRS_SS_3 ) +return false; + +/* Disable rates according to ce_vht_mcs_nss_supp_tx */ +if ((cl_hw->conf->ce_vht_mcs_nss_supp_tx[nss] +1 ) <= mcs) +return false; + +return true; +} + +static bool cl_wrs_is_rate_valid (struct cl_hw *cl_hw,struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params, +u8 mode,u8 bw,u8 nss,u8 mcs,u8 gi) +{ +struct cl_wrs_db *wrs_db = &cl_hw->wrs_db; + +if (gi > wrs_db->max_cap.gi || gi > wrs_sta->gi_cap[bw]) +return false; + +if (mode ==WRS_MODE_HE ) +return cl_wrs_is_rate_valid_he (cl_hw, wrs_sta, wrs_params, bw, nss, mcs, gi); + +if (mode ==WRS_MODE_VHT ) +return cl_wrs_is_rate_valid_vht (cl_hw, bw, nss, mcs); + +return true; +} + +static bool cl_wrs_is_rate_supported (u64 *rate_bitmap,u8 bw,u8 nss,u8 mcs) +{ +u8 rate_idx = mcs + (nss *WRS_MCS_MAX ); +u64 mask =BIT (rate_idx); + +return rate_bitmap[bw] & mask; +}
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.36.1
Part of the diff is not shown here. View the raw message.
RFC v2 95/96 cl8k: add wrs.h
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/celeno/cl8k/wrs.h | 565 +++++++++++++++++++++++++ 1 file changed, 565 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/wrs.h
drivers/net/wireless/celeno/cl8k/wrs.h new file +565 -0
@@ -0,0 +1,565 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_WRS_H +#define CL_WRS_H + +#include <net/mac80211.h> + +#include "def.h" +#include "debug.h" +#include "rx.h" + +/** +* WRS (=Weighted Rate Selection) +*/ + +struct cl_hw ; +struct cl_sta ; +struct cl_vif ; + +/* Rate Table Size */ +#define WRS_HE_RATE_TABLE_SIZE (WRS_MCS_MAX_HE * WRS_SS_MAX * CHNL_BW_MAX * WRS_GI_MAX_HE) +#define WRS_HT_VHT_RATE_TABLE_SIZE (WRS_MCS_MAX_VHT * WRS_SS_MAX * CHNL_BW_MAX * WRS_GI_MAX_VHT) + +/* Initial Thresholds */ +#define WRS_INIT_MSEC_WEIGHT_DOWN (WRS_MAINTENANCE_PERIOD_MS * 3)/* Msec */ +#define WRS_INIT_MSEC_WEIGHT_UP (WRS_MAINTENANCE_PERIOD_MS * 3)/* Msec */ + +#define WRS_MSEC_WEIGHT_MIN (WRS_MAINTENANCE_PERIOD_MS * 2)/* Msec */ +#define WRS_MSEC_WEIGHT_MAX_UP 30000/* Msec */ +#define WRS_MSEC_WEIGHT_MAX_DOWN 4000/* Msec */ +#define WRS_MSEC_STEP_DOWN 5000/* Msec */ +#define WRS_MSEC_STEP_UP_SAME 1000/* Msec */ +#define WRS_INVALID_RATE ((u16)(~0)) + +enum cl_wrs_table_node_up { +WRS_TABLE_NODE_UP_MCS , +WRS_TABLE_NODE_UP_BW , +WRS_TABLE_NODE_UP_NSS , +WRS_TABLE_NODE_UP_BF , +WRS_TABLE_NODE_UP_GI , + +WRS_TABLE_NODE_UP_MAX +}; + +struct cl_wrs_table_validity { +bool is_valid; +u16 new_rate_idx; +}; + +struct cl_wrs_table_node { +u16 rate_idx; +u16 time_th; +bool quick_up_check; +}; + +struct cl_wrs_rate { +u16 mcs :4 , + nss :3 , + bw :2 , + gi :2 , + rsv :2 ; +}; + +struct cl_wrs_table { +struct cl_wrs_rate rate; +struct cl_wrs_table_node rate_down; +struct cl_wrs_table_node rate_up[WRS_TABLE_NODE_UP_MAX ]; +u32 frames_total; +u32 ba_not_rcv_total; +u64 epr_acc; +}; + +#define WRS_MAINTENANCE_PERIOD_MS 40 +#define WRS_DATA_RATE_FACTOR 10 +#define WRS_RSSI_PROTECT_UP_THR 10 +#define WRS_RSSI_PROTECT_DN_THR 10 +#define WRS_MIN_FRAMES_FOR_DECISION 15 +#define WRS_EPR_FACTOR 105 +#define WRS_CONVERGE_IDLE_PACKET_TH 5 +#define WRS_CONVERGE_IDLE_INTERVAL_RESET 6000/* 6 sec */ +#define WRS_CONVERGE_IDLE_INTERVAL_RSSI 2000/* 2 sec */ +#define WRS_CONVERGE_TRFC_INTERVAL_STATIC 30000/* 30 sec */ +#define WRS_CONVERGE_TRFC_INTERVAL_MOTION 1000/* 1 sec */ +#define WRS_IMMEDIATE_DROP_EPR_FACTOR 70/* 70% */ +#define WRS_IMMEDIATE_DROP_MAX_IN_ROW U32_MAX +#define WRS_SYNC_MIN_ATTEMPTS 4 +#define WRS_SYNC_TIMEOUT 1000/* 1 sec */ +#define WRS_QUICK_UP_BA_THR 5 +#define WRS_QUICK_UP_INTERVAL_MS 1000 +#define WRS_QUICK_DOWN_EPR_FACTOR 85 +#define WRS_QUICK_DOWN_AGG_THR 3 +#define WRS_QUICK_DOWN_PKT_THR 60 +#define WRS_RSSI_PROTECT_SHIFT 7 +#define WRS_RSSI_PROTECT_BUF_SZ_OLD BIT(WRS_RSSI_PROTECT_SHIFT)/* 2 ^ 7 = 128 */ +#define WRS_RSSI_PROTECT_BUF_SZ_NEW 3 +#define WRS_BA_NOT_RCV_TIME_SINCE_SYNC 1000 +#define WRS_CCA_PERIOD_MS 1000 +#define WRS_CCA_PRIMARY_SHIFT 7 +#define WRS_CCA_PRIMARY_FACTOR 160/* 160 / 2^7 = 1.25 = 25% */ + +enum cl_wrs_rssi_prot_mode { +WRS_RSSI_PROT_MODE_RSSI ,/* Up/down based on rssi */ +WRS_RSSI_PROT_MODE_NEIGHBOR ,/* Up/down based on neighbors */ + +WRS_RSSI_PROTECT_MODE_MAX +}; + +enum cl_wrs_fixed_rate { +WRS_AUTO_RATE , +WRS_FIXED_FALLBACK_EN , +WRS_FIXED_FALLBACK_DIS , + +WRS_FIXED_RATE_MAX +}; + +enum cl_wrs_fixed_param { +WRS_FIXED_PARAM_MODE , +WRS_FIXED_PARAM_BW , +WRS_FIXED_PARAM_NSS , +WRS_FIXED_PARAM_MCS , +WRS_FIXED_PARAM_GI , + +WRS_FIXED_PARAM_MAX +}; + +#define FIXED_RATE_STR (x) \ + (((x) == WRS_AUTO_RATE) ? "auto rate" : \ + (((x) == WRS_FIXED_FALLBACK_EN) ? "fixed rate (fallbacks enabled)" : \ + "fixed rate (fallbacks disabled)")) + +enum cl_wrs_decision { +WRS_DECISION_NONE , +WRS_DECISION_SAME , +WRS_DECISION_UP , +WRS_DECISION_UP_QUICK , +WRS_DECISION_UP_RSSI , +WRS_DECISION_UP_MCS1 , +WRS_DECISION_DOWN , +WRS_DECISION_DOWN_RSSI , +WRS_DECISION_DOWN_IMMEDIATE , +WRS_DECISION_DOWN_QUICK , +WRS_DECISION_DOWN_NO_SYNC , +WRS_DECISION_RSSI_MGMT , +WRS_DECISION_RX_RATE , + +WRS_DECISION_MAX , +}; + +enum cl_wrs_mcs { +WRS_MCS_0 , +WRS_MCS_1 , +WRS_MCS_2 , +WRS_MCS_3 , +WRS_MCS_4 , +WRS_MCS_5 , +WRS_MCS_6 , +WRS_MCS_7 , +WRS_MCS_8 , +WRS_MCS_9 , +WRS_MCS_10 , +WRS_MCS_11 , +WRS_MCS_MAX , +}; + +#define WRS_MCS_MAX_CCK WRS_MCS_4 +#define WRS_MCS_MAX_OFDM WRS_MCS_8 +#define WRS_MCS_MAX_HT WRS_MCS_8 +#define WRS_MCS_MAX_VHT WRS_MCS_10 +#define WRS_MCS_MAX_HE WRS_MCS_MAX + +enum cl_wrs_ss { +WRS_SS_1 , +WRS_SS_2 , +WRS_SS_3 , +WRS_SS_4 , + +WRS_SS_MAX +}; + +enum cl_wrs_gi { +WRS_GI_LONG , +WRS_GI_SHORT , +WRS_GI_VSHORT , + +WRS_GI_MAX +}; + +#define WRS_GI_MAX_HT WRS_GI_VSHORT +#define WRS_GI_MAX_VHT WRS_GI_VSHORT +#define WRS_GI_MAX_HE WRS_GI_MAX + +enum cl_wrs_ltf { +LTF_X1 , +LTF_X2 , +LTF_X4 , +LTF_MAX +}; + +enum cl_wrs_converge_mode { +WRS_CONVERGE_MODE_RESET , +WRS_CONVERGE_MODE_RSSI , + +WRS_CONVERGE_MODE_MAX , +}; + +enum cl_wrs_mode { +WRS_MODE_CCK , +WRS_MODE_OFDM , +WRS_MODE_HT , +WRS_MODE_VHT , +WRS_MODE_HE , + +WRS_MODE_MAX , +}; + +enum cl_wrs_type { +WRS_TYPE_TX_SU , +WRS_TYPE_TX_MU_MIMO , +WRS_TYPE_RX , + +WRS_TYPE_MAX , +}; + +#define WRS_TYPE_STR (type) \ + ((type) == WRS_TYPE_TX_SU ? "TX_SU" : \ + ((type) == WRS_TYPE_RX ? "RX" : \ + ((type) == WRS_TYPE_TX_MU_MIMO ? "TX_MU-MIMO" : ""))) + +#define WRS_TYPE_IS_TX_SU (wrs_params) ((wrs_params)->type == WRS_TYPE_TX_SU) +#define WRS_TYPE_IS_TX_MU_MIMO (wrs_params) ((wrs_params)->type == WRS_TYPE_TX_MU_MIMO) +#define WRS_TYPE_IS_RX (wrs_params) ((wrs_params)->type == WRS_TYPE_RX) + +/* m MUST be power of 2 ! */ +#define WRS_INC_POW2 (c, m) (((c) + 1) & ((m) - 1)) + +#define WRS_INC (c, m) \ + do { \ + (c)++; \ + if ((c) == (m)) \ + (c) = 0; \ + } while (0) + +#define WRS_IS_DECISION_UP (decision) \ + (((decision) >= WRS_DECISION_UP) && ((decision) <= WRS_DECISION_UP_MCS1)) +#define WRS_IS_DECISION_DOWN (decision) \ + (((decision) >= WRS_DECISION_DOWN) && ((decision) <= WRS_DECISION_DOWN_NO_SYNC)) + +#define WRS_DECISION_STR (decision) ( \ + (decision) == WRS_DECISION_NONE ? "NONE" : \ + (decision) == WRS_DECISION_SAME ? "SAME" : \ + (decision) == WRS_DECISION_UP ? "UP" : \ + (decision) == WRS_DECISION_UP_QUICK ? "UP QUICK" : \ + (decision) == WRS_DECISION_UP_RSSI ? "UP RSSI" : \ + (decision) == WRS_DECISION_UP_MCS1 ? "UP MCS1" : \ + (decision) == WRS_DECISION_DOWN ? "DOWN" : \ + (decision) == WRS_DECISION_DOWN_RSSI ? "DOWN RSSI" : \ + (decision) == WRS_DECISION_DOWN_IMMEDIATE ? "DOWN IMMEDIATE" : \ + (decision) == WRS_DECISION_DOWN_QUICK ? "DOWN QUICK" : \ + (decision) == WRS_DECISION_DOWN_NO_SYNC ? "DOWN NO_SYNC" : \ + (decision) == WRS_DECISION_RSSI_MGMT ? "RSSI MGMT" : \ + (decision) == WRS_DECISION_RX_RATE ? "RX_RATE" : \ + "ERROR") + +struct cl_wrs_cntrs { +u64 epr_acc; +u32 total; +u32 fail; +u32 ba_not_rcv; +u32 ba_not_rcv_consecutive; +}; + +struct cl_wrs_rate_params { +u16 mode :3 ,/* Mode - 0 = CCK, 1 = OFDM, 2 = HT, 3 = VHT, 4 = HE. */ + gi :2 ,/* GI - O = Long, 1 = Short, 2 = Very short. */ + bw :2 ,/* Bandwidth - 0 = 20M, 1 = 40M, 2 = 80M, 3 = 160M. */ + nss :3 ,/* Spatial Streams - 0 = 1SS, 1 = 2SS, .. 7 = 8SS. */ + mcs :4 ,/* MCS - CCK (0 - 3), OFDM/HT (0 - 7), VHT (0 - 9), HE (0 - 11). */ + fallback_en :1 , + is_fixed :1 ; +}; + +struct cl_wrs_logger { +unsigned long timestamp; +u16 rate_idx; +u32 success; +u32 fail; +u32 ba_not_rcv; +u16 down_rate_idx; +u16 up_rate_idx; +u16 curr_epr; +u16 down_epr; +u16 down_epr_factorized; +u16 penalty; +u16 up_time; +enum cl_wrs_decision decision; +u16 new_rate_idx; +}; + +struct cl_wrs_per_stats { +struct list_head list; +u8 mcs; +u8 bw; +u8 nss; +u8 gi; +u32 frames_total; +u32 frames_failed; +u64 epr_acc; +}; + +struct cl_wrs_rssi_prot_db { +s8 samples_old[WRS_RSSI_PROTECT_BUF_SZ_OLD ]; +s8 samples_new[WRS_RSSI_PROTECT_BUF_SZ_NEW ]; +u8 curr_idx_old; +u8 curr_idx_new; +s32 sum; +}; + +struct cl_wrs_params { +u8 group_id; +u8 is_mu_valid :1 , + is_fixed_rate :2 , + is_logger_en :1 , + quick_up_check :1 , + type :2 , + rsv :1 ; +u32 up_same_time_cnt; +u32 down_time_cnt; +enum cl_wrs_converge_mode converge_mode; +u32 converge_time_idle; +u32 converge_time_trfc; +u16 data_rate; +u16 rate_idx; +u16 initial_rate_idx; +struct cl_wrs_table *table; +u16 table_size; +u16 penalty_decision_dn; +struct cl_wrs_rate_params rate_params; +struct cl_wrs_rate rx_rate_idle; +enum cl_wrs_decision last_decision; +u32 decision_cnt[WRS_DECISION_MAX ]; +struct list_head list_rates; +u32 frames_total; +u32 fail_total; +u32 ba_not_rcv_total; +u64 epr_acc; +bool calc_ba_not_rcv; +bool sync; +unsigned long sync_timestamp; +unsigned long no_sync_timestamp; +struct cl_wrs_logger *logger; +u16 logger_idx; +u16 logger_size; +u32 immediate_drop_cntr; +u32 immediate_drop_ignore; +}; + +struct cl_wrs_sta { +u8 sta_idx; +bool smps_enable; +u8 assoc_bw; +u8 he_minrate; +u8 gi_cap[CHNL_BW_MAX ]; +u64 supported_rates[CHNL_BW_MAX ]; +enum cl_wrs_mode mode; +struct cl_wrs_rate max_rate_cap; +struct cl_wrs_rssi_prot_db rssi_prot_db; +struct cl_wrs_params tx_su_params; +struct cl_wrs_params *rx_params; +}; + +struct cl_wrs_db { +/* General */ +spinlock_t lock; +enum cl_dbg_level debug_level; +/* Timer */ +struct timer_list timer_maintenance; +u32 interval; +/* Fixed rate */ +u8 is_fixed_rate; +/* Conservative initial rate */ +bool conservative_mcs_noisy_env; +bool conservative_nss_noisy_env; +/* Immediate drop */ +bool immediate_drop_en; +u8 immediate_drop_epr_factor; +u32 immediate_drop_max_in_row; +/* Converge idle */ +bool converge_idle_en; +u32 converge_idle_interval_reset; +u32 converge_idle_interval_rssi; +u32 converge_idle_packet_th; +/* Converge traffic */ +bool converge_trfc_en; +u32 converge_trfc_interval_static; +u32 converge_trfc_interval_motion; +/* Supported rates */ +u8 mode; +u64 ap_supported_rates[CHNL_BW_MAX ];/* Bit array for each bw */ +struct cl_wrs_rate max_cap; +u8 coex_bw; +/* RSSI protect */ +bool rssi_protect_en; +u8 rssi_protect_mode; +s8 rssi_protect_up_thr; +s8 rssi_protect_dn_thr; +/* Time + step thresholds */ +u16 time_th_min; +u16 time_th_max_up; +u16 time_th_max_down; +u16 step_down; +u16 step_up_same; +/* Quick up */ +bool quick_up_en; +u8 quick_up_ba_thr; +u16 quick_up_interval; +/* Quick down */ +bool quick_down_en; +u8 quick_down_epr_factor; +u8 quick_down_agg_thr; +u16 quick_down_pkt_thr; +/* BA not received */ +bool ba_not_rcv_collision_filter; +bool ba_not_rcv_force; +u32 ba_not_rcv_time_since_sync; +/* Sync */ +u16 sync_timeout; +u8 sync_min_attempts; +/* CCA counters */ +unsigned long cca_timestamp; +u32 cca_primary; +u32 cca_sec80; +u32 cca_sec40; +u32 cca_sec20; +bool adjacent_interference20; +bool adjacent_interference40; +bool adjacent_interference80; +/* All the rest */ +u32 min_frames_for_decision; +u8 epr_factor; +}; + +struct cl_wrs_info { +u64 epr_acc; +u32 success; +u32 fail; +u32 fail_prev; +u32 ba_not_rcv; +u8 ba_not_rcv_consecutive; +u8 ba_not_rcv_consecutive_max; +bool synced; +u32 sync_attempts; +u8 quick_rate_agg_cntr; +u16 quick_rate_pkt_cntr; +bool quick_rate_check; +}; + +struct cl_wrs_rssi { +s32 sum[MAX_ANTENNAS ]; +s32 cnt; +}; + +bool cl_wrs_rssi_set_rate (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta); +void cl_wrs_rssi_prot_start (struct cl_hw *cl_hw,struct cl_sta *cl_sta); +bool cl_wrs_rssi_prot_decision (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params, +bool up_rate_valid, +u8 up_rate_idx,u8 down_rate_idx); +u16 cl_wrs_rssi_find_rate (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params, +s8 *rssi_sort); +void cl_wrs_sta_add (struct cl_hw *cl_hw,struct ieee80211_sta *sta); +bool cl_wrs_sta_add_mu (struct cl_hw *cl_hw,struct cl_wrs_sta *wrs_sta,u8 group_id); +void cl_wrs_sta_add_rx (struct cl_hw *cl_hw,struct ieee80211_sta *sta); +void cl_wrs_sta_remove (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db,struct cl_sta *cl_sta); +bool cl_wrs_sta_remove_mu (struct cl_wrs_db *wrs_db,struct cl_wrs_sta *wrs_sta); +struct cl_wrs_sta *cl_wrs_sta_get (struct cl_hw *cl_hw,u8 sta_idx); +void cl_wrs_sta_select_first_rate (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params); +void cl_wrs_sta_capabilities_set (struct cl_wrs_db *wrs_db,struct ieee80211_sta *sta); +void cl_wrs_sta_set_supported_rate (struct cl_wrs_sta *wrs_sta,u8 bw,u8 nss,u8 mcs); +void cl_wrs_stats_per_update (struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params, +struct cl_wrs_cntrs *cntrs); +void cl_wrs_stats_per_init (struct cl_wrs_params *wrs_params); +void cl_wrs_stats_per_remove (struct cl_wrs_params *wrs_params); +void cl_wrs_tables_global_build (void ); +void cl_wrs_tables_reset (struct cl_wrs_db *wrs_db,struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params); +void cl_wrs_tables_build (struct cl_hw *cl_hw,struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params); +u16 cl_wrs_tables_find_rate_idx (struct cl_wrs_params *wrs_params, +u8 bw,u8 nss,u8 mcs,u8 gi); +void cl_wrs_init (struct cl_hw *cl_hw); +void cl_wrs_lock_bh (struct cl_wrs_db *wrs_db); +void cl_wrs_unlock_bh (struct cl_wrs_db *wrs_db); +void cl_wrs_lock (struct cl_wrs_db *wrs_db); +void cl_wrs_unlock (struct cl_wrs_db *wrs_db); +void cl_wrs_fixed_rate_set (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params, +u8 is_fixed_rate,u8 mode,u8 bw,u8 nss,u8 mcs,u8 gi,bool mu_valid); +void cl_wrs_rate_param_sync (struct cl_wrs_db *wrs_db,struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params); +void cl_wrs_rate_params_update (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params, +u16 new_rate_idx,bool is_sync_required,bool mu_valid); +void cl_wrs_decision_make (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params, +enum cl_wrs_decision decision,u16 new_rate_idx); +void cl_wrs_decision_update (struct cl_wrs_db *wrs_db,struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params,enum cl_wrs_decision decision, +u16 new_rate_idx); +void cl_wrs_quick_down_check (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params); +bool cl_wrs_up_mcs1 (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params); +void cl_wrs_rate_param_set (struct cl_hw *cl_hw,struct cl_wrs_sta *wrs_sta, +struct cl_wrs_params *wrs_params, +struct cl_wrs_rate_params *rate_params, +struct cl_wrs_rate *rate_fallback, +bool mu_mimo_valid,bool set_su); +s8 cl_wrs_rssi_eq_calc (struct cl_hw *cl_hw,struct cl_wrs_sta *wrs_sta, +bool read_clear,s8 *sorted_rssi); +void cl_wrs_cntrs_reset (struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params); +struct cl_wrs_info *cl_wrs_info_get (struct cl_sta *cl_sta,u8 type); +struct cl_wrs_params *cl_wrs_params_get (struct cl_wrs_sta *wrs_sta,u8 type); +void cl_wrs_update_rx_rate (struct cl_hw *cl_hw,struct cl_sta *cl_sta,struct hw_rxhdr *rxhdr); +bool cl_wrs_set_rate_idle (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db, +struct cl_wrs_sta *wrs_sta,struct cl_wrs_params *wrs_params); +struct cl_wrs_rate_params *cl_wrs_rx_rate_get (struct cl_sta *cl_sta); +void cl_wrs_rx_rate_idle_reset (struct cl_wrs_params *rx_params); +void cl_wrs_ap_capab_set (struct cl_hw *cl_hw,u8 bw,u8 use_sgi); +void cl_wrs_ap_capab_modify_bw (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db,u8 max_bw); +void cl_wrs_ap_capab_modify_gi (struct cl_hw *cl_hw,struct cl_wrs_db *wrs_db,u8 use_sgi); +void cl_wrs_ap_capab_update (struct cl_hw *cl_hw,u8 bw,u8 use_sgi); + +/* Driver --> WRS */ +void cl_wrs_api_init (struct cl_hw *cl_hw); +void cl_wrs_api_close (struct cl_hw *cl_hw); +void cl_wrs_api_sta_add (struct cl_hw *cl_hw,struct ieee80211_sta *sta); +void cl_wrs_api_sta_remove (struct cl_hw *cl_hw,struct cl_sta *cl_sta); +void cl_wrs_api_bss_set_bw (struct cl_hw *cl_hw,u8 bw); +void cl_wrs_api_bss_set_sgi (struct cl_hw *cl_hw,u8 use_sgi); +bool cl_wrs_api_bss_is_sgi_en (struct cl_hw *cl_hw); +void cl_wrs_api_nss_or_bw_changed (struct cl_hw *cl_hw,struct ieee80211_sta *sta,u8 nss,u8 bw); +void cl_wrs_api_he_minrate_changed (struct cl_sta *cl_sta,u8 he_minrate); +void cl_wrs_api_recovery (struct cl_hw *cl_hw); +void cl_wrs_api_beamforming_sync (struct cl_hw *cl_hw,struct cl_sta *cl_sta); +void cl_wrs_api_quick_down_check (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_wrs_params *wrs_params); +void cl_wrs_api_rate_sync (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_wrs_params *wrs_params); +bool cl_wrs_api_up_mcs1 (struct cl_hw *cl_hw,struct cl_sta *cl_sta, +struct cl_wrs_params *wrs_params); +void cl_wrs_api_set_smps_mode (struct cl_hw *cl_hw,struct ieee80211_sta *sta,const u8 bw); +u16 cl_wrs_api_get_tx_sta_data_rate (struct cl_sta *cl_sta); +void cl_wrs_api_bss_capab_update (struct cl_hw *cl_hw,u8 bw,u8 use_sgi); +void cl_wrs_fill_sinfo_rates (struct rate_info *rate_info, +const struct cl_wrs_params *wrs_params, +const struct cl_sta *sta); + +#endif /* CL_WRS_H */
Signature · 1 line
2.36.1
RFC v2 96/96 wireless: add Celeno vendor
In reply to [email protected]From: Viktor Barna <[email protected]>
(Part of the split. Please, take a look at the cover letter for more details).
--- drivers/net/wireless/Kconfig | 1 + drivers/net/wireless/Makefile | 1 + 2 files changed, 2 insertions(+)
drivers/net/wireless/Kconfig +1 -0
@@ -35,6 +35,7 @@ source "drivers/net/wireless/st/Kconfig" source "drivers/net/wireless/ti/Kconfig" source "drivers/net/wireless/zydas/Kconfig" source "drivers/net/wireless/quantenna/Kconfig" +source "drivers/net/wireless/celeno/Kconfig" config PCMCIA_RAYCS tristate "Aviator/Raytheon 2.4GHz wireless support"
drivers/net/wireless/Makefile +1 -0
@@ -20,6 +20,7 @@ obj-$(CONFIG_WLAN_VENDOR_ST) += st/ obj-$(CONFIG_WLAN_VENDOR_TI) += ti/ obj-$(CONFIG_WLAN_VENDOR_ZYDAS) += zydas/ obj-$(CONFIG_WLAN_VENDOR_QUANTENNA) += quantenna/ +obj-$(CONFIG_WLAN_VENDOR_CELENO) += celeno/ # 16-bit wireless PCMCIA client drivers obj-$(CONFIG_PCMCIA_RAYCS) += ray_cs.o
Signature · 1 line
2.36.1