dp_htt.c 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896
  1. /*
  2. * Copyright (c) 2016-2019 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 <hal_hw_headers.h>
  20. #include <hal_api.h>
  21. #include "dp_peer.h"
  22. #include "dp_types.h"
  23. #include "dp_internal.h"
  24. #include "dp_rx_mon.h"
  25. #include "htt_stats.h"
  26. #include "htt_ppdu_stats.h"
  27. #include "dp_htt.h"
  28. #include "qdf_mem.h" /* qdf_mem_malloc,free */
  29. #include "cdp_txrx_cmn_struct.h"
  30. #ifdef FEATURE_PERPKT_INFO
  31. #include "dp_ratetable.h"
  32. #endif
  33. #define HTT_TLV_HDR_LEN HTT_T2H_EXT_STATS_CONF_TLV_HDR_SIZE
  34. #define HTT_HTC_PKT_POOL_INIT_SIZE 64
  35. #define HTT_MSG_BUF_SIZE(msg_bytes) \
  36. ((msg_bytes) + HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING)
  37. #define HTT_PID_BIT_MASK 0x3
  38. #define DP_EXT_MSG_LENGTH 2048
  39. #define HTT_MGMT_CTRL_TLV_HDR_RESERVERD_LEN 16
  40. /*
  41. * dp_htt_get_ppdu_sniffer_ampdu_tlv_bitmap() - Get ppdu stats tlv
  42. * bitmap for sniffer mode
  43. * @bitmap: received bitmap
  44. *
  45. * Return: expected bitmap value, returns zero if doesn't match with
  46. * either 64-bit Tx window or 256-bit window tlv bitmap
  47. */
  48. int
  49. dp_htt_get_ppdu_sniffer_ampdu_tlv_bitmap(uint32_t bitmap)
  50. {
  51. if (bitmap == (HTT_PPDU_SNIFFER_AMPDU_TLV_BITMAP_64))
  52. return HTT_PPDU_SNIFFER_AMPDU_TLV_BITMAP_64;
  53. else if (bitmap == (HTT_PPDU_SNIFFER_AMPDU_TLV_BITMAP_256))
  54. return HTT_PPDU_SNIFFER_AMPDU_TLV_BITMAP_256;
  55. return 0;
  56. }
  57. #ifdef FEATURE_PERPKT_INFO
  58. /*
  59. * dp_tx_rate_stats_update() - Update rate per-peer statistics
  60. * @peer: Datapath peer handle
  61. * @ppdu: PPDU Descriptor
  62. *
  63. * Return: None
  64. */
  65. static void
  66. dp_tx_rate_stats_update(struct dp_peer *peer,
  67. struct cdp_tx_completion_ppdu_user *ppdu)
  68. {
  69. uint32_t ratekbps = 0;
  70. uint64_t ppdu_tx_rate = 0;
  71. uint32_t rix;
  72. if (!peer || !ppdu)
  73. return;
  74. ratekbps = dp_getrateindex(ppdu->gi,
  75. ppdu->mcs,
  76. ppdu->nss,
  77. ppdu->preamble,
  78. ppdu->bw,
  79. &rix);
  80. DP_STATS_UPD(peer, tx.last_tx_rate, ratekbps);
  81. if (!ratekbps)
  82. return;
  83. ppdu->rix = rix;
  84. ppdu->tx_ratekbps = ratekbps;
  85. peer->stats.tx.avg_tx_rate =
  86. dp_ath_rate_lpf(peer->stats.tx.avg_tx_rate, ratekbps);
  87. ppdu_tx_rate = dp_ath_rate_out(peer->stats.tx.avg_tx_rate);
  88. DP_STATS_UPD(peer, tx.rnd_avg_tx_rate, ppdu_tx_rate);
  89. if (peer->vdev) {
  90. /*
  91. * In STA mode:
  92. * We get ucast stats as BSS peer stats.
  93. *
  94. * In AP mode:
  95. * We get mcast stats as BSS peer stats.
  96. * We get ucast stats as assoc peer stats.
  97. */
  98. if (peer->vdev->opmode == wlan_op_mode_ap && peer->bss_peer) {
  99. peer->vdev->stats.tx.mcast_last_tx_rate = ratekbps;
  100. peer->vdev->stats.tx.mcast_last_tx_rate_mcs = ppdu->mcs;
  101. } else {
  102. peer->vdev->stats.tx.last_tx_rate = ratekbps;
  103. peer->vdev->stats.tx.last_tx_rate_mcs = ppdu->mcs;
  104. }
  105. }
  106. }
  107. /*
  108. * dp_tx_stats_update() - Update per-peer statistics
  109. * @soc: Datapath soc handle
  110. * @peer: Datapath peer handle
  111. * @ppdu: PPDU Descriptor
  112. * @ack_rssi: RSSI of last ack received
  113. *
  114. * Return: None
  115. */
  116. static void
  117. dp_tx_stats_update(struct dp_soc *soc, struct dp_peer *peer,
  118. struct cdp_tx_completion_ppdu_user *ppdu,
  119. uint32_t ack_rssi)
  120. {
  121. struct dp_pdev *pdev = peer->vdev->pdev;
  122. uint8_t preamble, mcs;
  123. uint16_t num_msdu;
  124. preamble = ppdu->preamble;
  125. mcs = ppdu->mcs;
  126. num_msdu = ppdu->num_msdu;
  127. /* If the peer statistics are already processed as part of
  128. * per-MSDU completion handler, do not process these again in per-PPDU
  129. * indications */
  130. if (soc->process_tx_status)
  131. return;
  132. if (ppdu->completion_status != HTT_PPDU_STATS_USER_STATUS_OK) {
  133. DP_STATS_INC(peer, tx.retries,
  134. (ppdu->long_retries + ppdu->short_retries));
  135. DP_STATS_INC(peer, tx.tx_failed, ppdu->failed_msdus);
  136. return;
  137. }
  138. if (ppdu->is_ppdu_cookie_valid)
  139. DP_STATS_INC(peer, tx.num_ppdu_cookie_valid, 1);
  140. if (ppdu->mu_group_id <= MAX_MU_GROUP_ID &&
  141. ppdu->ppdu_type != HTT_PPDU_STATS_PPDU_TYPE_SU) {
  142. if (unlikely(!(ppdu->mu_group_id & (MAX_MU_GROUP_ID - 1))))
  143. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  144. "mu_group_id out of bound!!\n");
  145. else
  146. DP_STATS_UPD(peer, tx.mu_group_id[ppdu->mu_group_id],
  147. (ppdu->user_pos + 1));
  148. }
  149. if (ppdu->ppdu_type == HTT_PPDU_STATS_PPDU_TYPE_MU_OFDMA ||
  150. ppdu->ppdu_type == HTT_PPDU_STATS_PPDU_TYPE_MU_MIMO_OFDMA) {
  151. DP_STATS_UPD(peer, tx.ru_tones, ppdu->ru_tones);
  152. DP_STATS_UPD(peer, tx.ru_start, ppdu->ru_start);
  153. switch (ppdu->ru_tones) {
  154. case RU_26:
  155. DP_STATS_INC(peer, tx.ru_loc[0], num_msdu);
  156. break;
  157. case RU_52:
  158. DP_STATS_INC(peer, tx.ru_loc[1], num_msdu);
  159. break;
  160. case RU_106:
  161. DP_STATS_INC(peer, tx.ru_loc[2], num_msdu);
  162. break;
  163. case RU_242:
  164. DP_STATS_INC(peer, tx.ru_loc[3], num_msdu);
  165. break;
  166. case RU_484:
  167. DP_STATS_INC(peer, tx.ru_loc[4], num_msdu);
  168. break;
  169. case RU_996:
  170. DP_STATS_INC(peer, tx.ru_loc[5], num_msdu);
  171. break;
  172. }
  173. }
  174. DP_STATS_INC(peer, tx.transmit_type[ppdu->ppdu_type], num_msdu);
  175. DP_STATS_INC_PKT(peer, tx.comp_pkt,
  176. num_msdu, (ppdu->success_bytes +
  177. ppdu->retry_bytes + ppdu->failed_bytes));
  178. DP_STATS_UPD(peer, tx.tx_rate, ppdu->tx_rate);
  179. DP_STATS_INC(peer, tx.sgi_count[ppdu->gi], num_msdu);
  180. DP_STATS_INC(peer, tx.bw[ppdu->bw], num_msdu);
  181. DP_STATS_INC(peer, tx.nss[ppdu->nss], num_msdu);
  182. if (ppdu->tid < CDP_DATA_TID_MAX)
  183. DP_STATS_INC(peer, tx.wme_ac_type[TID_TO_WME_AC(ppdu->tid)],
  184. num_msdu);
  185. DP_STATS_INCC(peer, tx.stbc, num_msdu, ppdu->stbc);
  186. DP_STATS_INCC(peer, tx.ldpc, num_msdu, ppdu->ldpc);
  187. if (!(ppdu->is_mcast) && ppdu->ack_rssi_valid)
  188. DP_STATS_UPD(peer, tx.last_ack_rssi, ack_rssi);
  189. DP_STATS_INCC(peer,
  190. tx.pkt_type[preamble].mcs_count[MAX_MCS-1], num_msdu,
  191. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
  192. DP_STATS_INCC(peer,
  193. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  194. ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
  195. DP_STATS_INCC(peer,
  196. tx.pkt_type[preamble].mcs_count[MAX_MCS-1], num_msdu,
  197. ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
  198. DP_STATS_INCC(peer,
  199. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  200. ((mcs < (MAX_MCS_11B)) && (preamble == DOT11_B)));
  201. DP_STATS_INCC(peer,
  202. tx.pkt_type[preamble].mcs_count[MAX_MCS-1], num_msdu,
  203. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
  204. DP_STATS_INCC(peer,
  205. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  206. ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
  207. DP_STATS_INCC(peer,
  208. tx.pkt_type[preamble].mcs_count[MAX_MCS-1], num_msdu,
  209. ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
  210. DP_STATS_INCC(peer,
  211. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  212. ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
  213. DP_STATS_INCC(peer,
  214. tx.pkt_type[preamble].mcs_count[MAX_MCS-1], num_msdu,
  215. ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
  216. DP_STATS_INCC(peer,
  217. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  218. ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
  219. DP_STATS_INCC(peer, tx.ampdu_cnt, num_msdu, ppdu->is_ampdu);
  220. DP_STATS_INCC(peer, tx.non_ampdu_cnt, num_msdu, !(ppdu->is_ampdu));
  221. dp_peer_stats_notify(peer);
  222. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  223. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc,
  224. &peer->stats, ppdu->peer_id,
  225. UPDATE_PEER_STATS, pdev->pdev_id);
  226. #endif
  227. }
  228. #endif
  229. #ifdef WLAN_TX_PKT_CAPTURE_ENH
  230. #include "dp_tx_capture.h"
  231. #else
  232. static inline void
  233. dp_process_ppdu_stats_update_failed_bitmap(struct dp_pdev *pdev,
  234. void *data,
  235. uint32_t ppdu_id,
  236. uint32_t size)
  237. {
  238. }
  239. #endif
  240. /*
  241. * htt_htc_pkt_alloc() - Allocate HTC packet buffer
  242. * @htt_soc: HTT SOC handle
  243. *
  244. * Return: Pointer to htc packet buffer
  245. */
  246. static struct dp_htt_htc_pkt *
  247. htt_htc_pkt_alloc(struct htt_soc *soc)
  248. {
  249. struct dp_htt_htc_pkt_union *pkt = NULL;
  250. HTT_TX_MUTEX_ACQUIRE(&soc->htt_tx_mutex);
  251. if (soc->htt_htc_pkt_freelist) {
  252. pkt = soc->htt_htc_pkt_freelist;
  253. soc->htt_htc_pkt_freelist = soc->htt_htc_pkt_freelist->u.next;
  254. }
  255. HTT_TX_MUTEX_RELEASE(&soc->htt_tx_mutex);
  256. if (!pkt)
  257. pkt = qdf_mem_malloc(sizeof(*pkt));
  258. return &pkt->u.pkt; /* not actually a dereference */
  259. }
  260. /*
  261. * htt_htc_pkt_free() - Free HTC packet buffer
  262. * @htt_soc: HTT SOC handle
  263. */
  264. static void
  265. htt_htc_pkt_free(struct htt_soc *soc, struct dp_htt_htc_pkt *pkt)
  266. {
  267. struct dp_htt_htc_pkt_union *u_pkt =
  268. (struct dp_htt_htc_pkt_union *)pkt;
  269. HTT_TX_MUTEX_ACQUIRE(&soc->htt_tx_mutex);
  270. u_pkt->u.next = soc->htt_htc_pkt_freelist;
  271. soc->htt_htc_pkt_freelist = u_pkt;
  272. HTT_TX_MUTEX_RELEASE(&soc->htt_tx_mutex);
  273. }
  274. /*
  275. * htt_htc_pkt_pool_free() - Free HTC packet pool
  276. * @htt_soc: HTT SOC handle
  277. */
  278. static void
  279. htt_htc_pkt_pool_free(struct htt_soc *soc)
  280. {
  281. struct dp_htt_htc_pkt_union *pkt, *next;
  282. pkt = soc->htt_htc_pkt_freelist;
  283. while (pkt) {
  284. next = pkt->u.next;
  285. qdf_mem_free(pkt);
  286. pkt = next;
  287. }
  288. soc->htt_htc_pkt_freelist = NULL;
  289. }
  290. /*
  291. * htt_htc_misc_pkt_list_trim() - trim misc list
  292. * @htt_soc: HTT SOC handle
  293. * @level: max no. of pkts in list
  294. */
  295. static void
  296. htt_htc_misc_pkt_list_trim(struct htt_soc *soc, int level)
  297. {
  298. struct dp_htt_htc_pkt_union *pkt, *next, *prev = NULL;
  299. int i = 0;
  300. qdf_nbuf_t netbuf;
  301. HTT_TX_MUTEX_ACQUIRE(&soc->htt_tx_mutex);
  302. pkt = soc->htt_htc_pkt_misclist;
  303. while (pkt) {
  304. next = pkt->u.next;
  305. /* trim the out grown list*/
  306. if (++i > level) {
  307. netbuf =
  308. (qdf_nbuf_t)(pkt->u.pkt.htc_pkt.pNetBufContext);
  309. qdf_nbuf_unmap(soc->osdev, netbuf, QDF_DMA_TO_DEVICE);
  310. qdf_nbuf_free(netbuf);
  311. qdf_mem_free(pkt);
  312. pkt = NULL;
  313. if (prev)
  314. prev->u.next = NULL;
  315. }
  316. prev = pkt;
  317. pkt = next;
  318. }
  319. HTT_TX_MUTEX_RELEASE(&soc->htt_tx_mutex);
  320. }
  321. /*
  322. * htt_htc_misc_pkt_list_add() - Add pkt to misc list
  323. * @htt_soc: HTT SOC handle
  324. * @dp_htt_htc_pkt: pkt to be added to list
  325. */
  326. static void
  327. htt_htc_misc_pkt_list_add(struct htt_soc *soc, struct dp_htt_htc_pkt *pkt)
  328. {
  329. struct dp_htt_htc_pkt_union *u_pkt =
  330. (struct dp_htt_htc_pkt_union *)pkt;
  331. int misclist_trim_level = htc_get_tx_queue_depth(soc->htc_soc,
  332. pkt->htc_pkt.Endpoint)
  333. + DP_HTT_HTC_PKT_MISCLIST_SIZE;
  334. HTT_TX_MUTEX_ACQUIRE(&soc->htt_tx_mutex);
  335. if (soc->htt_htc_pkt_misclist) {
  336. u_pkt->u.next = soc->htt_htc_pkt_misclist;
  337. soc->htt_htc_pkt_misclist = u_pkt;
  338. } else {
  339. soc->htt_htc_pkt_misclist = u_pkt;
  340. }
  341. HTT_TX_MUTEX_RELEASE(&soc->htt_tx_mutex);
  342. /* only ce pipe size + tx_queue_depth could possibly be in use
  343. * free older packets in the misclist
  344. */
  345. htt_htc_misc_pkt_list_trim(soc, misclist_trim_level);
  346. }
  347. /**
  348. * DP_HTT_SEND_HTC_PKT() - Send htt packet from host
  349. * @soc : HTT SOC handle
  350. * @pkt: pkt to be send
  351. * @cmd : command to be recorded in dp htt logger
  352. * @buf : Pointer to buffer needs to be recored for above cmd
  353. *
  354. * Return: None
  355. */
  356. static inline void DP_HTT_SEND_HTC_PKT(struct htt_soc *soc,
  357. struct dp_htt_htc_pkt *pkt, uint8_t cmd,
  358. uint8_t *buf)
  359. {
  360. htt_command_record(soc->htt_logger_handle, cmd, buf);
  361. if (htc_send_pkt(soc->htc_soc, &pkt->htc_pkt) ==
  362. QDF_STATUS_SUCCESS)
  363. htt_htc_misc_pkt_list_add(soc, pkt);
  364. }
  365. /*
  366. * htt_htc_misc_pkt_pool_free() - free pkts in misc list
  367. * @htt_soc: HTT SOC handle
  368. */
  369. static void
  370. htt_htc_misc_pkt_pool_free(struct htt_soc *soc)
  371. {
  372. struct dp_htt_htc_pkt_union *pkt, *next;
  373. qdf_nbuf_t netbuf;
  374. pkt = soc->htt_htc_pkt_misclist;
  375. while (pkt) {
  376. next = pkt->u.next;
  377. netbuf = (qdf_nbuf_t) (pkt->u.pkt.htc_pkt.pNetBufContext);
  378. qdf_nbuf_unmap(soc->osdev, netbuf, QDF_DMA_TO_DEVICE);
  379. soc->stats.htc_pkt_free++;
  380. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
  381. "%s: Pkt free count %d",
  382. __func__, soc->stats.htc_pkt_free);
  383. qdf_nbuf_free(netbuf);
  384. qdf_mem_free(pkt);
  385. pkt = next;
  386. }
  387. soc->htt_htc_pkt_misclist = NULL;
  388. }
  389. /*
  390. * htt_t2h_mac_addr_deswizzle() - Swap MAC addr bytes if FW endianness differ
  391. * @tgt_mac_addr: Target MAC
  392. * @buffer: Output buffer
  393. */
  394. static u_int8_t *
  395. htt_t2h_mac_addr_deswizzle(u_int8_t *tgt_mac_addr, u_int8_t *buffer)
  396. {
  397. #ifdef BIG_ENDIAN_HOST
  398. /*
  399. * The host endianness is opposite of the target endianness.
  400. * To make u_int32_t elements come out correctly, the target->host
  401. * upload has swizzled the bytes in each u_int32_t element of the
  402. * message.
  403. * For byte-array message fields like the MAC address, this
  404. * upload swizzling puts the bytes in the wrong order, and needs
  405. * to be undone.
  406. */
  407. buffer[0] = tgt_mac_addr[3];
  408. buffer[1] = tgt_mac_addr[2];
  409. buffer[2] = tgt_mac_addr[1];
  410. buffer[3] = tgt_mac_addr[0];
  411. buffer[4] = tgt_mac_addr[7];
  412. buffer[5] = tgt_mac_addr[6];
  413. return buffer;
  414. #else
  415. /*
  416. * The host endianness matches the target endianness -
  417. * we can use the mac addr directly from the message buffer.
  418. */
  419. return tgt_mac_addr;
  420. #endif
  421. }
  422. /*
  423. * dp_htt_h2t_send_complete_free_netbuf() - Free completed buffer
  424. * @soc: SOC handle
  425. * @status: Completion status
  426. * @netbuf: HTT buffer
  427. */
  428. static void
  429. dp_htt_h2t_send_complete_free_netbuf(
  430. void *soc, A_STATUS status, qdf_nbuf_t netbuf)
  431. {
  432. qdf_nbuf_free(netbuf);
  433. }
  434. /*
  435. * dp_htt_h2t_send_complete() - H2T completion handler
  436. * @context: Opaque context (HTT SOC handle)
  437. * @htc_pkt: HTC packet
  438. */
  439. static void
  440. dp_htt_h2t_send_complete(void *context, HTC_PACKET *htc_pkt)
  441. {
  442. void (*send_complete_part2)(
  443. void *soc, QDF_STATUS status, qdf_nbuf_t msdu);
  444. struct htt_soc *soc = (struct htt_soc *) context;
  445. struct dp_htt_htc_pkt *htt_pkt;
  446. qdf_nbuf_t netbuf;
  447. send_complete_part2 = htc_pkt->pPktContext;
  448. htt_pkt = container_of(htc_pkt, struct dp_htt_htc_pkt, htc_pkt);
  449. /* process (free or keep) the netbuf that held the message */
  450. netbuf = (qdf_nbuf_t) htc_pkt->pNetBufContext;
  451. /*
  452. * adf sendcomplete is required for windows only
  453. */
  454. /* qdf_nbuf_set_sendcompleteflag(netbuf, TRUE); */
  455. if (send_complete_part2) {
  456. send_complete_part2(
  457. htt_pkt->soc_ctxt, htc_pkt->Status, netbuf);
  458. }
  459. /* free the htt_htc_pkt / HTC_PACKET object */
  460. htt_htc_pkt_free(soc, htt_pkt);
  461. }
  462. /*
  463. * htt_h2t_ver_req_msg() - Send HTT version request message to target
  464. * @htt_soc: HTT SOC handle
  465. *
  466. * Return: 0 on success; error code on failure
  467. */
  468. static int htt_h2t_ver_req_msg(struct htt_soc *soc)
  469. {
  470. struct dp_htt_htc_pkt *pkt;
  471. qdf_nbuf_t msg;
  472. uint32_t *msg_word;
  473. msg = qdf_nbuf_alloc(
  474. soc->osdev,
  475. HTT_MSG_BUF_SIZE(HTT_VER_REQ_BYTES),
  476. /* reserve room for the HTC header */
  477. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  478. if (!msg)
  479. return QDF_STATUS_E_NOMEM;
  480. /*
  481. * Set the length of the message.
  482. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  483. * separately during the below call to qdf_nbuf_push_head.
  484. * The contribution from the HTC header is added separately inside HTC.
  485. */
  486. if (qdf_nbuf_put_tail(msg, HTT_VER_REQ_BYTES) == NULL) {
  487. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  488. "%s: Failed to expand head for HTT_H2T_MSG_TYPE_VERSION_REQ msg",
  489. __func__);
  490. return QDF_STATUS_E_FAILURE;
  491. }
  492. /* fill in the message contents */
  493. msg_word = (u_int32_t *) qdf_nbuf_data(msg);
  494. /* rewind beyond alignment pad to get to the HTC header reserved area */
  495. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  496. *msg_word = 0;
  497. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_VERSION_REQ);
  498. pkt = htt_htc_pkt_alloc(soc);
  499. if (!pkt) {
  500. qdf_nbuf_free(msg);
  501. return QDF_STATUS_E_FAILURE;
  502. }
  503. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  504. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  505. dp_htt_h2t_send_complete_free_netbuf, qdf_nbuf_data(msg),
  506. qdf_nbuf_len(msg), soc->htc_endpoint,
  507. 1); /* tag - not relevant here */
  508. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  509. DP_HTT_SEND_HTC_PKT(soc, pkt, HTT_H2T_MSG_TYPE_VERSION_REQ, NULL);
  510. return 0;
  511. }
  512. /*
  513. * htt_srng_setup() - Send SRNG setup message to target
  514. * @htt_soc: HTT SOC handle
  515. * @mac_id: MAC Id
  516. * @hal_srng: Opaque HAL SRNG pointer
  517. * @hal_ring_type: SRNG ring type
  518. *
  519. * Return: 0 on success; error code on failure
  520. */
  521. int htt_srng_setup(struct htt_soc *soc, int mac_id,
  522. hal_ring_handle_t hal_ring_hdl,
  523. int hal_ring_type)
  524. {
  525. struct dp_htt_htc_pkt *pkt;
  526. qdf_nbuf_t htt_msg;
  527. uint32_t *msg_word;
  528. struct hal_srng_params srng_params;
  529. qdf_dma_addr_t hp_addr, tp_addr;
  530. uint32_t ring_entry_size =
  531. hal_srng_get_entrysize(soc->hal_soc, hal_ring_type);
  532. int htt_ring_type, htt_ring_id;
  533. uint8_t *htt_logger_bufp;
  534. /* Sizes should be set in 4-byte words */
  535. ring_entry_size = ring_entry_size >> 2;
  536. htt_msg = qdf_nbuf_alloc(soc->osdev,
  537. HTT_MSG_BUF_SIZE(HTT_SRING_SETUP_SZ),
  538. /* reserve room for the HTC header */
  539. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  540. if (!htt_msg)
  541. goto fail0;
  542. hal_get_srng_params(soc->hal_soc, hal_ring_hdl, &srng_params);
  543. hp_addr = hal_srng_get_hp_addr(soc->hal_soc, hal_ring_hdl);
  544. tp_addr = hal_srng_get_tp_addr(soc->hal_soc, hal_ring_hdl);
  545. switch (hal_ring_type) {
  546. case RXDMA_BUF:
  547. #ifdef QCA_HOST2FW_RXBUF_RING
  548. if (srng_params.ring_id ==
  549. (HAL_SRNG_WMAC1_SW2RXDMA0_BUF0)) {
  550. htt_ring_id = HTT_HOST1_TO_FW_RXBUF_RING;
  551. htt_ring_type = HTT_SW_TO_SW_RING;
  552. #ifdef IPA_OFFLOAD
  553. } else if (srng_params.ring_id ==
  554. (HAL_SRNG_WMAC1_SW2RXDMA0_BUF2)) {
  555. htt_ring_id = HTT_HOST2_TO_FW_RXBUF_RING;
  556. htt_ring_type = HTT_SW_TO_SW_RING;
  557. #endif
  558. #else
  559. if (srng_params.ring_id ==
  560. (HAL_SRNG_WMAC1_SW2RXDMA0_BUF0 +
  561. (mac_id * HAL_MAX_RINGS_PER_LMAC))) {
  562. htt_ring_id = HTT_RXDMA_HOST_BUF_RING;
  563. htt_ring_type = HTT_SW_TO_HW_RING;
  564. #endif
  565. } else if (srng_params.ring_id ==
  566. #ifdef IPA_OFFLOAD
  567. (HAL_SRNG_WMAC1_SW2RXDMA0_BUF1 +
  568. #else
  569. (HAL_SRNG_WMAC1_SW2RXDMA1_BUF +
  570. #endif
  571. (mac_id * HAL_MAX_RINGS_PER_LMAC))) {
  572. htt_ring_id = HTT_RXDMA_HOST_BUF_RING;
  573. htt_ring_type = HTT_SW_TO_HW_RING;
  574. } else {
  575. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  576. "%s: Ring %d currently not supported",
  577. __func__, srng_params.ring_id);
  578. goto fail1;
  579. }
  580. dp_info("ring_type %d ring_id %d htt_ring_id %d hp_addr 0x%llx tp_addr 0x%llx",
  581. hal_ring_type, srng_params.ring_id, htt_ring_id,
  582. (uint64_t)hp_addr,
  583. (uint64_t)tp_addr);
  584. break;
  585. case RXDMA_MONITOR_BUF:
  586. htt_ring_id = HTT_RXDMA_MONITOR_BUF_RING;
  587. htt_ring_type = HTT_SW_TO_HW_RING;
  588. break;
  589. case RXDMA_MONITOR_STATUS:
  590. htt_ring_id = HTT_RXDMA_MONITOR_STATUS_RING;
  591. htt_ring_type = HTT_SW_TO_HW_RING;
  592. break;
  593. case RXDMA_MONITOR_DST:
  594. htt_ring_id = HTT_RXDMA_MONITOR_DEST_RING;
  595. htt_ring_type = HTT_HW_TO_SW_RING;
  596. break;
  597. case RXDMA_MONITOR_DESC:
  598. htt_ring_id = HTT_RXDMA_MONITOR_DESC_RING;
  599. htt_ring_type = HTT_SW_TO_HW_RING;
  600. break;
  601. case RXDMA_DST:
  602. htt_ring_id = HTT_RXDMA_NON_MONITOR_DEST_RING;
  603. htt_ring_type = HTT_HW_TO_SW_RING;
  604. break;
  605. default:
  606. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  607. "%s: Ring currently not supported", __func__);
  608. goto fail1;
  609. }
  610. /*
  611. * Set the length of the message.
  612. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  613. * separately during the below call to qdf_nbuf_push_head.
  614. * The contribution from the HTC header is added separately inside HTC.
  615. */
  616. if (qdf_nbuf_put_tail(htt_msg, HTT_SRING_SETUP_SZ) == NULL) {
  617. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  618. "%s: Failed to expand head for SRING_SETUP msg",
  619. __func__);
  620. return QDF_STATUS_E_FAILURE;
  621. }
  622. msg_word = (uint32_t *)qdf_nbuf_data(htt_msg);
  623. /* rewind beyond alignment pad to get to the HTC header reserved area */
  624. qdf_nbuf_push_head(htt_msg, HTC_HDR_ALIGNMENT_PADDING);
  625. /* word 0 */
  626. *msg_word = 0;
  627. htt_logger_bufp = (uint8_t *)msg_word;
  628. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_SRING_SETUP);
  629. if ((htt_ring_type == HTT_SW_TO_HW_RING) ||
  630. (htt_ring_type == HTT_HW_TO_SW_RING))
  631. HTT_SRING_SETUP_PDEV_ID_SET(*msg_word,
  632. DP_SW2HW_MACID(mac_id));
  633. else
  634. HTT_SRING_SETUP_PDEV_ID_SET(*msg_word, mac_id);
  635. dp_info("%s: mac_id %d", __func__, mac_id);
  636. HTT_SRING_SETUP_RING_TYPE_SET(*msg_word, htt_ring_type);
  637. /* TODO: Discuss with FW on changing this to unique ID and using
  638. * htt_ring_type to send the type of ring
  639. */
  640. HTT_SRING_SETUP_RING_ID_SET(*msg_word, htt_ring_id);
  641. /* word 1 */
  642. msg_word++;
  643. *msg_word = 0;
  644. HTT_SRING_SETUP_RING_BASE_ADDR_LO_SET(*msg_word,
  645. srng_params.ring_base_paddr & 0xffffffff);
  646. /* word 2 */
  647. msg_word++;
  648. *msg_word = 0;
  649. HTT_SRING_SETUP_RING_BASE_ADDR_HI_SET(*msg_word,
  650. (uint64_t)srng_params.ring_base_paddr >> 32);
  651. /* word 3 */
  652. msg_word++;
  653. *msg_word = 0;
  654. HTT_SRING_SETUP_ENTRY_SIZE_SET(*msg_word, ring_entry_size);
  655. HTT_SRING_SETUP_RING_SIZE_SET(*msg_word,
  656. (ring_entry_size * srng_params.num_entries));
  657. dp_info("%s: entry_size %d", __func__, ring_entry_size);
  658. dp_info("%s: num_entries %d", __func__, srng_params.num_entries);
  659. dp_info("%s: ring_size %d", __func__,
  660. (ring_entry_size * srng_params.num_entries));
  661. if (htt_ring_type == HTT_SW_TO_HW_RING)
  662. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_LOOPCOUNT_DISABLE_SET(
  663. *msg_word, 1);
  664. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_MSI_SWAP_SET(*msg_word,
  665. !!(srng_params.flags & HAL_SRNG_MSI_SWAP));
  666. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_TLV_SWAP_SET(*msg_word,
  667. !!(srng_params.flags & HAL_SRNG_DATA_TLV_SWAP));
  668. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_HOST_FW_SWAP_SET(*msg_word,
  669. !!(srng_params.flags & HAL_SRNG_RING_PTR_SWAP));
  670. /* word 4 */
  671. msg_word++;
  672. *msg_word = 0;
  673. HTT_SRING_SETUP_HEAD_OFFSET32_REMOTE_BASE_ADDR_LO_SET(*msg_word,
  674. hp_addr & 0xffffffff);
  675. /* word 5 */
  676. msg_word++;
  677. *msg_word = 0;
  678. HTT_SRING_SETUP_HEAD_OFFSET32_REMOTE_BASE_ADDR_HI_SET(*msg_word,
  679. (uint64_t)hp_addr >> 32);
  680. /* word 6 */
  681. msg_word++;
  682. *msg_word = 0;
  683. HTT_SRING_SETUP_TAIL_OFFSET32_REMOTE_BASE_ADDR_LO_SET(*msg_word,
  684. tp_addr & 0xffffffff);
  685. /* word 7 */
  686. msg_word++;
  687. *msg_word = 0;
  688. HTT_SRING_SETUP_TAIL_OFFSET32_REMOTE_BASE_ADDR_HI_SET(*msg_word,
  689. (uint64_t)tp_addr >> 32);
  690. /* word 8 */
  691. msg_word++;
  692. *msg_word = 0;
  693. HTT_SRING_SETUP_RING_MSI_ADDR_LO_SET(*msg_word,
  694. srng_params.msi_addr & 0xffffffff);
  695. /* word 9 */
  696. msg_word++;
  697. *msg_word = 0;
  698. HTT_SRING_SETUP_RING_MSI_ADDR_HI_SET(*msg_word,
  699. (uint64_t)(srng_params.msi_addr) >> 32);
  700. /* word 10 */
  701. msg_word++;
  702. *msg_word = 0;
  703. HTT_SRING_SETUP_RING_MSI_DATA_SET(*msg_word,
  704. srng_params.msi_data);
  705. /* word 11 */
  706. msg_word++;
  707. *msg_word = 0;
  708. HTT_SRING_SETUP_INTR_BATCH_COUNTER_TH_SET(*msg_word,
  709. srng_params.intr_batch_cntr_thres_entries *
  710. ring_entry_size);
  711. HTT_SRING_SETUP_INTR_TIMER_TH_SET(*msg_word,
  712. srng_params.intr_timer_thres_us >> 3);
  713. /* word 12 */
  714. msg_word++;
  715. *msg_word = 0;
  716. if (srng_params.flags & HAL_SRNG_LOW_THRES_INTR_ENABLE) {
  717. /* TODO: Setting low threshold to 1/8th of ring size - see
  718. * if this needs to be configurable
  719. */
  720. HTT_SRING_SETUP_INTR_LOW_TH_SET(*msg_word,
  721. srng_params.low_threshold);
  722. }
  723. /* "response_required" field should be set if a HTT response message is
  724. * required after setting up the ring.
  725. */
  726. pkt = htt_htc_pkt_alloc(soc);
  727. if (!pkt)
  728. goto fail1;
  729. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  730. SET_HTC_PACKET_INFO_TX(
  731. &pkt->htc_pkt,
  732. dp_htt_h2t_send_complete_free_netbuf,
  733. qdf_nbuf_data(htt_msg),
  734. qdf_nbuf_len(htt_msg),
  735. soc->htc_endpoint,
  736. HTC_TX_PACKET_TAG_RUNTIME_PUT); /* tag for no FW response msg */
  737. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, htt_msg);
  738. DP_HTT_SEND_HTC_PKT(soc, pkt, HTT_H2T_MSG_TYPE_SRING_SETUP,
  739. htt_logger_bufp);
  740. return QDF_STATUS_SUCCESS;
  741. fail1:
  742. qdf_nbuf_free(htt_msg);
  743. fail0:
  744. return QDF_STATUS_E_FAILURE;
  745. }
  746. /*
  747. * htt_h2t_rx_ring_cfg() - Send SRNG packet and TLV filter
  748. * config message to target
  749. * @htt_soc: HTT SOC handle
  750. * @pdev_id: PDEV Id
  751. * @hal_srng: Opaque HAL SRNG pointer
  752. * @hal_ring_type: SRNG ring type
  753. * @ring_buf_size: SRNG buffer size
  754. * @htt_tlv_filter: Rx SRNG TLV and filter setting
  755. * Return: 0 on success; error code on failure
  756. */
  757. int htt_h2t_rx_ring_cfg(struct htt_soc *htt_soc, int pdev_id,
  758. hal_ring_handle_t hal_ring_hdl,
  759. int hal_ring_type, int ring_buf_size,
  760. struct htt_rx_ring_tlv_filter *htt_tlv_filter)
  761. {
  762. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  763. struct dp_htt_htc_pkt *pkt;
  764. qdf_nbuf_t htt_msg;
  765. uint32_t *msg_word;
  766. struct hal_srng_params srng_params;
  767. uint32_t htt_ring_type, htt_ring_id;
  768. uint32_t tlv_filter;
  769. uint8_t *htt_logger_bufp;
  770. htt_msg = qdf_nbuf_alloc(soc->osdev,
  771. HTT_MSG_BUF_SIZE(HTT_RX_RING_SELECTION_CFG_SZ),
  772. /* reserve room for the HTC header */
  773. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  774. if (!htt_msg)
  775. goto fail0;
  776. hal_get_srng_params(soc->hal_soc, hal_ring_hdl, &srng_params);
  777. switch (hal_ring_type) {
  778. case RXDMA_BUF:
  779. htt_ring_id = HTT_RXDMA_HOST_BUF_RING;
  780. htt_ring_type = HTT_SW_TO_HW_RING;
  781. break;
  782. case RXDMA_MONITOR_BUF:
  783. htt_ring_id = HTT_RXDMA_MONITOR_BUF_RING;
  784. htt_ring_type = HTT_SW_TO_HW_RING;
  785. break;
  786. case RXDMA_MONITOR_STATUS:
  787. htt_ring_id = HTT_RXDMA_MONITOR_STATUS_RING;
  788. htt_ring_type = HTT_SW_TO_HW_RING;
  789. break;
  790. case RXDMA_MONITOR_DST:
  791. htt_ring_id = HTT_RXDMA_MONITOR_DEST_RING;
  792. htt_ring_type = HTT_HW_TO_SW_RING;
  793. break;
  794. case RXDMA_MONITOR_DESC:
  795. htt_ring_id = HTT_RXDMA_MONITOR_DESC_RING;
  796. htt_ring_type = HTT_SW_TO_HW_RING;
  797. break;
  798. case RXDMA_DST:
  799. htt_ring_id = HTT_RXDMA_NON_MONITOR_DEST_RING;
  800. htt_ring_type = HTT_HW_TO_SW_RING;
  801. break;
  802. default:
  803. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  804. "%s: Ring currently not supported", __func__);
  805. goto fail1;
  806. }
  807. /*
  808. * Set the length of the message.
  809. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  810. * separately during the below call to qdf_nbuf_push_head.
  811. * The contribution from the HTC header is added separately inside HTC.
  812. */
  813. if (qdf_nbuf_put_tail(htt_msg, HTT_RX_RING_SELECTION_CFG_SZ) == NULL) {
  814. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  815. "%s: Failed to expand head for RX Ring Cfg msg",
  816. __func__);
  817. goto fail1; /* failure */
  818. }
  819. msg_word = (uint32_t *)qdf_nbuf_data(htt_msg);
  820. /* rewind beyond alignment pad to get to the HTC header reserved area */
  821. qdf_nbuf_push_head(htt_msg, HTC_HDR_ALIGNMENT_PADDING);
  822. /* word 0 */
  823. htt_logger_bufp = (uint8_t *)msg_word;
  824. *msg_word = 0;
  825. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_RX_RING_SELECTION_CFG);
  826. /*
  827. * pdev_id is indexed from 0 whereas mac_id is indexed from 1
  828. * SW_TO_SW and SW_TO_HW rings are unaffected by this
  829. */
  830. if (htt_ring_type == HTT_SW_TO_SW_RING ||
  831. htt_ring_type == HTT_SW_TO_HW_RING)
  832. HTT_RX_RING_SELECTION_CFG_PDEV_ID_SET(*msg_word,
  833. DP_SW2HW_MACID(pdev_id));
  834. /* TODO: Discuss with FW on changing this to unique ID and using
  835. * htt_ring_type to send the type of ring
  836. */
  837. HTT_RX_RING_SELECTION_CFG_RING_ID_SET(*msg_word, htt_ring_id);
  838. HTT_RX_RING_SELECTION_CFG_STATUS_TLV_SET(*msg_word,
  839. !!(srng_params.flags & HAL_SRNG_MSI_SWAP));
  840. HTT_RX_RING_SELECTION_CFG_PKT_TLV_SET(*msg_word,
  841. !!(srng_params.flags & HAL_SRNG_DATA_TLV_SWAP));
  842. HTT_RX_RING_SELECTION_CFG_RX_OFFSETS_VALID_SET(*msg_word,
  843. htt_tlv_filter->offset_valid);
  844. /* word 1 */
  845. msg_word++;
  846. *msg_word = 0;
  847. HTT_RX_RING_SELECTION_CFG_RING_BUFFER_SIZE_SET(*msg_word,
  848. ring_buf_size);
  849. /* word 2 */
  850. msg_word++;
  851. *msg_word = 0;
  852. if (htt_tlv_filter->enable_fp) {
  853. /* TYPE: MGMT */
  854. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  855. FP, MGMT, 0000,
  856. (htt_tlv_filter->fp_mgmt_filter &
  857. FILTER_MGMT_ASSOC_REQ) ? 1 : 0);
  858. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  859. FP, MGMT, 0001,
  860. (htt_tlv_filter->fp_mgmt_filter &
  861. FILTER_MGMT_ASSOC_RES) ? 1 : 0);
  862. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  863. FP, MGMT, 0010,
  864. (htt_tlv_filter->fp_mgmt_filter &
  865. FILTER_MGMT_REASSOC_REQ) ? 1 : 0);
  866. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  867. FP, MGMT, 0011,
  868. (htt_tlv_filter->fp_mgmt_filter &
  869. FILTER_MGMT_REASSOC_RES) ? 1 : 0);
  870. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  871. FP, MGMT, 0100,
  872. (htt_tlv_filter->fp_mgmt_filter &
  873. FILTER_MGMT_PROBE_REQ) ? 1 : 0);
  874. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  875. FP, MGMT, 0101,
  876. (htt_tlv_filter->fp_mgmt_filter &
  877. FILTER_MGMT_PROBE_RES) ? 1 : 0);
  878. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  879. FP, MGMT, 0110,
  880. (htt_tlv_filter->fp_mgmt_filter &
  881. FILTER_MGMT_TIM_ADVT) ? 1 : 0);
  882. /* reserved */
  883. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  884. MGMT, 0111,
  885. (htt_tlv_filter->fp_mgmt_filter &
  886. FILTER_MGMT_RESERVED_7) ? 1 : 0);
  887. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  888. FP, MGMT, 1000,
  889. (htt_tlv_filter->fp_mgmt_filter &
  890. FILTER_MGMT_BEACON) ? 1 : 0);
  891. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  892. FP, MGMT, 1001,
  893. (htt_tlv_filter->fp_mgmt_filter &
  894. FILTER_MGMT_ATIM) ? 1 : 0);
  895. }
  896. if (htt_tlv_filter->enable_md) {
  897. /* TYPE: MGMT */
  898. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  899. MD, MGMT, 0000,
  900. (htt_tlv_filter->md_mgmt_filter &
  901. FILTER_MGMT_ASSOC_REQ) ? 1 : 0);
  902. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  903. MD, MGMT, 0001,
  904. (htt_tlv_filter->md_mgmt_filter &
  905. FILTER_MGMT_ASSOC_RES) ? 1 : 0);
  906. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  907. MD, MGMT, 0010,
  908. (htt_tlv_filter->md_mgmt_filter &
  909. FILTER_MGMT_REASSOC_REQ) ? 1 : 0);
  910. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  911. MD, MGMT, 0011,
  912. (htt_tlv_filter->md_mgmt_filter &
  913. FILTER_MGMT_REASSOC_RES) ? 1 : 0);
  914. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  915. MD, MGMT, 0100,
  916. (htt_tlv_filter->md_mgmt_filter &
  917. FILTER_MGMT_PROBE_REQ) ? 1 : 0);
  918. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  919. MD, MGMT, 0101,
  920. (htt_tlv_filter->md_mgmt_filter &
  921. FILTER_MGMT_PROBE_RES) ? 1 : 0);
  922. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  923. MD, MGMT, 0110,
  924. (htt_tlv_filter->md_mgmt_filter &
  925. FILTER_MGMT_TIM_ADVT) ? 1 : 0);
  926. /* reserved */
  927. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  928. MGMT, 0111,
  929. (htt_tlv_filter->md_mgmt_filter &
  930. FILTER_MGMT_RESERVED_7) ? 1 : 0);
  931. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  932. MD, MGMT, 1000,
  933. (htt_tlv_filter->md_mgmt_filter &
  934. FILTER_MGMT_BEACON) ? 1 : 0);
  935. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  936. MD, MGMT, 1001,
  937. (htt_tlv_filter->md_mgmt_filter &
  938. FILTER_MGMT_ATIM) ? 1 : 0);
  939. }
  940. if (htt_tlv_filter->enable_mo) {
  941. /* TYPE: MGMT */
  942. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  943. MO, MGMT, 0000,
  944. (htt_tlv_filter->mo_mgmt_filter &
  945. FILTER_MGMT_ASSOC_REQ) ? 1 : 0);
  946. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  947. MO, MGMT, 0001,
  948. (htt_tlv_filter->mo_mgmt_filter &
  949. FILTER_MGMT_ASSOC_RES) ? 1 : 0);
  950. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  951. MO, MGMT, 0010,
  952. (htt_tlv_filter->mo_mgmt_filter &
  953. FILTER_MGMT_REASSOC_REQ) ? 1 : 0);
  954. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  955. MO, MGMT, 0011,
  956. (htt_tlv_filter->mo_mgmt_filter &
  957. FILTER_MGMT_REASSOC_RES) ? 1 : 0);
  958. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  959. MO, MGMT, 0100,
  960. (htt_tlv_filter->mo_mgmt_filter &
  961. FILTER_MGMT_PROBE_REQ) ? 1 : 0);
  962. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  963. MO, MGMT, 0101,
  964. (htt_tlv_filter->mo_mgmt_filter &
  965. FILTER_MGMT_PROBE_RES) ? 1 : 0);
  966. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  967. MO, MGMT, 0110,
  968. (htt_tlv_filter->mo_mgmt_filter &
  969. FILTER_MGMT_TIM_ADVT) ? 1 : 0);
  970. /* reserved */
  971. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  972. MGMT, 0111,
  973. (htt_tlv_filter->mo_mgmt_filter &
  974. FILTER_MGMT_RESERVED_7) ? 1 : 0);
  975. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  976. MO, MGMT, 1000,
  977. (htt_tlv_filter->mo_mgmt_filter &
  978. FILTER_MGMT_BEACON) ? 1 : 0);
  979. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0,
  980. MO, MGMT, 1001,
  981. (htt_tlv_filter->mo_mgmt_filter &
  982. FILTER_MGMT_ATIM) ? 1 : 0);
  983. }
  984. /* word 3 */
  985. msg_word++;
  986. *msg_word = 0;
  987. if (htt_tlv_filter->enable_fp) {
  988. /* TYPE: MGMT */
  989. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  990. FP, MGMT, 1010,
  991. (htt_tlv_filter->fp_mgmt_filter &
  992. FILTER_MGMT_DISASSOC) ? 1 : 0);
  993. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  994. FP, MGMT, 1011,
  995. (htt_tlv_filter->fp_mgmt_filter &
  996. FILTER_MGMT_AUTH) ? 1 : 0);
  997. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  998. FP, MGMT, 1100,
  999. (htt_tlv_filter->fp_mgmt_filter &
  1000. FILTER_MGMT_DEAUTH) ? 1 : 0);
  1001. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  1002. FP, MGMT, 1101,
  1003. (htt_tlv_filter->fp_mgmt_filter &
  1004. FILTER_MGMT_ACTION) ? 1 : 0);
  1005. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  1006. FP, MGMT, 1110,
  1007. (htt_tlv_filter->fp_mgmt_filter &
  1008. FILTER_MGMT_ACT_NO_ACK) ? 1 : 0);
  1009. /* reserved*/
  1010. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  1011. MGMT, 1111,
  1012. (htt_tlv_filter->fp_mgmt_filter &
  1013. FILTER_MGMT_RESERVED_15) ? 1 : 0);
  1014. }
  1015. if (htt_tlv_filter->enable_md) {
  1016. /* TYPE: MGMT */
  1017. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  1018. MD, MGMT, 1010,
  1019. (htt_tlv_filter->md_mgmt_filter &
  1020. FILTER_MGMT_DISASSOC) ? 1 : 0);
  1021. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  1022. MD, MGMT, 1011,
  1023. (htt_tlv_filter->md_mgmt_filter &
  1024. FILTER_MGMT_AUTH) ? 1 : 0);
  1025. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  1026. MD, MGMT, 1100,
  1027. (htt_tlv_filter->md_mgmt_filter &
  1028. FILTER_MGMT_DEAUTH) ? 1 : 0);
  1029. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  1030. MD, MGMT, 1101,
  1031. (htt_tlv_filter->md_mgmt_filter &
  1032. FILTER_MGMT_ACTION) ? 1 : 0);
  1033. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  1034. MD, MGMT, 1110,
  1035. (htt_tlv_filter->md_mgmt_filter &
  1036. FILTER_MGMT_ACT_NO_ACK) ? 1 : 0);
  1037. }
  1038. if (htt_tlv_filter->enable_mo) {
  1039. /* TYPE: MGMT */
  1040. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  1041. MO, MGMT, 1010,
  1042. (htt_tlv_filter->mo_mgmt_filter &
  1043. FILTER_MGMT_DISASSOC) ? 1 : 0);
  1044. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  1045. MO, MGMT, 1011,
  1046. (htt_tlv_filter->mo_mgmt_filter &
  1047. FILTER_MGMT_AUTH) ? 1 : 0);
  1048. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  1049. MO, MGMT, 1100,
  1050. (htt_tlv_filter->mo_mgmt_filter &
  1051. FILTER_MGMT_DEAUTH) ? 1 : 0);
  1052. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  1053. MO, MGMT, 1101,
  1054. (htt_tlv_filter->mo_mgmt_filter &
  1055. FILTER_MGMT_ACTION) ? 1 : 0);
  1056. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1,
  1057. MO, MGMT, 1110,
  1058. (htt_tlv_filter->mo_mgmt_filter &
  1059. FILTER_MGMT_ACT_NO_ACK) ? 1 : 0);
  1060. /* reserved*/
  1061. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  1062. MGMT, 1111,
  1063. (htt_tlv_filter->mo_mgmt_filter &
  1064. FILTER_MGMT_RESERVED_15) ? 1 : 0);
  1065. }
  1066. /* word 4 */
  1067. msg_word++;
  1068. *msg_word = 0;
  1069. if (htt_tlv_filter->enable_fp) {
  1070. /* TYPE: CTRL */
  1071. /* reserved */
  1072. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  1073. CTRL, 0000,
  1074. (htt_tlv_filter->fp_ctrl_filter &
  1075. FILTER_CTRL_RESERVED_1) ? 1 : 0);
  1076. /* reserved */
  1077. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  1078. CTRL, 0001,
  1079. (htt_tlv_filter->fp_ctrl_filter &
  1080. FILTER_CTRL_RESERVED_2) ? 1 : 0);
  1081. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  1082. CTRL, 0010,
  1083. (htt_tlv_filter->fp_ctrl_filter &
  1084. FILTER_CTRL_TRIGGER) ? 1 : 0);
  1085. /* reserved */
  1086. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  1087. CTRL, 0011,
  1088. (htt_tlv_filter->fp_ctrl_filter &
  1089. FILTER_CTRL_RESERVED_4) ? 1 : 0);
  1090. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  1091. CTRL, 0100,
  1092. (htt_tlv_filter->fp_ctrl_filter &
  1093. FILTER_CTRL_BF_REP_POLL) ? 1 : 0);
  1094. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  1095. CTRL, 0101,
  1096. (htt_tlv_filter->fp_ctrl_filter &
  1097. FILTER_CTRL_VHT_NDP) ? 1 : 0);
  1098. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  1099. CTRL, 0110,
  1100. (htt_tlv_filter->fp_ctrl_filter &
  1101. FILTER_CTRL_FRAME_EXT) ? 1 : 0);
  1102. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  1103. CTRL, 0111,
  1104. (htt_tlv_filter->fp_ctrl_filter &
  1105. FILTER_CTRL_CTRLWRAP) ? 1 : 0);
  1106. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  1107. CTRL, 1000,
  1108. (htt_tlv_filter->fp_ctrl_filter &
  1109. FILTER_CTRL_BA_REQ) ? 1 : 0);
  1110. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  1111. CTRL, 1001,
  1112. (htt_tlv_filter->fp_ctrl_filter &
  1113. FILTER_CTRL_BA) ? 1 : 0);
  1114. }
  1115. if (htt_tlv_filter->enable_md) {
  1116. /* TYPE: CTRL */
  1117. /* reserved */
  1118. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  1119. CTRL, 0000,
  1120. (htt_tlv_filter->md_ctrl_filter &
  1121. FILTER_CTRL_RESERVED_1) ? 1 : 0);
  1122. /* reserved */
  1123. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  1124. CTRL, 0001,
  1125. (htt_tlv_filter->md_ctrl_filter &
  1126. FILTER_CTRL_RESERVED_2) ? 1 : 0);
  1127. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  1128. CTRL, 0010,
  1129. (htt_tlv_filter->md_ctrl_filter &
  1130. FILTER_CTRL_TRIGGER) ? 1 : 0);
  1131. /* reserved */
  1132. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  1133. CTRL, 0011,
  1134. (htt_tlv_filter->md_ctrl_filter &
  1135. FILTER_CTRL_RESERVED_4) ? 1 : 0);
  1136. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  1137. CTRL, 0100,
  1138. (htt_tlv_filter->md_ctrl_filter &
  1139. FILTER_CTRL_BF_REP_POLL) ? 1 : 0);
  1140. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  1141. CTRL, 0101,
  1142. (htt_tlv_filter->md_ctrl_filter &
  1143. FILTER_CTRL_VHT_NDP) ? 1 : 0);
  1144. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  1145. CTRL, 0110,
  1146. (htt_tlv_filter->md_ctrl_filter &
  1147. FILTER_CTRL_FRAME_EXT) ? 1 : 0);
  1148. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  1149. CTRL, 0111,
  1150. (htt_tlv_filter->md_ctrl_filter &
  1151. FILTER_CTRL_CTRLWRAP) ? 1 : 0);
  1152. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  1153. CTRL, 1000,
  1154. (htt_tlv_filter->md_ctrl_filter &
  1155. FILTER_CTRL_BA_REQ) ? 1 : 0);
  1156. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  1157. CTRL, 1001,
  1158. (htt_tlv_filter->md_ctrl_filter &
  1159. FILTER_CTRL_BA) ? 1 : 0);
  1160. }
  1161. if (htt_tlv_filter->enable_mo) {
  1162. /* TYPE: CTRL */
  1163. /* reserved */
  1164. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  1165. CTRL, 0000,
  1166. (htt_tlv_filter->mo_ctrl_filter &
  1167. FILTER_CTRL_RESERVED_1) ? 1 : 0);
  1168. /* reserved */
  1169. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  1170. CTRL, 0001,
  1171. (htt_tlv_filter->mo_ctrl_filter &
  1172. FILTER_CTRL_RESERVED_2) ? 1 : 0);
  1173. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  1174. CTRL, 0010,
  1175. (htt_tlv_filter->mo_ctrl_filter &
  1176. FILTER_CTRL_TRIGGER) ? 1 : 0);
  1177. /* reserved */
  1178. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  1179. CTRL, 0011,
  1180. (htt_tlv_filter->mo_ctrl_filter &
  1181. FILTER_CTRL_RESERVED_4) ? 1 : 0);
  1182. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  1183. CTRL, 0100,
  1184. (htt_tlv_filter->mo_ctrl_filter &
  1185. FILTER_CTRL_BF_REP_POLL) ? 1 : 0);
  1186. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  1187. CTRL, 0101,
  1188. (htt_tlv_filter->mo_ctrl_filter &
  1189. FILTER_CTRL_VHT_NDP) ? 1 : 0);
  1190. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  1191. CTRL, 0110,
  1192. (htt_tlv_filter->mo_ctrl_filter &
  1193. FILTER_CTRL_FRAME_EXT) ? 1 : 0);
  1194. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  1195. CTRL, 0111,
  1196. (htt_tlv_filter->mo_ctrl_filter &
  1197. FILTER_CTRL_CTRLWRAP) ? 1 : 0);
  1198. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  1199. CTRL, 1000,
  1200. (htt_tlv_filter->mo_ctrl_filter &
  1201. FILTER_CTRL_BA_REQ) ? 1 : 0);
  1202. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  1203. CTRL, 1001,
  1204. (htt_tlv_filter->mo_ctrl_filter &
  1205. FILTER_CTRL_BA) ? 1 : 0);
  1206. }
  1207. /* word 5 */
  1208. msg_word++;
  1209. *msg_word = 0;
  1210. if (htt_tlv_filter->enable_fp) {
  1211. /* TYPE: CTRL */
  1212. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  1213. CTRL, 1010,
  1214. (htt_tlv_filter->fp_ctrl_filter &
  1215. FILTER_CTRL_PSPOLL) ? 1 : 0);
  1216. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  1217. CTRL, 1011,
  1218. (htt_tlv_filter->fp_ctrl_filter &
  1219. FILTER_CTRL_RTS) ? 1 : 0);
  1220. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  1221. CTRL, 1100,
  1222. (htt_tlv_filter->fp_ctrl_filter &
  1223. FILTER_CTRL_CTS) ? 1 : 0);
  1224. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  1225. CTRL, 1101,
  1226. (htt_tlv_filter->fp_ctrl_filter &
  1227. FILTER_CTRL_ACK) ? 1 : 0);
  1228. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  1229. CTRL, 1110,
  1230. (htt_tlv_filter->fp_ctrl_filter &
  1231. FILTER_CTRL_CFEND) ? 1 : 0);
  1232. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  1233. CTRL, 1111,
  1234. (htt_tlv_filter->fp_ctrl_filter &
  1235. FILTER_CTRL_CFEND_CFACK) ? 1 : 0);
  1236. /* TYPE: DATA */
  1237. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  1238. DATA, MCAST,
  1239. (htt_tlv_filter->fp_data_filter &
  1240. FILTER_DATA_MCAST) ? 1 : 0);
  1241. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  1242. DATA, UCAST,
  1243. (htt_tlv_filter->fp_data_filter &
  1244. FILTER_DATA_UCAST) ? 1 : 0);
  1245. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  1246. DATA, NULL,
  1247. (htt_tlv_filter->fp_data_filter &
  1248. FILTER_DATA_NULL) ? 1 : 0);
  1249. }
  1250. if (htt_tlv_filter->enable_md) {
  1251. /* TYPE: CTRL */
  1252. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  1253. CTRL, 1010,
  1254. (htt_tlv_filter->md_ctrl_filter &
  1255. FILTER_CTRL_PSPOLL) ? 1 : 0);
  1256. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  1257. CTRL, 1011,
  1258. (htt_tlv_filter->md_ctrl_filter &
  1259. FILTER_CTRL_RTS) ? 1 : 0);
  1260. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  1261. CTRL, 1100,
  1262. (htt_tlv_filter->md_ctrl_filter &
  1263. FILTER_CTRL_CTS) ? 1 : 0);
  1264. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  1265. CTRL, 1101,
  1266. (htt_tlv_filter->md_ctrl_filter &
  1267. FILTER_CTRL_ACK) ? 1 : 0);
  1268. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  1269. CTRL, 1110,
  1270. (htt_tlv_filter->md_ctrl_filter &
  1271. FILTER_CTRL_CFEND) ? 1 : 0);
  1272. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  1273. CTRL, 1111,
  1274. (htt_tlv_filter->md_ctrl_filter &
  1275. FILTER_CTRL_CFEND_CFACK) ? 1 : 0);
  1276. /* TYPE: DATA */
  1277. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  1278. DATA, MCAST,
  1279. (htt_tlv_filter->md_data_filter &
  1280. FILTER_DATA_MCAST) ? 1 : 0);
  1281. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  1282. DATA, UCAST,
  1283. (htt_tlv_filter->md_data_filter &
  1284. FILTER_DATA_UCAST) ? 1 : 0);
  1285. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  1286. DATA, NULL,
  1287. (htt_tlv_filter->md_data_filter &
  1288. FILTER_DATA_NULL) ? 1 : 0);
  1289. }
  1290. if (htt_tlv_filter->enable_mo) {
  1291. /* TYPE: CTRL */
  1292. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  1293. CTRL, 1010,
  1294. (htt_tlv_filter->mo_ctrl_filter &
  1295. FILTER_CTRL_PSPOLL) ? 1 : 0);
  1296. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  1297. CTRL, 1011,
  1298. (htt_tlv_filter->mo_ctrl_filter &
  1299. FILTER_CTRL_RTS) ? 1 : 0);
  1300. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  1301. CTRL, 1100,
  1302. (htt_tlv_filter->mo_ctrl_filter &
  1303. FILTER_CTRL_CTS) ? 1 : 0);
  1304. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  1305. CTRL, 1101,
  1306. (htt_tlv_filter->mo_ctrl_filter &
  1307. FILTER_CTRL_ACK) ? 1 : 0);
  1308. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  1309. CTRL, 1110,
  1310. (htt_tlv_filter->mo_ctrl_filter &
  1311. FILTER_CTRL_CFEND) ? 1 : 0);
  1312. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  1313. CTRL, 1111,
  1314. (htt_tlv_filter->mo_ctrl_filter &
  1315. FILTER_CTRL_CFEND_CFACK) ? 1 : 0);
  1316. /* TYPE: DATA */
  1317. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  1318. DATA, MCAST,
  1319. (htt_tlv_filter->mo_data_filter &
  1320. FILTER_DATA_MCAST) ? 1 : 0);
  1321. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  1322. DATA, UCAST,
  1323. (htt_tlv_filter->mo_data_filter &
  1324. FILTER_DATA_UCAST) ? 1 : 0);
  1325. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  1326. DATA, NULL,
  1327. (htt_tlv_filter->mo_data_filter &
  1328. FILTER_DATA_NULL) ? 1 : 0);
  1329. }
  1330. /* word 6 */
  1331. msg_word++;
  1332. *msg_word = 0;
  1333. tlv_filter = 0;
  1334. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MPDU_START,
  1335. htt_tlv_filter->mpdu_start);
  1336. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MSDU_START,
  1337. htt_tlv_filter->msdu_start);
  1338. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PACKET,
  1339. htt_tlv_filter->packet);
  1340. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MSDU_END,
  1341. htt_tlv_filter->msdu_end);
  1342. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MPDU_END,
  1343. htt_tlv_filter->mpdu_end);
  1344. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PACKET_HEADER,
  1345. htt_tlv_filter->packet_header);
  1346. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, ATTENTION,
  1347. htt_tlv_filter->attention);
  1348. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_START,
  1349. htt_tlv_filter->ppdu_start);
  1350. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_END,
  1351. htt_tlv_filter->ppdu_end);
  1352. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_END_USER_STATS,
  1353. htt_tlv_filter->ppdu_end_user_stats);
  1354. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter,
  1355. PPDU_END_USER_STATS_EXT,
  1356. htt_tlv_filter->ppdu_end_user_stats_ext);
  1357. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_END_STATUS_DONE,
  1358. htt_tlv_filter->ppdu_end_status_done);
  1359. /* RESERVED bit maps to header_per_msdu in htt_tlv_filter*/
  1360. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, RESERVED,
  1361. htt_tlv_filter->header_per_msdu);
  1362. HTT_RX_RING_SELECTION_CFG_TLV_FILTER_IN_FLAG_SET(*msg_word, tlv_filter);
  1363. msg_word++;
  1364. *msg_word = 0;
  1365. if (htt_tlv_filter->offset_valid) {
  1366. HTT_RX_RING_SELECTION_CFG_RX_PACKET_OFFSET_SET(*msg_word,
  1367. htt_tlv_filter->rx_packet_offset);
  1368. HTT_RX_RING_SELECTION_CFG_RX_HEADER_OFFSET_SET(*msg_word,
  1369. htt_tlv_filter->rx_header_offset);
  1370. msg_word++;
  1371. *msg_word = 0;
  1372. HTT_RX_RING_SELECTION_CFG_RX_MPDU_END_OFFSET_SET(*msg_word,
  1373. htt_tlv_filter->rx_mpdu_end_offset);
  1374. HTT_RX_RING_SELECTION_CFG_RX_MPDU_START_OFFSET_SET(*msg_word,
  1375. htt_tlv_filter->rx_mpdu_start_offset);
  1376. msg_word++;
  1377. *msg_word = 0;
  1378. HTT_RX_RING_SELECTION_CFG_RX_MSDU_END_OFFSET_SET(*msg_word,
  1379. htt_tlv_filter->rx_msdu_end_offset);
  1380. HTT_RX_RING_SELECTION_CFG_RX_MSDU_START_OFFSET_SET(*msg_word,
  1381. htt_tlv_filter->rx_msdu_start_offset);
  1382. msg_word++;
  1383. *msg_word = 0;
  1384. HTT_RX_RING_SELECTION_CFG_RX_ATTENTION_OFFSET_SET(*msg_word,
  1385. htt_tlv_filter->rx_attn_offset);
  1386. }
  1387. /* "response_required" field should be set if a HTT response message is
  1388. * required after setting up the ring.
  1389. */
  1390. pkt = htt_htc_pkt_alloc(soc);
  1391. if (!pkt)
  1392. goto fail1;
  1393. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  1394. SET_HTC_PACKET_INFO_TX(
  1395. &pkt->htc_pkt,
  1396. dp_htt_h2t_send_complete_free_netbuf,
  1397. qdf_nbuf_data(htt_msg),
  1398. qdf_nbuf_len(htt_msg),
  1399. soc->htc_endpoint,
  1400. 1); /* tag - not relevant here */
  1401. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, htt_msg);
  1402. DP_HTT_SEND_HTC_PKT(soc, pkt, HTT_H2T_MSG_TYPE_RX_RING_SELECTION_CFG,
  1403. htt_logger_bufp);
  1404. return QDF_STATUS_SUCCESS;
  1405. fail1:
  1406. qdf_nbuf_free(htt_msg);
  1407. fail0:
  1408. return QDF_STATUS_E_FAILURE;
  1409. }
  1410. #if defined(HTT_STATS_ENABLE)
  1411. static inline QDF_STATUS dp_send_htt_stat_resp(struct htt_stats_context *htt_stats,
  1412. struct dp_soc *soc, qdf_nbuf_t htt_msg)
  1413. {
  1414. uint32_t pdev_id;
  1415. uint32_t *msg_word = NULL;
  1416. uint32_t msg_remain_len = 0;
  1417. msg_word = (uint32_t *) qdf_nbuf_data(htt_msg);
  1418. /*COOKIE MSB*/
  1419. pdev_id = *(msg_word + 2) & HTT_PID_BIT_MASK;
  1420. /* stats message length + 16 size of HTT header*/
  1421. msg_remain_len = qdf_min(htt_stats->msg_len + 16,
  1422. (uint32_t)DP_EXT_MSG_LENGTH);
  1423. dp_wdi_event_handler(WDI_EVENT_HTT_STATS, soc,
  1424. msg_word, msg_remain_len,
  1425. WDI_NO_VAL, pdev_id);
  1426. if (htt_stats->msg_len >= DP_EXT_MSG_LENGTH) {
  1427. htt_stats->msg_len -= DP_EXT_MSG_LENGTH;
  1428. }
  1429. /* Need to be freed here as WDI handler will
  1430. * make a copy of pkt to send data to application
  1431. */
  1432. qdf_nbuf_free(htt_msg);
  1433. return QDF_STATUS_SUCCESS;
  1434. }
  1435. #else
  1436. static inline QDF_STATUS
  1437. dp_send_htt_stat_resp(struct htt_stats_context *htt_stats,
  1438. struct dp_soc *soc, qdf_nbuf_t htt_msg)
  1439. {
  1440. return QDF_STATUS_E_NOSUPPORT;
  1441. }
  1442. #endif
  1443. /**
  1444. * dp_process_htt_stat_msg(): Process the list of buffers of HTT EXT stats
  1445. * @htt_stats: htt stats info
  1446. *
  1447. * The FW sends the HTT EXT STATS as a stream of T2H messages. Each T2H message
  1448. * contains sub messages which are identified by a TLV header.
  1449. * In this function we will process the stream of T2H messages and read all the
  1450. * TLV contained in the message.
  1451. *
  1452. * THe following cases have been taken care of
  1453. * Case 1: When the tlv_remain_length <= msg_remain_length of HTT MSG buffer
  1454. * In this case the buffer will contain multiple tlvs.
  1455. * Case 2: When the tlv_remain_length > msg_remain_length of HTT MSG buffer.
  1456. * Only one tlv will be contained in the HTT message and this tag
  1457. * will extend onto the next buffer.
  1458. * Case 3: When the buffer is the continuation of the previous message
  1459. * Case 4: tlv length is 0. which will indicate the end of message
  1460. *
  1461. * return: void
  1462. */
  1463. static inline void dp_process_htt_stat_msg(struct htt_stats_context *htt_stats,
  1464. struct dp_soc *soc)
  1465. {
  1466. htt_tlv_tag_t tlv_type = 0xff;
  1467. qdf_nbuf_t htt_msg = NULL;
  1468. uint32_t *msg_word;
  1469. uint8_t *tlv_buf_head = NULL;
  1470. uint8_t *tlv_buf_tail = NULL;
  1471. uint32_t msg_remain_len = 0;
  1472. uint32_t tlv_remain_len = 0;
  1473. uint32_t *tlv_start;
  1474. int cookie_val;
  1475. int cookie_msb;
  1476. int pdev_id;
  1477. bool copy_stats = false;
  1478. struct dp_pdev *pdev;
  1479. /* Process node in the HTT message queue */
  1480. while ((htt_msg = qdf_nbuf_queue_remove(&htt_stats->msg))
  1481. != NULL) {
  1482. msg_word = (uint32_t *) qdf_nbuf_data(htt_msg);
  1483. cookie_val = *(msg_word + 1);
  1484. htt_stats->msg_len = HTT_T2H_EXT_STATS_CONF_TLV_LENGTH_GET(
  1485. *(msg_word +
  1486. HTT_T2H_EXT_STATS_TLV_START_OFFSET));
  1487. if (cookie_val) {
  1488. if (dp_send_htt_stat_resp(htt_stats, soc, htt_msg)
  1489. == QDF_STATUS_SUCCESS) {
  1490. continue;
  1491. }
  1492. }
  1493. cookie_msb = *(msg_word + 2);
  1494. pdev_id = *(msg_word + 2) & HTT_PID_BIT_MASK;
  1495. pdev = soc->pdev_list[pdev_id];
  1496. if (cookie_msb >> 2) {
  1497. copy_stats = true;
  1498. }
  1499. /* read 5th word */
  1500. msg_word = msg_word + 4;
  1501. msg_remain_len = qdf_min(htt_stats->msg_len,
  1502. (uint32_t) DP_EXT_MSG_LENGTH);
  1503. /* Keep processing the node till node length is 0 */
  1504. while (msg_remain_len) {
  1505. /*
  1506. * if message is not a continuation of previous message
  1507. * read the tlv type and tlv length
  1508. */
  1509. if (!tlv_buf_head) {
  1510. tlv_type = HTT_STATS_TLV_TAG_GET(
  1511. *msg_word);
  1512. tlv_remain_len = HTT_STATS_TLV_LENGTH_GET(
  1513. *msg_word);
  1514. }
  1515. if (tlv_remain_len == 0) {
  1516. msg_remain_len = 0;
  1517. if (tlv_buf_head) {
  1518. qdf_mem_free(tlv_buf_head);
  1519. tlv_buf_head = NULL;
  1520. tlv_buf_tail = NULL;
  1521. }
  1522. goto error;
  1523. }
  1524. if (!tlv_buf_head)
  1525. tlv_remain_len += HTT_TLV_HDR_LEN;
  1526. if ((tlv_remain_len <= msg_remain_len)) {
  1527. /* Case 3 */
  1528. if (tlv_buf_head) {
  1529. qdf_mem_copy(tlv_buf_tail,
  1530. (uint8_t *)msg_word,
  1531. tlv_remain_len);
  1532. tlv_start = (uint32_t *)tlv_buf_head;
  1533. } else {
  1534. /* Case 1 */
  1535. tlv_start = msg_word;
  1536. }
  1537. if (copy_stats)
  1538. dp_htt_stats_copy_tag(pdev, tlv_type, tlv_start);
  1539. else
  1540. dp_htt_stats_print_tag(tlv_type, tlv_start);
  1541. if (tlv_type == HTT_STATS_PEER_DETAILS_TAG ||
  1542. tlv_type == HTT_STATS_PEER_STATS_CMN_TAG)
  1543. dp_peer_update_inactive_time(pdev,
  1544. tlv_type,
  1545. tlv_start);
  1546. msg_remain_len -= tlv_remain_len;
  1547. msg_word = (uint32_t *)
  1548. (((uint8_t *)msg_word) +
  1549. tlv_remain_len);
  1550. tlv_remain_len = 0;
  1551. if (tlv_buf_head) {
  1552. qdf_mem_free(tlv_buf_head);
  1553. tlv_buf_head = NULL;
  1554. tlv_buf_tail = NULL;
  1555. }
  1556. } else { /* tlv_remain_len > msg_remain_len */
  1557. /* Case 2 & 3 */
  1558. if (!tlv_buf_head) {
  1559. tlv_buf_head = qdf_mem_malloc(
  1560. tlv_remain_len);
  1561. if (!tlv_buf_head) {
  1562. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1563. QDF_TRACE_LEVEL_ERROR,
  1564. "Alloc failed");
  1565. goto error;
  1566. }
  1567. tlv_buf_tail = tlv_buf_head;
  1568. }
  1569. qdf_mem_copy(tlv_buf_tail, (uint8_t *)msg_word,
  1570. msg_remain_len);
  1571. tlv_remain_len -= msg_remain_len;
  1572. tlv_buf_tail += msg_remain_len;
  1573. }
  1574. }
  1575. if (htt_stats->msg_len >= DP_EXT_MSG_LENGTH) {
  1576. htt_stats->msg_len -= DP_EXT_MSG_LENGTH;
  1577. }
  1578. qdf_nbuf_free(htt_msg);
  1579. }
  1580. return;
  1581. error:
  1582. qdf_nbuf_free(htt_msg);
  1583. while ((htt_msg = qdf_nbuf_queue_remove(&htt_stats->msg))
  1584. != NULL)
  1585. qdf_nbuf_free(htt_msg);
  1586. }
  1587. void htt_t2h_stats_handler(void *context)
  1588. {
  1589. struct dp_soc *soc = (struct dp_soc *)context;
  1590. struct htt_stats_context htt_stats;
  1591. uint32_t *msg_word;
  1592. qdf_nbuf_t htt_msg = NULL;
  1593. uint8_t done;
  1594. uint8_t rem_stats;
  1595. if (!soc || !qdf_atomic_read(&soc->cmn_init_done)) {
  1596. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1597. "soc: 0x%pK, init_done: %d", soc,
  1598. qdf_atomic_read(&soc->cmn_init_done));
  1599. return;
  1600. }
  1601. qdf_mem_zero(&htt_stats, sizeof(htt_stats));
  1602. qdf_nbuf_queue_init(&htt_stats.msg);
  1603. /* pull one completed stats from soc->htt_stats_msg and process */
  1604. qdf_spin_lock_bh(&soc->htt_stats.lock);
  1605. if (!soc->htt_stats.num_stats) {
  1606. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1607. return;
  1608. }
  1609. while ((htt_msg = qdf_nbuf_queue_remove(&soc->htt_stats.msg)) != NULL) {
  1610. msg_word = (uint32_t *) qdf_nbuf_data(htt_msg);
  1611. msg_word = msg_word + HTT_T2H_EXT_STATS_TLV_START_OFFSET;
  1612. done = HTT_T2H_EXT_STATS_CONF_TLV_DONE_GET(*msg_word);
  1613. qdf_nbuf_queue_add(&htt_stats.msg, htt_msg);
  1614. /*
  1615. * Done bit signifies that this is the last T2H buffer in the
  1616. * stream of HTT EXT STATS message
  1617. */
  1618. if (done)
  1619. break;
  1620. }
  1621. rem_stats = --soc->htt_stats.num_stats;
  1622. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1623. dp_process_htt_stat_msg(&htt_stats, soc);
  1624. /* If there are more stats to process, schedule stats work again */
  1625. if (rem_stats)
  1626. qdf_sched_work(0, &soc->htt_stats.work);
  1627. }
  1628. /*
  1629. * dp_get_ppdu_info_user_index: Find and allocate a per-user descriptor for a PPDU,
  1630. * if a new peer id arrives in a PPDU
  1631. * pdev: DP pdev handle
  1632. * @peer_id : peer unique identifier
  1633. * @ppdu_info: per ppdu tlv structure
  1634. *
  1635. * return:user index to be populated
  1636. */
  1637. #ifdef FEATURE_PERPKT_INFO
  1638. static uint8_t dp_get_ppdu_info_user_index(struct dp_pdev *pdev,
  1639. uint16_t peer_id,
  1640. struct ppdu_info *ppdu_info)
  1641. {
  1642. uint8_t user_index = 0;
  1643. struct cdp_tx_completion_ppdu *ppdu_desc;
  1644. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1645. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  1646. while ((user_index + 1) <= ppdu_info->last_user) {
  1647. ppdu_user_desc = &ppdu_desc->user[user_index];
  1648. if (ppdu_user_desc->peer_id != peer_id) {
  1649. user_index++;
  1650. continue;
  1651. } else {
  1652. /* Max users possible is 8 so user array index should
  1653. * not exceed 7
  1654. */
  1655. qdf_assert_always(user_index <= CDP_MU_MAX_USER_INDEX);
  1656. return user_index;
  1657. }
  1658. }
  1659. ppdu_info->last_user++;
  1660. /* Max users possible is 8 so last user should not exceed 8 */
  1661. qdf_assert_always(ppdu_info->last_user <= CDP_MU_MAX_USERS);
  1662. return ppdu_info->last_user - 1;
  1663. }
  1664. /*
  1665. * dp_process_ppdu_stats_common_tlv: Process htt_ppdu_stats_common_tlv
  1666. * pdev: DP pdev handle
  1667. * @tag_buf: buffer containing the tlv htt_ppdu_stats_common_tlv
  1668. * @ppdu_info: per ppdu tlv structure
  1669. *
  1670. * return:void
  1671. */
  1672. static void dp_process_ppdu_stats_common_tlv(struct dp_pdev *pdev,
  1673. uint32_t *tag_buf, struct ppdu_info *ppdu_info)
  1674. {
  1675. uint16_t frame_type;
  1676. uint16_t frame_ctrl;
  1677. uint16_t freq;
  1678. struct dp_soc *soc = NULL;
  1679. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  1680. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  1681. tag_buf += 2;
  1682. ppdu_info->sched_cmdid =
  1683. HTT_PPDU_STATS_COMMON_TLV_SCH_CMDID_GET(*tag_buf);
  1684. ppdu_desc->num_users =
  1685. HTT_PPDU_STATS_COMMON_TLV_NUM_USERS_GET(*tag_buf);
  1686. tag_buf++;
  1687. frame_type = HTT_PPDU_STATS_COMMON_TLV_FRM_TYPE_GET(*tag_buf);
  1688. frame_ctrl = ppdu_desc->frame_ctrl;
  1689. switch (frame_type) {
  1690. case HTT_STATS_FTYPE_TIDQ_DATA_SU:
  1691. case HTT_STATS_FTYPE_TIDQ_DATA_MU:
  1692. /*
  1693. * for management packet, frame type come as DATA_SU
  1694. * need to check frame_ctrl before setting frame_type
  1695. */
  1696. if (HTT_GET_FRAME_CTRL_TYPE(frame_ctrl) <= FRAME_CTRL_TYPE_CTRL)
  1697. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  1698. else
  1699. ppdu_desc->frame_type = CDP_PPDU_FTYPE_DATA;
  1700. break;
  1701. case HTT_STATS_FTYPE_SGEN_MU_BAR:
  1702. case HTT_STATS_FTYPE_SGEN_BAR:
  1703. ppdu_desc->frame_type = CDP_PPDU_FTYPE_BAR;
  1704. break;
  1705. default:
  1706. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  1707. break;
  1708. }
  1709. tag_buf += 2;
  1710. ppdu_desc->tx_duration = *tag_buf;
  1711. tag_buf += 3;
  1712. ppdu_desc->ppdu_start_timestamp = *tag_buf;
  1713. ppdu_desc->ppdu_end_timestamp = ppdu_desc->ppdu_start_timestamp +
  1714. ppdu_desc->tx_duration;
  1715. /* Ack time stamp is same as end time stamp*/
  1716. ppdu_desc->ack_timestamp = ppdu_desc->ppdu_end_timestamp;
  1717. tag_buf++;
  1718. freq = HTT_PPDU_STATS_COMMON_TLV_CHAN_MHZ_GET(*tag_buf);
  1719. if (freq != ppdu_desc->channel) {
  1720. soc = pdev->soc;
  1721. ppdu_desc->channel = freq;
  1722. if (soc && soc->cdp_soc.ol_ops->freq_to_channel)
  1723. pdev->operating_channel =
  1724. soc->cdp_soc.ol_ops->freq_to_channel(pdev->ctrl_pdev, freq);
  1725. }
  1726. ppdu_desc->phy_mode = HTT_PPDU_STATS_COMMON_TLV_PHY_MODE_GET(*tag_buf);
  1727. }
  1728. /*
  1729. * dp_process_ppdu_stats_user_common_tlv: Process ppdu_stats_user_common
  1730. * @tag_buf: buffer containing the tlv htt_ppdu_stats_user_common_tlv
  1731. * @ppdu_info: per ppdu tlv structure
  1732. *
  1733. * return:void
  1734. */
  1735. static void dp_process_ppdu_stats_user_common_tlv(
  1736. struct dp_pdev *pdev, uint32_t *tag_buf,
  1737. struct ppdu_info *ppdu_info)
  1738. {
  1739. uint16_t peer_id;
  1740. struct cdp_tx_completion_ppdu *ppdu_desc;
  1741. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1742. uint8_t curr_user_index = 0;
  1743. ppdu_desc =
  1744. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  1745. tag_buf++;
  1746. peer_id = HTT_PPDU_STATS_USER_RATE_TLV_SW_PEER_ID_GET(*tag_buf);
  1747. curr_user_index =
  1748. dp_get_ppdu_info_user_index(pdev,
  1749. peer_id, ppdu_info);
  1750. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1751. if (peer_id == DP_SCAN_PEER_ID) {
  1752. ppdu_desc->vdev_id =
  1753. HTT_PPDU_STATS_USER_COMMON_TLV_VAP_ID_GET(*tag_buf);
  1754. } else {
  1755. if (!dp_peer_find_by_id_valid(pdev->soc, peer_id))
  1756. return;
  1757. }
  1758. ppdu_user_desc->peer_id = peer_id;
  1759. tag_buf++;
  1760. if (HTT_PPDU_STATS_USER_COMMON_TLV_DELAYED_BA_GET(*tag_buf)) {
  1761. ppdu_user_desc->delayed_ba = 1;
  1762. }
  1763. if (HTT_PPDU_STATS_USER_COMMON_TLV_MCAST_GET(*tag_buf)) {
  1764. ppdu_user_desc->is_mcast = true;
  1765. ppdu_user_desc->mpdu_tried_mcast =
  1766. HTT_PPDU_STATS_USER_COMMON_TLV_MPDUS_TRIED_GET(*tag_buf);
  1767. ppdu_user_desc->num_mpdu = ppdu_user_desc->mpdu_tried_mcast;
  1768. } else {
  1769. ppdu_user_desc->mpdu_tried_ucast =
  1770. HTT_PPDU_STATS_USER_COMMON_TLV_MPDUS_TRIED_GET(*tag_buf);
  1771. }
  1772. tag_buf++;
  1773. ppdu_user_desc->qos_ctrl =
  1774. HTT_PPDU_STATS_USER_COMMON_TLV_QOS_CTRL_GET(*tag_buf);
  1775. ppdu_user_desc->frame_ctrl =
  1776. HTT_PPDU_STATS_USER_COMMON_TLV_FRAME_CTRL_GET(*tag_buf);
  1777. ppdu_desc->frame_ctrl = ppdu_user_desc->frame_ctrl;
  1778. if (ppdu_user_desc->delayed_ba) {
  1779. ppdu_user_desc->mpdu_success = 0;
  1780. ppdu_user_desc->mpdu_tried_mcast = 0;
  1781. ppdu_user_desc->mpdu_tried_ucast = 0;
  1782. }
  1783. tag_buf += 3;
  1784. if (HTT_PPDU_STATS_IS_OPAQUE_VALID_GET(*tag_buf)) {
  1785. ppdu_user_desc->ppdu_cookie =
  1786. HTT_PPDU_STATS_HOST_OPAQUE_COOKIE_GET(*tag_buf);
  1787. ppdu_user_desc->is_ppdu_cookie_valid = 1;
  1788. }
  1789. }
  1790. /**
  1791. * dp_process_ppdu_stats_user_rate_tlv() - Process htt_ppdu_stats_user_rate_tlv
  1792. * @pdev: DP pdev handle
  1793. * @tag_buf: T2H message buffer carrying the user rate TLV
  1794. * @ppdu_info: per ppdu tlv structure
  1795. *
  1796. * return:void
  1797. */
  1798. static void dp_process_ppdu_stats_user_rate_tlv(struct dp_pdev *pdev,
  1799. uint32_t *tag_buf,
  1800. struct ppdu_info *ppdu_info)
  1801. {
  1802. uint16_t peer_id;
  1803. struct dp_peer *peer;
  1804. struct cdp_tx_completion_ppdu *ppdu_desc;
  1805. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1806. uint8_t curr_user_index = 0;
  1807. struct dp_vdev *vdev;
  1808. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  1809. tag_buf++;
  1810. peer_id = HTT_PPDU_STATS_USER_RATE_TLV_SW_PEER_ID_GET(*tag_buf);
  1811. curr_user_index =
  1812. dp_get_ppdu_info_user_index(pdev,
  1813. peer_id, ppdu_info);
  1814. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1815. if (peer_id == DP_SCAN_PEER_ID) {
  1816. vdev =
  1817. dp_get_vdev_from_soc_vdev_id_wifi3(pdev->soc,
  1818. ppdu_desc->vdev_id);
  1819. if (!vdev)
  1820. return;
  1821. qdf_mem_copy(ppdu_user_desc->mac_addr, vdev->mac_addr.raw,
  1822. QDF_MAC_ADDR_SIZE);
  1823. } else {
  1824. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1825. if (!peer)
  1826. return;
  1827. qdf_mem_copy(ppdu_user_desc->mac_addr,
  1828. peer->mac_addr.raw, QDF_MAC_ADDR_SIZE);
  1829. dp_peer_unref_del_find_by_id(peer);
  1830. }
  1831. ppdu_user_desc->peer_id = peer_id;
  1832. ppdu_user_desc->tid =
  1833. HTT_PPDU_STATS_USER_RATE_TLV_TID_NUM_GET(*tag_buf);
  1834. tag_buf += 1;
  1835. ppdu_user_desc->user_pos =
  1836. HTT_PPDU_STATS_USER_RATE_TLV_USER_POS_GET(*tag_buf);
  1837. ppdu_user_desc->mu_group_id =
  1838. HTT_PPDU_STATS_USER_RATE_TLV_MU_GROUPID_GET(*tag_buf);
  1839. tag_buf += 1;
  1840. ppdu_user_desc->ru_start =
  1841. HTT_PPDU_STATS_USER_RATE_TLV_RU_START_GET(*tag_buf);
  1842. ppdu_user_desc->ru_tones =
  1843. (HTT_PPDU_STATS_USER_RATE_TLV_RU_END_GET(*tag_buf) -
  1844. HTT_PPDU_STATS_USER_RATE_TLV_RU_START_GET(*tag_buf)) + 1;
  1845. tag_buf += 2;
  1846. ppdu_user_desc->ppdu_type =
  1847. HTT_PPDU_STATS_USER_RATE_TLV_PPDU_TYPE_GET(*tag_buf);
  1848. tag_buf++;
  1849. ppdu_user_desc->tx_rate = *tag_buf;
  1850. ppdu_user_desc->ltf_size =
  1851. HTT_PPDU_STATS_USER_RATE_TLV_LTF_SIZE_GET(*tag_buf);
  1852. ppdu_user_desc->stbc =
  1853. HTT_PPDU_STATS_USER_RATE_TLV_STBC_GET(*tag_buf);
  1854. ppdu_user_desc->he_re =
  1855. HTT_PPDU_STATS_USER_RATE_TLV_HE_RE_GET(*tag_buf);
  1856. ppdu_user_desc->txbf =
  1857. HTT_PPDU_STATS_USER_RATE_TLV_TXBF_GET(*tag_buf);
  1858. ppdu_user_desc->bw =
  1859. HTT_PPDU_STATS_USER_RATE_TLV_BW_GET(*tag_buf) - 2;
  1860. ppdu_user_desc->nss = HTT_PPDU_STATS_USER_RATE_TLV_NSS_GET(*tag_buf);
  1861. ppdu_user_desc->mcs = HTT_PPDU_STATS_USER_RATE_TLV_MCS_GET(*tag_buf);
  1862. ppdu_user_desc->preamble =
  1863. HTT_PPDU_STATS_USER_RATE_TLV_PREAMBLE_GET(*tag_buf);
  1864. ppdu_user_desc->gi = HTT_PPDU_STATS_USER_RATE_TLV_GI_GET(*tag_buf);
  1865. ppdu_user_desc->dcm = HTT_PPDU_STATS_USER_RATE_TLV_DCM_GET(*tag_buf);
  1866. ppdu_user_desc->ldpc = HTT_PPDU_STATS_USER_RATE_TLV_LDPC_GET(*tag_buf);
  1867. }
  1868. /*
  1869. * dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv: Process
  1870. * htt_ppdu_stats_enq_mpdu_bitmap_64_tlv
  1871. * pdev: DP PDEV handle
  1872. * @tag_buf: buffer containing the tlv htt_ppdu_stats_enq_mpdu_bitmap_64_tlv
  1873. * @ppdu_info: per ppdu tlv structure
  1874. *
  1875. * return:void
  1876. */
  1877. static void dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv(
  1878. struct dp_pdev *pdev, uint32_t *tag_buf,
  1879. struct ppdu_info *ppdu_info)
  1880. {
  1881. htt_ppdu_stats_enq_mpdu_bitmap_64_tlv *dp_stats_buf =
  1882. (htt_ppdu_stats_enq_mpdu_bitmap_64_tlv *)tag_buf;
  1883. struct cdp_tx_completion_ppdu *ppdu_desc;
  1884. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1885. uint8_t curr_user_index = 0;
  1886. uint16_t peer_id;
  1887. uint32_t size = CDP_BA_64_BIT_MAP_SIZE_DWORDS;
  1888. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  1889. tag_buf++;
  1890. peer_id =
  1891. HTT_PPDU_STATS_ENQ_MPDU_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  1892. if (!dp_peer_find_by_id_valid(pdev->soc, peer_id))
  1893. return;
  1894. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id, ppdu_info);
  1895. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1896. ppdu_user_desc->peer_id = peer_id;
  1897. ppdu_user_desc->start_seq = dp_stats_buf->start_seq;
  1898. qdf_mem_copy(&ppdu_user_desc->enq_bitmap, &dp_stats_buf->enq_bitmap,
  1899. sizeof(uint32_t) * CDP_BA_64_BIT_MAP_SIZE_DWORDS);
  1900. dp_process_ppdu_stats_update_failed_bitmap(pdev,
  1901. (void *)ppdu_user_desc,
  1902. ppdu_info->ppdu_id,
  1903. size);
  1904. }
  1905. /*
  1906. * dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv: Process
  1907. * htt_ppdu_stats_enq_mpdu_bitmap_256_tlv
  1908. * soc: DP SOC handle
  1909. * @tag_buf: buffer containing the tlv htt_ppdu_stats_enq_mpdu_bitmap_256_tlv
  1910. * @ppdu_info: per ppdu tlv structure
  1911. *
  1912. * return:void
  1913. */
  1914. static void dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv(
  1915. struct dp_pdev *pdev, uint32_t *tag_buf,
  1916. struct ppdu_info *ppdu_info)
  1917. {
  1918. htt_ppdu_stats_enq_mpdu_bitmap_256_tlv *dp_stats_buf =
  1919. (htt_ppdu_stats_enq_mpdu_bitmap_256_tlv *)tag_buf;
  1920. struct cdp_tx_completion_ppdu *ppdu_desc;
  1921. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1922. uint8_t curr_user_index = 0;
  1923. uint16_t peer_id;
  1924. uint32_t size = CDP_BA_256_BIT_MAP_SIZE_DWORDS;
  1925. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  1926. tag_buf++;
  1927. peer_id =
  1928. HTT_PPDU_STATS_ENQ_MPDU_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  1929. if (!dp_peer_find_by_id_valid(pdev->soc, peer_id))
  1930. return;
  1931. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id, ppdu_info);
  1932. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1933. ppdu_user_desc->peer_id = peer_id;
  1934. ppdu_user_desc->start_seq = dp_stats_buf->start_seq;
  1935. qdf_mem_copy(&ppdu_user_desc->enq_bitmap, &dp_stats_buf->enq_bitmap,
  1936. sizeof(uint32_t) * CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  1937. dp_process_ppdu_stats_update_failed_bitmap(pdev,
  1938. (void *)ppdu_user_desc,
  1939. ppdu_info->ppdu_id,
  1940. size);
  1941. }
  1942. /*
  1943. * dp_process_ppdu_stats_user_cmpltn_common_tlv: Process
  1944. * htt_ppdu_stats_user_cmpltn_common_tlv
  1945. * soc: DP SOC handle
  1946. * @tag_buf: buffer containing the tlv htt_ppdu_stats_user_cmpltn_common_tlv
  1947. * @ppdu_info: per ppdu tlv structure
  1948. *
  1949. * return:void
  1950. */
  1951. static void dp_process_ppdu_stats_user_cmpltn_common_tlv(
  1952. struct dp_pdev *pdev, uint32_t *tag_buf,
  1953. struct ppdu_info *ppdu_info)
  1954. {
  1955. uint16_t peer_id;
  1956. struct cdp_tx_completion_ppdu *ppdu_desc;
  1957. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1958. uint8_t curr_user_index = 0;
  1959. htt_ppdu_stats_user_cmpltn_common_tlv *dp_stats_buf =
  1960. (htt_ppdu_stats_user_cmpltn_common_tlv *)tag_buf;
  1961. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  1962. tag_buf++;
  1963. peer_id =
  1964. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_SW_PEER_ID_GET(*tag_buf);
  1965. if (!dp_peer_find_by_id_valid(pdev->soc, peer_id))
  1966. return;
  1967. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id, ppdu_info);
  1968. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1969. ppdu_user_desc->peer_id = peer_id;
  1970. ppdu_desc->last_usr_index = curr_user_index;
  1971. ppdu_user_desc->completion_status =
  1972. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_COMPLETION_STATUS_GET(
  1973. *tag_buf);
  1974. ppdu_user_desc->tid =
  1975. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_TID_NUM_GET(*tag_buf);
  1976. tag_buf++;
  1977. if (qdf_likely(ppdu_user_desc->completion_status ==
  1978. HTT_PPDU_STATS_USER_STATUS_OK)) {
  1979. ppdu_desc->ack_rssi = dp_stats_buf->ack_rssi;
  1980. ppdu_user_desc->ack_rssi_valid = 1;
  1981. } else {
  1982. ppdu_user_desc->ack_rssi_valid = 0;
  1983. }
  1984. tag_buf++;
  1985. ppdu_user_desc->mpdu_success =
  1986. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_MPDU_SUCCESS_GET(*tag_buf);
  1987. ppdu_user_desc->mpdu_failed =
  1988. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_MPDU_TRIED_GET(*tag_buf) -
  1989. ppdu_user_desc->mpdu_success;
  1990. tag_buf++;
  1991. ppdu_user_desc->long_retries =
  1992. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_LONG_RETRY_GET(*tag_buf);
  1993. ppdu_user_desc->short_retries =
  1994. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_SHORT_RETRY_GET(*tag_buf);
  1995. ppdu_user_desc->retry_msdus =
  1996. ppdu_user_desc->long_retries + ppdu_user_desc->short_retries;
  1997. ppdu_user_desc->is_ampdu =
  1998. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_IS_AMPDU_GET(*tag_buf);
  1999. ppdu_info->is_ampdu = ppdu_user_desc->is_ampdu;
  2000. }
  2001. /*
  2002. * dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv: Process
  2003. * htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv
  2004. * pdev: DP PDEV handle
  2005. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv
  2006. * @ppdu_info: per ppdu tlv structure
  2007. *
  2008. * return:void
  2009. */
  2010. static void dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv(
  2011. struct dp_pdev *pdev, uint32_t *tag_buf,
  2012. struct ppdu_info *ppdu_info)
  2013. {
  2014. htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv *dp_stats_buf =
  2015. (htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv *)tag_buf;
  2016. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  2017. struct cdp_tx_completion_ppdu *ppdu_desc;
  2018. uint8_t curr_user_index = 0;
  2019. uint16_t peer_id;
  2020. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2021. tag_buf++;
  2022. peer_id =
  2023. HTT_PPDU_STATS_USER_CMPLTN_BA_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  2024. if (!dp_peer_find_by_id_valid(pdev->soc, peer_id))
  2025. return;
  2026. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id, ppdu_info);
  2027. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  2028. ppdu_user_desc->peer_id = peer_id;
  2029. ppdu_user_desc->ba_seq_no = dp_stats_buf->ba_seq_no;
  2030. qdf_mem_copy(&ppdu_user_desc->ba_bitmap, &dp_stats_buf->ba_bitmap,
  2031. sizeof(uint32_t) * CDP_BA_64_BIT_MAP_SIZE_DWORDS);
  2032. }
  2033. /*
  2034. * dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv: Process
  2035. * htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv
  2036. * pdev: DP PDEV handle
  2037. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv
  2038. * @ppdu_info: per ppdu tlv structure
  2039. *
  2040. * return:void
  2041. */
  2042. static void dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv(
  2043. struct dp_pdev *pdev, uint32_t *tag_buf,
  2044. struct ppdu_info *ppdu_info)
  2045. {
  2046. htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv *dp_stats_buf =
  2047. (htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv *)tag_buf;
  2048. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  2049. struct cdp_tx_completion_ppdu *ppdu_desc;
  2050. uint8_t curr_user_index = 0;
  2051. uint16_t peer_id;
  2052. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2053. tag_buf++;
  2054. peer_id =
  2055. HTT_PPDU_STATS_USER_CMPLTN_BA_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  2056. if (!dp_peer_find_by_id_valid(pdev->soc, peer_id))
  2057. return;
  2058. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id, ppdu_info);
  2059. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  2060. ppdu_user_desc->peer_id = peer_id;
  2061. ppdu_user_desc->ba_seq_no = dp_stats_buf->ba_seq_no;
  2062. qdf_mem_copy(&ppdu_user_desc->ba_bitmap, &dp_stats_buf->ba_bitmap,
  2063. sizeof(uint32_t) * CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  2064. }
  2065. /*
  2066. * dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv: Process
  2067. * htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  2068. * pdev: DP PDE handle
  2069. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  2070. * @ppdu_info: per ppdu tlv structure
  2071. *
  2072. * return:void
  2073. */
  2074. static void dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv(
  2075. struct dp_pdev *pdev, uint32_t *tag_buf,
  2076. struct ppdu_info *ppdu_info)
  2077. {
  2078. uint16_t peer_id;
  2079. struct cdp_tx_completion_ppdu *ppdu_desc;
  2080. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  2081. uint8_t curr_user_index = 0;
  2082. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2083. tag_buf += 2;
  2084. peer_id =
  2085. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_SW_PEER_ID_GET(*tag_buf);
  2086. if (!dp_peer_find_by_id_valid(pdev->soc, peer_id))
  2087. return;
  2088. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id, ppdu_info);
  2089. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  2090. ppdu_user_desc->peer_id = peer_id;
  2091. tag_buf++;
  2092. ppdu_user_desc->tid =
  2093. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_TID_NUM_GET(*tag_buf);
  2094. ppdu_user_desc->num_mpdu =
  2095. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_NUM_MPDU_GET(*tag_buf);
  2096. ppdu_user_desc->num_msdu =
  2097. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_NUM_MSDU_GET(*tag_buf);
  2098. ppdu_user_desc->success_msdus = ppdu_user_desc->num_msdu;
  2099. tag_buf += 2;
  2100. ppdu_user_desc->success_bytes = *tag_buf;
  2101. }
  2102. /*
  2103. * dp_process_ppdu_stats_user_common_array_tlv: Process
  2104. * htt_ppdu_stats_user_common_array_tlv
  2105. * pdev: DP PDEV handle
  2106. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  2107. * @ppdu_info: per ppdu tlv structure
  2108. *
  2109. * return:void
  2110. */
  2111. static void dp_process_ppdu_stats_user_common_array_tlv(
  2112. struct dp_pdev *pdev, uint32_t *tag_buf,
  2113. struct ppdu_info *ppdu_info)
  2114. {
  2115. uint32_t peer_id;
  2116. struct cdp_tx_completion_ppdu *ppdu_desc;
  2117. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  2118. uint8_t curr_user_index = 0;
  2119. struct htt_tx_ppdu_stats_info *dp_stats_buf;
  2120. ppdu_desc = (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2121. tag_buf++;
  2122. dp_stats_buf = (struct htt_tx_ppdu_stats_info *)tag_buf;
  2123. tag_buf += 3;
  2124. peer_id =
  2125. HTT_PPDU_STATS_ARRAY_ITEM_TLV_PEERID_GET(*tag_buf);
  2126. if (!dp_peer_find_by_id_valid(pdev->soc, peer_id)) {
  2127. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  2128. "Invalid peer");
  2129. return;
  2130. }
  2131. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id, ppdu_info);
  2132. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  2133. ppdu_user_desc->retry_bytes = dp_stats_buf->tx_retry_bytes;
  2134. ppdu_user_desc->failed_bytes = dp_stats_buf->tx_failed_bytes;
  2135. tag_buf++;
  2136. ppdu_user_desc->success_msdus =
  2137. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_SUCC_MSDUS_GET(*tag_buf);
  2138. ppdu_user_desc->retry_bytes =
  2139. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_RETRY_MSDUS_GET(*tag_buf);
  2140. tag_buf++;
  2141. ppdu_user_desc->failed_msdus =
  2142. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_FAILED_MSDUS_GET(*tag_buf);
  2143. }
  2144. /*
  2145. * dp_process_ppdu_stats_flush_tlv: Process
  2146. * htt_ppdu_stats_flush_tlv
  2147. * @pdev: DP PDEV handle
  2148. * @tag_buf: buffer containing the htt_ppdu_stats_flush_tlv
  2149. *
  2150. * return:void
  2151. */
  2152. static void dp_process_ppdu_stats_user_compltn_flush_tlv(struct dp_pdev *pdev,
  2153. uint32_t *tag_buf)
  2154. {
  2155. uint32_t peer_id;
  2156. uint32_t drop_reason;
  2157. uint8_t tid;
  2158. uint32_t num_msdu;
  2159. struct dp_peer *peer;
  2160. tag_buf++;
  2161. drop_reason = *tag_buf;
  2162. tag_buf++;
  2163. num_msdu = HTT_PPDU_STATS_FLUSH_TLV_NUM_MSDU_GET(*tag_buf);
  2164. tag_buf++;
  2165. peer_id =
  2166. HTT_PPDU_STATS_FLUSH_TLV_SW_PEER_ID_GET(*tag_buf);
  2167. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  2168. if (!peer)
  2169. return;
  2170. tid = HTT_PPDU_STATS_FLUSH_TLV_TID_NUM_GET(*tag_buf);
  2171. if (drop_reason == HTT_FLUSH_EXCESS_RETRIES) {
  2172. DP_STATS_INC(peer, tx.excess_retries_per_ac[TID_TO_WME_AC(tid)],
  2173. num_msdu);
  2174. }
  2175. dp_peer_unref_del_find_by_id(peer);
  2176. }
  2177. #ifndef WLAN_TX_PKT_CAPTURE_ENH
  2178. /*
  2179. * dp_deliver_mgmt_frm: Process
  2180. * @pdev: DP PDEV handle
  2181. * @nbuf: buffer containing the htt_ppdu_stats_tx_mgmtctrl_payload_tlv
  2182. *
  2183. * return: void
  2184. */
  2185. static void dp_deliver_mgmt_frm(struct dp_pdev *pdev, qdf_nbuf_t nbuf)
  2186. {
  2187. if (pdev->tx_sniffer_enable || pdev->mcopy_mode) {
  2188. dp_wdi_event_handler(WDI_EVENT_TX_MGMT_CTRL, pdev->soc,
  2189. nbuf, HTT_INVALID_PEER,
  2190. WDI_NO_VAL, pdev->pdev_id);
  2191. }
  2192. }
  2193. #endif
  2194. /*
  2195. * dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv: Process
  2196. * htt_ppdu_stats_tx_mgmtctrl_payload_tlv
  2197. * @pdev: DP PDEV handle
  2198. * @tag_buf: buffer containing the htt_ppdu_stats_tx_mgmtctrl_payload_tlv
  2199. * @length: tlv_length
  2200. *
  2201. * return:QDF_STATUS_SUCCESS if nbuf as to be freed in caller
  2202. */
  2203. static QDF_STATUS
  2204. dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv(struct dp_pdev *pdev,
  2205. qdf_nbuf_t tag_buf,
  2206. uint32_t ppdu_id)
  2207. {
  2208. uint32_t *nbuf_ptr;
  2209. uint8_t trim_size;
  2210. if ((!pdev->tx_sniffer_enable) && (!pdev->mcopy_mode) &&
  2211. (!pdev->bpr_enable) && (!pdev->tx_capture_enabled))
  2212. return QDF_STATUS_SUCCESS;
  2213. trim_size = ((pdev->mgmtctrl_frm_info.mgmt_buf +
  2214. HTT_MGMT_CTRL_TLV_HDR_RESERVERD_LEN) -
  2215. qdf_nbuf_data(tag_buf));
  2216. if (!qdf_nbuf_pull_head(tag_buf, trim_size))
  2217. return QDF_STATUS_SUCCESS;
  2218. qdf_nbuf_trim_tail(tag_buf, qdf_nbuf_len(tag_buf) -
  2219. pdev->mgmtctrl_frm_info.mgmt_buf_len);
  2220. nbuf_ptr = (uint32_t *)qdf_nbuf_push_head(
  2221. tag_buf, sizeof(ppdu_id));
  2222. *nbuf_ptr = ppdu_id;
  2223. if (pdev->bpr_enable) {
  2224. dp_wdi_event_handler(WDI_EVENT_TX_BEACON, pdev->soc,
  2225. tag_buf, HTT_INVALID_PEER,
  2226. WDI_NO_VAL, pdev->pdev_id);
  2227. }
  2228. dp_deliver_mgmt_frm(pdev, tag_buf);
  2229. return QDF_STATUS_E_ALREADY;
  2230. }
  2231. /**
  2232. * dp_validate_fix_ppdu_tlv(): Function to validate the length of PPDU
  2233. *
  2234. * If the TLV length sent as part of PPDU TLV is less that expected size i.e
  2235. * size of corresponding data structure, pad the remaining bytes with zeros
  2236. * and continue processing the TLVs
  2237. *
  2238. * @pdev: DP pdev handle
  2239. * @tag_buf: TLV buffer
  2240. * @tlv_expected_size: Expected size of Tag
  2241. * @tlv_len: TLV length received from FW
  2242. *
  2243. * Return: Pointer to updated TLV
  2244. */
  2245. static inline uint32_t *dp_validate_fix_ppdu_tlv(struct dp_pdev *pdev,
  2246. uint32_t *tag_buf,
  2247. uint16_t tlv_expected_size,
  2248. uint16_t tlv_len)
  2249. {
  2250. uint32_t *tlv_desc = tag_buf;
  2251. qdf_assert_always(tlv_len != 0);
  2252. if (tlv_len < tlv_expected_size) {
  2253. qdf_mem_zero(pdev->ppdu_tlv_buf, tlv_expected_size);
  2254. qdf_mem_copy(pdev->ppdu_tlv_buf, tag_buf, tlv_len);
  2255. tlv_desc = pdev->ppdu_tlv_buf;
  2256. }
  2257. return tlv_desc;
  2258. }
  2259. /**
  2260. * dp_process_ppdu_tag(): Function to process the PPDU TLVs
  2261. * @pdev: DP pdev handle
  2262. * @tag_buf: TLV buffer
  2263. * @tlv_len: length of tlv
  2264. * @ppdu_info: per ppdu tlv structure
  2265. *
  2266. * return: void
  2267. */
  2268. static void dp_process_ppdu_tag(struct dp_pdev *pdev, uint32_t *tag_buf,
  2269. uint32_t tlv_len, struct ppdu_info *ppdu_info)
  2270. {
  2271. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  2272. uint16_t tlv_expected_size;
  2273. uint32_t *tlv_desc;
  2274. switch (tlv_type) {
  2275. case HTT_PPDU_STATS_COMMON_TLV:
  2276. tlv_expected_size = sizeof(htt_ppdu_stats_common_tlv);
  2277. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  2278. tlv_expected_size, tlv_len);
  2279. dp_process_ppdu_stats_common_tlv(pdev, tlv_desc, ppdu_info);
  2280. break;
  2281. case HTT_PPDU_STATS_USR_COMMON_TLV:
  2282. tlv_expected_size = sizeof(htt_ppdu_stats_user_common_tlv);
  2283. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  2284. tlv_expected_size, tlv_len);
  2285. dp_process_ppdu_stats_user_common_tlv(pdev, tlv_desc,
  2286. ppdu_info);
  2287. break;
  2288. case HTT_PPDU_STATS_USR_RATE_TLV:
  2289. tlv_expected_size = sizeof(htt_ppdu_stats_user_rate_tlv);
  2290. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  2291. tlv_expected_size, tlv_len);
  2292. dp_process_ppdu_stats_user_rate_tlv(pdev, tlv_desc,
  2293. ppdu_info);
  2294. break;
  2295. case HTT_PPDU_STATS_USR_MPDU_ENQ_BITMAP_64_TLV:
  2296. tlv_expected_size =
  2297. sizeof(htt_ppdu_stats_enq_mpdu_bitmap_64_tlv);
  2298. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  2299. tlv_expected_size, tlv_len);
  2300. dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv(
  2301. pdev, tlv_desc, ppdu_info);
  2302. break;
  2303. case HTT_PPDU_STATS_USR_MPDU_ENQ_BITMAP_256_TLV:
  2304. tlv_expected_size =
  2305. sizeof(htt_ppdu_stats_enq_mpdu_bitmap_256_tlv);
  2306. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  2307. tlv_expected_size, tlv_len);
  2308. dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv(
  2309. pdev, tlv_desc, ppdu_info);
  2310. break;
  2311. case HTT_PPDU_STATS_USR_COMPLTN_COMMON_TLV:
  2312. tlv_expected_size =
  2313. sizeof(htt_ppdu_stats_user_cmpltn_common_tlv);
  2314. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  2315. tlv_expected_size, tlv_len);
  2316. dp_process_ppdu_stats_user_cmpltn_common_tlv(
  2317. pdev, tlv_desc, ppdu_info);
  2318. break;
  2319. case HTT_PPDU_STATS_USR_COMPLTN_BA_BITMAP_64_TLV:
  2320. tlv_expected_size =
  2321. sizeof(htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv);
  2322. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  2323. tlv_expected_size, tlv_len);
  2324. dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv(
  2325. pdev, tlv_desc, ppdu_info);
  2326. break;
  2327. case HTT_PPDU_STATS_USR_COMPLTN_BA_BITMAP_256_TLV:
  2328. tlv_expected_size =
  2329. sizeof(htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv);
  2330. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  2331. tlv_expected_size, tlv_len);
  2332. dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv(
  2333. pdev, tlv_desc, ppdu_info);
  2334. break;
  2335. case HTT_PPDU_STATS_USR_COMPLTN_ACK_BA_STATUS_TLV:
  2336. tlv_expected_size =
  2337. sizeof(htt_ppdu_stats_user_compltn_ack_ba_status_tlv);
  2338. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  2339. tlv_expected_size, tlv_len);
  2340. dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv(
  2341. pdev, tlv_desc, ppdu_info);
  2342. break;
  2343. case HTT_PPDU_STATS_USR_COMMON_ARRAY_TLV:
  2344. tlv_expected_size =
  2345. sizeof(htt_ppdu_stats_usr_common_array_tlv_v);
  2346. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  2347. tlv_expected_size, tlv_len);
  2348. dp_process_ppdu_stats_user_common_array_tlv(
  2349. pdev, tlv_desc, ppdu_info);
  2350. break;
  2351. case HTT_PPDU_STATS_USR_COMPLTN_FLUSH_TLV:
  2352. tlv_expected_size = sizeof(htt_ppdu_stats_flush_tlv);
  2353. tlv_desc = dp_validate_fix_ppdu_tlv(pdev, tag_buf,
  2354. tlv_expected_size, tlv_len);
  2355. dp_process_ppdu_stats_user_compltn_flush_tlv(
  2356. pdev, tlv_desc);
  2357. break;
  2358. default:
  2359. break;
  2360. }
  2361. }
  2362. /**
  2363. * dp_ppdu_desc_user_stats_update(): Function to update TX user stats
  2364. * @pdev: DP pdev handle
  2365. * @ppdu_info: per PPDU TLV descriptor
  2366. *
  2367. * return: void
  2368. */
  2369. void
  2370. dp_ppdu_desc_user_stats_update(struct dp_pdev *pdev,
  2371. struct ppdu_info *ppdu_info)
  2372. {
  2373. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  2374. struct dp_peer *peer = NULL;
  2375. uint32_t tlv_bitmap_expected;
  2376. uint32_t tlv_bitmap_default;
  2377. uint16_t i;
  2378. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  2379. qdf_nbuf_data(ppdu_info->nbuf);
  2380. ppdu_desc->num_users = ppdu_info->last_user;
  2381. ppdu_desc->ppdu_id = ppdu_info->ppdu_id;
  2382. tlv_bitmap_expected = HTT_PPDU_DEFAULT_TLV_BITMAP;
  2383. if (pdev->tx_sniffer_enable || pdev->mcopy_mode) {
  2384. if (ppdu_info->is_ampdu)
  2385. tlv_bitmap_expected =
  2386. dp_htt_get_ppdu_sniffer_ampdu_tlv_bitmap(
  2387. ppdu_info->tlv_bitmap);
  2388. }
  2389. tlv_bitmap_default = tlv_bitmap_expected;
  2390. for (i = 0; i < ppdu_desc->num_users; i++) {
  2391. ppdu_desc->num_mpdu += ppdu_desc->user[i].num_mpdu;
  2392. ppdu_desc->num_msdu += ppdu_desc->user[i].num_msdu;
  2393. peer = dp_peer_find_by_id(pdev->soc,
  2394. ppdu_desc->user[i].peer_id);
  2395. /**
  2396. * This check is to make sure peer is not deleted
  2397. * after processing the TLVs.
  2398. */
  2399. if (!peer)
  2400. continue;
  2401. ppdu_desc->user[i].cookie = (void *)peer->wlanstats_ctx;
  2402. if (ppdu_desc->user[i].completion_status !=
  2403. HTT_PPDU_STATS_USER_STATUS_OK)
  2404. tlv_bitmap_expected = tlv_bitmap_expected & 0xFF;
  2405. if (ppdu_info->tlv_bitmap != tlv_bitmap_expected) {
  2406. dp_peer_unref_del_find_by_id(peer);
  2407. continue;
  2408. }
  2409. /**
  2410. * Update tx stats for data frames having Qos as well as
  2411. * non-Qos data tid
  2412. */
  2413. if ((ppdu_desc->user[i].tid < CDP_DATA_TID_MAX ||
  2414. (ppdu_desc->user[i].tid == CDP_DATA_NON_QOS_TID)) &&
  2415. (ppdu_desc->frame_type == CDP_PPDU_FTYPE_DATA)) {
  2416. dp_tx_stats_update(pdev->soc, peer,
  2417. &ppdu_desc->user[i],
  2418. ppdu_desc->ack_rssi);
  2419. dp_tx_rate_stats_update(peer, &ppdu_desc->user[i]);
  2420. }
  2421. dp_peer_unref_del_find_by_id(peer);
  2422. tlv_bitmap_expected = tlv_bitmap_default;
  2423. }
  2424. }
  2425. #ifndef WLAN_TX_PKT_CAPTURE_ENH
  2426. /**
  2427. * dp_ppdu_desc_deliver(): Function to deliver Tx PPDU status descriptor
  2428. * to upper layer
  2429. * @pdev: DP pdev handle
  2430. * @ppdu_info: per PPDU TLV descriptor
  2431. *
  2432. * return: void
  2433. */
  2434. static
  2435. void dp_ppdu_desc_deliver(struct dp_pdev *pdev,
  2436. struct ppdu_info *ppdu_info)
  2437. {
  2438. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  2439. qdf_nbuf_t nbuf;
  2440. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  2441. qdf_nbuf_data(ppdu_info->nbuf);
  2442. dp_ppdu_desc_user_stats_update(pdev, ppdu_info);
  2443. /*
  2444. * Remove from the list
  2445. */
  2446. TAILQ_REMOVE(&pdev->ppdu_info_list, ppdu_info, ppdu_info_list_elem);
  2447. nbuf = ppdu_info->nbuf;
  2448. pdev->list_depth--;
  2449. qdf_mem_free(ppdu_info);
  2450. qdf_assert_always(nbuf);
  2451. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  2452. qdf_nbuf_data(nbuf);
  2453. /**
  2454. * Deliver PPDU stats only for valid (acked) data frames if
  2455. * sniffer mode is not enabled.
  2456. * If sniffer mode is enabled, PPDU stats for all frames
  2457. * including mgmt/control frames should be delivered to upper layer
  2458. */
  2459. if (pdev->tx_sniffer_enable || pdev->mcopy_mode) {
  2460. dp_wdi_event_handler(WDI_EVENT_TX_PPDU_DESC, pdev->soc,
  2461. nbuf, HTT_INVALID_PEER,
  2462. WDI_NO_VAL, pdev->pdev_id);
  2463. } else {
  2464. if (ppdu_desc->num_mpdu != 0 && ppdu_desc->num_users != 0 &&
  2465. ppdu_desc->frame_ctrl & HTT_FRAMECTRL_DATATYPE) {
  2466. dp_wdi_event_handler(WDI_EVENT_TX_PPDU_DESC,
  2467. pdev->soc, nbuf, HTT_INVALID_PEER,
  2468. WDI_NO_VAL, pdev->pdev_id);
  2469. } else
  2470. qdf_nbuf_free(nbuf);
  2471. }
  2472. return;
  2473. }
  2474. #endif
  2475. /**
  2476. * dp_get_ppdu_desc(): Function to allocate new PPDU status
  2477. * desc for new ppdu id
  2478. * @pdev: DP pdev handle
  2479. * @ppdu_id: PPDU unique identifier
  2480. * @tlv_type: TLV type received
  2481. *
  2482. * return: ppdu_info per ppdu tlv structure
  2483. */
  2484. static
  2485. struct ppdu_info *dp_get_ppdu_desc(struct dp_pdev *pdev, uint32_t ppdu_id,
  2486. uint8_t tlv_type)
  2487. {
  2488. struct ppdu_info *ppdu_info = NULL;
  2489. /*
  2490. * Find ppdu_id node exists or not
  2491. */
  2492. TAILQ_FOREACH(ppdu_info, &pdev->ppdu_info_list, ppdu_info_list_elem) {
  2493. if (ppdu_info && (ppdu_info->ppdu_id == ppdu_id)) {
  2494. break;
  2495. }
  2496. }
  2497. if (ppdu_info) {
  2498. if (ppdu_info->tlv_bitmap & (1 << tlv_type)) {
  2499. /**
  2500. * if we get tlv_type that is already been processed
  2501. * for ppdu, that means we got a new ppdu with same
  2502. * ppdu id. Hence Flush the older ppdu
  2503. * for MUMIMO and OFDMA, In a PPDU we have
  2504. * multiple user with same tlv types. tlv bitmap is
  2505. * used to check whether SU or MU_MIMO/OFDMA
  2506. */
  2507. if (!(ppdu_info->tlv_bitmap &
  2508. (1 << HTT_PPDU_STATS_SCH_CMD_STATUS_TLV)))
  2509. return ppdu_info;
  2510. dp_ppdu_desc_deliver(pdev, ppdu_info);
  2511. } else {
  2512. return ppdu_info;
  2513. }
  2514. }
  2515. /**
  2516. * Flush the head ppdu descriptor if ppdu desc list reaches max
  2517. * threshold
  2518. */
  2519. if (pdev->list_depth > HTT_PPDU_DESC_MAX_DEPTH) {
  2520. ppdu_info = TAILQ_FIRST(&pdev->ppdu_info_list);
  2521. dp_ppdu_desc_deliver(pdev, ppdu_info);
  2522. }
  2523. /*
  2524. * Allocate new ppdu_info node
  2525. */
  2526. ppdu_info = qdf_mem_malloc(sizeof(struct ppdu_info));
  2527. if (!ppdu_info)
  2528. return NULL;
  2529. ppdu_info->nbuf = qdf_nbuf_alloc(pdev->soc->osdev,
  2530. sizeof(struct cdp_tx_completion_ppdu), 0, 4,
  2531. TRUE);
  2532. if (!ppdu_info->nbuf) {
  2533. qdf_mem_free(ppdu_info);
  2534. return NULL;
  2535. }
  2536. ppdu_info->ppdu_desc =
  2537. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(ppdu_info->nbuf);
  2538. qdf_mem_zero(qdf_nbuf_data(ppdu_info->nbuf),
  2539. sizeof(struct cdp_tx_completion_ppdu));
  2540. if (qdf_nbuf_put_tail(ppdu_info->nbuf,
  2541. sizeof(struct cdp_tx_completion_ppdu)) == NULL) {
  2542. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  2543. "No tailroom for HTT PPDU");
  2544. qdf_nbuf_free(ppdu_info->nbuf);
  2545. ppdu_info->nbuf = NULL;
  2546. ppdu_info->last_user = 0;
  2547. qdf_mem_free(ppdu_info);
  2548. return NULL;
  2549. }
  2550. /**
  2551. * No lock is needed because all PPDU TLVs are processed in
  2552. * same context and this list is updated in same context
  2553. */
  2554. TAILQ_INSERT_TAIL(&pdev->ppdu_info_list, ppdu_info,
  2555. ppdu_info_list_elem);
  2556. pdev->list_depth++;
  2557. return ppdu_info;
  2558. }
  2559. /**
  2560. * dp_htt_process_tlv(): Function to process each PPDU TLVs
  2561. * @pdev: DP pdev handle
  2562. * @htt_t2h_msg: HTT target to host message
  2563. *
  2564. * return: ppdu_info per ppdu tlv structure
  2565. */
  2566. static struct ppdu_info *dp_htt_process_tlv(struct dp_pdev *pdev,
  2567. qdf_nbuf_t htt_t2h_msg)
  2568. {
  2569. uint32_t length;
  2570. uint32_t ppdu_id;
  2571. uint8_t tlv_type;
  2572. uint32_t tlv_length, tlv_bitmap_expected;
  2573. uint8_t *tlv_buf;
  2574. struct ppdu_info *ppdu_info = NULL;
  2575. struct cdp_tx_completion_ppdu *ppdu_desc = NULL;
  2576. uint32_t *msg_word = (uint32_t *) qdf_nbuf_data(htt_t2h_msg);
  2577. length = HTT_T2H_PPDU_STATS_PAYLOAD_SIZE_GET(*msg_word);
  2578. msg_word = msg_word + 1;
  2579. ppdu_id = HTT_T2H_PPDU_STATS_PPDU_ID_GET(*msg_word);
  2580. msg_word = msg_word + 3;
  2581. while (length > 0) {
  2582. tlv_buf = (uint8_t *)msg_word;
  2583. tlv_type = HTT_STATS_TLV_TAG_GET(*msg_word);
  2584. tlv_length = HTT_STATS_TLV_LENGTH_GET(*msg_word);
  2585. if (qdf_likely(tlv_type < CDP_PPDU_STATS_MAX_TAG))
  2586. pdev->stats.ppdu_stats_counter[tlv_type]++;
  2587. if (tlv_length == 0)
  2588. break;
  2589. tlv_length += HTT_TLV_HDR_LEN;
  2590. /**
  2591. * Not allocating separate ppdu descriptor for MGMT Payload
  2592. * TLV as this is sent as separate WDI indication and it
  2593. * doesn't contain any ppdu information
  2594. */
  2595. if (tlv_type == HTT_PPDU_STATS_TX_MGMTCTRL_PAYLOAD_TLV) {
  2596. pdev->mgmtctrl_frm_info.mgmt_buf = tlv_buf;
  2597. pdev->mgmtctrl_frm_info.ppdu_id = ppdu_id;
  2598. pdev->mgmtctrl_frm_info.mgmt_buf_len =
  2599. HTT_PPDU_STATS_TX_MGMTCTRL_TLV_FRAME_LENGTH_GET
  2600. (*(msg_word + 1));
  2601. msg_word =
  2602. (uint32_t *)((uint8_t *)tlv_buf + tlv_length);
  2603. length -= (tlv_length);
  2604. continue;
  2605. }
  2606. ppdu_info = dp_get_ppdu_desc(pdev, ppdu_id, tlv_type);
  2607. if (!ppdu_info)
  2608. return NULL;
  2609. ppdu_info->ppdu_id = ppdu_id;
  2610. ppdu_info->tlv_bitmap |= (1 << tlv_type);
  2611. dp_process_ppdu_tag(pdev, msg_word, tlv_length, ppdu_info);
  2612. /**
  2613. * Increment pdev level tlv count to monitor
  2614. * missing TLVs
  2615. */
  2616. pdev->tlv_count++;
  2617. ppdu_info->last_tlv_cnt = pdev->tlv_count;
  2618. msg_word = (uint32_t *)((uint8_t *)tlv_buf + tlv_length);
  2619. length -= (tlv_length);
  2620. }
  2621. if (!ppdu_info)
  2622. return NULL;
  2623. pdev->last_ppdu_id = ppdu_id;
  2624. tlv_bitmap_expected = HTT_PPDU_DEFAULT_TLV_BITMAP;
  2625. ppdu_desc = ppdu_info->ppdu_desc;
  2626. if (ppdu_desc &&
  2627. ppdu_desc->user[ppdu_desc->last_usr_index].completion_status !=
  2628. HTT_PPDU_STATS_USER_STATUS_OK) {
  2629. tlv_bitmap_expected = tlv_bitmap_expected & 0xFF;
  2630. }
  2631. if (pdev->tx_sniffer_enable || pdev->mcopy_mode) {
  2632. if (ppdu_info->is_ampdu)
  2633. tlv_bitmap_expected =
  2634. dp_htt_get_ppdu_sniffer_ampdu_tlv_bitmap(
  2635. ppdu_info->tlv_bitmap);
  2636. }
  2637. /**
  2638. * Once all the TLVs for a given PPDU has been processed,
  2639. * return PPDU status to be delivered to higher layer
  2640. */
  2641. if (ppdu_info->tlv_bitmap != 0 &&
  2642. ppdu_info->tlv_bitmap == tlv_bitmap_expected)
  2643. return ppdu_info;
  2644. return NULL;
  2645. }
  2646. #endif /* FEATURE_PERPKT_INFO */
  2647. /**
  2648. * dp_txrx_ppdu_stats_handler() - Function to process HTT PPDU stats from FW
  2649. * @soc: DP SOC handle
  2650. * @pdev_id: pdev id
  2651. * @htt_t2h_msg: HTT message nbuf
  2652. *
  2653. * return:void
  2654. */
  2655. #if defined(WDI_EVENT_ENABLE)
  2656. #ifdef FEATURE_PERPKT_INFO
  2657. static bool dp_txrx_ppdu_stats_handler(struct dp_soc *soc,
  2658. uint8_t pdev_id, qdf_nbuf_t htt_t2h_msg)
  2659. {
  2660. struct dp_pdev *pdev = soc->pdev_list[pdev_id];
  2661. struct ppdu_info *ppdu_info = NULL;
  2662. bool free_buf = true;
  2663. if (!pdev)
  2664. return true;
  2665. if (!pdev->enhanced_stats_en && !pdev->tx_sniffer_enable &&
  2666. !pdev->mcopy_mode && !pdev->bpr_enable)
  2667. return free_buf;
  2668. ppdu_info = dp_htt_process_tlv(pdev, htt_t2h_msg);
  2669. if (pdev->mgmtctrl_frm_info.mgmt_buf) {
  2670. if (dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv
  2671. (pdev, htt_t2h_msg, pdev->mgmtctrl_frm_info.ppdu_id) !=
  2672. QDF_STATUS_SUCCESS)
  2673. free_buf = false;
  2674. }
  2675. if (ppdu_info)
  2676. dp_ppdu_desc_deliver(pdev, ppdu_info);
  2677. pdev->mgmtctrl_frm_info.mgmt_buf = NULL;
  2678. pdev->mgmtctrl_frm_info.mgmt_buf_len = 0;
  2679. pdev->mgmtctrl_frm_info.ppdu_id = 0;
  2680. return free_buf;
  2681. }
  2682. #else
  2683. static bool dp_txrx_ppdu_stats_handler(struct dp_soc *soc,
  2684. uint8_t pdev_id, qdf_nbuf_t htt_t2h_msg)
  2685. {
  2686. return true;
  2687. }
  2688. #endif
  2689. #endif
  2690. /**
  2691. * dp_txrx_fw_stats_handler() - Function to process HTT EXT stats
  2692. * @soc: DP SOC handle
  2693. * @htt_t2h_msg: HTT message nbuf
  2694. *
  2695. * return:void
  2696. */
  2697. static inline void dp_txrx_fw_stats_handler(struct dp_soc *soc,
  2698. qdf_nbuf_t htt_t2h_msg)
  2699. {
  2700. uint8_t done;
  2701. qdf_nbuf_t msg_copy;
  2702. uint32_t *msg_word;
  2703. msg_word = (uint32_t *) qdf_nbuf_data(htt_t2h_msg);
  2704. msg_word = msg_word + 3;
  2705. done = HTT_T2H_EXT_STATS_CONF_TLV_DONE_GET(*msg_word);
  2706. /*
  2707. * HTT EXT stats response comes as stream of TLVs which span over
  2708. * multiple T2H messages.
  2709. * The first message will carry length of the response.
  2710. * For rest of the messages length will be zero.
  2711. *
  2712. * Clone the T2H message buffer and store it in a list to process
  2713. * it later.
  2714. *
  2715. * The original T2H message buffers gets freed in the T2H HTT event
  2716. * handler
  2717. */
  2718. msg_copy = qdf_nbuf_clone(htt_t2h_msg);
  2719. if (!msg_copy) {
  2720. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  2721. "T2H messge clone failed for HTT EXT STATS");
  2722. goto error;
  2723. }
  2724. qdf_spin_lock_bh(&soc->htt_stats.lock);
  2725. qdf_nbuf_queue_add(&soc->htt_stats.msg, msg_copy);
  2726. /*
  2727. * Done bit signifies that this is the last T2H buffer in the stream of
  2728. * HTT EXT STATS message
  2729. */
  2730. if (done) {
  2731. soc->htt_stats.num_stats++;
  2732. qdf_sched_work(0, &soc->htt_stats.work);
  2733. }
  2734. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  2735. return;
  2736. error:
  2737. qdf_spin_lock_bh(&soc->htt_stats.lock);
  2738. while ((msg_copy = qdf_nbuf_queue_remove(&soc->htt_stats.msg))
  2739. != NULL) {
  2740. qdf_nbuf_free(msg_copy);
  2741. }
  2742. soc->htt_stats.num_stats = 0;
  2743. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  2744. return;
  2745. }
  2746. /*
  2747. * htt_soc_attach_target() - SOC level HTT setup
  2748. * @htt_soc: HTT SOC handle
  2749. *
  2750. * Return: 0 on success; error code on failure
  2751. */
  2752. int htt_soc_attach_target(struct htt_soc *htt_soc)
  2753. {
  2754. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  2755. return htt_h2t_ver_req_msg(soc);
  2756. }
  2757. void htt_set_htc_handle(struct htt_soc *htt_soc, HTC_HANDLE htc_soc)
  2758. {
  2759. htt_soc->htc_soc = htc_soc;
  2760. }
  2761. HTC_HANDLE htt_get_htc_handle(struct htt_soc *htt_soc)
  2762. {
  2763. return htt_soc->htc_soc;
  2764. }
  2765. struct htt_soc *htt_soc_attach(struct dp_soc *soc, HTC_HANDLE htc_handle)
  2766. {
  2767. struct htt_soc *htt_soc = NULL;
  2768. htt_soc = qdf_mem_malloc(sizeof(*htt_soc));
  2769. if (!htt_soc) {
  2770. dp_err("HTT attach failed");
  2771. return NULL;
  2772. }
  2773. htt_soc->dp_soc = soc;
  2774. htt_soc->htc_soc = htc_handle;
  2775. HTT_TX_MUTEX_INIT(&htt_soc->htt_tx_mutex);
  2776. return htt_soc;
  2777. }
  2778. #if defined(WDI_EVENT_ENABLE) && !defined(REMOVE_PKT_LOG)
  2779. /*
  2780. * dp_ppdu_stats_ind_handler() - PPDU stats msg handler
  2781. * @htt_soc: HTT SOC handle
  2782. * @msg_word: Pointer to payload
  2783. * @htt_t2h_msg: HTT msg nbuf
  2784. *
  2785. * Return: True if buffer should be freed by caller.
  2786. */
  2787. static bool
  2788. dp_ppdu_stats_ind_handler(struct htt_soc *soc,
  2789. uint32_t *msg_word,
  2790. qdf_nbuf_t htt_t2h_msg)
  2791. {
  2792. u_int8_t pdev_id;
  2793. bool free_buf;
  2794. qdf_nbuf_set_pktlen(htt_t2h_msg, HTT_T2H_MAX_MSG_SIZE);
  2795. pdev_id = HTT_T2H_PPDU_STATS_PDEV_ID_GET(*msg_word);
  2796. pdev_id = DP_HW2SW_MACID(pdev_id);
  2797. free_buf = dp_txrx_ppdu_stats_handler(soc->dp_soc, pdev_id,
  2798. htt_t2h_msg);
  2799. dp_wdi_event_handler(WDI_EVENT_LITE_T2H, soc->dp_soc,
  2800. htt_t2h_msg, HTT_INVALID_PEER, WDI_NO_VAL,
  2801. pdev_id);
  2802. return free_buf;
  2803. }
  2804. #else
  2805. static bool
  2806. dp_ppdu_stats_ind_handler(struct htt_soc *soc,
  2807. uint32_t *msg_word,
  2808. qdf_nbuf_t htt_t2h_msg)
  2809. {
  2810. return true;
  2811. }
  2812. #endif
  2813. #if defined(WDI_EVENT_ENABLE) && \
  2814. !defined(REMOVE_PKT_LOG)
  2815. /*
  2816. * dp_pktlog_msg_handler() - Pktlog msg handler
  2817. * @htt_soc: HTT SOC handle
  2818. * @msg_word: Pointer to payload
  2819. *
  2820. * Return: None
  2821. */
  2822. static void
  2823. dp_pktlog_msg_handler(struct htt_soc *soc,
  2824. uint32_t *msg_word)
  2825. {
  2826. uint8_t pdev_id;
  2827. uint32_t *pl_hdr;
  2828. pdev_id = HTT_T2H_PKTLOG_PDEV_ID_GET(*msg_word);
  2829. pdev_id = DP_HW2SW_MACID(pdev_id);
  2830. pl_hdr = (msg_word + 1);
  2831. dp_wdi_event_handler(WDI_EVENT_OFFLOAD_ALL, soc->dp_soc,
  2832. pl_hdr, HTT_INVALID_PEER, WDI_NO_VAL,
  2833. pdev_id);
  2834. }
  2835. #else
  2836. static void
  2837. dp_pktlog_msg_handler(struct htt_soc *soc,
  2838. uint32_t *msg_word)
  2839. {
  2840. }
  2841. #endif
  2842. /*
  2843. * dp_htt_t2h_msg_handler() - Generic Target to host Msg/event handler
  2844. * @context: Opaque context (HTT SOC handle)
  2845. * @pkt: HTC packet
  2846. */
  2847. static void dp_htt_t2h_msg_handler(void *context, HTC_PACKET *pkt)
  2848. {
  2849. struct htt_soc *soc = (struct htt_soc *) context;
  2850. qdf_nbuf_t htt_t2h_msg = (qdf_nbuf_t) pkt->pPktContext;
  2851. u_int32_t *msg_word;
  2852. enum htt_t2h_msg_type msg_type;
  2853. bool free_buf = true;
  2854. /* check for successful message reception */
  2855. if (pkt->Status != QDF_STATUS_SUCCESS) {
  2856. if (pkt->Status != QDF_STATUS_E_CANCELED)
  2857. soc->stats.htc_err_cnt++;
  2858. qdf_nbuf_free(htt_t2h_msg);
  2859. return;
  2860. }
  2861. /* TODO: Check if we should pop the HTC/HTT header alignment padding */
  2862. msg_word = (u_int32_t *) qdf_nbuf_data(htt_t2h_msg);
  2863. msg_type = HTT_T2H_MSG_TYPE_GET(*msg_word);
  2864. htt_event_record(soc->htt_logger_handle,
  2865. msg_type, (uint8_t *)msg_word);
  2866. switch (msg_type) {
  2867. case HTT_T2H_MSG_TYPE_PEER_MAP:
  2868. {
  2869. u_int8_t mac_addr_deswizzle_buf[QDF_MAC_ADDR_SIZE];
  2870. u_int8_t *peer_mac_addr;
  2871. u_int16_t peer_id;
  2872. u_int16_t hw_peer_id;
  2873. u_int8_t vdev_id;
  2874. u_int8_t is_wds;
  2875. struct dp_soc *dpsoc = (struct dp_soc *)soc->dp_soc;
  2876. peer_id = HTT_RX_PEER_MAP_PEER_ID_GET(*msg_word);
  2877. hw_peer_id =
  2878. HTT_RX_PEER_MAP_HW_PEER_ID_GET(*(msg_word+2));
  2879. vdev_id = HTT_RX_PEER_MAP_VDEV_ID_GET(*msg_word);
  2880. peer_mac_addr = htt_t2h_mac_addr_deswizzle(
  2881. (u_int8_t *) (msg_word+1),
  2882. &mac_addr_deswizzle_buf[0]);
  2883. QDF_TRACE(QDF_MODULE_ID_TXRX,
  2884. QDF_TRACE_LEVEL_INFO,
  2885. "HTT_T2H_MSG_TYPE_PEER_MAP msg for peer id %d vdev id %d n",
  2886. peer_id, vdev_id);
  2887. /*
  2888. * check if peer already exists for this peer_id, if so
  2889. * this peer map event is in response for a wds peer add
  2890. * wmi command sent during wds source port learning.
  2891. * in this case just add the ast entry to the existing
  2892. * peer ast_list.
  2893. */
  2894. is_wds = !!(dpsoc->peer_id_to_obj_map[peer_id]);
  2895. dp_rx_peer_map_handler(soc->dp_soc, peer_id, hw_peer_id,
  2896. vdev_id, peer_mac_addr, 0,
  2897. is_wds);
  2898. break;
  2899. }
  2900. case HTT_T2H_MSG_TYPE_PEER_UNMAP:
  2901. {
  2902. u_int16_t peer_id;
  2903. u_int8_t vdev_id;
  2904. u_int8_t mac_addr[QDF_MAC_ADDR_SIZE] = {0};
  2905. peer_id = HTT_RX_PEER_UNMAP_PEER_ID_GET(*msg_word);
  2906. vdev_id = HTT_RX_PEER_UNMAP_VDEV_ID_GET(*msg_word);
  2907. dp_rx_peer_unmap_handler(soc->dp_soc, peer_id,
  2908. vdev_id, mac_addr, 0);
  2909. break;
  2910. }
  2911. case HTT_T2H_MSG_TYPE_SEC_IND:
  2912. {
  2913. u_int16_t peer_id;
  2914. enum cdp_sec_type sec_type;
  2915. int is_unicast;
  2916. peer_id = HTT_SEC_IND_PEER_ID_GET(*msg_word);
  2917. sec_type = HTT_SEC_IND_SEC_TYPE_GET(*msg_word);
  2918. is_unicast = HTT_SEC_IND_UNICAST_GET(*msg_word);
  2919. /* point to the first part of the Michael key */
  2920. msg_word++;
  2921. dp_rx_sec_ind_handler(
  2922. soc->dp_soc, peer_id, sec_type, is_unicast,
  2923. msg_word, msg_word + 2);
  2924. break;
  2925. }
  2926. case HTT_T2H_MSG_TYPE_PPDU_STATS_IND:
  2927. {
  2928. free_buf = dp_ppdu_stats_ind_handler(soc, msg_word,
  2929. htt_t2h_msg);
  2930. break;
  2931. }
  2932. case HTT_T2H_MSG_TYPE_PKTLOG:
  2933. {
  2934. dp_pktlog_msg_handler(soc, msg_word);
  2935. break;
  2936. }
  2937. case HTT_T2H_MSG_TYPE_VERSION_CONF:
  2938. {
  2939. htc_pm_runtime_put(soc->htc_soc);
  2940. soc->tgt_ver.major = HTT_VER_CONF_MAJOR_GET(*msg_word);
  2941. soc->tgt_ver.minor = HTT_VER_CONF_MINOR_GET(*msg_word);
  2942. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  2943. "target uses HTT version %d.%d; host uses %d.%d",
  2944. soc->tgt_ver.major, soc->tgt_ver.minor,
  2945. HTT_CURRENT_VERSION_MAJOR,
  2946. HTT_CURRENT_VERSION_MINOR);
  2947. if (soc->tgt_ver.major != HTT_CURRENT_VERSION_MAJOR) {
  2948. QDF_TRACE(QDF_MODULE_ID_TXRX,
  2949. QDF_TRACE_LEVEL_ERROR,
  2950. "*** Incompatible host/target HTT versions!");
  2951. }
  2952. /* abort if the target is incompatible with the host */
  2953. qdf_assert(soc->tgt_ver.major ==
  2954. HTT_CURRENT_VERSION_MAJOR);
  2955. if (soc->tgt_ver.minor != HTT_CURRENT_VERSION_MINOR) {
  2956. QDF_TRACE(QDF_MODULE_ID_TXRX,
  2957. QDF_TRACE_LEVEL_WARN,
  2958. "*** Warning: host/target HTT versions"
  2959. " are different, though compatible!");
  2960. }
  2961. break;
  2962. }
  2963. case HTT_T2H_MSG_TYPE_RX_ADDBA:
  2964. {
  2965. uint16_t peer_id;
  2966. uint8_t tid;
  2967. uint8_t win_sz;
  2968. uint16_t status;
  2969. struct dp_peer *peer;
  2970. /*
  2971. * Update REO Queue Desc with new values
  2972. */
  2973. peer_id = HTT_RX_ADDBA_PEER_ID_GET(*msg_word);
  2974. tid = HTT_RX_ADDBA_TID_GET(*msg_word);
  2975. win_sz = HTT_RX_ADDBA_WIN_SIZE_GET(*msg_word);
  2976. peer = dp_peer_find_by_id(soc->dp_soc, peer_id);
  2977. /*
  2978. * Window size needs to be incremented by 1
  2979. * since fw needs to represent a value of 256
  2980. * using just 8 bits
  2981. */
  2982. if (peer) {
  2983. status = dp_addba_requestprocess_wifi3(peer,
  2984. 0, tid, 0, win_sz + 1, 0xffff);
  2985. /*
  2986. * If PEER_LOCK_REF_PROTECT enbled dec ref
  2987. * which is inc by dp_peer_find_by_id
  2988. */
  2989. dp_peer_unref_del_find_by_id(peer);
  2990. QDF_TRACE(QDF_MODULE_ID_TXRX,
  2991. QDF_TRACE_LEVEL_INFO,
  2992. FL("PeerID %d BAW %d TID %d stat %d"),
  2993. peer_id, win_sz, tid, status);
  2994. } else {
  2995. QDF_TRACE(QDF_MODULE_ID_TXRX,
  2996. QDF_TRACE_LEVEL_ERROR,
  2997. FL("Peer not found peer id %d"),
  2998. peer_id);
  2999. }
  3000. break;
  3001. }
  3002. case HTT_T2H_MSG_TYPE_EXT_STATS_CONF:
  3003. {
  3004. dp_txrx_fw_stats_handler(soc->dp_soc, htt_t2h_msg);
  3005. break;
  3006. }
  3007. case HTT_T2H_MSG_TYPE_PEER_MAP_V2:
  3008. {
  3009. u_int8_t mac_addr_deswizzle_buf[QDF_MAC_ADDR_SIZE];
  3010. u_int8_t *peer_mac_addr;
  3011. u_int16_t peer_id;
  3012. u_int16_t hw_peer_id;
  3013. u_int8_t vdev_id;
  3014. bool is_wds;
  3015. u_int16_t ast_hash;
  3016. peer_id = HTT_RX_PEER_MAP_V2_SW_PEER_ID_GET(*msg_word);
  3017. hw_peer_id =
  3018. HTT_RX_PEER_MAP_V2_HW_PEER_ID_GET(*(msg_word + 2));
  3019. vdev_id = HTT_RX_PEER_MAP_V2_VDEV_ID_GET(*msg_word);
  3020. peer_mac_addr =
  3021. htt_t2h_mac_addr_deswizzle((u_int8_t *)(msg_word + 1),
  3022. &mac_addr_deswizzle_buf[0]);
  3023. is_wds =
  3024. HTT_RX_PEER_MAP_V2_NEXT_HOP_GET(*(msg_word + 3));
  3025. ast_hash =
  3026. HTT_RX_PEER_MAP_V2_AST_HASH_VALUE_GET(*(msg_word + 3));
  3027. QDF_TRACE(QDF_MODULE_ID_TXRX,
  3028. QDF_TRACE_LEVEL_INFO,
  3029. "HTT_T2H_MSG_TYPE_PEER_MAP msg for peer id %d vdev id %d n",
  3030. peer_id, vdev_id);
  3031. dp_rx_peer_map_handler(soc->dp_soc, peer_id,
  3032. hw_peer_id, vdev_id,
  3033. peer_mac_addr, ast_hash,
  3034. is_wds);
  3035. break;
  3036. }
  3037. case HTT_T2H_MSG_TYPE_PEER_UNMAP_V2:
  3038. {
  3039. u_int8_t mac_addr_deswizzle_buf[QDF_MAC_ADDR_SIZE];
  3040. u_int8_t *mac_addr;
  3041. u_int16_t peer_id;
  3042. u_int8_t vdev_id;
  3043. u_int8_t is_wds;
  3044. peer_id =
  3045. HTT_RX_PEER_UNMAP_V2_SW_PEER_ID_GET(*msg_word);
  3046. vdev_id = HTT_RX_PEER_UNMAP_V2_VDEV_ID_GET(*msg_word);
  3047. mac_addr =
  3048. htt_t2h_mac_addr_deswizzle((u_int8_t *)(msg_word + 1),
  3049. &mac_addr_deswizzle_buf[0]);
  3050. is_wds =
  3051. HTT_RX_PEER_UNMAP_V2_NEXT_HOP_GET(*(msg_word + 2));
  3052. QDF_TRACE(QDF_MODULE_ID_TXRX,
  3053. QDF_TRACE_LEVEL_INFO,
  3054. "HTT_T2H_MSG_TYPE_PEER_UNMAP msg for peer id %d vdev id %d n",
  3055. peer_id, vdev_id);
  3056. dp_rx_peer_unmap_handler(soc->dp_soc, peer_id,
  3057. vdev_id, mac_addr,
  3058. is_wds);
  3059. break;
  3060. }
  3061. default:
  3062. break;
  3063. };
  3064. /* Free the indication buffer */
  3065. if (free_buf)
  3066. qdf_nbuf_free(htt_t2h_msg);
  3067. }
  3068. /*
  3069. * dp_htt_h2t_full() - Send full handler (called from HTC)
  3070. * @context: Opaque context (HTT SOC handle)
  3071. * @pkt: HTC packet
  3072. *
  3073. * Return: enum htc_send_full_action
  3074. */
  3075. static enum htc_send_full_action
  3076. dp_htt_h2t_full(void *context, HTC_PACKET *pkt)
  3077. {
  3078. return HTC_SEND_FULL_KEEP;
  3079. }
  3080. /*
  3081. * dp_htt_hif_t2h_hp_callback() - HIF callback for high priority T2H messages
  3082. * @context: Opaque context (HTT SOC handle)
  3083. * @nbuf: nbuf containing T2H message
  3084. * @pipe_id: HIF pipe ID
  3085. *
  3086. * Return: QDF_STATUS
  3087. *
  3088. * TODO: Temporary change to bypass HTC connection for this new HIF pipe, which
  3089. * will be used for packet log and other high-priority HTT messages. Proper
  3090. * HTC connection to be added later once required FW changes are available
  3091. */
  3092. static QDF_STATUS
  3093. dp_htt_hif_t2h_hp_callback (void *context, qdf_nbuf_t nbuf, uint8_t pipe_id)
  3094. {
  3095. QDF_STATUS rc = QDF_STATUS_SUCCESS;
  3096. HTC_PACKET htc_pkt;
  3097. qdf_assert_always(pipe_id == DP_HTT_T2H_HP_PIPE);
  3098. qdf_mem_zero(&htc_pkt, sizeof(htc_pkt));
  3099. htc_pkt.Status = QDF_STATUS_SUCCESS;
  3100. htc_pkt.pPktContext = (void *)nbuf;
  3101. dp_htt_t2h_msg_handler(context, &htc_pkt);
  3102. return rc;
  3103. }
  3104. /*
  3105. * htt_htc_soc_attach() - Register SOC level HTT instance with HTC
  3106. * @htt_soc: HTT SOC handle
  3107. *
  3108. * Return: QDF_STATUS
  3109. */
  3110. static QDF_STATUS
  3111. htt_htc_soc_attach(struct htt_soc *soc)
  3112. {
  3113. struct htc_service_connect_req connect;
  3114. struct htc_service_connect_resp response;
  3115. QDF_STATUS status;
  3116. struct dp_soc *dpsoc = soc->dp_soc;
  3117. qdf_mem_zero(&connect, sizeof(connect));
  3118. qdf_mem_zero(&response, sizeof(response));
  3119. connect.pMetaData = NULL;
  3120. connect.MetaDataLength = 0;
  3121. connect.EpCallbacks.pContext = soc;
  3122. connect.EpCallbacks.EpTxComplete = dp_htt_h2t_send_complete;
  3123. connect.EpCallbacks.EpTxCompleteMultiple = NULL;
  3124. connect.EpCallbacks.EpRecv = dp_htt_t2h_msg_handler;
  3125. /* rx buffers currently are provided by HIF, not by EpRecvRefill */
  3126. connect.EpCallbacks.EpRecvRefill = NULL;
  3127. /* N/A, fill is done by HIF */
  3128. connect.EpCallbacks.RecvRefillWaterMark = 1;
  3129. connect.EpCallbacks.EpSendFull = dp_htt_h2t_full;
  3130. /*
  3131. * Specify how deep to let a queue get before htc_send_pkt will
  3132. * call the EpSendFull function due to excessive send queue depth.
  3133. */
  3134. connect.MaxSendQueueDepth = DP_HTT_MAX_SEND_QUEUE_DEPTH;
  3135. /* disable flow control for HTT data message service */
  3136. connect.ConnectionFlags |= HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  3137. /* connect to control service */
  3138. connect.service_id = HTT_DATA_MSG_SVC;
  3139. status = htc_connect_service(soc->htc_soc, &connect, &response);
  3140. if (status != QDF_STATUS_SUCCESS)
  3141. return status;
  3142. soc->htc_endpoint = response.Endpoint;
  3143. hif_save_htc_htt_config_endpoint(dpsoc->hif_handle, soc->htc_endpoint);
  3144. htt_interface_logging_init(&soc->htt_logger_handle);
  3145. dp_hif_update_pipe_callback(soc->dp_soc, (void *)soc,
  3146. dp_htt_hif_t2h_hp_callback, DP_HTT_T2H_HP_PIPE);
  3147. return QDF_STATUS_SUCCESS; /* success */
  3148. }
  3149. /*
  3150. * htt_soc_initialize() - SOC level HTT initialization
  3151. * @htt_soc: Opaque htt SOC handle
  3152. * @ctrl_psoc: Opaque ctrl SOC handle
  3153. * @htc_soc: SOC level HTC handle
  3154. * @hal_soc: Opaque HAL SOC handle
  3155. * @osdev: QDF device
  3156. *
  3157. * Return: HTT handle on success; NULL on failure
  3158. */
  3159. void *
  3160. htt_soc_initialize(struct htt_soc *htt_soc,
  3161. struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
  3162. HTC_HANDLE htc_soc,
  3163. void *hal_soc, qdf_device_t osdev)
  3164. {
  3165. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  3166. soc->osdev = osdev;
  3167. soc->ctrl_psoc = ctrl_psoc;
  3168. soc->htc_soc = htc_soc;
  3169. soc->hal_soc = hal_soc;
  3170. if (htt_htc_soc_attach(soc))
  3171. goto fail2;
  3172. return soc;
  3173. fail2:
  3174. return NULL;
  3175. }
  3176. void htt_soc_htc_dealloc(struct htt_soc *htt_handle)
  3177. {
  3178. htt_interface_logging_deinit(htt_handle->htt_logger_handle);
  3179. htt_htc_misc_pkt_pool_free(htt_handle);
  3180. htt_htc_pkt_pool_free(htt_handle);
  3181. }
  3182. /*
  3183. * htt_soc_htc_prealloc() - HTC memory prealloc
  3184. * @htt_soc: SOC level HTT handle
  3185. *
  3186. * Return: QDF_STATUS_SUCCESS on Success or
  3187. * QDF_STATUS_E_NOMEM on allocation failure
  3188. */
  3189. QDF_STATUS htt_soc_htc_prealloc(struct htt_soc *soc)
  3190. {
  3191. int i;
  3192. soc->htt_htc_pkt_freelist = NULL;
  3193. /* pre-allocate some HTC_PACKET objects */
  3194. for (i = 0; i < HTT_HTC_PKT_POOL_INIT_SIZE; i++) {
  3195. struct dp_htt_htc_pkt_union *pkt;
  3196. pkt = qdf_mem_malloc(sizeof(*pkt));
  3197. if (!pkt)
  3198. return QDF_STATUS_E_NOMEM;
  3199. htt_htc_pkt_free(soc, &pkt->u.pkt);
  3200. }
  3201. return QDF_STATUS_SUCCESS;
  3202. }
  3203. /*
  3204. * htt_soc_detach() - Free SOC level HTT handle
  3205. * @htt_hdl: HTT SOC handle
  3206. */
  3207. void htt_soc_detach(struct htt_soc *htt_hdl)
  3208. {
  3209. struct htt_soc *htt_handle = (struct htt_soc *)htt_hdl;
  3210. HTT_TX_MUTEX_DESTROY(&htt_handle->htt_tx_mutex);
  3211. qdf_mem_free(htt_handle);
  3212. }
  3213. /**
  3214. * dp_h2t_ext_stats_msg_send(): function to contruct HTT message to pass to FW
  3215. * @pdev: DP PDEV handle
  3216. * @stats_type_upload_mask: stats type requested by user
  3217. * @config_param_0: extra configuration parameters
  3218. * @config_param_1: extra configuration parameters
  3219. * @config_param_2: extra configuration parameters
  3220. * @config_param_3: extra configuration parameters
  3221. * @mac_id: mac number
  3222. *
  3223. * return: QDF STATUS
  3224. */
  3225. QDF_STATUS dp_h2t_ext_stats_msg_send(struct dp_pdev *pdev,
  3226. uint32_t stats_type_upload_mask, uint32_t config_param_0,
  3227. uint32_t config_param_1, uint32_t config_param_2,
  3228. uint32_t config_param_3, int cookie_val, int cookie_msb,
  3229. uint8_t mac_id)
  3230. {
  3231. struct htt_soc *soc = pdev->soc->htt_handle;
  3232. struct dp_htt_htc_pkt *pkt;
  3233. qdf_nbuf_t msg;
  3234. uint32_t *msg_word;
  3235. uint8_t pdev_mask = 0;
  3236. uint8_t *htt_logger_bufp;
  3237. msg = qdf_nbuf_alloc(
  3238. soc->osdev,
  3239. HTT_MSG_BUF_SIZE(HTT_H2T_EXT_STATS_REQ_MSG_SZ),
  3240. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  3241. if (!msg)
  3242. return QDF_STATUS_E_NOMEM;
  3243. /*TODO:Add support for SOC stats
  3244. * Bit 0: SOC Stats
  3245. * Bit 1: Pdev stats for pdev id 0
  3246. * Bit 2: Pdev stats for pdev id 1
  3247. * Bit 3: Pdev stats for pdev id 2
  3248. */
  3249. mac_id = dp_get_mac_id_for_pdev(mac_id, pdev->pdev_id);
  3250. pdev_mask = 1 << DP_SW2HW_MACID(mac_id);
  3251. /*
  3252. * Set the length of the message.
  3253. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  3254. * separately during the below call to qdf_nbuf_push_head.
  3255. * The contribution from the HTC header is added separately inside HTC.
  3256. */
  3257. if (qdf_nbuf_put_tail(msg, HTT_H2T_EXT_STATS_REQ_MSG_SZ) == NULL) {
  3258. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  3259. "Failed to expand head for HTT_EXT_STATS");
  3260. qdf_nbuf_free(msg);
  3261. return QDF_STATUS_E_FAILURE;
  3262. }
  3263. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  3264. "-----%s:%d----\n cookie <-> %d\n config_param_0 %u\n"
  3265. "config_param_1 %u\n config_param_2 %u\n"
  3266. "config_param_4 %u\n -------------",
  3267. __func__, __LINE__, cookie_val, config_param_0,
  3268. config_param_1, config_param_2, config_param_3);
  3269. msg_word = (uint32_t *) qdf_nbuf_data(msg);
  3270. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  3271. htt_logger_bufp = (uint8_t *)msg_word;
  3272. *msg_word = 0;
  3273. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_EXT_STATS_REQ);
  3274. HTT_H2T_EXT_STATS_REQ_PDEV_MASK_SET(*msg_word, pdev_mask);
  3275. HTT_H2T_EXT_STATS_REQ_STATS_TYPE_SET(*msg_word, stats_type_upload_mask);
  3276. /* word 1 */
  3277. msg_word++;
  3278. *msg_word = 0;
  3279. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_0);
  3280. /* word 2 */
  3281. msg_word++;
  3282. *msg_word = 0;
  3283. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_1);
  3284. /* word 3 */
  3285. msg_word++;
  3286. *msg_word = 0;
  3287. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_2);
  3288. /* word 4 */
  3289. msg_word++;
  3290. *msg_word = 0;
  3291. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_3);
  3292. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, 0);
  3293. /* word 5 */
  3294. msg_word++;
  3295. /* word 6 */
  3296. msg_word++;
  3297. *msg_word = 0;
  3298. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, cookie_val);
  3299. /* word 7 */
  3300. msg_word++;
  3301. *msg_word = 0;
  3302. /*Using last 2 bits for pdev_id */
  3303. cookie_msb = ((cookie_msb << 2) | pdev->pdev_id);
  3304. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, cookie_msb);
  3305. pkt = htt_htc_pkt_alloc(soc);
  3306. if (!pkt) {
  3307. qdf_nbuf_free(msg);
  3308. return QDF_STATUS_E_NOMEM;
  3309. }
  3310. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  3311. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  3312. dp_htt_h2t_send_complete_free_netbuf,
  3313. qdf_nbuf_data(msg), qdf_nbuf_len(msg),
  3314. soc->htc_endpoint,
  3315. 1); /* tag - not relevant here */
  3316. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  3317. DP_HTT_SEND_HTC_PKT(soc, pkt, HTT_H2T_MSG_TYPE_EXT_STATS_REQ,
  3318. htt_logger_bufp);
  3319. return 0;
  3320. }
  3321. /* This macro will revert once proper HTT header will define for
  3322. * HTT_H2T_MSG_TYPE_PPDU_STATS_CFG in htt.h file
  3323. * */
  3324. #if defined(WDI_EVENT_ENABLE)
  3325. /**
  3326. * dp_h2t_cfg_stats_msg_send(): function to construct HTT message to pass to FW
  3327. * @pdev: DP PDEV handle
  3328. * @stats_type_upload_mask: stats type requested by user
  3329. * @mac_id: Mac id number
  3330. *
  3331. * return: QDF STATUS
  3332. */
  3333. QDF_STATUS dp_h2t_cfg_stats_msg_send(struct dp_pdev *pdev,
  3334. uint32_t stats_type_upload_mask, uint8_t mac_id)
  3335. {
  3336. struct htt_soc *soc = pdev->soc->htt_handle;
  3337. struct dp_htt_htc_pkt *pkt;
  3338. qdf_nbuf_t msg;
  3339. uint32_t *msg_word;
  3340. uint8_t pdev_mask;
  3341. msg = qdf_nbuf_alloc(
  3342. soc->osdev,
  3343. HTT_MSG_BUF_SIZE(HTT_H2T_PPDU_STATS_CFG_MSG_SZ),
  3344. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, true);
  3345. if (!msg) {
  3346. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3347. "Fail to allocate HTT_H2T_PPDU_STATS_CFG_MSG_SZ msg buffer");
  3348. qdf_assert(0);
  3349. return QDF_STATUS_E_NOMEM;
  3350. }
  3351. /*TODO:Add support for SOC stats
  3352. * Bit 0: SOC Stats
  3353. * Bit 1: Pdev stats for pdev id 0
  3354. * Bit 2: Pdev stats for pdev id 1
  3355. * Bit 3: Pdev stats for pdev id 2
  3356. */
  3357. pdev_mask = 1 << DP_SW2HW_MACID(mac_id);
  3358. /*
  3359. * Set the length of the message.
  3360. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  3361. * separately during the below call to qdf_nbuf_push_head.
  3362. * The contribution from the HTC header is added separately inside HTC.
  3363. */
  3364. if (qdf_nbuf_put_tail(msg, HTT_H2T_PPDU_STATS_CFG_MSG_SZ) == NULL) {
  3365. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3366. "Failed to expand head for HTT_CFG_STATS");
  3367. qdf_nbuf_free(msg);
  3368. return QDF_STATUS_E_FAILURE;
  3369. }
  3370. msg_word = (uint32_t *) qdf_nbuf_data(msg);
  3371. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  3372. *msg_word = 0;
  3373. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_PPDU_STATS_CFG);
  3374. HTT_H2T_PPDU_STATS_CFG_PDEV_MASK_SET(*msg_word, pdev_mask);
  3375. HTT_H2T_PPDU_STATS_CFG_TLV_BITMASK_SET(*msg_word,
  3376. stats_type_upload_mask);
  3377. pkt = htt_htc_pkt_alloc(soc);
  3378. if (!pkt) {
  3379. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3380. "Fail to allocate dp_htt_htc_pkt buffer");
  3381. qdf_assert(0);
  3382. qdf_nbuf_free(msg);
  3383. return QDF_STATUS_E_NOMEM;
  3384. }
  3385. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  3386. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  3387. dp_htt_h2t_send_complete_free_netbuf,
  3388. qdf_nbuf_data(msg), qdf_nbuf_len(msg),
  3389. soc->htc_endpoint,
  3390. 1); /* tag - not relevant here */
  3391. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  3392. DP_HTT_SEND_HTC_PKT(soc, pkt, HTT_H2T_MSG_TYPE_PPDU_STATS_CFG,
  3393. (uint8_t *)msg_word);
  3394. return 0;
  3395. }
  3396. #endif
  3397. void
  3398. dp_peer_update_inactive_time(struct dp_pdev *pdev, uint32_t tag_type,
  3399. uint32_t *tag_buf)
  3400. {
  3401. switch (tag_type) {
  3402. case HTT_STATS_PEER_DETAILS_TAG:
  3403. {
  3404. htt_peer_details_tlv *dp_stats_buf =
  3405. (htt_peer_details_tlv *)tag_buf;
  3406. pdev->fw_stats_peer_id = dp_stats_buf->sw_peer_id;
  3407. }
  3408. break;
  3409. case HTT_STATS_PEER_STATS_CMN_TAG:
  3410. {
  3411. htt_peer_stats_cmn_tlv *dp_stats_buf =
  3412. (htt_peer_stats_cmn_tlv *)tag_buf;
  3413. struct dp_peer *peer = dp_peer_find_by_id(pdev->soc,
  3414. pdev->fw_stats_peer_id);
  3415. if (peer && !peer->bss_peer) {
  3416. peer->stats.tx.inactive_time =
  3417. dp_stats_buf->inactive_time;
  3418. qdf_event_set(&pdev->fw_peer_stats_event);
  3419. }
  3420. if (peer)
  3421. dp_peer_unref_del_find_by_id(peer);
  3422. }
  3423. break;
  3424. default:
  3425. qdf_err("Invalid tag_type");
  3426. }
  3427. }