dp_main.c 278 KB

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