dp_main.c 268 KB

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