dp_main.c 268 KB

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