dp_tx.c 162 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125
  1. /*
  2. * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include "htt.h"
  20. #include "dp_htt.h"
  21. #include "hal_hw_headers.h"
  22. #include "dp_tx.h"
  23. #include "dp_tx_desc.h"
  24. #include "dp_peer.h"
  25. #include "dp_types.h"
  26. #include "hal_tx.h"
  27. #include "qdf_mem.h"
  28. #include "qdf_nbuf.h"
  29. #include "qdf_net_types.h"
  30. #include "qdf_module.h"
  31. #include <wlan_cfg.h>
  32. #include "dp_ipa.h"
  33. #if defined(MESH_MODE_SUPPORT) || defined(FEATURE_PERPKT_INFO)
  34. #include "if_meta_hdr.h"
  35. #endif
  36. #include "enet.h"
  37. #include "dp_internal.h"
  38. #ifdef ATH_SUPPORT_IQUE
  39. #include "dp_txrx_me.h"
  40. #endif
  41. #include "dp_hist.h"
  42. #ifdef WLAN_DP_FEATURE_SW_LATENCY_MGR
  43. #include <wlan_dp_swlm.h>
  44. #endif
  45. #ifdef WIFI_MONITOR_SUPPORT
  46. #include <dp_mon.h>
  47. #endif
  48. #ifdef FEATURE_WDS
  49. #include "dp_txrx_wds.h"
  50. #endif
  51. #include "cdp_txrx_cmn_reg.h"
  52. #ifdef CONFIG_SAWF
  53. #include <dp_sawf.h>
  54. #endif
  55. /* Flag to skip CCE classify when mesh or tid override enabled */
  56. #define DP_TX_SKIP_CCE_CLASSIFY \
  57. (DP_TXRX_HLOS_TID_OVERRIDE_ENABLED | DP_TX_MESH_ENABLED)
  58. /* TODO Add support in TSO */
  59. #define DP_DESC_NUM_FRAG(x) 0
  60. /* disable TQM_BYPASS */
  61. #define TQM_BYPASS_WAR 0
  62. /* invalid peer id for reinject*/
  63. #define DP_INVALID_PEER 0XFFFE
  64. #define DP_RETRY_COUNT 7
  65. #ifdef QCA_DP_TX_FW_METADATA_V2
  66. #define DP_TX_TCL_METADATA_PDEV_ID_SET(_var, _val)\
  67. HTT_TX_TCL_METADATA_V2_PDEV_ID_SET(_var, _val)
  68. #define DP_TX_TCL_METADATA_VALID_HTT_SET(_var, _val) \
  69. HTT_TX_TCL_METADATA_V2_VALID_HTT_SET(_var, _val)
  70. #define DP_TX_TCL_METADATA_TYPE_SET(_var, _val) \
  71. HTT_TX_TCL_METADATA_TYPE_V2_SET(_var, _val)
  72. #define DP_TX_TCL_METADATA_HOST_INSPECTED_SET(_var, _val) \
  73. HTT_TX_TCL_METADATA_V2_HOST_INSPECTED_SET(_var, _val)
  74. #define DP_TX_TCL_METADATA_PEER_ID_SET(_var, _val) \
  75. HTT_TX_TCL_METADATA_V2_PEER_ID_SET(_var, _val)
  76. #define DP_TX_TCL_METADATA_VDEV_ID_SET(_var, _val) \
  77. HTT_TX_TCL_METADATA_V2_VDEV_ID_SET(_var, _val)
  78. #define DP_TCL_METADATA_TYPE_PEER_BASED \
  79. HTT_TCL_METADATA_V2_TYPE_PEER_BASED
  80. #define DP_TCL_METADATA_TYPE_VDEV_BASED \
  81. HTT_TCL_METADATA_V2_TYPE_VDEV_BASED
  82. #else
  83. #define DP_TX_TCL_METADATA_PDEV_ID_SET(_var, _val)\
  84. HTT_TX_TCL_METADATA_PDEV_ID_SET(_var, _val)
  85. #define DP_TX_TCL_METADATA_VALID_HTT_SET(_var, _val) \
  86. HTT_TX_TCL_METADATA_VALID_HTT_SET(_var, _val)
  87. #define DP_TX_TCL_METADATA_TYPE_SET(_var, _val) \
  88. HTT_TX_TCL_METADATA_TYPE_SET(_var, _val)
  89. #define DP_TX_TCL_METADATA_HOST_INSPECTED_SET(_var, _val) \
  90. HTT_TX_TCL_METADATA_HOST_INSPECTED_SET(_var, _val)
  91. #define DP_TX_TCL_METADATA_PEER_ID_SET(_var, _val) \
  92. HTT_TX_TCL_METADATA_PEER_ID_SET(_var, _val)
  93. #define DP_TX_TCL_METADATA_VDEV_ID_SET(_var, _val) \
  94. HTT_TX_TCL_METADATA_VDEV_ID_SET(_var, _val)
  95. #define DP_TCL_METADATA_TYPE_PEER_BASED \
  96. HTT_TCL_METADATA_TYPE_PEER_BASED
  97. #define DP_TCL_METADATA_TYPE_VDEV_BASED \
  98. HTT_TCL_METADATA_TYPE_VDEV_BASED
  99. #endif
  100. /*mapping between hal encrypt type and cdp_sec_type*/
  101. uint8_t sec_type_map[MAX_CDP_SEC_TYPE] = {HAL_TX_ENCRYPT_TYPE_NO_CIPHER,
  102. HAL_TX_ENCRYPT_TYPE_WEP_128,
  103. HAL_TX_ENCRYPT_TYPE_WEP_104,
  104. HAL_TX_ENCRYPT_TYPE_WEP_40,
  105. HAL_TX_ENCRYPT_TYPE_TKIP_WITH_MIC,
  106. HAL_TX_ENCRYPT_TYPE_TKIP_NO_MIC,
  107. HAL_TX_ENCRYPT_TYPE_AES_CCMP_128,
  108. HAL_TX_ENCRYPT_TYPE_WAPI,
  109. HAL_TX_ENCRYPT_TYPE_AES_CCMP_256,
  110. HAL_TX_ENCRYPT_TYPE_AES_GCMP_128,
  111. HAL_TX_ENCRYPT_TYPE_AES_GCMP_256,
  112. HAL_TX_ENCRYPT_TYPE_WAPI_GCM_SM4};
  113. qdf_export_symbol(sec_type_map);
  114. #ifdef WLAN_FEATURE_DP_TX_DESC_HISTORY
  115. static inline enum dp_tx_event_type dp_tx_get_event_type(uint32_t flags)
  116. {
  117. enum dp_tx_event_type type;
  118. if (flags & DP_TX_DESC_FLAG_FLUSH)
  119. type = DP_TX_DESC_FLUSH;
  120. else if (flags & DP_TX_DESC_FLAG_TX_COMP_ERR)
  121. type = DP_TX_COMP_UNMAP_ERR;
  122. else if (flags & DP_TX_DESC_FLAG_COMPLETED_TX)
  123. type = DP_TX_COMP_UNMAP;
  124. else
  125. type = DP_TX_DESC_UNMAP;
  126. return type;
  127. }
  128. static inline void
  129. dp_tx_desc_history_add(struct dp_soc *soc, dma_addr_t paddr,
  130. qdf_nbuf_t skb, uint32_t sw_cookie,
  131. enum dp_tx_event_type type)
  132. {
  133. struct dp_tx_tcl_history *tx_tcl_history = &soc->tx_tcl_history;
  134. struct dp_tx_comp_history *tx_comp_history = &soc->tx_comp_history;
  135. struct dp_tx_desc_event *entry;
  136. uint32_t idx;
  137. uint16_t slot;
  138. switch (type) {
  139. case DP_TX_COMP_UNMAP:
  140. case DP_TX_COMP_UNMAP_ERR:
  141. case DP_TX_COMP_MSDU_EXT:
  142. if (qdf_unlikely(!tx_comp_history->allocated))
  143. return;
  144. dp_get_frag_hist_next_atomic_idx(&tx_comp_history->index, &idx,
  145. &slot,
  146. DP_TX_COMP_HIST_SLOT_SHIFT,
  147. DP_TX_COMP_HIST_PER_SLOT_MAX,
  148. DP_TX_COMP_HISTORY_SIZE);
  149. entry = &tx_comp_history->entry[slot][idx];
  150. break;
  151. case DP_TX_DESC_MAP:
  152. case DP_TX_DESC_UNMAP:
  153. case DP_TX_DESC_COOKIE:
  154. case DP_TX_DESC_FLUSH:
  155. if (qdf_unlikely(!tx_tcl_history->allocated))
  156. return;
  157. dp_get_frag_hist_next_atomic_idx(&tx_tcl_history->index, &idx,
  158. &slot,
  159. DP_TX_TCL_HIST_SLOT_SHIFT,
  160. DP_TX_TCL_HIST_PER_SLOT_MAX,
  161. DP_TX_TCL_HISTORY_SIZE);
  162. entry = &tx_tcl_history->entry[slot][idx];
  163. break;
  164. default:
  165. dp_info_rl("Invalid dp_tx_event_type: %d", type);
  166. return;
  167. }
  168. entry->skb = skb;
  169. entry->paddr = paddr;
  170. entry->sw_cookie = sw_cookie;
  171. entry->type = type;
  172. entry->ts = qdf_get_log_timestamp();
  173. }
  174. static inline void
  175. dp_tx_tso_seg_history_add(struct dp_soc *soc,
  176. struct qdf_tso_seg_elem_t *tso_seg,
  177. qdf_nbuf_t skb, uint32_t sw_cookie,
  178. enum dp_tx_event_type type)
  179. {
  180. int i;
  181. for (i = 1; i < tso_seg->seg.num_frags; i++) {
  182. dp_tx_desc_history_add(soc, tso_seg->seg.tso_frags[i].paddr,
  183. skb, sw_cookie, type);
  184. }
  185. if (!tso_seg->next)
  186. dp_tx_desc_history_add(soc, tso_seg->seg.tso_frags[0].paddr,
  187. skb, 0xFFFFFFFF, type);
  188. }
  189. static inline void
  190. dp_tx_tso_history_add(struct dp_soc *soc, struct qdf_tso_info_t tso_info,
  191. qdf_nbuf_t skb, uint32_t sw_cookie,
  192. enum dp_tx_event_type type)
  193. {
  194. struct qdf_tso_seg_elem_t *curr_seg = tso_info.tso_seg_list;
  195. uint32_t num_segs = tso_info.num_segs;
  196. while (num_segs) {
  197. dp_tx_tso_seg_history_add(soc, curr_seg, skb, sw_cookie, type);
  198. curr_seg = curr_seg->next;
  199. num_segs--;
  200. }
  201. }
  202. #else
  203. static inline enum dp_tx_event_type dp_tx_get_event_type(uint32_t flags)
  204. {
  205. return DP_TX_DESC_INVAL_EVT;
  206. }
  207. static inline void
  208. dp_tx_desc_history_add(struct dp_soc *soc, dma_addr_t paddr,
  209. qdf_nbuf_t skb, uint32_t sw_cookie,
  210. enum dp_tx_event_type type)
  211. {
  212. }
  213. static inline void
  214. dp_tx_tso_seg_history_add(struct dp_soc *soc,
  215. struct qdf_tso_seg_elem_t *tso_seg,
  216. qdf_nbuf_t skb, uint32_t sw_cookie,
  217. enum dp_tx_event_type type)
  218. {
  219. }
  220. static inline void
  221. dp_tx_tso_history_add(struct dp_soc *soc, struct qdf_tso_info_t tso_info,
  222. qdf_nbuf_t skb, uint32_t sw_cookie,
  223. enum dp_tx_event_type type)
  224. {
  225. }
  226. #endif /* WLAN_FEATURE_DP_TX_DESC_HISTORY */
  227. static int dp_get_rtpm_tput_policy_requirement(struct dp_soc *soc);
  228. /**
  229. * dp_is_tput_high() - Check if throughput is high
  230. *
  231. * @soc - core txrx main context
  232. *
  233. * The current function is based of the RTPM tput policy variable where RTPM is
  234. * avoided based on throughput.
  235. */
  236. static inline int dp_is_tput_high(struct dp_soc *soc)
  237. {
  238. return dp_get_rtpm_tput_policy_requirement(soc);
  239. }
  240. #if defined(FEATURE_TSO)
  241. /**
  242. * dp_tx_tso_unmap_segment() - Unmap TSO segment
  243. *
  244. * @soc - core txrx main context
  245. * @seg_desc - tso segment descriptor
  246. * @num_seg_desc - tso number segment descriptor
  247. */
  248. static void dp_tx_tso_unmap_segment(
  249. struct dp_soc *soc,
  250. struct qdf_tso_seg_elem_t *seg_desc,
  251. struct qdf_tso_num_seg_elem_t *num_seg_desc)
  252. {
  253. TSO_DEBUG("%s: Unmap the tso segment", __func__);
  254. if (qdf_unlikely(!seg_desc)) {
  255. DP_TRACE(ERROR, "%s %d TSO desc is NULL!",
  256. __func__, __LINE__);
  257. qdf_assert(0);
  258. } else if (qdf_unlikely(!num_seg_desc)) {
  259. DP_TRACE(ERROR, "%s %d TSO num desc is NULL!",
  260. __func__, __LINE__);
  261. qdf_assert(0);
  262. } else {
  263. bool is_last_seg;
  264. /* no tso segment left to do dma unmap */
  265. if (num_seg_desc->num_seg.tso_cmn_num_seg < 1)
  266. return;
  267. is_last_seg = (num_seg_desc->num_seg.tso_cmn_num_seg == 1) ?
  268. true : false;
  269. qdf_nbuf_unmap_tso_segment(soc->osdev,
  270. seg_desc, is_last_seg);
  271. num_seg_desc->num_seg.tso_cmn_num_seg--;
  272. }
  273. }
  274. /**
  275. * dp_tx_tso_desc_release() - Release the tso segment and tso_cmn_num_seg
  276. * back to the freelist
  277. *
  278. * @soc - soc device handle
  279. * @tx_desc - Tx software descriptor
  280. */
  281. static void dp_tx_tso_desc_release(struct dp_soc *soc,
  282. struct dp_tx_desc_s *tx_desc)
  283. {
  284. TSO_DEBUG("%s: Free the tso descriptor", __func__);
  285. if (qdf_unlikely(!tx_desc->msdu_ext_desc->tso_desc)) {
  286. dp_tx_err("SO desc is NULL!");
  287. qdf_assert(0);
  288. } else if (qdf_unlikely(!tx_desc->msdu_ext_desc->tso_num_desc)) {
  289. dp_tx_err("TSO num desc is NULL!");
  290. qdf_assert(0);
  291. } else {
  292. struct qdf_tso_num_seg_elem_t *tso_num_desc =
  293. (struct qdf_tso_num_seg_elem_t *)tx_desc->
  294. msdu_ext_desc->tso_num_desc;
  295. /* Add the tso num segment into the free list */
  296. if (tso_num_desc->num_seg.tso_cmn_num_seg == 0) {
  297. dp_tso_num_seg_free(soc, tx_desc->pool_id,
  298. tx_desc->msdu_ext_desc->
  299. tso_num_desc);
  300. tx_desc->msdu_ext_desc->tso_num_desc = NULL;
  301. DP_STATS_INC(tx_desc->pdev, tso_stats.tso_comp, 1);
  302. }
  303. /* Add the tso segment into the free list*/
  304. dp_tx_tso_desc_free(soc,
  305. tx_desc->pool_id, tx_desc->msdu_ext_desc->
  306. tso_desc);
  307. tx_desc->msdu_ext_desc->tso_desc = NULL;
  308. }
  309. }
  310. #else
  311. static void dp_tx_tso_unmap_segment(
  312. struct dp_soc *soc,
  313. struct qdf_tso_seg_elem_t *seg_desc,
  314. struct qdf_tso_num_seg_elem_t *num_seg_desc)
  315. {
  316. }
  317. static void dp_tx_tso_desc_release(struct dp_soc *soc,
  318. struct dp_tx_desc_s *tx_desc)
  319. {
  320. }
  321. #endif
  322. /**
  323. * dp_tx_desc_release() - Release Tx Descriptor
  324. * @tx_desc : Tx Descriptor
  325. * @desc_pool_id: Descriptor Pool ID
  326. *
  327. * Deallocate all resources attached to Tx descriptor and free the Tx
  328. * descriptor.
  329. *
  330. * Return:
  331. */
  332. void
  333. dp_tx_desc_release(struct dp_tx_desc_s *tx_desc, uint8_t desc_pool_id)
  334. {
  335. struct dp_pdev *pdev = tx_desc->pdev;
  336. struct dp_soc *soc;
  337. uint8_t comp_status = 0;
  338. qdf_assert(pdev);
  339. soc = pdev->soc;
  340. dp_tx_outstanding_dec(pdev);
  341. if (tx_desc->msdu_ext_desc) {
  342. if (tx_desc->frm_type == dp_tx_frm_tso)
  343. dp_tx_tso_desc_release(soc, tx_desc);
  344. if (tx_desc->flags & DP_TX_DESC_FLAG_ME)
  345. dp_tx_me_free_buf(tx_desc->pdev,
  346. tx_desc->msdu_ext_desc->me_buffer);
  347. dp_tx_ext_desc_free(soc, tx_desc->msdu_ext_desc, desc_pool_id);
  348. }
  349. if (tx_desc->flags & DP_TX_DESC_FLAG_TO_FW)
  350. qdf_atomic_dec(&soc->num_tx_exception);
  351. if (HAL_TX_COMP_RELEASE_SOURCE_TQM ==
  352. tx_desc->buffer_src)
  353. comp_status = hal_tx_comp_get_release_reason(&tx_desc->comp,
  354. soc->hal_soc);
  355. else
  356. comp_status = HAL_TX_COMP_RELEASE_REASON_FW;
  357. dp_tx_debug("Tx Completion Release desc %d status %d outstanding %d",
  358. tx_desc->id, comp_status,
  359. qdf_atomic_read(&pdev->num_tx_outstanding));
  360. dp_tx_desc_free(soc, tx_desc, desc_pool_id);
  361. return;
  362. }
  363. /**
  364. * dp_tx_htt_metadata_prepare() - Prepare HTT metadata for special frames
  365. * @vdev: DP vdev Handle
  366. * @nbuf: skb
  367. * @msdu_info: msdu_info required to create HTT metadata
  368. *
  369. * Prepares and fills HTT metadata in the frame pre-header for special frames
  370. * that should be transmitted using varying transmit parameters.
  371. * There are 2 VDEV modes that currently needs this special metadata -
  372. * 1) Mesh Mode
  373. * 2) DSRC Mode
  374. *
  375. * Return: HTT metadata size
  376. *
  377. */
  378. static uint8_t dp_tx_prepare_htt_metadata(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  379. struct dp_tx_msdu_info_s *msdu_info)
  380. {
  381. uint32_t *meta_data = msdu_info->meta_data;
  382. struct htt_tx_msdu_desc_ext2_t *desc_ext =
  383. (struct htt_tx_msdu_desc_ext2_t *) meta_data;
  384. uint8_t htt_desc_size;
  385. /* Size rounded of multiple of 8 bytes */
  386. uint8_t htt_desc_size_aligned;
  387. uint8_t *hdr = NULL;
  388. /*
  389. * Metadata - HTT MSDU Extension header
  390. */
  391. htt_desc_size = sizeof(struct htt_tx_msdu_desc_ext2_t);
  392. htt_desc_size_aligned = (htt_desc_size + 7) & ~0x7;
  393. if (vdev->mesh_vdev || msdu_info->is_tx_sniffer ||
  394. HTT_TX_MSDU_EXT2_DESC_FLAG_VALID_KEY_FLAGS_GET(msdu_info->
  395. meta_data[0]) ||
  396. msdu_info->exception_fw) {
  397. if (qdf_unlikely(qdf_nbuf_headroom(nbuf) <
  398. htt_desc_size_aligned)) {
  399. nbuf = qdf_nbuf_realloc_headroom(nbuf,
  400. htt_desc_size_aligned);
  401. if (!nbuf) {
  402. /*
  403. * qdf_nbuf_realloc_headroom won't do skb_clone
  404. * as skb_realloc_headroom does. so, no free is
  405. * needed here.
  406. */
  407. DP_STATS_INC(vdev,
  408. tx_i.dropped.headroom_insufficient,
  409. 1);
  410. qdf_print(" %s[%d] skb_realloc_headroom failed",
  411. __func__, __LINE__);
  412. return 0;
  413. }
  414. }
  415. /* Fill and add HTT metaheader */
  416. hdr = qdf_nbuf_push_head(nbuf, htt_desc_size_aligned);
  417. if (!hdr) {
  418. dp_tx_err("Error in filling HTT metadata");
  419. return 0;
  420. }
  421. qdf_mem_copy(hdr, desc_ext, htt_desc_size);
  422. } else if (vdev->opmode == wlan_op_mode_ocb) {
  423. /* Todo - Add support for DSRC */
  424. }
  425. return htt_desc_size_aligned;
  426. }
  427. /**
  428. * dp_tx_prepare_tso_ext_desc() - Prepare MSDU extension descriptor for TSO
  429. * @tso_seg: TSO segment to process
  430. * @ext_desc: Pointer to MSDU extension descriptor
  431. *
  432. * Return: void
  433. */
  434. #if defined(FEATURE_TSO)
  435. static void dp_tx_prepare_tso_ext_desc(struct qdf_tso_seg_t *tso_seg,
  436. void *ext_desc)
  437. {
  438. uint8_t num_frag;
  439. uint32_t tso_flags;
  440. /*
  441. * Set tso_en, tcp_flags(NS, CWR, ECE, URG, ACK, PSH, RST, SYN, FIN),
  442. * tcp_flag_mask
  443. *
  444. * Checksum enable flags are set in TCL descriptor and not in Extension
  445. * Descriptor (H/W ignores checksum_en flags in MSDU ext descriptor)
  446. */
  447. tso_flags = *(uint32_t *) &tso_seg->tso_flags;
  448. hal_tx_ext_desc_set_tso_flags(ext_desc, tso_flags);
  449. hal_tx_ext_desc_set_msdu_length(ext_desc, tso_seg->tso_flags.l2_len,
  450. tso_seg->tso_flags.ip_len);
  451. hal_tx_ext_desc_set_tcp_seq(ext_desc, tso_seg->tso_flags.tcp_seq_num);
  452. hal_tx_ext_desc_set_ip_id(ext_desc, tso_seg->tso_flags.ip_id);
  453. for (num_frag = 0; num_frag < tso_seg->num_frags; num_frag++) {
  454. uint32_t lo = 0;
  455. uint32_t hi = 0;
  456. qdf_assert_always((tso_seg->tso_frags[num_frag].paddr) &&
  457. (tso_seg->tso_frags[num_frag].length));
  458. qdf_dmaaddr_to_32s(
  459. tso_seg->tso_frags[num_frag].paddr, &lo, &hi);
  460. hal_tx_ext_desc_set_buffer(ext_desc, num_frag, lo, hi,
  461. tso_seg->tso_frags[num_frag].length);
  462. }
  463. return;
  464. }
  465. #else
  466. static void dp_tx_prepare_tso_ext_desc(struct qdf_tso_seg_t *tso_seg,
  467. void *ext_desc)
  468. {
  469. return;
  470. }
  471. #endif
  472. #if defined(FEATURE_TSO)
  473. /**
  474. * dp_tx_free_tso_seg_list() - Loop through the tso segments
  475. * allocated and free them
  476. *
  477. * @soc: soc handle
  478. * @free_seg: list of tso segments
  479. * @msdu_info: msdu descriptor
  480. *
  481. * Return - void
  482. */
  483. static void dp_tx_free_tso_seg_list(
  484. struct dp_soc *soc,
  485. struct qdf_tso_seg_elem_t *free_seg,
  486. struct dp_tx_msdu_info_s *msdu_info)
  487. {
  488. struct qdf_tso_seg_elem_t *next_seg;
  489. while (free_seg) {
  490. next_seg = free_seg->next;
  491. dp_tx_tso_desc_free(soc,
  492. msdu_info->tx_queue.desc_pool_id,
  493. free_seg);
  494. free_seg = next_seg;
  495. }
  496. }
  497. /**
  498. * dp_tx_free_tso_num_seg_list() - Loop through the tso num segments
  499. * allocated and free them
  500. *
  501. * @soc: soc handle
  502. * @free_num_seg: list of tso number segments
  503. * @msdu_info: msdu descriptor
  504. * Return - void
  505. */
  506. static void dp_tx_free_tso_num_seg_list(
  507. struct dp_soc *soc,
  508. struct qdf_tso_num_seg_elem_t *free_num_seg,
  509. struct dp_tx_msdu_info_s *msdu_info)
  510. {
  511. struct qdf_tso_num_seg_elem_t *next_num_seg;
  512. while (free_num_seg) {
  513. next_num_seg = free_num_seg->next;
  514. dp_tso_num_seg_free(soc,
  515. msdu_info->tx_queue.desc_pool_id,
  516. free_num_seg);
  517. free_num_seg = next_num_seg;
  518. }
  519. }
  520. /**
  521. * dp_tx_unmap_tso_seg_list() - Loop through the tso segments
  522. * do dma unmap for each segment
  523. *
  524. * @soc: soc handle
  525. * @free_seg: list of tso segments
  526. * @num_seg_desc: tso number segment descriptor
  527. *
  528. * Return - void
  529. */
  530. static void dp_tx_unmap_tso_seg_list(
  531. struct dp_soc *soc,
  532. struct qdf_tso_seg_elem_t *free_seg,
  533. struct qdf_tso_num_seg_elem_t *num_seg_desc)
  534. {
  535. struct qdf_tso_seg_elem_t *next_seg;
  536. if (qdf_unlikely(!num_seg_desc)) {
  537. DP_TRACE(ERROR, "TSO number seg desc is NULL!");
  538. return;
  539. }
  540. while (free_seg) {
  541. next_seg = free_seg->next;
  542. dp_tx_tso_unmap_segment(soc, free_seg, num_seg_desc);
  543. free_seg = next_seg;
  544. }
  545. }
  546. #ifdef FEATURE_TSO_STATS
  547. /**
  548. * dp_tso_get_stats_idx: Retrieve the tso packet id
  549. * @pdev - pdev handle
  550. *
  551. * Return: id
  552. */
  553. static uint32_t dp_tso_get_stats_idx(struct dp_pdev *pdev)
  554. {
  555. uint32_t stats_idx;
  556. stats_idx = (((uint32_t)qdf_atomic_inc_return(&pdev->tso_idx))
  557. % CDP_MAX_TSO_PACKETS);
  558. return stats_idx;
  559. }
  560. #else
  561. static int dp_tso_get_stats_idx(struct dp_pdev *pdev)
  562. {
  563. return 0;
  564. }
  565. #endif /* FEATURE_TSO_STATS */
  566. /**
  567. * dp_tx_free_remaining_tso_desc() - do dma unmap for tso segments if any,
  568. * free the tso segments descriptor and
  569. * tso num segments descriptor
  570. *
  571. * @soc: soc handle
  572. * @msdu_info: msdu descriptor
  573. * @tso_seg_unmap: flag to show if dma unmap is necessary
  574. *
  575. * Return - void
  576. */
  577. static void dp_tx_free_remaining_tso_desc(struct dp_soc *soc,
  578. struct dp_tx_msdu_info_s *msdu_info,
  579. bool tso_seg_unmap)
  580. {
  581. struct qdf_tso_info_t *tso_info = &msdu_info->u.tso_info;
  582. struct qdf_tso_seg_elem_t *free_seg = tso_info->tso_seg_list;
  583. struct qdf_tso_num_seg_elem_t *tso_num_desc =
  584. tso_info->tso_num_seg_list;
  585. /* do dma unmap for each segment */
  586. if (tso_seg_unmap)
  587. dp_tx_unmap_tso_seg_list(soc, free_seg, tso_num_desc);
  588. /* free all tso number segment descriptor though looks only have 1 */
  589. dp_tx_free_tso_num_seg_list(soc, tso_num_desc, msdu_info);
  590. /* free all tso segment descriptor */
  591. dp_tx_free_tso_seg_list(soc, free_seg, msdu_info);
  592. }
  593. /**
  594. * dp_tx_prepare_tso() - Given a jumbo msdu, prepare the TSO info
  595. * @vdev: virtual device handle
  596. * @msdu: network buffer
  597. * @msdu_info: meta data associated with the msdu
  598. *
  599. * Return: QDF_STATUS_SUCCESS success
  600. */
  601. static QDF_STATUS dp_tx_prepare_tso(struct dp_vdev *vdev,
  602. qdf_nbuf_t msdu, struct dp_tx_msdu_info_s *msdu_info)
  603. {
  604. struct qdf_tso_seg_elem_t *tso_seg;
  605. int num_seg = qdf_nbuf_get_tso_num_seg(msdu);
  606. struct dp_soc *soc = vdev->pdev->soc;
  607. struct dp_pdev *pdev = vdev->pdev;
  608. struct qdf_tso_info_t *tso_info;
  609. struct qdf_tso_num_seg_elem_t *tso_num_seg;
  610. tso_info = &msdu_info->u.tso_info;
  611. tso_info->curr_seg = NULL;
  612. tso_info->tso_seg_list = NULL;
  613. tso_info->num_segs = num_seg;
  614. msdu_info->frm_type = dp_tx_frm_tso;
  615. tso_info->tso_num_seg_list = NULL;
  616. TSO_DEBUG(" %s: num_seg: %d", __func__, num_seg);
  617. while (num_seg) {
  618. tso_seg = dp_tx_tso_desc_alloc(
  619. soc, msdu_info->tx_queue.desc_pool_id);
  620. if (tso_seg) {
  621. tso_seg->next = tso_info->tso_seg_list;
  622. tso_info->tso_seg_list = tso_seg;
  623. num_seg--;
  624. } else {
  625. dp_err_rl("Failed to alloc tso seg desc");
  626. DP_STATS_INC_PKT(vdev->pdev,
  627. tso_stats.tso_no_mem_dropped, 1,
  628. qdf_nbuf_len(msdu));
  629. dp_tx_free_remaining_tso_desc(soc, msdu_info, false);
  630. return QDF_STATUS_E_NOMEM;
  631. }
  632. }
  633. TSO_DEBUG(" %s: num_seg: %d", __func__, num_seg);
  634. tso_num_seg = dp_tso_num_seg_alloc(soc,
  635. msdu_info->tx_queue.desc_pool_id);
  636. if (tso_num_seg) {
  637. tso_num_seg->next = tso_info->tso_num_seg_list;
  638. tso_info->tso_num_seg_list = tso_num_seg;
  639. } else {
  640. DP_TRACE(ERROR, "%s: Failed to alloc - Number of segs desc",
  641. __func__);
  642. dp_tx_free_remaining_tso_desc(soc, msdu_info, false);
  643. return QDF_STATUS_E_NOMEM;
  644. }
  645. msdu_info->num_seg =
  646. qdf_nbuf_get_tso_info(soc->osdev, msdu, tso_info);
  647. TSO_DEBUG(" %s: msdu_info->num_seg: %d", __func__,
  648. msdu_info->num_seg);
  649. if (!(msdu_info->num_seg)) {
  650. /*
  651. * Free allocated TSO seg desc and number seg desc,
  652. * do unmap for segments if dma map has done.
  653. */
  654. DP_TRACE(ERROR, "%s: Failed to get tso info", __func__);
  655. dp_tx_free_remaining_tso_desc(soc, msdu_info, true);
  656. return QDF_STATUS_E_INVAL;
  657. }
  658. dp_tx_tso_history_add(soc, msdu_info->u.tso_info,
  659. msdu, 0, DP_TX_DESC_MAP);
  660. tso_info->curr_seg = tso_info->tso_seg_list;
  661. tso_info->msdu_stats_idx = dp_tso_get_stats_idx(pdev);
  662. dp_tso_packet_update(pdev, tso_info->msdu_stats_idx,
  663. msdu, msdu_info->num_seg);
  664. dp_tso_segment_stats_update(pdev, tso_info->tso_seg_list,
  665. tso_info->msdu_stats_idx);
  666. dp_stats_tso_segment_histogram_update(pdev, msdu_info->num_seg);
  667. return QDF_STATUS_SUCCESS;
  668. }
  669. #else
  670. static QDF_STATUS dp_tx_prepare_tso(struct dp_vdev *vdev,
  671. qdf_nbuf_t msdu, struct dp_tx_msdu_info_s *msdu_info)
  672. {
  673. return QDF_STATUS_E_NOMEM;
  674. }
  675. #endif
  676. QDF_COMPILE_TIME_ASSERT(dp_tx_htt_metadata_len_check,
  677. (DP_TX_MSDU_INFO_META_DATA_DWORDS * 4 >=
  678. sizeof(struct htt_tx_msdu_desc_ext2_t)));
  679. /**
  680. * dp_tx_prepare_ext_desc() - Allocate and prepare MSDU extension descriptor
  681. * @vdev: DP Vdev handle
  682. * @msdu_info: MSDU info to be setup in MSDU extension descriptor
  683. * @desc_pool_id: Descriptor Pool ID
  684. *
  685. * Return:
  686. */
  687. static
  688. struct dp_tx_ext_desc_elem_s *dp_tx_prepare_ext_desc(struct dp_vdev *vdev,
  689. struct dp_tx_msdu_info_s *msdu_info, uint8_t desc_pool_id)
  690. {
  691. uint8_t i;
  692. uint8_t cached_ext_desc[HAL_TX_EXT_DESC_WITH_META_DATA];
  693. struct dp_tx_seg_info_s *seg_info;
  694. struct dp_tx_ext_desc_elem_s *msdu_ext_desc;
  695. struct dp_soc *soc = vdev->pdev->soc;
  696. /* Allocate an extension descriptor */
  697. msdu_ext_desc = dp_tx_ext_desc_alloc(soc, desc_pool_id);
  698. qdf_mem_zero(&cached_ext_desc[0], HAL_TX_EXT_DESC_WITH_META_DATA);
  699. if (!msdu_ext_desc) {
  700. DP_STATS_INC(vdev, tx_i.dropped.desc_na.num, 1);
  701. return NULL;
  702. }
  703. if (msdu_info->exception_fw &&
  704. qdf_unlikely(vdev->mesh_vdev)) {
  705. qdf_mem_copy(&cached_ext_desc[HAL_TX_EXTENSION_DESC_LEN_BYTES],
  706. &msdu_info->meta_data[0],
  707. sizeof(struct htt_tx_msdu_desc_ext2_t));
  708. qdf_atomic_inc(&soc->num_tx_exception);
  709. msdu_ext_desc->flags |= DP_TX_EXT_DESC_FLAG_METADATA_VALID;
  710. }
  711. switch (msdu_info->frm_type) {
  712. case dp_tx_frm_sg:
  713. case dp_tx_frm_me:
  714. case dp_tx_frm_raw:
  715. seg_info = msdu_info->u.sg_info.curr_seg;
  716. /* Update the buffer pointers in MSDU Extension Descriptor */
  717. for (i = 0; i < seg_info->frag_cnt; i++) {
  718. hal_tx_ext_desc_set_buffer(&cached_ext_desc[0], i,
  719. seg_info->frags[i].paddr_lo,
  720. seg_info->frags[i].paddr_hi,
  721. seg_info->frags[i].len);
  722. }
  723. break;
  724. case dp_tx_frm_tso:
  725. dp_tx_prepare_tso_ext_desc(&msdu_info->u.tso_info.curr_seg->seg,
  726. &cached_ext_desc[0]);
  727. break;
  728. default:
  729. break;
  730. }
  731. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  732. cached_ext_desc, HAL_TX_EXT_DESC_WITH_META_DATA);
  733. hal_tx_ext_desc_sync(&cached_ext_desc[0],
  734. msdu_ext_desc->vaddr);
  735. return msdu_ext_desc;
  736. }
  737. /**
  738. * dp_tx_trace_pkt() - Trace TX packet at DP layer
  739. *
  740. * @skb: skb to be traced
  741. * @msdu_id: msdu_id of the packet
  742. * @vdev_id: vdev_id of the packet
  743. *
  744. * Return: None
  745. */
  746. #ifdef DP_DISABLE_TX_PKT_TRACE
  747. static void dp_tx_trace_pkt(struct dp_soc *soc,
  748. qdf_nbuf_t skb, uint16_t msdu_id,
  749. uint8_t vdev_id)
  750. {
  751. }
  752. #else
  753. static void dp_tx_trace_pkt(struct dp_soc *soc,
  754. qdf_nbuf_t skb, uint16_t msdu_id,
  755. uint8_t vdev_id)
  756. {
  757. if (dp_is_tput_high(soc))
  758. return;
  759. QDF_NBUF_CB_TX_PACKET_TRACK(skb) = QDF_NBUF_TX_PKT_DATA_TRACK;
  760. QDF_NBUF_CB_TX_DP_TRACE(skb) = 1;
  761. DPTRACE(qdf_dp_trace_ptr(skb,
  762. QDF_DP_TRACE_LI_DP_TX_PACKET_PTR_RECORD,
  763. QDF_TRACE_DEFAULT_PDEV_ID,
  764. qdf_nbuf_data_addr(skb),
  765. sizeof(qdf_nbuf_data(skb)),
  766. msdu_id, vdev_id, 0));
  767. qdf_dp_trace_log_pkt(vdev_id, skb, QDF_TX, QDF_TRACE_DEFAULT_PDEV_ID);
  768. DPTRACE(qdf_dp_trace_data_pkt(skb, QDF_TRACE_DEFAULT_PDEV_ID,
  769. QDF_DP_TRACE_LI_DP_TX_PACKET_RECORD,
  770. msdu_id, QDF_TX));
  771. }
  772. #endif
  773. #ifdef WLAN_DP_FEATURE_MARK_ICMP_REQ_TO_FW
  774. /**
  775. * dp_tx_is_nbuf_marked_exception() - Check if the packet has been marked as
  776. * exception by the upper layer (OS_IF)
  777. * @soc: DP soc handle
  778. * @nbuf: packet to be transmitted
  779. *
  780. * Returns: 1 if the packet is marked as exception,
  781. * 0, if the packet is not marked as exception.
  782. */
  783. static inline int dp_tx_is_nbuf_marked_exception(struct dp_soc *soc,
  784. qdf_nbuf_t nbuf)
  785. {
  786. return QDF_NBUF_CB_TX_PACKET_TO_FW(nbuf);
  787. }
  788. #else
  789. static inline int dp_tx_is_nbuf_marked_exception(struct dp_soc *soc,
  790. qdf_nbuf_t nbuf)
  791. {
  792. return 0;
  793. }
  794. #endif
  795. #ifdef DP_TRAFFIC_END_INDICATION
  796. /**
  797. * dp_tx_get_traffic_end_indication_pkt() - Allocate and prepare packet to send
  798. * as indication to fw to inform that
  799. * data stream has ended
  800. * @vdev: DP vdev handle
  801. * @nbuf: original buffer from network stack
  802. *
  803. * Return: NULL on failure,
  804. * nbuf on success
  805. */
  806. static inline qdf_nbuf_t
  807. dp_tx_get_traffic_end_indication_pkt(struct dp_vdev *vdev,
  808. qdf_nbuf_t nbuf)
  809. {
  810. /* Packet length should be enough to copy upto L3 header */
  811. uint8_t end_nbuf_len = 64;
  812. uint8_t htt_desc_size_aligned;
  813. uint8_t htt_desc_size;
  814. qdf_nbuf_t end_nbuf;
  815. if (qdf_unlikely(QDF_NBUF_CB_GET_PACKET_TYPE(nbuf) ==
  816. QDF_NBUF_CB_PACKET_TYPE_END_INDICATION)) {
  817. htt_desc_size = sizeof(struct htt_tx_msdu_desc_ext2_t);
  818. htt_desc_size_aligned = (htt_desc_size + 7) & ~0x7;
  819. end_nbuf = qdf_nbuf_queue_remove(&vdev->end_ind_pkt_q);
  820. if (!end_nbuf) {
  821. end_nbuf = qdf_nbuf_alloc(NULL,
  822. (htt_desc_size_aligned +
  823. end_nbuf_len),
  824. htt_desc_size_aligned,
  825. 8, false);
  826. if (!end_nbuf) {
  827. dp_err("Packet allocation failed");
  828. goto out;
  829. }
  830. } else {
  831. qdf_nbuf_reset(end_nbuf, htt_desc_size_aligned, 8);
  832. }
  833. qdf_mem_copy(qdf_nbuf_data(end_nbuf), qdf_nbuf_data(nbuf),
  834. end_nbuf_len);
  835. qdf_nbuf_set_pktlen(end_nbuf, end_nbuf_len);
  836. return end_nbuf;
  837. }
  838. out:
  839. return NULL;
  840. }
  841. /**
  842. * dp_tx_send_traffic_end_indication_pkt() - Send indication packet to FW
  843. * via exception path.
  844. * @vdev: DP vdev handle
  845. * @end_nbuf: skb to send as indication
  846. * @msdu_info: msdu_info of original nbuf
  847. * @peer_id: peer id
  848. *
  849. * Return: None
  850. */
  851. static inline void
  852. dp_tx_send_traffic_end_indication_pkt(struct dp_vdev *vdev,
  853. qdf_nbuf_t end_nbuf,
  854. struct dp_tx_msdu_info_s *msdu_info,
  855. uint16_t peer_id)
  856. {
  857. struct dp_tx_msdu_info_s e_msdu_info = {0};
  858. qdf_nbuf_t nbuf;
  859. struct htt_tx_msdu_desc_ext2_t *desc_ext =
  860. (struct htt_tx_msdu_desc_ext2_t *)(e_msdu_info.meta_data);
  861. e_msdu_info.tx_queue = msdu_info->tx_queue;
  862. e_msdu_info.tid = msdu_info->tid;
  863. e_msdu_info.exception_fw = 1;
  864. desc_ext->host_tx_desc_pool = 1;
  865. desc_ext->traffic_end_indication = 1;
  866. nbuf = dp_tx_send_msdu_single(vdev, end_nbuf, &e_msdu_info,
  867. peer_id, NULL);
  868. if (nbuf) {
  869. dp_err("Traffic end indication packet tx failed");
  870. qdf_nbuf_free(nbuf);
  871. }
  872. }
  873. /**
  874. * dp_tx_traffic_end_indication_set_desc_flag() - Set tx descriptor flag to
  875. * mark it trafic end indication
  876. * packet.
  877. * @tx_desc: Tx descriptor pointer
  878. * @msdu_info: msdu_info structure pointer
  879. *
  880. * Return: None
  881. */
  882. static inline void
  883. dp_tx_traffic_end_indication_set_desc_flag(struct dp_tx_desc_s *tx_desc,
  884. struct dp_tx_msdu_info_s *msdu_info)
  885. {
  886. struct htt_tx_msdu_desc_ext2_t *desc_ext =
  887. (struct htt_tx_msdu_desc_ext2_t *)(msdu_info->meta_data);
  888. if (qdf_unlikely(desc_ext->traffic_end_indication))
  889. tx_desc->flags |= DP_TX_DESC_FLAG_TRAFFIC_END_IND;
  890. }
  891. /**
  892. * dp_tx_traffic_end_indication_enq_ind_pkt() - Enqueue the packet instead of
  893. * freeing which are associated
  894. * with traffic end indication
  895. * flagged descriptor.
  896. * @soc: dp soc handle
  897. * @desc: Tx descriptor pointer
  898. * @nbuf: buffer pointer
  899. *
  900. * Return: True if packet gets enqueued else false
  901. */
  902. static bool
  903. dp_tx_traffic_end_indication_enq_ind_pkt(struct dp_soc *soc,
  904. struct dp_tx_desc_s *desc,
  905. qdf_nbuf_t nbuf)
  906. {
  907. struct dp_vdev *vdev = NULL;
  908. if (qdf_unlikely((desc->flags &
  909. DP_TX_DESC_FLAG_TRAFFIC_END_IND) != 0)) {
  910. vdev = dp_vdev_get_ref_by_id(soc, desc->vdev_id,
  911. DP_MOD_ID_TX_COMP);
  912. if (vdev) {
  913. qdf_nbuf_queue_add(&vdev->end_ind_pkt_q, nbuf);
  914. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TX_COMP);
  915. return true;
  916. }
  917. }
  918. return false;
  919. }
  920. /**
  921. * dp_tx_traffic_end_indication_is_enabled() - get the feature
  922. * enable/disable status
  923. * @vdev: dp vdev handle
  924. *
  925. * Return: True if feature is enable else false
  926. */
  927. static inline bool
  928. dp_tx_traffic_end_indication_is_enabled(struct dp_vdev *vdev)
  929. {
  930. return qdf_unlikely(vdev->traffic_end_ind_en);
  931. }
  932. static inline qdf_nbuf_t
  933. dp_tx_send_msdu_single_wrapper(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  934. struct dp_tx_msdu_info_s *msdu_info,
  935. uint16_t peer_id, qdf_nbuf_t end_nbuf)
  936. {
  937. if (dp_tx_traffic_end_indication_is_enabled(vdev))
  938. end_nbuf = dp_tx_get_traffic_end_indication_pkt(vdev, nbuf);
  939. nbuf = dp_tx_send_msdu_single(vdev, nbuf, msdu_info, peer_id, NULL);
  940. if (qdf_unlikely(end_nbuf))
  941. dp_tx_send_traffic_end_indication_pkt(vdev, end_nbuf,
  942. msdu_info, peer_id);
  943. return nbuf;
  944. }
  945. #else
  946. static inline qdf_nbuf_t
  947. dp_tx_get_traffic_end_indication_pkt(struct dp_vdev *vdev,
  948. qdf_nbuf_t nbuf)
  949. {
  950. return NULL;
  951. }
  952. static inline void
  953. dp_tx_send_traffic_end_indication_pkt(struct dp_vdev *vdev,
  954. qdf_nbuf_t end_nbuf,
  955. struct dp_tx_msdu_info_s *msdu_info,
  956. uint16_t peer_id)
  957. {}
  958. static inline void
  959. dp_tx_traffic_end_indication_set_desc_flag(struct dp_tx_desc_s *tx_desc,
  960. struct dp_tx_msdu_info_s *msdu_info)
  961. {}
  962. static inline bool
  963. dp_tx_traffic_end_indication_enq_ind_pkt(struct dp_soc *soc,
  964. struct dp_tx_desc_s *desc,
  965. qdf_nbuf_t nbuf)
  966. {
  967. return false;
  968. }
  969. static inline bool
  970. dp_tx_traffic_end_indication_is_enabled(struct dp_vdev *vdev)
  971. {
  972. return false;
  973. }
  974. static inline qdf_nbuf_t
  975. dp_tx_send_msdu_single_wrapper(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  976. struct dp_tx_msdu_info_s *msdu_info,
  977. uint16_t peer_id, qdf_nbuf_t end_nbuf)
  978. {
  979. return dp_tx_send_msdu_single(vdev, nbuf, msdu_info, peer_id, NULL);
  980. }
  981. #endif
  982. /**
  983. * dp_tx_desc_prepare_single - Allocate and prepare Tx descriptor
  984. * @vdev: DP vdev handle
  985. * @nbuf: skb
  986. * @desc_pool_id: Descriptor pool ID
  987. * @meta_data: Metadata to the fw
  988. * @tx_exc_metadata: Handle that holds exception path metadata
  989. * Allocate and prepare Tx descriptor with msdu information.
  990. *
  991. * Return: Pointer to Tx Descriptor on success,
  992. * NULL on failure
  993. */
  994. static
  995. struct dp_tx_desc_s *dp_tx_prepare_desc_single(struct dp_vdev *vdev,
  996. qdf_nbuf_t nbuf, uint8_t desc_pool_id,
  997. struct dp_tx_msdu_info_s *msdu_info,
  998. struct cdp_tx_exception_metadata *tx_exc_metadata)
  999. {
  1000. uint8_t align_pad;
  1001. uint8_t is_exception = 0;
  1002. uint8_t htt_hdr_size;
  1003. struct dp_tx_desc_s *tx_desc;
  1004. struct dp_pdev *pdev = vdev->pdev;
  1005. struct dp_soc *soc = pdev->soc;
  1006. if (dp_tx_limit_check(vdev))
  1007. return NULL;
  1008. /* Allocate software Tx descriptor */
  1009. tx_desc = dp_tx_desc_alloc(soc, desc_pool_id);
  1010. if (qdf_unlikely(!tx_desc)) {
  1011. DP_STATS_INC(vdev, tx_i.dropped.desc_na.num, 1);
  1012. DP_STATS_INC(vdev, tx_i.dropped.desc_na_exc_alloc_fail.num, 1);
  1013. return NULL;
  1014. }
  1015. dp_tx_outstanding_inc(pdev);
  1016. /* Initialize the SW tx descriptor */
  1017. tx_desc->nbuf = nbuf;
  1018. tx_desc->frm_type = dp_tx_frm_std;
  1019. tx_desc->tx_encap_type = ((tx_exc_metadata &&
  1020. (tx_exc_metadata->tx_encap_type != CDP_INVALID_TX_ENCAP_TYPE)) ?
  1021. tx_exc_metadata->tx_encap_type : vdev->tx_encap_type);
  1022. tx_desc->vdev_id = vdev->vdev_id;
  1023. tx_desc->pdev = pdev;
  1024. tx_desc->msdu_ext_desc = NULL;
  1025. tx_desc->pkt_offset = 0;
  1026. tx_desc->length = qdf_nbuf_headlen(nbuf);
  1027. tx_desc->shinfo_addr = skb_end_pointer(nbuf);
  1028. dp_tx_trace_pkt(soc, nbuf, tx_desc->id, vdev->vdev_id);
  1029. if (qdf_unlikely(vdev->multipass_en)) {
  1030. if (!dp_tx_multipass_process(soc, vdev, nbuf, msdu_info))
  1031. goto failure;
  1032. }
  1033. /* Packets marked by upper layer (OS-IF) to be sent to FW */
  1034. if (dp_tx_is_nbuf_marked_exception(soc, nbuf))
  1035. is_exception = 1;
  1036. /*
  1037. * For special modes (vdev_type == ocb or mesh), data frames should be
  1038. * transmitted using varying transmit parameters (tx spec) which include
  1039. * transmit rate, power, priority, channel, channel bandwidth , nss etc.
  1040. * These are filled in HTT MSDU descriptor and sent in frame pre-header.
  1041. * These frames are sent as exception packets to firmware.
  1042. *
  1043. * HW requirement is that metadata should always point to a
  1044. * 8-byte aligned address. So we add alignment pad to start of buffer.
  1045. * HTT Metadata should be ensured to be multiple of 8-bytes,
  1046. * to get 8-byte aligned start address along with align_pad added
  1047. *
  1048. * |-----------------------------|
  1049. * | |
  1050. * |-----------------------------| <-----Buffer Pointer Address given
  1051. * | | ^ in HW descriptor (aligned)
  1052. * | HTT Metadata | |
  1053. * | | |
  1054. * | | | Packet Offset given in descriptor
  1055. * | | |
  1056. * |-----------------------------| |
  1057. * | Alignment Pad | v
  1058. * |-----------------------------| <----- Actual buffer start address
  1059. * | SKB Data | (Unaligned)
  1060. * | |
  1061. * | |
  1062. * | |
  1063. * | |
  1064. * | |
  1065. * |-----------------------------|
  1066. */
  1067. if (qdf_unlikely((msdu_info->exception_fw)) ||
  1068. (vdev->opmode == wlan_op_mode_ocb) ||
  1069. (tx_exc_metadata &&
  1070. tx_exc_metadata->is_tx_sniffer)) {
  1071. align_pad = ((unsigned long) qdf_nbuf_data(nbuf)) & 0x7;
  1072. if (qdf_unlikely(qdf_nbuf_headroom(nbuf) < align_pad)) {
  1073. DP_STATS_INC(vdev,
  1074. tx_i.dropped.headroom_insufficient, 1);
  1075. goto failure;
  1076. }
  1077. if (qdf_nbuf_push_head(nbuf, align_pad) == NULL) {
  1078. dp_tx_err("qdf_nbuf_push_head failed");
  1079. goto failure;
  1080. }
  1081. htt_hdr_size = dp_tx_prepare_htt_metadata(vdev, nbuf,
  1082. msdu_info);
  1083. if (htt_hdr_size == 0)
  1084. goto failure;
  1085. tx_desc->length = qdf_nbuf_headlen(nbuf);
  1086. tx_desc->pkt_offset = align_pad + htt_hdr_size;
  1087. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  1088. dp_tx_traffic_end_indication_set_desc_flag(tx_desc,
  1089. msdu_info);
  1090. is_exception = 1;
  1091. tx_desc->length -= tx_desc->pkt_offset;
  1092. }
  1093. #if !TQM_BYPASS_WAR
  1094. if (is_exception || tx_exc_metadata)
  1095. #endif
  1096. {
  1097. /* Temporary WAR due to TQM VP issues */
  1098. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  1099. qdf_atomic_inc(&soc->num_tx_exception);
  1100. }
  1101. return tx_desc;
  1102. failure:
  1103. dp_tx_desc_release(tx_desc, desc_pool_id);
  1104. return NULL;
  1105. }
  1106. /**
  1107. * dp_tx_prepare_desc() - Allocate and prepare Tx descriptor for multisegment frame
  1108. * @vdev: DP vdev handle
  1109. * @nbuf: skb
  1110. * @msdu_info: Info to be setup in MSDU descriptor and MSDU extension descriptor
  1111. * @desc_pool_id : Descriptor Pool ID
  1112. *
  1113. * Allocate and prepare Tx descriptor with msdu and fragment descritor
  1114. * information. For frames wth fragments, allocate and prepare
  1115. * an MSDU extension descriptor
  1116. *
  1117. * Return: Pointer to Tx Descriptor on success,
  1118. * NULL on failure
  1119. */
  1120. static struct dp_tx_desc_s *dp_tx_prepare_desc(struct dp_vdev *vdev,
  1121. qdf_nbuf_t nbuf, struct dp_tx_msdu_info_s *msdu_info,
  1122. uint8_t desc_pool_id)
  1123. {
  1124. struct dp_tx_desc_s *tx_desc;
  1125. struct dp_tx_ext_desc_elem_s *msdu_ext_desc;
  1126. struct dp_pdev *pdev = vdev->pdev;
  1127. struct dp_soc *soc = pdev->soc;
  1128. if (dp_tx_limit_check(vdev))
  1129. return NULL;
  1130. /* Allocate software Tx descriptor */
  1131. tx_desc = dp_tx_desc_alloc(soc, desc_pool_id);
  1132. if (!tx_desc) {
  1133. DP_STATS_INC(vdev, tx_i.dropped.desc_na.num, 1);
  1134. return NULL;
  1135. }
  1136. dp_tx_tso_seg_history_add(soc, msdu_info->u.tso_info.curr_seg,
  1137. nbuf, tx_desc->id, DP_TX_DESC_COOKIE);
  1138. dp_tx_outstanding_inc(pdev);
  1139. /* Initialize the SW tx descriptor */
  1140. tx_desc->nbuf = nbuf;
  1141. tx_desc->frm_type = msdu_info->frm_type;
  1142. tx_desc->tx_encap_type = vdev->tx_encap_type;
  1143. tx_desc->vdev_id = vdev->vdev_id;
  1144. tx_desc->pdev = pdev;
  1145. tx_desc->pkt_offset = 0;
  1146. dp_tx_trace_pkt(soc, nbuf, tx_desc->id, vdev->vdev_id);
  1147. /* Handle scattered frames - TSO/SG/ME */
  1148. /* Allocate and prepare an extension descriptor for scattered frames */
  1149. msdu_ext_desc = dp_tx_prepare_ext_desc(vdev, msdu_info, desc_pool_id);
  1150. if (!msdu_ext_desc) {
  1151. dp_tx_info("Tx Extension Descriptor Alloc Fail");
  1152. goto failure;
  1153. }
  1154. #if TQM_BYPASS_WAR
  1155. /* Temporary WAR due to TQM VP issues */
  1156. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  1157. qdf_atomic_inc(&soc->num_tx_exception);
  1158. #endif
  1159. if (qdf_unlikely(msdu_info->exception_fw))
  1160. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  1161. tx_desc->msdu_ext_desc = msdu_ext_desc;
  1162. tx_desc->flags |= DP_TX_DESC_FLAG_FRAG;
  1163. msdu_ext_desc->tso_desc = msdu_info->u.tso_info.curr_seg;
  1164. msdu_ext_desc->tso_num_desc = msdu_info->u.tso_info.tso_num_seg_list;
  1165. tx_desc->dma_addr = msdu_ext_desc->paddr;
  1166. if (msdu_ext_desc->flags & DP_TX_EXT_DESC_FLAG_METADATA_VALID)
  1167. tx_desc->length = HAL_TX_EXT_DESC_WITH_META_DATA;
  1168. else
  1169. tx_desc->length = HAL_TX_EXTENSION_DESC_LEN_BYTES;
  1170. return tx_desc;
  1171. failure:
  1172. dp_tx_desc_release(tx_desc, desc_pool_id);
  1173. return NULL;
  1174. }
  1175. /**
  1176. * dp_tx_prepare_raw() - Prepare RAW packet TX
  1177. * @vdev: DP vdev handle
  1178. * @nbuf: buffer pointer
  1179. * @seg_info: Pointer to Segment info Descriptor to be prepared
  1180. * @msdu_info: MSDU info to be setup in MSDU descriptor and MSDU extension
  1181. * descriptor
  1182. *
  1183. * Return:
  1184. */
  1185. static qdf_nbuf_t dp_tx_prepare_raw(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1186. struct dp_tx_seg_info_s *seg_info, struct dp_tx_msdu_info_s *msdu_info)
  1187. {
  1188. qdf_nbuf_t curr_nbuf = NULL;
  1189. uint16_t total_len = 0;
  1190. qdf_dma_addr_t paddr;
  1191. int32_t i;
  1192. int32_t mapped_buf_num = 0;
  1193. struct dp_tx_sg_info_s *sg_info = &msdu_info->u.sg_info;
  1194. qdf_dot3_qosframe_t *qos_wh = (qdf_dot3_qosframe_t *) nbuf->data;
  1195. DP_STATS_INC_PKT(vdev, tx_i.raw.raw_pkt, 1, qdf_nbuf_len(nbuf));
  1196. /* Continue only if frames are of DATA type */
  1197. if (!DP_FRAME_IS_DATA(qos_wh)) {
  1198. DP_STATS_INC(vdev, tx_i.raw.invalid_raw_pkt_datatype, 1);
  1199. dp_tx_debug("Pkt. recd is of not data type");
  1200. goto error;
  1201. }
  1202. /* SWAR for HW: Enable WEP bit in the AMSDU frames for RAW mode */
  1203. if (vdev->raw_mode_war &&
  1204. (qos_wh->i_fc[0] & QDF_IEEE80211_FC0_SUBTYPE_QOS) &&
  1205. (qos_wh->i_qos[0] & IEEE80211_QOS_AMSDU))
  1206. qos_wh->i_fc[1] |= IEEE80211_FC1_WEP;
  1207. for (curr_nbuf = nbuf, i = 0; curr_nbuf;
  1208. curr_nbuf = qdf_nbuf_next(curr_nbuf), i++) {
  1209. /*
  1210. * Number of nbuf's must not exceed the size of the frags
  1211. * array in seg_info.
  1212. */
  1213. if (i >= DP_TX_MAX_NUM_FRAGS) {
  1214. dp_err_rl("nbuf cnt exceeds the max number of segs");
  1215. DP_STATS_INC(vdev, tx_i.raw.num_frags_overflow_err, 1);
  1216. goto error;
  1217. }
  1218. if (QDF_STATUS_SUCCESS !=
  1219. qdf_nbuf_map_nbytes_single(vdev->osdev,
  1220. curr_nbuf,
  1221. QDF_DMA_TO_DEVICE,
  1222. curr_nbuf->len)) {
  1223. dp_tx_err("%s dma map error ", __func__);
  1224. DP_STATS_INC(vdev, tx_i.raw.dma_map_error, 1);
  1225. goto error;
  1226. }
  1227. /* Update the count of mapped nbuf's */
  1228. mapped_buf_num++;
  1229. paddr = qdf_nbuf_get_frag_paddr(curr_nbuf, 0);
  1230. seg_info->frags[i].paddr_lo = paddr;
  1231. seg_info->frags[i].paddr_hi = ((uint64_t)paddr >> 32);
  1232. seg_info->frags[i].len = qdf_nbuf_len(curr_nbuf);
  1233. seg_info->frags[i].vaddr = (void *) curr_nbuf;
  1234. total_len += qdf_nbuf_len(curr_nbuf);
  1235. }
  1236. seg_info->frag_cnt = i;
  1237. seg_info->total_len = total_len;
  1238. seg_info->next = NULL;
  1239. sg_info->curr_seg = seg_info;
  1240. msdu_info->frm_type = dp_tx_frm_raw;
  1241. msdu_info->num_seg = 1;
  1242. return nbuf;
  1243. error:
  1244. i = 0;
  1245. while (nbuf) {
  1246. curr_nbuf = nbuf;
  1247. if (i < mapped_buf_num) {
  1248. qdf_nbuf_unmap_nbytes_single(vdev->osdev, curr_nbuf,
  1249. QDF_DMA_TO_DEVICE,
  1250. curr_nbuf->len);
  1251. i++;
  1252. }
  1253. nbuf = qdf_nbuf_next(nbuf);
  1254. qdf_nbuf_free(curr_nbuf);
  1255. }
  1256. return NULL;
  1257. }
  1258. /**
  1259. * dp_tx_raw_prepare_unset() - unmap the chain of nbufs belonging to RAW frame.
  1260. * @soc: DP soc handle
  1261. * @nbuf: Buffer pointer
  1262. *
  1263. * unmap the chain of nbufs that belong to this RAW frame.
  1264. *
  1265. * Return: None
  1266. */
  1267. static void dp_tx_raw_prepare_unset(struct dp_soc *soc,
  1268. qdf_nbuf_t nbuf)
  1269. {
  1270. qdf_nbuf_t cur_nbuf = nbuf;
  1271. do {
  1272. qdf_nbuf_unmap_nbytes_single(soc->osdev, cur_nbuf,
  1273. QDF_DMA_TO_DEVICE,
  1274. cur_nbuf->len);
  1275. cur_nbuf = qdf_nbuf_next(cur_nbuf);
  1276. } while (cur_nbuf);
  1277. }
  1278. #ifdef VDEV_PEER_PROTOCOL_COUNT
  1279. void dp_vdev_peer_stats_update_protocol_cnt_tx(struct dp_vdev *vdev_hdl,
  1280. qdf_nbuf_t nbuf)
  1281. {
  1282. qdf_nbuf_t nbuf_local;
  1283. struct dp_vdev *vdev_local = vdev_hdl;
  1284. do {
  1285. if (qdf_likely(!((vdev_local)->peer_protocol_count_track)))
  1286. break;
  1287. nbuf_local = nbuf;
  1288. if (qdf_unlikely(((vdev_local)->tx_encap_type) ==
  1289. htt_cmn_pkt_type_raw))
  1290. break;
  1291. else if (qdf_unlikely(qdf_nbuf_is_nonlinear((nbuf_local))))
  1292. break;
  1293. else if (qdf_nbuf_is_tso((nbuf_local)))
  1294. break;
  1295. dp_vdev_peer_stats_update_protocol_cnt((vdev_local),
  1296. (nbuf_local),
  1297. NULL, 1, 0);
  1298. } while (0);
  1299. }
  1300. #endif
  1301. #ifdef WLAN_DP_FEATURE_SW_LATENCY_MGR
  1302. /**
  1303. * dp_tx_update_stats() - Update soc level tx stats
  1304. * @soc: DP soc handle
  1305. * @tx_desc: TX descriptor reference
  1306. * @ring_id: TCL ring id
  1307. *
  1308. * Returns: none
  1309. */
  1310. void dp_tx_update_stats(struct dp_soc *soc,
  1311. struct dp_tx_desc_s *tx_desc,
  1312. uint8_t ring_id)
  1313. {
  1314. uint32_t stats_len = 0;
  1315. if (tx_desc->frm_type == dp_tx_frm_tso)
  1316. stats_len = tx_desc->msdu_ext_desc->tso_desc->seg.total_len;
  1317. else
  1318. stats_len = qdf_nbuf_len(tx_desc->nbuf);
  1319. DP_STATS_INC_PKT(soc, tx.egress[ring_id], 1, stats_len);
  1320. }
  1321. int
  1322. dp_tx_attempt_coalescing(struct dp_soc *soc, struct dp_vdev *vdev,
  1323. struct dp_tx_desc_s *tx_desc,
  1324. uint8_t tid,
  1325. struct dp_tx_msdu_info_s *msdu_info,
  1326. uint8_t ring_id)
  1327. {
  1328. struct dp_swlm *swlm = &soc->swlm;
  1329. union swlm_data swlm_query_data;
  1330. struct dp_swlm_tcl_data tcl_data;
  1331. QDF_STATUS status;
  1332. int ret;
  1333. if (!swlm->is_enabled)
  1334. return msdu_info->skip_hp_update;
  1335. tcl_data.nbuf = tx_desc->nbuf;
  1336. tcl_data.tid = tid;
  1337. tcl_data.ring_id = ring_id;
  1338. if (tx_desc->frm_type == dp_tx_frm_tso) {
  1339. tcl_data.pkt_len =
  1340. tx_desc->msdu_ext_desc->tso_desc->seg.total_len;
  1341. } else {
  1342. tcl_data.pkt_len = qdf_nbuf_len(tx_desc->nbuf);
  1343. }
  1344. tcl_data.num_ll_connections = vdev->num_latency_critical_conn;
  1345. swlm_query_data.tcl_data = &tcl_data;
  1346. status = dp_swlm_tcl_pre_check(soc, &tcl_data);
  1347. if (QDF_IS_STATUS_ERROR(status)) {
  1348. dp_swlm_tcl_reset_session_data(soc, ring_id);
  1349. DP_STATS_INC(swlm, tcl[ring_id].coalesce_fail, 1);
  1350. return 0;
  1351. }
  1352. ret = dp_swlm_query_policy(soc, TCL_DATA, swlm_query_data);
  1353. if (ret) {
  1354. DP_STATS_INC(swlm, tcl[ring_id].coalesce_success, 1);
  1355. } else {
  1356. DP_STATS_INC(swlm, tcl[ring_id].coalesce_fail, 1);
  1357. }
  1358. return ret;
  1359. }
  1360. void
  1361. dp_tx_ring_access_end(struct dp_soc *soc, hal_ring_handle_t hal_ring_hdl,
  1362. int coalesce)
  1363. {
  1364. if (coalesce)
  1365. dp_tx_hal_ring_access_end_reap(soc, hal_ring_hdl);
  1366. else
  1367. dp_tx_hal_ring_access_end(soc, hal_ring_hdl);
  1368. }
  1369. static inline void
  1370. dp_tx_is_hp_update_required(uint32_t i, struct dp_tx_msdu_info_s *msdu_info)
  1371. {
  1372. if (((i + 1) < msdu_info->num_seg))
  1373. msdu_info->skip_hp_update = 1;
  1374. else
  1375. msdu_info->skip_hp_update = 0;
  1376. }
  1377. static inline void
  1378. dp_flush_tcp_hp(struct dp_soc *soc, uint8_t ring_id)
  1379. {
  1380. hal_ring_handle_t hal_ring_hdl =
  1381. dp_tx_get_hal_ring_hdl(soc, ring_id);
  1382. if (dp_tx_hal_ring_access_start(soc, hal_ring_hdl)) {
  1383. dp_err("Fillmore: SRNG access start failed");
  1384. return;
  1385. }
  1386. dp_tx_ring_access_end_wrapper(soc, hal_ring_hdl, 0);
  1387. }
  1388. static inline void
  1389. dp_tx_check_and_flush_hp(struct dp_soc *soc,
  1390. QDF_STATUS status,
  1391. struct dp_tx_msdu_info_s *msdu_info)
  1392. {
  1393. if (QDF_IS_STATUS_ERROR(status) && !msdu_info->skip_hp_update) {
  1394. dp_flush_tcp_hp(soc,
  1395. (msdu_info->tx_queue.ring_id & DP_TX_QUEUE_MASK));
  1396. }
  1397. }
  1398. #else
  1399. static inline void
  1400. dp_tx_is_hp_update_required(uint32_t i, struct dp_tx_msdu_info_s *msdu_info)
  1401. {
  1402. }
  1403. static inline void
  1404. dp_tx_check_and_flush_hp(struct dp_soc *soc,
  1405. QDF_STATUS status,
  1406. struct dp_tx_msdu_info_s *msdu_info)
  1407. {
  1408. }
  1409. #endif
  1410. #ifdef FEATURE_RUNTIME_PM
  1411. static inline int dp_get_rtpm_tput_policy_requirement(struct dp_soc *soc)
  1412. {
  1413. int ret;
  1414. ret = qdf_atomic_read(&soc->rtpm_high_tput_flag) &&
  1415. (hif_rtpm_get_state() <= HIF_RTPM_STATE_ON);
  1416. return ret;
  1417. }
  1418. /**
  1419. * dp_tx_ring_access_end_wrapper() - Wrapper for ring access end
  1420. * @soc: Datapath soc handle
  1421. * @hal_ring_hdl: HAL ring handle
  1422. * @coalesce: Coalesce the current write or not
  1423. *
  1424. * Wrapper for HAL ring access end for data transmission for
  1425. * FEATURE_RUNTIME_PM
  1426. *
  1427. * Returns: none
  1428. */
  1429. void
  1430. dp_tx_ring_access_end_wrapper(struct dp_soc *soc,
  1431. hal_ring_handle_t hal_ring_hdl,
  1432. int coalesce)
  1433. {
  1434. int ret;
  1435. /*
  1436. * Avoid runtime get and put APIs under high throughput scenarios.
  1437. */
  1438. if (dp_get_rtpm_tput_policy_requirement(soc)) {
  1439. dp_tx_ring_access_end(soc, hal_ring_hdl, coalesce);
  1440. return;
  1441. }
  1442. ret = hif_rtpm_get(HIF_RTPM_GET_ASYNC, HIF_RTPM_ID_DP);
  1443. if (QDF_IS_STATUS_SUCCESS(ret)) {
  1444. if (hif_system_pm_state_check(soc->hif_handle)) {
  1445. dp_tx_hal_ring_access_end_reap(soc, hal_ring_hdl);
  1446. hal_srng_set_event(hal_ring_hdl, HAL_SRNG_FLUSH_EVENT);
  1447. hal_srng_inc_flush_cnt(hal_ring_hdl);
  1448. } else {
  1449. dp_tx_ring_access_end(soc, hal_ring_hdl, coalesce);
  1450. }
  1451. hif_rtpm_put(HIF_RTPM_PUT_ASYNC, HIF_RTPM_ID_DP);
  1452. } else {
  1453. dp_runtime_get(soc);
  1454. dp_tx_hal_ring_access_end_reap(soc, hal_ring_hdl);
  1455. hal_srng_set_event(hal_ring_hdl, HAL_SRNG_FLUSH_EVENT);
  1456. qdf_atomic_inc(&soc->tx_pending_rtpm);
  1457. hal_srng_inc_flush_cnt(hal_ring_hdl);
  1458. dp_runtime_put(soc);
  1459. }
  1460. }
  1461. #else
  1462. #ifdef DP_POWER_SAVE
  1463. void
  1464. dp_tx_ring_access_end_wrapper(struct dp_soc *soc,
  1465. hal_ring_handle_t hal_ring_hdl,
  1466. int coalesce)
  1467. {
  1468. if (hif_system_pm_state_check(soc->hif_handle)) {
  1469. dp_tx_hal_ring_access_end_reap(soc, hal_ring_hdl);
  1470. hal_srng_set_event(hal_ring_hdl, HAL_SRNG_FLUSH_EVENT);
  1471. hal_srng_inc_flush_cnt(hal_ring_hdl);
  1472. } else {
  1473. dp_tx_ring_access_end(soc, hal_ring_hdl, coalesce);
  1474. }
  1475. }
  1476. #endif
  1477. static inline int dp_get_rtpm_tput_policy_requirement(struct dp_soc *soc)
  1478. {
  1479. return 0;
  1480. }
  1481. #endif
  1482. /**
  1483. * dp_tx_get_tid() - Obtain TID to be used for this frame
  1484. * @vdev: DP vdev handle
  1485. * @nbuf: skb
  1486. *
  1487. * Extract the DSCP or PCP information from frame and map into TID value.
  1488. *
  1489. * Return: void
  1490. */
  1491. static void dp_tx_get_tid(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1492. struct dp_tx_msdu_info_s *msdu_info)
  1493. {
  1494. uint8_t tos = 0, dscp_tid_override = 0;
  1495. uint8_t *hdr_ptr, *L3datap;
  1496. uint8_t is_mcast = 0;
  1497. qdf_ether_header_t *eh = NULL;
  1498. qdf_ethervlan_header_t *evh = NULL;
  1499. uint16_t ether_type;
  1500. qdf_llc_t *llcHdr;
  1501. struct dp_pdev *pdev = (struct dp_pdev *)vdev->pdev;
  1502. DP_TX_TID_OVERRIDE(msdu_info, nbuf);
  1503. if (qdf_likely(vdev->tx_encap_type != htt_cmn_pkt_type_raw)) {
  1504. eh = (qdf_ether_header_t *)nbuf->data;
  1505. hdr_ptr = (uint8_t *)(eh->ether_dhost);
  1506. L3datap = hdr_ptr + sizeof(qdf_ether_header_t);
  1507. } else {
  1508. qdf_dot3_qosframe_t *qos_wh =
  1509. (qdf_dot3_qosframe_t *) nbuf->data;
  1510. msdu_info->tid = qos_wh->i_fc[0] & DP_FC0_SUBTYPE_QOS ?
  1511. qos_wh->i_qos[0] & DP_QOS_TID : 0;
  1512. return;
  1513. }
  1514. is_mcast = DP_FRAME_IS_MULTICAST(hdr_ptr);
  1515. ether_type = eh->ether_type;
  1516. llcHdr = (qdf_llc_t *)(nbuf->data + sizeof(qdf_ether_header_t));
  1517. /*
  1518. * Check if packet is dot3 or eth2 type.
  1519. */
  1520. if (DP_FRAME_IS_LLC(ether_type) && DP_FRAME_IS_SNAP(llcHdr)) {
  1521. ether_type = (uint16_t)*(nbuf->data + 2*QDF_MAC_ADDR_SIZE +
  1522. sizeof(*llcHdr));
  1523. if (ether_type == htons(ETHERTYPE_VLAN)) {
  1524. L3datap = hdr_ptr + sizeof(qdf_ethervlan_header_t) +
  1525. sizeof(*llcHdr);
  1526. ether_type = (uint16_t)*(nbuf->data + 2*QDF_MAC_ADDR_SIZE
  1527. + sizeof(*llcHdr) +
  1528. sizeof(qdf_net_vlanhdr_t));
  1529. } else {
  1530. L3datap = hdr_ptr + sizeof(qdf_ether_header_t) +
  1531. sizeof(*llcHdr);
  1532. }
  1533. } else {
  1534. if (ether_type == htons(ETHERTYPE_VLAN)) {
  1535. evh = (qdf_ethervlan_header_t *) eh;
  1536. ether_type = evh->ether_type;
  1537. L3datap = hdr_ptr + sizeof(qdf_ethervlan_header_t);
  1538. }
  1539. }
  1540. /*
  1541. * Find priority from IP TOS DSCP field
  1542. */
  1543. if (qdf_nbuf_is_ipv4_pkt(nbuf)) {
  1544. qdf_net_iphdr_t *ip = (qdf_net_iphdr_t *) L3datap;
  1545. if (qdf_nbuf_is_ipv4_dhcp_pkt(nbuf)) {
  1546. /* Only for unicast frames */
  1547. if (!is_mcast) {
  1548. /* send it on VO queue */
  1549. msdu_info->tid = DP_VO_TID;
  1550. }
  1551. } else {
  1552. /*
  1553. * IP frame: exclude ECN bits 0-1 and map DSCP bits 2-7
  1554. * from TOS byte.
  1555. */
  1556. tos = ip->ip_tos;
  1557. dscp_tid_override = 1;
  1558. }
  1559. } else if (qdf_nbuf_is_ipv6_pkt(nbuf)) {
  1560. /* TODO
  1561. * use flowlabel
  1562. *igmpmld cases to be handled in phase 2
  1563. */
  1564. unsigned long ver_pri_flowlabel;
  1565. unsigned long pri;
  1566. ver_pri_flowlabel = *(unsigned long *) L3datap;
  1567. pri = (ntohl(ver_pri_flowlabel) & IPV6_FLOWINFO_PRIORITY) >>
  1568. DP_IPV6_PRIORITY_SHIFT;
  1569. tos = pri;
  1570. dscp_tid_override = 1;
  1571. } else if (qdf_nbuf_is_ipv4_eapol_pkt(nbuf))
  1572. msdu_info->tid = DP_VO_TID;
  1573. else if (qdf_nbuf_is_ipv4_arp_pkt(nbuf)) {
  1574. /* Only for unicast frames */
  1575. if (!is_mcast) {
  1576. /* send ucast arp on VO queue */
  1577. msdu_info->tid = DP_VO_TID;
  1578. }
  1579. }
  1580. /*
  1581. * Assign all MCAST packets to BE
  1582. */
  1583. if (qdf_unlikely(vdev->tx_encap_type != htt_cmn_pkt_type_raw)) {
  1584. if (is_mcast) {
  1585. tos = 0;
  1586. dscp_tid_override = 1;
  1587. }
  1588. }
  1589. if (dscp_tid_override == 1) {
  1590. tos = (tos >> DP_IP_DSCP_SHIFT) & DP_IP_DSCP_MASK;
  1591. msdu_info->tid = pdev->dscp_tid_map[vdev->dscp_tid_map_id][tos];
  1592. }
  1593. if (msdu_info->tid >= CDP_MAX_DATA_TIDS)
  1594. msdu_info->tid = CDP_MAX_DATA_TIDS - 1;
  1595. return;
  1596. }
  1597. /**
  1598. * dp_tx_classify_tid() - Obtain TID to be used for this frame
  1599. * @vdev: DP vdev handle
  1600. * @nbuf: skb
  1601. *
  1602. * Software based TID classification is required when more than 2 DSCP-TID
  1603. * mapping tables are needed.
  1604. * Hardware supports 2 DSCP-TID mapping tables for HKv1 and 48 for HKv2.
  1605. *
  1606. * Return: void
  1607. */
  1608. static inline void dp_tx_classify_tid(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1609. struct dp_tx_msdu_info_s *msdu_info)
  1610. {
  1611. DP_TX_TID_OVERRIDE(msdu_info, nbuf);
  1612. /*
  1613. * skip_sw_tid_classification flag will set in below cases-
  1614. * 1. vdev->dscp_tid_map_id < pdev->soc->num_hw_dscp_tid_map
  1615. * 2. hlos_tid_override enabled for vdev
  1616. * 3. mesh mode enabled for vdev
  1617. */
  1618. if (qdf_likely(vdev->skip_sw_tid_classification)) {
  1619. /* Update tid in msdu_info from skb priority */
  1620. if (qdf_unlikely(vdev->skip_sw_tid_classification
  1621. & DP_TXRX_HLOS_TID_OVERRIDE_ENABLED)) {
  1622. uint32_t tid = qdf_nbuf_get_priority(nbuf);
  1623. if (tid == DP_TX_INVALID_QOS_TAG)
  1624. return;
  1625. msdu_info->tid = tid;
  1626. return;
  1627. }
  1628. return;
  1629. }
  1630. dp_tx_get_tid(vdev, nbuf, msdu_info);
  1631. }
  1632. #ifdef FEATURE_WLAN_TDLS
  1633. /**
  1634. * dp_tx_update_tdls_flags() - Update descriptor flags for TDLS frame
  1635. * @soc: datapath SOC
  1636. * @vdev: datapath vdev
  1637. * @tx_desc: TX descriptor
  1638. *
  1639. * Return: None
  1640. */
  1641. static void dp_tx_update_tdls_flags(struct dp_soc *soc,
  1642. struct dp_vdev *vdev,
  1643. struct dp_tx_desc_s *tx_desc)
  1644. {
  1645. if (vdev) {
  1646. if (vdev->is_tdls_frame) {
  1647. tx_desc->flags |= DP_TX_DESC_FLAG_TDLS_FRAME;
  1648. vdev->is_tdls_frame = false;
  1649. }
  1650. }
  1651. }
  1652. static uint8_t dp_htt_tx_comp_get_status(struct dp_soc *soc, char *htt_desc)
  1653. {
  1654. uint8_t tx_status = HTT_TX_FW2WBM_TX_STATUS_MAX;
  1655. switch (soc->arch_id) {
  1656. case CDP_ARCH_TYPE_LI:
  1657. tx_status = HTT_TX_WBM_COMPLETION_V2_TX_STATUS_GET(htt_desc[0]);
  1658. break;
  1659. case CDP_ARCH_TYPE_BE:
  1660. tx_status = HTT_TX_WBM_COMPLETION_V3_TX_STATUS_GET(htt_desc[0]);
  1661. break;
  1662. default:
  1663. dp_err("Incorrect CDP_ARCH %d", soc->arch_id);
  1664. QDF_BUG(0);
  1665. }
  1666. return tx_status;
  1667. }
  1668. /**
  1669. * dp_non_std_htt_tx_comp_free_buff() - Free the non std tx packet buffer
  1670. * @soc: dp_soc handle
  1671. * @tx_desc: TX descriptor
  1672. * @vdev: datapath vdev handle
  1673. *
  1674. * Return: None
  1675. */
  1676. static void dp_non_std_htt_tx_comp_free_buff(struct dp_soc *soc,
  1677. struct dp_tx_desc_s *tx_desc)
  1678. {
  1679. uint8_t tx_status = 0;
  1680. uint8_t htt_tx_status[HAL_TX_COMP_HTT_STATUS_LEN];
  1681. qdf_nbuf_t nbuf = tx_desc->nbuf;
  1682. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, tx_desc->vdev_id,
  1683. DP_MOD_ID_TDLS);
  1684. if (qdf_unlikely(!vdev)) {
  1685. dp_err_rl("vdev is null!");
  1686. goto error;
  1687. }
  1688. hal_tx_comp_get_htt_desc(&tx_desc->comp, htt_tx_status);
  1689. tx_status = dp_htt_tx_comp_get_status(soc, htt_tx_status);
  1690. dp_debug("vdev_id: %d tx_status: %d", tx_desc->vdev_id, tx_status);
  1691. if (vdev->tx_non_std_data_callback.func) {
  1692. qdf_nbuf_set_next(nbuf, NULL);
  1693. vdev->tx_non_std_data_callback.func(
  1694. vdev->tx_non_std_data_callback.ctxt,
  1695. nbuf, tx_status);
  1696. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TDLS);
  1697. return;
  1698. } else {
  1699. dp_err_rl("callback func is null");
  1700. }
  1701. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TDLS);
  1702. error:
  1703. qdf_nbuf_unmap_single(soc->osdev, nbuf, QDF_DMA_TO_DEVICE);
  1704. qdf_nbuf_free(nbuf);
  1705. }
  1706. /**
  1707. * dp_tx_msdu_single_map() - do nbuf map
  1708. * @vdev: DP vdev handle
  1709. * @tx_desc: DP TX descriptor pointer
  1710. * @nbuf: skb pointer
  1711. *
  1712. * For TDLS frame, use qdf_nbuf_map_single() to align with the unmap
  1713. * operation done in other component.
  1714. *
  1715. * Return: QDF_STATUS
  1716. */
  1717. static inline QDF_STATUS dp_tx_msdu_single_map(struct dp_vdev *vdev,
  1718. struct dp_tx_desc_s *tx_desc,
  1719. qdf_nbuf_t nbuf)
  1720. {
  1721. if (qdf_likely(!(tx_desc->flags & DP_TX_DESC_FLAG_TDLS_FRAME)))
  1722. return qdf_nbuf_map_nbytes_single(vdev->osdev,
  1723. nbuf,
  1724. QDF_DMA_TO_DEVICE,
  1725. nbuf->len);
  1726. else
  1727. return qdf_nbuf_map_single(vdev->osdev, nbuf,
  1728. QDF_DMA_TO_DEVICE);
  1729. }
  1730. #else
  1731. static inline void dp_tx_update_tdls_flags(struct dp_soc *soc,
  1732. struct dp_vdev *vdev,
  1733. struct dp_tx_desc_s *tx_desc)
  1734. {
  1735. }
  1736. static inline void dp_non_std_htt_tx_comp_free_buff(struct dp_soc *soc,
  1737. struct dp_tx_desc_s *tx_desc)
  1738. {
  1739. }
  1740. static inline QDF_STATUS dp_tx_msdu_single_map(struct dp_vdev *vdev,
  1741. struct dp_tx_desc_s *tx_desc,
  1742. qdf_nbuf_t nbuf)
  1743. {
  1744. return qdf_nbuf_map_nbytes_single(vdev->osdev,
  1745. nbuf,
  1746. QDF_DMA_TO_DEVICE,
  1747. nbuf->len);
  1748. }
  1749. #endif
  1750. static inline
  1751. qdf_dma_addr_t dp_tx_nbuf_map_regular(struct dp_vdev *vdev,
  1752. struct dp_tx_desc_s *tx_desc,
  1753. qdf_nbuf_t nbuf)
  1754. {
  1755. QDF_STATUS ret = QDF_STATUS_E_FAILURE;
  1756. ret = dp_tx_msdu_single_map(vdev, tx_desc, nbuf);
  1757. if (qdf_unlikely(QDF_IS_STATUS_ERROR(ret)))
  1758. return 0;
  1759. return qdf_nbuf_mapped_paddr_get(nbuf);
  1760. }
  1761. static inline
  1762. void dp_tx_nbuf_unmap_regular(struct dp_soc *soc, struct dp_tx_desc_s *desc)
  1763. {
  1764. qdf_nbuf_unmap_nbytes_single_paddr(soc->osdev,
  1765. desc->nbuf,
  1766. desc->dma_addr,
  1767. QDF_DMA_TO_DEVICE,
  1768. desc->length);
  1769. }
  1770. #if defined(QCA_DP_TX_NBUF_NO_MAP_UNMAP) && !defined(BUILD_X86)
  1771. static inline
  1772. qdf_dma_addr_t dp_tx_nbuf_map(struct dp_vdev *vdev,
  1773. struct dp_tx_desc_s *tx_desc,
  1774. qdf_nbuf_t nbuf)
  1775. {
  1776. if (qdf_likely(tx_desc->flags & DP_TX_DESC_FLAG_SIMPLE)) {
  1777. qdf_nbuf_dma_clean_range((void *)nbuf->data,
  1778. (void *)(nbuf->data + nbuf->len));
  1779. return (qdf_dma_addr_t)qdf_mem_virt_to_phys(nbuf->data);
  1780. } else {
  1781. return dp_tx_nbuf_map_regular(vdev, tx_desc, nbuf);
  1782. }
  1783. }
  1784. static inline
  1785. void dp_tx_nbuf_unmap(struct dp_soc *soc,
  1786. struct dp_tx_desc_s *desc)
  1787. {
  1788. if (qdf_unlikely(!(desc->flags & DP_TX_DESC_FLAG_SIMPLE)))
  1789. return dp_tx_nbuf_unmap_regular(soc, desc);
  1790. }
  1791. #else
  1792. static inline
  1793. qdf_dma_addr_t dp_tx_nbuf_map(struct dp_vdev *vdev,
  1794. struct dp_tx_desc_s *tx_desc,
  1795. qdf_nbuf_t nbuf)
  1796. {
  1797. return dp_tx_nbuf_map_regular(vdev, tx_desc, nbuf);
  1798. }
  1799. static inline
  1800. void dp_tx_nbuf_unmap(struct dp_soc *soc,
  1801. struct dp_tx_desc_s *desc)
  1802. {
  1803. return dp_tx_nbuf_unmap_regular(soc, desc);
  1804. }
  1805. #endif
  1806. #if defined(WLAN_TX_PKT_CAPTURE_ENH) || defined(FEATURE_PERPKT_INFO)
  1807. static inline
  1808. void dp_tx_enh_unmap(struct dp_soc *soc, struct dp_tx_desc_s *desc)
  1809. {
  1810. dp_tx_nbuf_unmap(soc, desc);
  1811. desc->flags |= DP_TX_DESC_FLAG_UNMAP_DONE;
  1812. }
  1813. static inline void dp_tx_unmap(struct dp_soc *soc, struct dp_tx_desc_s *desc)
  1814. {
  1815. if (qdf_likely(!(desc->flags & DP_TX_DESC_FLAG_UNMAP_DONE)))
  1816. dp_tx_nbuf_unmap(soc, desc);
  1817. }
  1818. #else
  1819. static inline
  1820. void dp_tx_enh_unmap(struct dp_soc *soc, struct dp_tx_desc_s *desc)
  1821. {
  1822. }
  1823. static inline void dp_tx_unmap(struct dp_soc *soc, struct dp_tx_desc_s *desc)
  1824. {
  1825. dp_tx_nbuf_unmap(soc, desc);
  1826. }
  1827. #endif
  1828. #ifdef MESH_MODE_SUPPORT
  1829. /**
  1830. * dp_tx_update_mesh_flags() - Update descriptor flags for mesh VAP
  1831. * @soc: datapath SOC
  1832. * @vdev: datapath vdev
  1833. * @tx_desc: TX descriptor
  1834. *
  1835. * Return: None
  1836. */
  1837. static inline void dp_tx_update_mesh_flags(struct dp_soc *soc,
  1838. struct dp_vdev *vdev,
  1839. struct dp_tx_desc_s *tx_desc)
  1840. {
  1841. if (qdf_unlikely(vdev->mesh_vdev))
  1842. tx_desc->flags |= DP_TX_DESC_FLAG_MESH_MODE;
  1843. }
  1844. /**
  1845. * dp_mesh_tx_comp_free_buff() - Free the mesh tx packet buffer
  1846. * @soc: dp_soc handle
  1847. * @tx_desc: TX descriptor
  1848. * @delayed_free: delay the nbuf free
  1849. *
  1850. * Return: nbuf to be freed late
  1851. */
  1852. static inline qdf_nbuf_t dp_mesh_tx_comp_free_buff(struct dp_soc *soc,
  1853. struct dp_tx_desc_s *tx_desc,
  1854. bool delayed_free)
  1855. {
  1856. qdf_nbuf_t nbuf = tx_desc->nbuf;
  1857. struct dp_vdev *vdev = NULL;
  1858. vdev = dp_vdev_get_ref_by_id(soc, tx_desc->vdev_id, DP_MOD_ID_MESH);
  1859. if (tx_desc->flags & DP_TX_DESC_FLAG_TO_FW) {
  1860. if (vdev)
  1861. DP_STATS_INC(vdev, tx_i.mesh.completion_fw, 1);
  1862. if (delayed_free)
  1863. return nbuf;
  1864. qdf_nbuf_free(nbuf);
  1865. } else {
  1866. if (vdev && vdev->osif_tx_free_ext) {
  1867. vdev->osif_tx_free_ext((nbuf));
  1868. } else {
  1869. if (delayed_free)
  1870. return nbuf;
  1871. qdf_nbuf_free(nbuf);
  1872. }
  1873. }
  1874. if (vdev)
  1875. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_MESH);
  1876. return NULL;
  1877. }
  1878. #else
  1879. static inline void dp_tx_update_mesh_flags(struct dp_soc *soc,
  1880. struct dp_vdev *vdev,
  1881. struct dp_tx_desc_s *tx_desc)
  1882. {
  1883. }
  1884. static inline qdf_nbuf_t dp_mesh_tx_comp_free_buff(struct dp_soc *soc,
  1885. struct dp_tx_desc_s *tx_desc,
  1886. bool delayed_free)
  1887. {
  1888. return NULL;
  1889. }
  1890. #endif
  1891. /**
  1892. * dp_tx_frame_is_drop() - checks if the packet is loopback
  1893. * @vdev: DP vdev handle
  1894. * @nbuf: skb
  1895. *
  1896. * Return: 1 if frame needs to be dropped else 0
  1897. */
  1898. int dp_tx_frame_is_drop(struct dp_vdev *vdev, uint8_t *srcmac, uint8_t *dstmac)
  1899. {
  1900. struct dp_pdev *pdev = NULL;
  1901. struct dp_ast_entry *src_ast_entry = NULL;
  1902. struct dp_ast_entry *dst_ast_entry = NULL;
  1903. struct dp_soc *soc = NULL;
  1904. qdf_assert(vdev);
  1905. pdev = vdev->pdev;
  1906. qdf_assert(pdev);
  1907. soc = pdev->soc;
  1908. dst_ast_entry = dp_peer_ast_hash_find_by_pdevid
  1909. (soc, dstmac, vdev->pdev->pdev_id);
  1910. src_ast_entry = dp_peer_ast_hash_find_by_pdevid
  1911. (soc, srcmac, vdev->pdev->pdev_id);
  1912. if (dst_ast_entry && src_ast_entry) {
  1913. if (dst_ast_entry->peer_id ==
  1914. src_ast_entry->peer_id)
  1915. return 1;
  1916. }
  1917. return 0;
  1918. }
  1919. #if defined(WLAN_FEATURE_11BE_MLO) && defined(WLAN_MLO_MULTI_CHIP) && \
  1920. defined(WLAN_MCAST_MLO)
  1921. /* MLO peer id for reinject*/
  1922. #define DP_MLO_MCAST_REINJECT_PEER_ID 0XFFFD
  1923. /* MLO vdev id inc offset */
  1924. #define DP_MLO_VDEV_ID_OFFSET 0x80
  1925. static inline void
  1926. dp_tx_bypass_reinjection(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc)
  1927. {
  1928. if (!(tx_desc->flags & DP_TX_DESC_FLAG_TO_FW)) {
  1929. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  1930. qdf_atomic_inc(&soc->num_tx_exception);
  1931. }
  1932. }
  1933. static inline void
  1934. dp_tx_update_mcast_param(uint16_t peer_id,
  1935. uint16_t *htt_tcl_metadata,
  1936. struct dp_vdev *vdev,
  1937. struct dp_tx_msdu_info_s *msdu_info)
  1938. {
  1939. if (peer_id == DP_MLO_MCAST_REINJECT_PEER_ID) {
  1940. *htt_tcl_metadata = 0;
  1941. DP_TX_TCL_METADATA_TYPE_SET(
  1942. *htt_tcl_metadata,
  1943. HTT_TCL_METADATA_V2_TYPE_GLOBAL_SEQ_BASED);
  1944. HTT_TX_TCL_METADATA_GLBL_SEQ_NO_SET(*htt_tcl_metadata,
  1945. msdu_info->gsn);
  1946. msdu_info->vdev_id = vdev->vdev_id + DP_MLO_VDEV_ID_OFFSET;
  1947. if (qdf_unlikely(vdev->nawds_enabled))
  1948. HTT_TX_TCL_METADATA_GLBL_SEQ_HOST_INSPECTED_SET(
  1949. *htt_tcl_metadata, 1);
  1950. } else {
  1951. msdu_info->vdev_id = vdev->vdev_id;
  1952. }
  1953. }
  1954. #else
  1955. static inline void
  1956. dp_tx_bypass_reinjection(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc)
  1957. {
  1958. }
  1959. static inline void
  1960. dp_tx_update_mcast_param(uint16_t peer_id,
  1961. uint16_t *htt_tcl_metadata,
  1962. struct dp_vdev *vdev,
  1963. struct dp_tx_msdu_info_s *msdu_info)
  1964. {
  1965. }
  1966. #endif
  1967. /**
  1968. * dp_tx_send_msdu_single() - Setup descriptor and enqueue single MSDU to TCL
  1969. * @vdev: DP vdev handle
  1970. * @nbuf: skb
  1971. * @tid: TID from HLOS for overriding default DSCP-TID mapping
  1972. * @meta_data: Metadata to the fw
  1973. * @tx_q: Tx queue to be used for this Tx frame
  1974. * @peer_id: peer_id of the peer in case of NAWDS frames
  1975. * @tx_exc_metadata: Handle that holds exception path metadata
  1976. *
  1977. * Return: NULL on success,
  1978. * nbuf when it fails to send
  1979. */
  1980. qdf_nbuf_t
  1981. dp_tx_send_msdu_single(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1982. struct dp_tx_msdu_info_s *msdu_info, uint16_t peer_id,
  1983. struct cdp_tx_exception_metadata *tx_exc_metadata)
  1984. {
  1985. struct dp_pdev *pdev = vdev->pdev;
  1986. struct dp_soc *soc = pdev->soc;
  1987. struct dp_tx_desc_s *tx_desc;
  1988. QDF_STATUS status;
  1989. struct dp_tx_queue *tx_q = &(msdu_info->tx_queue);
  1990. uint16_t htt_tcl_metadata = 0;
  1991. enum cdp_tx_sw_drop drop_code = TX_MAX_DROP;
  1992. uint8_t tid = msdu_info->tid;
  1993. struct cdp_tid_tx_stats *tid_stats = NULL;
  1994. qdf_dma_addr_t paddr;
  1995. /* Setup Tx descriptor for an MSDU, and MSDU extension descriptor */
  1996. tx_desc = dp_tx_prepare_desc_single(vdev, nbuf, tx_q->desc_pool_id,
  1997. msdu_info, tx_exc_metadata);
  1998. if (!tx_desc) {
  1999. dp_err_rl("Tx_desc prepare Fail vdev %pK queue %d",
  2000. vdev, tx_q->desc_pool_id);
  2001. drop_code = TX_DESC_ERR;
  2002. goto fail_return;
  2003. }
  2004. dp_tx_update_tdls_flags(soc, vdev, tx_desc);
  2005. if (qdf_unlikely(peer_id == DP_INVALID_PEER)) {
  2006. htt_tcl_metadata = vdev->htt_tcl_metadata;
  2007. DP_TX_TCL_METADATA_HOST_INSPECTED_SET(htt_tcl_metadata, 1);
  2008. } else if (qdf_unlikely(peer_id != HTT_INVALID_PEER)) {
  2009. DP_TX_TCL_METADATA_TYPE_SET(htt_tcl_metadata,
  2010. DP_TCL_METADATA_TYPE_PEER_BASED);
  2011. DP_TX_TCL_METADATA_PEER_ID_SET(htt_tcl_metadata,
  2012. peer_id);
  2013. dp_tx_bypass_reinjection(soc, tx_desc);
  2014. } else
  2015. htt_tcl_metadata = vdev->htt_tcl_metadata;
  2016. if (msdu_info->exception_fw)
  2017. DP_TX_TCL_METADATA_VALID_HTT_SET(htt_tcl_metadata, 1);
  2018. dp_tx_desc_update_fast_comp_flag(soc, tx_desc,
  2019. !pdev->enhanced_stats_en);
  2020. dp_tx_update_mesh_flags(soc, vdev, tx_desc);
  2021. paddr = dp_tx_nbuf_map(vdev, tx_desc, nbuf);
  2022. if (!paddr) {
  2023. /* Handle failure */
  2024. dp_err("qdf_nbuf_map failed");
  2025. DP_STATS_INC(vdev, tx_i.dropped.dma_error, 1);
  2026. drop_code = TX_DMA_MAP_ERR;
  2027. goto release_desc;
  2028. }
  2029. tx_desc->dma_addr = paddr;
  2030. dp_tx_desc_history_add(soc, tx_desc->dma_addr, nbuf,
  2031. tx_desc->id, DP_TX_DESC_MAP);
  2032. dp_tx_update_mcast_param(peer_id, &htt_tcl_metadata, vdev, msdu_info);
  2033. /* Enqueue the Tx MSDU descriptor to HW for transmit */
  2034. status = soc->arch_ops.tx_hw_enqueue(soc, vdev, tx_desc,
  2035. htt_tcl_metadata,
  2036. tx_exc_metadata, msdu_info);
  2037. if (status != QDF_STATUS_SUCCESS) {
  2038. dp_tx_err_rl("Tx_hw_enqueue Fail tx_desc %pK queue %d",
  2039. tx_desc, tx_q->ring_id);
  2040. dp_tx_desc_history_add(soc, tx_desc->dma_addr, nbuf,
  2041. tx_desc->id, DP_TX_DESC_UNMAP);
  2042. dp_tx_nbuf_unmap(soc, tx_desc);
  2043. drop_code = TX_HW_ENQUEUE;
  2044. goto release_desc;
  2045. }
  2046. return NULL;
  2047. release_desc:
  2048. dp_tx_desc_release(tx_desc, tx_q->desc_pool_id);
  2049. fail_return:
  2050. dp_tx_get_tid(vdev, nbuf, msdu_info);
  2051. tid_stats = &pdev->stats.tid_stats.
  2052. tid_tx_stats[tx_q->ring_id][tid];
  2053. tid_stats->swdrop_cnt[drop_code]++;
  2054. return nbuf;
  2055. }
  2056. /**
  2057. * dp_tx_comp_free_buf() - Free nbuf associated with the Tx Descriptor
  2058. * @soc: Soc handle
  2059. * @desc: software Tx descriptor to be processed
  2060. * @delayed_free: defer freeing of nbuf
  2061. *
  2062. * Return: nbuf to be freed later
  2063. */
  2064. qdf_nbuf_t dp_tx_comp_free_buf(struct dp_soc *soc, struct dp_tx_desc_s *desc,
  2065. bool delayed_free)
  2066. {
  2067. qdf_nbuf_t nbuf = desc->nbuf;
  2068. enum dp_tx_event_type type = dp_tx_get_event_type(desc->flags);
  2069. /* nbuf already freed in vdev detach path */
  2070. if (!nbuf)
  2071. return NULL;
  2072. /* If it is TDLS mgmt, don't unmap or free the frame */
  2073. if (desc->flags & DP_TX_DESC_FLAG_TDLS_FRAME) {
  2074. dp_non_std_htt_tx_comp_free_buff(soc, desc);
  2075. return NULL;
  2076. }
  2077. /* 0 : MSDU buffer, 1 : MLE */
  2078. if (desc->msdu_ext_desc) {
  2079. /* TSO free */
  2080. if (hal_tx_ext_desc_get_tso_enable(
  2081. desc->msdu_ext_desc->vaddr)) {
  2082. dp_tx_desc_history_add(soc, desc->dma_addr, desc->nbuf,
  2083. desc->id, DP_TX_COMP_MSDU_EXT);
  2084. dp_tx_tso_seg_history_add(soc,
  2085. desc->msdu_ext_desc->tso_desc,
  2086. desc->nbuf, desc->id, type);
  2087. /* unmap eash TSO seg before free the nbuf */
  2088. dp_tx_tso_unmap_segment(soc,
  2089. desc->msdu_ext_desc->tso_desc,
  2090. desc->msdu_ext_desc->
  2091. tso_num_desc);
  2092. goto nbuf_free;
  2093. }
  2094. if (qdf_unlikely(desc->frm_type == dp_tx_frm_sg)) {
  2095. void *msdu_ext_desc = desc->msdu_ext_desc->vaddr;
  2096. qdf_dma_addr_t iova;
  2097. uint32_t frag_len;
  2098. uint32_t i;
  2099. qdf_nbuf_unmap_nbytes_single(soc->osdev, nbuf,
  2100. QDF_DMA_TO_DEVICE,
  2101. qdf_nbuf_headlen(nbuf));
  2102. for (i = 1; i < DP_TX_MAX_NUM_FRAGS; i++) {
  2103. hal_tx_ext_desc_get_frag_info(msdu_ext_desc, i,
  2104. &iova,
  2105. &frag_len);
  2106. if (!iova || !frag_len)
  2107. break;
  2108. qdf_mem_unmap_page(soc->osdev, iova, frag_len,
  2109. QDF_DMA_TO_DEVICE);
  2110. }
  2111. goto nbuf_free;
  2112. }
  2113. }
  2114. /* If it's ME frame, dont unmap the cloned nbuf's */
  2115. if ((desc->flags & DP_TX_DESC_FLAG_ME) && qdf_nbuf_is_cloned(nbuf))
  2116. goto nbuf_free;
  2117. dp_tx_desc_history_add(soc, desc->dma_addr, desc->nbuf, desc->id, type);
  2118. dp_tx_unmap(soc, desc);
  2119. if (desc->flags & DP_TX_DESC_FLAG_MESH_MODE)
  2120. return dp_mesh_tx_comp_free_buff(soc, desc, delayed_free);
  2121. if (dp_tx_traffic_end_indication_enq_ind_pkt(soc, desc, nbuf))
  2122. return NULL;
  2123. nbuf_free:
  2124. if (delayed_free)
  2125. return nbuf;
  2126. qdf_nbuf_free(nbuf);
  2127. return NULL;
  2128. }
  2129. /**
  2130. * dp_tx_sg_unmap_buf() - Unmap scatter gather fragments
  2131. * @soc: DP soc handle
  2132. * @nbuf: skb
  2133. * @msdu_info: MSDU info
  2134. *
  2135. * Return: None
  2136. */
  2137. static inline void
  2138. dp_tx_sg_unmap_buf(struct dp_soc *soc, qdf_nbuf_t nbuf,
  2139. struct dp_tx_msdu_info_s *msdu_info)
  2140. {
  2141. uint32_t cur_idx;
  2142. struct dp_tx_seg_info_s *seg = msdu_info->u.sg_info.curr_seg;
  2143. qdf_nbuf_unmap_nbytes_single(soc->osdev, nbuf, QDF_DMA_TO_DEVICE,
  2144. qdf_nbuf_headlen(nbuf));
  2145. for (cur_idx = 1; cur_idx < seg->frag_cnt; cur_idx++)
  2146. qdf_mem_unmap_page(soc->osdev, (qdf_dma_addr_t)
  2147. (seg->frags[cur_idx].paddr_lo | ((uint64_t)
  2148. seg->frags[cur_idx].paddr_hi) << 32),
  2149. seg->frags[cur_idx].len,
  2150. QDF_DMA_TO_DEVICE);
  2151. }
  2152. /**
  2153. * dp_tx_send_msdu_multiple() - Enqueue multiple MSDUs
  2154. * @vdev: DP vdev handle
  2155. * @nbuf: skb
  2156. * @msdu_info: MSDU info to be setup in MSDU extension descriptor
  2157. *
  2158. * Prepare descriptors for multiple MSDUs (TSO segments) and enqueue to TCL
  2159. *
  2160. * Return: NULL on success,
  2161. * nbuf when it fails to send
  2162. */
  2163. #if QDF_LOCK_STATS
  2164. noinline
  2165. #else
  2166. #endif
  2167. qdf_nbuf_t dp_tx_send_msdu_multiple(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  2168. struct dp_tx_msdu_info_s *msdu_info)
  2169. {
  2170. uint32_t i;
  2171. struct dp_pdev *pdev = vdev->pdev;
  2172. struct dp_soc *soc = pdev->soc;
  2173. struct dp_tx_desc_s *tx_desc;
  2174. bool is_cce_classified = false;
  2175. QDF_STATUS status;
  2176. uint16_t htt_tcl_metadata = 0;
  2177. struct dp_tx_queue *tx_q = &msdu_info->tx_queue;
  2178. struct cdp_tid_tx_stats *tid_stats = NULL;
  2179. uint8_t prep_desc_fail = 0, hw_enq_fail = 0;
  2180. if (msdu_info->frm_type == dp_tx_frm_me)
  2181. nbuf = msdu_info->u.sg_info.curr_seg->nbuf;
  2182. i = 0;
  2183. /* Print statement to track i and num_seg */
  2184. /*
  2185. * For each segment (maps to 1 MSDU) , prepare software and hardware
  2186. * descriptors using information in msdu_info
  2187. */
  2188. while (i < msdu_info->num_seg) {
  2189. /*
  2190. * Setup Tx descriptor for an MSDU, and MSDU extension
  2191. * descriptor
  2192. */
  2193. tx_desc = dp_tx_prepare_desc(vdev, nbuf, msdu_info,
  2194. tx_q->desc_pool_id);
  2195. if (!tx_desc) {
  2196. if (msdu_info->frm_type == dp_tx_frm_me) {
  2197. prep_desc_fail++;
  2198. dp_tx_me_free_buf(pdev,
  2199. (void *)(msdu_info->u.sg_info
  2200. .curr_seg->frags[0].vaddr));
  2201. if (prep_desc_fail == msdu_info->num_seg) {
  2202. /*
  2203. * Unmap is needed only if descriptor
  2204. * preparation failed for all segments.
  2205. */
  2206. qdf_nbuf_unmap(soc->osdev,
  2207. msdu_info->u.sg_info.
  2208. curr_seg->nbuf,
  2209. QDF_DMA_TO_DEVICE);
  2210. }
  2211. /*
  2212. * Free the nbuf for the current segment
  2213. * and make it point to the next in the list.
  2214. * For me, there are as many segments as there
  2215. * are no of clients.
  2216. */
  2217. qdf_nbuf_free(msdu_info->u.sg_info
  2218. .curr_seg->nbuf);
  2219. if (msdu_info->u.sg_info.curr_seg->next) {
  2220. msdu_info->u.sg_info.curr_seg =
  2221. msdu_info->u.sg_info
  2222. .curr_seg->next;
  2223. nbuf = msdu_info->u.sg_info
  2224. .curr_seg->nbuf;
  2225. }
  2226. i++;
  2227. continue;
  2228. }
  2229. if (msdu_info->frm_type == dp_tx_frm_tso) {
  2230. dp_tx_tso_seg_history_add(
  2231. soc,
  2232. msdu_info->u.tso_info.curr_seg,
  2233. nbuf, 0, DP_TX_DESC_UNMAP);
  2234. dp_tx_tso_unmap_segment(soc,
  2235. msdu_info->u.tso_info.
  2236. curr_seg,
  2237. msdu_info->u.tso_info.
  2238. tso_num_seg_list);
  2239. if (msdu_info->u.tso_info.curr_seg->next) {
  2240. msdu_info->u.tso_info.curr_seg =
  2241. msdu_info->u.tso_info.curr_seg->next;
  2242. i++;
  2243. continue;
  2244. }
  2245. }
  2246. if (msdu_info->frm_type == dp_tx_frm_sg)
  2247. dp_tx_sg_unmap_buf(soc, nbuf, msdu_info);
  2248. goto done;
  2249. }
  2250. if (msdu_info->frm_type == dp_tx_frm_me) {
  2251. tx_desc->msdu_ext_desc->me_buffer =
  2252. (struct dp_tx_me_buf_t *)msdu_info->
  2253. u.sg_info.curr_seg->frags[0].vaddr;
  2254. tx_desc->flags |= DP_TX_DESC_FLAG_ME;
  2255. }
  2256. if (is_cce_classified)
  2257. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  2258. htt_tcl_metadata = vdev->htt_tcl_metadata;
  2259. if (msdu_info->exception_fw) {
  2260. DP_TX_TCL_METADATA_VALID_HTT_SET(htt_tcl_metadata, 1);
  2261. }
  2262. dp_tx_is_hp_update_required(i, msdu_info);
  2263. /*
  2264. * For frames with multiple segments (TSO, ME), jump to next
  2265. * segment.
  2266. */
  2267. if (msdu_info->frm_type == dp_tx_frm_tso) {
  2268. if (msdu_info->u.tso_info.curr_seg->next) {
  2269. msdu_info->u.tso_info.curr_seg =
  2270. msdu_info->u.tso_info.curr_seg->next;
  2271. /*
  2272. * If this is a jumbo nbuf, then increment the
  2273. * number of nbuf users for each additional
  2274. * segment of the msdu. This will ensure that
  2275. * the skb is freed only after receiving tx
  2276. * completion for all segments of an nbuf
  2277. */
  2278. qdf_nbuf_inc_users(nbuf);
  2279. /* Check with MCL if this is needed */
  2280. /* nbuf = msdu_info->u.tso_info.curr_seg->nbuf;
  2281. */
  2282. }
  2283. }
  2284. dp_tx_update_mcast_param(DP_INVALID_PEER,
  2285. &htt_tcl_metadata,
  2286. vdev,
  2287. msdu_info);
  2288. /*
  2289. * Enqueue the Tx MSDU descriptor to HW for transmit
  2290. */
  2291. status = soc->arch_ops.tx_hw_enqueue(soc, vdev, tx_desc,
  2292. htt_tcl_metadata,
  2293. NULL, msdu_info);
  2294. dp_tx_check_and_flush_hp(soc, status, msdu_info);
  2295. if (status != QDF_STATUS_SUCCESS) {
  2296. dp_info_rl("Tx_hw_enqueue Fail tx_desc %pK queue %d",
  2297. tx_desc, tx_q->ring_id);
  2298. dp_tx_get_tid(vdev, nbuf, msdu_info);
  2299. tid_stats = &pdev->stats.tid_stats.
  2300. tid_tx_stats[tx_q->ring_id][msdu_info->tid];
  2301. tid_stats->swdrop_cnt[TX_HW_ENQUEUE]++;
  2302. if (msdu_info->frm_type == dp_tx_frm_me) {
  2303. hw_enq_fail++;
  2304. if (hw_enq_fail == msdu_info->num_seg) {
  2305. /*
  2306. * Unmap is needed only if enqueue
  2307. * failed for all segments.
  2308. */
  2309. qdf_nbuf_unmap(soc->osdev,
  2310. msdu_info->u.sg_info.
  2311. curr_seg->nbuf,
  2312. QDF_DMA_TO_DEVICE);
  2313. }
  2314. /*
  2315. * Free the nbuf for the current segment
  2316. * and make it point to the next in the list.
  2317. * For me, there are as many segments as there
  2318. * are no of clients.
  2319. */
  2320. qdf_nbuf_free(msdu_info->u.sg_info
  2321. .curr_seg->nbuf);
  2322. dp_tx_desc_release(tx_desc, tx_q->desc_pool_id);
  2323. if (msdu_info->u.sg_info.curr_seg->next) {
  2324. msdu_info->u.sg_info.curr_seg =
  2325. msdu_info->u.sg_info
  2326. .curr_seg->next;
  2327. nbuf = msdu_info->u.sg_info
  2328. .curr_seg->nbuf;
  2329. } else
  2330. break;
  2331. i++;
  2332. continue;
  2333. }
  2334. /*
  2335. * For TSO frames, the nbuf users increment done for
  2336. * the current segment has to be reverted, since the
  2337. * hw enqueue for this segment failed
  2338. */
  2339. if (msdu_info->frm_type == dp_tx_frm_tso &&
  2340. msdu_info->u.tso_info.curr_seg) {
  2341. /*
  2342. * unmap and free current,
  2343. * retransmit remaining segments
  2344. */
  2345. dp_tx_comp_free_buf(soc, tx_desc, false);
  2346. i++;
  2347. dp_tx_desc_release(tx_desc, tx_q->desc_pool_id);
  2348. continue;
  2349. }
  2350. if (msdu_info->frm_type == dp_tx_frm_sg)
  2351. dp_tx_sg_unmap_buf(soc, nbuf, msdu_info);
  2352. dp_tx_desc_release(tx_desc, tx_q->desc_pool_id);
  2353. goto done;
  2354. }
  2355. /*
  2356. * TODO
  2357. * if tso_info structure can be modified to have curr_seg
  2358. * as first element, following 2 blocks of code (for TSO and SG)
  2359. * can be combined into 1
  2360. */
  2361. /*
  2362. * For Multicast-Unicast converted packets,
  2363. * each converted frame (for a client) is represented as
  2364. * 1 segment
  2365. */
  2366. if ((msdu_info->frm_type == dp_tx_frm_sg) ||
  2367. (msdu_info->frm_type == dp_tx_frm_me)) {
  2368. if (msdu_info->u.sg_info.curr_seg->next) {
  2369. msdu_info->u.sg_info.curr_seg =
  2370. msdu_info->u.sg_info.curr_seg->next;
  2371. nbuf = msdu_info->u.sg_info.curr_seg->nbuf;
  2372. } else
  2373. break;
  2374. }
  2375. i++;
  2376. }
  2377. nbuf = NULL;
  2378. done:
  2379. return nbuf;
  2380. }
  2381. /**
  2382. * dp_tx_prepare_sg()- Extract SG info from NBUF and prepare msdu_info
  2383. * for SG frames
  2384. * @vdev: DP vdev handle
  2385. * @nbuf: skb
  2386. * @seg_info: Pointer to Segment info Descriptor to be prepared
  2387. * @msdu_info: MSDU info to be setup in MSDU descriptor and MSDU extension desc.
  2388. *
  2389. * Return: NULL on success,
  2390. * nbuf when it fails to send
  2391. */
  2392. static qdf_nbuf_t dp_tx_prepare_sg(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  2393. struct dp_tx_seg_info_s *seg_info, struct dp_tx_msdu_info_s *msdu_info)
  2394. {
  2395. uint32_t cur_frag, nr_frags, i;
  2396. qdf_dma_addr_t paddr;
  2397. struct dp_tx_sg_info_s *sg_info;
  2398. sg_info = &msdu_info->u.sg_info;
  2399. nr_frags = qdf_nbuf_get_nr_frags(nbuf);
  2400. if (QDF_STATUS_SUCCESS !=
  2401. qdf_nbuf_map_nbytes_single(vdev->osdev, nbuf,
  2402. QDF_DMA_TO_DEVICE,
  2403. qdf_nbuf_headlen(nbuf))) {
  2404. dp_tx_err("dma map error");
  2405. DP_STATS_INC(vdev, tx_i.sg.dma_map_error, 1);
  2406. qdf_nbuf_free(nbuf);
  2407. return NULL;
  2408. }
  2409. paddr = qdf_nbuf_mapped_paddr_get(nbuf);
  2410. seg_info->frags[0].paddr_lo = paddr;
  2411. seg_info->frags[0].paddr_hi = ((uint64_t) paddr) >> 32;
  2412. seg_info->frags[0].len = qdf_nbuf_headlen(nbuf);
  2413. seg_info->frags[0].vaddr = (void *) nbuf;
  2414. for (cur_frag = 0; cur_frag < nr_frags; cur_frag++) {
  2415. if (QDF_STATUS_SUCCESS != qdf_nbuf_frag_map(vdev->osdev,
  2416. nbuf, 0,
  2417. QDF_DMA_TO_DEVICE,
  2418. cur_frag)) {
  2419. dp_tx_err("frag dma map error");
  2420. DP_STATS_INC(vdev, tx_i.sg.dma_map_error, 1);
  2421. goto map_err;
  2422. }
  2423. paddr = qdf_nbuf_get_tx_frag_paddr(nbuf);
  2424. seg_info->frags[cur_frag + 1].paddr_lo = paddr;
  2425. seg_info->frags[cur_frag + 1].paddr_hi =
  2426. ((uint64_t) paddr) >> 32;
  2427. seg_info->frags[cur_frag + 1].len =
  2428. qdf_nbuf_get_frag_size(nbuf, cur_frag);
  2429. }
  2430. seg_info->frag_cnt = (cur_frag + 1);
  2431. seg_info->total_len = qdf_nbuf_len(nbuf);
  2432. seg_info->next = NULL;
  2433. sg_info->curr_seg = seg_info;
  2434. msdu_info->frm_type = dp_tx_frm_sg;
  2435. msdu_info->num_seg = 1;
  2436. return nbuf;
  2437. map_err:
  2438. /* restore paddr into nbuf before calling unmap */
  2439. qdf_nbuf_mapped_paddr_set(nbuf,
  2440. (qdf_dma_addr_t)(seg_info->frags[0].paddr_lo |
  2441. ((uint64_t)
  2442. seg_info->frags[0].paddr_hi) << 32));
  2443. qdf_nbuf_unmap_nbytes_single(vdev->osdev, nbuf,
  2444. QDF_DMA_TO_DEVICE,
  2445. seg_info->frags[0].len);
  2446. for (i = 1; i <= cur_frag; i++) {
  2447. qdf_mem_unmap_page(vdev->osdev, (qdf_dma_addr_t)
  2448. (seg_info->frags[i].paddr_lo | ((uint64_t)
  2449. seg_info->frags[i].paddr_hi) << 32),
  2450. seg_info->frags[i].len,
  2451. QDF_DMA_TO_DEVICE);
  2452. }
  2453. qdf_nbuf_free(nbuf);
  2454. return NULL;
  2455. }
  2456. /**
  2457. * dp_tx_add_tx_sniffer_meta_data()- Add tx_sniffer meta hdr info
  2458. * @vdev: DP vdev handle
  2459. * @msdu_info: MSDU info to be setup in MSDU descriptor and MSDU extension desc.
  2460. * @ppdu_cookie: PPDU cookie that should be replayed in the ppdu completions
  2461. *
  2462. * Return: NULL on failure,
  2463. * nbuf when extracted successfully
  2464. */
  2465. static
  2466. void dp_tx_add_tx_sniffer_meta_data(struct dp_vdev *vdev,
  2467. struct dp_tx_msdu_info_s *msdu_info,
  2468. uint16_t ppdu_cookie)
  2469. {
  2470. struct htt_tx_msdu_desc_ext2_t *meta_data =
  2471. (struct htt_tx_msdu_desc_ext2_t *)&msdu_info->meta_data[0];
  2472. qdf_mem_zero(meta_data, sizeof(struct htt_tx_msdu_desc_ext2_t));
  2473. HTT_TX_MSDU_EXT2_DESC_FLAG_SEND_AS_STANDALONE_SET
  2474. (msdu_info->meta_data[5], 1);
  2475. HTT_TX_MSDU_EXT2_DESC_FLAG_HOST_OPAQUE_VALID_SET
  2476. (msdu_info->meta_data[5], 1);
  2477. HTT_TX_MSDU_EXT2_DESC_HOST_OPAQUE_COOKIE_SET
  2478. (msdu_info->meta_data[6], ppdu_cookie);
  2479. msdu_info->exception_fw = 1;
  2480. msdu_info->is_tx_sniffer = 1;
  2481. }
  2482. #ifdef MESH_MODE_SUPPORT
  2483. /**
  2484. * dp_tx_extract_mesh_meta_data()- Extract mesh meta hdr info from nbuf
  2485. and prepare msdu_info for mesh frames.
  2486. * @vdev: DP vdev handle
  2487. * @nbuf: skb
  2488. * @msdu_info: MSDU info to be setup in MSDU descriptor and MSDU extension desc.
  2489. *
  2490. * Return: NULL on failure,
  2491. * nbuf when extracted successfully
  2492. */
  2493. static
  2494. qdf_nbuf_t dp_tx_extract_mesh_meta_data(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  2495. struct dp_tx_msdu_info_s *msdu_info)
  2496. {
  2497. struct meta_hdr_s *mhdr;
  2498. struct htt_tx_msdu_desc_ext2_t *meta_data =
  2499. (struct htt_tx_msdu_desc_ext2_t *)&msdu_info->meta_data[0];
  2500. mhdr = (struct meta_hdr_s *)qdf_nbuf_data(nbuf);
  2501. if (CB_FTYPE_MESH_TX_INFO != qdf_nbuf_get_tx_ftype(nbuf)) {
  2502. msdu_info->exception_fw = 0;
  2503. goto remove_meta_hdr;
  2504. }
  2505. msdu_info->exception_fw = 1;
  2506. qdf_mem_zero(meta_data, sizeof(struct htt_tx_msdu_desc_ext2_t));
  2507. meta_data->host_tx_desc_pool = 1;
  2508. meta_data->update_peer_cache = 1;
  2509. meta_data->learning_frame = 1;
  2510. if (!(mhdr->flags & METAHDR_FLAG_AUTO_RATE)) {
  2511. meta_data->power = mhdr->power;
  2512. meta_data->mcs_mask = 1 << mhdr->rate_info[0].mcs;
  2513. meta_data->nss_mask = 1 << mhdr->rate_info[0].nss;
  2514. meta_data->pream_type = mhdr->rate_info[0].preamble_type;
  2515. meta_data->retry_limit = mhdr->rate_info[0].max_tries;
  2516. meta_data->dyn_bw = 1;
  2517. meta_data->valid_pwr = 1;
  2518. meta_data->valid_mcs_mask = 1;
  2519. meta_data->valid_nss_mask = 1;
  2520. meta_data->valid_preamble_type = 1;
  2521. meta_data->valid_retries = 1;
  2522. meta_data->valid_bw_info = 1;
  2523. }
  2524. if (mhdr->flags & METAHDR_FLAG_NOENCRYPT) {
  2525. meta_data->encrypt_type = 0;
  2526. meta_data->valid_encrypt_type = 1;
  2527. meta_data->learning_frame = 0;
  2528. }
  2529. meta_data->valid_key_flags = 1;
  2530. meta_data->key_flags = (mhdr->keyix & 0x3);
  2531. remove_meta_hdr:
  2532. if (qdf_nbuf_pull_head(nbuf, sizeof(struct meta_hdr_s)) == NULL) {
  2533. dp_tx_err("qdf_nbuf_pull_head failed");
  2534. qdf_nbuf_free(nbuf);
  2535. return NULL;
  2536. }
  2537. msdu_info->tid = qdf_nbuf_get_priority(nbuf);
  2538. dp_tx_info("Meta hdr %0x %0x %0x %0x %0x %0x"
  2539. " tid %d to_fw %d",
  2540. msdu_info->meta_data[0],
  2541. msdu_info->meta_data[1],
  2542. msdu_info->meta_data[2],
  2543. msdu_info->meta_data[3],
  2544. msdu_info->meta_data[4],
  2545. msdu_info->meta_data[5],
  2546. msdu_info->tid, msdu_info->exception_fw);
  2547. return nbuf;
  2548. }
  2549. #else
  2550. static
  2551. qdf_nbuf_t dp_tx_extract_mesh_meta_data(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  2552. struct dp_tx_msdu_info_s *msdu_info)
  2553. {
  2554. return nbuf;
  2555. }
  2556. #endif
  2557. /**
  2558. * dp_check_exc_metadata() - Checks if parameters are valid
  2559. * @tx_exc - holds all exception path parameters
  2560. *
  2561. * Returns true when all the parameters are valid else false
  2562. *
  2563. */
  2564. static bool dp_check_exc_metadata(struct cdp_tx_exception_metadata *tx_exc)
  2565. {
  2566. bool invalid_tid = (tx_exc->tid >= DP_MAX_TIDS && tx_exc->tid !=
  2567. HTT_INVALID_TID);
  2568. bool invalid_encap_type =
  2569. (tx_exc->tx_encap_type > htt_cmn_pkt_num_types &&
  2570. tx_exc->tx_encap_type != CDP_INVALID_TX_ENCAP_TYPE);
  2571. bool invalid_sec_type = (tx_exc->sec_type > cdp_num_sec_types &&
  2572. tx_exc->sec_type != CDP_INVALID_SEC_TYPE);
  2573. bool invalid_cookie = (tx_exc->is_tx_sniffer == 1 &&
  2574. tx_exc->ppdu_cookie == 0);
  2575. if (tx_exc->is_intrabss_fwd)
  2576. return true;
  2577. if (invalid_tid || invalid_encap_type || invalid_sec_type ||
  2578. invalid_cookie) {
  2579. return false;
  2580. }
  2581. return true;
  2582. }
  2583. #ifdef ATH_SUPPORT_IQUE
  2584. /**
  2585. * dp_tx_mcast_enhance() - Multicast enhancement on TX
  2586. * @vdev: vdev handle
  2587. * @nbuf: skb
  2588. *
  2589. * Return: true on success,
  2590. * false on failure
  2591. */
  2592. static inline bool dp_tx_mcast_enhance(struct dp_vdev *vdev, qdf_nbuf_t nbuf)
  2593. {
  2594. qdf_ether_header_t *eh;
  2595. /* Mcast to Ucast Conversion*/
  2596. if (qdf_likely(!vdev->mcast_enhancement_en))
  2597. return true;
  2598. eh = (qdf_ether_header_t *)qdf_nbuf_data(nbuf);
  2599. if (DP_FRAME_IS_MULTICAST((eh)->ether_dhost) &&
  2600. !DP_FRAME_IS_BROADCAST((eh)->ether_dhost)) {
  2601. dp_verbose_debug("Mcast frm for ME %pK", vdev);
  2602. qdf_nbuf_set_next(nbuf, NULL);
  2603. DP_STATS_INC_PKT(vdev, tx_i.mcast_en.mcast_pkt, 1,
  2604. qdf_nbuf_len(nbuf));
  2605. if (dp_tx_prepare_send_me(vdev, nbuf) ==
  2606. QDF_STATUS_SUCCESS) {
  2607. return false;
  2608. }
  2609. if (qdf_unlikely(vdev->igmp_mcast_enhanc_en > 0)) {
  2610. if (dp_tx_prepare_send_igmp_me(vdev, nbuf) ==
  2611. QDF_STATUS_SUCCESS) {
  2612. return false;
  2613. }
  2614. }
  2615. }
  2616. return true;
  2617. }
  2618. #else
  2619. static inline bool dp_tx_mcast_enhance(struct dp_vdev *vdev, qdf_nbuf_t nbuf)
  2620. {
  2621. return true;
  2622. }
  2623. #endif
  2624. /**
  2625. * dp_tx_per_pkt_vdev_id_check() - vdev id check for frame
  2626. * @nbuf: qdf_nbuf_t
  2627. * @vdev: struct dp_vdev *
  2628. *
  2629. * Allow packet for processing only if it is for peer client which is
  2630. * connected with same vap. Drop packet if client is connected to
  2631. * different vap.
  2632. *
  2633. * Return: QDF_STATUS
  2634. */
  2635. static inline QDF_STATUS
  2636. dp_tx_per_pkt_vdev_id_check(qdf_nbuf_t nbuf, struct dp_vdev *vdev)
  2637. {
  2638. struct dp_ast_entry *dst_ast_entry = NULL;
  2639. qdf_ether_header_t *eh = (qdf_ether_header_t *)qdf_nbuf_data(nbuf);
  2640. if (DP_FRAME_IS_MULTICAST((eh)->ether_dhost) ||
  2641. DP_FRAME_IS_BROADCAST((eh)->ether_dhost))
  2642. return QDF_STATUS_SUCCESS;
  2643. qdf_spin_lock_bh(&vdev->pdev->soc->ast_lock);
  2644. dst_ast_entry = dp_peer_ast_hash_find_by_vdevid(vdev->pdev->soc,
  2645. eh->ether_dhost,
  2646. vdev->vdev_id);
  2647. /* If there is no ast entry, return failure */
  2648. if (qdf_unlikely(!dst_ast_entry)) {
  2649. qdf_spin_unlock_bh(&vdev->pdev->soc->ast_lock);
  2650. return QDF_STATUS_E_FAILURE;
  2651. }
  2652. qdf_spin_unlock_bh(&vdev->pdev->soc->ast_lock);
  2653. return QDF_STATUS_SUCCESS;
  2654. }
  2655. /**
  2656. * dp_tx_nawds_handler() - NAWDS handler
  2657. *
  2658. * @soc: DP soc handle
  2659. * @vdev_id: id of DP vdev handle
  2660. * @msdu_info: msdu_info required to create HTT metadata
  2661. * @nbuf: skb
  2662. *
  2663. * This API transfers the multicast frames with the peer id
  2664. * on NAWDS enabled peer.
  2665. * Return: none
  2666. */
  2667. static inline
  2668. void dp_tx_nawds_handler(struct dp_soc *soc, struct dp_vdev *vdev,
  2669. struct dp_tx_msdu_info_s *msdu_info,
  2670. qdf_nbuf_t nbuf, uint16_t sa_peer_id)
  2671. {
  2672. struct dp_peer *peer = NULL;
  2673. qdf_nbuf_t nbuf_clone = NULL;
  2674. uint16_t peer_id = DP_INVALID_PEER;
  2675. struct dp_txrx_peer *txrx_peer;
  2676. /* This check avoids pkt forwarding which is entered
  2677. * in the ast table but still doesn't have valid peerid.
  2678. */
  2679. if (sa_peer_id == HTT_INVALID_PEER)
  2680. return;
  2681. qdf_spin_lock_bh(&vdev->peer_list_lock);
  2682. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  2683. txrx_peer = dp_get_txrx_peer(peer);
  2684. if (!txrx_peer)
  2685. continue;
  2686. if (!txrx_peer->bss_peer && txrx_peer->nawds_enabled) {
  2687. peer_id = peer->peer_id;
  2688. if (!dp_peer_is_primary_link_peer(peer))
  2689. continue;
  2690. /* Multicast packets needs to be
  2691. * dropped in case of intra bss forwarding
  2692. */
  2693. if (sa_peer_id == txrx_peer->peer_id) {
  2694. dp_tx_debug("multicast packet");
  2695. DP_PEER_PER_PKT_STATS_INC(txrx_peer,
  2696. tx.nawds_mcast_drop,
  2697. 1);
  2698. continue;
  2699. }
  2700. nbuf_clone = qdf_nbuf_clone(nbuf);
  2701. if (!nbuf_clone) {
  2702. QDF_TRACE(QDF_MODULE_ID_DP,
  2703. QDF_TRACE_LEVEL_ERROR,
  2704. FL("nbuf clone failed"));
  2705. break;
  2706. }
  2707. nbuf_clone = dp_tx_send_msdu_single(vdev, nbuf_clone,
  2708. msdu_info, peer_id,
  2709. NULL);
  2710. if (nbuf_clone) {
  2711. dp_tx_debug("pkt send failed");
  2712. qdf_nbuf_free(nbuf_clone);
  2713. } else {
  2714. if (peer_id != DP_INVALID_PEER)
  2715. DP_PEER_PER_PKT_STATS_INC_PKT(txrx_peer,
  2716. tx.nawds_mcast,
  2717. 1, qdf_nbuf_len(nbuf));
  2718. }
  2719. }
  2720. }
  2721. qdf_spin_unlock_bh(&vdev->peer_list_lock);
  2722. }
  2723. /**
  2724. * dp_tx_send_exception() - Transmit a frame on a given VAP in exception path
  2725. * @soc: DP soc handle
  2726. * @vdev_id: id of DP vdev handle
  2727. * @nbuf: skb
  2728. * @tx_exc_metadata: Handle that holds exception path meta data
  2729. *
  2730. * Entry point for Core Tx layer (DP_TX) invoked from
  2731. * hard_start_xmit in OSIF/HDD to transmit frames through fw
  2732. *
  2733. * Return: NULL on success,
  2734. * nbuf when it fails to send
  2735. */
  2736. qdf_nbuf_t
  2737. dp_tx_send_exception(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  2738. qdf_nbuf_t nbuf,
  2739. struct cdp_tx_exception_metadata *tx_exc_metadata)
  2740. {
  2741. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  2742. qdf_ether_header_t *eh = NULL;
  2743. struct dp_tx_msdu_info_s msdu_info;
  2744. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  2745. DP_MOD_ID_TX_EXCEPTION);
  2746. if (qdf_unlikely(!vdev))
  2747. goto fail;
  2748. qdf_mem_zero(&msdu_info, sizeof(msdu_info));
  2749. if (!tx_exc_metadata)
  2750. goto fail;
  2751. msdu_info.tid = tx_exc_metadata->tid;
  2752. eh = (qdf_ether_header_t *)qdf_nbuf_data(nbuf);
  2753. dp_verbose_debug("skb "QDF_MAC_ADDR_FMT,
  2754. QDF_MAC_ADDR_REF(nbuf->data));
  2755. DP_STATS_INC_PKT(vdev, tx_i.rcvd, 1, qdf_nbuf_len(nbuf));
  2756. if (qdf_unlikely(!dp_check_exc_metadata(tx_exc_metadata))) {
  2757. dp_tx_err("Invalid parameters in exception path");
  2758. goto fail;
  2759. }
  2760. /* Basic sanity checks for unsupported packets */
  2761. /* MESH mode */
  2762. if (qdf_unlikely(vdev->mesh_vdev)) {
  2763. dp_tx_err("Mesh mode is not supported in exception path");
  2764. goto fail;
  2765. }
  2766. /*
  2767. * Classify the frame and call corresponding
  2768. * "prepare" function which extracts the segment (TSO)
  2769. * and fragmentation information (for TSO , SG, ME, or Raw)
  2770. * into MSDU_INFO structure which is later used to fill
  2771. * SW and HW descriptors.
  2772. */
  2773. if (qdf_nbuf_is_tso(nbuf)) {
  2774. dp_verbose_debug("TSO frame %pK", vdev);
  2775. DP_STATS_INC_PKT(vdev->pdev, tso_stats.num_tso_pkts, 1,
  2776. qdf_nbuf_len(nbuf));
  2777. if (dp_tx_prepare_tso(vdev, nbuf, &msdu_info)) {
  2778. DP_STATS_INC_PKT(vdev->pdev, tso_stats.dropped_host, 1,
  2779. qdf_nbuf_len(nbuf));
  2780. goto fail;
  2781. }
  2782. goto send_multiple;
  2783. }
  2784. /* SG */
  2785. if (qdf_unlikely(qdf_nbuf_is_nonlinear(nbuf))) {
  2786. struct dp_tx_seg_info_s seg_info = {0};
  2787. nbuf = dp_tx_prepare_sg(vdev, nbuf, &seg_info, &msdu_info);
  2788. if (!nbuf)
  2789. goto fail;
  2790. dp_verbose_debug("non-TSO SG frame %pK", vdev);
  2791. DP_STATS_INC_PKT(vdev, tx_i.sg.sg_pkt, 1,
  2792. qdf_nbuf_len(nbuf));
  2793. goto send_multiple;
  2794. }
  2795. if (qdf_likely(tx_exc_metadata->is_tx_sniffer)) {
  2796. DP_STATS_INC_PKT(vdev, tx_i.sniffer_rcvd, 1,
  2797. qdf_nbuf_len(nbuf));
  2798. dp_tx_add_tx_sniffer_meta_data(vdev, &msdu_info,
  2799. tx_exc_metadata->ppdu_cookie);
  2800. }
  2801. /*
  2802. * Get HW Queue to use for this frame.
  2803. * TCL supports upto 4 DMA rings, out of which 3 rings are
  2804. * dedicated for data and 1 for command.
  2805. * "queue_id" maps to one hardware ring.
  2806. * With each ring, we also associate a unique Tx descriptor pool
  2807. * to minimize lock contention for these resources.
  2808. */
  2809. dp_tx_get_queue(vdev, nbuf, &msdu_info.tx_queue);
  2810. if (qdf_likely(tx_exc_metadata->is_intrabss_fwd)) {
  2811. if (qdf_unlikely(vdev->nawds_enabled)) {
  2812. /*
  2813. * This is a multicast packet
  2814. */
  2815. dp_tx_nawds_handler(soc, vdev, &msdu_info, nbuf,
  2816. tx_exc_metadata->peer_id);
  2817. DP_STATS_INC_PKT(vdev, tx_i.nawds_mcast,
  2818. 1, qdf_nbuf_len(nbuf));
  2819. }
  2820. nbuf = dp_tx_send_msdu_single(vdev, nbuf, &msdu_info,
  2821. DP_INVALID_PEER, NULL);
  2822. } else {
  2823. /*
  2824. * Check exception descriptors
  2825. */
  2826. if (dp_tx_exception_limit_check(vdev))
  2827. goto fail;
  2828. /* Single linear frame */
  2829. /*
  2830. * If nbuf is a simple linear frame, use send_single function to
  2831. * prepare direct-buffer type TCL descriptor and enqueue to TCL
  2832. * SRNG. There is no need to setup a MSDU extension descriptor.
  2833. */
  2834. nbuf = dp_tx_send_msdu_single(vdev, nbuf, &msdu_info,
  2835. tx_exc_metadata->peer_id,
  2836. tx_exc_metadata);
  2837. }
  2838. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TX_EXCEPTION);
  2839. return nbuf;
  2840. send_multiple:
  2841. nbuf = dp_tx_send_msdu_multiple(vdev, nbuf, &msdu_info);
  2842. fail:
  2843. if (vdev)
  2844. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TX_EXCEPTION);
  2845. dp_verbose_debug("pkt send failed");
  2846. return nbuf;
  2847. }
  2848. /**
  2849. * dp_tx_send_exception_vdev_id_check() - Transmit a frame on a given VAP
  2850. * in exception path in special case to avoid regular exception path chk.
  2851. * @soc: DP soc handle
  2852. * @vdev_id: id of DP vdev handle
  2853. * @nbuf: skb
  2854. * @tx_exc_metadata: Handle that holds exception path meta data
  2855. *
  2856. * Entry point for Core Tx layer (DP_TX) invoked from
  2857. * hard_start_xmit in OSIF/HDD to transmit frames through fw
  2858. *
  2859. * Return: NULL on success,
  2860. * nbuf when it fails to send
  2861. */
  2862. qdf_nbuf_t
  2863. dp_tx_send_exception_vdev_id_check(struct cdp_soc_t *soc_hdl,
  2864. uint8_t vdev_id, qdf_nbuf_t nbuf,
  2865. struct cdp_tx_exception_metadata *tx_exc_metadata)
  2866. {
  2867. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  2868. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  2869. DP_MOD_ID_TX_EXCEPTION);
  2870. if (qdf_unlikely(!vdev))
  2871. goto fail;
  2872. if (qdf_unlikely(dp_tx_per_pkt_vdev_id_check(nbuf, vdev)
  2873. == QDF_STATUS_E_FAILURE)) {
  2874. DP_STATS_INC(vdev, tx_i.dropped.fail_per_pkt_vdev_id_check, 1);
  2875. goto fail;
  2876. }
  2877. /* Unref count as it will agin be taken inside dp_tx_exception */
  2878. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TX_EXCEPTION);
  2879. return dp_tx_send_exception(soc_hdl, vdev_id, nbuf, tx_exc_metadata);
  2880. fail:
  2881. if (vdev)
  2882. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TX_EXCEPTION);
  2883. dp_verbose_debug("pkt send failed");
  2884. return nbuf;
  2885. }
  2886. /**
  2887. * dp_tx_send_mesh() - Transmit mesh frame on a given VAP
  2888. * @soc: DP soc handle
  2889. * @vdev_id: DP vdev handle
  2890. * @nbuf: skb
  2891. *
  2892. * Entry point for Core Tx layer (DP_TX) invoked from
  2893. * hard_start_xmit in OSIF/HDD
  2894. *
  2895. * Return: NULL on success,
  2896. * nbuf when it fails to send
  2897. */
  2898. #ifdef MESH_MODE_SUPPORT
  2899. qdf_nbuf_t dp_tx_send_mesh(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  2900. qdf_nbuf_t nbuf)
  2901. {
  2902. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  2903. struct meta_hdr_s *mhdr;
  2904. qdf_nbuf_t nbuf_mesh = NULL;
  2905. qdf_nbuf_t nbuf_clone = NULL;
  2906. struct dp_vdev *vdev;
  2907. uint8_t no_enc_frame = 0;
  2908. nbuf_mesh = qdf_nbuf_unshare(nbuf);
  2909. if (!nbuf_mesh) {
  2910. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2911. "qdf_nbuf_unshare failed");
  2912. return nbuf;
  2913. }
  2914. vdev = dp_vdev_get_ref_by_id(soc, vdev_id, DP_MOD_ID_MESH);
  2915. if (!vdev) {
  2916. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2917. "vdev is NULL for vdev_id %d", vdev_id);
  2918. return nbuf;
  2919. }
  2920. nbuf = nbuf_mesh;
  2921. mhdr = (struct meta_hdr_s *)qdf_nbuf_data(nbuf);
  2922. if ((vdev->sec_type != cdp_sec_type_none) &&
  2923. (mhdr->flags & METAHDR_FLAG_NOENCRYPT))
  2924. no_enc_frame = 1;
  2925. if (mhdr->flags & METAHDR_FLAG_NOQOS)
  2926. qdf_nbuf_set_priority(nbuf, HTT_TX_EXT_TID_NON_QOS_MCAST_BCAST);
  2927. if ((mhdr->flags & METAHDR_FLAG_INFO_UPDATED) &&
  2928. !no_enc_frame) {
  2929. nbuf_clone = qdf_nbuf_clone(nbuf);
  2930. if (!nbuf_clone) {
  2931. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2932. "qdf_nbuf_clone failed");
  2933. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_MESH);
  2934. return nbuf;
  2935. }
  2936. qdf_nbuf_set_tx_ftype(nbuf_clone, CB_FTYPE_MESH_TX_INFO);
  2937. }
  2938. if (nbuf_clone) {
  2939. if (!dp_tx_send(soc_hdl, vdev_id, nbuf_clone)) {
  2940. DP_STATS_INC(vdev, tx_i.mesh.exception_fw, 1);
  2941. } else {
  2942. qdf_nbuf_free(nbuf_clone);
  2943. }
  2944. }
  2945. if (no_enc_frame)
  2946. qdf_nbuf_set_tx_ftype(nbuf, CB_FTYPE_MESH_TX_INFO);
  2947. else
  2948. qdf_nbuf_set_tx_ftype(nbuf, CB_FTYPE_INVALID);
  2949. nbuf = dp_tx_send(soc_hdl, vdev_id, nbuf);
  2950. if ((!nbuf) && no_enc_frame) {
  2951. DP_STATS_INC(vdev, tx_i.mesh.exception_fw, 1);
  2952. }
  2953. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_MESH);
  2954. return nbuf;
  2955. }
  2956. #else
  2957. qdf_nbuf_t dp_tx_send_mesh(struct cdp_soc_t *soc, uint8_t vdev_id,
  2958. qdf_nbuf_t nbuf)
  2959. {
  2960. return dp_tx_send(soc, vdev_id, nbuf);
  2961. }
  2962. #endif
  2963. #ifdef QCA_DP_TX_NBUF_AND_NBUF_DATA_PREFETCH
  2964. static inline
  2965. void dp_tx_prefetch_nbuf_data(qdf_nbuf_t nbuf)
  2966. {
  2967. if (nbuf) {
  2968. qdf_prefetch(&nbuf->len);
  2969. qdf_prefetch(&nbuf->data);
  2970. }
  2971. }
  2972. #else
  2973. static inline
  2974. void dp_tx_prefetch_nbuf_data(qdf_nbuf_t nbuf)
  2975. {
  2976. }
  2977. #endif
  2978. #ifdef DP_UMAC_HW_RESET_SUPPORT
  2979. /*
  2980. * dp_tx_drop() - Drop the frame on a given VAP
  2981. * @soc: DP soc handle
  2982. * @vdev_id: id of DP vdev handle
  2983. * @nbuf: skb
  2984. *
  2985. * Drop all the incoming packets
  2986. *
  2987. * Return: nbuf
  2988. *
  2989. */
  2990. qdf_nbuf_t dp_tx_drop(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  2991. qdf_nbuf_t nbuf)
  2992. {
  2993. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  2994. struct dp_vdev *vdev = NULL;
  2995. vdev = soc->vdev_id_map[vdev_id];
  2996. if (qdf_unlikely(!vdev))
  2997. return nbuf;
  2998. DP_STATS_INC(vdev, tx_i.dropped.drop_ingress, 1);
  2999. return nbuf;
  3000. }
  3001. /*
  3002. * dp_tx_exc_drop() - Drop the frame on a given VAP
  3003. * @soc: DP soc handle
  3004. * @vdev_id: id of DP vdev handle
  3005. * @nbuf: skb
  3006. * @tx_exc_metadata: Handle that holds exception path meta data
  3007. *
  3008. * Drop all the incoming packets
  3009. *
  3010. * Return: nbuf
  3011. *
  3012. */
  3013. qdf_nbuf_t dp_tx_exc_drop(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  3014. qdf_nbuf_t nbuf,
  3015. struct cdp_tx_exception_metadata *tx_exc_metadata)
  3016. {
  3017. return dp_tx_drop(soc_hdl, vdev_id, nbuf);
  3018. }
  3019. #endif
  3020. /*
  3021. * dp_tx_send() - Transmit a frame on a given VAP
  3022. * @soc: DP soc handle
  3023. * @vdev_id: id of DP vdev handle
  3024. * @nbuf: skb
  3025. *
  3026. * Entry point for Core Tx layer (DP_TX) invoked from
  3027. * hard_start_xmit in OSIF/HDD or from dp_rx_process for intravap forwarding
  3028. * cases
  3029. *
  3030. * Return: NULL on success,
  3031. * nbuf when it fails to send
  3032. */
  3033. qdf_nbuf_t dp_tx_send(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  3034. qdf_nbuf_t nbuf)
  3035. {
  3036. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  3037. uint16_t peer_id = HTT_INVALID_PEER;
  3038. /*
  3039. * doing a memzero is causing additional function call overhead
  3040. * so doing static stack clearing
  3041. */
  3042. struct dp_tx_msdu_info_s msdu_info = {0};
  3043. struct dp_vdev *vdev = NULL;
  3044. qdf_nbuf_t end_nbuf = NULL;
  3045. if (qdf_unlikely(vdev_id >= MAX_VDEV_CNT))
  3046. return nbuf;
  3047. /*
  3048. * dp_vdev_get_ref_by_id does does a atomic operation avoid using
  3049. * this in per packet path.
  3050. *
  3051. * As in this path vdev memory is already protected with netdev
  3052. * tx lock
  3053. */
  3054. vdev = soc->vdev_id_map[vdev_id];
  3055. if (qdf_unlikely(!vdev))
  3056. return nbuf;
  3057. /*
  3058. * Set Default Host TID value to invalid TID
  3059. * (TID override disabled)
  3060. */
  3061. msdu_info.tid = HTT_TX_EXT_TID_INVALID;
  3062. DP_STATS_INC_PKT(vdev, tx_i.rcvd, 1, qdf_nbuf_headlen(nbuf));
  3063. if (qdf_unlikely(vdev->mesh_vdev)) {
  3064. qdf_nbuf_t nbuf_mesh = dp_tx_extract_mesh_meta_data(vdev, nbuf,
  3065. &msdu_info);
  3066. if (!nbuf_mesh) {
  3067. dp_verbose_debug("Extracting mesh metadata failed");
  3068. return nbuf;
  3069. }
  3070. nbuf = nbuf_mesh;
  3071. }
  3072. /*
  3073. * Get HW Queue to use for this frame.
  3074. * TCL supports upto 4 DMA rings, out of which 3 rings are
  3075. * dedicated for data and 1 for command.
  3076. * "queue_id" maps to one hardware ring.
  3077. * With each ring, we also associate a unique Tx descriptor pool
  3078. * to minimize lock contention for these resources.
  3079. */
  3080. dp_tx_get_queue(vdev, nbuf, &msdu_info.tx_queue);
  3081. DP_STATS_INC(vdev, tx_i.rcvd_per_core[msdu_info.tx_queue.desc_pool_id],
  3082. 1);
  3083. /*
  3084. * TCL H/W supports 2 DSCP-TID mapping tables.
  3085. * Table 1 - Default DSCP-TID mapping table
  3086. * Table 2 - 1 DSCP-TID override table
  3087. *
  3088. * If we need a different DSCP-TID mapping for this vap,
  3089. * call tid_classify to extract DSCP/ToS from frame and
  3090. * map to a TID and store in msdu_info. This is later used
  3091. * to fill in TCL Input descriptor (per-packet TID override).
  3092. */
  3093. dp_tx_classify_tid(vdev, nbuf, &msdu_info);
  3094. /*
  3095. * Classify the frame and call corresponding
  3096. * "prepare" function which extracts the segment (TSO)
  3097. * and fragmentation information (for TSO , SG, ME, or Raw)
  3098. * into MSDU_INFO structure which is later used to fill
  3099. * SW and HW descriptors.
  3100. */
  3101. if (qdf_nbuf_is_tso(nbuf)) {
  3102. dp_verbose_debug("TSO frame %pK", vdev);
  3103. DP_STATS_INC_PKT(vdev->pdev, tso_stats.num_tso_pkts, 1,
  3104. qdf_nbuf_len(nbuf));
  3105. if (dp_tx_prepare_tso(vdev, nbuf, &msdu_info)) {
  3106. DP_STATS_INC_PKT(vdev->pdev, tso_stats.dropped_host, 1,
  3107. qdf_nbuf_len(nbuf));
  3108. return nbuf;
  3109. }
  3110. goto send_multiple;
  3111. }
  3112. /* SG */
  3113. if (qdf_unlikely(qdf_nbuf_is_nonlinear(nbuf))) {
  3114. if (qdf_nbuf_get_nr_frags(nbuf) > DP_TX_MAX_NUM_FRAGS - 1) {
  3115. if (qdf_unlikely(qdf_nbuf_linearize(nbuf)))
  3116. return nbuf;
  3117. } else {
  3118. struct dp_tx_seg_info_s seg_info = {0};
  3119. nbuf = dp_tx_prepare_sg(vdev, nbuf, &seg_info,
  3120. &msdu_info);
  3121. if (!nbuf)
  3122. return NULL;
  3123. dp_verbose_debug("non-TSO SG frame %pK", vdev);
  3124. DP_STATS_INC_PKT(vdev, tx_i.sg.sg_pkt, 1,
  3125. qdf_nbuf_len(nbuf));
  3126. goto send_multiple;
  3127. }
  3128. }
  3129. if (qdf_unlikely(!dp_tx_mcast_enhance(vdev, nbuf)))
  3130. return NULL;
  3131. /* RAW */
  3132. if (qdf_unlikely(vdev->tx_encap_type == htt_cmn_pkt_type_raw)) {
  3133. struct dp_tx_seg_info_s seg_info = {0};
  3134. nbuf = dp_tx_prepare_raw(vdev, nbuf, &seg_info, &msdu_info);
  3135. if (!nbuf)
  3136. return NULL;
  3137. dp_verbose_debug("Raw frame %pK", vdev);
  3138. goto send_multiple;
  3139. }
  3140. if (qdf_unlikely(vdev->nawds_enabled)) {
  3141. qdf_ether_header_t *eh = (qdf_ether_header_t *)
  3142. qdf_nbuf_data(nbuf);
  3143. if (DP_FRAME_IS_MULTICAST((eh)->ether_dhost)) {
  3144. uint16_t sa_peer_id = DP_INVALID_PEER;
  3145. if (!soc->ast_offload_support) {
  3146. struct dp_ast_entry *ast_entry = NULL;
  3147. qdf_spin_lock_bh(&soc->ast_lock);
  3148. ast_entry = dp_peer_ast_hash_find_by_pdevid
  3149. (soc,
  3150. (uint8_t *)(eh->ether_shost),
  3151. vdev->pdev->pdev_id);
  3152. if (ast_entry)
  3153. sa_peer_id = ast_entry->peer_id;
  3154. qdf_spin_unlock_bh(&soc->ast_lock);
  3155. }
  3156. dp_tx_nawds_handler(soc, vdev, &msdu_info, nbuf,
  3157. sa_peer_id);
  3158. }
  3159. peer_id = DP_INVALID_PEER;
  3160. DP_STATS_INC_PKT(vdev, tx_i.nawds_mcast,
  3161. 1, qdf_nbuf_len(nbuf));
  3162. }
  3163. /* Single linear frame */
  3164. /*
  3165. * If nbuf is a simple linear frame, use send_single function to
  3166. * prepare direct-buffer type TCL descriptor and enqueue to TCL
  3167. * SRNG. There is no need to setup a MSDU extension descriptor.
  3168. */
  3169. dp_tx_prefetch_nbuf_data(nbuf);
  3170. nbuf = dp_tx_send_msdu_single_wrapper(vdev, nbuf, &msdu_info,
  3171. peer_id, end_nbuf);
  3172. return nbuf;
  3173. send_multiple:
  3174. nbuf = dp_tx_send_msdu_multiple(vdev, nbuf, &msdu_info);
  3175. if (qdf_unlikely(nbuf && msdu_info.frm_type == dp_tx_frm_raw))
  3176. dp_tx_raw_prepare_unset(vdev->pdev->soc, nbuf);
  3177. return nbuf;
  3178. }
  3179. /**
  3180. * dp_tx_send_vdev_id_check() - Transmit a frame on a given VAP in special
  3181. * case to vaoid check in perpkt path.
  3182. * @soc: DP soc handle
  3183. * @vdev_id: id of DP vdev handle
  3184. * @nbuf: skb
  3185. *
  3186. * Entry point for Core Tx layer (DP_TX) invoked from
  3187. * hard_start_xmit in OSIF/HDD to transmit packet through dp_tx_send
  3188. * with special condition to avoid per pkt check in dp_tx_send
  3189. *
  3190. * Return: NULL on success,
  3191. * nbuf when it fails to send
  3192. */
  3193. qdf_nbuf_t dp_tx_send_vdev_id_check(struct cdp_soc_t *soc_hdl,
  3194. uint8_t vdev_id, qdf_nbuf_t nbuf)
  3195. {
  3196. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  3197. struct dp_vdev *vdev = NULL;
  3198. if (qdf_unlikely(vdev_id >= MAX_VDEV_CNT))
  3199. return nbuf;
  3200. /*
  3201. * dp_vdev_get_ref_by_id does does a atomic operation avoid using
  3202. * this in per packet path.
  3203. *
  3204. * As in this path vdev memory is already protected with netdev
  3205. * tx lock
  3206. */
  3207. vdev = soc->vdev_id_map[vdev_id];
  3208. if (qdf_unlikely(!vdev))
  3209. return nbuf;
  3210. if (qdf_unlikely(dp_tx_per_pkt_vdev_id_check(nbuf, vdev)
  3211. == QDF_STATUS_E_FAILURE)) {
  3212. DP_STATS_INC(vdev, tx_i.dropped.fail_per_pkt_vdev_id_check, 1);
  3213. return nbuf;
  3214. }
  3215. return dp_tx_send(soc_hdl, vdev_id, nbuf);
  3216. }
  3217. #ifdef UMAC_SUPPORT_PROXY_ARP
  3218. /**
  3219. * dp_tx_proxy_arp() - Tx proxy arp handler
  3220. * @vdev: datapath vdev handle
  3221. * @buf: sk buffer
  3222. *
  3223. * Return: status
  3224. */
  3225. static inline
  3226. int dp_tx_proxy_arp(struct dp_vdev *vdev, qdf_nbuf_t nbuf)
  3227. {
  3228. if (vdev->osif_proxy_arp)
  3229. return vdev->osif_proxy_arp(vdev->osif_vdev, nbuf);
  3230. /*
  3231. * when UMAC_SUPPORT_PROXY_ARP is defined, we expect
  3232. * osif_proxy_arp has a valid function pointer assigned
  3233. * to it
  3234. */
  3235. dp_tx_err("valid function pointer for osif_proxy_arp is expected!!\n");
  3236. return QDF_STATUS_NOT_INITIALIZED;
  3237. }
  3238. #else
  3239. /**
  3240. * dp_tx_proxy_arp() - Tx proxy arp handler
  3241. * @vdev: datapath vdev handle
  3242. * @buf: sk buffer
  3243. *
  3244. * This function always return 0 when UMAC_SUPPORT_PROXY_ARP
  3245. * is not defined.
  3246. *
  3247. * Return: status
  3248. */
  3249. static inline
  3250. int dp_tx_proxy_arp(struct dp_vdev *vdev, qdf_nbuf_t nbuf)
  3251. {
  3252. return QDF_STATUS_SUCCESS;
  3253. }
  3254. #endif
  3255. #if defined(WLAN_FEATURE_11BE_MLO) && defined(WLAN_MLO_MULTI_CHIP)
  3256. #ifdef WLAN_MCAST_MLO
  3257. static bool
  3258. dp_tx_reinject_mlo_hdl(struct dp_soc *soc, struct dp_vdev *vdev,
  3259. struct dp_tx_desc_s *tx_desc,
  3260. qdf_nbuf_t nbuf,
  3261. uint8_t reinject_reason)
  3262. {
  3263. if (reinject_reason == HTT_TX_FW2WBM_REINJECT_REASON_MLO_MCAST) {
  3264. if (soc->arch_ops.dp_tx_mcast_handler)
  3265. soc->arch_ops.dp_tx_mcast_handler(soc, vdev, nbuf);
  3266. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  3267. return true;
  3268. }
  3269. return false;
  3270. }
  3271. #else /* WLAN_MCAST_MLO */
  3272. static inline bool
  3273. dp_tx_reinject_mlo_hdl(struct dp_soc *soc, struct dp_vdev *vdev,
  3274. struct dp_tx_desc_s *tx_desc,
  3275. qdf_nbuf_t nbuf,
  3276. uint8_t reinject_reason)
  3277. {
  3278. return false;
  3279. }
  3280. #endif /* WLAN_MCAST_MLO */
  3281. #else
  3282. static inline bool
  3283. dp_tx_reinject_mlo_hdl(struct dp_soc *soc, struct dp_vdev *vdev,
  3284. struct dp_tx_desc_s *tx_desc,
  3285. qdf_nbuf_t nbuf,
  3286. uint8_t reinject_reason)
  3287. {
  3288. return false;
  3289. }
  3290. #endif
  3291. /**
  3292. * dp_tx_reinject_handler() - Tx Reinject Handler
  3293. * @soc: datapath soc handle
  3294. * @vdev: datapath vdev handle
  3295. * @tx_desc: software descriptor head pointer
  3296. * @status : Tx completion status from HTT descriptor
  3297. * @reinject_reason : reinject reason from HTT descriptor
  3298. *
  3299. * This function reinjects frames back to Target.
  3300. * Todo - Host queue needs to be added
  3301. *
  3302. * Return: none
  3303. */
  3304. void dp_tx_reinject_handler(struct dp_soc *soc,
  3305. struct dp_vdev *vdev,
  3306. struct dp_tx_desc_s *tx_desc,
  3307. uint8_t *status,
  3308. uint8_t reinject_reason)
  3309. {
  3310. struct dp_peer *peer = NULL;
  3311. uint32_t peer_id = HTT_INVALID_PEER;
  3312. qdf_nbuf_t nbuf = tx_desc->nbuf;
  3313. qdf_nbuf_t nbuf_copy = NULL;
  3314. struct dp_tx_msdu_info_s msdu_info;
  3315. #ifdef WDS_VENDOR_EXTENSION
  3316. int is_mcast = 0, is_ucast = 0;
  3317. int num_peers_3addr = 0;
  3318. qdf_ether_header_t *eth_hdr = (qdf_ether_header_t *)(qdf_nbuf_data(nbuf));
  3319. struct ieee80211_frame_addr4 *wh = (struct ieee80211_frame_addr4 *)(qdf_nbuf_data(nbuf));
  3320. #endif
  3321. struct dp_txrx_peer *txrx_peer;
  3322. qdf_assert(vdev);
  3323. dp_tx_debug("Tx reinject path");
  3324. DP_STATS_INC_PKT(vdev, tx_i.reinject_pkts, 1,
  3325. qdf_nbuf_len(tx_desc->nbuf));
  3326. if (dp_tx_reinject_mlo_hdl(soc, vdev, tx_desc, nbuf, reinject_reason))
  3327. return;
  3328. #ifdef WDS_VENDOR_EXTENSION
  3329. if (qdf_unlikely(vdev->tx_encap_type != htt_cmn_pkt_type_raw)) {
  3330. is_mcast = (IS_MULTICAST(wh->i_addr1)) ? 1 : 0;
  3331. } else {
  3332. is_mcast = (IS_MULTICAST(eth_hdr->ether_dhost)) ? 1 : 0;
  3333. }
  3334. is_ucast = !is_mcast;
  3335. qdf_spin_lock_bh(&vdev->peer_list_lock);
  3336. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  3337. txrx_peer = dp_get_txrx_peer(peer);
  3338. if (!txrx_peer || txrx_peer->bss_peer)
  3339. continue;
  3340. /* Detect wds peers that use 3-addr framing for mcast.
  3341. * if there are any, the bss_peer is used to send the
  3342. * the mcast frame using 3-addr format. all wds enabled
  3343. * peers that use 4-addr framing for mcast frames will
  3344. * be duplicated and sent as 4-addr frames below.
  3345. */
  3346. if (!txrx_peer->wds_enabled ||
  3347. !txrx_peer->wds_ecm.wds_tx_mcast_4addr) {
  3348. num_peers_3addr = 1;
  3349. break;
  3350. }
  3351. }
  3352. qdf_spin_unlock_bh(&vdev->peer_list_lock);
  3353. #endif
  3354. if (qdf_unlikely(vdev->mesh_vdev)) {
  3355. DP_TX_FREE_SINGLE_BUF(vdev->pdev->soc, tx_desc->nbuf);
  3356. } else {
  3357. qdf_spin_lock_bh(&vdev->peer_list_lock);
  3358. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  3359. txrx_peer = dp_get_txrx_peer(peer);
  3360. if (!txrx_peer)
  3361. continue;
  3362. if ((txrx_peer->peer_id != HTT_INVALID_PEER) &&
  3363. #ifdef WDS_VENDOR_EXTENSION
  3364. /*
  3365. * . if 3-addr STA, then send on BSS Peer
  3366. * . if Peer WDS enabled and accept 4-addr mcast,
  3367. * send mcast on that peer only
  3368. * . if Peer WDS enabled and accept 4-addr ucast,
  3369. * send ucast on that peer only
  3370. */
  3371. ((txrx_peer->bss_peer && num_peers_3addr && is_mcast) ||
  3372. (txrx_peer->wds_enabled &&
  3373. ((is_mcast && txrx_peer->wds_ecm.wds_tx_mcast_4addr) ||
  3374. (is_ucast &&
  3375. txrx_peer->wds_ecm.wds_tx_ucast_4addr))))) {
  3376. #else
  3377. (txrx_peer->bss_peer &&
  3378. (dp_tx_proxy_arp(vdev, nbuf) == QDF_STATUS_SUCCESS))) {
  3379. #endif
  3380. peer_id = DP_INVALID_PEER;
  3381. nbuf_copy = qdf_nbuf_copy(nbuf);
  3382. if (!nbuf_copy) {
  3383. dp_tx_debug("nbuf copy failed");
  3384. break;
  3385. }
  3386. qdf_mem_zero(&msdu_info, sizeof(msdu_info));
  3387. dp_tx_get_queue(vdev, nbuf,
  3388. &msdu_info.tx_queue);
  3389. nbuf_copy = dp_tx_send_msdu_single(vdev,
  3390. nbuf_copy,
  3391. &msdu_info,
  3392. peer_id,
  3393. NULL);
  3394. if (nbuf_copy) {
  3395. dp_tx_debug("pkt send failed");
  3396. qdf_nbuf_free(nbuf_copy);
  3397. }
  3398. }
  3399. }
  3400. qdf_spin_unlock_bh(&vdev->peer_list_lock);
  3401. qdf_nbuf_unmap_nbytes_single(vdev->osdev, nbuf,
  3402. QDF_DMA_TO_DEVICE, nbuf->len);
  3403. qdf_nbuf_free(nbuf);
  3404. }
  3405. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  3406. }
  3407. /**
  3408. * dp_tx_inspect_handler() - Tx Inspect Handler
  3409. * @soc: datapath soc handle
  3410. * @vdev: datapath vdev handle
  3411. * @tx_desc: software descriptor head pointer
  3412. * @status : Tx completion status from HTT descriptor
  3413. *
  3414. * Handles Tx frames sent back to Host for inspection
  3415. * (ProxyARP)
  3416. *
  3417. * Return: none
  3418. */
  3419. void dp_tx_inspect_handler(struct dp_soc *soc,
  3420. struct dp_vdev *vdev,
  3421. struct dp_tx_desc_s *tx_desc,
  3422. uint8_t *status)
  3423. {
  3424. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  3425. "%s Tx inspect path",
  3426. __func__);
  3427. DP_STATS_INC_PKT(vdev, tx_i.inspect_pkts, 1,
  3428. qdf_nbuf_len(tx_desc->nbuf));
  3429. DP_TX_FREE_SINGLE_BUF(soc, tx_desc->nbuf);
  3430. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  3431. }
  3432. #ifdef MESH_MODE_SUPPORT
  3433. /**
  3434. * dp_tx_comp_fill_tx_completion_stats() - Fill per packet Tx completion stats
  3435. * in mesh meta header
  3436. * @tx_desc: software descriptor head pointer
  3437. * @ts: pointer to tx completion stats
  3438. * Return: none
  3439. */
  3440. static
  3441. void dp_tx_comp_fill_tx_completion_stats(struct dp_tx_desc_s *tx_desc,
  3442. struct hal_tx_completion_status *ts)
  3443. {
  3444. qdf_nbuf_t netbuf = tx_desc->nbuf;
  3445. if (!tx_desc->msdu_ext_desc) {
  3446. if (qdf_nbuf_pull_head(netbuf, tx_desc->pkt_offset) == NULL) {
  3447. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3448. "netbuf %pK offset %d",
  3449. netbuf, tx_desc->pkt_offset);
  3450. return;
  3451. }
  3452. }
  3453. }
  3454. #else
  3455. static
  3456. void dp_tx_comp_fill_tx_completion_stats(struct dp_tx_desc_s *tx_desc,
  3457. struct hal_tx_completion_status *ts)
  3458. {
  3459. }
  3460. #endif
  3461. #ifdef CONFIG_SAWF
  3462. static void dp_tx_update_peer_sawf_stats(struct dp_soc *soc,
  3463. struct dp_vdev *vdev,
  3464. struct dp_txrx_peer *txrx_peer,
  3465. struct dp_tx_desc_s *tx_desc,
  3466. struct hal_tx_completion_status *ts,
  3467. uint8_t tid)
  3468. {
  3469. dp_sawf_tx_compl_update_peer_stats(soc, vdev, txrx_peer, tx_desc,
  3470. ts, tid);
  3471. }
  3472. #else
  3473. static void dp_tx_update_peer_sawf_stats(struct dp_soc *soc,
  3474. struct dp_vdev *vdev,
  3475. struct dp_txrx_peer *txrx_peer,
  3476. struct dp_tx_desc_s *tx_desc,
  3477. struct hal_tx_completion_status *ts,
  3478. uint8_t tid)
  3479. {
  3480. }
  3481. #endif
  3482. #ifdef QCA_PEER_EXT_STATS
  3483. /*
  3484. * dp_tx_compute_tid_delay() - Compute per TID delay
  3485. * @stats: Per TID delay stats
  3486. * @tx_desc: Software Tx descriptor
  3487. *
  3488. * Compute the software enqueue and hw enqueue delays and
  3489. * update the respective histograms
  3490. *
  3491. * Return: void
  3492. */
  3493. static void dp_tx_compute_tid_delay(struct cdp_delay_tid_stats *stats,
  3494. struct dp_tx_desc_s *tx_desc)
  3495. {
  3496. struct cdp_delay_tx_stats *tx_delay = &stats->tx_delay;
  3497. int64_t current_timestamp, timestamp_ingress, timestamp_hw_enqueue;
  3498. uint32_t sw_enqueue_delay, fwhw_transmit_delay;
  3499. current_timestamp = qdf_ktime_to_ms(qdf_ktime_real_get());
  3500. timestamp_ingress = qdf_nbuf_get_timestamp(tx_desc->nbuf);
  3501. timestamp_hw_enqueue = qdf_ktime_to_ms(tx_desc->timestamp);
  3502. sw_enqueue_delay = (uint32_t)(timestamp_hw_enqueue - timestamp_ingress);
  3503. fwhw_transmit_delay = (uint32_t)(current_timestamp -
  3504. timestamp_hw_enqueue);
  3505. /*
  3506. * Update the Tx software enqueue delay and HW enque-Completion delay.
  3507. */
  3508. dp_hist_update_stats(&tx_delay->tx_swq_delay, sw_enqueue_delay);
  3509. dp_hist_update_stats(&tx_delay->hwtx_delay, fwhw_transmit_delay);
  3510. }
  3511. /*
  3512. * dp_tx_update_peer_delay_stats() - Update the peer delay stats
  3513. * @txrx_peer: DP peer context
  3514. * @tx_desc: Tx software descriptor
  3515. * @tid: Transmission ID
  3516. * @ring_id: Rx CPU context ID/CPU_ID
  3517. *
  3518. * Update the peer extended stats. These are enhanced other
  3519. * delay stats per msdu level.
  3520. *
  3521. * Return: void
  3522. */
  3523. static void dp_tx_update_peer_delay_stats(struct dp_txrx_peer *txrx_peer,
  3524. struct dp_tx_desc_s *tx_desc,
  3525. uint8_t tid, uint8_t ring_id)
  3526. {
  3527. struct dp_pdev *pdev = txrx_peer->vdev->pdev;
  3528. struct dp_soc *soc = NULL;
  3529. struct dp_peer_delay_stats *delay_stats = NULL;
  3530. soc = pdev->soc;
  3531. if (qdf_likely(!wlan_cfg_is_peer_ext_stats_enabled(soc->wlan_cfg_ctx)))
  3532. return;
  3533. delay_stats = txrx_peer->delay_stats;
  3534. qdf_assert(delay_stats);
  3535. qdf_assert(ring < CDP_MAX_TXRX_CTX);
  3536. /*
  3537. * For non-TID packets use the TID 9
  3538. */
  3539. if (qdf_unlikely(tid >= CDP_MAX_DATA_TIDS))
  3540. tid = CDP_MAX_DATA_TIDS - 1;
  3541. dp_tx_compute_tid_delay(&delay_stats->delay_tid_stats[tid][ring_id],
  3542. tx_desc);
  3543. }
  3544. #else
  3545. static inline void dp_tx_update_peer_delay_stats(struct dp_txrx_peer *txrx_peer,
  3546. struct dp_tx_desc_s *tx_desc,
  3547. uint8_t tid, uint8_t ring_id)
  3548. {
  3549. }
  3550. #endif
  3551. #ifdef HW_TX_DELAY_STATS_ENABLE
  3552. /**
  3553. * dp_update_tx_delay_stats() - update the delay stats
  3554. * @vdev: vdev handle
  3555. * @delay: delay in ms or us based on the flag delay_in_us
  3556. * @tid: tid value
  3557. * @mode: type of tx delay mode
  3558. * @ring id: ring number
  3559. * @delay_in_us: flag to indicate whether the delay is in ms or us
  3560. *
  3561. * Return: none
  3562. */
  3563. static inline
  3564. void dp_update_tx_delay_stats(struct dp_vdev *vdev, uint32_t delay, uint8_t tid,
  3565. uint8_t mode, uint8_t ring_id, bool delay_in_us)
  3566. {
  3567. struct cdp_tid_tx_stats *tstats =
  3568. &vdev->stats.tid_tx_stats[ring_id][tid];
  3569. dp_update_delay_stats(tstats, NULL, delay, tid, mode, ring_id,
  3570. delay_in_us);
  3571. }
  3572. #else
  3573. static inline
  3574. void dp_update_tx_delay_stats(struct dp_vdev *vdev, uint32_t delay, uint8_t tid,
  3575. uint8_t mode, uint8_t ring_id, bool delay_in_us)
  3576. {
  3577. struct cdp_tid_tx_stats *tstats =
  3578. &vdev->pdev->stats.tid_stats.tid_tx_stats[ring_id][tid];
  3579. dp_update_delay_stats(tstats, NULL, delay, tid, mode, ring_id,
  3580. delay_in_us);
  3581. }
  3582. #endif
  3583. /**
  3584. * dp_tx_compute_delay() - Compute and fill in all timestamps
  3585. * to pass in correct fields
  3586. *
  3587. * @vdev: pdev handle
  3588. * @tx_desc: tx descriptor
  3589. * @tid: tid value
  3590. * @ring_id: TCL or WBM ring number for transmit path
  3591. * Return: none
  3592. */
  3593. void dp_tx_compute_delay(struct dp_vdev *vdev, struct dp_tx_desc_s *tx_desc,
  3594. uint8_t tid, uint8_t ring_id)
  3595. {
  3596. int64_t current_timestamp, timestamp_ingress, timestamp_hw_enqueue;
  3597. uint32_t sw_enqueue_delay, fwhw_transmit_delay, interframe_delay;
  3598. uint32_t fwhw_transmit_delay_us;
  3599. if (qdf_likely(!vdev->pdev->delay_stats_flag) &&
  3600. qdf_likely(!dp_is_vdev_tx_delay_stats_enabled(vdev)))
  3601. return;
  3602. if (dp_is_vdev_tx_delay_stats_enabled(vdev)) {
  3603. fwhw_transmit_delay_us =
  3604. qdf_ktime_to_us(qdf_ktime_real_get()) -
  3605. qdf_ktime_to_us(tx_desc->timestamp);
  3606. /*
  3607. * Delay between packet enqueued to HW and Tx completion in us
  3608. */
  3609. dp_update_tx_delay_stats(vdev, fwhw_transmit_delay_us, tid,
  3610. CDP_DELAY_STATS_FW_HW_TRANSMIT,
  3611. ring_id, true);
  3612. /*
  3613. * For MCL, only enqueue to completion delay is required
  3614. * so return if the vdev flag is enabled.
  3615. */
  3616. return;
  3617. }
  3618. current_timestamp = qdf_ktime_to_ms(qdf_ktime_real_get());
  3619. timestamp_hw_enqueue = qdf_ktime_to_ms(tx_desc->timestamp);
  3620. fwhw_transmit_delay = (uint32_t)(current_timestamp -
  3621. timestamp_hw_enqueue);
  3622. /*
  3623. * Delay between packet enqueued to HW and Tx completion in ms
  3624. */
  3625. dp_update_tx_delay_stats(vdev, fwhw_transmit_delay, tid,
  3626. CDP_DELAY_STATS_FW_HW_TRANSMIT, ring_id,
  3627. false);
  3628. timestamp_ingress = qdf_nbuf_get_timestamp(tx_desc->nbuf);
  3629. sw_enqueue_delay = (uint32_t)(timestamp_hw_enqueue - timestamp_ingress);
  3630. interframe_delay = (uint32_t)(timestamp_ingress -
  3631. vdev->prev_tx_enq_tstamp);
  3632. /*
  3633. * Delay in software enqueue
  3634. */
  3635. dp_update_tx_delay_stats(vdev, sw_enqueue_delay, tid,
  3636. CDP_DELAY_STATS_SW_ENQ, ring_id,
  3637. false);
  3638. /*
  3639. * Update interframe delay stats calculated at hardstart receive point.
  3640. * Value of vdev->prev_tx_enq_tstamp will be 0 for 1st frame, so
  3641. * interframe delay will not be calculate correctly for 1st frame.
  3642. * On the other side, this will help in avoiding extra per packet check
  3643. * of !vdev->prev_tx_enq_tstamp.
  3644. */
  3645. dp_update_tx_delay_stats(vdev, interframe_delay, tid,
  3646. CDP_DELAY_STATS_TX_INTERFRAME, ring_id,
  3647. false);
  3648. vdev->prev_tx_enq_tstamp = timestamp_ingress;
  3649. }
  3650. #ifdef DISABLE_DP_STATS
  3651. static
  3652. inline void dp_update_no_ack_stats(qdf_nbuf_t nbuf,
  3653. struct dp_txrx_peer *txrx_peer)
  3654. {
  3655. }
  3656. #else
  3657. static inline void
  3658. dp_update_no_ack_stats(qdf_nbuf_t nbuf, struct dp_txrx_peer *txrx_peer)
  3659. {
  3660. enum qdf_proto_subtype subtype = QDF_PROTO_INVALID;
  3661. DPTRACE(qdf_dp_track_noack_check(nbuf, &subtype));
  3662. if (subtype != QDF_PROTO_INVALID)
  3663. DP_PEER_PER_PKT_STATS_INC(txrx_peer, tx.no_ack_count[subtype],
  3664. 1);
  3665. }
  3666. #endif
  3667. #ifndef QCA_ENHANCED_STATS_SUPPORT
  3668. #ifdef DP_PEER_EXTENDED_API
  3669. static inline uint8_t
  3670. dp_tx_get_mpdu_retry_threshold(struct dp_txrx_peer *txrx_peer)
  3671. {
  3672. return txrx_peer->mpdu_retry_threshold;
  3673. }
  3674. #else
  3675. static inline uint8_t
  3676. dp_tx_get_mpdu_retry_threshold(struct dp_txrx_peer *txrx_peer)
  3677. {
  3678. return 0;
  3679. }
  3680. #endif
  3681. /**
  3682. * dp_tx_update_peer_extd_stats()- Update Tx extended path stats for peer
  3683. *
  3684. * @ts: Tx compltion status
  3685. * @txrx_peer: datapath txrx_peer handle
  3686. *
  3687. * Return: void
  3688. */
  3689. static inline void
  3690. dp_tx_update_peer_extd_stats(struct hal_tx_completion_status *ts,
  3691. struct dp_txrx_peer *txrx_peer)
  3692. {
  3693. uint8_t mcs, pkt_type, dst_mcs_idx;
  3694. uint8_t retry_threshold = dp_tx_get_mpdu_retry_threshold(txrx_peer);
  3695. mcs = ts->mcs;
  3696. pkt_type = ts->pkt_type;
  3697. /* do HW to SW pkt type conversion */
  3698. pkt_type = (pkt_type >= HAL_DOT11_MAX ? DOT11_MAX :
  3699. hal_2_dp_pkt_type_map[pkt_type]);
  3700. dst_mcs_idx = dp_get_mcs_array_index_by_pkt_type_mcs(pkt_type, mcs);
  3701. if (MCS_INVALID_ARRAY_INDEX != dst_mcs_idx)
  3702. DP_PEER_EXTD_STATS_INC(txrx_peer,
  3703. tx.pkt_type[pkt_type].mcs_count[dst_mcs_idx],
  3704. 1);
  3705. DP_PEER_EXTD_STATS_INC(txrx_peer, tx.sgi_count[ts->sgi], 1);
  3706. DP_PEER_EXTD_STATS_INC(txrx_peer, tx.bw[ts->bw], 1);
  3707. DP_PEER_EXTD_STATS_UPD(txrx_peer, tx.last_ack_rssi, ts->ack_frame_rssi);
  3708. DP_PEER_EXTD_STATS_INC(txrx_peer,
  3709. tx.wme_ac_type[TID_TO_WME_AC(ts->tid)], 1);
  3710. DP_PEER_EXTD_STATS_INCC(txrx_peer, tx.stbc, 1, ts->stbc);
  3711. DP_PEER_EXTD_STATS_INCC(txrx_peer, tx.ldpc, 1, ts->ldpc);
  3712. DP_PEER_EXTD_STATS_INCC(txrx_peer, tx.retries, 1, ts->transmit_cnt > 1);
  3713. if (ts->first_msdu) {
  3714. DP_PEER_EXTD_STATS_INCC(txrx_peer, tx.retries_mpdu, 1,
  3715. ts->transmit_cnt > 1);
  3716. if (!retry_threshold)
  3717. return;
  3718. DP_PEER_EXTD_STATS_INCC(txrx_peer, tx.mpdu_success_with_retries,
  3719. qdf_do_div(ts->transmit_cnt,
  3720. retry_threshold),
  3721. ts->transmit_cnt > retry_threshold);
  3722. }
  3723. }
  3724. #else
  3725. static inline void
  3726. dp_tx_update_peer_extd_stats(struct hal_tx_completion_status *ts,
  3727. struct dp_txrx_peer *txrx_peer)
  3728. {
  3729. }
  3730. #endif
  3731. /**
  3732. * dp_tx_update_peer_stats() - Update peer stats from Tx completion indications
  3733. * per wbm ring
  3734. *
  3735. * @tx_desc: software descriptor head pointer
  3736. * @ts: Tx completion status
  3737. * @peer: peer handle
  3738. * @ring_id: ring number
  3739. *
  3740. * Return: None
  3741. */
  3742. static inline void
  3743. dp_tx_update_peer_stats(struct dp_tx_desc_s *tx_desc,
  3744. struct hal_tx_completion_status *ts,
  3745. struct dp_txrx_peer *txrx_peer, uint8_t ring_id)
  3746. {
  3747. struct dp_pdev *pdev = txrx_peer->vdev->pdev;
  3748. uint8_t tid = ts->tid;
  3749. uint32_t length;
  3750. struct cdp_tid_tx_stats *tid_stats;
  3751. if (!pdev)
  3752. return;
  3753. if (qdf_unlikely(tid >= CDP_MAX_DATA_TIDS))
  3754. tid = CDP_MAX_DATA_TIDS - 1;
  3755. tid_stats = &pdev->stats.tid_stats.tid_tx_stats[ring_id][tid];
  3756. if (ts->release_src != HAL_TX_COMP_RELEASE_SOURCE_TQM) {
  3757. dp_err_rl("Release source:%d is not from TQM", ts->release_src);
  3758. DP_PEER_PER_PKT_STATS_INC(txrx_peer, tx.release_src_not_tqm, 1);
  3759. return;
  3760. }
  3761. length = qdf_nbuf_len(tx_desc->nbuf);
  3762. DP_PEER_STATS_FLAT_INC_PKT(txrx_peer, comp_pkt, 1, length);
  3763. if (qdf_unlikely(pdev->delay_stats_flag) ||
  3764. qdf_unlikely(dp_is_vdev_tx_delay_stats_enabled(txrx_peer->vdev)))
  3765. dp_tx_compute_delay(txrx_peer->vdev, tx_desc, tid, ring_id);
  3766. if (ts->status < CDP_MAX_TX_TQM_STATUS) {
  3767. tid_stats->tqm_status_cnt[ts->status]++;
  3768. }
  3769. if (qdf_likely(ts->status == HAL_TX_TQM_RR_FRAME_ACKED)) {
  3770. DP_PEER_PER_PKT_STATS_INCC(txrx_peer, tx.retry_count, 1,
  3771. ts->transmit_cnt > 1);
  3772. DP_PEER_PER_PKT_STATS_INCC(txrx_peer, tx.multiple_retry_count,
  3773. 1, ts->transmit_cnt > 2);
  3774. DP_PEER_PER_PKT_STATS_INCC(txrx_peer, tx.ofdma, 1, ts->ofdma);
  3775. DP_PEER_PER_PKT_STATS_INCC(txrx_peer, tx.amsdu_cnt, 1,
  3776. ts->msdu_part_of_amsdu);
  3777. DP_PEER_PER_PKT_STATS_INCC(txrx_peer, tx.non_amsdu_cnt, 1,
  3778. !ts->msdu_part_of_amsdu);
  3779. txrx_peer->stats.per_pkt_stats.tx.last_tx_ts =
  3780. qdf_system_ticks();
  3781. dp_tx_update_peer_extd_stats(ts, txrx_peer);
  3782. return;
  3783. }
  3784. /*
  3785. * tx_failed is ideally supposed to be updated from HTT ppdu
  3786. * completion stats. But in IPQ807X/IPQ6018 chipsets owing to
  3787. * hw limitation there are no completions for failed cases.
  3788. * Hence updating tx_failed from data path. Please note that
  3789. * if tx_failed is fixed to be from ppdu, then this has to be
  3790. * removed
  3791. */
  3792. DP_PEER_STATS_FLAT_INC(txrx_peer, tx_failed, 1);
  3793. DP_PEER_PER_PKT_STATS_INCC(txrx_peer, tx.failed_retry_count, 1,
  3794. ts->transmit_cnt > DP_RETRY_COUNT);
  3795. dp_update_no_ack_stats(tx_desc->nbuf, txrx_peer);
  3796. if (ts->status == HAL_TX_TQM_RR_REM_CMD_AGED) {
  3797. DP_PEER_PER_PKT_STATS_INC(txrx_peer, tx.dropped.age_out, 1);
  3798. } else if (ts->status == HAL_TX_TQM_RR_REM_CMD_REM) {
  3799. DP_PEER_PER_PKT_STATS_INC_PKT(txrx_peer, tx.dropped.fw_rem, 1,
  3800. length);
  3801. } else if (ts->status == HAL_TX_TQM_RR_REM_CMD_NOTX) {
  3802. DP_PEER_PER_PKT_STATS_INC(txrx_peer, tx.dropped.fw_rem_notx, 1);
  3803. } else if (ts->status == HAL_TX_TQM_RR_REM_CMD_TX) {
  3804. DP_PEER_PER_PKT_STATS_INC(txrx_peer, tx.dropped.fw_rem_tx, 1);
  3805. } else if (ts->status == HAL_TX_TQM_RR_FW_REASON1) {
  3806. DP_PEER_PER_PKT_STATS_INC(txrx_peer, tx.dropped.fw_reason1, 1);
  3807. } else if (ts->status == HAL_TX_TQM_RR_FW_REASON2) {
  3808. DP_PEER_PER_PKT_STATS_INC(txrx_peer, tx.dropped.fw_reason2, 1);
  3809. } else if (ts->status == HAL_TX_TQM_RR_FW_REASON3) {
  3810. DP_PEER_PER_PKT_STATS_INC(txrx_peer, tx.dropped.fw_reason3, 1);
  3811. } else if (ts->status == HAL_TX_TQM_RR_REM_CMD_DISABLE_QUEUE) {
  3812. DP_PEER_PER_PKT_STATS_INC(txrx_peer,
  3813. tx.dropped.fw_rem_queue_disable, 1);
  3814. } else if (ts->status == HAL_TX_TQM_RR_REM_CMD_TILL_NONMATCHING) {
  3815. DP_PEER_PER_PKT_STATS_INC(txrx_peer,
  3816. tx.dropped.fw_rem_no_match, 1);
  3817. } else if (ts->status == HAL_TX_TQM_RR_DROP_THRESHOLD) {
  3818. DP_PEER_PER_PKT_STATS_INC(txrx_peer,
  3819. tx.dropped.drop_threshold, 1);
  3820. } else if (ts->status == HAL_TX_TQM_RR_LINK_DESC_UNAVAILABLE) {
  3821. DP_PEER_PER_PKT_STATS_INC(txrx_peer,
  3822. tx.dropped.drop_link_desc_na, 1);
  3823. } else if (ts->status == HAL_TX_TQM_RR_DROP_OR_INVALID_MSDU) {
  3824. DP_PEER_PER_PKT_STATS_INC(txrx_peer,
  3825. tx.dropped.invalid_drop, 1);
  3826. } else if (ts->status == HAL_TX_TQM_RR_MULTICAST_DROP) {
  3827. DP_PEER_PER_PKT_STATS_INC(txrx_peer,
  3828. tx.dropped.mcast_vdev_drop, 1);
  3829. } else {
  3830. DP_PEER_PER_PKT_STATS_INC(txrx_peer, tx.dropped.invalid_rr, 1);
  3831. }
  3832. }
  3833. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  3834. /**
  3835. * dp_tx_flow_pool_lock() - take flow pool lock
  3836. * @soc: core txrx main context
  3837. * @tx_desc: tx desc
  3838. *
  3839. * Return: None
  3840. */
  3841. static inline
  3842. void dp_tx_flow_pool_lock(struct dp_soc *soc,
  3843. struct dp_tx_desc_s *tx_desc)
  3844. {
  3845. struct dp_tx_desc_pool_s *pool;
  3846. uint8_t desc_pool_id;
  3847. desc_pool_id = tx_desc->pool_id;
  3848. pool = &soc->tx_desc[desc_pool_id];
  3849. qdf_spin_lock_bh(&pool->flow_pool_lock);
  3850. }
  3851. /**
  3852. * dp_tx_flow_pool_unlock() - release flow pool lock
  3853. * @soc: core txrx main context
  3854. * @tx_desc: tx desc
  3855. *
  3856. * Return: None
  3857. */
  3858. static inline
  3859. void dp_tx_flow_pool_unlock(struct dp_soc *soc,
  3860. struct dp_tx_desc_s *tx_desc)
  3861. {
  3862. struct dp_tx_desc_pool_s *pool;
  3863. uint8_t desc_pool_id;
  3864. desc_pool_id = tx_desc->pool_id;
  3865. pool = &soc->tx_desc[desc_pool_id];
  3866. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  3867. }
  3868. #else
  3869. static inline
  3870. void dp_tx_flow_pool_lock(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc)
  3871. {
  3872. }
  3873. static inline
  3874. void dp_tx_flow_pool_unlock(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc)
  3875. {
  3876. }
  3877. #endif
  3878. /**
  3879. * dp_tx_notify_completion() - Notify tx completion for this desc
  3880. * @soc: core txrx main context
  3881. * @vdev: datapath vdev handle
  3882. * @tx_desc: tx desc
  3883. * @netbuf: buffer
  3884. * @status: tx status
  3885. *
  3886. * Return: none
  3887. */
  3888. static inline void dp_tx_notify_completion(struct dp_soc *soc,
  3889. struct dp_vdev *vdev,
  3890. struct dp_tx_desc_s *tx_desc,
  3891. qdf_nbuf_t netbuf,
  3892. uint8_t status)
  3893. {
  3894. void *osif_dev;
  3895. ol_txrx_completion_fp tx_compl_cbk = NULL;
  3896. uint16_t flag = BIT(QDF_TX_RX_STATUS_DOWNLOAD_SUCC);
  3897. qdf_assert(tx_desc);
  3898. if (!vdev ||
  3899. !vdev->osif_vdev) {
  3900. return;
  3901. }
  3902. osif_dev = vdev->osif_vdev;
  3903. tx_compl_cbk = vdev->tx_comp;
  3904. if (status == HAL_TX_TQM_RR_FRAME_ACKED)
  3905. flag |= BIT(QDF_TX_RX_STATUS_OK);
  3906. if (tx_compl_cbk)
  3907. tx_compl_cbk(netbuf, osif_dev, flag);
  3908. }
  3909. /** dp_tx_sojourn_stats_process() - Collect sojourn stats
  3910. * @pdev: pdev handle
  3911. * @tid: tid value
  3912. * @txdesc_ts: timestamp from txdesc
  3913. * @ppdu_id: ppdu id
  3914. *
  3915. * Return: none
  3916. */
  3917. #ifdef FEATURE_PERPKT_INFO
  3918. static inline void dp_tx_sojourn_stats_process(struct dp_pdev *pdev,
  3919. struct dp_txrx_peer *txrx_peer,
  3920. uint8_t tid,
  3921. uint64_t txdesc_ts,
  3922. uint32_t ppdu_id)
  3923. {
  3924. uint64_t delta_ms;
  3925. struct cdp_tx_sojourn_stats *sojourn_stats;
  3926. struct dp_peer *primary_link_peer = NULL;
  3927. struct dp_soc *link_peer_soc = NULL;
  3928. if (qdf_unlikely(!pdev->enhanced_stats_en))
  3929. return;
  3930. if (qdf_unlikely(tid == HTT_INVALID_TID ||
  3931. tid >= CDP_DATA_TID_MAX))
  3932. return;
  3933. if (qdf_unlikely(!pdev->sojourn_buf))
  3934. return;
  3935. primary_link_peer = dp_get_primary_link_peer_by_id(pdev->soc,
  3936. txrx_peer->peer_id,
  3937. DP_MOD_ID_TX_COMP);
  3938. if (qdf_unlikely(!primary_link_peer))
  3939. return;
  3940. sojourn_stats = (struct cdp_tx_sojourn_stats *)
  3941. qdf_nbuf_data(pdev->sojourn_buf);
  3942. link_peer_soc = primary_link_peer->vdev->pdev->soc;
  3943. sojourn_stats->cookie = (void *)
  3944. dp_monitor_peer_get_peerstats_ctx(link_peer_soc,
  3945. primary_link_peer);
  3946. delta_ms = qdf_ktime_to_ms(qdf_ktime_real_get()) -
  3947. txdesc_ts;
  3948. qdf_ewma_tx_lag_add(&txrx_peer->stats.per_pkt_stats.tx.avg_sojourn_msdu[tid],
  3949. delta_ms);
  3950. sojourn_stats->sum_sojourn_msdu[tid] = delta_ms;
  3951. sojourn_stats->num_msdus[tid] = 1;
  3952. sojourn_stats->avg_sojourn_msdu[tid].internal =
  3953. txrx_peer->stats.per_pkt_stats.tx.avg_sojourn_msdu[tid].internal;
  3954. dp_wdi_event_handler(WDI_EVENT_TX_SOJOURN_STAT, pdev->soc,
  3955. pdev->sojourn_buf, HTT_INVALID_PEER,
  3956. WDI_NO_VAL, pdev->pdev_id);
  3957. sojourn_stats->sum_sojourn_msdu[tid] = 0;
  3958. sojourn_stats->num_msdus[tid] = 0;
  3959. sojourn_stats->avg_sojourn_msdu[tid].internal = 0;
  3960. dp_peer_unref_delete(primary_link_peer, DP_MOD_ID_TX_COMP);
  3961. }
  3962. #else
  3963. static inline void dp_tx_sojourn_stats_process(struct dp_pdev *pdev,
  3964. struct dp_txrx_peer *txrx_peer,
  3965. uint8_t tid,
  3966. uint64_t txdesc_ts,
  3967. uint32_t ppdu_id)
  3968. {
  3969. }
  3970. #endif
  3971. #ifdef WLAN_FEATURE_PKT_CAPTURE_V2
  3972. /**
  3973. * dp_send_completion_to_pkt_capture() - send tx completion to packet capture
  3974. * @soc: dp_soc handle
  3975. * @desc: Tx Descriptor
  3976. * @ts: HAL Tx completion descriptor contents
  3977. *
  3978. * This function is used to send tx completion to packet capture
  3979. */
  3980. void dp_send_completion_to_pkt_capture(struct dp_soc *soc,
  3981. struct dp_tx_desc_s *desc,
  3982. struct hal_tx_completion_status *ts)
  3983. {
  3984. dp_wdi_event_handler(WDI_EVENT_PKT_CAPTURE_TX_DATA, soc,
  3985. desc, ts->peer_id,
  3986. WDI_NO_VAL, desc->pdev->pdev_id);
  3987. }
  3988. #endif
  3989. /**
  3990. * dp_tx_comp_process_desc() - Process tx descriptor and free associated nbuf
  3991. * @soc: DP Soc handle
  3992. * @tx_desc: software Tx descriptor
  3993. * @ts : Tx completion status from HAL/HTT descriptor
  3994. *
  3995. * Return: none
  3996. */
  3997. void
  3998. dp_tx_comp_process_desc(struct dp_soc *soc,
  3999. struct dp_tx_desc_s *desc,
  4000. struct hal_tx_completion_status *ts,
  4001. struct dp_txrx_peer *txrx_peer)
  4002. {
  4003. uint64_t time_latency = 0;
  4004. uint16_t peer_id = DP_INVALID_PEER_ID;
  4005. /*
  4006. * m_copy/tx_capture modes are not supported for
  4007. * scatter gather packets
  4008. */
  4009. if (qdf_unlikely(!!desc->pdev->latency_capture_enable)) {
  4010. time_latency = (qdf_ktime_to_ms(qdf_ktime_real_get()) -
  4011. qdf_ktime_to_ms(desc->timestamp));
  4012. }
  4013. dp_send_completion_to_pkt_capture(soc, desc, ts);
  4014. if (dp_tx_pkt_tracepoints_enabled())
  4015. qdf_trace_dp_packet(desc->nbuf, QDF_TX,
  4016. desc->msdu_ext_desc ?
  4017. desc->msdu_ext_desc->tso_desc : NULL,
  4018. qdf_ktime_to_ms(desc->timestamp));
  4019. if (!(desc->msdu_ext_desc)) {
  4020. dp_tx_enh_unmap(soc, desc);
  4021. if (txrx_peer)
  4022. peer_id = txrx_peer->peer_id;
  4023. if (QDF_STATUS_SUCCESS ==
  4024. dp_monitor_tx_add_to_comp_queue(soc, desc, ts, peer_id)) {
  4025. return;
  4026. }
  4027. if (QDF_STATUS_SUCCESS ==
  4028. dp_get_completion_indication_for_stack(soc,
  4029. desc->pdev,
  4030. txrx_peer, ts,
  4031. desc->nbuf,
  4032. time_latency)) {
  4033. dp_send_completion_to_stack(soc,
  4034. desc->pdev,
  4035. ts->peer_id,
  4036. ts->ppdu_id,
  4037. desc->nbuf);
  4038. return;
  4039. }
  4040. }
  4041. desc->flags |= DP_TX_DESC_FLAG_COMPLETED_TX;
  4042. dp_tx_comp_free_buf(soc, desc, false);
  4043. }
  4044. #ifdef DISABLE_DP_STATS
  4045. /**
  4046. * dp_tx_update_connectivity_stats() - update tx connectivity stats
  4047. * @soc: core txrx main context
  4048. * @tx_desc: tx desc
  4049. * @status: tx status
  4050. *
  4051. * Return: none
  4052. */
  4053. static inline
  4054. void dp_tx_update_connectivity_stats(struct dp_soc *soc,
  4055. struct dp_vdev *vdev,
  4056. struct dp_tx_desc_s *tx_desc,
  4057. uint8_t status)
  4058. {
  4059. }
  4060. #else
  4061. static inline
  4062. void dp_tx_update_connectivity_stats(struct dp_soc *soc,
  4063. struct dp_vdev *vdev,
  4064. struct dp_tx_desc_s *tx_desc,
  4065. uint8_t status)
  4066. {
  4067. void *osif_dev;
  4068. ol_txrx_stats_rx_fp stats_cbk;
  4069. uint8_t pkt_type;
  4070. qdf_assert(tx_desc);
  4071. if (!vdev ||
  4072. !vdev->osif_vdev ||
  4073. !vdev->stats_cb)
  4074. return;
  4075. osif_dev = vdev->osif_vdev;
  4076. stats_cbk = vdev->stats_cb;
  4077. stats_cbk(tx_desc->nbuf, osif_dev, PKT_TYPE_TX_HOST_FW_SENT, &pkt_type);
  4078. if (status == HAL_TX_TQM_RR_FRAME_ACKED)
  4079. stats_cbk(tx_desc->nbuf, osif_dev, PKT_TYPE_TX_ACK_CNT,
  4080. &pkt_type);
  4081. }
  4082. #endif
  4083. #if defined(WLAN_FEATURE_TSF_UPLINK_DELAY) || defined(WLAN_CONFIG_TX_DELAY)
  4084. QDF_STATUS
  4085. dp_tx_compute_hw_delay_us(struct hal_tx_completion_status *ts,
  4086. uint32_t delta_tsf,
  4087. uint32_t *delay_us)
  4088. {
  4089. uint32_t buffer_ts;
  4090. uint32_t delay;
  4091. if (!delay_us)
  4092. return QDF_STATUS_E_INVAL;
  4093. /* Tx_rate_stats_info_valid is 0 and tsf is invalid then */
  4094. if (!ts->valid)
  4095. return QDF_STATUS_E_INVAL;
  4096. /* buffer_timestamp is in units of 1024 us and is [31:13] of
  4097. * WBM_RELEASE_RING_4. After left shift 10 bits, it's
  4098. * valid up to 29 bits.
  4099. */
  4100. buffer_ts = ts->buffer_timestamp << 10;
  4101. delay = ts->tsf - buffer_ts - delta_tsf;
  4102. delay &= 0x1FFFFFFF; /* mask 29 BITS */
  4103. if (delay > 0x1000000) {
  4104. dp_info_rl("----------------------\n"
  4105. "Tx completion status:\n"
  4106. "----------------------\n"
  4107. "release_src = %d\n"
  4108. "ppdu_id = 0x%x\n"
  4109. "release_reason = %d\n"
  4110. "tsf = %u (0x%x)\n"
  4111. "buffer_timestamp = %u (0x%x)\n"
  4112. "delta_tsf = %u (0x%x)\n",
  4113. ts->release_src, ts->ppdu_id, ts->status,
  4114. ts->tsf, ts->tsf, ts->buffer_timestamp,
  4115. ts->buffer_timestamp, delta_tsf, delta_tsf);
  4116. return QDF_STATUS_E_FAILURE;
  4117. }
  4118. *delay_us = delay;
  4119. return QDF_STATUS_SUCCESS;
  4120. }
  4121. void dp_set_delta_tsf(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  4122. uint32_t delta_tsf)
  4123. {
  4124. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  4125. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  4126. DP_MOD_ID_CDP);
  4127. if (!vdev) {
  4128. dp_err_rl("vdev %d does not exist", vdev_id);
  4129. return;
  4130. }
  4131. vdev->delta_tsf = delta_tsf;
  4132. dp_debug("vdev id %u delta_tsf %u", vdev_id, delta_tsf);
  4133. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  4134. }
  4135. #endif
  4136. #ifdef WLAN_FEATURE_TSF_UPLINK_DELAY
  4137. QDF_STATUS dp_set_tsf_ul_delay_report(struct cdp_soc_t *soc_hdl,
  4138. uint8_t vdev_id, bool enable)
  4139. {
  4140. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  4141. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  4142. DP_MOD_ID_CDP);
  4143. if (!vdev) {
  4144. dp_err_rl("vdev %d does not exist", vdev_id);
  4145. return QDF_STATUS_E_FAILURE;
  4146. }
  4147. qdf_atomic_set(&vdev->ul_delay_report, enable);
  4148. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  4149. return QDF_STATUS_SUCCESS;
  4150. }
  4151. QDF_STATUS dp_get_uplink_delay(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  4152. uint32_t *val)
  4153. {
  4154. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  4155. struct dp_vdev *vdev;
  4156. uint32_t delay_accum;
  4157. uint32_t pkts_accum;
  4158. vdev = dp_vdev_get_ref_by_id(soc, vdev_id, DP_MOD_ID_CDP);
  4159. if (!vdev) {
  4160. dp_err_rl("vdev %d does not exist", vdev_id);
  4161. return QDF_STATUS_E_FAILURE;
  4162. }
  4163. if (!qdf_atomic_read(&vdev->ul_delay_report)) {
  4164. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  4165. return QDF_STATUS_E_FAILURE;
  4166. }
  4167. /* Average uplink delay based on current accumulated values */
  4168. delay_accum = qdf_atomic_read(&vdev->ul_delay_accum);
  4169. pkts_accum = qdf_atomic_read(&vdev->ul_pkts_accum);
  4170. *val = delay_accum / pkts_accum;
  4171. dp_debug("uplink_delay %u delay_accum %u pkts_accum %u", *val,
  4172. delay_accum, pkts_accum);
  4173. /* Reset accumulated values to 0 */
  4174. qdf_atomic_set(&vdev->ul_delay_accum, 0);
  4175. qdf_atomic_set(&vdev->ul_pkts_accum, 0);
  4176. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  4177. return QDF_STATUS_SUCCESS;
  4178. }
  4179. static void dp_tx_update_uplink_delay(struct dp_soc *soc, struct dp_vdev *vdev,
  4180. struct hal_tx_completion_status *ts)
  4181. {
  4182. uint32_t ul_delay;
  4183. if (qdf_unlikely(!vdev)) {
  4184. dp_info_rl("vdev is null or delete in progrss");
  4185. return;
  4186. }
  4187. if (!qdf_atomic_read(&vdev->ul_delay_report))
  4188. return;
  4189. if (QDF_IS_STATUS_ERROR(dp_tx_compute_hw_delay_us(ts,
  4190. vdev->delta_tsf,
  4191. &ul_delay)))
  4192. return;
  4193. ul_delay /= 1000; /* in unit of ms */
  4194. qdf_atomic_add(ul_delay, &vdev->ul_delay_accum);
  4195. qdf_atomic_inc(&vdev->ul_pkts_accum);
  4196. }
  4197. #else /* !WLAN_FEATURE_TSF_UPLINK_DELAY */
  4198. static inline
  4199. void dp_tx_update_uplink_delay(struct dp_soc *soc, struct dp_vdev *vdev,
  4200. struct hal_tx_completion_status *ts)
  4201. {
  4202. }
  4203. #endif /* WLAN_FEATURE_TSF_UPLINK_DELAY */
  4204. /**
  4205. * dp_tx_comp_process_tx_status() - Parse and Dump Tx completion status info
  4206. * @soc: DP soc handle
  4207. * @tx_desc: software descriptor head pointer
  4208. * @ts: Tx completion status
  4209. * @txrx_peer: txrx peer handle
  4210. * @ring_id: ring number
  4211. *
  4212. * Return: none
  4213. */
  4214. void dp_tx_comp_process_tx_status(struct dp_soc *soc,
  4215. struct dp_tx_desc_s *tx_desc,
  4216. struct hal_tx_completion_status *ts,
  4217. struct dp_txrx_peer *txrx_peer,
  4218. uint8_t ring_id)
  4219. {
  4220. uint32_t length;
  4221. qdf_ether_header_t *eh;
  4222. struct dp_vdev *vdev = NULL;
  4223. qdf_nbuf_t nbuf = tx_desc->nbuf;
  4224. enum qdf_dp_tx_rx_status dp_status;
  4225. if (!nbuf) {
  4226. dp_info_rl("invalid tx descriptor. nbuf NULL");
  4227. goto out;
  4228. }
  4229. eh = (qdf_ether_header_t *)qdf_nbuf_data(nbuf);
  4230. length = qdf_nbuf_len(nbuf);
  4231. dp_status = dp_tx_hw_to_qdf(ts->status);
  4232. DPTRACE(qdf_dp_trace_ptr(tx_desc->nbuf,
  4233. QDF_DP_TRACE_LI_DP_FREE_PACKET_PTR_RECORD,
  4234. QDF_TRACE_DEFAULT_PDEV_ID,
  4235. qdf_nbuf_data_addr(nbuf),
  4236. sizeof(qdf_nbuf_data(nbuf)),
  4237. tx_desc->id, ts->status, dp_status));
  4238. dp_tx_comp_debug("-------------------- \n"
  4239. "Tx Completion Stats: \n"
  4240. "-------------------- \n"
  4241. "ack_frame_rssi = %d \n"
  4242. "first_msdu = %d \n"
  4243. "last_msdu = %d \n"
  4244. "msdu_part_of_amsdu = %d \n"
  4245. "rate_stats valid = %d \n"
  4246. "bw = %d \n"
  4247. "pkt_type = %d \n"
  4248. "stbc = %d \n"
  4249. "ldpc = %d \n"
  4250. "sgi = %d \n"
  4251. "mcs = %d \n"
  4252. "ofdma = %d \n"
  4253. "tones_in_ru = %d \n"
  4254. "tsf = %d \n"
  4255. "ppdu_id = %d \n"
  4256. "transmit_cnt = %d \n"
  4257. "tid = %d \n"
  4258. "peer_id = %d\n"
  4259. "tx_status = %d\n",
  4260. ts->ack_frame_rssi, ts->first_msdu,
  4261. ts->last_msdu, ts->msdu_part_of_amsdu,
  4262. ts->valid, ts->bw, ts->pkt_type, ts->stbc,
  4263. ts->ldpc, ts->sgi, ts->mcs, ts->ofdma,
  4264. ts->tones_in_ru, ts->tsf, ts->ppdu_id,
  4265. ts->transmit_cnt, ts->tid, ts->peer_id,
  4266. ts->status);
  4267. /* Update SoC level stats */
  4268. DP_STATS_INCC(soc, tx.dropped_fw_removed, 1,
  4269. (ts->status == HAL_TX_TQM_RR_REM_CMD_REM));
  4270. if (!txrx_peer) {
  4271. dp_info_rl("peer is null or deletion in progress");
  4272. DP_STATS_INC_PKT(soc, tx.tx_invalid_peer, 1, length);
  4273. goto out;
  4274. }
  4275. vdev = txrx_peer->vdev;
  4276. dp_tx_update_connectivity_stats(soc, vdev, tx_desc, ts->status);
  4277. dp_tx_update_uplink_delay(soc, vdev, ts);
  4278. /* check tx complete notification */
  4279. if (qdf_nbuf_tx_notify_comp_get(nbuf))
  4280. dp_tx_notify_completion(soc, vdev, tx_desc,
  4281. nbuf, ts->status);
  4282. /* Update per-packet stats for mesh mode */
  4283. if (qdf_unlikely(vdev->mesh_vdev) &&
  4284. !(tx_desc->flags & DP_TX_DESC_FLAG_TO_FW))
  4285. dp_tx_comp_fill_tx_completion_stats(tx_desc, ts);
  4286. /* Update peer level stats */
  4287. if (qdf_unlikely(txrx_peer->bss_peer &&
  4288. vdev->opmode == wlan_op_mode_ap)) {
  4289. if (ts->status != HAL_TX_TQM_RR_REM_CMD_REM) {
  4290. DP_PEER_PER_PKT_STATS_INC_PKT(txrx_peer, tx.mcast, 1,
  4291. length);
  4292. if (txrx_peer->vdev->tx_encap_type ==
  4293. htt_cmn_pkt_type_ethernet &&
  4294. QDF_IS_ADDR_BROADCAST(eh->ether_dhost)) {
  4295. DP_PEER_PER_PKT_STATS_INC_PKT(txrx_peer,
  4296. tx.bcast, 1,
  4297. length);
  4298. }
  4299. }
  4300. } else {
  4301. DP_PEER_PER_PKT_STATS_INC_PKT(txrx_peer, tx.ucast, 1, length);
  4302. if (ts->status == HAL_TX_TQM_RR_FRAME_ACKED) {
  4303. DP_PEER_PER_PKT_STATS_INC_PKT(txrx_peer, tx.tx_success,
  4304. 1, length);
  4305. if (qdf_unlikely(txrx_peer->in_twt)) {
  4306. DP_PEER_PER_PKT_STATS_INC_PKT(txrx_peer,
  4307. tx.tx_success_twt,
  4308. 1, length);
  4309. }
  4310. }
  4311. }
  4312. dp_tx_update_peer_stats(tx_desc, ts, txrx_peer, ring_id);
  4313. dp_tx_update_peer_delay_stats(txrx_peer, tx_desc, ts->tid, ring_id);
  4314. dp_tx_update_peer_sawf_stats(soc, vdev, txrx_peer, tx_desc,
  4315. ts, ts->tid);
  4316. dp_tx_send_pktlog(soc, vdev->pdev, tx_desc, nbuf, dp_status);
  4317. #ifdef QCA_SUPPORT_RDK_STATS
  4318. if (soc->peerstats_enabled)
  4319. dp_tx_sojourn_stats_process(vdev->pdev, txrx_peer, ts->tid,
  4320. qdf_ktime_to_ms(tx_desc->timestamp),
  4321. ts->ppdu_id);
  4322. #endif
  4323. out:
  4324. return;
  4325. }
  4326. #if defined(QCA_VDEV_STATS_HW_OFFLOAD_SUPPORT) && \
  4327. defined(QCA_ENHANCED_STATS_SUPPORT)
  4328. /*
  4329. * dp_tx_update_peer_basic_stats(): Update peer basic stats
  4330. * @txrx_peer: Datapath txrx_peer handle
  4331. * @length: Length of the packet
  4332. * @tx_status: Tx status from TQM/FW
  4333. * @update: enhanced flag value present in dp_pdev
  4334. *
  4335. * Return: none
  4336. */
  4337. void dp_tx_update_peer_basic_stats(struct dp_txrx_peer *txrx_peer,
  4338. uint32_t length, uint8_t tx_status,
  4339. bool update)
  4340. {
  4341. if (update || (!txrx_peer->hw_txrx_stats_en)) {
  4342. DP_PEER_STATS_FLAT_INC_PKT(txrx_peer, comp_pkt, 1, length);
  4343. if (tx_status != HAL_TX_TQM_RR_FRAME_ACKED)
  4344. DP_PEER_STATS_FLAT_INC(txrx_peer, tx_failed, 1);
  4345. }
  4346. }
  4347. #elif defined(QCA_VDEV_STATS_HW_OFFLOAD_SUPPORT)
  4348. void dp_tx_update_peer_basic_stats(struct dp_txrx_peer *txrx_peer,
  4349. uint32_t length, uint8_t tx_status,
  4350. bool update)
  4351. {
  4352. if (!txrx_peer->hw_txrx_stats_en) {
  4353. DP_PEER_STATS_FLAT_INC_PKT(txrx_peer, comp_pkt, 1, length);
  4354. if (tx_status != HAL_TX_TQM_RR_FRAME_ACKED)
  4355. DP_PEER_STATS_FLAT_INC(txrx_peer, tx_failed, 1);
  4356. }
  4357. }
  4358. #else
  4359. void dp_tx_update_peer_basic_stats(struct dp_txrx_peer *txrx_peer,
  4360. uint32_t length, uint8_t tx_status,
  4361. bool update)
  4362. {
  4363. DP_PEER_STATS_FLAT_INC_PKT(txrx_peer, comp_pkt, 1, length);
  4364. if (tx_status != HAL_TX_TQM_RR_FRAME_ACKED)
  4365. DP_PEER_STATS_FLAT_INC(txrx_peer, tx_failed, 1);
  4366. }
  4367. #endif
  4368. /*
  4369. * dp_tx_prefetch_next_nbuf_data(): Prefetch nbuf and nbuf data
  4370. * @nbuf: skb buffer
  4371. *
  4372. * Return: none
  4373. */
  4374. #ifdef QCA_DP_RX_NBUF_AND_NBUF_DATA_PREFETCH
  4375. static inline
  4376. void dp_tx_prefetch_next_nbuf_data(struct dp_tx_desc_s *next)
  4377. {
  4378. qdf_nbuf_t nbuf = NULL;
  4379. if (next)
  4380. nbuf = next->nbuf;
  4381. if (nbuf) {
  4382. /* prefetch skb->next and first few bytes of skb->cb */
  4383. qdf_prefetch(next->shinfo_addr);
  4384. qdf_prefetch(nbuf);
  4385. /* prefetch skb fields present in different cachelines */
  4386. qdf_prefetch(&nbuf->len);
  4387. qdf_prefetch(&nbuf->users);
  4388. }
  4389. }
  4390. #else
  4391. static inline
  4392. void dp_tx_prefetch_next_nbuf_data(struct dp_tx_desc_s *next)
  4393. {
  4394. }
  4395. #endif
  4396. /**
  4397. * dp_tx_mcast_reinject_handler() - Tx reinjected multicast packets handler
  4398. * @soc: core txrx main context
  4399. * @desc: software descriptor
  4400. *
  4401. * Return: true when packet is reinjected
  4402. */
  4403. #if defined(WLAN_FEATURE_11BE_MLO) && defined(WLAN_MLO_MULTI_CHIP) && \
  4404. defined(WLAN_MCAST_MLO)
  4405. static inline bool
  4406. dp_tx_mcast_reinject_handler(struct dp_soc *soc, struct dp_tx_desc_s *desc)
  4407. {
  4408. struct dp_vdev *vdev = NULL;
  4409. if (desc->tx_status == HAL_TX_TQM_RR_MULTICAST_DROP) {
  4410. if (!soc->arch_ops.dp_tx_mcast_handler)
  4411. return false;
  4412. vdev = dp_vdev_get_ref_by_id(soc, desc->vdev_id,
  4413. DP_MOD_ID_REINJECT);
  4414. if (qdf_unlikely(!vdev)) {
  4415. dp_tx_comp_info_rl("Unable to get vdev ref %d",
  4416. desc->id);
  4417. return false;
  4418. }
  4419. DP_STATS_INC_PKT(vdev, tx_i.reinject_pkts, 1,
  4420. qdf_nbuf_len(desc->nbuf));
  4421. soc->arch_ops.dp_tx_mcast_handler(soc, vdev, desc->nbuf);
  4422. dp_tx_desc_release(desc, desc->pool_id);
  4423. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_REINJECT);
  4424. return true;
  4425. }
  4426. return false;
  4427. }
  4428. #else
  4429. static inline bool
  4430. dp_tx_mcast_reinject_handler(struct dp_soc *soc, struct dp_tx_desc_s *desc)
  4431. {
  4432. return false;
  4433. }
  4434. #endif
  4435. /**
  4436. * dp_tx_comp_process_desc_list() - Tx complete software descriptor handler
  4437. * @soc: core txrx main context
  4438. * @comp_head: software descriptor head pointer
  4439. * @ring_id: ring number
  4440. *
  4441. * This function will process batch of descriptors reaped by dp_tx_comp_handler
  4442. * and release the software descriptors after processing is complete
  4443. *
  4444. * Return: none
  4445. */
  4446. static void
  4447. dp_tx_comp_process_desc_list(struct dp_soc *soc,
  4448. struct dp_tx_desc_s *comp_head, uint8_t ring_id)
  4449. {
  4450. struct dp_tx_desc_s *desc;
  4451. struct dp_tx_desc_s *next;
  4452. struct hal_tx_completion_status ts;
  4453. struct dp_txrx_peer *txrx_peer = NULL;
  4454. uint16_t peer_id = DP_INVALID_PEER;
  4455. dp_txrx_ref_handle txrx_ref_handle = NULL;
  4456. desc = comp_head;
  4457. while (desc) {
  4458. next = desc->next;
  4459. dp_tx_prefetch_next_nbuf_data(next);
  4460. if (peer_id != desc->peer_id) {
  4461. if (txrx_peer)
  4462. dp_txrx_peer_unref_delete(txrx_ref_handle,
  4463. DP_MOD_ID_TX_COMP);
  4464. peer_id = desc->peer_id;
  4465. txrx_peer =
  4466. dp_txrx_peer_get_ref_by_id(soc, peer_id,
  4467. &txrx_ref_handle,
  4468. DP_MOD_ID_TX_COMP);
  4469. }
  4470. if (dp_tx_mcast_reinject_handler(soc, desc)) {
  4471. desc = next;
  4472. continue;
  4473. }
  4474. if (qdf_likely(desc->flags & DP_TX_DESC_FLAG_SIMPLE)) {
  4475. struct dp_pdev *pdev = desc->pdev;
  4476. if (qdf_likely(txrx_peer))
  4477. dp_tx_update_peer_basic_stats(txrx_peer,
  4478. desc->length,
  4479. desc->tx_status,
  4480. false);
  4481. qdf_assert(pdev);
  4482. dp_tx_outstanding_dec(pdev);
  4483. /*
  4484. * Calling a QDF WRAPPER here is creating signifcant
  4485. * performance impact so avoided the wrapper call here
  4486. */
  4487. dp_tx_desc_history_add(soc, desc->dma_addr, desc->nbuf,
  4488. desc->id, DP_TX_COMP_UNMAP);
  4489. dp_tx_nbuf_unmap(soc, desc);
  4490. qdf_nbuf_free_simple(desc->nbuf);
  4491. dp_tx_desc_free(soc, desc, desc->pool_id);
  4492. desc = next;
  4493. continue;
  4494. }
  4495. hal_tx_comp_get_status(&desc->comp, &ts, soc->hal_soc);
  4496. dp_tx_comp_process_tx_status(soc, desc, &ts, txrx_peer,
  4497. ring_id);
  4498. dp_tx_comp_process_desc(soc, desc, &ts, txrx_peer);
  4499. dp_tx_desc_release(desc, desc->pool_id);
  4500. desc = next;
  4501. }
  4502. if (txrx_peer)
  4503. dp_txrx_peer_unref_delete(txrx_ref_handle, DP_MOD_ID_TX_COMP);
  4504. }
  4505. #ifdef WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT
  4506. static inline
  4507. bool dp_tx_comp_loop_pkt_limit_hit(struct dp_soc *soc, int num_reaped,
  4508. int max_reap_limit)
  4509. {
  4510. bool limit_hit = false;
  4511. limit_hit =
  4512. (num_reaped >= max_reap_limit) ? true : false;
  4513. if (limit_hit)
  4514. DP_STATS_INC(soc, tx.tx_comp_loop_pkt_limit_hit, 1);
  4515. return limit_hit;
  4516. }
  4517. static inline bool dp_tx_comp_enable_eol_data_check(struct dp_soc *soc)
  4518. {
  4519. return soc->wlan_cfg_ctx->tx_comp_enable_eol_data_check;
  4520. }
  4521. static inline int dp_tx_comp_get_loop_pkt_limit(struct dp_soc *soc)
  4522. {
  4523. struct wlan_cfg_dp_soc_ctxt *cfg = soc->wlan_cfg_ctx;
  4524. return cfg->tx_comp_loop_pkt_limit;
  4525. }
  4526. #else
  4527. static inline
  4528. bool dp_tx_comp_loop_pkt_limit_hit(struct dp_soc *soc, int num_reaped,
  4529. int max_reap_limit)
  4530. {
  4531. return false;
  4532. }
  4533. static inline bool dp_tx_comp_enable_eol_data_check(struct dp_soc *soc)
  4534. {
  4535. return false;
  4536. }
  4537. static inline int dp_tx_comp_get_loop_pkt_limit(struct dp_soc *soc)
  4538. {
  4539. return 0;
  4540. }
  4541. #endif
  4542. #ifdef WLAN_FEATURE_NEAR_FULL_IRQ
  4543. static inline int
  4544. dp_srng_test_and_update_nf_params(struct dp_soc *soc, struct dp_srng *dp_srng,
  4545. int *max_reap_limit)
  4546. {
  4547. return soc->arch_ops.dp_srng_test_and_update_nf_params(soc, dp_srng,
  4548. max_reap_limit);
  4549. }
  4550. #else
  4551. static inline int
  4552. dp_srng_test_and_update_nf_params(struct dp_soc *soc, struct dp_srng *dp_srng,
  4553. int *max_reap_limit)
  4554. {
  4555. return 0;
  4556. }
  4557. #endif
  4558. #ifdef DP_TX_TRACKING
  4559. void dp_tx_desc_check_corruption(struct dp_tx_desc_s *tx_desc)
  4560. {
  4561. if ((tx_desc->magic != DP_TX_MAGIC_PATTERN_INUSE) &&
  4562. (tx_desc->magic != DP_TX_MAGIC_PATTERN_FREE)) {
  4563. dp_err_rl("tx_desc %u is corrupted", tx_desc->id);
  4564. qdf_trigger_self_recovery(NULL, QDF_TX_DESC_LEAK);
  4565. }
  4566. }
  4567. #endif
  4568. uint32_t dp_tx_comp_handler(struct dp_intr *int_ctx, struct dp_soc *soc,
  4569. hal_ring_handle_t hal_ring_hdl, uint8_t ring_id,
  4570. uint32_t quota)
  4571. {
  4572. void *tx_comp_hal_desc;
  4573. void *last_prefetched_hw_desc = NULL;
  4574. struct dp_tx_desc_s *last_prefetched_sw_desc = NULL;
  4575. hal_soc_handle_t hal_soc;
  4576. uint8_t buffer_src;
  4577. struct dp_tx_desc_s *tx_desc = NULL;
  4578. struct dp_tx_desc_s *head_desc = NULL;
  4579. struct dp_tx_desc_s *tail_desc = NULL;
  4580. uint32_t num_processed = 0;
  4581. uint32_t count;
  4582. uint32_t num_avail_for_reap = 0;
  4583. bool force_break = false;
  4584. struct dp_srng *tx_comp_ring = &soc->tx_comp_ring[ring_id];
  4585. int max_reap_limit, ring_near_full;
  4586. DP_HIST_INIT();
  4587. more_data:
  4588. hal_soc = soc->hal_soc;
  4589. /* Re-initialize local variables to be re-used */
  4590. head_desc = NULL;
  4591. tail_desc = NULL;
  4592. count = 0;
  4593. max_reap_limit = dp_tx_comp_get_loop_pkt_limit(soc);
  4594. ring_near_full = dp_srng_test_and_update_nf_params(soc, tx_comp_ring,
  4595. &max_reap_limit);
  4596. if (qdf_unlikely(dp_srng_access_start(int_ctx, soc, hal_ring_hdl))) {
  4597. dp_err("HAL RING Access Failed -- %pK", hal_ring_hdl);
  4598. return 0;
  4599. }
  4600. num_avail_for_reap = hal_srng_dst_num_valid(hal_soc, hal_ring_hdl, 0);
  4601. if (num_avail_for_reap >= quota)
  4602. num_avail_for_reap = quota;
  4603. dp_srng_dst_inv_cached_descs(soc, hal_ring_hdl, num_avail_for_reap);
  4604. last_prefetched_hw_desc = dp_srng_dst_prefetch_32_byte_desc(hal_soc,
  4605. hal_ring_hdl,
  4606. num_avail_for_reap);
  4607. /* Find head descriptor from completion ring */
  4608. while (qdf_likely(num_avail_for_reap--)) {
  4609. tx_comp_hal_desc = dp_srng_dst_get_next(soc, hal_ring_hdl);
  4610. if (qdf_unlikely(!tx_comp_hal_desc))
  4611. break;
  4612. buffer_src = hal_tx_comp_get_buffer_source(hal_soc,
  4613. tx_comp_hal_desc);
  4614. /* If this buffer was not released by TQM or FW, then it is not
  4615. * Tx completion indication, assert */
  4616. if (qdf_unlikely(buffer_src !=
  4617. HAL_TX_COMP_RELEASE_SOURCE_TQM) &&
  4618. (qdf_unlikely(buffer_src !=
  4619. HAL_TX_COMP_RELEASE_SOURCE_FW))) {
  4620. uint8_t wbm_internal_error;
  4621. dp_err_rl(
  4622. "Tx comp release_src != TQM | FW but from %d",
  4623. buffer_src);
  4624. hal_dump_comp_desc(tx_comp_hal_desc);
  4625. DP_STATS_INC(soc, tx.invalid_release_source, 1);
  4626. /* When WBM sees NULL buffer_addr_info in any of
  4627. * ingress rings it sends an error indication,
  4628. * with wbm_internal_error=1, to a specific ring.
  4629. * The WBM2SW ring used to indicate these errors is
  4630. * fixed in HW, and that ring is being used as Tx
  4631. * completion ring. These errors are not related to
  4632. * Tx completions, and should just be ignored
  4633. */
  4634. wbm_internal_error = hal_get_wbm_internal_error(
  4635. hal_soc,
  4636. tx_comp_hal_desc);
  4637. if (wbm_internal_error) {
  4638. dp_err_rl("Tx comp wbm_internal_error!!");
  4639. DP_STATS_INC(soc, tx.wbm_internal_error[WBM_INT_ERROR_ALL], 1);
  4640. if (HAL_TX_COMP_RELEASE_SOURCE_REO ==
  4641. buffer_src)
  4642. dp_handle_wbm_internal_error(
  4643. soc,
  4644. tx_comp_hal_desc,
  4645. hal_tx_comp_get_buffer_type(
  4646. tx_comp_hal_desc));
  4647. } else {
  4648. dp_err_rl("Tx comp wbm_internal_error false");
  4649. DP_STATS_INC(soc, tx.non_wbm_internal_err, 1);
  4650. }
  4651. continue;
  4652. }
  4653. soc->arch_ops.tx_comp_get_params_from_hal_desc(soc,
  4654. tx_comp_hal_desc,
  4655. &tx_desc);
  4656. if (!tx_desc) {
  4657. dp_err("unable to retrieve tx_desc!");
  4658. QDF_BUG(0);
  4659. continue;
  4660. }
  4661. tx_desc->buffer_src = buffer_src;
  4662. /*
  4663. * If the release source is FW, process the HTT status
  4664. */
  4665. if (qdf_unlikely(buffer_src ==
  4666. HAL_TX_COMP_RELEASE_SOURCE_FW)) {
  4667. uint8_t htt_tx_status[HAL_TX_COMP_HTT_STATUS_LEN];
  4668. hal_tx_comp_get_htt_desc(tx_comp_hal_desc,
  4669. htt_tx_status);
  4670. /* Collect hw completion contents */
  4671. hal_tx_comp_desc_sync(tx_comp_hal_desc,
  4672. &tx_desc->comp, 1);
  4673. soc->arch_ops.dp_tx_process_htt_completion(
  4674. soc,
  4675. tx_desc,
  4676. htt_tx_status,
  4677. ring_id);
  4678. } else {
  4679. tx_desc->tx_status =
  4680. hal_tx_comp_get_tx_status(tx_comp_hal_desc);
  4681. tx_desc->buffer_src = buffer_src;
  4682. /*
  4683. * If the fast completion mode is enabled extended
  4684. * metadata from descriptor is not copied
  4685. */
  4686. if (qdf_likely(tx_desc->flags &
  4687. DP_TX_DESC_FLAG_SIMPLE))
  4688. goto add_to_pool;
  4689. /*
  4690. * If the descriptor is already freed in vdev_detach,
  4691. * continue to next descriptor
  4692. */
  4693. if (qdf_unlikely
  4694. ((tx_desc->vdev_id == DP_INVALID_VDEV_ID) &&
  4695. !tx_desc->flags)) {
  4696. dp_tx_comp_info_rl("Descriptor freed in vdev_detach %d",
  4697. tx_desc->id);
  4698. DP_STATS_INC(soc, tx.tx_comp_exception, 1);
  4699. dp_tx_desc_check_corruption(tx_desc);
  4700. continue;
  4701. }
  4702. if (qdf_unlikely(tx_desc->pdev->is_pdev_down)) {
  4703. dp_tx_comp_info_rl("pdev in down state %d",
  4704. tx_desc->id);
  4705. tx_desc->flags |= DP_TX_DESC_FLAG_TX_COMP_ERR;
  4706. dp_tx_comp_free_buf(soc, tx_desc, false);
  4707. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  4708. goto next_desc;
  4709. }
  4710. if (!(tx_desc->flags & DP_TX_DESC_FLAG_ALLOCATED) ||
  4711. !(tx_desc->flags & DP_TX_DESC_FLAG_QUEUED_TX)) {
  4712. dp_tx_comp_alert("Txdesc invalid, flgs = %x,id = %d",
  4713. tx_desc->flags, tx_desc->id);
  4714. qdf_assert_always(0);
  4715. }
  4716. /* Collect hw completion contents */
  4717. hal_tx_comp_desc_sync(tx_comp_hal_desc,
  4718. &tx_desc->comp, 1);
  4719. add_to_pool:
  4720. DP_HIST_PACKET_COUNT_INC(tx_desc->pdev->pdev_id);
  4721. /* First ring descriptor on the cycle */
  4722. if (!head_desc) {
  4723. head_desc = tx_desc;
  4724. tail_desc = tx_desc;
  4725. }
  4726. tail_desc->next = tx_desc;
  4727. tx_desc->next = NULL;
  4728. tail_desc = tx_desc;
  4729. }
  4730. next_desc:
  4731. num_processed += !(count & DP_TX_NAPI_BUDGET_DIV_MASK);
  4732. /*
  4733. * Processed packet count is more than given quota
  4734. * stop to processing
  4735. */
  4736. count++;
  4737. dp_tx_prefetch_hw_sw_nbuf_desc(soc, hal_soc,
  4738. num_avail_for_reap,
  4739. hal_ring_hdl,
  4740. &last_prefetched_hw_desc,
  4741. &last_prefetched_sw_desc);
  4742. if (dp_tx_comp_loop_pkt_limit_hit(soc, count, max_reap_limit))
  4743. break;
  4744. }
  4745. dp_srng_access_end(int_ctx, soc, hal_ring_hdl);
  4746. /* Process the reaped descriptors */
  4747. if (head_desc)
  4748. dp_tx_comp_process_desc_list(soc, head_desc, ring_id);
  4749. DP_STATS_INC(soc, tx.tx_comp[ring_id], count);
  4750. /*
  4751. * If we are processing in near-full condition, there are 3 scenario
  4752. * 1) Ring entries has reached critical state
  4753. * 2) Ring entries are still near high threshold
  4754. * 3) Ring entries are below the safe level
  4755. *
  4756. * One more loop will move te state to normal processing and yield
  4757. */
  4758. if (ring_near_full)
  4759. goto more_data;
  4760. if (dp_tx_comp_enable_eol_data_check(soc)) {
  4761. if (num_processed >= quota)
  4762. force_break = true;
  4763. if (!force_break &&
  4764. hal_srng_dst_peek_sync_locked(soc->hal_soc,
  4765. hal_ring_hdl)) {
  4766. DP_STATS_INC(soc, tx.hp_oos2, 1);
  4767. if (!hif_exec_should_yield(soc->hif_handle,
  4768. int_ctx->dp_intr_id))
  4769. goto more_data;
  4770. }
  4771. }
  4772. DP_TX_HIST_STATS_PER_PDEV();
  4773. return num_processed;
  4774. }
  4775. #ifdef FEATURE_WLAN_TDLS
  4776. qdf_nbuf_t dp_tx_non_std(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  4777. enum ol_tx_spec tx_spec, qdf_nbuf_t msdu_list)
  4778. {
  4779. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  4780. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  4781. DP_MOD_ID_TDLS);
  4782. if (!vdev) {
  4783. dp_err("vdev handle for id %d is NULL", vdev_id);
  4784. return NULL;
  4785. }
  4786. if (tx_spec & OL_TX_SPEC_NO_FREE)
  4787. vdev->is_tdls_frame = true;
  4788. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TDLS);
  4789. return dp_tx_send(soc_hdl, vdev_id, msdu_list);
  4790. }
  4791. #endif
  4792. /**
  4793. * dp_tx_vdev_attach() - attach vdev to dp tx
  4794. * @vdev: virtual device instance
  4795. *
  4796. * Return: QDF_STATUS_SUCCESS: success
  4797. * QDF_STATUS_E_RESOURCES: Error return
  4798. */
  4799. QDF_STATUS dp_tx_vdev_attach(struct dp_vdev *vdev)
  4800. {
  4801. int pdev_id;
  4802. /*
  4803. * Fill HTT TCL Metadata with Vdev ID and MAC ID
  4804. */
  4805. DP_TX_TCL_METADATA_TYPE_SET(vdev->htt_tcl_metadata,
  4806. DP_TCL_METADATA_TYPE_VDEV_BASED);
  4807. DP_TX_TCL_METADATA_VDEV_ID_SET(vdev->htt_tcl_metadata,
  4808. vdev->vdev_id);
  4809. pdev_id =
  4810. dp_get_target_pdev_id_for_host_pdev_id(vdev->pdev->soc,
  4811. vdev->pdev->pdev_id);
  4812. DP_TX_TCL_METADATA_PDEV_ID_SET(vdev->htt_tcl_metadata, pdev_id);
  4813. /*
  4814. * Set HTT Extension Valid bit to 0 by default
  4815. */
  4816. DP_TX_TCL_METADATA_VALID_HTT_SET(vdev->htt_tcl_metadata, 0);
  4817. dp_tx_vdev_update_search_flags(vdev);
  4818. return QDF_STATUS_SUCCESS;
  4819. }
  4820. #ifndef FEATURE_WDS
  4821. static inline bool dp_tx_da_search_override(struct dp_vdev *vdev)
  4822. {
  4823. return false;
  4824. }
  4825. #endif
  4826. /**
  4827. * dp_tx_vdev_update_search_flags() - Update vdev flags as per opmode
  4828. * @vdev: virtual device instance
  4829. *
  4830. * Return: void
  4831. *
  4832. */
  4833. void dp_tx_vdev_update_search_flags(struct dp_vdev *vdev)
  4834. {
  4835. struct dp_soc *soc = vdev->pdev->soc;
  4836. /*
  4837. * Enable both AddrY (SA based search) and AddrX (Da based search)
  4838. * for TDLS link
  4839. *
  4840. * Enable AddrY (SA based search) only for non-WDS STA and
  4841. * ProxySTA VAP (in HKv1) modes.
  4842. *
  4843. * In all other VAP modes, only DA based search should be
  4844. * enabled
  4845. */
  4846. if (vdev->opmode == wlan_op_mode_sta &&
  4847. vdev->tdls_link_connected)
  4848. vdev->hal_desc_addr_search_flags =
  4849. (HAL_TX_DESC_ADDRX_EN | HAL_TX_DESC_ADDRY_EN);
  4850. else if ((vdev->opmode == wlan_op_mode_sta) &&
  4851. !dp_tx_da_search_override(vdev))
  4852. vdev->hal_desc_addr_search_flags = HAL_TX_DESC_ADDRY_EN;
  4853. else
  4854. vdev->hal_desc_addr_search_flags = HAL_TX_DESC_ADDRX_EN;
  4855. if (vdev->opmode == wlan_op_mode_sta && !vdev->tdls_link_connected)
  4856. vdev->search_type = soc->sta_mode_search_policy;
  4857. else
  4858. vdev->search_type = HAL_TX_ADDR_SEARCH_DEFAULT;
  4859. }
  4860. static inline bool
  4861. dp_is_tx_desc_flush_match(struct dp_pdev *pdev,
  4862. struct dp_vdev *vdev,
  4863. struct dp_tx_desc_s *tx_desc)
  4864. {
  4865. if (!(tx_desc && (tx_desc->flags & DP_TX_DESC_FLAG_ALLOCATED)))
  4866. return false;
  4867. /*
  4868. * if vdev is given, then only check whether desc
  4869. * vdev match. if vdev is NULL, then check whether
  4870. * desc pdev match.
  4871. */
  4872. return vdev ? (tx_desc->vdev_id == vdev->vdev_id) :
  4873. (tx_desc->pdev == pdev);
  4874. }
  4875. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  4876. /**
  4877. * dp_tx_desc_flush() - release resources associated
  4878. * to TX Desc
  4879. *
  4880. * @dp_pdev: Handle to DP pdev structure
  4881. * @vdev: virtual device instance
  4882. * NULL: no specific Vdev is required and check all allcated TX desc
  4883. * on this pdev.
  4884. * Non-NULL: only check the allocated TX Desc associated to this Vdev.
  4885. *
  4886. * @force_free:
  4887. * true: flush the TX desc.
  4888. * false: only reset the Vdev in each allocated TX desc
  4889. * that associated to current Vdev.
  4890. *
  4891. * This function will go through the TX desc pool to flush
  4892. * the outstanding TX data or reset Vdev to NULL in associated TX
  4893. * Desc.
  4894. */
  4895. void dp_tx_desc_flush(struct dp_pdev *pdev, struct dp_vdev *vdev,
  4896. bool force_free)
  4897. {
  4898. uint8_t i;
  4899. uint32_t j;
  4900. uint32_t num_desc, page_id, offset;
  4901. uint16_t num_desc_per_page;
  4902. struct dp_soc *soc = pdev->soc;
  4903. struct dp_tx_desc_s *tx_desc = NULL;
  4904. struct dp_tx_desc_pool_s *tx_desc_pool = NULL;
  4905. if (!vdev && !force_free) {
  4906. dp_err("Reset TX desc vdev, Vdev param is required!");
  4907. return;
  4908. }
  4909. for (i = 0; i < MAX_TXDESC_POOLS; i++) {
  4910. tx_desc_pool = &soc->tx_desc[i];
  4911. if (!(tx_desc_pool->pool_size) ||
  4912. IS_TX_DESC_POOL_STATUS_INACTIVE(tx_desc_pool) ||
  4913. !(tx_desc_pool->desc_pages.cacheable_pages))
  4914. continue;
  4915. /*
  4916. * Add flow pool lock protection in case pool is freed
  4917. * due to all tx_desc is recycled when handle TX completion.
  4918. * this is not necessary when do force flush as:
  4919. * a. double lock will happen if dp_tx_desc_release is
  4920. * also trying to acquire it.
  4921. * b. dp interrupt has been disabled before do force TX desc
  4922. * flush in dp_pdev_deinit().
  4923. */
  4924. if (!force_free)
  4925. qdf_spin_lock_bh(&tx_desc_pool->flow_pool_lock);
  4926. num_desc = tx_desc_pool->pool_size;
  4927. num_desc_per_page =
  4928. tx_desc_pool->desc_pages.num_element_per_page;
  4929. for (j = 0; j < num_desc; j++) {
  4930. page_id = j / num_desc_per_page;
  4931. offset = j % num_desc_per_page;
  4932. if (qdf_unlikely(!(tx_desc_pool->
  4933. desc_pages.cacheable_pages)))
  4934. break;
  4935. tx_desc = dp_tx_desc_find(soc, i, page_id, offset);
  4936. if (dp_is_tx_desc_flush_match(pdev, vdev, tx_desc)) {
  4937. /*
  4938. * Free TX desc if force free is
  4939. * required, otherwise only reset vdev
  4940. * in this TX desc.
  4941. */
  4942. if (force_free) {
  4943. tx_desc->flags |= DP_TX_DESC_FLAG_FLUSH;
  4944. dp_tx_comp_free_buf(soc, tx_desc,
  4945. false);
  4946. dp_tx_desc_release(tx_desc, i);
  4947. } else {
  4948. tx_desc->vdev_id = DP_INVALID_VDEV_ID;
  4949. }
  4950. }
  4951. }
  4952. if (!force_free)
  4953. qdf_spin_unlock_bh(&tx_desc_pool->flow_pool_lock);
  4954. }
  4955. }
  4956. #else /* QCA_LL_TX_FLOW_CONTROL_V2! */
  4957. /**
  4958. * dp_tx_desc_reset_vdev() - reset vdev to NULL in TX Desc
  4959. *
  4960. * @soc: Handle to DP soc structure
  4961. * @tx_desc: pointer of one TX desc
  4962. * @desc_pool_id: TX Desc pool id
  4963. */
  4964. static inline void
  4965. dp_tx_desc_reset_vdev(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  4966. uint8_t desc_pool_id)
  4967. {
  4968. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  4969. tx_desc->vdev_id = DP_INVALID_VDEV_ID;
  4970. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  4971. }
  4972. void dp_tx_desc_flush(struct dp_pdev *pdev, struct dp_vdev *vdev,
  4973. bool force_free)
  4974. {
  4975. uint8_t i, num_pool;
  4976. uint32_t j;
  4977. uint32_t num_desc, page_id, offset;
  4978. uint16_t num_desc_per_page;
  4979. struct dp_soc *soc = pdev->soc;
  4980. struct dp_tx_desc_s *tx_desc = NULL;
  4981. struct dp_tx_desc_pool_s *tx_desc_pool = NULL;
  4982. if (!vdev && !force_free) {
  4983. dp_err("Reset TX desc vdev, Vdev param is required!");
  4984. return;
  4985. }
  4986. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  4987. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  4988. for (i = 0; i < num_pool; i++) {
  4989. tx_desc_pool = &soc->tx_desc[i];
  4990. if (!tx_desc_pool->desc_pages.cacheable_pages)
  4991. continue;
  4992. num_desc_per_page =
  4993. tx_desc_pool->desc_pages.num_element_per_page;
  4994. for (j = 0; j < num_desc; j++) {
  4995. page_id = j / num_desc_per_page;
  4996. offset = j % num_desc_per_page;
  4997. tx_desc = dp_tx_desc_find(soc, i, page_id, offset);
  4998. if (dp_is_tx_desc_flush_match(pdev, vdev, tx_desc)) {
  4999. if (force_free) {
  5000. tx_desc->flags |= DP_TX_DESC_FLAG_FLUSH;
  5001. dp_tx_comp_free_buf(soc, tx_desc,
  5002. false);
  5003. dp_tx_desc_release(tx_desc, i);
  5004. } else {
  5005. dp_tx_desc_reset_vdev(soc, tx_desc,
  5006. i);
  5007. }
  5008. }
  5009. }
  5010. }
  5011. }
  5012. #endif /* !QCA_LL_TX_FLOW_CONTROL_V2 */
  5013. /**
  5014. * dp_tx_vdev_detach() - detach vdev from dp tx
  5015. * @vdev: virtual device instance
  5016. *
  5017. * Return: QDF_STATUS_SUCCESS: success
  5018. * QDF_STATUS_E_RESOURCES: Error return
  5019. */
  5020. QDF_STATUS dp_tx_vdev_detach(struct dp_vdev *vdev)
  5021. {
  5022. struct dp_pdev *pdev = vdev->pdev;
  5023. /* Reset TX desc associated to this Vdev as NULL */
  5024. dp_tx_desc_flush(pdev, vdev, false);
  5025. return QDF_STATUS_SUCCESS;
  5026. }
  5027. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  5028. /* Pools will be allocated dynamically */
  5029. static QDF_STATUS dp_tx_alloc_static_pools(struct dp_soc *soc, int num_pool,
  5030. int num_desc)
  5031. {
  5032. uint8_t i;
  5033. for (i = 0; i < num_pool; i++) {
  5034. qdf_spinlock_create(&soc->tx_desc[i].flow_pool_lock);
  5035. soc->tx_desc[i].status = FLOW_POOL_INACTIVE;
  5036. }
  5037. return QDF_STATUS_SUCCESS;
  5038. }
  5039. static QDF_STATUS dp_tx_init_static_pools(struct dp_soc *soc, int num_pool,
  5040. uint32_t num_desc)
  5041. {
  5042. return QDF_STATUS_SUCCESS;
  5043. }
  5044. static void dp_tx_deinit_static_pools(struct dp_soc *soc, int num_pool)
  5045. {
  5046. }
  5047. static void dp_tx_delete_static_pools(struct dp_soc *soc, int num_pool)
  5048. {
  5049. uint8_t i;
  5050. for (i = 0; i < num_pool; i++)
  5051. qdf_spinlock_destroy(&soc->tx_desc[i].flow_pool_lock);
  5052. }
  5053. #else /* QCA_LL_TX_FLOW_CONTROL_V2! */
  5054. static QDF_STATUS dp_tx_alloc_static_pools(struct dp_soc *soc, int num_pool,
  5055. uint32_t num_desc)
  5056. {
  5057. uint8_t i, count;
  5058. /* Allocate software Tx descriptor pools */
  5059. for (i = 0; i < num_pool; i++) {
  5060. if (dp_tx_desc_pool_alloc(soc, i, num_desc)) {
  5061. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  5062. FL("Tx Desc Pool alloc %d failed %pK"),
  5063. i, soc);
  5064. goto fail;
  5065. }
  5066. }
  5067. return QDF_STATUS_SUCCESS;
  5068. fail:
  5069. for (count = 0; count < i; count++)
  5070. dp_tx_desc_pool_free(soc, count);
  5071. return QDF_STATUS_E_NOMEM;
  5072. }
  5073. static QDF_STATUS dp_tx_init_static_pools(struct dp_soc *soc, int num_pool,
  5074. uint32_t num_desc)
  5075. {
  5076. uint8_t i;
  5077. for (i = 0; i < num_pool; i++) {
  5078. if (dp_tx_desc_pool_init(soc, i, num_desc)) {
  5079. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  5080. FL("Tx Desc Pool init %d failed %pK"),
  5081. i, soc);
  5082. return QDF_STATUS_E_NOMEM;
  5083. }
  5084. }
  5085. return QDF_STATUS_SUCCESS;
  5086. }
  5087. static void dp_tx_deinit_static_pools(struct dp_soc *soc, int num_pool)
  5088. {
  5089. uint8_t i;
  5090. for (i = 0; i < num_pool; i++)
  5091. dp_tx_desc_pool_deinit(soc, i);
  5092. }
  5093. static void dp_tx_delete_static_pools(struct dp_soc *soc, int num_pool)
  5094. {
  5095. uint8_t i;
  5096. for (i = 0; i < num_pool; i++)
  5097. dp_tx_desc_pool_free(soc, i);
  5098. }
  5099. #endif /* !QCA_LL_TX_FLOW_CONTROL_V2 */
  5100. /**
  5101. * dp_tx_tso_cmn_desc_pool_deinit() - de-initialize TSO descriptors
  5102. * @soc: core txrx main context
  5103. * @num_pool: number of pools
  5104. *
  5105. */
  5106. void dp_tx_tso_cmn_desc_pool_deinit(struct dp_soc *soc, uint8_t num_pool)
  5107. {
  5108. dp_tx_tso_desc_pool_deinit(soc, num_pool);
  5109. dp_tx_tso_num_seg_pool_deinit(soc, num_pool);
  5110. }
  5111. /**
  5112. * dp_tx_tso_cmn_desc_pool_free() - free TSO descriptors
  5113. * @soc: core txrx main context
  5114. * @num_pool: number of pools
  5115. *
  5116. */
  5117. void dp_tx_tso_cmn_desc_pool_free(struct dp_soc *soc, uint8_t num_pool)
  5118. {
  5119. dp_tx_tso_desc_pool_free(soc, num_pool);
  5120. dp_tx_tso_num_seg_pool_free(soc, num_pool);
  5121. }
  5122. /**
  5123. * dp_soc_tx_desc_sw_pools_free() - free all TX descriptors
  5124. * @soc: core txrx main context
  5125. *
  5126. * This function frees all tx related descriptors as below
  5127. * 1. Regular TX descriptors (static pools)
  5128. * 2. extension TX descriptors (used for ME, RAW, TSO etc...)
  5129. * 3. TSO descriptors
  5130. *
  5131. */
  5132. void dp_soc_tx_desc_sw_pools_free(struct dp_soc *soc)
  5133. {
  5134. uint8_t num_pool;
  5135. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  5136. dp_tx_tso_cmn_desc_pool_free(soc, num_pool);
  5137. dp_tx_ext_desc_pool_free(soc, num_pool);
  5138. dp_tx_delete_static_pools(soc, num_pool);
  5139. }
  5140. /**
  5141. * dp_soc_tx_desc_sw_pools_deinit() - de-initialize all TX descriptors
  5142. * @soc: core txrx main context
  5143. *
  5144. * This function de-initializes all tx related descriptors as below
  5145. * 1. Regular TX descriptors (static pools)
  5146. * 2. extension TX descriptors (used for ME, RAW, TSO etc...)
  5147. * 3. TSO descriptors
  5148. *
  5149. */
  5150. void dp_soc_tx_desc_sw_pools_deinit(struct dp_soc *soc)
  5151. {
  5152. uint8_t num_pool;
  5153. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  5154. dp_tx_flow_control_deinit(soc);
  5155. dp_tx_tso_cmn_desc_pool_deinit(soc, num_pool);
  5156. dp_tx_ext_desc_pool_deinit(soc, num_pool);
  5157. dp_tx_deinit_static_pools(soc, num_pool);
  5158. }
  5159. /**
  5160. * dp_tso_attach() - TSO attach handler
  5161. * @txrx_soc: Opaque Dp handle
  5162. *
  5163. * Reserve TSO descriptor buffers
  5164. *
  5165. * Return: QDF_STATUS_E_FAILURE on failure or
  5166. * QDF_STATUS_SUCCESS on success
  5167. */
  5168. QDF_STATUS dp_tx_tso_cmn_desc_pool_alloc(struct dp_soc *soc,
  5169. uint8_t num_pool,
  5170. uint32_t num_desc)
  5171. {
  5172. if (dp_tx_tso_desc_pool_alloc(soc, num_pool, num_desc)) {
  5173. dp_err("TSO Desc Pool alloc %d failed %pK", num_pool, soc);
  5174. return QDF_STATUS_E_FAILURE;
  5175. }
  5176. if (dp_tx_tso_num_seg_pool_alloc(soc, num_pool, num_desc)) {
  5177. dp_err("TSO Num of seg Pool alloc %d failed %pK",
  5178. num_pool, soc);
  5179. return QDF_STATUS_E_FAILURE;
  5180. }
  5181. return QDF_STATUS_SUCCESS;
  5182. }
  5183. /**
  5184. * dp_tx_tso_cmn_desc_pool_init() - TSO cmn desc pool init
  5185. * @soc: DP soc handle
  5186. * @num_pool: Number of pools
  5187. * @num_desc: Number of descriptors
  5188. *
  5189. * Initialize TSO descriptor pools
  5190. *
  5191. * Return: QDF_STATUS_E_FAILURE on failure or
  5192. * QDF_STATUS_SUCCESS on success
  5193. */
  5194. QDF_STATUS dp_tx_tso_cmn_desc_pool_init(struct dp_soc *soc,
  5195. uint8_t num_pool,
  5196. uint32_t num_desc)
  5197. {
  5198. if (dp_tx_tso_desc_pool_init(soc, num_pool, num_desc)) {
  5199. dp_err("TSO Desc Pool alloc %d failed %pK", num_pool, soc);
  5200. return QDF_STATUS_E_FAILURE;
  5201. }
  5202. if (dp_tx_tso_num_seg_pool_init(soc, num_pool, num_desc)) {
  5203. dp_err("TSO Num of seg Pool alloc %d failed %pK",
  5204. num_pool, soc);
  5205. return QDF_STATUS_E_FAILURE;
  5206. }
  5207. return QDF_STATUS_SUCCESS;
  5208. }
  5209. /**
  5210. * dp_soc_tx_desc_sw_pools_alloc() - Allocate tx descriptor pool memory
  5211. * @soc: core txrx main context
  5212. *
  5213. * This function allocates memory for following descriptor pools
  5214. * 1. regular sw tx descriptor pools (static pools)
  5215. * 2. TX extension descriptor pools (ME, RAW, TSO etc...)
  5216. * 3. TSO descriptor pools
  5217. *
  5218. * Return: QDF_STATUS_SUCCESS: success
  5219. * QDF_STATUS_E_RESOURCES: Error return
  5220. */
  5221. QDF_STATUS dp_soc_tx_desc_sw_pools_alloc(struct dp_soc *soc)
  5222. {
  5223. uint8_t num_pool;
  5224. uint32_t num_desc;
  5225. uint32_t num_ext_desc;
  5226. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  5227. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  5228. num_ext_desc = wlan_cfg_get_num_tx_ext_desc(soc->wlan_cfg_ctx);
  5229. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  5230. "%s Tx Desc Alloc num_pool = %d, descs = %d",
  5231. __func__, num_pool, num_desc);
  5232. if ((num_pool > MAX_TXDESC_POOLS) ||
  5233. (num_desc > WLAN_CFG_NUM_TX_DESC_MAX))
  5234. goto fail1;
  5235. if (dp_tx_alloc_static_pools(soc, num_pool, num_desc))
  5236. goto fail1;
  5237. if (dp_tx_ext_desc_pool_alloc(soc, num_pool, num_ext_desc))
  5238. goto fail2;
  5239. if (wlan_cfg_is_tso_desc_attach_defer(soc->wlan_cfg_ctx))
  5240. return QDF_STATUS_SUCCESS;
  5241. if (dp_tx_tso_cmn_desc_pool_alloc(soc, num_pool, num_ext_desc))
  5242. goto fail3;
  5243. return QDF_STATUS_SUCCESS;
  5244. fail3:
  5245. dp_tx_ext_desc_pool_free(soc, num_pool);
  5246. fail2:
  5247. dp_tx_delete_static_pools(soc, num_pool);
  5248. fail1:
  5249. return QDF_STATUS_E_RESOURCES;
  5250. }
  5251. /**
  5252. * dp_soc_tx_desc_sw_pools_init() - Initialise TX descriptor pools
  5253. * @soc: core txrx main context
  5254. *
  5255. * This function initializes the following TX descriptor pools
  5256. * 1. regular sw tx descriptor pools (static pools)
  5257. * 2. TX extension descriptor pools (ME, RAW, TSO etc...)
  5258. * 3. TSO descriptor pools
  5259. *
  5260. * Return: QDF_STATUS_SUCCESS: success
  5261. * QDF_STATUS_E_RESOURCES: Error return
  5262. */
  5263. QDF_STATUS dp_soc_tx_desc_sw_pools_init(struct dp_soc *soc)
  5264. {
  5265. uint8_t num_pool;
  5266. uint32_t num_desc;
  5267. uint32_t num_ext_desc;
  5268. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  5269. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  5270. num_ext_desc = wlan_cfg_get_num_tx_ext_desc(soc->wlan_cfg_ctx);
  5271. if (dp_tx_init_static_pools(soc, num_pool, num_desc))
  5272. goto fail1;
  5273. if (dp_tx_ext_desc_pool_init(soc, num_pool, num_ext_desc))
  5274. goto fail2;
  5275. if (wlan_cfg_is_tso_desc_attach_defer(soc->wlan_cfg_ctx))
  5276. return QDF_STATUS_SUCCESS;
  5277. if (dp_tx_tso_cmn_desc_pool_init(soc, num_pool, num_ext_desc))
  5278. goto fail3;
  5279. dp_tx_flow_control_init(soc);
  5280. soc->process_tx_status = CONFIG_PROCESS_TX_STATUS;
  5281. return QDF_STATUS_SUCCESS;
  5282. fail3:
  5283. dp_tx_ext_desc_pool_deinit(soc, num_pool);
  5284. fail2:
  5285. dp_tx_deinit_static_pools(soc, num_pool);
  5286. fail1:
  5287. return QDF_STATUS_E_RESOURCES;
  5288. }
  5289. /**
  5290. * dp_tso_soc_attach() - Allocate and initialize TSO descriptors
  5291. * @txrx_soc: dp soc handle
  5292. *
  5293. * Return: QDF_STATUS - QDF_STATUS_SUCCESS
  5294. * QDF_STATUS_E_FAILURE
  5295. */
  5296. QDF_STATUS dp_tso_soc_attach(struct cdp_soc_t *txrx_soc)
  5297. {
  5298. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  5299. uint8_t num_pool;
  5300. uint32_t num_desc;
  5301. uint32_t num_ext_desc;
  5302. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  5303. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  5304. num_ext_desc = wlan_cfg_get_num_tx_ext_desc(soc->wlan_cfg_ctx);
  5305. if (dp_tx_tso_cmn_desc_pool_alloc(soc, num_pool, num_ext_desc))
  5306. return QDF_STATUS_E_FAILURE;
  5307. if (dp_tx_tso_cmn_desc_pool_init(soc, num_pool, num_ext_desc))
  5308. return QDF_STATUS_E_FAILURE;
  5309. return QDF_STATUS_SUCCESS;
  5310. }
  5311. /**
  5312. * dp_tso_soc_detach() - de-initialize and free the TSO descriptors
  5313. * @txrx_soc: dp soc handle
  5314. *
  5315. * Return: QDF_STATUS - QDF_STATUS_SUCCESS
  5316. */
  5317. QDF_STATUS dp_tso_soc_detach(struct cdp_soc_t *txrx_soc)
  5318. {
  5319. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  5320. uint8_t num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  5321. dp_tx_tso_cmn_desc_pool_deinit(soc, num_pool);
  5322. dp_tx_tso_cmn_desc_pool_free(soc, num_pool);
  5323. return QDF_STATUS_SUCCESS;
  5324. }
  5325. #ifdef CONFIG_DP_PKT_ADD_TIMESTAMP
  5326. void dp_pkt_add_timestamp(struct dp_vdev *vdev,
  5327. enum qdf_pkt_timestamp_index index, uint64_t time,
  5328. qdf_nbuf_t nbuf)
  5329. {
  5330. if (qdf_unlikely(qdf_is_dp_pkt_timestamp_enabled())) {
  5331. uint64_t tsf_time;
  5332. if (vdev->get_tsf_time) {
  5333. vdev->get_tsf_time(vdev->osif_vdev, time, &tsf_time);
  5334. qdf_add_dp_pkt_timestamp(nbuf, index, tsf_time);
  5335. }
  5336. }
  5337. }
  5338. void dp_pkt_get_timestamp(uint64_t *time)
  5339. {
  5340. if (qdf_unlikely(qdf_is_dp_pkt_timestamp_enabled()))
  5341. *time = qdf_get_log_timestamp();
  5342. }
  5343. #endif