dp_main.c 277 KB

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