dp_tx.c 157 KB

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