dp_tx.c 143 KB

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