halbtc8821a1ant.c 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2012 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. * Description:
  27. *
  28. * This file is for RTL8821A Co-exist mechanism
  29. *
  30. * History
  31. * 2012/11/15 Cosa first check in.
  32. *
  33. *============================================================
  34. */
  35. /*============================================================
  36. * include files
  37. *============================================================
  38. */
  39. #include "halbt_precomp.h"
  40. /*============================================================
  41. * Global variables, these are static variables
  42. *============================================================
  43. */
  44. static struct coex_dm_8821a_1ant glcoex_dm_8821a_1ant;
  45. static struct coex_dm_8821a_1ant *coex_dm = &glcoex_dm_8821a_1ant;
  46. static struct coex_sta_8821a_1ant glcoex_sta_8821a_1ant;
  47. static struct coex_sta_8821a_1ant *coex_sta = &glcoex_sta_8821a_1ant;
  48. static const char *const glbt_info_src_8821a_1ant[] = {
  49. "BT Info[wifi fw]",
  50. "BT Info[bt rsp]",
  51. "BT Info[bt auto report]",
  52. };
  53. static u32 glcoex_ver_date_8821a_1ant = 20130816;
  54. static u32 glcoex_ver_8821a_1ant = 0x41;
  55. /*============================================================
  56. * local function proto type if needed
  57. *
  58. * local function start with halbtc8821a1ant_
  59. *============================================================
  60. */
  61. static u8 halbtc8821a1ant_bt_rssi_state(struct btc_coexist *btcoexist,
  62. u8 level_num, u8 rssi_thresh,
  63. u8 rssi_thresh1)
  64. {
  65. struct rtl_priv *rtlpriv = btcoexist->adapter;
  66. long bt_rssi = 0;
  67. u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
  68. bt_rssi = coex_sta->bt_rssi;
  69. if (level_num == 2) {
  70. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  71. (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
  72. if (bt_rssi >= (rssi_thresh +
  73. BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) {
  74. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  75. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  76. "[BTCoex], BT Rssi state switch to High\n");
  77. } else {
  78. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  79. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  80. "[BTCoex], BT Rssi state stay at Low\n");
  81. }
  82. } else {
  83. if (bt_rssi < rssi_thresh) {
  84. bt_rssi_state = BTC_RSSI_STATE_LOW;
  85. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  86. "[BTCoex], BT Rssi state switch to Low\n");
  87. } else {
  88. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  89. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  90. "[BTCoex], BT Rssi state stay at High\n");
  91. }
  92. }
  93. } else if (level_num == 3) {
  94. if (rssi_thresh > rssi_thresh1) {
  95. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  96. "[BTCoex], BT Rssi thresh error!!\n");
  97. return coex_sta->pre_bt_rssi_state;
  98. }
  99. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  100. (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
  101. if (bt_rssi >= (rssi_thresh +
  102. BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) {
  103. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  104. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  105. "[BTCoex], BT Rssi state switch to Medium\n");
  106. } else {
  107. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  108. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  109. "[BTCoex], BT Rssi state stay at Low\n");
  110. }
  111. } else if ((coex_sta->pre_bt_rssi_state ==
  112. BTC_RSSI_STATE_MEDIUM) ||
  113. (coex_sta->pre_bt_rssi_state ==
  114. BTC_RSSI_STATE_STAY_MEDIUM)) {
  115. if (bt_rssi >= (rssi_thresh1 +
  116. BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) {
  117. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  118. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  119. "[BTCoex], BT Rssi state switch to High\n");
  120. } else if (bt_rssi < rssi_thresh) {
  121. bt_rssi_state = BTC_RSSI_STATE_LOW;
  122. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  123. "[BTCoex], BT Rssi state switch to Low\n");
  124. } else {
  125. bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  126. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  127. "[BTCoex], BT Rssi state stay at Medium\n");
  128. }
  129. } else {
  130. if (bt_rssi < rssi_thresh1) {
  131. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  132. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  133. "[BTCoex], BT Rssi state switch to Medium\n");
  134. } else {
  135. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  136. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  137. "[BTCoex], BT Rssi state stay at High\n");
  138. }
  139. }
  140. }
  141. coex_sta->pre_bt_rssi_state = bt_rssi_state;
  142. return bt_rssi_state;
  143. }
  144. static u8 halbtc8821a1ant_WifiRssiState(struct btc_coexist *btcoexist,
  145. u8 index, u8 level_num, u8 rssi_thresh,
  146. u8 rssi_thresh1)
  147. {
  148. struct rtl_priv *rtlpriv = btcoexist->adapter;
  149. long wifi_rssi = 0;
  150. u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
  151. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  152. if (level_num == 2) {
  153. if ((coex_sta->pre_wifi_rssi_state[index] ==
  154. BTC_RSSI_STATE_LOW) ||
  155. (coex_sta->pre_wifi_rssi_state[index] ==
  156. BTC_RSSI_STATE_STAY_LOW)) {
  157. if (wifi_rssi >=
  158. (rssi_thresh+BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) {
  159. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  160. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  161. "[BTCoex], wifi RSSI state switch to High\n");
  162. } else {
  163. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  164. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  165. "[BTCoex], wifi RSSI state stay at Low\n");
  166. }
  167. } else {
  168. if (wifi_rssi < rssi_thresh) {
  169. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  170. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  171. "[BTCoex], wifi RSSI state switch to Low\n");
  172. } else {
  173. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  174. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  175. "[BTCoex], wifi RSSI state stay at High\n");
  176. }
  177. }
  178. } else if (level_num == 3) {
  179. if (rssi_thresh > rssi_thresh1) {
  180. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  181. "[BTCoex], wifi RSSI thresh error!!\n");
  182. return coex_sta->pre_wifi_rssi_state[index];
  183. }
  184. if ((coex_sta->pre_wifi_rssi_state[index] ==
  185. BTC_RSSI_STATE_LOW) ||
  186. (coex_sta->pre_wifi_rssi_state[index] ==
  187. BTC_RSSI_STATE_STAY_LOW)) {
  188. if (wifi_rssi >=
  189. (rssi_thresh+BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) {
  190. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  191. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  192. "[BTCoex], wifi RSSI state switch to Medium\n");
  193. } else {
  194. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  195. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  196. "[BTCoex], wifi RSSI state stay at Low\n");
  197. }
  198. } else if ((coex_sta->pre_wifi_rssi_state[index] ==
  199. BTC_RSSI_STATE_MEDIUM) ||
  200. (coex_sta->pre_wifi_rssi_state[index] ==
  201. BTC_RSSI_STATE_STAY_MEDIUM)) {
  202. if (wifi_rssi >=
  203. (rssi_thresh1 +
  204. BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) {
  205. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  206. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  207. "[BTCoex], wifi RSSI state switch to High\n");
  208. } else if (wifi_rssi < rssi_thresh) {
  209. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  210. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  211. "[BTCoex], wifi RSSI state switch to Low\n");
  212. } else {
  213. wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  214. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  215. "[BTCoex], wifi RSSI state stay at Medium\n");
  216. }
  217. } else {
  218. if (wifi_rssi < rssi_thresh1) {
  219. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  220. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  221. "[BTCoex], wifi RSSI state switch to Medium\n");
  222. } else {
  223. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  224. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  225. "[BTCoex], wifi RSSI state stay at High\n");
  226. }
  227. }
  228. }
  229. coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
  230. return wifi_rssi_state;
  231. }
  232. static void halbtc8821a1ant_update_ra_mask(struct btc_coexist *btcoexist,
  233. bool force_exec, u32 dis_rate_mask)
  234. {
  235. coex_dm->cur_ra_mask = dis_rate_mask;
  236. if (force_exec ||
  237. (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask)) {
  238. btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_ra_mask,
  239. &coex_dm->cur_ra_mask);
  240. }
  241. coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
  242. }
  243. static void btc8821a1ant_auto_rate_fb_retry(struct btc_coexist *btcoexist,
  244. bool force_exec, u8 type)
  245. {
  246. bool wifi_under_b_mode = false;
  247. coex_dm->cur_arfr_type = type;
  248. if (force_exec ||
  249. (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
  250. switch (coex_dm->cur_arfr_type) {
  251. case 0: /* normal mode*/
  252. btcoexist->btc_write_4byte(btcoexist, 0x430,
  253. coex_dm->backup_arfr_cnt1);
  254. btcoexist->btc_write_4byte(btcoexist, 0x434,
  255. coex_dm->backup_arfr_cnt2);
  256. break;
  257. case 1:
  258. btcoexist->btc_get(btcoexist,
  259. BTC_GET_BL_WIFI_UNDER_B_MODE,
  260. &wifi_under_b_mode);
  261. if (wifi_under_b_mode) {
  262. btcoexist->btc_write_4byte(btcoexist, 0x430,
  263. 0x0);
  264. btcoexist->btc_write_4byte(btcoexist, 0x434,
  265. 0x01010101);
  266. } else {
  267. btcoexist->btc_write_4byte(btcoexist, 0x430,
  268. 0x0);
  269. btcoexist->btc_write_4byte(btcoexist, 0x434,
  270. 0x04030201);
  271. }
  272. break;
  273. default:
  274. break;
  275. }
  276. }
  277. coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
  278. }
  279. static void halbtc8821a1ant_retry_limit(struct btc_coexist *btcoexist,
  280. bool force_exec, u8 type)
  281. {
  282. coex_dm->cur_retry_limit_type = type;
  283. if (force_exec ||
  284. (coex_dm->pre_retry_limit_type != coex_dm->cur_retry_limit_type)) {
  285. switch (coex_dm->cur_retry_limit_type) {
  286. case 0: /* normal mode*/
  287. btcoexist->btc_write_2byte(btcoexist, 0x42a,
  288. coex_dm->backup_retry_limit);
  289. break;
  290. case 1: /* retry limit = 8*/
  291. btcoexist->btc_write_2byte(btcoexist, 0x42a, 0x0808);
  292. break;
  293. default:
  294. break;
  295. }
  296. }
  297. coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
  298. }
  299. static void halbtc8821a1ant_ampdu_max_time(struct btc_coexist *btcoexist,
  300. bool force_exec, u8 type)
  301. {
  302. coex_dm->cur_ampdu_time_type = type;
  303. if (force_exec ||
  304. (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
  305. switch (coex_dm->cur_ampdu_time_type) {
  306. case 0: /* normal mode*/
  307. btcoexist->btc_write_1byte(btcoexist, 0x456,
  308. coex_dm->backup_ampdu_max_time);
  309. break;
  310. case 1: /* AMPDU timw = 0x38 * 32us*/
  311. btcoexist->btc_write_1byte(btcoexist, 0x456, 0x38);
  312. break;
  313. default:
  314. break;
  315. }
  316. }
  317. coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
  318. }
  319. static void halbtc8821a1ant_limited_tx(struct btc_coexist *btcoexist,
  320. bool force_exec, u8 ra_mask_type,
  321. u8 arfr_type, u8 retry_limit_type,
  322. u8 ampdu_time_type)
  323. {
  324. switch (ra_mask_type) {
  325. case 0: /* normal mode*/
  326. halbtc8821a1ant_update_ra_mask(btcoexist, force_exec, 0x0);
  327. break;
  328. case 1: /* disable cck 1/2*/
  329. halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
  330. 0x00000003);
  331. break;
  332. case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4*/
  333. halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
  334. 0x0001f1f7);
  335. break;
  336. default:
  337. break;
  338. }
  339. btc8821a1ant_auto_rate_fb_retry(btcoexist, force_exec, arfr_type);
  340. halbtc8821a1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
  341. halbtc8821a1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
  342. }
  343. static void halbtc8821a1ant_limited_rx(struct btc_coexist *btcoexist,
  344. bool force_exec, bool rej_ap_agg_pkt,
  345. bool bt_ctrl_agg_buf_size,
  346. u8 agg_buf_size)
  347. {
  348. bool reject_rx_agg = rej_ap_agg_pkt;
  349. bool bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
  350. u8 rx_agg_size = agg_buf_size;
  351. /*============================================*/
  352. /* Rx Aggregation related setting*/
  353. /*============================================*/
  354. btcoexist->btc_set(btcoexist,
  355. BTC_SET_BL_TO_REJ_AP_AGG_PKT, &reject_rx_agg);
  356. /* decide BT control aggregation buf size or not*/
  357. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
  358. &bt_ctrl_rx_agg_size);
  359. /* aggregation buf size, only work when BT control Rx agg size.*/
  360. btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
  361. /* real update aggregation setting*/
  362. btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
  363. }
  364. static void halbtc8821a1ant_monitor_bt_ctr(struct btc_coexist *btcoexist)
  365. {
  366. u32 reg_hp_tx_rx, reg_lp_tx_rx, u4_tmp;
  367. u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
  368. reg_hp_tx_rx = 0x770;
  369. reg_lp_tx_rx = 0x774;
  370. u4_tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_tx_rx);
  371. reg_hp_tx = u4_tmp & MASKLWORD;
  372. reg_hp_rx = (u4_tmp & MASKHWORD)>>16;
  373. u4_tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_tx_rx);
  374. reg_lp_tx = u4_tmp & MASKLWORD;
  375. reg_lp_rx = (u4_tmp & MASKHWORD)>>16;
  376. coex_sta->high_priority_tx = reg_hp_tx;
  377. coex_sta->high_priority_rx = reg_hp_rx;
  378. coex_sta->low_priority_tx = reg_lp_tx;
  379. coex_sta->low_priority_rx = reg_lp_rx;
  380. /* reset counter*/
  381. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
  382. }
  383. static void halbtc8821a1ant_query_bt_info(struct btc_coexist *btcoexist)
  384. {
  385. struct rtl_priv *rtlpriv = btcoexist->adapter;
  386. u8 h2c_parameter[1] = {0};
  387. coex_sta->c2h_bt_info_req_sent = true;
  388. h2c_parameter[0] |= BIT0; /* trigger*/
  389. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  390. "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
  391. h2c_parameter[0]);
  392. btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
  393. }
  394. static void halbtc8821a1ant_update_bt_link_info(struct btc_coexist *btcoexist)
  395. {
  396. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  397. bool bt_hs_on = false;
  398. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  399. bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
  400. bt_link_info->sco_exist = coex_sta->sco_exist;
  401. bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
  402. bt_link_info->pan_exist = coex_sta->pan_exist;
  403. bt_link_info->hid_exist = coex_sta->hid_exist;
  404. /* work around for HS mode.*/
  405. if (bt_hs_on) {
  406. bt_link_info->pan_exist = true;
  407. bt_link_info->bt_link_exist = true;
  408. }
  409. /* check if Sco only*/
  410. if (bt_link_info->sco_exist &&
  411. !bt_link_info->a2dp_exist &&
  412. !bt_link_info->pan_exist &&
  413. !bt_link_info->hid_exist)
  414. bt_link_info->sco_only = true;
  415. else
  416. bt_link_info->sco_only = false;
  417. /* check if A2dp only*/
  418. if (!bt_link_info->sco_exist &&
  419. bt_link_info->a2dp_exist &&
  420. !bt_link_info->pan_exist &&
  421. !bt_link_info->hid_exist)
  422. bt_link_info->a2dp_only = true;
  423. else
  424. bt_link_info->a2dp_only = false;
  425. /* check if Pan only*/
  426. if (!bt_link_info->sco_exist &&
  427. !bt_link_info->a2dp_exist &&
  428. bt_link_info->pan_exist &&
  429. !bt_link_info->hid_exist)
  430. bt_link_info->pan_only = true;
  431. else
  432. bt_link_info->pan_only = false;
  433. /* check if Hid only*/
  434. if (!bt_link_info->sco_exist &&
  435. !bt_link_info->a2dp_exist &&
  436. !bt_link_info->pan_exist &&
  437. bt_link_info->hid_exist)
  438. bt_link_info->hid_only = true;
  439. else
  440. bt_link_info->hid_only = false;
  441. }
  442. static u8 halbtc8821a1ant_action_algorithm(struct btc_coexist *btcoexist)
  443. {
  444. struct rtl_priv *rtlpriv = btcoexist->adapter;
  445. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  446. bool bt_hs_on = false;
  447. u8 algorithm = BT_8821A_1ANT_COEX_ALGO_UNDEFINED;
  448. u8 num_of_diff_profile = 0;
  449. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  450. if (!bt_link_info->bt_link_exist) {
  451. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  452. "[BTCoex], No BT link exists!!!\n");
  453. return algorithm;
  454. }
  455. if (bt_link_info->sco_exist)
  456. num_of_diff_profile++;
  457. if (bt_link_info->hid_exist)
  458. num_of_diff_profile++;
  459. if (bt_link_info->pan_exist)
  460. num_of_diff_profile++;
  461. if (bt_link_info->a2dp_exist)
  462. num_of_diff_profile++;
  463. if (num_of_diff_profile == 1) {
  464. if (bt_link_info->sco_exist) {
  465. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  466. "[BTCoex], BT Profile = SCO only\n");
  467. algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
  468. } else {
  469. if (bt_link_info->hid_exist) {
  470. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  471. "[BTCoex], BT Profile = HID only\n");
  472. algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
  473. } else if (bt_link_info->a2dp_exist) {
  474. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  475. "[BTCoex], BT Profile = A2DP only\n");
  476. algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP;
  477. } else if (bt_link_info->pan_exist) {
  478. if (bt_hs_on) {
  479. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  480. DBG_LOUD,
  481. "[BTCoex], BT Profile = PAN(HS) only\n");
  482. algorithm = BT_8821A_1ANT_COEX_ALGO_PANHS;
  483. } else {
  484. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  485. DBG_LOUD,
  486. "[BTCoex], BT Profile = PAN(EDR) only\n");
  487. algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR;
  488. }
  489. }
  490. }
  491. } else if (num_of_diff_profile == 2) {
  492. if (bt_link_info->sco_exist) {
  493. if (bt_link_info->hid_exist) {
  494. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  495. "[BTCoex], BT Profile = SCO + HID\n");
  496. algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
  497. } else if (bt_link_info->a2dp_exist) {
  498. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  499. "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
  500. algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
  501. } else if (bt_link_info->pan_exist) {
  502. if (bt_hs_on) {
  503. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  504. DBG_LOUD,
  505. "[BTCoex], BT Profile = SCO + PAN(HS)\n");
  506. algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
  507. } else {
  508. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  509. DBG_LOUD,
  510. "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
  511. algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
  512. }
  513. }
  514. } else {
  515. if (bt_link_info->hid_exist &&
  516. bt_link_info->a2dp_exist) {
  517. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  518. "[BTCoex], BT Profile = HID + A2DP\n");
  519. algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
  520. } else if (bt_link_info->hid_exist &&
  521. bt_link_info->pan_exist) {
  522. if (bt_hs_on) {
  523. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  524. DBG_LOUD,
  525. "[BTCoex], BT Profile = HID + PAN(HS)\n");
  526. algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
  527. } else {
  528. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  529. DBG_LOUD,
  530. "[BTCoex], BT Profile = HID + PAN(EDR)\n");
  531. algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
  532. }
  533. } else if (bt_link_info->pan_exist &&
  534. bt_link_info->a2dp_exist) {
  535. if (bt_hs_on) {
  536. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  537. DBG_LOUD,
  538. "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
  539. algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS;
  540. } else {
  541. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  542. DBG_LOUD,
  543. "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
  544. algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP;
  545. }
  546. }
  547. }
  548. } else if (num_of_diff_profile == 3) {
  549. if (bt_link_info->sco_exist) {
  550. if (bt_link_info->hid_exist &&
  551. bt_link_info->a2dp_exist) {
  552. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  553. "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
  554. algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
  555. } else if (bt_link_info->hid_exist &&
  556. bt_link_info->pan_exist) {
  557. if (bt_hs_on) {
  558. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  559. DBG_LOUD,
  560. "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
  561. algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
  562. } else {
  563. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  564. DBG_LOUD,
  565. "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
  566. algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
  567. }
  568. } else if (bt_link_info->pan_exist &&
  569. bt_link_info->a2dp_exist) {
  570. if (bt_hs_on) {
  571. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  572. DBG_LOUD,
  573. "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
  574. algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
  575. } else {
  576. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  577. DBG_LOUD,
  578. "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
  579. algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
  580. }
  581. }
  582. } else {
  583. if (bt_link_info->hid_exist &&
  584. bt_link_info->pan_exist &&
  585. bt_link_info->a2dp_exist) {
  586. if (bt_hs_on) {
  587. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  588. DBG_LOUD,
  589. "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
  590. algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
  591. } else {
  592. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  593. DBG_LOUD,
  594. "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
  595. algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
  596. }
  597. }
  598. }
  599. } else if (num_of_diff_profile >= 3) {
  600. if (bt_link_info->sco_exist) {
  601. if (bt_link_info->hid_exist &&
  602. bt_link_info->pan_exist &&
  603. bt_link_info->a2dp_exist) {
  604. if (bt_hs_on) {
  605. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  606. DBG_LOUD,
  607. "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
  608. } else {
  609. RT_TRACE(rtlpriv, COMP_BT_COEXIST,
  610. DBG_LOUD,
  611. "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
  612. algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
  613. }
  614. }
  615. }
  616. }
  617. return algorithm;
  618. }
  619. static void halbtc8821a1ant_set_bt_auto_report(struct btc_coexist *btcoexist,
  620. bool enable_auto_report)
  621. {
  622. struct rtl_priv *rtlpriv = btcoexist->adapter;
  623. u8 h2c_parameter[1] = {0};
  624. h2c_parameter[0] = 0;
  625. if (enable_auto_report)
  626. h2c_parameter[0] |= BIT0;
  627. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  628. "[BTCoex], BT FW auto report : %s, FW write 0x68 = 0x%x\n",
  629. (enable_auto_report ? "Enabled!!" : "Disabled!!"),
  630. h2c_parameter[0]);
  631. btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
  632. }
  633. static void halbtc8821a1ant_bt_auto_report(struct btc_coexist *btcoexist,
  634. bool force_exec,
  635. bool enable_auto_report)
  636. {
  637. struct rtl_priv *rtlpriv = btcoexist->adapter;
  638. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  639. "[BTCoex], %s BT Auto report = %s\n",
  640. (force_exec ? "force to" : ""), ((enable_auto_report) ?
  641. "Enabled" : "Disabled"));
  642. coex_dm->cur_bt_auto_report = enable_auto_report;
  643. if (!force_exec) {
  644. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  645. "[BTCoex], pre_bt_auto_report = %d, cur_bt_auto_report = %d\n",
  646. coex_dm->pre_bt_auto_report,
  647. coex_dm->cur_bt_auto_report);
  648. if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
  649. return;
  650. }
  651. halbtc8821a1ant_set_bt_auto_report(btcoexist, coex_dm->cur_bt_auto_report);
  652. coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
  653. }
  654. static void btc8821a1ant_set_sw_pen_tx_rate(struct btc_coexist *btcoexist,
  655. bool low_penalty_ra)
  656. {
  657. struct rtl_priv *rtlpriv = btcoexist->adapter;
  658. u8 h2c_parameter[6] = {0};
  659. h2c_parameter[0] = 0x6; /* opCode, 0x6= Retry_Penalty*/
  660. if (low_penalty_ra) {
  661. h2c_parameter[1] |= BIT0;
  662. /*normal rate except MCS7/6/5, OFDM54/48/36*/
  663. h2c_parameter[2] = 0x00;
  664. h2c_parameter[3] = 0xf7; /*MCS7 or OFDM54*/
  665. h2c_parameter[4] = 0xf8; /*MCS6 or OFDM48*/
  666. h2c_parameter[5] = 0xf9; /*MCS5 or OFDM36*/
  667. }
  668. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  669. "[BTCoex], set WiFi Low-Penalty Retry: %s",
  670. (low_penalty_ra ? "ON!!" : "OFF!!"));
  671. btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
  672. }
  673. static void halbtc8821a1ant_low_penalty_ra(struct btc_coexist *btcoexist,
  674. bool force_exec, bool low_penalty_ra)
  675. {
  676. coex_dm->cur_low_penalty_ra = low_penalty_ra;
  677. if (!force_exec) {
  678. if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
  679. return;
  680. }
  681. btc8821a1ant_set_sw_pen_tx_rate(btcoexist, coex_dm->cur_low_penalty_ra);
  682. coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
  683. }
  684. static void halbtc8821a1ant_set_coex_table(struct btc_coexist *btcoexist,
  685. u32 val0x6c0, u32 val0x6c4,
  686. u32 val0x6c8, u8 val0x6cc)
  687. {
  688. struct rtl_priv *rtlpriv = btcoexist->adapter;
  689. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  690. "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0);
  691. btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
  692. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  693. "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4);
  694. btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
  695. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  696. "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8);
  697. btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
  698. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  699. "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc);
  700. btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
  701. }
  702. static void halbtc8821a1ant_coex_table(struct btc_coexist *btcoexist,
  703. bool force_exec, u32 val0x6c0,
  704. u32 val0x6c4, u32 val0x6c8, u8 val0x6cc)
  705. {
  706. struct rtl_priv *rtlpriv = btcoexist->adapter;
  707. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  708. "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
  709. (force_exec ? "force to" : ""), val0x6c0, val0x6c4,
  710. val0x6c8, val0x6cc);
  711. coex_dm->cur_val_0x6c0 = val0x6c0;
  712. coex_dm->cur_val_0x6c4 = val0x6c4;
  713. coex_dm->cur_val_0x6c8 = val0x6c8;
  714. coex_dm->cur_val_0x6cc = val0x6cc;
  715. if (!force_exec) {
  716. if ((coex_dm->pre_val_0x6c0 == coex_dm->cur_val_0x6c0) &&
  717. (coex_dm->pre_val_0x6c4 == coex_dm->cur_val_0x6c4) &&
  718. (coex_dm->pre_val_0x6c8 == coex_dm->cur_val_0x6c8) &&
  719. (coex_dm->pre_val_0x6cc == coex_dm->cur_val_0x6cc))
  720. return;
  721. }
  722. halbtc8821a1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4,
  723. val0x6c8, val0x6cc);
  724. coex_dm->pre_val_0x6c0 = coex_dm->cur_val_0x6c0;
  725. coex_dm->pre_val_0x6c4 = coex_dm->cur_val_0x6c4;
  726. coex_dm->pre_val_0x6c8 = coex_dm->cur_val_0x6c8;
  727. coex_dm->pre_val_0x6cc = coex_dm->cur_val_0x6cc;
  728. }
  729. static void halbtc8821a1ant_coex_table_with_type(struct btc_coexist *btcoexist,
  730. bool force_exec, u8 type)
  731. {
  732. switch (type) {
  733. case 0:
  734. halbtc8821a1ant_coex_table(btcoexist, force_exec, 0x55555555,
  735. 0x55555555, 0xffffff, 0x3);
  736. break;
  737. case 1:
  738. halbtc8821a1ant_coex_table(btcoexist, force_exec,
  739. 0x55555555, 0x5a5a5a5a,
  740. 0xffffff, 0x3);
  741. break;
  742. case 2:
  743. halbtc8821a1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
  744. 0x5a5a5a5a, 0xffffff, 0x3);
  745. break;
  746. case 3:
  747. halbtc8821a1ant_coex_table(btcoexist, force_exec, 0x55555555,
  748. 0xaaaaaaaa, 0xffffff, 0x3);
  749. break;
  750. case 4:
  751. halbtc8821a1ant_coex_table(btcoexist, force_exec, 0xffffffff,
  752. 0xffffffff, 0xffffff, 0x3);
  753. break;
  754. case 5:
  755. halbtc8821a1ant_coex_table(btcoexist, force_exec, 0x5fff5fff,
  756. 0x5fff5fff, 0xffffff, 0x3);
  757. break;
  758. case 6:
  759. halbtc8821a1ant_coex_table(btcoexist, force_exec, 0x55ff55ff,
  760. 0x5a5a5a5a, 0xffffff, 0x3);
  761. break;
  762. case 7:
  763. halbtc8821a1ant_coex_table(btcoexist, force_exec, 0x5afa5afa,
  764. 0x5afa5afa, 0xffffff, 0x3);
  765. break;
  766. default:
  767. break;
  768. }
  769. }
  770. static void btc8821a1ant_set_fw_ignore_wlan_act(struct btc_coexist *btcoexist,
  771. bool enable)
  772. {
  773. struct rtl_priv *rtlpriv = btcoexist->adapter;
  774. u8 h2c_parameter[1] = {0};
  775. if (enable)
  776. h2c_parameter[0] |= BIT0; /* function enable*/
  777. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  778. "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
  779. h2c_parameter[0]);
  780. btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
  781. }
  782. static void halbtc8821a1ant_ignore_wlan_act(struct btc_coexist *btcoexist,
  783. bool force_exec, bool enable)
  784. {
  785. struct rtl_priv *rtlpriv = btcoexist->adapter;
  786. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  787. "[BTCoex], %s turn Ignore WlanAct %s\n",
  788. (force_exec ? "force to" : ""), (enable ? "ON" : "OFF"));
  789. coex_dm->cur_ignore_wlan_act = enable;
  790. if (!force_exec) {
  791. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  792. "[BTCoex], pre_ignore_wlan_act = %d, cur_ignore_wlan_act = %d!!\n",
  793. coex_dm->pre_ignore_wlan_act,
  794. coex_dm->cur_ignore_wlan_act);
  795. if (coex_dm->pre_ignore_wlan_act ==
  796. coex_dm->cur_ignore_wlan_act)
  797. return;
  798. }
  799. btc8821a1ant_set_fw_ignore_wlan_act(btcoexist, enable);
  800. coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
  801. }
  802. static void halbtc8821a1ant_set_fw_pstdma(struct btc_coexist *btcoexist,
  803. u8 byte1, u8 byte2, u8 byte3,
  804. u8 byte4, u8 byte5)
  805. {
  806. struct rtl_priv *rtlpriv = btcoexist->adapter;
  807. u8 h2c_parameter[5] = {0};
  808. h2c_parameter[0] = byte1;
  809. h2c_parameter[1] = byte2;
  810. h2c_parameter[2] = byte3;
  811. h2c_parameter[3] = byte4;
  812. h2c_parameter[4] = byte5;
  813. coex_dm->ps_tdma_para[0] = byte1;
  814. coex_dm->ps_tdma_para[1] = byte2;
  815. coex_dm->ps_tdma_para[2] = byte3;
  816. coex_dm->ps_tdma_para[3] = byte4;
  817. coex_dm->ps_tdma_para[4] = byte5;
  818. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  819. "[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n",
  820. h2c_parameter[0],
  821. h2c_parameter[1] << 24 |
  822. h2c_parameter[2] << 16 |
  823. h2c_parameter[3] << 8 |
  824. h2c_parameter[4]);
  825. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
  826. }
  827. static void halbtc8821a1ant_set_lps_rpwm(struct btc_coexist *btcoexist,
  828. u8 lps_val, u8 rpwm_val)
  829. {
  830. u8 lps = lps_val;
  831. u8 rpwm = rpwm_val;
  832. btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
  833. btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
  834. }
  835. static void halbtc8821a1ant_lps_rpwm(struct btc_coexist *btcoexist,
  836. bool force_exec, u8 lps_val, u8 rpwm_val)
  837. {
  838. struct rtl_priv *rtlpriv = btcoexist->adapter;
  839. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  840. "[BTCoex], %s set lps/rpwm = 0x%x/0x%x\n",
  841. (force_exec ? "force to" : ""), lps_val, rpwm_val);
  842. coex_dm->cur_lps = lps_val;
  843. coex_dm->cur_rpwm = rpwm_val;
  844. if (!force_exec) {
  845. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  846. "[BTCoex], LPS-RxBeaconMode = 0x%x, LPS-RPWM = 0x%x!!\n",
  847. coex_dm->cur_lps, coex_dm->cur_rpwm);
  848. if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
  849. (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) {
  850. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  851. "[BTCoex], LPS-RPWM_Last = 0x%x, LPS-RPWM_Now = 0x%x!!\n",
  852. coex_dm->pre_rpwm, coex_dm->cur_rpwm);
  853. return;
  854. }
  855. }
  856. halbtc8821a1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
  857. coex_dm->pre_lps = coex_dm->cur_lps;
  858. coex_dm->pre_rpwm = coex_dm->cur_rpwm;
  859. }
  860. static void halbtc8821a1ant_sw_mechanism(struct btc_coexist *btcoexist,
  861. bool low_penalty_ra)
  862. {
  863. struct rtl_priv *rtlpriv = btcoexist->adapter;
  864. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  865. "[BTCoex], SM[LpRA] = %d\n", low_penalty_ra);
  866. halbtc8821a1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
  867. }
  868. static void halbtc8821a1ant_set_ant_path(struct btc_coexist *btcoexist,
  869. u8 ant_pos_type, bool init_hw_cfg,
  870. bool wifi_off)
  871. {
  872. struct btc_board_info *board_info = &btcoexist->board_info;
  873. u32 u4_tmp = 0;
  874. u8 h2c_parameter[2] = {0};
  875. if (init_hw_cfg) {
  876. /* 0x4c[23] = 0, 0x4c[24] = 1 Antenna control by WL/BT*/
  877. u4_tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  878. u4_tmp &= ~BIT23;
  879. u4_tmp |= BIT24;
  880. btcoexist->btc_write_4byte(btcoexist, 0x4c, u4_tmp);
  881. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x975, 0x3, 0x3);
  882. btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77);
  883. if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) {
  884. /*tell firmware "antenna inverse" ==>
  885. * WRONG firmware antenna control code.==>need fw to fix
  886. */
  887. h2c_parameter[0] = 1;
  888. h2c_parameter[1] = 1;
  889. btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
  890. h2c_parameter);
  891. /*Main Ant to BT for IPS case 0x4c[23] = 1*/
  892. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64,
  893. 0x1, 0x1);
  894. } else {
  895. /*tell firmware "no antenna inverse" ==>
  896. * WRONG firmware antenna control code.==>need fw to fix
  897. */
  898. h2c_parameter[0] = 0;
  899. h2c_parameter[1] = 1;
  900. btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
  901. h2c_parameter);
  902. /*Aux Ant to BT for IPS case 0x4c[23] = 1*/
  903. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64,
  904. 0x1, 0x0);
  905. }
  906. } else if (wifi_off) {
  907. /* 0x4c[24:23] = 00, Set Antenna control
  908. * by BT_RFE_CTRL BT Vendor 0xac = 0xf002
  909. */
  910. u4_tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  911. u4_tmp &= ~BIT23;
  912. u4_tmp &= ~BIT24;
  913. btcoexist->btc_write_4byte(btcoexist, 0x4c, u4_tmp);
  914. }
  915. /* ext switch setting*/
  916. switch (ant_pos_type) {
  917. case BTC_ANT_PATH_WIFI:
  918. if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT)
  919. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
  920. 0x30, 0x1);
  921. else
  922. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
  923. 0x30, 0x2);
  924. break;
  925. case BTC_ANT_PATH_BT:
  926. if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT)
  927. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
  928. 0x30, 0x2);
  929. else
  930. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
  931. 0x30, 0x1);
  932. break;
  933. default:
  934. case BTC_ANT_PATH_PTA:
  935. if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT)
  936. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
  937. 0x30, 0x1);
  938. else
  939. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
  940. 0x30, 0x2);
  941. break;
  942. }
  943. }
  944. static void halbtc8821a1ant_ps_tdma(struct btc_coexist *btcoexist,
  945. bool force_exec, bool turn_on, u8 type)
  946. {
  947. struct rtl_priv *rtlpriv = btcoexist->adapter;
  948. u8 rssi_adjust_val = 0;
  949. coex_dm->cur_ps_tdma_on = turn_on;
  950. coex_dm->cur_ps_tdma = type;
  951. if (!force_exec) {
  952. if (coex_dm->cur_ps_tdma_on) {
  953. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  954. "[BTCoex], ********** TDMA(on, %d) **********\n",
  955. coex_dm->cur_ps_tdma);
  956. } else {
  957. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  958. "[BTCoex], ********** TDMA(off, %d) **********\n",
  959. coex_dm->cur_ps_tdma);
  960. }
  961. if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
  962. (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
  963. return;
  964. }
  965. if (turn_on) {
  966. switch (type) {
  967. default:
  968. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, 0x1a,
  969. 0x1a, 0x0, 0x50);
  970. break;
  971. case 1:
  972. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, 0x3a,
  973. 0x03, 0x10, 0x50);
  974. rssi_adjust_val = 11;
  975. break;
  976. case 2:
  977. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, 0x2b,
  978. 0x03, 0x10, 0x50);
  979. rssi_adjust_val = 14;
  980. break;
  981. case 3:
  982. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, 0x1d,
  983. 0x1d, 0x0, 0x10);
  984. break;
  985. case 4:
  986. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93, 0x15,
  987. 0x3, 0x14, 0x0);
  988. rssi_adjust_val = 17;
  989. break;
  990. case 5:
  991. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61, 0x15,
  992. 0x3, 0x11, 0x10);
  993. break;
  994. case 6:
  995. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13, 0xa,
  996. 0x3, 0x0, 0x0);
  997. break;
  998. case 7:
  999. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13, 0xc,
  1000. 0x5, 0x0, 0x0);
  1001. break;
  1002. case 8:
  1003. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93, 0x25,
  1004. 0x3, 0x10, 0x0);
  1005. break;
  1006. case 9:
  1007. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, 0x21,
  1008. 0x3, 0x10, 0x50);
  1009. rssi_adjust_val = 18;
  1010. break;
  1011. case 10:
  1012. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13, 0xa,
  1013. 0xa, 0x0, 0x40);
  1014. break;
  1015. case 11:
  1016. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, 0x14,
  1017. 0x03, 0x10, 0x10);
  1018. rssi_adjust_val = 20;
  1019. break;
  1020. case 12:
  1021. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, 0x0a,
  1022. 0x0a, 0x0, 0x50);
  1023. break;
  1024. case 13:
  1025. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, 0x18,
  1026. 0x18, 0x0, 0x10);
  1027. break;
  1028. case 14:
  1029. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, 0x21,
  1030. 0x3, 0x10, 0x10);
  1031. break;
  1032. case 15:
  1033. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13, 0xa,
  1034. 0x3, 0x8, 0x0);
  1035. break;
  1036. case 16:
  1037. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93, 0x15,
  1038. 0x3, 0x10, 0x0);
  1039. rssi_adjust_val = 18;
  1040. break;
  1041. case 18:
  1042. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93, 0x25,
  1043. 0x3, 0x10, 0x0);
  1044. rssi_adjust_val = 14;
  1045. break;
  1046. case 20:
  1047. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61, 0x35,
  1048. 0x03, 0x11, 0x10);
  1049. break;
  1050. case 21:
  1051. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61, 0x15,
  1052. 0x03, 0x11, 0x10);
  1053. break;
  1054. case 22:
  1055. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61, 0x25,
  1056. 0x03, 0x11, 0x10);
  1057. break;
  1058. case 23:
  1059. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3, 0x25,
  1060. 0x3, 0x31, 0x18);
  1061. rssi_adjust_val = 22;
  1062. break;
  1063. case 24:
  1064. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3, 0x15,
  1065. 0x3, 0x31, 0x18);
  1066. rssi_adjust_val = 22;
  1067. break;
  1068. case 25:
  1069. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3, 0xa,
  1070. 0x3, 0x31, 0x18);
  1071. rssi_adjust_val = 22;
  1072. break;
  1073. case 26:
  1074. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3, 0xa,
  1075. 0x3, 0x31, 0x18);
  1076. rssi_adjust_val = 22;
  1077. break;
  1078. case 27:
  1079. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3, 0x25,
  1080. 0x3, 0x31, 0x98);
  1081. rssi_adjust_val = 22;
  1082. break;
  1083. case 28:
  1084. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x69, 0x25,
  1085. 0x3, 0x31, 0x0);
  1086. break;
  1087. case 29:
  1088. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xab, 0x1a,
  1089. 0x1a, 0x1, 0x10);
  1090. break;
  1091. case 30:
  1092. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, 0x14,
  1093. 0x3, 0x10, 0x50);
  1094. break;
  1095. case 31:
  1096. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xd3, 0x1a,
  1097. 0x1a, 0, 0x58);
  1098. break;
  1099. case 32:
  1100. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61, 0xa,
  1101. 0x3, 0x10, 0x0);
  1102. break;
  1103. case 33:
  1104. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xa3, 0x25,
  1105. 0x3, 0x30, 0x90);
  1106. break;
  1107. case 34:
  1108. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x53, 0x1a,
  1109. 0x1a, 0x0, 0x10);
  1110. break;
  1111. case 35:
  1112. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x63, 0x1a,
  1113. 0x1a, 0x0, 0x10);
  1114. break;
  1115. case 36:
  1116. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xd3, 0x12,
  1117. 0x3, 0x14, 0x50);
  1118. break;
  1119. }
  1120. } else {
  1121. /* disable PS tdma*/
  1122. switch (type) {
  1123. case 8: /*PTA Control*/
  1124. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x8, 0x0, 0x0,
  1125. 0x0, 0x0);
  1126. halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
  1127. false, false);
  1128. break;
  1129. case 0:
  1130. default: /*Software control, Antenna at BT side*/
  1131. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
  1132. 0x0, 0x0);
  1133. halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
  1134. false, false);
  1135. break;
  1136. case 9: /*Software control, Antenna at WiFi side*/
  1137. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
  1138. 0x0, 0x0);
  1139. halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI,
  1140. false, false);
  1141. break;
  1142. case 10: /* under 5G*/
  1143. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0, 0x0, 0x0,
  1144. 0x8, 0x0);
  1145. halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
  1146. false, false);
  1147. break;
  1148. }
  1149. }
  1150. rssi_adjust_val = 0;
  1151. btcoexist->btc_set(btcoexist,
  1152. BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val);
  1153. /* update pre state*/
  1154. coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
  1155. coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
  1156. }
  1157. static bool halbtc8821a1ant_is_common_action(struct btc_coexist *btcoexist)
  1158. {
  1159. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1160. bool common = false, wifi_connected = false, wifi_busy = false;
  1161. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1162. &wifi_connected);
  1163. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1164. if (!wifi_connected &&
  1165. BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  1166. coex_dm->bt_status) {
  1167. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1168. "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
  1169. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1170. common = true;
  1171. } else if (wifi_connected &&
  1172. (BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  1173. coex_dm->bt_status)) {
  1174. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1175. "[BTCoex], Wifi connected + BT non connected-idle!!\n");
  1176. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1177. common = true;
  1178. } else if (!wifi_connected &&
  1179. (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE ==
  1180. coex_dm->bt_status)) {
  1181. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1182. "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
  1183. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1184. common = true;
  1185. } else if (wifi_connected &&
  1186. (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE ==
  1187. coex_dm->bt_status)) {
  1188. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1189. "[BTCoex], Wifi connected + BT connected-idle!!\n");
  1190. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1191. common = true;
  1192. } else if (!wifi_connected &&
  1193. (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE !=
  1194. coex_dm->bt_status)) {
  1195. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1196. "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
  1197. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1198. common = true;
  1199. } else {
  1200. if (wifi_busy) {
  1201. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1202. "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
  1203. } else {
  1204. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1205. "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
  1206. }
  1207. common = false;
  1208. }
  1209. return common;
  1210. }
  1211. static void btc8821a1ant_tdma_dur_adj(struct btc_coexist *btcoexist,
  1212. u8 wifi_status)
  1213. {
  1214. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1215. static long up, dn, m, n, wait_count;
  1216. /*0: no change, +1: increase WiFi duration, -1: decrease WiFi duration*/
  1217. long result;
  1218. u8 retry_count = 0, bt_info_ext;
  1219. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1220. "[BTCoex], TdmaDurationAdjustForAcl()\n");
  1221. if ((BT_8821A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN ==
  1222. wifi_status) ||
  1223. (BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN ==
  1224. wifi_status) ||
  1225. (BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT ==
  1226. wifi_status)) {
  1227. if (coex_dm->cur_ps_tdma != 1 &&
  1228. coex_dm->cur_ps_tdma != 2 &&
  1229. coex_dm->cur_ps_tdma != 3 &&
  1230. coex_dm->cur_ps_tdma != 9) {
  1231. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1232. true, 9);
  1233. coex_dm->tdma_adj_type = 9;
  1234. up = 0;
  1235. dn = 0;
  1236. m = 1;
  1237. n = 3;
  1238. result = 0;
  1239. wait_count = 0;
  1240. }
  1241. return;
  1242. }
  1243. if (!coex_dm->auto_tdma_adjust) {
  1244. coex_dm->auto_tdma_adjust = true;
  1245. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1246. "[BTCoex], first run TdmaDurationAdjust()!!\n");
  1247. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2);
  1248. coex_dm->tdma_adj_type = 2;
  1249. /*============*/
  1250. up = 0;
  1251. dn = 0;
  1252. m = 1;
  1253. n = 3;
  1254. result = 0;
  1255. wait_count = 0;
  1256. } else {
  1257. /*accquire the BT TRx retry count from BT_Info byte2*/
  1258. retry_count = coex_sta->bt_retry_cnt;
  1259. bt_info_ext = coex_sta->bt_info_ext;
  1260. result = 0;
  1261. wait_count++;
  1262. if (retry_count == 0) {
  1263. /* no retry in the last 2-second duration*/
  1264. up++;
  1265. dn--;
  1266. if (dn <= 0)
  1267. dn = 0;
  1268. if (up >= n) {
  1269. /* if (retry count == 0) for 2*n seconds ,
  1270. * make WiFi duration wider
  1271. */
  1272. wait_count = 0;
  1273. n = 3;
  1274. up = 0;
  1275. dn = 0;
  1276. result = 1;
  1277. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1278. "[BTCoex], Increase wifi duration!!\n");
  1279. }
  1280. } else if (retry_count <= 3) {
  1281. /* <=3 retry in the last 2-second duration*/
  1282. up--;
  1283. dn++;
  1284. if (up <= 0)
  1285. up = 0;
  1286. if (dn == 2) {
  1287. /* if retry count< 3 for 2*2 seconds,
  1288. * shrink wifi duration
  1289. */
  1290. if (wait_count <= 2)
  1291. m++; /* avoid bounce in two levels */
  1292. else
  1293. m = 1;
  1294. if (m >= 20) {
  1295. /* m max value is 20, max time is 120 s,
  1296. * recheck if adjust WiFi duration.
  1297. */
  1298. m = 20;
  1299. }
  1300. n = 3*m;
  1301. up = 0;
  1302. dn = 0;
  1303. wait_count = 0;
  1304. result = -1;
  1305. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1306. "[BTCoex], Decrease wifi duration for retryCounter<3!!\n");
  1307. }
  1308. } else {
  1309. /* retry count > 3, if retry count > 3 happens once,
  1310. * shrink WiFi duration
  1311. */
  1312. if (wait_count == 1)
  1313. m++; /* avoid bounce in two levels */
  1314. else
  1315. m = 1;
  1316. /* m max value is 20, max time is 120 second,
  1317. * recheck if adjust WiFi duration.
  1318. */
  1319. if (m >= 20)
  1320. m = 20;
  1321. n = 3*m;
  1322. up = 0;
  1323. dn = 0;
  1324. wait_count = 0;
  1325. result = -1;
  1326. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1327. "[BTCoex], Decrease wifi duration for retryCounter>3!!\n");
  1328. }
  1329. if (result == -1) {
  1330. if ((BT_INFO_8821A_1ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
  1331. ((coex_dm->cur_ps_tdma == 1) ||
  1332. (coex_dm->cur_ps_tdma == 2))) {
  1333. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1334. true, 9);
  1335. coex_dm->tdma_adj_type = 9;
  1336. } else if (coex_dm->cur_ps_tdma == 1) {
  1337. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1338. true, 2);
  1339. coex_dm->tdma_adj_type = 2;
  1340. } else if (coex_dm->cur_ps_tdma == 2) {
  1341. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1342. true, 9);
  1343. coex_dm->tdma_adj_type = 9;
  1344. } else if (coex_dm->cur_ps_tdma == 9) {
  1345. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1346. true, 11);
  1347. coex_dm->tdma_adj_type = 11;
  1348. }
  1349. } else if (result == 1) {
  1350. if ((BT_INFO_8821A_1ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
  1351. ((coex_dm->cur_ps_tdma == 1) ||
  1352. (coex_dm->cur_ps_tdma == 2))) {
  1353. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1354. true, 9);
  1355. coex_dm->tdma_adj_type = 9;
  1356. } else if (coex_dm->cur_ps_tdma == 11) {
  1357. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1358. true, 9);
  1359. coex_dm->tdma_adj_type = 9;
  1360. } else if (coex_dm->cur_ps_tdma == 9) {
  1361. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1362. true, 2);
  1363. coex_dm->tdma_adj_type = 2;
  1364. } else if (coex_dm->cur_ps_tdma == 2) {
  1365. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1366. true, 1);
  1367. coex_dm->tdma_adj_type = 1;
  1368. }
  1369. } else {
  1370. /*no change*/
  1371. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1372. "[BTCoex], ********** TDMA(on, %d) **********\n",
  1373. coex_dm->cur_ps_tdma);
  1374. }
  1375. if (coex_dm->cur_ps_tdma != 1 &&
  1376. coex_dm->cur_ps_tdma != 2 &&
  1377. coex_dm->cur_ps_tdma != 9 &&
  1378. coex_dm->cur_ps_tdma != 11) {
  1379. /* recover to previous adjust type*/
  1380. halbtc8821a1ant_ps_tdma(btcoexist,
  1381. NORMAL_EXEC, true,
  1382. coex_dm->tdma_adj_type);
  1383. }
  1384. }
  1385. }
  1386. static void btc8821a1ant_ps_tdma_check_for_pwr_save(struct btc_coexist *btcoex,
  1387. bool new_ps_state)
  1388. {
  1389. u8 lps_mode = 0x0;
  1390. btcoex->btc_get(btcoex, BTC_GET_U1_LPS_MODE, &lps_mode);
  1391. if (lps_mode) {
  1392. /* already under LPS state*/
  1393. if (new_ps_state) {
  1394. /* keep state under LPS, do nothing.*/
  1395. } else {
  1396. /* will leave LPS state, turn off psTdma first*/
  1397. halbtc8821a1ant_ps_tdma(btcoex, NORMAL_EXEC, false, 0);
  1398. }
  1399. } else {
  1400. /* NO PS state*/
  1401. if (new_ps_state) {
  1402. /* will enter LPS state, turn off psTdma first*/
  1403. halbtc8821a1ant_ps_tdma(btcoex, NORMAL_EXEC, false, 0);
  1404. } else {
  1405. /* keep state under NO PS state, do nothing.*/
  1406. }
  1407. }
  1408. }
  1409. static void halbtc8821a1ant_power_save_state(struct btc_coexist *btcoexist,
  1410. u8 ps_type, u8 lps_val,
  1411. u8 rpwm_val)
  1412. {
  1413. bool low_pwr_disable = false;
  1414. switch (ps_type) {
  1415. case BTC_PS_WIFI_NATIVE:
  1416. /* recover to original 32k low power setting*/
  1417. low_pwr_disable = false;
  1418. btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
  1419. &low_pwr_disable);
  1420. btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
  1421. break;
  1422. case BTC_PS_LPS_ON:
  1423. btc8821a1ant_ps_tdma_check_for_pwr_save(btcoexist,
  1424. true);
  1425. halbtc8821a1ant_lps_rpwm(btcoexist,
  1426. NORMAL_EXEC, lps_val, rpwm_val);
  1427. /* when coex force to enter LPS, do not enter 32k low power.*/
  1428. low_pwr_disable = true;
  1429. btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
  1430. &low_pwr_disable);
  1431. /* power save must executed before psTdma.*/
  1432. btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, NULL);
  1433. break;
  1434. case BTC_PS_LPS_OFF:
  1435. btc8821a1ant_ps_tdma_check_for_pwr_save(btcoexist, false);
  1436. btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
  1437. break;
  1438. default:
  1439. break;
  1440. }
  1441. }
  1442. static void halbtc8821a1ant_coex_under_5g(struct btc_coexist *btcoexist)
  1443. {
  1444. halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1445. 0x0, 0x0);
  1446. halbtc8821a1ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
  1447. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 10);
  1448. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1449. halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  1450. halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 5);
  1451. }
  1452. static void halbtc8821a1ant_action_wifi_only(struct btc_coexist *btcoexist)
  1453. {
  1454. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1455. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 9);
  1456. }
  1457. static void btc8821a1ant_mon_bt_en_dis(struct btc_coexist *btcoexist)
  1458. {
  1459. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1460. static bool pre_bt_disabled;
  1461. static u32 bt_disable_cnt;
  1462. bool bt_active = true, bt_disabled = false;
  1463. /* This function check if bt is disabled*/
  1464. if (coex_sta->high_priority_tx == 0 &&
  1465. coex_sta->high_priority_rx == 0 &&
  1466. coex_sta->low_priority_tx == 0 &&
  1467. coex_sta->low_priority_rx == 0) {
  1468. bt_active = false;
  1469. }
  1470. if (coex_sta->high_priority_tx == 0xffff &&
  1471. coex_sta->high_priority_rx == 0xffff &&
  1472. coex_sta->low_priority_tx == 0xffff &&
  1473. coex_sta->low_priority_rx == 0xffff) {
  1474. bt_active = false;
  1475. }
  1476. if (bt_active) {
  1477. bt_disable_cnt = 0;
  1478. bt_disabled = false;
  1479. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
  1480. &bt_disabled);
  1481. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1482. "[BTCoex], BT is enabled !!\n");
  1483. } else {
  1484. bt_disable_cnt++;
  1485. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1486. "[BTCoex], bt all counters = 0, %d times!!\n",
  1487. bt_disable_cnt);
  1488. if (bt_disable_cnt >= 2) {
  1489. bt_disabled = true;
  1490. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
  1491. &bt_disabled);
  1492. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1493. "[BTCoex], BT is disabled !!\n");
  1494. halbtc8821a1ant_action_wifi_only(btcoexist);
  1495. }
  1496. }
  1497. if (pre_bt_disabled != bt_disabled) {
  1498. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1499. "[BTCoex], BT is from %s to %s!!\n",
  1500. (pre_bt_disabled ? "disabled" : "enabled"),
  1501. (bt_disabled ? "disabled" : "enabled"));
  1502. pre_bt_disabled = bt_disabled;
  1503. if (bt_disabled) {
  1504. btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
  1505. NULL);
  1506. btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
  1507. NULL);
  1508. }
  1509. }
  1510. }
  1511. /*=============================================*/
  1512. /**/
  1513. /* Software Coex Mechanism start*/
  1514. /**/
  1515. /*=============================================*/
  1516. /* SCO only or SCO+PAN(HS)*/
  1517. static void halbtc8821a1ant_action_sco(struct btc_coexist *btcoexist)
  1518. {
  1519. halbtc8821a1ant_sw_mechanism(btcoexist, true);
  1520. }
  1521. static void halbtc8821a1ant_action_hid(struct btc_coexist *btcoexist)
  1522. {
  1523. halbtc8821a1ant_sw_mechanism(btcoexist, true);
  1524. }
  1525. /*A2DP only / PAN(EDR) only/ A2DP+PAN(HS)*/
  1526. static void halbtc8821a1ant_action_a2dp(struct btc_coexist *btcoexist)
  1527. {
  1528. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1529. }
  1530. static void halbtc8821a1ant_action_a2dp_pan_hs(struct btc_coexist *btcoexist)
  1531. {
  1532. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1533. }
  1534. static void halbtc8821a1ant_action_pan_edr(struct btc_coexist *btcoexist)
  1535. {
  1536. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1537. }
  1538. /*PAN(HS) only*/
  1539. static void halbtc8821a1ant_action_pan_hs(struct btc_coexist *btcoexist)
  1540. {
  1541. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1542. }
  1543. /*PAN(EDR)+A2DP*/
  1544. static void halbtc8821a1ant_action_pan_edr_a2dp(struct btc_coexist *btcoexist)
  1545. {
  1546. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1547. }
  1548. static void halbtc8821a1ant_action_pan_edr_hid(struct btc_coexist *btcoexist)
  1549. {
  1550. halbtc8821a1ant_sw_mechanism(btcoexist, true);
  1551. }
  1552. /* HID+A2DP+PAN(EDR)*/
  1553. static void btc8821a1ant_action_hid_a2dp_pan_edr(struct btc_coexist *btcoexist)
  1554. {
  1555. halbtc8821a1ant_sw_mechanism(btcoexist, true);
  1556. }
  1557. static void halbtc8821a1ant_action_hid_a2dp(struct btc_coexist *btcoexist)
  1558. {
  1559. halbtc8821a1ant_sw_mechanism(btcoexist, true);
  1560. }
  1561. /*=============================================*/
  1562. /**/
  1563. /* Non-Software Coex Mechanism start*/
  1564. /**/
  1565. /*=============================================*/
  1566. static void halbtc8821a1ant_action_hs(struct btc_coexist *btcoexist)
  1567. {
  1568. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  1569. halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 2);
  1570. }
  1571. static void halbtc8821a1ant_action_bt_inquiry(struct btc_coexist *btcoexist)
  1572. {
  1573. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1574. bool wifi_connected = false;
  1575. btcoexist->btc_get(btcoexist,
  1576. BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
  1577. if (!wifi_connected) {
  1578. halbtc8821a1ant_power_save_state(btcoexist,
  1579. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1580. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  1581. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1582. } else if ((bt_link_info->sco_exist) ||
  1583. (bt_link_info->hid_only)) {
  1584. /* SCO/HID-only busy*/
  1585. halbtc8821a1ant_power_save_state(btcoexist,
  1586. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1587. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  1588. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1589. } else {
  1590. halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_LPS_ON,
  1591. 0x50, 0x4);
  1592. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 30);
  1593. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1594. }
  1595. }
  1596. static void btc8821a1ant_act_bt_sco_hid_only_busy(struct btc_coexist *btcoexist,
  1597. u8 wifi_status) {
  1598. /* tdma and coex table*/
  1599. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  1600. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1601. }
  1602. static void btc8821a1ant_act_wifi_con_bt_acl_busy(struct btc_coexist *btcoexist,
  1603. u8 wifi_status)
  1604. {
  1605. u8 bt_rssi_state;
  1606. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1607. bt_rssi_state = halbtc8821a1ant_bt_rssi_state(btcoexist, 2, 28, 0);
  1608. if (bt_link_info->hid_only) {
  1609. /*HID*/
  1610. btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist,
  1611. wifi_status);
  1612. coex_dm->auto_tdma_adjust = false;
  1613. return;
  1614. } else if (bt_link_info->a2dp_only) {
  1615. /*A2DP*/
  1616. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  1617. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  1618. btc8821a1ant_tdma_dur_adj(btcoexist, wifi_status);
  1619. } else {
  1620. /*for low BT RSSI*/
  1621. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1622. true, 11);
  1623. coex_dm->auto_tdma_adjust = false;
  1624. }
  1625. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1626. } else if (bt_link_info->hid_exist && bt_link_info->a2dp_exist) {
  1627. /*HID+A2DP*/
  1628. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  1629. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  1630. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1631. true, 14);
  1632. coex_dm->auto_tdma_adjust = false;
  1633. } else {
  1634. /*for low BT RSSI*/
  1635. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1636. true, 11);
  1637. coex_dm->auto_tdma_adjust = false;
  1638. }
  1639. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1640. } else if ((bt_link_info->pan_only) ||
  1641. (bt_link_info->hid_exist && bt_link_info->pan_exist)) {
  1642. /*PAN(OPP, FTP), HID+PAN(OPP, FTP)*/
  1643. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
  1644. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1645. coex_dm->auto_tdma_adjust = false;
  1646. } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
  1647. (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
  1648. bt_link_info->pan_exist)) {
  1649. /*A2DP+PAN(OPP, FTP), HID+A2DP+PAN(OPP, FTP)*/
  1650. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
  1651. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1652. coex_dm->auto_tdma_adjust = false;
  1653. } else {
  1654. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
  1655. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1656. coex_dm->auto_tdma_adjust = false;
  1657. }
  1658. }
  1659. static void halbtc8821a1ant_action_wifi_not_connected(
  1660. struct btc_coexist *btcoexist)
  1661. {
  1662. /* power save state*/
  1663. halbtc8821a1ant_power_save_state(btcoexist,
  1664. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1665. /* tdma and coex table*/
  1666. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1667. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1668. }
  1669. static void btc8821a1ant_act_wifi_not_conn_scan(struct btc_coexist *btcoexist)
  1670. {
  1671. halbtc8821a1ant_power_save_state(btcoexist,
  1672. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1673. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
  1674. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1675. }
  1676. static void halbtc8821a1ant_action_wifi_connected_scan(
  1677. struct btc_coexist *btcoexist) {
  1678. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1679. /* power save state*/
  1680. halbtc8821a1ant_power_save_state(btcoexist,
  1681. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1682. /* tdma and coex table*/
  1683. if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1684. if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) {
  1685. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1686. true, 22);
  1687. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1688. NORMAL_EXEC, 1);
  1689. } else {
  1690. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1691. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1692. }
  1693. } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
  1694. coex_dm->bt_status) ||
  1695. (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1696. coex_dm->bt_status)) {
  1697. btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist,
  1698. BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
  1699. } else {
  1700. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1701. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1702. }
  1703. }
  1704. static void btc8821a1ant_act_wifi_conn_sp_pkt(struct btc_coexist *btcoexist)
  1705. {
  1706. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1707. bool hs_connecting = false;
  1708. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_CONNECTING, &hs_connecting);
  1709. halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1710. 0x0, 0x0);
  1711. /* tdma and coex table*/
  1712. if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1713. if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) {
  1714. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1715. true, 22);
  1716. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1717. NORMAL_EXEC, 1);
  1718. } else {
  1719. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1720. true, 20);
  1721. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1722. NORMAL_EXEC, 1);
  1723. }
  1724. } else {
  1725. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1726. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1727. }
  1728. }
  1729. static void halbtc8821a1ant_action_wifi_connected(struct btc_coexist *btcoexist)
  1730. {
  1731. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1732. bool wifi_busy = false;
  1733. bool scan = false, link = false, roam = false;
  1734. bool under_4way = false;
  1735. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1736. "[BTCoex], CoexForWifiConnect()===>\n");
  1737. btcoexist->btc_get(btcoexist,
  1738. BTC_GET_BL_WIFI_4_WAY_PROGRESS, &under_4way);
  1739. if (under_4way) {
  1740. btc8821a1ant_act_wifi_conn_sp_pkt(btcoexist);
  1741. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1742. "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
  1743. return;
  1744. }
  1745. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  1746. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  1747. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  1748. if (scan || link || roam) {
  1749. halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
  1750. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1751. "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
  1752. return;
  1753. }
  1754. /* power save state*/
  1755. if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY ==
  1756. coex_dm->bt_status && !btcoexist->bt_link_info.hid_only)
  1757. halbtc8821a1ant_power_save_state(btcoexist,
  1758. BTC_PS_LPS_ON, 0x50, 0x4);
  1759. else
  1760. halbtc8821a1ant_power_save_state(btcoexist,
  1761. BTC_PS_WIFI_NATIVE,
  1762. 0x0, 0x0);
  1763. /* tdma and coex table*/
  1764. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1765. if (!wifi_busy) {
  1766. if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1767. btc8821a1ant_act_wifi_con_bt_acl_busy(btcoexist,
  1768. BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
  1769. } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
  1770. coex_dm->bt_status) ||
  1771. (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1772. coex_dm->bt_status)) {
  1773. btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist,
  1774. BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
  1775. } else {
  1776. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1777. true, 5);
  1778. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1779. NORMAL_EXEC, 2);
  1780. }
  1781. } else {
  1782. if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1783. btc8821a1ant_act_wifi_con_bt_acl_busy(btcoexist,
  1784. BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
  1785. } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
  1786. coex_dm->bt_status) ||
  1787. (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1788. coex_dm->bt_status)) {
  1789. btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist,
  1790. BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
  1791. } else {
  1792. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1793. true, 5);
  1794. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1795. NORMAL_EXEC, 2);
  1796. }
  1797. }
  1798. }
  1799. static void btc8821a1ant_run_sw_coex_mech(struct btc_coexist *btcoexist)
  1800. {
  1801. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1802. u8 algorithm = 0;
  1803. algorithm = halbtc8821a1ant_action_algorithm(btcoexist);
  1804. coex_dm->cur_algorithm = algorithm;
  1805. if (!halbtc8821a1ant_is_common_action(btcoexist)) {
  1806. switch (coex_dm->cur_algorithm) {
  1807. case BT_8821A_1ANT_COEX_ALGO_SCO:
  1808. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1809. "[BTCoex], Action algorithm = SCO\n");
  1810. halbtc8821a1ant_action_sco(btcoexist);
  1811. break;
  1812. case BT_8821A_1ANT_COEX_ALGO_HID:
  1813. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1814. "[BTCoex], Action algorithm = HID\n");
  1815. halbtc8821a1ant_action_hid(btcoexist);
  1816. break;
  1817. case BT_8821A_1ANT_COEX_ALGO_A2DP:
  1818. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1819. "[BTCoex], Action algorithm = A2DP\n");
  1820. halbtc8821a1ant_action_a2dp(btcoexist);
  1821. break;
  1822. case BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS:
  1823. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1824. "[BTCoex], Action algorithm = A2DP+PAN(HS)\n");
  1825. halbtc8821a1ant_action_a2dp_pan_hs(btcoexist);
  1826. break;
  1827. case BT_8821A_1ANT_COEX_ALGO_PANEDR:
  1828. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1829. "[BTCoex], Action algorithm = PAN(EDR)\n");
  1830. halbtc8821a1ant_action_pan_edr(btcoexist);
  1831. break;
  1832. case BT_8821A_1ANT_COEX_ALGO_PANHS:
  1833. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1834. "[BTCoex], Action algorithm = HS mode\n");
  1835. halbtc8821a1ant_action_pan_hs(btcoexist);
  1836. break;
  1837. case BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP:
  1838. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1839. "[BTCoex], Action algorithm = PAN+A2DP\n");
  1840. halbtc8821a1ant_action_pan_edr_a2dp(btcoexist);
  1841. break;
  1842. case BT_8821A_1ANT_COEX_ALGO_PANEDR_HID:
  1843. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1844. "[BTCoex], Action algorithm = PAN(EDR)+HID\n");
  1845. halbtc8821a1ant_action_pan_edr_hid(btcoexist);
  1846. break;
  1847. case BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
  1848. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1849. "[BTCoex], Action algorithm = HID+A2DP+PAN\n");
  1850. btc8821a1ant_action_hid_a2dp_pan_edr(btcoexist);
  1851. break;
  1852. case BT_8821A_1ANT_COEX_ALGO_HID_A2DP:
  1853. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1854. "[BTCoex], Action algorithm = HID+A2DP\n");
  1855. halbtc8821a1ant_action_hid_a2dp(btcoexist);
  1856. break;
  1857. default:
  1858. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1859. "[BTCoex], Action algorithm = coexist All Off!!\n");
  1860. /*halbtc8821a1ant_coex_all_off(btcoexist);*/
  1861. break;
  1862. }
  1863. coex_dm->pre_algorithm = coex_dm->cur_algorithm;
  1864. }
  1865. }
  1866. static void halbtc8821a1ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
  1867. {
  1868. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1869. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1870. bool wifi_connected = false, bt_hs_on = false;
  1871. bool increase_scan_dev_num = false;
  1872. bool bt_ctrl_agg_buf_size = false;
  1873. u8 agg_buf_size = 5;
  1874. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  1875. bool wifi_under_5g = false;
  1876. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1877. "[BTCoex], RunCoexistMechanism()===>\n");
  1878. if (btcoexist->manual_control) {
  1879. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1880. "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
  1881. return;
  1882. }
  1883. if (btcoexist->stop_coex_dm) {
  1884. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1885. "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
  1886. return;
  1887. }
  1888. if (coex_sta->under_ips) {
  1889. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1890. "[BTCoex], wifi is under IPS !!!\n");
  1891. return;
  1892. }
  1893. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  1894. if (wifi_under_5g) {
  1895. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1896. "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
  1897. halbtc8821a1ant_coex_under_5g(btcoexist);
  1898. return;
  1899. }
  1900. if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  1901. (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  1902. (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
  1903. increase_scan_dev_num = true;
  1904. btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
  1905. &increase_scan_dev_num);
  1906. btcoexist->btc_get(btcoexist,
  1907. BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
  1908. if (!bt_link_info->sco_exist && !bt_link_info->hid_exist) {
  1909. halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  1910. } else {
  1911. if (wifi_connected) {
  1912. wifi_rssi_state =
  1913. halbtc8821a1ant_WifiRssiState(btcoexist, 1, 2,
  1914. 30, 0);
  1915. halbtc8821a1ant_limited_tx(btcoexist,
  1916. NORMAL_EXEC, 1, 1, 1, 1);
  1917. } else {
  1918. halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC,
  1919. 0, 0, 0, 0);
  1920. }
  1921. }
  1922. if (bt_link_info->sco_exist) {
  1923. bt_ctrl_agg_buf_size = true;
  1924. agg_buf_size = 0x3;
  1925. } else if (bt_link_info->hid_exist) {
  1926. bt_ctrl_agg_buf_size = true;
  1927. agg_buf_size = 0x5;
  1928. } else if (bt_link_info->a2dp_exist || bt_link_info->pan_exist) {
  1929. bt_ctrl_agg_buf_size = true;
  1930. agg_buf_size = 0x8;
  1931. }
  1932. halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  1933. bt_ctrl_agg_buf_size, agg_buf_size);
  1934. btc8821a1ant_run_sw_coex_mech(btcoexist);
  1935. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  1936. if (coex_sta->c2h_bt_inquiry_page) {
  1937. halbtc8821a1ant_action_bt_inquiry(btcoexist);
  1938. return;
  1939. } else if (bt_hs_on) {
  1940. halbtc8821a1ant_action_hs(btcoexist);
  1941. return;
  1942. }
  1943. if (!wifi_connected) {
  1944. bool scan = false, link = false, roam = false;
  1945. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1946. "[BTCoex], wifi is non connected-idle !!!\n");
  1947. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  1948. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  1949. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  1950. if (scan || link || roam)
  1951. btc8821a1ant_act_wifi_not_conn_scan(btcoexist);
  1952. else
  1953. halbtc8821a1ant_action_wifi_not_connected(btcoexist);
  1954. } else {
  1955. /* wifi LPS/Busy*/
  1956. halbtc8821a1ant_action_wifi_connected(btcoexist);
  1957. }
  1958. }
  1959. static void halbtc8821a1ant_init_coex_dm(struct btc_coexist *btcoexist)
  1960. {
  1961. /* force to reset coex mechanism*/
  1962. /* sw all off*/
  1963. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1964. halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
  1965. halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  1966. }
  1967. static void halbtc8821a1ant_init_hw_config(struct btc_coexist *btcoexist,
  1968. bool back_up)
  1969. {
  1970. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1971. u8 u1_tmp = 0;
  1972. bool wifi_under_5g = false;
  1973. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1974. "[BTCoex], 1Ant Init HW Config!!\n");
  1975. if (back_up) {
  1976. coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
  1977. 0x430);
  1978. coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
  1979. 0x434);
  1980. coex_dm->backup_retry_limit =
  1981. btcoexist->btc_read_2byte(btcoexist, 0x42a);
  1982. coex_dm->backup_ampdu_max_time =
  1983. btcoexist->btc_read_1byte(btcoexist, 0x456);
  1984. }
  1985. /* 0x790[5:0] = 0x5*/
  1986. u1_tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
  1987. u1_tmp &= 0xc0;
  1988. u1_tmp |= 0x5;
  1989. btcoexist->btc_write_1byte(btcoexist, 0x790, u1_tmp);
  1990. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  1991. /*Antenna config*/
  1992. if (wifi_under_5g)
  1993. halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
  1994. true, false);
  1995. else
  1996. halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
  1997. true, false);
  1998. /* PTA parameter*/
  1999. halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  2000. /* Enable counter statistics*/
  2001. /*0x76e[3] =1, WLAN_Act control by PTA*/
  2002. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
  2003. btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
  2004. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
  2005. }
  2006. /*============================================================*/
  2007. /* work around function start with wa_halbtc8821a1ant_*/
  2008. /*============================================================*/
  2009. /*============================================================*/
  2010. /* extern function start with EXhalbtc8821a1ant_*/
  2011. /*============================================================*/
  2012. void ex_halbtc8821a1ant_init_hwconfig(struct btc_coexist *btcoexist)
  2013. {
  2014. halbtc8821a1ant_init_hw_config(btcoexist, true);
  2015. }
  2016. void ex_halbtc8821a1ant_init_coex_dm(struct btc_coexist *btcoexist)
  2017. {
  2018. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2019. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2020. "[BTCoex], Coex Mechanism Init!!\n");
  2021. btcoexist->stop_coex_dm = false;
  2022. halbtc8821a1ant_init_coex_dm(btcoexist);
  2023. halbtc8821a1ant_query_bt_info(btcoexist);
  2024. }
  2025. void ex_halbtc8821a1ant_display_coex_info(struct btc_coexist *btcoexist)
  2026. {
  2027. struct btc_board_info *board_info = &btcoexist->board_info;
  2028. struct btc_stack_info *stack_info = &btcoexist->stack_info;
  2029. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2030. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2031. u8 u1_tmp[4], i, bt_info_ext, ps_tdma_case = 0;
  2032. u16 u2_tmp[4];
  2033. u32 u4_tmp[4];
  2034. bool roam = false, scan = false, link = false, wifi_under_5g = false;
  2035. bool bt_hs_on = false, wifi_busy = false;
  2036. long wifi_rssi = 0, bt_hs_rssi = 0;
  2037. u32 wifi_bw, wifi_traffic_dir;
  2038. u8 wifi_dot11_chnl, wifi_hs_chnl;
  2039. u32 fw_ver = 0, bt_patch_ver = 0;
  2040. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2041. "\r\n ============[BT Coexist info]============");
  2042. if (btcoexist->manual_control) {
  2043. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2044. "\r\n ============[Under Manual Control]============");
  2045. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2046. "\r\n ==========================================");
  2047. }
  2048. if (btcoexist->stop_coex_dm) {
  2049. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2050. "\r\n ============[Coex is STOPPED]============");
  2051. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2052. "\r\n ==========================================");
  2053. }
  2054. if (!board_info->bt_exist) {
  2055. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n BT not exists !!!");
  2056. return;
  2057. }
  2058. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2059. "\r\n %-35s = %d/ %d/ %d",
  2060. "Ant PG Num/ Ant Mech/ Ant Pos:",
  2061. board_info->pg_ant_num,
  2062. board_info->btdm_ant_num,
  2063. board_info->btdm_ant_pos);
  2064. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2065. "\r\n %-35s = %s / %d", "BT stack/ hci ext ver",
  2066. ((stack_info->profile_notified) ? "Yes" : "No"),
  2067. stack_info->hci_version);
  2068. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
  2069. &bt_patch_ver);
  2070. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  2071. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2072. "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
  2073. "CoexVer/ FwVer/ PatchVer",
  2074. glcoex_ver_date_8821a_1ant,
  2075. glcoex_ver_8821a_1ant,
  2076. fw_ver, bt_patch_ver,
  2077. bt_patch_ver);
  2078. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION,
  2079. &bt_hs_on);
  2080. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL,
  2081. &wifi_dot11_chnl);
  2082. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL,
  2083. &wifi_hs_chnl);
  2084. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2085. "\r\n %-35s = %d / %d(%d)",
  2086. "Dot11 channel / HsChnl(HsMode)",
  2087. wifi_dot11_chnl, wifi_hs_chnl, bt_hs_on);
  2088. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2089. "\r\n %-35s = %3ph ",
  2090. "H2C Wifi inform bt chnl Info",
  2091. coex_dm->wifi_chnl_info);
  2092. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  2093. btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
  2094. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2095. "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi",
  2096. (int)wifi_rssi, (int)bt_hs_rssi);
  2097. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  2098. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  2099. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  2100. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2101. "\r\n %-35s = %d/ %d/ %d ", "Wifi link/ roam/ scan",
  2102. link, roam, scan);
  2103. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
  2104. &wifi_under_5g);
  2105. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW,
  2106. &wifi_bw);
  2107. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY,
  2108. &wifi_busy);
  2109. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
  2110. &wifi_traffic_dir);
  2111. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2112. "\r\n %-35s = %s / %s/ %s ", "Wifi status",
  2113. (wifi_under_5g ? "5G" : "2.4G"),
  2114. ((wifi_bw == BTC_WIFI_BW_LEGACY) ? "Legacy" :
  2115. (((wifi_bw == BTC_WIFI_BW_HT40) ? "HT40" : "HT20"))),
  2116. ((!wifi_busy) ? "idle" :
  2117. ((wifi_traffic_dir == BTC_WIFI_TRAFFIC_TX) ?
  2118. "uplink" : "downlink")));
  2119. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2120. "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]",
  2121. ((btcoexist->bt_info.bt_disabled) ? ("disabled") :
  2122. ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") :
  2123. ((BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  2124. coex_dm->bt_status) ?
  2125. "non-connected idle" :
  2126. ((BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE ==
  2127. coex_dm->bt_status) ?
  2128. "connected-idle" : "busy")))),
  2129. coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
  2130. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2131. "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
  2132. bt_link_info->sco_exist,
  2133. bt_link_info->hid_exist,
  2134. bt_link_info->pan_exist,
  2135. bt_link_info->a2dp_exist);
  2136. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
  2137. bt_info_ext = coex_sta->bt_info_ext;
  2138. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2139. "\r\n %-35s = %s",
  2140. "BT Info A2DP rate",
  2141. (bt_info_ext & BIT0) ?
  2142. "Basic rate" : "EDR rate");
  2143. for (i = 0; i < BT_INFO_SRC_8821A_1ANT_MAX; i++) {
  2144. if (coex_sta->bt_info_c2h_cnt[i]) {
  2145. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2146. "\r\n %-35s = %7ph(%d)",
  2147. glbt_info_src_8821a_1ant[i],
  2148. coex_sta->bt_info_c2h[i],
  2149. coex_sta->bt_info_c2h_cnt[i]);
  2150. }
  2151. }
  2152. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2153. "\r\n %-35s = %s/%s, (0x%x/0x%x)",
  2154. "PS state, IPS/LPS, (lps/rpwm)",
  2155. ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")),
  2156. ((coex_sta->under_Lps ? "LPS ON" : "LPS OFF")),
  2157. btcoexist->bt_info.lps_val,
  2158. btcoexist->bt_info.rpwm_val);
  2159. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
  2160. if (!btcoexist->manual_control) {
  2161. /* Sw mechanism*/
  2162. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2163. "\r\n %-35s",
  2164. "============[Sw mechanism]============");
  2165. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2166. "\r\n %-35s = %d", "SM[LowPenaltyRA]",
  2167. coex_dm->cur_low_penalty_ra);
  2168. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2169. "\r\n %-35s = %s/ %s/ %d ",
  2170. "DelBA/ BtCtrlAgg/ AggSize",
  2171. (btcoexist->bt_info.reject_agg_pkt ? "Yes" : "No"),
  2172. (btcoexist->bt_info.bt_ctrl_buf_size ? "Yes" : "No"),
  2173. btcoexist->bt_info.agg_buf_size);
  2174. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2175. "\r\n %-35s = 0x%x ", "Rate Mask",
  2176. btcoexist->bt_info.ra_mask);
  2177. /* Fw mechanism*/
  2178. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
  2179. "============[Fw mechanism]============");
  2180. ps_tdma_case = coex_dm->cur_ps_tdma;
  2181. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2182. "\r\n %-35s = %5ph case-%d (auto:%d)",
  2183. "PS TDMA",
  2184. coex_dm->ps_tdma_para,
  2185. ps_tdma_case,
  2186. coex_dm->auto_tdma_adjust);
  2187. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2188. "\r\n %-35s = 0x%x ",
  2189. "Latest error condition(should be 0)",
  2190. coex_dm->error_condition);
  2191. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2192. "\r\n %-35s = %d ", "IgnWlanAct",
  2193. coex_dm->cur_ignore_wlan_act);
  2194. }
  2195. /* Hw setting*/
  2196. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2197. "\r\n %-35s", "============[Hw setting]============");
  2198. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2199. "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
  2200. "backup ARFR1/ARFR2/RL/AMaxTime",
  2201. coex_dm->backup_arfr_cnt1,
  2202. coex_dm->backup_arfr_cnt2,
  2203. coex_dm->backup_retry_limit,
  2204. coex_dm->backup_ampdu_max_time);
  2205. u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
  2206. u4_tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
  2207. u2_tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
  2208. u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
  2209. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2210. "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
  2211. "0x430/0x434/0x42a/0x456",
  2212. u4_tmp[0], u4_tmp[1], u2_tmp[0], u1_tmp[0]);
  2213. u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
  2214. u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc58);
  2215. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2216. "\r\n %-35s = 0x%x/ 0x%x", "0x778/ 0xc58[29:25]",
  2217. u1_tmp[0], (u4_tmp[0] & 0x3e000000) >> 25);
  2218. u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db);
  2219. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2220. "\r\n %-35s = 0x%x", "0x8db[6:5]",
  2221. ((u1_tmp[0] & 0x60) >> 5));
  2222. u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x975);
  2223. u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
  2224. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2225. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  2226. "0xcb4[29:28]/0xcb4[7:0]/0x974[9:8]",
  2227. (u4_tmp[0] & 0x30000000) >> 28,
  2228. u4_tmp[0] & 0xff,
  2229. u1_tmp[0] & 0x3);
  2230. u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
  2231. u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  2232. u1_tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x64);
  2233. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2234. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  2235. "0x40/0x4c[24:23]/0x64[0]",
  2236. u1_tmp[0], ((u4_tmp[0] & 0x01800000) >> 23), u1_tmp[1] & 0x1);
  2237. u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
  2238. u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
  2239. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2240. "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522",
  2241. u4_tmp[0], u1_tmp[0]);
  2242. u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
  2243. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2244. "\r\n %-35s = 0x%x", "0xc50(dig)",
  2245. u4_tmp[0] & 0xff);
  2246. u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xf48);
  2247. u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5d);
  2248. u1_tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
  2249. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2250. "\r\n %-35s = 0x%x/ 0x%x", "OFDM-FA/ CCK-FA",
  2251. u4_tmp[0], (u1_tmp[0] << 8) + u1_tmp[1]);
  2252. u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
  2253. u4_tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
  2254. u4_tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
  2255. u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
  2256. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2257. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  2258. "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
  2259. u4_tmp[0], u4_tmp[1], u4_tmp[2], u1_tmp[0]);
  2260. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2261. "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)",
  2262. coex_sta->high_priority_rx, coex_sta->high_priority_tx);
  2263. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2264. "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)",
  2265. coex_sta->low_priority_rx, coex_sta->low_priority_tx);
  2266. #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 1)
  2267. halbtc8821a1ant_monitor_bt_ctr(btcoexist);
  2268. #endif
  2269. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
  2270. }
  2271. void ex_halbtc8821a1ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
  2272. {
  2273. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2274. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  2275. return;
  2276. if (BTC_IPS_ENTER == type) {
  2277. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2278. "[BTCoex], IPS ENTER notify\n");
  2279. coex_sta->under_ips = true;
  2280. halbtc8821a1ant_set_ant_path(btcoexist,
  2281. BTC_ANT_PATH_BT, false, true);
  2282. /*set PTA control*/
  2283. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  2284. halbtc8821a1ant_coex_table_with_type(btcoexist,
  2285. NORMAL_EXEC, 0);
  2286. } else if (BTC_IPS_LEAVE == type) {
  2287. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2288. "[BTCoex], IPS LEAVE notify\n");
  2289. coex_sta->under_ips = false;
  2290. halbtc8821a1ant_run_coexist_mechanism(btcoexist);
  2291. }
  2292. }
  2293. void ex_halbtc8821a1ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
  2294. {
  2295. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2296. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  2297. return;
  2298. if (BTC_LPS_ENABLE == type) {
  2299. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2300. "[BTCoex], LPS ENABLE notify\n");
  2301. coex_sta->under_Lps = true;
  2302. } else if (BTC_LPS_DISABLE == type) {
  2303. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2304. "[BTCoex], LPS DISABLE notify\n");
  2305. coex_sta->under_Lps = false;
  2306. }
  2307. }
  2308. void ex_halbtc8821a1ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
  2309. {
  2310. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2311. bool wifi_connected = false, bt_hs_on = false;
  2312. if (btcoexist->manual_control ||
  2313. btcoexist->stop_coex_dm ||
  2314. btcoexist->bt_info.bt_disabled)
  2315. return;
  2316. btcoexist->btc_get(btcoexist,
  2317. BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2318. btcoexist->btc_get(btcoexist,
  2319. BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
  2320. halbtc8821a1ant_query_bt_info(btcoexist);
  2321. if (coex_sta->c2h_bt_inquiry_page) {
  2322. halbtc8821a1ant_action_bt_inquiry(btcoexist);
  2323. return;
  2324. } else if (bt_hs_on) {
  2325. halbtc8821a1ant_action_hs(btcoexist);
  2326. return;
  2327. }
  2328. if (BTC_SCAN_START == type) {
  2329. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2330. "[BTCoex], SCAN START notify\n");
  2331. if (!wifi_connected) {
  2332. /* non-connected scan*/
  2333. btc8821a1ant_act_wifi_not_conn_scan(btcoexist);
  2334. } else {
  2335. /* wifi is connected*/
  2336. halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
  2337. }
  2338. } else if (BTC_SCAN_FINISH == type) {
  2339. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2340. "[BTCoex], SCAN FINISH notify\n");
  2341. if (!wifi_connected) {
  2342. /* non-connected scan*/
  2343. halbtc8821a1ant_action_wifi_not_connected(btcoexist);
  2344. } else {
  2345. halbtc8821a1ant_action_wifi_connected(btcoexist);
  2346. }
  2347. }
  2348. }
  2349. void ex_halbtc8821a1ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
  2350. {
  2351. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2352. bool wifi_connected = false, bt_hs_on = false;
  2353. if (btcoexist->manual_control ||
  2354. btcoexist->stop_coex_dm ||
  2355. btcoexist->bt_info.bt_disabled)
  2356. return;
  2357. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2358. if (coex_sta->c2h_bt_inquiry_page) {
  2359. halbtc8821a1ant_action_bt_inquiry(btcoexist);
  2360. return;
  2361. } else if (bt_hs_on) {
  2362. halbtc8821a1ant_action_hs(btcoexist);
  2363. return;
  2364. }
  2365. if (BTC_ASSOCIATE_START == type) {
  2366. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2367. "[BTCoex], CONNECT START notify\n");
  2368. btc8821a1ant_act_wifi_not_conn_scan(btcoexist);
  2369. } else if (BTC_ASSOCIATE_FINISH == type) {
  2370. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2371. "[BTCoex], CONNECT FINISH notify\n");
  2372. btcoexist->btc_get(btcoexist,
  2373. BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
  2374. if (!wifi_connected) {
  2375. /* non-connected scan*/
  2376. halbtc8821a1ant_action_wifi_not_connected(btcoexist);
  2377. } else {
  2378. halbtc8821a1ant_action_wifi_connected(btcoexist);
  2379. }
  2380. }
  2381. }
  2382. void ex_halbtc8821a1ant_media_status_notify(struct btc_coexist *btcoexist,
  2383. u8 type)
  2384. {
  2385. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2386. u8 h2c_parameter[3] = {0};
  2387. u32 wifi_bw;
  2388. u8 wifi_central_chnl;
  2389. if (btcoexist->manual_control ||
  2390. btcoexist->stop_coex_dm ||
  2391. btcoexist->bt_info.bt_disabled)
  2392. return;
  2393. if (BTC_MEDIA_CONNECT == type) {
  2394. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2395. "[BTCoex], MEDIA connect notify\n");
  2396. } else {
  2397. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2398. "[BTCoex], MEDIA disconnect notify\n");
  2399. }
  2400. /* only 2.4G we need to inform bt the chnl mask*/
  2401. btcoexist->btc_get(btcoexist,
  2402. BTC_GET_U1_WIFI_CENTRAL_CHNL,
  2403. &wifi_central_chnl);
  2404. if ((BTC_MEDIA_CONNECT == type) &&
  2405. (wifi_central_chnl <= 14)) {
  2406. /*h2c_parameter[0] = 0x1;*/
  2407. h2c_parameter[0] = 0x0;
  2408. h2c_parameter[1] = wifi_central_chnl;
  2409. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2410. if (BTC_WIFI_BW_HT40 == wifi_bw)
  2411. h2c_parameter[2] = 0x30;
  2412. else
  2413. h2c_parameter[2] = 0x20;
  2414. }
  2415. coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
  2416. coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
  2417. coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
  2418. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2419. "[BTCoex], FW write 0x66 = 0x%x\n",
  2420. h2c_parameter[0] << 16 |
  2421. h2c_parameter[1] << 8 |
  2422. h2c_parameter[2]);
  2423. btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
  2424. }
  2425. void ex_halbtc8821a1ant_special_packet_notify(struct btc_coexist *btcoexist,
  2426. u8 type)
  2427. {
  2428. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2429. bool bt_hs_on = false;
  2430. if (btcoexist->manual_control ||
  2431. btcoexist->stop_coex_dm ||
  2432. btcoexist->bt_info.bt_disabled)
  2433. return;
  2434. coex_sta->special_pkt_period_cnt = 0;
  2435. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2436. if (coex_sta->c2h_bt_inquiry_page) {
  2437. halbtc8821a1ant_action_bt_inquiry(btcoexist);
  2438. return;
  2439. } else if (bt_hs_on) {
  2440. halbtc8821a1ant_action_hs(btcoexist);
  2441. return;
  2442. }
  2443. if (BTC_PACKET_DHCP == type ||
  2444. BTC_PACKET_EAPOL == type) {
  2445. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2446. "[BTCoex], special Packet(%d) notify\n", type);
  2447. btc8821a1ant_act_wifi_conn_sp_pkt(btcoexist);
  2448. }
  2449. }
  2450. void ex_halbtc8821a1ant_bt_info_notify(struct btc_coexist *btcoexist,
  2451. u8 *tmp_buf, u8 length)
  2452. {
  2453. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2454. u8 bt_info = 0;
  2455. u8 i, rsp_source = 0;
  2456. bool wifi_connected = false;
  2457. bool bt_busy = false;
  2458. bool wifi_under_5g = false;
  2459. coex_sta->c2h_bt_info_req_sent = false;
  2460. btcoexist->btc_get(btcoexist,
  2461. BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  2462. rsp_source = tmp_buf[0]&0xf;
  2463. if (rsp_source >= BT_INFO_SRC_8821A_1ANT_MAX)
  2464. rsp_source = BT_INFO_SRC_8821A_1ANT_WIFI_FW;
  2465. coex_sta->bt_info_c2h_cnt[rsp_source]++;
  2466. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2467. "[BTCoex], Bt info[%d], length = %d, hex data = [",
  2468. rsp_source, length);
  2469. for (i = 0; i < length; i++) {
  2470. coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
  2471. if (i == 1)
  2472. bt_info = tmp_buf[i];
  2473. if (i == length-1) {
  2474. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2475. "0x%02x]\n", tmp_buf[i]);
  2476. } else {
  2477. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2478. "0x%02x, ", tmp_buf[i]);
  2479. }
  2480. }
  2481. if (BT_INFO_SRC_8821A_1ANT_WIFI_FW != rsp_source) {
  2482. coex_sta->bt_retry_cnt = /* [3:0]*/
  2483. coex_sta->bt_info_c2h[rsp_source][2]&0xf;
  2484. coex_sta->bt_rssi =
  2485. coex_sta->bt_info_c2h[rsp_source][3]*2+10;
  2486. coex_sta->bt_info_ext =
  2487. coex_sta->bt_info_c2h[rsp_source][4];
  2488. /* Here we need to resend some wifi info to BT*/
  2489. /* because bt is reset and loss of the info.*/
  2490. if (coex_sta->bt_info_ext & BIT1) {
  2491. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2492. "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
  2493. btcoexist->btc_get(btcoexist,
  2494. BTC_GET_BL_WIFI_CONNECTED,
  2495. &wifi_connected);
  2496. if (wifi_connected) {
  2497. ex_halbtc8821a1ant_media_status_notify(btcoexist,
  2498. BTC_MEDIA_CONNECT);
  2499. } else {
  2500. ex_halbtc8821a1ant_media_status_notify(btcoexist,
  2501. BTC_MEDIA_DISCONNECT);
  2502. }
  2503. }
  2504. if ((coex_sta->bt_info_ext & BIT3) && !wifi_under_5g) {
  2505. if (!btcoexist->manual_control &&
  2506. !btcoexist->stop_coex_dm) {
  2507. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2508. "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
  2509. halbtc8821a1ant_ignore_wlan_act(btcoexist,
  2510. FORCE_EXEC,
  2511. false);
  2512. }
  2513. }
  2514. #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)
  2515. if (!(coex_sta->bt_info_ext & BIT4)) {
  2516. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2517. "[BTCoex], BT ext info bit4 check, set BT to enable Auto Report!!\n");
  2518. halbtc8821a1ant_bt_auto_report(btcoexist,
  2519. FORCE_EXEC, true);
  2520. }
  2521. #endif
  2522. }
  2523. /* check BIT2 first ==> check if bt is under inquiry or page scan*/
  2524. if (bt_info & BT_INFO_8821A_1ANT_B_INQ_PAGE)
  2525. coex_sta->c2h_bt_inquiry_page = true;
  2526. else
  2527. coex_sta->c2h_bt_inquiry_page = false;
  2528. /* set link exist status*/
  2529. if (!(bt_info&BT_INFO_8821A_1ANT_B_CONNECTION)) {
  2530. coex_sta->bt_link_exist = false;
  2531. coex_sta->pan_exist = false;
  2532. coex_sta->a2dp_exist = false;
  2533. coex_sta->hid_exist = false;
  2534. coex_sta->sco_exist = false;
  2535. } else {
  2536. /* connection exists*/
  2537. coex_sta->bt_link_exist = true;
  2538. if (bt_info & BT_INFO_8821A_1ANT_B_FTP)
  2539. coex_sta->pan_exist = true;
  2540. else
  2541. coex_sta->pan_exist = false;
  2542. if (bt_info & BT_INFO_8821A_1ANT_B_A2DP)
  2543. coex_sta->a2dp_exist = true;
  2544. else
  2545. coex_sta->a2dp_exist = false;
  2546. if (bt_info & BT_INFO_8821A_1ANT_B_HID)
  2547. coex_sta->hid_exist = true;
  2548. else
  2549. coex_sta->hid_exist = false;
  2550. if (bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO)
  2551. coex_sta->sco_exist = true;
  2552. else
  2553. coex_sta->sco_exist = false;
  2554. }
  2555. halbtc8821a1ant_update_bt_link_info(btcoexist);
  2556. if (!(bt_info&BT_INFO_8821A_1ANT_B_CONNECTION)) {
  2557. coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
  2558. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2559. "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
  2560. } else if (bt_info == BT_INFO_8821A_1ANT_B_CONNECTION) {
  2561. /* connection exists but no busy*/
  2562. coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE;
  2563. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2564. "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
  2565. } else if ((bt_info&BT_INFO_8821A_1ANT_B_SCO_ESCO) ||
  2566. (bt_info&BT_INFO_8821A_1ANT_B_SCO_BUSY)) {
  2567. coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_SCO_BUSY;
  2568. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2569. "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
  2570. } else if (bt_info&BT_INFO_8821A_1ANT_B_ACL_BUSY) {
  2571. if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
  2572. coex_dm->auto_tdma_adjust = false;
  2573. coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_ACL_BUSY;
  2574. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2575. "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
  2576. } else {
  2577. coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_MAX;
  2578. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2579. "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
  2580. }
  2581. if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  2582. (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  2583. (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
  2584. bt_busy = true;
  2585. else
  2586. bt_busy = false;
  2587. btcoexist->btc_set(btcoexist,
  2588. BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  2589. halbtc8821a1ant_run_coexist_mechanism(btcoexist);
  2590. }
  2591. void ex_halbtc8821a1ant_halt_notify(struct btc_coexist *btcoexist)
  2592. {
  2593. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2594. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2595. "[BTCoex], Halt notify\n");
  2596. btcoexist->stop_coex_dm = true;
  2597. halbtc8821a1ant_set_ant_path(btcoexist,
  2598. BTC_ANT_PATH_BT, false, true);
  2599. halbtc8821a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  2600. halbtc8821a1ant_power_save_state(btcoexist,
  2601. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  2602. halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
  2603. ex_halbtc8821a1ant_media_status_notify(btcoexist,
  2604. BTC_MEDIA_DISCONNECT);
  2605. }
  2606. void ex_halbtc8821a1ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
  2607. {
  2608. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2609. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2610. "[BTCoex], Pnp notify\n");
  2611. if (BTC_WIFI_PNP_SLEEP == pnp_state) {
  2612. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2613. "[BTCoex], Pnp notify to SLEEP\n");
  2614. btcoexist->stop_coex_dm = true;
  2615. halbtc8821a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  2616. halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  2617. 0x0, 0x0);
  2618. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 9);
  2619. } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
  2620. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2621. "[BTCoex], Pnp notify to WAKE UP\n");
  2622. btcoexist->stop_coex_dm = false;
  2623. halbtc8821a1ant_init_hw_config(btcoexist, false);
  2624. halbtc8821a1ant_init_coex_dm(btcoexist);
  2625. halbtc8821a1ant_query_bt_info(btcoexist);
  2626. }
  2627. }
  2628. void ex_halbtc8821a1ant_periodical(struct btc_coexist *btcoexist)
  2629. {
  2630. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2631. static u8 dis_ver_info_cnt;
  2632. u32 fw_ver = 0, bt_patch_ver = 0;
  2633. struct btc_board_info *board_info = &btcoexist->board_info;
  2634. struct btc_stack_info *stack_info = &btcoexist->stack_info;
  2635. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2636. "[BTCoex], ==========================Periodical===========================\n");
  2637. if (dis_ver_info_cnt <= 5) {
  2638. dis_ver_info_cnt += 1;
  2639. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2640. "[BTCoex], ****************************************************************\n");
  2641. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2642. "[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
  2643. board_info->pg_ant_num,
  2644. board_info->btdm_ant_num,
  2645. board_info->btdm_ant_pos);
  2646. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2647. "[BTCoex], BT stack/ hci ext ver = %s / %d\n",
  2648. stack_info->profile_notified ? "Yes" : "No",
  2649. stack_info->hci_version);
  2650. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
  2651. &bt_patch_ver);
  2652. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  2653. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2654. "[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
  2655. glcoex_ver_date_8821a_1ant,
  2656. glcoex_ver_8821a_1ant,
  2657. fw_ver, bt_patch_ver,
  2658. bt_patch_ver);
  2659. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  2660. "[BTCoex], ****************************************************************\n");
  2661. }
  2662. #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)
  2663. halbtc8821a1ant_query_bt_info(btcoexist);
  2664. halbtc8821a1ant_monitor_bt_ctr(btcoexist);
  2665. btc8821a1ant_mon_bt_en_dis(btcoexist);
  2666. #else
  2667. if (halbtc8821a1ant_Is_wifi_status_changed(btcoexist) ||
  2668. coex_dm->auto_tdma_adjust) {
  2669. if (coex_sta->special_pkt_period_cnt > 2)
  2670. halbtc8821a1ant_run_coexist_mechanism(btcoexist);
  2671. }
  2672. coex_sta->special_pkt_period_cnt++;
  2673. #endif
  2674. }