phydm_pow_train.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. * include files
  27. ************************************************************/
  28. #include "mp_precomp.h"
  29. #include "phydm_precomp.h"
  30. #ifdef PHYDM_POWER_TRAINING_SUPPORT
  31. void phydm_reset_pt_para(void *dm_void)
  32. {
  33. struct dm_struct *dm = (struct dm_struct *)dm_void;
  34. struct phydm_pow_train_stuc *pt_t = &dm->pow_train_table;
  35. pt_t->pow_train_score = 0;
  36. }
  37. void phydm_update_power_training_state(void *dm_void)
  38. {
  39. struct dm_struct *dm = (struct dm_struct *)dm_void;
  40. struct phydm_pow_train_stuc *pt_t = &dm->pow_train_table;
  41. struct phydm_fa_struct *fa_cnt = &dm->false_alm_cnt;
  42. struct ccx_info *ccx = &dm->dm_ccx_info;
  43. u32 pt_score_tmp = ENABLE_PT_SCORE;
  44. u32 crc_ok_cnt = 0;
  45. u32 cca_cnt = 0;
  46. /*@is_disable_power_training is the key to H2C to disable/enable PT*/
  47. /*@if is_disable_power_training == 1, it will use largest power*/
  48. if (!(dm->support_ability & ODM_BB_PWR_TRAIN) || !dm->is_linked) {
  49. dm->is_disable_power_training = true;
  50. phydm_reset_pt_para(dm);
  51. return;
  52. }
  53. PHYDM_DBG(dm, DBG_PWR_TRAIN, "%s ======>\n", __func__);
  54. if (pt_t->pt_state == DISABLE_POW_TRAIN) {
  55. dm->is_disable_power_training = true;
  56. phydm_reset_pt_para(dm);
  57. PHYDM_DBG(dm, DBG_PWR_TRAIN, "Disable PT\n");
  58. return;
  59. } else if (pt_t->pt_state == ENABLE_POW_TRAIN) {
  60. dm->is_disable_power_training = false;
  61. phydm_reset_pt_para(dm);
  62. PHYDM_DBG(dm, DBG_PWR_TRAIN, "Enable PT\n");
  63. return;
  64. } else if (pt_t->pt_state == DYNAMIC_POW_TRAIN) {
  65. PHYDM_DBG(dm, DBG_PWR_TRAIN, "Dynamic PT\n");
  66. /* @Compute score */
  67. crc_ok_cnt = dm->phy_dbg_info.num_qry_phy_status_ofdm +
  68. dm->phy_dbg_info.num_qry_phy_status_cck;
  69. cca_cnt = fa_cnt->cnt_cca_all;
  70. #if 0
  71. if (crc_ok_cnt > cca_cnt) { /*invalid situation*/
  72. pt_score_tmp = KEEP_PRE_PT_SCORE;
  73. return;
  74. } else if ((crc_ok_cnt + (crc_ok_cnt >> 1)) <= cca_cnt) {
  75. /* @???crc_ok <= (2/3)*cca */
  76. pt_score_tmp = DISABLE_PT_SCORE;
  77. dm->is_disable_power_training = true;
  78. } else if ((crc_ok_cnt + (crc_ok_cnt >> 2)) <= cca_cnt) {
  79. /* @???crc_ok <= (4/5)*cca */
  80. pt_score_tmp = KEEP_PRE_PT_SCORE;
  81. } else {
  82. /* @???crc_ok > (4/5)*cca */
  83. pt_score_tmp = ENABLE_PT_SCORE;
  84. dm->is_disable_power_training = false;
  85. }
  86. #endif
  87. if (ccx->nhm_ratio > 10) {
  88. pt_score_tmp = DISABLE_PT_SCORE;
  89. dm->is_disable_power_training = true;
  90. } else if (ccx->nhm_ratio < 5) {
  91. pt_score_tmp = ENABLE_PT_SCORE;
  92. dm->is_disable_power_training = false;
  93. } else {
  94. pt_score_tmp = KEEP_PRE_PT_SCORE;
  95. }
  96. PHYDM_DBG(dm, DBG_PWR_TRAIN,
  97. "pkt_cnt{ofdm,cck,all} = {%d, %d, %d}, cnt_cca_all=%d\n",
  98. dm->phy_dbg_info.num_qry_phy_status_ofdm,
  99. dm->phy_dbg_info.num_qry_phy_status_cck,
  100. crc_ok_cnt, cca_cnt);
  101. PHYDM_DBG(dm, DBG_PWR_TRAIN, "pt_score_tmp=%d\n", pt_score_tmp);
  102. /* smoothing */
  103. pt_t->pow_train_score = (pt_score_tmp << 4) +
  104. (pt_t->pow_train_score >> 1) +
  105. (pt_t->pow_train_score >> 2);
  106. pt_score_tmp = (pt_t->pow_train_score + 32) >> 6;
  107. PHYDM_DBG(dm, DBG_PWR_TRAIN,
  108. "pow_train_score = %d, score after smoothing = %d, is_disable_PT = %d\n",
  109. pt_t->pow_train_score, pt_score_tmp,
  110. dm->is_disable_power_training);
  111. } else {
  112. PHYDM_DBG(dm, DBG_PWR_TRAIN, "[%s]warning\n", __func__);
  113. }
  114. }
  115. void phydm_pow_train_debug(
  116. void *dm_void,
  117. char input[][16],
  118. u32 *_used,
  119. char *output,
  120. u32 *_out_len)
  121. {
  122. struct dm_struct *dm = (struct dm_struct *)dm_void;
  123. struct phydm_pow_train_stuc *pt_t = &dm->pow_train_table;
  124. char help[] = "-h";
  125. u32 var1[10] = {0};
  126. u32 used = *_used;
  127. u32 out_len = *_out_len;
  128. u32 i;
  129. if ((strcmp(input[1], help) == 0)) {
  130. PDM_SNPF(out_len, used, output + used, out_len - used,
  131. "0: Dynamic state\n");
  132. PDM_SNPF(out_len, used, output + used, out_len - used,
  133. "1: Enable PT\n");
  134. PDM_SNPF(out_len, used, output + used, out_len - used,
  135. "2: Disable PT\n");
  136. } else {
  137. for (i = 0; i < 10; i++) {
  138. if (input[i + 1])
  139. PHYDM_SSCANF(input[i + 1], DCMD_HEX, &var1[i]);
  140. }
  141. if (var1[0] == 0) {
  142. pt_t->pt_state = DYNAMIC_POW_TRAIN;
  143. PDM_SNPF(out_len, used, output + used, out_len - used,
  144. "Dynamic state\n");
  145. } else if (var1[0] == 1) {
  146. pt_t->pt_state = ENABLE_POW_TRAIN;
  147. PDM_SNPF(out_len, used, output + used, out_len - used,
  148. "Enable PT\n");
  149. } else if (var1[0] == 2) {
  150. pt_t->pt_state = DISABLE_POW_TRAIN;
  151. PDM_SNPF(out_len, used, output + used, out_len - used,
  152. "Disable PT\n");
  153. } else {
  154. PDM_SNPF(out_len, used, output + used, out_len - used,
  155. "Set Error\n");
  156. }
  157. }
  158. *_used = used;
  159. *_out_len = out_len;
  160. }
  161. #endif