halbtc8821a1ant.c 92 KB

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