dp_htt.c 99 KB

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