Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /******************************************************************************
0003  *
0004  * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
0005  * Copyright(c) 2015 Intel Mobile Communications GmbH
0006  * Copyright(c) 2017 Intel Deutschland GmbH
0007  * Copyright(c) 2018 - 2019 Intel Corporation
0008  *****************************************************************************/
0009 
0010 #ifndef __rs_h__
0011 #define __rs_h__
0012 
0013 #include <net/mac80211.h>
0014 
0015 #include "iwl-config.h"
0016 
0017 #include "fw-api.h"
0018 #include "iwl-trans.h"
0019 
0020 #define RS_NAME "iwl-mvm-rs"
0021 
0022 struct iwl_rs_rate_info {
0023     u8 plcp;      /* uCode API:  IWL_RATE_6M_PLCP, etc. */
0024     u8 plcp_ht_siso;  /* uCode API:  IWL_RATE_SISO_6M_PLCP, etc. */
0025     u8 plcp_ht_mimo2; /* uCode API:  IWL_RATE_MIMO2_6M_PLCP, etc. */
0026     u8 plcp_vht_siso;
0027     u8 plcp_vht_mimo2;
0028     u8 prev_rs;      /* previous rate used in rs algo */
0029     u8 next_rs;      /* next rate used in rs algo */
0030 };
0031 
0032 #define IWL_RATE_60M_PLCP 3
0033 
0034 #define LINK_QUAL_MAX_RETRY_NUM 16
0035 
0036 enum {
0037     IWL_RATE_6M_INDEX_TABLE = 0,
0038     IWL_RATE_9M_INDEX_TABLE,
0039     IWL_RATE_12M_INDEX_TABLE,
0040     IWL_RATE_18M_INDEX_TABLE,
0041     IWL_RATE_24M_INDEX_TABLE,
0042     IWL_RATE_36M_INDEX_TABLE,
0043     IWL_RATE_48M_INDEX_TABLE,
0044     IWL_RATE_54M_INDEX_TABLE,
0045     IWL_RATE_1M_INDEX_TABLE,
0046     IWL_RATE_2M_INDEX_TABLE,
0047     IWL_RATE_5M_INDEX_TABLE,
0048     IWL_RATE_11M_INDEX_TABLE,
0049     IWL_RATE_INVM_INDEX_TABLE = IWL_RATE_INVM_INDEX - 1,
0050 };
0051 
0052 /* #define vs. enum to keep from defaulting to 'large integer' */
0053 #define IWL_RATE_6M_MASK   (1 << IWL_RATE_6M_INDEX)
0054 #define IWL_RATE_9M_MASK   (1 << IWL_RATE_9M_INDEX)
0055 #define IWL_RATE_12M_MASK  (1 << IWL_RATE_12M_INDEX)
0056 #define IWL_RATE_18M_MASK  (1 << IWL_RATE_18M_INDEX)
0057 #define IWL_RATE_24M_MASK  (1 << IWL_RATE_24M_INDEX)
0058 #define IWL_RATE_36M_MASK  (1 << IWL_RATE_36M_INDEX)
0059 #define IWL_RATE_48M_MASK  (1 << IWL_RATE_48M_INDEX)
0060 #define IWL_RATE_54M_MASK  (1 << IWL_RATE_54M_INDEX)
0061 #define IWL_RATE_60M_MASK  (1 << IWL_RATE_60M_INDEX)
0062 #define IWL_RATE_1M_MASK   (1 << IWL_RATE_1M_INDEX)
0063 #define IWL_RATE_2M_MASK   (1 << IWL_RATE_2M_INDEX)
0064 #define IWL_RATE_5M_MASK   (1 << IWL_RATE_5M_INDEX)
0065 #define IWL_RATE_11M_MASK  (1 << IWL_RATE_11M_INDEX)
0066 
0067 
0068 /* uCode API values for HT/VHT bit rates */
0069 enum {
0070     IWL_RATE_HT_SISO_MCS_0_PLCP = 0,
0071     IWL_RATE_HT_SISO_MCS_1_PLCP = 1,
0072     IWL_RATE_HT_SISO_MCS_2_PLCP = 2,
0073     IWL_RATE_HT_SISO_MCS_3_PLCP = 3,
0074     IWL_RATE_HT_SISO_MCS_4_PLCP = 4,
0075     IWL_RATE_HT_SISO_MCS_5_PLCP = 5,
0076     IWL_RATE_HT_SISO_MCS_6_PLCP = 6,
0077     IWL_RATE_HT_SISO_MCS_7_PLCP = 7,
0078     IWL_RATE_HT_MIMO2_MCS_0_PLCP = 0x8,
0079     IWL_RATE_HT_MIMO2_MCS_1_PLCP = 0x9,
0080     IWL_RATE_HT_MIMO2_MCS_2_PLCP = 0xA,
0081     IWL_RATE_HT_MIMO2_MCS_3_PLCP = 0xB,
0082     IWL_RATE_HT_MIMO2_MCS_4_PLCP = 0xC,
0083     IWL_RATE_HT_MIMO2_MCS_5_PLCP = 0xD,
0084     IWL_RATE_HT_MIMO2_MCS_6_PLCP = 0xE,
0085     IWL_RATE_HT_MIMO2_MCS_7_PLCP = 0xF,
0086     IWL_RATE_VHT_SISO_MCS_0_PLCP = 0,
0087     IWL_RATE_VHT_SISO_MCS_1_PLCP = 1,
0088     IWL_RATE_VHT_SISO_MCS_2_PLCP = 2,
0089     IWL_RATE_VHT_SISO_MCS_3_PLCP = 3,
0090     IWL_RATE_VHT_SISO_MCS_4_PLCP = 4,
0091     IWL_RATE_VHT_SISO_MCS_5_PLCP = 5,
0092     IWL_RATE_VHT_SISO_MCS_6_PLCP = 6,
0093     IWL_RATE_VHT_SISO_MCS_7_PLCP = 7,
0094     IWL_RATE_VHT_SISO_MCS_8_PLCP = 8,
0095     IWL_RATE_VHT_SISO_MCS_9_PLCP = 9,
0096     IWL_RATE_VHT_MIMO2_MCS_0_PLCP = 0x10,
0097     IWL_RATE_VHT_MIMO2_MCS_1_PLCP = 0x11,
0098     IWL_RATE_VHT_MIMO2_MCS_2_PLCP = 0x12,
0099     IWL_RATE_VHT_MIMO2_MCS_3_PLCP = 0x13,
0100     IWL_RATE_VHT_MIMO2_MCS_4_PLCP = 0x14,
0101     IWL_RATE_VHT_MIMO2_MCS_5_PLCP = 0x15,
0102     IWL_RATE_VHT_MIMO2_MCS_6_PLCP = 0x16,
0103     IWL_RATE_VHT_MIMO2_MCS_7_PLCP = 0x17,
0104     IWL_RATE_VHT_MIMO2_MCS_8_PLCP = 0x18,
0105     IWL_RATE_VHT_MIMO2_MCS_9_PLCP = 0x19,
0106     IWL_RATE_HT_SISO_MCS_INV_PLCP,
0107     IWL_RATE_HT_MIMO2_MCS_INV_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP,
0108     IWL_RATE_VHT_SISO_MCS_INV_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP,
0109     IWL_RATE_VHT_MIMO2_MCS_INV_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP,
0110     IWL_RATE_HT_SISO_MCS_8_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP,
0111     IWL_RATE_HT_SISO_MCS_9_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP,
0112     IWL_RATE_HT_MIMO2_MCS_8_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP,
0113     IWL_RATE_HT_MIMO2_MCS_9_PLCP = IWL_RATE_HT_SISO_MCS_INV_PLCP,
0114 };
0115 
0116 #define IWL_RATES_MASK ((1 << IWL_RATE_COUNT) - 1)
0117 
0118 #define IWL_INVALID_VALUE    -1
0119 
0120 #define TPC_MAX_REDUCTION       15
0121 #define TPC_NO_REDUCTION        0
0122 #define TPC_INVALID         0xff
0123 
0124 #define LINK_QUAL_AGG_FRAME_LIMIT_DEF   (63)
0125 #define LINK_QUAL_AGG_FRAME_LIMIT_MAX   (63)
0126 /*
0127  * FIXME - various places in firmware API still use u8,
0128  * e.g. LQ command and SCD config command.
0129  * This should be 256 instead.
0130  */
0131 #define LINK_QUAL_AGG_FRAME_LIMIT_GEN2_DEF  (255)
0132 #define LINK_QUAL_AGG_FRAME_LIMIT_GEN2_MAX  (255)
0133 #define LINK_QUAL_AGG_FRAME_LIMIT_MIN   (0)
0134 
0135 #define LQ_SIZE     2   /* 2 mode tables:  "Active" and "Search" */
0136 
0137 /* load per tid defines for A-MPDU activation */
0138 #define IWL_AGG_TPT_THREHOLD    0
0139 #define IWL_AGG_ALL_TID     0xff
0140 
0141 enum iwl_table_type {
0142     LQ_NONE,
0143     LQ_LEGACY_G,    /* legacy types */
0144     LQ_LEGACY_A,
0145     LQ_HT_SISO, /* HT types */
0146     LQ_HT_MIMO2,
0147     LQ_VHT_SISO,    /* VHT types */
0148     LQ_VHT_MIMO2,
0149     LQ_HE_SISO,     /* HE types */
0150     LQ_HE_MIMO2,
0151     LQ_MAX,
0152 };
0153 
0154 struct rs_rate {
0155     int index;
0156     enum iwl_table_type type;
0157     u8 ant;
0158     u32 bw;
0159     bool sgi;
0160     bool ldpc;
0161     bool stbc;
0162     bool bfer;
0163 };
0164 
0165 
0166 #define is_type_legacy(type) (((type) == LQ_LEGACY_G) || \
0167                   ((type) == LQ_LEGACY_A))
0168 #define is_type_ht_siso(type) ((type) == LQ_HT_SISO)
0169 #define is_type_ht_mimo2(type) ((type) == LQ_HT_MIMO2)
0170 #define is_type_vht_siso(type) ((type) == LQ_VHT_SISO)
0171 #define is_type_vht_mimo2(type) ((type) == LQ_VHT_MIMO2)
0172 #define is_type_he_siso(type) ((type) == LQ_HE_SISO)
0173 #define is_type_he_mimo2(type) ((type) == LQ_HE_MIMO2)
0174 #define is_type_siso(type) (is_type_ht_siso(type) || is_type_vht_siso(type) || \
0175                 is_type_he_siso(type))
0176 #define is_type_mimo2(type) (is_type_ht_mimo2(type) || \
0177                  is_type_vht_mimo2(type) || is_type_he_mimo2(type))
0178 #define is_type_mimo(type) (is_type_mimo2(type))
0179 #define is_type_ht(type) (is_type_ht_siso(type) || is_type_ht_mimo2(type))
0180 #define is_type_vht(type) (is_type_vht_siso(type) || is_type_vht_mimo2(type))
0181 #define is_type_he(type) (is_type_he_siso(type) || is_type_he_mimo2(type))
0182 #define is_type_a_band(type) ((type) == LQ_LEGACY_A)
0183 #define is_type_g_band(type) ((type) == LQ_LEGACY_G)
0184 
0185 #define is_legacy(rate)       is_type_legacy((rate)->type)
0186 #define is_ht_siso(rate)      is_type_ht_siso((rate)->type)
0187 #define is_ht_mimo2(rate)     is_type_ht_mimo2((rate)->type)
0188 #define is_vht_siso(rate)     is_type_vht_siso((rate)->type)
0189 #define is_vht_mimo2(rate)    is_type_vht_mimo2((rate)->type)
0190 #define is_siso(rate)         is_type_siso((rate)->type)
0191 #define is_mimo2(rate)        is_type_mimo2((rate)->type)
0192 #define is_mimo(rate)         is_type_mimo((rate)->type)
0193 #define is_ht(rate)           is_type_ht((rate)->type)
0194 #define is_vht(rate)          is_type_vht((rate)->type)
0195 #define is_he(rate)           is_type_he((rate)->type)
0196 #define is_a_band(rate)       is_type_a_band((rate)->type)
0197 #define is_g_band(rate)       is_type_g_band((rate)->type)
0198 
0199 #define is_ht20(rate)         ((rate)->bw == RATE_MCS_CHAN_WIDTH_20)
0200 #define is_ht40(rate)         ((rate)->bw == RATE_MCS_CHAN_WIDTH_40)
0201 #define is_ht80(rate)         ((rate)->bw == RATE_MCS_CHAN_WIDTH_80)
0202 #define is_ht160(rate)        ((rate)->bw == RATE_MCS_CHAN_WIDTH_160)
0203 
0204 /**
0205  * struct iwl_lq_sta_rs_fw - rate and related statistics for RS in FW
0206  * @last_rate_n_flags: last rate reported by FW
0207  * @sta_id: the id of the station
0208 #ifdef CONFIG_MAC80211_DEBUGFS
0209  * @dbg_fixed_rate: for debug, use fixed rate if not 0
0210  * @dbg_agg_frame_count_lim: for debug, max number of frames in A-MPDU
0211 #endif
0212  * @chains: bitmask of chains reported in %chain_signal
0213  * @chain_signal: per chain signal strength
0214  * @last_rssi: last rssi reported
0215  * @drv: pointer back to the driver data
0216  */
0217 
0218 struct iwl_lq_sta_rs_fw {
0219     /* last tx rate_n_flags */
0220     u32 last_rate_n_flags;
0221 
0222     /* persistent fields - initialized only once - keep last! */
0223     struct lq_sta_pers_rs_fw {
0224         u32 sta_id;
0225 #ifdef CONFIG_MAC80211_DEBUGFS
0226         u32 dbg_fixed_rate;
0227         u16 dbg_agg_frame_count_lim;
0228 #endif
0229         u8 chains;
0230         s8 chain_signal[IEEE80211_MAX_CHAINS];
0231         s8 last_rssi;
0232         struct iwl_mvm *drv;
0233     } pers;
0234 };
0235 
0236 /**
0237  * struct iwl_rate_scale_data -- tx success history for one rate
0238  */
0239 struct iwl_rate_scale_data {
0240     u64 data;       /* bitmap of successful frames */
0241     s32 success_counter;    /* number of frames successful */
0242     s32 success_ratio;  /* per-cent * 128  */
0243     s32 counter;        /* number of frames attempted */
0244     s32 average_tpt;    /* success ratio * expected throughput */
0245 };
0246 
0247 /* Possible Tx columns
0248  * Tx Column = a combo of legacy/siso/mimo x antenna x SGI
0249  */
0250 enum rs_column {
0251     RS_COLUMN_LEGACY_ANT_A = 0,
0252     RS_COLUMN_LEGACY_ANT_B,
0253     RS_COLUMN_SISO_ANT_A,
0254     RS_COLUMN_SISO_ANT_B,
0255     RS_COLUMN_SISO_ANT_A_SGI,
0256     RS_COLUMN_SISO_ANT_B_SGI,
0257     RS_COLUMN_MIMO2,
0258     RS_COLUMN_MIMO2_SGI,
0259 
0260     RS_COLUMN_LAST = RS_COLUMN_MIMO2_SGI,
0261     RS_COLUMN_COUNT = RS_COLUMN_LAST + 1,
0262     RS_COLUMN_INVALID,
0263 };
0264 
0265 enum rs_ss_force_opt {
0266     RS_SS_FORCE_NONE = 0,
0267     RS_SS_FORCE_STBC,
0268     RS_SS_FORCE_BFER,
0269     RS_SS_FORCE_SISO,
0270 };
0271 
0272 /* Packet stats per rate */
0273 struct rs_rate_stats {
0274     u64 success;
0275     u64 total;
0276 };
0277 
0278 /**
0279  * struct iwl_scale_tbl_info -- tx params and success history for all rates
0280  *
0281  * There are two of these in struct iwl_lq_sta,
0282  * one for "active", and one for "search".
0283  */
0284 struct iwl_scale_tbl_info {
0285     struct rs_rate rate;
0286     enum rs_column column;
0287     const u16 *expected_tpt;    /* throughput metrics; expected_tpt_G, etc. */
0288     struct iwl_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */
0289     /* per txpower-reduction history */
0290     struct iwl_rate_scale_data tpc_win[TPC_MAX_REDUCTION + 1];
0291 };
0292 
0293 enum {
0294     RS_STATE_SEARCH_CYCLE_STARTED,
0295     RS_STATE_SEARCH_CYCLE_ENDED,
0296     RS_STATE_STAY_IN_COLUMN,
0297 };
0298 
0299 /**
0300  * struct iwl_lq_sta -- driver's rate scaling private structure
0301  *
0302  * Pointer to this gets passed back and forth between driver and mac80211.
0303  */
0304 struct iwl_lq_sta {
0305     u8 active_tbl;      /* index of active table, range 0-1 */
0306     u8 rs_state;            /* RS_STATE_* */
0307     u8 search_better_tbl;   /* 1: currently trying alternate mode */
0308     s32 last_tpt;
0309 
0310     /* The following determine when to search for a new mode */
0311     u32 table_count_limit;
0312     u32 max_failure_limit;  /* # failed frames before new search */
0313     u32 max_success_limit;  /* # successful frames before new search */
0314     u32 table_count;
0315     u32 total_failed;   /* total failed frames, any/all rates */
0316     u32 total_success;  /* total successful frames, any/all rates */
0317     u64 flush_timer;    /* time staying in mode before new search */
0318 
0319     u32 visited_columns;    /* Bitmask marking which Tx columns were
0320                  * explored during a search cycle
0321                  */
0322     u64 last_tx;
0323     bool is_vht;
0324     bool ldpc;              /* LDPC Rx is supported by the STA */
0325     bool stbc_capable;      /* Tx STBC is supported by chip and Rx by STA */
0326     bool bfer_capable;      /* Remote supports beamformee and we BFer */
0327 
0328     enum nl80211_band band;
0329 
0330     /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */
0331     unsigned long active_legacy_rate;
0332     unsigned long active_siso_rate;
0333     unsigned long active_mimo2_rate;
0334 
0335     /* Highest rate per Tx mode */
0336     u8 max_legacy_rate_idx;
0337     u8 max_siso_rate_idx;
0338     u8 max_mimo2_rate_idx;
0339 
0340     /* Optimal rate based on RSSI and STA caps.
0341      * Used only to reflect link speed to userspace.
0342      */
0343     struct rs_rate optimal_rate;
0344     unsigned long optimal_rate_mask;
0345     const struct rs_init_rate_info *optimal_rates;
0346     int optimal_nentries;
0347 
0348     u8 missed_rate_counter;
0349 
0350     struct iwl_lq_cmd lq;
0351     struct iwl_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */
0352     u8 tx_agg_tid_en;
0353 
0354     /* last tx rate_n_flags */
0355     u32 last_rate_n_flags;
0356     /* packets destined for this STA are aggregated */
0357     u8 is_agg;
0358 
0359     /* tx power reduce for this sta */
0360     int tpc_reduce;
0361 
0362     /* persistent fields - initialized only once - keep last! */
0363     struct lq_sta_pers {
0364 #ifdef CONFIG_MAC80211_DEBUGFS
0365         u32 dbg_fixed_rate;
0366         u8 dbg_fixed_txp_reduction;
0367 
0368         /* force STBC/BFER/SISO for testing */
0369         enum rs_ss_force_opt ss_force;
0370 #endif
0371         u8 chains;
0372         s8 chain_signal[IEEE80211_MAX_CHAINS];
0373         s8 last_rssi;
0374         struct rs_rate_stats tx_stats[RS_COLUMN_COUNT][IWL_RATE_COUNT];
0375         struct iwl_mvm *drv;
0376         spinlock_t lock; /* for races in reinit/update table */
0377     } pers;
0378 };
0379 
0380 /* ieee80211_tx_info's status_driver_data[0] is packed with lq color and txp
0381  * Note, it's iwlmvm <-> mac80211 interface.
0382  * bits 0-7: reduced tx power
0383  * bits 8-10: LQ command's color
0384  */
0385 #define RS_DRV_DATA_TXP_MSK 0xff
0386 #define RS_DRV_DATA_LQ_COLOR_POS 8
0387 #define RS_DRV_DATA_LQ_COLOR_MSK (7 << RS_DRV_DATA_LQ_COLOR_POS)
0388 #define RS_DRV_DATA_LQ_COLOR_GET(_f) (((_f) & RS_DRV_DATA_LQ_COLOR_MSK) >>\
0389                       RS_DRV_DATA_LQ_COLOR_POS)
0390 #define RS_DRV_DATA_PACK(_c, _p) ((void *)(uintptr_t)\
0391                   (((uintptr_t)_p) |\
0392                    ((_c) << RS_DRV_DATA_LQ_COLOR_POS)))
0393 
0394 /* Initialize station's rate scaling information after adding station */
0395 void iwl_mvm_rs_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
0396               enum nl80211_band band, bool init);
0397 
0398 /* Notify RS about Tx status */
0399 void iwl_mvm_rs_tx_status(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
0400               int tid, struct ieee80211_tx_info *info, bool ndp);
0401 
0402 /**
0403  * iwl_rate_control_register - Register the rate control algorithm callbacks
0404  *
0405  * Since the rate control algorithm is hardware specific, there is no need
0406  * or reason to place it as a stand alone module.  The driver can call
0407  * iwl_rate_control_register in order to register the rate control callbacks
0408  * with the mac80211 subsystem.  This should be performed prior to calling
0409  * ieee80211_register_hw
0410  *
0411  */
0412 int iwl_mvm_rate_control_register(void);
0413 
0414 /**
0415  * iwl_rate_control_unregister - Unregister the rate control callbacks
0416  *
0417  * This should be called after calling ieee80211_unregister_hw, but before
0418  * the driver is unloaded.
0419  */
0420 void iwl_mvm_rate_control_unregister(void);
0421 
0422 struct iwl_mvm_sta;
0423 
0424 int iwl_mvm_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
0425               bool enable);
0426 
0427 #ifdef CONFIG_IWLWIFI_DEBUGFS
0428 void iwl_mvm_reset_frame_stats(struct iwl_mvm *mvm);
0429 #endif
0430 
0431 void iwl_mvm_rs_add_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta);
0432 void rs_fw_rate_init(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
0433              enum nl80211_band band, bool update);
0434 int rs_fw_tx_protection(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
0435             bool enable);
0436 void iwl_mvm_tlc_update_notif(struct iwl_mvm *mvm,
0437                   struct iwl_rx_cmd_buffer *rxb);
0438 
0439 u16 rs_fw_get_max_amsdu_len(struct ieee80211_sta *sta);
0440 #endif /* __rs__ */