hal_btcoex.c 157 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2013 - 2017 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. *****************************************************************************/
  15. #define __HAL_BTCOEX_C__
  16. #ifdef CONFIG_BT_COEXIST
  17. #include <hal_data.h>
  18. #include <hal_btcoex.h>
  19. #include "btc/mp_precomp.h"
  20. /* ************************************
  21. * Global variables
  22. * ************************************ */
  23. const char *const BtProfileString[] = {
  24. "NONE",
  25. "A2DP",
  26. "PAN",
  27. "HID",
  28. "SCO",
  29. };
  30. const char *const BtSpecString[] = {
  31. "1.0b",
  32. "1.1",
  33. "1.2",
  34. "2.0+EDR",
  35. "2.1+EDR",
  36. "3.0+HS",
  37. "4.0",
  38. };
  39. const char *const BtLinkRoleString[] = {
  40. "Master",
  41. "Slave",
  42. };
  43. const char *const h2cStaString[] = {
  44. "successful",
  45. "h2c busy",
  46. "rf off",
  47. "fw not read",
  48. };
  49. const char *const ioStaString[] = {
  50. "success",
  51. "can not IO",
  52. "rf off",
  53. "fw not read",
  54. "wait io timeout",
  55. "invalid len",
  56. "idle Q empty",
  57. "insert waitQ fail",
  58. "unknown fail",
  59. "wrong level",
  60. "h2c stopped",
  61. };
  62. const char *const GLBtcWifiBwString[] = {
  63. "11bg",
  64. "HT20",
  65. "HT40",
  66. "VHT80",
  67. "VHT160"
  68. };
  69. const char *const GLBtcWifiFreqString[] = {
  70. "2.4G",
  71. "5G",
  72. "2.4G+5G"
  73. };
  74. const char *const GLBtcIotPeerString[] = {
  75. "UNKNOWN",
  76. "REALTEK",
  77. "REALTEK_92SE",
  78. "BROADCOM",
  79. "RALINK",
  80. "ATHEROS",
  81. "CISCO",
  82. "MERU",
  83. "MARVELL",
  84. "REALTEK_SOFTAP", /* peer is RealTek SOFT_AP, by Bohn, 2009.12.17 */
  85. "SELF_SOFTAP", /* Self is SoftAP */
  86. "AIRGO",
  87. "INTEL",
  88. "RTK_APCLIENT",
  89. "REALTEK_81XX",
  90. "REALTEK_WOW",
  91. "REALTEK_JAGUAR_BCUTAP",
  92. "REALTEK_JAGUAR_CCUTAP"
  93. };
  94. const char *const coexOpcodeString[] = {
  95. "Wifi status notify",
  96. "Wifi progress",
  97. "Wifi info",
  98. "Power state",
  99. "Set Control",
  100. "Get Control"
  101. };
  102. const char *const coexIndTypeString[] = {
  103. "bt info",
  104. "pstdma",
  105. "limited tx/rx",
  106. "coex table",
  107. "request"
  108. };
  109. const char *const coexH2cResultString[] = {
  110. "ok",
  111. "unknown",
  112. "un opcode",
  113. "opVer MM",
  114. "par Err",
  115. "par OoR",
  116. "reqNum MM",
  117. "halMac Fail",
  118. "h2c TimeOut",
  119. "Invalid c2h Len",
  120. "data overflow"
  121. };
  122. #define HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS 8000
  123. struct btc_coexist GLBtCoexist;
  124. BTC_OFFLOAD gl_coex_offload;
  125. u8 GLBtcWiFiInScanState;
  126. u8 GLBtcWiFiInIQKState;
  127. u8 GLBtcWiFiInIPS;
  128. u8 GLBtcWiFiInLPS;
  129. u8 GLBtcBtCoexAliveRegistered;
  130. /*
  131. * BT control H2C/C2H
  132. */
  133. /* EXT_EID */
  134. typedef enum _bt_ext_eid {
  135. C2H_WIFI_FW_ACTIVE_RSP = 0,
  136. C2H_TRIG_BY_BT_FW
  137. } BT_EXT_EID;
  138. /* C2H_STATUS */
  139. typedef enum _bt_c2h_status {
  140. BT_STATUS_OK = 0,
  141. BT_STATUS_VERSION_MISMATCH,
  142. BT_STATUS_UNKNOWN_OPCODE,
  143. BT_STATUS_ERROR_PARAMETER
  144. } BT_C2H_STATUS;
  145. /* C2H BT OP CODES */
  146. typedef enum _bt_op_code {
  147. BT_OP_GET_BT_VERSION = 0x00,
  148. BT_OP_WRITE_REG_ADDR = 0x0c,
  149. BT_OP_WRITE_REG_VALUE = 0x0d,
  150. BT_OP_READ_REG = 0x11,
  151. BT_LO_OP_GET_AFH_MAP_L = 0x1e,
  152. BT_LO_OP_GET_AFH_MAP_M = 0x1f,
  153. BT_LO_OP_GET_AFH_MAP_H = 0x20,
  154. BT_OP_GET_BT_COEX_SUPPORTED_FEATURE = 0x2a,
  155. BT_OP_GET_BT_COEX_SUPPORTED_VERSION = 0x2b,
  156. BT_OP_GET_BT_ANT_DET_VAL = 0x2c,
  157. BT_OP_GET_BT_BLE_SCAN_TYPE = 0x2d,
  158. BT_OP_GET_BT_BLE_SCAN_PARA = 0x2e,
  159. BT_OP_GET_BT_DEVICE_INFO = 0x30,
  160. BT_OP_GET_BT_FORBIDDEN_SLOT_VAL = 0x31,
  161. BT_OP_SET_BT_LANCONSTRAIN_LEVEL = 0x32,
  162. BT_OP_MAX
  163. } BT_OP_CODE;
  164. #define BTC_MPOPER_TIMEOUT 50 /* unit: ms */
  165. #define C2H_MAX_SIZE 16
  166. u8 GLBtcBtMpOperSeq;
  167. _mutex GLBtcBtMpOperLock;
  168. _timer GLBtcBtMpOperTimer;
  169. _sema GLBtcBtMpRptSema;
  170. u8 GLBtcBtMpRptSeq;
  171. u8 GLBtcBtMpRptStatus;
  172. u8 GLBtcBtMpRptRsp[C2H_MAX_SIZE];
  173. u8 GLBtcBtMpRptRspSize;
  174. u8 GLBtcBtMpRptWait;
  175. u8 GLBtcBtMpRptWiFiOK;
  176. u8 GLBtcBtMpRptBTOK;
  177. /*
  178. * Debug
  179. */
  180. u32 GLBtcDbgType[COMP_MAX];
  181. u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];
  182. u1Byte gl_btc_trace_buf[BT_TMP_BUF_SIZE];
  183. typedef struct _btcoexdbginfo {
  184. u8 *info;
  185. u32 size; /* buffer total size */
  186. u32 len; /* now used length */
  187. } BTCDBGINFO, *PBTCDBGINFO;
  188. BTCDBGINFO GLBtcDbgInfo;
  189. #define BT_Operation(Adapter) _FALSE
  190. static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)
  191. {
  192. if (NULL == pinfo)
  193. return;
  194. _rtw_memset(pinfo, 0, sizeof(BTCDBGINFO));
  195. if (pbuf && size) {
  196. pinfo->info = pbuf;
  197. pinfo->size = size;
  198. }
  199. }
  200. void DBG_BT_INFO(u8 *dbgmsg)
  201. {
  202. PBTCDBGINFO pinfo;
  203. u32 msglen, buflen;
  204. u8 *pbuf;
  205. pinfo = &GLBtcDbgInfo;
  206. if (NULL == pinfo->info)
  207. return;
  208. msglen = strlen(dbgmsg);
  209. if (pinfo->len + msglen > pinfo->size)
  210. return;
  211. pbuf = pinfo->info + pinfo->len;
  212. _rtw_memcpy(pbuf, dbgmsg, msglen);
  213. pinfo->len += msglen;
  214. }
  215. /* ************************************
  216. * Debug related function
  217. * ************************************ */
  218. static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
  219. {
  220. if (!pBtCoexist->bBinded ||
  221. NULL == pBtCoexist->Adapter)
  222. return _FALSE;
  223. return _TRUE;
  224. }
  225. static void halbtcoutsrc_DbgInit(void)
  226. {
  227. u8 i;
  228. for (i = 0; i < COMP_MAX; i++)
  229. GLBtcDbgType[i] = 0;
  230. }
  231. static u8 halbtcoutsrc_IsCsrBtCoex(PBTC_COEXIST pBtCoexist)
  232. {
  233. if (pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC4
  234. || pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC8
  235. )
  236. return _TRUE;
  237. return _FALSE;
  238. }
  239. static void halbtcoutsrc_EnterPwrLock(PBTC_COEXIST pBtCoexist)
  240. {
  241. struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter);
  242. struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
  243. _enter_pwrlock(&pwrpriv->lock);
  244. }
  245. static void halbtcoutsrc_ExitPwrLock(PBTC_COEXIST pBtCoexist)
  246. {
  247. struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter);
  248. struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
  249. _exit_pwrlock(&pwrpriv->lock);
  250. }
  251. static u8 halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)
  252. {
  253. if (pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC4
  254. || pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC8
  255. )
  256. return _FALSE;
  257. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
  258. return _FALSE;
  259. else
  260. return _TRUE;
  261. }
  262. static u8 halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
  263. {
  264. PADAPTER padapter;
  265. padapter = pBtCoexist->Adapter;
  266. pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;
  267. pBtCoexist->bt_info.bt_lps_on = _FALSE;
  268. return rtw_btcoex_LPS_Leave(padapter);
  269. }
  270. void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
  271. {
  272. PADAPTER padapter;
  273. padapter = pBtCoexist->Adapter;
  274. if (pBtCoexist->bdontenterLPS == _FALSE) {
  275. pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;
  276. pBtCoexist->bt_info.bt_lps_on = _TRUE;
  277. rtw_btcoex_LPS_Enter(padapter);
  278. }
  279. }
  280. void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
  281. {
  282. PADAPTER padapter;
  283. padapter = pBtCoexist->Adapter;
  284. if (pBtCoexist->bt_info.bt_ctrl_lps) {
  285. pBtCoexist->bt_info.bt_lps_on = _FALSE;
  286. rtw_btcoex_LPS_Leave(padapter);
  287. pBtCoexist->bt_info.bt_ctrl_lps = _FALSE;
  288. /* recover the LPS state to the original */
  289. #if 0
  290. padapter->hal_func.UpdateLPSStatusHandler(
  291. padapter,
  292. pPSC->RegLeisurePsMode,
  293. pPSC->RegPowerSaveMode);
  294. #endif
  295. }
  296. }
  297. void halbtcoutsrc_Pre_NormalLps(PBTC_COEXIST pBtCoexist)
  298. {
  299. PADAPTER padapter;
  300. padapter = pBtCoexist->Adapter;
  301. if (pBtCoexist->bt_info.bt_ctrl_lps) {
  302. pBtCoexist->bt_info.bt_lps_on = _FALSE;
  303. rtw_btcoex_LPS_Leave(padapter);
  304. }
  305. }
  306. void halbtcoutsrc_Post_NormalLps(PBTC_COEXIST pBtCoexist)
  307. {
  308. if (pBtCoexist->bt_info.bt_ctrl_lps)
  309. pBtCoexist->bt_info.bt_ctrl_lps = _FALSE;
  310. }
  311. /*
  312. * Constraint:
  313. * 1. this function will request pwrctrl->lock
  314. */
  315. void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
  316. {
  317. #ifdef CONFIG_LPS_LCLK
  318. PADAPTER padapter;
  319. PHAL_DATA_TYPE pHalData;
  320. struct pwrctrl_priv *pwrctrl;
  321. s32 ready;
  322. systime stime;
  323. s32 utime;
  324. u32 timeout; /* unit: ms */
  325. padapter = pBtCoexist->Adapter;
  326. pHalData = GET_HAL_DATA(padapter);
  327. pwrctrl = adapter_to_pwrctl(padapter);
  328. ready = _FAIL;
  329. #ifdef LPS_RPWM_WAIT_MS
  330. timeout = LPS_RPWM_WAIT_MS;
  331. #else /* !LPS_RPWM_WAIT_MS */
  332. timeout = 30;
  333. #endif /* !LPS_RPWM_WAIT_MS */
  334. if (GLBtcBtCoexAliveRegistered == _TRUE)
  335. return;
  336. stime = rtw_get_current_time();
  337. do {
  338. ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
  339. if (_SUCCESS == ready)
  340. break;
  341. utime = rtw_get_passing_time_ms(stime);
  342. if (utime > timeout)
  343. break;
  344. rtw_msleep_os(1);
  345. } while (1);
  346. GLBtcBtCoexAliveRegistered = _TRUE;
  347. #endif /* CONFIG_LPS_LCLK */
  348. }
  349. /*
  350. * Constraint:
  351. * 1. this function will request pwrctrl->lock
  352. */
  353. void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
  354. {
  355. #ifdef CONFIG_LPS_LCLK
  356. PADAPTER padapter;
  357. if (GLBtcBtCoexAliveRegistered == _FALSE)
  358. return;
  359. padapter = pBtCoexist->Adapter;
  360. rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
  361. GLBtcBtCoexAliveRegistered = _FALSE;
  362. #endif /* CONFIG_LPS_LCLK */
  363. }
  364. void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
  365. {
  366. pBtCoexist->bt_info.bt_disable_low_pwr = bLowPwrDisable;
  367. if (bLowPwrDisable)
  368. halbtcoutsrc_LeaveLowPower(pBtCoexist); /* leave 32k low power. */
  369. else
  370. halbtcoutsrc_NormalLowPower(pBtCoexist); /* original 32k low power behavior. */
  371. }
  372. void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
  373. {
  374. PADAPTER padapter;
  375. BOOLEAN bNeedToAct = _FALSE;
  376. static u32 preTime = 0;
  377. u32 curTime = 0;
  378. padapter = pBtCoexist->Adapter;
  379. /* ===================================== */
  380. /* To void continuous deleteBA=>addBA=>deleteBA=>addBA */
  381. /* This function is not allowed to continuous called. */
  382. /* It can only be called after 8 seconds. */
  383. /* ===================================== */
  384. curTime = rtw_systime_to_ms(rtw_get_current_time());
  385. if ((curTime - preTime) < HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS) /* over 8 seconds you can execute this function again. */
  386. return;
  387. else
  388. preTime = curTime;
  389. if (pBtCoexist->bt_info.reject_agg_pkt) {
  390. bNeedToAct = _TRUE;
  391. pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;
  392. } else {
  393. if (pBtCoexist->bt_info.pre_reject_agg_pkt) {
  394. bNeedToAct = _TRUE;
  395. pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;
  396. }
  397. if (pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
  398. pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {
  399. bNeedToAct = _TRUE;
  400. pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size = pBtCoexist->bt_info.bt_ctrl_agg_buf_size;
  401. }
  402. if (pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {
  403. if (pBtCoexist->bt_info.pre_agg_buf_size !=
  404. pBtCoexist->bt_info.agg_buf_size)
  405. bNeedToAct = _TRUE;
  406. pBtCoexist->bt_info.pre_agg_buf_size = pBtCoexist->bt_info.agg_buf_size;
  407. }
  408. }
  409. if (bNeedToAct)
  410. rtw_btcoex_rx_ampdu_apply(padapter);
  411. }
  412. u8 halbtcoutsrc_is_autoload_fail(PBTC_COEXIST pBtCoexist)
  413. {
  414. PADAPTER padapter;
  415. PHAL_DATA_TYPE pHalData;
  416. padapter = pBtCoexist->Adapter;
  417. pHalData = GET_HAL_DATA(padapter);
  418. return pHalData->bautoload_fail_flag;
  419. }
  420. u8 halbtcoutsrc_is_fw_ready(PBTC_COEXIST pBtCoexist)
  421. {
  422. PADAPTER padapter;
  423. padapter = pBtCoexist->Adapter;
  424. return GET_HAL_DATA(padapter)->bFWReady;
  425. }
  426. u8 halbtcoutsrc_IsDualBandConnected(PADAPTER padapter)
  427. {
  428. u8 ret = BTC_MULTIPORT_SCC;
  429. #ifdef CONFIG_MCC_MODE
  430. if (MCC_EN(padapter) && (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))) {
  431. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  432. struct mcc_obj_priv *mccobjpriv = &(dvobj->mcc_objpriv);
  433. u8 band0 = mccobjpriv->iface[0]->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
  434. u8 band1 = mccobjpriv->iface[1]->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
  435. if (band0 != band1)
  436. ret = BTC_MULTIPORT_MCC_DUAL_BAND;
  437. else
  438. ret = BTC_MULTIPORT_MCC_DUAL_CHANNEL;
  439. }
  440. #endif
  441. return ret;
  442. }
  443. u8 halbtcoutsrc_IsWifiBusy(PADAPTER padapter)
  444. {
  445. if (rtw_mi_check_status(padapter, MI_AP_ASSOC))
  446. return _TRUE;
  447. if (rtw_mi_busy_traffic_check(padapter, _FALSE))
  448. return _TRUE;
  449. return _FALSE;
  450. }
  451. static u32 _halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)
  452. {
  453. struct mlme_priv *pmlmepriv;
  454. u8 bp2p;
  455. u32 portConnectedStatus;
  456. pmlmepriv = &padapter->mlmepriv;
  457. bp2p = _FALSE;
  458. portConnectedStatus = 0;
  459. #ifdef CONFIG_P2P
  460. if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))
  461. bp2p = _TRUE;
  462. #endif /* CONFIG_P2P */
  463. if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) {
  464. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
  465. if (_TRUE == bp2p)
  466. portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
  467. else
  468. portConnectedStatus |= WIFI_AP_CONNECTED;
  469. } else {
  470. if (_TRUE == bp2p)
  471. portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
  472. else
  473. portConnectedStatus |= WIFI_STA_CONNECTED;
  474. }
  475. }
  476. return portConnectedStatus;
  477. }
  478. u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
  479. {
  480. /* ================================= */
  481. /* return value: */
  482. /* [31:16]=> connected port number */
  483. /* [15:0]=> port connected bit define */
  484. /* ================================ */
  485. PADAPTER padapter;
  486. u32 retVal;
  487. u32 portConnectedStatus, numOfConnectedPort;
  488. struct dvobj_priv *dvobj;
  489. _adapter *iface;
  490. int i;
  491. padapter = pBtCoexist->Adapter;
  492. retVal = 0;
  493. portConnectedStatus = 0;
  494. numOfConnectedPort = 0;
  495. dvobj = adapter_to_dvobj(padapter);
  496. for (i = 0; i < dvobj->iface_nums; i++) {
  497. iface = dvobj->padapters[i];
  498. if ((iface) && rtw_is_adapter_up(iface)) {
  499. retVal = _halbtcoutsrc_GetWifiLinkStatus(iface);
  500. if (retVal) {
  501. portConnectedStatus |= retVal;
  502. numOfConnectedPort++;
  503. }
  504. }
  505. }
  506. retVal = (numOfConnectedPort << 16) | portConnectedStatus;
  507. return retVal;
  508. }
  509. struct btc_wifi_link_info halbtcoutsrc_getwifilinkinfo(PBTC_COEXIST pBtCoexist)
  510. {
  511. u8 n_assoc_iface = 0, i =0, mcc_en = _FALSE;
  512. PADAPTER adapter = NULL;
  513. PADAPTER iface = NULL;
  514. PADAPTER sta_iface = NULL, p2p_iface = NULL, ap_iface = NULL;
  515. BTC_LINK_MODE btc_link_moe = BTC_LINK_MAX;
  516. struct dvobj_priv *dvobj = NULL;
  517. struct mlme_ext_priv *mlmeext = NULL;
  518. struct btc_wifi_link_info wifi_link_info;
  519. adapter = (PADAPTER)pBtCoexist->Adapter;
  520. dvobj = adapter_to_dvobj(adapter);
  521. n_assoc_iface = rtw_mi_get_assoc_if_num(adapter);
  522. /* init value */
  523. wifi_link_info.link_mode = BTC_LINK_NONE;
  524. wifi_link_info.sta_center_channel = 0;
  525. wifi_link_info.p2p_center_channel = 0;
  526. wifi_link_info.bany_client_join_go = _FALSE;
  527. wifi_link_info.benable_noa = _FALSE;
  528. wifi_link_info.bhotspot = _FALSE;
  529. for (i = 0; i < dvobj->iface_nums; i++) {
  530. iface = dvobj->padapters[i];
  531. if (!iface)
  532. continue;
  533. mlmeext = &iface->mlmeextpriv;
  534. if (MLME_IS_GO(iface)) {
  535. wifi_link_info.link_mode = BTC_LINK_ONLY_GO;
  536. wifi_link_info.p2p_center_channel =
  537. rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
  538. p2p_iface = iface;
  539. if (rtw_linked_check(iface))
  540. wifi_link_info.bany_client_join_go = _TRUE;
  541. } else if (MLME_IS_GC(iface)) {
  542. wifi_link_info.link_mode = BTC_LINK_ONLY_GC;
  543. wifi_link_info.p2p_center_channel =
  544. rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
  545. p2p_iface = iface;
  546. } else if (MLME_IS_AP(iface)) {
  547. wifi_link_info.link_mode = BTC_LINK_ONLY_AP;
  548. ap_iface = iface;
  549. wifi_link_info.p2p_center_channel =
  550. rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
  551. } else if (MLME_IS_STA(iface) && rtw_linked_check(iface)) {
  552. wifi_link_info.link_mode = BTC_LINK_ONLY_STA;
  553. wifi_link_info.sta_center_channel =
  554. rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
  555. sta_iface = iface;
  556. }
  557. }
  558. #ifdef CONFIG_MCC_MODE
  559. if (MCC_EN(adapter)) {
  560. if (rtw_hal_check_mcc_status(adapter, MCC_STATUS_DOING_MCC))
  561. mcc_en = _TRUE;
  562. }
  563. #endif/* CONFIG_MCC_MODE */
  564. if (n_assoc_iface == 0) {
  565. wifi_link_info.link_mode = BTC_LINK_NONE;
  566. } else if (n_assoc_iface == 1) {
  567. /* by pass */
  568. } else if (n_assoc_iface == 2) {
  569. if (sta_iface && p2p_iface) {
  570. u8 band_sta = sta_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
  571. u8 band_p2p = p2p_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
  572. if (band_sta == band_p2p) {
  573. switch (band_sta) {
  574. case BAND_ON_2_4G:
  575. if (MLME_IS_GO(p2p_iface))
  576. wifi_link_info.link_mode =
  577. mcc_en == _TRUE ? BTC_LINK_2G_MCC_GO_STA : BTC_LINK_2G_SCC_GO_STA;
  578. else if (MLME_IS_GC(p2p_iface))
  579. wifi_link_info.link_mode =
  580. mcc_en == _TRUE ? BTC_LINK_2G_MCC_GC_STA : BTC_LINK_2G_SCC_GC_STA;
  581. break;
  582. case BAND_ON_5G:
  583. if (MLME_IS_GO(p2p_iface))
  584. wifi_link_info.link_mode =
  585. mcc_en == _TRUE ? BTC_LINK_5G_MCC_GO_STA : BTC_LINK_5G_SCC_GO_STA;
  586. else if (MLME_IS_GC(p2p_iface))
  587. wifi_link_info.link_mode =
  588. mcc_en == _TRUE ? BTC_LINK_5G_MCC_GC_STA : BTC_LINK_5G_SCC_GC_STA;
  589. break;
  590. default:
  591. break;
  592. }
  593. } else {
  594. if (MLME_IS_GO(p2p_iface))
  595. wifi_link_info.link_mode = BTC_LINK_25G_MCC_GO_STA;
  596. else if (MLME_IS_GC(p2p_iface))
  597. wifi_link_info.link_mode = BTC_LINK_25G_MCC_GC_STA;
  598. }
  599. }
  600. } else {
  601. if (pBtCoexist->board_info.btdm_ant_num == 1)
  602. RTW_ERR("%s do not support n_assoc_iface > 2 (ant_num == 1)", __func__);
  603. }
  604. return wifi_link_info;
  605. }
  606. static void _btmpoper_timer_hdl(void *p)
  607. {
  608. if (GLBtcBtMpRptWait == _TRUE) {
  609. GLBtcBtMpRptWait = _FALSE;
  610. _rtw_up_sema(&GLBtcBtMpRptSema);
  611. }
  612. }
  613. /*
  614. * !IMPORTANT!
  615. * Before call this function, caller should acquire "GLBtcBtMpOperLock"!
  616. * Othrewise there will be racing problem and something may go wrong.
  617. */
  618. static u8 _btmpoper_cmd(PBTC_COEXIST pBtCoexist, u8 opcode, u8 opcodever, u8 *cmd, u8 size)
  619. {
  620. PADAPTER padapter;
  621. u8 buf[H2C_BTMP_OPER_LEN] = {0};
  622. u8 buflen;
  623. u8 seq;
  624. s32 ret;
  625. if (!cmd && size)
  626. size = 0;
  627. if ((size + 2) > H2C_BTMP_OPER_LEN)
  628. return BT_STATUS_H2C_LENGTH_EXCEEDED;
  629. buflen = size + 2;
  630. seq = GLBtcBtMpOperSeq & 0xF;
  631. GLBtcBtMpOperSeq++;
  632. buf[0] = (opcodever & 0xF) | (seq << 4);
  633. buf[1] = opcode;
  634. if (cmd && size)
  635. _rtw_memcpy(buf + 2, cmd, size);
  636. GLBtcBtMpRptWait = _TRUE;
  637. GLBtcBtMpRptWiFiOK = _FALSE;
  638. GLBtcBtMpRptBTOK = _FALSE;
  639. GLBtcBtMpRptStatus = 0;
  640. padapter = pBtCoexist->Adapter;
  641. _set_timer(&GLBtcBtMpOperTimer, BTC_MPOPER_TIMEOUT);
  642. if (rtw_hal_fill_h2c_cmd(padapter, H2C_BT_MP_OPER, buflen, buf) == _FAIL) {
  643. _cancel_timer_ex(&GLBtcBtMpOperTimer);
  644. ret = BT_STATUS_H2C_FAIL;
  645. goto exit;
  646. }
  647. _rtw_down_sema(&GLBtcBtMpRptSema);
  648. /* GLBtcBtMpRptWait should be _FALSE here*/
  649. if (GLBtcBtMpRptWiFiOK == _FALSE) {
  650. RTW_ERR("%s: Didn't get H2C Rsp Event!\n", __FUNCTION__);
  651. ret = BT_STATUS_H2C_TIMTOUT;
  652. goto exit;
  653. }
  654. if (GLBtcBtMpRptBTOK == _FALSE) {
  655. RTW_DBG("%s: Didn't get BT response!\n", __FUNCTION__);
  656. ret = BT_STATUS_H2C_BT_NO_RSP;
  657. goto exit;
  658. }
  659. if (seq != GLBtcBtMpRptSeq) {
  660. RTW_ERR("%s: Sequence number not match!(%d!=%d)!\n",
  661. __FUNCTION__, seq, GLBtcBtMpRptSeq);
  662. ret = BT_STATUS_C2H_REQNUM_MISMATCH;
  663. goto exit;
  664. }
  665. switch (GLBtcBtMpRptStatus) {
  666. /* Examine the status reported from C2H */
  667. case BT_STATUS_OK:
  668. ret = BT_STATUS_BT_OP_SUCCESS;
  669. RTW_DBG("%s: C2H status = BT_STATUS_BT_OP_SUCCESS\n", __FUNCTION__);
  670. break;
  671. case BT_STATUS_VERSION_MISMATCH:
  672. ret = BT_STATUS_OPCODE_L_VERSION_MISMATCH;
  673. RTW_DBG("%s: C2H status = BT_STATUS_OPCODE_L_VERSION_MISMATCH\n", __FUNCTION__);
  674. break;
  675. case BT_STATUS_UNKNOWN_OPCODE:
  676. ret = BT_STATUS_UNKNOWN_OPCODE_L;
  677. RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_OPCODE_L\n", __FUNCTION__);
  678. break;
  679. case BT_STATUS_ERROR_PARAMETER:
  680. ret = BT_STATUS_PARAMETER_FORMAT_ERROR_L;
  681. RTW_DBG("%s: C2H status = MP_BT_STATUS_PARAMETER_FORMAT_ERROR_L\n", __FUNCTION__);
  682. break;
  683. default:
  684. ret = BT_STATUS_UNKNOWN_STATUS_L;
  685. RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_STATUS_L\n", __FUNCTION__);
  686. break;
  687. }
  688. exit:
  689. return ret;
  690. }
  691. u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
  692. {
  693. if (pBtCoexist->bt_info.get_bt_fw_ver_cnt <= 5) {
  694. if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
  695. _irqL irqL;
  696. u8 ret;
  697. _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  698. ret = _btmpoper_cmd(pBtCoexist, BT_OP_GET_BT_VERSION, 0, NULL, 0);
  699. if (BT_STATUS_BT_OP_SUCCESS == ret) {
  700. pBtCoexist->bt_info.bt_real_fw_ver = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
  701. pBtCoexist->bt_info.bt_fw_ver = *(GLBtcBtMpRptRsp + 2);
  702. pBtCoexist->bt_info.get_bt_fw_ver_cnt++;
  703. }
  704. _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  705. } else {
  706. #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
  707. u1Byte dataLen = 2;
  708. u1Byte buf[4] = {0};
  709. buf[0] = 0x0; /* OP_Code */
  710. buf[1] = 0x0; /* OP_Code_Length */
  711. BT_SendEventExtBtCoexControl(pBtCoexist->Adapter, _FALSE, dataLen, &buf[0]);
  712. #endif /* !CONFIG_BT_COEXIST_SOCKET_TRX */
  713. }
  714. }
  715. exit:
  716. return pBtCoexist->bt_info.bt_real_fw_ver;
  717. }
  718. s32 halbtcoutsrc_GetWifiRssi(PADAPTER padapter)
  719. {
  720. return rtw_phydm_get_min_rssi(padapter);
  721. }
  722. u32 halbtcoutsrc_GetBtCoexSupportedFeature(void *pBtcContext)
  723. {
  724. PBTC_COEXIST pBtCoexist;
  725. u32 ret = BT_STATUS_BT_OP_SUCCESS;
  726. u32 data = 0;
  727. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  728. if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
  729. u8 buf[3] = {0};
  730. _irqL irqL;
  731. u8 op_code;
  732. u8 status;
  733. _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  734. op_code = BT_OP_GET_BT_COEX_SUPPORTED_FEATURE;
  735. status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
  736. if (status == BT_STATUS_BT_OP_SUCCESS)
  737. data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
  738. else
  739. ret = SET_BT_MP_OPER_RET(op_code, status);
  740. _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  741. } else
  742. ret = BT_STATUS_NOT_IMPLEMENT;
  743. return data;
  744. }
  745. u32 halbtcoutsrc_GetBtCoexSupportedVersion(void *pBtcContext)
  746. {
  747. PBTC_COEXIST pBtCoexist;
  748. u32 ret = BT_STATUS_BT_OP_SUCCESS;
  749. u32 data = 0xFFFF;
  750. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  751. if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
  752. u8 buf[3] = {0};
  753. _irqL irqL;
  754. u8 op_code;
  755. u8 status;
  756. _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  757. op_code = BT_OP_GET_BT_COEX_SUPPORTED_VERSION;
  758. status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
  759. if (status == BT_STATUS_BT_OP_SUCCESS)
  760. data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
  761. else
  762. ret = SET_BT_MP_OPER_RET(op_code, status);
  763. _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  764. } else
  765. ret = BT_STATUS_NOT_IMPLEMENT;
  766. return data;
  767. }
  768. u32 halbtcoutsrc_GetBtDeviceInfo(void *pBtcContext)
  769. {
  770. PBTC_COEXIST pBtCoexist;
  771. u32 ret = BT_STATUS_BT_OP_SUCCESS;
  772. u32 btDeviceInfo = 0;
  773. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  774. if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
  775. u8 buf[3] = {0};
  776. _irqL irqL;
  777. u8 op_code;
  778. u8 status;
  779. _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  780. op_code = BT_OP_GET_BT_DEVICE_INFO;
  781. status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
  782. if (status == BT_STATUS_BT_OP_SUCCESS)
  783. btDeviceInfo = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
  784. else
  785. ret = SET_BT_MP_OPER_RET(op_code, status);
  786. _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  787. } else
  788. ret = BT_STATUS_NOT_IMPLEMENT;
  789. return btDeviceInfo;
  790. }
  791. u32 halbtcoutsrc_GetBtForbiddenSlotVal(void *pBtcContext)
  792. {
  793. PBTC_COEXIST pBtCoexist;
  794. u32 ret = BT_STATUS_BT_OP_SUCCESS;
  795. u32 btForbiddenSlotVal = 0;
  796. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  797. if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
  798. u8 buf[3] = {0};
  799. _irqL irqL;
  800. u8 op_code;
  801. u8 status;
  802. _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  803. op_code = BT_OP_GET_BT_FORBIDDEN_SLOT_VAL;
  804. status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
  805. if (status == BT_STATUS_BT_OP_SUCCESS)
  806. btForbiddenSlotVal = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
  807. else
  808. ret = SET_BT_MP_OPER_RET(op_code, status);
  809. _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  810. } else
  811. ret = BT_STATUS_NOT_IMPLEMENT;
  812. return btForbiddenSlotVal;
  813. }
  814. static u8 halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)
  815. {
  816. struct mlme_priv *pmlmepriv;
  817. struct mlme_ext_priv *pmlmeext;
  818. static u8 scan_AP_num = 0;
  819. pmlmepriv = &padapter->mlmepriv;
  820. pmlmeext = &padapter->mlmeextpriv;
  821. if (GLBtcWiFiInScanState == _FALSE) {
  822. if (pmlmepriv->num_of_scanned > 0xFF)
  823. scan_AP_num = 0xFF;
  824. else
  825. scan_AP_num = (u8)pmlmepriv->num_of_scanned;
  826. }
  827. return scan_AP_num;
  828. }
  829. u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
  830. {
  831. PBTC_COEXIST pBtCoexist;
  832. PADAPTER padapter;
  833. PHAL_DATA_TYPE pHalData;
  834. struct mlme_ext_priv *mlmeext;
  835. struct btc_wifi_link_info *wifi_link_info;
  836. u8 bSoftApExist, bVwifiExist;
  837. u8 *pu8;
  838. s32 *pS4Tmp;
  839. u32 *pU4Tmp;
  840. u8 *pU1Tmp;
  841. u16 *pU2Tmp;
  842. u8 ret;
  843. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  844. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  845. return _FALSE;
  846. padapter = pBtCoexist->Adapter;
  847. pHalData = GET_HAL_DATA(padapter);
  848. mlmeext = &padapter->mlmeextpriv;
  849. bSoftApExist = _FALSE;
  850. bVwifiExist = _FALSE;
  851. pu8 = (u8 *)pOutBuf;
  852. pS4Tmp = (s32 *)pOutBuf;
  853. pU4Tmp = (u32 *)pOutBuf;
  854. pU1Tmp = (u8 *)pOutBuf;
  855. pU2Tmp = (u16*)pOutBuf;
  856. wifi_link_info = (struct btc_wifi_link_info *)pOutBuf;
  857. ret = _TRUE;
  858. switch (getType) {
  859. case BTC_GET_BL_HS_OPERATION:
  860. *pu8 = _FALSE;
  861. ret = _FALSE;
  862. break;
  863. case BTC_GET_BL_HS_CONNECTING:
  864. *pu8 = _FALSE;
  865. ret = _FALSE;
  866. break;
  867. case BTC_GET_BL_WIFI_FW_READY:
  868. *pu8 = halbtcoutsrc_is_fw_ready(pBtCoexist);
  869. break;
  870. case BTC_GET_BL_WIFI_CONNECTED:
  871. *pu8 = (rtw_mi_check_status(padapter, MI_LINKED)) ? _TRUE : _FALSE;
  872. break;
  873. case BTC_GET_BL_WIFI_DUAL_BAND_CONNECTED:
  874. *pu8 = halbtcoutsrc_IsDualBandConnected(padapter);
  875. break;
  876. case BTC_GET_BL_WIFI_BUSY:
  877. *pu8 = halbtcoutsrc_IsWifiBusy(padapter);
  878. break;
  879. case BTC_GET_BL_WIFI_SCAN:
  880. #if 0
  881. *pu8 = (rtw_mi_check_fwstate(padapter, WIFI_SITE_MONITOR)) ? _TRUE : _FALSE;
  882. #else
  883. /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag
  884. WIFI_SITE_MONITOR in fwstate may not be cleared in time */
  885. *pu8 = GLBtcWiFiInScanState;
  886. #endif
  887. break;
  888. case BTC_GET_BL_WIFI_LINK:
  889. *pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE;
  890. break;
  891. case BTC_GET_BL_WIFI_ROAM:
  892. *pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE;
  893. break;
  894. case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
  895. *pu8 = _FALSE;
  896. break;
  897. case BTC_GET_BL_WIFI_UNDER_5G:
  898. *pu8 = (pHalData->current_band_type == BAND_ON_5G) ? _TRUE : _FALSE;
  899. break;
  900. case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
  901. *pu8 = (rtw_mi_check_status(padapter, MI_AP_MODE)) ? _TRUE : _FALSE;
  902. break;
  903. case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
  904. *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0 ? _FALSE : _TRUE;
  905. break;
  906. case BTC_GET_BL_WIFI_UNDER_B_MODE:
  907. if (mlmeext->cur_wireless_mode == WIRELESS_11B)
  908. *pu8 = _TRUE;
  909. else
  910. *pu8 = _FALSE;
  911. break;
  912. case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
  913. if (padapter->registrypriv.mp_mode == 0)
  914. *pu8 = _FALSE;
  915. else
  916. *pu8 = _TRUE;
  917. break;
  918. case BTC_GET_BL_EXT_SWITCH:
  919. *pu8 = _FALSE;
  920. break;
  921. case BTC_GET_BL_IS_ASUS_8723B:
  922. /* Always return FALSE in linux driver since this case is added only for windows driver */
  923. *pu8 = _FALSE;
  924. break;
  925. case BTC_GET_BL_RF4CE_CONNECTED:
  926. #ifdef CONFIG_RF4CE_COEXIST
  927. if (hal_btcoex_get_rf4ce_link_state() == 0)
  928. *pu8 = FALSE;
  929. else
  930. *pu8 = TRUE;
  931. #else
  932. *pu8 = FALSE;
  933. #endif
  934. break;
  935. case BTC_GET_BL_WIFI_LW_PWR_STATE:
  936. /* return false due to coex do not run during 32K */
  937. *pu8 = FALSE;
  938. break;
  939. case BTC_GET_S4_WIFI_RSSI:
  940. *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
  941. break;
  942. case BTC_GET_S4_HS_RSSI:
  943. *pS4Tmp = 0;
  944. ret = _FALSE;
  945. break;
  946. case BTC_GET_U4_WIFI_BW:
  947. if (IsLegacyOnly(mlmeext->cur_wireless_mode))
  948. *pU4Tmp = BTC_WIFI_BW_LEGACY;
  949. else {
  950. switch (pHalData->current_channel_bw) {
  951. case CHANNEL_WIDTH_20:
  952. *pU4Tmp = BTC_WIFI_BW_HT20;
  953. break;
  954. case CHANNEL_WIDTH_40:
  955. *pU4Tmp = BTC_WIFI_BW_HT40;
  956. break;
  957. case CHANNEL_WIDTH_80:
  958. *pU4Tmp = BTC_WIFI_BW_HT80;
  959. break;
  960. case CHANNEL_WIDTH_160:
  961. *pU4Tmp = BTC_WIFI_BW_HT160;
  962. break;
  963. default:
  964. RTW_INFO("[BTCOEX] unknown bandwidth(%d)\n", pHalData->current_channel_bw);
  965. *pU4Tmp = BTC_WIFI_BW_HT40;
  966. break;
  967. }
  968. }
  969. break;
  970. case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION: {
  971. PRT_LINK_DETECT_T plinkinfo;
  972. plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
  973. if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
  974. *pU4Tmp = BTC_WIFI_TRAFFIC_TX;
  975. else
  976. *pU4Tmp = BTC_WIFI_TRAFFIC_RX;
  977. }
  978. break;
  979. case BTC_GET_U4_WIFI_FW_VER:
  980. *pU4Tmp = pHalData->firmware_version << 16;
  981. *pU4Tmp |= pHalData->firmware_sub_version;
  982. break;
  983. case BTC_GET_U4_WIFI_LINK_STATUS:
  984. *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
  985. break;
  986. case BTC_GET_BL_WIFI_LINK_INFO:
  987. *wifi_link_info = halbtcoutsrc_getwifilinkinfo(pBtCoexist);
  988. break;
  989. case BTC_GET_U4_BT_PATCH_VER:
  990. *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
  991. break;
  992. case BTC_GET_U4_VENDOR:
  993. *pU4Tmp = BTC_VENDOR_OTHER;
  994. break;
  995. case BTC_GET_U4_SUPPORTED_VERSION:
  996. *pU4Tmp = halbtcoutsrc_GetBtCoexSupportedVersion(pBtCoexist);
  997. break;
  998. case BTC_GET_U4_SUPPORTED_FEATURE:
  999. *pU4Tmp = halbtcoutsrc_GetBtCoexSupportedFeature(pBtCoexist);
  1000. break;
  1001. case BTC_GET_U4_BT_DEVICE_INFO:
  1002. *pU4Tmp = halbtcoutsrc_GetBtDeviceInfo(pBtCoexist);
  1003. break;
  1004. case BTC_GET_U4_BT_FORBIDDEN_SLOT_VAL:
  1005. *pU4Tmp = halbtcoutsrc_GetBtForbiddenSlotVal(pBtCoexist);
  1006. break;
  1007. case BTC_GET_U4_WIFI_IQK_TOTAL:
  1008. *pU4Tmp = pHalData->odmpriv.n_iqk_cnt;
  1009. break;
  1010. case BTC_GET_U4_WIFI_IQK_OK:
  1011. *pU4Tmp = pHalData->odmpriv.n_iqk_ok_cnt;
  1012. break;
  1013. case BTC_GET_U4_WIFI_IQK_FAIL:
  1014. *pU4Tmp = pHalData->odmpriv.n_iqk_fail_cnt;
  1015. break;
  1016. case BTC_GET_U1_WIFI_DOT11_CHNL:
  1017. *pU1Tmp = padapter->mlmeextpriv.cur_channel;
  1018. break;
  1019. case BTC_GET_U1_WIFI_CENTRAL_CHNL:
  1020. *pU1Tmp = pHalData->current_channel;
  1021. break;
  1022. case BTC_GET_U1_WIFI_HS_CHNL:
  1023. *pU1Tmp = 0;
  1024. ret = _FALSE;
  1025. break;
  1026. case BTC_GET_U1_WIFI_P2P_CHNL:
  1027. #ifdef CONFIG_P2P
  1028. {
  1029. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  1030. *pU1Tmp = pwdinfo->operating_channel;
  1031. }
  1032. #else
  1033. *pU1Tmp = 0;
  1034. #endif
  1035. break;
  1036. case BTC_GET_U1_MAC_PHY_MODE:
  1037. /* *pU1Tmp = BTC_SMSP;
  1038. * *pU1Tmp = BTC_DMSP;
  1039. * *pU1Tmp = BTC_DMDP;
  1040. * *pU1Tmp = BTC_MP_UNKNOWN; */
  1041. break;
  1042. case BTC_GET_U1_AP_NUM:
  1043. *pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);
  1044. break;
  1045. case BTC_GET_U1_ANT_TYPE:
  1046. switch (pHalData->bt_coexist.btAntisolation) {
  1047. case 0:
  1048. *pU1Tmp = (u1Byte)BTC_ANT_TYPE_0;
  1049. pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_0;
  1050. break;
  1051. case 1:
  1052. *pU1Tmp = (u1Byte)BTC_ANT_TYPE_1;
  1053. pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_1;
  1054. break;
  1055. case 2:
  1056. *pU1Tmp = (u1Byte)BTC_ANT_TYPE_2;
  1057. pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_2;
  1058. break;
  1059. case 3:
  1060. *pU1Tmp = (u1Byte)BTC_ANT_TYPE_3;
  1061. pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_3;
  1062. break;
  1063. case 4:
  1064. *pU1Tmp = (u1Byte)BTC_ANT_TYPE_4;
  1065. pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_4;
  1066. break;
  1067. }
  1068. break;
  1069. case BTC_GET_U1_IOT_PEER:
  1070. *pU1Tmp = mlmeext->mlmext_info.assoc_AP_vendor;
  1071. break;
  1072. /* =======1Ant=========== */
  1073. case BTC_GET_U1_LPS_MODE:
  1074. *pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;
  1075. break;
  1076. case BTC_GET_U2_BEACON_PERIOD:
  1077. *pU2Tmp = mlmeext->mlmext_info.bcn_interval;
  1078. break;
  1079. default:
  1080. ret = _FALSE;
  1081. break;
  1082. }
  1083. return ret;
  1084. }
  1085. u16 halbtcoutsrc_LnaConstrainLvl(void *pBtcContext, u8 *lna_constrain_level)
  1086. {
  1087. PBTC_COEXIST pBtCoexist;
  1088. u16 ret = BT_STATUS_BT_OP_SUCCESS;
  1089. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1090. if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
  1091. _irqL irqL;
  1092. u8 op_code;
  1093. _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  1094. ret = _btmpoper_cmd(pBtCoexist, BT_OP_SET_BT_LANCONSTRAIN_LEVEL, 0, lna_constrain_level, 1);
  1095. _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  1096. } else {
  1097. ret = BT_STATUS_NOT_IMPLEMENT;
  1098. RTW_INFO("%s halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == FALSE\n", __func__);
  1099. }
  1100. return ret;
  1101. }
  1102. u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
  1103. {
  1104. PBTC_COEXIST pBtCoexist;
  1105. PADAPTER padapter;
  1106. PHAL_DATA_TYPE pHalData;
  1107. u8 *pu8;
  1108. u8 *pU1Tmp;
  1109. u32 *pU4Tmp;
  1110. u8 ret;
  1111. u8 result = _TRUE;
  1112. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1113. padapter = pBtCoexist->Adapter;
  1114. pHalData = GET_HAL_DATA(padapter);
  1115. pu8 = (u8 *)pInBuf;
  1116. pU1Tmp = (u8 *)pInBuf;
  1117. pU4Tmp = (u32 *)pInBuf;
  1118. ret = _TRUE;
  1119. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  1120. return _FALSE;
  1121. switch (setType) {
  1122. /* set some u8 type variables. */
  1123. case BTC_SET_BL_BT_DISABLE:
  1124. pBtCoexist->bt_info.bt_disabled = *pu8;
  1125. break;
  1126. case BTC_SET_BL_BT_ENABLE_DISABLE_CHANGE:
  1127. pBtCoexist->bt_info.bt_enable_disable_change = *pu8;
  1128. break;
  1129. case BTC_SET_BL_BT_TRAFFIC_BUSY:
  1130. pBtCoexist->bt_info.bt_busy = *pu8;
  1131. break;
  1132. case BTC_SET_BL_BT_LIMITED_DIG:
  1133. pBtCoexist->bt_info.limited_dig = *pu8;
  1134. break;
  1135. case BTC_SET_BL_FORCE_TO_ROAM:
  1136. pBtCoexist->bt_info.force_to_roam = *pu8;
  1137. break;
  1138. case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
  1139. pBtCoexist->bt_info.reject_agg_pkt = *pu8;
  1140. break;
  1141. case BTC_SET_BL_BT_CTRL_AGG_SIZE:
  1142. pBtCoexist->bt_info.bt_ctrl_agg_buf_size = *pu8;
  1143. break;
  1144. case BTC_SET_BL_INC_SCAN_DEV_NUM:
  1145. pBtCoexist->bt_info.increase_scan_dev_num = *pu8;
  1146. break;
  1147. case BTC_SET_BL_BT_TX_RX_MASK:
  1148. pBtCoexist->bt_info.bt_tx_rx_mask = *pu8;
  1149. break;
  1150. case BTC_SET_BL_MIRACAST_PLUS_BT:
  1151. pBtCoexist->bt_info.miracast_plus_bt = *pu8;
  1152. break;
  1153. /* set some u8 type variables. */
  1154. case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
  1155. pBtCoexist->bt_info.rssi_adjust_for_agc_table_on = *pU1Tmp;
  1156. break;
  1157. case BTC_SET_U1_AGG_BUF_SIZE:
  1158. pBtCoexist->bt_info.agg_buf_size = *pU1Tmp;
  1159. break;
  1160. /* the following are some action which will be triggered */
  1161. case BTC_SET_ACT_GET_BT_RSSI:
  1162. #if 0
  1163. BT_SendGetBtRssiEvent(padapter);
  1164. #else
  1165. ret = _FALSE;
  1166. #endif
  1167. break;
  1168. case BTC_SET_ACT_AGGREGATE_CTRL:
  1169. halbtcoutsrc_AggregationCheck(pBtCoexist);
  1170. break;
  1171. /* =======1Ant=========== */
  1172. /* set some u8 type variables. */
  1173. case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
  1174. pBtCoexist->bt_info.rssi_adjust_for_1ant_coex_type = *pU1Tmp;
  1175. break;
  1176. case BTC_SET_U1_LPS_VAL:
  1177. pBtCoexist->bt_info.lps_val = *pU1Tmp;
  1178. break;
  1179. case BTC_SET_U1_RPWM_VAL:
  1180. pBtCoexist->bt_info.rpwm_val = *pU1Tmp;
  1181. break;
  1182. /* the following are some action which will be triggered */
  1183. case BTC_SET_ACT_LEAVE_LPS:
  1184. result = halbtcoutsrc_LeaveLps(pBtCoexist);
  1185. break;
  1186. case BTC_SET_ACT_ENTER_LPS:
  1187. halbtcoutsrc_EnterLps(pBtCoexist);
  1188. break;
  1189. case BTC_SET_ACT_NORMAL_LPS:
  1190. halbtcoutsrc_NormalLps(pBtCoexist);
  1191. break;
  1192. case BTC_SET_ACT_PRE_NORMAL_LPS:
  1193. halbtcoutsrc_Pre_NormalLps(pBtCoexist);
  1194. break;
  1195. case BTC_SET_ACT_POST_NORMAL_LPS:
  1196. halbtcoutsrc_Post_NormalLps(pBtCoexist);
  1197. break;
  1198. case BTC_SET_ACT_DISABLE_LOW_POWER:
  1199. halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
  1200. break;
  1201. case BTC_SET_ACT_UPDATE_RAMASK:
  1202. /*
  1203. pBtCoexist->bt_info.ra_mask = *pU4Tmp;
  1204. if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _TRUE) {
  1205. struct sta_info *psta;
  1206. PWLAN_BSSID_EX cur_network;
  1207. cur_network = &padapter->mlmeextpriv.mlmext_info.network;
  1208. psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress);
  1209. rtw_hal_update_ra_mask(psta);
  1210. }
  1211. */
  1212. break;
  1213. case BTC_SET_ACT_SEND_MIMO_PS: {
  1214. u8 newMimoPsMode = 3;
  1215. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1216. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  1217. /* *pU1Tmp = 0 use SM_PS static type */
  1218. /* *pU1Tmp = 1 disable SM_PS */
  1219. if (*pU1Tmp == 0)
  1220. newMimoPsMode = WLAN_HT_CAP_SM_PS_STATIC;
  1221. else if (*pU1Tmp == 1)
  1222. newMimoPsMode = WLAN_HT_CAP_SM_PS_DISABLED;
  1223. if (check_fwstate(&padapter->mlmepriv , WIFI_ASOC_STATE) == _TRUE) {
  1224. /* issue_action_SM_PS(padapter, get_my_bssid(&(pmlmeinfo->network)), newMimoPsMode); */
  1225. issue_action_SM_PS_wait_ack(padapter , get_my_bssid(&(pmlmeinfo->network)) , newMimoPsMode, 3 , 1);
  1226. }
  1227. }
  1228. break;
  1229. case BTC_SET_ACT_CTRL_BT_INFO:
  1230. #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
  1231. {
  1232. u8 dataLen = *pU1Tmp;
  1233. u8 tmpBuf[BTC_TMP_BUF_SHORT];
  1234. if (dataLen)
  1235. _rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen);
  1236. BT_SendEventExtBtInfoControl(padapter, dataLen, &tmpBuf[0]);
  1237. }
  1238. #else /* !CONFIG_BT_COEXIST_SOCKET_TRX */
  1239. ret = _FALSE;
  1240. #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
  1241. break;
  1242. case BTC_SET_ACT_CTRL_BT_COEX:
  1243. #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
  1244. {
  1245. u8 dataLen = *pU1Tmp;
  1246. u8 tmpBuf[BTC_TMP_BUF_SHORT];
  1247. if (dataLen)
  1248. _rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen);
  1249. BT_SendEventExtBtCoexControl(padapter, _FALSE, dataLen, &tmpBuf[0]);
  1250. }
  1251. #else /* !CONFIG_BT_COEXIST_SOCKET_TRX */
  1252. ret = _FALSE;
  1253. #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
  1254. break;
  1255. case BTC_SET_ACT_CTRL_8723B_ANT:
  1256. #if 0
  1257. {
  1258. u1Byte dataLen = *pU1Tmp;
  1259. u1Byte tmpBuf[BTC_TMP_BUF_SHORT];
  1260. if (dataLen)
  1261. PlatformMoveMemory(&tmpBuf[0], pU1Tmp + 1, dataLen);
  1262. BT_Set8723bAnt(Adapter, dataLen, &tmpBuf[0]);
  1263. }
  1264. #else
  1265. ret = _FALSE;
  1266. #endif
  1267. break;
  1268. case BTC_SET_BL_BT_LNA_CONSTRAIN_LEVEL:
  1269. halbtcoutsrc_LnaConstrainLvl(pBtCoexist, pu8);
  1270. break;
  1271. /* ===================== */
  1272. default:
  1273. ret = _FALSE;
  1274. break;
  1275. }
  1276. return result;
  1277. }
  1278. u8 halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)
  1279. {
  1280. PADAPTER padapter;
  1281. struct pwrctrl_priv *pwrpriv;
  1282. u8 bMacPwrCtrlOn;
  1283. padapter = pBtCoexist->Adapter;
  1284. pwrpriv = &padapter->dvobj->pwrctl_priv;
  1285. bMacPwrCtrlOn = _FALSE;
  1286. if ((_TRUE == pwrpriv->bips_processing)
  1287. && (IPS_NONE != pwrpriv->ips_mode_req)
  1288. )
  1289. return _TRUE;
  1290. if (rf_off == pwrpriv->rf_pwrstate)
  1291. return _TRUE;
  1292. rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
  1293. if (_FALSE == bMacPwrCtrlOn)
  1294. return _TRUE;
  1295. return _FALSE;
  1296. }
  1297. u8 halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)
  1298. {
  1299. return GLBtcWiFiInLPS;
  1300. }
  1301. u8 halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)
  1302. {
  1303. /* todo: the method to check whether wifi is under 32K or not */
  1304. return _FALSE;
  1305. }
  1306. void halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)
  1307. {
  1308. #if 0
  1309. PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
  1310. PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
  1311. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
  1312. u8 *cliBuf = pBtCoexist->cliBuf;
  1313. u1Byte i, j;
  1314. u1Byte tmpbuf[BTC_TMP_BUF_SHORT];
  1315. if (gl_coex_offload.cnt_h2c_sent) {
  1316. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex h2c notify]============");
  1317. CL_PRINTF(cliBuf);
  1318. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = H2c(%d)/Ack(%d)", "Coex h2c/c2h overall statistics",
  1319. gl_coex_offload.cnt_h2c_sent, gl_coex_offload.cnt_c2h_ack);
  1320. for (j = 0; j < COL_STATUS_MAX; j++) {
  1321. if (gl_coex_offload.status[j]) {
  1322. CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.status[j]);
  1323. CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
  1324. }
  1325. }
  1326. CL_PRINTF(cliBuf);
  1327. }
  1328. for (i = 0; i < COL_OP_WIFI_OPCODE_MAX; i++) {
  1329. if (gl_coex_offload.h2c_record[i].count) {
  1330. /*==========================================*/
  1331. /* H2C result statistics*/
  1332. /*==========================================*/
  1333. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = total:%d", coexOpcodeString[i], gl_coex_offload.h2c_record[i].count);
  1334. for (j = 0; j < COL_STATUS_MAX; j++) {
  1335. if (gl_coex_offload.h2c_record[i].status[j]) {
  1336. CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.h2c_record[i].status[j]);
  1337. CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
  1338. }
  1339. }
  1340. CL_PRINTF(cliBuf);
  1341. /*==========================================*/
  1342. /* H2C/C2H content*/
  1343. /*==========================================*/
  1344. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = ", "H2C / C2H content");
  1345. for (j = 0; j < gl_coex_offload.h2c_record[i].h2c_len; j++) {
  1346. CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.h2c_record[i].h2c_buf[j]);
  1347. CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
  1348. }
  1349. if (gl_coex_offload.h2c_record[i].c2h_ack_len) {
  1350. CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, "/ ", 2);
  1351. for (j = 0; j < gl_coex_offload.h2c_record[i].c2h_ack_len; j++) {
  1352. CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.h2c_record[i].c2h_ack_buf[j]);
  1353. CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
  1354. }
  1355. }
  1356. CL_PRINTF(cliBuf);
  1357. /*==========================================*/
  1358. }
  1359. }
  1360. if (gl_coex_offload.cnt_c2h_ind) {
  1361. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex c2h indication]============");
  1362. CL_PRINTF(cliBuf);
  1363. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = Ind(%d)", "C2H indication statistics",
  1364. gl_coex_offload.cnt_c2h_ind);
  1365. for (j = 0; j < COL_STATUS_MAX; j++) {
  1366. if (gl_coex_offload.c2h_ind_status[j]) {
  1367. CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.c2h_ind_status[j]);
  1368. CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
  1369. }
  1370. }
  1371. CL_PRINTF(cliBuf);
  1372. }
  1373. for (i = 0; i < COL_IND_MAX; i++) {
  1374. if (gl_coex_offload.c2h_ind_record[i].count) {
  1375. /*==========================================*/
  1376. /* H2C result statistics*/
  1377. /*==========================================*/
  1378. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = total:%d", coexIndTypeString[i], gl_coex_offload.c2h_ind_record[i].count);
  1379. for (j = 0; j < COL_STATUS_MAX; j++) {
  1380. if (gl_coex_offload.c2h_ind_record[i].status[j]) {
  1381. CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.c2h_ind_record[i].status[j]);
  1382. CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
  1383. }
  1384. }
  1385. CL_PRINTF(cliBuf);
  1386. /*==========================================*/
  1387. /* content*/
  1388. /*==========================================*/
  1389. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = ", "C2H indication content");
  1390. for (j = 0; j < gl_coex_offload.c2h_ind_record[i].ind_len; j++) {
  1391. CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.c2h_ind_record[i].ind_buf[j]);
  1392. CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
  1393. }
  1394. CL_PRINTF(cliBuf);
  1395. /*==========================================*/
  1396. }
  1397. }
  1398. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Statistics]============");
  1399. CL_PRINTF(cliBuf);
  1400. #if (H2C_USE_IO_THREAD != 1)
  1401. for (i = 0; i < H2C_STATUS_MAX; i++) {
  1402. if (pHalData->h2cStatistics[i]) {
  1403. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
  1404. h2cStaString[i], pHalData->h2cStatistics[i]);
  1405. CL_PRINTF(cliBuf);
  1406. }
  1407. }
  1408. #else
  1409. for (i = 0; i < IO_STATUS_MAX; i++) {
  1410. if (Adapter->ioComStr.ioH2cStatistics[i]) {
  1411. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
  1412. ioStaString[i], Adapter->ioComStr.ioH2cStatistics[i]);
  1413. CL_PRINTF(cliBuf);
  1414. }
  1415. }
  1416. #endif
  1417. #if 0
  1418. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
  1419. pHalData->LastHMEBoxNum);
  1420. CL_PRINTF(cliBuf);
  1421. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "LastOkH2c/FirstFailH2c(fwNotRead)", \
  1422. pHalData->lastSuccessH2cEid, pHalData->firstFailedH2cEid);
  1423. CL_PRINTF(cliBuf);
  1424. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "c2hIsr/c2hIntr/clr1AF/noRdy/noBuf", \
  1425. pHalData->InterruptLog.nIMR_C2HCMD, DBG_Var.c2hInterruptCnt, DBG_Var.c2hClrReadC2hCnt,
  1426. DBG_Var.c2hNotReadyCnt, DBG_Var.c2hBufAlloFailCnt);
  1427. CL_PRINTF(cliBuf);
  1428. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "c2hPacket", \
  1429. DBG_Var.c2hPacketCnt);
  1430. CL_PRINTF(cliBuf);
  1431. #endif
  1432. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Periodical/ DbgCtrl", \
  1433. pBtCoexist->statistics.cntPeriodical, pBtCoexist->statistics.cntDbgCtrl);
  1434. CL_PRINTF(cliBuf);
  1435. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "PowerOn/InitHw/InitCoexDm/RfStatus", \
  1436. pBtCoexist->statistics.cntPowerOn, pBtCoexist->statistics.cntInitHwConfig, pBtCoexist->statistics.cntInitCoexDm,
  1437. pBtCoexist->statistics.cntRfStatusNotify);
  1438. CL_PRINTF(cliBuf);
  1439. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "Ips/Lps/Scan/Connect/Mstatus", \
  1440. pBtCoexist->statistics.cntIpsNotify, pBtCoexist->statistics.cntLpsNotify,
  1441. pBtCoexist->statistics.cntScanNotify, pBtCoexist->statistics.cntConnectNotify,
  1442. pBtCoexist->statistics.cntMediaStatusNotify);
  1443. CL_PRINTF(cliBuf);
  1444. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Special pkt/Bt info/ bind",
  1445. pBtCoexist->statistics.cntSpecialPacketNotify, pBtCoexist->statistics.cntBtInfoNotify,
  1446. pBtCoexist->statistics.cntBind);
  1447. CL_PRINTF(cliBuf);
  1448. #endif
  1449. PADAPTER padapter = pBtCoexist->Adapter;
  1450. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
  1451. u8 *cliBuf = pBtCoexist->cli_buf;
  1452. if (pHalData->EEPROMBluetoothCoexist == 1) {
  1453. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex Status]============");
  1454. CL_PRINTF(cliBuf);
  1455. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtDisabled", rtw_btcoex_IsBtDisabled(padapter));
  1456. CL_PRINTF(cliBuf);
  1457. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtControlLps", rtw_btcoex_IsBtControlLps(padapter));
  1458. CL_PRINTF(cliBuf);
  1459. }
  1460. }
  1461. void halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)
  1462. {
  1463. #if 0
  1464. PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
  1465. PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
  1466. u8 *cliBuf = pBtCoexist->cliBuf;
  1467. u8 i;
  1468. if (pBtCoexist->stack_info.profile_notified) {
  1469. for (i = 0; i < pBtMgnt->ExtConfig.NumberOfACL; i++) {
  1470. if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
  1471. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role", \
  1472. BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
  1473. BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec],
  1474. BtLinkRoleString[pBtMgnt->ExtConfig.aclLink[i].linkRole]);
  1475. CL_PRINTF(cliBuf);
  1476. } else {
  1477. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
  1478. BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
  1479. BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec]);
  1480. CL_PRINTF(cliBuf);
  1481. }
  1482. }
  1483. }
  1484. #endif
  1485. }
  1486. void halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)
  1487. {
  1488. PADAPTER padapter = pBtCoexist->Adapter;
  1489. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  1490. u8 *cliBuf = pBtCoexist->cli_buf;
  1491. s32 wifiRssi = 0, btHsRssi = 0;
  1492. BOOLEAN bScan = _FALSE, bLink = _FALSE, bRoam = _FALSE, bWifiBusy = _FALSE, bWifiUnderBMode = _FALSE;
  1493. u32 wifiBw = BTC_WIFI_BW_HT20, wifiTrafficDir = BTC_WIFI_TRAFFIC_TX, wifiFreq = BTC_FREQ_2_4G;
  1494. u32 wifiLinkStatus = 0x0;
  1495. BOOLEAN bBtHsOn = _FALSE, bLowPower = _FALSE;
  1496. u8 wifiChnl = 0, wifiP2PChnl = 0, nScanAPNum = 0, FwPSState;
  1497. u32 iqk_cnt_total = 0, iqk_cnt_ok = 0, iqk_cnt_fail = 0;
  1498. u16 wifiBcnInterval = 0;
  1499. PHAL_DATA_TYPE hal = GET_HAL_DATA(padapter);
  1500. struct btc_wifi_link_info wifi_link_info;
  1501. wifi_link_info = halbtcoutsrc_getwifilinkinfo(pBtCoexist);
  1502. switch (wifi_link_info.link_mode) {
  1503. case BTC_LINK_NONE:
  1504. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1505. "None", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1506. wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;
  1507. break;
  1508. case BTC_LINK_ONLY_GO:
  1509. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1510. "ONLY_GO", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1511. wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;
  1512. break;
  1513. case BTC_LINK_ONLY_GC:
  1514. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1515. "ONLY_GC", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1516. wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;
  1517. break;
  1518. case BTC_LINK_ONLY_STA:
  1519. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1520. "ONLY_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1521. wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;
  1522. break;
  1523. case BTC_LINK_ONLY_AP:
  1524. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1525. "ONLY_AP", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1526. wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;
  1527. break;
  1528. case BTC_LINK_2G_MCC_GO_STA:
  1529. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1530. "24G_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1531. wifiFreq = BTC_FREQ_2_4G;
  1532. break;
  1533. case BTC_LINK_5G_MCC_GO_STA:
  1534. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1535. "5G_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1536. wifiFreq = BTC_FREQ_5G;
  1537. break;
  1538. case BTC_LINK_25G_MCC_GO_STA:
  1539. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1540. "2BANDS_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1541. wifiFreq = BTC_FREQ_25G;
  1542. break;
  1543. case BTC_LINK_2G_MCC_GC_STA:
  1544. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1545. "24G_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1546. wifiFreq = BTC_FREQ_2_4G;
  1547. break;
  1548. case BTC_LINK_5G_MCC_GC_STA:
  1549. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1550. "5G_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1551. wifiFreq = BTC_FREQ_5G;
  1552. break;
  1553. case BTC_LINK_25G_MCC_GC_STA:
  1554. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1555. "2BANDS_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1556. wifiFreq = BTC_FREQ_25G;
  1557. break;
  1558. case BTC_LINK_2G_SCC_GO_STA:
  1559. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1560. "24G_SCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1561. wifiFreq = BTC_FREQ_2_4G;
  1562. break;
  1563. case BTC_LINK_5G_SCC_GO_STA:
  1564. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1565. "5G_SCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1566. wifiFreq = BTC_FREQ_5G;
  1567. break;
  1568. case BTC_LINK_2G_SCC_GC_STA:
  1569. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1570. "24G_SCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1571. wifiFreq = BTC_FREQ_2_4G;
  1572. break;
  1573. case BTC_LINK_5G_SCC_GC_STA:
  1574. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1575. "5G_SCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1576. wifiFreq = BTC_FREQ_5G;
  1577. break;
  1578. default:
  1579. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
  1580. "UNKNOWN", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
  1581. wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;
  1582. break;
  1583. }
  1584. CL_PRINTF(cliBuf);
  1585. wifiLinkStatus = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
  1586. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "STA/vWifi/HS/p2pGo/p2pGc",
  1587. ((wifiLinkStatus & WIFI_STA_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_AP_CONNECTED) ? 1 : 0),
  1588. ((wifiLinkStatus & WIFI_HS_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
  1589. ((wifiLinkStatus & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
  1590. CL_PRINTF(cliBuf);
  1591. pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
  1592. pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
  1593. pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
  1594. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Link/ Roam/ Scan",
  1595. bLink, bRoam, bScan);
  1596. CL_PRINTF(cliBuf);
  1597. pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_TOTAL, &iqk_cnt_total);
  1598. pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_OK, &iqk_cnt_ok);
  1599. pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_FAIL, &iqk_cnt_fail);
  1600. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d %s %s",
  1601. "IQK All/ OK/ Fail/AutoLoad/FWDL", iqk_cnt_total, iqk_cnt_ok, iqk_cnt_fail,
  1602. ((halbtcoutsrc_is_autoload_fail(pBtCoexist) == _TRUE) ? "fail":"ok"), ((halbtcoutsrc_is_fw_ready(pBtCoexist) == _TRUE) ? "ok":"fail"));
  1603. CL_PRINTF(cliBuf);
  1604. if (wifiLinkStatus & WIFI_STA_CONNECTED) {
  1605. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "IOT Peer", GLBtcIotPeerString[padapter->mlmeextpriv.mlmext_info.assoc_AP_vendor]);
  1606. CL_PRINTF(cliBuf);
  1607. }
  1608. pBtCoexist->btc_get(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
  1609. pBtCoexist->btc_get(pBtCoexist, BTC_GET_U2_BEACON_PERIOD, &wifiBcnInterval);
  1610. wifiChnl = wifi_link_info.sta_center_channel;
  1611. wifiP2PChnl = wifi_link_info.p2p_center_channel;
  1612. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dBm/ %d/ %d/ %d", "RSSI/ STA_Chnl/ P2P_Chnl/ BI",
  1613. wifiRssi-100, wifiChnl, wifiP2PChnl, wifiBcnInterval);
  1614. CL_PRINTF(cliBuf);
  1615. pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
  1616. pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
  1617. pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
  1618. pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
  1619. pBtCoexist->btc_get(pBtCoexist, BTC_GET_U1_AP_NUM, &nScanAPNum);
  1620. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s/ %d ", "Band/ BW/ Traffic/ APCnt",
  1621. GLBtcWifiFreqString[wifiFreq], ((bWifiUnderBMode) ? "11b" : GLBtcWifiBwString[wifiBw]),
  1622. ((!bWifiBusy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX == wifiTrafficDir) ? "uplink" : "downlink")),
  1623. nScanAPNum);
  1624. CL_PRINTF(cliBuf);
  1625. /* power status */
  1626. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s%s%s", "Power Status", \
  1627. ((halbtcoutsrc_UnderIps(pBtCoexist) == _TRUE) ? "IPS ON" : "IPS OFF"),
  1628. ((halbtcoutsrc_UnderLps(pBtCoexist) == _TRUE) ? ", LPS ON" : ", LPS OFF"),
  1629. ((halbtcoutsrc_Under32K(pBtCoexist) == _TRUE) ? ", 32k" : ""));
  1630. CL_PRINTF(cliBuf);
  1631. CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)", "Power mode cmd(lps/rpwm)",
  1632. pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1],
  1633. pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3],
  1634. pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5],
  1635. pBtCoexist->bt_info.lps_val,
  1636. pBtCoexist->bt_info.rpwm_val);
  1637. CL_PRINTF(cliBuf);
  1638. }
  1639. void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)
  1640. {
  1641. PBTC_COEXIST pBtCoexist;
  1642. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1643. switch (dispType) {
  1644. case BTC_DBG_DISP_COEX_STATISTICS:
  1645. halbtcoutsrc_DisplayCoexStatistics(pBtCoexist);
  1646. break;
  1647. case BTC_DBG_DISP_BT_LINK_INFO:
  1648. halbtcoutsrc_DisplayBtLinkInfo(pBtCoexist);
  1649. break;
  1650. case BTC_DBG_DISP_WIFI_STATUS:
  1651. halbtcoutsrc_DisplayWifiStatus(pBtCoexist);
  1652. break;
  1653. default:
  1654. break;
  1655. }
  1656. }
  1657. /* ************************************
  1658. * IO related function
  1659. * ************************************ */
  1660. u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
  1661. {
  1662. PBTC_COEXIST pBtCoexist;
  1663. PADAPTER padapter;
  1664. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1665. padapter = pBtCoexist->Adapter;
  1666. return rtw_read8(padapter, RegAddr);
  1667. }
  1668. u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
  1669. {
  1670. PBTC_COEXIST pBtCoexist;
  1671. PADAPTER padapter;
  1672. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1673. padapter = pBtCoexist->Adapter;
  1674. return rtw_read16(padapter, RegAddr);
  1675. }
  1676. u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
  1677. {
  1678. PBTC_COEXIST pBtCoexist;
  1679. PADAPTER padapter;
  1680. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1681. padapter = pBtCoexist->Adapter;
  1682. return rtw_read32(padapter, RegAddr);
  1683. }
  1684. void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
  1685. {
  1686. PBTC_COEXIST pBtCoexist;
  1687. PADAPTER padapter;
  1688. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1689. padapter = pBtCoexist->Adapter;
  1690. rtw_write8(padapter, RegAddr, Data);
  1691. }
  1692. void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
  1693. {
  1694. PBTC_COEXIST pBtCoexist;
  1695. PADAPTER padapter;
  1696. u8 originalValue, bitShift;
  1697. u8 i;
  1698. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1699. padapter = pBtCoexist->Adapter;
  1700. originalValue = 0;
  1701. bitShift = 0;
  1702. if (bitMask != 0xff) {
  1703. originalValue = rtw_read8(padapter, regAddr);
  1704. for (i = 0; i <= 7; i++) {
  1705. if ((bitMask >> i) & 0x1)
  1706. break;
  1707. }
  1708. bitShift = i;
  1709. data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
  1710. }
  1711. rtw_write8(padapter, regAddr, data1b);
  1712. }
  1713. void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
  1714. {
  1715. PBTC_COEXIST pBtCoexist;
  1716. PADAPTER padapter;
  1717. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1718. padapter = pBtCoexist->Adapter;
  1719. rtw_write16(padapter, RegAddr, Data);
  1720. }
  1721. void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
  1722. {
  1723. PBTC_COEXIST pBtCoexist;
  1724. PADAPTER padapter;
  1725. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1726. padapter = pBtCoexist->Adapter;
  1727. rtw_write32(padapter, RegAddr, Data);
  1728. }
  1729. void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
  1730. {
  1731. PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1732. PADAPTER Adapter = pBtCoexist->Adapter;
  1733. if (BTC_INTF_SDIO == pBtCoexist->chip_interface)
  1734. rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
  1735. else
  1736. rtw_write8(Adapter, RegAddr, Data);
  1737. }
  1738. void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
  1739. {
  1740. PBTC_COEXIST pBtCoexist;
  1741. PADAPTER padapter;
  1742. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1743. padapter = pBtCoexist->Adapter;
  1744. phy_set_bb_reg(padapter, RegAddr, BitMask, Data);
  1745. }
  1746. u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
  1747. {
  1748. PBTC_COEXIST pBtCoexist;
  1749. PADAPTER padapter;
  1750. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1751. padapter = pBtCoexist->Adapter;
  1752. return phy_query_bb_reg(padapter, RegAddr, BitMask);
  1753. }
  1754. void halbtcoutsrc_SetRfReg(void *pBtcContext, enum rf_path eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
  1755. {
  1756. PBTC_COEXIST pBtCoexist;
  1757. PADAPTER padapter;
  1758. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1759. padapter = pBtCoexist->Adapter;
  1760. phy_set_rf_reg(padapter, eRFPath, RegAddr, BitMask, Data);
  1761. }
  1762. u32 halbtcoutsrc_GetRfReg(void *pBtcContext, enum rf_path eRFPath, u32 RegAddr, u32 BitMask)
  1763. {
  1764. PBTC_COEXIST pBtCoexist;
  1765. PADAPTER padapter;
  1766. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1767. padapter = pBtCoexist->Adapter;
  1768. return phy_query_rf_reg(padapter, eRFPath, RegAddr, BitMask);
  1769. }
  1770. u16 halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
  1771. {
  1772. PBTC_COEXIST pBtCoexist;
  1773. u16 ret = BT_STATUS_BT_OP_SUCCESS;
  1774. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1775. if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
  1776. u8 buf[3] = {0};
  1777. _irqL irqL;
  1778. u8 op_code;
  1779. u8 status;
  1780. _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  1781. Data = cpu_to_le32(Data);
  1782. op_code = BT_OP_WRITE_REG_VALUE;
  1783. status = _btmpoper_cmd(pBtCoexist, op_code, 0, (u8 *)&Data, 3);
  1784. if (status != BT_STATUS_BT_OP_SUCCESS)
  1785. ret = SET_BT_MP_OPER_RET(op_code, status);
  1786. else {
  1787. buf[0] = RegType;
  1788. *(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr);
  1789. op_code = BT_OP_WRITE_REG_ADDR;
  1790. status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);
  1791. if (status != BT_STATUS_BT_OP_SUCCESS)
  1792. ret = SET_BT_MP_OPER_RET(op_code, status);
  1793. }
  1794. _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  1795. } else
  1796. ret = BT_STATUS_NOT_IMPLEMENT;
  1797. return ret;
  1798. }
  1799. u8 halbtcoutsrc_SetBtAntDetection(void *pBtcContext, u8 txTime, u8 btChnl)
  1800. {
  1801. /* Always return _FALSE since we don't implement this yet */
  1802. #if 0
  1803. PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1804. PADAPTER Adapter = pBtCoexist->Adapter;
  1805. u1Byte btCanTx = 0;
  1806. BOOLEAN bStatus = FALSE;
  1807. bStatus = NDBG_SetBtAntDetection(Adapter, txTime, btChnl, &btCanTx);
  1808. if (bStatus && btCanTx)
  1809. return _TRUE;
  1810. else
  1811. return _FALSE;
  1812. #else
  1813. return _FALSE;
  1814. #endif
  1815. }
  1816. BOOLEAN
  1817. halbtcoutsrc_SetBtTRXMASK(
  1818. IN PVOID pBtcContext,
  1819. IN u1Byte bt_trx_mask
  1820. )
  1821. {
  1822. /* Always return _FALSE since we don't implement this yet */
  1823. #if 0
  1824. struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
  1825. PADAPTER Adapter = pBtCoexist->Adapter;
  1826. BOOLEAN bStatus = FALSE;
  1827. u1Byte btCanTx = 0;
  1828. if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter) || IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)
  1829. || IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  1830. if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
  1831. bStatus = NDBG_SetBtTRXMASK(Adapter, 1, bt_trx_mask, &btCanTx);
  1832. else
  1833. bStatus = NDBG_SetBtTRXMASK(Adapter, 2, bt_trx_mask, &btCanTx);
  1834. }
  1835. if (bStatus)
  1836. return TRUE;
  1837. else
  1838. return FALSE;
  1839. #else
  1840. return _FALSE;
  1841. #endif
  1842. }
  1843. u16 halbtcoutsrc_GetBtReg_with_status(void *pBtcContext, u8 RegType, u32 RegAddr, u32 *data)
  1844. {
  1845. PBTC_COEXIST pBtCoexist;
  1846. u16 ret = BT_STATUS_BT_OP_SUCCESS;
  1847. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1848. if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
  1849. u8 buf[3] = {0};
  1850. _irqL irqL;
  1851. u8 op_code;
  1852. u8 status;
  1853. buf[0] = RegType;
  1854. *(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr);
  1855. _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  1856. op_code = BT_OP_READ_REG;
  1857. status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);
  1858. if (status == BT_STATUS_BT_OP_SUCCESS)
  1859. *data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
  1860. else
  1861. ret = SET_BT_MP_OPER_RET(op_code, status);
  1862. _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  1863. } else
  1864. ret = BT_STATUS_NOT_IMPLEMENT;
  1865. return ret;
  1866. }
  1867. u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
  1868. {
  1869. u32 regVal;
  1870. return (BT_STATUS_BT_OP_SUCCESS == halbtcoutsrc_GetBtReg_with_status(pBtcContext, RegType, RegAddr, &regVal)) ? regVal : 0xffffffff;
  1871. }
  1872. void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
  1873. {
  1874. PBTC_COEXIST pBtCoexist;
  1875. PADAPTER padapter;
  1876. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1877. padapter = pBtCoexist->Adapter;
  1878. rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
  1879. }
  1880. static void halbtcoutsrc_coex_offload_init(void)
  1881. {
  1882. u1Byte i;
  1883. gl_coex_offload.h2c_req_num = 0;
  1884. gl_coex_offload.cnt_h2c_sent = 0;
  1885. gl_coex_offload.cnt_c2h_ack = 0;
  1886. gl_coex_offload.cnt_c2h_ind = 0;
  1887. for (i = 0; i < COL_MAX_H2C_REQ_NUM; i++)
  1888. init_completion(&gl_coex_offload.c2h_event[i]);
  1889. }
  1890. static COL_H2C_STATUS halbtcoutsrc_send_h2c(PADAPTER Adapter, PCOL_H2C pcol_h2c, u16 h2c_cmd_len)
  1891. {
  1892. COL_H2C_STATUS h2c_status = COL_STATUS_C2H_OK;
  1893. u8 i;
  1894. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
  1895. reinit_completion(&gl_coex_offload.c2h_event[pcol_h2c->req_num]); /* set event to un signaled state */
  1896. #else
  1897. INIT_COMPLETION(gl_coex_offload.c2h_event[pcol_h2c->req_num]);
  1898. #endif
  1899. if (TRUE) {
  1900. #if 0 /*(USE_HAL_MAC_API == 1) */
  1901. if (RT_STATUS_SUCCESS == HAL_MAC_Send_BT_COEX(&GET_HAL_MAC_INFO(Adapter), (pu1Byte)(pcol_h2c), (u4Byte)h2c_cmd_len, 1)) {
  1902. if (!wait_for_completion_timeout(&gl_coex_offload.c2h_event[pcol_h2c->req_num], 20)) {
  1903. h2c_status = COL_STATUS_H2C_TIMTOUT;
  1904. }
  1905. } else {
  1906. h2c_status = COL_STATUS_H2C_HALMAC_FAIL;
  1907. }
  1908. #endif
  1909. }
  1910. return h2c_status;
  1911. }
  1912. static COL_H2C_STATUS halbtcoutsrc_check_c2h_ack(PADAPTER Adapter, PCOL_SINGLE_H2C_RECORD pH2cRecord)
  1913. {
  1914. COL_H2C_STATUS c2h_status = COL_STATUS_C2H_OK;
  1915. PCOL_H2C p_h2c_cmd = (PCOL_H2C)&pH2cRecord->h2c_buf[0];
  1916. u8 req_num = p_h2c_cmd->req_num;
  1917. PCOL_C2H_ACK p_c2h_ack = (PCOL_C2H_ACK)&gl_coex_offload.c2h_ack_buf[req_num];
  1918. if ((COL_C2H_ACK_HDR_LEN + p_c2h_ack->ret_len) > gl_coex_offload.c2h_ack_len[req_num]) {
  1919. c2h_status = COL_STATUS_COEX_DATA_OVERFLOW;
  1920. return c2h_status;
  1921. }
  1922. /* else */
  1923. {
  1924. _rtw_memmove(&pH2cRecord->c2h_ack_buf[0], &gl_coex_offload.c2h_ack_buf[req_num], gl_coex_offload.c2h_ack_len[req_num]);
  1925. pH2cRecord->c2h_ack_len = gl_coex_offload.c2h_ack_len[req_num];
  1926. }
  1927. if (p_c2h_ack->req_num != p_h2c_cmd->req_num) {
  1928. c2h_status = COL_STATUS_C2H_REQ_NUM_MISMATCH;
  1929. } else if (p_c2h_ack->opcode_ver != p_h2c_cmd->opcode_ver) {
  1930. c2h_status = COL_STATUS_C2H_OPCODE_VER_MISMATCH;
  1931. } else {
  1932. c2h_status = p_c2h_ack->status;
  1933. }
  1934. return c2h_status;
  1935. }
  1936. COL_H2C_STATUS halbtcoutsrc_CoexH2cProcess(void *pBtCoexist,
  1937. u8 opcode, u8 opcode_ver, u8 *ph2c_par, u8 h2c_par_len)
  1938. {
  1939. PADAPTER Adapter = ((struct btc_coexist *)pBtCoexist)->Adapter;
  1940. u8 H2C_Parameter[BTC_TMP_BUF_SHORT] = {0};
  1941. PCOL_H2C pcol_h2c = (PCOL_H2C)&H2C_Parameter[0];
  1942. u16 paraLen = 0;
  1943. COL_H2C_STATUS h2c_status = COL_STATUS_C2H_OK, c2h_status = COL_STATUS_C2H_OK;
  1944. COL_H2C_STATUS ret_status = COL_STATUS_C2H_OK;
  1945. u16 i, col_h2c_len = 0;
  1946. pcol_h2c->opcode = opcode;
  1947. pcol_h2c->opcode_ver = opcode_ver;
  1948. pcol_h2c->req_num = gl_coex_offload.h2c_req_num;
  1949. gl_coex_offload.h2c_req_num++;
  1950. gl_coex_offload.h2c_req_num %= 16;
  1951. _rtw_memmove(&pcol_h2c->buf[0], ph2c_par, h2c_par_len);
  1952. col_h2c_len = h2c_par_len + 2; /* 2=sizeof(OPCode, OPCode_version and Request number) */
  1953. BT_PrintData(Adapter, "[COL], H2C cmd: ", col_h2c_len, H2C_Parameter);
  1954. gl_coex_offload.cnt_h2c_sent++;
  1955. gl_coex_offload.h2c_record[opcode].count++;
  1956. gl_coex_offload.h2c_record[opcode].h2c_len = col_h2c_len;
  1957. _rtw_memmove((PVOID)&gl_coex_offload.h2c_record[opcode].h2c_buf[0], (PVOID)pcol_h2c, col_h2c_len);
  1958. h2c_status = halbtcoutsrc_send_h2c(Adapter, pcol_h2c, col_h2c_len);
  1959. gl_coex_offload.h2c_record[opcode].c2h_ack_len = 0;
  1960. if (COL_STATUS_C2H_OK == h2c_status) {
  1961. /* if reach here, it means H2C get the correct c2h response, */
  1962. c2h_status = halbtcoutsrc_check_c2h_ack(Adapter, &gl_coex_offload.h2c_record[opcode]);
  1963. ret_status = c2h_status;
  1964. } else {
  1965. /* check h2c status error, return error status code to upper layer. */
  1966. ret_status = h2c_status;
  1967. }
  1968. gl_coex_offload.h2c_record[opcode].status[ret_status]++;
  1969. gl_coex_offload.status[ret_status]++;
  1970. return ret_status;
  1971. }
  1972. u8 halbtcoutsrc_GetAntDetValFromBt(void *pBtcContext)
  1973. {
  1974. /* Always return 0 since we don't implement this yet */
  1975. #if 0
  1976. struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
  1977. PADAPTER Adapter = pBtCoexist->Adapter;
  1978. u1Byte AntDetVal = 0x0;
  1979. u1Byte opcodeVer = 1;
  1980. BOOLEAN status = false;
  1981. status = NDBG_GetAntDetValFromBt(Adapter, opcodeVer, &AntDetVal);
  1982. RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$ halbtcoutsrc_GetAntDetValFromBt(): status = %d, feature = %x\n", status, AntDetVal));
  1983. return AntDetVal;
  1984. #else
  1985. return 0;
  1986. #endif
  1987. }
  1988. u8 halbtcoutsrc_GetBleScanTypeFromBt(void *pBtcContext)
  1989. {
  1990. PBTC_COEXIST pBtCoexist;
  1991. u32 ret = BT_STATUS_BT_OP_SUCCESS;
  1992. u8 data = 0;
  1993. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  1994. if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
  1995. u8 buf[3] = {0};
  1996. _irqL irqL;
  1997. u8 op_code;
  1998. u8 status;
  1999. _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  2000. op_code = BT_OP_GET_BT_BLE_SCAN_TYPE;
  2001. status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
  2002. if (status == BT_STATUS_BT_OP_SUCCESS)
  2003. data = *(u8 *)GLBtcBtMpRptRsp;
  2004. else
  2005. ret = SET_BT_MP_OPER_RET(op_code, status);
  2006. _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  2007. } else
  2008. ret = BT_STATUS_NOT_IMPLEMENT;
  2009. return data;
  2010. }
  2011. u32 halbtcoutsrc_GetBleScanParaFromBt(void *pBtcContext, u8 scanType)
  2012. {
  2013. PBTC_COEXIST pBtCoexist;
  2014. u32 ret = BT_STATUS_BT_OP_SUCCESS;
  2015. u32 data = 0;
  2016. pBtCoexist = (PBTC_COEXIST)pBtcContext;
  2017. if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
  2018. u8 buf[3] = {0};
  2019. _irqL irqL;
  2020. u8 op_code;
  2021. u8 status;
  2022. buf[0] = scanType;
  2023. _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  2024. op_code = BT_OP_GET_BT_BLE_SCAN_PARA;
  2025. status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 1);
  2026. if (status == BT_STATUS_BT_OP_SUCCESS)
  2027. data = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
  2028. else
  2029. ret = SET_BT_MP_OPER_RET(op_code, status);
  2030. _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  2031. } else
  2032. ret = BT_STATUS_NOT_IMPLEMENT;
  2033. return data;
  2034. }
  2035. u8 halbtcoutsrc_GetBtAFHMapFromBt(void *pBtcContext, u8 mapType, u8 *afhMap)
  2036. {
  2037. struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
  2038. u8 buf[2] = {0};
  2039. _irqL irqL;
  2040. u8 op_code;
  2041. u32 *AfhMapL = (u32 *)&(afhMap[0]);
  2042. u32 *AfhMapM = (u32 *)&(afhMap[4]);
  2043. u16 *AfhMapH = (u16 *)&(afhMap[8]);
  2044. u8 status;
  2045. u32 ret = BT_STATUS_BT_OP_SUCCESS;
  2046. if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _FALSE)
  2047. return _FALSE;
  2048. buf[0] = 0;
  2049. buf[1] = mapType;
  2050. _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  2051. op_code = BT_LO_OP_GET_AFH_MAP_L;
  2052. status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
  2053. if (status == BT_STATUS_BT_OP_SUCCESS)
  2054. *AfhMapL = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
  2055. else {
  2056. ret = SET_BT_MP_OPER_RET(op_code, status);
  2057. goto exit;
  2058. }
  2059. op_code = BT_LO_OP_GET_AFH_MAP_M;
  2060. status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
  2061. if (status == BT_STATUS_BT_OP_SUCCESS)
  2062. *AfhMapM = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
  2063. else {
  2064. ret = SET_BT_MP_OPER_RET(op_code, status);
  2065. goto exit;
  2066. }
  2067. op_code = BT_LO_OP_GET_AFH_MAP_H;
  2068. status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
  2069. if (status == BT_STATUS_BT_OP_SUCCESS)
  2070. *AfhMapH = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
  2071. else {
  2072. ret = SET_BT_MP_OPER_RET(op_code, status);
  2073. goto exit;
  2074. }
  2075. exit:
  2076. _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
  2077. return (ret == BT_STATUS_BT_OP_SUCCESS) ? _TRUE : _FALSE;
  2078. }
  2079. u32 halbtcoutsrc_GetPhydmVersion(void *pBtcContext)
  2080. {
  2081. struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
  2082. PADAPTER Adapter = pBtCoexist->Adapter;
  2083. #ifdef CONFIG_RTL8192E
  2084. return RELEASE_VERSION_8192E;
  2085. #endif
  2086. #ifdef CONFIG_RTL8821A
  2087. return RELEASE_VERSION_8821A;
  2088. #endif
  2089. #ifdef CONFIG_RTL8723B
  2090. return RELEASE_VERSION_8723B;
  2091. #endif
  2092. #ifdef CONFIG_RTL8812A
  2093. return RELEASE_VERSION_8812A;
  2094. #endif
  2095. #ifdef CONFIG_RTL8703B
  2096. return RELEASE_VERSION_8703B;
  2097. #endif
  2098. #ifdef CONFIG_RTL8822B
  2099. return RELEASE_VERSION_8822B;
  2100. #endif
  2101. #ifdef CONFIG_RTL8723D
  2102. return RELEASE_VERSION_8723D;
  2103. #endif
  2104. #ifdef CONFIG_RTL8821C
  2105. return RELEASE_VERSION_8821C;
  2106. #endif
  2107. #ifdef CONFIG_RTL8192F
  2108. return RELEASE_VERSION_8192F;
  2109. #endif
  2110. }
  2111. u32 halbtcoutsrc_SetAtomic (void *btc_ctx, u32 *target, u32 val)
  2112. {
  2113. *target = val;
  2114. return _SUCCESS;
  2115. }
  2116. void halbtcoutsrc_phydm_modify_AntDiv_HwSw(void *pBtcContext, u8 is_hw)
  2117. {
  2118. /* empty function since we don't need it */
  2119. }
  2120. void halbtcoutsrc_phydm_modify_RA_PCR_threshold(void *pBtcContext, u8 RA_offset_direction, u8 RA_threshold_offset)
  2121. {
  2122. struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
  2123. /* switch to #if 0 in case the phydm version does not provide the function */
  2124. #if 1
  2125. phydm_modify_RA_PCR_threshold(pBtCoexist->odm_priv, RA_offset_direction, RA_threshold_offset);
  2126. #endif
  2127. }
  2128. u32 halbtcoutsrc_phydm_query_PHY_counter(void *pBtcContext, u8 info_type)
  2129. {
  2130. struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
  2131. /* switch to #if 0 in case the phydm version does not provide the function */
  2132. #if 1
  2133. return phydm_cmn_info_query((struct dm_struct *)pBtCoexist->odm_priv, (enum phydm_info_query)info_type);
  2134. #else
  2135. return 0;
  2136. #endif
  2137. }
  2138. #if 0
  2139. static void BT_CoexOffloadRecordErrC2hAck(PADAPTER Adapter)
  2140. {
  2141. PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter);
  2142. if (pDefaultAdapter != Adapter)
  2143. return;
  2144. if (!hal_btcoex_IsBtExist(Adapter))
  2145. return;
  2146. gl_coex_offload.cnt_c2h_ack++;
  2147. gl_coex_offload.status[COL_STATUS_INVALID_C2H_LEN]++;
  2148. }
  2149. static void BT_CoexOffloadC2hAckCheck(PADAPTER Adapter, u8 *tmpBuf, u8 length)
  2150. {
  2151. PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter);
  2152. PCOL_C2H_ACK p_c2h_ack = NULL;
  2153. u8 req_num = 0xff;
  2154. if (pDefaultAdapter != Adapter)
  2155. return;
  2156. if (!hal_btcoex_IsBtExist(Adapter))
  2157. return;
  2158. gl_coex_offload.cnt_c2h_ack++;
  2159. if (length < COL_C2H_ACK_HDR_LEN) { /* c2h ack length must >= 3 (status, opcode_ver, req_num and ret_len) */
  2160. gl_coex_offload.status[COL_STATUS_INVALID_C2H_LEN]++;
  2161. } else {
  2162. BT_PrintData(Adapter, "[COL], c2h ack:", length, tmpBuf);
  2163. p_c2h_ack = (PCOL_C2H_ACK)tmpBuf;
  2164. req_num = p_c2h_ack->req_num;
  2165. _rtw_memmove(&gl_coex_offload.c2h_ack_buf[req_num][0], tmpBuf, length);
  2166. gl_coex_offload.c2h_ack_len[req_num] = length;
  2167. complete(&gl_coex_offload.c2h_event[req_num]);
  2168. }
  2169. }
  2170. static void BT_CoexOffloadC2hIndCheck(PADAPTER Adapter, u8 *tmpBuf, u8 length)
  2171. {
  2172. PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter);
  2173. PCOL_C2H_IND p_c2h_ind = NULL;
  2174. u8 ind_type = 0, ind_version = 0, ind_length = 0;
  2175. if (pDefaultAdapter != Adapter)
  2176. return;
  2177. if (!hal_btcoex_IsBtExist(Adapter))
  2178. return;
  2179. gl_coex_offload.cnt_c2h_ind++;
  2180. if (length < COL_C2H_IND_HDR_LEN) { /* c2h indication length must >= 3 (type, version and length) */
  2181. gl_coex_offload.c2h_ind_status[COL_STATUS_INVALID_C2H_LEN]++;
  2182. } else {
  2183. BT_PrintData(Adapter, "[COL], c2h indication:", length, tmpBuf);
  2184. p_c2h_ind = (PCOL_C2H_IND)tmpBuf;
  2185. ind_type = p_c2h_ind->type;
  2186. ind_version = p_c2h_ind->version;
  2187. ind_length = p_c2h_ind->length;
  2188. _rtw_memmove(&gl_coex_offload.c2h_ind_buf[0], tmpBuf, length);
  2189. gl_coex_offload.c2h_ind_len = length;
  2190. /* log */
  2191. gl_coex_offload.c2h_ind_record[ind_type].count++;
  2192. gl_coex_offload.c2h_ind_record[ind_type].status[COL_STATUS_C2H_OK]++;
  2193. _rtw_memmove(&gl_coex_offload.c2h_ind_record[ind_type].ind_buf[0], tmpBuf, length);
  2194. gl_coex_offload.c2h_ind_record[ind_type].ind_len = length;
  2195. gl_coex_offload.c2h_ind_status[COL_STATUS_C2H_OK]++;
  2196. /*TODO: need to check c2h indication length*/
  2197. /* TODO: Notification */
  2198. }
  2199. }
  2200. void BT_CoexOffloadC2hCheck(PADAPTER Adapter, u8 *Buffer, u8 Length)
  2201. {
  2202. #if 0 /*(USE_HAL_MAC_API == 1)*/
  2203. u8 c2hSubCmdId = 0, c2hAckLen = 0, h2cCmdId = 0, h2cSubCmdId = 0, c2hIndLen = 0;
  2204. BT_PrintData(Adapter, "[COL], c2h packet:", Length - 2, Buffer + 2);
  2205. c2hSubCmdId = (u1Byte)C2H_HDR_GET_C2H_SUB_CMD_ID(Buffer);
  2206. if (c2hSubCmdId == C2H_SUB_CMD_ID_H2C_ACK_HDR ||
  2207. c2hSubCmdId == C2H_SUB_CMD_ID_BT_COEX_INFO) {
  2208. if (c2hSubCmdId == C2H_SUB_CMD_ID_H2C_ACK_HDR) {
  2209. /* coex c2h ack */
  2210. h2cCmdId = (u1Byte)H2C_ACK_HDR_GET_H2C_CMD_ID(Buffer);
  2211. h2cSubCmdId = (u1Byte)H2C_ACK_HDR_GET_H2C_SUB_CMD_ID(Buffer);
  2212. if (h2cCmdId == 0xff && h2cSubCmdId == 0x60) {
  2213. c2hAckLen = (u1Byte)C2H_HDR_GET_LEN(Buffer);
  2214. if (c2hAckLen >= 8)
  2215. BT_CoexOffloadC2hAckCheck(Adapter, &Buffer[12], (u1Byte)(c2hAckLen - 8));
  2216. else
  2217. BT_CoexOffloadRecordErrC2hAck(Adapter);
  2218. }
  2219. } else if (c2hSubCmdId == C2H_SUB_CMD_ID_BT_COEX_INFO) {
  2220. /* coex c2h indication */
  2221. c2hIndLen = (u1Byte)C2H_HDR_GET_LEN(Buffer);
  2222. BT_CoexOffloadC2hIndCheck(Adapter, &Buffer[4], (u1Byte)c2hIndLen);
  2223. }
  2224. }
  2225. #endif
  2226. }
  2227. #endif
  2228. /* ************************************
  2229. * Extern functions called by other module
  2230. * ************************************ */
  2231. u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
  2232. {
  2233. PBTC_COEXIST pBtCoexist = &GLBtCoexist;
  2234. HAL_DATA_TYPE *pHalData = GET_HAL_DATA((PADAPTER)padapter);
  2235. if (pBtCoexist->bBinded)
  2236. return _FALSE;
  2237. else
  2238. pBtCoexist->bBinded = _TRUE;
  2239. pBtCoexist->statistics.cnt_bind++;
  2240. pBtCoexist->Adapter = padapter;
  2241. pBtCoexist->odm_priv = (PVOID)&(pHalData->odmpriv);
  2242. pBtCoexist->stack_info.profile_notified = _FALSE;
  2243. pBtCoexist->bt_info.bt_ctrl_agg_buf_size = _FALSE;
  2244. pBtCoexist->bt_info.agg_buf_size = 5;
  2245. pBtCoexist->bt_info.increase_scan_dev_num = _FALSE;
  2246. pBtCoexist->bt_info.miracast_plus_bt = _FALSE;
  2247. return _TRUE;
  2248. }
  2249. void EXhalbtcoutsrc_AntInfoSetting(void *padapter)
  2250. {
  2251. PBTC_COEXIST pBtCoexist = &GLBtCoexist;
  2252. u8 antNum = 1, singleAntPath = 0;
  2253. antNum = rtw_btcoex_get_pg_ant_num((PADAPTER)padapter);
  2254. EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
  2255. if (antNum == 1) {
  2256. singleAntPath = rtw_btcoex_get_pg_single_ant_path((PADAPTER)padapter);
  2257. EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
  2258. }
  2259. pBtCoexist->board_info.customerID = RT_CID_DEFAULT;
  2260. pBtCoexist->board_info.customer_id = RT_CID_DEFAULT;
  2261. /* set default antenna position to main port */
  2262. pBtCoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
  2263. pBtCoexist->board_info.btdm_ant_det_finish = _FALSE;
  2264. pBtCoexist->board_info.btdm_ant_num_by_ant_det = 1;
  2265. pBtCoexist->board_info.tfbga_package = rtw_btcoex_is_tfbga_package_type((PADAPTER)padapter);
  2266. pBtCoexist->board_info.rfe_type = rtw_btcoex_get_pg_rfe_type((PADAPTER)padapter);
  2267. pBtCoexist->board_info.ant_div_cfg = rtw_btcoex_get_ant_div_cfg((PADAPTER)padapter);
  2268. }
  2269. u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)
  2270. {
  2271. PBTC_COEXIST pBtCoexist = &GLBtCoexist;
  2272. /* pBtCoexist->statistics.cntBind++; */
  2273. halbtcoutsrc_DbgInit();
  2274. halbtcoutsrc_coex_offload_init();
  2275. #ifdef CONFIG_PCI_HCI
  2276. pBtCoexist->chip_interface = BTC_INTF_PCI;
  2277. #elif defined(CONFIG_USB_HCI)
  2278. pBtCoexist->chip_interface = BTC_INTF_USB;
  2279. #elif defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
  2280. pBtCoexist->chip_interface = BTC_INTF_SDIO;
  2281. #else
  2282. pBtCoexist->chip_interface = BTC_INTF_UNKNOWN;
  2283. #endif
  2284. EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
  2285. pBtCoexist->btc_read_1byte = halbtcoutsrc_Read1Byte;
  2286. pBtCoexist->btc_write_1byte = halbtcoutsrc_Write1Byte;
  2287. pBtCoexist->btc_write_1byte_bitmask = halbtcoutsrc_BitMaskWrite1Byte;
  2288. pBtCoexist->btc_read_2byte = halbtcoutsrc_Read2Byte;
  2289. pBtCoexist->btc_write_2byte = halbtcoutsrc_Write2Byte;
  2290. pBtCoexist->btc_read_4byte = halbtcoutsrc_Read4Byte;
  2291. pBtCoexist->btc_write_4byte = halbtcoutsrc_Write4Byte;
  2292. pBtCoexist->btc_write_local_reg_1byte = halbtcoutsrc_WriteLocalReg1Byte;
  2293. pBtCoexist->btc_set_bb_reg = halbtcoutsrc_SetBbReg;
  2294. pBtCoexist->btc_get_bb_reg = halbtcoutsrc_GetBbReg;
  2295. pBtCoexist->btc_set_rf_reg = halbtcoutsrc_SetRfReg;
  2296. pBtCoexist->btc_get_rf_reg = halbtcoutsrc_GetRfReg;
  2297. pBtCoexist->btc_fill_h2c = halbtcoutsrc_FillH2cCmd;
  2298. pBtCoexist->btc_disp_dbg_msg = halbtcoutsrc_DisplayDbgMsg;
  2299. pBtCoexist->btc_get = halbtcoutsrc_Get;
  2300. pBtCoexist->btc_set = halbtcoutsrc_Set;
  2301. pBtCoexist->btc_get_bt_reg = halbtcoutsrc_GetBtReg;
  2302. pBtCoexist->btc_set_bt_reg = halbtcoutsrc_SetBtReg;
  2303. pBtCoexist->btc_set_bt_ant_detection = halbtcoutsrc_SetBtAntDetection;
  2304. pBtCoexist->btc_set_bt_trx_mask = halbtcoutsrc_SetBtTRXMASK;
  2305. pBtCoexist->btc_coex_h2c_process = halbtcoutsrc_CoexH2cProcess;
  2306. pBtCoexist->btc_get_bt_coex_supported_feature = halbtcoutsrc_GetBtCoexSupportedFeature;
  2307. pBtCoexist->btc_get_bt_coex_supported_version= halbtcoutsrc_GetBtCoexSupportedVersion;
  2308. pBtCoexist->btc_get_ant_det_val_from_bt = halbtcoutsrc_GetAntDetValFromBt;
  2309. pBtCoexist->btc_get_ble_scan_type_from_bt = halbtcoutsrc_GetBleScanTypeFromBt;
  2310. pBtCoexist->btc_get_ble_scan_para_from_bt = halbtcoutsrc_GetBleScanParaFromBt;
  2311. pBtCoexist->btc_get_bt_afh_map_from_bt = halbtcoutsrc_GetBtAFHMapFromBt;
  2312. pBtCoexist->btc_get_bt_phydm_version = halbtcoutsrc_GetPhydmVersion;
  2313. pBtCoexist->btc_set_atomic= halbtcoutsrc_SetAtomic;
  2314. pBtCoexist->btc_phydm_modify_RA_PCR_threshold = halbtcoutsrc_phydm_modify_RA_PCR_threshold;
  2315. pBtCoexist->btc_phydm_query_PHY_counter = halbtcoutsrc_phydm_query_PHY_counter;
  2316. pBtCoexist->btc_phydm_modify_antdiv_hwsw = halbtcoutsrc_phydm_modify_AntDiv_HwSw;
  2317. pBtCoexist->cli_buf = &GLBtcDbgBuf[0];
  2318. GLBtcWiFiInScanState = _FALSE;
  2319. GLBtcWiFiInIQKState = _FALSE;
  2320. GLBtcWiFiInIPS = _FALSE;
  2321. GLBtcWiFiInLPS = _FALSE;
  2322. GLBtcBtCoexAliveRegistered = _FALSE;
  2323. /* BT Control H2C/C2H*/
  2324. GLBtcBtMpOperSeq = 0;
  2325. _rtw_mutex_init(&GLBtcBtMpOperLock);
  2326. rtw_init_timer(&GLBtcBtMpOperTimer, padapter, _btmpoper_timer_hdl, pBtCoexist);
  2327. _rtw_init_sema(&GLBtcBtMpRptSema, 0);
  2328. GLBtcBtMpRptSeq = 0;
  2329. GLBtcBtMpRptStatus = 0;
  2330. _rtw_memset(GLBtcBtMpRptRsp, 0, C2H_MAX_SIZE);
  2331. GLBtcBtMpRptRspSize = 0;
  2332. GLBtcBtMpRptWait = _FALSE;
  2333. GLBtcBtMpRptWiFiOK = _FALSE;
  2334. GLBtcBtMpRptBTOK = _FALSE;
  2335. return _TRUE;
  2336. }
  2337. void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)
  2338. {
  2339. HAL_DATA_TYPE *pHalData = NULL;
  2340. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  2341. return;
  2342. pHalData = GET_HAL_DATA((PADAPTER)pBtCoexist->Adapter);
  2343. if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  2344. #ifdef CONFIG_RTL8723B
  2345. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2346. ex_halbtc8723b2ant_power_on_setting(pBtCoexist);
  2347. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2348. ex_halbtc8723b1ant_power_on_setting(pBtCoexist);
  2349. #endif
  2350. }
  2351. #ifdef CONFIG_RTL8703B
  2352. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  2353. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2354. ex_halbtc8703b1ant_power_on_setting(pBtCoexist);
  2355. }
  2356. #endif
  2357. #ifdef CONFIG_RTL8723D
  2358. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  2359. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2360. ex_halbtc8723d2ant_power_on_setting(pBtCoexist);
  2361. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2362. ex_halbtc8723d1ant_power_on_setting(pBtCoexist);
  2363. }
  2364. #endif
  2365. #ifdef CONFIG_RTL8821A
  2366. else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
  2367. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2368. ex_halbtc8821a1ant_power_on_setting(pBtCoexist);
  2369. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  2370. ex_halbtc8821a2ant_power_on_setting(pBtCoexist);
  2371. }
  2372. #endif
  2373. #ifdef CONFIG_RTL8822B
  2374. else if ((IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) && (pHalData->EEPROMBluetoothCoexist == _TRUE)) {
  2375. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2376. ex_halbtc8822b1ant_power_on_setting(pBtCoexist);
  2377. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  2378. ex_halbtc8822b2ant_power_on_setting(pBtCoexist);
  2379. }
  2380. #endif
  2381. #ifdef CONFIG_RTL8821C
  2382. else if ((IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) && (pHalData->EEPROMBluetoothCoexist == _TRUE)) {
  2383. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2384. ex_halbtc8821c2ant_power_on_setting(pBtCoexist);
  2385. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2386. ex_halbtc8821c1ant_power_on_setting(pBtCoexist);
  2387. }
  2388. #endif
  2389. }
  2390. void EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist)
  2391. {
  2392. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  2393. return;
  2394. pBtCoexist->statistics.cnt_pre_load_firmware++;
  2395. if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  2396. #ifdef CONFIG_RTL8723B
  2397. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2398. ex_halbtc8723b2ant_pre_load_firmware(pBtCoexist);
  2399. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2400. ex_halbtc8723b1ant_pre_load_firmware(pBtCoexist);
  2401. #endif
  2402. }
  2403. #ifdef CONFIG_RTL8723D
  2404. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  2405. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2406. ex_halbtc8723d2ant_pre_load_firmware(pBtCoexist);
  2407. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2408. ex_halbtc8723d1ant_pre_load_firmware(pBtCoexist);
  2409. }
  2410. #endif
  2411. #ifdef CONFIG_RTL8821C
  2412. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  2413. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2414. ex_halbtc8821c2ant_pre_load_firmware(pBtCoexist);
  2415. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2416. ex_halbtc8821c1ant_pre_load_firmware(pBtCoexist);
  2417. }
  2418. #endif
  2419. }
  2420. void EXhalbtcoutsrc_init_hw_config(PBTC_COEXIST pBtCoexist, u8 bWifiOnly)
  2421. {
  2422. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  2423. return;
  2424. pBtCoexist->statistics.cnt_init_hw_config++;
  2425. if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
  2426. #ifdef CONFIG_RTL8821A
  2427. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2428. ex_halbtc8821a2ant_init_hw_config(pBtCoexist, bWifiOnly);
  2429. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2430. ex_halbtc8821a1ant_init_hw_config(pBtCoexist, bWifiOnly);
  2431. #endif
  2432. }
  2433. #ifdef CONFIG_RTL8723B
  2434. else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  2435. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2436. ex_halbtc8723b2ant_init_hw_config(pBtCoexist, bWifiOnly);
  2437. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2438. ex_halbtc8723b1ant_init_hw_config(pBtCoexist, bWifiOnly);
  2439. }
  2440. #endif
  2441. #ifdef CONFIG_RTL8703B
  2442. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  2443. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2444. ex_halbtc8703b1ant_init_hw_config(pBtCoexist, bWifiOnly);
  2445. }
  2446. #endif
  2447. #ifdef CONFIG_RTL8723D
  2448. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  2449. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2450. ex_halbtc8723d2ant_init_hw_config(pBtCoexist, bWifiOnly);
  2451. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2452. ex_halbtc8723d1ant_init_hw_config(pBtCoexist, bWifiOnly);
  2453. }
  2454. #endif
  2455. #ifdef CONFIG_RTL8192E
  2456. else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
  2457. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2458. ex_halbtc8192e2ant_init_hw_config(pBtCoexist, bWifiOnly);
  2459. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2460. ex_halbtc8192e1ant_init_hw_config(pBtCoexist, bWifiOnly);
  2461. }
  2462. #endif
  2463. #ifdef CONFIG_RTL8812A
  2464. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  2465. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2466. ex_halbtc8812a2ant_init_hw_config(pBtCoexist, bWifiOnly);
  2467. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2468. ex_halbtc8812a1ant_init_hw_config(pBtCoexist, bWifiOnly);
  2469. }
  2470. #endif
  2471. #ifdef CONFIG_RTL8822B
  2472. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  2473. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2474. ex_halbtc8822b1ant_init_hw_config(pBtCoexist, bWifiOnly);
  2475. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  2476. ex_halbtc8822b2ant_init_hw_config(pBtCoexist, bWifiOnly);
  2477. }
  2478. #endif
  2479. #ifdef CONFIG_RTL8821C
  2480. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  2481. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2482. ex_halbtc8821c2ant_init_hw_config(pBtCoexist, bWifiOnly);
  2483. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2484. ex_halbtc8821c1ant_init_hw_config(pBtCoexist, bWifiOnly);
  2485. }
  2486. #endif
  2487. }
  2488. void EXhalbtcoutsrc_init_coex_dm(PBTC_COEXIST pBtCoexist)
  2489. {
  2490. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  2491. return;
  2492. pBtCoexist->statistics.cnt_init_coex_dm++;
  2493. if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
  2494. #ifdef CONFIG_RTL8821A
  2495. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2496. ex_halbtc8821a2ant_init_coex_dm(pBtCoexist);
  2497. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2498. ex_halbtc8821a1ant_init_coex_dm(pBtCoexist);
  2499. #endif
  2500. }
  2501. #ifdef CONFIG_RTL8723B
  2502. else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  2503. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2504. ex_halbtc8723b2ant_init_coex_dm(pBtCoexist);
  2505. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2506. ex_halbtc8723b1ant_init_coex_dm(pBtCoexist);
  2507. }
  2508. #endif
  2509. #ifdef CONFIG_RTL8703B
  2510. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  2511. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2512. ex_halbtc8703b1ant_init_coex_dm(pBtCoexist);
  2513. }
  2514. #endif
  2515. #ifdef CONFIG_RTL8723D
  2516. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  2517. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2518. ex_halbtc8723d2ant_init_coex_dm(pBtCoexist);
  2519. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2520. ex_halbtc8723d1ant_init_coex_dm(pBtCoexist);
  2521. }
  2522. #endif
  2523. #ifdef CONFIG_RTL8192E
  2524. else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
  2525. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2526. ex_halbtc8192e2ant_init_coex_dm(pBtCoexist);
  2527. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2528. ex_halbtc8192e1ant_init_coex_dm(pBtCoexist);
  2529. }
  2530. #endif
  2531. #ifdef CONFIG_RTL8812A
  2532. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  2533. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2534. ex_halbtc8812a2ant_init_coex_dm(pBtCoexist);
  2535. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2536. ex_halbtc8812a1ant_init_coex_dm(pBtCoexist);
  2537. }
  2538. #endif
  2539. #ifdef CONFIG_RTL8822B
  2540. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  2541. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2542. ex_halbtc8822b1ant_init_coex_dm(pBtCoexist);
  2543. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  2544. ex_halbtc8822b2ant_init_coex_dm(pBtCoexist);
  2545. }
  2546. #endif
  2547. #ifdef CONFIG_RTL8821C
  2548. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  2549. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2550. ex_halbtc8821c2ant_init_coex_dm(pBtCoexist);
  2551. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2552. ex_halbtc8821c1ant_init_coex_dm(pBtCoexist);
  2553. }
  2554. #endif
  2555. pBtCoexist->initilized = _TRUE;
  2556. }
  2557. void EXhalbtcoutsrc_ips_notify(PBTC_COEXIST pBtCoexist, u8 type)
  2558. {
  2559. u8 ipsType;
  2560. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  2561. return;
  2562. pBtCoexist->statistics.cnt_ips_notify++;
  2563. if (pBtCoexist->manual_control)
  2564. return;
  2565. if (IPS_NONE == type) {
  2566. ipsType = BTC_IPS_LEAVE;
  2567. GLBtcWiFiInIPS = _FALSE;
  2568. } else {
  2569. ipsType = BTC_IPS_ENTER;
  2570. GLBtcWiFiInIPS = _TRUE;
  2571. }
  2572. /* All notify is called in cmd thread, don't need to leave low power again
  2573. * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
  2574. if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
  2575. #ifdef CONFIG_RTL8821A
  2576. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2577. ex_halbtc8821a2ant_ips_notify(pBtCoexist, ipsType);
  2578. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2579. ex_halbtc8821a1ant_ips_notify(pBtCoexist, ipsType);
  2580. #endif
  2581. }
  2582. #ifdef CONFIG_RTL8723B
  2583. else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  2584. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2585. ex_halbtc8723b2ant_ips_notify(pBtCoexist, ipsType);
  2586. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2587. ex_halbtc8723b1ant_ips_notify(pBtCoexist, ipsType);
  2588. }
  2589. #endif
  2590. #ifdef CONFIG_RTL8703B
  2591. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  2592. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2593. ex_halbtc8703b1ant_ips_notify(pBtCoexist, ipsType);
  2594. }
  2595. #endif
  2596. #ifdef CONFIG_RTL8723D
  2597. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  2598. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2599. ex_halbtc8723d2ant_ips_notify(pBtCoexist, ipsType);
  2600. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2601. ex_halbtc8723d1ant_ips_notify(pBtCoexist, ipsType);
  2602. }
  2603. #endif
  2604. #ifdef CONFIG_RTL8192E
  2605. else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
  2606. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2607. ex_halbtc8192e2ant_ips_notify(pBtCoexist, ipsType);
  2608. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2609. ex_halbtc8192e1ant_ips_notify(pBtCoexist, ipsType);
  2610. }
  2611. #endif
  2612. #ifdef CONFIG_RTL8812A
  2613. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  2614. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2615. ex_halbtc8812a2ant_ips_notify(pBtCoexist, ipsType);
  2616. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2617. ex_halbtc8812a1ant_ips_notify(pBtCoexist, ipsType);
  2618. }
  2619. #endif
  2620. #ifdef CONFIG_RTL8822B
  2621. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  2622. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2623. ex_halbtc8822b1ant_ips_notify(pBtCoexist, ipsType);
  2624. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  2625. ex_halbtc8822b2ant_ips_notify(pBtCoexist, ipsType);
  2626. }
  2627. #endif
  2628. #ifdef CONFIG_RTL8821C
  2629. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  2630. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2631. ex_halbtc8821c2ant_ips_notify(pBtCoexist, ipsType);
  2632. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2633. ex_halbtc8821c1ant_ips_notify(pBtCoexist, ipsType);
  2634. }
  2635. #endif
  2636. /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
  2637. }
  2638. void EXhalbtcoutsrc_lps_notify(PBTC_COEXIST pBtCoexist, u8 type)
  2639. {
  2640. u8 lpsType;
  2641. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  2642. return;
  2643. pBtCoexist->statistics.cnt_lps_notify++;
  2644. if (pBtCoexist->manual_control)
  2645. return;
  2646. if (PS_MODE_ACTIVE == type) {
  2647. lpsType = BTC_LPS_DISABLE;
  2648. GLBtcWiFiInLPS = _FALSE;
  2649. } else {
  2650. lpsType = BTC_LPS_ENABLE;
  2651. GLBtcWiFiInLPS = _TRUE;
  2652. }
  2653. if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
  2654. #ifdef CONFIG_RTL8821A
  2655. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2656. ex_halbtc8821a2ant_lps_notify(pBtCoexist, lpsType);
  2657. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2658. ex_halbtc8821a1ant_lps_notify(pBtCoexist, lpsType);
  2659. #endif
  2660. }
  2661. #ifdef CONFIG_RTL8723B
  2662. else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  2663. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2664. ex_halbtc8723b2ant_lps_notify(pBtCoexist, lpsType);
  2665. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2666. ex_halbtc8723b1ant_lps_notify(pBtCoexist, lpsType);
  2667. }
  2668. #endif
  2669. #ifdef CONFIG_RTL8703B
  2670. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  2671. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2672. ex_halbtc8703b1ant_lps_notify(pBtCoexist, lpsType);
  2673. }
  2674. #endif
  2675. #ifdef CONFIG_RTL8723D
  2676. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  2677. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2678. ex_halbtc8723d2ant_lps_notify(pBtCoexist, lpsType);
  2679. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2680. ex_halbtc8723d1ant_lps_notify(pBtCoexist, lpsType);
  2681. }
  2682. #endif
  2683. #ifdef CONFIG_RTL8192E
  2684. else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
  2685. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2686. ex_halbtc8192e2ant_lps_notify(pBtCoexist, lpsType);
  2687. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2688. ex_halbtc8192e1ant_lps_notify(pBtCoexist, lpsType);
  2689. }
  2690. #endif
  2691. #ifdef CONFIG_RTL8812A
  2692. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  2693. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2694. ex_halbtc8812a2ant_lps_notify(pBtCoexist, lpsType);
  2695. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2696. ex_halbtc8812a1ant_lps_notify(pBtCoexist, lpsType);
  2697. }
  2698. #endif
  2699. #ifdef CONFIG_RTL8822B
  2700. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  2701. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2702. ex_halbtc8822b1ant_lps_notify(pBtCoexist, lpsType);
  2703. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  2704. ex_halbtc8822b2ant_lps_notify(pBtCoexist, lpsType);
  2705. }
  2706. #endif
  2707. #ifdef CONFIG_RTL8821C
  2708. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  2709. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2710. ex_halbtc8821c2ant_lps_notify(pBtCoexist, lpsType);
  2711. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2712. ex_halbtc8821c1ant_lps_notify(pBtCoexist, lpsType);
  2713. }
  2714. #endif
  2715. }
  2716. void EXhalbtcoutsrc_scan_notify(PBTC_COEXIST pBtCoexist, u8 type)
  2717. {
  2718. u8 scanType;
  2719. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  2720. return;
  2721. pBtCoexist->statistics.cnt_scan_notify++;
  2722. if (pBtCoexist->manual_control)
  2723. return;
  2724. if (type) {
  2725. scanType = BTC_SCAN_START;
  2726. GLBtcWiFiInScanState = _TRUE;
  2727. } else {
  2728. scanType = BTC_SCAN_FINISH;
  2729. GLBtcWiFiInScanState = _FALSE;
  2730. }
  2731. /* All notify is called in cmd thread, don't need to leave low power again
  2732. * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
  2733. if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
  2734. #ifdef CONFIG_RTL8821A
  2735. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2736. ex_halbtc8821a2ant_scan_notify(pBtCoexist, scanType);
  2737. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2738. ex_halbtc8821a1ant_scan_notify(pBtCoexist, scanType);
  2739. #endif
  2740. }
  2741. #ifdef CONFIG_RTL8723B
  2742. else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  2743. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2744. ex_halbtc8723b2ant_scan_notify(pBtCoexist, scanType);
  2745. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2746. ex_halbtc8723b1ant_scan_notify(pBtCoexist, scanType);
  2747. }
  2748. #endif
  2749. #ifdef CONFIG_RTL8703B
  2750. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  2751. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2752. ex_halbtc8703b1ant_scan_notify(pBtCoexist, scanType);
  2753. }
  2754. #endif
  2755. #ifdef CONFIG_RTL8723D
  2756. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  2757. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2758. ex_halbtc8723d2ant_scan_notify(pBtCoexist, scanType);
  2759. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2760. ex_halbtc8723d1ant_scan_notify(pBtCoexist, scanType);
  2761. }
  2762. #endif
  2763. #ifdef CONFIG_RTL8192E
  2764. else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
  2765. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2766. ex_halbtc8192e2ant_scan_notify(pBtCoexist, scanType);
  2767. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2768. ex_halbtc8192e1ant_scan_notify(pBtCoexist, scanType);
  2769. }
  2770. #endif
  2771. #ifdef CONFIG_RTL8812A
  2772. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  2773. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2774. ex_halbtc8812a2ant_scan_notify(pBtCoexist, scanType);
  2775. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2776. ex_halbtc8812a1ant_scan_notify(pBtCoexist, scanType);
  2777. }
  2778. #endif
  2779. #ifdef CONFIG_RTL8822B
  2780. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  2781. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2782. ex_halbtc8822b1ant_scan_notify(pBtCoexist, scanType);
  2783. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  2784. ex_halbtc8822b2ant_scan_notify(pBtCoexist, scanType);
  2785. }
  2786. #endif
  2787. #ifdef CONFIG_RTL8821C
  2788. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  2789. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2790. ex_halbtc8821c2ant_scan_notify(pBtCoexist, scanType);
  2791. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2792. ex_halbtc8821c1ant_scan_notify(pBtCoexist, scanType);
  2793. }
  2794. #endif
  2795. /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
  2796. }
  2797. void EXhalbtcoutsrc_SetAntennaPathNotify(PBTC_COEXIST pBtCoexist, u8 type)
  2798. {
  2799. #if 0
  2800. u8 switchType;
  2801. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  2802. return;
  2803. if (pBtCoexist->manual_control)
  2804. return;
  2805. halbtcoutsrc_LeaveLowPower(pBtCoexist);
  2806. switchType = type;
  2807. if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  2808. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2809. ex_halbtc8723b1ant_set_antenna_notify(pBtCoexist, type);
  2810. }
  2811. if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  2812. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2813. ex_halbtc8723d1ant_set_antenna_notify(pBtCoexist, type);
  2814. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  2815. ex_halbtc8723d2ant_set_antenna_notify(pBtCoexist, type);
  2816. }
  2817. halbtcoutsrc_NormalLowPower(pBtCoexist);
  2818. #endif
  2819. }
  2820. void EXhalbtcoutsrc_connect_notify(PBTC_COEXIST pBtCoexist, u8 assoType)
  2821. {
  2822. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  2823. return;
  2824. pBtCoexist->statistics.cnt_connect_notify++;
  2825. if (pBtCoexist->manual_control)
  2826. return;
  2827. /* All notify is called in cmd thread, don't need to leave low power again
  2828. * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
  2829. if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
  2830. #ifdef CONFIG_RTL8821A
  2831. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2832. ex_halbtc8821a2ant_connect_notify(pBtCoexist, assoType);
  2833. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2834. ex_halbtc8821a1ant_connect_notify(pBtCoexist, assoType);
  2835. #endif
  2836. }
  2837. #ifdef CONFIG_RTL8723B
  2838. else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  2839. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2840. ex_halbtc8723b2ant_connect_notify(pBtCoexist, assoType);
  2841. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2842. ex_halbtc8723b1ant_connect_notify(pBtCoexist, assoType);
  2843. }
  2844. #endif
  2845. #ifdef CONFIG_RTL8703B
  2846. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  2847. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2848. ex_halbtc8703b1ant_connect_notify(pBtCoexist, assoType);
  2849. }
  2850. #endif
  2851. #ifdef CONFIG_RTL8723D
  2852. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  2853. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2854. ex_halbtc8723d2ant_connect_notify(pBtCoexist, assoType);
  2855. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2856. ex_halbtc8723d1ant_connect_notify(pBtCoexist, assoType);
  2857. }
  2858. #endif
  2859. #ifdef CONFIG_RTL8192E
  2860. else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
  2861. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2862. ex_halbtc8192e2ant_connect_notify(pBtCoexist, assoType);
  2863. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2864. ex_halbtc8192e1ant_connect_notify(pBtCoexist, assoType);
  2865. }
  2866. #endif
  2867. #ifdef CONFIG_RTL8812A
  2868. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  2869. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2870. ex_halbtc8812a2ant_connect_notify(pBtCoexist, assoType);
  2871. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2872. ex_halbtc8812a1ant_connect_notify(pBtCoexist, assoType);
  2873. }
  2874. #endif
  2875. #ifdef CONFIG_RTL8822B
  2876. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  2877. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2878. ex_halbtc8822b1ant_connect_notify(pBtCoexist, assoType);
  2879. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  2880. ex_halbtc8822b2ant_connect_notify(pBtCoexist, assoType);
  2881. }
  2882. #endif
  2883. #ifdef CONFIG_RTL8821C
  2884. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  2885. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2886. ex_halbtc8821c2ant_connect_notify(pBtCoexist, assoType);
  2887. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2888. ex_halbtc8821c1ant_connect_notify(pBtCoexist, assoType);
  2889. }
  2890. #endif
  2891. /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
  2892. }
  2893. void EXhalbtcoutsrc_media_status_notify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus)
  2894. {
  2895. u8 mStatus = BTC_MEDIA_MAX;
  2896. PADAPTER adapter = (PADAPTER)pBtCoexist->Adapter;
  2897. HAL_DATA_TYPE *hal = GET_HAL_DATA(adapter);
  2898. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  2899. return;
  2900. pBtCoexist->statistics.cnt_media_status_notify++;
  2901. if (pBtCoexist->manual_control)
  2902. return;
  2903. if (RT_MEDIA_CONNECT == mediaStatus) {
  2904. if (hal->current_band_type == BAND_ON_2_4G)
  2905. mStatus = BTC_MEDIA_CONNECT;
  2906. else if (hal->current_band_type == BAND_ON_5G)
  2907. mStatus = BTC_MEDIA_CONNECT_5G;
  2908. else {
  2909. mStatus = BTC_MEDIA_CONNECT;
  2910. RTW_ERR("%s unknow band type\n", __func__);
  2911. }
  2912. } else
  2913. mStatus = BTC_MEDIA_DISCONNECT;
  2914. /* All notify is called in cmd thread, don't need to leave low power again
  2915. * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
  2916. if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
  2917. #ifdef CONFIG_RTL8821A
  2918. /* compatible for 8821A */
  2919. if (mStatus == BTC_MEDIA_CONNECT_5G)
  2920. mStatus = BTC_MEDIA_CONNECT;
  2921. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2922. ex_halbtc8821a2ant_media_status_notify(pBtCoexist, mStatus);
  2923. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2924. ex_halbtc8821a1ant_media_status_notify(pBtCoexist, mStatus);
  2925. #endif
  2926. }
  2927. #ifdef CONFIG_RTL8723B
  2928. else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  2929. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2930. ex_halbtc8723b2ant_media_status_notify(pBtCoexist, mStatus);
  2931. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2932. ex_halbtc8723b1ant_media_status_notify(pBtCoexist, mStatus);
  2933. }
  2934. #endif
  2935. #ifdef CONFIG_RTL8703B
  2936. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  2937. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2938. ex_halbtc8703b1ant_media_status_notify(pBtCoexist, mStatus);
  2939. }
  2940. #endif
  2941. #ifdef CONFIG_RTL8723D
  2942. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  2943. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2944. ex_halbtc8723d2ant_media_status_notify(pBtCoexist, mStatus);
  2945. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2946. ex_halbtc8723d1ant_media_status_notify(pBtCoexist, mStatus);
  2947. }
  2948. #endif
  2949. #ifdef CONFIG_RTL8192E
  2950. else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
  2951. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2952. ex_halbtc8192e2ant_media_status_notify(pBtCoexist, mStatus);
  2953. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2954. ex_halbtc8192e1ant_media_status_notify(pBtCoexist, mStatus);
  2955. }
  2956. #endif
  2957. #ifdef CONFIG_RTL8812A
  2958. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  2959. /* compatible for 8812A */
  2960. if (mStatus == BTC_MEDIA_CONNECT_5G)
  2961. mStatus = BTC_MEDIA_CONNECT;
  2962. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2963. ex_halbtc8812a2ant_media_status_notify(pBtCoexist, mStatus);
  2964. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2965. ex_halbtc8812a1ant_media_status_notify(pBtCoexist, mStatus);
  2966. }
  2967. #endif
  2968. #ifdef CONFIG_RTL8822B
  2969. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  2970. if (pBtCoexist->board_info.btdm_ant_num == 1)
  2971. ex_halbtc8822b1ant_media_status_notify(pBtCoexist, mStatus);
  2972. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  2973. ex_halbtc8822b2ant_media_status_notify(pBtCoexist, mStatus);
  2974. }
  2975. #endif
  2976. #ifdef CONFIG_RTL8821C
  2977. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  2978. if (pBtCoexist->board_info.btdm_ant_num == 2)
  2979. ex_halbtc8821c2ant_media_status_notify(pBtCoexist, mStatus);
  2980. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  2981. ex_halbtc8821c1ant_media_status_notify(pBtCoexist, mStatus);
  2982. }
  2983. #endif
  2984. /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
  2985. }
  2986. void EXhalbtcoutsrc_specific_packet_notify(PBTC_COEXIST pBtCoexist, u8 pktType)
  2987. {
  2988. u8 packetType;
  2989. PADAPTER adapter = (PADAPTER)pBtCoexist->Adapter;
  2990. HAL_DATA_TYPE *hal = GET_HAL_DATA(adapter);
  2991. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  2992. return;
  2993. pBtCoexist->statistics.cnt_specific_packet_notify++;
  2994. if (pBtCoexist->manual_control)
  2995. return;
  2996. if (PACKET_DHCP == pktType)
  2997. packetType = BTC_PACKET_DHCP;
  2998. else if (PACKET_EAPOL == pktType)
  2999. packetType = BTC_PACKET_EAPOL;
  3000. else if (PACKET_ARP == pktType)
  3001. packetType = BTC_PACKET_ARP;
  3002. else {
  3003. packetType = BTC_PACKET_UNKNOWN;
  3004. return;
  3005. }
  3006. if (hal->current_band_type == BAND_ON_5G)
  3007. packetType |= BTC_5G_BAND;
  3008. /* All notify is called in cmd thread, don't need to leave low power again
  3009. * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
  3010. if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
  3011. #ifdef CONFIG_RTL8821A
  3012. /* compatible for 8821A */
  3013. if (hal->current_band_type == BAND_ON_5G)
  3014. packetType &= ~BTC_5G_BAND;
  3015. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3016. ex_halbtc8821a2ant_specific_packet_notify(pBtCoexist, packetType);
  3017. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3018. ex_halbtc8821a1ant_specific_packet_notify(pBtCoexist, packetType);
  3019. #endif
  3020. }
  3021. #ifdef CONFIG_RTL8723B
  3022. else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  3023. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3024. ex_halbtc8723b2ant_specific_packet_notify(pBtCoexist, packetType);
  3025. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3026. ex_halbtc8723b1ant_specific_packet_notify(pBtCoexist, packetType);
  3027. }
  3028. #endif
  3029. #ifdef CONFIG_RTL8703B
  3030. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  3031. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3032. ex_halbtc8703b1ant_specific_packet_notify(pBtCoexist, packetType);
  3033. }
  3034. #endif
  3035. #ifdef CONFIG_RTL8723D
  3036. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  3037. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3038. ex_halbtc8723d2ant_specific_packet_notify(pBtCoexist, packetType);
  3039. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3040. ex_halbtc8723d1ant_specific_packet_notify(pBtCoexist, packetType);
  3041. }
  3042. #endif
  3043. #ifdef CONFIG_RTL8192E
  3044. else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
  3045. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3046. ex_halbtc8192e2ant_specific_packet_notify(pBtCoexist, packetType);
  3047. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3048. ex_halbtc8192e1ant_specific_packet_notify(pBtCoexist, packetType);
  3049. }
  3050. #endif
  3051. #ifdef CONFIG_RTL8812A
  3052. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  3053. /* compatible for 8812A */
  3054. if (hal->current_band_type == BAND_ON_5G)
  3055. packetType &= ~BTC_5G_BAND;
  3056. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3057. ex_halbtc8812a2ant_specific_packet_notify(pBtCoexist, packetType);
  3058. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3059. ex_halbtc8812a1ant_specific_packet_notify(pBtCoexist, packetType);
  3060. }
  3061. #endif
  3062. #ifdef CONFIG_RTL8822B
  3063. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  3064. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3065. ex_halbtc8822b1ant_specific_packet_notify(pBtCoexist, packetType);
  3066. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  3067. ex_halbtc8822b2ant_specific_packet_notify(pBtCoexist, packetType);
  3068. }
  3069. #endif
  3070. #ifdef CONFIG_RTL8821C
  3071. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  3072. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3073. ex_halbtc8821c2ant_specific_packet_notify(pBtCoexist, packetType);
  3074. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3075. ex_halbtc8821c1ant_specific_packet_notify(pBtCoexist, packetType);
  3076. }
  3077. #endif
  3078. /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
  3079. }
  3080. void EXhalbtcoutsrc_bt_info_notify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
  3081. {
  3082. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3083. return;
  3084. pBtCoexist->statistics.cnt_bt_info_notify++;
  3085. /* All notify is called in cmd thread, don't need to leave low power again
  3086. * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
  3087. if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
  3088. #ifdef CONFIG_RTL8821A
  3089. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3090. ex_halbtc8821a2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3091. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3092. ex_halbtc8821a1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3093. #endif
  3094. }
  3095. #ifdef CONFIG_RTL8723B
  3096. else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  3097. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3098. ex_halbtc8723b2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3099. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3100. ex_halbtc8723b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3101. }
  3102. #endif
  3103. #ifdef CONFIG_RTL8703B
  3104. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  3105. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3106. ex_halbtc8703b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3107. }
  3108. #endif
  3109. #ifdef CONFIG_RTL8723D
  3110. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  3111. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3112. ex_halbtc8723d2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3113. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3114. ex_halbtc8723d1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3115. }
  3116. #endif
  3117. #ifdef CONFIG_RTL8192E
  3118. else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
  3119. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3120. ex_halbtc8192e2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3121. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3122. ex_halbtc8192e1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3123. }
  3124. #endif
  3125. #ifdef CONFIG_RTL8812A
  3126. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  3127. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3128. ex_halbtc8812a2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3129. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3130. ex_halbtc8812a1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3131. }
  3132. #endif
  3133. #ifdef CONFIG_RTL8822B
  3134. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  3135. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3136. ex_halbtc8822b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3137. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  3138. ex_halbtc8822b2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3139. }
  3140. #endif
  3141. #ifdef CONFIG_RTL8821C
  3142. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  3143. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3144. ex_halbtc8821c2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3145. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3146. ex_halbtc8821c1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
  3147. }
  3148. #endif
  3149. /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
  3150. }
  3151. void EXhalbtcoutsrc_WlFwDbgInfoNotify(PBTC_COEXIST pBtCoexist, u8* tmpBuf, u8 length)
  3152. {
  3153. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3154. return;
  3155. if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  3156. #ifdef CONFIG_RTL8703B
  3157. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3158. ex_halbtc8703b1ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);
  3159. #endif
  3160. }
  3161. #ifdef CONFIG_RTL8723D
  3162. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  3163. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3164. ex_halbtc8723d1ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);
  3165. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  3166. ex_halbtc8723d2ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);
  3167. }
  3168. #endif
  3169. #ifdef CONFIG_RTL8821C
  3170. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  3171. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3172. ex_halbtc8821c2ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);
  3173. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3174. ex_halbtc8821c1ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);
  3175. }
  3176. #endif
  3177. }
  3178. void EXhalbtcoutsrc_rx_rate_change_notify(PBTC_COEXIST pBtCoexist, u8 is_data_frame, u8 btc_rate_id)
  3179. {
  3180. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3181. return;
  3182. pBtCoexist->statistics.cnt_rate_id_notify++;
  3183. if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  3184. #ifdef CONFIG_RTL8703B
  3185. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3186. ex_halbtc8703b1ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);
  3187. #endif
  3188. }
  3189. #ifdef CONFIG_RTL8723D
  3190. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  3191. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3192. ex_halbtc8723d1ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);
  3193. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  3194. ex_halbtc8723d2ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);
  3195. }
  3196. #endif
  3197. #ifdef CONFIG_RTL8821C
  3198. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  3199. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3200. ex_halbtc8821c1ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);
  3201. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  3202. ex_halbtc8821c2ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);
  3203. }
  3204. #endif
  3205. }
  3206. VOID
  3207. EXhalbtcoutsrc_RfStatusNotify(
  3208. IN PBTC_COEXIST pBtCoexist,
  3209. IN u1Byte type
  3210. )
  3211. {
  3212. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3213. return;
  3214. pBtCoexist->statistics.cnt_rf_status_notify++;
  3215. if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  3216. #ifdef CONFIG_RTL8723B
  3217. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3218. ex_halbtc8723b1ant_rf_status_notify(pBtCoexist, type);
  3219. #endif
  3220. }
  3221. #ifdef CONFIG_RTL8703B
  3222. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  3223. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3224. ex_halbtc8703b1ant_rf_status_notify(pBtCoexist, type);
  3225. }
  3226. #endif
  3227. #ifdef CONFIG_RTL8723D
  3228. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  3229. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3230. ex_halbtc8723d1ant_rf_status_notify(pBtCoexist, type);
  3231. }
  3232. #endif
  3233. #ifdef CONFIG_RTL8822B
  3234. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  3235. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3236. ex_halbtc8822b1ant_rf_status_notify(pBtCoexist, type);
  3237. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  3238. ex_halbtc8822b2ant_rf_status_notify(pBtCoexist, type);
  3239. }
  3240. #endif
  3241. #ifdef CONFIG_RTL8821C
  3242. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  3243. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3244. ex_halbtc8821c2ant_rf_status_notify(pBtCoexist, type);
  3245. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3246. ex_halbtc8821c1ant_rf_status_notify(pBtCoexist, type);
  3247. }
  3248. #endif
  3249. }
  3250. void EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist, u8 type)
  3251. {
  3252. #if 0
  3253. u8 stackOpType;
  3254. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3255. return;
  3256. pBtCoexist->statistics.cntStackOperationNotify++;
  3257. if (pBtCoexist->manual_control)
  3258. return;
  3259. if ((HCI_BT_OP_INQUIRY_START == type) ||
  3260. (HCI_BT_OP_PAGING_START == type) ||
  3261. (HCI_BT_OP_PAIRING_START == type))
  3262. stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_START;
  3263. else if ((HCI_BT_OP_INQUIRY_FINISH == type) ||
  3264. (HCI_BT_OP_PAGING_SUCCESS == type) ||
  3265. (HCI_BT_OP_PAGING_UNSUCCESS == type) ||
  3266. (HCI_BT_OP_PAIRING_FINISH == type))
  3267. stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
  3268. else
  3269. stackOpType = BTC_STACK_OP_NONE;
  3270. #endif
  3271. }
  3272. void EXhalbtcoutsrc_halt_notify(PBTC_COEXIST pBtCoexist)
  3273. {
  3274. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3275. return;
  3276. pBtCoexist->statistics.cnt_halt_notify++;
  3277. if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
  3278. #ifdef CONFIG_RTL8821A
  3279. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3280. ex_halbtc8821a2ant_halt_notify(pBtCoexist);
  3281. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3282. ex_halbtc8821a1ant_halt_notify(pBtCoexist);
  3283. #endif
  3284. }
  3285. #ifdef CONFIG_RTL8723B
  3286. else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  3287. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3288. ex_halbtc8723b2ant_halt_notify(pBtCoexist);
  3289. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3290. ex_halbtc8723b1ant_halt_notify(pBtCoexist);
  3291. }
  3292. #endif
  3293. #ifdef CONFIG_RTL8703B
  3294. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  3295. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3296. ex_halbtc8703b1ant_halt_notify(pBtCoexist);
  3297. }
  3298. #endif
  3299. #ifdef CONFIG_RTL8723D
  3300. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  3301. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3302. ex_halbtc8723d2ant_halt_notify(pBtCoexist);
  3303. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3304. ex_halbtc8723d1ant_halt_notify(pBtCoexist);
  3305. }
  3306. #endif
  3307. #ifdef CONFIG_RTL8192E
  3308. else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
  3309. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3310. ex_halbtc8192e2ant_halt_notify(pBtCoexist);
  3311. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3312. ex_halbtc8192e1ant_halt_notify(pBtCoexist);
  3313. }
  3314. #endif
  3315. #ifdef CONFIG_RTL8812A
  3316. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  3317. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3318. ex_halbtc8812a2ant_halt_notify(pBtCoexist);
  3319. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3320. ex_halbtc8812a1ant_halt_notify(pBtCoexist);
  3321. }
  3322. #endif
  3323. #ifdef CONFIG_RTL8822B
  3324. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  3325. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3326. ex_halbtc8822b1ant_halt_notify(pBtCoexist);
  3327. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  3328. ex_halbtc8822b2ant_halt_notify(pBtCoexist);
  3329. }
  3330. #endif
  3331. #ifdef CONFIG_RTL8821C
  3332. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  3333. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3334. ex_halbtc8821c2ant_halt_notify(pBtCoexist);
  3335. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3336. ex_halbtc8821c1ant_halt_notify(pBtCoexist);
  3337. }
  3338. #endif
  3339. }
  3340. void EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist)
  3341. {
  3342. if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  3343. if (pBtCoexist->board_info.btdm_ant_num == 2) {
  3344. halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x01); /* BT goto standby while GNT_BT 1-->0 */
  3345. } else if (pBtCoexist->board_info.btdm_ant_num == 1) {
  3346. halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x15); /* BT goto standby while GNT_BT 1-->0 */
  3347. }
  3348. }
  3349. }
  3350. void EXhalbtcoutsrc_pnp_notify(PBTC_COEXIST pBtCoexist, u8 pnpState)
  3351. {
  3352. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3353. return;
  3354. pBtCoexist->statistics.cnt_pnp_notify++;
  3355. /* */
  3356. /* currently only 1ant we have to do the notification, */
  3357. /* once pnp is notified to sleep state, we have to leave LPS that we can sleep normally. */
  3358. /* */
  3359. if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  3360. #ifdef CONFIG_RTL8723B
  3361. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3362. ex_halbtc8723b1ant_pnp_notify(pBtCoexist, pnpState);
  3363. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  3364. ex_halbtc8723b2ant_pnp_notify(pBtCoexist, pnpState);
  3365. #endif
  3366. }
  3367. #ifdef CONFIG_RTL8703B
  3368. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  3369. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3370. ex_halbtc8703b1ant_pnp_notify(pBtCoexist, pnpState);
  3371. }
  3372. #endif
  3373. #ifdef CONFIG_RTL8723D
  3374. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  3375. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3376. ex_halbtc8723d1ant_pnp_notify(pBtCoexist, pnpState);
  3377. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  3378. ex_halbtc8723d2ant_pnp_notify(pBtCoexist, pnpState);
  3379. }
  3380. #endif
  3381. #ifdef CONFIG_RTL8821A
  3382. else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
  3383. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3384. ex_halbtc8821a1ant_pnp_notify(pBtCoexist, pnpState);
  3385. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  3386. ex_halbtc8821a2ant_pnp_notify(pBtCoexist, pnpState);
  3387. }
  3388. #endif
  3389. #ifdef CONFIG_RTL8192E
  3390. else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
  3391. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3392. ex_halbtc8192e1ant_pnp_notify(pBtCoexist, pnpState);
  3393. }
  3394. #endif
  3395. #ifdef CONFIG_RTL8812A
  3396. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  3397. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3398. ex_halbtc8812a1ant_pnp_notify(pBtCoexist, pnpState);
  3399. }
  3400. #endif
  3401. #ifdef CONFIG_RTL8822B
  3402. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  3403. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3404. ex_halbtc8822b1ant_pnp_notify(pBtCoexist, pnpState);
  3405. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  3406. ex_halbtc8822b2ant_pnp_notify(pBtCoexist, pnpState);
  3407. }
  3408. #endif
  3409. #ifdef CONFIG_RTL8821C
  3410. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  3411. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3412. ex_halbtc8821c2ant_pnp_notify(pBtCoexist, pnpState);
  3413. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3414. ex_halbtc8821c1ant_pnp_notify(pBtCoexist, pnpState);
  3415. }
  3416. #endif
  3417. }
  3418. void EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist)
  3419. {
  3420. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3421. return;
  3422. pBtCoexist->statistics.cnt_coex_dm_switch++;
  3423. halbtcoutsrc_LeaveLowPower(pBtCoexist);
  3424. if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  3425. #ifdef CONFIG_RTL8723B
  3426. if (pBtCoexist->board_info.btdm_ant_num == 1) {
  3427. pBtCoexist->stop_coex_dm = TRUE;
  3428. ex_halbtc8723b1ant_coex_dm_reset(pBtCoexist);
  3429. EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);
  3430. ex_halbtc8723b2ant_init_hw_config(pBtCoexist, FALSE);
  3431. ex_halbtc8723b2ant_init_coex_dm(pBtCoexist);
  3432. pBtCoexist->stop_coex_dm = FALSE;
  3433. }
  3434. #endif
  3435. }
  3436. #ifdef CONFIG_RTL8723D
  3437. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  3438. if (pBtCoexist->board_info.btdm_ant_num == 1) {
  3439. pBtCoexist->stop_coex_dm = TRUE;
  3440. ex_halbtc8723d1ant_coex_dm_reset(pBtCoexist);
  3441. EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);
  3442. ex_halbtc8723d2ant_init_hw_config(pBtCoexist, FALSE);
  3443. ex_halbtc8723d2ant_init_coex_dm(pBtCoexist);
  3444. pBtCoexist->stop_coex_dm = FALSE;
  3445. }
  3446. }
  3447. #endif
  3448. halbtcoutsrc_NormalLowPower(pBtCoexist);
  3449. }
  3450. void EXhalbtcoutsrc_periodical(PBTC_COEXIST pBtCoexist)
  3451. {
  3452. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3453. return;
  3454. pBtCoexist->statistics.cnt_periodical++;
  3455. /* Periodical should be called in cmd thread, */
  3456. /* don't need to leave low power again
  3457. * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
  3458. if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
  3459. #ifdef CONFIG_RTL8821A
  3460. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3461. ex_halbtc8821a2ant_periodical(pBtCoexist);
  3462. else if (pBtCoexist->board_info.btdm_ant_num == 1) {
  3463. if (!halbtcoutsrc_UnderIps(pBtCoexist))
  3464. ex_halbtc8821a1ant_periodical(pBtCoexist);
  3465. }
  3466. #endif
  3467. }
  3468. #ifdef CONFIG_RTL8723B
  3469. else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  3470. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3471. ex_halbtc8723b2ant_periodical(pBtCoexist);
  3472. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3473. ex_halbtc8723b1ant_periodical(pBtCoexist);
  3474. }
  3475. #endif
  3476. #ifdef CONFIG_RTL8723D
  3477. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  3478. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3479. ex_halbtc8723d2ant_periodical(pBtCoexist);
  3480. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3481. ex_halbtc8723d1ant_periodical(pBtCoexist);
  3482. }
  3483. #endif
  3484. #ifdef CONFIG_RTL8703B
  3485. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  3486. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3487. ex_halbtc8703b1ant_periodical(pBtCoexist);
  3488. }
  3489. #endif
  3490. #ifdef CONFIG_RTL8192E
  3491. else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
  3492. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3493. ex_halbtc8192e2ant_periodical(pBtCoexist);
  3494. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3495. ex_halbtc8192e1ant_periodical(pBtCoexist);
  3496. }
  3497. #endif
  3498. #ifdef CONFIG_RTL8812A
  3499. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  3500. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3501. ex_halbtc8812a2ant_periodical(pBtCoexist);
  3502. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3503. ex_halbtc8812a1ant_periodical(pBtCoexist);
  3504. }
  3505. #endif
  3506. #ifdef CONFIG_RTL8822B
  3507. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  3508. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3509. ex_halbtc8822b1ant_periodical(pBtCoexist);
  3510. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  3511. ex_halbtc8822b2ant_periodical(pBtCoexist);
  3512. }
  3513. #endif
  3514. #ifdef CONFIG_RTL8821C
  3515. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  3516. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3517. ex_halbtc8821c2ant_periodical(pBtCoexist);
  3518. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3519. ex_halbtc8821c1ant_periodical(pBtCoexist);
  3520. }
  3521. #endif
  3522. /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
  3523. }
  3524. void EXhalbtcoutsrc_dbg_control(PBTC_COEXIST pBtCoexist, u8 opCode, u8 opLen, u8 *pData)
  3525. {
  3526. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3527. return;
  3528. pBtCoexist->statistics.cnt_dbg_ctrl++;
  3529. /* This function doesn't be called yet, */
  3530. /* default no need to leave low power to avoid deadlock
  3531. * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
  3532. if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
  3533. #ifdef CONFIG_RTL8192E
  3534. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3535. ex_halbtc8192e1ant_dbg_control(pBtCoexist, opCode, opLen, pData);
  3536. #endif
  3537. }
  3538. #ifdef CONFIG_RTL8812A
  3539. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  3540. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3541. ex_halbtc8812a2ant_dbg_control(pBtCoexist, opCode, opLen, pData);
  3542. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3543. ex_halbtc8812a1ant_dbg_control(pBtCoexist, opCode, opLen, pData);
  3544. }
  3545. #endif
  3546. #ifdef CONFIG_RTL8822B
  3547. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter))
  3548. if(pBtCoexist->board_info.btdm_ant_num == 1)
  3549. ex_halbtc8822b1ant_dbg_control(pBtCoexist, opCode, opLen, pData);
  3550. #endif
  3551. /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
  3552. }
  3553. #if 0
  3554. VOID
  3555. EXhalbtcoutsrc_AntennaDetection(
  3556. IN PBTC_COEXIST pBtCoexist,
  3557. IN u4Byte centFreq,
  3558. IN u4Byte offset,
  3559. IN u4Byte span,
  3560. IN u4Byte seconds
  3561. )
  3562. {
  3563. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3564. return;
  3565. /* Need to refine the following power save operations to enable this function in the future */
  3566. #if 0
  3567. IPSDisable(pBtCoexist->Adapter, FALSE, 0);
  3568. LeisurePSLeave(pBtCoexist->Adapter, LPS_DISABLE_BT_COEX);
  3569. #endif
  3570. if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  3571. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3572. ex_halbtc8723b1ant_AntennaDetection(pBtCoexist, centFreq, offset, span, seconds);
  3573. }
  3574. /* IPSReturn(pBtCoexist->Adapter, 0xff); */
  3575. }
  3576. #endif
  3577. void EXhalbtcoutsrc_StackUpdateProfileInfo(void)
  3578. {
  3579. #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
  3580. PBTC_COEXIST pBtCoexist = &GLBtCoexist;
  3581. PADAPTER padapter = (PADAPTER)GLBtCoexist.Adapter;
  3582. PBT_MGNT pBtMgnt = &padapter->coex_info.BtMgnt;
  3583. u8 i;
  3584. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3585. return;
  3586. pBtCoexist->stack_info.profile_notified = _TRUE;
  3587. pBtCoexist->stack_info.num_of_link =
  3588. pBtMgnt->ExtConfig.NumberOfACL + pBtMgnt->ExtConfig.NumberOfSCO;
  3589. /* reset first */
  3590. pBtCoexist->stack_info.bt_link_exist = _FALSE;
  3591. pBtCoexist->stack_info.sco_exist = _FALSE;
  3592. pBtCoexist->stack_info.acl_exist = _FALSE;
  3593. pBtCoexist->stack_info.a2dp_exist = _FALSE;
  3594. pBtCoexist->stack_info.hid_exist = _FALSE;
  3595. pBtCoexist->stack_info.num_of_hid = 0;
  3596. pBtCoexist->stack_info.pan_exist = _FALSE;
  3597. if (!pBtMgnt->ExtConfig.NumberOfACL)
  3598. pBtCoexist->stack_info.min_bt_rssi = 0;
  3599. if (pBtCoexist->stack_info.num_of_link) {
  3600. pBtCoexist->stack_info.bt_link_exist = _TRUE;
  3601. if (pBtMgnt->ExtConfig.NumberOfSCO)
  3602. pBtCoexist->stack_info.sco_exist = _TRUE;
  3603. if (pBtMgnt->ExtConfig.NumberOfACL)
  3604. pBtCoexist->stack_info.acl_exist = _TRUE;
  3605. }
  3606. for (i = 0; i < pBtMgnt->ExtConfig.NumberOfACL; i++) {
  3607. if (BT_PROFILE_A2DP == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
  3608. pBtCoexist->stack_info.a2dp_exist = _TRUE;
  3609. else if (BT_PROFILE_PAN == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
  3610. pBtCoexist->stack_info.pan_exist = _TRUE;
  3611. else if (BT_PROFILE_HID == pBtMgnt->ExtConfig.aclLink[i].BTProfile) {
  3612. pBtCoexist->stack_info.hid_exist = _TRUE;
  3613. pBtCoexist->stack_info.num_of_hid++;
  3614. } else
  3615. pBtCoexist->stack_info.unknown_acl_exist = _TRUE;
  3616. }
  3617. #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
  3618. }
  3619. void EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi)
  3620. {
  3621. PBTC_COEXIST pBtCoexist = &GLBtCoexist;
  3622. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3623. return;
  3624. pBtCoexist->stack_info.min_bt_rssi = btRssi;
  3625. }
  3626. void EXhalbtcoutsrc_SetHciVersion(u16 hciVersion)
  3627. {
  3628. PBTC_COEXIST pBtCoexist = &GLBtCoexist;
  3629. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3630. return;
  3631. pBtCoexist->stack_info.hci_version = hciVersion;
  3632. }
  3633. void EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion, u16 btPatchVersion)
  3634. {
  3635. PBTC_COEXIST pBtCoexist = &GLBtCoexist;
  3636. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3637. return;
  3638. pBtCoexist->bt_info.bt_real_fw_ver = btPatchVersion;
  3639. pBtCoexist->bt_info.bt_hci_ver = btHciVersion;
  3640. }
  3641. #if 0
  3642. void EXhalbtcoutsrc_SetBtExist(u8 bBtExist)
  3643. {
  3644. GLBtCoexist.boardInfo.bBtExist = bBtExist;
  3645. }
  3646. #endif
  3647. void EXhalbtcoutsrc_SetChipType(u8 chipType)
  3648. {
  3649. switch (chipType) {
  3650. default:
  3651. case BT_2WIRE:
  3652. case BT_ISSC_3WIRE:
  3653. case BT_ACCEL:
  3654. case BT_RTL8756:
  3655. GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_UNDEF;
  3656. break;
  3657. case BT_CSR_BC4:
  3658. GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
  3659. break;
  3660. case BT_CSR_BC8:
  3661. GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
  3662. break;
  3663. case BT_RTL8723A:
  3664. GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A;
  3665. break;
  3666. case BT_RTL8821:
  3667. GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8821;
  3668. break;
  3669. case BT_RTL8723B:
  3670. GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B;
  3671. break;
  3672. }
  3673. }
  3674. void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
  3675. {
  3676. if (BT_COEX_ANT_TYPE_PG == type) {
  3677. GLBtCoexist.board_info.pg_ant_num = antNum;
  3678. GLBtCoexist.board_info.btdm_ant_num = antNum;
  3679. #if 0
  3680. /* The antenna position: Main (default) or Aux for pgAntNum=2 && btdmAntNum =1 */
  3681. /* The antenna position should be determined by auto-detect mechanism */
  3682. /* The following is assumed to main, and those must be modified if y auto-detect mechanism is ready */
  3683. if ((GLBtCoexist.board_info.pg_ant_num == 2) && (GLBtCoexist.board_info.btdm_ant_num == 1))
  3684. GLBtCoexist.board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
  3685. else
  3686. GLBtCoexist.board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
  3687. #endif
  3688. } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
  3689. GLBtCoexist.board_info.btdm_ant_num = antNum;
  3690. /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
  3691. } else if (BT_COEX_ANT_TYPE_DETECTED == type) {
  3692. GLBtCoexist.board_info.btdm_ant_num = antNum;
  3693. /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
  3694. }
  3695. }
  3696. /*
  3697. * Currently used by 8723b only, S0 or S1
  3698. * */
  3699. void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
  3700. {
  3701. GLBtCoexist.board_info.single_ant_path = singleAntPath;
  3702. }
  3703. void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)
  3704. {
  3705. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3706. return;
  3707. halbtcoutsrc_LeaveLowPower(pBtCoexist);
  3708. /* To prevent the racing with IPS enter */
  3709. halbtcoutsrc_EnterPwrLock(pBtCoexist);
  3710. if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
  3711. #ifdef CONFIG_RTL8821A
  3712. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3713. ex_halbtc8821a2ant_display_coex_info(pBtCoexist);
  3714. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3715. ex_halbtc8821a1ant_display_coex_info(pBtCoexist);
  3716. #endif
  3717. }
  3718. #ifdef CONFIG_RTL8723B
  3719. else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  3720. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3721. ex_halbtc8723b2ant_display_coex_info(pBtCoexist);
  3722. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3723. ex_halbtc8723b1ant_display_coex_info(pBtCoexist);
  3724. }
  3725. #endif
  3726. #ifdef CONFIG_RTL8703B
  3727. else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
  3728. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3729. ex_halbtc8703b1ant_display_coex_info(pBtCoexist);
  3730. }
  3731. #endif
  3732. #ifdef CONFIG_RTL8723D
  3733. else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
  3734. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3735. ex_halbtc8723d2ant_display_coex_info(pBtCoexist);
  3736. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3737. ex_halbtc8723d1ant_display_coex_info(pBtCoexist);
  3738. }
  3739. #endif
  3740. #ifdef CONFIG_RTL8192E
  3741. else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
  3742. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3743. ex_halbtc8192e2ant_display_coex_info(pBtCoexist);
  3744. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3745. ex_halbtc8192e1ant_display_coex_info(pBtCoexist);
  3746. }
  3747. #endif
  3748. #ifdef CONFIG_RTL8812A
  3749. else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  3750. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3751. ex_halbtc8812a2ant_display_coex_info(pBtCoexist);
  3752. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3753. ex_halbtc8812a1ant_display_coex_info(pBtCoexist);
  3754. }
  3755. #endif
  3756. #ifdef CONFIG_RTL8822B
  3757. else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  3758. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3759. ex_halbtc8822b1ant_display_coex_info(pBtCoexist);
  3760. else if (pBtCoexist->board_info.btdm_ant_num == 2)
  3761. ex_halbtc8822b2ant_display_coex_info(pBtCoexist);
  3762. }
  3763. #endif
  3764. #ifdef CONFIG_RTL8821C
  3765. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  3766. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3767. ex_halbtc8821c2ant_display_coex_info(pBtCoexist);
  3768. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3769. ex_halbtc8821c1ant_display_coex_info(pBtCoexist);
  3770. }
  3771. #endif
  3772. halbtcoutsrc_ExitPwrLock(pBtCoexist);
  3773. halbtcoutsrc_NormalLowPower(pBtCoexist);
  3774. }
  3775. void EXhalbtcoutsrc_DisplayAntDetection(PBTC_COEXIST pBtCoexist)
  3776. {
  3777. if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3778. return;
  3779. halbtcoutsrc_LeaveLowPower(pBtCoexist);
  3780. if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
  3781. #ifdef CONFIG_RTL8723B
  3782. if (pBtCoexist->board_info.btdm_ant_num == 1)
  3783. ex_halbtc8723b1ant_display_ant_detection(pBtCoexist);
  3784. #endif
  3785. }
  3786. halbtcoutsrc_NormalLowPower(pBtCoexist);
  3787. }
  3788. void ex_halbtcoutsrc_pta_off_on_notify(PBTC_COEXIST pBtCoexist, u8 bBTON)
  3789. {
  3790. #ifdef CONFIG_RTL8812A
  3791. if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
  3792. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3793. ex_halbtc8812a2ant_pta_off_on_notify(pBtCoexist, (bBTON == _TRUE) ? BTC_BT_ON : BTC_BT_OFF);
  3794. }
  3795. #endif
  3796. }
  3797. void EXhalbtcoutsrc_set_rfe_type(u8 type)
  3798. {
  3799. GLBtCoexist.board_info.rfe_type= type;
  3800. }
  3801. #ifdef CONFIG_RF4CE_COEXIST
  3802. void EXhalbtcoutsrc_set_rf4ce_link_state(u8 state)
  3803. {
  3804. GLBtCoexist.rf4ce_info.link_state = state;
  3805. }
  3806. u8 EXhalbtcoutsrc_get_rf4ce_link_state(void)
  3807. {
  3808. return GLBtCoexist.rf4ce_info.link_state;
  3809. }
  3810. #endif
  3811. void EXhalbtcoutsrc_switchband_notify(struct btc_coexist *pBtCoexist, u8 type)
  3812. {
  3813. if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
  3814. return;
  3815. if(pBtCoexist->manual_control)
  3816. return;
  3817. /* Driver should guarantee that the HW status isn't in low power mode */
  3818. /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
  3819. if(IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
  3820. #ifdef CONFIG_RTL8822B
  3821. if(pBtCoexist->board_info.btdm_ant_num == 1)
  3822. ex_halbtc8822b1ant_switchband_notify(pBtCoexist, type);
  3823. else if(pBtCoexist->board_info.btdm_ant_num == 2)
  3824. ex_halbtc8822b2ant_switchband_notify(pBtCoexist, type);
  3825. #endif
  3826. }
  3827. #ifdef CONFIG_RTL8821C
  3828. else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
  3829. if (pBtCoexist->board_info.btdm_ant_num == 2)
  3830. ex_halbtc8821c2ant_switchband_notify(pBtCoexist, type);
  3831. else if (pBtCoexist->board_info.btdm_ant_num == 1)
  3832. ex_halbtc8821c1ant_switchband_notify(pBtCoexist, type);
  3833. }
  3834. #endif
  3835. /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
  3836. }
  3837. u8 EXhalbtcoutsrc_rate_id_to_btc_rate_id(u8 rate_id)
  3838. {
  3839. u8 btc_rate_id = BTC_UNKNOWN;
  3840. switch (rate_id) {
  3841. /* CCK rates */
  3842. case DESC_RATE1M:
  3843. btc_rate_id = BTC_CCK_1;
  3844. break;
  3845. case DESC_RATE2M:
  3846. btc_rate_id = BTC_CCK_2;
  3847. break;
  3848. case DESC_RATE5_5M:
  3849. btc_rate_id = BTC_CCK_5_5;
  3850. break;
  3851. case DESC_RATE11M:
  3852. btc_rate_id = BTC_CCK_11;
  3853. break;
  3854. /* OFDM rates */
  3855. case DESC_RATE6M:
  3856. btc_rate_id = BTC_OFDM_6;
  3857. break;
  3858. case DESC_RATE9M:
  3859. btc_rate_id = BTC_OFDM_9;
  3860. break;
  3861. case DESC_RATE12M:
  3862. btc_rate_id = BTC_OFDM_12;
  3863. break;
  3864. case DESC_RATE18M:
  3865. btc_rate_id = BTC_OFDM_18;
  3866. break;
  3867. case DESC_RATE24M:
  3868. btc_rate_id = BTC_OFDM_24;
  3869. break;
  3870. case DESC_RATE36M:
  3871. btc_rate_id = BTC_OFDM_36;
  3872. break;
  3873. case DESC_RATE48M:
  3874. btc_rate_id = BTC_OFDM_48;
  3875. break;
  3876. case DESC_RATE54M:
  3877. btc_rate_id = BTC_OFDM_54;
  3878. break;
  3879. /* MCS rates */
  3880. case DESC_RATEMCS0:
  3881. btc_rate_id = BTC_MCS_0;
  3882. break;
  3883. case DESC_RATEMCS1:
  3884. btc_rate_id = BTC_MCS_1;
  3885. break;
  3886. case DESC_RATEMCS2:
  3887. btc_rate_id = BTC_MCS_2;
  3888. break;
  3889. case DESC_RATEMCS3:
  3890. btc_rate_id = BTC_MCS_3;
  3891. break;
  3892. case DESC_RATEMCS4:
  3893. btc_rate_id = BTC_MCS_4;
  3894. break;
  3895. case DESC_RATEMCS5:
  3896. btc_rate_id = BTC_MCS_5;
  3897. break;
  3898. case DESC_RATEMCS6:
  3899. btc_rate_id = BTC_MCS_6;
  3900. break;
  3901. case DESC_RATEMCS7:
  3902. btc_rate_id = BTC_MCS_7;
  3903. break;
  3904. case DESC_RATEMCS8:
  3905. btc_rate_id = BTC_MCS_8;
  3906. break;
  3907. case DESC_RATEMCS9:
  3908. btc_rate_id = BTC_MCS_9;
  3909. break;
  3910. case DESC_RATEMCS10:
  3911. btc_rate_id = BTC_MCS_10;
  3912. break;
  3913. case DESC_RATEMCS11:
  3914. btc_rate_id = BTC_MCS_11;
  3915. break;
  3916. case DESC_RATEMCS12:
  3917. btc_rate_id = BTC_MCS_12;
  3918. break;
  3919. case DESC_RATEMCS13:
  3920. btc_rate_id = BTC_MCS_13;
  3921. break;
  3922. case DESC_RATEMCS14:
  3923. btc_rate_id = BTC_MCS_14;
  3924. break;
  3925. case DESC_RATEMCS15:
  3926. btc_rate_id = BTC_MCS_15;
  3927. break;
  3928. case DESC_RATEMCS16:
  3929. btc_rate_id = BTC_MCS_16;
  3930. break;
  3931. case DESC_RATEMCS17:
  3932. btc_rate_id = BTC_MCS_17;
  3933. break;
  3934. case DESC_RATEMCS18:
  3935. btc_rate_id = BTC_MCS_18;
  3936. break;
  3937. case DESC_RATEMCS19:
  3938. btc_rate_id = BTC_MCS_19;
  3939. break;
  3940. case DESC_RATEMCS20:
  3941. btc_rate_id = BTC_MCS_20;
  3942. break;
  3943. case DESC_RATEMCS21:
  3944. btc_rate_id = BTC_MCS_21;
  3945. break;
  3946. case DESC_RATEMCS22:
  3947. btc_rate_id = BTC_MCS_22;
  3948. break;
  3949. case DESC_RATEMCS23:
  3950. btc_rate_id = BTC_MCS_23;
  3951. break;
  3952. case DESC_RATEMCS24:
  3953. btc_rate_id = BTC_MCS_24;
  3954. break;
  3955. case DESC_RATEMCS25:
  3956. btc_rate_id = BTC_MCS_25;
  3957. break;
  3958. case DESC_RATEMCS26:
  3959. btc_rate_id = BTC_MCS_26;
  3960. break;
  3961. case DESC_RATEMCS27:
  3962. btc_rate_id = BTC_MCS_27;
  3963. break;
  3964. case DESC_RATEMCS28:
  3965. btc_rate_id = BTC_MCS_28;
  3966. break;
  3967. case DESC_RATEMCS29:
  3968. btc_rate_id = BTC_MCS_29;
  3969. break;
  3970. case DESC_RATEMCS30:
  3971. btc_rate_id = BTC_MCS_30;
  3972. break;
  3973. case DESC_RATEMCS31:
  3974. btc_rate_id = BTC_MCS_31;
  3975. break;
  3976. case DESC_RATEVHTSS1MCS0:
  3977. btc_rate_id = BTC_VHT_1SS_MCS_0;
  3978. break;
  3979. case DESC_RATEVHTSS1MCS1:
  3980. btc_rate_id = BTC_VHT_1SS_MCS_1;
  3981. break;
  3982. case DESC_RATEVHTSS1MCS2:
  3983. btc_rate_id = BTC_VHT_1SS_MCS_2;
  3984. break;
  3985. case DESC_RATEVHTSS1MCS3:
  3986. btc_rate_id = BTC_VHT_1SS_MCS_3;
  3987. break;
  3988. case DESC_RATEVHTSS1MCS4:
  3989. btc_rate_id = BTC_VHT_1SS_MCS_4;
  3990. break;
  3991. case DESC_RATEVHTSS1MCS5:
  3992. btc_rate_id = BTC_VHT_1SS_MCS_5;
  3993. break;
  3994. case DESC_RATEVHTSS1MCS6:
  3995. btc_rate_id = BTC_VHT_1SS_MCS_6;
  3996. break;
  3997. case DESC_RATEVHTSS1MCS7:
  3998. btc_rate_id = BTC_VHT_1SS_MCS_7;
  3999. break;
  4000. case DESC_RATEVHTSS1MCS8:
  4001. btc_rate_id = BTC_VHT_1SS_MCS_8;
  4002. break;
  4003. case DESC_RATEVHTSS1MCS9:
  4004. btc_rate_id = BTC_VHT_1SS_MCS_9;
  4005. break;
  4006. case DESC_RATEVHTSS2MCS0:
  4007. btc_rate_id = BTC_VHT_2SS_MCS_0;
  4008. break;
  4009. case DESC_RATEVHTSS2MCS1:
  4010. btc_rate_id = BTC_VHT_2SS_MCS_1;
  4011. break;
  4012. case DESC_RATEVHTSS2MCS2:
  4013. btc_rate_id = BTC_VHT_2SS_MCS_2;
  4014. break;
  4015. case DESC_RATEVHTSS2MCS3:
  4016. btc_rate_id = BTC_VHT_2SS_MCS_3;
  4017. break;
  4018. case DESC_RATEVHTSS2MCS4:
  4019. btc_rate_id = BTC_VHT_2SS_MCS_4;
  4020. break;
  4021. case DESC_RATEVHTSS2MCS5:
  4022. btc_rate_id = BTC_VHT_2SS_MCS_5;
  4023. break;
  4024. case DESC_RATEVHTSS2MCS6:
  4025. btc_rate_id = BTC_VHT_2SS_MCS_6;
  4026. break;
  4027. case DESC_RATEVHTSS2MCS7:
  4028. btc_rate_id = BTC_VHT_2SS_MCS_7;
  4029. break;
  4030. case DESC_RATEVHTSS2MCS8:
  4031. btc_rate_id = BTC_VHT_2SS_MCS_8;
  4032. break;
  4033. case DESC_RATEVHTSS2MCS9:
  4034. btc_rate_id = BTC_VHT_2SS_MCS_9;
  4035. break;
  4036. case DESC_RATEVHTSS3MCS0:
  4037. btc_rate_id = BTC_VHT_3SS_MCS_0;
  4038. break;
  4039. case DESC_RATEVHTSS3MCS1:
  4040. btc_rate_id = BTC_VHT_3SS_MCS_1;
  4041. break;
  4042. case DESC_RATEVHTSS3MCS2:
  4043. btc_rate_id = BTC_VHT_3SS_MCS_2;
  4044. break;
  4045. case DESC_RATEVHTSS3MCS3:
  4046. btc_rate_id = BTC_VHT_3SS_MCS_3;
  4047. break;
  4048. case DESC_RATEVHTSS3MCS4:
  4049. btc_rate_id = BTC_VHT_3SS_MCS_4;
  4050. break;
  4051. case DESC_RATEVHTSS3MCS5:
  4052. btc_rate_id = BTC_VHT_3SS_MCS_5;
  4053. break;
  4054. case DESC_RATEVHTSS3MCS6:
  4055. btc_rate_id = BTC_VHT_3SS_MCS_6;
  4056. break;
  4057. case DESC_RATEVHTSS3MCS7:
  4058. btc_rate_id = BTC_VHT_3SS_MCS_7;
  4059. break;
  4060. case DESC_RATEVHTSS3MCS8:
  4061. btc_rate_id = BTC_VHT_3SS_MCS_8;
  4062. break;
  4063. case DESC_RATEVHTSS3MCS9:
  4064. btc_rate_id = BTC_VHT_3SS_MCS_9;
  4065. break;
  4066. case DESC_RATEVHTSS4MCS0:
  4067. btc_rate_id = BTC_VHT_4SS_MCS_0;
  4068. break;
  4069. case DESC_RATEVHTSS4MCS1:
  4070. btc_rate_id = BTC_VHT_4SS_MCS_1;
  4071. break;
  4072. case DESC_RATEVHTSS4MCS2:
  4073. btc_rate_id = BTC_VHT_4SS_MCS_2;
  4074. break;
  4075. case DESC_RATEVHTSS4MCS3:
  4076. btc_rate_id = BTC_VHT_4SS_MCS_3;
  4077. break;
  4078. case DESC_RATEVHTSS4MCS4:
  4079. btc_rate_id = BTC_VHT_4SS_MCS_4;
  4080. break;
  4081. case DESC_RATEVHTSS4MCS5:
  4082. btc_rate_id = BTC_VHT_4SS_MCS_5;
  4083. break;
  4084. case DESC_RATEVHTSS4MCS6:
  4085. btc_rate_id = BTC_VHT_4SS_MCS_6;
  4086. break;
  4087. case DESC_RATEVHTSS4MCS7:
  4088. btc_rate_id = BTC_VHT_4SS_MCS_7;
  4089. break;
  4090. case DESC_RATEVHTSS4MCS8:
  4091. btc_rate_id = BTC_VHT_4SS_MCS_8;
  4092. break;
  4093. case DESC_RATEVHTSS4MCS9:
  4094. btc_rate_id = BTC_VHT_4SS_MCS_9;
  4095. break;
  4096. }
  4097. return btc_rate_id;
  4098. }
  4099. static void halbt_init_hw_config92C(PADAPTER padapter)
  4100. {
  4101. PHAL_DATA_TYPE pHalData;
  4102. u8 u1Tmp;
  4103. pHalData = GET_HAL_DATA(padapter);
  4104. if ((pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
  4105. (pHalData->bt_coexist.btChipType == BT_CSR_BC8)) {
  4106. if (pHalData->rf_type == RF_1T1R) {
  4107. /* Config to 1T1R */
  4108. u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
  4109. u1Tmp &= ~BIT(1);
  4110. rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
  4111. RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
  4112. u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
  4113. u1Tmp &= ~BIT(1);
  4114. rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
  4115. RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
  4116. }
  4117. }
  4118. }
  4119. static void halbt_init_hw_config92D(PADAPTER padapter)
  4120. {
  4121. PHAL_DATA_TYPE pHalData;
  4122. u8 u1Tmp;
  4123. pHalData = GET_HAL_DATA(padapter);
  4124. if ((pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
  4125. (pHalData->bt_coexist.btChipType == BT_CSR_BC8)) {
  4126. if (pHalData->rf_type == RF_1T1R) {
  4127. /* Config to 1T1R */
  4128. u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
  4129. u1Tmp &= ~BIT(1);
  4130. rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
  4131. RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
  4132. u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
  4133. u1Tmp &= ~BIT(1);
  4134. rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
  4135. RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
  4136. }
  4137. }
  4138. }
  4139. /*
  4140. * Description:
  4141. * Run BT-Coexist mechansim or not
  4142. *
  4143. */
  4144. void hal_btcoex_SetBTCoexist(PADAPTER padapter, u8 bBtExist)
  4145. {
  4146. PHAL_DATA_TYPE pHalData;
  4147. pHalData = GET_HAL_DATA(padapter);
  4148. pHalData->bt_coexist.bBtExist = bBtExist;
  4149. }
  4150. /*
  4151. * Dewcription:
  4152. * Check is co-exist mechanism enabled or not
  4153. *
  4154. * Return:
  4155. * _TRUE Enable BT co-exist mechanism
  4156. * _FALSE Disable BT co-exist mechanism
  4157. */
  4158. u8 hal_btcoex_IsBtExist(PADAPTER padapter)
  4159. {
  4160. PHAL_DATA_TYPE pHalData;
  4161. pHalData = GET_HAL_DATA(padapter);
  4162. return pHalData->bt_coexist.bBtExist;
  4163. }
  4164. u8 hal_btcoex_IsBtDisabled(PADAPTER padapter)
  4165. {
  4166. if (!hal_btcoex_IsBtExist(padapter))
  4167. return _TRUE;
  4168. if (GLBtCoexist.bt_info.bt_disabled)
  4169. return _TRUE;
  4170. else
  4171. return _FALSE;
  4172. }
  4173. void hal_btcoex_SetChipType(PADAPTER padapter, u8 chipType)
  4174. {
  4175. PHAL_DATA_TYPE pHalData;
  4176. pHalData = GET_HAL_DATA(padapter);
  4177. pHalData->bt_coexist.btChipType = chipType;
  4178. }
  4179. void hal_btcoex_SetPgAntNum(PADAPTER padapter, u8 antNum)
  4180. {
  4181. PHAL_DATA_TYPE pHalData;
  4182. pHalData = GET_HAL_DATA(padapter);
  4183. pHalData->bt_coexist.btTotalAntNum = antNum;
  4184. }
  4185. u8 hal_btcoex_Initialize(PADAPTER padapter)
  4186. {
  4187. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  4188. u8 ret;
  4189. _rtw_memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
  4190. ret = EXhalbtcoutsrc_InitlizeVariables((void *)padapter);
  4191. return ret;
  4192. }
  4193. void hal_btcoex_PowerOnSetting(PADAPTER padapter)
  4194. {
  4195. EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
  4196. }
  4197. void hal_btcoex_AntInfoSetting(PADAPTER padapter)
  4198. {
  4199. hal_btcoex_SetBTCoexist(padapter, rtw_btcoex_get_bt_coexist(padapter));
  4200. hal_btcoex_SetChipType(padapter, rtw_btcoex_get_chip_type(padapter));
  4201. hal_btcoex_SetPgAntNum(padapter, rtw_btcoex_get_pg_ant_num(padapter));
  4202. EXhalbtcoutsrc_AntInfoSetting(padapter);
  4203. }
  4204. void hal_btcoex_PowerOffSetting(PADAPTER padapter)
  4205. {
  4206. /* Clear the WiFi on/off bit in scoreboard reg. if necessary */
  4207. if (IS_HARDWARE_TYPE_8703B(padapter) || IS_HARDWARE_TYPE_8723D(padapter)
  4208. || IS_HARDWARE_TYPE_8821C(padapter) || IS_HARDWARE_TYPE_8822B(padapter))
  4209. rtw_write16(padapter, 0xaa, 0x8000);
  4210. }
  4211. void hal_btcoex_PreLoadFirmware(PADAPTER padapter)
  4212. {
  4213. EXhalbtcoutsrc_PreLoadFirmware(&GLBtCoexist);
  4214. }
  4215. void hal_btcoex_InitHwConfig(PADAPTER padapter, u8 bWifiOnly)
  4216. {
  4217. if (!hal_btcoex_IsBtExist(padapter))
  4218. return;
  4219. EXhalbtcoutsrc_init_hw_config(&GLBtCoexist, bWifiOnly);
  4220. EXhalbtcoutsrc_init_coex_dm(&GLBtCoexist);
  4221. }
  4222. void hal_btcoex_IpsNotify(PADAPTER padapter, u8 type)
  4223. {
  4224. EXhalbtcoutsrc_ips_notify(&GLBtCoexist, type);
  4225. }
  4226. void hal_btcoex_LpsNotify(PADAPTER padapter, u8 type)
  4227. {
  4228. EXhalbtcoutsrc_lps_notify(&GLBtCoexist, type);
  4229. }
  4230. void hal_btcoex_ScanNotify(PADAPTER padapter, u8 type)
  4231. {
  4232. EXhalbtcoutsrc_scan_notify(&GLBtCoexist, type);
  4233. }
  4234. void hal_btcoex_ConnectNotify(PADAPTER padapter, u8 action)
  4235. {
  4236. u8 assoType = 0;
  4237. u8 is_5g_band = _FALSE;
  4238. is_5g_band = (padapter->mlmeextpriv.cur_channel > 14) ? _TRUE : _FALSE;
  4239. if (action == _TRUE) {
  4240. if (is_5g_band == _TRUE)
  4241. assoType = BTC_ASSOCIATE_5G_START;
  4242. else
  4243. assoType = BTC_ASSOCIATE_START;
  4244. }
  4245. else {
  4246. if (is_5g_band == _TRUE)
  4247. assoType = BTC_ASSOCIATE_5G_FINISH;
  4248. else
  4249. assoType = BTC_ASSOCIATE_FINISH;
  4250. }
  4251. EXhalbtcoutsrc_connect_notify(&GLBtCoexist, assoType);
  4252. }
  4253. void hal_btcoex_MediaStatusNotify(PADAPTER padapter, u8 mediaStatus)
  4254. {
  4255. EXhalbtcoutsrc_media_status_notify(&GLBtCoexist, mediaStatus);
  4256. }
  4257. void hal_btcoex_SpecialPacketNotify(PADAPTER padapter, u8 pktType)
  4258. {
  4259. EXhalbtcoutsrc_specific_packet_notify(&GLBtCoexist, pktType);
  4260. }
  4261. void hal_btcoex_IQKNotify(PADAPTER padapter, u8 state)
  4262. {
  4263. GLBtcWiFiInIQKState = state;
  4264. }
  4265. void hal_btcoex_BtInfoNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
  4266. {
  4267. if (GLBtcWiFiInIQKState == _TRUE)
  4268. return;
  4269. EXhalbtcoutsrc_bt_info_notify(&GLBtCoexist, tmpBuf, length);
  4270. }
  4271. void hal_btcoex_BtMpRptNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
  4272. {
  4273. u8 extid, status, len, seq;
  4274. if (GLBtcBtMpRptWait == _FALSE)
  4275. return;
  4276. if ((length < 3) || (!tmpBuf))
  4277. return;
  4278. extid = tmpBuf[0];
  4279. /* not response from BT FW then exit*/
  4280. switch (extid) {
  4281. case C2H_WIFI_FW_ACTIVE_RSP:
  4282. GLBtcBtMpRptWiFiOK = _TRUE;
  4283. break;
  4284. case C2H_TRIG_BY_BT_FW:
  4285. GLBtcBtMpRptBTOK = _TRUE;
  4286. status = tmpBuf[1] & 0xF;
  4287. len = length - 3;
  4288. seq = tmpBuf[2] >> 4;
  4289. GLBtcBtMpRptSeq = seq;
  4290. GLBtcBtMpRptStatus = status;
  4291. _rtw_memcpy(GLBtcBtMpRptRsp, tmpBuf + 3, len);
  4292. GLBtcBtMpRptRspSize = len;
  4293. break;
  4294. default:
  4295. return;
  4296. }
  4297. if ((GLBtcBtMpRptWiFiOK == _TRUE) && (GLBtcBtMpRptBTOK == _TRUE)) {
  4298. GLBtcBtMpRptWait = _FALSE;
  4299. _cancel_timer_ex(&GLBtcBtMpOperTimer);
  4300. _rtw_up_sema(&GLBtcBtMpRptSema);
  4301. }
  4302. }
  4303. void hal_btcoex_SuspendNotify(PADAPTER padapter, u8 state)
  4304. {
  4305. switch (state) {
  4306. case BTCOEX_SUSPEND_STATE_SUSPEND:
  4307. EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP);
  4308. break;
  4309. case BTCOEX_SUSPEND_STATE_SUSPEND_KEEP_ANT:
  4310. /* should switch to "#if 1" once all ICs' coex. revision are upgraded to support the KEEP_ANT case */
  4311. #if 0
  4312. EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP_KEEP_ANT);
  4313. #else
  4314. EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP);
  4315. EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP_KEEP_ANT);
  4316. #endif
  4317. break;
  4318. case BTCOEX_SUSPEND_STATE_RESUME:
  4319. #ifdef CONFIG_FW_MULTI_PORT_SUPPORT
  4320. /* re-download FW after resume, inform WL FW port number */
  4321. rtw_hal_set_wifi_btc_port_id_cmd(GLBtCoexist.Adapter);
  4322. #endif
  4323. EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_WAKE_UP);
  4324. break;
  4325. }
  4326. }
  4327. void hal_btcoex_HaltNotify(PADAPTER padapter, u8 do_halt)
  4328. {
  4329. if (do_halt == 1)
  4330. EXhalbtcoutsrc_halt_notify(&GLBtCoexist);
  4331. GLBtCoexist.bBinded = _FALSE;
  4332. GLBtCoexist.Adapter = NULL;
  4333. }
  4334. void hal_btcoex_SwitchBtTRxMask(PADAPTER padapter)
  4335. {
  4336. EXhalbtcoutsrc_SwitchBtTRxMask(&GLBtCoexist);
  4337. }
  4338. void hal_btcoex_Hanlder(PADAPTER padapter)
  4339. {
  4340. u32 bt_patch_ver;
  4341. EXhalbtcoutsrc_periodical(&GLBtCoexist);
  4342. if (GLBtCoexist.bt_info.bt_get_fw_ver == 0) {
  4343. GLBtCoexist.btc_get(&GLBtCoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
  4344. GLBtCoexist.bt_info.bt_get_fw_ver = bt_patch_ver;
  4345. }
  4346. }
  4347. s32 hal_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter)
  4348. {
  4349. return (s32)GLBtCoexist.bt_info.reject_agg_pkt;
  4350. }
  4351. s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)
  4352. {
  4353. return (s32)GLBtCoexist.bt_info.bt_ctrl_agg_buf_size;
  4354. }
  4355. u32 hal_btcoex_GetAMPDUSize(PADAPTER padapter)
  4356. {
  4357. return (u32)GLBtCoexist.bt_info.agg_buf_size;
  4358. }
  4359. void hal_btcoex_SetManualControl(PADAPTER padapter, u8 bmanual)
  4360. {
  4361. GLBtCoexist.manual_control = bmanual;
  4362. }
  4363. u8 hal_btcoex_1Ant(PADAPTER padapter)
  4364. {
  4365. if (hal_btcoex_IsBtExist(padapter) == _FALSE)
  4366. return _FALSE;
  4367. if (GLBtCoexist.board_info.btdm_ant_num == 1)
  4368. return _TRUE;
  4369. return _FALSE;
  4370. }
  4371. u8 hal_btcoex_IsBtControlLps(PADAPTER padapter)
  4372. {
  4373. if (GLBtCoexist.bdontenterLPS == _TRUE)
  4374. return _TRUE;
  4375. if (hal_btcoex_IsBtExist(padapter) == _FALSE)
  4376. return _FALSE;
  4377. if (GLBtCoexist.bt_info.bt_disabled)
  4378. return _FALSE;
  4379. if (GLBtCoexist.bt_info.bt_ctrl_lps)
  4380. return _TRUE;
  4381. return _FALSE;
  4382. }
  4383. u8 hal_btcoex_IsLpsOn(PADAPTER padapter)
  4384. {
  4385. if (GLBtCoexist.bdontenterLPS == _TRUE)
  4386. return _FALSE;
  4387. if (hal_btcoex_IsBtExist(padapter) == _FALSE)
  4388. return _FALSE;
  4389. if (GLBtCoexist.bt_info.bt_disabled)
  4390. return _FALSE;
  4391. if (GLBtCoexist.bt_info.bt_lps_on)
  4392. return _TRUE;
  4393. return _FALSE;
  4394. }
  4395. u8 hal_btcoex_RpwmVal(PADAPTER padapter)
  4396. {
  4397. return GLBtCoexist.bt_info.rpwm_val;
  4398. }
  4399. u8 hal_btcoex_LpsVal(PADAPTER padapter)
  4400. {
  4401. return GLBtCoexist.bt_info.lps_val;
  4402. }
  4403. u32 hal_btcoex_GetRaMask(PADAPTER padapter)
  4404. {
  4405. if (!hal_btcoex_IsBtExist(padapter))
  4406. return 0;
  4407. if (GLBtCoexist.bt_info.bt_disabled)
  4408. return 0;
  4409. /* Modify by YiWei , suggest by Cosa and Jenyu
  4410. * Remove the limit antenna number , because 2 antenna case (ex: 8192eu)also want to get BT coex report rate mask.
  4411. */
  4412. /*if (GLBtCoexist.board_info.btdm_ant_num != 1)
  4413. return 0;*/
  4414. return GLBtCoexist.bt_info.ra_mask;
  4415. }
  4416. void hal_btcoex_RecordPwrMode(PADAPTER padapter, u8 *pCmdBuf, u8 cmdLen)
  4417. {
  4418. _rtw_memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
  4419. }
  4420. void hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter, u8 *pbuf, u32 bufsize)
  4421. {
  4422. PBTCDBGINFO pinfo;
  4423. pinfo = &GLBtcDbgInfo;
  4424. DBG_BT_INFO_INIT(pinfo, pbuf, bufsize);
  4425. EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist);
  4426. DBG_BT_INFO_INIT(pinfo, NULL, 0);
  4427. }
  4428. void hal_btcoex_SetDBG(PADAPTER padapter, u32 *pDbgModule)
  4429. {
  4430. u32 i;
  4431. if (NULL == pDbgModule)
  4432. return;
  4433. for (i = 0; i < COMP_MAX; i++)
  4434. GLBtcDbgType[i] = pDbgModule[i];
  4435. }
  4436. u32 hal_btcoex_GetDBG(PADAPTER padapter, u8 *pStrBuf, u32 bufSize)
  4437. {
  4438. s32 count;
  4439. u8 *pstr;
  4440. u32 leftSize;
  4441. if ((NULL == pStrBuf) || (0 == bufSize))
  4442. return 0;
  4443. count = 0;
  4444. pstr = pStrBuf;
  4445. leftSize = bufSize;
  4446. /* RTW_INFO(FUNC_ADPT_FMT ": bufsize=%d\n", FUNC_ADPT_ARG(padapter), bufSize); */
  4447. count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG);
  4448. if ((count < 0) || (count >= leftSize))
  4449. goto exit;
  4450. pstr += count;
  4451. leftSize -= count;
  4452. count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n");
  4453. if ((count < 0) || (count >= leftSize))
  4454. goto exit;
  4455. pstr += count;
  4456. leftSize -= count;
  4457. count = rtw_sprintf(pstr, leftSize,
  4458. "COMP_COEX: 0x%08X\n\n",
  4459. GLBtcDbgType[COMP_COEX]);
  4460. if ((count < 0) || (count >= leftSize))
  4461. goto exit;
  4462. pstr += count;
  4463. leftSize -= count;
  4464. #if 0
  4465. count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n");
  4466. if ((count < 0) || (count >= leftSize))
  4467. goto exit;
  4468. pstr += count;
  4469. leftSize -= count;
  4470. count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for INTF_INIT\n",
  4471. GLBtcDbgType[BTC_MSG_INTERFACE] & INTF_INIT ? 1 : 0);
  4472. if ((count < 0) || (count >= leftSize))
  4473. goto exit;
  4474. pstr += count;
  4475. leftSize -= count;
  4476. count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for INTF_NOTIFY\n\n",
  4477. GLBtcDbgType[BTC_MSG_INTERFACE] & INTF_NOTIFY ? 1 : 0);
  4478. if ((count < 0) || (count >= leftSize))
  4479. goto exit;
  4480. pstr += count;
  4481. leftSize -= count;
  4482. count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n");
  4483. if ((count < 0) || (count >= leftSize))
  4484. goto exit;
  4485. pstr += count;
  4486. leftSize -= count;
  4487. count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for BT_RSSI_STATE\n",
  4488. GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_BT_RSSI_STATE ? 1 : 0);
  4489. if ((count < 0) || (count >= leftSize))
  4490. goto exit;
  4491. pstr += count;
  4492. leftSize -= count;
  4493. count = rtw_sprintf(pstr, leftSize, "\tbit[1]=%d for WIFI_RSSI_STATE\n",
  4494. GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_WIFI_RSSI_STATE ? 1 : 0);
  4495. if ((count < 0) || (count >= leftSize))
  4496. goto exit;
  4497. pstr += count;
  4498. leftSize -= count;
  4499. count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for BT_MONITOR\n",
  4500. GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_BT_MONITOR ? 1 : 0);
  4501. if ((count < 0) || (count >= leftSize))
  4502. goto exit;
  4503. pstr += count;
  4504. leftSize -= count;
  4505. count = rtw_sprintf(pstr, leftSize, "\tbit[3]=%d for TRACE\n",
  4506. GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE ? 1 : 0);
  4507. if ((count < 0) || (count >= leftSize))
  4508. goto exit;
  4509. pstr += count;
  4510. leftSize -= count;
  4511. count = rtw_sprintf(pstr, leftSize, "\tbit[4]=%d for TRACE_FW\n",
  4512. GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW ? 1 : 0);
  4513. if ((count < 0) || (count >= leftSize))
  4514. goto exit;
  4515. pstr += count;
  4516. leftSize -= count;
  4517. count = rtw_sprintf(pstr, leftSize, "\tbit[5]=%d for TRACE_FW_DETAIL\n",
  4518. GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW_DETAIL ? 1 : 0);
  4519. if ((count < 0) || (count >= leftSize))
  4520. goto exit;
  4521. pstr += count;
  4522. leftSize -= count;
  4523. count = rtw_sprintf(pstr, leftSize, "\tbit[6]=%d for TRACE_FW_EXEC\n",
  4524. GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW_EXEC ? 1 : 0);
  4525. if ((count < 0) || (count >= leftSize))
  4526. goto exit;
  4527. pstr += count;
  4528. leftSize -= count;
  4529. count = rtw_sprintf(pstr, leftSize, "\tbit[7]=%d for TRACE_SW\n",
  4530. GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW ? 1 : 0);
  4531. if ((count < 0) || (count >= leftSize))
  4532. goto exit;
  4533. pstr += count;
  4534. leftSize -= count;
  4535. count = rtw_sprintf(pstr, leftSize, "\tbit[8]=%d for TRACE_SW_DETAIL\n",
  4536. GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW_DETAIL ? 1 : 0);
  4537. if ((count < 0) || (count >= leftSize))
  4538. goto exit;
  4539. pstr += count;
  4540. leftSize -= count;
  4541. count = rtw_sprintf(pstr, leftSize, "\tbit[9]=%d for TRACE_SW_EXEC\n",
  4542. GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW_EXEC ? 1 : 0);
  4543. if ((count < 0) || (count >= leftSize))
  4544. goto exit;
  4545. pstr += count;
  4546. leftSize -= count;
  4547. #endif
  4548. exit:
  4549. count = pstr - pStrBuf;
  4550. /* RTW_INFO(FUNC_ADPT_FMT ": usedsize=%d\n", FUNC_ADPT_ARG(padapter), count); */
  4551. return count;
  4552. }
  4553. u8 hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)
  4554. {
  4555. if (!hal_btcoex_IsBtExist(padapter))
  4556. return _FALSE;
  4557. if (GLBtCoexist.bt_info.increase_scan_dev_num)
  4558. return _TRUE;
  4559. return _FALSE;
  4560. }
  4561. u8 hal_btcoex_IsBtLinkExist(PADAPTER padapter)
  4562. {
  4563. if (GLBtCoexist.bt_link_info.bt_link_exist)
  4564. return _TRUE;
  4565. return _FALSE;
  4566. }
  4567. void hal_btcoex_SetBtPatchVersion(PADAPTER padapter, u16 btHciVer, u16 btPatchVer)
  4568. {
  4569. EXhalbtcoutsrc_SetBtPatchVersion(btHciVer, btPatchVer);
  4570. }
  4571. void hal_btcoex_SetHciVersion(PADAPTER padapter, u16 hciVersion)
  4572. {
  4573. EXhalbtcoutsrc_SetHciVersion(hciVersion);
  4574. }
  4575. void hal_btcoex_StackUpdateProfileInfo(void)
  4576. {
  4577. EXhalbtcoutsrc_StackUpdateProfileInfo();
  4578. }
  4579. void hal_btcoex_pta_off_on_notify(PADAPTER padapter, u8 bBTON)
  4580. {
  4581. ex_halbtcoutsrc_pta_off_on_notify(&GLBtCoexist, bBTON);
  4582. }
  4583. /*
  4584. * Description:
  4585. * Setting BT coex antenna isolation type .
  4586. * coex mechanisn/ spital stream/ best throughput
  4587. * anttype = 0 , PSTDMA / 2SS / 0.5T , bad isolation , WiFi/BT ANT Distance<15cm , (<20dB) for 2,3 antenna
  4588. * anttype = 1 , PSTDMA / 1SS / 0.5T , normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 2 antenna
  4589. * anttype = 2 , TDMA / 2SS / T , normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 3 antenna
  4590. * anttype = 3 , no TDMA / 1SS / 0.5T , good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 2 antenna
  4591. * anttype = 4 , no TDMA / 2SS / T , good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 3 antenna
  4592. * wifi only throughput ~ T
  4593. * wifi/BT share one antenna with SPDT
  4594. */
  4595. void hal_btcoex_SetAntIsolationType(PADAPTER padapter, u8 anttype)
  4596. {
  4597. PHAL_DATA_TYPE pHalData;
  4598. PBTC_COEXIST pBtCoexist = &GLBtCoexist;
  4599. /*RTW_INFO("####%s , anttype = %d , %d\n" , __func__ , anttype , __LINE__); */
  4600. pHalData = GET_HAL_DATA(padapter);
  4601. pHalData->bt_coexist.btAntisolation = anttype;
  4602. switch (pHalData->bt_coexist.btAntisolation) {
  4603. case 0:
  4604. pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_0;
  4605. break;
  4606. case 1:
  4607. pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_1;
  4608. break;
  4609. case 2:
  4610. pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_2;
  4611. break;
  4612. case 3:
  4613. pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_3;
  4614. break;
  4615. case 4:
  4616. pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_4;
  4617. break;
  4618. }
  4619. }
  4620. #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
  4621. int
  4622. hal_btcoex_ParseAntIsolationConfigFile(
  4623. PADAPTER Adapter,
  4624. char *buffer
  4625. )
  4626. {
  4627. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  4628. u32 i = 0 , j = 0;
  4629. char *szLine , *ptmp;
  4630. int rtStatus = _SUCCESS;
  4631. char param_value_string[10];
  4632. u8 param_value;
  4633. u8 anttype = 4;
  4634. u8 ant_num = 3 , ant_distance = 50 , rfe_type = 1;
  4635. typedef struct ant_isolation {
  4636. char *param_name; /* antenna isolation config parameter name */
  4637. u8 *value; /* antenna isolation config parameter value */
  4638. } ANT_ISOLATION;
  4639. ANT_ISOLATION ant_isolation_param[] = {
  4640. {"ANT_NUMBER" , &ant_num},
  4641. {"ANT_DISTANCE" , &ant_distance},
  4642. {"RFE_TYPE" , &rfe_type},
  4643. {NULL , 0}
  4644. };
  4645. /* RTW_INFO("===>Hal_ParseAntIsolationConfigFile()\n" ); */
  4646. ptmp = buffer;
  4647. for (szLine = GetLineFromBuffer(ptmp) ; szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
  4648. /* skip comment */
  4649. if (IsCommentString(szLine))
  4650. continue;
  4651. /* RTW_INFO("%s : szLine = %s , strlen(szLine) = %d\n" , __func__ , szLine , strlen(szLine));*/
  4652. for (j = 0 ; ant_isolation_param[j].param_name != NULL ; j++) {
  4653. if (strstr(szLine , ant_isolation_param[j].param_name) != NULL) {
  4654. i = 0;
  4655. while (i < strlen(szLine)) {
  4656. if (szLine[i] != '"')
  4657. ++i;
  4658. else {
  4659. /* skip only has one " */
  4660. if (strpbrk(szLine , "\"") == strrchr(szLine , '"')) {
  4661. RTW_INFO("Fail to parse parameters , format error!\n");
  4662. break;
  4663. }
  4664. _rtw_memset((PVOID)param_value_string , 0 , 10);
  4665. if (!ParseQualifiedString(szLine , &i , param_value_string , '"' , '"')) {
  4666. RTW_INFO("Fail to parse parameters\n");
  4667. return _FAIL;
  4668. } else if (!GetU1ByteIntegerFromStringInDecimal(param_value_string , ant_isolation_param[j].value))
  4669. RTW_INFO("Fail to GetU1ByteIntegerFromStringInDecimal\n");
  4670. break;
  4671. }
  4672. }
  4673. }
  4674. }
  4675. }
  4676. /* YiWei 20140716 , for BT coex antenna isolation control */
  4677. /* rfe_type = 0 was SPDT , rfe_type = 1 was coupler */
  4678. if (ant_num == 3 && ant_distance >= 50)
  4679. anttype = 3;
  4680. else if (ant_num == 2 && ant_distance >= 50 && rfe_type == 1)
  4681. anttype = 2;
  4682. else if (ant_num == 3 && ant_distance >= 15 && ant_distance < 50)
  4683. anttype = 2;
  4684. else if (ant_num == 2 && ant_distance >= 15 && ant_distance < 50 && rfe_type == 1)
  4685. anttype = 2;
  4686. else if ((ant_num == 2 && ant_distance < 15 && rfe_type == 1) || (ant_num == 3 && ant_distance < 15))
  4687. anttype = 1;
  4688. else if (ant_num == 2 && rfe_type == 0)
  4689. anttype = 0;
  4690. else
  4691. anttype = 0;
  4692. hal_btcoex_SetAntIsolationType(Adapter, anttype);
  4693. RTW_INFO("%s : ant_num = %d\n" , __func__ , ant_num);
  4694. RTW_INFO("%s : ant_distance = %d\n" , __func__ , ant_distance);
  4695. RTW_INFO("%s : rfe_type = %d\n" , __func__ , rfe_type);
  4696. /* RTW_INFO("<===Hal_ParseAntIsolationConfigFile()\n"); */
  4697. return rtStatus;
  4698. }
  4699. int
  4700. hal_btcoex_AntIsolationConfig_ParaFile(
  4701. IN PADAPTER Adapter,
  4702. IN char *pFileName
  4703. )
  4704. {
  4705. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  4706. int rlen = 0 , rtStatus = _FAIL;
  4707. _rtw_memset(pHalData->para_file_buf , 0 , MAX_PARA_FILE_BUF_LEN);
  4708. rtw_get_phy_file_path(Adapter, pFileName);
  4709. if (rtw_is_file_readable(rtw_phy_para_file_path) == _TRUE) {
  4710. rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
  4711. if (rlen > 0)
  4712. rtStatus = _SUCCESS;
  4713. }
  4714. if (rtStatus == _SUCCESS) {
  4715. /*RTW_INFO("%s(): read %s ok\n", __func__ , pFileName);*/
  4716. rtStatus = hal_btcoex_ParseAntIsolationConfigFile(Adapter , pHalData->para_file_buf);
  4717. } else
  4718. RTW_INFO("%s(): No File %s, Load from *** Array!\n" , __func__ , pFileName);
  4719. return rtStatus;
  4720. }
  4721. #endif /* CONFIG_LOAD_PHY_PARA_FROM_FILE */
  4722. u16 hal_btcoex_btreg_read(PADAPTER padapter, u8 type, u16 addr, u32 *data)
  4723. {
  4724. u16 ret = 0;
  4725. halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
  4726. ret = halbtcoutsrc_GetBtReg_with_status(&GLBtCoexist, type, addr, data);
  4727. halbtcoutsrc_NormalLowPower(&GLBtCoexist);
  4728. return ret;
  4729. }
  4730. u16 hal_btcoex_btreg_write(PADAPTER padapter, u8 type, u16 addr, u16 val)
  4731. {
  4732. u16 ret = 0;
  4733. halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
  4734. ret = halbtcoutsrc_SetBtReg(&GLBtCoexist, type, addr, val);
  4735. halbtcoutsrc_NormalLowPower(&GLBtCoexist);
  4736. return ret;
  4737. }
  4738. void hal_btcoex_set_rfe_type(u8 type)
  4739. {
  4740. EXhalbtcoutsrc_set_rfe_type(type);
  4741. }
  4742. #ifdef CONFIG_RF4CE_COEXIST
  4743. void hal_btcoex_set_rf4ce_link_state(u8 state)
  4744. {
  4745. EXhalbtcoutsrc_set_rf4ce_link_state(state);
  4746. }
  4747. u8 hal_btcoex_get_rf4ce_link_state(void)
  4748. {
  4749. return EXhalbtcoutsrc_get_rf4ce_link_state();
  4750. }
  4751. #endif /* CONFIG_RF4CE_COEXIST */
  4752. void hal_btcoex_switchband_notify(u8 under_scan, u8 band_type)
  4753. {
  4754. switch (band_type) {
  4755. case BAND_ON_2_4G:
  4756. if (under_scan)
  4757. EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_24G);
  4758. else
  4759. EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_24G_NOFORSCAN);
  4760. break;
  4761. case BAND_ON_5G:
  4762. EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_5G);
  4763. break;
  4764. default:
  4765. RTW_INFO("[BTCOEX] unkown switch band type\n");
  4766. break;
  4767. }
  4768. }
  4769. void hal_btcoex_WlFwDbgInfoNotify(PADAPTER padapter, u8* tmpBuf, u8 length)
  4770. {
  4771. EXhalbtcoutsrc_WlFwDbgInfoNotify(&GLBtCoexist, tmpBuf, length);
  4772. }
  4773. void hal_btcoex_rx_rate_change_notify(PADAPTER padapter, u8 is_data_frame, u8 rate_id)
  4774. {
  4775. EXhalbtcoutsrc_rx_rate_change_notify(&GLBtCoexist, is_data_frame, EXhalbtcoutsrc_rate_id_to_btc_rate_id(rate_id));
  4776. }
  4777. #endif /* CONFIG_BT_COEXIST */