dp_htt.c 73 KB

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