coex.c 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188
  1. // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
  2. /* Copyright(c) 2018-2019 Realtek Corporation
  3. */
  4. #include "main.h"
  5. #include "coex.h"
  6. #include "fw.h"
  7. #include "ps.h"
  8. #include "debug.h"
  9. #include "reg.h"
  10. #include "phy.h"
  11. static u8 rtw_coex_next_rssi_state(struct rtw_dev *rtwdev, u8 pre_state,
  12. u8 rssi, u8 rssi_thresh)
  13. {
  14. const struct rtw_chip_info *chip = rtwdev->chip;
  15. u8 tol = chip->rssi_tolerance;
  16. u8 next_state;
  17. if (pre_state == COEX_RSSI_STATE_LOW ||
  18. pre_state == COEX_RSSI_STATE_STAY_LOW) {
  19. if (rssi >= (rssi_thresh + tol))
  20. next_state = COEX_RSSI_STATE_HIGH;
  21. else
  22. next_state = COEX_RSSI_STATE_STAY_LOW;
  23. } else {
  24. if (rssi < rssi_thresh)
  25. next_state = COEX_RSSI_STATE_LOW;
  26. else
  27. next_state = COEX_RSSI_STATE_STAY_HIGH;
  28. }
  29. return next_state;
  30. }
  31. static void rtw_coex_limited_tx(struct rtw_dev *rtwdev,
  32. bool tx_limit_en, bool ampdu_limit_en)
  33. {
  34. const struct rtw_chip_info *chip = rtwdev->chip;
  35. struct rtw_coex *coex = &rtwdev->coex;
  36. struct rtw_coex_stat *coex_stat = &coex->stat;
  37. u8 num_of_active_port = 1;
  38. if (!chip->scbd_support)
  39. return;
  40. /* force max tx retry limit = 8 */
  41. if (coex_stat->wl_tx_limit_en == tx_limit_en &&
  42. coex_stat->wl_ampdu_limit_en == ampdu_limit_en)
  43. return;
  44. if (!coex_stat->wl_tx_limit_en) {
  45. coex_stat->darfrc = rtw_read32(rtwdev, REG_DARFRC);
  46. coex_stat->darfrch = rtw_read32(rtwdev, REG_DARFRCH);
  47. coex_stat->retry_limit = rtw_read16(rtwdev, REG_RETRY_LIMIT);
  48. }
  49. if (!coex_stat->wl_ampdu_limit_en)
  50. coex_stat->ampdu_max_time =
  51. rtw_read8(rtwdev, REG_AMPDU_MAX_TIME_V1);
  52. coex_stat->wl_tx_limit_en = tx_limit_en;
  53. coex_stat->wl_ampdu_limit_en = ampdu_limit_en;
  54. if (tx_limit_en) {
  55. /* set BT polluted packet on for tx rate adaptive,
  56. * not including tx retry broken by PTA
  57. */
  58. rtw_write8_set(rtwdev, REG_TX_HANG_CTRL, BIT_EN_GNT_BT_AWAKE);
  59. /* set queue life time to avoid can't reach tx retry limit
  60. * if tx is always broken by GNT_BT
  61. */
  62. if (num_of_active_port <= 1)
  63. rtw_write8_set(rtwdev, REG_LIFETIME_EN, 0xf);
  64. rtw_write16(rtwdev, REG_RETRY_LIMIT, 0x0808);
  65. /* auto rate fallback step within 8 retries */
  66. rtw_write32(rtwdev, REG_DARFRC, 0x1000000);
  67. rtw_write32(rtwdev, REG_DARFRCH, 0x4030201);
  68. } else {
  69. rtw_write8_clr(rtwdev, REG_TX_HANG_CTRL, BIT_EN_GNT_BT_AWAKE);
  70. rtw_write8_clr(rtwdev, REG_LIFETIME_EN, 0xf);
  71. rtw_write16(rtwdev, REG_RETRY_LIMIT, coex_stat->retry_limit);
  72. rtw_write32(rtwdev, REG_DARFRC, coex_stat->darfrc);
  73. rtw_write32(rtwdev, REG_DARFRCH, coex_stat->darfrch);
  74. }
  75. if (ampdu_limit_en)
  76. rtw_write8(rtwdev, REG_AMPDU_MAX_TIME_V1, 0x20);
  77. else
  78. rtw_write8(rtwdev, REG_AMPDU_MAX_TIME_V1,
  79. coex_stat->ampdu_max_time);
  80. }
  81. static void rtw_coex_limited_wl(struct rtw_dev *rtwdev)
  82. {
  83. struct rtw_coex *coex = &rtwdev->coex;
  84. struct rtw_coex_dm *coex_dm = &coex->dm;
  85. bool tx_limit = false;
  86. bool tx_agg_ctrl = false;
  87. if (!coex->under_5g && coex_dm->bt_status != COEX_BTSTATUS_NCON_IDLE) {
  88. tx_limit = true;
  89. tx_agg_ctrl = true;
  90. }
  91. rtw_coex_limited_tx(rtwdev, tx_limit, tx_agg_ctrl);
  92. }
  93. static bool rtw_coex_freerun_check(struct rtw_dev *rtwdev)
  94. {
  95. struct rtw_coex *coex = &rtwdev->coex;
  96. struct rtw_coex_dm *coex_dm = &coex->dm;
  97. struct rtw_coex_stat *coex_stat = &coex->stat;
  98. struct rtw_efuse *efuse = &rtwdev->efuse;
  99. u8 bt_rssi;
  100. u8 ant_distance = 10;
  101. if (coex_stat->bt_disabled)
  102. return false;
  103. if (efuse->share_ant || ant_distance <= 5 || !coex_stat->wl_gl_busy)
  104. return false;
  105. if (ant_distance >= 40 || coex_stat->bt_hid_pair_num >= 2)
  106. return true;
  107. /* ant_distance = 5 ~ 40 */
  108. if (COEX_RSSI_HIGH(coex_dm->wl_rssi_state[1]) &&
  109. COEX_RSSI_HIGH(coex_dm->bt_rssi_state[0]))
  110. return true;
  111. if (coex_stat->wl_tput_dir == COEX_WL_TPUT_TX)
  112. bt_rssi = coex_dm->bt_rssi_state[0];
  113. else
  114. bt_rssi = coex_dm->bt_rssi_state[1];
  115. if (COEX_RSSI_HIGH(coex_dm->wl_rssi_state[3]) &&
  116. COEX_RSSI_HIGH(bt_rssi) &&
  117. coex_stat->cnt_wl[COEX_CNT_WL_SCANAP] <= 5)
  118. return true;
  119. return false;
  120. }
  121. static void rtw_coex_wl_slot_extend(struct rtw_dev *rtwdev, bool enable)
  122. {
  123. struct rtw_coex *coex = &rtwdev->coex;
  124. struct rtw_coex_stat *coex_stat = &coex->stat;
  125. u8 para[6] = {0};
  126. para[0] = COEX_H2C69_WL_LEAKAP;
  127. para[1] = PARA1_H2C69_DIS_5MS;
  128. if (enable)
  129. para[1] = PARA1_H2C69_EN_5MS;
  130. else
  131. coex_stat->cnt_wl[COEX_CNT_WL_5MS_NOEXTEND] = 0;
  132. coex_stat->wl_slot_extend = enable;
  133. rtw_fw_bt_wifi_control(rtwdev, para[0], &para[1]);
  134. }
  135. static void rtw_coex_wl_ccklock_action(struct rtw_dev *rtwdev)
  136. {
  137. struct rtw_coex *coex = &rtwdev->coex;
  138. struct rtw_coex_stat *coex_stat = &coex->stat;
  139. if (coex->manual_control || coex->stop_dm)
  140. return;
  141. if (coex_stat->tdma_timer_base == 3 && coex_stat->wl_slot_extend) {
  142. rtw_dbg(rtwdev, RTW_DBG_COEX,
  143. "[BTCoex], set h2c 0x69 opcode 12 to turn off 5ms WL slot extend!!\n");
  144. rtw_coex_wl_slot_extend(rtwdev, false);
  145. return;
  146. }
  147. if (coex_stat->wl_slot_extend && coex_stat->wl_force_lps_ctrl &&
  148. !coex_stat->wl_cck_lock_ever) {
  149. if (coex_stat->wl_fw_dbg_info[7] <= 5)
  150. coex_stat->cnt_wl[COEX_CNT_WL_5MS_NOEXTEND]++;
  151. else
  152. coex_stat->cnt_wl[COEX_CNT_WL_5MS_NOEXTEND] = 0;
  153. rtw_dbg(rtwdev, RTW_DBG_COEX,
  154. "[BTCoex], 5ms WL slot extend cnt = %d!!\n",
  155. coex_stat->cnt_wl[COEX_CNT_WL_5MS_NOEXTEND]);
  156. if (coex_stat->cnt_wl[COEX_CNT_WL_5MS_NOEXTEND] == 7) {
  157. rtw_dbg(rtwdev, RTW_DBG_COEX,
  158. "[BTCoex], set h2c 0x69 opcode 12 to turn off 5ms WL slot extend!!\n");
  159. rtw_coex_wl_slot_extend(rtwdev, false);
  160. }
  161. } else if (!coex_stat->wl_slot_extend && coex_stat->wl_cck_lock) {
  162. rtw_dbg(rtwdev, RTW_DBG_COEX,
  163. "[BTCoex], set h2c 0x69 opcode 12 to turn on 5ms WL slot extend!!\n");
  164. rtw_coex_wl_slot_extend(rtwdev, true);
  165. }
  166. }
  167. static void rtw_coex_wl_ccklock_detect(struct rtw_dev *rtwdev)
  168. {
  169. struct rtw_coex *coex = &rtwdev->coex;
  170. struct rtw_coex_stat *coex_stat = &coex->stat;
  171. struct rtw_coex_dm *coex_dm = &coex->dm;
  172. bool is_cck_lock_rate = false;
  173. if (coex_stat->wl_coex_mode != COEX_WLINK_2G1PORT &&
  174. coex_stat->wl_coex_mode != COEX_WLINK_2GFREE)
  175. return;
  176. if (coex_dm->bt_status == COEX_BTSTATUS_INQ_PAGE ||
  177. coex_stat->bt_setup_link) {
  178. coex_stat->wl_cck_lock = false;
  179. coex_stat->wl_cck_lock_pre = false;
  180. return;
  181. }
  182. if (coex_stat->wl_rx_rate <= COEX_CCK_2 ||
  183. coex_stat->wl_rts_rx_rate <= COEX_CCK_2)
  184. is_cck_lock_rate = true;
  185. if (coex_stat->wl_connected && coex_stat->wl_gl_busy &&
  186. COEX_RSSI_HIGH(coex_dm->wl_rssi_state[3]) &&
  187. (coex_dm->bt_status == COEX_BTSTATUS_ACL_BUSY ||
  188. coex_dm->bt_status == COEX_BTSTATUS_ACL_SCO_BUSY ||
  189. coex_dm->bt_status == COEX_BTSTATUS_SCO_BUSY)) {
  190. if (is_cck_lock_rate) {
  191. coex_stat->wl_cck_lock = true;
  192. rtw_dbg(rtwdev, RTW_DBG_COEX,
  193. "[BTCoex], cck locking...\n");
  194. } else {
  195. coex_stat->wl_cck_lock = false;
  196. rtw_dbg(rtwdev, RTW_DBG_COEX,
  197. "[BTCoex], cck unlock...\n");
  198. }
  199. } else {
  200. coex_stat->wl_cck_lock = false;
  201. }
  202. /* CCK lock identification */
  203. if (coex_stat->wl_cck_lock && !coex_stat->wl_cck_lock_pre)
  204. ieee80211_queue_delayed_work(rtwdev->hw, &coex->wl_ccklock_work,
  205. 3 * HZ);
  206. coex_stat->wl_cck_lock_pre = coex_stat->wl_cck_lock;
  207. }
  208. static void rtw_coex_wl_noisy_detect(struct rtw_dev *rtwdev)
  209. {
  210. struct rtw_coex *coex = &rtwdev->coex;
  211. struct rtw_coex_stat *coex_stat = &coex->stat;
  212. struct rtw_dm_info *dm_info = &rtwdev->dm_info;
  213. u32 cnt_cck;
  214. bool wl_cck_lock = false;
  215. /* wifi noisy environment identification */
  216. cnt_cck = dm_info->cck_ok_cnt + dm_info->cck_err_cnt;
  217. if (!coex_stat->wl_gl_busy && !wl_cck_lock) {
  218. if (cnt_cck > 250) {
  219. if (coex_stat->cnt_wl[COEX_CNT_WL_NOISY2] < 5)
  220. coex_stat->cnt_wl[COEX_CNT_WL_NOISY2]++;
  221. if (coex_stat->cnt_wl[COEX_CNT_WL_NOISY2] == 5) {
  222. coex_stat->cnt_wl[COEX_CNT_WL_NOISY0] = 0;
  223. coex_stat->cnt_wl[COEX_CNT_WL_NOISY1] = 0;
  224. }
  225. } else if (cnt_cck < 100) {
  226. if (coex_stat->cnt_wl[COEX_CNT_WL_NOISY0] < 5)
  227. coex_stat->cnt_wl[COEX_CNT_WL_NOISY0]++;
  228. if (coex_stat->cnt_wl[COEX_CNT_WL_NOISY0] == 5) {
  229. coex_stat->cnt_wl[COEX_CNT_WL_NOISY1] = 0;
  230. coex_stat->cnt_wl[COEX_CNT_WL_NOISY2] = 0;
  231. }
  232. } else {
  233. if (coex_stat->cnt_wl[COEX_CNT_WL_NOISY1] < 5)
  234. coex_stat->cnt_wl[COEX_CNT_WL_NOISY1]++;
  235. if (coex_stat->cnt_wl[COEX_CNT_WL_NOISY1] == 5) {
  236. coex_stat->cnt_wl[COEX_CNT_WL_NOISY0] = 0;
  237. coex_stat->cnt_wl[COEX_CNT_WL_NOISY2] = 0;
  238. }
  239. }
  240. if (coex_stat->cnt_wl[COEX_CNT_WL_NOISY2] == 5)
  241. coex_stat->wl_noisy_level = 2;
  242. else if (coex_stat->cnt_wl[COEX_CNT_WL_NOISY1] == 5)
  243. coex_stat->wl_noisy_level = 1;
  244. else
  245. coex_stat->wl_noisy_level = 0;
  246. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], wl_noisy_level = %d\n",
  247. coex_stat->wl_noisy_level);
  248. }
  249. }
  250. static void rtw_coex_tdma_timer_base(struct rtw_dev *rtwdev, u8 type)
  251. {
  252. struct rtw_coex *coex = &rtwdev->coex;
  253. struct rtw_coex_stat *coex_stat = &coex->stat;
  254. u8 para[6] = {};
  255. u8 times;
  256. u16 tbtt_interval = coex_stat->wl_beacon_interval;
  257. if (coex_stat->tdma_timer_base == type)
  258. return;
  259. coex_stat->tdma_timer_base = type;
  260. para[0] = COEX_H2C69_TDMA_SLOT;
  261. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], tbtt_interval = %d\n",
  262. tbtt_interval);
  263. if (type == TDMA_TIMER_TYPE_4SLOT && tbtt_interval < 120) {
  264. para[1] = PARA1_H2C69_TDMA_4SLOT; /* 4-slot */
  265. } else if (tbtt_interval < 80 && tbtt_interval > 0) {
  266. times = 100 / tbtt_interval;
  267. if (100 % tbtt_interval != 0)
  268. times++;
  269. para[1] = FIELD_PREP(PARA1_H2C69_TBTT_TIMES, times);
  270. } else if (tbtt_interval >= 180) {
  271. times = tbtt_interval / 100;
  272. if (tbtt_interval % 100 <= 80)
  273. times--;
  274. para[1] = FIELD_PREP(PARA1_H2C69_TBTT_TIMES, times) |
  275. FIELD_PREP(PARA1_H2C69_TBTT_DIV100, 1);
  276. } else {
  277. para[1] = PARA1_H2C69_TDMA_2SLOT;
  278. }
  279. rtw_fw_bt_wifi_control(rtwdev, para[0], &para[1]);
  280. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(): h2c_0x69 = 0x%x\n",
  281. __func__, para[1]);
  282. /* no 5ms_wl_slot_extend for 4-slot mode */
  283. if (coex_stat->tdma_timer_base == 3)
  284. rtw_coex_wl_ccklock_action(rtwdev);
  285. }
  286. static void rtw_coex_set_wl_pri_mask(struct rtw_dev *rtwdev, u8 bitmap,
  287. u8 data)
  288. {
  289. u32 addr;
  290. addr = REG_BT_COEX_TABLE_H + (bitmap / 8);
  291. bitmap = bitmap % 8;
  292. rtw_write8_mask(rtwdev, addr, BIT(bitmap), data);
  293. }
  294. void rtw_coex_write_scbd(struct rtw_dev *rtwdev, u16 bitpos, bool set)
  295. {
  296. const struct rtw_chip_info *chip = rtwdev->chip;
  297. struct rtw_coex *coex = &rtwdev->coex;
  298. struct rtw_coex_stat *coex_stat = &coex->stat;
  299. u16 val = 0x2;
  300. if (!chip->scbd_support)
  301. return;
  302. val |= coex_stat->score_board;
  303. /* for 8822b, scbd[10] is CQDDR on
  304. * for 8822c, scbd[10] is no fix 2M
  305. */
  306. if (!chip->new_scbd10_def && (bitpos & COEX_SCBD_FIX2M)) {
  307. if (set)
  308. val &= ~COEX_SCBD_FIX2M;
  309. else
  310. val |= COEX_SCBD_FIX2M;
  311. } else {
  312. if (set)
  313. val |= bitpos;
  314. else
  315. val &= ~bitpos;
  316. }
  317. if (val != coex_stat->score_board) {
  318. coex_stat->score_board = val;
  319. val |= BIT_BT_INT_EN;
  320. rtw_write16(rtwdev, REG_WIFI_BT_INFO, val);
  321. }
  322. }
  323. EXPORT_SYMBOL(rtw_coex_write_scbd);
  324. static u16 rtw_coex_read_scbd(struct rtw_dev *rtwdev)
  325. {
  326. const struct rtw_chip_info *chip = rtwdev->chip;
  327. if (!chip->scbd_support)
  328. return 0;
  329. return (rtw_read16(rtwdev, REG_WIFI_BT_INFO)) & ~(BIT_BT_INT_EN);
  330. }
  331. static void rtw_coex_check_rfk(struct rtw_dev *rtwdev)
  332. {
  333. const struct rtw_chip_info *chip = rtwdev->chip;
  334. struct rtw_coex *coex = &rtwdev->coex;
  335. struct rtw_coex_stat *coex_stat = &coex->stat;
  336. struct rtw_coex_rfe *coex_rfe = &coex->rfe;
  337. u8 cnt = 0;
  338. u32 wait_cnt;
  339. bool btk, wlk;
  340. if (coex_rfe->wlg_at_btg && chip->scbd_support &&
  341. coex_stat->bt_iqk_state != 0xff) {
  342. rtw_dbg(rtwdev, RTW_DBG_COEX,
  343. "[BTCoex], (Before Ant Setup) Delay by IQK\n");
  344. wait_cnt = COEX_RFK_TIMEOUT / COEX_MIN_DELAY;
  345. do {
  346. /* BT RFK */
  347. btk = !!(rtw_coex_read_scbd(rtwdev) & COEX_SCBD_BT_RFK);
  348. /* WL RFK */
  349. wlk = !!(rtw_read8(rtwdev, REG_ARFR4) & BIT_WL_RFK);
  350. if (!btk && !wlk)
  351. break;
  352. rtw_dbg(rtwdev, RTW_DBG_COEX,
  353. "[BTCoex], (Before Ant Setup) wlk = %d, btk = %d\n",
  354. wlk, btk);
  355. mdelay(COEX_MIN_DELAY);
  356. } while (++cnt < wait_cnt);
  357. if (cnt >= wait_cnt)
  358. coex_stat->bt_iqk_state = 0xff;
  359. }
  360. }
  361. void rtw_coex_query_bt_info(struct rtw_dev *rtwdev)
  362. {
  363. struct rtw_coex *coex = &rtwdev->coex;
  364. struct rtw_coex_stat *coex_stat = &coex->stat;
  365. if (coex_stat->bt_disabled)
  366. return;
  367. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  368. rtw_fw_query_bt_info(rtwdev);
  369. }
  370. static void rtw_coex_gnt_workaround(struct rtw_dev *rtwdev, bool force, u8 mode)
  371. {
  372. rtw_coex_set_gnt_fix(rtwdev);
  373. }
  374. static void rtw_coex_monitor_bt_ctr(struct rtw_dev *rtwdev)
  375. {
  376. struct rtw_coex *coex = &rtwdev->coex;
  377. struct rtw_coex_stat *coex_stat = &coex->stat;
  378. u32 tmp;
  379. tmp = rtw_read32(rtwdev, REG_BT_ACT_STATISTICS);
  380. coex_stat->hi_pri_tx = FIELD_GET(MASKLWORD, tmp);
  381. coex_stat->hi_pri_rx = FIELD_GET(MASKHWORD, tmp);
  382. tmp = rtw_read32(rtwdev, REG_BT_ACT_STATISTICS_1);
  383. coex_stat->lo_pri_tx = FIELD_GET(MASKLWORD, tmp);
  384. coex_stat->lo_pri_rx = FIELD_GET(MASKHWORD, tmp);
  385. rtw_write8(rtwdev, REG_BT_COEX_ENH_INTR_CTRL,
  386. BIT_R_GRANTALL_WLMASK | BIT_STATIS_BT_EN);
  387. rtw_dbg(rtwdev, RTW_DBG_COEX,
  388. "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
  389. coex_stat->hi_pri_rx, coex_stat->hi_pri_tx,
  390. coex_stat->lo_pri_rx, coex_stat->lo_pri_tx);
  391. }
  392. static void rtw_coex_monitor_bt_enable(struct rtw_dev *rtwdev)
  393. {
  394. const struct rtw_chip_info *chip = rtwdev->chip;
  395. struct rtw_coex *coex = &rtwdev->coex;
  396. struct rtw_coex_stat *coex_stat = &coex->stat;
  397. struct rtw_coex_dm *coex_dm = &coex->dm;
  398. bool bt_disabled = false;
  399. bool bt_active = true;
  400. u16 score_board;
  401. if (chip->scbd_support) {
  402. score_board = rtw_coex_read_scbd(rtwdev);
  403. bt_disabled = !(score_board & COEX_SCBD_ONOFF);
  404. } else {
  405. if (coex_stat->hi_pri_tx == 0 && coex_stat->hi_pri_rx == 0 &&
  406. coex_stat->lo_pri_tx == 0 && coex_stat->lo_pri_rx == 0)
  407. bt_active = false;
  408. if (coex_stat->hi_pri_tx == 0xffff && coex_stat->hi_pri_rx == 0xffff &&
  409. coex_stat->lo_pri_tx == 0xffff && coex_stat->lo_pri_rx == 0xffff)
  410. bt_active = false;
  411. if (bt_active) {
  412. coex_stat->bt_disable_cnt = 0;
  413. bt_disabled = false;
  414. } else {
  415. coex_stat->bt_disable_cnt++;
  416. if (coex_stat->bt_disable_cnt >= 10)
  417. bt_disabled = true;
  418. }
  419. }
  420. if (coex_stat->bt_disabled != bt_disabled) {
  421. rtw_dbg(rtwdev, RTW_DBG_COEX,
  422. "[BTCoex], BT state changed (%d) -> (%d)\n",
  423. coex_stat->bt_disabled, bt_disabled);
  424. coex_stat->bt_disabled = bt_disabled;
  425. coex_stat->bt_ble_scan_type = 0;
  426. coex_dm->cur_bt_lna_lvl = 0;
  427. if (!coex_stat->bt_disabled) {
  428. coex_stat->bt_reenable = true;
  429. ieee80211_queue_delayed_work(rtwdev->hw,
  430. &coex->bt_reenable_work,
  431. 15 * HZ);
  432. } else {
  433. coex_stat->bt_mailbox_reply = false;
  434. coex_stat->bt_reenable = false;
  435. }
  436. }
  437. }
  438. static void rtw_coex_update_wl_link_info(struct rtw_dev *rtwdev, u8 reason)
  439. {
  440. const struct rtw_chip_info *chip = rtwdev->chip;
  441. struct rtw_coex *coex = &rtwdev->coex;
  442. struct rtw_coex_stat *coex_stat = &coex->stat;
  443. struct rtw_coex_dm *coex_dm = &coex->dm;
  444. struct rtw_traffic_stats *stats = &rtwdev->stats;
  445. bool is_5G = false;
  446. bool wl_busy = false;
  447. bool scan = false, link = false;
  448. int i;
  449. u8 rssi_state;
  450. u8 rssi_step;
  451. u8 rssi;
  452. scan = test_bit(RTW_FLAG_SCANNING, rtwdev->flags);
  453. coex_stat->wl_connected = !!rtwdev->sta_cnt;
  454. wl_busy = test_bit(RTW_FLAG_BUSY_TRAFFIC, rtwdev->flags);
  455. if (wl_busy != coex_stat->wl_gl_busy) {
  456. if (wl_busy)
  457. coex_stat->wl_gl_busy = true;
  458. else
  459. ieee80211_queue_delayed_work(rtwdev->hw,
  460. &coex->wl_remain_work,
  461. 12 * HZ);
  462. }
  463. if (stats->tx_throughput > stats->rx_throughput)
  464. coex_stat->wl_tput_dir = COEX_WL_TPUT_TX;
  465. else
  466. coex_stat->wl_tput_dir = COEX_WL_TPUT_RX;
  467. if (scan || link || reason == COEX_RSN_2GCONSTART ||
  468. reason == COEX_RSN_2GSCANSTART || reason == COEX_RSN_2GSWITCHBAND)
  469. coex_stat->wl_linkscan_proc = true;
  470. else
  471. coex_stat->wl_linkscan_proc = false;
  472. rtw_coex_wl_noisy_detect(rtwdev);
  473. for (i = 0; i < 4; i++) {
  474. rssi_state = coex_dm->wl_rssi_state[i];
  475. rssi_step = chip->wl_rssi_step[i];
  476. rssi = rtwdev->dm_info.min_rssi;
  477. rssi_state = rtw_coex_next_rssi_state(rtwdev, rssi_state,
  478. rssi, rssi_step);
  479. coex_dm->wl_rssi_state[i] = rssi_state;
  480. }
  481. if (coex_stat->wl_linkscan_proc || coex_stat->wl_hi_pri_task1 ||
  482. coex_stat->wl_hi_pri_task2 || coex_stat->wl_gl_busy)
  483. rtw_coex_write_scbd(rtwdev, COEX_SCBD_SCAN, true);
  484. else
  485. rtw_coex_write_scbd(rtwdev, COEX_SCBD_SCAN, false);
  486. switch (reason) {
  487. case COEX_RSN_5GSCANSTART:
  488. case COEX_RSN_5GSWITCHBAND:
  489. case COEX_RSN_5GCONSTART:
  490. is_5G = true;
  491. break;
  492. case COEX_RSN_2GSCANSTART:
  493. case COEX_RSN_2GSWITCHBAND:
  494. case COEX_RSN_2GCONSTART:
  495. is_5G = false;
  496. break;
  497. default:
  498. if (rtwdev->hal.current_band_type == RTW_BAND_5G)
  499. is_5G = true;
  500. else
  501. is_5G = false;
  502. break;
  503. }
  504. coex->under_5g = is_5G;
  505. }
  506. static inline u8 *get_payload_from_coex_resp(struct sk_buff *resp)
  507. {
  508. struct rtw_c2h_cmd *c2h;
  509. u32 pkt_offset;
  510. pkt_offset = *((u32 *)resp->cb);
  511. c2h = (struct rtw_c2h_cmd *)(resp->data + pkt_offset);
  512. return c2h->payload;
  513. }
  514. void rtw_coex_info_response(struct rtw_dev *rtwdev, struct sk_buff *skb)
  515. {
  516. struct rtw_coex *coex = &rtwdev->coex;
  517. u8 *payload = get_payload_from_coex_resp(skb);
  518. if (payload[0] != COEX_RESP_ACK_BY_WL_FW) {
  519. dev_kfree_skb_any(skb);
  520. return;
  521. }
  522. skb_queue_tail(&coex->queue, skb);
  523. wake_up(&coex->wait);
  524. }
  525. static struct sk_buff *rtw_coex_info_request(struct rtw_dev *rtwdev,
  526. struct rtw_coex_info_req *req)
  527. {
  528. struct rtw_coex *coex = &rtwdev->coex;
  529. struct sk_buff *skb_resp = NULL;
  530. lockdep_assert_held(&rtwdev->mutex);
  531. rtw_fw_query_bt_mp_info(rtwdev, req);
  532. if (!wait_event_timeout(coex->wait, !skb_queue_empty(&coex->queue),
  533. COEX_REQUEST_TIMEOUT)) {
  534. rtw_err(rtwdev, "coex request time out\n");
  535. goto out;
  536. }
  537. skb_resp = skb_dequeue(&coex->queue);
  538. if (!skb_resp) {
  539. rtw_err(rtwdev, "failed to get coex info response\n");
  540. goto out;
  541. }
  542. out:
  543. return skb_resp;
  544. }
  545. static bool rtw_coex_get_bt_scan_type(struct rtw_dev *rtwdev, u8 *scan_type)
  546. {
  547. struct rtw_coex_info_req req = {0};
  548. struct sk_buff *skb;
  549. u8 *payload;
  550. req.op_code = BT_MP_INFO_OP_SCAN_TYPE;
  551. skb = rtw_coex_info_request(rtwdev, &req);
  552. if (!skb)
  553. return false;
  554. payload = get_payload_from_coex_resp(skb);
  555. *scan_type = GET_COEX_RESP_BT_SCAN_TYPE(payload);
  556. dev_kfree_skb_any(skb);
  557. return true;
  558. }
  559. static bool rtw_coex_set_lna_constrain_level(struct rtw_dev *rtwdev,
  560. u8 lna_constrain_level)
  561. {
  562. struct rtw_coex_info_req req = {0};
  563. struct sk_buff *skb;
  564. req.op_code = BT_MP_INFO_OP_LNA_CONSTRAINT;
  565. req.para1 = lna_constrain_level;
  566. skb = rtw_coex_info_request(rtwdev, &req);
  567. if (!skb)
  568. return false;
  569. dev_kfree_skb_any(skb);
  570. return true;
  571. }
  572. #define case_BTSTATUS(src) \
  573. case COEX_BTSTATUS_##src: return #src
  574. static const char *rtw_coex_get_bt_status_string(u8 bt_status)
  575. {
  576. switch (bt_status) {
  577. case_BTSTATUS(NCON_IDLE);
  578. case_BTSTATUS(CON_IDLE);
  579. case_BTSTATUS(INQ_PAGE);
  580. case_BTSTATUS(ACL_BUSY);
  581. case_BTSTATUS(SCO_BUSY);
  582. case_BTSTATUS(ACL_SCO_BUSY);
  583. default:
  584. return "Unknown";
  585. }
  586. }
  587. static void rtw_coex_update_bt_link_info(struct rtw_dev *rtwdev)
  588. {
  589. const struct rtw_chip_info *chip = rtwdev->chip;
  590. struct rtw_coex *coex = &rtwdev->coex;
  591. struct rtw_coex_stat *coex_stat = &coex->stat;
  592. struct rtw_coex_dm *coex_dm = &coex->dm;
  593. u8 i;
  594. u8 rssi_state;
  595. u8 rssi_step;
  596. u8 rssi;
  597. /* update wl/bt rssi by btinfo */
  598. for (i = 0; i < COEX_RSSI_STEP; i++) {
  599. rssi_state = coex_dm->bt_rssi_state[i];
  600. rssi_step = chip->bt_rssi_step[i];
  601. rssi = coex_stat->bt_rssi;
  602. rssi_state = rtw_coex_next_rssi_state(rtwdev, rssi_state, rssi,
  603. rssi_step);
  604. coex_dm->bt_rssi_state[i] = rssi_state;
  605. }
  606. if (coex_stat->bt_ble_scan_en &&
  607. coex_stat->cnt_bt[COEX_CNT_BT_INFOUPDATE] % 3 == 0) {
  608. u8 scan_type;
  609. if (rtw_coex_get_bt_scan_type(rtwdev, &scan_type)) {
  610. coex_stat->bt_ble_scan_type = scan_type;
  611. if ((coex_stat->bt_ble_scan_type & 0x1) == 0x1)
  612. coex_stat->bt_init_scan = true;
  613. else
  614. coex_stat->bt_init_scan = false;
  615. }
  616. }
  617. coex_stat->bt_profile_num = 0;
  618. /* set link exist status */
  619. if (!(coex_stat->bt_info_lb2 & COEX_INFO_CONNECTION)) {
  620. coex_stat->bt_link_exist = false;
  621. coex_stat->bt_pan_exist = false;
  622. coex_stat->bt_a2dp_exist = false;
  623. coex_stat->bt_hid_exist = false;
  624. coex_stat->bt_hfp_exist = false;
  625. } else {
  626. /* connection exists */
  627. coex_stat->bt_link_exist = true;
  628. if (coex_stat->bt_info_lb2 & COEX_INFO_FTP) {
  629. coex_stat->bt_pan_exist = true;
  630. coex_stat->bt_profile_num++;
  631. } else {
  632. coex_stat->bt_pan_exist = false;
  633. }
  634. if (coex_stat->bt_info_lb2 & COEX_INFO_A2DP) {
  635. coex_stat->bt_a2dp_exist = true;
  636. coex_stat->bt_profile_num++;
  637. } else {
  638. coex_stat->bt_a2dp_exist = false;
  639. }
  640. if (coex_stat->bt_info_lb2 & COEX_INFO_HID) {
  641. coex_stat->bt_hid_exist = true;
  642. coex_stat->bt_profile_num++;
  643. } else {
  644. coex_stat->bt_hid_exist = false;
  645. }
  646. if (coex_stat->bt_info_lb2 & COEX_INFO_SCO_ESCO) {
  647. coex_stat->bt_hfp_exist = true;
  648. coex_stat->bt_profile_num++;
  649. } else {
  650. coex_stat->bt_hfp_exist = false;
  651. }
  652. }
  653. if (coex_stat->bt_info_lb2 & COEX_INFO_INQ_PAGE) {
  654. coex_dm->bt_status = COEX_BTSTATUS_INQ_PAGE;
  655. } else if (!(coex_stat->bt_info_lb2 & COEX_INFO_CONNECTION)) {
  656. coex_dm->bt_status = COEX_BTSTATUS_NCON_IDLE;
  657. coex_stat->bt_multi_link_remain = false;
  658. } else if (coex_stat->bt_info_lb2 == COEX_INFO_CONNECTION) {
  659. coex_dm->bt_status = COEX_BTSTATUS_CON_IDLE;
  660. } else if ((coex_stat->bt_info_lb2 & COEX_INFO_SCO_ESCO) ||
  661. (coex_stat->bt_info_lb2 & COEX_INFO_SCO_BUSY)) {
  662. if (coex_stat->bt_info_lb2 & COEX_INFO_ACL_BUSY)
  663. coex_dm->bt_status = COEX_BTSTATUS_ACL_SCO_BUSY;
  664. else
  665. coex_dm->bt_status = COEX_BTSTATUS_SCO_BUSY;
  666. } else if (coex_stat->bt_info_lb2 & COEX_INFO_ACL_BUSY) {
  667. coex_dm->bt_status = COEX_BTSTATUS_ACL_BUSY;
  668. } else {
  669. coex_dm->bt_status = COEX_BTSTATUS_MAX;
  670. }
  671. coex_stat->cnt_bt[COEX_CNT_BT_INFOUPDATE]++;
  672. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(), %s!!!\n", __func__,
  673. rtw_coex_get_bt_status_string(coex_dm->bt_status));
  674. }
  675. static void rtw_coex_update_wl_ch_info(struct rtw_dev *rtwdev, u8 type)
  676. {
  677. const struct rtw_chip_info *chip = rtwdev->chip;
  678. struct rtw_efuse *efuse = &rtwdev->efuse;
  679. struct rtw_coex_dm *coex_dm = &rtwdev->coex.dm;
  680. struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
  681. u8 link = 0;
  682. u8 center_chan = 0;
  683. u8 bw;
  684. int i;
  685. bw = rtwdev->hal.current_band_width;
  686. if (type != COEX_MEDIA_DISCONNECT)
  687. center_chan = rtwdev->hal.current_channel;
  688. if (center_chan == 0 ||
  689. (efuse->share_ant && center_chan <= 14 &&
  690. coex_stat->wl_coex_mode != COEX_WLINK_2GFREE)) {
  691. link = 0;
  692. center_chan = 0;
  693. bw = 0;
  694. } else if (center_chan <= 14) {
  695. link = 0x1;
  696. if (bw == RTW_CHANNEL_WIDTH_40)
  697. bw = chip->bt_afh_span_bw40;
  698. else
  699. bw = chip->bt_afh_span_bw20;
  700. } else if (chip->afh_5g_num > 1) {
  701. for (i = 0; i < chip->afh_5g_num; i++) {
  702. if (center_chan == chip->afh_5g[i].wl_5g_ch) {
  703. link = 0x3;
  704. center_chan = chip->afh_5g[i].bt_skip_ch;
  705. bw = chip->afh_5g[i].bt_skip_span;
  706. break;
  707. }
  708. }
  709. }
  710. coex_dm->wl_ch_info[0] = link;
  711. coex_dm->wl_ch_info[1] = center_chan;
  712. coex_dm->wl_ch_info[2] = bw;
  713. rtw_fw_wl_ch_info(rtwdev, link, center_chan, bw);
  714. rtw_dbg(rtwdev, RTW_DBG_COEX,
  715. "[BTCoex], %s: para[0:2] = 0x%x 0x%x 0x%x\n", __func__, link,
  716. center_chan, bw);
  717. }
  718. static void rtw_coex_set_bt_tx_power(struct rtw_dev *rtwdev, u8 bt_pwr_dec_lvl)
  719. {
  720. struct rtw_coex *coex = &rtwdev->coex;
  721. struct rtw_coex_dm *coex_dm = &coex->dm;
  722. if (bt_pwr_dec_lvl == coex_dm->cur_bt_pwr_lvl)
  723. return;
  724. coex_dm->cur_bt_pwr_lvl = bt_pwr_dec_lvl;
  725. rtw_fw_force_bt_tx_power(rtwdev, bt_pwr_dec_lvl);
  726. }
  727. static void rtw_coex_set_bt_rx_gain(struct rtw_dev *rtwdev, u8 bt_lna_lvl)
  728. {
  729. struct rtw_coex *coex = &rtwdev->coex;
  730. struct rtw_coex_dm *coex_dm = &coex->dm;
  731. if (bt_lna_lvl == coex_dm->cur_bt_lna_lvl)
  732. return;
  733. coex_dm->cur_bt_lna_lvl = bt_lna_lvl;
  734. /* notify BT rx gain table changed */
  735. if (bt_lna_lvl < 7) {
  736. rtw_coex_set_lna_constrain_level(rtwdev, bt_lna_lvl);
  737. rtw_coex_write_scbd(rtwdev, COEX_SCBD_RXGAIN, true);
  738. } else {
  739. rtw_coex_write_scbd(rtwdev, COEX_SCBD_RXGAIN, false);
  740. }
  741. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(): bt_rx_LNA_level = %d\n",
  742. __func__, bt_lna_lvl);
  743. }
  744. static void rtw_coex_set_rf_para(struct rtw_dev *rtwdev,
  745. struct coex_rf_para para)
  746. {
  747. struct rtw_coex *coex = &rtwdev->coex;
  748. struct rtw_coex_stat *coex_stat = &coex->stat;
  749. u8 offset = 0;
  750. if (coex->freerun && coex_stat->cnt_wl[COEX_CNT_WL_SCANAP] <= 5)
  751. offset = 3;
  752. rtw_coex_set_wl_tx_power(rtwdev, para.wl_pwr_dec_lvl);
  753. rtw_coex_set_bt_tx_power(rtwdev, para.bt_pwr_dec_lvl + offset);
  754. rtw_coex_set_wl_rx_gain(rtwdev, para.wl_low_gain_en);
  755. rtw_coex_set_bt_rx_gain(rtwdev, para.bt_lna_lvl);
  756. }
  757. u32 rtw_coex_read_indirect_reg(struct rtw_dev *rtwdev, u16 addr)
  758. {
  759. u32 val;
  760. if (!ltecoex_read_reg(rtwdev, addr, &val)) {
  761. rtw_err(rtwdev, "failed to read indirect register\n");
  762. return 0;
  763. }
  764. return val;
  765. }
  766. EXPORT_SYMBOL(rtw_coex_read_indirect_reg);
  767. void rtw_coex_write_indirect_reg(struct rtw_dev *rtwdev, u16 addr,
  768. u32 mask, u32 val)
  769. {
  770. u32 shift = __ffs(mask);
  771. u32 tmp;
  772. tmp = rtw_coex_read_indirect_reg(rtwdev, addr);
  773. tmp = (tmp & (~mask)) | ((val << shift) & mask);
  774. if (!ltecoex_reg_write(rtwdev, addr, tmp))
  775. rtw_err(rtwdev, "failed to write indirect register\n");
  776. }
  777. EXPORT_SYMBOL(rtw_coex_write_indirect_reg);
  778. static void rtw_coex_coex_ctrl_owner(struct rtw_dev *rtwdev, bool wifi_control)
  779. {
  780. const struct rtw_chip_info *chip = rtwdev->chip;
  781. const struct rtw_hw_reg *btg_reg = chip->btg_reg;
  782. if (wifi_control) {
  783. rtw_write8_set(rtwdev, REG_SYS_SDIO_CTRL + 3,
  784. BIT_LTE_MUX_CTRL_PATH >> 24);
  785. if (btg_reg)
  786. rtw_write8_set(rtwdev, btg_reg->addr, btg_reg->mask);
  787. } else {
  788. rtw_write8_clr(rtwdev, REG_SYS_SDIO_CTRL + 3,
  789. BIT_LTE_MUX_CTRL_PATH >> 24);
  790. if (btg_reg)
  791. rtw_write8_clr(rtwdev, btg_reg->addr, btg_reg->mask);
  792. }
  793. }
  794. static void rtw_coex_set_gnt_bt(struct rtw_dev *rtwdev, u8 state)
  795. {
  796. if (!rtwdev->chip->ltecoex_addr)
  797. return;
  798. rtw_coex_write_indirect_reg(rtwdev, LTE_COEX_CTRL, 0xc000, state);
  799. rtw_coex_write_indirect_reg(rtwdev, LTE_COEX_CTRL, 0x0c00, state);
  800. }
  801. static void rtw_coex_set_gnt_wl(struct rtw_dev *rtwdev, u8 state)
  802. {
  803. if (!rtwdev->chip->ltecoex_addr)
  804. return;
  805. rtw_coex_write_indirect_reg(rtwdev, LTE_COEX_CTRL, 0x3000, state);
  806. rtw_coex_write_indirect_reg(rtwdev, LTE_COEX_CTRL, 0x0300, state);
  807. }
  808. static void rtw_coex_mimo_ps(struct rtw_dev *rtwdev, bool force, bool state)
  809. {
  810. struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
  811. if (!force && state == coex_stat->wl_mimo_ps)
  812. return;
  813. coex_stat->wl_mimo_ps = state;
  814. rtw_set_txrx_1ss(rtwdev, state);
  815. rtw_coex_update_wl_ch_info(rtwdev, (u8)coex_stat->wl_connected);
  816. rtw_dbg(rtwdev, RTW_DBG_COEX,
  817. "[BTCoex], %s(): state = %d\n", __func__, state);
  818. }
  819. static void rtw_btc_wltoggle_table_a(struct rtw_dev *rtwdev, bool force,
  820. u8 table_case)
  821. {
  822. const struct rtw_chip_info *chip = rtwdev->chip;
  823. struct rtw_efuse *efuse = &rtwdev->efuse;
  824. u8 h2c_para[6] = {0};
  825. u32 table_wl = 0x5a5a5a5a;
  826. h2c_para[0] = COEX_H2C69_TOGGLE_TABLE_A;
  827. /* no definition */
  828. h2c_para[1] = 0x1;
  829. if (efuse->share_ant) {
  830. if (table_case < chip->table_sant_num)
  831. table_wl = chip->table_sant[table_case].wl;
  832. } else {
  833. if (table_case < chip->table_nsant_num)
  834. table_wl = chip->table_nsant[table_case].wl;
  835. }
  836. /* tell WL FW WL slot toggle table-A*/
  837. h2c_para[2] = (u8)u32_get_bits(table_wl, GENMASK(7, 0));
  838. h2c_para[3] = (u8)u32_get_bits(table_wl, GENMASK(15, 8));
  839. h2c_para[4] = (u8)u32_get_bits(table_wl, GENMASK(23, 16));
  840. h2c_para[5] = (u8)u32_get_bits(table_wl, GENMASK(31, 24));
  841. rtw_fw_bt_wifi_control(rtwdev, h2c_para[0], &h2c_para[1]);
  842. rtw_dbg(rtwdev, RTW_DBG_COEX,
  843. "[BTCoex], %s(): H2C = [%02x %02x %02x %02x %02x %02x]\n",
  844. __func__, h2c_para[0], h2c_para[1], h2c_para[2],
  845. h2c_para[3], h2c_para[4], h2c_para[5]);
  846. }
  847. #define COEX_WL_SLOT_TOGLLE 0x5a5a5aaa
  848. static void rtw_btc_wltoggle_table_b(struct rtw_dev *rtwdev, bool force,
  849. u8 interval, u32 table)
  850. {
  851. struct rtw_coex *coex = &rtwdev->coex;
  852. struct rtw_coex_stat *coex_stat = &coex->stat;
  853. u8 cur_h2c_para[6] = {0};
  854. u8 i;
  855. cur_h2c_para[0] = COEX_H2C69_TOGGLE_TABLE_B;
  856. cur_h2c_para[1] = interval;
  857. cur_h2c_para[2] = (u8)u32_get_bits(table, GENMASK(7, 0));
  858. cur_h2c_para[3] = (u8)u32_get_bits(table, GENMASK(15, 8));
  859. cur_h2c_para[4] = (u8)u32_get_bits(table, GENMASK(23, 16));
  860. cur_h2c_para[5] = (u8)u32_get_bits(table, GENMASK(31, 24));
  861. coex_stat->wl_toggle_interval = interval;
  862. for (i = 0; i <= 5; i++)
  863. coex_stat->wl_toggle_para[i] = cur_h2c_para[i];
  864. rtw_fw_bt_wifi_control(rtwdev, cur_h2c_para[0], &cur_h2c_para[1]);
  865. rtw_dbg(rtwdev, RTW_DBG_COEX,
  866. "[BTCoex], %s(): H2C = [%02x %02x %02x %02x %02x %02x]\n",
  867. __func__, cur_h2c_para[0], cur_h2c_para[1], cur_h2c_para[2],
  868. cur_h2c_para[3], cur_h2c_para[4], cur_h2c_para[5]);
  869. }
  870. static void rtw_coex_set_table(struct rtw_dev *rtwdev, bool force, u32 table0,
  871. u32 table1)
  872. {
  873. #define DEF_BRK_TABLE_VAL 0xf0ffffff
  874. struct rtw_coex *coex = &rtwdev->coex;
  875. struct rtw_coex_dm *coex_dm = &coex->dm;
  876. /* If last tdma is wl slot toggle, force write table*/
  877. if (!force && coex_dm->reason != COEX_RSN_LPS) {
  878. if (table0 == rtw_read32(rtwdev, REG_BT_COEX_TABLE0) &&
  879. table1 == rtw_read32(rtwdev, REG_BT_COEX_TABLE1))
  880. return;
  881. }
  882. rtw_write32(rtwdev, REG_BT_COEX_TABLE0, table0);
  883. rtw_write32(rtwdev, REG_BT_COEX_TABLE1, table1);
  884. rtw_write32(rtwdev, REG_BT_COEX_BRK_TABLE, DEF_BRK_TABLE_VAL);
  885. rtw_dbg(rtwdev, RTW_DBG_COEX,
  886. "[BTCoex], %s(): 0x6c0 = %x, 0x6c4 = %x\n", __func__, table0,
  887. table1);
  888. }
  889. static void rtw_coex_table(struct rtw_dev *rtwdev, bool force, u8 type)
  890. {
  891. const struct rtw_chip_info *chip = rtwdev->chip;
  892. struct rtw_coex *coex = &rtwdev->coex;
  893. struct rtw_coex_dm *coex_dm = &coex->dm;
  894. struct rtw_efuse *efuse = &rtwdev->efuse;
  895. struct rtw_coex_stat *coex_stat = &coex->stat;
  896. coex_dm->cur_table = type;
  897. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], Coex_Table - %d\n", type);
  898. if (efuse->share_ant) {
  899. if (type < chip->table_sant_num)
  900. rtw_coex_set_table(rtwdev, force,
  901. chip->table_sant[type].bt,
  902. chip->table_sant[type].wl);
  903. } else {
  904. type = type - 100;
  905. if (type < chip->table_nsant_num)
  906. rtw_coex_set_table(rtwdev, force,
  907. chip->table_nsant[type].bt,
  908. chip->table_nsant[type].wl);
  909. }
  910. if (coex_stat->wl_slot_toggle_change)
  911. rtw_btc_wltoggle_table_a(rtwdev, true, type);
  912. }
  913. static void rtw_coex_ignore_wlan_act(struct rtw_dev *rtwdev, bool enable)
  914. {
  915. struct rtw_coex *coex = &rtwdev->coex;
  916. if (coex->manual_control || coex->stop_dm)
  917. return;
  918. rtw_fw_bt_ignore_wlan_action(rtwdev, enable);
  919. }
  920. static void rtw_coex_power_save_state(struct rtw_dev *rtwdev, u8 ps_type,
  921. u8 lps_val, u8 rpwm_val)
  922. {
  923. struct rtw_coex *coex = &rtwdev->coex;
  924. struct rtw_coex_stat *coex_stat = &coex->stat;
  925. u8 lps_mode = 0x0;
  926. lps_mode = rtwdev->lps_conf.mode;
  927. switch (ps_type) {
  928. case COEX_PS_WIFI_NATIVE:
  929. /* recover to original 32k low power setting */
  930. coex_stat->wl_force_lps_ctrl = false;
  931. rtw_dbg(rtwdev, RTW_DBG_COEX,
  932. "[BTCoex], %s(): COEX_PS_WIFI_NATIVE\n", __func__);
  933. rtw_leave_lps(rtwdev);
  934. break;
  935. case COEX_PS_LPS_OFF:
  936. coex_stat->wl_force_lps_ctrl = true;
  937. if (lps_mode)
  938. rtw_fw_coex_tdma_type(rtwdev, 0, 0, 0, 0, 0);
  939. rtw_leave_lps(rtwdev);
  940. rtw_dbg(rtwdev, RTW_DBG_COEX,
  941. "[BTCoex], %s(): COEX_PS_LPS_OFF\n", __func__);
  942. break;
  943. default:
  944. break;
  945. }
  946. }
  947. static void rtw_coex_set_tdma(struct rtw_dev *rtwdev, u8 byte1, u8 byte2,
  948. u8 byte3, u8 byte4, u8 byte5)
  949. {
  950. const struct rtw_chip_info *chip = rtwdev->chip;
  951. struct rtw_coex *coex = &rtwdev->coex;
  952. struct rtw_coex_dm *coex_dm = &coex->dm;
  953. struct rtw_coex_stat *coex_stat = &coex->stat;
  954. u8 ps_type = COEX_PS_WIFI_NATIVE;
  955. bool ap_enable = false;
  956. if (ap_enable && (byte1 & BIT(4) && !(byte1 & BIT(5)))) {
  957. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(): AP mode\n",
  958. __func__);
  959. byte1 &= ~BIT(4);
  960. byte1 |= BIT(5);
  961. byte5 |= BIT(5);
  962. byte5 &= ~BIT(6);
  963. ps_type = COEX_PS_WIFI_NATIVE;
  964. rtw_coex_power_save_state(rtwdev, ps_type, 0x0, 0x0);
  965. } else if ((byte1 & BIT(4) && !(byte1 & BIT(5))) ||
  966. coex_stat->wl_coex_mode == COEX_WLINK_2GFREE) {
  967. rtw_dbg(rtwdev, RTW_DBG_COEX,
  968. "[BTCoex], %s(): Force LPS (byte1 = 0x%x)\n", __func__,
  969. byte1);
  970. if (chip->pstdma_type == COEX_PSTDMA_FORCE_LPSOFF)
  971. ps_type = COEX_PS_LPS_OFF;
  972. else
  973. ps_type = COEX_PS_LPS_ON;
  974. rtw_coex_power_save_state(rtwdev, ps_type, 0x50, 0x4);
  975. } else {
  976. rtw_dbg(rtwdev, RTW_DBG_COEX,
  977. "[BTCoex], %s(): native power save (byte1 = 0x%x)\n",
  978. __func__, byte1);
  979. ps_type = COEX_PS_WIFI_NATIVE;
  980. rtw_coex_power_save_state(rtwdev, ps_type, 0x0, 0x0);
  981. }
  982. coex_dm->ps_tdma_para[0] = byte1;
  983. coex_dm->ps_tdma_para[1] = byte2;
  984. coex_dm->ps_tdma_para[2] = byte3;
  985. coex_dm->ps_tdma_para[3] = byte4;
  986. coex_dm->ps_tdma_para[4] = byte5;
  987. rtw_fw_coex_tdma_type(rtwdev, byte1, byte2, byte3, byte4, byte5);
  988. if (byte1 & BIT(2)) {
  989. coex_stat->wl_slot_toggle = true;
  990. coex_stat->wl_slot_toggle_change = false;
  991. } else {
  992. coex_stat->wl_slot_toggle_change = coex_stat->wl_slot_toggle;
  993. coex_stat->wl_slot_toggle = false;
  994. }
  995. }
  996. static void rtw_coex_tdma(struct rtw_dev *rtwdev, bool force, u32 tcase)
  997. {
  998. const struct rtw_chip_info *chip = rtwdev->chip;
  999. struct rtw_coex *coex = &rtwdev->coex;
  1000. struct rtw_coex_dm *coex_dm = &coex->dm;
  1001. struct rtw_coex_stat *coex_stat = &coex->stat;
  1002. struct rtw_efuse *efuse = &rtwdev->efuse;
  1003. u8 n, type;
  1004. bool turn_on;
  1005. bool wl_busy = false;
  1006. if (tcase & TDMA_4SLOT) /* 4-slot (50ms) mode */
  1007. rtw_coex_tdma_timer_base(rtwdev, TDMA_TIMER_TYPE_4SLOT);
  1008. else
  1009. rtw_coex_tdma_timer_base(rtwdev, TDMA_TIMER_TYPE_2SLOT);
  1010. type = (u8)(tcase & 0xff);
  1011. turn_on = (type == 0 || type == 100) ? false : true;
  1012. if (!force && turn_on == coex_dm->cur_ps_tdma_on &&
  1013. type == coex_dm->cur_ps_tdma) {
  1014. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1015. "[BTCoex], Skip TDMA because no change TDMA(%s, %d)\n",
  1016. (coex_dm->cur_ps_tdma_on ? "on" : "off"),
  1017. coex_dm->cur_ps_tdma);
  1018. return;
  1019. }
  1020. wl_busy = test_bit(RTW_FLAG_BUSY_TRAFFIC, rtwdev->flags);
  1021. if ((coex_stat->bt_a2dp_exist &&
  1022. (coex_stat->bt_inq_remain || coex_stat->bt_multi_link)) ||
  1023. !wl_busy)
  1024. rtw_coex_write_scbd(rtwdev, COEX_SCBD_TDMA, false);
  1025. else
  1026. rtw_coex_write_scbd(rtwdev, COEX_SCBD_TDMA, true);
  1027. /* update pre state */
  1028. coex_dm->cur_ps_tdma_on = turn_on;
  1029. coex_dm->cur_ps_tdma = type;
  1030. if (efuse->share_ant) {
  1031. if (type < chip->tdma_sant_num)
  1032. rtw_coex_set_tdma(rtwdev,
  1033. chip->tdma_sant[type].para[0],
  1034. chip->tdma_sant[type].para[1],
  1035. chip->tdma_sant[type].para[2],
  1036. chip->tdma_sant[type].para[3],
  1037. chip->tdma_sant[type].para[4]);
  1038. } else {
  1039. n = type - 100;
  1040. if (n < chip->tdma_nsant_num)
  1041. rtw_coex_set_tdma(rtwdev,
  1042. chip->tdma_nsant[n].para[0],
  1043. chip->tdma_nsant[n].para[1],
  1044. chip->tdma_nsant[n].para[2],
  1045. chip->tdma_nsant[n].para[3],
  1046. chip->tdma_nsant[n].para[4]);
  1047. }
  1048. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], coex tdma type(%s, %d)\n",
  1049. turn_on ? "on" : "off", type);
  1050. }
  1051. static void rtw_coex_set_ant_path(struct rtw_dev *rtwdev, bool force, u8 phase)
  1052. {
  1053. struct rtw_coex *coex = &rtwdev->coex;
  1054. struct rtw_coex_stat *coex_stat = &coex->stat;
  1055. struct rtw_coex_rfe *coex_rfe = &coex->rfe;
  1056. struct rtw_coex_dm *coex_dm = &coex->dm;
  1057. u8 ctrl_type = COEX_SWITCH_CTRL_MAX;
  1058. u8 pos_type = COEX_SWITCH_TO_MAX;
  1059. if (!force && coex_dm->cur_ant_pos_type == phase)
  1060. return;
  1061. coex_dm->cur_ant_pos_type = phase;
  1062. /* avoid switch coex_ctrl_owner during BT IQK */
  1063. rtw_coex_check_rfk(rtwdev);
  1064. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1065. "[BTCoex], coex_stat->bt_disabled = 0x%x\n",
  1066. coex_stat->bt_disabled);
  1067. switch (phase) {
  1068. case COEX_SET_ANT_POWERON:
  1069. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1070. "[BTCoex], %s() - PHASE_COEX_POWERON\n", __func__);
  1071. /* set path control owner to BT at power-on */
  1072. if (coex_stat->bt_disabled)
  1073. rtw_coex_coex_ctrl_owner(rtwdev, true);
  1074. else
  1075. rtw_coex_coex_ctrl_owner(rtwdev, false);
  1076. ctrl_type = COEX_SWITCH_CTRL_BY_BBSW;
  1077. pos_type = COEX_SWITCH_TO_BT;
  1078. break;
  1079. case COEX_SET_ANT_INIT:
  1080. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1081. "[BTCoex], %s() - PHASE_COEX_INIT\n", __func__);
  1082. if (coex_stat->bt_disabled) {
  1083. /* set GNT_BT to SW low */
  1084. rtw_coex_set_gnt_bt(rtwdev, COEX_GNT_SET_SW_LOW);
  1085. /* set GNT_WL to SW high */
  1086. rtw_coex_set_gnt_wl(rtwdev, COEX_GNT_SET_SW_HIGH);
  1087. } else {
  1088. /* set GNT_BT to SW high */
  1089. rtw_coex_set_gnt_bt(rtwdev, COEX_GNT_SET_SW_HIGH);
  1090. /* set GNT_WL to SW low */
  1091. rtw_coex_set_gnt_wl(rtwdev, COEX_GNT_SET_SW_LOW);
  1092. }
  1093. /* set path control owner to wl at initial step */
  1094. rtw_coex_coex_ctrl_owner(rtwdev, true);
  1095. ctrl_type = COEX_SWITCH_CTRL_BY_BBSW;
  1096. pos_type = COEX_SWITCH_TO_BT;
  1097. break;
  1098. case COEX_SET_ANT_WONLY:
  1099. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1100. "[BTCoex], %s() - PHASE_WLANONLY_INIT\n", __func__);
  1101. /* set GNT_BT to SW Low */
  1102. rtw_coex_set_gnt_bt(rtwdev, COEX_GNT_SET_SW_LOW);
  1103. /* set GNT_WL to SW high */
  1104. rtw_coex_set_gnt_wl(rtwdev, COEX_GNT_SET_SW_HIGH);
  1105. /* set path control owner to wl at initial step */
  1106. rtw_coex_coex_ctrl_owner(rtwdev, true);
  1107. ctrl_type = COEX_SWITCH_CTRL_BY_BBSW;
  1108. pos_type = COEX_SWITCH_TO_WLG;
  1109. break;
  1110. case COEX_SET_ANT_WOFF:
  1111. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1112. "[BTCoex], %s() - PHASE_WLAN_OFF\n", __func__);
  1113. /* set path control owner to BT */
  1114. rtw_coex_coex_ctrl_owner(rtwdev, false);
  1115. ctrl_type = COEX_SWITCH_CTRL_BY_BT;
  1116. pos_type = COEX_SWITCH_TO_NOCARE;
  1117. break;
  1118. case COEX_SET_ANT_2G:
  1119. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1120. "[BTCoex], %s() - PHASE_2G_RUNTIME\n", __func__);
  1121. /* set GNT_BT to PTA */
  1122. rtw_coex_set_gnt_bt(rtwdev, COEX_GNT_SET_HW_PTA);
  1123. /* set GNT_WL to PTA */
  1124. rtw_coex_set_gnt_wl(rtwdev, COEX_GNT_SET_HW_PTA);
  1125. /* set path control owner to wl at runtime step */
  1126. rtw_coex_coex_ctrl_owner(rtwdev, true);
  1127. ctrl_type = COEX_SWITCH_CTRL_BY_PTA;
  1128. pos_type = COEX_SWITCH_TO_NOCARE;
  1129. break;
  1130. case COEX_SET_ANT_5G:
  1131. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1132. "[BTCoex], %s() - PHASE_5G_RUNTIME\n", __func__);
  1133. /* set GNT_BT to HW PTA */
  1134. rtw_coex_set_gnt_bt(rtwdev, COEX_GNT_SET_HW_PTA);
  1135. /* set GNT_WL to SW high */
  1136. rtw_coex_set_gnt_wl(rtwdev, COEX_GNT_SET_SW_HIGH);
  1137. /* set path control owner to wl at runtime step */
  1138. rtw_coex_coex_ctrl_owner(rtwdev, true);
  1139. ctrl_type = COEX_SWITCH_CTRL_BY_BBSW;
  1140. pos_type = COEX_SWITCH_TO_WLA;
  1141. break;
  1142. case COEX_SET_ANT_2G_FREERUN:
  1143. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1144. "[BTCoex], %s() - PHASE_2G_FREERUN\n", __func__);
  1145. /* set GNT_BT to HW PTA */
  1146. rtw_coex_set_gnt_bt(rtwdev, COEX_GNT_SET_HW_PTA);
  1147. /* Set GNT_WL to SW high */
  1148. rtw_coex_set_gnt_wl(rtwdev, COEX_GNT_SET_SW_HIGH);
  1149. /* set path control owner to wl at runtime step */
  1150. rtw_coex_coex_ctrl_owner(rtwdev, true);
  1151. ctrl_type = COEX_SWITCH_CTRL_BY_BBSW;
  1152. pos_type = COEX_SWITCH_TO_WLG_BT;
  1153. break;
  1154. case COEX_SET_ANT_2G_WLBT:
  1155. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1156. "[BTCoex], %s() - PHASE_2G_WLBT\n", __func__);
  1157. /* set GNT_BT to HW PTA */
  1158. rtw_coex_set_gnt_bt(rtwdev, COEX_GNT_SET_HW_PTA);
  1159. /* Set GNT_WL to HW PTA */
  1160. rtw_coex_set_gnt_wl(rtwdev, COEX_GNT_SET_HW_PTA);
  1161. /* set path control owner to wl at runtime step */
  1162. rtw_coex_coex_ctrl_owner(rtwdev, true);
  1163. ctrl_type = COEX_SWITCH_CTRL_BY_BBSW;
  1164. pos_type = COEX_SWITCH_TO_WLG_BT;
  1165. break;
  1166. default:
  1167. WARN(1, "unknown phase when setting antenna path\n");
  1168. return;
  1169. }
  1170. if (ctrl_type < COEX_SWITCH_CTRL_MAX && pos_type < COEX_SWITCH_TO_MAX &&
  1171. coex_rfe->ant_switch_exist)
  1172. rtw_coex_set_ant_switch(rtwdev, ctrl_type, pos_type);
  1173. }
  1174. #define case_ALGO(src) \
  1175. case COEX_ALGO_##src: return #src
  1176. static const char *rtw_coex_get_algo_string(u8 algo)
  1177. {
  1178. switch (algo) {
  1179. case_ALGO(NOPROFILE);
  1180. case_ALGO(HFP);
  1181. case_ALGO(HID);
  1182. case_ALGO(A2DP);
  1183. case_ALGO(PAN);
  1184. case_ALGO(A2DP_HID);
  1185. case_ALGO(A2DP_PAN);
  1186. case_ALGO(PAN_HID);
  1187. case_ALGO(A2DP_PAN_HID);
  1188. default:
  1189. return "Unknown";
  1190. }
  1191. }
  1192. #define case_BT_PROFILE(src) \
  1193. case BPM_##src: return #src
  1194. static const char *rtw_coex_get_bt_profile_string(u8 bt_profile)
  1195. {
  1196. switch (bt_profile) {
  1197. case_BT_PROFILE(NOPROFILE);
  1198. case_BT_PROFILE(HFP);
  1199. case_BT_PROFILE(HID);
  1200. case_BT_PROFILE(A2DP);
  1201. case_BT_PROFILE(PAN);
  1202. case_BT_PROFILE(HID_HFP);
  1203. case_BT_PROFILE(A2DP_HFP);
  1204. case_BT_PROFILE(A2DP_HID);
  1205. case_BT_PROFILE(A2DP_HID_HFP);
  1206. case_BT_PROFILE(PAN_HFP);
  1207. case_BT_PROFILE(PAN_HID);
  1208. case_BT_PROFILE(PAN_HID_HFP);
  1209. case_BT_PROFILE(PAN_A2DP);
  1210. case_BT_PROFILE(PAN_A2DP_HFP);
  1211. case_BT_PROFILE(PAN_A2DP_HID);
  1212. case_BT_PROFILE(PAN_A2DP_HID_HFP);
  1213. default:
  1214. return "Unknown";
  1215. }
  1216. }
  1217. static u8 rtw_coex_algorithm(struct rtw_dev *rtwdev)
  1218. {
  1219. struct rtw_coex *coex = &rtwdev->coex;
  1220. struct rtw_coex_stat *coex_stat = &coex->stat;
  1221. u8 algorithm = COEX_ALGO_NOPROFILE;
  1222. u8 profile_map = 0;
  1223. if (coex_stat->bt_hfp_exist)
  1224. profile_map |= BPM_HFP;
  1225. if (coex_stat->bt_hid_exist)
  1226. profile_map |= BPM_HID;
  1227. if (coex_stat->bt_a2dp_exist)
  1228. profile_map |= BPM_A2DP;
  1229. if (coex_stat->bt_pan_exist)
  1230. profile_map |= BPM_PAN;
  1231. switch (profile_map) {
  1232. case BPM_HFP:
  1233. algorithm = COEX_ALGO_HFP;
  1234. break;
  1235. case BPM_HID:
  1236. case BPM_HFP | BPM_HID:
  1237. algorithm = COEX_ALGO_HID;
  1238. break;
  1239. case BPM_HFP | BPM_A2DP:
  1240. case BPM_HID | BPM_A2DP:
  1241. case BPM_HFP | BPM_HID | BPM_A2DP:
  1242. algorithm = COEX_ALGO_A2DP_HID;
  1243. break;
  1244. case BPM_HFP | BPM_PAN:
  1245. case BPM_HID | BPM_PAN:
  1246. case BPM_HFP | BPM_HID | BPM_PAN:
  1247. algorithm = COEX_ALGO_PAN_HID;
  1248. break;
  1249. case BPM_HFP | BPM_A2DP | BPM_PAN:
  1250. case BPM_HID | BPM_A2DP | BPM_PAN:
  1251. case BPM_HFP | BPM_HID | BPM_A2DP | BPM_PAN:
  1252. algorithm = COEX_ALGO_A2DP_PAN_HID;
  1253. break;
  1254. case BPM_PAN:
  1255. algorithm = COEX_ALGO_PAN;
  1256. break;
  1257. case BPM_A2DP | BPM_PAN:
  1258. algorithm = COEX_ALGO_A2DP_PAN;
  1259. break;
  1260. case BPM_A2DP:
  1261. if (coex_stat->bt_multi_link) {
  1262. if (coex_stat->bt_hid_pair_num > 0)
  1263. algorithm = COEX_ALGO_A2DP_HID;
  1264. else
  1265. algorithm = COEX_ALGO_A2DP_PAN;
  1266. } else {
  1267. algorithm = COEX_ALGO_A2DP;
  1268. }
  1269. break;
  1270. default:
  1271. algorithm = COEX_ALGO_NOPROFILE;
  1272. break;
  1273. }
  1274. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1275. "[BTCoex], BT Profile = %s => Algorithm = %s\n",
  1276. rtw_coex_get_bt_profile_string(profile_map),
  1277. rtw_coex_get_algo_string(algorithm));
  1278. return algorithm;
  1279. }
  1280. static void rtw_coex_action_coex_all_off(struct rtw_dev *rtwdev)
  1281. {
  1282. const struct rtw_chip_info *chip = rtwdev->chip;
  1283. struct rtw_efuse *efuse = &rtwdev->efuse;
  1284. u8 table_case, tdma_case;
  1285. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1286. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1287. if (efuse->share_ant) {
  1288. /* Shared-Ant */
  1289. table_case = 2;
  1290. tdma_case = 0;
  1291. } else {
  1292. /* Non-Shared-Ant */
  1293. table_case = 100;
  1294. tdma_case = 100;
  1295. }
  1296. rtw_coex_table(rtwdev, false, table_case);
  1297. rtw_coex_tdma(rtwdev, false, tdma_case);
  1298. }
  1299. static void rtw_coex_action_freerun(struct rtw_dev *rtwdev)
  1300. {
  1301. const struct rtw_chip_info *chip = rtwdev->chip;
  1302. struct rtw_coex *coex = &rtwdev->coex;
  1303. struct rtw_coex_stat *coex_stat = &coex->stat;
  1304. struct rtw_coex_dm *coex_dm = &coex->dm;
  1305. struct rtw_efuse *efuse = &rtwdev->efuse;
  1306. u8 level = 0;
  1307. bool bt_afh_loss = true;
  1308. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1309. if (efuse->share_ant)
  1310. return;
  1311. coex->freerun = true;
  1312. if (bt_afh_loss)
  1313. rtw_coex_update_wl_ch_info(rtwdev, COEX_MEDIA_CONNECT);
  1314. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G_FREERUN);
  1315. rtw_coex_write_scbd(rtwdev, COEX_SCBD_FIX2M, false);
  1316. if (COEX_RSSI_HIGH(coex_dm->wl_rssi_state[0]))
  1317. level = 2;
  1318. else if (COEX_RSSI_HIGH(coex_dm->wl_rssi_state[1]))
  1319. level = 3;
  1320. else if (COEX_RSSI_HIGH(coex_dm->wl_rssi_state[2]))
  1321. level = 4;
  1322. else
  1323. level = 5;
  1324. if (level > chip->wl_rf_para_num - 1)
  1325. level = chip->wl_rf_para_num - 1;
  1326. if (coex_stat->wl_tput_dir == COEX_WL_TPUT_TX)
  1327. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_tx[level]);
  1328. else
  1329. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[level]);
  1330. rtw_coex_table(rtwdev, false, 100);
  1331. rtw_coex_tdma(rtwdev, false, 100);
  1332. }
  1333. static void rtw_coex_action_rf4ce(struct rtw_dev *rtwdev)
  1334. {
  1335. const struct rtw_chip_info *chip = rtwdev->chip;
  1336. struct rtw_efuse *efuse = &rtwdev->efuse;
  1337. u8 table_case, tdma_case;
  1338. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1339. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1340. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1341. if (efuse->share_ant) {
  1342. /* Shared-Ant */
  1343. table_case = 9;
  1344. tdma_case = 16;
  1345. } else {
  1346. /* Non-Shared-Ant */
  1347. table_case = 100;
  1348. tdma_case = 100;
  1349. }
  1350. rtw_coex_table(rtwdev, false, table_case);
  1351. rtw_coex_tdma(rtwdev, false, tdma_case);
  1352. }
  1353. static void rtw_coex_action_bt_whql_test(struct rtw_dev *rtwdev)
  1354. {
  1355. const struct rtw_chip_info *chip = rtwdev->chip;
  1356. struct rtw_efuse *efuse = &rtwdev->efuse;
  1357. u8 table_case, tdma_case;
  1358. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1359. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1360. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1361. if (efuse->share_ant) {
  1362. /* Shared-Ant */
  1363. table_case = 2;
  1364. tdma_case = 0;
  1365. } else {
  1366. /* Non-Shared-Ant */
  1367. table_case = 100;
  1368. tdma_case = 100;
  1369. }
  1370. rtw_coex_table(rtwdev, false, table_case);
  1371. rtw_coex_tdma(rtwdev, false, tdma_case);
  1372. }
  1373. static void rtw_coex_action_bt_relink(struct rtw_dev *rtwdev)
  1374. {
  1375. const struct rtw_chip_info *chip = rtwdev->chip;
  1376. struct rtw_coex *coex = &rtwdev->coex;
  1377. struct rtw_coex_stat *coex_stat = &coex->stat;
  1378. struct rtw_efuse *efuse = &rtwdev->efuse;
  1379. u8 table_case, tdma_case;
  1380. u32 slot_type = 0;
  1381. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1382. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1383. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1384. if (efuse->share_ant) { /* Shared-Ant */
  1385. if (coex_stat->wl_gl_busy) {
  1386. table_case = 26;
  1387. if (coex_stat->bt_hid_exist &&
  1388. coex_stat->bt_profile_num == 1) {
  1389. slot_type = TDMA_4SLOT;
  1390. tdma_case = 20;
  1391. } else {
  1392. tdma_case = 20;
  1393. }
  1394. } else {
  1395. table_case = 1;
  1396. tdma_case = 0;
  1397. }
  1398. } else { /* Non-Shared-Ant */
  1399. if (coex_stat->wl_gl_busy)
  1400. table_case = 115;
  1401. else
  1402. table_case = 100;
  1403. tdma_case = 100;
  1404. }
  1405. rtw_coex_table(rtwdev, false, table_case);
  1406. rtw_coex_tdma(rtwdev, false, tdma_case | slot_type);
  1407. }
  1408. static void rtw_coex_action_bt_idle(struct rtw_dev *rtwdev)
  1409. {
  1410. const struct rtw_chip_info *chip = rtwdev->chip;
  1411. struct rtw_coex *coex = &rtwdev->coex;
  1412. struct rtw_coex_stat *coex_stat = &coex->stat;
  1413. struct rtw_coex_dm *coex_dm = &coex->dm;
  1414. struct rtw_efuse *efuse = &rtwdev->efuse;
  1415. struct rtw_coex_rfe *coex_rfe = &coex->rfe;
  1416. u8 table_case = 0xff, tdma_case = 0xff;
  1417. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1418. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1419. if (coex_rfe->ant_switch_with_bt &&
  1420. coex_dm->bt_status == COEX_BTSTATUS_NCON_IDLE) {
  1421. if (efuse->share_ant &&
  1422. COEX_RSSI_HIGH(coex_dm->wl_rssi_state[3]) &&
  1423. coex_stat->wl_gl_busy) {
  1424. table_case = 0;
  1425. tdma_case = 0;
  1426. } else if (!efuse->share_ant) {
  1427. table_case = 100;
  1428. tdma_case = 100;
  1429. }
  1430. }
  1431. if (table_case != 0xff && tdma_case != 0xff) {
  1432. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G_FREERUN);
  1433. goto exit;
  1434. }
  1435. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1436. if (efuse->share_ant) {
  1437. /* Shared-Ant */
  1438. if (!coex_stat->wl_gl_busy) {
  1439. table_case = 10;
  1440. tdma_case = 3;
  1441. } else if (coex_dm->bt_status == COEX_BTSTATUS_NCON_IDLE) {
  1442. table_case = 11;
  1443. if (coex_stat->lo_pri_rx + coex_stat->lo_pri_tx > 250)
  1444. tdma_case = 17;
  1445. else
  1446. tdma_case = 7;
  1447. } else {
  1448. table_case = 12;
  1449. tdma_case = 7;
  1450. }
  1451. } else {
  1452. /* Non-Shared-Ant */
  1453. if (!coex_stat->wl_gl_busy) {
  1454. table_case = 112;
  1455. tdma_case = 104;
  1456. } else if ((coex_stat->bt_ble_scan_type & 0x2) &&
  1457. coex_dm->bt_status == COEX_BTSTATUS_NCON_IDLE) {
  1458. table_case = 114;
  1459. tdma_case = 103;
  1460. } else {
  1461. table_case = 112;
  1462. tdma_case = 103;
  1463. }
  1464. }
  1465. exit:
  1466. rtw_coex_table(rtwdev, false, table_case);
  1467. rtw_coex_tdma(rtwdev, false, tdma_case);
  1468. }
  1469. static void rtw_coex_action_bt_inquiry(struct rtw_dev *rtwdev)
  1470. {
  1471. const struct rtw_chip_info *chip = rtwdev->chip;
  1472. struct rtw_coex *coex = &rtwdev->coex;
  1473. struct rtw_coex_stat *coex_stat = &coex->stat;
  1474. struct rtw_efuse *efuse = &rtwdev->efuse;
  1475. bool wl_hi_pri = false;
  1476. u8 table_case, tdma_case;
  1477. u32 slot_type = 0;
  1478. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1479. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1480. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1481. if (coex_stat->wl_linkscan_proc || coex_stat->wl_hi_pri_task1 ||
  1482. coex_stat->wl_hi_pri_task2)
  1483. wl_hi_pri = true;
  1484. if (efuse->share_ant) {
  1485. /* Shared-Ant */
  1486. if (wl_hi_pri) {
  1487. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1488. "[BTCoex], bt inq/page + wifi hi-pri task\n");
  1489. table_case = 15;
  1490. if (coex_stat->bt_profile_num > 0)
  1491. tdma_case = 10;
  1492. else if (coex_stat->wl_hi_pri_task1)
  1493. tdma_case = 6;
  1494. else if (!coex_stat->bt_page)
  1495. tdma_case = 8;
  1496. else
  1497. tdma_case = 9;
  1498. } else if (coex_stat->wl_gl_busy) {
  1499. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1500. "[BTCoex], bt inq/page + wifi busy\n");
  1501. if (coex_stat->bt_profile_num == 0) {
  1502. table_case = 12;
  1503. tdma_case = 18;
  1504. } else if (coex_stat->bt_profile_num == 1 &&
  1505. !coex_stat->bt_a2dp_exist) {
  1506. slot_type = TDMA_4SLOT;
  1507. table_case = 12;
  1508. tdma_case = 20;
  1509. } else {
  1510. slot_type = TDMA_4SLOT;
  1511. table_case = 12;
  1512. tdma_case = 26;
  1513. }
  1514. } else if (coex_stat->wl_connected) {
  1515. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1516. "[BTCoex], bt inq/page + wifi connected\n");
  1517. table_case = 9;
  1518. tdma_case = 27;
  1519. } else {
  1520. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1521. "[BTCoex], bt inq/page + wifi not-connected\n");
  1522. table_case = 1;
  1523. tdma_case = 0;
  1524. }
  1525. } else {
  1526. /* Non_Shared-Ant */
  1527. if (wl_hi_pri) {
  1528. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1529. "[BTCoex], bt inq/page + wifi hi-pri task\n");
  1530. table_case = 114;
  1531. if (coex_stat->bt_profile_num > 0)
  1532. tdma_case = 110;
  1533. else if (coex_stat->wl_hi_pri_task1)
  1534. tdma_case = 106;
  1535. else if (!coex_stat->bt_page)
  1536. tdma_case = 108;
  1537. else
  1538. tdma_case = 109;
  1539. } else if (coex_stat->wl_gl_busy) {
  1540. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1541. "[BTCoex], bt inq/page + wifi busy\n");
  1542. table_case = 114;
  1543. tdma_case = 121;
  1544. } else if (coex_stat->wl_connected) {
  1545. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1546. "[BTCoex], bt inq/page + wifi connected\n");
  1547. table_case = 101;
  1548. tdma_case = 100;
  1549. } else {
  1550. rtw_dbg(rtwdev, RTW_DBG_COEX,
  1551. "[BTCoex], bt inq/page + wifi not-connected\n");
  1552. table_case = 101;
  1553. tdma_case = 100;
  1554. }
  1555. }
  1556. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], wifi hi(%d), bt page(%d)\n",
  1557. wl_hi_pri, coex_stat->bt_page);
  1558. rtw_coex_table(rtwdev, false, table_case);
  1559. rtw_coex_tdma(rtwdev, false, tdma_case | slot_type);
  1560. }
  1561. static void rtw_coex_action_bt_game_hid(struct rtw_dev *rtwdev)
  1562. {
  1563. const struct rtw_chip_info *chip = rtwdev->chip;
  1564. struct rtw_coex *coex = &rtwdev->coex;
  1565. struct rtw_coex_stat *coex_stat = &coex->stat;
  1566. struct rtw_efuse *efuse = &rtwdev->efuse;
  1567. struct rtw_coex_dm *coex_dm = &coex->dm;
  1568. u8 table_case, tdma_case;
  1569. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1570. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1571. if (efuse->share_ant) {
  1572. coex_stat->wl_coex_mode = COEX_WLINK_2GFREE;
  1573. if (coex_stat->bt_whck_test)
  1574. table_case = 2;
  1575. else if (coex_stat->wl_linkscan_proc || coex_stat->bt_hid_exist)
  1576. table_case = 33;
  1577. else if (coex_stat->bt_setup_link || coex_stat->bt_inq_page)
  1578. table_case = 0;
  1579. else if (coex_stat->bt_a2dp_exist)
  1580. table_case = 34;
  1581. else
  1582. table_case = 33;
  1583. tdma_case = 0;
  1584. } else {
  1585. if (COEX_RSSI_HIGH(coex_dm->wl_rssi_state[1]))
  1586. tdma_case = 112;
  1587. else
  1588. tdma_case = 113;
  1589. table_case = 121;
  1590. }
  1591. if (coex_stat->wl_coex_mode == COEX_WLINK_2GFREE) {
  1592. if (coex_stat->wl_tput_dir == COEX_WL_TPUT_TX)
  1593. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_tx[6]);
  1594. else
  1595. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[5]);
  1596. } else {
  1597. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1598. }
  1599. rtw_coex_table(rtwdev, false, table_case);
  1600. rtw_coex_tdma(rtwdev, false, tdma_case);
  1601. }
  1602. static void rtw_coex_action_bt_hfp(struct rtw_dev *rtwdev)
  1603. {
  1604. const struct rtw_chip_info *chip = rtwdev->chip;
  1605. struct rtw_coex *coex = &rtwdev->coex;
  1606. struct rtw_coex_stat *coex_stat = &coex->stat;
  1607. struct rtw_efuse *efuse = &rtwdev->efuse;
  1608. u8 table_case, tdma_case;
  1609. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1610. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1611. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1612. if (efuse->share_ant) {
  1613. /* Shared-Ant */
  1614. table_case = 10;
  1615. tdma_case = 5;
  1616. } else {
  1617. /* Non-Shared-Ant */
  1618. if (coex_stat->bt_multi_link) {
  1619. table_case = 112;
  1620. tdma_case = 117;
  1621. } else {
  1622. table_case = 105;
  1623. tdma_case = 100;
  1624. }
  1625. }
  1626. rtw_coex_table(rtwdev, false, table_case);
  1627. rtw_coex_tdma(rtwdev, false, tdma_case);
  1628. }
  1629. static void rtw_coex_action_bt_hid(struct rtw_dev *rtwdev)
  1630. {
  1631. const struct rtw_chip_info *chip = rtwdev->chip;
  1632. struct rtw_coex *coex = &rtwdev->coex;
  1633. struct rtw_coex_stat *coex_stat = &coex->stat;
  1634. struct rtw_efuse *efuse = &rtwdev->efuse;
  1635. u8 table_case, tdma_case;
  1636. u32 slot_type = 0;
  1637. bool bt_multi_link_remain = false, is_toggle_table = false;
  1638. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1639. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1640. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1641. if (efuse->share_ant) {
  1642. /* Shared-Ant */
  1643. if (coex_stat->bt_ble_exist) {
  1644. /* RCU */
  1645. if (coex_stat->cnt_wl[COEX_CNT_WL_SCANAP] > 5) {
  1646. table_case = 26;
  1647. tdma_case = 2;
  1648. } else {
  1649. table_case = 27;
  1650. tdma_case = 9;
  1651. }
  1652. } else {
  1653. /* Legacy HID */
  1654. if (coex_stat->bt_profile_num == 1 &&
  1655. (coex_stat->bt_multi_link ||
  1656. (coex_stat->lo_pri_rx +
  1657. coex_stat->lo_pri_tx > 360) ||
  1658. coex_stat->bt_slave ||
  1659. bt_multi_link_remain)) {
  1660. slot_type = TDMA_4SLOT;
  1661. table_case = 12;
  1662. tdma_case = 20;
  1663. } else if (coex_stat->bt_a2dp_active) {
  1664. table_case = 9;
  1665. tdma_case = 18;
  1666. } else if (coex_stat->bt_418_hid_exist &&
  1667. coex_stat->wl_gl_busy) {
  1668. is_toggle_table = true;
  1669. slot_type = TDMA_4SLOT;
  1670. table_case = 9;
  1671. tdma_case = 24;
  1672. } else if (coex_stat->bt_ble_hid_exist &&
  1673. coex_stat->wl_gl_busy) {
  1674. table_case = 32;
  1675. tdma_case = 9;
  1676. } else {
  1677. table_case = 9;
  1678. tdma_case = 9;
  1679. }
  1680. }
  1681. } else {
  1682. /* Non-Shared-Ant */
  1683. if (coex_stat->bt_ble_exist) {
  1684. /* BLE */
  1685. if (coex_stat->cnt_wl[COEX_CNT_WL_SCANAP] > 5) {
  1686. table_case = 121;
  1687. tdma_case = 102;
  1688. } else {
  1689. table_case = 122;
  1690. tdma_case = 109;
  1691. }
  1692. } else if (coex_stat->bt_a2dp_active) {
  1693. table_case = 113;
  1694. tdma_case = 118;
  1695. } else {
  1696. table_case = 113;
  1697. tdma_case = 104;
  1698. }
  1699. }
  1700. rtw_coex_table(rtwdev, false, table_case);
  1701. if (is_toggle_table) {
  1702. rtw_btc_wltoggle_table_a(rtwdev, true, table_case);
  1703. rtw_btc_wltoggle_table_b(rtwdev, false, 1, COEX_WL_SLOT_TOGLLE);
  1704. }
  1705. rtw_coex_tdma(rtwdev, false, tdma_case | slot_type);
  1706. }
  1707. static void rtw_coex_action_bt_a2dp(struct rtw_dev *rtwdev)
  1708. {
  1709. const struct rtw_chip_info *chip = rtwdev->chip;
  1710. struct rtw_coex *coex = &rtwdev->coex;
  1711. struct rtw_coex_stat *coex_stat = &coex->stat;
  1712. struct rtw_coex_dm *coex_dm = &coex->dm;
  1713. struct rtw_efuse *efuse = &rtwdev->efuse;
  1714. u8 table_case, tdma_case;
  1715. u32 slot_type = 0;
  1716. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1717. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1718. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1719. slot_type = TDMA_4SLOT;
  1720. if (efuse->share_ant) {
  1721. /* Shared-Ant */
  1722. if (coex_stat->wl_gl_busy && coex_stat->wl_noisy_level == 0)
  1723. table_case = 12;
  1724. else
  1725. table_case = 9;
  1726. if (coex_stat->wl_connecting || !coex_stat->wl_gl_busy)
  1727. tdma_case = 14;
  1728. else
  1729. tdma_case = 13;
  1730. } else {
  1731. /* Non-Shared-Ant */
  1732. table_case = 112;
  1733. if (COEX_RSSI_HIGH(coex_dm->wl_rssi_state[1]))
  1734. tdma_case = 112;
  1735. else
  1736. tdma_case = 113;
  1737. }
  1738. rtw_coex_table(rtwdev, false, table_case);
  1739. rtw_coex_tdma(rtwdev, false, tdma_case | slot_type);
  1740. }
  1741. static void rtw_coex_action_bt_a2dpsink(struct rtw_dev *rtwdev)
  1742. {
  1743. const struct rtw_chip_info *chip = rtwdev->chip;
  1744. struct rtw_coex *coex = &rtwdev->coex;
  1745. struct rtw_coex_stat *coex_stat = &coex->stat;
  1746. struct rtw_efuse *efuse = &rtwdev->efuse;
  1747. u8 table_case, tdma_case;
  1748. bool ap_enable = false;
  1749. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1750. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1751. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1752. if (efuse->share_ant) { /* Shared-Ant */
  1753. if (ap_enable) {
  1754. table_case = 2;
  1755. tdma_case = 0;
  1756. } else if (coex_stat->wl_gl_busy) {
  1757. table_case = 28;
  1758. tdma_case = 20;
  1759. } else {
  1760. table_case = 28;
  1761. tdma_case = 26;
  1762. }
  1763. } else { /* Non-Shared-Ant */
  1764. if (ap_enable) {
  1765. table_case = 100;
  1766. tdma_case = 100;
  1767. } else {
  1768. table_case = 119;
  1769. tdma_case = 120;
  1770. }
  1771. }
  1772. rtw_coex_table(rtwdev, false, table_case);
  1773. rtw_coex_tdma(rtwdev, false, tdma_case);
  1774. }
  1775. static void rtw_coex_action_bt_pan(struct rtw_dev *rtwdev)
  1776. {
  1777. const struct rtw_chip_info *chip = rtwdev->chip;
  1778. struct rtw_coex *coex = &rtwdev->coex;
  1779. struct rtw_coex_stat *coex_stat = &coex->stat;
  1780. struct rtw_efuse *efuse = &rtwdev->efuse;
  1781. u8 table_case, tdma_case;
  1782. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1783. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1784. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1785. if (efuse->share_ant) {
  1786. /* Shared-Ant */
  1787. if (coex_stat->wl_gl_busy && coex_stat->wl_noisy_level == 0)
  1788. table_case = 14;
  1789. else
  1790. table_case = 10;
  1791. if (coex_stat->wl_gl_busy)
  1792. tdma_case = 17;
  1793. else
  1794. tdma_case = 20;
  1795. } else {
  1796. /* Non-Shared-Ant */
  1797. table_case = 112;
  1798. if (coex_stat->wl_gl_busy)
  1799. tdma_case = 117;
  1800. else
  1801. tdma_case = 119;
  1802. }
  1803. rtw_coex_table(rtwdev, false, table_case);
  1804. rtw_coex_tdma(rtwdev, false, tdma_case);
  1805. }
  1806. static void rtw_coex_action_bt_a2dp_hid(struct rtw_dev *rtwdev)
  1807. {
  1808. const struct rtw_chip_info *chip = rtwdev->chip;
  1809. struct rtw_coex *coex = &rtwdev->coex;
  1810. struct rtw_coex_stat *coex_stat = &coex->stat;
  1811. struct rtw_coex_dm *coex_dm = &coex->dm;
  1812. struct rtw_efuse *efuse = &rtwdev->efuse;
  1813. u8 table_case, tdma_case, interval = 0;
  1814. u32 slot_type = 0;
  1815. bool is_toggle_table = false;
  1816. slot_type = TDMA_4SLOT;
  1817. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1818. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1819. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1820. if (efuse->share_ant) {
  1821. /* Shared-Ant */
  1822. if (coex_stat->bt_ble_exist) {
  1823. table_case = 26; /* for RCU */
  1824. } else if (coex_stat->bt_418_hid_exist) {
  1825. table_case = 9;
  1826. interval = 1;
  1827. } else {
  1828. table_case = 9;
  1829. }
  1830. if (coex_stat->wl_connecting || !coex_stat->wl_gl_busy) {
  1831. tdma_case = 14;
  1832. } else if (coex_stat->bt_418_hid_exist) {
  1833. is_toggle_table = true;
  1834. tdma_case = 23;
  1835. } else {
  1836. tdma_case = 13;
  1837. }
  1838. } else {
  1839. /* Non-Shared-Ant */
  1840. if (coex_stat->bt_ble_exist)
  1841. table_case = 121;
  1842. else
  1843. table_case = 113;
  1844. if (COEX_RSSI_HIGH(coex_dm->wl_rssi_state[1]))
  1845. tdma_case = 112;
  1846. else
  1847. tdma_case = 113;
  1848. }
  1849. rtw_coex_table(rtwdev, false, table_case);
  1850. if (is_toggle_table) {
  1851. rtw_btc_wltoggle_table_a(rtwdev, true, table_case);
  1852. rtw_btc_wltoggle_table_b(rtwdev, false, interval, COEX_WL_SLOT_TOGLLE);
  1853. }
  1854. rtw_coex_tdma(rtwdev, false, tdma_case | slot_type);
  1855. }
  1856. static void rtw_coex_action_bt_a2dp_pan(struct rtw_dev *rtwdev)
  1857. {
  1858. const struct rtw_chip_info *chip = rtwdev->chip;
  1859. struct rtw_coex *coex = &rtwdev->coex;
  1860. struct rtw_coex_stat *coex_stat = &coex->stat;
  1861. struct rtw_efuse *efuse = &rtwdev->efuse;
  1862. u8 table_case, tdma_case;
  1863. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1864. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1865. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1866. if (efuse->share_ant) {
  1867. /* Shared-Ant */
  1868. if (coex_stat->wl_gl_busy &&
  1869. coex_stat->wl_noisy_level == 0)
  1870. table_case = 14;
  1871. else
  1872. table_case = 10;
  1873. if (coex_stat->wl_gl_busy)
  1874. tdma_case = 15;
  1875. else
  1876. tdma_case = 20;
  1877. } else {
  1878. /* Non-Shared-Ant */
  1879. table_case = 112;
  1880. if (coex_stat->wl_gl_busy)
  1881. tdma_case = 115;
  1882. else
  1883. tdma_case = 120;
  1884. }
  1885. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1886. rtw_coex_table(rtwdev, false, table_case);
  1887. rtw_coex_tdma(rtwdev, false, tdma_case);
  1888. }
  1889. static void rtw_coex_action_bt_pan_hid(struct rtw_dev *rtwdev)
  1890. {
  1891. const struct rtw_chip_info *chip = rtwdev->chip;
  1892. struct rtw_coex *coex = &rtwdev->coex;
  1893. struct rtw_coex_stat *coex_stat = &coex->stat;
  1894. struct rtw_efuse *efuse = &rtwdev->efuse;
  1895. u8 table_case, tdma_case;
  1896. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1897. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1898. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1899. if (efuse->share_ant) {
  1900. /* Shared-Ant */
  1901. table_case = 9;
  1902. if (coex_stat->wl_gl_busy)
  1903. tdma_case = 18;
  1904. else
  1905. tdma_case = 19;
  1906. } else {
  1907. /* Non-Shared-Ant */
  1908. table_case = 113;
  1909. if (coex_stat->wl_gl_busy)
  1910. tdma_case = 117;
  1911. else
  1912. tdma_case = 119;
  1913. }
  1914. rtw_coex_table(rtwdev, false, table_case);
  1915. rtw_coex_tdma(rtwdev, false, tdma_case);
  1916. }
  1917. static void rtw_coex_action_bt_a2dp_pan_hid(struct rtw_dev *rtwdev)
  1918. {
  1919. const struct rtw_chip_info *chip = rtwdev->chip;
  1920. struct rtw_coex *coex = &rtwdev->coex;
  1921. struct rtw_coex_stat *coex_stat = &coex->stat;
  1922. struct rtw_efuse *efuse = &rtwdev->efuse;
  1923. u8 table_case, tdma_case;
  1924. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1925. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1926. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1927. if (efuse->share_ant) {
  1928. /* Shared-Ant */
  1929. table_case = 10;
  1930. if (coex_stat->wl_gl_busy)
  1931. tdma_case = 15;
  1932. else
  1933. tdma_case = 20;
  1934. } else {
  1935. /* Non-Shared-Ant */
  1936. table_case = 113;
  1937. if (coex_stat->wl_gl_busy)
  1938. tdma_case = 115;
  1939. else
  1940. tdma_case = 120;
  1941. }
  1942. rtw_coex_table(rtwdev, false, table_case);
  1943. rtw_coex_tdma(rtwdev, false, tdma_case);
  1944. }
  1945. static void rtw_coex_action_wl_under5g(struct rtw_dev *rtwdev)
  1946. {
  1947. const struct rtw_chip_info *chip = rtwdev->chip;
  1948. struct rtw_coex *coex = &rtwdev->coex;
  1949. struct rtw_efuse *efuse = &rtwdev->efuse;
  1950. struct rtw_coex_stat *coex_stat = &coex->stat;
  1951. u8 table_case, tdma_case;
  1952. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1953. rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_5G);
  1954. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1955. rtw_coex_write_scbd(rtwdev, COEX_SCBD_FIX2M, false);
  1956. if (coex_stat->bt_game_hid_exist && coex_stat->wl_linkscan_proc)
  1957. coex_stat->wl_coex_mode = COEX_WLINK_2GFREE;
  1958. if (efuse->share_ant) {
  1959. /* Shared-Ant */
  1960. table_case = 0;
  1961. tdma_case = 0;
  1962. } else {
  1963. /* Non-Shared-Ant */
  1964. table_case = 100;
  1965. tdma_case = 100;
  1966. }
  1967. rtw_coex_table(rtwdev, false, table_case);
  1968. rtw_coex_tdma(rtwdev, false, tdma_case);
  1969. }
  1970. static void rtw_coex_action_wl_only(struct rtw_dev *rtwdev)
  1971. {
  1972. const struct rtw_chip_info *chip = rtwdev->chip;
  1973. struct rtw_efuse *efuse = &rtwdev->efuse;
  1974. u8 table_case, tdma_case;
  1975. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  1976. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  1977. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  1978. if (efuse->share_ant) {
  1979. /* Shared-Ant */
  1980. table_case = 2;
  1981. tdma_case = 0;
  1982. } else {
  1983. /* Non-Shared-Ant */
  1984. table_case = 100;
  1985. tdma_case = 100;
  1986. }
  1987. rtw_coex_table(rtwdev, false, table_case);
  1988. rtw_coex_tdma(rtwdev, false, tdma_case);
  1989. }
  1990. static void rtw_coex_action_wl_native_lps(struct rtw_dev *rtwdev)
  1991. {
  1992. const struct rtw_chip_info *chip = rtwdev->chip;
  1993. struct rtw_coex *coex = &rtwdev->coex;
  1994. struct rtw_efuse *efuse = &rtwdev->efuse;
  1995. struct rtw_coex_stat *coex_stat = &coex->stat;
  1996. u8 table_case, tdma_case;
  1997. if (coex->under_5g)
  1998. return;
  1999. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  2000. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  2001. if (efuse->share_ant) {
  2002. /* Shared-Ant */
  2003. table_case = 28;
  2004. tdma_case = 0;
  2005. } else {
  2006. /* Non-Shared-Ant */
  2007. table_case = 100;
  2008. tdma_case = 100;
  2009. }
  2010. if (coex_stat->bt_game_hid_exist) {
  2011. coex_stat->wl_coex_mode = COEX_WLINK_2GFREE;
  2012. if (coex_stat->wl_tput_dir == COEX_WL_TPUT_TX)
  2013. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_tx[6]);
  2014. else
  2015. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[5]);
  2016. } else {
  2017. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  2018. }
  2019. rtw_coex_table(rtwdev, false, table_case);
  2020. rtw_coex_tdma(rtwdev, false, tdma_case);
  2021. }
  2022. static void rtw_coex_action_wl_linkscan(struct rtw_dev *rtwdev)
  2023. {
  2024. const struct rtw_chip_info *chip = rtwdev->chip;
  2025. struct rtw_coex *coex = &rtwdev->coex;
  2026. struct rtw_coex_stat *coex_stat = &coex->stat;
  2027. struct rtw_efuse *efuse = &rtwdev->efuse;
  2028. u8 table_case, tdma_case;
  2029. u32 slot_type = 0;
  2030. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  2031. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  2032. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  2033. if (efuse->share_ant) { /* Shared-Ant */
  2034. if (coex_stat->bt_a2dp_exist) {
  2035. slot_type = TDMA_4SLOT;
  2036. tdma_case = 11;
  2037. if (coex_stat->wl_gl_busy)
  2038. table_case = 26;
  2039. else
  2040. table_case = 9;
  2041. } else {
  2042. table_case = 9;
  2043. tdma_case = 7;
  2044. }
  2045. } else { /* Non-Shared-Ant */
  2046. if (coex_stat->bt_a2dp_exist) {
  2047. slot_type = TDMA_4SLOT;
  2048. table_case = 112;
  2049. tdma_case = 111;
  2050. } else {
  2051. table_case = 112;
  2052. tdma_case = 107;
  2053. }
  2054. }
  2055. rtw_coex_table(rtwdev, false, table_case);
  2056. rtw_coex_tdma(rtwdev, false, tdma_case | slot_type);
  2057. }
  2058. static void rtw_coex_action_wl_not_connected(struct rtw_dev *rtwdev)
  2059. {
  2060. const struct rtw_chip_info *chip = rtwdev->chip;
  2061. struct rtw_efuse *efuse = &rtwdev->efuse;
  2062. u8 table_case, tdma_case;
  2063. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  2064. rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
  2065. rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
  2066. if (efuse->share_ant) {
  2067. /* Shared-Ant */
  2068. table_case = 1;
  2069. tdma_case = 0;
  2070. } else {
  2071. /* Non-Shared-Ant */
  2072. table_case = 100;
  2073. tdma_case = 100;
  2074. }
  2075. rtw_coex_table(rtwdev, false, table_case);
  2076. rtw_coex_tdma(rtwdev, false, tdma_case);
  2077. }
  2078. static void rtw_coex_action_wl_connected(struct rtw_dev *rtwdev)
  2079. {
  2080. struct rtw_coex *coex = &rtwdev->coex;
  2081. struct rtw_coex_stat *coex_stat = &coex->stat;
  2082. u8 algorithm;
  2083. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  2084. algorithm = rtw_coex_algorithm(rtwdev);
  2085. switch (algorithm) {
  2086. case COEX_ALGO_HFP:
  2087. rtw_coex_action_bt_hfp(rtwdev);
  2088. break;
  2089. case COEX_ALGO_HID:
  2090. if (rtw_coex_freerun_check(rtwdev))
  2091. rtw_coex_action_freerun(rtwdev);
  2092. else
  2093. rtw_coex_action_bt_hid(rtwdev);
  2094. break;
  2095. case COEX_ALGO_A2DP:
  2096. if (rtw_coex_freerun_check(rtwdev))
  2097. rtw_coex_action_freerun(rtwdev);
  2098. else if (coex_stat->bt_a2dp_sink)
  2099. rtw_coex_action_bt_a2dpsink(rtwdev);
  2100. else
  2101. rtw_coex_action_bt_a2dp(rtwdev);
  2102. break;
  2103. case COEX_ALGO_PAN:
  2104. rtw_coex_action_bt_pan(rtwdev);
  2105. break;
  2106. case COEX_ALGO_A2DP_HID:
  2107. if (rtw_coex_freerun_check(rtwdev))
  2108. rtw_coex_action_freerun(rtwdev);
  2109. else
  2110. rtw_coex_action_bt_a2dp_hid(rtwdev);
  2111. break;
  2112. case COEX_ALGO_A2DP_PAN:
  2113. rtw_coex_action_bt_a2dp_pan(rtwdev);
  2114. break;
  2115. case COEX_ALGO_PAN_HID:
  2116. rtw_coex_action_bt_pan_hid(rtwdev);
  2117. break;
  2118. case COEX_ALGO_A2DP_PAN_HID:
  2119. rtw_coex_action_bt_a2dp_pan_hid(rtwdev);
  2120. break;
  2121. default:
  2122. case COEX_ALGO_NOPROFILE:
  2123. rtw_coex_action_bt_idle(rtwdev);
  2124. break;
  2125. }
  2126. }
  2127. static void rtw_coex_run_coex(struct rtw_dev *rtwdev, u8 reason)
  2128. {
  2129. const struct rtw_chip_info *chip = rtwdev->chip;
  2130. struct rtw_coex *coex = &rtwdev->coex;
  2131. struct rtw_coex_dm *coex_dm = &coex->dm;
  2132. struct rtw_coex_stat *coex_stat = &coex->stat;
  2133. bool rf4ce_en = false;
  2134. lockdep_assert_held(&rtwdev->mutex);
  2135. if (!test_bit(RTW_FLAG_RUNNING, rtwdev->flags))
  2136. return;
  2137. coex_dm->reason = reason;
  2138. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(): reason = %d\n", __func__,
  2139. reason);
  2140. /* update wifi_link_info_ext variable */
  2141. rtw_coex_update_wl_link_info(rtwdev, reason);
  2142. rtw_coex_monitor_bt_enable(rtwdev);
  2143. if (coex->manual_control) {
  2144. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2145. "[BTCoex], return for Manual CTRL!!\n");
  2146. return;
  2147. }
  2148. if (coex->stop_dm) {
  2149. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2150. "[BTCoex], return for Stop Coex DM!!\n");
  2151. return;
  2152. }
  2153. if (coex_stat->wl_under_ips) {
  2154. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2155. "[BTCoex], return for wifi is under IPS!!\n");
  2156. return;
  2157. }
  2158. if (coex->freeze && coex_dm->reason == COEX_RSN_BTINFO &&
  2159. !coex_stat->bt_setup_link) {
  2160. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2161. "[BTCoex], return for coex_freeze!!\n");
  2162. return;
  2163. }
  2164. coex_stat->cnt_wl[COEX_CNT_WL_COEXRUN]++;
  2165. coex->freerun = false;
  2166. /* Pure-5G Coex Process */
  2167. if (coex->under_5g) {
  2168. coex_stat->wl_coex_mode = COEX_WLINK_5G;
  2169. rtw_coex_action_wl_under5g(rtwdev);
  2170. goto exit;
  2171. }
  2172. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], WiFi is single-port 2G!!\n");
  2173. coex_stat->wl_coex_mode = COEX_WLINK_2G1PORT;
  2174. if (coex_stat->bt_disabled) {
  2175. if (coex_stat->wl_connected && rf4ce_en)
  2176. rtw_coex_action_rf4ce(rtwdev);
  2177. else if (!coex_stat->wl_connected)
  2178. rtw_coex_action_wl_not_connected(rtwdev);
  2179. else
  2180. rtw_coex_action_wl_only(rtwdev);
  2181. goto exit;
  2182. }
  2183. if (coex_stat->wl_under_lps && !coex_stat->wl_force_lps_ctrl) {
  2184. rtw_coex_action_wl_native_lps(rtwdev);
  2185. goto exit;
  2186. }
  2187. if (coex_stat->bt_game_hid_exist && coex_stat->wl_connected) {
  2188. rtw_coex_action_bt_game_hid(rtwdev);
  2189. goto exit;
  2190. }
  2191. if (coex_stat->bt_whck_test) {
  2192. rtw_coex_action_bt_whql_test(rtwdev);
  2193. goto exit;
  2194. }
  2195. if (coex_stat->bt_setup_link) {
  2196. rtw_coex_action_bt_relink(rtwdev);
  2197. goto exit;
  2198. }
  2199. if (coex_stat->bt_inq_page) {
  2200. rtw_coex_action_bt_inquiry(rtwdev);
  2201. goto exit;
  2202. }
  2203. if ((coex_dm->bt_status == COEX_BTSTATUS_NCON_IDLE ||
  2204. coex_dm->bt_status == COEX_BTSTATUS_CON_IDLE) &&
  2205. coex_stat->wl_connected) {
  2206. rtw_coex_action_bt_idle(rtwdev);
  2207. goto exit;
  2208. }
  2209. if (coex_stat->wl_linkscan_proc && !coex->freerun) {
  2210. rtw_coex_action_wl_linkscan(rtwdev);
  2211. goto exit;
  2212. }
  2213. if (coex_stat->wl_connected) {
  2214. rtw_coex_action_wl_connected(rtwdev);
  2215. goto exit;
  2216. } else {
  2217. rtw_coex_action_wl_not_connected(rtwdev);
  2218. goto exit;
  2219. }
  2220. exit:
  2221. if (chip->wl_mimo_ps_support) {
  2222. if (coex_stat->wl_coex_mode == COEX_WLINK_2GFREE) {
  2223. if (coex_dm->reason == COEX_RSN_2GMEDIA)
  2224. rtw_coex_mimo_ps(rtwdev, true, true);
  2225. else
  2226. rtw_coex_mimo_ps(rtwdev, false, true);
  2227. } else {
  2228. rtw_coex_mimo_ps(rtwdev, false, false);
  2229. }
  2230. }
  2231. rtw_coex_gnt_workaround(rtwdev, false, coex_stat->wl_coex_mode);
  2232. rtw_coex_limited_wl(rtwdev);
  2233. }
  2234. static void rtw_coex_init_coex_var(struct rtw_dev *rtwdev)
  2235. {
  2236. struct rtw_coex *coex = &rtwdev->coex;
  2237. struct rtw_coex_stat *coex_stat = &coex->stat;
  2238. struct rtw_coex_dm *coex_dm = &coex->dm;
  2239. u8 i;
  2240. memset(coex_dm, 0, sizeof(*coex_dm));
  2241. memset(coex_stat, 0, sizeof(*coex_stat));
  2242. for (i = 0; i < COEX_CNT_WL_MAX; i++)
  2243. coex_stat->cnt_wl[i] = 0;
  2244. for (i = 0; i < COEX_CNT_BT_MAX; i++)
  2245. coex_stat->cnt_bt[i] = 0;
  2246. for (i = 0; i < ARRAY_SIZE(coex_dm->bt_rssi_state); i++)
  2247. coex_dm->bt_rssi_state[i] = COEX_RSSI_STATE_LOW;
  2248. for (i = 0; i < ARRAY_SIZE(coex_dm->wl_rssi_state); i++)
  2249. coex_dm->wl_rssi_state[i] = COEX_RSSI_STATE_LOW;
  2250. coex_stat->wl_coex_mode = COEX_WLINK_MAX;
  2251. coex_stat->wl_rx_rate = DESC_RATE5_5M;
  2252. coex_stat->wl_rts_rx_rate = DESC_RATE5_5M;
  2253. }
  2254. static void __rtw_coex_init_hw_config(struct rtw_dev *rtwdev, bool wifi_only)
  2255. {
  2256. struct rtw_coex *coex = &rtwdev->coex;
  2257. struct rtw_coex_stat *coex_stat = &coex->stat;
  2258. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  2259. rtw_coex_init_coex_var(rtwdev);
  2260. coex_stat->kt_ver = u8_get_bits(rtw_read8(rtwdev, 0xf1), GENMASK(7, 4));
  2261. rtw_coex_monitor_bt_enable(rtwdev);
  2262. rtw_coex_wl_slot_extend(rtwdev, coex_stat->wl_slot_extend);
  2263. rtw_write8_set(rtwdev, REG_BCN_CTRL, BIT_EN_BCN_FUNCTION);
  2264. rtw_coex_set_rfe_type(rtwdev);
  2265. rtw_coex_set_init(rtwdev);
  2266. /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */
  2267. rtw_coex_set_wl_pri_mask(rtwdev, COEX_WLPRI_TX_RSP, 1);
  2268. /* set Tx beacon = Hi-Pri */
  2269. rtw_coex_set_wl_pri_mask(rtwdev, COEX_WLPRI_TX_BEACON, 1);
  2270. /* set Tx beacon queue = Hi-Pri */
  2271. rtw_coex_set_wl_pri_mask(rtwdev, COEX_WLPRI_TX_BEACONQ, 1);
  2272. /* antenna config */
  2273. if (coex->wl_rf_off) {
  2274. rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_WOFF);
  2275. rtw_coex_write_scbd(rtwdev, COEX_SCBD_ALL, false);
  2276. coex->stop_dm = true;
  2277. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(): RF Off\n",
  2278. __func__);
  2279. } else if (wifi_only) {
  2280. rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_WONLY);
  2281. rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE | COEX_SCBD_ONOFF,
  2282. true);
  2283. coex->stop_dm = true;
  2284. } else {
  2285. rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_INIT);
  2286. rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE | COEX_SCBD_ONOFF,
  2287. true);
  2288. coex->stop_dm = false;
  2289. coex->freeze = true;
  2290. }
  2291. /* PTA parameter */
  2292. rtw_coex_table(rtwdev, true, 1);
  2293. rtw_coex_tdma(rtwdev, true, 0);
  2294. rtw_coex_query_bt_info(rtwdev);
  2295. }
  2296. void rtw_coex_power_on_setting(struct rtw_dev *rtwdev)
  2297. {
  2298. struct rtw_coex *coex = &rtwdev->coex;
  2299. u8 table_case = 1;
  2300. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  2301. coex->stop_dm = true;
  2302. coex->wl_rf_off = false;
  2303. /* enable BB, we can write 0x948 */
  2304. rtw_write8_set(rtwdev, REG_SYS_FUNC_EN,
  2305. BIT_FEN_BB_GLB_RST | BIT_FEN_BB_RSTB);
  2306. rtw_coex_monitor_bt_enable(rtwdev);
  2307. rtw_coex_set_rfe_type(rtwdev);
  2308. /* set antenna path to BT */
  2309. rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_POWERON);
  2310. rtw_coex_table(rtwdev, true, table_case);
  2311. /* red x issue */
  2312. rtw_write8(rtwdev, 0xff1a, 0x0);
  2313. rtw_coex_set_gnt_debug(rtwdev);
  2314. }
  2315. EXPORT_SYMBOL(rtw_coex_power_on_setting);
  2316. void rtw_coex_power_off_setting(struct rtw_dev *rtwdev)
  2317. {
  2318. rtw_write16(rtwdev, REG_WIFI_BT_INFO, BIT_BT_INT_EN);
  2319. }
  2320. EXPORT_SYMBOL(rtw_coex_power_off_setting);
  2321. void rtw_coex_init_hw_config(struct rtw_dev *rtwdev, bool wifi_only)
  2322. {
  2323. __rtw_coex_init_hw_config(rtwdev, wifi_only);
  2324. }
  2325. EXPORT_SYMBOL(rtw_coex_init_hw_config);
  2326. void rtw_coex_ips_notify(struct rtw_dev *rtwdev, u8 type)
  2327. {
  2328. struct rtw_coex *coex = &rtwdev->coex;
  2329. struct rtw_coex_stat *coex_stat = &coex->stat;
  2330. if (coex->manual_control || coex->stop_dm)
  2331. return;
  2332. if (type == COEX_IPS_ENTER) {
  2333. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], IPS ENTER notify\n");
  2334. coex_stat->wl_under_ips = true;
  2335. /* for lps off */
  2336. rtw_coex_write_scbd(rtwdev, COEX_SCBD_ALL, false);
  2337. rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_WOFF);
  2338. rtw_coex_action_coex_all_off(rtwdev);
  2339. } else if (type == COEX_IPS_LEAVE) {
  2340. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], IPS LEAVE notify\n");
  2341. rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE | COEX_SCBD_ONOFF, true);
  2342. /* run init hw config (exclude wifi only) */
  2343. __rtw_coex_init_hw_config(rtwdev, false);
  2344. coex_stat->wl_under_ips = false;
  2345. }
  2346. }
  2347. void rtw_coex_lps_notify(struct rtw_dev *rtwdev, u8 type)
  2348. {
  2349. struct rtw_coex *coex = &rtwdev->coex;
  2350. struct rtw_coex_stat *coex_stat = &coex->stat;
  2351. if (coex->manual_control || coex->stop_dm)
  2352. return;
  2353. if (type == COEX_LPS_ENABLE) {
  2354. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], LPS ENABLE notify\n");
  2355. coex_stat->wl_under_lps = true;
  2356. if (coex_stat->wl_force_lps_ctrl) {
  2357. /* for ps-tdma */
  2358. rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE, true);
  2359. } else {
  2360. /* for native ps */
  2361. rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE, false);
  2362. rtw_coex_write_scbd(rtwdev, COEX_SCBD_WLBUSY, false);
  2363. rtw_coex_run_coex(rtwdev, COEX_RSN_LPS);
  2364. }
  2365. } else if (type == COEX_LPS_DISABLE) {
  2366. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], LPS DISABLE notify\n");
  2367. coex_stat->wl_under_lps = false;
  2368. /* for lps off */
  2369. rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE, true);
  2370. if (!coex_stat->wl_force_lps_ctrl)
  2371. rtw_coex_query_bt_info(rtwdev);
  2372. rtw_coex_run_coex(rtwdev, COEX_RSN_LPS);
  2373. }
  2374. }
  2375. void rtw_coex_scan_notify(struct rtw_dev *rtwdev, u8 type)
  2376. {
  2377. struct rtw_coex *coex = &rtwdev->coex;
  2378. struct rtw_coex_stat *coex_stat = &coex->stat;
  2379. if (coex->manual_control || coex->stop_dm)
  2380. return;
  2381. coex->freeze = false;
  2382. rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE | COEX_SCBD_ONOFF, true);
  2383. if (type == COEX_SCAN_START_5G) {
  2384. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2385. "[BTCoex], SCAN START notify (5G)\n");
  2386. rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_5G);
  2387. rtw_coex_run_coex(rtwdev, COEX_RSN_5GSCANSTART);
  2388. } else if ((type == COEX_SCAN_START_2G) || (type == COEX_SCAN_START)) {
  2389. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2390. "[BTCoex], SCAN START notify (2G)\n");
  2391. coex_stat->wl_hi_pri_task2 = true;
  2392. /* Force antenna setup for no scan result issue */
  2393. rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_2G);
  2394. rtw_coex_run_coex(rtwdev, COEX_RSN_2GSCANSTART);
  2395. } else {
  2396. coex_stat->cnt_wl[COEX_CNT_WL_SCANAP] = 30; /* To do */
  2397. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2398. "[BTCoex], SCAN FINISH notify (Scan-AP = %d)\n",
  2399. coex_stat->cnt_wl[COEX_CNT_WL_SCANAP]);
  2400. coex_stat->wl_hi_pri_task2 = false;
  2401. rtw_coex_run_coex(rtwdev, COEX_RSN_SCANFINISH);
  2402. }
  2403. }
  2404. void rtw_coex_switchband_notify(struct rtw_dev *rtwdev, u8 type)
  2405. {
  2406. struct rtw_coex *coex = &rtwdev->coex;
  2407. if (coex->manual_control || coex->stop_dm)
  2408. return;
  2409. if (type == COEX_SWITCH_TO_5G) {
  2410. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(): TO_5G\n",
  2411. __func__);
  2412. } else if (type == COEX_SWITCH_TO_24G_NOFORSCAN) {
  2413. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2414. "[BTCoex], %s(): TO_24G_NOFORSCAN\n", __func__);
  2415. } else {
  2416. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(): TO_2G\n",
  2417. __func__);
  2418. }
  2419. if (type == COEX_SWITCH_TO_5G)
  2420. rtw_coex_run_coex(rtwdev, COEX_RSN_5GSWITCHBAND);
  2421. else if (type == COEX_SWITCH_TO_24G_NOFORSCAN)
  2422. rtw_coex_run_coex(rtwdev, COEX_RSN_2GSWITCHBAND);
  2423. else
  2424. rtw_coex_scan_notify(rtwdev, COEX_SCAN_START_2G);
  2425. }
  2426. void rtw_coex_connect_notify(struct rtw_dev *rtwdev, u8 type)
  2427. {
  2428. struct rtw_coex *coex = &rtwdev->coex;
  2429. struct rtw_coex_stat *coex_stat = &coex->stat;
  2430. if (coex->manual_control || coex->stop_dm)
  2431. return;
  2432. rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE | COEX_SCBD_ONOFF, true);
  2433. if (type == COEX_ASSOCIATE_5G_START) {
  2434. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(): 5G start\n",
  2435. __func__);
  2436. rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_5G);
  2437. rtw_coex_run_coex(rtwdev, COEX_RSN_5GCONSTART);
  2438. } else if (type == COEX_ASSOCIATE_5G_FINISH) {
  2439. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(): 5G finish\n",
  2440. __func__);
  2441. rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_5G);
  2442. rtw_coex_run_coex(rtwdev, COEX_RSN_5GCONFINISH);
  2443. } else if (type == COEX_ASSOCIATE_START) {
  2444. coex_stat->wl_hi_pri_task1 = true;
  2445. coex_stat->wl_connecting = true;
  2446. coex_stat->cnt_wl[COEX_CNT_WL_CONNPKT] = 2;
  2447. coex_stat->wl_connecting = true;
  2448. ieee80211_queue_delayed_work(rtwdev->hw,
  2449. &coex->wl_connecting_work, 2 * HZ);
  2450. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(): 2G start\n",
  2451. __func__);
  2452. /* Force antenna setup for no scan result issue */
  2453. rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_2G);
  2454. rtw_coex_run_coex(rtwdev, COEX_RSN_2GCONSTART);
  2455. /* To keep TDMA case during connect process,
  2456. * to avoid changed by Btinfo and runcoexmechanism
  2457. */
  2458. coex->freeze = true;
  2459. ieee80211_queue_delayed_work(rtwdev->hw, &coex->defreeze_work,
  2460. 5 * HZ);
  2461. } else {
  2462. coex_stat->wl_hi_pri_task1 = false;
  2463. coex->freeze = false;
  2464. coex_stat->wl_connecting = false;
  2465. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(): 2G finish\n",
  2466. __func__);
  2467. rtw_coex_run_coex(rtwdev, COEX_RSN_2GCONFINISH);
  2468. }
  2469. }
  2470. void rtw_coex_media_status_notify(struct rtw_dev *rtwdev, u8 type)
  2471. {
  2472. struct rtw_coex *coex = &rtwdev->coex;
  2473. struct rtw_coex_stat *coex_stat = &coex->stat;
  2474. if (coex->manual_control || coex->stop_dm)
  2475. return;
  2476. if (type == COEX_MEDIA_CONNECT_5G) {
  2477. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(): 5G\n", __func__);
  2478. rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE, true);
  2479. rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_5G);
  2480. rtw_coex_run_coex(rtwdev, COEX_RSN_5GMEDIA);
  2481. } else if (type == COEX_MEDIA_CONNECT) {
  2482. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(): 2G\n", __func__);
  2483. coex_stat->wl_connecting = false;
  2484. rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE, true);
  2485. /* Force antenna setup for no scan result issue */
  2486. rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_2G);
  2487. /* Set CCK Rx high Pri */
  2488. rtw_coex_set_wl_pri_mask(rtwdev, COEX_WLPRI_RX_CCK, 1);
  2489. rtw_coex_run_coex(rtwdev, COEX_RSN_2GMEDIA);
  2490. } else {
  2491. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s(): disconnect!!\n",
  2492. __func__);
  2493. rtw_coex_set_wl_pri_mask(rtwdev, COEX_WLPRI_RX_CCK, 0);
  2494. rtw_coex_run_coex(rtwdev, COEX_RSN_MEDIADISCON);
  2495. }
  2496. rtw_coex_update_wl_ch_info(rtwdev, type);
  2497. }
  2498. void rtw_coex_bt_info_notify(struct rtw_dev *rtwdev, u8 *buf, u8 length)
  2499. {
  2500. const struct rtw_chip_info *chip = rtwdev->chip;
  2501. struct rtw_coex *coex = &rtwdev->coex;
  2502. struct rtw_coex_stat *coex_stat = &coex->stat;
  2503. struct rtw_coex_dm *coex_dm = &coex->dm;
  2504. u32 bt_relink_time;
  2505. u8 i, rsp_source = 0, type;
  2506. bool inq_page = false;
  2507. rsp_source = buf[0] & 0xf;
  2508. if (rsp_source >= COEX_BTINFO_SRC_MAX)
  2509. return;
  2510. coex_stat->cnt_bt_info_c2h[rsp_source]++;
  2511. if (rsp_source == COEX_BTINFO_SRC_BT_IQK) {
  2512. coex_stat->bt_iqk_state = buf[1];
  2513. if (coex_stat->bt_iqk_state == 0)
  2514. coex_stat->cnt_bt[COEX_CNT_BT_IQK]++;
  2515. else if (coex_stat->bt_iqk_state == 2)
  2516. coex_stat->cnt_bt[COEX_CNT_BT_IQKFAIL]++;
  2517. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2518. "[BTCoex], BT IQK by bt_info, data0 = 0x%02x\n",
  2519. buf[1]);
  2520. return;
  2521. }
  2522. if (rsp_source == COEX_BTINFO_SRC_BT_SCBD) {
  2523. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2524. "[BTCoex], BT Scoreboard change notify by WL FW c2h, 0xaa = 0x%02x, 0xab = 0x%02x\n",
  2525. buf[1], buf[2]);
  2526. rtw_coex_monitor_bt_enable(rtwdev);
  2527. if (coex_stat->bt_disabled != coex_stat->bt_disabled_pre) {
  2528. coex_stat->bt_disabled_pre = coex_stat->bt_disabled;
  2529. rtw_coex_run_coex(rtwdev, COEX_RSN_BTINFO);
  2530. }
  2531. return;
  2532. }
  2533. if (rsp_source == COEX_BTINFO_SRC_H2C60) {
  2534. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2535. "[BTCoex], H2C 0x60 content replied by WL FW: H2C_0x60 = [%02x %02x %02x %02x %02x]\n",
  2536. buf[1], buf[2], buf[3], buf[4], buf[5]);
  2537. for (i = 1; i <= COEX_WL_TDMA_PARA_LENGTH; i++)
  2538. coex_dm->fw_tdma_para[i - 1] = buf[i];
  2539. return;
  2540. }
  2541. if (rsp_source == COEX_BTINFO_SRC_WL_FW) {
  2542. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2543. "[BTCoex], bt_info reply by WL FW\n");
  2544. rtw_coex_update_bt_link_info(rtwdev);
  2545. return;
  2546. }
  2547. if (rsp_source == COEX_BTINFO_SRC_BT_RSP ||
  2548. rsp_source == COEX_BTINFO_SRC_BT_ACT) {
  2549. if (coex_stat->bt_disabled) {
  2550. coex_stat->bt_disabled = false;
  2551. coex_stat->bt_reenable = true;
  2552. ieee80211_queue_delayed_work(rtwdev->hw,
  2553. &coex->bt_reenable_work,
  2554. 15 * HZ);
  2555. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2556. "[BTCoex], BT enable detected by bt_info\n");
  2557. }
  2558. }
  2559. if (length != COEX_BTINFO_LENGTH) {
  2560. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2561. "[BTCoex], Bt_info length = %d invalid!!\n", length);
  2562. return;
  2563. }
  2564. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2565. "[BTCoex], Bt_info[%d], len=%d, data=[%02x %02x %02x %02x %02x %02x]\n",
  2566. buf[0], length, buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
  2567. for (i = 0; i < COEX_BTINFO_LENGTH; i++)
  2568. coex_stat->bt_info_c2h[rsp_source][i] = buf[i];
  2569. /* get the same info from bt, skip it */
  2570. if (coex_stat->bt_info_c2h[rsp_source][1] == coex_stat->bt_info_lb2 &&
  2571. coex_stat->bt_info_c2h[rsp_source][2] == coex_stat->bt_info_lb3 &&
  2572. coex_stat->bt_info_c2h[rsp_source][3] == coex_stat->bt_info_hb0 &&
  2573. coex_stat->bt_info_c2h[rsp_source][4] == coex_stat->bt_info_hb1 &&
  2574. coex_stat->bt_info_c2h[rsp_source][5] == coex_stat->bt_info_hb2 &&
  2575. coex_stat->bt_info_c2h[rsp_source][6] == coex_stat->bt_info_hb3) {
  2576. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2577. "[BTCoex], Return because Btinfo duplicate!!\n");
  2578. return;
  2579. }
  2580. coex_stat->bt_info_lb2 = coex_stat->bt_info_c2h[rsp_source][1];
  2581. coex_stat->bt_info_lb3 = coex_stat->bt_info_c2h[rsp_source][2];
  2582. coex_stat->bt_info_hb0 = coex_stat->bt_info_c2h[rsp_source][3];
  2583. coex_stat->bt_info_hb1 = coex_stat->bt_info_c2h[rsp_source][4];
  2584. coex_stat->bt_info_hb2 = coex_stat->bt_info_c2h[rsp_source][5];
  2585. coex_stat->bt_info_hb3 = coex_stat->bt_info_c2h[rsp_source][6];
  2586. /* 0xff means BT is under WHCK test */
  2587. coex_stat->bt_whck_test = (coex_stat->bt_info_lb2 == 0xff);
  2588. inq_page = ((coex_stat->bt_info_lb2 & BIT(2)) == BIT(2));
  2589. if (inq_page != coex_stat->bt_inq_page) {
  2590. cancel_delayed_work_sync(&coex->bt_remain_work);
  2591. coex_stat->bt_inq_page = inq_page;
  2592. if (inq_page)
  2593. coex_stat->bt_inq_remain = true;
  2594. else
  2595. ieee80211_queue_delayed_work(rtwdev->hw,
  2596. &coex->bt_remain_work,
  2597. 4 * HZ);
  2598. }
  2599. coex_stat->bt_acl_busy = ((coex_stat->bt_info_lb2 & BIT(3)) == BIT(3));
  2600. if (chip->ble_hid_profile_support) {
  2601. if (coex_stat->bt_info_lb2 & BIT(5)) {
  2602. if (coex_stat->bt_info_hb1 & BIT(0)) {
  2603. /*BLE HID*/
  2604. coex_stat->bt_ble_hid_exist = true;
  2605. } else {
  2606. coex_stat->bt_ble_hid_exist = false;
  2607. }
  2608. coex_stat->bt_ble_exist = false;
  2609. } else if (coex_stat->bt_info_hb1 & BIT(0)) {
  2610. /*RCU*/
  2611. coex_stat->bt_ble_hid_exist = false;
  2612. coex_stat->bt_ble_exist = true;
  2613. } else {
  2614. coex_stat->bt_ble_hid_exist = false;
  2615. coex_stat->bt_ble_exist = false;
  2616. }
  2617. } else {
  2618. if (coex_stat->bt_info_hb1 & BIT(0)) {
  2619. if (coex_stat->bt_hid_slot == 1 &&
  2620. coex_stat->hi_pri_rx + 100 < coex_stat->hi_pri_tx &&
  2621. coex_stat->hi_pri_rx < 100) {
  2622. coex_stat->bt_ble_hid_exist = true;
  2623. coex_stat->bt_ble_exist = false;
  2624. } else {
  2625. coex_stat->bt_ble_hid_exist = false;
  2626. coex_stat->bt_ble_exist = true;
  2627. }
  2628. } else {
  2629. coex_stat->bt_ble_hid_exist = false;
  2630. coex_stat->bt_ble_exist = false;
  2631. }
  2632. }
  2633. coex_stat->cnt_bt[COEX_CNT_BT_RETRY] = coex_stat->bt_info_lb3 & 0xf;
  2634. if (coex_stat->cnt_bt[COEX_CNT_BT_RETRY] >= 1)
  2635. coex_stat->cnt_bt[COEX_CNT_BT_POPEVENT]++;
  2636. coex_stat->bt_fix_2M = ((coex_stat->bt_info_lb3 & BIT(4)) == BIT(4));
  2637. coex_stat->bt_inq = ((coex_stat->bt_info_lb3 & BIT(5)) == BIT(5));
  2638. if (coex_stat->bt_inq)
  2639. coex_stat->cnt_bt[COEX_CNT_BT_INQ]++;
  2640. coex_stat->bt_page = ((coex_stat->bt_info_lb3 & BIT(7)) == BIT(7));
  2641. if (coex_stat->bt_page)
  2642. coex_stat->cnt_bt[COEX_CNT_BT_PAGE]++;
  2643. /* unit: % (value-100 to translate to unit: dBm in coex info) */
  2644. if (chip->bt_rssi_type == COEX_BTRSSI_RATIO) {
  2645. coex_stat->bt_rssi = coex_stat->bt_info_hb0 * 2 + 10;
  2646. } else {
  2647. if (coex_stat->bt_info_hb0 <= 127)
  2648. coex_stat->bt_rssi = 100;
  2649. else if (256 - coex_stat->bt_info_hb0 <= 100)
  2650. coex_stat->bt_rssi = 100 - (256 - coex_stat->bt_info_hb0);
  2651. else
  2652. coex_stat->bt_rssi = 0;
  2653. }
  2654. if (coex_stat->bt_info_hb1 & BIT(1))
  2655. coex_stat->cnt_bt[COEX_CNT_BT_REINIT]++;
  2656. if (coex_stat->bt_info_hb1 & BIT(2)) {
  2657. coex_stat->cnt_bt[COEX_CNT_BT_SETUPLINK]++;
  2658. coex_stat->bt_setup_link = true;
  2659. if (coex_stat->bt_reenable)
  2660. bt_relink_time = 6 * HZ;
  2661. else
  2662. bt_relink_time = 1 * HZ;
  2663. ieee80211_queue_delayed_work(rtwdev->hw,
  2664. &coex->bt_relink_work,
  2665. bt_relink_time);
  2666. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2667. "[BTCoex], Re-Link start in BT info!!\n");
  2668. }
  2669. if (coex_stat->bt_info_hb1 & BIT(3))
  2670. coex_stat->cnt_bt[COEX_CNT_BT_IGNWLANACT]++;
  2671. coex_stat->bt_ble_voice = ((coex_stat->bt_info_hb1 & BIT(4)) == BIT(4));
  2672. coex_stat->bt_ble_scan_en = ((coex_stat->bt_info_hb1 & BIT(5)) == BIT(5));
  2673. if (coex_stat->bt_info_hb1 & BIT(6))
  2674. coex_stat->cnt_bt[COEX_CNT_BT_ROLESWITCH]++;
  2675. coex_stat->bt_multi_link = ((coex_stat->bt_info_hb1 & BIT(7)) == BIT(7));
  2676. /* for multi_link = 0 but bt pkt remain exist */
  2677. /* Use PS-TDMA to protect WL RX */
  2678. if (!coex_stat->bt_multi_link && coex_stat->bt_multi_link_pre) {
  2679. coex_stat->bt_multi_link_remain = true;
  2680. ieee80211_queue_delayed_work(rtwdev->hw,
  2681. &coex->bt_multi_link_remain_work,
  2682. 3 * HZ);
  2683. }
  2684. coex_stat->bt_multi_link_pre = coex_stat->bt_multi_link;
  2685. /* resend wifi info to bt, it is reset and lost the info */
  2686. if (coex_stat->bt_info_hb1 & BIT(1)) {
  2687. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2688. "[BTCoex], BT Re-init, send wifi BW & Chnl to BT!!\n");
  2689. if (coex_stat->wl_connected)
  2690. type = COEX_MEDIA_CONNECT;
  2691. else
  2692. type = COEX_MEDIA_DISCONNECT;
  2693. rtw_coex_update_wl_ch_info(rtwdev, type);
  2694. }
  2695. /* if ignore_wlan_act && not set_up_link */
  2696. if ((coex_stat->bt_info_hb1 & BIT(3)) &&
  2697. (!(coex_stat->bt_info_hb1 & BIT(2)))) {
  2698. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2699. "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
  2700. rtw_coex_ignore_wlan_act(rtwdev, false);
  2701. }
  2702. coex_stat->bt_opp_exist = ((coex_stat->bt_info_hb2 & BIT(0)) == BIT(0));
  2703. if (coex_stat->bt_info_hb2 & BIT(1))
  2704. coex_stat->cnt_bt[COEX_CNT_BT_AFHUPDATE]++;
  2705. coex_stat->bt_a2dp_active = (coex_stat->bt_info_hb2 & BIT(2)) == BIT(2);
  2706. coex_stat->bt_slave = ((coex_stat->bt_info_hb2 & BIT(3)) == BIT(3));
  2707. coex_stat->bt_hid_slot = (coex_stat->bt_info_hb2 & 0x30) >> 4;
  2708. coex_stat->bt_hid_pair_num = (coex_stat->bt_info_hb2 & 0xc0) >> 6;
  2709. if (coex_stat->bt_hid_pair_num > 0 && coex_stat->bt_hid_slot >= 2)
  2710. coex_stat->bt_418_hid_exist = true;
  2711. else if (coex_stat->bt_hid_pair_num == 0 || coex_stat->bt_hid_slot == 1)
  2712. coex_stat->bt_418_hid_exist = false;
  2713. if ((coex_stat->bt_info_lb2 & 0x49) == 0x49)
  2714. coex_stat->bt_a2dp_bitpool = (coex_stat->bt_info_hb3 & 0x7f);
  2715. else
  2716. coex_stat->bt_a2dp_bitpool = 0;
  2717. coex_stat->bt_a2dp_sink = ((coex_stat->bt_info_hb3 & BIT(7)) == BIT(7));
  2718. rtw_coex_update_bt_link_info(rtwdev);
  2719. rtw_coex_run_coex(rtwdev, COEX_RSN_BTINFO);
  2720. }
  2721. #define COEX_BT_HIDINFO_MTK 0x46
  2722. static const u8 coex_bt_hidinfo_ps[] = {0x57, 0x69, 0x72};
  2723. static const u8 coex_bt_hidinfo_xb[] = {0x58, 0x62, 0x6f};
  2724. void rtw_coex_bt_hid_info_notify(struct rtw_dev *rtwdev, u8 *buf, u8 length)
  2725. {
  2726. const struct rtw_chip_info *chip = rtwdev->chip;
  2727. struct rtw_coex *coex = &rtwdev->coex;
  2728. struct rtw_coex_stat *coex_stat = &coex->stat;
  2729. struct rtw_coex_hid *hidinfo;
  2730. struct rtw_coex_hid_info_a *hida;
  2731. struct rtw_coex_hid_handle_list *hl, *bhl;
  2732. u8 sub_id = buf[2], gamehid_cnt = 0, handle, i;
  2733. bool cur_game_hid_exist, complete;
  2734. if (!chip->wl_mimo_ps_support &&
  2735. (sub_id == COEX_BT_HIDINFO_LIST || sub_id == COEX_BT_HIDINFO_A))
  2736. return;
  2737. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2738. "[BTCoex], HID info notify, sub_id = 0x%x\n", sub_id);
  2739. switch (sub_id) {
  2740. case COEX_BT_HIDINFO_LIST:
  2741. hl = &coex_stat->hid_handle_list;
  2742. bhl = (struct rtw_coex_hid_handle_list *)buf;
  2743. if (!memcmp(hl, bhl, sizeof(*hl)))
  2744. return;
  2745. coex_stat->hid_handle_list = *bhl;
  2746. memset(&coex_stat->hid_info, 0, sizeof(coex_stat->hid_info));
  2747. for (i = 0; i < COEX_BT_HIDINFO_HANDLE_NUM; i++) {
  2748. hidinfo = &coex_stat->hid_info[i];
  2749. if (hl->handle[i] != COEX_BT_HIDINFO_NOTCON &&
  2750. hl->handle[i] != 0)
  2751. hidinfo->hid_handle = hl->handle[i];
  2752. }
  2753. break;
  2754. case COEX_BT_HIDINFO_A:
  2755. hida = (struct rtw_coex_hid_info_a *)buf;
  2756. handle = hida->handle;
  2757. for (i = 0; i < COEX_BT_HIDINFO_HANDLE_NUM; i++) {
  2758. hidinfo = &coex_stat->hid_info[i];
  2759. if (hidinfo->hid_handle == handle) {
  2760. hidinfo->hid_vendor = hida->vendor;
  2761. memcpy(hidinfo->hid_name, hida->name,
  2762. sizeof(hidinfo->hid_name));
  2763. hidinfo->hid_info_completed = true;
  2764. break;
  2765. }
  2766. }
  2767. break;
  2768. }
  2769. for (i = 0; i < COEX_BT_HIDINFO_HANDLE_NUM; i++) {
  2770. hidinfo = &coex_stat->hid_info[i];
  2771. complete = hidinfo->hid_info_completed;
  2772. handle = hidinfo->hid_handle;
  2773. if (!complete || handle == COEX_BT_HIDINFO_NOTCON ||
  2774. handle == 0 || handle >= COEX_BT_BLE_HANDLE_THRS) {
  2775. hidinfo->is_game_hid = false;
  2776. continue;
  2777. }
  2778. if (hidinfo->hid_vendor == COEX_BT_HIDINFO_MTK) {
  2779. if ((memcmp(hidinfo->hid_name,
  2780. coex_bt_hidinfo_ps,
  2781. COEX_BT_HIDINFO_NAME)) == 0)
  2782. hidinfo->is_game_hid = true;
  2783. else if ((memcmp(hidinfo->hid_name,
  2784. coex_bt_hidinfo_xb,
  2785. COEX_BT_HIDINFO_NAME)) == 0)
  2786. hidinfo->is_game_hid = true;
  2787. else
  2788. hidinfo->is_game_hid = false;
  2789. } else {
  2790. hidinfo->is_game_hid = false;
  2791. }
  2792. if (hidinfo->is_game_hid)
  2793. gamehid_cnt++;
  2794. }
  2795. if (gamehid_cnt > 0)
  2796. cur_game_hid_exist = true;
  2797. else
  2798. cur_game_hid_exist = false;
  2799. if (cur_game_hid_exist != coex_stat->bt_game_hid_exist) {
  2800. coex_stat->bt_game_hid_exist = cur_game_hid_exist;
  2801. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2802. "[BTCoex], HID info changed!bt_game_hid_exist = %d!\n",
  2803. coex_stat->bt_game_hid_exist);
  2804. rtw_coex_run_coex(rtwdev, COEX_RSN_BTSTATUS);
  2805. }
  2806. }
  2807. void rtw_coex_query_bt_hid_list(struct rtw_dev *rtwdev)
  2808. {
  2809. const struct rtw_chip_info *chip = rtwdev->chip;
  2810. struct rtw_coex *coex = &rtwdev->coex;
  2811. struct rtw_coex_stat *coex_stat = &coex->stat;
  2812. struct rtw_coex_hid *hidinfo;
  2813. u8 i, handle;
  2814. bool complete;
  2815. if (!chip->wl_mimo_ps_support || coex_stat->wl_under_ips ||
  2816. (coex_stat->wl_under_lps && !coex_stat->wl_force_lps_ctrl))
  2817. return;
  2818. if (!coex_stat->bt_hid_exist &&
  2819. !((coex_stat->bt_info_lb2 & COEX_INFO_CONNECTION) &&
  2820. (coex_stat->hi_pri_tx + coex_stat->hi_pri_rx >
  2821. COEX_BT_GAMEHID_CNT)))
  2822. return;
  2823. rtw_fw_coex_query_hid_info(rtwdev, COEX_BT_HIDINFO_LIST, 0);
  2824. for (i = 0; i < COEX_BT_HIDINFO_HANDLE_NUM; i++) {
  2825. hidinfo = &coex_stat->hid_info[i];
  2826. complete = hidinfo->hid_info_completed;
  2827. handle = hidinfo->hid_handle;
  2828. if (handle == 0 || handle == COEX_BT_HIDINFO_NOTCON ||
  2829. handle >= COEX_BT_BLE_HANDLE_THRS || complete)
  2830. continue;
  2831. rtw_fw_coex_query_hid_info(rtwdev,
  2832. COEX_BT_HIDINFO_A,
  2833. handle);
  2834. }
  2835. }
  2836. void rtw_coex_wl_fwdbginfo_notify(struct rtw_dev *rtwdev, u8 *buf, u8 length)
  2837. {
  2838. struct rtw_coex *coex = &rtwdev->coex;
  2839. struct rtw_coex_stat *coex_stat = &coex->stat;
  2840. u8 val;
  2841. int i;
  2842. rtw_dbg(rtwdev, RTW_DBG_COEX,
  2843. "[BTCoex], WiFi Fw Dbg info = %8ph (len = %d)\n",
  2844. buf, length);
  2845. if (WARN(length < 8, "invalid wl info c2h length\n"))
  2846. return;
  2847. if (buf[0] != 0x08)
  2848. return;
  2849. for (i = 1; i < 8; i++) {
  2850. val = coex_stat->wl_fw_dbg_info_pre[i];
  2851. if (buf[i] >= val)
  2852. coex_stat->wl_fw_dbg_info[i] = buf[i] - val;
  2853. else
  2854. coex_stat->wl_fw_dbg_info[i] = 255 - val + buf[i];
  2855. coex_stat->wl_fw_dbg_info_pre[i] = buf[i];
  2856. }
  2857. coex_stat->cnt_wl[COEX_CNT_WL_FW_NOTIFY]++;
  2858. rtw_coex_wl_ccklock_action(rtwdev);
  2859. rtw_coex_wl_ccklock_detect(rtwdev);
  2860. }
  2861. void rtw_coex_wl_status_change_notify(struct rtw_dev *rtwdev, u32 type)
  2862. {
  2863. rtw_coex_run_coex(rtwdev, COEX_RSN_WLSTATUS);
  2864. }
  2865. void rtw_coex_wl_status_check(struct rtw_dev *rtwdev)
  2866. {
  2867. struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
  2868. if ((coex_stat->wl_under_lps && !coex_stat->wl_force_lps_ctrl) ||
  2869. coex_stat->wl_under_ips)
  2870. return;
  2871. rtw_coex_monitor_bt_ctr(rtwdev);
  2872. }
  2873. void rtw_coex_bt_relink_work(struct work_struct *work)
  2874. {
  2875. struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
  2876. coex.bt_relink_work.work);
  2877. struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
  2878. mutex_lock(&rtwdev->mutex);
  2879. coex_stat->bt_setup_link = false;
  2880. rtw_coex_run_coex(rtwdev, COEX_RSN_WLSTATUS);
  2881. mutex_unlock(&rtwdev->mutex);
  2882. }
  2883. void rtw_coex_bt_reenable_work(struct work_struct *work)
  2884. {
  2885. struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
  2886. coex.bt_reenable_work.work);
  2887. struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
  2888. mutex_lock(&rtwdev->mutex);
  2889. coex_stat->bt_reenable = false;
  2890. mutex_unlock(&rtwdev->mutex);
  2891. }
  2892. void rtw_coex_defreeze_work(struct work_struct *work)
  2893. {
  2894. struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
  2895. coex.defreeze_work.work);
  2896. struct rtw_coex *coex = &rtwdev->coex;
  2897. struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
  2898. mutex_lock(&rtwdev->mutex);
  2899. coex->freeze = false;
  2900. coex_stat->wl_hi_pri_task1 = false;
  2901. rtw_coex_run_coex(rtwdev, COEX_RSN_WLSTATUS);
  2902. mutex_unlock(&rtwdev->mutex);
  2903. }
  2904. void rtw_coex_wl_remain_work(struct work_struct *work)
  2905. {
  2906. struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
  2907. coex.wl_remain_work.work);
  2908. struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
  2909. mutex_lock(&rtwdev->mutex);
  2910. coex_stat->wl_gl_busy = test_bit(RTW_FLAG_BUSY_TRAFFIC, rtwdev->flags);
  2911. rtw_coex_run_coex(rtwdev, COEX_RSN_WLSTATUS);
  2912. mutex_unlock(&rtwdev->mutex);
  2913. }
  2914. void rtw_coex_bt_remain_work(struct work_struct *work)
  2915. {
  2916. struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
  2917. coex.bt_remain_work.work);
  2918. struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
  2919. mutex_lock(&rtwdev->mutex);
  2920. coex_stat->bt_inq_remain = coex_stat->bt_inq_page;
  2921. rtw_coex_run_coex(rtwdev, COEX_RSN_BTSTATUS);
  2922. mutex_unlock(&rtwdev->mutex);
  2923. }
  2924. void rtw_coex_wl_connecting_work(struct work_struct *work)
  2925. {
  2926. struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
  2927. coex.wl_connecting_work.work);
  2928. struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
  2929. mutex_lock(&rtwdev->mutex);
  2930. coex_stat->wl_connecting = false;
  2931. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], WL connecting stop!!\n");
  2932. rtw_coex_run_coex(rtwdev, COEX_RSN_WLSTATUS);
  2933. mutex_unlock(&rtwdev->mutex);
  2934. }
  2935. void rtw_coex_bt_multi_link_remain_work(struct work_struct *work)
  2936. {
  2937. struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
  2938. coex.bt_multi_link_remain_work.work);
  2939. struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
  2940. mutex_lock(&rtwdev->mutex);
  2941. coex_stat->bt_multi_link_remain = false;
  2942. mutex_unlock(&rtwdev->mutex);
  2943. }
  2944. void rtw_coex_wl_ccklock_work(struct work_struct *work)
  2945. {
  2946. struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
  2947. coex.wl_ccklock_work.work);
  2948. struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
  2949. mutex_lock(&rtwdev->mutex);
  2950. coex_stat->wl_cck_lock = false;
  2951. mutex_unlock(&rtwdev->mutex);
  2952. }
  2953. #ifdef CONFIG_RTW88_DEBUGFS
  2954. #define INFO_SIZE 80
  2955. #define case_BTINFO(src) \
  2956. case COEX_BTINFO_SRC_##src: return #src
  2957. static const char *rtw_coex_get_bt_info_src_string(u8 bt_info_src)
  2958. {
  2959. switch (bt_info_src) {
  2960. case_BTINFO(WL_FW);
  2961. case_BTINFO(BT_RSP);
  2962. case_BTINFO(BT_ACT);
  2963. default:
  2964. return "Unknown";
  2965. }
  2966. }
  2967. #define case_RSN(src) \
  2968. case COEX_RSN_##src: return #src
  2969. static const char *rtw_coex_get_reason_string(u8 reason)
  2970. {
  2971. switch (reason) {
  2972. case_RSN(2GSCANSTART);
  2973. case_RSN(5GSCANSTART);
  2974. case_RSN(SCANFINISH);
  2975. case_RSN(2GSWITCHBAND);
  2976. case_RSN(5GSWITCHBAND);
  2977. case_RSN(2GCONSTART);
  2978. case_RSN(5GCONSTART);
  2979. case_RSN(2GCONFINISH);
  2980. case_RSN(5GCONFINISH);
  2981. case_RSN(2GMEDIA);
  2982. case_RSN(5GMEDIA);
  2983. case_RSN(MEDIADISCON);
  2984. case_RSN(BTINFO);
  2985. case_RSN(LPS);
  2986. case_RSN(WLSTATUS);
  2987. default:
  2988. return "Unknown";
  2989. }
  2990. }
  2991. static u8 rtw_coex_get_table_index(struct rtw_dev *rtwdev, u32 wl_reg_6c0,
  2992. u32 wl_reg_6c4)
  2993. {
  2994. const struct rtw_chip_info *chip = rtwdev->chip;
  2995. struct rtw_efuse *efuse = &rtwdev->efuse;
  2996. u8 ans = 0xFF;
  2997. u8 n, i;
  2998. u32 load_bt_val;
  2999. u32 load_wl_val;
  3000. bool share_ant = efuse->share_ant;
  3001. if (share_ant)
  3002. n = chip->table_sant_num;
  3003. else
  3004. n = chip->table_nsant_num;
  3005. for (i = 0; i < n; i++) {
  3006. if (share_ant) {
  3007. load_bt_val = chip->table_sant[i].bt;
  3008. load_wl_val = chip->table_sant[i].wl;
  3009. } else {
  3010. load_bt_val = chip->table_nsant[i].bt;
  3011. load_wl_val = chip->table_nsant[i].wl;
  3012. }
  3013. if (wl_reg_6c0 == load_bt_val &&
  3014. wl_reg_6c4 == load_wl_val) {
  3015. ans = i;
  3016. if (!share_ant)
  3017. ans += 100;
  3018. break;
  3019. }
  3020. }
  3021. return ans;
  3022. }
  3023. static u8 rtw_coex_get_tdma_index(struct rtw_dev *rtwdev, u8 *tdma_para)
  3024. {
  3025. const struct rtw_chip_info *chip = rtwdev->chip;
  3026. struct rtw_efuse *efuse = &rtwdev->efuse;
  3027. u8 ans = 0xFF;
  3028. u8 n, i, j;
  3029. u8 load_cur_tab_val;
  3030. bool valid = false;
  3031. bool share_ant = efuse->share_ant;
  3032. if (share_ant)
  3033. n = chip->tdma_sant_num;
  3034. else
  3035. n = chip->tdma_nsant_num;
  3036. for (i = 0; i < n; i++) {
  3037. valid = false;
  3038. for (j = 0; j < 5; j++) {
  3039. if (share_ant)
  3040. load_cur_tab_val = chip->tdma_sant[i].para[j];
  3041. else
  3042. load_cur_tab_val = chip->tdma_nsant[i].para[j];
  3043. if (*(tdma_para + j) != load_cur_tab_val)
  3044. break;
  3045. if (j == 4)
  3046. valid = true;
  3047. }
  3048. if (valid) {
  3049. ans = i;
  3050. break;
  3051. }
  3052. }
  3053. return ans;
  3054. }
  3055. static int rtw_coex_addr_info(struct rtw_dev *rtwdev,
  3056. const struct rtw_reg_domain *reg,
  3057. char addr_info[], int n)
  3058. {
  3059. const char *rf_prefix = "";
  3060. const char *sep = n == 0 ? "" : "/ ";
  3061. int ffs, fls;
  3062. int max_fls;
  3063. if (INFO_SIZE - n <= 0)
  3064. return 0;
  3065. switch (reg->domain) {
  3066. case RTW_REG_DOMAIN_MAC32:
  3067. max_fls = 31;
  3068. break;
  3069. case RTW_REG_DOMAIN_MAC16:
  3070. max_fls = 15;
  3071. break;
  3072. case RTW_REG_DOMAIN_MAC8:
  3073. max_fls = 7;
  3074. break;
  3075. case RTW_REG_DOMAIN_RF_A:
  3076. case RTW_REG_DOMAIN_RF_B:
  3077. rf_prefix = "RF_";
  3078. max_fls = 19;
  3079. break;
  3080. default:
  3081. return 0;
  3082. }
  3083. ffs = __ffs(reg->mask);
  3084. fls = __fls(reg->mask);
  3085. if (ffs == 0 && fls == max_fls)
  3086. return scnprintf(addr_info + n, INFO_SIZE - n, "%s%s%x",
  3087. sep, rf_prefix, reg->addr);
  3088. else if (ffs == fls)
  3089. return scnprintf(addr_info + n, INFO_SIZE - n, "%s%s%x[%d]",
  3090. sep, rf_prefix, reg->addr, ffs);
  3091. else
  3092. return scnprintf(addr_info + n, INFO_SIZE - n, "%s%s%x[%d:%d]",
  3093. sep, rf_prefix, reg->addr, fls, ffs);
  3094. }
  3095. static int rtw_coex_val_info(struct rtw_dev *rtwdev,
  3096. const struct rtw_reg_domain *reg,
  3097. char val_info[], int n)
  3098. {
  3099. const char *sep = n == 0 ? "" : "/ ";
  3100. u8 rf_path;
  3101. if (INFO_SIZE - n <= 0)
  3102. return 0;
  3103. switch (reg->domain) {
  3104. case RTW_REG_DOMAIN_MAC32:
  3105. return scnprintf(val_info + n, INFO_SIZE - n, "%s0x%x", sep,
  3106. rtw_read32_mask(rtwdev, reg->addr, reg->mask));
  3107. case RTW_REG_DOMAIN_MAC16:
  3108. return scnprintf(val_info + n, INFO_SIZE - n, "%s0x%x", sep,
  3109. rtw_read16_mask(rtwdev, reg->addr, reg->mask));
  3110. case RTW_REG_DOMAIN_MAC8:
  3111. return scnprintf(val_info + n, INFO_SIZE - n, "%s0x%x", sep,
  3112. rtw_read8_mask(rtwdev, reg->addr, reg->mask));
  3113. case RTW_REG_DOMAIN_RF_A:
  3114. rf_path = RF_PATH_A;
  3115. break;
  3116. case RTW_REG_DOMAIN_RF_B:
  3117. rf_path = RF_PATH_B;
  3118. break;
  3119. default:
  3120. return 0;
  3121. }
  3122. /* only RF go through here */
  3123. return scnprintf(val_info + n, INFO_SIZE - n, "%s0x%x", sep,
  3124. rtw_read_rf(rtwdev, rf_path, reg->addr, reg->mask));
  3125. }
  3126. static void rtw_coex_set_coexinfo_hw(struct rtw_dev *rtwdev, struct seq_file *m)
  3127. {
  3128. const struct rtw_chip_info *chip = rtwdev->chip;
  3129. const struct rtw_reg_domain *reg;
  3130. char addr_info[INFO_SIZE];
  3131. int n_addr = 0;
  3132. char val_info[INFO_SIZE];
  3133. int n_val = 0;
  3134. int i;
  3135. for (i = 0; i < chip->coex_info_hw_regs_num; i++) {
  3136. reg = &chip->coex_info_hw_regs[i];
  3137. n_addr += rtw_coex_addr_info(rtwdev, reg, addr_info, n_addr);
  3138. n_val += rtw_coex_val_info(rtwdev, reg, val_info, n_val);
  3139. if (reg->domain == RTW_REG_DOMAIN_NL) {
  3140. seq_printf(m, "%-40s = %s\n", addr_info, val_info);
  3141. n_addr = 0;
  3142. n_val = 0;
  3143. }
  3144. }
  3145. if (n_addr != 0 && n_val != 0)
  3146. seq_printf(m, "%-40s = %s\n", addr_info, val_info);
  3147. }
  3148. static bool rtw_coex_get_bt_reg(struct rtw_dev *rtwdev,
  3149. u8 type, u16 addr, u16 *val)
  3150. {
  3151. struct rtw_coex_info_req req = {0};
  3152. struct sk_buff *skb;
  3153. __le16 le_addr;
  3154. u8 *payload;
  3155. le_addr = cpu_to_le16(addr);
  3156. req.op_code = BT_MP_INFO_OP_READ_REG;
  3157. req.para1 = type;
  3158. req.para2 = le16_get_bits(le_addr, GENMASK(7, 0));
  3159. req.para3 = le16_get_bits(le_addr, GENMASK(15, 8));
  3160. skb = rtw_coex_info_request(rtwdev, &req);
  3161. if (!skb) {
  3162. *val = 0xeaea;
  3163. return false;
  3164. }
  3165. payload = get_payload_from_coex_resp(skb);
  3166. *val = GET_COEX_RESP_BT_REG_VAL(payload);
  3167. dev_kfree_skb_any(skb);
  3168. return true;
  3169. }
  3170. static bool rtw_coex_get_bt_patch_version(struct rtw_dev *rtwdev,
  3171. u32 *patch_version)
  3172. {
  3173. struct rtw_coex_info_req req = {0};
  3174. struct sk_buff *skb;
  3175. u8 *payload;
  3176. req.op_code = BT_MP_INFO_OP_PATCH_VER;
  3177. skb = rtw_coex_info_request(rtwdev, &req);
  3178. if (!skb)
  3179. return false;
  3180. payload = get_payload_from_coex_resp(skb);
  3181. *patch_version = GET_COEX_RESP_BT_PATCH_VER(payload);
  3182. dev_kfree_skb_any(skb);
  3183. return true;
  3184. }
  3185. static bool rtw_coex_get_bt_supported_version(struct rtw_dev *rtwdev,
  3186. u32 *supported_version)
  3187. {
  3188. struct rtw_coex_info_req req = {0};
  3189. struct sk_buff *skb;
  3190. u8 *payload;
  3191. req.op_code = BT_MP_INFO_OP_SUPP_VER;
  3192. skb = rtw_coex_info_request(rtwdev, &req);
  3193. if (!skb)
  3194. return false;
  3195. payload = get_payload_from_coex_resp(skb);
  3196. *supported_version = GET_COEX_RESP_BT_SUPP_VER(payload);
  3197. dev_kfree_skb_any(skb);
  3198. return true;
  3199. }
  3200. static bool rtw_coex_get_bt_supported_feature(struct rtw_dev *rtwdev,
  3201. u32 *supported_feature)
  3202. {
  3203. struct rtw_coex_info_req req = {0};
  3204. struct sk_buff *skb;
  3205. u8 *payload;
  3206. req.op_code = BT_MP_INFO_OP_SUPP_FEAT;
  3207. skb = rtw_coex_info_request(rtwdev, &req);
  3208. if (!skb)
  3209. return false;
  3210. payload = get_payload_from_coex_resp(skb);
  3211. *supported_feature = GET_COEX_RESP_BT_SUPP_FEAT(payload);
  3212. dev_kfree_skb_any(skb);
  3213. return true;
  3214. }
  3215. struct rtw_coex_sta_stat_iter_data {
  3216. struct rtw_vif *rtwvif;
  3217. struct seq_file *file;
  3218. };
  3219. static void rtw_coex_sta_stat_iter(void *data, struct ieee80211_sta *sta)
  3220. {
  3221. struct rtw_coex_sta_stat_iter_data *sta_iter_data = data;
  3222. struct rtw_vif *rtwvif = sta_iter_data->rtwvif;
  3223. struct rtw_sta_info *si = (struct rtw_sta_info *)sta->drv_priv;
  3224. struct seq_file *m = sta_iter_data->file;
  3225. struct ieee80211_vif *vif = rtwvif_to_vif(rtwvif);
  3226. u8 rssi;
  3227. if (si->vif != vif)
  3228. return;
  3229. rssi = ewma_rssi_read(&si->avg_rssi);
  3230. seq_printf(m, "\tPeer %3d\n", si->mac_id);
  3231. seq_printf(m, "\t\t%-24s = %d\n", "RSSI", rssi);
  3232. seq_printf(m, "\t\t%-24s = %d\n", "BW mode", si->bw_mode);
  3233. }
  3234. struct rtw_coex_vif_stat_iter_data {
  3235. struct rtw_dev *rtwdev;
  3236. struct seq_file *file;
  3237. };
  3238. static void rtw_coex_vif_stat_iter(void *data, u8 *mac,
  3239. struct ieee80211_vif *vif)
  3240. {
  3241. struct rtw_coex_vif_stat_iter_data *vif_iter_data = data;
  3242. struct rtw_coex_sta_stat_iter_data sta_iter_data;
  3243. struct rtw_dev *rtwdev = vif_iter_data->rtwdev;
  3244. struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv;
  3245. struct seq_file *m = vif_iter_data->file;
  3246. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  3247. seq_printf(m, "Iface on Port (%d)\n", rtwvif->port);
  3248. seq_printf(m, "\t%-32s = %d\n",
  3249. "Beacon interval", bss_conf->beacon_int);
  3250. seq_printf(m, "\t%-32s = %d\n",
  3251. "Network Type", rtwvif->net_type);
  3252. sta_iter_data.rtwvif = rtwvif;
  3253. sta_iter_data.file = m;
  3254. rtw_iterate_stas_atomic(rtwdev, rtw_coex_sta_stat_iter,
  3255. &sta_iter_data);
  3256. }
  3257. #define case_WLINK(src) \
  3258. case COEX_WLINK_##src: return #src
  3259. static const char *rtw_coex_get_wl_coex_mode(u8 coex_wl_link_mode)
  3260. {
  3261. switch (coex_wl_link_mode) {
  3262. case_WLINK(2G1PORT);
  3263. case_WLINK(5G);
  3264. case_WLINK(2GFREE);
  3265. default:
  3266. return "Unknown";
  3267. }
  3268. }
  3269. void rtw_coex_display_coex_info(struct rtw_dev *rtwdev, struct seq_file *m)
  3270. {
  3271. const struct rtw_chip_info *chip = rtwdev->chip;
  3272. struct rtw_dm_info *dm_info = &rtwdev->dm_info;
  3273. struct rtw_coex *coex = &rtwdev->coex;
  3274. struct rtw_coex_stat *coex_stat = &coex->stat;
  3275. struct rtw_coex_dm *coex_dm = &coex->dm;
  3276. struct rtw_hal *hal = &rtwdev->hal;
  3277. struct rtw_efuse *efuse = &rtwdev->efuse;
  3278. struct rtw_fw_state *fw = &rtwdev->fw;
  3279. struct rtw_coex_vif_stat_iter_data vif_iter_data;
  3280. u8 reason = coex_dm->reason;
  3281. u8 sys_lte;
  3282. u16 score_board_WB, score_board_BW;
  3283. u32 wl_reg_6c0, wl_reg_6c4, wl_reg_6c8, wl_reg_778, wl_reg_6cc;
  3284. u32 lte_coex = 0, bt_coex = 0;
  3285. int i;
  3286. score_board_BW = rtw_coex_read_scbd(rtwdev);
  3287. score_board_WB = coex_stat->score_board;
  3288. wl_reg_6c0 = rtw_read32(rtwdev, REG_BT_COEX_TABLE0);
  3289. wl_reg_6c4 = rtw_read32(rtwdev, REG_BT_COEX_TABLE1);
  3290. wl_reg_6c8 = rtw_read32(rtwdev, REG_BT_COEX_BRK_TABLE);
  3291. wl_reg_6cc = rtw_read32(rtwdev, REG_BT_COEX_TABLE_H);
  3292. wl_reg_778 = rtw_read8(rtwdev, REG_BT_STAT_CTRL);
  3293. sys_lte = rtw_read8(rtwdev, 0x73);
  3294. if (rtwdev->chip->ltecoex_addr) {
  3295. lte_coex = rtw_coex_read_indirect_reg(rtwdev, 0x38);
  3296. bt_coex = rtw_coex_read_indirect_reg(rtwdev, 0x54);
  3297. }
  3298. if (!coex_stat->wl_under_ips &&
  3299. (!coex_stat->wl_under_lps || coex_stat->wl_force_lps_ctrl) &&
  3300. !coex_stat->bt_disabled && !coex_stat->bt_mailbox_reply) {
  3301. rtw_coex_get_bt_supported_version(rtwdev,
  3302. &coex_stat->bt_supported_version);
  3303. rtw_coex_get_bt_patch_version(rtwdev, &coex_stat->patch_ver);
  3304. rtw_coex_get_bt_supported_feature(rtwdev,
  3305. &coex_stat->bt_supported_feature);
  3306. rtw_coex_get_bt_reg(rtwdev, 3, 0xae, &coex_stat->bt_reg_vendor_ae);
  3307. rtw_coex_get_bt_reg(rtwdev, 3, 0xac, &coex_stat->bt_reg_vendor_ac);
  3308. if (coex_stat->patch_ver != 0)
  3309. coex_stat->bt_mailbox_reply = true;
  3310. }
  3311. rtw_dbg(rtwdev, RTW_DBG_COEX, "[BTCoex], %s()\n", __func__);
  3312. seq_printf(m, "**********************************************\n");
  3313. seq_printf(m, "\t\tBT Coexist info %x\n", chip->id);
  3314. seq_printf(m, "**********************************************\n");
  3315. if (coex->manual_control) {
  3316. seq_puts(m, "============[Under Manual Control]============\n");
  3317. seq_puts(m, "==========================================\n");
  3318. } else if (coex->stop_dm) {
  3319. seq_puts(m, "============[Coex is STOPPED]============\n");
  3320. seq_puts(m, "==========================================\n");
  3321. } else if (coex->freeze) {
  3322. seq_puts(m, "============[coex_freeze]============\n");
  3323. seq_puts(m, "==========================================\n");
  3324. }
  3325. seq_printf(m, "%-40s = %s/ %d\n",
  3326. "Mech/ RFE",
  3327. efuse->share_ant ? "Shared" : "Non-Shared",
  3328. efuse->rfe_option);
  3329. seq_printf(m, "%-40s = %08x/ 0x%02x/ 0x%08x %s\n",
  3330. "Coex Ver/ BT Dez/ BT Rpt",
  3331. chip->coex_para_ver, chip->bt_desired_ver,
  3332. coex_stat->bt_supported_version,
  3333. coex_stat->bt_disabled ? "(BT disabled)" :
  3334. coex_stat->bt_supported_version >= chip->bt_desired_ver ?
  3335. "(Match)" : "(Mismatch)");
  3336. seq_printf(m, "%-40s = %s/ %u/ %d\n",
  3337. "Role/ RoleSwCnt/ IgnWL/ Feature",
  3338. coex_stat->bt_slave ? "Slave" : "Master",
  3339. coex_stat->cnt_bt[COEX_CNT_BT_ROLESWITCH],
  3340. coex_dm->ignore_wl_act);
  3341. seq_printf(m, "%-40s = %u.%u/ 0x%x/ 0x%x/ %c\n",
  3342. "WL FW/ BT FW/ BT FW Desired/ KT",
  3343. fw->version, fw->sub_version,
  3344. coex_stat->patch_ver,
  3345. chip->wl_fw_desired_ver, coex_stat->kt_ver + 65);
  3346. seq_printf(m, "%-40s = %u/ %u/ %u/ ch-(%u)\n",
  3347. "AFH Map",
  3348. coex_dm->wl_ch_info[0], coex_dm->wl_ch_info[1],
  3349. coex_dm->wl_ch_info[2], hal->current_channel);
  3350. rtw_debugfs_get_simple_phy_info(m);
  3351. seq_printf(m, "**********************************************\n");
  3352. seq_printf(m, "\t\tBT Status\n");
  3353. seq_printf(m, "**********************************************\n");
  3354. seq_printf(m, "%-40s = %s/ %ddBm/ %u/ %u\n",
  3355. "BT status/ rssi/ retry/ pop",
  3356. coex_dm->bt_status == COEX_BTSTATUS_NCON_IDLE ? "non-conn" :
  3357. coex_dm->bt_status == COEX_BTSTATUS_CON_IDLE ? "conn-idle" : "busy",
  3358. coex_stat->bt_rssi - 100,
  3359. coex_stat->cnt_bt[COEX_CNT_BT_RETRY],
  3360. coex_stat->cnt_bt[COEX_CNT_BT_POPEVENT]);
  3361. seq_printf(m, "%-40s = %s%s%s%s%s (multi-link %d)\n",
  3362. "Profiles",
  3363. coex_stat->bt_a2dp_exist ? (coex_stat->bt_a2dp_sink ?
  3364. "A2DP sink," : "A2DP,") : "",
  3365. coex_stat->bt_hfp_exist ? "HFP," : "",
  3366. coex_stat->bt_hid_exist ?
  3367. (coex_stat->bt_ble_exist ? "HID(RCU)," :
  3368. coex_stat->bt_hid_slot >= 2 ? "HID(4/18)" :
  3369. coex_stat->bt_ble_hid_exist ? "HID(BLE)" :
  3370. "HID(2/18),") : "",
  3371. coex_stat->bt_pan_exist ? coex_stat->bt_opp_exist ?
  3372. "OPP," : "PAN," : "",
  3373. coex_stat->bt_ble_voice ? "Voice," : "",
  3374. coex_stat->bt_multi_link);
  3375. seq_printf(m, "%-40s = %u/ %u/ %u/ 0x%08x\n",
  3376. "Reinit/ Relink/ IgnWl/ Feature",
  3377. coex_stat->cnt_bt[COEX_CNT_BT_REINIT],
  3378. coex_stat->cnt_bt[COEX_CNT_BT_SETUPLINK],
  3379. coex_stat->cnt_bt[COEX_CNT_BT_IGNWLANACT],
  3380. coex_stat->bt_supported_feature);
  3381. seq_printf(m, "%-40s = %u/ %u/ %u/ %u\n",
  3382. "Page/ Inq/ iqk/ iqk fail",
  3383. coex_stat->cnt_bt[COEX_CNT_BT_PAGE],
  3384. coex_stat->cnt_bt[COEX_CNT_BT_INQ],
  3385. coex_stat->cnt_bt[COEX_CNT_BT_IQK],
  3386. coex_stat->cnt_bt[COEX_CNT_BT_IQKFAIL]);
  3387. seq_printf(m, "%-40s = 0x%04x/ 0x%04x/ 0x%04x/ 0x%04x\n",
  3388. "0xae/ 0xac/ score board (W->B)/ (B->W)",
  3389. coex_stat->bt_reg_vendor_ae,
  3390. coex_stat->bt_reg_vendor_ac,
  3391. score_board_WB, score_board_BW);
  3392. seq_printf(m, "%-40s = %u/%u, %u/%u\n",
  3393. "Hi-Pri TX/RX, Lo-Pri TX/RX",
  3394. coex_stat->hi_pri_tx, coex_stat->hi_pri_rx,
  3395. coex_stat->lo_pri_tx, coex_stat->lo_pri_rx);
  3396. for (i = 0; i < COEX_BTINFO_SRC_BT_IQK; i++)
  3397. seq_printf(m, "%-40s = %7ph\n",
  3398. rtw_coex_get_bt_info_src_string(i),
  3399. coex_stat->bt_info_c2h[i]);
  3400. seq_printf(m, "**********************************************\n");
  3401. seq_printf(m, "\t\tWiFi Status\n");
  3402. seq_printf(m, "**********************************************\n");
  3403. seq_printf(m, "%-40s = %d\n",
  3404. "Scanning", test_bit(RTW_FLAG_SCANNING, rtwdev->flags));
  3405. seq_printf(m, "%-40s = %u/ TX %d Mbps/ RX %d Mbps\n",
  3406. "G_busy/ TX/ RX",
  3407. coex_stat->wl_gl_busy,
  3408. rtwdev->stats.tx_throughput, rtwdev->stats.rx_throughput);
  3409. seq_printf(m, "%-40s = %u/ %u/ %u\n",
  3410. "IPS/ Low Power/ PS mode",
  3411. !test_bit(RTW_FLAG_POWERON, rtwdev->flags),
  3412. test_bit(RTW_FLAG_LEISURE_PS_DEEP, rtwdev->flags),
  3413. rtwdev->lps_conf.mode);
  3414. vif_iter_data.rtwdev = rtwdev;
  3415. vif_iter_data.file = m;
  3416. rtw_iterate_vifs_atomic(rtwdev, rtw_coex_vif_stat_iter, &vif_iter_data);
  3417. if (coex->manual_control) {
  3418. seq_printf(m, "**********************************************\n");
  3419. seq_printf(m, "\t\tMechanism (Under Manual)\n");
  3420. seq_printf(m, "**********************************************\n");
  3421. seq_printf(m, "%-40s = %5ph (%d)\n",
  3422. "TDMA Now",
  3423. coex_dm->fw_tdma_para,
  3424. rtw_coex_get_tdma_index(rtwdev,
  3425. &coex_dm->fw_tdma_para[0]));
  3426. } else {
  3427. seq_printf(m, "**********************************************\n");
  3428. seq_printf(m, "\t\tMechanism\n");
  3429. seq_printf(m, "**********************************************\n");
  3430. seq_printf(m, "%-40s = %5ph (case-%d)\n",
  3431. "TDMA",
  3432. coex_dm->ps_tdma_para, coex_dm->cur_ps_tdma);
  3433. }
  3434. seq_printf(m, "%-40s = %s/ %s/ %d\n",
  3435. "Coex Mode/Free Run/Timer base",
  3436. rtw_coex_get_wl_coex_mode(coex_stat->wl_coex_mode),
  3437. coex->freerun ? "Yes" : "No",
  3438. coex_stat->tdma_timer_base);
  3439. seq_printf(m, "%-40s = %d(%d)/ 0x%08x/ 0x%08x/ 0x%08x\n",
  3440. "Table/ 0x6c0/ 0x6c4/ 0x6c8",
  3441. coex_dm->cur_table,
  3442. rtw_coex_get_table_index(rtwdev, wl_reg_6c0, wl_reg_6c4),
  3443. wl_reg_6c0, wl_reg_6c4, wl_reg_6c8);
  3444. seq_printf(m, "%-40s = 0x%08x/ 0x%08x/ %d/ reason (%s)\n",
  3445. "0x778/ 0x6cc/ Run Count/ Reason",
  3446. wl_reg_778, wl_reg_6cc,
  3447. coex_stat->cnt_wl[COEX_CNT_WL_COEXRUN],
  3448. rtw_coex_get_reason_string(reason));
  3449. seq_printf(m, "%-40s = %3ph\n",
  3450. "AFH Map to BT",
  3451. coex_dm->wl_ch_info);
  3452. seq_printf(m, "%-40s = %s/ %d\n",
  3453. "AntDiv/ BtCtrlLPS/ g_busy",
  3454. coex_stat->wl_force_lps_ctrl ? "On" : "Off",
  3455. coex_stat->wl_gl_busy);
  3456. seq_printf(m, "%-40s = %u/ %u/ %u/ %u/ %u\n",
  3457. "Null All/ Retry/ Ack/ BT Empty/ BT Late",
  3458. coex_stat->wl_fw_dbg_info[1], coex_stat->wl_fw_dbg_info[2],
  3459. coex_stat->wl_fw_dbg_info[3], coex_stat->wl_fw_dbg_info[4],
  3460. coex_stat->wl_fw_dbg_info[5]);
  3461. seq_printf(m, "%-40s = %u/ %u/ %s/ %u\n",
  3462. "Cnt TDMA Toggle/ Lk 5ms/ Lk 5ms on/ FW",
  3463. coex_stat->wl_fw_dbg_info[6],
  3464. coex_stat->wl_fw_dbg_info[7],
  3465. coex_stat->wl_slot_extend ? "Yes" : "No",
  3466. coex_stat->cnt_wl[COEX_CNT_WL_FW_NOTIFY]);
  3467. seq_printf(m, "%-40s = %d/ %d/ %s/ %d\n",
  3468. "WL_TxPw/ BT_TxPw/ WL_Rx/ BT_LNA_Lvl",
  3469. coex_dm->cur_wl_pwr_lvl,
  3470. coex_dm->cur_bt_pwr_lvl,
  3471. coex_dm->cur_wl_rx_low_gain_en ? "On" : "Off",
  3472. coex_dm->cur_bt_lna_lvl);
  3473. seq_printf(m, "**********************************************\n");
  3474. seq_printf(m, "\t\tHW setting\n");
  3475. seq_printf(m, "**********************************************\n");
  3476. seq_printf(m, "%-40s = %s/ %s\n",
  3477. "LTE Coex/ Path Owner",
  3478. lte_coex & BIT(7) ? "ON" : "OFF",
  3479. sys_lte & BIT(2) ? "WL" : "BT");
  3480. seq_printf(m, "%-40s = RF:%s_BB:%s/ RF:%s_BB:%s/ %s\n",
  3481. "GNT_WL_CTRL/ GNT_BT_CTRL/ Dbg",
  3482. lte_coex & BIT(12) ? "SW" : "HW",
  3483. lte_coex & BIT(8) ? "SW" : "HW",
  3484. lte_coex & BIT(14) ? "SW" : "HW",
  3485. lte_coex & BIT(10) ? "SW" : "HW",
  3486. sys_lte & BIT(3) ? "On" : "Off");
  3487. seq_printf(m, "%-40s = %lu/ %lu\n",
  3488. "GNT_WL/ GNT_BT",
  3489. (bt_coex & BIT(2)) >> 2, (bt_coex & BIT(3)) >> 3);
  3490. seq_printf(m, "%-40s = %u/ %u/ %u/ %u\n",
  3491. "CRC OK CCK/ OFDM/ HT/ VHT",
  3492. dm_info->cck_ok_cnt, dm_info->ofdm_ok_cnt,
  3493. dm_info->ht_ok_cnt, dm_info->vht_ok_cnt);
  3494. seq_printf(m, "%-40s = %u/ %u/ %u/ %u\n",
  3495. "CRC ERR CCK/ OFDM/ HT/ VHT",
  3496. dm_info->cck_err_cnt, dm_info->ofdm_err_cnt,
  3497. dm_info->ht_err_cnt, dm_info->vht_err_cnt);
  3498. seq_printf(m, "%-40s = %s/ %s/ %s/ %u\n",
  3499. "HiPr/ Locking/ Locked/ Noisy",
  3500. coex_stat->wl_hi_pri_task1 ? "Y" : "N",
  3501. coex_stat->wl_cck_lock ? "Y" : "N",
  3502. coex_stat->wl_cck_lock_ever ? "Y" : "N",
  3503. coex_stat->wl_noisy_level);
  3504. rtw_coex_set_coexinfo_hw(rtwdev, m);
  3505. seq_printf(m, "%-40s = %d/ %d/ %d/ %d\n",
  3506. "EVM A/ EVM B/ SNR A/ SNR B",
  3507. -dm_info->rx_evm_dbm[RF_PATH_A],
  3508. -dm_info->rx_evm_dbm[RF_PATH_B],
  3509. -dm_info->rx_snr[RF_PATH_A],
  3510. -dm_info->rx_snr[RF_PATH_B]);
  3511. seq_printf(m, "%-40s = %d/ %d/ %d/ %d\n",
  3512. "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA",
  3513. dm_info->cck_cca_cnt, dm_info->cck_fa_cnt,
  3514. dm_info->ofdm_cca_cnt, dm_info->ofdm_fa_cnt);
  3515. seq_printf(m, "%-40s = %d/ %d/ %d/ %d\n", "CRC OK CCK/11g/11n/11ac",
  3516. dm_info->cck_ok_cnt, dm_info->ofdm_ok_cnt,
  3517. dm_info->ht_ok_cnt, dm_info->vht_ok_cnt);
  3518. seq_printf(m, "%-40s = %d/ %d/ %d/ %d\n", "CRC Err CCK/11g/11n/11ac",
  3519. dm_info->cck_err_cnt, dm_info->ofdm_err_cnt,
  3520. dm_info->ht_err_cnt, dm_info->vht_err_cnt);
  3521. }
  3522. #endif /* CONFIG_RTW88_DEBUGFS */