1 /******************************************************************************
3 * Copyright(c) 2007 - 2017 Realtek Corporation.
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.
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
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
26 /*************************************************************
28 ************************************************************/
30 #include "mp_precomp.h"
31 #include "phydm_precomp.h"
33 #ifdef PHYDM_POWER_TRAINING_SUPPORT
34 void phydm_reset_pt_para(void *dm_void)
36 struct dm_struct *dm = (struct dm_struct *)dm_void;
37 struct phydm_pow_train_stuc *pt_t = &dm->pow_train_table;
39 pt_t->pow_train_score = 0;
42 void phydm_update_power_training_state(void *dm_void)
44 struct dm_struct *dm = (struct dm_struct *)dm_void;
45 struct phydm_pow_train_stuc *pt_t = &dm->pow_train_table;
46 struct phydm_fa_struct *fa_cnt = &dm->false_alm_cnt;
47 struct ccx_info *ccx = &dm->dm_ccx_info;
48 u32 pt_score_tmp = ENABLE_PT_SCORE;
52 /*@is_disable_power_training is the key to H2C to disable/enable PT*/
53 /*@if is_disable_power_training == 1, it will use largest power*/
54 if (!(dm->support_ability & ODM_BB_PWR_TRAIN) || !dm->is_linked) {
55 dm->is_disable_power_training = true;
56 phydm_reset_pt_para(dm);
60 PHYDM_DBG(dm, DBG_PWR_TRAIN, "%s ======>\n", __func__);
62 if (pt_t->pt_state == DISABLE_POW_TRAIN) {
63 dm->is_disable_power_training = true;
64 phydm_reset_pt_para(dm);
65 PHYDM_DBG(dm, DBG_PWR_TRAIN, "Disable PT\n");
68 } else if (pt_t->pt_state == ENABLE_POW_TRAIN) {
69 dm->is_disable_power_training = false;
70 phydm_reset_pt_para(dm);
71 PHYDM_DBG(dm, DBG_PWR_TRAIN, "Enable PT\n");
74 } else if (pt_t->pt_state == DYNAMIC_POW_TRAIN) {
75 PHYDM_DBG(dm, DBG_PWR_TRAIN, "Dynamic PT\n");
78 crc_ok_cnt = dm->phy_dbg_info.num_qry_phy_status_ofdm +
79 dm->phy_dbg_info.num_qry_phy_status_cck;
80 cca_cnt = fa_cnt->cnt_cca_all;
82 if (crc_ok_cnt > cca_cnt) { /*invalid situation*/
83 pt_score_tmp = KEEP_PRE_PT_SCORE;
85 } else if ((crc_ok_cnt + (crc_ok_cnt >> 1)) <= cca_cnt) {
86 /* @???crc_ok <= (2/3)*cca */
87 pt_score_tmp = DISABLE_PT_SCORE;
88 dm->is_disable_power_training = true;
89 } else if ((crc_ok_cnt + (crc_ok_cnt >> 2)) <= cca_cnt) {
90 /* @???crc_ok <= (4/5)*cca */
91 pt_score_tmp = KEEP_PRE_PT_SCORE;
93 /* @???crc_ok > (4/5)*cca */
94 pt_score_tmp = ENABLE_PT_SCORE;
95 dm->is_disable_power_training = false;
98 if (ccx->nhm_ratio > 10) {
99 pt_score_tmp = DISABLE_PT_SCORE;
100 dm->is_disable_power_training = true;
101 } else if (ccx->nhm_ratio < 5) {
102 pt_score_tmp = ENABLE_PT_SCORE;
103 dm->is_disable_power_training = false;
105 pt_score_tmp = KEEP_PRE_PT_SCORE;
108 PHYDM_DBG(dm, DBG_PWR_TRAIN,
109 "pkt_cnt{ofdm,cck,all} = {%d, %d, %d}, cnt_cca_all=%d\n",
110 dm->phy_dbg_info.num_qry_phy_status_ofdm,
111 dm->phy_dbg_info.num_qry_phy_status_cck,
112 crc_ok_cnt, cca_cnt);
114 PHYDM_DBG(dm, DBG_PWR_TRAIN, "pt_score_tmp=%d\n", pt_score_tmp);
117 pt_t->pow_train_score = (pt_score_tmp << 4) +
118 (pt_t->pow_train_score >> 1) +
119 (pt_t->pow_train_score >> 2);
121 pt_score_tmp = (pt_t->pow_train_score + 32) >> 6;
123 PHYDM_DBG(dm, DBG_PWR_TRAIN,
124 "pow_train_score = %d, score after smoothing = %d, is_disable_PT = %d\n",
125 pt_t->pow_train_score, pt_score_tmp,
126 dm->is_disable_power_training);
128 PHYDM_DBG(dm, DBG_PWR_TRAIN, "[%s]warning\n", __func__);
132 void phydm_pow_train_debug(
139 struct dm_struct *dm = (struct dm_struct *)dm_void;
140 struct phydm_pow_train_stuc *pt_t = &dm->pow_train_table;
144 u32 out_len = *_out_len;
147 if ((strcmp(input[1], help) == 0)) {
148 PDM_SNPF(out_len, used, output + used, out_len - used,
149 "0: Dynamic state\n");
150 PDM_SNPF(out_len, used, output + used, out_len - used,
152 PDM_SNPF(out_len, used, output + used, out_len - used,
156 for (i = 0; i < 10; i++) {
158 PHYDM_SSCANF(input[i + 1], DCMD_HEX, &var1[i]);
162 pt_t->pt_state = DYNAMIC_POW_TRAIN;
163 PDM_SNPF(out_len, used, output + used, out_len - used,
165 } else if (var1[0] == 1) {
166 pt_t->pt_state = ENABLE_POW_TRAIN;
167 PDM_SNPF(out_len, used, output + used, out_len - used,
169 } else if (var1[0] == 2) {
170 pt_t->pt_state = DISABLE_POW_TRAIN;
171 PDM_SNPF(out_len, used, output + used, out_len - used,
174 PDM_SNPF(out_len, used, output + used, out_len - used,