dp_tx_capture.c 126 KB

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