dp_tx.c 178 KB

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