halbtc8192e1ant.c 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417
  1. /* ************************************************************
  2. * Description:
  3. *
  4. * This file is for RTL8192E Co-exist mechanism
  5. *
  6. * History
  7. * 2012/11/15 Cosa first check in.
  8. *
  9. * ************************************************************ */
  10. /* ************************************************************
  11. * include files
  12. * ************************************************************ */
  13. #include "mp_precomp.h"
  14. #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
  15. #if (RTL8192E_SUPPORT == 1)
  16. /* ************************************************************
  17. * Global variables, these are static variables
  18. * ************************************************************ */
  19. static u8 *trace_buf = &gl_btc_trace_buf[0];
  20. static struct coex_dm_8192e_1ant glcoex_dm_8192e_1ant;
  21. static struct coex_dm_8192e_1ant *coex_dm = &glcoex_dm_8192e_1ant;
  22. static struct coex_sta_8192e_1ant glcoex_sta_8192e_1ant;
  23. static struct coex_sta_8192e_1ant *coex_sta = &glcoex_sta_8192e_1ant;
  24. const char *const glbt_info_src_8192e_1ant[] = {
  25. "BT Info[wifi fw]",
  26. "BT Info[bt rsp]",
  27. "BT Info[bt auto report]",
  28. };
  29. u32 glcoex_ver_date_8192e_1ant = 20140527;
  30. u32 glcoex_ver_8192e_1ant = 0x4f;
  31. /* ************************************************************
  32. * local function proto type if needed
  33. * ************************************************************
  34. * ************************************************************
  35. * local function start with halbtc8192e1ant_
  36. * ************************************************************ */
  37. u8 halbtc8192e1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
  38. {
  39. s32 bt_rssi = 0;
  40. u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
  41. bt_rssi = coex_sta->bt_rssi;
  42. if (level_num == 2) {
  43. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  44. (coex_sta->pre_bt_rssi_state ==
  45. BTC_RSSI_STATE_STAY_LOW)) {
  46. if (bt_rssi >= (rssi_thresh +
  47. BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))
  48. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  49. else
  50. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  51. } else {
  52. if (bt_rssi < rssi_thresh)
  53. bt_rssi_state = BTC_RSSI_STATE_LOW;
  54. else
  55. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  56. }
  57. } else if (level_num == 3) {
  58. if (rssi_thresh > rssi_thresh1) {
  59. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  60. "[BTCoex], BT Rssi thresh error!!\n");
  61. BTC_TRACE(trace_buf);
  62. return coex_sta->pre_bt_rssi_state;
  63. }
  64. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  65. (coex_sta->pre_bt_rssi_state ==
  66. BTC_RSSI_STATE_STAY_LOW)) {
  67. if (bt_rssi >= (rssi_thresh +
  68. BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))
  69. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  70. else
  71. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  72. } else if ((coex_sta->pre_bt_rssi_state ==
  73. BTC_RSSI_STATE_MEDIUM) ||
  74. (coex_sta->pre_bt_rssi_state ==
  75. BTC_RSSI_STATE_STAY_MEDIUM)) {
  76. if (bt_rssi >= (rssi_thresh1 +
  77. BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))
  78. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  79. else if (bt_rssi < rssi_thresh)
  80. bt_rssi_state = BTC_RSSI_STATE_LOW;
  81. else
  82. bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  83. } else {
  84. if (bt_rssi < rssi_thresh1)
  85. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  86. else
  87. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  88. }
  89. }
  90. coex_sta->pre_bt_rssi_state = bt_rssi_state;
  91. return bt_rssi_state;
  92. }
  93. u8 halbtc8192e1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
  94. IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
  95. {
  96. s32 wifi_rssi = 0;
  97. u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
  98. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  99. if (level_num == 2) {
  100. if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
  101. ||
  102. (coex_sta->pre_wifi_rssi_state[index] ==
  103. BTC_RSSI_STATE_STAY_LOW)) {
  104. if (wifi_rssi >= (rssi_thresh +
  105. BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))
  106. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  107. else
  108. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  109. } else {
  110. if (wifi_rssi < rssi_thresh)
  111. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  112. else
  113. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  114. }
  115. } else if (level_num == 3) {
  116. if (rssi_thresh > rssi_thresh1) {
  117. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  118. "[BTCoex], wifi RSSI thresh error!!\n");
  119. BTC_TRACE(trace_buf);
  120. return coex_sta->pre_wifi_rssi_state[index];
  121. }
  122. if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
  123. ||
  124. (coex_sta->pre_wifi_rssi_state[index] ==
  125. BTC_RSSI_STATE_STAY_LOW)) {
  126. if (wifi_rssi >= (rssi_thresh +
  127. BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))
  128. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  129. else
  130. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  131. } else if ((coex_sta->pre_wifi_rssi_state[index] ==
  132. BTC_RSSI_STATE_MEDIUM) ||
  133. (coex_sta->pre_wifi_rssi_state[index] ==
  134. BTC_RSSI_STATE_STAY_MEDIUM)) {
  135. if (wifi_rssi >= (rssi_thresh1 +
  136. BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))
  137. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  138. else if (wifi_rssi < rssi_thresh)
  139. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  140. else
  141. wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  142. } else {
  143. if (wifi_rssi < rssi_thresh1)
  144. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  145. else
  146. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  147. }
  148. }
  149. coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
  150. return wifi_rssi_state;
  151. }
  152. void halbtc8192e1ant_update_ra_mask(IN struct btc_coexist *btcoexist,
  153. IN boolean force_exec, IN u32 dis_rate_mask)
  154. {
  155. coex_dm->cur_ra_mask = dis_rate_mask;
  156. if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
  157. btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
  158. &coex_dm->cur_ra_mask);
  159. coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
  160. }
  161. void halbtc8192e1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
  162. IN boolean force_exec, IN u8 type)
  163. {
  164. boolean wifi_under_b_mode = false;
  165. coex_dm->cur_arfr_type = type;
  166. if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
  167. switch (coex_dm->cur_arfr_type) {
  168. case 0: /* normal mode */
  169. btcoexist->btc_write_4byte(btcoexist, 0x430,
  170. coex_dm->backup_arfr_cnt1);
  171. btcoexist->btc_write_4byte(btcoexist, 0x434,
  172. coex_dm->backup_arfr_cnt2);
  173. break;
  174. case 1:
  175. btcoexist->btc_get(btcoexist,
  176. BTC_GET_BL_WIFI_UNDER_B_MODE,
  177. &wifi_under_b_mode);
  178. if (wifi_under_b_mode) {
  179. btcoexist->btc_write_4byte(btcoexist,
  180. 0x430, 0x0);
  181. btcoexist->btc_write_4byte(btcoexist,
  182. 0x434, 0x01010101);
  183. } else {
  184. btcoexist->btc_write_4byte(btcoexist,
  185. 0x430, 0x0);
  186. btcoexist->btc_write_4byte(btcoexist,
  187. 0x434, 0x04030201);
  188. }
  189. break;
  190. default:
  191. break;
  192. }
  193. }
  194. coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
  195. }
  196. void halbtc8192e1ant_retry_limit(IN struct btc_coexist *btcoexist,
  197. IN boolean force_exec, IN u8 type)
  198. {
  199. coex_dm->cur_retry_limit_type = type;
  200. if (force_exec ||
  201. (coex_dm->pre_retry_limit_type !=
  202. coex_dm->cur_retry_limit_type)) {
  203. switch (coex_dm->cur_retry_limit_type) {
  204. case 0: /* normal mode */
  205. btcoexist->btc_write_2byte(btcoexist, 0x42a,
  206. coex_dm->backup_retry_limit);
  207. break;
  208. case 1: /* retry limit=8 */
  209. btcoexist->btc_write_2byte(btcoexist, 0x42a,
  210. 0x0808);
  211. break;
  212. default:
  213. break;
  214. }
  215. }
  216. coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
  217. }
  218. void halbtc8192e1ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
  219. IN boolean force_exec, IN u8 type)
  220. {
  221. coex_dm->cur_ampdu_time_type = type;
  222. if (force_exec ||
  223. (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
  224. switch (coex_dm->cur_ampdu_time_type) {
  225. case 0: /* normal mode */
  226. btcoexist->btc_write_1byte(btcoexist, 0x456,
  227. coex_dm->backup_ampdu_max_time);
  228. break;
  229. case 1: /* AMPDU timw = 0x38 * 32us */
  230. btcoexist->btc_write_1byte(btcoexist, 0x456,
  231. 0x38);
  232. break;
  233. default:
  234. break;
  235. }
  236. }
  237. coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
  238. }
  239. void halbtc8192e1ant_limited_tx(IN struct btc_coexist *btcoexist,
  240. IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
  241. IN u8 retry_limit_type, IN u8 ampdu_time_type)
  242. {
  243. switch (ra_mask_type) {
  244. case 0: /* normal mode */
  245. halbtc8192e1ant_update_ra_mask(btcoexist, force_exec,
  246. 0x0);
  247. break;
  248. case 1: /* disable cck 1/2 */
  249. halbtc8192e1ant_update_ra_mask(btcoexist, force_exec,
  250. 0x00000003);
  251. break;
  252. case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
  253. halbtc8192e1ant_update_ra_mask(btcoexist, force_exec,
  254. 0x0001f1f7);
  255. break;
  256. default:
  257. break;
  258. }
  259. halbtc8192e1ant_auto_rate_fallback_retry(btcoexist, force_exec,
  260. arfr_type);
  261. halbtc8192e1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
  262. halbtc8192e1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
  263. }
  264. void halbtc8192e1ant_limited_rx(IN struct btc_coexist *btcoexist,
  265. IN boolean force_exec, IN boolean rej_ap_agg_pkt,
  266. IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
  267. {
  268. boolean reject_rx_agg = rej_ap_agg_pkt;
  269. boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
  270. u8 rx_agg_size = agg_buf_size;
  271. /* ============================================ */
  272. /* Rx Aggregation related setting */
  273. /* ============================================ */
  274. btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
  275. &reject_rx_agg);
  276. /* decide BT control aggregation buf size or not */
  277. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
  278. &bt_ctrl_rx_agg_size);
  279. /* aggregation buf size, only work when BT control Rx aggregation size. */
  280. btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
  281. /* real update aggregation setting */
  282. btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
  283. }
  284. void halbtc8192e1ant_query_bt_info(IN struct btc_coexist *btcoexist)
  285. {
  286. u8 h2c_parameter[1] = {0};
  287. coex_sta->c2h_bt_info_req_sent = true;
  288. h2c_parameter[0] |= BIT(0); /* trigger */
  289. btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
  290. }
  291. void halbtc8192e1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
  292. {
  293. u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
  294. u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
  295. static u8 num_of_bt_counter_chk = 0;
  296. /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
  297. /* if (! (btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8) ) */
  298. if (coex_sta->under_ips) {
  299. coex_sta->high_priority_tx = 65535;
  300. coex_sta->high_priority_rx = 65535;
  301. coex_sta->low_priority_tx = 65535;
  302. coex_sta->low_priority_rx = 65535;
  303. return;
  304. }
  305. reg_hp_txrx = 0x770;
  306. reg_lp_txrx = 0x774;
  307. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
  308. reg_hp_tx = u32tmp & MASKLWORD;
  309. reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
  310. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
  311. reg_lp_tx = u32tmp & MASKLWORD;
  312. reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
  313. coex_sta->high_priority_tx = reg_hp_tx;
  314. coex_sta->high_priority_rx = reg_hp_rx;
  315. coex_sta->low_priority_tx = reg_lp_tx;
  316. coex_sta->low_priority_rx = reg_lp_rx;
  317. if ((coex_sta->low_priority_tx >= 1050) &&
  318. (!coex_sta->c2h_bt_inquiry_page))
  319. coex_sta->pop_event_cnt++;
  320. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  321. "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
  322. reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx);
  323. BTC_TRACE(trace_buf);
  324. /* reset counter */
  325. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
  326. if ((reg_hp_tx == 0) && (reg_hp_rx == 0) && (reg_lp_tx == 0) &&
  327. (reg_lp_rx == 0)) {
  328. num_of_bt_counter_chk++;
  329. if (num_of_bt_counter_chk >= 3) {
  330. halbtc8192e1ant_query_bt_info(btcoexist);
  331. num_of_bt_counter_chk = 0;
  332. }
  333. }
  334. }
  335. void halbtc8192e1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
  336. {
  337. s32 wifi_rssi = 0;
  338. boolean wifi_busy = false, wifi_under_b_mode = false;
  339. static u8 cck_lock_counter = 0;
  340. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  341. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  342. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
  343. &wifi_under_b_mode);
  344. if (coex_sta->under_ips) {
  345. coex_sta->crc_ok_cck = 0;
  346. coex_sta->crc_ok_11g = 0;
  347. coex_sta->crc_ok_11n = 0;
  348. coex_sta->crc_ok_11n_agg = 0;
  349. coex_sta->crc_err_cck = 0;
  350. coex_sta->crc_err_11g = 0;
  351. coex_sta->crc_err_11n = 0;
  352. coex_sta->crc_err_11n_agg = 0;
  353. } else {
  354. coex_sta->crc_ok_cck = btcoexist->btc_read_4byte(btcoexist,
  355. 0xf88);
  356. coex_sta->crc_ok_11g = btcoexist->btc_read_2byte(btcoexist,
  357. 0xf94);
  358. coex_sta->crc_ok_11n = btcoexist->btc_read_2byte(btcoexist,
  359. 0xf90);
  360. coex_sta->crc_ok_11n_agg = btcoexist->btc_read_2byte(btcoexist,
  361. 0xfb8);
  362. coex_sta->crc_err_cck = btcoexist->btc_read_4byte(btcoexist,
  363. 0xf84);
  364. coex_sta->crc_err_11g = btcoexist->btc_read_2byte(btcoexist,
  365. 0xf96);
  366. coex_sta->crc_err_11n = btcoexist->btc_read_2byte(btcoexist,
  367. 0xf92);
  368. coex_sta->crc_err_11n_agg = btcoexist->btc_read_2byte(btcoexist,
  369. 0xfba);
  370. }
  371. /* reset counter */
  372. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x1);
  373. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x0);
  374. if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) {
  375. if ((coex_dm->bt_status == BT_8192E_1ANT_BT_STATUS_ACL_BUSY) ||
  376. (coex_dm->bt_status ==
  377. BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
  378. (coex_dm->bt_status ==
  379. BT_8192E_1ANT_BT_STATUS_SCO_BUSY)) {
  380. if (coex_sta->crc_ok_cck > (coex_sta->crc_ok_11g +
  381. coex_sta->crc_ok_11n +
  382. coex_sta->crc_ok_11n_agg)) {
  383. if (cck_lock_counter < 5)
  384. cck_lock_counter++;
  385. } else {
  386. if (cck_lock_counter > 0)
  387. cck_lock_counter--;
  388. }
  389. } else {
  390. if (cck_lock_counter > 0)
  391. cck_lock_counter--;
  392. }
  393. } else {
  394. if (cck_lock_counter > 0)
  395. cck_lock_counter--;
  396. }
  397. if (!coex_sta->pre_ccklock) {
  398. if (cck_lock_counter >= 5)
  399. coex_sta->cck_lock = true;
  400. else
  401. coex_sta->cck_lock = false;
  402. } else {
  403. if (cck_lock_counter == 0)
  404. coex_sta->cck_lock = false;
  405. else
  406. coex_sta->cck_lock = true;
  407. }
  408. coex_sta->pre_ccklock = coex_sta->cck_lock;
  409. }
  410. boolean halbtc8192e1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
  411. {
  412. static boolean pre_wifi_busy = false, pre_under_4way = false,
  413. pre_bt_hs_on = false;
  414. boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
  415. boolean wifi_connected = false;
  416. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  417. &wifi_connected);
  418. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  419. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  420. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  421. &under_4way);
  422. if (wifi_connected) {
  423. if (wifi_busy != pre_wifi_busy) {
  424. pre_wifi_busy = wifi_busy;
  425. return true;
  426. }
  427. if (under_4way != pre_under_4way) {
  428. pre_under_4way = under_4way;
  429. return true;
  430. }
  431. if (bt_hs_on != pre_bt_hs_on) {
  432. pre_bt_hs_on = bt_hs_on;
  433. return true;
  434. }
  435. }
  436. return false;
  437. }
  438. void halbtc8192e1ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
  439. {
  440. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  441. boolean bt_hs_on = false;
  442. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  443. bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
  444. bt_link_info->sco_exist = coex_sta->sco_exist;
  445. bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
  446. bt_link_info->pan_exist = coex_sta->pan_exist;
  447. bt_link_info->hid_exist = coex_sta->hid_exist;
  448. /* work around for HS mode. */
  449. if (bt_hs_on) {
  450. bt_link_info->pan_exist = true;
  451. bt_link_info->bt_link_exist = true;
  452. }
  453. /* check if Sco only */
  454. if (bt_link_info->sco_exist &&
  455. !bt_link_info->a2dp_exist &&
  456. !bt_link_info->pan_exist &&
  457. !bt_link_info->hid_exist)
  458. bt_link_info->sco_only = true;
  459. else
  460. bt_link_info->sco_only = false;
  461. /* check if A2dp only */
  462. if (!bt_link_info->sco_exist &&
  463. bt_link_info->a2dp_exist &&
  464. !bt_link_info->pan_exist &&
  465. !bt_link_info->hid_exist)
  466. bt_link_info->a2dp_only = true;
  467. else
  468. bt_link_info->a2dp_only = false;
  469. /* check if Pan only */
  470. if (!bt_link_info->sco_exist &&
  471. !bt_link_info->a2dp_exist &&
  472. bt_link_info->pan_exist &&
  473. !bt_link_info->hid_exist)
  474. bt_link_info->pan_only = true;
  475. else
  476. bt_link_info->pan_only = false;
  477. /* check if Hid only */
  478. if (!bt_link_info->sco_exist &&
  479. !bt_link_info->a2dp_exist &&
  480. !bt_link_info->pan_exist &&
  481. bt_link_info->hid_exist)
  482. bt_link_info->hid_only = true;
  483. else
  484. bt_link_info->hid_only = false;
  485. }
  486. u8 halbtc8192e1ant_action_algorithm(IN struct btc_coexist *btcoexist)
  487. {
  488. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  489. boolean bt_hs_on = false;
  490. u8 algorithm = BT_8192E_1ANT_COEX_ALGO_UNDEFINED;
  491. u8 num_of_diff_profile = 0;
  492. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  493. if (!bt_link_info->bt_link_exist) {
  494. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  495. "[BTCoex], No BT link exists!!!\n");
  496. BTC_TRACE(trace_buf);
  497. return algorithm;
  498. }
  499. if (bt_link_info->sco_exist)
  500. num_of_diff_profile++;
  501. if (bt_link_info->hid_exist)
  502. num_of_diff_profile++;
  503. if (bt_link_info->pan_exist)
  504. num_of_diff_profile++;
  505. if (bt_link_info->a2dp_exist)
  506. num_of_diff_profile++;
  507. if (num_of_diff_profile == 1) {
  508. if (bt_link_info->sco_exist) {
  509. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  510. "[BTCoex], BT Profile = SCO only\n");
  511. BTC_TRACE(trace_buf);
  512. algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;
  513. } else {
  514. if (bt_link_info->hid_exist) {
  515. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  516. "[BTCoex], BT Profile = HID only\n");
  517. BTC_TRACE(trace_buf);
  518. algorithm = BT_8192E_1ANT_COEX_ALGO_HID;
  519. } else if (bt_link_info->a2dp_exist) {
  520. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  521. "[BTCoex], BT Profile = A2DP only\n");
  522. BTC_TRACE(trace_buf);
  523. algorithm = BT_8192E_1ANT_COEX_ALGO_A2DP;
  524. } else if (bt_link_info->pan_exist) {
  525. if (bt_hs_on) {
  526. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  527. "[BTCoex], BT Profile = PAN(HS) only\n");
  528. BTC_TRACE(trace_buf);
  529. algorithm =
  530. BT_8192E_1ANT_COEX_ALGO_PANHS;
  531. } else {
  532. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  533. "[BTCoex], BT Profile = PAN(EDR) only\n");
  534. BTC_TRACE(trace_buf);
  535. algorithm =
  536. BT_8192E_1ANT_COEX_ALGO_PANEDR;
  537. }
  538. }
  539. }
  540. } else if (num_of_diff_profile == 2) {
  541. if (bt_link_info->sco_exist) {
  542. if (bt_link_info->hid_exist) {
  543. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  544. "[BTCoex], BT Profile = SCO + HID\n");
  545. BTC_TRACE(trace_buf);
  546. algorithm = BT_8192E_1ANT_COEX_ALGO_HID;
  547. } else if (bt_link_info->a2dp_exist) {
  548. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  549. "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
  550. BTC_TRACE(trace_buf);
  551. algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;
  552. } else if (bt_link_info->pan_exist) {
  553. if (bt_hs_on) {
  554. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  555. "[BTCoex], BT Profile = SCO + PAN(HS)\n");
  556. BTC_TRACE(trace_buf);
  557. algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;
  558. } else {
  559. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  560. "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
  561. BTC_TRACE(trace_buf);
  562. algorithm =
  563. BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
  564. }
  565. }
  566. } else {
  567. if (bt_link_info->hid_exist &&
  568. bt_link_info->a2dp_exist) {
  569. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  570. "[BTCoex], BT Profile = HID + A2DP\n");
  571. BTC_TRACE(trace_buf);
  572. algorithm = BT_8192E_1ANT_COEX_ALGO_HID_A2DP;
  573. } else if (bt_link_info->hid_exist &&
  574. bt_link_info->pan_exist) {
  575. if (bt_hs_on) {
  576. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  577. "[BTCoex], BT Profile = HID + PAN(HS)\n");
  578. BTC_TRACE(trace_buf);
  579. algorithm =
  580. BT_8192E_1ANT_COEX_ALGO_HID_A2DP;
  581. } else {
  582. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  583. "[BTCoex], BT Profile = HID + PAN(EDR)\n");
  584. BTC_TRACE(trace_buf);
  585. algorithm =
  586. BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
  587. }
  588. } else if (bt_link_info->pan_exist &&
  589. bt_link_info->a2dp_exist) {
  590. if (bt_hs_on) {
  591. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  592. "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
  593. BTC_TRACE(trace_buf);
  594. algorithm =
  595. BT_8192E_1ANT_COEX_ALGO_A2DP_PANHS;
  596. } else {
  597. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  598. "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
  599. BTC_TRACE(trace_buf);
  600. algorithm =
  601. BT_8192E_1ANT_COEX_ALGO_PANEDR_A2DP;
  602. }
  603. }
  604. }
  605. } else if (num_of_diff_profile == 3) {
  606. if (bt_link_info->sco_exist) {
  607. if (bt_link_info->hid_exist &&
  608. bt_link_info->a2dp_exist) {
  609. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  610. "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
  611. BTC_TRACE(trace_buf);
  612. algorithm = BT_8192E_1ANT_COEX_ALGO_HID;
  613. } else if (bt_link_info->hid_exist &&
  614. bt_link_info->pan_exist) {
  615. if (bt_hs_on) {
  616. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  617. "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
  618. BTC_TRACE(trace_buf);
  619. algorithm =
  620. BT_8192E_1ANT_COEX_ALGO_HID_A2DP;
  621. } else {
  622. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  623. "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
  624. BTC_TRACE(trace_buf);
  625. algorithm =
  626. BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
  627. }
  628. } else if (bt_link_info->pan_exist &&
  629. bt_link_info->a2dp_exist) {
  630. if (bt_hs_on) {
  631. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  632. "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
  633. BTC_TRACE(trace_buf);
  634. algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;
  635. } else {
  636. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  637. "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
  638. BTC_TRACE(trace_buf);
  639. algorithm =
  640. BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
  641. }
  642. }
  643. } else {
  644. if (bt_link_info->hid_exist &&
  645. bt_link_info->pan_exist &&
  646. bt_link_info->a2dp_exist) {
  647. if (bt_hs_on) {
  648. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  649. "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
  650. BTC_TRACE(trace_buf);
  651. algorithm =
  652. BT_8192E_1ANT_COEX_ALGO_HID_A2DP;
  653. } else {
  654. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  655. "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
  656. BTC_TRACE(trace_buf);
  657. algorithm =
  658. BT_8192E_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
  659. }
  660. }
  661. }
  662. } else if (num_of_diff_profile >= 3) {
  663. if (bt_link_info->sco_exist) {
  664. if (bt_link_info->hid_exist &&
  665. bt_link_info->pan_exist &&
  666. bt_link_info->a2dp_exist) {
  667. if (bt_hs_on) {
  668. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  669. "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
  670. BTC_TRACE(trace_buf);
  671. } else {
  672. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  673. "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
  674. BTC_TRACE(trace_buf);
  675. algorithm =
  676. BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;
  677. }
  678. }
  679. }
  680. }
  681. return algorithm;
  682. }
  683. void halbtc8192e1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
  684. IN boolean enable_auto_report)
  685. {
  686. u8 h2c_parameter[1] = {0};
  687. h2c_parameter[0] = 0;
  688. if (enable_auto_report)
  689. h2c_parameter[0] |= BIT(0);
  690. btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
  691. }
  692. void halbtc8192e1ant_bt_auto_report(IN struct btc_coexist *btcoexist,
  693. IN boolean force_exec, IN boolean enable_auto_report)
  694. {
  695. coex_dm->cur_bt_auto_report = enable_auto_report;
  696. if (!force_exec) {
  697. if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
  698. return;
  699. }
  700. halbtc8192e1ant_set_bt_auto_report(btcoexist,
  701. coex_dm->cur_bt_auto_report);
  702. coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
  703. }
  704. void halbtc8192e1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
  705. *btcoexist, IN boolean low_penalty_ra)
  706. {
  707. u8 h2c_parameter[6] = {0};
  708. h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */
  709. if (low_penalty_ra) {
  710. h2c_parameter[1] |= BIT(0);
  711. h2c_parameter[2] =
  712. 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
  713. h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */
  714. h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */
  715. h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */
  716. }
  717. btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
  718. }
  719. void halbtc8192e1ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
  720. IN boolean force_exec, IN boolean low_penalty_ra)
  721. {
  722. coex_dm->cur_low_penalty_ra = low_penalty_ra;
  723. if (!force_exec) {
  724. if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
  725. return;
  726. }
  727. halbtc8192e1ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
  728. coex_dm->cur_low_penalty_ra);
  729. coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
  730. }
  731. void halbtc8192e1ant_set_coex_table(IN struct btc_coexist *btcoexist,
  732. IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
  733. {
  734. btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
  735. btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
  736. btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
  737. btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
  738. }
  739. void halbtc8192e1ant_coex_table(IN struct btc_coexist *btcoexist,
  740. IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
  741. IN u32 val0x6c8, IN u8 val0x6cc)
  742. {
  743. coex_dm->cur_val0x6c0 = val0x6c0;
  744. coex_dm->cur_val0x6c4 = val0x6c4;
  745. coex_dm->cur_val0x6c8 = val0x6c8;
  746. coex_dm->cur_val0x6cc = val0x6cc;
  747. if (!force_exec) {
  748. if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
  749. (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
  750. (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
  751. (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
  752. return;
  753. }
  754. halbtc8192e1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
  755. val0x6cc);
  756. coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
  757. coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
  758. coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
  759. coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
  760. }
  761. void halbtc8192e1ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
  762. IN boolean force_exec, IN u8 type)
  763. {
  764. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  765. "[BTCoex], ********** CoexTable(%d) **********\n", type);
  766. BTC_TRACE(trace_buf);
  767. coex_sta->coex_table_type = type;
  768. switch (type) {
  769. case 0:
  770. halbtc8192e1ant_coex_table(btcoexist, force_exec,
  771. 0x55555555, 0x55555555, 0xffffff, 0x3);
  772. break;
  773. case 1:
  774. halbtc8192e1ant_coex_table(btcoexist, force_exec,
  775. 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
  776. break;
  777. case 2:
  778. halbtc8192e1ant_coex_table(btcoexist, force_exec,
  779. 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
  780. break;
  781. case 3:
  782. halbtc8192e1ant_coex_table(btcoexist, force_exec,
  783. 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
  784. break;
  785. case 4:
  786. halbtc8192e1ant_coex_table(btcoexist, force_exec,
  787. 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);
  788. break;
  789. case 5:
  790. halbtc8192e1ant_coex_table(btcoexist, force_exec,
  791. 0x5a5a5a5a, 0xaa5a5a5a, 0xffffff, 0x3);
  792. break;
  793. case 6:
  794. halbtc8192e1ant_coex_table(btcoexist, force_exec,
  795. 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3);
  796. break;
  797. case 7:
  798. halbtc8192e1ant_coex_table(btcoexist, force_exec,
  799. 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
  800. break;
  801. default:
  802. break;
  803. }
  804. }
  805. void halbtc8192e1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
  806. IN boolean enable)
  807. {
  808. u8 h2c_parameter[1] = {0};
  809. if (enable)
  810. h2c_parameter[0] |= BIT(0); /* function enable */
  811. btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
  812. }
  813. void halbtc8192e1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
  814. IN boolean force_exec, IN boolean enable)
  815. {
  816. coex_dm->cur_ignore_wlan_act = enable;
  817. if (!force_exec) {
  818. if (coex_dm->pre_ignore_wlan_act ==
  819. coex_dm->cur_ignore_wlan_act)
  820. return;
  821. }
  822. halbtc8192e1ant_set_fw_ignore_wlan_act(btcoexist, enable);
  823. coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
  824. }
  825. void halbtc8192e1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
  826. IN u8 lps_val, IN u8 rpwm_val)
  827. {
  828. u8 lps = lps_val;
  829. u8 rpwm = rpwm_val;
  830. btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
  831. btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
  832. }
  833. void halbtc8192e1ant_lps_rpwm(IN struct btc_coexist *btcoexist,
  834. IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
  835. {
  836. coex_dm->cur_lps = lps_val;
  837. coex_dm->cur_rpwm = rpwm_val;
  838. if (!force_exec) {
  839. if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
  840. (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
  841. return;
  842. }
  843. halbtc8192e1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
  844. coex_dm->pre_lps = coex_dm->cur_lps;
  845. coex_dm->pre_rpwm = coex_dm->cur_rpwm;
  846. }
  847. void halbtc8192e1ant_sw_mechanism(IN struct btc_coexist *btcoexist,
  848. IN boolean low_penalty_ra)
  849. {
  850. halbtc8192e1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
  851. }
  852. void halbtc8192e1ant_set_ant_path(IN struct btc_coexist *btcoexist,
  853. IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off)
  854. {
  855. u32 u32tmp = 0;
  856. if (init_hwcfg) {
  857. btcoexist->btc_write_1byte(btcoexist, 0x944, 0x24);
  858. btcoexist->btc_write_4byte(btcoexist, 0x930, 0x700700);
  859. if (btcoexist->chip_interface == BTC_INTF_USB)
  860. btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30430004);
  861. else
  862. btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30030004);
  863. /* 0x4c[27][24]='00', Set Antenna to BB */
  864. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  865. u32tmp &= ~BIT(24);
  866. u32tmp &= ~BIT(27);
  867. btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
  868. } else if (wifi_off) {
  869. if (btcoexist->chip_interface == BTC_INTF_USB)
  870. btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30430004);
  871. else
  872. btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30030004);
  873. /* 0x4c[27][24]='11', Set Antenna to BT, 0x64[8:7]=0, 0x64[2]=1 */
  874. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  875. u32tmp |= BIT(24);
  876. u32tmp |= BIT(27);
  877. btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
  878. }
  879. /* ext switch setting */
  880. switch (ant_pos_type) {
  881. case BTC_ANT_PATH_WIFI:
  882. btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x4);
  883. break;
  884. case BTC_ANT_PATH_BT:
  885. btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x20);
  886. break;
  887. default:
  888. case BTC_ANT_PATH_PTA:
  889. btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x4);
  890. break;
  891. }
  892. }
  893. void halbtc8192e1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
  894. IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
  895. {
  896. u8 h2c_parameter[5] = {0};
  897. u8 real_byte1 = byte1, real_byte5 = byte5;
  898. boolean ap_enable = false;
  899. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  900. &ap_enable);
  901. if (ap_enable) {
  902. if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
  903. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  904. "[BTCoex], FW for 1Ant AP mode\n");
  905. BTC_TRACE(trace_buf);
  906. real_byte1 &= ~BIT(4);
  907. real_byte1 |= BIT(5);
  908. real_byte5 |= BIT(5);
  909. real_byte5 &= ~BIT(6);
  910. }
  911. }
  912. h2c_parameter[0] = real_byte1;
  913. h2c_parameter[1] = byte2;
  914. h2c_parameter[2] = byte3;
  915. h2c_parameter[3] = byte4;
  916. h2c_parameter[4] = real_byte5;
  917. coex_dm->ps_tdma_para[0] = real_byte1;
  918. coex_dm->ps_tdma_para[1] = byte2;
  919. coex_dm->ps_tdma_para[2] = byte3;
  920. coex_dm->ps_tdma_para[3] = byte4;
  921. coex_dm->ps_tdma_para[4] = real_byte5;
  922. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
  923. }
  924. void halbtc8192e1ant_ps_tdma(IN struct btc_coexist *btcoexist,
  925. IN boolean force_exec, IN boolean turn_on, IN u8 type)
  926. {
  927. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  928. boolean wifi_busy = false;
  929. u8 rssi_adjust_val = 0;
  930. u8 ps_tdma_byte4_val = 0x50, ps_tdma_byte0_val = 0x51,
  931. ps_tdma_byte3_val = 0x10;
  932. s8 wifi_duration_adjust = 0x0;
  933. coex_dm->cur_ps_tdma_on = turn_on;
  934. coex_dm->cur_ps_tdma = type;
  935. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  936. if (coex_dm->cur_ps_tdma_on) {
  937. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  938. "[BTCoex], ********** TDMA(on, %d) **********\n",
  939. coex_dm->cur_ps_tdma);
  940. BTC_TRACE(trace_buf);
  941. } else {
  942. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  943. "[BTCoex], ********** TDMA(off, %d) **********\n",
  944. coex_dm->cur_ps_tdma);
  945. BTC_TRACE(trace_buf);
  946. }
  947. if (!force_exec) {
  948. if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
  949. (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
  950. return;
  951. }
  952. if (coex_sta->scan_ap_num <= 5)
  953. wifi_duration_adjust = 5;
  954. else if (coex_sta->scan_ap_num >= 40)
  955. wifi_duration_adjust = -15;
  956. else if (coex_sta->scan_ap_num >= 20)
  957. wifi_duration_adjust = -10;
  958. if (!coex_sta->force_lps_on) { /* only for A2DP-only case 1/2/9/11 while wifi noisy threshold > 30 */
  959. ps_tdma_byte0_val = 0x61; /* no null-pkt */
  960. ps_tdma_byte3_val = 0x11; /* no tx-pause at BT-slot */
  961. ps_tdma_byte4_val = 0x10; /* 0x778 = d/1 toggle */
  962. }
  963. if ((type == 3) || (type == 13) || (type == 14))
  964. ps_tdma_byte4_val = ps_tdma_byte4_val &
  965. 0xbf; /* no dynamic slot for multi-profile */
  966. if (bt_link_info->slave_role == true)
  967. ps_tdma_byte4_val = ps_tdma_byte4_val |
  968. 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
  969. if (turn_on) {
  970. switch (type) {
  971. default:
  972. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
  973. 0x1a, 0x1a, 0x0, ps_tdma_byte4_val);
  974. break;
  975. case 1:
  976. halbtc8192e1ant_set_fw_pstdma(btcoexist,
  977. ps_tdma_byte0_val, 0x3a +
  978. wifi_duration_adjust, 0x03,
  979. ps_tdma_byte3_val, ps_tdma_byte4_val);
  980. break;
  981. case 2:
  982. halbtc8192e1ant_set_fw_pstdma(btcoexist,
  983. ps_tdma_byte0_val, 0x2d +
  984. wifi_duration_adjust, 0x03,
  985. ps_tdma_byte3_val, ps_tdma_byte4_val);
  986. break;
  987. case 3:
  988. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
  989. 0x1d, 0x1d, 0x0, ps_tdma_byte4_val);
  990. break;
  991. case 4:
  992. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93,
  993. 0x15, 0x3, 0x14, 0x0);
  994. break;
  995. case 5:
  996. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
  997. 0x15, 0x3, 0x11, 0x11);
  998. break;
  999. case 6:
  1000. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
  1001. 0x20, 0x3, 0x11, 0x11);
  1002. break;
  1003. case 7:
  1004. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x13,
  1005. 0xc, 0x5, 0x0, 0x0);
  1006. break;
  1007. case 8:
  1008. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93,
  1009. 0x25, 0x3, 0x10, 0x0);
  1010. break;
  1011. case 9:
  1012. halbtc8192e1ant_set_fw_pstdma(btcoexist,
  1013. ps_tdma_byte0_val, 0x21, 0x3,
  1014. ps_tdma_byte3_val, ps_tdma_byte4_val);
  1015. break;
  1016. case 10:
  1017. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x13,
  1018. 0xa, 0xa, 0x0, 0x40);
  1019. break;
  1020. case 11:
  1021. halbtc8192e1ant_set_fw_pstdma(btcoexist,
  1022. ps_tdma_byte0_val, 0x21, 0x03,
  1023. ps_tdma_byte3_val, ps_tdma_byte4_val);
  1024. break;
  1025. case 12:
  1026. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
  1027. 0x0a, 0x0a, 0x0, 0x50);
  1028. break;
  1029. case 13:
  1030. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
  1031. 0x12, 0x12, 0x0, ps_tdma_byte4_val);
  1032. break;
  1033. case 14:
  1034. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
  1035. 0x21, 0x3, 0x10, ps_tdma_byte4_val);
  1036. break;
  1037. case 15:
  1038. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x13,
  1039. 0xa, 0x3, 0x8, 0x0);
  1040. break;
  1041. case 16:
  1042. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93,
  1043. 0x15, 0x3, 0x10, 0x0);
  1044. break;
  1045. case 18:
  1046. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93,
  1047. 0x25, 0x3, 0x10, 0x0);
  1048. break;
  1049. case 20:
  1050. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
  1051. 0x3f, 0x03, 0x11, 0x10);
  1052. break;
  1053. case 21:
  1054. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
  1055. 0x25, 0x03, 0x11, 0x11);
  1056. break;
  1057. case 22:
  1058. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
  1059. 0x25, 0x03, 0x11, 0x10);
  1060. break;
  1061. case 23:
  1062. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
  1063. 0x25, 0x3, 0x31, 0x18);
  1064. break;
  1065. case 24:
  1066. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
  1067. 0x15, 0x3, 0x31, 0x18);
  1068. break;
  1069. case 25:
  1070. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
  1071. 0xa, 0x3, 0x31, 0x18);
  1072. break;
  1073. case 26:
  1074. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
  1075. 0xa, 0x3, 0x31, 0x18);
  1076. break;
  1077. case 27:
  1078. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3,
  1079. 0x25, 0x3, 0x31, 0x98);
  1080. break;
  1081. case 28:
  1082. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x69,
  1083. 0x25, 0x3, 0x31, 0x0);
  1084. break;
  1085. case 29:
  1086. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xab,
  1087. 0x1a, 0x1a, 0x1, 0x10);
  1088. break;
  1089. case 30:
  1090. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51,
  1091. 0x30, 0x3, 0x10, 0x10);
  1092. break;
  1093. case 31:
  1094. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xd3,
  1095. 0x1a, 0x1a, 0, 0x58);
  1096. break;
  1097. case 32:
  1098. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61,
  1099. 0x35, 0x3, 0x11, 0x11);
  1100. break;
  1101. case 33:
  1102. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xa3,
  1103. 0x25, 0x3, 0x30, 0x90);
  1104. break;
  1105. case 34:
  1106. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x53,
  1107. 0x1a, 0x1a, 0x0, 0x10);
  1108. break;
  1109. case 35:
  1110. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x63,
  1111. 0x1a, 0x1a, 0x0, 0x10);
  1112. break;
  1113. case 36:
  1114. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xd3,
  1115. 0x12, 0x3, 0x14, 0x50);
  1116. break;
  1117. case 40: /* SoftAP only with no sta associated,BT disable ,TDMA mode for power saving */
  1118. /* here softap mode screen off will cost 70-80mA for phone */
  1119. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x23,
  1120. 0x18, 0x00, 0x10, 0x24);
  1121. break;
  1122. }
  1123. } else {
  1124. /* disable PS tdma */
  1125. switch (type) {
  1126. case 8: /* PTA Control */
  1127. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x8,
  1128. 0x0, 0x0, 0x0, 0x0);
  1129. halbtc8192e1ant_set_ant_path(btcoexist,
  1130. BTC_ANT_PATH_PTA, false, false);
  1131. break;
  1132. case 0:
  1133. default: /* Software control, Antenna at BT side */
  1134. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x0,
  1135. 0x0, 0x0, 0x0, 0x0);
  1136. halbtc8192e1ant_set_ant_path(btcoexist,
  1137. BTC_ANT_PATH_BT, false, false);
  1138. break;
  1139. case 9: /* Software control, Antenna at WiFi side */
  1140. halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x0,
  1141. 0x0, 0x0, 0x0, 0x0);
  1142. halbtc8192e1ant_set_ant_path(btcoexist,
  1143. BTC_ANT_PATH_WIFI, false, false);
  1144. break;
  1145. }
  1146. }
  1147. rssi_adjust_val = 0;
  1148. btcoexist->btc_set(btcoexist,
  1149. BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val);
  1150. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1151. "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
  1152. btcoexist->btc_read_4byte(btcoexist, 0x948),
  1153. btcoexist->btc_read_1byte(btcoexist, 0x765),
  1154. btcoexist->btc_read_1byte(btcoexist, 0x67));
  1155. BTC_TRACE(trace_buf);
  1156. /* update pre state */
  1157. coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
  1158. coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
  1159. }
  1160. void halbtc8192e1ant_coex_all_off(IN struct btc_coexist *btcoexist)
  1161. {
  1162. /* sw all off */
  1163. halbtc8192e1ant_sw_mechanism(btcoexist, false);
  1164. /* hw all off */
  1165. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1166. }
  1167. boolean halbtc8192e1ant_is_common_action(IN struct btc_coexist *btcoexist)
  1168. {
  1169. boolean common = false, wifi_connected = false, wifi_busy = false;
  1170. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1171. &wifi_connected);
  1172. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1173. if (!wifi_connected &&
  1174. BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  1175. coex_dm->bt_status) {
  1176. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1177. "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
  1178. BTC_TRACE(trace_buf);
  1179. /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
  1180. common = true;
  1181. } else if (wifi_connected &&
  1182. (BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  1183. coex_dm->bt_status)) {
  1184. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1185. "[BTCoex], Wifi connected + BT non connected-idle!!\n");
  1186. BTC_TRACE(trace_buf);
  1187. /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
  1188. common = true;
  1189. } else if (!wifi_connected &&
  1190. (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
  1191. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1192. "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
  1193. BTC_TRACE(trace_buf);
  1194. /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
  1195. common = true;
  1196. } else if (wifi_connected &&
  1197. (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
  1198. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1199. "[BTCoex], Wifi connected + BT connected-idle!!\n");
  1200. BTC_TRACE(trace_buf);
  1201. /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
  1202. common = true;
  1203. } else if (!wifi_connected &&
  1204. (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE != coex_dm->bt_status)) {
  1205. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1206. "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
  1207. BTC_TRACE(trace_buf);
  1208. /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */
  1209. common = true;
  1210. } else {
  1211. if (wifi_busy) {
  1212. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1213. "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
  1214. BTC_TRACE(trace_buf);
  1215. } else {
  1216. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1217. "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
  1218. BTC_TRACE(trace_buf);
  1219. }
  1220. common = false;
  1221. }
  1222. return common;
  1223. }
  1224. void halbtc8192e1ant_tdma_duration_adjust_for_acl(IN struct btc_coexist
  1225. *btcoexist, IN u8 wifi_status)
  1226. {
  1227. static s32 up, dn, m, n, wait_count;
  1228. s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
  1229. u8 retry_count = 0, bt_info_ext;
  1230. boolean wifi_busy = false;
  1231. /*static boolean pre_wifi_busy = false;*/
  1232. if (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifi_status)
  1233. wifi_busy = true;
  1234. else
  1235. wifi_busy = false;
  1236. if ((BT_8192E_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN ==
  1237. wifi_status) ||
  1238. (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifi_status) ||
  1239. (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT ==
  1240. wifi_status)) {
  1241. if (coex_dm->cur_ps_tdma != 1 &&
  1242. coex_dm->cur_ps_tdma != 2 &&
  1243. coex_dm->cur_ps_tdma != 3 &&
  1244. coex_dm->cur_ps_tdma != 9) {
  1245. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1246. 9);
  1247. coex_dm->ps_tdma_du_adj_type = 9;
  1248. up = 0;
  1249. dn = 0;
  1250. m = 1;
  1251. n = 3;
  1252. result = 0;
  1253. wait_count = 0;
  1254. }
  1255. return;
  1256. }
  1257. if (!coex_dm->auto_tdma_adjust) {
  1258. coex_dm->auto_tdma_adjust = true;
  1259. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2);
  1260. coex_dm->ps_tdma_du_adj_type = 2;
  1261. /* ============ */
  1262. up = 0;
  1263. dn = 0;
  1264. m = 1;
  1265. n = 3;
  1266. result = 0;
  1267. wait_count = 0;
  1268. } else {
  1269. /* acquire the BT TRx retry count from BT_Info byte2 */
  1270. retry_count = coex_sta->bt_retry_cnt;
  1271. bt_info_ext = coex_sta->bt_info_ext;
  1272. if ((coex_sta->low_priority_tx) > 1050 ||
  1273. (coex_sta->low_priority_rx) > 1250)
  1274. retry_count++;
  1275. result = 0;
  1276. wait_count++;
  1277. if (retry_count ==
  1278. 0) { /* no retry in the last 2-second duration */
  1279. up++;
  1280. dn--;
  1281. if (dn <= 0)
  1282. dn = 0;
  1283. if (up >= n) { /* if retry count during continuous n*2 seconds is 0, enlarge WiFi duration */
  1284. wait_count = 0;
  1285. n = 3;
  1286. up = 0;
  1287. dn = 0;
  1288. result = 1;
  1289. }
  1290. } else if (retry_count <=
  1291. 3) { /* <=3 retry in the last 2-second duration */
  1292. up--;
  1293. dn++;
  1294. if (up <= 0)
  1295. up = 0;
  1296. if (dn == 2) { /* if continuous 2 retry count(every 2 seconds) >0 and < 3, reduce WiFi duration */
  1297. if (wait_count <= 2)
  1298. m++; /* to avoid loop between the two levels */
  1299. else
  1300. m = 1;
  1301. if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */
  1302. m = 20;
  1303. n = 3 * m;
  1304. up = 0;
  1305. dn = 0;
  1306. wait_count = 0;
  1307. result = -1;
  1308. }
  1309. } else { /* retry count > 3, once retry count > 3, to reduce WiFi duration */
  1310. if (wait_count == 1)
  1311. m++; /* to avoid loop between the two levels */
  1312. else
  1313. m = 1;
  1314. if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */
  1315. m = 20;
  1316. n = 3 * m;
  1317. up = 0;
  1318. dn = 0;
  1319. wait_count = 0;
  1320. result = -1;
  1321. }
  1322. if (result == -1) {
  1323. if ((BT_INFO_8192E_1ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
  1324. ((coex_dm->cur_ps_tdma == 1) ||
  1325. (coex_dm->cur_ps_tdma == 2))) {
  1326. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1327. true, 9);
  1328. coex_dm->ps_tdma_du_adj_type = 9;
  1329. } else if (coex_dm->cur_ps_tdma == 1) {
  1330. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1331. true, 2);
  1332. coex_dm->ps_tdma_du_adj_type = 2;
  1333. } else if (coex_dm->cur_ps_tdma == 2) {
  1334. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1335. true, 9);
  1336. coex_dm->ps_tdma_du_adj_type = 9;
  1337. } else if (coex_dm->cur_ps_tdma == 9) {
  1338. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1339. true, 11);
  1340. coex_dm->ps_tdma_du_adj_type = 11;
  1341. }
  1342. } else if (result == 1) {
  1343. if ((BT_INFO_8192E_1ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
  1344. ((coex_dm->cur_ps_tdma == 1) ||
  1345. (coex_dm->cur_ps_tdma == 2))) {
  1346. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1347. true, 9);
  1348. coex_dm->ps_tdma_du_adj_type = 9;
  1349. } else if (coex_dm->cur_ps_tdma == 11) {
  1350. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1351. true, 9);
  1352. coex_dm->ps_tdma_du_adj_type = 9;
  1353. } else if (coex_dm->cur_ps_tdma == 9) {
  1354. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1355. true, 2);
  1356. coex_dm->ps_tdma_du_adj_type = 2;
  1357. } else if (coex_dm->cur_ps_tdma == 2) {
  1358. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1359. true, 1);
  1360. coex_dm->ps_tdma_du_adj_type = 1;
  1361. }
  1362. } else { /* no change */
  1363. /* Bryant Modify
  1364. if(wifi_busy != pre_wifi_busy)
  1365. {
  1366. pre_wifi_busy = wifi_busy;
  1367. halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, true, coex_dm->cur_ps_tdma);
  1368. }
  1369. */
  1370. }
  1371. if (coex_dm->cur_ps_tdma != 1 &&
  1372. coex_dm->cur_ps_tdma != 2 &&
  1373. coex_dm->cur_ps_tdma != 9 &&
  1374. coex_dm->cur_ps_tdma != 11) {
  1375. /* recover to previous adjust type */
  1376. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1377. coex_dm->ps_tdma_du_adj_type);
  1378. }
  1379. }
  1380. }
  1381. void halbtc8192e1ant_ps_tdma_check_for_power_save_state(
  1382. IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
  1383. {
  1384. u8 lps_mode = 0x0;
  1385. btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
  1386. if (lps_mode) { /* already under LPS state */
  1387. if (new_ps_state) {
  1388. /* keep state under LPS, do nothing. */
  1389. } else {
  1390. /* will leave LPS state, turn off psTdma first */
  1391. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1392. 0);
  1393. }
  1394. } else { /* NO PS state */
  1395. if (new_ps_state) {
  1396. /* will enter LPS state, turn off psTdma first */
  1397. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1398. 0);
  1399. } else {
  1400. /* keep state under NO PS state, do nothing. */
  1401. }
  1402. }
  1403. }
  1404. void halbtc8192e1ant_power_save_state(IN struct btc_coexist *btcoexist,
  1405. IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
  1406. {
  1407. boolean low_pwr_disable = false;
  1408. switch (ps_type) {
  1409. case BTC_PS_WIFI_NATIVE:
  1410. /* recover to original 32k low power setting */
  1411. low_pwr_disable = false;
  1412. btcoexist->btc_set(btcoexist,
  1413. BTC_SET_ACT_DISABLE_LOW_POWER,
  1414. &low_pwr_disable);
  1415. btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
  1416. NULL);
  1417. coex_sta->force_lps_on = false;
  1418. break;
  1419. case BTC_PS_LPS_ON:
  1420. halbtc8192e1ant_ps_tdma_check_for_power_save_state(
  1421. btcoexist, true);
  1422. halbtc8192e1ant_lps_rpwm(btcoexist, NORMAL_EXEC,
  1423. lps_val, rpwm_val);
  1424. /* when coex force to enter LPS, do not enter 32k low power. */
  1425. low_pwr_disable = true;
  1426. btcoexist->btc_set(btcoexist,
  1427. BTC_SET_ACT_DISABLE_LOW_POWER,
  1428. &low_pwr_disable);
  1429. /* power save must executed before psTdma. */
  1430. btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
  1431. NULL);
  1432. coex_sta->force_lps_on = true;
  1433. break;
  1434. case BTC_PS_LPS_OFF:
  1435. halbtc8192e1ant_ps_tdma_check_for_power_save_state(
  1436. btcoexist, false);
  1437. btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
  1438. NULL);
  1439. coex_sta->force_lps_on = false;
  1440. break;
  1441. default:
  1442. break;
  1443. }
  1444. }
  1445. void halbtc8192e1ant_action_wifi_only(IN struct btc_coexist *btcoexist)
  1446. {
  1447. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1448. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 9);
  1449. }
  1450. void halbtc8192e1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
  1451. {
  1452. static u32 bt_disable_cnt = 0;
  1453. boolean bt_active = true, bt_disabled = false;
  1454. /* This function check if bt is disabled */
  1455. if (coex_sta->high_priority_tx == 0 &&
  1456. coex_sta->high_priority_rx == 0 &&
  1457. coex_sta->low_priority_tx == 0 &&
  1458. coex_sta->low_priority_rx == 0)
  1459. bt_active = false;
  1460. if (coex_sta->high_priority_tx == 0xffff &&
  1461. coex_sta->high_priority_rx == 0xffff &&
  1462. coex_sta->low_priority_tx == 0xffff &&
  1463. coex_sta->low_priority_rx == 0xffff)
  1464. bt_active = false;
  1465. if (bt_active) {
  1466. bt_disable_cnt = 0;
  1467. bt_disabled = false;
  1468. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
  1469. &bt_disabled);
  1470. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1471. "[BTCoex], BT is enabled !!\n");
  1472. BTC_TRACE(trace_buf);
  1473. } else {
  1474. bt_disable_cnt++;
  1475. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1476. "[BTCoex], bt all counters=0, %d times!!\n",
  1477. bt_disable_cnt);
  1478. BTC_TRACE(trace_buf);
  1479. if (bt_disable_cnt >= 2) {
  1480. bt_disabled = true;
  1481. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
  1482. &bt_disabled);
  1483. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1484. "[BTCoex], BT is disabled !!\n");
  1485. BTC_TRACE(trace_buf);
  1486. halbtc8192e1ant_action_wifi_only(btcoexist);
  1487. }
  1488. }
  1489. if (coex_sta->bt_disabled != bt_disabled) {
  1490. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1491. "[BTCoex], BT is from %s to %s!!\n",
  1492. (coex_sta->bt_disabled ? "disabled" : "enabled"),
  1493. (bt_disabled ? "disabled" : "enabled"));
  1494. BTC_TRACE(trace_buf);
  1495. coex_sta->bt_disabled = bt_disabled;
  1496. if (!bt_disabled) {
  1497. } else {
  1498. btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
  1499. NULL);
  1500. btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
  1501. NULL);
  1502. }
  1503. }
  1504. }
  1505. /* *********************************************
  1506. *
  1507. * Software Coex Mechanism start
  1508. *
  1509. * ********************************************* */
  1510. /* SCO only or SCO+PAN(HS) */
  1511. /*
  1512. void halbtc8192e1ant_action_sco(IN struct btc_coexist* btcoexist)
  1513. {
  1514. halbtc8192e1ant_sw_mechanism(btcoexist, true);
  1515. }
  1516. void halbtc8192e1ant_action_hid(IN struct btc_coexist* btcoexist)
  1517. {
  1518. halbtc8192e1ant_sw_mechanism(btcoexist, true);
  1519. }
  1520. void halbtc8192e1ant_action_a2dp(IN struct btc_coexist* btcoexist)
  1521. {
  1522. halbtc8192e1ant_sw_mechanism(btcoexist, false);
  1523. }
  1524. void halbtc8192e1ant_action_a2dp_pan_hs(IN struct btc_coexist* btcoexist)
  1525. {
  1526. halbtc8192e1ant_sw_mechanism(btcoexist, false);
  1527. }
  1528. void halbtc8192e1ant_action_pan_edr(IN struct btc_coexist* btcoexist)
  1529. {
  1530. halbtc8192e1ant_sw_mechanism(btcoexist, false);
  1531. }
  1532. void halbtc8192e1ant_action_pan_hs(IN struct btc_coexist* btcoexist)
  1533. {
  1534. halbtc8192e1ant_sw_mechanism(btcoexist, false);
  1535. }
  1536. void halbtc8192e1ant_action_pan_edr_a2dp(IN struct btc_coexist* btcoexist)
  1537. {
  1538. halbtc8192e1ant_sw_mechanism(btcoexist, false);
  1539. }
  1540. void halbtc8192e1ant_action_pan_edr_hid(IN struct btc_coexist* btcoexist)
  1541. {
  1542. halbtc8192e1ant_sw_mechanism(btcoexist, true);
  1543. }
  1544. void halbtc8192e1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist* btcoexist)
  1545. {
  1546. halbtc8192e1ant_sw_mechanism(btcoexist, true);
  1547. }
  1548. void halbtc8192e1ant_action_hid_a2dp(IN struct btc_coexist* btcoexist)
  1549. {
  1550. halbtc8192e1ant_sw_mechanism(btcoexist, true);
  1551. }
  1552. */
  1553. /* *********************************************
  1554. *
  1555. * Non-Software Coex Mechanism start
  1556. *
  1557. * ********************************************* */
  1558. void halbtc8192e1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
  1559. {
  1560. halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1561. 0x0);
  1562. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1563. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1564. }
  1565. void halbtc8192e1ant_action_hs(IN struct btc_coexist *btcoexist)
  1566. {
  1567. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  1568. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1569. }
  1570. void halbtc8192e1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
  1571. {
  1572. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1573. boolean wifi_connected = false, ap_enable = false, wifi_busy = false,
  1574. bt_busy = false;
  1575. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1576. &ap_enable);
  1577. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1578. &wifi_connected);
  1579. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1580. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  1581. if ((!wifi_connected) && (!coex_sta->wifi_is_high_pri_task)) {
  1582. halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1583. 0x0, 0x0);
  1584. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1585. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1586. } else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
  1587. (bt_link_info->a2dp_exist)) {
  1588. /* SCO/HID/A2DP busy */
  1589. halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1590. 0x0, 0x0);
  1591. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  1592. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1593. } else if ((bt_link_info->pan_exist) || (wifi_busy)) {
  1594. halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1595. 0x0, 0x0);
  1596. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1597. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1598. } else {
  1599. halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1600. 0x0, 0x0);
  1601. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1602. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  1603. }
  1604. }
  1605. void halbtc8192e1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist
  1606. *btcoexist, IN u8 wifi_status)
  1607. {
  1608. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1609. boolean wifi_connected = false;
  1610. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1611. &wifi_connected);
  1612. /* tdma and coex table */
  1613. if (bt_link_info->sco_exist) {
  1614. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  1615. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
  1616. } else { /* HID */
  1617. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6);
  1618. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
  1619. }
  1620. }
  1621. void halbtc8192e1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist
  1622. *btcoexist, IN u8 wifi_status)
  1623. {
  1624. u8 bt_rssi_state;
  1625. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1626. bt_rssi_state = halbtc8192e1ant_bt_rssi_state(2, 28, 0);
  1627. if ((coex_sta->low_priority_rx >= 1000) &&
  1628. (coex_sta->low_priority_rx != 65535))
  1629. bt_link_info->slave_role = true;
  1630. else
  1631. bt_link_info->slave_role = false;
  1632. if (bt_link_info->hid_only) { /* HID */
  1633. halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
  1634. wifi_status);
  1635. coex_dm->auto_tdma_adjust = false;
  1636. return;
  1637. } else if (bt_link_info->a2dp_only) { /* A2DP */
  1638. if (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) {
  1639. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1640. 32);
  1641. halbtc8192e1ant_coex_table_with_type(btcoexist,
  1642. NORMAL_EXEC, 4);
  1643. coex_dm->auto_tdma_adjust = false;
  1644. } else {
  1645. halbtc8192e1ant_tdma_duration_adjust_for_acl(btcoexist,
  1646. wifi_status);
  1647. #if 0
  1648. if (coex_sta->cck_lock)
  1649. halbtc8192e1ant_coex_table_with_type(btcoexist,
  1650. NORMAL_EXEC, 3);
  1651. else
  1652. #endif
  1653. halbtc8192e1ant_coex_table_with_type(btcoexist,
  1654. NORMAL_EXEC, 4);
  1655. coex_dm->auto_tdma_adjust = true;
  1656. }
  1657. } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
  1658. (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
  1659. bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
  1660. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
  1661. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1662. coex_dm->auto_tdma_adjust = false;
  1663. } else if (bt_link_info->hid_exist &&
  1664. bt_link_info->a2dp_exist) { /* HID+A2DP */
  1665. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
  1666. coex_dm->auto_tdma_adjust = false;
  1667. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
  1668. } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist &&
  1669. bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */
  1670. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
  1671. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1672. coex_dm->auto_tdma_adjust = false;
  1673. } else {
  1674. /* BT no-profile busy (0x9) */
  1675. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  1676. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1677. coex_dm->auto_tdma_adjust = false;
  1678. }
  1679. }
  1680. void halbtc8192e1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
  1681. {
  1682. /* power save state */
  1683. halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1684. 0x0);
  1685. /* tdma and coex table */
  1686. halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
  1687. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1688. }
  1689. void halbtc8192e1ant_action_wifi_not_connected_scan(IN struct btc_coexist
  1690. *btcoexist)
  1691. {
  1692. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1693. halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1694. 0x0);
  1695. /* tdma and coex table */
  1696. if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1697. if (bt_link_info->a2dp_exist) {
  1698. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1699. 32);
  1700. halbtc8192e1ant_coex_table_with_type(btcoexist,
  1701. NORMAL_EXEC, 4);
  1702. } else if (bt_link_info->a2dp_exist &&
  1703. bt_link_info->pan_exist) {
  1704. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1705. 22);
  1706. halbtc8192e1ant_coex_table_with_type(btcoexist,
  1707. NORMAL_EXEC, 4);
  1708. } else {
  1709. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1710. 20);
  1711. halbtc8192e1ant_coex_table_with_type(btcoexist,
  1712. NORMAL_EXEC, 4);
  1713. }
  1714. } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  1715. (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1716. coex_dm->bt_status)) {
  1717. halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
  1718. BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN);
  1719. } else {
  1720. /* Bryant Add */
  1721. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1722. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1723. }
  1724. }
  1725. void halbtc8192e1ant_action_wifi_not_connected_asso_auth(
  1726. IN struct btc_coexist *btcoexist)
  1727. {
  1728. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1729. halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1730. 0x0);
  1731. /* tdma and coex table */
  1732. if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
  1733. (bt_link_info->a2dp_exist)) {
  1734. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  1735. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1736. } else if (bt_link_info->pan_exist) {
  1737. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1738. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1739. } else {
  1740. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1741. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1742. }
  1743. }
  1744. void halbtc8192e1ant_action_wifi_connected_scan(IN struct btc_coexist
  1745. *btcoexist)
  1746. {
  1747. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1748. halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1749. 0x0);
  1750. /* tdma and coex table */
  1751. if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1752. if (bt_link_info->a2dp_exist) {
  1753. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1754. 32);
  1755. halbtc8192e1ant_coex_table_with_type(btcoexist,
  1756. NORMAL_EXEC, 4);
  1757. } else if (bt_link_info->a2dp_exist &&
  1758. bt_link_info->pan_exist) {
  1759. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1760. 22);
  1761. halbtc8192e1ant_coex_table_with_type(btcoexist,
  1762. NORMAL_EXEC, 4);
  1763. } else {
  1764. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1765. 20);
  1766. halbtc8192e1ant_coex_table_with_type(btcoexist,
  1767. NORMAL_EXEC, 4);
  1768. }
  1769. } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  1770. (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1771. coex_dm->bt_status)) {
  1772. halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
  1773. BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN);
  1774. } else {
  1775. /* Bryant Add */
  1776. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1777. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1778. }
  1779. }
  1780. void halbtc8192e1ant_action_wifi_connected_specific_packet(
  1781. IN struct btc_coexist *btcoexist)
  1782. {
  1783. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1784. halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1785. 0x0);
  1786. /* tdma and coex table */
  1787. if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
  1788. (bt_link_info->a2dp_exist)) {
  1789. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  1790. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1791. } else if (bt_link_info->pan_exist) {
  1792. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1793. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1794. } else {
  1795. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1796. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1797. }
  1798. }
  1799. void halbtc8192e1ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
  1800. {
  1801. boolean wifi_busy = false;
  1802. boolean scan = false, link = false, roam = false;
  1803. boolean under_4way = false, ap_enable = false;
  1804. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1805. "[BTCoex], CoexForWifiConnect()===>\n");
  1806. BTC_TRACE(trace_buf);
  1807. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  1808. &under_4way);
  1809. if (under_4way) {
  1810. halbtc8192e1ant_action_wifi_connected_specific_packet(btcoexist);
  1811. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1812. "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
  1813. BTC_TRACE(trace_buf);
  1814. return;
  1815. }
  1816. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  1817. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  1818. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  1819. if (scan || link || roam) {
  1820. if (scan)
  1821. halbtc8192e1ant_action_wifi_connected_scan(btcoexist);
  1822. else
  1823. halbtc8192e1ant_action_wifi_connected_specific_packet(
  1824. btcoexist);
  1825. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1826. "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
  1827. BTC_TRACE(trace_buf);
  1828. return;
  1829. }
  1830. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1831. &ap_enable);
  1832. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1833. /* power save state */
  1834. if (!ap_enable &&
  1835. BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status &&
  1836. !btcoexist->bt_link_info.hid_only) {
  1837. if (btcoexist->bt_link_info.a2dp_only) { /* A2DP */
  1838. if (!wifi_busy)
  1839. halbtc8192e1ant_power_save_state(btcoexist,
  1840. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1841. else { /* busy */
  1842. if (coex_sta->scan_ap_num >=
  1843. BT_8192E_1ANT_WIFI_NOISY_THRESH) /* no force LPS, no PS-TDMA, use pure TDMA */
  1844. halbtc8192e1ant_power_save_state(
  1845. btcoexist, BTC_PS_WIFI_NATIVE,
  1846. 0x0, 0x0);
  1847. else
  1848. halbtc8192e1ant_power_save_state(
  1849. btcoexist, BTC_PS_LPS_ON, 0x50,
  1850. 0x4);
  1851. }
  1852. } else if ((coex_sta->pan_exist == false) &&
  1853. (coex_sta->a2dp_exist == false) &&
  1854. (coex_sta->hid_exist == false))
  1855. halbtc8192e1ant_power_save_state(btcoexist,
  1856. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1857. else
  1858. halbtc8192e1ant_power_save_state(btcoexist,
  1859. BTC_PS_LPS_ON, 0x50, 0x4);
  1860. } else
  1861. halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1862. 0x0, 0x0);
  1863. /* tdma and coex table */
  1864. if (!wifi_busy) {
  1865. if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1866. halbtc8192e1ant_action_wifi_connected_bt_acl_busy(
  1867. btcoexist,
  1868. BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE);
  1869. } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY ==
  1870. coex_dm->bt_status) ||
  1871. (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1872. coex_dm->bt_status)) {
  1873. halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
  1874. BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE);
  1875. } else {
  1876. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1877. 8);
  1878. if ((coex_sta->high_priority_tx) +
  1879. (coex_sta->high_priority_rx) <= 60)
  1880. halbtc8192e1ant_coex_table_with_type(btcoexist,
  1881. NORMAL_EXEC, 2);
  1882. else
  1883. halbtc8192e1ant_coex_table_with_type(btcoexist,
  1884. NORMAL_EXEC, 7);
  1885. }
  1886. } else {
  1887. if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1888. halbtc8192e1ant_action_wifi_connected_bt_acl_busy(
  1889. btcoexist,
  1890. BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY);
  1891. } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY ==
  1892. coex_dm->bt_status) ||
  1893. (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1894. coex_dm->bt_status)) {
  1895. halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist,
  1896. BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY);
  1897. } else {
  1898. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1899. 8);
  1900. if ((coex_sta->high_priority_tx) +
  1901. (coex_sta->high_priority_rx) <= 60)
  1902. halbtc8192e1ant_coex_table_with_type(btcoexist,
  1903. NORMAL_EXEC, 2);
  1904. else
  1905. halbtc8192e1ant_coex_table_with_type(btcoexist,
  1906. NORMAL_EXEC, 7);
  1907. }
  1908. }
  1909. }
  1910. void halbtc8192e1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist)
  1911. {
  1912. u8 algorithm = 0;
  1913. algorithm = halbtc8192e1ant_action_algorithm(btcoexist);
  1914. coex_dm->cur_algorithm = algorithm;
  1915. if (halbtc8192e1ant_is_common_action(btcoexist)) {
  1916. } else {
  1917. switch (coex_dm->cur_algorithm) {
  1918. case BT_8192E_1ANT_COEX_ALGO_SCO:
  1919. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1920. "[BTCoex], Action algorithm = SCO.\n");
  1921. BTC_TRACE(trace_buf);
  1922. /* halbtc8192e1ant_action_sco(btcoexist); */
  1923. break;
  1924. case BT_8192E_1ANT_COEX_ALGO_HID:
  1925. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1926. "[BTCoex], Action algorithm = HID.\n");
  1927. BTC_TRACE(trace_buf);
  1928. /* halbtc8192e1ant_action_hid(btcoexist); */
  1929. break;
  1930. case BT_8192E_1ANT_COEX_ALGO_A2DP:
  1931. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1932. "[BTCoex], Action algorithm = A2DP.\n");
  1933. BTC_TRACE(trace_buf);
  1934. /* halbtc8192e1ant_action_a2dp(btcoexist); */
  1935. break;
  1936. case BT_8192E_1ANT_COEX_ALGO_A2DP_PANHS:
  1937. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1938. "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
  1939. BTC_TRACE(trace_buf);
  1940. /* halbtc8192e1ant_action_a2dp_pan_hs(btcoexist); */
  1941. break;
  1942. case BT_8192E_1ANT_COEX_ALGO_PANEDR:
  1943. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1944. "[BTCoex], Action algorithm = PAN(EDR).\n");
  1945. BTC_TRACE(trace_buf);
  1946. /* halbtc8192e1ant_action_pan_edr(btcoexist); */
  1947. break;
  1948. case BT_8192E_1ANT_COEX_ALGO_PANHS:
  1949. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1950. "[BTCoex], Action algorithm = HS mode.\n");
  1951. BTC_TRACE(trace_buf);
  1952. /* halbtc8192e1ant_action_pan_hs(btcoexist); */
  1953. break;
  1954. case BT_8192E_1ANT_COEX_ALGO_PANEDR_A2DP:
  1955. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1956. "[BTCoex], Action algorithm = PAN+A2DP.\n");
  1957. BTC_TRACE(trace_buf);
  1958. /* halbtc8192e1ant_action_pan_edr_a2dp(btcoexist); */
  1959. break;
  1960. case BT_8192E_1ANT_COEX_ALGO_PANEDR_HID:
  1961. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1962. "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
  1963. BTC_TRACE(trace_buf);
  1964. /* halbtc8192e1ant_action_pan_edr_hid(btcoexist); */
  1965. break;
  1966. case BT_8192E_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
  1967. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1968. "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
  1969. BTC_TRACE(trace_buf);
  1970. /* halbtc8192e1ant_action_hid_a2dp_pan_edr(btcoexist); */
  1971. break;
  1972. case BT_8192E_1ANT_COEX_ALGO_HID_A2DP:
  1973. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1974. "[BTCoex], Action algorithm = HID+A2DP.\n");
  1975. BTC_TRACE(trace_buf);
  1976. /* halbtc8192e1ant_action_hid_a2dp(btcoexist); */
  1977. break;
  1978. default:
  1979. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1980. "[BTCoex], Action algorithm = coexist All Off!!\n");
  1981. BTC_TRACE(trace_buf);
  1982. /* halbtc8192e1ant_coex_all_off(btcoexist); */
  1983. break;
  1984. }
  1985. coex_dm->pre_algorithm = coex_dm->cur_algorithm;
  1986. }
  1987. }
  1988. void halbtc8192e1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
  1989. {
  1990. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1991. boolean wifi_connected = false, bt_hs_on = false;
  1992. boolean increase_scan_dev_num = false;
  1993. boolean bt_ctrl_agg_buf_size = false;
  1994. boolean miracast_plus_bt = false;
  1995. u8 agg_buf_size = 5;
  1996. u32 wifi_link_status = 0;
  1997. u32 num_of_wifi_link = 0;
  1998. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1999. "[BTCoex], RunCoexistMechanism()===>\n");
  2000. BTC_TRACE(trace_buf);
  2001. if (btcoexist->manual_control) {
  2002. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2003. "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
  2004. BTC_TRACE(trace_buf);
  2005. return;
  2006. }
  2007. if (btcoexist->stop_coex_dm) {
  2008. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2009. "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
  2010. BTC_TRACE(trace_buf);
  2011. return;
  2012. }
  2013. if (coex_sta->under_ips) {
  2014. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2015. "[BTCoex], wifi is under IPS !!!\n");
  2016. BTC_TRACE(trace_buf);
  2017. return;
  2018. }
  2019. if ((BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  2020. (BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  2021. (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
  2022. increase_scan_dev_num = true;
  2023. btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
  2024. &increase_scan_dev_num);
  2025. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2026. &wifi_connected);
  2027. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2028. &wifi_link_status);
  2029. num_of_wifi_link = wifi_link_status >> 16;
  2030. if ((num_of_wifi_link >= 2) ||
  2031. (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
  2032. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2033. "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
  2034. num_of_wifi_link, wifi_link_status);
  2035. BTC_TRACE(trace_buf);
  2036. if (bt_link_info->bt_link_exist) {
  2037. halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1,
  2038. 0, 1);
  2039. miracast_plus_bt = true;
  2040. } else {
  2041. halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0,
  2042. 0, 0);
  2043. miracast_plus_bt = false;
  2044. }
  2045. btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
  2046. &miracast_plus_bt);
  2047. halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2048. bt_ctrl_agg_buf_size, agg_buf_size);
  2049. if ((bt_link_info->a2dp_exist) &&
  2050. (coex_sta->c2h_bt_inquiry_page)) {
  2051. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2052. "############# [BTCoex], BT Is Inquirying\n");
  2053. BTC_TRACE(trace_buf);
  2054. halbtc8192e1ant_action_bt_inquiry(btcoexist);
  2055. } else
  2056. halbtc8192e1ant_action_wifi_multi_port(btcoexist);
  2057. return;
  2058. }
  2059. miracast_plus_bt = false;
  2060. btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
  2061. &miracast_plus_bt);
  2062. if ((bt_link_info->bt_link_exist) && (wifi_connected)) {
  2063. halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1);
  2064. if (bt_link_info->sco_exist)
  2065. halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC,
  2066. false, true, 0x5);
  2067. else
  2068. halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC,
  2069. false, true, 0x8);
  2070. halbtc8192e1ant_sw_mechanism(btcoexist, true);
  2071. halbtc8192e1ant_run_sw_coexist_mechanism(
  2072. btcoexist); /* just print debug message */
  2073. } else {
  2074. halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2075. halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
  2076. 0x5);
  2077. halbtc8192e1ant_sw_mechanism(btcoexist, false);
  2078. halbtc8192e1ant_run_sw_coexist_mechanism(
  2079. btcoexist); /* just print debug message */
  2080. }
  2081. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2082. if (coex_sta->c2h_bt_inquiry_page) {
  2083. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2084. "############# [BTCoex], BT Is Inquirying\n");
  2085. BTC_TRACE(trace_buf);
  2086. halbtc8192e1ant_action_bt_inquiry(btcoexist);
  2087. return;
  2088. } else if (bt_hs_on) {
  2089. halbtc8192e1ant_action_hs(btcoexist);
  2090. return;
  2091. }
  2092. if (!wifi_connected) {
  2093. boolean scan = false, link = false, roam = false;
  2094. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2095. "[BTCoex], wifi is non connected-idle !!!\n");
  2096. BTC_TRACE(trace_buf);
  2097. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  2098. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  2099. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  2100. if (scan || link || roam) {
  2101. if (scan)
  2102. halbtc8192e1ant_action_wifi_not_connected_scan(
  2103. btcoexist);
  2104. else
  2105. halbtc8192e1ant_action_wifi_not_connected_asso_auth(
  2106. btcoexist);
  2107. } else
  2108. halbtc8192e1ant_action_wifi_not_connected(btcoexist);
  2109. } else /* wifi LPS/Busy */
  2110. halbtc8192e1ant_action_wifi_connected(btcoexist);
  2111. }
  2112. void halbtc8192e1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  2113. {
  2114. /* force to reset coex mechanism */
  2115. /* sw all off */
  2116. halbtc8192e1ant_sw_mechanism(btcoexist, false);
  2117. /* halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */
  2118. halbtc8192e1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  2119. coex_sta->pop_event_cnt = 0;
  2120. }
  2121. void halbtc8192e1ant_init_hw_config(IN struct btc_coexist *btcoexist,
  2122. IN boolean wifi_only)
  2123. {
  2124. u16 u16tmp = 0;
  2125. u8 u8tmp = 0;
  2126. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2127. "[BTCoex], 1Ant Init HW Config!!\n");
  2128. BTC_TRACE(trace_buf);
  2129. /* antenna sw ctrl to bt */
  2130. halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, true, false);
  2131. halbtc8192e1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  2132. /* antenna switch control parameter */
  2133. btcoexist->btc_write_4byte(btcoexist, 0x858, 0x55555555);
  2134. /* coex parameters */
  2135. btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
  2136. /* 0x790[5:0]=0x5 */
  2137. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
  2138. u8tmp &= 0xc0;
  2139. u8tmp |= 0x5;
  2140. btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
  2141. /* enable counter statistics */
  2142. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
  2143. /* enable PTA */
  2144. btcoexist->btc_write_1byte(btcoexist, 0x40, 0x20);
  2145. /* enable mailbox interface */
  2146. u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x40);
  2147. u16tmp |= BIT(9);
  2148. btcoexist->btc_write_2byte(btcoexist, 0x40, u16tmp);
  2149. /* enable PTA I2C mailbox */
  2150. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x101);
  2151. u8tmp |= BIT(4);
  2152. btcoexist->btc_write_1byte(btcoexist, 0x101, u8tmp);
  2153. /* enable bt clock when wifi is disabled. */
  2154. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x93);
  2155. u8tmp |= BIT(0);
  2156. btcoexist->btc_write_1byte(btcoexist, 0x93, u8tmp);
  2157. /* enable bt clock when suspend. */
  2158. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x7);
  2159. u8tmp |= BIT(0);
  2160. btcoexist->btc_write_1byte(btcoexist, 0x7, u8tmp);
  2161. }
  2162. /*
  2163. void halbtc8192e1ant_wifi_off_hw_cfg(IN struct btc_coexist* btcoexist)
  2164. {
  2165. }
  2166. */
  2167. /* ************************************************************
  2168. * work around function start with wa_halbtc8192e1ant_
  2169. * ************************************************************
  2170. * ************************************************************
  2171. * extern function start with ex_halbtc8192e1ant_
  2172. * ************************************************************ */
  2173. void ex_halbtc8192e1ant_power_on_setting(IN struct btc_coexist *btcoexist)
  2174. {
  2175. #if 0
  2176. struct btc_board_info *board_info = &btcoexist->board_info;
  2177. u8 u8tmp = 0x0;
  2178. u16 u16tmp = 0x0;
  2179. btcoexist->stop_coex_dm = true;
  2180. btcoexist->btc_write_1byte(btcoexist, 0x67, 0x20);
  2181. /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
  2182. u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2);
  2183. btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1));
  2184. /* set GRAN_BT = 1 */
  2185. btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18);
  2186. /* set WLAN_ACT = 0 */
  2187. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
  2188. /* */
  2189. /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */
  2190. /* Local setting bit define */
  2191. /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */
  2192. /* BIT1: "0" for internal switch; "1" for external switch */
  2193. /* BIT2: "0" for one antenna; "1" for two antenna */
  2194. /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */
  2195. if (btcoexist->chip_interface == BTC_INTF_USB) {
  2196. /* fixed at S0 for USB interface */
  2197. btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0);
  2198. u8tmp |= 0x1; /* antenna inverse */
  2199. btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
  2200. board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
  2201. } else {
  2202. /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
  2203. if (board_info->single_ant_path == 0) {
  2204. /* set to S1 */
  2205. btcoexist->btc_write_4byte(btcoexist, 0x948, 0x280);
  2206. board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
  2207. } else if (board_info->single_ant_path == 1) {
  2208. /* set to S0 */
  2209. btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0);
  2210. u8tmp |= 0x1; /* antenna inverse */
  2211. board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
  2212. }
  2213. if (btcoexist->chip_interface == BTC_INTF_PCI)
  2214. btcoexist->btc_write_local_reg_1byte(btcoexist, 0x384,
  2215. u8tmp);
  2216. else if (btcoexist->chip_interface == BTC_INTF_SDIO)
  2217. btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60,
  2218. u8tmp);
  2219. }
  2220. #endif
  2221. }
  2222. void ex_halbtc8192e1ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
  2223. {
  2224. }
  2225. void ex_halbtc8192e1ant_init_hw_config(IN struct btc_coexist *btcoexist,
  2226. IN boolean wifi_only)
  2227. {
  2228. halbtc8192e1ant_init_hw_config(btcoexist, wifi_only);
  2229. btcoexist->stop_coex_dm = false;
  2230. }
  2231. void ex_halbtc8192e1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  2232. {
  2233. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2234. "[BTCoex], Coex Mechanism Init!!\n");
  2235. BTC_TRACE(trace_buf);
  2236. btcoexist->stop_coex_dm = false;
  2237. halbtc8192e1ant_init_coex_dm(btcoexist);
  2238. halbtc8192e1ant_query_bt_info(btcoexist);
  2239. }
  2240. void ex_halbtc8192e1ant_display_coex_info(IN struct btc_coexist *btcoexist)
  2241. {
  2242. struct btc_board_info *board_info = &btcoexist->board_info;
  2243. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2244. u8 *cli_buf = btcoexist->cli_buf;
  2245. u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
  2246. u32 u32tmp[4];
  2247. u32 fw_ver = 0, bt_patch_ver = 0;
  2248. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2249. "\r\n ============[BT Coexist info]============");
  2250. CL_PRINTF(cli_buf);
  2251. if (btcoexist->manual_control) {
  2252. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2253. "\r\n ============[Under Manual Control]============");
  2254. CL_PRINTF(cli_buf);
  2255. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2256. "\r\n ==========================================");
  2257. CL_PRINTF(cli_buf);
  2258. }
  2259. if (btcoexist->stop_coex_dm) {
  2260. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2261. "\r\n ============[Coex is STOPPED]============");
  2262. CL_PRINTF(cli_buf);
  2263. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2264. "\r\n ==========================================");
  2265. CL_PRINTF(cli_buf);
  2266. }
  2267. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
  2268. "Ant PG number/ Ant mechanism:",
  2269. board_info->pg_ant_num, board_info->btdm_ant_num);
  2270. CL_PRINTF(cli_buf);
  2271. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
  2272. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  2273. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2274. "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)",
  2275. "CoexVer/ FwVer/ PatchVer",
  2276. glcoex_ver_date_8192e_1ant, glcoex_ver_8192e_1ant, fw_ver,
  2277. bt_patch_ver, bt_patch_ver);
  2278. CL_PRINTF(cli_buf);
  2279. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
  2280. "Wifi channel informed to BT",
  2281. coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
  2282. coex_dm->wifi_chnl_info[2]);
  2283. CL_PRINTF(cli_buf);
  2284. /* wifi status */
  2285. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  2286. "============[Wifi Status]============");
  2287. CL_PRINTF(cli_buf);
  2288. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
  2289. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  2290. "============[BT Status]============");
  2291. CL_PRINTF(cli_buf);
  2292. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ",
  2293. "BT [status/ rssi/ retryCnt]",
  2294. ((coex_sta->bt_disabled) ? ("disabled") : ((
  2295. coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
  2296. : ((BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  2297. coex_dm->bt_status) ? "non-connected idle" :
  2298. ((BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
  2299. ? "connected-idle" : "busy")))),
  2300. coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
  2301. CL_PRINTF(cli_buf);
  2302. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
  2303. "SCO/HID/PAN/A2DP",
  2304. bt_link_info->sco_exist, bt_link_info->hid_exist,
  2305. bt_link_info->pan_exist, bt_link_info->a2dp_exist);
  2306. CL_PRINTF(cli_buf);
  2307. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
  2308. bt_info_ext = coex_sta->bt_info_ext;
  2309. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
  2310. "BT Info A2DP rate",
  2311. (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
  2312. CL_PRINTF(cli_buf);
  2313. for (i = 0; i < BT_INFO_SRC_8192E_1ANT_MAX; i++) {
  2314. if (coex_sta->bt_info_c2h_cnt[i]) {
  2315. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2316. "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
  2317. glbt_info_src_8192e_1ant[i],
  2318. coex_sta->bt_info_c2h[i][0],
  2319. coex_sta->bt_info_c2h[i][1],
  2320. coex_sta->bt_info_c2h[i][2],
  2321. coex_sta->bt_info_c2h[i][3],
  2322. coex_sta->bt_info_c2h[i][4],
  2323. coex_sta->bt_info_c2h[i][5],
  2324. coex_sta->bt_info_c2h[i][6],
  2325. coex_sta->bt_info_c2h_cnt[i]);
  2326. CL_PRINTF(cli_buf);
  2327. }
  2328. }
  2329. if (!btcoexist->manual_control) {
  2330. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  2331. "============[mechanisms]============");
  2332. CL_PRINTF(cli_buf);
  2333. ps_tdma_case = coex_dm->cur_ps_tdma;
  2334. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2335. "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)",
  2336. "PS TDMA",
  2337. coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
  2338. coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
  2339. coex_dm->ps_tdma_para[4], ps_tdma_case,
  2340. coex_dm->auto_tdma_adjust);
  2341. CL_PRINTF(cli_buf);
  2342. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ",
  2343. "Latest error condition(should be 0)",
  2344. coex_dm->error_condition);
  2345. CL_PRINTF(cli_buf);
  2346. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ",
  2347. "IgnWlanAct",
  2348. coex_dm->cur_ignore_wlan_act);
  2349. CL_PRINTF(cli_buf);
  2350. }
  2351. /* Hw setting */
  2352. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  2353. "============[Hw setting]============");
  2354. CL_PRINTF(cli_buf);
  2355. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc04);
  2356. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xd04);
  2357. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x90c);
  2358. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  2359. "0xc04/ 0xd04/ 0x90c",
  2360. u32tmp[0], u32tmp[1], u32tmp[2]);
  2361. CL_PRINTF(cli_buf);
  2362. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
  2363. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x778",
  2364. u8tmp[0]);
  2365. CL_PRINTF(cli_buf);
  2366. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x92c);
  2367. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x930);
  2368. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  2369. "0x92c/ 0x930",
  2370. (u8tmp[0]), u32tmp[0]);
  2371. CL_PRINTF(cli_buf);
  2372. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
  2373. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x4f);
  2374. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  2375. "0x40/ 0x4f",
  2376. u8tmp[0], u8tmp[1]);
  2377. CL_PRINTF(cli_buf);
  2378. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
  2379. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
  2380. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  2381. "0x550(bcn ctrl)/0x522",
  2382. u32tmp[0], u8tmp[0]);
  2383. CL_PRINTF(cli_buf);
  2384. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
  2385. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)",
  2386. u32tmp[0]);
  2387. CL_PRINTF(cli_buf);
  2388. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
  2389. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
  2390. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
  2391. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
  2392. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2393. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  2394. "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
  2395. u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]);
  2396. CL_PRINTF(cli_buf);
  2397. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  2398. "0x770(hp rx[31:16]/tx[15:0])",
  2399. coex_sta->high_priority_rx, coex_sta->high_priority_tx);
  2400. CL_PRINTF(cli_buf);
  2401. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  2402. "0x774(lp rx[31:16]/tx[15:0])",
  2403. coex_sta->low_priority_rx, coex_sta->low_priority_tx);
  2404. CL_PRINTF(cli_buf);
  2405. #if (BT_AUTO_REPORT_ONLY_8192E_1ANT == 1)
  2406. halbtc8192e1ant_monitor_bt_ctr(btcoexist);
  2407. #endif
  2408. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
  2409. }
  2410. void ex_halbtc8192e1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  2411. {
  2412. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  2413. return;
  2414. if (BTC_IPS_ENTER == type) {
  2415. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2416. "[BTCoex], IPS ENTER notify\n");
  2417. BTC_TRACE(trace_buf);
  2418. coex_sta->under_ips = true;
  2419. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2420. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2421. halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
  2422. true);
  2423. } else if (BTC_IPS_LEAVE == type) {
  2424. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2425. "[BTCoex], IPS LEAVE notify\n");
  2426. BTC_TRACE(trace_buf);
  2427. coex_sta->under_ips = false;
  2428. halbtc8192e1ant_init_hw_config(btcoexist, false);
  2429. halbtc8192e1ant_init_coex_dm(btcoexist);
  2430. halbtc8192e1ant_query_bt_info(btcoexist);
  2431. }
  2432. }
  2433. void ex_halbtc8192e1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  2434. {
  2435. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  2436. return;
  2437. if (BTC_LPS_ENABLE == type) {
  2438. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2439. "[BTCoex], LPS ENABLE notify\n");
  2440. BTC_TRACE(trace_buf);
  2441. coex_sta->under_lps = true;
  2442. } else if (BTC_LPS_DISABLE == type) {
  2443. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2444. "[BTCoex], LPS DISABLE notify\n");
  2445. BTC_TRACE(trace_buf);
  2446. coex_sta->under_lps = false;
  2447. }
  2448. }
  2449. void ex_halbtc8192e1ant_scan_notify(IN struct btc_coexist *btcoexist,
  2450. IN u8 type)
  2451. {
  2452. boolean wifi_connected = false, bt_hs_on = false;
  2453. u32 wifi_link_status = 0;
  2454. u32 num_of_wifi_link = 0;
  2455. boolean bt_ctrl_agg_buf_size = false;
  2456. u8 agg_buf_size = 5;
  2457. u8 u8tmpa, u8tmpb;
  2458. u32 u32tmp;
  2459. if (btcoexist->manual_control ||
  2460. btcoexist->stop_coex_dm)
  2461. return;
  2462. if (BTC_SCAN_START == type) {
  2463. coex_sta->wifi_is_high_pri_task = true;
  2464. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2465. "[BTCoex], SCAN START notify\n");
  2466. BTC_TRACE(trace_buf);
  2467. halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  2468. 8); /* Force antenna setup for no scan result issue */
  2469. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948);
  2470. u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
  2471. u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67);
  2472. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2473. "[BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
  2474. u32tmp, u8tmpa, u8tmpb);
  2475. BTC_TRACE(trace_buf);
  2476. } else {
  2477. coex_sta->wifi_is_high_pri_task = false;
  2478. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2479. "[BTCoex], SCAN FINISH notify\n");
  2480. BTC_TRACE(trace_buf);
  2481. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
  2482. &coex_sta->scan_ap_num);
  2483. }
  2484. if (coex_sta->bt_disabled)
  2485. return;
  2486. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2487. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2488. &wifi_connected);
  2489. halbtc8192e1ant_query_bt_info(btcoexist);
  2490. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2491. &wifi_link_status);
  2492. num_of_wifi_link = wifi_link_status >> 16;
  2493. if (num_of_wifi_link >= 2) {
  2494. halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2495. halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2496. bt_ctrl_agg_buf_size, agg_buf_size);
  2497. halbtc8192e1ant_action_wifi_multi_port(btcoexist);
  2498. return;
  2499. }
  2500. if (coex_sta->c2h_bt_inquiry_page) {
  2501. halbtc8192e1ant_action_bt_inquiry(btcoexist);
  2502. return;
  2503. } else if (bt_hs_on) {
  2504. halbtc8192e1ant_action_hs(btcoexist);
  2505. return;
  2506. }
  2507. if (BTC_SCAN_START == type) {
  2508. if (!wifi_connected) /* non-connected scan */
  2509. halbtc8192e1ant_action_wifi_not_connected_scan(
  2510. btcoexist);
  2511. else /* wifi is connected */
  2512. halbtc8192e1ant_action_wifi_connected_scan(btcoexist);
  2513. } else if (BTC_SCAN_FINISH == type) {
  2514. if (!wifi_connected) /* non-connected scan */
  2515. halbtc8192e1ant_action_wifi_not_connected(btcoexist);
  2516. else
  2517. halbtc8192e1ant_action_wifi_connected(btcoexist);
  2518. }
  2519. }
  2520. void ex_halbtc8192e1ant_connect_notify(IN struct btc_coexist *btcoexist,
  2521. IN u8 type)
  2522. {
  2523. boolean wifi_connected = false, bt_hs_on = false;
  2524. u32 wifi_link_status = 0;
  2525. u32 num_of_wifi_link = 0;
  2526. boolean bt_ctrl_agg_buf_size = false;
  2527. u8 agg_buf_size = 5;
  2528. if (btcoexist->manual_control ||
  2529. btcoexist->stop_coex_dm ||
  2530. coex_sta->bt_disabled)
  2531. return;
  2532. if (BTC_ASSOCIATE_START == type) {
  2533. coex_sta->wifi_is_high_pri_task = true;
  2534. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2535. "[BTCoex], CONNECT START notify\n");
  2536. BTC_TRACE(trace_buf);
  2537. coex_dm->arp_cnt = 0;
  2538. } else {
  2539. coex_sta->wifi_is_high_pri_task = false;
  2540. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2541. "[BTCoex], CONNECT FINISH notify\n");
  2542. BTC_TRACE(trace_buf);
  2543. /* coex_dm->arp_cnt = 0; */
  2544. }
  2545. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2546. &wifi_link_status);
  2547. num_of_wifi_link = wifi_link_status >> 16;
  2548. if (num_of_wifi_link >= 2) {
  2549. halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2550. halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2551. bt_ctrl_agg_buf_size, agg_buf_size);
  2552. halbtc8192e1ant_action_wifi_multi_port(btcoexist);
  2553. return;
  2554. }
  2555. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2556. if (coex_sta->c2h_bt_inquiry_page) {
  2557. halbtc8192e1ant_action_bt_inquiry(btcoexist);
  2558. return;
  2559. } else if (bt_hs_on) {
  2560. halbtc8192e1ant_action_hs(btcoexist);
  2561. return;
  2562. }
  2563. if (BTC_ASSOCIATE_START == type)
  2564. halbtc8192e1ant_action_wifi_not_connected_asso_auth(btcoexist);
  2565. else if (BTC_ASSOCIATE_FINISH == type) {
  2566. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2567. &wifi_connected);
  2568. if (!wifi_connected) /* non-connected scan */
  2569. halbtc8192e1ant_action_wifi_not_connected(btcoexist);
  2570. else
  2571. halbtc8192e1ant_action_wifi_connected(btcoexist);
  2572. }
  2573. }
  2574. void ex_halbtc8192e1ant_media_status_notify(IN struct btc_coexist *btcoexist,
  2575. IN u8 type)
  2576. {
  2577. u8 h2c_parameter[3] = {0};
  2578. u32 wifi_bw;
  2579. u8 wifi_central_chnl;
  2580. boolean wifi_under_b_mode = false;
  2581. if (btcoexist->manual_control ||
  2582. btcoexist->stop_coex_dm ||
  2583. coex_sta->bt_disabled)
  2584. return;
  2585. if (BTC_MEDIA_CONNECT == type) {
  2586. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2587. "[BTCoex], MEDIA connect notify\n");
  2588. BTC_TRACE(trace_buf);
  2589. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
  2590. &wifi_under_b_mode);
  2591. /* Set CCK Tx/Rx high Pri except 11b mode */
  2592. if (wifi_under_b_mode) {
  2593. btcoexist->btc_write_1byte(btcoexist, 0x6cd,
  2594. 0x00); /* CCK Tx */
  2595. btcoexist->btc_write_1byte(btcoexist, 0x6cf,
  2596. 0x00); /* CCK Rx */
  2597. } else {
  2598. btcoexist->btc_write_1byte(btcoexist, 0x6cd,
  2599. 0x10); /* CCK Tx */
  2600. btcoexist->btc_write_1byte(btcoexist, 0x6cf,
  2601. 0x10); /* CCK Rx */
  2602. }
  2603. coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
  2604. 0x430);
  2605. coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
  2606. 0x434);
  2607. coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
  2608. btcoexist, 0x42a);
  2609. coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
  2610. btcoexist, 0x456);
  2611. } else {
  2612. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2613. "[BTCoex], MEDIA disconnect notify\n");
  2614. BTC_TRACE(trace_buf);
  2615. coex_dm->arp_cnt = 0;
  2616. btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */
  2617. btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */
  2618. }
  2619. /* only 2.4G we need to inform bt the chnl mask */
  2620. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
  2621. &wifi_central_chnl);
  2622. if ((BTC_MEDIA_CONNECT == type) &&
  2623. (wifi_central_chnl <= 14)) {
  2624. /* h2c_parameter[0] = 0x1; */
  2625. h2c_parameter[0] = 0x0;
  2626. h2c_parameter[1] = wifi_central_chnl;
  2627. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2628. if (BTC_WIFI_BW_HT40 == wifi_bw)
  2629. h2c_parameter[2] = 0x30;
  2630. else
  2631. h2c_parameter[2] = 0x20;
  2632. }
  2633. coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
  2634. coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
  2635. coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
  2636. btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
  2637. }
  2638. void ex_halbtc8192e1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
  2639. IN u8 type)
  2640. {
  2641. boolean bt_hs_on = false;
  2642. u32 wifi_link_status = 0;
  2643. u32 num_of_wifi_link = 0;
  2644. boolean bt_ctrl_agg_buf_size = false;
  2645. u8 agg_buf_size = 5;
  2646. if (btcoexist->manual_control ||
  2647. btcoexist->stop_coex_dm ||
  2648. coex_sta->bt_disabled)
  2649. return;
  2650. if (BTC_PACKET_DHCP == type ||
  2651. BTC_PACKET_EAPOL == type ||
  2652. BTC_PACKET_ARP == type) {
  2653. if (BTC_PACKET_ARP == type) {
  2654. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2655. "[BTCoex], specific Packet ARP notify\n");
  2656. BTC_TRACE(trace_buf);
  2657. coex_dm->arp_cnt++;
  2658. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2659. "[BTCoex], ARP Packet Count = %d\n",
  2660. coex_dm->arp_cnt);
  2661. BTC_TRACE(trace_buf);
  2662. if (coex_dm->arp_cnt >=
  2663. 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecificPacket(btcoexist) */
  2664. coex_sta->wifi_is_high_pri_task = false;
  2665. else
  2666. coex_sta->wifi_is_high_pri_task = true;
  2667. } else {
  2668. coex_sta->wifi_is_high_pri_task = true;
  2669. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2670. "[BTCoex], specific Packet DHCP or EAPOL notify\n");
  2671. BTC_TRACE(trace_buf);
  2672. }
  2673. } else {
  2674. coex_sta->wifi_is_high_pri_task = false;
  2675. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2676. "[BTCoex], specific Packet [Type = %d] notify\n", type);
  2677. BTC_TRACE(trace_buf);
  2678. }
  2679. coex_sta->specific_pkt_period_cnt = 0;
  2680. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2681. &wifi_link_status);
  2682. num_of_wifi_link = wifi_link_status >> 16;
  2683. if (num_of_wifi_link >= 2) {
  2684. halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2685. halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2686. bt_ctrl_agg_buf_size, agg_buf_size);
  2687. halbtc8192e1ant_action_wifi_multi_port(btcoexist);
  2688. return;
  2689. }
  2690. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2691. if (coex_sta->c2h_bt_inquiry_page) {
  2692. halbtc8192e1ant_action_bt_inquiry(btcoexist);
  2693. return;
  2694. } else if (bt_hs_on) {
  2695. halbtc8192e1ant_action_hs(btcoexist);
  2696. return;
  2697. }
  2698. if (BTC_PACKET_DHCP == type ||
  2699. BTC_PACKET_EAPOL == type ||
  2700. ((BTC_PACKET_ARP == type) && (coex_sta->wifi_is_high_pri_task)))
  2701. halbtc8192e1ant_action_wifi_connected_specific_packet(btcoexist);
  2702. }
  2703. void ex_halbtc8192e1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
  2704. IN u8 *tmp_buf, IN u8 length)
  2705. {
  2706. u8 bt_info = 0;
  2707. u8 i, rsp_source = 0;
  2708. boolean wifi_connected = false;
  2709. boolean bt_busy = false;
  2710. coex_sta->c2h_bt_info_req_sent = false;
  2711. rsp_source = tmp_buf[0] & 0xf;
  2712. if (rsp_source >= BT_INFO_SRC_8192E_1ANT_MAX)
  2713. rsp_source = BT_INFO_SRC_8192E_1ANT_WIFI_FW;
  2714. coex_sta->bt_info_c2h_cnt[rsp_source]++;
  2715. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2716. "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
  2717. length);
  2718. BTC_TRACE(trace_buf);
  2719. for (i = 0; i < length; i++) {
  2720. coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
  2721. if (i == 1)
  2722. bt_info = tmp_buf[i];
  2723. if (i == length - 1) {
  2724. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
  2725. tmp_buf[i]);
  2726. BTC_TRACE(trace_buf);
  2727. } else {
  2728. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
  2729. tmp_buf[i]);
  2730. BTC_TRACE(trace_buf);
  2731. }
  2732. }
  2733. if (BT_INFO_SRC_8192E_1ANT_WIFI_FW != rsp_source) {
  2734. coex_sta->bt_retry_cnt = /* [3:0] */
  2735. coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
  2736. if (coex_sta->bt_retry_cnt >= 1)
  2737. coex_sta->pop_event_cnt++;
  2738. if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20)
  2739. coex_sta->c2h_bt_page = true;
  2740. else
  2741. coex_sta->c2h_bt_page = false;
  2742. coex_sta->bt_rssi =
  2743. coex_sta->bt_info_c2h[rsp_source][3] * 2 - 90;
  2744. /* coex_sta->bt_info_c2h[rsp_source][3]*2+10; */
  2745. coex_sta->bt_info_ext =
  2746. coex_sta->bt_info_c2h[rsp_source][4];
  2747. coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2]
  2748. & 0x40);
  2749. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
  2750. &coex_sta->bt_tx_rx_mask);
  2751. if (!coex_sta->bt_tx_rx_mask) {
  2752. /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
  2753. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2754. "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n");
  2755. BTC_TRACE(trace_buf);
  2756. btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
  2757. 0x3c, 0x15);
  2758. }
  2759. /* Here we need to resend some wifi info to BT */
  2760. /* because bt is reset and loss of the info. */
  2761. if (coex_sta->bt_info_ext & BIT(1)) {
  2762. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2763. "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
  2764. BTC_TRACE(trace_buf);
  2765. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2766. &wifi_connected);
  2767. if (wifi_connected)
  2768. ex_halbtc8192e1ant_media_status_notify(
  2769. btcoexist, BTC_MEDIA_CONNECT);
  2770. else
  2771. ex_halbtc8192e1ant_media_status_notify(
  2772. btcoexist, BTC_MEDIA_DISCONNECT);
  2773. }
  2774. if (coex_sta->bt_info_ext & BIT(3)) {
  2775. if (!btcoexist->manual_control &&
  2776. !btcoexist->stop_coex_dm) {
  2777. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2778. "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
  2779. BTC_TRACE(trace_buf);
  2780. halbtc8192e1ant_ignore_wlan_act(btcoexist,
  2781. FORCE_EXEC, false);
  2782. }
  2783. } else {
  2784. /* BT already NOT ignore Wlan active, do nothing here. */
  2785. }
  2786. #if (BT_AUTO_REPORT_ONLY_8192E_1ANT == 0)
  2787. if ((coex_sta->bt_info_ext & BIT(4))) {
  2788. /* BT auto report already enabled, do nothing */
  2789. } else
  2790. halbtc8192e1ant_bt_auto_report(btcoexist, FORCE_EXEC,
  2791. true);
  2792. #endif
  2793. }
  2794. /* check BIT2 first ==> check if bt is under inquiry or page scan */
  2795. if (bt_info & BT_INFO_8192E_1ANT_B_INQ_PAGE)
  2796. coex_sta->c2h_bt_inquiry_page = true;
  2797. else
  2798. coex_sta->c2h_bt_inquiry_page = false;
  2799. /* set link exist status */
  2800. if (!(bt_info & BT_INFO_8192E_1ANT_B_CONNECTION)) {
  2801. coex_sta->bt_link_exist = false;
  2802. coex_sta->pan_exist = false;
  2803. coex_sta->a2dp_exist = false;
  2804. coex_sta->hid_exist = false;
  2805. coex_sta->sco_exist = false;
  2806. } else { /* connection exists */
  2807. coex_sta->bt_link_exist = true;
  2808. if (bt_info & BT_INFO_8192E_1ANT_B_FTP)
  2809. coex_sta->pan_exist = true;
  2810. else
  2811. coex_sta->pan_exist = false;
  2812. if (bt_info & BT_INFO_8192E_1ANT_B_A2DP)
  2813. coex_sta->a2dp_exist = true;
  2814. else
  2815. coex_sta->a2dp_exist = false;
  2816. if (bt_info & BT_INFO_8192E_1ANT_B_HID)
  2817. coex_sta->hid_exist = true;
  2818. else
  2819. coex_sta->hid_exist = false;
  2820. if (bt_info & BT_INFO_8192E_1ANT_B_SCO_ESCO)
  2821. coex_sta->sco_exist = true;
  2822. else
  2823. coex_sta->sco_exist = false;
  2824. }
  2825. halbtc8192e1ant_update_bt_link_info(btcoexist);
  2826. bt_info = bt_info &
  2827. 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */
  2828. if (!(bt_info & BT_INFO_8192E_1ANT_B_CONNECTION)) {
  2829. coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
  2830. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2831. "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
  2832. BTC_TRACE(trace_buf);
  2833. } else if (bt_info ==
  2834. BT_INFO_8192E_1ANT_B_CONNECTION) { /* connection exists but no busy */
  2835. coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE;
  2836. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2837. "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
  2838. BTC_TRACE(trace_buf);
  2839. } else if ((bt_info & BT_INFO_8192E_1ANT_B_SCO_ESCO) ||
  2840. (bt_info & BT_INFO_8192E_1ANT_B_SCO_BUSY)) {
  2841. coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_SCO_BUSY;
  2842. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2843. "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
  2844. BTC_TRACE(trace_buf);
  2845. } else if (bt_info & BT_INFO_8192E_1ANT_B_ACL_BUSY) {
  2846. if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
  2847. coex_dm->auto_tdma_adjust = false;
  2848. coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_ACL_BUSY;
  2849. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2850. "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
  2851. BTC_TRACE(trace_buf);
  2852. } else {
  2853. coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_MAX;
  2854. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2855. "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
  2856. BTC_TRACE(trace_buf);
  2857. }
  2858. if ((BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  2859. (BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  2860. (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
  2861. bt_busy = true;
  2862. else
  2863. bt_busy = false;
  2864. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  2865. halbtc8192e1ant_run_coexist_mechanism(btcoexist);
  2866. }
  2867. void ex_halbtc8192e1ant_rf_status_notify(IN struct btc_coexist *btcoexist,
  2868. IN u8 type)
  2869. {
  2870. u32 u32tmp;
  2871. u8 u8tmpa, u8tmpb, u8tmpc;
  2872. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
  2873. BTC_TRACE(trace_buf);
  2874. if (BTC_RF_ON == type) {
  2875. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2876. "[BTCoex], RF is turned ON!!\n");
  2877. BTC_TRACE(trace_buf);
  2878. btcoexist->stop_coex_dm = false;
  2879. } else if (BTC_RF_OFF == type) {
  2880. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2881. "[BTCoex], RF is turned OFF!!\n");
  2882. BTC_TRACE(trace_buf);
  2883. halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  2884. 0x0, 0x0);
  2885. halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
  2886. halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
  2887. true);
  2888. halbtc8192e1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  2889. btcoexist->stop_coex_dm = true;
  2890. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948);
  2891. u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
  2892. u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67);
  2893. u8tmpc = btcoexist->btc_read_1byte(btcoexist, 0x76e);
  2894. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2895. "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x, 0x76e=0x%x\n",
  2896. u32tmp, u8tmpa, u8tmpb, u8tmpc);
  2897. BTC_TRACE(trace_buf);
  2898. }
  2899. }
  2900. void ex_halbtc8192e1ant_halt_notify(IN struct btc_coexist *btcoexist)
  2901. {
  2902. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
  2903. BTC_TRACE(trace_buf);
  2904. halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  2905. 0x0);
  2906. halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
  2907. halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true);
  2908. halbtc8192e1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  2909. ex_halbtc8192e1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
  2910. btcoexist->stop_coex_dm = true;
  2911. }
  2912. void ex_halbtc8192e1ant_pnp_notify(IN struct btc_coexist *btcoexist,
  2913. IN u8 pnp_state)
  2914. {
  2915. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
  2916. BTC_TRACE(trace_buf);
  2917. if (BTC_WIFI_PNP_SLEEP == pnp_state) {
  2918. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2919. "[BTCoex], Pnp notify to SLEEP\n");
  2920. BTC_TRACE(trace_buf);
  2921. halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  2922. 0x0, 0x0);
  2923. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2924. halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  2925. halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
  2926. true);
  2927. /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */
  2928. /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */
  2929. /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */
  2930. coex_sta->under_ips = false;
  2931. coex_sta->under_lps = false;
  2932. btcoexist->stop_coex_dm = true;
  2933. } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
  2934. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2935. "[BTCoex], Pnp notify to WAKE UP\n");
  2936. BTC_TRACE(trace_buf);
  2937. btcoexist->stop_coex_dm = false;
  2938. halbtc8192e1ant_init_hw_config(btcoexist, false);
  2939. halbtc8192e1ant_init_coex_dm(btcoexist);
  2940. halbtc8192e1ant_query_bt_info(btcoexist);
  2941. }
  2942. }
  2943. void ex_halbtc8192e1ant_coex_dm_reset(IN struct btc_coexist *btcoexist)
  2944. {
  2945. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2946. "[BTCoex], *****************Coex DM Reset*****************\n");
  2947. BTC_TRACE(trace_buf);
  2948. halbtc8192e1ant_init_hw_config(btcoexist, false);
  2949. /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */
  2950. /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x2, 0xfffff, 0x0); */
  2951. halbtc8192e1ant_init_coex_dm(btcoexist);
  2952. }
  2953. void ex_halbtc8192e1ant_periodical(IN struct btc_coexist *btcoexist)
  2954. {
  2955. #if (BT_AUTO_REPORT_ONLY_8192E_1ANT == 0)
  2956. halbtc8192e1ant_query_bt_info(btcoexist);
  2957. halbtc8192e1ant_monitor_bt_enable_disable(btcoexist);
  2958. #else
  2959. halbtc8192e1ant_monitor_bt_ctr(btcoexist);
  2960. halbtc8192e1ant_monitor_wifi_ctr(btcoexist);
  2961. if (halbtc8192e1ant_is_wifi_status_changed(btcoexist) ||
  2962. coex_dm->auto_tdma_adjust)
  2963. halbtc8192e1ant_run_coexist_mechanism(btcoexist);
  2964. coex_sta->specific_pkt_period_cnt++;
  2965. #endif
  2966. }
  2967. void ex_halbtc8192e1ant_dbg_control(IN struct btc_coexist *btcoexist,
  2968. IN u8 op_code, IN u8 op_len, IN u8 *pdata)
  2969. {
  2970. switch (op_code) {
  2971. case BTC_DBG_SET_COEX_NORMAL:
  2972. btcoexist->manual_control = false;
  2973. halbtc8192e1ant_init_coex_dm(btcoexist);
  2974. break;
  2975. case BTC_DBG_SET_COEX_WIFI_ONLY:
  2976. btcoexist->manual_control = true;
  2977. halbtc8192e1ant_power_save_state(btcoexist,
  2978. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  2979. halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  2980. 9);
  2981. break;
  2982. case BTC_DBG_SET_COEX_BT_ONLY:
  2983. /* todo */
  2984. break;
  2985. default:
  2986. break;
  2987. }
  2988. }
  2989. #endif /* #if (RTL8192E_SUPPORT == 1) */
  2990. #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */