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 * The full GNU General Public License is included in this distribution in the 15 * file called LICENSE. 16 * 17 * Contact Information: 18 * wlanfae <wlanfae@realtek.com> 19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, 20 * Hsinchu 300, Taiwan. 21 * 22 * Larry Finger <Larry.Finger@lwfinger.net> 23 * 24 *****************************************************************************/ 25 26 #ifndef __PHYDMCCX_H__ 27 #define __PHYDMCCX_H__ 28 29 /* 2020.08.12 split env_mntr api into set_env_mntr and result_env_mntr api for dig_fa_source*/ 30 #define CCX_VERSION "4.7" 31 32 /* @1 ============================================================ 33 * 1 Definition 34 * 1 ============================================================ 35 */ 36 #define CCX_EN 1 37 38 #define MAX_ENV_MNTR_TIME 8 /*second*/ 39 #define MS_TO_US 1000 40 #define MS_TO_4US_RATIO 250 41 #define CCA_CAP 14 42 /*CLM*/ 43 #define CLM_MAX_REPORT_TIME 10 44 #define CLM_PERIOD_MAX 65535 45 /*NHM*/ 46 #define NHM_PERIOD_MAX 65534 47 #define NHM_TH_NUM 11 /*threshold number of NHM*/ 48 #define NHM_RPT_NUM 12 49 #define NHM_IC_NOISE_TH 60 /*60/2 - 10 = 20 = -80 dBm*/ 50 #define NHM_RPT_MAX 255 51 #ifdef NHM_DYM_PW_TH_SUPPORT 52 #define DYM_PWTH_CCA_CAP 24 53 #endif 54 #define IGI_2_NHM_TH(igi) ((igi) << 1)/*NHM/FAHM threshold = IGI * 2*/ 55 #define NTH_TH_2_RSSI(th) ((th >> 1) - 10) 56 /*FAHM*/ 57 #define FAHM_INCLU_FA BIT(0) 58 #define FAHM_INCLU_CRC_OK BIT(1) 59 #define FAHM_INCLU_CRC_ERR BIT(2) 60 #define FAHM_PERIOD_MAX 65534 61 #define FAHM_TH_NUM 11 /*threshold number of FAHM*/ 62 #define FAHM_RPT_NUM 12 63 /*IFS-CLM*/ 64 #define IFS_CLM_PERIOD_MAX 65535 65 #define IFS_CLM_NUM 4 66 67 #define NHM_SUCCESS BIT(0) 68 #define CLM_SUCCESS BIT(1) 69 #define FAHM_SUCCESS BIT(2) 70 #define IFS_CLM_SUCCESS BIT(3) 71 #define ENV_MNTR_FAIL 0xff 72 73 /* @1 ============================================================ 74 * 1 enumrate 75 * 1 ============================================================ 76 */ 77 enum phydm_clm_level { 78 CLM_RELEASE = 0, 79 CLM_LV_1 = 1, /* @Low Priority function */ 80 CLM_LV_2 = 2, /* @Middle Priority function */ 81 CLM_LV_3 = 3, /* @High priority function (ex: Check hang function) */ 82 CLM_LV_4 = 4, /* @Debug function (the highest priority) */ 83 CLM_MAX_NUM = 5 84 }; 85 86 enum phydm_nhm_level { 87 NHM_RELEASE = 0, 88 NHM_LV_1 = 1, /* @Low Priority function */ 89 NHM_LV_2 = 2, /* @Middle Priority function */ 90 NHM_LV_3 = 3, /* @High priority function (ex: Check hang function) */ 91 NHM_LV_4 = 4, /* @Debug function (the highest priority) */ 92 NHM_MAX_NUM = 5 93 }; 94 95 enum phydm_fahm_level { 96 FAHM_RELEASE = 0, 97 FAHM_LV_1 = 1, /* Low Priority function */ 98 FAHM_LV_2 = 2, /* Middle Priority function */ 99 FAHM_LV_3 = 3, /* High priority function (ex: Check hang function) */ 100 FAHM_LV_4 = 4, /* Debug function (the highest priority) */ 101 FAHM_MAX_NUM = 5 102 }; 103 104 enum phydm_ifs_clm_level { 105 IFS_CLM_RELEASE = 0, 106 IFS_CLM_LV_1 = 1, /* @Low Priority function */ 107 IFS_CLM_LV_2 = 2, /* @Middle Priority function */ 108 IFS_CLM_LV_3 = 3, /* @High priority function (ex: Check hang function) */ 109 IFS_CLM_LV_4 = 4, /* @Debug function (the highest priority) */ 110 IFS_CLM_MAX_NUM = 5 111 }; 112 113 enum nhm_divider_opt_all { 114 NHM_CNT_ALL = 0, /*nhm SUM report <= 255*/ 115 NHM_VALID = 1, /*nhm SUM report = 255*/ 116 NHM_CNT_INIT 117 }; 118 119 enum nhm_setting { 120 SET_NHM_SETTING, 121 STORE_NHM_SETTING, 122 RESTORE_NHM_SETTING 123 }; 124 125 enum nhm_option_cca_all { 126 NHM_EXCLUDE_CCA = 0, 127 NHM_INCLUDE_CCA = 1, 128 NHM_CCA_INIT 129 }; 130 131 enum nhm_option_txon_all { 132 NHM_EXCLUDE_TXON = 0, 133 NHM_INCLUDE_TXON = 1, 134 NHM_TXON_INIT 135 }; 136 137 enum nhm_application { 138 NHM_BACKGROUND = 0,/*@default*/ 139 NHM_ACS = 1, 140 IEEE_11K_HIGH = 2, 141 IEEE_11K_LOW = 3, 142 INTEL_XBOX = 4, 143 NHM_DBG = 5, /*@manual trigger*/ 144 }; 145 146 enum clm_application { 147 CLM_BACKGROUND = 0,/*@default*/ 148 CLM_ACS = 1, 149 }; 150 151 enum fahm_application { 152 FAHM_BACKGROUND = 0,/*default*/ 153 FAHM_ACS = 1, 154 FAHM_DBG = 2, /*manual trigger*/ 155 }; 156 157 enum ifs_clm_application { 158 IFS_CLM_BACKGROUND = 0,/*default*/ 159 IFS_CLM_ACS = 1, 160 IFS_CLM_HP_TAS = 2, 161 IFS_CLM_DBG = 3, 162 }; 163 164 enum clm_monitor_mode { 165 CLM_DRIVER_MNTR = 1, 166 CLM_FW_MNTR = 2 167 }; 168 169 enum phydm_ifs_clm_unit { 170 IFS_CLM_4 = 0, /*4us*/ 171 IFS_CLM_8 = 1, /*8us*/ 172 IFS_CLM_12 = 2, /*12us*/ 173 IFS_CLM_16 = 3, /*16us*/ 174 IFS_CLM_INIT 175 }; 176 177 /* @1 ============================================================ 178 * 1 structure 179 * 1 ============================================================ 180 */ 181 struct env_trig_rpt { 182 u8 nhm_rpt_stamp; 183 u8 clm_rpt_stamp; 184 }; 185 186 struct env_mntr_rpt { 187 u8 nhm_ratio; 188 u8 nhm_env_ratio; /*exclude nhm_r[0] above -80dBm or first cluster under -80dBm*/ 189 u8 nhm_result[NHM_RPT_NUM]; 190 u8 clm_ratio; 191 u8 nhm_rpt_stamp; 192 u8 clm_rpt_stamp; 193 u8 nhm_noise_pwr; /*including r[0]~r[10]*/ 194 u8 nhm_pwr; /*including r[0]~r[11]*/ 195 }; 196 197 struct enhance_mntr_trig_rpt { 198 u8 nhm_rpt_stamp; 199 u8 clm_rpt_stamp; 200 u8 fahm_rpt_stamp; 201 u8 ifs_clm_rpt_stamp; 202 }; 203 204 struct enhance_mntr_rpt { 205 u8 nhm_ratio; 206 u8 nhm_env_ratio; /*exclude nhm_r[0] above -80dBm or first cluster under -80dBm*/ 207 u8 nhm_result[NHM_RPT_NUM]; 208 u8 clm_ratio; 209 u8 nhm_rpt_stamp; 210 u8 clm_rpt_stamp; 211 u8 nhm_noise_pwr; /*including r[0]~r[10]*/ 212 u8 nhm_pwr; /*including r[0]~r[11]*/ 213 u16 fahm_result[NHM_RPT_NUM]; 214 u8 fahm_rpt_stamp; 215 u8 fahm_pwr; 216 u8 fahm_ratio; 217 u8 fahm_denom_ratio; 218 u8 fahm_inclu_cck; 219 u8 ifs_clm_rpt_stamp; 220 u8 ifs_clm_tx_ratio; 221 u8 ifs_clm_edcca_excl_cca_ratio; 222 u8 ifs_clm_cck_fa_ratio; 223 u8 ifs_clm_cck_cca_excl_fa_ratio; 224 u8 ifs_clm_ofdm_fa_ratio; 225 u8 ifs_clm_ofdm_cca_excl_fa_ratio; 226 }; 227 228 struct nhm_para_info { 229 enum nhm_option_txon_all incld_txon; /*@Include TX on*/ 230 enum nhm_option_cca_all incld_cca; /*@Include CCA*/ 231 enum nhm_divider_opt_all div_opt; /*@divider option*/ 232 enum nhm_application nhm_app; 233 enum phydm_nhm_level nhm_lv; 234 u16 mntr_time; /*@0~262 unit ms*/ 235 boolean en_1db_mode; 236 u8 nhm_th0_manual; /* for 1-db mode*/ 237 }; 238 239 struct clm_para_info { 240 enum clm_application clm_app; 241 enum phydm_clm_level clm_lv; 242 u16 mntr_time; /*@0~262 unit ms*/ 243 }; 244 245 struct fahm_para_info { 246 enum fahm_application app; 247 enum phydm_fahm_level lv; 248 u16 mntr_time; /*0~262 unit ms*/ 249 u8 numer_opt; 250 u8 denom_opt; 251 boolean en_1db_mode; 252 u8 th0_manual;/* for 1-db mode*/ 253 }; 254 255 struct ifs_clm_para_info { 256 enum ifs_clm_application ifs_clm_app; 257 enum phydm_ifs_clm_level ifs_clm_lv; 258 enum phydm_ifs_clm_unit ifs_clm_ctrl_unit; /*unit*/ 259 u16 mntr_time; /*ms*/ 260 boolean ifs_clm_th_en[IFS_CLM_NUM]; 261 u16 ifs_clm_th_low[IFS_CLM_NUM]; 262 u16 ifs_clm_th_high[IFS_CLM_NUM]; 263 s16 th_shift; 264 }; 265 266 struct ccx_info { 267 u32 nhm_trigger_time; 268 u32 clm_trigger_time; 269 u32 fahm_trigger_time; 270 u32 ifs_clm_trigger_time; 271 u64 start_time; /*@monitor for the test duration*/ 272 u8 ccx_watchdog_result; 273 #ifdef NHM_SUPPORT 274 enum nhm_application nhm_app; 275 enum nhm_option_txon_all nhm_include_txon; 276 enum nhm_option_cca_all nhm_include_cca; 277 enum nhm_divider_opt_all nhm_divider_opt; 278 /*Report*/ 279 u8 nhm_th[NHM_TH_NUM]; 280 u8 nhm_result[NHM_RPT_NUM]; 281 u8 nhm_wgt[NHM_RPT_NUM]; 282 u16 nhm_period; /* @4us per unit */ 283 u8 nhm_igi; 284 u8 nhm_manual_ctrl; 285 u8 nhm_ratio; /*@1% per nuit, it means the interference igi can't overcome.*/ 286 u8 nhm_env_ratio; /*exclude nhm_r[0] above -80dBm or first cluster under -80dBm*/ 287 u8 nhm_rpt_sum; 288 u8 nhm_set_lv; 289 boolean nhm_ongoing; 290 u8 nhm_rpt_stamp; 291 u8 nhm_level; /*including r[0]~r[10]*/ 292 u8 nhm_level_valid; 293 u8 nhm_pwr; /*including r[0]~r[11]*/ 294 #ifdef NHM_DYM_PW_TH_SUPPORT 295 boolean nhm_dym_pw_th_en; 296 boolean dym_pwth_manual_ctrl; 297 u8 pw_th_rf20_ori; 298 u8 pw_th_rf20_cur; 299 u8 nhm_pw_th_max; 300 u8 nhm_period_decre; 301 u8 nhm_sl_pw_th; 302 #endif 303 #endif 304 305 #ifdef CLM_SUPPORT 306 enum clm_application clm_app; 307 u8 clm_manual_ctrl; 308 u8 clm_set_lv; 309 boolean clm_ongoing; 310 u16 clm_period; /* @4us per unit */ 311 u16 clm_result; 312 u8 clm_ratio; 313 u32 clm_fw_result_acc; 314 u8 clm_fw_result_cnt; 315 enum clm_monitor_mode clm_mntr_mode; 316 u8 clm_rpt_stamp; 317 #endif 318 #ifdef FAHM_SUPPORT 319 enum fahm_application fahm_app; 320 boolean fahm_ongoing; 321 u8 fahm_numer_opt; 322 u8 fahm_denom_opt; 323 boolean fahm_inclu_cck; 324 u8 fahm_th[NHM_TH_NUM]; 325 u16 fahm_result[NHM_RPT_NUM]; 326 u16 fahm_result_sum; 327 u16 fahm_denom_result; 328 u16 fahm_period; /*unit: 4us*/ 329 u8 fahm_igi; 330 u8 fahm_manual_ctrl; 331 u8 fahm_set_lv; 332 u8 fahm_rpt_stamp; 333 u8 fahm_pwr; /*including r[0]~r[11]*/ 334 u8 fahm_ratio; 335 u8 fahm_denom_ratio; 336 #endif 337 #ifdef IFS_CLM_SUPPORT 338 enum ifs_clm_application ifs_clm_app; 339 /*Control*/ 340 enum phydm_ifs_clm_unit ifs_clm_ctrl_unit; /*4,8,12,16us per unit*/ 341 u16 ifs_clm_period; 342 boolean ifs_clm_th_en[IFS_CLM_NUM]; 343 u16 ifs_clm_th_low[IFS_CLM_NUM]; 344 u16 ifs_clm_th_high[IFS_CLM_NUM]; 345 /*Flow control*/ 346 u8 ifs_clm_set_lv; 347 u8 ifs_clm_manual_ctrl; 348 boolean ifs_clm_ongoing; 349 /*Report*/ 350 u8 ifs_clm_rpt_stamp; 351 u16 ifs_clm_tx; 352 u16 ifs_clm_edcca_excl_cca; 353 u16 ifs_clm_ofdmfa; 354 u16 ifs_clm_ofdmcca_excl_fa; 355 u16 ifs_clm_cckfa; 356 u16 ifs_clm_cckcca_excl_fa; 357 u8 ifs_clm_his[IFS_CLM_NUM]; /*trx_neg_edge to CCA/FA posedge per times*/ 358 u16 ifs_clm_total_cca; 359 u16 ifs_clm_avg[IFS_CLM_NUM]; /*4,8,12,16us per unit*/ 360 u16 ifs_clm_avg_cca[IFS_CLM_NUM]; /*4,8,12,16us per unit*/ 361 u8 ifs_clm_tx_ratio; 362 u8 ifs_clm_edcca_excl_cca_ratio; 363 u8 ifs_clm_cck_fa_ratio; 364 u8 ifs_clm_cck_cca_excl_fa_ratio; 365 u8 ifs_clm_ofdm_fa_ratio; 366 u8 ifs_clm_ofdm_cca_excl_fa_ratio; 367 #endif 368 }; 369 370 /* @1 ============================================================ 371 * 1 Function Prototype 372 * 1 ============================================================ 373 */ 374 375 u8 phydm_env_mntr_get_802_11_k_rsni(void *dm_void, s8 rcpi, s8 anpi); 376 377 #ifdef FAHM_SUPPORT 378 void phydm_fahm_init(void *dm_void); 379 380 void phydm_fahm_dbg(void *dm_void, char input[][16], u32 *_used, char *output, 381 u32 *_out_len); 382 #endif 383 384 #ifdef NHM_SUPPORT 385 void phydm_nhm_dbg(void *dm_void, char input[][16], u32 *_used, char *output, 386 u32 *_out_len); 387 u8 phydm_get_igi(void *dm_void, enum bb_path path); 388 #endif 389 390 #ifdef CLM_SUPPORT 391 void phydm_clm_c2h_report_handler(void *dm_void, u8 *cmd_buf, u8 cmd_len); 392 393 void phydm_clm_dbg(void *dm_void, char input[][16], u32 *_used, char *output, 394 u32 *_out_len); 395 #endif 396 397 u8 phydm_env_mntr_trigger(void *dm_void, struct nhm_para_info *nhm_para, 398 struct clm_para_info *clm_para, 399 struct env_trig_rpt *rpt); 400 401 u8 phydm_env_mntr_result(void *dm_void, struct env_mntr_rpt *rpt); 402 403 void phydm_env_mntr_dbg(void *dm_void, char input[][16], u32 *_used, 404 char *output, u32 *_out_len); 405 406 #ifdef IFS_CLM_SUPPORT 407 void phydm_ifs_clm_dbg(void *dm_void, char input[][16], u32 *_used, 408 char *output, u32 *_out_len); 409 #endif 410 411 u8 phydm_enhance_mntr_trigger(void *dm_void, 412 struct nhm_para_info *nhm_para, 413 struct clm_para_info *clm_para, 414 struct fahm_para_info *fahm_para, 415 struct ifs_clm_para_info *ifs_clm_para, 416 struct enhance_mntr_trig_rpt *trig_rpt); 417 418 u8 phydm_enhance_mntr_result(void *dm_void, struct enhance_mntr_rpt *rpt); 419 420 void phydm_enhance_mntr_dbg(void *dm_void, char input[][16], u32 *_used, 421 char *output, u32 *_out_len); 422 423 void phydm_env_mntr_result_watchdog(void *dm_void); 424 425 void phydm_env_mntr_set_watchdog(void *dm_void); 426 427 void phydm_env_monitor_init(void *dm_void); 428 429 #endif 430