dm.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2014 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. #include "../wifi.h"
  26. #include "../base.h"
  27. #include "../pci.h"
  28. #include "../core.h"
  29. #include "reg.h"
  30. #include "def.h"
  31. #include "phy.h"
  32. #include "dm.h"
  33. #include "../rtl8723com/dm_common.h"
  34. #include "fw.h"
  35. #include "trx.h"
  36. #include "../btcoexist/rtl_btc.h"
  37. static const u32 ofdmswing_table[] = {
  38. 0x0b40002d, /* 0, -15.0dB */
  39. 0x0c000030, /* 1, -14.5dB */
  40. 0x0cc00033, /* 2, -14.0dB */
  41. 0x0d800036, /* 3, -13.5dB */
  42. 0x0e400039, /* 4, -13.0dB */
  43. 0x0f00003c, /* 5, -12.5dB */
  44. 0x10000040, /* 6, -12.0dB */
  45. 0x11000044, /* 7, -11.5dB */
  46. 0x12000048, /* 8, -11.0dB */
  47. 0x1300004c, /* 9, -10.5dB */
  48. 0x14400051, /* 10, -10.0dB */
  49. 0x15800056, /* 11, -9.5dB */
  50. 0x16c0005b, /* 12, -9.0dB */
  51. 0x18000060, /* 13, -8.5dB */
  52. 0x19800066, /* 14, -8.0dB */
  53. 0x1b00006c, /* 15, -7.5dB */
  54. 0x1c800072, /* 16, -7.0dB */
  55. 0x1e400079, /* 17, -6.5dB */
  56. 0x20000080, /* 18, -6.0dB */
  57. 0x22000088, /* 19, -5.5dB */
  58. 0x24000090, /* 20, -5.0dB */
  59. 0x26000098, /* 21, -4.5dB */
  60. 0x288000a2, /* 22, -4.0dB */
  61. 0x2ac000ab, /* 23, -3.5dB */
  62. 0x2d4000b5, /* 24, -3.0dB */
  63. 0x300000c0, /* 25, -2.5dB */
  64. 0x32c000cb, /* 26, -2.0dB */
  65. 0x35c000d7, /* 27, -1.5dB */
  66. 0x390000e4, /* 28, -1.0dB */
  67. 0x3c8000f2, /* 29, -0.5dB */
  68. 0x40000100, /* 30, +0dB */
  69. 0x43c0010f, /* 31, +0.5dB */
  70. 0x47c0011f, /* 32, +1.0dB */
  71. 0x4c000130, /* 33, +1.5dB */
  72. 0x50800142, /* 34, +2.0dB */
  73. 0x55400155, /* 35, +2.5dB */
  74. 0x5a400169, /* 36, +3.0dB */
  75. 0x5fc0017f, /* 37, +3.5dB */
  76. 0x65400195, /* 38, +4.0dB */
  77. 0x6b8001ae, /* 39, +4.5dB */
  78. 0x71c001c7, /* 40, +5.0dB */
  79. 0x788001e2, /* 41, +5.5dB */
  80. 0x7f8001fe /* 42, +6.0dB */
  81. };
  82. static const u8 cckswing_table_ch1ch13[CCK_TABLE_SIZE][8] = {
  83. {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}, /* 0, -16.0dB */
  84. {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /* 1, -15.5dB */
  85. {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 2, -15.0dB */
  86. {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 3, -14.5dB */
  87. {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 4, -14.0dB */
  88. {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 5, -13.5dB */
  89. {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /* 6, -13.0dB */
  90. {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /* 7, -12.5dB */
  91. {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /* 8, -12.0dB */
  92. {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /* 9, -11.5dB */
  93. {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 10, -11.0dB */
  94. {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 11, -10.5dB */
  95. {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 12, -10.0dB */
  96. {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 13, -9.5dB */
  97. {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 14, -9.0dB */
  98. {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /* 15, -8.5dB */
  99. {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 16, -8.0dB */
  100. {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /* 17, -7.5dB */
  101. {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 18, -7.0dB */
  102. {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /* 19, -6.5dB */
  103. {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /* 20, -6.0dB */
  104. {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /* 21, -5.5dB */
  105. {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 22, -5.0dB */
  106. {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /* 23, -4.5dB */
  107. {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 24, -4.0dB */
  108. {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /* 25, -3.5dB */
  109. {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 26, -3.0dB */
  110. {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /* 27, -2.5dB */
  111. {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 28, -2.0dB */
  112. {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /* 29, -1.5dB */
  113. {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 30, -1.0dB */
  114. {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /* 31, -0.5dB */
  115. {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04} /* 32, +0dB */
  116. };
  117. static const u8 cckswing_table_ch14[CCK_TABLE_SIZE][8] = {
  118. {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}, /* 0, -16.0dB */
  119. {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 1, -15.5dB */
  120. {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 2, -15.0dB */
  121. {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 3, -14.5dB */
  122. {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 4, -14.0dB */
  123. {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 5, -13.5dB */
  124. {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 6, -13.0dB */
  125. {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 7, -12.5dB */
  126. {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 8, -12.0dB */
  127. {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 9, -11.5dB */
  128. {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 10, -11.0dB */
  129. {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 11, -10.5dB */
  130. {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 12, -10.0dB */
  131. {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 13, -9.5dB */
  132. {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 14, -9.0dB */
  133. {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 15, -8.5dB */
  134. {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 16, -8.0dB */
  135. {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 17, -7.5dB */
  136. {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 18, -7.0dB */
  137. {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /* 19, -6.5dB */
  138. {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 20, -6.0dB */
  139. {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 21, -5.5dB */
  140. {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 22, -5.0dB */
  141. {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /* 23, -4.5dB */
  142. {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 24, -4.0dB */
  143. {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /* 25, -3.5dB */
  144. {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 26, -3.0dB */
  145. {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /* 27, -2.5dB */
  146. {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 28, -2.0dB */
  147. {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /* 29, -1.5dB */
  148. {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 30, -1.0dB */
  149. {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /* 31, -0.5dB */
  150. {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00} /* 32, +0dB */
  151. };
  152. static const u32 edca_setting_dl[PEER_MAX] = {
  153. 0xa44f, /* 0 UNKNOWN */
  154. 0x5ea44f, /* 1 REALTEK_90 */
  155. 0x5e4322, /* 2 REALTEK_92SE */
  156. 0x5ea42b, /* 3 BROAD */
  157. 0xa44f, /* 4 RAL */
  158. 0xa630, /* 5 ATH */
  159. 0x5ea630, /* 6 CISCO */
  160. 0x5ea42b, /* 7 MARVELL */
  161. };
  162. static const u32 edca_setting_ul[PEER_MAX] = {
  163. 0x5e4322, /* 0 UNKNOWN */
  164. 0xa44f, /* 1 REALTEK_90 */
  165. 0x5ea44f, /* 2 REALTEK_92SE */
  166. 0x5ea32b, /* 3 BROAD */
  167. 0x5ea422, /* 4 RAL */
  168. 0x5ea322, /* 5 ATH */
  169. 0x3ea430, /* 6 CISCO */
  170. 0x5ea44f, /* 7 MARV */
  171. };
  172. void rtl8723be_dm_txpower_track_adjust(struct ieee80211_hw *hw, u8 type,
  173. u8 *pdirection, u32 *poutwrite_val)
  174. {
  175. struct rtl_priv *rtlpriv = rtl_priv(hw);
  176. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  177. u8 pwr_val = 0;
  178. u8 ofdm_base = rtlpriv->dm.swing_idx_ofdm_base[RF90_PATH_A];
  179. u8 ofdm_val = rtlpriv->dm.swing_idx_ofdm[RF90_PATH_A];
  180. u8 cck_base = rtldm->swing_idx_cck_base;
  181. u8 cck_val = rtldm->swing_idx_cck;
  182. if (type == 0) {
  183. if (ofdm_val <= ofdm_base) {
  184. *pdirection = 1;
  185. pwr_val = ofdm_base - ofdm_val;
  186. } else {
  187. *pdirection = 2;
  188. pwr_val = ofdm_val - ofdm_base;
  189. }
  190. } else if (type == 1) {
  191. if (cck_val <= cck_base) {
  192. *pdirection = 1;
  193. pwr_val = cck_base - cck_val;
  194. } else {
  195. *pdirection = 2;
  196. pwr_val = cck_val - cck_base;
  197. }
  198. }
  199. if (pwr_val >= TXPWRTRACK_MAX_IDX && (*pdirection == 1))
  200. pwr_val = TXPWRTRACK_MAX_IDX;
  201. *poutwrite_val = pwr_val | (pwr_val << 8) |
  202. (pwr_val << 16) | (pwr_val << 24);
  203. }
  204. void rtl8723be_dm_init_rate_adaptive_mask(struct ieee80211_hw *hw)
  205. {
  206. struct rtl_priv *rtlpriv = rtl_priv(hw);
  207. struct rate_adaptive *p_ra = &rtlpriv->ra;
  208. p_ra->ratr_state = DM_RATR_STA_INIT;
  209. p_ra->pre_ratr_state = DM_RATR_STA_INIT;
  210. if (rtlpriv->dm.dm_type == DM_TYPE_BYDRIVER)
  211. rtlpriv->dm.useramask = true;
  212. else
  213. rtlpriv->dm.useramask = false;
  214. p_ra->high_rssi_thresh_for_ra = 50;
  215. p_ra->low_rssi_thresh_for_ra40m = 20;
  216. }
  217. static void rtl8723be_dm_init_txpower_tracking(struct ieee80211_hw *hw)
  218. {
  219. struct rtl_priv *rtlpriv = rtl_priv(hw);
  220. rtlpriv->dm.txpower_tracking = true;
  221. rtlpriv->dm.txpower_track_control = true;
  222. rtlpriv->dm.thermalvalue = 0;
  223. rtlpriv->dm.ofdm_index[0] = 30;
  224. rtlpriv->dm.cck_index = 20;
  225. rtlpriv->dm.swing_idx_cck_base = rtlpriv->dm.cck_index;
  226. rtlpriv->dm.swing_idx_ofdm_base[0] = rtlpriv->dm.ofdm_index[0];
  227. rtlpriv->dm.delta_power_index[RF90_PATH_A] = 0;
  228. rtlpriv->dm.delta_power_index_last[RF90_PATH_A] = 0;
  229. rtlpriv->dm.power_index_offset[RF90_PATH_A] = 0;
  230. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  231. " rtlpriv->dm.txpower_tracking = %d\n",
  232. rtlpriv->dm.txpower_tracking);
  233. }
  234. static void rtl8723be_dm_init_dynamic_atc_switch(struct ieee80211_hw *hw)
  235. {
  236. struct rtl_priv *rtlpriv = rtl_priv(hw);
  237. rtlpriv->dm.crystal_cap = rtlpriv->efuse.crystalcap;
  238. rtlpriv->dm.atc_status = rtl_get_bbreg(hw, ROFDM1_CFOTRACKING, 0x800);
  239. rtlpriv->dm.cfo_threshold = CFO_THRESHOLD_XTAL;
  240. }
  241. void rtl8723be_dm_init(struct ieee80211_hw *hw)
  242. {
  243. struct rtl_priv *rtlpriv = rtl_priv(hw);
  244. u32 cur_igvalue = rtl_get_bbreg(hw, ROFDM0_XAAGCCORE1, 0x7f);
  245. rtlpriv->dm.dm_type = DM_TYPE_BYDRIVER;
  246. rtl_dm_diginit(hw, cur_igvalue);
  247. rtl8723be_dm_init_rate_adaptive_mask(hw);
  248. rtl8723_dm_init_edca_turbo(hw);
  249. rtl8723_dm_init_dynamic_bb_powersaving(hw);
  250. rtl8723_dm_init_dynamic_txpower(hw);
  251. rtl8723be_dm_init_txpower_tracking(hw);
  252. rtl8723be_dm_init_dynamic_atc_switch(hw);
  253. }
  254. static void rtl8723be_dm_find_minimum_rssi(struct ieee80211_hw *hw)
  255. {
  256. struct rtl_priv *rtlpriv = rtl_priv(hw);
  257. struct dig_t *rtl_dm_dig = &rtlpriv->dm_digtable;
  258. struct rtl_mac *mac = rtl_mac(rtlpriv);
  259. /* Determine the minimum RSSI */
  260. if ((mac->link_state < MAC80211_LINKED) &&
  261. (rtlpriv->dm.entry_min_undec_sm_pwdb == 0)) {
  262. rtl_dm_dig->min_undec_pwdb_for_dm = 0;
  263. RT_TRACE(rtlpriv, COMP_BB_POWERSAVING, DBG_LOUD,
  264. "Not connected to any\n");
  265. }
  266. if (mac->link_state >= MAC80211_LINKED) {
  267. if (mac->opmode == NL80211_IFTYPE_AP ||
  268. mac->opmode == NL80211_IFTYPE_ADHOC) {
  269. rtl_dm_dig->min_undec_pwdb_for_dm =
  270. rtlpriv->dm.entry_min_undec_sm_pwdb;
  271. RT_TRACE(rtlpriv, COMP_BB_POWERSAVING, DBG_LOUD,
  272. "AP Client PWDB = 0x%lx\n",
  273. rtlpriv->dm.entry_min_undec_sm_pwdb);
  274. } else {
  275. rtl_dm_dig->min_undec_pwdb_for_dm =
  276. rtlpriv->dm.undec_sm_pwdb;
  277. RT_TRACE(rtlpriv, COMP_BB_POWERSAVING, DBG_LOUD,
  278. "STA Default Port PWDB = 0x%x\n",
  279. rtl_dm_dig->min_undec_pwdb_for_dm);
  280. }
  281. } else {
  282. rtl_dm_dig->min_undec_pwdb_for_dm =
  283. rtlpriv->dm.entry_min_undec_sm_pwdb;
  284. RT_TRACE(rtlpriv, COMP_BB_POWERSAVING, DBG_LOUD,
  285. "AP Ext Port or disconnect PWDB = 0x%x\n",
  286. rtl_dm_dig->min_undec_pwdb_for_dm);
  287. }
  288. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD, "MinUndecoratedPWDBForDM =%d\n",
  289. rtl_dm_dig->min_undec_pwdb_for_dm);
  290. }
  291. static void rtl8723be_dm_check_rssi_monitor(struct ieee80211_hw *hw)
  292. {
  293. struct rtl_priv *rtlpriv = rtl_priv(hw);
  294. struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
  295. struct rtl_sta_info *drv_priv;
  296. u8 h2c_parameter[3] = { 0 };
  297. long tmp_entry_max_pwdb = 0, tmp_entry_min_pwdb = 0xff;
  298. /* AP & ADHOC & MESH */
  299. spin_lock_bh(&rtlpriv->locks.entry_list_lock);
  300. list_for_each_entry(drv_priv, &rtlpriv->entry_list, list) {
  301. if (drv_priv->rssi_stat.undec_sm_pwdb <
  302. tmp_entry_min_pwdb)
  303. tmp_entry_min_pwdb =
  304. drv_priv->rssi_stat.undec_sm_pwdb;
  305. if (drv_priv->rssi_stat.undec_sm_pwdb >
  306. tmp_entry_max_pwdb)
  307. tmp_entry_max_pwdb =
  308. drv_priv->rssi_stat.undec_sm_pwdb;
  309. }
  310. spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
  311. /* If associated entry is found */
  312. if (tmp_entry_max_pwdb != 0) {
  313. rtlpriv->dm.entry_max_undec_sm_pwdb =
  314. tmp_entry_max_pwdb;
  315. RTPRINT(rtlpriv, FDM, DM_PWDB,
  316. "EntryMaxPWDB = 0x%lx(%ld)\n",
  317. tmp_entry_max_pwdb, tmp_entry_max_pwdb);
  318. } else {
  319. rtlpriv->dm.entry_max_undec_sm_pwdb = 0;
  320. }
  321. /* If associated entry is found */
  322. if (tmp_entry_min_pwdb != 0xff) {
  323. rtlpriv->dm.entry_min_undec_sm_pwdb =
  324. tmp_entry_min_pwdb;
  325. RTPRINT(rtlpriv, FDM, DM_PWDB,
  326. "EntryMinPWDB = 0x%lx(%ld)\n",
  327. tmp_entry_min_pwdb, tmp_entry_min_pwdb);
  328. } else {
  329. rtlpriv->dm.entry_min_undec_sm_pwdb = 0;
  330. }
  331. /* Indicate Rx signal strength to FW. */
  332. if (rtlpriv->dm.useramask) {
  333. h2c_parameter[2] =
  334. (u8)(rtlpriv->dm.undec_sm_pwdb & 0xFF);
  335. h2c_parameter[1] = 0x20;
  336. h2c_parameter[0] = 0;
  337. rtl8723be_fill_h2c_cmd(hw, H2C_RSSIBE_REPORT, 3, h2c_parameter);
  338. } else {
  339. rtl_write_byte(rtlpriv, 0x4fe,
  340. rtlpriv->dm.undec_sm_pwdb);
  341. }
  342. rtl8723be_dm_find_minimum_rssi(hw);
  343. dm_digtable->rssi_val_min =
  344. rtlpriv->dm_digtable.min_undec_pwdb_for_dm;
  345. }
  346. void rtl8723be_dm_write_dig(struct ieee80211_hw *hw, u8 current_igi)
  347. {
  348. struct rtl_priv *rtlpriv = rtl_priv(hw);
  349. struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
  350. if (dm_digtable->stop_dig)
  351. return;
  352. if (dm_digtable->cur_igvalue != current_igi) {
  353. rtl_set_bbreg(hw, ROFDM0_XAAGCCORE1, 0x7f, current_igi);
  354. if (rtlpriv->phy.rf_type != RF_1T1R)
  355. rtl_set_bbreg(hw, ROFDM0_XBAGCCORE1,
  356. 0x7f, current_igi);
  357. }
  358. dm_digtable->pre_igvalue = dm_digtable->cur_igvalue;
  359. dm_digtable->cur_igvalue = current_igi;
  360. }
  361. static void rtl8723be_dm_dig(struct ieee80211_hw *hw)
  362. {
  363. struct rtl_priv *rtlpriv = rtl_priv(hw);
  364. struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
  365. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  366. u8 dig_min_0, dig_maxofmin;
  367. bool bfirstconnect, bfirstdisconnect;
  368. u8 dm_dig_max, dm_dig_min;
  369. u8 current_igi = dm_digtable->cur_igvalue;
  370. u8 offset;
  371. /* AP,BT */
  372. if (mac->act_scanning)
  373. return;
  374. dig_min_0 = dm_digtable->dig_min_0;
  375. bfirstconnect = (mac->link_state >= MAC80211_LINKED) &&
  376. !dm_digtable->media_connect_0;
  377. bfirstdisconnect = (mac->link_state < MAC80211_LINKED) &&
  378. (dm_digtable->media_connect_0);
  379. dm_dig_max = 0x5a;
  380. dm_dig_min = DM_DIG_MIN;
  381. dig_maxofmin = DM_DIG_MAX_AP;
  382. if (mac->link_state >= MAC80211_LINKED) {
  383. if ((dm_digtable->rssi_val_min + 10) > dm_dig_max)
  384. dm_digtable->rx_gain_max = dm_dig_max;
  385. else if ((dm_digtable->rssi_val_min + 10) < dm_dig_min)
  386. dm_digtable->rx_gain_max = dm_dig_min;
  387. else
  388. dm_digtable->rx_gain_max =
  389. dm_digtable->rssi_val_min + 10;
  390. if (rtlpriv->dm.one_entry_only) {
  391. offset = 12;
  392. if (dm_digtable->rssi_val_min - offset < dm_dig_min)
  393. dig_min_0 = dm_dig_min;
  394. else if (dm_digtable->rssi_val_min - offset >
  395. dig_maxofmin)
  396. dig_min_0 = dig_maxofmin;
  397. else
  398. dig_min_0 =
  399. dm_digtable->rssi_val_min - offset;
  400. } else {
  401. dig_min_0 = dm_dig_min;
  402. }
  403. } else {
  404. dm_digtable->rx_gain_max = dm_dig_max;
  405. dig_min_0 = dm_dig_min;
  406. RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD, "no link\n");
  407. }
  408. if (rtlpriv->falsealm_cnt.cnt_all > 10000) {
  409. if (dm_digtable->large_fa_hit != 3)
  410. dm_digtable->large_fa_hit++;
  411. if (dm_digtable->forbidden_igi < current_igi) {
  412. dm_digtable->forbidden_igi = current_igi;
  413. dm_digtable->large_fa_hit = 1;
  414. }
  415. if (dm_digtable->large_fa_hit >= 3) {
  416. if ((dm_digtable->forbidden_igi + 1) >
  417. dm_digtable->rx_gain_max)
  418. dm_digtable->rx_gain_min =
  419. dm_digtable->rx_gain_max;
  420. else
  421. dm_digtable->rx_gain_min =
  422. dm_digtable->forbidden_igi + 1;
  423. dm_digtable->recover_cnt = 3600;
  424. }
  425. } else {
  426. if (dm_digtable->recover_cnt != 0) {
  427. dm_digtable->recover_cnt--;
  428. } else {
  429. if (dm_digtable->large_fa_hit < 3) {
  430. if ((dm_digtable->forbidden_igi - 1) <
  431. dig_min_0) {
  432. dm_digtable->forbidden_igi =
  433. dig_min_0;
  434. dm_digtable->rx_gain_min =
  435. dig_min_0;
  436. } else {
  437. dm_digtable->forbidden_igi--;
  438. dm_digtable->rx_gain_min =
  439. dm_digtable->forbidden_igi + 1;
  440. }
  441. } else {
  442. dm_digtable->large_fa_hit = 0;
  443. }
  444. }
  445. }
  446. if (dm_digtable->rx_gain_min > dm_digtable->rx_gain_max)
  447. dm_digtable->rx_gain_min = dm_digtable->rx_gain_max;
  448. if (mac->link_state >= MAC80211_LINKED) {
  449. if (bfirstconnect) {
  450. if (dm_digtable->rssi_val_min <= dig_maxofmin)
  451. current_igi = dm_digtable->rssi_val_min;
  452. else
  453. current_igi = dig_maxofmin;
  454. dm_digtable->large_fa_hit = 0;
  455. } else {
  456. if (rtlpriv->falsealm_cnt.cnt_all > DM_DIG_FA_TH2)
  457. current_igi += 4;
  458. else if (rtlpriv->falsealm_cnt.cnt_all > DM_DIG_FA_TH1)
  459. current_igi += 2;
  460. else if (rtlpriv->falsealm_cnt.cnt_all < DM_DIG_FA_TH0)
  461. current_igi -= 2;
  462. }
  463. } else {
  464. if (bfirstdisconnect) {
  465. current_igi = dm_digtable->rx_gain_min;
  466. } else {
  467. if (rtlpriv->falsealm_cnt.cnt_all > 10000)
  468. current_igi += 4;
  469. else if (rtlpriv->falsealm_cnt.cnt_all > 8000)
  470. current_igi += 2;
  471. else if (rtlpriv->falsealm_cnt.cnt_all < 500)
  472. current_igi -= 2;
  473. }
  474. }
  475. if (current_igi > dm_digtable->rx_gain_max)
  476. current_igi = dm_digtable->rx_gain_max;
  477. else if (current_igi < dm_digtable->rx_gain_min)
  478. current_igi = dm_digtable->rx_gain_min;
  479. rtl8723be_dm_write_dig(hw, current_igi);
  480. dm_digtable->media_connect_0 =
  481. ((mac->link_state >= MAC80211_LINKED) ? true : false);
  482. dm_digtable->dig_min_0 = dig_min_0;
  483. }
  484. static void rtl8723be_dm_false_alarm_counter_statistics(
  485. struct ieee80211_hw *hw)
  486. {
  487. u32 ret_value;
  488. struct rtl_priv *rtlpriv = rtl_priv(hw);
  489. struct false_alarm_statistics *falsealm_cnt = &rtlpriv->falsealm_cnt;
  490. rtl_set_bbreg(hw, DM_REG_OFDM_FA_HOLDC_11N, BIT(31), 1);
  491. rtl_set_bbreg(hw, DM_REG_OFDM_FA_RSTD_11N, BIT(31), 1);
  492. ret_value = rtl_get_bbreg(hw, DM_REG_OFDM_FA_TYPE1_11N, MASKDWORD);
  493. falsealm_cnt->cnt_fast_fsync_fail = ret_value & 0xffff;
  494. falsealm_cnt->cnt_sb_search_fail = (ret_value & 0xffff0000) >> 16;
  495. ret_value = rtl_get_bbreg(hw, DM_REG_OFDM_FA_TYPE2_11N, MASKDWORD);
  496. falsealm_cnt->cnt_ofdm_cca = ret_value & 0xffff;
  497. falsealm_cnt->cnt_parity_fail = (ret_value & 0xffff0000) >> 16;
  498. ret_value = rtl_get_bbreg(hw, DM_REG_OFDM_FA_TYPE3_11N, MASKDWORD);
  499. falsealm_cnt->cnt_rate_illegal = ret_value & 0xffff;
  500. falsealm_cnt->cnt_crc8_fail = (ret_value & 0xffff0000) >> 16;
  501. ret_value = rtl_get_bbreg(hw, DM_REG_OFDM_FA_TYPE4_11N, MASKDWORD);
  502. falsealm_cnt->cnt_mcs_fail = ret_value & 0xffff;
  503. falsealm_cnt->cnt_ofdm_fail = falsealm_cnt->cnt_parity_fail +
  504. falsealm_cnt->cnt_rate_illegal +
  505. falsealm_cnt->cnt_crc8_fail +
  506. falsealm_cnt->cnt_mcs_fail +
  507. falsealm_cnt->cnt_fast_fsync_fail +
  508. falsealm_cnt->cnt_sb_search_fail;
  509. rtl_set_bbreg(hw, DM_REG_CCK_FA_RST_11N, BIT(12), 1);
  510. rtl_set_bbreg(hw, DM_REG_CCK_FA_RST_11N, BIT(14), 1);
  511. ret_value = rtl_get_bbreg(hw, DM_REG_CCK_FA_RST_11N, MASKBYTE0);
  512. falsealm_cnt->cnt_cck_fail = ret_value;
  513. ret_value = rtl_get_bbreg(hw, DM_REG_CCK_FA_MSB_11N, MASKBYTE3);
  514. falsealm_cnt->cnt_cck_fail += (ret_value & 0xff) << 8;
  515. ret_value = rtl_get_bbreg(hw, DM_REG_CCK_CCA_CNT_11N, MASKDWORD);
  516. falsealm_cnt->cnt_cck_cca = ((ret_value & 0xff) << 8) |
  517. ((ret_value & 0xff00) >> 8);
  518. falsealm_cnt->cnt_all = falsealm_cnt->cnt_fast_fsync_fail +
  519. falsealm_cnt->cnt_sb_search_fail +
  520. falsealm_cnt->cnt_parity_fail +
  521. falsealm_cnt->cnt_rate_illegal +
  522. falsealm_cnt->cnt_crc8_fail +
  523. falsealm_cnt->cnt_mcs_fail +
  524. falsealm_cnt->cnt_cck_fail;
  525. falsealm_cnt->cnt_cca_all = falsealm_cnt->cnt_ofdm_cca +
  526. falsealm_cnt->cnt_cck_cca;
  527. rtl_set_bbreg(hw, DM_REG_OFDM_FA_RSTC_11N, BIT(31), 1);
  528. rtl_set_bbreg(hw, DM_REG_OFDM_FA_RSTC_11N, BIT(31), 0);
  529. rtl_set_bbreg(hw, DM_REG_OFDM_FA_RSTD_11N, BIT(27), 1);
  530. rtl_set_bbreg(hw, DM_REG_OFDM_FA_RSTD_11N, BIT(27), 0);
  531. rtl_set_bbreg(hw, DM_REG_OFDM_FA_HOLDC_11N, BIT(31), 0);
  532. rtl_set_bbreg(hw, DM_REG_OFDM_FA_RSTD_11N, BIT(31), 0);
  533. rtl_set_bbreg(hw, DM_REG_CCK_FA_RST_11N, BIT(13) | BIT(12), 0);
  534. rtl_set_bbreg(hw, DM_REG_CCK_FA_RST_11N, BIT(13) | BIT(12), 2);
  535. rtl_set_bbreg(hw, DM_REG_CCK_FA_RST_11N, BIT(15) | BIT(14), 0);
  536. rtl_set_bbreg(hw, DM_REG_CCK_FA_RST_11N, BIT(15) | BIT(14), 2);
  537. RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE,
  538. "cnt_parity_fail = %d, cnt_rate_illegal = %d, cnt_crc8_fail = %d, cnt_mcs_fail = %d\n",
  539. falsealm_cnt->cnt_parity_fail,
  540. falsealm_cnt->cnt_rate_illegal,
  541. falsealm_cnt->cnt_crc8_fail,
  542. falsealm_cnt->cnt_mcs_fail);
  543. RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE,
  544. "cnt_ofdm_fail = %x, cnt_cck_fail = %x, cnt_all = %x\n",
  545. falsealm_cnt->cnt_ofdm_fail,
  546. falsealm_cnt->cnt_cck_fail,
  547. falsealm_cnt->cnt_all);
  548. }
  549. static void rtl8723be_dm_dynamic_txpower(struct ieee80211_hw *hw)
  550. {
  551. /* 8723BE does not support ODM_BB_DYNAMIC_TXPWR*/
  552. return;
  553. }
  554. static void rtl8723be_set_iqk_matrix(struct ieee80211_hw *hw, u8 ofdm_index,
  555. u8 rfpath, long iqk_result_x,
  556. long iqk_result_y)
  557. {
  558. long ele_a = 0, ele_d, ele_c = 0, value32;
  559. if (ofdm_index >= 43)
  560. ofdm_index = 43 - 1;
  561. ele_d = (ofdmswing_table[ofdm_index] & 0xFFC00000) >> 22;
  562. if (iqk_result_x != 0) {
  563. if ((iqk_result_x & 0x00000200) != 0)
  564. iqk_result_x = iqk_result_x | 0xFFFFFC00;
  565. ele_a = ((iqk_result_x * ele_d) >> 8) & 0x000003FF;
  566. if ((iqk_result_y & 0x00000200) != 0)
  567. iqk_result_y = iqk_result_y | 0xFFFFFC00;
  568. ele_c = ((iqk_result_y * ele_d) >> 8) & 0x000003FF;
  569. switch (rfpath) {
  570. case RF90_PATH_A:
  571. value32 = (ele_d << 22) |
  572. ((ele_c & 0x3F) << 16) | ele_a;
  573. rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, MASKDWORD,
  574. value32);
  575. value32 = (ele_c & 0x000003C0) >> 6;
  576. rtl_set_bbreg(hw, ROFDM0_XCTXAFE, MASKH4BITS, value32);
  577. value32 = ((iqk_result_x * ele_d) >> 7) & 0x01;
  578. rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(24),
  579. value32);
  580. break;
  581. default:
  582. break;
  583. }
  584. } else {
  585. switch (rfpath) {
  586. case RF90_PATH_A:
  587. rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, MASKDWORD,
  588. ofdmswing_table[ofdm_index]);
  589. rtl_set_bbreg(hw, ROFDM0_XCTXAFE, MASKH4BITS, 0x00);
  590. rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(24), 0x00);
  591. break;
  592. default:
  593. break;
  594. }
  595. }
  596. }
  597. static void rtl8723be_dm_tx_power_track_set_power(struct ieee80211_hw *hw,
  598. enum pwr_track_control_method method,
  599. u8 rfpath, u8 idx)
  600. {
  601. struct rtl_priv *rtlpriv = rtl_priv(hw);
  602. struct rtl_phy *rtlphy = &rtlpriv->phy;
  603. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  604. u8 swing_idx_ofdm_limit = 36;
  605. if (method == TXAGC) {
  606. rtl8723be_phy_set_txpower_level(hw, rtlphy->current_channel);
  607. } else if (method == BBSWING) {
  608. if (rtldm->swing_idx_cck >= CCK_TABLE_SIZE)
  609. rtldm->swing_idx_cck = CCK_TABLE_SIZE - 1;
  610. if (!rtldm->cck_inch14) {
  611. rtl_write_byte(rtlpriv, 0xa22,
  612. cckswing_table_ch1ch13[rtldm->swing_idx_cck][0]);
  613. rtl_write_byte(rtlpriv, 0xa23,
  614. cckswing_table_ch1ch13[rtldm->swing_idx_cck][1]);
  615. rtl_write_byte(rtlpriv, 0xa24,
  616. cckswing_table_ch1ch13[rtldm->swing_idx_cck][2]);
  617. rtl_write_byte(rtlpriv, 0xa25,
  618. cckswing_table_ch1ch13[rtldm->swing_idx_cck][3]);
  619. rtl_write_byte(rtlpriv, 0xa26,
  620. cckswing_table_ch1ch13[rtldm->swing_idx_cck][4]);
  621. rtl_write_byte(rtlpriv, 0xa27,
  622. cckswing_table_ch1ch13[rtldm->swing_idx_cck][5]);
  623. rtl_write_byte(rtlpriv, 0xa28,
  624. cckswing_table_ch1ch13[rtldm->swing_idx_cck][6]);
  625. rtl_write_byte(rtlpriv, 0xa29,
  626. cckswing_table_ch1ch13[rtldm->swing_idx_cck][7]);
  627. } else {
  628. rtl_write_byte(rtlpriv, 0xa22,
  629. cckswing_table_ch14[rtldm->swing_idx_cck][0]);
  630. rtl_write_byte(rtlpriv, 0xa23,
  631. cckswing_table_ch14[rtldm->swing_idx_cck][1]);
  632. rtl_write_byte(rtlpriv, 0xa24,
  633. cckswing_table_ch14[rtldm->swing_idx_cck][2]);
  634. rtl_write_byte(rtlpriv, 0xa25,
  635. cckswing_table_ch14[rtldm->swing_idx_cck][3]);
  636. rtl_write_byte(rtlpriv, 0xa26,
  637. cckswing_table_ch14[rtldm->swing_idx_cck][4]);
  638. rtl_write_byte(rtlpriv, 0xa27,
  639. cckswing_table_ch14[rtldm->swing_idx_cck][5]);
  640. rtl_write_byte(rtlpriv, 0xa28,
  641. cckswing_table_ch14[rtldm->swing_idx_cck][6]);
  642. rtl_write_byte(rtlpriv, 0xa29,
  643. cckswing_table_ch14[rtldm->swing_idx_cck][7]);
  644. }
  645. if (rfpath == RF90_PATH_A) {
  646. if (rtldm->swing_idx_ofdm[RF90_PATH_A] <
  647. swing_idx_ofdm_limit)
  648. swing_idx_ofdm_limit =
  649. rtldm->swing_idx_ofdm[RF90_PATH_A];
  650. rtl8723be_set_iqk_matrix(hw,
  651. rtldm->swing_idx_ofdm[rfpath], rfpath,
  652. rtlphy->iqk_matrix[idx].value[0][0],
  653. rtlphy->iqk_matrix[idx].value[0][1]);
  654. } else if (rfpath == RF90_PATH_B) {
  655. if (rtldm->swing_idx_ofdm[RF90_PATH_B] <
  656. swing_idx_ofdm_limit)
  657. swing_idx_ofdm_limit =
  658. rtldm->swing_idx_ofdm[RF90_PATH_B];
  659. rtl8723be_set_iqk_matrix(hw,
  660. rtldm->swing_idx_ofdm[rfpath], rfpath,
  661. rtlphy->iqk_matrix[idx].value[0][4],
  662. rtlphy->iqk_matrix[idx].value[0][5]);
  663. }
  664. } else {
  665. return;
  666. }
  667. }
  668. static void rtl8723be_dm_txpower_tracking_callback_thermalmeter(
  669. struct ieee80211_hw *hw)
  670. {
  671. struct rtl_priv *rtlpriv = rtl_priv(hw);
  672. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  673. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  674. u8 thermalvalue = 0, delta, delta_lck, delta_iqk;
  675. u8 thermalvalue_avg_count = 0;
  676. u32 thermalvalue_avg = 0;
  677. int i = 0;
  678. u8 ofdm_min_index = 6;
  679. u8 index_for_channel = 0;
  680. s8 delta_swing_table_idx_tup_a[TXSCALE_TABLE_SIZE] = {
  681. 0, 0, 1, 2, 2, 2, 3, 3, 3, 4, 5,
  682. 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 10,
  683. 10, 11, 11, 12, 12, 13, 14, 15};
  684. s8 delta_swing_table_idx_tdown_a[TXSCALE_TABLE_SIZE] = {
  685. 0, 0, 1, 2, 2, 2, 3, 3, 3, 4, 5,
  686. 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9,
  687. 9, 10, 10, 11, 12, 13, 14, 15};
  688. /*Initilization ( 7 steps in total )*/
  689. rtlpriv->dm.txpower_trackinginit = true;
  690. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  691. "rtl8723be_dm_txpower_tracking_callback_thermalmeter\n");
  692. thermalvalue = (u8)rtl_get_rfreg(hw,
  693. RF90_PATH_A, RF_T_METER, 0xfc00);
  694. if (!rtlpriv->dm.txpower_track_control || thermalvalue == 0 ||
  695. rtlefuse->eeprom_thermalmeter == 0xFF)
  696. return;
  697. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  698. "Readback Thermal Meter = 0x%x pre thermal meter 0x%x eeprom_thermalmeter 0x%x\n",
  699. thermalvalue, rtldm->thermalvalue,
  700. rtlefuse->eeprom_thermalmeter);
  701. /*3 Initialize ThermalValues of RFCalibrateInfo*/
  702. if (!rtldm->thermalvalue) {
  703. rtlpriv->dm.thermalvalue_lck = thermalvalue;
  704. rtlpriv->dm.thermalvalue_iqk = thermalvalue;
  705. }
  706. /*4 Calculate average thermal meter*/
  707. rtldm->thermalvalue_avg[rtldm->thermalvalue_avg_index] = thermalvalue;
  708. rtldm->thermalvalue_avg_index++;
  709. if (rtldm->thermalvalue_avg_index == AVG_THERMAL_NUM_8723BE)
  710. rtldm->thermalvalue_avg_index = 0;
  711. for (i = 0; i < AVG_THERMAL_NUM_8723BE; i++) {
  712. if (rtldm->thermalvalue_avg[i]) {
  713. thermalvalue_avg += rtldm->thermalvalue_avg[i];
  714. thermalvalue_avg_count++;
  715. }
  716. }
  717. if (thermalvalue_avg_count)
  718. thermalvalue = (u8)(thermalvalue_avg / thermalvalue_avg_count);
  719. /* 5 Calculate delta, delta_LCK, delta_IQK.*/
  720. delta = (thermalvalue > rtlpriv->dm.thermalvalue) ?
  721. (thermalvalue - rtlpriv->dm.thermalvalue) :
  722. (rtlpriv->dm.thermalvalue - thermalvalue);
  723. delta_lck = (thermalvalue > rtlpriv->dm.thermalvalue_lck) ?
  724. (thermalvalue - rtlpriv->dm.thermalvalue_lck) :
  725. (rtlpriv->dm.thermalvalue_lck - thermalvalue);
  726. delta_iqk = (thermalvalue > rtlpriv->dm.thermalvalue_iqk) ?
  727. (thermalvalue - rtlpriv->dm.thermalvalue_iqk) :
  728. (rtlpriv->dm.thermalvalue_iqk - thermalvalue);
  729. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  730. "Readback Thermal Meter = 0x%x pre thermal meter 0x%x eeprom_thermalmeter 0x%x delta 0x%x delta_lck 0x%x delta_iqk 0x%x\n",
  731. thermalvalue, rtlpriv->dm.thermalvalue,
  732. rtlefuse->eeprom_thermalmeter, delta, delta_lck, delta_iqk);
  733. /* 6 If necessary, do LCK.*/
  734. if (delta_lck >= IQK_THRESHOLD) {
  735. rtlpriv->dm.thermalvalue_lck = thermalvalue;
  736. rtl8723be_phy_lc_calibrate(hw);
  737. }
  738. /* 7 If necessary, move the index of
  739. * swing table to adjust Tx power.
  740. */
  741. if (delta > 0 && rtlpriv->dm.txpower_track_control) {
  742. delta = (thermalvalue > rtlefuse->eeprom_thermalmeter) ?
  743. (thermalvalue - rtlefuse->eeprom_thermalmeter) :
  744. (rtlefuse->eeprom_thermalmeter - thermalvalue);
  745. if (delta >= TXSCALE_TABLE_SIZE)
  746. delta = TXSCALE_TABLE_SIZE - 1;
  747. /* 7.1 Get the final CCK_index and
  748. * OFDM_index for each swing table.
  749. */
  750. if (thermalvalue > rtlefuse->eeprom_thermalmeter) {
  751. rtldm->delta_power_index_last[RF90_PATH_A] =
  752. rtldm->delta_power_index[RF90_PATH_A];
  753. rtldm->delta_power_index[RF90_PATH_A] =
  754. delta_swing_table_idx_tup_a[delta];
  755. } else {
  756. rtldm->delta_power_index_last[RF90_PATH_A] =
  757. rtldm->delta_power_index[RF90_PATH_A];
  758. rtldm->delta_power_index[RF90_PATH_A] =
  759. -1 * delta_swing_table_idx_tdown_a[delta];
  760. }
  761. /* 7.2 Handle boundary conditions of index.*/
  762. if (rtldm->delta_power_index[RF90_PATH_A] ==
  763. rtldm->delta_power_index_last[RF90_PATH_A])
  764. rtldm->power_index_offset[RF90_PATH_A] = 0;
  765. else
  766. rtldm->power_index_offset[RF90_PATH_A] =
  767. rtldm->delta_power_index[RF90_PATH_A] -
  768. rtldm->delta_power_index_last[RF90_PATH_A];
  769. rtldm->ofdm_index[0] =
  770. rtldm->swing_idx_ofdm_base[RF90_PATH_A] +
  771. rtldm->power_index_offset[RF90_PATH_A];
  772. rtldm->cck_index = rtldm->swing_idx_cck_base +
  773. rtldm->power_index_offset[RF90_PATH_A];
  774. rtldm->swing_idx_cck = rtldm->cck_index;
  775. rtldm->swing_idx_ofdm[0] = rtldm->ofdm_index[0];
  776. if (rtldm->ofdm_index[0] > OFDM_TABLE_SIZE - 1)
  777. rtldm->ofdm_index[0] = OFDM_TABLE_SIZE - 1;
  778. else if (rtldm->ofdm_index[0] < ofdm_min_index)
  779. rtldm->ofdm_index[0] = ofdm_min_index;
  780. if (rtldm->cck_index > CCK_TABLE_SIZE - 1)
  781. rtldm->cck_index = CCK_TABLE_SIZE - 1;
  782. else if (rtldm->cck_index < 0)
  783. rtldm->cck_index = 0;
  784. } else {
  785. rtldm->power_index_offset[RF90_PATH_A] = 0;
  786. }
  787. if ((rtldm->power_index_offset[RF90_PATH_A] != 0) &&
  788. (rtldm->txpower_track_control)) {
  789. rtldm->done_txpower = true;
  790. rtl8723be_dm_tx_power_track_set_power(hw, BBSWING, 0,
  791. index_for_channel);
  792. rtldm->swing_idx_cck_base = rtldm->swing_idx_cck;
  793. rtldm->swing_idx_ofdm_base[RF90_PATH_A] =
  794. rtldm->swing_idx_ofdm[0];
  795. rtldm->thermalvalue = thermalvalue;
  796. }
  797. if (delta_iqk >= IQK_THRESHOLD) {
  798. rtldm->thermalvalue_iqk = thermalvalue;
  799. rtl8723be_phy_iq_calibrate(hw, false);
  800. }
  801. rtldm->txpowercount = 0;
  802. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, "end\n");
  803. }
  804. void rtl8723be_dm_check_txpower_tracking(struct ieee80211_hw *hw)
  805. {
  806. struct rtl_priv *rtlpriv = rtl_priv(hw);
  807. if (!rtlpriv->dm.txpower_tracking)
  808. return;
  809. if (!rtlpriv->dm.tm_trigger) {
  810. rtl_set_rfreg(hw, RF90_PATH_A, RF_T_METER, BIT(17) | BIT(16),
  811. 0x03);
  812. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  813. "Trigger 8723be Thermal Meter!!\n");
  814. rtlpriv->dm.tm_trigger = 1;
  815. return;
  816. } else {
  817. RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
  818. "Schedule TxPowerTracking !!\n");
  819. rtl8723be_dm_txpower_tracking_callback_thermalmeter(hw);
  820. rtlpriv->dm.tm_trigger = 0;
  821. }
  822. }
  823. static void rtl8723be_dm_refresh_rate_adaptive_mask(struct ieee80211_hw *hw)
  824. {
  825. struct rtl_priv *rtlpriv = rtl_priv(hw);
  826. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  827. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  828. struct rate_adaptive *p_ra = &rtlpriv->ra;
  829. u32 low_rssithresh_for_ra = p_ra->low2high_rssi_thresh_for_ra40m;
  830. u32 high_rssithresh_for_ra = p_ra->high_rssi_thresh_for_ra;
  831. u8 go_up_gap = 5;
  832. struct ieee80211_sta *sta = NULL;
  833. if (is_hal_stop(rtlhal)) {
  834. RT_TRACE(rtlpriv, COMP_RATE, DBG_LOUD,
  835. "driver is going to unload\n");
  836. return;
  837. }
  838. if (!rtlpriv->dm.useramask) {
  839. RT_TRACE(rtlpriv, COMP_RATE, DBG_LOUD,
  840. "driver does not control rate adaptive mask\n");
  841. return;
  842. }
  843. if (mac->link_state == MAC80211_LINKED &&
  844. mac->opmode == NL80211_IFTYPE_STATION) {
  845. switch (p_ra->pre_ratr_state) {
  846. case DM_RATR_STA_MIDDLE:
  847. high_rssithresh_for_ra += go_up_gap;
  848. break;
  849. case DM_RATR_STA_LOW:
  850. high_rssithresh_for_ra += go_up_gap;
  851. low_rssithresh_for_ra += go_up_gap;
  852. break;
  853. default:
  854. break;
  855. }
  856. if (rtlpriv->dm.undec_sm_pwdb >
  857. (long)high_rssithresh_for_ra)
  858. p_ra->ratr_state = DM_RATR_STA_HIGH;
  859. else if (rtlpriv->dm.undec_sm_pwdb >
  860. (long)low_rssithresh_for_ra)
  861. p_ra->ratr_state = DM_RATR_STA_MIDDLE;
  862. else
  863. p_ra->ratr_state = DM_RATR_STA_LOW;
  864. if (p_ra->pre_ratr_state != p_ra->ratr_state) {
  865. RT_TRACE(rtlpriv, COMP_RATE, DBG_LOUD,
  866. "RSSI = %ld\n",
  867. rtlpriv->dm.undec_sm_pwdb);
  868. RT_TRACE(rtlpriv, COMP_RATE, DBG_LOUD,
  869. "RSSI_LEVEL = %d\n", p_ra->ratr_state);
  870. RT_TRACE(rtlpriv, COMP_RATE, DBG_LOUD,
  871. "PreState = %d, CurState = %d\n",
  872. p_ra->pre_ratr_state, p_ra->ratr_state);
  873. rcu_read_lock();
  874. sta = rtl_find_sta(hw, mac->bssid);
  875. if (sta)
  876. rtlpriv->cfg->ops->update_rate_tbl(hw, sta,
  877. p_ra->ratr_state,
  878. true);
  879. rcu_read_unlock();
  880. p_ra->pre_ratr_state = p_ra->ratr_state;
  881. }
  882. }
  883. }
  884. static bool rtl8723be_dm_is_edca_turbo_disable(struct ieee80211_hw *hw)
  885. {
  886. struct rtl_priv *rtlpriv = rtl_priv(hw);
  887. if (rtlpriv->mac80211.mode == WIRELESS_MODE_B)
  888. return true;
  889. return false;
  890. }
  891. static void rtl8723be_dm_check_edca_turbo(struct ieee80211_hw *hw)
  892. {
  893. struct rtl_priv *rtlpriv = rtl_priv(hw);
  894. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  895. static u64 last_txok_cnt;
  896. static u64 last_rxok_cnt;
  897. u64 cur_txok_cnt = 0;
  898. u64 cur_rxok_cnt = 0;
  899. u32 edca_be_ul = 0x6ea42b;
  900. u32 edca_be_dl = 0x6ea42b;/*not sure*/
  901. u32 edca_be = 0x5ea42b;
  902. u32 iot_peer = 0;
  903. bool b_is_cur_rdlstate;
  904. bool b_last_is_cur_rdlstate = false;
  905. bool b_bias_on_rx = false;
  906. bool b_edca_turbo_on = false;
  907. b_last_is_cur_rdlstate = rtlpriv->dm.is_cur_rdlstate;
  908. cur_txok_cnt = rtlpriv->stats.txbytesunicast - last_txok_cnt;
  909. cur_rxok_cnt = rtlpriv->stats.rxbytesunicast - last_rxok_cnt;
  910. iot_peer = rtlpriv->mac80211.vendor;
  911. b_bias_on_rx = (iot_peer == PEER_RAL || iot_peer == PEER_ATH) ?
  912. true : false;
  913. b_edca_turbo_on = ((!rtlpriv->dm.is_any_nonbepkts) &&
  914. (!rtlpriv->dm.disable_framebursting)) ?
  915. true : false;
  916. if ((iot_peer == PEER_CISCO) &&
  917. (mac->mode == WIRELESS_MODE_N_24G)) {
  918. edca_be_dl = edca_setting_dl[iot_peer];
  919. edca_be_ul = edca_setting_ul[iot_peer];
  920. }
  921. if (rtl8723be_dm_is_edca_turbo_disable(hw))
  922. goto exit;
  923. if (b_edca_turbo_on) {
  924. if (b_bias_on_rx)
  925. b_is_cur_rdlstate = (cur_txok_cnt > cur_rxok_cnt * 4) ?
  926. false : true;
  927. else
  928. b_is_cur_rdlstate = (cur_rxok_cnt > cur_txok_cnt * 4) ?
  929. true : false;
  930. edca_be = (b_is_cur_rdlstate) ? edca_be_dl : edca_be_ul;
  931. rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, edca_be);
  932. rtlpriv->dm.is_cur_rdlstate = b_is_cur_rdlstate;
  933. rtlpriv->dm.current_turbo_edca = true;
  934. } else {
  935. if (rtlpriv->dm.current_turbo_edca) {
  936. u8 tmp = AC0_BE;
  937. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AC_PARAM,
  938. (u8 *)(&tmp));
  939. }
  940. rtlpriv->dm.current_turbo_edca = false;
  941. }
  942. exit:
  943. rtlpriv->dm.is_any_nonbepkts = false;
  944. last_txok_cnt = rtlpriv->stats.txbytesunicast;
  945. last_rxok_cnt = rtlpriv->stats.rxbytesunicast;
  946. }
  947. static void rtl8723be_dm_cck_packet_detection_thresh(struct ieee80211_hw *hw)
  948. {
  949. struct rtl_priv *rtlpriv = rtl_priv(hw);
  950. struct dig_t *dm_digtable = &rtlpriv->dm_digtable;
  951. u8 cur_cck_cca_thresh;
  952. if (rtlpriv->mac80211.link_state >= MAC80211_LINKED) {
  953. if (dm_digtable->rssi_val_min > 25) {
  954. cur_cck_cca_thresh = 0xcd;
  955. } else if ((dm_digtable->rssi_val_min <= 25) &&
  956. (dm_digtable->rssi_val_min > 10)) {
  957. cur_cck_cca_thresh = 0x83;
  958. } else {
  959. if (rtlpriv->falsealm_cnt.cnt_cck_fail > 1000)
  960. cur_cck_cca_thresh = 0x83;
  961. else
  962. cur_cck_cca_thresh = 0x40;
  963. }
  964. } else {
  965. if (rtlpriv->falsealm_cnt.cnt_cck_fail > 1000)
  966. cur_cck_cca_thresh = 0x83;
  967. else
  968. cur_cck_cca_thresh = 0x40;
  969. }
  970. if (dm_digtable->cur_cck_cca_thres != cur_cck_cca_thresh)
  971. rtl_set_bbreg(hw, RCCK0_CCA, MASKBYTE2, cur_cck_cca_thresh);
  972. dm_digtable->pre_cck_cca_thres = dm_digtable->cur_cck_cca_thres;
  973. dm_digtable->cur_cck_cca_thres = cur_cck_cca_thresh;
  974. RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE,
  975. "CCK cca thresh hold =%x\n", dm_digtable->cur_cck_cca_thres);
  976. }
  977. static void rtl8723be_dm_dynamic_edcca(struct ieee80211_hw *hw)
  978. {
  979. struct rtl_priv *rtlpriv = rtl_priv(hw);
  980. u8 reg_c50, reg_c58;
  981. bool fw_current_in_ps_mode = false;
  982. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  983. (u8 *)(&fw_current_in_ps_mode));
  984. if (fw_current_in_ps_mode)
  985. return;
  986. reg_c50 = rtl_get_bbreg(hw, ROFDM0_XAAGCCORE1, MASKBYTE0);
  987. reg_c58 = rtl_get_bbreg(hw, ROFDM0_XBAGCCORE1, MASKBYTE0);
  988. if (reg_c50 > 0x28 && reg_c58 > 0x28) {
  989. if (!rtlpriv->rtlhal.pre_edcca_enable) {
  990. rtl_write_byte(rtlpriv, ROFDM0_ECCATHRESHOLD, 0x03);
  991. rtl_write_byte(rtlpriv, ROFDM0_ECCATHRESHOLD + 2, 0x00);
  992. }
  993. } else if (reg_c50 < 0x25 && reg_c58 < 0x25) {
  994. if (rtlpriv->rtlhal.pre_edcca_enable) {
  995. rtl_write_byte(rtlpriv, ROFDM0_ECCATHRESHOLD, 0x7f);
  996. rtl_write_byte(rtlpriv, ROFDM0_ECCATHRESHOLD + 2, 0x7f);
  997. }
  998. }
  999. }
  1000. static void rtl8723be_dm_dynamic_atc_switch(struct ieee80211_hw *hw)
  1001. {
  1002. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1003. struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
  1004. u8 crystal_cap;
  1005. u32 packet_count;
  1006. int cfo_khz_a, cfo_khz_b, cfo_ave = 0, adjust_xtal = 0;
  1007. int cfo_ave_diff;
  1008. if (rtlpriv->mac80211.link_state < MAC80211_LINKED) {
  1009. if (rtldm->atc_status == ATC_STATUS_OFF) {
  1010. rtl_set_bbreg(hw, ROFDM1_CFOTRACKING, BIT(11),
  1011. ATC_STATUS_ON);
  1012. rtldm->atc_status = ATC_STATUS_ON;
  1013. }
  1014. if (rtlpriv->cfg->ops->get_btc_status()) {
  1015. if (!rtlpriv->btcoexist.btc_ops->btc_is_bt_disabled(rtlpriv)) {
  1016. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1017. "odm_DynamicATCSwitch(): Disable CFO tracking for BT!!\n");
  1018. return;
  1019. }
  1020. }
  1021. if (rtldm->crystal_cap != rtlpriv->efuse.crystalcap) {
  1022. rtldm->crystal_cap = rtlpriv->efuse.crystalcap;
  1023. crystal_cap = rtldm->crystal_cap & 0x3f;
  1024. rtl_set_bbreg(hw, REG_MAC_PHY_CTRL, 0xFFF000,
  1025. (crystal_cap | (crystal_cap << 6)));
  1026. }
  1027. } else {
  1028. cfo_khz_a = (int)(rtldm->cfo_tail[0] * 3125) / 1280;
  1029. cfo_khz_b = (int)(rtldm->cfo_tail[1] * 3125) / 1280;
  1030. packet_count = rtldm->packet_count;
  1031. if (packet_count == rtldm->packet_count_pre)
  1032. return;
  1033. rtldm->packet_count_pre = packet_count;
  1034. if (rtlpriv->phy.rf_type == RF_1T1R)
  1035. cfo_ave = cfo_khz_a;
  1036. else
  1037. cfo_ave = (int)(cfo_khz_a + cfo_khz_b) >> 1;
  1038. cfo_ave_diff = (rtldm->cfo_ave_pre >= cfo_ave) ?
  1039. (rtldm->cfo_ave_pre - cfo_ave) :
  1040. (cfo_ave - rtldm->cfo_ave_pre);
  1041. if (cfo_ave_diff > 20 && rtldm->large_cfo_hit == 0) {
  1042. rtldm->large_cfo_hit = 1;
  1043. return;
  1044. } else
  1045. rtldm->large_cfo_hit = 0;
  1046. rtldm->cfo_ave_pre = cfo_ave;
  1047. if (cfo_ave >= -rtldm->cfo_threshold &&
  1048. cfo_ave <= rtldm->cfo_threshold && rtldm->is_freeze == 0) {
  1049. if (rtldm->cfo_threshold == CFO_THRESHOLD_XTAL) {
  1050. rtldm->cfo_threshold = CFO_THRESHOLD_XTAL + 10;
  1051. rtldm->is_freeze = 1;
  1052. } else {
  1053. rtldm->cfo_threshold = CFO_THRESHOLD_XTAL;
  1054. }
  1055. }
  1056. if (cfo_ave > rtldm->cfo_threshold && rtldm->crystal_cap < 0x3f)
  1057. adjust_xtal = ((cfo_ave - CFO_THRESHOLD_XTAL) >> 1) + 1;
  1058. else if ((cfo_ave < -rtlpriv->dm.cfo_threshold) &&
  1059. rtlpriv->dm.crystal_cap > 0)
  1060. adjust_xtal = ((cfo_ave + CFO_THRESHOLD_XTAL) >> 1) - 1;
  1061. if (adjust_xtal != 0) {
  1062. rtldm->is_freeze = 0;
  1063. rtldm->crystal_cap += adjust_xtal;
  1064. if (rtldm->crystal_cap > 0x3f)
  1065. rtldm->crystal_cap = 0x3f;
  1066. else if (rtldm->crystal_cap < 0)
  1067. rtldm->crystal_cap = 0;
  1068. crystal_cap = rtldm->crystal_cap & 0x3f;
  1069. rtl_set_bbreg(hw, REG_MAC_PHY_CTRL, 0xFFF000,
  1070. (crystal_cap | (crystal_cap << 6)));
  1071. }
  1072. if (cfo_ave < CFO_THRESHOLD_ATC &&
  1073. cfo_ave > -CFO_THRESHOLD_ATC) {
  1074. if (rtldm->atc_status == ATC_STATUS_ON) {
  1075. rtl_set_bbreg(hw, ROFDM1_CFOTRACKING, BIT(11),
  1076. ATC_STATUS_OFF);
  1077. rtldm->atc_status = ATC_STATUS_OFF;
  1078. }
  1079. } else {
  1080. if (rtldm->atc_status == ATC_STATUS_OFF) {
  1081. rtl_set_bbreg(hw, ROFDM1_CFOTRACKING, BIT(11),
  1082. ATC_STATUS_ON);
  1083. rtldm->atc_status = ATC_STATUS_ON;
  1084. }
  1085. }
  1086. }
  1087. }
  1088. static void rtl8723be_dm_common_info_self_update(struct ieee80211_hw *hw)
  1089. {
  1090. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1091. u8 cnt = 0;
  1092. struct rtl_sta_info *drv_priv;
  1093. rtlpriv->dm.one_entry_only = false;
  1094. if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
  1095. rtlpriv->mac80211.link_state >= MAC80211_LINKED) {
  1096. rtlpriv->dm.one_entry_only = true;
  1097. return;
  1098. }
  1099. if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP ||
  1100. rtlpriv->mac80211.opmode == NL80211_IFTYPE_ADHOC ||
  1101. rtlpriv->mac80211.opmode == NL80211_IFTYPE_MESH_POINT) {
  1102. spin_lock_bh(&rtlpriv->locks.entry_list_lock);
  1103. list_for_each_entry(drv_priv, &rtlpriv->entry_list, list) {
  1104. cnt++;
  1105. }
  1106. spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
  1107. if (cnt == 1)
  1108. rtlpriv->dm.one_entry_only = true;
  1109. }
  1110. }
  1111. void rtl8723be_dm_watchdog(struct ieee80211_hw *hw)
  1112. {
  1113. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1114. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1115. bool fw_current_inpsmode = false;
  1116. bool fw_ps_awake = true;
  1117. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  1118. (u8 *)(&fw_current_inpsmode));
  1119. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_FWLPS_RF_ON,
  1120. (u8 *)(&fw_ps_awake));
  1121. if (ppsc->p2p_ps_info.p2p_ps_mode)
  1122. fw_ps_awake = false;
  1123. spin_lock(&rtlpriv->locks.rf_ps_lock);
  1124. if ((ppsc->rfpwr_state == ERFON) &&
  1125. ((!fw_current_inpsmode) && fw_ps_awake) &&
  1126. (!ppsc->rfchange_inprogress)) {
  1127. rtl8723be_dm_common_info_self_update(hw);
  1128. rtl8723be_dm_false_alarm_counter_statistics(hw);
  1129. rtl8723be_dm_check_rssi_monitor(hw);
  1130. rtl8723be_dm_dig(hw);
  1131. rtl8723be_dm_dynamic_edcca(hw);
  1132. rtl8723be_dm_cck_packet_detection_thresh(hw);
  1133. rtl8723be_dm_refresh_rate_adaptive_mask(hw);
  1134. rtl8723be_dm_check_edca_turbo(hw);
  1135. rtl8723be_dm_dynamic_atc_switch(hw);
  1136. rtl8723be_dm_check_txpower_tracking(hw);
  1137. rtl8723be_dm_dynamic_txpower(hw);
  1138. }
  1139. spin_unlock(&rtlpriv->locks.rf_ps_lock);
  1140. rtlpriv->dm.dbginfo.num_qry_beacon_pkt = 0;
  1141. }