dp_tx.c 177 KB

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