dp_tx.c 152 KB

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