halbtc8723b1ant.c 106 KB

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