halbtc8821a1ant.c 93 KB

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