dp_main.c 283 KB

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