dp_tx_capture.c 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548
  1. /*
  2. * Copyright (c) 2017-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 "qdf_trace.h"
  20. #include "qdf_nbuf.h"
  21. #include "dp_peer.h"
  22. #include "dp_types.h"
  23. #include "dp_internal.h"
  24. #include "htt_ppdu_stats.h"
  25. #include "dp_htt.h"
  26. #include "qdf_mem.h" /* qdf_mem_malloc,free */
  27. #include "cdp_txrx_cmn_struct.h"
  28. #include <enet.h>
  29. #include "dp_tx_capture.h"
  30. #define MAX_MONITOR_HEADER (512)
  31. #define MAX_DUMMY_FRM_BODY (128)
  32. #define DP_BA_ACK_FRAME_SIZE (sizeof(struct ieee80211_ctlframe_addr2) + 36)
  33. #define DP_ACK_FRAME_SIZE (sizeof(struct ieee80211_frame_min_one))
  34. #define DP_CTS_FRAME_SIZE (sizeof(struct ieee80211_frame_min_one))
  35. #define DP_ACKNOACK_FRAME_SIZE (sizeof(struct ieee80211_frame) + 16)
  36. #define DP_MAX_MPDU_64 64
  37. #define DP_NUM_WORDS_PER_PPDU_BITMAP_64 (DP_MAX_MPDU_64 >> 5)
  38. #define DP_NUM_BYTES_PER_PPDU_BITMAP_64 (DP_MAX_MPDU_64 >> 3)
  39. #define DP_NUM_BYTES_PER_PPDU_BITMAP (HAL_RX_MAX_MPDU >> 3)
  40. #define DP_IEEE80211_BAR_CTL_TID_S 12
  41. #define DP_IEEE80211_BAR_CTL_TID_M 0xf
  42. #define DP_IEEE80211_BAR_CTL_POLICY_S 0
  43. #define DP_IEEE80211_BAR_CTL_POLICY_M 0x1
  44. #define DP_IEEE80211_BA_S_SEQ_S 4
  45. #define DP_IEEE80211_BAR_CTL_COMBA 0x0004
  46. #define INVALID_PPDU_ID 0xFFFF
  47. #define MAX_END_TSF 0xFFFFFFFF
  48. #define DP_IEEE80211_CATEGORY_VHT (21)
  49. #define DP_NOACK_SOUNDING_TOKEN_POS (4)
  50. #define DP_NOACK_STOKEN_POS_SHIFT (2)
  51. #define DP_NDPA_TOKEN_POS (16)
  52. /* Macros to handle sequence number bitmaps */
  53. /* HW generated rts frame flag */
  54. #define SEND_WIFIRTS_LEGACY_E 1
  55. /* HW generated 11 AC static bw flag */
  56. #define SEND_WIFIRTS_11AC_STATIC_BW_E 2
  57. /* HW generated 11 AC dynamic bw flag */
  58. #define SEND_WIFIRTS_11AC_DYNAMIC_BW_E 3
  59. /* HW generated cts frame flag */
  60. #define SEND_WIFICTS2SELF_E 4
  61. /* Size (in bits) of a segment of sequence number bitmap */
  62. #define SEQ_SEG_SZ_BITS(_seqarr) (sizeof(_seqarr[0]) << 3)
  63. /* Array index of a segment of sequence number bitmap */
  64. #define SEQ_SEG_INDEX(_seqarr, _seqno) ((_seqno) / SEQ_SEG_SZ_BITS(_seqarr))
  65. /* Bit mask of a seqno within a segment of sequence bitmap */
  66. #define SEQ_SEG_MSK(_seqseg, _index) \
  67. (1 << ((_index) & ((sizeof(_seqseg) << 3) - 1)))
  68. /* Check seqno bit in a segment of sequence bitmap */
  69. #define SEQ_SEG_BIT(_seqseg, _index) \
  70. ((_seqseg) & SEQ_SEG_MSK((_seqseg), _index))
  71. /* Segment of sequence bitmap containing a given sequence number */
  72. #define SEQ_SEG(_seqarr, _seqno) \
  73. (_seqarr[(_seqno) / (sizeof(_seqarr[0]) << 3)])
  74. /* Check seqno bit in the sequence bitmap */
  75. #define SEQ_BIT(_seqarr, _seqno) \
  76. SEQ_SEG_BIT(SEQ_SEG(_seqarr, (_seqno)), (_seqno))
  77. /* Lower 32 mask for timestamp us as completion path has 32 bits timestamp */
  78. #define LOWER_32_MASK 0xFFFFFFFF
  79. /* Maximum time taken to enqueue next mgmt pkt */
  80. #define MAX_MGMT_ENQ_DELAY 10000
  81. /* Schedule id counter mask in ppdu_id */
  82. #define SCH_ID_MASK 0xFF
  83. #ifdef WLAN_TX_PKT_CAPTURE_ENH
  84. /**
  85. * dp_tx_cap_peer_find_by_id() - Returns peer object given the peer id
  86. * if delete_in_progress in not set for peer
  87. *
  88. * @soc : core DP soc context
  89. * @peer_id : peer id from peer object can be retrieved
  90. *
  91. * Return: struct dp_peer*: Pointer to DP peer object
  92. */
  93. static inline
  94. struct dp_peer *dp_tx_cap_peer_find_by_id(struct dp_soc *soc,
  95. uint16_t peer_id)
  96. {
  97. struct dp_peer *peer;
  98. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  99. peer = __dp_peer_find_by_id(soc, peer_id);
  100. if (!peer || (peer && peer->delete_in_progress)) {
  101. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  102. return NULL;
  103. }
  104. qdf_atomic_inc(&peer->ref_cnt);
  105. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  106. return peer;
  107. }
  108. /**
  109. * dp_tx_cap_peer_unref_del() - dec ref and del peer if ref count is
  110. * taken by dp_tx_cap_peer_find_by_id
  111. * @peer: peer context
  112. *
  113. * Return: none
  114. */
  115. static inline void dp_tx_cap_peer_unref_del(struct dp_peer *peer)
  116. {
  117. dp_peer_unref_delete(peer);
  118. }
  119. /*
  120. * dp_tx_capture_htt_frame_counter: increment counter for htt_frame_type
  121. * pdev: DP pdev handle
  122. * htt_frame_type: htt frame type received from fw
  123. *
  124. * return: void
  125. */
  126. void dp_tx_capture_htt_frame_counter(struct dp_pdev *pdev,
  127. uint32_t htt_frame_type)
  128. {
  129. if (htt_frame_type >= TX_CAP_HTT_MAX_FTYPE)
  130. return;
  131. pdev->tx_capture.htt_frame_type[htt_frame_type]++;
  132. }
  133. void dp_print_tid_qlen_per_peer(void *pdev_hdl)
  134. {
  135. struct dp_pdev *pdev = (struct dp_pdev *)pdev_hdl;
  136. struct dp_soc *soc = pdev->soc;
  137. struct dp_vdev *vdev = NULL;
  138. struct dp_peer *peer = NULL;
  139. struct dp_pdev_tx_capture *ptr_tx_cap;
  140. ptr_tx_cap = &(pdev->tx_capture);
  141. DP_PRINT_STATS("pending peer msdu and ppdu:");
  142. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  143. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  144. DP_PDEV_ITERATE_VDEV_LIST(pdev, vdev) {
  145. DP_VDEV_ITERATE_PEER_LIST(vdev, peer) {
  146. int tid;
  147. struct dp_tx_tid *tx_tid;
  148. uint32_t msdu_len;
  149. uint32_t ppdu_len;
  150. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  151. tx_tid = &peer->tx_capture.tx_tid[tid];
  152. msdu_len =
  153. qdf_nbuf_queue_len(&tx_tid->msdu_comp_q);
  154. ppdu_len =
  155. qdf_nbuf_queue_len(&tx_tid->pending_ppdu_q);
  156. if (!msdu_len && !ppdu_len)
  157. continue;
  158. DP_PRINT_STATS(" peer_id[%d] tid[%d] msdu_comp_q[%d] pending_ppdu_q[%d]",
  159. peer->peer_ids[0], tid,
  160. msdu_len, ppdu_len);
  161. }
  162. }
  163. }
  164. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  165. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  166. }
  167. /*
  168. * dp_tx_cature_stats: print tx capture stats
  169. * @pdev: DP PDEV handle
  170. *
  171. * return: void
  172. */
  173. void dp_print_pdev_tx_capture_stats(struct dp_pdev *pdev)
  174. {
  175. struct dp_pdev_tx_capture *ptr_tx_cap;
  176. uint8_t i = 0, j = 0;
  177. ptr_tx_cap = &(pdev->tx_capture);
  178. DP_PRINT_STATS("tx capture stats:");
  179. DP_PRINT_STATS(" mgmt control enqueue stats:");
  180. for (i = 0; i < TXCAP_MAX_TYPE; i++) {
  181. for (j = 0; j < TXCAP_MAX_SUBTYPE; j++) {
  182. if (ptr_tx_cap->ctl_mgmt_q[i][j].qlen)
  183. DP_PRINT_STATS(" ctl_mgmt_q[%d][%d] = queue_len[%d]",
  184. i, j, ptr_tx_cap->ctl_mgmt_q[i][j].qlen);
  185. }
  186. }
  187. DP_PRINT_STATS(" mgmt control retry queue stats:");
  188. for (i = 0; i < TXCAP_MAX_TYPE; i++) {
  189. for (j = 0; j < TXCAP_MAX_SUBTYPE; j++) {
  190. if (ptr_tx_cap->retries_ctl_mgmt_q[i][j].qlen)
  191. DP_PRINT_STATS(" retries_ctl_mgmt_q[%d][%d] = queue_len[%d]",
  192. i, j,
  193. ptr_tx_cap->retries_ctl_mgmt_q[i][j].qlen);
  194. }
  195. }
  196. dp_print_tid_qlen_per_peer(pdev);
  197. for (i = 0; i < TX_CAP_HTT_MAX_FTYPE; i++) {
  198. if (!ptr_tx_cap->htt_frame_type[i])
  199. continue;
  200. DP_PRINT_STATS(" sgen htt frame type[%d] = %d",
  201. i, ptr_tx_cap->htt_frame_type[i]);
  202. }
  203. }
  204. /**
  205. * dp_peer_or_pdev_tx_cap_enabled - Returns status of tx_cap_enabled
  206. * based on global per-pdev setting or per-peer setting
  207. * @pdev: Datapath pdev handle
  208. * @peer: Datapath peer
  209. * @mac_addr: peer mac address
  210. *
  211. * Return: true if feature is enabled on a per-pdev basis or if
  212. * enabled for the given peer when per-peer mode is set, false otherwise
  213. */
  214. inline bool
  215. dp_peer_or_pdev_tx_cap_enabled(struct dp_pdev *pdev,
  216. struct dp_peer *peer, uint8_t *mac_addr)
  217. {
  218. if (pdev->tx_capture_enabled == CDP_TX_ENH_CAPTURE_ENABLE_ALL_PEERS) {
  219. return true;
  220. } else if (pdev->tx_capture_enabled ==
  221. CDP_TX_ENH_CAPTURE_ENDIS_PER_PEER) {
  222. if (peer && peer->tx_cap_enabled)
  223. return true;
  224. /* do search based on mac address */
  225. return is_dp_peer_mgmt_pkt_filter(pdev,
  226. HTT_INVALID_PEER,
  227. mac_addr);
  228. }
  229. return false;
  230. }
  231. /*
  232. * dp_peer_tid_queue_init() – Initialize ppdu stats queue per TID
  233. * @peer: Datapath peer
  234. *
  235. */
  236. void dp_peer_tid_queue_init(struct dp_peer *peer)
  237. {
  238. int tid;
  239. struct dp_tx_tid *tx_tid;
  240. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  241. tx_tid = &peer->tx_capture.tx_tid[tid];
  242. tx_tid->tid = tid;
  243. qdf_nbuf_queue_init(&tx_tid->msdu_comp_q);
  244. qdf_nbuf_queue_init(&tx_tid->pending_ppdu_q);
  245. tx_tid->max_ppdu_id = 0;
  246. /* spinlock create */
  247. qdf_spinlock_create(&tx_tid->tid_lock);
  248. }
  249. }
  250. static
  251. void dp_peer_tx_cap_tid_queue_flush(struct dp_peer *peer)
  252. {
  253. int tid;
  254. struct dp_tx_tid *tx_tid;
  255. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  256. tx_tid = &peer->tx_capture.tx_tid[tid];
  257. qdf_spin_lock_bh(&tx_tid->tid_lock);
  258. qdf_nbuf_queue_free(&tx_tid->msdu_comp_q);
  259. qdf_spin_unlock_bh(&tx_tid->tid_lock);
  260. tx_tid->max_ppdu_id = 0;
  261. }
  262. }
  263. /*
  264. * dp_peer_tid_queue_cleanup() – remove ppdu stats queue per TID
  265. * @peer: Datapath peer
  266. *
  267. */
  268. void dp_peer_tid_queue_cleanup(struct dp_peer *peer)
  269. {
  270. int tid;
  271. struct dp_tx_tid *tx_tid;
  272. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  273. tx_tid = &peer->tx_capture.tx_tid[tid];
  274. qdf_spin_lock_bh(&tx_tid->tid_lock);
  275. qdf_nbuf_queue_free(&tx_tid->msdu_comp_q);
  276. qdf_spin_unlock_bh(&tx_tid->tid_lock);
  277. /* spinlock destroy */
  278. qdf_spinlock_destroy(&tx_tid->tid_lock);
  279. tx_tid->max_ppdu_id = 0;
  280. }
  281. }
  282. /*
  283. * dp_peer_update_80211_hdr: update 80211 hdr
  284. * @vdev: DP VDEV
  285. * @peer: DP PEER
  286. *
  287. * return: void
  288. */
  289. void dp_peer_update_80211_hdr(struct dp_vdev *vdev, struct dp_peer *peer)
  290. {
  291. struct ieee80211_frame *ptr_wh;
  292. ptr_wh = &peer->tx_capture.tx_wifi_hdr;
  293. /* i_addr1 - Receiver mac address */
  294. /* i_addr2 - Transmitter mac address */
  295. /* i_addr3 - Destination mac address */
  296. qdf_mem_copy(ptr_wh->i_addr1,
  297. peer->mac_addr.raw,
  298. QDF_MAC_ADDR_SIZE);
  299. qdf_mem_copy(ptr_wh->i_addr3,
  300. peer->mac_addr.raw,
  301. QDF_MAC_ADDR_SIZE);
  302. qdf_mem_copy(ptr_wh->i_addr2,
  303. vdev->mac_addr.raw,
  304. QDF_MAC_ADDR_SIZE);
  305. }
  306. /*
  307. * dp_deliver_mgmt_frm: Process
  308. * @pdev: DP PDEV handle
  309. * @nbuf: buffer containing the htt_ppdu_stats_tx_mgmtctrl_payload_tlv
  310. *
  311. * return: void
  312. */
  313. void dp_deliver_mgmt_frm(struct dp_pdev *pdev, qdf_nbuf_t nbuf)
  314. {
  315. if (pdev->tx_sniffer_enable || pdev->mcopy_mode) {
  316. dp_wdi_event_handler(WDI_EVENT_TX_MGMT_CTRL, pdev->soc,
  317. nbuf, HTT_INVALID_PEER,
  318. WDI_NO_VAL, pdev->pdev_id);
  319. return;
  320. }
  321. if (pdev->tx_capture_enabled == CDP_TX_ENH_CAPTURE_ENABLE_ALL_PEERS ||
  322. pdev->tx_capture_enabled == CDP_TX_ENH_CAPTURE_ENDIS_PER_PEER) {
  323. /* invoke WDI event handler here send mgmt pkt here */
  324. struct ieee80211_frame *wh;
  325. uint8_t type, subtype;
  326. struct cdp_tx_mgmt_comp_info *ptr_mgmt_hdr;
  327. ptr_mgmt_hdr = (struct cdp_tx_mgmt_comp_info *)
  328. qdf_nbuf_data(nbuf);
  329. wh = (struct ieee80211_frame *)(qdf_nbuf_data(nbuf) +
  330. sizeof(struct cdp_tx_mgmt_comp_info));
  331. type = (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) >>
  332. IEEE80211_FC0_TYPE_SHIFT;
  333. subtype = (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) >>
  334. IEEE80211_FC0_SUBTYPE_SHIFT;
  335. if (!ptr_mgmt_hdr->ppdu_id || !ptr_mgmt_hdr->tx_tsf ||
  336. (!type && !subtype)) {
  337. /*
  338. * if either ppdu_id and tx_tsf are zero then
  339. * storing the payload won't be useful
  340. * in constructing the packet
  341. * Hence freeing the packet
  342. */
  343. qdf_nbuf_free(nbuf);
  344. return;
  345. }
  346. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, NULL, wh->i_addr1)) {
  347. qdf_nbuf_free(nbuf);
  348. return;
  349. }
  350. qdf_spin_lock_bh(
  351. &pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  352. qdf_nbuf_queue_add(&pdev->tx_capture.ctl_mgmt_q[type][subtype],
  353. nbuf);
  354. qdf_spin_unlock_bh(
  355. &pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  356. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_DEBUG,
  357. "dlvr mgmt frm(0x%08x): fc 0x%x %x, dur 0x%x%x\n",
  358. ptr_mgmt_hdr->ppdu_id, wh->i_fc[1], wh->i_fc[0],
  359. wh->i_dur[1], wh->i_dur[0]);
  360. } else {
  361. if (!pdev->bpr_enable)
  362. qdf_nbuf_free(nbuf);
  363. }
  364. }
  365. static inline int dp_peer_compare_mac_addr(void *addr1, void *addr2)
  366. {
  367. union dp_align_mac_addr *mac_addr1 = (union dp_align_mac_addr *)addr1;
  368. union dp_align_mac_addr *mac_addr2 = (union dp_align_mac_addr *)addr2;
  369. return !((mac_addr1->align4.bytes_abcd == mac_addr2->align4.bytes_abcd)
  370. & (mac_addr1->align4.bytes_ef == mac_addr2->align4.bytes_ef));
  371. }
  372. /*
  373. * dp_peer_tx_cap_search: filter mgmt pkt based on peer and mac address
  374. * @pdev: DP PDEV handle
  375. * @peer_id: DP PEER ID
  376. * @mac_addr: pointer to mac address
  377. *
  378. * return: true on matched and false on not found
  379. */
  380. static
  381. bool dp_peer_tx_cap_search(struct dp_pdev *pdev,
  382. uint16_t peer_id, uint8_t *mac_addr)
  383. {
  384. struct dp_pdev_tx_capture *tx_capture;
  385. struct dp_peer_mgmt_list *ptr_peer_mgmt_list;
  386. uint8_t i = 0;
  387. bool found = false;
  388. tx_capture = &pdev->tx_capture;
  389. /* search based on mac address */
  390. for (i = 0; i < MAX_MGMT_PEER_FILTER; i++) {
  391. uint8_t *peer_mac_addr;
  392. ptr_peer_mgmt_list = &tx_capture->ptr_peer_mgmt_list[i];
  393. if (ptr_peer_mgmt_list->avail)
  394. continue;
  395. peer_mac_addr = ptr_peer_mgmt_list->mac_addr;
  396. if (!dp_peer_compare_mac_addr(mac_addr,
  397. peer_mac_addr)) {
  398. found = true;
  399. break;
  400. }
  401. }
  402. return found;
  403. }
  404. /*
  405. * dp_peer_tx_cap_add_filter: add peer filter mgmt pkt based on peer
  406. * and mac address
  407. * @pdev: DP PDEV handle
  408. * @peer_id: DP PEER ID
  409. * @mac_addr: pointer to mac address
  410. *
  411. * return: true on added and false on not failed
  412. */
  413. bool dp_peer_tx_cap_add_filter(struct dp_pdev *pdev,
  414. uint16_t peer_id, uint8_t *mac_addr)
  415. {
  416. struct dp_pdev_tx_capture *tx_capture;
  417. struct dp_peer_mgmt_list *ptr_peer_mgmt_list;
  418. uint8_t i = 0;
  419. bool status = false;
  420. tx_capture = &pdev->tx_capture;
  421. if (dp_peer_tx_cap_search(pdev, peer_id, mac_addr)) {
  422. /* mac address and peer_id already there */
  423. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_INFO_LOW,
  424. "%s: %d peer_id[%d] mac_addr[%pM] already there\n",
  425. __func__, __LINE__, peer_id, mac_addr);
  426. return status;
  427. }
  428. for (i = 0; i < MAX_MGMT_PEER_FILTER; i++) {
  429. ptr_peer_mgmt_list = &tx_capture->ptr_peer_mgmt_list[i];
  430. if (!ptr_peer_mgmt_list->avail)
  431. continue;
  432. qdf_mem_copy(ptr_peer_mgmt_list->mac_addr,
  433. mac_addr, QDF_MAC_ADDR_SIZE);
  434. ptr_peer_mgmt_list->avail = false;
  435. ptr_peer_mgmt_list->peer_id = peer_id;
  436. status = true;
  437. break;
  438. }
  439. return status;
  440. }
  441. /*
  442. * dp_peer_tx_cap_del_all_filter: delete all peer filter mgmt pkt based on peer
  443. * and mac address
  444. * @pdev: DP PDEV handle
  445. * @peer_id: DP PEER ID
  446. * @mac_addr: pointer to mac address
  447. *
  448. * return: void
  449. */
  450. void dp_peer_tx_cap_del_all_filter(struct dp_pdev *pdev)
  451. {
  452. struct dp_pdev_tx_capture *tx_capture;
  453. struct dp_peer_mgmt_list *ptr_peer_mgmt_list;
  454. uint8_t i = 0;
  455. tx_capture = &pdev->tx_capture;
  456. for (i = 0; i < MAX_MGMT_PEER_FILTER; i++) {
  457. ptr_peer_mgmt_list = &tx_capture->ptr_peer_mgmt_list[i];
  458. ptr_peer_mgmt_list->avail = true;
  459. ptr_peer_mgmt_list->peer_id = HTT_INVALID_PEER;
  460. qdf_mem_zero(ptr_peer_mgmt_list->mac_addr, QDF_MAC_ADDR_SIZE);
  461. }
  462. }
  463. /*
  464. * dp_peer_tx_cap_del_filter: delete peer filter mgmt pkt based on peer
  465. * and mac address
  466. * @pdev: DP PDEV handle
  467. * @peer_id: DP PEER ID
  468. * @mac_addr: pointer to mac address
  469. *
  470. * return: true on added and false on not failed
  471. */
  472. bool dp_peer_tx_cap_del_filter(struct dp_pdev *pdev,
  473. uint16_t peer_id, uint8_t *mac_addr)
  474. {
  475. struct dp_pdev_tx_capture *tx_capture;
  476. struct dp_peer_mgmt_list *ptr_peer_mgmt_list;
  477. uint8_t i = 0;
  478. bool status = false;
  479. tx_capture = &pdev->tx_capture;
  480. for (i = 0; i < MAX_MGMT_PEER_FILTER; i++) {
  481. ptr_peer_mgmt_list = &tx_capture->ptr_peer_mgmt_list[i];
  482. if (!dp_peer_compare_mac_addr(mac_addr,
  483. ptr_peer_mgmt_list->mac_addr) &&
  484. (!ptr_peer_mgmt_list->avail)) {
  485. ptr_peer_mgmt_list->avail = true;
  486. ptr_peer_mgmt_list->peer_id = HTT_INVALID_PEER;
  487. qdf_mem_zero(ptr_peer_mgmt_list->mac_addr,
  488. QDF_MAC_ADDR_SIZE);
  489. status = true;
  490. break;
  491. }
  492. }
  493. if (!status)
  494. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_INFO_LOW,
  495. "unable to delete peer[%d] mac[%pM] filter list",
  496. peer_id, mac_addr);
  497. return status;
  498. }
  499. /*
  500. * dp_peer_tx_cap_print_mgmt_filter: pradd peer filter mgmt pkt based on peer
  501. * and mac address
  502. * @pdev: DP PDEV handle
  503. * @peer_id: DP PEER ID
  504. * @mac_addr: pointer to mac address
  505. *
  506. * return: true on added and false on not failed
  507. */
  508. void dp_peer_tx_cap_print_mgmt_filter(struct dp_pdev *pdev,
  509. uint16_t peer_id, uint8_t *mac_addr)
  510. {
  511. struct dp_pdev_tx_capture *tx_capture;
  512. struct dp_peer_mgmt_list *ptr_peer_mgmt_list;
  513. uint8_t i = 0;
  514. tx_capture = &pdev->tx_capture;
  515. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_INFO_LOW,
  516. "peer filter list:");
  517. for (i = 0; i < MAX_MGMT_PEER_FILTER; i++) {
  518. ptr_peer_mgmt_list = &tx_capture->ptr_peer_mgmt_list[i];
  519. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_INFO_LOW,
  520. "peer_id[%d] mac_addr[%pM] avail[%d]",
  521. ptr_peer_mgmt_list->peer_id,
  522. ptr_peer_mgmt_list->mac_addr,
  523. ptr_peer_mgmt_list->avail);
  524. }
  525. }
  526. /*
  527. * dp_peer_mgmt_pkt_filter: filter mgmt pkt based on peer and mac address
  528. * @pdev: DP PDEV handle
  529. * @nbuf: buffer containing the ppdu_desc
  530. *
  531. * return: status
  532. */
  533. bool is_dp_peer_mgmt_pkt_filter(struct dp_pdev *pdev,
  534. uint32_t peer_id, uint8_t *mac_addr)
  535. {
  536. bool found = false;
  537. found = dp_peer_tx_cap_search(pdev, peer_id, mac_addr);
  538. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_INFO_HIGH,
  539. "%s: %d peer_id[%d] mac_addr[%pM] found[%d]!",
  540. __func__, __LINE__, peer_id, mac_addr, found);
  541. return found;
  542. }
  543. /**
  544. * dp_tx_ppdu_stats_attach - Initialize Tx PPDU stats and enhanced capture
  545. * @pdev: DP PDEV
  546. *
  547. * Return: none
  548. */
  549. void dp_tx_ppdu_stats_attach(struct dp_pdev *pdev)
  550. {
  551. struct dp_peer_mgmt_list *ptr_peer_mgmt_list;
  552. struct dp_pdev_tx_capture *tx_capture;
  553. int i, j;
  554. tx_capture = &pdev->tx_capture;
  555. tx_capture->tx_cap_mode_flag = true;
  556. /* Work queue setup for HTT stats and tx capture handling */
  557. qdf_create_work(0, &pdev->tx_capture.ppdu_stats_work,
  558. dp_tx_ppdu_stats_process,
  559. pdev);
  560. pdev->tx_capture.ppdu_stats_workqueue =
  561. qdf_alloc_unbound_workqueue("ppdu_stats_work_queue");
  562. STAILQ_INIT(&pdev->tx_capture.ppdu_stats_queue);
  563. STAILQ_INIT(&pdev->tx_capture.ppdu_stats_defer_queue);
  564. qdf_spinlock_create(&pdev->tx_capture.ppdu_stats_lock);
  565. pdev->tx_capture.ppdu_stats_queue_depth = 0;
  566. pdev->tx_capture.ppdu_stats_next_sched = 0;
  567. pdev->tx_capture.ppdu_stats_defer_queue_depth = 0;
  568. pdev->tx_capture.ppdu_dropped = 0;
  569. for (i = 0; i < TXCAP_MAX_TYPE; i++) {
  570. for (j = 0; j < TXCAP_MAX_SUBTYPE; j++) {
  571. qdf_nbuf_queue_init(
  572. &pdev->tx_capture.ctl_mgmt_q[i][j]);
  573. qdf_spinlock_create(
  574. &pdev->tx_capture.ctl_mgmt_lock[i][j]);
  575. }
  576. }
  577. qdf_mem_zero(&pdev->tx_capture.dummy_ppdu_desc,
  578. sizeof(struct cdp_tx_completion_ppdu));
  579. pdev->tx_capture.ptr_peer_mgmt_list = (struct dp_peer_mgmt_list *)
  580. qdf_mem_malloc(sizeof(struct dp_peer_mgmt_list) *
  581. MAX_MGMT_PEER_FILTER);
  582. for (i = 0; i < MAX_MGMT_PEER_FILTER; i++) {
  583. ptr_peer_mgmt_list = &tx_capture->ptr_peer_mgmt_list[i];
  584. ptr_peer_mgmt_list->avail = true;
  585. }
  586. }
  587. /**
  588. * dp_tx_ppdu_stats_detach - Cleanup Tx PPDU stats and enhanced capture
  589. * @pdev: DP PDEV
  590. *
  591. * Return: none
  592. */
  593. void dp_tx_ppdu_stats_detach(struct dp_pdev *pdev)
  594. {
  595. struct ppdu_info *ppdu_info, *tmp_ppdu_info = NULL;
  596. int i, j;
  597. if (!pdev || !pdev->tx_capture.ppdu_stats_workqueue)
  598. return;
  599. qdf_flush_workqueue(0, pdev->tx_capture.ppdu_stats_workqueue);
  600. qdf_destroy_workqueue(0, pdev->tx_capture.ppdu_stats_workqueue);
  601. qdf_spinlock_destroy(&pdev->tx_capture.ppdu_stats_lock);
  602. STAILQ_FOREACH_SAFE(ppdu_info,
  603. &pdev->tx_capture.ppdu_stats_queue,
  604. ppdu_info_queue_elem, tmp_ppdu_info) {
  605. STAILQ_REMOVE(&pdev->tx_capture.ppdu_stats_queue,
  606. ppdu_info, ppdu_info, ppdu_info_queue_elem);
  607. qdf_nbuf_free(ppdu_info->nbuf);
  608. qdf_mem_free(ppdu_info);
  609. }
  610. STAILQ_FOREACH_SAFE(ppdu_info,
  611. &pdev->tx_capture.ppdu_stats_defer_queue,
  612. ppdu_info_queue_elem, tmp_ppdu_info) {
  613. STAILQ_REMOVE(&pdev->tx_capture.ppdu_stats_defer_queue,
  614. ppdu_info, ppdu_info, ppdu_info_queue_elem);
  615. qdf_nbuf_free(ppdu_info->nbuf);
  616. qdf_mem_free(ppdu_info);
  617. }
  618. for (i = 0; i < TXCAP_MAX_TYPE; i++) {
  619. for (j = 0; j < TXCAP_MAX_SUBTYPE; j++) {
  620. qdf_spin_lock_bh(
  621. &pdev->tx_capture.ctl_mgmt_lock[i][j]);
  622. qdf_nbuf_queue_free(
  623. &pdev->tx_capture.ctl_mgmt_q[i][j]);
  624. qdf_spin_unlock_bh(
  625. &pdev->tx_capture.ctl_mgmt_lock[i][j]);
  626. qdf_spinlock_destroy(
  627. &pdev->tx_capture.ctl_mgmt_lock[i][j]);
  628. }
  629. }
  630. qdf_mem_free(pdev->tx_capture.ptr_peer_mgmt_list);
  631. }
  632. #define MAX_MSDU_THRESHOLD_TSF 100000
  633. #define MAX_MSDU_ENQUEUE_THRESHOLD 10000
  634. /**
  635. * dp_update_msdu_to_list(): Function to queue msdu from wbm
  636. * @pdev: dp_pdev
  637. * @peer: dp_peer
  638. * @ts: hal tx completion status
  639. * @netbuf: msdu
  640. *
  641. * return: status
  642. */
  643. QDF_STATUS
  644. dp_update_msdu_to_list(struct dp_soc *soc,
  645. struct dp_pdev *pdev,
  646. struct dp_peer *peer,
  647. struct hal_tx_completion_status *ts,
  648. qdf_nbuf_t netbuf)
  649. {
  650. struct dp_tx_tid *tx_tid;
  651. struct msdu_completion_info *msdu_comp_info;
  652. struct msdu_completion_info *ptr_msdu_info = NULL;
  653. qdf_nbuf_t nbuf;
  654. qdf_nbuf_t head_msdu;
  655. uint32_t tsf_delta;
  656. uint32_t qlen;
  657. if (!peer) {
  658. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_ERROR,
  659. "%s: %d peer NULL !", __func__, __LINE__);
  660. return QDF_STATUS_E_FAILURE;
  661. }
  662. if ((ts->tid > DP_MAX_TIDS) ||
  663. (peer->bss_peer && ts->tid == DP_NON_QOS_TID)) {
  664. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_ERROR,
  665. "%s: %d peer_id %d, tid %d > NON_QOS_TID!",
  666. __func__, __LINE__, ts->peer_id, ts->tid);
  667. return QDF_STATUS_E_FAILURE;
  668. }
  669. tx_tid = &peer->tx_capture.tx_tid[ts->tid];
  670. if (!tx_tid) {
  671. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_ERROR,
  672. "%s: %d tid[%d] NULL !", __func__, __LINE__, ts->tid);
  673. return QDF_STATUS_E_FAILURE;
  674. }
  675. qdf_nbuf_unmap(soc->osdev, netbuf, QDF_DMA_TO_DEVICE);
  676. if (!qdf_nbuf_push_head(netbuf, sizeof(struct msdu_completion_info))) {
  677. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  678. FL("No headroom"));
  679. return QDF_STATUS_E_NOMEM;
  680. }
  681. msdu_comp_info = (struct msdu_completion_info *)qdf_nbuf_data(netbuf);
  682. /* copy msdu_completion_info to control buffer */
  683. msdu_comp_info->ppdu_id = ts->ppdu_id;
  684. msdu_comp_info->peer_id = ts->peer_id;
  685. msdu_comp_info->tid = ts->tid;
  686. msdu_comp_info->first_msdu = ts->first_msdu;
  687. msdu_comp_info->last_msdu = ts->last_msdu;
  688. msdu_comp_info->msdu_part_of_amsdu = ts->msdu_part_of_amsdu;
  689. msdu_comp_info->transmit_cnt = ts->transmit_cnt;
  690. msdu_comp_info->tsf = ts->tsf;
  691. msdu_comp_info->status = ts->status;
  692. /* update max ppdu_id */
  693. tx_tid->max_ppdu_id = ts->ppdu_id;
  694. pdev->tx_capture.last_msdu_id = ts->ppdu_id;
  695. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_INFO,
  696. "msdu_completion: ppdu_id[%d] peer_id[%d] tid[%d] rel_src[%d] status[%d] tsf[%u] A[%d] CNT[%d]",
  697. ts->ppdu_id, ts->peer_id, ts->tid, ts->release_src,
  698. ts->status, ts->tsf, ts->msdu_part_of_amsdu,
  699. ts->transmit_cnt);
  700. /* lock here */
  701. qdf_spin_lock_bh(&tx_tid->tid_lock);
  702. while ((head_msdu = qdf_nbuf_queue_first(&tx_tid->msdu_comp_q))) {
  703. ptr_msdu_info =
  704. (struct msdu_completion_info *)qdf_nbuf_data(head_msdu);
  705. if (ts->tsf > ptr_msdu_info->tsf)
  706. tsf_delta = ts->tsf - ptr_msdu_info->tsf;
  707. else
  708. tsf_delta = LOWER_32_MASK - ptr_msdu_info->tsf + ts->tsf;
  709. if (tsf_delta < MAX_MSDU_THRESHOLD_TSF)
  710. break;
  711. /* free head */
  712. nbuf = qdf_nbuf_queue_remove(&tx_tid->msdu_comp_q);
  713. qdf_nbuf_free(nbuf);
  714. }
  715. /* get queue length */
  716. qlen = qdf_nbuf_queue_len(&tx_tid->msdu_comp_q);
  717. if (qlen > MAX_MSDU_ENQUEUE_THRESHOLD) {
  718. /* free head */
  719. nbuf = qdf_nbuf_queue_remove(&tx_tid->msdu_comp_q);
  720. qdf_nbuf_free(nbuf);
  721. }
  722. /* add nbuf to tail queue per peer tid */
  723. qdf_nbuf_queue_add(&tx_tid->msdu_comp_q, netbuf);
  724. qdf_spin_unlock_bh(&tx_tid->tid_lock);
  725. return QDF_STATUS_SUCCESS;
  726. }
  727. /**
  728. * dp_tx_add_to_comp_queue() - add completion msdu to queue
  729. * @soc: DP Soc handle
  730. * @tx_desc: software Tx descriptor
  731. * @ts : Tx completion status from HAL/HTT descriptor
  732. * @peer: DP peer
  733. *
  734. * Return: none
  735. */
  736. QDF_STATUS dp_tx_add_to_comp_queue(struct dp_soc *soc,
  737. struct dp_tx_desc_s *desc,
  738. struct hal_tx_completion_status *ts,
  739. struct dp_peer *peer)
  740. {
  741. int ret = QDF_STATUS_E_FAILURE;
  742. struct dp_pdev *pdev = desc->pdev;
  743. if (peer &&
  744. dp_peer_or_pdev_tx_cap_enabled(pdev, peer, peer->mac_addr.raw) &&
  745. ((ts->status == HAL_TX_TQM_RR_FRAME_ACKED) ||
  746. (ts->status == HAL_TX_TQM_RR_REM_CMD_TX) ||
  747. ((ts->status == HAL_TX_TQM_RR_REM_CMD_AGED) && ts->transmit_cnt))) {
  748. /* skip enqueuing OFDMA frames */
  749. if (ts->ofdma)
  750. return ret;
  751. ret = dp_update_msdu_to_list(soc, pdev, peer, ts, desc->nbuf);
  752. }
  753. return ret;
  754. }
  755. /**
  756. * dp_process_ppdu_stats_update_failed_bitmap(): update failed bitmap
  757. * @pdev: dp_pdev
  758. * @data: tx completion ppdu desc
  759. * @ppdu_id: ppdu id
  760. * @size: size of bitmap
  761. *
  762. * return: status
  763. */
  764. void dp_process_ppdu_stats_update_failed_bitmap(struct dp_pdev *pdev,
  765. void *data,
  766. uint32_t ppdu_id,
  767. uint32_t size)
  768. {
  769. struct cdp_tx_completion_ppdu_user *user;
  770. uint32_t mpdu_tried;
  771. uint32_t ba_seq_no;
  772. uint32_t start_seq;
  773. uint32_t num_mpdu;
  774. uint32_t diff;
  775. uint32_t carry = 0;
  776. uint32_t bitmask = 0;
  777. uint32_t i;
  778. uint32_t k;
  779. uint32_t ba_bitmap = 0;
  780. int last_set_bit;
  781. user = (struct cdp_tx_completion_ppdu_user *)data;
  782. /* get number of mpdu from ppdu_desc */
  783. mpdu_tried = user->mpdu_tried_mcast + user->mpdu_tried_ucast;
  784. ba_seq_no = user->ba_seq_no;
  785. start_seq = user->start_seq;
  786. num_mpdu = user->num_mpdu;
  787. /* assumption: number of mpdu will be less than 32 */
  788. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_INFO,
  789. "ppdu_id[%d] ba_seq_no[%d] start_seq_no[%d] mpdu_tried[%d]",
  790. ppdu_id, ba_seq_no, start_seq, mpdu_tried);
  791. for (i = 0; i < size; i++) {
  792. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_INFO,
  793. "ppdu_id[%d] ba_bitmap[%x] enqueue_bitmap[%x]",
  794. ppdu_id, user->ba_bitmap[i], user->enq_bitmap[i]);
  795. }
  796. /* Handle sequence no. wraparound */
  797. if (start_seq <= ba_seq_no) {
  798. diff = ba_seq_no - start_seq;
  799. /* Sequence delta of more than 2048 is considered wraparound
  800. * and we extend start_seq to be more than ba_seq just to
  801. * adjust failed_bitmap
  802. */
  803. if (qdf_unlikely(diff > (IEEE80211_SEQ_MAX / 2))) {
  804. diff = (start_seq - ba_seq_no) &
  805. (IEEE80211_SEQ_MAX - 1);
  806. start_seq = ba_seq_no + diff;
  807. }
  808. } else {
  809. diff = start_seq - ba_seq_no;
  810. /* Sequence delta of more than 2048 is considered wraparound
  811. * and we extend ba_seq to be more than start_seq just to
  812. * adjust failed_bitmap
  813. */
  814. if (qdf_unlikely(diff > (IEEE80211_SEQ_MAX / 2))) {
  815. diff = (ba_seq_no - start_seq) &
  816. (IEEE80211_SEQ_MAX - 1);
  817. ba_seq_no = start_seq + diff;
  818. }
  819. }
  820. /* Adjust failed_bitmap to start from same seq_no as enq_bitmap */
  821. last_set_bit = 0;
  822. if (start_seq <= ba_seq_no) {
  823. bitmask = (1 << diff) - 1;
  824. for (i = 0; i < size; i++) {
  825. ba_bitmap = user->ba_bitmap[i];
  826. user->failed_bitmap[i] = (ba_bitmap << diff);
  827. user->failed_bitmap[i] |= (bitmask & carry);
  828. carry = ((ba_bitmap & (bitmask << (32 - diff))) >>
  829. (32 - diff));
  830. user->failed_bitmap[i] = user->enq_bitmap[i] &
  831. user->failed_bitmap[i];
  832. if (user->enq_bitmap[i]) {
  833. last_set_bit = i * 32 +
  834. qdf_fls(user->enq_bitmap[i]) - 1;
  835. }
  836. }
  837. } else {
  838. /* array index */
  839. k = diff >> 5;
  840. diff = diff & 0x1F;
  841. bitmask = (1 << diff) - 1;
  842. for (i = 0; i < size; i++, k++) {
  843. ba_bitmap = user->ba_bitmap[k];
  844. user->failed_bitmap[i] = ba_bitmap >> diff;
  845. /* get next ba_bitmap */
  846. ba_bitmap = user->ba_bitmap[k + 1];
  847. carry = (ba_bitmap & bitmask);
  848. user->failed_bitmap[i] |=
  849. ((carry & bitmask) << (32 - diff));
  850. user->failed_bitmap[i] = user->enq_bitmap[i] &
  851. user->failed_bitmap[i];
  852. if (user->enq_bitmap[i]) {
  853. last_set_bit = i * 32 +
  854. qdf_fls(user->enq_bitmap[i]) - 1;
  855. }
  856. }
  857. }
  858. user->last_enq_seq = user->start_seq + last_set_bit;
  859. user->ba_size = user->last_enq_seq - user->start_seq + 1;
  860. }
  861. /*
  862. * dp_soc_set_txrx_ring_map_single()
  863. * @dp_soc: DP handler for soc
  864. *
  865. * Return: Void
  866. */
  867. static void dp_soc_set_txrx_ring_map_single(struct dp_soc *soc)
  868. {
  869. uint32_t i;
  870. for (i = 0; i < WLAN_CFG_INT_NUM_CONTEXTS; i++) {
  871. soc->tx_ring_map[i] =
  872. dp_cpu_ring_map[DP_SINGLE_TX_RING_MAP][i];
  873. }
  874. }
  875. /*
  876. * dp_iterate_free_peer_msdu_q()- API to free msdu queue
  877. * @pdev_handle: DP_PDEV handle
  878. *
  879. * Return: void
  880. */
  881. static void dp_iterate_free_peer_msdu_q(void *pdev_hdl)
  882. {
  883. struct dp_pdev *pdev = (struct dp_pdev *)pdev_hdl;
  884. struct dp_soc *soc = pdev->soc;
  885. struct dp_vdev *vdev = NULL;
  886. struct dp_peer *peer = NULL;
  887. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  888. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  889. DP_PDEV_ITERATE_VDEV_LIST(pdev, vdev) {
  890. DP_VDEV_ITERATE_PEER_LIST(vdev, peer) {
  891. int tid;
  892. struct dp_tx_tid *tx_tid;
  893. /* set peer tx cap enabled to 0, when feature disable */
  894. peer->tx_cap_enabled = 0;
  895. for (tid = 0; tid < DP_MAX_TIDS; tid++) {
  896. qdf_nbuf_t ppdu_nbuf = NULL;
  897. struct cdp_tx_completion_ppdu *ppdu_desc =
  898. NULL;
  899. int i;
  900. tx_tid = &peer->tx_capture.tx_tid[tid];
  901. /* spinlock hold */
  902. qdf_spin_lock_bh(&tx_tid->tid_lock);
  903. qdf_nbuf_queue_free(&tx_tid->msdu_comp_q);
  904. qdf_spin_unlock_bh(&tx_tid->tid_lock);
  905. while ((ppdu_nbuf = qdf_nbuf_queue_remove(
  906. &tx_tid->pending_ppdu_q))) {
  907. ppdu_desc =
  908. (struct cdp_tx_completion_ppdu *)
  909. qdf_nbuf_data(ppdu_nbuf);
  910. if (!ppdu_desc->mpdus) {
  911. qdf_nbuf_free(ppdu_nbuf);
  912. continue;
  913. }
  914. for (i = 0; i <
  915. ppdu_desc->user[0].ba_size; i++) {
  916. if (!ppdu_desc->mpdus[i])
  917. continue;
  918. qdf_nbuf_free(
  919. ppdu_desc->mpdus[i]);
  920. ppdu_desc->mpdus[i] = NULL;
  921. }
  922. qdf_mem_free(ppdu_desc->mpdus);
  923. ppdu_desc->mpdus = NULL;
  924. qdf_nbuf_free(ppdu_nbuf);
  925. }
  926. }
  927. }
  928. }
  929. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  930. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  931. }
  932. /*
  933. * dp_enh_tx_capture_disable()- API to disable enhanced tx capture
  934. * @pdev_handle: DP_PDEV handle
  935. *
  936. * Return: void
  937. */
  938. void
  939. dp_enh_tx_capture_disable(struct dp_pdev *pdev)
  940. {
  941. int i, j;
  942. dp_soc_set_txrx_ring_map(pdev->soc);
  943. dp_h2t_cfg_stats_msg_send(pdev,
  944. DP_PPDU_STATS_CFG_ENH_STATS,
  945. pdev->pdev_id);
  946. dp_iterate_free_peer_msdu_q(pdev);
  947. for (i = 0; i < TXCAP_MAX_TYPE; i++) {
  948. for (j = 0; j < TXCAP_MAX_SUBTYPE; j++) {
  949. qdf_nbuf_queue_t *retries_q;
  950. qdf_spin_lock_bh(
  951. &pdev->tx_capture.ctl_mgmt_lock[i][j]);
  952. qdf_nbuf_queue_free(
  953. &pdev->tx_capture.ctl_mgmt_q[i][j]);
  954. qdf_spin_unlock_bh(
  955. &pdev->tx_capture.ctl_mgmt_lock[i][j]);
  956. retries_q = &pdev->tx_capture.retries_ctl_mgmt_q[i][j];
  957. if (!qdf_nbuf_is_queue_empty(retries_q))
  958. qdf_nbuf_queue_free(retries_q);
  959. }
  960. }
  961. dp_peer_tx_cap_del_all_filter(pdev);
  962. pdev->tx_capture.tx_cap_mode_flag = true;
  963. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_INFO_LOW,
  964. "Mode change request done cur mode - %d\n",
  965. pdev->tx_capture_enabled);
  966. }
  967. /*
  968. * dp_config_enh_tx_capture()- API to enable/disable enhanced tx capture
  969. * @pdev_handle: DP_PDEV handle
  970. * @val: user provided value
  971. *
  972. * Return: QDF_STATUS
  973. */
  974. QDF_STATUS
  975. dp_config_enh_tx_capture(struct dp_pdev *pdev, uint8_t val)
  976. {
  977. qdf_spin_lock(&pdev->tx_capture.config_lock);
  978. if (pdev->tx_capture.tx_cap_mode_flag) {
  979. pdev->tx_capture.tx_cap_mode_flag = false;
  980. pdev->tx_capture_enabled = val;
  981. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_INFO_LOW,
  982. "Mode change requested - %d\n",
  983. pdev->tx_capture_enabled);
  984. } else if (!pdev->tx_capture.tx_cap_mode_flag &&
  985. !val && !!pdev->tx_capture_enabled) {
  986. /* here the val is always 0 which is disable */
  987. pdev->tx_capture_enabled = val;
  988. pdev->tx_capture.tx_cap_mode_flag = false;
  989. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_INFO_LOW,
  990. "Mode change requested - %d\n",
  991. pdev->tx_capture_enabled);
  992. } else {
  993. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_INFO_LOW,
  994. "Mode change request pending prev mode - %d\n",
  995. pdev->tx_capture_enabled);
  996. qdf_spin_unlock(&pdev->tx_capture.config_lock);
  997. return QDF_STATUS_E_BUSY;
  998. }
  999. if (pdev->tx_capture_enabled == CDP_TX_ENH_CAPTURE_ENABLE_ALL_PEERS ||
  1000. pdev->tx_capture_enabled == CDP_TX_ENH_CAPTURE_ENDIS_PER_PEER) {
  1001. dp_soc_set_txrx_ring_map_single(pdev->soc);
  1002. if (!pdev->pktlog_ppdu_stats)
  1003. dp_h2t_cfg_stats_msg_send(pdev,
  1004. DP_PPDU_STATS_CFG_SNIFFER,
  1005. pdev->pdev_id);
  1006. pdev->tx_capture.tx_cap_mode_flag = true;
  1007. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_INFO_LOW,
  1008. "Mode change request done cur mode - %d\n",
  1009. pdev->tx_capture_enabled);
  1010. }
  1011. qdf_spin_unlock(&pdev->tx_capture.config_lock);
  1012. return QDF_STATUS_SUCCESS;
  1013. }
  1014. /**
  1015. * get_number_of_1s(): Function to get number of 1s
  1016. * @value: value to find
  1017. *
  1018. * return: number of 1s
  1019. */
  1020. static
  1021. inline uint32_t get_number_of_1s(uint32_t value)
  1022. {
  1023. uint32_t shift[] = {1, 2, 4, 8, 16};
  1024. uint32_t magic_number[] = { 0x55555555, 0x33333333, 0x0F0F0F0F,
  1025. 0x00FF00FF, 0x0000FFFF};
  1026. uint8_t k = 0;
  1027. for (; k <= 4; k++) {
  1028. value = (value & magic_number[k]) +
  1029. ((value >> shift[k]) & magic_number[k]);
  1030. }
  1031. return value;
  1032. }
  1033. /**
  1034. * dp_tx_print_bitmap(): Function to print bitmap
  1035. * @pdev: dp_pdev
  1036. * @ppdu_desc: ppdu completion descriptor
  1037. * @user_inder: user index
  1038. * @ppdu_id: ppdu id
  1039. *
  1040. * return: status
  1041. */
  1042. static
  1043. QDF_STATUS dp_tx_print_bitmap(struct dp_pdev *pdev,
  1044. struct cdp_tx_completion_ppdu *ppdu_desc,
  1045. uint32_t user_index,
  1046. uint32_t ppdu_id)
  1047. {
  1048. struct cdp_tx_completion_ppdu_user *user;
  1049. uint8_t i;
  1050. uint32_t mpdu_tried;
  1051. uint32_t ba_seq_no;
  1052. uint32_t start_seq;
  1053. uint32_t num_mpdu;
  1054. uint32_t fail_num_mpdu = 0;
  1055. user = &ppdu_desc->user[user_index];
  1056. /* get number of mpdu from ppdu_desc */
  1057. mpdu_tried = user->mpdu_tried_mcast + user->mpdu_tried_ucast;
  1058. ba_seq_no = user->ba_seq_no;
  1059. start_seq = user->start_seq;
  1060. num_mpdu = user->mpdu_success;
  1061. if (user->tid > DP_MAX_TIDS) {
  1062. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_ERROR,
  1063. "%s: ppdu[%d] peer_id[%d] TID[%d] > NON_QOS_TID!",
  1064. __func__, ppdu_id, user->peer_id, user->tid);
  1065. return QDF_STATUS_E_FAILURE;
  1066. }
  1067. if (mpdu_tried != num_mpdu) {
  1068. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_INFO,
  1069. "%s: ppdu[%d] peer[%d] tid[%d] ba[%d] start[%d] mpdu_tri[%d] num_mpdu[%d] is_mcast[%d]",
  1070. __func__, ppdu_id, user->peer_id, user->tid,
  1071. ba_seq_no, start_seq, mpdu_tried,
  1072. num_mpdu, user->is_mcast);
  1073. for (i = 0; i < CDP_BA_256_BIT_MAP_SIZE_DWORDS; i++) {
  1074. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  1075. QDF_TRACE_LEVEL_INFO,
  1076. "ppdu_id[%d] ba_bitmap[0x%x] enqueue_bitmap[0x%x] failed_bitmap[0x%x]",
  1077. ppdu_id, user->ba_bitmap[i],
  1078. user->enq_bitmap[i],
  1079. user->failed_bitmap[i]);
  1080. fail_num_mpdu +=
  1081. get_number_of_1s(user->failed_bitmap[i]);
  1082. }
  1083. }
  1084. if (fail_num_mpdu == num_mpdu && num_mpdu)
  1085. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_DEBUG,
  1086. "%s: %d ppdu_id[%d] num_mpdu[%d, %d]",
  1087. __func__, __LINE__, ppdu_id, num_mpdu, fail_num_mpdu);
  1088. return QDF_STATUS_SUCCESS;
  1089. }
  1090. /*
  1091. * dp_peer_tx_wds_addr_add() – Update WDS peer to include 4th address
  1092. * @peer: Datapath peer
  1093. * @addr4_mac_addr: Source MAC address for WDS TX
  1094. *
  1095. */
  1096. static
  1097. void dp_peer_tx_wds_addr_add(struct dp_peer *peer, uint8_t *addr4_mac_addr)
  1098. {
  1099. struct ieee80211_frame_addr4 *ptr_wh;
  1100. if (!peer)
  1101. return;
  1102. ptr_wh = &peer->tx_capture.tx_wifi_addr4_hdr;
  1103. qdf_mem_copy(ptr_wh->i_addr4,
  1104. addr4_mac_addr,
  1105. QDF_MAC_ADDR_SIZE);
  1106. }
  1107. /*
  1108. * dp_peer_tx_update_80211_wds_hdr() – Update 80211 frame header to include a
  1109. * 4 address frame, and set QoS related information if necessary
  1110. * @pdev: Physical device reference
  1111. * @peer: Datapath peer
  1112. * @data: ppdu_descriptor
  1113. * @nbuf: 802.11 frame
  1114. * @ether_type: ethernet type
  1115. * @src_addr: ether shost address
  1116. *
  1117. */
  1118. static uint32_t dp_tx_update_80211_wds_hdr(struct dp_pdev *pdev,
  1119. struct dp_peer *peer,
  1120. void *data,
  1121. qdf_nbuf_t nbuf,
  1122. uint16_t ether_type,
  1123. uint8_t *src_addr)
  1124. {
  1125. struct cdp_tx_completion_ppdu *ppdu_desc;
  1126. uint32_t mpdu_buf_len, frame_size;
  1127. uint8_t *ptr_hdr;
  1128. uint16_t eth_type = qdf_htons(ether_type);
  1129. struct ieee80211_qosframe_addr4 *ptr_wh;
  1130. ppdu_desc = (struct cdp_tx_completion_ppdu *)data;
  1131. ptr_wh = &peer->tx_capture.tx_wifi_addr4_qos_hdr;
  1132. /*
  1133. * update framectrl only for first ppdu_id
  1134. * rest of mpdu will have same frame ctrl
  1135. * mac address and duration
  1136. */
  1137. if (ppdu_desc->ppdu_id != peer->tx_capture.tx_wifi_ppdu_id) {
  1138. ptr_wh->i_fc[1] = (ppdu_desc->frame_ctrl & 0xFF00) >> 8;
  1139. ptr_wh->i_fc[0] = (ppdu_desc->frame_ctrl & 0xFF);
  1140. ptr_wh->i_dur[1] = (ppdu_desc->tx_duration & 0xFF00) >> 8;
  1141. ptr_wh->i_dur[0] = (ppdu_desc->tx_duration & 0xFF);
  1142. ptr_wh->i_qos[1] = (ppdu_desc->user[0].qos_ctrl & 0xFF00) >> 8;
  1143. ptr_wh->i_qos[0] = (ppdu_desc->user[0].qos_ctrl & 0xFF);
  1144. /* Update Addr 3 (SA) with SA derived from ether packet */
  1145. qdf_mem_copy(ptr_wh->i_addr3, src_addr, QDF_MAC_ADDR_SIZE);
  1146. peer->tx_capture.tx_wifi_ppdu_id = ppdu_desc->ppdu_id;
  1147. }
  1148. frame_size = (ppdu_desc->user[0].tid != DP_NON_QOS_TID) ?
  1149. sizeof(struct ieee80211_qosframe_addr4) :
  1150. sizeof(struct ieee80211_frame_addr4);
  1151. mpdu_buf_len = frame_size + LLC_SNAP_HDR_LEN;
  1152. nbuf->protocol = qdf_htons(ETH_P_802_2);
  1153. /* update ieee80211_frame header */
  1154. if (!qdf_nbuf_push_head(nbuf, mpdu_buf_len)) {
  1155. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_ERROR,
  1156. FL("No headroom"));
  1157. return QDF_STATUS_E_NOMEM;
  1158. }
  1159. ptr_hdr = (void *)qdf_nbuf_data(nbuf);
  1160. qdf_mem_copy(ptr_hdr, ptr_wh, frame_size);
  1161. ptr_hdr = ptr_hdr + frame_size;
  1162. /* update LLC */
  1163. *ptr_hdr = LLC_SNAP_LSAP;
  1164. *(ptr_hdr + 1) = LLC_SNAP_LSAP;
  1165. *(ptr_hdr + 2) = LLC_UI;
  1166. *(ptr_hdr + 3) = 0x00;
  1167. *(ptr_hdr + 4) = 0x00;
  1168. *(ptr_hdr + 5) = 0x00;
  1169. *(ptr_hdr + 6) = (eth_type & 0xFF00) >> 8;
  1170. *(ptr_hdr + 7) = (eth_type & 0xFF);
  1171. qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) - mpdu_buf_len);
  1172. return 0;
  1173. }
  1174. /*
  1175. * dp_peer_tx_update_80211_hdr() – Update 80211 frame header to set QoS
  1176. * related information if necessary
  1177. * @pdev: Physical device reference
  1178. * @peer: Datapath peer
  1179. * @data: ppdu_descriptor
  1180. * @nbuf: 802.11 frame
  1181. * @ether_type: ethernet type
  1182. * @src_addr: ether shost address
  1183. *
  1184. */
  1185. static uint32_t dp_tx_update_80211_hdr(struct dp_pdev *pdev,
  1186. struct dp_peer *peer,
  1187. void *data,
  1188. qdf_nbuf_t nbuf,
  1189. uint16_t ether_type,
  1190. uint8_t *src_addr)
  1191. {
  1192. struct cdp_tx_completion_ppdu *ppdu_desc;
  1193. uint32_t mpdu_buf_len, frame_size;
  1194. uint8_t *ptr_hdr;
  1195. uint16_t eth_type = qdf_htons(ether_type);
  1196. struct ieee80211_qosframe *ptr_wh;
  1197. ppdu_desc = (struct cdp_tx_completion_ppdu *)data;
  1198. ptr_wh = &peer->tx_capture.tx_wifi_qos_hdr;
  1199. /*
  1200. * update framectrl only for first ppdu_id
  1201. * rest of mpdu will have same frame ctrl
  1202. * mac address and duration
  1203. */
  1204. if (ppdu_desc->ppdu_id != peer->tx_capture.tx_wifi_ppdu_id) {
  1205. ptr_wh->i_fc[1] = (ppdu_desc->frame_ctrl & 0xFF00) >> 8;
  1206. ptr_wh->i_fc[0] = (ppdu_desc->frame_ctrl & 0xFF);
  1207. ptr_wh->i_dur[1] = (ppdu_desc->tx_duration & 0xFF00) >> 8;
  1208. ptr_wh->i_dur[0] = (ppdu_desc->tx_duration & 0xFF);
  1209. ptr_wh->i_qos[1] = (ppdu_desc->user[0].qos_ctrl & 0xFF00) >> 8;
  1210. ptr_wh->i_qos[0] = (ppdu_desc->user[0].qos_ctrl & 0xFF);
  1211. /* Update Addr 3 (SA) with SA derived from ether packet */
  1212. qdf_mem_copy(ptr_wh->i_addr3, src_addr, QDF_MAC_ADDR_SIZE);
  1213. peer->tx_capture.tx_wifi_ppdu_id = ppdu_desc->ppdu_id;
  1214. }
  1215. frame_size = (ppdu_desc->user[0].tid != DP_NON_QOS_TID) ?
  1216. sizeof(struct ieee80211_qosframe) :
  1217. sizeof(struct ieee80211_frame);
  1218. mpdu_buf_len = frame_size + LLC_SNAP_HDR_LEN;
  1219. nbuf->protocol = qdf_htons(ETH_P_802_2);
  1220. /* update ieee80211_frame header */
  1221. if (!qdf_nbuf_push_head(nbuf, mpdu_buf_len)) {
  1222. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_ERROR,
  1223. FL("No headroom"));
  1224. return QDF_STATUS_E_NOMEM;
  1225. }
  1226. ptr_hdr = (void *)qdf_nbuf_data(nbuf);
  1227. qdf_mem_copy(ptr_hdr, ptr_wh, frame_size);
  1228. ptr_hdr = ptr_hdr + frame_size;
  1229. /* update LLC */
  1230. *ptr_hdr = LLC_SNAP_LSAP;
  1231. *(ptr_hdr + 1) = LLC_SNAP_LSAP;
  1232. *(ptr_hdr + 2) = LLC_UI;
  1233. *(ptr_hdr + 3) = 0x00;
  1234. *(ptr_hdr + 4) = 0x00;
  1235. *(ptr_hdr + 5) = 0x00;
  1236. *(ptr_hdr + 6) = (eth_type & 0xFF00) >> 8;
  1237. *(ptr_hdr + 7) = (eth_type & 0xFF);
  1238. qdf_nbuf_trim_tail(nbuf, qdf_nbuf_len(nbuf) - mpdu_buf_len);
  1239. return 0;
  1240. }
  1241. /**
  1242. * dp_tx_mon_restitch_mpdu(): Function to restitch msdu to mpdu
  1243. * @pdev: dp_pdev
  1244. * @peer: dp_peer
  1245. * @head_msdu: head msdu queue
  1246. *
  1247. * return: status
  1248. */
  1249. static uint32_t
  1250. dp_tx_mon_restitch_mpdu(struct dp_pdev *pdev, struct dp_peer *peer,
  1251. struct cdp_tx_completion_ppdu *ppdu_desc,
  1252. qdf_nbuf_queue_t *head_msdu,
  1253. qdf_nbuf_queue_t *mpdu_q)
  1254. {
  1255. qdf_nbuf_t curr_nbuf = NULL;
  1256. qdf_nbuf_t first_nbuf = NULL;
  1257. qdf_nbuf_t prev_nbuf = NULL;
  1258. qdf_nbuf_t mpdu_nbuf = NULL;
  1259. struct msdu_completion_info *ptr_msdu_info = NULL;
  1260. uint8_t first_msdu = 0;
  1261. uint8_t last_msdu = 0;
  1262. uint32_t frag_list_sum_len = 0;
  1263. uint8_t first_msdu_not_seen = 1;
  1264. uint16_t ether_type = 0;
  1265. qdf_ether_header_t *eh = NULL;
  1266. curr_nbuf = qdf_nbuf_queue_remove(head_msdu);
  1267. while (curr_nbuf) {
  1268. ptr_msdu_info =
  1269. (struct msdu_completion_info *)qdf_nbuf_data(curr_nbuf);
  1270. first_msdu = ptr_msdu_info->first_msdu;
  1271. last_msdu = ptr_msdu_info->last_msdu;
  1272. eh = (qdf_ether_header_t *)(curr_nbuf->data +
  1273. sizeof(struct msdu_completion_info));
  1274. ether_type = eh->ether_type;
  1275. /* pull msdu_completion_info added in pre header */
  1276. qdf_nbuf_pull_head(curr_nbuf,
  1277. sizeof(struct msdu_completion_info));
  1278. if ((qdf_likely((peer->vdev->tx_encap_type !=
  1279. htt_cmn_pkt_type_raw))) &&
  1280. ((ppdu_desc->frame_ctrl & IEEE80211_FC1_DIR_MASK) &&
  1281. (IEEE80211_FC1_DIR_TODS | IEEE80211_FC1_DIR_FROMDS)))
  1282. dp_peer_tx_wds_addr_add(peer, eh->ether_shost);
  1283. if (first_msdu && first_msdu_not_seen) {
  1284. first_nbuf = curr_nbuf;
  1285. frag_list_sum_len = 0;
  1286. first_msdu_not_seen = 0;
  1287. /* pull ethernet header from first MSDU alone */
  1288. qdf_nbuf_pull_head(curr_nbuf,
  1289. sizeof(qdf_ether_header_t));
  1290. /* update first buffer to previous buffer */
  1291. prev_nbuf = curr_nbuf;
  1292. } else if (first_msdu && !first_msdu_not_seen) {
  1293. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  1294. QDF_TRACE_LEVEL_FATAL,
  1295. "!!!!! NO LAST MSDU\n");
  1296. /*
  1297. * no last msdu in a mpdu
  1298. * handle this case
  1299. */
  1300. qdf_nbuf_free(curr_nbuf);
  1301. /*
  1302. * No last msdu found because WBM comes out
  1303. * of order, free the pkt
  1304. */
  1305. goto free_ppdu_desc_mpdu_q;
  1306. } else if (!first_msdu && first_msdu_not_seen) {
  1307. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  1308. QDF_TRACE_LEVEL_FATAL,
  1309. "!!!!! NO FIRST MSDU\n");
  1310. /*
  1311. * no first msdu in a mpdu
  1312. * handle this case
  1313. */
  1314. qdf_nbuf_free(curr_nbuf);
  1315. /*
  1316. * no first msdu found beacuse WBM comes out
  1317. * of order, free the pkt
  1318. */
  1319. goto free_ppdu_desc_mpdu_q;
  1320. } else {
  1321. /* update current buffer to previous buffer next */
  1322. prev_nbuf->next = curr_nbuf;
  1323. /* move the previous buffer to next buffer */
  1324. prev_nbuf = prev_nbuf->next;
  1325. }
  1326. frag_list_sum_len += qdf_nbuf_len(curr_nbuf);
  1327. if (last_msdu) {
  1328. mpdu_nbuf = qdf_nbuf_alloc(pdev->soc->osdev,
  1329. MAX_MONITOR_HEADER,
  1330. MAX_MONITOR_HEADER,
  1331. 4, FALSE);
  1332. if (!mpdu_nbuf) {
  1333. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  1334. QDF_TRACE_LEVEL_FATAL,
  1335. "MPDU head allocation failed !!!");
  1336. goto free_ppdu_desc_mpdu_q;
  1337. }
  1338. if (((ppdu_desc->frame_ctrl & IEEE80211_FC1_DIR_MASK) &&
  1339. (IEEE80211_FC1_DIR_TODS |
  1340. IEEE80211_FC1_DIR_FROMDS))) {
  1341. dp_tx_update_80211_wds_hdr(pdev, peer,
  1342. ppdu_desc, mpdu_nbuf,
  1343. ether_type,
  1344. eh->ether_shost);
  1345. } else {
  1346. dp_tx_update_80211_hdr(pdev, peer,
  1347. ppdu_desc, mpdu_nbuf,
  1348. ether_type,
  1349. eh->ether_shost);
  1350. }
  1351. /*
  1352. * first nbuf will hold list of msdu
  1353. * stored in prev_nbuf
  1354. */
  1355. qdf_nbuf_append_ext_list(mpdu_nbuf,
  1356. first_nbuf,
  1357. frag_list_sum_len);
  1358. /* add mpdu to mpdu queue */
  1359. qdf_nbuf_queue_add(mpdu_q, mpdu_nbuf);
  1360. first_nbuf = NULL;
  1361. mpdu_nbuf = NULL;
  1362. /* next msdu will start with first msdu */
  1363. first_msdu_not_seen = 1;
  1364. goto check_for_next_msdu;
  1365. }
  1366. /* get next msdu from the head_msdu */
  1367. curr_nbuf = qdf_nbuf_queue_remove(head_msdu);
  1368. if (!curr_nbuf) {
  1369. /* msdu missed in list */
  1370. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  1371. QDF_TRACE_LEVEL_FATAL,
  1372. "!!!! WAITING for msdu but list empty !!!!");
  1373. /* for incomplete list, free up the queue */
  1374. goto free_ppdu_desc_mpdu_q;
  1375. }
  1376. continue;
  1377. check_for_next_msdu:
  1378. if (qdf_nbuf_is_queue_empty(head_msdu))
  1379. return 0;
  1380. curr_nbuf = qdf_nbuf_queue_remove(head_msdu);
  1381. }
  1382. return 0;
  1383. free_ppdu_desc_mpdu_q:
  1384. /* free already chained msdu pkt */
  1385. while (first_nbuf) {
  1386. curr_nbuf = first_nbuf;
  1387. first_nbuf = first_nbuf->next;
  1388. qdf_nbuf_free(curr_nbuf);
  1389. }
  1390. /* free allocated mpdu hdr */
  1391. if (mpdu_nbuf)
  1392. qdf_nbuf_free(mpdu_nbuf);
  1393. /* free queued remaining msdu pkt per ppdu */
  1394. qdf_nbuf_queue_free(head_msdu);
  1395. /* free queued mpdu per ppdu */
  1396. qdf_nbuf_queue_free(mpdu_q);
  1397. return 0;
  1398. }
  1399. /**
  1400. * dp_tx_msdu_dequeue(): Function to dequeue msdu from peer based tid
  1401. * @peer: dp_peer
  1402. * @ppdu_id: ppdu_id
  1403. * @tid: tid
  1404. * @num_msdu: number of msdu
  1405. * @head: head queue
  1406. * @start_tsf: start tsf from ppdu_desc
  1407. * @end_tsf: end tsf from ppdu_desc
  1408. *
  1409. * return: status
  1410. */
  1411. static
  1412. uint32_t dp_tx_msdu_dequeue(struct dp_peer *peer, uint32_t ppdu_id,
  1413. uint16_t tid, uint32_t num_msdu,
  1414. qdf_nbuf_queue_t *head,
  1415. qdf_nbuf_queue_t *head_xretries,
  1416. uint32_t start_tsf, uint32_t end_tsf)
  1417. {
  1418. struct dp_tx_tid *tx_tid = NULL;
  1419. uint32_t msdu_ppdu_id;
  1420. qdf_nbuf_t curr_msdu = NULL;
  1421. qdf_nbuf_t prev_msdu = NULL;
  1422. struct msdu_completion_info *ptr_msdu_info = NULL;
  1423. uint32_t wbm_tsf;
  1424. uint32_t matched = 0;
  1425. if (qdf_unlikely(!peer))
  1426. return 0;
  1427. /* Non-QOS frames are being indicated with TID 0
  1428. * in WBM completion path, an hence we should
  1429. * TID 0 to reap MSDUs from completion path
  1430. */
  1431. if (qdf_unlikely(tid == DP_NON_QOS_TID))
  1432. tid = 0;
  1433. tx_tid = &peer->tx_capture.tx_tid[tid];
  1434. if (qdf_unlikely(!tx_tid))
  1435. return 0;
  1436. /* lock here */
  1437. qdf_spin_lock_bh(&tx_tid->tid_lock);
  1438. if (qdf_nbuf_is_queue_empty(&tx_tid->msdu_comp_q)) {
  1439. qdf_spin_unlock_bh(&tx_tid->tid_lock);
  1440. return 0;
  1441. }
  1442. curr_msdu = qdf_nbuf_queue_first(&tx_tid->msdu_comp_q);
  1443. while (curr_msdu) {
  1444. if (qdf_nbuf_queue_len(head) == num_msdu) {
  1445. matched = 1;
  1446. break;
  1447. }
  1448. ptr_msdu_info =
  1449. (struct msdu_completion_info *)qdf_nbuf_data(curr_msdu);
  1450. msdu_ppdu_id = ptr_msdu_info->ppdu_id;
  1451. wbm_tsf = ptr_msdu_info->tsf;
  1452. if ((ptr_msdu_info->status == HAL_TX_TQM_RR_REM_CMD_TX) ||
  1453. (ptr_msdu_info->status == HAL_TX_TQM_RR_REM_CMD_AGED)) {
  1454. /* Frames removed due to excessive retries */
  1455. qdf_nbuf_queue_remove(&tx_tid->msdu_comp_q);
  1456. qdf_nbuf_queue_add(head_xretries, curr_msdu);
  1457. curr_msdu = qdf_nbuf_queue_first(
  1458. &tx_tid->msdu_comp_q);
  1459. prev_msdu = NULL;
  1460. continue;
  1461. }
  1462. if (wbm_tsf > end_tsf) {
  1463. /* PPDU being matched is older than MSDU at head of
  1464. * completion queue. Return matched=1 to skip PPDU
  1465. */
  1466. matched = 1;
  1467. break;
  1468. }
  1469. if (wbm_tsf && (wbm_tsf < start_tsf)) {
  1470. /* remove the aged packet */
  1471. qdf_nbuf_queue_remove(&tx_tid->msdu_comp_q);
  1472. qdf_nbuf_free(curr_msdu);
  1473. curr_msdu = qdf_nbuf_queue_first(
  1474. &tx_tid->msdu_comp_q);
  1475. prev_msdu = NULL;
  1476. continue;
  1477. }
  1478. if (msdu_ppdu_id == ppdu_id) {
  1479. if (qdf_likely(!prev_msdu)) {
  1480. /* remove head */
  1481. qdf_nbuf_queue_remove(&tx_tid->msdu_comp_q);
  1482. /* add msdu to head queue */
  1483. qdf_nbuf_queue_add(head, curr_msdu);
  1484. /* get next msdu from msdu_comp_q */
  1485. curr_msdu = qdf_nbuf_queue_first(
  1486. &tx_tid->msdu_comp_q);
  1487. continue;
  1488. } else {
  1489. /* update prev_msdu next to current msdu next */
  1490. prev_msdu->next = curr_msdu->next;
  1491. /* set current msdu next as NULL */
  1492. curr_msdu->next = NULL;
  1493. /* decrement length */
  1494. ((qdf_nbuf_queue_t *)(
  1495. &tx_tid->msdu_comp_q))->qlen--;
  1496. /* add msdu to head queue */
  1497. qdf_nbuf_queue_add(head, curr_msdu);
  1498. /* set previous msdu to current msdu */
  1499. curr_msdu = prev_msdu->next;
  1500. continue;
  1501. }
  1502. }
  1503. prev_msdu = curr_msdu;
  1504. curr_msdu = prev_msdu->next;
  1505. }
  1506. qdf_spin_unlock_bh(&tx_tid->tid_lock);
  1507. return matched;
  1508. }
  1509. /**
  1510. * get_mpdu_clone_from_next_ppdu(): Function to clone missing mpdu from
  1511. * next ppdu
  1512. * @nbuf_ppdu_desc_list: nbuf list
  1513. * @ppdu_desc_cnt: ppdu_desc_cnt
  1514. * @missed_seq_no:
  1515. * @ppdu_id: ppdu_id
  1516. * @mpdu_info: cdp_tx_indication_mpdu_info
  1517. *
  1518. * return: void
  1519. */
  1520. static
  1521. qdf_nbuf_t get_mpdu_clone_from_next_ppdu(qdf_nbuf_t nbuf_ppdu_desc_list[],
  1522. uint32_t ppdu_desc_cnt,
  1523. uint16_t missed_seq_no,
  1524. uint16_t peer_id, uint32_t ppdu_id)
  1525. {
  1526. uint32_t i = 0;
  1527. uint32_t found = 0;
  1528. uint32_t seq_no = 0;
  1529. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  1530. qdf_nbuf_t mpdu = NULL;
  1531. for (i = 1; i < ppdu_desc_cnt; i++) {
  1532. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  1533. qdf_nbuf_data(nbuf_ppdu_desc_list[i]);
  1534. /* check if seq number is between the range */
  1535. if ((peer_id == ppdu_desc->user[0].peer_id) &&
  1536. ((missed_seq_no >= ppdu_desc->user[0].start_seq) &&
  1537. (missed_seq_no <= ppdu_desc->user[0].last_enq_seq))) {
  1538. seq_no = ppdu_desc->user[0].start_seq;
  1539. if (SEQ_BIT(ppdu_desc->user[0].failed_bitmap,
  1540. (missed_seq_no - seq_no))) {
  1541. found = 1;
  1542. break;
  1543. }
  1544. }
  1545. }
  1546. if (found == 0) {
  1547. /* mpdu not found in sched cmd id */
  1548. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_DEBUG,
  1549. "%s: missed seq_no[%d] ppdu_id[%d] [%d] not found!!!",
  1550. __func__, missed_seq_no, ppdu_id, ppdu_desc_cnt);
  1551. return NULL;
  1552. }
  1553. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_DEBUG,
  1554. "%s: seq_no[%d] missed ppdu_id[%d] m[%d] found in ppdu_id[%d]!!",
  1555. __func__,
  1556. missed_seq_no, ppdu_id,
  1557. (missed_seq_no - seq_no), ppdu_desc->ppdu_id);
  1558. mpdu = qdf_nbuf_queue_first(&ppdu_desc->mpdu_q);
  1559. if (!mpdu) {
  1560. /* bitmap shows it found sequence number, but
  1561. * MPDU not found in PPDU
  1562. */
  1563. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE, QDF_TRACE_LEVEL_ERROR,
  1564. "%s: missed seq_no[%d] ppdu_id[%d] [%d] found but queue empty!!!",
  1565. __func__, missed_seq_no, ppdu_id, ppdu_desc_cnt);
  1566. return NULL;
  1567. }
  1568. for (i = 0; i < (missed_seq_no - seq_no); i++) {
  1569. mpdu = mpdu->next;
  1570. if (!mpdu) {
  1571. /*
  1572. * bitmap shows it found sequence number,
  1573. * but queue empty, do we need to allocate
  1574. * skb and send instead of NULL ?
  1575. * add counter here:
  1576. */
  1577. return NULL;
  1578. }
  1579. }
  1580. return qdf_nbuf_copy_expand_fraglist(mpdu, MAX_MONITOR_HEADER, 0);
  1581. }
  1582. /**
  1583. * dp_tx_update_user_mpdu_info(): Function to update mpdu info
  1584. * from ppdu_desc
  1585. * @ppdu_id: ppdu_id
  1586. * @mpdu_info: cdp_tx_indication_mpdu_info
  1587. * @user: cdp_tx_completion_ppdu_user
  1588. *
  1589. * return: void
  1590. */
  1591. static void
  1592. dp_tx_update_user_mpdu_info(uint32_t ppdu_id,
  1593. struct cdp_tx_indication_mpdu_info *mpdu_info,
  1594. struct cdp_tx_completion_ppdu_user *user)
  1595. {
  1596. mpdu_info->ppdu_id = ppdu_id;
  1597. mpdu_info->frame_ctrl = user->frame_ctrl;
  1598. mpdu_info->qos_ctrl = user->qos_ctrl;
  1599. mpdu_info->tid = user->tid;
  1600. mpdu_info->ltf_size = user->ltf_size;
  1601. mpdu_info->he_re = user->he_re;
  1602. mpdu_info->txbf = user->txbf;
  1603. mpdu_info->bw = user->bw;
  1604. mpdu_info->nss = user->nss;
  1605. mpdu_info->mcs = user->mcs;
  1606. mpdu_info->preamble = user->preamble;
  1607. mpdu_info->gi = user->gi;
  1608. mpdu_info->ack_rssi = user->ack_rssi[0];
  1609. mpdu_info->tx_rate = user->tx_rate;
  1610. mpdu_info->ldpc = user->ldpc;
  1611. mpdu_info->ppdu_cookie = user->ppdu_cookie;
  1612. mpdu_info->long_retries = user->long_retries;
  1613. mpdu_info->short_retries = user->short_retries;
  1614. mpdu_info->completion_status = user->completion_status;
  1615. qdf_mem_copy(mpdu_info->mac_address, user->mac_addr, 6);
  1616. mpdu_info->ba_start_seq = user->ba_seq_no;
  1617. qdf_mem_copy(mpdu_info->ba_bitmap, user->ba_bitmap,
  1618. CDP_BA_256_BIT_MAP_SIZE_DWORDS * sizeof(uint32_t));
  1619. }
  1620. static inline
  1621. void dp_tx_update_sequence_number(qdf_nbuf_t nbuf, uint32_t seq_no)
  1622. {
  1623. struct ieee80211_frame *ptr_wh = NULL;
  1624. uint16_t wh_seq = 0;
  1625. if (!nbuf)
  1626. return;
  1627. /* update sequence number in frame header */
  1628. ptr_wh = (struct ieee80211_frame *)qdf_nbuf_data(nbuf);
  1629. wh_seq = (seq_no & 0xFFF) << 4;
  1630. qdf_mem_copy(ptr_wh->i_seq, &wh_seq, sizeof(uint16_t));
  1631. }
  1632. static inline
  1633. void dp_update_frame_ctrl_from_frame_type(void *desc)
  1634. {
  1635. struct cdp_tx_completion_ppdu *ppdu_desc = desc;
  1636. /* frame control is not set properly, sometimes it is zero */
  1637. switch (ppdu_desc->htt_frame_type) {
  1638. case HTT_STATS_FTYPE_SGEN_NDPA:
  1639. case HTT_STATS_FTYPE_SGEN_NDP:
  1640. case HTT_STATS_FTYPE_SGEN_AX_NDPA:
  1641. case HTT_STATS_FTYPE_SGEN_AX_NDP:
  1642. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_NDPA |
  1643. IEEE80211_FC0_TYPE_CTL);
  1644. break;
  1645. case HTT_STATS_FTYPE_SGEN_BRP:
  1646. case HTT_STATS_FTYPE_SGEN_MU_BRP:
  1647. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_BRPOLL |
  1648. IEEE80211_FC0_TYPE_CTL);
  1649. break;
  1650. case HTT_STATS_FTYPE_SGEN_RTS:
  1651. case HTT_STATS_FTYPE_SGEN_MU_RTS:
  1652. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_RTS |
  1653. IEEE80211_FC0_TYPE_CTL);
  1654. break;
  1655. case HTT_STATS_FTYPE_SGEN_CTS:
  1656. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_CTS |
  1657. IEEE80211_FC0_TYPE_CTL);
  1658. break;
  1659. case HTT_STATS_FTYPE_SGEN_CFEND:
  1660. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_CF_END |
  1661. IEEE80211_FC0_TYPE_CTL);
  1662. break;
  1663. case HTT_STATS_FTYPE_SGEN_MU_TRIG:
  1664. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_TRIGGER |
  1665. IEEE80211_FC0_TYPE_CTL);
  1666. break;
  1667. case HTT_STATS_FTYPE_SGEN_BAR:
  1668. case HTT_STATS_FTYPE_SGEN_MU_BAR:
  1669. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_BAR |
  1670. IEEE80211_FC0_TYPE_CTL);
  1671. break;
  1672. }
  1673. }
  1674. /**
  1675. * dp_send_dummy_mpdu_info_to_stack(): send dummy payload to stack
  1676. * to upper layer if complete
  1677. * @pdev: DP pdev handle
  1678. * @desc: cdp tx completion ppdu desc
  1679. *
  1680. * return: status
  1681. */
  1682. static inline
  1683. QDF_STATUS dp_send_dummy_mpdu_info_to_stack(struct dp_pdev *pdev,
  1684. void *desc)
  1685. {
  1686. struct dp_peer *peer;
  1687. struct dp_vdev *vdev = NULL;
  1688. struct cdp_tx_completion_ppdu *ppdu_desc = desc;
  1689. struct cdp_tx_completion_ppdu_user *user = &ppdu_desc->user[0];
  1690. struct ieee80211_ctlframe_addr2 *wh_min;
  1691. uint16_t frame_ctrl_le, duration_le;
  1692. struct cdp_tx_indication_info tx_capture_info;
  1693. struct cdp_tx_indication_mpdu_info *mpdu_info;
  1694. uint8_t type, subtype;
  1695. qdf_mem_set(&tx_capture_info,
  1696. sizeof(struct cdp_tx_indication_info),
  1697. 0);
  1698. tx_capture_info.mpdu_nbuf =
  1699. qdf_nbuf_alloc(pdev->soc->osdev,
  1700. MAX_MONITOR_HEADER + MAX_DUMMY_FRM_BODY,
  1701. MAX_MONITOR_HEADER,
  1702. 4, FALSE);
  1703. if (!tx_capture_info.mpdu_nbuf)
  1704. return QDF_STATUS_E_ABORTED;
  1705. mpdu_info = &tx_capture_info.mpdu_info;
  1706. mpdu_info->resp_type = ppdu_desc->resp_type;
  1707. mpdu_info->mprot_type = ppdu_desc->mprot_type;
  1708. mpdu_info->rts_success = ppdu_desc->rts_success;
  1709. mpdu_info->rts_failure = ppdu_desc->rts_failure;
  1710. /* update cdp_tx_indication_mpdu_info */
  1711. dp_tx_update_user_mpdu_info(ppdu_desc->bar_ppdu_id,
  1712. &tx_capture_info.mpdu_info,
  1713. &ppdu_desc->user[0]);
  1714. tx_capture_info.ppdu_desc = ppdu_desc;
  1715. mpdu_info->ppdu_id = ppdu_desc->ppdu_id;
  1716. mpdu_info->channel_num = pdev->operating_channel.num;
  1717. mpdu_info->channel = ppdu_desc->channel;
  1718. mpdu_info->frame_type = ppdu_desc->frame_type;
  1719. mpdu_info->ppdu_start_timestamp = ppdu_desc->ppdu_start_timestamp;
  1720. mpdu_info->ppdu_end_timestamp = ppdu_desc->ppdu_end_timestamp;
  1721. mpdu_info->tx_duration = ppdu_desc->tx_duration;
  1722. mpdu_info->seq_no = user->start_seq;
  1723. qdf_mem_copy(mpdu_info->mac_address, user->mac_addr, QDF_MAC_ADDR_SIZE);
  1724. mpdu_info->ba_start_seq = user->ba_seq_no;
  1725. qdf_mem_copy(mpdu_info->ba_bitmap, user->ba_bitmap,
  1726. CDP_BA_256_BIT_MAP_SIZE_DWORDS * sizeof(uint32_t));
  1727. mpdu_info->frame_ctrl = ppdu_desc->frame_ctrl;
  1728. type = (ppdu_desc->frame_ctrl & IEEE80211_FC0_TYPE_MASK);
  1729. subtype = (ppdu_desc->frame_ctrl & IEEE80211_FC0_SUBTYPE_MASK);
  1730. if (type == IEEE80211_FC0_TYPE_CTL &&
  1731. subtype == IEEE80211_FC0_SUBTYPE_BAR) {
  1732. mpdu_info->frame_ctrl = (IEEE80211_FC0_SUBTYPE_BAR |
  1733. IEEE80211_FC0_TYPE_CTL);
  1734. mpdu_info->ppdu_id = ppdu_desc->bar_ppdu_id;
  1735. mpdu_info->ppdu_start_timestamp =
  1736. ppdu_desc->bar_ppdu_start_timestamp;
  1737. mpdu_info->ppdu_end_timestamp =
  1738. ppdu_desc->bar_ppdu_end_timestamp;
  1739. mpdu_info->tx_duration = ppdu_desc->bar_tx_duration;
  1740. }
  1741. wh_min = (struct ieee80211_ctlframe_addr2 *)
  1742. qdf_nbuf_data(
  1743. tx_capture_info.mpdu_nbuf);
  1744. qdf_mem_zero(wh_min, MAX_DUMMY_FRM_BODY);
  1745. frame_ctrl_le =
  1746. qdf_cpu_to_le16(mpdu_info->frame_ctrl);
  1747. duration_le =
  1748. qdf_cpu_to_le16(mpdu_info->tx_duration);
  1749. wh_min->i_fc[1] = (frame_ctrl_le & 0xFF00) >> 8;
  1750. wh_min->i_fc[0] = (frame_ctrl_le & 0xFF);
  1751. wh_min->i_aidordur[1] = (duration_le & 0xFF00) >> 8;
  1752. wh_min->i_aidordur[0] = (duration_le & 0xFF);
  1753. qdf_mem_copy(wh_min->i_addr1,
  1754. mpdu_info->mac_address,
  1755. QDF_MAC_ADDR_SIZE);
  1756. if (subtype == IEEE80211_FC0_SUBTYPE_ACK)
  1757. qdf_nbuf_set_pktlen(tx_capture_info.mpdu_nbuf,
  1758. sizeof(struct ieee80211_frame_min_one));
  1759. else {
  1760. peer = dp_tx_cap_peer_find_by_id(pdev->soc, user->peer_id);
  1761. if (peer) {
  1762. vdev = peer->vdev;
  1763. dp_tx_cap_peer_unref_del(peer);
  1764. } else {
  1765. vdev =
  1766. dp_get_vdev_from_soc_vdev_id_wifi3(pdev->soc,
  1767. ppdu_desc->vdev_id);
  1768. }
  1769. if (vdev)
  1770. qdf_mem_copy(wh_min->i_addr2,
  1771. vdev->mac_addr.raw,
  1772. QDF_MAC_ADDR_SIZE);
  1773. qdf_nbuf_set_pktlen(tx_capture_info.mpdu_nbuf, sizeof(*wh_min));
  1774. }
  1775. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  1776. QDF_TRACE_LEVEL_DEBUG,
  1777. "HTT_FTYPE[%d] frm(0x%08x): fc %x %x, dur 0x%x%x\n",
  1778. ppdu_desc->htt_frame_type, mpdu_info->ppdu_id,
  1779. wh_min->i_fc[1], wh_min->i_fc[0],
  1780. wh_min->i_aidordur[1], wh_min->i_aidordur[0]);
  1781. /*
  1782. * send MPDU to osif layer
  1783. */
  1784. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  1785. &tx_capture_info, HTT_INVALID_PEER,
  1786. WDI_NO_VAL, pdev->pdev_id);
  1787. if (tx_capture_info.mpdu_nbuf)
  1788. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  1789. return QDF_STATUS_SUCCESS;
  1790. }
  1791. /**
  1792. * dp_send_dummy_rts_cts_frame(): send dummy rts and cts frame out
  1793. * to upper layer if complete
  1794. * @pdev: DP pdev handle
  1795. * @cur_ppdu_desc: cdp tx completion ppdu desc
  1796. *
  1797. * return: void
  1798. */
  1799. static
  1800. void dp_send_dummy_rts_cts_frame(struct dp_pdev *pdev,
  1801. struct cdp_tx_completion_ppdu *cur_ppdu_desc)
  1802. {
  1803. struct cdp_tx_completion_ppdu *ppdu_desc;
  1804. struct dp_pdev_tx_capture *ptr_tx_cap;
  1805. struct dp_peer *peer;
  1806. uint8_t rts_send;
  1807. struct dp_vdev *vdev = NULL;
  1808. rts_send = 0;
  1809. ptr_tx_cap = &pdev->tx_capture;
  1810. ppdu_desc = &ptr_tx_cap->dummy_ppdu_desc;
  1811. ppdu_desc->channel = cur_ppdu_desc->channel;
  1812. ppdu_desc->num_mpdu = 1;
  1813. ppdu_desc->num_msdu = 1;
  1814. ppdu_desc->user[0].ppdu_type = HTT_PPDU_STATS_PPDU_TYPE_SU;
  1815. ppdu_desc->bar_num_users = 0;
  1816. ppdu_desc->num_users = 1;
  1817. if (cur_ppdu_desc->mprot_type == SEND_WIFIRTS_LEGACY_E ||
  1818. cur_ppdu_desc->mprot_type == SEND_WIFIRTS_11AC_DYNAMIC_BW_E ||
  1819. cur_ppdu_desc->mprot_type == SEND_WIFIRTS_11AC_STATIC_BW_E) {
  1820. rts_send = 1;
  1821. /*
  1822. * send dummy RTS frame followed by CTS
  1823. * update frame_ctrl and htt_frame_type
  1824. */
  1825. ppdu_desc->htt_frame_type = HTT_STATS_FTYPE_SGEN_RTS;
  1826. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  1827. ppdu_desc->ppdu_start_timestamp =
  1828. cur_ppdu_desc->ppdu_start_timestamp;
  1829. ppdu_desc->ppdu_end_timestamp =
  1830. cur_ppdu_desc->ppdu_end_timestamp;
  1831. ppdu_desc->tx_duration = cur_ppdu_desc->tx_duration;
  1832. ppdu_desc->user[0].peer_id = cur_ppdu_desc->user[0].peer_id;
  1833. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_RTS |
  1834. IEEE80211_FC0_TYPE_CTL);
  1835. qdf_mem_copy(&ppdu_desc->user[0].mac_addr,
  1836. &cur_ppdu_desc->user[0].mac_addr,
  1837. QDF_MAC_ADDR_SIZE);
  1838. dp_send_dummy_mpdu_info_to_stack(pdev, ppdu_desc);
  1839. }
  1840. if ((rts_send && cur_ppdu_desc->rts_success) ||
  1841. cur_ppdu_desc->mprot_type == SEND_WIFICTS2SELF_E) {
  1842. uint16_t peer_id;
  1843. peer_id = cur_ppdu_desc->user[0].peer_id;
  1844. /* send dummy CTS frame */
  1845. ppdu_desc->htt_frame_type = HTT_STATS_FTYPE_SGEN_CTS;
  1846. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  1847. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_CTS |
  1848. IEEE80211_FC0_TYPE_CTL);
  1849. ppdu_desc->ppdu_start_timestamp =
  1850. cur_ppdu_desc->ppdu_start_timestamp;
  1851. ppdu_desc->ppdu_end_timestamp =
  1852. cur_ppdu_desc->ppdu_end_timestamp;
  1853. ppdu_desc->tx_duration = cur_ppdu_desc->tx_duration -
  1854. (RTS_INTERVAL + SIFS_INTERVAL);
  1855. ppdu_desc->user[0].peer_id = peer_id;
  1856. peer = dp_tx_cap_peer_find_by_id(pdev->soc, peer_id);
  1857. if (peer) {
  1858. vdev = peer->vdev;
  1859. dp_tx_cap_peer_unref_del(peer);
  1860. } else {
  1861. uint8_t vdev_id;
  1862. vdev_id = ppdu_desc->vdev_id;
  1863. vdev = dp_get_vdev_from_soc_vdev_id_wifi3(pdev->soc,
  1864. vdev_id);
  1865. }
  1866. if (vdev)
  1867. qdf_mem_copy(&ppdu_desc->user[0].mac_addr,
  1868. vdev->mac_addr.raw, QDF_MAC_ADDR_SIZE);
  1869. dp_send_dummy_mpdu_info_to_stack(pdev, ppdu_desc);
  1870. }
  1871. }
  1872. static void dp_gen_ack_rx_frame(struct dp_pdev *pdev,
  1873. struct cdp_tx_indication_info *tx_capture_info)
  1874. {
  1875. struct cdp_tx_completion_ppdu *ppdu_desc;
  1876. struct dp_peer *peer;
  1877. struct dp_pdev_tx_capture *ptr_tx_cap;
  1878. ptr_tx_cap = &pdev->tx_capture;
  1879. ppdu_desc = &ptr_tx_cap->dummy_ppdu_desc;
  1880. ppdu_desc->channel = tx_capture_info->ppdu_desc->channel;
  1881. ppdu_desc->num_mpdu = 1;
  1882. ppdu_desc->num_msdu = 1;
  1883. ppdu_desc->user[0].ppdu_type = HTT_PPDU_STATS_PPDU_TYPE_SU;
  1884. ppdu_desc->bar_num_users = 0;
  1885. ppdu_desc->num_users = 1;
  1886. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  1887. ppdu_desc->frame_ctrl = (IEEE80211_FC0_SUBTYPE_ACK |
  1888. IEEE80211_FC0_TYPE_CTL);
  1889. ppdu_desc->ppdu_start_timestamp =
  1890. tx_capture_info->ppdu_desc->ppdu_start_timestamp;
  1891. ppdu_desc->ppdu_end_timestamp =
  1892. tx_capture_info->ppdu_desc->ppdu_end_timestamp;
  1893. ppdu_desc->user[0].peer_id =
  1894. tx_capture_info->ppdu_desc->user[0].peer_id;
  1895. peer = dp_peer_find_by_id(pdev->soc,
  1896. tx_capture_info->ppdu_desc->user[0].peer_id);
  1897. if (peer) {
  1898. struct dp_vdev *vdev = NULL;
  1899. vdev = peer->vdev;
  1900. if (vdev)
  1901. qdf_mem_copy(&ppdu_desc->user[0].mac_addr,
  1902. vdev->mac_addr.raw,
  1903. QDF_MAC_ADDR_SIZE);
  1904. dp_peer_unref_del_find_by_id(peer);
  1905. }
  1906. dp_send_dummy_mpdu_info_to_stack(pdev, ppdu_desc);
  1907. }
  1908. /**
  1909. * dp_send_data_to_stack(): Function to deliver mpdu info to stack
  1910. * to upper layer
  1911. * @pdev: DP pdev handle
  1912. * @nbuf_ppdu_desc_list: ppdu_desc_list per sched cmd id
  1913. * @ppdu_desc_cnt: number of ppdu_desc_cnt
  1914. *
  1915. * return: status
  1916. */
  1917. static
  1918. void dp_send_data_to_stack(struct dp_pdev *pdev,
  1919. struct cdp_tx_completion_ppdu *ppdu_desc)
  1920. {
  1921. struct cdp_tx_indication_info tx_capture_info;
  1922. struct cdp_tx_indication_mpdu_info *mpdu_info;
  1923. int i;
  1924. uint32_t seq_no, start_seq;
  1925. uint32_t ppdu_id = ppdu_desc->ppdu_id;
  1926. qdf_mem_set(&tx_capture_info,
  1927. sizeof(struct cdp_tx_indication_info),
  1928. 0);
  1929. mpdu_info = &tx_capture_info.mpdu_info;
  1930. mpdu_info->channel = ppdu_desc->channel;
  1931. mpdu_info->frame_type = ppdu_desc->frame_type;
  1932. mpdu_info->ppdu_start_timestamp =
  1933. ppdu_desc->ppdu_start_timestamp;
  1934. mpdu_info->ppdu_end_timestamp =
  1935. ppdu_desc->ppdu_end_timestamp;
  1936. mpdu_info->tx_duration = ppdu_desc->tx_duration;
  1937. mpdu_info->num_msdu = ppdu_desc->num_msdu;
  1938. mpdu_info->resp_type = ppdu_desc->resp_type;
  1939. mpdu_info->mprot_type = ppdu_desc->mprot_type;
  1940. mpdu_info->rts_success = ppdu_desc->rts_success;
  1941. mpdu_info->rts_failure = ppdu_desc->rts_failure;
  1942. /* update cdp_tx_indication_mpdu_info */
  1943. dp_tx_update_user_mpdu_info(ppdu_id,
  1944. &tx_capture_info.mpdu_info,
  1945. &ppdu_desc->user[0]);
  1946. tx_capture_info.ppdu_desc = ppdu_desc;
  1947. tx_capture_info.mpdu_info.channel_num = pdev->operating_channel.num;
  1948. if (ppdu_desc->mprot_type)
  1949. dp_send_dummy_rts_cts_frame(pdev, ppdu_desc);
  1950. start_seq = ppdu_desc->user[0].start_seq;
  1951. for (i = 0; i < ppdu_desc->user[0].ba_size; i++) {
  1952. if (qdf_likely(ppdu_desc->user[0].tid !=
  1953. DP_NON_QOS_TID) &&
  1954. !(SEQ_BIT(ppdu_desc->user[0].enq_bitmap, i))) {
  1955. continue;
  1956. }
  1957. seq_no = start_seq + i;
  1958. if (!ppdu_desc->mpdus[i])
  1959. continue;
  1960. tx_capture_info.mpdu_nbuf = ppdu_desc->mpdus[i];
  1961. ppdu_desc->mpdus[i] = NULL;
  1962. mpdu_info->seq_no = seq_no;
  1963. dp_tx_update_sequence_number(tx_capture_info.mpdu_nbuf, seq_no);
  1964. /*
  1965. * send MPDU to osif layer
  1966. * do we need to update mpdu_info before tranmit
  1967. * get current mpdu_nbuf
  1968. */
  1969. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  1970. &tx_capture_info,
  1971. HTT_INVALID_PEER,
  1972. WDI_NO_VAL, pdev->pdev_id);
  1973. if (tx_capture_info.mpdu_nbuf)
  1974. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  1975. }
  1976. if (ppdu_desc->resp_type == HTT_PPDU_STATS_ACK_EXPECTED_E &&
  1977. ppdu_desc->user[0].completion_status ==
  1978. HTT_PPDU_STATS_USER_STATUS_OK)
  1979. dp_gen_ack_rx_frame(pdev, &tx_capture_info);
  1980. }
  1981. static qdf_nbuf_t dp_tx_mon_get_next_mpdu(
  1982. struct cdp_tx_completion_ppdu *xretry_ppdu,
  1983. qdf_nbuf_t mpdu_nbuf)
  1984. {
  1985. qdf_nbuf_t next_nbuf = NULL;
  1986. qdf_nbuf_queue_t temp_xretries;
  1987. if (mpdu_nbuf != qdf_nbuf_queue_first(&xretry_ppdu->mpdu_q)) {
  1988. next_nbuf = qdf_nbuf_queue_next(mpdu_nbuf);
  1989. /* Initialize temp list */
  1990. qdf_nbuf_queue_init(&temp_xretries);
  1991. /* Move entries into temp list till the mpdu_nbuf is found */
  1992. while ((qdf_nbuf_queue_first(&xretry_ppdu->mpdu_q)) &&
  1993. (mpdu_nbuf !=
  1994. qdf_nbuf_queue_first(&xretry_ppdu->mpdu_q))) {
  1995. qdf_nbuf_queue_add(&temp_xretries,
  1996. qdf_nbuf_queue_remove(&xretry_ppdu->mpdu_q));
  1997. }
  1998. if ((qdf_nbuf_queue_first(&xretry_ppdu->mpdu_q)) &&
  1999. (mpdu_nbuf == qdf_nbuf_queue_first(&xretry_ppdu->mpdu_q))) {
  2000. /* Remove mpdu_nbuf from queue */
  2001. qdf_nbuf_queue_remove(&xretry_ppdu->mpdu_q);
  2002. /* Add remaining nbufs into temp queue */
  2003. qdf_nbuf_queue_append(&temp_xretries,
  2004. &xretry_ppdu->mpdu_q);
  2005. /* Reinit xretry_ppdu->mpdu_q */
  2006. qdf_nbuf_queue_init(&xretry_ppdu->mpdu_q);
  2007. /* append all the entries into original queue */
  2008. qdf_nbuf_queue_append(&xretry_ppdu->mpdu_q,
  2009. &temp_xretries);
  2010. } else {
  2011. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  2012. QDF_TRACE_LEVEL_FATAL,
  2013. "%s: This is buggy scenario, did not find nbuf in queue ",
  2014. __func__);
  2015. }
  2016. } else {
  2017. qdf_nbuf_queue_remove(&xretry_ppdu->mpdu_q);
  2018. next_nbuf = qdf_nbuf_queue_first(&xretry_ppdu->mpdu_q);
  2019. }
  2020. return next_nbuf;
  2021. }
  2022. static void
  2023. dp_tx_mon_proc_xretries(struct dp_pdev *pdev, struct dp_peer *peer,
  2024. uint16_t tid)
  2025. {
  2026. struct dp_tx_tid *tx_tid = &peer->tx_capture.tx_tid[tid];
  2027. struct cdp_tx_completion_ppdu *ppdu_desc;
  2028. struct cdp_tx_completion_ppdu *xretry_ppdu;
  2029. qdf_nbuf_t ppdu_nbuf;
  2030. qdf_nbuf_t mpdu_nbuf;
  2031. uint32_t mpdu_tried = 0;
  2032. int i;
  2033. uint32_t seq_no;
  2034. xretry_ppdu = &tx_tid->xretry_ppdu;
  2035. if (qdf_nbuf_is_queue_empty(&tx_tid->pending_ppdu_q)) {
  2036. qdf_nbuf_queue_free(&xretry_ppdu->mpdu_q);
  2037. return;
  2038. }
  2039. if (qdf_nbuf_is_queue_empty(&xretry_ppdu->mpdu_q))
  2040. return;
  2041. ppdu_nbuf = qdf_nbuf_queue_first(&tx_tid->pending_ppdu_q);
  2042. while (ppdu_nbuf) {
  2043. struct msdu_completion_info *ptr_msdu_info = NULL;
  2044. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  2045. qdf_nbuf_data(ppdu_nbuf);
  2046. if (ppdu_desc->pending_retries) {
  2047. uint32_t start_seq = ppdu_desc->user[0].start_seq;
  2048. mpdu_tried = ppdu_desc->user[0].mpdu_tried_ucast +
  2049. ppdu_desc->user[0].mpdu_tried_mcast;
  2050. mpdu_nbuf = qdf_nbuf_queue_first(&xretry_ppdu->mpdu_q);
  2051. for (i = 0; (i < ppdu_desc->user[0].ba_size) &&
  2052. (mpdu_tried > 0) && (mpdu_nbuf); i++) {
  2053. if (!(SEQ_BIT(ppdu_desc->user[0].enq_bitmap,
  2054. i)))
  2055. continue;
  2056. mpdu_tried--;
  2057. /* missed seq number */
  2058. seq_no = start_seq + i;
  2059. if (SEQ_BIT(ppdu_desc->user[0].failed_bitmap, i))
  2060. continue;
  2061. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  2062. QDF_TRACE_LEVEL_INFO,
  2063. "%s: fill seqno %d from xretries",
  2064. __func__, seq_no);
  2065. ptr_msdu_info = (struct msdu_completion_info *)
  2066. (qdf_nbuf_data(qdf_nbuf_get_ext_list(
  2067. mpdu_nbuf)) -
  2068. (sizeof(struct msdu_completion_info) +
  2069. sizeof(qdf_ether_header_t)));
  2070. ptr_msdu_info->transmit_cnt--;
  2071. SEQ_SEG(ppdu_desc->user[0].failed_bitmap, i) |=
  2072. SEQ_SEG_MSK(ppdu_desc->user[0].failed_bitmap[0],
  2073. i);
  2074. ppdu_desc->pending_retries--;
  2075. if (ptr_msdu_info->transmit_cnt == 0) {
  2076. ppdu_desc->mpdus[seq_no - start_seq] =
  2077. mpdu_nbuf;
  2078. /*
  2079. * This API removes mpdu_nbuf from q and
  2080. * returns next mpdu from the queue
  2081. */
  2082. mpdu_nbuf = dp_tx_mon_get_next_mpdu(
  2083. xretry_ppdu, mpdu_nbuf);
  2084. } else {
  2085. ppdu_desc->mpdus[seq_no - start_seq] =
  2086. qdf_nbuf_copy_expand_fraglist(
  2087. mpdu_nbuf,
  2088. MAX_MONITOR_HEADER, 0);
  2089. mpdu_nbuf =
  2090. qdf_nbuf_queue_next(mpdu_nbuf);
  2091. }
  2092. }
  2093. }
  2094. if ((ppdu_desc->pending_retries == 0) && (ppdu_nbuf ==
  2095. qdf_nbuf_queue_first(&tx_tid->pending_ppdu_q))) {
  2096. qdf_nbuf_queue_remove(&tx_tid->pending_ppdu_q);
  2097. /* Deliver PPDU */
  2098. dp_send_data_to_stack(pdev, ppdu_desc);
  2099. qdf_nbuf_queue_free(&ppdu_desc->mpdu_q);
  2100. qdf_mem_free(ppdu_desc->mpdus);
  2101. ppdu_desc->mpdus = NULL;
  2102. qdf_nbuf_free(ppdu_nbuf);
  2103. ppdu_nbuf = qdf_nbuf_queue_first(
  2104. &tx_tid->pending_ppdu_q);
  2105. } else {
  2106. ppdu_nbuf = qdf_nbuf_queue_next(ppdu_nbuf);
  2107. }
  2108. }
  2109. qdf_nbuf_queue_free(&xretry_ppdu->mpdu_q);
  2110. }
  2111. #define MAX_PENDING_PPDUS 32
  2112. static void
  2113. dp_tx_mon_proc_pending_ppdus(struct dp_pdev *pdev, struct dp_tx_tid *tx_tid,
  2114. qdf_nbuf_t nbuf_ppdu_desc_list[], uint32_t
  2115. ppdu_desc_cnt, qdf_nbuf_queue_t *head_ppdu,
  2116. uint32_t peer_id)
  2117. {
  2118. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  2119. struct cdp_tx_completion_ppdu *cur_ppdu_desc = NULL;
  2120. qdf_nbuf_t pend_ppdu;
  2121. uint32_t ppdu_cnt;
  2122. uint32_t failed_seq;
  2123. uint32_t cur_index, cur_start_seq, cur_last_seq;
  2124. int i, k;
  2125. bool last_pend_ppdu = false;
  2126. qdf_nbuf_t tmp_nbuf;
  2127. pend_ppdu = qdf_nbuf_queue_first(&tx_tid->pending_ppdu_q);
  2128. if (!pend_ppdu) {
  2129. for (ppdu_cnt = 0; ppdu_cnt < ppdu_desc_cnt; ppdu_cnt++) {
  2130. if (!nbuf_ppdu_desc_list[ppdu_cnt])
  2131. continue;
  2132. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  2133. qdf_nbuf_data(
  2134. nbuf_ppdu_desc_list[ppdu_cnt]);
  2135. if (!ppdu_desc || (peer_id !=
  2136. ppdu_desc->user[0].peer_id) || (tx_tid->tid !=
  2137. ppdu_desc->user[0].tid))
  2138. continue;
  2139. if ((ppdu_desc->pending_retries == 0) &&
  2140. qdf_nbuf_is_queue_empty(&tx_tid->pending_ppdu_q) &&
  2141. qdf_nbuf_is_queue_empty(head_ppdu)) {
  2142. dp_send_data_to_stack(pdev, ppdu_desc);
  2143. qdf_nbuf_queue_free(&ppdu_desc->mpdu_q);
  2144. qdf_mem_free(ppdu_desc->mpdus);
  2145. ppdu_desc->mpdus = NULL;
  2146. tmp_nbuf = nbuf_ppdu_desc_list[ppdu_cnt];
  2147. nbuf_ppdu_desc_list[ppdu_cnt] = NULL;
  2148. qdf_nbuf_free(tmp_nbuf);
  2149. } else {
  2150. qdf_nbuf_queue_add(head_ppdu,
  2151. nbuf_ppdu_desc_list[ppdu_cnt]);
  2152. nbuf_ppdu_desc_list[ppdu_cnt] = NULL;
  2153. }
  2154. }
  2155. return;
  2156. }
  2157. while (pend_ppdu) {
  2158. qdf_nbuf_t mpdu_nbuf;
  2159. /* Find missing mpdus from current schedule list */
  2160. ppdu_cnt = 0;
  2161. while (!nbuf_ppdu_desc_list[ppdu_cnt]) {
  2162. ppdu_cnt++;
  2163. if (ppdu_cnt < ppdu_desc_cnt)
  2164. continue;
  2165. break;
  2166. }
  2167. if (ppdu_cnt == ppdu_desc_cnt)
  2168. break;
  2169. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(
  2170. pend_ppdu);
  2171. cur_ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(
  2172. nbuf_ppdu_desc_list[ppdu_cnt]);
  2173. if (pend_ppdu == qdf_nbuf_queue_last(
  2174. &tx_tid->pending_ppdu_q)) {
  2175. last_pend_ppdu = true;
  2176. qdf_nbuf_queue_add(head_ppdu,
  2177. nbuf_ppdu_desc_list[ppdu_cnt]);
  2178. nbuf_ppdu_desc_list[ppdu_cnt] = NULL;
  2179. }
  2180. cur_index = 0;
  2181. cur_start_seq = cur_ppdu_desc->user[0].start_seq;
  2182. cur_last_seq = cur_ppdu_desc->user[0].last_enq_seq;
  2183. if (qdf_unlikely(ppdu_desc->user[0].ba_size >
  2184. CDP_BA_256_BIT_MAP_SIZE_DWORDS *
  2185. SEQ_SEG_SZ_BITS(ppdu_desc->user[0].failed_bitmap))) {
  2186. qdf_assert_always(0);
  2187. return;
  2188. }
  2189. for (i = 0; (i < ppdu_desc->user[0].ba_size) && cur_ppdu_desc;
  2190. i++) {
  2191. if (!(i & (SEQ_SEG_SZ_BITS(
  2192. ppdu_desc->user[0].failed_bitmap) - 1))) {
  2193. k =
  2194. SEQ_SEG_INDEX(ppdu_desc->user[0].failed_bitmap,
  2195. i);
  2196. failed_seq =
  2197. ppdu_desc->user[0].failed_bitmap[k] ^
  2198. ppdu_desc->user[0].enq_bitmap[k];
  2199. }
  2200. /* Skip to next bitmap segment if there are no
  2201. * more holes in current segment
  2202. */
  2203. if (!failed_seq) {
  2204. i = ((k + 1) *
  2205. SEQ_SEG_SZ_BITS(ppdu_desc->user[0].failed_bitmap))
  2206. - 1;
  2207. continue;
  2208. }
  2209. if (!(SEQ_SEG_BIT(failed_seq, i)))
  2210. continue;
  2211. failed_seq ^= SEQ_SEG_MSK(failed_seq, i);
  2212. mpdu_nbuf = cur_ppdu_desc->mpdus[cur_index];
  2213. if (mpdu_nbuf) {
  2214. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  2215. QDF_TRACE_LEVEL_INFO,
  2216. "%s: fill seqno %d (%d) from swretries",
  2217. __func__,
  2218. ppdu_desc->user[0].start_seq + i,
  2219. ppdu_desc->ppdu_id);
  2220. ppdu_desc->mpdus[i] =
  2221. qdf_nbuf_copy_expand_fraglist(
  2222. mpdu_nbuf, MAX_MONITOR_HEADER, 0);
  2223. ppdu_desc->user[0].failed_bitmap[k] |=
  2224. SEQ_SEG_MSK(ppdu_desc->user[0].failed_bitmap[k],
  2225. i);
  2226. ppdu_desc->pending_retries--;
  2227. }
  2228. cur_index++;
  2229. if (cur_index >= cur_ppdu_desc->user[0].ba_size) {
  2230. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  2231. QDF_TRACE_LEVEL_INFO,
  2232. "%s: ba_size[%d] cur_index[%d]\n",
  2233. __func__,
  2234. cur_ppdu_desc->user[0].ba_size,
  2235. cur_index);
  2236. break;
  2237. }
  2238. /* Skip through empty slots in current PPDU */
  2239. while (!(SEQ_BIT(cur_ppdu_desc->user[0].enq_bitmap,
  2240. cur_index))) {
  2241. struct cdp_tx_completion_ppdu *next_ppdu = NULL;
  2242. cur_index++;
  2243. if (cur_index <= (cur_last_seq -
  2244. cur_start_seq))
  2245. continue;
  2246. cur_ppdu_desc = NULL;
  2247. /* Check if subsequent PPDUs in this schedule
  2248. * has higher sequence numbers enqueued
  2249. */
  2250. while (ppdu_cnt < (ppdu_desc_cnt - 1)) {
  2251. ppdu_cnt++;
  2252. if (!nbuf_ppdu_desc_list[ppdu_cnt])
  2253. continue;
  2254. next_ppdu =
  2255. (struct cdp_tx_completion_ppdu *)
  2256. qdf_nbuf_data(
  2257. nbuf_ppdu_desc_list[
  2258. ppdu_cnt]);
  2259. if (!next_ppdu || (peer_id !=
  2260. next_ppdu->user[0].peer_id))
  2261. continue;
  2262. if (last_pend_ppdu) {
  2263. qdf_nbuf_queue_add(head_ppdu,
  2264. nbuf_ppdu_desc_list[ppdu_cnt]);
  2265. nbuf_ppdu_desc_list[ppdu_cnt] =
  2266. NULL;
  2267. }
  2268. if (next_ppdu->user[0].last_enq_seq >
  2269. cur_last_seq) {
  2270. cur_ppdu_desc = next_ppdu;
  2271. break;
  2272. }
  2273. }
  2274. if (!cur_ppdu_desc)
  2275. break;
  2276. /* Start from seq. no following cur_last_seq
  2277. * since everything before is already populated
  2278. * from previous PPDU
  2279. */
  2280. cur_start_seq =
  2281. cur_ppdu_desc->user[0].start_seq;
  2282. cur_index = (cur_last_seq >= cur_start_seq) ?
  2283. cur_last_seq - cur_start_seq + 1 : 0;
  2284. cur_last_seq =
  2285. cur_ppdu_desc->user[0].last_enq_seq;
  2286. }
  2287. }
  2288. if ((pend_ppdu ==
  2289. qdf_nbuf_queue_first(&tx_tid->pending_ppdu_q)) &&
  2290. (ppdu_desc->pending_retries == 0)) {
  2291. qdf_nbuf_queue_remove(&tx_tid->pending_ppdu_q);
  2292. dp_send_data_to_stack(pdev, ppdu_desc);
  2293. qdf_nbuf_queue_free(&ppdu_desc->mpdu_q);
  2294. qdf_mem_free(ppdu_desc->mpdus);
  2295. ppdu_desc->mpdus = NULL;
  2296. qdf_nbuf_free(pend_ppdu);
  2297. pend_ppdu = qdf_nbuf_queue_first(
  2298. &tx_tid->pending_ppdu_q);
  2299. } else {
  2300. pend_ppdu = qdf_nbuf_queue_next(pend_ppdu);
  2301. }
  2302. }
  2303. }
  2304. static uint32_t
  2305. dp_send_mgmt_ctrl_to_stack(struct dp_pdev *pdev,
  2306. qdf_nbuf_t nbuf_ppdu_desc,
  2307. struct cdp_tx_indication_info *ptr_tx_cap_info,
  2308. qdf_nbuf_t mgmt_ctl_nbuf,
  2309. bool is_payload)
  2310. {
  2311. struct cdp_tx_completion_ppdu *ppdu_desc;
  2312. struct cdp_tx_indication_mpdu_info *mpdu_info;
  2313. struct ieee80211_frame *wh;
  2314. uint16_t duration_le, seq_le;
  2315. struct ieee80211_frame_min_one *wh_min;
  2316. uint16_t frame_ctrl_le;
  2317. uint8_t type, subtype;
  2318. mpdu_info = &ptr_tx_cap_info->mpdu_info;
  2319. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  2320. qdf_nbuf_data(nbuf_ppdu_desc);
  2321. if (ppdu_desc->mprot_type)
  2322. dp_send_dummy_rts_cts_frame(pdev, ppdu_desc);
  2323. type = (ppdu_desc->frame_ctrl &
  2324. IEEE80211_FC0_TYPE_MASK) >>
  2325. IEEE80211_FC0_TYPE_SHIFT;
  2326. subtype = (ppdu_desc->frame_ctrl &
  2327. IEEE80211_FC0_SUBTYPE_MASK) >>
  2328. IEEE80211_FC0_SUBTYPE_SHIFT;
  2329. if (is_payload) {
  2330. wh = (struct ieee80211_frame *)qdf_nbuf_data(mgmt_ctl_nbuf);
  2331. if (subtype != IEEE80211_FC0_SUBTYPE_BEACON) {
  2332. duration_le = qdf_cpu_to_le16(ppdu_desc->tx_duration);
  2333. wh->i_dur[1] = (duration_le & 0xFF00) >> 8;
  2334. wh->i_dur[0] = duration_le & 0xFF;
  2335. seq_le = qdf_cpu_to_le16(ppdu_desc->user[0].start_seq <<
  2336. IEEE80211_SEQ_SEQ_SHIFT);
  2337. wh->i_seq[1] = (seq_le & 0xFF00) >> 8;
  2338. wh->i_seq[0] = seq_le & 0xFF;
  2339. }
  2340. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  2341. QDF_TRACE_LEVEL_DEBUG,
  2342. "ctrl/mgmt frm(0x%08x): fc 0x%x 0x%x\n",
  2343. ptr_tx_cap_info->mpdu_info.ppdu_id,
  2344. wh->i_fc[1], wh->i_fc[0]);
  2345. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  2346. QDF_TRACE_LEVEL_DEBUG,
  2347. "desc->ppdu_id 0x%08x\n", ppdu_desc->ppdu_id);
  2348. /* append ext list */
  2349. qdf_nbuf_append_ext_list(ptr_tx_cap_info->mpdu_nbuf,
  2350. mgmt_ctl_nbuf,
  2351. qdf_nbuf_len(mgmt_ctl_nbuf));
  2352. } else {
  2353. wh_min = (struct ieee80211_frame_min_one *)
  2354. qdf_nbuf_data(ptr_tx_cap_info->mpdu_nbuf);
  2355. qdf_mem_zero(wh_min, MAX_DUMMY_FRM_BODY);
  2356. frame_ctrl_le = qdf_cpu_to_le16(ppdu_desc->frame_ctrl);
  2357. duration_le = qdf_cpu_to_le16(ppdu_desc->tx_duration);
  2358. wh_min->i_fc[1] = (frame_ctrl_le & 0xFF00) >> 8;
  2359. wh_min->i_fc[0] = (frame_ctrl_le & 0xFF);
  2360. wh_min->i_dur[1] = (duration_le & 0xFF00) >> 8;
  2361. wh_min->i_dur[0] = (duration_le & 0xFF);
  2362. qdf_mem_copy(wh_min->i_addr1, mpdu_info->mac_address,
  2363. QDF_MAC_ADDR_SIZE);
  2364. qdf_nbuf_set_pktlen(ptr_tx_cap_info->mpdu_nbuf,
  2365. sizeof(*wh_min));
  2366. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  2367. QDF_TRACE_LEVEL_DEBUG,
  2368. "frm(0x%08x): fc %x %x, dur 0x%x%x\n",
  2369. ptr_tx_cap_info->mpdu_info.ppdu_id,
  2370. wh_min->i_fc[1], wh_min->i_fc[0],
  2371. wh_min->i_dur[1], wh_min->i_dur[0]);
  2372. }
  2373. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  2374. ptr_tx_cap_info, HTT_INVALID_PEER,
  2375. WDI_NO_VAL, pdev->pdev_id);
  2376. if (ptr_tx_cap_info->mpdu_nbuf)
  2377. qdf_nbuf_free(ptr_tx_cap_info->mpdu_nbuf);
  2378. return 0;
  2379. }
  2380. static uint32_t
  2381. dp_update_tx_cap_info(struct dp_pdev *pdev,
  2382. qdf_nbuf_t nbuf_ppdu_desc,
  2383. void *tx_info, bool is_payload)
  2384. {
  2385. struct cdp_tx_completion_ppdu *ppdu_desc;
  2386. struct cdp_tx_indication_info *tx_capture_info =
  2387. (struct cdp_tx_indication_info *)tx_info;
  2388. struct cdp_tx_indication_mpdu_info *mpdu_info;
  2389. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  2390. qdf_nbuf_data(nbuf_ppdu_desc);
  2391. qdf_mem_set(tx_capture_info, sizeof(struct cdp_tx_indication_info), 0);
  2392. mpdu_info = &tx_capture_info->mpdu_info;
  2393. mpdu_info->channel = ppdu_desc->channel;
  2394. mpdu_info->frame_type = ppdu_desc->frame_type;
  2395. mpdu_info->ppdu_start_timestamp = ppdu_desc->ppdu_start_timestamp;
  2396. mpdu_info->ppdu_end_timestamp = ppdu_desc->ppdu_end_timestamp;
  2397. mpdu_info->tx_duration = ppdu_desc->tx_duration;
  2398. mpdu_info->seq_no = ppdu_desc->user[0].start_seq;
  2399. mpdu_info->num_msdu = ppdu_desc->num_msdu;
  2400. /* update cdp_tx_indication_mpdu_info */
  2401. dp_tx_update_user_mpdu_info(ppdu_desc->ppdu_id,
  2402. &tx_capture_info->mpdu_info,
  2403. &ppdu_desc->user[0]);
  2404. tx_capture_info->ppdu_desc = ppdu_desc;
  2405. tx_capture_info->mpdu_info.channel_num = pdev->operating_channel.num;
  2406. tx_capture_info->mpdu_info.ppdu_id = ppdu_desc->ppdu_id;
  2407. if (is_payload)
  2408. tx_capture_info->mpdu_nbuf = qdf_nbuf_alloc(pdev->soc->osdev,
  2409. MAX_MONITOR_HEADER,
  2410. MAX_MONITOR_HEADER,
  2411. 4, FALSE);
  2412. else
  2413. tx_capture_info->mpdu_nbuf = qdf_nbuf_alloc(pdev->soc->osdev,
  2414. MAX_MONITOR_HEADER +
  2415. MAX_DUMMY_FRM_BODY,
  2416. MAX_MONITOR_HEADER,
  2417. 4, FALSE);
  2418. return 0;
  2419. }
  2420. static uint32_t
  2421. dp_check_mgmt_ctrl_ppdu(struct dp_pdev *pdev,
  2422. qdf_nbuf_t nbuf_ppdu_desc)
  2423. {
  2424. struct cdp_tx_indication_info tx_capture_info;
  2425. qdf_nbuf_t mgmt_ctl_nbuf;
  2426. uint8_t type, subtype;
  2427. uint8_t fc_type, fc_subtype;
  2428. bool is_sgen_pkt;
  2429. struct cdp_tx_mgmt_comp_info *ptr_comp_info;
  2430. qdf_nbuf_queue_t *retries_q;
  2431. struct cdp_tx_completion_ppdu *ppdu_desc;
  2432. uint32_t ppdu_id;
  2433. size_t head_size;
  2434. uint32_t status = 1;
  2435. uint32_t tsf_delta;
  2436. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  2437. qdf_nbuf_data(nbuf_ppdu_desc);
  2438. /*
  2439. * only for host generated frame we do have
  2440. * timestamp and retries count.
  2441. */
  2442. head_size = sizeof(struct cdp_tx_mgmt_comp_info);
  2443. fc_type = (ppdu_desc->frame_ctrl &
  2444. IEEE80211_FC0_TYPE_MASK);
  2445. fc_subtype = (ppdu_desc->frame_ctrl &
  2446. IEEE80211_FC0_SUBTYPE_MASK);
  2447. type = (ppdu_desc->frame_ctrl &
  2448. IEEE80211_FC0_TYPE_MASK) >>
  2449. IEEE80211_FC0_TYPE_SHIFT;
  2450. subtype = (ppdu_desc->frame_ctrl &
  2451. IEEE80211_FC0_SUBTYPE_MASK) >>
  2452. IEEE80211_FC0_SUBTYPE_SHIFT;
  2453. if (ppdu_desc->htt_frame_type == HTT_STATS_FTYPE_SGEN_NDP) {
  2454. dp_update_frame_ctrl_from_frame_type(ppdu_desc);
  2455. type = 0;
  2456. subtype = 0;
  2457. }
  2458. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, NULL,
  2459. ppdu_desc->user[0].mac_addr)) {
  2460. qdf_nbuf_free(nbuf_ppdu_desc);
  2461. status = 0;
  2462. goto free_ppdu_desc;
  2463. }
  2464. switch (ppdu_desc->htt_frame_type) {
  2465. case HTT_STATS_FTYPE_TIDQ_DATA_SU:
  2466. case HTT_STATS_FTYPE_TIDQ_DATA_MU:
  2467. if ((fc_type == IEEE80211_FC0_TYPE_MGT) &&
  2468. (fc_subtype == IEEE80211_FC0_SUBTYPE_BEACON))
  2469. is_sgen_pkt = true;
  2470. else
  2471. is_sgen_pkt = false;
  2472. break;
  2473. default:
  2474. is_sgen_pkt = true;
  2475. break;
  2476. }
  2477. retries_q = &pdev->tx_capture.retries_ctl_mgmt_q[type][subtype];
  2478. get_mgmt_pkt_from_queue:
  2479. qdf_spin_lock_bh(
  2480. &pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  2481. mgmt_ctl_nbuf = qdf_nbuf_queue_remove(
  2482. &pdev->tx_capture.ctl_mgmt_q[type][subtype]);
  2483. qdf_spin_unlock_bh(&pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  2484. if (mgmt_ctl_nbuf) {
  2485. qdf_nbuf_t tmp_mgmt_ctl_nbuf;
  2486. uint32_t start_tsf;
  2487. ptr_comp_info = (struct cdp_tx_mgmt_comp_info *)
  2488. qdf_nbuf_data(mgmt_ctl_nbuf);
  2489. is_sgen_pkt = ptr_comp_info->is_sgen_pkt;
  2490. ppdu_id = ptr_comp_info->ppdu_id;
  2491. if (!is_sgen_pkt && ptr_comp_info->tx_tsf <
  2492. ppdu_desc->ppdu_start_timestamp) {
  2493. /*
  2494. * free the older mgmt buffer from
  2495. * the queue and get new mgmt buffer
  2496. */
  2497. qdf_nbuf_free(mgmt_ctl_nbuf);
  2498. goto get_mgmt_pkt_from_queue;
  2499. }
  2500. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  2501. QDF_TRACE_LEVEL_INFO_HIGH,
  2502. "ppdu_id [%d 0x%x] type_subtype[%d %d] is_sgen[%d] h_sz[%d]",
  2503. ppdu_id, ppdu_id, type, subtype,
  2504. is_sgen_pkt, head_size);
  2505. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_TX_CAPTURE,
  2506. QDF_TRACE_LEVEL_INFO_HIGH,
  2507. qdf_nbuf_data(mgmt_ctl_nbuf), 32);
  2508. /*
  2509. * for sgen frame we won't have, retries count
  2510. * and 64 bits tsf in the head.
  2511. */
  2512. if (ppdu_id != ppdu_desc->ppdu_id) {
  2513. if (is_sgen_pkt) {
  2514. start_tsf = (ppdu_desc->ppdu_start_timestamp &
  2515. LOWER_32_MASK);
  2516. if (start_tsf > ptr_comp_info->tx_tsf)
  2517. tsf_delta = start_tsf - ptr_comp_info->tx_tsf;
  2518. else
  2519. tsf_delta = LOWER_32_MASK - ptr_comp_info->tx_tsf + start_tsf;
  2520. if (tsf_delta > MAX_MGMT_ENQ_DELAY) {
  2521. /*
  2522. * free the older mgmt buffer from
  2523. * the queue and get new mgmt buffer
  2524. */
  2525. qdf_nbuf_free(mgmt_ctl_nbuf);
  2526. goto get_mgmt_pkt_from_queue;
  2527. }
  2528. }
  2529. /*
  2530. * only for the packets send over the air are handled
  2531. * packets drop by firmware is not handled in this
  2532. * feature
  2533. */
  2534. if (ppdu_desc->user[0].completion_status ==
  2535. HTT_PPDU_STATS_USER_STATUS_FILTERED) {
  2536. qdf_nbuf_free(nbuf_ppdu_desc);
  2537. status = 0;
  2538. goto insert_mgmt_buf_to_queue;
  2539. }
  2540. /*
  2541. * add the ppdu_desc into retry queue
  2542. */
  2543. qdf_nbuf_queue_add(retries_q, nbuf_ppdu_desc);
  2544. status = 0;
  2545. insert_mgmt_buf_to_queue:
  2546. /*
  2547. * insert the mgmt_ctl buffer back to
  2548. * the queue
  2549. */
  2550. qdf_spin_lock_bh(
  2551. &pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  2552. qdf_nbuf_queue_insert_head(
  2553. &pdev->tx_capture.ctl_mgmt_q[type][subtype],
  2554. mgmt_ctl_nbuf);
  2555. qdf_spin_unlock_bh(
  2556. &pdev->tx_capture.ctl_mgmt_lock[type][subtype]);
  2557. } else {
  2558. qdf_nbuf_t nbuf_retry_ppdu;
  2559. struct cdp_tx_completion_ppdu *tmp_ppdu_desc;
  2560. uint16_t frame_ctrl_le;
  2561. struct ieee80211_frame *wh;
  2562. /*
  2563. * only for the packets send over the air are handled
  2564. * packets drop by firmware is not handled in this
  2565. * feature
  2566. */
  2567. if (ppdu_desc->user[0].completion_status ==
  2568. HTT_PPDU_STATS_USER_STATUS_FILTERED) {
  2569. qdf_nbuf_free(nbuf_ppdu_desc);
  2570. qdf_nbuf_free(mgmt_ctl_nbuf);
  2571. status = 0;
  2572. goto free_ppdu_desc;
  2573. }
  2574. while (!!qdf_nbuf_queue_len(retries_q)) {
  2575. /*
  2576. * send retried packet stored
  2577. * in queue
  2578. */
  2579. nbuf_retry_ppdu =
  2580. qdf_nbuf_queue_remove(retries_q);
  2581. tmp_ppdu_desc =
  2582. (struct cdp_tx_completion_ppdu *)
  2583. qdf_nbuf_data(nbuf_retry_ppdu);
  2584. tmp_mgmt_ctl_nbuf =
  2585. qdf_nbuf_copy_expand(mgmt_ctl_nbuf,
  2586. 0, 0);
  2587. dp_update_tx_cap_info(pdev, nbuf_retry_ppdu,
  2588. &tx_capture_info, true);
  2589. if (!tx_capture_info.mpdu_nbuf) {
  2590. qdf_nbuf_free(nbuf_retry_ppdu);
  2591. qdf_nbuf_free(tmp_mgmt_ctl_nbuf);
  2592. continue;
  2593. }
  2594. /* pull head based on sgen pkt or mgmt pkt */
  2595. qdf_nbuf_pull_head(tmp_mgmt_ctl_nbuf,
  2596. head_size);
  2597. /*
  2598. * frame control from ppdu_desc has
  2599. * retry flag set
  2600. */
  2601. frame_ctrl_le =
  2602. qdf_cpu_to_le16(tmp_ppdu_desc->frame_ctrl);
  2603. wh = (struct ieee80211_frame *)
  2604. (qdf_nbuf_data(tmp_mgmt_ctl_nbuf));
  2605. wh->i_fc[1] = (frame_ctrl_le & 0xFF00) >> 8;
  2606. wh->i_fc[0] = (frame_ctrl_le & 0xFF);
  2607. tx_capture_info.ppdu_desc = tmp_ppdu_desc;
  2608. /*
  2609. * send MPDU to osif layer
  2610. */
  2611. dp_send_mgmt_ctrl_to_stack(pdev,
  2612. nbuf_retry_ppdu,
  2613. &tx_capture_info,
  2614. tmp_mgmt_ctl_nbuf,
  2615. true);
  2616. /* free retried queue nbuf ppdu_desc */
  2617. qdf_nbuf_free(nbuf_retry_ppdu);
  2618. }
  2619. dp_update_tx_cap_info(pdev, nbuf_ppdu_desc,
  2620. &tx_capture_info, true);
  2621. if (!tx_capture_info.mpdu_nbuf) {
  2622. qdf_nbuf_free(mgmt_ctl_nbuf);
  2623. goto free_ppdu_desc;
  2624. }
  2625. tx_capture_info.mpdu_info.ppdu_id =
  2626. *(uint32_t *)qdf_nbuf_data(mgmt_ctl_nbuf);
  2627. /* pull head based on sgen pkt or mgmt pkt */
  2628. qdf_nbuf_pull_head(mgmt_ctl_nbuf, head_size);
  2629. /* frame control from ppdu_desc has retry flag set */
  2630. frame_ctrl_le = qdf_cpu_to_le16(ppdu_desc->frame_ctrl);
  2631. wh = (struct ieee80211_frame *)
  2632. (qdf_nbuf_data(mgmt_ctl_nbuf));
  2633. wh->i_fc[1] = (frame_ctrl_le & 0xFF00) >> 8;
  2634. wh->i_fc[0] = (frame_ctrl_le & 0xFF);
  2635. tx_capture_info.ppdu_desc = ppdu_desc;
  2636. /*
  2637. * send MPDU to osif layer
  2638. */
  2639. dp_send_mgmt_ctrl_to_stack(pdev, nbuf_ppdu_desc,
  2640. &tx_capture_info,
  2641. mgmt_ctl_nbuf, true);
  2642. }
  2643. } else if (!is_sgen_pkt) {
  2644. /*
  2645. * only for the packets send over the air are handled
  2646. * packets drop by firmware is not handled in this
  2647. * feature
  2648. */
  2649. if (ppdu_desc->user[0].completion_status ==
  2650. HTT_PPDU_STATS_USER_STATUS_FILTERED) {
  2651. qdf_nbuf_free(nbuf_ppdu_desc);
  2652. status = 0;
  2653. goto free_ppdu_desc;
  2654. }
  2655. /*
  2656. * add the ppdu_desc into retry queue
  2657. */
  2658. qdf_nbuf_queue_add(retries_q, nbuf_ppdu_desc);
  2659. status = 0;
  2660. } else if ((ppdu_desc->frame_ctrl &
  2661. IEEE80211_FC0_TYPE_MASK) ==
  2662. IEEE80211_FC0_TYPE_CTL) {
  2663. /*
  2664. * only for the packets send over the air are handled
  2665. * packets drop by firmware is not handled in this
  2666. * feature
  2667. */
  2668. if (ppdu_desc->user[0].completion_status ==
  2669. HTT_PPDU_STATS_USER_STATUS_FILTERED) {
  2670. qdf_nbuf_free(nbuf_ppdu_desc);
  2671. status = 0;
  2672. goto free_ppdu_desc;
  2673. }
  2674. dp_update_tx_cap_info(pdev, nbuf_ppdu_desc,
  2675. &tx_capture_info, false);
  2676. if (!tx_capture_info.mpdu_nbuf)
  2677. goto free_ppdu_desc;
  2678. /*
  2679. * send MPDU to osif layer
  2680. */
  2681. dp_send_mgmt_ctrl_to_stack(pdev, nbuf_ppdu_desc,
  2682. &tx_capture_info, NULL, false);
  2683. }
  2684. free_ppdu_desc:
  2685. return status;
  2686. }
  2687. /**
  2688. * dp_peer_tx_cap_tid_queue_flush_tlv(): Function to dequeue peer queue
  2689. * @pdev: DP pdev handle
  2690. * @peer; DP peer handle
  2691. * @ppdu_desc: ppdu_desc
  2692. *
  2693. * return: void
  2694. */
  2695. static void
  2696. dp_peer_tx_cap_tid_queue_flush_tlv(struct dp_pdev *pdev,
  2697. struct dp_peer *peer,
  2698. struct cdp_tx_completion_ppdu *ppdu_desc)
  2699. {
  2700. int tid;
  2701. struct dp_tx_tid *tx_tid;
  2702. qdf_nbuf_queue_t head_xretries;
  2703. qdf_nbuf_queue_t head_msdu;
  2704. uint32_t qlen = 0;
  2705. uint32_t qlen_curr = 0;
  2706. tid = ppdu_desc->user[0].tid;
  2707. tx_tid = &peer->tx_capture.tx_tid[tid];
  2708. qdf_nbuf_queue_init(&head_msdu);
  2709. qdf_nbuf_queue_init(&head_xretries);
  2710. qlen = qdf_nbuf_queue_len(&tx_tid->msdu_comp_q);
  2711. dp_tx_msdu_dequeue(peer, INVALID_PPDU_ID,
  2712. tid, ppdu_desc->num_msdu,
  2713. &head_msdu,
  2714. &head_xretries,
  2715. 0, MAX_END_TSF);
  2716. if (!qdf_nbuf_is_queue_empty(&head_xretries)) {
  2717. struct cdp_tx_completion_ppdu *xretry_ppdu =
  2718. &tx_tid->xretry_ppdu;
  2719. xretry_ppdu->ppdu_id = peer->tx_capture.tx_wifi_ppdu_id;
  2720. /* Restitch MPDUs from xretry MSDUs */
  2721. dp_tx_mon_restitch_mpdu(pdev, peer,
  2722. xretry_ppdu,
  2723. &head_xretries,
  2724. &xretry_ppdu->mpdu_q);
  2725. }
  2726. qdf_nbuf_queue_free(&head_msdu);
  2727. qdf_nbuf_queue_free(&head_xretries);
  2728. qlen_curr = qdf_nbuf_queue_len(&tx_tid->msdu_comp_q);
  2729. dp_tx_mon_proc_xretries(pdev, peer, tid);
  2730. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  2731. QDF_TRACE_LEVEL_INFO_MED,
  2732. "peer_id [%d 0x%x] tid[%d] qlen[%d -> %d]",
  2733. ppdu_desc->user[0].peer_id, peer, tid, qlen, qlen_curr);
  2734. }
  2735. /**
  2736. * dp_tx_ppdu_stats_flush(): Function to flush pending retried ppdu desc
  2737. * @pdev: DP pdev handle
  2738. * @nbuf: ppdu_desc
  2739. *
  2740. * return: void
  2741. */
  2742. static void
  2743. dp_tx_ppdu_stats_flush(struct dp_pdev *pdev,
  2744. struct cdp_tx_completion_ppdu *ppdu_desc)
  2745. {
  2746. struct dp_peer *peer;
  2747. peer = dp_tx_cap_peer_find_by_id(pdev->soc,
  2748. ppdu_desc->user[0].peer_id);
  2749. if (!peer)
  2750. return;
  2751. dp_peer_tx_cap_tid_queue_flush_tlv(pdev, peer, ppdu_desc);
  2752. dp_tx_cap_peer_unref_del(peer);
  2753. return;
  2754. }
  2755. static void dp_ppdu_queue_free(struct cdp_tx_completion_ppdu *ppdu_desc)
  2756. {
  2757. int i;
  2758. qdf_nbuf_t mpdu_nbuf = NULL;
  2759. for (i = 0; i < ppdu_desc->user[0].ba_size; i++) {
  2760. mpdu_nbuf = ppdu_desc->mpdus[i];
  2761. if (mpdu_nbuf)
  2762. qdf_nbuf_free(mpdu_nbuf);
  2763. }
  2764. qdf_nbuf_queue_free(&ppdu_desc->mpdu_q);
  2765. qdf_mem_free(ppdu_desc->mpdus);
  2766. ppdu_desc->mpdus = NULL;
  2767. return;
  2768. }
  2769. /**
  2770. * dp_check_ppdu_and_deliver(): Check PPDUs for any holes and deliver
  2771. * to upper layer if complete
  2772. * @pdev: DP pdev handle
  2773. * @nbuf_ppdu_desc_list: ppdu_desc_list per sched cmd id
  2774. * @ppdu_desc_cnt: number of ppdu_desc_cnt
  2775. *
  2776. * return: status
  2777. */
  2778. static void
  2779. dp_check_ppdu_and_deliver(struct dp_pdev *pdev,
  2780. qdf_nbuf_t nbuf_ppdu_desc_list[],
  2781. uint32_t ppdu_desc_cnt)
  2782. {
  2783. uint32_t ppdu_id;
  2784. uint32_t desc_cnt;
  2785. qdf_nbuf_t tmp_nbuf;
  2786. struct dp_tx_tid *tx_tid = NULL;
  2787. int i;
  2788. for (desc_cnt = 0; desc_cnt < ppdu_desc_cnt; desc_cnt++) {
  2789. struct cdp_tx_completion_ppdu *ppdu_desc;
  2790. uint32_t num_mpdu;
  2791. uint16_t start_seq, seq_no = 0;
  2792. int i;
  2793. qdf_nbuf_t mpdu_nbuf;
  2794. struct dp_peer *peer;
  2795. uint8_t type;
  2796. uint32_t mpdus_tried;
  2797. if (!nbuf_ppdu_desc_list[desc_cnt])
  2798. continue;
  2799. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  2800. qdf_nbuf_data(nbuf_ppdu_desc_list[desc_cnt]);
  2801. ppdu_id = ppdu_desc->ppdu_id;
  2802. type = (ppdu_desc->frame_ctrl & IEEE80211_FC0_TYPE_MASK) >>
  2803. IEEE80211_FC0_TYPE_SHIFT;
  2804. if (ppdu_desc->is_flush) {
  2805. dp_tx_ppdu_stats_flush(pdev, ppdu_desc);
  2806. tmp_nbuf = nbuf_ppdu_desc_list[desc_cnt];
  2807. nbuf_ppdu_desc_list[desc_cnt] = NULL;
  2808. qdf_nbuf_free(tmp_nbuf);
  2809. continue;
  2810. }
  2811. if ((ppdu_desc->frame_type == CDP_PPDU_FTYPE_CTRL) ||
  2812. (ppdu_desc->htt_frame_type ==
  2813. HTT_STATS_FTYPE_SGEN_QOS_NULL) ||
  2814. (type != FRAME_CTRL_TYPE_DATA)) {
  2815. qdf_nbuf_t nbuf_ppdu = nbuf_ppdu_desc_list[desc_cnt];
  2816. if (dp_check_mgmt_ctrl_ppdu(pdev, nbuf_ppdu)) {
  2817. tmp_nbuf = nbuf_ppdu_desc_list[desc_cnt];
  2818. nbuf_ppdu_desc_list[desc_cnt] = NULL;
  2819. qdf_nbuf_free(tmp_nbuf);
  2820. continue;
  2821. }
  2822. nbuf_ppdu_desc_list[desc_cnt] = NULL;
  2823. continue;
  2824. }
  2825. peer = dp_tx_cap_peer_find_by_id(pdev->soc,
  2826. ppdu_desc->user[0].peer_id);
  2827. if (!peer) {
  2828. tmp_nbuf = nbuf_ppdu_desc_list[desc_cnt];
  2829. nbuf_ppdu_desc_list[desc_cnt] = NULL;
  2830. qdf_nbuf_queue_free(&ppdu_desc->mpdu_q);
  2831. qdf_nbuf_free(tmp_nbuf);
  2832. continue;
  2833. }
  2834. tx_tid = &peer->tx_capture.tx_tid[ppdu_desc->user[0].tid];
  2835. ppdu_id = ppdu_desc->ppdu_id;
  2836. /* find mpdu tried is same as success mpdu */
  2837. num_mpdu = ppdu_desc->user[0].mpdu_success;
  2838. /* ba_size is updated in BA bitmap TLVs, which are not received
  2839. * in case of non-QoS TID.
  2840. */
  2841. if (qdf_unlikely(ppdu_desc->user[0].tid == DP_NON_QOS_TID)) {
  2842. ppdu_desc->user[0].ba_size = 1;
  2843. ppdu_desc->user[0].last_enq_seq =
  2844. ppdu_desc->user[0].start_seq;
  2845. }
  2846. if (ppdu_desc->user[0].ba_size == 0)
  2847. ppdu_desc->user[0].ba_size = 1;
  2848. /* find list of missing sequence */
  2849. ppdu_desc->mpdus = qdf_mem_malloc(sizeof(qdf_nbuf_t) *
  2850. ppdu_desc->user[0].ba_size);
  2851. if (ppdu_desc->frame_type == CDP_PPDU_FTYPE_BAR)
  2852. dp_send_dummy_mpdu_info_to_stack(pdev,
  2853. ppdu_desc);
  2854. if (qdf_unlikely(!ppdu_desc->mpdus)) {
  2855. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  2856. QDF_TRACE_LEVEL_FATAL,
  2857. "%s: ppdu_desc->mpdus allocation failed",
  2858. __func__);
  2859. tmp_nbuf = nbuf_ppdu_desc_list[desc_cnt];
  2860. nbuf_ppdu_desc_list[desc_cnt] = NULL;
  2861. qdf_nbuf_queue_free(&ppdu_desc->mpdu_q);
  2862. qdf_nbuf_free(tmp_nbuf);
  2863. dp_tx_cap_peer_unref_del(peer);
  2864. continue;
  2865. }
  2866. if (qdf_unlikely(ppdu_desc->user[0].ba_size >
  2867. CDP_BA_256_BIT_MAP_SIZE_DWORDS *
  2868. SEQ_SEG_SZ_BITS(ppdu_desc->user[0].failed_bitmap))) {
  2869. dp_tx_cap_peer_unref_del(peer);
  2870. qdf_assert_always(0);
  2871. return;
  2872. }
  2873. /* Fill seq holes within current schedule list */
  2874. start_seq = ppdu_desc->user[0].start_seq;
  2875. mpdus_tried = ppdu_desc->user[0].mpdu_tried_mcast +
  2876. ppdu_desc->user[0].mpdu_tried_ucast;
  2877. for (i = 0; (i < ppdu_desc->user[0].ba_size) && mpdus_tried;
  2878. i++) {
  2879. if (qdf_likely(ppdu_desc->user[0].tid !=
  2880. DP_NON_QOS_TID) &&
  2881. !(SEQ_BIT(ppdu_desc->user[0].enq_bitmap, i)))
  2882. continue;
  2883. mpdus_tried--;
  2884. /* missed seq number */
  2885. seq_no = start_seq + i;
  2886. /* Fill failed MPDUs in AMPDU if they're available in
  2887. * subsequent PPDUs in current burst schedule. This
  2888. * is not applicable for non-QoS TIDs (no AMPDUs)
  2889. */
  2890. if (qdf_likely(ppdu_desc->user[0].tid !=
  2891. DP_NON_QOS_TID) &&
  2892. !(SEQ_BIT(ppdu_desc->user[0].failed_bitmap, i))) {
  2893. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  2894. QDF_TRACE_LEVEL_DEBUG,
  2895. "%s:find seq %d in next ppdu %d",
  2896. __func__, seq_no,
  2897. ppdu_desc_cnt);
  2898. mpdu_nbuf = get_mpdu_clone_from_next_ppdu(
  2899. nbuf_ppdu_desc_list +
  2900. desc_cnt,
  2901. ppdu_desc_cnt -
  2902. desc_cnt, seq_no,
  2903. ppdu_desc->user[0].peer_id,
  2904. ppdu_id);
  2905. /* check mpdu_nbuf NULL */
  2906. if (!mpdu_nbuf) {
  2907. ppdu_desc->pending_retries++;
  2908. continue;
  2909. }
  2910. ppdu_desc->mpdus[seq_no - start_seq] =
  2911. mpdu_nbuf;
  2912. SEQ_SEG(ppdu_desc->user[0].failed_bitmap, i) |=
  2913. SEQ_SEG_MSK(ppdu_desc->user[0].failed_bitmap[0],
  2914. i);
  2915. } else {
  2916. /* any error case we need to handle */
  2917. mpdu_nbuf = qdf_nbuf_queue_remove(
  2918. &ppdu_desc->mpdu_q);
  2919. /* check mpdu_nbuf NULL */
  2920. if (!mpdu_nbuf)
  2921. continue;
  2922. ppdu_desc->mpdus[seq_no - start_seq] =
  2923. mpdu_nbuf;
  2924. }
  2925. }
  2926. /* It is possible that enq_bitmap received has more bits than
  2927. * actual mpdus tried if HW was unable to send all MPDUs, and
  2928. * last_enq_seq and ba_size should be adjusted in that case
  2929. */
  2930. if (i < ppdu_desc->user[0].ba_size) {
  2931. ppdu_desc->user[0].last_enq_seq = seq_no;
  2932. ppdu_desc->user[0].ba_size = seq_no - start_seq + 1;
  2933. }
  2934. dp_tx_cap_peer_unref_del(peer);
  2935. if ((ppdu_desc->pending_retries == 0) &&
  2936. qdf_nbuf_is_queue_empty(&tx_tid->pending_ppdu_q)) {
  2937. dp_send_data_to_stack(pdev, ppdu_desc);
  2938. dp_ppdu_queue_free(ppdu_desc);
  2939. tmp_nbuf = nbuf_ppdu_desc_list[desc_cnt];
  2940. nbuf_ppdu_desc_list[desc_cnt] = NULL;
  2941. qdf_nbuf_free(tmp_nbuf);
  2942. }
  2943. }
  2944. for (i = 0; i < ppdu_desc_cnt; i++) {
  2945. uint32_t pending_ppdus;
  2946. struct cdp_tx_completion_ppdu *cur_ppdu_desc;
  2947. struct dp_peer *peer;
  2948. qdf_nbuf_queue_t head_ppdu;
  2949. uint16_t peer_id;
  2950. if (!nbuf_ppdu_desc_list[i])
  2951. continue;
  2952. cur_ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(
  2953. nbuf_ppdu_desc_list[i]);
  2954. if (!cur_ppdu_desc)
  2955. continue;
  2956. peer_id = cur_ppdu_desc->user[0].peer_id;
  2957. peer = dp_tx_cap_peer_find_by_id(pdev->soc, peer_id);
  2958. if (!peer) {
  2959. tmp_nbuf = nbuf_ppdu_desc_list[i];
  2960. nbuf_ppdu_desc_list[i] = NULL;
  2961. dp_ppdu_queue_free(cur_ppdu_desc);
  2962. qdf_nbuf_free(tmp_nbuf);
  2963. continue;
  2964. }
  2965. tx_tid = &peer->tx_capture.tx_tid[cur_ppdu_desc->user[0].tid];
  2966. qdf_nbuf_queue_init(&head_ppdu);
  2967. dp_tx_mon_proc_pending_ppdus(pdev, tx_tid,
  2968. nbuf_ppdu_desc_list + i,
  2969. ppdu_desc_cnt - i, &head_ppdu,
  2970. peer_id);
  2971. if (qdf_nbuf_is_queue_empty(&tx_tid->pending_ppdu_q)) {
  2972. while ((tmp_nbuf = qdf_nbuf_queue_first(&head_ppdu))) {
  2973. cur_ppdu_desc =
  2974. (struct cdp_tx_completion_ppdu *)
  2975. qdf_nbuf_data(tmp_nbuf);
  2976. if (cur_ppdu_desc->pending_retries)
  2977. break;
  2978. dp_send_data_to_stack(pdev, cur_ppdu_desc);
  2979. dp_ppdu_queue_free(cur_ppdu_desc);
  2980. qdf_nbuf_queue_remove(&head_ppdu);
  2981. qdf_nbuf_free(tmp_nbuf);
  2982. }
  2983. }
  2984. qdf_nbuf_queue_append(&tx_tid->pending_ppdu_q, &head_ppdu);
  2985. dp_tx_mon_proc_xretries(pdev, peer, tx_tid->tid);
  2986. dp_tx_cap_peer_unref_del(peer);
  2987. pending_ppdus = qdf_nbuf_queue_len(&tx_tid->pending_ppdu_q);
  2988. if (pending_ppdus > MAX_PENDING_PPDUS) {
  2989. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  2990. QDF_TRACE_LEVEL_FATAL,
  2991. "pending ppdus (%d, %d) : %d\n",
  2992. cur_ppdu_desc->user[0].peer_id,
  2993. tx_tid->tid, pending_ppdus);
  2994. }
  2995. }
  2996. }
  2997. /**
  2998. * dp_tx_ppdu_stats_process - Deferred PPDU stats handler
  2999. * @context: Opaque work context (PDEV)
  3000. *
  3001. * Return: none
  3002. */
  3003. void dp_tx_ppdu_stats_process(void *context)
  3004. {
  3005. uint32_t curr_sched_cmdid;
  3006. uint32_t last_ppdu_id;
  3007. uint32_t ppdu_cnt;
  3008. uint32_t ppdu_desc_cnt = 0;
  3009. struct dp_pdev *pdev = (struct dp_pdev *)context;
  3010. struct ppdu_info *ppdu_info, *tmp_ppdu_info = NULL;
  3011. uint32_t now_ms = qdf_system_ticks_to_msecs(qdf_system_ticks());
  3012. struct ppdu_info *sched_ppdu_info = NULL;
  3013. STAILQ_HEAD(, ppdu_info) sched_ppdu_queue;
  3014. struct ppdu_info *sched_ppdu_list_last_ptr;
  3015. qdf_nbuf_t *nbuf_ppdu_desc_list;
  3016. qdf_nbuf_t tmp_nbuf;
  3017. struct dp_pdev_tx_capture *ptr_tx_cap = &pdev->tx_capture;
  3018. qdf_nbuf_queue_t head_xretries;
  3019. STAILQ_INIT(&sched_ppdu_queue);
  3020. /* Move the PPDU entries to defer list */
  3021. qdf_spin_lock_bh(&ptr_tx_cap->ppdu_stats_lock);
  3022. STAILQ_CONCAT(&ptr_tx_cap->ppdu_stats_defer_queue,
  3023. &ptr_tx_cap->ppdu_stats_queue);
  3024. ptr_tx_cap->ppdu_stats_defer_queue_depth +=
  3025. ptr_tx_cap->ppdu_stats_queue_depth;
  3026. ptr_tx_cap->ppdu_stats_queue_depth = 0;
  3027. qdf_spin_unlock_bh(&ptr_tx_cap->ppdu_stats_lock);
  3028. while (!STAILQ_EMPTY(&ptr_tx_cap->ppdu_stats_defer_queue)) {
  3029. ppdu_info =
  3030. STAILQ_FIRST(&ptr_tx_cap->ppdu_stats_defer_queue);
  3031. curr_sched_cmdid = ppdu_info->sched_cmdid;
  3032. ppdu_cnt = 0;
  3033. STAILQ_FOREACH_SAFE(ppdu_info,
  3034. &ptr_tx_cap->ppdu_stats_defer_queue,
  3035. ppdu_info_queue_elem, tmp_ppdu_info) {
  3036. if (curr_sched_cmdid != ppdu_info->sched_cmdid)
  3037. break;
  3038. sched_ppdu_list_last_ptr = ppdu_info;
  3039. ppdu_cnt++;
  3040. }
  3041. if (ppdu_info && (curr_sched_cmdid == ppdu_info->sched_cmdid) &&
  3042. ptr_tx_cap->ppdu_stats_next_sched < now_ms)
  3043. break;
  3044. last_ppdu_id = sched_ppdu_list_last_ptr->ppdu_id;
  3045. STAILQ_FIRST(&sched_ppdu_queue) =
  3046. STAILQ_FIRST(&ptr_tx_cap->ppdu_stats_defer_queue);
  3047. STAILQ_REMOVE_HEAD_UNTIL(&ptr_tx_cap->ppdu_stats_defer_queue,
  3048. sched_ppdu_list_last_ptr,
  3049. ppdu_info_queue_elem);
  3050. STAILQ_NEXT(sched_ppdu_list_last_ptr,
  3051. ppdu_info_queue_elem) = NULL;
  3052. ptr_tx_cap->ppdu_stats_defer_queue_depth -= ppdu_cnt;
  3053. nbuf_ppdu_desc_list =
  3054. (qdf_nbuf_t *) qdf_mem_malloc(sizeof(qdf_nbuf_t) *
  3055. ppdu_cnt);
  3056. /*
  3057. * if there is no memory allocated we need to free sched ppdu
  3058. * list, no ppdu stats will be updated.
  3059. */
  3060. if (!nbuf_ppdu_desc_list) {
  3061. STAILQ_FOREACH_SAFE(sched_ppdu_info,
  3062. &sched_ppdu_queue,
  3063. ppdu_info_queue_elem,
  3064. tmp_ppdu_info) {
  3065. ppdu_info = sched_ppdu_info;
  3066. tmp_nbuf = ppdu_info->nbuf;
  3067. qdf_mem_free(ppdu_info);
  3068. qdf_nbuf_free(tmp_nbuf);
  3069. }
  3070. continue;
  3071. }
  3072. qdf_spin_lock(&ptr_tx_cap->config_lock);
  3073. ppdu_desc_cnt = 0;
  3074. STAILQ_FOREACH_SAFE(sched_ppdu_info,
  3075. &sched_ppdu_queue,
  3076. ppdu_info_queue_elem, tmp_ppdu_info) {
  3077. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  3078. struct dp_peer *peer = NULL;
  3079. qdf_nbuf_t nbuf;
  3080. uint32_t retries = 0;
  3081. uint32_t ret = 0;
  3082. qdf_nbuf_queue_t head_msdu;
  3083. uint32_t start_tsf = 0;
  3084. uint32_t end_tsf = 0;
  3085. uint16_t tid = 0;
  3086. uint32_t num_msdu = 0;
  3087. uint32_t qlen = 0;
  3088. uint16_t peer_id;
  3089. uint8_t type, subtype;
  3090. qdf_nbuf_queue_init(&head_msdu);
  3091. qdf_nbuf_queue_init(&head_xretries);
  3092. ppdu_info = sched_ppdu_info;
  3093. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3094. qdf_nbuf_data(ppdu_info->nbuf);
  3095. pdev->tx_ppdu_proc++;
  3096. dp_ppdu_desc_user_stats_update(pdev, ppdu_info);
  3097. /*
  3098. * While processing/corelating Tx buffers, we should
  3099. * hold the entire PPDU list for the give sched_cmdid
  3100. * instead of freeing below.
  3101. */
  3102. nbuf = ppdu_info->nbuf;
  3103. qdf_mem_free(ppdu_info);
  3104. qdf_assert_always(nbuf);
  3105. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3106. qdf_nbuf_data(nbuf);
  3107. type = (ppdu_desc->frame_ctrl &
  3108. IEEE80211_FC0_TYPE_MASK);
  3109. subtype = (ppdu_desc->frame_ctrl &
  3110. IEEE80211_FC0_SUBTYPE_MASK);
  3111. if ((type == IEEE80211_FC0_TYPE_DATA) &&
  3112. (subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL) &&
  3113. (ppdu_desc->htt_frame_type ==
  3114. HTT_STATS_FTYPE_TIDQ_DATA_SU)) {
  3115. ppdu_desc->htt_frame_type =
  3116. HTT_STATS_FTYPE_SGEN_QOS_NULL;
  3117. }
  3118. /* send WDI event */
  3119. if (pdev->tx_capture_enabled ==
  3120. CDP_TX_ENH_CAPTURE_DISABLED) {
  3121. if (!pdev->tx_capture.tx_cap_mode_flag)
  3122. dp_enh_tx_capture_disable(pdev);
  3123. /**
  3124. * Deliver PPDU stats only for valid (acked)
  3125. * data frames if sniffer mode is not enabled.
  3126. * If sniffer mode is enabled,
  3127. * PPDU stats for all frames including
  3128. * mgmt/control frames should be delivered
  3129. * to upper layer
  3130. */
  3131. if (pdev->tx_sniffer_enable ||
  3132. pdev->mcopy_mode) {
  3133. dp_wdi_event_handler(
  3134. WDI_EVENT_TX_PPDU_DESC,
  3135. pdev->soc,
  3136. nbuf,
  3137. HTT_INVALID_PEER,
  3138. WDI_NO_VAL,
  3139. pdev->pdev_id);
  3140. } else {
  3141. if (ppdu_desc->num_mpdu != 0 &&
  3142. ppdu_desc->num_users != 0 &&
  3143. (ppdu_desc->frame_ctrl &
  3144. HTT_FRAMECTRL_DATATYPE)) {
  3145. dp_wdi_event_handler(
  3146. WDI_EVENT_TX_PPDU_DESC,
  3147. pdev->soc,
  3148. nbuf,
  3149. HTT_INVALID_PEER,
  3150. WDI_NO_VAL,
  3151. pdev->pdev_id);
  3152. } else {
  3153. qdf_nbuf_free(nbuf);
  3154. }
  3155. }
  3156. continue;
  3157. }
  3158. /* Drop all type of MU frame */
  3159. if ((ppdu_desc->htt_frame_type ==
  3160. HTT_STATS_FTYPE_TIDQ_DATA_MU) ||
  3161. ((ppdu_desc->htt_frame_type >=
  3162. HTT_STATS_FTYPE_SGEN_MU_BAR) &&
  3163. (ppdu_desc->htt_frame_type <=
  3164. HTT_STATS_FTYPE_SGEN_MU_BSR))) {
  3165. qdf_nbuf_free(nbuf);
  3166. continue;
  3167. }
  3168. if (((ppdu_desc->frame_type == CDP_PPDU_FTYPE_DATA) &&
  3169. (ppdu_desc->htt_frame_type !=
  3170. HTT_STATS_FTYPE_SGEN_QOS_NULL)) ||
  3171. (ppdu_desc->num_mpdu &&
  3172. ppdu_desc->frame_type == CDP_PPDU_FTYPE_BAR)) {
  3173. peer_id = ppdu_desc->user[0].peer_id;
  3174. peer = dp_tx_cap_peer_find_by_id(pdev->soc,
  3175. peer_id);
  3176. /**
  3177. * peer can be NULL
  3178. */
  3179. if (!peer) {
  3180. qdf_nbuf_free(nbuf);
  3181. continue;
  3182. }
  3183. /**
  3184. * check whether it is bss peer,
  3185. * if bss_peer no need to process further
  3186. * check whether tx_capture feature is enabled
  3187. * for this peer or globally for all peers
  3188. */
  3189. if (peer->bss_peer ||
  3190. !dp_peer_or_pdev_tx_cap_enabled(pdev,
  3191. peer, peer->mac_addr.raw)) {
  3192. dp_tx_cap_peer_unref_del(peer);
  3193. qdf_nbuf_free(nbuf);
  3194. continue;
  3195. }
  3196. /* print the bit map */
  3197. dp_tx_print_bitmap(pdev, ppdu_desc,
  3198. 0, ppdu_desc->ppdu_id);
  3199. if (ppdu_desc->user[0].tid > DP_MAX_TIDS) {
  3200. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  3201. QDF_TRACE_LEVEL_ERROR,
  3202. "%s: ppdu[%d] peer_id[%d] TID[%d] > NON_QOS_TID!",
  3203. __func__,
  3204. ppdu_desc->ppdu_id,
  3205. ppdu_desc->user[0].peer_id,
  3206. ppdu_desc->user[0].tid);
  3207. dp_tx_cap_peer_unref_del(peer);
  3208. qdf_nbuf_free(nbuf);
  3209. continue;
  3210. }
  3211. tid = ppdu_desc->user[0].tid;
  3212. dequeue_msdu_again:
  3213. num_msdu = ppdu_desc->user[0].num_msdu;
  3214. start_tsf = ppdu_desc->ppdu_start_timestamp;
  3215. end_tsf = ppdu_desc->ppdu_end_timestamp;
  3216. /*
  3217. * retrieve msdu buffer based on ppdu_id & tid
  3218. * based msdu queue and store it in local queue
  3219. * sometimes, wbm comes later than per ppdu
  3220. * stats. Assumption: all packets are SU,
  3221. * and packets comes in order
  3222. */
  3223. ret = dp_tx_msdu_dequeue(peer,
  3224. ppdu_desc->ppdu_id,
  3225. ppdu_desc->user[0].tid,
  3226. num_msdu,
  3227. &head_msdu,
  3228. &head_xretries,
  3229. start_tsf, end_tsf);
  3230. if (!ret && (++retries < 2)) {
  3231. /* wait for wbm to complete */
  3232. qdf_mdelay(2);
  3233. goto dequeue_msdu_again;
  3234. }
  3235. if (!qdf_nbuf_is_queue_empty(&head_xretries)) {
  3236. struct dp_tx_tid *tx_tid =
  3237. &peer->tx_capture.tx_tid[tid];
  3238. struct cdp_tx_completion_ppdu
  3239. *xretry_ppdu =
  3240. &tx_tid->xretry_ppdu;
  3241. xretry_ppdu->ppdu_id =
  3242. peer->tx_capture.tx_wifi_ppdu_id;
  3243. /* Restitch MPDUs from xretry MSDUs */
  3244. dp_tx_mon_restitch_mpdu(pdev, peer,
  3245. xretry_ppdu,
  3246. &head_xretries,
  3247. &xretry_ppdu->mpdu_q);
  3248. }
  3249. if (!qdf_nbuf_is_queue_empty(&head_msdu)) {
  3250. /*
  3251. * now head_msdu hold - msdu list for
  3252. * that particular ppdu_id, restitch
  3253. * mpdu from msdu and create a mpdu
  3254. * queue
  3255. */
  3256. dp_tx_mon_restitch_mpdu(pdev, peer,
  3257. ppdu_desc,
  3258. &head_msdu,
  3259. &ppdu_desc->mpdu_q);
  3260. /*
  3261. * sanity: free local head msdu queue
  3262. * do we need this ?
  3263. */
  3264. qdf_nbuf_queue_free(&head_msdu);
  3265. qlen =
  3266. qdf_nbuf_queue_len(&ppdu_desc->mpdu_q);
  3267. if (!qlen) {
  3268. qdf_nbuf_free(nbuf);
  3269. dp_tx_cap_peer_unref_del(peer);
  3270. continue;
  3271. }
  3272. } else {
  3273. qdf_nbuf_free(nbuf);
  3274. dp_tx_cap_peer_unref_del(peer);
  3275. continue;
  3276. }
  3277. nbuf_ppdu_desc_list[ppdu_desc_cnt++] = nbuf;
  3278. /* print ppdu_desc info for debugging purpose */
  3279. QDF_TRACE(QDF_MODULE_ID_TX_CAPTURE,
  3280. QDF_TRACE_LEVEL_INFO,
  3281. "%s: ppdu[%d], p_id[%d], tid[%d], n_mpdu[%d %d] n_msdu[%d] retr[%d] qlen[%d] s_tsf[%u] dur[%u] seq[%d] [%d %d]",
  3282. __func__, ppdu_desc->ppdu_id,
  3283. ppdu_desc->user[0].peer_id,
  3284. ppdu_desc->user[0].tid,
  3285. ppdu_desc->num_mpdu,
  3286. ppdu_desc->user[0].mpdu_success,
  3287. ppdu_desc->num_msdu, retries,
  3288. qlen,
  3289. ppdu_desc->ppdu_start_timestamp,
  3290. ppdu_desc->tx_duration,
  3291. ppdu_desc->user[0].start_seq,
  3292. ppdu_cnt,
  3293. ppdu_desc_cnt);
  3294. dp_tx_cap_peer_unref_del(peer);
  3295. } else {
  3296. /*
  3297. * other packet frame also added to
  3298. * descriptor list
  3299. */
  3300. nbuf_ppdu_desc_list[ppdu_desc_cnt++] = nbuf;
  3301. }
  3302. }
  3303. /*
  3304. * At this point we have mpdu queued per ppdu_desc
  3305. * based on packet capture flags send mpdu info to upper stack
  3306. */
  3307. if (ppdu_desc_cnt) {
  3308. dp_check_ppdu_and_deliver(pdev, nbuf_ppdu_desc_list,
  3309. ppdu_desc_cnt);
  3310. }
  3311. qdf_spin_unlock(&ptr_tx_cap->config_lock);
  3312. qdf_mem_free(nbuf_ppdu_desc_list);
  3313. qdf_spin_lock(&pdev->tx_capture.config_lock);
  3314. if (!pdev->tx_capture.tx_cap_mode_flag)
  3315. dp_enh_tx_capture_disable(pdev);
  3316. qdf_spin_unlock(&pdev->tx_capture.config_lock);
  3317. }
  3318. }
  3319. /**
  3320. * dp_ppdu_desc_deliver(): Function to deliver Tx PPDU status descriptor
  3321. * to upper layer
  3322. * @pdev: DP pdev handle
  3323. * @ppdu_info: per PPDU TLV descriptor
  3324. *
  3325. * return: void
  3326. */
  3327. void dp_ppdu_desc_deliver(struct dp_pdev *pdev,
  3328. struct ppdu_info *ppdu_info)
  3329. {
  3330. uint32_t now_ms = qdf_system_ticks_to_msecs(qdf_system_ticks());
  3331. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  3332. TAILQ_REMOVE(&pdev->ppdu_info_list, ppdu_info, ppdu_info_list_elem);
  3333. pdev->list_depth--;
  3334. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  3335. qdf_nbuf_data(ppdu_info->nbuf);
  3336. qdf_spin_lock_bh(&pdev->tx_capture.ppdu_stats_lock);
  3337. if (qdf_unlikely(!pdev->tx_capture_enabled &&
  3338. (pdev->tx_capture.ppdu_stats_queue_depth +
  3339. pdev->tx_capture.ppdu_stats_defer_queue_depth) >
  3340. DP_TX_PPDU_PROC_MAX_DEPTH)) {
  3341. qdf_nbuf_free(ppdu_info->nbuf);
  3342. qdf_mem_free(ppdu_info);
  3343. pdev->tx_capture.ppdu_dropped++;
  3344. } else {
  3345. STAILQ_INSERT_TAIL(&pdev->tx_capture.ppdu_stats_queue,
  3346. ppdu_info, ppdu_info_queue_elem);
  3347. pdev->tx_capture.ppdu_stats_queue_depth++;
  3348. }
  3349. qdf_spin_unlock_bh(&pdev->tx_capture.ppdu_stats_lock);
  3350. if ((pdev->tx_capture.ppdu_stats_queue_depth >
  3351. DP_TX_PPDU_PROC_THRESHOLD) ||
  3352. (pdev->tx_capture.ppdu_stats_next_sched <= now_ms)) {
  3353. qdf_queue_work(0, pdev->tx_capture.ppdu_stats_workqueue,
  3354. &pdev->tx_capture.ppdu_stats_work);
  3355. pdev->tx_capture.ppdu_stats_next_sched =
  3356. now_ms + DP_TX_PPDU_PROC_TIMEOUT;
  3357. }
  3358. }
  3359. static void set_mpdu_info(
  3360. struct cdp_tx_indication_info *tx_capture_info,
  3361. struct mon_rx_status *rx_status,
  3362. struct mon_rx_user_status *rx_user_status)
  3363. {
  3364. struct cdp_tx_indication_mpdu_info *mpdu_info;
  3365. qdf_mem_set(tx_capture_info,
  3366. sizeof(struct cdp_tx_indication_info), 0);
  3367. mpdu_info = &tx_capture_info->mpdu_info;
  3368. mpdu_info->ppdu_start_timestamp = rx_status->tsft + 16;
  3369. mpdu_info->channel_num = rx_status->chan_num;
  3370. mpdu_info->channel = rx_status->chan_freq;
  3371. mpdu_info->bw = 0;
  3372. if (rx_status->preamble_type == HAL_RX_PKT_TYPE_11B) {
  3373. mpdu_info->preamble = DOT11_B;
  3374. mpdu_info->mcs = CDP_LEGACY_MCS3;
  3375. } else if (rx_status->preamble_type == HAL_RX_PKT_TYPE_11A) {
  3376. mpdu_info->preamble = DOT11_A;
  3377. mpdu_info->mcs = CDP_LEGACY_MCS3;
  3378. } else {
  3379. mpdu_info->preamble = DOT11_A;
  3380. mpdu_info->mcs = CDP_LEGACY_MCS1;
  3381. }
  3382. }
  3383. static void dp_gen_ack_frame(struct hal_rx_ppdu_info *ppdu_info,
  3384. struct dp_peer *peer,
  3385. qdf_nbuf_t mpdu_nbuf)
  3386. {
  3387. struct ieee80211_frame_min_one *wh_addr1;
  3388. wh_addr1 = (struct ieee80211_frame_min_one *)
  3389. qdf_nbuf_data(mpdu_nbuf);
  3390. wh_addr1->i_fc[0] = 0;
  3391. wh_addr1->i_fc[1] = 0;
  3392. wh_addr1->i_fc[0] = IEEE80211_FC0_VERSION_0 |
  3393. IEEE80211_FC0_TYPE_CTL |
  3394. IEEE80211_FC0_SUBTYPE_ACK;
  3395. if (peer) {
  3396. qdf_mem_copy(wh_addr1->i_addr1,
  3397. &peer->mac_addr.raw[0],
  3398. QDF_MAC_ADDR_SIZE);
  3399. } else {
  3400. qdf_mem_copy(wh_addr1->i_addr1,
  3401. &ppdu_info->nac_info.mac_addr2[0],
  3402. QDF_MAC_ADDR_SIZE);
  3403. }
  3404. *(u_int16_t *)(&wh_addr1->i_dur) = qdf_cpu_to_le16(0x0000);
  3405. qdf_nbuf_set_pktlen(mpdu_nbuf, sizeof(*wh_addr1));
  3406. }
  3407. static void dp_gen_block_ack_frame(
  3408. struct hal_rx_ppdu_info *ppdu_info,
  3409. struct mon_rx_user_status *rx_user_status,
  3410. struct mon_rx_user_info *rx_user_info,
  3411. struct dp_peer *peer,
  3412. qdf_nbuf_t mpdu_nbuf)
  3413. {
  3414. struct dp_vdev *vdev = NULL;
  3415. uint32_t tid;
  3416. struct dp_tx_tid *tx_tid;
  3417. struct ieee80211_ctlframe_addr2 *wh_addr2;
  3418. uint8_t *frm;
  3419. tid = rx_user_status->tid;
  3420. tx_tid = &peer->tx_capture.tx_tid[tid];
  3421. if (ppdu_info->sw_frame_group_id != HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR) {
  3422. tx_tid->first_data_seq_ctrl =
  3423. rx_user_status->first_data_seq_ctrl;
  3424. tx_tid->mpdu_cnt = rx_user_status->mpdu_cnt_fcs_ok +
  3425. rx_user_status->mpdu_cnt_fcs_err;
  3426. if (tx_tid->mpdu_cnt > DP_MAX_MPDU_64)
  3427. qdf_mem_copy(tx_tid->mpdu_fcs_ok_bitmap,
  3428. rx_user_status->mpdu_fcs_ok_bitmap,
  3429. HAL_RX_NUM_WORDS_PER_PPDU_BITMAP * sizeof(
  3430. rx_user_status->mpdu_fcs_ok_bitmap[0]));
  3431. else
  3432. qdf_mem_copy(tx_tid->mpdu_fcs_ok_bitmap,
  3433. rx_user_status->mpdu_fcs_ok_bitmap,
  3434. DP_NUM_WORDS_PER_PPDU_BITMAP_64 * sizeof(
  3435. rx_user_status->mpdu_fcs_ok_bitmap[0]));
  3436. }
  3437. wh_addr2 = (struct ieee80211_ctlframe_addr2 *)
  3438. qdf_nbuf_data(mpdu_nbuf);
  3439. qdf_mem_zero(wh_addr2, DP_BA_ACK_FRAME_SIZE);
  3440. wh_addr2->i_fc[0] = 0;
  3441. wh_addr2->i_fc[1] = 0;
  3442. wh_addr2->i_fc[0] = IEEE80211_FC0_VERSION_0 |
  3443. IEEE80211_FC0_TYPE_CTL |
  3444. IEEE80211_FC0_BLOCK_ACK;
  3445. *(u_int16_t *)(&wh_addr2->i_aidordur) = qdf_cpu_to_le16(0x0000);
  3446. vdev = peer->vdev;
  3447. if (vdev)
  3448. qdf_mem_copy(wh_addr2->i_addr2, vdev->mac_addr.raw,
  3449. QDF_MAC_ADDR_SIZE);
  3450. qdf_mem_copy(wh_addr2->i_addr1, &peer->mac_addr.raw[0],
  3451. QDF_MAC_ADDR_SIZE);
  3452. frm = (uint8_t *)&wh_addr2[1];
  3453. *((uint16_t *)frm) =
  3454. qdf_cpu_to_le16((rx_user_status->tid <<
  3455. DP_IEEE80211_BAR_CTL_TID_S) |
  3456. DP_IEEE80211_BAR_CTL_COMBA);
  3457. frm += 2;
  3458. *((uint16_t *)frm) =
  3459. tx_tid->first_data_seq_ctrl;
  3460. frm += 2;
  3461. if (tx_tid->mpdu_cnt > DP_MAX_MPDU_64) {
  3462. qdf_mem_copy(frm,
  3463. tx_tid->mpdu_fcs_ok_bitmap,
  3464. HAL_RX_NUM_WORDS_PER_PPDU_BITMAP *
  3465. sizeof(rx_user_status->mpdu_fcs_ok_bitmap[0]));
  3466. frm += DP_NUM_BYTES_PER_PPDU_BITMAP;
  3467. } else {
  3468. qdf_mem_copy(frm,
  3469. tx_tid->mpdu_fcs_ok_bitmap,
  3470. DP_NUM_WORDS_PER_PPDU_BITMAP_64 *
  3471. sizeof(rx_user_status->mpdu_fcs_ok_bitmap[0]));
  3472. frm += DP_NUM_BYTES_PER_PPDU_BITMAP_64;
  3473. }
  3474. qdf_nbuf_set_pktlen(mpdu_nbuf,
  3475. (frm - (uint8_t *)qdf_nbuf_data(mpdu_nbuf)));
  3476. }
  3477. static void dp_gen_cts_frame(struct hal_rx_ppdu_info *ppdu_info,
  3478. struct dp_peer *peer,
  3479. qdf_nbuf_t mpdu_nbuf)
  3480. {
  3481. struct ieee80211_frame_min_one *wh_addr1;
  3482. uint16_t duration;
  3483. wh_addr1 = (struct ieee80211_frame_min_one *)
  3484. qdf_nbuf_data(mpdu_nbuf);
  3485. wh_addr1->i_fc[0] = 0;
  3486. wh_addr1->i_fc[1] = 0;
  3487. wh_addr1->i_fc[0] = IEEE80211_FC0_VERSION_0 |
  3488. IEEE80211_FC0_TYPE_CTL |
  3489. IEEE80211_FC0_SUBTYPE_CTS;
  3490. qdf_mem_copy(wh_addr1->i_addr1, &peer->mac_addr.raw[0],
  3491. QDF_MAC_ADDR_SIZE);
  3492. duration = (ppdu_info->rx_status.duration > SIFS_INTERVAL) ?
  3493. ppdu_info->rx_status.duration - SIFS_INTERVAL : 0;
  3494. wh_addr1->i_dur[0] = duration & 0xff;
  3495. wh_addr1->i_dur[1] = (duration >> 8) & 0xff;
  3496. qdf_nbuf_set_pktlen(mpdu_nbuf, sizeof(*wh_addr1));
  3497. }
  3498. /**
  3499. * dp_send_cts_frame_to_stack(): Function to deliver HW generated CTS frame
  3500. * in reponse to RTS
  3501. * @soc: core txrx main context
  3502. * @pdev: DP pdev object
  3503. * @ppdu_info: HAL RX PPDU info retrieved from status ring TLV
  3504. *
  3505. * return: status
  3506. */
  3507. QDF_STATUS dp_send_cts_frame_to_stack(struct dp_soc *soc,
  3508. struct dp_pdev *pdev,
  3509. struct hal_rx_ppdu_info *ppdu_info)
  3510. {
  3511. struct cdp_tx_indication_info tx_capture_info;
  3512. struct mon_rx_user_status *rx_user_status =
  3513. &ppdu_info->rx_user_status[0];
  3514. struct dp_ast_entry *ast_entry;
  3515. uint32_t peer_id;
  3516. struct dp_peer *peer;
  3517. if (rx_user_status->ast_index >=
  3518. wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  3519. return QDF_STATUS_E_FAILURE;
  3520. }
  3521. qdf_spin_lock_bh(&soc->ast_lock);
  3522. ast_entry = soc->ast_table[rx_user_status->ast_index];
  3523. if (!ast_entry) {
  3524. qdf_spin_unlock_bh(&soc->ast_lock);
  3525. return QDF_STATUS_E_FAILURE;
  3526. }
  3527. peer = ast_entry->peer;
  3528. if (!peer || peer->peer_ids[0] == HTT_INVALID_PEER) {
  3529. qdf_spin_unlock_bh(&soc->ast_lock);
  3530. return QDF_STATUS_E_FAILURE;
  3531. }
  3532. peer_id = peer->peer_ids[0];
  3533. qdf_spin_unlock_bh(&soc->ast_lock);
  3534. peer = dp_peer_find_by_id(soc, peer_id);
  3535. if (!peer)
  3536. return QDF_STATUS_E_FAILURE;
  3537. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, NULL, peer->mac_addr.raw)) {
  3538. dp_peer_unref_del_find_by_id(peer);
  3539. return QDF_STATUS_E_FAILURE;
  3540. }
  3541. set_mpdu_info(&tx_capture_info,
  3542. &ppdu_info->rx_status, rx_user_status);
  3543. tx_capture_info.mpdu_info.mcs = rx_user_status->mcs;
  3544. /* ppdu_desc is not required for legacy frames */
  3545. tx_capture_info.ppdu_desc = NULL;
  3546. tx_capture_info.mpdu_nbuf =
  3547. qdf_nbuf_alloc(pdev->soc->osdev,
  3548. MAX_MONITOR_HEADER +
  3549. DP_CTS_FRAME_SIZE,
  3550. MAX_MONITOR_HEADER,
  3551. 4, FALSE);
  3552. if (!tx_capture_info.mpdu_nbuf) {
  3553. dp_peer_unref_del_find_by_id(peer);
  3554. return QDF_STATUS_E_NOMEM;
  3555. }
  3556. dp_gen_cts_frame(ppdu_info, peer,
  3557. tx_capture_info.mpdu_nbuf);
  3558. dp_peer_unref_del_find_by_id(peer);
  3559. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  3560. &tx_capture_info, HTT_INVALID_PEER,
  3561. WDI_NO_VAL, pdev->pdev_id);
  3562. if (tx_capture_info.mpdu_nbuf)
  3563. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  3564. return QDF_STATUS_SUCCESS;
  3565. }
  3566. /**
  3567. * dp_send_usr_ack_frm_to_stack(): Function to generate BA or ACK frame and
  3568. * send to upper layer
  3569. * @soc: core txrx main context
  3570. * @pdev: DP pdev object
  3571. * @ppdu_info: HAL RX PPDU info retrieved from status ring TLV
  3572. * @rx_status: variable for rx status
  3573. * @rx_user_status: variable for rx user status
  3574. * @rx_user_info: variable for rx user info
  3575. *
  3576. * return: no
  3577. */
  3578. void dp_send_usr_ack_frm_to_stack(struct dp_soc *soc,
  3579. struct dp_pdev *pdev,
  3580. struct hal_rx_ppdu_info *ppdu_info,
  3581. struct mon_rx_status *rx_status,
  3582. struct mon_rx_user_status *rx_user_status,
  3583. struct mon_rx_user_info *rx_user_info)
  3584. {
  3585. struct cdp_tx_indication_info tx_capture_info;
  3586. struct dp_peer *peer;
  3587. struct dp_ast_entry *ast_entry;
  3588. uint32_t peer_id;
  3589. uint32_t ast_index;
  3590. uint8_t *ptr_mac_addr;
  3591. if (rx_user_info->qos_control_info_valid &&
  3592. ((rx_user_info->qos_control &
  3593. IEEE80211_QOS_ACKPOLICY) >> IEEE80211_QOS_ACKPOLICY_S)
  3594. == IEEE80211_BAR_CTL_NOACK)
  3595. return;
  3596. ast_index = rx_user_status->ast_index;
  3597. if (ast_index >=
  3598. wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  3599. if (ppdu_info->sw_frame_group_id ==
  3600. HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR)
  3601. return;
  3602. ptr_mac_addr = &ppdu_info->nac_info.mac_addr2[0];
  3603. if (!dp_peer_or_pdev_tx_cap_enabled(pdev,
  3604. NULL, ptr_mac_addr))
  3605. return;
  3606. set_mpdu_info(&tx_capture_info,
  3607. rx_status, rx_user_status);
  3608. tx_capture_info.mpdu_nbuf =
  3609. qdf_nbuf_alloc(pdev->soc->osdev,
  3610. MAX_MONITOR_HEADER +
  3611. DP_BA_ACK_FRAME_SIZE,
  3612. MAX_MONITOR_HEADER,
  3613. 4, FALSE);
  3614. if (!tx_capture_info.mpdu_nbuf)
  3615. return;
  3616. dp_gen_ack_frame(ppdu_info, NULL,
  3617. tx_capture_info.mpdu_nbuf);
  3618. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  3619. &tx_capture_info, HTT_INVALID_PEER,
  3620. WDI_NO_VAL, pdev->pdev_id);
  3621. return;
  3622. }
  3623. qdf_spin_lock_bh(&soc->ast_lock);
  3624. ast_entry = soc->ast_table[ast_index];
  3625. if (!ast_entry) {
  3626. qdf_spin_unlock_bh(&soc->ast_lock);
  3627. return;
  3628. }
  3629. peer = ast_entry->peer;
  3630. if (!peer || peer->peer_ids[0] == HTT_INVALID_PEER) {
  3631. qdf_spin_unlock_bh(&soc->ast_lock);
  3632. return;
  3633. }
  3634. peer_id = peer->peer_ids[0];
  3635. qdf_spin_unlock_bh(&soc->ast_lock);
  3636. peer = dp_peer_find_by_id(soc, peer_id);
  3637. if (!peer)
  3638. return;
  3639. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, peer,
  3640. peer->mac_addr.raw)) {
  3641. dp_peer_unref_del_find_by_id(peer);
  3642. return;
  3643. }
  3644. set_mpdu_info(&tx_capture_info,
  3645. rx_status, rx_user_status);
  3646. tx_capture_info.mpdu_nbuf =
  3647. qdf_nbuf_alloc(pdev->soc->osdev,
  3648. MAX_MONITOR_HEADER +
  3649. DP_BA_ACK_FRAME_SIZE,
  3650. MAX_MONITOR_HEADER,
  3651. 4, FALSE);
  3652. if (!tx_capture_info.mpdu_nbuf) {
  3653. dp_peer_unref_del_find_by_id(peer);
  3654. return;
  3655. }
  3656. if (peer->rx_tid[rx_user_status->tid].ba_status == DP_RX_BA_ACTIVE ||
  3657. ppdu_info->sw_frame_group_id == HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR) {
  3658. dp_gen_block_ack_frame(ppdu_info,
  3659. rx_user_status,
  3660. rx_user_info,
  3661. peer,
  3662. tx_capture_info.mpdu_nbuf);
  3663. tx_capture_info.mpdu_info.tid = rx_user_status->tid;
  3664. } else {
  3665. dp_gen_ack_frame(ppdu_info, peer,
  3666. tx_capture_info.mpdu_nbuf);
  3667. }
  3668. dp_peer_unref_del_find_by_id(peer);
  3669. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  3670. &tx_capture_info, HTT_INVALID_PEER,
  3671. WDI_NO_VAL, pdev->pdev_id);
  3672. }
  3673. /**
  3674. * dp_send_ack_frame_to_stack(): Function to generate BA or ACK frame and
  3675. * send to upper layer on received unicast frame
  3676. * @soc: core txrx main context
  3677. * @pdev: DP pdev object
  3678. * @ppdu_info: HAL RX PPDU info retrieved from status ring TLV
  3679. *
  3680. * return: status
  3681. */
  3682. QDF_STATUS dp_send_ack_frame_to_stack(struct dp_soc *soc,
  3683. struct dp_pdev *pdev,
  3684. struct hal_rx_ppdu_info *ppdu_info)
  3685. {
  3686. struct mon_rx_status *rx_status;
  3687. struct mon_rx_user_status *rx_user_status;
  3688. struct mon_rx_user_info *rx_user_info;
  3689. uint32_t i;
  3690. rx_status = &ppdu_info->rx_status;
  3691. if (!rx_status->rxpcu_filter_pass)
  3692. return QDF_STATUS_SUCCESS;
  3693. if (ppdu_info->sw_frame_group_id ==
  3694. HAL_MPDU_SW_FRAME_GROUP_MGMT_BEACON ||
  3695. ppdu_info->sw_frame_group_id ==
  3696. HAL_MPDU_SW_FRAME_GROUP_CTRL_NDPA)
  3697. return QDF_STATUS_SUCCESS;
  3698. if (ppdu_info->sw_frame_group_id == HAL_MPDU_SW_FRAME_GROUP_MGMT_PROBE_REQ &&
  3699. (ppdu_info->rx_info.mac_addr1[0] & 1)) {
  3700. return QDF_STATUS_SUCCESS;
  3701. }
  3702. if (ppdu_info->sw_frame_group_id ==
  3703. HAL_MPDU_SW_FRAME_GROUP_CTRL_RTS)
  3704. return dp_send_cts_frame_to_stack(soc, pdev, ppdu_info);
  3705. if (ppdu_info->sw_frame_group_id == HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR)
  3706. return QDF_STATUS_SUCCESS;
  3707. for (i = 0; i < ppdu_info->com_info.num_users; i++) {
  3708. if (i > OFDMA_NUM_USERS)
  3709. return QDF_STATUS_E_FAULT;
  3710. rx_user_status = &ppdu_info->rx_user_status[i];
  3711. rx_user_info = &ppdu_info->rx_user_info[i];
  3712. dp_send_usr_ack_frm_to_stack(soc, pdev, ppdu_info, rx_status,
  3713. rx_user_status, rx_user_info);
  3714. }
  3715. return QDF_STATUS_SUCCESS;
  3716. }
  3717. /**
  3718. * dp_bar_send_ack_frm_to_stack(): send BA or ACK frame
  3719. * to upper layers on received BAR packet for tx capture feature
  3720. *
  3721. * @soc: soc handle
  3722. * @pdev: pdev handle
  3723. * @nbuf: received packet
  3724. *
  3725. * Return: QDF_STATUS_SUCCESS on success
  3726. * others on error
  3727. */
  3728. QDF_STATUS
  3729. dp_bar_send_ack_frm_to_stack(struct dp_soc *soc,
  3730. struct dp_pdev *pdev,
  3731. qdf_nbuf_t nbuf)
  3732. {
  3733. struct ieee80211_ctlframe_addr2 *wh;
  3734. uint8_t *frm;
  3735. struct hal_rx_ppdu_info *ppdu_info;
  3736. struct mon_rx_status *rx_status;
  3737. struct mon_rx_user_status *rx_user_status;
  3738. struct mon_rx_user_info *rx_user_info;
  3739. uint16_t bar_ctl;
  3740. uint32_t user_id;
  3741. uint8_t tid;
  3742. if (!nbuf)
  3743. return QDF_STATUS_E_INVAL;
  3744. wh = (struct ieee80211_ctlframe_addr2 *)qdf_nbuf_data(nbuf);
  3745. if (wh->i_fc[0] != (IEEE80211_FC0_VERSION_0 |
  3746. IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_BAR)) {
  3747. return QDF_STATUS_SUCCESS;
  3748. }
  3749. frm = (uint8_t *)&wh[1];
  3750. bar_ctl = qdf_le16_to_cpu(*(uint16_t *)frm);
  3751. if (bar_ctl & DP_IEEE80211_BAR_CTL_POLICY_M)
  3752. return QDF_STATUS_SUCCESS;
  3753. tid = (bar_ctl >> DP_IEEE80211_BAR_CTL_TID_S) &
  3754. DP_IEEE80211_BAR_CTL_TID_M;
  3755. ppdu_info = &pdev->ppdu_info;
  3756. user_id = ppdu_info->rx_info.user_id;
  3757. rx_status = &ppdu_info->rx_status;
  3758. rx_user_status = &ppdu_info->rx_user_status[user_id];
  3759. rx_user_info = &ppdu_info->rx_user_info[user_id];
  3760. rx_user_status->tid = tid;
  3761. dp_send_usr_ack_frm_to_stack(soc, pdev, ppdu_info, rx_status,
  3762. rx_user_status, rx_user_info);
  3763. return QDF_STATUS_SUCCESS;
  3764. }
  3765. /**
  3766. * dp_gen_noack_frame: generate noack Action frame by using parameters
  3767. * from received NDPA frame
  3768. * @ppdu_info: pointer to ppdu_info
  3769. * @peer: pointer to peer structure
  3770. * @mpdu_nbuf: buffer for the generated noack frame
  3771. * @mon_mpdu: mpdu from monitor destination path
  3772. *
  3773. * Return: QDF_STATUS
  3774. */
  3775. static void dp_gen_noack_frame(struct hal_rx_ppdu_info *ppdu_info,
  3776. struct dp_peer *peer, qdf_nbuf_t mpdu_nbuf,
  3777. qdf_nbuf_t mon_mpdu)
  3778. {
  3779. struct ieee80211_frame *wh;
  3780. uint16_t duration;
  3781. struct dp_vdev *vdev = NULL;
  3782. char *ndpa_buf = qdf_nbuf_data(mon_mpdu);
  3783. uint8_t token = 0;
  3784. uint8_t *frm;
  3785. wh = (struct ieee80211_frame *)qdf_nbuf_data(mpdu_nbuf);
  3786. qdf_mem_zero(((char *)wh), DP_ACKNOACK_FRAME_SIZE);
  3787. wh->i_fc[0] = IEEE80211_FC0_VERSION_0 |
  3788. IEEE80211_FC0_TYPE_MGT |
  3789. IEEE80211_FCO_SUBTYPE_ACTION_NO_ACK;
  3790. qdf_mem_copy(wh->i_addr1, &peer->mac_addr.raw[0], QDF_MAC_ADDR_SIZE);
  3791. vdev = peer->vdev;
  3792. if (vdev) {
  3793. qdf_mem_copy(wh->i_addr2,
  3794. vdev->mac_addr.raw,
  3795. QDF_MAC_ADDR_SIZE);
  3796. qdf_mem_copy(wh->i_addr3,
  3797. vdev->mac_addr.raw,
  3798. QDF_MAC_ADDR_SIZE);
  3799. }
  3800. duration = (ppdu_info->rx_status.duration > SIFS_INTERVAL) ?
  3801. ppdu_info->rx_status.duration - SIFS_INTERVAL : 0;
  3802. wh->i_dur[0] = duration & 0xff;
  3803. wh->i_dur[1] = (duration >> 8) & 0xff;
  3804. frm = (uint8_t *)&wh[1];
  3805. /*
  3806. * Update category field
  3807. */
  3808. *frm = DP_IEEE80211_CATEGORY_VHT;
  3809. /*
  3810. * Update sounding token obtained from NDPA,
  3811. * shift to get upper six bits
  3812. */
  3813. frm += DP_NOACK_SOUNDING_TOKEN_POS;
  3814. token = ndpa_buf[DP_NDPA_TOKEN_POS] >> DP_NOACK_STOKEN_POS_SHIFT;
  3815. *frm = (token) << DP_NOACK_STOKEN_POS_SHIFT;
  3816. qdf_nbuf_set_pktlen(mpdu_nbuf, DP_ACKNOACK_FRAME_SIZE);
  3817. }
  3818. /**
  3819. * dp_send_noack_frame_to_stack: Sends noack Action frame to upper stack
  3820. * in response to received NDPA frame.
  3821. * @soc: SoC handle
  3822. * @pdev: PDEV pointer
  3823. * @mon_mpdu: mpdu from monitor destination path
  3824. *
  3825. * Return: QDF_STATUS
  3826. */
  3827. QDF_STATUS dp_send_noack_frame_to_stack(struct dp_soc *soc,
  3828. struct dp_pdev *pdev,
  3829. qdf_nbuf_t mon_mpdu)
  3830. {
  3831. struct hal_rx_ppdu_info *ppdu_info = &pdev->ppdu_info;
  3832. struct mon_rx_user_status *rx_user_status =
  3833. &ppdu_info->rx_user_status[0];
  3834. struct dp_ast_entry *ast_entry;
  3835. uint32_t peer_id;
  3836. struct dp_peer *peer;
  3837. struct cdp_tx_indication_info tx_capture_info;
  3838. if (rx_user_status->ast_index >=
  3839. wlan_cfg_get_max_ast_idx(soc->wlan_cfg_ctx)) {
  3840. return QDF_STATUS_E_FAILURE;
  3841. }
  3842. qdf_spin_lock_bh(&soc->ast_lock);
  3843. ast_entry = soc->ast_table[rx_user_status->ast_index];
  3844. if (!ast_entry) {
  3845. qdf_spin_unlock_bh(&soc->ast_lock);
  3846. return QDF_STATUS_E_FAILURE;
  3847. }
  3848. peer = ast_entry->peer;
  3849. if (!peer || peer->peer_ids[0] == HTT_INVALID_PEER) {
  3850. qdf_spin_unlock_bh(&soc->ast_lock);
  3851. return QDF_STATUS_E_FAILURE;
  3852. }
  3853. peer_id = peer->peer_ids[0];
  3854. qdf_spin_unlock_bh(&soc->ast_lock);
  3855. peer = dp_peer_find_by_id(soc, peer_id);
  3856. if (!peer) {
  3857. return QDF_STATUS_E_FAILURE;
  3858. }
  3859. if (!dp_peer_or_pdev_tx_cap_enabled(pdev, peer, peer->mac_addr.raw)) {
  3860. dp_peer_unref_del_find_by_id(peer);
  3861. return QDF_STATUS_E_FAILURE;
  3862. }
  3863. set_mpdu_info(&tx_capture_info,
  3864. &ppdu_info->rx_status, rx_user_status);
  3865. tx_capture_info.mpdu_info.mcs = rx_user_status->mcs;
  3866. /*
  3867. *ppdu_desc is not required for legacy frames
  3868. */
  3869. tx_capture_info.ppdu_desc = NULL;
  3870. tx_capture_info.mpdu_nbuf =
  3871. qdf_nbuf_alloc(pdev->soc->osdev,
  3872. MAX_MONITOR_HEADER +
  3873. DP_ACKNOACK_FRAME_SIZE,
  3874. MAX_MONITOR_HEADER,
  3875. 4, FALSE);
  3876. if (!tx_capture_info.mpdu_nbuf) {
  3877. dp_peer_unref_del_find_by_id(peer);
  3878. return QDF_STATUS_E_NOMEM;
  3879. }
  3880. dp_gen_noack_frame(ppdu_info, peer,
  3881. tx_capture_info.mpdu_nbuf, mon_mpdu);
  3882. dp_peer_unref_del_find_by_id(peer);
  3883. dp_wdi_event_handler(WDI_EVENT_TX_DATA, pdev->soc,
  3884. &tx_capture_info, HTT_INVALID_PEER,
  3885. WDI_NO_VAL, pdev->pdev_id);
  3886. if (tx_capture_info.mpdu_nbuf)
  3887. qdf_nbuf_free(tx_capture_info.mpdu_nbuf);
  3888. return QDF_STATUS_SUCCESS;
  3889. }
  3890. /**
  3891. * dp_handle_tx_capture_from_dest: Handle any TX capture frames from
  3892. * monitor destination path.
  3893. * @soc: SoC handle
  3894. * @pdev: PDEV pointer
  3895. * @mon_mpdu: mpdu from monitor destination path
  3896. *
  3897. * Return: QDF_STATUS
  3898. */
  3899. QDF_STATUS dp_handle_tx_capture_from_dest(struct dp_soc *soc,
  3900. struct dp_pdev *pdev,
  3901. qdf_nbuf_t mon_mpdu)
  3902. {
  3903. struct hal_rx_ppdu_info *ppdu_info = &pdev->ppdu_info;
  3904. /*
  3905. * The below switch case can be extended to
  3906. * add more frame types as needed
  3907. */
  3908. switch (ppdu_info->sw_frame_group_id) {
  3909. case HAL_MPDU_SW_FRAME_GROUP_CTRL_NDPA:
  3910. return dp_send_noack_frame_to_stack(soc, pdev, mon_mpdu);
  3911. case HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR:
  3912. return dp_bar_send_ack_frm_to_stack(soc, pdev, mon_mpdu);
  3913. default:
  3914. break;
  3915. }
  3916. return QDF_STATUS_SUCCESS;
  3917. }
  3918. /**
  3919. * dp_peer_set_tx_capture_enabled: Set tx_cap_enabled bit in peer
  3920. * @pdev: DP PDEV handle
  3921. * @peer: Peer handle
  3922. * @value: Enable/disable setting for tx_cap_enabled
  3923. * @peer_mac: peer mac address
  3924. *
  3925. * Return: QDF_STATUS
  3926. */
  3927. QDF_STATUS
  3928. dp_peer_set_tx_capture_enabled(struct dp_pdev *pdev,
  3929. struct dp_peer *peer, uint8_t value,
  3930. uint8_t *peer_mac)
  3931. {
  3932. uint32_t peer_id = HTT_INVALID_PEER;
  3933. QDF_STATUS status = QDF_STATUS_E_FAILURE;
  3934. if (value) {
  3935. if (dp_peer_tx_cap_add_filter(pdev, peer_id, peer_mac)) {
  3936. if (peer)
  3937. peer->tx_cap_enabled = value;
  3938. status = QDF_STATUS_SUCCESS;
  3939. }
  3940. } else {
  3941. if (dp_peer_tx_cap_del_filter(pdev, peer_id, peer_mac)) {
  3942. if (peer)
  3943. peer->tx_cap_enabled = value;
  3944. status = QDF_STATUS_SUCCESS;
  3945. }
  3946. }
  3947. return status;
  3948. }
  3949. /*
  3950. * dp_peer_tx_capture_filter_check: check filter is enable for the filter
  3951. * and update tx_cap_enabled flag
  3952. * @pdev: DP PDEV handle
  3953. * @peer: DP PEER handle
  3954. *
  3955. * return: void
  3956. */
  3957. void dp_peer_tx_capture_filter_check(struct dp_pdev *pdev,
  3958. struct dp_peer *peer)
  3959. {
  3960. if (!peer)
  3961. return;
  3962. if (dp_peer_tx_cap_search(pdev, peer->peer_ids[0],
  3963. peer->mac_addr.raw)) {
  3964. peer->tx_cap_enabled = 1;
  3965. }
  3966. return;
  3967. }
  3968. #endif