dp_htt.c 69 KB

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