phydm_rssi_monitor.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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_SUPPORT_RSSI_MONITOR
  31. void phydm_rssi_monitor_h2c(void *dm_void, u8 macid)
  32. {
  33. struct dm_struct *dm = (struct dm_struct *)dm_void;
  34. struct ra_table *ra_t = &dm->dm_ra_table;
  35. struct cmn_sta_info *sta = dm->phydm_sta_info[macid];
  36. struct ra_sta_info *ra = NULL;
  37. #ifdef CONFIG_BEAMFORMING
  38. struct bf_cmn_info *bf = NULL;
  39. #endif
  40. u8 h2c[H2C_MAX_LENGTH] = {0};
  41. u8 stbc_en, ldpc_en;
  42. u8 bf_en = 0;
  43. u8 is_rx, is_tx;
  44. if (is_sta_active(sta)) {
  45. ra = &sta->ra_info;
  46. } else {
  47. PHYDM_DBG(dm, DBG_RSSI_MNTR, "[Warning] %s\n", __func__);
  48. return;
  49. }
  50. PHYDM_DBG(dm, DBG_RSSI_MNTR, "%s ======>\n", __func__);
  51. PHYDM_DBG(dm, DBG_RSSI_MNTR, "MACID=%d\n", sta->mac_id);
  52. is_rx = (ra->txrx_state == RX_STATE) ? 1 : 0;
  53. is_tx = (ra->txrx_state == TX_STATE) ? 1 : 0;
  54. stbc_en = (sta->stbc_en) ? 1 : 0;
  55. ldpc_en = (sta->ldpc_en) ? 1 : 0;
  56. #ifdef CONFIG_BEAMFORMING
  57. bf = &sta->bf_info;
  58. if ((bf->ht_beamform_cap & BEAMFORMING_HT_BEAMFORMEE_ENABLE) ||
  59. (bf->vht_beamform_cap & BEAMFORMING_VHT_BEAMFORMEE_ENABLE))
  60. bf_en = 1;
  61. #endif
  62. PHYDM_DBG(dm, DBG_RSSI_MNTR, "RA_th_ofst=(( %s%d ))\n",
  63. ((ra_t->ra_ofst_direc) ? "+" : "-"), ra_t->ra_th_ofst);
  64. h2c[0] = sta->mac_id;
  65. h2c[1] = 0;
  66. h2c[2] = sta->rssi_stat.rssi;
  67. h2c[3] = is_rx | (stbc_en << 1) |
  68. ((dm->noisy_decision & 0x1) << 2) | (bf_en << 6);
  69. h2c[4] = (ra_t->ra_th_ofst & 0x7f) |
  70. ((ra_t->ra_ofst_direc & 0x1) << 7);
  71. h2c[5] = 0;
  72. h2c[6] = 0;
  73. PHYDM_DBG(dm, DBG_RSSI_MNTR, "PHYDM h2c[0x42]=0x%x %x %x %x %x %x %x\n",
  74. h2c[6], h2c[5], h2c[4], h2c[3], h2c[2], h2c[1], h2c[0]);
  75. #if (RTL8188E_SUPPORT)
  76. if (dm->support_ic_type == ODM_RTL8188E)
  77. odm_ra_set_rssi_8188e(dm, sta->mac_id, sta->rssi_stat.rssi);
  78. else
  79. #endif
  80. {
  81. odm_fill_h2c_cmd(dm, ODM_H2C_RSSI_REPORT, H2C_MAX_LENGTH, h2c);
  82. }
  83. }
  84. void phydm_calculate_rssi_min_max(void *dm_void)
  85. {
  86. struct dm_struct *dm = (struct dm_struct *)dm_void;
  87. struct cmn_sta_info *sta;
  88. s8 rssi_max_tmp = 0, rssi_min_tmp = 100;
  89. u8 i;
  90. u8 sta_cnt = 0;
  91. if (!dm->is_linked)
  92. return;
  93. PHYDM_DBG(dm, DBG_RSSI_MNTR, "%s ======>\n", __func__);
  94. for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
  95. sta = dm->phydm_sta_info[i];
  96. if (is_sta_active(sta)) {
  97. sta_cnt++;
  98. if (sta->rssi_stat.rssi < rssi_min_tmp) {
  99. rssi_min_tmp = sta->rssi_stat.rssi;
  100. dm->rssi_min_macid = i;
  101. }
  102. if (sta->rssi_stat.rssi > rssi_max_tmp) {
  103. rssi_max_tmp = sta->rssi_stat.rssi;
  104. dm->rssi_max_macid = i;
  105. }
  106. /*@[Send RSSI to FW]*/
  107. if (!sta->ra_info.disable_ra)
  108. phydm_rssi_monitor_h2c(dm, i);
  109. if (sta_cnt == dm->number_linked_client)
  110. break;
  111. }
  112. }
  113. dm->pre_rssi_min = dm->rssi_min;
  114. dm->rssi_max = (u8)rssi_max_tmp;
  115. dm->rssi_min = (u8)rssi_min_tmp;
  116. }
  117. void phydm_rssi_monitor_check(void *dm_void)
  118. {
  119. struct dm_struct *dm = (struct dm_struct *)dm_void;
  120. if (!(dm->support_ability & ODM_BB_RSSI_MONITOR))
  121. return;
  122. /*@for AP watchdog period = 1 sec*/
  123. if ((dm->phydm_sys_up_time % 2) == 1)
  124. return;
  125. PHYDM_DBG(dm, DBG_RSSI_MNTR, "%s ======>\n", __func__);
  126. phydm_calculate_rssi_min_max(dm);
  127. PHYDM_DBG(dm, DBG_RSSI_MNTR, "RSSI {max, min} = {%d, %d}\n",
  128. dm->rssi_max, dm->rssi_min);
  129. }
  130. void phydm_rssi_monitor_init(void *dm_void)
  131. {
  132. struct dm_struct *dm = (struct dm_struct *)dm_void;
  133. struct ra_table *ra_tab = &dm->dm_ra_table;
  134. ra_tab->firstconnect = false;
  135. dm->pre_rssi_min = 0;
  136. dm->rssi_max = 0;
  137. dm->rssi_min = 0;
  138. }
  139. #endif