dp_tx_capture.c 194 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269
  1. /*
  2. * Copyright (c) 2017-2021 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 <htt.h>
  19. #include "qdf_trace.h"
  20. #include "qdf_nbuf.h"
  21. #include "dp_peer.h"
  22. #include "dp_types.h"
  23. #include "dp_internal.h"
  24. #include "htt_ppdu_stats.h"
  25. #include "dp_htt.h"
  26. #include "qdf_mem.h" /* qdf_mem_malloc,free */
  27. #include "cdp_txrx_cmn_struct.h"
  28. #include <enet.h>
  29. #include <linux/debugfs.h>
  30. #include <linux/uaccess.h>
  31. #include "qdf_lock.h"
  32. #include "qdf_debugfs.h"
  33. #include "dp_rx.h"
  34. #include "dp_rx_mon.h"
  35. #include "dp_tx_capture.h"
  36. #define NUM_BITS_DWORD 32
  37. #define MAX_MONITOR_HEADER (512)
  38. #define MAX_DUMMY_FRM_BODY (128)
  39. #define DP_BA_ACK_FRAME_SIZE (sizeof(struct ieee80211_ctlframe_addr2) + 36)
  40. #define DP_ACK_FRAME_SIZE (sizeof(struct ieee80211_frame_min_one))
  41. #define DP_CTS_FRAME_SIZE (sizeof(struct ieee80211_frame_min_one))
  42. #define DP_ACKNOACK_FRAME_SIZE (sizeof(struct ieee80211_frame) + 16)
  43. #define DP_MAX_MPDU_64 64
  44. #define DP_NUM_WORDS_PER_PPDU_BITMAP_64 (DP_MAX_MPDU_64 >> 5)
  45. #define DP_NUM_BYTES_PER_PPDU_BITMAP_64 (DP_MAX_MPDU_64 >> 3)
  46. #define DP_NUM_BYTES_PER_PPDU_BITMAP (HAL_RX_MAX_MPDU >> 3)
  47. #define DP_IEEE80211_BAR_CTL_TID_S 12
  48. #define DP_IEEE80211_BAR_CTL_TID_M 0xf
  49. #define DP_IEEE80211_BAR_CTL_POLICY_S 0
  50. #define DP_IEEE80211_BAR_CTL_POLICY_M 0x1
  51. #define DP_IEEE80211_BA_S_SEQ_S 4
  52. #define DP_IEEE80211_BAR_CTL_COMBA 0x0004
  53. #define INVALID_PPDU_ID 0xFFFF
  54. #define MAX_END_TSF 0xFFFFFFFF
  55. #define DP_IEEE80211_CATEGORY_VHT (21)
  56. #define DP_NOACK_SOUNDING_TOKEN_POS (4)
  57. #define DP_NOACK_STOKEN_POS_SHIFT (2)
  58. #define DP_NDPA_TOKEN_POS (16)
  59. #define IEEE80211_FC1_SHIFT (8)
  60. /* Macros to handle sequence number bitmaps */
  61. /* HW generated rts frame flag */
  62. #define SEND_WIFIRTS_LEGACY_E 1
  63. /* HW generated 11 AC static bw flag */
  64. #define SEND_WIFIRTS_11AC_STATIC_BW_E 2
  65. /* HW generated 11 AC dynamic bw flag */
  66. #define SEND_WIFIRTS_11AC_DYNAMIC_BW_E 3
  67. /* HW generated cts frame flag */
  68. #define SEND_WIFICTS2SELF_E 4
  69. /* Size (in bits) of a segment of sequence number bitmap */
  70. #define SEQ_SEG_SZ_BITS(_seqarr) (sizeof(_seqarr[0]) << 3)
  71. /* Array index of a segment of sequence number bitmap */
  72. #define SEQ_SEG_INDEX(_seqarr, _seqno) ((_seqno) / SEQ_SEG_SZ_BITS(_seqarr))
  73. /* Bit mask of a seqno within a segment of sequence bitmap */
  74. #define SEQ_SEG_MSK(_seqseg, _index) \
  75. (1 << ((_index) & ((sizeof(_seqseg) << 3) - 1)))
  76. /* Check seqno bit in a segment of sequence bitmap */
  77. #define SEQ_SEG_BIT(_seqseg, _index) \
  78. ((_seqseg) & SEQ_SEG_MSK((_seqseg), _index))
  79. /* Segment of sequence bitmap containing a given sequence number */
  80. #define SEQ_SEG(_seqarr, _seqno) \
  81. (_seqarr[(_seqno) / (sizeof(_seqarr[0]) << 3)])
  82. /* Check seqno bit in the sequence bitmap */
  83. #define SEQ_BIT(_seqarr, _seqno) \
  84. SEQ_SEG_BIT(SEQ_SEG(_seqarr, (_seqno)), (_seqno))
  85. /* Lower 32 mask for timestamp us as completion path has 32 bits timestamp */
  86. #define LOWER_32_MASK 0xFFFFFFFF
  87. /* Maximum time taken to enqueue next mgmt pkt */
  88. #define MAX_MGMT_ENQ_DELAY 10000
  89. /* Schedule id counter mask in ppdu_id */
  90. #define SCH_ID_MASK 0xFF
  91. #define IEEE80211_IS_ZERO(_a) \
  92. ((_a)[0] == 0x00 && \
  93. (_a)[1] == 0x00 && \
  94. (_a)[2] == 0x00 && \
  95. (_a)[3] == 0x00 && \
  96. (_a)[4] == 0x00 && \
  97. (_a)[5] == 0x00)
  98. /* Maximum number of retries */
  99. #define MAX_RETRY_Q_COUNT 20
  100. #define DP_PEER_TX_TID_INIT_DONE_BIT 0
  101. #ifdef WLAN_TX_PKT_CAPTURE_ENH
  102. #define CHECK_MPDUS_NULL(ptr_val) \
  103. { \
  104. if (qdf_unlikely(ptr_val)) { \
  105. dp_tx_capture_alert( \
  106. "already stored value over written"); \
  107. QDF_BUG(0); \
  108. } \
  109. }
  110. #ifdef WLAN_TX_PKT_CAPTURE_ENH_DEBUG
  111. #define TX_CAP_NBUF_QUEUE_FREE(q_head) \
  112. tx_cap_nbuf_queue_free_test(q_head, __func__, __LINE__)
  113. /**
  114. * check_queue_empty() - check queue is empty if not assert
  115. * @qhead: head of queue
  116. *
  117. * Return: void
  118. */
  119. static inline void check_queue_empty(qdf_nbuf_queue_t *qhead)
  120. {
  121. if (qdf_unlikely(!qdf_nbuf_is_queue_empty(qhead))) {
  122. dp_tx_capture_alert("Queue is not empty len(%d) !!",
  123. qdf_nbuf_queue_len(qhead));
  124. QDF_BUG(0);
  125. }
  126. }
  127. /**
  128. * tx_cap_nbuf_queue_free_test() - free a queue and check queue length matching
  129. * element to be free.
  130. * @qhead: head of queue
  131. * @func: caller name
  132. * @line: line number
  133. *
  134. * Return: QDF status
  135. */
  136. static inline QDF_STATUS
  137. tx_cap_nbuf_queue_free_test(qdf_nbuf_queue_t *qhead,
  138. const char *func, uint32_t line)
  139. {
  140. qdf_nbuf_t buf = NULL;
  141. uint32_t len = 0;
  142. uint32_t actual_len = 0;
  143. if (qhead) {
  144. len = qhead->qlen;
  145. actual_len = qhead->qlen;
  146. }
  147. while ((buf = qdf_nbuf_queue_remove(qhead)) != NULL) {
  148. qdf_nbuf_free(buf);
  149. len--;
  150. }
  151. if (len) {
  152. dp_tx_capture_alert("Error actual len: [u], mem_free len: [%u]\n",
  153. actual_len, len);
  154. QDF_BUG(0);
  155. }
  156. return QDF_STATUS_SUCCESS;
  157. }
  158. /* stats counter */
  159. /**
  160. * dp_tx_cap_stats_msdu_update() - update msdu level stats counter per peer
  161. * @peer: DP PEER object
  162. * @msdu_desc: msdu desc index
  163. * @count: count to update
  164. *
  165. * Return: void
  166. */
  167. static inline
  168. void dp_tx_cap_stats_msdu_update(struct dp_peer *peer,
  169. uint8_t msdu_desc, uint32_t count)
  170. {
  171. struct dp_peer_tx_capture_stats *stats;
  172. stats = &peer->tx_capture.stats;
  173. stats->msdu[msdu_desc] += count;
  174. }
  175. /**
  176. * dp_tx_cap_stats_mpdu_update() - update mpdu level stats counter per peer
  177. * @peer: DP PEER object
  178. * @mpdu_desc: mpdu desc index
  179. * @count: count to update
  180. *
  181. * Return: void
  182. */
  183. static inline
  184. void dp_tx_cap_stats_mpdu_update(struct dp_peer *peer,
  185. uint8_t mpdu_desc, uint32_t count)
  186. {
  187. struct dp_peer_tx_capture_stats *stats;
  188. stats = &peer->tx_capture.stats;
  189. stats->mpdu[mpdu_desc] += count;
  190. }
  191. /**
  192. * dp_tx_capture_print_stats() - print stats counter per peer
  193. * @peer: DP PEER object
  194. *
  195. * Return: void
  196. */
  197. static inline
  198. void dp_tx_capture_print_stats(struct dp_peer *peer)
  199. {
  200. struct dp_peer_tx_capture_stats *stats;
  201. stats = &peer->tx_capture.stats;
  202. DP_PRINT_STATS(" peer_id[%d] MSDU[S:%u E:%u D:%u F:%u DP:%u X:%u] MPDU[T:%u S:%u R:%u A:%u C:%u ST:%u]",
  203. peer->peer_id,
  204. stats->msdu[PEER_MSDU_SUCC],
  205. stats->msdu[PEER_MSDU_ENQ],
  206. stats->msdu[PEER_MSDU_DEQ],
  207. stats->msdu[PEER_MSDU_FLUSH],
  208. stats->msdu[PEER_MSDU_DROP],
  209. stats->msdu[PEER_MSDU_XRETRY],
  210. stats->mpdu[PEER_MPDU_TRI],
  211. stats->mpdu[PEER_MPDU_SUCC],
  212. stats->mpdu[PEER_MPDU_RESTITCH],
  213. stats->mpdu[PEER_MPDU_ARR],
  214. stats->mpdu[PEER_MPDU_CLONE],
  215. stats->mpdu[PEER_MPDU_TO_STACK]);
  216. }
  217. #else
  218. #define TX_CAP_NBUF_QUEUE_FREE(q_head) qdf_nbuf_queue_free(q_head)
  219. /**
  220. * check_queue_empty() - check queue is empty if not assert
  221. * @qhead: head of queue
  222. *
  223. * Return: void
  224. */
  225. static inline void check_queue_empty(qdf_nbuf_queue_t *qhead)
  226. {
  227. }
  228. /**
  229. * dp_tx_cap_stats_msdu_update() - update msdu level stats counter per peer
  230. * @peer: DP PEER object
  231. * @msdu_desc: msdu desc index
  232. * @count: count to update
  233. *
  234. * Return: void
  235. */
  236. static inline
  237. void dp_tx_cap_stats_msdu_update(struct dp_peer *peer,
  238. uint8_t msdu_desc, uint32_t count)
  239. {
  240. }
  241. /**
  242. * dp_tx_cap_stats_mpdu_update() - update mpdu level stats counter per peer
  243. * @peer: DP PEER object
  244. * @mpdu_desc: mpdu desc index
  245. * @count: count to update
  246. *
  247. * Return: void
  248. */
  249. static inline
  250. void dp_tx_cap_stats_mpdu_update(struct dp_peer *peer,
  251. uint8_t mpdu_desc, uint32_t count)
  252. {
  253. }
  254. /**
  255. * dp_tx_capture_print_stats() - print stats counter per peer
  256. * @peer: DP PEER object
  257. *
  258. * Return: void
  259. */
  260. static inline
  261. void dp_tx_capture_print_stats(struct dp_peer *peer)
  262. {
  263. }
  264. #endif
  265. #define DP_TX_PEER_DEL_REF(peer) \
  266. dp_tx_peer_del_ref(__func__, __LINE__, peer)
  267. #define DP_TX_PEER_GET_REF(pdev, peer_id) \
  268. dp_tx_peer_get_ref(__func__, __LINE__, pdev, peer_id)
  269. /**
  270. * dp_tx_peer_del_ref() - delete the reference held by peer
  271. * @func: caller function name
  272. * @line: caller line number
  273. * @peer: DP PEER object
  274. *
  275. * Return: void
  276. */
  277. static inline
  278. void dp_tx_peer_del_ref(const char *func, uint32_t line, struct dp_peer *peer)
  279. {
  280. dp_peer_unref_delete(peer, DP_MOD_ID_TX_CAPTURE);
  281. }
  282. /**
  283. * dp_tx_peer_get_ref() - get the peer reference
  284. * @func: caller function name
  285. * @line: caller line number
  286. * @cur_pdev: DP PDEV object
  287. * @peer_id: peer id
  288. *
  289. * Return: DP PEER object
  290. */
  291. static inline
  292. struct dp_peer *
  293. dp_tx_peer_get_ref(const char *func, uint32_t line, struct dp_pdev *cur_pdev,
  294. uint16_t peer_id)
  295. {
  296. struct dp_peer *peer = NULL;
  297. struct dp_vdev *vdev = NULL;
  298. struct dp_pdev *pdev = NULL;
  299. if (qdf_unlikely(!cur_pdev))
  300. return NULL;
  301. peer = dp_peer_get_ref_by_id(cur_pdev->soc, peer_id,
  302. DP_MOD_ID_TX_CAPTURE);
  303. if (!peer)
  304. return NULL;
  305. /* sanity check vdev NULL */
  306. vdev = peer->vdev;
  307. if (qdf_unlikely(!vdev)) {
  308. DP_TX_PEER_DEL_REF(peer);
  309. return NULL;
  310. }
  311. /* sanity check pdev NULL */
  312. pdev = vdev->pdev;
  313. if (qdf_unlikely(!pdev)) {
  314. DP_TX_PEER_DEL_REF(peer);
  315. return NULL;
  316. }
  317. if (qdf_unlikely(pdev->pdev_id != cur_pdev->pdev_id)) {
  318. dp_tx_capture_info("%pK: peer %p peer_id: %d mapped to pdev %p %d, cur_pdev %p %d",
  319. pdev->soc,
  320. peer, peer_id,
  321. pdev, pdev->pdev_id,
  322. cur_pdev, cur_pdev->pdev_id);
  323. DP_TX_PEER_DEL_REF(peer);
  324. cur_pdev->tx_capture.peer_mismatch++;
  325. return NULL;
  326. }
  327. return peer;
  328. }
  329. /*
  330. * dp_tx_capture_htt_frame_counter: increment counter for htt_frame_type
  331. * pdev: DP pdev handle
  332. * htt_frame_type: htt frame type received from fw
  333. *
  334. * return: void
  335. */
  336. void dp_tx_capture_htt_frame_counter(struct dp_pdev *pdev,
  337. uint32_t htt_frame_type)
  338. {
  339. if (htt_frame_type >= TX_CAP_HTT_MAX_FTYPE)
  340. return;
  341. pdev->tx_capture.htt_frame_type[htt_frame_type]++;
  342. }
  343. static void
  344. dp_peer_print_tid_qlen(struct dp_soc *soc,
  345. struct dp_peer *peer,
  346. void *arg)
  347. {
  348. int tid;
  349. struct dp_tx_tid *tx_tid;
  350. uint32_t msdu_len;
  351. uint32_t tasklet_msdu_len;
  352. uint32_t ppdu_len;
  353. struct tid_q_len *c_tid_q_len = (struct tid_q_len *)arg;
  354. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  355. tx_tid = &peer->tx_capture.tx_tid[tid];
  356. msdu_len = qdf_nbuf_queue_len(&tx_tid->defer_msdu_q);
  357. tasklet_msdu_len = qdf_nbuf_queue_len(&tx_tid->msdu_comp_q);
  358. ppdu_len = qdf_nbuf_queue_len(&tx_tid->pending_ppdu_q);
  359. /*
  360. * if not NULL requested for aggreated stats hence add and
  361. * return do not print individual peer stats
  362. */
  363. if (c_tid_q_len) {
  364. c_tid_q_len->defer_msdu_len += msdu_len;
  365. c_tid_q_len->tasklet_msdu_len += tasklet_msdu_len;
  366. c_tid_q_len->pending_q_len += ppdu_len;
  367. continue;
  368. }
  369. if (!msdu_len && !ppdu_len && !tasklet_msdu_len)
  370. continue;
  371. DP_PRINT_STATS(" peer_id[%d] tid[%d] msdu_comp_q[%d] defer_msdu_q[%d] pending_ppdu_q[%d]",
  372. peer->peer_id, tid,
  373. tasklet_msdu_len,
  374. msdu_len, ppdu_len);
  375. }
  376. dp_tx_capture_print_stats(peer);
  377. }
  378. /*
  379. * dp_iterate_print_tid_qlen_per_peer()- API to print peer tid msdu queue
  380. * @pdev_handle: DP_PDEV handle
  381. *
  382. * Return: void
  383. */
  384. void dp_print_tid_qlen_per_peer(void *pdev_hdl, uint8_t consolidated)
  385. {
  386. struct dp_pdev *pdev = (struct dp_pdev *)pdev_hdl;
  387. DP_PRINT_STATS("pending peer msdu and ppdu:");
  388. if (consolidated) {
  389. struct tid_q_len c_tid_q_len = {0};
  390. dp_pdev_iterate_peer(pdev, dp_peer_print_tid_qlen, &c_tid_q_len,
  391. DP_MOD_ID_TX_CAPTURE);
  392. DP_PRINT_STATS("consolidated: msdu_comp_q[%llu] defer_msdu_q[%llu] pending_ppdu_q[%llu]",
  393. c_tid_q_len.tasklet_msdu_len, c_tid_q_len.defer_msdu_len,
  394. c_tid_q_len.pending_q_len);
  395. }
  396. dp_pdev_iterate_peer(pdev, dp_peer_print_tid_qlen, NULL,
  397. DP_MOD_ID_TX_CAPTURE);
  398. }
  399. static void
  400. dp_ppdu_queue_free(qdf_nbuf_t ppdu_nbuf, uint8_t usr_idx)
  401. {
  402. int i;
  403. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  404. struct cdp_tx_completion_ppdu_user *user;
  405. qdf_nbuf_t mpdu_nbuf = NULL;
  406. if (!ppdu_nbuf)
  407. return;
  408. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_nbuf);
  409. if (!ppdu_desc)
  410. return;
  411. user = &ppdu_desc->user[usr_idx];
  412. if (!user->mpdus)
  413. goto free_ppdu_desc_mpdu_q;
  414. for (i = 0; i < user->ba_size &&
  415. i < (CDP_BA_256_BIT_MAP_SIZE_DWORDS * NUM_BITS_DWORD); i++) {
  416. mpdu_nbuf = user->mpdus[i];
  417. if (mpdu_nbuf) {
  418. qdf_nbuf_free(mpdu_nbuf);
  419. user->mpdus[i] = NULL;
  420. }
  421. }
  422. free_ppdu_desc_mpdu_q:
  423. if (!qdf_nbuf_is_queue_empty(&user->mpdu_q))
  424. TX_CAP_NBUF_QUEUE_FREE(&user->mpdu_q);
  425. if (user->mpdus)
  426. qdf_mem_free(user->mpdus);
  427. user->mpdus = NULL;
  428. }
  429. /*
  430. * dp_tx_cature_stats: print tx capture stats
  431. * @pdev: DP PDEV handle
  432. *
  433. * return: void
  434. */
  435. void dp_print_pdev_tx_capture_stats(struct dp_pdev *pdev)
  436. {
  437. struct dp_pdev_tx_capture *ptr_tx_cap;
  438. uint8_t i = 0, j = 0;
  439. uint32_t ppdu_stats_ms = 0;
  440. uint32_t now_ms = 0;
  441. ptr_tx_cap = &(pdev->tx_capture);
  442. ppdu_stats_ms = ptr_tx_cap->ppdu_stats_ms;
  443. now_ms = qdf_system_ticks_to_msecs(qdf_system_ticks());
  444. DP_PRINT_STATS("tx capture stats:");
  445. DP_PRINT_STATS(" Last recv ppdu stats: %u",
  446. now_ms - ppdu_stats_ms);
  447. DP_PRINT_STATS(" ppdu stats queue depth: %u",
  448. ptr_tx_cap->ppdu_stats_queue_depth);
  449. DP_PRINT_STATS(" ppdu stats defer queue depth: %u",
  450. ptr_tx_cap->ppdu_stats_defer_queue_depth);
  451. DP_PRINT_STATS(" pending ppdu dropped: %u",
  452. ptr_tx_cap->pend_ppdu_dropped);
  453. DP_PRINT_STATS(" peer mismatch: %llu",
  454. ptr_tx_cap->peer_mismatch);
  455. DP_PRINT_STATS(" ppdu peer flush counter: %u",
  456. ptr_tx_cap->ppdu_flush_count);
  457. DP_PRINT_STATS(" ppdu msdu threshold drop: %u",
  458. ptr_tx_cap->msdu_threshold_drop);
  459. DP_PRINT_STATS(" mgmt control enqueue stats:");
  460. for (i = 0; i < TXCAP_MAX_TYPE; i++) {
  461. for (j = 0; j < TXCAP_MAX_SUBTYPE; j++) {
  462. if (ptr_tx_cap->ctl_mgmt_q[i][j].qlen)
  463. DP_PRINT_STATS(" ctl_mgmt_q[%d][%d] = queue_len[%d]",
  464. i, j, ptr_tx_cap->ctl_mgmt_q[i][j].qlen);
  465. }
  466. }
  467. DP_PRINT_STATS(" mgmt control retry queue stats:");
  468. for (i = 0; i < TXCAP_MAX_TYPE; i++) {
  469. for (j = 0; j < TXCAP_MAX_SUBTYPE; j++) {
  470. if (ptr_tx_cap->retries_ctl_mgmt_q[i][j].qlen)
  471. DP_PRINT_STATS(" retries_ctl_mgmt_q[%d][%d] = queue_len[%d]",
  472. i, j,
  473. ptr_tx_cap->retries_ctl_mgmt_q[i][j].qlen);
  474. }
  475. }
  476. for (i = 0; i < TX_CAP_HTT_MAX_FTYPE; i++) {
  477. if (!ptr_tx_cap->htt_frame_type[i])
  478. continue;
  479. DP_PRINT_STATS(" sgen htt frame type[%d] = %d",
  480. i, ptr_tx_cap->htt_frame_type[i]);
  481. }
  482. dp_print_tid_qlen_per_peer(pdev, 0);
  483. }
  484. /**
  485. * dp_peer_or_pdev_tx_cap_enabled - Returns status of tx_cap_enabled
  486. * based on global per-pdev setting or per-peer setting
  487. * @pdev: Datapath pdev handle
  488. * @peer: Datapath peer
  489. * @mac_addr: peer mac address
  490. *
  491. * Return: true if feature is enabled on a per-pdev basis or if
  492. * enabled for the given peer when per-peer mode is set, false otherwise
  493. */
  494. inline bool
  495. dp_peer_or_pdev_tx_cap_enabled(struct dp_pdev *pdev,
  496. struct dp_peer *peer, uint8_t *mac_addr)
  497. {
  498. bool flag = false;
  499. if (pdev->tx_capture_enabled == CDP_TX_ENH_CAPTURE_ENABLE_ALL_PEERS) {
  500. return true;
  501. } else if (pdev->tx_capture_enabled ==
  502. CDP_TX_ENH_CAPTURE_ENDIS_PER_PEER) {
  503. if (peer && peer->tx_cap_enabled)
  504. return true;
  505. /* do search based on mac address */
  506. flag = is_dp_peer_mgmt_pkt_filter(pdev,
  507. HTT_INVALID_PEER,
  508. mac_addr);
  509. if (flag && peer)
  510. peer->tx_cap_enabled = 1;
  511. return flag;
  512. }
  513. return false;
  514. }
  515. /*
  516. * dp_tx_find_usr_idx_from_peer_id()- find user index based on peer_id
  517. * @ppdu_desc: pointer to ppdu_desc structure
  518. * @peer_id: peer id
  519. *
  520. * Return: user index
  521. */
  522. static uint8_t
  523. dp_tx_find_usr_idx_from_peer_id(struct cdp_tx_completion_ppdu *ppdu_desc,
  524. uint16_t peer_id)
  525. {
  526. uint8_t usr_idx = 0;
  527. bool found = false;
  528. for (usr_idx = 0; usr_idx < ppdu_desc->num_users; usr_idx++) {
  529. if (ppdu_desc->user[usr_idx].peer_id == peer_id) {
  530. found = true;
  531. break;
  532. }
  533. }
  534. if (!found) {
  535. dp_tx_capture_alert("peer_id: %d, ppdu_desc[%p][num_users: %d]\n",
  536. peer_id, ppdu_desc, ppdu_desc->num_users);
  537. qdf_assert_always(0);
  538. }
  539. return usr_idx;
  540. }
  541. /*
  542. * dp_peer_tid_peer_id_update() – update peer_id to tid structure
  543. * @peer: Datapath peer
  544. * @peer_id: peer_id
  545. *
  546. */
  547. void dp_peer_tid_peer_id_update(struct dp_peer *peer, uint16_t peer_id)
  548. {
  549. int tid;
  550. struct dp_tx_tid *tx_tid;
  551. /*
  552. * For the newly created peer after tx monitor turned ON,
  553. * initialization check is already taken care in queue init
  554. */
  555. dp_peer_tid_queue_init(peer);
  556. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  557. tx_tid = &peer->tx_capture.tx_tid[tid];
  558. tx_tid->peer_id = peer_id;
  559. tx_tid->tid = tid;
  560. }
  561. }
  562. /*
  563. * dp_peer_tid_queue_init() – Initialize ppdu stats queue per TID
  564. * @peer: Datapath peer
  565. *
  566. */
  567. void dp_peer_tid_queue_init(struct dp_peer *peer)
  568. {
  569. struct dp_pdev *pdev;
  570. struct dp_vdev *vdev;
  571. int tid;
  572. struct dp_tx_tid *tx_tid;
  573. if (!peer)
  574. return;
  575. vdev = peer->vdev;
  576. pdev = vdev->pdev;
  577. /* only if tx capture is turned on we will initialize the tid */
  578. if (qdf_atomic_read(&pdev->tx_capture.tx_cap_usr_mode) ==
  579. CDP_TX_ENH_CAPTURE_DISABLED)
  580. return;
  581. dp_tx_capture_info("%pK: peer(%p) id:%d init!!", pdev->soc, peer, peer->peer_id);
  582. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  583. struct cdp_tx_completion_ppdu *xretry_ppdu = NULL;
  584. struct cdp_tx_completion_ppdu_user *xretry_user = NULL;
  585. tx_tid = &peer->tx_capture.tx_tid[tid];
  586. if (qdf_atomic_test_and_set_bit(DP_PEER_TX_TID_INIT_DONE_BIT,
  587. &tx_tid->tid_flags))
  588. continue;
  589. tx_tid->peer_id = peer->peer_id;
  590. tx_tid->tid = tid;
  591. check_queue_empty(&tx_tid->defer_msdu_q);
  592. qdf_nbuf_queue_init(&tx_tid->defer_msdu_q);
  593. check_queue_empty(&tx_tid->msdu_comp_q);
  594. qdf_nbuf_queue_init(&tx_tid->msdu_comp_q);
  595. check_queue_empty(&tx_tid->pending_ppdu_q);
  596. qdf_nbuf_queue_init(&tx_tid->pending_ppdu_q);
  597. tx_tid->max_ppdu_id = 0;
  598. tx_tid->xretry_ppdu =
  599. qdf_mem_malloc(sizeof(struct cdp_tx_completion_ppdu) +
  600. sizeof(struct cdp_tx_completion_ppdu_user));
  601. if (qdf_unlikely(!tx_tid->xretry_ppdu)) {
  602. int i;
  603. QDF_TRACE(QDF_MODULE_ID_TXRX,
  604. QDF_TRACE_LEVEL_ERROR,
  605. "Alloc failed");
  606. for (i = 0; i < tid; i++) {
  607. tx_tid = &peer->tx_capture.tx_tid[i];
  608. qdf_mem_free(tx_tid->xretry_ppdu);
  609. tx_tid->xretry_ppdu = NULL;
  610. qdf_atomic_clear_bit(DP_PEER_TX_TID_INIT_DONE_BIT,
  611. &tx_tid->tid_flags);
  612. }
  613. QDF_ASSERT(0);
  614. return;
  615. }
  616. /* initialize xretry user mpduq */
  617. xretry_ppdu = tx_tid->xretry_ppdu;
  618. xretry_user = &xretry_ppdu->user[0];
  619. qdf_nbuf_queue_init(&xretry_user->mpdu_q);
  620. /* spinlock create */
  621. qdf_spinlock_create(&tx_tid->tid_lock);
  622. qdf_spinlock_create(&tx_tid->tasklet_tid_lock);
  623. }
  624. peer->tx_capture.is_tid_initialized = 1;
  625. }
  626. /*
  627. * dp_peer_tx_cap_tid_queue_flush() – flush inactive peer tx cap per
  628. * @soc: Datapath SoC object
  629. * @peer: Datapath peer
  630. * @arg: argument
  631. *
  632. * return: void
  633. */
  634. static
  635. void dp_peer_tx_cap_tid_queue_flush(struct dp_soc *soc, struct dp_peer *peer,
  636. void *arg)
  637. {
  638. struct dp_pdev *pdev = NULL;
  639. struct dp_vdev *vdev = NULL;
  640. struct dp_tx_tid *tx_tid = NULL;
  641. struct dp_pdev_flush *flush = (struct dp_pdev_flush *)arg;
  642. uint16_t peer_id = 0;
  643. int tid;
  644. /* sanity check vdev NULL */
  645. vdev = peer->vdev;
  646. if (qdf_unlikely(!vdev))
  647. return;
  648. /* sanity check pdev NULL */
  649. pdev = vdev->pdev;
  650. if (qdf_unlikely(!pdev))
  651. return;
  652. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, peer, peer->mac_addr.raw))
  653. return;
  654. if (!peer->tx_capture.is_tid_initialized)
  655. return;
  656. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  657. struct cdp_tx_completion_ppdu *xretry_ppdu;
  658. struct cdp_tx_completion_ppdu_user *xretry_user;
  659. struct cdp_tx_completion_ppdu *ppdu_desc;
  660. struct cdp_tx_completion_ppdu_user *user;
  661. qdf_nbuf_t ppdu_nbuf = NULL;
  662. uint32_t len = 0;
  663. uint32_t actual_len = 0;
  664. uint32_t delta_ms = 0;
  665. tx_tid = &peer->tx_capture.tx_tid[tid];
  666. /*
  667. * check whether the peer tid payload queue is inactive
  668. * now_ms will be always greater than last_deq_ms
  669. * if it is less than last_deq_ms then wrap
  670. * around happened
  671. */
  672. if (flush->now_ms > tx_tid->last_deq_ms)
  673. delta_ms = flush->now_ms - tx_tid->last_deq_ms;
  674. else
  675. delta_ms = (DP_TX_CAP_MAX_MS + flush->now_ms) -
  676. tx_tid->last_deq_ms;
  677. /* check whether we need to flush all peer */
  678. if (!flush->flush_all && delta_ms < TX_CAPTURE_PEER_DEQ_MS)
  679. continue;
  680. xretry_ppdu = tx_tid->xretry_ppdu;
  681. if (qdf_unlikely(!xretry_ppdu))
  682. continue;
  683. xretry_user = &xretry_ppdu->user[0];
  684. qdf_spin_lock_bh(&tx_tid->tid_lock);
  685. TX_CAP_NBUF_QUEUE_FREE(&tx_tid->defer_msdu_q);
  686. /* update last dequeue time with current msec */
  687. tx_tid->last_deq_ms = flush->now_ms;
  688. /* update last processed time with current msec */
  689. tx_tid->last_processed_ms = flush->now_ms;
  690. qdf_spin_unlock_bh(&tx_tid->tid_lock);
  691. qdf_spin_lock_bh(&tx_tid->tasklet_tid_lock);
  692. TX_CAP_NBUF_QUEUE_FREE(&tx_tid->msdu_comp_q);
  693. qdf_spin_unlock_bh(&tx_tid->tasklet_tid_lock);
  694. tx_tid->max_ppdu_id = 0;
  695. peer_id = tx_tid->peer_id;
  696. len = qdf_nbuf_queue_len(&tx_tid->pending_ppdu_q);
  697. actual_len = len;
  698. /* free pending ppdu_q and xretry mpdu_q */
  699. while ((ppdu_nbuf = qdf_nbuf_queue_remove(
  700. &tx_tid->pending_ppdu_q))) {
  701. uint64_t ppdu_start_timestamp;
  702. uint8_t usr_idx = 0;
  703. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  704. qdf_nbuf_data(ppdu_nbuf);
  705. ppdu_start_timestamp = ppdu_desc->ppdu_start_timestamp;
  706. dp_tx_capture_info("ppdu_id:%u tsf:%llu removed from pending ppdu q",
  707. ppdu_desc->ppdu_id,
  708. ppdu_start_timestamp);
  709. /*
  710. * check if peer id is matching
  711. * the user peer_id
  712. */
  713. usr_idx = dp_tx_find_usr_idx_from_peer_id(ppdu_desc,
  714. peer_id);
  715. user = &ppdu_desc->user[usr_idx];
  716. /* free all the mpdu_q and mpdus for usr_idx */
  717. dp_ppdu_queue_free(ppdu_nbuf, usr_idx);
  718. qdf_nbuf_free(ppdu_nbuf);
  719. len--;
  720. }
  721. if (len) {
  722. dp_tx_capture_alert("Actual_len: %d pending len:%d !!!",
  723. actual_len, len);
  724. QDF_BUG(0);
  725. }
  726. /* free xretry ppdu user alone */
  727. TX_CAP_NBUF_QUEUE_FREE(&xretry_user->mpdu_q);
  728. }
  729. }
  730. /*
  731. * dp_peer_tid_queue_cleanup() – remove ppdu stats queue per TID
  732. * @peer: Datapath peer
  733. *
  734. */
  735. void dp_peer_tid_queue_cleanup(struct dp_peer *peer)
  736. {
  737. struct dp_tx_tid *tx_tid;
  738. struct cdp_tx_completion_ppdu *xretry_ppdu;
  739. struct cdp_tx_completion_ppdu_user *xretry_user;
  740. struct cdp_tx_completion_ppdu *ppdu_desc;
  741. struct cdp_tx_completion_ppdu_user *user;
  742. qdf_nbuf_t ppdu_nbuf = NULL;
  743. int tid;
  744. uint16_t peer_id;
  745. if (!peer->tx_capture.is_tid_initialized)
  746. return;
  747. dp_tx_capture_info("peer(%p) id:%d cleanup!!",
  748. peer, peer->peer_id);
  749. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  750. uint32_t len = 0;
  751. uint32_t actual_len = 0;
  752. tx_tid = &peer->tx_capture.tx_tid[tid];
  753. if (!qdf_atomic_test_and_clear_bit(DP_PEER_TX_TID_INIT_DONE_BIT,
  754. &tx_tid->tid_flags))
  755. continue;
  756. xretry_ppdu = tx_tid->xretry_ppdu;
  757. xretry_user = &xretry_ppdu->user[0];
  758. qdf_spin_lock_bh(&tx_tid->tid_lock);
  759. TX_CAP_NBUF_QUEUE_FREE(&tx_tid->defer_msdu_q);
  760. qdf_spin_unlock_bh(&tx_tid->tid_lock);
  761. qdf_spin_lock_bh(&tx_tid->tasklet_tid_lock);
  762. TX_CAP_NBUF_QUEUE_FREE(&tx_tid->msdu_comp_q);
  763. qdf_spin_unlock_bh(&tx_tid->tasklet_tid_lock);
  764. /* spinlock destroy */
  765. qdf_spinlock_destroy(&tx_tid->tid_lock);
  766. qdf_spinlock_destroy(&tx_tid->tasklet_tid_lock);
  767. peer_id = tx_tid->peer_id;
  768. len = qdf_nbuf_queue_len(&tx_tid->pending_ppdu_q);
  769. actual_len = len;
  770. /* free pending ppdu_q and xretry mpdu_q */
  771. while ((ppdu_nbuf = qdf_nbuf_queue_remove(
  772. &tx_tid->pending_ppdu_q))) {
  773. uint8_t usr_idx;
  774. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  775. qdf_nbuf_data(ppdu_nbuf);
  776. dp_tx_capture_info("ppdu_id:%u tsf:%llu removed from pending ppdu q",
  777. ppdu_desc->ppdu_id,
  778. ppdu_desc->ppdu_start_timestamp);
  779. /*
  780. * check if peer id is matching
  781. * the user peer_id
  782. */
  783. usr_idx = dp_tx_find_usr_idx_from_peer_id(ppdu_desc,
  784. peer_id);
  785. user = &ppdu_desc->user[usr_idx];
  786. /* free all the mpdu_q and mpdus for usr_idx */
  787. dp_ppdu_queue_free(ppdu_nbuf, usr_idx);
  788. qdf_nbuf_free(ppdu_nbuf);
  789. len--;
  790. }
  791. if (len) {
  792. dp_tx_capture_alert("Actual_len: %d pending len:%d !!!",
  793. actual_len, len);
  794. QDF_BUG(0);
  795. }
  796. TX_CAP_NBUF_QUEUE_FREE(&xretry_user->mpdu_q);
  797. qdf_mem_free(xretry_ppdu);
  798. tx_tid->xretry_ppdu = NULL;
  799. tx_tid->max_ppdu_id = 0;
  800. }
  801. peer->tx_capture.is_tid_initialized = 0;
  802. }
  803. /*
  804. * dp_peer_update_80211_hdr: update 80211 hdr
  805. * @vdev: DP VDEV
  806. * @peer: DP PEER
  807. *
  808. * return: void
  809. */
  810. void dp_peer_update_80211_hdr(struct dp_vdev *vdev, struct dp_peer *peer)
  811. {
  812. struct ieee80211_frame *ptr_wh;
  813. ptr_wh = &peer->tx_capture.tx_wifi_hdr;
  814. /* i_addr1 - Receiver mac address */
  815. /* i_addr2 - Transmitter mac address */
  816. /* i_addr3 - Destination mac address */
  817. qdf_mem_copy(ptr_wh->i_addr1,
  818. peer->mac_addr.raw,
  819. QDF_MAC_ADDR_SIZE);
  820. qdf_mem_copy(ptr_wh->i_addr3,
  821. peer->mac_addr.raw,
  822. QDF_MAC_ADDR_SIZE);
  823. qdf_mem_copy(ptr_wh->i_addr2,
  824. vdev->mac_addr.raw,
  825. QDF_MAC_ADDR_SIZE);
  826. }
  827. /*
  828. * dp_action_frame_is_hostgen
  829. * @category: action category code number
  830. * @action: action code number
  831. *
  832. * return: true if action frame is host generated, else false
  833. */
  834. bool dp_action_frame_is_hostgen(int category, int action)
  835. {
  836. bool retval = true;
  837. switch (category) {
  838. case IEEE80211_ACTION_CAT_BA:
  839. switch (action) {
  840. case IEEE80211_ACTION_BA_ADDBA_REQUEST:
  841. case IEEE80211_ACTION_BA_ADDBA_RESPONSE:
  842. case IEEE80211_ACTION_BA_DELBA:
  843. retval = false;
  844. break;
  845. default:
  846. break;
  847. }
  848. break;
  849. case IEEE80211_ACTION_CAT_PUBLIC:
  850. switch (action) {
  851. case IEEE80211_ACTION_PUBLIC_FINE_TMR:
  852. case IEEE80211_ACTION_PUBLIC_FINE_TM:
  853. case IEEE80211_ACTION_PUBLIC_FILS_DISC:
  854. retval = false;
  855. break;
  856. default:
  857. break;
  858. }
  859. break;
  860. case IEEE80211_ACTION_CAT_RADIO:
  861. switch (action) {
  862. case IEEE80211_ACTION_RADIO_MGMT_NEIGH_REPT_REQ:
  863. retval = false;
  864. break;
  865. default:
  866. break;
  867. }
  868. break;
  869. case IEEE80211_ACTION_CAT_HT:
  870. switch (action) {
  871. case IEEE80211_ACTION_HT_SMPOWERSAVE:
  872. retval = false;
  873. break;
  874. default:
  875. break;
  876. }
  877. break;
  878. case IEEE80211_ACTION_CAT_SA_QUERY:
  879. switch (action) {
  880. case IEEE80211_ACTION_SA_QUERY_REQUEST:
  881. case IEEE80211_ACTION_SA_QUERY_RESPONSE:
  882. retval = false;
  883. break;
  884. default:
  885. break;
  886. }
  887. break;
  888. case IEEE80211_ACTION_CAT_WNM:
  889. switch (action) {
  890. case IEEE80211_ACTION_EVENT_REPORT:
  891. case IEEE80211_ACTION_BSTM_QUERY:
  892. case IEEE80211_ACTION_BSTM_RESP:
  893. retval = false;
  894. break;
  895. default:
  896. break;
  897. }
  898. break;
  899. case IEEE80211_ACTION_CAT_TDLS:
  900. switch (action) {
  901. case IEEE80211_ACTION_TDLS_PEER_TRAFFIC_IND:
  902. case IEEE80211_ACTION_TDLS_CHAN_SWITCH_REQ:
  903. case IEEE80211_ACTION_TDLS_CHAN_SWITCH_RESP:
  904. case IEEE80211_ACTION_TDLS_PEER_TRAFFIC_RESP:
  905. retval = false;
  906. break;
  907. default:
  908. break;
  909. }
  910. break;
  911. case IEEE80211_ACTION_CAT_VHT:
  912. switch (action) {
  913. case IEEE80211_ACTION_VHT_OPMODE:
  914. case IEEE80211_ACTION_VHT_GROUP_ID:
  915. retval = false;
  916. break;
  917. default:
  918. break;
  919. }
  920. break;
  921. case IEEE80211_ACTION_CAT_S1G:
  922. switch (action) {
  923. case IEEE80211_ACTION_TWT_SETUP:
  924. case IEEE80211_ACTION_TWT_TEARDOWN:
  925. case IEEE80211_ACTION_TWT_INFORMATION:
  926. retval = false;
  927. break;
  928. default:
  929. break;
  930. }
  931. break;
  932. default:
  933. break;
  934. }
  935. return retval;
  936. }
  937. /*
  938. * dp_deliver_mgmt_frm: Process
  939. * @pdev: DP PDEV handle
  940. * @nbuf: buffer containing the htt_ppdu_stats_tx_mgmtctrl_payload_tlv
  941. *
  942. * return: void
  943. */
  944. void dp_deliver_mgmt_frm(struct dp_pdev *pdev, qdf_nbuf_t nbuf)
  945. {
  946. if (pdev->tx_sniffer_enable || pdev->mcopy_mode) {
  947. dp_wdi_event_handler(WDI_EVENT_TX_MGMT_CTRL, pdev->soc,
  948. nbuf, HTT_INVALID_PEER,
  949. WDI_NO_VAL, pdev->pdev_id);
  950. return;
  951. }
  952. if (pdev->tx_capture_enabled == CDP_TX_ENH_CAPTURE_ENABLE_ALL_PEERS ||
  953. pdev->tx_capture_enabled == CDP_TX_ENH_CAPTURE_ENDIS_PER_PEER) {
  954. /* invoke WDI event handler here send mgmt pkt here */
  955. struct ieee80211_frame *wh;
  956. uint8_t type, subtype;
  957. struct cdp_tx_mgmt_comp_info *ptr_mgmt_hdr;
  958. ptr_mgmt_hdr = (struct cdp_tx_mgmt_comp_info *)
  959. qdf_nbuf_data(nbuf);
  960. wh = (struct ieee80211_frame *)(qdf_nbuf_data(nbuf) +
  961. sizeof(struct cdp_tx_mgmt_comp_info));
  962. type = (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) >>
  963. IEEE80211_FC0_TYPE_SHIFT;
  964. subtype = (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) >>
  965. IEEE80211_FC0_SUBTYPE_SHIFT;
  966. if (!ptr_mgmt_hdr->ppdu_id || !ptr_mgmt_hdr->tx_tsf ||
  967. (!type && !subtype)) {
  968. /*
  969. * if either ppdu_id and tx_tsf are zero then
  970. * storing the payload won't be useful
  971. * in constructing the packet
  972. * Hence freeing the packet
  973. */
  974. qdf_nbuf_free(nbuf);
  975. return;
  976. }
  977. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, NULL, wh->i_addr1)) {
  978. qdf_nbuf_free(nbuf);
  979. return;
  980. }
  981. if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) ==
  982. IEEE80211_FC0_TYPE_MGT) &&
  983. ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) ==
  984. IEEE80211_FC0_SUBTYPE_ACTION)) {
  985. uint8_t *frm;
  986. struct ieee80211_action *ia;
  987. frm = (u_int8_t *)&wh[1];
  988. ia = (struct ieee80211_action *)frm;
  989. if (!dp_action_frame_is_hostgen(ia->ia_category,
  990. ia->ia_action)) {
  991. ptr_mgmt_hdr->is_sgen_pkt = false;
  992. }
  993. }
  994. dp_tx_capture_debug("%pK: dlvr mgmt frm(%d 0x%08x): fc 0x%x %x, dur 0x%x%x tsf:%llu, retries_count: %d, is_sgen: %d",
  995. pdev->soc,
  996. ptr_mgmt_hdr->ppdu_id,
  997. ptr_mgmt_hdr->ppdu_id,
  998. wh->i_fc[1], wh->i_fc[0],
  999. wh->i_dur[1], wh->i_dur[0], ptr_mgmt_hdr->tx_tsf,
  1000. ptr_mgmt_hdr->retries_count,
  1001. ptr_mgmt_hdr->is_sgen_pkt);
  1002. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP_TX_CAPTURE,
  1003. QDF_TRACE_LEVEL_DEBUG,
  1004. qdf_nbuf_data(nbuf), 64);
  1005. qdf_spin_lock_bh(
  1006. &pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  1007. qdf_nbuf_queue_add(&pdev->tx_capture.ctl_mgmt_q[type][subtype],
  1008. nbuf);
  1009. qdf_spin_unlock_bh(
  1010. &pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  1011. } else {
  1012. if (!pdev->bpr_enable)
  1013. qdf_nbuf_free(nbuf);
  1014. }
  1015. }
  1016. static inline int dp_peer_compare_mac_addr(void *addr1, void *addr2)
  1017. {
  1018. union dp_align_mac_addr *mac_addr1 = (union dp_align_mac_addr *)addr1;
  1019. union dp_align_mac_addr *mac_addr2 = (union dp_align_mac_addr *)addr2;
  1020. return !((mac_addr1->align4.bytes_abcd == mac_addr2->align4.bytes_abcd)
  1021. & (mac_addr1->align4.bytes_ef == mac_addr2->align4.bytes_ef));
  1022. }
  1023. /*
  1024. * dp_peer_tx_cap_search: filter mgmt pkt based on peer and mac address
  1025. * @pdev: DP PDEV handle
  1026. * @peer_id: DP PEER ID
  1027. * @mac_addr: pointer to mac address
  1028. *
  1029. * return: true on matched and false on not found
  1030. */
  1031. static
  1032. bool dp_peer_tx_cap_search(struct dp_pdev *pdev,
  1033. uint16_t peer_id, uint8_t *mac_addr)
  1034. {
  1035. struct dp_pdev_tx_capture *tx_capture;
  1036. struct dp_peer_mgmt_list *ptr_peer_mgmt_list;
  1037. uint8_t i = 0;
  1038. bool found = false;
  1039. tx_capture = &pdev->tx_capture;
  1040. /* search based on mac address */
  1041. for (i = 0; i < MAX_MGMT_PEER_FILTER; i++) {
  1042. uint8_t *peer_mac_addr;
  1043. ptr_peer_mgmt_list = &tx_capture->ptr_peer_mgmt_list[i];
  1044. if (ptr_peer_mgmt_list->avail)
  1045. continue;
  1046. peer_mac_addr = ptr_peer_mgmt_list->mac_addr;
  1047. if (!dp_peer_compare_mac_addr(mac_addr,
  1048. peer_mac_addr)) {
  1049. found = true;
  1050. break;
  1051. }
  1052. }
  1053. return found;
  1054. }
  1055. /*
  1056. * dp_peer_tx_cap_add_filter: add peer filter mgmt pkt based on peer
  1057. * and mac address
  1058. * @pdev: DP PDEV handle
  1059. * @peer_id: DP PEER ID
  1060. * @mac_addr: pointer to mac address
  1061. *
  1062. * return: true on added and false on not failed
  1063. */
  1064. bool dp_peer_tx_cap_add_filter(struct dp_pdev *pdev,
  1065. uint16_t peer_id, uint8_t *mac_addr)
  1066. {
  1067. struct dp_pdev_tx_capture *tx_capture;
  1068. struct dp_peer_mgmt_list *ptr_peer_mgmt_list;
  1069. uint8_t i = 0;
  1070. bool status = false;
  1071. tx_capture = &pdev->tx_capture;
  1072. if (dp_peer_tx_cap_search(pdev, peer_id, mac_addr)) {
  1073. /* mac address and peer_id already there */
  1074. dp_tx_capture_info("%pk: peer_id[%d] mac_addr[%pM] already there\n",
  1075. pdev->soc, peer_id, mac_addr);
  1076. return status;
  1077. }
  1078. for (i = 0; i < MAX_MGMT_PEER_FILTER; i++) {
  1079. ptr_peer_mgmt_list = &tx_capture->ptr_peer_mgmt_list[i];
  1080. if (!ptr_peer_mgmt_list->avail)
  1081. continue;
  1082. qdf_mem_copy(ptr_peer_mgmt_list->mac_addr,
  1083. mac_addr, QDF_MAC_ADDR_SIZE);
  1084. ptr_peer_mgmt_list->avail = false;
  1085. ptr_peer_mgmt_list->peer_id = peer_id;
  1086. status = true;
  1087. break;
  1088. }
  1089. return status;
  1090. }
  1091. /*
  1092. * dp_peer_tx_cap_del_all_filter: delete all peer filter mgmt pkt based on peer
  1093. * and mac address
  1094. * @pdev: DP PDEV handle
  1095. * @peer_id: DP PEER ID
  1096. * @mac_addr: pointer to mac address
  1097. *
  1098. * return: void
  1099. */
  1100. void dp_peer_tx_cap_del_all_filter(struct dp_pdev *pdev)
  1101. {
  1102. struct dp_pdev_tx_capture *tx_capture;
  1103. struct dp_peer_mgmt_list *ptr_peer_mgmt_list;
  1104. uint8_t i = 0;
  1105. tx_capture = &pdev->tx_capture;
  1106. for (i = 0; i < MAX_MGMT_PEER_FILTER; i++) {
  1107. ptr_peer_mgmt_list = &tx_capture->ptr_peer_mgmt_list[i];
  1108. ptr_peer_mgmt_list->avail = true;
  1109. ptr_peer_mgmt_list->peer_id = HTT_INVALID_PEER;
  1110. qdf_mem_zero(ptr_peer_mgmt_list->mac_addr, QDF_MAC_ADDR_SIZE);
  1111. }
  1112. }
  1113. /*
  1114. * dp_peer_tx_cap_del_filter: delete peer filter mgmt pkt based on peer
  1115. * and mac address
  1116. * @pdev: DP PDEV handle
  1117. * @peer_id: DP PEER ID
  1118. * @mac_addr: pointer to mac address
  1119. *
  1120. * return: true on added and false on not failed
  1121. */
  1122. bool dp_peer_tx_cap_del_filter(struct dp_pdev *pdev,
  1123. uint16_t peer_id, uint8_t *mac_addr)
  1124. {
  1125. struct dp_pdev_tx_capture *tx_capture;
  1126. struct dp_peer_mgmt_list *ptr_peer_mgmt_list;
  1127. uint8_t i = 0;
  1128. bool status = false;
  1129. tx_capture = &pdev->tx_capture;
  1130. for (i = 0; i < MAX_MGMT_PEER_FILTER; i++) {
  1131. ptr_peer_mgmt_list = &tx_capture->ptr_peer_mgmt_list[i];
  1132. if (!dp_peer_compare_mac_addr(mac_addr,
  1133. ptr_peer_mgmt_list->mac_addr) &&
  1134. (!ptr_peer_mgmt_list->avail)) {
  1135. ptr_peer_mgmt_list->avail = true;
  1136. ptr_peer_mgmt_list->peer_id = HTT_INVALID_PEER;
  1137. qdf_mem_zero(ptr_peer_mgmt_list->mac_addr,
  1138. QDF_MAC_ADDR_SIZE);
  1139. status = true;
  1140. break;
  1141. }
  1142. }
  1143. if (!status)
  1144. dp_tx_capture_info("%pK: unable to delete peer[%d] mac[%pM] filter list",
  1145. pdev->soc, peer_id, mac_addr);
  1146. return status;
  1147. }
  1148. /*
  1149. * dp_peer_tx_cap_print_mgmt_filter: pradd peer filter mgmt pkt based on peer
  1150. * and mac address
  1151. * @pdev: DP PDEV handle
  1152. * @peer_id: DP PEER ID
  1153. * @mac_addr: pointer to mac address
  1154. *
  1155. * return: true on added and false on not failed
  1156. */
  1157. void dp_peer_tx_cap_print_mgmt_filter(struct dp_pdev *pdev,
  1158. uint16_t peer_id, uint8_t *mac_addr)
  1159. {
  1160. struct dp_pdev_tx_capture *tx_capture;
  1161. struct dp_peer_mgmt_list *ptr_peer_mgmt_list;
  1162. uint8_t i = 0;
  1163. tx_capture = &pdev->tx_capture;
  1164. dp_tx_capture_info("%pK: peer filter list:", pdev->soc);
  1165. for (i = 0; i < MAX_MGMT_PEER_FILTER; i++) {
  1166. ptr_peer_mgmt_list = &tx_capture->ptr_peer_mgmt_list[i];
  1167. dp_tx_capture_info("%pK: peer_id[%d] mac_addr[%pM] avail[%d]",
  1168. pdev->soc,
  1169. ptr_peer_mgmt_list->peer_id,
  1170. ptr_peer_mgmt_list->mac_addr,
  1171. ptr_peer_mgmt_list->avail);
  1172. }
  1173. }
  1174. /*
  1175. * dp_peer_mgmt_pkt_filter: filter mgmt pkt based on peer and mac address
  1176. * @pdev: DP PDEV handle
  1177. * @nbuf: buffer containing the ppdu_desc
  1178. *
  1179. * return: status
  1180. */
  1181. bool is_dp_peer_mgmt_pkt_filter(struct dp_pdev *pdev,
  1182. uint32_t peer_id, uint8_t *mac_addr)
  1183. {
  1184. bool found = false;
  1185. found = dp_peer_tx_cap_search(pdev, peer_id, mac_addr);
  1186. dp_tx_capture_info("%pK: peer_id[%d] mac_addr[%pM] found[%d]!",
  1187. pdev->soc, peer_id, mac_addr, found);
  1188. return found;
  1189. }
  1190. /**
  1191. * ppdu_desc_dbg_enqueue() - enqueue tx cap debug ppdu desc to the list
  1192. * @ptr_log_info: tx capture log info
  1193. * @ptr_dbg_ppdu: tx capture ppdu desc pointer
  1194. *
  1195. * Return: list size
  1196. */
  1197. static
  1198. uint32_t ppdu_desc_dbg_enqueue(struct tx_cap_debug_log_info *ptr_log_info,
  1199. struct dbg_tx_comp_ppdu *ptr_dbg_ppdu)
  1200. {
  1201. uint32_t list_size;
  1202. qdf_spin_lock(&ptr_log_info->dbg_log_lock);
  1203. qdf_list_insert_back_size(&ptr_log_info->ppdu_dbg_queue,
  1204. &ptr_dbg_ppdu->node, &list_size);
  1205. qdf_spin_unlock(&ptr_log_info->dbg_log_lock);
  1206. return list_size;
  1207. }
  1208. /**
  1209. * ppdu_desc_dbg_dequeue() - dequeue tx cap debug ppdu desc from list
  1210. * @ptr_log_info: tx capture log info
  1211. *
  1212. * Return: tx capture ppdu desc pointer
  1213. */
  1214. static
  1215. struct dbg_tx_comp_ppdu *
  1216. ppdu_desc_dbg_dequeue(struct tx_cap_debug_log_info *ptr_log_info)
  1217. {
  1218. qdf_list_node_t *list_node = NULL;
  1219. qdf_spin_lock(&ptr_log_info->dbg_log_lock);
  1220. qdf_list_remove_front(&ptr_log_info->ppdu_dbg_queue, &list_node);
  1221. qdf_spin_unlock(&ptr_log_info->dbg_log_lock);
  1222. if (!list_node)
  1223. return NULL;
  1224. return qdf_container_of(list_node, struct dbg_tx_comp_ppdu, node);
  1225. }
  1226. /*
  1227. * ppdu_desc_dbg_queue_init: ppdu desc logging debugfs queue init
  1228. * @ptr_log_info: tx capture debugfs log structure
  1229. *
  1230. * return: void
  1231. */
  1232. static void ppdu_desc_dbg_queue_init(struct tx_cap_debug_log_info *ptr_log_info)
  1233. {
  1234. ptr_log_info->ppdu_queue_size = MAX_TX_CAP_QUEUE_SIZE;
  1235. qdf_list_create(&ptr_log_info->ppdu_dbg_queue,
  1236. ptr_log_info->ppdu_queue_size);
  1237. qdf_spinlock_create(&ptr_log_info->dbg_log_lock);
  1238. ptr_log_info->pause_dbg_log = 0;
  1239. }
  1240. /*
  1241. * ppdu_desc_dbg_queue_deinit: ppdu desc logging debugfs queue deinit
  1242. * @ptr_log_info: tx capture debugfs log structure
  1243. *
  1244. * return: void
  1245. */
  1246. static
  1247. void ppdu_desc_dbg_queue_deinit(struct tx_cap_debug_log_info *ptr_log_info)
  1248. {
  1249. qdf_list_destroy(&ptr_log_info->ppdu_dbg_queue);
  1250. qdf_spinlock_destroy(&ptr_log_info->dbg_log_lock);
  1251. }
  1252. /*
  1253. * dp_tx_capture_work_q_timer_handler()- timer to schedule tx capture
  1254. * work queue
  1255. * @arg: pdev Handle
  1256. *
  1257. * Return:
  1258. *
  1259. */
  1260. static void dp_tx_capture_work_q_timer_handler(void *arg)
  1261. {
  1262. struct dp_pdev *pdev = (struct dp_pdev *)arg;
  1263. qdf_queue_work(0, pdev->tx_capture.ppdu_stats_workqueue,
  1264. &pdev->tx_capture.ppdu_stats_work);
  1265. qdf_timer_mod(&pdev->tx_capture.work_q_timer,
  1266. TX_CAPTURE_WORK_Q_TIMER_MS);
  1267. }
  1268. /**
  1269. * dp_tx_ppdu_stats_attach - Initialize Tx PPDU stats and enhanced capture
  1270. * @pdev: DP PDEV
  1271. *
  1272. * Return: none
  1273. */
  1274. void dp_tx_ppdu_stats_attach(struct dp_pdev *pdev)
  1275. {
  1276. struct dp_peer_mgmt_list *ptr_peer_mgmt_list;
  1277. struct dp_pdev_tx_capture *tx_capture;
  1278. struct tx_cap_debug_log_info *ptr_log_info;
  1279. int i, j;
  1280. qdf_atomic_init(&pdev->tx_capture.tx_cap_usr_mode);
  1281. qdf_atomic_set(&pdev->tx_capture.tx_cap_usr_mode, 0);
  1282. tx_capture = &pdev->tx_capture;
  1283. ptr_log_info = &tx_capture->log_info;
  1284. /* Work queue setup for HTT stats and tx capture handling */
  1285. qdf_create_work(0, &pdev->tx_capture.ppdu_stats_work,
  1286. dp_tx_ppdu_stats_process,
  1287. pdev);
  1288. pdev->tx_capture.ppdu_stats_workqueue =
  1289. qdf_alloc_unbound_workqueue("ppdu_stats_work_queue");
  1290. STAILQ_INIT(&pdev->tx_capture.ppdu_stats_queue);
  1291. STAILQ_INIT(&pdev->tx_capture.ppdu_stats_defer_queue);
  1292. qdf_spinlock_create(&pdev->tx_capture.ppdu_stats_lock);
  1293. pdev->tx_capture.ppdu_stats_queue_depth = 0;
  1294. pdev->tx_capture.ppdu_stats_defer_queue_depth = 0;
  1295. pdev->tx_capture.ppdu_dropped = 0;
  1296. qdf_timer_init(NULL, &pdev->tx_capture.work_q_timer,
  1297. dp_tx_capture_work_q_timer_handler,
  1298. (void *)pdev,
  1299. QDF_TIMER_TYPE_WAKE_APPS);
  1300. for (i = 0; i < TXCAP_MAX_TYPE; i++) {
  1301. for (j = 0; j < TXCAP_MAX_SUBTYPE; j++) {
  1302. check_queue_empty(
  1303. &pdev->tx_capture.ctl_mgmt_q[i][j]);
  1304. qdf_nbuf_queue_init(
  1305. &pdev->tx_capture.ctl_mgmt_q[i][j]);
  1306. qdf_spinlock_create(
  1307. &pdev->tx_capture.ctl_mgmt_lock[i][j]);
  1308. check_queue_empty(
  1309. &pdev->tx_capture.retries_ctl_mgmt_q[i][j]);
  1310. qdf_nbuf_queue_init(
  1311. &pdev->tx_capture.retries_ctl_mgmt_q[i][j]);
  1312. }
  1313. }
  1314. pdev->tx_capture.dummy_ppdu_desc = qdf_mem_malloc(
  1315. sizeof(struct cdp_tx_completion_ppdu) +
  1316. sizeof(struct cdp_tx_completion_ppdu_user));
  1317. if (qdf_unlikely(!pdev->tx_capture.dummy_ppdu_desc)) {
  1318. dp_tx_capture_err("%pK: Alloc failed", pdev->soc);
  1319. QDF_ASSERT(0);
  1320. return;
  1321. }
  1322. pdev->tx_capture.ptr_peer_mgmt_list = (struct dp_peer_mgmt_list *)
  1323. qdf_mem_malloc(sizeof(struct dp_peer_mgmt_list) *
  1324. MAX_MGMT_PEER_FILTER);
  1325. for (i = 0; i < MAX_MGMT_PEER_FILTER; i++) {
  1326. ptr_peer_mgmt_list = &tx_capture->ptr_peer_mgmt_list[i];
  1327. ptr_peer_mgmt_list->avail = true;
  1328. }
  1329. ppdu_desc_dbg_queue_init(ptr_log_info);
  1330. }
  1331. /**
  1332. * dp_tx_ppdu_stats_detach - Cleanup Tx PPDU stats and enhanced capture
  1333. * @pdev: DP PDEV
  1334. *
  1335. * Return: none
  1336. */
  1337. void dp_tx_ppdu_stats_detach(struct dp_pdev *pdev)
  1338. {
  1339. struct ppdu_info *ppdu_info, *tmp_ppdu_info = NULL;
  1340. struct tx_cap_debug_log_info *ptr_log_info;
  1341. int i, j;
  1342. void *buf;
  1343. if (!pdev || !pdev->tx_capture.ppdu_stats_workqueue)
  1344. return;
  1345. ptr_log_info = &pdev->tx_capture.log_info;
  1346. qdf_timer_sync_cancel(&pdev->tx_capture.work_q_timer);
  1347. qdf_timer_free(&pdev->tx_capture.work_q_timer);
  1348. qdf_flush_workqueue(0, pdev->tx_capture.ppdu_stats_workqueue);
  1349. qdf_destroy_workqueue(0, pdev->tx_capture.ppdu_stats_workqueue);
  1350. qdf_spinlock_destroy(&pdev->tx_capture.ppdu_stats_lock);
  1351. STAILQ_FOREACH_SAFE(ppdu_info,
  1352. &pdev->tx_capture.ppdu_stats_queue,
  1353. ppdu_info_queue_elem, tmp_ppdu_info) {
  1354. STAILQ_REMOVE(&pdev->tx_capture.ppdu_stats_queue,
  1355. ppdu_info, ppdu_info, ppdu_info_queue_elem);
  1356. qdf_nbuf_free(ppdu_info->nbuf);
  1357. qdf_mem_free(ppdu_info);
  1358. }
  1359. STAILQ_FOREACH_SAFE(ppdu_info,
  1360. &pdev->tx_capture.ppdu_stats_defer_queue,
  1361. ppdu_info_queue_elem, tmp_ppdu_info) {
  1362. STAILQ_REMOVE(&pdev->tx_capture.ppdu_stats_defer_queue,
  1363. ppdu_info, ppdu_info, ppdu_info_queue_elem);
  1364. qdf_nbuf_free(ppdu_info->nbuf);
  1365. qdf_mem_free(ppdu_info);
  1366. }
  1367. for (i = 0; i < TXCAP_MAX_TYPE; i++) {
  1368. for (j = 0; j < TXCAP_MAX_SUBTYPE; j++) {
  1369. qdf_nbuf_queue_t *retries_q;
  1370. qdf_spin_lock_bh(
  1371. &pdev->tx_capture.ctl_mgmt_lock[i][j]);
  1372. TX_CAP_NBUF_QUEUE_FREE(
  1373. &pdev->tx_capture.ctl_mgmt_q[i][j]);
  1374. qdf_spin_unlock_bh(
  1375. &pdev->tx_capture.ctl_mgmt_lock[i][j]);
  1376. qdf_spinlock_destroy(
  1377. &pdev->tx_capture.ctl_mgmt_lock[i][j]);
  1378. retries_q = &pdev->tx_capture.retries_ctl_mgmt_q[i][j];
  1379. if (!qdf_nbuf_is_queue_empty(retries_q))
  1380. TX_CAP_NBUF_QUEUE_FREE(retries_q);
  1381. }
  1382. }
  1383. qdf_mem_free(pdev->tx_capture.dummy_ppdu_desc);
  1384. qdf_mem_free(pdev->tx_capture.ptr_peer_mgmt_list);
  1385. /* disable the ppdu_desc_log to avoid storing further */
  1386. ptr_log_info->ppdu_desc_log = 0;
  1387. ptr_log_info->pause_dbg_log = 1;
  1388. /* loop through the list and free the nbuf */
  1389. while (!qdf_list_empty(&ptr_log_info->ppdu_dbg_queue)) {
  1390. buf = ppdu_desc_dbg_dequeue(ptr_log_info);
  1391. if (!buf)
  1392. qdf_mem_free(buf);
  1393. }
  1394. ppdu_desc_dbg_queue_deinit(ptr_log_info);
  1395. dp_tx_capture_debugfs_deinit(pdev);
  1396. }
  1397. #define MAX_MSDU_THRESHOLD_TSF 100000
  1398. #define MAX_MSDU_ENQUEUE_THRESHOLD 4096
  1399. /**
  1400. * dp_drop_enq_msdu_on_thresh(): Function to drop msdu when exceed
  1401. * storing threshold limit
  1402. * @pdev: Datapath pdev object
  1403. * @peer: Datapath peer object
  1404. * @tx_tid: tx tid
  1405. * @ptr_msdu_comp_q: pointer to skb queue, it can be either tasklet or WQ msdu q
  1406. * @tsf: current timestamp
  1407. *
  1408. * return: status
  1409. */
  1410. QDF_STATUS
  1411. dp_drop_enq_msdu_on_thresh(struct dp_pdev *pdev,
  1412. struct dp_peer *peer,
  1413. struct dp_tx_tid *tx_tid,
  1414. qdf_nbuf_queue_t *ptr_msdu_comp_q,
  1415. uint32_t tsf)
  1416. {
  1417. struct msdu_completion_info *ptr_msdu_info = NULL;
  1418. qdf_nbuf_t nbuf;
  1419. qdf_nbuf_t head_msdu;
  1420. uint32_t tsf_delta;
  1421. uint32_t comp_qlen = 0;
  1422. uint32_t defer_msdu_qlen = 0;
  1423. uint32_t qlen = 0;
  1424. uint32_t ppdu_id = 0;
  1425. uint32_t cur_ppdu_id = 0;
  1426. /* take lock here */
  1427. qdf_spin_lock_bh(&tx_tid->tasklet_tid_lock);
  1428. while ((head_msdu = qdf_nbuf_queue_first(ptr_msdu_comp_q))) {
  1429. ptr_msdu_info =
  1430. (struct msdu_completion_info *)qdf_nbuf_data(head_msdu);
  1431. if (tsf > ptr_msdu_info->tsf)
  1432. tsf_delta = tsf - ptr_msdu_info->tsf;
  1433. else
  1434. tsf_delta = LOWER_32_MASK - ptr_msdu_info->tsf + tsf;
  1435. /* exit loop if time difference is less than 100 msec */
  1436. if (tsf_delta < MAX_MSDU_THRESHOLD_TSF)
  1437. break;
  1438. /* free head */
  1439. nbuf = qdf_nbuf_queue_remove(ptr_msdu_comp_q);
  1440. if (qdf_unlikely(!nbuf)) {
  1441. qdf_assert_always(0);
  1442. break;
  1443. }
  1444. qdf_nbuf_free(nbuf);
  1445. dp_tx_cap_stats_msdu_update(peer, PEER_MSDU_DROP, 1);
  1446. pdev->tx_capture.msdu_threshold_drop++;
  1447. }
  1448. /* get queue length */
  1449. comp_qlen = qdf_nbuf_queue_len(ptr_msdu_comp_q);
  1450. /* release lock here */
  1451. qdf_spin_unlock_bh(&tx_tid->tasklet_tid_lock);
  1452. /* take lock here */
  1453. qdf_spin_lock_bh(&tx_tid->tid_lock);
  1454. defer_msdu_qlen = qdf_nbuf_queue_len(&tx_tid->defer_msdu_q);
  1455. qlen = defer_msdu_qlen + comp_qlen;
  1456. /* Drop queued msdu when exceed threshold */
  1457. while (qlen > MAX_MSDU_ENQUEUE_THRESHOLD) {
  1458. /* get first msdu */
  1459. head_msdu = qdf_nbuf_queue_first(&tx_tid->defer_msdu_q);
  1460. if (qdf_unlikely(!head_msdu))
  1461. break;
  1462. ptr_msdu_info =
  1463. (struct msdu_completion_info *)qdf_nbuf_data(head_msdu);
  1464. ppdu_id = ptr_msdu_info->ppdu_id;
  1465. cur_ppdu_id = ppdu_id;
  1466. while (ppdu_id == cur_ppdu_id) {
  1467. qdf_nbuf_t nbuf = NULL;
  1468. /* free head, nbuf will be NULL if queue empty */
  1469. nbuf = qdf_nbuf_queue_remove(&tx_tid->defer_msdu_q);
  1470. if (qdf_likely(nbuf)) {
  1471. qdf_nbuf_free(nbuf);
  1472. dp_tx_cap_stats_msdu_update(peer,
  1473. PEER_MSDU_DROP, 1);
  1474. pdev->tx_capture.msdu_threshold_drop++;
  1475. }
  1476. head_msdu = qdf_nbuf_queue_first(&tx_tid->defer_msdu_q);
  1477. if (qdf_unlikely(!head_msdu))
  1478. break;
  1479. ptr_msdu_info =
  1480. (struct msdu_completion_info *)qdf_nbuf_data(head_msdu);
  1481. cur_ppdu_id = ptr_msdu_info->ppdu_id;
  1482. }
  1483. /* get length again */
  1484. defer_msdu_qlen = qdf_nbuf_queue_len(&tx_tid->defer_msdu_q);
  1485. qlen = defer_msdu_qlen + comp_qlen;
  1486. }
  1487. /* release lock here */
  1488. qdf_spin_unlock_bh(&tx_tid->tid_lock);
  1489. return QDF_STATUS_SUCCESS;
  1490. }
  1491. /**
  1492. * dp_update_msdu_to_list(): Function to queue msdu from wbm
  1493. * @pdev: dp_pdev
  1494. * @peer: dp_peer
  1495. * @ts: hal tx completion status
  1496. * @netbuf: msdu
  1497. *
  1498. * return: status
  1499. */
  1500. QDF_STATUS
  1501. dp_update_msdu_to_list(struct dp_soc *soc,
  1502. struct dp_pdev *pdev,
  1503. struct dp_peer *peer,
  1504. struct hal_tx_completion_status *ts,
  1505. qdf_nbuf_t netbuf)
  1506. {
  1507. struct dp_tx_tid *tx_tid;
  1508. struct msdu_completion_info *msdu_comp_info;
  1509. if (!peer) {
  1510. dp_tx_capture_err("%pK: peer NULL !", soc);
  1511. return QDF_STATUS_E_FAILURE;
  1512. }
  1513. if ((ts->tid > DP_MAX_TIDS) ||
  1514. (peer->bss_peer && ts->tid == DP_NON_QOS_TID)) {
  1515. dp_tx_capture_err("%pK: peer_id %d, tid %d > NON_QOS_TID!",
  1516. soc, ts->peer_id, ts->tid);
  1517. return QDF_STATUS_E_FAILURE;
  1518. }
  1519. tx_tid = &peer->tx_capture.tx_tid[ts->tid];
  1520. if (!tx_tid) {
  1521. dp_tx_capture_err("%pK: tid[%d] NULL !", soc, ts->tid);
  1522. return QDF_STATUS_E_FAILURE;
  1523. }
  1524. if (!qdf_nbuf_push_head(netbuf, sizeof(struct msdu_completion_info))) {
  1525. dp_tx_capture_err("%pK: No headroom", soc);
  1526. return QDF_STATUS_E_NOMEM;
  1527. }
  1528. qdf_nbuf_unmap(soc->osdev, netbuf, QDF_DMA_TO_DEVICE);
  1529. msdu_comp_info = (struct msdu_completion_info *)qdf_nbuf_data(netbuf);
  1530. /* copy msdu_completion_info to control buffer */
  1531. msdu_comp_info->ppdu_id = ts->ppdu_id;
  1532. msdu_comp_info->peer_id = ts->peer_id;
  1533. msdu_comp_info->tid = ts->tid;
  1534. msdu_comp_info->first_msdu = ts->first_msdu;
  1535. msdu_comp_info->last_msdu = ts->last_msdu;
  1536. msdu_comp_info->msdu_part_of_amsdu = ts->msdu_part_of_amsdu;
  1537. msdu_comp_info->transmit_cnt = ts->transmit_cnt;
  1538. msdu_comp_info->tsf = ts->tsf;
  1539. msdu_comp_info->status = ts->status;
  1540. if (tx_tid->max_ppdu_id != ts->ppdu_id)
  1541. dp_drop_enq_msdu_on_thresh(pdev, peer, tx_tid,
  1542. &tx_tid->msdu_comp_q, ts->tsf);
  1543. /* lock here */
  1544. qdf_spin_lock_bh(&tx_tid->tasklet_tid_lock);
  1545. /* add nbuf to tail queue per peer tid */
  1546. qdf_nbuf_queue_add(&tx_tid->msdu_comp_q, netbuf);
  1547. dp_tx_cap_stats_msdu_update(peer, PEER_MSDU_ENQ, 1);
  1548. /* store last enqueue msec */
  1549. tx_tid->last_enq_ms = qdf_system_ticks_to_msecs(qdf_system_ticks());
  1550. /* unlock here */
  1551. qdf_spin_unlock_bh(&tx_tid->tasklet_tid_lock);
  1552. /* update max ppdu_id */
  1553. tx_tid->max_ppdu_id = ts->ppdu_id;
  1554. pdev->tx_capture.last_msdu_id = ts->ppdu_id;
  1555. pdev->tx_capture.last_peer_id = ts->peer_id;
  1556. dp_tx_capture_info("%pK: msdu_completion: ppdu_id[%d] peer_id[%d] tid[%d] rel_src[%d] status[%d] tsf[%u] A[%d] CNT[%d]",
  1557. soc, ts->ppdu_id, ts->peer_id, ts->tid, ts->release_src,
  1558. ts->status, ts->tsf, ts->msdu_part_of_amsdu,
  1559. ts->transmit_cnt);
  1560. return QDF_STATUS_SUCCESS;
  1561. }
  1562. /**
  1563. * dp_tx_add_to_comp_queue() - add completion msdu to queue
  1564. * @soc: DP Soc handle
  1565. * @tx_desc: software Tx descriptor
  1566. * @ts: Tx completion status from HAL/HTT descriptor
  1567. * @peer: DP peer
  1568. *
  1569. * Return: none
  1570. */
  1571. QDF_STATUS dp_tx_add_to_comp_queue(struct dp_soc *soc,
  1572. struct dp_tx_desc_s *desc,
  1573. struct hal_tx_completion_status *ts,
  1574. struct dp_peer *peer)
  1575. {
  1576. int ret = QDF_STATUS_E_FAILURE;
  1577. struct dp_pdev *pdev = desc->pdev;
  1578. if (peer &&
  1579. dp_peer_or_pdev_tx_cap_enabled(pdev, peer, peer->mac_addr.raw) &&
  1580. ((ts->status == HAL_TX_TQM_RR_FRAME_ACKED) ||
  1581. (ts->status == HAL_TX_TQM_RR_REM_CMD_TX) ||
  1582. ((ts->status == HAL_TX_TQM_RR_REM_CMD_AGED) && ts->transmit_cnt))) {
  1583. if (qdf_unlikely(desc->pkt_offset != 0) &&
  1584. (qdf_nbuf_pull_head(
  1585. desc->nbuf, desc->pkt_offset) == NULL)) {
  1586. dp_tx_capture_err("%pK: netbuf %pK offset %d",
  1587. soc, desc->nbuf, desc->pkt_offset);
  1588. return ret;
  1589. }
  1590. ret = dp_update_msdu_to_list(soc, pdev, peer, ts, desc->nbuf);
  1591. }
  1592. return ret;
  1593. }
  1594. /**
  1595. * get_number_of_1s(): Function to get number of 1s
  1596. * @value: value to find
  1597. *
  1598. * return: number of 1s
  1599. */
  1600. static
  1601. inline uint32_t get_number_of_1s(uint32_t value)
  1602. {
  1603. uint32_t shift[] = {1, 2, 4, 8, 16};
  1604. uint32_t magic_number[] = { 0x55555555, 0x33333333, 0x0F0F0F0F,
  1605. 0x00FF00FF, 0x0000FFFF};
  1606. uint8_t k = 0;
  1607. for (; k <= 4; k++) {
  1608. value = (value & magic_number[k]) +
  1609. ((value >> shift[k]) & magic_number[k]);
  1610. }
  1611. return value;
  1612. }
  1613. /**
  1614. * dp_process_ppdu_stats_update_failed_bitmap(): update failed bitmap
  1615. * @pdev: dp_pdev
  1616. * @data: tx completion ppdu desc
  1617. * @ppdu_id: ppdu id
  1618. * @size: size of bitmap
  1619. *
  1620. * return: status
  1621. */
  1622. void dp_process_ppdu_stats_update_failed_bitmap(struct dp_pdev *pdev,
  1623. void *data,
  1624. uint32_t ppdu_id,
  1625. uint32_t size)
  1626. {
  1627. struct cdp_tx_completion_ppdu_user *user;
  1628. uint32_t mpdu_tried;
  1629. uint32_t ba_seq_no;
  1630. uint32_t start_seq;
  1631. uint32_t num_mpdu;
  1632. uint32_t diff;
  1633. uint32_t carry = 0;
  1634. uint32_t bitmask = 0;
  1635. uint32_t i;
  1636. uint32_t k;
  1637. uint32_t ba_bitmap = 0;
  1638. int last_set_bit;
  1639. uint32_t last_ba_set_bit = 0;
  1640. uint8_t extra_ba_mpdus = 0;
  1641. uint32_t last_ba_seq = 0;
  1642. uint32_t enq_ba_bitmap[CDP_BA_256_BIT_MAP_SIZE_DWORDS] = {0};
  1643. uint32_t mpdu_enq = 0;
  1644. user = (struct cdp_tx_completion_ppdu_user *)data;
  1645. /* get number of mpdu from ppdu_desc */
  1646. mpdu_tried = user->mpdu_tried_mcast + user->mpdu_tried_ucast;
  1647. ba_seq_no = user->ba_seq_no;
  1648. start_seq = user->start_seq;
  1649. num_mpdu = user->num_mpdu;
  1650. /* assumption: number of mpdu will be less than 32 */
  1651. dp_tx_capture_info("%pK: ppdu_id[%d] ba_seq_no[%d] start_seq_no[%d] mpdu_tried[%d]",
  1652. pdev->soc, ppdu_id, ba_seq_no, start_seq, mpdu_tried);
  1653. for (i = 0; i < size; i++) {
  1654. dp_tx_capture_info("%pK: ppdu_id[%d] ba_bitmap[%x] enqueue_bitmap[%x]",
  1655. pdev->soc, ppdu_id, user->ba_bitmap[i], user->enq_bitmap[i]);
  1656. }
  1657. /* Handle sequence no. wraparound */
  1658. if (start_seq <= ba_seq_no) {
  1659. diff = ba_seq_no - start_seq;
  1660. /* Sequence delta of more than 2048 is considered wraparound
  1661. * and we extend start_seq to be more than ba_seq just to
  1662. * adjust failed_bitmap
  1663. */
  1664. if (qdf_unlikely(diff > (IEEE80211_SEQ_MAX / 2))) {
  1665. diff = (start_seq - ba_seq_no) &
  1666. (IEEE80211_SEQ_MAX - 1);
  1667. start_seq = ba_seq_no + diff;
  1668. }
  1669. } else {
  1670. diff = start_seq - ba_seq_no;
  1671. /* Sequence delta of more than 2048 is considered wraparound
  1672. * and we extend ba_seq to be more than start_seq just to
  1673. * adjust failed_bitmap
  1674. */
  1675. if (qdf_unlikely(diff > (IEEE80211_SEQ_MAX / 2))) {
  1676. diff = (ba_seq_no - start_seq) &
  1677. (IEEE80211_SEQ_MAX - 1);
  1678. ba_seq_no = start_seq + diff;
  1679. }
  1680. }
  1681. if (num_mpdu > mpdu_tried) {
  1682. extra_ba_mpdus = 1;
  1683. }
  1684. /* Adjust failed_bitmap to start from same seq_no as enq_bitmap */
  1685. last_set_bit = 0;
  1686. if (start_seq <= ba_seq_no) {
  1687. bitmask = (1 << diff) - 1;
  1688. for (i = 0; i < size; i++) {
  1689. ba_bitmap = user->ba_bitmap[i];
  1690. user->failed_bitmap[i] = (ba_bitmap << diff);
  1691. user->failed_bitmap[i] |= (bitmask & carry);
  1692. carry = ((ba_bitmap & (bitmask << (32 - diff))) >>
  1693. (32 - diff));
  1694. if (user->failed_bitmap[i]) {
  1695. last_ba_set_bit = i * 32 +
  1696. qdf_fls(user->failed_bitmap[i]) - 1;
  1697. if (extra_ba_mpdus) {
  1698. enq_ba_bitmap[i] =
  1699. user->failed_bitmap[i];
  1700. dp_tx_capture_info("%pK: i=%d failed_bitmap[%d] = 0x%x last_ba_set_bit:%d\n",
  1701. pdev->soc, i, i, user->failed_bitmap[i],
  1702. last_ba_set_bit);
  1703. }
  1704. }
  1705. if (user->enq_bitmap[i]) {
  1706. last_set_bit = i * 32 +
  1707. qdf_fls(user->enq_bitmap[i]) - 1;
  1708. }
  1709. if (extra_ba_mpdus) {
  1710. user->enq_bitmap[i] = enq_ba_bitmap[i];
  1711. } else {
  1712. user->failed_bitmap[i] = user->enq_bitmap[i] &
  1713. user->failed_bitmap[i];
  1714. }
  1715. }
  1716. } else {
  1717. /* array index */
  1718. k = diff >> 5;
  1719. diff = diff & 0x1F;
  1720. bitmask = (1 << diff) - 1;
  1721. for (i = 0; i < size && (k < (size - 1)); i++, k++) {
  1722. ba_bitmap = user->ba_bitmap[k];
  1723. user->failed_bitmap[i] = ba_bitmap >> diff;
  1724. /* get next ba_bitmap */
  1725. ba_bitmap = user->ba_bitmap[k + 1];
  1726. carry = (ba_bitmap & bitmask);
  1727. user->failed_bitmap[i] |=
  1728. ((carry & bitmask) << (32 - diff));
  1729. if (user->failed_bitmap[i]) {
  1730. last_ba_set_bit = i * 32 +
  1731. qdf_fls(user->failed_bitmap[i]) - 1;
  1732. if (extra_ba_mpdus) {
  1733. enq_ba_bitmap[i] =
  1734. user->failed_bitmap[i];
  1735. dp_tx_capture_info("%pK: i=%d failed_bitmap[%d] = 0x%x last_ba_set_bit:%d\n",
  1736. pdev->soc, i, i, user->failed_bitmap[i],
  1737. last_ba_set_bit);
  1738. }
  1739. }
  1740. if (user->enq_bitmap[i]) {
  1741. last_set_bit = i * 32 +
  1742. qdf_fls(user->enq_bitmap[i]) - 1;
  1743. }
  1744. if (extra_ba_mpdus) {
  1745. user->enq_bitmap[i] = enq_ba_bitmap[i];
  1746. } else {
  1747. user->failed_bitmap[i] = user->enq_bitmap[i] &
  1748. user->failed_bitmap[i];
  1749. }
  1750. }
  1751. }
  1752. user->last_enq_seq = user->start_seq + last_set_bit;
  1753. user->ba_size = user->last_enq_seq - user->start_seq + 1;
  1754. last_ba_seq = user->start_seq + last_ba_set_bit;
  1755. /* mpdu_tried should be always higher than last ba bit in ba bitmap */
  1756. if ((user->mpdu_tried_ucast) &&
  1757. (user->mpdu_tried_ucast < (last_set_bit + 1))) {
  1758. for (i = 0; i < size; i++)
  1759. mpdu_enq += get_number_of_1s(user->enq_bitmap[i]);
  1760. if (user->mpdu_tried_ucast < mpdu_enq) {
  1761. for (i = 0; i < size; i++)
  1762. dp_tx_capture_info("%pK: ppdu_id[%d] ba_bitmap[%x] enqueue_bitmap[%x] failed_bitmap[%x]",
  1763. pdev->soc, ppdu_id, user->ba_bitmap[i],
  1764. user->enq_bitmap[i],
  1765. user->failed_bitmap[i]);
  1766. dp_tx_capture_info("%pK: last_set_bit:%d mpdu_tried_ucast %d mpdu_enq %d\n",
  1767. pdev->soc, last_set_bit,
  1768. user->mpdu_tried_ucast, mpdu_enq);
  1769. user->mpdu_tried_ucast = mpdu_enq;
  1770. }
  1771. }
  1772. if (extra_ba_mpdus) {
  1773. dp_tx_capture_info("%pK: ppdu_id:%u ba_size:%u modified_ba_size:%u last_ba_set_bit:%u start_seq: %u\n",
  1774. pdev->soc,
  1775. ppdu_id,
  1776. user->ba_size,
  1777. last_ba_seq - user->start_seq + 1,
  1778. last_ba_set_bit, user->start_seq);
  1779. user->ba_size = last_ba_seq - user->start_seq + 1;
  1780. user->last_enq_seq = last_ba_seq;
  1781. }
  1782. }
  1783. /*
  1784. * dp_soc_set_txrx_ring_map_single()
  1785. * @dp_soc: DP handler for soc
  1786. *
  1787. * Return: Void
  1788. */
  1789. static void dp_soc_set_txrx_ring_map_single(struct dp_soc *soc)
  1790. {
  1791. uint32_t i;
  1792. for (i = 0; i < WLAN_CFG_INT_NUM_CONTEXTS; i++) {
  1793. soc->tx_ring_map[i] =
  1794. dp_cpu_ring_map[DP_SINGLE_TX_RING_MAP][i];
  1795. }
  1796. }
  1797. static void dp_peer_free_msdu_q(struct dp_soc *soc,
  1798. struct dp_peer *peer,
  1799. void *arg)
  1800. {
  1801. /* disable tx capture flag in peer */
  1802. peer->tx_cap_enabled = 0;
  1803. dp_peer_tid_queue_cleanup(peer);
  1804. }
  1805. static void dp_peer_init_msdu_q(struct dp_soc *soc,
  1806. struct dp_peer *peer,
  1807. void *arg)
  1808. {
  1809. dp_peer_tid_queue_init(peer);
  1810. }
  1811. /*
  1812. * dp_soc_is_tx_capture_set_in_pdev() - API to get tx capture set in any pdev
  1813. * @soc_handle: DP_SOC handle
  1814. *
  1815. * return: true
  1816. */
  1817. uint8_t
  1818. dp_soc_is_tx_capture_set_in_pdev(struct dp_soc *soc)
  1819. {
  1820. struct dp_pdev *pdev;
  1821. uint8_t pdev_tx_capture = 0;
  1822. uint8_t i;
  1823. for (i = 0; i < MAX_PDEV_CNT; i++) {
  1824. pdev = soc->pdev_list[i];
  1825. if (!pdev)
  1826. continue;
  1827. if (!pdev->tx_capture_enabled)
  1828. continue;
  1829. pdev_tx_capture++;
  1830. }
  1831. return pdev_tx_capture;
  1832. }
  1833. /*
  1834. * dp_enh_tx_capture_disable()- API to disable enhanced tx capture
  1835. * @pdev_handle: DP_PDEV handle
  1836. * Return: void
  1837. */
  1838. void
  1839. dp_enh_tx_capture_disable(struct dp_pdev *pdev)
  1840. {
  1841. int i, j;
  1842. dp_peer_tx_cap_del_all_filter(pdev);
  1843. pdev->tx_capture_enabled = CDP_TX_ENH_CAPTURE_DISABLED;
  1844. if (!dp_soc_is_tx_capture_set_in_pdev(pdev->soc))
  1845. dp_soc_set_txrx_ring_map(pdev->soc);
  1846. dp_h2t_cfg_stats_msg_send(pdev,
  1847. DP_PPDU_STATS_CFG_ENH_STATS,
  1848. pdev->pdev_id);
  1849. dp_pdev_iterate_peer(pdev, dp_peer_free_msdu_q, NULL,
  1850. DP_MOD_ID_TX_CAPTURE);
  1851. for (i = 0; i < TXCAP_MAX_TYPE; i++) {
  1852. for (j = 0; j < TXCAP_MAX_SUBTYPE; j++) {
  1853. qdf_nbuf_queue_t *retries_q;
  1854. qdf_spin_lock_bh(
  1855. &pdev->tx_capture.ctl_mgmt_lock[i][j]);
  1856. TX_CAP_NBUF_QUEUE_FREE(
  1857. &pdev->tx_capture.ctl_mgmt_q[i][j]);
  1858. qdf_spin_unlock_bh(
  1859. &pdev->tx_capture.ctl_mgmt_lock[i][j]);
  1860. retries_q = &pdev->tx_capture.retries_ctl_mgmt_q[i][j];
  1861. if (!qdf_nbuf_is_queue_empty(retries_q))
  1862. TX_CAP_NBUF_QUEUE_FREE(retries_q);
  1863. }
  1864. }
  1865. dp_tx_capture_info("%pK: Mode change request done cur mode - %d user_mode - %d\n",
  1866. pdev->soc, pdev->tx_capture_enabled, CDP_TX_ENH_CAPTURE_DISABLED);
  1867. }
  1868. /*
  1869. * dp_enh_tx_capture_enable()- API to disable enhanced tx capture
  1870. * @pdev_handle: DP_PDEV handle
  1871. * @user_mode: user mode
  1872. *
  1873. * Return: void
  1874. */
  1875. void
  1876. dp_enh_tx_capture_enable(struct dp_pdev *pdev, uint8_t user_mode)
  1877. {
  1878. dp_pdev_iterate_peer(pdev, dp_peer_init_msdu_q, NULL,
  1879. DP_MOD_ID_TX_CAPTURE);
  1880. if (!dp_soc_is_tx_capture_set_in_pdev(pdev->soc))
  1881. dp_soc_set_txrx_ring_map_single(pdev->soc);
  1882. if (!pdev->pktlog_ppdu_stats)
  1883. dp_h2t_cfg_stats_msg_send(pdev,
  1884. DP_PPDU_STATS_CFG_SNIFFER,
  1885. pdev->pdev_id);
  1886. pdev->tx_capture.msdu_threshold_drop = 0;
  1887. pdev->tx_capture_enabled = user_mode;
  1888. dp_tx_capture_info("%pK: Mode change request done cur mode - %d user_mode - %d\n",
  1889. pdev->soc, pdev->tx_capture_enabled, user_mode);
  1890. }
  1891. /*
  1892. * dp_enh_tx_cap_mode_change()- API to enable/disable enhanced tx capture
  1893. * @pdev_handle: DP_PDEV handle
  1894. * @user_mode: user provided value
  1895. *
  1896. * Return: void
  1897. */
  1898. static void
  1899. dp_enh_tx_cap_mode_change(struct dp_pdev *pdev, uint8_t user_mode)
  1900. {
  1901. if (user_mode == CDP_TX_ENH_CAPTURE_DISABLED) {
  1902. dp_enh_tx_capture_disable(pdev);
  1903. } else {
  1904. dp_enh_tx_capture_enable(pdev, user_mode);
  1905. }
  1906. }
  1907. /*
  1908. * dp_config_enh_tx_capture()- API to enable/disable enhanced tx capture
  1909. * @pdev_handle: DP_PDEV handle
  1910. * @val: user provided value
  1911. *
  1912. * Return: QDF_STATUS
  1913. */
  1914. QDF_STATUS
  1915. dp_config_enh_tx_capture(struct dp_pdev *pdev, uint8_t val)
  1916. {
  1917. qdf_atomic_set(&pdev->tx_capture.tx_cap_usr_mode, val);
  1918. dp_tx_capture_info("%pK: User mode change requested - %d\n",
  1919. pdev->soc, qdf_atomic_read(&pdev->tx_capture.tx_cap_usr_mode));
  1920. return QDF_STATUS_SUCCESS;
  1921. }
  1922. /**
  1923. * dp_tx_print_bitmap(): Function to print bitmap
  1924. * @pdev: dp_pdev
  1925. * @ppdu_desc: ppdu completion descriptor
  1926. * @user_inder: user index
  1927. * @ppdu_id: ppdu id
  1928. *
  1929. * return: status
  1930. */
  1931. static
  1932. QDF_STATUS dp_tx_print_bitmap(struct dp_pdev *pdev,
  1933. struct cdp_tx_completion_ppdu *ppdu_desc,
  1934. uint32_t user_index,
  1935. uint32_t ppdu_id)
  1936. {
  1937. struct cdp_tx_completion_ppdu_user *user;
  1938. uint8_t i;
  1939. uint32_t mpdu_tried;
  1940. uint32_t ba_seq_no;
  1941. uint32_t start_seq;
  1942. uint32_t num_mpdu;
  1943. uint32_t fail_num_mpdu = 0;
  1944. user = &ppdu_desc->user[user_index];
  1945. /* get number of mpdu from ppdu_desc */
  1946. mpdu_tried = user->mpdu_tried_mcast + user->mpdu_tried_ucast;
  1947. ba_seq_no = user->ba_seq_no;
  1948. start_seq = user->start_seq;
  1949. num_mpdu = user->mpdu_success;
  1950. if (user->tid > DP_MAX_TIDS) {
  1951. dp_tx_capture_err("%pK: ppdu[%d] peer_id[%d] TID[%d] > NON_QOS_TID!",
  1952. pdev->soc, ppdu_id, user->peer_id, user->tid);
  1953. return QDF_STATUS_E_FAILURE;
  1954. }
  1955. if (mpdu_tried != num_mpdu) {
  1956. dp_tx_capture_info("%pK: ppdu[%d] peer[%d] tid[%d] ba[%d] start[%d] mpdu_tri[%d] num_mpdu[%d] is_mcast[%d]",
  1957. pdev->soc, ppdu_id, user->peer_id, user->tid,
  1958. ba_seq_no, start_seq, mpdu_tried,
  1959. num_mpdu, user->is_mcast);
  1960. for (i = 0; i < CDP_BA_256_BIT_MAP_SIZE_DWORDS; i++) {
  1961. dp_tx_capture_err("%pK: ppdu_id[%d] ba_bitmap[0x%x] enqueue_bitmap[0x%x] failed_bitmap[0x%x]",
  1962. pdev->soc, ppdu_id, user->ba_bitmap[i],
  1963. user->enq_bitmap[i],
  1964. user->failed_bitmap[i]);
  1965. fail_num_mpdu +=
  1966. get_number_of_1s(user->failed_bitmap[i]);
  1967. }
  1968. }
  1969. if (fail_num_mpdu == num_mpdu && num_mpdu)
  1970. dp_tx_capture_debug("%pK: ppdu_id[%d] num_mpdu[%d, %d]",
  1971. pdev->soc, ppdu_id, num_mpdu, fail_num_mpdu);
  1972. return QDF_STATUS_SUCCESS;
  1973. }
  1974. /**
  1975. * dp_ppdu_desc_debug_print(): Function to print ppdu_desc
  1976. * @ppdu_desc: ppdu desc pointer
  1977. * @usr_idx: user index
  1978. * @func: caller function name
  1979. * @line: caller function line number
  1980. *
  1981. * return: void
  1982. */
  1983. void dp_ppdu_desc_debug_print(struct cdp_tx_completion_ppdu *ppdu_desc,
  1984. uint8_t usr_idx, const char *func, uint32_t line)
  1985. {
  1986. struct cdp_tx_completion_ppdu_user *user;
  1987. uint8_t num_users;
  1988. num_users = ppdu_desc->num_users;
  1989. dp_tx_capture_info("PID: %d, BPID: %d SCHED: %d usr_idx: %d TLV_BITMAP[0x%x] num_users:%d",
  1990. ppdu_desc->ppdu_id, ppdu_desc->bar_ppdu_id,
  1991. ppdu_desc->sched_cmdid,
  1992. usr_idx, ppdu_desc->tlv_bitmap, ppdu_desc->num_users);
  1993. user = &ppdu_desc->user[usr_idx];
  1994. dp_tx_capture_info("P[%d] CS:%d S_SEQ: %d L_ENQ_SEQ:%d BA_SEQ:%d BA_SZ:%d M[TRI: %d, SUC: %d] ENQ[%x:%x:%x:%x] BA[%x:%x:%x:%x] F[%x:%x:%x:%x] tlv[0x%x]",
  1995. user->peer_id,
  1996. user->completion_status,
  1997. user->start_seq, user->last_enq_seq,
  1998. user->ba_seq_no, user->ba_size,
  1999. user->mpdu_tried_ucast + user->mpdu_tried_mcast,
  2000. user->mpdu_success,
  2001. user->enq_bitmap[0], user->enq_bitmap[1],
  2002. user->enq_bitmap[2], user->enq_bitmap[3],
  2003. user->ba_bitmap[0], user->ba_bitmap[1],
  2004. user->ba_bitmap[2], user->ba_bitmap[3],
  2005. user->failed_bitmap[0], user->failed_bitmap[1],
  2006. user->failed_bitmap[2], user->failed_bitmap[3],
  2007. user->tlv_bitmap);
  2008. }
  2009. /*
  2010. * dp_peer_tx_wds_addr_add() – Update WDS peer to include 4th address
  2011. * @peer: Datapath peer
  2012. * @addr4_mac_addr: Source MAC address for WDS TX
  2013. *
  2014. */
  2015. static
  2016. void dp_peer_tx_wds_addr_add(struct dp_peer *peer, uint8_t *addr4_mac_addr)
  2017. {
  2018. struct ieee80211_frame_addr4 *ptr_wh = NULL;
  2019. struct dp_vdev *vdev = NULL;
  2020. if (!peer) {
  2021. qdf_err("peer is NULL!");
  2022. return;
  2023. }
  2024. vdev = peer->vdev;
  2025. if (!vdev) {
  2026. qdf_err("vdev is NULL!");
  2027. return;
  2028. }
  2029. ptr_wh = &peer->tx_capture.tx_wifi_addr4_hdr;
  2030. qdf_mem_copy(ptr_wh->i_addr1,
  2031. peer->mac_addr.raw,
  2032. QDF_MAC_ADDR_SIZE);
  2033. qdf_mem_copy(ptr_wh->i_addr2,
  2034. vdev->mac_addr.raw,
  2035. QDF_MAC_ADDR_SIZE);
  2036. qdf_mem_copy(ptr_wh->i_addr4,
  2037. addr4_mac_addr,
  2038. QDF_MAC_ADDR_SIZE);
  2039. }
  2040. /*
  2041. * dp_peer_tx_update_80211_wds_hdr() – Update 80211 frame header to include a
  2042. * 4 address frame, and set QoS related information if necessary
  2043. * @pdev: Physical device reference
  2044. * @peer: Datapath peer
  2045. * @data: ppdu_descriptor
  2046. * @nbuf: 802.11 frame
  2047. * @ether_type: ethernet type
  2048. * @src_addr: ether shost address
  2049. * @usr_idx: user index
  2050. *
  2051. */
  2052. static uint32_t dp_tx_update_80211_wds_hdr(struct dp_pdev *pdev,
  2053. struct dp_peer *peer,
  2054. void *data,
  2055. qdf_nbuf_t nbuf,
  2056. uint16_t ether_type,
  2057. uint8_t *dst_addr,
  2058. uint8_t usr_idx,
  2059. bool is_amsdu)
  2060. {
  2061. struct cdp_tx_completion_ppdu *ppdu_desc;
  2062. struct cdp_tx_completion_ppdu_user *user;
  2063. uint32_t mpdu_buf_len, frame_size;
  2064. uint8_t *ptr_hdr;
  2065. uint16_t eth_type = qdf_htons(ether_type);
  2066. struct ieee80211_qosframe_addr4 *ptr_wh;
  2067. ppdu_desc = (struct cdp_tx_completion_ppdu *)data;
  2068. user = &ppdu_desc->user[usr_idx];
  2069. ptr_wh = &peer->tx_capture.tx_wifi_addr4_qos_hdr;
  2070. /*
  2071. * update framectrl only for first ppdu_id
  2072. * rest of mpdu will have same frame ctrl
  2073. * mac address and duration
  2074. */
  2075. if (ppdu_desc->ppdu_id != peer->tx_capture.tx_wifi_ppdu_id) {
  2076. ptr_wh->i_fc[1] = (ppdu_desc->frame_ctrl & 0xFF00) >> 8;
  2077. ptr_wh->i_fc[0] = (ppdu_desc->frame_ctrl & 0xFF);
  2078. ptr_wh->i_dur[1] = (ppdu_desc->tx_duration & 0xFF00) >> 8;
  2079. ptr_wh->i_dur[0] = (ppdu_desc->tx_duration & 0xFF);
  2080. ptr_wh->i_qos[1] = (user->qos_ctrl & 0xFF00) >> 8;
  2081. ptr_wh->i_qos[0] = (user->qos_ctrl & 0xFF);
  2082. peer->tx_capture.tx_wifi_ppdu_id = ppdu_desc->ppdu_id;
  2083. }
  2084. if (is_amsdu) {
  2085. ptr_wh->i_qos[0] |= IEEE80211_QOS_AMSDU;
  2086. /* update addr3 and addr4 with BSSID in an AMSDU frame */
  2087. qdf_mem_copy(ptr_wh->i_addr3, ptr_wh->i_addr2,
  2088. QDF_MAC_ADDR_SIZE);
  2089. qdf_mem_copy(ptr_wh->i_addr4, ptr_wh->i_addr2,
  2090. QDF_MAC_ADDR_SIZE);
  2091. } else {
  2092. /* Update Addr 3 (DA) with DA derived from ether packet */
  2093. qdf_mem_copy(ptr_wh->i_addr3, dst_addr, QDF_MAC_ADDR_SIZE);
  2094. }
  2095. frame_size = (user->tid != DP_NON_QOS_TID) ?
  2096. sizeof(struct ieee80211_qosframe_addr4) :
  2097. sizeof(struct ieee80211_frame_addr4);
  2098. if (is_amsdu)
  2099. mpdu_buf_len = frame_size;
  2100. else
  2101. mpdu_buf_len = frame_size + LLC_SNAP_HDR_LEN;
  2102. nbuf->protocol = qdf_htons(ETH_P_802_2);
  2103. /* update ieee80211_frame header */
  2104. if (!qdf_nbuf_push_head(nbuf, mpdu_buf_len)) {
  2105. dp_tx_capture_err("%pK: No headroom", pdev->soc);
  2106. return QDF_STATUS_E_NOMEM;
  2107. }
  2108. ptr_hdr = (void *)qdf_nbuf_data(nbuf);
  2109. qdf_mem_copy(ptr_hdr, ptr_wh, frame_size);
  2110. ptr_hdr = ptr_hdr + frame_size;
  2111. /* update LLC */
  2112. if (!is_amsdu) {
  2113. *ptr_hdr = LLC_SNAP_LSAP;
  2114. *(ptr_hdr + 1) = LLC_SNAP_LSAP;
  2115. *(ptr_hdr + 2) = LLC_UI;
  2116. *(ptr_hdr + 3) = 0x00;
  2117. *(ptr_hdr + 4) = 0x00;
  2118. *(ptr_hdr + 5) = 0x00;
  2119. *(ptr_hdr + 6) = (eth_type & 0xFF00) >> 8;
  2120. *(ptr_hdr + 7) = (eth_type & 0xFF);
  2121. }
  2122. qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) - mpdu_buf_len);
  2123. return 0;
  2124. }
  2125. /**
  2126. * dp_tx_update_80211_hdr() – Update 80211 frame header to set QoS
  2127. * related information if necessary
  2128. * @pdev: Physical device reference
  2129. * @peer: Datapath peer
  2130. * @data: ppdu_descriptor
  2131. * @nbuf: 802.11 frame
  2132. * @ether_type: ethernet type
  2133. * @src_addr: ether shost address
  2134. *
  2135. */
  2136. static uint32_t dp_tx_update_80211_hdr(struct dp_pdev *pdev,
  2137. struct dp_peer *peer,
  2138. void *data,
  2139. qdf_nbuf_t nbuf,
  2140. uint16_t ether_type,
  2141. uint8_t *src_addr,
  2142. uint8_t usr_idx,
  2143. bool is_amsdu)
  2144. {
  2145. struct cdp_tx_completion_ppdu *ppdu_desc;
  2146. struct cdp_tx_completion_ppdu_user *user;
  2147. uint32_t mpdu_buf_len, frame_size;
  2148. uint8_t *ptr_hdr;
  2149. uint16_t eth_type = qdf_htons(ether_type);
  2150. struct ieee80211_qosframe *ptr_wh;
  2151. ppdu_desc = (struct cdp_tx_completion_ppdu *)data;
  2152. user = &ppdu_desc->user[usr_idx];
  2153. ptr_wh = &peer->tx_capture.tx_wifi_qos_hdr;
  2154. /*
  2155. * update framectrl only for first ppdu_id
  2156. * rest of mpdu will have same frame ctrl
  2157. * mac address and duration
  2158. */
  2159. if (ppdu_desc->ppdu_id != peer->tx_capture.tx_wifi_ppdu_id) {
  2160. ptr_wh->i_fc[1] = (user->frame_ctrl & 0xFF00) >> 8;
  2161. ptr_wh->i_fc[0] = (user->frame_ctrl & 0xFF);
  2162. ptr_wh->i_dur[1] = (ppdu_desc->tx_duration & 0xFF00) >> 8;
  2163. ptr_wh->i_dur[0] = (ppdu_desc->tx_duration & 0xFF);
  2164. ptr_wh->i_qos[1] = (user->qos_ctrl & 0xFF00) >> 8;
  2165. ptr_wh->i_qos[0] = (user->qos_ctrl & 0xFF);
  2166. peer->tx_capture.tx_wifi_ppdu_id = ppdu_desc->ppdu_id;
  2167. }
  2168. if (is_amsdu) {
  2169. ptr_wh->i_qos[0] |= IEEE80211_QOS_AMSDU;
  2170. /* update addr3 with BSSID in an AMSDU frame */
  2171. qdf_mem_copy(ptr_wh->i_addr3, ptr_wh->i_addr2,
  2172. QDF_MAC_ADDR_SIZE);
  2173. } else {
  2174. /* Update Addr 3 (SA) with SA derived from ether packet */
  2175. qdf_mem_copy(ptr_wh->i_addr3, src_addr, QDF_MAC_ADDR_SIZE);
  2176. }
  2177. frame_size = (user->tid != DP_NON_QOS_TID) ?
  2178. sizeof(struct ieee80211_qosframe) :
  2179. sizeof(struct ieee80211_frame);
  2180. if (is_amsdu)
  2181. mpdu_buf_len = frame_size;
  2182. else
  2183. mpdu_buf_len = frame_size + LLC_SNAP_HDR_LEN;
  2184. nbuf->protocol = qdf_htons(ETH_P_802_2);
  2185. /* update ieee80211_frame header */
  2186. if (!qdf_nbuf_push_head(nbuf, mpdu_buf_len)) {
  2187. dp_tx_capture_err("%pK: No headroom", pdev->soc);
  2188. return QDF_STATUS_E_NOMEM;
  2189. }
  2190. ptr_hdr = (void *)qdf_nbuf_data(nbuf);
  2191. qdf_mem_copy(ptr_hdr, ptr_wh, frame_size);
  2192. if (!is_amsdu) {
  2193. ptr_hdr = ptr_hdr + frame_size;
  2194. /* update LLC */
  2195. *ptr_hdr = LLC_SNAP_LSAP;
  2196. *(ptr_hdr + 1) = LLC_SNAP_LSAP;
  2197. *(ptr_hdr + 2) = LLC_UI;
  2198. *(ptr_hdr + 3) = 0x00;
  2199. *(ptr_hdr + 4) = 0x00;
  2200. *(ptr_hdr + 5) = 0x00;
  2201. *(ptr_hdr + 6) = (eth_type & 0xFF00) >> 8;
  2202. *(ptr_hdr + 7) = (eth_type & 0xFF);
  2203. }
  2204. qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) - mpdu_buf_len);
  2205. return 0;
  2206. }
  2207. static QDF_STATUS dp_tx_add_amsdu_llc_hdr(qdf_nbuf_t nbuf, bool is_last_msdu)
  2208. {
  2209. qdf_ether_header_t *eh = NULL;
  2210. struct llc_snap_hdr_t *llchdr = NULL;
  2211. uint8_t *p_len = NULL;
  2212. uint16_t eth_type;
  2213. uint16_t nbuf_len = qdf_nbuf_len(nbuf);
  2214. /*
  2215. * Steps-
  2216. * 1.nbuf->data is pointing to beginning of ethernet header.
  2217. * 2.push is done to create space for LLC header
  2218. * 3.Move 14 bytes (size of ether_header_t) to nbuf->data
  2219. * 4.update AMSDU subframe length
  2220. * 5.populate LLC and add padding if needed
  2221. *
  2222. * AMSDU format: DA | SA | LEN | LLC_SNAP | TYPE | PAYLOAD
  2223. */
  2224. eh = (qdf_ether_header_t *)qdf_nbuf_data(nbuf);
  2225. eth_type = qdf_htons(eh->ether_type);
  2226. /* increase data area to include LLC header */
  2227. if (qdf_unlikely(qdf_nbuf_headroom(nbuf) < LLC_SNAP_HDR_LEN)) {
  2228. dp_tx_capture_alert("No Head room to push %zu bytes, avail:%d\n",
  2229. LLC_SNAP_HDR_LEN,
  2230. qdf_nbuf_headroom(nbuf));
  2231. return QDF_STATUS_E_NOMEM;
  2232. }
  2233. qdf_nbuf_push_head(nbuf, LLC_SNAP_HDR_LEN);
  2234. /* AMSDU subframe header */
  2235. qdf_mem_move(qdf_nbuf_data(nbuf), eh, sizeof(qdf_ether_header_t));
  2236. p_len = qdf_nbuf_data(nbuf) + (2 * QDF_NET_ETH_LEN);
  2237. /*
  2238. * update AMSDU length field with size up to LLC not including the
  2239. * subframe header
  2240. */
  2241. nbuf_len -= sizeof(qdf_ether_header_t);
  2242. nbuf_len += LLC_SNAP_HDR_LEN;
  2243. p_len[0] = (nbuf_len >> 8);
  2244. p_len[1] = (nbuf_len & 0xFF);
  2245. /* LLC header */
  2246. llchdr = (struct llc_snap_hdr_t *)(qdf_nbuf_data(nbuf) +
  2247. sizeof(qdf_ether_header_t));
  2248. llchdr->dsap = LLC_SNAP_LSAP;
  2249. llchdr->ssap = LLC_SNAP_LSAP;
  2250. llchdr->cntl = LLC_UI;
  2251. qdf_mem_set(llchdr->org_code, 3, 0);
  2252. llchdr->ethertype[0] = (eth_type & 0xFF00) >> 8;
  2253. llchdr->ethertype[1] = (eth_type & 0xFF);
  2254. /* add padding to end of A-MSDU except the last one (Spec requirement)*/
  2255. if (!is_last_msdu) {
  2256. nbuf_len = qdf_nbuf_len(nbuf);
  2257. if (nbuf_len & 0x3)
  2258. qdf_nbuf_put_tail(nbuf, 4 - (nbuf_len & 3));
  2259. }
  2260. return QDF_STATUS_SUCCESS;
  2261. }
  2262. /**
  2263. * dp_tx_mon_restitch_mpdu(): Function to restitch msdu to mpdu
  2264. * @pdev: dp_pdev
  2265. * @peer: dp_peer
  2266. * @head_msdu: head msdu queue
  2267. *
  2268. * return: status
  2269. */
  2270. static uint32_t
  2271. dp_tx_mon_restitch_mpdu(struct dp_pdev *pdev, struct dp_peer *peer,
  2272. struct cdp_tx_completion_ppdu *ppdu_desc,
  2273. qdf_nbuf_queue_t *head_msdu,
  2274. qdf_nbuf_queue_t *mpdu_q, uint8_t usr_idx)
  2275. {
  2276. qdf_nbuf_t curr_nbuf = NULL;
  2277. qdf_nbuf_t first_nbuf = NULL;
  2278. qdf_nbuf_t prev_nbuf = NULL;
  2279. qdf_nbuf_t mpdu_nbuf = NULL;
  2280. struct msdu_completion_info *ptr_msdu_info = NULL;
  2281. uint8_t first_msdu = 0;
  2282. uint8_t last_msdu = 0;
  2283. uint32_t frag_list_sum_len = 0;
  2284. uint8_t first_msdu_not_seen = 1;
  2285. uint16_t ether_type = 0;
  2286. qdf_ether_header_t *eh = NULL;
  2287. size_t msdu_comp_info_sz;
  2288. size_t ether_hdr_sz;
  2289. bool is_amsdu = 0;
  2290. if (qdf_nbuf_is_queue_empty(head_msdu))
  2291. return 0;
  2292. curr_nbuf = qdf_nbuf_queue_remove(head_msdu);
  2293. while (curr_nbuf) {
  2294. ptr_msdu_info =
  2295. (struct msdu_completion_info *)qdf_nbuf_data(curr_nbuf);
  2296. first_msdu = ptr_msdu_info->first_msdu;
  2297. last_msdu = ptr_msdu_info->last_msdu;
  2298. is_amsdu = ptr_msdu_info->msdu_part_of_amsdu;
  2299. eh = (qdf_ether_header_t *)(curr_nbuf->data +
  2300. sizeof(struct msdu_completion_info));
  2301. ether_type = eh->ether_type;
  2302. msdu_comp_info_sz = sizeof(struct msdu_completion_info);
  2303. /* pull msdu_completion_info added in pre header */
  2304. if (NULL == qdf_nbuf_pull_head(curr_nbuf, msdu_comp_info_sz)) {
  2305. dp_tx_capture_alert(" No Head space to pull !!\n");
  2306. qdf_assert_always(0);
  2307. }
  2308. if ((qdf_likely((peer->vdev->tx_encap_type !=
  2309. htt_cmn_pkt_type_raw))) &&
  2310. (((ppdu_desc->frame_ctrl >> IEEE80211_FC1_SHIFT) &
  2311. IEEE80211_FC1_DIR_MASK) ==
  2312. (IEEE80211_FC1_DIR_TODS | IEEE80211_FC1_DIR_FROMDS)))
  2313. dp_peer_tx_wds_addr_add(peer, eh->ether_shost);
  2314. if (first_msdu && first_msdu_not_seen) {
  2315. first_nbuf = curr_nbuf;
  2316. frag_list_sum_len = 0;
  2317. first_msdu_not_seen = 0;
  2318. if (!is_amsdu) {
  2319. ether_hdr_sz = sizeof(qdf_ether_header_t);
  2320. /* pull ethernet header from first MSDU alone */
  2321. if (NULL == qdf_nbuf_pull_head(curr_nbuf,
  2322. ether_hdr_sz)) {
  2323. dp_tx_capture_alert(" No Head space to pull !!\n");
  2324. qdf_assert_always(0);
  2325. }
  2326. }
  2327. /* update first buffer to previous buffer */
  2328. prev_nbuf = curr_nbuf;
  2329. } else if (first_msdu && !first_msdu_not_seen) {
  2330. dp_tx_capture_err("!!!!! NO LAST MSDU\n");
  2331. /*
  2332. * no last msdu in a mpdu
  2333. * handle this case
  2334. */
  2335. qdf_nbuf_free(curr_nbuf);
  2336. /*
  2337. * No last msdu found because WBM comes out
  2338. * of order, free the pkt
  2339. */
  2340. goto free_ppdu_desc_mpdu_q;
  2341. } else if (!first_msdu && first_msdu_not_seen) {
  2342. dp_tx_capture_err("!!!!! NO FIRST MSDU\n");
  2343. /*
  2344. * no first msdu in a mpdu
  2345. * handle this case
  2346. */
  2347. qdf_nbuf_free(curr_nbuf);
  2348. /*
  2349. * no first msdu found beacuse WBM comes out
  2350. * of order, free the pkt
  2351. */
  2352. goto free_ppdu_desc_mpdu_q;
  2353. } else {
  2354. /* update current buffer to previous buffer next */
  2355. prev_nbuf->next = curr_nbuf;
  2356. /* move the previous buffer to next buffer */
  2357. prev_nbuf = prev_nbuf->next;
  2358. }
  2359. if (is_amsdu) {
  2360. if (dp_tx_add_amsdu_llc_hdr(curr_nbuf,
  2361. last_msdu ? 1 : 0) !=
  2362. QDF_STATUS_SUCCESS)
  2363. goto free_ppdu_desc_mpdu_q;
  2364. }
  2365. frag_list_sum_len += qdf_nbuf_len(curr_nbuf);
  2366. if (last_msdu) {
  2367. mpdu_nbuf = qdf_nbuf_alloc(pdev->soc->osdev,
  2368. MAX_MONITOR_HEADER,
  2369. MAX_MONITOR_HEADER,
  2370. 4, FALSE);
  2371. if (!mpdu_nbuf) {
  2372. dp_tx_capture_err("MPDU head allocation failed !!!");
  2373. goto free_ppdu_desc_mpdu_q;
  2374. }
  2375. if (((ppdu_desc->frame_ctrl >> IEEE80211_FC1_SHIFT) &
  2376. IEEE80211_FC1_DIR_MASK) ==
  2377. (IEEE80211_FC1_DIR_TODS |
  2378. IEEE80211_FC1_DIR_FROMDS)) {
  2379. dp_tx_update_80211_wds_hdr(pdev, peer,
  2380. ppdu_desc, mpdu_nbuf,
  2381. ether_type,
  2382. eh->ether_dhost,
  2383. usr_idx,
  2384. is_amsdu);
  2385. } else {
  2386. dp_tx_update_80211_hdr(pdev, peer,
  2387. ppdu_desc, mpdu_nbuf,
  2388. ether_type,
  2389. eh->ether_shost,
  2390. usr_idx,
  2391. is_amsdu);
  2392. }
  2393. /*
  2394. * first nbuf will hold list of msdu
  2395. * stored in prev_nbuf
  2396. */
  2397. qdf_nbuf_append_ext_list(mpdu_nbuf,
  2398. first_nbuf,
  2399. frag_list_sum_len);
  2400. /* add mpdu to mpdu queue */
  2401. qdf_nbuf_queue_add(mpdu_q, mpdu_nbuf);
  2402. first_nbuf = NULL;
  2403. mpdu_nbuf = NULL;
  2404. /* next msdu will start with first msdu */
  2405. first_msdu_not_seen = 1;
  2406. goto check_for_next_msdu;
  2407. }
  2408. /* get next msdu from the head_msdu */
  2409. curr_nbuf = qdf_nbuf_queue_remove(head_msdu);
  2410. if (!curr_nbuf) {
  2411. /* msdu missed in list */
  2412. dp_tx_capture_err("!!!! WAITING for msdu but list empty !!!!");
  2413. /* for incomplete list, free up the queue */
  2414. goto free_ppdu_desc_mpdu_q;
  2415. }
  2416. continue;
  2417. check_for_next_msdu:
  2418. if (qdf_nbuf_is_queue_empty(head_msdu))
  2419. return 0;
  2420. curr_nbuf = qdf_nbuf_queue_remove(head_msdu);
  2421. }
  2422. return 0;
  2423. free_ppdu_desc_mpdu_q:
  2424. /* free already chained msdu pkt */
  2425. while (first_nbuf) {
  2426. curr_nbuf = first_nbuf;
  2427. first_nbuf = first_nbuf->next;
  2428. qdf_nbuf_free(curr_nbuf);
  2429. }
  2430. /* free allocated mpdu hdr */
  2431. if (mpdu_nbuf)
  2432. qdf_nbuf_free(mpdu_nbuf);
  2433. /* free queued remaining msdu pkt per ppdu */
  2434. TX_CAP_NBUF_QUEUE_FREE(head_msdu);
  2435. /* free queued mpdu per ppdu */
  2436. TX_CAP_NBUF_QUEUE_FREE(mpdu_q);
  2437. return 0;
  2438. }
  2439. /**
  2440. * dp_tx_msdu_dequeue(): Function to dequeue msdu from peer based tid
  2441. * @peer: dp_peer
  2442. * @ppdu_id: ppdu_id
  2443. * @tid: tid
  2444. * @num_msdu: number of msdu
  2445. * @head: head queue
  2446. * @start_tsf: start tsf from ppdu_desc
  2447. * @end_tsf: end tsf from ppdu_desc
  2448. *
  2449. * return: status
  2450. */
  2451. static
  2452. uint32_t dp_tx_msdu_dequeue(struct dp_peer *peer, uint32_t ppdu_id,
  2453. uint16_t tid, uint32_t num_msdu,
  2454. qdf_nbuf_queue_t *head,
  2455. qdf_nbuf_queue_t *head_xretries,
  2456. uint32_t start_tsf, uint32_t end_tsf)
  2457. {
  2458. struct dp_tx_tid *tx_tid = NULL;
  2459. uint32_t msdu_ppdu_id;
  2460. qdf_nbuf_t curr_msdu = NULL;
  2461. struct msdu_completion_info *ptr_msdu_info = NULL;
  2462. uint32_t wbm_tsf;
  2463. uint32_t matched = 0;
  2464. if (qdf_unlikely(!peer))
  2465. return 0;
  2466. /* Non-QOS frames are being indicated with TID 0
  2467. * in WBM completion path, an hence we should
  2468. * TID 0 to reap MSDUs from completion path
  2469. */
  2470. if (qdf_unlikely(tid == DP_NON_QOS_TID))
  2471. tid = 0;
  2472. tx_tid = &peer->tx_capture.tx_tid[tid];
  2473. if (qdf_unlikely(!tx_tid))
  2474. return 0;
  2475. /* lock here */
  2476. qdf_spin_lock_bh(&tx_tid->tasklet_tid_lock);
  2477. qdf_nbuf_queue_append(&tx_tid->defer_msdu_q, &tx_tid->msdu_comp_q);
  2478. qdf_nbuf_queue_init(&tx_tid->msdu_comp_q);
  2479. /* unlock here */
  2480. qdf_spin_unlock_bh(&tx_tid->tasklet_tid_lock);
  2481. /* lock here */
  2482. qdf_spin_lock_bh(&tx_tid->tid_lock);
  2483. if (qdf_nbuf_is_queue_empty(&tx_tid->defer_msdu_q)) {
  2484. /* release lock here */
  2485. qdf_spin_unlock_bh(&tx_tid->tid_lock);
  2486. return 0;
  2487. }
  2488. curr_msdu = qdf_nbuf_queue_first(&tx_tid->defer_msdu_q);
  2489. while (curr_msdu) {
  2490. if (qdf_nbuf_queue_len(head) == num_msdu) {
  2491. matched = 1;
  2492. break;
  2493. }
  2494. ptr_msdu_info =
  2495. (struct msdu_completion_info *)qdf_nbuf_data(curr_msdu);
  2496. msdu_ppdu_id = ptr_msdu_info->ppdu_id;
  2497. wbm_tsf = ptr_msdu_info->tsf;
  2498. if ((ptr_msdu_info->status == HAL_TX_TQM_RR_REM_CMD_TX) ||
  2499. (ptr_msdu_info->status == HAL_TX_TQM_RR_REM_CMD_AGED)) {
  2500. /* Frames removed due to excessive retries */
  2501. qdf_nbuf_queue_remove(&tx_tid->defer_msdu_q);
  2502. qdf_nbuf_queue_add(head_xretries, curr_msdu);
  2503. dp_tx_cap_stats_msdu_update(peer, PEER_MSDU_XRETRY, 1);
  2504. curr_msdu = qdf_nbuf_queue_first(
  2505. &tx_tid->defer_msdu_q);
  2506. continue;
  2507. }
  2508. if (wbm_tsf > end_tsf) {
  2509. /* PPDU being matched is older than MSDU at head of
  2510. * completion queue. Return matched=1 to skip PPDU
  2511. */
  2512. matched = 1;
  2513. break;
  2514. }
  2515. if (wbm_tsf && (wbm_tsf < start_tsf)) {
  2516. /* remove the aged packet */
  2517. qdf_nbuf_queue_remove(&tx_tid->defer_msdu_q);
  2518. qdf_nbuf_free(curr_msdu);
  2519. dp_tx_cap_stats_msdu_update(peer, PEER_MSDU_DROP, 1);
  2520. curr_msdu = qdf_nbuf_queue_first(
  2521. &tx_tid->defer_msdu_q);
  2522. continue;
  2523. }
  2524. if (msdu_ppdu_id == ppdu_id) {
  2525. /* remove head */
  2526. qdf_nbuf_queue_remove(&tx_tid->defer_msdu_q);
  2527. /* add msdu to head queue */
  2528. qdf_nbuf_queue_add(head, curr_msdu);
  2529. dp_tx_cap_stats_msdu_update(peer, PEER_MSDU_DEQ,
  2530. 1);
  2531. /* get next msdu from defer_msdu_q */
  2532. curr_msdu = qdf_nbuf_queue_first(&tx_tid->defer_msdu_q);
  2533. continue;
  2534. } else {
  2535. /*
  2536. * at this point wbm_tsf is inbetween start_tsf and
  2537. * end tsf but there is a mismatch in ppdu_id
  2538. */
  2539. break;
  2540. }
  2541. }
  2542. /* store last dequeue time in msec */
  2543. tx_tid->last_deq_ms = qdf_system_ticks_to_msecs(qdf_system_ticks());
  2544. /* release lock here */
  2545. qdf_spin_unlock_bh(&tx_tid->tid_lock);
  2546. return matched;
  2547. }
  2548. /**
  2549. * dp_tx_cap_nbuf_list_get_ref() - get nbuf_list reference
  2550. * @ptr_nbuf_list: dp_tx_cap_nbuf_list list
  2551. *
  2552. * Return: reference count
  2553. */
  2554. static inline uint8_t
  2555. dp_tx_cap_nbuf_list_get_ref(struct dp_tx_cap_nbuf_list *ptr_nbuf_list)
  2556. {
  2557. return ptr_nbuf_list->ref_cnt;
  2558. }
  2559. /**
  2560. * dp_tx_cap_nbuf_list_dec_ref() - dec nbuf_list reference
  2561. * @ptr_nbuf_list: dp_tx_cap_nbuf_list list
  2562. *
  2563. * Return: none
  2564. */
  2565. static inline
  2566. void dp_tx_cap_nbuf_list_dec_ref(struct dp_tx_cap_nbuf_list *ptr_nbuf_list)
  2567. {
  2568. ptr_nbuf_list->ref_cnt--;
  2569. if (!ptr_nbuf_list->ref_cnt)
  2570. ptr_nbuf_list->nbuf_ppdu = NULL;
  2571. }
  2572. /**
  2573. * dp_tx_cap_nbuf_list_inc_ref() - inc nbuf_list reference
  2574. * @ptr_nbuf_list: dp_tx_cap_nbuf_list list
  2575. *
  2576. * Return: none
  2577. */
  2578. static inline
  2579. void dp_tx_cap_nbuf_list_inc_ref(struct dp_tx_cap_nbuf_list *ptr_nbuf_list)
  2580. {
  2581. ptr_nbuf_list->ref_cnt++;
  2582. }
  2583. /**
  2584. * dp_tx_cap_nbuf_list_update_ref() - update nbuf_list reference
  2585. * @ptr_nbuf_list: dp_tx_cap_nbuf_list list
  2586. * @ref_cnt: reference count
  2587. *
  2588. * Return: none
  2589. */
  2590. static inline void
  2591. dp_tx_cap_nbuf_list_update_ref(struct dp_tx_cap_nbuf_list *ptr_nbuf_list,
  2592. uint8_t ref_cnt)
  2593. {
  2594. ptr_nbuf_list->ref_cnt = ref_cnt;
  2595. }
  2596. /**
  2597. * get_mpdu_clone_from_next_ppdu(): Function to clone missing mpdu from
  2598. * next ppdu
  2599. * @nbuf_ppdu_list: nbuf list
  2600. * @ppdu_desc_cnt: ppdu_desc_cnt
  2601. * @missed_seq_no:
  2602. * @ppdu_id: ppdu_id
  2603. * @mpdu_info: cdp_tx_indication_mpdu_info
  2604. *
  2605. * return: void
  2606. */
  2607. static qdf_nbuf_t
  2608. get_mpdu_clone_from_next_ppdu(struct dp_tx_cap_nbuf_list nbuf_list[],
  2609. uint32_t ppdu_desc_cnt,
  2610. uint16_t missed_seq_no,
  2611. uint16_t peer_id, uint32_t ppdu_id,
  2612. uint8_t usr_idx)
  2613. {
  2614. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  2615. struct cdp_tx_completion_ppdu_user *user;
  2616. qdf_nbuf_t mpdu = NULL;
  2617. struct dp_tx_cap_nbuf_list *ptr_nbuf_list;
  2618. qdf_nbuf_t nbuf_ppdu;
  2619. uint32_t i = 0;
  2620. uint32_t found = 0;
  2621. uint32_t seq_no = 0;
  2622. uint32_t mpdu_q_len;
  2623. for (i = 1; i < ppdu_desc_cnt; i++) {
  2624. ptr_nbuf_list = &nbuf_list[i];
  2625. nbuf_ppdu = ptr_nbuf_list->nbuf_ppdu;
  2626. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  2627. qdf_nbuf_data(nbuf_ppdu);
  2628. user = &ppdu_desc->user[usr_idx];
  2629. if (user->skip == 1)
  2630. continue;
  2631. /* check if seq number is between the range */
  2632. if ((peer_id == user->peer_id) &&
  2633. ((missed_seq_no >= user->start_seq) &&
  2634. (missed_seq_no <= user->last_enq_seq))) {
  2635. seq_no = user->start_seq;
  2636. if (SEQ_BIT(user->failed_bitmap,
  2637. (missed_seq_no - seq_no))) {
  2638. found = 1;
  2639. break;
  2640. }
  2641. }
  2642. }
  2643. if (found == 0) {
  2644. /* mpdu not found in sched cmd id */
  2645. dp_tx_capture_debug("peer_id[%d] missed seq_no[%d] ppdu_id[%d] [%d] not found!!!",
  2646. peer_id,
  2647. missed_seq_no, ppdu_id, ppdu_desc_cnt);
  2648. return NULL;
  2649. }
  2650. dp_tx_capture_debug("peer_id[%d] seq_no[%d] missed ppdu_id[%d] m[%d] found in ppdu_id[%d]!!",
  2651. peer_id,
  2652. missed_seq_no, ppdu_id,
  2653. (missed_seq_no - seq_no), ppdu_desc->ppdu_id);
  2654. mpdu = qdf_nbuf_queue_first(&ppdu_desc->user[usr_idx].mpdu_q);
  2655. mpdu_q_len = qdf_nbuf_queue_len(&ppdu_desc->user[usr_idx].mpdu_q);
  2656. if (!mpdu) {
  2657. /* bitmap shows it found sequence number, but
  2658. * MPDU not found in PPDU
  2659. */
  2660. dp_tx_capture_err("missed seq_no[%d] ppdu_id[%d] [%d] found but queue empty!!!",
  2661. missed_seq_no, ppdu_id, ppdu_desc_cnt);
  2662. if (mpdu_q_len)
  2663. qdf_assert_always(0);
  2664. return NULL;
  2665. }
  2666. for (i = 0; i < (missed_seq_no - seq_no); i++) {
  2667. mpdu = mpdu->next;
  2668. if (!mpdu) {
  2669. /*
  2670. * bitmap shows it found sequence number,
  2671. * but queue empty, do we need to allocate
  2672. * skb and send instead of NULL ?
  2673. * add counter here:
  2674. */
  2675. return NULL;
  2676. }
  2677. }
  2678. if (!mpdu)
  2679. return NULL;
  2680. return qdf_nbuf_copy_expand_fraglist(mpdu, MAX_MONITOR_HEADER, 0);
  2681. }
  2682. /**
  2683. * dp_tx_update_user_mpdu_info(): Function to update mpdu info
  2684. * from ppdu_desc
  2685. * @ppdu_id: ppdu_id
  2686. * @mpdu_info: cdp_tx_indication_mpdu_info
  2687. * @user: cdp_tx_completion_ppdu_user
  2688. *
  2689. * return: void
  2690. */
  2691. static void
  2692. dp_tx_update_user_mpdu_info(uint32_t ppdu_id,
  2693. struct cdp_tx_indication_mpdu_info *mpdu_info,
  2694. struct cdp_tx_completion_ppdu_user *user)
  2695. {
  2696. mpdu_info->ppdu_id = ppdu_id;
  2697. mpdu_info->frame_ctrl = user->frame_ctrl;
  2698. mpdu_info->qos_ctrl = user->qos_ctrl;
  2699. mpdu_info->tid = user->tid;
  2700. mpdu_info->ltf_size = user->ltf_size;
  2701. mpdu_info->he_re = user->he_re;
  2702. mpdu_info->txbf = user->txbf;
  2703. mpdu_info->bw = user->bw;
  2704. mpdu_info->nss = user->nss;
  2705. mpdu_info->mcs = user->mcs;
  2706. mpdu_info->preamble = user->preamble;
  2707. mpdu_info->gi = user->gi;
  2708. mpdu_info->ack_rssi = user->ack_rssi[0];
  2709. mpdu_info->tx_rate = user->tx_rate;
  2710. mpdu_info->ldpc = user->ldpc;
  2711. mpdu_info->ppdu_cookie = user->ppdu_cookie;
  2712. mpdu_info->long_retries = user->long_retries;
  2713. mpdu_info->short_retries = user->short_retries;
  2714. mpdu_info->completion_status = user->completion_status;
  2715. qdf_mem_copy(mpdu_info->mac_address, user->mac_addr, 6);
  2716. mpdu_info->ba_start_seq = user->ba_seq_no;
  2717. qdf_mem_copy(mpdu_info->ba_bitmap, user->ba_bitmap,
  2718. CDP_BA_256_BIT_MAP_SIZE_DWORDS * sizeof(uint32_t));
  2719. }
  2720. static inline
  2721. void dp_tx_update_sequence_number(qdf_nbuf_t nbuf, uint32_t seq_no)
  2722. {
  2723. struct ieee80211_frame *ptr_wh = NULL;
  2724. uint16_t wh_seq = 0;
  2725. if (!nbuf)
  2726. return;
  2727. /* update sequence number in frame header */
  2728. ptr_wh = (struct ieee80211_frame *)qdf_nbuf_data(nbuf);
  2729. wh_seq = (seq_no & 0xFFF) << 4;
  2730. qdf_mem_copy(ptr_wh->i_seq, &wh_seq, sizeof(uint16_t));
  2731. }
  2732. static inline
  2733. void dp_update_frame_ctrl_from_frame_type(void *desc)
  2734. {
  2735. struct cdp_tx_completion_ppdu *ppdu_desc = desc;
  2736. /* frame control is not set properly, sometimes it is zero */
  2737. switch (ppdu_desc->htt_frame_type) {
  2738. case HTT_STATS_FTYPE_SGEN_NDPA:
  2739. case HTT_STATS_FTYPE_SGEN_NDP:
  2740. case HTT_STATS_FTYPE_SGEN_AX_NDPA:
  2741. case HTT_STATS_FTYPE_SGEN_AX_NDP:
  2742. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_NDPA |
  2743. IEEE80211_FC0_TYPE_CTL);
  2744. break;
  2745. case HTT_STATS_FTYPE_SGEN_BRP:
  2746. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_BRPOLL |
  2747. IEEE80211_FC0_TYPE_CTL);
  2748. break;
  2749. case HTT_STATS_FTYPE_SGEN_RTS:
  2750. case HTT_STATS_FTYPE_SGEN_MU_RTS:
  2751. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_RTS |
  2752. IEEE80211_FC0_TYPE_CTL);
  2753. break;
  2754. case HTT_STATS_FTYPE_SGEN_CTS:
  2755. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_CTS |
  2756. IEEE80211_FC0_TYPE_CTL);
  2757. break;
  2758. case HTT_STATS_FTYPE_SGEN_CFEND:
  2759. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_CF_END |
  2760. IEEE80211_FC0_TYPE_CTL);
  2761. break;
  2762. case HTT_STATS_FTYPE_SGEN_MU_TRIG:
  2763. case HTT_STATS_FTYPE_SGEN_MU_BAR:
  2764. case HTT_STATS_FTYPE_SGEN_MU_BRP:
  2765. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_TRIGGER |
  2766. IEEE80211_FC0_TYPE_CTL);
  2767. break;
  2768. case HTT_STATS_FTYPE_SGEN_BAR:
  2769. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_BAR |
  2770. IEEE80211_FC0_TYPE_CTL);
  2771. break;
  2772. }
  2773. }
  2774. /**
  2775. * dp_send_dummy_mpdu_info_to_stack(): send dummy payload to stack
  2776. * to upper layer if complete
  2777. * @pdev: DP pdev handle
  2778. * @desc: cdp tx completion ppdu desc
  2779. * @usr_idx: user index
  2780. *
  2781. * return: status
  2782. */
  2783. static inline
  2784. QDF_STATUS dp_send_dummy_mpdu_info_to_stack(struct dp_pdev *pdev,
  2785. void *desc, uint8_t usr_idx)
  2786. {
  2787. struct cdp_tx_completion_ppdu *ppdu_desc = desc;
  2788. struct cdp_tx_completion_ppdu_user *user = &ppdu_desc->user[usr_idx];
  2789. struct ieee80211_ctlframe_addr2 *wh_min;
  2790. uint16_t frame_ctrl_le, duration_le;
  2791. struct cdp_tx_indication_info tx_capture_info;
  2792. struct cdp_tx_indication_mpdu_info *mpdu_info;
  2793. uint8_t type, subtype;
  2794. qdf_mem_set(&tx_capture_info,
  2795. sizeof(struct cdp_tx_indication_info),
  2796. 0);
  2797. tx_capture_info.mpdu_nbuf =
  2798. qdf_nbuf_alloc(pdev->soc->osdev,
  2799. MAX_MONITOR_HEADER + MAX_DUMMY_FRM_BODY,
  2800. MAX_MONITOR_HEADER,
  2801. 4, FALSE);
  2802. if (!tx_capture_info.mpdu_nbuf)
  2803. return QDF_STATUS_E_ABORTED;
  2804. mpdu_info = &tx_capture_info.mpdu_info;
  2805. mpdu_info->resp_type = ppdu_desc->resp_type;
  2806. mpdu_info->mprot_type = ppdu_desc->mprot_type;
  2807. mpdu_info->rts_success = ppdu_desc->rts_success;
  2808. mpdu_info->rts_failure = ppdu_desc->rts_failure;
  2809. /* update cdp_tx_indication_mpdu_info */
  2810. dp_tx_update_user_mpdu_info(ppdu_desc->bar_ppdu_id,
  2811. &tx_capture_info.mpdu_info,
  2812. user);
  2813. tx_capture_info.ppdu_desc = ppdu_desc;
  2814. mpdu_info->ppdu_id = ppdu_desc->ppdu_id;
  2815. mpdu_info->channel_num = pdev->operating_channel.num;
  2816. mpdu_info->channel = ppdu_desc->channel;
  2817. mpdu_info->frame_type = ppdu_desc->frame_type;
  2818. mpdu_info->ppdu_start_timestamp = ppdu_desc->ppdu_start_timestamp;
  2819. mpdu_info->ppdu_end_timestamp = ppdu_desc->ppdu_end_timestamp;
  2820. mpdu_info->tx_duration = ppdu_desc->tx_duration;
  2821. mpdu_info->seq_no = user->start_seq;
  2822. qdf_mem_copy(mpdu_info->mac_address, user->mac_addr, QDF_MAC_ADDR_SIZE);
  2823. mpdu_info->ba_start_seq = user->ba_seq_no;
  2824. qdf_mem_copy(mpdu_info->ba_bitmap, user->ba_bitmap,
  2825. CDP_BA_256_BIT_MAP_SIZE_DWORDS * sizeof(uint32_t));
  2826. mpdu_info->frame_ctrl = ppdu_desc->frame_ctrl;
  2827. type = (ppdu_desc->frame_ctrl & IEEE80211_FC0_TYPE_MASK);
  2828. subtype = (ppdu_desc->frame_ctrl & IEEE80211_FC0_SUBTYPE_MASK);
  2829. if (type == IEEE80211_FC0_TYPE_CTL &&
  2830. subtype == IEEE80211_FC0_SUBTYPE_BAR) {
  2831. mpdu_info->frame_ctrl = (IEEE80211_FC0_SUBTYPE_BAR |
  2832. IEEE80211_FC0_TYPE_CTL);
  2833. mpdu_info->ppdu_id = ppdu_desc->bar_ppdu_id;
  2834. mpdu_info->ppdu_start_timestamp =
  2835. ppdu_desc->bar_ppdu_start_timestamp;
  2836. mpdu_info->ppdu_end_timestamp =
  2837. ppdu_desc->bar_ppdu_end_timestamp;
  2838. mpdu_info->tx_duration = ppdu_desc->bar_tx_duration;
  2839. }
  2840. wh_min = (struct ieee80211_ctlframe_addr2 *)
  2841. qdf_nbuf_data(
  2842. tx_capture_info.mpdu_nbuf);
  2843. qdf_mem_zero(wh_min, MAX_DUMMY_FRM_BODY);
  2844. frame_ctrl_le =
  2845. qdf_cpu_to_le16(mpdu_info->frame_ctrl);
  2846. duration_le =
  2847. qdf_cpu_to_le16(mpdu_info->tx_duration);
  2848. wh_min->i_fc[1] = (frame_ctrl_le & 0xFF00) >> 8;
  2849. wh_min->i_fc[0] = (frame_ctrl_le & 0xFF);
  2850. wh_min->i_aidordur[1] = (duration_le & 0xFF00) >> 8;
  2851. wh_min->i_aidordur[0] = (duration_le & 0xFF);
  2852. qdf_mem_copy(wh_min->i_addr1,
  2853. mpdu_info->mac_address,
  2854. QDF_MAC_ADDR_SIZE);
  2855. if (subtype == IEEE80211_FC0_SUBTYPE_ACK)
  2856. qdf_nbuf_set_pktlen(tx_capture_info.mpdu_nbuf,
  2857. sizeof(struct ieee80211_frame_min_one));
  2858. else {
  2859. struct dp_peer *peer;
  2860. struct dp_vdev *vdev = NULL;
  2861. peer = DP_TX_PEER_GET_REF(pdev, user->peer_id);
  2862. if (peer) {
  2863. vdev = peer->vdev;
  2864. if (vdev)
  2865. qdf_mem_copy(wh_min->i_addr2,
  2866. vdev->mac_addr.raw,
  2867. QDF_MAC_ADDR_SIZE);
  2868. DP_TX_PEER_DEL_REF(peer);
  2869. } else {
  2870. vdev =
  2871. dp_vdev_get_ref_by_id(pdev->soc, ppdu_desc->vdev_id,
  2872. DP_MOD_ID_TX_CAPTURE);
  2873. if (vdev) {
  2874. qdf_mem_copy(wh_min->i_addr2,
  2875. vdev->mac_addr.raw,
  2876. QDF_MAC_ADDR_SIZE);
  2877. dp_vdev_unref_delete(pdev->soc, vdev,
  2878. DP_MOD_ID_TX_CAPTURE);
  2879. }
  2880. }
  2881. qdf_nbuf_set_pktlen(tx_capture_info.mpdu_nbuf, sizeof(*wh_min));
  2882. }
  2883. dp_tx_capture_debug("%pK: HTT_FTYPE[%d] frm(0x%08x): fc %x %x, dur 0x%x%x\n",
  2884. pdev->soc, ppdu_desc->htt_frame_type, mpdu_info->ppdu_id,
  2885. wh_min->i_fc[1], wh_min->i_fc[0],
  2886. wh_min->i_aidordur[1], wh_min->i_aidordur[0]);
  2887. /*
  2888. * send MPDU to osif layer
  2889. */
  2890. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  2891. &tx_capture_info, HTT_INVALID_PEER,
  2892. WDI_NO_VAL, pdev->pdev_id);
  2893. if (tx_capture_info.mpdu_nbuf)
  2894. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  2895. return QDF_STATUS_SUCCESS;
  2896. }
  2897. /**
  2898. * dp_send_dummy_rts_cts_frame(): send dummy rts and cts frame out
  2899. * to upper layer if complete
  2900. * @pdev: DP pdev handle
  2901. * @cur_ppdu_desc: cdp tx completion ppdu desc
  2902. *
  2903. * return: void
  2904. */
  2905. static
  2906. void dp_send_dummy_rts_cts_frame(struct dp_pdev *pdev,
  2907. struct cdp_tx_completion_ppdu *cur_ppdu_desc,
  2908. uint8_t usr_id)
  2909. {
  2910. struct cdp_tx_completion_ppdu *ppdu_desc;
  2911. struct dp_pdev_tx_capture *ptr_tx_cap;
  2912. struct dp_peer *peer;
  2913. uint8_t rts_send;
  2914. struct dp_vdev *vdev = NULL;
  2915. rts_send = 0;
  2916. ptr_tx_cap = &pdev->tx_capture;
  2917. ppdu_desc = ptr_tx_cap->dummy_ppdu_desc;
  2918. ppdu_desc->channel = cur_ppdu_desc->channel;
  2919. ppdu_desc->num_mpdu = 1;
  2920. ppdu_desc->num_msdu = 1;
  2921. ppdu_desc->user[usr_id].ppdu_type = HTT_PPDU_STATS_PPDU_TYPE_SU;
  2922. ppdu_desc->bar_num_users = 0;
  2923. ppdu_desc->num_users = 1;
  2924. if (cur_ppdu_desc->mprot_type == SEND_WIFIRTS_LEGACY_E ||
  2925. cur_ppdu_desc->mprot_type == SEND_WIFIRTS_11AC_DYNAMIC_BW_E ||
  2926. cur_ppdu_desc->mprot_type == SEND_WIFIRTS_11AC_STATIC_BW_E) {
  2927. rts_send = 1;
  2928. /*
  2929. * send dummy RTS frame followed by CTS
  2930. * update frame_ctrl and htt_frame_type
  2931. */
  2932. ppdu_desc->htt_frame_type = HTT_STATS_FTYPE_SGEN_RTS;
  2933. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  2934. ppdu_desc->ppdu_start_timestamp =
  2935. cur_ppdu_desc->ppdu_start_timestamp;
  2936. ppdu_desc->ppdu_end_timestamp =
  2937. cur_ppdu_desc->ppdu_end_timestamp;
  2938. ppdu_desc->tx_duration = cur_ppdu_desc->tx_duration;
  2939. ppdu_desc->user[usr_id].peer_id =
  2940. cur_ppdu_desc->user[usr_id].peer_id;
  2941. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_RTS |
  2942. IEEE80211_FC0_TYPE_CTL);
  2943. qdf_mem_copy(&ppdu_desc->user[usr_id].mac_addr,
  2944. &cur_ppdu_desc->user[usr_id].mac_addr,
  2945. QDF_MAC_ADDR_SIZE);
  2946. dp_send_dummy_mpdu_info_to_stack(pdev, ppdu_desc, usr_id);
  2947. }
  2948. if ((rts_send && cur_ppdu_desc->rts_success) ||
  2949. cur_ppdu_desc->mprot_type == SEND_WIFICTS2SELF_E) {
  2950. uint16_t peer_id;
  2951. peer_id = cur_ppdu_desc->user[usr_id].peer_id;
  2952. /* send dummy CTS frame */
  2953. ppdu_desc->htt_frame_type = HTT_STATS_FTYPE_SGEN_CTS;
  2954. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  2955. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_CTS |
  2956. IEEE80211_FC0_TYPE_CTL);
  2957. ppdu_desc->ppdu_start_timestamp =
  2958. cur_ppdu_desc->ppdu_start_timestamp;
  2959. ppdu_desc->ppdu_end_timestamp =
  2960. cur_ppdu_desc->ppdu_end_timestamp;
  2961. ppdu_desc->tx_duration = cur_ppdu_desc->tx_duration -
  2962. (RTS_INTERVAL + SIFS_INTERVAL);
  2963. ppdu_desc->user[usr_id].peer_id = peer_id;
  2964. peer = DP_TX_PEER_GET_REF(pdev, peer_id);
  2965. if (peer) {
  2966. vdev = peer->vdev;
  2967. if (vdev)
  2968. qdf_mem_copy(&ppdu_desc->user[usr_id].mac_addr,
  2969. vdev->mac_addr.raw,
  2970. QDF_MAC_ADDR_SIZE);
  2971. DP_TX_PEER_DEL_REF(peer);
  2972. } else {
  2973. uint8_t vdev_id;
  2974. vdev_id = ppdu_desc->vdev_id;
  2975. vdev = dp_vdev_get_ref_by_id(pdev->soc, vdev_id,
  2976. DP_MOD_ID_TX_CAPTURE);
  2977. if (vdev) {
  2978. qdf_mem_copy(&ppdu_desc->user[usr_id].mac_addr,
  2979. vdev->mac_addr.raw,
  2980. QDF_MAC_ADDR_SIZE);
  2981. dp_vdev_unref_delete(pdev->soc, vdev,
  2982. DP_MOD_ID_TX_CAPTURE);
  2983. }
  2984. }
  2985. dp_send_dummy_mpdu_info_to_stack(pdev, ppdu_desc, usr_id);
  2986. }
  2987. }
  2988. static void dp_gen_ack_rx_frame(struct dp_pdev *pdev,
  2989. struct cdp_tx_indication_info *tx_capture_info)
  2990. {
  2991. struct cdp_tx_completion_ppdu *ppdu_desc;
  2992. struct dp_peer *peer;
  2993. struct dp_pdev_tx_capture *ptr_tx_cap;
  2994. ptr_tx_cap = &pdev->tx_capture;
  2995. ppdu_desc = ptr_tx_cap->dummy_ppdu_desc;
  2996. ppdu_desc->channel = tx_capture_info->ppdu_desc->channel;
  2997. ppdu_desc->num_mpdu = 1;
  2998. ppdu_desc->num_msdu = 1;
  2999. ppdu_desc->user[0].ppdu_type = HTT_PPDU_STATS_PPDU_TYPE_SU;
  3000. ppdu_desc->bar_num_users = 0;
  3001. ppdu_desc->num_users = 1;
  3002. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  3003. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_ACK |
  3004. IEEE80211_FC0_TYPE_CTL);
  3005. ppdu_desc->ppdu_start_timestamp =
  3006. tx_capture_info->ppdu_desc->ppdu_start_timestamp;
  3007. ppdu_desc->ppdu_end_timestamp =
  3008. tx_capture_info->ppdu_desc->ppdu_end_timestamp;
  3009. ppdu_desc->user[0].peer_id =
  3010. tx_capture_info->ppdu_desc->user[0].peer_id;
  3011. peer = DP_TX_PEER_GET_REF(pdev,
  3012. tx_capture_info->ppdu_desc->user[0].peer_id);
  3013. if (peer) {
  3014. struct dp_vdev *vdev = NULL;
  3015. vdev = peer->vdev;
  3016. if (vdev)
  3017. qdf_mem_copy(&ppdu_desc->user[0].mac_addr,
  3018. vdev->mac_addr.raw,
  3019. QDF_MAC_ADDR_SIZE);
  3020. DP_TX_PEER_DEL_REF(peer);
  3021. }
  3022. dp_send_dummy_mpdu_info_to_stack(pdev, ppdu_desc, 0);
  3023. }
  3024. /**
  3025. * dp_send_data_to_stack(): Function to deliver mpdu info to stack
  3026. * to upper layer
  3027. * @pdev: DP pdev handle
  3028. * @nbuf_ppdu_list: ppdu_desc_list per sched cmd id
  3029. * @ppdu_desc_cnt: number of ppdu_desc_cnt
  3030. *
  3031. * return: status
  3032. */
  3033. static
  3034. void dp_send_data_to_stack(struct dp_pdev *pdev,
  3035. struct cdp_tx_completion_ppdu *ppdu_desc,
  3036. uint8_t usr_idx)
  3037. {
  3038. struct cdp_tx_completion_ppdu_user *user = NULL;
  3039. struct cdp_tx_indication_info tx_capture_info;
  3040. struct cdp_tx_indication_mpdu_info *mpdu_info;
  3041. int i;
  3042. uint32_t seq_no, start_seq;
  3043. uint32_t ppdu_id;
  3044. uint32_t mpdu_tried;
  3045. uint32_t mpdu_enq = 0;
  3046. struct dp_peer *peer;
  3047. if (!ppdu_desc)
  3048. return;
  3049. ppdu_id = ppdu_desc->ppdu_id;
  3050. user = &ppdu_desc->user[usr_idx];
  3051. peer = DP_TX_PEER_GET_REF(pdev, user->peer_id);
  3052. if (!peer) {
  3053. return;
  3054. }
  3055. qdf_mem_set(&tx_capture_info,
  3056. sizeof(struct cdp_tx_indication_info),
  3057. 0);
  3058. mpdu_info = &tx_capture_info.mpdu_info;
  3059. mpdu_info->usr_idx = usr_idx;
  3060. mpdu_info->channel = ppdu_desc->channel;
  3061. mpdu_info->frame_type = ppdu_desc->frame_type;
  3062. mpdu_info->ppdu_start_timestamp =
  3063. ppdu_desc->ppdu_start_timestamp;
  3064. mpdu_info->ppdu_end_timestamp =
  3065. ppdu_desc->ppdu_end_timestamp;
  3066. mpdu_info->tx_duration = ppdu_desc->tx_duration;
  3067. mpdu_info->num_msdu = ppdu_desc->num_msdu;
  3068. mpdu_info->resp_type = ppdu_desc->resp_type;
  3069. mpdu_info->mprot_type = ppdu_desc->mprot_type;
  3070. mpdu_info->rts_success = ppdu_desc->rts_success;
  3071. mpdu_info->rts_failure = ppdu_desc->rts_failure;
  3072. /* update cdp_tx_indication_mpdu_info */
  3073. dp_tx_update_user_mpdu_info(ppdu_id,
  3074. &tx_capture_info.mpdu_info,
  3075. user);
  3076. tx_capture_info.ppdu_desc = ppdu_desc;
  3077. tx_capture_info.mpdu_info.channel_num = pdev->operating_channel.num;
  3078. if (ppdu_desc->mprot_type && (usr_idx == 0))
  3079. dp_send_dummy_rts_cts_frame(pdev, ppdu_desc, usr_idx);
  3080. start_seq = user->start_seq;
  3081. if (!user->mpdus)
  3082. goto return_send_to_stack;
  3083. mpdu_tried = user->mpdu_tried_ucast + user->mpdu_tried_mcast;
  3084. for (i = 0; i < CDP_BA_256_BIT_MAP_SIZE_DWORDS; i++)
  3085. mpdu_enq += get_number_of_1s(user->enq_bitmap[i]);
  3086. if (mpdu_tried > mpdu_enq)
  3087. dp_ppdu_desc_debug_print(ppdu_desc, usr_idx,
  3088. __func__, __LINE__);
  3089. for (i = 0; i < user->ba_size && mpdu_tried; i++) {
  3090. if (qdf_likely(user->tid != DP_NON_QOS_TID) &&
  3091. !(SEQ_BIT(user->enq_bitmap, i))) {
  3092. continue;
  3093. }
  3094. mpdu_tried--;
  3095. seq_no = start_seq + i;
  3096. if (!user->mpdus[i])
  3097. continue;
  3098. tx_capture_info.mpdu_nbuf = user->mpdus[i];
  3099. dp_tx_cap_stats_mpdu_update(peer, PEER_MPDU_TO_STACK, 1);
  3100. user->mpdus[i] = NULL;
  3101. mpdu_info->seq_no = seq_no;
  3102. dp_tx_update_sequence_number(tx_capture_info.mpdu_nbuf, seq_no);
  3103. /*
  3104. * send MPDU to osif layer
  3105. * do we need to update mpdu_info before tranmit
  3106. * get current mpdu_nbuf
  3107. */
  3108. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  3109. &tx_capture_info,
  3110. HTT_INVALID_PEER,
  3111. WDI_NO_VAL, pdev->pdev_id);
  3112. if (tx_capture_info.mpdu_nbuf)
  3113. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  3114. }
  3115. if (ppdu_desc->resp_type == HTT_PPDU_STATS_ACK_EXPECTED_E &&
  3116. ppdu_desc->user[usr_idx].completion_status ==
  3117. HTT_PPDU_STATS_USER_STATUS_OK)
  3118. dp_gen_ack_rx_frame(pdev, &tx_capture_info);
  3119. return_send_to_stack:
  3120. DP_TX_PEER_DEL_REF(peer);
  3121. return;
  3122. }
  3123. /**
  3124. * dp_ppdu_desc_free(): Function to free ppdu_desc and stored queue
  3125. * @ptr_nbuf_list: pointer to ptr_nbuf_list
  3126. * @usr_idx: user index
  3127. *
  3128. * return: void
  3129. */
  3130. static void dp_ppdu_desc_free(struct dp_tx_cap_nbuf_list *ptr_nbuf_list,
  3131. uint8_t usr_idx)
  3132. {
  3133. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  3134. qdf_nbuf_t tmp_nbuf;
  3135. if (!ptr_nbuf_list->nbuf_ppdu ||
  3136. !dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list))
  3137. return;
  3138. tmp_nbuf = ptr_nbuf_list->nbuf_ppdu;
  3139. if (tmp_nbuf) {
  3140. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3141. qdf_nbuf_data(tmp_nbuf);
  3142. dp_ppdu_queue_free(tmp_nbuf, usr_idx);
  3143. dp_tx_cap_nbuf_list_dec_ref(ptr_nbuf_list);
  3144. qdf_nbuf_free(tmp_nbuf);
  3145. }
  3146. }
  3147. /**
  3148. * dp_ppdu_desc_free_all(): Function to free all user in a ppdu_desc and
  3149. * its stored queue
  3150. * @ptr_nbuf_list: pointer to ptr_nbuf_list
  3151. * @max_users: maximum number of users
  3152. *
  3153. * return: void
  3154. */
  3155. static void dp_ppdu_desc_free_all(struct dp_tx_cap_nbuf_list *ptr_nbuf_list,
  3156. uint8_t max_users)
  3157. {
  3158. uint8_t i = 0;
  3159. for (i = 0; i < max_users; i++)
  3160. dp_ppdu_desc_free(ptr_nbuf_list, i);
  3161. }
  3162. /**
  3163. * dp_tx_mon_get_next_mpdu(): get next mpdu from retry queue.
  3164. * @tx_tid: tx capture peer tid
  3165. * @xretry_user: pointer to ppdu_desc user.
  3166. * @mpdu_nbuf: mpdu nbuf
  3167. * @ppdu_nbuf: ppdu nbuf from pending ppdu q
  3168. *
  3169. * return: qdf_nbuf_t
  3170. */
  3171. static qdf_nbuf_t
  3172. dp_tx_mon_get_next_mpdu(struct dp_pdev *pdev, struct dp_tx_tid *tx_tid,
  3173. struct cdp_tx_completion_ppdu_user *xretry_user,
  3174. qdf_nbuf_t mpdu_nbuf, qdf_nbuf_t ppdu_nbuf)
  3175. {
  3176. qdf_nbuf_t next_nbuf = NULL;
  3177. qdf_nbuf_queue_t temp_xretries;
  3178. qdf_nbuf_t first_nbuf = NULL;
  3179. qdf_nbuf_t temp_nbuf = NULL;
  3180. if (mpdu_nbuf != qdf_nbuf_queue_first(&xretry_user->mpdu_q)) {
  3181. next_nbuf = qdf_nbuf_queue_next(mpdu_nbuf);
  3182. dp_tx_capture_info("%pK: mpdu %p not head, next %p mpdu_q[%p L %d] ppdu %p",
  3183. pdev->soc, mpdu_nbuf, next_nbuf,
  3184. &xretry_user->mpdu_q,
  3185. qdf_nbuf_queue_len(&xretry_user->mpdu_q), ppdu_nbuf);
  3186. /* Initialize temp list */
  3187. qdf_nbuf_queue_init(&temp_xretries);
  3188. /* Move entries into temp list till the mpdu_nbuf is found */
  3189. first_nbuf = qdf_nbuf_queue_first(&xretry_user->mpdu_q);
  3190. while (first_nbuf && (mpdu_nbuf != first_nbuf)) {
  3191. /* remove nbuf from queue */
  3192. temp_nbuf = qdf_nbuf_queue_remove(&xretry_user->mpdu_q);
  3193. qdf_nbuf_queue_add(&temp_xretries, temp_nbuf);
  3194. /* get first nbuf from queue again */
  3195. first_nbuf = qdf_nbuf_queue_first(&xretry_user->mpdu_q);
  3196. }
  3197. if (first_nbuf && (mpdu_nbuf == first_nbuf)) {
  3198. /* Remove mpdu_nbuf from queue */
  3199. qdf_nbuf_queue_remove(&xretry_user->mpdu_q);
  3200. /* Add remaining nbufs into temp queue */
  3201. qdf_nbuf_queue_append(&temp_xretries,
  3202. &xretry_user->mpdu_q);
  3203. /* Reinit xretry_user->mpdu_q */
  3204. qdf_nbuf_queue_init(&xretry_user->mpdu_q);
  3205. /* append all the entries into original queue */
  3206. qdf_nbuf_queue_append(&xretry_user->mpdu_q,
  3207. &temp_xretries);
  3208. } else {
  3209. dp_tx_capture_alert("%pK: bug scenario, did not find nbuf in queue\npdev %p "
  3210. "peer id %d, tid: %p mpdu_nbuf %p xretry_user %p "
  3211. "mpdu_q %p len %d temp_xretry %p",
  3212. pdev->soc, pdev, tx_tid->peer_id, tx_tid, mpdu_nbuf,
  3213. xretry_user, &xretry_user->mpdu_q,
  3214. qdf_nbuf_queue_len(&xretry_user->mpdu_q),
  3215. &temp_xretries);
  3216. qdf_assert_always(0);
  3217. }
  3218. } else {
  3219. qdf_nbuf_queue_remove(&xretry_user->mpdu_q);
  3220. next_nbuf = qdf_nbuf_queue_first(&xretry_user->mpdu_q);
  3221. }
  3222. return next_nbuf;
  3223. }
  3224. static void
  3225. dp_tx_mon_proc_xretries(struct dp_pdev *pdev, struct dp_peer *peer,
  3226. uint16_t tid)
  3227. {
  3228. struct dp_tx_tid *tx_tid = &peer->tx_capture.tx_tid[tid];
  3229. struct cdp_tx_completion_ppdu *ppdu_desc;
  3230. struct cdp_tx_completion_ppdu *xretry_ppdu;
  3231. struct cdp_tx_completion_ppdu_user *user = NULL;
  3232. struct cdp_tx_completion_ppdu_user *xretry_user = NULL;
  3233. qdf_nbuf_t ppdu_nbuf;
  3234. qdf_nbuf_t mpdu_nbuf;
  3235. uint32_t mpdu_tried = 0;
  3236. int i;
  3237. uint32_t seq_no;
  3238. uint8_t usr_idx = 0;
  3239. xretry_ppdu = tx_tid->xretry_ppdu;
  3240. if (!xretry_ppdu) {
  3241. dp_tx_capture_alert("%pK: xretry_ppdu is NULL",
  3242. pdev->soc);
  3243. return;
  3244. }
  3245. xretry_user = &xretry_ppdu->user[0];
  3246. if (!xretry_user) {
  3247. dp_tx_capture_alert("%pK: xretry_user is NULL",
  3248. pdev->soc);
  3249. return;
  3250. }
  3251. if (qdf_nbuf_is_queue_empty(&tx_tid->pending_ppdu_q)) {
  3252. TX_CAP_NBUF_QUEUE_FREE(&xretry_user->mpdu_q);
  3253. return;
  3254. }
  3255. if (qdf_nbuf_is_queue_empty(&xretry_user->mpdu_q))
  3256. return;
  3257. ppdu_nbuf = qdf_nbuf_queue_first(&tx_tid->pending_ppdu_q);
  3258. while (ppdu_nbuf) {
  3259. struct msdu_completion_info *ptr_msdu_info = NULL;
  3260. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3261. qdf_nbuf_data(ppdu_nbuf);
  3262. usr_idx = dp_tx_find_usr_idx_from_peer_id(ppdu_desc,
  3263. tx_tid->peer_id);
  3264. user = &ppdu_desc->user[usr_idx];
  3265. if (user->pending_retries) {
  3266. uint32_t start_seq = user->start_seq;
  3267. uint32_t index = 0;
  3268. mpdu_tried = user->mpdu_tried_ucast +
  3269. user->mpdu_tried_mcast;
  3270. mpdu_nbuf = qdf_nbuf_queue_first(&xretry_user->mpdu_q);
  3271. for (i = 0;
  3272. (i < user->ba_size) &&
  3273. (mpdu_tried > 0) && mpdu_nbuf;
  3274. i++) {
  3275. if (!(SEQ_BIT(user->enq_bitmap, i)))
  3276. continue;
  3277. mpdu_tried--;
  3278. /* missed seq number */
  3279. seq_no = start_seq + i;
  3280. if (SEQ_BIT(user->failed_bitmap, i))
  3281. continue;
  3282. dp_tx_capture_info("%pK: fill seqno %d from xretries",
  3283. pdev->soc, seq_no);
  3284. ptr_msdu_info = (struct msdu_completion_info *)
  3285. (qdf_nbuf_data(qdf_nbuf_get_ext_list(
  3286. mpdu_nbuf)) -
  3287. (sizeof(struct msdu_completion_info) +
  3288. sizeof(qdf_ether_header_t)));
  3289. ptr_msdu_info->transmit_cnt--;
  3290. SEQ_SEG(user->failed_bitmap, i) |=
  3291. SEQ_SEG_MSK(user->failed_bitmap[0], i);
  3292. user->pending_retries--;
  3293. if (ptr_msdu_info->transmit_cnt == 0) {
  3294. index = seq_no - start_seq;
  3295. CHECK_MPDUS_NULL(user->mpdus[index]);
  3296. user->mpdus[index] = mpdu_nbuf;
  3297. dp_tx_cap_stats_mpdu_update(peer,
  3298. PEER_MPDU_ARR, 1);
  3299. /*
  3300. * This API removes mpdu_nbuf from q
  3301. * and returns next mpdu from the queue
  3302. */
  3303. mpdu_nbuf = dp_tx_mon_get_next_mpdu(pdev,
  3304. tx_tid,
  3305. xretry_user, mpdu_nbuf,
  3306. ppdu_nbuf);
  3307. } else {
  3308. index = seq_no - start_seq;
  3309. CHECK_MPDUS_NULL(user->mpdus[index]);
  3310. user->mpdus[index] =
  3311. qdf_nbuf_copy_expand_fraglist(
  3312. mpdu_nbuf,
  3313. MAX_MONITOR_HEADER, 0);
  3314. dp_tx_cap_stats_mpdu_update(peer,
  3315. PEER_MPDU_CLONE, 1);
  3316. mpdu_nbuf =
  3317. qdf_nbuf_queue_next(mpdu_nbuf);
  3318. }
  3319. }
  3320. }
  3321. if ((user->pending_retries == 0) &&
  3322. (ppdu_nbuf ==
  3323. qdf_nbuf_queue_first(&tx_tid->pending_ppdu_q))) {
  3324. qdf_nbuf_queue_remove(&tx_tid->pending_ppdu_q);
  3325. /* Deliver PPDU */
  3326. dp_send_data_to_stack(pdev, ppdu_desc, usr_idx);
  3327. dp_ppdu_queue_free(ppdu_nbuf, usr_idx);
  3328. qdf_nbuf_free(ppdu_nbuf);
  3329. ppdu_nbuf = qdf_nbuf_queue_first(
  3330. &tx_tid->pending_ppdu_q);
  3331. } else {
  3332. ppdu_nbuf = qdf_nbuf_queue_next(ppdu_nbuf);
  3333. }
  3334. }
  3335. TX_CAP_NBUF_QUEUE_FREE(&xretry_user->mpdu_q);
  3336. }
  3337. static
  3338. struct cdp_tx_completion_ppdu *
  3339. check_subseq_ppdu_to_pending_q(struct dp_tx_cap_nbuf_list nbuf_ppdu_list[],
  3340. uint32_t ppdu_desc_cnt,
  3341. uint32_t *ppdu_cnt,
  3342. qdf_nbuf_queue_t *head_ppdu,
  3343. uint32_t peer_id, uint32_t cur_last_seq,
  3344. bool last_pend_ppdu)
  3345. {
  3346. struct cdp_tx_completion_ppdu *next_ppdu = NULL;
  3347. struct cdp_tx_completion_ppdu_user *next_user;
  3348. struct dp_tx_cap_nbuf_list *ptr_nbuf_list = NULL;
  3349. uint8_t cur_usr_idx;
  3350. while (*ppdu_cnt < (ppdu_desc_cnt - 1)) {
  3351. (*ppdu_cnt)++;
  3352. ptr_nbuf_list = &nbuf_ppdu_list[*ppdu_cnt];
  3353. if (!ptr_nbuf_list->nbuf_ppdu ||
  3354. !dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list))
  3355. continue;
  3356. next_ppdu = (struct cdp_tx_completion_ppdu *)
  3357. qdf_nbuf_data(ptr_nbuf_list->nbuf_ppdu);
  3358. if (!next_ppdu)
  3359. continue;
  3360. cur_usr_idx = dp_tx_find_usr_idx_from_peer_id(next_ppdu,
  3361. peer_id);
  3362. next_user = &next_ppdu->user[cur_usr_idx];
  3363. if ((next_user->skip == 1) || (peer_id != next_user->peer_id) ||
  3364. (next_user->mon_procd == 1))
  3365. continue;
  3366. if (last_pend_ppdu) {
  3367. qdf_nbuf_t tmp_pend_nbuf;
  3368. uint32_t ppdu_ref_cnt;
  3369. /*
  3370. * get reference count if it
  3371. * more than one do clone and
  3372. * add that to head_ppdu
  3373. */
  3374. ppdu_ref_cnt =
  3375. dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list);
  3376. if (ppdu_ref_cnt == 1) {
  3377. tmp_pend_nbuf = ptr_nbuf_list->nbuf_ppdu;
  3378. } else {
  3379. tmp_pend_nbuf = qdf_nbuf_clone(
  3380. ptr_nbuf_list->nbuf_ppdu);
  3381. if (qdf_unlikely(!tmp_pend_nbuf)) {
  3382. qdf_assert_always(0);
  3383. continue;
  3384. }
  3385. qdf_nbuf_free(ptr_nbuf_list->nbuf_ppdu);
  3386. }
  3387. qdf_nbuf_queue_add(head_ppdu, tmp_pend_nbuf);
  3388. /* decrement reference */
  3389. dp_tx_cap_nbuf_list_dec_ref(ptr_nbuf_list);
  3390. next_user->mon_procd = 1;
  3391. }
  3392. if (next_user->last_enq_seq > cur_last_seq)
  3393. return next_ppdu;
  3394. }
  3395. return NULL;
  3396. }
  3397. #define MAX_PENDING_PPDUS 32
  3398. static void
  3399. dp_tx_mon_proc_pending_ppdus(struct dp_pdev *pdev, struct dp_tx_tid *tx_tid,
  3400. struct dp_tx_cap_nbuf_list nbuf_ppdu_list[],
  3401. uint32_t ppdu_desc_cnt, qdf_nbuf_queue_t *head_ppdu,
  3402. uint32_t peer_id, uint8_t cur_usr_idx)
  3403. {
  3404. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  3405. struct cdp_tx_completion_ppdu *cur_ppdu_desc = NULL;
  3406. struct cdp_tx_completion_ppdu_user *user = NULL;
  3407. struct cdp_tx_completion_ppdu_user *cur_user = NULL;
  3408. struct dp_tx_cap_nbuf_list *ptr_nbuf_list = NULL;
  3409. qdf_nbuf_t pend_ppdu;
  3410. uint32_t ppdu_cnt;
  3411. uint32_t failed_seq;
  3412. uint32_t cur_index, cur_start_seq, cur_last_seq;
  3413. int i, k;
  3414. bool last_pend_ppdu = false;
  3415. uint8_t usr_idx;
  3416. pend_ppdu = qdf_nbuf_queue_first(&tx_tid->pending_ppdu_q);
  3417. if (!pend_ppdu) {
  3418. for (ppdu_cnt = 0; ppdu_cnt < ppdu_desc_cnt; ppdu_cnt++) {
  3419. ptr_nbuf_list = &nbuf_ppdu_list[ppdu_cnt];
  3420. if (!dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list)) {
  3421. if (ptr_nbuf_list->nbuf_ppdu)
  3422. qdf_assert_always(0);
  3423. continue;
  3424. }
  3425. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3426. qdf_nbuf_data(ptr_nbuf_list->nbuf_ppdu);
  3427. if (!ppdu_desc)
  3428. continue;
  3429. user = &ppdu_desc->user[cur_usr_idx];
  3430. if ((user->skip == 1) || (peer_id != user->peer_id) ||
  3431. (tx_tid->tid != user->tid) || (user->mon_procd == 1))
  3432. continue;
  3433. if ((user->pending_retries == 0) &&
  3434. qdf_nbuf_is_queue_empty(&tx_tid->pending_ppdu_q) &&
  3435. qdf_nbuf_is_queue_empty(head_ppdu)) {
  3436. dp_send_data_to_stack(pdev, ppdu_desc,
  3437. cur_usr_idx);
  3438. user->mon_procd = 1;
  3439. /* free ppd_desc from list */
  3440. dp_ppdu_desc_free(ptr_nbuf_list, cur_usr_idx);
  3441. } else {
  3442. qdf_nbuf_t tmp_pend_nbuf;
  3443. uint32_t ppdu_ref_cnt;
  3444. /*
  3445. * get reference count if it more than one
  3446. * do clone and add that to head_ppdu
  3447. */
  3448. ppdu_ref_cnt =
  3449. dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list);
  3450. if (ppdu_ref_cnt == 1) {
  3451. tmp_pend_nbuf =
  3452. ptr_nbuf_list->nbuf_ppdu;
  3453. } else {
  3454. tmp_pend_nbuf =
  3455. qdf_nbuf_clone(
  3456. ptr_nbuf_list->nbuf_ppdu);
  3457. if (qdf_unlikely(!tmp_pend_nbuf)) {
  3458. qdf_assert_always(0);
  3459. continue;
  3460. }
  3461. /*
  3462. * free ppdu_desc to
  3463. * decrease reference
  3464. */
  3465. qdf_nbuf_free(ptr_nbuf_list->nbuf_ppdu);
  3466. }
  3467. qdf_nbuf_queue_add(head_ppdu, tmp_pend_nbuf);
  3468. /* decrement reference */
  3469. dp_tx_cap_nbuf_list_dec_ref(ptr_nbuf_list);
  3470. user->mon_procd = 1;
  3471. }
  3472. }
  3473. return;
  3474. }
  3475. while (pend_ppdu) {
  3476. qdf_nbuf_t mpdu_nbuf;
  3477. uint32_t mpdu_tried = 0;
  3478. /* Find missing mpdus from current schedule list */
  3479. ppdu_cnt = 0;
  3480. while (ppdu_cnt < ppdu_desc_cnt) {
  3481. ptr_nbuf_list = &nbuf_ppdu_list[ppdu_cnt];
  3482. ppdu_cnt++;
  3483. if (!dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list))
  3484. continue;
  3485. cur_ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3486. qdf_nbuf_data(ptr_nbuf_list->nbuf_ppdu);
  3487. if (!cur_ppdu_desc)
  3488. continue;
  3489. cur_usr_idx = dp_tx_find_usr_idx_from_peer_id(
  3490. cur_ppdu_desc, peer_id);
  3491. cur_user = &cur_ppdu_desc->user[cur_usr_idx];
  3492. if ((cur_user->skip == 1) ||
  3493. (cur_user->mon_procd == 1))
  3494. continue;
  3495. /* to handle last ppdu case we need to decrement */
  3496. ppdu_cnt--;
  3497. break;
  3498. }
  3499. if (ppdu_cnt == ppdu_desc_cnt)
  3500. break;
  3501. if (qdf_unlikely(!cur_user))
  3502. break;
  3503. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(
  3504. pend_ppdu);
  3505. usr_idx = dp_tx_find_usr_idx_from_peer_id(ppdu_desc,
  3506. peer_id);
  3507. user = &ppdu_desc->user[usr_idx];
  3508. if (pend_ppdu == qdf_nbuf_queue_last(
  3509. &tx_tid->pending_ppdu_q)) {
  3510. qdf_nbuf_t tmp_pend_nbuf;
  3511. uint32_t ppdu_ref_cnt;
  3512. last_pend_ppdu = true;
  3513. /*
  3514. * get reference count if it more than one
  3515. * do clone and add that to head_ppdu
  3516. */
  3517. ppdu_ref_cnt =
  3518. dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list);
  3519. if (ppdu_ref_cnt == 1) {
  3520. tmp_pend_nbuf =
  3521. ptr_nbuf_list->nbuf_ppdu;
  3522. } else {
  3523. tmp_pend_nbuf = qdf_nbuf_clone(
  3524. ptr_nbuf_list->nbuf_ppdu);
  3525. if (qdf_unlikely(!tmp_pend_nbuf)) {
  3526. qdf_assert_always(0);
  3527. break;
  3528. }
  3529. qdf_nbuf_free(ptr_nbuf_list->nbuf_ppdu);
  3530. }
  3531. qdf_nbuf_queue_add(head_ppdu, tmp_pend_nbuf);
  3532. /* decrement reference */
  3533. dp_tx_cap_nbuf_list_dec_ref(ptr_nbuf_list);
  3534. cur_user->mon_procd = 1;
  3535. }
  3536. cur_index = 0;
  3537. cur_start_seq = cur_user->start_seq;
  3538. cur_last_seq = cur_user->last_enq_seq;
  3539. if (qdf_unlikely(user->ba_size >
  3540. CDP_BA_256_BIT_MAP_SIZE_DWORDS *
  3541. SEQ_SEG_SZ_BITS(user->failed_bitmap))) {
  3542. dp_ppdu_desc_debug_print(ppdu_desc, usr_idx,
  3543. __func__, __LINE__);
  3544. qdf_assert_always(0);
  3545. return;
  3546. }
  3547. /* mpdu tried */
  3548. mpdu_tried = user->mpdu_tried_mcast + user->mpdu_tried_ucast;
  3549. for (i = 0; (i < user->ba_size) && cur_ppdu_desc &&
  3550. mpdu_tried && cur_index < cur_user->ba_size; i++) {
  3551. if (!(i & (SEQ_SEG_SZ_BITS(user->failed_bitmap) - 1))) {
  3552. k = SEQ_SEG_INDEX(user->failed_bitmap, i);
  3553. failed_seq = user->failed_bitmap[k] ^
  3554. user->enq_bitmap[k];
  3555. }
  3556. if (SEQ_BIT(user->enq_bitmap, i))
  3557. mpdu_tried--;
  3558. /* Skip to next bitmap segment if there are no
  3559. * more holes in current segment
  3560. */
  3561. if (!failed_seq) {
  3562. i = ((k + 1) *
  3563. SEQ_SEG_SZ_BITS(user->failed_bitmap)) - 1;
  3564. continue;
  3565. }
  3566. if (!(SEQ_SEG_BIT(failed_seq, i)))
  3567. continue;
  3568. failed_seq ^= SEQ_SEG_MSK(failed_seq, i);
  3569. if (!cur_user->mpdus) {
  3570. dp_tx_capture_info("%pK: peer_id:%d usr_idx:%d cur_usr_idx:%d cur_usr_peer_id:%d\n",
  3571. pdev->soc,
  3572. peer_id, usr_idx,
  3573. cur_usr_idx, cur_user->peer_id);
  3574. continue;
  3575. }
  3576. mpdu_nbuf = cur_user->mpdus[cur_index];
  3577. if (mpdu_nbuf) {
  3578. struct dp_peer *peer;
  3579. dp_tx_capture_info("%pK: fill seqno %d (%d) from swretries",
  3580. pdev->soc,
  3581. user->start_seq + i,
  3582. ppdu_desc->ppdu_id);
  3583. CHECK_MPDUS_NULL(user->mpdus[i]);
  3584. user->mpdus[i] =
  3585. qdf_nbuf_copy_expand_fraglist(
  3586. mpdu_nbuf, MAX_MONITOR_HEADER, 0);
  3587. peer = DP_TX_PEER_GET_REF(pdev, user->peer_id);
  3588. if (peer) {
  3589. dp_tx_cap_stats_mpdu_update(peer,
  3590. PEER_MPDU_CLONE, 1);
  3591. DP_TX_PEER_DEL_REF(peer);
  3592. }
  3593. user->failed_bitmap[k] |=
  3594. SEQ_SEG_MSK(user->failed_bitmap[k], i);
  3595. user->pending_retries--;
  3596. }
  3597. cur_index++;
  3598. if (cur_index >= cur_user->ba_size) {
  3599. dp_tx_capture_info("%pK: ba_size[%d] cur_index[%d]\n",
  3600. pdev->soc, cur_user->ba_size, cur_index);
  3601. break;
  3602. }
  3603. /* Skip through empty slots in current PPDU */
  3604. while (!(SEQ_BIT(cur_user->enq_bitmap, cur_index))) {
  3605. cur_index++;
  3606. if (cur_index <= (cur_last_seq - cur_start_seq))
  3607. continue;
  3608. cur_ppdu_desc = NULL;
  3609. /*
  3610. * Check if subsequent PPDUs in this schedule
  3611. * has higher sequence numbers enqueued
  3612. */
  3613. cur_ppdu_desc = check_subseq_ppdu_to_pending_q(
  3614. nbuf_ppdu_list,
  3615. ppdu_desc_cnt,
  3616. &ppdu_cnt,
  3617. head_ppdu,
  3618. peer_id,
  3619. cur_last_seq,
  3620. last_pend_ppdu);
  3621. if (!cur_ppdu_desc)
  3622. break;
  3623. cur_usr_idx = dp_tx_find_usr_idx_from_peer_id(
  3624. cur_ppdu_desc, peer_id);
  3625. cur_user = &cur_ppdu_desc->user[cur_usr_idx];
  3626. /* Start from seq. no following cur_last_seq
  3627. * since everything before is already populated
  3628. * from previous PPDU
  3629. */
  3630. cur_start_seq = cur_user->start_seq;
  3631. cur_index = (cur_last_seq >= cur_start_seq) ?
  3632. cur_last_seq - cur_start_seq + 1 : 0;
  3633. cur_last_seq = cur_user->last_enq_seq;
  3634. }
  3635. }
  3636. if ((pend_ppdu ==
  3637. qdf_nbuf_queue_first(&tx_tid->pending_ppdu_q)) &&
  3638. (user->pending_retries == 0)) {
  3639. qdf_nbuf_queue_remove(&tx_tid->pending_ppdu_q);
  3640. dp_send_data_to_stack(pdev, ppdu_desc, usr_idx);
  3641. dp_ppdu_queue_free(pend_ppdu, usr_idx);
  3642. qdf_nbuf_free(pend_ppdu);
  3643. pend_ppdu = qdf_nbuf_queue_first(
  3644. &tx_tid->pending_ppdu_q);
  3645. } else {
  3646. pend_ppdu = qdf_nbuf_queue_next(pend_ppdu);
  3647. }
  3648. }
  3649. }
  3650. static uint32_t
  3651. dp_send_mgmt_ctrl_to_stack(struct dp_pdev *pdev,
  3652. qdf_nbuf_t nbuf_ppdu_desc,
  3653. struct cdp_tx_indication_info *ptr_tx_cap_info,
  3654. qdf_nbuf_t mgmt_ctl_nbuf,
  3655. bool is_payload)
  3656. {
  3657. struct cdp_tx_completion_ppdu *ppdu_desc;
  3658. struct cdp_tx_completion_ppdu_user *user;
  3659. struct cdp_tx_indication_mpdu_info *mpdu_info;
  3660. struct ieee80211_frame *wh;
  3661. uint16_t duration_le, seq_le;
  3662. struct ieee80211_frame_min_one *wh_min;
  3663. uint16_t frame_ctrl_le;
  3664. uint8_t type, subtype;
  3665. mpdu_info = &ptr_tx_cap_info->mpdu_info;
  3666. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3667. qdf_nbuf_data(nbuf_ppdu_desc);
  3668. user = &ppdu_desc->user[0];
  3669. if (ppdu_desc->mprot_type)
  3670. dp_send_dummy_rts_cts_frame(pdev, ppdu_desc, 0);
  3671. type = (ppdu_desc->frame_ctrl &
  3672. IEEE80211_FC0_TYPE_MASK) >>
  3673. IEEE80211_FC0_TYPE_SHIFT;
  3674. subtype = (ppdu_desc->frame_ctrl &
  3675. IEEE80211_FC0_SUBTYPE_MASK) >>
  3676. IEEE80211_FC0_SUBTYPE_SHIFT;
  3677. if (is_payload) {
  3678. wh = (struct ieee80211_frame *)qdf_nbuf_data(mgmt_ctl_nbuf);
  3679. if (subtype != IEEE80211_FC0_SUBTYPE_BEACON) {
  3680. duration_le = qdf_cpu_to_le16(ppdu_desc->tx_duration);
  3681. wh->i_dur[1] = (duration_le & 0xFF00) >> 8;
  3682. wh->i_dur[0] = duration_le & 0xFF;
  3683. seq_le = qdf_cpu_to_le16(user->start_seq <<
  3684. IEEE80211_SEQ_SEQ_SHIFT);
  3685. wh->i_seq[1] = (seq_le & 0xFF00) >> 8;
  3686. wh->i_seq[0] = seq_le & 0xFF;
  3687. }
  3688. dp_tx_capture_debug("%pK: ctrl/mgmt frm(0x%08x): fc 0x%x 0x%x\n",
  3689. pdev->soc, ptr_tx_cap_info->mpdu_info.ppdu_id,
  3690. wh->i_fc[1], wh->i_fc[0]);
  3691. dp_tx_capture_debug("%pK: desc->ppdu_id 0x%08x\n", pdev->soc, ppdu_desc->ppdu_id);
  3692. /* append ext list */
  3693. qdf_nbuf_append_ext_list(ptr_tx_cap_info->mpdu_nbuf,
  3694. mgmt_ctl_nbuf,
  3695. qdf_nbuf_len(mgmt_ctl_nbuf));
  3696. } else {
  3697. wh_min = (struct ieee80211_frame_min_one *)
  3698. qdf_nbuf_data(ptr_tx_cap_info->mpdu_nbuf);
  3699. qdf_mem_zero(wh_min, MAX_DUMMY_FRM_BODY);
  3700. frame_ctrl_le = qdf_cpu_to_le16(ppdu_desc->frame_ctrl);
  3701. duration_le = qdf_cpu_to_le16(ppdu_desc->tx_duration);
  3702. wh_min->i_fc[1] = (frame_ctrl_le & 0xFF00) >> 8;
  3703. wh_min->i_fc[0] = (frame_ctrl_le & 0xFF);
  3704. wh_min->i_dur[1] = (duration_le & 0xFF00) >> 8;
  3705. wh_min->i_dur[0] = (duration_le & 0xFF);
  3706. qdf_mem_copy(wh_min->i_addr1, mpdu_info->mac_address,
  3707. QDF_MAC_ADDR_SIZE);
  3708. qdf_nbuf_set_pktlen(ptr_tx_cap_info->mpdu_nbuf,
  3709. sizeof(*wh_min));
  3710. dp_tx_capture_debug("%pK: frm(0x%08x): fc %x %x, dur 0x%x%x\n",
  3711. pdev->soc, ptr_tx_cap_info->mpdu_info.ppdu_id,
  3712. wh_min->i_fc[1], wh_min->i_fc[0],
  3713. wh_min->i_dur[1], wh_min->i_dur[0]);
  3714. }
  3715. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  3716. ptr_tx_cap_info, HTT_INVALID_PEER,
  3717. WDI_NO_VAL, pdev->pdev_id);
  3718. if (ptr_tx_cap_info->mpdu_nbuf)
  3719. qdf_nbuf_free(ptr_tx_cap_info->mpdu_nbuf);
  3720. return 0;
  3721. }
  3722. static uint32_t
  3723. dp_update_tx_cap_info(struct dp_pdev *pdev,
  3724. qdf_nbuf_t nbuf_ppdu_desc,
  3725. void *tx_info, bool is_payload,
  3726. bool bar_frm_with_data)
  3727. {
  3728. struct cdp_tx_completion_ppdu *ppdu_desc;
  3729. struct cdp_tx_completion_ppdu_user *user;
  3730. struct cdp_tx_indication_info *tx_capture_info =
  3731. (struct cdp_tx_indication_info *)tx_info;
  3732. struct cdp_tx_indication_mpdu_info *mpdu_info;
  3733. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3734. qdf_nbuf_data(nbuf_ppdu_desc);
  3735. user = &ppdu_desc->user[0];
  3736. qdf_mem_set(tx_capture_info, sizeof(struct cdp_tx_indication_info), 0);
  3737. mpdu_info = &tx_capture_info->mpdu_info;
  3738. mpdu_info->channel = ppdu_desc->channel;
  3739. mpdu_info->frame_type = ppdu_desc->frame_type;
  3740. mpdu_info->ppdu_start_timestamp = ppdu_desc->ppdu_start_timestamp;
  3741. mpdu_info->ppdu_end_timestamp = ppdu_desc->ppdu_end_timestamp;
  3742. mpdu_info->tx_duration = ppdu_desc->tx_duration;
  3743. /* update cdp_tx_indication_mpdu_info */
  3744. dp_tx_update_user_mpdu_info(ppdu_desc->ppdu_id,
  3745. &tx_capture_info->mpdu_info,
  3746. user);
  3747. if (bar_frm_with_data) {
  3748. mpdu_info->ppdu_start_timestamp =
  3749. ppdu_desc->bar_ppdu_start_timestamp;
  3750. mpdu_info->ppdu_end_timestamp =
  3751. ppdu_desc->bar_ppdu_end_timestamp;
  3752. mpdu_info->tx_duration = ppdu_desc->bar_tx_duration;
  3753. mpdu_info->preamble = ppdu_desc->phy_mode;
  3754. }
  3755. mpdu_info->seq_no = user->start_seq;
  3756. mpdu_info->num_msdu = ppdu_desc->num_msdu;
  3757. tx_capture_info->ppdu_desc = ppdu_desc;
  3758. tx_capture_info->mpdu_info.channel_num = pdev->operating_channel.num;
  3759. tx_capture_info->mpdu_info.ppdu_id = ppdu_desc->ppdu_id;
  3760. if (is_payload)
  3761. tx_capture_info->mpdu_nbuf = qdf_nbuf_alloc(pdev->soc->osdev,
  3762. MAX_MONITOR_HEADER,
  3763. MAX_MONITOR_HEADER,
  3764. 4, FALSE);
  3765. else
  3766. tx_capture_info->mpdu_nbuf = qdf_nbuf_alloc(pdev->soc->osdev,
  3767. MAX_MONITOR_HEADER +
  3768. MAX_DUMMY_FRM_BODY,
  3769. MAX_MONITOR_HEADER,
  3770. 4, FALSE);
  3771. return 0;
  3772. }
  3773. static uint32_t
  3774. dp_check_mgmt_ctrl_ppdu(struct dp_pdev *pdev,
  3775. qdf_nbuf_t nbuf_ppdu_desc, bool bar_frm_with_data)
  3776. {
  3777. struct cdp_tx_indication_info tx_capture_info;
  3778. qdf_nbuf_t mgmt_ctl_nbuf, tmp_nbuf;
  3779. uint8_t type, subtype;
  3780. uint8_t fc_type, fc_subtype;
  3781. bool is_sgen_pkt;
  3782. struct cdp_tx_mgmt_comp_info *ptr_comp_info;
  3783. qdf_nbuf_queue_t *retries_q;
  3784. struct cdp_tx_completion_ppdu *ppdu_desc, *retry_ppdu;
  3785. struct cdp_tx_completion_ppdu_user *user;
  3786. uint32_t ppdu_id;
  3787. uint32_t desc_ppdu_id;
  3788. size_t head_size;
  3789. uint32_t status = 1;
  3790. uint64_t tsf_delta;
  3791. uint64_t start_tsf;
  3792. uint64_t end_tsf;
  3793. uint16_t ppdu_desc_frame_ctrl;
  3794. struct dp_peer *peer;
  3795. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3796. qdf_nbuf_data(nbuf_ppdu_desc);
  3797. user = &ppdu_desc->user[0];
  3798. ppdu_desc_frame_ctrl = ppdu_desc->frame_ctrl;
  3799. if ((ppdu_desc->htt_frame_type == HTT_STATS_FTYPE_SGEN_MU_BAR) ||
  3800. (ppdu_desc->htt_frame_type == HTT_STATS_FTYPE_SGEN_MU_BRP))
  3801. ppdu_desc_frame_ctrl = (IEEE80211_FC0_SUBTYPE_TRIGGER |
  3802. IEEE80211_FC0_TYPE_CTL);
  3803. if (bar_frm_with_data) {
  3804. desc_ppdu_id = ppdu_desc->bar_ppdu_id;
  3805. start_tsf = ppdu_desc->bar_ppdu_start_timestamp;
  3806. end_tsf = ppdu_desc->bar_ppdu_end_timestamp;
  3807. } else {
  3808. desc_ppdu_id = ppdu_desc->ppdu_id;
  3809. start_tsf = ppdu_desc->ppdu_start_timestamp;
  3810. end_tsf = ppdu_desc->ppdu_end_timestamp;
  3811. }
  3812. /*
  3813. * only for host generated frame we do have
  3814. * timestamp and retries count.
  3815. */
  3816. head_size = sizeof(struct cdp_tx_mgmt_comp_info);
  3817. fc_type = (ppdu_desc_frame_ctrl &
  3818. IEEE80211_FC0_TYPE_MASK);
  3819. fc_subtype = (ppdu_desc_frame_ctrl &
  3820. IEEE80211_FC0_SUBTYPE_MASK);
  3821. type = (ppdu_desc_frame_ctrl &
  3822. IEEE80211_FC0_TYPE_MASK) >>
  3823. IEEE80211_FC0_TYPE_SHIFT;
  3824. subtype = (ppdu_desc_frame_ctrl &
  3825. IEEE80211_FC0_SUBTYPE_MASK) >>
  3826. IEEE80211_FC0_SUBTYPE_SHIFT;
  3827. if (ppdu_desc->htt_frame_type == HTT_STATS_FTYPE_SGEN_NDP) {
  3828. dp_update_frame_ctrl_from_frame_type(ppdu_desc);
  3829. type = 0;
  3830. subtype = 0;
  3831. }
  3832. peer = DP_TX_PEER_GET_REF(pdev, ppdu_desc->user[0].peer_id);
  3833. if (peer && !peer->bss_peer) {
  3834. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, peer,
  3835. ppdu_desc->user[0].mac_addr
  3836. )) {
  3837. qdf_nbuf_free(nbuf_ppdu_desc);
  3838. status = 0;
  3839. DP_TX_PEER_DEL_REF(peer);
  3840. goto free_ppdu_desc;
  3841. }
  3842. DP_TX_PEER_DEL_REF(peer);
  3843. } else {
  3844. if (peer)
  3845. DP_TX_PEER_DEL_REF(peer);
  3846. if (!(type == IEEE80211_FC0_TYPE_MGT &&
  3847. (subtype == MGMT_SUBTYPE_PROBE_RESP >> 4 ||
  3848. subtype == MGMT_SUBTYPE_DISASSOC >> 4 ||
  3849. subtype == MGMT_SUBTYPE_DEAUTH >> 4))) {
  3850. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, NULL,
  3851. ppdu_desc->user[0]
  3852. .mac_addr)) {
  3853. qdf_nbuf_free(nbuf_ppdu_desc);
  3854. status = 0;
  3855. goto free_ppdu_desc;
  3856. }
  3857. }
  3858. }
  3859. switch (ppdu_desc->htt_frame_type) {
  3860. case HTT_STATS_FTYPE_TIDQ_DATA_SU:
  3861. case HTT_STATS_FTYPE_TIDQ_DATA_MU:
  3862. if ((fc_type == IEEE80211_FC0_TYPE_MGT) &&
  3863. (fc_subtype == IEEE80211_FC0_SUBTYPE_BEACON))
  3864. is_sgen_pkt = true;
  3865. else
  3866. is_sgen_pkt = false;
  3867. break;
  3868. default:
  3869. is_sgen_pkt = true;
  3870. break;
  3871. }
  3872. retries_q = &pdev->tx_capture.retries_ctl_mgmt_q[type][subtype];
  3873. if (!qdf_nbuf_is_queue_empty(retries_q)) {
  3874. tmp_nbuf = qdf_nbuf_queue_first(retries_q);
  3875. retry_ppdu = (struct cdp_tx_completion_ppdu *)
  3876. qdf_nbuf_data(tmp_nbuf);
  3877. if (ppdu_desc->sched_cmdid != retry_ppdu->sched_cmdid)
  3878. TX_CAP_NBUF_QUEUE_FREE(retries_q);
  3879. }
  3880. get_mgmt_pkt_from_queue:
  3881. qdf_spin_lock_bh(
  3882. &pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  3883. mgmt_ctl_nbuf = qdf_nbuf_queue_remove(
  3884. &pdev->tx_capture.ctl_mgmt_q[type][subtype]);
  3885. qdf_spin_unlock_bh(&pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  3886. if (mgmt_ctl_nbuf) {
  3887. qdf_nbuf_t tmp_mgmt_ctl_nbuf;
  3888. ptr_comp_info = (struct cdp_tx_mgmt_comp_info *)
  3889. qdf_nbuf_data(mgmt_ctl_nbuf);
  3890. is_sgen_pkt = ptr_comp_info->is_sgen_pkt;
  3891. ppdu_id = ptr_comp_info->ppdu_id;
  3892. if (!is_sgen_pkt && ptr_comp_info->tx_tsf < start_tsf) {
  3893. /*
  3894. * free the older mgmt buffer from
  3895. * the queue and get new mgmt buffer
  3896. */
  3897. qdf_nbuf_free(mgmt_ctl_nbuf);
  3898. goto get_mgmt_pkt_from_queue;
  3899. }
  3900. /*
  3901. * for sgen frame we won't have, retries count
  3902. * and 64 bits tsf in the head.
  3903. */
  3904. if (ppdu_id != desc_ppdu_id) {
  3905. if (is_sgen_pkt) {
  3906. start_tsf = (start_tsf & LOWER_32_MASK);
  3907. if (start_tsf > ptr_comp_info->tx_tsf)
  3908. tsf_delta = start_tsf -
  3909. ptr_comp_info->tx_tsf;
  3910. else
  3911. tsf_delta = LOWER_32_MASK -
  3912. ptr_comp_info->tx_tsf +
  3913. start_tsf;
  3914. dp_tx_capture_info("%pK: ppdu_id[m:%d desc:%d] start_tsf: %llu mgmt_tsf:%llu tsf_delta:%llu bar_frm_with_data:%d",
  3915. pdev->soc, ppdu_id, desc_ppdu_id,
  3916. start_tsf, ptr_comp_info->tx_tsf,
  3917. tsf_delta, bar_frm_with_data);
  3918. if (tsf_delta > MAX_MGMT_ENQ_DELAY) {
  3919. /*
  3920. * free the older mgmt buffer from
  3921. * the queue and get new mgmt buffer
  3922. */
  3923. qdf_nbuf_free(mgmt_ctl_nbuf);
  3924. goto get_mgmt_pkt_from_queue;
  3925. } else {
  3926. /* drop the ppdu_desc */
  3927. qdf_nbuf_free(nbuf_ppdu_desc);
  3928. status = 0;
  3929. goto insert_mgmt_buf_to_queue;
  3930. }
  3931. }
  3932. /*
  3933. * only for the packets send over the air are handled
  3934. * packets drop by firmware is not handled in this
  3935. * feature
  3936. */
  3937. if (user->completion_status ==
  3938. HTT_PPDU_STATS_USER_STATUS_FILTERED) {
  3939. qdf_nbuf_free(nbuf_ppdu_desc);
  3940. status = 0;
  3941. goto insert_mgmt_buf_to_queue;
  3942. }
  3943. /* check for max retry count */
  3944. if (qdf_nbuf_queue_len(retries_q) >=
  3945. MAX_RETRY_Q_COUNT) {
  3946. qdf_nbuf_t nbuf_retry_ppdu;
  3947. nbuf_retry_ppdu =
  3948. qdf_nbuf_queue_remove(retries_q);
  3949. qdf_nbuf_free(nbuf_retry_ppdu);
  3950. }
  3951. /*
  3952. * add the ppdu_desc into retry queue
  3953. */
  3954. qdf_nbuf_queue_add(retries_q, nbuf_ppdu_desc);
  3955. /* flushing retry queue since completion status is
  3956. * in final state. meaning that even though ppdu_id are
  3957. * different there is a payload already.
  3958. */
  3959. if (qdf_unlikely(ppdu_desc->user[0].completion_status ==
  3960. HTT_PPDU_STATS_USER_STATUS_OK)) {
  3961. TX_CAP_NBUF_QUEUE_FREE(retries_q);
  3962. }
  3963. status = 0;
  3964. insert_mgmt_buf_to_queue:
  3965. /*
  3966. * insert the mgmt_ctl buffer back to
  3967. * the queue
  3968. */
  3969. qdf_spin_lock_bh(
  3970. &pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  3971. qdf_nbuf_queue_insert_head(
  3972. &pdev->tx_capture.ctl_mgmt_q[type][subtype],
  3973. mgmt_ctl_nbuf);
  3974. qdf_spin_unlock_bh(
  3975. &pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  3976. } else {
  3977. qdf_nbuf_t nbuf_retry_ppdu;
  3978. struct cdp_tx_completion_ppdu *tmp_ppdu_desc;
  3979. uint16_t frame_ctrl_le;
  3980. struct ieee80211_frame *wh;
  3981. uint32_t retry_len = 0;
  3982. dp_tx_capture_info("%pK: ppdu_id[m:%d desc:%d] start_tsf: %llu mgmt_tsf:%llu bar_frm_with_data:%d is_sgen:%d",
  3983. pdev->soc, ppdu_id, desc_ppdu_id,
  3984. start_tsf, ptr_comp_info->tx_tsf,
  3985. bar_frm_with_data, is_sgen_pkt);
  3986. /*
  3987. * only for the packets send over the air are handled
  3988. * packets drop by firmware is not handled in this
  3989. * feature
  3990. */
  3991. if (user->completion_status ==
  3992. HTT_PPDU_STATS_USER_STATUS_FILTERED) {
  3993. qdf_nbuf_free(nbuf_ppdu_desc);
  3994. qdf_nbuf_free(mgmt_ctl_nbuf);
  3995. status = 0;
  3996. goto free_ppdu_desc;
  3997. }
  3998. /* pull head based on sgen pkt or mgmt pkt */
  3999. if (NULL == qdf_nbuf_pull_head(mgmt_ctl_nbuf,
  4000. head_size)) {
  4001. dp_tx_capture_alert("%pK: No Head space to pull !!\n", pdev->soc);
  4002. qdf_assert_always(0);
  4003. }
  4004. wh = (struct ieee80211_frame *)
  4005. (qdf_nbuf_data(mgmt_ctl_nbuf));
  4006. if (type == IEEE80211_FC0_TYPE_MGT &&
  4007. (subtype == MGMT_SUBTYPE_PROBE_RESP >> 4 ||
  4008. subtype == MGMT_SUBTYPE_DISASSOC >> 4 ||
  4009. subtype == MGMT_SUBTYPE_DEAUTH >> 4)) {
  4010. if (!dp_peer_or_pdev_tx_cap_enabled(pdev,
  4011. NULL,
  4012. wh->i_addr1
  4013. )) {
  4014. qdf_nbuf_free(nbuf_ppdu_desc);
  4015. qdf_nbuf_free(mgmt_ctl_nbuf);
  4016. TX_CAP_NBUF_QUEUE_FREE(retries_q);
  4017. status = 0;
  4018. goto free_ppdu_desc;
  4019. }
  4020. }
  4021. while (qdf_nbuf_queue_len(retries_q)) {
  4022. /*
  4023. * send retried packet stored
  4024. * in queue
  4025. */
  4026. nbuf_retry_ppdu =
  4027. qdf_nbuf_queue_remove(retries_q);
  4028. retry_len = qdf_nbuf_queue_len(retries_q);
  4029. if (!nbuf_retry_ppdu) {
  4030. dp_tx_capture_alert("%pK: retry q type[%d][%d] retry q len = %d\n",
  4031. pdev->soc,
  4032. type, subtype, retry_len);
  4033. qdf_assert_always(0);
  4034. break;
  4035. }
  4036. tmp_ppdu_desc =
  4037. (struct cdp_tx_completion_ppdu *)
  4038. qdf_nbuf_data(nbuf_retry_ppdu);
  4039. tmp_mgmt_ctl_nbuf =
  4040. qdf_nbuf_copy_expand(mgmt_ctl_nbuf,
  4041. 0, 0);
  4042. if (qdf_unlikely(!tmp_mgmt_ctl_nbuf)) {
  4043. dp_tx_capture_alert("%pK: No memory to do copy!!", pdev->soc);
  4044. qdf_assert_always(0);
  4045. }
  4046. dp_update_tx_cap_info(pdev, nbuf_retry_ppdu,
  4047. &tx_capture_info, true,
  4048. bar_frm_with_data);
  4049. if (!tx_capture_info.mpdu_nbuf) {
  4050. qdf_nbuf_free(nbuf_retry_ppdu);
  4051. qdf_nbuf_free(tmp_mgmt_ctl_nbuf);
  4052. continue;
  4053. }
  4054. /*
  4055. * frame control from ppdu_desc has
  4056. * retry flag set
  4057. */
  4058. frame_ctrl_le =
  4059. qdf_cpu_to_le16(tmp_ppdu_desc->frame_ctrl);
  4060. wh = (struct ieee80211_frame *)
  4061. (qdf_nbuf_data(tmp_mgmt_ctl_nbuf));
  4062. wh->i_fc[1] = (frame_ctrl_le & 0xFF00) >> 8;
  4063. wh->i_fc[0] = (frame_ctrl_le & 0xFF);
  4064. tx_capture_info.ppdu_desc = tmp_ppdu_desc;
  4065. /*
  4066. * send MPDU to osif layer
  4067. */
  4068. dp_send_mgmt_ctrl_to_stack(pdev,
  4069. nbuf_retry_ppdu,
  4070. &tx_capture_info,
  4071. tmp_mgmt_ctl_nbuf,
  4072. true);
  4073. /* free retried queue nbuf ppdu_desc */
  4074. qdf_nbuf_free(nbuf_retry_ppdu);
  4075. }
  4076. dp_update_tx_cap_info(pdev, nbuf_ppdu_desc,
  4077. &tx_capture_info, true,
  4078. bar_frm_with_data);
  4079. if (!tx_capture_info.mpdu_nbuf) {
  4080. qdf_nbuf_free(mgmt_ctl_nbuf);
  4081. qdf_nbuf_free(nbuf_ppdu_desc);
  4082. status = 0;
  4083. goto free_ppdu_desc;
  4084. }
  4085. tx_capture_info.mpdu_info.ppdu_id =
  4086. *(uint32_t *)qdf_nbuf_data(mgmt_ctl_nbuf);
  4087. /* frame control from ppdu_desc has retry flag set */
  4088. frame_ctrl_le = qdf_cpu_to_le16(ppdu_desc_frame_ctrl);
  4089. wh = (struct ieee80211_frame *)
  4090. (qdf_nbuf_data(mgmt_ctl_nbuf));
  4091. wh->i_fc[1] = (frame_ctrl_le & 0xFF00) >> 8;
  4092. wh->i_fc[0] = (frame_ctrl_le & 0xFF);
  4093. tx_capture_info.ppdu_desc = ppdu_desc;
  4094. /*
  4095. * send MPDU to osif layer
  4096. */
  4097. dp_send_mgmt_ctrl_to_stack(pdev, nbuf_ppdu_desc,
  4098. &tx_capture_info,
  4099. mgmt_ctl_nbuf, true);
  4100. }
  4101. } else if (!is_sgen_pkt) {
  4102. /*
  4103. * only for the packets send over the air are handled
  4104. * packets drop by firmware is not handled in this
  4105. * feature
  4106. */
  4107. if (user->completion_status ==
  4108. HTT_PPDU_STATS_USER_STATUS_FILTERED) {
  4109. qdf_nbuf_free(nbuf_ppdu_desc);
  4110. status = 0;
  4111. goto free_ppdu_desc;
  4112. }
  4113. /* check for max retry count */
  4114. if (qdf_nbuf_queue_len(retries_q) >= MAX_RETRY_Q_COUNT) {
  4115. qdf_nbuf_t nbuf_retry_ppdu;
  4116. nbuf_retry_ppdu =
  4117. qdf_nbuf_queue_remove(retries_q);
  4118. qdf_nbuf_free(nbuf_retry_ppdu);
  4119. }
  4120. /*
  4121. * add the ppdu_desc into retry queue
  4122. */
  4123. qdf_nbuf_queue_add(retries_q, nbuf_ppdu_desc);
  4124. /* flushing retry queue since completion status is
  4125. * in final state. meaning that even though ppdu_id are
  4126. * different there is a payload already.
  4127. */
  4128. if (qdf_unlikely(ppdu_desc->user[0].completion_status ==
  4129. HTT_PPDU_STATS_USER_STATUS_OK)) {
  4130. TX_CAP_NBUF_QUEUE_FREE(retries_q);
  4131. }
  4132. status = 0;
  4133. } else if ((ppdu_desc_frame_ctrl &
  4134. IEEE80211_FC0_TYPE_MASK) ==
  4135. IEEE80211_FC0_TYPE_CTL) {
  4136. /*
  4137. * only for the packets send over the air are handled
  4138. * packets drop by firmware is not handled in this
  4139. * feature
  4140. */
  4141. if (user->completion_status ==
  4142. HTT_PPDU_STATS_USER_STATUS_FILTERED) {
  4143. qdf_nbuf_free(nbuf_ppdu_desc);
  4144. status = 0;
  4145. goto free_ppdu_desc;
  4146. }
  4147. dp_update_tx_cap_info(pdev, nbuf_ppdu_desc,
  4148. &tx_capture_info, false,
  4149. bar_frm_with_data);
  4150. if (!tx_capture_info.mpdu_nbuf) {
  4151. qdf_nbuf_free(nbuf_ppdu_desc);
  4152. status = 0;
  4153. goto free_ppdu_desc;
  4154. }
  4155. /*
  4156. * send MPDU to osif layer
  4157. */
  4158. dp_send_mgmt_ctrl_to_stack(pdev, nbuf_ppdu_desc,
  4159. &tx_capture_info, NULL, false);
  4160. }
  4161. free_ppdu_desc:
  4162. return status;
  4163. }
  4164. /**
  4165. * dp_peer_tx_cap_tid_queue_flush_tlv(): Function to dequeue peer queue
  4166. * @pdev: DP pdev handle
  4167. * @peer; DP peer handle
  4168. * @ppdu_desc: ppdu_desc
  4169. *
  4170. * return: void
  4171. */
  4172. static void
  4173. dp_peer_tx_cap_tid_queue_flush_tlv(struct dp_pdev *pdev,
  4174. struct dp_peer *peer,
  4175. struct cdp_tx_completion_ppdu *ppdu_desc,
  4176. uint8_t usr_idx)
  4177. {
  4178. int tid;
  4179. struct dp_tx_tid *tx_tid;
  4180. qdf_nbuf_queue_t head_xretries;
  4181. qdf_nbuf_queue_t head_msdu;
  4182. uint32_t qlen = 0;
  4183. uint32_t qlen_curr = 0;
  4184. struct cdp_tx_completion_ppdu_user *user;
  4185. user = &ppdu_desc->user[usr_idx];
  4186. tid = user->tid;
  4187. tx_tid = &peer->tx_capture.tx_tid[tid];
  4188. qdf_nbuf_queue_init(&head_msdu);
  4189. qdf_nbuf_queue_init(&head_xretries);
  4190. qlen = qdf_nbuf_queue_len(&tx_tid->defer_msdu_q);
  4191. dp_tx_msdu_dequeue(peer, INVALID_PPDU_ID,
  4192. tid, ppdu_desc->num_msdu,
  4193. &head_msdu,
  4194. &head_xretries,
  4195. 0, MAX_END_TSF);
  4196. dp_tx_cap_stats_msdu_update(peer, PEER_MSDU_FLUSH,
  4197. qdf_nbuf_queue_len(&head_msdu));
  4198. dp_tx_cap_stats_msdu_update(peer, PEER_MSDU_FLUSH,
  4199. qdf_nbuf_queue_len(&head_xretries));
  4200. if (!qdf_nbuf_is_queue_empty(&head_xretries)) {
  4201. struct cdp_tx_completion_ppdu *xretry_ppdu = NULL;
  4202. struct cdp_tx_completion_ppdu_user *xretry_user = NULL;
  4203. uint32_t xretry_qlen;
  4204. xretry_ppdu = tx_tid->xretry_ppdu;
  4205. if (!xretry_ppdu) {
  4206. dp_tx_capture_alert("%pK: xretry_ppdu is NULL",
  4207. pdev->soc);
  4208. return;
  4209. }
  4210. xretry_user = &xretry_ppdu->user[0];
  4211. if (!xretry_user) {
  4212. dp_tx_capture_alert("%pK: xretry_user is NULL",
  4213. pdev->soc);
  4214. return;
  4215. }
  4216. xretry_ppdu->ppdu_id = peer->tx_capture.tx_wifi_ppdu_id;
  4217. /* Restitch MPDUs from xretry MSDUs */
  4218. dp_tx_mon_restitch_mpdu(pdev, peer,
  4219. xretry_ppdu,
  4220. &head_xretries,
  4221. &xretry_user->mpdu_q,
  4222. 0);
  4223. xretry_qlen = qdf_nbuf_queue_len(&xretry_user->mpdu_q);
  4224. dp_tx_cap_stats_mpdu_update(peer, PEER_MPDU_RESTITCH,
  4225. xretry_qlen);
  4226. }
  4227. TX_CAP_NBUF_QUEUE_FREE(&head_msdu);
  4228. TX_CAP_NBUF_QUEUE_FREE(&head_xretries);
  4229. qlen_curr = qdf_nbuf_queue_len(&tx_tid->defer_msdu_q);
  4230. dp_tx_mon_proc_xretries(pdev, peer, tid);
  4231. dp_tx_capture_info("%pK: peer_id [%d %pK] tid[%d] qlen[%d -> %d]",
  4232. pdev->soc, ppdu_desc->user[usr_idx].peer_id, peer, tid, qlen, qlen_curr);
  4233. }
  4234. /**
  4235. * dp_tx_ppdu_stats_flush(): Function to flush pending retried ppdu desc
  4236. * @pdev: DP pdev handle
  4237. * @nbuf: ppdu_desc
  4238. *
  4239. * return: void
  4240. */
  4241. static void
  4242. dp_tx_ppdu_stats_flush(struct dp_pdev *pdev,
  4243. struct cdp_tx_completion_ppdu *ppdu_desc,
  4244. uint8_t usr_idx)
  4245. {
  4246. struct dp_peer *peer;
  4247. struct cdp_tx_completion_ppdu_user *user;
  4248. user = &ppdu_desc->user[usr_idx];
  4249. peer = DP_TX_PEER_GET_REF(pdev, user->peer_id);
  4250. if (!peer)
  4251. return;
  4252. if (peer->tx_capture.is_tid_initialized) {
  4253. dp_peer_tx_cap_tid_queue_flush_tlv(pdev, peer, ppdu_desc, usr_idx);
  4254. }
  4255. DP_TX_PEER_DEL_REF(peer);
  4256. return;
  4257. }
  4258. /**
  4259. * dp_check_ppdu_and_deliver(): Check PPDUs for any holes and deliver
  4260. * to upper layer if complete
  4261. * @pdev: DP pdev handle
  4262. * @nbuf_ppdu_list: ppdu_desc_list per sched cmd id
  4263. * @ppdu_desc_cnt: number of ppdu_desc_cnt
  4264. *
  4265. * return: status
  4266. */
  4267. static void
  4268. dp_check_ppdu_and_deliver(struct dp_pdev *pdev,
  4269. struct dp_tx_cap_nbuf_list nbuf_ppdu_list[],
  4270. uint32_t ppdu_desc_cnt)
  4271. {
  4272. uint32_t ppdu_id;
  4273. uint32_t desc_cnt;
  4274. qdf_nbuf_t tmp_nbuf;
  4275. struct dp_tx_tid *tx_tid = NULL;
  4276. int i;
  4277. uint8_t max_num_users = 0;
  4278. uint8_t usr_idx;
  4279. struct dp_tx_cap_nbuf_list *ptr_nbuf_list;
  4280. for (desc_cnt = 0; desc_cnt < ppdu_desc_cnt; desc_cnt++) {
  4281. struct cdp_tx_completion_ppdu *ppdu_desc;
  4282. struct cdp_tx_completion_ppdu_user *user;
  4283. uint32_t num_mpdu;
  4284. uint16_t start_seq, seq_no = 0;
  4285. int i;
  4286. qdf_nbuf_t mpdu_nbuf;
  4287. struct dp_peer *peer;
  4288. uint8_t type;
  4289. uint8_t subtype;
  4290. uint8_t usr_type;
  4291. uint32_t mpdus_tried;
  4292. uint8_t num_users;
  4293. qdf_nbuf_t nbuf_ppdu;
  4294. bool is_bar_frm_with_data = false;
  4295. ptr_nbuf_list = &nbuf_ppdu_list[desc_cnt];
  4296. if (!dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list)) {
  4297. if (ptr_nbuf_list->nbuf_ppdu)
  4298. qdf_assert_always(0);
  4299. continue;
  4300. }
  4301. nbuf_ppdu = ptr_nbuf_list->nbuf_ppdu;
  4302. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  4303. qdf_nbuf_data(nbuf_ppdu);
  4304. ppdu_id = ppdu_desc->ppdu_id;
  4305. num_users = ppdu_desc->num_users;
  4306. if (ppdu_desc->is_flush) {
  4307. dp_tx_ppdu_stats_flush(pdev, ppdu_desc, 0);
  4308. dp_ppdu_desc_free_all(ptr_nbuf_list, num_users);
  4309. continue;
  4310. }
  4311. if (max_num_users < ppdu_desc->num_users)
  4312. max_num_users = ppdu_desc->num_users;
  4313. type = (ppdu_desc->frame_ctrl & IEEE80211_FC0_TYPE_MASK);
  4314. subtype = (ppdu_desc->frame_ctrl &
  4315. IEEE80211_FC0_SUBTYPE_MASK);
  4316. usr_type = (ppdu_desc->user[0].frame_ctrl &
  4317. IEEE80211_FC0_TYPE_MASK);
  4318. /* handle management frame */
  4319. if ((type != IEEE80211_FC0_TYPE_DATA) ||
  4320. (ppdu_desc->htt_frame_type ==
  4321. HTT_STATS_FTYPE_SGEN_MU_BAR) ||
  4322. (ppdu_desc->htt_frame_type ==
  4323. HTT_STATS_FTYPE_SGEN_QOS_NULL)) {
  4324. qdf_nbuf_t tmp_nbuf_ppdu;
  4325. tmp_nbuf_ppdu = nbuf_ppdu;
  4326. /*
  4327. * take reference of ppdu_desc if the htt_frame_type is
  4328. * HTT_STATS_FTYPE_SGEN_MU_BAR, as there will be
  4329. * corresponding data frame
  4330. */
  4331. if (((type == IEEE80211_FC0_TYPE_CTL) &&
  4332. (subtype == IEEE80211_FC0_SUBTYPE_BAR) &&
  4333. (usr_type == IEEE80211_FC0_TYPE_DATA)) ||
  4334. (ppdu_desc->htt_frame_type ==
  4335. HTT_STATS_FTYPE_SGEN_MU_BAR)) {
  4336. /*
  4337. * clonning ppdu_desc additional reference as
  4338. * handling data frame
  4339. */
  4340. tmp_nbuf_ppdu = qdf_nbuf_clone(nbuf_ppdu);
  4341. if (qdf_unlikely(!tmp_nbuf_ppdu)) {
  4342. qdf_assert_always(0);
  4343. continue;
  4344. }
  4345. dp_tx_cap_nbuf_list_inc_ref(ptr_nbuf_list);
  4346. is_bar_frm_with_data = true;
  4347. }
  4348. if (dp_check_mgmt_ctrl_ppdu(pdev, tmp_nbuf_ppdu,
  4349. is_bar_frm_with_data)) {
  4350. dp_tx_cap_nbuf_list_dec_ref(ptr_nbuf_list);
  4351. qdf_nbuf_free(tmp_nbuf_ppdu);
  4352. } else {
  4353. dp_tx_cap_nbuf_list_dec_ref(ptr_nbuf_list);
  4354. }
  4355. if (!is_bar_frm_with_data)
  4356. continue;
  4357. }
  4358. /*
  4359. * process only data frame and other
  4360. */
  4361. for (usr_idx = 0; usr_idx < num_users; usr_idx++) {
  4362. uint32_t mpdu_enq = 0;
  4363. uint32_t mpdu_tried = 0;
  4364. if (!ptr_nbuf_list->nbuf_ppdu ||
  4365. !dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list)) {
  4366. continue;
  4367. }
  4368. nbuf_ppdu = ptr_nbuf_list->nbuf_ppdu;
  4369. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  4370. qdf_nbuf_data(nbuf_ppdu);
  4371. user = &ppdu_desc->user[usr_idx];
  4372. if (user->delayed_ba || user->skip == 1)
  4373. continue;
  4374. peer = DP_TX_PEER_GET_REF(pdev, user->peer_id);
  4375. if (!peer) {
  4376. user->skip = 1;
  4377. dp_ppdu_desc_free(ptr_nbuf_list, usr_idx);
  4378. continue;
  4379. }
  4380. if (!peer->tx_capture.is_tid_initialized) {
  4381. user->skip = 1;
  4382. dp_ppdu_desc_free(ptr_nbuf_list, usr_idx);
  4383. DP_TX_PEER_DEL_REF(peer);
  4384. continue;
  4385. }
  4386. tx_tid = &peer->tx_capture.tx_tid[user->tid];
  4387. tx_tid->last_processed_ms =
  4388. qdf_system_ticks_to_msecs(qdf_system_ticks());
  4389. ppdu_id = ppdu_desc->ppdu_id;
  4390. /* find mpdu tried is same as success mpdu */
  4391. num_mpdu = user->mpdu_success;
  4392. /*
  4393. * ba_size is updated in BA bitmap TLVs,
  4394. * which are not received
  4395. * in case of non-QoS TID.
  4396. */
  4397. if (qdf_unlikely(user->tid == DP_NON_QOS_TID)) {
  4398. user->ba_size = 1;
  4399. user->last_enq_seq = user->start_seq;
  4400. }
  4401. if (user->ba_size == 0)
  4402. user->ba_size = 1;
  4403. /* find list of missing sequence */
  4404. user->mpdus = qdf_mem_malloc(sizeof(qdf_nbuf_t) *
  4405. user->ba_size);
  4406. if (qdf_unlikely(!user->mpdus)) {
  4407. dp_tx_capture_alert("%pK: ppdu_desc->mpdus allocation failed",
  4408. pdev->soc);
  4409. dp_ppdu_desc_free_all(ptr_nbuf_list, num_users);
  4410. DP_TX_PEER_DEL_REF(peer);
  4411. dp_print_pdev_tx_capture_stats(pdev);
  4412. qdf_assert_always(0);
  4413. return;
  4414. }
  4415. if (qdf_unlikely(user->ba_size >
  4416. CDP_BA_256_BIT_MAP_SIZE_DWORDS *
  4417. SEQ_SEG_SZ_BITS(user->failed_bitmap))) {
  4418. DP_TX_PEER_DEL_REF(peer);
  4419. qdf_assert_always(0);
  4420. return;
  4421. }
  4422. /* Fill seq holes within current schedule list */
  4423. start_seq = user->start_seq;
  4424. seq_no = 0;
  4425. mpdus_tried = user->mpdu_tried_mcast +
  4426. user->mpdu_tried_ucast;
  4427. for (i = 0; (i < user->ba_size) && mpdus_tried; i++) {
  4428. if (qdf_likely(user->tid != DP_NON_QOS_TID) &&
  4429. !(SEQ_BIT(user->enq_bitmap, i)) &&
  4430. !mpdu_tried)
  4431. continue;
  4432. mpdus_tried--;
  4433. /* missed seq number */
  4434. seq_no = start_seq + i;
  4435. /*
  4436. * Fill failed MPDUs in AMPDU if they're
  4437. * available in subsequent PPDUs in current
  4438. * burst schedule. This is not applicable
  4439. * for non-QoS TIDs (no AMPDUs)
  4440. */
  4441. if (qdf_likely(user->tid != DP_NON_QOS_TID) &&
  4442. !(SEQ_BIT(user->failed_bitmap, i))) {
  4443. uint8_t seq_idx;
  4444. dp_tx_capture_debug("%pK:find seq %d in next ppdu %d",
  4445. pdev->soc, seq_no,
  4446. ppdu_desc_cnt);
  4447. mpdu_nbuf =
  4448. get_mpdu_clone_from_next_ppdu(
  4449. nbuf_ppdu_list +
  4450. desc_cnt,
  4451. ppdu_desc_cnt -
  4452. desc_cnt, seq_no,
  4453. user->peer_id,
  4454. ppdu_id, usr_idx);
  4455. seq_idx = seq_no - start_seq;
  4456. /* check mpdu_nbuf NULL */
  4457. if (!mpdu_nbuf) {
  4458. qdf_nbuf_t m_nbuf = NULL;
  4459. m_nbuf = user->mpdus[seq_idx];
  4460. CHECK_MPDUS_NULL(m_nbuf);
  4461. user->mpdus[seq_idx] = NULL;
  4462. user->pending_retries++;
  4463. continue;
  4464. }
  4465. dp_tx_cap_stats_mpdu_update(peer,
  4466. PEER_MPDU_CLONE, 1);
  4467. CHECK_MPDUS_NULL(user->mpdus[seq_idx]);
  4468. user->mpdus[seq_idx] = mpdu_nbuf;
  4469. SEQ_SEG(user->failed_bitmap, i) |=
  4470. SEQ_SEG_MSK(user->failed_bitmap[0], i);
  4471. } else {
  4472. qdf_nbuf_queue_t *tmp_q;
  4473. uint32_t index = 0;
  4474. tmp_q = &user->mpdu_q;
  4475. /* any error case we need to handle */
  4476. mpdu_nbuf =
  4477. qdf_nbuf_queue_remove(tmp_q);
  4478. /* check mpdu_nbuf NULL */
  4479. if (!mpdu_nbuf)
  4480. continue;
  4481. index = seq_no - start_seq;
  4482. CHECK_MPDUS_NULL(user->mpdus[index]);
  4483. user->mpdus[index] = mpdu_nbuf;
  4484. dp_tx_cap_stats_mpdu_update(peer,
  4485. PEER_MPDU_ARR, 1);
  4486. }
  4487. }
  4488. for (/* get i from previous stored value*/;
  4489. i < user->ba_size; i++) {
  4490. qdf_nbuf_queue_t *tmp_q;
  4491. /* missed seq number */
  4492. seq_no = start_seq + i;
  4493. tmp_q = &user->mpdu_q;
  4494. /* any error case we need to handle */
  4495. mpdu_nbuf = qdf_nbuf_queue_remove(tmp_q);
  4496. /* check mpdu_nbuf NULL */
  4497. if (!mpdu_nbuf)
  4498. continue;
  4499. user->mpdus[seq_no - start_seq] = mpdu_nbuf;
  4500. dp_tx_cap_stats_mpdu_update(peer,
  4501. PEER_MPDU_ARR, 1);
  4502. }
  4503. mpdu_tried = user->mpdu_tried_ucast +
  4504. user->mpdu_tried_mcast;
  4505. for (i = 0; i < CDP_BA_256_BIT_MAP_SIZE_DWORDS; i++)
  4506. mpdu_enq +=
  4507. get_number_of_1s(user->enq_bitmap[i]);
  4508. if (mpdu_tried > mpdu_enq)
  4509. dp_ppdu_desc_debug_print(ppdu_desc, usr_idx,
  4510. __func__, __LINE__);
  4511. /*
  4512. * It is possible that enq_bitmap received has
  4513. * more bits than actual mpdus tried if HW was
  4514. * unable to send all MPDUs, and last_enq_seq
  4515. * and ba_size should be adjusted in that case
  4516. */
  4517. if (i < user->ba_size) {
  4518. user->last_enq_seq = seq_no;
  4519. user->ba_size = seq_no - start_seq + 1;
  4520. }
  4521. DP_TX_PEER_DEL_REF(peer);
  4522. }
  4523. }
  4524. for (usr_idx = 0; usr_idx < max_num_users; usr_idx++) {
  4525. for (i = 0; i < ppdu_desc_cnt; i++) {
  4526. uint32_t pending_ppdus;
  4527. struct cdp_tx_completion_ppdu *cur_ppdu_desc;
  4528. struct cdp_tx_completion_ppdu_user *cur_user;
  4529. struct dp_peer *peer;
  4530. qdf_nbuf_queue_t head_ppdu;
  4531. uint16_t peer_id;
  4532. ptr_nbuf_list = &nbuf_ppdu_list[i];
  4533. if (!ptr_nbuf_list->nbuf_ppdu ||
  4534. !dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list))
  4535. continue;
  4536. cur_ppdu_desc = (struct cdp_tx_completion_ppdu *)
  4537. qdf_nbuf_data(ptr_nbuf_list->nbuf_ppdu);
  4538. if (!cur_ppdu_desc)
  4539. continue;
  4540. if (usr_idx >= cur_ppdu_desc->num_users)
  4541. continue;
  4542. cur_user = &cur_ppdu_desc->user[usr_idx];
  4543. if ((cur_user->delayed_ba == 1) ||
  4544. (cur_user->skip == 1) || (cur_user->mon_procd == 1))
  4545. continue;
  4546. peer_id = cur_ppdu_desc->user[usr_idx].peer_id;
  4547. peer = DP_TX_PEER_GET_REF(pdev, peer_id);
  4548. if (!peer) {
  4549. dp_ppdu_desc_free(ptr_nbuf_list, usr_idx);
  4550. continue;
  4551. }
  4552. if (!peer->tx_capture.is_tid_initialized) {
  4553. dp_ppdu_desc_free(ptr_nbuf_list, usr_idx);
  4554. DP_TX_PEER_DEL_REF(peer);
  4555. continue;
  4556. }
  4557. tx_tid = &peer->tx_capture.tx_tid[cur_user->tid];
  4558. qdf_nbuf_queue_init(&head_ppdu);
  4559. dp_tx_mon_proc_pending_ppdus(pdev, tx_tid,
  4560. nbuf_ppdu_list + i,
  4561. ppdu_desc_cnt - i,
  4562. &head_ppdu,
  4563. cur_user->peer_id,
  4564. usr_idx);
  4565. if (qdf_nbuf_is_queue_empty(&tx_tid->pending_ppdu_q)) {
  4566. while ((tmp_nbuf =
  4567. qdf_nbuf_queue_first(&head_ppdu))) {
  4568. cur_ppdu_desc =
  4569. (struct cdp_tx_completion_ppdu *)
  4570. qdf_nbuf_data(tmp_nbuf);
  4571. cur_user =
  4572. &cur_ppdu_desc->user[usr_idx];
  4573. if (cur_user->pending_retries)
  4574. break;
  4575. dp_send_data_to_stack(pdev,
  4576. cur_ppdu_desc,
  4577. usr_idx);
  4578. dp_ppdu_queue_free(tmp_nbuf, usr_idx);
  4579. qdf_nbuf_queue_remove(&head_ppdu);
  4580. qdf_nbuf_free(tmp_nbuf);
  4581. }
  4582. }
  4583. qdf_nbuf_queue_append(&tx_tid->pending_ppdu_q,
  4584. &head_ppdu);
  4585. dp_tx_mon_proc_xretries(pdev, peer, tx_tid->tid);
  4586. pending_ppdus =
  4587. qdf_nbuf_queue_len(&tx_tid->pending_ppdu_q);
  4588. if (pending_ppdus > MAX_PENDING_PPDUS) {
  4589. struct cdp_tx_completion_ppdu *tmp_ppdu_desc;
  4590. uint8_t tmp_usr_idx;
  4591. qdf_nbuf_queue_t *tmp_ppdu_q;
  4592. dp_tx_capture_err("%pK: pending ppdus (%d, %d) : %d\n",
  4593. pdev->soc, peer_id,
  4594. tx_tid->tid, pending_ppdus);
  4595. tmp_ppdu_q = &tx_tid->pending_ppdu_q;
  4596. tmp_nbuf = qdf_nbuf_queue_remove(tmp_ppdu_q);
  4597. if (qdf_unlikely(!tmp_nbuf)) {
  4598. DP_TX_PEER_DEL_REF(peer);
  4599. qdf_assert_always(0);
  4600. return;
  4601. }
  4602. tmp_ppdu_desc =
  4603. (struct cdp_tx_completion_ppdu *)
  4604. qdf_nbuf_data(tmp_nbuf);
  4605. tmp_usr_idx = dp_tx_find_usr_idx_from_peer_id(
  4606. tmp_ppdu_desc, peer_id);
  4607. dp_send_data_to_stack(pdev, tmp_ppdu_desc,
  4608. tmp_usr_idx);
  4609. dp_ppdu_queue_free(tmp_nbuf, tmp_usr_idx);
  4610. qdf_nbuf_free(tmp_nbuf);
  4611. pdev->tx_capture.pend_ppdu_dropped++;
  4612. }
  4613. DP_TX_PEER_DEL_REF(peer);
  4614. }
  4615. }
  4616. }
  4617. static uint32_t
  4618. dp_tx_cap_proc_per_ppdu_info(struct dp_pdev *pdev, qdf_nbuf_t nbuf_ppdu,
  4619. struct dp_tx_cap_nbuf_list nbuf_ppdu_list[],
  4620. uint32_t ppdu_desc_cnt)
  4621. {
  4622. struct dp_tx_cap_nbuf_list *ptr_nbuf_list;
  4623. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  4624. struct dp_peer *peer = NULL;
  4625. qdf_nbuf_queue_t head_msdu;
  4626. qdf_nbuf_queue_t head_xretries;
  4627. uint32_t retries = 0;
  4628. uint32_t ret = 0;
  4629. uint32_t start_tsf = 0;
  4630. uint32_t end_tsf = 0;
  4631. uint32_t bar_start_tsf = 0;
  4632. uint32_t bar_end_tsf = 0;
  4633. uint16_t tid = 0;
  4634. uint32_t num_msdu = 0;
  4635. uint32_t qlen = 0;
  4636. uint16_t peer_id;
  4637. uint8_t type, subtype;
  4638. uint8_t usr_idx;
  4639. bool is_bar_frm_with_data = false;
  4640. uint8_t usr_type;
  4641. uint8_t usr_subtype;
  4642. qdf_nbuf_queue_init(&head_msdu);
  4643. qdf_nbuf_queue_init(&head_xretries);
  4644. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(nbuf_ppdu);
  4645. type = (ppdu_desc->frame_ctrl &
  4646. IEEE80211_FC0_TYPE_MASK);
  4647. subtype = (ppdu_desc->frame_ctrl &
  4648. IEEE80211_FC0_SUBTYPE_MASK);
  4649. if ((type == IEEE80211_FC0_TYPE_DATA) &&
  4650. (subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL) &&
  4651. (ppdu_desc->htt_frame_type ==
  4652. HTT_STATS_FTYPE_TIDQ_DATA_SU)) {
  4653. ppdu_desc->htt_frame_type =
  4654. HTT_STATS_FTYPE_SGEN_QOS_NULL;
  4655. }
  4656. usr_type = (ppdu_desc->user[0].frame_ctrl &
  4657. IEEE80211_FC0_TYPE_MASK);
  4658. usr_subtype = (ppdu_desc->user[0].frame_ctrl &
  4659. IEEE80211_FC0_SUBTYPE_MASK);
  4660. if (((type == IEEE80211_FC0_TYPE_CTL) &&
  4661. (subtype == IEEE80211_FC0_SUBTYPE_BAR) &&
  4662. (usr_type == IEEE80211_FC0_TYPE_DATA)) ||
  4663. ppdu_desc->htt_frame_type == HTT_STATS_FTYPE_SGEN_MU_BAR)
  4664. is_bar_frm_with_data = true;
  4665. ptr_nbuf_list = &nbuf_ppdu_list[ppdu_desc_cnt];
  4666. /* ppdu start timestamp */
  4667. start_tsf = ppdu_desc->ppdu_start_timestamp;
  4668. end_tsf = ppdu_desc->ppdu_end_timestamp;
  4669. bar_start_tsf = ppdu_desc->bar_ppdu_start_timestamp;
  4670. bar_end_tsf = ppdu_desc->bar_ppdu_end_timestamp;
  4671. if (((ppdu_desc->frame_type == CDP_PPDU_FTYPE_DATA) &&
  4672. (ppdu_desc->htt_frame_type !=
  4673. HTT_STATS_FTYPE_SGEN_QOS_NULL)) ||
  4674. is_bar_frm_with_data) {
  4675. uint32_t mpdu_suc;
  4676. uint32_t mpdu_tri;
  4677. uint8_t ref_cnt = 0;
  4678. uint8_t num_users = ppdu_desc->num_users;
  4679. struct dp_tx_tid *tx_tid;
  4680. struct cdp_tx_completion_ppdu *xretry_ppdu;
  4681. struct cdp_tx_completion_ppdu_user *xretry_user;
  4682. struct cdp_tx_completion_ppdu_user *user;
  4683. qdf_nbuf_queue_t *mpdu_q;
  4684. qdf_nbuf_queue_t *x_mpdu_q;
  4685. for (usr_idx = 0; usr_idx < num_users;
  4686. usr_idx++) {
  4687. uint32_t ppdu_id;
  4688. peer = NULL;
  4689. user = &ppdu_desc->user[usr_idx];
  4690. if (usr_idx + 1 != num_users)
  4691. qdf_nbuf_ref(nbuf_ppdu);
  4692. if (user->delayed_ba == 1) {
  4693. user->skip = 1;
  4694. goto free_nbuf_dec_ref;
  4695. }
  4696. peer_id = user->peer_id;
  4697. peer = DP_TX_PEER_GET_REF(pdev, peer_id);
  4698. /**
  4699. * peer can be NULL
  4700. */
  4701. if (!peer || !peer->tx_capture.is_tid_initialized) {
  4702. user->skip = 1;
  4703. goto free_nbuf_dec_ref;
  4704. }
  4705. /**
  4706. * check whether it is bss peer,
  4707. * if bss_peer no need to process
  4708. * further check whether tx_capture
  4709. * feature is enabled for this peer
  4710. * or globally for all peers
  4711. */
  4712. if (peer->bss_peer ||
  4713. !dp_peer_or_pdev_tx_cap_enabled(pdev,
  4714. peer, peer->mac_addr.raw) || user->is_mcast) {
  4715. user->skip = 1;
  4716. goto free_nbuf_dec_ref;
  4717. }
  4718. /* update failed bitmap */
  4719. dp_process_ppdu_stats_update_failed_bitmap(
  4720. pdev, user, ppdu_desc->ppdu_id,
  4721. CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  4722. /* print the bit map */
  4723. dp_tx_print_bitmap(pdev, ppdu_desc,
  4724. usr_idx,
  4725. ppdu_desc->ppdu_id);
  4726. if (user->tid > DP_MAX_TIDS) {
  4727. dp_tx_capture_err("%pK: ppdu[%d] peer_id[%d] TID[%d] > NON_QOS_TID!",
  4728. pdev->soc,
  4729. ppdu_desc->ppdu_id,
  4730. user->peer_id,
  4731. user->tid);
  4732. user->skip = 1;
  4733. goto free_nbuf_dec_ref;
  4734. }
  4735. if (is_bar_frm_with_data)
  4736. ppdu_id = ppdu_desc->bar_ppdu_id;
  4737. else
  4738. ppdu_id = ppdu_desc->ppdu_id;
  4739. tid = user->tid;
  4740. num_msdu = user->num_msdu;
  4741. dequeue_msdu_again:
  4742. /*
  4743. * retrieve msdu buffer based on ppdu_id & tid
  4744. * based msdu queue and store it in local queue
  4745. * sometimes, wbm comes later than per ppdu
  4746. * stats. Assumption: all packets are SU,
  4747. * and packets comes in order
  4748. */
  4749. ret = dp_tx_msdu_dequeue(peer,
  4750. ppdu_id,
  4751. tid,
  4752. num_msdu,
  4753. &head_msdu,
  4754. &head_xretries,
  4755. start_tsf,
  4756. end_tsf);
  4757. if (!ret && (++retries < 2)) {
  4758. /* wait for wbm to complete */
  4759. qdf_mdelay(2);
  4760. goto dequeue_msdu_again;
  4761. }
  4762. /*
  4763. * restitch mpdu from xretry msdu
  4764. * xretry msdu queue empty check is
  4765. * done inside restitch function
  4766. */
  4767. tx_tid = &peer->tx_capture.tx_tid[tid];
  4768. xretry_ppdu = tx_tid->xretry_ppdu;
  4769. xretry_user = &xretry_ppdu->user[0];
  4770. xretry_ppdu->ppdu_id =
  4771. peer->tx_capture.tx_wifi_ppdu_id;
  4772. x_mpdu_q = &xretry_user->mpdu_q;
  4773. /* Restitch MPDUs from xretry MSDUs */
  4774. dp_tx_mon_restitch_mpdu(pdev, peer,
  4775. xretry_ppdu,
  4776. &head_xretries,
  4777. x_mpdu_q, 0);
  4778. qlen = qdf_nbuf_queue_len(x_mpdu_q);
  4779. dp_tx_cap_stats_mpdu_update(peer, PEER_MPDU_RESTITCH,
  4780. qlen);
  4781. if (qdf_nbuf_is_queue_empty(
  4782. &head_msdu)) {
  4783. if (user->completion_status == 2)
  4784. goto nbuf_add_ref;
  4785. user->skip = 1;
  4786. goto free_nbuf_dec_ref;
  4787. }
  4788. mpdu_q = &user->mpdu_q;
  4789. /*
  4790. * now head_msdu hold - msdu list for
  4791. * that particular ppdu_id, restitch
  4792. * mpdu from msdu and create a mpdu
  4793. * queue
  4794. */
  4795. dp_tx_mon_restitch_mpdu(pdev,
  4796. peer,
  4797. ppdu_desc,
  4798. &head_msdu,
  4799. mpdu_q,
  4800. usr_idx);
  4801. /*
  4802. * sanity: free local head msdu queue
  4803. * do we need this ?
  4804. */
  4805. TX_CAP_NBUF_QUEUE_FREE(&head_msdu);
  4806. qlen = qdf_nbuf_queue_len(mpdu_q);
  4807. dp_tx_cap_stats_mpdu_update(peer, PEER_MPDU_RESTITCH,
  4808. qlen);
  4809. if (!qlen) {
  4810. user->skip = 1;
  4811. dp_ppdu_queue_free(nbuf_ppdu,
  4812. usr_idx);
  4813. goto free_nbuf_dec_ref;
  4814. }
  4815. mpdu_suc = user->mpdu_success;
  4816. mpdu_tri = user->mpdu_tried_ucast +
  4817. user->mpdu_tried_mcast;
  4818. /* print ppdu_desc info for debugging purpose */
  4819. dp_tx_capture_info("%pK: ppdu[%d] b_ppdu_id[%d] p_id[%d], tid[%d], n_mpdu[%d %d] n_msdu[%d] retr[%d] qlen[%d] tsf[%u - %u] b_tsf[%u - %u] dur[%u] seq[%d] ppdu_desc_cnt[%d]",
  4820. pdev->soc,
  4821. ppdu_desc->ppdu_id,
  4822. ppdu_desc->bar_ppdu_id,
  4823. user->peer_id,
  4824. user->tid,
  4825. ppdu_desc->num_mpdu,
  4826. mpdu_suc,
  4827. ppdu_desc->num_msdu, retries,
  4828. qlen,
  4829. start_tsf, end_tsf,
  4830. bar_start_tsf, bar_end_tsf,
  4831. ppdu_desc->tx_duration,
  4832. user->start_seq,
  4833. ppdu_desc_cnt);
  4834. dp_tx_cap_stats_mpdu_update(peer, PEER_MPDU_SUCC,
  4835. mpdu_suc);
  4836. dp_tx_cap_stats_mpdu_update(peer, PEER_MPDU_TRI,
  4837. mpdu_tri);
  4838. nbuf_add_ref:
  4839. DP_TX_PEER_DEL_REF(peer);
  4840. /* get reference count */
  4841. ref_cnt = qdf_nbuf_get_users(nbuf_ppdu);
  4842. continue;
  4843. free_nbuf_dec_ref:
  4844. /* get reference before free */
  4845. ref_cnt = qdf_nbuf_get_users(nbuf_ppdu);
  4846. qdf_nbuf_free(nbuf_ppdu);
  4847. ref_cnt--;
  4848. if (peer)
  4849. DP_TX_PEER_DEL_REF(peer);
  4850. continue;
  4851. }
  4852. if (ref_cnt == 0)
  4853. return ppdu_desc_cnt;
  4854. ptr_nbuf_list->nbuf_ppdu = nbuf_ppdu;
  4855. dp_tx_cap_nbuf_list_update_ref(ptr_nbuf_list, ref_cnt);
  4856. ppdu_desc_cnt++;
  4857. } else {
  4858. /*
  4859. * other packet frame also added to
  4860. * descriptor list
  4861. */
  4862. /* print ppdu_desc info for debugging purpose */
  4863. dp_tx_capture_info("%pK: ppdu[%d], p_id[%d], tid[%d], fctrl[0x%x 0x%x] ftype[%d] h_frm_t[%d] seq[%d] tsf[%llu b %u] dur[%u]",
  4864. pdev->soc, ppdu_desc->ppdu_id,
  4865. ppdu_desc->user[0].peer_id,
  4866. ppdu_desc->user[0].tid,
  4867. ppdu_desc->frame_ctrl,
  4868. ppdu_desc->user[0].frame_ctrl,
  4869. ppdu_desc->frame_type,
  4870. ppdu_desc->htt_frame_type,
  4871. ppdu_desc->user[0].start_seq,
  4872. ppdu_desc->ppdu_start_timestamp,
  4873. ppdu_desc->bar_ppdu_start_timestamp,
  4874. ppdu_desc->tx_duration);
  4875. ptr_nbuf_list->nbuf_ppdu = nbuf_ppdu;
  4876. dp_tx_cap_nbuf_list_update_ref(ptr_nbuf_list,
  4877. 1);
  4878. ppdu_desc_cnt++;
  4879. }
  4880. return ppdu_desc_cnt;
  4881. }
  4882. /*
  4883. * dp_pdev_tx_cap_flush() - flush pdev queue and peer queue
  4884. * @pdev: Datapath pdev
  4885. * @is_stats_queue_empty: stats queue status
  4886. *
  4887. * return: void
  4888. */
  4889. static void
  4890. dp_pdev_tx_cap_flush(struct dp_pdev *pdev, bool is_stats_queue_empty)
  4891. {
  4892. struct dp_pdev_tx_capture *ptr_tx_cap = &pdev->tx_capture;
  4893. struct dp_pdev_flush flush = {0};
  4894. uint32_t now_ms = 0;
  4895. uint32_t delta_ms = 0;
  4896. uint32_t i = 0, j = 0;
  4897. now_ms = qdf_system_ticks_to_msecs(qdf_system_ticks());
  4898. delta_ms = now_ms - ptr_tx_cap->last_processed_ms;
  4899. /*
  4900. * check difference is more than 3 sec and stats queue is empty
  4901. * then invoke flush all else, check if difference is more
  4902. * than 1.5 second invoke peer check to free unflushed queue
  4903. */
  4904. if (delta_ms > TX_CAPTURE_NO_PPDU_DESC_MS && is_stats_queue_empty)
  4905. flush.flush_all = true;
  4906. else if (delta_ms > TX_CAPTURE_PEER_CHECK_MS && !is_stats_queue_empty)
  4907. flush.flush_all = false;
  4908. else
  4909. return;
  4910. /* update last process ppdu stats queue with current msec */
  4911. ptr_tx_cap->last_processed_ms = now_ms;
  4912. flush.now_ms = now_ms;
  4913. /*
  4914. * iterate over peer and flush the unreleased queue
  4915. * which is in queue without processing.
  4916. */
  4917. dp_pdev_iterate_peer(pdev, dp_peer_tx_cap_tid_queue_flush,
  4918. &flush, DP_MOD_ID_TX_CAPTURE);
  4919. /* free mgmt packet */
  4920. for (i = 0; i < TXCAP_MAX_TYPE; i++) {
  4921. for (j = 0; j < TXCAP_MAX_SUBTYPE; j++) {
  4922. qdf_nbuf_queue_t *retries_q;
  4923. qdf_spin_lock_bh(
  4924. &pdev->tx_capture.ctl_mgmt_lock[i][j]);
  4925. TX_CAP_NBUF_QUEUE_FREE(
  4926. &pdev->tx_capture.ctl_mgmt_q[i][j]);
  4927. qdf_spin_unlock_bh(
  4928. &pdev->tx_capture.ctl_mgmt_lock[i][j]);
  4929. /*
  4930. * no lock required for retries ctrl mgmt queue
  4931. * as it is used only in workqueue function.
  4932. */
  4933. retries_q = &pdev->tx_capture.retries_ctl_mgmt_q[i][j];
  4934. if (!qdf_nbuf_is_queue_empty(retries_q))
  4935. TX_CAP_NBUF_QUEUE_FREE(retries_q);
  4936. }
  4937. }
  4938. /* increment flush counter */
  4939. pdev->tx_capture.ppdu_flush_count++;
  4940. dp_tx_capture_info("now_ms[%u] proc_ms[%u] delta[%u] stats_Q[%d]\n",
  4941. now_ms,
  4942. ptr_tx_cap->last_processed_ms,
  4943. delta_ms, is_stats_queue_empty);
  4944. }
  4945. /**
  4946. * dp_tx_ppdu_stats_process - Deferred PPDU stats handler
  4947. * @context: Opaque work context (PDEV)
  4948. *
  4949. * Return: none
  4950. */
  4951. void dp_tx_ppdu_stats_process(void *context)
  4952. {
  4953. uint32_t curr_sched_cmdid;
  4954. uint32_t last_ppdu_id;
  4955. uint32_t ppdu_cnt;
  4956. uint32_t ppdu_desc_cnt = 0;
  4957. struct dp_pdev *pdev = (struct dp_pdev *)context;
  4958. struct ppdu_info *ppdu_info, *tmp_ppdu_info = NULL;
  4959. struct ppdu_info *sched_ppdu_info = NULL;
  4960. STAILQ_HEAD(, ppdu_info) sched_ppdu_queue;
  4961. struct ppdu_info *sched_ppdu_list_last_ptr;
  4962. struct dp_tx_cap_nbuf_list *nbuf_ppdu_list;
  4963. struct dp_tx_cap_nbuf_list *ptr_nbuf_list;
  4964. qdf_nbuf_t tmp_nbuf;
  4965. qdf_nbuf_t nbuf_ppdu;
  4966. struct dp_pdev_tx_capture *ptr_tx_cap = &pdev->tx_capture;
  4967. size_t nbuf_list_sz;
  4968. uint8_t user_mode;
  4969. bool is_stats_queue_empty = false;
  4970. STAILQ_INIT(&sched_ppdu_queue);
  4971. /* Move the PPDU entries to defer list */
  4972. qdf_spin_lock_bh(&ptr_tx_cap->ppdu_stats_lock);
  4973. STAILQ_CONCAT(&ptr_tx_cap->ppdu_stats_defer_queue,
  4974. &ptr_tx_cap->ppdu_stats_queue);
  4975. ptr_tx_cap->ppdu_stats_defer_queue_depth +=
  4976. ptr_tx_cap->ppdu_stats_queue_depth;
  4977. ptr_tx_cap->ppdu_stats_queue_depth = 0;
  4978. qdf_spin_unlock_bh(&ptr_tx_cap->ppdu_stats_lock);
  4979. is_stats_queue_empty =
  4980. STAILQ_EMPTY(&ptr_tx_cap->ppdu_stats_defer_queue);
  4981. /*
  4982. * if any chance defer queue is empty, mode change
  4983. * check need to be done
  4984. */
  4985. if (is_stats_queue_empty) {
  4986. /* get user mode */
  4987. user_mode = qdf_atomic_read(&pdev->tx_capture.tx_cap_usr_mode);
  4988. /*
  4989. * invoke mode change if user mode value is
  4990. * different from driver mode value,
  4991. * this was done to reduce config lock
  4992. */
  4993. if (user_mode != pdev->tx_capture_enabled)
  4994. dp_enh_tx_cap_mode_change(pdev, user_mode);
  4995. }
  4996. /*
  4997. * check and flush any pending queue and release queue if it
  4998. * get build up
  4999. */
  5000. if (pdev->tx_capture_enabled != CDP_TX_ENH_CAPTURE_DISABLED)
  5001. dp_pdev_tx_cap_flush(pdev, is_stats_queue_empty);
  5002. while (!STAILQ_EMPTY(&ptr_tx_cap->ppdu_stats_defer_queue)) {
  5003. ppdu_info =
  5004. STAILQ_FIRST(&ptr_tx_cap->ppdu_stats_defer_queue);
  5005. curr_sched_cmdid = ppdu_info->sched_cmdid;
  5006. ppdu_cnt = 0;
  5007. STAILQ_FOREACH_SAFE(ppdu_info,
  5008. &ptr_tx_cap->ppdu_stats_defer_queue,
  5009. ppdu_info_queue_elem, tmp_ppdu_info) {
  5010. if (curr_sched_cmdid != ppdu_info->sched_cmdid)
  5011. break;
  5012. sched_ppdu_list_last_ptr = ppdu_info;
  5013. ppdu_cnt++;
  5014. }
  5015. if (ppdu_info && (curr_sched_cmdid == ppdu_info->sched_cmdid))
  5016. break;
  5017. last_ppdu_id = sched_ppdu_list_last_ptr->ppdu_id;
  5018. STAILQ_FIRST(&sched_ppdu_queue) =
  5019. STAILQ_FIRST(&ptr_tx_cap->ppdu_stats_defer_queue);
  5020. STAILQ_REMOVE_HEAD_UNTIL(&ptr_tx_cap->ppdu_stats_defer_queue,
  5021. sched_ppdu_list_last_ptr,
  5022. ppdu_info_queue_elem);
  5023. STAILQ_NEXT(sched_ppdu_list_last_ptr,
  5024. ppdu_info_queue_elem) = NULL;
  5025. ptr_tx_cap->ppdu_stats_defer_queue_depth -= ppdu_cnt;
  5026. nbuf_list_sz = sizeof(struct dp_tx_cap_nbuf_list);
  5027. nbuf_ppdu_list = (struct dp_tx_cap_nbuf_list *)
  5028. qdf_mem_malloc(nbuf_list_sz * ppdu_cnt);
  5029. /*
  5030. * if there is no memory allocated we need to free sched ppdu
  5031. * list, no ppdu stats will be updated.
  5032. */
  5033. if (!nbuf_ppdu_list) {
  5034. STAILQ_FOREACH_SAFE(sched_ppdu_info,
  5035. &sched_ppdu_queue,
  5036. ppdu_info_queue_elem,
  5037. tmp_ppdu_info) {
  5038. ppdu_info = sched_ppdu_info;
  5039. tmp_nbuf = ppdu_info->nbuf;
  5040. qdf_mem_free(ppdu_info);
  5041. qdf_nbuf_free(tmp_nbuf);
  5042. }
  5043. continue;
  5044. }
  5045. /*
  5046. * value stored for debugging purpose to get info
  5047. * for debugging purpose.
  5048. */
  5049. ptr_tx_cap->last_nbuf_ppdu_list = nbuf_ppdu_list;
  5050. ptr_tx_cap->last_nbuf_ppdu_list_arr_sz = ppdu_cnt;
  5051. ptr_tx_cap->last_processed_ms =
  5052. qdf_system_ticks_to_msecs(qdf_system_ticks());
  5053. ppdu_desc_cnt = 0;
  5054. STAILQ_FOREACH_SAFE(sched_ppdu_info,
  5055. &sched_ppdu_queue,
  5056. ppdu_info_queue_elem, tmp_ppdu_info) {
  5057. ppdu_info = sched_ppdu_info;
  5058. pdev->stats.tx_ppdu_proc++;
  5059. /* update ppdu desc user stats */
  5060. dp_ppdu_desc_user_stats_update(pdev, ppdu_info);
  5061. /*
  5062. * While processing/corelating Tx buffers, we should
  5063. * hold the entire PPDU list for the give sched_cmdid
  5064. * instead of freeing below.
  5065. */
  5066. nbuf_ppdu = ppdu_info->nbuf;
  5067. qdf_mem_free(ppdu_info);
  5068. qdf_assert_always(nbuf_ppdu);
  5069. /* check tx capture disable */
  5070. if (pdev->tx_capture_enabled ==
  5071. CDP_TX_ENH_CAPTURE_DISABLED) {
  5072. struct cdp_tx_completion_ppdu *ppdu_desc;
  5073. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  5074. qdf_nbuf_data(nbuf_ppdu);
  5075. /**
  5076. * Deliver PPDU stats only for valid (acked)
  5077. * data frames if sniffer mode is not enabled.
  5078. * If sniffer mode is enabled,
  5079. * PPDU stats for all frames including
  5080. * mgmt/control frames should be delivered
  5081. * to upper layer
  5082. */
  5083. if (pdev->tx_sniffer_enable ||
  5084. pdev->mcopy_mode) {
  5085. dp_wdi_event_handler(
  5086. WDI_EVENT_TX_PPDU_DESC,
  5087. pdev->soc,
  5088. nbuf_ppdu,
  5089. HTT_INVALID_PEER,
  5090. WDI_NO_VAL,
  5091. pdev->pdev_id);
  5092. } else {
  5093. if (ppdu_desc->num_mpdu != 0 &&
  5094. ppdu_desc->num_users != 0 &&
  5095. (ppdu_desc->frame_ctrl &
  5096. HTT_FRAMECTRL_DATATYPE)) {
  5097. dp_wdi_event_handler(
  5098. WDI_EVENT_TX_PPDU_DESC,
  5099. pdev->soc,
  5100. nbuf_ppdu,
  5101. HTT_INVALID_PEER,
  5102. WDI_NO_VAL,
  5103. pdev->pdev_id);
  5104. } else {
  5105. qdf_nbuf_free(nbuf_ppdu);
  5106. }
  5107. }
  5108. continue;
  5109. } else {
  5110. tx_cap_debugfs_log_ppdu_desc(pdev, nbuf_ppdu);
  5111. /* process ppdu_info on tx capture turned on */
  5112. ppdu_desc_cnt = dp_tx_cap_proc_per_ppdu_info(
  5113. pdev,
  5114. nbuf_ppdu,
  5115. nbuf_ppdu_list,
  5116. ppdu_desc_cnt);
  5117. }
  5118. }
  5119. /*
  5120. * At this point we have mpdu queued per ppdu_desc
  5121. * based on packet capture flags send mpdu info to upper stack
  5122. */
  5123. if (ppdu_desc_cnt) {
  5124. uint32_t i;
  5125. dp_check_ppdu_and_deliver(pdev, nbuf_ppdu_list,
  5126. ppdu_desc_cnt);
  5127. for (i = 0; i < ppdu_desc_cnt; i++) {
  5128. ptr_nbuf_list = &nbuf_ppdu_list[i];
  5129. if (dp_tx_cap_nbuf_list_get_ref(
  5130. ptr_nbuf_list)) {
  5131. dp_tx_capture_alert("%pK: missing handling of ppdu_desc ref_cnt:%d ,i : %d ptr %p, ppdu_desc_cnt %d!!!\n",
  5132. pdev->soc,
  5133. ptr_nbuf_list->ref_cnt, i, ptr_nbuf_list, ppdu_desc_cnt);
  5134. QDF_BUG(0);
  5135. }
  5136. }
  5137. }
  5138. qdf_mem_free(nbuf_ppdu_list);
  5139. /* get user mode */
  5140. user_mode = qdf_atomic_read(&pdev->tx_capture.tx_cap_usr_mode);
  5141. /*
  5142. * invoke mode change if user mode value is
  5143. * different from driver mode value,
  5144. * this was done to reduce config lock
  5145. */
  5146. if (user_mode != pdev->tx_capture_enabled)
  5147. dp_enh_tx_cap_mode_change(pdev, user_mode);
  5148. }
  5149. }
  5150. /**
  5151. * dp_ppdu_desc_deliver(): Function to deliver Tx PPDU status descriptor
  5152. * to upper layer
  5153. * @pdev: DP pdev handle
  5154. * @ppdu_info: per PPDU TLV descriptor
  5155. *
  5156. * return: void
  5157. */
  5158. void dp_ppdu_desc_deliver(struct dp_pdev *pdev,
  5159. struct ppdu_info *ppdu_info)
  5160. {
  5161. struct ppdu_info *s_ppdu_info = NULL;
  5162. struct ppdu_info *ppdu_info_next = NULL;
  5163. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  5164. uint32_t time_delta = 0;
  5165. bool starved = 0;
  5166. bool matched = 0;
  5167. bool recv_ack_ba_done = 0;
  5168. if (ppdu_info->tlv_bitmap & (1 << HTT_PPDU_STATS_USR_COMPLTN_ACK_BA_STATUS_TLV) && ppdu_info->done)
  5169. recv_ack_ba_done = 1;
  5170. pdev->last_sched_cmdid = ppdu_info->sched_cmdid;
  5171. s_ppdu_info = TAILQ_FIRST(&pdev->sched_comp_ppdu_list);
  5172. TAILQ_FOREACH_SAFE(s_ppdu_info, &pdev->sched_comp_ppdu_list,
  5173. ppdu_info_list_elem, ppdu_info_next) {
  5174. if (s_ppdu_info->tsf_l32 > ppdu_info->tsf_l32)
  5175. time_delta = (MAX_TSF_32 - s_ppdu_info->tsf_l32) +
  5176. ppdu_info->tsf_l32;
  5177. else
  5178. time_delta = ppdu_info->tsf_l32 - s_ppdu_info->tsf_l32;
  5179. if (!s_ppdu_info->done && !recv_ack_ba_done) {
  5180. if (time_delta < MAX_SCHED_STARVE) {
  5181. dp_tx_capture_info("%pK: pdev[%d] ppdu_id[0x%x %d] sched_cmdid[0x%x %d] TLV_B[0x%x] TSF[%u] D[%d]",
  5182. pdev->soc, pdev->pdev_id,
  5183. s_ppdu_info->ppdu_id, s_ppdu_info->ppdu_id,
  5184. s_ppdu_info->sched_cmdid, s_ppdu_info->sched_cmdid,
  5185. s_ppdu_info->tlv_bitmap, s_ppdu_info->tsf_l32,
  5186. s_ppdu_info->done);
  5187. break;
  5188. } else {
  5189. starved = 1;
  5190. }
  5191. }
  5192. pdev->delivered_sched_cmdid = s_ppdu_info->sched_cmdid;
  5193. TAILQ_REMOVE(&pdev->sched_comp_ppdu_list, s_ppdu_info,
  5194. ppdu_info_list_elem);
  5195. pdev->sched_comp_list_depth--;
  5196. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  5197. qdf_nbuf_data(s_ppdu_info->nbuf);
  5198. ppdu_desc->tlv_bitmap = s_ppdu_info->tlv_bitmap;
  5199. ppdu_desc->sched_cmdid = ppdu_info->sched_cmdid;
  5200. if (starved) {
  5201. dp_tx_capture_info("%pK: ppdu starved fc[0x%x] h_ftype[%d] tlv_bitmap[0x%x] cs[%d]\n",
  5202. pdev->soc, ppdu_desc->frame_ctrl,
  5203. ppdu_desc->htt_frame_type,
  5204. ppdu_desc->tlv_bitmap,
  5205. ppdu_desc->user[0].completion_status);
  5206. starved = 0;
  5207. }
  5208. if (ppdu_info->ppdu_id == s_ppdu_info->ppdu_id &&
  5209. ppdu_info->sched_cmdid == s_ppdu_info->sched_cmdid)
  5210. matched = 1;
  5211. dp_tx_capture_info("%pK: pdev[%d] vdev[%d] ppdu_id[0x%x %d] sched_cmdid[0x%x %d] FC[0x%x] H_FTYPE[0x%x] TLV_B[0x%x] TSF[%u] cs[%d] M[%d] R_PID[%d S %d]",
  5212. pdev->soc, pdev->pdev_id, ppdu_desc->vdev_id,
  5213. s_ppdu_info->ppdu_id, s_ppdu_info->ppdu_id,
  5214. s_ppdu_info->sched_cmdid, s_ppdu_info->sched_cmdid,
  5215. ppdu_desc->frame_ctrl,
  5216. ppdu_desc->htt_frame_type,
  5217. ppdu_desc->tlv_bitmap, s_ppdu_info->tsf_l32,
  5218. ppdu_desc->user[0].completion_status, matched,
  5219. ppdu_info->ppdu_id, ppdu_info->sched_cmdid);
  5220. qdf_spin_lock_bh(&pdev->tx_capture.ppdu_stats_lock);
  5221. if (qdf_unlikely(!pdev->tx_capture_enabled &&
  5222. (pdev->tx_capture.ppdu_stats_queue_depth +
  5223. pdev->tx_capture.ppdu_stats_defer_queue_depth) >
  5224. DP_TX_PPDU_PROC_MAX_DEPTH)) {
  5225. qdf_nbuf_free(s_ppdu_info->nbuf);
  5226. qdf_mem_free(s_ppdu_info);
  5227. pdev->tx_capture.ppdu_dropped++;
  5228. } else {
  5229. STAILQ_INSERT_TAIL(&pdev->tx_capture.ppdu_stats_queue,
  5230. s_ppdu_info, ppdu_info_queue_elem);
  5231. pdev->tx_capture.ppdu_stats_queue_depth++;
  5232. }
  5233. qdf_spin_unlock_bh(&pdev->tx_capture.ppdu_stats_lock);
  5234. if (matched)
  5235. break;
  5236. }
  5237. /* update timestamp of last received ppdu stats tlv */
  5238. pdev->tx_capture.ppdu_stats_ms =
  5239. qdf_system_ticks_to_msecs(qdf_system_ticks());
  5240. if (pdev->tx_capture.ppdu_stats_queue_depth >
  5241. DP_TX_PPDU_PROC_THRESHOLD) {
  5242. qdf_queue_work(0, pdev->tx_capture.ppdu_stats_workqueue,
  5243. &pdev->tx_capture.ppdu_stats_work);
  5244. }
  5245. qdf_timer_mod(&pdev->tx_capture.work_q_timer,
  5246. TX_CAPTURE_WORK_Q_TIMER_MS);
  5247. }
  5248. static void set_mpdu_info(
  5249. struct cdp_tx_indication_info *tx_capture_info,
  5250. struct mon_rx_status *rx_status,
  5251. struct mon_rx_user_status *rx_user_status)
  5252. {
  5253. struct cdp_tx_indication_mpdu_info *mpdu_info;
  5254. qdf_mem_set(tx_capture_info,
  5255. sizeof(struct cdp_tx_indication_info), 0);
  5256. mpdu_info = &tx_capture_info->mpdu_info;
  5257. mpdu_info->ppdu_start_timestamp = rx_status->tsft + 16;
  5258. mpdu_info->channel_num = rx_status->chan_num;
  5259. mpdu_info->channel = rx_status->chan_freq;
  5260. mpdu_info->bw = 0;
  5261. if (rx_status->preamble_type == HAL_RX_PKT_TYPE_11B) {
  5262. mpdu_info->preamble = DOT11_B;
  5263. mpdu_info->mcs = CDP_LEGACY_MCS3;
  5264. } else if (rx_status->preamble_type == HAL_RX_PKT_TYPE_11A) {
  5265. mpdu_info->preamble = DOT11_A;
  5266. mpdu_info->mcs = CDP_LEGACY_MCS3;
  5267. } else {
  5268. mpdu_info->preamble = DOT11_A;
  5269. mpdu_info->mcs = CDP_LEGACY_MCS1;
  5270. }
  5271. }
  5272. static void dp_gen_ack_frame(struct hal_rx_ppdu_info *ppdu_info,
  5273. struct dp_peer *peer,
  5274. qdf_nbuf_t mpdu_nbuf)
  5275. {
  5276. struct ieee80211_frame_min_one *wh_addr1;
  5277. wh_addr1 = (struct ieee80211_frame_min_one *)
  5278. qdf_nbuf_data(mpdu_nbuf);
  5279. wh_addr1->i_fc[0] = 0;
  5280. wh_addr1->i_fc[1] = 0;
  5281. wh_addr1->i_fc[0] = IEEE80211_FC0_VERSION_0 |
  5282. IEEE80211_FC0_TYPE_CTL |
  5283. IEEE80211_FC0_SUBTYPE_ACK;
  5284. if (peer) {
  5285. qdf_mem_copy(wh_addr1->i_addr1,
  5286. &peer->mac_addr.raw[0],
  5287. QDF_MAC_ADDR_SIZE);
  5288. } else {
  5289. qdf_mem_copy(wh_addr1->i_addr1,
  5290. &ppdu_info->nac_info.mac_addr2[0],
  5291. QDF_MAC_ADDR_SIZE);
  5292. }
  5293. *(u_int16_t *)(&wh_addr1->i_dur) = qdf_cpu_to_le16(0x0000);
  5294. qdf_nbuf_set_pktlen(mpdu_nbuf, sizeof(*wh_addr1));
  5295. }
  5296. static void dp_gen_block_ack_frame(
  5297. struct hal_rx_ppdu_info *ppdu_info,
  5298. struct mon_rx_user_status *rx_user_status,
  5299. struct mon_rx_user_info *rx_user_info,
  5300. struct dp_peer *peer,
  5301. qdf_nbuf_t mpdu_nbuf)
  5302. {
  5303. struct dp_vdev *vdev = NULL;
  5304. uint32_t tid;
  5305. struct dp_tx_tid *tx_tid;
  5306. struct ieee80211_ctlframe_addr2 *wh_addr2;
  5307. uint8_t *frm;
  5308. tid = rx_user_status->tid;
  5309. tx_tid = &peer->tx_capture.tx_tid[tid];
  5310. if (ppdu_info->sw_frame_group_id != HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR) {
  5311. tx_tid->first_data_seq_ctrl =
  5312. rx_user_status->first_data_seq_ctrl;
  5313. tx_tid->mpdu_cnt = rx_user_status->mpdu_cnt_fcs_ok +
  5314. rx_user_status->mpdu_cnt_fcs_err;
  5315. if (tx_tid->mpdu_cnt > DP_MAX_MPDU_64)
  5316. qdf_mem_copy(tx_tid->mpdu_fcs_ok_bitmap,
  5317. rx_user_status->mpdu_fcs_ok_bitmap,
  5318. HAL_RX_NUM_WORDS_PER_PPDU_BITMAP * sizeof(
  5319. rx_user_status->mpdu_fcs_ok_bitmap[0]));
  5320. else
  5321. qdf_mem_copy(tx_tid->mpdu_fcs_ok_bitmap,
  5322. rx_user_status->mpdu_fcs_ok_bitmap,
  5323. DP_NUM_WORDS_PER_PPDU_BITMAP_64 * sizeof(
  5324. rx_user_status->mpdu_fcs_ok_bitmap[0]));
  5325. }
  5326. wh_addr2 = (struct ieee80211_ctlframe_addr2 *)
  5327. qdf_nbuf_data(mpdu_nbuf);
  5328. qdf_mem_zero(wh_addr2, DP_BA_ACK_FRAME_SIZE);
  5329. wh_addr2->i_fc[0] = 0;
  5330. wh_addr2->i_fc[1] = 0;
  5331. wh_addr2->i_fc[0] = IEEE80211_FC0_VERSION_0 |
  5332. IEEE80211_FC0_TYPE_CTL |
  5333. IEEE80211_FC0_BLOCK_ACK;
  5334. *(u_int16_t *)(&wh_addr2->i_aidordur) = qdf_cpu_to_le16(0x0000);
  5335. vdev = peer->vdev;
  5336. if (vdev)
  5337. qdf_mem_copy(wh_addr2->i_addr2, vdev->mac_addr.raw,
  5338. QDF_MAC_ADDR_SIZE);
  5339. qdf_mem_copy(wh_addr2->i_addr1, &peer->mac_addr.raw[0],
  5340. QDF_MAC_ADDR_SIZE);
  5341. frm = (uint8_t *)&wh_addr2[1];
  5342. *((uint16_t *)frm) =
  5343. qdf_cpu_to_le16((rx_user_status->tid <<
  5344. DP_IEEE80211_BAR_CTL_TID_S) |
  5345. DP_IEEE80211_BAR_CTL_COMBA);
  5346. frm += 2;
  5347. *((uint16_t *)frm) =
  5348. tx_tid->first_data_seq_ctrl;
  5349. frm += 2;
  5350. if (tx_tid->mpdu_cnt > DP_MAX_MPDU_64) {
  5351. qdf_mem_copy(frm,
  5352. tx_tid->mpdu_fcs_ok_bitmap,
  5353. HAL_RX_NUM_WORDS_PER_PPDU_BITMAP *
  5354. sizeof(rx_user_status->mpdu_fcs_ok_bitmap[0]));
  5355. frm += DP_NUM_BYTES_PER_PPDU_BITMAP;
  5356. } else {
  5357. qdf_mem_copy(frm,
  5358. tx_tid->mpdu_fcs_ok_bitmap,
  5359. DP_NUM_WORDS_PER_PPDU_BITMAP_64 *
  5360. sizeof(rx_user_status->mpdu_fcs_ok_bitmap[0]));
  5361. frm += DP_NUM_BYTES_PER_PPDU_BITMAP_64;
  5362. }
  5363. qdf_nbuf_set_pktlen(mpdu_nbuf,
  5364. (frm - (uint8_t *)qdf_nbuf_data(mpdu_nbuf)));
  5365. }
  5366. static void dp_gen_cts_frame(struct hal_rx_ppdu_info *ppdu_info,
  5367. struct dp_peer *peer,
  5368. qdf_nbuf_t mpdu_nbuf)
  5369. {
  5370. struct ieee80211_frame_min_one *wh_addr1;
  5371. uint16_t duration;
  5372. wh_addr1 = (struct ieee80211_frame_min_one *)
  5373. qdf_nbuf_data(mpdu_nbuf);
  5374. wh_addr1->i_fc[0] = 0;
  5375. wh_addr1->i_fc[1] = 0;
  5376. wh_addr1->i_fc[0] = IEEE80211_FC0_VERSION_0 |
  5377. IEEE80211_FC0_TYPE_CTL |
  5378. IEEE80211_FC0_SUBTYPE_CTS;
  5379. qdf_mem_copy(wh_addr1->i_addr1, &peer->mac_addr.raw[0],
  5380. QDF_MAC_ADDR_SIZE);
  5381. duration = (ppdu_info->rx_status.duration > SIFS_INTERVAL) ?
  5382. ppdu_info->rx_status.duration - SIFS_INTERVAL : 0;
  5383. wh_addr1->i_dur[0] = duration & 0xff;
  5384. wh_addr1->i_dur[1] = (duration >> 8) & 0xff;
  5385. qdf_nbuf_set_pktlen(mpdu_nbuf, sizeof(*wh_addr1));
  5386. }
  5387. /**
  5388. * dp_send_cts_frame_to_stack(): Function to deliver HW generated CTS frame
  5389. * in reponse to RTS
  5390. * @soc: core txrx main context
  5391. * @pdev: DP pdev object
  5392. * @ppdu_info: HAL RX PPDU info retrieved from status ring TLV
  5393. *
  5394. * return: status
  5395. */
  5396. QDF_STATUS dp_send_cts_frame_to_stack(struct dp_soc *soc,
  5397. struct dp_pdev *pdev,
  5398. struct hal_rx_ppdu_info *ppdu_info)
  5399. {
  5400. struct cdp_tx_indication_info tx_capture_info;
  5401. struct mon_rx_user_status *rx_user_status =
  5402. &ppdu_info->rx_user_status[0];
  5403. struct dp_ast_entry *ast_entry;
  5404. uint32_t peer_id;
  5405. struct dp_peer *peer;
  5406. struct dp_vdev *vdev = NULL;
  5407. if (rx_user_status->ast_index >=
  5408. wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  5409. return QDF_STATUS_E_FAILURE;
  5410. }
  5411. qdf_spin_lock_bh(&soc->ast_lock);
  5412. ast_entry = soc->ast_table[rx_user_status->ast_index];
  5413. if (!ast_entry) {
  5414. qdf_spin_unlock_bh(&soc->ast_lock);
  5415. return QDF_STATUS_E_FAILURE;
  5416. }
  5417. peer_id = ast_entry->peer_id;
  5418. qdf_spin_unlock_bh(&soc->ast_lock);
  5419. peer = DP_TX_PEER_GET_REF(pdev, peer_id);
  5420. if (!peer)
  5421. return QDF_STATUS_E_FAILURE;
  5422. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, NULL, peer->mac_addr.raw)) {
  5423. DP_TX_PEER_DEL_REF(peer);
  5424. return QDF_STATUS_E_FAILURE;
  5425. }
  5426. if (pdev->tx_capture_enabled == CDP_TX_ENH_CAPTURE_ENABLE_ALL_PEERS) {
  5427. int8_t match = 0;
  5428. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  5429. if (!qdf_mem_cmp(vdev->mac_addr.raw,
  5430. ppdu_info->rx_info.mac_addr1,
  5431. QDF_MAC_ADDR_SIZE)) {
  5432. match = 1;
  5433. break;
  5434. }
  5435. }
  5436. if (!match) {
  5437. DP_TX_PEER_DEL_REF(peer);
  5438. return QDF_STATUS_E_FAILURE;
  5439. }
  5440. }
  5441. set_mpdu_info(&tx_capture_info,
  5442. &ppdu_info->rx_status, rx_user_status);
  5443. /* ppdu_desc is not required for legacy frames */
  5444. tx_capture_info.ppdu_desc = NULL;
  5445. tx_capture_info.mpdu_nbuf =
  5446. qdf_nbuf_alloc(pdev->soc->osdev,
  5447. MAX_MONITOR_HEADER +
  5448. DP_CTS_FRAME_SIZE,
  5449. MAX_MONITOR_HEADER,
  5450. 4, FALSE);
  5451. if (!tx_capture_info.mpdu_nbuf) {
  5452. DP_TX_PEER_DEL_REF(peer);
  5453. return QDF_STATUS_E_NOMEM;
  5454. }
  5455. dp_gen_cts_frame(ppdu_info, peer,
  5456. tx_capture_info.mpdu_nbuf);
  5457. DP_TX_PEER_DEL_REF(peer);
  5458. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  5459. &tx_capture_info, HTT_INVALID_PEER,
  5460. WDI_NO_VAL, pdev->pdev_id);
  5461. if (tx_capture_info.mpdu_nbuf)
  5462. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  5463. return QDF_STATUS_SUCCESS;
  5464. }
  5465. /**
  5466. * dp_send_usr_ack_frm_to_stack(): Function to generate BA or ACK frame and
  5467. * send to upper layer
  5468. * @soc: core txrx main context
  5469. * @pdev: DP pdev object
  5470. * @ppdu_info: HAL RX PPDU info retrieved from status ring TLV
  5471. * @rx_status: variable for rx status
  5472. * @rx_user_status: variable for rx user status
  5473. * @rx_user_info: variable for rx user info
  5474. *
  5475. * return: no
  5476. */
  5477. void dp_send_usr_ack_frm_to_stack(struct dp_soc *soc,
  5478. struct dp_pdev *pdev,
  5479. struct hal_rx_ppdu_info *ppdu_info,
  5480. struct mon_rx_status *rx_status,
  5481. struct mon_rx_user_status *rx_user_status,
  5482. struct mon_rx_user_info *rx_user_info)
  5483. {
  5484. struct cdp_tx_indication_info tx_capture_info;
  5485. struct dp_peer *peer;
  5486. struct dp_ast_entry *ast_entry;
  5487. uint32_t peer_id;
  5488. uint32_t ast_index;
  5489. uint8_t *ptr_mac_addr;
  5490. if (rx_user_info->qos_control_info_valid &&
  5491. ((rx_user_info->qos_control &
  5492. IEEE80211_QOS_ACKPOLICY) >> IEEE80211_QOS_ACKPOLICY_S)
  5493. == IEEE80211_BAR_CTL_NOACK)
  5494. return;
  5495. ast_index = rx_user_status->ast_index;
  5496. if (ast_index >=
  5497. wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  5498. if (ppdu_info->sw_frame_group_id ==
  5499. HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR)
  5500. return;
  5501. ptr_mac_addr = &ppdu_info->nac_info.mac_addr2[0];
  5502. if (!dp_peer_or_pdev_tx_cap_enabled(pdev,
  5503. NULL, ptr_mac_addr))
  5504. return;
  5505. if (IEEE80211_IS_ZERO(ppdu_info->nac_info.mac_addr2))
  5506. return;
  5507. set_mpdu_info(&tx_capture_info,
  5508. rx_status, rx_user_status);
  5509. tx_capture_info.mpdu_nbuf =
  5510. qdf_nbuf_alloc(pdev->soc->osdev,
  5511. MAX_MONITOR_HEADER +
  5512. DP_BA_ACK_FRAME_SIZE,
  5513. MAX_MONITOR_HEADER,
  5514. 4, FALSE);
  5515. if (!tx_capture_info.mpdu_nbuf)
  5516. return;
  5517. dp_gen_ack_frame(ppdu_info, NULL,
  5518. tx_capture_info.mpdu_nbuf);
  5519. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  5520. &tx_capture_info, HTT_INVALID_PEER,
  5521. WDI_NO_VAL, pdev->pdev_id);
  5522. if (tx_capture_info.mpdu_nbuf)
  5523. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  5524. return;
  5525. }
  5526. qdf_spin_lock_bh(&soc->ast_lock);
  5527. ast_entry = soc->ast_table[ast_index];
  5528. if (!ast_entry) {
  5529. qdf_spin_unlock_bh(&soc->ast_lock);
  5530. return;
  5531. }
  5532. peer_id = ast_entry->peer_id;
  5533. qdf_spin_unlock_bh(&soc->ast_lock);
  5534. peer = DP_TX_PEER_GET_REF(pdev, peer_id);
  5535. if (!peer)
  5536. return;
  5537. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, peer,
  5538. peer->mac_addr.raw)) {
  5539. DP_TX_PEER_DEL_REF(peer);
  5540. return;
  5541. }
  5542. set_mpdu_info(&tx_capture_info,
  5543. rx_status, rx_user_status);
  5544. tx_capture_info.mpdu_nbuf =
  5545. qdf_nbuf_alloc(pdev->soc->osdev,
  5546. MAX_MONITOR_HEADER +
  5547. DP_BA_ACK_FRAME_SIZE,
  5548. MAX_MONITOR_HEADER,
  5549. 4, FALSE);
  5550. if (!tx_capture_info.mpdu_nbuf) {
  5551. DP_TX_PEER_DEL_REF(peer);
  5552. return;
  5553. }
  5554. if (peer->rx_tid[rx_user_status->tid].ba_status == DP_RX_BA_ACTIVE ||
  5555. ppdu_info->sw_frame_group_id == HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR) {
  5556. dp_gen_block_ack_frame(ppdu_info,
  5557. rx_user_status,
  5558. rx_user_info,
  5559. peer,
  5560. tx_capture_info.mpdu_nbuf);
  5561. tx_capture_info.mpdu_info.tid = rx_user_status->tid;
  5562. } else {
  5563. dp_gen_ack_frame(ppdu_info, peer,
  5564. tx_capture_info.mpdu_nbuf);
  5565. }
  5566. DP_TX_PEER_DEL_REF(peer);
  5567. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  5568. &tx_capture_info, HTT_INVALID_PEER,
  5569. WDI_NO_VAL, pdev->pdev_id);
  5570. if (tx_capture_info.mpdu_nbuf)
  5571. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  5572. }
  5573. /**
  5574. * dp_send_ack_frame_to_stack(): Function to generate BA or ACK frame and
  5575. * send to upper layer on received unicast frame
  5576. * @soc: core txrx main context
  5577. * @pdev: DP pdev object
  5578. * @ppdu_info: HAL RX PPDU info retrieved from status ring TLV
  5579. *
  5580. * return: status
  5581. */
  5582. QDF_STATUS dp_send_ack_frame_to_stack(struct dp_soc *soc,
  5583. struct dp_pdev *pdev,
  5584. struct hal_rx_ppdu_info *ppdu_info)
  5585. {
  5586. struct mon_rx_status *rx_status;
  5587. struct mon_rx_user_status *rx_user_status;
  5588. struct mon_rx_user_info *rx_user_info;
  5589. uint32_t i;
  5590. rx_status = &ppdu_info->rx_status;
  5591. if (ppdu_info->sw_frame_group_id ==
  5592. HAL_MPDU_SW_FRAME_GROUP_CTRL_RTS) {
  5593. return dp_send_cts_frame_to_stack(soc, pdev, ppdu_info);
  5594. }
  5595. if (!rx_status->rxpcu_filter_pass)
  5596. return QDF_STATUS_SUCCESS;
  5597. if (ppdu_info->sw_frame_group_id ==
  5598. HAL_MPDU_SW_FRAME_GROUP_MGMT_BEACON ||
  5599. ppdu_info->sw_frame_group_id ==
  5600. HAL_MPDU_SW_FRAME_GROUP_CTRL_NDPA)
  5601. return QDF_STATUS_SUCCESS;
  5602. if (ppdu_info->sw_frame_group_id == HAL_MPDU_SW_FRAME_GROUP_MGMT_PROBE_REQ &&
  5603. (ppdu_info->rx_info.mac_addr1[0] & 1)) {
  5604. return QDF_STATUS_SUCCESS;
  5605. }
  5606. if (ppdu_info->sw_frame_group_id == HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR)
  5607. return QDF_STATUS_SUCCESS;
  5608. for (i = 0; i < ppdu_info->com_info.num_users; i++) {
  5609. if (i > OFDMA_NUM_USERS)
  5610. return QDF_STATUS_E_FAULT;
  5611. rx_user_status = &ppdu_info->rx_user_status[i];
  5612. rx_user_info = &ppdu_info->rx_user_info[i];
  5613. dp_send_usr_ack_frm_to_stack(soc, pdev, ppdu_info, rx_status,
  5614. rx_user_status, rx_user_info);
  5615. }
  5616. return QDF_STATUS_SUCCESS;
  5617. }
  5618. /**
  5619. * dp_bar_send_ack_frm_to_stack(): send BA or ACK frame
  5620. * to upper layers on received BAR packet for tx capture feature
  5621. *
  5622. * @soc: soc handle
  5623. * @pdev: pdev handle
  5624. * @nbuf: received packet
  5625. *
  5626. * Return: QDF_STATUS_SUCCESS on success
  5627. * others on error
  5628. */
  5629. QDF_STATUS
  5630. dp_bar_send_ack_frm_to_stack(struct dp_soc *soc,
  5631. struct dp_pdev *pdev,
  5632. qdf_nbuf_t nbuf)
  5633. {
  5634. struct ieee80211_ctlframe_addr2 *wh;
  5635. uint8_t *frm;
  5636. struct hal_rx_ppdu_info *ppdu_info;
  5637. struct mon_rx_status *rx_status;
  5638. struct mon_rx_user_status *rx_user_status;
  5639. struct mon_rx_user_info *rx_user_info;
  5640. uint16_t bar_ctl;
  5641. uint32_t user_id;
  5642. uint8_t tid;
  5643. qdf_frag_t addr;
  5644. if (!nbuf)
  5645. return QDF_STATUS_E_INVAL;
  5646. /* Get addr pointing to 80211 header */
  5647. addr = dp_rx_mon_get_nbuf_80211_hdr(nbuf);
  5648. if (qdf_unlikely(!addr)) {
  5649. dp_tx_capture_err("%pK: Unable to get 80211 header address", soc);
  5650. return QDF_STATUS_E_INVAL;
  5651. }
  5652. wh = (struct ieee80211_ctlframe_addr2 *)addr;
  5653. if (wh->i_fc[0] != (IEEE80211_FC0_VERSION_0 |
  5654. IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_BAR)) {
  5655. return QDF_STATUS_SUCCESS;
  5656. }
  5657. frm = (uint8_t *)&wh[1];
  5658. bar_ctl = qdf_le16_to_cpu(*(uint16_t *)frm);
  5659. if (bar_ctl & DP_IEEE80211_BAR_CTL_POLICY_M)
  5660. return QDF_STATUS_SUCCESS;
  5661. tid = (bar_ctl >> DP_IEEE80211_BAR_CTL_TID_S) &
  5662. DP_IEEE80211_BAR_CTL_TID_M;
  5663. ppdu_info = &pdev->ppdu_info;
  5664. user_id = ppdu_info->rx_info.user_id;
  5665. rx_status = &ppdu_info->rx_status;
  5666. rx_user_status = &ppdu_info->rx_user_status[user_id];
  5667. rx_user_info = &ppdu_info->rx_user_info[user_id];
  5668. rx_user_status->tid = tid;
  5669. dp_send_usr_ack_frm_to_stack(soc, pdev, ppdu_info, rx_status,
  5670. rx_user_status, rx_user_info);
  5671. return QDF_STATUS_SUCCESS;
  5672. }
  5673. /**
  5674. * dp_gen_noack_frame: generate noack Action frame by using parameters
  5675. * from received NDPA frame
  5676. * @ppdu_info: pointer to ppdu_info
  5677. * @peer: pointer to peer structure
  5678. * @mpdu_nbuf: buffer for the generated noack frame
  5679. * @mon_mpdu: mpdu from monitor destination path
  5680. *
  5681. * Return: QDF_STATUS
  5682. */
  5683. static void dp_gen_noack_frame(struct hal_rx_ppdu_info *ppdu_info,
  5684. struct dp_peer *peer, qdf_nbuf_t mpdu_nbuf,
  5685. qdf_nbuf_t mon_mpdu)
  5686. {
  5687. struct ieee80211_frame *wh;
  5688. uint16_t duration;
  5689. struct dp_vdev *vdev = NULL;
  5690. uint8_t token = 0;
  5691. uint8_t *frm;
  5692. char *ndpa_buf = NULL;
  5693. /* Get addr pointing to 80211 header */
  5694. ndpa_buf = dp_rx_mon_get_nbuf_80211_hdr(mon_mpdu);
  5695. if (qdf_unlikely(!ndpa_buf)) {
  5696. dp_tx_capture_err("Unable to get 80211 header address");
  5697. return;
  5698. }
  5699. wh = (struct ieee80211_frame *)qdf_nbuf_data(mpdu_nbuf);
  5700. qdf_mem_zero(((char *)wh), DP_ACKNOACK_FRAME_SIZE);
  5701. wh->i_fc[0] = IEEE80211_FC0_VERSION_0 |
  5702. IEEE80211_FC0_TYPE_MGT |
  5703. IEEE80211_FCO_SUBTYPE_ACTION_NO_ACK;
  5704. qdf_mem_copy(wh->i_addr1, &peer->mac_addr.raw[0], QDF_MAC_ADDR_SIZE);
  5705. vdev = peer->vdev;
  5706. if (vdev) {
  5707. qdf_mem_copy(wh->i_addr2,
  5708. vdev->mac_addr.raw,
  5709. QDF_MAC_ADDR_SIZE);
  5710. qdf_mem_copy(wh->i_addr3,
  5711. vdev->mac_addr.raw,
  5712. QDF_MAC_ADDR_SIZE);
  5713. }
  5714. duration = (ppdu_info->rx_status.duration > SIFS_INTERVAL) ?
  5715. ppdu_info->rx_status.duration - SIFS_INTERVAL : 0;
  5716. wh->i_dur[0] = duration & 0xff;
  5717. wh->i_dur[1] = (duration >> 8) & 0xff;
  5718. frm = (uint8_t *)&wh[1];
  5719. /*
  5720. * Update category field
  5721. */
  5722. *frm = DP_IEEE80211_CATEGORY_VHT;
  5723. /*
  5724. * Update sounding token obtained from NDPA,
  5725. * shift to get upper six bits
  5726. */
  5727. frm += DP_NOACK_SOUNDING_TOKEN_POS;
  5728. token = ndpa_buf[DP_NDPA_TOKEN_POS] >> DP_NOACK_STOKEN_POS_SHIFT;
  5729. *frm = (token) << DP_NOACK_STOKEN_POS_SHIFT;
  5730. qdf_nbuf_set_pktlen(mpdu_nbuf, DP_ACKNOACK_FRAME_SIZE);
  5731. }
  5732. /**
  5733. * dp_send_noack_frame_to_stack: Sends noack Action frame to upper stack
  5734. * in response to received NDPA frame.
  5735. * @soc: SoC handle
  5736. * @pdev: PDEV pointer
  5737. * @mon_mpdu: mpdu from monitor destination path
  5738. *
  5739. * Return: QDF_STATUS
  5740. */
  5741. QDF_STATUS dp_send_noack_frame_to_stack(struct dp_soc *soc,
  5742. struct dp_pdev *pdev,
  5743. qdf_nbuf_t mon_mpdu)
  5744. {
  5745. struct hal_rx_ppdu_info *ppdu_info = &pdev->ppdu_info;
  5746. struct mon_rx_user_status *rx_user_status =
  5747. &ppdu_info->rx_user_status[0];
  5748. struct dp_ast_entry *ast_entry;
  5749. uint32_t peer_id;
  5750. struct dp_peer *peer;
  5751. struct cdp_tx_indication_info tx_capture_info;
  5752. if (rx_user_status->ast_index >=
  5753. wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  5754. return QDF_STATUS_E_FAILURE;
  5755. }
  5756. qdf_spin_lock_bh(&soc->ast_lock);
  5757. ast_entry = soc->ast_table[rx_user_status->ast_index];
  5758. if (!ast_entry) {
  5759. qdf_spin_unlock_bh(&soc->ast_lock);
  5760. return QDF_STATUS_E_FAILURE;
  5761. }
  5762. peer_id = ast_entry->peer_id;
  5763. qdf_spin_unlock_bh(&soc->ast_lock);
  5764. peer = DP_TX_PEER_GET_REF(pdev, peer_id);
  5765. if (!peer) {
  5766. return QDF_STATUS_E_FAILURE;
  5767. }
  5768. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, peer, peer->mac_addr.raw)) {
  5769. DP_TX_PEER_DEL_REF(peer);
  5770. return QDF_STATUS_E_FAILURE;
  5771. }
  5772. set_mpdu_info(&tx_capture_info,
  5773. &ppdu_info->rx_status, rx_user_status);
  5774. tx_capture_info.mpdu_info.mcs = rx_user_status->mcs;
  5775. /*
  5776. *ppdu_desc is not required for legacy frames
  5777. */
  5778. tx_capture_info.ppdu_desc = NULL;
  5779. tx_capture_info.mpdu_nbuf =
  5780. qdf_nbuf_alloc(pdev->soc->osdev,
  5781. MAX_MONITOR_HEADER +
  5782. DP_ACKNOACK_FRAME_SIZE,
  5783. MAX_MONITOR_HEADER,
  5784. 4, FALSE);
  5785. if (!tx_capture_info.mpdu_nbuf) {
  5786. DP_TX_PEER_DEL_REF(peer);
  5787. return QDF_STATUS_E_NOMEM;
  5788. }
  5789. dp_gen_noack_frame(ppdu_info, peer,
  5790. tx_capture_info.mpdu_nbuf, mon_mpdu);
  5791. DP_TX_PEER_DEL_REF(peer);
  5792. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  5793. &tx_capture_info, HTT_INVALID_PEER,
  5794. WDI_NO_VAL, pdev->pdev_id);
  5795. if (tx_capture_info.mpdu_nbuf)
  5796. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  5797. return QDF_STATUS_SUCCESS;
  5798. }
  5799. /**
  5800. * dp_handle_tx_capture_from_dest: Handle any TX capture frames from
  5801. * monitor destination path.
  5802. * @soc: SoC handle
  5803. * @pdev: PDEV pointer
  5804. * @mon_mpdu: mpdu from monitor destination path
  5805. *
  5806. * Return: QDF_STATUS
  5807. */
  5808. QDF_STATUS dp_handle_tx_capture_from_dest(struct dp_soc *soc,
  5809. struct dp_pdev *pdev,
  5810. qdf_nbuf_t mon_mpdu)
  5811. {
  5812. struct hal_rx_ppdu_info *ppdu_info = &pdev->ppdu_info;
  5813. /*
  5814. * The below switch case can be extended to
  5815. * add more frame types as needed
  5816. */
  5817. switch (ppdu_info->sw_frame_group_id) {
  5818. case HAL_MPDU_SW_FRAME_GROUP_CTRL_NDPA:
  5819. return dp_send_noack_frame_to_stack(soc, pdev, mon_mpdu);
  5820. case HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR:
  5821. return dp_bar_send_ack_frm_to_stack(soc, pdev, mon_mpdu);
  5822. default:
  5823. break;
  5824. }
  5825. return QDF_STATUS_SUCCESS;
  5826. }
  5827. /**
  5828. * dp_peer_set_tx_capture_enabled: Set tx_cap_enabled bit in peer
  5829. * @pdev: DP PDEV handle
  5830. * @peer: Peer handle
  5831. * @value: Enable/disable setting for tx_cap_enabled
  5832. * @peer_mac: peer mac address
  5833. *
  5834. * Return: QDF_STATUS
  5835. */
  5836. QDF_STATUS
  5837. dp_peer_set_tx_capture_enabled(struct dp_pdev *pdev,
  5838. struct dp_peer *peer, uint8_t value,
  5839. uint8_t *peer_mac)
  5840. {
  5841. uint32_t peer_id = HTT_INVALID_PEER;
  5842. QDF_STATUS status = QDF_STATUS_E_FAILURE;
  5843. if (value) {
  5844. if (dp_peer_tx_cap_add_filter(pdev, peer_id, peer_mac)) {
  5845. if (peer)
  5846. peer->tx_cap_enabled = value;
  5847. status = QDF_STATUS_SUCCESS;
  5848. }
  5849. } else {
  5850. if (dp_peer_tx_cap_del_filter(pdev, peer_id, peer_mac)) {
  5851. if (peer)
  5852. peer->tx_cap_enabled = value;
  5853. status = QDF_STATUS_SUCCESS;
  5854. }
  5855. }
  5856. return status;
  5857. }
  5858. /*
  5859. * dp_peer_tx_capture_filter_check: check filter is enable for the filter
  5860. * and update tx_cap_enabled flag
  5861. * @pdev: DP PDEV handle
  5862. * @peer: DP PEER handle
  5863. *
  5864. * return: void
  5865. */
  5866. void dp_peer_tx_capture_filter_check(struct dp_pdev *pdev,
  5867. struct dp_peer *peer)
  5868. {
  5869. if (!peer)
  5870. return;
  5871. if (dp_peer_tx_cap_search(pdev, peer->peer_id,
  5872. peer->mac_addr.raw)) {
  5873. peer->tx_cap_enabled = 1;
  5874. }
  5875. return;
  5876. }
  5877. /*
  5878. * dbg_copy_ppdu_desc: copy ppdu_desc to tx capture debugfs
  5879. * @nbuf_ppdu: nbuf ppdu
  5880. *
  5881. * return: void
  5882. */
  5883. void *dbg_copy_ppdu_desc(qdf_nbuf_t nbuf_ppdu)
  5884. {
  5885. struct dbg_tx_comp_ppdu *ptr_dbg_ppdu = NULL;
  5886. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  5887. uint8_t i = 0;
  5888. uint8_t num_users = 0;
  5889. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  5890. qdf_nbuf_data(nbuf_ppdu);
  5891. ptr_dbg_ppdu = qdf_mem_malloc(sizeof(struct dbg_tx_comp_ppdu) +
  5892. (ppdu_desc->num_users *
  5893. sizeof(struct dbg_tx_comp_ppdu_user)));
  5894. if (!ptr_dbg_ppdu)
  5895. return NULL;
  5896. num_users = ppdu_desc->num_users;
  5897. ptr_dbg_ppdu->ppdu_id = ppdu_desc->ppdu_id;
  5898. ptr_dbg_ppdu->bar_ppdu_id = ppdu_desc->bar_ppdu_id;
  5899. ptr_dbg_ppdu->vdev_id = ppdu_desc->vdev_id;
  5900. ptr_dbg_ppdu->bar_num_users = ppdu_desc->bar_num_users;
  5901. ptr_dbg_ppdu->num_users = ppdu_desc->num_users;
  5902. ptr_dbg_ppdu->sched_cmdid = ppdu_desc->sched_cmdid;
  5903. ptr_dbg_ppdu->tlv_bitmap = ppdu_desc->tlv_bitmap;
  5904. ptr_dbg_ppdu->htt_frame_type = ppdu_desc->htt_frame_type;
  5905. ptr_dbg_ppdu->frame_ctrl = ppdu_desc->frame_ctrl;
  5906. ptr_dbg_ppdu->ppdu_start_timestamp = ppdu_desc->ppdu_start_timestamp;
  5907. ptr_dbg_ppdu->ppdu_end_timestamp = ppdu_desc->ppdu_end_timestamp;
  5908. ptr_dbg_ppdu->bar_ppdu_start_timestamp =
  5909. ppdu_desc->bar_ppdu_start_timestamp;
  5910. ptr_dbg_ppdu->bar_ppdu_end_timestamp =
  5911. ppdu_desc->bar_ppdu_end_timestamp;
  5912. for (i = 0; i < ppdu_desc->num_users; i++) {
  5913. ptr_dbg_ppdu->user[i].completion_status =
  5914. ppdu_desc->user[i].completion_status;
  5915. ptr_dbg_ppdu->user[i].tid = ppdu_desc->user[i].tid;
  5916. ptr_dbg_ppdu->user[i].peer_id = ppdu_desc->user[i].peer_id;
  5917. qdf_mem_copy(ptr_dbg_ppdu->user[i].mac_addr,
  5918. ppdu_desc->user[i].mac_addr, 6);
  5919. ptr_dbg_ppdu->user[i].frame_ctrl =
  5920. ppdu_desc->user[i].frame_ctrl;
  5921. ptr_dbg_ppdu->user[i].qos_ctrl = ppdu_desc->user[i].qos_ctrl;
  5922. ptr_dbg_ppdu->user[i].mpdu_tried =
  5923. ppdu_desc->user[i].mpdu_tried_ucast +
  5924. ppdu_desc->user[i].mpdu_tried_mcast;
  5925. ptr_dbg_ppdu->user[i].mpdu_success =
  5926. ppdu_desc->user[i].mpdu_success;
  5927. ptr_dbg_ppdu->user[i].ltf_size = ppdu_desc->user[i].ltf_size;
  5928. ptr_dbg_ppdu->user[i].stbc = ppdu_desc->user[i].stbc;
  5929. ptr_dbg_ppdu->user[i].he_re = ppdu_desc->user[i].he_re;
  5930. ptr_dbg_ppdu->user[i].txbf = ppdu_desc->user[i].txbf;
  5931. ptr_dbg_ppdu->user[i].bw = ppdu_desc->user[i].bw;
  5932. ptr_dbg_ppdu->user[i].nss = ppdu_desc->user[i].nss;
  5933. ptr_dbg_ppdu->user[i].mcs = ppdu_desc->user[i].mcs;
  5934. ptr_dbg_ppdu->user[i].preamble = ppdu_desc->user[i].preamble;
  5935. ptr_dbg_ppdu->user[i].gi = ppdu_desc->user[i].gi;
  5936. ptr_dbg_ppdu->user[i].dcm = ppdu_desc->user[i].dcm;
  5937. ptr_dbg_ppdu->user[i].ldpc = ppdu_desc->user[i].ldpc;
  5938. ptr_dbg_ppdu->user[i].delayed_ba =
  5939. ppdu_desc->user[i].delayed_ba;
  5940. ptr_dbg_ppdu->user[i].ack_ba_tlv =
  5941. ppdu_desc->user[i].ack_ba_tlv;
  5942. ptr_dbg_ppdu->user[i].ba_seq_no = ppdu_desc->user[i].ba_seq_no;
  5943. ptr_dbg_ppdu->user[i].start_seq = ppdu_desc->user[i].start_seq;
  5944. qdf_mem_copy(ptr_dbg_ppdu->user[i].ba_bitmap,
  5945. ppdu_desc->user[i].ba_bitmap,
  5946. CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  5947. qdf_mem_copy(ptr_dbg_ppdu->user[i].enq_bitmap,
  5948. ppdu_desc->user[i].enq_bitmap,
  5949. CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  5950. ptr_dbg_ppdu->user[i].num_mpdu = ppdu_desc->user[i].num_mpdu;
  5951. ptr_dbg_ppdu->user[i].num_msdu = ppdu_desc->user[i].num_msdu;
  5952. ptr_dbg_ppdu->user[i].is_mcast = ppdu_desc->user[i].is_mcast;
  5953. ptr_dbg_ppdu->user[i].tlv_bitmap =
  5954. ppdu_desc->user[i].tlv_bitmap;
  5955. }
  5956. return ptr_dbg_ppdu;
  5957. }
  5958. /**
  5959. * debug_ppdu_log_enable_show() - debugfs function to display ppdu_desc
  5960. * @file: qdf debugfs handler
  5961. * @arg: priv data used to get htt_logger_handler
  5962. *
  5963. * Return: QDF_STATUS
  5964. */
  5965. static QDF_STATUS debug_ppdu_desc_log_show(qdf_debugfs_file_t file, void *arg)
  5966. {
  5967. struct dp_pdev *pdev;
  5968. struct dp_pdev_tx_capture *ptr_tx_cap;
  5969. struct tx_cap_debug_log_info *ptr_log_info;
  5970. struct dbg_tx_comp_ppdu *ptr_dbg_ppdu;
  5971. uint8_t k = 0;
  5972. uint8_t i = 0;
  5973. pdev = (struct dp_pdev *)arg;
  5974. ptr_tx_cap = &pdev->tx_capture;
  5975. ptr_log_info = &ptr_tx_cap->log_info;
  5976. if ((ptr_log_info->stop_seq & (0x1 << PPDU_LOG_DISPLAY_LIST)) &&
  5977. !ptr_log_info->ppdu_desc_log) {
  5978. ptr_log_info->stop_seq &= ~(0x1 << PPDU_LOG_DISPLAY_LIST);
  5979. return QDF_STATUS_SUCCESS;
  5980. }
  5981. if (!ptr_log_info->ppdu_desc_log) {
  5982. ptr_log_info->pause_dbg_log = 0;
  5983. ptr_log_info->stop_seq |= (0x1 << PPDU_LOG_DISPLAY_LIST);
  5984. return QDF_STATUS_SUCCESS;
  5985. }
  5986. ptr_log_info->pause_dbg_log = 1;
  5987. ptr_dbg_ppdu = ppdu_desc_dbg_dequeue(ptr_log_info);
  5988. if (!ptr_dbg_ppdu) {
  5989. ptr_log_info->pause_dbg_log = 0;
  5990. ptr_log_info->stop_seq |= (0x1 << PPDU_LOG_DISPLAY_LIST);
  5991. return QDF_STATUS_SUCCESS;
  5992. }
  5993. qdf_debugfs_printf(file,
  5994. "===============================================\n");
  5995. qdf_debugfs_printf(file,
  5996. "P_ID:%d B_P_ID:%d VDEV:%d N_USR[%d %d] SCH_ID:%d\n",
  5997. ptr_dbg_ppdu->ppdu_id,
  5998. ptr_dbg_ppdu->bar_ppdu_id,
  5999. ptr_dbg_ppdu->vdev_id,
  6000. ptr_dbg_ppdu->num_users,
  6001. ptr_dbg_ppdu->bar_num_users,
  6002. ptr_dbg_ppdu->sched_cmdid);
  6003. qdf_debugfs_printf(file,
  6004. "TLV:0x%x H_FRM:%d FCTRL:0x%x\n",
  6005. ptr_dbg_ppdu->tlv_bitmap,
  6006. ptr_dbg_ppdu->htt_frame_type,
  6007. ptr_dbg_ppdu->frame_ctrl);
  6008. qdf_debugfs_printf(file,
  6009. "TSF[%llu - %llu] B_TSF[%llu - %llu]\n",
  6010. ptr_dbg_ppdu->ppdu_start_timestamp,
  6011. ptr_dbg_ppdu->ppdu_end_timestamp,
  6012. ptr_dbg_ppdu->bar_ppdu_start_timestamp,
  6013. ptr_dbg_ppdu->bar_ppdu_end_timestamp);
  6014. for (k = 0; k < ptr_dbg_ppdu->num_users; k++) {
  6015. struct dbg_tx_comp_ppdu_user *user;
  6016. user = &ptr_dbg_ppdu->user[k];
  6017. qdf_debugfs_printf(file, "USER: %d\n", k);
  6018. qdf_debugfs_printf(file,
  6019. "\tPEER:%d TID:%d CS:%d TLV:0x%x\n",
  6020. user->peer_id,
  6021. user->tid,
  6022. user->completion_status,
  6023. user->tlv_bitmap);
  6024. qdf_debugfs_printf(file,
  6025. "\tFCTRL:0x%x QOS:0x%x\n",
  6026. user->frame_ctrl,
  6027. user->qos_ctrl);
  6028. qdf_debugfs_printf(file,
  6029. "\tMPDU[T:%d S:%d] N_MPDU:%d N_MSDU:%d\n",
  6030. user->mpdu_tried,
  6031. user->mpdu_success,
  6032. user->num_mpdu,
  6033. user->num_msdu);
  6034. qdf_debugfs_printf(file,
  6035. "\tMCS:%d NSS:%d PRE:%d BW:%d D_BA:%d\n",
  6036. user->mcs,
  6037. user->nss,
  6038. user->preamble,
  6039. user->bw,
  6040. user->delayed_ba);
  6041. qdf_debugfs_printf(file,
  6042. "\tS_SEQ:%d ENQ_BITMAP[", user->start_seq);
  6043. for (i = 0; i < CDP_BA_256_BIT_MAP_SIZE_DWORDS; i++)
  6044. qdf_debugfs_printf(file, " 0x%x",
  6045. user->enq_bitmap[i]);
  6046. qdf_debugfs_printf(file, "]\n");
  6047. qdf_debugfs_printf(file,
  6048. "\tBA_SEQ:%d BA_BITMAP[",
  6049. user->ba_seq_no);
  6050. for (i = 0; i < CDP_BA_256_BIT_MAP_SIZE_DWORDS; i++)
  6051. qdf_debugfs_printf(file, " 0x%x",
  6052. user->ba_bitmap[i]);
  6053. qdf_debugfs_printf(file, "]\n");
  6054. }
  6055. qdf_debugfs_printf(file,
  6056. "===============================================\n");
  6057. /* free the dequeued dbg ppdu_desc */
  6058. qdf_mem_free(ptr_dbg_ppdu);
  6059. return QDF_STATUS_E_AGAIN;
  6060. }
  6061. /**
  6062. * debug_ppdu_desc_log_write() - write is not allowed in ppdu_desc_log.
  6063. * @priv: file handler to access tx capture log info
  6064. * @buf: received data buffer
  6065. * @len: length of received buffer
  6066. *
  6067. * Return: QDF_STATUS
  6068. */
  6069. static QDF_STATUS debug_ppdu_desc_log_write(void *priv,
  6070. const char *buf,
  6071. qdf_size_t len)
  6072. {
  6073. return -EINVAL;
  6074. }
  6075. /**
  6076. * debug_ppdu_log_enable_show() - debugfs function to show the
  6077. * enable/disable flag.
  6078. * @file: qdf debugfs handler
  6079. * @arg: priv data used to get htt_logger_handler
  6080. *
  6081. * Return: QDF_STATUS
  6082. */
  6083. static QDF_STATUS debug_ppdu_log_enable_show(qdf_debugfs_file_t file, void *arg)
  6084. {
  6085. struct dp_pdev *pdev;
  6086. struct dp_pdev_tx_capture *ptr_tx_cap;
  6087. struct tx_cap_debug_log_info *ptr_log_info;
  6088. pdev = (struct dp_pdev *)arg;
  6089. ptr_tx_cap = &pdev->tx_capture;
  6090. ptr_log_info = &ptr_tx_cap->log_info;
  6091. if ((ptr_log_info->stop_seq & (0x1 << PPDU_LOG_ENABLE_LIST))) {
  6092. ptr_log_info->stop_seq &= ~(0x1 << PPDU_LOG_ENABLE_LIST);
  6093. return QDF_STATUS_SUCCESS;
  6094. }
  6095. qdf_debugfs_printf(file, "%u\n", ptr_log_info->ppdu_desc_log);
  6096. ptr_log_info->stop_seq |= (0x1 << PPDU_LOG_ENABLE_LIST);
  6097. return QDF_STATUS_SUCCESS;
  6098. }
  6099. /**
  6100. * debug_ppdu_log_enable_write() - debugfs function to enable/disable
  6101. * the debugfs flag.
  6102. * @priv: file handler to access tx capture log info
  6103. * @buf: received data buffer
  6104. * @len: length of received buffer
  6105. *
  6106. * Return: QDF_STATUS
  6107. */
  6108. static QDF_STATUS debug_ppdu_log_enable_write(void *priv,
  6109. const char *buf,
  6110. qdf_size_t len)
  6111. {
  6112. struct dp_pdev *pdev;
  6113. struct dp_pdev_tx_capture *ptr_tx_cap;
  6114. struct tx_cap_debug_log_info *ptr_log_info;
  6115. int k, ret;
  6116. pdev = (struct dp_pdev *)priv;
  6117. ptr_tx_cap = &pdev->tx_capture;
  6118. ptr_log_info = &ptr_tx_cap->log_info;
  6119. ret = kstrtoint(buf, 0, &k);
  6120. if ((ret != 0) || ((k != 0) && (k != 1)))
  6121. return QDF_STATUS_E_PERM;
  6122. if (k == 1) {
  6123. /* if ppdu_desc log already 1 return success */
  6124. if (ptr_log_info->ppdu_desc_log)
  6125. return QDF_STATUS_SUCCESS;
  6126. /* initialize ppdu_desc_log to 1 */
  6127. ptr_log_info->ppdu_desc_log = 1;
  6128. } else {
  6129. /* if ppdu_desc log already 0 return success */
  6130. if (!ptr_log_info->ppdu_desc_log)
  6131. return QDF_STATUS_SUCCESS;
  6132. /* initialize ppdu_desc_log to 0 */
  6133. ptr_log_info->ppdu_desc_log = 0;
  6134. }
  6135. return QDF_STATUS_SUCCESS;
  6136. }
  6137. /*
  6138. * tx_cap_debugfs_log_ppdu_desc: tx capture logging ppdu desc
  6139. * @pdev: DP PDEV handle
  6140. * @nbuf_ppdu: nbuf ppdu
  6141. *
  6142. * return: void
  6143. */
  6144. void tx_cap_debugfs_log_ppdu_desc(struct dp_pdev *pdev, qdf_nbuf_t nbuf_ppdu)
  6145. {
  6146. struct dp_pdev_tx_capture *ptr_tx_cap;
  6147. struct tx_cap_debug_log_info *ptr_log_info;
  6148. struct dbg_tx_comp_ppdu *ptr_dbg_ppdu;
  6149. struct dbg_tx_comp_ppdu *ptr_tmp_ppdu;
  6150. uint32_t list_size;
  6151. ptr_tx_cap = &pdev->tx_capture;
  6152. ptr_log_info = &ptr_tx_cap->log_info;
  6153. if (!ptr_log_info->ppdu_desc_log || ptr_log_info->pause_dbg_log)
  6154. return;
  6155. ptr_dbg_ppdu = dbg_copy_ppdu_desc(nbuf_ppdu);
  6156. if (!ptr_dbg_ppdu)
  6157. return;
  6158. list_size = ppdu_desc_dbg_enqueue(ptr_log_info, ptr_dbg_ppdu);
  6159. dp_tx_capture_info("%pK: enqueue list_size:%d\n", pdev->soc, list_size);
  6160. if (list_size >= ptr_log_info->ppdu_queue_size) {
  6161. ptr_tmp_ppdu = ppdu_desc_dbg_dequeue(ptr_log_info);
  6162. qdf_mem_free(ptr_tmp_ppdu);
  6163. }
  6164. }
  6165. #define DEBUGFS_FOPS(func_base) \
  6166. { \
  6167. .name = #func_base, \
  6168. .ops = { \
  6169. .show = debug_##func_base##_show, \
  6170. .write = debug_##func_base##_write, \
  6171. .priv = NULL, \
  6172. } \
  6173. }
  6174. struct tx_cap_debugfs_info tx_cap_debugfs_infos[NUM_TX_CAP_DEBUG_INFOS] = {
  6175. DEBUGFS_FOPS(ppdu_log_enable),
  6176. DEBUGFS_FOPS(ppdu_desc_log),
  6177. };
  6178. /*
  6179. * tx_cap_debugfs_remove: remove dentry and file created.
  6180. * @ptr_log_info: tx capture debugfs log structure
  6181. *
  6182. * return: void
  6183. */
  6184. static void tx_cap_debugfs_remove(struct tx_cap_debug_log_info *ptr_log_info)
  6185. {
  6186. qdf_dentry_t dentry;
  6187. uint8_t i = 0;
  6188. for (i = 0; i < NUM_TX_CAP_DEBUG_INFOS; ++i) {
  6189. dentry = ptr_log_info->debugfs_de[i];
  6190. if (dentry) {
  6191. qdf_debugfs_remove_file(dentry);
  6192. ptr_log_info->debugfs_de[i] = NULL;
  6193. }
  6194. }
  6195. dentry = ptr_log_info->tx_cap_debugfs_dir;
  6196. if (dentry) {
  6197. qdf_debugfs_remove_dir(dentry);
  6198. ptr_log_info->tx_cap_debugfs_dir = NULL;
  6199. }
  6200. }
  6201. /*
  6202. * dp_tx_capture_debugfs_init: tx capture debugfs init
  6203. * @pdev: DP PDEV handle
  6204. *
  6205. * return: QDF_STATUS
  6206. */
  6207. QDF_STATUS dp_tx_capture_debugfs_init(struct dp_pdev *pdev)
  6208. {
  6209. qdf_dentry_t dentry;
  6210. struct dp_soc *soc;
  6211. struct dp_pdev_tx_capture *ptr_tx_cap;
  6212. struct tx_cap_debug_log_info *ptr_log_info;
  6213. struct tx_cap_debugfs_info *ptr_debugfs_info;
  6214. uint8_t i = 0;
  6215. char buf[32];
  6216. char *name = NULL;
  6217. soc = pdev->soc;
  6218. ptr_tx_cap = &pdev->tx_capture;
  6219. ptr_log_info = &ptr_tx_cap->log_info;
  6220. if (soc->cdp_soc.ol_ops->get_device_name) {
  6221. name = soc->cdp_soc.ol_ops->get_device_name(
  6222. pdev->soc->ctrl_psoc, pdev->pdev_id);
  6223. }
  6224. if (name == NULL)
  6225. return QDF_STATUS_E_FAILURE;
  6226. /* directory creation with name */
  6227. snprintf(buf, sizeof(buf), "tx_cap_log_%s", name);
  6228. dentry = qdf_debugfs_create_dir(buf, NULL);
  6229. if (!dentry) {
  6230. dp_tx_capture_err("%pK: error while creating debugfs dir for %s", pdev->soc, buf);
  6231. goto out;
  6232. }
  6233. ptr_log_info->tx_cap_debugfs_dir = dentry;
  6234. qdf_mem_copy(ptr_log_info->tx_cap_debugfs_infos,
  6235. tx_cap_debugfs_infos,
  6236. (sizeof(struct tx_cap_debugfs_info) *
  6237. NUM_TX_CAP_DEBUG_INFOS));
  6238. for (i = 0; i < NUM_TX_CAP_DEBUG_INFOS; i++) {
  6239. ptr_debugfs_info = &ptr_log_info->tx_cap_debugfs_infos[i];
  6240. /* store pdev tx capture pointer to private data pointer */
  6241. ptr_debugfs_info->ops.priv = pdev;
  6242. ptr_log_info->debugfs_de[i] = qdf_debugfs_create_file(
  6243. ptr_debugfs_info->name,
  6244. TX_CAP_DBG_FILE_PERM,
  6245. ptr_log_info->tx_cap_debugfs_dir,
  6246. &ptr_debugfs_info->ops);
  6247. if (!ptr_log_info->debugfs_de[i]) {
  6248. dp_tx_capture_err("%pK: debug Entry creation failed[%s]!",
  6249. pdev->soc, ptr_debugfs_info->name);
  6250. goto out;
  6251. }
  6252. }
  6253. return QDF_STATUS_SUCCESS;
  6254. out:
  6255. tx_cap_debugfs_remove(ptr_log_info);
  6256. return QDF_STATUS_E_FAILURE;
  6257. }
  6258. /*
  6259. * dp_tx_capture_debugfs_deinit: tx capture debugfs deinit
  6260. * @pdev: DP PDEV handle
  6261. *
  6262. * return: void
  6263. */
  6264. void dp_tx_capture_debugfs_deinit(struct dp_pdev *pdev)
  6265. {
  6266. struct dp_pdev_tx_capture *ptr_tx_cap;
  6267. struct tx_cap_debug_log_info *ptr_log_info;
  6268. ptr_tx_cap = &pdev->tx_capture;
  6269. ptr_log_info = &ptr_tx_cap->log_info;
  6270. tx_cap_debugfs_remove(ptr_log_info);
  6271. }
  6272. #endif