dp_tx.c 143 KB

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