dp_htt.c 74 KB

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