hal_halmac.c 129 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2015 - 2019 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_HALMAC_C_
  16. #include <drv_types.h> /* PADAPTER, struct dvobj_priv, SDIO_ERR_VAL8 and etc. */
  17. #include <hal_data.h> /* efuse, PHAL_DATA_TYPE and etc. */
  18. #include "hal_halmac.h" /* dvobj_to_halmac() and ect. */
  19. /*
  20. * HALMAC take return value 0 for fail and 1 for success to replace
  21. * _FALSE/_TRUE after V1_04_09
  22. */
  23. #define RTW_HALMAC_FAIL 0
  24. #define RTW_HALMAC_SUCCESS 1
  25. #define DEFAULT_INDICATOR_TIMELMT 1000 /* ms */
  26. #define MSG_PREFIX "[HALMAC]"
  27. #define RTW_HALMAC_DLFW_MEM_NO_STOP_TX
  28. /*
  29. * Driver API for HALMAC operations
  30. */
  31. #ifdef CONFIG_SDIO_HCI
  32. #include <rtw_sdio.h>
  33. static u8 _halmac_mac_reg_page0_chk(const char *func, struct dvobj_priv *dvobj, u32 offset)
  34. {
  35. #if defined(CONFIG_IO_CHECK_IN_ANA_LOW_CLK) && defined(CONFIG_LPS_LCLK)
  36. struct pwrctrl_priv *pwrpriv = &dvobj->pwrctl_priv;
  37. u32 mac_reg_offset = 0;
  38. if (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
  39. return _TRUE;
  40. if (pwrpriv->lps_level == LPS_NORMAL)
  41. return _TRUE;
  42. if (pwrpriv->rpwm >= PS_STATE_S2)
  43. return _TRUE;
  44. if (offset & (WLAN_IOREG_DEVICE_ID << 13)) { /*WLAN_IOREG_OFFSET*/
  45. mac_reg_offset = offset & HALMAC_WLAN_MAC_REG_MSK;
  46. if (mac_reg_offset < 0x100) {
  47. RTW_ERR(FUNC_ADPT_FMT
  48. "access MAC REG -0x%04x in PS-mode:0x%02x (rpwm:0x%02x, lps_level:0x%02x)\n",
  49. FUNC_ADPT_ARG(dvobj_get_primary_adapter(dvobj)), mac_reg_offset,
  50. pwrpriv->pwr_mode, pwrpriv->rpwm, pwrpriv->lps_level);
  51. rtw_warn_on(1);
  52. return _FALSE;
  53. }
  54. }
  55. #endif
  56. return _TRUE;
  57. }
  58. static u8 _halmac_sdio_cmd52_read(void *p, u32 offset)
  59. {
  60. struct dvobj_priv *d;
  61. u8 val;
  62. u8 ret;
  63. d = (struct dvobj_priv *)p;
  64. _halmac_mac_reg_page0_chk(__func__, d, offset);
  65. ret = rtw_sdio_read_cmd52(d, offset, &val, 1);
  66. if (_FAIL == ret) {
  67. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  68. return SDIO_ERR_VAL8;
  69. }
  70. return val;
  71. }
  72. static void _halmac_sdio_cmd52_write(void *p, u32 offset, u8 val)
  73. {
  74. struct dvobj_priv *d;
  75. u8 ret;
  76. d = (struct dvobj_priv *)p;
  77. _halmac_mac_reg_page0_chk(__func__, d, offset);
  78. ret = rtw_sdio_write_cmd52(d, offset, &val, 1);
  79. if (_FAIL == ret)
  80. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  81. }
  82. static u8 _halmac_sdio_reg_read_8(void *p, u32 offset)
  83. {
  84. struct dvobj_priv *d;
  85. u8 *pbuf;
  86. u8 val;
  87. u8 ret;
  88. d = (struct dvobj_priv *)p;
  89. val = SDIO_ERR_VAL8;
  90. _halmac_mac_reg_page0_chk(__func__, d, offset);
  91. pbuf = rtw_zmalloc(1);
  92. if (!pbuf)
  93. return val;
  94. ret = rtw_sdio_read_cmd53(d, offset, pbuf, 1);
  95. if (ret == _FAIL) {
  96. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  97. goto exit;
  98. }
  99. val = *pbuf;
  100. exit:
  101. rtw_mfree(pbuf, 1);
  102. return val;
  103. }
  104. static u16 _halmac_sdio_reg_read_16(void *p, u32 offset)
  105. {
  106. struct dvobj_priv *d;
  107. u8 *pbuf;
  108. u16 val;
  109. u8 ret;
  110. d = (struct dvobj_priv *)p;
  111. val = SDIO_ERR_VAL16;
  112. _halmac_mac_reg_page0_chk(__func__, d, offset);
  113. pbuf = rtw_zmalloc(2);
  114. if (!pbuf)
  115. return val;
  116. ret = rtw_sdio_read_cmd53(d, offset, pbuf, 2);
  117. if (ret == _FAIL) {
  118. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  119. goto exit;
  120. }
  121. val = le16_to_cpu(*(u16 *)pbuf);
  122. exit:
  123. rtw_mfree(pbuf, 2);
  124. return val;
  125. }
  126. static u32 _halmac_sdio_reg_read_32(void *p, u32 offset)
  127. {
  128. struct dvobj_priv *d;
  129. u8 *pbuf;
  130. u32 val;
  131. u8 ret;
  132. d = (struct dvobj_priv *)p;
  133. val = SDIO_ERR_VAL32;
  134. _halmac_mac_reg_page0_chk(__func__, d, offset);
  135. pbuf = rtw_zmalloc(4);
  136. if (!pbuf)
  137. return val;
  138. ret = rtw_sdio_read_cmd53(d, offset, pbuf, 4);
  139. if (ret == _FAIL) {
  140. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  141. goto exit;
  142. }
  143. val = le32_to_cpu(*(u32 *)pbuf);
  144. exit:
  145. rtw_mfree(pbuf, 4);
  146. return val;
  147. }
  148. static u8 _halmac_sdio_reg_read_n(void *p, u32 offset, u32 size, u8 *data)
  149. {
  150. struct dvobj_priv *d = (struct dvobj_priv *)p;
  151. u8 *pbuf;
  152. u8 ret;
  153. u8 rst = RTW_HALMAC_FAIL;
  154. u32 sdio_read_size;
  155. if (!data)
  156. return rst;
  157. sdio_read_size = RND4(size);
  158. sdio_read_size = rtw_sdio_cmd53_align_size(d, sdio_read_size);
  159. pbuf = rtw_zmalloc(sdio_read_size);
  160. if (!pbuf)
  161. return rst;
  162. ret = rtw_sdio_read_cmd53(d, offset, pbuf, sdio_read_size);
  163. if (ret == _FAIL) {
  164. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  165. goto exit;
  166. }
  167. _rtw_memcpy(data, pbuf, size);
  168. rst = RTW_HALMAC_SUCCESS;
  169. exit:
  170. rtw_mfree(pbuf, sdio_read_size);
  171. return rst;
  172. }
  173. static void _halmac_sdio_reg_write_8(void *p, u32 offset, u8 val)
  174. {
  175. struct dvobj_priv *d;
  176. u8 *pbuf;
  177. u8 ret;
  178. d = (struct dvobj_priv *)p;
  179. _halmac_mac_reg_page0_chk(__func__, d, offset);
  180. pbuf = rtw_zmalloc(1);
  181. if (!pbuf)
  182. return;
  183. _rtw_memcpy(pbuf, &val, 1);
  184. ret = rtw_sdio_write_cmd53(d, offset, pbuf, 1);
  185. if (ret == _FAIL)
  186. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  187. rtw_mfree(pbuf, 1);
  188. }
  189. static void _halmac_sdio_reg_write_16(void *p, u32 offset, u16 val)
  190. {
  191. struct dvobj_priv *d;
  192. u8 *pbuf;
  193. u8 ret;
  194. d = (struct dvobj_priv *)p;
  195. _halmac_mac_reg_page0_chk(__func__, d, offset);
  196. val = cpu_to_le16(val);
  197. pbuf = rtw_zmalloc(2);
  198. if (!pbuf)
  199. return;
  200. _rtw_memcpy(pbuf, &val, 2);
  201. ret = rtw_sdio_write_cmd53(d, offset, pbuf, 2);
  202. if (ret == _FAIL)
  203. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  204. rtw_mfree(pbuf, 2);
  205. }
  206. static void _halmac_sdio_reg_write_32(void *p, u32 offset, u32 val)
  207. {
  208. struct dvobj_priv *d;
  209. u8 *pbuf;
  210. u8 ret;
  211. d = (struct dvobj_priv *)p;
  212. _halmac_mac_reg_page0_chk(__func__, d, offset);
  213. val = cpu_to_le32(val);
  214. pbuf = rtw_zmalloc(4);
  215. if (!pbuf)
  216. return;
  217. _rtw_memcpy(pbuf, &val, 4);
  218. ret = rtw_sdio_write_cmd53(d, offset, pbuf, 4);
  219. if (ret == _FAIL)
  220. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  221. rtw_mfree(pbuf, 4);
  222. }
  223. static u8 _halmac_sdio_read_cia(void *p, u32 offset)
  224. {
  225. struct dvobj_priv *d;
  226. u8 data = 0;
  227. u8 ret;
  228. d = (struct dvobj_priv *)p;
  229. ret = rtw_sdio_f0_read(d, offset, &data, 1);
  230. if (ret == _FAIL)
  231. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  232. return data;
  233. }
  234. #else /* !CONFIG_SDIO_HCI */
  235. static u8 _halmac_reg_read_8(void *p, u32 offset)
  236. {
  237. struct dvobj_priv *d;
  238. PADAPTER adapter;
  239. d = (struct dvobj_priv *)p;
  240. adapter = dvobj_get_primary_adapter(d);
  241. return _rtw_read8(adapter, offset);
  242. }
  243. static u16 _halmac_reg_read_16(void *p, u32 offset)
  244. {
  245. struct dvobj_priv *d;
  246. PADAPTER adapter;
  247. d = (struct dvobj_priv *)p;
  248. adapter = dvobj_get_primary_adapter(d);
  249. return _rtw_read16(adapter, offset);
  250. }
  251. static u32 _halmac_reg_read_32(void *p, u32 offset)
  252. {
  253. struct dvobj_priv *d;
  254. PADAPTER adapter;
  255. d = (struct dvobj_priv *)p;
  256. adapter = dvobj_get_primary_adapter(d);
  257. return _rtw_read32(adapter, offset);
  258. }
  259. static void _halmac_reg_write_8(void *p, u32 offset, u8 val)
  260. {
  261. struct dvobj_priv *d;
  262. PADAPTER adapter;
  263. int err;
  264. d = (struct dvobj_priv *)p;
  265. adapter = dvobj_get_primary_adapter(d);
  266. err = _rtw_write8(adapter, offset, val);
  267. if (err == _FAIL)
  268. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  269. }
  270. static void _halmac_reg_write_16(void *p, u32 offset, u16 val)
  271. {
  272. struct dvobj_priv *d;
  273. PADAPTER adapter;
  274. int err;
  275. d = (struct dvobj_priv *)p;
  276. adapter = dvobj_get_primary_adapter(d);
  277. err = _rtw_write16(adapter, offset, val);
  278. if (err == _FAIL)
  279. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  280. }
  281. static void _halmac_reg_write_32(void *p, u32 offset, u32 val)
  282. {
  283. struct dvobj_priv *d;
  284. PADAPTER adapter;
  285. int err;
  286. d = (struct dvobj_priv *)p;
  287. adapter = dvobj_get_primary_adapter(d);
  288. err = _rtw_write32(adapter, offset, val);
  289. if (err == _FAIL)
  290. RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
  291. }
  292. #endif /* !CONFIG_SDIO_HCI */
  293. #ifdef DBG_IO
  294. static void _halmac_reg_read_monitor(void *p, u32 addr, u32 len, u32 val
  295. , const char *caller, const u32 line)
  296. {
  297. struct dvobj_priv *d = (struct dvobj_priv *)p;
  298. _adapter *adapter = dvobj_get_primary_adapter(d);
  299. dbg_rtw_reg_read_monitor(adapter, addr, len, val, caller, line);
  300. }
  301. static void _halmac_reg_write_monitor(void *p, u32 addr, u32 len, u32 val
  302. , const char *caller, const u32 line)
  303. {
  304. struct dvobj_priv *d = (struct dvobj_priv *)p;
  305. _adapter *adapter = dvobj_get_primary_adapter(d);
  306. dbg_rtw_reg_write_monitor(adapter, addr, len, val, caller, line);
  307. }
  308. #endif
  309. static u8 _halmac_mfree(void *p, void *buffer, u32 size)
  310. {
  311. rtw_mfree(buffer, size);
  312. return RTW_HALMAC_SUCCESS;
  313. }
  314. static void *_halmac_malloc(void *p, u32 size)
  315. {
  316. return rtw_zmalloc(size);
  317. }
  318. static u8 _halmac_memcpy(void *p, void *dest, void *src, u32 size)
  319. {
  320. _rtw_memcpy(dest, src, size);
  321. return RTW_HALMAC_SUCCESS;
  322. }
  323. static u8 _halmac_memset(void *p, void *addr, u8 value, u32 size)
  324. {
  325. _rtw_memset(addr, value, size);
  326. return RTW_HALMAC_SUCCESS;
  327. }
  328. static void _halmac_udelay(void *p, u32 us)
  329. {
  330. /* Most hardware polling wait time < 50us) */
  331. if (us <= 50)
  332. rtw_udelay_os(us);
  333. else if (us <= 1000)
  334. rtw_usleep_os(us);
  335. else
  336. rtw_msleep_os(RTW_DIV_ROUND_UP(us, 1000));
  337. }
  338. static u8 _halmac_mutex_init(void *p, HALMAC_MUTEX *pMutex)
  339. {
  340. _rtw_mutex_init(pMutex);
  341. return RTW_HALMAC_SUCCESS;
  342. }
  343. static u8 _halmac_mutex_deinit(void *p, HALMAC_MUTEX *pMutex)
  344. {
  345. _rtw_mutex_free(pMutex);
  346. return RTW_HALMAC_SUCCESS;
  347. }
  348. static u8 _halmac_mutex_lock(void *p, HALMAC_MUTEX *pMutex)
  349. {
  350. int err;
  351. err = _enter_critical_mutex(pMutex, NULL);
  352. if (err)
  353. return RTW_HALMAC_FAIL;
  354. return RTW_HALMAC_SUCCESS;
  355. }
  356. static u8 _halmac_mutex_unlock(void *p, HALMAC_MUTEX *pMutex)
  357. {
  358. _exit_critical_mutex(pMutex, NULL);
  359. return RTW_HALMAC_SUCCESS;
  360. }
  361. #ifndef CONFIG_SDIO_HCI
  362. #define DBG_MSG_FILTER
  363. #endif
  364. #ifdef DBG_MSG_FILTER
  365. static u8 is_msg_allowed(uint drv_lv, u8 msg_lv)
  366. {
  367. switch (drv_lv) {
  368. case _DRV_NONE_:
  369. return _FALSE;
  370. case _DRV_ALWAYS_:
  371. if (msg_lv > HALMAC_DBG_ALWAYS)
  372. return _FALSE;
  373. break;
  374. case _DRV_ERR_:
  375. if (msg_lv > HALMAC_DBG_ERR)
  376. return _FALSE;
  377. break;
  378. case _DRV_WARNING_:
  379. if (msg_lv > HALMAC_DBG_WARN)
  380. return _FALSE;
  381. break;
  382. case _DRV_INFO_:
  383. if (msg_lv >= HALMAC_DBG_TRACE)
  384. return _FALSE;
  385. break;
  386. }
  387. return _TRUE;
  388. }
  389. #endif /* DBG_MSG_FILTER */
  390. static u8 _halmac_msg_print(void *p, u32 msg_type, u8 msg_level, s8 *fmt, ...)
  391. {
  392. #define MSG_LEN 100
  393. va_list args;
  394. u8 str[MSG_LEN] = {0};
  395. #ifdef DBG_MSG_FILTER
  396. uint drv_level = _DRV_NONE_;
  397. #endif
  398. int err;
  399. u8 ret = RTW_HALMAC_SUCCESS;
  400. #ifdef DBG_MSG_FILTER
  401. #ifdef CONFIG_RTW_DEBUG
  402. drv_level = rtw_drv_log_level;
  403. #endif
  404. if (is_msg_allowed(drv_level, msg_level) == _FALSE)
  405. return ret;
  406. #endif
  407. str[0] = '\n';
  408. va_start(args, fmt);
  409. err = vsnprintf(str, MSG_LEN, fmt, args);
  410. va_end(args);
  411. /* An output error is encountered */
  412. if (err < 0)
  413. return RTW_HALMAC_FAIL;
  414. /* Output may be truncated due to size limit */
  415. if ((err == (MSG_LEN - 1)) && (str[MSG_LEN - 2] != '\n'))
  416. ret = RTW_HALMAC_FAIL;
  417. if (msg_level == HALMAC_DBG_ALWAYS)
  418. RTW_PRINT(MSG_PREFIX "%s", str);
  419. else if (msg_level <= HALMAC_DBG_ERR)
  420. RTW_ERR(MSG_PREFIX "%s", str);
  421. else if (msg_level <= HALMAC_DBG_WARN)
  422. RTW_WARN(MSG_PREFIX "%s", str);
  423. else
  424. RTW_DBG(MSG_PREFIX "%s", str);
  425. return ret;
  426. }
  427. static u8 _halmac_buff_print(void *p, u32 msg_type, u8 msg_level, s8 *buf, u32 size)
  428. {
  429. if (msg_level <= HALMAC_DBG_WARN)
  430. RTW_INFO_DUMP(MSG_PREFIX, buf, size);
  431. else
  432. RTW_DBG_DUMP(MSG_PREFIX, buf, size);
  433. return RTW_HALMAC_SUCCESS;
  434. }
  435. const char *const RTW_HALMAC_FEATURE_NAME[] = {
  436. "HALMAC_FEATURE_CFG_PARA",
  437. "HALMAC_FEATURE_DUMP_PHYSICAL_EFUSE",
  438. "HALMAC_FEATURE_DUMP_LOGICAL_EFUSE",
  439. "HALMAC_FEATURE_DUMP_LOGICAL_EFUSE_MASK",
  440. "HALMAC_FEATURE_UPDATE_PACKET",
  441. "HALMAC_FEATURE_SEND_SCAN_PACKET",
  442. "HALMAC_FEATURE_DROP_SCAN_PACKET",
  443. "HALMAC_FEATURE_UPDATE_DATAPACK",
  444. "HALMAC_FEATURE_RUN_DATAPACK",
  445. "HALMAC_FEATURE_CHANNEL_SWITCH",
  446. "HALMAC_FEATURE_IQK",
  447. "HALMAC_FEATURE_POWER_TRACKING",
  448. "HALMAC_FEATURE_PSD",
  449. "HALMAC_FEATURE_FW_SNDING",
  450. "HALMAC_FEATURE_ALL"
  451. };
  452. static inline u8 is_valid_id_status(enum halmac_feature_id id, enum halmac_cmd_process_status status)
  453. {
  454. switch (id) {
  455. case HALMAC_FEATURE_CFG_PARA:
  456. RTW_DBG("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  457. break;
  458. case HALMAC_FEATURE_DUMP_PHYSICAL_EFUSE:
  459. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  460. if (HALMAC_CMD_PROCESS_DONE != status)
  461. RTW_INFO("%s: id(%d) unspecified status(%d)!\n",
  462. __FUNCTION__, id, status);
  463. break;
  464. case HALMAC_FEATURE_DUMP_LOGICAL_EFUSE:
  465. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  466. if (HALMAC_CMD_PROCESS_DONE != status)
  467. RTW_INFO("%s: id(%d) unspecified status(%d)!\n",
  468. __FUNCTION__, id, status);
  469. break;
  470. case HALMAC_FEATURE_UPDATE_PACKET:
  471. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  472. if (status != HALMAC_CMD_PROCESS_DONE)
  473. RTW_INFO("%s: id(%d) unspecified status(%d)!\n",
  474. __FUNCTION__, id, status);
  475. break;
  476. case HALMAC_FEATURE_UPDATE_DATAPACK:
  477. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  478. break;
  479. case HALMAC_FEATURE_RUN_DATAPACK:
  480. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  481. break;
  482. case HALMAC_FEATURE_CHANNEL_SWITCH:
  483. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  484. if ((status != HALMAC_CMD_PROCESS_DONE) && (status != HALMAC_CMD_PROCESS_RCVD))
  485. RTW_INFO("%s: id(%d) unspecified status(%d)!\n",
  486. __FUNCTION__, id, status);
  487. if (status == HALMAC_CMD_PROCESS_DONE)
  488. return _FALSE;
  489. break;
  490. case HALMAC_FEATURE_IQK:
  491. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  492. break;
  493. case HALMAC_FEATURE_POWER_TRACKING:
  494. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  495. break;
  496. case HALMAC_FEATURE_PSD:
  497. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  498. break;
  499. case HALMAC_FEATURE_FW_SNDING:
  500. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  501. break;
  502. case HALMAC_FEATURE_ALL:
  503. RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
  504. break;
  505. default:
  506. RTW_ERR("%s: unknown feature id(%d)\n", __FUNCTION__, id);
  507. return _FALSE;
  508. }
  509. return _TRUE;
  510. }
  511. static int init_halmac_event_with_waittime(struct dvobj_priv *d, enum halmac_feature_id id, u8 *buf, u32 size, u32 time)
  512. {
  513. struct submit_ctx *sctx;
  514. if (!d->hmpriv.indicator[id].sctx) {
  515. sctx = (struct submit_ctx *)rtw_zmalloc(sizeof(*sctx));
  516. if (!sctx)
  517. return -1;
  518. } else {
  519. RTW_WARN("%s: id(%d) sctx is not NULL!!\n", __FUNCTION__, id);
  520. sctx = d->hmpriv.indicator[id].sctx;
  521. d->hmpriv.indicator[id].sctx = NULL;
  522. }
  523. rtw_sctx_init(sctx, time);
  524. d->hmpriv.indicator[id].buffer = buf;
  525. d->hmpriv.indicator[id].buf_size = size;
  526. d->hmpriv.indicator[id].ret_size = 0;
  527. d->hmpriv.indicator[id].status = 0;
  528. /* fill sctx at least to sure other variables are all ready! */
  529. d->hmpriv.indicator[id].sctx = sctx;
  530. return 0;
  531. }
  532. static inline int init_halmac_event(struct dvobj_priv *d, enum halmac_feature_id id, u8 *buf, u32 size)
  533. {
  534. return init_halmac_event_with_waittime(d, id, buf, size, DEFAULT_INDICATOR_TIMELMT);
  535. }
  536. static void free_halmac_event(struct dvobj_priv *d, enum halmac_feature_id id)
  537. {
  538. struct submit_ctx *sctx;
  539. if (!d->hmpriv.indicator[id].sctx)
  540. return;
  541. sctx = d->hmpriv.indicator[id].sctx;
  542. d->hmpriv.indicator[id].sctx = NULL;
  543. rtw_mfree((u8 *)sctx, sizeof(*sctx));
  544. }
  545. static int wait_halmac_event(struct dvobj_priv *d, enum halmac_feature_id id)
  546. {
  547. struct halmac_adapter *mac;
  548. struct halmac_api *api;
  549. struct submit_ctx *sctx;
  550. int ret;
  551. sctx = d->hmpriv.indicator[id].sctx;
  552. if (!sctx)
  553. return -1;
  554. ret = rtw_sctx_wait(sctx, RTW_HALMAC_FEATURE_NAME[id]);
  555. free_halmac_event(d, id);
  556. if (_SUCCESS == ret)
  557. return 0;
  558. /* timeout! We have to reset halmac state */
  559. RTW_ERR("%s: Wait id(%d, %s) TIMEOUT! Reset HALMAC state!\n",
  560. __FUNCTION__, id, RTW_HALMAC_FEATURE_NAME[id]);
  561. mac = dvobj_to_halmac(d);
  562. api = HALMAC_GET_API(mac);
  563. api->halmac_reset_feature(mac, id);
  564. return -1;
  565. }
  566. /*
  567. * Return:
  568. * Always return RTW_HALMAC_SUCCESS, HALMAC don't care the return value.
  569. */
  570. static u8 _halmac_event_indication(void *p, enum halmac_feature_id feature_id, enum halmac_cmd_process_status process_status, u8 *buf, u32 size)
  571. {
  572. struct dvobj_priv *d;
  573. PADAPTER adapter;
  574. PHAL_DATA_TYPE hal;
  575. struct halmac_indicator *tbl, *indicator;
  576. struct submit_ctx *sctx;
  577. u32 cpsz;
  578. u8 ret;
  579. d = (struct dvobj_priv *)p;
  580. adapter = dvobj_get_primary_adapter(d);
  581. hal = GET_HAL_DATA(adapter);
  582. tbl = d->hmpriv.indicator;
  583. /* Filter(Skip) middle status indication */
  584. ret = is_valid_id_status(feature_id, process_status);
  585. if (_FALSE == ret)
  586. goto exit;
  587. indicator = &tbl[feature_id];
  588. indicator->status = process_status;
  589. indicator->ret_size = size;
  590. if (!indicator->sctx) {
  591. RTW_WARN("%s: No feature id(%d, %s) waiting!!\n", __FUNCTION__, feature_id, RTW_HALMAC_FEATURE_NAME[feature_id]);
  592. goto exit;
  593. }
  594. sctx = indicator->sctx;
  595. if (HALMAC_CMD_PROCESS_ERROR == process_status) {
  596. RTW_ERR("%s: Something wrong id(%d, %s)!!\n", __FUNCTION__, feature_id, RTW_HALMAC_FEATURE_NAME[feature_id]);
  597. rtw_sctx_done_err(&sctx, RTW_SCTX_DONE_UNKNOWN);
  598. goto exit;
  599. }
  600. if (size > indicator->buf_size) {
  601. RTW_WARN("%s: id(%d, %s) buffer is not enough(%d<%d), data will be truncated!\n",
  602. __FUNCTION__, feature_id, RTW_HALMAC_FEATURE_NAME[feature_id], indicator->buf_size, size);
  603. cpsz = indicator->buf_size;
  604. } else {
  605. cpsz = size;
  606. }
  607. if (cpsz && indicator->buffer)
  608. _rtw_memcpy(indicator->buffer, buf, cpsz);
  609. rtw_sctx_done(&sctx);
  610. exit:
  611. return RTW_HALMAC_SUCCESS;
  612. }
  613. struct halmac_platform_api rtw_halmac_platform_api = {
  614. /* R/W register */
  615. #ifdef CONFIG_SDIO_HCI
  616. .SDIO_CMD52_READ = _halmac_sdio_cmd52_read,
  617. .SDIO_CMD53_READ_8 = _halmac_sdio_reg_read_8,
  618. .SDIO_CMD53_READ_16 = _halmac_sdio_reg_read_16,
  619. .SDIO_CMD53_READ_32 = _halmac_sdio_reg_read_32,
  620. .SDIO_CMD53_READ_N = _halmac_sdio_reg_read_n,
  621. .SDIO_CMD52_WRITE = _halmac_sdio_cmd52_write,
  622. .SDIO_CMD53_WRITE_8 = _halmac_sdio_reg_write_8,
  623. .SDIO_CMD53_WRITE_16 = _halmac_sdio_reg_write_16,
  624. .SDIO_CMD53_WRITE_32 = _halmac_sdio_reg_write_32,
  625. .SDIO_CMD52_CIA_READ = _halmac_sdio_read_cia,
  626. #endif /* CONFIG_SDIO_HCI */
  627. #if defined(CONFIG_USB_HCI) || defined(CONFIG_PCI_HCI)
  628. .REG_READ_8 = _halmac_reg_read_8,
  629. .REG_READ_16 = _halmac_reg_read_16,
  630. .REG_READ_32 = _halmac_reg_read_32,
  631. .REG_WRITE_8 = _halmac_reg_write_8,
  632. .REG_WRITE_16 = _halmac_reg_write_16,
  633. .REG_WRITE_32 = _halmac_reg_write_32,
  634. #endif /* CONFIG_USB_HCI || CONFIG_PCI_HCI */
  635. #ifdef DBG_IO
  636. .READ_MONITOR = _halmac_reg_read_monitor,
  637. .WRITE_MONITOR = _halmac_reg_write_monitor,
  638. #endif
  639. /* Write data */
  640. #if 0
  641. /* impletement in HAL-IC level */
  642. .SEND_RSVD_PAGE = sdio_write_data_rsvd_page,
  643. .SEND_H2C_PKT = sdio_write_data_h2c,
  644. #endif
  645. /* Memory allocate */
  646. .RTL_FREE = _halmac_mfree,
  647. .RTL_MALLOC = _halmac_malloc,
  648. .RTL_MEMCPY = _halmac_memcpy,
  649. .RTL_MEMSET = _halmac_memset,
  650. /* Sleep */
  651. .RTL_DELAY_US = _halmac_udelay,
  652. /* Process Synchronization */
  653. .MUTEX_INIT = _halmac_mutex_init,
  654. .MUTEX_DEINIT = _halmac_mutex_deinit,
  655. .MUTEX_LOCK = _halmac_mutex_lock,
  656. .MUTEX_UNLOCK = _halmac_mutex_unlock,
  657. .MSG_PRINT = _halmac_msg_print,
  658. .BUFF_PRINT = _halmac_buff_print,
  659. .EVENT_INDICATION = _halmac_event_indication,
  660. };
  661. u8 rtw_halmac_read8(struct intf_hdl *pintfhdl, u32 addr)
  662. {
  663. struct halmac_adapter *mac;
  664. struct halmac_api *api;
  665. /* WARNING: pintf_dev should not be null! */
  666. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  667. api = HALMAC_GET_API(mac);
  668. return api->halmac_reg_read_8(mac, addr);
  669. }
  670. u16 rtw_halmac_read16(struct intf_hdl *pintfhdl, u32 addr)
  671. {
  672. struct halmac_adapter *mac;
  673. struct halmac_api *api;
  674. /* WARNING: pintf_dev should not be null! */
  675. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  676. api = HALMAC_GET_API(mac);
  677. return api->halmac_reg_read_16(mac, addr);
  678. }
  679. u32 rtw_halmac_read32(struct intf_hdl *pintfhdl, u32 addr)
  680. {
  681. struct halmac_adapter *mac;
  682. struct halmac_api *api;
  683. /* WARNING: pintf_dev should not be null! */
  684. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  685. api = HALMAC_GET_API(mac);
  686. return api->halmac_reg_read_32(mac, addr);
  687. }
  688. static void _read_register(struct dvobj_priv *d, u32 addr, u32 cnt, u8 *buf)
  689. {
  690. #if 1
  691. struct _ADAPTER *a;
  692. u32 i, n;
  693. u16 val16;
  694. u32 val32;
  695. a = dvobj_get_primary_adapter(d);
  696. i = addr & 0x3;
  697. /* Handle address not start from 4 bytes alignment case */
  698. if (i) {
  699. val32 = cpu_to_le32(rtw_read32(a, addr & ~0x3));
  700. n = 4 - i;
  701. _rtw_memcpy(buf, ((u8 *)&val32) + i, n);
  702. i = n;
  703. cnt -= n;
  704. }
  705. while (cnt) {
  706. if (cnt >= 4)
  707. n = 4;
  708. else if (cnt >= 2)
  709. n = 2;
  710. else
  711. n = 1;
  712. cnt -= n;
  713. switch (n) {
  714. case 1:
  715. buf[i] = rtw_read8(a, addr+i);
  716. i++;
  717. break;
  718. case 2:
  719. val16 = cpu_to_le16(rtw_read16(a, addr+i));
  720. _rtw_memcpy(&buf[i], &val16, 2);
  721. i += 2;
  722. break;
  723. case 4:
  724. val32 = cpu_to_le32(rtw_read32(a, addr+i));
  725. _rtw_memcpy(&buf[i], &val32, 4);
  726. i += 4;
  727. break;
  728. }
  729. }
  730. #else
  731. struct _ADAPTER *a;
  732. u32 i;
  733. a = dvobj_get_primary_adapter(d);
  734. for (i = 0; i < cnt; i++)
  735. buf[i] = rtw_read8(a, addr + i);
  736. #endif
  737. }
  738. #ifdef CONFIG_SDIO_HCI
  739. static int _sdio_read_local(struct dvobj_priv *d, u32 addr, u32 cnt, u8 *buf)
  740. {
  741. struct halmac_adapter *mac;
  742. struct halmac_api *api;
  743. enum halmac_ret_status status;
  744. if (buf == NULL)
  745. return -1;
  746. mac = dvobj_to_halmac(d);
  747. api = HALMAC_GET_API(mac);
  748. status = api->halmac_reg_sdio_cmd53_read_n(mac, addr, cnt, buf);
  749. if (status != HALMAC_RET_SUCCESS) {
  750. RTW_ERR("%s: addr=0x%08x cnt=%d err=%d\n",
  751. __FUNCTION__, addr, cnt, status);
  752. return -1;
  753. }
  754. return 0;
  755. }
  756. #endif /* CONFIG_SDIO_HCI */
  757. void rtw_halmac_read_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem)
  758. {
  759. struct dvobj_priv *d;
  760. if (pmem == NULL) {
  761. RTW_ERR("pmem is NULL\n");
  762. return;
  763. }
  764. d = pintfhdl->pintf_dev;
  765. #ifdef CONFIG_SDIO_HCI
  766. if (addr & 0xFFFF0000) {
  767. int err = 0;
  768. err = _sdio_read_local(d, addr, cnt, pmem);
  769. if (!err)
  770. return;
  771. }
  772. #endif /* CONFIG_SDIO_HCI */
  773. _read_register(d, addr, cnt, pmem);
  774. }
  775. #ifdef CONFIG_SDIO_INDIRECT_ACCESS
  776. u8 rtw_halmac_iread8(struct intf_hdl *pintfhdl, u32 addr)
  777. {
  778. struct halmac_adapter *mac;
  779. struct halmac_api *api;
  780. /* WARNING: pintf_dev should not be null! */
  781. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  782. api = HALMAC_GET_API(mac);
  783. /*return api->halmac_reg_read_indirect_8(mac, addr);*/
  784. return api->halmac_reg_read_8(mac, addr);
  785. }
  786. u16 rtw_halmac_iread16(struct intf_hdl *pintfhdl, u32 addr)
  787. {
  788. struct halmac_adapter *mac;
  789. struct halmac_api *api;
  790. u16 val16 = 0;
  791. /* WARNING: pintf_dev should not be null! */
  792. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  793. api = HALMAC_GET_API(mac);
  794. /*return api->halmac_reg_read_indirect_16(mac, addr);*/
  795. return api->halmac_reg_read_16(mac, addr);
  796. }
  797. u32 rtw_halmac_iread32(struct intf_hdl *pintfhdl, u32 addr)
  798. {
  799. struct halmac_adapter *mac;
  800. struct halmac_api *api;
  801. /* WARNING: pintf_dev should not be null! */
  802. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  803. api = HALMAC_GET_API(mac);
  804. return api->halmac_reg_read_indirect_32(mac, addr);
  805. }
  806. #endif /* CONFIG_SDIO_INDIRECT_ACCESS */
  807. int rtw_halmac_write8(struct intf_hdl *pintfhdl, u32 addr, u8 value)
  808. {
  809. struct halmac_adapter *mac;
  810. struct halmac_api *api;
  811. enum halmac_ret_status status;
  812. /* WARNING: pintf_dev should not be null! */
  813. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  814. api = HALMAC_GET_API(mac);
  815. status = api->halmac_reg_write_8(mac, addr, value);
  816. if (status == HALMAC_RET_SUCCESS)
  817. return 0;
  818. return -1;
  819. }
  820. int rtw_halmac_write16(struct intf_hdl *pintfhdl, u32 addr, u16 value)
  821. {
  822. struct halmac_adapter *mac;
  823. struct halmac_api *api;
  824. enum halmac_ret_status status;
  825. /* WARNING: pintf_dev should not be null! */
  826. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  827. api = HALMAC_GET_API(mac);
  828. status = api->halmac_reg_write_16(mac, addr, value);
  829. if (status == HALMAC_RET_SUCCESS)
  830. return 0;
  831. return -1;
  832. }
  833. int rtw_halmac_write32(struct intf_hdl *pintfhdl, u32 addr, u32 value)
  834. {
  835. struct halmac_adapter *mac;
  836. struct halmac_api *api;
  837. enum halmac_ret_status status;
  838. /* WARNING: pintf_dev should not be null! */
  839. mac = dvobj_to_halmac(pintfhdl->pintf_dev);
  840. api = HALMAC_GET_API(mac);
  841. status = api->halmac_reg_write_32(mac, addr, value);
  842. if (status == HALMAC_RET_SUCCESS)
  843. return 0;
  844. return -1;
  845. }
  846. static int init_write_rsvd_page_size(struct dvobj_priv *d)
  847. {
  848. struct halmac_adapter *mac;
  849. struct halmac_api *api;
  850. u32 size = 0;
  851. struct halmac_ofld_func_info ofld_info;
  852. enum halmac_ret_status status;
  853. int err = 0;
  854. #ifdef CONFIG_USB_HCI
  855. /* for USB do not exceed MAX_CMDBUF_SZ */
  856. size = 0x1000;
  857. #elif defined(CONFIG_PCI_HCI)
  858. size = MAX_CMDBUF_SZ - TXDESC_OFFSET;
  859. #elif defined(CONFIG_SDIO_HCI)
  860. size = 0x7000; /* 28KB */
  861. #else
  862. /* Use HALMAC default setting and don't call any function */
  863. return 0;
  864. #endif
  865. #if 0 /* Fail to pass coverity DEADCODE check */
  866. /* If size==0, use HALMAC default setting and don't call any function */
  867. if (!size)
  868. return 0;
  869. #endif
  870. err = rtw_halmac_set_max_dl_fw_size(d, size);
  871. if (err) {
  872. RTW_ERR("%s: Fail to set max download fw size!\n", __FUNCTION__);
  873. return -1;
  874. }
  875. mac = dvobj_to_halmac(d);
  876. api = HALMAC_GET_API(mac);
  877. _rtw_memset(&ofld_info, 0, sizeof(ofld_info));
  878. ofld_info.halmac_malloc_max_sz = 0xFFFFFFFF;
  879. ofld_info.rsvd_pg_drv_buf_max_sz = size;
  880. status = api->halmac_ofld_func_cfg(mac, &ofld_info);
  881. if (status != HALMAC_RET_SUCCESS) {
  882. RTW_ERR("%s: Fail to config offload parameters!\n", __FUNCTION__);
  883. return -1;
  884. }
  885. return 0;
  886. }
  887. static int init_priv(struct halmacpriv *priv)
  888. {
  889. struct halmac_indicator *indicator;
  890. u32 count, size;
  891. if (priv->indicator)
  892. RTW_WARN("%s: HALMAC private data is not CLEAR!\n", __FUNCTION__);
  893. count = HALMAC_FEATURE_ALL + 1;
  894. size = sizeof(*indicator) * count;
  895. indicator = (struct halmac_indicator *)rtw_zmalloc(size);
  896. if (!indicator)
  897. return -1;
  898. priv->indicator = indicator;
  899. return 0;
  900. }
  901. static void deinit_priv(struct halmacpriv *priv)
  902. {
  903. struct halmac_indicator *indicator;
  904. indicator = priv->indicator;
  905. priv->indicator = NULL;
  906. if (indicator) {
  907. u32 count, size;
  908. count = HALMAC_FEATURE_ALL + 1;
  909. #ifdef CONFIG_RTW_DEBUG
  910. {
  911. struct submit_ctx *sctx;
  912. u32 i;
  913. for (i = 0; i < count; i++) {
  914. if (!indicator[i].sctx)
  915. continue;
  916. RTW_WARN("%s: %s id(%d) sctx still exist!!\n",
  917. __FUNCTION__, RTW_HALMAC_FEATURE_NAME[i], i);
  918. sctx = indicator[i].sctx;
  919. indicator[i].sctx = NULL;
  920. rtw_mfree((u8 *)sctx, sizeof(*sctx));
  921. }
  922. }
  923. #endif /* !CONFIG_RTW_DEBUG */
  924. size = sizeof(*indicator) * count;
  925. rtw_mfree((u8 *)indicator, size);
  926. }
  927. }
  928. #ifdef CONFIG_SDIO_HCI
  929. static enum halmac_sdio_spec_ver _sdio_ver_drv2halmac(struct dvobj_priv *d)
  930. {
  931. bool v3;
  932. enum halmac_sdio_spec_ver ver;
  933. v3 = rtw_is_sdio30(dvobj_get_primary_adapter(d));
  934. if (v3)
  935. ver = HALMAC_SDIO_SPEC_VER_3_00;
  936. else
  937. ver = HALMAC_SDIO_SPEC_VER_2_00;
  938. return ver;
  939. }
  940. #endif /* CONFIG_SDIO_HCI */
  941. void rtw_halmac_get_version(char *str, u32 len)
  942. {
  943. enum halmac_ret_status status;
  944. struct halmac_ver ver;
  945. status = halmac_get_version(&ver);
  946. if (status != HALMAC_RET_SUCCESS)
  947. return;
  948. rtw_sprintf(str, len, "V%d_%02d_%02d",
  949. ver.major_ver, ver.prototype_ver, ver.minor_ver);
  950. }
  951. int rtw_halmac_init_adapter(struct dvobj_priv *d, struct halmac_platform_api *pf_api)
  952. {
  953. struct halmac_adapter *halmac;
  954. struct halmac_api *api;
  955. enum halmac_interface intf;
  956. enum halmac_ret_status status;
  957. int err = 0;
  958. #ifdef CONFIG_SDIO_HCI
  959. struct halmac_sdio_hw_info info;
  960. #endif /* CONFIG_SDIO_HCI */
  961. halmac = dvobj_to_halmac(d);
  962. if (halmac) {
  963. RTW_WARN("%s: initialize already completed!\n", __FUNCTION__);
  964. goto error;
  965. }
  966. err = init_priv(&d->hmpriv);
  967. if (err)
  968. goto error;
  969. #ifdef CONFIG_SDIO_HCI
  970. intf = HALMAC_INTERFACE_SDIO;
  971. #elif defined(CONFIG_USB_HCI)
  972. intf = HALMAC_INTERFACE_USB;
  973. #elif defined(CONFIG_PCI_HCI)
  974. intf = HALMAC_INTERFACE_PCIE;
  975. #else
  976. #warning "INTERFACE(CONFIG_XXX_HCI) not be defined!!"
  977. intf = HALMAC_INTERFACE_UNDEFINE;
  978. #endif
  979. status = halmac_init_adapter(d, pf_api, intf, &halmac, &api);
  980. if (HALMAC_RET_SUCCESS != status) {
  981. RTW_ERR("%s: halmac_init_adapter fail!(status=%d)\n", __FUNCTION__, status);
  982. err = -1;
  983. if (halmac)
  984. goto deinit;
  985. goto free;
  986. }
  987. dvobj_set_halmac(d, halmac);
  988. status = api->halmac_interface_integration_tuning(halmac);
  989. if (status != HALMAC_RET_SUCCESS) {
  990. RTW_ERR("%s: halmac_interface_integration_tuning fail!(status=%d)\n", __FUNCTION__, status);
  991. err = -1;
  992. goto deinit;
  993. }
  994. status = api->halmac_phy_cfg(halmac, HALMAC_INTF_PHY_PLATFORM_ALL);
  995. if (status != HALMAC_RET_SUCCESS) {
  996. RTW_ERR("%s: halmac_phy_cfg fail!(status=%d)\n", __FUNCTION__, status);
  997. err = -1;
  998. goto deinit;
  999. }
  1000. init_write_rsvd_page_size(d);
  1001. #ifdef CONFIG_SDIO_HCI
  1002. _rtw_memset(&info, 0, sizeof(info));
  1003. info.spec_ver = _sdio_ver_drv2halmac(d);
  1004. /* Convert clock speed unit to MHz from Hz */
  1005. info.clock_speed = RTW_DIV_ROUND_UP(rtw_sdio_get_clock(d), 1000000);
  1006. info.block_size = rtw_sdio_get_block_size(d);
  1007. if (d->hmpriv.sdio_io_indir == 2)
  1008. info.io_indir_flag = 0;
  1009. else
  1010. info.io_indir_flag = 1; /* Default enable indirect I/O */
  1011. RTW_DBG("%s: SDIO ver=%u clock=%uMHz blk_size=%u bytes, io_indir=%u\n",
  1012. __FUNCTION__, info.spec_ver+2, info.clock_speed,
  1013. info.block_size, info.io_indir_flag);
  1014. status = api->halmac_sdio_hw_info(halmac, &info);
  1015. if (status != HALMAC_RET_SUCCESS) {
  1016. RTW_ERR("%s: halmac_sdio_hw_info fail!(status=%d)\n",
  1017. __FUNCTION__, status);
  1018. err = -1;
  1019. goto deinit;
  1020. }
  1021. #endif /* CONFIG_SDIO_HCI */
  1022. return 0;
  1023. deinit:
  1024. status = halmac_deinit_adapter(halmac);
  1025. dvobj_set_halmac(d, NULL);
  1026. if (status != HALMAC_RET_SUCCESS)
  1027. RTW_ERR("%s: halmac_deinit_adapter fail!(status=%d)\n",
  1028. __FUNCTION__, status);
  1029. free:
  1030. deinit_priv(&d->hmpriv);
  1031. error:
  1032. return err;
  1033. }
  1034. int rtw_halmac_deinit_adapter(struct dvobj_priv *d)
  1035. {
  1036. struct halmac_adapter *halmac;
  1037. enum halmac_ret_status status;
  1038. int err = 0;
  1039. halmac = dvobj_to_halmac(d);
  1040. if (halmac) {
  1041. status = halmac_deinit_adapter(halmac);
  1042. dvobj_set_halmac(d, NULL);
  1043. if (status != HALMAC_RET_SUCCESS)
  1044. err = -1;
  1045. }
  1046. deinit_priv(&d->hmpriv);
  1047. return err;
  1048. }
  1049. static inline enum halmac_portid _hw_port_drv2halmac(enum _hw_port hwport)
  1050. {
  1051. enum halmac_portid port = HALMAC_PORTID_NUM;
  1052. switch (hwport) {
  1053. case HW_PORT0:
  1054. port = HALMAC_PORTID0;
  1055. break;
  1056. case HW_PORT1:
  1057. port = HALMAC_PORTID1;
  1058. break;
  1059. case HW_PORT2:
  1060. port = HALMAC_PORTID2;
  1061. break;
  1062. case HW_PORT3:
  1063. port = HALMAC_PORTID3;
  1064. break;
  1065. case HW_PORT4:
  1066. port = HALMAC_PORTID4;
  1067. break;
  1068. default:
  1069. break;
  1070. }
  1071. return port;
  1072. }
  1073. static enum halmac_network_type_select _network_type_drv2halmac(u8 type)
  1074. {
  1075. enum halmac_network_type_select network = HALMAC_NETWORK_UNDEFINE;
  1076. switch (type) {
  1077. case _HW_STATE_NOLINK_:
  1078. case _HW_STATE_MONITOR_:
  1079. network = HALMAC_NETWORK_NO_LINK;
  1080. break;
  1081. case _HW_STATE_ADHOC_:
  1082. network = HALMAC_NETWORK_ADHOC;
  1083. break;
  1084. case _HW_STATE_STATION_:
  1085. network = HALMAC_NETWORK_INFRASTRUCTURE;
  1086. break;
  1087. case _HW_STATE_AP_:
  1088. network = HALMAC_NETWORK_AP;
  1089. break;
  1090. }
  1091. return network;
  1092. }
  1093. static u8 _network_type_halmac2drv(enum halmac_network_type_select network)
  1094. {
  1095. u8 type = _HW_STATE_NOLINK_;
  1096. switch (network) {
  1097. case HALMAC_NETWORK_NO_LINK:
  1098. case HALMAC_NETWORK_UNDEFINE:
  1099. type = _HW_STATE_NOLINK_;
  1100. break;
  1101. case HALMAC_NETWORK_ADHOC:
  1102. type = _HW_STATE_ADHOC_;
  1103. break;
  1104. case HALMAC_NETWORK_INFRASTRUCTURE:
  1105. type = _HW_STATE_STATION_;
  1106. break;
  1107. case HALMAC_NETWORK_AP:
  1108. type = _HW_STATE_AP_;
  1109. break;
  1110. }
  1111. return type;
  1112. }
  1113. static void _beacon_ctrl_halmac2drv(struct halmac_bcn_ctrl *ctrl,
  1114. struct rtw_halmac_bcn_ctrl *drv_ctrl)
  1115. {
  1116. drv_ctrl->rx_bssid_fit = ctrl->dis_rx_bssid_fit ? 0 : 1;
  1117. drv_ctrl->txbcn_rpt = ctrl->en_txbcn_rpt ? 1 : 0;
  1118. drv_ctrl->tsf_update = ctrl->dis_tsf_udt ? 0 : 1;
  1119. drv_ctrl->enable_bcn = ctrl->en_bcn ? 1 : 0;
  1120. drv_ctrl->rxbcn_rpt = ctrl->en_rxbcn_rpt ? 1 : 0;
  1121. drv_ctrl->p2p_ctwin = ctrl->en_p2p_ctwin ? 1 : 0;
  1122. drv_ctrl->p2p_bcn_area = ctrl->en_p2p_bcn_area ? 1 : 0;
  1123. }
  1124. static void _beacon_ctrl_drv2halmac(struct rtw_halmac_bcn_ctrl *drv_ctrl,
  1125. struct halmac_bcn_ctrl *ctrl)
  1126. {
  1127. ctrl->dis_rx_bssid_fit = drv_ctrl->rx_bssid_fit ? 0 : 1;
  1128. ctrl->en_txbcn_rpt = drv_ctrl->txbcn_rpt ? 1 : 0;
  1129. ctrl->dis_tsf_udt = drv_ctrl->tsf_update ? 0 : 1;
  1130. ctrl->en_bcn = drv_ctrl->enable_bcn ? 1 : 0;
  1131. ctrl->en_rxbcn_rpt = drv_ctrl->rxbcn_rpt ? 1 : 0;
  1132. ctrl->en_p2p_ctwin = drv_ctrl->p2p_ctwin ? 1 : 0;
  1133. ctrl->en_p2p_bcn_area = drv_ctrl->p2p_bcn_area ? 1 : 0;
  1134. }
  1135. int rtw_halmac_get_hw_value(struct dvobj_priv *d, enum halmac_hw_id hw_id, void *pvalue)
  1136. {
  1137. struct halmac_adapter *mac;
  1138. struct halmac_api *api;
  1139. enum halmac_ret_status status;
  1140. mac = dvobj_to_halmac(d);
  1141. api = HALMAC_GET_API(mac);
  1142. status = api->halmac_get_hw_value(mac, hw_id, pvalue);
  1143. if (HALMAC_RET_SUCCESS != status)
  1144. return -1;
  1145. return 0;
  1146. }
  1147. /**
  1148. * rtw_halmac_get_tx_fifo_size() - TX FIFO size
  1149. * @d: struct dvobj_priv*
  1150. * @size: TX FIFO size, unit is byte.
  1151. *
  1152. * Get TX FIFO size(byte) from HALMAC.
  1153. *
  1154. * Return 0 for OK, otherwise fail.
  1155. */
  1156. int rtw_halmac_get_tx_fifo_size(struct dvobj_priv *d, u32 *size)
  1157. {
  1158. struct halmac_adapter *halmac;
  1159. struct halmac_api *api;
  1160. enum halmac_ret_status status;
  1161. u32 val = 0;
  1162. halmac = dvobj_to_halmac(d);
  1163. api = HALMAC_GET_API(halmac);
  1164. status = api->halmac_get_hw_value(halmac, HALMAC_HW_TXFIFO_SIZE, &val);
  1165. if (status != HALMAC_RET_SUCCESS)
  1166. return -1;
  1167. *size = val;
  1168. return 0;
  1169. }
  1170. /**
  1171. * rtw_halmac_get_rx_fifo_size() - RX FIFO size
  1172. * @d: struct dvobj_priv*
  1173. * @size: RX FIFO size, unit is byte
  1174. *
  1175. * Get RX FIFO size(byte) from HALMAC.
  1176. *
  1177. * Return 0 for OK, otherwise fail.
  1178. */
  1179. int rtw_halmac_get_rx_fifo_size(struct dvobj_priv *d, u32 *size)
  1180. {
  1181. struct halmac_adapter *halmac;
  1182. struct halmac_api *api;
  1183. enum halmac_ret_status status;
  1184. u32 val = 0;
  1185. halmac = dvobj_to_halmac(d);
  1186. api = HALMAC_GET_API(halmac);
  1187. status = api->halmac_get_hw_value(halmac, HALMAC_HW_RXFIFO_SIZE, &val);
  1188. if (status != HALMAC_RET_SUCCESS)
  1189. return -1;
  1190. *size = val;
  1191. return 0;
  1192. }
  1193. /**
  1194. * rtw_halmac_get_rsvd_drv_pg_bndy() - Reserve page boundary of driver
  1195. * @d: struct dvobj_priv*
  1196. * @size: Page size, unit is byte
  1197. *
  1198. * Get reserve page boundary of driver from HALMAC.
  1199. *
  1200. * Return 0 for OK, otherwise fail.
  1201. */
  1202. int rtw_halmac_get_rsvd_drv_pg_bndy(struct dvobj_priv *d, u16 *bndy)
  1203. {
  1204. struct halmac_adapter *halmac;
  1205. struct halmac_api *api;
  1206. enum halmac_ret_status status;
  1207. u16 val = 0;
  1208. halmac = dvobj_to_halmac(d);
  1209. api = HALMAC_GET_API(halmac);
  1210. status = api->halmac_get_hw_value(halmac, HALMAC_HW_RSVD_PG_BNDY, &val);
  1211. if (status != HALMAC_RET_SUCCESS)
  1212. return -1;
  1213. *bndy = val;
  1214. return 0;
  1215. }
  1216. /**
  1217. * rtw_halmac_get_page_size() - Page size
  1218. * @d: struct dvobj_priv*
  1219. * @size: Page size, unit is byte
  1220. *
  1221. * Get TX/RX page size(byte) from HALMAC.
  1222. *
  1223. * Return 0 for OK, otherwise fail.
  1224. */
  1225. int rtw_halmac_get_page_size(struct dvobj_priv *d, u32 *size)
  1226. {
  1227. struct halmac_adapter *halmac;
  1228. struct halmac_api *api;
  1229. enum halmac_ret_status status;
  1230. u32 val = 0;
  1231. halmac = dvobj_to_halmac(d);
  1232. api = HALMAC_GET_API(halmac);
  1233. status = api->halmac_get_hw_value(halmac, HALMAC_HW_PAGE_SIZE, &val);
  1234. if (status != HALMAC_RET_SUCCESS)
  1235. return -1;
  1236. *size = val;
  1237. return 0;
  1238. }
  1239. /**
  1240. * rtw_halmac_get_tx_agg_align_size() - TX aggregation align size
  1241. * @d: struct dvobj_priv*
  1242. * @size: TX aggregation align size, unit is byte
  1243. *
  1244. * Get TX aggregation align size(byte) from HALMAC.
  1245. *
  1246. * Return 0 for OK, otherwise fail.
  1247. */
  1248. int rtw_halmac_get_tx_agg_align_size(struct dvobj_priv *d, u16 *size)
  1249. {
  1250. struct halmac_adapter *halmac;
  1251. struct halmac_api *api;
  1252. enum halmac_ret_status status;
  1253. u16 val = 0;
  1254. halmac = dvobj_to_halmac(d);
  1255. api = HALMAC_GET_API(halmac);
  1256. status = api->halmac_get_hw_value(halmac, HALMAC_HW_TX_AGG_ALIGN_SIZE, &val);
  1257. if (status != HALMAC_RET_SUCCESS)
  1258. return -1;
  1259. *size = val;
  1260. return 0;
  1261. }
  1262. /**
  1263. * rtw_halmac_get_rx_agg_align_size() - RX aggregation align size
  1264. * @d: struct dvobj_priv*
  1265. * @size: RX aggregation align size, unit is byte
  1266. *
  1267. * Get RX aggregation align size(byte) from HALMAC.
  1268. *
  1269. * Return 0 for OK, otherwise fail.
  1270. */
  1271. int rtw_halmac_get_rx_agg_align_size(struct dvobj_priv *d, u8 *size)
  1272. {
  1273. struct halmac_adapter *halmac;
  1274. struct halmac_api *api;
  1275. enum halmac_ret_status status;
  1276. u8 val = 0;
  1277. halmac = dvobj_to_halmac(d);
  1278. api = HALMAC_GET_API(halmac);
  1279. status = api->halmac_get_hw_value(halmac, HALMAC_HW_RX_AGG_ALIGN_SIZE, &val);
  1280. if (status != HALMAC_RET_SUCCESS)
  1281. return -1;
  1282. *size = val;
  1283. return 0;
  1284. }
  1285. /*
  1286. * Description:
  1287. * Get RX driver info size. RX driver info is a small memory space between
  1288. * scriptor and RX payload.
  1289. *
  1290. * +-------------------------+
  1291. * | RX descriptor |
  1292. * | usually 24 bytes |
  1293. * +-------------------------+
  1294. * | RX driver info |
  1295. * | depends on driver cfg |
  1296. * +-------------------------+
  1297. * | RX paylad |
  1298. * | |
  1299. * +-------------------------+
  1300. *
  1301. * Parameter:
  1302. * d pointer to struct dvobj_priv of driver
  1303. * sz rx driver info size in bytes.
  1304. *
  1305. * Return:
  1306. * 0 Success
  1307. * other Fail
  1308. */
  1309. int rtw_halmac_get_rx_drv_info_sz(struct dvobj_priv *d, u8 *sz)
  1310. {
  1311. enum halmac_ret_status status;
  1312. struct halmac_adapter *halmac = dvobj_to_halmac(d);
  1313. struct halmac_api *api = HALMAC_GET_API(halmac);
  1314. u8 dw = 0;
  1315. status = api->halmac_get_hw_value(halmac, HALMAC_HW_DRV_INFO_SIZE, &dw);
  1316. if (status != HALMAC_RET_SUCCESS)
  1317. return -1;
  1318. *sz = dw * 8;
  1319. return 0;
  1320. }
  1321. /**
  1322. * rtw_halmac_get_tx_desc_size() - TX descriptor size
  1323. * @d: struct dvobj_priv*
  1324. * @size: TX descriptor size, unit is byte.
  1325. *
  1326. * Get TX descriptor size(byte) from HALMAC.
  1327. *
  1328. * Return 0 for OK, otherwise fail.
  1329. */
  1330. int rtw_halmac_get_tx_desc_size(struct dvobj_priv *d, u32 *size)
  1331. {
  1332. struct halmac_adapter *halmac;
  1333. struct halmac_api *api;
  1334. enum halmac_ret_status status;
  1335. u32 val = 0;
  1336. halmac = dvobj_to_halmac(d);
  1337. api = HALMAC_GET_API(halmac);
  1338. status = api->halmac_get_hw_value(halmac, HALMAC_HW_TX_DESC_SIZE, &val);
  1339. if (status != HALMAC_RET_SUCCESS)
  1340. return -1;
  1341. *size = val;
  1342. return 0;
  1343. }
  1344. /**
  1345. * rtw_halmac_get_rx_desc_size() - RX descriptor size
  1346. * @d: struct dvobj_priv*
  1347. * @size: RX descriptor size, unit is byte.
  1348. *
  1349. * Get RX descriptor size(byte) from HALMAC.
  1350. *
  1351. * Return 0 for OK, otherwise fail.
  1352. */
  1353. int rtw_halmac_get_rx_desc_size(struct dvobj_priv *d, u32 *size)
  1354. {
  1355. struct halmac_adapter *halmac;
  1356. struct halmac_api *api;
  1357. enum halmac_ret_status status;
  1358. u32 val = 0;
  1359. halmac = dvobj_to_halmac(d);
  1360. api = HALMAC_GET_API(halmac);
  1361. status = api->halmac_get_hw_value(halmac, HALMAC_HW_RX_DESC_SIZE, &val);
  1362. if (status != HALMAC_RET_SUCCESS)
  1363. return -1;
  1364. *size = val;
  1365. return 0;
  1366. }
  1367. /**
  1368. * rtw_halmac_get_tx_dma_ch_map() - Get TX DMA channel Map for tx desc
  1369. * @d: struct dvobj_priv*
  1370. * @dma_ch_map: return map of QSEL to DMA channel
  1371. * @map_size: size of dma_ch_map
  1372. * Suggest size to be last valid QSEL(QSLT_CMD)+1 or full QSLT
  1373. * size(0x20)
  1374. *
  1375. * 8814B would need this to get mapping of QSEL to DMA channel for TX desc.
  1376. *
  1377. * Return 0 for OK, otherwise fail.
  1378. */
  1379. int rtw_halmac_get_tx_dma_ch_map(struct dvobj_priv *d, u8 *dma_ch_map, u8 map_size)
  1380. {
  1381. struct halmac_adapter *halmac;
  1382. struct halmac_api *api;
  1383. enum halmac_ret_status status;
  1384. struct halmac_rqpn_ch_map map;
  1385. enum halmac_dma_ch channel = HALMAC_DMA_CH_UNDEFINE;
  1386. u8 qsel;
  1387. halmac = dvobj_to_halmac(d);
  1388. api = HALMAC_GET_API(halmac);
  1389. status = api->halmac_get_hw_value(halmac, HALMAC_HW_RQPN_CH_MAPPING, &map);
  1390. if (status != HALMAC_RET_SUCCESS)
  1391. return -1;
  1392. for (qsel = 0; qsel < map_size; qsel++) {
  1393. switch (qsel) {
  1394. /*case QSLT_VO:*/
  1395. case 0x06:
  1396. case 0x07:
  1397. channel = map.dma_map_vo;
  1398. break;
  1399. /*case QSLT_VI:*/
  1400. case 0x04:
  1401. case 0x05:
  1402. channel = map.dma_map_vi;
  1403. break;
  1404. /*case QSLT_BE:*/
  1405. case 0x00:
  1406. case 0x03:
  1407. channel = map.dma_map_be;
  1408. break;
  1409. /*case QSLT_BK:*/
  1410. case 0x01:
  1411. case 0x02:
  1412. channel = map.dma_map_bk;
  1413. break;
  1414. /*case QSLT_BEACON:*/
  1415. case 0x10:
  1416. channel = HALMAC_DMA_CH_BCN;
  1417. break;
  1418. /*case QSLT_HIGH:*/
  1419. case 0x11:
  1420. channel = map.dma_map_hi;
  1421. break;
  1422. /*case QSLT_MGNT:*/
  1423. case 0x12:
  1424. channel = map.dma_map_mg;
  1425. break;
  1426. /*case QSLT_CMD:*/
  1427. case 0x13:
  1428. channel = HALMAC_DMA_CH_H2C;
  1429. break;
  1430. default:
  1431. /*RTW_ERR("%s: invalid qsel=0x%x\n", __FUNCTION__, qsel);*/
  1432. channel = HALMAC_DMA_CH_UNDEFINE;
  1433. break;
  1434. }
  1435. dma_ch_map[qsel] = (u8)channel;
  1436. }
  1437. return 0;
  1438. }
  1439. /**
  1440. * rtw_halmac_get_fw_max_size() - Firmware MAX size
  1441. * @d: struct dvobj_priv*
  1442. * @size: MAX Firmware size, unit is byte.
  1443. *
  1444. * Get Firmware MAX size(byte) from HALMAC.
  1445. *
  1446. * Return 0 for OK, otherwise fail.
  1447. */
  1448. static int rtw_halmac_get_fw_max_size(struct dvobj_priv *d, u32 *size)
  1449. {
  1450. struct halmac_adapter *halmac;
  1451. struct halmac_api *api;
  1452. enum halmac_ret_status status;
  1453. u32 val = 0;
  1454. halmac = dvobj_to_halmac(d);
  1455. api = HALMAC_GET_API(halmac);
  1456. status = api->halmac_get_hw_value(halmac, HALMAC_HW_FW_MAX_SIZE, &val);
  1457. if (status != HALMAC_RET_SUCCESS)
  1458. return -1;
  1459. *size = val;
  1460. return 0;
  1461. }
  1462. /**
  1463. * rtw_halmac_get_ori_h2c_size() - Original H2C MAX size
  1464. * @d: struct dvobj_priv*
  1465. * @size: H2C MAX size, unit is byte.
  1466. *
  1467. * Get original H2C MAX size(byte) from HALMAC.
  1468. *
  1469. * Return 0 for OK, otherwise fail.
  1470. */
  1471. int rtw_halmac_get_ori_h2c_size(struct dvobj_priv *d, u32 *size)
  1472. {
  1473. struct halmac_adapter *halmac;
  1474. struct halmac_api *api;
  1475. enum halmac_ret_status status;
  1476. u32 val = 0;
  1477. halmac = dvobj_to_halmac(d);
  1478. api = HALMAC_GET_API(halmac);
  1479. status = api->halmac_get_hw_value(halmac, HALMAC_HW_ORI_H2C_SIZE, &val);
  1480. if (status != HALMAC_RET_SUCCESS)
  1481. return -1;
  1482. *size = val;
  1483. return 0;
  1484. }
  1485. int rtw_halmac_get_oqt_size(struct dvobj_priv *d, u8 *size)
  1486. {
  1487. enum halmac_ret_status status;
  1488. struct halmac_adapter *halmac;
  1489. struct halmac_api *api;
  1490. u8 val;
  1491. if (!size)
  1492. return -1;
  1493. halmac = dvobj_to_halmac(d);
  1494. api = HALMAC_GET_API(halmac);
  1495. status = api->halmac_get_hw_value(halmac, HALMAC_HW_AC_OQT_SIZE, &val);
  1496. if (status != HALMAC_RET_SUCCESS)
  1497. return -1;
  1498. *size = val;
  1499. return 0;
  1500. }
  1501. int rtw_halmac_get_ac_queue_number(struct dvobj_priv *d, u8 *num)
  1502. {
  1503. enum halmac_ret_status status;
  1504. struct halmac_adapter *halmac;
  1505. struct halmac_api *api;
  1506. u8 val;
  1507. if (!num)
  1508. return -1;
  1509. halmac = dvobj_to_halmac(d);
  1510. api = HALMAC_GET_API(halmac);
  1511. status = api->halmac_get_hw_value(halmac, HALMAC_HW_AC_QUEUE_NUM, &val);
  1512. if (status != HALMAC_RET_SUCCESS)
  1513. return -1;
  1514. *num = val;
  1515. return 0;
  1516. }
  1517. /**
  1518. * rtw_halmac_get_mac_address() - Get MAC address of specific port
  1519. * @d: struct dvobj_priv*
  1520. * @hwport: port
  1521. * @addr: buffer for storing MAC address
  1522. *
  1523. * Get MAC address of specific port from HALMAC.
  1524. *
  1525. * Return 0 for OK, otherwise fail.
  1526. */
  1527. int rtw_halmac_get_mac_address(struct dvobj_priv *d, enum _hw_port hwport, u8 *addr)
  1528. {
  1529. struct halmac_adapter *halmac;
  1530. struct halmac_api *api;
  1531. enum halmac_portid port;
  1532. union halmac_wlan_addr hwa;
  1533. enum halmac_ret_status status;
  1534. int err = -1;
  1535. if (!addr)
  1536. goto out;
  1537. halmac = dvobj_to_halmac(d);
  1538. api = HALMAC_GET_API(halmac);
  1539. port = _hw_port_drv2halmac(hwport);
  1540. _rtw_memset(&hwa, 0, sizeof(hwa));
  1541. status = api->halmac_get_mac_addr(halmac, port, &hwa);
  1542. if (status != HALMAC_RET_SUCCESS)
  1543. goto out;
  1544. _rtw_memcpy(addr, hwa.addr, 6);
  1545. err = 0;
  1546. out:
  1547. return err;
  1548. }
  1549. /**
  1550. * rtw_halmac_get_network_type() - Get network type of specific port
  1551. * @d: struct dvobj_priv*
  1552. * @hwport: port
  1553. * @type: buffer to put network type (_HW_STATE_*)
  1554. *
  1555. * Get network type of specific port from HALMAC.
  1556. *
  1557. * Return 0 for OK, otherwise fail.
  1558. */
  1559. int rtw_halmac_get_network_type(struct dvobj_priv *d, enum _hw_port hwport, u8 *type)
  1560. {
  1561. #if 0
  1562. struct halmac_adapter *halmac;
  1563. struct halmac_api *api;
  1564. enum halmac_portid port;
  1565. enum halmac_network_type_select network;
  1566. enum halmac_ret_status status;
  1567. int err = -1;
  1568. halmac = dvobj_to_halmac(d);
  1569. api = HALMAC_GET_API(halmac);
  1570. port = _hw_port_drv2halmac(hwport);
  1571. network = HALMAC_NETWORK_UNDEFINE;
  1572. status = api->halmac_get_net_type(halmac, port, &network);
  1573. if (status != HALMAC_RET_SUCCESS)
  1574. goto out;
  1575. *type = _network_type_halmac2drv(network);
  1576. err = 0;
  1577. out:
  1578. return err;
  1579. #else
  1580. struct _ADAPTER *a;
  1581. enum halmac_portid port;
  1582. enum halmac_network_type_select network;
  1583. u32 val;
  1584. int err = -1;
  1585. a = dvobj_get_primary_adapter(d);
  1586. port = _hw_port_drv2halmac(hwport);
  1587. network = HALMAC_NETWORK_UNDEFINE;
  1588. switch (port) {
  1589. case HALMAC_PORTID0:
  1590. val = rtw_read32(a, REG_CR);
  1591. network = BIT_GET_NETYPE0(val);
  1592. break;
  1593. case HALMAC_PORTID1:
  1594. val = rtw_read32(a, REG_CR);
  1595. network = BIT_GET_NETYPE1(val);
  1596. break;
  1597. case HALMAC_PORTID2:
  1598. val = rtw_read32(a, REG_CR_EXT);
  1599. network = BIT_GET_NETYPE2(val);
  1600. break;
  1601. case HALMAC_PORTID3:
  1602. val = rtw_read32(a, REG_CR_EXT);
  1603. network = BIT_GET_NETYPE3(val);
  1604. break;
  1605. case HALMAC_PORTID4:
  1606. val = rtw_read32(a, REG_CR_EXT);
  1607. network = BIT_GET_NETYPE4(val);
  1608. break;
  1609. default:
  1610. goto out;
  1611. }
  1612. *type = _network_type_halmac2drv(network);
  1613. err = 0;
  1614. out:
  1615. return err;
  1616. #endif
  1617. }
  1618. /**
  1619. * rtw_halmac_get_bcn_ctrl() - Get beacon control setting of specific port
  1620. * @d: struct dvobj_priv*
  1621. * @hwport: port
  1622. * @bcn_ctrl: setting of beacon control
  1623. *
  1624. * Get beacon control setting of specific port from HALMAC.
  1625. *
  1626. * Return 0 for OK, otherwise fail.
  1627. */
  1628. int rtw_halmac_get_bcn_ctrl(struct dvobj_priv *d, enum _hw_port hwport,
  1629. struct rtw_halmac_bcn_ctrl *bcn_ctrl)
  1630. {
  1631. struct halmac_adapter *halmac;
  1632. struct halmac_api *api;
  1633. enum halmac_portid port;
  1634. struct halmac_bcn_ctrl ctrl;
  1635. enum halmac_ret_status status;
  1636. int err = -1;
  1637. halmac = dvobj_to_halmac(d);
  1638. api = HALMAC_GET_API(halmac);
  1639. port = _hw_port_drv2halmac(hwport);
  1640. _rtw_memset(&ctrl, 0, sizeof(ctrl));
  1641. status = api->halmac_rw_bcn_ctrl(halmac, port, 0, &ctrl);
  1642. if (status != HALMAC_RET_SUCCESS)
  1643. goto out;
  1644. _beacon_ctrl_halmac2drv(&ctrl, bcn_ctrl);
  1645. err = 0;
  1646. out:
  1647. return err;
  1648. }
  1649. /*
  1650. * Note:
  1651. * When this function return, the register REG_RCR may be changed.
  1652. */
  1653. int rtw_halmac_config_rx_info(struct dvobj_priv *d, enum halmac_drv_info info)
  1654. {
  1655. struct halmac_adapter *halmac;
  1656. struct halmac_api *api;
  1657. enum halmac_ret_status status;
  1658. int err = -1;
  1659. halmac = dvobj_to_halmac(d);
  1660. api = HALMAC_GET_API(halmac);
  1661. status = api->halmac_cfg_drv_info(halmac, info);
  1662. if (status != HALMAC_RET_SUCCESS)
  1663. goto out;
  1664. err = 0;
  1665. out:
  1666. return err;
  1667. }
  1668. /**
  1669. * rtw_halmac_set_max_dl_fw_size() - Set the MAX download firmware size
  1670. * @d: struct dvobj_priv*
  1671. * @size: the max download firmware size in one I/O
  1672. *
  1673. * Set the max download firmware size in one I/O.
  1674. * Please also consider the max size of the callback function "SEND_RSVD_PAGE"
  1675. * could accept, because download firmware would call "SEND_RSVD_PAGE" to send
  1676. * firmware to IC.
  1677. *
  1678. * If the value of "size" is not even, it would be rounded down to nearest
  1679. * even, and 0 and 1 are both invalid value.
  1680. *
  1681. * Return 0 for setting OK, otherwise fail.
  1682. */
  1683. int rtw_halmac_set_max_dl_fw_size(struct dvobj_priv *d, u32 size)
  1684. {
  1685. struct halmac_adapter *mac;
  1686. struct halmac_api *api;
  1687. enum halmac_ret_status status;
  1688. if (!size || (size == 1))
  1689. return -1;
  1690. mac = dvobj_to_halmac(d);
  1691. if (!mac) {
  1692. RTW_ERR("%s: HALMAC is not ready!!\n", __FUNCTION__);
  1693. return -1;
  1694. }
  1695. api = HALMAC_GET_API(mac);
  1696. size &= ~1; /* round down to even */
  1697. status = api->halmac_cfg_max_dl_size(mac, size);
  1698. if (status != HALMAC_RET_SUCCESS) {
  1699. RTW_WARN("%s: Fail to cfg_max_dl_size(%d), err=%d!!\n",
  1700. __FUNCTION__, size, status);
  1701. return -1;
  1702. }
  1703. return 0;
  1704. }
  1705. /**
  1706. * rtw_halmac_set_mac_address() - Set mac address of specific port
  1707. * @d: struct dvobj_priv*
  1708. * @hwport: port
  1709. * @addr: mac address
  1710. *
  1711. * Set self mac address of specific port to HALMAC.
  1712. *
  1713. * Return 0 for OK, otherwise fail.
  1714. */
  1715. int rtw_halmac_set_mac_address(struct dvobj_priv *d, enum _hw_port hwport, u8 *addr)
  1716. {
  1717. struct halmac_adapter *halmac;
  1718. struct halmac_api *api;
  1719. enum halmac_portid port;
  1720. union halmac_wlan_addr hwa;
  1721. enum halmac_ret_status status;
  1722. int err = -1;
  1723. halmac = dvobj_to_halmac(d);
  1724. api = HALMAC_GET_API(halmac);
  1725. port = _hw_port_drv2halmac(hwport);
  1726. _rtw_memset(&hwa, 0, sizeof(hwa));
  1727. _rtw_memcpy(hwa.addr, addr, 6);
  1728. status = api->halmac_cfg_mac_addr(halmac, port, &hwa);
  1729. if (status != HALMAC_RET_SUCCESS)
  1730. goto out;
  1731. err = 0;
  1732. out:
  1733. return err;
  1734. }
  1735. /**
  1736. * rtw_halmac_set_bssid() - Set BSSID of specific port
  1737. * @d: struct dvobj_priv*
  1738. * @hwport: port
  1739. * @addr: BSSID, mac address of AP
  1740. *
  1741. * Set BSSID of specific port to HALMAC.
  1742. *
  1743. * Return 0 for OK, otherwise fail.
  1744. */
  1745. int rtw_halmac_set_bssid(struct dvobj_priv *d, enum _hw_port hwport, u8 *addr)
  1746. {
  1747. struct halmac_adapter *halmac;
  1748. struct halmac_api *api;
  1749. enum halmac_portid port;
  1750. union halmac_wlan_addr hwa;
  1751. enum halmac_ret_status status;
  1752. int err = -1;
  1753. halmac = dvobj_to_halmac(d);
  1754. api = HALMAC_GET_API(halmac);
  1755. port = _hw_port_drv2halmac(hwport);
  1756. _rtw_memset(&hwa, 0, sizeof(hwa));
  1757. _rtw_memcpy(hwa.addr, addr, 6);
  1758. status = api->halmac_cfg_bssid(halmac, port, &hwa);
  1759. if (status != HALMAC_RET_SUCCESS)
  1760. goto out;
  1761. err = 0;
  1762. out:
  1763. return err;
  1764. }
  1765. /**
  1766. * rtw_halmac_set_tx_address() - Set transmitter address of specific port
  1767. * @d: struct dvobj_priv*
  1768. * @hwport: port
  1769. * @addr: transmitter address
  1770. *
  1771. * Set transmitter address of specific port to HALMAC.
  1772. *
  1773. * Return 0 for OK, otherwise fail.
  1774. */
  1775. int rtw_halmac_set_tx_address(struct dvobj_priv *d, enum _hw_port hwport, u8 *addr)
  1776. {
  1777. struct halmac_adapter *halmac;
  1778. struct halmac_api *api;
  1779. enum halmac_portid port;
  1780. union halmac_wlan_addr hwa;
  1781. enum halmac_ret_status status;
  1782. int err = -1;
  1783. halmac = dvobj_to_halmac(d);
  1784. api = HALMAC_GET_API(halmac);
  1785. port = _hw_port_drv2halmac(hwport);
  1786. _rtw_memset(&hwa, 0, sizeof(hwa));
  1787. _rtw_memcpy(hwa.addr, addr, 6);
  1788. status = api->halmac_cfg_transmitter_addr(halmac, port, &hwa);
  1789. if (status != HALMAC_RET_SUCCESS)
  1790. goto out;
  1791. err = 0;
  1792. out:
  1793. return err;
  1794. }
  1795. /**
  1796. * rtw_halmac_set_network_type() - Set network type of specific port
  1797. * @d: struct dvobj_priv*
  1798. * @hwport: port
  1799. * @type: network type (_HW_STATE_*)
  1800. *
  1801. * Set network type of specific port to HALMAC.
  1802. *
  1803. * Return 0 for OK, otherwise fail.
  1804. */
  1805. int rtw_halmac_set_network_type(struct dvobj_priv *d, enum _hw_port hwport, u8 type)
  1806. {
  1807. struct halmac_adapter *halmac;
  1808. struct halmac_api *api;
  1809. enum halmac_portid port;
  1810. enum halmac_network_type_select network;
  1811. enum halmac_ret_status status;
  1812. int err = -1;
  1813. halmac = dvobj_to_halmac(d);
  1814. api = HALMAC_GET_API(halmac);
  1815. port = _hw_port_drv2halmac(hwport);
  1816. network = _network_type_drv2halmac(type);
  1817. status = api->halmac_cfg_net_type(halmac, port, network);
  1818. if (status != HALMAC_RET_SUCCESS)
  1819. goto out;
  1820. err = 0;
  1821. out:
  1822. return err;
  1823. }
  1824. /**
  1825. * rtw_halmac_reset_tsf() - Reset TSF timer of specific port
  1826. * @d: struct dvobj_priv*
  1827. * @hwport: port
  1828. *
  1829. * Notice HALMAC to reset timing synchronization function(TSF) timer of
  1830. * specific port.
  1831. *
  1832. * Return 0 for OK, otherwise fail.
  1833. */
  1834. int rtw_halmac_reset_tsf(struct dvobj_priv *d, enum _hw_port hwport)
  1835. {
  1836. struct halmac_adapter *halmac;
  1837. struct halmac_api *api;
  1838. enum halmac_portid port;
  1839. enum halmac_ret_status status;
  1840. int err = -1;
  1841. halmac = dvobj_to_halmac(d);
  1842. api = HALMAC_GET_API(halmac);
  1843. port = _hw_port_drv2halmac(hwport);
  1844. status = api->halmac_cfg_tsf_rst(halmac, port);
  1845. if (status != HALMAC_RET_SUCCESS)
  1846. goto out;
  1847. err = 0;
  1848. out:
  1849. return err;
  1850. }
  1851. /**
  1852. * rtw_halmac_set_bcn_interval() - Set beacon interval of each port
  1853. * @d: struct dvobj_priv*
  1854. * @hwport: port
  1855. * @space: beacon interval, unit is ms
  1856. *
  1857. * Set beacon interval of specific port to HALMAC.
  1858. *
  1859. * Return 0 for OK, otherwise fail.
  1860. */
  1861. int rtw_halmac_set_bcn_interval(struct dvobj_priv *d, enum _hw_port hwport,
  1862. u32 interval)
  1863. {
  1864. struct halmac_adapter *halmac;
  1865. struct halmac_api *api;
  1866. enum halmac_portid port;
  1867. enum halmac_ret_status status;
  1868. int err = -1;
  1869. halmac = dvobj_to_halmac(d);
  1870. api = HALMAC_GET_API(halmac);
  1871. port = _hw_port_drv2halmac(hwport);
  1872. status = api->halmac_cfg_bcn_space(halmac, port, interval);
  1873. if (status != HALMAC_RET_SUCCESS)
  1874. goto out;
  1875. err = 0;
  1876. out:
  1877. return err;
  1878. }
  1879. /**
  1880. * rtw_halmac_set_bcn_ctrl() - Set beacon control setting of each port
  1881. * @d: struct dvobj_priv*
  1882. * @hwport: port
  1883. * @bcn_ctrl: setting of beacon control
  1884. *
  1885. * Set beacon control setting of specific port to HALMAC.
  1886. *
  1887. * Return 0 for OK, otherwise fail.
  1888. */
  1889. int rtw_halmac_set_bcn_ctrl(struct dvobj_priv *d, enum _hw_port hwport,
  1890. struct rtw_halmac_bcn_ctrl *bcn_ctrl)
  1891. {
  1892. struct halmac_adapter *halmac;
  1893. struct halmac_api *api;
  1894. enum halmac_portid port;
  1895. struct halmac_bcn_ctrl ctrl;
  1896. enum halmac_ret_status status;
  1897. int err = -1;
  1898. halmac = dvobj_to_halmac(d);
  1899. api = HALMAC_GET_API(halmac);
  1900. port = _hw_port_drv2halmac(hwport);
  1901. _rtw_memset(&ctrl, 0, sizeof(ctrl));
  1902. _beacon_ctrl_drv2halmac(bcn_ctrl, &ctrl);
  1903. status = api->halmac_rw_bcn_ctrl(halmac, port, 1, &ctrl);
  1904. if (status != HALMAC_RET_SUCCESS)
  1905. goto out;
  1906. err = 0;
  1907. out:
  1908. return err;
  1909. }
  1910. /**
  1911. * rtw_halmac_set_aid() - Set association identifier(AID) of specific port
  1912. * @d: struct dvobj_priv*
  1913. * @hwport: port
  1914. * @aid: Association identifier
  1915. *
  1916. * Set association identifier(AID) of specific port to HALMAC.
  1917. *
  1918. * Return 0 for OK, otherwise fail.
  1919. */
  1920. int rtw_halmac_set_aid(struct dvobj_priv *d, enum _hw_port hwport, u16 aid)
  1921. {
  1922. struct halmac_adapter *halmac;
  1923. struct halmac_api *api;
  1924. enum halmac_portid port;
  1925. enum halmac_ret_status status;
  1926. int err = -1;
  1927. halmac = dvobj_to_halmac(d);
  1928. api = HALMAC_GET_API(halmac);
  1929. port = _hw_port_drv2halmac(hwport);
  1930. #if 0
  1931. status = api->halmac_cfg_aid(halmac, port, aid);
  1932. if (status != HALMAC_RET_SUCCESS)
  1933. goto out;
  1934. #else
  1935. {
  1936. struct _ADAPTER *a;
  1937. u32 addr;
  1938. u16 val;
  1939. a = dvobj_get_primary_adapter(d);
  1940. switch (port) {
  1941. case 0:
  1942. addr = REG_BCN_PSR_RPT;
  1943. val = rtw_read16(a, addr);
  1944. val = BIT_SET_PS_AID_0(val, aid);
  1945. rtw_write16(a, addr, val);
  1946. break;
  1947. case 1:
  1948. addr = REG_BCN_PSR_RPT1;
  1949. val = rtw_read16(a, addr);
  1950. val = BIT_SET_PS_AID_1(val, aid);
  1951. rtw_write16(a, addr, val);
  1952. break;
  1953. case 2:
  1954. addr = REG_BCN_PSR_RPT2;
  1955. val = rtw_read16(a, addr);
  1956. val = BIT_SET_PS_AID_2(val, aid);
  1957. rtw_write16(a, addr, val);
  1958. break;
  1959. case 3:
  1960. addr = REG_BCN_PSR_RPT3;
  1961. val = rtw_read16(a, addr);
  1962. val = BIT_SET_PS_AID_3(val, aid);
  1963. rtw_write16(a, addr, val);
  1964. break;
  1965. case 4:
  1966. addr = REG_BCN_PSR_RPT4;
  1967. val = rtw_read16(a, addr);
  1968. val = BIT_SET_PS_AID_4(val, aid);
  1969. rtw_write16(a, addr, val);
  1970. break;
  1971. default:
  1972. goto out;
  1973. }
  1974. }
  1975. #endif
  1976. err = 0;
  1977. out:
  1978. return err;
  1979. }
  1980. int rtw_halmac_set_bandwidth(struct dvobj_priv *d, u8 channel, u8 pri_ch_idx, u8 bw)
  1981. {
  1982. struct halmac_adapter *mac;
  1983. struct halmac_api *api;
  1984. enum halmac_ret_status status;
  1985. mac = dvobj_to_halmac(d);
  1986. api = HALMAC_GET_API(mac);
  1987. status = api->halmac_cfg_ch_bw(mac, channel, pri_ch_idx, bw);
  1988. if (HALMAC_RET_SUCCESS != status)
  1989. return -1;
  1990. return 0;
  1991. }
  1992. /**
  1993. * rtw_halmac_set_edca() - config edca parameter
  1994. * @d: struct dvobj_priv*
  1995. * @queue: XMIT_[VO/VI/BE/BK]_QUEUE
  1996. * @aifs: Arbitration inter-frame space(AIFS)
  1997. * @cw: Contention window(CW)
  1998. * @txop: MAX Transmit Opportunity(TXOP)
  1999. *
  2000. * Return: 0 if process OK, otherwise -1.
  2001. */
  2002. int rtw_halmac_set_edca(struct dvobj_priv *d, u8 queue, u8 aifs, u8 cw, u16 txop)
  2003. {
  2004. struct halmac_adapter *mac;
  2005. struct halmac_api *api;
  2006. enum halmac_acq_id ac;
  2007. struct halmac_edca_para edca;
  2008. enum halmac_ret_status status;
  2009. mac = dvobj_to_halmac(d);
  2010. api = HALMAC_GET_API(mac);
  2011. switch (queue) {
  2012. case XMIT_VO_QUEUE:
  2013. ac = HALMAC_ACQ_ID_VO;
  2014. break;
  2015. case XMIT_VI_QUEUE:
  2016. ac = HALMAC_ACQ_ID_VI;
  2017. break;
  2018. case XMIT_BE_QUEUE:
  2019. ac = HALMAC_ACQ_ID_BE;
  2020. break;
  2021. case XMIT_BK_QUEUE:
  2022. ac = HALMAC_ACQ_ID_BK;
  2023. break;
  2024. default:
  2025. return -1;
  2026. }
  2027. edca.aifs = aifs;
  2028. edca.cw = cw;
  2029. edca.txop_limit = txop;
  2030. status = api->halmac_cfg_edca_para(mac, ac, &edca);
  2031. if (status != HALMAC_RET_SUCCESS)
  2032. return -1;
  2033. return 0;
  2034. }
  2035. /**
  2036. * rtw_halmac_set_rts_full_bw() - Send RTS to all covered channels
  2037. * @d: struct dvobj_priv*
  2038. * @enable: _TRUE(enable), _FALSE(disable)
  2039. *
  2040. * Hradware will duplicate RTS packet to all channels which are covered in used
  2041. * bandwidth.
  2042. *
  2043. * Return 0 if process OK, otherwise -1.
  2044. */
  2045. int rtw_halmac_set_rts_full_bw(struct dvobj_priv *d, u8 enable)
  2046. {
  2047. struct halmac_adapter *mac;
  2048. struct halmac_api *api;
  2049. enum halmac_ret_status status;
  2050. u8 full;
  2051. mac = dvobj_to_halmac(d);
  2052. api = HALMAC_GET_API(mac);
  2053. full = (enable == _TRUE) ? 1 : 0;
  2054. status = api->halmac_set_hw_value(mac, HALMAC_HW_RTS_FULL_BW, &full);
  2055. if (HALMAC_RET_SUCCESS != status)
  2056. return -1;
  2057. return 0;
  2058. }
  2059. #ifdef RTW_HALMAC_DBG_POWER_SWITCH
  2060. static void _dump_mac_reg(struct dvobj_priv *d, u32 start, u32 end)
  2061. {
  2062. struct _ADAPTER *adapter;
  2063. int i, j = 1;
  2064. adapter = dvobj_get_primary_adapter(d);
  2065. for (i = start; i < end; i += 4) {
  2066. if (j % 4 == 1)
  2067. RTW_PRINT("0x%04x", i);
  2068. _RTW_PRINT(" 0x%08x ", rtw_read32(adapter, i));
  2069. if ((j++) % 4 == 0)
  2070. _RTW_PRINT("\n");
  2071. }
  2072. }
  2073. void dump_dbg_val(struct _ADAPTER *a, u32 reg)
  2074. {
  2075. u32 v32;
  2076. rtw_write8(a, 0x3A, reg);
  2077. v32 = rtw_read32(a, 0xC0);
  2078. RTW_PRINT("0x3A = %02x, 0xC0 = 0x%08x\n",reg, v32);
  2079. }
  2080. #ifdef CONFIG_PCI_HCI
  2081. static void _dump_pcie_cfg_space(struct dvobj_priv *d)
  2082. {
  2083. struct _ADAPTER *padapter = dvobj_get_primary_adapter(d);
  2084. struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
  2085. struct pci_dev *pdev = pdvobjpriv->ppcidev;
  2086. struct pci_dev *bridge_pdev = pdev->bus->self;
  2087. u32 tmp[4] = { 0 };
  2088. u32 i, j;
  2089. RTW_PRINT("\n***** PCI Device Configuration Space *****\n\n");
  2090. for(i = 0; i < 0x100; i += 0x10)
  2091. {
  2092. for (j = 0 ; j < 4 ; j++)
  2093. pci_read_config_dword(pdev, i + j * 4, tmp+j);
  2094. RTW_PRINT("%03x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  2095. i, tmp[0] & 0xFF, (tmp[0] >> 8) & 0xFF, (tmp[0] >> 16) & 0xFF, (tmp[0] >> 24) & 0xFF,
  2096. tmp[1] & 0xFF, (tmp[1] >> 8) & 0xFF, (tmp[1] >> 16) & 0xFF, (tmp[1] >> 24) & 0xFF,
  2097. tmp[2] & 0xFF, (tmp[2] >> 8) & 0xFF, (tmp[2] >> 16) & 0xFF, (tmp[2] >> 24) & 0xFF,
  2098. tmp[3] & 0xFF, (tmp[3] >> 8) & 0xFF, (tmp[3] >> 16) & 0xFF, (tmp[3] >> 24) & 0xFF);
  2099. }
  2100. RTW_PRINT("\n***** PCI Host Device Configuration Space*****\n\n");
  2101. for(i = 0; i < 0x100; i += 0x10)
  2102. {
  2103. for (j = 0 ; j < 4 ; j++)
  2104. pci_read_config_dword(bridge_pdev, i + j * 4, tmp+j);
  2105. RTW_PRINT("%03x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  2106. i, tmp[0] & 0xFF, (tmp[0] >> 8) & 0xFF, (tmp[0] >> 16) & 0xFF, (tmp[0] >> 24) & 0xFF,
  2107. tmp[1] & 0xFF, (tmp[1] >> 8) & 0xFF, (tmp[1] >> 16) & 0xFF, (tmp[1] >> 24) & 0xFF,
  2108. tmp[2] & 0xFF, (tmp[2] >> 8) & 0xFF, (tmp[2] >> 16) & 0xFF, (tmp[2] >> 24) & 0xFF,
  2109. tmp[3] & 0xFF, (tmp[3] >> 8) & 0xFF, (tmp[3] >> 16) & 0xFF, (tmp[3] >> 24) & 0xFF);
  2110. }
  2111. }
  2112. #endif
  2113. static void _dump_mac_reg_for_power_switch(struct dvobj_priv *d,
  2114. const char* caller, char* desc)
  2115. {
  2116. struct _ADAPTER *a;
  2117. u8 v8;
  2118. RTW_PRINT("%s: %s\n", caller, desc);
  2119. RTW_PRINT("======= MAC REG =======\n");
  2120. /* page 0/1 */
  2121. _dump_mac_reg(d, 0x0, 0x200);
  2122. _dump_mac_reg(d, 0x300, 0x400); /* also dump page 3 */
  2123. /* dump debug register */
  2124. a = dvobj_get_primary_adapter(d);
  2125. #ifdef CONFIG_PCI_HCI
  2126. _dump_pcie_cfg_space(d);
  2127. v8 = rtw_read8(a, 0xF6) | 0x01;
  2128. rtw_write8(a, 0xF6, v8);
  2129. RTW_PRINT("0xF6 = %02x\n", v8);
  2130. dump_dbg_val(a, 0x63);
  2131. dump_dbg_val(a, 0x64);
  2132. dump_dbg_val(a, 0x68);
  2133. dump_dbg_val(a, 0x69);
  2134. dump_dbg_val(a, 0x6a);
  2135. dump_dbg_val(a, 0x6b);
  2136. dump_dbg_val(a, 0x71);
  2137. dump_dbg_val(a, 0x72);
  2138. #endif
  2139. }
  2140. static enum halmac_ret_status _power_switch(struct halmac_adapter *halmac,
  2141. struct halmac_api *api,
  2142. enum halmac_mac_power pwr)
  2143. {
  2144. enum halmac_ret_status status;
  2145. char desc[80] = {0};
  2146. rtw_sprintf(desc, 80, "before calling power %s",
  2147. (pwr==HALMAC_MAC_POWER_ON)?"on":"off");
  2148. _dump_mac_reg_for_power_switch((struct dvobj_priv *)halmac->drv_adapter,
  2149. __FUNCTION__, desc);
  2150. status = api->halmac_mac_power_switch(halmac, pwr);
  2151. RTW_PRINT("%s: status=%d\n", __FUNCTION__, status);
  2152. rtw_sprintf(desc, 80, "after calling power %s",
  2153. (pwr==HALMAC_MAC_POWER_ON)?"on":"off");
  2154. _dump_mac_reg_for_power_switch((struct dvobj_priv *)halmac->drv_adapter,
  2155. __FUNCTION__, desc);
  2156. return status;
  2157. }
  2158. #else /* !RTW_HALMAC_DBG_POWER_SWITCH */
  2159. #define _power_switch(mac, api, pwr) (api)->halmac_mac_power_switch(mac, pwr)
  2160. #endif /* !RTW_HALMAC_DBG_POWER_SWITCH */
  2161. /*
  2162. * Description:
  2163. * Power on device hardware.
  2164. * [Notice!] If device's power state is on before,
  2165. * it would be power off first and turn on power again.
  2166. *
  2167. * Return:
  2168. * 0 power on success
  2169. * -1 power on fail
  2170. * -2 power state unchange
  2171. */
  2172. int rtw_halmac_poweron(struct dvobj_priv *d)
  2173. {
  2174. struct halmac_adapter *halmac;
  2175. struct halmac_api *api;
  2176. enum halmac_ret_status status;
  2177. int err = -1;
  2178. #if defined(CONFIG_PCI_HCI) && defined(CONFIG_RTL8822B)
  2179. struct _ADAPTER *a;
  2180. u8 v8;
  2181. u32 addr;
  2182. a = dvobj_get_primary_adapter(d);
  2183. #endif
  2184. halmac = dvobj_to_halmac(d);
  2185. if (!halmac)
  2186. goto out;
  2187. api = HALMAC_GET_API(halmac);
  2188. status = api->halmac_pre_init_system_cfg(halmac);
  2189. if (status != HALMAC_RET_SUCCESS)
  2190. goto out;
  2191. #ifdef CONFIG_SDIO_HCI
  2192. status = api->halmac_sdio_cmd53_4byte(halmac, HALMAC_SDIO_CMD53_4BYTE_MODE_RW);
  2193. if (status != HALMAC_RET_SUCCESS)
  2194. goto out;
  2195. #endif /* CONFIG_SDIO_HCI */
  2196. #if defined(CONFIG_PCI_HCI) && defined(CONFIG_RTL8822B)
  2197. addr = 0x3F3;
  2198. v8 = rtw_read8(a, addr);
  2199. RTW_PRINT("%s: 0x%X = 0x%02x\n", __FUNCTION__, addr, v8);
  2200. /* are we in pcie debug mode? */
  2201. if (!(v8 & BIT(2))) {
  2202. RTW_PRINT("%s: Enable pcie debug mode\n", __FUNCTION__);
  2203. v8 |= BIT(2);
  2204. v8 = rtw_write8(a, addr, v8);
  2205. }
  2206. #endif
  2207. status = _power_switch(halmac, api, HALMAC_MAC_POWER_ON);
  2208. if (HALMAC_RET_PWR_UNCHANGE == status) {
  2209. #if defined(CONFIG_PCI_HCI) && defined(CONFIG_RTL8822B)
  2210. addr = 0x3F3;
  2211. v8 = rtw_read8(a, addr);
  2212. RTW_PRINT("%s: 0x%X = 0x%02x\n", __FUNCTION__, addr, v8);
  2213. /* are we in pcie debug mode? */
  2214. if (!(v8 & BIT(2))) {
  2215. RTW_PRINT("%s: Enable pcie debug mode\n", __FUNCTION__);
  2216. v8 |= BIT(2);
  2217. v8 = rtw_write8(a, addr, v8);
  2218. } else if (v8 & BIT(0)) {
  2219. /* DMA stuck */
  2220. addr = 0x1350;
  2221. v8 = rtw_read8(a, addr);
  2222. RTW_PRINT("%s: 0x%X = 0x%02x\n", __FUNCTION__, addr, v8);
  2223. RTW_PRINT("%s: recover DMA stuck\n", __FUNCTION__);
  2224. v8 |= BIT(6);
  2225. v8 = rtw_write8(a, addr, v8);
  2226. RTW_PRINT("%s: 0x%X = 0x%02x\n", __FUNCTION__, addr, v8);
  2227. }
  2228. #endif
  2229. /*
  2230. * Work around for warm reboot but device not power off,
  2231. * but it would also fall into this case when auto power on is enabled.
  2232. */
  2233. _power_switch(halmac, api, HALMAC_MAC_POWER_OFF);
  2234. status = _power_switch(halmac, api, HALMAC_MAC_POWER_ON);
  2235. RTW_WARN("%s: Power state abnormal, try to recover...%s\n",
  2236. __FUNCTION__, (HALMAC_RET_SUCCESS == status)?"OK":"FAIL!");
  2237. }
  2238. if (HALMAC_RET_SUCCESS != status) {
  2239. if (HALMAC_RET_PWR_UNCHANGE == status)
  2240. err = -2;
  2241. goto out;
  2242. }
  2243. status = api->halmac_init_system_cfg(halmac);
  2244. if (status != HALMAC_RET_SUCCESS)
  2245. goto out;
  2246. err = 0;
  2247. out:
  2248. return err;
  2249. }
  2250. /*
  2251. * Description:
  2252. * Power off device hardware.
  2253. *
  2254. * Return:
  2255. * 0 Power off success
  2256. * -1 Power off fail
  2257. */
  2258. int rtw_halmac_poweroff(struct dvobj_priv *d)
  2259. {
  2260. struct halmac_adapter *halmac;
  2261. struct halmac_api *api;
  2262. enum halmac_ret_status status;
  2263. int err = -1;
  2264. halmac = dvobj_to_halmac(d);
  2265. if (!halmac)
  2266. goto out;
  2267. api = HALMAC_GET_API(halmac);
  2268. status = _power_switch(halmac, api, HALMAC_MAC_POWER_OFF);
  2269. if ((HALMAC_RET_SUCCESS != status)
  2270. && (HALMAC_RET_PWR_UNCHANGE != status))
  2271. goto out;
  2272. err = 0;
  2273. out:
  2274. return err;
  2275. }
  2276. #ifdef CONFIG_SUPPORT_TRX_SHARED
  2277. static inline enum halmac_rx_fifo_expanding_mode _trx_share_mode_drv2halmac(u8 trx_share_mode)
  2278. {
  2279. if (0 == trx_share_mode)
  2280. return HALMAC_RX_FIFO_EXPANDING_MODE_DISABLE;
  2281. else if (1 == trx_share_mode)
  2282. return HALMAC_RX_FIFO_EXPANDING_MODE_1_BLOCK;
  2283. else if (2 == trx_share_mode)
  2284. return HALMAC_RX_FIFO_EXPANDING_MODE_2_BLOCK;
  2285. else if (3 == trx_share_mode)
  2286. return HALMAC_RX_FIFO_EXPANDING_MODE_3_BLOCK;
  2287. else
  2288. return HALMAC_RX_FIFO_EXPANDING_MODE_DISABLE;
  2289. }
  2290. static enum halmac_rx_fifo_expanding_mode _rtw_get_trx_share_mode(struct _ADAPTER *adapter)
  2291. {
  2292. struct registry_priv *registry_par = &adapter->registrypriv;
  2293. return _trx_share_mode_drv2halmac(registry_par->trx_share_mode);
  2294. }
  2295. void dump_trx_share_mode(void *sel, struct _ADAPTER *adapter)
  2296. {
  2297. struct registry_priv *registry_par = &adapter->registrypriv;
  2298. u8 mode = _trx_share_mode_drv2halmac(registry_par->trx_share_mode);
  2299. if (HALMAC_RX_FIFO_EXPANDING_MODE_1_BLOCK == mode)
  2300. RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "RX_FIFO_EXPANDING_MODE_1");
  2301. else if (HALMAC_RX_FIFO_EXPANDING_MODE_2_BLOCK == mode)
  2302. RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "RX_FIFO_EXPANDING_MODE_2");
  2303. else if (HALMAC_RX_FIFO_EXPANDING_MODE_3_BLOCK == mode)
  2304. RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "RX_FIFO_EXPANDING_MODE_3");
  2305. else
  2306. RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "DISABLE");
  2307. }
  2308. #endif
  2309. static enum halmac_drv_rsvd_pg_num _rsvd_page_num_drv2halmac(u16 num)
  2310. {
  2311. if (num <= 8)
  2312. return HALMAC_RSVD_PG_NUM8;
  2313. if (num <= 16)
  2314. return HALMAC_RSVD_PG_NUM16;
  2315. if (num <= 24)
  2316. return HALMAC_RSVD_PG_NUM24;
  2317. if (num <= 32)
  2318. return HALMAC_RSVD_PG_NUM32;
  2319. if (num <= 64)
  2320. return HALMAC_RSVD_PG_NUM64;
  2321. if (num <= 128)
  2322. return HALMAC_RSVD_PG_NUM128;
  2323. if (num > 256)
  2324. RTW_WARN("%s: Fail to allocate RSVD page(%d)!!"
  2325. " The MAX RSVD page number is 256...\n",
  2326. __FUNCTION__, num);
  2327. return HALMAC_RSVD_PG_NUM256;
  2328. }
  2329. static u16 _rsvd_page_num_halmac2drv(enum halmac_drv_rsvd_pg_num rsvd_page_number)
  2330. {
  2331. u16 num = 0;
  2332. switch (rsvd_page_number) {
  2333. case HALMAC_RSVD_PG_NUM8:
  2334. num = 8;
  2335. break;
  2336. case HALMAC_RSVD_PG_NUM16:
  2337. num = 16;
  2338. break;
  2339. case HALMAC_RSVD_PG_NUM24:
  2340. num = 24;
  2341. break;
  2342. case HALMAC_RSVD_PG_NUM32:
  2343. num = 32;
  2344. break;
  2345. case HALMAC_RSVD_PG_NUM64:
  2346. num = 64;
  2347. break;
  2348. case HALMAC_RSVD_PG_NUM128:
  2349. num = 128;
  2350. break;
  2351. case HALMAC_RSVD_PG_NUM256:
  2352. num = 256;
  2353. break;
  2354. }
  2355. return num;
  2356. }
  2357. static enum halmac_trx_mode _choose_trx_mode(struct dvobj_priv *d)
  2358. {
  2359. PADAPTER p;
  2360. p = dvobj_get_primary_adapter(d);
  2361. if (p->registrypriv.wifi_spec)
  2362. return HALMAC_TRX_MODE_WMM;
  2363. #ifdef CONFIG_SUPPORT_TRX_SHARED
  2364. if (_rtw_get_trx_share_mode(p))
  2365. return HALMAC_TRX_MODE_TRXSHARE;
  2366. #endif
  2367. return HALMAC_TRX_MODE_NORMAL;
  2368. }
  2369. static inline enum halmac_rf_type _rf_type_drv2halmac(enum rf_type rf_drv)
  2370. {
  2371. enum halmac_rf_type rf_mac;
  2372. switch (rf_drv) {
  2373. case RF_1T1R:
  2374. rf_mac = HALMAC_RF_1T1R;
  2375. break;
  2376. case RF_1T2R:
  2377. rf_mac = HALMAC_RF_1T2R;
  2378. break;
  2379. case RF_2T2R:
  2380. rf_mac = HALMAC_RF_2T2R;
  2381. break;
  2382. case RF_2T3R:
  2383. rf_mac = HALMAC_RF_2T3R;
  2384. break;
  2385. case RF_2T4R:
  2386. rf_mac = HALMAC_RF_2T4R;
  2387. break;
  2388. case RF_3T3R:
  2389. rf_mac = HALMAC_RF_3T3R;
  2390. break;
  2391. case RF_3T4R:
  2392. rf_mac = HALMAC_RF_3T4R;
  2393. break;
  2394. case RF_4T4R:
  2395. rf_mac = HALMAC_RF_4T4R;
  2396. break;
  2397. default:
  2398. rf_mac = HALMAC_RF_MAX_TYPE;
  2399. RTW_ERR("%s: Invalid RF type(0x%x)!\n", __FUNCTION__, rf_drv);
  2400. break;
  2401. }
  2402. return rf_mac;
  2403. }
  2404. static inline enum rf_type _rf_type_halmac2drv(enum halmac_rf_type rf_mac)
  2405. {
  2406. enum rf_type rf_drv;
  2407. switch (rf_mac) {
  2408. case HALMAC_RF_1T2R:
  2409. rf_drv = RF_1T2R;
  2410. break;
  2411. case HALMAC_RF_2T4R:
  2412. rf_drv = RF_2T4R;
  2413. break;
  2414. case HALMAC_RF_2T2R:
  2415. case HALMAC_RF_2T2R_GREEN:
  2416. rf_drv = RF_2T2R;
  2417. break;
  2418. case HALMAC_RF_2T3R:
  2419. rf_drv = RF_2T3R;
  2420. break;
  2421. case HALMAC_RF_1T1R:
  2422. rf_drv = RF_1T1R;
  2423. break;
  2424. case HALMAC_RF_3T3R:
  2425. rf_drv = RF_3T3R;
  2426. break;
  2427. case HALMAC_RF_3T4R:
  2428. rf_drv = RF_3T4R;
  2429. break;
  2430. case HALMAC_RF_4T4R:
  2431. rf_drv = RF_4T4R;
  2432. break;
  2433. default:
  2434. rf_drv = RF_TYPE_MAX;
  2435. RTW_ERR("%s: Invalid RF type(0x%x)!\n", __FUNCTION__, rf_mac);
  2436. break;
  2437. }
  2438. return rf_drv;
  2439. }
  2440. static enum odm_cut_version _cut_version_drv2phydm(
  2441. enum tag_HAL_Cut_Version_Definition cut_drv)
  2442. {
  2443. enum odm_cut_version cut_phydm = ODM_CUT_A;
  2444. u32 diff;
  2445. if (cut_drv > K_CUT_VERSION)
  2446. RTW_WARN("%s: unknown cut_ver=%d !!\n", __FUNCTION__, cut_drv);
  2447. diff = cut_drv - A_CUT_VERSION;
  2448. cut_phydm += diff;
  2449. return cut_phydm;
  2450. }
  2451. static int _send_general_info_by_reg(struct dvobj_priv *d,
  2452. struct halmac_general_info *info)
  2453. {
  2454. struct _ADAPTER *a;
  2455. struct hal_com_data *hal;
  2456. enum tag_HAL_Cut_Version_Definition cut_drv;
  2457. enum rf_type rftype;
  2458. enum odm_cut_version cut_phydm;
  2459. u8 h2c[RTW_HALMAC_H2C_MAX_SIZE] = {0};
  2460. a = dvobj_get_primary_adapter(d);
  2461. hal = GET_HAL_DATA(a);
  2462. rftype = _rf_type_halmac2drv(info->rf_type);
  2463. cut_drv = GET_CVID_CUT_VERSION(hal->version_id);
  2464. cut_phydm = _cut_version_drv2phydm(cut_drv);
  2465. #define CLASS_GENERAL_INFO_REG 0x02
  2466. #define CMD_ID_GENERAL_INFO_REG 0x0C
  2467. #define GENERAL_INFO_REG_SET_CMD_ID(buf, v) SET_BITS_TO_LE_4BYTE(buf, 0, 5, v)
  2468. #define GENERAL_INFO_REG_SET_CLASS(buf, v) SET_BITS_TO_LE_4BYTE(buf, 5, 3, v)
  2469. #define GENERAL_INFO_REG_SET_RFE_TYPE(buf, v) SET_BITS_TO_LE_4BYTE(buf, 8, 8, v)
  2470. #define GENERAL_INFO_REG_SET_RF_TYPE(buf, v) SET_BITS_TO_LE_4BYTE(buf, 16, 8, v)
  2471. #define GENERAL_INFO_REG_SET_CUT_VERSION(buf, v) SET_BITS_TO_LE_4BYTE(buf, 24, 8, v)
  2472. #define GENERAL_INFO_REG_SET_RX_ANT_STATUS(buf, v) SET_BITS_TO_LE_1BYTE(buf+4, 0, 4, v)
  2473. #define GENERAL_INFO_REG_SET_TX_ANT_STATUS(buf, v) SET_BITS_TO_LE_1BYTE(buf+4, 4, 4, v)
  2474. GENERAL_INFO_REG_SET_CMD_ID(h2c, CMD_ID_GENERAL_INFO_REG);
  2475. GENERAL_INFO_REG_SET_CLASS(h2c, CLASS_GENERAL_INFO_REG);
  2476. GENERAL_INFO_REG_SET_RFE_TYPE(h2c, info->rfe_type);
  2477. GENERAL_INFO_REG_SET_RF_TYPE(h2c, rftype);
  2478. GENERAL_INFO_REG_SET_CUT_VERSION(h2c, cut_phydm);
  2479. GENERAL_INFO_REG_SET_RX_ANT_STATUS(h2c, info->rx_ant_status);
  2480. GENERAL_INFO_REG_SET_TX_ANT_STATUS(h2c, info->tx_ant_status);
  2481. return rtw_halmac_send_h2c(d, h2c);
  2482. }
  2483. static int _send_general_info(struct dvobj_priv *d)
  2484. {
  2485. struct _ADAPTER *adapter;
  2486. struct hal_com_data *hal;
  2487. struct halmac_adapter *halmac;
  2488. struct halmac_api *api;
  2489. struct halmac_general_info info;
  2490. enum halmac_ret_status status;
  2491. enum rf_type rf = RF_1T1R;
  2492. enum bb_path txpath = BB_PATH_A;
  2493. enum bb_path rxpath = BB_PATH_A;
  2494. int err;
  2495. adapter = dvobj_get_primary_adapter(d);
  2496. hal = GET_HAL_DATA(adapter);
  2497. halmac = dvobj_to_halmac(d);
  2498. if (!halmac)
  2499. return -1;
  2500. api = HALMAC_GET_API(halmac);
  2501. _rtw_memset(&info, 0, sizeof(info));
  2502. info.rfe_type = (u8)hal->rfe_type;
  2503. rtw_hal_get_trx_path(d, &rf, &txpath, &rxpath);
  2504. info.rf_type = _rf_type_drv2halmac(rf);
  2505. info.tx_ant_status = (u8)txpath;
  2506. info.rx_ant_status = (u8)rxpath;
  2507. info.ext_pa = 0; /* 2.4G or 5G? format not known */
  2508. info.package_type = hal->PackageType;
  2509. info.mp_mode = adapter->registrypriv.mp_mode;
  2510. status = api->halmac_send_general_info(halmac, &info);
  2511. switch (status) {
  2512. case HALMAC_RET_SUCCESS:
  2513. break;
  2514. case HALMAC_RET_NO_DLFW:
  2515. RTW_WARN("%s: halmac_send_general_info() fail because fw not dl!\n",
  2516. __FUNCTION__);
  2517. /* go through */
  2518. default:
  2519. return -1;
  2520. }
  2521. err = _send_general_info_by_reg(d, &info);
  2522. if (err) {
  2523. RTW_ERR("%s: Fail to send general info by register!\n",
  2524. __FUNCTION__);
  2525. return -1;
  2526. }
  2527. return 0;
  2528. }
  2529. static int _cfg_drv_rsvd_pg_num(struct dvobj_priv *d)
  2530. {
  2531. struct _ADAPTER *a;
  2532. struct hal_com_data *hal;
  2533. struct halmac_adapter *halmac;
  2534. struct halmac_api *api;
  2535. enum halmac_drv_rsvd_pg_num rsvd_page_number;
  2536. enum halmac_ret_status status;
  2537. u16 drv_rsvd_num;
  2538. int ret = 0;
  2539. a = dvobj_get_primary_adapter(d);
  2540. hal = GET_HAL_DATA(a);
  2541. halmac = dvobj_to_halmac(d);
  2542. api = HALMAC_GET_API(halmac);
  2543. drv_rsvd_num = rtw_hal_get_rsvd_page_num(a);
  2544. rsvd_page_number = _rsvd_page_num_drv2halmac(drv_rsvd_num);
  2545. status = api->halmac_cfg_drv_rsvd_pg_num(halmac, rsvd_page_number);
  2546. if (status != HALMAC_RET_SUCCESS) {
  2547. ret = -1;
  2548. goto exit;
  2549. }
  2550. hal->drv_rsvd_page_number = _rsvd_page_num_halmac2drv(rsvd_page_number);
  2551. exit:
  2552. #ifndef DBG_RSVD_PAGE_CFG
  2553. if (drv_rsvd_num != _rsvd_page_num_halmac2drv(rsvd_page_number))
  2554. #endif
  2555. RTW_INFO("%s: request %d pages => halmac %d pages %s\n"
  2556. , __FUNCTION__, drv_rsvd_num, _rsvd_page_num_halmac2drv(rsvd_page_number)
  2557. , ret ? "fail" : "success");
  2558. return ret;
  2559. }
  2560. static void _debug_dlfw_fail(struct dvobj_priv *d)
  2561. {
  2562. struct _ADAPTER *a;
  2563. u32 addr;
  2564. u32 v32, i, n;
  2565. a = dvobj_get_primary_adapter(d);
  2566. /* read 0x80[15:0], 0x10F8[31:0] once */
  2567. addr = 0x80;
  2568. v32 = rtw_read16(a, addr);
  2569. RTW_PRINT("%s: 0x%X = 0x%04x\n", __FUNCTION__, addr, v32);
  2570. addr = 0x10F8;
  2571. v32 = rtw_read32(a, addr);
  2572. RTW_PRINT("%s: 0x%X = 0x%08x\n", __FUNCTION__, addr, v32);
  2573. /* read 0x10FC[31:0], 5 times */
  2574. addr = 0x10FC;
  2575. n = 5;
  2576. for (i = 0; i < n; i++) {
  2577. v32 = rtw_read32(a, addr);
  2578. RTW_PRINT("%s: 0x%X = 0x%08x (%u/%u)\n",
  2579. __FUNCTION__, addr, v32, i, n);
  2580. }
  2581. /*
  2582. * write 0x3A[7:0]=0x28 and 0xF6[7:0]=0x01
  2583. * and then read 0xC0[31:0] 5 times
  2584. */
  2585. addr = 0x3A;
  2586. v32 = 0x28;
  2587. rtw_write8(a, addr, (u8)v32);
  2588. v32 = rtw_read8(a, addr);
  2589. RTW_PRINT("%s: 0x%X = 0x%02x\n", __FUNCTION__, addr, v32);
  2590. addr = 0xF6;
  2591. v32 = 0x1;
  2592. rtw_write8(a, addr, (u8)v32);
  2593. v32 = rtw_read8(a, addr);
  2594. RTW_PRINT("%s: 0x%X = 0x%02x\n", __FUNCTION__, addr, v32);
  2595. addr = 0xC0;
  2596. n = 5;
  2597. for (i = 0; i < n; i++) {
  2598. v32 = rtw_read32(a, addr);
  2599. RTW_PRINT("%s: 0x%X = 0x%08x (%u/%u)\n",
  2600. __FUNCTION__, addr, v32, i, n);
  2601. }
  2602. mac_reg_dump(NULL, a);
  2603. #ifdef CONFIG_SDIO_HCI
  2604. RTW_PRINT("======= SDIO Local REG =======\n");
  2605. sdio_local_reg_dump(NULL, a);
  2606. RTW_PRINT("======= SDIO CCCR REG =======\n");
  2607. sd_f0_reg_dump(NULL, a);
  2608. #endif /* CONFIG_SDIO_HCI */
  2609. /* read 0x80 after 10 secs */
  2610. rtw_msleep_os(10000);
  2611. addr = 0x80;
  2612. v32 = rtw_read16(a, addr);
  2613. RTW_PRINT("%s: 0x%X = 0x%04x (after 10 secs)\n",
  2614. __FUNCTION__, addr, v32);
  2615. }
  2616. static enum halmac_ret_status _enter_cpu_sleep_mode(struct dvobj_priv *d)
  2617. {
  2618. struct hal_com_data *hal;
  2619. struct halmac_adapter *mac;
  2620. struct halmac_api *api;
  2621. hal = GET_HAL_DATA(dvobj_get_primary_adapter(d));
  2622. mac = dvobj_to_halmac(d);
  2623. api = HALMAC_GET_API(mac);
  2624. #ifdef CONFIG_RTL8822B
  2625. /* Support after firmware version 21 */
  2626. if (hal->firmware_version < 21)
  2627. return HALMAC_RET_NOT_SUPPORT;
  2628. #elif defined(CONFIG_RTL8821C)
  2629. /* Support after firmware version 13.6 or 16 */
  2630. if (hal->firmware_version == 13) {
  2631. if (hal->firmware_sub_version < 6)
  2632. return HALMAC_RET_NOT_SUPPORT;
  2633. } else if (hal->firmware_version < 16) {
  2634. return HALMAC_RET_NOT_SUPPORT;
  2635. }
  2636. #endif
  2637. return api->halmac_enter_cpu_sleep_mode(mac);
  2638. }
  2639. /*
  2640. * _cpu_sleep() - Let IC CPU enter sleep mode
  2641. * @d: struct dvobj_priv*
  2642. * @timeout: time limit of wait, unit is ms
  2643. * 0 for no limit
  2644. *
  2645. * Return 0 for CPU in sleep mode, otherwise fail to enter sleep mode.
  2646. * Error codes definition are as follow:
  2647. * -1 HALMAC enter sleep return fail
  2648. * -2 HALMAC get CPU mode return fail
  2649. * -110 timeout
  2650. */
  2651. static int _cpu_sleep(struct dvobj_priv *d, u32 timeout)
  2652. {
  2653. struct halmac_adapter *mac;
  2654. struct halmac_api *api;
  2655. enum halmac_ret_status status;
  2656. enum halmac_wlcpu_mode mode = HALMAC_WLCPU_UNDEFINE;
  2657. systime start_t;
  2658. s32 period = 0;
  2659. u32 cnt = 0;
  2660. int err = 0;
  2661. mac = dvobj_to_halmac(d);
  2662. api = HALMAC_GET_API(mac);
  2663. start_t = rtw_get_current_time();
  2664. status = _enter_cpu_sleep_mode(d);
  2665. if (status != HALMAC_RET_SUCCESS) {
  2666. if (status != HALMAC_RET_NOT_SUPPORT)
  2667. err = -1;
  2668. goto exit;
  2669. }
  2670. do {
  2671. cnt++;
  2672. mode = HALMAC_WLCPU_UNDEFINE;
  2673. status = api->halmac_get_cpu_mode(mac, &mode);
  2674. period = rtw_get_passing_time_ms(start_t);
  2675. if (status != HALMAC_RET_SUCCESS) {
  2676. err = -2;
  2677. break;
  2678. }
  2679. if (mode == HALMAC_WLCPU_SLEEP)
  2680. break;
  2681. if (period > timeout) {
  2682. err = -110;
  2683. break;
  2684. }
  2685. rtw_msleep_os(1);
  2686. } while (1);
  2687. exit:
  2688. if (err)
  2689. RTW_ERR("%s: Fail to enter sleep mode! (%d, %d)\n",
  2690. __FUNCTION__, status, mode);
  2691. RTW_INFO("%s: Cost %dms to polling %u times. (err=%d)\n",
  2692. __FUNCTION__, period, cnt, err);
  2693. return err;
  2694. }
  2695. static void _init_trx_cfg_drv(struct dvobj_priv *d)
  2696. {
  2697. #ifdef CONFIG_PCI_HCI
  2698. rtw_hal_irp_reset(dvobj_get_primary_adapter(d));
  2699. #endif
  2700. }
  2701. /*
  2702. * Description:
  2703. * Downlaod Firmware Flow
  2704. *
  2705. * Parameters:
  2706. * d pointer of struct dvobj_priv
  2707. * fw firmware array
  2708. * fwsize firmware size
  2709. * re_dl re-download firmware or not
  2710. * 0: run in init hal flow, not re-download
  2711. * 1: it is a stand alone operation, not in init hal flow
  2712. *
  2713. * Return:
  2714. * 0 Success
  2715. * others Fail
  2716. */
  2717. static int download_fw(struct dvobj_priv *d, u8 *fw, u32 fwsize, u8 re_dl)
  2718. {
  2719. PHAL_DATA_TYPE hal;
  2720. struct halmac_adapter *mac;
  2721. struct halmac_api *api;
  2722. struct halmac_fw_version fw_vesion;
  2723. enum halmac_ret_status status;
  2724. int err = 0;
  2725. hal = GET_HAL_DATA(dvobj_get_primary_adapter(d));
  2726. mac = dvobj_to_halmac(d);
  2727. api = HALMAC_GET_API(mac);
  2728. if ((!fw) || (!fwsize))
  2729. return -1;
  2730. /* 1. Driver Stop Tx */
  2731. /* ToDo */
  2732. /* 2. Driver Check Tx FIFO is empty */
  2733. err = rtw_halmac_txfifo_wait_empty(d, 2000); /* wait 2s */
  2734. if (err) {
  2735. err = -1;
  2736. goto resume_tx;
  2737. }
  2738. /* 3. Config MAX download size */
  2739. /*
  2740. * Already done in rtw_halmac_init_adapter() or
  2741. * somewhere calling rtw_halmac_set_max_dl_fw_size().
  2742. */
  2743. if (re_dl) {
  2744. /* 4. Enter IC CPU sleep mode */
  2745. err = _cpu_sleep(d, 2000);
  2746. if (err) {
  2747. RTW_ERR("%s: IC CPU fail to enter sleep mode!(%d)\n",
  2748. __FUNCTION__, err);
  2749. /* skip this error */
  2750. err = 0;
  2751. }
  2752. }
  2753. /* 5. Download Firmware */
  2754. status = api->halmac_download_firmware(mac, fw, fwsize);
  2755. if (status != HALMAC_RET_SUCCESS) {
  2756. RTW_ERR("%s: download firmware FAIL! status=0x%02x\n",
  2757. __FUNCTION__, status);
  2758. _debug_dlfw_fail(d);
  2759. err = -1;
  2760. goto resume_tx;
  2761. }
  2762. /* 5.1. (Driver) Reset driver variables if needed */
  2763. hal->LastHMEBoxNum = 0;
  2764. /* 5.2. (Driver) Get FW version */
  2765. status = api->halmac_get_fw_version(mac, &fw_vesion);
  2766. if (status == HALMAC_RET_SUCCESS) {
  2767. hal->firmware_version = fw_vesion.version;
  2768. hal->firmware_sub_version = fw_vesion.sub_version;
  2769. hal->firmware_size = fwsize;
  2770. }
  2771. resume_tx:
  2772. /* 6. Driver resume TX if needed */
  2773. /* ToDo */
  2774. if (err)
  2775. goto exit;
  2776. if (re_dl) {
  2777. enum halmac_trx_mode mode;
  2778. /* 7. Change reserved page size */
  2779. err = _cfg_drv_rsvd_pg_num(d);
  2780. if (err)
  2781. return -1;
  2782. /* 8. Init TRX Configuration */
  2783. mode = _choose_trx_mode(d);
  2784. status = api->halmac_init_trx_cfg(mac, mode);
  2785. if (HALMAC_RET_SUCCESS != status)
  2786. return -1;
  2787. _init_trx_cfg_drv(d);
  2788. /* 9. Config RX Aggregation */
  2789. err = rtw_halmac_rx_agg_switch(d, _TRUE);
  2790. if (err)
  2791. return -1;
  2792. /* 10. Send General Info */
  2793. err = _send_general_info(d);
  2794. if (err)
  2795. return -1;
  2796. }
  2797. exit:
  2798. return err;
  2799. }
  2800. static int init_mac_flow(struct dvobj_priv *d)
  2801. {
  2802. PADAPTER p;
  2803. struct hal_com_data *hal;
  2804. struct halmac_adapter *halmac;
  2805. struct halmac_api *api;
  2806. enum halmac_drv_rsvd_pg_num rsvd_page_number;
  2807. union halmac_wlan_addr hwa;
  2808. enum halmac_trx_mode trx_mode;
  2809. enum halmac_ret_status status;
  2810. u8 drv_rsvd_num;
  2811. u8 nettype;
  2812. int err, err_ret = -1;
  2813. p = dvobj_get_primary_adapter(d);
  2814. hal = GET_HAL_DATA(p);
  2815. halmac = dvobj_to_halmac(d);
  2816. api = HALMAC_GET_API(halmac);
  2817. #ifdef CONFIG_SUPPORT_TRX_SHARED
  2818. status = api->halmac_cfg_rxff_expand_mode(halmac,
  2819. _rtw_get_trx_share_mode(p));
  2820. if (status != HALMAC_RET_SUCCESS)
  2821. goto out;
  2822. #endif
  2823. #ifdef DBG_LA_MODE
  2824. if (dvobj_to_regsty(d)->la_mode_en) {
  2825. status = api->halmac_cfg_la_mode(halmac, HALMAC_LA_MODE_PARTIAL);
  2826. if (status != HALMAC_RET_SUCCESS) {
  2827. RTW_ERR("%s: Fail to enable LA mode!\n", __FUNCTION__);
  2828. goto out;
  2829. }
  2830. RTW_PRINT("%s: Enable LA mode OK.\n", __FUNCTION__);
  2831. }
  2832. #endif
  2833. err = _cfg_drv_rsvd_pg_num(d);
  2834. if (err)
  2835. goto out;
  2836. #ifdef CONFIG_USB_HCI
  2837. status = api->halmac_set_bulkout_num(halmac, d->RtNumOutPipes);
  2838. if (status != HALMAC_RET_SUCCESS)
  2839. goto out;
  2840. #endif /* CONFIG_USB_HCI */
  2841. trx_mode = _choose_trx_mode(d);
  2842. status = api->halmac_init_mac_cfg(halmac, trx_mode);
  2843. if (status != HALMAC_RET_SUCCESS)
  2844. goto out;
  2845. _init_trx_cfg_drv(d);
  2846. err = rtw_halmac_rx_agg_switch(d, _TRUE);
  2847. if (err)
  2848. goto out;
  2849. nettype = dvobj_to_regsty(d)->wireless_mode;
  2850. if (is_supported_vht(nettype) == _TRUE)
  2851. status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_AC);
  2852. else if (is_supported_ht(nettype) == _TRUE)
  2853. status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_N);
  2854. else if (IsSupportedTxOFDM(nettype) == _TRUE)
  2855. status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_G);
  2856. else
  2857. status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_B);
  2858. if (status != HALMAC_RET_SUCCESS)
  2859. goto out;
  2860. err_ret = 0;
  2861. out:
  2862. return err_ret;
  2863. }
  2864. static int _drv_enable_trx(struct dvobj_priv *d)
  2865. {
  2866. struct _ADAPTER *adapter;
  2867. u32 status;
  2868. adapter = dvobj_get_primary_adapter(d);
  2869. if (adapter->bup == _FALSE) {
  2870. #ifdef CONFIG_NEW_NETDEV_HDL
  2871. status = rtw_mi_start_drv_threads(adapter);
  2872. #else
  2873. status = rtw_start_drv_threads(adapter);
  2874. #endif
  2875. if (status == _FAIL) {
  2876. RTW_ERR("%s: Start threads Failed!\n", __FUNCTION__);
  2877. return -1;
  2878. }
  2879. }
  2880. rtw_intf_start(adapter);
  2881. return 0;
  2882. }
  2883. /*
  2884. * Notices:
  2885. * Make sure following information
  2886. * 1. GET_HAL_RFPATH
  2887. * 2. GET_HAL_DATA(dvobj_get_primary_adapter(d))->rfe_type
  2888. * 3. GET_HAL_DATA(dvobj_get_primary_adapter(d))->PackageType
  2889. * 4. dvobj_get_primary_adapter(d)->registrypriv.mp_mode
  2890. * are all ready before calling this function.
  2891. */
  2892. static int _halmac_init_hal(struct dvobj_priv *d, u8 *fw, u32 fwsize)
  2893. {
  2894. PADAPTER adapter;
  2895. struct halmac_adapter *halmac;
  2896. struct halmac_api *api;
  2897. enum halmac_ret_status status;
  2898. u32 ok;
  2899. u8 fw_ok = _FALSE;
  2900. int err, err_ret = -1;
  2901. adapter = dvobj_get_primary_adapter(d);
  2902. halmac = dvobj_to_halmac(d);
  2903. if (!halmac)
  2904. goto out;
  2905. api = HALMAC_GET_API(halmac);
  2906. /* StatePowerOff */
  2907. /* SKIP: halmac_init_adapter (Already done before) */
  2908. /* halmac_pre_Init_system_cfg */
  2909. /* halmac_mac_power_switch(on) */
  2910. /* halmac_Init_system_cfg */
  2911. ok = rtw_hal_power_on(adapter);
  2912. if (_FAIL == ok)
  2913. goto out;
  2914. /* StatePowerOn */
  2915. /* DownloadFW */
  2916. if (fw && fwsize) {
  2917. err = download_fw(d, fw, fwsize, 0);
  2918. if (err)
  2919. goto out;
  2920. fw_ok = _TRUE;
  2921. }
  2922. /* InitMACFlow */
  2923. err = init_mac_flow(d);
  2924. if (err)
  2925. goto out;
  2926. /* Driver insert flow: Enable TR/RX */
  2927. err = _drv_enable_trx(d);
  2928. if (err)
  2929. goto out;
  2930. /* halmac_send_general_info */
  2931. if (_TRUE == fw_ok) {
  2932. err = _send_general_info(d);
  2933. if (err)
  2934. goto out;
  2935. }
  2936. /* Init Phy parameter-MAC */
  2937. ok = rtw_hal_init_mac_register(adapter);
  2938. if (_FALSE == ok)
  2939. goto out;
  2940. /* StateMacInitialized */
  2941. /* halmac_cfg_drv_info */
  2942. err = rtw_halmac_config_rx_info(d, HALMAC_DRV_INFO_PHY_STATUS);
  2943. if (err)
  2944. goto out;
  2945. /* halmac_set_hw_value(HALMAC_HW_EN_BB_RF) */
  2946. /* Init BB, RF */
  2947. ok = rtw_hal_init_phy(adapter);
  2948. if (_FALSE == ok)
  2949. goto out;
  2950. status = api->halmac_init_interface_cfg(halmac);
  2951. if (status != HALMAC_RET_SUCCESS)
  2952. goto out;
  2953. /* SKIP: halmac_verify_platform_api */
  2954. /* SKIP: halmac_h2c_lb */
  2955. /* StateRxIdle */
  2956. err_ret = 0;
  2957. out:
  2958. return err_ret;
  2959. }
  2960. int rtw_halmac_init_hal(struct dvobj_priv *d)
  2961. {
  2962. return _halmac_init_hal(d, NULL, 0);
  2963. }
  2964. /*
  2965. * Notices:
  2966. * Make sure following information
  2967. * 1. GET_HAL_RFPATH
  2968. * 2. GET_HAL_DATA(dvobj_get_primary_adapter(d))->rfe_type
  2969. * 3. GET_HAL_DATA(dvobj_get_primary_adapter(d))->PackageType
  2970. * 4. dvobj_get_primary_adapter(d)->registrypriv.mp_mode
  2971. * are all ready before calling this function.
  2972. */
  2973. int rtw_halmac_init_hal_fw(struct dvobj_priv *d, u8 *fw, u32 fwsize)
  2974. {
  2975. return _halmac_init_hal(d, fw, fwsize);
  2976. }
  2977. /*
  2978. * Notices:
  2979. * Make sure following information
  2980. * 1. GET_HAL_RFPATH
  2981. * 2. GET_HAL_DATA(dvobj_get_primary_adapter(d))->rfe_type
  2982. * 3. GET_HAL_DATA(dvobj_get_primary_adapter(d))->PackageType
  2983. * 4. dvobj_get_primary_adapter(d)->registrypriv.mp_mode
  2984. * are all ready before calling this function.
  2985. */
  2986. int rtw_halmac_init_hal_fw_file(struct dvobj_priv *d, u8 *fwpath)
  2987. {
  2988. u8 *fw = NULL;
  2989. u32 fwmaxsize = 0, size = 0;
  2990. int err = 0;
  2991. err = rtw_halmac_get_fw_max_size(d, &fwmaxsize);
  2992. if (err) {
  2993. RTW_ERR("%s: Fail to get Firmware MAX size(err=%d)\n", __FUNCTION__, err);
  2994. return -1;
  2995. }
  2996. fw = rtw_zmalloc(fwmaxsize);
  2997. if (!fw)
  2998. return -1;
  2999. size = rtw_retrieve_from_file(fwpath, fw, fwmaxsize);
  3000. if (!size) {
  3001. err = -1;
  3002. goto exit;
  3003. }
  3004. err = _halmac_init_hal(d, fw, size);
  3005. exit:
  3006. rtw_mfree(fw, fwmaxsize);
  3007. /*fw = NULL;*/
  3008. return err;
  3009. }
  3010. int rtw_halmac_deinit_hal(struct dvobj_priv *d)
  3011. {
  3012. PADAPTER adapter;
  3013. struct halmac_adapter *halmac;
  3014. struct halmac_api *api;
  3015. enum halmac_ret_status status;
  3016. int err = -1;
  3017. adapter = dvobj_get_primary_adapter(d);
  3018. halmac = dvobj_to_halmac(d);
  3019. if (!halmac)
  3020. goto out;
  3021. api = HALMAC_GET_API(halmac);
  3022. status = api->halmac_deinit_interface_cfg(halmac);
  3023. if (status != HALMAC_RET_SUCCESS)
  3024. goto out;
  3025. rtw_hal_power_off(adapter);
  3026. err = 0;
  3027. out:
  3028. return err;
  3029. }
  3030. int rtw_halmac_self_verify(struct dvobj_priv *d)
  3031. {
  3032. struct halmac_adapter *mac;
  3033. struct halmac_api *api;
  3034. enum halmac_ret_status status;
  3035. int err = -1;
  3036. mac = dvobj_to_halmac(d);
  3037. api = HALMAC_GET_API(mac);
  3038. status = api->halmac_verify_platform_api(mac);
  3039. if (status != HALMAC_RET_SUCCESS)
  3040. goto out;
  3041. status = api->halmac_h2c_lb(mac);
  3042. if (status != HALMAC_RET_SUCCESS)
  3043. goto out;
  3044. err = 0;
  3045. out:
  3046. return err;
  3047. }
  3048. static u8 rtw_halmac_txfifo_is_empty(struct dvobj_priv *d)
  3049. {
  3050. struct halmac_adapter *mac;
  3051. struct halmac_api *api;
  3052. enum halmac_ret_status status;
  3053. u32 chk_num = 10;
  3054. u8 rst = _FALSE;
  3055. mac = dvobj_to_halmac(d);
  3056. api = HALMAC_GET_API(mac);
  3057. status = api->halmac_txfifo_is_empty(mac, chk_num);
  3058. if (status == HALMAC_RET_SUCCESS)
  3059. rst = _TRUE;
  3060. return rst;
  3061. }
  3062. /**
  3063. * rtw_halmac_txfifo_wait_empty() - Wait TX FIFO to be emtpy
  3064. * @d: struct dvobj_priv*
  3065. * @timeout: time limit of wait, unit is ms
  3066. * 0 for no limit
  3067. *
  3068. * Wait TX FIFO to be emtpy.
  3069. *
  3070. * Return 0 for TX FIFO is empty, otherwise not empty.
  3071. */
  3072. int rtw_halmac_txfifo_wait_empty(struct dvobj_priv *d, u32 timeout)
  3073. {
  3074. struct _ADAPTER *a;
  3075. u8 empty = _FALSE;
  3076. u32 cnt = 0;
  3077. systime start_time = 0;
  3078. u32 pass_time; /* ms */
  3079. a = dvobj_get_primary_adapter(d);
  3080. start_time = rtw_get_current_time();
  3081. do {
  3082. cnt++;
  3083. empty = rtw_halmac_txfifo_is_empty(d);
  3084. if (empty == _TRUE)
  3085. break;
  3086. if (timeout) {
  3087. pass_time = rtw_get_passing_time_ms(start_time);
  3088. if (pass_time > timeout)
  3089. break;
  3090. }
  3091. if (RTW_CANNOT_IO(a)) {
  3092. RTW_WARN("%s: Interrupted by I/O forbiden!\n", __FUNCTION__);
  3093. break;
  3094. }
  3095. rtw_msleep_os(2);
  3096. } while (1);
  3097. if (empty == _FALSE) {
  3098. #ifdef CONFIG_RTW_DEBUG
  3099. u16 dbg_reg[] = {0x210, 0x230, 0x234, 0x238, 0x23C, 0x240,
  3100. 0x418, 0x10FC, 0x10F8, 0x11F4, 0x11F8};
  3101. u8 i;
  3102. u32 val;
  3103. if (!RTW_CANNOT_IO(a)) {
  3104. for (i = 0; i < ARRAY_SIZE(dbg_reg); i++) {
  3105. val = rtw_read32(a, dbg_reg[i]);
  3106. RTW_ERR("REG_%X:0x%08x\n", dbg_reg[i], val);
  3107. }
  3108. }
  3109. #endif /* CONFIG_RTW_DEBUG */
  3110. RTW_ERR("%s: Fail to wait txfifo empty!(cnt=%d)\n",
  3111. __FUNCTION__, cnt);
  3112. return -1;
  3113. }
  3114. return 0;
  3115. }
  3116. static enum halmac_dlfw_mem _fw_mem_drv2halmac(enum fw_mem mem, u8 tx_stop)
  3117. {
  3118. enum halmac_dlfw_mem mem_halmac = HALMAC_DLFW_MEM_UNDEFINE;
  3119. switch (mem) {
  3120. case FW_EMEM:
  3121. if (tx_stop == _FALSE)
  3122. mem_halmac = HALMAC_DLFW_MEM_EMEM_RSVD_PG;
  3123. else
  3124. mem_halmac = HALMAC_DLFW_MEM_EMEM;
  3125. break;
  3126. case FW_IMEM:
  3127. case FW_DMEM:
  3128. mem_halmac = HALMAC_DLFW_MEM_UNDEFINE;
  3129. break;
  3130. }
  3131. return mem_halmac;
  3132. }
  3133. int rtw_halmac_dlfw_mem(struct dvobj_priv *d, u8 *fw, u32 fwsize, enum fw_mem mem)
  3134. {
  3135. struct halmac_adapter *mac;
  3136. struct halmac_api *api;
  3137. enum halmac_ret_status status;
  3138. enum halmac_dlfw_mem dlfw_mem;
  3139. u8 tx_stop = _FALSE;
  3140. u32 chk_timeout = 2000; /* unit: ms */
  3141. int err = 0;
  3142. mac = dvobj_to_halmac(d);
  3143. api = HALMAC_GET_API(mac);
  3144. if ((!fw) || (!fwsize))
  3145. return -1;
  3146. #ifndef RTW_HALMAC_DLFW_MEM_NO_STOP_TX
  3147. /* 1. Driver Stop Tx */
  3148. /* ToDo */
  3149. /* 2. Driver Check Tx FIFO is empty */
  3150. err = rtw_halmac_txfifo_wait_empty(d, chk_timeout);
  3151. if (err)
  3152. tx_stop = _FALSE;
  3153. else
  3154. tx_stop = _TRUE;
  3155. #endif /* !RTW_HALMAC_DLFW_MEM_NO_STOP_TX */
  3156. /* 3. Download Firmware MEM */
  3157. dlfw_mem = _fw_mem_drv2halmac(mem, tx_stop);
  3158. if (dlfw_mem == HALMAC_DLFW_MEM_UNDEFINE) {
  3159. err = -1;
  3160. goto resume_tx;
  3161. }
  3162. status = api->halmac_free_download_firmware(mac, dlfw_mem, fw, fwsize);
  3163. if (status != HALMAC_RET_SUCCESS) {
  3164. RTW_ERR("%s: halmac_free_download_firmware fail(err=0x%x)\n",
  3165. __FUNCTION__, status);
  3166. err = -1;
  3167. goto resume_tx;
  3168. }
  3169. resume_tx:
  3170. #ifndef RTW_HALMAC_DLFW_MEM_NO_STOP_TX
  3171. /* 4. Driver resume TX if needed */
  3172. /* ToDo */
  3173. #endif /* !RTW_HALMAC_DLFW_MEM_NO_STOP_TX */
  3174. return err;
  3175. }
  3176. int rtw_halmac_dlfw_mem_from_file(struct dvobj_priv *d, u8 *fwpath, enum fw_mem mem)
  3177. {
  3178. u8 *fw = NULL;
  3179. u32 fwmaxsize = 0, size = 0;
  3180. int err = 0;
  3181. err = rtw_halmac_get_fw_max_size(d, &fwmaxsize);
  3182. if (err) {
  3183. RTW_ERR("%s: Fail to get Firmware MAX size(err=%d)\n", __FUNCTION__, err);
  3184. return -1;
  3185. }
  3186. fw = rtw_zmalloc(fwmaxsize);
  3187. if (!fw)
  3188. return -1;
  3189. size = rtw_retrieve_from_file(fwpath, fw, fwmaxsize);
  3190. if (size)
  3191. err = rtw_halmac_dlfw_mem(d, fw, size, mem);
  3192. else
  3193. err = -1;
  3194. rtw_mfree(fw, fwmaxsize);
  3195. /*fw = NULL;*/
  3196. return err;
  3197. }
  3198. /*
  3199. * Return:
  3200. * 0 Success
  3201. * -22 Invalid arguemnt
  3202. */
  3203. int rtw_halmac_dlfw(struct dvobj_priv *d, u8 *fw, u32 fwsize)
  3204. {
  3205. PADAPTER adapter;
  3206. enum halmac_ret_status status;
  3207. u32 ok;
  3208. int err, err_ret = -1;
  3209. if (!fw || !fwsize)
  3210. return -22;
  3211. adapter = dvobj_get_primary_adapter(d);
  3212. /* re-download firmware */
  3213. if (rtw_is_hw_init_completed(adapter))
  3214. return download_fw(d, fw, fwsize, 1);
  3215. /* Download firmware before hal init */
  3216. /* Power on, download firmware and init mac */
  3217. ok = rtw_hal_power_on(adapter);
  3218. if (_FAIL == ok)
  3219. goto out;
  3220. err = download_fw(d, fw, fwsize, 0);
  3221. if (err) {
  3222. err_ret = err;
  3223. goto out;
  3224. }
  3225. err = init_mac_flow(d);
  3226. if (err)
  3227. goto out;
  3228. err = _send_general_info(d);
  3229. if (err)
  3230. goto out;
  3231. err_ret = 0;
  3232. out:
  3233. return err_ret;
  3234. }
  3235. int rtw_halmac_dlfw_from_file(struct dvobj_priv *d, u8 *fwpath)
  3236. {
  3237. u8 *fw = NULL;
  3238. u32 fwmaxsize = 0, size = 0;
  3239. int err = 0;
  3240. err = rtw_halmac_get_fw_max_size(d, &fwmaxsize);
  3241. if (err) {
  3242. RTW_ERR("%s: Fail to get Firmware MAX size(err=%d)\n", __FUNCTION__, err);
  3243. return -1;
  3244. }
  3245. fw = rtw_zmalloc(fwmaxsize);
  3246. if (!fw)
  3247. return -1;
  3248. size = rtw_retrieve_from_file(fwpath, fw, fwmaxsize);
  3249. if (size)
  3250. err = rtw_halmac_dlfw(d, fw, size);
  3251. else
  3252. err = -1;
  3253. rtw_mfree(fw, fwmaxsize);
  3254. /*fw = NULL;*/
  3255. return err;
  3256. }
  3257. /*
  3258. * Description:
  3259. * Power on/off BB/RF domain.
  3260. *
  3261. * Parameters:
  3262. * enable _TRUE/_FALSE for power on/off
  3263. *
  3264. * Return:
  3265. * 0 Success
  3266. * others Fail
  3267. */
  3268. int rtw_halmac_phy_power_switch(struct dvobj_priv *d, u8 enable)
  3269. {
  3270. PADAPTER adapter;
  3271. struct halmac_adapter *halmac;
  3272. struct halmac_api *api;
  3273. enum halmac_ret_status status;
  3274. u8 on;
  3275. adapter = dvobj_get_primary_adapter(d);
  3276. halmac = dvobj_to_halmac(d);
  3277. if (!halmac)
  3278. return -1;
  3279. api = HALMAC_GET_API(halmac);
  3280. on = (enable == _TRUE) ? 1 : 0;
  3281. status = api->halmac_set_hw_value(halmac, HALMAC_HW_EN_BB_RF, &on);
  3282. if (status != HALMAC_RET_SUCCESS)
  3283. return -1;
  3284. return 0;
  3285. }
  3286. static u8 _is_fw_read_cmd_down(PADAPTER adapter, u8 msgbox_num)
  3287. {
  3288. u8 read_down = _FALSE;
  3289. int retry_cnts = 100;
  3290. u8 valid;
  3291. do {
  3292. valid = rtw_read8(adapter, REG_HMETFR) & BIT(msgbox_num);
  3293. if (0 == valid)
  3294. read_down = _TRUE;
  3295. else
  3296. rtw_msleep_os(1);
  3297. } while ((!read_down) && (retry_cnts--));
  3298. if (_FALSE == read_down)
  3299. RTW_WARN("%s, reg_1cc(%x), msg_box(%d)...\n", __func__, rtw_read8(adapter, REG_HMETFR), msgbox_num);
  3300. return read_down;
  3301. }
  3302. /**
  3303. * rtw_halmac_send_h2c() - Send H2C to firmware
  3304. * @d: struct dvobj_priv*
  3305. * @h2c: H2C data buffer, suppose to be 8 bytes
  3306. *
  3307. * Send H2C to firmware by message box register(0x1D0~0x1D3 & 0x1F0~0x1F3).
  3308. *
  3309. * Assume firmware be ready to accept H2C here, please check
  3310. * (hal->bFWReady == _TRUE) before call this function or make sure firmware is
  3311. * ready.
  3312. *
  3313. * Return: 0 if process OK, otherwise fail to send this H2C.
  3314. */
  3315. int rtw_halmac_send_h2c(struct dvobj_priv *d, u8 *h2c)
  3316. {
  3317. PADAPTER adapter = dvobj_get_primary_adapter(d);
  3318. PHAL_DATA_TYPE hal = GET_HAL_DATA(adapter);
  3319. u8 h2c_box_num = 0;
  3320. u32 msgbox_addr = 0;
  3321. u32 msgbox_ex_addr = 0;
  3322. u32 h2c_cmd = 0;
  3323. u32 h2c_cmd_ex = 0;
  3324. int err = -1;
  3325. if (!h2c) {
  3326. RTW_WARN("%s: pbuf is NULL\n", __FUNCTION__);
  3327. return err;
  3328. }
  3329. if (rtw_is_surprise_removed(adapter)) {
  3330. RTW_WARN("%s: surprise removed\n", __FUNCTION__);
  3331. return err;
  3332. }
  3333. _enter_critical_mutex(&d->h2c_fwcmd_mutex, NULL);
  3334. /* pay attention to if race condition happened in H2C cmd setting */
  3335. h2c_box_num = hal->LastHMEBoxNum;
  3336. if (!_is_fw_read_cmd_down(adapter, h2c_box_num)) {
  3337. RTW_WARN(" fw read cmd failed...\n");
  3338. #ifdef DBG_CONFIG_ERROR_DETECT
  3339. hal->srestpriv.self_dect_fw = _TRUE;
  3340. hal->srestpriv.self_dect_fw_cnt++;
  3341. #endif /* DBG_CONFIG_ERROR_DETECT */
  3342. goto exit;
  3343. }
  3344. /* Write Ext command (byte 4~7) */
  3345. msgbox_ex_addr = REG_HMEBOX_E0 + (h2c_box_num * EX_MESSAGE_BOX_SIZE);
  3346. _rtw_memcpy((u8 *)(&h2c_cmd_ex), h2c + 4, EX_MESSAGE_BOX_SIZE);
  3347. h2c_cmd_ex = le32_to_cpu(h2c_cmd_ex);
  3348. rtw_write32(adapter, msgbox_ex_addr, h2c_cmd_ex);
  3349. /* Write command (byte 0~3) */
  3350. msgbox_addr = REG_HMEBOX0 + (h2c_box_num * MESSAGE_BOX_SIZE);
  3351. _rtw_memcpy((u8 *)(&h2c_cmd), h2c, 4);
  3352. h2c_cmd = le32_to_cpu(h2c_cmd);
  3353. rtw_write32(adapter, msgbox_addr, h2c_cmd);
  3354. /* update last msg box number */
  3355. hal->LastHMEBoxNum = (h2c_box_num + 1) % MAX_H2C_BOX_NUMS;
  3356. err = 0;
  3357. #ifdef DBG_H2C_CONTENT
  3358. RTW_INFO_DUMP("[H2C] - ", h2c, RTW_HALMAC_H2C_MAX_SIZE);
  3359. #endif
  3360. exit:
  3361. _exit_critical_mutex(&d->h2c_fwcmd_mutex, NULL);
  3362. return err;
  3363. }
  3364. /**
  3365. * rtw_halmac_c2h_handle() - Handle C2H for HALMAC
  3366. * @d: struct dvobj_priv*
  3367. * @c2h: Full C2H packet, including RX description and payload
  3368. * @size: Size(byte) of c2h
  3369. *
  3370. * Send C2H packet to HALMAC to process C2H packets, and the expected C2H ID is
  3371. * 0xFF. This function won't have any I/O, so caller doesn't have to call it in
  3372. * I/O safe place(ex. command thread).
  3373. *
  3374. * Please sure doesn't call this function in the same thread as someone is
  3375. * waiting HALMAC C2H ack, otherwise there is a deadlock happen.
  3376. *
  3377. * Return: 0 if process OK, otherwise no action for this C2H.
  3378. */
  3379. int rtw_halmac_c2h_handle(struct dvobj_priv *d, u8 *c2h, u32 size)
  3380. {
  3381. struct halmac_adapter *mac;
  3382. struct halmac_api *api;
  3383. enum halmac_ret_status status;
  3384. mac = dvobj_to_halmac(d);
  3385. api = HALMAC_GET_API(mac);
  3386. status = api->halmac_get_c2h_info(mac, c2h, size);
  3387. if (HALMAC_RET_SUCCESS != status)
  3388. return -1;
  3389. return 0;
  3390. }
  3391. int rtw_halmac_get_available_efuse_size(struct dvobj_priv *d, u32 *size)
  3392. {
  3393. struct halmac_adapter *mac;
  3394. struct halmac_api *api;
  3395. enum halmac_ret_status status;
  3396. u32 val;
  3397. mac = dvobj_to_halmac(d);
  3398. api = HALMAC_GET_API(mac);
  3399. status = api->halmac_get_efuse_available_size(mac, &val);
  3400. if (HALMAC_RET_SUCCESS != status)
  3401. return -1;
  3402. *size = val;
  3403. return 0;
  3404. }
  3405. int rtw_halmac_get_physical_efuse_size(struct dvobj_priv *d, u32 *size)
  3406. {
  3407. struct halmac_adapter *mac;
  3408. struct halmac_api *api;
  3409. enum halmac_ret_status status;
  3410. u32 val;
  3411. mac = dvobj_to_halmac(d);
  3412. api = HALMAC_GET_API(mac);
  3413. status = api->halmac_get_efuse_size(mac, &val);
  3414. if (HALMAC_RET_SUCCESS != status)
  3415. return -1;
  3416. *size = val;
  3417. return 0;
  3418. }
  3419. int rtw_halmac_read_physical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size)
  3420. {
  3421. struct halmac_adapter *mac;
  3422. struct halmac_api *api;
  3423. enum halmac_ret_status status;
  3424. enum halmac_feature_id id;
  3425. int ret;
  3426. mac = dvobj_to_halmac(d);
  3427. api = HALMAC_GET_API(mac);
  3428. id = HALMAC_FEATURE_DUMP_PHYSICAL_EFUSE;
  3429. ret = init_halmac_event(d, id, map, size);
  3430. if (ret)
  3431. return -1;
  3432. status = api->halmac_dump_efuse_map(mac, HALMAC_EFUSE_R_DRV);
  3433. if (HALMAC_RET_SUCCESS != status) {
  3434. free_halmac_event(d, id);
  3435. return -1;
  3436. }
  3437. ret = wait_halmac_event(d, id);
  3438. if (ret)
  3439. return -1;
  3440. return 0;
  3441. }
  3442. int rtw_halmac_read_physical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
  3443. {
  3444. struct halmac_adapter *mac;
  3445. struct halmac_api *api;
  3446. enum halmac_ret_status status;
  3447. u8 v;
  3448. u32 i;
  3449. u8 *efuse = NULL;
  3450. u32 size = 0;
  3451. int err = 0;
  3452. mac = dvobj_to_halmac(d);
  3453. api = HALMAC_GET_API(mac);
  3454. if (api->halmac_read_efuse) {
  3455. for (i = 0; i < cnt; i++) {
  3456. status = api->halmac_read_efuse(mac, offset + i, &v);
  3457. if (HALMAC_RET_SUCCESS != status)
  3458. return -1;
  3459. data[i] = v;
  3460. }
  3461. } else {
  3462. err = rtw_halmac_get_physical_efuse_size(d, &size);
  3463. if (err)
  3464. return -1;
  3465. efuse = rtw_zmalloc(size);
  3466. if (!efuse)
  3467. return -1;
  3468. err = rtw_halmac_read_physical_efuse_map(d, efuse, size);
  3469. if (err)
  3470. err = -1;
  3471. else
  3472. _rtw_memcpy(data, efuse + offset, cnt);
  3473. rtw_mfree(efuse, size);
  3474. }
  3475. return err;
  3476. }
  3477. int rtw_halmac_write_physical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
  3478. {
  3479. struct halmac_adapter *mac;
  3480. struct halmac_api *api;
  3481. enum halmac_ret_status status;
  3482. u32 i;
  3483. mac = dvobj_to_halmac(d);
  3484. api = HALMAC_GET_API(mac);
  3485. if (api->halmac_write_efuse == NULL)
  3486. return -1;
  3487. for (i = 0; i < cnt; i++) {
  3488. status = api->halmac_write_efuse(mac, offset + i, data[i]);
  3489. if (HALMAC_RET_SUCCESS != status)
  3490. return -1;
  3491. }
  3492. return 0;
  3493. }
  3494. int rtw_halmac_get_logical_efuse_size(struct dvobj_priv *d, u32 *size)
  3495. {
  3496. struct halmac_adapter *mac;
  3497. struct halmac_api *api;
  3498. enum halmac_ret_status status;
  3499. u32 val;
  3500. mac = dvobj_to_halmac(d);
  3501. api = HALMAC_GET_API(mac);
  3502. status = api->halmac_get_logical_efuse_size(mac, &val);
  3503. if (HALMAC_RET_SUCCESS != status)
  3504. return -1;
  3505. *size = val;
  3506. return 0;
  3507. }
  3508. int rtw_halmac_read_logical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size, u8 *maskmap, u32 masksize)
  3509. {
  3510. struct halmac_adapter *mac;
  3511. struct halmac_api *api;
  3512. enum halmac_ret_status status;
  3513. enum halmac_feature_id id;
  3514. int ret;
  3515. mac = dvobj_to_halmac(d);
  3516. api = HALMAC_GET_API(mac);
  3517. id = HALMAC_FEATURE_DUMP_LOGICAL_EFUSE;
  3518. ret = init_halmac_event(d, id, map, size);
  3519. if (ret)
  3520. return -1;
  3521. status = api->halmac_dump_logical_efuse_map(mac, HALMAC_EFUSE_R_DRV);
  3522. if (HALMAC_RET_SUCCESS != status) {
  3523. free_halmac_event(d, id);
  3524. return -1;
  3525. }
  3526. ret = wait_halmac_event(d, id);
  3527. if (ret)
  3528. return -1;
  3529. if (maskmap && masksize) {
  3530. struct halmac_pg_efuse_info pginfo;
  3531. pginfo.efuse_map = map;
  3532. pginfo.efuse_map_size = size;
  3533. pginfo.efuse_mask = maskmap;
  3534. pginfo.efuse_mask_size = masksize;
  3535. status = api->halmac_mask_logical_efuse(mac, &pginfo);
  3536. if (status != HALMAC_RET_SUCCESS)
  3537. RTW_WARN("%s: mask logical efuse FAIL!\n", __FUNCTION__);
  3538. }
  3539. return 0;
  3540. }
  3541. int rtw_halmac_write_logical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size, u8 *maskmap, u32 masksize)
  3542. {
  3543. struct halmac_adapter *mac;
  3544. struct halmac_api *api;
  3545. struct halmac_pg_efuse_info pginfo;
  3546. enum halmac_ret_status status;
  3547. mac = dvobj_to_halmac(d);
  3548. api = HALMAC_GET_API(mac);
  3549. pginfo.efuse_map = map;
  3550. pginfo.efuse_map_size = size;
  3551. pginfo.efuse_mask = maskmap;
  3552. pginfo.efuse_mask_size = masksize;
  3553. status = api->halmac_pg_efuse_by_map(mac, &pginfo, HALMAC_EFUSE_R_AUTO);
  3554. if (HALMAC_RET_SUCCESS != status)
  3555. return -1;
  3556. return 0;
  3557. }
  3558. int rtw_halmac_read_logical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
  3559. {
  3560. struct halmac_adapter *mac;
  3561. struct halmac_api *api;
  3562. enum halmac_ret_status status;
  3563. u8 v;
  3564. u32 i;
  3565. mac = dvobj_to_halmac(d);
  3566. api = HALMAC_GET_API(mac);
  3567. for (i = 0; i < cnt; i++) {
  3568. status = api->halmac_read_logical_efuse(mac, offset + i, &v);
  3569. if (HALMAC_RET_SUCCESS != status)
  3570. return -1;
  3571. data[i] = v;
  3572. }
  3573. return 0;
  3574. }
  3575. int rtw_halmac_write_logical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
  3576. {
  3577. struct halmac_adapter *mac;
  3578. struct halmac_api *api;
  3579. enum halmac_ret_status status;
  3580. u32 i;
  3581. mac = dvobj_to_halmac(d);
  3582. api = HALMAC_GET_API(mac);
  3583. for (i = 0; i < cnt; i++) {
  3584. status = api->halmac_write_logical_efuse(mac, offset + i, data[i]);
  3585. if (HALMAC_RET_SUCCESS != status)
  3586. return -1;
  3587. }
  3588. return 0;
  3589. }
  3590. int rtw_halmac_write_bt_physical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
  3591. {
  3592. struct halmac_adapter *mac;
  3593. struct halmac_api *api;
  3594. enum halmac_ret_status status;
  3595. u32 i;
  3596. u8 bank = 1;
  3597. mac = dvobj_to_halmac(d);
  3598. api = HALMAC_GET_API(mac);
  3599. for (i = 0; i < cnt; i++) {
  3600. status = api->halmac_write_efuse_bt(mac, offset + i, data[i], bank);
  3601. if (HALMAC_RET_SUCCESS != status) {
  3602. printk("%s: halmac_write_efuse_bt status = %d\n", __FUNCTION__, status);
  3603. return -1;
  3604. }
  3605. }
  3606. printk("%s: halmac_write_efuse_bt status = HALMAC_RET_SUCCESS %d\n", __FUNCTION__, status);
  3607. return 0;
  3608. }
  3609. int rtw_halmac_read_bt_physical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size)
  3610. {
  3611. struct halmac_adapter *mac;
  3612. struct halmac_api *api;
  3613. enum halmac_ret_status status;
  3614. int bank = 1;
  3615. mac = dvobj_to_halmac(d);
  3616. api = HALMAC_GET_API(mac);
  3617. status = api->halmac_dump_efuse_map_bt(mac, bank, size, map);
  3618. if (HALMAC_RET_SUCCESS != status) {
  3619. printk("%s: halmac_dump_efuse_map_bt fail!\n", __FUNCTION__);
  3620. return -1;
  3621. }
  3622. printk("%s: OK!\n", __FUNCTION__);
  3623. return 0;
  3624. }
  3625. static enum hal_fifo_sel _fifo_sel_drv2halmac(u8 fifo_sel)
  3626. {
  3627. switch (fifo_sel) {
  3628. case 0:
  3629. return HAL_FIFO_SEL_TX;
  3630. case 1:
  3631. return HAL_FIFO_SEL_RX;
  3632. case 2:
  3633. return HAL_FIFO_SEL_RSVD_PAGE;
  3634. case 3:
  3635. return HAL_FIFO_SEL_REPORT;
  3636. case 4:
  3637. return HAL_FIFO_SEL_LLT;
  3638. case 5:
  3639. return HAL_FIFO_SEL_RXBUF_FW;
  3640. }
  3641. return HAL_FIFO_SEL_RSVD_PAGE;
  3642. }
  3643. /*#define CONFIG_HALMAC_FIFO_DUMP*/
  3644. int rtw_halmac_dump_fifo(struct dvobj_priv *d, u8 fifo_sel, u32 addr, u32 size, u8 *buffer)
  3645. {
  3646. struct halmac_adapter *mac;
  3647. struct halmac_api *api;
  3648. enum hal_fifo_sel halmac_fifo_sel;
  3649. enum halmac_ret_status status;
  3650. u8 *pfifo_map = NULL;
  3651. u32 fifo_size = 0;
  3652. s8 ret = 0;/* 0:success, -1:error */
  3653. u8 mem_created = _FALSE;
  3654. mac = dvobj_to_halmac(d);
  3655. api = HALMAC_GET_API(mac);
  3656. if ((size != 0) && (buffer == NULL))
  3657. return -1;
  3658. halmac_fifo_sel = _fifo_sel_drv2halmac(fifo_sel);
  3659. if ((size) && (buffer)) {
  3660. pfifo_map = buffer;
  3661. fifo_size = size;
  3662. } else {
  3663. fifo_size = api->halmac_get_fifo_size(mac, halmac_fifo_sel);
  3664. if (fifo_size)
  3665. pfifo_map = rtw_zvmalloc(fifo_size);
  3666. if (pfifo_map == NULL)
  3667. return -1;
  3668. mem_created = _TRUE;
  3669. }
  3670. status = api->halmac_dump_fifo(mac, halmac_fifo_sel, addr, fifo_size, pfifo_map);
  3671. if (HALMAC_RET_SUCCESS != status) {
  3672. ret = -1;
  3673. goto _exit;
  3674. }
  3675. #ifdef CONFIG_HALMAC_FIFO_DUMP
  3676. {
  3677. static const char * const fifo_sel_str[] = {
  3678. "TX", "RX", "RSVD_PAGE", "REPORT", "LLT", "RXBUF_FW"
  3679. };
  3680. RTW_INFO("%s FIFO DUMP [start_addr:0x%04x , size:%d]\n", fifo_sel_str[halmac_fifo_sel], addr, fifo_size);
  3681. RTW_INFO_DUMP("\n", pfifo_map, fifo_size);
  3682. RTW_INFO(" ==================================================\n");
  3683. }
  3684. #endif /* CONFIG_HALMAC_FIFO_DUMP */
  3685. _exit:
  3686. if ((mem_created == _TRUE) && pfifo_map)
  3687. rtw_vmfree(pfifo_map, fifo_size);
  3688. return ret;
  3689. }
  3690. /*
  3691. * rtw_halmac_rx_agg_switch() - Switch RX aggregation function and setting
  3692. * @d struct dvobj_priv *
  3693. * @enable _FALSE/_TRUE for disable/enable RX aggregation function
  3694. *
  3695. * This function could help to on/off bus RX aggregation function, and is only
  3696. * useful for SDIO and USB interface. Although only "enable" flag is brough in,
  3697. * some setting would be taken from other places, and they are from:
  3698. * [DMA aggregation]
  3699. * struct hal_com_data.rxagg_dma_size
  3700. * struct hal_com_data.rxagg_dma_timeout
  3701. * [USB aggregation] (only use for USB interface)
  3702. * struct hal_com_data.rxagg_usb_size
  3703. * struct hal_com_data.rxagg_usb_timeout
  3704. * If above values of size and timeout are both 0 means driver would not
  3705. * control the threshold setting and leave it to HALMAC handle.
  3706. *
  3707. * From HALMAC V1_04_04, driver force the size threshold be hard limit, and the
  3708. * rx size can not exceed the setting.
  3709. *
  3710. * Return 0 for success, otherwise fail.
  3711. */
  3712. int rtw_halmac_rx_agg_switch(struct dvobj_priv *d, u8 enable)
  3713. {
  3714. struct _ADAPTER *adapter;
  3715. struct hal_com_data *hal;
  3716. struct halmac_adapter *halmac;
  3717. struct halmac_api *api;
  3718. struct halmac_rxagg_cfg rxaggcfg;
  3719. enum halmac_ret_status status;
  3720. adapter = dvobj_get_primary_adapter(d);
  3721. hal = GET_HAL_DATA(adapter);
  3722. halmac = dvobj_to_halmac(d);
  3723. api = HALMAC_GET_API(halmac);
  3724. _rtw_memset((void *)&rxaggcfg, 0, sizeof(rxaggcfg));
  3725. rxaggcfg.mode = HALMAC_RX_AGG_MODE_NONE;
  3726. /*
  3727. * Always enable size limit to avoid rx size exceed
  3728. * driver defined size.
  3729. */
  3730. rxaggcfg.threshold.size_limit_en = 1;
  3731. #ifdef RTW_RX_AGGREGATION
  3732. if (_TRUE == enable) {
  3733. #ifdef CONFIG_SDIO_HCI
  3734. rxaggcfg.mode = HALMAC_RX_AGG_MODE_DMA;
  3735. rxaggcfg.threshold.drv_define = 0;
  3736. if (hal->rxagg_dma_size || hal->rxagg_dma_timeout) {
  3737. rxaggcfg.threshold.drv_define = 1;
  3738. rxaggcfg.threshold.timeout = hal->rxagg_dma_timeout;
  3739. rxaggcfg.threshold.size = hal->rxagg_dma_size;
  3740. RTW_INFO("%s: RX aggregation threshold: "
  3741. "timeout=%u size=%u\n",
  3742. __FUNCTION__,
  3743. hal->rxagg_dma_timeout,
  3744. hal->rxagg_dma_size);
  3745. }
  3746. #elif defined(CONFIG_USB_HCI)
  3747. switch (hal->rxagg_mode) {
  3748. case RX_AGG_DISABLE:
  3749. rxaggcfg.mode = HALMAC_RX_AGG_MODE_NONE;
  3750. break;
  3751. case RX_AGG_DMA:
  3752. rxaggcfg.mode = HALMAC_RX_AGG_MODE_DMA;
  3753. if (hal->rxagg_dma_size || hal->rxagg_dma_timeout) {
  3754. rxaggcfg.threshold.drv_define = 1;
  3755. rxaggcfg.threshold.timeout = hal->rxagg_dma_timeout;
  3756. rxaggcfg.threshold.size = hal->rxagg_dma_size;
  3757. }
  3758. break;
  3759. case RX_AGG_USB:
  3760. case RX_AGG_MIX:
  3761. rxaggcfg.mode = HALMAC_RX_AGG_MODE_USB;
  3762. if (hal->rxagg_usb_size || hal->rxagg_usb_timeout) {
  3763. rxaggcfg.threshold.drv_define = 1;
  3764. rxaggcfg.threshold.timeout = hal->rxagg_usb_timeout;
  3765. rxaggcfg.threshold.size = hal->rxagg_usb_size;
  3766. }
  3767. break;
  3768. }
  3769. #endif /* CONFIG_USB_HCI */
  3770. }
  3771. #endif /* RTW_RX_AGGREGATION */
  3772. status = api->halmac_cfg_rx_aggregation(halmac, &rxaggcfg);
  3773. if (status != HALMAC_RET_SUCCESS)
  3774. return -1;
  3775. return 0;
  3776. }
  3777. int rtw_halmac_download_rsvd_page(struct dvobj_priv *dvobj, u8 pg_offset, u8 *pbuf, u32 size)
  3778. {
  3779. enum halmac_ret_status status = HALMAC_RET_SUCCESS;
  3780. struct halmac_adapter *halmac = dvobj_to_halmac(dvobj);
  3781. struct halmac_api *api = HALMAC_GET_API(halmac);
  3782. status = api->halmac_dl_drv_rsvd_page(halmac, pg_offset, pbuf, size);
  3783. if (status != HALMAC_RET_SUCCESS)
  3784. return -1;
  3785. return 0;
  3786. }
  3787. /*
  3788. * Description
  3789. * Fill following spec info from HALMAC API:
  3790. * sec_cam_ent_num
  3791. *
  3792. * Return
  3793. * 0 Success
  3794. * others Fail
  3795. */
  3796. int rtw_halmac_fill_hal_spec(struct dvobj_priv *dvobj, struct hal_spec_t *spec)
  3797. {
  3798. enum halmac_ret_status status;
  3799. struct halmac_adapter *halmac;
  3800. struct halmac_api *api;
  3801. u8 cam = 0; /* Security Cam Entry Number */
  3802. halmac = dvobj_to_halmac(dvobj);
  3803. api = HALMAC_GET_API(halmac);
  3804. /* Prepare data from HALMAC */
  3805. status = api->halmac_get_hw_value(halmac, HALMAC_HW_CAM_ENTRY_NUM, &cam);
  3806. if (status != HALMAC_RET_SUCCESS)
  3807. return -1;
  3808. /* Fill data to hal_spec_t */
  3809. spec->sec_cam_ent_num = cam;
  3810. return 0;
  3811. }
  3812. int rtw_halmac_p2pps(struct dvobj_priv *dvobj, struct hal_p2p_ps_para *pp2p_ps_para)
  3813. {
  3814. enum halmac_ret_status status = HALMAC_RET_SUCCESS;
  3815. struct halmac_adapter *halmac = dvobj_to_halmac(dvobj);
  3816. struct halmac_api *api = HALMAC_GET_API(halmac);
  3817. struct halmac_p2pps halmac_p2p_ps;
  3818. (&halmac_p2p_ps)->offload_en = pp2p_ps_para->offload_en;
  3819. (&halmac_p2p_ps)->role = pp2p_ps_para->role;
  3820. (&halmac_p2p_ps)->ctwindow_en = pp2p_ps_para->ctwindow_en;
  3821. (&halmac_p2p_ps)->noa_en = pp2p_ps_para->noa_en;
  3822. (&halmac_p2p_ps)->noa_sel = pp2p_ps_para->noa_sel;
  3823. (&halmac_p2p_ps)->all_sta_sleep = pp2p_ps_para->all_sta_sleep;
  3824. (&halmac_p2p_ps)->discovery = pp2p_ps_para->discovery;
  3825. (&halmac_p2p_ps)->disable_close_rf = pp2p_ps_para->disable_close_rf;
  3826. (&halmac_p2p_ps)->p2p_port_id = _hw_port_drv2halmac(pp2p_ps_para->p2p_port_id);
  3827. (&halmac_p2p_ps)->p2p_group = pp2p_ps_para->p2p_group;
  3828. (&halmac_p2p_ps)->p2p_macid = pp2p_ps_para->p2p_macid;
  3829. (&halmac_p2p_ps)->ctwindow_length = pp2p_ps_para->ctwindow_length;
  3830. (&halmac_p2p_ps)->noa_duration_para = pp2p_ps_para->noa_duration_para;
  3831. (&halmac_p2p_ps)->noa_interval_para = pp2p_ps_para->noa_interval_para;
  3832. (&halmac_p2p_ps)->noa_start_time_para = pp2p_ps_para->noa_start_time_para;
  3833. (&halmac_p2p_ps)->noa_count_para = pp2p_ps_para->noa_count_para;
  3834. status = api->halmac_p2pps(halmac, (&halmac_p2p_ps));
  3835. if (status != HALMAC_RET_SUCCESS)
  3836. return -1;
  3837. return 0;
  3838. }
  3839. /**
  3840. * rtw_halmac_iqk() - Run IQ Calibration
  3841. * @d: struct dvobj_priv*
  3842. * @clear: IQK parameters
  3843. * @segment: IQK parameters
  3844. *
  3845. * Process IQ Calibration(IQK).
  3846. *
  3847. * Return 0 for OK, otherwise fail.
  3848. */
  3849. int rtw_halmac_iqk(struct dvobj_priv *d, u8 clear, u8 segment)
  3850. {
  3851. struct halmac_adapter *mac;
  3852. struct halmac_api *api;
  3853. enum halmac_ret_status status;
  3854. enum halmac_feature_id id;
  3855. struct halmac_iqk_para para;
  3856. int ret;
  3857. u8 retry = 3;
  3858. u8 delay = 1; /* ms */
  3859. mac = dvobj_to_halmac(d);
  3860. api = HALMAC_GET_API(mac);
  3861. id = HALMAC_FEATURE_IQK;
  3862. ret = init_halmac_event(d, id, NULL, 0);
  3863. if (ret)
  3864. return -1;
  3865. para.clear = clear;
  3866. para.segment_iqk = segment;
  3867. do {
  3868. status = api->halmac_start_iqk(mac, &para);
  3869. if (status != HALMAC_RET_BUSY_STATE)
  3870. break;
  3871. RTW_WARN("%s: Fail to start IQK, status is BUSY! retry=%d\n", __FUNCTION__, retry);
  3872. if (!retry)
  3873. break;
  3874. retry--;
  3875. rtw_msleep_os(delay);
  3876. } while (1);
  3877. if (status != HALMAC_RET_SUCCESS) {
  3878. free_halmac_event(d, id);
  3879. return -1;
  3880. }
  3881. ret = wait_halmac_event(d, id);
  3882. if (ret)
  3883. return -1;
  3884. return 0;
  3885. }
  3886. static inline u32 _phy_parameter_val_drv2halmac(u32 val, u8 msk_en, u32 msk)
  3887. {
  3888. if (!msk_en)
  3889. return val;
  3890. return (val << bitshift(msk));
  3891. }
  3892. static int _phy_parameter_drv2halmac(struct rtw_phy_parameter *para, struct halmac_phy_parameter_info *info)
  3893. {
  3894. if (!para || !info)
  3895. return -1;
  3896. _rtw_memset(info, 0, sizeof(*info));
  3897. switch (para->cmd) {
  3898. case 0:
  3899. /* MAC register */
  3900. switch (para->data.mac.size) {
  3901. case 1:
  3902. info->cmd_id = HALMAC_PARAMETER_CMD_MAC_W8;
  3903. break;
  3904. case 2:
  3905. info->cmd_id = HALMAC_PARAMETER_CMD_MAC_W16;
  3906. break;
  3907. default:
  3908. info->cmd_id = HALMAC_PARAMETER_CMD_MAC_W32;
  3909. break;
  3910. }
  3911. info->content.MAC_REG_W.value = _phy_parameter_val_drv2halmac(
  3912. para->data.mac.value,
  3913. para->data.mac.msk_en,
  3914. para->data.mac.msk);
  3915. info->content.MAC_REG_W.msk = para->data.mac.msk;
  3916. info->content.MAC_REG_W.offset = para->data.mac.offset;
  3917. info->content.MAC_REG_W.msk_en = para->data.mac.msk_en;
  3918. break;
  3919. case 1:
  3920. /* BB register */
  3921. switch (para->data.bb.size) {
  3922. case 1:
  3923. info->cmd_id = HALMAC_PARAMETER_CMD_BB_W8;
  3924. break;
  3925. case 2:
  3926. info->cmd_id = HALMAC_PARAMETER_CMD_BB_W16;
  3927. break;
  3928. default:
  3929. info->cmd_id = HALMAC_PARAMETER_CMD_BB_W32;
  3930. break;
  3931. }
  3932. info->content.BB_REG_W.value = _phy_parameter_val_drv2halmac(
  3933. para->data.bb.value,
  3934. para->data.bb.msk_en,
  3935. para->data.bb.msk);
  3936. info->content.BB_REG_W.msk = para->data.bb.msk;
  3937. info->content.BB_REG_W.offset = para->data.bb.offset;
  3938. info->content.BB_REG_W.msk_en = para->data.bb.msk_en;
  3939. break;
  3940. case 2:
  3941. /* RF register */
  3942. info->cmd_id = HALMAC_PARAMETER_CMD_RF_W;
  3943. info->content.RF_REG_W.value = _phy_parameter_val_drv2halmac(
  3944. para->data.rf.value,
  3945. para->data.rf.msk_en,
  3946. para->data.rf.msk);
  3947. info->content.RF_REG_W.msk = para->data.rf.msk;
  3948. info->content.RF_REG_W.offset = para->data.rf.offset;
  3949. info->content.RF_REG_W.msk_en = para->data.rf.msk_en;
  3950. info->content.RF_REG_W.rf_path = para->data.rf.path;
  3951. break;
  3952. case 3:
  3953. /* Delay register */
  3954. if (para->data.delay.unit == 0)
  3955. info->cmd_id = HALMAC_PARAMETER_CMD_DELAY_US;
  3956. else
  3957. info->cmd_id = HALMAC_PARAMETER_CMD_DELAY_MS;
  3958. info->content.DELAY_TIME.delay_time = para->data.delay.value;
  3959. break;
  3960. case 0xFF:
  3961. /* Latest(End) command */
  3962. info->cmd_id = HALMAC_PARAMETER_CMD_END;
  3963. break;
  3964. default:
  3965. return -1;
  3966. }
  3967. return 0;
  3968. }
  3969. /**
  3970. * rtw_halmac_cfg_phy_para() - Register(Phy parameter) configuration
  3971. * @d: struct dvobj_priv*
  3972. * @para: phy parameter
  3973. *
  3974. * Configure registers by firmware using H2C/C2H mechanism.
  3975. * The latest command should be para->cmd==0xFF(End command) to finish all
  3976. * processes.
  3977. *
  3978. * Return: 0 for OK, otherwise fail.
  3979. */
  3980. int rtw_halmac_cfg_phy_para(struct dvobj_priv *d, struct rtw_phy_parameter *para)
  3981. {
  3982. struct halmac_adapter *mac;
  3983. struct halmac_api *api;
  3984. enum halmac_ret_status status;
  3985. enum halmac_feature_id id;
  3986. struct halmac_phy_parameter_info info;
  3987. u8 full_fifo;
  3988. int err, ret;
  3989. mac = dvobj_to_halmac(d);
  3990. api = HALMAC_GET_API(mac);
  3991. id = HALMAC_FEATURE_CFG_PARA;
  3992. full_fifo = 1; /* ToDo: How to deciede? */
  3993. ret = 0;
  3994. err = _phy_parameter_drv2halmac(para, &info);
  3995. if (err)
  3996. return -1;
  3997. err = init_halmac_event(d, id, NULL, 0);
  3998. if (err)
  3999. return -1;
  4000. status = api->halmac_cfg_parameter(mac, &info, full_fifo);
  4001. if (info.cmd_id == HALMAC_PARAMETER_CMD_END) {
  4002. if (status == HALMAC_RET_SUCCESS) {
  4003. err = wait_halmac_event(d, id);
  4004. if (err)
  4005. ret = -1;
  4006. } else {
  4007. free_halmac_event(d, id);
  4008. ret = -1;
  4009. RTW_ERR("%s: Fail to send END of cfg parameter, status is 0x%x!\n", __FUNCTION__, status);
  4010. }
  4011. } else {
  4012. if (status == HALMAC_RET_PARA_SENDING) {
  4013. err = wait_halmac_event(d, id);
  4014. if (err)
  4015. ret = -1;
  4016. } else {
  4017. free_halmac_event(d, id);
  4018. if (status != HALMAC_RET_SUCCESS) {
  4019. ret = -1;
  4020. RTW_ERR("%s: Fail to cfg parameter, status is 0x%x!\n", __FUNCTION__, status);
  4021. }
  4022. }
  4023. }
  4024. return ret;
  4025. }
  4026. static enum halmac_wlled_mode _led_mode_drv2halmac(u8 drv_mode)
  4027. {
  4028. enum halmac_wlled_mode halmac_mode;
  4029. switch (drv_mode) {
  4030. case 1:
  4031. halmac_mode = HALMAC_WLLED_MODE_TX;
  4032. break;
  4033. case 2:
  4034. halmac_mode = HALMAC_WLLED_MODE_RX;
  4035. break;
  4036. case 3:
  4037. halmac_mode = HALMAC_WLLED_MODE_SW_CTRL;
  4038. break;
  4039. case 0:
  4040. default:
  4041. halmac_mode = HALMAC_WLLED_MODE_TRX;
  4042. break;
  4043. }
  4044. return halmac_mode;
  4045. }
  4046. /**
  4047. * rtw_halmac_led_cfg() - Configure Hardware LED Mode
  4048. * @d: struct dvobj_priv*
  4049. * @enable: enable or disable LED function
  4050. * 0: disable
  4051. * 1: enable
  4052. * @mode: WLan LED mode (valid when enable==1)
  4053. * 0: Blink when TX(transmit packet) and RX(receive packet)
  4054. * 1: Blink when TX only
  4055. * 2: Blink when RX only
  4056. * 3: Software control
  4057. *
  4058. * Configure hardware WLan LED mode.
  4059. * If want to change LED mode after enabled, need to disable LED first and
  4060. * enable again to set new mode.
  4061. *
  4062. * Return 0 for OK, otherwise fail.
  4063. */
  4064. int rtw_halmac_led_cfg(struct dvobj_priv *d, u8 enable, u8 mode)
  4065. {
  4066. struct halmac_adapter *halmac;
  4067. struct halmac_api *api;
  4068. enum halmac_wlled_mode led_mode;
  4069. enum halmac_ret_status status;
  4070. halmac = dvobj_to_halmac(d);
  4071. api = HALMAC_GET_API(halmac);
  4072. if (enable) {
  4073. status = api->halmac_pinmux_set_func(halmac,
  4074. HALMAC_GPIO_FUNC_WL_LED);
  4075. if (status != HALMAC_RET_SUCCESS) {
  4076. RTW_ERR("%s: pinmux set fail!(0x%x)\n",
  4077. __FUNCTION__, status);
  4078. return -1;
  4079. }
  4080. led_mode = _led_mode_drv2halmac(mode);
  4081. status = api->halmac_pinmux_wl_led_mode(halmac, led_mode);
  4082. if (status != HALMAC_RET_SUCCESS) {
  4083. RTW_ERR("%s: mode set fail!(0x%x)\n",
  4084. __FUNCTION__, status);
  4085. return -1;
  4086. }
  4087. } else {
  4088. /* Change LED to software control and turn off */
  4089. api->halmac_pinmux_wl_led_mode(halmac,
  4090. HALMAC_WLLED_MODE_SW_CTRL);
  4091. api->halmac_pinmux_wl_led_sw_ctrl(halmac, 0);
  4092. status = api->halmac_pinmux_free_func(halmac,
  4093. HALMAC_GPIO_FUNC_WL_LED);
  4094. if (status != HALMAC_RET_SUCCESS) {
  4095. RTW_ERR("%s: pinmux free fail!(0x%x)\n",
  4096. __FUNCTION__, status);
  4097. return -1;
  4098. }
  4099. }
  4100. return 0;
  4101. }
  4102. /**
  4103. * rtw_halmac_led_switch() - Turn Hardware LED on/off
  4104. * @d: struct dvobj_priv*
  4105. * @on: LED light or not
  4106. * 0: Off
  4107. * 1: On(Light)
  4108. *
  4109. * Turn Hardware WLan LED On/Off.
  4110. * Before use this function, user should call rtw_halmac_led_ctrl() to switch
  4111. * mode to "software control(3)" first, otherwise control would fail.
  4112. * The interval between on and off must be longer than 1 ms, or the LED would
  4113. * keep light or dark only.
  4114. * Ex. Turn off LED at first, turn on after 0.5ms and turn off again after
  4115. * 0.5ms. The LED during this flow will only keep dark, and miss the turn on
  4116. * operation between two turn off operations.
  4117. */
  4118. void rtw_halmac_led_switch(struct dvobj_priv *d, u8 on)
  4119. {
  4120. struct halmac_adapter *halmac;
  4121. struct halmac_api *api;
  4122. halmac = dvobj_to_halmac(d);
  4123. api = HALMAC_GET_API(halmac);
  4124. api->halmac_pinmux_wl_led_sw_ctrl(halmac, on);
  4125. }
  4126. /**
  4127. * rtw_halmac_bt_wake_cfg() - Configure BT wake host function
  4128. * @d: struct dvobj_priv*
  4129. * @enable: enable or disable BT wake host function
  4130. * 0: disable
  4131. * 1: enable
  4132. *
  4133. * Configure pinmux to allow BT to control BT wake host pin.
  4134. *
  4135. * Return 0 for OK, otherwise fail.
  4136. */
  4137. int rtw_halmac_bt_wake_cfg(struct dvobj_priv *d, u8 enable)
  4138. {
  4139. struct halmac_adapter *halmac;
  4140. struct halmac_api *api;
  4141. enum halmac_ret_status status;
  4142. halmac = dvobj_to_halmac(d);
  4143. api = HALMAC_GET_API(halmac);
  4144. if (enable) {
  4145. status = api->halmac_pinmux_set_func(halmac,
  4146. HALMAC_GPIO_FUNC_BT_HOST_WAKE1);
  4147. if (status != HALMAC_RET_SUCCESS) {
  4148. RTW_ERR("%s: pinmux set BT_HOST_WAKE1 fail!(0x%x)\n",
  4149. __FUNCTION__, status);
  4150. return -1;
  4151. }
  4152. } else {
  4153. status = api->halmac_pinmux_free_func(halmac,
  4154. HALMAC_GPIO_FUNC_BT_HOST_WAKE1);
  4155. if (status != HALMAC_RET_SUCCESS) {
  4156. RTW_ERR("%s: pinmux free BT_HOST_WAKE1 fail!(0x%x)\n",
  4157. __FUNCTION__, status);
  4158. return -1;
  4159. }
  4160. }
  4161. return 0;
  4162. }
  4163. #ifdef CONFIG_PNO_SUPPORT
  4164. /**
  4165. * _halmac_scanoffload() - Switch channel by firmware during scanning
  4166. * @d: struct dvobj_priv*
  4167. * @enable: 1: enable, 0: disable
  4168. * @nlo: 1: nlo mode (no c2h event), 0: normal mode
  4169. * @ssid: ssid of probe request
  4170. * @ssid_len: ssid length
  4171. *
  4172. * Switch Channel and Send Porbe Request Offloaded by FW
  4173. *
  4174. * Return 0 for OK, otherwise fail.
  4175. */
  4176. static int _halmac_scanoffload(struct dvobj_priv *d, u32 enable, u8 nlo,
  4177. u8 *ssid, u8 ssid_len)
  4178. {
  4179. struct _ADAPTER *adapter;
  4180. struct halmac_adapter *mac;
  4181. struct halmac_api *api;
  4182. enum halmac_ret_status status;
  4183. struct halmac_ch_info ch_info;
  4184. struct halmac_ch_switch_option cs_option;
  4185. struct mlme_ext_priv *pmlmeext;
  4186. enum halmac_feature_id id_update, id_ch_sw;
  4187. struct halmac_indicator *indicator, *tbl;
  4188. int err = 0;
  4189. u8 probereq[64];
  4190. u32 len = 0;
  4191. int i = 0;
  4192. struct pno_ssid pnossid;
  4193. struct rf_ctl_t *rfctl = NULL;
  4194. struct _RT_CHANNEL_INFO *ch_set;
  4195. tbl = d->hmpriv.indicator;
  4196. adapter = dvobj_get_primary_adapter(d);
  4197. mac = dvobj_to_halmac(d);
  4198. if (!mac)
  4199. return -1;
  4200. api = HALMAC_GET_API(mac);
  4201. id_update = HALMAC_FEATURE_UPDATE_PACKET;
  4202. id_ch_sw = HALMAC_FEATURE_CHANNEL_SWITCH;
  4203. pmlmeext = &(adapter->mlmeextpriv);
  4204. rfctl = adapter_to_rfctl(adapter);
  4205. ch_set = rfctl->channel_set;
  4206. RTW_INFO("%s: %s scanoffload, mode: %s\n",
  4207. __FUNCTION__, enable?"Enable":"Disable",
  4208. nlo?"PNO/NLO":"Normal");
  4209. if (enable) {
  4210. _rtw_memset(probereq, 0, sizeof(probereq));
  4211. _rtw_memset(&pnossid, 0, sizeof(pnossid));
  4212. if (ssid) {
  4213. if (ssid_len > sizeof(pnossid.SSID)) {
  4214. RTW_ERR("%s: SSID length(%d) is too long(>%d)!!\n",
  4215. __FUNCTION__, ssid_len, sizeof(pnossid.SSID));
  4216. return -1;
  4217. }
  4218. pnossid.SSID_len = ssid_len;
  4219. _rtw_memcpy(pnossid.SSID, ssid, ssid_len);
  4220. }
  4221. rtw_hal_construct_ProbeReq(adapter, probereq, &len, &pnossid);
  4222. if (!nlo) {
  4223. err = init_halmac_event(d, id_update, NULL, 0);
  4224. if (err)
  4225. return -1;
  4226. }
  4227. status = api->halmac_update_packet(mac, HALMAC_PACKET_PROBE_REQ,
  4228. probereq, len);
  4229. if (status != HALMAC_RET_SUCCESS) {
  4230. if (!nlo)
  4231. free_halmac_event(d, id_update);
  4232. RTW_ERR("%s: halmac_update_packet FAIL(%d)!!\n",
  4233. __FUNCTION__, status);
  4234. return -1;
  4235. }
  4236. if (!nlo) {
  4237. err = wait_halmac_event(d, id_update);
  4238. if (err)
  4239. RTW_ERR("%s: wait update packet FAIL(%d)!!\n",
  4240. __FUNCTION__, err);
  4241. }
  4242. api->halmac_clear_ch_info(mac);
  4243. for (i = 0; i < rfctl->max_chan_nums && ch_set[i].ChannelNum != 0; i++) {
  4244. _rtw_memset(&ch_info, 0, sizeof(ch_info));
  4245. ch_info.extra_info = 0;
  4246. ch_info.channel = ch_set[i].ChannelNum;
  4247. ch_info.bw = HALMAC_BW_20;
  4248. ch_info.pri_ch_idx = HALMAC_CH_IDX_1;
  4249. ch_info.action_id = HALMAC_CS_ACTIVE_SCAN;
  4250. ch_info.timeout = 1;
  4251. status = api->halmac_add_ch_info(mac, &ch_info);
  4252. if (status != HALMAC_RET_SUCCESS) {
  4253. RTW_ERR("%s: add_ch_info FAIL(%d)!!\n",
  4254. __FUNCTION__, status);
  4255. return -1;
  4256. }
  4257. }
  4258. /* set channel switch option */
  4259. _rtw_memset(&cs_option, 0, sizeof(cs_option));
  4260. cs_option.dest_bw = HALMAC_BW_20;
  4261. cs_option.periodic_option = HALMAC_CS_PERIODIC_2_PHASE;
  4262. cs_option.dest_pri_ch_idx = HALMAC_CH_IDX_UNDEFINE;
  4263. cs_option.tsf_low = 0;
  4264. cs_option.switch_en = 1;
  4265. cs_option.dest_ch_en = 1;
  4266. cs_option.absolute_time_en = 0;
  4267. cs_option.dest_ch = 1;
  4268. cs_option.normal_period = 5;
  4269. cs_option.normal_period_sel = 0;
  4270. cs_option.normal_cycle = 10;
  4271. cs_option.phase_2_period = 1;
  4272. cs_option.phase_2_period_sel = 1;
  4273. /* nlo is for wow fw, 1: no c2h response */
  4274. cs_option.nlo_en = nlo;
  4275. if (!nlo) {
  4276. err = init_halmac_event(d, id_ch_sw, NULL, 0);
  4277. if (err)
  4278. return -1;
  4279. }
  4280. status = api->halmac_ctrl_ch_switch(mac, &cs_option);
  4281. if (status != HALMAC_RET_SUCCESS) {
  4282. if (!nlo)
  4283. free_halmac_event(d, id_ch_sw);
  4284. RTW_ERR("%s: halmac_ctrl_ch_switch FAIL(%d)!!\n",
  4285. __FUNCTION__, status);
  4286. return -1;
  4287. }
  4288. if (!nlo) {
  4289. err = wait_halmac_event(d, id_ch_sw);
  4290. if (err)
  4291. RTW_ERR("%s: wait ctrl_ch_switch FAIL(%d)!!\n",
  4292. __FUNCTION__, err);
  4293. }
  4294. } else {
  4295. api->halmac_clear_ch_info(mac);
  4296. _rtw_memset(&cs_option, 0, sizeof(cs_option));
  4297. cs_option.switch_en = 0;
  4298. if (!nlo) {
  4299. err = init_halmac_event(d, id_ch_sw, NULL, 0);
  4300. if (err)
  4301. return -1;
  4302. }
  4303. status = api->halmac_ctrl_ch_switch(mac, &cs_option);
  4304. if (status != HALMAC_RET_SUCCESS) {
  4305. if (!nlo)
  4306. free_halmac_event(d, id_ch_sw);
  4307. RTW_ERR("%s: halmac_ctrl_ch_switch FAIL(%d)!!\n",
  4308. __FUNCTION__, status);
  4309. return -1;
  4310. }
  4311. if (!nlo) {
  4312. err = wait_halmac_event(d, id_ch_sw);
  4313. if (err)
  4314. RTW_ERR("%s: wait ctrl_ch_switch FAIL(%d)!!\n",
  4315. __FUNCTION__, err);
  4316. }
  4317. }
  4318. return 0;
  4319. }
  4320. /**
  4321. * rtw_halmac_pno_scanoffload() - Control firmware scan AP function for PNO
  4322. * @d: struct dvobj_priv*
  4323. * @enable: 1: enable, 0: disable
  4324. *
  4325. * Switch firmware scan AP function for PNO(prefer network offload) or
  4326. * NLO(network list offload).
  4327. *
  4328. * Return 0 for OK, otherwise fail.
  4329. */
  4330. int rtw_halmac_pno_scanoffload(struct dvobj_priv *d, u32 enable)
  4331. {
  4332. return _halmac_scanoffload(d, enable, 1, NULL, 0);
  4333. }
  4334. #endif /* CONFIG_PNO_SUPPORT */
  4335. #ifdef CONFIG_SDIO_HCI
  4336. /**
  4337. * rtw_halmac_preinit_sdio_io_indirect() - Enable indirect I/O or not
  4338. * @d: struct dvobj_priv*
  4339. * @enable: true: enable, false: disable
  4340. *
  4341. * Enable register access using direct I/O or indirect. This function should be
  4342. * called before rtw_halmac_init_adapter(), and the life cycle is the same as
  4343. * driver until removing driver.
  4344. *
  4345. * Return 0 for OK, otherwise fail.
  4346. */
  4347. int rtw_halmac_preinit_sdio_io_indirect(struct dvobj_priv *d, bool enable)
  4348. {
  4349. struct halmac_adapter *halmac;
  4350. struct halmacpriv *priv;
  4351. halmac = dvobj_to_halmac(d);
  4352. if (halmac) {
  4353. RTW_WARN("%s: illegal operation! "
  4354. "preinit function only could be called before init!\n",
  4355. __FUNCTION__);
  4356. return -1;
  4357. }
  4358. priv = &d->hmpriv;
  4359. priv->sdio_io_indir = (enable ? 1 : 2);
  4360. return 0;
  4361. }
  4362. /*
  4363. * Description:
  4364. * Update queue allocated page number to driver
  4365. *
  4366. * Parameter:
  4367. * d pointer to struct dvobj_priv of driver
  4368. *
  4369. * Return:
  4370. * 0 Success, "page" is valid.
  4371. * others Fail, "page" is invalid.
  4372. */
  4373. int rtw_halmac_query_tx_page_num(struct dvobj_priv *d)
  4374. {
  4375. PADAPTER adapter;
  4376. struct halmacpriv *hmpriv;
  4377. struct halmac_adapter *halmac;
  4378. struct halmac_api *api;
  4379. struct halmac_rqpn_map rqpn;
  4380. enum halmac_dma_mapping dmaqueue;
  4381. struct halmac_txff_allocation fifosize;
  4382. enum halmac_ret_status status;
  4383. u8 i;
  4384. adapter = dvobj_get_primary_adapter(d);
  4385. hmpriv = &d->hmpriv;
  4386. halmac = dvobj_to_halmac(d);
  4387. api = HALMAC_GET_API(halmac);
  4388. _rtw_memset((void *)&rqpn, 0, sizeof(rqpn));
  4389. _rtw_memset((void *)&fifosize, 0, sizeof(fifosize));
  4390. status = api->halmac_get_hw_value(halmac, HALMAC_HW_RQPN_MAPPING, &rqpn);
  4391. if (status != HALMAC_RET_SUCCESS)
  4392. return -1;
  4393. status = api->halmac_get_hw_value(halmac, HALMAC_HW_TXFF_ALLOCATION, &fifosize);
  4394. if (status != HALMAC_RET_SUCCESS)
  4395. return -1;
  4396. for (i = 0; i < HW_QUEUE_ENTRY; i++) {
  4397. hmpriv->txpage[i] = 0;
  4398. /* Driver index mapping to HALMAC DMA queue */
  4399. dmaqueue = HALMAC_DMA_MAPPING_UNDEFINE;
  4400. switch (i) {
  4401. case VO_QUEUE_INX:
  4402. dmaqueue = rqpn.dma_map_vo;
  4403. break;
  4404. case VI_QUEUE_INX:
  4405. dmaqueue = rqpn.dma_map_vi;
  4406. break;
  4407. case BE_QUEUE_INX:
  4408. dmaqueue = rqpn.dma_map_be;
  4409. break;
  4410. case BK_QUEUE_INX:
  4411. dmaqueue = rqpn.dma_map_bk;
  4412. break;
  4413. case MGT_QUEUE_INX:
  4414. dmaqueue = rqpn.dma_map_mg;
  4415. break;
  4416. case HIGH_QUEUE_INX:
  4417. dmaqueue = rqpn.dma_map_hi;
  4418. break;
  4419. case BCN_QUEUE_INX:
  4420. case TXCMD_QUEUE_INX:
  4421. /* Unlimited */
  4422. hmpriv->txpage[i] = 0xFFFF;
  4423. continue;
  4424. }
  4425. switch (dmaqueue) {
  4426. case HALMAC_DMA_MAPPING_EXTRA:
  4427. hmpriv->txpage[i] = fifosize.extra_queue_pg_num;
  4428. break;
  4429. case HALMAC_DMA_MAPPING_LOW:
  4430. hmpriv->txpage[i] = fifosize.low_queue_pg_num;
  4431. break;
  4432. case HALMAC_DMA_MAPPING_NORMAL:
  4433. hmpriv->txpage[i] = fifosize.normal_queue_pg_num;
  4434. break;
  4435. case HALMAC_DMA_MAPPING_HIGH:
  4436. hmpriv->txpage[i] = fifosize.high_queue_pg_num;
  4437. break;
  4438. case HALMAC_DMA_MAPPING_UNDEFINE:
  4439. break;
  4440. }
  4441. hmpriv->txpage[i] += fifosize.pub_queue_pg_num;
  4442. }
  4443. return 0;
  4444. }
  4445. /*
  4446. * Description:
  4447. * Get specific queue allocated page number
  4448. *
  4449. * Parameter:
  4450. * d pointer to struct dvobj_priv of driver
  4451. * queue target queue to query, VO/VI/BE/BK/.../TXCMD_QUEUE_INX
  4452. * page return allocated page number
  4453. *
  4454. * Return:
  4455. * 0 Success, "page" is valid.
  4456. * others Fail, "page" is invalid.
  4457. */
  4458. int rtw_halmac_get_tx_queue_page_num(struct dvobj_priv *d, u8 queue, u32 *page)
  4459. {
  4460. *page = 0;
  4461. if (queue < HW_QUEUE_ENTRY)
  4462. *page = d->hmpriv.txpage[queue];
  4463. return 0;
  4464. }
  4465. /*
  4466. * Return:
  4467. * address for SDIO command
  4468. */
  4469. u32 rtw_halmac_sdio_get_tx_addr(struct dvobj_priv *d, u8 *desc, u32 size)
  4470. {
  4471. struct halmac_adapter *mac;
  4472. struct halmac_api *api;
  4473. enum halmac_ret_status status;
  4474. u32 addr;
  4475. mac = dvobj_to_halmac(d);
  4476. api = HALMAC_GET_API(mac);
  4477. status = api->halmac_get_sdio_tx_addr(mac, desc, size, &addr);
  4478. if (HALMAC_RET_SUCCESS != status)
  4479. return 0;
  4480. return addr;
  4481. }
  4482. int rtw_halmac_sdio_tx_allowed(struct dvobj_priv *d, u8 *buf, u32 size)
  4483. {
  4484. struct halmac_adapter *mac;
  4485. struct halmac_api *api;
  4486. enum halmac_ret_status status;
  4487. mac = dvobj_to_halmac(d);
  4488. api = HALMAC_GET_API(mac);
  4489. status = api->halmac_tx_allowed_sdio(mac, buf, size);
  4490. if (HALMAC_RET_SUCCESS != status)
  4491. return -1;
  4492. return 0;
  4493. }
  4494. u32 rtw_halmac_sdio_get_rx_addr(struct dvobj_priv *d, u8 *seq)
  4495. {
  4496. u8 id;
  4497. #define RTW_SDIO_ADDR_RX_RX0FF_PRFIX 0x0E000
  4498. #define RTW_SDIO_ADDR_RX_RX0FF_GEN(a) (RTW_SDIO_ADDR_RX_RX0FF_PRFIX|(a&0x3))
  4499. id = *seq;
  4500. (*seq)++;
  4501. return RTW_SDIO_ADDR_RX_RX0FF_GEN(id);
  4502. }
  4503. int rtw_halmac_sdio_set_tx_format(struct dvobj_priv *d, enum halmac_sdio_tx_format format)
  4504. {
  4505. struct halmac_adapter *mac;
  4506. struct halmac_api *api;
  4507. enum halmac_ret_status status;
  4508. mac = dvobj_to_halmac(d);
  4509. api = HALMAC_GET_API(mac);
  4510. status = api->halmac_set_hw_value(mac, HALMAC_HW_SDIO_TX_FORMAT, &format);
  4511. if (HALMAC_RET_SUCCESS != status)
  4512. return -1;
  4513. return 0;
  4514. }
  4515. #endif /* CONFIG_SDIO_HCI */
  4516. #ifdef CONFIG_USB_HCI
  4517. u8 rtw_halmac_usb_get_bulkout_id(struct dvobj_priv *d, u8 *buf, u32 size)
  4518. {
  4519. struct halmac_adapter *mac;
  4520. struct halmac_api *api;
  4521. enum halmac_ret_status status;
  4522. u8 bulkout_id;
  4523. mac = dvobj_to_halmac(d);
  4524. api = HALMAC_GET_API(mac);
  4525. status = api->halmac_get_usb_bulkout_id(mac, buf, size, &bulkout_id);
  4526. if (HALMAC_RET_SUCCESS != status)
  4527. return 0;
  4528. return bulkout_id;
  4529. }
  4530. /**
  4531. * rtw_halmac_usb_get_txagg_desc_num() - MAX descriptor number in one bulk for TX
  4532. * @d: struct dvobj_priv*
  4533. * @size: TX FIFO size, unit is byte.
  4534. *
  4535. * Get MAX descriptor number in one bulk out from HALMAC.
  4536. *
  4537. * Return 0 for OK, otherwise fail.
  4538. */
  4539. int rtw_halmac_usb_get_txagg_desc_num(struct dvobj_priv *d, u8 *num)
  4540. {
  4541. struct halmac_adapter *halmac;
  4542. struct halmac_api *api;
  4543. enum halmac_ret_status status;
  4544. u8 val = 0;
  4545. halmac = dvobj_to_halmac(d);
  4546. api = HALMAC_GET_API(halmac);
  4547. status = api->halmac_get_hw_value(halmac, HALMAC_HW_USB_TXAGG_DESC_NUM, &val);
  4548. if (status != HALMAC_RET_SUCCESS)
  4549. return -1;
  4550. *num = val;
  4551. return 0;
  4552. }
  4553. static inline enum halmac_usb_mode _usb_mode_drv2halmac(enum RTW_USB_SPEED usb_mode)
  4554. {
  4555. enum halmac_usb_mode halmac_usb_mode = HALMAC_USB_MODE_U2;
  4556. switch (usb_mode) {
  4557. case RTW_USB_SPEED_2:
  4558. halmac_usb_mode = HALMAC_USB_MODE_U2;
  4559. break;
  4560. case RTW_USB_SPEED_3:
  4561. halmac_usb_mode = HALMAC_USB_MODE_U3;
  4562. break;
  4563. default:
  4564. halmac_usb_mode = HALMAC_USB_MODE_U2;
  4565. break;
  4566. }
  4567. return halmac_usb_mode;
  4568. }
  4569. u8 rtw_halmac_switch_usb_mode(struct dvobj_priv *d, enum RTW_USB_SPEED usb_mode)
  4570. {
  4571. PADAPTER adapter;
  4572. struct halmac_adapter *mac;
  4573. struct halmac_api *api;
  4574. enum halmac_ret_status status;
  4575. enum halmac_usb_mode halmac_usb_mode;
  4576. adapter = dvobj_get_primary_adapter(d);
  4577. mac = dvobj_to_halmac(d);
  4578. api = HALMAC_GET_API(mac);
  4579. halmac_usb_mode = _usb_mode_drv2halmac(usb_mode);
  4580. status = api->halmac_set_hw_value(mac, HALMAC_HW_USB_MODE, (void *)&halmac_usb_mode);
  4581. if (HALMAC_RET_SUCCESS != status)
  4582. return _FAIL;
  4583. return _SUCCESS;
  4584. }
  4585. #endif /* CONFIG_USB_HCI */
  4586. #ifdef CONFIG_BEAMFORMING
  4587. #ifdef RTW_BEAMFORMING_VERSION_2
  4588. int rtw_halmac_bf_add_mu_bfer(struct dvobj_priv *d, u16 paid, u16 csi_para,
  4589. u16 my_aid, enum halmac_csi_seg_len sel, u8 *addr)
  4590. {
  4591. struct halmac_adapter *mac;
  4592. struct halmac_api *api;
  4593. enum halmac_ret_status status;
  4594. struct halmac_mu_bfer_init_para param;
  4595. mac = dvobj_to_halmac(d);
  4596. api = HALMAC_GET_API(mac);
  4597. _rtw_memset(&param, 0, sizeof(param));
  4598. param.paid = paid;
  4599. param.csi_para = csi_para;
  4600. param.my_aid = my_aid;
  4601. param.csi_length_sel = sel;
  4602. _rtw_memcpy(param.bfer_address.addr, addr, 6);
  4603. status = api->halmac_mu_bfer_entry_init(mac, &param);
  4604. if (status != HALMAC_RET_SUCCESS)
  4605. return -1;
  4606. return 0;
  4607. }
  4608. int rtw_halmac_bf_del_mu_bfer(struct dvobj_priv *d)
  4609. {
  4610. struct halmac_adapter *mac;
  4611. struct halmac_api *api;
  4612. enum halmac_ret_status status;
  4613. mac = dvobj_to_halmac(d);
  4614. api = HALMAC_GET_API(mac);
  4615. status = api->halmac_mu_bfer_entry_del(mac);
  4616. if (status != HALMAC_RET_SUCCESS)
  4617. return -1;
  4618. return 0;
  4619. }
  4620. int rtw_halmac_bf_cfg_sounding(struct dvobj_priv *d,
  4621. enum halmac_snd_role role, enum halmac_data_rate rate)
  4622. {
  4623. struct halmac_adapter *mac;
  4624. struct halmac_api *api;
  4625. enum halmac_ret_status status;
  4626. mac = dvobj_to_halmac(d);
  4627. api = HALMAC_GET_API(mac);
  4628. status = api->halmac_cfg_sounding(mac, role, rate);
  4629. if (status != HALMAC_RET_SUCCESS)
  4630. return -1;
  4631. return 0;
  4632. }
  4633. int rtw_halmac_bf_del_sounding(struct dvobj_priv *d,
  4634. enum halmac_snd_role role)
  4635. {
  4636. struct halmac_adapter *mac;
  4637. struct halmac_api *api;
  4638. enum halmac_ret_status status;
  4639. mac = dvobj_to_halmac(d);
  4640. api = HALMAC_GET_API(mac);
  4641. status = api->halmac_del_sounding(mac, role);
  4642. if (status != HALMAC_RET_SUCCESS)
  4643. return -1;
  4644. return 0;
  4645. }
  4646. /**
  4647. * rtw_halmac_bf_cfg_csi_rate() - Config data rate for CSI report frame by RSSI
  4648. * @d: struct dvobj_priv*
  4649. * @rssi: RSSI vlaue, unit is percentage (0~100).
  4650. * @current_rate: Current CSI frame rate
  4651. * Valid value example
  4652. * 0 CCK 1M
  4653. * 3 CCK 11M
  4654. * 4 OFDM 6M
  4655. * and so on
  4656. * @fixrate_en: Enable to fix CSI frame in VHT rate, otherwise legacy OFDM rate.
  4657. * The value "0" for disable, otheriwse enable.
  4658. * @new_rate: Return new data rate, and value range is the same as
  4659. * current_rate
  4660. * @bmp_ofdm54: Return to suggest enabling OFDM 54M for CSI report frame or not,
  4661. * The valid values and meanings are:
  4662. * 0x00 disable
  4663. * 0x01 enable
  4664. * 0xFF Keep current setting
  4665. *
  4666. * According RSSI to config data rate for CSI report frame of Beamforming.
  4667. *
  4668. * Return 0 for OK, otherwise fail.
  4669. */
  4670. int rtw_halmac_bf_cfg_csi_rate(struct dvobj_priv *d, u8 rssi,
  4671. u8 current_rate, u8 fixrate_en, u8 *new_rate,
  4672. u8 *bmp_ofdm54)
  4673. {
  4674. struct halmac_adapter *mac;
  4675. struct halmac_api *api;
  4676. enum halmac_ret_status status;
  4677. mac = dvobj_to_halmac(d);
  4678. api = HALMAC_GET_API(mac);
  4679. status = api->halmac_cfg_csi_rate(mac,
  4680. rssi, current_rate, fixrate_en, new_rate,
  4681. bmp_ofdm54);
  4682. if (status != HALMAC_RET_SUCCESS)
  4683. return -1;
  4684. return 0;
  4685. }
  4686. int rtw_halmac_bf_cfg_mu_mimo(struct dvobj_priv *d, enum halmac_snd_role role,
  4687. u8 *sounding_sts, u16 grouping_bitmap, u8 mu_tx_en,
  4688. u32 *given_gid_tab, u32 *given_user_pos)
  4689. {
  4690. struct halmac_adapter *mac;
  4691. struct halmac_api *api;
  4692. enum halmac_ret_status status;
  4693. struct halmac_cfg_mumimo_para param;
  4694. mac = dvobj_to_halmac(d);
  4695. api = HALMAC_GET_API(mac);
  4696. _rtw_memset(&param, 0, sizeof(param));
  4697. param.role = role;
  4698. param.grouping_bitmap = grouping_bitmap;
  4699. param.mu_tx_en = mu_tx_en;
  4700. if (sounding_sts)
  4701. _rtw_memcpy(param.sounding_sts, sounding_sts, 6);
  4702. if (given_gid_tab)
  4703. _rtw_memcpy(param.given_gid_tab, given_gid_tab, 8);
  4704. if (given_user_pos)
  4705. _rtw_memcpy(param.given_user_pos, given_user_pos, 16);
  4706. status = api->halmac_cfg_mumimo(mac, &param);
  4707. if (status != HALMAC_RET_SUCCESS)
  4708. return -1;
  4709. return 0;
  4710. }
  4711. #endif /* RTW_BEAMFORMING_VERSION_2 */
  4712. #endif /* CONFIG_BEAMFORMING */