coex.c 113 KB

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