dp_tx.c 139 KB

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