1 /****************************************************************************** 2 * 3 * Copyright(c) 2007 - 2017 Realtek Corporation. 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of version 2 of the GNU General Public License as 7 * published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * more details. 13 * 14 *****************************************************************************/ 15 #ifndef __HAL_COM_PHYCFG_H__ 16 #define __HAL_COM_PHYCFG_H__ 17 18 #ifndef DBG_TX_POWER_IDX 19 #define DBG_TX_POWER_IDX 0 20 #endif 21 22 #define PathA 0x0 /* Useless */ 23 #define PathB 0x1 24 #define PathC 0x2 25 #define PathD 0x3 26 27 typedef enum _RF_TX_NUM { 28 RF_1TX = 0, 29 RF_2TX, 30 RF_3TX, 31 RF_4TX, 32 RF_MAX_TX_NUM, 33 RF_TX_NUM_NONIMPLEMENT, 34 } RF_TX_NUM; 35 36 enum txpwr_pg_mode { 37 TXPWR_PG_WITH_PWR_IDX, 38 TXPWR_PG_WITH_TSSI_OFFSET, 39 TXPWR_PG_UNKNOWN, /* keep last */ 40 }; 41 42 /*------------------------------Define structure----------------------------*/ 43 typedef struct _BB_REGISTER_DEFINITION { 44 u32 rfintfs; /* set software control: */ 45 /* 0x870~0x877[8 bytes] */ 46 47 u32 rfintfo; /* output data: */ 48 /* 0x860~0x86f [16 bytes] */ 49 50 u32 rfintfe; /* output enable: */ 51 /* 0x860~0x86f [16 bytes] */ 52 53 u32 rf3wireOffset; /* LSSI data: */ 54 /* 0x840~0x84f [16 bytes] */ 55 56 u32 rfHSSIPara2; /* wire parameter control2 : */ 57 /* 0x824~0x827,0x82c~0x82f, 0x834~0x837, 0x83c~0x83f [16 bytes] */ 58 59 u32 rfLSSIReadBack; /* LSSI RF readback data SI mode */ 60 /* 0x8a0~0x8af [16 bytes] */ 61 62 u32 rfLSSIReadBackPi; /* LSSI RF readback data PI mode 0x8b8-8bc for Path A and B */ 63 64 } BB_REGISTER_DEFINITION_T, *PBB_REGISTER_DEFINITION_T; 65 66 67 /* ---------------------------------------------------------------------- */ 68 69 extern const char *const _txpwr_pg_mode_str[]; 70 #define txpwr_pg_mode_str(_mode) (((_mode) >= TXPWR_PG_UNKNOWN) ? _txpwr_pg_mode_str[TXPWR_PG_UNKNOWN] : _txpwr_pg_mode_str[(_mode)]) 71 72 u8 phy_get_target_txpwr( 73 PADAPTER Adapter, 74 u8 Band, 75 u8 RfPath, 76 RATE_SECTION RateSection 77 ); 78 79 void 80 PHY_GetRateValuesOfTxPowerByRate( 81 PADAPTER pAdapter, 82 u32 RegAddr, 83 u32 BitMask, 84 u32 Value, 85 u8 *Rate, 86 s8 *PwrByRateVal, 87 u8 *RateNum 88 ); 89 90 u8 91 PHY_GetRateIndexOfTxPowerByRate( 92 u8 Rate 93 ); 94 95 void 96 phy_set_tx_power_index_by_rate_section( 97 PADAPTER pAdapter, 98 enum rf_path RFPath, 99 u8 Channel, 100 u8 RateSection 101 ); 102 103 s8 104 _PHY_GetTxPowerByRate( 105 PADAPTER pAdapter, 106 u8 Band, 107 enum rf_path RFPath, 108 u8 RateIndex 109 ); 110 111 s8 112 PHY_GetTxPowerByRate( 113 PADAPTER pAdapter, 114 u8 Band, 115 enum rf_path RFPath, 116 RATE_SECTION rs, 117 enum MGN_RATE rate 118 ); 119 120 void 121 PHY_SetTxPowerByRate( 122 PADAPTER pAdapter, 123 u8 Band, 124 enum rf_path RFPath, 125 u8 Rate, 126 s8 Value 127 ); 128 129 void 130 phy_set_tx_power_level_by_path( 131 PADAPTER Adapter, 132 u8 channel, 133 u8 path 134 ); 135 136 void 137 PHY_InitTxPowerByRate( 138 PADAPTER pAdapter 139 ); 140 141 void 142 phy_store_tx_power_by_rate( 143 PADAPTER pAdapter, 144 u32 Band, 145 u32 RfPath, 146 u32 TxNum, 147 u32 RegAddr, 148 u32 BitMask, 149 u32 Data 150 ); 151 152 void 153 PHY_TxPowerByRateConfiguration( 154 PADAPTER pAdapter 155 ); 156 157 bool phy_chk_ch_setting_consistency(_adapter *adapter, u8 ch); 158 159 #ifdef CONFIG_TXPWR_PG_WITH_PWR_IDX 160 u8 phy_get_pg_txpwr_idx(_adapter *pAdapter 161 , enum rf_path RFPath, RATE_SECTION rs, u8 ntx_idx 162 , enum channel_width BandWidth, u8 band, u8 Channel); 163 #endif 164 165 #if CONFIG_TXPWR_LIMIT 166 s8 phy_get_txpwr_lmt(_adapter *adapter 167 , const char *regd_name 168 , BAND_TYPE band, enum channel_width bw 169 , u8 tlrs, u8 ntx_idx, u8 cch, u8 lock 170 ); 171 172 s8 phy_get_txpwr_lmt_diff(_adapter *adapter 173 , const char *regd_name 174 , BAND_TYPE band, enum channel_width bw 175 , u8 rfpath, u8 rs, u8 tlrs, u8 ntx_idx, u8 cch, u8 lock 176 ); 177 178 s8 phy_get_txpwr_lmt_sub_chs(_adapter *adapter 179 , const char *regd_name 180 , BAND_TYPE band, enum channel_width bw 181 , u8 rfpath, u8 rate, u8 ntx_idx, u8 cch, u8 opch 182 ); 183 #else 184 #define phy_get_txpwr_lmt(adapter, regd_name, band, bw, tlrs, ntx_idx, cch, lock) (GET_HAL_SPEC(adapter)->txgi_max) 185 #define phy_get_txpwr_lmt_diff(adapter, regd_name, band, bw, rfpath, rs, tlrs, ntx_idx, cch, lock) (GET_HAL_SPEC(adapter)->txgi_max) 186 #define phy_get_txpwr_lmt_sub_chs(adapter, regd_name, band, bw, rfpath, rate, ntx_idx, cch, opch) (GET_HAL_SPEC(adapter)->txgi_max) 187 #endif /* CONFIG_TXPWR_LIMIT */ 188 189 void dump_txpwr_tpc_settings(void *sel, _adapter *adapter); 190 void dump_txpwr_antenna_gain(void *sel, _adapter *adapter); 191 192 s8 phy_get_txpwr_target(_adapter *adapter, u8 rfpath, RATE_SECTION rs, u8 rate, u8 ntx_idx 193 , enum channel_width bw, BAND_TYPE band, u8 cch, u8 opch, struct txpwr_idx_comp *tic); 194 s8 phy_get_txpwr_amends(_adapter *adapter, u8 rfpath, RATE_SECTION rs, u8 rate, u8 ntx_idx 195 , enum channel_width bw, BAND_TYPE band, u8 cch, struct txpwr_idx_comp *tic); 196 #ifdef CONFIG_TXPWR_PG_WITH_TSSI_OFFSET 197 s8 phy_get_tssi_txpwr_by_rate_ref(_adapter *adapter, enum rf_path path 198 , enum channel_width bw, u8 cch, u8 opch); 199 #endif 200 u8 hal_com_get_txpwr_idx(_adapter *adapter, enum rf_path rfpath 201 , RATE_SECTION rs, enum MGN_RATE rate, enum channel_width bw, BAND_TYPE band, u8 cch, u8 opch 202 , struct txpwr_idx_comp *tic); 203 204 s16 phy_get_txpwr_single_mbm(_adapter *adapter, u8 rfpath, RATE_SECTION rs, u8 rate 205 , enum channel_width bw, u8 cch, u8 opch, bool eirp, struct txpwr_idx_comp *tic); 206 s16 phy_get_txpwr_total_mbm(_adapter *adapter, RATE_SECTION rs, u8 rate 207 , enum channel_width bw, u8 cch, u8 opch, bool eirp, struct txpwr_idx_comp *tic); 208 209 s16 phy_get_txpwr_single_max_mbm(_adapter *adapter, u8 rfpath 210 , enum channel_width bw, u8 cch, u8 opch, u16 bmp_cck_ofdm, u32 bmp_ht, u64 bmp_vht, bool eirp); 211 s16 phy_get_txpwr_total_max_mbm(_adapter *adapter 212 , enum channel_width bw, u8 cch, u8 opch, u16 bmp_cck_ofdm, u32 bmp_ht, u64 bmp_vht, bool eirp); 213 214 s8 215 phy_get_tx_power_final_absolute_value(_adapter *adapter, u8 rfpath, u8 rate, 216 enum channel_width bw, u8 channel); 217 218 s8 219 PHY_GetTxPowerTrackingOffset( 220 PADAPTER pAdapter, 221 enum rf_path RFPath, 222 u8 Rate 223 ); 224 225 struct txpwr_idx_comp { 226 u8 ntx_idx; 227 s8 target; 228 s8 base; 229 230 /* for target */ 231 s8 by_rate; 232 s8 btc; 233 s8 extra; 234 s8 utarget; 235 s8 limit; 236 s8 ulimit; 237 s8 tpc; 238 239 /* for amends */ 240 s8 tpt; 241 s8 dpd; 242 }; 243 244 u8 phy_get_tx_power_index_ex(_adapter *adapter 245 , enum rf_path rfpath, RATE_SECTION rs, enum MGN_RATE rate 246 , enum channel_width bw, BAND_TYPE band, u8 cch, u8 opch); 247 248 u8 249 phy_get_tx_power_index( 250 PADAPTER pAdapter, 251 enum rf_path RFPath, 252 u8 Rate, 253 enum channel_width BandWidth, 254 u8 Channel 255 ); 256 257 void 258 PHY_SetTxPowerIndex( 259 PADAPTER pAdapter, 260 u32 PowerIndex, 261 enum rf_path RFPath, 262 u8 Rate 263 ); 264 265 bool phy_is_txpwr_user_mbm_valid(_adapter *adapter, s16 mbm); 266 bool phy_is_txpwr_user_target_specified(_adapter *adapter); 267 268 void dump_tx_power_index_inline(void *sel, _adapter *adapter, u8 rfpath 269 , enum channel_width bw, u8 cch, enum MGN_RATE rate, u8 pwr_idx, struct txpwr_idx_comp *tic); 270 #ifdef CONFIG_PROC_DEBUG 271 void dump_tx_power_idx_title(void *sel, _adapter *adapter 272 , enum channel_width bw, u8 cch, u8 opch); 273 void dump_tx_power_idx_by_path_rs(void *sel, _adapter *adapter, u8 rfpath 274 , RATE_SECTION rs, enum channel_width bw, u8 cch, u8 opch); 275 void dump_tx_power_idx(void *sel, _adapter *adapter 276 , enum channel_width bw, u8 cch, u8 opch); 277 void dump_txpwr_total_dbm_title(void *sel, _adapter *adapter 278 , enum channel_width bw, u8 cch, u8 opch); 279 void dump_txpwr_total_dbm_by_rs(void *sel, _adapter *adapter, u8 rs 280 , enum channel_width bw, u8 cch, u8 opch); 281 void dump_txpwr_total_dbm(void *sel, _adapter *adapter 282 , enum channel_width bw, u8 cch, u8 opch); 283 #endif 284 285 bool phy_is_tx_power_limit_needed(_adapter *adapter); 286 bool phy_is_tx_power_by_rate_needed(_adapter *adapter); 287 int phy_load_tx_power_by_rate(_adapter *adapter, u8 chk_file); 288 #if CONFIG_TXPWR_LIMIT 289 int phy_load_tx_power_limit(_adapter *adapter, u8 chk_file); 290 #endif 291 void phy_load_tx_power_ext_info(_adapter *adapter, u8 chk_file); 292 void phy_reload_tx_power_ext_info(_adapter *adapter); 293 void phy_reload_default_tx_power_ext_info(_adapter *adapter); 294 295 const struct map_t *hal_pg_txpwr_def_info(_adapter *adapter); 296 297 #ifdef CONFIG_EFUSE_CONFIG_FILE 298 int check_phy_efuse_tx_power_info_valid(_adapter *adapter); 299 #endif 300 301 #ifdef CONFIG_TXPWR_PG_WITH_PWR_IDX 302 void dump_hal_txpwr_info_2g(void *sel, _adapter *adapter, u8 rfpath_num, u8 max_tx_cnt); 303 void dump_hal_txpwr_info_5g(void *sel, _adapter *adapter, u8 rfpath_num, u8 max_tx_cnt); 304 305 void hal_load_txpwr_info(_adapter *adapter); 306 #endif 307 308 #ifdef CONFIG_PROC_DEBUG 309 void dump_tx_power_ext_info(void *sel, _adapter *adapter); 310 void dump_target_tx_power(void *sel, _adapter *adapter); 311 void dump_tx_power_by_rate(void *sel, _adapter *adapter); 312 #endif 313 314 int rtw_get_phy_file_path(_adapter *adapter, const char *file_name); 315 316 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE 317 #define MAC_FILE_FW_NIC "FW_NIC.bin" 318 #define MAC_FILE_FW_WW_IMG "FW_WoWLAN.bin" 319 #define PHY_FILE_MAC_REG "MAC_REG.txt" 320 321 #define PHY_FILE_AGC_TAB "AGC_TAB.txt" 322 #define PHY_FILE_PHY_REG "PHY_REG.txt" 323 #define PHY_FILE_PHY_REG_MP "PHY_REG_MP.txt" 324 #define PHY_FILE_PHY_REG_PG "PHY_REG_PG.txt" 325 326 #define PHY_FILE_RADIO_A "RadioA.txt" 327 #define PHY_FILE_RADIO_B "RadioB.txt" 328 #define PHY_FILE_RADIO_C "RadioC.txt" 329 #define PHY_FILE_RADIO_D "RadioD.txt" 330 #define PHY_FILE_TXPWR_TRACK "TxPowerTrack.txt" 331 #define PHY_FILE_TXPWR_LMT "TXPWR_LMT.txt" 332 333 #define PHY_FILE_WIFI_ANT_ISOLATION "wifi_ant_isolation.txt" 334 335 #define MAX_PARA_FILE_BUF_LEN 32768 /* 32k */ 336 337 #define LOAD_MAC_PARA_FILE BIT0 338 #define LOAD_BB_PARA_FILE BIT1 339 #define LOAD_BB_PG_PARA_FILE BIT2 340 #define LOAD_BB_MP_PARA_FILE BIT3 341 #define LOAD_RF_PARA_FILE BIT4 342 #define LOAD_RF_TXPWR_TRACK_PARA_FILE BIT5 343 #define LOAD_RF_TXPWR_LMT_PARA_FILE BIT6 344 345 int phy_ConfigMACWithParaFile(PADAPTER Adapter, char *pFileName); 346 int phy_ConfigBBWithParaFile(PADAPTER Adapter, char *pFileName, u32 ConfigType); 347 int phy_ConfigBBWithPgParaFile(PADAPTER Adapter, const char *pFileName); 348 int phy_ConfigBBWithMpParaFile(PADAPTER Adapter, char *pFileName); 349 int PHY_ConfigRFWithParaFile(PADAPTER Adapter, char *pFileName, enum rf_path eRFPath); 350 int PHY_ConfigRFWithTxPwrTrackParaFile(PADAPTER Adapter, char *pFileName); 351 #if CONFIG_TXPWR_LIMIT 352 int PHY_ConfigRFWithPowerLimitTableParaFile(PADAPTER Adapter, const char *pFileName); 353 #endif 354 void phy_free_filebuf_mask(_adapter *padapter, u8 mask); 355 void phy_free_filebuf(_adapter *padapter); 356 #endif /* CONFIG_LOAD_PHY_PARA_FROM_FILE */ 357 u8 phy_check_under_survey_ch(_adapter *adapter); 358 #endif /* __HAL_COMMON_H__ */ 359