dp_tx_capture.c 188 KB

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