dp_tx_capture.c 127 KB

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