halbtc8821a1ant.c 91 KB

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