dp_main.c 310 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679
  1. /*
  2. * Copyright (c) 2016-2020 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include <qdf_types.h>
  19. #include <qdf_lock.h>
  20. #include <qdf_net_types.h>
  21. #include <qdf_lro.h>
  22. #include <qdf_module.h>
  23. #include <hal_hw_headers.h>
  24. #include <hal_api.h>
  25. #include <hif.h>
  26. #include <htt.h>
  27. #include <wdi_event.h>
  28. #include <queue.h>
  29. #include "dp_types.h"
  30. #include "dp_internal.h"
  31. #include "dp_tx.h"
  32. #include "dp_tx_desc.h"
  33. #include "dp_rx.h"
  34. #include "dp_rx_mon.h"
  35. #ifdef DP_RATETABLE_SUPPORT
  36. #include "dp_ratetable.h"
  37. #endif
  38. #include <cdp_txrx_handle.h>
  39. #include <wlan_cfg.h>
  40. #include "cdp_txrx_cmn_struct.h"
  41. #include "cdp_txrx_stats_struct.h"
  42. #include "cdp_txrx_cmn_reg.h"
  43. #include <qdf_util.h>
  44. #include "dp_peer.h"
  45. #include "dp_rx_mon.h"
  46. #include "htt_stats.h"
  47. #include "dp_htt.h"
  48. #include "htt_ppdu_stats.h"
  49. #include "qdf_mem.h" /* qdf_mem_malloc,free */
  50. #include "cfg_ucfg_api.h"
  51. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  52. #include "cdp_txrx_flow_ctrl_v2.h"
  53. #else
  54. static inline void
  55. cdp_dump_flow_pool_info(struct cdp_soc_t *soc)
  56. {
  57. return;
  58. }
  59. #endif
  60. #include "dp_ipa.h"
  61. #include "dp_cal_client_api.h"
  62. #ifdef FEATURE_WDS
  63. #include "dp_txrx_wds.h"
  64. #endif
  65. #ifdef ATH_SUPPORT_IQUE
  66. #include "dp_txrx_me.h"
  67. #endif
  68. #if defined(DP_CON_MON)
  69. #ifndef REMOVE_PKT_LOG
  70. #include <pktlog_ac_api.h>
  71. #include <pktlog_ac.h>
  72. #endif
  73. #endif
  74. /*
  75. * The max size of cdp_peer_stats_param_t is limited to 16 bytes.
  76. * If the buffer size is exceeding this size limit,
  77. * dp_txrx_get_peer_stats is to be used instead.
  78. */
  79. QDF_COMPILE_TIME_ASSERT(cdp_peer_stats_param_t_max_size,
  80. (sizeof(cdp_peer_stats_param_t) <= 16));
  81. #ifdef WLAN_FEATURE_DP_EVENT_HISTORY
  82. /*
  83. * If WLAN_CFG_INT_NUM_CONTEXTS is changed, HIF_NUM_INT_CONTEXTS
  84. * also should be updated accordingly
  85. */
  86. QDF_COMPILE_TIME_ASSERT(num_intr_grps,
  87. HIF_NUM_INT_CONTEXTS == WLAN_CFG_INT_NUM_CONTEXTS);
  88. /*
  89. * HIF_EVENT_HIST_MAX should always be power of 2
  90. */
  91. QDF_COMPILE_TIME_ASSERT(hif_event_history_size,
  92. (HIF_EVENT_HIST_MAX & (HIF_EVENT_HIST_MAX - 1)) == 0);
  93. #endif /* WLAN_FEATURE_DP_EVENT_HISTORY */
  94. /*
  95. * If WLAN_CFG_INT_NUM_CONTEXTS is changed,
  96. * WLAN_CFG_INT_NUM_CONTEXTS_MAX should also be updated
  97. */
  98. QDF_COMPILE_TIME_ASSERT(wlan_cfg_num_int_ctxs,
  99. WLAN_CFG_INT_NUM_CONTEXTS_MAX >=
  100. WLAN_CFG_INT_NUM_CONTEXTS);
  101. #ifdef WLAN_RX_PKT_CAPTURE_ENH
  102. #include "dp_rx_mon_feature.h"
  103. #else
  104. /*
  105. * dp_config_enh_rx_capture()- API to enable/disable enhanced rx capture
  106. * @pdev_handle: DP_PDEV handle
  107. * @val: user provided value
  108. *
  109. * Return: QDF_STATUS
  110. */
  111. static QDF_STATUS
  112. dp_config_enh_rx_capture(struct dp_pdev *pdev_handle, uint8_t val)
  113. {
  114. return QDF_STATUS_E_INVAL;
  115. }
  116. #endif /* WLAN_RX_PKT_CAPTURE_ENH */
  117. #ifdef WLAN_TX_PKT_CAPTURE_ENH
  118. #include "dp_tx_capture.h"
  119. #else
  120. /*
  121. * dp_config_enh_tx_capture()- API to enable/disable enhanced tx capture
  122. * @pdev_handle: DP_PDEV handle
  123. * @val: user provided value
  124. *
  125. * Return: QDF_STATUS
  126. */
  127. static QDF_STATUS
  128. dp_config_enh_tx_capture(struct dp_pdev *pdev_handle, uint8_t val)
  129. {
  130. return QDF_STATUS_E_INVAL;
  131. }
  132. #endif
  133. void *dp_soc_init(struct dp_soc *soc, HTC_HANDLE htc_handle,
  134. struct hif_opaque_softc *hif_handle);
  135. static void dp_pdev_detach(struct cdp_pdev *txrx_pdev, int force);
  136. static struct dp_soc *
  137. dp_soc_attach(struct cdp_ctrl_objmgr_psoc *ctrl_psoc, HTC_HANDLE htc_handle,
  138. qdf_device_t qdf_osdev,
  139. struct ol_if_ops *ol_ops, uint16_t device_id);
  140. static void dp_pktlogmod_exit(struct dp_pdev *handle);
  141. static inline QDF_STATUS dp_peer_create_wifi3(struct cdp_soc_t *soc_hdl,
  142. uint8_t vdev_id,
  143. uint8_t *peer_mac_addr);
  144. static QDF_STATUS dp_peer_delete_wifi3(struct cdp_soc_t *soc, uint8_t vdev_id,
  145. uint8_t *peer_mac, uint32_t bitmap);
  146. static void dp_ppdu_ring_reset(struct dp_pdev *pdev);
  147. static void dp_ppdu_ring_cfg(struct dp_pdev *pdev);
  148. static void dp_vdev_flush_peers(struct cdp_vdev *vdev_handle,
  149. bool unmap_only);
  150. #ifdef ENABLE_VERBOSE_DEBUG
  151. bool is_dp_verbose_debug_enabled;
  152. #endif
  153. #if defined(WLAN_CFR_ENABLE) && defined(WLAN_ENH_CFR_ENABLE)
  154. static void dp_cfr_filter(struct cdp_soc_t *soc_hdl,
  155. uint8_t pdev_id,
  156. bool enable,
  157. struct cdp_monitor_filter *filter_val);
  158. static bool dp_get_cfr_rcc(struct cdp_soc_t *soc_hdl, uint8_t pdev_id);
  159. static void dp_set_cfr_rcc(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  160. bool enable);
  161. #endif
  162. static uint8_t dp_soc_ring_if_nss_offloaded(struct dp_soc *soc,
  163. enum hal_ring_type ring_type,
  164. int ring_num);
  165. #define DP_INTR_POLL_TIMER_MS 10
  166. /* Generic AST entry aging timer value */
  167. #define DP_AST_AGING_TIMER_DEFAULT_MS 1000
  168. #define DP_MCS_LENGTH (6*MAX_MCS)
  169. #define DP_CURR_FW_STATS_AVAIL 19
  170. #define DP_HTT_DBG_EXT_STATS_MAX 256
  171. #define DP_MAX_SLEEP_TIME 100
  172. #ifndef QCA_WIFI_3_0_EMU
  173. #define SUSPEND_DRAIN_WAIT 500
  174. #else
  175. #define SUSPEND_DRAIN_WAIT 3000
  176. #endif
  177. #ifdef IPA_OFFLOAD
  178. /* Exclude IPA rings from the interrupt context */
  179. #define TX_RING_MASK_VAL 0xb
  180. #define RX_RING_MASK_VAL 0x7
  181. #else
  182. #define TX_RING_MASK_VAL 0xF
  183. #define RX_RING_MASK_VAL 0xF
  184. #endif
  185. #define STR_MAXLEN 64
  186. #define RNG_ERR "SRNG setup failed for"
  187. /* Threshold for peer's cached buf queue beyond which frames are dropped */
  188. #define DP_RX_CACHED_BUFQ_THRESH 64
  189. /**
  190. * default_dscp_tid_map - Default DSCP-TID mapping
  191. *
  192. * DSCP TID
  193. * 000000 0
  194. * 001000 1
  195. * 010000 2
  196. * 011000 3
  197. * 100000 4
  198. * 101000 5
  199. * 110000 6
  200. * 111000 7
  201. */
  202. static uint8_t default_dscp_tid_map[DSCP_TID_MAP_MAX] = {
  203. 0, 0, 0, 0, 0, 0, 0, 0,
  204. 1, 1, 1, 1, 1, 1, 1, 1,
  205. 2, 2, 2, 2, 2, 2, 2, 2,
  206. 3, 3, 3, 3, 3, 3, 3, 3,
  207. 4, 4, 4, 4, 4, 4, 4, 4,
  208. 5, 5, 5, 5, 5, 5, 5, 5,
  209. 6, 6, 6, 6, 6, 6, 6, 6,
  210. 7, 7, 7, 7, 7, 7, 7, 7,
  211. };
  212. /**
  213. * default_pcp_tid_map - Default PCP-TID mapping
  214. *
  215. * PCP TID
  216. * 000 0
  217. * 001 1
  218. * 010 2
  219. * 011 3
  220. * 100 4
  221. * 101 5
  222. * 110 6
  223. * 111 7
  224. */
  225. static uint8_t default_pcp_tid_map[PCP_TID_MAP_MAX] = {
  226. 0, 1, 2, 3, 4, 5, 6, 7,
  227. };
  228. /**
  229. * @brief Cpu to tx ring map
  230. */
  231. uint8_t
  232. dp_cpu_ring_map[DP_NSS_CPU_RING_MAP_MAX][WLAN_CFG_INT_NUM_CONTEXTS_MAX] = {
  233. {0x0, 0x1, 0x2, 0x0, 0x0, 0x1, 0x2, 0x0, 0x0, 0x1, 0x2},
  234. {0x1, 0x2, 0x1, 0x2, 0x1, 0x2, 0x1, 0x2, 0x1, 0x2, 0x1},
  235. {0x0, 0x2, 0x0, 0x2, 0x0, 0x2, 0x0, 0x2, 0x0, 0x2, 0x0},
  236. {0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2},
  237. {0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3},
  238. #ifdef WLAN_TX_PKT_CAPTURE_ENH
  239. {0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1}
  240. #endif
  241. };
  242. /**
  243. * @brief Select the type of statistics
  244. */
  245. enum dp_stats_type {
  246. STATS_FW = 0,
  247. STATS_HOST = 1,
  248. STATS_TYPE_MAX = 2,
  249. };
  250. /**
  251. * @brief General Firmware statistics options
  252. *
  253. */
  254. enum dp_fw_stats {
  255. TXRX_FW_STATS_INVALID = -1,
  256. };
  257. /**
  258. * dp_stats_mapping_table - Firmware and Host statistics
  259. * currently supported
  260. */
  261. const int dp_stats_mapping_table[][STATS_TYPE_MAX] = {
  262. {HTT_DBG_EXT_STATS_RESET, TXRX_HOST_STATS_INVALID},
  263. {HTT_DBG_EXT_STATS_PDEV_TX, TXRX_HOST_STATS_INVALID},
  264. {HTT_DBG_EXT_STATS_PDEV_RX, TXRX_HOST_STATS_INVALID},
  265. {HTT_DBG_EXT_STATS_PDEV_TX_HWQ, TXRX_HOST_STATS_INVALID},
  266. {HTT_DBG_EXT_STATS_PDEV_TX_SCHED, TXRX_HOST_STATS_INVALID},
  267. {HTT_DBG_EXT_STATS_PDEV_ERROR, TXRX_HOST_STATS_INVALID},
  268. {HTT_DBG_EXT_STATS_PDEV_TQM, TXRX_HOST_STATS_INVALID},
  269. {HTT_DBG_EXT_STATS_TQM_CMDQ, TXRX_HOST_STATS_INVALID},
  270. {HTT_DBG_EXT_STATS_TX_DE_INFO, TXRX_HOST_STATS_INVALID},
  271. {HTT_DBG_EXT_STATS_PDEV_TX_RATE, TXRX_HOST_STATS_INVALID},
  272. {HTT_DBG_EXT_STATS_PDEV_RX_RATE, TXRX_HOST_STATS_INVALID},
  273. {TXRX_FW_STATS_INVALID, TXRX_HOST_STATS_INVALID},
  274. {HTT_DBG_EXT_STATS_TX_SELFGEN_INFO, TXRX_HOST_STATS_INVALID},
  275. {HTT_DBG_EXT_STATS_TX_MU_HWQ, TXRX_HOST_STATS_INVALID},
  276. {HTT_DBG_EXT_STATS_RING_IF_INFO, TXRX_HOST_STATS_INVALID},
  277. {HTT_DBG_EXT_STATS_SRNG_INFO, TXRX_HOST_STATS_INVALID},
  278. {HTT_DBG_EXT_STATS_SFM_INFO, TXRX_HOST_STATS_INVALID},
  279. {HTT_DBG_EXT_STATS_PDEV_TX_MU, TXRX_HOST_STATS_INVALID},
  280. {HTT_DBG_EXT_STATS_ACTIVE_PEERS_LIST, TXRX_HOST_STATS_INVALID},
  281. /* Last ENUM for HTT FW STATS */
  282. {DP_HTT_DBG_EXT_STATS_MAX, TXRX_HOST_STATS_INVALID},
  283. {TXRX_FW_STATS_INVALID, TXRX_CLEAR_STATS},
  284. {TXRX_FW_STATS_INVALID, TXRX_RX_RATE_STATS},
  285. {TXRX_FW_STATS_INVALID, TXRX_TX_RATE_STATS},
  286. {TXRX_FW_STATS_INVALID, TXRX_TX_HOST_STATS},
  287. {TXRX_FW_STATS_INVALID, TXRX_RX_HOST_STATS},
  288. {TXRX_FW_STATS_INVALID, TXRX_AST_STATS},
  289. {TXRX_FW_STATS_INVALID, TXRX_SRNG_PTR_STATS},
  290. {TXRX_FW_STATS_INVALID, TXRX_RX_MON_STATS},
  291. {TXRX_FW_STATS_INVALID, TXRX_REO_QUEUE_STATS},
  292. {TXRX_FW_STATS_INVALID, TXRX_SOC_CFG_PARAMS},
  293. {TXRX_FW_STATS_INVALID, TXRX_PDEV_CFG_PARAMS},
  294. {TXRX_FW_STATS_INVALID, TXRX_SOC_INTERRUPT_STATS},
  295. };
  296. /* MCL specific functions */
  297. #if defined(DP_CON_MON)
  298. /**
  299. * dp_soc_get_mon_mask_for_interrupt_mode() - get mon mode mask for intr mode
  300. * @soc: pointer to dp_soc handle
  301. * @intr_ctx_num: interrupt context number for which mon mask is needed
  302. *
  303. * For MCL, monitor mode rings are being processed in timer contexts (polled).
  304. * This function is returning 0, since in interrupt mode(softirq based RX),
  305. * we donot want to process monitor mode rings in a softirq.
  306. *
  307. * So, in case packet log is enabled for SAP/STA/P2P modes,
  308. * regular interrupt processing will not process monitor mode rings. It would be
  309. * done in a separate timer context.
  310. *
  311. * Return: 0
  312. */
  313. static inline
  314. uint32_t dp_soc_get_mon_mask_for_interrupt_mode(struct dp_soc *soc, int intr_ctx_num)
  315. {
  316. return 0;
  317. }
  318. /*
  319. * dp_service_mon_rings()- timer to reap monitor rings
  320. * reqd as we are not getting ppdu end interrupts
  321. * @arg: SoC Handle
  322. *
  323. * Return:
  324. *
  325. */
  326. static void dp_service_mon_rings(void *arg)
  327. {
  328. struct dp_soc *soc = (struct dp_soc *)arg;
  329. int ring = 0, work_done;
  330. struct dp_pdev *pdev = NULL;
  331. for (ring = 0 ; ring < MAX_NUM_LMAC_HW; ring++) {
  332. pdev = dp_get_pdev_for_lmac_id(soc, ring);
  333. if (!pdev)
  334. continue;
  335. work_done = dp_mon_process(soc, ring,
  336. QCA_NAPI_BUDGET);
  337. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  338. FL("Reaped %d descs from Monitor rings"),
  339. work_done);
  340. }
  341. qdf_timer_mod(&soc->mon_reap_timer, DP_INTR_POLL_TIMER_MS);
  342. }
  343. #ifndef REMOVE_PKT_LOG
  344. /**
  345. * dp_pkt_log_init() - API to initialize packet log
  346. * @soc_hdl: Datapath soc handle
  347. * @pdev_id: id of data path pdev handle
  348. * @scn: HIF context
  349. *
  350. * Return: none
  351. */
  352. void dp_pkt_log_init(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, void *scn)
  353. {
  354. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  355. struct dp_pdev *handle =
  356. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  357. if (!handle) {
  358. dp_err("pdev handle is NULL");
  359. return;
  360. }
  361. if (handle->pkt_log_init) {
  362. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  363. "%s: Packet log not initialized", __func__);
  364. return;
  365. }
  366. pktlog_sethandle(&handle->pl_dev, scn);
  367. pktlog_set_pdev_id(handle->pl_dev, pdev_id);
  368. pktlog_set_callback_regtype(PKTLOG_DEFAULT_CALLBACK_REGISTRATION);
  369. if (pktlogmod_init(scn)) {
  370. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  371. "%s: pktlogmod_init failed", __func__);
  372. handle->pkt_log_init = false;
  373. } else {
  374. handle->pkt_log_init = true;
  375. }
  376. }
  377. /**
  378. * dp_pkt_log_con_service() - connect packet log service
  379. * @soc_hdl: Datapath soc handle
  380. * @pdev_id: id of data path pdev handle
  381. * @scn: device context
  382. *
  383. * Return: none
  384. */
  385. static void dp_pkt_log_con_service(struct cdp_soc_t *soc_hdl,
  386. uint8_t pdev_id, void *scn)
  387. {
  388. dp_pkt_log_init(soc_hdl, pdev_id, scn);
  389. pktlog_htc_attach();
  390. }
  391. /**
  392. * dp_get_num_rx_contexts() - get number of RX contexts
  393. * @soc_hdl: cdp opaque soc handle
  394. *
  395. * Return: number of RX contexts
  396. */
  397. static int dp_get_num_rx_contexts(struct cdp_soc_t *soc_hdl)
  398. {
  399. int i;
  400. int num_rx_contexts = 0;
  401. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  402. for (i = 0; i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++)
  403. if (wlan_cfg_get_rx_ring_mask(soc->wlan_cfg_ctx, i))
  404. num_rx_contexts++;
  405. return num_rx_contexts;
  406. }
  407. /**
  408. * dp_pktlogmod_exit() - API to cleanup pktlog info
  409. * @pdev: Pdev handle
  410. *
  411. * Return: none
  412. */
  413. static void dp_pktlogmod_exit(struct dp_pdev *pdev)
  414. {
  415. struct dp_soc *soc = pdev->soc;
  416. struct hif_opaque_softc *scn = soc->hif_handle;
  417. if (!scn) {
  418. dp_err("Invalid hif(scn) handle");
  419. return;
  420. }
  421. /* stop mon_reap_timer if it has been started */
  422. if (pdev->rx_pktlog_mode != DP_RX_PKTLOG_DISABLED &&
  423. soc->reap_timer_init)
  424. qdf_timer_sync_cancel(&soc->mon_reap_timer);
  425. pktlogmod_exit(scn);
  426. pdev->pkt_log_init = false;
  427. }
  428. #endif
  429. #else
  430. static void dp_pktlogmod_exit(struct dp_pdev *handle) { }
  431. /**
  432. * dp_soc_get_mon_mask_for_interrupt_mode() - get mon mode mask for intr mode
  433. * @soc: pointer to dp_soc handle
  434. * @intr_ctx_num: interrupt context number for which mon mask is needed
  435. *
  436. * Return: mon mask value
  437. */
  438. static inline
  439. uint32_t dp_soc_get_mon_mask_for_interrupt_mode(struct dp_soc *soc, int intr_ctx_num)
  440. {
  441. return wlan_cfg_get_rx_mon_ring_mask(soc->wlan_cfg_ctx, intr_ctx_num);
  442. }
  443. /*
  444. * dp_service_lmac_rings()- timer to reap lmac rings
  445. * @arg: SoC Handle
  446. *
  447. * Return:
  448. *
  449. */
  450. static void dp_service_lmac_rings(void *arg)
  451. {
  452. struct dp_soc *soc = (struct dp_soc *)arg;
  453. int ring = 0, i;
  454. struct dp_pdev *pdev = NULL;
  455. union dp_rx_desc_list_elem_t *desc_list = NULL;
  456. union dp_rx_desc_list_elem_t *tail = NULL;
  457. /* Process LMAC interrupts */
  458. for (ring = 0 ; ring < MAX_NUM_LMAC_HW; ring++) {
  459. int mac_for_pdev = ring;
  460. struct dp_srng *rx_refill_buf_ring;
  461. pdev = dp_get_pdev_for_lmac_id(soc, mac_for_pdev);
  462. if (!pdev)
  463. continue;
  464. rx_refill_buf_ring = &soc->rx_refill_buf_ring[mac_for_pdev];
  465. dp_mon_process(soc, mac_for_pdev,
  466. QCA_NAPI_BUDGET);
  467. for (i = 0;
  468. i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++)
  469. dp_rxdma_err_process(&soc->intr_ctx[i], soc,
  470. mac_for_pdev,
  471. QCA_NAPI_BUDGET);
  472. if (!dp_soc_ring_if_nss_offloaded(soc, RXDMA_BUF,
  473. mac_for_pdev))
  474. dp_rx_buffers_replenish(soc, mac_for_pdev,
  475. rx_refill_buf_ring,
  476. &soc->rx_desc_buf[mac_for_pdev],
  477. 0, &desc_list, &tail);
  478. }
  479. qdf_timer_mod(&soc->lmac_reap_timer, DP_INTR_POLL_TIMER_MS);
  480. }
  481. #endif
  482. static int dp_peer_add_ast_wifi3(struct cdp_soc_t *soc_hdl,
  483. uint8_t vdev_id,
  484. uint8_t *peer_mac,
  485. uint8_t *mac_addr,
  486. enum cdp_txrx_ast_entry_type type,
  487. uint32_t flags)
  488. {
  489. int ret = -1;
  490. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc_hdl,
  491. peer_mac, 0, vdev_id);
  492. if (!peer || peer->delete_in_progress) {
  493. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  494. "%s: Peer is NULL!\n", __func__);
  495. goto fail;
  496. }
  497. ret = dp_peer_add_ast((struct dp_soc *)soc_hdl,
  498. peer,
  499. mac_addr,
  500. type,
  501. flags);
  502. fail:
  503. if (peer)
  504. dp_peer_unref_delete(peer);
  505. return ret;
  506. }
  507. static int dp_peer_update_ast_wifi3(struct cdp_soc_t *soc_hdl,
  508. uint8_t vdev_id,
  509. uint8_t *peer_mac,
  510. uint8_t *wds_macaddr,
  511. uint32_t flags)
  512. {
  513. int status = -1;
  514. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  515. struct dp_ast_entry *ast_entry = NULL;
  516. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc_hdl,
  517. peer_mac, 0, vdev_id);
  518. if (!peer || peer->delete_in_progress) {
  519. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  520. "%s: Peer is NULL!\n", __func__);
  521. goto fail;
  522. }
  523. qdf_spin_lock_bh(&soc->ast_lock);
  524. ast_entry = dp_peer_ast_hash_find_by_pdevid(soc, wds_macaddr,
  525. peer->vdev->pdev->pdev_id);
  526. if (ast_entry) {
  527. status = dp_peer_update_ast(soc,
  528. peer,
  529. ast_entry, flags);
  530. }
  531. qdf_spin_unlock_bh(&soc->ast_lock);
  532. fail:
  533. if (peer)
  534. dp_peer_unref_delete(peer);
  535. return status;
  536. }
  537. /*
  538. * dp_wds_reset_ast_wifi3() - Reset the is_active param for ast entry
  539. * @soc_handle: Datapath SOC handle
  540. * @wds_macaddr: WDS entry MAC Address
  541. * @peer_macaddr: WDS entry MAC Address
  542. * @vdev_id: id of vdev handle
  543. * Return: QDF_STATUS
  544. */
  545. static QDF_STATUS dp_wds_reset_ast_wifi3(struct cdp_soc_t *soc_hdl,
  546. uint8_t *wds_macaddr,
  547. uint8_t *peer_mac_addr,
  548. uint8_t vdev_id)
  549. {
  550. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  551. struct dp_ast_entry *ast_entry = NULL;
  552. struct dp_ast_entry *tmp_ast_entry;
  553. struct dp_peer *peer;
  554. struct dp_pdev *pdev;
  555. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  556. if (!vdev)
  557. return QDF_STATUS_E_FAILURE;
  558. pdev = vdev->pdev;
  559. if (peer_mac_addr) {
  560. peer = dp_peer_find_hash_find(soc, peer_mac_addr,
  561. 0, vdev->vdev_id);
  562. if (!peer) {
  563. return QDF_STATUS_E_FAILURE;
  564. }
  565. if (peer->delete_in_progress) {
  566. dp_peer_unref_delete(peer);
  567. return QDF_STATUS_E_FAILURE;
  568. }
  569. qdf_spin_lock_bh(&soc->ast_lock);
  570. DP_PEER_ITERATE_ASE_LIST(peer, ast_entry, tmp_ast_entry) {
  571. if ((ast_entry->type == CDP_TXRX_AST_TYPE_WDS_HM) ||
  572. (ast_entry->type == CDP_TXRX_AST_TYPE_WDS_HM_SEC))
  573. dp_peer_del_ast(soc, ast_entry);
  574. }
  575. qdf_spin_unlock_bh(&soc->ast_lock);
  576. dp_peer_unref_delete(peer);
  577. return QDF_STATUS_SUCCESS;
  578. } else if (wds_macaddr) {
  579. qdf_spin_lock_bh(&soc->ast_lock);
  580. ast_entry = dp_peer_ast_hash_find_by_pdevid(soc, wds_macaddr,
  581. pdev->pdev_id);
  582. if (ast_entry) {
  583. if ((ast_entry->type == CDP_TXRX_AST_TYPE_WDS_HM) ||
  584. (ast_entry->type == CDP_TXRX_AST_TYPE_WDS_HM_SEC))
  585. dp_peer_del_ast(soc, ast_entry);
  586. }
  587. qdf_spin_unlock_bh(&soc->ast_lock);
  588. }
  589. return QDF_STATUS_SUCCESS;
  590. }
  591. /*
  592. * dp_wds_reset_ast_table_wifi3() - Reset the is_active param for all ast entry
  593. * @soc: Datapath SOC handle
  594. *
  595. * Return: QDF_STATUS
  596. */
  597. static QDF_STATUS
  598. dp_wds_reset_ast_table_wifi3(struct cdp_soc_t *soc_hdl,
  599. uint8_t vdev_id)
  600. {
  601. struct dp_soc *soc = (struct dp_soc *) soc_hdl;
  602. struct dp_pdev *pdev;
  603. struct dp_vdev *vdev;
  604. struct dp_peer *peer;
  605. struct dp_ast_entry *ase, *temp_ase;
  606. int i;
  607. qdf_spin_lock_bh(&soc->ast_lock);
  608. for (i = 0; i < MAX_PDEV_CNT && soc->pdev_list[i]; i++) {
  609. pdev = soc->pdev_list[i];
  610. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  611. DP_PDEV_ITERATE_VDEV_LIST(pdev, vdev) {
  612. DP_VDEV_ITERATE_PEER_LIST(vdev, peer) {
  613. DP_PEER_ITERATE_ASE_LIST(peer, ase, temp_ase) {
  614. if ((ase->type ==
  615. CDP_TXRX_AST_TYPE_WDS_HM) ||
  616. (ase->type ==
  617. CDP_TXRX_AST_TYPE_WDS_HM_SEC))
  618. dp_peer_del_ast(soc, ase);
  619. }
  620. }
  621. }
  622. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  623. }
  624. qdf_spin_unlock_bh(&soc->ast_lock);
  625. return QDF_STATUS_SUCCESS;
  626. }
  627. /*
  628. * dp_wds_flush_ast_table_wifi3() - Delete all wds and hmwds ast entry
  629. * @soc: Datapath SOC handle
  630. *
  631. * Return: None
  632. */
  633. static void dp_wds_flush_ast_table_wifi3(struct cdp_soc_t *soc_hdl)
  634. {
  635. struct dp_soc *soc = (struct dp_soc *) soc_hdl;
  636. struct dp_pdev *pdev;
  637. struct dp_vdev *vdev;
  638. struct dp_peer *peer;
  639. struct dp_ast_entry *ase, *temp_ase;
  640. int i;
  641. qdf_spin_lock_bh(&soc->ast_lock);
  642. for (i = 0; i < MAX_PDEV_CNT && soc->pdev_list[i]; i++) {
  643. pdev = soc->pdev_list[i];
  644. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  645. DP_PDEV_ITERATE_VDEV_LIST(pdev, vdev) {
  646. DP_VDEV_ITERATE_PEER_LIST(vdev, peer) {
  647. DP_PEER_ITERATE_ASE_LIST(peer, ase, temp_ase) {
  648. if ((ase->type ==
  649. CDP_TXRX_AST_TYPE_STATIC) ||
  650. (ase->type ==
  651. CDP_TXRX_AST_TYPE_SELF) ||
  652. (ase->type ==
  653. CDP_TXRX_AST_TYPE_STA_BSS))
  654. continue;
  655. dp_peer_del_ast(soc, ase);
  656. }
  657. }
  658. }
  659. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  660. }
  661. qdf_spin_unlock_bh(&soc->ast_lock);
  662. }
  663. /**
  664. * dp_peer_get_ast_info_by_soc_wifi3() - search the soc AST hash table
  665. * and return ast entry information
  666. * of first ast entry found in the
  667. * table with given mac address
  668. *
  669. * @soc : data path soc handle
  670. * @ast_mac_addr : AST entry mac address
  671. * @ast_entry_info : ast entry information
  672. *
  673. * return : true if ast entry found with ast_mac_addr
  674. * false if ast entry not found
  675. */
  676. static bool dp_peer_get_ast_info_by_soc_wifi3
  677. (struct cdp_soc_t *soc_hdl,
  678. uint8_t *ast_mac_addr,
  679. struct cdp_ast_entry_info *ast_entry_info)
  680. {
  681. struct dp_ast_entry *ast_entry = NULL;
  682. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  683. qdf_spin_lock_bh(&soc->ast_lock);
  684. ast_entry = dp_peer_ast_hash_find_soc(soc, ast_mac_addr);
  685. if (!ast_entry || !ast_entry->peer) {
  686. qdf_spin_unlock_bh(&soc->ast_lock);
  687. return false;
  688. }
  689. if (ast_entry->delete_in_progress && !ast_entry->callback) {
  690. qdf_spin_unlock_bh(&soc->ast_lock);
  691. return false;
  692. }
  693. ast_entry_info->type = ast_entry->type;
  694. ast_entry_info->pdev_id = ast_entry->pdev_id;
  695. ast_entry_info->vdev_id = ast_entry->peer->vdev->vdev_id;
  696. ast_entry_info->peer_id = ast_entry->peer->peer_ids[0];
  697. qdf_mem_copy(&ast_entry_info->peer_mac_addr[0],
  698. &ast_entry->peer->mac_addr.raw[0],
  699. QDF_MAC_ADDR_SIZE);
  700. qdf_spin_unlock_bh(&soc->ast_lock);
  701. return true;
  702. }
  703. /**
  704. * dp_peer_get_ast_info_by_pdevid_wifi3() - search the soc AST hash table
  705. * and return ast entry information
  706. * if mac address and pdev_id matches
  707. *
  708. * @soc : data path soc handle
  709. * @ast_mac_addr : AST entry mac address
  710. * @pdev_id : pdev_id
  711. * @ast_entry_info : ast entry information
  712. *
  713. * return : true if ast entry found with ast_mac_addr
  714. * false if ast entry not found
  715. */
  716. static bool dp_peer_get_ast_info_by_pdevid_wifi3
  717. (struct cdp_soc_t *soc_hdl,
  718. uint8_t *ast_mac_addr,
  719. uint8_t pdev_id,
  720. struct cdp_ast_entry_info *ast_entry_info)
  721. {
  722. struct dp_ast_entry *ast_entry;
  723. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  724. qdf_spin_lock_bh(&soc->ast_lock);
  725. ast_entry = dp_peer_ast_hash_find_by_pdevid(soc, ast_mac_addr, pdev_id);
  726. if (!ast_entry || !ast_entry->peer) {
  727. qdf_spin_unlock_bh(&soc->ast_lock);
  728. return false;
  729. }
  730. if (ast_entry->delete_in_progress && !ast_entry->callback) {
  731. qdf_spin_unlock_bh(&soc->ast_lock);
  732. return false;
  733. }
  734. ast_entry_info->type = ast_entry->type;
  735. ast_entry_info->pdev_id = ast_entry->pdev_id;
  736. ast_entry_info->vdev_id = ast_entry->peer->vdev->vdev_id;
  737. ast_entry_info->peer_id = ast_entry->peer->peer_ids[0];
  738. qdf_mem_copy(&ast_entry_info->peer_mac_addr[0],
  739. &ast_entry->peer->mac_addr.raw[0],
  740. QDF_MAC_ADDR_SIZE);
  741. qdf_spin_unlock_bh(&soc->ast_lock);
  742. return true;
  743. }
  744. /**
  745. * dp_peer_ast_entry_del_by_soc() - delete the ast entry from soc AST hash table
  746. * with given mac address
  747. *
  748. * @soc : data path soc handle
  749. * @ast_mac_addr : AST entry mac address
  750. * @callback : callback function to called on ast delete response from FW
  751. * @cookie : argument to be passed to callback
  752. *
  753. * return : QDF_STATUS_SUCCESS if ast entry found with ast_mac_addr and delete
  754. * is sent
  755. * QDF_STATUS_E_INVAL false if ast entry not found
  756. */
  757. static QDF_STATUS dp_peer_ast_entry_del_by_soc(struct cdp_soc_t *soc_handle,
  758. uint8_t *mac_addr,
  759. txrx_ast_free_cb callback,
  760. void *cookie)
  761. {
  762. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  763. struct dp_ast_entry *ast_entry = NULL;
  764. txrx_ast_free_cb cb = NULL;
  765. void *arg = NULL;
  766. qdf_spin_lock_bh(&soc->ast_lock);
  767. ast_entry = dp_peer_ast_hash_find_soc(soc, mac_addr);
  768. if (!ast_entry) {
  769. qdf_spin_unlock_bh(&soc->ast_lock);
  770. return -QDF_STATUS_E_INVAL;
  771. }
  772. if (ast_entry->callback) {
  773. cb = ast_entry->callback;
  774. arg = ast_entry->cookie;
  775. }
  776. ast_entry->callback = callback;
  777. ast_entry->cookie = cookie;
  778. /*
  779. * if delete_in_progress is set AST delete is sent to target
  780. * and host is waiting for response should not send delete
  781. * again
  782. */
  783. if (!ast_entry->delete_in_progress)
  784. dp_peer_del_ast(soc, ast_entry);
  785. qdf_spin_unlock_bh(&soc->ast_lock);
  786. if (cb) {
  787. cb(soc->ctrl_psoc,
  788. dp_soc_to_cdp_soc(soc),
  789. arg,
  790. CDP_TXRX_AST_DELETE_IN_PROGRESS);
  791. }
  792. return QDF_STATUS_SUCCESS;
  793. }
  794. /**
  795. * dp_peer_ast_entry_del_by_pdev() - delete the ast entry from soc AST hash
  796. * table if mac address and pdev_id matches
  797. *
  798. * @soc : data path soc handle
  799. * @ast_mac_addr : AST entry mac address
  800. * @pdev_id : pdev id
  801. * @callback : callback function to called on ast delete response from FW
  802. * @cookie : argument to be passed to callback
  803. *
  804. * return : QDF_STATUS_SUCCESS if ast entry found with ast_mac_addr and delete
  805. * is sent
  806. * QDF_STATUS_E_INVAL false if ast entry not found
  807. */
  808. static QDF_STATUS dp_peer_ast_entry_del_by_pdev(struct cdp_soc_t *soc_handle,
  809. uint8_t *mac_addr,
  810. uint8_t pdev_id,
  811. txrx_ast_free_cb callback,
  812. void *cookie)
  813. {
  814. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  815. struct dp_ast_entry *ast_entry;
  816. txrx_ast_free_cb cb = NULL;
  817. void *arg = NULL;
  818. qdf_spin_lock_bh(&soc->ast_lock);
  819. ast_entry = dp_peer_ast_hash_find_by_pdevid(soc, mac_addr, pdev_id);
  820. if (!ast_entry) {
  821. qdf_spin_unlock_bh(&soc->ast_lock);
  822. return -QDF_STATUS_E_INVAL;
  823. }
  824. if (ast_entry->callback) {
  825. cb = ast_entry->callback;
  826. arg = ast_entry->cookie;
  827. }
  828. ast_entry->callback = callback;
  829. ast_entry->cookie = cookie;
  830. /*
  831. * if delete_in_progress is set AST delete is sent to target
  832. * and host is waiting for response should not sent delete
  833. * again
  834. */
  835. if (!ast_entry->delete_in_progress)
  836. dp_peer_del_ast(soc, ast_entry);
  837. qdf_spin_unlock_bh(&soc->ast_lock);
  838. if (cb) {
  839. cb(soc->ctrl_psoc,
  840. dp_soc_to_cdp_soc(soc),
  841. arg,
  842. CDP_TXRX_AST_DELETE_IN_PROGRESS);
  843. }
  844. return QDF_STATUS_SUCCESS;
  845. }
  846. /**
  847. * dp_srng_find_ring_in_mask() - find which ext_group a ring belongs
  848. * @ring_num: ring num of the ring being queried
  849. * @grp_mask: the grp_mask array for the ring type in question.
  850. *
  851. * The grp_mask array is indexed by group number and the bit fields correspond
  852. * to ring numbers. We are finding which interrupt group a ring belongs to.
  853. *
  854. * Return: the index in the grp_mask array with the ring number.
  855. * -QDF_STATUS_E_NOENT if no entry is found
  856. */
  857. static int dp_srng_find_ring_in_mask(int ring_num, int *grp_mask)
  858. {
  859. int ext_group_num;
  860. int mask = 1 << ring_num;
  861. for (ext_group_num = 0; ext_group_num < WLAN_CFG_INT_NUM_CONTEXTS;
  862. ext_group_num++) {
  863. if (mask & grp_mask[ext_group_num])
  864. return ext_group_num;
  865. }
  866. return -QDF_STATUS_E_NOENT;
  867. }
  868. static int dp_srng_calculate_msi_group(struct dp_soc *soc,
  869. enum hal_ring_type ring_type,
  870. int ring_num)
  871. {
  872. int *grp_mask;
  873. switch (ring_type) {
  874. case WBM2SW_RELEASE:
  875. /* dp_tx_comp_handler - soc->tx_comp_ring */
  876. if (ring_num < 3)
  877. grp_mask = &soc->wlan_cfg_ctx->int_tx_ring_mask[0];
  878. /* dp_rx_wbm_err_process - soc->rx_rel_ring */
  879. else if (ring_num == 3) {
  880. /* sw treats this as a separate ring type */
  881. grp_mask = &soc->wlan_cfg_ctx->
  882. int_rx_wbm_rel_ring_mask[0];
  883. ring_num = 0;
  884. } else {
  885. qdf_assert(0);
  886. return -QDF_STATUS_E_NOENT;
  887. }
  888. break;
  889. case REO_EXCEPTION:
  890. /* dp_rx_err_process - &soc->reo_exception_ring */
  891. grp_mask = &soc->wlan_cfg_ctx->int_rx_err_ring_mask[0];
  892. break;
  893. case REO_DST:
  894. /* dp_rx_process - soc->reo_dest_ring */
  895. grp_mask = &soc->wlan_cfg_ctx->int_rx_ring_mask[0];
  896. break;
  897. case REO_STATUS:
  898. /* dp_reo_status_ring_handler - soc->reo_status_ring */
  899. grp_mask = &soc->wlan_cfg_ctx->int_reo_status_ring_mask[0];
  900. break;
  901. /* dp_rx_mon_status_srng_process - pdev->rxdma_mon_status_ring*/
  902. case RXDMA_MONITOR_STATUS:
  903. /* dp_rx_mon_dest_process - pdev->rxdma_mon_dst_ring */
  904. case RXDMA_MONITOR_DST:
  905. /* dp_mon_process */
  906. grp_mask = &soc->wlan_cfg_ctx->int_rx_mon_ring_mask[0];
  907. break;
  908. case RXDMA_DST:
  909. /* dp_rxdma_err_process */
  910. grp_mask = &soc->wlan_cfg_ctx->int_rxdma2host_ring_mask[0];
  911. break;
  912. case RXDMA_BUF:
  913. grp_mask = &soc->wlan_cfg_ctx->int_host2rxdma_ring_mask[0];
  914. break;
  915. case RXDMA_MONITOR_BUF:
  916. /* TODO: support low_thresh interrupt */
  917. return -QDF_STATUS_E_NOENT;
  918. break;
  919. case TCL_DATA:
  920. case TCL_CMD:
  921. case REO_CMD:
  922. case SW2WBM_RELEASE:
  923. case WBM_IDLE_LINK:
  924. /* normally empty SW_TO_HW rings */
  925. return -QDF_STATUS_E_NOENT;
  926. break;
  927. case TCL_STATUS:
  928. case REO_REINJECT:
  929. /* misc unused rings */
  930. return -QDF_STATUS_E_NOENT;
  931. break;
  932. case CE_SRC:
  933. case CE_DST:
  934. case CE_DST_STATUS:
  935. /* CE_rings - currently handled by hif */
  936. default:
  937. return -QDF_STATUS_E_NOENT;
  938. break;
  939. }
  940. return dp_srng_find_ring_in_mask(ring_num, grp_mask);
  941. }
  942. static void dp_srng_msi_setup(struct dp_soc *soc, struct hal_srng_params
  943. *ring_params, int ring_type, int ring_num)
  944. {
  945. int msi_group_number;
  946. int msi_data_count;
  947. int ret;
  948. uint32_t msi_data_start, msi_irq_start, addr_low, addr_high;
  949. ret = pld_get_user_msi_assignment(soc->osdev->dev, "DP",
  950. &msi_data_count, &msi_data_start,
  951. &msi_irq_start);
  952. if (ret)
  953. return;
  954. msi_group_number = dp_srng_calculate_msi_group(soc, ring_type,
  955. ring_num);
  956. if (msi_group_number < 0) {
  957. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
  958. FL("ring not part of an ext_group; ring_type: %d,ring_num %d"),
  959. ring_type, ring_num);
  960. ring_params->msi_addr = 0;
  961. ring_params->msi_data = 0;
  962. return;
  963. }
  964. if (msi_group_number > msi_data_count) {
  965. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_WARN,
  966. FL("2 msi_groups will share an msi; msi_group_num %d"),
  967. msi_group_number);
  968. QDF_ASSERT(0);
  969. }
  970. pld_get_msi_address(soc->osdev->dev, &addr_low, &addr_high);
  971. ring_params->msi_addr = addr_low;
  972. ring_params->msi_addr |= (qdf_dma_addr_t)(((uint64_t)addr_high) << 32);
  973. ring_params->msi_data = (msi_group_number % msi_data_count)
  974. + msi_data_start;
  975. ring_params->flags |= HAL_SRNG_MSI_INTR;
  976. }
  977. /**
  978. * dp_print_ast_stats() - Dump AST table contents
  979. * @soc: Datapath soc handle
  980. *
  981. * return void
  982. */
  983. #ifdef FEATURE_AST
  984. void dp_print_ast_stats(struct dp_soc *soc)
  985. {
  986. uint8_t i;
  987. uint8_t num_entries = 0;
  988. struct dp_vdev *vdev;
  989. struct dp_pdev *pdev;
  990. struct dp_peer *peer;
  991. struct dp_ast_entry *ase, *tmp_ase;
  992. char type[CDP_TXRX_AST_TYPE_MAX][10] = {
  993. "NONE", "STATIC", "SELF", "WDS", "MEC", "HMWDS", "BSS",
  994. "DA", "HMWDS_SEC"};
  995. DP_PRINT_STATS("AST Stats:");
  996. DP_PRINT_STATS(" Entries Added = %d", soc->stats.ast.added);
  997. DP_PRINT_STATS(" Entries Deleted = %d", soc->stats.ast.deleted);
  998. DP_PRINT_STATS(" Entries Agedout = %d", soc->stats.ast.aged_out);
  999. DP_PRINT_STATS(" Entries MAP ERR = %d", soc->stats.ast.map_err);
  1000. DP_PRINT_STATS("AST Table:");
  1001. qdf_spin_lock_bh(&soc->ast_lock);
  1002. for (i = 0; i < MAX_PDEV_CNT && soc->pdev_list[i]; i++) {
  1003. pdev = soc->pdev_list[i];
  1004. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  1005. DP_PDEV_ITERATE_VDEV_LIST(pdev, vdev) {
  1006. DP_VDEV_ITERATE_PEER_LIST(vdev, peer) {
  1007. DP_PEER_ITERATE_ASE_LIST(peer, ase, tmp_ase) {
  1008. DP_PRINT_STATS("%6d mac_addr = %pM"
  1009. " peer_mac_addr = %pM"
  1010. " peer_id = %u"
  1011. " type = %s"
  1012. " next_hop = %d"
  1013. " is_active = %d"
  1014. " ast_idx = %d"
  1015. " ast_hash = %d"
  1016. " delete_in_progress = %d"
  1017. " pdev_id = %d"
  1018. " vdev_id = %d",
  1019. ++num_entries,
  1020. ase->mac_addr.raw,
  1021. ase->peer->mac_addr.raw,
  1022. ase->peer->peer_ids[0],
  1023. type[ase->type],
  1024. ase->next_hop,
  1025. ase->is_active,
  1026. ase->ast_idx,
  1027. ase->ast_hash_value,
  1028. ase->delete_in_progress,
  1029. ase->pdev_id,
  1030. vdev->vdev_id);
  1031. }
  1032. }
  1033. }
  1034. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  1035. }
  1036. qdf_spin_unlock_bh(&soc->ast_lock);
  1037. }
  1038. #else
  1039. void dp_print_ast_stats(struct dp_soc *soc)
  1040. {
  1041. DP_PRINT_STATS("AST Stats not available.Enable FEATURE_AST");
  1042. return;
  1043. }
  1044. #endif
  1045. /**
  1046. * dp_print_peer_table() - Dump all Peer stats
  1047. * @vdev: Datapath Vdev handle
  1048. *
  1049. * return void
  1050. */
  1051. static void dp_print_peer_table(struct dp_vdev *vdev)
  1052. {
  1053. struct dp_peer *peer = NULL;
  1054. DP_PRINT_STATS("Dumping Peer Table Stats:");
  1055. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  1056. if (!peer) {
  1057. DP_PRINT_STATS("Invalid Peer");
  1058. return;
  1059. }
  1060. DP_PRINT_STATS(" peer_mac_addr = %pM"
  1061. " nawds_enabled = %d"
  1062. " bss_peer = %d"
  1063. " wds_enabled = %d"
  1064. " tx_cap_enabled = %d"
  1065. " rx_cap_enabled = %d"
  1066. " delete in progress = %d"
  1067. " peer id = %d",
  1068. peer->mac_addr.raw,
  1069. peer->nawds_enabled,
  1070. peer->bss_peer,
  1071. peer->wds_enabled,
  1072. peer->tx_cap_enabled,
  1073. peer->rx_cap_enabled,
  1074. peer->delete_in_progress,
  1075. peer->peer_ids[0]);
  1076. }
  1077. }
  1078. #ifdef WLAN_DP_PER_RING_TYPE_CONFIG
  1079. /**
  1080. * dp_srng_configure_interrupt_thresholds() - Retrieve interrupt
  1081. * threshold values from the wlan_srng_cfg table for each ring type
  1082. * @soc: device handle
  1083. * @ring_params: per ring specific parameters
  1084. * @ring_type: Ring type
  1085. * @ring_num: Ring number for a given ring type
  1086. *
  1087. * Fill the ring params with the interrupt threshold
  1088. * configuration parameters available in the per ring type wlan_srng_cfg
  1089. * table.
  1090. *
  1091. * Return: None
  1092. */
  1093. static void
  1094. dp_srng_configure_interrupt_thresholds(struct dp_soc *soc,
  1095. struct hal_srng_params *ring_params,
  1096. int ring_type, int ring_num,
  1097. int num_entries)
  1098. {
  1099. if (ring_type == WBM2SW_RELEASE && (ring_num == 3)) {
  1100. ring_params->intr_timer_thres_us =
  1101. wlan_cfg_get_int_timer_threshold_other(soc->wlan_cfg_ctx);
  1102. ring_params->intr_batch_cntr_thres_entries =
  1103. wlan_cfg_get_int_batch_threshold_other(soc->wlan_cfg_ctx);
  1104. } else {
  1105. ring_params->intr_timer_thres_us =
  1106. soc->wlan_srng_cfg[ring_type].timer_threshold;
  1107. ring_params->intr_batch_cntr_thres_entries =
  1108. soc->wlan_srng_cfg[ring_type].batch_count_threshold;
  1109. }
  1110. ring_params->low_threshold =
  1111. soc->wlan_srng_cfg[ring_type].low_threshold;
  1112. if (ring_params->low_threshold)
  1113. ring_params->flags |= HAL_SRNG_LOW_THRES_INTR_ENABLE;
  1114. }
  1115. #else
  1116. static void
  1117. dp_srng_configure_interrupt_thresholds(struct dp_soc *soc,
  1118. struct hal_srng_params *ring_params,
  1119. int ring_type, int ring_num,
  1120. int num_entries)
  1121. {
  1122. if (ring_type == REO_DST) {
  1123. ring_params->intr_timer_thres_us =
  1124. wlan_cfg_get_int_timer_threshold_rx(soc->wlan_cfg_ctx);
  1125. ring_params->intr_batch_cntr_thres_entries =
  1126. wlan_cfg_get_int_batch_threshold_rx(soc->wlan_cfg_ctx);
  1127. } else if (ring_type == WBM2SW_RELEASE && (ring_num < 3)) {
  1128. ring_params->intr_timer_thres_us =
  1129. wlan_cfg_get_int_timer_threshold_tx(soc->wlan_cfg_ctx);
  1130. ring_params->intr_batch_cntr_thres_entries =
  1131. wlan_cfg_get_int_batch_threshold_tx(soc->wlan_cfg_ctx);
  1132. } else {
  1133. ring_params->intr_timer_thres_us =
  1134. wlan_cfg_get_int_timer_threshold_other(soc->wlan_cfg_ctx);
  1135. ring_params->intr_batch_cntr_thres_entries =
  1136. wlan_cfg_get_int_batch_threshold_other(soc->wlan_cfg_ctx);
  1137. }
  1138. /* Enable low threshold interrupts for rx buffer rings (regular and
  1139. * monitor buffer rings.
  1140. * TODO: See if this is required for any other ring
  1141. */
  1142. if ((ring_type == RXDMA_BUF) || (ring_type == RXDMA_MONITOR_BUF) ||
  1143. (ring_type == RXDMA_MONITOR_STATUS)) {
  1144. /* TODO: Setting low threshold to 1/8th of ring size
  1145. * see if this needs to be configurable
  1146. */
  1147. ring_params->low_threshold = num_entries >> 3;
  1148. ring_params->intr_timer_thres_us =
  1149. wlan_cfg_get_int_timer_threshold_rx(soc->wlan_cfg_ctx);
  1150. ring_params->flags |= HAL_SRNG_LOW_THRES_INTR_ENABLE;
  1151. ring_params->intr_batch_cntr_thres_entries = 0;
  1152. }
  1153. }
  1154. #endif
  1155. /**
  1156. * dp_srng_setup() - Internal function to setup SRNG rings used by data path
  1157. * @soc: datapath soc handle
  1158. * @srng: srng handle
  1159. * @ring_type: ring that needs to be configured
  1160. * @mac_id: mac number
  1161. * @num_entries: Total number of entries for a given ring
  1162. *
  1163. * Return: non-zero - failure/zero - success
  1164. */
  1165. static int dp_srng_setup(struct dp_soc *soc, struct dp_srng *srng,
  1166. int ring_type, int ring_num, int mac_id,
  1167. uint32_t num_entries, bool cached)
  1168. {
  1169. hal_soc_handle_t hal_soc = soc->hal_soc;
  1170. uint32_t entry_size = hal_srng_get_entrysize(hal_soc, ring_type);
  1171. /* TODO: See if we should get align size from hal */
  1172. uint32_t ring_base_align = 8;
  1173. struct hal_srng_params ring_params;
  1174. uint32_t max_entries = hal_srng_max_entries(hal_soc, ring_type);
  1175. /* TODO: Currently hal layer takes care of endianness related settings.
  1176. * See if these settings need to passed from DP layer
  1177. */
  1178. ring_params.flags = 0;
  1179. num_entries = (num_entries > max_entries) ? max_entries : num_entries;
  1180. srng->hal_srng = NULL;
  1181. srng->alloc_size = num_entries * entry_size;
  1182. srng->num_entries = num_entries;
  1183. if (!dp_is_soc_reinit(soc)) {
  1184. if (!cached) {
  1185. ring_params.ring_base_vaddr =
  1186. qdf_aligned_mem_alloc_consistent(
  1187. soc->osdev, &srng->alloc_size,
  1188. &srng->base_vaddr_unaligned,
  1189. &srng->base_paddr_unaligned,
  1190. &ring_params.ring_base_paddr,
  1191. ring_base_align);
  1192. } else {
  1193. ring_params.ring_base_vaddr = qdf_aligned_malloc(
  1194. &srng->alloc_size,
  1195. &srng->base_vaddr_unaligned,
  1196. &srng->base_paddr_unaligned,
  1197. &ring_params.ring_base_paddr,
  1198. ring_base_align);
  1199. }
  1200. if (!ring_params.ring_base_vaddr) {
  1201. dp_err("alloc failed - ring_type: %d, ring_num %d",
  1202. ring_type, ring_num);
  1203. return QDF_STATUS_E_NOMEM;
  1204. }
  1205. }
  1206. ring_params.ring_base_paddr = (qdf_dma_addr_t)qdf_align(
  1207. (unsigned long)(srng->base_paddr_unaligned),
  1208. ring_base_align);
  1209. ring_params.ring_base_vaddr = (void *)(
  1210. (unsigned long)(srng->base_vaddr_unaligned) +
  1211. ((unsigned long)(ring_params.ring_base_paddr) -
  1212. (unsigned long)(srng->base_paddr_unaligned)));
  1213. qdf_assert_always(ring_params.ring_base_vaddr);
  1214. ring_params.num_entries = num_entries;
  1215. dp_verbose_debug("Ring type: %d, num:%d vaddr %pK paddr %pK entries %u",
  1216. ring_type, ring_num,
  1217. (void *)ring_params.ring_base_vaddr,
  1218. (void *)ring_params.ring_base_paddr,
  1219. ring_params.num_entries);
  1220. if (soc->intr_mode == DP_INTR_MSI) {
  1221. dp_srng_msi_setup(soc, &ring_params, ring_type, ring_num);
  1222. dp_verbose_debug("Using MSI for ring_type: %d, ring_num %d",
  1223. ring_type, ring_num);
  1224. } else {
  1225. ring_params.msi_data = 0;
  1226. ring_params.msi_addr = 0;
  1227. dp_verbose_debug("Skipping MSI for ring_type: %d, ring_num %d",
  1228. ring_type, ring_num);
  1229. }
  1230. dp_srng_configure_interrupt_thresholds(soc, &ring_params,
  1231. ring_type, ring_num,
  1232. num_entries);
  1233. if (cached) {
  1234. ring_params.flags |= HAL_SRNG_CACHED_DESC;
  1235. srng->cached = 1;
  1236. }
  1237. srng->hal_srng = hal_srng_setup(hal_soc, ring_type, ring_num,
  1238. mac_id, &ring_params);
  1239. if (!srng->hal_srng) {
  1240. if (cached) {
  1241. qdf_mem_free(srng->base_vaddr_unaligned);
  1242. } else {
  1243. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  1244. srng->alloc_size,
  1245. srng->base_vaddr_unaligned,
  1246. srng->base_paddr_unaligned, 0);
  1247. }
  1248. }
  1249. return 0;
  1250. }
  1251. /*
  1252. * dp_srng_deinit() - Internal function to deinit SRNG rings used by data path
  1253. * @soc: DP SOC handle
  1254. * @srng: source ring structure
  1255. * @ring_type: type of ring
  1256. * @ring_num: ring number
  1257. *
  1258. * Return: None
  1259. */
  1260. static void dp_srng_deinit(struct dp_soc *soc, struct dp_srng *srng,
  1261. int ring_type, int ring_num)
  1262. {
  1263. if (!srng->hal_srng) {
  1264. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1265. FL("Ring type: %d, num:%d not setup"),
  1266. ring_type, ring_num);
  1267. return;
  1268. }
  1269. hal_srng_cleanup(soc->hal_soc, srng->hal_srng);
  1270. srng->hal_srng = NULL;
  1271. }
  1272. /**
  1273. * dp_srng_cleanup - Internal function to cleanup SRNG rings used by data path
  1274. * Any buffers allocated and attached to ring entries are expected to be freed
  1275. * before calling this function.
  1276. */
  1277. static void dp_srng_cleanup(struct dp_soc *soc, struct dp_srng *srng,
  1278. int ring_type, int ring_num)
  1279. {
  1280. if (!dp_is_soc_reinit(soc)) {
  1281. if (!srng->hal_srng && (srng->alloc_size == 0)) {
  1282. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1283. FL("Ring type: %d, num:%d not setup"),
  1284. ring_type, ring_num);
  1285. return;
  1286. }
  1287. if (srng->hal_srng) {
  1288. hal_srng_cleanup(soc->hal_soc, srng->hal_srng);
  1289. srng->hal_srng = NULL;
  1290. }
  1291. }
  1292. if (srng->alloc_size && srng->base_vaddr_unaligned) {
  1293. if (!srng->cached) {
  1294. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  1295. srng->alloc_size,
  1296. srng->base_vaddr_unaligned,
  1297. srng->base_paddr_unaligned, 0);
  1298. } else {
  1299. qdf_mem_free(srng->base_vaddr_unaligned);
  1300. }
  1301. srng->alloc_size = 0;
  1302. srng->base_vaddr_unaligned = NULL;
  1303. }
  1304. srng->hal_srng = NULL;
  1305. }
  1306. /* TODO: Need this interface from HIF */
  1307. void *hif_get_hal_handle(struct hif_opaque_softc *hif_handle);
  1308. #ifdef WLAN_FEATURE_DP_EVENT_HISTORY
  1309. int dp_srng_access_start(struct dp_intr *int_ctx, struct dp_soc *dp_soc,
  1310. hal_ring_handle_t hal_ring_hdl)
  1311. {
  1312. hal_soc_handle_t hal_soc = dp_soc->hal_soc;
  1313. uint32_t hp, tp;
  1314. uint8_t ring_id;
  1315. hal_get_sw_hptp(hal_soc, hal_ring_hdl, &tp, &hp);
  1316. ring_id = hal_srng_ring_id_get(hal_ring_hdl);
  1317. hif_record_event(dp_soc->hif_handle, int_ctx->dp_intr_id,
  1318. ring_id, hp, tp, HIF_EVENT_SRNG_ACCESS_START);
  1319. return hal_srng_access_start(hal_soc, hal_ring_hdl);
  1320. }
  1321. void dp_srng_access_end(struct dp_intr *int_ctx, struct dp_soc *dp_soc,
  1322. hal_ring_handle_t hal_ring_hdl)
  1323. {
  1324. hal_soc_handle_t hal_soc = dp_soc->hal_soc;
  1325. uint32_t hp, tp;
  1326. uint8_t ring_id;
  1327. hal_get_sw_hptp(hal_soc, hal_ring_hdl, &tp, &hp);
  1328. ring_id = hal_srng_ring_id_get(hal_ring_hdl);
  1329. hif_record_event(dp_soc->hif_handle, int_ctx->dp_intr_id,
  1330. ring_id, hp, tp, HIF_EVENT_SRNG_ACCESS_END);
  1331. return hal_srng_access_end(hal_soc, hal_ring_hdl);
  1332. }
  1333. #endif /* WLAN_FEATURE_DP_EVENT_HISTORY */
  1334. /*
  1335. * dp_service_srngs() - Top level interrupt handler for DP Ring interrupts
  1336. * @dp_ctx: DP SOC handle
  1337. * @budget: Number of frames/descriptors that can be processed in one shot
  1338. *
  1339. * Return: remaining budget/quota for the soc device
  1340. */
  1341. static uint32_t dp_service_srngs(void *dp_ctx, uint32_t dp_budget)
  1342. {
  1343. struct dp_intr *int_ctx = (struct dp_intr *)dp_ctx;
  1344. struct dp_intr_stats *intr_stats = &int_ctx->intr_stats;
  1345. struct dp_soc *soc = int_ctx->soc;
  1346. int ring = 0;
  1347. uint32_t work_done = 0;
  1348. int budget = dp_budget;
  1349. uint8_t tx_mask = int_ctx->tx_ring_mask;
  1350. uint8_t rx_mask = int_ctx->rx_ring_mask;
  1351. uint8_t rx_err_mask = int_ctx->rx_err_ring_mask;
  1352. uint8_t rx_wbm_rel_mask = int_ctx->rx_wbm_rel_ring_mask;
  1353. uint8_t reo_status_mask = int_ctx->reo_status_ring_mask;
  1354. uint32_t remaining_quota = dp_budget;
  1355. struct dp_pdev *pdev = NULL;
  1356. dp_verbose_debug("tx %x rx %x rx_err %x rx_wbm_rel %x reo_status %x rx_mon_ring %x host2rxdma %x rxdma2host %x\n",
  1357. tx_mask, rx_mask, rx_err_mask, rx_wbm_rel_mask,
  1358. reo_status_mask,
  1359. int_ctx->rx_mon_ring_mask,
  1360. int_ctx->host2rxdma_ring_mask,
  1361. int_ctx->rxdma2host_ring_mask);
  1362. /* Process Tx completion interrupts first to return back buffers */
  1363. while (tx_mask) {
  1364. if (tx_mask & 0x1) {
  1365. work_done = dp_tx_comp_handler(int_ctx,
  1366. soc,
  1367. soc->tx_comp_ring[ring].hal_srng,
  1368. ring, remaining_quota);
  1369. if (work_done) {
  1370. intr_stats->num_tx_ring_masks[ring]++;
  1371. dp_verbose_debug("tx mask 0x%x ring %d, budget %d, work_done %d",
  1372. tx_mask, ring, budget,
  1373. work_done);
  1374. }
  1375. budget -= work_done;
  1376. if (budget <= 0)
  1377. goto budget_done;
  1378. remaining_quota = budget;
  1379. }
  1380. tx_mask = tx_mask >> 1;
  1381. ring++;
  1382. }
  1383. /* Process REO Exception ring interrupt */
  1384. if (rx_err_mask) {
  1385. work_done = dp_rx_err_process(int_ctx, soc,
  1386. soc->reo_exception_ring.hal_srng,
  1387. remaining_quota);
  1388. if (work_done) {
  1389. intr_stats->num_rx_err_ring_masks++;
  1390. dp_verbose_debug("REO Exception Ring: work_done %d budget %d",
  1391. work_done, budget);
  1392. }
  1393. budget -= work_done;
  1394. if (budget <= 0) {
  1395. goto budget_done;
  1396. }
  1397. remaining_quota = budget;
  1398. }
  1399. /* Process Rx WBM release ring interrupt */
  1400. if (rx_wbm_rel_mask) {
  1401. work_done = dp_rx_wbm_err_process(int_ctx, soc,
  1402. soc->rx_rel_ring.hal_srng,
  1403. remaining_quota);
  1404. if (work_done) {
  1405. intr_stats->num_rx_wbm_rel_ring_masks++;
  1406. dp_verbose_debug("WBM Release Ring: work_done %d budget %d",
  1407. work_done, budget);
  1408. }
  1409. budget -= work_done;
  1410. if (budget <= 0) {
  1411. goto budget_done;
  1412. }
  1413. remaining_quota = budget;
  1414. }
  1415. /* Process Rx interrupts */
  1416. if (rx_mask) {
  1417. for (ring = 0; ring < soc->num_reo_dest_rings; ring++) {
  1418. if (!(rx_mask & (1 << ring)))
  1419. continue;
  1420. work_done = dp_rx_process(int_ctx,
  1421. soc->reo_dest_ring[ring].hal_srng,
  1422. ring,
  1423. remaining_quota);
  1424. if (work_done) {
  1425. intr_stats->num_rx_ring_masks[ring]++;
  1426. dp_verbose_debug("rx mask 0x%x ring %d, work_done %d budget %d",
  1427. rx_mask, ring,
  1428. work_done, budget);
  1429. budget -= work_done;
  1430. if (budget <= 0)
  1431. goto budget_done;
  1432. remaining_quota = budget;
  1433. }
  1434. }
  1435. }
  1436. if (reo_status_mask) {
  1437. if (dp_reo_status_ring_handler(int_ctx, soc))
  1438. int_ctx->intr_stats.num_reo_status_ring_masks++;
  1439. }
  1440. /* Process LMAC interrupts */
  1441. for (ring = 0 ; ring < MAX_NUM_LMAC_HW; ring++) {
  1442. int mac_for_pdev = ring;
  1443. pdev = dp_get_pdev_for_lmac_id(soc, mac_for_pdev);
  1444. if (!pdev)
  1445. continue;
  1446. if (int_ctx->rx_mon_ring_mask & (1 << mac_for_pdev)) {
  1447. work_done = dp_mon_process(soc, mac_for_pdev,
  1448. remaining_quota);
  1449. if (work_done)
  1450. intr_stats->num_rx_mon_ring_masks++;
  1451. budget -= work_done;
  1452. if (budget <= 0)
  1453. goto budget_done;
  1454. remaining_quota = budget;
  1455. }
  1456. if (int_ctx->rxdma2host_ring_mask &
  1457. (1 << mac_for_pdev)) {
  1458. work_done = dp_rxdma_err_process(int_ctx, soc,
  1459. mac_for_pdev,
  1460. remaining_quota);
  1461. if (work_done)
  1462. intr_stats->num_rxdma2host_ring_masks++;
  1463. budget -= work_done;
  1464. if (budget <= 0)
  1465. goto budget_done;
  1466. remaining_quota = budget;
  1467. }
  1468. if (int_ctx->host2rxdma_ring_mask &
  1469. (1 << mac_for_pdev)) {
  1470. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1471. union dp_rx_desc_list_elem_t *tail = NULL;
  1472. struct dp_srng *rx_refill_buf_ring =
  1473. &soc->rx_refill_buf_ring[mac_for_pdev];
  1474. intr_stats->num_host2rxdma_ring_masks++;
  1475. DP_STATS_INC(pdev, replenish.low_thresh_intrs,
  1476. 1);
  1477. dp_rx_buffers_replenish(soc, mac_for_pdev,
  1478. rx_refill_buf_ring,
  1479. &soc->rx_desc_buf[mac_for_pdev],
  1480. 0, &desc_list, &tail);
  1481. }
  1482. }
  1483. qdf_lro_flush(int_ctx->lro_ctx);
  1484. intr_stats->num_masks++;
  1485. budget_done:
  1486. return dp_budget - budget;
  1487. }
  1488. /* dp_interrupt_timer()- timer poll for interrupts
  1489. *
  1490. * @arg: SoC Handle
  1491. *
  1492. * Return:
  1493. *
  1494. */
  1495. static void dp_interrupt_timer(void *arg)
  1496. {
  1497. struct dp_soc *soc = (struct dp_soc *) arg;
  1498. int i;
  1499. if (qdf_atomic_read(&soc->cmn_init_done)) {
  1500. for (i = 0;
  1501. i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++)
  1502. dp_service_srngs(&soc->intr_ctx[i], 0xffff);
  1503. qdf_timer_mod(&soc->int_timer, DP_INTR_POLL_TIMER_MS);
  1504. }
  1505. }
  1506. /*
  1507. * dp_soc_attach_poll() - Register handlers for DP interrupts
  1508. * @txrx_soc: DP SOC handle
  1509. *
  1510. * Host driver will register for “DP_NUM_INTERRUPT_CONTEXTS” number of NAPI
  1511. * contexts. Each NAPI context will have a tx_ring_mask , rx_ring_mask ,and
  1512. * rx_monitor_ring mask to indicate the rings that are processed by the handler.
  1513. *
  1514. * Return: 0 for success, nonzero for failure.
  1515. */
  1516. static QDF_STATUS dp_soc_attach_poll(struct cdp_soc_t *txrx_soc)
  1517. {
  1518. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  1519. int i;
  1520. soc->intr_mode = DP_INTR_POLL;
  1521. for (i = 0; i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++) {
  1522. soc->intr_ctx[i].dp_intr_id = i;
  1523. soc->intr_ctx[i].tx_ring_mask =
  1524. wlan_cfg_get_tx_ring_mask(soc->wlan_cfg_ctx, i);
  1525. soc->intr_ctx[i].rx_ring_mask =
  1526. wlan_cfg_get_rx_ring_mask(soc->wlan_cfg_ctx, i);
  1527. soc->intr_ctx[i].rx_mon_ring_mask =
  1528. wlan_cfg_get_rx_mon_ring_mask(soc->wlan_cfg_ctx, i);
  1529. soc->intr_ctx[i].rx_err_ring_mask =
  1530. wlan_cfg_get_rx_err_ring_mask(soc->wlan_cfg_ctx, i);
  1531. soc->intr_ctx[i].rx_wbm_rel_ring_mask =
  1532. wlan_cfg_get_rx_wbm_rel_ring_mask(soc->wlan_cfg_ctx, i);
  1533. soc->intr_ctx[i].reo_status_ring_mask =
  1534. wlan_cfg_get_reo_status_ring_mask(soc->wlan_cfg_ctx, i);
  1535. soc->intr_ctx[i].rxdma2host_ring_mask =
  1536. wlan_cfg_get_rxdma2host_ring_mask(soc->wlan_cfg_ctx, i);
  1537. soc->intr_ctx[i].soc = soc;
  1538. soc->intr_ctx[i].lro_ctx = qdf_lro_init();
  1539. }
  1540. qdf_timer_init(soc->osdev, &soc->int_timer,
  1541. dp_interrupt_timer, (void *)soc,
  1542. QDF_TIMER_TYPE_WAKE_APPS);
  1543. return QDF_STATUS_SUCCESS;
  1544. }
  1545. /**
  1546. * dp_soc_set_interrupt_mode() - Set the interrupt mode in soc
  1547. * soc: DP soc handle
  1548. *
  1549. * Set the appropriate interrupt mode flag in the soc
  1550. */
  1551. static void dp_soc_set_interrupt_mode(struct dp_soc *soc)
  1552. {
  1553. uint32_t msi_base_data, msi_vector_start;
  1554. int msi_vector_count, ret;
  1555. soc->intr_mode = DP_INTR_INTEGRATED;
  1556. if (!(soc->wlan_cfg_ctx->napi_enabled) ||
  1557. (soc->cdp_soc.ol_ops->get_con_mode &&
  1558. soc->cdp_soc.ol_ops->get_con_mode() == QDF_GLOBAL_MONITOR_MODE)) {
  1559. soc->intr_mode = DP_INTR_POLL;
  1560. } else {
  1561. ret = pld_get_user_msi_assignment(soc->osdev->dev, "DP",
  1562. &msi_vector_count,
  1563. &msi_base_data,
  1564. &msi_vector_start);
  1565. if (ret)
  1566. return;
  1567. soc->intr_mode = DP_INTR_MSI;
  1568. }
  1569. }
  1570. static QDF_STATUS dp_soc_interrupt_attach(struct cdp_soc_t *txrx_soc);
  1571. #if defined(DP_INTR_POLL_BOTH)
  1572. /*
  1573. * dp_soc_interrupt_attach_wrapper() - Register handlers for DP interrupts
  1574. * @txrx_soc: DP SOC handle
  1575. *
  1576. * Call the appropriate attach function based on the mode of operation.
  1577. * This is a WAR for enabling monitor mode.
  1578. *
  1579. * Return: 0 for success. nonzero for failure.
  1580. */
  1581. static QDF_STATUS dp_soc_interrupt_attach_wrapper(struct cdp_soc_t *txrx_soc)
  1582. {
  1583. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  1584. if (!(soc->wlan_cfg_ctx->napi_enabled) ||
  1585. (soc->cdp_soc.ol_ops->get_con_mode &&
  1586. soc->cdp_soc.ol_ops->get_con_mode() ==
  1587. QDF_GLOBAL_MONITOR_MODE)) {
  1588. dp_info("Poll mode");
  1589. return dp_soc_attach_poll(txrx_soc);
  1590. } else {
  1591. dp_info("Interrupt mode");
  1592. return dp_soc_interrupt_attach(txrx_soc);
  1593. }
  1594. }
  1595. #else
  1596. #if defined(DP_INTR_POLL_BASED) && DP_INTR_POLL_BASED
  1597. static QDF_STATUS dp_soc_interrupt_attach_wrapper(struct cdp_soc_t *txrx_soc)
  1598. {
  1599. return dp_soc_attach_poll(txrx_soc);
  1600. }
  1601. #else
  1602. static QDF_STATUS dp_soc_interrupt_attach_wrapper(struct cdp_soc_t *txrx_soc)
  1603. {
  1604. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  1605. if (hif_is_polled_mode_enabled(soc->hif_handle))
  1606. return dp_soc_attach_poll(txrx_soc);
  1607. else
  1608. return dp_soc_interrupt_attach(txrx_soc);
  1609. }
  1610. #endif
  1611. #endif
  1612. static void dp_soc_interrupt_map_calculate_integrated(struct dp_soc *soc,
  1613. int intr_ctx_num, int *irq_id_map, int *num_irq_r)
  1614. {
  1615. int j;
  1616. int num_irq = 0;
  1617. int tx_mask =
  1618. wlan_cfg_get_tx_ring_mask(soc->wlan_cfg_ctx, intr_ctx_num);
  1619. int rx_mask =
  1620. wlan_cfg_get_rx_ring_mask(soc->wlan_cfg_ctx, intr_ctx_num);
  1621. int rx_mon_mask =
  1622. wlan_cfg_get_rx_mon_ring_mask(soc->wlan_cfg_ctx, intr_ctx_num);
  1623. int rx_err_ring_mask = wlan_cfg_get_rx_err_ring_mask(
  1624. soc->wlan_cfg_ctx, intr_ctx_num);
  1625. int rx_wbm_rel_ring_mask = wlan_cfg_get_rx_wbm_rel_ring_mask(
  1626. soc->wlan_cfg_ctx, intr_ctx_num);
  1627. int reo_status_ring_mask = wlan_cfg_get_reo_status_ring_mask(
  1628. soc->wlan_cfg_ctx, intr_ctx_num);
  1629. int rxdma2host_ring_mask = wlan_cfg_get_rxdma2host_ring_mask(
  1630. soc->wlan_cfg_ctx, intr_ctx_num);
  1631. int host2rxdma_ring_mask = wlan_cfg_get_host2rxdma_ring_mask(
  1632. soc->wlan_cfg_ctx, intr_ctx_num);
  1633. int host2rxdma_mon_ring_mask = wlan_cfg_get_host2rxdma_mon_ring_mask(
  1634. soc->wlan_cfg_ctx, intr_ctx_num);
  1635. soc->intr_mode = DP_INTR_INTEGRATED;
  1636. for (j = 0; j < HIF_MAX_GRP_IRQ; j++) {
  1637. if (tx_mask & (1 << j)) {
  1638. irq_id_map[num_irq++] =
  1639. (wbm2host_tx_completions_ring1 - j);
  1640. }
  1641. if (rx_mask & (1 << j)) {
  1642. irq_id_map[num_irq++] =
  1643. (reo2host_destination_ring1 - j);
  1644. }
  1645. if (rxdma2host_ring_mask & (1 << j)) {
  1646. irq_id_map[num_irq++] =
  1647. rxdma2host_destination_ring_mac1 - j;
  1648. }
  1649. if (host2rxdma_ring_mask & (1 << j)) {
  1650. irq_id_map[num_irq++] =
  1651. host2rxdma_host_buf_ring_mac1 - j;
  1652. }
  1653. if (host2rxdma_mon_ring_mask & (1 << j)) {
  1654. irq_id_map[num_irq++] =
  1655. host2rxdma_monitor_ring1 - j;
  1656. }
  1657. if (rx_mon_mask & (1 << j)) {
  1658. irq_id_map[num_irq++] =
  1659. ppdu_end_interrupts_mac1 - j;
  1660. irq_id_map[num_irq++] =
  1661. rxdma2host_monitor_status_ring_mac1 - j;
  1662. }
  1663. if (rx_wbm_rel_ring_mask & (1 << j))
  1664. irq_id_map[num_irq++] = wbm2host_rx_release;
  1665. if (rx_err_ring_mask & (1 << j))
  1666. irq_id_map[num_irq++] = reo2host_exception;
  1667. if (reo_status_ring_mask & (1 << j))
  1668. irq_id_map[num_irq++] = reo2host_status;
  1669. }
  1670. *num_irq_r = num_irq;
  1671. }
  1672. static void dp_soc_interrupt_map_calculate_msi(struct dp_soc *soc,
  1673. int intr_ctx_num, int *irq_id_map, int *num_irq_r,
  1674. int msi_vector_count, int msi_vector_start)
  1675. {
  1676. int tx_mask = wlan_cfg_get_tx_ring_mask(
  1677. soc->wlan_cfg_ctx, intr_ctx_num);
  1678. int rx_mask = wlan_cfg_get_rx_ring_mask(
  1679. soc->wlan_cfg_ctx, intr_ctx_num);
  1680. int rx_mon_mask = wlan_cfg_get_rx_mon_ring_mask(
  1681. soc->wlan_cfg_ctx, intr_ctx_num);
  1682. int rx_err_ring_mask = wlan_cfg_get_rx_err_ring_mask(
  1683. soc->wlan_cfg_ctx, intr_ctx_num);
  1684. int rx_wbm_rel_ring_mask = wlan_cfg_get_rx_wbm_rel_ring_mask(
  1685. soc->wlan_cfg_ctx, intr_ctx_num);
  1686. int reo_status_ring_mask = wlan_cfg_get_reo_status_ring_mask(
  1687. soc->wlan_cfg_ctx, intr_ctx_num);
  1688. int rxdma2host_ring_mask = wlan_cfg_get_rxdma2host_ring_mask(
  1689. soc->wlan_cfg_ctx, intr_ctx_num);
  1690. unsigned int vector =
  1691. (intr_ctx_num % msi_vector_count) + msi_vector_start;
  1692. int num_irq = 0;
  1693. soc->intr_mode = DP_INTR_MSI;
  1694. if (tx_mask | rx_mask | rx_mon_mask | rx_err_ring_mask |
  1695. rx_wbm_rel_ring_mask | reo_status_ring_mask | rxdma2host_ring_mask)
  1696. irq_id_map[num_irq++] =
  1697. pld_get_msi_irq(soc->osdev->dev, vector);
  1698. *num_irq_r = num_irq;
  1699. }
  1700. static void dp_soc_interrupt_map_calculate(struct dp_soc *soc, int intr_ctx_num,
  1701. int *irq_id_map, int *num_irq)
  1702. {
  1703. int msi_vector_count, ret;
  1704. uint32_t msi_base_data, msi_vector_start;
  1705. ret = pld_get_user_msi_assignment(soc->osdev->dev, "DP",
  1706. &msi_vector_count,
  1707. &msi_base_data,
  1708. &msi_vector_start);
  1709. if (ret)
  1710. return dp_soc_interrupt_map_calculate_integrated(soc,
  1711. intr_ctx_num, irq_id_map, num_irq);
  1712. else
  1713. dp_soc_interrupt_map_calculate_msi(soc,
  1714. intr_ctx_num, irq_id_map, num_irq,
  1715. msi_vector_count, msi_vector_start);
  1716. }
  1717. /*
  1718. * dp_soc_interrupt_attach() - Register handlers for DP interrupts
  1719. * @txrx_soc: DP SOC handle
  1720. *
  1721. * Host driver will register for “DP_NUM_INTERRUPT_CONTEXTS” number of NAPI
  1722. * contexts. Each NAPI context will have a tx_ring_mask , rx_ring_mask ,and
  1723. * rx_monitor_ring mask to indicate the rings that are processed by the handler.
  1724. *
  1725. * Return: 0 for success. nonzero for failure.
  1726. */
  1727. static QDF_STATUS dp_soc_interrupt_attach(struct cdp_soc_t *txrx_soc)
  1728. {
  1729. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  1730. int i = 0;
  1731. int num_irq = 0;
  1732. for (i = 0; i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++) {
  1733. int ret = 0;
  1734. /* Map of IRQ ids registered with one interrupt context */
  1735. int irq_id_map[HIF_MAX_GRP_IRQ];
  1736. int tx_mask =
  1737. wlan_cfg_get_tx_ring_mask(soc->wlan_cfg_ctx, i);
  1738. int rx_mask =
  1739. wlan_cfg_get_rx_ring_mask(soc->wlan_cfg_ctx, i);
  1740. int rx_mon_mask =
  1741. dp_soc_get_mon_mask_for_interrupt_mode(soc, i);
  1742. int rx_err_ring_mask =
  1743. wlan_cfg_get_rx_err_ring_mask(soc->wlan_cfg_ctx, i);
  1744. int rx_wbm_rel_ring_mask =
  1745. wlan_cfg_get_rx_wbm_rel_ring_mask(soc->wlan_cfg_ctx, i);
  1746. int reo_status_ring_mask =
  1747. wlan_cfg_get_reo_status_ring_mask(soc->wlan_cfg_ctx, i);
  1748. int rxdma2host_ring_mask =
  1749. wlan_cfg_get_rxdma2host_ring_mask(soc->wlan_cfg_ctx, i);
  1750. int host2rxdma_ring_mask =
  1751. wlan_cfg_get_host2rxdma_ring_mask(soc->wlan_cfg_ctx, i);
  1752. int host2rxdma_mon_ring_mask =
  1753. wlan_cfg_get_host2rxdma_mon_ring_mask(
  1754. soc->wlan_cfg_ctx, i);
  1755. soc->intr_ctx[i].dp_intr_id = i;
  1756. soc->intr_ctx[i].tx_ring_mask = tx_mask;
  1757. soc->intr_ctx[i].rx_ring_mask = rx_mask;
  1758. soc->intr_ctx[i].rx_mon_ring_mask = rx_mon_mask;
  1759. soc->intr_ctx[i].rx_err_ring_mask = rx_err_ring_mask;
  1760. soc->intr_ctx[i].rxdma2host_ring_mask = rxdma2host_ring_mask;
  1761. soc->intr_ctx[i].host2rxdma_ring_mask = host2rxdma_ring_mask;
  1762. soc->intr_ctx[i].rx_wbm_rel_ring_mask = rx_wbm_rel_ring_mask;
  1763. soc->intr_ctx[i].reo_status_ring_mask = reo_status_ring_mask;
  1764. soc->intr_ctx[i].host2rxdma_mon_ring_mask =
  1765. host2rxdma_mon_ring_mask;
  1766. soc->intr_ctx[i].soc = soc;
  1767. num_irq = 0;
  1768. dp_soc_interrupt_map_calculate(soc, i, &irq_id_map[0],
  1769. &num_irq);
  1770. ret = hif_register_ext_group(soc->hif_handle,
  1771. num_irq, irq_id_map, dp_service_srngs,
  1772. &soc->intr_ctx[i], "dp_intr",
  1773. HIF_EXEC_NAPI_TYPE, QCA_NAPI_DEF_SCALE_BIN_SHIFT);
  1774. if (ret) {
  1775. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1776. FL("failed, ret = %d"), ret);
  1777. return QDF_STATUS_E_FAILURE;
  1778. }
  1779. soc->intr_ctx[i].lro_ctx = qdf_lro_init();
  1780. }
  1781. hif_configure_ext_group_interrupts(soc->hif_handle);
  1782. return QDF_STATUS_SUCCESS;
  1783. }
  1784. /*
  1785. * dp_soc_interrupt_detach() - Deregister any allocations done for interrupts
  1786. * @txrx_soc: DP SOC handle
  1787. *
  1788. * Return: none
  1789. */
  1790. static void dp_soc_interrupt_detach(struct cdp_soc_t *txrx_soc)
  1791. {
  1792. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  1793. int i;
  1794. if (soc->intr_mode == DP_INTR_POLL) {
  1795. qdf_timer_stop(&soc->int_timer);
  1796. qdf_timer_free(&soc->int_timer);
  1797. } else {
  1798. hif_deregister_exec_group(soc->hif_handle, "dp_intr");
  1799. }
  1800. for (i = 0; i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++) {
  1801. soc->intr_ctx[i].tx_ring_mask = 0;
  1802. soc->intr_ctx[i].rx_ring_mask = 0;
  1803. soc->intr_ctx[i].rx_mon_ring_mask = 0;
  1804. soc->intr_ctx[i].rx_err_ring_mask = 0;
  1805. soc->intr_ctx[i].rx_wbm_rel_ring_mask = 0;
  1806. soc->intr_ctx[i].reo_status_ring_mask = 0;
  1807. soc->intr_ctx[i].rxdma2host_ring_mask = 0;
  1808. soc->intr_ctx[i].host2rxdma_ring_mask = 0;
  1809. soc->intr_ctx[i].host2rxdma_mon_ring_mask = 0;
  1810. qdf_lro_deinit(soc->intr_ctx[i].lro_ctx);
  1811. }
  1812. }
  1813. #define AVG_MAX_MPDUS_PER_TID 128
  1814. #define AVG_TIDS_PER_CLIENT 2
  1815. #define AVG_FLOWS_PER_TID 2
  1816. #define AVG_MSDUS_PER_FLOW 128
  1817. #define AVG_MSDUS_PER_MPDU 4
  1818. /*
  1819. * Allocate and setup link descriptor pool that will be used by HW for
  1820. * various link and queue descriptors and managed by WBM
  1821. */
  1822. static int dp_hw_link_desc_pool_setup(struct dp_soc *soc)
  1823. {
  1824. int link_desc_size = hal_get_link_desc_size(soc->hal_soc);
  1825. int link_desc_align = hal_get_link_desc_align(soc->hal_soc);
  1826. uint32_t max_clients = wlan_cfg_get_max_clients(soc->wlan_cfg_ctx);
  1827. uint32_t num_mpdus_per_link_desc =
  1828. hal_num_mpdus_per_link_desc(soc->hal_soc);
  1829. uint32_t num_msdus_per_link_desc =
  1830. hal_num_msdus_per_link_desc(soc->hal_soc);
  1831. uint32_t num_mpdu_links_per_queue_desc =
  1832. hal_num_mpdu_links_per_queue_desc(soc->hal_soc);
  1833. uint32_t max_alloc_size = wlan_cfg_max_alloc_size(soc->wlan_cfg_ctx);
  1834. uint32_t total_link_descs, total_mem_size;
  1835. uint32_t num_mpdu_link_descs, num_mpdu_queue_descs;
  1836. uint32_t num_tx_msdu_link_descs, num_rx_msdu_link_descs;
  1837. uint32_t num_link_desc_banks;
  1838. uint32_t last_bank_size = 0;
  1839. uint32_t entry_size, num_entries;
  1840. int i;
  1841. uint32_t desc_id = 0;
  1842. qdf_dma_addr_t *baseaddr = NULL;
  1843. /* Only Tx queue descriptors are allocated from common link descriptor
  1844. * pool Rx queue descriptors are not included in this because (REO queue
  1845. * extension descriptors) they are expected to be allocated contiguously
  1846. * with REO queue descriptors
  1847. */
  1848. num_mpdu_link_descs = (max_clients * AVG_TIDS_PER_CLIENT *
  1849. AVG_MAX_MPDUS_PER_TID) / num_mpdus_per_link_desc;
  1850. num_mpdu_queue_descs = num_mpdu_link_descs /
  1851. num_mpdu_links_per_queue_desc;
  1852. num_tx_msdu_link_descs = (max_clients * AVG_TIDS_PER_CLIENT *
  1853. AVG_FLOWS_PER_TID * AVG_MSDUS_PER_FLOW) /
  1854. num_msdus_per_link_desc;
  1855. num_rx_msdu_link_descs = (max_clients * AVG_TIDS_PER_CLIENT *
  1856. AVG_MAX_MPDUS_PER_TID * AVG_MSDUS_PER_MPDU) / 6;
  1857. num_entries = num_mpdu_link_descs + num_mpdu_queue_descs +
  1858. num_tx_msdu_link_descs + num_rx_msdu_link_descs;
  1859. /* Round up to power of 2 */
  1860. total_link_descs = 1;
  1861. while (total_link_descs < num_entries)
  1862. total_link_descs <<= 1;
  1863. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  1864. FL("total_link_descs: %u, link_desc_size: %d"),
  1865. total_link_descs, link_desc_size);
  1866. total_mem_size = total_link_descs * link_desc_size;
  1867. total_mem_size += link_desc_align;
  1868. if (total_mem_size <= max_alloc_size) {
  1869. num_link_desc_banks = 0;
  1870. last_bank_size = total_mem_size;
  1871. } else {
  1872. num_link_desc_banks = (total_mem_size) /
  1873. (max_alloc_size - link_desc_align);
  1874. last_bank_size = total_mem_size %
  1875. (max_alloc_size - link_desc_align);
  1876. }
  1877. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  1878. FL("total_mem_size: %d, num_link_desc_banks: %u"),
  1879. total_mem_size, num_link_desc_banks);
  1880. for (i = 0; i < num_link_desc_banks; i++) {
  1881. if (!dp_is_soc_reinit(soc)) {
  1882. baseaddr = &soc->link_desc_banks[i].
  1883. base_paddr_unaligned;
  1884. soc->link_desc_banks[i].base_vaddr_unaligned =
  1885. qdf_mem_alloc_consistent(soc->osdev,
  1886. soc->osdev->dev,
  1887. max_alloc_size,
  1888. baseaddr);
  1889. }
  1890. soc->link_desc_banks[i].size = max_alloc_size;
  1891. soc->link_desc_banks[i].base_vaddr = (void *)((unsigned long)(
  1892. soc->link_desc_banks[i].base_vaddr_unaligned) +
  1893. ((unsigned long)(
  1894. soc->link_desc_banks[i].base_vaddr_unaligned) %
  1895. link_desc_align));
  1896. soc->link_desc_banks[i].base_paddr = (unsigned long)(
  1897. soc->link_desc_banks[i].base_paddr_unaligned) +
  1898. ((unsigned long)(soc->link_desc_banks[i].base_vaddr) -
  1899. (unsigned long)(
  1900. soc->link_desc_banks[i].base_vaddr_unaligned));
  1901. if (!soc->link_desc_banks[i].base_vaddr_unaligned) {
  1902. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1903. FL("Link descriptor memory alloc failed"));
  1904. goto fail;
  1905. }
  1906. if (!dp_is_soc_reinit(soc)) {
  1907. qdf_minidump_log(soc->link_desc_banks[i].base_vaddr,
  1908. soc->link_desc_banks[i].size,
  1909. "link_desc_bank");
  1910. }
  1911. qdf_minidump_log((soc->link_desc_banks[i].base_vaddr),
  1912. soc->link_desc_banks[i].size,
  1913. "link_desc_bank");
  1914. }
  1915. if (last_bank_size) {
  1916. /* Allocate last bank in case total memory required is not exact
  1917. * multiple of max_alloc_size
  1918. */
  1919. if (!dp_is_soc_reinit(soc)) {
  1920. baseaddr = &soc->link_desc_banks[i].
  1921. base_paddr_unaligned;
  1922. soc->link_desc_banks[i].base_vaddr_unaligned =
  1923. qdf_mem_alloc_consistent(soc->osdev,
  1924. soc->osdev->dev,
  1925. last_bank_size,
  1926. baseaddr);
  1927. }
  1928. soc->link_desc_banks[i].size = last_bank_size;
  1929. soc->link_desc_banks[i].base_vaddr = (void *)((unsigned long)
  1930. (soc->link_desc_banks[i].base_vaddr_unaligned) +
  1931. ((unsigned long)(
  1932. soc->link_desc_banks[i].base_vaddr_unaligned) %
  1933. link_desc_align));
  1934. soc->link_desc_banks[i].base_paddr =
  1935. (unsigned long)(
  1936. soc->link_desc_banks[i].base_paddr_unaligned) +
  1937. ((unsigned long)(soc->link_desc_banks[i].base_vaddr) -
  1938. (unsigned long)(
  1939. soc->link_desc_banks[i].base_vaddr_unaligned));
  1940. if (!dp_is_soc_reinit(soc)) {
  1941. qdf_minidump_log(soc->link_desc_banks[i].base_vaddr,
  1942. soc->link_desc_banks[i].size,
  1943. "link_desc_bank");
  1944. }
  1945. qdf_minidump_log((soc->link_desc_banks[i].base_vaddr),
  1946. soc->link_desc_banks[i].size,
  1947. "link_desc_bank");
  1948. }
  1949. /* Allocate and setup link descriptor idle list for HW internal use */
  1950. entry_size = hal_srng_get_entrysize(soc->hal_soc, WBM_IDLE_LINK);
  1951. total_mem_size = entry_size * total_link_descs;
  1952. if (total_mem_size <= max_alloc_size) {
  1953. void *desc;
  1954. if (dp_srng_setup(soc, &soc->wbm_idle_link_ring,
  1955. WBM_IDLE_LINK, 0, 0, total_link_descs, 0)) {
  1956. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1957. FL("Link desc idle ring setup failed"));
  1958. goto fail;
  1959. }
  1960. qdf_minidump_log(soc->wbm_idle_link_ring.base_vaddr_unaligned,
  1961. soc->wbm_idle_link_ring.alloc_size,
  1962. "wbm_idle_link_ring");
  1963. hal_srng_access_start_unlocked(soc->hal_soc,
  1964. soc->wbm_idle_link_ring.hal_srng);
  1965. for (i = 0; i < MAX_LINK_DESC_BANKS &&
  1966. soc->link_desc_banks[i].base_paddr; i++) {
  1967. uint32_t num_entries = (soc->link_desc_banks[i].size -
  1968. ((unsigned long)(
  1969. soc->link_desc_banks[i].base_vaddr) -
  1970. (unsigned long)(
  1971. soc->link_desc_banks[i].base_vaddr_unaligned)))
  1972. / link_desc_size;
  1973. unsigned long paddr = (unsigned long)(
  1974. soc->link_desc_banks[i].base_paddr);
  1975. while (num_entries && (desc = hal_srng_src_get_next(
  1976. soc->hal_soc,
  1977. soc->wbm_idle_link_ring.hal_srng))) {
  1978. hal_set_link_desc_addr(desc,
  1979. LINK_DESC_COOKIE(desc_id, i), paddr);
  1980. num_entries--;
  1981. desc_id++;
  1982. paddr += link_desc_size;
  1983. }
  1984. }
  1985. hal_srng_access_end_unlocked(soc->hal_soc,
  1986. soc->wbm_idle_link_ring.hal_srng);
  1987. } else {
  1988. uint32_t num_scatter_bufs;
  1989. uint32_t num_entries_per_buf;
  1990. uint32_t rem_entries;
  1991. uint8_t *scatter_buf_ptr;
  1992. uint16_t scatter_buf_num;
  1993. uint32_t buf_size = 0;
  1994. soc->wbm_idle_scatter_buf_size =
  1995. hal_idle_list_scatter_buf_size(soc->hal_soc);
  1996. num_entries_per_buf = hal_idle_scatter_buf_num_entries(
  1997. soc->hal_soc, soc->wbm_idle_scatter_buf_size);
  1998. num_scatter_bufs = hal_idle_list_num_scatter_bufs(
  1999. soc->hal_soc, total_mem_size,
  2000. soc->wbm_idle_scatter_buf_size);
  2001. if (num_scatter_bufs > MAX_IDLE_SCATTER_BUFS) {
  2002. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2003. FL("scatter bufs size out of bounds"));
  2004. goto fail;
  2005. }
  2006. for (i = 0; i < num_scatter_bufs; i++) {
  2007. baseaddr = &soc->wbm_idle_scatter_buf_base_paddr[i];
  2008. if (!dp_is_soc_reinit(soc)) {
  2009. buf_size = soc->wbm_idle_scatter_buf_size;
  2010. soc->wbm_idle_scatter_buf_base_vaddr[i] =
  2011. qdf_mem_alloc_consistent(soc->osdev,
  2012. soc->osdev->
  2013. dev,
  2014. buf_size,
  2015. baseaddr);
  2016. }
  2017. if (!soc->wbm_idle_scatter_buf_base_vaddr[i]) {
  2018. QDF_TRACE(QDF_MODULE_ID_DP,
  2019. QDF_TRACE_LEVEL_ERROR,
  2020. FL("Scatter lst memory alloc fail"));
  2021. goto fail;
  2022. }
  2023. }
  2024. /* Populate idle list scatter buffers with link descriptor
  2025. * pointers
  2026. */
  2027. scatter_buf_num = 0;
  2028. scatter_buf_ptr = (uint8_t *)(
  2029. soc->wbm_idle_scatter_buf_base_vaddr[scatter_buf_num]);
  2030. rem_entries = num_entries_per_buf;
  2031. for (i = 0; i < MAX_LINK_DESC_BANKS &&
  2032. soc->link_desc_banks[i].base_paddr; i++) {
  2033. uint32_t num_link_descs =
  2034. (soc->link_desc_banks[i].size -
  2035. ((unsigned long)(
  2036. soc->link_desc_banks[i].base_vaddr) -
  2037. (unsigned long)(
  2038. soc->link_desc_banks[i].base_vaddr_unaligned)))
  2039. / link_desc_size;
  2040. unsigned long paddr = (unsigned long)(
  2041. soc->link_desc_banks[i].base_paddr);
  2042. while (num_link_descs) {
  2043. hal_set_link_desc_addr((void *)scatter_buf_ptr,
  2044. LINK_DESC_COOKIE(desc_id, i), paddr);
  2045. num_link_descs--;
  2046. desc_id++;
  2047. paddr += link_desc_size;
  2048. rem_entries--;
  2049. if (rem_entries) {
  2050. scatter_buf_ptr += entry_size;
  2051. } else {
  2052. rem_entries = num_entries_per_buf;
  2053. scatter_buf_num++;
  2054. if (scatter_buf_num >= num_scatter_bufs)
  2055. break;
  2056. scatter_buf_ptr = (uint8_t *)(
  2057. soc->wbm_idle_scatter_buf_base_vaddr[
  2058. scatter_buf_num]);
  2059. }
  2060. }
  2061. }
  2062. /* Setup link descriptor idle list in HW */
  2063. hal_setup_link_idle_list(soc->hal_soc,
  2064. soc->wbm_idle_scatter_buf_base_paddr,
  2065. soc->wbm_idle_scatter_buf_base_vaddr,
  2066. num_scatter_bufs, soc->wbm_idle_scatter_buf_size,
  2067. (uint32_t)(scatter_buf_ptr -
  2068. (uint8_t *)(soc->wbm_idle_scatter_buf_base_vaddr[
  2069. scatter_buf_num-1])), total_link_descs);
  2070. }
  2071. return 0;
  2072. fail:
  2073. if (soc->wbm_idle_link_ring.hal_srng) {
  2074. dp_srng_cleanup(soc, &soc->wbm_idle_link_ring,
  2075. WBM_IDLE_LINK, 0);
  2076. }
  2077. for (i = 0; i < MAX_IDLE_SCATTER_BUFS; i++) {
  2078. if (soc->wbm_idle_scatter_buf_base_vaddr[i]) {
  2079. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  2080. soc->wbm_idle_scatter_buf_size,
  2081. soc->wbm_idle_scatter_buf_base_vaddr[i],
  2082. soc->wbm_idle_scatter_buf_base_paddr[i], 0);
  2083. soc->wbm_idle_scatter_buf_base_vaddr[i] = NULL;
  2084. }
  2085. }
  2086. for (i = 0; i < MAX_LINK_DESC_BANKS; i++) {
  2087. if (soc->link_desc_banks[i].base_vaddr_unaligned) {
  2088. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  2089. soc->link_desc_banks[i].size,
  2090. soc->link_desc_banks[i].base_vaddr_unaligned,
  2091. soc->link_desc_banks[i].base_paddr_unaligned,
  2092. 0);
  2093. soc->link_desc_banks[i].base_vaddr_unaligned = NULL;
  2094. }
  2095. }
  2096. return QDF_STATUS_E_FAILURE;
  2097. }
  2098. /*
  2099. * Free link descriptor pool that was setup HW
  2100. */
  2101. static void dp_hw_link_desc_pool_cleanup(struct dp_soc *soc)
  2102. {
  2103. int i;
  2104. if (soc->wbm_idle_link_ring.hal_srng) {
  2105. qdf_minidump_remove(
  2106. soc->wbm_idle_link_ring.base_vaddr_unaligned);
  2107. dp_srng_cleanup(soc, &soc->wbm_idle_link_ring,
  2108. WBM_IDLE_LINK, 0);
  2109. }
  2110. for (i = 0; i < MAX_IDLE_SCATTER_BUFS; i++) {
  2111. if (soc->wbm_idle_scatter_buf_base_vaddr[i]) {
  2112. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  2113. soc->wbm_idle_scatter_buf_size,
  2114. soc->wbm_idle_scatter_buf_base_vaddr[i],
  2115. soc->wbm_idle_scatter_buf_base_paddr[i], 0);
  2116. soc->wbm_idle_scatter_buf_base_vaddr[i] = NULL;
  2117. }
  2118. }
  2119. for (i = 0; i < MAX_LINK_DESC_BANKS; i++) {
  2120. if (soc->link_desc_banks[i].base_vaddr_unaligned) {
  2121. qdf_minidump_remove(soc->link_desc_banks[i].base_vaddr);
  2122. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  2123. soc->link_desc_banks[i].size,
  2124. soc->link_desc_banks[i].base_vaddr_unaligned,
  2125. soc->link_desc_banks[i].base_paddr_unaligned,
  2126. 0);
  2127. soc->link_desc_banks[i].base_vaddr_unaligned = NULL;
  2128. }
  2129. }
  2130. }
  2131. #ifdef IPA_OFFLOAD
  2132. #define REO_DST_RING_SIZE_QCA6290 1023
  2133. #ifndef QCA_WIFI_QCA8074_VP
  2134. #define REO_DST_RING_SIZE_QCA8074 1023
  2135. #define REO_DST_RING_SIZE_QCN9000 2048
  2136. #else
  2137. #define REO_DST_RING_SIZE_QCA8074 8
  2138. #define REO_DST_RING_SIZE_QCN9000 8
  2139. #endif /* QCA_WIFI_QCA8074_VP */
  2140. #else
  2141. #define REO_DST_RING_SIZE_QCA6290 1024
  2142. #ifndef QCA_WIFI_QCA8074_VP
  2143. #define REO_DST_RING_SIZE_QCA8074 2048
  2144. #define REO_DST_RING_SIZE_QCN9000 2048
  2145. #else
  2146. #define REO_DST_RING_SIZE_QCA8074 8
  2147. #define REO_DST_RING_SIZE_QCN9000 8
  2148. #endif /* QCA_WIFI_QCA8074_VP */
  2149. #endif /* IPA_OFFLOAD */
  2150. #ifndef FEATURE_WDS
  2151. static void dp_soc_wds_attach(struct dp_soc *soc)
  2152. {
  2153. }
  2154. static void dp_soc_wds_detach(struct dp_soc *soc)
  2155. {
  2156. }
  2157. #endif
  2158. /*
  2159. * dp_soc_reset_ring_map() - Reset cpu ring map
  2160. * @soc: Datapath soc handler
  2161. *
  2162. * This api resets the default cpu ring map
  2163. */
  2164. static void dp_soc_reset_cpu_ring_map(struct dp_soc *soc)
  2165. {
  2166. uint8_t i;
  2167. int nss_config = wlan_cfg_get_dp_soc_nss_cfg(soc->wlan_cfg_ctx);
  2168. for (i = 0; i < WLAN_CFG_INT_NUM_CONTEXTS; i++) {
  2169. switch (nss_config) {
  2170. case dp_nss_cfg_first_radio:
  2171. /*
  2172. * Setting Tx ring map for one nss offloaded radio
  2173. */
  2174. soc->tx_ring_map[i] = dp_cpu_ring_map[DP_NSS_FIRST_RADIO_OFFLOADED_MAP][i];
  2175. break;
  2176. case dp_nss_cfg_second_radio:
  2177. /*
  2178. * Setting Tx ring for two nss offloaded radios
  2179. */
  2180. soc->tx_ring_map[i] = dp_cpu_ring_map[DP_NSS_SECOND_RADIO_OFFLOADED_MAP][i];
  2181. break;
  2182. case dp_nss_cfg_dbdc:
  2183. /*
  2184. * Setting Tx ring map for 2 nss offloaded radios
  2185. */
  2186. soc->tx_ring_map[i] =
  2187. dp_cpu_ring_map[DP_NSS_DBDC_OFFLOADED_MAP][i];
  2188. break;
  2189. case dp_nss_cfg_dbtc:
  2190. /*
  2191. * Setting Tx ring map for 3 nss offloaded radios
  2192. */
  2193. soc->tx_ring_map[i] =
  2194. dp_cpu_ring_map[DP_NSS_DBTC_OFFLOADED_MAP][i];
  2195. break;
  2196. default:
  2197. dp_err("tx_ring_map failed due to invalid nss cfg");
  2198. break;
  2199. }
  2200. }
  2201. }
  2202. /*
  2203. * dp_soc_ring_if_nss_offloaded() - find if ring is offloaded to NSS
  2204. * @dp_soc - DP soc handle
  2205. * @ring_type - ring type
  2206. * @ring_num - ring_num
  2207. *
  2208. * return 0 or 1
  2209. */
  2210. static uint8_t dp_soc_ring_if_nss_offloaded(struct dp_soc *soc, enum hal_ring_type ring_type, int ring_num)
  2211. {
  2212. uint8_t nss_config = wlan_cfg_get_dp_soc_nss_cfg(soc->wlan_cfg_ctx);
  2213. uint8_t status = 0;
  2214. switch (ring_type) {
  2215. case WBM2SW_RELEASE:
  2216. case REO_DST:
  2217. case RXDMA_BUF:
  2218. status = ((nss_config) & (1 << ring_num));
  2219. break;
  2220. default:
  2221. break;
  2222. }
  2223. return status;
  2224. }
  2225. /*
  2226. * dp_soc_disable_mac2_intr_mask() - reset interrupt mask for WMAC2 hw rings
  2227. * @dp_soc - DP Soc handle
  2228. *
  2229. * Return: Return void
  2230. */
  2231. static void dp_soc_disable_mac2_intr_mask(struct dp_soc *soc)
  2232. {
  2233. int *grp_mask = NULL;
  2234. int group_number;
  2235. grp_mask = &soc->wlan_cfg_ctx->int_host2rxdma_ring_mask[0];
  2236. group_number = dp_srng_find_ring_in_mask(0x2, grp_mask);
  2237. wlan_cfg_set_host2rxdma_ring_mask(soc->wlan_cfg_ctx,
  2238. group_number, 0x0);
  2239. grp_mask = &soc->wlan_cfg_ctx->int_rx_mon_ring_mask[0];
  2240. group_number = dp_srng_find_ring_in_mask(0x2, grp_mask);
  2241. wlan_cfg_set_rx_mon_ring_mask(soc->wlan_cfg_ctx,
  2242. group_number, 0x0);
  2243. grp_mask = &soc->wlan_cfg_ctx->int_rxdma2host_ring_mask[0];
  2244. group_number = dp_srng_find_ring_in_mask(0x2, grp_mask);
  2245. wlan_cfg_set_rxdma2host_ring_mask(soc->wlan_cfg_ctx,
  2246. group_number, 0x0);
  2247. grp_mask = &soc->wlan_cfg_ctx->int_host2rxdma_mon_ring_mask[0];
  2248. group_number = dp_srng_find_ring_in_mask(0x2, grp_mask);
  2249. wlan_cfg_set_host2rxdma_mon_ring_mask(soc->wlan_cfg_ctx,
  2250. group_number, 0x0);
  2251. }
  2252. /*
  2253. * dp_soc_reset_intr_mask() - reset interrupt mask
  2254. * @dp_soc - DP Soc handle
  2255. *
  2256. * Return: Return void
  2257. */
  2258. static void dp_soc_reset_intr_mask(struct dp_soc *soc)
  2259. {
  2260. uint8_t j;
  2261. int *grp_mask = NULL;
  2262. int group_number, mask, num_ring;
  2263. /* number of tx ring */
  2264. num_ring = wlan_cfg_num_tcl_data_rings(soc->wlan_cfg_ctx);
  2265. /*
  2266. * group mask for tx completion ring.
  2267. */
  2268. grp_mask = &soc->wlan_cfg_ctx->int_tx_ring_mask[0];
  2269. /* loop and reset the mask for only offloaded ring */
  2270. for (j = 0; j < num_ring; j++) {
  2271. if (!dp_soc_ring_if_nss_offloaded(soc, WBM2SW_RELEASE, j)) {
  2272. continue;
  2273. }
  2274. /*
  2275. * Group number corresponding to tx offloaded ring.
  2276. */
  2277. group_number = dp_srng_find_ring_in_mask(j, grp_mask);
  2278. if (group_number < 0) {
  2279. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2280. FL("ring not part of any group; ring_type: %d,ring_num %d"),
  2281. WBM2SW_RELEASE, j);
  2282. return;
  2283. }
  2284. /* reset the tx mask for offloaded ring */
  2285. mask = wlan_cfg_get_tx_ring_mask(soc->wlan_cfg_ctx, group_number);
  2286. mask &= (~(1 << j));
  2287. /*
  2288. * reset the interrupt mask for offloaded ring.
  2289. */
  2290. wlan_cfg_set_tx_ring_mask(soc->wlan_cfg_ctx, group_number, mask);
  2291. }
  2292. /* number of rx rings */
  2293. num_ring = wlan_cfg_num_reo_dest_rings(soc->wlan_cfg_ctx);
  2294. /*
  2295. * group mask for reo destination ring.
  2296. */
  2297. grp_mask = &soc->wlan_cfg_ctx->int_rx_ring_mask[0];
  2298. /* loop and reset the mask for only offloaded ring */
  2299. for (j = 0; j < num_ring; j++) {
  2300. if (!dp_soc_ring_if_nss_offloaded(soc, REO_DST, j)) {
  2301. continue;
  2302. }
  2303. /*
  2304. * Group number corresponding to rx offloaded ring.
  2305. */
  2306. group_number = dp_srng_find_ring_in_mask(j, grp_mask);
  2307. if (group_number < 0) {
  2308. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2309. FL("ring not part of any group; ring_type: %d,ring_num %d"),
  2310. REO_DST, j);
  2311. return;
  2312. }
  2313. /* set the interrupt mask for offloaded ring */
  2314. mask = wlan_cfg_get_rx_ring_mask(soc->wlan_cfg_ctx, group_number);
  2315. mask &= (~(1 << j));
  2316. /*
  2317. * set the interrupt mask to zero for rx offloaded radio.
  2318. */
  2319. wlan_cfg_set_rx_ring_mask(soc->wlan_cfg_ctx, group_number, mask);
  2320. }
  2321. /*
  2322. * group mask for Rx buffer refill ring
  2323. */
  2324. grp_mask = &soc->wlan_cfg_ctx->int_host2rxdma_ring_mask[0];
  2325. /* loop and reset the mask for only offloaded ring */
  2326. for (j = 0; j < MAX_PDEV_CNT; j++) {
  2327. int lmac_id = wlan_cfg_get_hw_mac_idx(soc->wlan_cfg_ctx, j);
  2328. if (!dp_soc_ring_if_nss_offloaded(soc, RXDMA_BUF, j)) {
  2329. continue;
  2330. }
  2331. /*
  2332. * Group number corresponding to rx offloaded ring.
  2333. */
  2334. group_number = dp_srng_find_ring_in_mask(lmac_id, grp_mask);
  2335. if (group_number < 0) {
  2336. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2337. FL("ring not part of any group; ring_type: %d,ring_num %d"),
  2338. REO_DST, lmac_id);
  2339. return;
  2340. }
  2341. /* set the interrupt mask for offloaded ring */
  2342. mask = wlan_cfg_get_host2rxdma_ring_mask(soc->wlan_cfg_ctx,
  2343. group_number);
  2344. mask &= (~(1 << lmac_id));
  2345. /*
  2346. * set the interrupt mask to zero for rx offloaded radio.
  2347. */
  2348. wlan_cfg_set_host2rxdma_ring_mask(soc->wlan_cfg_ctx,
  2349. group_number, mask);
  2350. }
  2351. }
  2352. #ifdef IPA_OFFLOAD
  2353. /**
  2354. * dp_reo_remap_config() - configure reo remap register value based
  2355. * nss configuration.
  2356. * based on offload_radio value below remap configuration
  2357. * get applied.
  2358. * 0 - both Radios handled by host (remap rings 1, 2, 3 & 4)
  2359. * 1 - 1st Radio handled by NSS (remap rings 2, 3 & 4)
  2360. * 2 - 2nd Radio handled by NSS (remap rings 1, 2 & 4)
  2361. * 3 - both Radios handled by NSS (remap not required)
  2362. * 4 - IPA OFFLOAD enabled (remap rings 1,2 & 3)
  2363. *
  2364. * @remap1: output parameter indicates reo remap 1 register value
  2365. * @remap2: output parameter indicates reo remap 2 register value
  2366. * Return: bool type, true if remap is configured else false.
  2367. */
  2368. bool dp_reo_remap_config(struct dp_soc *soc, uint32_t *remap1, uint32_t *remap2)
  2369. {
  2370. *remap1 = HAL_REO_REMAP_IX2(REO_REMAP_SW1, 16) |
  2371. HAL_REO_REMAP_IX2(REO_REMAP_SW2, 17) |
  2372. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 18) |
  2373. HAL_REO_REMAP_IX2(REO_REMAP_SW1, 19) |
  2374. HAL_REO_REMAP_IX2(REO_REMAP_SW2, 20) |
  2375. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 21) |
  2376. HAL_REO_REMAP_IX2(REO_REMAP_SW1, 22) |
  2377. HAL_REO_REMAP_IX2(REO_REMAP_SW2, 23);
  2378. *remap2 = HAL_REO_REMAP_IX3(REO_REMAP_SW3, 24) |
  2379. HAL_REO_REMAP_IX3(REO_REMAP_SW1, 25) |
  2380. HAL_REO_REMAP_IX3(REO_REMAP_SW2, 26) |
  2381. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 27) |
  2382. HAL_REO_REMAP_IX3(REO_REMAP_SW1, 28) |
  2383. HAL_REO_REMAP_IX3(REO_REMAP_SW2, 29) |
  2384. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 30) |
  2385. HAL_REO_REMAP_IX3(REO_REMAP_SW1, 31);
  2386. dp_debug("remap1 %x remap2 %x", *remap1, *remap2);
  2387. return true;
  2388. }
  2389. #else
  2390. static bool dp_reo_remap_config(struct dp_soc *soc,
  2391. uint32_t *remap1,
  2392. uint32_t *remap2)
  2393. {
  2394. uint8_t offload_radio = wlan_cfg_get_dp_soc_nss_cfg(soc->wlan_cfg_ctx);
  2395. uint8_t target_type;
  2396. target_type = hal_get_target_type(soc->hal_soc);
  2397. switch (offload_radio) {
  2398. case dp_nss_cfg_default:
  2399. *remap1 = HAL_REO_REMAP_IX2(REO_REMAP_SW1, 16) |
  2400. HAL_REO_REMAP_IX2(REO_REMAP_SW2, 17) |
  2401. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 18) |
  2402. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 19) |
  2403. HAL_REO_REMAP_IX2(REO_REMAP_SW1, 20) |
  2404. HAL_REO_REMAP_IX2(REO_REMAP_SW2, 21) |
  2405. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 22) |
  2406. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 23);
  2407. *remap2 = HAL_REO_REMAP_IX3(REO_REMAP_SW1, 24) |
  2408. HAL_REO_REMAP_IX3(REO_REMAP_SW2, 25) |
  2409. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 26) |
  2410. HAL_REO_REMAP_IX3(REO_REMAP_SW4, 27) |
  2411. HAL_REO_REMAP_IX3(REO_REMAP_SW1, 28) |
  2412. HAL_REO_REMAP_IX3(REO_REMAP_SW2, 29) |
  2413. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 30) |
  2414. HAL_REO_REMAP_IX3(REO_REMAP_SW4, 31);
  2415. break;
  2416. case dp_nss_cfg_first_radio:
  2417. *remap1 = HAL_REO_REMAP_IX2(REO_REMAP_SW2, 16) |
  2418. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 17) |
  2419. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 18) |
  2420. HAL_REO_REMAP_IX2(REO_REMAP_SW2, 19) |
  2421. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 20) |
  2422. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 21) |
  2423. HAL_REO_REMAP_IX2(REO_REMAP_SW2, 22) |
  2424. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 23);
  2425. *remap2 = HAL_REO_REMAP_IX3(REO_REMAP_SW4, 24) |
  2426. HAL_REO_REMAP_IX3(REO_REMAP_SW2, 25) |
  2427. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 26) |
  2428. HAL_REO_REMAP_IX3(REO_REMAP_SW4, 27) |
  2429. HAL_REO_REMAP_IX3(REO_REMAP_SW2, 28) |
  2430. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 29) |
  2431. HAL_REO_REMAP_IX3(REO_REMAP_SW4, 30) |
  2432. HAL_REO_REMAP_IX3(REO_REMAP_SW2, 31);
  2433. break;
  2434. case dp_nss_cfg_second_radio:
  2435. *remap1 = HAL_REO_REMAP_IX2(REO_REMAP_SW1, 16) |
  2436. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 17) |
  2437. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 18) |
  2438. HAL_REO_REMAP_IX2(REO_REMAP_SW1, 19) |
  2439. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 20) |
  2440. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 21) |
  2441. HAL_REO_REMAP_IX2(REO_REMAP_SW1, 22) |
  2442. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 23);
  2443. *remap2 = HAL_REO_REMAP_IX3(REO_REMAP_SW4, 24) |
  2444. HAL_REO_REMAP_IX3(REO_REMAP_SW1, 25) |
  2445. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 26) |
  2446. HAL_REO_REMAP_IX3(REO_REMAP_SW4, 27) |
  2447. HAL_REO_REMAP_IX3(REO_REMAP_SW1, 28) |
  2448. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 29) |
  2449. HAL_REO_REMAP_IX3(REO_REMAP_SW4, 30) |
  2450. HAL_REO_REMAP_IX3(REO_REMAP_SW1, 31);
  2451. break;
  2452. case dp_nss_cfg_dbdc:
  2453. case dp_nss_cfg_dbtc:
  2454. /* return false if both or all are offloaded to NSS */
  2455. return false;
  2456. }
  2457. dp_debug("remap1 %x remap2 %x offload_radio %u",
  2458. *remap1, *remap2, offload_radio);
  2459. return true;
  2460. }
  2461. #endif /* IPA_OFFLOAD */
  2462. /*
  2463. * dp_reo_frag_dst_set() - configure reo register to set the
  2464. * fragment destination ring
  2465. * @soc : Datapath soc
  2466. * @frag_dst_ring : output parameter to set fragment destination ring
  2467. *
  2468. * Based on offload_radio below fragment destination rings is selected
  2469. * 0 - TCL
  2470. * 1 - SW1
  2471. * 2 - SW2
  2472. * 3 - SW3
  2473. * 4 - SW4
  2474. * 5 - Release
  2475. * 6 - FW
  2476. * 7 - alternate select
  2477. *
  2478. * return: void
  2479. */
  2480. static void dp_reo_frag_dst_set(struct dp_soc *soc, uint8_t *frag_dst_ring)
  2481. {
  2482. uint8_t offload_radio = wlan_cfg_get_dp_soc_nss_cfg(soc->wlan_cfg_ctx);
  2483. switch (offload_radio) {
  2484. case dp_nss_cfg_default:
  2485. *frag_dst_ring = HAL_SRNG_REO_EXCEPTION;
  2486. break;
  2487. case dp_nss_cfg_first_radio:
  2488. /*
  2489. * This configuration is valid for single band radio which
  2490. * is also NSS offload.
  2491. */
  2492. case dp_nss_cfg_dbdc:
  2493. case dp_nss_cfg_dbtc:
  2494. *frag_dst_ring = HAL_SRNG_REO_ALTERNATE_SELECT;
  2495. break;
  2496. default:
  2497. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2498. FL("dp_reo_frag_dst_set invalid offload radio config"));
  2499. break;
  2500. }
  2501. }
  2502. #ifdef ENABLE_VERBOSE_DEBUG
  2503. static void dp_enable_verbose_debug(struct dp_soc *soc)
  2504. {
  2505. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx;
  2506. soc_cfg_ctx = soc->wlan_cfg_ctx;
  2507. if (soc_cfg_ctx->per_pkt_trace & dp_verbose_debug_mask)
  2508. is_dp_verbose_debug_enabled = true;
  2509. if (soc_cfg_ctx->per_pkt_trace & hal_verbose_debug_mask)
  2510. hal_set_verbose_debug(true);
  2511. else
  2512. hal_set_verbose_debug(false);
  2513. }
  2514. #else
  2515. static void dp_enable_verbose_debug(struct dp_soc *soc)
  2516. {
  2517. }
  2518. #endif
  2519. #ifdef WLAN_FEATURE_STATS_EXT
  2520. static inline void dp_create_ext_stats_event(struct dp_soc *soc)
  2521. {
  2522. qdf_event_create(&soc->rx_hw_stats_event);
  2523. }
  2524. #else
  2525. static inline void dp_create_ext_stats_event(struct dp_soc *soc)
  2526. {
  2527. }
  2528. #endif
  2529. /*
  2530. * dp_soc_cmn_setup() - Common SoC level initializion
  2531. * @soc: Datapath SOC handle
  2532. *
  2533. * This is an internal function used to setup common SOC data structures,
  2534. * to be called from PDEV attach after receiving HW mode capabilities from FW
  2535. */
  2536. static int dp_soc_cmn_setup(struct dp_soc *soc)
  2537. {
  2538. int i, cached;
  2539. struct hal_reo_params reo_params;
  2540. int tx_ring_size;
  2541. int tx_comp_ring_size;
  2542. int reo_dst_ring_size;
  2543. uint32_t entries;
  2544. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx;
  2545. if (qdf_atomic_read(&soc->cmn_init_done))
  2546. return 0;
  2547. if (dp_hw_link_desc_pool_setup(soc))
  2548. goto fail1;
  2549. soc_cfg_ctx = soc->wlan_cfg_ctx;
  2550. dp_enable_verbose_debug(soc);
  2551. /* Setup SRNG rings */
  2552. /* Common rings */
  2553. entries = wlan_cfg_get_dp_soc_wbm_release_ring_size(soc_cfg_ctx);
  2554. if (dp_srng_setup(soc, &soc->wbm_desc_rel_ring, SW2WBM_RELEASE, 0, 0,
  2555. entries, 0)) {
  2556. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2557. FL("dp_srng_setup failed for wbm_desc_rel_ring"));
  2558. goto fail1;
  2559. }
  2560. qdf_minidump_log(soc->wbm_desc_rel_ring.base_vaddr_unaligned,
  2561. soc->wbm_desc_rel_ring.alloc_size,
  2562. "wbm_desc_rel_ring");
  2563. soc->num_tcl_data_rings = 0;
  2564. /* Tx data rings */
  2565. if (!wlan_cfg_per_pdev_tx_ring(soc_cfg_ctx)) {
  2566. soc->num_tcl_data_rings =
  2567. wlan_cfg_num_tcl_data_rings(soc_cfg_ctx);
  2568. tx_comp_ring_size =
  2569. wlan_cfg_tx_comp_ring_size(soc_cfg_ctx);
  2570. tx_ring_size =
  2571. wlan_cfg_tx_ring_size(soc_cfg_ctx);
  2572. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  2573. if (dp_srng_setup(soc, &soc->tcl_data_ring[i],
  2574. TCL_DATA, i, 0, tx_ring_size, 0)) {
  2575. QDF_TRACE(QDF_MODULE_ID_DP,
  2576. QDF_TRACE_LEVEL_ERROR,
  2577. FL("dp_srng_setup failed for tcl_data_ring[%d]"), i);
  2578. goto fail1;
  2579. }
  2580. /* Disable cached desc if NSS offload is enabled */
  2581. cached = WLAN_CFG_DST_RING_CACHED_DESC;
  2582. if (wlan_cfg_get_dp_soc_nss_cfg(soc_cfg_ctx))
  2583. cached = 0;
  2584. /*
  2585. * TBD: Set IPA WBM ring size with ini IPA UC tx buffer
  2586. * count
  2587. */
  2588. if (dp_srng_setup(soc, &soc->tx_comp_ring[i],
  2589. WBM2SW_RELEASE, i, 0,
  2590. tx_comp_ring_size,
  2591. cached)) {
  2592. QDF_TRACE(QDF_MODULE_ID_DP,
  2593. QDF_TRACE_LEVEL_ERROR,
  2594. FL("dp_srng_setup failed for tx_comp_ring[%d]"), i);
  2595. goto fail1;
  2596. }
  2597. }
  2598. } else {
  2599. /* This will be incremented during per pdev ring setup */
  2600. soc->num_tcl_data_rings = 0;
  2601. }
  2602. if (dp_tx_soc_attach(soc)) {
  2603. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2604. FL("dp_tx_soc_attach failed"));
  2605. goto fail1;
  2606. }
  2607. entries = wlan_cfg_get_dp_soc_tcl_cmd_ring_size(soc_cfg_ctx);
  2608. /* TCL command and status rings */
  2609. if (dp_srng_setup(soc, &soc->tcl_cmd_ring, TCL_CMD, 0, 0,
  2610. entries, 0)) {
  2611. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2612. FL("dp_srng_setup failed for tcl_cmd_ring"));
  2613. goto fail2;
  2614. }
  2615. entries = wlan_cfg_get_dp_soc_tcl_status_ring_size(soc_cfg_ctx);
  2616. if (dp_srng_setup(soc, &soc->tcl_status_ring, TCL_STATUS, 0, 0,
  2617. entries, 0)) {
  2618. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2619. FL("dp_srng_setup failed for tcl_status_ring"));
  2620. goto fail2;
  2621. }
  2622. reo_dst_ring_size = wlan_cfg_get_reo_dst_ring_size(soc->wlan_cfg_ctx);
  2623. /* TBD: call dp_tx_init to setup Tx SW descriptors and MSDU extension
  2624. * descriptors
  2625. */
  2626. /* Rx data rings */
  2627. if (!wlan_cfg_per_pdev_rx_ring(soc_cfg_ctx)) {
  2628. soc->num_reo_dest_rings =
  2629. wlan_cfg_num_reo_dest_rings(soc_cfg_ctx);
  2630. QDF_TRACE(QDF_MODULE_ID_DP,
  2631. QDF_TRACE_LEVEL_INFO,
  2632. FL("num_reo_dest_rings %d"), soc->num_reo_dest_rings);
  2633. /* Disable cached desc if NSS offload is enabled */
  2634. cached = WLAN_CFG_DST_RING_CACHED_DESC;
  2635. if (wlan_cfg_get_dp_soc_nss_cfg(soc_cfg_ctx))
  2636. cached = 0;
  2637. for (i = 0; i < soc->num_reo_dest_rings; i++) {
  2638. if (dp_srng_setup(soc, &soc->reo_dest_ring[i], REO_DST,
  2639. i, 0, reo_dst_ring_size, cached)) {
  2640. QDF_TRACE(QDF_MODULE_ID_DP,
  2641. QDF_TRACE_LEVEL_ERROR,
  2642. FL(RNG_ERR "reo_dest_ring [%d]"), i);
  2643. goto fail2;
  2644. }
  2645. }
  2646. } else {
  2647. /* This will be incremented during per pdev ring setup */
  2648. soc->num_reo_dest_rings = 0;
  2649. }
  2650. entries = wlan_cfg_get_dp_soc_rxdma_err_dst_ring_size(soc_cfg_ctx);
  2651. /* LMAC RxDMA to SW Rings configuration */
  2652. if (!wlan_cfg_per_pdev_lmac_ring(soc_cfg_ctx)) {
  2653. for (i = 0; i < MAX_RX_MAC_RINGS; i++) {
  2654. if (dp_srng_setup(soc, &soc->rxdma_err_dst_ring[i],
  2655. RXDMA_DST, 0, i, entries, 0)) {
  2656. QDF_TRACE(QDF_MODULE_ID_DP,
  2657. QDF_TRACE_LEVEL_ERROR,
  2658. FL(RNG_ERR "rxdma_err_dst_ring"));
  2659. goto fail2;
  2660. }
  2661. }
  2662. }
  2663. /* TBD: call dp_rx_init to setup Rx SW descriptors */
  2664. /* REO reinjection ring */
  2665. entries = wlan_cfg_get_dp_soc_reo_reinject_ring_size(soc_cfg_ctx);
  2666. if (dp_srng_setup(soc, &soc->reo_reinject_ring, REO_REINJECT, 0, 0,
  2667. entries, 0)) {
  2668. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2669. FL("dp_srng_setup failed for reo_reinject_ring"));
  2670. goto fail2;
  2671. }
  2672. /* Rx release ring */
  2673. if (dp_srng_setup(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 3, 0,
  2674. wlan_cfg_get_dp_soc_rx_release_ring_size(soc_cfg_ctx),
  2675. 0)) {
  2676. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2677. FL("dp_srng_setup failed for rx_rel_ring"));
  2678. goto fail2;
  2679. }
  2680. /* Rx exception ring */
  2681. entries = wlan_cfg_get_dp_soc_reo_exception_ring_size(soc_cfg_ctx);
  2682. if (dp_srng_setup(soc, &soc->reo_exception_ring,
  2683. REO_EXCEPTION, 0, MAX_REO_DEST_RINGS, entries, 0)) {
  2684. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2685. FL("dp_srng_setup failed for reo_exception_ring"));
  2686. goto fail2;
  2687. }
  2688. /* REO command and status rings */
  2689. if (dp_srng_setup(soc, &soc->reo_cmd_ring, REO_CMD, 0, 0,
  2690. wlan_cfg_get_dp_soc_reo_cmd_ring_size(soc_cfg_ctx),
  2691. 0)) {
  2692. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2693. FL("dp_srng_setup failed for reo_cmd_ring"));
  2694. goto fail2;
  2695. }
  2696. hal_reo_init_cmd_ring(soc->hal_soc, soc->reo_cmd_ring.hal_srng);
  2697. TAILQ_INIT(&soc->rx.reo_cmd_list);
  2698. qdf_spinlock_create(&soc->rx.reo_cmd_lock);
  2699. if (dp_srng_setup(soc, &soc->reo_status_ring, REO_STATUS, 0, 0,
  2700. wlan_cfg_get_dp_soc_reo_status_ring_size(soc_cfg_ctx),
  2701. 0)) {
  2702. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2703. FL("dp_srng_setup failed for reo_status_ring"));
  2704. goto fail2;
  2705. }
  2706. /*
  2707. * Skip registering hw ring interrupts for WMAC2 on IPQ6018
  2708. * WMAC2 is not there in IPQ6018 platform.
  2709. */
  2710. if (hal_get_target_type(soc->hal_soc) == TARGET_TYPE_QCA6018) {
  2711. dp_soc_disable_mac2_intr_mask(soc);
  2712. }
  2713. /* Reset the cpu ring map if radio is NSS offloaded */
  2714. if (wlan_cfg_get_dp_soc_nss_cfg(soc_cfg_ctx)) {
  2715. dp_soc_reset_cpu_ring_map(soc);
  2716. dp_soc_reset_intr_mask(soc);
  2717. }
  2718. /* Setup HW REO */
  2719. qdf_mem_zero(&reo_params, sizeof(reo_params));
  2720. if (wlan_cfg_is_rx_hash_enabled(soc_cfg_ctx)) {
  2721. /*
  2722. * Reo ring remap is not required if both radios
  2723. * are offloaded to NSS
  2724. */
  2725. if (!dp_reo_remap_config(soc,
  2726. &reo_params.remap1,
  2727. &reo_params.remap2))
  2728. goto out;
  2729. reo_params.rx_hash_enabled = true;
  2730. }
  2731. /* setup the global rx defrag waitlist */
  2732. TAILQ_INIT(&soc->rx.defrag.waitlist);
  2733. soc->rx.defrag.timeout_ms =
  2734. wlan_cfg_get_rx_defrag_min_timeout(soc_cfg_ctx);
  2735. soc->rx.defrag.next_flush_ms = 0;
  2736. soc->rx.flags.defrag_timeout_check =
  2737. wlan_cfg_get_defrag_timeout_check(soc_cfg_ctx);
  2738. qdf_spinlock_create(&soc->rx.defrag.defrag_lock);
  2739. dp_create_ext_stats_event(soc);
  2740. out:
  2741. /*
  2742. * set the fragment destination ring
  2743. */
  2744. dp_reo_frag_dst_set(soc, &reo_params.frag_dst_ring);
  2745. hal_reo_setup(soc->hal_soc, &reo_params);
  2746. qdf_atomic_set(&soc->cmn_init_done, 1);
  2747. dp_soc_wds_attach(soc);
  2748. qdf_nbuf_queue_init(&soc->htt_stats.msg);
  2749. return 0;
  2750. fail2:
  2751. dp_tx_soc_detach(soc);
  2752. fail1:
  2753. /*
  2754. * Cleanup will be done as part of soc_detach, which will
  2755. * be called on pdev attach failure
  2756. */
  2757. return QDF_STATUS_E_FAILURE;
  2758. }
  2759. /*
  2760. * dp_soc_cmn_cleanup() - Common SoC level De-initializion
  2761. *
  2762. * @soc: Datapath SOC handle
  2763. *
  2764. * This function is responsible for cleaning up DP resource of Soc
  2765. * initialled in dp_pdev_attach_wifi3-->dp_soc_cmn_setup, since
  2766. * dp_soc_detach_wifi3 could not identify some of them
  2767. * whether they have done initialized or not accurately.
  2768. *
  2769. */
  2770. static void dp_soc_cmn_cleanup(struct dp_soc *soc)
  2771. {
  2772. if (!dp_is_soc_reinit(soc)) {
  2773. dp_tx_soc_detach(soc);
  2774. }
  2775. qdf_spinlock_destroy(&soc->rx.defrag.defrag_lock);
  2776. dp_reo_cmdlist_destroy(soc);
  2777. qdf_spinlock_destroy(&soc->rx.reo_cmd_lock);
  2778. }
  2779. static QDF_STATUS
  2780. dp_pdev_detach_wifi3(struct cdp_soc_t *psoc, uint8_t pdev_id,
  2781. int force);
  2782. static QDF_STATUS dp_lro_hash_setup(struct dp_soc *soc, struct dp_pdev *pdev)
  2783. {
  2784. struct cdp_lro_hash_config lro_hash;
  2785. QDF_STATUS status;
  2786. if (!wlan_cfg_is_lro_enabled(soc->wlan_cfg_ctx) &&
  2787. !wlan_cfg_is_gro_enabled(soc->wlan_cfg_ctx) &&
  2788. !wlan_cfg_is_rx_hash_enabled(soc->wlan_cfg_ctx)) {
  2789. dp_err("LRO, GRO and RX hash disabled");
  2790. return QDF_STATUS_E_FAILURE;
  2791. }
  2792. qdf_mem_zero(&lro_hash, sizeof(lro_hash));
  2793. if (wlan_cfg_is_lro_enabled(soc->wlan_cfg_ctx) ||
  2794. wlan_cfg_is_gro_enabled(soc->wlan_cfg_ctx)) {
  2795. lro_hash.lro_enable = 1;
  2796. lro_hash.tcp_flag = QDF_TCPHDR_ACK;
  2797. lro_hash.tcp_flag_mask = QDF_TCPHDR_FIN | QDF_TCPHDR_SYN |
  2798. QDF_TCPHDR_RST | QDF_TCPHDR_ACK | QDF_TCPHDR_URG |
  2799. QDF_TCPHDR_ECE | QDF_TCPHDR_CWR;
  2800. }
  2801. qdf_get_random_bytes(lro_hash.toeplitz_hash_ipv4,
  2802. (sizeof(lro_hash.toeplitz_hash_ipv4[0]) *
  2803. LRO_IPV4_SEED_ARR_SZ));
  2804. qdf_get_random_bytes(lro_hash.toeplitz_hash_ipv6,
  2805. (sizeof(lro_hash.toeplitz_hash_ipv6[0]) *
  2806. LRO_IPV6_SEED_ARR_SZ));
  2807. qdf_assert(soc->cdp_soc.ol_ops->lro_hash_config);
  2808. if (!soc->cdp_soc.ol_ops->lro_hash_config) {
  2809. QDF_BUG(0);
  2810. dp_err("lro_hash_config not configured");
  2811. return QDF_STATUS_E_FAILURE;
  2812. }
  2813. status = soc->cdp_soc.ol_ops->lro_hash_config(soc->ctrl_psoc,
  2814. pdev->pdev_id,
  2815. &lro_hash);
  2816. if (!QDF_IS_STATUS_SUCCESS(status)) {
  2817. dp_err("failed to send lro_hash_config to FW %u", status);
  2818. return status;
  2819. }
  2820. dp_info("LRO CMD config: lro_enable: 0x%x tcp_flag 0x%x tcp_flag_mask 0x%x",
  2821. lro_hash.lro_enable, lro_hash.tcp_flag,
  2822. lro_hash.tcp_flag_mask);
  2823. dp_info("toeplitz_hash_ipv4:");
  2824. qdf_trace_hex_dump(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2825. lro_hash.toeplitz_hash_ipv4,
  2826. (sizeof(lro_hash.toeplitz_hash_ipv4[0]) *
  2827. LRO_IPV4_SEED_ARR_SZ));
  2828. dp_info("toeplitz_hash_ipv6:");
  2829. qdf_trace_hex_dump(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2830. lro_hash.toeplitz_hash_ipv6,
  2831. (sizeof(lro_hash.toeplitz_hash_ipv6[0]) *
  2832. LRO_IPV6_SEED_ARR_SZ));
  2833. return status;
  2834. }
  2835. /*
  2836. * dp_rxdma_ring_setup() - configure the RX DMA rings
  2837. * @soc: data path SoC handle
  2838. * @pdev: Physical device handle
  2839. *
  2840. * Return: 0 - success, > 0 - failure
  2841. */
  2842. #ifdef QCA_HOST2FW_RXBUF_RING
  2843. static int dp_rxdma_ring_setup(struct dp_soc *soc,
  2844. struct dp_pdev *pdev)
  2845. {
  2846. struct wlan_cfg_dp_pdev_ctxt *pdev_cfg_ctx;
  2847. int max_mac_rings;
  2848. int i;
  2849. int ring_size;
  2850. pdev_cfg_ctx = pdev->wlan_cfg_ctx;
  2851. max_mac_rings = wlan_cfg_get_num_mac_rings(pdev_cfg_ctx);
  2852. ring_size = wlan_cfg_get_rx_dma_buf_ring_size(pdev_cfg_ctx);
  2853. for (i = 0; i < max_mac_rings; i++) {
  2854. dp_verbose_debug("pdev_id %d mac_id %d", pdev->pdev_id, i);
  2855. if (dp_srng_setup(soc, &pdev->rx_mac_buf_ring[i],
  2856. RXDMA_BUF, 1, i, ring_size, 0)) {
  2857. QDF_TRACE(QDF_MODULE_ID_DP,
  2858. QDF_TRACE_LEVEL_ERROR,
  2859. FL("failed rx mac ring setup"));
  2860. return QDF_STATUS_E_FAILURE;
  2861. }
  2862. }
  2863. return QDF_STATUS_SUCCESS;
  2864. }
  2865. #else
  2866. static int dp_rxdma_ring_setup(struct dp_soc *soc,
  2867. struct dp_pdev *pdev)
  2868. {
  2869. return QDF_STATUS_SUCCESS;
  2870. }
  2871. #endif
  2872. /**
  2873. * dp_dscp_tid_map_setup(): Initialize the dscp-tid maps
  2874. * @pdev - DP_PDEV handle
  2875. *
  2876. * Return: void
  2877. */
  2878. static inline void
  2879. dp_dscp_tid_map_setup(struct dp_pdev *pdev)
  2880. {
  2881. uint8_t map_id;
  2882. struct dp_soc *soc = pdev->soc;
  2883. if (!soc)
  2884. return;
  2885. for (map_id = 0; map_id < DP_MAX_TID_MAPS; map_id++) {
  2886. qdf_mem_copy(pdev->dscp_tid_map[map_id],
  2887. default_dscp_tid_map,
  2888. sizeof(default_dscp_tid_map));
  2889. }
  2890. for (map_id = 0; map_id < soc->num_hw_dscp_tid_map; map_id++) {
  2891. hal_tx_set_dscp_tid_map(soc->hal_soc,
  2892. default_dscp_tid_map,
  2893. map_id);
  2894. }
  2895. }
  2896. /**
  2897. * dp_pcp_tid_map_setup(): Initialize the pcp-tid maps
  2898. * @pdev - DP_PDEV handle
  2899. *
  2900. * Return: void
  2901. */
  2902. static inline void
  2903. dp_pcp_tid_map_setup(struct dp_pdev *pdev)
  2904. {
  2905. struct dp_soc *soc = pdev->soc;
  2906. if (!soc)
  2907. return;
  2908. qdf_mem_copy(soc->pcp_tid_map, default_pcp_tid_map,
  2909. sizeof(default_pcp_tid_map));
  2910. hal_tx_set_pcp_tid_map_default(soc->hal_soc, default_pcp_tid_map);
  2911. }
  2912. #ifdef IPA_OFFLOAD
  2913. /**
  2914. * dp_setup_ipa_rx_refill_buf_ring - Setup second Rx refill buffer ring
  2915. * @soc: data path instance
  2916. * @pdev: core txrx pdev context
  2917. *
  2918. * Return: QDF_STATUS_SUCCESS: success
  2919. * QDF_STATUS_E_RESOURCES: Error return
  2920. */
  2921. static int dp_setup_ipa_rx_refill_buf_ring(struct dp_soc *soc,
  2922. struct dp_pdev *pdev)
  2923. {
  2924. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx;
  2925. int entries;
  2926. soc_cfg_ctx = soc->wlan_cfg_ctx;
  2927. entries = wlan_cfg_get_dp_soc_rxdma_refill_ring_size(soc_cfg_ctx);
  2928. /* Setup second Rx refill buffer ring */
  2929. if (dp_srng_setup(soc, &pdev->rx_refill_buf_ring2, RXDMA_BUF,
  2930. IPA_RX_REFILL_BUF_RING_IDX, pdev->pdev_id, entries, 0)
  2931. ) {
  2932. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2933. FL("dp_srng_setup failed second rx refill ring"));
  2934. return QDF_STATUS_E_FAILURE;
  2935. }
  2936. return QDF_STATUS_SUCCESS;
  2937. }
  2938. /**
  2939. * dp_cleanup_ipa_rx_refill_buf_ring - Cleanup second Rx refill buffer ring
  2940. * @soc: data path instance
  2941. * @pdev: core txrx pdev context
  2942. *
  2943. * Return: void
  2944. */
  2945. static void dp_cleanup_ipa_rx_refill_buf_ring(struct dp_soc *soc,
  2946. struct dp_pdev *pdev)
  2947. {
  2948. dp_srng_cleanup(soc, &pdev->rx_refill_buf_ring2, RXDMA_BUF,
  2949. IPA_RX_REFILL_BUF_RING_IDX);
  2950. }
  2951. #else
  2952. static int dp_setup_ipa_rx_refill_buf_ring(struct dp_soc *soc,
  2953. struct dp_pdev *pdev)
  2954. {
  2955. return QDF_STATUS_SUCCESS;
  2956. }
  2957. static void dp_cleanup_ipa_rx_refill_buf_ring(struct dp_soc *soc,
  2958. struct dp_pdev *pdev)
  2959. {
  2960. }
  2961. #endif
  2962. #if !defined(DISABLE_MON_CONFIG)
  2963. /**
  2964. * dp_mon_rings_setup() - Initialize Monitor rings based on target
  2965. * @soc: soc handle
  2966. * @pdev: physical device handle
  2967. *
  2968. * Return: nonzero on failure and zero on success
  2969. */
  2970. static
  2971. QDF_STATUS dp_mon_rings_setup(struct dp_soc *soc, struct dp_pdev *pdev)
  2972. {
  2973. int mac_id = 0;
  2974. int pdev_id = pdev->pdev_id;
  2975. int entries;
  2976. struct wlan_cfg_dp_pdev_ctxt *pdev_cfg_ctx;
  2977. pdev_cfg_ctx = pdev->wlan_cfg_ctx;
  2978. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  2979. int lmac_id = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  2980. if (soc->wlan_cfg_ctx->rxdma1_enable) {
  2981. entries =
  2982. wlan_cfg_get_dma_mon_buf_ring_size(pdev_cfg_ctx);
  2983. if (dp_srng_setup(soc,
  2984. &soc->rxdma_mon_buf_ring[lmac_id],
  2985. RXDMA_MONITOR_BUF, 0, lmac_id,
  2986. entries, 0)) {
  2987. QDF_TRACE(QDF_MODULE_ID_DP,
  2988. QDF_TRACE_LEVEL_ERROR,
  2989. FL(RNG_ERR "rxdma_mon_buf_ring "));
  2990. return QDF_STATUS_E_NOMEM;
  2991. }
  2992. entries =
  2993. wlan_cfg_get_dma_mon_dest_ring_size(pdev_cfg_ctx);
  2994. if (dp_srng_setup(soc,
  2995. &soc->rxdma_mon_dst_ring[lmac_id],
  2996. RXDMA_MONITOR_DST, 0, lmac_id,
  2997. entries, 0)) {
  2998. QDF_TRACE(QDF_MODULE_ID_DP,
  2999. QDF_TRACE_LEVEL_ERROR,
  3000. FL(RNG_ERR "rxdma_mon_dst_ring"));
  3001. return QDF_STATUS_E_NOMEM;
  3002. }
  3003. entries =
  3004. wlan_cfg_get_dma_mon_stat_ring_size(pdev_cfg_ctx);
  3005. if (dp_srng_setup(soc,
  3006. &soc->rxdma_mon_status_ring[lmac_id],
  3007. RXDMA_MONITOR_STATUS, 0, lmac_id,
  3008. entries, 0)) {
  3009. QDF_TRACE(QDF_MODULE_ID_DP,
  3010. QDF_TRACE_LEVEL_ERROR,
  3011. FL(RNG_ERR "rxdma_mon_status_ring"));
  3012. return QDF_STATUS_E_NOMEM;
  3013. }
  3014. entries =
  3015. wlan_cfg_get_dma_mon_desc_ring_size(pdev_cfg_ctx);
  3016. if (dp_srng_setup(soc,
  3017. &soc->rxdma_mon_desc_ring[lmac_id],
  3018. RXDMA_MONITOR_DESC, 0, lmac_id,
  3019. entries, 0)) {
  3020. QDF_TRACE(QDF_MODULE_ID_DP,
  3021. QDF_TRACE_LEVEL_ERROR,
  3022. FL(RNG_ERR "rxdma_mon_desc_ring"));
  3023. return QDF_STATUS_E_NOMEM;
  3024. }
  3025. } else {
  3026. entries =
  3027. wlan_cfg_get_dma_mon_stat_ring_size(pdev_cfg_ctx);
  3028. if (dp_srng_setup(soc,
  3029. &soc->rxdma_mon_status_ring[lmac_id],
  3030. RXDMA_MONITOR_STATUS, 0, lmac_id,
  3031. entries, 0)) {
  3032. QDF_TRACE(QDF_MODULE_ID_DP,
  3033. QDF_TRACE_LEVEL_ERROR,
  3034. FL(RNG_ERR "rxdma_mon_status_ring"));
  3035. return QDF_STATUS_E_NOMEM;
  3036. }
  3037. }
  3038. }
  3039. return QDF_STATUS_SUCCESS;
  3040. }
  3041. #else
  3042. static
  3043. QDF_STATUS dp_mon_rings_setup(struct dp_soc *soc, struct dp_pdev *pdev)
  3044. {
  3045. return QDF_STATUS_SUCCESS;
  3046. }
  3047. #endif
  3048. /*dp_iterate_update_peer_list - update peer stats on cal client timer
  3049. * @pdev_hdl: pdev handle
  3050. */
  3051. #ifdef ATH_SUPPORT_EXT_STAT
  3052. void dp_iterate_update_peer_list(struct cdp_pdev *pdev_hdl)
  3053. {
  3054. struct dp_pdev *pdev = (struct dp_pdev *)pdev_hdl;
  3055. struct dp_soc *soc = pdev->soc;
  3056. struct dp_vdev *vdev = NULL;
  3057. struct dp_peer *peer = NULL;
  3058. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  3059. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  3060. DP_PDEV_ITERATE_VDEV_LIST(pdev, vdev) {
  3061. DP_VDEV_ITERATE_PEER_LIST(vdev, peer) {
  3062. dp_cal_client_update_peer_stats(&peer->stats);
  3063. }
  3064. }
  3065. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  3066. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  3067. }
  3068. #else
  3069. void dp_iterate_update_peer_list(struct cdp_pdev *pdev_hdl)
  3070. {
  3071. }
  3072. #endif
  3073. /*
  3074. * dp_htt_ppdu_stats_attach() - attach resources for HTT PPDU stats processing
  3075. * @pdev: Datapath PDEV handle
  3076. *
  3077. * Return: QDF_STATUS_SUCCESS: Success
  3078. * QDF_STATUS_E_NOMEM: Error
  3079. */
  3080. static QDF_STATUS dp_htt_ppdu_stats_attach(struct dp_pdev *pdev)
  3081. {
  3082. pdev->ppdu_tlv_buf = qdf_mem_malloc(HTT_T2H_MAX_MSG_SIZE);
  3083. if (!pdev->ppdu_tlv_buf) {
  3084. QDF_TRACE_ERROR(QDF_MODULE_ID_DP, "ppdu_tlv_buf alloc fail");
  3085. return QDF_STATUS_E_NOMEM;
  3086. }
  3087. return QDF_STATUS_SUCCESS;
  3088. }
  3089. /*
  3090. * dp_pdev_attach_wifi3() - attach txrx pdev
  3091. * @txrx_soc: Datapath SOC handle
  3092. * @htc_handle: HTC handle for host-target interface
  3093. * @qdf_osdev: QDF OS device
  3094. * @pdev_id: PDEV ID
  3095. *
  3096. * Return: QDF_STATUS
  3097. */
  3098. static inline QDF_STATUS dp_pdev_attach_wifi3(struct cdp_soc_t *txrx_soc,
  3099. HTC_HANDLE htc_handle,
  3100. qdf_device_t qdf_osdev,
  3101. uint8_t pdev_id)
  3102. {
  3103. int ring_size;
  3104. int entries;
  3105. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx;
  3106. int nss_cfg;
  3107. void *sojourn_buf;
  3108. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3109. struct dp_pdev *pdev = NULL;
  3110. QDF_STATUS ret;
  3111. if (dp_is_soc_reinit(soc)) {
  3112. pdev = soc->pdev_list[pdev_id];
  3113. } else {
  3114. pdev = qdf_mem_malloc(sizeof(*pdev));
  3115. qdf_minidump_log(pdev, sizeof(*pdev), "dp_pdev");
  3116. }
  3117. if (!pdev) {
  3118. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3119. FL("DP PDEV memory allocation failed"));
  3120. ret = QDF_STATUS_E_NOMEM;
  3121. goto fail0;
  3122. }
  3123. /*
  3124. * Variable to prevent double pdev deinitialization during
  3125. * radio detach execution .i.e. in the absence of any vdev.
  3126. */
  3127. pdev->pdev_deinit = 0;
  3128. pdev->invalid_peer = qdf_mem_malloc(sizeof(struct dp_peer));
  3129. if (!pdev->invalid_peer) {
  3130. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3131. FL("Invalid peer memory allocation failed"));
  3132. qdf_mem_free(pdev);
  3133. ret = QDF_STATUS_E_NOMEM;
  3134. goto fail0;
  3135. }
  3136. soc_cfg_ctx = soc->wlan_cfg_ctx;
  3137. pdev->wlan_cfg_ctx = wlan_cfg_pdev_attach(soc->ctrl_psoc);
  3138. if (!pdev->wlan_cfg_ctx) {
  3139. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3140. FL("pdev cfg_attach failed"));
  3141. qdf_mem_free(pdev->invalid_peer);
  3142. qdf_mem_free(pdev);
  3143. ret = QDF_STATUS_E_FAILURE;
  3144. goto fail0;
  3145. }
  3146. /*
  3147. * set nss pdev config based on soc config
  3148. */
  3149. nss_cfg = wlan_cfg_get_dp_soc_nss_cfg(soc_cfg_ctx);
  3150. wlan_cfg_set_dp_pdev_nss_enabled(pdev->wlan_cfg_ctx,
  3151. (nss_cfg & (1 << pdev_id)));
  3152. pdev->soc = soc;
  3153. pdev->pdev_id = pdev_id;
  3154. soc->pdev_list[pdev_id] = pdev;
  3155. pdev->lmac_id = wlan_cfg_get_hw_mac_idx(soc->wlan_cfg_ctx, pdev_id);
  3156. soc->pdev_count++;
  3157. TAILQ_INIT(&pdev->vdev_list);
  3158. qdf_spinlock_create(&pdev->vdev_list_lock);
  3159. pdev->vdev_count = 0;
  3160. qdf_spinlock_create(&pdev->tx_mutex);
  3161. qdf_spinlock_create(&pdev->neighbour_peer_mutex);
  3162. TAILQ_INIT(&pdev->neighbour_peers_list);
  3163. pdev->neighbour_peers_added = false;
  3164. pdev->monitor_configured = false;
  3165. if (dp_soc_cmn_setup(soc)) {
  3166. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3167. FL("dp_soc_cmn_setup failed"));
  3168. ret = QDF_STATUS_E_FAILURE;
  3169. goto fail1;
  3170. }
  3171. /* Setup per PDEV TCL rings if configured */
  3172. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3173. ring_size =
  3174. wlan_cfg_tx_ring_size(soc_cfg_ctx);
  3175. if (dp_srng_setup(soc, &soc->tcl_data_ring[pdev_id], TCL_DATA,
  3176. pdev_id, pdev_id, ring_size, 0)) {
  3177. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3178. FL("dp_srng_setup failed for tcl_data_ring"));
  3179. ret = QDF_STATUS_E_FAILURE;
  3180. goto fail1;
  3181. }
  3182. ring_size =
  3183. wlan_cfg_tx_comp_ring_size(soc_cfg_ctx);
  3184. if (dp_srng_setup(soc, &soc->tx_comp_ring[pdev_id],
  3185. WBM2SW_RELEASE, pdev_id, pdev_id,
  3186. ring_size, 0)) {
  3187. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3188. FL("dp_srng_setup failed for tx_comp_ring"));
  3189. ret = QDF_STATUS_E_FAILURE;
  3190. goto fail1;
  3191. }
  3192. soc->num_tcl_data_rings++;
  3193. }
  3194. /* Tx specific init */
  3195. if (dp_tx_pdev_attach(pdev)) {
  3196. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3197. FL("dp_tx_pdev_attach failed"));
  3198. ret = QDF_STATUS_E_FAILURE;
  3199. goto fail1;
  3200. }
  3201. ring_size = wlan_cfg_get_reo_dst_ring_size(soc->wlan_cfg_ctx);
  3202. /* Setup per PDEV REO rings if configured */
  3203. if (wlan_cfg_per_pdev_rx_ring(soc_cfg_ctx)) {
  3204. if (dp_srng_setup(soc, &soc->reo_dest_ring[pdev_id], REO_DST,
  3205. pdev_id, pdev_id, ring_size, 0)) {
  3206. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3207. FL("dp_srng_setup failed for reo_dest_ringn"));
  3208. ret = QDF_STATUS_E_FAILURE;
  3209. goto fail1;
  3210. }
  3211. soc->num_reo_dest_rings++;
  3212. }
  3213. ring_size =
  3214. wlan_cfg_get_dp_soc_rxdma_refill_ring_size(soc->wlan_cfg_ctx);
  3215. if (dp_srng_setup(soc, &soc->rx_refill_buf_ring[pdev->lmac_id],
  3216. RXDMA_BUF, 0, pdev->lmac_id, ring_size, 0)) {
  3217. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3218. FL("dp_srng_setup failed rx refill ring"));
  3219. ret = QDF_STATUS_E_FAILURE;
  3220. goto fail1;
  3221. }
  3222. if (dp_rxdma_ring_setup(soc, pdev)) {
  3223. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3224. FL("RXDMA ring config failed"));
  3225. ret = QDF_STATUS_E_FAILURE;
  3226. goto fail1;
  3227. }
  3228. if (dp_mon_rings_setup(soc, pdev)) {
  3229. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3230. FL("MONITOR rings setup failed"));
  3231. ret = QDF_STATUS_E_FAILURE;
  3232. goto fail1;
  3233. }
  3234. entries = wlan_cfg_get_dp_soc_rxdma_err_dst_ring_size(soc_cfg_ctx);
  3235. if (wlan_cfg_per_pdev_lmac_ring(soc->wlan_cfg_ctx)) {
  3236. if (dp_srng_setup(soc,
  3237. &soc->rxdma_err_dst_ring[pdev->lmac_id],
  3238. RXDMA_DST,
  3239. 0, pdev->lmac_id, entries, 0)) {
  3240. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3241. FL(RNG_ERR "rxdma_err_dst_ring"));
  3242. ret = QDF_STATUS_E_FAILURE;
  3243. goto fail1;
  3244. }
  3245. }
  3246. if (dp_setup_ipa_rx_refill_buf_ring(soc, pdev)) {
  3247. ret = QDF_STATUS_E_FAILURE;
  3248. goto fail1;
  3249. }
  3250. if (dp_ipa_ring_resource_setup(soc, pdev)) {
  3251. ret = QDF_STATUS_E_FAILURE;
  3252. goto fail1;
  3253. }
  3254. if (dp_ipa_uc_attach(soc, pdev) != QDF_STATUS_SUCCESS) {
  3255. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3256. FL("dp_ipa_uc_attach failed"));
  3257. ret = QDF_STATUS_E_FAILURE;
  3258. goto fail1;
  3259. }
  3260. /* Rx specific init */
  3261. if (dp_rx_pdev_attach(pdev)) {
  3262. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3263. FL("dp_rx_pdev_attach failed"));
  3264. ret = QDF_STATUS_E_FAILURE;
  3265. goto fail2;
  3266. }
  3267. DP_STATS_INIT(pdev);
  3268. /* Monitor filter init */
  3269. pdev->mon_filter_mode = MON_FILTER_ALL;
  3270. pdev->fp_mgmt_filter = FILTER_MGMT_ALL;
  3271. pdev->fp_ctrl_filter = FILTER_CTRL_ALL;
  3272. pdev->fp_data_filter = FILTER_DATA_ALL;
  3273. pdev->mo_mgmt_filter = FILTER_MGMT_ALL;
  3274. pdev->mo_ctrl_filter = FILTER_CTRL_ALL;
  3275. pdev->mo_data_filter = FILTER_DATA_ALL;
  3276. dp_local_peer_id_pool_init(pdev);
  3277. dp_dscp_tid_map_setup(pdev);
  3278. dp_pcp_tid_map_setup(pdev);
  3279. /* Rx monitor mode specific init */
  3280. if (dp_rx_pdev_mon_attach(pdev)) {
  3281. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  3282. "dp_rx_pdev_mon_attach failed");
  3283. ret = QDF_STATUS_E_FAILURE;
  3284. goto fail2;
  3285. }
  3286. if (dp_wdi_event_attach(pdev)) {
  3287. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  3288. "dp_wdi_evet_attach failed");
  3289. ret = QDF_STATUS_E_FAILURE;
  3290. goto wdi_attach_fail;
  3291. }
  3292. /* set the reo destination during initialization */
  3293. pdev->reo_dest = pdev->pdev_id + 1;
  3294. /*
  3295. * initialize ppdu tlv list
  3296. */
  3297. TAILQ_INIT(&pdev->ppdu_info_list);
  3298. pdev->tlv_count = 0;
  3299. pdev->list_depth = 0;
  3300. qdf_mem_zero(&pdev->sojourn_stats, sizeof(struct cdp_tx_sojourn_stats));
  3301. pdev->sojourn_buf = qdf_nbuf_alloc(pdev->soc->osdev,
  3302. sizeof(struct cdp_tx_sojourn_stats), 0, 4,
  3303. TRUE);
  3304. if (pdev->sojourn_buf) {
  3305. sojourn_buf = qdf_nbuf_data(pdev->sojourn_buf);
  3306. qdf_mem_zero(sojourn_buf, sizeof(struct cdp_tx_sojourn_stats));
  3307. }
  3308. /* initlialize cal client timer */
  3309. dp_cal_client_attach(&pdev->cal_client_ctx,
  3310. dp_pdev_to_cdp_pdev(pdev),
  3311. pdev->soc->osdev,
  3312. &dp_iterate_update_peer_list);
  3313. qdf_event_create(&pdev->fw_peer_stats_event);
  3314. pdev->num_tx_allowed = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  3315. dp_init_tso_stats(pdev);
  3316. if (dp_htt_ppdu_stats_attach(pdev) != QDF_STATUS_SUCCESS) {
  3317. ret = QDF_STATUS_E_FAILURE;
  3318. goto fail1;
  3319. }
  3320. dp_tx_ppdu_stats_attach(pdev);
  3321. return QDF_STATUS_SUCCESS;
  3322. wdi_attach_fail:
  3323. /*
  3324. * dp_mon_link_desc_pool_cleanup is done in dp_pdev_detach
  3325. * and hence need not to be done here.
  3326. */
  3327. dp_rx_pdev_mon_detach(pdev);
  3328. fail2:
  3329. dp_rx_pdev_detach(pdev);
  3330. fail1:
  3331. if (pdev->invalid_peer)
  3332. qdf_mem_free(pdev->invalid_peer);
  3333. dp_pdev_detach((struct cdp_pdev *)pdev, 0);
  3334. fail0:
  3335. return ret;
  3336. }
  3337. /*
  3338. * dp_rxdma_ring_cleanup() - configure the RX DMA rings
  3339. * @soc: data path SoC handle
  3340. * @pdev: Physical device handle
  3341. *
  3342. * Return: void
  3343. */
  3344. #ifdef QCA_HOST2FW_RXBUF_RING
  3345. static void dp_rxdma_ring_cleanup(struct dp_soc *soc,
  3346. struct dp_pdev *pdev)
  3347. {
  3348. int i;
  3349. for (i = 0; i < MAX_RX_MAC_RINGS; i++)
  3350. dp_srng_cleanup(soc, &pdev->rx_mac_buf_ring[i],
  3351. RXDMA_BUF, 1);
  3352. if (soc->reap_timer_init) {
  3353. qdf_timer_free(&soc->mon_reap_timer);
  3354. soc->reap_timer_init = 0;
  3355. }
  3356. }
  3357. #else
  3358. static void dp_rxdma_ring_cleanup(struct dp_soc *soc,
  3359. struct dp_pdev *pdev)
  3360. {
  3361. if (soc->lmac_timer_init) {
  3362. qdf_timer_stop(&soc->lmac_reap_timer);
  3363. qdf_timer_free(&soc->lmac_reap_timer);
  3364. soc->lmac_timer_init = 0;
  3365. }
  3366. }
  3367. #endif
  3368. /*
  3369. * dp_neighbour_peers_detach() - Detach neighbour peers(nac clients)
  3370. * @pdev: device object
  3371. *
  3372. * Return: void
  3373. */
  3374. static void dp_neighbour_peers_detach(struct dp_pdev *pdev)
  3375. {
  3376. struct dp_neighbour_peer *peer = NULL;
  3377. struct dp_neighbour_peer *temp_peer = NULL;
  3378. TAILQ_FOREACH_SAFE(peer, &pdev->neighbour_peers_list,
  3379. neighbour_peer_list_elem, temp_peer) {
  3380. /* delete this peer from the list */
  3381. TAILQ_REMOVE(&pdev->neighbour_peers_list,
  3382. peer, neighbour_peer_list_elem);
  3383. qdf_mem_free(peer);
  3384. }
  3385. qdf_spinlock_destroy(&pdev->neighbour_peer_mutex);
  3386. }
  3387. /**
  3388. * dp_htt_ppdu_stats_detach() - detach stats resources
  3389. * @pdev: Datapath PDEV handle
  3390. *
  3391. * Return: void
  3392. */
  3393. static void dp_htt_ppdu_stats_detach(struct dp_pdev *pdev)
  3394. {
  3395. struct ppdu_info *ppdu_info, *ppdu_info_next;
  3396. TAILQ_FOREACH_SAFE(ppdu_info, &pdev->ppdu_info_list,
  3397. ppdu_info_list_elem, ppdu_info_next) {
  3398. if (!ppdu_info)
  3399. break;
  3400. qdf_assert_always(ppdu_info->nbuf);
  3401. qdf_nbuf_free(ppdu_info->nbuf);
  3402. qdf_mem_free(ppdu_info);
  3403. }
  3404. if (pdev->ppdu_tlv_buf)
  3405. qdf_mem_free(pdev->ppdu_tlv_buf);
  3406. }
  3407. #if !defined(DISABLE_MON_CONFIG)
  3408. static
  3409. void dp_mon_ring_cleanup(struct dp_soc *soc, struct dp_pdev *pdev,
  3410. int mac_id)
  3411. {
  3412. if (soc->wlan_cfg_ctx->rxdma1_enable) {
  3413. dp_srng_cleanup(soc,
  3414. &soc->rxdma_mon_buf_ring[mac_id],
  3415. RXDMA_MONITOR_BUF, 0);
  3416. dp_srng_cleanup(soc,
  3417. &soc->rxdma_mon_dst_ring[mac_id],
  3418. RXDMA_MONITOR_DST, 0);
  3419. dp_srng_cleanup(soc,
  3420. &soc->rxdma_mon_status_ring[mac_id],
  3421. RXDMA_MONITOR_STATUS, 0);
  3422. dp_srng_cleanup(soc,
  3423. &soc->rxdma_mon_desc_ring[mac_id],
  3424. RXDMA_MONITOR_DESC, 0);
  3425. dp_srng_cleanup(soc,
  3426. &soc->rxdma_err_dst_ring[mac_id],
  3427. RXDMA_DST, 0);
  3428. } else {
  3429. dp_srng_cleanup(soc,
  3430. &soc->rxdma_mon_status_ring[mac_id],
  3431. RXDMA_MONITOR_STATUS, 0);
  3432. dp_srng_cleanup(soc,
  3433. &soc->rxdma_err_dst_ring[mac_id],
  3434. RXDMA_DST, 0);
  3435. }
  3436. }
  3437. #else
  3438. static void dp_mon_ring_cleanup(struct dp_soc *soc, struct dp_pdev *pdev,
  3439. int mac_id)
  3440. {
  3441. }
  3442. #endif
  3443. /**
  3444. * dp_mon_ring_deinit() - Placeholder to deinitialize Monitor rings
  3445. *
  3446. * @soc: soc handle
  3447. * @pdev: datapath physical dev handle
  3448. * @mac_id: mac number
  3449. *
  3450. * Return: None
  3451. */
  3452. static void dp_mon_ring_deinit(struct dp_soc *soc, struct dp_pdev *pdev,
  3453. int mac_id)
  3454. {
  3455. }
  3456. /**
  3457. * dp_pdev_mem_reset() - Reset txrx pdev memory
  3458. * @pdev: dp pdev handle
  3459. *
  3460. * Return: None
  3461. */
  3462. static void dp_pdev_mem_reset(struct dp_pdev *pdev)
  3463. {
  3464. uint16_t len = 0;
  3465. uint8_t *dp_pdev_offset = (uint8_t *)pdev;
  3466. len = sizeof(struct dp_pdev) -
  3467. offsetof(struct dp_pdev, pdev_deinit) -
  3468. sizeof(pdev->pdev_deinit);
  3469. dp_pdev_offset = dp_pdev_offset +
  3470. offsetof(struct dp_pdev, pdev_deinit) +
  3471. sizeof(pdev->pdev_deinit);
  3472. qdf_mem_zero(dp_pdev_offset, len);
  3473. }
  3474. #ifdef WLAN_DP_PENDING_MEM_FLUSH
  3475. /**
  3476. * dp_pdev_flush_pending_vdevs() - Flush all delete pending vdevs in pdev
  3477. * @pdev: Datapath PDEV handle
  3478. *
  3479. * This is the last chance to flush all pending dp vdevs/peers,
  3480. * some peer/vdev leak case like Non-SSR + peer unmap missing
  3481. * will be covered here.
  3482. *
  3483. * Return: None
  3484. */
  3485. static void dp_pdev_flush_pending_vdevs(struct dp_pdev *pdev)
  3486. {
  3487. struct dp_vdev *vdev = NULL;
  3488. while (true) {
  3489. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  3490. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  3491. if (vdev->delete.pending)
  3492. break;
  3493. }
  3494. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  3495. /*
  3496. * vdev will be freed when all peers get cleanup,
  3497. * dp_delete_pending_vdev will remove vdev from vdev_list
  3498. * in pdev.
  3499. */
  3500. if (vdev)
  3501. dp_vdev_flush_peers((struct cdp_vdev *)vdev, 0);
  3502. else
  3503. break;
  3504. }
  3505. }
  3506. #else
  3507. static void dp_pdev_flush_pending_vdevs(struct dp_pdev *pdev)
  3508. {
  3509. }
  3510. #endif
  3511. /**
  3512. * dp_pdev_deinit() - Deinit txrx pdev
  3513. * @txrx_pdev: Datapath PDEV handle
  3514. * @force: Force deinit
  3515. *
  3516. * Return: None
  3517. */
  3518. static void dp_pdev_deinit(struct cdp_pdev *txrx_pdev, int force)
  3519. {
  3520. struct dp_pdev *pdev = (struct dp_pdev *)txrx_pdev;
  3521. struct dp_soc *soc = pdev->soc;
  3522. qdf_nbuf_t curr_nbuf, next_nbuf;
  3523. int mac_id;
  3524. /*
  3525. * Prevent double pdev deinitialization during radio detach
  3526. * execution .i.e. in the absence of any vdev
  3527. */
  3528. if (pdev->pdev_deinit)
  3529. return;
  3530. pdev->pdev_deinit = 1;
  3531. dp_wdi_event_detach(pdev);
  3532. dp_pdev_flush_pending_vdevs(pdev);
  3533. dp_tx_pdev_detach(pdev);
  3534. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3535. dp_srng_deinit(soc, &soc->tcl_data_ring[pdev->pdev_id],
  3536. TCL_DATA, pdev->pdev_id);
  3537. dp_srng_deinit(soc, &soc->tx_comp_ring[pdev->pdev_id],
  3538. WBM2SW_RELEASE, pdev->pdev_id);
  3539. }
  3540. dp_pktlogmod_exit(pdev);
  3541. dp_rx_fst_detach(soc, pdev);
  3542. dp_rx_pdev_detach(pdev);
  3543. dp_rx_pdev_mon_detach(pdev);
  3544. dp_neighbour_peers_detach(pdev);
  3545. qdf_spinlock_destroy(&pdev->tx_mutex);
  3546. qdf_spinlock_destroy(&pdev->vdev_list_lock);
  3547. dp_ipa_uc_detach(soc, pdev);
  3548. dp_cleanup_ipa_rx_refill_buf_ring(soc, pdev);
  3549. /* Cleanup per PDEV REO rings if configured */
  3550. if (wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  3551. dp_srng_deinit(soc, &soc->reo_dest_ring[pdev->pdev_id],
  3552. REO_DST, pdev->pdev_id);
  3553. }
  3554. dp_srng_deinit(soc, &soc->rx_refill_buf_ring[pdev->lmac_id],
  3555. RXDMA_BUF, 0);
  3556. dp_rxdma_ring_cleanup(soc, pdev);
  3557. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  3558. int lmac_id =
  3559. dp_get_lmac_id_for_pdev_id(soc, pdev->pdev_id, mac_id);
  3560. dp_mon_ring_deinit(soc, pdev, lmac_id);
  3561. dp_srng_deinit(soc, &soc->rxdma_err_dst_ring[lmac_id],
  3562. RXDMA_DST, 0);
  3563. }
  3564. curr_nbuf = pdev->invalid_peer_head_msdu;
  3565. while (curr_nbuf) {
  3566. next_nbuf = qdf_nbuf_next(curr_nbuf);
  3567. qdf_nbuf_free(curr_nbuf);
  3568. curr_nbuf = next_nbuf;
  3569. }
  3570. pdev->invalid_peer_head_msdu = NULL;
  3571. pdev->invalid_peer_tail_msdu = NULL;
  3572. dp_htt_ppdu_stats_detach(pdev);
  3573. dp_tx_ppdu_stats_detach(pdev);
  3574. qdf_nbuf_free(pdev->sojourn_buf);
  3575. qdf_nbuf_queue_free(&pdev->rx_ppdu_buf_q);
  3576. dp_cal_client_detach(&pdev->cal_client_ctx);
  3577. soc->pdev_count--;
  3578. /* only do soc common cleanup when last pdev do detach */
  3579. if (!(soc->pdev_count))
  3580. dp_soc_cmn_cleanup(soc);
  3581. wlan_cfg_pdev_detach(pdev->wlan_cfg_ctx);
  3582. if (pdev->invalid_peer)
  3583. qdf_mem_free(pdev->invalid_peer);
  3584. qdf_mem_free(pdev->dp_txrx_handle);
  3585. dp_pdev_mem_reset(pdev);
  3586. }
  3587. /**
  3588. * dp_pdev_deinit_wifi3() - Deinit txrx pdev
  3589. * @psoc: Datapath psoc handle
  3590. * @pdev_id: Id of datapath PDEV handle
  3591. * @force: Force deinit
  3592. *
  3593. * Return: QDF_STATUS
  3594. */
  3595. static QDF_STATUS
  3596. dp_pdev_deinit_wifi3(struct cdp_soc_t *psoc, uint8_t pdev_id,
  3597. int force)
  3598. {
  3599. struct dp_soc *soc = (struct dp_soc *)psoc;
  3600. struct dp_pdev *txrx_pdev =
  3601. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)psoc,
  3602. pdev_id);
  3603. if (!txrx_pdev)
  3604. return QDF_STATUS_E_FAILURE;
  3605. soc->dp_soc_reinit = TRUE;
  3606. dp_pdev_deinit((struct cdp_pdev *)txrx_pdev, force);
  3607. return QDF_STATUS_SUCCESS;
  3608. }
  3609. /*
  3610. * dp_pdev_detach() - Complete rest of pdev detach
  3611. * @txrx_pdev: Datapath PDEV handle
  3612. * @force: Force deinit
  3613. *
  3614. * Return: None
  3615. */
  3616. static void dp_pdev_detach(struct cdp_pdev *txrx_pdev, int force)
  3617. {
  3618. struct dp_pdev *pdev = (struct dp_pdev *)txrx_pdev;
  3619. struct dp_soc *soc = pdev->soc;
  3620. struct rx_desc_pool *rx_desc_pool;
  3621. int mac_id, mac_for_pdev;
  3622. int lmac_id;
  3623. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3624. dp_srng_cleanup(soc, &soc->tcl_data_ring[pdev->pdev_id],
  3625. TCL_DATA, pdev->pdev_id);
  3626. dp_srng_cleanup(soc, &soc->tx_comp_ring[pdev->pdev_id],
  3627. WBM2SW_RELEASE, pdev->pdev_id);
  3628. }
  3629. dp_mon_link_free(pdev);
  3630. /* Cleanup per PDEV REO rings if configured */
  3631. if (wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  3632. dp_srng_cleanup(soc, &soc->reo_dest_ring[pdev->pdev_id],
  3633. REO_DST, pdev->pdev_id);
  3634. }
  3635. dp_rxdma_ring_cleanup(soc, pdev);
  3636. wlan_cfg_pdev_detach(pdev->wlan_cfg_ctx);
  3637. dp_srng_cleanup(soc, &soc->rx_refill_buf_ring[pdev->lmac_id],
  3638. RXDMA_BUF, 0);
  3639. dp_cleanup_ipa_rx_refill_buf_ring(soc, pdev);
  3640. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  3641. lmac_id =
  3642. dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev->pdev_id);
  3643. dp_mon_ring_cleanup(soc, pdev, lmac_id);
  3644. dp_srng_cleanup(soc, &soc->rxdma_err_dst_ring[lmac_id],
  3645. RXDMA_DST, 0);
  3646. if (dp_is_soc_reinit(soc)) {
  3647. mac_for_pdev =
  3648. dp_get_lmac_id_for_pdev_id(soc, mac_id,
  3649. pdev->pdev_id);
  3650. rx_desc_pool = &soc->rx_desc_status[mac_for_pdev];
  3651. dp_rx_desc_pool_free(soc, rx_desc_pool);
  3652. rx_desc_pool = &soc->rx_desc_mon[mac_for_pdev];
  3653. dp_rx_desc_pool_free(soc, rx_desc_pool);
  3654. }
  3655. }
  3656. if (dp_is_soc_reinit(soc)) {
  3657. rx_desc_pool = &soc->rx_desc_buf[pdev->lmac_id];
  3658. dp_rx_desc_pool_free(soc, rx_desc_pool);
  3659. }
  3660. soc->pdev_list[pdev->pdev_id] = NULL;
  3661. qdf_minidump_remove(pdev);
  3662. qdf_mem_free(pdev);
  3663. }
  3664. /*
  3665. * dp_pdev_detach_wifi3() - detach txrx pdev
  3666. * @psoc: Datapath soc handle
  3667. * @pdev_id: pdev id of pdev
  3668. * @force: Force detach
  3669. *
  3670. * Return: QDF_STATUS
  3671. */
  3672. static QDF_STATUS dp_pdev_detach_wifi3(struct cdp_soc_t *psoc, uint8_t pdev_id,
  3673. int force)
  3674. {
  3675. struct dp_soc *soc = (struct dp_soc *)psoc;
  3676. struct dp_pdev *txrx_pdev =
  3677. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)psoc,
  3678. pdev_id);
  3679. if (!txrx_pdev) {
  3680. dp_err("Couldn't find dp pdev");
  3681. return QDF_STATUS_E_FAILURE;
  3682. }
  3683. if (dp_is_soc_reinit(soc)) {
  3684. dp_pdev_detach((struct cdp_pdev *)txrx_pdev, force);
  3685. } else {
  3686. dp_pdev_deinit((struct cdp_pdev *)txrx_pdev, force);
  3687. dp_pdev_detach((struct cdp_pdev *)txrx_pdev, force);
  3688. }
  3689. return QDF_STATUS_SUCCESS;
  3690. }
  3691. /*
  3692. * dp_reo_desc_freelist_destroy() - Flush REO descriptors from deferred freelist
  3693. * @soc: DP SOC handle
  3694. */
  3695. static inline void dp_reo_desc_freelist_destroy(struct dp_soc *soc)
  3696. {
  3697. struct reo_desc_list_node *desc;
  3698. struct dp_rx_tid *rx_tid;
  3699. qdf_spin_lock_bh(&soc->reo_desc_freelist_lock);
  3700. while (qdf_list_remove_front(&soc->reo_desc_freelist,
  3701. (qdf_list_node_t **)&desc) == QDF_STATUS_SUCCESS) {
  3702. rx_tid = &desc->rx_tid;
  3703. qdf_mem_unmap_nbytes_single(soc->osdev,
  3704. rx_tid->hw_qdesc_paddr,
  3705. QDF_DMA_BIDIRECTIONAL,
  3706. rx_tid->hw_qdesc_alloc_size);
  3707. qdf_mem_free(rx_tid->hw_qdesc_vaddr_unaligned);
  3708. qdf_mem_free(desc);
  3709. }
  3710. qdf_spin_unlock_bh(&soc->reo_desc_freelist_lock);
  3711. qdf_list_destroy(&soc->reo_desc_freelist);
  3712. qdf_spinlock_destroy(&soc->reo_desc_freelist_lock);
  3713. }
  3714. /**
  3715. * dp_soc_mem_reset() - Reset Dp Soc memory
  3716. * @soc: DP handle
  3717. *
  3718. * Return: None
  3719. */
  3720. static void dp_soc_mem_reset(struct dp_soc *soc)
  3721. {
  3722. uint16_t len = 0;
  3723. uint8_t *dp_soc_offset = (uint8_t *)soc;
  3724. len = sizeof(struct dp_soc) -
  3725. offsetof(struct dp_soc, dp_soc_reinit) -
  3726. sizeof(soc->dp_soc_reinit);
  3727. dp_soc_offset = dp_soc_offset +
  3728. offsetof(struct dp_soc, dp_soc_reinit) +
  3729. sizeof(soc->dp_soc_reinit);
  3730. qdf_mem_zero(dp_soc_offset, len);
  3731. }
  3732. /**
  3733. * dp_soc_deinit() - Deinitialize txrx SOC
  3734. * @txrx_soc: Opaque DP SOC handle
  3735. *
  3736. * Return: None
  3737. */
  3738. static void dp_soc_deinit(void *txrx_soc)
  3739. {
  3740. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3741. int i;
  3742. qdf_atomic_set(&soc->cmn_init_done, 0);
  3743. for (i = 0; i < MAX_PDEV_CNT; i++) {
  3744. if (soc->pdev_list[i])
  3745. dp_pdev_deinit((struct cdp_pdev *)
  3746. soc->pdev_list[i], 1);
  3747. }
  3748. qdf_flush_work(&soc->htt_stats.work);
  3749. qdf_disable_work(&soc->htt_stats.work);
  3750. /* Free pending htt stats messages */
  3751. qdf_nbuf_queue_free(&soc->htt_stats.msg);
  3752. dp_peer_find_detach(soc);
  3753. /* Free the ring memories */
  3754. /* Common rings */
  3755. dp_srng_deinit(soc, &soc->wbm_desc_rel_ring, SW2WBM_RELEASE, 0);
  3756. /* Tx data rings */
  3757. if (!wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3758. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  3759. dp_srng_deinit(soc, &soc->tcl_data_ring[i],
  3760. TCL_DATA, i);
  3761. dp_srng_deinit(soc, &soc->tx_comp_ring[i],
  3762. WBM2SW_RELEASE, i);
  3763. }
  3764. }
  3765. /* TCL command and status rings */
  3766. dp_srng_deinit(soc, &soc->tcl_cmd_ring, TCL_CMD, 0);
  3767. dp_srng_deinit(soc, &soc->tcl_status_ring, TCL_STATUS, 0);
  3768. /* Rx data rings */
  3769. if (!wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  3770. soc->num_reo_dest_rings =
  3771. wlan_cfg_num_reo_dest_rings(soc->wlan_cfg_ctx);
  3772. for (i = 0; i < soc->num_reo_dest_rings; i++) {
  3773. /* TODO: Get number of rings and ring sizes
  3774. * from wlan_cfg
  3775. */
  3776. dp_srng_deinit(soc, &soc->reo_dest_ring[i],
  3777. REO_DST, i);
  3778. }
  3779. }
  3780. /* REO reinjection ring */
  3781. dp_srng_deinit(soc, &soc->reo_reinject_ring, REO_REINJECT, 0);
  3782. /* Rx release ring */
  3783. dp_srng_deinit(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 0);
  3784. /* Rx exception ring */
  3785. /* TODO: Better to store ring_type and ring_num in
  3786. * dp_srng during setup
  3787. */
  3788. dp_srng_deinit(soc, &soc->reo_exception_ring, REO_EXCEPTION, 0);
  3789. /* REO command and status rings */
  3790. dp_srng_deinit(soc, &soc->reo_cmd_ring, REO_CMD, 0);
  3791. dp_srng_deinit(soc, &soc->reo_status_ring, REO_STATUS, 0);
  3792. dp_soc_wds_detach(soc);
  3793. qdf_spinlock_destroy(&soc->peer_ref_mutex);
  3794. qdf_spinlock_destroy(&soc->htt_stats.lock);
  3795. htt_soc_htc_dealloc(soc->htt_handle);
  3796. dp_reo_desc_freelist_destroy(soc);
  3797. qdf_spinlock_destroy(&soc->ast_lock);
  3798. dp_soc_mem_reset(soc);
  3799. }
  3800. /**
  3801. * dp_soc_deinit_wifi3() - Deinitialize txrx SOC
  3802. * @txrx_soc: Opaque DP SOC handle
  3803. *
  3804. * Return: None
  3805. */
  3806. static void dp_soc_deinit_wifi3(struct cdp_soc_t *txrx_soc)
  3807. {
  3808. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3809. soc->dp_soc_reinit = 1;
  3810. dp_soc_deinit(txrx_soc);
  3811. }
  3812. /*
  3813. * dp_soc_detach() - Detach rest of txrx SOC
  3814. * @txrx_soc: DP SOC handle, struct cdp_soc_t is first element of struct dp_soc.
  3815. *
  3816. * Return: None
  3817. */
  3818. static void dp_soc_detach(struct cdp_soc_t *txrx_soc)
  3819. {
  3820. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3821. int i;
  3822. qdf_atomic_set(&soc->cmn_init_done, 0);
  3823. /* TBD: Call Tx and Rx cleanup functions to free buffers and
  3824. * SW descriptors
  3825. */
  3826. for (i = 0; i < MAX_PDEV_CNT; i++) {
  3827. if (soc->pdev_list[i])
  3828. dp_pdev_detach((struct cdp_pdev *)
  3829. soc->pdev_list[i], 1);
  3830. }
  3831. /* Free the ring memories */
  3832. /* Common rings */
  3833. qdf_minidump_remove(soc->wbm_desc_rel_ring.base_vaddr_unaligned);
  3834. dp_srng_cleanup(soc, &soc->wbm_desc_rel_ring, SW2WBM_RELEASE, 0);
  3835. if (dp_is_soc_reinit(soc)) {
  3836. dp_tx_soc_detach(soc);
  3837. }
  3838. /* Tx data rings */
  3839. if (!wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3840. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  3841. dp_srng_cleanup(soc, &soc->tcl_data_ring[i],
  3842. TCL_DATA, i);
  3843. dp_srng_cleanup(soc, &soc->tx_comp_ring[i],
  3844. WBM2SW_RELEASE, i);
  3845. }
  3846. }
  3847. /* TCL command and status rings */
  3848. dp_srng_cleanup(soc, &soc->tcl_cmd_ring, TCL_CMD, 0);
  3849. dp_srng_cleanup(soc, &soc->tcl_status_ring, TCL_STATUS, 0);
  3850. /* Rx data rings */
  3851. if (!wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  3852. soc->num_reo_dest_rings =
  3853. wlan_cfg_num_reo_dest_rings(soc->wlan_cfg_ctx);
  3854. for (i = 0; i < soc->num_reo_dest_rings; i++) {
  3855. /* TODO: Get number of rings and ring sizes
  3856. * from wlan_cfg
  3857. */
  3858. dp_srng_cleanup(soc, &soc->reo_dest_ring[i],
  3859. REO_DST, i);
  3860. }
  3861. }
  3862. /* REO reinjection ring */
  3863. dp_srng_cleanup(soc, &soc->reo_reinject_ring, REO_REINJECT, 0);
  3864. /* Rx release ring */
  3865. dp_srng_cleanup(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 0);
  3866. dp_srng_cleanup(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 3);
  3867. /* Rx exception ring */
  3868. /* TODO: Better to store ring_type and ring_num in
  3869. * dp_srng during setup
  3870. */
  3871. dp_srng_cleanup(soc, &soc->reo_exception_ring, REO_EXCEPTION, 0);
  3872. /* REO command and status rings */
  3873. dp_srng_cleanup(soc, &soc->reo_cmd_ring, REO_CMD, 0);
  3874. dp_srng_cleanup(soc, &soc->reo_status_ring, REO_STATUS, 0);
  3875. dp_hw_link_desc_pool_cleanup(soc);
  3876. htt_soc_detach(soc->htt_handle);
  3877. soc->dp_soc_reinit = 0;
  3878. wlan_cfg_soc_detach(soc->wlan_cfg_ctx);
  3879. qdf_minidump_remove(soc);
  3880. qdf_mem_free(soc);
  3881. }
  3882. /*
  3883. * dp_soc_detach_wifi3() - Detach txrx SOC
  3884. * @txrx_soc: DP SOC handle, struct cdp_soc_t is first element of struct dp_soc.
  3885. *
  3886. * Return: None
  3887. */
  3888. static void dp_soc_detach_wifi3(struct cdp_soc_t *txrx_soc)
  3889. {
  3890. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3891. if (dp_is_soc_reinit(soc)) {
  3892. dp_soc_detach(txrx_soc);
  3893. } else {
  3894. dp_soc_deinit(txrx_soc);
  3895. dp_soc_detach(txrx_soc);
  3896. }
  3897. }
  3898. #if !defined(DISABLE_MON_CONFIG)
  3899. /**
  3900. * dp_mon_htt_srng_setup() - Prepare HTT messages for Monitor rings
  3901. * @soc: soc handle
  3902. * @pdev: physical device handle
  3903. * @mac_id: ring number
  3904. * @mac_for_pdev: mac_id
  3905. *
  3906. * Return: non-zero for failure, zero for success
  3907. */
  3908. static QDF_STATUS dp_mon_htt_srng_setup(struct dp_soc *soc,
  3909. struct dp_pdev *pdev,
  3910. int mac_id,
  3911. int mac_for_pdev)
  3912. {
  3913. QDF_STATUS status = QDF_STATUS_SUCCESS;
  3914. if (soc->wlan_cfg_ctx->rxdma1_enable) {
  3915. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3916. soc->rxdma_mon_buf_ring[mac_id]
  3917. .hal_srng,
  3918. RXDMA_MONITOR_BUF);
  3919. if (status != QDF_STATUS_SUCCESS) {
  3920. dp_err("Failed to send htt srng setup message for Rxdma mon buf ring");
  3921. return status;
  3922. }
  3923. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3924. soc->rxdma_mon_dst_ring[mac_id]
  3925. .hal_srng,
  3926. RXDMA_MONITOR_DST);
  3927. if (status != QDF_STATUS_SUCCESS) {
  3928. dp_err("Failed to send htt srng setup message for Rxdma mon dst ring");
  3929. return status;
  3930. }
  3931. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3932. soc->rxdma_mon_status_ring[mac_id]
  3933. .hal_srng,
  3934. RXDMA_MONITOR_STATUS);
  3935. if (status != QDF_STATUS_SUCCESS) {
  3936. dp_err("Failed to send htt srng setup message for Rxdma mon status ring");
  3937. return status;
  3938. }
  3939. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3940. soc->rxdma_mon_desc_ring[mac_id]
  3941. .hal_srng,
  3942. RXDMA_MONITOR_DESC);
  3943. if (status != QDF_STATUS_SUCCESS) {
  3944. dp_err("Failed to send htt srng message for Rxdma mon desc ring");
  3945. return status;
  3946. }
  3947. } else {
  3948. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3949. soc->rxdma_mon_status_ring[mac_id]
  3950. .hal_srng,
  3951. RXDMA_MONITOR_STATUS);
  3952. if (status != QDF_STATUS_SUCCESS) {
  3953. dp_err("Failed to send htt srng setup message for Rxdma mon status ring");
  3954. return status;
  3955. }
  3956. }
  3957. return status;
  3958. }
  3959. #else
  3960. static QDF_STATUS dp_mon_htt_srng_setup(struct dp_soc *soc,
  3961. struct dp_pdev *pdev,
  3962. int mac_id,
  3963. int mac_for_pdev)
  3964. {
  3965. return QDF_STATUS_SUCCESS;
  3966. }
  3967. #endif
  3968. /*
  3969. * dp_rxdma_ring_config() - configure the RX DMA rings
  3970. *
  3971. * This function is used to configure the MAC rings.
  3972. * On MCL host provides buffers in Host2FW ring
  3973. * FW refills (copies) buffers to the ring and updates
  3974. * ring_idx in register
  3975. *
  3976. * @soc: data path SoC handle
  3977. *
  3978. * Return: zero on success, non-zero on failure
  3979. */
  3980. #ifdef QCA_HOST2FW_RXBUF_RING
  3981. static QDF_STATUS dp_rxdma_ring_config(struct dp_soc *soc)
  3982. {
  3983. int i;
  3984. QDF_STATUS status = QDF_STATUS_SUCCESS;
  3985. for (i = 0; i < MAX_PDEV_CNT; i++) {
  3986. struct dp_pdev *pdev = soc->pdev_list[i];
  3987. if (pdev) {
  3988. int mac_id;
  3989. bool dbs_enable = 0;
  3990. int max_mac_rings =
  3991. wlan_cfg_get_num_mac_rings
  3992. (pdev->wlan_cfg_ctx);
  3993. int lmac_id = dp_get_lmac_id_for_pdev_id(soc, 0, i);
  3994. htt_srng_setup(soc->htt_handle, 0,
  3995. soc->rx_refill_buf_ring[lmac_id]
  3996. .hal_srng,
  3997. RXDMA_BUF);
  3998. if (pdev->rx_refill_buf_ring2.hal_srng)
  3999. htt_srng_setup(soc->htt_handle, 0,
  4000. pdev->rx_refill_buf_ring2.hal_srng,
  4001. RXDMA_BUF);
  4002. if (soc->cdp_soc.ol_ops->
  4003. is_hw_dbs_2x2_capable) {
  4004. dbs_enable = soc->cdp_soc.ol_ops->
  4005. is_hw_dbs_2x2_capable(
  4006. (void *)soc->ctrl_psoc);
  4007. }
  4008. if (dbs_enable) {
  4009. QDF_TRACE(QDF_MODULE_ID_TXRX,
  4010. QDF_TRACE_LEVEL_ERROR,
  4011. FL("DBS enabled max_mac_rings %d"),
  4012. max_mac_rings);
  4013. } else {
  4014. max_mac_rings = 1;
  4015. QDF_TRACE(QDF_MODULE_ID_TXRX,
  4016. QDF_TRACE_LEVEL_ERROR,
  4017. FL("DBS disabled, max_mac_rings %d"),
  4018. max_mac_rings);
  4019. }
  4020. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  4021. FL("pdev_id %d max_mac_rings %d"),
  4022. pdev->pdev_id, max_mac_rings);
  4023. for (mac_id = 0; mac_id < max_mac_rings; mac_id++) {
  4024. int mac_for_pdev =
  4025. dp_get_mac_id_for_pdev(mac_id,
  4026. pdev->pdev_id);
  4027. /*
  4028. * Obtain lmac id from pdev to access the LMAC
  4029. * ring in soc context
  4030. */
  4031. lmac_id =
  4032. dp_get_lmac_id_for_pdev_id(soc,
  4033. mac_id,
  4034. pdev->pdev_id);
  4035. QDF_TRACE(QDF_MODULE_ID_TXRX,
  4036. QDF_TRACE_LEVEL_ERROR,
  4037. FL("mac_id %d"), mac_for_pdev);
  4038. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4039. pdev->rx_mac_buf_ring[mac_id]
  4040. .hal_srng,
  4041. RXDMA_BUF);
  4042. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4043. soc->rxdma_err_dst_ring[lmac_id]
  4044. .hal_srng,
  4045. RXDMA_DST);
  4046. /* Configure monitor mode rings */
  4047. status = dp_mon_htt_srng_setup(soc, pdev,
  4048. lmac_id,
  4049. mac_for_pdev);
  4050. if (status != QDF_STATUS_SUCCESS) {
  4051. dp_err("Failed to send htt monitor messages to target");
  4052. return status;
  4053. }
  4054. }
  4055. }
  4056. }
  4057. /*
  4058. * Timer to reap rxdma status rings.
  4059. * Needed until we enable ppdu end interrupts
  4060. */
  4061. qdf_timer_init(soc->osdev, &soc->mon_reap_timer,
  4062. dp_service_mon_rings, (void *)soc,
  4063. QDF_TIMER_TYPE_WAKE_APPS);
  4064. soc->reap_timer_init = 1;
  4065. return status;
  4066. }
  4067. #else
  4068. /* This is only for WIN */
  4069. static QDF_STATUS dp_rxdma_ring_config(struct dp_soc *soc)
  4070. {
  4071. int i;
  4072. QDF_STATUS status = QDF_STATUS_SUCCESS;
  4073. int mac_for_pdev;
  4074. int lmac_id;
  4075. for (i = 0; i < MAX_PDEV_CNT; i++) {
  4076. struct dp_pdev *pdev = soc->pdev_list[i];
  4077. if (!pdev)
  4078. continue;
  4079. mac_for_pdev = i;
  4080. lmac_id = dp_get_lmac_id_for_pdev_id(soc, 0, i);
  4081. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4082. soc->rx_refill_buf_ring[lmac_id].
  4083. hal_srng, RXDMA_BUF);
  4084. #ifndef DISABLE_MON_CONFIG
  4085. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4086. soc->rxdma_mon_buf_ring[lmac_id].hal_srng,
  4087. RXDMA_MONITOR_BUF);
  4088. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4089. soc->rxdma_mon_dst_ring[lmac_id].hal_srng,
  4090. RXDMA_MONITOR_DST);
  4091. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4092. soc->rxdma_mon_status_ring[lmac_id].hal_srng,
  4093. RXDMA_MONITOR_STATUS);
  4094. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4095. soc->rxdma_mon_desc_ring[lmac_id].hal_srng,
  4096. RXDMA_MONITOR_DESC);
  4097. #endif
  4098. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4099. soc->rxdma_err_dst_ring[lmac_id].hal_srng,
  4100. RXDMA_DST);
  4101. }
  4102. /* Configure LMAC rings in Polled mode */
  4103. if (soc->lmac_polled_mode) {
  4104. /*
  4105. * Timer to reap lmac rings.
  4106. */
  4107. qdf_timer_init(soc->osdev, &soc->lmac_reap_timer,
  4108. dp_service_lmac_rings, (void *)soc,
  4109. QDF_TIMER_TYPE_WAKE_APPS);
  4110. soc->lmac_timer_init = 1;
  4111. qdf_timer_mod(&soc->lmac_reap_timer, DP_INTR_POLL_TIMER_MS);
  4112. }
  4113. return status;
  4114. }
  4115. #endif
  4116. #ifdef NO_RX_PKT_HDR_TLV
  4117. static QDF_STATUS
  4118. dp_rxdma_ring_sel_cfg(struct dp_soc *soc)
  4119. {
  4120. int i;
  4121. int mac_id;
  4122. struct htt_rx_ring_tlv_filter htt_tlv_filter = {0};
  4123. QDF_STATUS status = QDF_STATUS_SUCCESS;
  4124. htt_tlv_filter.mpdu_start = 1;
  4125. htt_tlv_filter.msdu_start = 1;
  4126. htt_tlv_filter.mpdu_end = 1;
  4127. htt_tlv_filter.msdu_end = 1;
  4128. htt_tlv_filter.attention = 1;
  4129. htt_tlv_filter.packet = 1;
  4130. htt_tlv_filter.packet_header = 0;
  4131. htt_tlv_filter.ppdu_start = 0;
  4132. htt_tlv_filter.ppdu_end = 0;
  4133. htt_tlv_filter.ppdu_end_user_stats = 0;
  4134. htt_tlv_filter.ppdu_end_user_stats_ext = 0;
  4135. htt_tlv_filter.ppdu_end_status_done = 0;
  4136. htt_tlv_filter.enable_fp = 1;
  4137. htt_tlv_filter.enable_md = 0;
  4138. htt_tlv_filter.enable_md = 0;
  4139. htt_tlv_filter.enable_mo = 0;
  4140. htt_tlv_filter.fp_mgmt_filter = 0;
  4141. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_BA_REQ;
  4142. htt_tlv_filter.fp_data_filter = (FILTER_DATA_UCAST |
  4143. FILTER_DATA_MCAST |
  4144. FILTER_DATA_DATA);
  4145. htt_tlv_filter.mo_mgmt_filter = 0;
  4146. htt_tlv_filter.mo_ctrl_filter = 0;
  4147. htt_tlv_filter.mo_data_filter = 0;
  4148. htt_tlv_filter.md_data_filter = 0;
  4149. htt_tlv_filter.offset_valid = true;
  4150. htt_tlv_filter.rx_packet_offset = RX_PKT_TLVS_LEN;
  4151. /*Not subscribing rx_pkt_header*/
  4152. htt_tlv_filter.rx_header_offset = 0;
  4153. htt_tlv_filter.rx_mpdu_start_offset =
  4154. HAL_RX_PKT_TLV_MPDU_START_OFFSET(soc->hal_soc);
  4155. htt_tlv_filter.rx_mpdu_end_offset =
  4156. HAL_RX_PKT_TLV_MPDU_END_OFFSET(soc->hal_soc);
  4157. htt_tlv_filter.rx_msdu_start_offset =
  4158. HAL_RX_PKT_TLV_MSDU_START_OFFSET(soc->hal_soc);
  4159. htt_tlv_filter.rx_msdu_end_offset =
  4160. HAL_RX_PKT_TLV_MSDU_END_OFFSET(soc->hal_soc);
  4161. htt_tlv_filter.rx_attn_offset =
  4162. HAL_RX_PKT_TLV_ATTN_OFFSET(soc->hal_soc);
  4163. for (i = 0; i < MAX_PDEV_CNT; i++) {
  4164. struct dp_pdev *pdev = soc->pdev_list[i];
  4165. if (!pdev)
  4166. continue;
  4167. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  4168. int mac_for_pdev =
  4169. dp_get_mac_id_for_pdev(mac_id, pdev->pdev_id);
  4170. /*
  4171. * Obtain lmac id from pdev to access the LMAC ring
  4172. * in soc context
  4173. */
  4174. int lmac_id =
  4175. dp_get_lmac_id_for_pdev_id(soc, mac_id,
  4176. pdev->pdev_id);
  4177. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  4178. soc->rx_refill_buf_ring[lmac_id].
  4179. hal_srng,
  4180. RXDMA_BUF, RX_DATA_BUFFER_SIZE,
  4181. &htt_tlv_filter);
  4182. }
  4183. }
  4184. return status;
  4185. }
  4186. #else
  4187. static QDF_STATUS
  4188. dp_rxdma_ring_sel_cfg(struct dp_soc *soc)
  4189. {
  4190. return QDF_STATUS_SUCCESS;
  4191. }
  4192. #endif
  4193. /*
  4194. * dp_rx_target_fst_config() - configure the RXOLE Flow Search Engine
  4195. *
  4196. * This function is used to configure the FSE HW block in RX OLE on a
  4197. * per pdev basis. Here, we will be programming parameters related to
  4198. * the Flow Search Table.
  4199. *
  4200. * @soc: data path SoC handle
  4201. *
  4202. * Return: zero on success, non-zero on failure
  4203. */
  4204. #ifdef WLAN_SUPPORT_RX_FLOW_TAG
  4205. static QDF_STATUS
  4206. dp_rx_target_fst_config(struct dp_soc *soc)
  4207. {
  4208. int i;
  4209. QDF_STATUS status = QDF_STATUS_SUCCESS;
  4210. for (i = 0; i < MAX_PDEV_CNT; i++) {
  4211. struct dp_pdev *pdev = soc->pdev_list[i];
  4212. /* Flow search is not enabled if NSS offload is enabled */
  4213. if (pdev &&
  4214. !wlan_cfg_get_dp_pdev_nss_enabled(pdev->wlan_cfg_ctx)) {
  4215. status = dp_rx_flow_send_fst_fw_setup(pdev->soc, pdev);
  4216. if (status != QDF_STATUS_SUCCESS)
  4217. break;
  4218. }
  4219. }
  4220. return status;
  4221. }
  4222. #else
  4223. /**
  4224. * dp_rx_target_fst_config() - Configure RX OLE FSE engine in HW
  4225. * @soc: SoC handle
  4226. *
  4227. * Return: Success
  4228. */
  4229. static inline QDF_STATUS
  4230. dp_rx_target_fst_config(struct dp_soc *soc)
  4231. {
  4232. return QDF_STATUS_SUCCESS;
  4233. }
  4234. #endif /* WLAN_SUPPORT_RX_FLOW_TAG */
  4235. /*
  4236. * dp_soc_attach_target_wifi3() - SOC initialization in the target
  4237. * @cdp_soc: Opaque Datapath SOC handle
  4238. *
  4239. * Return: zero on success, non-zero on failure
  4240. */
  4241. static QDF_STATUS
  4242. dp_soc_attach_target_wifi3(struct cdp_soc_t *cdp_soc)
  4243. {
  4244. struct dp_soc *soc = (struct dp_soc *)cdp_soc;
  4245. QDF_STATUS status = QDF_STATUS_SUCCESS;
  4246. htt_soc_attach_target(soc->htt_handle);
  4247. status = dp_rxdma_ring_config(soc);
  4248. if (status != QDF_STATUS_SUCCESS) {
  4249. dp_err("Failed to send htt srng setup messages to target");
  4250. return status;
  4251. }
  4252. status = dp_rxdma_ring_sel_cfg(soc);
  4253. if (status != QDF_STATUS_SUCCESS) {
  4254. dp_err("Failed to send htt ring config message to target");
  4255. return status;
  4256. }
  4257. status = dp_rx_target_fst_config(soc);
  4258. if (status != QDF_STATUS_SUCCESS) {
  4259. dp_err("Failed to send htt fst setup config message to target");
  4260. return status;
  4261. }
  4262. DP_STATS_INIT(soc);
  4263. /* initialize work queue for stats processing */
  4264. qdf_create_work(0, &soc->htt_stats.work, htt_t2h_stats_handler, soc);
  4265. qdf_minidump_log(soc, sizeof(*soc), "dp_soc");
  4266. return QDF_STATUS_SUCCESS;
  4267. }
  4268. /*
  4269. * dp_vdev_attach_wifi3() - attach txrx vdev
  4270. * @txrx_pdev: Datapath PDEV handle
  4271. * @vdev_mac_addr: MAC address of the virtual interface
  4272. * @vdev_id: VDEV Id
  4273. * @wlan_op_mode: VDEV operating mode
  4274. * @subtype: VDEV operating subtype
  4275. *
  4276. * Return: status
  4277. */
  4278. static QDF_STATUS dp_vdev_attach_wifi3(struct cdp_soc_t *cdp_soc,
  4279. uint8_t pdev_id,
  4280. uint8_t *vdev_mac_addr,
  4281. uint8_t vdev_id,
  4282. enum wlan_op_mode op_mode,
  4283. enum wlan_op_subtype subtype)
  4284. {
  4285. struct dp_soc *soc = (struct dp_soc *)cdp_soc;
  4286. struct dp_pdev *pdev =
  4287. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  4288. pdev_id);
  4289. struct dp_vdev *vdev = qdf_mem_malloc(sizeof(*vdev));
  4290. if (!pdev) {
  4291. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  4292. FL("DP PDEV is Null for pdev id %d"), pdev_id);
  4293. qdf_mem_free(vdev);
  4294. goto fail0;
  4295. }
  4296. if (!vdev) {
  4297. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  4298. FL("DP VDEV memory allocation failed"));
  4299. goto fail0;
  4300. }
  4301. vdev->pdev = pdev;
  4302. vdev->vdev_id = vdev_id;
  4303. vdev->opmode = op_mode;
  4304. vdev->subtype = subtype;
  4305. vdev->osdev = soc->osdev;
  4306. vdev->osif_rx = NULL;
  4307. vdev->osif_rsim_rx_decap = NULL;
  4308. vdev->osif_get_key = NULL;
  4309. vdev->osif_rx_mon = NULL;
  4310. vdev->osif_tx_free_ext = NULL;
  4311. vdev->osif_vdev = NULL;
  4312. vdev->delete.pending = 0;
  4313. vdev->safemode = 0;
  4314. vdev->drop_unenc = 1;
  4315. vdev->sec_type = cdp_sec_type_none;
  4316. vdev->multipass_en = false;
  4317. #ifdef notyet
  4318. vdev->filters_num = 0;
  4319. #endif
  4320. qdf_mem_copy(
  4321. &vdev->mac_addr.raw[0], vdev_mac_addr, QDF_MAC_ADDR_SIZE);
  4322. /* TODO: Initialize default HTT meta data that will be used in
  4323. * TCL descriptors for packets transmitted from this VDEV
  4324. */
  4325. TAILQ_INIT(&vdev->peer_list);
  4326. dp_peer_multipass_list_init(vdev);
  4327. if ((soc->intr_mode == DP_INTR_POLL) &&
  4328. wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx) != 0) {
  4329. if ((pdev->vdev_count == 0) ||
  4330. (wlan_op_mode_monitor == vdev->opmode))
  4331. qdf_timer_mod(&soc->int_timer, DP_INTR_POLL_TIMER_MS);
  4332. }
  4333. soc->vdev_id_map[vdev_id] = vdev;
  4334. if (wlan_op_mode_monitor == vdev->opmode) {
  4335. pdev->monitor_vdev = vdev;
  4336. return QDF_STATUS_SUCCESS;
  4337. }
  4338. vdev->tx_encap_type = wlan_cfg_pkt_type(soc->wlan_cfg_ctx);
  4339. vdev->rx_decap_type = wlan_cfg_pkt_type(soc->wlan_cfg_ctx);
  4340. vdev->dscp_tid_map_id = 0;
  4341. vdev->mcast_enhancement_en = 0;
  4342. vdev->raw_mode_war = wlan_cfg_get_raw_mode_war(soc->wlan_cfg_ctx);
  4343. vdev->prev_tx_enq_tstamp = 0;
  4344. vdev->prev_rx_deliver_tstamp = 0;
  4345. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  4346. /* add this vdev into the pdev's list */
  4347. TAILQ_INSERT_TAIL(&pdev->vdev_list, vdev, vdev_list_elem);
  4348. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  4349. pdev->vdev_count++;
  4350. if (wlan_op_mode_sta != vdev->opmode)
  4351. vdev->ap_bridge_enabled = true;
  4352. else
  4353. vdev->ap_bridge_enabled = false;
  4354. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  4355. "%s: wlan_cfg_ap_bridge_enabled %d",
  4356. __func__, vdev->ap_bridge_enabled);
  4357. dp_tx_vdev_attach(vdev);
  4358. if (pdev->vdev_count == 1)
  4359. dp_lro_hash_setup(soc, pdev);
  4360. dp_info("Created vdev %pK (%pM)", vdev, vdev->mac_addr.raw);
  4361. DP_STATS_INIT(vdev);
  4362. if (wlan_op_mode_sta == vdev->opmode)
  4363. dp_peer_create_wifi3((struct cdp_soc_t *)soc, vdev_id,
  4364. vdev->mac_addr.raw);
  4365. return QDF_STATUS_SUCCESS;
  4366. fail0:
  4367. return QDF_STATUS_E_FAILURE;
  4368. }
  4369. /**
  4370. * dp_vdev_register_wifi3() - Register VDEV operations from osif layer
  4371. * @soc: Datapath soc handle
  4372. * @vdev_id: id of Datapath VDEV handle
  4373. * @osif_vdev: OSIF vdev handle
  4374. * @txrx_ops: Tx and Rx operations
  4375. *
  4376. * Return: DP VDEV handle on success, NULL on failure
  4377. */
  4378. static QDF_STATUS dp_vdev_register_wifi3(struct cdp_soc_t *soc,
  4379. uint8_t vdev_id,
  4380. ol_osif_vdev_handle osif_vdev,
  4381. struct ol_txrx_ops *txrx_ops)
  4382. {
  4383. struct dp_vdev *vdev =
  4384. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  4385. vdev_id);
  4386. if (!vdev)
  4387. return QDF_STATUS_E_FAILURE;
  4388. vdev->osif_vdev = osif_vdev;
  4389. vdev->osif_rx = txrx_ops->rx.rx;
  4390. vdev->osif_rx_stack = txrx_ops->rx.rx_stack;
  4391. vdev->osif_rx_flush = txrx_ops->rx.rx_flush;
  4392. vdev->osif_gro_flush = txrx_ops->rx.rx_gro_flush;
  4393. vdev->osif_rsim_rx_decap = txrx_ops->rx.rsim_rx_decap;
  4394. vdev->osif_get_key = txrx_ops->get_key;
  4395. vdev->osif_rx_mon = txrx_ops->rx.mon;
  4396. vdev->osif_tx_free_ext = txrx_ops->tx.tx_free_ext;
  4397. vdev->tx_comp = txrx_ops->tx.tx_comp;
  4398. #ifdef notyet
  4399. #if ATH_SUPPORT_WAPI
  4400. vdev->osif_check_wai = txrx_ops->rx.wai_check;
  4401. #endif
  4402. #endif
  4403. #ifdef UMAC_SUPPORT_PROXY_ARP
  4404. vdev->osif_proxy_arp = txrx_ops->proxy_arp;
  4405. #endif
  4406. vdev->me_convert = txrx_ops->me_convert;
  4407. /* TODO: Enable the following once Tx code is integrated */
  4408. if (vdev->mesh_vdev)
  4409. txrx_ops->tx.tx = dp_tx_send_mesh;
  4410. else
  4411. txrx_ops->tx.tx = dp_tx_send;
  4412. txrx_ops->tx.tx_exception = dp_tx_send_exception;
  4413. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
  4414. "DP Vdev Register success");
  4415. return QDF_STATUS_SUCCESS;
  4416. }
  4417. /**
  4418. * dp_peer_flush_ast_entry() - Forcibily flush all AST entry of peer
  4419. * @soc: Datapath soc handle
  4420. * @peer: Datapath peer handle
  4421. * @peer_id: Peer ID
  4422. * @vdev_id: Vdev ID
  4423. *
  4424. * Return: void
  4425. */
  4426. static void dp_peer_flush_ast_entry(struct dp_soc *soc,
  4427. struct dp_peer *peer,
  4428. uint16_t peer_id,
  4429. uint8_t vdev_id)
  4430. {
  4431. struct dp_ast_entry *ase, *tmp_ase;
  4432. if (soc->is_peer_map_unmap_v2) {
  4433. DP_PEER_ITERATE_ASE_LIST(peer, ase, tmp_ase) {
  4434. dp_rx_peer_unmap_handler
  4435. (soc, peer_id,
  4436. vdev_id,
  4437. ase->mac_addr.raw,
  4438. 1);
  4439. }
  4440. }
  4441. }
  4442. /**
  4443. * dp_vdev_flush_peers() - Forcibily Flush peers of vdev
  4444. * @vdev: Datapath VDEV handle
  4445. * @unmap_only: Flag to indicate "only unmap"
  4446. *
  4447. * Return: void
  4448. */
  4449. static void dp_vdev_flush_peers(struct cdp_vdev *vdev_handle, bool unmap_only)
  4450. {
  4451. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  4452. struct dp_pdev *pdev = vdev->pdev;
  4453. struct dp_soc *soc = pdev->soc;
  4454. struct dp_peer *peer;
  4455. uint16_t *peer_ids;
  4456. struct dp_peer **peer_array = NULL;
  4457. uint8_t i = 0, j = 0;
  4458. uint8_t m = 0, n = 0;
  4459. peer_ids = qdf_mem_malloc(soc->max_peers * sizeof(peer_ids[0]));
  4460. if (!peer_ids) {
  4461. dp_err("DP alloc failure - unable to flush peers");
  4462. return;
  4463. }
  4464. if (!unmap_only) {
  4465. peer_array = qdf_mem_malloc(
  4466. soc->max_peers * sizeof(struct dp_peer *));
  4467. if (!peer_array) {
  4468. qdf_mem_free(peer_ids);
  4469. dp_err("DP alloc failure - unable to flush peers");
  4470. return;
  4471. }
  4472. }
  4473. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  4474. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  4475. if (!unmap_only && n < soc->max_peers)
  4476. peer_array[n++] = peer;
  4477. for (i = 0; i < MAX_NUM_PEER_ID_PER_PEER; i++)
  4478. if (peer->peer_ids[i] != HTT_INVALID_PEER)
  4479. if (j < soc->max_peers)
  4480. peer_ids[j++] = peer->peer_ids[i];
  4481. }
  4482. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  4483. /*
  4484. * If peer id is invalid, need to flush the peer if
  4485. * peer valid flag is true, this is needed for NAN + SSR case.
  4486. */
  4487. if (!unmap_only) {
  4488. for (m = 0; m < n ; m++) {
  4489. peer = peer_array[m];
  4490. dp_info("peer: %pM is getting deleted",
  4491. peer->mac_addr.raw);
  4492. /* only if peer valid is true */
  4493. if (peer->valid)
  4494. dp_peer_delete_wifi3((struct cdp_soc_t *)soc,
  4495. vdev->vdev_id,
  4496. peer->mac_addr.raw, 0);
  4497. }
  4498. qdf_mem_free(peer_array);
  4499. }
  4500. for (i = 0; i < j ; i++) {
  4501. peer = __dp_peer_find_by_id(soc, peer_ids[i]);
  4502. if (!peer)
  4503. continue;
  4504. dp_info("peer: %pM is getting unmap",
  4505. peer->mac_addr.raw);
  4506. /* free AST entries of peer */
  4507. dp_peer_flush_ast_entry(soc, peer,
  4508. peer_ids[i],
  4509. vdev->vdev_id);
  4510. dp_rx_peer_unmap_handler(soc, peer_ids[i],
  4511. vdev->vdev_id,
  4512. peer->mac_addr.raw, 0);
  4513. }
  4514. qdf_mem_free(peer_ids);
  4515. dp_info("Flushed peers for vdev object %pK ", vdev);
  4516. }
  4517. /*
  4518. * dp_vdev_detach_wifi3() - Detach txrx vdev
  4519. * @cdp_soc: Datapath soc handle
  4520. * @vdev_id: VDEV Id
  4521. * @callback: Callback OL_IF on completion of detach
  4522. * @cb_context: Callback context
  4523. *
  4524. */
  4525. static QDF_STATUS dp_vdev_detach_wifi3(struct cdp_soc_t *cdp_soc,
  4526. uint8_t vdev_id,
  4527. ol_txrx_vdev_delete_cb callback,
  4528. void *cb_context)
  4529. {
  4530. struct dp_soc *soc = (struct dp_soc *)cdp_soc;
  4531. struct dp_pdev *pdev;
  4532. struct dp_neighbour_peer *peer = NULL;
  4533. struct dp_neighbour_peer *temp_peer = NULL;
  4534. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  4535. if (!vdev)
  4536. return QDF_STATUS_E_FAILURE;
  4537. pdev = vdev->pdev;
  4538. soc->vdev_id_map[vdev->vdev_id] = NULL;
  4539. if (wlan_op_mode_sta == vdev->opmode)
  4540. dp_peer_delete_wifi3((struct cdp_soc_t *)soc, vdev->vdev_id,
  4541. vdev->vap_self_peer->mac_addr.raw, 0);
  4542. /*
  4543. * If Target is hung, flush all peers before detaching vdev
  4544. * this will free all references held due to missing
  4545. * unmap commands from Target
  4546. */
  4547. if (!hif_is_target_ready(HIF_GET_SOFTC(soc->hif_handle)))
  4548. dp_vdev_flush_peers((struct cdp_vdev *)vdev, false);
  4549. else if (hif_get_target_status(soc->hif_handle) == TARGET_STATUS_RESET)
  4550. dp_vdev_flush_peers((struct cdp_vdev *)vdev, true);
  4551. /*
  4552. * Use peer_ref_mutex while accessing peer_list, in case
  4553. * a peer is in the process of being removed from the list.
  4554. */
  4555. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  4556. /* check that the vdev has no peers allocated */
  4557. if (!TAILQ_EMPTY(&vdev->peer_list)) {
  4558. /* debug print - will be removed later */
  4559. dp_warn("not deleting vdev object %pK (%pM) until deletion finishes for all its peers",
  4560. vdev, vdev->mac_addr.raw);
  4561. if (vdev->vdev_dp_ext_handle) {
  4562. qdf_mem_free(vdev->vdev_dp_ext_handle);
  4563. vdev->vdev_dp_ext_handle = NULL;
  4564. }
  4565. /* indicate that the vdev needs to be deleted */
  4566. vdev->delete.pending = 1;
  4567. vdev->delete.callback = callback;
  4568. vdev->delete.context = cb_context;
  4569. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  4570. return QDF_STATUS_E_FAILURE;
  4571. }
  4572. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  4573. if (wlan_op_mode_monitor == vdev->opmode)
  4574. goto free_vdev;
  4575. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  4576. if (!soc->hw_nac_monitor_support) {
  4577. TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
  4578. neighbour_peer_list_elem) {
  4579. QDF_ASSERT(peer->vdev != vdev);
  4580. }
  4581. } else {
  4582. TAILQ_FOREACH_SAFE(peer, &pdev->neighbour_peers_list,
  4583. neighbour_peer_list_elem, temp_peer) {
  4584. if (peer->vdev == vdev) {
  4585. TAILQ_REMOVE(&pdev->neighbour_peers_list, peer,
  4586. neighbour_peer_list_elem);
  4587. qdf_mem_free(peer);
  4588. }
  4589. }
  4590. }
  4591. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  4592. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  4593. /* remove the vdev from its parent pdev's list */
  4594. TAILQ_REMOVE(&pdev->vdev_list, vdev, vdev_list_elem);
  4595. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  4596. dp_tx_vdev_detach(vdev);
  4597. dp_rx_vdev_detach(vdev);
  4598. free_vdev:
  4599. if (wlan_op_mode_monitor == vdev->opmode)
  4600. pdev->monitor_vdev = NULL;
  4601. if (vdev->vdev_dp_ext_handle) {
  4602. qdf_mem_free(vdev->vdev_dp_ext_handle);
  4603. vdev->vdev_dp_ext_handle = NULL;
  4604. }
  4605. dp_info("deleting vdev object %pK (%pM)", vdev, vdev->mac_addr.raw);
  4606. qdf_mem_free(vdev);
  4607. if (callback)
  4608. callback(cb_context);
  4609. return QDF_STATUS_SUCCESS;
  4610. }
  4611. #ifdef FEATURE_AST
  4612. /*
  4613. * dp_peer_delete_ast_entries(): Delete all AST entries for a peer
  4614. * @soc - datapath soc handle
  4615. * @peer - datapath peer handle
  4616. *
  4617. * Delete the AST entries belonging to a peer
  4618. */
  4619. static inline void dp_peer_delete_ast_entries(struct dp_soc *soc,
  4620. struct dp_peer *peer)
  4621. {
  4622. struct dp_ast_entry *ast_entry, *temp_ast_entry;
  4623. DP_PEER_ITERATE_ASE_LIST(peer, ast_entry, temp_ast_entry)
  4624. dp_peer_del_ast(soc, ast_entry);
  4625. peer->self_ast_entry = NULL;
  4626. }
  4627. #else
  4628. static inline void dp_peer_delete_ast_entries(struct dp_soc *soc,
  4629. struct dp_peer *peer)
  4630. {
  4631. }
  4632. #endif
  4633. #if ATH_SUPPORT_WRAP
  4634. static inline struct dp_peer *dp_peer_can_reuse(struct dp_vdev *vdev,
  4635. uint8_t *peer_mac_addr)
  4636. {
  4637. struct dp_peer *peer;
  4638. peer = dp_peer_find_hash_find(vdev->pdev->soc, peer_mac_addr,
  4639. 0, vdev->vdev_id);
  4640. if (!peer)
  4641. return NULL;
  4642. if (peer->bss_peer)
  4643. return peer;
  4644. dp_peer_unref_delete(peer);
  4645. return NULL;
  4646. }
  4647. #else
  4648. static inline struct dp_peer *dp_peer_can_reuse(struct dp_vdev *vdev,
  4649. uint8_t *peer_mac_addr)
  4650. {
  4651. struct dp_peer *peer;
  4652. peer = dp_peer_find_hash_find(vdev->pdev->soc, peer_mac_addr,
  4653. 0, vdev->vdev_id);
  4654. if (!peer)
  4655. return NULL;
  4656. if (peer->bss_peer && (peer->vdev->vdev_id == vdev->vdev_id))
  4657. return peer;
  4658. dp_peer_unref_delete(peer);
  4659. return NULL;
  4660. }
  4661. #endif
  4662. #ifdef FEATURE_AST
  4663. static inline void dp_peer_ast_handle_roam_del(struct dp_soc *soc,
  4664. struct dp_pdev *pdev,
  4665. uint8_t *peer_mac_addr)
  4666. {
  4667. struct dp_ast_entry *ast_entry;
  4668. qdf_spin_lock_bh(&soc->ast_lock);
  4669. if (soc->ast_override_support)
  4670. ast_entry = dp_peer_ast_hash_find_by_pdevid(soc, peer_mac_addr,
  4671. pdev->pdev_id);
  4672. else
  4673. ast_entry = dp_peer_ast_hash_find_soc(soc, peer_mac_addr);
  4674. if (ast_entry && ast_entry->next_hop && !ast_entry->delete_in_progress)
  4675. dp_peer_del_ast(soc, ast_entry);
  4676. qdf_spin_unlock_bh(&soc->ast_lock);
  4677. }
  4678. #endif
  4679. #ifdef PEER_CACHE_RX_PKTS
  4680. static inline void dp_peer_rx_bufq_resources_init(struct dp_peer *peer)
  4681. {
  4682. qdf_spinlock_create(&peer->bufq_info.bufq_lock);
  4683. peer->bufq_info.thresh = DP_RX_CACHED_BUFQ_THRESH;
  4684. qdf_list_create(&peer->bufq_info.cached_bufq, DP_RX_CACHED_BUFQ_THRESH);
  4685. }
  4686. #else
  4687. static inline void dp_peer_rx_bufq_resources_init(struct dp_peer *peer)
  4688. {
  4689. }
  4690. #endif
  4691. #ifdef WLAN_FEATURE_STATS_EXT
  4692. /*
  4693. * dp_set_ignore_reo_status_cb() - set ignore reo status cb flag
  4694. * @soc: dp soc handle
  4695. * @flag: flag to set or reset
  4696. *
  4697. * Return: None
  4698. */
  4699. static inline void dp_set_ignore_reo_status_cb(struct dp_soc *soc,
  4700. bool flag)
  4701. {
  4702. soc->ignore_reo_status_cb = flag;
  4703. }
  4704. #else
  4705. static inline void dp_set_ignore_reo_status_cb(struct dp_soc *soc,
  4706. bool flag)
  4707. {
  4708. }
  4709. #endif
  4710. /*
  4711. * dp_peer_create_wifi3() - attach txrx peer
  4712. * @soc_hdl: Datapath soc handle
  4713. * @vdev_id: id of vdev
  4714. * @peer_mac_addr: Peer MAC address
  4715. *
  4716. * Return: 0 on success, -1 on failure
  4717. */
  4718. static QDF_STATUS
  4719. dp_peer_create_wifi3(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  4720. uint8_t *peer_mac_addr)
  4721. {
  4722. struct dp_peer *peer;
  4723. int i;
  4724. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  4725. struct dp_pdev *pdev;
  4726. struct cdp_peer_cookie peer_cookie;
  4727. enum cdp_txrx_ast_entry_type ast_type = CDP_TXRX_AST_TYPE_STATIC;
  4728. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  4729. if (!vdev || !peer_mac_addr)
  4730. return QDF_STATUS_E_FAILURE;
  4731. pdev = vdev->pdev;
  4732. soc = pdev->soc;
  4733. /*
  4734. * If a peer entry with given MAC address already exists,
  4735. * reuse the peer and reset the state of peer.
  4736. */
  4737. peer = dp_peer_can_reuse(vdev, peer_mac_addr);
  4738. if (peer) {
  4739. qdf_atomic_init(&peer->is_default_route_set);
  4740. dp_peer_cleanup(vdev, peer, true);
  4741. qdf_spin_lock_bh(&soc->ast_lock);
  4742. dp_peer_delete_ast_entries(soc, peer);
  4743. peer->delete_in_progress = false;
  4744. qdf_spin_unlock_bh(&soc->ast_lock);
  4745. if ((vdev->opmode == wlan_op_mode_sta) &&
  4746. !qdf_mem_cmp(peer_mac_addr, &vdev->mac_addr.raw[0],
  4747. QDF_MAC_ADDR_SIZE)) {
  4748. ast_type = CDP_TXRX_AST_TYPE_SELF;
  4749. }
  4750. dp_peer_add_ast(soc, peer, peer_mac_addr, ast_type, 0);
  4751. /*
  4752. * Control path maintains a node count which is incremented
  4753. * for every new peer create command. Since new peer is not being
  4754. * created and earlier reference is reused here,
  4755. * peer_unref_delete event is sent to control path to
  4756. * increment the count back.
  4757. */
  4758. if (soc->cdp_soc.ol_ops->peer_unref_delete) {
  4759. soc->cdp_soc.ol_ops->peer_unref_delete(
  4760. soc->ctrl_psoc,
  4761. pdev->pdev_id,
  4762. peer->mac_addr.raw, vdev->mac_addr.raw,
  4763. vdev->opmode);
  4764. }
  4765. dp_local_peer_id_alloc(pdev, peer);
  4766. qdf_spinlock_create(&peer->peer_info_lock);
  4767. dp_peer_rx_bufq_resources_init(peer);
  4768. DP_STATS_INIT(peer);
  4769. DP_STATS_UPD(peer, rx.avg_rssi, INVALID_RSSI);
  4770. return QDF_STATUS_SUCCESS;
  4771. } else {
  4772. /*
  4773. * When a STA roams from RPTR AP to ROOT AP and vice versa, we
  4774. * need to remove the AST entry which was earlier added as a WDS
  4775. * entry.
  4776. * If an AST entry exists, but no peer entry exists with a given
  4777. * MAC addresses, we could deduce it as a WDS entry
  4778. */
  4779. dp_peer_ast_handle_roam_del(soc, pdev, peer_mac_addr);
  4780. }
  4781. #ifdef notyet
  4782. peer = (struct dp_peer *)qdf_mempool_alloc(soc->osdev,
  4783. soc->mempool_ol_ath_peer);
  4784. #else
  4785. peer = (struct dp_peer *)qdf_mem_malloc(sizeof(*peer));
  4786. #endif
  4787. if (!peer)
  4788. return QDF_STATUS_E_FAILURE; /* failure */
  4789. qdf_mem_zero(peer, sizeof(struct dp_peer));
  4790. TAILQ_INIT(&peer->ast_entry_list);
  4791. /* store provided params */
  4792. peer->vdev = vdev;
  4793. if ((vdev->opmode == wlan_op_mode_sta) &&
  4794. !qdf_mem_cmp(peer_mac_addr, &vdev->mac_addr.raw[0],
  4795. QDF_MAC_ADDR_SIZE)) {
  4796. ast_type = CDP_TXRX_AST_TYPE_SELF;
  4797. }
  4798. dp_peer_add_ast(soc, peer, peer_mac_addr, ast_type, 0);
  4799. qdf_spinlock_create(&peer->peer_info_lock);
  4800. dp_peer_rx_bufq_resources_init(peer);
  4801. qdf_mem_copy(
  4802. &peer->mac_addr.raw[0], peer_mac_addr, QDF_MAC_ADDR_SIZE);
  4803. /* initialize the peer_id */
  4804. for (i = 0; i < MAX_NUM_PEER_ID_PER_PEER; i++)
  4805. peer->peer_ids[i] = HTT_INVALID_PEER;
  4806. /* reset the ast index to flowid table */
  4807. dp_peer_reset_flowq_map(peer);
  4808. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  4809. qdf_atomic_init(&peer->ref_cnt);
  4810. /* keep one reference for attach */
  4811. qdf_atomic_inc(&peer->ref_cnt);
  4812. /* add this peer into the vdev's list */
  4813. if (wlan_op_mode_sta == vdev->opmode)
  4814. TAILQ_INSERT_HEAD(&vdev->peer_list, peer, peer_list_elem);
  4815. else
  4816. TAILQ_INSERT_TAIL(&vdev->peer_list, peer, peer_list_elem);
  4817. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  4818. /* TODO: See if hash based search is required */
  4819. dp_peer_find_hash_add(soc, peer);
  4820. /* Initialize the peer state */
  4821. peer->state = OL_TXRX_PEER_STATE_DISC;
  4822. dp_info("vdev %pK created peer %pK (%pM) ref_cnt: %d",
  4823. vdev, peer, peer->mac_addr.raw,
  4824. qdf_atomic_read(&peer->ref_cnt));
  4825. /*
  4826. * For every peer MAp message search and set if bss_peer
  4827. */
  4828. if (qdf_mem_cmp(peer->mac_addr.raw, vdev->mac_addr.raw,
  4829. QDF_MAC_ADDR_SIZE) == 0 &&
  4830. (wlan_op_mode_sta != vdev->opmode)) {
  4831. dp_info("vdev bss_peer!!");
  4832. peer->bss_peer = 1;
  4833. vdev->vap_bss_peer = peer;
  4834. }
  4835. if (wlan_op_mode_sta == vdev->opmode &&
  4836. qdf_mem_cmp(peer->mac_addr.raw, vdev->mac_addr.raw,
  4837. QDF_MAC_ADDR_SIZE) == 0) {
  4838. vdev->vap_self_peer = peer;
  4839. }
  4840. if (wlan_op_mode_sta == vdev->opmode &&
  4841. qdf_mem_cmp(peer->mac_addr.raw, vdev->mac_addr.raw,
  4842. QDF_MAC_ADDR_SIZE) != 0) {
  4843. dp_set_ignore_reo_status_cb(soc, false);
  4844. }
  4845. for (i = 0; i < DP_MAX_TIDS; i++)
  4846. qdf_spinlock_create(&peer->rx_tid[i].tid_lock);
  4847. peer->valid = 1;
  4848. dp_local_peer_id_alloc(pdev, peer);
  4849. DP_STATS_INIT(peer);
  4850. DP_STATS_UPD(peer, rx.avg_rssi, INVALID_RSSI);
  4851. qdf_mem_copy(peer_cookie.mac_addr, peer->mac_addr.raw,
  4852. QDF_MAC_ADDR_SIZE);
  4853. peer_cookie.ctx = NULL;
  4854. peer_cookie.pdev_id = pdev->pdev_id;
  4855. peer_cookie.cookie = pdev->next_peer_cookie++;
  4856. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  4857. dp_wdi_event_handler(WDI_EVENT_PEER_CREATE, pdev->soc,
  4858. (void *)&peer_cookie,
  4859. peer->peer_ids[0], WDI_NO_VAL, pdev->pdev_id);
  4860. #endif
  4861. if (soc->wlanstats_enabled) {
  4862. if (!peer_cookie.ctx) {
  4863. pdev->next_peer_cookie--;
  4864. qdf_err("Failed to initialize peer rate stats");
  4865. } else {
  4866. peer->wlanstats_ctx = (struct cdp_peer_rate_stats_ctx *)
  4867. peer_cookie.ctx;
  4868. }
  4869. }
  4870. return QDF_STATUS_SUCCESS;
  4871. }
  4872. /*
  4873. * dp_vdev_get_default_reo_hash() - get reo dest ring and hash values for a vdev
  4874. * @vdev: Datapath VDEV handle
  4875. * @reo_dest: pointer to default reo_dest ring for vdev to be populated
  4876. * @hash_based: pointer to hash value (enabled/disabled) to be populated
  4877. *
  4878. * Return: None
  4879. */
  4880. static
  4881. void dp_vdev_get_default_reo_hash(struct dp_vdev *vdev,
  4882. enum cdp_host_reo_dest_ring *reo_dest,
  4883. bool *hash_based)
  4884. {
  4885. struct dp_soc *soc;
  4886. struct dp_pdev *pdev;
  4887. pdev = vdev->pdev;
  4888. soc = pdev->soc;
  4889. /*
  4890. * hash based steering is disabled for Radios which are offloaded
  4891. * to NSS
  4892. */
  4893. if (!wlan_cfg_get_dp_pdev_nss_enabled(pdev->wlan_cfg_ctx))
  4894. *hash_based = wlan_cfg_is_rx_hash_enabled(soc->wlan_cfg_ctx);
  4895. /*
  4896. * Below line of code will ensure the proper reo_dest ring is chosen
  4897. * for cases where toeplitz hash cannot be generated (ex: non TCP/UDP)
  4898. */
  4899. *reo_dest = pdev->reo_dest;
  4900. }
  4901. #ifdef IPA_OFFLOAD
  4902. /**
  4903. * dp_is_vdev_subtype_p2p() - Check if the subtype for vdev is P2P
  4904. * @vdev: Virtual device
  4905. *
  4906. * Return: true if the vdev is of subtype P2P
  4907. * false if the vdev is of any other subtype
  4908. */
  4909. static inline bool dp_is_vdev_subtype_p2p(struct dp_vdev *vdev)
  4910. {
  4911. if (vdev->subtype == wlan_op_subtype_p2p_device ||
  4912. vdev->subtype == wlan_op_subtype_p2p_cli ||
  4913. vdev->subtype == wlan_op_subtype_p2p_go)
  4914. return true;
  4915. return false;
  4916. }
  4917. /*
  4918. * dp_peer_setup_get_reo_hash() - get reo dest ring and hash values for a peer
  4919. * @vdev: Datapath VDEV handle
  4920. * @reo_dest: pointer to default reo_dest ring for vdev to be populated
  4921. * @hash_based: pointer to hash value (enabled/disabled) to be populated
  4922. *
  4923. * If IPA is enabled in ini, for SAP mode, disable hash based
  4924. * steering, use default reo_dst ring for RX. Use config values for other modes.
  4925. * Return: None
  4926. */
  4927. static void dp_peer_setup_get_reo_hash(struct dp_vdev *vdev,
  4928. enum cdp_host_reo_dest_ring *reo_dest,
  4929. bool *hash_based)
  4930. {
  4931. struct dp_soc *soc;
  4932. struct dp_pdev *pdev;
  4933. pdev = vdev->pdev;
  4934. soc = pdev->soc;
  4935. dp_vdev_get_default_reo_hash(vdev, reo_dest, hash_based);
  4936. /* For P2P-GO interfaces we do not need to change the REO
  4937. * configuration even if IPA config is enabled
  4938. */
  4939. if (dp_is_vdev_subtype_p2p(vdev))
  4940. return;
  4941. /*
  4942. * If IPA is enabled, disable hash-based flow steering and set
  4943. * reo_dest_ring_4 as the REO ring to receive packets on.
  4944. * IPA is configured to reap reo_dest_ring_4.
  4945. *
  4946. * Note - REO DST indexes are from 0 - 3, while cdp_host_reo_dest_ring
  4947. * value enum value is from 1 - 4.
  4948. * Hence, *reo_dest = IPA_REO_DEST_RING_IDX + 1
  4949. */
  4950. if (wlan_cfg_is_ipa_enabled(soc->wlan_cfg_ctx)) {
  4951. if (vdev->opmode == wlan_op_mode_ap) {
  4952. *reo_dest = IPA_REO_DEST_RING_IDX + 1;
  4953. *hash_based = 0;
  4954. } else if (vdev->opmode == wlan_op_mode_sta &&
  4955. dp_ipa_is_mdm_platform()) {
  4956. *reo_dest = IPA_REO_DEST_RING_IDX + 1;
  4957. }
  4958. }
  4959. }
  4960. #else
  4961. /*
  4962. * dp_peer_setup_get_reo_hash() - get reo dest ring and hash values for a peer
  4963. * @vdev: Datapath VDEV handle
  4964. * @reo_dest: pointer to default reo_dest ring for vdev to be populated
  4965. * @hash_based: pointer to hash value (enabled/disabled) to be populated
  4966. *
  4967. * Use system config values for hash based steering.
  4968. * Return: None
  4969. */
  4970. static void dp_peer_setup_get_reo_hash(struct dp_vdev *vdev,
  4971. enum cdp_host_reo_dest_ring *reo_dest,
  4972. bool *hash_based)
  4973. {
  4974. dp_vdev_get_default_reo_hash(vdev, reo_dest, hash_based);
  4975. }
  4976. #endif /* IPA_OFFLOAD */
  4977. /*
  4978. * dp_peer_setup_wifi3() - initialize the peer
  4979. * @soc_hdl: soc handle object
  4980. * @vdev_id : vdev_id of vdev object
  4981. * @peer_mac: Peer's mac address
  4982. *
  4983. * Return: QDF_STATUS
  4984. */
  4985. static QDF_STATUS
  4986. dp_peer_setup_wifi3(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  4987. uint8_t *peer_mac)
  4988. {
  4989. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  4990. struct dp_pdev *pdev;
  4991. bool hash_based = 0;
  4992. enum cdp_host_reo_dest_ring reo_dest;
  4993. QDF_STATUS status = QDF_STATUS_SUCCESS;
  4994. struct dp_vdev *vdev =
  4995. dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  4996. struct dp_peer *peer =
  4997. dp_peer_find_hash_find(soc, peer_mac, 0, vdev_id);
  4998. if (!vdev || !peer || peer->delete_in_progress) {
  4999. status = QDF_STATUS_E_FAILURE;
  5000. goto fail;
  5001. }
  5002. pdev = vdev->pdev;
  5003. dp_peer_setup_get_reo_hash(vdev, &reo_dest, &hash_based);
  5004. dp_info("pdev: %d vdev :%d opmode:%u hash-based-steering:%d default-reo_dest:%u",
  5005. pdev->pdev_id, vdev->vdev_id,
  5006. vdev->opmode, hash_based, reo_dest);
  5007. /*
  5008. * There are corner cases where the AD1 = AD2 = "VAPs address"
  5009. * i.e both the devices have same MAC address. In these
  5010. * cases we want such pkts to be processed in NULL Q handler
  5011. * which is REO2TCL ring. for this reason we should
  5012. * not setup reo_queues and default route for bss_peer.
  5013. */
  5014. if (peer->bss_peer && vdev->opmode == wlan_op_mode_ap) {
  5015. status = QDF_STATUS_E_FAILURE;
  5016. goto fail;
  5017. }
  5018. if (soc->cdp_soc.ol_ops->peer_set_default_routing) {
  5019. /* TODO: Check the destination ring number to be passed to FW */
  5020. soc->cdp_soc.ol_ops->peer_set_default_routing(
  5021. soc->ctrl_psoc,
  5022. peer->vdev->pdev->pdev_id,
  5023. peer->mac_addr.raw,
  5024. peer->vdev->vdev_id, hash_based, reo_dest);
  5025. }
  5026. qdf_atomic_set(&peer->is_default_route_set, 1);
  5027. dp_peer_rx_init(pdev, peer);
  5028. dp_peer_tx_init(pdev, peer);
  5029. dp_peer_ppdu_delayed_ba_init(peer);
  5030. fail:
  5031. if (peer)
  5032. dp_peer_unref_delete(peer);
  5033. return status;
  5034. }
  5035. /*
  5036. * dp_cp_peer_del_resp_handler - Handle the peer delete response
  5037. * @soc_hdl: Datapath SOC handle
  5038. * @vdev_id: id of virtual device object
  5039. * @mac_addr: Mac address of the peer
  5040. *
  5041. * Return: QDF_STATUS
  5042. */
  5043. static QDF_STATUS dp_cp_peer_del_resp_handler(struct cdp_soc_t *soc_hdl,
  5044. uint8_t vdev_id,
  5045. uint8_t *mac_addr)
  5046. {
  5047. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  5048. struct dp_ast_entry *ast_entry = NULL;
  5049. txrx_ast_free_cb cb = NULL;
  5050. void *cookie;
  5051. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  5052. if (!vdev)
  5053. return QDF_STATUS_E_FAILURE;
  5054. qdf_spin_lock_bh(&soc->ast_lock);
  5055. if (soc->ast_override_support)
  5056. ast_entry =
  5057. dp_peer_ast_hash_find_by_pdevid(soc, mac_addr,
  5058. vdev->pdev->pdev_id);
  5059. else
  5060. ast_entry = dp_peer_ast_hash_find_soc(soc, mac_addr);
  5061. /* in case of qwrap we have multiple BSS peers
  5062. * with same mac address
  5063. *
  5064. * AST entry for this mac address will be created
  5065. * only for one peer hence it will be NULL here
  5066. */
  5067. if (!ast_entry || ast_entry->peer || !ast_entry->delete_in_progress) {
  5068. qdf_spin_unlock_bh(&soc->ast_lock);
  5069. return QDF_STATUS_E_FAILURE;
  5070. }
  5071. if (ast_entry->is_mapped)
  5072. soc->ast_table[ast_entry->ast_idx] = NULL;
  5073. DP_STATS_INC(soc, ast.deleted, 1);
  5074. dp_peer_ast_hash_remove(soc, ast_entry);
  5075. cb = ast_entry->callback;
  5076. cookie = ast_entry->cookie;
  5077. ast_entry->callback = NULL;
  5078. ast_entry->cookie = NULL;
  5079. soc->num_ast_entries--;
  5080. qdf_spin_unlock_bh(&soc->ast_lock);
  5081. if (cb) {
  5082. cb(soc->ctrl_psoc,
  5083. dp_soc_to_cdp_soc(soc),
  5084. cookie,
  5085. CDP_TXRX_AST_DELETED);
  5086. }
  5087. qdf_mem_free(ast_entry);
  5088. return QDF_STATUS_SUCCESS;
  5089. }
  5090. /*
  5091. * dp_set_ba_aging_timeout() - set ba aging timeout per AC
  5092. * @txrx_soc: cdp soc handle
  5093. * @ac: Access category
  5094. * @value: timeout value in millisec
  5095. *
  5096. * Return: void
  5097. */
  5098. static void dp_set_ba_aging_timeout(struct cdp_soc_t *txrx_soc,
  5099. uint8_t ac, uint32_t value)
  5100. {
  5101. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  5102. hal_set_ba_aging_timeout(soc->hal_soc, ac, value);
  5103. }
  5104. /*
  5105. * dp_get_ba_aging_timeout() - get ba aging timeout per AC
  5106. * @txrx_soc: cdp soc handle
  5107. * @ac: access category
  5108. * @value: timeout value in millisec
  5109. *
  5110. * Return: void
  5111. */
  5112. static void dp_get_ba_aging_timeout(struct cdp_soc_t *txrx_soc,
  5113. uint8_t ac, uint32_t *value)
  5114. {
  5115. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  5116. hal_get_ba_aging_timeout(soc->hal_soc, ac, value);
  5117. }
  5118. /*
  5119. * dp_set_pdev_reo_dest() - set the reo destination ring for this pdev
  5120. * @txrx_soc: cdp soc handle
  5121. * @pdev_id: id of physical device object
  5122. * @val: reo destination ring index (1 - 4)
  5123. *
  5124. * Return: QDF_STATUS
  5125. */
  5126. static QDF_STATUS
  5127. dp_set_pdev_reo_dest(struct cdp_soc_t *txrx_soc, uint8_t pdev_id,
  5128. enum cdp_host_reo_dest_ring val)
  5129. {
  5130. struct dp_pdev *pdev =
  5131. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)txrx_soc,
  5132. pdev_id);
  5133. if (pdev) {
  5134. pdev->reo_dest = val;
  5135. return QDF_STATUS_SUCCESS;
  5136. }
  5137. return QDF_STATUS_E_FAILURE;
  5138. }
  5139. /*
  5140. * dp_get_pdev_reo_dest() - get the reo destination for this pdev
  5141. * @txrx_soc: cdp soc handle
  5142. * @pdev_id: id of physical device object
  5143. *
  5144. * Return: reo destination ring index
  5145. */
  5146. static enum cdp_host_reo_dest_ring
  5147. dp_get_pdev_reo_dest(struct cdp_soc_t *txrx_soc, uint8_t pdev_id)
  5148. {
  5149. struct dp_pdev *pdev =
  5150. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)txrx_soc,
  5151. pdev_id);
  5152. if (pdev)
  5153. return pdev->reo_dest;
  5154. else
  5155. return cdp_host_reo_dest_ring_unknown;
  5156. }
  5157. /*
  5158. * dp_set_filter_neigh_peers() - set filter neighbour peers for smart mesh
  5159. * @pdev_handle: device object
  5160. * @val: value to be set
  5161. *
  5162. * Return: void
  5163. */
  5164. static int dp_set_filter_neigh_peers(struct dp_pdev *pdev,
  5165. bool val)
  5166. {
  5167. /* Enable/Disable smart mesh filtering. This flag will be checked
  5168. * during rx processing to check if packets are from NAC clients.
  5169. */
  5170. pdev->filter_neighbour_peers = val;
  5171. return 0;
  5172. }
  5173. /*
  5174. * dp_update_filter_neighbour_peers() - set neighbour peers(nac clients)
  5175. * address for smart mesh filtering
  5176. * @txrx_soc: cdp soc handle
  5177. * @vdev_id: id of virtual device object
  5178. * @cmd: Add/Del command
  5179. * @macaddr: nac client mac address
  5180. *
  5181. * Return: success/failure
  5182. */
  5183. static int dp_update_filter_neighbour_peers(struct cdp_soc_t *soc,
  5184. uint8_t vdev_id,
  5185. uint32_t cmd, uint8_t *macaddr)
  5186. {
  5187. struct dp_pdev *pdev;
  5188. struct dp_neighbour_peer *peer = NULL;
  5189. struct dp_vdev *vdev =
  5190. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  5191. vdev_id);
  5192. if (!vdev || !macaddr)
  5193. goto fail0;
  5194. pdev = vdev->pdev;
  5195. if (!pdev)
  5196. goto fail0;
  5197. /* Store address of NAC (neighbour peer) which will be checked
  5198. * against TA of received packets.
  5199. */
  5200. if (cmd == DP_NAC_PARAM_ADD) {
  5201. peer = (struct dp_neighbour_peer *) qdf_mem_malloc(
  5202. sizeof(*peer));
  5203. if (!peer) {
  5204. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  5205. FL("DP neighbour peer node memory allocation failed"));
  5206. goto fail0;
  5207. }
  5208. qdf_mem_copy(&peer->neighbour_peers_macaddr.raw[0],
  5209. macaddr, QDF_MAC_ADDR_SIZE);
  5210. peer->vdev = vdev;
  5211. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  5212. /* add this neighbour peer into the list */
  5213. TAILQ_INSERT_TAIL(&pdev->neighbour_peers_list, peer,
  5214. neighbour_peer_list_elem);
  5215. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  5216. /* first neighbour */
  5217. if (!pdev->neighbour_peers_added) {
  5218. pdev->neighbour_peers_added = true;
  5219. dp_ppdu_ring_cfg(pdev);
  5220. }
  5221. return 1;
  5222. } else if (cmd == DP_NAC_PARAM_DEL) {
  5223. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  5224. TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
  5225. neighbour_peer_list_elem) {
  5226. if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr.raw[0],
  5227. macaddr, QDF_MAC_ADDR_SIZE)) {
  5228. /* delete this peer from the list */
  5229. TAILQ_REMOVE(&pdev->neighbour_peers_list,
  5230. peer, neighbour_peer_list_elem);
  5231. qdf_mem_free(peer);
  5232. break;
  5233. }
  5234. }
  5235. /* last neighbour deleted */
  5236. if (TAILQ_EMPTY(&pdev->neighbour_peers_list)) {
  5237. pdev->neighbour_peers_added = false;
  5238. dp_ppdu_ring_cfg(pdev);
  5239. }
  5240. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  5241. if (!pdev->mcopy_mode && !pdev->neighbour_peers_added &&
  5242. !pdev->enhanced_stats_en)
  5243. dp_ppdu_ring_reset(pdev);
  5244. return 1;
  5245. }
  5246. fail0:
  5247. return 0;
  5248. }
  5249. /*
  5250. * dp_get_sec_type() - Get the security type
  5251. * @soc: soc handle
  5252. * @vdev_id: id of dp handle
  5253. * @peer_mac: mac of datapath PEER handle
  5254. * @sec_idx: Security id (mcast, ucast)
  5255. *
  5256. * return sec_type: Security type
  5257. */
  5258. static int dp_get_sec_type(struct cdp_soc_t *soc, uint8_t vdev_id,
  5259. uint8_t *peer_mac, uint8_t sec_idx)
  5260. {
  5261. int sec_type = 0;
  5262. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  5263. peer_mac, 0, vdev_id);
  5264. if (!peer || peer->delete_in_progress) {
  5265. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  5266. "%s: Peer is NULL!\n", __func__);
  5267. goto fail;
  5268. }
  5269. sec_type = peer->security[sec_idx].sec_type;
  5270. fail:
  5271. if (peer)
  5272. dp_peer_unref_delete(peer);
  5273. return sec_type;
  5274. }
  5275. /*
  5276. * dp_peer_authorize() - authorize txrx peer
  5277. * @soc: soc handle
  5278. * @vdev_id: id of dp handle
  5279. * @peer_mac: mac of datapath PEER handle
  5280. * @authorize
  5281. *
  5282. */
  5283. static QDF_STATUS
  5284. dp_peer_authorize(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  5285. uint8_t *peer_mac, uint32_t authorize)
  5286. {
  5287. QDF_STATUS status = QDF_STATUS_SUCCESS;
  5288. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  5289. struct dp_peer *peer = dp_peer_find_hash_find(soc,
  5290. peer_mac,
  5291. 0, vdev_id);
  5292. if (!peer || peer->delete_in_progress) {
  5293. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  5294. "%s: Peer is NULL!\n", __func__);
  5295. status = QDF_STATUS_E_FAILURE;
  5296. } else {
  5297. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  5298. peer->authorize = authorize ? 1 : 0;
  5299. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  5300. }
  5301. if (peer)
  5302. dp_peer_unref_delete(peer);
  5303. return status;
  5304. }
  5305. /*
  5306. * dp_vdev_reset_peer() - Update peer related member in vdev
  5307. as peer is going to free
  5308. * @vdev: datapath vdev handle
  5309. * @peer: dataptah peer handle
  5310. *
  5311. * Return: None
  5312. */
  5313. static void dp_vdev_reset_peer(struct dp_vdev *vdev,
  5314. struct dp_peer *peer)
  5315. {
  5316. struct dp_peer *bss_peer = NULL;
  5317. if (!vdev) {
  5318. dp_err("vdev is NULL");
  5319. } else {
  5320. if (vdev->vap_bss_peer == peer)
  5321. vdev->vap_bss_peer = NULL;
  5322. if (vdev && vdev->vap_bss_peer) {
  5323. bss_peer = vdev->vap_bss_peer;
  5324. DP_UPDATE_STATS(vdev, peer);
  5325. }
  5326. }
  5327. }
  5328. /*
  5329. * dp_peer_release_mem() - free dp peer handle memory
  5330. * @soc: dataptah soc handle
  5331. * @pdev: datapath pdev handle
  5332. * @peer: datapath peer handle
  5333. * @vdev_opmode: Vdev operation mode
  5334. * @vdev_mac_addr: Vdev Mac address
  5335. *
  5336. * Return: None
  5337. */
  5338. static void dp_peer_release_mem(struct dp_soc *soc,
  5339. struct dp_pdev *pdev,
  5340. struct dp_peer *peer,
  5341. enum wlan_op_mode vdev_opmode,
  5342. uint8_t *vdev_mac_addr)
  5343. {
  5344. if (soc->cdp_soc.ol_ops->peer_unref_delete)
  5345. soc->cdp_soc.ol_ops->peer_unref_delete(
  5346. soc->ctrl_psoc,
  5347. pdev->pdev_id,
  5348. peer->mac_addr.raw, vdev_mac_addr,
  5349. vdev_opmode);
  5350. /*
  5351. * Peer AST list hast to be empty here
  5352. */
  5353. DP_AST_ASSERT(TAILQ_EMPTY(&peer->ast_entry_list));
  5354. qdf_mem_free(peer);
  5355. }
  5356. /**
  5357. * dp_delete_pending_vdev() - check and process vdev delete
  5358. * @pdev: DP specific pdev pointer
  5359. * @vdev: DP specific vdev pointer
  5360. * @vdev_id: vdev id corresponding to vdev
  5361. *
  5362. * This API does following:
  5363. * 1) It releases tx flow pools buffers as vdev is
  5364. * going down and no peers are associated.
  5365. * 2) It also detaches vdev before cleaning vdev (struct dp_vdev) memory
  5366. */
  5367. static void dp_delete_pending_vdev(struct dp_pdev *pdev, struct dp_vdev *vdev,
  5368. uint8_t vdev_id)
  5369. {
  5370. ol_txrx_vdev_delete_cb vdev_delete_cb = NULL;
  5371. void *vdev_delete_context = NULL;
  5372. vdev_delete_cb = vdev->delete.callback;
  5373. vdev_delete_context = vdev->delete.context;
  5374. dp_info("deleting vdev object %pK (%pM)- its last peer is done",
  5375. vdev, vdev->mac_addr.raw);
  5376. /* all peers are gone, go ahead and delete it */
  5377. dp_tx_flow_pool_unmap_handler(pdev, vdev_id,
  5378. FLOW_TYPE_VDEV, vdev_id);
  5379. dp_tx_vdev_detach(vdev);
  5380. pdev->soc->vdev_id_map[vdev_id] = NULL;
  5381. if (wlan_op_mode_monitor == vdev->opmode) {
  5382. pdev->monitor_vdev = NULL;
  5383. } else {
  5384. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  5385. TAILQ_REMOVE(&pdev->vdev_list, vdev, vdev_list_elem);
  5386. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  5387. }
  5388. dp_info("deleting vdev object %pK (%pM)",
  5389. vdev, vdev->mac_addr.raw);
  5390. qdf_mem_free(vdev);
  5391. vdev = NULL;
  5392. if (vdev_delete_cb)
  5393. vdev_delete_cb(vdev_delete_context);
  5394. }
  5395. /*
  5396. * dp_peer_unref_delete() - unref and delete peer
  5397. * @peer_handle: Datapath peer handle
  5398. *
  5399. */
  5400. void dp_peer_unref_delete(struct dp_peer *peer)
  5401. {
  5402. struct dp_vdev *vdev = peer->vdev;
  5403. struct dp_pdev *pdev = vdev->pdev;
  5404. struct dp_soc *soc = pdev->soc;
  5405. struct dp_peer *tmppeer;
  5406. int found = 0;
  5407. uint16_t peer_id;
  5408. uint16_t vdev_id;
  5409. bool vdev_delete = false;
  5410. struct cdp_peer_cookie peer_cookie;
  5411. enum wlan_op_mode vdev_opmode;
  5412. uint8_t vdev_mac_addr[QDF_MAC_ADDR_SIZE];
  5413. struct dp_ast_entry *peer_ast_entry = NULL;
  5414. /*
  5415. * Hold the lock all the way from checking if the peer ref count
  5416. * is zero until the peer references are removed from the hash
  5417. * table and vdev list (if the peer ref count is zero).
  5418. * This protects against a new HL tx operation starting to use the
  5419. * peer object just after this function concludes it's done being used.
  5420. * Furthermore, the lock needs to be held while checking whether the
  5421. * vdev's list of peers is empty, to make sure that list is not modified
  5422. * concurrently with the empty check.
  5423. */
  5424. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  5425. if (qdf_atomic_dec_and_test(&peer->ref_cnt)) {
  5426. peer_id = peer->peer_ids[0];
  5427. vdev_id = vdev->vdev_id;
  5428. /*
  5429. * Make sure that the reference to the peer in
  5430. * peer object map is removed
  5431. */
  5432. if (peer_id != HTT_INVALID_PEER)
  5433. soc->peer_id_to_obj_map[peer_id] = NULL;
  5434. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  5435. "Deleting peer %pK (%pM)", peer, peer->mac_addr.raw);
  5436. /* remove the reference to the peer from the hash table */
  5437. dp_peer_find_hash_remove(soc, peer);
  5438. qdf_spin_lock_bh(&soc->ast_lock);
  5439. if (peer->self_ast_entry) {
  5440. peer_ast_entry = peer->self_ast_entry;
  5441. dp_peer_unlink_ast_entry(soc, peer_ast_entry);
  5442. dp_peer_free_ast_entry(soc, peer_ast_entry);
  5443. peer->self_ast_entry = NULL;
  5444. }
  5445. qdf_spin_unlock_bh(&soc->ast_lock);
  5446. TAILQ_FOREACH(tmppeer, &peer->vdev->peer_list, peer_list_elem) {
  5447. if (tmppeer == peer) {
  5448. found = 1;
  5449. break;
  5450. }
  5451. }
  5452. if (found) {
  5453. TAILQ_REMOVE(&peer->vdev->peer_list, peer,
  5454. peer_list_elem);
  5455. } else {
  5456. /*Ignoring the remove operation as peer not found*/
  5457. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  5458. "peer:%pK not found in vdev:%pK peerlist:%pK",
  5459. peer, vdev, &peer->vdev->peer_list);
  5460. }
  5461. /* send peer destroy event to upper layer */
  5462. qdf_mem_copy(peer_cookie.mac_addr, peer->mac_addr.raw,
  5463. QDF_MAC_ADDR_SIZE);
  5464. peer_cookie.ctx = NULL;
  5465. peer_cookie.ctx = (struct cdp_stats_cookie *)
  5466. peer->wlanstats_ctx;
  5467. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  5468. dp_wdi_event_handler(WDI_EVENT_PEER_DESTROY,
  5469. pdev->soc,
  5470. (void *)&peer_cookie,
  5471. peer->peer_ids[0],
  5472. WDI_NO_VAL,
  5473. pdev->pdev_id);
  5474. #endif
  5475. peer->wlanstats_ctx = NULL;
  5476. /* cleanup the peer data */
  5477. dp_peer_cleanup(vdev, peer, false);
  5478. /* reset this peer related info in vdev */
  5479. dp_vdev_reset_peer(vdev, peer);
  5480. /* save vdev related member in case vdev freed */
  5481. vdev_opmode = vdev->opmode;
  5482. qdf_mem_copy(vdev_mac_addr, vdev->mac_addr.raw,
  5483. QDF_MAC_ADDR_SIZE);
  5484. /*
  5485. * check whether the parent vdev is pending for deleting
  5486. * and no peers left.
  5487. */
  5488. if (vdev->delete.pending && TAILQ_EMPTY(&vdev->peer_list))
  5489. vdev_delete = true;
  5490. /*
  5491. * Now that there are no references to the peer, we can
  5492. * release the peer reference lock.
  5493. */
  5494. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  5495. /*
  5496. * Invoke soc.ol_ops->peer_unref_delete out of
  5497. * peer_ref_mutex in case deadlock issue.
  5498. */
  5499. dp_peer_release_mem(soc, pdev, peer,
  5500. vdev_opmode,
  5501. vdev_mac_addr);
  5502. /*
  5503. * Delete the vdev if it's waiting all peer deleted
  5504. * and it's chance now.
  5505. */
  5506. if (vdev_delete)
  5507. dp_delete_pending_vdev(pdev, vdev, vdev_id);
  5508. } else {
  5509. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  5510. }
  5511. }
  5512. #ifdef PEER_CACHE_RX_PKTS
  5513. static inline void dp_peer_rx_bufq_resources_deinit(struct dp_peer *peer)
  5514. {
  5515. dp_rx_flush_rx_cached(peer, true);
  5516. qdf_list_destroy(&peer->bufq_info.cached_bufq);
  5517. qdf_spinlock_destroy(&peer->bufq_info.bufq_lock);
  5518. }
  5519. #else
  5520. static inline void dp_peer_rx_bufq_resources_deinit(struct dp_peer *peer)
  5521. {
  5522. }
  5523. #endif
  5524. /*
  5525. * dp_peer_detach_wifi3() – Detach txrx peer
  5526. * @soc: soc handle
  5527. * @vdev_id: id of dp handle
  5528. * @peer_mac: mac of datapath PEER handle
  5529. * @bitmap: bitmap indicating special handling of request.
  5530. *
  5531. */
  5532. static QDF_STATUS dp_peer_delete_wifi3(struct cdp_soc_t *soc, uint8_t vdev_id,
  5533. uint8_t *peer_mac, uint32_t bitmap)
  5534. {
  5535. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  5536. peer_mac, 0, vdev_id);
  5537. /* Peer can be null for monitor vap mac address */
  5538. if (!peer) {
  5539. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  5540. "%s: Invalid peer\n", __func__);
  5541. return QDF_STATUS_E_FAILURE;
  5542. }
  5543. peer->valid = 0;
  5544. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  5545. FL("peer %pK (%pM)"), peer, peer->mac_addr.raw);
  5546. dp_local_peer_id_free(peer->vdev->pdev, peer);
  5547. dp_peer_rx_bufq_resources_deinit(peer);
  5548. qdf_spinlock_destroy(&peer->peer_info_lock);
  5549. dp_peer_multipass_list_remove(peer);
  5550. if (wlan_op_mode_sta == peer->vdev->opmode &&
  5551. qdf_mem_cmp(peer->mac_addr.raw, peer->vdev->mac_addr.raw,
  5552. QDF_MAC_ADDR_SIZE) != 0) {
  5553. dp_set_ignore_reo_status_cb(peer->vdev->pdev->soc, true);
  5554. }
  5555. /*
  5556. * Remove the reference added during peer_attach.
  5557. * The peer will still be left allocated until the
  5558. * PEER_UNMAP message arrives to remove the other
  5559. * reference, added by the PEER_MAP message.
  5560. */
  5561. dp_peer_unref_delete(peer);
  5562. /*
  5563. * Remove the reference taken above
  5564. */
  5565. dp_peer_unref_delete(peer);
  5566. return QDF_STATUS_SUCCESS;
  5567. }
  5568. /*
  5569. * dp_get_vdev_mac_addr_wifi3() – Detach txrx peer
  5570. * @soc_hdl: Datapath soc handle
  5571. * @vdev_id: virtual interface id
  5572. *
  5573. * Return: MAC address on success, NULL on failure.
  5574. *
  5575. */
  5576. static uint8 *dp_get_vdev_mac_addr_wifi3(struct cdp_soc_t *soc_hdl,
  5577. uint8_t vdev_id)
  5578. {
  5579. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  5580. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  5581. if (!vdev)
  5582. return NULL;
  5583. return vdev->mac_addr.raw;
  5584. }
  5585. /*
  5586. * dp_vdev_set_wds() - Enable per packet stats
  5587. * @soc: DP soc handle
  5588. * @vdev_id: id of DP VDEV handle
  5589. * @val: value
  5590. *
  5591. * Return: none
  5592. */
  5593. static int dp_vdev_set_wds(struct cdp_soc_t *soc, uint8_t vdev_id, uint32_t val)
  5594. {
  5595. struct dp_vdev *vdev =
  5596. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  5597. vdev_id);
  5598. if (!vdev)
  5599. return QDF_STATUS_E_FAILURE;
  5600. vdev->wds_enabled = val;
  5601. return QDF_STATUS_SUCCESS;
  5602. }
  5603. /*
  5604. * dp_get_mon_vdev_from_pdev_wifi3() - Get vdev id of monitor mode
  5605. * @soc_hdl: datapath soc handle
  5606. * @pdev_id: physical device instance id
  5607. *
  5608. * Return: virtual interface id
  5609. */
  5610. static uint8_t dp_get_mon_vdev_from_pdev_wifi3(struct cdp_soc_t *soc_hdl,
  5611. uint8_t pdev_id)
  5612. {
  5613. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  5614. struct dp_pdev *pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  5615. if (qdf_unlikely(!pdev))
  5616. return -EINVAL;
  5617. return pdev->monitor_vdev->vdev_id;
  5618. }
  5619. static int dp_get_opmode(struct cdp_soc_t *soc_hdl, uint8_t vdev_id)
  5620. {
  5621. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  5622. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  5623. if (!vdev) {
  5624. dp_err("vdev for id %d is NULL", vdev_id);
  5625. return -EINVAL;
  5626. }
  5627. return vdev->opmode;
  5628. }
  5629. /**
  5630. * dp_get_os_rx_handles_from_vdev_wifi3() - Get os rx handles for a vdev
  5631. * @soc_hdl: ol_txrx_soc_handle handle
  5632. * @vdev_id: vdev id for which os rx handles are needed
  5633. * @stack_fn_p: pointer to stack function pointer
  5634. * @osif_handle_p: pointer to ol_osif_vdev_handle
  5635. *
  5636. * Return: void
  5637. */
  5638. static
  5639. void dp_get_os_rx_handles_from_vdev_wifi3(struct cdp_soc_t *soc_hdl,
  5640. uint8_t vdev_id,
  5641. ol_txrx_rx_fp *stack_fn_p,
  5642. ol_osif_vdev_handle *osif_vdev_p)
  5643. {
  5644. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  5645. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  5646. if (!vdev)
  5647. return;
  5648. *stack_fn_p = vdev->osif_rx_stack;
  5649. *osif_vdev_p = vdev->osif_vdev;
  5650. }
  5651. /**
  5652. * dp_get_ctrl_pdev_from_vdev() - Get control pdev of vdev
  5653. * @soc_hdl: datapath soc handle
  5654. * @vdev_id: virtual device/interface id
  5655. *
  5656. * Return: Handle to control pdev
  5657. */
  5658. static struct cdp_cfg *dp_get_ctrl_pdev_from_vdev_wifi3(
  5659. struct cdp_soc_t *soc_hdl,
  5660. uint8_t vdev_id)
  5661. {
  5662. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  5663. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  5664. struct dp_pdev *pdev;
  5665. if (!vdev || !vdev->pdev)
  5666. return NULL;
  5667. pdev = vdev->pdev;
  5668. return (struct cdp_cfg *)pdev->wlan_cfg_ctx;
  5669. }
  5670. /**
  5671. * dp_monitor_mode_ring_config() - Send the tlv config to fw for monitor buffer
  5672. * ring based on target
  5673. * @soc: soc handle
  5674. * @mac_for_pdev: WIN- pdev_id, MCL- mac id
  5675. * @pdev: physical device handle
  5676. * @ring_num: mac id
  5677. * @htt_tlv_filter: tlv filter
  5678. *
  5679. * Return: zero on success, non-zero on failure
  5680. */
  5681. static inline
  5682. QDF_STATUS dp_monitor_mode_ring_config(struct dp_soc *soc, uint8_t mac_for_pdev,
  5683. struct dp_pdev *pdev, uint8_t ring_num,
  5684. struct htt_rx_ring_tlv_filter htt_tlv_filter)
  5685. {
  5686. QDF_STATUS status;
  5687. if (soc->wlan_cfg_ctx->rxdma1_enable)
  5688. status = htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  5689. soc->rxdma_mon_buf_ring[ring_num]
  5690. .hal_srng,
  5691. RXDMA_MONITOR_BUF,
  5692. RX_MONITOR_BUFFER_SIZE,
  5693. &htt_tlv_filter);
  5694. else
  5695. status = htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  5696. pdev->rx_mac_buf_ring[ring_num]
  5697. .hal_srng,
  5698. RXDMA_BUF, RX_DATA_BUFFER_SIZE,
  5699. &htt_tlv_filter);
  5700. return status;
  5701. }
  5702. static inline void
  5703. dp_pdev_disable_mcopy_code(struct dp_pdev *pdev)
  5704. {
  5705. pdev->mcopy_mode = 0;
  5706. qdf_nbuf_queue_free(&pdev->rx_ppdu_buf_q);
  5707. }
  5708. /**
  5709. * dp_reset_monitor_mode() - Disable monitor mode
  5710. * @soc_hdl: Datapath soc handle
  5711. * @pdev_id: id of datapath PDEV handle
  5712. *
  5713. * Return: QDF_STATUS
  5714. */
  5715. QDF_STATUS dp_reset_monitor_mode(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  5716. {
  5717. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  5718. struct htt_rx_ring_tlv_filter htt_tlv_filter;
  5719. int mac_id;
  5720. QDF_STATUS status = QDF_STATUS_SUCCESS;
  5721. struct dp_pdev *pdev =
  5722. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  5723. pdev_id);
  5724. if (!pdev)
  5725. return QDF_STATUS_E_FAILURE;
  5726. qdf_spin_lock_bh(&pdev->mon_lock);
  5727. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  5728. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  5729. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  5730. /*
  5731. * Obtain lmac id from pdev to access the ring in soc
  5732. * context
  5733. */
  5734. int lmac_id = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  5735. status = dp_monitor_mode_ring_config(soc, mac_for_pdev,
  5736. pdev, lmac_id,
  5737. htt_tlv_filter);
  5738. if (status != QDF_STATUS_SUCCESS) {
  5739. dp_err("Failed to send tlv filter for monitor mode rings");
  5740. qdf_spin_unlock_bh(&pdev->mon_lock);
  5741. return status;
  5742. }
  5743. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  5744. soc->rxdma_mon_status_ring[lmac_id]
  5745. .hal_srng,
  5746. RXDMA_MONITOR_STATUS, RX_DATA_BUFFER_SIZE,
  5747. &htt_tlv_filter);
  5748. }
  5749. pdev->monitor_vdev = NULL;
  5750. if (pdev->mcopy_mode)
  5751. dp_pdev_disable_mcopy_code(pdev);
  5752. pdev->monitor_configured = false;
  5753. qdf_spin_unlock_bh(&pdev->mon_lock);
  5754. return QDF_STATUS_SUCCESS;
  5755. }
  5756. /**
  5757. * dp_get_tx_pending() - read pending tx
  5758. * @pdev_handle: Datapath PDEV handle
  5759. *
  5760. * Return: outstanding tx
  5761. */
  5762. static uint32_t dp_get_tx_pending(struct cdp_pdev *pdev_handle)
  5763. {
  5764. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  5765. return qdf_atomic_read(&pdev->num_tx_outstanding);
  5766. }
  5767. /**
  5768. * dp_get_peer_mac_from_peer_id() - get peer mac
  5769. * @pdev_handle: Datapath PDEV handle
  5770. * @peer_id: Peer ID
  5771. * @peer_mac: MAC addr of PEER
  5772. *
  5773. * Return: QDF_STATUS
  5774. */
  5775. static QDF_STATUS dp_get_peer_mac_from_peer_id(struct cdp_soc_t *soc,
  5776. uint32_t peer_id,
  5777. uint8_t *peer_mac)
  5778. {
  5779. struct dp_peer *peer;
  5780. if (soc && peer_mac) {
  5781. peer = dp_peer_find_by_id((struct dp_soc *)soc,
  5782. (uint16_t)peer_id);
  5783. if (peer) {
  5784. qdf_mem_copy(peer_mac, peer->mac_addr.raw,
  5785. QDF_MAC_ADDR_SIZE);
  5786. dp_peer_unref_del_find_by_id(peer);
  5787. return QDF_STATUS_SUCCESS;
  5788. }
  5789. }
  5790. return QDF_STATUS_E_FAILURE;
  5791. }
  5792. /**
  5793. * dp_pdev_configure_monitor_rings() - configure monitor rings
  5794. * @vdev_handle: Datapath VDEV handle
  5795. *
  5796. * Return: QDF_STATUS
  5797. */
  5798. QDF_STATUS dp_pdev_configure_monitor_rings(struct dp_pdev *pdev)
  5799. {
  5800. struct htt_rx_ring_tlv_filter htt_tlv_filter;
  5801. struct dp_soc *soc;
  5802. uint8_t pdev_id;
  5803. int mac_id;
  5804. QDF_STATUS status = QDF_STATUS_SUCCESS;
  5805. pdev_id = pdev->pdev_id;
  5806. soc = pdev->soc;
  5807. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  5808. "MODE[%x] FP[%02x|%02x|%02x] MO[%02x|%02x|%02x]",
  5809. pdev->mon_filter_mode, pdev->fp_mgmt_filter,
  5810. pdev->fp_ctrl_filter, pdev->fp_data_filter,
  5811. pdev->mo_mgmt_filter, pdev->mo_ctrl_filter,
  5812. pdev->mo_data_filter);
  5813. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  5814. htt_tlv_filter.mpdu_start = 1;
  5815. htt_tlv_filter.msdu_start = 1;
  5816. htt_tlv_filter.packet = 1;
  5817. htt_tlv_filter.msdu_end = 1;
  5818. htt_tlv_filter.mpdu_end = 1;
  5819. htt_tlv_filter.packet_header = 1;
  5820. htt_tlv_filter.attention = 1;
  5821. htt_tlv_filter.ppdu_start = 0;
  5822. htt_tlv_filter.ppdu_end = 0;
  5823. htt_tlv_filter.ppdu_end_user_stats = 0;
  5824. htt_tlv_filter.ppdu_end_user_stats_ext = 0;
  5825. htt_tlv_filter.ppdu_end_status_done = 0;
  5826. htt_tlv_filter.header_per_msdu = 1;
  5827. htt_tlv_filter.enable_fp =
  5828. (pdev->mon_filter_mode & MON_FILTER_PASS) ? 1 : 0;
  5829. htt_tlv_filter.enable_md = 0;
  5830. htt_tlv_filter.enable_mo =
  5831. (pdev->mon_filter_mode & MON_FILTER_OTHER) ? 1 : 0;
  5832. htt_tlv_filter.fp_mgmt_filter = pdev->fp_mgmt_filter;
  5833. htt_tlv_filter.fp_ctrl_filter = pdev->fp_ctrl_filter;
  5834. if (pdev->mcopy_mode) {
  5835. htt_tlv_filter.fp_data_filter = 0;
  5836. htt_tlv_filter.mo_data_filter = 0;
  5837. } else {
  5838. htt_tlv_filter.fp_data_filter = pdev->fp_data_filter;
  5839. htt_tlv_filter.mo_data_filter = pdev->mo_data_filter;
  5840. }
  5841. htt_tlv_filter.mo_mgmt_filter = pdev->mo_mgmt_filter;
  5842. htt_tlv_filter.mo_ctrl_filter = pdev->mo_ctrl_filter;
  5843. htt_tlv_filter.offset_valid = false;
  5844. if ((pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU) ||
  5845. (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU_MSDU)) {
  5846. htt_tlv_filter.fp_mgmt_filter = 0;
  5847. htt_tlv_filter.fp_ctrl_filter = 0;
  5848. htt_tlv_filter.fp_data_filter = 0;
  5849. htt_tlv_filter.mo_mgmt_filter = 0;
  5850. htt_tlv_filter.mo_ctrl_filter = 0;
  5851. htt_tlv_filter.mo_data_filter = 0;
  5852. }
  5853. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  5854. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  5855. /*
  5856. * Obtain lmac id from pdev to access the LMAC ring in soc
  5857. * context
  5858. */
  5859. int lmac_id = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  5860. status = dp_monitor_mode_ring_config(soc, mac_for_pdev,
  5861. pdev, lmac_id,
  5862. htt_tlv_filter);
  5863. if (status != QDF_STATUS_SUCCESS) {
  5864. dp_err("Failed to send tlv filter for monitor mode rings");
  5865. return status;
  5866. }
  5867. }
  5868. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  5869. htt_tlv_filter.mpdu_start = 1;
  5870. htt_tlv_filter.msdu_start = 0;
  5871. htt_tlv_filter.packet = 0;
  5872. htt_tlv_filter.msdu_end = 0;
  5873. htt_tlv_filter.mpdu_end = 0;
  5874. if ((pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU) ||
  5875. (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU_MSDU)) {
  5876. htt_tlv_filter.mpdu_end = 1;
  5877. }
  5878. htt_tlv_filter.attention = 0;
  5879. htt_tlv_filter.ppdu_start = 1;
  5880. htt_tlv_filter.ppdu_end = 1;
  5881. htt_tlv_filter.ppdu_end_user_stats = 1;
  5882. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  5883. htt_tlv_filter.ppdu_end_status_done = 1;
  5884. htt_tlv_filter.enable_fp = 1;
  5885. htt_tlv_filter.enable_md = 0;
  5886. htt_tlv_filter.enable_mo = 1;
  5887. if (pdev->mcopy_mode ||
  5888. (pdev->rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED)) {
  5889. htt_tlv_filter.packet_header = 1;
  5890. if (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU) {
  5891. htt_tlv_filter.header_per_msdu = 0;
  5892. htt_tlv_filter.enable_mo = 0;
  5893. } else if (pdev->rx_enh_capture_mode ==
  5894. CDP_RX_ENH_CAPTURE_MPDU_MSDU) {
  5895. bool is_rx_mon_proto_flow_tag_enabled =
  5896. wlan_cfg_is_rx_mon_protocol_flow_tag_enabled(
  5897. soc->wlan_cfg_ctx);
  5898. htt_tlv_filter.header_per_msdu = 1;
  5899. htt_tlv_filter.enable_mo = 0;
  5900. if (pdev->is_rx_enh_capture_trailer_enabled ||
  5901. is_rx_mon_proto_flow_tag_enabled)
  5902. htt_tlv_filter.msdu_end = 1;
  5903. }
  5904. }
  5905. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  5906. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  5907. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  5908. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  5909. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  5910. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  5911. htt_tlv_filter.offset_valid = false;
  5912. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  5913. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  5914. /*
  5915. * Obtain lmac id from pdev to access the LMAC ring in soc
  5916. * context
  5917. */
  5918. int lmac_id = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  5919. /*
  5920. * If two back to back HTT msg sending happened in
  5921. * short time, the second HTT msg source SRNG HP
  5922. * writing has chance to fail, this has been confirmed
  5923. * by HST HW.
  5924. * for monitor mode, here is the last HTT msg for sending.
  5925. * if the 2nd HTT msg for monitor status ring sending failed,
  5926. * HW won't provide anything into 2nd monitor status ring.
  5927. * as a WAR, add some delay before 2nd HTT msg start sending,
  5928. * > 2us is required per HST HW, delay 100 us for safe.
  5929. */
  5930. if (mac_id)
  5931. qdf_udelay(100);
  5932. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  5933. soc->rxdma_mon_status_ring[lmac_id]
  5934. .hal_srng,
  5935. RXDMA_MONITOR_STATUS,
  5936. RX_DATA_BUFFER_SIZE, &htt_tlv_filter);
  5937. }
  5938. return status;
  5939. }
  5940. /**
  5941. * dp_vdev_set_monitor_mode() - Set DP VDEV to monitor mode
  5942. * @vdev_handle: Datapath VDEV handle
  5943. * @smart_monitor: Flag to denote if its smart monitor mode
  5944. *
  5945. * Return: 0 on success, not 0 on failure
  5946. */
  5947. static QDF_STATUS dp_vdev_set_monitor_mode(struct cdp_soc_t *soc,
  5948. uint8_t vdev_id,
  5949. uint8_t special_monitor)
  5950. {
  5951. struct dp_pdev *pdev;
  5952. struct dp_vdev *vdev =
  5953. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  5954. vdev_id);
  5955. if (!vdev)
  5956. return QDF_STATUS_E_FAILURE;
  5957. pdev = vdev->pdev;
  5958. pdev->monitor_vdev = vdev;
  5959. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  5960. "pdev=%pK, pdev_id=%d, soc=%pK vdev=%pK\n",
  5961. pdev, pdev->pdev_id, pdev->soc, vdev);
  5962. /*
  5963. * do not configure monitor buf ring and filter for smart and
  5964. * lite monitor
  5965. * for smart monitor filters are added along with first NAC
  5966. * for lite monitor required configuration done through
  5967. * dp_set_pdev_param
  5968. */
  5969. if (special_monitor)
  5970. return QDF_STATUS_SUCCESS;
  5971. /*Check if current pdev's monitor_vdev exists */
  5972. if (pdev->monitor_configured) {
  5973. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  5974. "monitor vap already created vdev=%pK\n", vdev);
  5975. return QDF_STATUS_E_RESOURCES;
  5976. }
  5977. pdev->monitor_configured = true;
  5978. dp_mon_buf_delayed_replenish(pdev);
  5979. return dp_pdev_configure_monitor_rings(pdev);
  5980. }
  5981. /**
  5982. * dp_pdev_set_advance_monitor_filter() - Set DP PDEV monitor filter
  5983. * @soc: soc handle
  5984. * @pdev_id: id of Datapath PDEV handle
  5985. * @filter_val: Flag to select Filter for monitor mode
  5986. * Return: 0 on success, not 0 on failure
  5987. */
  5988. static QDF_STATUS
  5989. dp_pdev_set_advance_monitor_filter(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  5990. struct cdp_monitor_filter *filter_val)
  5991. {
  5992. /* Many monitor VAPs can exists in a system but only one can be up at
  5993. * anytime
  5994. */
  5995. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  5996. struct dp_vdev *vdev;
  5997. struct htt_rx_ring_tlv_filter htt_tlv_filter;
  5998. int mac_id;
  5999. QDF_STATUS status = QDF_STATUS_SUCCESS;
  6000. struct dp_pdev *pdev =
  6001. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  6002. pdev_id);
  6003. if (!pdev)
  6004. return QDF_STATUS_E_FAILURE;
  6005. vdev = pdev->monitor_vdev;
  6006. if (!vdev)
  6007. return QDF_STATUS_E_FAILURE;
  6008. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  6009. "pdev=%pK, pdev_id=%d, soc=%pK vdev=%pK",
  6010. pdev, pdev_id, soc, vdev);
  6011. /*Check if current pdev's monitor_vdev exists */
  6012. if (!pdev->monitor_vdev) {
  6013. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  6014. "vdev=%pK", vdev);
  6015. qdf_assert(vdev);
  6016. }
  6017. /* update filter mode, type in pdev structure */
  6018. pdev->mon_filter_mode = filter_val->mode;
  6019. pdev->fp_mgmt_filter = filter_val->fp_mgmt;
  6020. pdev->fp_ctrl_filter = filter_val->fp_ctrl;
  6021. pdev->fp_data_filter = filter_val->fp_data;
  6022. pdev->mo_mgmt_filter = filter_val->mo_mgmt;
  6023. pdev->mo_ctrl_filter = filter_val->mo_ctrl;
  6024. pdev->mo_data_filter = filter_val->mo_data;
  6025. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  6026. "MODE[%x] FP[%02x|%02x|%02x] MO[%02x|%02x|%02x]",
  6027. pdev->mon_filter_mode, pdev->fp_mgmt_filter,
  6028. pdev->fp_ctrl_filter, pdev->fp_data_filter,
  6029. pdev->mo_mgmt_filter, pdev->mo_ctrl_filter,
  6030. pdev->mo_data_filter);
  6031. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  6032. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  6033. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  6034. /*
  6035. * Obtain lmac id from pdev to access the LMAC ring in soc
  6036. * context
  6037. */
  6038. int lmac_id = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  6039. status = dp_monitor_mode_ring_config(soc, mac_for_pdev,
  6040. pdev, lmac_id,
  6041. htt_tlv_filter);
  6042. if (status != QDF_STATUS_SUCCESS) {
  6043. dp_err("Failed to send tlv filter for monitor mode rings");
  6044. return status;
  6045. }
  6046. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  6047. soc->rxdma_mon_status_ring[lmac_id].hal_srng,
  6048. RXDMA_MONITOR_STATUS, RX_DATA_BUFFER_SIZE,
  6049. &htt_tlv_filter);
  6050. }
  6051. htt_tlv_filter.mpdu_start = 1;
  6052. htt_tlv_filter.msdu_start = 1;
  6053. htt_tlv_filter.packet = 1;
  6054. htt_tlv_filter.msdu_end = 1;
  6055. htt_tlv_filter.mpdu_end = 1;
  6056. htt_tlv_filter.packet_header = 1;
  6057. htt_tlv_filter.attention = 1;
  6058. htt_tlv_filter.ppdu_start = 0;
  6059. htt_tlv_filter.ppdu_end = 0;
  6060. htt_tlv_filter.ppdu_end_user_stats = 0;
  6061. htt_tlv_filter.ppdu_end_user_stats_ext = 0;
  6062. htt_tlv_filter.ppdu_end_status_done = 0;
  6063. htt_tlv_filter.header_per_msdu = 1;
  6064. htt_tlv_filter.enable_fp =
  6065. (pdev->mon_filter_mode & MON_FILTER_PASS) ? 1 : 0;
  6066. htt_tlv_filter.enable_md = 0;
  6067. htt_tlv_filter.enable_mo =
  6068. (pdev->mon_filter_mode & MON_FILTER_OTHER) ? 1 : 0;
  6069. htt_tlv_filter.fp_mgmt_filter = pdev->fp_mgmt_filter;
  6070. htt_tlv_filter.fp_ctrl_filter = pdev->fp_ctrl_filter;
  6071. if (pdev->mcopy_mode)
  6072. htt_tlv_filter.fp_data_filter = 0;
  6073. else
  6074. htt_tlv_filter.fp_data_filter = pdev->fp_data_filter;
  6075. htt_tlv_filter.mo_mgmt_filter = pdev->mo_mgmt_filter;
  6076. htt_tlv_filter.mo_ctrl_filter = pdev->mo_ctrl_filter;
  6077. htt_tlv_filter.mo_data_filter = pdev->mo_data_filter;
  6078. htt_tlv_filter.offset_valid = false;
  6079. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  6080. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  6081. /*
  6082. * Obtain lmac id from pdev to access the LMAC ring in soc
  6083. * context
  6084. */
  6085. int lmac_id = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  6086. status = dp_monitor_mode_ring_config(soc, mac_for_pdev,
  6087. pdev, lmac_id,
  6088. htt_tlv_filter);
  6089. if (status != QDF_STATUS_SUCCESS) {
  6090. dp_err("Failed to send tlv filter for monitor mode rings");
  6091. return status;
  6092. }
  6093. }
  6094. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  6095. htt_tlv_filter.mpdu_start = 1;
  6096. htt_tlv_filter.msdu_start = 0;
  6097. htt_tlv_filter.packet = 0;
  6098. htt_tlv_filter.msdu_end = 0;
  6099. htt_tlv_filter.mpdu_end = 0;
  6100. htt_tlv_filter.attention = 0;
  6101. htt_tlv_filter.ppdu_start = 1;
  6102. htt_tlv_filter.ppdu_end = 1;
  6103. htt_tlv_filter.ppdu_end_user_stats = 1;
  6104. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  6105. htt_tlv_filter.ppdu_end_status_done = 1;
  6106. htt_tlv_filter.enable_fp = 1;
  6107. htt_tlv_filter.enable_md = 0;
  6108. htt_tlv_filter.enable_mo = 1;
  6109. if (pdev->mcopy_mode) {
  6110. htt_tlv_filter.packet_header = 1;
  6111. }
  6112. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  6113. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  6114. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  6115. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  6116. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  6117. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  6118. htt_tlv_filter.offset_valid = false;
  6119. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  6120. int mac_for_pdev =
  6121. dp_get_mac_id_for_pdev(mac_id,
  6122. pdev->pdev_id);
  6123. /*
  6124. * Obtain lmac id from pdev to access the LMAC ring in soc
  6125. * context
  6126. */
  6127. int lmac_id =
  6128. dp_get_lmac_id_for_pdev_id(soc,
  6129. mac_id, pdev->pdev_id);
  6130. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  6131. soc->rxdma_mon_status_ring[lmac_id].hal_srng,
  6132. RXDMA_MONITOR_STATUS, RX_DATA_BUFFER_SIZE,
  6133. &htt_tlv_filter);
  6134. }
  6135. return QDF_STATUS_SUCCESS;
  6136. }
  6137. /**
  6138. * dp_deliver_tx_mgmt() - Deliver mgmt frame for tx capture
  6139. * @cdp_soc : data path soc handle
  6140. * @pdev_id : pdev_id
  6141. * @nbuf: Management frame buffer
  6142. */
  6143. static QDF_STATUS
  6144. dp_deliver_tx_mgmt(struct cdp_soc_t *cdp_soc, uint8_t pdev_id, qdf_nbuf_t nbuf)
  6145. {
  6146. struct dp_pdev *pdev =
  6147. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)cdp_soc,
  6148. pdev_id);
  6149. if (!pdev)
  6150. return QDF_STATUS_E_FAILURE;
  6151. dp_deliver_mgmt_frm(pdev, nbuf);
  6152. return QDF_STATUS_SUCCESS;
  6153. }
  6154. /**
  6155. * dp_set_bsscolor() - sets bsscolor for tx capture
  6156. * @pdev: Datapath PDEV handle
  6157. * @bsscolor: new bsscolor
  6158. */
  6159. static void
  6160. dp_mon_set_bsscolor(struct dp_pdev *pdev, uint8_t bsscolor)
  6161. {
  6162. pdev->rx_mon_recv_status.bsscolor = bsscolor;
  6163. }
  6164. /**
  6165. * dp_pdev_get_filter_ucast_data() - get DP PDEV monitor ucast filter
  6166. * @soc : data path soc handle
  6167. * @pdev_id : pdev_id
  6168. * Return: true on ucast filter flag set
  6169. */
  6170. static bool dp_pdev_get_filter_ucast_data(struct cdp_pdev *pdev_handle)
  6171. {
  6172. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6173. if ((pdev->fp_data_filter & FILTER_DATA_UCAST) ||
  6174. (pdev->mo_data_filter & FILTER_DATA_UCAST))
  6175. return true;
  6176. return false;
  6177. }
  6178. /**
  6179. * dp_pdev_get_filter_mcast_data() - get DP PDEV monitor mcast filter
  6180. * @pdev_handle: Datapath PDEV handle
  6181. * Return: true on mcast filter flag set
  6182. */
  6183. static bool dp_pdev_get_filter_mcast_data(struct cdp_pdev *pdev_handle)
  6184. {
  6185. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6186. if ((pdev->fp_data_filter & FILTER_DATA_MCAST) ||
  6187. (pdev->mo_data_filter & FILTER_DATA_MCAST))
  6188. return true;
  6189. return false;
  6190. }
  6191. /**
  6192. * dp_pdev_get_filter_non_data() - get DP PDEV monitor non_data filter
  6193. * @pdev_handle: Datapath PDEV handle
  6194. * Return: true on non data filter flag set
  6195. */
  6196. static bool dp_pdev_get_filter_non_data(struct cdp_pdev *pdev_handle)
  6197. {
  6198. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6199. if ((pdev->fp_mgmt_filter & FILTER_MGMT_ALL) ||
  6200. (pdev->mo_mgmt_filter & FILTER_MGMT_ALL)) {
  6201. if ((pdev->fp_ctrl_filter & FILTER_CTRL_ALL) ||
  6202. (pdev->mo_ctrl_filter & FILTER_CTRL_ALL)) {
  6203. return true;
  6204. }
  6205. }
  6206. return false;
  6207. }
  6208. #ifdef MESH_MODE_SUPPORT
  6209. void dp_peer_set_mesh_mode(struct cdp_vdev *vdev_hdl, uint32_t val)
  6210. {
  6211. struct dp_vdev *vdev = (struct dp_vdev *)vdev_hdl;
  6212. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  6213. FL("val %d"), val);
  6214. vdev->mesh_vdev = val;
  6215. }
  6216. /*
  6217. * dp_peer_set_mesh_rx_filter() - to set the mesh rx filter
  6218. * @vdev_hdl: virtual device object
  6219. * @val: value to be set
  6220. *
  6221. * Return: void
  6222. */
  6223. void dp_peer_set_mesh_rx_filter(struct cdp_vdev *vdev_hdl, uint32_t val)
  6224. {
  6225. struct dp_vdev *vdev = (struct dp_vdev *)vdev_hdl;
  6226. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  6227. FL("val %d"), val);
  6228. vdev->mesh_rx_filter = val;
  6229. }
  6230. #endif
  6231. bool dp_check_pdev_exists(struct dp_soc *soc, struct dp_pdev *data)
  6232. {
  6233. uint8_t pdev_count;
  6234. for (pdev_count = 0; pdev_count < MAX_PDEV_CNT; pdev_count++) {
  6235. if (soc->pdev_list[pdev_count] &&
  6236. soc->pdev_list[pdev_count] == data)
  6237. return true;
  6238. }
  6239. return false;
  6240. }
  6241. /**
  6242. * dp_rx_bar_stats_cb(): BAR received stats callback
  6243. * @soc: SOC handle
  6244. * @cb_ctxt: Call back context
  6245. * @reo_status: Reo status
  6246. *
  6247. * return: void
  6248. */
  6249. void dp_rx_bar_stats_cb(struct dp_soc *soc, void *cb_ctxt,
  6250. union hal_reo_status *reo_status)
  6251. {
  6252. struct dp_pdev *pdev = (struct dp_pdev *)cb_ctxt;
  6253. struct hal_reo_queue_status *queue_status = &(reo_status->queue_status);
  6254. if (!dp_check_pdev_exists(soc, pdev)) {
  6255. dp_err_rl("pdev doesn't exist");
  6256. return;
  6257. }
  6258. if (!qdf_atomic_read(&soc->cmn_init_done))
  6259. return;
  6260. if (queue_status->header.status != HAL_REO_CMD_SUCCESS) {
  6261. DP_PRINT_STATS("REO stats failure %d",
  6262. queue_status->header.status);
  6263. qdf_atomic_set(&(pdev->stats_cmd_complete), 1);
  6264. return;
  6265. }
  6266. pdev->stats.rx.bar_recv_cnt += queue_status->bar_rcvd_cnt;
  6267. qdf_atomic_set(&(pdev->stats_cmd_complete), 1);
  6268. }
  6269. /**
  6270. * dp_aggregate_vdev_stats(): Consolidate stats at VDEV level
  6271. * @vdev: DP VDEV handle
  6272. *
  6273. * return: void
  6274. */
  6275. void dp_aggregate_vdev_stats(struct dp_vdev *vdev,
  6276. struct cdp_vdev_stats *vdev_stats)
  6277. {
  6278. struct dp_peer *peer = NULL;
  6279. struct dp_soc *soc = NULL;
  6280. if (!vdev || !vdev->pdev)
  6281. return;
  6282. soc = vdev->pdev->soc;
  6283. qdf_mem_copy(vdev_stats, &vdev->stats, sizeof(vdev->stats));
  6284. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem)
  6285. dp_update_vdev_stats(vdev_stats, peer);
  6286. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  6287. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, vdev->pdev->soc,
  6288. vdev_stats, vdev->vdev_id,
  6289. UPDATE_VDEV_STATS, vdev->pdev->pdev_id);
  6290. #endif
  6291. }
  6292. void dp_aggregate_pdev_stats(struct dp_pdev *pdev)
  6293. {
  6294. struct dp_vdev *vdev = NULL;
  6295. struct dp_soc *soc;
  6296. struct cdp_vdev_stats *vdev_stats =
  6297. qdf_mem_malloc(sizeof(struct cdp_vdev_stats));
  6298. if (!vdev_stats) {
  6299. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  6300. "DP alloc failure - unable to get alloc vdev stats");
  6301. return;
  6302. }
  6303. qdf_mem_zero(&pdev->stats.tx, sizeof(pdev->stats.tx));
  6304. qdf_mem_zero(&pdev->stats.rx, sizeof(pdev->stats.rx));
  6305. qdf_mem_zero(&pdev->stats.tx_i, sizeof(pdev->stats.tx_i));
  6306. if (pdev->mcopy_mode)
  6307. DP_UPDATE_STATS(pdev, pdev->invalid_peer);
  6308. soc = pdev->soc;
  6309. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  6310. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  6311. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  6312. dp_aggregate_vdev_stats(vdev, vdev_stats);
  6313. dp_update_pdev_stats(pdev, vdev_stats);
  6314. dp_update_pdev_ingress_stats(pdev, vdev);
  6315. }
  6316. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  6317. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  6318. qdf_mem_free(vdev_stats);
  6319. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  6320. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc, &pdev->stats,
  6321. pdev->pdev_id, UPDATE_PDEV_STATS, pdev->pdev_id);
  6322. #endif
  6323. }
  6324. /**
  6325. * dp_vdev_getstats() - get vdev packet level stats
  6326. * @vdev_handle: Datapath VDEV handle
  6327. * @stats: cdp network device stats structure
  6328. *
  6329. * Return: QDF_STATUS
  6330. */
  6331. static QDF_STATUS dp_vdev_getstats(struct cdp_vdev *vdev_handle,
  6332. struct cdp_dev_stats *stats)
  6333. {
  6334. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  6335. struct dp_pdev *pdev;
  6336. struct dp_soc *soc;
  6337. struct cdp_vdev_stats *vdev_stats;
  6338. if (!vdev)
  6339. return QDF_STATUS_E_FAILURE;
  6340. pdev = vdev->pdev;
  6341. if (!pdev)
  6342. return QDF_STATUS_E_FAILURE;
  6343. soc = pdev->soc;
  6344. vdev_stats = qdf_mem_malloc(sizeof(struct cdp_vdev_stats));
  6345. if (!vdev_stats) {
  6346. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  6347. "DP alloc failure - unable to get alloc vdev stats");
  6348. return QDF_STATUS_E_FAILURE;
  6349. }
  6350. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  6351. dp_aggregate_vdev_stats(vdev, vdev_stats);
  6352. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  6353. stats->tx_packets = vdev_stats->tx_i.rcvd.num;
  6354. stats->tx_bytes = vdev_stats->tx_i.rcvd.bytes;
  6355. stats->tx_errors = vdev_stats->tx.tx_failed +
  6356. vdev_stats->tx_i.dropped.dropped_pkt.num;
  6357. stats->tx_dropped = stats->tx_errors;
  6358. stats->rx_packets = vdev_stats->rx.unicast.num +
  6359. vdev_stats->rx.multicast.num +
  6360. vdev_stats->rx.bcast.num;
  6361. stats->rx_bytes = vdev_stats->rx.unicast.bytes +
  6362. vdev_stats->rx.multicast.bytes +
  6363. vdev_stats->rx.bcast.bytes;
  6364. qdf_mem_free(vdev_stats);
  6365. return QDF_STATUS_SUCCESS;
  6366. }
  6367. /**
  6368. * dp_pdev_getstats() - get pdev packet level stats
  6369. * @pdev_handle: Datapath PDEV handle
  6370. * @stats: cdp network device stats structure
  6371. *
  6372. * Return: QDF_STATUS
  6373. */
  6374. static void dp_pdev_getstats(struct cdp_pdev *pdev_handle,
  6375. struct cdp_dev_stats *stats)
  6376. {
  6377. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6378. dp_aggregate_pdev_stats(pdev);
  6379. stats->tx_packets = pdev->stats.tx_i.rcvd.num;
  6380. stats->tx_bytes = pdev->stats.tx_i.rcvd.bytes;
  6381. stats->tx_errors = pdev->stats.tx.tx_failed +
  6382. pdev->stats.tx_i.dropped.dropped_pkt.num;
  6383. stats->tx_dropped = stats->tx_errors;
  6384. stats->rx_packets = pdev->stats.rx.unicast.num +
  6385. pdev->stats.rx.multicast.num +
  6386. pdev->stats.rx.bcast.num;
  6387. stats->rx_bytes = pdev->stats.rx.unicast.bytes +
  6388. pdev->stats.rx.multicast.bytes +
  6389. pdev->stats.rx.bcast.bytes;
  6390. stats->rx_errors = pdev->stats.err.desc_alloc_fail +
  6391. pdev->stats.err.ip_csum_err +
  6392. pdev->stats.err.tcp_udp_csum_err +
  6393. pdev->stats.rx.err.mic_err +
  6394. pdev->stats.rx.err.decrypt_err +
  6395. pdev->stats.err.rxdma_error +
  6396. pdev->stats.err.reo_error;
  6397. stats->rx_dropped = pdev->stats.dropped.msdu_not_done +
  6398. pdev->stats.dropped.mec +
  6399. pdev->stats.dropped.mesh_filter +
  6400. pdev->stats.dropped.wifi_parse +
  6401. pdev->stats.dropped.mon_rx_drop +
  6402. pdev->stats.dropped.mon_radiotap_update_err;
  6403. }
  6404. /**
  6405. * dp_get_device_stats() - get interface level packet stats
  6406. * @soc: soc handle
  6407. * @id : vdev_id or pdev_id based on type
  6408. * @stats: cdp network device stats structure
  6409. * @type: device type pdev/vdev
  6410. *
  6411. * Return: QDF_STATUS
  6412. */
  6413. static QDF_STATUS dp_get_device_stats(struct cdp_soc_t *soc, uint8_t id,
  6414. struct cdp_dev_stats *stats,
  6415. uint8_t type)
  6416. {
  6417. switch (type) {
  6418. case UPDATE_VDEV_STATS:
  6419. return dp_vdev_getstats(
  6420. (struct cdp_vdev *)dp_get_vdev_from_soc_vdev_id_wifi3(
  6421. (struct dp_soc *)soc, id), stats);
  6422. case UPDATE_PDEV_STATS:
  6423. {
  6424. struct dp_pdev *pdev =
  6425. dp_get_pdev_from_soc_pdev_id_wifi3(
  6426. (struct dp_soc *)soc,
  6427. id);
  6428. if (pdev) {
  6429. dp_pdev_getstats((struct cdp_pdev *)pdev,
  6430. stats);
  6431. return QDF_STATUS_SUCCESS;
  6432. }
  6433. }
  6434. break;
  6435. default:
  6436. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  6437. "apstats cannot be updated for this input "
  6438. "type %d", type);
  6439. break;
  6440. }
  6441. return QDF_STATUS_E_FAILURE;
  6442. }
  6443. const
  6444. char *dp_srng_get_str_from_hal_ring_type(enum hal_ring_type ring_type)
  6445. {
  6446. switch (ring_type) {
  6447. case REO_DST:
  6448. return "Reo_dst";
  6449. case REO_EXCEPTION:
  6450. return "Reo_exception";
  6451. case REO_CMD:
  6452. return "Reo_cmd";
  6453. case REO_REINJECT:
  6454. return "Reo_reinject";
  6455. case REO_STATUS:
  6456. return "Reo_status";
  6457. case WBM2SW_RELEASE:
  6458. return "wbm2sw_release";
  6459. case TCL_DATA:
  6460. return "tcl_data";
  6461. case TCL_CMD:
  6462. return "tcl_cmd";
  6463. case TCL_STATUS:
  6464. return "tcl_status";
  6465. case SW2WBM_RELEASE:
  6466. return "sw2wbm_release";
  6467. case RXDMA_BUF:
  6468. return "Rxdma_buf";
  6469. case RXDMA_DST:
  6470. return "Rxdma_dst";
  6471. case RXDMA_MONITOR_BUF:
  6472. return "Rxdma_monitor_buf";
  6473. case RXDMA_MONITOR_DESC:
  6474. return "Rxdma_monitor_desc";
  6475. case RXDMA_MONITOR_STATUS:
  6476. return "Rxdma_monitor_status";
  6477. default:
  6478. dp_err("Invalid ring type");
  6479. break;
  6480. }
  6481. return "Invalid";
  6482. }
  6483. /*
  6484. * dp_print_napi_stats(): NAPI stats
  6485. * @soc - soc handle
  6486. */
  6487. void dp_print_napi_stats(struct dp_soc *soc)
  6488. {
  6489. hif_print_napi_stats(soc->hif_handle);
  6490. }
  6491. /**
  6492. * dp_txrx_host_stats_clr(): Reinitialize the txrx stats
  6493. * @vdev: DP_VDEV handle
  6494. *
  6495. * Return: QDF_STATUS
  6496. */
  6497. static inline QDF_STATUS
  6498. dp_txrx_host_stats_clr(struct dp_vdev *vdev)
  6499. {
  6500. struct dp_peer *peer = NULL;
  6501. if (!vdev || !vdev->pdev)
  6502. return QDF_STATUS_E_FAILURE;
  6503. DP_STATS_CLR(vdev->pdev);
  6504. DP_STATS_CLR(vdev->pdev->soc);
  6505. DP_STATS_CLR(vdev);
  6506. hif_clear_napi_stats(vdev->pdev->soc->hif_handle);
  6507. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  6508. if (!peer)
  6509. return QDF_STATUS_E_FAILURE;
  6510. DP_STATS_CLR(peer);
  6511. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  6512. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, vdev->pdev->soc,
  6513. &peer->stats, peer->peer_ids[0],
  6514. UPDATE_PEER_STATS, vdev->pdev->pdev_id);
  6515. #endif
  6516. }
  6517. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  6518. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, vdev->pdev->soc,
  6519. &vdev->stats, vdev->vdev_id,
  6520. UPDATE_VDEV_STATS, vdev->pdev->pdev_id);
  6521. #endif
  6522. return QDF_STATUS_SUCCESS;
  6523. }
  6524. /*
  6525. * dp_get_host_peer_stats()- function to print peer stats
  6526. * @soc: dp_soc handle
  6527. * @mac_addr: mac address of the peer
  6528. *
  6529. * Return: QDF_STATUS
  6530. */
  6531. static QDF_STATUS
  6532. dp_get_host_peer_stats(struct cdp_soc_t *soc, uint8_t *mac_addr)
  6533. {
  6534. QDF_STATUS status = QDF_STATUS_SUCCESS;
  6535. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  6536. mac_addr, 0,
  6537. DP_VDEV_ALL);
  6538. if (!peer || peer->delete_in_progress) {
  6539. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  6540. "%s: Invalid peer\n", __func__);
  6541. status = QDF_STATUS_E_FAILURE;
  6542. goto fail;
  6543. }
  6544. dp_print_peer_stats(peer);
  6545. dp_peer_rxtid_stats(peer, dp_rx_tid_stats_cb, NULL);
  6546. fail:
  6547. if (peer)
  6548. dp_peer_unref_delete(peer);
  6549. return status;
  6550. }
  6551. /**
  6552. * dp_txrx_stats_help() - Helper function for Txrx_Stats
  6553. *
  6554. * Return: None
  6555. */
  6556. static void dp_txrx_stats_help(void)
  6557. {
  6558. dp_info("Command: iwpriv wlan0 txrx_stats <stats_option> <mac_id>");
  6559. dp_info("stats_option:");
  6560. dp_info(" 1 -- HTT Tx Statistics");
  6561. dp_info(" 2 -- HTT Rx Statistics");
  6562. dp_info(" 3 -- HTT Tx HW Queue Statistics");
  6563. dp_info(" 4 -- HTT Tx HW Sched Statistics");
  6564. dp_info(" 5 -- HTT Error Statistics");
  6565. dp_info(" 6 -- HTT TQM Statistics");
  6566. dp_info(" 7 -- HTT TQM CMDQ Statistics");
  6567. dp_info(" 8 -- HTT TX_DE_CMN Statistics");
  6568. dp_info(" 9 -- HTT Tx Rate Statistics");
  6569. dp_info(" 10 -- HTT Rx Rate Statistics");
  6570. dp_info(" 11 -- HTT Peer Statistics");
  6571. dp_info(" 12 -- HTT Tx SelfGen Statistics");
  6572. dp_info(" 13 -- HTT Tx MU HWQ Statistics");
  6573. dp_info(" 14 -- HTT RING_IF_INFO Statistics");
  6574. dp_info(" 15 -- HTT SRNG Statistics");
  6575. dp_info(" 16 -- HTT SFM Info Statistics");
  6576. dp_info(" 17 -- HTT PDEV_TX_MU_MIMO_SCHED INFO Statistics");
  6577. dp_info(" 18 -- HTT Peer List Details");
  6578. dp_info(" 20 -- Clear Host Statistics");
  6579. dp_info(" 21 -- Host Rx Rate Statistics");
  6580. dp_info(" 22 -- Host Tx Rate Statistics");
  6581. dp_info(" 23 -- Host Tx Statistics");
  6582. dp_info(" 24 -- Host Rx Statistics");
  6583. dp_info(" 25 -- Host AST Statistics");
  6584. dp_info(" 26 -- Host SRNG PTR Statistics");
  6585. dp_info(" 27 -- Host Mon Statistics");
  6586. dp_info(" 28 -- Host REO Queue Statistics");
  6587. dp_info(" 29 -- Host Soc cfg param Statistics");
  6588. dp_info(" 30 -- Host pdev cfg param Statistics");
  6589. }
  6590. /**
  6591. * dp_print_host_stats()- Function to print the stats aggregated at host
  6592. * @vdev_handle: DP_VDEV handle
  6593. * @type: host stats type
  6594. *
  6595. * Return: 0 on success, print error message in case of failure
  6596. */
  6597. static int
  6598. dp_print_host_stats(struct dp_vdev *vdev,
  6599. struct cdp_txrx_stats_req *req)
  6600. {
  6601. struct dp_pdev *pdev = (struct dp_pdev *)vdev->pdev;
  6602. enum cdp_host_txrx_stats type =
  6603. dp_stats_mapping_table[req->stats][STATS_HOST];
  6604. dp_aggregate_pdev_stats(pdev);
  6605. switch (type) {
  6606. case TXRX_CLEAR_STATS:
  6607. dp_txrx_host_stats_clr(vdev);
  6608. break;
  6609. case TXRX_RX_RATE_STATS:
  6610. dp_print_rx_rates(vdev);
  6611. break;
  6612. case TXRX_TX_RATE_STATS:
  6613. dp_print_tx_rates(vdev);
  6614. break;
  6615. case TXRX_TX_HOST_STATS:
  6616. dp_print_pdev_tx_stats(pdev);
  6617. dp_print_soc_tx_stats(pdev->soc);
  6618. break;
  6619. case TXRX_RX_HOST_STATS:
  6620. dp_print_pdev_rx_stats(pdev);
  6621. dp_print_soc_rx_stats(pdev->soc);
  6622. break;
  6623. case TXRX_AST_STATS:
  6624. dp_print_ast_stats(pdev->soc);
  6625. dp_print_peer_table(vdev);
  6626. break;
  6627. case TXRX_SRNG_PTR_STATS:
  6628. dp_print_ring_stats(pdev);
  6629. break;
  6630. case TXRX_RX_MON_STATS:
  6631. dp_print_pdev_rx_mon_stats(pdev);
  6632. break;
  6633. case TXRX_REO_QUEUE_STATS:
  6634. dp_get_host_peer_stats((struct cdp_soc_t *)pdev->soc,
  6635. req->peer_addr);
  6636. break;
  6637. case TXRX_SOC_CFG_PARAMS:
  6638. dp_print_soc_cfg_params(pdev->soc);
  6639. break;
  6640. case TXRX_PDEV_CFG_PARAMS:
  6641. dp_print_pdev_cfg_params(pdev);
  6642. break;
  6643. case TXRX_NAPI_STATS:
  6644. dp_print_napi_stats(pdev->soc);
  6645. case TXRX_SOC_INTERRUPT_STATS:
  6646. dp_print_soc_interrupt_stats(pdev->soc);
  6647. break;
  6648. default:
  6649. dp_info("Wrong Input For TxRx Host Stats");
  6650. dp_txrx_stats_help();
  6651. break;
  6652. }
  6653. return 0;
  6654. }
  6655. /*
  6656. * dp_ppdu_ring_reset()- Reset PPDU Stats ring
  6657. * @pdev: DP_PDEV handle
  6658. *
  6659. * Return: void
  6660. */
  6661. static void
  6662. dp_ppdu_ring_reset(struct dp_pdev *pdev)
  6663. {
  6664. struct htt_rx_ring_tlv_filter htt_tlv_filter;
  6665. int mac_id;
  6666. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  6667. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  6668. int mac_for_pdev =
  6669. dp_get_mac_id_for_pdev(mac_id, pdev->pdev_id);
  6670. /*
  6671. * Obtain lmac id from pdev to access the LMAC ring in soc
  6672. * context
  6673. */
  6674. int lmac_id =
  6675. dp_get_lmac_id_for_pdev_id(pdev->soc,
  6676. mac_id, pdev->pdev_id);
  6677. htt_h2t_rx_ring_cfg(pdev->soc->htt_handle, mac_for_pdev,
  6678. pdev->soc->rxdma_mon_status_ring[lmac_id].hal_srng,
  6679. RXDMA_MONITOR_STATUS, RX_DATA_BUFFER_SIZE,
  6680. &htt_tlv_filter);
  6681. }
  6682. }
  6683. /*
  6684. * dp_ppdu_ring_cfg()- Configure PPDU Stats ring
  6685. * @pdev: DP_PDEV handle
  6686. *
  6687. * Return: void
  6688. */
  6689. static void
  6690. dp_ppdu_ring_cfg(struct dp_pdev *pdev)
  6691. {
  6692. struct htt_rx_ring_tlv_filter htt_tlv_filter = {0};
  6693. int mac_id;
  6694. htt_tlv_filter.mpdu_start = 1;
  6695. htt_tlv_filter.msdu_start = 0;
  6696. htt_tlv_filter.packet = 0;
  6697. htt_tlv_filter.msdu_end = 0;
  6698. htt_tlv_filter.mpdu_end = 0;
  6699. htt_tlv_filter.attention = 0;
  6700. htt_tlv_filter.ppdu_start = 1;
  6701. htt_tlv_filter.ppdu_end = 1;
  6702. htt_tlv_filter.ppdu_end_user_stats = 1;
  6703. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  6704. htt_tlv_filter.ppdu_end_status_done = 1;
  6705. htt_tlv_filter.enable_fp = 1;
  6706. htt_tlv_filter.enable_md = 0;
  6707. if (pdev->neighbour_peers_added &&
  6708. pdev->soc->hw_nac_monitor_support) {
  6709. htt_tlv_filter.enable_md = 1;
  6710. htt_tlv_filter.packet_header = 1;
  6711. }
  6712. if (pdev->mcopy_mode) {
  6713. htt_tlv_filter.packet_header = 1;
  6714. htt_tlv_filter.enable_mo = 1;
  6715. }
  6716. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  6717. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  6718. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  6719. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  6720. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  6721. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  6722. if (pdev->neighbour_peers_added &&
  6723. pdev->soc->hw_nac_monitor_support)
  6724. htt_tlv_filter.md_data_filter = FILTER_DATA_ALL;
  6725. htt_tlv_filter.offset_valid = false;
  6726. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  6727. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id,
  6728. pdev->pdev_id);
  6729. /*
  6730. * Obtain lmac id from pdev to access the LMAC ring in soc
  6731. * context
  6732. */
  6733. int lmac_id =
  6734. dp_get_lmac_id_for_pdev_id(pdev->soc,
  6735. mac_id, pdev->pdev_id);
  6736. htt_h2t_rx_ring_cfg(pdev->soc->htt_handle, mac_for_pdev,
  6737. pdev->soc->rxdma_mon_status_ring[lmac_id].hal_srng,
  6738. RXDMA_MONITOR_STATUS, RX_DATA_BUFFER_SIZE,
  6739. &htt_tlv_filter);
  6740. }
  6741. }
  6742. /*
  6743. * is_ppdu_txrx_capture_enabled() - API to check both pktlog and debug_sniffer
  6744. * modes are enabled or not.
  6745. * @dp_pdev: dp pdev handle.
  6746. *
  6747. * Return: bool
  6748. */
  6749. static inline bool is_ppdu_txrx_capture_enabled(struct dp_pdev *pdev)
  6750. {
  6751. if (!pdev->pktlog_ppdu_stats && !pdev->tx_sniffer_enable &&
  6752. !pdev->mcopy_mode)
  6753. return true;
  6754. else
  6755. return false;
  6756. }
  6757. /*
  6758. *dp_set_bpr_enable() - API to enable/disable bpr feature
  6759. *@pdev_handle: DP_PDEV handle.
  6760. *@val: Provided value.
  6761. *
  6762. *Return: 0 for success. nonzero for failure.
  6763. */
  6764. static QDF_STATUS
  6765. dp_set_bpr_enable(struct dp_pdev *pdev, int val)
  6766. {
  6767. switch (val) {
  6768. case CDP_BPR_DISABLE:
  6769. pdev->bpr_enable = CDP_BPR_DISABLE;
  6770. if (!pdev->pktlog_ppdu_stats && !pdev->enhanced_stats_en &&
  6771. !pdev->tx_sniffer_enable && !pdev->mcopy_mode) {
  6772. dp_h2t_cfg_stats_msg_send(pdev, 0, pdev->pdev_id);
  6773. } else if (pdev->enhanced_stats_en &&
  6774. !pdev->tx_sniffer_enable && !pdev->mcopy_mode &&
  6775. !pdev->pktlog_ppdu_stats) {
  6776. dp_h2t_cfg_stats_msg_send(pdev,
  6777. DP_PPDU_STATS_CFG_ENH_STATS,
  6778. pdev->pdev_id);
  6779. }
  6780. break;
  6781. case CDP_BPR_ENABLE:
  6782. pdev->bpr_enable = CDP_BPR_ENABLE;
  6783. if (!pdev->enhanced_stats_en && !pdev->tx_sniffer_enable &&
  6784. !pdev->mcopy_mode && !pdev->pktlog_ppdu_stats) {
  6785. dp_h2t_cfg_stats_msg_send(pdev,
  6786. DP_PPDU_STATS_CFG_BPR,
  6787. pdev->pdev_id);
  6788. } else if (pdev->enhanced_stats_en &&
  6789. !pdev->tx_sniffer_enable && !pdev->mcopy_mode &&
  6790. !pdev->pktlog_ppdu_stats) {
  6791. dp_h2t_cfg_stats_msg_send(pdev,
  6792. DP_PPDU_STATS_CFG_BPR_ENH,
  6793. pdev->pdev_id);
  6794. } else if (pdev->pktlog_ppdu_stats) {
  6795. dp_h2t_cfg_stats_msg_send(pdev,
  6796. DP_PPDU_STATS_CFG_BPR_PKTLOG,
  6797. pdev->pdev_id);
  6798. }
  6799. break;
  6800. default:
  6801. break;
  6802. }
  6803. return QDF_STATUS_SUCCESS;
  6804. }
  6805. /*
  6806. * dp_pdev_tid_stats_ingress_inc
  6807. * @pdev: pdev handle
  6808. * @val: increase in value
  6809. *
  6810. * Return: void
  6811. */
  6812. static void
  6813. dp_pdev_tid_stats_ingress_inc(struct dp_pdev *pdev, uint32_t val)
  6814. {
  6815. pdev->stats.tid_stats.ingress_stack += val;
  6816. }
  6817. /*
  6818. * dp_pdev_tid_stats_osif_drop
  6819. * @pdev: pdev handle
  6820. * @val: increase in value
  6821. *
  6822. * Return: void
  6823. */
  6824. static void
  6825. dp_pdev_tid_stats_osif_drop(struct dp_pdev *pdev, uint32_t val)
  6826. {
  6827. pdev->stats.tid_stats.osif_drop += val;
  6828. }
  6829. /*
  6830. * dp_config_debug_sniffer()- API to enable/disable debug sniffer
  6831. * @pdev: DP_PDEV handle
  6832. * @val: user provided value
  6833. *
  6834. * Return: 0 for success. nonzero for failure.
  6835. */
  6836. static QDF_STATUS
  6837. dp_config_debug_sniffer(struct dp_pdev *pdev, int val)
  6838. {
  6839. QDF_STATUS status = QDF_STATUS_SUCCESS;
  6840. if (pdev->mcopy_mode)
  6841. dp_reset_monitor_mode((struct cdp_soc_t *)(pdev->soc),
  6842. pdev->pdev_id);
  6843. switch (val) {
  6844. case 0:
  6845. pdev->tx_sniffer_enable = 0;
  6846. pdev->monitor_configured = false;
  6847. if (!pdev->pktlog_ppdu_stats && !pdev->enhanced_stats_en &&
  6848. !pdev->bpr_enable) {
  6849. dp_h2t_cfg_stats_msg_send(pdev, 0, pdev->pdev_id);
  6850. dp_ppdu_ring_reset(pdev);
  6851. } else if (pdev->enhanced_stats_en && !pdev->bpr_enable) {
  6852. dp_h2t_cfg_stats_msg_send(pdev,
  6853. DP_PPDU_STATS_CFG_ENH_STATS, pdev->pdev_id);
  6854. } else if (!pdev->enhanced_stats_en && pdev->bpr_enable) {
  6855. dp_h2t_cfg_stats_msg_send(pdev,
  6856. DP_PPDU_STATS_CFG_BPR_ENH,
  6857. pdev->pdev_id);
  6858. } else {
  6859. dp_h2t_cfg_stats_msg_send(pdev,
  6860. DP_PPDU_STATS_CFG_BPR,
  6861. pdev->pdev_id);
  6862. }
  6863. break;
  6864. case 1:
  6865. pdev->tx_sniffer_enable = 1;
  6866. pdev->monitor_configured = false;
  6867. if (!pdev->pktlog_ppdu_stats)
  6868. dp_h2t_cfg_stats_msg_send(pdev,
  6869. DP_PPDU_STATS_CFG_SNIFFER, pdev->pdev_id);
  6870. break;
  6871. case 2:
  6872. if (pdev->monitor_vdev) {
  6873. status = QDF_STATUS_E_RESOURCES;
  6874. break;
  6875. }
  6876. pdev->mcopy_mode = 1;
  6877. dp_pdev_configure_monitor_rings(pdev);
  6878. pdev->monitor_configured = true;
  6879. pdev->tx_sniffer_enable = 0;
  6880. if (!pdev->pktlog_ppdu_stats)
  6881. dp_h2t_cfg_stats_msg_send(pdev,
  6882. DP_PPDU_STATS_CFG_SNIFFER, pdev->pdev_id);
  6883. break;
  6884. default:
  6885. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  6886. "Invalid value");
  6887. break;
  6888. }
  6889. return status;
  6890. }
  6891. /*
  6892. * dp_enable_enhanced_stats()- API to enable enhanced statistcs
  6893. * @soc_handle: DP_SOC handle
  6894. * @pdev_id: id of DP_PDEV handle
  6895. *
  6896. * Return: QDF_STATUS
  6897. */
  6898. static QDF_STATUS
  6899. dp_enable_enhanced_stats(struct cdp_soc_t *soc, uint8_t pdev_id)
  6900. {
  6901. struct dp_pdev *pdev =
  6902. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  6903. pdev_id);
  6904. if (!pdev)
  6905. return QDF_STATUS_E_FAILURE;
  6906. if (pdev->enhanced_stats_en == 0)
  6907. dp_cal_client_timer_start(pdev->cal_client_ctx);
  6908. pdev->enhanced_stats_en = 1;
  6909. if (!pdev->mcopy_mode && !pdev->neighbour_peers_added &&
  6910. !pdev->monitor_vdev)
  6911. dp_ppdu_ring_cfg(pdev);
  6912. if (is_ppdu_txrx_capture_enabled(pdev) && !pdev->bpr_enable) {
  6913. dp_h2t_cfg_stats_msg_send(pdev, DP_PPDU_STATS_CFG_ENH_STATS, pdev->pdev_id);
  6914. } else if (is_ppdu_txrx_capture_enabled(pdev) && pdev->bpr_enable) {
  6915. dp_h2t_cfg_stats_msg_send(pdev,
  6916. DP_PPDU_STATS_CFG_BPR_ENH,
  6917. pdev->pdev_id);
  6918. }
  6919. return QDF_STATUS_SUCCESS;
  6920. }
  6921. /*
  6922. * dp_disable_enhanced_stats()- API to disable enhanced statistcs
  6923. *
  6924. * @param soc - the soc handle
  6925. * @param pdev_id - pdev_id of pdev
  6926. * @return - QDF_STATUS
  6927. */
  6928. static QDF_STATUS
  6929. dp_disable_enhanced_stats(struct cdp_soc_t *soc, uint8_t pdev_id)
  6930. {
  6931. struct dp_pdev *pdev =
  6932. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  6933. pdev_id);
  6934. if (!pdev)
  6935. return QDF_STATUS_E_FAILURE;
  6936. if (pdev->enhanced_stats_en == 1)
  6937. dp_cal_client_timer_stop(pdev->cal_client_ctx);
  6938. pdev->enhanced_stats_en = 0;
  6939. if (is_ppdu_txrx_capture_enabled(pdev) && !pdev->bpr_enable) {
  6940. dp_h2t_cfg_stats_msg_send(pdev, 0, pdev->pdev_id);
  6941. } else if (is_ppdu_txrx_capture_enabled(pdev) && pdev->bpr_enable) {
  6942. dp_h2t_cfg_stats_msg_send(pdev,
  6943. DP_PPDU_STATS_CFG_BPR,
  6944. pdev->pdev_id);
  6945. }
  6946. if (!pdev->mcopy_mode && !pdev->neighbour_peers_added &&
  6947. !pdev->monitor_vdev)
  6948. dp_ppdu_ring_reset(pdev);
  6949. return QDF_STATUS_SUCCESS;
  6950. }
  6951. /*
  6952. * dp_get_fw_peer_stats()- function to print peer stats
  6953. * @soc: soc handle
  6954. * @pdev_id : id of the pdev handle
  6955. * @mac_addr: mac address of the peer
  6956. * @cap: Type of htt stats requested
  6957. * @is_wait: if set, wait on completion from firmware response
  6958. *
  6959. * Currently Supporting only MAC ID based requests Only
  6960. * 1: HTT_PEER_STATS_REQ_MODE_NO_QUERY
  6961. * 2: HTT_PEER_STATS_REQ_MODE_QUERY_TQM
  6962. * 3: HTT_PEER_STATS_REQ_MODE_FLUSH_TQM
  6963. *
  6964. * Return: QDF_STATUS
  6965. */
  6966. static QDF_STATUS
  6967. dp_get_fw_peer_stats(struct cdp_soc_t *soc, uint8_t pdev_id,
  6968. uint8_t *mac_addr,
  6969. uint32_t cap, uint32_t is_wait)
  6970. {
  6971. int i;
  6972. uint32_t config_param0 = 0;
  6973. uint32_t config_param1 = 0;
  6974. uint32_t config_param2 = 0;
  6975. uint32_t config_param3 = 0;
  6976. struct dp_pdev *pdev =
  6977. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  6978. pdev_id);
  6979. if (!pdev)
  6980. return QDF_STATUS_E_FAILURE;
  6981. HTT_DBG_EXT_STATS_PEER_INFO_IS_MAC_ADDR_SET(config_param0, 1);
  6982. config_param0 |= (1 << (cap + 1));
  6983. for (i = 0; i < HTT_PEER_STATS_MAX_TLV; i++) {
  6984. config_param1 |= (1 << i);
  6985. }
  6986. config_param2 |= (mac_addr[0] & 0x000000ff);
  6987. config_param2 |= ((mac_addr[1] << 8) & 0x0000ff00);
  6988. config_param2 |= ((mac_addr[2] << 16) & 0x00ff0000);
  6989. config_param2 |= ((mac_addr[3] << 24) & 0xff000000);
  6990. config_param3 |= (mac_addr[4] & 0x000000ff);
  6991. config_param3 |= ((mac_addr[5] << 8) & 0x0000ff00);
  6992. if (is_wait) {
  6993. qdf_event_reset(&pdev->fw_peer_stats_event);
  6994. dp_h2t_ext_stats_msg_send(pdev, HTT_DBG_EXT_STATS_PEER_INFO,
  6995. config_param0, config_param1,
  6996. config_param2, config_param3,
  6997. 0, 1, 0);
  6998. qdf_wait_single_event(&pdev->fw_peer_stats_event,
  6999. DP_FW_PEER_STATS_CMP_TIMEOUT_MSEC);
  7000. } else {
  7001. dp_h2t_ext_stats_msg_send(pdev, HTT_DBG_EXT_STATS_PEER_INFO,
  7002. config_param0, config_param1,
  7003. config_param2, config_param3,
  7004. 0, 0, 0);
  7005. }
  7006. return QDF_STATUS_SUCCESS;
  7007. }
  7008. /* This struct definition will be removed from here
  7009. * once it get added in FW headers*/
  7010. struct httstats_cmd_req {
  7011. uint32_t config_param0;
  7012. uint32_t config_param1;
  7013. uint32_t config_param2;
  7014. uint32_t config_param3;
  7015. int cookie;
  7016. u_int8_t stats_id;
  7017. };
  7018. /*
  7019. * dp_get_htt_stats: function to process the httstas request
  7020. * @soc: DP soc handle
  7021. * @pdev_id: id of pdev handle
  7022. * @data: pointer to request data
  7023. * @data_len: length for request data
  7024. *
  7025. * return: QDF_STATUS
  7026. */
  7027. static QDF_STATUS
  7028. dp_get_htt_stats(struct cdp_soc_t *soc, uint8_t pdev_id, void *data,
  7029. uint32_t data_len)
  7030. {
  7031. struct httstats_cmd_req *req = (struct httstats_cmd_req *)data;
  7032. struct dp_pdev *pdev =
  7033. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  7034. pdev_id);
  7035. if (!pdev)
  7036. return QDF_STATUS_E_FAILURE;
  7037. QDF_ASSERT(data_len == sizeof(struct httstats_cmd_req));
  7038. dp_h2t_ext_stats_msg_send(pdev, req->stats_id,
  7039. req->config_param0, req->config_param1,
  7040. req->config_param2, req->config_param3,
  7041. req->cookie, 0, 0);
  7042. return QDF_STATUS_SUCCESS;
  7043. }
  7044. /**
  7045. * dp_set_pdev_tidmap_prty_wifi3(): update tidmap priority in pdev
  7046. * @pdev: DP_PDEV handle
  7047. * @prio: tidmap priority value passed by the user
  7048. *
  7049. * Return: QDF_STATUS_SUCCESS on success
  7050. */
  7051. static QDF_STATUS dp_set_pdev_tidmap_prty_wifi3(struct dp_pdev *pdev,
  7052. uint8_t prio)
  7053. {
  7054. struct dp_soc *soc = pdev->soc;
  7055. soc->tidmap_prty = prio;
  7056. hal_tx_set_tidmap_prty(soc->hal_soc, prio);
  7057. return QDF_STATUS_SUCCESS;
  7058. }
  7059. /*
  7060. * dp_get_peer_param: function to get parameters in peer
  7061. * @cdp_soc: DP soc handle
  7062. * @vdev_id: id of vdev handle
  7063. * @peer_mac: peer mac address
  7064. * @param: parameter type to be set
  7065. * @val : address of buffer
  7066. *
  7067. * Return: val
  7068. */
  7069. static QDF_STATUS dp_get_peer_param(struct cdp_soc_t *cdp_soc, uint8_t vdev_id,
  7070. uint8_t *peer_mac,
  7071. enum cdp_peer_param_type param,
  7072. cdp_config_param_type *val)
  7073. {
  7074. return QDF_STATUS_SUCCESS;
  7075. }
  7076. /*
  7077. * dp_set_peer_param: function to set parameters in peer
  7078. * @cdp_soc: DP soc handle
  7079. * @vdev_id: id of vdev handle
  7080. * @peer_mac: peer mac address
  7081. * @param: parameter type to be set
  7082. * @val: value of parameter to be set
  7083. *
  7084. * Return: 0 for success. nonzero for failure.
  7085. */
  7086. static QDF_STATUS dp_set_peer_param(struct cdp_soc_t *cdp_soc, uint8_t vdev_id,
  7087. uint8_t *peer_mac,
  7088. enum cdp_peer_param_type param,
  7089. cdp_config_param_type val)
  7090. {
  7091. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)cdp_soc,
  7092. peer_mac, 0, vdev_id);
  7093. if (!peer || peer->delete_in_progress)
  7094. goto fail;
  7095. switch (param) {
  7096. case CDP_CONFIG_NAWDS:
  7097. peer->nawds_enabled = val.cdp_peer_param_nawds;
  7098. break;
  7099. case CDP_CONFIG_NAC:
  7100. peer->nac = !!(val.cdp_peer_param_nac);
  7101. break;
  7102. default:
  7103. break;
  7104. }
  7105. fail:
  7106. if (peer)
  7107. dp_peer_unref_delete(peer);
  7108. return QDF_STATUS_SUCCESS;
  7109. }
  7110. /*
  7111. * dp_get_pdev_param: function to get parameters from pdev
  7112. * @cdp_soc: DP soc handle
  7113. * @pdev_id: id of pdev handle
  7114. * @param: parameter type to be get
  7115. * @value : buffer for value
  7116. *
  7117. * Return: status
  7118. */
  7119. static QDF_STATUS dp_get_pdev_param(struct cdp_soc_t *cdp_soc, uint8_t pdev_id,
  7120. enum cdp_pdev_param_type param,
  7121. cdp_config_param_type *val)
  7122. {
  7123. struct cdp_pdev *pdev = (struct cdp_pdev *)
  7124. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)cdp_soc,
  7125. pdev_id);
  7126. if (!pdev)
  7127. return QDF_STATUS_E_FAILURE;
  7128. switch (param) {
  7129. case CDP_CONFIG_VOW:
  7130. val->cdp_pdev_param_cfg_vow =
  7131. ((struct dp_pdev *)pdev)->delay_stats_flag;
  7132. break;
  7133. case CDP_TX_PENDING:
  7134. val->cdp_pdev_param_tx_pending = dp_get_tx_pending(pdev);
  7135. break;
  7136. case CDP_FILTER_MCAST_DATA:
  7137. val->cdp_pdev_param_fltr_mcast =
  7138. dp_pdev_get_filter_mcast_data(pdev);
  7139. break;
  7140. case CDP_FILTER_NO_DATA:
  7141. val->cdp_pdev_param_fltr_none =
  7142. dp_pdev_get_filter_non_data(pdev);
  7143. break;
  7144. case CDP_FILTER_UCAST_DATA:
  7145. val->cdp_pdev_param_fltr_ucast =
  7146. dp_pdev_get_filter_ucast_data(pdev);
  7147. break;
  7148. default:
  7149. return QDF_STATUS_E_FAILURE;
  7150. }
  7151. return QDF_STATUS_SUCCESS;
  7152. }
  7153. /*
  7154. * dp_set_pdev_param: function to set parameters in pdev
  7155. * @cdp_soc: DP soc handle
  7156. * @pdev_id: id of pdev handle
  7157. * @param: parameter type to be set
  7158. * @val: value of parameter to be set
  7159. *
  7160. * Return: 0 for success. nonzero for failure.
  7161. */
  7162. static QDF_STATUS dp_set_pdev_param(struct cdp_soc_t *cdp_soc, uint8_t pdev_id,
  7163. enum cdp_pdev_param_type param,
  7164. cdp_config_param_type val)
  7165. {
  7166. struct dp_pdev *pdev =
  7167. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)cdp_soc,
  7168. pdev_id);
  7169. if (!pdev)
  7170. return QDF_STATUS_E_FAILURE;
  7171. switch (param) {
  7172. case CDP_CONFIG_TX_CAPTURE:
  7173. return dp_config_debug_sniffer(pdev,
  7174. val.cdp_pdev_param_tx_capture);
  7175. case CDP_CONFIG_DEBUG_SNIFFER:
  7176. return dp_config_debug_sniffer(pdev,
  7177. val.cdp_pdev_param_dbg_snf);
  7178. case CDP_CONFIG_BPR_ENABLE:
  7179. return dp_set_bpr_enable(pdev, val.cdp_pdev_param_bpr_enable);
  7180. case CDP_CONFIG_PRIMARY_RADIO:
  7181. pdev->is_primary = val.cdp_pdev_param_primary_radio;
  7182. break;
  7183. case CDP_CONFIG_CAPTURE_LATENCY:
  7184. pdev->latency_capture_enable = val.cdp_pdev_param_cptr_latcy;
  7185. break;
  7186. case CDP_INGRESS_STATS:
  7187. dp_pdev_tid_stats_ingress_inc(pdev,
  7188. val.cdp_pdev_param_ingrs_stats);
  7189. break;
  7190. case CDP_OSIF_DROP:
  7191. dp_pdev_tid_stats_osif_drop(pdev,
  7192. val.cdp_pdev_param_osif_drop);
  7193. break;
  7194. case CDP_CONFIG_ENH_RX_CAPTURE:
  7195. return dp_config_enh_rx_capture(pdev,
  7196. val.cdp_pdev_param_en_rx_cap);
  7197. case CDP_CONFIG_ENH_TX_CAPTURE:
  7198. return dp_config_enh_tx_capture(pdev,
  7199. val.cdp_pdev_param_en_tx_cap);
  7200. case CDP_CONFIG_HMMC_TID_OVERRIDE:
  7201. pdev->hmmc_tid_override_en = val.cdp_pdev_param_hmmc_tid_ovrd;
  7202. break;
  7203. case CDP_CONFIG_HMMC_TID_VALUE:
  7204. pdev->hmmc_tid = val.cdp_pdev_param_hmmc_tid;
  7205. break;
  7206. case CDP_CHAN_NOISE_FLOOR:
  7207. pdev->chan_noise_floor = val.cdp_pdev_param_chn_noise_flr;
  7208. break;
  7209. case CDP_TIDMAP_PRTY:
  7210. dp_set_pdev_tidmap_prty_wifi3(pdev,
  7211. val.cdp_pdev_param_tidmap_prty);
  7212. break;
  7213. case CDP_FILTER_NEIGH_PEERS:
  7214. dp_set_filter_neigh_peers(pdev,
  7215. val.cdp_pdev_param_fltr_neigh_peers);
  7216. break;
  7217. case CDP_MONITOR_CHANNEL:
  7218. pdev->mon_chan_num = val.cdp_pdev_param_monitor_chan;
  7219. break;
  7220. case CDP_MONITOR_FREQUENCY:
  7221. pdev->mon_chan_freq = val.cdp_pdev_param_mon_freq;
  7222. break;
  7223. case CDP_CONFIG_BSS_COLOR:
  7224. dp_mon_set_bsscolor(pdev, val.cdp_pdev_param_bss_color);
  7225. break;
  7226. default:
  7227. return QDF_STATUS_E_INVAL;
  7228. }
  7229. return QDF_STATUS_SUCCESS;
  7230. }
  7231. /*
  7232. * dp_calculate_delay_stats: function to get rx delay stats
  7233. * @cdp_soc: DP soc handle
  7234. * @vdev_id: id of DP vdev handle
  7235. * @nbuf: skb
  7236. *
  7237. * Return: QDF_STATUS
  7238. */
  7239. static QDF_STATUS
  7240. dp_calculate_delay_stats(struct cdp_soc_t *cdp_soc, uint8_t vdev_id,
  7241. qdf_nbuf_t nbuf)
  7242. {
  7243. struct dp_vdev *vdev =
  7244. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)cdp_soc,
  7245. vdev_id);
  7246. if (vdev) {
  7247. dp_rx_compute_delay(vdev, nbuf);
  7248. return QDF_STATUS_E_FAILURE;
  7249. }
  7250. return QDF_STATUS_SUCCESS;
  7251. }
  7252. /*
  7253. * dp_get_vdev_param: function to get parameters from vdev
  7254. * @cdp_soc : DP soc handle
  7255. * @vdev_id: id of DP vdev handle
  7256. * @param: parameter type to get value
  7257. * @val: buffer address
  7258. *
  7259. * return: status
  7260. */
  7261. static QDF_STATUS dp_get_vdev_param(struct cdp_soc_t *cdp_soc, uint8_t vdev_id,
  7262. enum cdp_vdev_param_type param,
  7263. cdp_config_param_type *val)
  7264. {
  7265. struct dp_vdev *vdev =
  7266. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)cdp_soc,
  7267. vdev_id);
  7268. if (!vdev)
  7269. return QDF_STATUS_E_FAILURE;
  7270. switch (param) {
  7271. case CDP_ENABLE_WDS:
  7272. val->cdp_vdev_param_wds = vdev->wds_enabled;
  7273. break;
  7274. case CDP_ENABLE_MEC:
  7275. val->cdp_vdev_param_mec = vdev->mec_enabled;
  7276. break;
  7277. case CDP_ENABLE_DA_WAR:
  7278. val->cdp_vdev_param_da_war = vdev->pdev->soc->da_war_enabled;
  7279. break;
  7280. default:
  7281. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7282. "param value %d is wrong\n",
  7283. param);
  7284. return QDF_STATUS_E_FAILURE;
  7285. }
  7286. return QDF_STATUS_SUCCESS;
  7287. }
  7288. /*
  7289. * dp_set_vdev_param: function to set parameters in vdev
  7290. * @cdp_soc : DP soc handle
  7291. * @vdev_id: id of DP vdev handle
  7292. * @param: parameter type to get value
  7293. * @val: value
  7294. *
  7295. * return: QDF_STATUS
  7296. */
  7297. static QDF_STATUS
  7298. dp_set_vdev_param(struct cdp_soc_t *cdp_soc, uint8_t vdev_id,
  7299. enum cdp_vdev_param_type param, cdp_config_param_type val)
  7300. {
  7301. struct dp_soc *dsoc = (struct dp_soc *)cdp_soc;
  7302. struct dp_vdev *vdev =
  7303. dp_get_vdev_from_soc_vdev_id_wifi3(dsoc, vdev_id);
  7304. uint32_t var = 0;
  7305. if (!vdev)
  7306. return QDF_STATUS_E_FAILURE;
  7307. switch (param) {
  7308. case CDP_ENABLE_WDS:
  7309. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7310. "wds_enable %d for vdev(%pK) id(%d)\n",
  7311. val.cdp_vdev_param_wds, vdev, vdev->vdev_id);
  7312. vdev->wds_enabled = val.cdp_vdev_param_wds;
  7313. break;
  7314. case CDP_ENABLE_MEC:
  7315. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7316. "mec_enable %d for vdev(%pK) id(%d)\n",
  7317. val.cdp_vdev_param_mec, vdev, vdev->vdev_id);
  7318. vdev->mec_enabled = val.cdp_vdev_param_mec;
  7319. break;
  7320. case CDP_ENABLE_DA_WAR:
  7321. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7322. "da_war_enable %d for vdev(%pK) id(%d)\n",
  7323. val.cdp_vdev_param_da_war, vdev, vdev->vdev_id);
  7324. vdev->pdev->soc->da_war_enabled = val.cdp_vdev_param_da_war;
  7325. dp_wds_flush_ast_table_wifi3(((struct cdp_soc_t *)
  7326. vdev->pdev->soc));
  7327. break;
  7328. case CDP_ENABLE_NAWDS:
  7329. vdev->nawds_enabled = val.cdp_vdev_param_nawds;
  7330. break;
  7331. case CDP_ENABLE_MCAST_EN:
  7332. vdev->mcast_enhancement_en = val.cdp_vdev_param_mcast_en;
  7333. break;
  7334. case CDP_ENABLE_PROXYSTA:
  7335. vdev->proxysta_vdev = val.cdp_vdev_param_proxysta;
  7336. break;
  7337. case CDP_UPDATE_TDLS_FLAGS:
  7338. vdev->tdls_link_connected = val.cdp_vdev_param_tdls_flags;
  7339. break;
  7340. case CDP_CFG_WDS_AGING_TIMER:
  7341. var = val.cdp_vdev_param_aging_tmr;
  7342. if (!var)
  7343. qdf_timer_stop(&vdev->pdev->soc->ast_aging_timer);
  7344. else if (var != vdev->wds_aging_timer_val)
  7345. qdf_timer_mod(&vdev->pdev->soc->ast_aging_timer, var);
  7346. vdev->wds_aging_timer_val = var;
  7347. break;
  7348. case CDP_ENABLE_AP_BRIDGE:
  7349. if (wlan_op_mode_sta != vdev->opmode)
  7350. vdev->ap_bridge_enabled = val.cdp_vdev_param_ap_brdg_en;
  7351. else
  7352. vdev->ap_bridge_enabled = false;
  7353. break;
  7354. case CDP_ENABLE_CIPHER:
  7355. vdev->sec_type = val.cdp_vdev_param_cipher_en;
  7356. break;
  7357. case CDP_ENABLE_QWRAP_ISOLATION:
  7358. vdev->isolation_vdev = val.cdp_vdev_param_qwrap_isolation;
  7359. break;
  7360. case CDP_UPDATE_MULTIPASS:
  7361. vdev->multipass_en = val.cdp_vdev_param_update_multipass;
  7362. break;
  7363. case CDP_TX_ENCAP_TYPE:
  7364. vdev->tx_encap_type = val.cdp_vdev_param_tx_encap;
  7365. break;
  7366. case CDP_RX_DECAP_TYPE:
  7367. vdev->rx_decap_type = val.cdp_vdev_param_rx_decap;
  7368. break;
  7369. case CDP_TID_VDEV_PRTY:
  7370. vdev->tidmap_prty = val.cdp_vdev_param_tidmap_prty;
  7371. break;
  7372. case CDP_TIDMAP_TBL_ID:
  7373. vdev->tidmap_tbl_id = val.cdp_vdev_param_tidmap_tbl_id;
  7374. break;
  7375. #ifdef MESH_MODE_SUPPORT
  7376. case CDP_MESH_RX_FILTER:
  7377. dp_peer_set_mesh_rx_filter((struct cdp_vdev *)vdev,
  7378. val.cdp_vdev_param_mesh_rx_filter);
  7379. break;
  7380. case CDP_MESH_MODE:
  7381. dp_peer_set_mesh_mode((struct cdp_vdev *)vdev,
  7382. val.cdp_vdev_param_mesh_mode);
  7383. break;
  7384. #endif
  7385. default:
  7386. break;
  7387. }
  7388. dp_tx_vdev_update_search_flags((struct dp_vdev *)vdev);
  7389. return QDF_STATUS_SUCCESS;
  7390. }
  7391. /*
  7392. * dp_set_psoc_param: function to set parameters in psoc
  7393. * @cdp_soc : DP soc handle
  7394. * @param: parameter type to be set
  7395. * @val: value of parameter to be set
  7396. *
  7397. * return: QDF_STATUS
  7398. */
  7399. static QDF_STATUS
  7400. dp_set_psoc_param(struct cdp_soc_t *cdp_soc,
  7401. enum cdp_psoc_param_type param, cdp_config_param_type val)
  7402. {
  7403. struct dp_soc *soc = (struct dp_soc *)cdp_soc;
  7404. struct wlan_cfg_dp_soc_ctxt *wlan_cfg_ctx = soc->wlan_cfg_ctx;
  7405. switch (param) {
  7406. case CDP_ENABLE_RATE_STATS:
  7407. soc->wlanstats_enabled = val.cdp_psoc_param_en_rate_stats;
  7408. break;
  7409. case CDP_SET_NSS_CFG:
  7410. wlan_cfg_set_dp_soc_nss_cfg(wlan_cfg_ctx,
  7411. val.cdp_psoc_param_en_nss_cfg);
  7412. /*
  7413. * TODO: masked out based on the per offloaded radio
  7414. */
  7415. switch (val.cdp_psoc_param_en_nss_cfg) {
  7416. case dp_nss_cfg_default:
  7417. break;
  7418. case dp_nss_cfg_first_radio:
  7419. /*
  7420. * This configuration is valid for single band radio which
  7421. * is also NSS offload.
  7422. */
  7423. case dp_nss_cfg_dbdc:
  7424. case dp_nss_cfg_dbtc:
  7425. wlan_cfg_set_num_tx_desc_pool(wlan_cfg_ctx, 0);
  7426. wlan_cfg_set_num_tx_ext_desc_pool(wlan_cfg_ctx, 0);
  7427. wlan_cfg_set_num_tx_desc(wlan_cfg_ctx, 0);
  7428. wlan_cfg_set_num_tx_ext_desc(wlan_cfg_ctx, 0);
  7429. break;
  7430. default:
  7431. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7432. "Invalid offload config %d",
  7433. val.cdp_psoc_param_en_nss_cfg);
  7434. }
  7435. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  7436. FL("nss-wifi<0> nss config is enabled"));
  7437. break;
  7438. default:
  7439. break;
  7440. }
  7441. return QDF_STATUS_SUCCESS;
  7442. }
  7443. /*
  7444. * dp_get_psoc_param: function to get parameters in soc
  7445. * @cdp_soc : DP soc handle
  7446. * @param: parameter type to be set
  7447. * @val: address of buffer
  7448. *
  7449. * return: status
  7450. */
  7451. static QDF_STATUS dp_get_psoc_param(struct cdp_soc_t *cdp_soc,
  7452. enum cdp_psoc_param_type param,
  7453. cdp_config_param_type *val)
  7454. {
  7455. return QDF_STATUS_SUCCESS;
  7456. }
  7457. /**
  7458. * dp_peer_update_pkt_capture_params: Set Rx & Tx Capture flags for a peer
  7459. * @soc: DP_SOC handle
  7460. * @pdev_id: id of DP_PDEV handle
  7461. * @is_rx_pkt_cap_enable: enable/disable Rx packet capture in monitor mode
  7462. * @is_tx_pkt_cap_enable: enable/disable Tx packet capture in monitor mode
  7463. * @peer_mac: MAC address for which the above need to be enabled/disabled
  7464. *
  7465. * Return: Success if Rx & Tx capture is enabled for peer, false otherwise
  7466. */
  7467. QDF_STATUS
  7468. dp_peer_update_pkt_capture_params(ol_txrx_soc_handle soc,
  7469. uint8_t pdev_id,
  7470. bool is_rx_pkt_cap_enable,
  7471. bool is_tx_pkt_cap_enable,
  7472. uint8_t *peer_mac)
  7473. {
  7474. struct dp_peer *peer;
  7475. struct dp_pdev *pdev =
  7476. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  7477. pdev_id);
  7478. if (!pdev)
  7479. return QDF_STATUS_E_FAILURE;
  7480. peer = (struct dp_peer *)dp_find_peer_by_addr((struct cdp_pdev *)pdev,
  7481. peer_mac);
  7482. if (!peer) {
  7483. dp_err("Invalid Peer");
  7484. return QDF_STATUS_E_FAILURE;
  7485. }
  7486. dp_peer_set_rx_capture_enabled(peer, is_rx_pkt_cap_enable);
  7487. dp_peer_set_tx_capture_enabled(peer, is_tx_pkt_cap_enable);
  7488. return QDF_STATUS_SUCCESS;
  7489. }
  7490. /*
  7491. * dp_set_vdev_dscp_tid_map_wifi3(): Update Map ID selected for particular vdev
  7492. * @soc: DP_SOC handle
  7493. * @vdev_id: id of DP_VDEV handle
  7494. * @map_id:ID of map that needs to be updated
  7495. *
  7496. * Return: QDF_STATUS
  7497. */
  7498. static QDF_STATUS dp_set_vdev_dscp_tid_map_wifi3(ol_txrx_soc_handle soc,
  7499. uint8_t vdev_id,
  7500. uint8_t map_id)
  7501. {
  7502. struct dp_vdev *vdev =
  7503. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  7504. vdev_id);
  7505. if (vdev) {
  7506. vdev->dscp_tid_map_id = map_id;
  7507. return QDF_STATUS_SUCCESS;
  7508. }
  7509. return QDF_STATUS_E_FAILURE;
  7510. }
  7511. #ifdef DP_RATETABLE_SUPPORT
  7512. static int dp_txrx_get_ratekbps(int preamb, int mcs,
  7513. int htflag, int gintval)
  7514. {
  7515. uint32_t rix;
  7516. uint16_t ratecode;
  7517. return dp_getrateindex((uint32_t)gintval, (uint16_t)mcs, 1,
  7518. (uint8_t)preamb, 1, &rix, &ratecode);
  7519. }
  7520. #else
  7521. static int dp_txrx_get_ratekbps(int preamb, int mcs,
  7522. int htflag, int gintval)
  7523. {
  7524. return 0;
  7525. }
  7526. #endif
  7527. /* dp_txrx_get_pdev_stats - Returns cdp_pdev_stats
  7528. * @soc: DP soc handle
  7529. * @pdev_id: id of DP pdev handle
  7530. * @pdev_stats: buffer to copy to
  7531. *
  7532. * return : status success/failure
  7533. */
  7534. static QDF_STATUS
  7535. dp_txrx_get_pdev_stats(struct cdp_soc_t *soc, uint8_t pdev_id,
  7536. struct cdp_pdev_stats *pdev_stats)
  7537. {
  7538. struct dp_pdev *pdev =
  7539. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  7540. pdev_id);
  7541. if (!pdev)
  7542. return QDF_STATUS_E_FAILURE;
  7543. dp_aggregate_pdev_stats(pdev);
  7544. qdf_mem_copy(pdev_stats, &pdev->stats, sizeof(struct cdp_pdev_stats));
  7545. return QDF_STATUS_SUCCESS;
  7546. }
  7547. /* dp_txrx_update_vdev_me_stats(): Update vdev ME stats sent from CDP
  7548. * @vdev: DP vdev handle
  7549. * @buf: buffer containing specific stats structure
  7550. *
  7551. * Returns: void
  7552. */
  7553. static void dp_txrx_update_vdev_me_stats(struct dp_vdev *vdev,
  7554. void *buf)
  7555. {
  7556. struct cdp_tx_ingress_stats *host_stats = NULL;
  7557. if (!buf) {
  7558. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7559. "Invalid host stats buf");
  7560. return;
  7561. }
  7562. host_stats = (struct cdp_tx_ingress_stats *)buf;
  7563. DP_STATS_INC_PKT(vdev, tx_i.mcast_en.mcast_pkt,
  7564. host_stats->mcast_en.mcast_pkt.num,
  7565. host_stats->mcast_en.mcast_pkt.bytes);
  7566. DP_STATS_INC(vdev, tx_i.mcast_en.dropped_map_error,
  7567. host_stats->mcast_en.dropped_map_error);
  7568. DP_STATS_INC(vdev, tx_i.mcast_en.dropped_self_mac,
  7569. host_stats->mcast_en.dropped_self_mac);
  7570. DP_STATS_INC(vdev, tx_i.mcast_en.dropped_send_fail,
  7571. host_stats->mcast_en.dropped_send_fail);
  7572. DP_STATS_INC(vdev, tx_i.mcast_en.ucast,
  7573. host_stats->mcast_en.ucast);
  7574. DP_STATS_INC(vdev, tx_i.mcast_en.fail_seg_alloc,
  7575. host_stats->mcast_en.fail_seg_alloc);
  7576. DP_STATS_INC(vdev, tx_i.mcast_en.clone_fail,
  7577. host_stats->mcast_en.clone_fail);
  7578. }
  7579. /* dp_txrx_update_vdev_host_stats(): Update stats sent through CDP
  7580. * @soc: DP soc handle
  7581. * @vdev_id: id of DP vdev handle
  7582. * @buf: buffer containing specific stats structure
  7583. * @stats_id: stats type
  7584. *
  7585. * Returns: QDF_STATUS
  7586. */
  7587. static QDF_STATUS dp_txrx_update_vdev_host_stats(struct cdp_soc_t *soc,
  7588. uint8_t vdev_id,
  7589. void *buf,
  7590. uint16_t stats_id)
  7591. {
  7592. struct dp_vdev *vdev =
  7593. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  7594. vdev_id);
  7595. if (!vdev) {
  7596. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7597. "Invalid vdev handle");
  7598. return QDF_STATUS_E_FAILURE;
  7599. }
  7600. switch (stats_id) {
  7601. case DP_VDEV_STATS_PKT_CNT_ONLY:
  7602. break;
  7603. case DP_VDEV_STATS_TX_ME:
  7604. dp_txrx_update_vdev_me_stats(vdev, buf);
  7605. break;
  7606. default:
  7607. qdf_info("Invalid stats_id %d", stats_id);
  7608. break;
  7609. }
  7610. return QDF_STATUS_SUCCESS;
  7611. }
  7612. /* dp_txrx_get_peer_stats - will return cdp_peer_stats
  7613. * @soc: soc handle
  7614. * @vdev_id: id of vdev handle
  7615. * @peer_mac: mac of DP_PEER handle
  7616. * @peer_stats: buffer to copy to
  7617. * return : status success/failure
  7618. */
  7619. static QDF_STATUS
  7620. dp_txrx_get_peer_stats(struct cdp_soc_t *soc, uint8_t vdev_id,
  7621. uint8_t *peer_mac, struct cdp_peer_stats *peer_stats)
  7622. {
  7623. QDF_STATUS status = QDF_STATUS_SUCCESS;
  7624. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  7625. peer_mac, 0, vdev_id);
  7626. if (!peer || peer->delete_in_progress) {
  7627. status = QDF_STATUS_E_FAILURE;
  7628. } else
  7629. qdf_mem_copy(peer_stats, &peer->stats,
  7630. sizeof(struct cdp_peer_stats));
  7631. if (peer)
  7632. dp_peer_unref_delete(peer);
  7633. return status;
  7634. }
  7635. /* dp_txrx_get_peer_stats_param - will return specified cdp_peer_stats
  7636. * @param soc - soc handle
  7637. * @param vdev_id - vdev_id of vdev object
  7638. * @param peer_mac - mac address of the peer
  7639. * @param type - enum of required stats
  7640. * @param buf - buffer to hold the value
  7641. * return : status success/failure
  7642. */
  7643. static QDF_STATUS
  7644. dp_txrx_get_peer_stats_param(struct cdp_soc_t *soc, uint8_t vdev_id,
  7645. uint8_t *peer_mac, enum cdp_peer_stats_type type,
  7646. cdp_peer_stats_param_t *buf)
  7647. {
  7648. QDF_STATUS ret = QDF_STATUS_SUCCESS;
  7649. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  7650. peer_mac, 0, vdev_id);
  7651. if (!peer || peer->delete_in_progress) {
  7652. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7653. "Invalid Peer for Mac %pM", peer_mac);
  7654. ret = QDF_STATUS_E_FAILURE;
  7655. } else if (type < cdp_peer_stats_max) {
  7656. switch (type) {
  7657. case cdp_peer_tx_ucast:
  7658. buf->tx_ucast = peer->stats.tx.ucast;
  7659. break;
  7660. case cdp_peer_tx_mcast:
  7661. buf->tx_mcast = peer->stats.tx.mcast;
  7662. break;
  7663. case cdp_peer_tx_rate:
  7664. buf->tx_rate = peer->stats.tx.tx_rate;
  7665. break;
  7666. case cdp_peer_tx_last_tx_rate:
  7667. buf->last_tx_rate = peer->stats.tx.last_tx_rate;
  7668. break;
  7669. case cdp_peer_tx_inactive_time:
  7670. buf->tx_inactive_time = peer->stats.tx.inactive_time;
  7671. break;
  7672. case cdp_peer_tx_ratecode:
  7673. buf->tx_ratecode = peer->stats.tx.tx_ratecode;
  7674. break;
  7675. case cdp_peer_tx_flags:
  7676. buf->tx_flags = peer->stats.tx.tx_flags;
  7677. break;
  7678. case cdp_peer_tx_power:
  7679. buf->tx_power = peer->stats.tx.tx_power;
  7680. break;
  7681. case cdp_peer_rx_rate:
  7682. buf->rx_rate = peer->stats.rx.rx_rate;
  7683. break;
  7684. case cdp_peer_rx_last_rx_rate:
  7685. buf->last_rx_rate = peer->stats.rx.last_rx_rate;
  7686. break;
  7687. case cdp_peer_rx_ratecode:
  7688. buf->rx_ratecode = peer->stats.rx.rx_ratecode;
  7689. break;
  7690. case cdp_peer_rx_ucast:
  7691. buf->rx_ucast = peer->stats.rx.unicast;
  7692. break;
  7693. case cdp_peer_rx_flags:
  7694. buf->rx_flags = peer->stats.rx.rx_flags;
  7695. break;
  7696. case cdp_peer_rx_avg_rssi:
  7697. buf->rx_avg_rssi = peer->stats.rx.avg_rssi;
  7698. break;
  7699. default:
  7700. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7701. "Invalid value");
  7702. ret = QDF_STATUS_E_FAILURE;
  7703. break;
  7704. }
  7705. } else {
  7706. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7707. "Invalid value");
  7708. ret = QDF_STATUS_E_FAILURE;
  7709. }
  7710. if (peer)
  7711. dp_peer_unref_delete(peer);
  7712. return ret;
  7713. }
  7714. /* dp_txrx_reset_peer_stats - reset cdp_peer_stats for particular peer
  7715. * @soc: soc handle
  7716. * @vdev_id: id of vdev handle
  7717. * @peer_mac: mac of DP_PEER handle
  7718. *
  7719. * return : QDF_STATUS
  7720. */
  7721. static QDF_STATUS
  7722. dp_txrx_reset_peer_stats(struct cdp_soc_t *soc, uint8_t vdev_id,
  7723. uint8_t *peer_mac)
  7724. {
  7725. QDF_STATUS status = QDF_STATUS_SUCCESS;
  7726. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  7727. peer_mac, 0, vdev_id);
  7728. if (!peer || peer->delete_in_progress) {
  7729. status = QDF_STATUS_E_FAILURE;
  7730. goto fail;
  7731. }
  7732. qdf_mem_zero(&peer->stats, sizeof(peer->stats));
  7733. fail:
  7734. if (peer)
  7735. dp_peer_unref_delete(peer);
  7736. return status;
  7737. }
  7738. /* dp_txrx_get_vdev_stats - Update buffer with cdp_vdev_stats
  7739. * @vdev_handle: DP_VDEV handle
  7740. * @buf: buffer for vdev stats
  7741. *
  7742. * return : int
  7743. */
  7744. static int dp_txrx_get_vdev_stats(struct cdp_soc_t *soc, uint8_t vdev_id,
  7745. void *buf, bool is_aggregate)
  7746. {
  7747. struct cdp_vdev_stats *vdev_stats;
  7748. struct dp_pdev *pdev;
  7749. struct dp_vdev *vdev =
  7750. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  7751. vdev_id);
  7752. if (!vdev)
  7753. return 1;
  7754. pdev = vdev->pdev;
  7755. if (!pdev)
  7756. return 1;
  7757. vdev_stats = (struct cdp_vdev_stats *)buf;
  7758. if (is_aggregate) {
  7759. qdf_spin_lock_bh(&((struct dp_soc *)soc)->peer_ref_mutex);
  7760. dp_aggregate_vdev_stats(vdev, buf);
  7761. qdf_spin_unlock_bh(&((struct dp_soc *)soc)->peer_ref_mutex);
  7762. } else {
  7763. qdf_mem_copy(vdev_stats, &vdev->stats, sizeof(vdev->stats));
  7764. }
  7765. return 0;
  7766. }
  7767. /*
  7768. * dp_get_total_per(): get total per
  7769. * @soc: DP soc handle
  7770. * @pdev_id: id of DP_PDEV handle
  7771. *
  7772. * Return: % error rate using retries per packet and success packets
  7773. */
  7774. static int dp_get_total_per(struct cdp_soc_t *soc, uint8_t pdev_id)
  7775. {
  7776. struct dp_pdev *pdev =
  7777. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  7778. pdev_id);
  7779. if (!pdev)
  7780. return 0;
  7781. dp_aggregate_pdev_stats(pdev);
  7782. if ((pdev->stats.tx.tx_success.num + pdev->stats.tx.retries) == 0)
  7783. return 0;
  7784. return ((pdev->stats.tx.retries * 100) /
  7785. ((pdev->stats.tx.tx_success.num) + (pdev->stats.tx.retries)));
  7786. }
  7787. /*
  7788. * dp_txrx_stats_publish(): publish pdev stats into a buffer
  7789. * @soc: DP soc handle
  7790. * @pdev_id: id of DP_PDEV handle
  7791. * @buf: to hold pdev_stats
  7792. *
  7793. * Return: int
  7794. */
  7795. static int
  7796. dp_txrx_stats_publish(struct cdp_soc_t *soc, uint8_t pdev_id,
  7797. struct cdp_stats_extd *buf)
  7798. {
  7799. struct cdp_txrx_stats_req req = {0,};
  7800. struct dp_pdev *pdev =
  7801. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  7802. pdev_id);
  7803. if (!pdev)
  7804. return TXRX_STATS_LEVEL_OFF;
  7805. dp_aggregate_pdev_stats(pdev);
  7806. req.stats = (enum cdp_stats)HTT_DBG_EXT_STATS_PDEV_TX;
  7807. req.cookie_val = 1;
  7808. dp_h2t_ext_stats_msg_send(pdev, req.stats, req.param0,
  7809. req.param1, req.param2, req.param3, 0,
  7810. req.cookie_val, 0);
  7811. msleep(DP_MAX_SLEEP_TIME);
  7812. req.stats = (enum cdp_stats)HTT_DBG_EXT_STATS_PDEV_RX;
  7813. req.cookie_val = 1;
  7814. dp_h2t_ext_stats_msg_send(pdev, req.stats, req.param0,
  7815. req.param1, req.param2, req.param3, 0,
  7816. req.cookie_val, 0);
  7817. msleep(DP_MAX_SLEEP_TIME);
  7818. qdf_mem_copy(buf, &pdev->stats, sizeof(struct cdp_pdev_stats));
  7819. return TXRX_STATS_LEVEL;
  7820. }
  7821. /**
  7822. * dp_set_pdev_dscp_tid_map_wifi3(): update dscp tid map in pdev
  7823. * @soc: soc handle
  7824. * @pdev_id: id of DP_PDEV handle
  7825. * @map_id: ID of map that needs to be updated
  7826. * @tos: index value in map
  7827. * @tid: tid value passed by the user
  7828. *
  7829. * Return: QDF_STATUS
  7830. */
  7831. static QDF_STATUS
  7832. dp_set_pdev_dscp_tid_map_wifi3(struct cdp_soc_t *soc_handle,
  7833. uint8_t pdev_id,
  7834. uint8_t map_id,
  7835. uint8_t tos, uint8_t tid)
  7836. {
  7837. uint8_t dscp;
  7838. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  7839. struct dp_pdev *pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  7840. if (!pdev)
  7841. return QDF_STATUS_E_FAILURE;
  7842. dscp = (tos >> DP_IP_DSCP_SHIFT) & DP_IP_DSCP_MASK;
  7843. pdev->dscp_tid_map[map_id][dscp] = tid;
  7844. if (map_id < soc->num_hw_dscp_tid_map)
  7845. hal_tx_update_dscp_tid(soc->hal_soc, tid,
  7846. map_id, dscp);
  7847. else
  7848. return QDF_STATUS_E_FAILURE;
  7849. return QDF_STATUS_SUCCESS;
  7850. }
  7851. /**
  7852. * dp_fw_stats_process(): Process TxRX FW stats request
  7853. * @vdev_handle: DP VDEV handle
  7854. * @req: stats request
  7855. *
  7856. * return: int
  7857. */
  7858. static int dp_fw_stats_process(struct dp_vdev *vdev,
  7859. struct cdp_txrx_stats_req *req)
  7860. {
  7861. struct dp_pdev *pdev = NULL;
  7862. uint32_t stats = req->stats;
  7863. uint8_t mac_id = req->mac_id;
  7864. if (!vdev) {
  7865. DP_TRACE(NONE, "VDEV not found");
  7866. return 1;
  7867. }
  7868. pdev = vdev->pdev;
  7869. /*
  7870. * For HTT_DBG_EXT_STATS_RESET command, FW need to config
  7871. * from param0 to param3 according to below rule:
  7872. *
  7873. * PARAM:
  7874. * - config_param0 : start_offset (stats type)
  7875. * - config_param1 : stats bmask from start offset
  7876. * - config_param2 : stats bmask from start offset + 32
  7877. * - config_param3 : stats bmask from start offset + 64
  7878. */
  7879. if (req->stats == CDP_TXRX_STATS_0) {
  7880. req->param0 = HTT_DBG_EXT_STATS_PDEV_TX;
  7881. req->param1 = 0xFFFFFFFF;
  7882. req->param2 = 0xFFFFFFFF;
  7883. req->param3 = 0xFFFFFFFF;
  7884. } else if (req->stats == (uint8_t)HTT_DBG_EXT_STATS_PDEV_TX_MU) {
  7885. req->param0 = HTT_DBG_EXT_STATS_SET_VDEV_MASK(vdev->vdev_id);
  7886. }
  7887. return dp_h2t_ext_stats_msg_send(pdev, stats, req->param0,
  7888. req->param1, req->param2, req->param3,
  7889. 0, 0, mac_id);
  7890. }
  7891. /**
  7892. * dp_txrx_stats_request - function to map to firmware and host stats
  7893. * @soc: soc handle
  7894. * @vdev_id: virtual device ID
  7895. * @req: stats request
  7896. *
  7897. * Return: QDF_STATUS
  7898. */
  7899. static
  7900. QDF_STATUS dp_txrx_stats_request(struct cdp_soc_t *soc_handle,
  7901. uint8_t vdev_id,
  7902. struct cdp_txrx_stats_req *req)
  7903. {
  7904. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_handle);
  7905. int host_stats;
  7906. int fw_stats;
  7907. enum cdp_stats stats;
  7908. int num_stats;
  7909. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  7910. vdev_id);
  7911. if (!vdev || !req) {
  7912. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7913. "Invalid vdev/req instance");
  7914. return QDF_STATUS_E_INVAL;
  7915. }
  7916. if (req->mac_id >= WLAN_CFG_MAC_PER_TARGET) {
  7917. dp_err("Invalid mac id request");
  7918. return QDF_STATUS_E_INVAL;
  7919. }
  7920. stats = req->stats;
  7921. if (stats >= CDP_TXRX_MAX_STATS)
  7922. return QDF_STATUS_E_INVAL;
  7923. /*
  7924. * DP_CURR_FW_STATS_AVAIL: no of FW stats currently available
  7925. * has to be updated if new FW HTT stats added
  7926. */
  7927. if (stats > CDP_TXRX_STATS_HTT_MAX)
  7928. stats = stats + DP_CURR_FW_STATS_AVAIL - DP_HTT_DBG_EXT_STATS_MAX;
  7929. num_stats = QDF_ARRAY_SIZE(dp_stats_mapping_table);
  7930. if (stats >= num_stats) {
  7931. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7932. "%s: Invalid stats option: %d", __func__, stats);
  7933. return QDF_STATUS_E_INVAL;
  7934. }
  7935. req->stats = stats;
  7936. fw_stats = dp_stats_mapping_table[stats][STATS_FW];
  7937. host_stats = dp_stats_mapping_table[stats][STATS_HOST];
  7938. dp_info("stats: %u fw_stats_type: %d host_stats: %d",
  7939. stats, fw_stats, host_stats);
  7940. if (fw_stats != TXRX_FW_STATS_INVALID) {
  7941. /* update request with FW stats type */
  7942. req->stats = fw_stats;
  7943. return dp_fw_stats_process(vdev, req);
  7944. }
  7945. if ((host_stats != TXRX_HOST_STATS_INVALID) &&
  7946. (host_stats <= TXRX_HOST_STATS_MAX))
  7947. return dp_print_host_stats(vdev, req);
  7948. else
  7949. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  7950. "Wrong Input for TxRx Stats");
  7951. return QDF_STATUS_SUCCESS;
  7952. }
  7953. /*
  7954. * dp_txrx_dump_stats() - Dump statistics
  7955. * @value - Statistics option
  7956. */
  7957. static QDF_STATUS dp_txrx_dump_stats(struct cdp_soc_t *psoc, uint16_t value,
  7958. enum qdf_stats_verbosity_level level)
  7959. {
  7960. struct dp_soc *soc =
  7961. (struct dp_soc *)psoc;
  7962. QDF_STATUS status = QDF_STATUS_SUCCESS;
  7963. if (!soc) {
  7964. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7965. "%s: soc is NULL", __func__);
  7966. return QDF_STATUS_E_INVAL;
  7967. }
  7968. switch (value) {
  7969. case CDP_TXRX_PATH_STATS:
  7970. dp_txrx_path_stats(soc);
  7971. dp_print_soc_interrupt_stats(soc);
  7972. break;
  7973. case CDP_RX_RING_STATS:
  7974. dp_print_per_ring_stats(soc);
  7975. break;
  7976. case CDP_TXRX_TSO_STATS:
  7977. dp_print_tso_stats(soc, level);
  7978. break;
  7979. case CDP_DUMP_TX_FLOW_POOL_INFO:
  7980. if (level == QDF_STATS_VERBOSITY_LEVEL_HIGH)
  7981. cdp_dump_flow_pool_info((struct cdp_soc_t *)soc);
  7982. break;
  7983. case CDP_DP_NAPI_STATS:
  7984. dp_print_napi_stats(soc);
  7985. break;
  7986. case CDP_TXRX_DESC_STATS:
  7987. /* TODO: NOT IMPLEMENTED */
  7988. break;
  7989. default:
  7990. status = QDF_STATUS_E_INVAL;
  7991. break;
  7992. }
  7993. return status;
  7994. }
  7995. /**
  7996. * dp_txrx_clear_dump_stats() - clear dumpStats
  7997. * @soc- soc handle
  7998. * @value - stats option
  7999. *
  8000. * Return: 0 - Success, non-zero - failure
  8001. */
  8002. static
  8003. QDF_STATUS dp_txrx_clear_dump_stats(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  8004. uint8_t value)
  8005. {
  8006. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  8007. QDF_STATUS status = QDF_STATUS_SUCCESS;
  8008. if (!soc) {
  8009. dp_err("%s: soc is NULL", __func__);
  8010. return QDF_STATUS_E_INVAL;
  8011. }
  8012. switch (value) {
  8013. case CDP_TXRX_TSO_STATS:
  8014. dp_txrx_clear_tso_stats(soc);
  8015. break;
  8016. default:
  8017. status = QDF_STATUS_E_INVAL;
  8018. break;
  8019. }
  8020. return status;
  8021. }
  8022. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  8023. /**
  8024. * dp_update_flow_control_parameters() - API to store datapath
  8025. * config parameters
  8026. * @soc: soc handle
  8027. * @cfg: ini parameter handle
  8028. *
  8029. * Return: void
  8030. */
  8031. static inline
  8032. void dp_update_flow_control_parameters(struct dp_soc *soc,
  8033. struct cdp_config_params *params)
  8034. {
  8035. soc->wlan_cfg_ctx->tx_flow_stop_queue_threshold =
  8036. params->tx_flow_stop_queue_threshold;
  8037. soc->wlan_cfg_ctx->tx_flow_start_queue_offset =
  8038. params->tx_flow_start_queue_offset;
  8039. }
  8040. #else
  8041. static inline
  8042. void dp_update_flow_control_parameters(struct dp_soc *soc,
  8043. struct cdp_config_params *params)
  8044. {
  8045. }
  8046. #endif
  8047. #ifdef WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT
  8048. /* Max packet limit for TX Comp packet loop (dp_tx_comp_handler) */
  8049. #define DP_TX_COMP_LOOP_PKT_LIMIT_MAX 1024
  8050. /* Max packet limit for RX REAP Loop (dp_rx_process) */
  8051. #define DP_RX_REAP_LOOP_PKT_LIMIT_MAX 1024
  8052. static
  8053. void dp_update_rx_soft_irq_limit_params(struct dp_soc *soc,
  8054. struct cdp_config_params *params)
  8055. {
  8056. soc->wlan_cfg_ctx->tx_comp_loop_pkt_limit =
  8057. params->tx_comp_loop_pkt_limit;
  8058. if (params->tx_comp_loop_pkt_limit < DP_TX_COMP_LOOP_PKT_LIMIT_MAX)
  8059. soc->wlan_cfg_ctx->tx_comp_enable_eol_data_check = true;
  8060. else
  8061. soc->wlan_cfg_ctx->tx_comp_enable_eol_data_check = false;
  8062. soc->wlan_cfg_ctx->rx_reap_loop_pkt_limit =
  8063. params->rx_reap_loop_pkt_limit;
  8064. if (params->rx_reap_loop_pkt_limit < DP_RX_REAP_LOOP_PKT_LIMIT_MAX)
  8065. soc->wlan_cfg_ctx->rx_enable_eol_data_check = true;
  8066. else
  8067. soc->wlan_cfg_ctx->rx_enable_eol_data_check = false;
  8068. soc->wlan_cfg_ctx->rx_hp_oos_update_limit =
  8069. params->rx_hp_oos_update_limit;
  8070. dp_info("tx_comp_loop_pkt_limit %u tx_comp_enable_eol_data_check %u rx_reap_loop_pkt_limit %u rx_enable_eol_data_check %u rx_hp_oos_update_limit %u",
  8071. soc->wlan_cfg_ctx->tx_comp_loop_pkt_limit,
  8072. soc->wlan_cfg_ctx->tx_comp_enable_eol_data_check,
  8073. soc->wlan_cfg_ctx->rx_reap_loop_pkt_limit,
  8074. soc->wlan_cfg_ctx->rx_enable_eol_data_check,
  8075. soc->wlan_cfg_ctx->rx_hp_oos_update_limit);
  8076. }
  8077. #else
  8078. static inline
  8079. void dp_update_rx_soft_irq_limit_params(struct dp_soc *soc,
  8080. struct cdp_config_params *params)
  8081. { }
  8082. #endif /* WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT */
  8083. /**
  8084. * dp_update_config_parameters() - API to store datapath
  8085. * config parameters
  8086. * @soc: soc handle
  8087. * @cfg: ini parameter handle
  8088. *
  8089. * Return: status
  8090. */
  8091. static
  8092. QDF_STATUS dp_update_config_parameters(struct cdp_soc *psoc,
  8093. struct cdp_config_params *params)
  8094. {
  8095. struct dp_soc *soc = (struct dp_soc *)psoc;
  8096. if (!(soc)) {
  8097. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  8098. "%s: Invalid handle", __func__);
  8099. return QDF_STATUS_E_INVAL;
  8100. }
  8101. soc->wlan_cfg_ctx->tso_enabled = params->tso_enable;
  8102. soc->wlan_cfg_ctx->lro_enabled = params->lro_enable;
  8103. soc->wlan_cfg_ctx->rx_hash = params->flow_steering_enable;
  8104. soc->wlan_cfg_ctx->tcp_udp_checksumoffload =
  8105. params->tcp_udp_checksumoffload;
  8106. soc->wlan_cfg_ctx->napi_enabled = params->napi_enable;
  8107. soc->wlan_cfg_ctx->ipa_enabled = params->ipa_enable;
  8108. soc->wlan_cfg_ctx->gro_enabled = params->gro_enable;
  8109. dp_update_rx_soft_irq_limit_params(soc, params);
  8110. dp_update_flow_control_parameters(soc, params);
  8111. return QDF_STATUS_SUCCESS;
  8112. }
  8113. static struct cdp_wds_ops dp_ops_wds = {
  8114. .vdev_set_wds = dp_vdev_set_wds,
  8115. #ifdef WDS_VENDOR_EXTENSION
  8116. .txrx_set_wds_rx_policy = dp_txrx_set_wds_rx_policy,
  8117. .txrx_wds_peer_tx_policy_update = dp_txrx_peer_wds_tx_policy_update,
  8118. #endif
  8119. };
  8120. /*
  8121. * dp_txrx_data_tx_cb_set(): set the callback for non standard tx
  8122. * @soc_hdl - datapath soc handle
  8123. * @vdev_id - virtual interface id
  8124. * @callback - callback function
  8125. * @ctxt: callback context
  8126. *
  8127. */
  8128. static void
  8129. dp_txrx_data_tx_cb_set(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  8130. ol_txrx_data_tx_cb callback, void *ctxt)
  8131. {
  8132. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  8133. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  8134. if (!vdev)
  8135. return;
  8136. vdev->tx_non_std_data_callback.func = callback;
  8137. vdev->tx_non_std_data_callback.ctxt = ctxt;
  8138. }
  8139. /**
  8140. * dp_pdev_get_dp_txrx_handle() - get dp handle from pdev
  8141. * @soc: datapath soc handle
  8142. * @pdev_id: id of datapath pdev handle
  8143. *
  8144. * Return: opaque pointer to dp txrx handle
  8145. */
  8146. static void *dp_pdev_get_dp_txrx_handle(struct cdp_soc_t *soc, uint8_t pdev_id)
  8147. {
  8148. struct dp_pdev *pdev =
  8149. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  8150. pdev_id);
  8151. if (qdf_unlikely(!pdev))
  8152. return NULL;
  8153. return pdev->dp_txrx_handle;
  8154. }
  8155. /**
  8156. * dp_pdev_set_dp_txrx_handle() - set dp handle in pdev
  8157. * @soc: datapath soc handle
  8158. * @pdev_id: id of datapath pdev handle
  8159. * @dp_txrx_hdl: opaque pointer for dp_txrx_handle
  8160. *
  8161. * Return: void
  8162. */
  8163. static void
  8164. dp_pdev_set_dp_txrx_handle(struct cdp_soc_t *soc, uint8_t pdev_id,
  8165. void *dp_txrx_hdl)
  8166. {
  8167. struct dp_pdev *pdev =
  8168. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  8169. pdev_id);
  8170. if (!pdev)
  8171. return;
  8172. pdev->dp_txrx_handle = dp_txrx_hdl;
  8173. }
  8174. /**
  8175. * dp_vdev_get_dp_ext_handle() - get dp handle from vdev
  8176. * @soc: datapath soc handle
  8177. * @vdev_id: vdev id
  8178. *
  8179. * Return: opaque pointer to dp txrx handle
  8180. */
  8181. static void *dp_vdev_get_dp_ext_handle(ol_txrx_soc_handle soc, uint8_t vdev_id)
  8182. {
  8183. struct dp_vdev *vdev =
  8184. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  8185. vdev_id);
  8186. if (!vdev)
  8187. return NULL;
  8188. return vdev->vdev_dp_ext_handle;
  8189. }
  8190. /**
  8191. * dp_vdev_set_dp_ext_handle() - set dp handle in vdev
  8192. * @soc: datapath soc handle
  8193. * @vdev_id: vdev id
  8194. * @size: size of advance dp handle
  8195. *
  8196. * Return: QDF_STATUS
  8197. */
  8198. static QDF_STATUS
  8199. dp_vdev_set_dp_ext_handle(ol_txrx_soc_handle soc, uint8_t vdev_id,
  8200. uint16_t size)
  8201. {
  8202. struct dp_vdev *vdev =
  8203. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  8204. vdev_id);
  8205. void *dp_ext_handle;
  8206. if (!vdev)
  8207. return QDF_STATUS_E_FAILURE;
  8208. dp_ext_handle = qdf_mem_malloc(size);
  8209. if (!dp_ext_handle)
  8210. return QDF_STATUS_E_FAILURE;
  8211. vdev->vdev_dp_ext_handle = dp_ext_handle;
  8212. return QDF_STATUS_SUCCESS;
  8213. }
  8214. /**
  8215. * dp_soc_get_dp_txrx_handle() - get context for external-dp from dp soc
  8216. * @soc_handle: datapath soc handle
  8217. *
  8218. * Return: opaque pointer to external dp (non-core DP)
  8219. */
  8220. static void *dp_soc_get_dp_txrx_handle(struct cdp_soc *soc_handle)
  8221. {
  8222. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  8223. return soc->external_txrx_handle;
  8224. }
  8225. /**
  8226. * dp_soc_set_dp_txrx_handle() - set external dp handle in soc
  8227. * @soc_handle: datapath soc handle
  8228. * @txrx_handle: opaque pointer to external dp (non-core DP)
  8229. *
  8230. * Return: void
  8231. */
  8232. static void
  8233. dp_soc_set_dp_txrx_handle(struct cdp_soc *soc_handle, void *txrx_handle)
  8234. {
  8235. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  8236. soc->external_txrx_handle = txrx_handle;
  8237. }
  8238. /**
  8239. * dp_soc_map_pdev_to_lmac() - Save pdev_id to lmac_id mapping
  8240. * @soc_hdl: datapath soc handle
  8241. * @pdev_id: id of the datapath pdev handle
  8242. * @lmac_id: lmac id
  8243. *
  8244. * Return: QDF_STATUS
  8245. */
  8246. static QDF_STATUS
  8247. dp_soc_map_pdev_to_lmac
  8248. (struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  8249. uint32_t lmac_id)
  8250. {
  8251. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  8252. wlan_cfg_set_hw_mac_idx(soc->wlan_cfg_ctx,
  8253. pdev_id,
  8254. lmac_id);
  8255. /*Set host PDEV ID for lmac_id*/
  8256. wlan_cfg_set_pdev_idx(soc->wlan_cfg_ctx,
  8257. pdev_id,
  8258. lmac_id);
  8259. return QDF_STATUS_SUCCESS;
  8260. }
  8261. /**
  8262. * dp_soc_handle_pdev_mode_change() - Update pdev to lmac mapping
  8263. * @soc_hdl: datapath soc handle
  8264. * @pdev_id: id of the datapath pdev handle
  8265. * @lmac_id: lmac id
  8266. *
  8267. * In the event of a dynamic mode change, update the pdev to lmac mapping
  8268. *
  8269. * Return: QDF_STATUS
  8270. */
  8271. static QDF_STATUS
  8272. dp_soc_handle_pdev_mode_change
  8273. (struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  8274. uint32_t lmac_id)
  8275. {
  8276. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  8277. struct dp_vdev *vdev = NULL;
  8278. uint8_t hw_pdev_id, mac_id;
  8279. struct dp_pdev *pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc,
  8280. pdev_id);
  8281. int nss_config = wlan_cfg_get_dp_soc_nss_cfg(soc->wlan_cfg_ctx);
  8282. if (qdf_unlikely(!pdev))
  8283. return QDF_STATUS_E_FAILURE;
  8284. pdev->lmac_id = lmac_id;
  8285. dp_info(" mode change %d %d\n", pdev->pdev_id, pdev->lmac_id);
  8286. /*Set host PDEV ID for lmac_id*/
  8287. wlan_cfg_set_pdev_idx(soc->wlan_cfg_ctx,
  8288. pdev->pdev_id,
  8289. lmac_id);
  8290. hw_pdev_id =
  8291. dp_get_target_pdev_id_for_host_pdev_id(soc,
  8292. pdev->pdev_id);
  8293. /*
  8294. * When NSS offload is enabled, send pdev_id->lmac_id
  8295. * and pdev_id to hw_pdev_id to NSS FW
  8296. */
  8297. if (nss_config) {
  8298. mac_id = pdev->lmac_id;
  8299. if (soc->cdp_soc.ol_ops->pdev_update_lmac_n_target_pdev_id)
  8300. soc->cdp_soc.ol_ops->
  8301. pdev_update_lmac_n_target_pdev_id(
  8302. soc->ctrl_psoc,
  8303. &pdev_id, &mac_id, &hw_pdev_id);
  8304. }
  8305. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  8306. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  8307. HTT_TX_TCL_METADATA_PDEV_ID_SET(vdev->htt_tcl_metadata,
  8308. hw_pdev_id);
  8309. }
  8310. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  8311. return QDF_STATUS_SUCCESS;
  8312. }
  8313. /**
  8314. * dp_soc_set_pdev_status_down() - set pdev down/up status
  8315. * @soc: datapath soc handle
  8316. * @pdev_id: id of datapath pdev handle
  8317. * @is_pdev_down: pdev down/up status
  8318. *
  8319. * Return: QDF_STATUS
  8320. */
  8321. static QDF_STATUS
  8322. dp_soc_set_pdev_status_down(struct cdp_soc_t *soc, uint8_t pdev_id,
  8323. bool is_pdev_down)
  8324. {
  8325. struct dp_pdev *pdev =
  8326. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  8327. pdev_id);
  8328. if (!pdev)
  8329. return QDF_STATUS_E_FAILURE;
  8330. pdev->is_pdev_down = is_pdev_down;
  8331. return QDF_STATUS_SUCCESS;
  8332. }
  8333. /**
  8334. * dp_get_cfg_capabilities() - get dp capabilities
  8335. * @soc_handle: datapath soc handle
  8336. * @dp_caps: enum for dp capabilities
  8337. *
  8338. * Return: bool to determine if dp caps is enabled
  8339. */
  8340. static bool
  8341. dp_get_cfg_capabilities(struct cdp_soc_t *soc_handle,
  8342. enum cdp_capabilities dp_caps)
  8343. {
  8344. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  8345. return wlan_cfg_get_dp_caps(soc->wlan_cfg_ctx, dp_caps);
  8346. }
  8347. #ifdef FEATURE_AST
  8348. static QDF_STATUS
  8349. dp_peer_teardown_wifi3(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  8350. uint8_t *peer_mac)
  8351. {
  8352. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  8353. QDF_STATUS status = QDF_STATUS_SUCCESS;
  8354. struct dp_peer *peer =
  8355. dp_peer_find_hash_find(soc, peer_mac, 0, vdev_id);
  8356. /* Peer can be null for monitor vap mac address */
  8357. if (!peer) {
  8358. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  8359. "%s: Invalid peer\n", __func__);
  8360. return QDF_STATUS_E_FAILURE;
  8361. }
  8362. /*
  8363. * For BSS peer, new peer is not created on alloc_node if the
  8364. * peer with same address already exists , instead refcnt is
  8365. * increased for existing peer. Correspondingly in delete path,
  8366. * only refcnt is decreased; and peer is only deleted , when all
  8367. * references are deleted. So delete_in_progress should not be set
  8368. * for bss_peer, unless only 3 reference remains (peer map reference,
  8369. * peer hash table reference and above local reference).
  8370. */
  8371. if (peer->bss_peer && (qdf_atomic_read(&peer->ref_cnt) > 3)) {
  8372. status = QDF_STATUS_E_FAILURE;
  8373. goto fail;
  8374. }
  8375. qdf_spin_lock_bh(&soc->ast_lock);
  8376. peer->delete_in_progress = true;
  8377. dp_peer_delete_ast_entries(soc, peer);
  8378. qdf_spin_unlock_bh(&soc->ast_lock);
  8379. fail:
  8380. if (peer)
  8381. dp_peer_unref_delete(peer);
  8382. return status;
  8383. }
  8384. #endif
  8385. #ifdef ATH_SUPPORT_NAC_RSSI
  8386. /**
  8387. * dp_vdev_get_neighbour_rssi(): Store RSSI for configured NAC
  8388. * @soc_hdl: DP soc handle
  8389. * @vdev_id: id of DP vdev handle
  8390. * @mac_addr: neighbour mac
  8391. * @rssi: rssi value
  8392. *
  8393. * Return: 0 for success. nonzero for failure.
  8394. */
  8395. static QDF_STATUS dp_vdev_get_neighbour_rssi(struct cdp_soc_t *soc,
  8396. uint8_t vdev_id,
  8397. char *mac_addr,
  8398. uint8_t *rssi)
  8399. {
  8400. struct dp_vdev *vdev =
  8401. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  8402. vdev_id);
  8403. struct dp_pdev *pdev;
  8404. struct dp_neighbour_peer *peer = NULL;
  8405. QDF_STATUS status = QDF_STATUS_E_FAILURE;
  8406. if (!vdev)
  8407. return status;
  8408. pdev = vdev->pdev;
  8409. *rssi = 0;
  8410. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  8411. TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
  8412. neighbour_peer_list_elem) {
  8413. if (qdf_mem_cmp(&peer->neighbour_peers_macaddr.raw[0],
  8414. mac_addr, QDF_MAC_ADDR_SIZE) == 0) {
  8415. *rssi = peer->rssi;
  8416. status = QDF_STATUS_SUCCESS;
  8417. break;
  8418. }
  8419. }
  8420. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  8421. return status;
  8422. }
  8423. static QDF_STATUS
  8424. dp_config_for_nac_rssi(struct cdp_soc_t *cdp_soc,
  8425. uint8_t vdev_id,
  8426. enum cdp_nac_param_cmd cmd, char *bssid,
  8427. char *client_macaddr,
  8428. uint8_t chan_num)
  8429. {
  8430. struct dp_soc *soc = (struct dp_soc *)cdp_soc;
  8431. struct dp_vdev *vdev =
  8432. dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  8433. vdev_id);
  8434. struct dp_pdev *pdev;
  8435. if (!vdev)
  8436. return QDF_STATUS_E_FAILURE;
  8437. pdev = (struct dp_pdev *)vdev->pdev;
  8438. pdev->nac_rssi_filtering = 1;
  8439. /* Store address of NAC (neighbour peer) which will be checked
  8440. * against TA of received packets.
  8441. */
  8442. if (cmd == CDP_NAC_PARAM_ADD) {
  8443. dp_update_filter_neighbour_peers(cdp_soc, vdev->vdev_id,
  8444. DP_NAC_PARAM_ADD,
  8445. (uint8_t *)client_macaddr);
  8446. } else if (cmd == CDP_NAC_PARAM_DEL) {
  8447. dp_update_filter_neighbour_peers(cdp_soc, vdev->vdev_id,
  8448. DP_NAC_PARAM_DEL,
  8449. (uint8_t *)client_macaddr);
  8450. }
  8451. if (soc->cdp_soc.ol_ops->config_bssid_in_fw_for_nac_rssi)
  8452. soc->cdp_soc.ol_ops->config_bssid_in_fw_for_nac_rssi
  8453. (soc->ctrl_psoc, pdev->pdev_id,
  8454. vdev->vdev_id, cmd, bssid, client_macaddr);
  8455. return QDF_STATUS_SUCCESS;
  8456. }
  8457. #endif
  8458. /**
  8459. * dp_enable_peer_based_pktlog() - Set Flag for peer based filtering
  8460. * for pktlog
  8461. * @soc: cdp_soc handle
  8462. * @pdev_id: id of dp pdev handle
  8463. * @mac_addr: Peer mac address
  8464. * @enb_dsb: Enable or disable peer based filtering
  8465. *
  8466. * Return: QDF_STATUS
  8467. */
  8468. static int
  8469. dp_enable_peer_based_pktlog(struct cdp_soc_t *soc, uint8_t pdev_id,
  8470. uint8_t *mac_addr, uint8_t enb_dsb)
  8471. {
  8472. struct dp_peer *peer;
  8473. struct dp_pdev *pdev =
  8474. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  8475. pdev_id);
  8476. if (!pdev) {
  8477. dp_err("Invalid Pdev for pdev_id %d", pdev_id);
  8478. return QDF_STATUS_E_FAILURE;
  8479. }
  8480. peer = (struct dp_peer *)dp_find_peer_by_addr((struct cdp_pdev *)pdev,
  8481. mac_addr);
  8482. if (!peer) {
  8483. dp_err("Invalid Peer");
  8484. return QDF_STATUS_E_FAILURE;
  8485. }
  8486. peer->peer_based_pktlog_filter = enb_dsb;
  8487. pdev->dp_peer_based_pktlog = enb_dsb;
  8488. return QDF_STATUS_SUCCESS;
  8489. }
  8490. #ifndef WLAN_SUPPORT_RX_TAG_STATISTICS
  8491. /**
  8492. * dp_dump_pdev_rx_protocol_tag_stats - dump the number of packets tagged for
  8493. * given protocol type (RX_PROTOCOL_TAG_ALL indicates for all protocol)
  8494. * @soc: cdp_soc handle
  8495. * @pdev_id: id of cdp_pdev handle
  8496. * @protocol_type: protocol type for which stats should be displayed
  8497. *
  8498. * Return: none
  8499. */
  8500. static inline void
  8501. dp_dump_pdev_rx_protocol_tag_stats(struct cdp_soc_t *soc, uint8_t pdev_id,
  8502. uint16_t protocol_type)
  8503. {
  8504. }
  8505. #endif /* WLAN_SUPPORT_RX_TAG_STATISTICS */
  8506. #ifndef WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG
  8507. /**
  8508. * dp_update_pdev_rx_protocol_tag - Add/remove a protocol tag that should be
  8509. * applied to the desired protocol type packets
  8510. * @soc: soc handle
  8511. * @pdev_id: id of cdp_pdev handle
  8512. * @enable_rx_protocol_tag - bitmask that indicates what protocol types
  8513. * are enabled for tagging. zero indicates disable feature, non-zero indicates
  8514. * enable feature
  8515. * @protocol_type: new protocol type for which the tag is being added
  8516. * @tag: user configured tag for the new protocol
  8517. *
  8518. * Return: Success
  8519. */
  8520. static inline QDF_STATUS
  8521. dp_update_pdev_rx_protocol_tag(struct cdp_soc_t *soc, uint8_t pdev_id,
  8522. uint32_t enable_rx_protocol_tag,
  8523. uint16_t protocol_type,
  8524. uint16_t tag)
  8525. {
  8526. return QDF_STATUS_SUCCESS;
  8527. }
  8528. #endif /* WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG */
  8529. #ifndef WLAN_SUPPORT_RX_FLOW_TAG
  8530. /**
  8531. * dp_set_rx_flow_tag - add/delete a flow
  8532. * @soc: soc handle
  8533. * @pdev_id: id of cdp_pdev handle
  8534. * @flow_info: flow tuple that is to be added to/deleted from flow search table
  8535. *
  8536. * Return: Success
  8537. */
  8538. static inline QDF_STATUS
  8539. dp_set_rx_flow_tag(struct cdp_soc_t *cdp_soc, uint8_t pdev_id,
  8540. struct cdp_rx_flow_info *flow_info)
  8541. {
  8542. return QDF_STATUS_SUCCESS;
  8543. }
  8544. /**
  8545. * dp_dump_rx_flow_tag_stats - dump the number of packets tagged for
  8546. * given flow 5-tuple
  8547. * @cdp_soc: soc handle
  8548. * @pdev_id: id of cdp_pdev handle
  8549. * @flow_info: flow 5-tuple for which stats should be displayed
  8550. *
  8551. * Return: Success
  8552. */
  8553. static inline QDF_STATUS
  8554. dp_dump_rx_flow_tag_stats(struct cdp_soc_t *cdp_soc, uint8_t pdev_id,
  8555. struct cdp_rx_flow_info *flow_info)
  8556. {
  8557. return QDF_STATUS_SUCCESS;
  8558. }
  8559. #endif /* WLAN_SUPPORT_RX_FLOW_TAG */
  8560. static QDF_STATUS dp_peer_map_attach_wifi3(struct cdp_soc_t *soc_hdl,
  8561. uint32_t max_peers,
  8562. uint32_t max_ast_index,
  8563. bool peer_map_unmap_v2)
  8564. {
  8565. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  8566. soc->max_peers = max_peers;
  8567. qdf_print ("%s max_peers %u, max_ast_index: %u\n",
  8568. __func__, max_peers, max_ast_index);
  8569. wlan_cfg_set_max_ast_idx(soc->wlan_cfg_ctx, max_ast_index);
  8570. if (dp_peer_find_attach(soc))
  8571. return QDF_STATUS_E_FAILURE;
  8572. soc->is_peer_map_unmap_v2 = peer_map_unmap_v2;
  8573. return QDF_STATUS_SUCCESS;
  8574. }
  8575. static void dp_soc_set_rate_stats_ctx(struct cdp_soc_t *soc_handle,
  8576. void *stats_ctx)
  8577. {
  8578. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  8579. soc->rate_stats_ctx = (struct cdp_soc_rate_stats_ctx *)stats_ctx;
  8580. }
  8581. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  8582. static QDF_STATUS dp_flush_rate_stats_req(struct cdp_soc_t *soc_hdl,
  8583. uint8_t pdev_id)
  8584. {
  8585. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  8586. struct dp_vdev *vdev = NULL;
  8587. struct dp_peer *peer = NULL;
  8588. struct dp_pdev *pdev =
  8589. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  8590. pdev_id);
  8591. if (!pdev)
  8592. return QDF_STATUS_E_FAILURE;
  8593. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  8594. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  8595. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  8596. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  8597. if (peer && !peer->bss_peer)
  8598. dp_wdi_event_handler(
  8599. WDI_EVENT_FLUSH_RATE_STATS_REQ,
  8600. soc, peer->wlanstats_ctx,
  8601. peer->peer_ids[0],
  8602. WDI_NO_VAL, pdev_id);
  8603. }
  8604. }
  8605. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  8606. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  8607. return QDF_STATUS_SUCCESS;
  8608. }
  8609. #else
  8610. static inline QDF_STATUS
  8611. dp_flush_rate_stats_req(struct cdp_soc_t *soc_hdl,
  8612. uint8_t pdev_id)
  8613. {
  8614. return QDF_STATUS_SUCCESS;
  8615. }
  8616. #endif
  8617. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  8618. static QDF_STATUS dp_peer_flush_rate_stats(struct cdp_soc_t *soc,
  8619. uint8_t pdev_id,
  8620. void *buf)
  8621. {
  8622. dp_wdi_event_handler(WDI_EVENT_PEER_FLUSH_RATE_STATS,
  8623. (struct dp_soc *)soc, buf, HTT_INVALID_PEER,
  8624. WDI_NO_VAL, pdev_id);
  8625. return QDF_STATUS_SUCCESS;
  8626. }
  8627. #else
  8628. static inline QDF_STATUS
  8629. dp_peer_flush_rate_stats(struct cdp_soc_t *soc,
  8630. uint8_t pdev_id,
  8631. void *buf)
  8632. {
  8633. return QDF_STATUS_SUCCESS;
  8634. }
  8635. #endif
  8636. static void *dp_soc_get_rate_stats_ctx(struct cdp_soc_t *soc_handle)
  8637. {
  8638. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  8639. return soc->rate_stats_ctx;
  8640. }
  8641. /*
  8642. * dp_get_cfg() - get dp cfg
  8643. * @soc: cdp soc handle
  8644. * @cfg: cfg enum
  8645. *
  8646. * Return: cfg value
  8647. */
  8648. static uint32_t dp_get_cfg(struct cdp_soc_t *soc, enum cdp_dp_cfg cfg)
  8649. {
  8650. struct dp_soc *dpsoc = (struct dp_soc *)soc;
  8651. uint32_t value = 0;
  8652. switch (cfg) {
  8653. case cfg_dp_enable_data_stall:
  8654. value = dpsoc->wlan_cfg_ctx->enable_data_stall_detection;
  8655. break;
  8656. case cfg_dp_enable_ip_tcp_udp_checksum_offload:
  8657. value = dpsoc->wlan_cfg_ctx->tcp_udp_checksumoffload;
  8658. break;
  8659. case cfg_dp_tso_enable:
  8660. value = dpsoc->wlan_cfg_ctx->tso_enabled;
  8661. break;
  8662. case cfg_dp_lro_enable:
  8663. value = dpsoc->wlan_cfg_ctx->lro_enabled;
  8664. break;
  8665. case cfg_dp_gro_enable:
  8666. value = dpsoc->wlan_cfg_ctx->gro_enabled;
  8667. break;
  8668. case cfg_dp_tx_flow_start_queue_offset:
  8669. value = dpsoc->wlan_cfg_ctx->tx_flow_start_queue_offset;
  8670. break;
  8671. case cfg_dp_tx_flow_stop_queue_threshold:
  8672. value = dpsoc->wlan_cfg_ctx->tx_flow_stop_queue_threshold;
  8673. break;
  8674. case cfg_dp_disable_intra_bss_fwd:
  8675. value = dpsoc->wlan_cfg_ctx->disable_intra_bss_fwd;
  8676. break;
  8677. default:
  8678. value = 0;
  8679. }
  8680. return value;
  8681. }
  8682. #ifdef PEER_FLOW_CONTROL
  8683. /**
  8684. * dp_tx_flow_ctrl_configure_pdev() - Configure flow control params
  8685. * @soc_handle: datapath soc handle
  8686. * @pdev_id: id of datapath pdev handle
  8687. * @param: ol ath params
  8688. * @value: value of the flag
  8689. * @buff: Buffer to be passed
  8690. *
  8691. * Implemented this function same as legacy function. In legacy code, single
  8692. * function is used to display stats and update pdev params.
  8693. *
  8694. * Return: 0 for success. nonzero for failure.
  8695. */
  8696. static uint32_t dp_tx_flow_ctrl_configure_pdev(struct cdp_soc_t *soc_handle,
  8697. uint8_t pdev_id,
  8698. enum _ol_ath_param_t param,
  8699. uint32_t value, void *buff)
  8700. {
  8701. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  8702. struct dp_pdev *pdev =
  8703. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  8704. pdev_id);
  8705. if (qdf_unlikely(!pdev))
  8706. return 1;
  8707. soc = pdev->soc;
  8708. if (!soc)
  8709. return 1;
  8710. switch (param) {
  8711. #ifdef QCA_ENH_V3_STATS_SUPPORT
  8712. case OL_ATH_PARAM_VIDEO_DELAY_STATS_FC:
  8713. if (value)
  8714. pdev->delay_stats_flag = true;
  8715. else
  8716. pdev->delay_stats_flag = false;
  8717. break;
  8718. case OL_ATH_PARAM_VIDEO_STATS_FC:
  8719. qdf_print("------- TID Stats ------\n");
  8720. dp_pdev_print_tid_stats(pdev);
  8721. qdf_print("------ Delay Stats ------\n");
  8722. dp_pdev_print_delay_stats(pdev);
  8723. break;
  8724. #endif
  8725. case OL_ATH_PARAM_TOTAL_Q_SIZE:
  8726. {
  8727. uint32_t tx_min, tx_max;
  8728. tx_min = wlan_cfg_get_min_tx_desc(soc->wlan_cfg_ctx);
  8729. tx_max = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  8730. if (!buff) {
  8731. if ((value >= tx_min) && (value <= tx_max)) {
  8732. pdev->num_tx_allowed = value;
  8733. } else {
  8734. QDF_TRACE(QDF_MODULE_ID_DP,
  8735. QDF_TRACE_LEVEL_INFO,
  8736. "Failed to update num_tx_allowed, Q_min = %d Q_max = %d",
  8737. tx_min, tx_max);
  8738. break;
  8739. }
  8740. } else {
  8741. *(int *)buff = pdev->num_tx_allowed;
  8742. }
  8743. }
  8744. break;
  8745. default:
  8746. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  8747. "%s: not handled param %d ", __func__, param);
  8748. break;
  8749. }
  8750. return 0;
  8751. }
  8752. #endif
  8753. /**
  8754. * dp_set_pdev_pcp_tid_map_wifi3(): update pcp tid map in pdev
  8755. * @psoc: dp soc handle
  8756. * @pdev_id: id of DP_PDEV handle
  8757. * @pcp: pcp value
  8758. * @tid: tid value passed by the user
  8759. *
  8760. * Return: QDF_STATUS_SUCCESS on success
  8761. */
  8762. static QDF_STATUS dp_set_pdev_pcp_tid_map_wifi3(ol_txrx_soc_handle psoc,
  8763. uint8_t pdev_id,
  8764. uint8_t pcp, uint8_t tid)
  8765. {
  8766. struct dp_soc *soc = (struct dp_soc *)psoc;
  8767. soc->pcp_tid_map[pcp] = tid;
  8768. hal_tx_update_pcp_tid_map(soc->hal_soc, pcp, tid);
  8769. return QDF_STATUS_SUCCESS;
  8770. }
  8771. /**
  8772. * dp_set_vdev_pcp_tid_map_wifi3(): update pcp tid map in vdev
  8773. * @soc: DP soc handle
  8774. * @vdev_id: id of DP_VDEV handle
  8775. * @pcp: pcp value
  8776. * @tid: tid value passed by the user
  8777. *
  8778. * Return: QDF_STATUS_SUCCESS on success
  8779. */
  8780. static QDF_STATUS dp_set_vdev_pcp_tid_map_wifi3(struct cdp_soc_t *soc,
  8781. uint8_t vdev_id,
  8782. uint8_t pcp, uint8_t tid)
  8783. {
  8784. struct dp_vdev *vdev =
  8785. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  8786. vdev_id);
  8787. if (!vdev)
  8788. return QDF_STATUS_E_FAILURE;
  8789. vdev->pcp_tid_map[pcp] = tid;
  8790. return QDF_STATUS_SUCCESS;
  8791. }
  8792. static struct cdp_cmn_ops dp_ops_cmn = {
  8793. .txrx_soc_attach_target = dp_soc_attach_target_wifi3,
  8794. .txrx_vdev_attach = dp_vdev_attach_wifi3,
  8795. .txrx_vdev_detach = dp_vdev_detach_wifi3,
  8796. .txrx_pdev_attach = dp_pdev_attach_wifi3,
  8797. .txrx_pdev_detach = dp_pdev_detach_wifi3,
  8798. .txrx_pdev_deinit = dp_pdev_deinit_wifi3,
  8799. .txrx_peer_create = dp_peer_create_wifi3,
  8800. .txrx_peer_setup = dp_peer_setup_wifi3,
  8801. #ifdef FEATURE_AST
  8802. .txrx_peer_teardown = dp_peer_teardown_wifi3,
  8803. #else
  8804. .txrx_peer_teardown = NULL,
  8805. #endif
  8806. .txrx_peer_add_ast = dp_peer_add_ast_wifi3,
  8807. .txrx_peer_update_ast = dp_peer_update_ast_wifi3,
  8808. .txrx_peer_get_ast_info_by_soc = dp_peer_get_ast_info_by_soc_wifi3,
  8809. .txrx_peer_get_ast_info_by_pdev =
  8810. dp_peer_get_ast_info_by_pdevid_wifi3,
  8811. .txrx_peer_ast_delete_by_soc =
  8812. dp_peer_ast_entry_del_by_soc,
  8813. .txrx_peer_ast_delete_by_pdev =
  8814. dp_peer_ast_entry_del_by_pdev,
  8815. .txrx_peer_delete = dp_peer_delete_wifi3,
  8816. .txrx_vdev_register = dp_vdev_register_wifi3,
  8817. .txrx_soc_detach = dp_soc_detach_wifi3,
  8818. .txrx_soc_deinit = dp_soc_deinit_wifi3,
  8819. .txrx_soc_init = dp_soc_init_wifi3,
  8820. .txrx_tso_soc_attach = dp_tso_soc_attach,
  8821. .txrx_tso_soc_detach = dp_tso_soc_detach,
  8822. .txrx_get_vdev_mac_addr = dp_get_vdev_mac_addr_wifi3,
  8823. .txrx_get_mon_vdev_from_pdev = dp_get_mon_vdev_from_pdev_wifi3,
  8824. .txrx_get_ctrl_pdev_from_vdev = dp_get_ctrl_pdev_from_vdev_wifi3,
  8825. .txrx_ath_getstats = dp_get_device_stats,
  8826. .addba_requestprocess = dp_addba_requestprocess_wifi3,
  8827. .addba_responsesetup = dp_addba_responsesetup_wifi3,
  8828. .addba_resp_tx_completion = dp_addba_resp_tx_completion_wifi3,
  8829. .delba_process = dp_delba_process_wifi3,
  8830. .set_addba_response = dp_set_addba_response,
  8831. .flush_cache_rx_queue = NULL,
  8832. /* TODO: get API's for dscp-tid need to be added*/
  8833. .set_vdev_dscp_tid_map = dp_set_vdev_dscp_tid_map_wifi3,
  8834. .set_pdev_dscp_tid_map = dp_set_pdev_dscp_tid_map_wifi3,
  8835. .txrx_get_total_per = dp_get_total_per,
  8836. .txrx_stats_request = dp_txrx_stats_request,
  8837. .txrx_set_monitor_mode = dp_vdev_set_monitor_mode,
  8838. .txrx_get_peer_mac_from_peer_id = dp_get_peer_mac_from_peer_id,
  8839. .display_stats = dp_txrx_dump_stats,
  8840. .txrx_intr_attach = dp_soc_interrupt_attach_wrapper,
  8841. .txrx_intr_detach = dp_soc_interrupt_detach,
  8842. .set_pn_check = dp_set_pn_check_wifi3,
  8843. .update_config_parameters = dp_update_config_parameters,
  8844. /* TODO: Add other functions */
  8845. .txrx_data_tx_cb_set = dp_txrx_data_tx_cb_set,
  8846. .get_dp_txrx_handle = dp_pdev_get_dp_txrx_handle,
  8847. .set_dp_txrx_handle = dp_pdev_set_dp_txrx_handle,
  8848. .get_vdev_dp_ext_txrx_handle = dp_vdev_get_dp_ext_handle,
  8849. .set_vdev_dp_ext_txrx_handle = dp_vdev_set_dp_ext_handle,
  8850. .get_soc_dp_txrx_handle = dp_soc_get_dp_txrx_handle,
  8851. .set_soc_dp_txrx_handle = dp_soc_set_dp_txrx_handle,
  8852. .map_pdev_to_lmac = dp_soc_map_pdev_to_lmac,
  8853. .handle_mode_change = dp_soc_handle_pdev_mode_change,
  8854. .set_pdev_status_down = dp_soc_set_pdev_status_down,
  8855. .txrx_set_ba_aging_timeout = dp_set_ba_aging_timeout,
  8856. .txrx_get_ba_aging_timeout = dp_get_ba_aging_timeout,
  8857. .tx_send = dp_tx_send,
  8858. .txrx_peer_reset_ast = dp_wds_reset_ast_wifi3,
  8859. .txrx_peer_reset_ast_table = dp_wds_reset_ast_table_wifi3,
  8860. .txrx_peer_flush_ast_table = dp_wds_flush_ast_table_wifi3,
  8861. .txrx_peer_map_attach = dp_peer_map_attach_wifi3,
  8862. .txrx_get_os_rx_handles_from_vdev =
  8863. dp_get_os_rx_handles_from_vdev_wifi3,
  8864. .delba_tx_completion = dp_delba_tx_completion_wifi3,
  8865. .get_dp_capabilities = dp_get_cfg_capabilities,
  8866. .txrx_get_cfg = dp_get_cfg,
  8867. .set_rate_stats_ctx = dp_soc_set_rate_stats_ctx,
  8868. .get_rate_stats_ctx = dp_soc_get_rate_stats_ctx,
  8869. .txrx_peer_flush_rate_stats = dp_peer_flush_rate_stats,
  8870. .txrx_flush_rate_stats_request = dp_flush_rate_stats_req,
  8871. .set_pdev_pcp_tid_map = dp_set_pdev_pcp_tid_map_wifi3,
  8872. .set_vdev_pcp_tid_map = dp_set_vdev_pcp_tid_map_wifi3,
  8873. .txrx_cp_peer_del_response = dp_cp_peer_del_resp_handler,
  8874. #ifdef QCA_MULTIPASS_SUPPORT
  8875. .set_vlan_groupkey = dp_set_vlan_groupkey,
  8876. #endif
  8877. .get_peer_mac_list = dp_get_peer_mac_list,
  8878. .tx_send_exc = dp_tx_send_exception,
  8879. };
  8880. static struct cdp_ctrl_ops dp_ops_ctrl = {
  8881. .txrx_peer_authorize = dp_peer_authorize,
  8882. .txrx_set_vdev_param = dp_set_vdev_param,
  8883. .txrx_set_psoc_param = dp_set_psoc_param,
  8884. .txrx_get_psoc_param = dp_get_psoc_param,
  8885. .txrx_set_pdev_reo_dest = dp_set_pdev_reo_dest,
  8886. .txrx_get_pdev_reo_dest = dp_get_pdev_reo_dest,
  8887. .txrx_update_filter_neighbour_peers =
  8888. dp_update_filter_neighbour_peers,
  8889. .txrx_get_sec_type = dp_get_sec_type,
  8890. .txrx_wdi_event_sub = dp_wdi_event_sub,
  8891. .txrx_wdi_event_unsub = dp_wdi_event_unsub,
  8892. #ifdef WDI_EVENT_ENABLE
  8893. .txrx_get_pldev = dp_get_pldev,
  8894. #endif
  8895. .txrx_set_pdev_param = dp_set_pdev_param,
  8896. .txrx_get_pdev_param = dp_get_pdev_param,
  8897. .txrx_set_peer_param = dp_set_peer_param,
  8898. .txrx_get_peer_param = dp_get_peer_param,
  8899. #ifdef ATH_SUPPORT_NAC_RSSI
  8900. .txrx_vdev_config_for_nac_rssi = dp_config_for_nac_rssi,
  8901. .txrx_vdev_get_neighbour_rssi = dp_vdev_get_neighbour_rssi,
  8902. #endif
  8903. .set_key = dp_set_michael_key,
  8904. .txrx_get_vdev_param = dp_get_vdev_param,
  8905. .enable_peer_based_pktlog = dp_enable_peer_based_pktlog,
  8906. .calculate_delay_stats = dp_calculate_delay_stats,
  8907. #ifdef WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG
  8908. .txrx_update_pdev_rx_protocol_tag = dp_update_pdev_rx_protocol_tag,
  8909. #ifdef WLAN_SUPPORT_RX_TAG_STATISTICS
  8910. .txrx_dump_pdev_rx_protocol_tag_stats =
  8911. dp_dump_pdev_rx_protocol_tag_stats,
  8912. #endif /* WLAN_SUPPORT_RX_TAG_STATISTICS */
  8913. #endif /* WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG */
  8914. #ifdef WLAN_SUPPORT_RX_FLOW_TAG
  8915. .txrx_set_rx_flow_tag = dp_set_rx_flow_tag,
  8916. .txrx_dump_rx_flow_tag_stats = dp_dump_rx_flow_tag_stats,
  8917. #endif /* WLAN_SUPPORT_RX_FLOW_TAG */
  8918. #ifdef QCA_MULTIPASS_SUPPORT
  8919. .txrx_peer_set_vlan_id = dp_peer_set_vlan_id,
  8920. #endif /*QCA_MULTIPASS_SUPPORT*/
  8921. #if defined(WLAN_TX_PKT_CAPTURE_ENH) || defined(WLAN_RX_PKT_CAPTURE_ENH)
  8922. .txrx_update_peer_pkt_capture_params =
  8923. dp_peer_update_pkt_capture_params,
  8924. #endif /* WLAN_TX_PKT_CAPTURE_ENH || WLAN_RX_PKT_CAPTURE_ENH */
  8925. };
  8926. static struct cdp_me_ops dp_ops_me = {
  8927. #ifdef ATH_SUPPORT_IQUE
  8928. .tx_me_alloc_descriptor = dp_tx_me_alloc_descriptor,
  8929. .tx_me_free_descriptor = dp_tx_me_free_descriptor,
  8930. .tx_me_convert_ucast = dp_tx_me_send_convert_ucast,
  8931. #endif
  8932. };
  8933. static struct cdp_mon_ops dp_ops_mon = {
  8934. .txrx_reset_monitor_mode = dp_reset_monitor_mode,
  8935. /* Added support for HK advance filter */
  8936. .txrx_set_advance_monitor_filter = dp_pdev_set_advance_monitor_filter,
  8937. .txrx_deliver_tx_mgmt = dp_deliver_tx_mgmt,
  8938. };
  8939. static struct cdp_host_stats_ops dp_ops_host_stats = {
  8940. .txrx_per_peer_stats = dp_get_host_peer_stats,
  8941. .get_fw_peer_stats = dp_get_fw_peer_stats,
  8942. .get_htt_stats = dp_get_htt_stats,
  8943. .txrx_enable_enhanced_stats = dp_enable_enhanced_stats,
  8944. .txrx_disable_enhanced_stats = dp_disable_enhanced_stats,
  8945. .txrx_stats_publish = dp_txrx_stats_publish,
  8946. .txrx_get_vdev_stats = dp_txrx_get_vdev_stats,
  8947. .txrx_get_peer_stats = dp_txrx_get_peer_stats,
  8948. .txrx_get_peer_stats_param = dp_txrx_get_peer_stats_param,
  8949. .txrx_reset_peer_stats = dp_txrx_reset_peer_stats,
  8950. .txrx_get_pdev_stats = dp_txrx_get_pdev_stats,
  8951. .txrx_get_ratekbps = dp_txrx_get_ratekbps,
  8952. .txrx_update_vdev_stats = dp_txrx_update_vdev_host_stats,
  8953. /* TODO */
  8954. };
  8955. static struct cdp_raw_ops dp_ops_raw = {
  8956. /* TODO */
  8957. };
  8958. #ifdef PEER_FLOW_CONTROL
  8959. static struct cdp_pflow_ops dp_ops_pflow = {
  8960. dp_tx_flow_ctrl_configure_pdev,
  8961. };
  8962. #endif /* CONFIG_WIN */
  8963. #if defined(WLAN_CFR_ENABLE) && defined(WLAN_ENH_CFR_ENABLE)
  8964. static struct cdp_cfr_ops dp_ops_cfr = {
  8965. .txrx_cfr_filter = dp_cfr_filter,
  8966. .txrx_get_cfr_rcc = dp_get_cfr_rcc,
  8967. .txrx_set_cfr_rcc = dp_set_cfr_rcc,
  8968. };
  8969. #endif
  8970. #ifdef FEATURE_RUNTIME_PM
  8971. /**
  8972. * dp_runtime_suspend() - ensure DP is ready to runtime suspend
  8973. * @soc_hdl: Datapath soc handle
  8974. * @pdev_id: id of data path pdev handle
  8975. *
  8976. * DP is ready to runtime suspend if there are no pending TX packets.
  8977. *
  8978. * Return: QDF_STATUS
  8979. */
  8980. static QDF_STATUS dp_runtime_suspend(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  8981. {
  8982. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  8983. struct dp_pdev *pdev;
  8984. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  8985. if (!pdev) {
  8986. dp_err("pdev is NULL");
  8987. return QDF_STATUS_E_INVAL;
  8988. }
  8989. /* Abort if there are any pending TX packets */
  8990. if (dp_get_tx_pending(dp_pdev_to_cdp_pdev(pdev)) > 0) {
  8991. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  8992. FL("Abort suspend due to pending TX packets"));
  8993. return QDF_STATUS_E_AGAIN;
  8994. }
  8995. if (soc->intr_mode == DP_INTR_POLL)
  8996. qdf_timer_stop(&soc->int_timer);
  8997. return QDF_STATUS_SUCCESS;
  8998. }
  8999. /**
  9000. * dp_flush_ring_hptp() - Update ring shadow
  9001. * register HP/TP address when runtime
  9002. * resume
  9003. * @opaque_soc: DP soc context
  9004. *
  9005. * Return: None
  9006. */
  9007. static
  9008. void dp_flush_ring_hptp(struct dp_soc *soc, hal_ring_handle_t hal_srng)
  9009. {
  9010. if (hal_srng && hal_srng_get_clear_event(hal_srng,
  9011. HAL_SRNG_FLUSH_EVENT)) {
  9012. /* Acquire the lock */
  9013. hal_srng_access_start(soc->hal_soc, hal_srng);
  9014. hal_srng_access_end(soc->hal_soc, hal_srng);
  9015. hal_srng_set_flush_last_ts(hal_srng);
  9016. }
  9017. }
  9018. /**
  9019. * dp_runtime_resume() - ensure DP is ready to runtime resume
  9020. * @soc_hdl: Datapath soc handle
  9021. * @pdev_id: id of data path pdev handle
  9022. *
  9023. * Resume DP for runtime PM.
  9024. *
  9025. * Return: QDF_STATUS
  9026. */
  9027. static QDF_STATUS dp_runtime_resume(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  9028. {
  9029. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9030. int i;
  9031. if (soc->intr_mode == DP_INTR_POLL)
  9032. qdf_timer_mod(&soc->int_timer, DP_INTR_POLL_TIMER_MS);
  9033. for (i = 0; i < MAX_TCL_DATA_RINGS; i++) {
  9034. dp_flush_ring_hptp(soc, soc->tcl_data_ring[i].hal_srng);
  9035. }
  9036. dp_flush_ring_hptp(soc, soc->reo_cmd_ring.hal_srng);
  9037. return QDF_STATUS_SUCCESS;
  9038. }
  9039. #endif /* FEATURE_RUNTIME_PM */
  9040. /**
  9041. * dp_tx_get_success_ack_stats() - get tx success completion count
  9042. * @soc_hdl: Datapath soc handle
  9043. * @vdevid: vdev identifier
  9044. *
  9045. * Return: tx success ack count
  9046. */
  9047. static uint32_t dp_tx_get_success_ack_stats(struct cdp_soc_t *soc_hdl,
  9048. uint8_t vdev_id)
  9049. {
  9050. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9051. struct cdp_vdev_stats *vdev_stats = NULL;
  9052. uint32_t tx_success;
  9053. struct dp_vdev *vdev =
  9054. (struct dp_vdev *)dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  9055. vdev_id);
  9056. if (!vdev) {
  9057. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  9058. FL("Invalid vdev id %d"), vdev_id);
  9059. return 0;
  9060. }
  9061. vdev_stats = qdf_mem_malloc_atomic(sizeof(struct cdp_vdev_stats));
  9062. if (!vdev_stats) {
  9063. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  9064. "DP alloc failure - unable to get alloc vdev stats");
  9065. return 0;
  9066. }
  9067. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  9068. dp_aggregate_vdev_stats(vdev, vdev_stats);
  9069. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  9070. tx_success = vdev_stats->tx.tx_success.num;
  9071. qdf_mem_free(vdev_stats);
  9072. return tx_success;
  9073. }
  9074. #ifdef WLAN_SUPPORT_DATA_STALL
  9075. /**
  9076. * dp_register_data_stall_detect_cb() - register data stall callback
  9077. * @soc_hdl: Datapath soc handle
  9078. * @pdev_id: id of data path pdev handle
  9079. * @data_stall_detect_callback: data stall callback function
  9080. *
  9081. * Return: QDF_STATUS Enumeration
  9082. */
  9083. static
  9084. QDF_STATUS dp_register_data_stall_detect_cb(
  9085. struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  9086. data_stall_detect_cb data_stall_detect_callback)
  9087. {
  9088. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9089. struct dp_pdev *pdev;
  9090. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9091. if (!pdev) {
  9092. dp_err("pdev NULL!");
  9093. return QDF_STATUS_E_INVAL;
  9094. }
  9095. pdev->data_stall_detect_callback = data_stall_detect_callback;
  9096. return QDF_STATUS_SUCCESS;
  9097. }
  9098. /**
  9099. * dp_deregister_data_stall_detect_cb() - de-register data stall callback
  9100. * @soc_hdl: Datapath soc handle
  9101. * @pdev_id: id of data path pdev handle
  9102. * @data_stall_detect_callback: data stall callback function
  9103. *
  9104. * Return: QDF_STATUS Enumeration
  9105. */
  9106. static
  9107. QDF_STATUS dp_deregister_data_stall_detect_cb(
  9108. struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  9109. data_stall_detect_cb data_stall_detect_callback)
  9110. {
  9111. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9112. struct dp_pdev *pdev;
  9113. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9114. if (!pdev) {
  9115. dp_err("pdev NULL!");
  9116. return QDF_STATUS_E_INVAL;
  9117. }
  9118. pdev->data_stall_detect_callback = NULL;
  9119. return QDF_STATUS_SUCCESS;
  9120. }
  9121. /**
  9122. * dp_txrx_post_data_stall_event() - post data stall event
  9123. * @soc_hdl: Datapath soc handle
  9124. * @indicator: Module triggering data stall
  9125. * @data_stall_type: data stall event type
  9126. * @pdev_id: pdev id
  9127. * @vdev_id_bitmap: vdev id bitmap
  9128. * @recovery_type: data stall recovery type
  9129. *
  9130. * Return: None
  9131. */
  9132. static void
  9133. dp_txrx_post_data_stall_event(struct cdp_soc_t *soc_hdl,
  9134. enum data_stall_log_event_indicator indicator,
  9135. enum data_stall_log_event_type data_stall_type,
  9136. uint32_t pdev_id, uint32_t vdev_id_bitmap,
  9137. enum data_stall_log_recovery_type recovery_type)
  9138. {
  9139. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9140. struct data_stall_event_info data_stall_info;
  9141. struct dp_pdev *pdev;
  9142. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9143. if (!pdev) {
  9144. dp_err("pdev NULL!");
  9145. return;
  9146. }
  9147. if (!pdev->data_stall_detect_callback) {
  9148. dp_err("data stall cb not registered!");
  9149. return;
  9150. }
  9151. dp_info("data_stall_type: %x pdev_id: %d",
  9152. data_stall_type, pdev_id);
  9153. data_stall_info.indicator = indicator;
  9154. data_stall_info.data_stall_type = data_stall_type;
  9155. data_stall_info.vdev_id_bitmap = vdev_id_bitmap;
  9156. data_stall_info.pdev_id = pdev_id;
  9157. data_stall_info.recovery_type = recovery_type;
  9158. pdev->data_stall_detect_callback(&data_stall_info);
  9159. }
  9160. #endif /* WLAN_SUPPORT_DATA_STALL */
  9161. #ifdef WLAN_FEATURE_STATS_EXT
  9162. /* rx hw stats event wait timeout in ms */
  9163. #define DP_REO_STATUS_STATS_TIMEOUT 1000
  9164. /**
  9165. * dp_txrx_ext_stats_request - request dp txrx extended stats request
  9166. * @soc_hdl: soc handle
  9167. * @pdev_id: pdev id
  9168. * @req: stats request
  9169. *
  9170. * Return: QDF_STATUS
  9171. */
  9172. static QDF_STATUS
  9173. dp_txrx_ext_stats_request(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  9174. struct cdp_txrx_ext_stats *req)
  9175. {
  9176. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  9177. struct dp_pdev *pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9178. if (!pdev) {
  9179. dp_err("pdev is null");
  9180. return QDF_STATUS_E_INVAL;
  9181. }
  9182. dp_aggregate_pdev_stats(pdev);
  9183. req->tx_msdu_enqueue = pdev->stats.tx_i.processed.num;
  9184. req->tx_msdu_overflow = pdev->stats.tx_i.dropped.ring_full;
  9185. req->rx_mpdu_received = soc->ext_stats.rx_mpdu_received;
  9186. req->rx_mpdu_delivered = soc->ext_stats.rx_mpdu_received;
  9187. req->rx_mpdu_missed = soc->ext_stats.rx_mpdu_missed;
  9188. req->rx_mpdu_error = soc->stats.rx.err_ring_pkts -
  9189. soc->stats.rx.rx_frags;
  9190. return QDF_STATUS_SUCCESS;
  9191. }
  9192. /**
  9193. * dp_rx_hw_stats_cb - request rx hw stats response callback
  9194. * @soc: soc handle
  9195. * @cb_ctxt: callback context
  9196. * @reo_status: reo command response status
  9197. *
  9198. * Return: None
  9199. */
  9200. static void dp_rx_hw_stats_cb(struct dp_soc *soc, void *cb_ctxt,
  9201. union hal_reo_status *reo_status)
  9202. {
  9203. struct dp_rx_tid *rx_tid = (struct dp_rx_tid *)cb_ctxt;
  9204. struct hal_reo_queue_status *queue_status = &reo_status->queue_status;
  9205. if (soc->ignore_reo_status_cb) {
  9206. qdf_event_set(&soc->rx_hw_stats_event);
  9207. return;
  9208. }
  9209. if (queue_status->header.status != HAL_REO_CMD_SUCCESS) {
  9210. dp_info("REO stats failure %d for TID %d",
  9211. queue_status->header.status, rx_tid->tid);
  9212. return;
  9213. }
  9214. soc->ext_stats.rx_mpdu_received += queue_status->mpdu_frms_cnt;
  9215. soc->ext_stats.rx_mpdu_missed += queue_status->late_recv_mpdu_cnt;
  9216. if (rx_tid->tid == (DP_MAX_TIDS - 1))
  9217. qdf_event_set(&soc->rx_hw_stats_event);
  9218. }
  9219. /**
  9220. * dp_request_rx_hw_stats - request rx hardware stats
  9221. * @soc_hdl: soc handle
  9222. * @vdev_id: vdev id
  9223. *
  9224. * Return: None
  9225. */
  9226. static void
  9227. dp_request_rx_hw_stats(struct cdp_soc_t *soc_hdl, uint8_t vdev_id)
  9228. {
  9229. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  9230. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  9231. struct dp_peer *peer;
  9232. if (!vdev) {
  9233. dp_err("vdev is null");
  9234. qdf_event_set(&soc->rx_hw_stats_event);
  9235. return;
  9236. }
  9237. peer = vdev->vap_bss_peer;
  9238. if (!peer || peer->delete_in_progress) {
  9239. dp_err("Peer deletion in progress");
  9240. qdf_event_set(&soc->rx_hw_stats_event);
  9241. return;
  9242. }
  9243. qdf_event_reset(&soc->rx_hw_stats_event);
  9244. dp_peer_rxtid_stats(peer, dp_rx_hw_stats_cb, NULL);
  9245. }
  9246. /**
  9247. * dp_wait_for_ext_rx_stats - wait for rx reo status for rx stats
  9248. * @soc_hdl: cdp opaque soc handle
  9249. *
  9250. * Return: status
  9251. */
  9252. static QDF_STATUS
  9253. dp_wait_for_ext_rx_stats(struct cdp_soc_t *soc_hdl)
  9254. {
  9255. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  9256. QDF_STATUS status;
  9257. status = qdf_wait_single_event(&soc->rx_hw_stats_event,
  9258. DP_REO_STATUS_STATS_TIMEOUT);
  9259. return status;
  9260. }
  9261. #endif /* WLAN_FEATURE_STATS_EXT */
  9262. #ifdef DP_PEER_EXTENDED_API
  9263. static struct cdp_misc_ops dp_ops_misc = {
  9264. #ifdef FEATURE_WLAN_TDLS
  9265. .tx_non_std = dp_tx_non_std,
  9266. #endif /* FEATURE_WLAN_TDLS */
  9267. .get_opmode = dp_get_opmode,
  9268. #ifdef FEATURE_RUNTIME_PM
  9269. .runtime_suspend = dp_runtime_suspend,
  9270. .runtime_resume = dp_runtime_resume,
  9271. #endif /* FEATURE_RUNTIME_PM */
  9272. .pkt_log_init = dp_pkt_log_init,
  9273. .pkt_log_con_service = dp_pkt_log_con_service,
  9274. .get_num_rx_contexts = dp_get_num_rx_contexts,
  9275. .get_tx_ack_stats = dp_tx_get_success_ack_stats,
  9276. #ifdef WLAN_SUPPORT_DATA_STALL
  9277. .txrx_data_stall_cb_register = dp_register_data_stall_detect_cb,
  9278. .txrx_data_stall_cb_deregister = dp_deregister_data_stall_detect_cb,
  9279. .txrx_post_data_stall_event = dp_txrx_post_data_stall_event,
  9280. #endif
  9281. #ifdef WLAN_FEATURE_STATS_EXT
  9282. .txrx_ext_stats_request = dp_txrx_ext_stats_request,
  9283. .request_rx_hw_stats = dp_request_rx_hw_stats,
  9284. .wait_for_ext_rx_stats = dp_wait_for_ext_rx_stats,
  9285. #endif
  9286. };
  9287. #endif
  9288. #ifdef DP_FLOW_CTL
  9289. static struct cdp_flowctl_ops dp_ops_flowctl = {
  9290. /* WIFI 3.0 DP implement as required. */
  9291. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  9292. .flow_pool_map_handler = dp_tx_flow_pool_map,
  9293. .flow_pool_unmap_handler = dp_tx_flow_pool_unmap,
  9294. .register_pause_cb = dp_txrx_register_pause_cb,
  9295. .dump_flow_pool_info = dp_tx_dump_flow_pool_info,
  9296. .tx_desc_thresh_reached = dp_tx_desc_thresh_reached,
  9297. #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */
  9298. };
  9299. static struct cdp_lflowctl_ops dp_ops_l_flowctl = {
  9300. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  9301. };
  9302. #endif
  9303. #ifdef IPA_OFFLOAD
  9304. static struct cdp_ipa_ops dp_ops_ipa = {
  9305. .ipa_get_resource = dp_ipa_get_resource,
  9306. .ipa_set_doorbell_paddr = dp_ipa_set_doorbell_paddr,
  9307. .ipa_op_response = dp_ipa_op_response,
  9308. .ipa_register_op_cb = dp_ipa_register_op_cb,
  9309. .ipa_get_stat = dp_ipa_get_stat,
  9310. .ipa_tx_data_frame = dp_tx_send_ipa_data_frame,
  9311. .ipa_enable_autonomy = dp_ipa_enable_autonomy,
  9312. .ipa_disable_autonomy = dp_ipa_disable_autonomy,
  9313. .ipa_setup = dp_ipa_setup,
  9314. .ipa_cleanup = dp_ipa_cleanup,
  9315. .ipa_setup_iface = dp_ipa_setup_iface,
  9316. .ipa_cleanup_iface = dp_ipa_cleanup_iface,
  9317. .ipa_enable_pipes = dp_ipa_enable_pipes,
  9318. .ipa_disable_pipes = dp_ipa_disable_pipes,
  9319. .ipa_set_perf_level = dp_ipa_set_perf_level,
  9320. .ipa_rx_intrabss_fwd = dp_ipa_rx_intrabss_fwd
  9321. };
  9322. #endif
  9323. #ifdef DP_POWER_SAVE
  9324. static QDF_STATUS dp_bus_suspend(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  9325. {
  9326. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9327. struct cdp_pdev *pdev = (struct cdp_pdev *)
  9328. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9329. int timeout = SUSPEND_DRAIN_WAIT;
  9330. int drain_wait_delay = 50; /* 50 ms */
  9331. if (qdf_unlikely(!pdev)) {
  9332. dp_err("pdev is NULL");
  9333. return QDF_STATUS_E_INVAL;
  9334. }
  9335. /* Abort if there are any pending TX packets */
  9336. while (dp_get_tx_pending(pdev) > 0) {
  9337. qdf_sleep(drain_wait_delay);
  9338. if (timeout <= 0) {
  9339. dp_err("TX frames are pending, abort suspend");
  9340. return QDF_STATUS_E_TIMEOUT;
  9341. }
  9342. timeout = timeout - drain_wait_delay;
  9343. }
  9344. if (soc->intr_mode == DP_INTR_POLL)
  9345. qdf_timer_stop(&soc->int_timer);
  9346. return QDF_STATUS_SUCCESS;
  9347. }
  9348. static QDF_STATUS dp_bus_resume(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  9349. {
  9350. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9351. if (soc->intr_mode == DP_INTR_POLL)
  9352. qdf_timer_mod(&soc->int_timer, DP_INTR_POLL_TIMER_MS);
  9353. return QDF_STATUS_SUCCESS;
  9354. }
  9355. static struct cdp_bus_ops dp_ops_bus = {
  9356. .bus_suspend = dp_bus_suspend,
  9357. .bus_resume = dp_bus_resume
  9358. };
  9359. #endif
  9360. #ifdef DP_FLOW_CTL
  9361. static struct cdp_throttle_ops dp_ops_throttle = {
  9362. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  9363. };
  9364. static struct cdp_cfg_ops dp_ops_cfg = {
  9365. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  9366. };
  9367. #endif
  9368. #ifdef DP_PEER_EXTENDED_API
  9369. static struct cdp_ocb_ops dp_ops_ocb = {
  9370. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  9371. };
  9372. static struct cdp_mob_stats_ops dp_ops_mob_stats = {
  9373. .clear_stats = dp_txrx_clear_dump_stats,
  9374. };
  9375. static struct cdp_peer_ops dp_ops_peer = {
  9376. .register_peer = dp_register_peer,
  9377. .clear_peer = dp_clear_peer,
  9378. .find_peer_exist = dp_find_peer_exist,
  9379. .find_peer_exist_on_vdev = dp_find_peer_exist_on_vdev,
  9380. .find_peer_exist_on_other_vdev = dp_find_peer_exist_on_other_vdev,
  9381. .peer_state_update = dp_peer_state_update,
  9382. .get_vdevid = dp_get_vdevid,
  9383. .get_vdev_by_peer_addr = dp_get_vdev_by_peer_addr,
  9384. .peer_get_peer_mac_addr = dp_peer_get_peer_mac_addr,
  9385. .get_peer_state = dp_get_peer_state,
  9386. };
  9387. #endif
  9388. static struct cdp_ops dp_txrx_ops = {
  9389. .cmn_drv_ops = &dp_ops_cmn,
  9390. .ctrl_ops = &dp_ops_ctrl,
  9391. .me_ops = &dp_ops_me,
  9392. .mon_ops = &dp_ops_mon,
  9393. .host_stats_ops = &dp_ops_host_stats,
  9394. .wds_ops = &dp_ops_wds,
  9395. .raw_ops = &dp_ops_raw,
  9396. #ifdef PEER_FLOW_CONTROL
  9397. .pflow_ops = &dp_ops_pflow,
  9398. #endif /* PEER_FLOW_CONTROL */
  9399. #ifdef DP_PEER_EXTENDED_API
  9400. .misc_ops = &dp_ops_misc,
  9401. .ocb_ops = &dp_ops_ocb,
  9402. .peer_ops = &dp_ops_peer,
  9403. .mob_stats_ops = &dp_ops_mob_stats,
  9404. #endif
  9405. #ifdef DP_FLOW_CTL
  9406. .cfg_ops = &dp_ops_cfg,
  9407. .flowctl_ops = &dp_ops_flowctl,
  9408. .l_flowctl_ops = &dp_ops_l_flowctl,
  9409. .throttle_ops = &dp_ops_throttle,
  9410. #endif
  9411. #ifdef IPA_OFFLOAD
  9412. .ipa_ops = &dp_ops_ipa,
  9413. #endif
  9414. #ifdef DP_POWER_SAVE
  9415. .bus_ops = &dp_ops_bus,
  9416. #endif
  9417. #if defined(WLAN_CFR_ENABLE) && defined(WLAN_ENH_CFR_ENABLE)
  9418. .cfr_ops = &dp_ops_cfr,
  9419. #endif
  9420. };
  9421. /*
  9422. * dp_soc_set_txrx_ring_map()
  9423. * @dp_soc: DP handler for soc
  9424. *
  9425. * Return: Void
  9426. */
  9427. void dp_soc_set_txrx_ring_map(struct dp_soc *soc)
  9428. {
  9429. uint32_t i;
  9430. for (i = 0; i < WLAN_CFG_INT_NUM_CONTEXTS; i++) {
  9431. soc->tx_ring_map[i] = dp_cpu_ring_map[DP_NSS_DEFAULT_MAP][i];
  9432. }
  9433. }
  9434. #if defined(QCA_WIFI_QCA8074) || defined(QCA_WIFI_QCA6018)
  9435. #ifndef QCA_MEM_ATTACH_ON_WIFI3
  9436. /**
  9437. * dp_soc_attach_wifi3() - Attach txrx SOC
  9438. * @ctrl_psoc: Opaque SOC handle from control plane
  9439. * @htc_handle: Opaque HTC handle
  9440. * @hif_handle: Opaque HIF handle
  9441. * @qdf_osdev: QDF device
  9442. * @ol_ops: Offload Operations
  9443. * @device_id: Device ID
  9444. *
  9445. * Return: DP SOC handle on success, NULL on failure
  9446. */
  9447. struct cdp_soc_t *
  9448. dp_soc_attach_wifi3(struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
  9449. struct hif_opaque_softc *hif_handle,
  9450. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev,
  9451. struct ol_if_ops *ol_ops, uint16_t device_id)
  9452. {
  9453. struct dp_soc *dp_soc = NULL;
  9454. dp_soc = dp_soc_attach(ctrl_psoc, htc_handle, qdf_osdev,
  9455. ol_ops, device_id);
  9456. if (!dp_soc)
  9457. return NULL;
  9458. if (!dp_soc_init(dp_soc, htc_handle, hif_handle))
  9459. return NULL;
  9460. return dp_soc_to_cdp_soc_t(dp_soc);
  9461. }
  9462. #else
  9463. /**
  9464. * dp_soc_attach_wifi3() - Attach txrx SOC
  9465. * @ctrl_psoc: Opaque SOC handle from control plane
  9466. * @htc_handle: Opaque HTC handle
  9467. * @hif_handle: Opaque HIF handle
  9468. * @qdf_osdev: QDF device
  9469. * @ol_ops: Offload Operations
  9470. * @device_id: Device ID
  9471. *
  9472. * Return: DP SOC handle on success, NULL on failure
  9473. */
  9474. struct cdp_soc_t *
  9475. dp_soc_attach_wifi3(struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
  9476. struct hif_opaque_softc *hif_handle,
  9477. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev,
  9478. struct ol_if_ops *ol_ops, uint16_t device_id)
  9479. {
  9480. struct dp_soc *dp_soc = NULL;
  9481. dp_soc = dp_soc_attach(ctrl_psoc, htc_handle, qdf_osdev,
  9482. ol_ops, device_id);
  9483. return dp_soc_to_cdp_soc_t(dp_soc);
  9484. }
  9485. #endif
  9486. /**
  9487. * dp_soc_attach() - Attach txrx SOC
  9488. * @ctrl_psoc: Opaque SOC handle from control plane
  9489. * @htc_handle: Opaque HTC handle
  9490. * @qdf_osdev: QDF device
  9491. * @ol_ops: Offload Operations
  9492. * @device_id: Device ID
  9493. *
  9494. * Return: DP SOC handle on success, NULL on failure
  9495. */
  9496. static struct dp_soc *
  9497. dp_soc_attach(struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
  9498. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev,
  9499. struct ol_if_ops *ol_ops, uint16_t device_id)
  9500. {
  9501. int int_ctx;
  9502. struct dp_soc *soc = NULL;
  9503. struct htt_soc *htt_soc;
  9504. soc = qdf_mem_malloc(sizeof(*soc));
  9505. if (!soc) {
  9506. dp_err("DP SOC memory allocation failed");
  9507. goto fail0;
  9508. }
  9509. int_ctx = 0;
  9510. soc->device_id = device_id;
  9511. soc->cdp_soc.ops = &dp_txrx_ops;
  9512. soc->cdp_soc.ol_ops = ol_ops;
  9513. soc->ctrl_psoc = ctrl_psoc;
  9514. soc->osdev = qdf_osdev;
  9515. soc->num_hw_dscp_tid_map = HAL_MAX_HW_DSCP_TID_MAPS;
  9516. wlan_set_srng_cfg(&soc->wlan_srng_cfg);
  9517. qdf_mem_zero(&soc->vdev_id_map, sizeof(soc->vdev_id_map));
  9518. soc->wlan_cfg_ctx = wlan_cfg_soc_attach(soc->ctrl_psoc);
  9519. if (!soc->wlan_cfg_ctx) {
  9520. dp_err("wlan_cfg_ctx failed\n");
  9521. goto fail1;
  9522. }
  9523. dp_soc_set_interrupt_mode(soc);
  9524. htt_soc = htt_soc_attach(soc, htc_handle);
  9525. if (!htt_soc)
  9526. goto fail1;
  9527. soc->htt_handle = htt_soc;
  9528. if (htt_soc_htc_prealloc(htt_soc) != QDF_STATUS_SUCCESS)
  9529. goto fail2;
  9530. return soc;
  9531. fail2:
  9532. htt_soc_detach(htt_soc);
  9533. fail1:
  9534. qdf_mem_free(soc);
  9535. fail0:
  9536. return NULL;
  9537. }
  9538. /**
  9539. * dp_soc_init() - Initialize txrx SOC
  9540. * @dp_soc: Opaque DP SOC handle
  9541. * @htc_handle: Opaque HTC handle
  9542. * @hif_handle: Opaque HIF handle
  9543. *
  9544. * Return: DP SOC handle on success, NULL on failure
  9545. */
  9546. void *dp_soc_init(struct dp_soc *soc, HTC_HANDLE htc_handle,
  9547. struct hif_opaque_softc *hif_handle)
  9548. {
  9549. int target_type;
  9550. struct htt_soc *htt_soc = (struct htt_soc *)soc->htt_handle;
  9551. htt_set_htc_handle(htt_soc, htc_handle);
  9552. soc->hif_handle = hif_handle;
  9553. soc->hal_soc = hif_get_hal_handle(soc->hif_handle);
  9554. if (!soc->hal_soc)
  9555. return NULL;
  9556. htt_soc_initialize(soc->htt_handle, soc->ctrl_psoc,
  9557. htt_get_htc_handle(htt_soc),
  9558. soc->hal_soc, soc->osdev);
  9559. target_type = hal_get_target_type(soc->hal_soc);
  9560. switch (target_type) {
  9561. case TARGET_TYPE_QCA6290:
  9562. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  9563. REO_DST_RING_SIZE_QCA6290);
  9564. soc->ast_override_support = 1;
  9565. soc->da_war_enabled = false;
  9566. break;
  9567. #if defined(QCA_WIFI_QCA6390) || defined(QCA_WIFI_QCA6490) || \
  9568. defined(QCA_WIFI_QCA6750)
  9569. case TARGET_TYPE_QCA6390:
  9570. case TARGET_TYPE_QCA6490:
  9571. case TARGET_TYPE_QCA6750:
  9572. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  9573. REO_DST_RING_SIZE_QCA6290);
  9574. wlan_cfg_set_raw_mode_war(soc->wlan_cfg_ctx, true);
  9575. soc->ast_override_support = 1;
  9576. if (soc->cdp_soc.ol_ops->get_con_mode &&
  9577. soc->cdp_soc.ol_ops->get_con_mode() ==
  9578. QDF_GLOBAL_MONITOR_MODE) {
  9579. int int_ctx;
  9580. for (int_ctx = 0; int_ctx < WLAN_CFG_INT_NUM_CONTEXTS; int_ctx++) {
  9581. soc->wlan_cfg_ctx->int_rx_ring_mask[int_ctx] = 0;
  9582. soc->wlan_cfg_ctx->int_rxdma2host_ring_mask[int_ctx] = 0;
  9583. }
  9584. }
  9585. soc->wlan_cfg_ctx->rxdma1_enable = 0;
  9586. break;
  9587. #endif /* QCA_WIFI_QCA6390 || QCA_WIFI_QCA6490 || QCA_WIFI_QCA6750 */
  9588. case TARGET_TYPE_QCA8074:
  9589. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  9590. REO_DST_RING_SIZE_QCA8074);
  9591. wlan_cfg_set_raw_mode_war(soc->wlan_cfg_ctx, true);
  9592. soc->da_war_enabled = true;
  9593. soc->is_rx_fse_full_cache_invalidate_war_enabled = true;
  9594. break;
  9595. case TARGET_TYPE_QCA8074V2:
  9596. case TARGET_TYPE_QCA6018:
  9597. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  9598. REO_DST_RING_SIZE_QCA8074);
  9599. wlan_cfg_set_raw_mode_war(soc->wlan_cfg_ctx, false);
  9600. soc->hw_nac_monitor_support = 1;
  9601. soc->ast_override_support = 1;
  9602. soc->per_tid_basize_max_tid = 8;
  9603. soc->num_hw_dscp_tid_map = HAL_MAX_HW_DSCP_TID_V2_MAPS;
  9604. soc->da_war_enabled = false;
  9605. soc->is_rx_fse_full_cache_invalidate_war_enabled = true;
  9606. break;
  9607. case TARGET_TYPE_QCN9000:
  9608. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  9609. REO_DST_RING_SIZE_QCN9000);
  9610. soc->ast_override_support = 1;
  9611. soc->da_war_enabled = false;
  9612. wlan_cfg_set_raw_mode_war(soc->wlan_cfg_ctx, false);
  9613. soc->hw_nac_monitor_support = 1;
  9614. soc->per_tid_basize_max_tid = 8;
  9615. soc->num_hw_dscp_tid_map = HAL_MAX_HW_DSCP_TID_V2_MAPS;
  9616. soc->lmac_polled_mode = 1;
  9617. break;
  9618. default:
  9619. qdf_print("%s: Unknown tgt type %d\n", __func__, target_type);
  9620. qdf_assert_always(0);
  9621. break;
  9622. }
  9623. dp_soc_set_interrupt_mode(soc);
  9624. wlan_cfg_fill_interrupt_mask(soc->wlan_cfg_ctx, soc->intr_mode);
  9625. wlan_cfg_set_rx_hash(soc->wlan_cfg_ctx,
  9626. cfg_get(soc->ctrl_psoc, CFG_DP_RX_HASH));
  9627. soc->cce_disable = false;
  9628. qdf_atomic_init(&soc->num_tx_outstanding);
  9629. soc->num_tx_allowed =
  9630. wlan_cfg_get_dp_soc_tx_device_limit(soc->wlan_cfg_ctx);
  9631. if (soc->cdp_soc.ol_ops->get_dp_cfg_param) {
  9632. int ret = soc->cdp_soc.ol_ops->get_dp_cfg_param(soc->ctrl_psoc,
  9633. CDP_CFG_MAX_PEER_ID);
  9634. if (ret != -EINVAL) {
  9635. wlan_cfg_set_max_peer_id(soc->wlan_cfg_ctx, ret);
  9636. }
  9637. ret = soc->cdp_soc.ol_ops->get_dp_cfg_param(soc->ctrl_psoc,
  9638. CDP_CFG_CCE_DISABLE);
  9639. if (ret == 1)
  9640. soc->cce_disable = true;
  9641. }
  9642. qdf_spinlock_create(&soc->peer_ref_mutex);
  9643. qdf_spinlock_create(&soc->ast_lock);
  9644. qdf_spinlock_create(&soc->reo_desc_freelist_lock);
  9645. qdf_list_create(&soc->reo_desc_freelist, REO_DESC_FREELIST_SIZE);
  9646. /* fill the tx/rx cpu ring map*/
  9647. dp_soc_set_txrx_ring_map(soc);
  9648. qdf_spinlock_create(&soc->htt_stats.lock);
  9649. /* initialize work queue for stats processing */
  9650. qdf_create_work(0, &soc->htt_stats.work, htt_t2h_stats_handler, soc);
  9651. return soc;
  9652. }
  9653. /**
  9654. * dp_soc_init_wifi3() - Initialize txrx SOC
  9655. * @soc: Opaque DP SOC handle
  9656. * @ctrl_psoc: Opaque SOC handle from control plane(Unused)
  9657. * @hif_handle: Opaque HIF handle
  9658. * @htc_handle: Opaque HTC handle
  9659. * @qdf_osdev: QDF device (Unused)
  9660. * @ol_ops: Offload Operations (Unused)
  9661. * @device_id: Device ID (Unused)
  9662. *
  9663. * Return: DP SOC handle on success, NULL on failure
  9664. */
  9665. void *dp_soc_init_wifi3(struct cdp_soc_t *soc,
  9666. struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
  9667. struct hif_opaque_softc *hif_handle,
  9668. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev,
  9669. struct ol_if_ops *ol_ops, uint16_t device_id)
  9670. {
  9671. return dp_soc_init((struct dp_soc *)soc, htc_handle, hif_handle);
  9672. }
  9673. #endif
  9674. /*
  9675. * dp_get_pdev_for_mac_id() - Return pdev for mac_id
  9676. *
  9677. * @soc: handle to DP soc
  9678. * @mac_id: MAC id
  9679. *
  9680. * Return: Return pdev corresponding to MAC
  9681. */
  9682. void *dp_get_pdev_for_mac_id(struct dp_soc *soc, uint32_t mac_id)
  9683. {
  9684. if (wlan_cfg_per_pdev_lmac_ring(soc->wlan_cfg_ctx))
  9685. return soc->pdev_list[mac_id];
  9686. /* Typically for MCL as there only 1 PDEV*/
  9687. return soc->pdev_list[0];
  9688. }
  9689. /*
  9690. * dp_is_hw_dbs_enable() - Procedure to check if DBS is supported
  9691. * @soc: DP SoC context
  9692. * @max_mac_rings: No of MAC rings
  9693. *
  9694. * Return: None
  9695. */
  9696. static
  9697. void dp_is_hw_dbs_enable(struct dp_soc *soc,
  9698. int *max_mac_rings)
  9699. {
  9700. bool dbs_enable = false;
  9701. if (soc->cdp_soc.ol_ops->is_hw_dbs_2x2_capable)
  9702. dbs_enable = soc->cdp_soc.ol_ops->
  9703. is_hw_dbs_2x2_capable((void *)soc->ctrl_psoc);
  9704. *max_mac_rings = (dbs_enable)?(*max_mac_rings):1;
  9705. }
  9706. #if defined(WLAN_CFR_ENABLE) && defined(WLAN_ENH_CFR_ENABLE)
  9707. /*
  9708. * dp_cfr_filter() - Configure HOST RX monitor status ring for CFR
  9709. * @soc_hdl: Datapath soc handle
  9710. * @pdev_id: id of data path pdev handle
  9711. * @enable: Enable/Disable CFR
  9712. * @filter_val: Flag to select Filter for monitor mode
  9713. */
  9714. static void dp_cfr_filter(struct cdp_soc_t *soc_hdl,
  9715. uint8_t pdev_id,
  9716. bool enable,
  9717. struct cdp_monitor_filter *filter_val)
  9718. {
  9719. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9720. struct dp_pdev *pdev = NULL;
  9721. struct htt_rx_ring_tlv_filter htt_tlv_filter = {0};
  9722. int max_mac_rings;
  9723. uint8_t mac_id = 0;
  9724. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9725. if (!pdev) {
  9726. dp_err("pdev is NULL");
  9727. return;
  9728. }
  9729. if (pdev->monitor_vdev) {
  9730. dp_info("No action is needed since monitor mode is enabled\n");
  9731. return;
  9732. }
  9733. soc = pdev->soc;
  9734. pdev->cfr_rcc_mode = false;
  9735. max_mac_rings = wlan_cfg_get_num_mac_rings(pdev->wlan_cfg_ctx);
  9736. dp_is_hw_dbs_enable(soc, &max_mac_rings);
  9737. dp_debug("Max_mac_rings %d", max_mac_rings);
  9738. dp_info("enable : %d, mode: 0x%x", enable, filter_val->mode);
  9739. if (enable) {
  9740. pdev->cfr_rcc_mode = true;
  9741. htt_tlv_filter.ppdu_start = 1;
  9742. htt_tlv_filter.ppdu_end = 1;
  9743. htt_tlv_filter.ppdu_end_user_stats = 1;
  9744. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  9745. htt_tlv_filter.ppdu_end_status_done = 1;
  9746. htt_tlv_filter.mpdu_start = 1;
  9747. htt_tlv_filter.offset_valid = false;
  9748. htt_tlv_filter.enable_fp =
  9749. (filter_val->mode & MON_FILTER_PASS) ? 1 : 0;
  9750. htt_tlv_filter.enable_md = 0;
  9751. htt_tlv_filter.enable_mo =
  9752. (filter_val->mode & MON_FILTER_OTHER) ? 1 : 0;
  9753. htt_tlv_filter.fp_mgmt_filter = filter_val->fp_mgmt;
  9754. htt_tlv_filter.fp_ctrl_filter = filter_val->fp_ctrl;
  9755. htt_tlv_filter.fp_data_filter = filter_val->fp_data;
  9756. htt_tlv_filter.mo_mgmt_filter = filter_val->mo_mgmt;
  9757. htt_tlv_filter.mo_ctrl_filter = filter_val->mo_ctrl;
  9758. htt_tlv_filter.mo_data_filter = filter_val->mo_data;
  9759. }
  9760. for (mac_id = 0; mac_id < max_mac_rings; mac_id++) {
  9761. int mac_for_pdev =
  9762. dp_get_mac_id_for_pdev(mac_id,
  9763. pdev->pdev_id);
  9764. htt_h2t_rx_ring_cfg(soc->htt_handle,
  9765. mac_for_pdev,
  9766. soc->rxdma_mon_status_ring[mac_id]
  9767. .hal_srng,
  9768. RXDMA_MONITOR_STATUS,
  9769. RX_DATA_BUFFER_SIZE,
  9770. &htt_tlv_filter);
  9771. }
  9772. }
  9773. /**
  9774. * dp_get_cfr_rcc() - get cfr rcc config
  9775. * @soc_hdl: Datapath soc handle
  9776. * @pdev_id: id of objmgr pdev
  9777. *
  9778. * Return: true/false based on cfr mode setting
  9779. */
  9780. static
  9781. bool dp_get_cfr_rcc(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  9782. {
  9783. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9784. struct dp_pdev *pdev = NULL;
  9785. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9786. if (!pdev) {
  9787. dp_err("pdev is NULL");
  9788. return false;
  9789. }
  9790. return pdev->cfr_rcc_mode;
  9791. }
  9792. /**
  9793. * dp_set_cfr_rcc() - enable/disable cfr rcc config
  9794. * @soc_hdl: Datapath soc handle
  9795. * @pdev_id: id of objmgr pdev
  9796. * @enable: Enable/Disable cfr rcc mode
  9797. *
  9798. * Return: none
  9799. */
  9800. static
  9801. void dp_set_cfr_rcc(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, bool enable)
  9802. {
  9803. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9804. struct dp_pdev *pdev = NULL;
  9805. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9806. if (!pdev) {
  9807. dp_err("pdev is NULL");
  9808. return;
  9809. }
  9810. pdev->cfr_rcc_mode = enable;
  9811. }
  9812. #endif
  9813. /*
  9814. * dp_is_soc_reinit() - Check if soc reinit is true
  9815. * @soc: DP SoC context
  9816. *
  9817. * Return: true or false
  9818. */
  9819. bool dp_is_soc_reinit(struct dp_soc *soc)
  9820. {
  9821. return soc->dp_soc_reinit;
  9822. }
  9823. /*
  9824. * dp_set_pktlog_wifi3() - attach txrx vdev
  9825. * @pdev: Datapath PDEV handle
  9826. * @event: which event's notifications are being subscribed to
  9827. * @enable: WDI event subscribe or not. (True or False)
  9828. *
  9829. * Return: Success, NULL on failure
  9830. */
  9831. #ifdef WDI_EVENT_ENABLE
  9832. int dp_set_pktlog_wifi3(struct dp_pdev *pdev, uint32_t event,
  9833. bool enable)
  9834. {
  9835. struct dp_soc *soc = NULL;
  9836. struct htt_rx_ring_tlv_filter htt_tlv_filter = {0};
  9837. int max_mac_rings = wlan_cfg_get_num_mac_rings
  9838. (pdev->wlan_cfg_ctx);
  9839. uint8_t mac_id = 0;
  9840. soc = pdev->soc;
  9841. dp_is_hw_dbs_enable(soc, &max_mac_rings);
  9842. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  9843. FL("Max_mac_rings %d "),
  9844. max_mac_rings);
  9845. if (enable) {
  9846. switch (event) {
  9847. case WDI_EVENT_RX_DESC:
  9848. if (pdev->monitor_vdev) {
  9849. /* Nothing needs to be done if monitor mode is
  9850. * enabled
  9851. */
  9852. return 0;
  9853. }
  9854. if (pdev->rx_pktlog_mode != DP_RX_PKTLOG_FULL) {
  9855. pdev->rx_pktlog_mode = DP_RX_PKTLOG_FULL;
  9856. htt_tlv_filter.mpdu_start = 1;
  9857. htt_tlv_filter.msdu_start = 1;
  9858. htt_tlv_filter.msdu_end = 1;
  9859. htt_tlv_filter.mpdu_end = 1;
  9860. htt_tlv_filter.packet_header = 1;
  9861. htt_tlv_filter.attention = 1;
  9862. htt_tlv_filter.ppdu_start = 1;
  9863. htt_tlv_filter.ppdu_end = 1;
  9864. htt_tlv_filter.ppdu_end_user_stats = 1;
  9865. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  9866. htt_tlv_filter.ppdu_end_status_done = 1;
  9867. htt_tlv_filter.enable_fp = 1;
  9868. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  9869. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  9870. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  9871. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  9872. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  9873. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  9874. htt_tlv_filter.offset_valid = false;
  9875. for (mac_id = 0; mac_id < max_mac_rings;
  9876. mac_id++) {
  9877. int pdev_id = pdev->pdev_id;
  9878. int mac_for_pdev =
  9879. dp_get_mac_id_for_pdev(mac_id,
  9880. pdev_id);
  9881. /*
  9882. * Obtain LMAC id from pdev for
  9883. * accessing LMAC ring from SOC
  9884. */
  9885. int lmac_id =
  9886. dp_get_lmac_id_for_pdev_id(soc,
  9887. mac_id,
  9888. pdev_id);
  9889. htt_h2t_rx_ring_cfg(soc->htt_handle,
  9890. mac_for_pdev,
  9891. soc->rxdma_mon_status_ring[lmac_id]
  9892. .hal_srng,
  9893. RXDMA_MONITOR_STATUS,
  9894. RX_DATA_BUFFER_SIZE,
  9895. &htt_tlv_filter);
  9896. }
  9897. if (soc->reap_timer_init)
  9898. qdf_timer_mod(&soc->mon_reap_timer,
  9899. DP_INTR_POLL_TIMER_MS);
  9900. }
  9901. break;
  9902. case WDI_EVENT_LITE_RX:
  9903. if (pdev->monitor_vdev) {
  9904. /* Nothing needs to be done if monitor mode is
  9905. * enabled
  9906. */
  9907. return 0;
  9908. }
  9909. if (pdev->rx_pktlog_mode != DP_RX_PKTLOG_LITE) {
  9910. pdev->rx_pktlog_mode = DP_RX_PKTLOG_LITE;
  9911. htt_tlv_filter.ppdu_start = 1;
  9912. htt_tlv_filter.ppdu_end = 1;
  9913. htt_tlv_filter.ppdu_end_user_stats = 1;
  9914. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  9915. htt_tlv_filter.ppdu_end_status_done = 1;
  9916. htt_tlv_filter.mpdu_start = 1;
  9917. htt_tlv_filter.enable_fp = 1;
  9918. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  9919. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  9920. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  9921. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  9922. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  9923. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  9924. htt_tlv_filter.offset_valid = false;
  9925. for (mac_id = 0; mac_id < max_mac_rings;
  9926. mac_id++) {
  9927. int pdev_id = pdev->pdev_id;
  9928. int mac_for_pdev =
  9929. dp_get_mac_id_for_pdev(mac_id,
  9930. pdev_id);
  9931. /*
  9932. * Obtain lmac id from pdev to access
  9933. * the LMAC ring in soc context
  9934. */
  9935. int lmac_id =
  9936. dp_get_lmac_id_for_pdev_id(soc,
  9937. mac_id,
  9938. pdev_id);
  9939. htt_h2t_rx_ring_cfg(soc->htt_handle,
  9940. mac_for_pdev,
  9941. soc->rxdma_mon_status_ring[lmac_id]
  9942. .hal_srng,
  9943. RXDMA_MONITOR_STATUS,
  9944. RX_BUFFER_SIZE_PKTLOG_LITE,
  9945. &htt_tlv_filter);
  9946. }
  9947. if (soc->reap_timer_init)
  9948. qdf_timer_mod(&soc->mon_reap_timer,
  9949. DP_INTR_POLL_TIMER_MS);
  9950. }
  9951. break;
  9952. case WDI_EVENT_LITE_T2H:
  9953. if (pdev->monitor_vdev) {
  9954. /* Nothing needs to be done if monitor mode is
  9955. * enabled
  9956. */
  9957. return 0;
  9958. }
  9959. for (mac_id = 0; mac_id < max_mac_rings; mac_id++) {
  9960. int mac_for_pdev = dp_get_mac_id_for_pdev(
  9961. mac_id, pdev->pdev_id);
  9962. pdev->pktlog_ppdu_stats = true;
  9963. dp_h2t_cfg_stats_msg_send(pdev,
  9964. DP_PPDU_TXLITE_STATS_BITMASK_CFG,
  9965. mac_for_pdev);
  9966. }
  9967. break;
  9968. default:
  9969. /* Nothing needs to be done for other pktlog types */
  9970. break;
  9971. }
  9972. } else {
  9973. switch (event) {
  9974. case WDI_EVENT_RX_DESC:
  9975. case WDI_EVENT_LITE_RX:
  9976. if (pdev->monitor_vdev) {
  9977. /* Nothing needs to be done if monitor mode is
  9978. * enabled
  9979. */
  9980. return 0;
  9981. }
  9982. if (pdev->rx_pktlog_mode != DP_RX_PKTLOG_DISABLED) {
  9983. pdev->rx_pktlog_mode = DP_RX_PKTLOG_DISABLED;
  9984. for (mac_id = 0; mac_id < max_mac_rings;
  9985. mac_id++) {
  9986. int pdev_id = pdev->pdev_id;
  9987. int mac_for_pdev =
  9988. dp_get_mac_id_for_pdev(mac_id,
  9989. pdev_id);
  9990. /*
  9991. * Obtain lmac id from pdev to access
  9992. * the LMAC ring in soc context
  9993. */
  9994. int lmac_id =
  9995. dp_get_lmac_id_for_pdev_id(soc,
  9996. mac_id,
  9997. pdev_id);
  9998. htt_h2t_rx_ring_cfg(soc->htt_handle,
  9999. mac_for_pdev,
  10000. soc->rxdma_mon_status_ring[lmac_id]
  10001. .hal_srng,
  10002. RXDMA_MONITOR_STATUS,
  10003. RX_DATA_BUFFER_SIZE,
  10004. &htt_tlv_filter);
  10005. }
  10006. if (soc->reap_timer_init)
  10007. qdf_timer_stop(&soc->mon_reap_timer);
  10008. }
  10009. break;
  10010. case WDI_EVENT_LITE_T2H:
  10011. if (pdev->monitor_vdev) {
  10012. /* Nothing needs to be done if monitor mode is
  10013. * enabled
  10014. */
  10015. return 0;
  10016. }
  10017. /* To disable HTT_H2T_MSG_TYPE_PPDU_STATS_CFG in FW
  10018. * passing value 0. Once these macros will define in htt
  10019. * header file will use proper macros
  10020. */
  10021. for (mac_id = 0; mac_id < max_mac_rings; mac_id++) {
  10022. int mac_for_pdev =
  10023. dp_get_mac_id_for_pdev(mac_id,
  10024. pdev->pdev_id);
  10025. pdev->pktlog_ppdu_stats = false;
  10026. if (!pdev->enhanced_stats_en && !pdev->tx_sniffer_enable && !pdev->mcopy_mode) {
  10027. dp_h2t_cfg_stats_msg_send(pdev, 0,
  10028. mac_for_pdev);
  10029. } else if (pdev->tx_sniffer_enable || pdev->mcopy_mode) {
  10030. dp_h2t_cfg_stats_msg_send(pdev, DP_PPDU_STATS_CFG_SNIFFER,
  10031. mac_for_pdev);
  10032. } else if (pdev->enhanced_stats_en) {
  10033. dp_h2t_cfg_stats_msg_send(pdev, DP_PPDU_STATS_CFG_ENH_STATS,
  10034. mac_for_pdev);
  10035. }
  10036. }
  10037. break;
  10038. default:
  10039. /* Nothing needs to be done for other pktlog types */
  10040. break;
  10041. }
  10042. }
  10043. return 0;
  10044. }
  10045. #endif
  10046. /**
  10047. * dp_bucket_index() - Return index from array
  10048. *
  10049. * @delay: delay measured
  10050. * @array: array used to index corresponding delay
  10051. *
  10052. * Return: index
  10053. */
  10054. static uint8_t dp_bucket_index(uint32_t delay, uint16_t *array)
  10055. {
  10056. uint8_t i = CDP_DELAY_BUCKET_0;
  10057. for (; i < CDP_DELAY_BUCKET_MAX; i++) {
  10058. if (delay >= array[i] && delay <= array[i + 1])
  10059. return i;
  10060. }
  10061. return (CDP_DELAY_BUCKET_MAX - 1);
  10062. }
  10063. /**
  10064. * dp_fill_delay_buckets() - Fill delay statistics bucket for each
  10065. * type of delay
  10066. *
  10067. * @pdev: pdev handle
  10068. * @delay: delay in ms
  10069. * @tid: tid value
  10070. * @mode: type of tx delay mode
  10071. * @ring_id: ring number
  10072. * Return: pointer to cdp_delay_stats structure
  10073. */
  10074. static struct cdp_delay_stats *
  10075. dp_fill_delay_buckets(struct dp_pdev *pdev, uint32_t delay,
  10076. uint8_t tid, uint8_t mode, uint8_t ring_id)
  10077. {
  10078. uint8_t delay_index = 0;
  10079. struct cdp_tid_tx_stats *tstats =
  10080. &pdev->stats.tid_stats.tid_tx_stats[ring_id][tid];
  10081. struct cdp_tid_rx_stats *rstats =
  10082. &pdev->stats.tid_stats.tid_rx_stats[ring_id][tid];
  10083. /*
  10084. * cdp_fw_to_hw_delay_range
  10085. * Fw to hw delay ranges in milliseconds
  10086. */
  10087. uint16_t cdp_fw_to_hw_delay[CDP_DELAY_BUCKET_MAX] = {
  10088. 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 250, 500};
  10089. /*
  10090. * cdp_sw_enq_delay_range
  10091. * Software enqueue delay ranges in milliseconds
  10092. */
  10093. uint16_t cdp_sw_enq_delay[CDP_DELAY_BUCKET_MAX] = {
  10094. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
  10095. /*
  10096. * cdp_intfrm_delay_range
  10097. * Interframe delay ranges in milliseconds
  10098. */
  10099. uint16_t cdp_intfrm_delay[CDP_DELAY_BUCKET_MAX] = {
  10100. 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60};
  10101. /*
  10102. * Update delay stats in proper bucket
  10103. */
  10104. switch (mode) {
  10105. /* Software Enqueue delay ranges */
  10106. case CDP_DELAY_STATS_SW_ENQ:
  10107. delay_index = dp_bucket_index(delay, cdp_sw_enq_delay);
  10108. tstats->swq_delay.delay_bucket[delay_index]++;
  10109. return &tstats->swq_delay;
  10110. /* Tx Completion delay ranges */
  10111. case CDP_DELAY_STATS_FW_HW_TRANSMIT:
  10112. delay_index = dp_bucket_index(delay, cdp_fw_to_hw_delay);
  10113. tstats->hwtx_delay.delay_bucket[delay_index]++;
  10114. return &tstats->hwtx_delay;
  10115. /* Interframe tx delay ranges */
  10116. case CDP_DELAY_STATS_TX_INTERFRAME:
  10117. delay_index = dp_bucket_index(delay, cdp_intfrm_delay);
  10118. tstats->intfrm_delay.delay_bucket[delay_index]++;
  10119. return &tstats->intfrm_delay;
  10120. /* Interframe rx delay ranges */
  10121. case CDP_DELAY_STATS_RX_INTERFRAME:
  10122. delay_index = dp_bucket_index(delay, cdp_intfrm_delay);
  10123. rstats->intfrm_delay.delay_bucket[delay_index]++;
  10124. return &rstats->intfrm_delay;
  10125. /* Ring reap to indication to network stack */
  10126. case CDP_DELAY_STATS_REAP_STACK:
  10127. delay_index = dp_bucket_index(delay, cdp_intfrm_delay);
  10128. rstats->to_stack_delay.delay_bucket[delay_index]++;
  10129. return &rstats->to_stack_delay;
  10130. default:
  10131. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  10132. "%s Incorrect delay mode: %d", __func__, mode);
  10133. }
  10134. return NULL;
  10135. }
  10136. /**
  10137. * dp_update_delay_stats() - Update delay statistics in structure
  10138. * and fill min, max and avg delay
  10139. *
  10140. * @pdev: pdev handle
  10141. * @delay: delay in ms
  10142. * @tid: tid value
  10143. * @mode: type of tx delay mode
  10144. * @ring id: ring number
  10145. * Return: none
  10146. */
  10147. void dp_update_delay_stats(struct dp_pdev *pdev, uint32_t delay,
  10148. uint8_t tid, uint8_t mode, uint8_t ring_id)
  10149. {
  10150. struct cdp_delay_stats *dstats = NULL;
  10151. /*
  10152. * Delay ranges are different for different delay modes
  10153. * Get the correct index to update delay bucket
  10154. */
  10155. dstats = dp_fill_delay_buckets(pdev, delay, tid, mode, ring_id);
  10156. if (qdf_unlikely(!dstats))
  10157. return;
  10158. if (delay != 0) {
  10159. /*
  10160. * Compute minimum,average and maximum
  10161. * delay
  10162. */
  10163. if (delay < dstats->min_delay)
  10164. dstats->min_delay = delay;
  10165. if (delay > dstats->max_delay)
  10166. dstats->max_delay = delay;
  10167. /*
  10168. * Average over delay measured till now
  10169. */
  10170. if (!dstats->avg_delay)
  10171. dstats->avg_delay = delay;
  10172. else
  10173. dstats->avg_delay = ((delay + dstats->avg_delay) / 2);
  10174. }
  10175. }
  10176. /**
  10177. * dp_get_peer_mac_list(): function to get peer mac list of vdev
  10178. * @soc: Datapath soc handle
  10179. * @vdev_id: vdev id
  10180. * @newmac: Table of the clients mac
  10181. * @mac_cnt: No. of MACs required
  10182. *
  10183. * return: no of clients
  10184. */
  10185. uint16_t dp_get_peer_mac_list(ol_txrx_soc_handle soc, uint8_t vdev_id,
  10186. u_int8_t newmac[][QDF_MAC_ADDR_SIZE],
  10187. u_int16_t mac_cnt)
  10188. {
  10189. struct dp_vdev *vdev =
  10190. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  10191. vdev_id);
  10192. struct dp_soc *dp_soc = (struct dp_soc *)soc;
  10193. struct dp_peer *peer;
  10194. uint16_t new_mac_cnt = 0;
  10195. if (!vdev)
  10196. return new_mac_cnt;
  10197. qdf_spin_lock_bh(&dp_soc->peer_ref_mutex);
  10198. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  10199. if (peer->bss_peer)
  10200. continue;
  10201. if (new_mac_cnt < mac_cnt) {
  10202. WLAN_ADDR_COPY(newmac[new_mac_cnt], peer->mac_addr.raw);
  10203. new_mac_cnt++;
  10204. }
  10205. }
  10206. qdf_spin_unlock_bh(&dp_soc->peer_ref_mutex);
  10207. return new_mac_cnt;
  10208. }