dp_main.c 266 KB

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