dp_tx_capture.c 185 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938
  1. /*
  2. * Copyright (c) 2017-2020 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[%d] defer_msdu_q[%d] pending_ppdu_q[%d]",
  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:%u, 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. {
  1955. struct cdp_tx_completion_ppdu *ppdu_desc;
  1956. struct cdp_tx_completion_ppdu_user *user;
  1957. uint32_t mpdu_buf_len, frame_size;
  1958. uint8_t *ptr_hdr;
  1959. uint16_t eth_type = qdf_htons(ether_type);
  1960. struct ieee80211_qosframe_addr4 *ptr_wh;
  1961. ppdu_desc = (struct cdp_tx_completion_ppdu *)data;
  1962. user = &ppdu_desc->user[usr_idx];
  1963. ptr_wh = &peer->tx_capture.tx_wifi_addr4_qos_hdr;
  1964. /*
  1965. * update framectrl only for first ppdu_id
  1966. * rest of mpdu will have same frame ctrl
  1967. * mac address and duration
  1968. */
  1969. if (ppdu_desc->ppdu_id != peer->tx_capture.tx_wifi_ppdu_id) {
  1970. ptr_wh->i_fc[1] = (ppdu_desc->frame_ctrl & 0xFF00) >> 8;
  1971. ptr_wh->i_fc[0] = (ppdu_desc->frame_ctrl & 0xFF);
  1972. ptr_wh->i_dur[1] = (ppdu_desc->tx_duration & 0xFF00) >> 8;
  1973. ptr_wh->i_dur[0] = (ppdu_desc->tx_duration & 0xFF);
  1974. ptr_wh->i_qos[1] = (user->qos_ctrl & 0xFF00) >> 8;
  1975. ptr_wh->i_qos[0] = (user->qos_ctrl & 0xFF);
  1976. /* Update Addr 3 (DA) with DA derived from ether packet */
  1977. qdf_mem_copy(ptr_wh->i_addr3, dst_addr, QDF_MAC_ADDR_SIZE);
  1978. peer->tx_capture.tx_wifi_ppdu_id = ppdu_desc->ppdu_id;
  1979. }
  1980. frame_size = (user->tid != DP_NON_QOS_TID) ?
  1981. sizeof(struct ieee80211_qosframe_addr4) :
  1982. sizeof(struct ieee80211_frame_addr4);
  1983. mpdu_buf_len = frame_size + LLC_SNAP_HDR_LEN;
  1984. nbuf->protocol = qdf_htons(ETH_P_802_2);
  1985. /* update ieee80211_frame header */
  1986. if (!qdf_nbuf_push_head(nbuf, mpdu_buf_len)) {
  1987. dp_tx_capture_err("%pK: No headroom", pdev->soc);
  1988. return QDF_STATUS_E_NOMEM;
  1989. }
  1990. ptr_hdr = (void *)qdf_nbuf_data(nbuf);
  1991. qdf_mem_copy(ptr_hdr, ptr_wh, frame_size);
  1992. ptr_hdr = ptr_hdr + frame_size;
  1993. /* update LLC */
  1994. *ptr_hdr = LLC_SNAP_LSAP;
  1995. *(ptr_hdr + 1) = LLC_SNAP_LSAP;
  1996. *(ptr_hdr + 2) = LLC_UI;
  1997. *(ptr_hdr + 3) = 0x00;
  1998. *(ptr_hdr + 4) = 0x00;
  1999. *(ptr_hdr + 5) = 0x00;
  2000. *(ptr_hdr + 6) = (eth_type & 0xFF00) >> 8;
  2001. *(ptr_hdr + 7) = (eth_type & 0xFF);
  2002. qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) - mpdu_buf_len);
  2003. return 0;
  2004. }
  2005. /**
  2006. * dp_tx_update_80211_hdr() – Update 80211 frame header to set QoS
  2007. * related information if necessary
  2008. * @pdev: Physical device reference
  2009. * @peer: Datapath peer
  2010. * @data: ppdu_descriptor
  2011. * @nbuf: 802.11 frame
  2012. * @ether_type: ethernet type
  2013. * @src_addr: ether shost address
  2014. *
  2015. */
  2016. static uint32_t dp_tx_update_80211_hdr(struct dp_pdev *pdev,
  2017. struct dp_peer *peer,
  2018. void *data,
  2019. qdf_nbuf_t nbuf,
  2020. uint16_t ether_type,
  2021. uint8_t *src_addr,
  2022. uint8_t usr_idx)
  2023. {
  2024. struct cdp_tx_completion_ppdu *ppdu_desc;
  2025. struct cdp_tx_completion_ppdu_user *user;
  2026. uint32_t mpdu_buf_len, frame_size;
  2027. uint8_t *ptr_hdr;
  2028. uint16_t eth_type = qdf_htons(ether_type);
  2029. struct ieee80211_qosframe *ptr_wh;
  2030. ppdu_desc = (struct cdp_tx_completion_ppdu *)data;
  2031. user = &ppdu_desc->user[usr_idx];
  2032. ptr_wh = &peer->tx_capture.tx_wifi_qos_hdr;
  2033. /*
  2034. * update framectrl only for first ppdu_id
  2035. * rest of mpdu will have same frame ctrl
  2036. * mac address and duration
  2037. */
  2038. if (ppdu_desc->ppdu_id != peer->tx_capture.tx_wifi_ppdu_id) {
  2039. ptr_wh->i_fc[1] = (user->frame_ctrl & 0xFF00) >> 8;
  2040. ptr_wh->i_fc[0] = (user->frame_ctrl & 0xFF);
  2041. ptr_wh->i_dur[1] = (ppdu_desc->tx_duration & 0xFF00) >> 8;
  2042. ptr_wh->i_dur[0] = (ppdu_desc->tx_duration & 0xFF);
  2043. ptr_wh->i_qos[1] = (user->qos_ctrl & 0xFF00) >> 8;
  2044. ptr_wh->i_qos[0] = (user->qos_ctrl & 0xFF);
  2045. /* Update Addr 3 (SA) with SA derived from ether packet */
  2046. qdf_mem_copy(ptr_wh->i_addr3, src_addr, QDF_MAC_ADDR_SIZE);
  2047. peer->tx_capture.tx_wifi_ppdu_id = ppdu_desc->ppdu_id;
  2048. }
  2049. frame_size = (user->tid != DP_NON_QOS_TID) ?
  2050. sizeof(struct ieee80211_qosframe) :
  2051. sizeof(struct ieee80211_frame);
  2052. mpdu_buf_len = frame_size + LLC_SNAP_HDR_LEN;
  2053. nbuf->protocol = qdf_htons(ETH_P_802_2);
  2054. /* update ieee80211_frame header */
  2055. if (!qdf_nbuf_push_head(nbuf, mpdu_buf_len)) {
  2056. dp_tx_capture_err("%pK: No headroom", pdev->soc);
  2057. return QDF_STATUS_E_NOMEM;
  2058. }
  2059. ptr_hdr = (void *)qdf_nbuf_data(nbuf);
  2060. qdf_mem_copy(ptr_hdr, ptr_wh, frame_size);
  2061. ptr_hdr = ptr_hdr + frame_size;
  2062. /* update LLC */
  2063. *ptr_hdr = LLC_SNAP_LSAP;
  2064. *(ptr_hdr + 1) = LLC_SNAP_LSAP;
  2065. *(ptr_hdr + 2) = LLC_UI;
  2066. *(ptr_hdr + 3) = 0x00;
  2067. *(ptr_hdr + 4) = 0x00;
  2068. *(ptr_hdr + 5) = 0x00;
  2069. *(ptr_hdr + 6) = (eth_type & 0xFF00) >> 8;
  2070. *(ptr_hdr + 7) = (eth_type & 0xFF);
  2071. qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) - mpdu_buf_len);
  2072. return 0;
  2073. }
  2074. /**
  2075. * dp_tx_mon_restitch_mpdu(): Function to restitch msdu to mpdu
  2076. * @pdev: dp_pdev
  2077. * @peer: dp_peer
  2078. * @head_msdu: head msdu queue
  2079. *
  2080. * return: status
  2081. */
  2082. static uint32_t
  2083. dp_tx_mon_restitch_mpdu(struct dp_pdev *pdev, struct dp_peer *peer,
  2084. struct cdp_tx_completion_ppdu *ppdu_desc,
  2085. qdf_nbuf_queue_t *head_msdu,
  2086. qdf_nbuf_queue_t *mpdu_q, uint8_t usr_idx)
  2087. {
  2088. qdf_nbuf_t curr_nbuf = NULL;
  2089. qdf_nbuf_t first_nbuf = NULL;
  2090. qdf_nbuf_t prev_nbuf = NULL;
  2091. qdf_nbuf_t mpdu_nbuf = NULL;
  2092. struct msdu_completion_info *ptr_msdu_info = NULL;
  2093. uint8_t first_msdu = 0;
  2094. uint8_t last_msdu = 0;
  2095. uint32_t frag_list_sum_len = 0;
  2096. uint8_t first_msdu_not_seen = 1;
  2097. uint16_t ether_type = 0;
  2098. qdf_ether_header_t *eh = NULL;
  2099. size_t msdu_comp_info_sz;
  2100. size_t ether_hdr_sz;
  2101. if (qdf_nbuf_is_queue_empty(head_msdu))
  2102. return 0;
  2103. curr_nbuf = qdf_nbuf_queue_remove(head_msdu);
  2104. while (curr_nbuf) {
  2105. ptr_msdu_info =
  2106. (struct msdu_completion_info *)qdf_nbuf_data(curr_nbuf);
  2107. first_msdu = ptr_msdu_info->first_msdu;
  2108. last_msdu = ptr_msdu_info->last_msdu;
  2109. eh = (qdf_ether_header_t *)(curr_nbuf->data +
  2110. sizeof(struct msdu_completion_info));
  2111. ether_type = eh->ether_type;
  2112. msdu_comp_info_sz = sizeof(struct msdu_completion_info);
  2113. /* pull msdu_completion_info added in pre header */
  2114. if (NULL == qdf_nbuf_pull_head(curr_nbuf, msdu_comp_info_sz)) {
  2115. dp_tx_capture_alert(" No Head space to pull !!\n");
  2116. qdf_assert_always(0);
  2117. }
  2118. if ((qdf_likely((peer->vdev->tx_encap_type !=
  2119. htt_cmn_pkt_type_raw))) &&
  2120. (((ppdu_desc->frame_ctrl >> IEEE80211_FC1_SHIFT) &
  2121. IEEE80211_FC1_DIR_MASK) ==
  2122. (IEEE80211_FC1_DIR_TODS | IEEE80211_FC1_DIR_FROMDS)))
  2123. dp_peer_tx_wds_addr_add(peer, eh->ether_shost);
  2124. if (first_msdu && first_msdu_not_seen) {
  2125. first_nbuf = curr_nbuf;
  2126. frag_list_sum_len = 0;
  2127. first_msdu_not_seen = 0;
  2128. ether_hdr_sz = sizeof(qdf_ether_header_t);
  2129. /* pull ethernet header from first MSDU alone */
  2130. if (NULL == qdf_nbuf_pull_head(curr_nbuf,
  2131. ether_hdr_sz)) {
  2132. dp_tx_capture_alert(" No Head space to pull !!\n");
  2133. qdf_assert_always(0);
  2134. }
  2135. /* update first buffer to previous buffer */
  2136. prev_nbuf = curr_nbuf;
  2137. } else if (first_msdu && !first_msdu_not_seen) {
  2138. dp_tx_capture_err("!!!!! NO LAST MSDU\n");
  2139. /*
  2140. * no last msdu in a mpdu
  2141. * handle this case
  2142. */
  2143. qdf_nbuf_free(curr_nbuf);
  2144. /*
  2145. * No last msdu found because WBM comes out
  2146. * of order, free the pkt
  2147. */
  2148. goto free_ppdu_desc_mpdu_q;
  2149. } else if (!first_msdu && first_msdu_not_seen) {
  2150. dp_tx_capture_err("!!!!! NO FIRST MSDU\n");
  2151. /*
  2152. * no first msdu in a mpdu
  2153. * handle this case
  2154. */
  2155. qdf_nbuf_free(curr_nbuf);
  2156. /*
  2157. * no first msdu found beacuse WBM comes out
  2158. * of order, free the pkt
  2159. */
  2160. goto free_ppdu_desc_mpdu_q;
  2161. } else {
  2162. /* update current buffer to previous buffer next */
  2163. prev_nbuf->next = curr_nbuf;
  2164. /* move the previous buffer to next buffer */
  2165. prev_nbuf = prev_nbuf->next;
  2166. }
  2167. frag_list_sum_len += qdf_nbuf_len(curr_nbuf);
  2168. if (last_msdu) {
  2169. mpdu_nbuf = qdf_nbuf_alloc(pdev->soc->osdev,
  2170. MAX_MONITOR_HEADER,
  2171. MAX_MONITOR_HEADER,
  2172. 4, FALSE);
  2173. if (!mpdu_nbuf) {
  2174. dp_tx_capture_err("MPDU head allocation failed !!!");
  2175. goto free_ppdu_desc_mpdu_q;
  2176. }
  2177. if (((ppdu_desc->frame_ctrl >> IEEE80211_FC1_SHIFT) &
  2178. IEEE80211_FC1_DIR_MASK) ==
  2179. (IEEE80211_FC1_DIR_TODS |
  2180. IEEE80211_FC1_DIR_FROMDS)) {
  2181. dp_tx_update_80211_wds_hdr(pdev, peer,
  2182. ppdu_desc, mpdu_nbuf,
  2183. ether_type,
  2184. eh->ether_dhost,
  2185. usr_idx);
  2186. } else {
  2187. dp_tx_update_80211_hdr(pdev, peer,
  2188. ppdu_desc, mpdu_nbuf,
  2189. ether_type,
  2190. eh->ether_shost,
  2191. usr_idx);
  2192. }
  2193. /*
  2194. * first nbuf will hold list of msdu
  2195. * stored in prev_nbuf
  2196. */
  2197. qdf_nbuf_append_ext_list(mpdu_nbuf,
  2198. first_nbuf,
  2199. frag_list_sum_len);
  2200. /* add mpdu to mpdu queue */
  2201. qdf_nbuf_queue_add(mpdu_q, mpdu_nbuf);
  2202. first_nbuf = NULL;
  2203. mpdu_nbuf = NULL;
  2204. /* next msdu will start with first msdu */
  2205. first_msdu_not_seen = 1;
  2206. goto check_for_next_msdu;
  2207. }
  2208. /* get next msdu from the head_msdu */
  2209. curr_nbuf = qdf_nbuf_queue_remove(head_msdu);
  2210. if (!curr_nbuf) {
  2211. /* msdu missed in list */
  2212. dp_tx_capture_err("!!!! WAITING for msdu but list empty !!!!");
  2213. /* for incomplete list, free up the queue */
  2214. goto free_ppdu_desc_mpdu_q;
  2215. }
  2216. continue;
  2217. check_for_next_msdu:
  2218. if (qdf_nbuf_is_queue_empty(head_msdu))
  2219. return 0;
  2220. curr_nbuf = qdf_nbuf_queue_remove(head_msdu);
  2221. }
  2222. return 0;
  2223. free_ppdu_desc_mpdu_q:
  2224. /* free already chained msdu pkt */
  2225. while (first_nbuf) {
  2226. curr_nbuf = first_nbuf;
  2227. first_nbuf = first_nbuf->next;
  2228. qdf_nbuf_free(curr_nbuf);
  2229. }
  2230. /* free allocated mpdu hdr */
  2231. if (mpdu_nbuf)
  2232. qdf_nbuf_free(mpdu_nbuf);
  2233. /* free queued remaining msdu pkt per ppdu */
  2234. TX_CAP_NBUF_QUEUE_FREE(head_msdu);
  2235. /* free queued mpdu per ppdu */
  2236. TX_CAP_NBUF_QUEUE_FREE(mpdu_q);
  2237. return 0;
  2238. }
  2239. /**
  2240. * dp_tx_msdu_dequeue(): Function to dequeue msdu from peer based tid
  2241. * @peer: dp_peer
  2242. * @ppdu_id: ppdu_id
  2243. * @tid: tid
  2244. * @num_msdu: number of msdu
  2245. * @head: head queue
  2246. * @start_tsf: start tsf from ppdu_desc
  2247. * @end_tsf: end tsf from ppdu_desc
  2248. *
  2249. * return: status
  2250. */
  2251. static
  2252. uint32_t dp_tx_msdu_dequeue(struct dp_peer *peer, uint32_t ppdu_id,
  2253. uint16_t tid, uint32_t num_msdu,
  2254. qdf_nbuf_queue_t *head,
  2255. qdf_nbuf_queue_t *head_xretries,
  2256. uint32_t start_tsf, uint32_t end_tsf)
  2257. {
  2258. struct dp_tx_tid *tx_tid = NULL;
  2259. uint32_t msdu_ppdu_id;
  2260. qdf_nbuf_t curr_msdu = NULL;
  2261. struct msdu_completion_info *ptr_msdu_info = NULL;
  2262. uint32_t wbm_tsf;
  2263. uint32_t matched = 0;
  2264. if (qdf_unlikely(!peer))
  2265. return 0;
  2266. /* Non-QOS frames are being indicated with TID 0
  2267. * in WBM completion path, an hence we should
  2268. * TID 0 to reap MSDUs from completion path
  2269. */
  2270. if (qdf_unlikely(tid == DP_NON_QOS_TID))
  2271. tid = 0;
  2272. tx_tid = &peer->tx_capture.tx_tid[tid];
  2273. if (qdf_unlikely(!tx_tid))
  2274. return 0;
  2275. /* lock here */
  2276. qdf_spin_lock_bh(&tx_tid->tasklet_tid_lock);
  2277. qdf_nbuf_queue_append(&tx_tid->defer_msdu_q, &tx_tid->msdu_comp_q);
  2278. qdf_nbuf_queue_init(&tx_tid->msdu_comp_q);
  2279. /* unlock here */
  2280. qdf_spin_unlock_bh(&tx_tid->tasklet_tid_lock);
  2281. /* lock here */
  2282. qdf_spin_lock_bh(&tx_tid->tid_lock);
  2283. if (qdf_nbuf_is_queue_empty(&tx_tid->defer_msdu_q)) {
  2284. qdf_spin_unlock_bh(&tx_tid->tid_lock);
  2285. return 0;
  2286. }
  2287. curr_msdu = qdf_nbuf_queue_first(&tx_tid->defer_msdu_q);
  2288. while (curr_msdu) {
  2289. if (qdf_nbuf_queue_len(head) == num_msdu) {
  2290. matched = 1;
  2291. break;
  2292. }
  2293. ptr_msdu_info =
  2294. (struct msdu_completion_info *)qdf_nbuf_data(curr_msdu);
  2295. msdu_ppdu_id = ptr_msdu_info->ppdu_id;
  2296. wbm_tsf = ptr_msdu_info->tsf;
  2297. if ((ptr_msdu_info->status == HAL_TX_TQM_RR_REM_CMD_TX) ||
  2298. (ptr_msdu_info->status == HAL_TX_TQM_RR_REM_CMD_AGED)) {
  2299. /* Frames removed due to excessive retries */
  2300. qdf_nbuf_queue_remove(&tx_tid->defer_msdu_q);
  2301. qdf_nbuf_queue_add(head_xretries, curr_msdu);
  2302. dp_tx_cap_stats_msdu_update(peer, PEER_MSDU_XRETRY, 1);
  2303. curr_msdu = qdf_nbuf_queue_first(
  2304. &tx_tid->defer_msdu_q);
  2305. continue;
  2306. }
  2307. if (wbm_tsf > end_tsf) {
  2308. /* PPDU being matched is older than MSDU at head of
  2309. * completion queue. Return matched=1 to skip PPDU
  2310. */
  2311. matched = 1;
  2312. break;
  2313. }
  2314. if (wbm_tsf && (wbm_tsf < start_tsf)) {
  2315. /* remove the aged packet */
  2316. qdf_nbuf_queue_remove(&tx_tid->defer_msdu_q);
  2317. qdf_nbuf_free(curr_msdu);
  2318. dp_tx_cap_stats_msdu_update(peer, PEER_MSDU_DROP, 1);
  2319. curr_msdu = qdf_nbuf_queue_first(
  2320. &tx_tid->defer_msdu_q);
  2321. continue;
  2322. }
  2323. if (msdu_ppdu_id == ppdu_id) {
  2324. /* remove head */
  2325. qdf_nbuf_queue_remove(&tx_tid->defer_msdu_q);
  2326. /* add msdu to head queue */
  2327. qdf_nbuf_queue_add(head, curr_msdu);
  2328. dp_tx_cap_stats_msdu_update(peer, PEER_MSDU_DEQ,
  2329. 1);
  2330. /* get next msdu from defer_msdu_q */
  2331. curr_msdu = qdf_nbuf_queue_first(&tx_tid->defer_msdu_q);
  2332. continue;
  2333. } else {
  2334. /*
  2335. * at this point wbm_tsf is inbetween start_tsf and
  2336. * end tsf but there is a mismatch in ppdu_id
  2337. */
  2338. break;
  2339. }
  2340. }
  2341. qdf_spin_unlock_bh(&tx_tid->tid_lock);
  2342. return matched;
  2343. }
  2344. /**
  2345. * dp_tx_cap_nbuf_list_get_ref() - get nbuf_list reference
  2346. * @ptr_nbuf_list: dp_tx_cap_nbuf_list list
  2347. *
  2348. * Return: reference count
  2349. */
  2350. static inline uint8_t
  2351. dp_tx_cap_nbuf_list_get_ref(struct dp_tx_cap_nbuf_list *ptr_nbuf_list)
  2352. {
  2353. return ptr_nbuf_list->ref_cnt;
  2354. }
  2355. /**
  2356. * dp_tx_cap_nbuf_list_dec_ref() - dec nbuf_list reference
  2357. * @ptr_nbuf_list: dp_tx_cap_nbuf_list list
  2358. *
  2359. * Return: none
  2360. */
  2361. static inline
  2362. void dp_tx_cap_nbuf_list_dec_ref(struct dp_tx_cap_nbuf_list *ptr_nbuf_list)
  2363. {
  2364. ptr_nbuf_list->ref_cnt--;
  2365. if (!ptr_nbuf_list->ref_cnt)
  2366. ptr_nbuf_list->nbuf_ppdu = NULL;
  2367. }
  2368. /**
  2369. * dp_tx_cap_nbuf_list_inc_ref() - inc nbuf_list reference
  2370. * @ptr_nbuf_list: dp_tx_cap_nbuf_list list
  2371. *
  2372. * Return: none
  2373. */
  2374. static inline
  2375. void dp_tx_cap_nbuf_list_inc_ref(struct dp_tx_cap_nbuf_list *ptr_nbuf_list)
  2376. {
  2377. ptr_nbuf_list->ref_cnt++;
  2378. }
  2379. /**
  2380. * dp_tx_cap_nbuf_list_update_ref() - update nbuf_list reference
  2381. * @ptr_nbuf_list: dp_tx_cap_nbuf_list list
  2382. * @ref_cnt: reference count
  2383. *
  2384. * Return: none
  2385. */
  2386. static inline void
  2387. dp_tx_cap_nbuf_list_update_ref(struct dp_tx_cap_nbuf_list *ptr_nbuf_list,
  2388. uint8_t ref_cnt)
  2389. {
  2390. ptr_nbuf_list->ref_cnt = ref_cnt;
  2391. }
  2392. /**
  2393. * get_mpdu_clone_from_next_ppdu(): Function to clone missing mpdu from
  2394. * next ppdu
  2395. * @nbuf_ppdu_list: nbuf list
  2396. * @ppdu_desc_cnt: ppdu_desc_cnt
  2397. * @missed_seq_no:
  2398. * @ppdu_id: ppdu_id
  2399. * @mpdu_info: cdp_tx_indication_mpdu_info
  2400. *
  2401. * return: void
  2402. */
  2403. static qdf_nbuf_t
  2404. get_mpdu_clone_from_next_ppdu(struct dp_tx_cap_nbuf_list nbuf_list[],
  2405. uint32_t ppdu_desc_cnt,
  2406. uint16_t missed_seq_no,
  2407. uint16_t peer_id, uint32_t ppdu_id,
  2408. uint8_t usr_idx)
  2409. {
  2410. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  2411. struct cdp_tx_completion_ppdu_user *user;
  2412. qdf_nbuf_t mpdu = NULL;
  2413. struct dp_tx_cap_nbuf_list *ptr_nbuf_list;
  2414. qdf_nbuf_t nbuf_ppdu;
  2415. uint32_t i = 0;
  2416. uint32_t found = 0;
  2417. uint32_t seq_no = 0;
  2418. uint32_t mpdu_q_len;
  2419. for (i = 1; i < ppdu_desc_cnt; i++) {
  2420. ptr_nbuf_list = &nbuf_list[i];
  2421. nbuf_ppdu = ptr_nbuf_list->nbuf_ppdu;
  2422. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  2423. qdf_nbuf_data(nbuf_ppdu);
  2424. user = &ppdu_desc->user[usr_idx];
  2425. if (user->skip == 1)
  2426. continue;
  2427. /* check if seq number is between the range */
  2428. if ((peer_id == user->peer_id) &&
  2429. ((missed_seq_no >= user->start_seq) &&
  2430. (missed_seq_no <= user->last_enq_seq))) {
  2431. seq_no = user->start_seq;
  2432. if (SEQ_BIT(user->failed_bitmap,
  2433. (missed_seq_no - seq_no))) {
  2434. found = 1;
  2435. break;
  2436. }
  2437. }
  2438. }
  2439. if (found == 0) {
  2440. /* mpdu not found in sched cmd id */
  2441. dp_tx_capture_debug("peer_id[%d] missed seq_no[%d] ppdu_id[%d] [%d] not found!!!",
  2442. peer_id,
  2443. missed_seq_no, ppdu_id, ppdu_desc_cnt);
  2444. return NULL;
  2445. }
  2446. dp_tx_capture_debug("peer_id[%d] seq_no[%d] missed ppdu_id[%d] m[%d] found in ppdu_id[%d]!!",
  2447. peer_id,
  2448. missed_seq_no, ppdu_id,
  2449. (missed_seq_no - seq_no), ppdu_desc->ppdu_id);
  2450. mpdu = qdf_nbuf_queue_first(&ppdu_desc->user[usr_idx].mpdu_q);
  2451. mpdu_q_len = qdf_nbuf_queue_len(&ppdu_desc->user[usr_idx].mpdu_q);
  2452. if (!mpdu) {
  2453. /* bitmap shows it found sequence number, but
  2454. * MPDU not found in PPDU
  2455. */
  2456. dp_tx_capture_err("missed seq_no[%d] ppdu_id[%d] [%d] found but queue empty!!!",
  2457. missed_seq_no, ppdu_id, ppdu_desc_cnt);
  2458. if (mpdu_q_len)
  2459. qdf_assert_always(0);
  2460. return NULL;
  2461. }
  2462. for (i = 0; i < (missed_seq_no - seq_no); i++) {
  2463. mpdu = mpdu->next;
  2464. if (!mpdu) {
  2465. /*
  2466. * bitmap shows it found sequence number,
  2467. * but queue empty, do we need to allocate
  2468. * skb and send instead of NULL ?
  2469. * add counter here:
  2470. */
  2471. return NULL;
  2472. }
  2473. }
  2474. if (!mpdu)
  2475. return NULL;
  2476. return qdf_nbuf_copy_expand_fraglist(mpdu, MAX_MONITOR_HEADER, 0);
  2477. }
  2478. /**
  2479. * dp_tx_update_user_mpdu_info(): Function to update mpdu info
  2480. * from ppdu_desc
  2481. * @ppdu_id: ppdu_id
  2482. * @mpdu_info: cdp_tx_indication_mpdu_info
  2483. * @user: cdp_tx_completion_ppdu_user
  2484. *
  2485. * return: void
  2486. */
  2487. static void
  2488. dp_tx_update_user_mpdu_info(uint32_t ppdu_id,
  2489. struct cdp_tx_indication_mpdu_info *mpdu_info,
  2490. struct cdp_tx_completion_ppdu_user *user)
  2491. {
  2492. mpdu_info->ppdu_id = ppdu_id;
  2493. mpdu_info->frame_ctrl = user->frame_ctrl;
  2494. mpdu_info->qos_ctrl = user->qos_ctrl;
  2495. mpdu_info->tid = user->tid;
  2496. mpdu_info->ltf_size = user->ltf_size;
  2497. mpdu_info->he_re = user->he_re;
  2498. mpdu_info->txbf = user->txbf;
  2499. mpdu_info->bw = user->bw;
  2500. mpdu_info->nss = user->nss;
  2501. mpdu_info->mcs = user->mcs;
  2502. mpdu_info->preamble = user->preamble;
  2503. mpdu_info->gi = user->gi;
  2504. mpdu_info->ack_rssi = user->ack_rssi[0];
  2505. mpdu_info->tx_rate = user->tx_rate;
  2506. mpdu_info->ldpc = user->ldpc;
  2507. mpdu_info->ppdu_cookie = user->ppdu_cookie;
  2508. mpdu_info->long_retries = user->long_retries;
  2509. mpdu_info->short_retries = user->short_retries;
  2510. mpdu_info->completion_status = user->completion_status;
  2511. qdf_mem_copy(mpdu_info->mac_address, user->mac_addr, 6);
  2512. mpdu_info->ba_start_seq = user->ba_seq_no;
  2513. qdf_mem_copy(mpdu_info->ba_bitmap, user->ba_bitmap,
  2514. CDP_BA_256_BIT_MAP_SIZE_DWORDS * sizeof(uint32_t));
  2515. }
  2516. static inline
  2517. void dp_tx_update_sequence_number(qdf_nbuf_t nbuf, uint32_t seq_no)
  2518. {
  2519. struct ieee80211_frame *ptr_wh = NULL;
  2520. uint16_t wh_seq = 0;
  2521. if (!nbuf)
  2522. return;
  2523. /* update sequence number in frame header */
  2524. ptr_wh = (struct ieee80211_frame *)qdf_nbuf_data(nbuf);
  2525. wh_seq = (seq_no & 0xFFF) << 4;
  2526. qdf_mem_copy(ptr_wh->i_seq, &wh_seq, sizeof(uint16_t));
  2527. }
  2528. static inline
  2529. void dp_update_frame_ctrl_from_frame_type(void *desc)
  2530. {
  2531. struct cdp_tx_completion_ppdu *ppdu_desc = desc;
  2532. /* frame control is not set properly, sometimes it is zero */
  2533. switch (ppdu_desc->htt_frame_type) {
  2534. case HTT_STATS_FTYPE_SGEN_NDPA:
  2535. case HTT_STATS_FTYPE_SGEN_NDP:
  2536. case HTT_STATS_FTYPE_SGEN_AX_NDPA:
  2537. case HTT_STATS_FTYPE_SGEN_AX_NDP:
  2538. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_NDPA |
  2539. IEEE80211_FC0_TYPE_CTL);
  2540. break;
  2541. case HTT_STATS_FTYPE_SGEN_BRP:
  2542. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_BRPOLL |
  2543. IEEE80211_FC0_TYPE_CTL);
  2544. break;
  2545. case HTT_STATS_FTYPE_SGEN_RTS:
  2546. case HTT_STATS_FTYPE_SGEN_MU_RTS:
  2547. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_RTS |
  2548. IEEE80211_FC0_TYPE_CTL);
  2549. break;
  2550. case HTT_STATS_FTYPE_SGEN_CTS:
  2551. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_CTS |
  2552. IEEE80211_FC0_TYPE_CTL);
  2553. break;
  2554. case HTT_STATS_FTYPE_SGEN_CFEND:
  2555. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_CF_END |
  2556. IEEE80211_FC0_TYPE_CTL);
  2557. break;
  2558. case HTT_STATS_FTYPE_SGEN_MU_TRIG:
  2559. case HTT_STATS_FTYPE_SGEN_MU_BAR:
  2560. case HTT_STATS_FTYPE_SGEN_MU_BRP:
  2561. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_TRIGGER |
  2562. IEEE80211_FC0_TYPE_CTL);
  2563. break;
  2564. case HTT_STATS_FTYPE_SGEN_BAR:
  2565. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_BAR |
  2566. IEEE80211_FC0_TYPE_CTL);
  2567. break;
  2568. }
  2569. }
  2570. /**
  2571. * dp_send_dummy_mpdu_info_to_stack(): send dummy payload to stack
  2572. * to upper layer if complete
  2573. * @pdev: DP pdev handle
  2574. * @desc: cdp tx completion ppdu desc
  2575. * @usr_idx: user index
  2576. *
  2577. * return: status
  2578. */
  2579. static inline
  2580. QDF_STATUS dp_send_dummy_mpdu_info_to_stack(struct dp_pdev *pdev,
  2581. void *desc, uint8_t usr_idx)
  2582. {
  2583. struct cdp_tx_completion_ppdu *ppdu_desc = desc;
  2584. struct cdp_tx_completion_ppdu_user *user = &ppdu_desc->user[usr_idx];
  2585. struct ieee80211_ctlframe_addr2 *wh_min;
  2586. uint16_t frame_ctrl_le, duration_le;
  2587. struct cdp_tx_indication_info tx_capture_info;
  2588. struct cdp_tx_indication_mpdu_info *mpdu_info;
  2589. uint8_t type, subtype;
  2590. qdf_mem_set(&tx_capture_info,
  2591. sizeof(struct cdp_tx_indication_info),
  2592. 0);
  2593. tx_capture_info.mpdu_nbuf =
  2594. qdf_nbuf_alloc(pdev->soc->osdev,
  2595. MAX_MONITOR_HEADER + MAX_DUMMY_FRM_BODY,
  2596. MAX_MONITOR_HEADER,
  2597. 4, FALSE);
  2598. if (!tx_capture_info.mpdu_nbuf)
  2599. return QDF_STATUS_E_ABORTED;
  2600. mpdu_info = &tx_capture_info.mpdu_info;
  2601. mpdu_info->resp_type = ppdu_desc->resp_type;
  2602. mpdu_info->mprot_type = ppdu_desc->mprot_type;
  2603. mpdu_info->rts_success = ppdu_desc->rts_success;
  2604. mpdu_info->rts_failure = ppdu_desc->rts_failure;
  2605. /* update cdp_tx_indication_mpdu_info */
  2606. dp_tx_update_user_mpdu_info(ppdu_desc->bar_ppdu_id,
  2607. &tx_capture_info.mpdu_info,
  2608. user);
  2609. tx_capture_info.ppdu_desc = ppdu_desc;
  2610. mpdu_info->ppdu_id = ppdu_desc->ppdu_id;
  2611. mpdu_info->channel_num = pdev->operating_channel.num;
  2612. mpdu_info->channel = ppdu_desc->channel;
  2613. mpdu_info->frame_type = ppdu_desc->frame_type;
  2614. mpdu_info->ppdu_start_timestamp = ppdu_desc->ppdu_start_timestamp;
  2615. mpdu_info->ppdu_end_timestamp = ppdu_desc->ppdu_end_timestamp;
  2616. mpdu_info->tx_duration = ppdu_desc->tx_duration;
  2617. mpdu_info->seq_no = user->start_seq;
  2618. qdf_mem_copy(mpdu_info->mac_address, user->mac_addr, QDF_MAC_ADDR_SIZE);
  2619. mpdu_info->ba_start_seq = user->ba_seq_no;
  2620. qdf_mem_copy(mpdu_info->ba_bitmap, user->ba_bitmap,
  2621. CDP_BA_256_BIT_MAP_SIZE_DWORDS * sizeof(uint32_t));
  2622. mpdu_info->frame_ctrl = ppdu_desc->frame_ctrl;
  2623. type = (ppdu_desc->frame_ctrl & IEEE80211_FC0_TYPE_MASK);
  2624. subtype = (ppdu_desc->frame_ctrl & IEEE80211_FC0_SUBTYPE_MASK);
  2625. if (type == IEEE80211_FC0_TYPE_CTL &&
  2626. subtype == IEEE80211_FC0_SUBTYPE_BAR) {
  2627. mpdu_info->frame_ctrl = (IEEE80211_FC0_SUBTYPE_BAR |
  2628. IEEE80211_FC0_TYPE_CTL);
  2629. mpdu_info->ppdu_id = ppdu_desc->bar_ppdu_id;
  2630. mpdu_info->ppdu_start_timestamp =
  2631. ppdu_desc->bar_ppdu_start_timestamp;
  2632. mpdu_info->ppdu_end_timestamp =
  2633. ppdu_desc->bar_ppdu_end_timestamp;
  2634. mpdu_info->tx_duration = ppdu_desc->bar_tx_duration;
  2635. }
  2636. wh_min = (struct ieee80211_ctlframe_addr2 *)
  2637. qdf_nbuf_data(
  2638. tx_capture_info.mpdu_nbuf);
  2639. qdf_mem_zero(wh_min, MAX_DUMMY_FRM_BODY);
  2640. frame_ctrl_le =
  2641. qdf_cpu_to_le16(mpdu_info->frame_ctrl);
  2642. duration_le =
  2643. qdf_cpu_to_le16(mpdu_info->tx_duration);
  2644. wh_min->i_fc[1] = (frame_ctrl_le & 0xFF00) >> 8;
  2645. wh_min->i_fc[0] = (frame_ctrl_le & 0xFF);
  2646. wh_min->i_aidordur[1] = (duration_le & 0xFF00) >> 8;
  2647. wh_min->i_aidordur[0] = (duration_le & 0xFF);
  2648. qdf_mem_copy(wh_min->i_addr1,
  2649. mpdu_info->mac_address,
  2650. QDF_MAC_ADDR_SIZE);
  2651. if (subtype == IEEE80211_FC0_SUBTYPE_ACK)
  2652. qdf_nbuf_set_pktlen(tx_capture_info.mpdu_nbuf,
  2653. sizeof(struct ieee80211_frame_min_one));
  2654. else {
  2655. struct dp_peer *peer;
  2656. struct dp_vdev *vdev = NULL;
  2657. peer = DP_TX_PEER_GET_REF(pdev, user->peer_id);
  2658. if (peer) {
  2659. vdev = peer->vdev;
  2660. if (vdev)
  2661. qdf_mem_copy(wh_min->i_addr2,
  2662. vdev->mac_addr.raw,
  2663. QDF_MAC_ADDR_SIZE);
  2664. DP_TX_PEER_DEL_REF(peer);
  2665. } else {
  2666. vdev =
  2667. dp_vdev_get_ref_by_id(pdev->soc, ppdu_desc->vdev_id,
  2668. DP_MOD_ID_TX_CAPTURE);
  2669. if (vdev) {
  2670. qdf_mem_copy(wh_min->i_addr2,
  2671. vdev->mac_addr.raw,
  2672. QDF_MAC_ADDR_SIZE);
  2673. dp_vdev_unref_delete(pdev->soc, vdev,
  2674. DP_MOD_ID_TX_CAPTURE);
  2675. }
  2676. }
  2677. qdf_nbuf_set_pktlen(tx_capture_info.mpdu_nbuf, sizeof(*wh_min));
  2678. }
  2679. dp_tx_capture_debug("%pK: HTT_FTYPE[%d] frm(0x%08x): fc %x %x, dur 0x%x%x\n",
  2680. pdev->soc, ppdu_desc->htt_frame_type, mpdu_info->ppdu_id,
  2681. wh_min->i_fc[1], wh_min->i_fc[0],
  2682. wh_min->i_aidordur[1], wh_min->i_aidordur[0]);
  2683. /*
  2684. * send MPDU to osif layer
  2685. */
  2686. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  2687. &tx_capture_info, HTT_INVALID_PEER,
  2688. WDI_NO_VAL, pdev->pdev_id);
  2689. if (tx_capture_info.mpdu_nbuf)
  2690. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  2691. return QDF_STATUS_SUCCESS;
  2692. }
  2693. /**
  2694. * dp_send_dummy_rts_cts_frame(): send dummy rts and cts frame out
  2695. * to upper layer if complete
  2696. * @pdev: DP pdev handle
  2697. * @cur_ppdu_desc: cdp tx completion ppdu desc
  2698. *
  2699. * return: void
  2700. */
  2701. static
  2702. void dp_send_dummy_rts_cts_frame(struct dp_pdev *pdev,
  2703. struct cdp_tx_completion_ppdu *cur_ppdu_desc,
  2704. uint8_t usr_id)
  2705. {
  2706. struct cdp_tx_completion_ppdu *ppdu_desc;
  2707. struct dp_pdev_tx_capture *ptr_tx_cap;
  2708. struct dp_peer *peer;
  2709. uint8_t rts_send;
  2710. struct dp_vdev *vdev = NULL;
  2711. rts_send = 0;
  2712. ptr_tx_cap = &pdev->tx_capture;
  2713. ppdu_desc = ptr_tx_cap->dummy_ppdu_desc;
  2714. ppdu_desc->channel = cur_ppdu_desc->channel;
  2715. ppdu_desc->num_mpdu = 1;
  2716. ppdu_desc->num_msdu = 1;
  2717. ppdu_desc->user[usr_id].ppdu_type = HTT_PPDU_STATS_PPDU_TYPE_SU;
  2718. ppdu_desc->bar_num_users = 0;
  2719. ppdu_desc->num_users = 1;
  2720. if (cur_ppdu_desc->mprot_type == SEND_WIFIRTS_LEGACY_E ||
  2721. cur_ppdu_desc->mprot_type == SEND_WIFIRTS_11AC_DYNAMIC_BW_E ||
  2722. cur_ppdu_desc->mprot_type == SEND_WIFIRTS_11AC_STATIC_BW_E) {
  2723. rts_send = 1;
  2724. /*
  2725. * send dummy RTS frame followed by CTS
  2726. * update frame_ctrl and htt_frame_type
  2727. */
  2728. ppdu_desc->htt_frame_type = HTT_STATS_FTYPE_SGEN_RTS;
  2729. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  2730. ppdu_desc->ppdu_start_timestamp =
  2731. cur_ppdu_desc->ppdu_start_timestamp;
  2732. ppdu_desc->ppdu_end_timestamp =
  2733. cur_ppdu_desc->ppdu_end_timestamp;
  2734. ppdu_desc->tx_duration = cur_ppdu_desc->tx_duration;
  2735. ppdu_desc->user[usr_id].peer_id =
  2736. cur_ppdu_desc->user[usr_id].peer_id;
  2737. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_RTS |
  2738. IEEE80211_FC0_TYPE_CTL);
  2739. qdf_mem_copy(&ppdu_desc->user[usr_id].mac_addr,
  2740. &cur_ppdu_desc->user[usr_id].mac_addr,
  2741. QDF_MAC_ADDR_SIZE);
  2742. dp_send_dummy_mpdu_info_to_stack(pdev, ppdu_desc, usr_id);
  2743. }
  2744. if ((rts_send && cur_ppdu_desc->rts_success) ||
  2745. cur_ppdu_desc->mprot_type == SEND_WIFICTS2SELF_E) {
  2746. uint16_t peer_id;
  2747. peer_id = cur_ppdu_desc->user[usr_id].peer_id;
  2748. /* send dummy CTS frame */
  2749. ppdu_desc->htt_frame_type = HTT_STATS_FTYPE_SGEN_CTS;
  2750. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  2751. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_CTS |
  2752. IEEE80211_FC0_TYPE_CTL);
  2753. ppdu_desc->ppdu_start_timestamp =
  2754. cur_ppdu_desc->ppdu_start_timestamp;
  2755. ppdu_desc->ppdu_end_timestamp =
  2756. cur_ppdu_desc->ppdu_end_timestamp;
  2757. ppdu_desc->tx_duration = cur_ppdu_desc->tx_duration -
  2758. (RTS_INTERVAL + SIFS_INTERVAL);
  2759. ppdu_desc->user[usr_id].peer_id = peer_id;
  2760. peer = DP_TX_PEER_GET_REF(pdev, peer_id);
  2761. if (peer) {
  2762. vdev = peer->vdev;
  2763. if (vdev)
  2764. qdf_mem_copy(&ppdu_desc->user[usr_id].mac_addr,
  2765. vdev->mac_addr.raw,
  2766. QDF_MAC_ADDR_SIZE);
  2767. DP_TX_PEER_DEL_REF(peer);
  2768. } else {
  2769. uint8_t vdev_id;
  2770. vdev_id = ppdu_desc->vdev_id;
  2771. vdev = dp_vdev_get_ref_by_id(pdev->soc, vdev_id,
  2772. DP_MOD_ID_TX_CAPTURE);
  2773. if (vdev) {
  2774. qdf_mem_copy(&ppdu_desc->user[usr_id].mac_addr,
  2775. vdev->mac_addr.raw,
  2776. QDF_MAC_ADDR_SIZE);
  2777. dp_vdev_unref_delete(pdev->soc, vdev,
  2778. DP_MOD_ID_TX_CAPTURE);
  2779. }
  2780. }
  2781. dp_send_dummy_mpdu_info_to_stack(pdev, ppdu_desc, usr_id);
  2782. }
  2783. }
  2784. static void dp_gen_ack_rx_frame(struct dp_pdev *pdev,
  2785. struct cdp_tx_indication_info *tx_capture_info)
  2786. {
  2787. struct cdp_tx_completion_ppdu *ppdu_desc;
  2788. struct dp_peer *peer;
  2789. struct dp_pdev_tx_capture *ptr_tx_cap;
  2790. ptr_tx_cap = &pdev->tx_capture;
  2791. ppdu_desc = ptr_tx_cap->dummy_ppdu_desc;
  2792. ppdu_desc->channel = tx_capture_info->ppdu_desc->channel;
  2793. ppdu_desc->num_mpdu = 1;
  2794. ppdu_desc->num_msdu = 1;
  2795. ppdu_desc->user[0].ppdu_type = HTT_PPDU_STATS_PPDU_TYPE_SU;
  2796. ppdu_desc->bar_num_users = 0;
  2797. ppdu_desc->num_users = 1;
  2798. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  2799. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_ACK |
  2800. IEEE80211_FC0_TYPE_CTL);
  2801. ppdu_desc->ppdu_start_timestamp =
  2802. tx_capture_info->ppdu_desc->ppdu_start_timestamp;
  2803. ppdu_desc->ppdu_end_timestamp =
  2804. tx_capture_info->ppdu_desc->ppdu_end_timestamp;
  2805. ppdu_desc->user[0].peer_id =
  2806. tx_capture_info->ppdu_desc->user[0].peer_id;
  2807. peer = DP_TX_PEER_GET_REF(pdev,
  2808. tx_capture_info->ppdu_desc->user[0].peer_id);
  2809. if (peer) {
  2810. struct dp_vdev *vdev = NULL;
  2811. vdev = peer->vdev;
  2812. if (vdev)
  2813. qdf_mem_copy(&ppdu_desc->user[0].mac_addr,
  2814. vdev->mac_addr.raw,
  2815. QDF_MAC_ADDR_SIZE);
  2816. DP_TX_PEER_DEL_REF(peer);
  2817. }
  2818. dp_send_dummy_mpdu_info_to_stack(pdev, ppdu_desc, 0);
  2819. }
  2820. /**
  2821. * dp_send_data_to_stack(): Function to deliver mpdu info to stack
  2822. * to upper layer
  2823. * @pdev: DP pdev handle
  2824. * @nbuf_ppdu_list: ppdu_desc_list per sched cmd id
  2825. * @ppdu_desc_cnt: number of ppdu_desc_cnt
  2826. *
  2827. * return: status
  2828. */
  2829. static
  2830. void dp_send_data_to_stack(struct dp_pdev *pdev,
  2831. struct cdp_tx_completion_ppdu *ppdu_desc,
  2832. uint8_t usr_idx)
  2833. {
  2834. struct cdp_tx_completion_ppdu_user *user = NULL;
  2835. struct cdp_tx_indication_info tx_capture_info;
  2836. struct cdp_tx_indication_mpdu_info *mpdu_info;
  2837. int i;
  2838. uint32_t seq_no, start_seq;
  2839. uint32_t ppdu_id;
  2840. uint32_t mpdu_tried;
  2841. uint32_t mpdu_enq = 0;
  2842. struct dp_peer *peer;
  2843. if (!ppdu_desc)
  2844. return;
  2845. ppdu_id = ppdu_desc->ppdu_id;
  2846. user = &ppdu_desc->user[usr_idx];
  2847. peer = DP_TX_PEER_GET_REF(pdev, user->peer_id);
  2848. if (!peer) {
  2849. return;
  2850. }
  2851. qdf_mem_set(&tx_capture_info,
  2852. sizeof(struct cdp_tx_indication_info),
  2853. 0);
  2854. mpdu_info = &tx_capture_info.mpdu_info;
  2855. mpdu_info->usr_idx = usr_idx;
  2856. mpdu_info->channel = ppdu_desc->channel;
  2857. mpdu_info->frame_type = ppdu_desc->frame_type;
  2858. mpdu_info->ppdu_start_timestamp =
  2859. ppdu_desc->ppdu_start_timestamp;
  2860. mpdu_info->ppdu_end_timestamp =
  2861. ppdu_desc->ppdu_end_timestamp;
  2862. mpdu_info->tx_duration = ppdu_desc->tx_duration;
  2863. mpdu_info->num_msdu = ppdu_desc->num_msdu;
  2864. mpdu_info->resp_type = ppdu_desc->resp_type;
  2865. mpdu_info->mprot_type = ppdu_desc->mprot_type;
  2866. mpdu_info->rts_success = ppdu_desc->rts_success;
  2867. mpdu_info->rts_failure = ppdu_desc->rts_failure;
  2868. /* update cdp_tx_indication_mpdu_info */
  2869. dp_tx_update_user_mpdu_info(ppdu_id,
  2870. &tx_capture_info.mpdu_info,
  2871. user);
  2872. tx_capture_info.ppdu_desc = ppdu_desc;
  2873. tx_capture_info.mpdu_info.channel_num = pdev->operating_channel.num;
  2874. if (ppdu_desc->mprot_type && (usr_idx == 0))
  2875. dp_send_dummy_rts_cts_frame(pdev, ppdu_desc, usr_idx);
  2876. start_seq = user->start_seq;
  2877. if (!user->mpdus)
  2878. goto return_send_to_stack;
  2879. mpdu_tried = user->mpdu_tried_ucast + user->mpdu_tried_mcast;
  2880. for (i = 0; i < CDP_BA_256_BIT_MAP_SIZE_DWORDS; i++)
  2881. mpdu_enq += get_number_of_1s(user->enq_bitmap[i]);
  2882. if (mpdu_tried > mpdu_enq)
  2883. dp_ppdu_desc_debug_print(ppdu_desc, usr_idx,
  2884. __func__, __LINE__);
  2885. for (i = 0; i < user->ba_size && mpdu_tried; i++) {
  2886. if (qdf_likely(user->tid != DP_NON_QOS_TID) &&
  2887. !(SEQ_BIT(user->enq_bitmap, i))) {
  2888. continue;
  2889. }
  2890. mpdu_tried--;
  2891. seq_no = start_seq + i;
  2892. if (!user->mpdus[i])
  2893. continue;
  2894. tx_capture_info.mpdu_nbuf = user->mpdus[i];
  2895. dp_tx_cap_stats_mpdu_update(peer, PEER_MPDU_TO_STACK, 1);
  2896. user->mpdus[i] = NULL;
  2897. mpdu_info->seq_no = seq_no;
  2898. dp_tx_update_sequence_number(tx_capture_info.mpdu_nbuf, seq_no);
  2899. /*
  2900. * send MPDU to osif layer
  2901. * do we need to update mpdu_info before tranmit
  2902. * get current mpdu_nbuf
  2903. */
  2904. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  2905. &tx_capture_info,
  2906. HTT_INVALID_PEER,
  2907. WDI_NO_VAL, pdev->pdev_id);
  2908. if (tx_capture_info.mpdu_nbuf)
  2909. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  2910. }
  2911. if (ppdu_desc->resp_type == HTT_PPDU_STATS_ACK_EXPECTED_E &&
  2912. ppdu_desc->user[usr_idx].completion_status ==
  2913. HTT_PPDU_STATS_USER_STATUS_OK)
  2914. dp_gen_ack_rx_frame(pdev, &tx_capture_info);
  2915. return_send_to_stack:
  2916. DP_TX_PEER_DEL_REF(peer);
  2917. return;
  2918. }
  2919. /**
  2920. * dp_ppdu_desc_free(): Function to free ppdu_desc and stored queue
  2921. * @ptr_nbuf_list: pointer to ptr_nbuf_list
  2922. * @usr_idx: user index
  2923. *
  2924. * return: void
  2925. */
  2926. static void dp_ppdu_desc_free(struct dp_tx_cap_nbuf_list *ptr_nbuf_list,
  2927. uint8_t usr_idx)
  2928. {
  2929. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  2930. qdf_nbuf_t tmp_nbuf;
  2931. if (!ptr_nbuf_list->nbuf_ppdu ||
  2932. !dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list))
  2933. return;
  2934. tmp_nbuf = ptr_nbuf_list->nbuf_ppdu;
  2935. if (tmp_nbuf) {
  2936. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  2937. qdf_nbuf_data(tmp_nbuf);
  2938. dp_ppdu_queue_free(tmp_nbuf, usr_idx);
  2939. dp_tx_cap_nbuf_list_dec_ref(ptr_nbuf_list);
  2940. qdf_nbuf_free(tmp_nbuf);
  2941. }
  2942. }
  2943. /**
  2944. * dp_ppdu_desc_free_all(): Function to free all user in a ppdu_desc and
  2945. * its stored queue
  2946. * @ptr_nbuf_list: pointer to ptr_nbuf_list
  2947. * @max_users: maximum number of users
  2948. *
  2949. * return: void
  2950. */
  2951. static void dp_ppdu_desc_free_all(struct dp_tx_cap_nbuf_list *ptr_nbuf_list,
  2952. uint8_t max_users)
  2953. {
  2954. uint8_t i = 0;
  2955. for (i = 0; i < max_users; i++)
  2956. dp_ppdu_desc_free(ptr_nbuf_list, i);
  2957. }
  2958. /**
  2959. * dp_tx_mon_get_next_mpdu(): get next mpdu from retry queue.
  2960. * @tx_tid: tx capture peer tid
  2961. * @xretry_user: pointer to ppdu_desc user.
  2962. * @mpdu_nbuf: mpdu nbuf
  2963. * @ppdu_nbuf: ppdu nbuf from pending ppdu q
  2964. *
  2965. * return: qdf_nbuf_t
  2966. */
  2967. static qdf_nbuf_t
  2968. dp_tx_mon_get_next_mpdu(struct dp_pdev *pdev, struct dp_tx_tid *tx_tid,
  2969. struct cdp_tx_completion_ppdu_user *xretry_user,
  2970. qdf_nbuf_t mpdu_nbuf, qdf_nbuf_t ppdu_nbuf)
  2971. {
  2972. qdf_nbuf_t next_nbuf = NULL;
  2973. qdf_nbuf_queue_t temp_xretries;
  2974. qdf_nbuf_t first_nbuf = NULL;
  2975. qdf_nbuf_t temp_nbuf = NULL;
  2976. if (mpdu_nbuf != qdf_nbuf_queue_first(&xretry_user->mpdu_q)) {
  2977. next_nbuf = qdf_nbuf_queue_next(mpdu_nbuf);
  2978. dp_tx_capture_info("%pK: mpdu %p not head, next %p mpdu_q[%p L %d] ppdu %p",
  2979. pdev->soc, mpdu_nbuf, next_nbuf,
  2980. &xretry_user->mpdu_q,
  2981. qdf_nbuf_queue_len(&xretry_user->mpdu_q), ppdu_nbuf);
  2982. /* Initialize temp list */
  2983. qdf_nbuf_queue_init(&temp_xretries);
  2984. /* Move entries into temp list till the mpdu_nbuf is found */
  2985. first_nbuf = qdf_nbuf_queue_first(&xretry_user->mpdu_q);
  2986. while (first_nbuf && (mpdu_nbuf != first_nbuf)) {
  2987. /* remove nbuf from queue */
  2988. temp_nbuf = qdf_nbuf_queue_remove(&xretry_user->mpdu_q);
  2989. qdf_nbuf_queue_add(&temp_xretries, temp_nbuf);
  2990. /* get first nbuf from queue again */
  2991. first_nbuf = qdf_nbuf_queue_first(&xretry_user->mpdu_q);
  2992. }
  2993. if (first_nbuf && (mpdu_nbuf == first_nbuf)) {
  2994. /* Remove mpdu_nbuf from queue */
  2995. qdf_nbuf_queue_remove(&xretry_user->mpdu_q);
  2996. /* Add remaining nbufs into temp queue */
  2997. qdf_nbuf_queue_append(&temp_xretries,
  2998. &xretry_user->mpdu_q);
  2999. /* Reinit xretry_user->mpdu_q */
  3000. qdf_nbuf_queue_init(&xretry_user->mpdu_q);
  3001. /* append all the entries into original queue */
  3002. qdf_nbuf_queue_append(&xretry_user->mpdu_q,
  3003. &temp_xretries);
  3004. } else {
  3005. dp_tx_capture_alert("%pK: bug scenario, did not find nbuf in queue\npdev %p "
  3006. "peer id %d, tid: %p mpdu_nbuf %p xretry_user %p "
  3007. "mpdu_q %p len %d temp_xretry %p",
  3008. pdev->soc, pdev, tx_tid->peer_id, tx_tid, mpdu_nbuf,
  3009. xretry_user, xretry_user->mpdu_q,
  3010. qdf_nbuf_queue_len(&xretry_user->mpdu_q),
  3011. &temp_xretries);
  3012. qdf_assert_always(0);
  3013. }
  3014. } else {
  3015. qdf_nbuf_queue_remove(&xretry_user->mpdu_q);
  3016. next_nbuf = qdf_nbuf_queue_first(&xretry_user->mpdu_q);
  3017. }
  3018. return next_nbuf;
  3019. }
  3020. static void
  3021. dp_tx_mon_proc_xretries(struct dp_pdev *pdev, struct dp_peer *peer,
  3022. uint16_t tid)
  3023. {
  3024. struct dp_tx_tid *tx_tid = &peer->tx_capture.tx_tid[tid];
  3025. struct cdp_tx_completion_ppdu *ppdu_desc;
  3026. struct cdp_tx_completion_ppdu *xretry_ppdu;
  3027. struct cdp_tx_completion_ppdu_user *user = NULL;
  3028. struct cdp_tx_completion_ppdu_user *xretry_user = NULL;
  3029. qdf_nbuf_t ppdu_nbuf;
  3030. qdf_nbuf_t mpdu_nbuf;
  3031. uint32_t mpdu_tried = 0;
  3032. int i;
  3033. uint32_t seq_no;
  3034. uint8_t usr_idx = 0;
  3035. xretry_ppdu = tx_tid->xretry_ppdu;
  3036. if (!xretry_ppdu) {
  3037. dp_tx_capture_alert("%pK: xretry_ppdu is NULL",
  3038. pdev->soc);
  3039. return;
  3040. }
  3041. xretry_user = &xretry_ppdu->user[0];
  3042. if (!xretry_user) {
  3043. dp_tx_capture_alert("%pK: xretry_user is NULL",
  3044. pdev->soc);
  3045. return;
  3046. }
  3047. if (qdf_nbuf_is_queue_empty(&tx_tid->pending_ppdu_q)) {
  3048. TX_CAP_NBUF_QUEUE_FREE(&xretry_user->mpdu_q);
  3049. return;
  3050. }
  3051. if (qdf_nbuf_is_queue_empty(&xretry_user->mpdu_q))
  3052. return;
  3053. ppdu_nbuf = qdf_nbuf_queue_first(&tx_tid->pending_ppdu_q);
  3054. while (ppdu_nbuf) {
  3055. struct msdu_completion_info *ptr_msdu_info = NULL;
  3056. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3057. qdf_nbuf_data(ppdu_nbuf);
  3058. usr_idx = dp_tx_find_usr_idx_from_peer_id(ppdu_desc,
  3059. tx_tid->peer_id);
  3060. user = &ppdu_desc->user[usr_idx];
  3061. if (user->pending_retries) {
  3062. uint32_t start_seq = user->start_seq;
  3063. uint32_t index = 0;
  3064. mpdu_tried = user->mpdu_tried_ucast +
  3065. user->mpdu_tried_mcast;
  3066. mpdu_nbuf = qdf_nbuf_queue_first(&xretry_user->mpdu_q);
  3067. for (i = 0;
  3068. (i < user->ba_size) &&
  3069. (mpdu_tried > 0) && mpdu_nbuf;
  3070. i++) {
  3071. if (!(SEQ_BIT(user->enq_bitmap, i)))
  3072. continue;
  3073. mpdu_tried--;
  3074. /* missed seq number */
  3075. seq_no = start_seq + i;
  3076. if (SEQ_BIT(user->failed_bitmap, i))
  3077. continue;
  3078. dp_tx_capture_info("%pK: fill seqno %d from xretries",
  3079. pdev->soc, seq_no);
  3080. ptr_msdu_info = (struct msdu_completion_info *)
  3081. (qdf_nbuf_data(qdf_nbuf_get_ext_list(
  3082. mpdu_nbuf)) -
  3083. (sizeof(struct msdu_completion_info) +
  3084. sizeof(qdf_ether_header_t)));
  3085. ptr_msdu_info->transmit_cnt--;
  3086. SEQ_SEG(user->failed_bitmap, i) |=
  3087. SEQ_SEG_MSK(user->failed_bitmap[0], i);
  3088. user->pending_retries--;
  3089. if (ptr_msdu_info->transmit_cnt == 0) {
  3090. index = seq_no - start_seq;
  3091. CHECK_MPDUS_NULL(user->mpdus[index]);
  3092. user->mpdus[index] = mpdu_nbuf;
  3093. dp_tx_cap_stats_mpdu_update(peer,
  3094. PEER_MPDU_ARR, 1);
  3095. /*
  3096. * This API removes mpdu_nbuf from q
  3097. * and returns next mpdu from the queue
  3098. */
  3099. mpdu_nbuf = dp_tx_mon_get_next_mpdu(pdev,
  3100. tx_tid,
  3101. xretry_user, mpdu_nbuf,
  3102. ppdu_nbuf);
  3103. } else {
  3104. index = seq_no - start_seq;
  3105. CHECK_MPDUS_NULL(user->mpdus[index]);
  3106. user->mpdus[index] =
  3107. qdf_nbuf_copy_expand_fraglist(
  3108. mpdu_nbuf,
  3109. MAX_MONITOR_HEADER, 0);
  3110. dp_tx_cap_stats_mpdu_update(peer,
  3111. PEER_MPDU_CLONE, 1);
  3112. mpdu_nbuf =
  3113. qdf_nbuf_queue_next(mpdu_nbuf);
  3114. }
  3115. }
  3116. }
  3117. if ((user->pending_retries == 0) &&
  3118. (ppdu_nbuf ==
  3119. qdf_nbuf_queue_first(&tx_tid->pending_ppdu_q))) {
  3120. qdf_nbuf_queue_remove(&tx_tid->pending_ppdu_q);
  3121. /* Deliver PPDU */
  3122. dp_send_data_to_stack(pdev, ppdu_desc, usr_idx);
  3123. dp_ppdu_queue_free(ppdu_nbuf, usr_idx);
  3124. qdf_nbuf_free(ppdu_nbuf);
  3125. ppdu_nbuf = qdf_nbuf_queue_first(
  3126. &tx_tid->pending_ppdu_q);
  3127. } else {
  3128. ppdu_nbuf = qdf_nbuf_queue_next(ppdu_nbuf);
  3129. }
  3130. }
  3131. TX_CAP_NBUF_QUEUE_FREE(&xretry_user->mpdu_q);
  3132. }
  3133. static
  3134. struct cdp_tx_completion_ppdu *
  3135. check_subseq_ppdu_to_pending_q(struct dp_tx_cap_nbuf_list nbuf_ppdu_list[],
  3136. uint32_t ppdu_desc_cnt,
  3137. uint32_t *ppdu_cnt,
  3138. qdf_nbuf_queue_t *head_ppdu,
  3139. uint32_t peer_id, uint32_t cur_last_seq,
  3140. bool last_pend_ppdu)
  3141. {
  3142. struct cdp_tx_completion_ppdu *next_ppdu = NULL;
  3143. struct cdp_tx_completion_ppdu_user *next_user;
  3144. struct dp_tx_cap_nbuf_list *ptr_nbuf_list = NULL;
  3145. uint8_t cur_usr_idx;
  3146. while (*ppdu_cnt < (ppdu_desc_cnt - 1)) {
  3147. (*ppdu_cnt)++;
  3148. ptr_nbuf_list = &nbuf_ppdu_list[*ppdu_cnt];
  3149. if (!ptr_nbuf_list->nbuf_ppdu ||
  3150. !dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list))
  3151. continue;
  3152. next_ppdu = (struct cdp_tx_completion_ppdu *)
  3153. qdf_nbuf_data(ptr_nbuf_list->nbuf_ppdu);
  3154. if (!next_ppdu)
  3155. continue;
  3156. cur_usr_idx = dp_tx_find_usr_idx_from_peer_id(next_ppdu,
  3157. peer_id);
  3158. next_user = &next_ppdu->user[cur_usr_idx];
  3159. if ((next_user->skip == 1) || (peer_id != next_user->peer_id) ||
  3160. (next_user->mon_procd == 1))
  3161. continue;
  3162. if (last_pend_ppdu) {
  3163. qdf_nbuf_t tmp_pend_nbuf;
  3164. uint32_t ppdu_ref_cnt;
  3165. /*
  3166. * get reference count if it
  3167. * more than one do clone and
  3168. * add that to head_ppdu
  3169. */
  3170. ppdu_ref_cnt =
  3171. dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list);
  3172. if (ppdu_ref_cnt == 1) {
  3173. tmp_pend_nbuf = ptr_nbuf_list->nbuf_ppdu;
  3174. } else {
  3175. tmp_pend_nbuf = qdf_nbuf_clone(
  3176. ptr_nbuf_list->nbuf_ppdu);
  3177. if (qdf_unlikely(!tmp_pend_nbuf)) {
  3178. qdf_assert_always(0);
  3179. continue;
  3180. }
  3181. qdf_nbuf_free(ptr_nbuf_list->nbuf_ppdu);
  3182. }
  3183. qdf_nbuf_queue_add(head_ppdu, tmp_pend_nbuf);
  3184. /* decrement reference */
  3185. dp_tx_cap_nbuf_list_dec_ref(ptr_nbuf_list);
  3186. next_user->mon_procd = 1;
  3187. }
  3188. if (next_user->last_enq_seq > cur_last_seq)
  3189. return next_ppdu;
  3190. }
  3191. return NULL;
  3192. }
  3193. #define MAX_PENDING_PPDUS 32
  3194. static void
  3195. dp_tx_mon_proc_pending_ppdus(struct dp_pdev *pdev, struct dp_tx_tid *tx_tid,
  3196. struct dp_tx_cap_nbuf_list nbuf_ppdu_list[],
  3197. uint32_t ppdu_desc_cnt, qdf_nbuf_queue_t *head_ppdu,
  3198. uint32_t peer_id, uint8_t cur_usr_idx)
  3199. {
  3200. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  3201. struct cdp_tx_completion_ppdu *cur_ppdu_desc = NULL;
  3202. struct cdp_tx_completion_ppdu_user *user = NULL;
  3203. struct cdp_tx_completion_ppdu_user *cur_user = NULL;
  3204. struct dp_tx_cap_nbuf_list *ptr_nbuf_list = NULL;
  3205. qdf_nbuf_t pend_ppdu;
  3206. uint32_t ppdu_cnt;
  3207. uint32_t failed_seq;
  3208. uint32_t cur_index, cur_start_seq, cur_last_seq;
  3209. int i, k;
  3210. bool last_pend_ppdu = false;
  3211. uint8_t usr_idx;
  3212. pend_ppdu = qdf_nbuf_queue_first(&tx_tid->pending_ppdu_q);
  3213. if (!pend_ppdu) {
  3214. for (ppdu_cnt = 0; ppdu_cnt < ppdu_desc_cnt; ppdu_cnt++) {
  3215. ptr_nbuf_list = &nbuf_ppdu_list[ppdu_cnt];
  3216. if (!dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list)) {
  3217. if (ptr_nbuf_list->nbuf_ppdu)
  3218. qdf_assert_always(0);
  3219. continue;
  3220. }
  3221. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3222. qdf_nbuf_data(ptr_nbuf_list->nbuf_ppdu);
  3223. if (!ppdu_desc)
  3224. continue;
  3225. user = &ppdu_desc->user[cur_usr_idx];
  3226. if ((user->skip == 1) || (peer_id != user->peer_id) ||
  3227. (tx_tid->tid != user->tid) || (user->mon_procd == 1))
  3228. continue;
  3229. if ((user->pending_retries == 0) &&
  3230. qdf_nbuf_is_queue_empty(&tx_tid->pending_ppdu_q) &&
  3231. qdf_nbuf_is_queue_empty(head_ppdu)) {
  3232. dp_send_data_to_stack(pdev, ppdu_desc,
  3233. cur_usr_idx);
  3234. user->mon_procd = 1;
  3235. /* free ppd_desc from list */
  3236. dp_ppdu_desc_free(ptr_nbuf_list, cur_usr_idx);
  3237. } else {
  3238. qdf_nbuf_t tmp_pend_nbuf;
  3239. uint32_t ppdu_ref_cnt;
  3240. /*
  3241. * get reference count if it more than one
  3242. * do clone and add that to head_ppdu
  3243. */
  3244. ppdu_ref_cnt =
  3245. dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list);
  3246. if (ppdu_ref_cnt == 1) {
  3247. tmp_pend_nbuf =
  3248. ptr_nbuf_list->nbuf_ppdu;
  3249. } else {
  3250. tmp_pend_nbuf =
  3251. qdf_nbuf_clone(
  3252. ptr_nbuf_list->nbuf_ppdu);
  3253. if (qdf_unlikely(!tmp_pend_nbuf)) {
  3254. qdf_assert_always(0);
  3255. continue;
  3256. }
  3257. /*
  3258. * free ppdu_desc to
  3259. * decrease reference
  3260. */
  3261. qdf_nbuf_free(ptr_nbuf_list->nbuf_ppdu);
  3262. }
  3263. qdf_nbuf_queue_add(head_ppdu, tmp_pend_nbuf);
  3264. /* decrement reference */
  3265. dp_tx_cap_nbuf_list_dec_ref(ptr_nbuf_list);
  3266. user->mon_procd = 1;
  3267. }
  3268. }
  3269. return;
  3270. }
  3271. while (pend_ppdu) {
  3272. qdf_nbuf_t mpdu_nbuf;
  3273. uint32_t mpdu_tried = 0;
  3274. /* Find missing mpdus from current schedule list */
  3275. ppdu_cnt = 0;
  3276. while (ppdu_cnt < ppdu_desc_cnt) {
  3277. ptr_nbuf_list = &nbuf_ppdu_list[ppdu_cnt];
  3278. ppdu_cnt++;
  3279. if (!dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list))
  3280. continue;
  3281. cur_ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3282. qdf_nbuf_data(ptr_nbuf_list->nbuf_ppdu);
  3283. if (!cur_ppdu_desc)
  3284. continue;
  3285. cur_usr_idx = dp_tx_find_usr_idx_from_peer_id(
  3286. cur_ppdu_desc, peer_id);
  3287. cur_user = &cur_ppdu_desc->user[cur_usr_idx];
  3288. if ((cur_user->skip == 1) ||
  3289. (cur_user->mon_procd == 1))
  3290. continue;
  3291. /* to handle last ppdu case we need to decrement */
  3292. ppdu_cnt--;
  3293. break;
  3294. }
  3295. if (ppdu_cnt == ppdu_desc_cnt)
  3296. break;
  3297. if (qdf_unlikely(!cur_user))
  3298. break;
  3299. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(
  3300. pend_ppdu);
  3301. usr_idx = dp_tx_find_usr_idx_from_peer_id(ppdu_desc,
  3302. peer_id);
  3303. user = &ppdu_desc->user[usr_idx];
  3304. if (pend_ppdu == qdf_nbuf_queue_last(
  3305. &tx_tid->pending_ppdu_q)) {
  3306. qdf_nbuf_t tmp_pend_nbuf;
  3307. uint32_t ppdu_ref_cnt;
  3308. last_pend_ppdu = true;
  3309. /*
  3310. * get reference count if it more than one
  3311. * do clone and add that to head_ppdu
  3312. */
  3313. ppdu_ref_cnt =
  3314. dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list);
  3315. if (ppdu_ref_cnt == 1) {
  3316. tmp_pend_nbuf =
  3317. ptr_nbuf_list->nbuf_ppdu;
  3318. } else {
  3319. tmp_pend_nbuf = qdf_nbuf_clone(
  3320. ptr_nbuf_list->nbuf_ppdu);
  3321. if (qdf_unlikely(!tmp_pend_nbuf)) {
  3322. qdf_assert_always(0);
  3323. break;
  3324. }
  3325. qdf_nbuf_free(ptr_nbuf_list->nbuf_ppdu);
  3326. }
  3327. qdf_nbuf_queue_add(head_ppdu, tmp_pend_nbuf);
  3328. /* decrement reference */
  3329. dp_tx_cap_nbuf_list_dec_ref(ptr_nbuf_list);
  3330. cur_user->mon_procd = 1;
  3331. }
  3332. cur_index = 0;
  3333. cur_start_seq = cur_user->start_seq;
  3334. cur_last_seq = cur_user->last_enq_seq;
  3335. if (qdf_unlikely(user->ba_size >
  3336. CDP_BA_256_BIT_MAP_SIZE_DWORDS *
  3337. SEQ_SEG_SZ_BITS(user->failed_bitmap))) {
  3338. dp_ppdu_desc_debug_print(ppdu_desc, usr_idx,
  3339. __func__, __LINE__);
  3340. qdf_assert_always(0);
  3341. return;
  3342. }
  3343. /* mpdu tried */
  3344. mpdu_tried = user->mpdu_tried_mcast + user->mpdu_tried_ucast;
  3345. for (i = 0; (i < user->ba_size) && cur_ppdu_desc &&
  3346. mpdu_tried && cur_index < cur_user->ba_size; i++) {
  3347. if (!(i & (SEQ_SEG_SZ_BITS(user->failed_bitmap) - 1))) {
  3348. k = SEQ_SEG_INDEX(user->failed_bitmap, i);
  3349. failed_seq = user->failed_bitmap[k] ^
  3350. user->enq_bitmap[k];
  3351. }
  3352. if (SEQ_BIT(user->enq_bitmap, i))
  3353. mpdu_tried--;
  3354. /* Skip to next bitmap segment if there are no
  3355. * more holes in current segment
  3356. */
  3357. if (!failed_seq) {
  3358. i = ((k + 1) *
  3359. SEQ_SEG_SZ_BITS(user->failed_bitmap)) - 1;
  3360. continue;
  3361. }
  3362. if (!(SEQ_SEG_BIT(failed_seq, i)))
  3363. continue;
  3364. failed_seq ^= SEQ_SEG_MSK(failed_seq, i);
  3365. if (!cur_user->mpdus) {
  3366. dp_tx_capture_info("%pK: peer_id:%d usr_idx:%d cur_usr_idx:%d cur_usr_peer_id:%d\n",
  3367. pdev->soc,
  3368. peer_id, usr_idx,
  3369. cur_usr_idx, cur_user->peer_id);
  3370. continue;
  3371. }
  3372. mpdu_nbuf = cur_user->mpdus[cur_index];
  3373. if (mpdu_nbuf) {
  3374. struct dp_peer *peer;
  3375. dp_tx_capture_info("%pK: fill seqno %d (%d) from swretries",
  3376. pdev->soc,
  3377. user->start_seq + i,
  3378. ppdu_desc->ppdu_id);
  3379. CHECK_MPDUS_NULL(user->mpdus[i]);
  3380. user->mpdus[i] =
  3381. qdf_nbuf_copy_expand_fraglist(
  3382. mpdu_nbuf, MAX_MONITOR_HEADER, 0);
  3383. peer = DP_TX_PEER_GET_REF(pdev, user->peer_id);
  3384. if (peer) {
  3385. dp_tx_cap_stats_mpdu_update(peer,
  3386. PEER_MPDU_CLONE, 1);
  3387. DP_TX_PEER_DEL_REF(peer);
  3388. }
  3389. user->failed_bitmap[k] |=
  3390. SEQ_SEG_MSK(user->failed_bitmap[k], i);
  3391. user->pending_retries--;
  3392. }
  3393. cur_index++;
  3394. if (cur_index >= cur_user->ba_size) {
  3395. dp_tx_capture_info("%pK: ba_size[%d] cur_index[%d]\n",
  3396. pdev->soc, cur_user->ba_size, cur_index);
  3397. break;
  3398. }
  3399. /* Skip through empty slots in current PPDU */
  3400. while (!(SEQ_BIT(cur_user->enq_bitmap, cur_index))) {
  3401. cur_index++;
  3402. if (cur_index <= (cur_last_seq - cur_start_seq))
  3403. continue;
  3404. cur_ppdu_desc = NULL;
  3405. /*
  3406. * Check if subsequent PPDUs in this schedule
  3407. * has higher sequence numbers enqueued
  3408. */
  3409. cur_ppdu_desc = check_subseq_ppdu_to_pending_q(
  3410. nbuf_ppdu_list,
  3411. ppdu_desc_cnt,
  3412. &ppdu_cnt,
  3413. head_ppdu,
  3414. peer_id,
  3415. cur_last_seq,
  3416. last_pend_ppdu);
  3417. if (!cur_ppdu_desc)
  3418. break;
  3419. cur_usr_idx = dp_tx_find_usr_idx_from_peer_id(
  3420. cur_ppdu_desc, peer_id);
  3421. cur_user = &cur_ppdu_desc->user[cur_usr_idx];
  3422. /* Start from seq. no following cur_last_seq
  3423. * since everything before is already populated
  3424. * from previous PPDU
  3425. */
  3426. cur_start_seq = cur_user->start_seq;
  3427. cur_index = (cur_last_seq >= cur_start_seq) ?
  3428. cur_last_seq - cur_start_seq + 1 : 0;
  3429. cur_last_seq = cur_user->last_enq_seq;
  3430. }
  3431. }
  3432. if ((pend_ppdu ==
  3433. qdf_nbuf_queue_first(&tx_tid->pending_ppdu_q)) &&
  3434. (user->pending_retries == 0)) {
  3435. qdf_nbuf_queue_remove(&tx_tid->pending_ppdu_q);
  3436. dp_send_data_to_stack(pdev, ppdu_desc, usr_idx);
  3437. dp_ppdu_queue_free(pend_ppdu, usr_idx);
  3438. qdf_nbuf_free(pend_ppdu);
  3439. pend_ppdu = qdf_nbuf_queue_first(
  3440. &tx_tid->pending_ppdu_q);
  3441. } else {
  3442. pend_ppdu = qdf_nbuf_queue_next(pend_ppdu);
  3443. }
  3444. }
  3445. }
  3446. static uint32_t
  3447. dp_send_mgmt_ctrl_to_stack(struct dp_pdev *pdev,
  3448. qdf_nbuf_t nbuf_ppdu_desc,
  3449. struct cdp_tx_indication_info *ptr_tx_cap_info,
  3450. qdf_nbuf_t mgmt_ctl_nbuf,
  3451. bool is_payload)
  3452. {
  3453. struct cdp_tx_completion_ppdu *ppdu_desc;
  3454. struct cdp_tx_completion_ppdu_user *user;
  3455. struct cdp_tx_indication_mpdu_info *mpdu_info;
  3456. struct ieee80211_frame *wh;
  3457. uint16_t duration_le, seq_le;
  3458. struct ieee80211_frame_min_one *wh_min;
  3459. uint16_t frame_ctrl_le;
  3460. uint8_t type, subtype;
  3461. mpdu_info = &ptr_tx_cap_info->mpdu_info;
  3462. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3463. qdf_nbuf_data(nbuf_ppdu_desc);
  3464. user = &ppdu_desc->user[0];
  3465. if (ppdu_desc->mprot_type)
  3466. dp_send_dummy_rts_cts_frame(pdev, ppdu_desc, 0);
  3467. type = (ppdu_desc->frame_ctrl &
  3468. IEEE80211_FC0_TYPE_MASK) >>
  3469. IEEE80211_FC0_TYPE_SHIFT;
  3470. subtype = (ppdu_desc->frame_ctrl &
  3471. IEEE80211_FC0_SUBTYPE_MASK) >>
  3472. IEEE80211_FC0_SUBTYPE_SHIFT;
  3473. if (is_payload) {
  3474. wh = (struct ieee80211_frame *)qdf_nbuf_data(mgmt_ctl_nbuf);
  3475. if (subtype != IEEE80211_FC0_SUBTYPE_BEACON) {
  3476. duration_le = qdf_cpu_to_le16(ppdu_desc->tx_duration);
  3477. wh->i_dur[1] = (duration_le & 0xFF00) >> 8;
  3478. wh->i_dur[0] = duration_le & 0xFF;
  3479. seq_le = qdf_cpu_to_le16(user->start_seq <<
  3480. IEEE80211_SEQ_SEQ_SHIFT);
  3481. wh->i_seq[1] = (seq_le & 0xFF00) >> 8;
  3482. wh->i_seq[0] = seq_le & 0xFF;
  3483. }
  3484. dp_tx_capture_debug("%pK: ctrl/mgmt frm(0x%08x): fc 0x%x 0x%x\n",
  3485. pdev->soc, ptr_tx_cap_info->mpdu_info.ppdu_id,
  3486. wh->i_fc[1], wh->i_fc[0]);
  3487. dp_tx_capture_debug("%pK: desc->ppdu_id 0x%08x\n", pdev->soc, ppdu_desc->ppdu_id);
  3488. /* append ext list */
  3489. qdf_nbuf_append_ext_list(ptr_tx_cap_info->mpdu_nbuf,
  3490. mgmt_ctl_nbuf,
  3491. qdf_nbuf_len(mgmt_ctl_nbuf));
  3492. } else {
  3493. wh_min = (struct ieee80211_frame_min_one *)
  3494. qdf_nbuf_data(ptr_tx_cap_info->mpdu_nbuf);
  3495. qdf_mem_zero(wh_min, MAX_DUMMY_FRM_BODY);
  3496. frame_ctrl_le = qdf_cpu_to_le16(ppdu_desc->frame_ctrl);
  3497. duration_le = qdf_cpu_to_le16(ppdu_desc->tx_duration);
  3498. wh_min->i_fc[1] = (frame_ctrl_le & 0xFF00) >> 8;
  3499. wh_min->i_fc[0] = (frame_ctrl_le & 0xFF);
  3500. wh_min->i_dur[1] = (duration_le & 0xFF00) >> 8;
  3501. wh_min->i_dur[0] = (duration_le & 0xFF);
  3502. qdf_mem_copy(wh_min->i_addr1, mpdu_info->mac_address,
  3503. QDF_MAC_ADDR_SIZE);
  3504. qdf_nbuf_set_pktlen(ptr_tx_cap_info->mpdu_nbuf,
  3505. sizeof(*wh_min));
  3506. dp_tx_capture_debug("%pK: frm(0x%08x): fc %x %x, dur 0x%x%x\n",
  3507. pdev->soc, ptr_tx_cap_info->mpdu_info.ppdu_id,
  3508. wh_min->i_fc[1], wh_min->i_fc[0],
  3509. wh_min->i_dur[1], wh_min->i_dur[0]);
  3510. }
  3511. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  3512. ptr_tx_cap_info, HTT_INVALID_PEER,
  3513. WDI_NO_VAL, pdev->pdev_id);
  3514. if (ptr_tx_cap_info->mpdu_nbuf)
  3515. qdf_nbuf_free(ptr_tx_cap_info->mpdu_nbuf);
  3516. return 0;
  3517. }
  3518. static uint32_t
  3519. dp_update_tx_cap_info(struct dp_pdev *pdev,
  3520. qdf_nbuf_t nbuf_ppdu_desc,
  3521. void *tx_info, bool is_payload,
  3522. bool bar_frm_with_data)
  3523. {
  3524. struct cdp_tx_completion_ppdu *ppdu_desc;
  3525. struct cdp_tx_completion_ppdu_user *user;
  3526. struct cdp_tx_indication_info *tx_capture_info =
  3527. (struct cdp_tx_indication_info *)tx_info;
  3528. struct cdp_tx_indication_mpdu_info *mpdu_info;
  3529. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3530. qdf_nbuf_data(nbuf_ppdu_desc);
  3531. user = &ppdu_desc->user[0];
  3532. qdf_mem_set(tx_capture_info, sizeof(struct cdp_tx_indication_info), 0);
  3533. mpdu_info = &tx_capture_info->mpdu_info;
  3534. mpdu_info->channel = ppdu_desc->channel;
  3535. mpdu_info->frame_type = ppdu_desc->frame_type;
  3536. mpdu_info->ppdu_start_timestamp = ppdu_desc->ppdu_start_timestamp;
  3537. mpdu_info->ppdu_end_timestamp = ppdu_desc->ppdu_end_timestamp;
  3538. mpdu_info->tx_duration = ppdu_desc->tx_duration;
  3539. /* update cdp_tx_indication_mpdu_info */
  3540. dp_tx_update_user_mpdu_info(ppdu_desc->ppdu_id,
  3541. &tx_capture_info->mpdu_info,
  3542. user);
  3543. if (bar_frm_with_data) {
  3544. mpdu_info->ppdu_start_timestamp =
  3545. ppdu_desc->bar_ppdu_start_timestamp;
  3546. mpdu_info->ppdu_end_timestamp =
  3547. ppdu_desc->bar_ppdu_end_timestamp;
  3548. mpdu_info->tx_duration = ppdu_desc->bar_tx_duration;
  3549. mpdu_info->preamble = ppdu_desc->phy_mode;
  3550. }
  3551. mpdu_info->seq_no = user->start_seq;
  3552. mpdu_info->num_msdu = ppdu_desc->num_msdu;
  3553. tx_capture_info->ppdu_desc = ppdu_desc;
  3554. tx_capture_info->mpdu_info.channel_num = pdev->operating_channel.num;
  3555. tx_capture_info->mpdu_info.ppdu_id = ppdu_desc->ppdu_id;
  3556. if (is_payload)
  3557. tx_capture_info->mpdu_nbuf = qdf_nbuf_alloc(pdev->soc->osdev,
  3558. MAX_MONITOR_HEADER,
  3559. MAX_MONITOR_HEADER,
  3560. 4, FALSE);
  3561. else
  3562. tx_capture_info->mpdu_nbuf = qdf_nbuf_alloc(pdev->soc->osdev,
  3563. MAX_MONITOR_HEADER +
  3564. MAX_DUMMY_FRM_BODY,
  3565. MAX_MONITOR_HEADER,
  3566. 4, FALSE);
  3567. return 0;
  3568. }
  3569. static uint32_t
  3570. dp_check_mgmt_ctrl_ppdu(struct dp_pdev *pdev,
  3571. qdf_nbuf_t nbuf_ppdu_desc, bool bar_frm_with_data)
  3572. {
  3573. struct cdp_tx_indication_info tx_capture_info;
  3574. qdf_nbuf_t mgmt_ctl_nbuf, tmp_nbuf;
  3575. uint8_t type, subtype;
  3576. uint8_t fc_type, fc_subtype;
  3577. bool is_sgen_pkt;
  3578. struct cdp_tx_mgmt_comp_info *ptr_comp_info;
  3579. qdf_nbuf_queue_t *retries_q;
  3580. struct cdp_tx_completion_ppdu *ppdu_desc, *retry_ppdu;
  3581. struct cdp_tx_completion_ppdu_user *user;
  3582. uint32_t ppdu_id;
  3583. uint32_t desc_ppdu_id;
  3584. size_t head_size;
  3585. uint32_t status = 1;
  3586. uint32_t tsf_delta;
  3587. uint64_t start_tsf;
  3588. uint64_t end_tsf;
  3589. uint16_t ppdu_desc_frame_ctrl;
  3590. struct dp_peer *peer;
  3591. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3592. qdf_nbuf_data(nbuf_ppdu_desc);
  3593. user = &ppdu_desc->user[0];
  3594. ppdu_desc_frame_ctrl = ppdu_desc->frame_ctrl;
  3595. if ((ppdu_desc->htt_frame_type == HTT_STATS_FTYPE_SGEN_MU_BAR) ||
  3596. (ppdu_desc->htt_frame_type == HTT_STATS_FTYPE_SGEN_MU_BRP))
  3597. ppdu_desc_frame_ctrl = (IEEE80211_FC0_SUBTYPE_TRIGGER |
  3598. IEEE80211_FC0_TYPE_CTL);
  3599. if (bar_frm_with_data) {
  3600. desc_ppdu_id = ppdu_desc->bar_ppdu_id;
  3601. start_tsf = ppdu_desc->bar_ppdu_start_timestamp;
  3602. end_tsf = ppdu_desc->bar_ppdu_end_timestamp;
  3603. } else {
  3604. desc_ppdu_id = ppdu_desc->ppdu_id;
  3605. start_tsf = ppdu_desc->ppdu_start_timestamp;
  3606. end_tsf = ppdu_desc->ppdu_end_timestamp;
  3607. }
  3608. /*
  3609. * only for host generated frame we do have
  3610. * timestamp and retries count.
  3611. */
  3612. head_size = sizeof(struct cdp_tx_mgmt_comp_info);
  3613. fc_type = (ppdu_desc_frame_ctrl &
  3614. IEEE80211_FC0_TYPE_MASK);
  3615. fc_subtype = (ppdu_desc_frame_ctrl &
  3616. IEEE80211_FC0_SUBTYPE_MASK);
  3617. type = (ppdu_desc_frame_ctrl &
  3618. IEEE80211_FC0_TYPE_MASK) >>
  3619. IEEE80211_FC0_TYPE_SHIFT;
  3620. subtype = (ppdu_desc_frame_ctrl &
  3621. IEEE80211_FC0_SUBTYPE_MASK) >>
  3622. IEEE80211_FC0_SUBTYPE_SHIFT;
  3623. if (ppdu_desc->htt_frame_type == HTT_STATS_FTYPE_SGEN_NDP) {
  3624. dp_update_frame_ctrl_from_frame_type(ppdu_desc);
  3625. type = 0;
  3626. subtype = 0;
  3627. }
  3628. peer = DP_TX_PEER_GET_REF(pdev, ppdu_desc->user[0].peer_id);
  3629. if (peer && !peer->bss_peer) {
  3630. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, peer,
  3631. ppdu_desc->user[0].mac_addr
  3632. )) {
  3633. qdf_nbuf_free(nbuf_ppdu_desc);
  3634. status = 0;
  3635. DP_TX_PEER_DEL_REF(peer);
  3636. goto free_ppdu_desc;
  3637. }
  3638. DP_TX_PEER_DEL_REF(peer);
  3639. } else {
  3640. if (peer)
  3641. DP_TX_PEER_DEL_REF(peer);
  3642. if (!(type == IEEE80211_FC0_TYPE_MGT &&
  3643. (subtype == MGMT_SUBTYPE_PROBE_RESP >> 4 ||
  3644. subtype == MGMT_SUBTYPE_DISASSOC >> 4 ||
  3645. subtype == MGMT_SUBTYPE_DEAUTH >> 4))) {
  3646. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, NULL,
  3647. ppdu_desc->user[0]
  3648. .mac_addr)) {
  3649. qdf_nbuf_free(nbuf_ppdu_desc);
  3650. status = 0;
  3651. goto free_ppdu_desc;
  3652. }
  3653. }
  3654. }
  3655. switch (ppdu_desc->htt_frame_type) {
  3656. case HTT_STATS_FTYPE_TIDQ_DATA_SU:
  3657. case HTT_STATS_FTYPE_TIDQ_DATA_MU:
  3658. if ((fc_type == IEEE80211_FC0_TYPE_MGT) &&
  3659. (fc_subtype == IEEE80211_FC0_SUBTYPE_BEACON))
  3660. is_sgen_pkt = true;
  3661. else
  3662. is_sgen_pkt = false;
  3663. break;
  3664. default:
  3665. is_sgen_pkt = true;
  3666. break;
  3667. }
  3668. retries_q = &pdev->tx_capture.retries_ctl_mgmt_q[type][subtype];
  3669. if (!qdf_nbuf_is_queue_empty(retries_q)) {
  3670. tmp_nbuf = qdf_nbuf_queue_first(retries_q);
  3671. retry_ppdu = (struct cdp_tx_completion_ppdu *)
  3672. qdf_nbuf_data(tmp_nbuf);
  3673. if (ppdu_desc->sched_cmdid != retry_ppdu->sched_cmdid)
  3674. TX_CAP_NBUF_QUEUE_FREE(retries_q);
  3675. }
  3676. get_mgmt_pkt_from_queue:
  3677. qdf_spin_lock_bh(
  3678. &pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  3679. mgmt_ctl_nbuf = qdf_nbuf_queue_remove(
  3680. &pdev->tx_capture.ctl_mgmt_q[type][subtype]);
  3681. qdf_spin_unlock_bh(&pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  3682. if (mgmt_ctl_nbuf) {
  3683. qdf_nbuf_t tmp_mgmt_ctl_nbuf;
  3684. ptr_comp_info = (struct cdp_tx_mgmt_comp_info *)
  3685. qdf_nbuf_data(mgmt_ctl_nbuf);
  3686. is_sgen_pkt = ptr_comp_info->is_sgen_pkt;
  3687. ppdu_id = ptr_comp_info->ppdu_id;
  3688. if (!is_sgen_pkt && ptr_comp_info->tx_tsf < start_tsf) {
  3689. /*
  3690. * free the older mgmt buffer from
  3691. * the queue and get new mgmt buffer
  3692. */
  3693. qdf_nbuf_free(mgmt_ctl_nbuf);
  3694. goto get_mgmt_pkt_from_queue;
  3695. }
  3696. /*
  3697. * for sgen frame we won't have, retries count
  3698. * and 64 bits tsf in the head.
  3699. */
  3700. if (ppdu_id != desc_ppdu_id) {
  3701. if (is_sgen_pkt) {
  3702. start_tsf = (start_tsf & LOWER_32_MASK);
  3703. if (start_tsf > ptr_comp_info->tx_tsf)
  3704. tsf_delta = start_tsf -
  3705. ptr_comp_info->tx_tsf;
  3706. else
  3707. tsf_delta = LOWER_32_MASK -
  3708. ptr_comp_info->tx_tsf +
  3709. start_tsf;
  3710. dp_tx_capture_info("%pK: ppdu_id[m:%d desc:%d] start_tsf: %u mgmt_tsf:%u tsf_delta:%u bar_frm_with_data:%d",
  3711. pdev->soc, ppdu_id, desc_ppdu_id,
  3712. start_tsf, ptr_comp_info->tx_tsf,
  3713. tsf_delta, bar_frm_with_data);
  3714. if (tsf_delta > MAX_MGMT_ENQ_DELAY) {
  3715. /*
  3716. * free the older mgmt buffer from
  3717. * the queue and get new mgmt buffer
  3718. */
  3719. qdf_nbuf_free(mgmt_ctl_nbuf);
  3720. goto get_mgmt_pkt_from_queue;
  3721. } else {
  3722. /* drop the ppdu_desc */
  3723. qdf_nbuf_free(nbuf_ppdu_desc);
  3724. status = 0;
  3725. goto insert_mgmt_buf_to_queue;
  3726. }
  3727. }
  3728. /*
  3729. * only for the packets send over the air are handled
  3730. * packets drop by firmware is not handled in this
  3731. * feature
  3732. */
  3733. if (user->completion_status ==
  3734. HTT_PPDU_STATS_USER_STATUS_FILTERED) {
  3735. qdf_nbuf_free(nbuf_ppdu_desc);
  3736. status = 0;
  3737. goto insert_mgmt_buf_to_queue;
  3738. }
  3739. /* check for max retry count */
  3740. if (qdf_nbuf_queue_len(retries_q) >=
  3741. MAX_RETRY_Q_COUNT) {
  3742. qdf_nbuf_t nbuf_retry_ppdu;
  3743. nbuf_retry_ppdu =
  3744. qdf_nbuf_queue_remove(retries_q);
  3745. qdf_nbuf_free(nbuf_retry_ppdu);
  3746. }
  3747. /*
  3748. * add the ppdu_desc into retry queue
  3749. */
  3750. qdf_nbuf_queue_add(retries_q, nbuf_ppdu_desc);
  3751. /* flushing retry queue since completion status is
  3752. * in final state. meaning that even though ppdu_id are
  3753. * different there is a payload already.
  3754. */
  3755. if (qdf_unlikely(ppdu_desc->user[0].completion_status ==
  3756. HTT_PPDU_STATS_USER_STATUS_OK)) {
  3757. TX_CAP_NBUF_QUEUE_FREE(retries_q);
  3758. }
  3759. status = 0;
  3760. insert_mgmt_buf_to_queue:
  3761. /*
  3762. * insert the mgmt_ctl buffer back to
  3763. * the queue
  3764. */
  3765. qdf_spin_lock_bh(
  3766. &pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  3767. qdf_nbuf_queue_insert_head(
  3768. &pdev->tx_capture.ctl_mgmt_q[type][subtype],
  3769. mgmt_ctl_nbuf);
  3770. qdf_spin_unlock_bh(
  3771. &pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  3772. } else {
  3773. qdf_nbuf_t nbuf_retry_ppdu;
  3774. struct cdp_tx_completion_ppdu *tmp_ppdu_desc;
  3775. uint16_t frame_ctrl_le;
  3776. struct ieee80211_frame *wh;
  3777. uint32_t retry_len = 0;
  3778. dp_tx_capture_info("%pK: ppdu_id[m:%d desc:%d] start_tsf: %u mgmt_tsf:%u bar_frm_with_data:%d is_sgen:%d",
  3779. pdev->soc, ppdu_id, desc_ppdu_id,
  3780. start_tsf, ptr_comp_info->tx_tsf,
  3781. bar_frm_with_data, is_sgen_pkt);
  3782. /*
  3783. * only for the packets send over the air are handled
  3784. * packets drop by firmware is not handled in this
  3785. * feature
  3786. */
  3787. if (user->completion_status ==
  3788. HTT_PPDU_STATS_USER_STATUS_FILTERED) {
  3789. qdf_nbuf_free(nbuf_ppdu_desc);
  3790. qdf_nbuf_free(mgmt_ctl_nbuf);
  3791. status = 0;
  3792. goto free_ppdu_desc;
  3793. }
  3794. /* pull head based on sgen pkt or mgmt pkt */
  3795. if (NULL == qdf_nbuf_pull_head(mgmt_ctl_nbuf,
  3796. head_size)) {
  3797. dp_tx_capture_alert("%pK: No Head space to pull !!\n", pdev->soc);
  3798. qdf_assert_always(0);
  3799. }
  3800. wh = (struct ieee80211_frame *)
  3801. (qdf_nbuf_data(mgmt_ctl_nbuf));
  3802. if (type == IEEE80211_FC0_TYPE_MGT &&
  3803. (subtype == MGMT_SUBTYPE_PROBE_RESP >> 4 ||
  3804. subtype == MGMT_SUBTYPE_DISASSOC >> 4 ||
  3805. subtype == MGMT_SUBTYPE_DEAUTH >> 4)) {
  3806. if (!dp_peer_or_pdev_tx_cap_enabled(pdev,
  3807. NULL,
  3808. wh->i_addr1
  3809. )) {
  3810. qdf_nbuf_free(nbuf_ppdu_desc);
  3811. qdf_nbuf_free(mgmt_ctl_nbuf);
  3812. TX_CAP_NBUF_QUEUE_FREE(retries_q);
  3813. status = 0;
  3814. goto free_ppdu_desc;
  3815. }
  3816. }
  3817. while (qdf_nbuf_queue_len(retries_q)) {
  3818. /*
  3819. * send retried packet stored
  3820. * in queue
  3821. */
  3822. nbuf_retry_ppdu =
  3823. qdf_nbuf_queue_remove(retries_q);
  3824. retry_len = qdf_nbuf_queue_len(retries_q);
  3825. if (!nbuf_retry_ppdu) {
  3826. dp_tx_capture_alert("%pK: retry q type[%d][%d] retry q len = %d\n",
  3827. pdev->soc,
  3828. type, subtype, retry_len);
  3829. qdf_assert_always(0);
  3830. break;
  3831. }
  3832. tmp_ppdu_desc =
  3833. (struct cdp_tx_completion_ppdu *)
  3834. qdf_nbuf_data(nbuf_retry_ppdu);
  3835. tmp_mgmt_ctl_nbuf =
  3836. qdf_nbuf_copy_expand(mgmt_ctl_nbuf,
  3837. 0, 0);
  3838. if (qdf_unlikely(!tmp_mgmt_ctl_nbuf)) {
  3839. dp_tx_capture_alert("%pK: No memory to do copy!!", pdev->soc);
  3840. qdf_assert_always(0);
  3841. }
  3842. dp_update_tx_cap_info(pdev, nbuf_retry_ppdu,
  3843. &tx_capture_info, true,
  3844. bar_frm_with_data);
  3845. if (!tx_capture_info.mpdu_nbuf) {
  3846. qdf_nbuf_free(nbuf_retry_ppdu);
  3847. qdf_nbuf_free(tmp_mgmt_ctl_nbuf);
  3848. continue;
  3849. }
  3850. /*
  3851. * frame control from ppdu_desc has
  3852. * retry flag set
  3853. */
  3854. frame_ctrl_le =
  3855. qdf_cpu_to_le16(tmp_ppdu_desc->frame_ctrl);
  3856. wh = (struct ieee80211_frame *)
  3857. (qdf_nbuf_data(tmp_mgmt_ctl_nbuf));
  3858. wh->i_fc[1] = (frame_ctrl_le & 0xFF00) >> 8;
  3859. wh->i_fc[0] = (frame_ctrl_le & 0xFF);
  3860. tx_capture_info.ppdu_desc = tmp_ppdu_desc;
  3861. /*
  3862. * send MPDU to osif layer
  3863. */
  3864. dp_send_mgmt_ctrl_to_stack(pdev,
  3865. nbuf_retry_ppdu,
  3866. &tx_capture_info,
  3867. tmp_mgmt_ctl_nbuf,
  3868. true);
  3869. /* free retried queue nbuf ppdu_desc */
  3870. qdf_nbuf_free(nbuf_retry_ppdu);
  3871. }
  3872. dp_update_tx_cap_info(pdev, nbuf_ppdu_desc,
  3873. &tx_capture_info, true,
  3874. bar_frm_with_data);
  3875. if (!tx_capture_info.mpdu_nbuf) {
  3876. qdf_nbuf_free(mgmt_ctl_nbuf);
  3877. qdf_nbuf_free(nbuf_ppdu_desc);
  3878. status = 0;
  3879. goto free_ppdu_desc;
  3880. }
  3881. tx_capture_info.mpdu_info.ppdu_id =
  3882. *(uint32_t *)qdf_nbuf_data(mgmt_ctl_nbuf);
  3883. /* frame control from ppdu_desc has retry flag set */
  3884. frame_ctrl_le = qdf_cpu_to_le16(ppdu_desc_frame_ctrl);
  3885. wh = (struct ieee80211_frame *)
  3886. (qdf_nbuf_data(mgmt_ctl_nbuf));
  3887. wh->i_fc[1] = (frame_ctrl_le & 0xFF00) >> 8;
  3888. wh->i_fc[0] = (frame_ctrl_le & 0xFF);
  3889. tx_capture_info.ppdu_desc = ppdu_desc;
  3890. /*
  3891. * send MPDU to osif layer
  3892. */
  3893. dp_send_mgmt_ctrl_to_stack(pdev, nbuf_ppdu_desc,
  3894. &tx_capture_info,
  3895. mgmt_ctl_nbuf, true);
  3896. }
  3897. } else if (!is_sgen_pkt) {
  3898. /*
  3899. * only for the packets send over the air are handled
  3900. * packets drop by firmware is not handled in this
  3901. * feature
  3902. */
  3903. if (user->completion_status ==
  3904. HTT_PPDU_STATS_USER_STATUS_FILTERED) {
  3905. qdf_nbuf_free(nbuf_ppdu_desc);
  3906. status = 0;
  3907. goto free_ppdu_desc;
  3908. }
  3909. /* check for max retry count */
  3910. if (qdf_nbuf_queue_len(retries_q) >= MAX_RETRY_Q_COUNT) {
  3911. qdf_nbuf_t nbuf_retry_ppdu;
  3912. nbuf_retry_ppdu =
  3913. qdf_nbuf_queue_remove(retries_q);
  3914. qdf_nbuf_free(nbuf_retry_ppdu);
  3915. }
  3916. /*
  3917. * add the ppdu_desc into retry queue
  3918. */
  3919. qdf_nbuf_queue_add(retries_q, nbuf_ppdu_desc);
  3920. /* flushing retry queue since completion status is
  3921. * in final state. meaning that even though ppdu_id are
  3922. * different there is a payload already.
  3923. */
  3924. if (qdf_unlikely(ppdu_desc->user[0].completion_status ==
  3925. HTT_PPDU_STATS_USER_STATUS_OK)) {
  3926. TX_CAP_NBUF_QUEUE_FREE(retries_q);
  3927. }
  3928. status = 0;
  3929. } else if ((ppdu_desc_frame_ctrl &
  3930. IEEE80211_FC0_TYPE_MASK) ==
  3931. IEEE80211_FC0_TYPE_CTL) {
  3932. /*
  3933. * only for the packets send over the air are handled
  3934. * packets drop by firmware is not handled in this
  3935. * feature
  3936. */
  3937. if (user->completion_status ==
  3938. HTT_PPDU_STATS_USER_STATUS_FILTERED) {
  3939. qdf_nbuf_free(nbuf_ppdu_desc);
  3940. status = 0;
  3941. goto free_ppdu_desc;
  3942. }
  3943. dp_update_tx_cap_info(pdev, nbuf_ppdu_desc,
  3944. &tx_capture_info, false,
  3945. bar_frm_with_data);
  3946. if (!tx_capture_info.mpdu_nbuf) {
  3947. qdf_nbuf_free(nbuf_ppdu_desc);
  3948. status = 0;
  3949. goto free_ppdu_desc;
  3950. }
  3951. /*
  3952. * send MPDU to osif layer
  3953. */
  3954. dp_send_mgmt_ctrl_to_stack(pdev, nbuf_ppdu_desc,
  3955. &tx_capture_info, NULL, false);
  3956. }
  3957. free_ppdu_desc:
  3958. return status;
  3959. }
  3960. /**
  3961. * dp_peer_tx_cap_tid_queue_flush_tlv(): Function to dequeue peer queue
  3962. * @pdev: DP pdev handle
  3963. * @peer; DP peer handle
  3964. * @ppdu_desc: ppdu_desc
  3965. *
  3966. * return: void
  3967. */
  3968. static void
  3969. dp_peer_tx_cap_tid_queue_flush_tlv(struct dp_pdev *pdev,
  3970. struct dp_peer *peer,
  3971. struct cdp_tx_completion_ppdu *ppdu_desc,
  3972. uint8_t usr_idx)
  3973. {
  3974. int tid;
  3975. struct dp_tx_tid *tx_tid;
  3976. qdf_nbuf_queue_t head_xretries;
  3977. qdf_nbuf_queue_t head_msdu;
  3978. uint32_t qlen = 0;
  3979. uint32_t qlen_curr = 0;
  3980. struct cdp_tx_completion_ppdu_user *user;
  3981. user = &ppdu_desc->user[usr_idx];
  3982. tid = user->tid;
  3983. tx_tid = &peer->tx_capture.tx_tid[tid];
  3984. qdf_nbuf_queue_init(&head_msdu);
  3985. qdf_nbuf_queue_init(&head_xretries);
  3986. qlen = qdf_nbuf_queue_len(&tx_tid->defer_msdu_q);
  3987. dp_tx_msdu_dequeue(peer, INVALID_PPDU_ID,
  3988. tid, ppdu_desc->num_msdu,
  3989. &head_msdu,
  3990. &head_xretries,
  3991. 0, MAX_END_TSF);
  3992. dp_tx_cap_stats_msdu_update(peer, PEER_MSDU_FLUSH,
  3993. qdf_nbuf_queue_len(&head_msdu));
  3994. dp_tx_cap_stats_msdu_update(peer, PEER_MSDU_FLUSH,
  3995. qdf_nbuf_queue_len(&head_xretries));
  3996. if (!qdf_nbuf_is_queue_empty(&head_xretries)) {
  3997. struct cdp_tx_completion_ppdu *xretry_ppdu = NULL;
  3998. struct cdp_tx_completion_ppdu_user *xretry_user = NULL;
  3999. uint32_t xretry_qlen;
  4000. xretry_ppdu = tx_tid->xretry_ppdu;
  4001. if (!xretry_ppdu) {
  4002. dp_tx_capture_alert("%pK: xretry_ppdu is NULL",
  4003. pdev->soc);
  4004. return;
  4005. }
  4006. xretry_user = &xretry_ppdu->user[0];
  4007. if (!xretry_user) {
  4008. dp_tx_capture_alert("%pK: xretry_user is NULL",
  4009. pdev->soc);
  4010. return;
  4011. }
  4012. xretry_ppdu->ppdu_id = peer->tx_capture.tx_wifi_ppdu_id;
  4013. /* Restitch MPDUs from xretry MSDUs */
  4014. dp_tx_mon_restitch_mpdu(pdev, peer,
  4015. xretry_ppdu,
  4016. &head_xretries,
  4017. &xretry_user->mpdu_q,
  4018. 0);
  4019. xretry_qlen = qdf_nbuf_queue_len(&xretry_user->mpdu_q);
  4020. dp_tx_cap_stats_mpdu_update(peer, PEER_MPDU_RESTITCH,
  4021. xretry_qlen);
  4022. }
  4023. TX_CAP_NBUF_QUEUE_FREE(&head_msdu);
  4024. TX_CAP_NBUF_QUEUE_FREE(&head_xretries);
  4025. qlen_curr = qdf_nbuf_queue_len(&tx_tid->defer_msdu_q);
  4026. dp_tx_mon_proc_xretries(pdev, peer, tid);
  4027. dp_tx_capture_info("%pK: peer_id [%d 0x%x] tid[%d] qlen[%d -> %d]",
  4028. pdev->soc, ppdu_desc->user[usr_idx].peer_id, peer, tid, qlen, qlen_curr);
  4029. }
  4030. /**
  4031. * dp_tx_ppdu_stats_flush(): Function to flush pending retried ppdu desc
  4032. * @pdev: DP pdev handle
  4033. * @nbuf: ppdu_desc
  4034. *
  4035. * return: void
  4036. */
  4037. static void
  4038. dp_tx_ppdu_stats_flush(struct dp_pdev *pdev,
  4039. struct cdp_tx_completion_ppdu *ppdu_desc,
  4040. uint8_t usr_idx)
  4041. {
  4042. struct dp_peer *peer;
  4043. struct cdp_tx_completion_ppdu_user *user;
  4044. user = &ppdu_desc->user[usr_idx];
  4045. peer = DP_TX_PEER_GET_REF(pdev, user->peer_id);
  4046. if (!peer)
  4047. return;
  4048. if (peer->tx_capture.is_tid_initialized) {
  4049. dp_peer_tx_cap_tid_queue_flush_tlv(pdev, peer, ppdu_desc, usr_idx);
  4050. }
  4051. DP_TX_PEER_DEL_REF(peer);
  4052. return;
  4053. }
  4054. /**
  4055. * dp_check_ppdu_and_deliver(): Check PPDUs for any holes and deliver
  4056. * to upper layer if complete
  4057. * @pdev: DP pdev handle
  4058. * @nbuf_ppdu_list: ppdu_desc_list per sched cmd id
  4059. * @ppdu_desc_cnt: number of ppdu_desc_cnt
  4060. *
  4061. * return: status
  4062. */
  4063. static void
  4064. dp_check_ppdu_and_deliver(struct dp_pdev *pdev,
  4065. struct dp_tx_cap_nbuf_list nbuf_ppdu_list[],
  4066. uint32_t ppdu_desc_cnt)
  4067. {
  4068. uint32_t ppdu_id;
  4069. uint32_t desc_cnt;
  4070. qdf_nbuf_t tmp_nbuf;
  4071. struct dp_tx_tid *tx_tid = NULL;
  4072. int i;
  4073. uint8_t max_num_users = 0;
  4074. uint8_t usr_idx;
  4075. struct dp_tx_cap_nbuf_list *ptr_nbuf_list;
  4076. for (desc_cnt = 0; desc_cnt < ppdu_desc_cnt; desc_cnt++) {
  4077. struct cdp_tx_completion_ppdu *ppdu_desc;
  4078. struct cdp_tx_completion_ppdu_user *user;
  4079. uint32_t num_mpdu;
  4080. uint16_t start_seq, seq_no = 0;
  4081. int i;
  4082. qdf_nbuf_t mpdu_nbuf;
  4083. struct dp_peer *peer;
  4084. uint8_t type;
  4085. uint8_t subtype;
  4086. uint8_t usr_type;
  4087. uint32_t mpdus_tried;
  4088. uint8_t num_users;
  4089. qdf_nbuf_t nbuf_ppdu;
  4090. bool is_bar_frm_with_data = false;
  4091. ptr_nbuf_list = &nbuf_ppdu_list[desc_cnt];
  4092. if (!dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list)) {
  4093. if (ptr_nbuf_list->nbuf_ppdu)
  4094. qdf_assert_always(0);
  4095. continue;
  4096. }
  4097. nbuf_ppdu = ptr_nbuf_list->nbuf_ppdu;
  4098. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  4099. qdf_nbuf_data(nbuf_ppdu);
  4100. ppdu_id = ppdu_desc->ppdu_id;
  4101. num_users = ppdu_desc->num_users;
  4102. if (ppdu_desc->is_flush) {
  4103. dp_tx_ppdu_stats_flush(pdev, ppdu_desc, 0);
  4104. dp_ppdu_desc_free_all(ptr_nbuf_list, num_users);
  4105. continue;
  4106. }
  4107. if (max_num_users < ppdu_desc->num_users)
  4108. max_num_users = ppdu_desc->num_users;
  4109. type = (ppdu_desc->frame_ctrl & IEEE80211_FC0_TYPE_MASK);
  4110. subtype = (ppdu_desc->frame_ctrl &
  4111. IEEE80211_FC0_SUBTYPE_MASK);
  4112. usr_type = (ppdu_desc->user[0].frame_ctrl &
  4113. IEEE80211_FC0_TYPE_MASK);
  4114. /* handle management frame */
  4115. if ((type != IEEE80211_FC0_TYPE_DATA) ||
  4116. (ppdu_desc->htt_frame_type ==
  4117. HTT_STATS_FTYPE_SGEN_MU_BAR) ||
  4118. (ppdu_desc->htt_frame_type ==
  4119. HTT_STATS_FTYPE_SGEN_QOS_NULL)) {
  4120. qdf_nbuf_t tmp_nbuf_ppdu;
  4121. tmp_nbuf_ppdu = nbuf_ppdu;
  4122. /*
  4123. * take reference of ppdu_desc if the htt_frame_type is
  4124. * HTT_STATS_FTYPE_SGEN_MU_BAR, as there will be
  4125. * corresponding data frame
  4126. */
  4127. if (((type == IEEE80211_FC0_TYPE_CTL) &&
  4128. (subtype == IEEE80211_FC0_SUBTYPE_BAR) &&
  4129. (usr_type == IEEE80211_FC0_TYPE_DATA)) ||
  4130. (ppdu_desc->htt_frame_type ==
  4131. HTT_STATS_FTYPE_SGEN_MU_BAR)) {
  4132. /*
  4133. * clonning ppdu_desc additional reference as
  4134. * handling data frame
  4135. */
  4136. tmp_nbuf_ppdu = qdf_nbuf_clone(nbuf_ppdu);
  4137. if (qdf_unlikely(!tmp_nbuf_ppdu)) {
  4138. qdf_assert_always(0);
  4139. continue;
  4140. }
  4141. dp_tx_cap_nbuf_list_inc_ref(ptr_nbuf_list);
  4142. is_bar_frm_with_data = true;
  4143. }
  4144. if (dp_check_mgmt_ctrl_ppdu(pdev, tmp_nbuf_ppdu,
  4145. is_bar_frm_with_data)) {
  4146. dp_tx_cap_nbuf_list_dec_ref(ptr_nbuf_list);
  4147. qdf_nbuf_free(tmp_nbuf_ppdu);
  4148. } else {
  4149. dp_tx_cap_nbuf_list_dec_ref(ptr_nbuf_list);
  4150. }
  4151. if (!is_bar_frm_with_data)
  4152. continue;
  4153. }
  4154. /*
  4155. * process only data frame and other
  4156. */
  4157. for (usr_idx = 0; usr_idx < num_users; usr_idx++) {
  4158. uint32_t mpdu_enq = 0;
  4159. uint32_t mpdu_tried = 0;
  4160. if (!ptr_nbuf_list->nbuf_ppdu ||
  4161. !dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list)) {
  4162. continue;
  4163. }
  4164. nbuf_ppdu = ptr_nbuf_list->nbuf_ppdu;
  4165. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  4166. qdf_nbuf_data(nbuf_ppdu);
  4167. user = &ppdu_desc->user[usr_idx];
  4168. if (user->delayed_ba || user->skip == 1)
  4169. continue;
  4170. peer = DP_TX_PEER_GET_REF(pdev, user->peer_id);
  4171. if (!peer) {
  4172. user->skip = 1;
  4173. dp_ppdu_desc_free(ptr_nbuf_list, usr_idx);
  4174. continue;
  4175. }
  4176. if (!peer->tx_capture.is_tid_initialized) {
  4177. user->skip = 1;
  4178. dp_ppdu_desc_free(ptr_nbuf_list, usr_idx);
  4179. DP_TX_PEER_DEL_REF(peer);
  4180. continue;
  4181. }
  4182. tx_tid = &peer->tx_capture.tx_tid[user->tid];
  4183. ppdu_id = ppdu_desc->ppdu_id;
  4184. /* find mpdu tried is same as success mpdu */
  4185. num_mpdu = user->mpdu_success;
  4186. /*
  4187. * ba_size is updated in BA bitmap TLVs,
  4188. * which are not received
  4189. * in case of non-QoS TID.
  4190. */
  4191. if (qdf_unlikely(user->tid == DP_NON_QOS_TID)) {
  4192. user->ba_size = 1;
  4193. user->last_enq_seq = user->start_seq;
  4194. }
  4195. if (user->ba_size == 0)
  4196. user->ba_size = 1;
  4197. /* find list of missing sequence */
  4198. user->mpdus = qdf_mem_malloc(sizeof(qdf_nbuf_t) *
  4199. user->ba_size);
  4200. if (qdf_unlikely(!user->mpdus)) {
  4201. dp_tx_capture_alert("%pK: ppdu_desc->mpdus allocation failed",
  4202. pdev->soc);
  4203. dp_ppdu_desc_free_all(ptr_nbuf_list, num_users);
  4204. DP_TX_PEER_DEL_REF(peer);
  4205. dp_print_pdev_tx_capture_stats(pdev);
  4206. qdf_assert_always(0);
  4207. return;
  4208. }
  4209. if (qdf_unlikely(user->ba_size >
  4210. CDP_BA_256_BIT_MAP_SIZE_DWORDS *
  4211. SEQ_SEG_SZ_BITS(user->failed_bitmap))) {
  4212. DP_TX_PEER_DEL_REF(peer);
  4213. qdf_assert_always(0);
  4214. return;
  4215. }
  4216. /* Fill seq holes within current schedule list */
  4217. start_seq = user->start_seq;
  4218. seq_no = 0;
  4219. mpdus_tried = user->mpdu_tried_mcast +
  4220. user->mpdu_tried_ucast;
  4221. for (i = 0; (i < user->ba_size) && mpdus_tried; i++) {
  4222. if (qdf_likely(user->tid != DP_NON_QOS_TID) &&
  4223. !(SEQ_BIT(user->enq_bitmap, i)) &&
  4224. !mpdu_tried)
  4225. continue;
  4226. mpdus_tried--;
  4227. /* missed seq number */
  4228. seq_no = start_seq + i;
  4229. /*
  4230. * Fill failed MPDUs in AMPDU if they're
  4231. * available in subsequent PPDUs in current
  4232. * burst schedule. This is not applicable
  4233. * for non-QoS TIDs (no AMPDUs)
  4234. */
  4235. if (qdf_likely(user->tid != DP_NON_QOS_TID) &&
  4236. !(SEQ_BIT(user->failed_bitmap, i))) {
  4237. uint8_t seq_idx;
  4238. dp_tx_capture_debug("%pK:find seq %d in next ppdu %d",
  4239. pdev->soc, seq_no,
  4240. ppdu_desc_cnt);
  4241. mpdu_nbuf =
  4242. get_mpdu_clone_from_next_ppdu(
  4243. nbuf_ppdu_list +
  4244. desc_cnt,
  4245. ppdu_desc_cnt -
  4246. desc_cnt, seq_no,
  4247. user->peer_id,
  4248. ppdu_id, usr_idx);
  4249. seq_idx = seq_no - start_seq;
  4250. /* check mpdu_nbuf NULL */
  4251. if (!mpdu_nbuf) {
  4252. qdf_nbuf_t m_nbuf = NULL;
  4253. m_nbuf = user->mpdus[seq_idx];
  4254. CHECK_MPDUS_NULL(m_nbuf);
  4255. user->mpdus[seq_idx] = NULL;
  4256. user->pending_retries++;
  4257. continue;
  4258. }
  4259. dp_tx_cap_stats_mpdu_update(peer,
  4260. PEER_MPDU_CLONE, 1);
  4261. CHECK_MPDUS_NULL(user->mpdus[seq_idx]);
  4262. user->mpdus[seq_idx] = mpdu_nbuf;
  4263. SEQ_SEG(user->failed_bitmap, i) |=
  4264. SEQ_SEG_MSK(user->failed_bitmap[0], i);
  4265. } else {
  4266. qdf_nbuf_queue_t *tmp_q;
  4267. uint32_t index = 0;
  4268. tmp_q = &user->mpdu_q;
  4269. /* any error case we need to handle */
  4270. mpdu_nbuf =
  4271. qdf_nbuf_queue_remove(tmp_q);
  4272. /* check mpdu_nbuf NULL */
  4273. if (!mpdu_nbuf)
  4274. continue;
  4275. index = seq_no - start_seq;
  4276. CHECK_MPDUS_NULL(user->mpdus[index]);
  4277. user->mpdus[index] = mpdu_nbuf;
  4278. dp_tx_cap_stats_mpdu_update(peer,
  4279. PEER_MPDU_ARR, 1);
  4280. }
  4281. }
  4282. for (/* get i from previous stored value*/;
  4283. i < user->ba_size; i++) {
  4284. qdf_nbuf_queue_t *tmp_q;
  4285. /* missed seq number */
  4286. seq_no = start_seq + i;
  4287. tmp_q = &user->mpdu_q;
  4288. /* any error case we need to handle */
  4289. mpdu_nbuf = qdf_nbuf_queue_remove(tmp_q);
  4290. /* check mpdu_nbuf NULL */
  4291. if (!mpdu_nbuf)
  4292. continue;
  4293. user->mpdus[seq_no - start_seq] = mpdu_nbuf;
  4294. dp_tx_cap_stats_mpdu_update(peer,
  4295. PEER_MPDU_ARR, 1);
  4296. }
  4297. mpdu_tried = user->mpdu_tried_ucast +
  4298. user->mpdu_tried_mcast;
  4299. for (i = 0; i < CDP_BA_256_BIT_MAP_SIZE_DWORDS; i++)
  4300. mpdu_enq +=
  4301. get_number_of_1s(user->enq_bitmap[i]);
  4302. if (mpdu_tried > mpdu_enq)
  4303. dp_ppdu_desc_debug_print(ppdu_desc, usr_idx,
  4304. __func__, __LINE__);
  4305. /*
  4306. * It is possible that enq_bitmap received has
  4307. * more bits than actual mpdus tried if HW was
  4308. * unable to send all MPDUs, and last_enq_seq
  4309. * and ba_size should be adjusted in that case
  4310. */
  4311. if (i < user->ba_size) {
  4312. user->last_enq_seq = seq_no;
  4313. user->ba_size = seq_no - start_seq + 1;
  4314. }
  4315. DP_TX_PEER_DEL_REF(peer);
  4316. }
  4317. }
  4318. for (usr_idx = 0; usr_idx < max_num_users; usr_idx++) {
  4319. for (i = 0; i < ppdu_desc_cnt; i++) {
  4320. uint32_t pending_ppdus;
  4321. struct cdp_tx_completion_ppdu *cur_ppdu_desc;
  4322. struct cdp_tx_completion_ppdu_user *cur_user;
  4323. struct dp_peer *peer;
  4324. qdf_nbuf_queue_t head_ppdu;
  4325. uint16_t peer_id;
  4326. ptr_nbuf_list = &nbuf_ppdu_list[i];
  4327. if (!ptr_nbuf_list->nbuf_ppdu ||
  4328. !dp_tx_cap_nbuf_list_get_ref(ptr_nbuf_list))
  4329. continue;
  4330. cur_ppdu_desc = (struct cdp_tx_completion_ppdu *)
  4331. qdf_nbuf_data(ptr_nbuf_list->nbuf_ppdu);
  4332. if (!cur_ppdu_desc)
  4333. continue;
  4334. if (usr_idx >= cur_ppdu_desc->num_users)
  4335. continue;
  4336. cur_user = &cur_ppdu_desc->user[usr_idx];
  4337. if ((cur_user->delayed_ba == 1) ||
  4338. (cur_user->skip == 1) || (cur_user->mon_procd == 1))
  4339. continue;
  4340. peer_id = cur_ppdu_desc->user[usr_idx].peer_id;
  4341. peer = DP_TX_PEER_GET_REF(pdev, peer_id);
  4342. if (!peer) {
  4343. dp_ppdu_desc_free(ptr_nbuf_list, usr_idx);
  4344. continue;
  4345. }
  4346. if (!peer->tx_capture.is_tid_initialized) {
  4347. dp_ppdu_desc_free(ptr_nbuf_list, usr_idx);
  4348. DP_TX_PEER_DEL_REF(peer);
  4349. continue;
  4350. }
  4351. tx_tid = &peer->tx_capture.tx_tid[cur_user->tid];
  4352. qdf_nbuf_queue_init(&head_ppdu);
  4353. dp_tx_mon_proc_pending_ppdus(pdev, tx_tid,
  4354. nbuf_ppdu_list + i,
  4355. ppdu_desc_cnt - i,
  4356. &head_ppdu,
  4357. cur_user->peer_id,
  4358. usr_idx);
  4359. if (qdf_nbuf_is_queue_empty(&tx_tid->pending_ppdu_q)) {
  4360. while ((tmp_nbuf =
  4361. qdf_nbuf_queue_first(&head_ppdu))) {
  4362. cur_ppdu_desc =
  4363. (struct cdp_tx_completion_ppdu *)
  4364. qdf_nbuf_data(tmp_nbuf);
  4365. cur_user =
  4366. &cur_ppdu_desc->user[usr_idx];
  4367. if (cur_user->pending_retries)
  4368. break;
  4369. dp_send_data_to_stack(pdev,
  4370. cur_ppdu_desc,
  4371. usr_idx);
  4372. dp_ppdu_queue_free(tmp_nbuf, usr_idx);
  4373. qdf_nbuf_queue_remove(&head_ppdu);
  4374. qdf_nbuf_free(tmp_nbuf);
  4375. }
  4376. }
  4377. qdf_nbuf_queue_append(&tx_tid->pending_ppdu_q,
  4378. &head_ppdu);
  4379. dp_tx_mon_proc_xretries(pdev, peer, tx_tid->tid);
  4380. pending_ppdus =
  4381. qdf_nbuf_queue_len(&tx_tid->pending_ppdu_q);
  4382. if (pending_ppdus > MAX_PENDING_PPDUS) {
  4383. struct cdp_tx_completion_ppdu *tmp_ppdu_desc;
  4384. uint8_t tmp_usr_idx;
  4385. qdf_nbuf_queue_t *tmp_ppdu_q;
  4386. dp_tx_capture_err("%pK: pending ppdus (%d, %d) : %d\n",
  4387. pdev->soc, peer_id,
  4388. tx_tid->tid, pending_ppdus);
  4389. tmp_ppdu_q = &tx_tid->pending_ppdu_q;
  4390. tmp_nbuf = qdf_nbuf_queue_remove(tmp_ppdu_q);
  4391. if (qdf_unlikely(!tmp_nbuf)) {
  4392. DP_TX_PEER_DEL_REF(peer);
  4393. qdf_assert_always(0);
  4394. return;
  4395. }
  4396. tmp_ppdu_desc =
  4397. (struct cdp_tx_completion_ppdu *)
  4398. qdf_nbuf_data(tmp_nbuf);
  4399. tmp_usr_idx = dp_tx_find_usr_idx_from_peer_id(
  4400. tmp_ppdu_desc, peer_id);
  4401. dp_send_data_to_stack(pdev, tmp_ppdu_desc,
  4402. tmp_usr_idx);
  4403. dp_ppdu_queue_free(tmp_nbuf, tmp_usr_idx);
  4404. qdf_nbuf_free(tmp_nbuf);
  4405. pdev->tx_capture.pend_ppdu_dropped++;
  4406. }
  4407. DP_TX_PEER_DEL_REF(peer);
  4408. }
  4409. }
  4410. }
  4411. static uint32_t
  4412. dp_tx_cap_proc_per_ppdu_info(struct dp_pdev *pdev, qdf_nbuf_t nbuf_ppdu,
  4413. struct dp_tx_cap_nbuf_list nbuf_ppdu_list[],
  4414. uint32_t ppdu_desc_cnt)
  4415. {
  4416. struct dp_tx_cap_nbuf_list *ptr_nbuf_list;
  4417. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  4418. struct dp_peer *peer = NULL;
  4419. qdf_nbuf_queue_t head_msdu;
  4420. qdf_nbuf_queue_t head_xretries;
  4421. uint32_t retries = 0;
  4422. uint32_t ret = 0;
  4423. uint32_t start_tsf = 0;
  4424. uint32_t end_tsf = 0;
  4425. uint32_t bar_start_tsf = 0;
  4426. uint32_t bar_end_tsf = 0;
  4427. uint16_t tid = 0;
  4428. uint32_t num_msdu = 0;
  4429. uint32_t qlen = 0;
  4430. uint16_t peer_id;
  4431. uint8_t type, subtype;
  4432. uint8_t usr_idx;
  4433. bool is_bar_frm_with_data = false;
  4434. uint8_t usr_type;
  4435. uint8_t usr_subtype;
  4436. qdf_nbuf_queue_init(&head_msdu);
  4437. qdf_nbuf_queue_init(&head_xretries);
  4438. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(nbuf_ppdu);
  4439. type = (ppdu_desc->frame_ctrl &
  4440. IEEE80211_FC0_TYPE_MASK);
  4441. subtype = (ppdu_desc->frame_ctrl &
  4442. IEEE80211_FC0_SUBTYPE_MASK);
  4443. if ((type == IEEE80211_FC0_TYPE_DATA) &&
  4444. (subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL) &&
  4445. (ppdu_desc->htt_frame_type ==
  4446. HTT_STATS_FTYPE_TIDQ_DATA_SU)) {
  4447. ppdu_desc->htt_frame_type =
  4448. HTT_STATS_FTYPE_SGEN_QOS_NULL;
  4449. }
  4450. usr_type = (ppdu_desc->user[0].frame_ctrl &
  4451. IEEE80211_FC0_TYPE_MASK);
  4452. usr_subtype = (ppdu_desc->user[0].frame_ctrl &
  4453. IEEE80211_FC0_SUBTYPE_MASK);
  4454. if (((type == IEEE80211_FC0_TYPE_CTL) &&
  4455. (subtype == IEEE80211_FC0_SUBTYPE_BAR) &&
  4456. (usr_type == IEEE80211_FC0_TYPE_DATA)) ||
  4457. ppdu_desc->htt_frame_type == HTT_STATS_FTYPE_SGEN_MU_BAR)
  4458. is_bar_frm_with_data = true;
  4459. ptr_nbuf_list = &nbuf_ppdu_list[ppdu_desc_cnt];
  4460. /* ppdu start timestamp */
  4461. start_tsf = ppdu_desc->ppdu_start_timestamp;
  4462. end_tsf = ppdu_desc->ppdu_end_timestamp;
  4463. bar_start_tsf = ppdu_desc->bar_ppdu_start_timestamp;
  4464. bar_end_tsf = ppdu_desc->bar_ppdu_end_timestamp;
  4465. if (((ppdu_desc->frame_type == CDP_PPDU_FTYPE_DATA) &&
  4466. (ppdu_desc->htt_frame_type !=
  4467. HTT_STATS_FTYPE_SGEN_QOS_NULL)) ||
  4468. is_bar_frm_with_data) {
  4469. uint32_t mpdu_suc;
  4470. uint32_t mpdu_tri;
  4471. uint8_t ref_cnt = 0;
  4472. uint8_t num_users = ppdu_desc->num_users;
  4473. struct dp_tx_tid *tx_tid;
  4474. struct cdp_tx_completion_ppdu *xretry_ppdu;
  4475. struct cdp_tx_completion_ppdu_user *xretry_user;
  4476. struct cdp_tx_completion_ppdu_user *user;
  4477. qdf_nbuf_queue_t *mpdu_q;
  4478. qdf_nbuf_queue_t *x_mpdu_q;
  4479. for (usr_idx = 0; usr_idx < num_users;
  4480. usr_idx++) {
  4481. uint32_t ppdu_id;
  4482. peer = NULL;
  4483. user = &ppdu_desc->user[usr_idx];
  4484. if (usr_idx + 1 != num_users)
  4485. qdf_nbuf_ref(nbuf_ppdu);
  4486. if (user->delayed_ba == 1) {
  4487. user->skip = 1;
  4488. goto free_nbuf_dec_ref;
  4489. }
  4490. peer_id = user->peer_id;
  4491. peer = DP_TX_PEER_GET_REF(pdev, peer_id);
  4492. /**
  4493. * peer can be NULL
  4494. */
  4495. if (!peer || !peer->tx_capture.is_tid_initialized) {
  4496. user->skip = 1;
  4497. goto free_nbuf_dec_ref;
  4498. }
  4499. /**
  4500. * check whether it is bss peer,
  4501. * if bss_peer no need to process
  4502. * further check whether tx_capture
  4503. * feature is enabled for this peer
  4504. * or globally for all peers
  4505. */
  4506. if (peer->bss_peer ||
  4507. !dp_peer_or_pdev_tx_cap_enabled(pdev,
  4508. peer, peer->mac_addr.raw) || user->is_mcast) {
  4509. user->skip = 1;
  4510. goto free_nbuf_dec_ref;
  4511. }
  4512. /* update failed bitmap */
  4513. dp_process_ppdu_stats_update_failed_bitmap(
  4514. pdev, user, ppdu_desc->ppdu_id,
  4515. CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  4516. /* print the bit map */
  4517. dp_tx_print_bitmap(pdev, ppdu_desc,
  4518. usr_idx,
  4519. ppdu_desc->ppdu_id);
  4520. if (user->tid > DP_MAX_TIDS) {
  4521. dp_tx_capture_err("%pK: ppdu[%d] peer_id[%d] TID[%d] > NON_QOS_TID!",
  4522. pdev->soc,
  4523. ppdu_desc->ppdu_id,
  4524. user->peer_id,
  4525. user->tid);
  4526. user->skip = 1;
  4527. goto free_nbuf_dec_ref;
  4528. }
  4529. if (is_bar_frm_with_data)
  4530. ppdu_id = ppdu_desc->bar_ppdu_id;
  4531. else
  4532. ppdu_id = ppdu_desc->ppdu_id;
  4533. tid = user->tid;
  4534. num_msdu = user->num_msdu;
  4535. dequeue_msdu_again:
  4536. /*
  4537. * retrieve msdu buffer based on ppdu_id & tid
  4538. * based msdu queue and store it in local queue
  4539. * sometimes, wbm comes later than per ppdu
  4540. * stats. Assumption: all packets are SU,
  4541. * and packets comes in order
  4542. */
  4543. ret = dp_tx_msdu_dequeue(peer,
  4544. ppdu_id,
  4545. tid,
  4546. num_msdu,
  4547. &head_msdu,
  4548. &head_xretries,
  4549. start_tsf,
  4550. end_tsf);
  4551. if (!ret && (++retries < 2)) {
  4552. /* wait for wbm to complete */
  4553. qdf_mdelay(2);
  4554. goto dequeue_msdu_again;
  4555. }
  4556. /*
  4557. * restitch mpdu from xretry msdu
  4558. * xretry msdu queue empty check is
  4559. * done inside restitch function
  4560. */
  4561. tx_tid = &peer->tx_capture.tx_tid[tid];
  4562. xretry_ppdu = tx_tid->xretry_ppdu;
  4563. xretry_user = &xretry_ppdu->user[0];
  4564. xretry_ppdu->ppdu_id =
  4565. peer->tx_capture.tx_wifi_ppdu_id;
  4566. x_mpdu_q = &xretry_user->mpdu_q;
  4567. /* Restitch MPDUs from xretry MSDUs */
  4568. dp_tx_mon_restitch_mpdu(pdev, peer,
  4569. xretry_ppdu,
  4570. &head_xretries,
  4571. x_mpdu_q, 0);
  4572. qlen = qdf_nbuf_queue_len(x_mpdu_q);
  4573. dp_tx_cap_stats_mpdu_update(peer, PEER_MPDU_RESTITCH,
  4574. qlen);
  4575. if (qdf_nbuf_is_queue_empty(
  4576. &head_msdu)) {
  4577. if (user->completion_status == 2)
  4578. goto nbuf_add_ref;
  4579. user->skip = 1;
  4580. goto free_nbuf_dec_ref;
  4581. }
  4582. mpdu_q = &user->mpdu_q;
  4583. /*
  4584. * now head_msdu hold - msdu list for
  4585. * that particular ppdu_id, restitch
  4586. * mpdu from msdu and create a mpdu
  4587. * queue
  4588. */
  4589. dp_tx_mon_restitch_mpdu(pdev,
  4590. peer,
  4591. ppdu_desc,
  4592. &head_msdu,
  4593. mpdu_q,
  4594. usr_idx);
  4595. /*
  4596. * sanity: free local head msdu queue
  4597. * do we need this ?
  4598. */
  4599. TX_CAP_NBUF_QUEUE_FREE(&head_msdu);
  4600. qlen = qdf_nbuf_queue_len(mpdu_q);
  4601. dp_tx_cap_stats_mpdu_update(peer, PEER_MPDU_RESTITCH,
  4602. qlen);
  4603. if (!qlen) {
  4604. user->skip = 1;
  4605. dp_ppdu_queue_free(nbuf_ppdu,
  4606. usr_idx);
  4607. goto free_nbuf_dec_ref;
  4608. }
  4609. mpdu_suc = user->mpdu_success;
  4610. mpdu_tri = user->mpdu_tried_ucast +
  4611. user->mpdu_tried_mcast;
  4612. /* print ppdu_desc info for debugging purpose */
  4613. 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]",
  4614. pdev->soc,
  4615. ppdu_desc->ppdu_id,
  4616. ppdu_desc->bar_ppdu_id,
  4617. user->peer_id,
  4618. user->tid,
  4619. ppdu_desc->num_mpdu,
  4620. mpdu_suc,
  4621. ppdu_desc->num_msdu, retries,
  4622. qlen,
  4623. start_tsf, end_tsf,
  4624. bar_start_tsf, bar_end_tsf,
  4625. ppdu_desc->tx_duration,
  4626. user->start_seq,
  4627. ppdu_desc_cnt);
  4628. dp_tx_cap_stats_mpdu_update(peer, PEER_MPDU_SUCC,
  4629. mpdu_suc);
  4630. dp_tx_cap_stats_mpdu_update(peer, PEER_MPDU_TRI,
  4631. mpdu_tri);
  4632. nbuf_add_ref:
  4633. DP_TX_PEER_DEL_REF(peer);
  4634. /* get reference count */
  4635. ref_cnt = qdf_nbuf_get_users(nbuf_ppdu);
  4636. continue;
  4637. free_nbuf_dec_ref:
  4638. /* get reference before free */
  4639. ref_cnt = qdf_nbuf_get_users(nbuf_ppdu);
  4640. qdf_nbuf_free(nbuf_ppdu);
  4641. ref_cnt--;
  4642. if (peer)
  4643. DP_TX_PEER_DEL_REF(peer);
  4644. continue;
  4645. }
  4646. if (ref_cnt == 0)
  4647. return ppdu_desc_cnt;
  4648. ptr_nbuf_list->nbuf_ppdu = nbuf_ppdu;
  4649. dp_tx_cap_nbuf_list_update_ref(ptr_nbuf_list, ref_cnt);
  4650. ppdu_desc_cnt++;
  4651. } else {
  4652. /*
  4653. * other packet frame also added to
  4654. * descriptor list
  4655. */
  4656. /* print ppdu_desc info for debugging purpose */
  4657. 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[%u b %u] dur[%u]",
  4658. pdev->soc, ppdu_desc->ppdu_id,
  4659. ppdu_desc->user[0].peer_id,
  4660. ppdu_desc->user[0].tid,
  4661. ppdu_desc->frame_ctrl,
  4662. ppdu_desc->user[0].frame_ctrl,
  4663. ppdu_desc->frame_type,
  4664. ppdu_desc->htt_frame_type,
  4665. ppdu_desc->user[0].start_seq,
  4666. ppdu_desc->ppdu_start_timestamp,
  4667. ppdu_desc->bar_ppdu_start_timestamp,
  4668. ppdu_desc->tx_duration);
  4669. ptr_nbuf_list->nbuf_ppdu = nbuf_ppdu;
  4670. dp_tx_cap_nbuf_list_update_ref(ptr_nbuf_list,
  4671. 1);
  4672. ppdu_desc_cnt++;
  4673. }
  4674. return ppdu_desc_cnt;
  4675. }
  4676. /**
  4677. * dp_tx_ppdu_stats_process - Deferred PPDU stats handler
  4678. * @context: Opaque work context (PDEV)
  4679. *
  4680. * Return: none
  4681. */
  4682. void dp_tx_ppdu_stats_process(void *context)
  4683. {
  4684. uint32_t curr_sched_cmdid;
  4685. uint32_t last_ppdu_id;
  4686. uint32_t ppdu_cnt;
  4687. uint32_t ppdu_desc_cnt = 0;
  4688. struct dp_pdev *pdev = (struct dp_pdev *)context;
  4689. struct ppdu_info *ppdu_info, *tmp_ppdu_info = NULL;
  4690. uint32_t now_ms = qdf_system_ticks_to_msecs(qdf_system_ticks());
  4691. struct ppdu_info *sched_ppdu_info = NULL;
  4692. STAILQ_HEAD(, ppdu_info) sched_ppdu_queue;
  4693. struct ppdu_info *sched_ppdu_list_last_ptr;
  4694. struct dp_tx_cap_nbuf_list *nbuf_ppdu_list;
  4695. struct dp_tx_cap_nbuf_list *ptr_nbuf_list;
  4696. qdf_nbuf_t tmp_nbuf;
  4697. qdf_nbuf_t nbuf_ppdu;
  4698. struct dp_pdev_tx_capture *ptr_tx_cap = &pdev->tx_capture;
  4699. size_t nbuf_list_sz;
  4700. uint8_t user_mode;
  4701. STAILQ_INIT(&sched_ppdu_queue);
  4702. /* Move the PPDU entries to defer list */
  4703. qdf_spin_lock_bh(&ptr_tx_cap->ppdu_stats_lock);
  4704. STAILQ_CONCAT(&ptr_tx_cap->ppdu_stats_defer_queue,
  4705. &ptr_tx_cap->ppdu_stats_queue);
  4706. ptr_tx_cap->ppdu_stats_defer_queue_depth +=
  4707. ptr_tx_cap->ppdu_stats_queue_depth;
  4708. ptr_tx_cap->ppdu_stats_queue_depth = 0;
  4709. qdf_spin_unlock_bh(&ptr_tx_cap->ppdu_stats_lock);
  4710. while (!STAILQ_EMPTY(&ptr_tx_cap->ppdu_stats_defer_queue)) {
  4711. ppdu_info =
  4712. STAILQ_FIRST(&ptr_tx_cap->ppdu_stats_defer_queue);
  4713. curr_sched_cmdid = ppdu_info->sched_cmdid;
  4714. ppdu_cnt = 0;
  4715. STAILQ_FOREACH_SAFE(ppdu_info,
  4716. &ptr_tx_cap->ppdu_stats_defer_queue,
  4717. ppdu_info_queue_elem, tmp_ppdu_info) {
  4718. if (curr_sched_cmdid != ppdu_info->sched_cmdid)
  4719. break;
  4720. sched_ppdu_list_last_ptr = ppdu_info;
  4721. ppdu_cnt++;
  4722. }
  4723. if (ppdu_info && (curr_sched_cmdid == ppdu_info->sched_cmdid) &&
  4724. ptr_tx_cap->ppdu_stats_next_sched < now_ms)
  4725. break;
  4726. last_ppdu_id = sched_ppdu_list_last_ptr->ppdu_id;
  4727. STAILQ_FIRST(&sched_ppdu_queue) =
  4728. STAILQ_FIRST(&ptr_tx_cap->ppdu_stats_defer_queue);
  4729. STAILQ_REMOVE_HEAD_UNTIL(&ptr_tx_cap->ppdu_stats_defer_queue,
  4730. sched_ppdu_list_last_ptr,
  4731. ppdu_info_queue_elem);
  4732. STAILQ_NEXT(sched_ppdu_list_last_ptr,
  4733. ppdu_info_queue_elem) = NULL;
  4734. ptr_tx_cap->ppdu_stats_defer_queue_depth -= ppdu_cnt;
  4735. nbuf_list_sz = sizeof(struct dp_tx_cap_nbuf_list);
  4736. nbuf_ppdu_list = (struct dp_tx_cap_nbuf_list *)
  4737. qdf_mem_malloc(nbuf_list_sz * ppdu_cnt);
  4738. /*
  4739. * if there is no memory allocated we need to free sched ppdu
  4740. * list, no ppdu stats will be updated.
  4741. */
  4742. if (!nbuf_ppdu_list) {
  4743. STAILQ_FOREACH_SAFE(sched_ppdu_info,
  4744. &sched_ppdu_queue,
  4745. ppdu_info_queue_elem,
  4746. tmp_ppdu_info) {
  4747. ppdu_info = sched_ppdu_info;
  4748. tmp_nbuf = ppdu_info->nbuf;
  4749. qdf_mem_free(ppdu_info);
  4750. qdf_nbuf_free(tmp_nbuf);
  4751. }
  4752. continue;
  4753. }
  4754. /*
  4755. * value stored for debugging purpose to get info
  4756. * for debugging purpose.
  4757. */
  4758. ptr_tx_cap->last_nbuf_ppdu_list = nbuf_ppdu_list;
  4759. ptr_tx_cap->last_nbuf_ppdu_list_arr_sz = ppdu_cnt;
  4760. ppdu_desc_cnt = 0;
  4761. STAILQ_FOREACH_SAFE(sched_ppdu_info,
  4762. &sched_ppdu_queue,
  4763. ppdu_info_queue_elem, tmp_ppdu_info) {
  4764. ppdu_info = sched_ppdu_info;
  4765. pdev->stats.tx_ppdu_proc++;
  4766. /* update ppdu desc user stats */
  4767. dp_ppdu_desc_user_stats_update(pdev, ppdu_info);
  4768. /*
  4769. * While processing/corelating Tx buffers, we should
  4770. * hold the entire PPDU list for the give sched_cmdid
  4771. * instead of freeing below.
  4772. */
  4773. nbuf_ppdu = ppdu_info->nbuf;
  4774. qdf_mem_free(ppdu_info);
  4775. qdf_assert_always(nbuf_ppdu);
  4776. /* check tx capture disable */
  4777. if (pdev->tx_capture_enabled ==
  4778. CDP_TX_ENH_CAPTURE_DISABLED) {
  4779. struct cdp_tx_completion_ppdu *ppdu_desc;
  4780. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  4781. qdf_nbuf_data(nbuf_ppdu);
  4782. /**
  4783. * Deliver PPDU stats only for valid (acked)
  4784. * data frames if sniffer mode is not enabled.
  4785. * If sniffer mode is enabled,
  4786. * PPDU stats for all frames including
  4787. * mgmt/control frames should be delivered
  4788. * to upper layer
  4789. */
  4790. if (pdev->tx_sniffer_enable ||
  4791. pdev->mcopy_mode) {
  4792. dp_wdi_event_handler(
  4793. WDI_EVENT_TX_PPDU_DESC,
  4794. pdev->soc,
  4795. nbuf_ppdu,
  4796. HTT_INVALID_PEER,
  4797. WDI_NO_VAL,
  4798. pdev->pdev_id);
  4799. } else {
  4800. if (ppdu_desc->num_mpdu != 0 &&
  4801. ppdu_desc->num_users != 0 &&
  4802. (ppdu_desc->frame_ctrl &
  4803. HTT_FRAMECTRL_DATATYPE)) {
  4804. dp_wdi_event_handler(
  4805. WDI_EVENT_TX_PPDU_DESC,
  4806. pdev->soc,
  4807. nbuf_ppdu,
  4808. HTT_INVALID_PEER,
  4809. WDI_NO_VAL,
  4810. pdev->pdev_id);
  4811. } else {
  4812. qdf_nbuf_free(nbuf_ppdu);
  4813. }
  4814. }
  4815. continue;
  4816. } else {
  4817. tx_cap_debugfs_log_ppdu_desc(pdev, nbuf_ppdu);
  4818. /* process ppdu_info on tx capture turned on */
  4819. ppdu_desc_cnt = dp_tx_cap_proc_per_ppdu_info(
  4820. pdev,
  4821. nbuf_ppdu,
  4822. nbuf_ppdu_list,
  4823. ppdu_desc_cnt);
  4824. }
  4825. }
  4826. /*
  4827. * At this point we have mpdu queued per ppdu_desc
  4828. * based on packet capture flags send mpdu info to upper stack
  4829. */
  4830. if (ppdu_desc_cnt) {
  4831. uint32_t i;
  4832. dp_check_ppdu_and_deliver(pdev, nbuf_ppdu_list,
  4833. ppdu_desc_cnt);
  4834. for (i = 0; i < ppdu_desc_cnt; i++) {
  4835. ptr_nbuf_list = &nbuf_ppdu_list[i];
  4836. if (dp_tx_cap_nbuf_list_get_ref(
  4837. ptr_nbuf_list)) {
  4838. dp_tx_capture_alert("%pK: missing handling of ppdu_desc ref_cnt:%d ,i : %d ptr %p, ppdu_desc_cnt %d!!!\n",
  4839. pdev->soc,
  4840. ptr_nbuf_list->ref_cnt, i, ptr_nbuf_list, ppdu_desc_cnt);
  4841. QDF_BUG(0);
  4842. }
  4843. }
  4844. }
  4845. qdf_mem_free(nbuf_ppdu_list);
  4846. /* get user mode */
  4847. user_mode = qdf_atomic_read(&pdev->tx_capture.tx_cap_usr_mode);
  4848. /*
  4849. * invoke mode change if user mode value is
  4850. * different from driver mode value,
  4851. * this was done to reduce config lock
  4852. */
  4853. if (user_mode != pdev->tx_capture_enabled)
  4854. dp_enh_tx_cap_mode_change(pdev, user_mode);
  4855. }
  4856. }
  4857. /**
  4858. * dp_ppdu_desc_deliver(): Function to deliver Tx PPDU status descriptor
  4859. * to upper layer
  4860. * @pdev: DP pdev handle
  4861. * @ppdu_info: per PPDU TLV descriptor
  4862. *
  4863. * return: void
  4864. */
  4865. void dp_ppdu_desc_deliver(struct dp_pdev *pdev,
  4866. struct ppdu_info *ppdu_info)
  4867. {
  4868. struct ppdu_info *s_ppdu_info = NULL;
  4869. struct ppdu_info *ppdu_info_next = NULL;
  4870. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  4871. uint32_t time_delta = 0;
  4872. bool starved = 0;
  4873. bool matched = 0;
  4874. bool recv_ack_ba_done = 0;
  4875. if (ppdu_info->tlv_bitmap & (1 << HTT_PPDU_STATS_USR_COMPLTN_ACK_BA_STATUS_TLV) && ppdu_info->done)
  4876. recv_ack_ba_done = 1;
  4877. pdev->last_sched_cmdid = ppdu_info->sched_cmdid;
  4878. s_ppdu_info = TAILQ_FIRST(&pdev->sched_comp_ppdu_list);
  4879. TAILQ_FOREACH_SAFE(s_ppdu_info, &pdev->sched_comp_ppdu_list,
  4880. ppdu_info_list_elem, ppdu_info_next) {
  4881. if (s_ppdu_info->tsf_l32 > ppdu_info->tsf_l32)
  4882. time_delta = (MAX_TSF_32 - s_ppdu_info->tsf_l32) +
  4883. ppdu_info->tsf_l32;
  4884. else
  4885. time_delta = ppdu_info->tsf_l32 - s_ppdu_info->tsf_l32;
  4886. if (!s_ppdu_info->done && !recv_ack_ba_done) {
  4887. if (time_delta < MAX_SCHED_STARVE) {
  4888. 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]",
  4889. pdev->soc, pdev->pdev_id,
  4890. s_ppdu_info->ppdu_id, s_ppdu_info->ppdu_id,
  4891. s_ppdu_info->sched_cmdid, s_ppdu_info->sched_cmdid,
  4892. s_ppdu_info->tlv_bitmap, s_ppdu_info->tsf_l32,
  4893. s_ppdu_info->done);
  4894. break;
  4895. } else {
  4896. starved = 1;
  4897. }
  4898. }
  4899. pdev->delivered_sched_cmdid = s_ppdu_info->sched_cmdid;
  4900. TAILQ_REMOVE(&pdev->sched_comp_ppdu_list, s_ppdu_info,
  4901. ppdu_info_list_elem);
  4902. pdev->sched_comp_list_depth--;
  4903. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  4904. qdf_nbuf_data(s_ppdu_info->nbuf);
  4905. ppdu_desc->tlv_bitmap = s_ppdu_info->tlv_bitmap;
  4906. ppdu_desc->sched_cmdid = ppdu_info->sched_cmdid;
  4907. if (starved) {
  4908. dp_tx_capture_info("%pK: ppdu starved fc[0x%x] h_ftype[%d] tlv_bitmap[0x%x] cs[%d]\n",
  4909. pdev->soc, ppdu_desc->frame_ctrl,
  4910. ppdu_desc->htt_frame_type,
  4911. ppdu_desc->tlv_bitmap,
  4912. ppdu_desc->user[0].completion_status);
  4913. starved = 0;
  4914. }
  4915. if (ppdu_info->ppdu_id == s_ppdu_info->ppdu_id &&
  4916. ppdu_info->sched_cmdid == s_ppdu_info->sched_cmdid)
  4917. matched = 1;
  4918. 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]",
  4919. pdev->soc, pdev->pdev_id, ppdu_desc->vdev_id,
  4920. s_ppdu_info->ppdu_id, s_ppdu_info->ppdu_id,
  4921. s_ppdu_info->sched_cmdid, s_ppdu_info->sched_cmdid,
  4922. ppdu_desc->frame_ctrl,
  4923. ppdu_desc->htt_frame_type,
  4924. ppdu_desc->tlv_bitmap, s_ppdu_info->tsf_l32,
  4925. ppdu_desc->user[0].completion_status, matched,
  4926. ppdu_info->ppdu_id, ppdu_info->sched_cmdid);
  4927. qdf_spin_lock_bh(&pdev->tx_capture.ppdu_stats_lock);
  4928. if (qdf_unlikely(!pdev->tx_capture_enabled &&
  4929. (pdev->tx_capture.ppdu_stats_queue_depth +
  4930. pdev->tx_capture.ppdu_stats_defer_queue_depth) >
  4931. DP_TX_PPDU_PROC_MAX_DEPTH)) {
  4932. qdf_nbuf_free(s_ppdu_info->nbuf);
  4933. qdf_mem_free(s_ppdu_info);
  4934. pdev->tx_capture.ppdu_dropped++;
  4935. } else {
  4936. STAILQ_INSERT_TAIL(&pdev->tx_capture.ppdu_stats_queue,
  4937. s_ppdu_info, ppdu_info_queue_elem);
  4938. pdev->tx_capture.ppdu_stats_queue_depth++;
  4939. }
  4940. qdf_spin_unlock_bh(&pdev->tx_capture.ppdu_stats_lock);
  4941. if (matched)
  4942. break;
  4943. }
  4944. if (pdev->tx_capture.ppdu_stats_queue_depth >
  4945. DP_TX_PPDU_PROC_THRESHOLD) {
  4946. qdf_queue_work(0, pdev->tx_capture.ppdu_stats_workqueue,
  4947. &pdev->tx_capture.ppdu_stats_work);
  4948. }
  4949. qdf_timer_mod(&pdev->tx_capture.work_q_timer,
  4950. TX_CAPTURE_WORK_Q_TIMER_MS);
  4951. }
  4952. static void set_mpdu_info(
  4953. struct cdp_tx_indication_info *tx_capture_info,
  4954. struct mon_rx_status *rx_status,
  4955. struct mon_rx_user_status *rx_user_status)
  4956. {
  4957. struct cdp_tx_indication_mpdu_info *mpdu_info;
  4958. qdf_mem_set(tx_capture_info,
  4959. sizeof(struct cdp_tx_indication_info), 0);
  4960. mpdu_info = &tx_capture_info->mpdu_info;
  4961. mpdu_info->ppdu_start_timestamp = rx_status->tsft + 16;
  4962. mpdu_info->channel_num = rx_status->chan_num;
  4963. mpdu_info->channel = rx_status->chan_freq;
  4964. mpdu_info->bw = 0;
  4965. if (rx_status->preamble_type == HAL_RX_PKT_TYPE_11B) {
  4966. mpdu_info->preamble = DOT11_B;
  4967. mpdu_info->mcs = CDP_LEGACY_MCS3;
  4968. } else if (rx_status->preamble_type == HAL_RX_PKT_TYPE_11A) {
  4969. mpdu_info->preamble = DOT11_A;
  4970. mpdu_info->mcs = CDP_LEGACY_MCS3;
  4971. } else {
  4972. mpdu_info->preamble = DOT11_A;
  4973. mpdu_info->mcs = CDP_LEGACY_MCS1;
  4974. }
  4975. }
  4976. static void dp_gen_ack_frame(struct hal_rx_ppdu_info *ppdu_info,
  4977. struct dp_peer *peer,
  4978. qdf_nbuf_t mpdu_nbuf)
  4979. {
  4980. struct ieee80211_frame_min_one *wh_addr1;
  4981. wh_addr1 = (struct ieee80211_frame_min_one *)
  4982. qdf_nbuf_data(mpdu_nbuf);
  4983. wh_addr1->i_fc[0] = 0;
  4984. wh_addr1->i_fc[1] = 0;
  4985. wh_addr1->i_fc[0] = IEEE80211_FC0_VERSION_0 |
  4986. IEEE80211_FC0_TYPE_CTL |
  4987. IEEE80211_FC0_SUBTYPE_ACK;
  4988. if (peer) {
  4989. qdf_mem_copy(wh_addr1->i_addr1,
  4990. &peer->mac_addr.raw[0],
  4991. QDF_MAC_ADDR_SIZE);
  4992. } else {
  4993. qdf_mem_copy(wh_addr1->i_addr1,
  4994. &ppdu_info->nac_info.mac_addr2[0],
  4995. QDF_MAC_ADDR_SIZE);
  4996. }
  4997. *(u_int16_t *)(&wh_addr1->i_dur) = qdf_cpu_to_le16(0x0000);
  4998. qdf_nbuf_set_pktlen(mpdu_nbuf, sizeof(*wh_addr1));
  4999. }
  5000. static void dp_gen_block_ack_frame(
  5001. struct hal_rx_ppdu_info *ppdu_info,
  5002. struct mon_rx_user_status *rx_user_status,
  5003. struct mon_rx_user_info *rx_user_info,
  5004. struct dp_peer *peer,
  5005. qdf_nbuf_t mpdu_nbuf)
  5006. {
  5007. struct dp_vdev *vdev = NULL;
  5008. uint32_t tid;
  5009. struct dp_tx_tid *tx_tid;
  5010. struct ieee80211_ctlframe_addr2 *wh_addr2;
  5011. uint8_t *frm;
  5012. tid = rx_user_status->tid;
  5013. tx_tid = &peer->tx_capture.tx_tid[tid];
  5014. if (ppdu_info->sw_frame_group_id != HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR) {
  5015. tx_tid->first_data_seq_ctrl =
  5016. rx_user_status->first_data_seq_ctrl;
  5017. tx_tid->mpdu_cnt = rx_user_status->mpdu_cnt_fcs_ok +
  5018. rx_user_status->mpdu_cnt_fcs_err;
  5019. if (tx_tid->mpdu_cnt > DP_MAX_MPDU_64)
  5020. qdf_mem_copy(tx_tid->mpdu_fcs_ok_bitmap,
  5021. rx_user_status->mpdu_fcs_ok_bitmap,
  5022. HAL_RX_NUM_WORDS_PER_PPDU_BITMAP * sizeof(
  5023. rx_user_status->mpdu_fcs_ok_bitmap[0]));
  5024. else
  5025. qdf_mem_copy(tx_tid->mpdu_fcs_ok_bitmap,
  5026. rx_user_status->mpdu_fcs_ok_bitmap,
  5027. DP_NUM_WORDS_PER_PPDU_BITMAP_64 * sizeof(
  5028. rx_user_status->mpdu_fcs_ok_bitmap[0]));
  5029. }
  5030. wh_addr2 = (struct ieee80211_ctlframe_addr2 *)
  5031. qdf_nbuf_data(mpdu_nbuf);
  5032. qdf_mem_zero(wh_addr2, DP_BA_ACK_FRAME_SIZE);
  5033. wh_addr2->i_fc[0] = 0;
  5034. wh_addr2->i_fc[1] = 0;
  5035. wh_addr2->i_fc[0] = IEEE80211_FC0_VERSION_0 |
  5036. IEEE80211_FC0_TYPE_CTL |
  5037. IEEE80211_FC0_BLOCK_ACK;
  5038. *(u_int16_t *)(&wh_addr2->i_aidordur) = qdf_cpu_to_le16(0x0000);
  5039. vdev = peer->vdev;
  5040. if (vdev)
  5041. qdf_mem_copy(wh_addr2->i_addr2, vdev->mac_addr.raw,
  5042. QDF_MAC_ADDR_SIZE);
  5043. qdf_mem_copy(wh_addr2->i_addr1, &peer->mac_addr.raw[0],
  5044. QDF_MAC_ADDR_SIZE);
  5045. frm = (uint8_t *)&wh_addr2[1];
  5046. *((uint16_t *)frm) =
  5047. qdf_cpu_to_le16((rx_user_status->tid <<
  5048. DP_IEEE80211_BAR_CTL_TID_S) |
  5049. DP_IEEE80211_BAR_CTL_COMBA);
  5050. frm += 2;
  5051. *((uint16_t *)frm) =
  5052. tx_tid->first_data_seq_ctrl;
  5053. frm += 2;
  5054. if (tx_tid->mpdu_cnt > DP_MAX_MPDU_64) {
  5055. qdf_mem_copy(frm,
  5056. tx_tid->mpdu_fcs_ok_bitmap,
  5057. HAL_RX_NUM_WORDS_PER_PPDU_BITMAP *
  5058. sizeof(rx_user_status->mpdu_fcs_ok_bitmap[0]));
  5059. frm += DP_NUM_BYTES_PER_PPDU_BITMAP;
  5060. } else {
  5061. qdf_mem_copy(frm,
  5062. tx_tid->mpdu_fcs_ok_bitmap,
  5063. DP_NUM_WORDS_PER_PPDU_BITMAP_64 *
  5064. sizeof(rx_user_status->mpdu_fcs_ok_bitmap[0]));
  5065. frm += DP_NUM_BYTES_PER_PPDU_BITMAP_64;
  5066. }
  5067. qdf_nbuf_set_pktlen(mpdu_nbuf,
  5068. (frm - (uint8_t *)qdf_nbuf_data(mpdu_nbuf)));
  5069. }
  5070. static void dp_gen_cts_frame(struct hal_rx_ppdu_info *ppdu_info,
  5071. struct dp_peer *peer,
  5072. qdf_nbuf_t mpdu_nbuf)
  5073. {
  5074. struct ieee80211_frame_min_one *wh_addr1;
  5075. uint16_t duration;
  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_CTS;
  5083. qdf_mem_copy(wh_addr1->i_addr1, &peer->mac_addr.raw[0],
  5084. QDF_MAC_ADDR_SIZE);
  5085. duration = (ppdu_info->rx_status.duration > SIFS_INTERVAL) ?
  5086. ppdu_info->rx_status.duration - SIFS_INTERVAL : 0;
  5087. wh_addr1->i_dur[0] = duration & 0xff;
  5088. wh_addr1->i_dur[1] = (duration >> 8) & 0xff;
  5089. qdf_nbuf_set_pktlen(mpdu_nbuf, sizeof(*wh_addr1));
  5090. }
  5091. /**
  5092. * dp_send_cts_frame_to_stack(): Function to deliver HW generated CTS frame
  5093. * in reponse to RTS
  5094. * @soc: core txrx main context
  5095. * @pdev: DP pdev object
  5096. * @ppdu_info: HAL RX PPDU info retrieved from status ring TLV
  5097. *
  5098. * return: status
  5099. */
  5100. QDF_STATUS dp_send_cts_frame_to_stack(struct dp_soc *soc,
  5101. struct dp_pdev *pdev,
  5102. struct hal_rx_ppdu_info *ppdu_info)
  5103. {
  5104. struct cdp_tx_indication_info tx_capture_info;
  5105. struct mon_rx_user_status *rx_user_status =
  5106. &ppdu_info->rx_user_status[0];
  5107. struct dp_ast_entry *ast_entry;
  5108. uint32_t peer_id;
  5109. struct dp_peer *peer;
  5110. struct dp_vdev *vdev = NULL;
  5111. if (rx_user_status->ast_index >=
  5112. wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  5113. return QDF_STATUS_E_FAILURE;
  5114. }
  5115. qdf_spin_lock_bh(&soc->ast_lock);
  5116. ast_entry = soc->ast_table[rx_user_status->ast_index];
  5117. if (!ast_entry) {
  5118. qdf_spin_unlock_bh(&soc->ast_lock);
  5119. return QDF_STATUS_E_FAILURE;
  5120. }
  5121. peer_id = ast_entry->peer_id;
  5122. qdf_spin_unlock_bh(&soc->ast_lock);
  5123. peer = DP_TX_PEER_GET_REF(pdev, peer_id);
  5124. if (!peer)
  5125. return QDF_STATUS_E_FAILURE;
  5126. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, NULL, peer->mac_addr.raw)) {
  5127. DP_TX_PEER_DEL_REF(peer);
  5128. return QDF_STATUS_E_FAILURE;
  5129. }
  5130. if (pdev->tx_capture_enabled == CDP_TX_ENH_CAPTURE_ENABLE_ALL_PEERS) {
  5131. int8_t match = 0;
  5132. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  5133. if (!qdf_mem_cmp(vdev->mac_addr.raw,
  5134. ppdu_info->rx_info.mac_addr1,
  5135. QDF_MAC_ADDR_SIZE)) {
  5136. match = 1;
  5137. break;
  5138. }
  5139. }
  5140. if (!match) {
  5141. DP_TX_PEER_DEL_REF(peer);
  5142. return QDF_STATUS_E_FAILURE;
  5143. }
  5144. }
  5145. set_mpdu_info(&tx_capture_info,
  5146. &ppdu_info->rx_status, rx_user_status);
  5147. /* ppdu_desc is not required for legacy frames */
  5148. tx_capture_info.ppdu_desc = NULL;
  5149. tx_capture_info.mpdu_nbuf =
  5150. qdf_nbuf_alloc(pdev->soc->osdev,
  5151. MAX_MONITOR_HEADER +
  5152. DP_CTS_FRAME_SIZE,
  5153. MAX_MONITOR_HEADER,
  5154. 4, FALSE);
  5155. if (!tx_capture_info.mpdu_nbuf) {
  5156. DP_TX_PEER_DEL_REF(peer);
  5157. return QDF_STATUS_E_NOMEM;
  5158. }
  5159. dp_gen_cts_frame(ppdu_info, peer,
  5160. tx_capture_info.mpdu_nbuf);
  5161. DP_TX_PEER_DEL_REF(peer);
  5162. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  5163. &tx_capture_info, HTT_INVALID_PEER,
  5164. WDI_NO_VAL, pdev->pdev_id);
  5165. if (tx_capture_info.mpdu_nbuf)
  5166. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  5167. return QDF_STATUS_SUCCESS;
  5168. }
  5169. /**
  5170. * dp_send_usr_ack_frm_to_stack(): Function to generate BA or ACK frame and
  5171. * send to upper layer
  5172. * @soc: core txrx main context
  5173. * @pdev: DP pdev object
  5174. * @ppdu_info: HAL RX PPDU info retrieved from status ring TLV
  5175. * @rx_status: variable for rx status
  5176. * @rx_user_status: variable for rx user status
  5177. * @rx_user_info: variable for rx user info
  5178. *
  5179. * return: no
  5180. */
  5181. void dp_send_usr_ack_frm_to_stack(struct dp_soc *soc,
  5182. struct dp_pdev *pdev,
  5183. struct hal_rx_ppdu_info *ppdu_info,
  5184. struct mon_rx_status *rx_status,
  5185. struct mon_rx_user_status *rx_user_status,
  5186. struct mon_rx_user_info *rx_user_info)
  5187. {
  5188. struct cdp_tx_indication_info tx_capture_info;
  5189. struct dp_peer *peer;
  5190. struct dp_ast_entry *ast_entry;
  5191. uint32_t peer_id;
  5192. uint32_t ast_index;
  5193. uint8_t *ptr_mac_addr;
  5194. if (rx_user_info->qos_control_info_valid &&
  5195. ((rx_user_info->qos_control &
  5196. IEEE80211_QOS_ACKPOLICY) >> IEEE80211_QOS_ACKPOLICY_S)
  5197. == IEEE80211_BAR_CTL_NOACK)
  5198. return;
  5199. ast_index = rx_user_status->ast_index;
  5200. if (ast_index >=
  5201. wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  5202. if (ppdu_info->sw_frame_group_id ==
  5203. HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR)
  5204. return;
  5205. ptr_mac_addr = &ppdu_info->nac_info.mac_addr2[0];
  5206. if (!dp_peer_or_pdev_tx_cap_enabled(pdev,
  5207. NULL, ptr_mac_addr))
  5208. return;
  5209. if (IEEE80211_IS_ZERO(ppdu_info->nac_info.mac_addr2))
  5210. return;
  5211. set_mpdu_info(&tx_capture_info,
  5212. rx_status, rx_user_status);
  5213. tx_capture_info.mpdu_nbuf =
  5214. qdf_nbuf_alloc(pdev->soc->osdev,
  5215. MAX_MONITOR_HEADER +
  5216. DP_BA_ACK_FRAME_SIZE,
  5217. MAX_MONITOR_HEADER,
  5218. 4, FALSE);
  5219. if (!tx_capture_info.mpdu_nbuf)
  5220. return;
  5221. dp_gen_ack_frame(ppdu_info, NULL,
  5222. tx_capture_info.mpdu_nbuf);
  5223. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  5224. &tx_capture_info, HTT_INVALID_PEER,
  5225. WDI_NO_VAL, pdev->pdev_id);
  5226. if (tx_capture_info.mpdu_nbuf)
  5227. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  5228. return;
  5229. }
  5230. qdf_spin_lock_bh(&soc->ast_lock);
  5231. ast_entry = soc->ast_table[ast_index];
  5232. if (!ast_entry) {
  5233. qdf_spin_unlock_bh(&soc->ast_lock);
  5234. return;
  5235. }
  5236. peer_id = ast_entry->peer_id;
  5237. qdf_spin_unlock_bh(&soc->ast_lock);
  5238. peer = DP_TX_PEER_GET_REF(pdev, peer_id);
  5239. if (!peer)
  5240. return;
  5241. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, peer,
  5242. peer->mac_addr.raw)) {
  5243. DP_TX_PEER_DEL_REF(peer);
  5244. return;
  5245. }
  5246. set_mpdu_info(&tx_capture_info,
  5247. rx_status, rx_user_status);
  5248. tx_capture_info.mpdu_nbuf =
  5249. qdf_nbuf_alloc(pdev->soc->osdev,
  5250. MAX_MONITOR_HEADER +
  5251. DP_BA_ACK_FRAME_SIZE,
  5252. MAX_MONITOR_HEADER,
  5253. 4, FALSE);
  5254. if (!tx_capture_info.mpdu_nbuf) {
  5255. DP_TX_PEER_DEL_REF(peer);
  5256. return;
  5257. }
  5258. if (peer->rx_tid[rx_user_status->tid].ba_status == DP_RX_BA_ACTIVE ||
  5259. ppdu_info->sw_frame_group_id == HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR) {
  5260. dp_gen_block_ack_frame(ppdu_info,
  5261. rx_user_status,
  5262. rx_user_info,
  5263. peer,
  5264. tx_capture_info.mpdu_nbuf);
  5265. tx_capture_info.mpdu_info.tid = rx_user_status->tid;
  5266. } else {
  5267. dp_gen_ack_frame(ppdu_info, peer,
  5268. tx_capture_info.mpdu_nbuf);
  5269. }
  5270. DP_TX_PEER_DEL_REF(peer);
  5271. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  5272. &tx_capture_info, HTT_INVALID_PEER,
  5273. WDI_NO_VAL, pdev->pdev_id);
  5274. if (tx_capture_info.mpdu_nbuf)
  5275. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  5276. }
  5277. /**
  5278. * dp_send_ack_frame_to_stack(): Function to generate BA or ACK frame and
  5279. * send to upper layer on received unicast frame
  5280. * @soc: core txrx main context
  5281. * @pdev: DP pdev object
  5282. * @ppdu_info: HAL RX PPDU info retrieved from status ring TLV
  5283. *
  5284. * return: status
  5285. */
  5286. QDF_STATUS dp_send_ack_frame_to_stack(struct dp_soc *soc,
  5287. struct dp_pdev *pdev,
  5288. struct hal_rx_ppdu_info *ppdu_info)
  5289. {
  5290. struct mon_rx_status *rx_status;
  5291. struct mon_rx_user_status *rx_user_status;
  5292. struct mon_rx_user_info *rx_user_info;
  5293. uint32_t i;
  5294. rx_status = &ppdu_info->rx_status;
  5295. if (ppdu_info->sw_frame_group_id ==
  5296. HAL_MPDU_SW_FRAME_GROUP_CTRL_RTS) {
  5297. return dp_send_cts_frame_to_stack(soc, pdev, ppdu_info);
  5298. }
  5299. if (!rx_status->rxpcu_filter_pass)
  5300. return QDF_STATUS_SUCCESS;
  5301. if (ppdu_info->sw_frame_group_id ==
  5302. HAL_MPDU_SW_FRAME_GROUP_MGMT_BEACON ||
  5303. ppdu_info->sw_frame_group_id ==
  5304. HAL_MPDU_SW_FRAME_GROUP_CTRL_NDPA)
  5305. return QDF_STATUS_SUCCESS;
  5306. if (ppdu_info->sw_frame_group_id == HAL_MPDU_SW_FRAME_GROUP_MGMT_PROBE_REQ &&
  5307. (ppdu_info->rx_info.mac_addr1[0] & 1)) {
  5308. return QDF_STATUS_SUCCESS;
  5309. }
  5310. if (ppdu_info->sw_frame_group_id == HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR)
  5311. return QDF_STATUS_SUCCESS;
  5312. for (i = 0; i < ppdu_info->com_info.num_users; i++) {
  5313. if (i > OFDMA_NUM_USERS)
  5314. return QDF_STATUS_E_FAULT;
  5315. rx_user_status = &ppdu_info->rx_user_status[i];
  5316. rx_user_info = &ppdu_info->rx_user_info[i];
  5317. dp_send_usr_ack_frm_to_stack(soc, pdev, ppdu_info, rx_status,
  5318. rx_user_status, rx_user_info);
  5319. }
  5320. return QDF_STATUS_SUCCESS;
  5321. }
  5322. /**
  5323. * dp_bar_send_ack_frm_to_stack(): send BA or ACK frame
  5324. * to upper layers on received BAR packet for tx capture feature
  5325. *
  5326. * @soc: soc handle
  5327. * @pdev: pdev handle
  5328. * @nbuf: received packet
  5329. *
  5330. * Return: QDF_STATUS_SUCCESS on success
  5331. * others on error
  5332. */
  5333. QDF_STATUS
  5334. dp_bar_send_ack_frm_to_stack(struct dp_soc *soc,
  5335. struct dp_pdev *pdev,
  5336. qdf_nbuf_t nbuf)
  5337. {
  5338. struct ieee80211_ctlframe_addr2 *wh;
  5339. uint8_t *frm;
  5340. struct hal_rx_ppdu_info *ppdu_info;
  5341. struct mon_rx_status *rx_status;
  5342. struct mon_rx_user_status *rx_user_status;
  5343. struct mon_rx_user_info *rx_user_info;
  5344. uint16_t bar_ctl;
  5345. uint32_t user_id;
  5346. uint8_t tid;
  5347. qdf_frag_t addr;
  5348. if (!nbuf)
  5349. return QDF_STATUS_E_INVAL;
  5350. /* Get addr pointing to 80211 header */
  5351. addr = dp_rx_mon_get_nbuf_80211_hdr(nbuf);
  5352. if (qdf_unlikely(!addr)) {
  5353. dp_tx_capture_err("%pK: Unable to get 80211 header address", soc);
  5354. return QDF_STATUS_E_INVAL;
  5355. }
  5356. wh = (struct ieee80211_ctlframe_addr2 *)addr;
  5357. if (wh->i_fc[0] != (IEEE80211_FC0_VERSION_0 |
  5358. IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_BAR)) {
  5359. return QDF_STATUS_SUCCESS;
  5360. }
  5361. frm = (uint8_t *)&wh[1];
  5362. bar_ctl = qdf_le16_to_cpu(*(uint16_t *)frm);
  5363. if (bar_ctl & DP_IEEE80211_BAR_CTL_POLICY_M)
  5364. return QDF_STATUS_SUCCESS;
  5365. tid = (bar_ctl >> DP_IEEE80211_BAR_CTL_TID_S) &
  5366. DP_IEEE80211_BAR_CTL_TID_M;
  5367. ppdu_info = &pdev->ppdu_info;
  5368. user_id = ppdu_info->rx_info.user_id;
  5369. rx_status = &ppdu_info->rx_status;
  5370. rx_user_status = &ppdu_info->rx_user_status[user_id];
  5371. rx_user_info = &ppdu_info->rx_user_info[user_id];
  5372. rx_user_status->tid = tid;
  5373. dp_send_usr_ack_frm_to_stack(soc, pdev, ppdu_info, rx_status,
  5374. rx_user_status, rx_user_info);
  5375. return QDF_STATUS_SUCCESS;
  5376. }
  5377. /**
  5378. * dp_gen_noack_frame: generate noack Action frame by using parameters
  5379. * from received NDPA frame
  5380. * @ppdu_info: pointer to ppdu_info
  5381. * @peer: pointer to peer structure
  5382. * @mpdu_nbuf: buffer for the generated noack frame
  5383. * @mon_mpdu: mpdu from monitor destination path
  5384. *
  5385. * Return: QDF_STATUS
  5386. */
  5387. static void dp_gen_noack_frame(struct hal_rx_ppdu_info *ppdu_info,
  5388. struct dp_peer *peer, qdf_nbuf_t mpdu_nbuf,
  5389. qdf_nbuf_t mon_mpdu)
  5390. {
  5391. struct ieee80211_frame *wh;
  5392. uint16_t duration;
  5393. struct dp_vdev *vdev = NULL;
  5394. uint8_t token = 0;
  5395. uint8_t *frm;
  5396. char *ndpa_buf = NULL;
  5397. /* Get addr pointing to 80211 header */
  5398. ndpa_buf = dp_rx_mon_get_nbuf_80211_hdr(mon_mpdu);
  5399. if (qdf_unlikely(!ndpa_buf)) {
  5400. dp_tx_capture_err("Unable to get 80211 header address");
  5401. return;
  5402. }
  5403. wh = (struct ieee80211_frame *)qdf_nbuf_data(mpdu_nbuf);
  5404. qdf_mem_zero(((char *)wh), DP_ACKNOACK_FRAME_SIZE);
  5405. wh->i_fc[0] = IEEE80211_FC0_VERSION_0 |
  5406. IEEE80211_FC0_TYPE_MGT |
  5407. IEEE80211_FCO_SUBTYPE_ACTION_NO_ACK;
  5408. qdf_mem_copy(wh->i_addr1, &peer->mac_addr.raw[0], QDF_MAC_ADDR_SIZE);
  5409. vdev = peer->vdev;
  5410. if (vdev) {
  5411. qdf_mem_copy(wh->i_addr2,
  5412. vdev->mac_addr.raw,
  5413. QDF_MAC_ADDR_SIZE);
  5414. qdf_mem_copy(wh->i_addr3,
  5415. vdev->mac_addr.raw,
  5416. QDF_MAC_ADDR_SIZE);
  5417. }
  5418. duration = (ppdu_info->rx_status.duration > SIFS_INTERVAL) ?
  5419. ppdu_info->rx_status.duration - SIFS_INTERVAL : 0;
  5420. wh->i_dur[0] = duration & 0xff;
  5421. wh->i_dur[1] = (duration >> 8) & 0xff;
  5422. frm = (uint8_t *)&wh[1];
  5423. /*
  5424. * Update category field
  5425. */
  5426. *frm = DP_IEEE80211_CATEGORY_VHT;
  5427. /*
  5428. * Update sounding token obtained from NDPA,
  5429. * shift to get upper six bits
  5430. */
  5431. frm += DP_NOACK_SOUNDING_TOKEN_POS;
  5432. token = ndpa_buf[DP_NDPA_TOKEN_POS] >> DP_NOACK_STOKEN_POS_SHIFT;
  5433. *frm = (token) << DP_NOACK_STOKEN_POS_SHIFT;
  5434. qdf_nbuf_set_pktlen(mpdu_nbuf, DP_ACKNOACK_FRAME_SIZE);
  5435. }
  5436. /**
  5437. * dp_send_noack_frame_to_stack: Sends noack Action frame to upper stack
  5438. * in response to received NDPA frame.
  5439. * @soc: SoC handle
  5440. * @pdev: PDEV pointer
  5441. * @mon_mpdu: mpdu from monitor destination path
  5442. *
  5443. * Return: QDF_STATUS
  5444. */
  5445. QDF_STATUS dp_send_noack_frame_to_stack(struct dp_soc *soc,
  5446. struct dp_pdev *pdev,
  5447. qdf_nbuf_t mon_mpdu)
  5448. {
  5449. struct hal_rx_ppdu_info *ppdu_info = &pdev->ppdu_info;
  5450. struct mon_rx_user_status *rx_user_status =
  5451. &ppdu_info->rx_user_status[0];
  5452. struct dp_ast_entry *ast_entry;
  5453. uint32_t peer_id;
  5454. struct dp_peer *peer;
  5455. struct cdp_tx_indication_info tx_capture_info;
  5456. if (rx_user_status->ast_index >=
  5457. wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  5458. return QDF_STATUS_E_FAILURE;
  5459. }
  5460. qdf_spin_lock_bh(&soc->ast_lock);
  5461. ast_entry = soc->ast_table[rx_user_status->ast_index];
  5462. if (!ast_entry) {
  5463. qdf_spin_unlock_bh(&soc->ast_lock);
  5464. return QDF_STATUS_E_FAILURE;
  5465. }
  5466. peer_id = ast_entry->peer_id;
  5467. qdf_spin_unlock_bh(&soc->ast_lock);
  5468. peer = DP_TX_PEER_GET_REF(pdev, peer_id);
  5469. if (!peer) {
  5470. return QDF_STATUS_E_FAILURE;
  5471. }
  5472. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, peer, peer->mac_addr.raw)) {
  5473. DP_TX_PEER_DEL_REF(peer);
  5474. return QDF_STATUS_E_FAILURE;
  5475. }
  5476. set_mpdu_info(&tx_capture_info,
  5477. &ppdu_info->rx_status, rx_user_status);
  5478. tx_capture_info.mpdu_info.mcs = rx_user_status->mcs;
  5479. /*
  5480. *ppdu_desc is not required for legacy frames
  5481. */
  5482. tx_capture_info.ppdu_desc = NULL;
  5483. tx_capture_info.mpdu_nbuf =
  5484. qdf_nbuf_alloc(pdev->soc->osdev,
  5485. MAX_MONITOR_HEADER +
  5486. DP_ACKNOACK_FRAME_SIZE,
  5487. MAX_MONITOR_HEADER,
  5488. 4, FALSE);
  5489. if (!tx_capture_info.mpdu_nbuf) {
  5490. DP_TX_PEER_DEL_REF(peer);
  5491. return QDF_STATUS_E_NOMEM;
  5492. }
  5493. dp_gen_noack_frame(ppdu_info, peer,
  5494. tx_capture_info.mpdu_nbuf, mon_mpdu);
  5495. DP_TX_PEER_DEL_REF(peer);
  5496. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  5497. &tx_capture_info, HTT_INVALID_PEER,
  5498. WDI_NO_VAL, pdev->pdev_id);
  5499. if (tx_capture_info.mpdu_nbuf)
  5500. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  5501. return QDF_STATUS_SUCCESS;
  5502. }
  5503. /**
  5504. * dp_handle_tx_capture_from_dest: Handle any TX capture frames from
  5505. * monitor destination path.
  5506. * @soc: SoC handle
  5507. * @pdev: PDEV pointer
  5508. * @mon_mpdu: mpdu from monitor destination path
  5509. *
  5510. * Return: QDF_STATUS
  5511. */
  5512. QDF_STATUS dp_handle_tx_capture_from_dest(struct dp_soc *soc,
  5513. struct dp_pdev *pdev,
  5514. qdf_nbuf_t mon_mpdu)
  5515. {
  5516. struct hal_rx_ppdu_info *ppdu_info = &pdev->ppdu_info;
  5517. /*
  5518. * The below switch case can be extended to
  5519. * add more frame types as needed
  5520. */
  5521. switch (ppdu_info->sw_frame_group_id) {
  5522. case HAL_MPDU_SW_FRAME_GROUP_CTRL_NDPA:
  5523. return dp_send_noack_frame_to_stack(soc, pdev, mon_mpdu);
  5524. case HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR:
  5525. return dp_bar_send_ack_frm_to_stack(soc, pdev, mon_mpdu);
  5526. default:
  5527. break;
  5528. }
  5529. return QDF_STATUS_SUCCESS;
  5530. }
  5531. /**
  5532. * dp_peer_set_tx_capture_enabled: Set tx_cap_enabled bit in peer
  5533. * @pdev: DP PDEV handle
  5534. * @peer: Peer handle
  5535. * @value: Enable/disable setting for tx_cap_enabled
  5536. * @peer_mac: peer mac address
  5537. *
  5538. * Return: QDF_STATUS
  5539. */
  5540. QDF_STATUS
  5541. dp_peer_set_tx_capture_enabled(struct dp_pdev *pdev,
  5542. struct dp_peer *peer, uint8_t value,
  5543. uint8_t *peer_mac)
  5544. {
  5545. uint32_t peer_id = HTT_INVALID_PEER;
  5546. QDF_STATUS status = QDF_STATUS_E_FAILURE;
  5547. if (value) {
  5548. if (dp_peer_tx_cap_add_filter(pdev, peer_id, peer_mac)) {
  5549. if (peer)
  5550. peer->tx_cap_enabled = value;
  5551. status = QDF_STATUS_SUCCESS;
  5552. }
  5553. } else {
  5554. if (dp_peer_tx_cap_del_filter(pdev, peer_id, peer_mac)) {
  5555. if (peer)
  5556. peer->tx_cap_enabled = value;
  5557. status = QDF_STATUS_SUCCESS;
  5558. }
  5559. }
  5560. return status;
  5561. }
  5562. /*
  5563. * dp_peer_tx_capture_filter_check: check filter is enable for the filter
  5564. * and update tx_cap_enabled flag
  5565. * @pdev: DP PDEV handle
  5566. * @peer: DP PEER handle
  5567. *
  5568. * return: void
  5569. */
  5570. void dp_peer_tx_capture_filter_check(struct dp_pdev *pdev,
  5571. struct dp_peer *peer)
  5572. {
  5573. if (!peer)
  5574. return;
  5575. if (dp_peer_tx_cap_search(pdev, peer->peer_id,
  5576. peer->mac_addr.raw)) {
  5577. peer->tx_cap_enabled = 1;
  5578. }
  5579. return;
  5580. }
  5581. /*
  5582. * dbg_copy_ppdu_desc: copy ppdu_desc to tx capture debugfs
  5583. * @nbuf_ppdu: nbuf ppdu
  5584. *
  5585. * return: void
  5586. */
  5587. void *dbg_copy_ppdu_desc(qdf_nbuf_t nbuf_ppdu)
  5588. {
  5589. struct dbg_tx_comp_ppdu *ptr_dbg_ppdu = NULL;
  5590. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  5591. uint8_t i = 0;
  5592. uint8_t num_users = 0;
  5593. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  5594. qdf_nbuf_data(nbuf_ppdu);
  5595. ptr_dbg_ppdu = qdf_mem_malloc(sizeof(struct dbg_tx_comp_ppdu) +
  5596. (ppdu_desc->num_users *
  5597. sizeof(struct dbg_tx_comp_ppdu_user)));
  5598. if (!ptr_dbg_ppdu)
  5599. return NULL;
  5600. num_users = ppdu_desc->num_users;
  5601. ptr_dbg_ppdu->ppdu_id = ppdu_desc->ppdu_id;
  5602. ptr_dbg_ppdu->bar_ppdu_id = ppdu_desc->bar_ppdu_id;
  5603. ptr_dbg_ppdu->vdev_id = ppdu_desc->vdev_id;
  5604. ptr_dbg_ppdu->bar_num_users = ppdu_desc->bar_num_users;
  5605. ptr_dbg_ppdu->num_users = ppdu_desc->num_users;
  5606. ptr_dbg_ppdu->sched_cmdid = ppdu_desc->sched_cmdid;
  5607. ptr_dbg_ppdu->tlv_bitmap = ppdu_desc->tlv_bitmap;
  5608. ptr_dbg_ppdu->htt_frame_type = ppdu_desc->htt_frame_type;
  5609. ptr_dbg_ppdu->frame_ctrl = ppdu_desc->frame_ctrl;
  5610. ptr_dbg_ppdu->ppdu_start_timestamp = ppdu_desc->ppdu_start_timestamp;
  5611. ptr_dbg_ppdu->ppdu_end_timestamp = ppdu_desc->ppdu_end_timestamp;
  5612. ptr_dbg_ppdu->bar_ppdu_start_timestamp =
  5613. ppdu_desc->bar_ppdu_start_timestamp;
  5614. ptr_dbg_ppdu->bar_ppdu_end_timestamp =
  5615. ppdu_desc->bar_ppdu_end_timestamp;
  5616. for (i = 0; i < ppdu_desc->num_users; i++) {
  5617. ptr_dbg_ppdu->user[i].completion_status =
  5618. ppdu_desc->user[i].completion_status;
  5619. ptr_dbg_ppdu->user[i].tid = ppdu_desc->user[i].tid;
  5620. ptr_dbg_ppdu->user[i].peer_id = ppdu_desc->user[i].peer_id;
  5621. qdf_mem_copy(ptr_dbg_ppdu->user[i].mac_addr,
  5622. ppdu_desc->user[i].mac_addr, 6);
  5623. ptr_dbg_ppdu->user[i].frame_ctrl =
  5624. ppdu_desc->user[i].frame_ctrl;
  5625. ptr_dbg_ppdu->user[i].qos_ctrl = ppdu_desc->user[i].qos_ctrl;
  5626. ptr_dbg_ppdu->user[i].mpdu_tried =
  5627. ppdu_desc->user[i].mpdu_tried_ucast +
  5628. ppdu_desc->user[i].mpdu_tried_mcast;
  5629. ptr_dbg_ppdu->user[i].mpdu_success =
  5630. ppdu_desc->user[i].mpdu_success;
  5631. ptr_dbg_ppdu->user[i].ltf_size = ppdu_desc->user[i].ltf_size;
  5632. ptr_dbg_ppdu->user[i].stbc = ppdu_desc->user[i].stbc;
  5633. ptr_dbg_ppdu->user[i].he_re = ppdu_desc->user[i].he_re;
  5634. ptr_dbg_ppdu->user[i].txbf = ppdu_desc->user[i].txbf;
  5635. ptr_dbg_ppdu->user[i].bw = ppdu_desc->user[i].bw;
  5636. ptr_dbg_ppdu->user[i].nss = ppdu_desc->user[i].nss;
  5637. ptr_dbg_ppdu->user[i].mcs = ppdu_desc->user[i].mcs;
  5638. ptr_dbg_ppdu->user[i].preamble = ppdu_desc->user[i].preamble;
  5639. ptr_dbg_ppdu->user[i].gi = ppdu_desc->user[i].gi;
  5640. ptr_dbg_ppdu->user[i].dcm = ppdu_desc->user[i].dcm;
  5641. ptr_dbg_ppdu->user[i].ldpc = ppdu_desc->user[i].ldpc;
  5642. ptr_dbg_ppdu->user[i].delayed_ba =
  5643. ppdu_desc->user[i].delayed_ba;
  5644. ptr_dbg_ppdu->user[i].ack_ba_tlv =
  5645. ppdu_desc->user[i].ack_ba_tlv;
  5646. ptr_dbg_ppdu->user[i].ba_seq_no = ppdu_desc->user[i].ba_seq_no;
  5647. ptr_dbg_ppdu->user[i].start_seq = ppdu_desc->user[i].start_seq;
  5648. qdf_mem_copy(ptr_dbg_ppdu->user[i].ba_bitmap,
  5649. ppdu_desc->user[i].ba_bitmap,
  5650. CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  5651. qdf_mem_copy(ptr_dbg_ppdu->user[i].enq_bitmap,
  5652. ppdu_desc->user[i].enq_bitmap,
  5653. CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  5654. ptr_dbg_ppdu->user[i].num_mpdu = ppdu_desc->user[i].num_mpdu;
  5655. ptr_dbg_ppdu->user[i].num_msdu = ppdu_desc->user[i].num_msdu;
  5656. ptr_dbg_ppdu->user[i].is_mcast = ppdu_desc->user[i].is_mcast;
  5657. ptr_dbg_ppdu->user[i].tlv_bitmap =
  5658. ppdu_desc->user[i].tlv_bitmap;
  5659. }
  5660. return ptr_dbg_ppdu;
  5661. }
  5662. /**
  5663. * debug_ppdu_log_enable_show() - debugfs function to display ppdu_desc
  5664. * @file: qdf debugfs handler
  5665. * @arg: priv data used to get htt_logger_handler
  5666. *
  5667. * Return: QDF_STATUS
  5668. */
  5669. static QDF_STATUS debug_ppdu_desc_log_show(qdf_debugfs_file_t file, void *arg)
  5670. {
  5671. struct dp_pdev *pdev;
  5672. struct dp_pdev_tx_capture *ptr_tx_cap;
  5673. struct tx_cap_debug_log_info *ptr_log_info;
  5674. struct dbg_tx_comp_ppdu *ptr_dbg_ppdu;
  5675. uint8_t k = 0;
  5676. uint8_t i = 0;
  5677. pdev = (struct dp_pdev *)arg;
  5678. ptr_tx_cap = &pdev->tx_capture;
  5679. ptr_log_info = &ptr_tx_cap->log_info;
  5680. if ((ptr_log_info->stop_seq & (0x1 << PPDU_LOG_DISPLAY_LIST)) &&
  5681. !ptr_log_info->ppdu_desc_log) {
  5682. ptr_log_info->stop_seq &= ~(0x1 << PPDU_LOG_DISPLAY_LIST);
  5683. return QDF_STATUS_SUCCESS;
  5684. }
  5685. if (!ptr_log_info->ppdu_desc_log) {
  5686. ptr_log_info->pause_dbg_log = 0;
  5687. ptr_log_info->stop_seq |= (0x1 << PPDU_LOG_DISPLAY_LIST);
  5688. return QDF_STATUS_SUCCESS;
  5689. }
  5690. ptr_log_info->pause_dbg_log = 1;
  5691. ptr_dbg_ppdu = ppdu_desc_dbg_dequeue(ptr_log_info);
  5692. if (!ptr_dbg_ppdu) {
  5693. ptr_log_info->pause_dbg_log = 0;
  5694. ptr_log_info->stop_seq |= (0x1 << PPDU_LOG_DISPLAY_LIST);
  5695. return QDF_STATUS_SUCCESS;
  5696. }
  5697. qdf_debugfs_printf(file,
  5698. "===============================================\n");
  5699. qdf_debugfs_printf(file,
  5700. "P_ID:%d B_P_ID:%d VDEV:%d N_USR[%d %d] SCH_ID:%d\n",
  5701. ptr_dbg_ppdu->ppdu_id,
  5702. ptr_dbg_ppdu->bar_ppdu_id,
  5703. ptr_dbg_ppdu->vdev_id,
  5704. ptr_dbg_ppdu->num_users,
  5705. ptr_dbg_ppdu->bar_num_users,
  5706. ptr_dbg_ppdu->sched_cmdid);
  5707. qdf_debugfs_printf(file,
  5708. "TLV:0x%x H_FRM:%d FCTRL:0x%x\n",
  5709. ptr_dbg_ppdu->tlv_bitmap,
  5710. ptr_dbg_ppdu->htt_frame_type,
  5711. ptr_dbg_ppdu->frame_ctrl);
  5712. qdf_debugfs_printf(file,
  5713. "TSF[%llu - %llu] B_TSF[%llu - %llu]\n",
  5714. ptr_dbg_ppdu->ppdu_start_timestamp,
  5715. ptr_dbg_ppdu->ppdu_end_timestamp,
  5716. ptr_dbg_ppdu->bar_ppdu_start_timestamp,
  5717. ptr_dbg_ppdu->bar_ppdu_end_timestamp);
  5718. for (k = 0; k < ptr_dbg_ppdu->num_users; k++) {
  5719. struct dbg_tx_comp_ppdu_user *user;
  5720. user = &ptr_dbg_ppdu->user[k];
  5721. qdf_debugfs_printf(file, "USER: %d\n", k);
  5722. qdf_debugfs_printf(file,
  5723. "\tPEER:%d TID:%d CS:%d TLV:0x%x\n",
  5724. user->peer_id,
  5725. user->tid,
  5726. user->completion_status,
  5727. user->tlv_bitmap);
  5728. qdf_debugfs_printf(file,
  5729. "\tFCTRL:0x%x QOS:0x%x\n",
  5730. user->frame_ctrl,
  5731. user->qos_ctrl);
  5732. qdf_debugfs_printf(file,
  5733. "\tMPDU[T:%d S:%d] N_MPDU:%d N_MSDU:%d\n",
  5734. user->mpdu_tried,
  5735. user->mpdu_success,
  5736. user->num_mpdu,
  5737. user->num_msdu);
  5738. qdf_debugfs_printf(file,
  5739. "\tMCS:%d NSS:%d PRE:%d BW:%d D_BA:%d\n",
  5740. user->mcs,
  5741. user->nss,
  5742. user->preamble,
  5743. user->bw,
  5744. user->delayed_ba);
  5745. qdf_debugfs_printf(file,
  5746. "\tS_SEQ:%d ENQ_BITMAP[", user->start_seq);
  5747. for (i = 0; i < CDP_BA_256_BIT_MAP_SIZE_DWORDS; i++)
  5748. qdf_debugfs_printf(file, " 0x%x",
  5749. user->enq_bitmap[i]);
  5750. qdf_debugfs_printf(file, "]\n");
  5751. qdf_debugfs_printf(file,
  5752. "\tBA_SEQ:%d BA_BITMAP[",
  5753. user->ba_seq_no);
  5754. for (i = 0; i < CDP_BA_256_BIT_MAP_SIZE_DWORDS; i++)
  5755. qdf_debugfs_printf(file, " 0x%x",
  5756. user->ba_bitmap[i]);
  5757. qdf_debugfs_printf(file, "]\n");
  5758. }
  5759. qdf_debugfs_printf(file,
  5760. "===============================================\n");
  5761. /* free the dequeued dbg ppdu_desc */
  5762. qdf_mem_free(ptr_dbg_ppdu);
  5763. return QDF_STATUS_E_AGAIN;
  5764. }
  5765. /**
  5766. * debug_ppdu_desc_log_write() - write is not allowed in ppdu_desc_log.
  5767. * @priv: file handler to access tx capture log info
  5768. * @buf: received data buffer
  5769. * @len: length of received buffer
  5770. *
  5771. * Return: QDF_STATUS
  5772. */
  5773. static QDF_STATUS debug_ppdu_desc_log_write(void *priv,
  5774. const char *buf,
  5775. qdf_size_t len)
  5776. {
  5777. return -EINVAL;
  5778. }
  5779. /**
  5780. * debug_ppdu_log_enable_show() - debugfs function to show the
  5781. * enable/disable flag.
  5782. * @file: qdf debugfs handler
  5783. * @arg: priv data used to get htt_logger_handler
  5784. *
  5785. * Return: QDF_STATUS
  5786. */
  5787. static QDF_STATUS debug_ppdu_log_enable_show(qdf_debugfs_file_t file, void *arg)
  5788. {
  5789. struct dp_pdev *pdev;
  5790. struct dp_pdev_tx_capture *ptr_tx_cap;
  5791. struct tx_cap_debug_log_info *ptr_log_info;
  5792. pdev = (struct dp_pdev *)arg;
  5793. ptr_tx_cap = &pdev->tx_capture;
  5794. ptr_log_info = &ptr_tx_cap->log_info;
  5795. if ((ptr_log_info->stop_seq & (0x1 << PPDU_LOG_ENABLE_LIST))) {
  5796. ptr_log_info->stop_seq &= ~(0x1 << PPDU_LOG_ENABLE_LIST);
  5797. return QDF_STATUS_SUCCESS;
  5798. }
  5799. qdf_debugfs_printf(file, "%u\n", ptr_log_info->ppdu_desc_log);
  5800. ptr_log_info->stop_seq |= (0x1 << PPDU_LOG_ENABLE_LIST);
  5801. return QDF_STATUS_SUCCESS;
  5802. }
  5803. /**
  5804. * debug_ppdu_log_enable_write() - debugfs function to enable/disable
  5805. * the debugfs flag.
  5806. * @priv: file handler to access tx capture log info
  5807. * @buf: received data buffer
  5808. * @len: length of received buffer
  5809. *
  5810. * Return: QDF_STATUS
  5811. */
  5812. static QDF_STATUS debug_ppdu_log_enable_write(void *priv,
  5813. const char *buf,
  5814. qdf_size_t len)
  5815. {
  5816. struct dp_pdev *pdev;
  5817. struct dp_pdev_tx_capture *ptr_tx_cap;
  5818. struct tx_cap_debug_log_info *ptr_log_info;
  5819. int k, ret;
  5820. pdev = (struct dp_pdev *)priv;
  5821. ptr_tx_cap = &pdev->tx_capture;
  5822. ptr_log_info = &ptr_tx_cap->log_info;
  5823. ret = kstrtoint(buf, 0, &k);
  5824. if ((ret != 0) || ((k != 0) && (k != 1)))
  5825. return QDF_STATUS_E_PERM;
  5826. if (k == 1) {
  5827. /* if ppdu_desc log already 1 return success */
  5828. if (ptr_log_info->ppdu_desc_log)
  5829. return QDF_STATUS_SUCCESS;
  5830. /* initialize ppdu_desc_log to 1 */
  5831. ptr_log_info->ppdu_desc_log = 1;
  5832. } else {
  5833. /* if ppdu_desc log already 0 return success */
  5834. if (!ptr_log_info->ppdu_desc_log)
  5835. return QDF_STATUS_SUCCESS;
  5836. /* initialize ppdu_desc_log to 0 */
  5837. ptr_log_info->ppdu_desc_log = 0;
  5838. }
  5839. return QDF_STATUS_SUCCESS;
  5840. }
  5841. /*
  5842. * tx_cap_debugfs_log_ppdu_desc: tx capture logging ppdu desc
  5843. * @pdev: DP PDEV handle
  5844. * @nbuf_ppdu: nbuf ppdu
  5845. *
  5846. * return: void
  5847. */
  5848. void tx_cap_debugfs_log_ppdu_desc(struct dp_pdev *pdev, qdf_nbuf_t nbuf_ppdu)
  5849. {
  5850. struct dp_pdev_tx_capture *ptr_tx_cap;
  5851. struct tx_cap_debug_log_info *ptr_log_info;
  5852. struct dbg_tx_comp_ppdu *ptr_dbg_ppdu;
  5853. struct dbg_tx_comp_ppdu *ptr_tmp_ppdu;
  5854. uint32_t list_size;
  5855. ptr_tx_cap = &pdev->tx_capture;
  5856. ptr_log_info = &ptr_tx_cap->log_info;
  5857. if (!ptr_log_info->ppdu_desc_log || ptr_log_info->pause_dbg_log)
  5858. return;
  5859. ptr_dbg_ppdu = dbg_copy_ppdu_desc(nbuf_ppdu);
  5860. if (!ptr_dbg_ppdu)
  5861. return;
  5862. list_size = ppdu_desc_dbg_enqueue(ptr_log_info, ptr_dbg_ppdu);
  5863. dp_tx_capture_info("%pK: enqueue list_size:%d\n", pdev->soc, list_size);
  5864. if (list_size >= ptr_log_info->ppdu_queue_size) {
  5865. ptr_tmp_ppdu = ppdu_desc_dbg_dequeue(ptr_log_info);
  5866. qdf_mem_free(ptr_tmp_ppdu);
  5867. }
  5868. }
  5869. #define DEBUGFS_FOPS(func_base) \
  5870. { \
  5871. .name = #func_base, \
  5872. .ops = { \
  5873. .show = debug_##func_base##_show, \
  5874. .write = debug_##func_base##_write, \
  5875. .priv = NULL, \
  5876. } \
  5877. }
  5878. struct tx_cap_debugfs_info tx_cap_debugfs_infos[NUM_TX_CAP_DEBUG_INFOS] = {
  5879. DEBUGFS_FOPS(ppdu_log_enable),
  5880. DEBUGFS_FOPS(ppdu_desc_log),
  5881. };
  5882. /*
  5883. * tx_cap_debugfs_remove: remove dentry and file created.
  5884. * @ptr_log_info: tx capture debugfs log structure
  5885. *
  5886. * return: void
  5887. */
  5888. static void tx_cap_debugfs_remove(struct tx_cap_debug_log_info *ptr_log_info)
  5889. {
  5890. qdf_dentry_t dentry;
  5891. uint8_t i = 0;
  5892. for (i = 0; i < NUM_TX_CAP_DEBUG_INFOS; ++i) {
  5893. dentry = ptr_log_info->debugfs_de[i];
  5894. if (dentry) {
  5895. qdf_debugfs_remove_file(dentry);
  5896. ptr_log_info->debugfs_de[i] = NULL;
  5897. }
  5898. }
  5899. dentry = ptr_log_info->tx_cap_debugfs_dir;
  5900. if (dentry) {
  5901. qdf_debugfs_remove_dir(dentry);
  5902. ptr_log_info->tx_cap_debugfs_dir = NULL;
  5903. }
  5904. }
  5905. /*
  5906. * dp_tx_capture_debugfs_init: tx capture debugfs init
  5907. * @pdev: DP PDEV handle
  5908. *
  5909. * return: QDF_STATUS
  5910. */
  5911. QDF_STATUS dp_tx_capture_debugfs_init(struct dp_pdev *pdev)
  5912. {
  5913. qdf_dentry_t dentry;
  5914. struct dp_soc *soc;
  5915. struct dp_pdev_tx_capture *ptr_tx_cap;
  5916. struct tx_cap_debug_log_info *ptr_log_info;
  5917. struct tx_cap_debugfs_info *ptr_debugfs_info;
  5918. uint8_t i = 0;
  5919. char buf[32];
  5920. char *name = NULL;
  5921. soc = pdev->soc;
  5922. ptr_tx_cap = &pdev->tx_capture;
  5923. ptr_log_info = &ptr_tx_cap->log_info;
  5924. if (soc->cdp_soc.ol_ops->get_device_name) {
  5925. name = soc->cdp_soc.ol_ops->get_device_name(
  5926. pdev->soc->ctrl_psoc, pdev->pdev_id);
  5927. }
  5928. if (name == NULL)
  5929. return QDF_STATUS_E_FAILURE;
  5930. /* directory creation with name */
  5931. snprintf(buf, sizeof(buf), "tx_cap_log_%s", name);
  5932. dentry = qdf_debugfs_create_dir(buf, NULL);
  5933. if (!dentry) {
  5934. dp_tx_capture_err("%pK: error while creating debugfs dir for %s", pdev->soc, buf);
  5935. goto out;
  5936. }
  5937. ptr_log_info->tx_cap_debugfs_dir = dentry;
  5938. qdf_mem_copy(ptr_log_info->tx_cap_debugfs_infos,
  5939. tx_cap_debugfs_infos,
  5940. (sizeof(struct tx_cap_debugfs_info) *
  5941. NUM_TX_CAP_DEBUG_INFOS));
  5942. for (i = 0; i < NUM_TX_CAP_DEBUG_INFOS; i++) {
  5943. ptr_debugfs_info = &ptr_log_info->tx_cap_debugfs_infos[i];
  5944. /* store pdev tx capture pointer to private data pointer */
  5945. ptr_debugfs_info->ops.priv = pdev;
  5946. ptr_log_info->debugfs_de[i] = qdf_debugfs_create_file(
  5947. ptr_debugfs_info->name,
  5948. TX_CAP_DBG_FILE_PERM,
  5949. ptr_log_info->tx_cap_debugfs_dir,
  5950. &ptr_debugfs_info->ops);
  5951. if (!ptr_log_info->debugfs_de[i]) {
  5952. dp_tx_capture_err("%pK: debug Entry creation failed[%s]!",
  5953. pdev->soc, ptr_debugfs_info->name);
  5954. goto out;
  5955. }
  5956. }
  5957. return QDF_STATUS_SUCCESS;
  5958. out:
  5959. tx_cap_debugfs_remove(ptr_log_info);
  5960. return QDF_STATUS_E_FAILURE;
  5961. }
  5962. /*
  5963. * dp_tx_capture_debugfs_deinit: tx capture debugfs deinit
  5964. * @pdev: DP PDEV handle
  5965. *
  5966. * return: void
  5967. */
  5968. void dp_tx_capture_debugfs_deinit(struct dp_pdev *pdev)
  5969. {
  5970. struct dp_pdev_tx_capture *ptr_tx_cap;
  5971. struct tx_cap_debug_log_info *ptr_log_info;
  5972. ptr_tx_cap = &pdev->tx_capture;
  5973. ptr_log_info = &ptr_tx_cap->log_info;
  5974. tx_cap_debugfs_remove(ptr_log_info);
  5975. }
  5976. #endif