dp_htt.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642
  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. tag_buf++;
  1248. ppdu_user_desc->qos_ctrl =
  1249. HTT_PPDU_STATS_USER_COMMON_TLV_QOS_CTRL_GET(*tag_buf);
  1250. ppdu_user_desc->frame_ctrl =
  1251. HTT_PPDU_STATS_USER_COMMON_TLV_FRAME_CTRL_GET(*tag_buf);
  1252. }
  1253. /**
  1254. * dp_process_ppdu_stats_user_rate_tlv() - Process htt_ppdu_stats_user_rate_tlv
  1255. * @pdev: DP pdev handle
  1256. * @tag_buf: T2H message buffer carrying the user rate TLV
  1257. *
  1258. * return:void
  1259. */
  1260. static void dp_process_ppdu_stats_user_rate_tlv(struct dp_pdev *pdev,
  1261. uint32_t *tag_buf)
  1262. {
  1263. uint16_t peer_id;
  1264. struct dp_peer *peer;
  1265. struct cdp_tx_completion_ppdu *ppdu_desc;
  1266. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1267. uint8_t curr_user_index = 0;
  1268. ppdu_desc =
  1269. (struct cdp_tx_completion_ppdu *) qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1270. tag_buf++;
  1271. peer_id = HTT_PPDU_STATS_USER_RATE_TLV_SW_PEER_ID_GET(*tag_buf);
  1272. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1273. if (!peer)
  1274. return;
  1275. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1276. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1277. ppdu_user_desc->peer_id = peer_id;
  1278. ppdu_user_desc->tid =
  1279. HTT_PPDU_STATS_USER_RATE_TLV_TID_NUM_GET(*tag_buf);
  1280. qdf_mem_copy(ppdu_user_desc->mac_addr, peer->mac_addr.raw,
  1281. DP_MAC_ADDR_LEN);
  1282. tag_buf += 4;
  1283. ppdu_user_desc->ppdu_type =
  1284. HTT_PPDU_STATS_USER_RATE_TLV_PPDU_TYPE_GET(*tag_buf);
  1285. tag_buf++;
  1286. ppdu_user_desc->ltf_size =
  1287. HTT_PPDU_STATS_USER_RATE_TLV_LTF_SIZE_GET(*tag_buf);
  1288. ppdu_user_desc->stbc =
  1289. HTT_PPDU_STATS_USER_RATE_TLV_STBC_GET(*tag_buf);
  1290. ppdu_user_desc->he_re =
  1291. HTT_PPDU_STATS_USER_RATE_TLV_HE_RE_GET(*tag_buf);
  1292. ppdu_user_desc->txbf =
  1293. HTT_PPDU_STATS_USER_RATE_TLV_TXBF_GET(*tag_buf);
  1294. ppdu_user_desc->bw =
  1295. HTT_PPDU_STATS_USER_RATE_TLV_BW_GET(*tag_buf);
  1296. ppdu_user_desc->nss = HTT_PPDU_STATS_USER_RATE_TLV_NSS_GET(*tag_buf);
  1297. ppdu_user_desc->mcs = HTT_PPDU_STATS_USER_RATE_TLV_MCS_GET(*tag_buf);
  1298. ppdu_user_desc->preamble =
  1299. HTT_PPDU_STATS_USER_RATE_TLV_PREAMBLE_GET(*tag_buf);
  1300. ppdu_user_desc->gi = HTT_PPDU_STATS_USER_RATE_TLV_GI_GET(*tag_buf);
  1301. ppdu_user_desc->dcm = HTT_PPDU_STATS_USER_RATE_TLV_DCM_GET(*tag_buf);
  1302. ppdu_user_desc->ldpc = HTT_PPDU_STATS_USER_RATE_TLV_LDPC_GET(*tag_buf);
  1303. }
  1304. /*
  1305. * dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv: Process
  1306. * htt_ppdu_stats_enq_mpdu_bitmap_64_tlv
  1307. * pdev: DP PDEV handle
  1308. * @tag_buf: buffer containing the tlv htt_ppdu_stats_enq_mpdu_bitmap_64_tlv
  1309. *
  1310. * return:void
  1311. */
  1312. static void dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv(
  1313. struct dp_pdev *pdev, uint32_t *tag_buf)
  1314. {
  1315. htt_ppdu_stats_enq_mpdu_bitmap_64_tlv *dp_stats_buf =
  1316. (htt_ppdu_stats_enq_mpdu_bitmap_64_tlv *)tag_buf;
  1317. struct cdp_tx_completion_ppdu *ppdu_desc;
  1318. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1319. uint8_t curr_user_index = 0;
  1320. uint16_t peer_id;
  1321. struct dp_peer *peer;
  1322. ppdu_desc =
  1323. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1324. tag_buf++;
  1325. peer_id =
  1326. HTT_PPDU_STATS_ENQ_MPDU_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  1327. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1328. if (!peer)
  1329. return;
  1330. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1331. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1332. ppdu_user_desc->peer_id = peer_id;
  1333. ppdu_user_desc->start_seq = dp_stats_buf->start_seq;
  1334. qdf_mem_copy(&ppdu_user_desc->enq_bitmap, &dp_stats_buf->enq_bitmap,
  1335. CDP_BA_64_BIT_MAP_SIZE_DWORDS);
  1336. }
  1337. /*
  1338. * dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv: Process
  1339. * htt_ppdu_stats_enq_mpdu_bitmap_256_tlv
  1340. * soc: DP SOC handle
  1341. * @tag_buf: buffer containing the tlv htt_ppdu_stats_enq_mpdu_bitmap_256_tlv
  1342. *
  1343. * return:void
  1344. */
  1345. static void dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv(
  1346. struct dp_pdev *pdev, uint32_t *tag_buf)
  1347. {
  1348. htt_ppdu_stats_enq_mpdu_bitmap_256_tlv *dp_stats_buf =
  1349. (htt_ppdu_stats_enq_mpdu_bitmap_256_tlv *)tag_buf;
  1350. struct cdp_tx_completion_ppdu *ppdu_desc;
  1351. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1352. uint8_t curr_user_index = 0;
  1353. uint16_t peer_id;
  1354. struct dp_peer *peer;
  1355. ppdu_desc =
  1356. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1357. tag_buf++;
  1358. peer_id =
  1359. HTT_PPDU_STATS_ENQ_MPDU_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  1360. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1361. if (!peer)
  1362. return;
  1363. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1364. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1365. ppdu_user_desc->peer_id = peer_id;
  1366. ppdu_user_desc->start_seq = dp_stats_buf->start_seq;
  1367. qdf_mem_copy(&ppdu_user_desc->enq_bitmap, &dp_stats_buf->enq_bitmap,
  1368. CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  1369. }
  1370. /*
  1371. * dp_process_ppdu_stats_user_cmpltn_common_tlv: Process
  1372. * htt_ppdu_stats_user_cmpltn_common_tlv
  1373. * soc: DP SOC handle
  1374. * @tag_buf: buffer containing the tlv htt_ppdu_stats_user_cmpltn_common_tlv
  1375. *
  1376. * return:void
  1377. */
  1378. static void dp_process_ppdu_stats_user_cmpltn_common_tlv(
  1379. struct dp_pdev *pdev, uint32_t *tag_buf)
  1380. {
  1381. uint16_t peer_id;
  1382. struct dp_peer *peer;
  1383. struct cdp_tx_completion_ppdu *ppdu_desc;
  1384. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1385. uint8_t curr_user_index = 0;
  1386. htt_ppdu_stats_user_cmpltn_common_tlv *dp_stats_buf =
  1387. (htt_ppdu_stats_user_cmpltn_common_tlv *)tag_buf;
  1388. ppdu_desc =
  1389. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1390. tag_buf++;
  1391. peer_id =
  1392. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_SW_PEER_ID_GET(*tag_buf);
  1393. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1394. if (!peer)
  1395. return;
  1396. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1397. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1398. ppdu_user_desc->peer_id = peer_id;
  1399. ppdu_user_desc->completion_status =
  1400. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_COMPLETION_STATUS_GET(
  1401. *tag_buf);
  1402. ppdu_user_desc->tid =
  1403. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_TID_NUM_GET(*tag_buf);
  1404. tag_buf++;
  1405. ppdu_desc->ack_rssi = dp_stats_buf->ack_rssi;
  1406. tag_buf++;
  1407. ppdu_user_desc->mpdu_success =
  1408. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_MPDU_SUCCESS_GET(*tag_buf);
  1409. tag_buf++;
  1410. ppdu_user_desc->long_retries =
  1411. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_LONG_RETRY_GET(*tag_buf);
  1412. ppdu_user_desc->short_retries =
  1413. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_SHORT_RETRY_GET(*tag_buf);
  1414. ppdu_user_desc->is_ampdu =
  1415. HTT_PPDU_STATS_USER_CMPLTN_COMMON_TLV_IS_AMPDU_GET(*tag_buf);
  1416. }
  1417. /*
  1418. * dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv: Process
  1419. * htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv
  1420. * pdev: DP PDEV handle
  1421. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv
  1422. *
  1423. * return:void
  1424. */
  1425. static void dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv(
  1426. struct dp_pdev *pdev, uint32_t *tag_buf)
  1427. {
  1428. htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv *dp_stats_buf =
  1429. (htt_ppdu_stats_user_compltn_ba_bitmap_64_tlv *)tag_buf;
  1430. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1431. struct cdp_tx_completion_ppdu *ppdu_desc;
  1432. uint8_t curr_user_index = 0;
  1433. uint16_t peer_id;
  1434. struct dp_peer *peer;
  1435. ppdu_desc =
  1436. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1437. tag_buf++;
  1438. peer_id =
  1439. HTT_PPDU_STATS_USER_CMPLTN_BA_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  1440. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1441. if (!peer)
  1442. return;
  1443. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1444. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1445. ppdu_user_desc->peer_id = peer_id;
  1446. ppdu_user_desc->ba_seq_no = dp_stats_buf->ba_seq_no;
  1447. qdf_mem_copy(&ppdu_user_desc->ba_bitmap, &dp_stats_buf->ba_bitmap,
  1448. CDP_BA_64_BIT_MAP_SIZE_DWORDS);
  1449. }
  1450. /*
  1451. * dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv: Process
  1452. * htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv
  1453. * pdev: DP PDEV handle
  1454. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv
  1455. *
  1456. * return:void
  1457. */
  1458. static void dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv(
  1459. struct dp_pdev *pdev, uint32_t *tag_buf)
  1460. {
  1461. htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv *dp_stats_buf =
  1462. (htt_ppdu_stats_user_compltn_ba_bitmap_256_tlv *)tag_buf;
  1463. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1464. struct cdp_tx_completion_ppdu *ppdu_desc;
  1465. uint8_t curr_user_index = 0;
  1466. uint16_t peer_id;
  1467. struct dp_peer *peer;
  1468. ppdu_desc =
  1469. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1470. tag_buf++;
  1471. peer_id =
  1472. HTT_PPDU_STATS_USER_CMPLTN_BA_BITMAP_TLV_SW_PEER_ID_GET(*tag_buf);
  1473. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1474. if (!peer)
  1475. return;
  1476. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1477. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1478. ppdu_user_desc->peer_id = peer_id;
  1479. ppdu_user_desc->ba_seq_no = dp_stats_buf->ba_seq_no;
  1480. qdf_mem_copy(&ppdu_user_desc->ba_bitmap, &dp_stats_buf->ba_bitmap,
  1481. CDP_BA_256_BIT_MAP_SIZE_DWORDS);
  1482. }
  1483. /*
  1484. * dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv: Process
  1485. * htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  1486. * pdev: DP PDE handle
  1487. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  1488. *
  1489. * return:void
  1490. */
  1491. static void dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv(
  1492. struct dp_pdev *pdev, uint32_t *tag_buf)
  1493. {
  1494. uint16_t peer_id;
  1495. struct dp_peer *peer;
  1496. struct cdp_tx_completion_ppdu *ppdu_desc;
  1497. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1498. uint8_t curr_user_index = 0;
  1499. ppdu_desc =
  1500. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1501. tag_buf += 2;
  1502. peer_id =
  1503. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_SW_PEER_ID_GET(*tag_buf);
  1504. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1505. if (!peer)
  1506. return;
  1507. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1508. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1509. ppdu_user_desc->peer_id = peer_id;
  1510. tag_buf++;
  1511. ppdu_user_desc->num_mpdu =
  1512. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_NUM_MPDU_GET(*tag_buf);
  1513. ppdu_user_desc->num_msdu =
  1514. HTT_PPDU_STATS_USER_CMPLTN_ACK_BA_STATUS_TLV_NUM_MSDU_GET(*tag_buf);
  1515. }
  1516. /*
  1517. * dp_process_ppdu_stats_user_common_array_tlv: Process
  1518. * htt_ppdu_stats_user_common_array_tlv
  1519. * pdev: DP PDEV handle
  1520. * @tag_buf: buffer containing the htt_ppdu_stats_user_compltn_ack_ba_status_tlv
  1521. *
  1522. * return:void
  1523. */
  1524. static void dp_process_ppdu_stats_user_common_array_tlv(struct dp_pdev *pdev,
  1525. uint32_t *tag_buf)
  1526. {
  1527. uint32_t peer_id;
  1528. struct dp_peer *peer;
  1529. struct cdp_tx_completion_ppdu *ppdu_desc;
  1530. struct cdp_tx_completion_ppdu_user *ppdu_user_desc;
  1531. uint8_t curr_user_index = 0;
  1532. struct htt_tx_ppdu_stats_info *dp_stats_buf;
  1533. ppdu_desc =
  1534. (struct cdp_tx_completion_ppdu *)qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1535. tag_buf += 2;
  1536. dp_stats_buf = (struct htt_tx_ppdu_stats_info *)tag_buf;
  1537. tag_buf += 4;
  1538. peer_id =
  1539. HTT_PPDU_STATS_ARRAY_ITEM_TLV_PEERID_GET(*tag_buf);
  1540. peer = dp_peer_find_by_id(pdev->soc, peer_id);
  1541. if (!peer) {
  1542. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1543. "Invalid peer");
  1544. return;
  1545. }
  1546. curr_user_index = dp_get_ppdu_info_user_index(pdev, peer_id);
  1547. ppdu_user_desc = &ppdu_desc->user[curr_user_index];
  1548. ppdu_user_desc->success_bytes = dp_stats_buf->tx_success_bytes;
  1549. ppdu_user_desc->retry_bytes = dp_stats_buf->tx_retry_bytes;
  1550. ppdu_user_desc->failed_bytes = dp_stats_buf->tx_failed_bytes;
  1551. tag_buf++;
  1552. ppdu_user_desc->success_msdus =
  1553. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_SUCC_MSDUS_GET(*tag_buf);
  1554. ppdu_user_desc->retry_bytes =
  1555. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_RETRY_MSDUS_GET(*tag_buf);
  1556. tag_buf++;
  1557. ppdu_user_desc->failed_msdus =
  1558. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_FAILED_MSDUS_GET(*tag_buf);
  1559. ppdu_user_desc->tx_duration =
  1560. HTT_PPDU_STATS_ARRAY_ITEM_TLV_TX_DUR_GET(*tag_buf);
  1561. }
  1562. /*
  1563. * dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv: Process
  1564. * htt_ppdu_stats_tx_mgmtctrl_payload_tlv
  1565. * @pdev: DP PDEV handle
  1566. * @tag_buf: buffer containing the htt_ppdu_stats_tx_mgmtctrl_payload_tlv
  1567. * @length: tlv_length
  1568. *
  1569. * return:void
  1570. */
  1571. static void dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv(
  1572. struct dp_pdev *pdev, uint32_t *tag_buf, uint32_t length)
  1573. {
  1574. htt_ppdu_stats_tx_mgmtctrl_payload_tlv *dp_stats_buf =
  1575. (htt_ppdu_stats_tx_mgmtctrl_payload_tlv *)tag_buf;
  1576. qdf_nbuf_t nbuf = NULL;
  1577. uint32_t payload_size = length - HTT_MGMT_CTRL_TLV_RESERVERD_LEN;
  1578. nbuf = qdf_nbuf_alloc(pdev->soc->osdev, payload_size, 0, 4, true);
  1579. if (!nbuf) {
  1580. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1581. "Nbuf Allocation failed for Mgmt. payload");
  1582. qdf_assert(0);
  1583. return;
  1584. }
  1585. qdf_nbuf_put_tail(nbuf, payload_size);
  1586. qdf_mem_copy(qdf_nbuf_data(nbuf), dp_stats_buf->payload, payload_size);
  1587. dp_wdi_event_handler(WDI_EVENT_TX_MGMT_CTRL, pdev->soc,
  1588. nbuf, HTT_INVALID_PEER,
  1589. WDI_NO_VAL, pdev->pdev_id);
  1590. }
  1591. /**
  1592. * dp_process_ppdu_tag(): Function to process the PPDU TLVs
  1593. * @soc: DP Physical device (radio) handle
  1594. * @tag_buf: TLV buffer
  1595. *
  1596. * return: void
  1597. */
  1598. static void dp_process_ppdu_tag(struct dp_pdev *pdev, uint32_t *tag_buf,
  1599. uint32_t tlv_len)
  1600. {
  1601. uint32_t tlv_type = HTT_STATS_TLV_TAG_GET(*tag_buf);
  1602. switch (tlv_type) {
  1603. case HTT_PPDU_STATS_COMMON_TLV:
  1604. dp_process_ppdu_stats_common_tlv(pdev, tag_buf);
  1605. break;
  1606. case HTT_PPDU_STATS_USR_COMMON_TLV:
  1607. dp_process_ppdu_stats_user_common_tlv(pdev, tag_buf);
  1608. break;
  1609. case HTT_PPDU_STATS_USR_RATE_TLV:
  1610. qdf_assert_always(tlv_len ==
  1611. sizeof(htt_ppdu_stats_user_rate_tlv));
  1612. dp_process_ppdu_stats_user_rate_tlv(pdev, tag_buf);
  1613. break;
  1614. case HTT_PPDU_STATS_USR_MPDU_ENQ_BITMAP_64_TLV:
  1615. dp_process_ppdu_stats_enq_mpdu_bitmap_64_tlv(pdev, tag_buf);
  1616. break;
  1617. case HTT_PPDU_STATS_USR_MPDU_ENQ_BITMAP_256_TLV:
  1618. dp_process_ppdu_stats_enq_mpdu_bitmap_256_tlv(pdev, tag_buf);
  1619. break;
  1620. case HTT_PPDU_STATS_USR_COMPLTN_COMMON_TLV:
  1621. dp_process_ppdu_stats_user_cmpltn_common_tlv(pdev, tag_buf);
  1622. break;
  1623. case HTT_PPDU_STATS_USR_COMPLTN_BA_BITMAP_64_TLV:
  1624. dp_process_ppdu_stats_user_compltn_ba_bitmap_64_tlv(pdev,
  1625. tag_buf);
  1626. break;
  1627. case HTT_PPDU_STATS_USR_COMPLTN_BA_BITMAP_256_TLV:
  1628. dp_process_ppdu_stats_user_compltn_ba_bitmap_256_tlv(pdev,
  1629. tag_buf);
  1630. break;
  1631. case HTT_PPDU_STATS_USR_COMPLTN_ACK_BA_STATUS_TLV:
  1632. dp_process_ppdu_stats_user_compltn_ack_ba_status_tlv(pdev,
  1633. tag_buf);
  1634. break;
  1635. case HTT_PPDU_STATS_USR_COMMON_ARRAY_TLV:
  1636. dp_process_ppdu_stats_user_common_array_tlv(pdev,
  1637. tag_buf);
  1638. break;
  1639. case HTT_PPDU_STATS_TX_MGMTCTRL_PAYLOAD_TLV:
  1640. dp_process_ppdu_stats_tx_mgmtctrl_payload_tlv(pdev,
  1641. tag_buf, tlv_len);
  1642. break;
  1643. default:
  1644. break;
  1645. }
  1646. }
  1647. static QDF_STATUS dp_htt_process_tlv(struct dp_pdev *pdev,
  1648. qdf_nbuf_t htt_t2h_msg)
  1649. {
  1650. uint32_t length;
  1651. uint32_t ppdu_id;
  1652. uint8_t tlv_type;
  1653. uint32_t tlv_length;
  1654. uint8_t *tlv_buf;
  1655. QDF_STATUS status = QDF_STATUS_E_PENDING;
  1656. uint32_t *msg_word = (uint32_t *) qdf_nbuf_data(htt_t2h_msg);
  1657. length = HTT_T2H_PPDU_STATS_PAYLOAD_SIZE_GET(*msg_word);
  1658. msg_word = msg_word + 1;
  1659. ppdu_id = HTT_T2H_PPDU_STATS_PPDU_ID_GET(*msg_word);
  1660. msg_word = msg_word + 3;
  1661. while (length > 0) {
  1662. tlv_buf = (uint8_t *)msg_word;
  1663. tlv_type = HTT_STATS_TLV_TAG_GET(*msg_word);
  1664. tlv_length = HTT_STATS_TLV_LENGTH_GET(*msg_word);
  1665. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  1666. "HTT PPDU Tag %d, Length %d", tlv_type,
  1667. tlv_length);
  1668. if (tlv_length == 0)
  1669. break;
  1670. if (tlv_type == HTT_PPDU_STATS_SCH_CMD_STATUS_TLV)
  1671. status = QDF_STATUS_SUCCESS;
  1672. tlv_length += HTT_TLV_HDR_LEN;
  1673. dp_process_ppdu_tag(pdev, msg_word, tlv_length);
  1674. msg_word = (uint32_t *)((uint8_t *)tlv_buf + tlv_length);
  1675. length -= (tlv_length);
  1676. }
  1677. return status;
  1678. }
  1679. #endif /* FEATURE_PERPKT_INFO */
  1680. /**
  1681. * dp_txrx_ppdu_stats_handler() - Function to process HTT PPDU stats from FW
  1682. * @soc: DP SOC handle
  1683. * @pdev_id: pdev id
  1684. * @htt_t2h_msg: HTT message nbuf
  1685. *
  1686. * return:void
  1687. */
  1688. #if defined(CONFIG_WIN) && WDI_EVENT_ENABLE
  1689. #ifdef FEATURE_PERPKT_INFO
  1690. static void dp_txrx_ppdu_stats_handler(struct dp_soc *soc,
  1691. uint8_t pdev_id, qdf_nbuf_t htt_t2h_msg)
  1692. {
  1693. struct dp_pdev *pdev = soc->pdev_list[pdev_id];
  1694. struct dp_vdev *vdev;
  1695. struct dp_peer *peer;
  1696. struct cdp_tx_completion_ppdu *ppdu_desc;
  1697. int status;
  1698. int i;
  1699. if (!pdev->enhanced_stats_en && !pdev->tx_sniffer_enable)
  1700. return;
  1701. if (!pdev->tx_ppdu_info.buf) {
  1702. /*
  1703. * Todo: For MU/OFDMA, we need to account for multiple user
  1704. * descriptors in a PPDU, in skb size.
  1705. * The allocation has to be moved to ppdu_cmn tlv processing
  1706. */
  1707. pdev->tx_ppdu_info.buf = qdf_nbuf_alloc(soc->osdev,
  1708. sizeof(struct cdp_tx_completion_ppdu), 0, 4,
  1709. TRUE);
  1710. if (!pdev->tx_ppdu_info.buf) {
  1711. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1712. "Nbuf Allocation failed for HTT PPDU");
  1713. return;
  1714. }
  1715. qdf_mem_zero(qdf_nbuf_data(pdev->tx_ppdu_info.buf),
  1716. sizeof(struct cdp_tx_completion_ppdu));
  1717. if (qdf_nbuf_put_tail(pdev->tx_ppdu_info.buf,
  1718. sizeof(struct cdp_tx_completion_ppdu)) == NULL) {
  1719. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1720. "No tailroom for HTT PPDU");
  1721. return;
  1722. }
  1723. }
  1724. status = dp_htt_process_tlv(pdev, htt_t2h_msg);
  1725. if (status == QDF_STATUS_SUCCESS) {
  1726. ppdu_desc = (struct cdp_tx_completion_ppdu *)
  1727. qdf_nbuf_data(pdev->tx_ppdu_info.buf);
  1728. vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  1729. ppdu_desc->vdev_id);
  1730. for (i = 0; i < ppdu_desc->num_users; i++) {
  1731. peer = dp_peer_find_by_id(soc,
  1732. ppdu_desc->user[i].peer_id);
  1733. if (!peer)
  1734. continue;
  1735. ppdu_desc->num_mpdu += ppdu_desc->user[i].num_mpdu;
  1736. ppdu_desc->num_msdu += ppdu_desc->user[i].num_msdu;
  1737. dp_tx_stats_update(soc, peer, &ppdu_desc->user[i],
  1738. ppdu_desc->ack_rssi);
  1739. }
  1740. dp_wdi_event_handler(WDI_EVENT_TX_PPDU_DESC, soc,
  1741. pdev->tx_ppdu_info.buf, HTT_INVALID_PEER,
  1742. WDI_NO_VAL, pdev_id);
  1743. pdev->tx_ppdu_info.buf = NULL;
  1744. pdev->tx_ppdu_info.last_user = 0;
  1745. }
  1746. }
  1747. #else
  1748. static void dp_txrx_ppdu_stats_handler(struct dp_soc *soc,
  1749. uint8_t pdev_id, qdf_nbuf_t htt_t2h_msg)
  1750. {
  1751. }
  1752. #endif
  1753. #endif
  1754. /**
  1755. * dp_txrx_fw_stats_handler() - Function to process HTT EXT stats
  1756. * @soc: DP SOC handle
  1757. * @htt_t2h_msg: HTT message nbuf
  1758. *
  1759. * return:void
  1760. */
  1761. static inline void dp_txrx_fw_stats_handler(struct dp_soc *soc,
  1762. qdf_nbuf_t htt_t2h_msg)
  1763. {
  1764. uint8_t done;
  1765. qdf_nbuf_t msg_copy;
  1766. uint32_t *msg_word;
  1767. msg_word = (uint32_t *) qdf_nbuf_data(htt_t2h_msg);
  1768. msg_word = msg_word + 3;
  1769. done = HTT_T2H_EXT_STATS_CONF_TLV_DONE_GET(*msg_word);
  1770. /*
  1771. * HTT EXT stats response comes as stream of TLVs which span over
  1772. * multiple T2H messages.
  1773. * The first message will carry length of the response.
  1774. * For rest of the messages length will be zero.
  1775. *
  1776. * Clone the T2H message buffer and store it in a list to process
  1777. * it later.
  1778. *
  1779. * The original T2H message buffers gets freed in the T2H HTT event
  1780. * handler
  1781. */
  1782. msg_copy = qdf_nbuf_clone(htt_t2h_msg);
  1783. if (!msg_copy) {
  1784. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  1785. "T2H messge clone failed for HTT EXT STATS");
  1786. goto error;
  1787. }
  1788. qdf_spin_lock_bh(&soc->htt_stats.lock);
  1789. qdf_nbuf_queue_add(&soc->htt_stats.msg, msg_copy);
  1790. /*
  1791. * Done bit signifies that this is the last T2H buffer in the stream of
  1792. * HTT EXT STATS message
  1793. */
  1794. if (done) {
  1795. soc->htt_stats.num_stats++;
  1796. qdf_sched_work(0, &soc->htt_stats.work);
  1797. }
  1798. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1799. return;
  1800. error:
  1801. qdf_spin_lock_bh(&soc->htt_stats.lock);
  1802. while ((msg_copy = qdf_nbuf_queue_remove(&soc->htt_stats.msg))
  1803. != NULL) {
  1804. qdf_nbuf_free(msg_copy);
  1805. }
  1806. soc->htt_stats.num_stats = 0;
  1807. qdf_spin_unlock_bh(&soc->htt_stats.lock);
  1808. return;
  1809. }
  1810. /*
  1811. * htt_soc_attach_target() - SOC level HTT setup
  1812. * @htt_soc: HTT SOC handle
  1813. *
  1814. * Return: 0 on success; error code on failure
  1815. */
  1816. int htt_soc_attach_target(void *htt_soc)
  1817. {
  1818. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  1819. return htt_h2t_ver_req_msg(soc);
  1820. }
  1821. /*
  1822. * dp_htt_t2h_msg_handler() - Generic Target to host Msg/event handler
  1823. * @context: Opaque context (HTT SOC handle)
  1824. * @pkt: HTC packet
  1825. */
  1826. static void dp_htt_t2h_msg_handler(void *context, HTC_PACKET *pkt)
  1827. {
  1828. struct htt_soc *soc = (struct htt_soc *) context;
  1829. qdf_nbuf_t htt_t2h_msg = (qdf_nbuf_t) pkt->pPktContext;
  1830. u_int32_t *msg_word;
  1831. enum htt_t2h_msg_type msg_type;
  1832. /* check for successful message reception */
  1833. if (pkt->Status != QDF_STATUS_SUCCESS) {
  1834. if (pkt->Status != QDF_STATUS_E_CANCELED)
  1835. soc->stats.htc_err_cnt++;
  1836. qdf_nbuf_free(htt_t2h_msg);
  1837. return;
  1838. }
  1839. /* TODO: Check if we should pop the HTC/HTT header alignment padding */
  1840. msg_word = (u_int32_t *) qdf_nbuf_data(htt_t2h_msg);
  1841. msg_type = HTT_T2H_MSG_TYPE_GET(*msg_word);
  1842. switch (msg_type) {
  1843. case HTT_T2H_MSG_TYPE_PEER_MAP:
  1844. {
  1845. u_int8_t mac_addr_deswizzle_buf[HTT_MAC_ADDR_LEN];
  1846. u_int8_t *peer_mac_addr;
  1847. u_int16_t peer_id;
  1848. u_int16_t hw_peer_id;
  1849. u_int8_t vdev_id;
  1850. peer_id = HTT_RX_PEER_MAP_PEER_ID_GET(*msg_word);
  1851. hw_peer_id =
  1852. HTT_RX_PEER_MAP_HW_PEER_ID_GET(*(msg_word+2));
  1853. vdev_id = HTT_RX_PEER_MAP_VDEV_ID_GET(*msg_word);
  1854. peer_mac_addr = htt_t2h_mac_addr_deswizzle(
  1855. (u_int8_t *) (msg_word+1),
  1856. &mac_addr_deswizzle_buf[0]);
  1857. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1858. QDF_TRACE_LEVEL_INFO,
  1859. "HTT_T2H_MSG_TYPE_PEER_MAP msg for peer id %d vdev id %d n",
  1860. peer_id, vdev_id);
  1861. dp_rx_peer_map_handler(soc->dp_soc, peer_id, hw_peer_id,
  1862. vdev_id, peer_mac_addr);
  1863. break;
  1864. }
  1865. case HTT_T2H_MSG_TYPE_PEER_UNMAP:
  1866. {
  1867. u_int16_t peer_id;
  1868. peer_id = HTT_RX_PEER_UNMAP_PEER_ID_GET(*msg_word);
  1869. dp_rx_peer_unmap_handler(soc->dp_soc, peer_id);
  1870. break;
  1871. }
  1872. case HTT_T2H_MSG_TYPE_SEC_IND:
  1873. {
  1874. u_int16_t peer_id;
  1875. enum htt_sec_type sec_type;
  1876. int is_unicast;
  1877. peer_id = HTT_SEC_IND_PEER_ID_GET(*msg_word);
  1878. sec_type = HTT_SEC_IND_SEC_TYPE_GET(*msg_word);
  1879. is_unicast = HTT_SEC_IND_UNICAST_GET(*msg_word);
  1880. /* point to the first part of the Michael key */
  1881. msg_word++;
  1882. dp_rx_sec_ind_handler(
  1883. soc->dp_soc, peer_id, sec_type, is_unicast,
  1884. msg_word, msg_word + 2);
  1885. break;
  1886. }
  1887. #if defined(CONFIG_WIN) && WDI_EVENT_ENABLE
  1888. #ifndef REMOVE_PKT_LOG
  1889. case HTT_T2H_MSG_TYPE_PPDU_STATS_IND:
  1890. {
  1891. u_int8_t pdev_id;
  1892. qdf_nbuf_set_pktlen(htt_t2h_msg, HTT_T2H_MAX_MSG_SIZE);
  1893. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  1894. "received HTT_T2H_MSG_TYPE_PPDU_STATS_IND\n");
  1895. pdev_id = HTT_T2H_PPDU_STATS_MAC_ID_GET(*msg_word);
  1896. pdev_id = DP_HW2SW_MACID(pdev_id);
  1897. dp_txrx_ppdu_stats_handler(soc->dp_soc, pdev_id,
  1898. htt_t2h_msg);
  1899. dp_wdi_event_handler(WDI_EVENT_LITE_T2H, soc->dp_soc,
  1900. htt_t2h_msg, HTT_INVALID_PEER, WDI_NO_VAL,
  1901. pdev_id);
  1902. break;
  1903. }
  1904. case HTT_T2H_MSG_TYPE_PKTLOG:
  1905. {
  1906. uint8_t pdev_id;
  1907. uint32_t *pl_hdr;
  1908. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  1909. "received HTT_T2H_MSG_TYPE_PKTLOG\n");
  1910. pdev_id = HTT_T2H_PKTLOG_MAC_ID_GET(*msg_word);
  1911. pdev_id = DP_HW2SW_MACID(pdev_id);
  1912. pl_hdr = (msg_word + 1);
  1913. dp_wdi_event_handler(WDI_EVENT_OFFLOAD_ALL, soc->dp_soc,
  1914. pl_hdr, HTT_INVALID_PEER, WDI_NO_VAL,
  1915. pdev_id);
  1916. break;
  1917. }
  1918. #endif
  1919. #endif
  1920. case HTT_T2H_MSG_TYPE_VERSION_CONF:
  1921. {
  1922. htc_pm_runtime_put(soc->htc_soc);
  1923. soc->tgt_ver.major = HTT_VER_CONF_MAJOR_GET(*msg_word);
  1924. soc->tgt_ver.minor = HTT_VER_CONF_MINOR_GET(*msg_word);
  1925. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  1926. "target uses HTT version %d.%d; host uses %d.%d\n",
  1927. soc->tgt_ver.major, soc->tgt_ver.minor,
  1928. HTT_CURRENT_VERSION_MAJOR,
  1929. HTT_CURRENT_VERSION_MINOR);
  1930. if (soc->tgt_ver.major != HTT_CURRENT_VERSION_MAJOR) {
  1931. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1932. QDF_TRACE_LEVEL_ERROR,
  1933. "*** Incompatible host/target HTT versions!\n");
  1934. }
  1935. /* abort if the target is incompatible with the host */
  1936. qdf_assert(soc->tgt_ver.major ==
  1937. HTT_CURRENT_VERSION_MAJOR);
  1938. if (soc->tgt_ver.minor != HTT_CURRENT_VERSION_MINOR) {
  1939. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1940. QDF_TRACE_LEVEL_WARN,
  1941. "*** Warning: host/target HTT versions"
  1942. " are different, though compatible!\n");
  1943. }
  1944. break;
  1945. }
  1946. case HTT_T2H_MSG_TYPE_RX_ADDBA:
  1947. {
  1948. uint16_t peer_id;
  1949. uint8_t tid;
  1950. uint8_t win_sz;
  1951. uint16_t status;
  1952. struct dp_peer *peer;
  1953. /*
  1954. * Update REO Queue Desc with new values
  1955. */
  1956. peer_id = HTT_RX_ADDBA_PEER_ID_GET(*msg_word);
  1957. tid = HTT_RX_ADDBA_TID_GET(*msg_word);
  1958. win_sz = HTT_RX_ADDBA_WIN_SIZE_GET(*msg_word);
  1959. peer = dp_peer_find_by_id(soc->dp_soc, peer_id);
  1960. /*
  1961. * Window size needs to be incremented by 1
  1962. * since fw needs to represent a value of 256
  1963. * using just 8 bits
  1964. */
  1965. if (peer) {
  1966. status = dp_addba_requestprocess_wifi3(peer,
  1967. 0, tid, 0, win_sz + 1, 0xffff);
  1968. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1969. QDF_TRACE_LEVEL_INFO,
  1970. FL("PeerID %d BAW %d TID %d stat %d\n"),
  1971. peer_id, win_sz, tid, status);
  1972. } else {
  1973. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1974. QDF_TRACE_LEVEL_ERROR,
  1975. FL("Peer not found peer id %d\n"),
  1976. peer_id);
  1977. }
  1978. break;
  1979. }
  1980. case HTT_T2H_MSG_TYPE_EXT_STATS_CONF:
  1981. {
  1982. dp_txrx_fw_stats_handler(soc->dp_soc, htt_t2h_msg);
  1983. break;
  1984. }
  1985. default:
  1986. break;
  1987. };
  1988. /* Free the indication buffer */
  1989. qdf_nbuf_free(htt_t2h_msg);
  1990. }
  1991. /*
  1992. * dp_htt_h2t_full() - Send full handler (called from HTC)
  1993. * @context: Opaque context (HTT SOC handle)
  1994. * @pkt: HTC packet
  1995. *
  1996. * Return: enum htc_send_full_action
  1997. */
  1998. static enum htc_send_full_action
  1999. dp_htt_h2t_full(void *context, HTC_PACKET *pkt)
  2000. {
  2001. return HTC_SEND_FULL_KEEP;
  2002. }
  2003. /*
  2004. * dp_htt_hif_t2h_hp_callback() - HIF callback for high priority T2H messages
  2005. * @context: Opaque context (HTT SOC handle)
  2006. * @nbuf: nbuf containing T2H message
  2007. * @pipe_id: HIF pipe ID
  2008. *
  2009. * Return: QDF_STATUS
  2010. *
  2011. * TODO: Temporary change to bypass HTC connection for this new HIF pipe, which
  2012. * will be used for packet log and other high-priority HTT messsages. Proper
  2013. * HTC connection to be added later once required FW changes are available
  2014. */
  2015. static QDF_STATUS
  2016. dp_htt_hif_t2h_hp_callback (void *context, qdf_nbuf_t nbuf, uint8_t pipe_id)
  2017. {
  2018. A_STATUS rc = QDF_STATUS_SUCCESS;
  2019. HTC_PACKET htc_pkt;
  2020. qdf_assert_always(pipe_id == DP_HTT_T2H_HP_PIPE);
  2021. qdf_mem_zero(&htc_pkt, sizeof(htc_pkt));
  2022. htc_pkt.Status = QDF_STATUS_SUCCESS;
  2023. htc_pkt.pPktContext = (void *)nbuf;
  2024. dp_htt_t2h_msg_handler(context, &htc_pkt);
  2025. return rc;
  2026. }
  2027. /*
  2028. * htt_htc_soc_attach() - Register SOC level HTT instance with HTC
  2029. * @htt_soc: HTT SOC handle
  2030. *
  2031. * Return: 0 on success; error code on failure
  2032. */
  2033. static int
  2034. htt_htc_soc_attach(struct htt_soc *soc)
  2035. {
  2036. struct htc_service_connect_req connect;
  2037. struct htc_service_connect_resp response;
  2038. A_STATUS status;
  2039. qdf_mem_set(&connect, sizeof(connect), 0);
  2040. qdf_mem_set(&response, sizeof(response), 0);
  2041. connect.pMetaData = NULL;
  2042. connect.MetaDataLength = 0;
  2043. connect.EpCallbacks.pContext = soc;
  2044. connect.EpCallbacks.EpTxComplete = dp_htt_h2t_send_complete;
  2045. connect.EpCallbacks.EpTxCompleteMultiple = NULL;
  2046. connect.EpCallbacks.EpRecv = dp_htt_t2h_msg_handler;
  2047. /* rx buffers currently are provided by HIF, not by EpRecvRefill */
  2048. connect.EpCallbacks.EpRecvRefill = NULL;
  2049. /* N/A, fill is done by HIF */
  2050. connect.EpCallbacks.RecvRefillWaterMark = 1;
  2051. connect.EpCallbacks.EpSendFull = dp_htt_h2t_full;
  2052. /*
  2053. * Specify how deep to let a queue get before htc_send_pkt will
  2054. * call the EpSendFull function due to excessive send queue depth.
  2055. */
  2056. connect.MaxSendQueueDepth = DP_HTT_MAX_SEND_QUEUE_DEPTH;
  2057. /* disable flow control for HTT data message service */
  2058. connect.ConnectionFlags |= HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  2059. /* connect to control service */
  2060. connect.service_id = HTT_DATA_MSG_SVC;
  2061. status = htc_connect_service(soc->htc_soc, &connect, &response);
  2062. if (status != A_OK)
  2063. return QDF_STATUS_E_FAILURE;
  2064. soc->htc_endpoint = response.Endpoint;
  2065. dp_hif_update_pipe_callback(soc->dp_soc, (void *)soc,
  2066. dp_htt_hif_t2h_hp_callback, DP_HTT_T2H_HP_PIPE);
  2067. return 0; /* success */
  2068. }
  2069. /*
  2070. * htt_soc_attach() - SOC level HTT initialization
  2071. * @dp_soc: Opaque Data path SOC handle
  2072. * @osif_soc: Opaque OSIF SOC handle
  2073. * @htc_soc: SOC level HTC handle
  2074. * @hal_soc: Opaque HAL SOC handle
  2075. * @osdev: QDF device
  2076. *
  2077. * Return: HTT handle on success; NULL on failure
  2078. */
  2079. void *
  2080. htt_soc_attach(void *dp_soc, void *osif_soc, HTC_HANDLE htc_soc,
  2081. void *hal_soc, qdf_device_t osdev)
  2082. {
  2083. struct htt_soc *soc;
  2084. int i;
  2085. soc = qdf_mem_malloc(sizeof(*soc));
  2086. if (!soc)
  2087. goto fail1;
  2088. soc->osdev = osdev;
  2089. soc->osif_soc = osif_soc;
  2090. soc->dp_soc = dp_soc;
  2091. soc->htc_soc = htc_soc;
  2092. soc->hal_soc = hal_soc;
  2093. /* TODO: See if any NSS related context is requred in htt_soc */
  2094. soc->htt_htc_pkt_freelist = NULL;
  2095. if (htt_htc_soc_attach(soc))
  2096. goto fail2;
  2097. /* TODO: See if any Rx data specific intialization is required. For
  2098. * MCL use cases, the data will be received as single packet and
  2099. * should not required any descriptor or reorder handling
  2100. */
  2101. HTT_TX_MUTEX_INIT(&soc->htt_tx_mutex);
  2102. /* pre-allocate some HTC_PACKET objects */
  2103. for (i = 0; i < HTT_HTC_PKT_POOL_INIT_SIZE; i++) {
  2104. struct dp_htt_htc_pkt_union *pkt;
  2105. pkt = qdf_mem_malloc(sizeof(*pkt));
  2106. if (!pkt)
  2107. break;
  2108. htt_htc_pkt_free(soc, &pkt->u.pkt);
  2109. }
  2110. return soc;
  2111. fail2:
  2112. qdf_mem_free(soc);
  2113. fail1:
  2114. return NULL;
  2115. }
  2116. /*
  2117. * htt_soc_detach() - Detach SOC level HTT
  2118. * @htt_soc: HTT SOC handle
  2119. */
  2120. void
  2121. htt_soc_detach(void *htt_soc)
  2122. {
  2123. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  2124. htt_htc_misc_pkt_pool_free(soc);
  2125. htt_htc_pkt_pool_free(soc);
  2126. HTT_TX_MUTEX_DESTROY(&soc->htt_tx_mutex);
  2127. qdf_mem_free(soc);
  2128. }
  2129. /**
  2130. * dp_h2t_ext_stats_msg_send(): function to contruct HTT message to pass to FW
  2131. * @pdev: DP PDEV handle
  2132. * @stats_type_upload_mask: stats type requested by user
  2133. * @config_param_0: extra configuration parameters
  2134. * @config_param_1: extra configuration parameters
  2135. * @config_param_2: extra configuration parameters
  2136. * @config_param_3: extra configuration parameters
  2137. *
  2138. * return: QDF STATUS
  2139. */
  2140. QDF_STATUS dp_h2t_ext_stats_msg_send(struct dp_pdev *pdev,
  2141. uint32_t stats_type_upload_mask, uint32_t config_param_0,
  2142. uint32_t config_param_1, uint32_t config_param_2,
  2143. uint32_t config_param_3)
  2144. {
  2145. struct htt_soc *soc = pdev->soc->htt_handle;
  2146. struct dp_htt_htc_pkt *pkt;
  2147. qdf_nbuf_t msg;
  2148. uint32_t *msg_word;
  2149. uint8_t pdev_mask;
  2150. msg = qdf_nbuf_alloc(
  2151. soc->osdev,
  2152. HTT_MSG_BUF_SIZE(HTT_H2T_EXT_STATS_REQ_MSG_SZ),
  2153. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  2154. if (!msg)
  2155. return QDF_STATUS_E_NOMEM;
  2156. /*TODO:Add support for SOC stats
  2157. * Bit 0: SOC Stats
  2158. * Bit 1: Pdev stats for pdev id 0
  2159. * Bit 2: Pdev stats for pdev id 1
  2160. * Bit 3: Pdev stats for pdev id 2
  2161. */
  2162. pdev_mask = 1 << (pdev->pdev_id + 1);
  2163. /*
  2164. * Set the length of the message.
  2165. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  2166. * separately during the below call to qdf_nbuf_push_head.
  2167. * The contribution from the HTC header is added separately inside HTC.
  2168. */
  2169. if (qdf_nbuf_put_tail(msg, HTT_H2T_EXT_STATS_REQ_MSG_SZ) == NULL) {
  2170. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  2171. "Failed to expand head for HTT_EXT_STATS");
  2172. qdf_nbuf_free(msg);
  2173. return QDF_STATUS_E_FAILURE;
  2174. }
  2175. msg_word = (uint32_t *) qdf_nbuf_data(msg);
  2176. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  2177. *msg_word = 0;
  2178. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_EXT_STATS_REQ);
  2179. HTT_H2T_EXT_STATS_REQ_PDEV_MASK_SET(*msg_word, pdev_mask);
  2180. HTT_H2T_EXT_STATS_REQ_STATS_TYPE_SET(*msg_word, stats_type_upload_mask);
  2181. /* word 1 */
  2182. msg_word++;
  2183. *msg_word = 0;
  2184. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_0);
  2185. /* word 2 */
  2186. msg_word++;
  2187. *msg_word = 0;
  2188. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_1);
  2189. /* word 3 */
  2190. msg_word++;
  2191. *msg_word = 0;
  2192. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_2);
  2193. /* word 4 */
  2194. msg_word++;
  2195. *msg_word = 0;
  2196. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_3);
  2197. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, 0);
  2198. pkt = htt_htc_pkt_alloc(soc);
  2199. if (!pkt) {
  2200. qdf_nbuf_free(msg);
  2201. return QDF_STATUS_E_NOMEM;
  2202. }
  2203. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  2204. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  2205. dp_htt_h2t_send_complete_free_netbuf,
  2206. qdf_nbuf_data(msg), qdf_nbuf_len(msg),
  2207. soc->htc_endpoint,
  2208. 1); /* tag - not relevant here */
  2209. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  2210. DP_HTT_SEND_HTC_PKT(soc, pkt);
  2211. return 0;
  2212. }
  2213. /* This macro will revert once proper HTT header will define for
  2214. * HTT_H2T_MSG_TYPE_PPDU_STATS_CFG in htt.h file
  2215. * */
  2216. #if defined(CONFIG_WIN) && WDI_EVENT_ENABLE
  2217. /**
  2218. * dp_h2t_cfg_stats_msg_send(): function to construct HTT message to pass to FW
  2219. * @pdev: DP PDEV handle
  2220. * @stats_type_upload_mask: stats type requested by user
  2221. *
  2222. * return: QDF STATUS
  2223. */
  2224. QDF_STATUS dp_h2t_cfg_stats_msg_send(struct dp_pdev *pdev,
  2225. uint32_t stats_type_upload_mask)
  2226. {
  2227. struct htt_soc *soc = pdev->soc->htt_handle;
  2228. struct dp_htt_htc_pkt *pkt;
  2229. qdf_nbuf_t msg;
  2230. uint32_t *msg_word;
  2231. uint8_t pdev_mask;
  2232. msg = qdf_nbuf_alloc(
  2233. soc->osdev,
  2234. HTT_MSG_BUF_SIZE(HTT_H2T_PPDU_STATS_CFG_MSG_SZ),
  2235. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, true);
  2236. if (!msg) {
  2237. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2238. "Fail to allocate HTT_H2T_PPDU_STATS_CFG_MSG_SZ msg buffer\n");
  2239. qdf_assert(0);
  2240. return QDF_STATUS_E_NOMEM;
  2241. }
  2242. /*TODO:Add support for SOC stats
  2243. * Bit 0: SOC Stats
  2244. * Bit 1: Pdev stats for pdev id 0
  2245. * Bit 2: Pdev stats for pdev id 1
  2246. * Bit 3: Pdev stats for pdev id 2
  2247. */
  2248. pdev_mask = 1 << DP_SW2HW_MACID(pdev->pdev_id);
  2249. /*
  2250. * Set the length of the message.
  2251. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  2252. * separately during the below call to qdf_nbuf_push_head.
  2253. * The contribution from the HTC header is added separately inside HTC.
  2254. */
  2255. if (qdf_nbuf_put_tail(msg, HTT_H2T_PPDU_STATS_CFG_MSG_SZ) == NULL) {
  2256. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2257. "Failed to expand head for HTT_CFG_STATS\n");
  2258. qdf_nbuf_free(msg);
  2259. return QDF_STATUS_E_FAILURE;
  2260. }
  2261. msg_word = (uint32_t *) qdf_nbuf_data(msg);
  2262. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  2263. *msg_word = 0;
  2264. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_PPDU_STATS_CFG);
  2265. HTT_H2T_PPDU_STATS_CFG_PDEV_MASK_SET(*msg_word, pdev_mask);
  2266. HTT_H2T_PPDU_STATS_CFG_TLV_BITMASK_SET(*msg_word,
  2267. stats_type_upload_mask);
  2268. pkt = htt_htc_pkt_alloc(soc);
  2269. if (!pkt) {
  2270. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2271. "Fail to allocate dp_htt_htc_pkt buffer\n");
  2272. qdf_assert(0);
  2273. qdf_nbuf_free(msg);
  2274. return QDF_STATUS_E_NOMEM;
  2275. }
  2276. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  2277. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  2278. dp_htt_h2t_send_complete_free_netbuf,
  2279. qdf_nbuf_data(msg), qdf_nbuf_len(msg),
  2280. soc->htc_endpoint,
  2281. 1); /* tag - not relevant here */
  2282. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  2283. DP_HTT_SEND_HTC_PKT(soc, pkt);
  2284. return 0;
  2285. }
  2286. #endif