dp_htt.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672
  1. /*
  2. * Copyright (c) 2016-2017 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_api.h>
  20. #include "dp_htt.h"
  21. #include "dp_peer.h"
  22. #include "dp_types.h"
  23. #include "dp_internal.h"
  24. #include "dp_rx_mon.h"
  25. #include "htt_stats.h"
  26. #include "htt_ppdu_stats.h"
  27. #include "qdf_mem.h" /* qdf_mem_malloc,free */
  28. #include "cdp_txrx_cmn_struct.h"
  29. #define HTT_TLV_HDR_LEN HTT_T2H_EXT_STATS_CONF_TLV_HDR_SIZE
  30. #define HTT_HTC_PKT_POOL_INIT_SIZE 64
  31. #define HTT_T2H_MAX_MSG_SIZE 2048
  32. #define HTT_MSG_BUF_SIZE(msg_bytes) \
  33. ((msg_bytes) + HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING)
  34. #define DP_EXT_MSG_LENGTH 2048
  35. #define DP_HTT_SEND_HTC_PKT(soc, pkt) \
  36. do { \
  37. if (htc_send_pkt(soc->htc_soc, &pkt->htc_pkt) == \
  38. QDF_STATUS_SUCCESS) \
  39. htt_htc_misc_pkt_list_add(soc, pkt); \
  40. } while (0)
  41. #define HTT_MGMT_CTRL_TLV_RESERVERD_LEN 12
  42. /*
  43. * dp_tx_stats_update() - Update per-peer statistics
  44. * @soc: Datapath soc handle
  45. * @peer: Datapath peer handle
  46. * @ppdu: PPDU Descriptor
  47. * @ack_rssi: RSSI of last ack received
  48. *
  49. * Return: None
  50. */
  51. #ifdef FEATURE_PERPKT_INFO
  52. static void dp_tx_stats_update(struct dp_soc *soc, struct dp_peer *peer,
  53. struct cdp_tx_completion_ppdu_user *ppdu, uint32_t ack_rssi)
  54. {
  55. struct dp_pdev *pdev = peer->vdev->pdev;
  56. uint8_t preamble, mcs;
  57. uint16_t num_msdu;
  58. preamble = ppdu->preamble;
  59. mcs = ppdu->mcs;
  60. num_msdu = ppdu->num_msdu;
  61. /* If the peer statistics are already processed as part of
  62. * per-MSDU completion handler, do not process these again in per-PPDU
  63. * indications */
  64. if (soc->process_tx_status)
  65. return;
  66. DP_STATS_INC_PKT(peer, tx.comp_pkt,
  67. num_msdu, ppdu->success_bytes);
  68. DP_STATS_INC(peer, tx.tx_failed, ppdu->failed_msdus);
  69. DP_STATS_INC(peer, tx.sgi_count[ppdu->gi], 1);
  70. DP_STATS_INC(peer, tx.bw[ppdu->bw], 1);
  71. DP_STATS_UPD(peer, tx.last_ack_rssi, ack_rssi);
  72. DP_STATS_INC(peer, tx.wme_ac_type[TID_TO_WME_AC(ppdu->tid)], 1);
  73. DP_STATS_INC(peer, tx.stbc, ppdu->stbc);
  74. DP_STATS_INC(peer, tx.ldpc, ppdu->ldpc);
  75. DP_STATS_INC_PKT(peer, tx.tx_success, ppdu->success_msdus,
  76. ppdu->success_bytes);
  77. DP_STATS_INC(peer, tx.retries,
  78. (ppdu->long_retries + ppdu->short_retries));
  79. DP_STATS_INCC(peer,
  80. tx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
  81. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_A)));
  82. DP_STATS_INCC(peer,
  83. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  84. ((mcs < MAX_MCS_11A) && (preamble == DOT11_A)));
  85. DP_STATS_INCC(peer,
  86. tx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
  87. ((mcs >= MAX_MCS_11B) && (preamble == DOT11_B)));
  88. DP_STATS_INCC(peer,
  89. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  90. ((mcs < (MAX_MCS_11B)) && (preamble == DOT11_B)));
  91. DP_STATS_INCC(peer,
  92. tx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
  93. ((mcs >= MAX_MCS_11A) && (preamble == DOT11_N)));
  94. DP_STATS_INCC(peer,
  95. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  96. ((mcs < MAX_MCS_11A) && (preamble == DOT11_N)));
  97. DP_STATS_INCC(peer,
  98. tx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
  99. ((mcs >= MAX_MCS_11AC) && (preamble == DOT11_AC)));
  100. DP_STATS_INCC(peer,
  101. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  102. ((mcs < MAX_MCS_11AC) && (preamble == DOT11_AC)));
  103. DP_STATS_INCC(peer,
  104. tx.pkt_type[preamble].mcs_count[MAX_MCS], num_msdu,
  105. ((mcs >= (MAX_MCS - 1)) && (preamble == DOT11_AX)));
  106. DP_STATS_INCC(peer,
  107. tx.pkt_type[preamble].mcs_count[mcs], num_msdu,
  108. ((mcs < (MAX_MCS - 1)) && (preamble == DOT11_AX)));
  109. if (soc->cdp_soc.ol_ops->update_dp_stats) {
  110. soc->cdp_soc.ol_ops->update_dp_stats(pdev->osif_pdev,
  111. &peer->stats, ppdu->peer_id,
  112. UPDATE_PEER_STATS);
  113. }
  114. }
  115. #endif
  116. /*
  117. * htt_htc_pkt_alloc() - Allocate HTC packet buffer
  118. * @htt_soc: HTT SOC handle
  119. *
  120. * Return: Pointer to htc packet buffer
  121. */
  122. static struct dp_htt_htc_pkt *
  123. htt_htc_pkt_alloc(struct htt_soc *soc)
  124. {
  125. struct dp_htt_htc_pkt_union *pkt = NULL;
  126. HTT_TX_MUTEX_ACQUIRE(&soc->htt_tx_mutex);
  127. if (soc->htt_htc_pkt_freelist) {
  128. pkt = soc->htt_htc_pkt_freelist;
  129. soc->htt_htc_pkt_freelist = soc->htt_htc_pkt_freelist->u.next;
  130. }
  131. HTT_TX_MUTEX_RELEASE(&soc->htt_tx_mutex);
  132. if (pkt == NULL)
  133. pkt = qdf_mem_malloc(sizeof(*pkt));
  134. return &pkt->u.pkt; /* not actually a dereference */
  135. }
  136. /*
  137. * htt_htc_pkt_free() - Free HTC packet buffer
  138. * @htt_soc: HTT SOC handle
  139. */
  140. static void
  141. htt_htc_pkt_free(struct htt_soc *soc, struct dp_htt_htc_pkt *pkt)
  142. {
  143. struct dp_htt_htc_pkt_union *u_pkt =
  144. (struct dp_htt_htc_pkt_union *)pkt;
  145. HTT_TX_MUTEX_ACQUIRE(&soc->htt_tx_mutex);
  146. u_pkt->u.next = soc->htt_htc_pkt_freelist;
  147. soc->htt_htc_pkt_freelist = u_pkt;
  148. HTT_TX_MUTEX_RELEASE(&soc->htt_tx_mutex);
  149. }
  150. /*
  151. * htt_htc_pkt_pool_free() - Free HTC packet pool
  152. * @htt_soc: HTT SOC handle
  153. */
  154. static void
  155. htt_htc_pkt_pool_free(struct htt_soc *soc)
  156. {
  157. struct dp_htt_htc_pkt_union *pkt, *next;
  158. pkt = soc->htt_htc_pkt_freelist;
  159. while (pkt) {
  160. next = pkt->u.next;
  161. qdf_mem_free(pkt);
  162. pkt = next;
  163. }
  164. soc->htt_htc_pkt_freelist = NULL;
  165. }
  166. /*
  167. * htt_htc_misc_pkt_list_trim() - trim misc list
  168. * @htt_soc: HTT SOC handle
  169. * @level: max no. of pkts in list
  170. */
  171. static void
  172. htt_htc_misc_pkt_list_trim(struct htt_soc *soc, int level)
  173. {
  174. struct dp_htt_htc_pkt_union *pkt, *next, *prev = NULL;
  175. int i = 0;
  176. qdf_nbuf_t netbuf;
  177. HTT_TX_MUTEX_ACQUIRE(&soc->htt_tx_mutex);
  178. pkt = soc->htt_htc_pkt_misclist;
  179. while (pkt) {
  180. next = pkt->u.next;
  181. /* trim the out grown list*/
  182. if (++i > level) {
  183. netbuf =
  184. (qdf_nbuf_t)(pkt->u.pkt.htc_pkt.pNetBufContext);
  185. qdf_nbuf_unmap(soc->osdev, netbuf, QDF_DMA_TO_DEVICE);
  186. qdf_nbuf_free(netbuf);
  187. qdf_mem_free(pkt);
  188. pkt = NULL;
  189. if (prev)
  190. prev->u.next = NULL;
  191. }
  192. prev = pkt;
  193. pkt = next;
  194. }
  195. HTT_TX_MUTEX_RELEASE(&soc->htt_tx_mutex);
  196. }
  197. /*
  198. * htt_htc_misc_pkt_list_add() - Add pkt to misc list
  199. * @htt_soc: HTT SOC handle
  200. * @dp_htt_htc_pkt: pkt to be added to list
  201. */
  202. static void
  203. htt_htc_misc_pkt_list_add(struct htt_soc *soc, struct dp_htt_htc_pkt *pkt)
  204. {
  205. struct dp_htt_htc_pkt_union *u_pkt =
  206. (struct dp_htt_htc_pkt_union *)pkt;
  207. int misclist_trim_level = htc_get_tx_queue_depth(soc->htc_soc,
  208. pkt->htc_pkt.Endpoint)
  209. + DP_HTT_HTC_PKT_MISCLIST_SIZE;
  210. HTT_TX_MUTEX_ACQUIRE(&soc->htt_tx_mutex);
  211. if (soc->htt_htc_pkt_misclist) {
  212. u_pkt->u.next = soc->htt_htc_pkt_misclist;
  213. soc->htt_htc_pkt_misclist = u_pkt;
  214. } else {
  215. soc->htt_htc_pkt_misclist = u_pkt;
  216. }
  217. HTT_TX_MUTEX_RELEASE(&soc->htt_tx_mutex);
  218. /* only ce pipe size + tx_queue_depth could possibly be in use
  219. * free older packets in the misclist
  220. */
  221. htt_htc_misc_pkt_list_trim(soc, misclist_trim_level);
  222. }
  223. /*
  224. * htt_htc_misc_pkt_pool_free() - free pkts in misc list
  225. * @htt_soc: HTT SOC handle
  226. */
  227. static void
  228. htt_htc_misc_pkt_pool_free(struct htt_soc *soc)
  229. {
  230. struct dp_htt_htc_pkt_union *pkt, *next;
  231. qdf_nbuf_t netbuf;
  232. pkt = soc->htt_htc_pkt_misclist;
  233. while (pkt) {
  234. next = pkt->u.next;
  235. netbuf = (qdf_nbuf_t) (pkt->u.pkt.htc_pkt.pNetBufContext);
  236. qdf_nbuf_unmap(soc->osdev, netbuf, QDF_DMA_TO_DEVICE);
  237. soc->stats.htc_pkt_free++;
  238. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
  239. "%s: Pkt free count %d\n",
  240. __func__, soc->stats.htc_pkt_free);
  241. qdf_nbuf_free(netbuf);
  242. qdf_mem_free(pkt);
  243. pkt = next;
  244. }
  245. soc->htt_htc_pkt_misclist = NULL;
  246. }
  247. /*
  248. * htt_t2h_mac_addr_deswizzle() - Swap MAC addr bytes if FW endianess differ
  249. * @tgt_mac_addr: Target MAC
  250. * @buffer: Output buffer
  251. */
  252. static u_int8_t *
  253. htt_t2h_mac_addr_deswizzle(u_int8_t *tgt_mac_addr, u_int8_t *buffer)
  254. {
  255. #ifdef BIG_ENDIAN_HOST
  256. /*
  257. * The host endianness is opposite of the target endianness.
  258. * To make u_int32_t elements come out correctly, the target->host
  259. * upload has swizzled the bytes in each u_int32_t element of the
  260. * message.
  261. * For byte-array message fields like the MAC address, this
  262. * upload swizzling puts the bytes in the wrong order, and needs
  263. * to be undone.
  264. */
  265. buffer[0] = tgt_mac_addr[3];
  266. buffer[1] = tgt_mac_addr[2];
  267. buffer[2] = tgt_mac_addr[1];
  268. buffer[3] = tgt_mac_addr[0];
  269. buffer[4] = tgt_mac_addr[7];
  270. buffer[5] = tgt_mac_addr[6];
  271. return buffer;
  272. #else
  273. /*
  274. * The host endianness matches the target endianness -
  275. * we can use the mac addr directly from the message buffer.
  276. */
  277. return tgt_mac_addr;
  278. #endif
  279. }
  280. /*
  281. * dp_htt_h2t_send_complete_free_netbuf() - Free completed buffer
  282. * @soc: SOC handle
  283. * @status: Completion status
  284. * @netbuf: HTT buffer
  285. */
  286. static void
  287. dp_htt_h2t_send_complete_free_netbuf(
  288. void *soc, A_STATUS status, qdf_nbuf_t netbuf)
  289. {
  290. qdf_nbuf_free(netbuf);
  291. }
  292. /*
  293. * dp_htt_h2t_send_complete() - H2T completion handler
  294. * @context: Opaque context (HTT SOC handle)
  295. * @htc_pkt: HTC packet
  296. */
  297. static void
  298. dp_htt_h2t_send_complete(void *context, HTC_PACKET *htc_pkt)
  299. {
  300. void (*send_complete_part2)(
  301. void *soc, A_STATUS status, qdf_nbuf_t msdu);
  302. struct htt_soc *soc = (struct htt_soc *) context;
  303. struct dp_htt_htc_pkt *htt_pkt;
  304. qdf_nbuf_t netbuf;
  305. send_complete_part2 = htc_pkt->pPktContext;
  306. htt_pkt = container_of(htc_pkt, struct dp_htt_htc_pkt, htc_pkt);
  307. /* process (free or keep) the netbuf that held the message */
  308. netbuf = (qdf_nbuf_t) htc_pkt->pNetBufContext;
  309. /*
  310. * adf sendcomplete is required for windows only
  311. */
  312. /* qdf_nbuf_set_sendcompleteflag(netbuf, TRUE); */
  313. if (send_complete_part2 != NULL) {
  314. send_complete_part2(
  315. htt_pkt->soc_ctxt, htc_pkt->Status, netbuf);
  316. }
  317. /* free the htt_htc_pkt / HTC_PACKET object */
  318. htt_htc_pkt_free(soc, htt_pkt);
  319. }
  320. /*
  321. * htt_h2t_ver_req_msg() - Send HTT version request message to target
  322. * @htt_soc: HTT SOC handle
  323. *
  324. * Return: 0 on success; error code on failure
  325. */
  326. static int htt_h2t_ver_req_msg(struct htt_soc *soc)
  327. {
  328. struct dp_htt_htc_pkt *pkt;
  329. qdf_nbuf_t msg;
  330. uint32_t *msg_word;
  331. msg = qdf_nbuf_alloc(
  332. soc->osdev,
  333. HTT_MSG_BUF_SIZE(HTT_VER_REQ_BYTES),
  334. /* reserve room for the HTC header */
  335. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  336. if (!msg)
  337. return QDF_STATUS_E_NOMEM;
  338. /*
  339. * Set the length of the message.
  340. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  341. * separately during the below call to qdf_nbuf_push_head.
  342. * The contribution from the HTC header is added separately inside HTC.
  343. */
  344. if (qdf_nbuf_put_tail(msg, HTT_VER_REQ_BYTES) == NULL) {
  345. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  346. "%s: Failed to expand head for HTT_H2T_MSG_TYPE_VERSION_REQ msg\n",
  347. __func__);
  348. return QDF_STATUS_E_FAILURE;
  349. }
  350. /* fill in the message contents */
  351. msg_word = (u_int32_t *) qdf_nbuf_data(msg);
  352. /* rewind beyond alignment pad to get to the HTC header reserved area */
  353. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  354. *msg_word = 0;
  355. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_VERSION_REQ);
  356. pkt = htt_htc_pkt_alloc(soc);
  357. if (!pkt) {
  358. qdf_nbuf_free(msg);
  359. return QDF_STATUS_E_FAILURE;
  360. }
  361. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  362. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  363. dp_htt_h2t_send_complete_free_netbuf, qdf_nbuf_data(msg),
  364. qdf_nbuf_len(msg), soc->htc_endpoint,
  365. 1); /* tag - not relevant here */
  366. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  367. DP_HTT_SEND_HTC_PKT(soc, pkt);
  368. return 0;
  369. }
  370. /*
  371. * htt_srng_setup() - Send SRNG setup message to target
  372. * @htt_soc: HTT SOC handle
  373. * @mac_id: MAC Id
  374. * @hal_srng: Opaque HAL SRNG pointer
  375. * @hal_ring_type: SRNG ring type
  376. *
  377. * Return: 0 on success; error code on failure
  378. */
  379. int htt_srng_setup(void *htt_soc, int mac_id, void *hal_srng,
  380. int hal_ring_type)
  381. {
  382. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  383. struct dp_htt_htc_pkt *pkt;
  384. qdf_nbuf_t htt_msg;
  385. uint32_t *msg_word;
  386. struct hal_srng_params srng_params;
  387. qdf_dma_addr_t hp_addr, tp_addr;
  388. uint32_t ring_entry_size =
  389. hal_srng_get_entrysize(soc->hal_soc, hal_ring_type);
  390. int htt_ring_type, htt_ring_id;
  391. /* Sizes should be set in 4-byte words */
  392. ring_entry_size = ring_entry_size >> 2;
  393. htt_msg = qdf_nbuf_alloc(soc->osdev,
  394. HTT_MSG_BUF_SIZE(HTT_SRING_SETUP_SZ),
  395. /* reserve room for the HTC header */
  396. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  397. if (!htt_msg)
  398. goto fail0;
  399. hal_get_srng_params(soc->hal_soc, hal_srng, &srng_params);
  400. hp_addr = hal_srng_get_hp_addr(soc->hal_soc, hal_srng);
  401. tp_addr = hal_srng_get_tp_addr(soc->hal_soc, hal_srng);
  402. switch (hal_ring_type) {
  403. case RXDMA_BUF:
  404. #ifdef QCA_HOST2FW_RXBUF_RING
  405. if (srng_params.ring_id ==
  406. (HAL_SRNG_WMAC1_SW2RXDMA0_BUF0)) {
  407. htt_ring_id = HTT_HOST1_TO_FW_RXBUF_RING;
  408. htt_ring_type = HTT_SW_TO_SW_RING;
  409. #ifdef IPA_OFFLOAD
  410. } else if (srng_params.ring_id ==
  411. (HAL_SRNG_WMAC1_SW2RXDMA0_BUF2)) {
  412. htt_ring_id = HTT_HOST2_TO_FW_RXBUF_RING;
  413. htt_ring_type = HTT_SW_TO_SW_RING;
  414. #endif
  415. #else
  416. if (srng_params.ring_id ==
  417. (HAL_SRNG_WMAC1_SW2RXDMA0_BUF0 +
  418. (mac_id * HAL_MAX_RINGS_PER_LMAC))) {
  419. htt_ring_id = HTT_RXDMA_HOST_BUF_RING;
  420. htt_ring_type = HTT_SW_TO_HW_RING;
  421. #endif
  422. } else if (srng_params.ring_id ==
  423. #ifdef IPA_OFFLOAD
  424. (HAL_SRNG_WMAC1_SW2RXDMA0_BUF1 +
  425. #else
  426. (HAL_SRNG_WMAC1_SW2RXDMA1_BUF +
  427. #endif
  428. (mac_id * HAL_MAX_RINGS_PER_LMAC))) {
  429. htt_ring_id = HTT_RXDMA_HOST_BUF_RING;
  430. htt_ring_type = HTT_SW_TO_HW_RING;
  431. } else {
  432. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  433. "%s: Ring %d currently not supported\n",
  434. __func__, srng_params.ring_id);
  435. goto fail1;
  436. }
  437. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  438. "%s: ring_type %d ring_id %d\n",
  439. __func__, hal_ring_type, srng_params.ring_id);
  440. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  441. "%s: hp_addr 0x%llx tp_addr 0x%llx\n",
  442. __func__, (uint64_t)hp_addr, (uint64_t)tp_addr);
  443. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  444. "%s: htt_ring_id %d\n", __func__, htt_ring_id);
  445. break;
  446. case RXDMA_MONITOR_BUF:
  447. htt_ring_id = HTT_RXDMA_MONITOR_BUF_RING;
  448. htt_ring_type = HTT_SW_TO_HW_RING;
  449. break;
  450. case RXDMA_MONITOR_STATUS:
  451. htt_ring_id = HTT_RXDMA_MONITOR_STATUS_RING;
  452. htt_ring_type = HTT_SW_TO_HW_RING;
  453. break;
  454. case RXDMA_MONITOR_DST:
  455. htt_ring_id = HTT_RXDMA_MONITOR_DEST_RING;
  456. htt_ring_type = HTT_HW_TO_SW_RING;
  457. break;
  458. case RXDMA_MONITOR_DESC:
  459. htt_ring_id = HTT_RXDMA_MONITOR_DESC_RING;
  460. htt_ring_type = HTT_SW_TO_HW_RING;
  461. break;
  462. case RXDMA_DST:
  463. htt_ring_id = HTT_RXDMA_NON_MONITOR_DEST_RING;
  464. htt_ring_type = HTT_HW_TO_SW_RING;
  465. break;
  466. default:
  467. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  468. "%s: Ring currently not supported\n", __func__);
  469. goto fail1;
  470. }
  471. /*
  472. * Set the length of the message.
  473. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  474. * separately during the below call to qdf_nbuf_push_head.
  475. * The contribution from the HTC header is added separately inside HTC.
  476. */
  477. if (qdf_nbuf_put_tail(htt_msg, HTT_SRING_SETUP_SZ) == NULL) {
  478. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  479. "%s: Failed to expand head for SRING_SETUP msg\n",
  480. __func__);
  481. return QDF_STATUS_E_FAILURE;
  482. }
  483. msg_word = (uint32_t *)qdf_nbuf_data(htt_msg);
  484. /* rewind beyond alignment pad to get to the HTC header reserved area */
  485. qdf_nbuf_push_head(htt_msg, HTC_HDR_ALIGNMENT_PADDING);
  486. /* word 0 */
  487. *msg_word = 0;
  488. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_SRING_SETUP);
  489. if ((htt_ring_type == HTT_SW_TO_HW_RING) ||
  490. (htt_ring_type == HTT_HW_TO_SW_RING))
  491. HTT_SRING_SETUP_PDEV_ID_SET(*msg_word,
  492. DP_SW2HW_MACID(mac_id));
  493. else
  494. HTT_SRING_SETUP_PDEV_ID_SET(*msg_word, mac_id);
  495. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  496. "%s: mac_id %d\n", __func__, mac_id);
  497. HTT_SRING_SETUP_RING_TYPE_SET(*msg_word, htt_ring_type);
  498. /* TODO: Discuss with FW on changing this to unique ID and using
  499. * htt_ring_type to send the type of ring
  500. */
  501. HTT_SRING_SETUP_RING_ID_SET(*msg_word, htt_ring_id);
  502. /* word 1 */
  503. msg_word++;
  504. *msg_word = 0;
  505. HTT_SRING_SETUP_RING_BASE_ADDR_LO_SET(*msg_word,
  506. srng_params.ring_base_paddr & 0xffffffff);
  507. /* word 2 */
  508. msg_word++;
  509. *msg_word = 0;
  510. HTT_SRING_SETUP_RING_BASE_ADDR_HI_SET(*msg_word,
  511. (uint64_t)srng_params.ring_base_paddr >> 32);
  512. /* word 3 */
  513. msg_word++;
  514. *msg_word = 0;
  515. HTT_SRING_SETUP_ENTRY_SIZE_SET(*msg_word, ring_entry_size);
  516. HTT_SRING_SETUP_RING_SIZE_SET(*msg_word,
  517. (ring_entry_size * srng_params.num_entries));
  518. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  519. "%s: entry_size %d\n", __func__,
  520. ring_entry_size);
  521. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  522. "%s: num_entries %d\n", __func__,
  523. srng_params.num_entries);
  524. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  525. "%s: ring_size %d\n", __func__,
  526. (ring_entry_size * srng_params.num_entries));
  527. if (htt_ring_type == HTT_SW_TO_HW_RING)
  528. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_LOOPCOUNT_DISABLE_SET(
  529. *msg_word, 1);
  530. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_MSI_SWAP_SET(*msg_word,
  531. !!(srng_params.flags & HAL_SRNG_MSI_SWAP));
  532. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_TLV_SWAP_SET(*msg_word,
  533. !!(srng_params.flags & HAL_SRNG_DATA_TLV_SWAP));
  534. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_HOST_FW_SWAP_SET(*msg_word,
  535. !!(srng_params.flags & HAL_SRNG_RING_PTR_SWAP));
  536. /* word 4 */
  537. msg_word++;
  538. *msg_word = 0;
  539. HTT_SRING_SETUP_HEAD_OFFSET32_REMOTE_BASE_ADDR_LO_SET(*msg_word,
  540. hp_addr & 0xffffffff);
  541. /* word 5 */
  542. msg_word++;
  543. *msg_word = 0;
  544. HTT_SRING_SETUP_HEAD_OFFSET32_REMOTE_BASE_ADDR_HI_SET(*msg_word,
  545. (uint64_t)hp_addr >> 32);
  546. /* word 6 */
  547. msg_word++;
  548. *msg_word = 0;
  549. HTT_SRING_SETUP_TAIL_OFFSET32_REMOTE_BASE_ADDR_LO_SET(*msg_word,
  550. tp_addr & 0xffffffff);
  551. /* word 7 */
  552. msg_word++;
  553. *msg_word = 0;
  554. HTT_SRING_SETUP_TAIL_OFFSET32_REMOTE_BASE_ADDR_HI_SET(*msg_word,
  555. (uint64_t)tp_addr >> 32);
  556. /* word 8 */
  557. msg_word++;
  558. *msg_word = 0;
  559. HTT_SRING_SETUP_RING_MSI_ADDR_LO_SET(*msg_word,
  560. srng_params.msi_addr & 0xffffffff);
  561. /* word 9 */
  562. msg_word++;
  563. *msg_word = 0;
  564. HTT_SRING_SETUP_RING_MSI_ADDR_HI_SET(*msg_word,
  565. (uint64_t)(srng_params.msi_addr) >> 32);
  566. /* word 10 */
  567. msg_word++;
  568. *msg_word = 0;
  569. HTT_SRING_SETUP_RING_MSI_DATA_SET(*msg_word,
  570. srng_params.msi_data);
  571. /* word 11 */
  572. msg_word++;
  573. *msg_word = 0;
  574. HTT_SRING_SETUP_INTR_BATCH_COUNTER_TH_SET(*msg_word,
  575. srng_params.intr_batch_cntr_thres_entries *
  576. ring_entry_size);
  577. HTT_SRING_SETUP_INTR_TIMER_TH_SET(*msg_word,
  578. srng_params.intr_timer_thres_us >> 3);
  579. /* word 12 */
  580. msg_word++;
  581. *msg_word = 0;
  582. if (srng_params.flags & HAL_SRNG_LOW_THRES_INTR_ENABLE) {
  583. /* TODO: Setting low threshold to 1/8th of ring size - see
  584. * if this needs to be configurable
  585. */
  586. HTT_SRING_SETUP_INTR_LOW_TH_SET(*msg_word,
  587. srng_params.low_threshold);
  588. }
  589. /* "response_required" field should be set if a HTT response message is
  590. * required after setting up the ring.
  591. */
  592. pkt = htt_htc_pkt_alloc(soc);
  593. if (!pkt)
  594. goto fail1;
  595. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  596. SET_HTC_PACKET_INFO_TX(
  597. &pkt->htc_pkt,
  598. dp_htt_h2t_send_complete_free_netbuf,
  599. qdf_nbuf_data(htt_msg),
  600. qdf_nbuf_len(htt_msg),
  601. soc->htc_endpoint,
  602. HTC_TX_PACKET_TAG_RUNTIME_PUT); /* tag for no FW response msg */
  603. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, htt_msg);
  604. DP_HTT_SEND_HTC_PKT(soc, pkt);
  605. return QDF_STATUS_SUCCESS;
  606. fail1:
  607. qdf_nbuf_free(htt_msg);
  608. fail0:
  609. return QDF_STATUS_E_FAILURE;
  610. }
  611. /*
  612. * htt_h2t_rx_ring_cfg() - Send SRNG packet and TLV filter
  613. * config message to target
  614. * @htt_soc: HTT SOC handle
  615. * @pdev_id: PDEV Id
  616. * @hal_srng: Opaque HAL SRNG pointer
  617. * @hal_ring_type: SRNG ring type
  618. * @ring_buf_size: SRNG buffer size
  619. * @htt_tlv_filter: Rx SRNG TLV and filter setting
  620. * Return: 0 on success; error code on failure
  621. */
  622. int htt_h2t_rx_ring_cfg(void *htt_soc, int pdev_id, void *hal_srng,
  623. int hal_ring_type, int ring_buf_size,
  624. struct htt_rx_ring_tlv_filter *htt_tlv_filter)
  625. {
  626. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  627. struct dp_htt_htc_pkt *pkt;
  628. qdf_nbuf_t htt_msg;
  629. uint32_t *msg_word;
  630. struct hal_srng_params srng_params;
  631. uint32_t htt_ring_type, htt_ring_id;
  632. uint32_t tlv_filter;
  633. htt_msg = qdf_nbuf_alloc(soc->osdev,
  634. HTT_MSG_BUF_SIZE(HTT_RX_RING_SELECTION_CFG_SZ),
  635. /* reserve room for the HTC header */
  636. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  637. if (!htt_msg)
  638. goto fail0;
  639. hal_get_srng_params(soc->hal_soc, hal_srng, &srng_params);
  640. switch (hal_ring_type) {
  641. case RXDMA_BUF:
  642. #if QCA_HOST2FW_RXBUF_RING
  643. htt_ring_id = HTT_HOST1_TO_FW_RXBUF_RING;
  644. htt_ring_type = HTT_SW_TO_SW_RING;
  645. #else
  646. htt_ring_id = HTT_RXDMA_HOST_BUF_RING;
  647. htt_ring_type = HTT_SW_TO_HW_RING;
  648. #endif
  649. break;
  650. case RXDMA_MONITOR_BUF:
  651. htt_ring_id = HTT_RXDMA_MONITOR_BUF_RING;
  652. htt_ring_type = HTT_SW_TO_HW_RING;
  653. break;
  654. case RXDMA_MONITOR_STATUS:
  655. htt_ring_id = HTT_RXDMA_MONITOR_STATUS_RING;
  656. htt_ring_type = HTT_SW_TO_HW_RING;
  657. break;
  658. case RXDMA_MONITOR_DST:
  659. htt_ring_id = HTT_RXDMA_MONITOR_DEST_RING;
  660. htt_ring_type = HTT_HW_TO_SW_RING;
  661. break;
  662. case RXDMA_MONITOR_DESC:
  663. htt_ring_id = HTT_RXDMA_MONITOR_DESC_RING;
  664. htt_ring_type = HTT_SW_TO_HW_RING;
  665. break;
  666. case RXDMA_DST:
  667. htt_ring_id = HTT_RXDMA_NON_MONITOR_DEST_RING;
  668. htt_ring_type = HTT_HW_TO_SW_RING;
  669. break;
  670. default:
  671. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  672. "%s: Ring currently not supported\n", __func__);
  673. goto fail1;
  674. }
  675. /*
  676. * Set the length of the message.
  677. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  678. * separately during the below call to qdf_nbuf_push_head.
  679. * The contribution from the HTC header is added separately inside HTC.
  680. */
  681. if (qdf_nbuf_put_tail(htt_msg, HTT_RX_RING_SELECTION_CFG_SZ) == NULL) {
  682. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  683. "%s: Failed to expand head for RX Ring Cfg msg\n",
  684. __func__);
  685. goto fail1; /* failure */
  686. }
  687. msg_word = (uint32_t *)qdf_nbuf_data(htt_msg);
  688. /* rewind beyond alignment pad to get to the HTC header reserved area */
  689. qdf_nbuf_push_head(htt_msg, HTC_HDR_ALIGNMENT_PADDING);
  690. /* word 0 */
  691. *msg_word = 0;
  692. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_RX_RING_SELECTION_CFG);
  693. /*
  694. * pdev_id is indexed from 0 whereas mac_id is indexed from 1
  695. * SW_TO_SW and SW_TO_HW rings are unaffected by this
  696. */
  697. if (htt_ring_type == HTT_SW_TO_SW_RING ||
  698. htt_ring_type == HTT_SW_TO_HW_RING)
  699. HTT_RX_RING_SELECTION_CFG_PDEV_ID_SET(*msg_word,
  700. DP_SW2HW_MACID(pdev_id));
  701. /* TODO: Discuss with FW on changing this to unique ID and using
  702. * htt_ring_type to send the type of ring
  703. */
  704. HTT_RX_RING_SELECTION_CFG_RING_ID_SET(*msg_word, htt_ring_id);
  705. HTT_RX_RING_SELECTION_CFG_STATUS_TLV_SET(*msg_word,
  706. !!(srng_params.flags & HAL_SRNG_MSI_SWAP));
  707. HTT_RX_RING_SELECTION_CFG_PKT_TLV_SET(*msg_word,
  708. !!(srng_params.flags & HAL_SRNG_DATA_TLV_SWAP));
  709. /* word 1 */
  710. msg_word++;
  711. *msg_word = 0;
  712. HTT_RX_RING_SELECTION_CFG_RING_BUFFER_SIZE_SET(*msg_word,
  713. ring_buf_size);
  714. /* word 2 */
  715. msg_word++;
  716. *msg_word = 0;
  717. if (htt_tlv_filter->enable_fp) {
  718. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  719. MGMT, 0000, 1);
  720. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  721. MGMT, 0001, 1);
  722. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  723. MGMT, 0010, 1);
  724. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  725. MGMT, 0011, 1);
  726. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  727. MGMT, 0100, 1);
  728. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  729. MGMT, 0101, 1);
  730. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  731. MGMT, 0110, 1);
  732. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  733. MGMT, 0111, 1);
  734. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  735. MGMT, 1000, 1);
  736. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  737. MGMT, 1001, 1);
  738. }
  739. if (htt_tlv_filter->enable_md) {
  740. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  741. MGMT, 0000, 1);
  742. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  743. MGMT, 0001, 1);
  744. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  745. MGMT, 0010, 1);
  746. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  747. MGMT, 0011, 1);
  748. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  749. MGMT, 0100, 1);
  750. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  751. MGMT, 0101, 1);
  752. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  753. MGMT, 0110, 1);
  754. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  755. MGMT, 0111, 1);
  756. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  757. MGMT, 1000, 1);
  758. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  759. MGMT, 1001, 1);
  760. }
  761. if (htt_tlv_filter->enable_mo) {
  762. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  763. MGMT, 0000, 1);
  764. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  765. MGMT, 0001, 1);
  766. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  767. MGMT, 0010, 1);
  768. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  769. MGMT, 0011, 1);
  770. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  771. MGMT, 0100, 1);
  772. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  773. MGMT, 0101, 1);
  774. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  775. MGMT, 0110, 1);
  776. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  777. MGMT, 0111, 1);
  778. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  779. MGMT, 1000, 1);
  780. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  781. MGMT, 1001, 1);
  782. }
  783. /* word 3 */
  784. msg_word++;
  785. *msg_word = 0;
  786. if (htt_tlv_filter->enable_fp) {
  787. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  788. MGMT, 1010, 1);
  789. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  790. MGMT, 1011, 1);
  791. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  792. MGMT, 1100, 1);
  793. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  794. MGMT, 1101, 1);
  795. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  796. MGMT, 1110, 1);
  797. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  798. MGMT, 1111, 1);
  799. }
  800. if (htt_tlv_filter->enable_md) {
  801. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  802. MGMT, 1010, 1);
  803. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  804. MGMT, 1011, 1);
  805. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  806. MGMT, 1100, 1);
  807. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  808. MGMT, 1101, 1);
  809. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  810. MGMT, 1110, 1);
  811. }
  812. if (htt_tlv_filter->enable_mo) {
  813. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  814. MGMT, 1010, 1);
  815. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  816. MGMT, 1011, 1);
  817. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  818. MGMT, 1100, 1);
  819. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  820. MGMT, 1101, 1);
  821. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  822. MGMT, 1110, 1);
  823. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  824. MGMT, 1111, 1);
  825. }
  826. /* word 4 */
  827. msg_word++;
  828. *msg_word = 0;
  829. if (htt_tlv_filter->enable_fp) {
  830. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  831. CTRL, 0000, 1);
  832. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  833. CTRL, 0001, 1);
  834. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  835. CTRL, 0010, 1);
  836. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  837. CTRL, 0011, 1);
  838. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  839. CTRL, 0100, 1);
  840. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  841. CTRL, 0101, 1);
  842. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  843. CTRL, 0110, 1);
  844. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  845. CTRL, 0111, 1);
  846. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  847. CTRL, 1000, 1);
  848. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  849. CTRL, 1001, 1);
  850. }
  851. if (htt_tlv_filter->enable_md) {
  852. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  853. CTRL, 0000, 1);
  854. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  855. CTRL, 0001, 1);
  856. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  857. CTRL, 0010, 1);
  858. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  859. CTRL, 0011, 1);
  860. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  861. CTRL, 0100, 1);
  862. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  863. CTRL, 0101, 1);
  864. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  865. CTRL, 0110, 1);
  866. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  867. CTRL, 0111, 1);
  868. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  869. CTRL, 1000, 1);
  870. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  871. CTRL, 1001, 1);
  872. }
  873. if (htt_tlv_filter->enable_mo) {
  874. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  875. CTRL, 0000, 1);
  876. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  877. CTRL, 0001, 1);
  878. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  879. CTRL, 0010, 1);
  880. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  881. CTRL, 0011, 1);
  882. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  883. CTRL, 0100, 1);
  884. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  885. CTRL, 0101, 1);
  886. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  887. CTRL, 0110, 1);
  888. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  889. CTRL, 0111, 1);
  890. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  891. CTRL, 1000, 1);
  892. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  893. CTRL, 1001, 1);
  894. }
  895. /* word 5 */
  896. msg_word++;
  897. *msg_word = 0;
  898. if (htt_tlv_filter->enable_fp) {
  899. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  900. CTRL, 1010, 1);
  901. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  902. CTRL, 1011, 1);
  903. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  904. CTRL, 1100, 1);
  905. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  906. CTRL, 1101, 1);
  907. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  908. CTRL, 1110, 1);
  909. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  910. CTRL, 1111, 1);
  911. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  912. DATA, MCAST, 1);
  913. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  914. DATA, UCAST, 1);
  915. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  916. DATA, NULL, 1);
  917. }
  918. if (htt_tlv_filter->enable_md) {
  919. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  920. CTRL, 1010, 1);
  921. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  922. CTRL, 1011, 1);
  923. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  924. CTRL, 1100, 1);
  925. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  926. CTRL, 1101, 1);
  927. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  928. CTRL, 1110, 1);
  929. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  930. CTRL, 1111, 1);
  931. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  932. DATA, MCAST, 1);
  933. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  934. DATA, UCAST, 1);
  935. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  936. DATA, NULL, 1);
  937. }
  938. if (htt_tlv_filter->enable_mo) {
  939. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  940. CTRL, 1010, 1);
  941. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  942. CTRL, 1011, 1);
  943. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  944. CTRL, 1100, 1);
  945. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  946. CTRL, 1101, 1);
  947. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  948. CTRL, 1110, 1);
  949. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  950. CTRL, 1111, 1);
  951. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  952. DATA, MCAST, 1);
  953. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  954. DATA, UCAST, 1);
  955. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  956. DATA, NULL, 1);
  957. }
  958. /* word 6 */
  959. msg_word++;
  960. *msg_word = 0;
  961. tlv_filter = 0;
  962. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MPDU_START,
  963. htt_tlv_filter->mpdu_start);
  964. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MSDU_START,
  965. htt_tlv_filter->msdu_start);
  966. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PACKET,
  967. htt_tlv_filter->packet);
  968. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MSDU_END,
  969. htt_tlv_filter->msdu_end);
  970. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MPDU_END,
  971. htt_tlv_filter->mpdu_end);
  972. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PACKET_HEADER,
  973. htt_tlv_filter->packet_header);
  974. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, ATTENTION,
  975. htt_tlv_filter->attention);
  976. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_START,
  977. htt_tlv_filter->ppdu_start);
  978. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_END,
  979. htt_tlv_filter->ppdu_end);
  980. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_END_USER_STATS,
  981. htt_tlv_filter->ppdu_end_user_stats);
  982. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter,
  983. PPDU_END_USER_STATS_EXT,
  984. htt_tlv_filter->ppdu_end_user_stats_ext);
  985. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_END_STATUS_DONE,
  986. htt_tlv_filter->ppdu_end_status_done);
  987. /* RESERVED bit maps to header_per_msdu in htt_tlv_filter*/
  988. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, RESERVED,
  989. htt_tlv_filter->header_per_msdu);
  990. HTT_RX_RING_SELECTION_CFG_TLV_FILTER_IN_FLAG_SET(*msg_word, tlv_filter);
  991. /* "response_required" field should be set if a HTT response message is
  992. * required after setting up the ring.
  993. */
  994. pkt = htt_htc_pkt_alloc(soc);
  995. if (!pkt)
  996. goto fail1;
  997. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  998. SET_HTC_PACKET_INFO_TX(
  999. &pkt->htc_pkt,
  1000. dp_htt_h2t_send_complete_free_netbuf,
  1001. qdf_nbuf_data(htt_msg),
  1002. qdf_nbuf_len(htt_msg),
  1003. soc->htc_endpoint,
  1004. 1); /* tag - not relevant here */
  1005. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, htt_msg);
  1006. DP_HTT_SEND_HTC_PKT(soc, pkt);
  1007. return QDF_STATUS_SUCCESS;
  1008. fail1:
  1009. qdf_nbuf_free(htt_msg);
  1010. fail0:
  1011. return QDF_STATUS_E_FAILURE;
  1012. }
  1013. /**
  1014. * dp_process_htt_stat_msg(): Process the list of buffers of HTT EXT stats
  1015. * @htt_stats: htt stats info
  1016. *
  1017. * The FW sends the HTT EXT STATS as a stream of T2H messages. Each T2H message
  1018. * contains sub messages which are identified by a TLV header.
  1019. * In this function we will process the stream of T2H messages and read all the
  1020. * TLV contained in the message.
  1021. *
  1022. * THe following cases have been taken care of
  1023. * Case 1: When the tlv_remain_length <= msg_remain_length of HTT MSG buffer
  1024. * In this case the buffer will contain multiple tlvs.
  1025. * Case 2: When the tlv_remain_length > msg_remain_length of HTT MSG buffer.
  1026. * Only one tlv will be contained in the HTT message and this tag
  1027. * will extend onto the next buffer.
  1028. * Case 3: When the buffer is the continuation of the previous message
  1029. * Case 4: tlv length is 0. which will indicate the end of message
  1030. *
  1031. * return: void
  1032. */
  1033. static inline void dp_process_htt_stat_msg(struct htt_stats_context *htt_stats)
  1034. {
  1035. htt_tlv_tag_t tlv_type = 0xff;
  1036. qdf_nbuf_t htt_msg = NULL;
  1037. uint32_t *msg_word;
  1038. uint8_t *tlv_buf_head = NULL;
  1039. uint8_t *tlv_buf_tail = NULL;
  1040. uint32_t msg_remain_len = 0;
  1041. uint32_t tlv_remain_len = 0;
  1042. uint32_t *tlv_start;
  1043. /* Process node in the HTT message queue */
  1044. while ((htt_msg = qdf_nbuf_queue_remove(&htt_stats->msg))
  1045. != NULL) {
  1046. msg_word = (uint32_t *) qdf_nbuf_data(htt_msg);
  1047. /* read 5th word */
  1048. msg_word = msg_word + 4;
  1049. msg_remain_len = qdf_min(htt_stats->msg_len,
  1050. (uint32_t) DP_EXT_MSG_LENGTH);
  1051. /* Keep processing the node till node length is 0 */
  1052. while (msg_remain_len) {
  1053. /*
  1054. * if message is not a continuation of previous message
  1055. * read the tlv type and tlv length
  1056. */
  1057. if (!tlv_buf_head) {
  1058. tlv_type = HTT_STATS_TLV_TAG_GET(
  1059. *msg_word);
  1060. tlv_remain_len = HTT_STATS_TLV_LENGTH_GET(
  1061. *msg_word);
  1062. }
  1063. if (tlv_remain_len == 0) {
  1064. msg_remain_len = 0;
  1065. if (tlv_buf_head) {
  1066. qdf_mem_free(tlv_buf_head);
  1067. tlv_buf_head = NULL;
  1068. tlv_buf_tail = NULL;
  1069. }
  1070. goto error;
  1071. }
  1072. tlv_remain_len += HTT_TLV_HDR_LEN;
  1073. if ((tlv_remain_len <= msg_remain_len)) {
  1074. /* Case 3 */
  1075. if (tlv_buf_head) {
  1076. qdf_mem_copy(tlv_buf_tail,
  1077. (uint8_t *)msg_word,
  1078. tlv_remain_len);
  1079. tlv_start = (uint32_t *)tlv_buf_head;
  1080. } else {
  1081. /* Case 1 */
  1082. tlv_start = msg_word;
  1083. }
  1084. dp_htt_stats_print_tag(tlv_type, tlv_start);
  1085. msg_remain_len -= tlv_remain_len;
  1086. msg_word = (uint32_t *)
  1087. (((uint8_t *)msg_word) +
  1088. tlv_remain_len);
  1089. tlv_remain_len = 0;
  1090. if (tlv_buf_head) {
  1091. qdf_mem_free(tlv_buf_head);
  1092. tlv_buf_head = NULL;
  1093. tlv_buf_tail = NULL;
  1094. }
  1095. } else { /* tlv_remain_len > msg_remain_len */
  1096. /* Case 2 & 3 */
  1097. if (!tlv_buf_head) {
  1098. tlv_buf_head = qdf_mem_malloc(
  1099. tlv_remain_len);
  1100. if (!tlv_buf_head) {
  1101. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1102. QDF_TRACE_LEVEL_ERROR,
  1103. "Alloc failed");
  1104. goto error;
  1105. }
  1106. tlv_buf_tail = tlv_buf_head;
  1107. }
  1108. qdf_mem_copy(tlv_buf_tail, (uint8_t *)msg_word,
  1109. msg_remain_len);
  1110. tlv_remain_len -= msg_remain_len;
  1111. tlv_buf_tail += msg_remain_len;
  1112. msg_remain_len = 0;
  1113. }
  1114. }
  1115. if (htt_stats->msg_len >= DP_EXT_MSG_LENGTH) {
  1116. htt_stats->msg_len -= DP_EXT_MSG_LENGTH;
  1117. }
  1118. qdf_nbuf_free(htt_msg);
  1119. }
  1120. return;
  1121. error:
  1122. qdf_nbuf_free(htt_msg);
  1123. while ((htt_msg = qdf_nbuf_queue_remove(&htt_stats->msg))
  1124. != NULL)
  1125. qdf_nbuf_free(htt_msg);
  1126. }
  1127. void htt_t2h_stats_handler(void *context)
  1128. {
  1129. struct dp_soc *soc = (struct dp_soc *)context;
  1130. struct htt_stats_context htt_stats;
  1131. uint32_t length;
  1132. uint32_t *msg_word;
  1133. qdf_nbuf_t htt_msg = NULL;
  1134. uint8_t done;
  1135. uint8_t rem_stats;
  1136. if (!soc || !qdf_atomic_read(&soc->cmn_init_done)) {
  1137. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1138. "soc: 0x%pK, init_done: %d", soc,
  1139. qdf_atomic_read(&soc->cmn_init_done));
  1140. return;
  1141. }
  1142. qdf_mem_zero(&htt_stats, sizeof(htt_stats));
  1143. qdf_nbuf_queue_init(&htt_stats.msg);
  1144. /* pull one completed stats from soc->htt_stats_msg and process */
  1145. qdf_spin_lock_bh(&soc->htt_stats.lock);
  1146. if (!soc->htt_stats.num_stats) {
  1147. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1148. return;
  1149. }
  1150. while ((htt_msg = qdf_nbuf_queue_remove(&soc->htt_stats.msg)) != NULL) {
  1151. msg_word = (uint32_t *) qdf_nbuf_data(htt_msg);
  1152. msg_word = msg_word + HTT_T2H_EXT_STATS_TLV_START_OFFSET;
  1153. length = HTT_T2H_EXT_STATS_CONF_TLV_LENGTH_GET(*msg_word);
  1154. done = HTT_T2H_EXT_STATS_CONF_TLV_DONE_GET(*msg_word);
  1155. qdf_nbuf_queue_add(&htt_stats.msg, htt_msg);
  1156. /*
  1157. * HTT EXT stats response comes as stream of TLVs which span over
  1158. * multiple T2H messages.
  1159. * The first message will carry length of the response.
  1160. * For rest of the messages length will be zero.
  1161. */
  1162. if (length)
  1163. htt_stats.msg_len = length;
  1164. /*
  1165. * Done bit signifies that this is the last T2H buffer in the
  1166. * stream of HTT EXT STATS message
  1167. */
  1168. if (done)
  1169. break;
  1170. }
  1171. rem_stats = --soc->htt_stats.num_stats;
  1172. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1173. dp_process_htt_stat_msg(&htt_stats);
  1174. /* If there are more stats to process, schedule stats work again */
  1175. if (rem_stats)
  1176. qdf_sched_work(0, &soc->htt_stats.work);
  1177. }
  1178. /*
  1179. * dp_get_ppdu_info_user_index: Find place holder for the received
  1180. * ppdu stats info
  1181. * pdev: DP pdev handle
  1182. *
  1183. * return:user index to be populated
  1184. */
  1185. #ifdef FEATURE_PERPKT_INFO
  1186. static uint8_t dp_get_ppdu_info_user_index(struct dp_pdev *pdev,
  1187. uint16_t peer_id)
  1188. {
  1189. uint8_t user_index = 0;
  1190. struct cdp_tx_completion_ppdu *ppdu_desc;
  1191. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1192. ppdu_desc =
  1193. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1194. while ((user_index + 1) <= pdev->tx_ppdu_info.last_user) {
  1195. ppdu_user_desc = &ppdu_desc->user[user_index];
  1196. if (ppdu_user_desc->peer_id != peer_id) {
  1197. user_index++;
  1198. continue;
  1199. } else {
  1200. /* Max users possible is 8 so user array index should
  1201. * not exceed 7
  1202. */
  1203. qdf_assert_always(user_index <= CDP_MU_MAX_USER_INDEX);
  1204. return user_index;
  1205. }
  1206. }
  1207. pdev->tx_ppdu_info.last_user++;
  1208. /* Max users possible is 8 so last user should not exceed 8 */
  1209. qdf_assert_always(pdev->tx_ppdu_info.last_user <= CDP_MU_MAX_USERS);
  1210. return pdev->tx_ppdu_info.last_user - 1;
  1211. }
  1212. /*
  1213. * dp_process_ppdu_stats_common_tlv: Process htt_ppdu_stats_common_tlv
  1214. * pdev: DP pdev handle
  1215. * @tag_buf: buffer containing the tlv htt_ppdu_stats_common_tlv
  1216. *
  1217. * return:void
  1218. */
  1219. static void dp_process_ppdu_stats_common_tlv(struct dp_pdev *pdev,
  1220. uint32_t *tag_buf)
  1221. {
  1222. uint16_t frame_type;
  1223. struct cdp_tx_completion_ppdu *ppdu_desc;
  1224. htt_ppdu_stats_common_tlv *dp_stats_buf =
  1225. (htt_ppdu_stats_common_tlv *)tag_buf;
  1226. ppdu_desc =
  1227. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1228. ppdu_desc->ppdu_id = dp_stats_buf->ppdu_id;
  1229. tag_buf += 2;
  1230. ppdu_desc->num_users =
  1231. HTT_PPDU_STATS_COMMON_TLV_NUM_USERS_GET(*tag_buf);
  1232. tag_buf++;
  1233. frame_type = HTT_PPDU_STATS_COMMON_TLV_FRM_TYPE_GET(*tag_buf);
  1234. if ((frame_type == HTT_STATS_FTYPE_TIDQ_DATA_SU) ||
  1235. (frame_type == HTT_STATS_FTYPE_TIDQ_DATA_MU))
  1236. ppdu_desc->frame_type = CDP_PPDU_FTYPE_DATA;
  1237. else
  1238. ppdu_desc->frame_type = CDP_PPDU_FTYPE_CTRL;
  1239. ppdu_desc->ppdu_start_timestamp = dp_stats_buf->ppdu_start_tstmp_us;
  1240. ppdu_desc->ppdu_end_timestamp = 0; /*TODO: value to be provided by FW */
  1241. tag_buf += 6;
  1242. ppdu_desc->channel = HTT_PPDU_STATS_COMMON_TLV_CHAN_MHZ_GET(*tag_buf);
  1243. ppdu_desc->phy_mode = HTT_PPDU_STATS_COMMON_TLV_PHY_MODE_GET(*tag_buf);
  1244. }
  1245. /*
  1246. * dp_process_ppdu_stats_user_common_tlv: Process ppdu_stats_user_common
  1247. * @tag_buf: buffer containing the tlv htt_ppdu_stats_user_common_tlv
  1248. *
  1249. * return:void
  1250. */
  1251. static void dp_process_ppdu_stats_user_common_tlv(
  1252. struct dp_pdev *pdev, uint32_t *tag_buf)
  1253. {
  1254. uint16_t peer_id;
  1255. struct dp_peer *peer;
  1256. struct cdp_tx_completion_ppdu *ppdu_desc;
  1257. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1258. uint8_t curr_user_index = 0;
  1259. ppdu_desc =
  1260. (struct cdp_tx_completion_ppdu *) qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1261. tag_buf++;
  1262. peer_id = HTT_PPDU_STATS_USER_COMMON_TLV_SW_PEER_ID_GET(*tag_buf);
  1263. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1264. if (!peer)
  1265. return;
  1266. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1267. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1268. ppdu_user_desc->peer_id = peer_id;
  1269. tag_buf++;
  1270. if (HTT_PPDU_STATS_USER_COMMON_TLV_MCAST_GET(*tag_buf)) {
  1271. ppdu_user_desc->is_mcast = true;
  1272. ppdu_user_desc->mpdu_tried_mcast =
  1273. HTT_PPDU_STATS_USER_COMMON_TLV_MPDUS_TRIED_GET(*tag_buf);
  1274. } else {
  1275. ppdu_user_desc->mpdu_tried_ucast =
  1276. HTT_PPDU_STATS_USER_COMMON_TLV_MPDUS_TRIED_GET(*tag_buf);
  1277. }
  1278. ppdu_user_desc->qos_ctrl =
  1279. HTT_PPDU_STATS_USER_COMMON_TLV_QOS_CTRL_GET(*tag_buf);
  1280. ppdu_user_desc->frame_ctrl =
  1281. HTT_PPDU_STATS_USER_COMMON_TLV_FRAME_CTRL_GET(*tag_buf);
  1282. }
  1283. /**
  1284. * dp_process_ppdu_stats_user_rate_tlv() - Process htt_ppdu_stats_user_rate_tlv
  1285. * @pdev: DP pdev handle
  1286. * @tag_buf: T2H message buffer carrying the user rate TLV
  1287. *
  1288. * return:void
  1289. */
  1290. static void dp_process_ppdu_stats_user_rate_tlv(struct dp_pdev *pdev,
  1291. uint32_t *tag_buf)
  1292. {
  1293. uint16_t peer_id;
  1294. struct dp_peer *peer;
  1295. struct cdp_tx_completion_ppdu *ppdu_desc;
  1296. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1297. uint8_t curr_user_index = 0;
  1298. ppdu_desc =
  1299. (struct cdp_tx_completion_ppdu *) qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1300. tag_buf++;
  1301. peer_id = HTT_PPDU_STATS_USER_RATE_TLV_SW_PEER_ID_GET(*tag_buf);
  1302. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1303. if (!peer)
  1304. return;
  1305. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1306. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1307. ppdu_user_desc->peer_id = peer_id;
  1308. ppdu_user_desc->tid =
  1309. HTT_PPDU_STATS_USER_RATE_TLV_TID_NUM_GET(*tag_buf);
  1310. qdf_mem_copy(ppdu_user_desc->mac_addr, peer->mac_addr.raw,
  1311. DP_MAC_ADDR_LEN);
  1312. tag_buf += 5;
  1313. ppdu_user_desc->ltf_size =
  1314. HTT_PPDU_STATS_USER_RATE_TLV_LTF_SIZE_GET(*tag_buf);
  1315. ppdu_user_desc->stbc =
  1316. HTT_PPDU_STATS_USER_RATE_TLV_STBC_GET(*tag_buf);
  1317. ppdu_user_desc->he_re =
  1318. HTT_PPDU_STATS_USER_RATE_TLV_HE_RE_GET(*tag_buf);
  1319. ppdu_user_desc->txbf =
  1320. HTT_PPDU_STATS_USER_RATE_TLV_TXBF_GET(*tag_buf);
  1321. ppdu_user_desc->bw =
  1322. HTT_PPDU_STATS_USER_RATE_TLV_BW_GET(*tag_buf);
  1323. ppdu_user_desc->nss = HTT_PPDU_STATS_USER_RATE_TLV_NSS_GET(*tag_buf);
  1324. ppdu_user_desc->mcs = HTT_PPDU_STATS_USER_RATE_TLV_MCS_GET(*tag_buf);
  1325. ppdu_user_desc->preamble =
  1326. HTT_PPDU_STATS_USER_RATE_TLV_PREAMBLE_GET(*tag_buf);
  1327. ppdu_user_desc->gi = HTT_PPDU_STATS_USER_RATE_TLV_GI_GET(*tag_buf);
  1328. ppdu_user_desc->dcm = HTT_PPDU_STATS_USER_RATE_TLV_DCM_GET(*tag_buf);
  1329. ppdu_user_desc->ldpc = HTT_PPDU_STATS_USER_RATE_TLV_LDPC_GET(*tag_buf);
  1330. ppdu_user_desc->ppdu_type =
  1331. HTT_PPDU_STATS_USER_RATE_TLV_PPDU_TYPE_GET(*tag_buf);
  1332. }
  1333. /*
  1334. * dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv: Process
  1335. * htt_ppdu_stats_enq_mpdu_bitmap_64_tlv
  1336. * pdev: DP PDEV handle
  1337. * @tag_buf: buffer containing the tlv htt_ppdu_stats_enq_mpdu_bitmap_64_tlv
  1338. *
  1339. * return:void
  1340. */
  1341. static void dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv(
  1342. struct dp_pdev *pdev, uint32_t *tag_buf)
  1343. {
  1344. htt_ppdu_stats_enq_mpdu_bitmap_64_tlv *dp_stats_buf =
  1345. (htt_ppdu_stats_enq_mpdu_bitmap_64_tlv *)tag_buf;
  1346. struct cdp_tx_completion_ppdu *ppdu_desc;
  1347. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1348. uint8_t curr_user_index = 0;
  1349. uint16_t peer_id;
  1350. struct dp_peer *peer;
  1351. ppdu_desc =
  1352. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1353. tag_buf++;
  1354. peer_id =
  1355. HTT_PPDU_STATS_ENQ_MPDU_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  1356. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1357. if (!peer)
  1358. return;
  1359. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1360. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1361. ppdu_user_desc->peer_id = peer_id;
  1362. ppdu_user_desc->start_seq = dp_stats_buf->start_seq;
  1363. qdf_mem_copy(&ppdu_user_desc->enq_bitmap, &dp_stats_buf->enq_bitmap,
  1364. CDP_BA_64_BIT_MAP_SIZE_DWORDS);
  1365. }
  1366. /*
  1367. * dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv: Process
  1368. * htt_ppdu_stats_enq_mpdu_bitmap_256_tlv
  1369. * soc: DP SOC handle
  1370. * @tag_buf: buffer containing the tlv htt_ppdu_stats_enq_mpdu_bitmap_256_tlv
  1371. *
  1372. * return:void
  1373. */
  1374. static void dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv(
  1375. struct dp_pdev *pdev, uint32_t *tag_buf)
  1376. {
  1377. htt_ppdu_stats_enq_mpdu_bitmap_256_tlv *dp_stats_buf =
  1378. (htt_ppdu_stats_enq_mpdu_bitmap_256_tlv *)tag_buf;
  1379. struct cdp_tx_completion_ppdu *ppdu_desc;
  1380. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1381. uint8_t curr_user_index = 0;
  1382. uint16_t peer_id;
  1383. struct dp_peer *peer;
  1384. ppdu_desc =
  1385. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1386. tag_buf++;
  1387. peer_id =
  1388. HTT_PPDU_STATS_ENQ_MPDU_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  1389. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1390. if (!peer)
  1391. return;
  1392. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1393. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1394. ppdu_user_desc->peer_id = peer_id;
  1395. ppdu_user_desc->start_seq = dp_stats_buf->start_seq;
  1396. qdf_mem_copy(&ppdu_user_desc->enq_bitmap, &dp_stats_buf->enq_bitmap,
  1397. CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  1398. }
  1399. /*
  1400. * dp_process_ppdu_stats_user_cmpltn_common_tlv: Process
  1401. * htt_ppdu_stats_user_cmpltn_common_tlv
  1402. * soc: DP SOC handle
  1403. * @tag_buf: buffer containing the tlv htt_ppdu_stats_user_cmpltn_common_tlv
  1404. *
  1405. * return:void
  1406. */
  1407. static void dp_process_ppdu_stats_user_cmpltn_common_tlv(
  1408. struct dp_pdev *pdev, uint32_t *tag_buf)
  1409. {
  1410. uint16_t peer_id;
  1411. struct dp_peer *peer;
  1412. struct cdp_tx_completion_ppdu *ppdu_desc;
  1413. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1414. uint8_t curr_user_index = 0;
  1415. htt_ppdu_stats_user_cmpltn_common_tlv *dp_stats_buf =
  1416. (htt_ppdu_stats_user_cmpltn_common_tlv *)tag_buf;
  1417. ppdu_desc =
  1418. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1419. tag_buf++;
  1420. peer_id =
  1421. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_SW_PEER_ID_GET(*tag_buf);
  1422. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1423. if (!peer)
  1424. return;
  1425. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1426. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1427. ppdu_user_desc->peer_id = peer_id;
  1428. ppdu_user_desc->completion_status =
  1429. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_COMPLETION_STATUS_GET(
  1430. *tag_buf);
  1431. ppdu_user_desc->tid =
  1432. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_TID_NUM_GET(*tag_buf);
  1433. tag_buf++;
  1434. ppdu_desc->ack_rssi = dp_stats_buf->ack_rssi;
  1435. tag_buf++;
  1436. ppdu_user_desc->mpdu_success =
  1437. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_MPDU_SUCCESS_GET(*tag_buf);
  1438. tag_buf++;
  1439. ppdu_user_desc->long_retries =
  1440. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_LONG_RETRY_GET(*tag_buf);
  1441. ppdu_user_desc->short_retries =
  1442. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_SHORT_RETRY_GET(*tag_buf);
  1443. ppdu_user_desc->is_ampdu =
  1444. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_IS_AMPDU_GET(*tag_buf);
  1445. }
  1446. /*
  1447. * dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv: Process
  1448. * htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv
  1449. * pdev: DP PDEV handle
  1450. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv
  1451. *
  1452. * return:void
  1453. */
  1454. static void dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv(
  1455. struct dp_pdev *pdev, uint32_t *tag_buf)
  1456. {
  1457. htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv *dp_stats_buf =
  1458. (htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv *)tag_buf;
  1459. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1460. struct cdp_tx_completion_ppdu *ppdu_desc;
  1461. uint8_t curr_user_index = 0;
  1462. uint16_t peer_id;
  1463. struct dp_peer *peer;
  1464. ppdu_desc =
  1465. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1466. tag_buf++;
  1467. peer_id =
  1468. HTT_PPDU_STATS_USER_CMPLTN_BA_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  1469. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1470. if (!peer)
  1471. return;
  1472. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1473. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1474. ppdu_user_desc->peer_id = peer_id;
  1475. ppdu_user_desc->ba_seq_no = dp_stats_buf->ba_seq_no;
  1476. qdf_mem_copy(&ppdu_user_desc->ba_bitmap, &dp_stats_buf->ba_bitmap,
  1477. CDP_BA_64_BIT_MAP_SIZE_DWORDS);
  1478. }
  1479. /*
  1480. * dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv: Process
  1481. * htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv
  1482. * pdev: DP PDEV handle
  1483. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv
  1484. *
  1485. * return:void
  1486. */
  1487. static void dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv(
  1488. struct dp_pdev *pdev, uint32_t *tag_buf)
  1489. {
  1490. htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv *dp_stats_buf =
  1491. (htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv *)tag_buf;
  1492. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1493. struct cdp_tx_completion_ppdu *ppdu_desc;
  1494. uint8_t curr_user_index = 0;
  1495. uint16_t peer_id;
  1496. struct dp_peer *peer;
  1497. ppdu_desc =
  1498. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1499. tag_buf++;
  1500. peer_id =
  1501. HTT_PPDU_STATS_USER_CMPLTN_BA_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  1502. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1503. if (!peer)
  1504. return;
  1505. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1506. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1507. ppdu_user_desc->peer_id = peer_id;
  1508. ppdu_user_desc->ba_seq_no = dp_stats_buf->ba_seq_no;
  1509. qdf_mem_copy(&ppdu_user_desc->ba_bitmap, &dp_stats_buf->ba_bitmap,
  1510. CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  1511. }
  1512. /*
  1513. * dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv: Process
  1514. * htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  1515. * pdev: DP PDE handle
  1516. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  1517. *
  1518. * return:void
  1519. */
  1520. static void dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv(
  1521. struct dp_pdev *pdev, uint32_t *tag_buf)
  1522. {
  1523. uint16_t peer_id;
  1524. struct dp_peer *peer;
  1525. struct cdp_tx_completion_ppdu *ppdu_desc;
  1526. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1527. uint8_t curr_user_index = 0;
  1528. ppdu_desc =
  1529. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1530. tag_buf += 2;
  1531. peer_id =
  1532. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_SW_PEER_ID_GET(*tag_buf);
  1533. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1534. if (!peer)
  1535. return;
  1536. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1537. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1538. ppdu_user_desc->peer_id = peer_id;
  1539. tag_buf += 2;
  1540. ppdu_user_desc->num_mpdu =
  1541. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_NUM_MPDU_GET(*tag_buf);
  1542. ppdu_user_desc->num_msdu =
  1543. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_NUM_MSDU_GET(*tag_buf);
  1544. }
  1545. /*
  1546. * dp_process_ppdu_stats_user_common_array_tlv: Process
  1547. * htt_ppdu_stats_user_common_array_tlv
  1548. * pdev: DP PDEV handle
  1549. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  1550. *
  1551. * return:void
  1552. */
  1553. static void dp_process_ppdu_stats_user_common_array_tlv(struct dp_pdev *pdev,
  1554. uint32_t *tag_buf)
  1555. {
  1556. uint32_t peer_id;
  1557. struct dp_peer *peer;
  1558. struct cdp_tx_completion_ppdu *ppdu_desc;
  1559. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1560. uint8_t curr_user_index = 0;
  1561. struct htt_tx_ppdu_stats_info *dp_stats_buf;
  1562. ppdu_desc =
  1563. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1564. tag_buf += 2;
  1565. dp_stats_buf = (struct htt_tx_ppdu_stats_info *)tag_buf;
  1566. tag_buf += 4;
  1567. peer_id =
  1568. HTT_PPDU_STATS_ARRAY_ITEM_TLV_PEERID_GET(*tag_buf);
  1569. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1570. if (!peer) {
  1571. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1572. "Invalid peer");
  1573. return;
  1574. }
  1575. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1576. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1577. ppdu_user_desc->success_bytes = dp_stats_buf->tx_success_bytes;
  1578. ppdu_user_desc->retry_bytes = dp_stats_buf->tx_retry_bytes;
  1579. ppdu_user_desc->failed_bytes = dp_stats_buf->tx_failed_bytes;
  1580. tag_buf++;
  1581. ppdu_user_desc->success_msdus =
  1582. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_SUCC_MSDUS_GET(*tag_buf);
  1583. ppdu_user_desc->retry_bytes =
  1584. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_RETRY_MSDUS_GET(*tag_buf);
  1585. tag_buf++;
  1586. ppdu_user_desc->failed_msdus =
  1587. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_FAILED_MSDUS_GET(*tag_buf);
  1588. ppdu_user_desc->tx_duration =
  1589. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_DUR_GET(*tag_buf);
  1590. }
  1591. /*
  1592. * dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv: Process
  1593. * htt_ppdu_stats_tx_mgmtctrl_payload_tlv
  1594. * @pdev: DP PDEV handle
  1595. * @tag_buf: buffer containing the htt_ppdu_stats_tx_mgmtctrl_payload_tlv
  1596. * @length: tlv_length
  1597. *
  1598. * return:void
  1599. */
  1600. static void dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv(
  1601. struct dp_pdev *pdev, uint32_t *tag_buf, uint32_t length)
  1602. {
  1603. htt_ppdu_stats_tx_mgmtctrl_payload_tlv *dp_stats_buf =
  1604. (htt_ppdu_stats_tx_mgmtctrl_payload_tlv *)tag_buf;
  1605. qdf_nbuf_t nbuf = NULL;
  1606. uint32_t payload_size = length - HTT_MGMT_CTRL_TLV_RESERVERD_LEN;
  1607. nbuf = qdf_nbuf_alloc(pdev->soc->osdev, payload_size, 0, 4, true);
  1608. if (!nbuf) {
  1609. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1610. "Nbuf Allocation failed for Mgmt. payload");
  1611. qdf_assert(0);
  1612. return;
  1613. }
  1614. qdf_nbuf_put_tail(nbuf, payload_size);
  1615. qdf_mem_copy(qdf_nbuf_data(nbuf), dp_stats_buf->payload, payload_size);
  1616. dp_wdi_event_handler(WDI_EVENT_TX_MGMT_CTRL, pdev->soc,
  1617. nbuf, HTT_INVALID_PEER,
  1618. WDI_NO_VAL, pdev->pdev_id);
  1619. }
  1620. /**
  1621. * dp_process_ppdu_tag(): Function to process the PPDU TLVs
  1622. * @soc: DP Physical device (radio) handle
  1623. * @tag_buf: TLV buffer
  1624. *
  1625. * return: void
  1626. */
  1627. static void dp_process_ppdu_tag(struct dp_pdev *pdev, uint32_t *tag_buf,
  1628. uint32_t tlv_len)
  1629. {
  1630. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  1631. switch (tlv_type) {
  1632. case HTT_PPDU_STATS_COMMON_TLV:
  1633. dp_process_ppdu_stats_common_tlv(pdev, tag_buf);
  1634. break;
  1635. case HTT_PPDU_STATS_USR_COMMON_TLV:
  1636. dp_process_ppdu_stats_user_common_tlv(pdev, tag_buf);
  1637. break;
  1638. case HTT_PPDU_STATS_USR_RATE_TLV:
  1639. qdf_assert_always(tlv_len ==
  1640. sizeof(htt_ppdu_stats_user_rate_tlv));
  1641. dp_process_ppdu_stats_user_rate_tlv(pdev, tag_buf);
  1642. break;
  1643. case HTT_PPDU_STATS_USR_MPDU_ENQ_BITMAP_64_TLV:
  1644. dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv(pdev, tag_buf);
  1645. break;
  1646. case HTT_PPDU_STATS_USR_MPDU_ENQ_BITMAP_256_TLV:
  1647. dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv(pdev, tag_buf);
  1648. break;
  1649. case HTT_PPDU_STATS_USR_COMPLTN_COMMON_TLV:
  1650. dp_process_ppdu_stats_user_cmpltn_common_tlv(pdev, tag_buf);
  1651. break;
  1652. case HTT_PPDU_STATS_USR_COMPLTN_BA_BITMAP_64_TLV:
  1653. dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv(pdev,
  1654. tag_buf);
  1655. break;
  1656. case HTT_PPDU_STATS_USR_COMPLTN_BA_BITMAP_256_TLV:
  1657. dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv(pdev,
  1658. tag_buf);
  1659. break;
  1660. case HTT_PPDU_STATS_USR_COMPLTN_ACK_BA_STATUS_TLV:
  1661. dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv(pdev,
  1662. tag_buf);
  1663. break;
  1664. case HTT_PPDU_STATS_USR_COMMON_ARRAY_TLV:
  1665. dp_process_ppdu_stats_user_common_array_tlv(pdev,
  1666. tag_buf);
  1667. break;
  1668. case HTT_PPDU_STATS_TX_MGMTCTRL_PAYLOAD_TLV:
  1669. dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv(pdev,
  1670. tag_buf, tlv_len);
  1671. break;
  1672. default:
  1673. break;
  1674. }
  1675. }
  1676. static QDF_STATUS dp_htt_process_tlv(struct dp_pdev *pdev,
  1677. qdf_nbuf_t htt_t2h_msg)
  1678. {
  1679. uint32_t length;
  1680. uint32_t ppdu_id;
  1681. uint8_t tlv_type;
  1682. uint32_t tlv_length;
  1683. uint8_t *tlv_buf;
  1684. QDF_STATUS status = QDF_STATUS_E_PENDING;
  1685. uint32_t *msg_word = (uint32_t *) qdf_nbuf_data(htt_t2h_msg);
  1686. length = HTT_T2H_PPDU_STATS_PAYLOAD_SIZE_GET(*msg_word);
  1687. msg_word = msg_word + 1;
  1688. ppdu_id = HTT_T2H_PPDU_STATS_PPDU_ID_GET(*msg_word);
  1689. msg_word = msg_word + 3;
  1690. while (length > 0) {
  1691. tlv_buf = (uint8_t *)msg_word;
  1692. tlv_type = HTT_STATS_TLV_TAG_GET(*msg_word);
  1693. tlv_length = HTT_STATS_TLV_LENGTH_GET(*msg_word);
  1694. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  1695. "HTT PPDU Tag %d, Length %d", tlv_type,
  1696. tlv_length);
  1697. if (tlv_length == 0)
  1698. break;
  1699. if (tlv_type == HTT_PPDU_STATS_SCH_CMD_STATUS_TLV)
  1700. status = QDF_STATUS_SUCCESS;
  1701. tlv_length += HTT_TLV_HDR_LEN;
  1702. dp_process_ppdu_tag(pdev, msg_word, tlv_length);
  1703. msg_word = (uint32_t *)((uint8_t *)tlv_buf + tlv_length);
  1704. length -= (tlv_length);
  1705. }
  1706. return status;
  1707. }
  1708. #endif /* FEATURE_PERPKT_INFO */
  1709. /**
  1710. * dp_txrx_ppdu_stats_handler() - Function to process HTT PPDU stats from FW
  1711. * @soc: DP SOC handle
  1712. * @pdev_id: pdev id
  1713. * @htt_t2h_msg: HTT message nbuf
  1714. *
  1715. * return:void
  1716. */
  1717. #if defined(CONFIG_WIN) && WDI_EVENT_ENABLE
  1718. #ifdef FEATURE_PERPKT_INFO
  1719. static void dp_txrx_ppdu_stats_handler(struct dp_soc *soc,
  1720. uint8_t pdev_id, qdf_nbuf_t htt_t2h_msg)
  1721. {
  1722. struct dp_pdev *pdev = soc->pdev_list[pdev_id];
  1723. struct dp_vdev *vdev;
  1724. struct dp_peer *peer;
  1725. struct cdp_tx_completion_ppdu *ppdu_desc;
  1726. int status;
  1727. int i;
  1728. if (!pdev->enhanced_stats_en && !pdev->tx_sniffer_enable)
  1729. return;
  1730. if (!pdev->tx_ppdu_info.buf) {
  1731. /*
  1732. * Todo: For MU/OFDMA, we need to account for multiple user
  1733. * descriptors in a PPDU, in skb size.
  1734. * The allocation has to be moved to ppdu_cmn tlv processing
  1735. */
  1736. pdev->tx_ppdu_info.buf = qdf_nbuf_alloc(soc->osdev,
  1737. sizeof(struct cdp_tx_completion_ppdu), 0, 4,
  1738. TRUE);
  1739. if (!pdev->tx_ppdu_info.buf) {
  1740. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1741. "Nbuf Allocation failed for HTT PPDU");
  1742. return;
  1743. }
  1744. qdf_mem_zero(qdf_nbuf_data(pdev->tx_ppdu_info.buf),
  1745. sizeof(struct cdp_tx_completion_ppdu));
  1746. if (qdf_nbuf_put_tail(pdev->tx_ppdu_info.buf,
  1747. sizeof(struct cdp_tx_completion_ppdu)) == NULL) {
  1748. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1749. "No tailroom for HTT PPDU");
  1750. return;
  1751. }
  1752. }
  1753. status = dp_htt_process_tlv(pdev, htt_t2h_msg);
  1754. if (status == QDF_STATUS_SUCCESS) {
  1755. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  1756. qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1757. vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  1758. ppdu_desc->vdev_id);
  1759. for (i = 0; i < ppdu_desc->num_users; i++) {
  1760. peer = dp_peer_find_by_id(soc,
  1761. ppdu_desc->user[i].peer_id);
  1762. if (!peer)
  1763. continue;
  1764. ppdu_desc->num_mpdu += ppdu_desc->user[i].num_mpdu;
  1765. ppdu_desc->num_msdu += ppdu_desc->user[i].num_msdu;
  1766. if (ppdu_desc->frame_type == CDP_PPDU_FTYPE_DATA) {
  1767. dp_tx_stats_update(soc, peer,
  1768. &ppdu_desc->user[i],
  1769. ppdu_desc->ack_rssi);
  1770. }
  1771. }
  1772. dp_wdi_event_handler(WDI_EVENT_TX_PPDU_DESC, soc,
  1773. pdev->tx_ppdu_info.buf, HTT_INVALID_PEER,
  1774. WDI_NO_VAL, pdev_id);
  1775. pdev->tx_ppdu_info.buf = NULL;
  1776. pdev->tx_ppdu_info.last_user = 0;
  1777. }
  1778. }
  1779. #else
  1780. static void dp_txrx_ppdu_stats_handler(struct dp_soc *soc,
  1781. uint8_t pdev_id, qdf_nbuf_t htt_t2h_msg)
  1782. {
  1783. }
  1784. #endif
  1785. #endif
  1786. /**
  1787. * dp_txrx_fw_stats_handler() - Function to process HTT EXT stats
  1788. * @soc: DP SOC handle
  1789. * @htt_t2h_msg: HTT message nbuf
  1790. *
  1791. * return:void
  1792. */
  1793. static inline void dp_txrx_fw_stats_handler(struct dp_soc *soc,
  1794. qdf_nbuf_t htt_t2h_msg)
  1795. {
  1796. uint8_t done;
  1797. qdf_nbuf_t msg_copy;
  1798. uint32_t *msg_word;
  1799. msg_word = (uint32_t *) qdf_nbuf_data(htt_t2h_msg);
  1800. msg_word = msg_word + 3;
  1801. done = HTT_T2H_EXT_STATS_CONF_TLV_DONE_GET(*msg_word);
  1802. /*
  1803. * HTT EXT stats response comes as stream of TLVs which span over
  1804. * multiple T2H messages.
  1805. * The first message will carry length of the response.
  1806. * For rest of the messages length will be zero.
  1807. *
  1808. * Clone the T2H message buffer and store it in a list to process
  1809. * it later.
  1810. *
  1811. * The original T2H message buffers gets freed in the T2H HTT event
  1812. * handler
  1813. */
  1814. msg_copy = qdf_nbuf_clone(htt_t2h_msg);
  1815. if (!msg_copy) {
  1816. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  1817. "T2H messge clone failed for HTT EXT STATS");
  1818. goto error;
  1819. }
  1820. qdf_spin_lock_bh(&soc->htt_stats.lock);
  1821. qdf_nbuf_queue_add(&soc->htt_stats.msg, msg_copy);
  1822. /*
  1823. * Done bit signifies that this is the last T2H buffer in the stream of
  1824. * HTT EXT STATS message
  1825. */
  1826. if (done) {
  1827. soc->htt_stats.num_stats++;
  1828. qdf_sched_work(0, &soc->htt_stats.work);
  1829. }
  1830. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1831. return;
  1832. error:
  1833. qdf_spin_lock_bh(&soc->htt_stats.lock);
  1834. while ((msg_copy = qdf_nbuf_queue_remove(&soc->htt_stats.msg))
  1835. != NULL) {
  1836. qdf_nbuf_free(msg_copy);
  1837. }
  1838. soc->htt_stats.num_stats = 0;
  1839. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1840. return;
  1841. }
  1842. /*
  1843. * htt_soc_attach_target() - SOC level HTT setup
  1844. * @htt_soc: HTT SOC handle
  1845. *
  1846. * Return: 0 on success; error code on failure
  1847. */
  1848. int htt_soc_attach_target(void *htt_soc)
  1849. {
  1850. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  1851. return htt_h2t_ver_req_msg(soc);
  1852. }
  1853. /*
  1854. * dp_htt_t2h_msg_handler() - Generic Target to host Msg/event handler
  1855. * @context: Opaque context (HTT SOC handle)
  1856. * @pkt: HTC packet
  1857. */
  1858. static void dp_htt_t2h_msg_handler(void *context, HTC_PACKET *pkt)
  1859. {
  1860. struct htt_soc *soc = (struct htt_soc *) context;
  1861. qdf_nbuf_t htt_t2h_msg = (qdf_nbuf_t) pkt->pPktContext;
  1862. u_int32_t *msg_word;
  1863. enum htt_t2h_msg_type msg_type;
  1864. /* check for successful message reception */
  1865. if (pkt->Status != QDF_STATUS_SUCCESS) {
  1866. if (pkt->Status != QDF_STATUS_E_CANCELED)
  1867. soc->stats.htc_err_cnt++;
  1868. qdf_nbuf_free(htt_t2h_msg);
  1869. return;
  1870. }
  1871. /* TODO: Check if we should pop the HTC/HTT header alignment padding */
  1872. msg_word = (u_int32_t *) qdf_nbuf_data(htt_t2h_msg);
  1873. msg_type = HTT_T2H_MSG_TYPE_GET(*msg_word);
  1874. switch (msg_type) {
  1875. case HTT_T2H_MSG_TYPE_PEER_MAP:
  1876. {
  1877. u_int8_t mac_addr_deswizzle_buf[HTT_MAC_ADDR_LEN];
  1878. u_int8_t *peer_mac_addr;
  1879. u_int16_t peer_id;
  1880. u_int16_t hw_peer_id;
  1881. u_int8_t vdev_id;
  1882. peer_id = HTT_RX_PEER_MAP_PEER_ID_GET(*msg_word);
  1883. hw_peer_id =
  1884. HTT_RX_PEER_MAP_HW_PEER_ID_GET(*(msg_word+2));
  1885. vdev_id = HTT_RX_PEER_MAP_VDEV_ID_GET(*msg_word);
  1886. peer_mac_addr = htt_t2h_mac_addr_deswizzle(
  1887. (u_int8_t *) (msg_word+1),
  1888. &mac_addr_deswizzle_buf[0]);
  1889. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1890. QDF_TRACE_LEVEL_INFO,
  1891. "HTT_T2H_MSG_TYPE_PEER_MAP msg for peer id %d vdev id %d n",
  1892. peer_id, vdev_id);
  1893. dp_rx_peer_map_handler(soc->dp_soc, peer_id, hw_peer_id,
  1894. vdev_id, peer_mac_addr);
  1895. break;
  1896. }
  1897. case HTT_T2H_MSG_TYPE_PEER_UNMAP:
  1898. {
  1899. u_int16_t peer_id;
  1900. peer_id = HTT_RX_PEER_UNMAP_PEER_ID_GET(*msg_word);
  1901. dp_rx_peer_unmap_handler(soc->dp_soc, peer_id);
  1902. break;
  1903. }
  1904. case HTT_T2H_MSG_TYPE_SEC_IND:
  1905. {
  1906. u_int16_t peer_id;
  1907. enum htt_sec_type sec_type;
  1908. int is_unicast;
  1909. peer_id = HTT_SEC_IND_PEER_ID_GET(*msg_word);
  1910. sec_type = HTT_SEC_IND_SEC_TYPE_GET(*msg_word);
  1911. is_unicast = HTT_SEC_IND_UNICAST_GET(*msg_word);
  1912. /* point to the first part of the Michael key */
  1913. msg_word++;
  1914. dp_rx_sec_ind_handler(
  1915. soc->dp_soc, peer_id, sec_type, is_unicast,
  1916. msg_word, msg_word + 2);
  1917. break;
  1918. }
  1919. #if defined(CONFIG_WIN) && WDI_EVENT_ENABLE
  1920. #ifndef REMOVE_PKT_LOG
  1921. case HTT_T2H_MSG_TYPE_PPDU_STATS_IND:
  1922. {
  1923. u_int8_t pdev_id;
  1924. qdf_nbuf_set_pktlen(htt_t2h_msg, HTT_T2H_MAX_MSG_SIZE);
  1925. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  1926. "received HTT_T2H_MSG_TYPE_PPDU_STATS_IND\n");
  1927. pdev_id = HTT_T2H_PPDU_STATS_MAC_ID_GET(*msg_word);
  1928. pdev_id = DP_HW2SW_MACID(pdev_id);
  1929. dp_txrx_ppdu_stats_handler(soc->dp_soc, pdev_id,
  1930. htt_t2h_msg);
  1931. dp_wdi_event_handler(WDI_EVENT_LITE_T2H, soc->dp_soc,
  1932. htt_t2h_msg, HTT_INVALID_PEER, WDI_NO_VAL,
  1933. pdev_id);
  1934. break;
  1935. }
  1936. case HTT_T2H_MSG_TYPE_PKTLOG:
  1937. {
  1938. uint8_t pdev_id;
  1939. uint32_t *pl_hdr;
  1940. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  1941. "received HTT_T2H_MSG_TYPE_PKTLOG\n");
  1942. pdev_id = HTT_T2H_PKTLOG_MAC_ID_GET(*msg_word);
  1943. pdev_id = DP_HW2SW_MACID(pdev_id);
  1944. pl_hdr = (msg_word + 1);
  1945. dp_wdi_event_handler(WDI_EVENT_OFFLOAD_ALL, soc->dp_soc,
  1946. pl_hdr, HTT_INVALID_PEER, WDI_NO_VAL,
  1947. pdev_id);
  1948. break;
  1949. }
  1950. #endif
  1951. #endif
  1952. case HTT_T2H_MSG_TYPE_VERSION_CONF:
  1953. {
  1954. htc_pm_runtime_put(soc->htc_soc);
  1955. soc->tgt_ver.major = HTT_VER_CONF_MAJOR_GET(*msg_word);
  1956. soc->tgt_ver.minor = HTT_VER_CONF_MINOR_GET(*msg_word);
  1957. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  1958. "target uses HTT version %d.%d; host uses %d.%d\n",
  1959. soc->tgt_ver.major, soc->tgt_ver.minor,
  1960. HTT_CURRENT_VERSION_MAJOR,
  1961. HTT_CURRENT_VERSION_MINOR);
  1962. if (soc->tgt_ver.major != HTT_CURRENT_VERSION_MAJOR) {
  1963. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1964. QDF_TRACE_LEVEL_ERROR,
  1965. "*** Incompatible host/target HTT versions!\n");
  1966. }
  1967. /* abort if the target is incompatible with the host */
  1968. qdf_assert(soc->tgt_ver.major ==
  1969. HTT_CURRENT_VERSION_MAJOR);
  1970. if (soc->tgt_ver.minor != HTT_CURRENT_VERSION_MINOR) {
  1971. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1972. QDF_TRACE_LEVEL_WARN,
  1973. "*** Warning: host/target HTT versions"
  1974. " are different, though compatible!\n");
  1975. }
  1976. break;
  1977. }
  1978. case HTT_T2H_MSG_TYPE_RX_ADDBA:
  1979. {
  1980. uint16_t peer_id;
  1981. uint8_t tid;
  1982. uint8_t win_sz;
  1983. uint16_t status;
  1984. struct dp_peer *peer;
  1985. /*
  1986. * Update REO Queue Desc with new values
  1987. */
  1988. peer_id = HTT_RX_ADDBA_PEER_ID_GET(*msg_word);
  1989. tid = HTT_RX_ADDBA_TID_GET(*msg_word);
  1990. win_sz = HTT_RX_ADDBA_WIN_SIZE_GET(*msg_word);
  1991. peer = dp_peer_find_by_id(soc->dp_soc, peer_id);
  1992. /*
  1993. * Window size needs to be incremented by 1
  1994. * since fw needs to represent a value of 256
  1995. * using just 8 bits
  1996. */
  1997. if (peer) {
  1998. status = dp_addba_requestprocess_wifi3(peer,
  1999. 0, tid, 0, win_sz + 1, 0xffff);
  2000. QDF_TRACE(QDF_MODULE_ID_TXRX,
  2001. QDF_TRACE_LEVEL_INFO,
  2002. FL("PeerID %d BAW %d TID %d stat %d\n"),
  2003. peer_id, win_sz, tid, status);
  2004. } else {
  2005. QDF_TRACE(QDF_MODULE_ID_TXRX,
  2006. QDF_TRACE_LEVEL_ERROR,
  2007. FL("Peer not found peer id %d\n"),
  2008. peer_id);
  2009. }
  2010. break;
  2011. }
  2012. case HTT_T2H_MSG_TYPE_EXT_STATS_CONF:
  2013. {
  2014. dp_txrx_fw_stats_handler(soc->dp_soc, htt_t2h_msg);
  2015. break;
  2016. }
  2017. default:
  2018. break;
  2019. };
  2020. /* Free the indication buffer */
  2021. qdf_nbuf_free(htt_t2h_msg);
  2022. }
  2023. /*
  2024. * dp_htt_h2t_full() - Send full handler (called from HTC)
  2025. * @context: Opaque context (HTT SOC handle)
  2026. * @pkt: HTC packet
  2027. *
  2028. * Return: enum htc_send_full_action
  2029. */
  2030. static enum htc_send_full_action
  2031. dp_htt_h2t_full(void *context, HTC_PACKET *pkt)
  2032. {
  2033. return HTC_SEND_FULL_KEEP;
  2034. }
  2035. /*
  2036. * dp_htt_hif_t2h_hp_callback() - HIF callback for high priority T2H messages
  2037. * @context: Opaque context (HTT SOC handle)
  2038. * @nbuf: nbuf containing T2H message
  2039. * @pipe_id: HIF pipe ID
  2040. *
  2041. * Return: QDF_STATUS
  2042. *
  2043. * TODO: Temporary change to bypass HTC connection for this new HIF pipe, which
  2044. * will be used for packet log and other high-priority HTT messsages. Proper
  2045. * HTC connection to be added later once required FW changes are available
  2046. */
  2047. static QDF_STATUS
  2048. dp_htt_hif_t2h_hp_callback (void *context, qdf_nbuf_t nbuf, uint8_t pipe_id)
  2049. {
  2050. A_STATUS rc = QDF_STATUS_SUCCESS;
  2051. HTC_PACKET htc_pkt;
  2052. qdf_assert_always(pipe_id == DP_HTT_T2H_HP_PIPE);
  2053. qdf_mem_zero(&htc_pkt, sizeof(htc_pkt));
  2054. htc_pkt.Status = QDF_STATUS_SUCCESS;
  2055. htc_pkt.pPktContext = (void *)nbuf;
  2056. dp_htt_t2h_msg_handler(context, &htc_pkt);
  2057. return rc;
  2058. }
  2059. /*
  2060. * htt_htc_soc_attach() - Register SOC level HTT instance with HTC
  2061. * @htt_soc: HTT SOC handle
  2062. *
  2063. * Return: 0 on success; error code on failure
  2064. */
  2065. static int
  2066. htt_htc_soc_attach(struct htt_soc *soc)
  2067. {
  2068. struct htc_service_connect_req connect;
  2069. struct htc_service_connect_resp response;
  2070. A_STATUS status;
  2071. qdf_mem_set(&connect, sizeof(connect), 0);
  2072. qdf_mem_set(&response, sizeof(response), 0);
  2073. connect.pMetaData = NULL;
  2074. connect.MetaDataLength = 0;
  2075. connect.EpCallbacks.pContext = soc;
  2076. connect.EpCallbacks.EpTxComplete = dp_htt_h2t_send_complete;
  2077. connect.EpCallbacks.EpTxCompleteMultiple = NULL;
  2078. connect.EpCallbacks.EpRecv = dp_htt_t2h_msg_handler;
  2079. /* rx buffers currently are provided by HIF, not by EpRecvRefill */
  2080. connect.EpCallbacks.EpRecvRefill = NULL;
  2081. /* N/A, fill is done by HIF */
  2082. connect.EpCallbacks.RecvRefillWaterMark = 1;
  2083. connect.EpCallbacks.EpSendFull = dp_htt_h2t_full;
  2084. /*
  2085. * Specify how deep to let a queue get before htc_send_pkt will
  2086. * call the EpSendFull function due to excessive send queue depth.
  2087. */
  2088. connect.MaxSendQueueDepth = DP_HTT_MAX_SEND_QUEUE_DEPTH;
  2089. /* disable flow control for HTT data message service */
  2090. connect.ConnectionFlags |= HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  2091. /* connect to control service */
  2092. connect.service_id = HTT_DATA_MSG_SVC;
  2093. status = htc_connect_service(soc->htc_soc, &connect, &response);
  2094. if (status != A_OK)
  2095. return QDF_STATUS_E_FAILURE;
  2096. soc->htc_endpoint = response.Endpoint;
  2097. dp_hif_update_pipe_callback(soc->dp_soc, (void *)soc,
  2098. dp_htt_hif_t2h_hp_callback, DP_HTT_T2H_HP_PIPE);
  2099. return 0; /* success */
  2100. }
  2101. /*
  2102. * htt_soc_attach() - SOC level HTT initialization
  2103. * @dp_soc: Opaque Data path SOC handle
  2104. * @osif_soc: Opaque OSIF SOC handle
  2105. * @htc_soc: SOC level HTC handle
  2106. * @hal_soc: Opaque HAL SOC handle
  2107. * @osdev: QDF device
  2108. *
  2109. * Return: HTT handle on success; NULL on failure
  2110. */
  2111. void *
  2112. htt_soc_attach(void *dp_soc, void *osif_soc, HTC_HANDLE htc_soc,
  2113. void *hal_soc, qdf_device_t osdev)
  2114. {
  2115. struct htt_soc *soc;
  2116. int i;
  2117. soc = qdf_mem_malloc(sizeof(*soc));
  2118. if (!soc)
  2119. goto fail1;
  2120. soc->osdev = osdev;
  2121. soc->osif_soc = osif_soc;
  2122. soc->dp_soc = dp_soc;
  2123. soc->htc_soc = htc_soc;
  2124. soc->hal_soc = hal_soc;
  2125. /* TODO: See if any NSS related context is requred in htt_soc */
  2126. soc->htt_htc_pkt_freelist = NULL;
  2127. if (htt_htc_soc_attach(soc))
  2128. goto fail2;
  2129. /* TODO: See if any Rx data specific intialization is required. For
  2130. * MCL use cases, the data will be received as single packet and
  2131. * should not required any descriptor or reorder handling
  2132. */
  2133. HTT_TX_MUTEX_INIT(&soc->htt_tx_mutex);
  2134. /* pre-allocate some HTC_PACKET objects */
  2135. for (i = 0; i < HTT_HTC_PKT_POOL_INIT_SIZE; i++) {
  2136. struct dp_htt_htc_pkt_union *pkt;
  2137. pkt = qdf_mem_malloc(sizeof(*pkt));
  2138. if (!pkt)
  2139. break;
  2140. htt_htc_pkt_free(soc, &pkt->u.pkt);
  2141. }
  2142. return soc;
  2143. fail2:
  2144. qdf_mem_free(soc);
  2145. fail1:
  2146. return NULL;
  2147. }
  2148. /*
  2149. * htt_soc_detach() - Detach SOC level HTT
  2150. * @htt_soc: HTT SOC handle
  2151. */
  2152. void
  2153. htt_soc_detach(void *htt_soc)
  2154. {
  2155. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  2156. htt_htc_misc_pkt_pool_free(soc);
  2157. htt_htc_pkt_pool_free(soc);
  2158. HTT_TX_MUTEX_DESTROY(&soc->htt_tx_mutex);
  2159. qdf_mem_free(soc);
  2160. }
  2161. /**
  2162. * dp_h2t_ext_stats_msg_send(): function to contruct HTT message to pass to FW
  2163. * @pdev: DP PDEV handle
  2164. * @stats_type_upload_mask: stats type requested by user
  2165. * @config_param_0: extra configuration parameters
  2166. * @config_param_1: extra configuration parameters
  2167. * @config_param_2: extra configuration parameters
  2168. * @config_param_3: extra configuration parameters
  2169. *
  2170. * return: QDF STATUS
  2171. */
  2172. QDF_STATUS dp_h2t_ext_stats_msg_send(struct dp_pdev *pdev,
  2173. uint32_t stats_type_upload_mask, uint32_t config_param_0,
  2174. uint32_t config_param_1, uint32_t config_param_2,
  2175. uint32_t config_param_3)
  2176. {
  2177. struct htt_soc *soc = pdev->soc->htt_handle;
  2178. struct dp_htt_htc_pkt *pkt;
  2179. qdf_nbuf_t msg;
  2180. uint32_t *msg_word;
  2181. uint8_t pdev_mask;
  2182. msg = qdf_nbuf_alloc(
  2183. soc->osdev,
  2184. HTT_MSG_BUF_SIZE(HTT_H2T_EXT_STATS_REQ_MSG_SZ),
  2185. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  2186. if (!msg)
  2187. return QDF_STATUS_E_NOMEM;
  2188. /*TODO:Add support for SOC stats
  2189. * Bit 0: SOC Stats
  2190. * Bit 1: Pdev stats for pdev id 0
  2191. * Bit 2: Pdev stats for pdev id 1
  2192. * Bit 3: Pdev stats for pdev id 2
  2193. */
  2194. pdev_mask = 1 << (pdev->pdev_id + 1);
  2195. /*
  2196. * Set the length of the message.
  2197. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  2198. * separately during the below call to qdf_nbuf_push_head.
  2199. * The contribution from the HTC header is added separately inside HTC.
  2200. */
  2201. if (qdf_nbuf_put_tail(msg, HTT_H2T_EXT_STATS_REQ_MSG_SZ) == NULL) {
  2202. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  2203. "Failed to expand head for HTT_EXT_STATS");
  2204. qdf_nbuf_free(msg);
  2205. return QDF_STATUS_E_FAILURE;
  2206. }
  2207. msg_word = (uint32_t *) qdf_nbuf_data(msg);
  2208. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  2209. *msg_word = 0;
  2210. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_EXT_STATS_REQ);
  2211. HTT_H2T_EXT_STATS_REQ_PDEV_MASK_SET(*msg_word, pdev_mask);
  2212. HTT_H2T_EXT_STATS_REQ_STATS_TYPE_SET(*msg_word, stats_type_upload_mask);
  2213. /* word 1 */
  2214. msg_word++;
  2215. *msg_word = 0;
  2216. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_0);
  2217. /* word 2 */
  2218. msg_word++;
  2219. *msg_word = 0;
  2220. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_1);
  2221. /* word 3 */
  2222. msg_word++;
  2223. *msg_word = 0;
  2224. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_2);
  2225. /* word 4 */
  2226. msg_word++;
  2227. *msg_word = 0;
  2228. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_3);
  2229. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, 0);
  2230. pkt = htt_htc_pkt_alloc(soc);
  2231. if (!pkt) {
  2232. qdf_nbuf_free(msg);
  2233. return QDF_STATUS_E_NOMEM;
  2234. }
  2235. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  2236. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  2237. dp_htt_h2t_send_complete_free_netbuf,
  2238. qdf_nbuf_data(msg), qdf_nbuf_len(msg),
  2239. soc->htc_endpoint,
  2240. 1); /* tag - not relevant here */
  2241. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  2242. DP_HTT_SEND_HTC_PKT(soc, pkt);
  2243. return 0;
  2244. }
  2245. /* This macro will revert once proper HTT header will define for
  2246. * HTT_H2T_MSG_TYPE_PPDU_STATS_CFG in htt.h file
  2247. * */
  2248. #if defined(CONFIG_WIN) && WDI_EVENT_ENABLE
  2249. /**
  2250. * dp_h2t_cfg_stats_msg_send(): function to construct HTT message to pass to FW
  2251. * @pdev: DP PDEV handle
  2252. * @stats_type_upload_mask: stats type requested by user
  2253. *
  2254. * return: QDF STATUS
  2255. */
  2256. QDF_STATUS dp_h2t_cfg_stats_msg_send(struct dp_pdev *pdev,
  2257. uint32_t stats_type_upload_mask)
  2258. {
  2259. struct htt_soc *soc = pdev->soc->htt_handle;
  2260. struct dp_htt_htc_pkt *pkt;
  2261. qdf_nbuf_t msg;
  2262. uint32_t *msg_word;
  2263. uint8_t pdev_mask;
  2264. msg = qdf_nbuf_alloc(
  2265. soc->osdev,
  2266. HTT_MSG_BUF_SIZE(HTT_H2T_PPDU_STATS_CFG_MSG_SZ),
  2267. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, true);
  2268. if (!msg) {
  2269. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2270. "Fail to allocate HTT_H2T_PPDU_STATS_CFG_MSG_SZ msg buffer\n");
  2271. qdf_assert(0);
  2272. return QDF_STATUS_E_NOMEM;
  2273. }
  2274. /*TODO:Add support for SOC stats
  2275. * Bit 0: SOC Stats
  2276. * Bit 1: Pdev stats for pdev id 0
  2277. * Bit 2: Pdev stats for pdev id 1
  2278. * Bit 3: Pdev stats for pdev id 2
  2279. */
  2280. pdev_mask = 1 << DP_SW2HW_MACID(pdev->pdev_id);
  2281. /*
  2282. * Set the length of the message.
  2283. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  2284. * separately during the below call to qdf_nbuf_push_head.
  2285. * The contribution from the HTC header is added separately inside HTC.
  2286. */
  2287. if (qdf_nbuf_put_tail(msg, HTT_H2T_PPDU_STATS_CFG_MSG_SZ) == NULL) {
  2288. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2289. "Failed to expand head for HTT_CFG_STATS\n");
  2290. qdf_nbuf_free(msg);
  2291. return QDF_STATUS_E_FAILURE;
  2292. }
  2293. msg_word = (uint32_t *) qdf_nbuf_data(msg);
  2294. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  2295. *msg_word = 0;
  2296. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_PPDU_STATS_CFG);
  2297. HTT_H2T_PPDU_STATS_CFG_PDEV_MASK_SET(*msg_word, pdev_mask);
  2298. HTT_H2T_PPDU_STATS_CFG_TLV_BITMASK_SET(*msg_word,
  2299. stats_type_upload_mask);
  2300. pkt = htt_htc_pkt_alloc(soc);
  2301. if (!pkt) {
  2302. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2303. "Fail to allocate dp_htt_htc_pkt buffer\n");
  2304. qdf_assert(0);
  2305. qdf_nbuf_free(msg);
  2306. return QDF_STATUS_E_NOMEM;
  2307. }
  2308. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  2309. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  2310. dp_htt_h2t_send_complete_free_netbuf,
  2311. qdf_nbuf_data(msg), qdf_nbuf_len(msg),
  2312. soc->htc_endpoint,
  2313. 1); /* tag - not relevant here */
  2314. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  2315. DP_HTT_SEND_HTC_PKT(soc, pkt);
  2316. return 0;
  2317. }
  2318. #endif