dp_htt.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553
  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 "qdf_mem.h" /* qdf_mem_malloc,free */
  27. #define HTT_TLV_HDR_LEN HTT_T2H_EXT_STATS_CONF_TLV_HDR_SIZE
  28. #define HTT_HTC_PKT_POOL_INIT_SIZE 64
  29. #define HTT_T2H_MAX_MSG_SIZE 2048
  30. #define HTT_MSG_BUF_SIZE(msg_bytes) \
  31. ((msg_bytes) + HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING)
  32. #define DP_EXT_MSG_LENGTH 2048
  33. /*
  34. * htt_htc_pkt_alloc() - Allocate HTC packet buffer
  35. * @htt_soc: HTT SOC handle
  36. *
  37. * Return: Pointer to htc packet buffer
  38. */
  39. static struct dp_htt_htc_pkt *
  40. htt_htc_pkt_alloc(struct htt_soc *soc)
  41. {
  42. struct dp_htt_htc_pkt_union *pkt = NULL;
  43. HTT_TX_MUTEX_ACQUIRE(&soc->htt_tx_mutex);
  44. if (soc->htt_htc_pkt_freelist) {
  45. pkt = soc->htt_htc_pkt_freelist;
  46. soc->htt_htc_pkt_freelist = soc->htt_htc_pkt_freelist->u.next;
  47. }
  48. HTT_TX_MUTEX_RELEASE(&soc->htt_tx_mutex);
  49. if (pkt == NULL)
  50. pkt = qdf_mem_malloc(sizeof(*pkt));
  51. return &pkt->u.pkt; /* not actually a dereference */
  52. }
  53. /*
  54. * htt_htc_pkt_free() - Free HTC packet buffer
  55. * @htt_soc: HTT SOC handle
  56. */
  57. static void
  58. htt_htc_pkt_free(struct htt_soc *soc, struct dp_htt_htc_pkt *pkt)
  59. {
  60. struct dp_htt_htc_pkt_union *u_pkt =
  61. (struct dp_htt_htc_pkt_union *)pkt;
  62. HTT_TX_MUTEX_ACQUIRE(&soc->htt_tx_mutex);
  63. u_pkt->u.next = soc->htt_htc_pkt_freelist;
  64. soc->htt_htc_pkt_freelist = u_pkt;
  65. HTT_TX_MUTEX_RELEASE(&soc->htt_tx_mutex);
  66. }
  67. /*
  68. * htt_htc_pkt_pool_free() - Free HTC packet pool
  69. * @htt_soc: HTT SOC handle
  70. */
  71. static void
  72. htt_htc_pkt_pool_free(struct htt_soc *soc)
  73. {
  74. struct dp_htt_htc_pkt_union *pkt, *next;
  75. pkt = soc->htt_htc_pkt_freelist;
  76. while (pkt) {
  77. next = pkt->u.next;
  78. qdf_mem_free(pkt);
  79. pkt = next;
  80. }
  81. soc->htt_htc_pkt_freelist = NULL;
  82. }
  83. /*
  84. * htt_t2h_mac_addr_deswizzle() - Swap MAC addr bytes if FW endianess differ
  85. * @tgt_mac_addr: Target MAC
  86. * @buffer: Output buffer
  87. */
  88. static u_int8_t *
  89. htt_t2h_mac_addr_deswizzle(u_int8_t *tgt_mac_addr, u_int8_t *buffer)
  90. {
  91. #ifdef BIG_ENDIAN_HOST
  92. /*
  93. * The host endianness is opposite of the target endianness.
  94. * To make u_int32_t elements come out correctly, the target->host
  95. * upload has swizzled the bytes in each u_int32_t element of the
  96. * message.
  97. * For byte-array message fields like the MAC address, this
  98. * upload swizzling puts the bytes in the wrong order, and needs
  99. * to be undone.
  100. */
  101. buffer[0] = tgt_mac_addr[3];
  102. buffer[1] = tgt_mac_addr[2];
  103. buffer[2] = tgt_mac_addr[1];
  104. buffer[3] = tgt_mac_addr[0];
  105. buffer[4] = tgt_mac_addr[7];
  106. buffer[5] = tgt_mac_addr[6];
  107. return buffer;
  108. #else
  109. /*
  110. * The host endianness matches the target endianness -
  111. * we can use the mac addr directly from the message buffer.
  112. */
  113. return tgt_mac_addr;
  114. #endif
  115. }
  116. /*
  117. * dp_htt_h2t_send_complete_free_netbuf() - Free completed buffer
  118. * @soc: SOC handle
  119. * @status: Completion status
  120. * @netbuf: HTT buffer
  121. */
  122. static void
  123. dp_htt_h2t_send_complete_free_netbuf(
  124. void *soc, A_STATUS status, qdf_nbuf_t netbuf)
  125. {
  126. qdf_nbuf_free(netbuf);
  127. }
  128. /*
  129. * dp_htt_h2t_send_complete() - H2T completion handler
  130. * @context: Opaque context (HTT SOC handle)
  131. * @htc_pkt: HTC packet
  132. */
  133. static void
  134. dp_htt_h2t_send_complete(void *context, HTC_PACKET *htc_pkt)
  135. {
  136. void (*send_complete_part2)(
  137. void *soc, A_STATUS status, qdf_nbuf_t msdu);
  138. struct htt_soc *soc = (struct htt_soc *) context;
  139. struct dp_htt_htc_pkt *htt_pkt;
  140. qdf_nbuf_t netbuf;
  141. send_complete_part2 = htc_pkt->pPktContext;
  142. htt_pkt = container_of(htc_pkt, struct dp_htt_htc_pkt, htc_pkt);
  143. /* process (free or keep) the netbuf that held the message */
  144. netbuf = (qdf_nbuf_t) htc_pkt->pNetBufContext;
  145. /*
  146. * adf sendcomplete is required for windows only
  147. */
  148. /* qdf_nbuf_set_sendcompleteflag(netbuf, TRUE); */
  149. if (send_complete_part2 != NULL) {
  150. send_complete_part2(
  151. htt_pkt->soc_ctxt, htc_pkt->Status, netbuf);
  152. }
  153. /* free the htt_htc_pkt / HTC_PACKET object */
  154. htt_htc_pkt_free(soc, htt_pkt);
  155. }
  156. /*
  157. * htt_h2t_ver_req_msg() - Send HTT version request message to target
  158. * @htt_soc: HTT SOC handle
  159. *
  160. * Return: 0 on success; error code on failure
  161. */
  162. static int htt_h2t_ver_req_msg(struct htt_soc *soc)
  163. {
  164. struct dp_htt_htc_pkt *pkt;
  165. qdf_nbuf_t msg;
  166. uint32_t *msg_word;
  167. msg = qdf_nbuf_alloc(
  168. soc->osdev,
  169. HTT_MSG_BUF_SIZE(HTT_VER_REQ_BYTES),
  170. /* reserve room for the HTC header */
  171. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  172. if (!msg)
  173. return QDF_STATUS_E_NOMEM;
  174. /*
  175. * Set the length of the message.
  176. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  177. * separately during the below call to qdf_nbuf_push_head.
  178. * The contribution from the HTC header is added separately inside HTC.
  179. */
  180. if (qdf_nbuf_put_tail(msg, HTT_VER_REQ_BYTES) == NULL) {
  181. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  182. "%s: Failed to expand head for HTT_H2T_MSG_TYPE_VERSION_REQ msg\n",
  183. __func__);
  184. return QDF_STATUS_E_FAILURE;
  185. }
  186. /* fill in the message contents */
  187. msg_word = (u_int32_t *) qdf_nbuf_data(msg);
  188. /* rewind beyond alignment pad to get to the HTC header reserved area */
  189. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  190. *msg_word = 0;
  191. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_VERSION_REQ);
  192. pkt = htt_htc_pkt_alloc(soc);
  193. if (!pkt) {
  194. qdf_nbuf_free(msg);
  195. return QDF_STATUS_E_FAILURE;
  196. }
  197. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  198. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  199. dp_htt_h2t_send_complete_free_netbuf, qdf_nbuf_data(msg),
  200. qdf_nbuf_len(msg), soc->htc_endpoint,
  201. 1); /* tag - not relevant here */
  202. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  203. htc_send_pkt(soc->htc_soc, &pkt->htc_pkt);
  204. return 0;
  205. }
  206. /*
  207. * htt_srng_setup() - Send SRNG setup message to target
  208. * @htt_soc: HTT SOC handle
  209. * @mac_id: MAC Id
  210. * @hal_srng: Opaque HAL SRNG pointer
  211. * @hal_ring_type: SRNG ring type
  212. *
  213. * Return: 0 on success; error code on failure
  214. */
  215. int htt_srng_setup(void *htt_soc, int mac_id, void *hal_srng,
  216. int hal_ring_type)
  217. {
  218. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  219. struct dp_htt_htc_pkt *pkt;
  220. qdf_nbuf_t htt_msg;
  221. uint32_t *msg_word;
  222. struct hal_srng_params srng_params;
  223. qdf_dma_addr_t hp_addr, tp_addr;
  224. uint32_t ring_entry_size =
  225. hal_srng_get_entrysize(soc->hal_soc, hal_ring_type);
  226. int htt_ring_type, htt_ring_id;
  227. /* Sizes should be set in 4-byte words */
  228. ring_entry_size = ring_entry_size >> 2;
  229. htt_msg = qdf_nbuf_alloc(soc->osdev,
  230. HTT_MSG_BUF_SIZE(HTT_SRING_SETUP_SZ),
  231. /* reserve room for the HTC header */
  232. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  233. if (!htt_msg)
  234. goto fail0;
  235. hal_get_srng_params(soc->hal_soc, hal_srng, &srng_params);
  236. hp_addr = hal_srng_get_hp_addr(soc->hal_soc, hal_srng);
  237. tp_addr = hal_srng_get_tp_addr(soc->hal_soc, hal_srng);
  238. switch (hal_ring_type) {
  239. case RXDMA_BUF:
  240. #ifdef QCA_HOST2FW_RXBUF_RING
  241. if (srng_params.ring_id ==
  242. (HAL_SRNG_WMAC1_SW2RXDMA0_BUF)) {
  243. htt_ring_id = HTT_HOST1_TO_FW_RXBUF_RING;
  244. htt_ring_type = HTT_SW_TO_SW_RING;
  245. #else
  246. if (srng_params.ring_id ==
  247. (HAL_SRNG_WMAC1_SW2RXDMA0_BUF +
  248. (mac_id * HAL_MAX_RINGS_PER_LMAC))) {
  249. htt_ring_id = HTT_RXDMA_HOST_BUF_RING;
  250. htt_ring_type = HTT_SW_TO_HW_RING;
  251. #endif
  252. } else if (srng_params.ring_id ==
  253. (HAL_SRNG_WMAC1_SW2RXDMA1_BUF +
  254. (mac_id * HAL_MAX_RINGS_PER_LMAC))) {
  255. htt_ring_id = HTT_RXDMA_HOST_BUF_RING;
  256. htt_ring_type = HTT_SW_TO_HW_RING;
  257. } else {
  258. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  259. "%s: Ring %d currently not supported\n",
  260. __func__, srng_params.ring_id);
  261. goto fail1;
  262. }
  263. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  264. "%s: ring_type %d ring_id %d\n",
  265. __func__, hal_ring_type, srng_params.ring_id);
  266. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  267. "%s: hp_addr 0x%llx tp_addr 0x%llx\n",
  268. __func__, (uint64_t)hp_addr, (uint64_t)tp_addr);
  269. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  270. "%s: htt_ring_id %d\n", __func__, htt_ring_id);
  271. break;
  272. case RXDMA_MONITOR_BUF:
  273. htt_ring_id = HTT_RXDMA_MONITOR_BUF_RING;
  274. htt_ring_type = HTT_SW_TO_HW_RING;
  275. break;
  276. case RXDMA_MONITOR_STATUS:
  277. htt_ring_id = HTT_RXDMA_MONITOR_STATUS_RING;
  278. htt_ring_type = HTT_SW_TO_HW_RING;
  279. break;
  280. case RXDMA_MONITOR_DST:
  281. htt_ring_id = HTT_RXDMA_MONITOR_DEST_RING;
  282. htt_ring_type = HTT_HW_TO_SW_RING;
  283. break;
  284. case RXDMA_MONITOR_DESC:
  285. htt_ring_id = HTT_RXDMA_MONITOR_DESC_RING;
  286. htt_ring_type = HTT_SW_TO_HW_RING;
  287. break;
  288. case RXDMA_DST:
  289. htt_ring_id = HTT_RXDMA_NON_MONITOR_DEST_RING;
  290. htt_ring_type = HTT_HW_TO_SW_RING;
  291. break;
  292. default:
  293. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  294. "%s: Ring currently not supported\n", __func__);
  295. goto fail1;
  296. }
  297. /*
  298. * Set the length of the message.
  299. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  300. * separately during the below call to qdf_nbuf_push_head.
  301. * The contribution from the HTC header is added separately inside HTC.
  302. */
  303. if (qdf_nbuf_put_tail(htt_msg, HTT_SRING_SETUP_SZ) == NULL) {
  304. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  305. "%s: Failed to expand head for SRING_SETUP msg\n",
  306. __func__);
  307. return QDF_STATUS_E_FAILURE;
  308. }
  309. msg_word = (uint32_t *)qdf_nbuf_data(htt_msg);
  310. /* rewind beyond alignment pad to get to the HTC header reserved area */
  311. qdf_nbuf_push_head(htt_msg, HTC_HDR_ALIGNMENT_PADDING);
  312. /* word 0 */
  313. *msg_word = 0;
  314. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_SRING_SETUP);
  315. if ((htt_ring_type == HTT_SW_TO_HW_RING) ||
  316. (htt_ring_type == HTT_HW_TO_SW_RING))
  317. HTT_SRING_SETUP_PDEV_ID_SET(*msg_word,
  318. DP_SW2HW_MACID(mac_id));
  319. else
  320. HTT_SRING_SETUP_PDEV_ID_SET(*msg_word, mac_id);
  321. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  322. "%s: mac_id %d\n", __func__, mac_id);
  323. HTT_SRING_SETUP_RING_TYPE_SET(*msg_word, htt_ring_type);
  324. /* TODO: Discuss with FW on changing this to unique ID and using
  325. * htt_ring_type to send the type of ring
  326. */
  327. HTT_SRING_SETUP_RING_ID_SET(*msg_word, htt_ring_id);
  328. /* word 1 */
  329. msg_word++;
  330. *msg_word = 0;
  331. HTT_SRING_SETUP_RING_BASE_ADDR_LO_SET(*msg_word,
  332. srng_params.ring_base_paddr & 0xffffffff);
  333. /* word 2 */
  334. msg_word++;
  335. *msg_word = 0;
  336. HTT_SRING_SETUP_RING_BASE_ADDR_HI_SET(*msg_word,
  337. (uint64_t)srng_params.ring_base_paddr >> 32);
  338. /* word 3 */
  339. msg_word++;
  340. *msg_word = 0;
  341. HTT_SRING_SETUP_ENTRY_SIZE_SET(*msg_word, ring_entry_size);
  342. HTT_SRING_SETUP_RING_SIZE_SET(*msg_word,
  343. (ring_entry_size * srng_params.num_entries));
  344. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  345. "%s: entry_size %d\n", __func__,
  346. ring_entry_size);
  347. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  348. "%s: num_entries %d\n", __func__,
  349. srng_params.num_entries);
  350. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  351. "%s: ring_size %d\n", __func__,
  352. (ring_entry_size * srng_params.num_entries));
  353. if (htt_ring_type == HTT_SW_TO_HW_RING)
  354. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_LOOPCOUNT_DISABLE_SET(
  355. *msg_word, 1);
  356. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_MSI_SWAP_SET(*msg_word,
  357. !!(srng_params.flags & HAL_SRNG_MSI_SWAP));
  358. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_TLV_SWAP_SET(*msg_word,
  359. !!(srng_params.flags & HAL_SRNG_DATA_TLV_SWAP));
  360. HTT_SRING_SETUP_RING_MISC_CFG_FLAG_HOST_FW_SWAP_SET(*msg_word,
  361. !!(srng_params.flags & HAL_SRNG_RING_PTR_SWAP));
  362. /* word 4 */
  363. msg_word++;
  364. *msg_word = 0;
  365. HTT_SRING_SETUP_HEAD_OFFSET32_REMOTE_BASE_ADDR_LO_SET(*msg_word,
  366. hp_addr & 0xffffffff);
  367. /* word 5 */
  368. msg_word++;
  369. *msg_word = 0;
  370. HTT_SRING_SETUP_HEAD_OFFSET32_REMOTE_BASE_ADDR_HI_SET(*msg_word,
  371. (uint64_t)hp_addr >> 32);
  372. /* word 6 */
  373. msg_word++;
  374. *msg_word = 0;
  375. HTT_SRING_SETUP_TAIL_OFFSET32_REMOTE_BASE_ADDR_LO_SET(*msg_word,
  376. tp_addr & 0xffffffff);
  377. /* word 7 */
  378. msg_word++;
  379. *msg_word = 0;
  380. HTT_SRING_SETUP_TAIL_OFFSET32_REMOTE_BASE_ADDR_HI_SET(*msg_word,
  381. (uint64_t)tp_addr >> 32);
  382. /* word 8 */
  383. msg_word++;
  384. *msg_word = 0;
  385. HTT_SRING_SETUP_RING_MSI_ADDR_LO_SET(*msg_word,
  386. srng_params.msi_addr & 0xffffffff);
  387. /* word 9 */
  388. msg_word++;
  389. *msg_word = 0;
  390. HTT_SRING_SETUP_RING_MSI_ADDR_HI_SET(*msg_word,
  391. (uint64_t)(srng_params.msi_addr) >> 32);
  392. /* word 10 */
  393. msg_word++;
  394. *msg_word = 0;
  395. HTT_SRING_SETUP_RING_MSI_DATA_SET(*msg_word,
  396. srng_params.msi_data);
  397. /* word 11 */
  398. msg_word++;
  399. *msg_word = 0;
  400. HTT_SRING_SETUP_INTR_BATCH_COUNTER_TH_SET(*msg_word,
  401. srng_params.intr_batch_cntr_thres_entries *
  402. ring_entry_size);
  403. HTT_SRING_SETUP_INTR_TIMER_TH_SET(*msg_word,
  404. srng_params.intr_timer_thres_us >> 3);
  405. /* word 12 */
  406. msg_word++;
  407. *msg_word = 0;
  408. if (srng_params.flags & HAL_SRNG_LOW_THRES_INTR_ENABLE) {
  409. /* TODO: Setting low threshold to 1/8th of ring size - see
  410. * if this needs to be configurable
  411. */
  412. HTT_SRING_SETUP_INTR_LOW_TH_SET(*msg_word,
  413. srng_params.low_threshold);
  414. }
  415. /* "response_required" field should be set if a HTT response message is
  416. * required after setting up the ring.
  417. */
  418. pkt = htt_htc_pkt_alloc(soc);
  419. if (!pkt)
  420. goto fail1;
  421. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  422. SET_HTC_PACKET_INFO_TX(
  423. &pkt->htc_pkt,
  424. dp_htt_h2t_send_complete_free_netbuf,
  425. qdf_nbuf_data(htt_msg),
  426. qdf_nbuf_len(htt_msg),
  427. soc->htc_endpoint,
  428. 1); /* tag - not relevant here */
  429. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, htt_msg);
  430. htc_send_pkt(soc->htc_soc, &pkt->htc_pkt);
  431. return QDF_STATUS_SUCCESS;
  432. fail1:
  433. qdf_nbuf_free(htt_msg);
  434. fail0:
  435. return QDF_STATUS_E_FAILURE;
  436. }
  437. /*
  438. * htt_h2t_rx_ring_cfg() - Send SRNG packet and TLV filter
  439. * config message to target
  440. * @htt_soc: HTT SOC handle
  441. * @pdev_id: PDEV Id
  442. * @hal_srng: Opaque HAL SRNG pointer
  443. * @hal_ring_type: SRNG ring type
  444. * @ring_buf_size: SRNG buffer size
  445. * @htt_tlv_filter: Rx SRNG TLV and filter setting
  446. * Return: 0 on success; error code on failure
  447. */
  448. int htt_h2t_rx_ring_cfg(void *htt_soc, int pdev_id, void *hal_srng,
  449. int hal_ring_type, int ring_buf_size,
  450. struct htt_rx_ring_tlv_filter *htt_tlv_filter)
  451. {
  452. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  453. struct dp_htt_htc_pkt *pkt;
  454. qdf_nbuf_t htt_msg;
  455. uint32_t *msg_word;
  456. struct hal_srng_params srng_params;
  457. uint32_t htt_ring_type, htt_ring_id;
  458. uint32_t tlv_filter;
  459. htt_msg = qdf_nbuf_alloc(soc->osdev,
  460. HTT_MSG_BUF_SIZE(HTT_RX_RING_SELECTION_CFG_SZ),
  461. /* reserve room for the HTC header */
  462. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  463. if (!htt_msg)
  464. goto fail0;
  465. hal_get_srng_params(soc->hal_soc, hal_srng, &srng_params);
  466. switch (hal_ring_type) {
  467. case RXDMA_BUF:
  468. #if QCA_HOST2FW_RXBUF_RING
  469. htt_ring_id = HTT_HOST1_TO_FW_RXBUF_RING;
  470. htt_ring_type = HTT_SW_TO_SW_RING;
  471. #else
  472. htt_ring_id = HTT_RXDMA_HOST_BUF_RING;
  473. htt_ring_type = HTT_SW_TO_HW_RING;
  474. #endif
  475. break;
  476. case RXDMA_MONITOR_BUF:
  477. htt_ring_id = HTT_RXDMA_MONITOR_BUF_RING;
  478. htt_ring_type = HTT_SW_TO_HW_RING;
  479. break;
  480. case RXDMA_MONITOR_STATUS:
  481. htt_ring_id = HTT_RXDMA_MONITOR_STATUS_RING;
  482. htt_ring_type = HTT_SW_TO_HW_RING;
  483. break;
  484. case RXDMA_MONITOR_DST:
  485. htt_ring_id = HTT_RXDMA_MONITOR_DEST_RING;
  486. htt_ring_type = HTT_HW_TO_SW_RING;
  487. break;
  488. case RXDMA_MONITOR_DESC:
  489. htt_ring_id = HTT_RXDMA_MONITOR_DESC_RING;
  490. htt_ring_type = HTT_SW_TO_HW_RING;
  491. break;
  492. case RXDMA_DST:
  493. htt_ring_id = HTT_RXDMA_NON_MONITOR_DEST_RING;
  494. htt_ring_type = HTT_HW_TO_SW_RING;
  495. break;
  496. default:
  497. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  498. "%s: Ring currently not supported\n", __func__);
  499. goto fail1;
  500. }
  501. /*
  502. * Set the length of the message.
  503. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  504. * separately during the below call to qdf_nbuf_push_head.
  505. * The contribution from the HTC header is added separately inside HTC.
  506. */
  507. if (qdf_nbuf_put_tail(htt_msg, HTT_RX_RING_SELECTION_CFG_SZ) == NULL) {
  508. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  509. "%s: Failed to expand head for RX Ring Cfg msg\n",
  510. __func__);
  511. goto fail1; /* failure */
  512. }
  513. msg_word = (uint32_t *)qdf_nbuf_data(htt_msg);
  514. /* rewind beyond alignment pad to get to the HTC header reserved area */
  515. qdf_nbuf_push_head(htt_msg, HTC_HDR_ALIGNMENT_PADDING);
  516. /* word 0 */
  517. *msg_word = 0;
  518. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_RX_RING_SELECTION_CFG);
  519. /*
  520. * pdev_id is indexed from 0 whereas mac_id is indexed from 1
  521. * SW_TO_SW and SW_TO_HW rings are unaffected by this
  522. */
  523. if (htt_ring_type == HTT_SW_TO_SW_RING ||
  524. htt_ring_type == HTT_SW_TO_HW_RING)
  525. HTT_RX_RING_SELECTION_CFG_PDEV_ID_SET(*msg_word,
  526. DP_SW2HW_MACID(pdev_id));
  527. /* TODO: Discuss with FW on changing this to unique ID and using
  528. * htt_ring_type to send the type of ring
  529. */
  530. HTT_RX_RING_SELECTION_CFG_RING_ID_SET(*msg_word, htt_ring_id);
  531. HTT_RX_RING_SELECTION_CFG_STATUS_TLV_SET(*msg_word,
  532. !!(srng_params.flags & HAL_SRNG_MSI_SWAP));
  533. HTT_RX_RING_SELECTION_CFG_PKT_TLV_SET(*msg_word,
  534. !!(srng_params.flags & HAL_SRNG_DATA_TLV_SWAP));
  535. /* word 1 */
  536. msg_word++;
  537. *msg_word = 0;
  538. HTT_RX_RING_SELECTION_CFG_RING_BUFFER_SIZE_SET(*msg_word,
  539. ring_buf_size);
  540. /* word 2 */
  541. msg_word++;
  542. *msg_word = 0;
  543. if (htt_tlv_filter->enable_fp) {
  544. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  545. MGMT, 0000, 1);
  546. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  547. MGMT, 0001, 1);
  548. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  549. MGMT, 0010, 1);
  550. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  551. MGMT, 0011, 1);
  552. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  553. MGMT, 0100, 1);
  554. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  555. MGMT, 0101, 1);
  556. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  557. MGMT, 0110, 1);
  558. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  559. MGMT, 0111, 1);
  560. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  561. MGMT, 1000, 1);
  562. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, FP,
  563. MGMT, 1001, 1);
  564. }
  565. if (htt_tlv_filter->enable_md) {
  566. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  567. MGMT, 0000, 1);
  568. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  569. MGMT, 0001, 1);
  570. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  571. MGMT, 0010, 1);
  572. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  573. MGMT, 0011, 1);
  574. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  575. MGMT, 0100, 1);
  576. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  577. MGMT, 0101, 1);
  578. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  579. MGMT, 0110, 1);
  580. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  581. MGMT, 0111, 1);
  582. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  583. MGMT, 1000, 1);
  584. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MD,
  585. MGMT, 1001, 1);
  586. }
  587. if (htt_tlv_filter->enable_mo) {
  588. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  589. MGMT, 0000, 1);
  590. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  591. MGMT, 0001, 1);
  592. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  593. MGMT, 0010, 1);
  594. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  595. MGMT, 0011, 1);
  596. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  597. MGMT, 0100, 1);
  598. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  599. MGMT, 0101, 1);
  600. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  601. MGMT, 0110, 1);
  602. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  603. MGMT, 0111, 1);
  604. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  605. MGMT, 1000, 1);
  606. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG0, MO,
  607. MGMT, 1001, 1);
  608. }
  609. /* word 3 */
  610. msg_word++;
  611. *msg_word = 0;
  612. if (htt_tlv_filter->enable_fp) {
  613. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  614. MGMT, 1010, 1);
  615. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  616. MGMT, 1011, 1);
  617. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  618. MGMT, 1100, 1);
  619. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  620. MGMT, 1101, 1);
  621. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  622. MGMT, 1110, 1);
  623. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, FP,
  624. MGMT, 1111, 1);
  625. }
  626. if (htt_tlv_filter->enable_md) {
  627. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  628. MGMT, 1010, 1);
  629. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  630. MGMT, 1011, 1);
  631. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  632. MGMT, 1100, 1);
  633. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  634. MGMT, 1101, 1);
  635. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MD,
  636. MGMT, 1110, 1);
  637. }
  638. if (htt_tlv_filter->enable_mo) {
  639. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  640. MGMT, 1010, 1);
  641. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  642. MGMT, 1011, 1);
  643. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  644. MGMT, 1100, 1);
  645. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  646. MGMT, 1101, 1);
  647. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  648. MGMT, 1110, 1);
  649. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG1, MO,
  650. MGMT, 1111, 1);
  651. }
  652. /* word 4 */
  653. msg_word++;
  654. *msg_word = 0;
  655. if (htt_tlv_filter->enable_fp) {
  656. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  657. CTRL, 0000, 1);
  658. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  659. CTRL, 0001, 1);
  660. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  661. CTRL, 0010, 1);
  662. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  663. CTRL, 0011, 1);
  664. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  665. CTRL, 0100, 1);
  666. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  667. CTRL, 0101, 1);
  668. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  669. CTRL, 0110, 1);
  670. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  671. CTRL, 0111, 1);
  672. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  673. CTRL, 1000, 1);
  674. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, FP,
  675. CTRL, 1001, 1);
  676. }
  677. if (htt_tlv_filter->enable_md) {
  678. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  679. CTRL, 0000, 1);
  680. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  681. CTRL, 0001, 1);
  682. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  683. CTRL, 0010, 1);
  684. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  685. CTRL, 0011, 1);
  686. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  687. CTRL, 0100, 1);
  688. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  689. CTRL, 0101, 1);
  690. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  691. CTRL, 0110, 1);
  692. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  693. CTRL, 0111, 1);
  694. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  695. CTRL, 1000, 1);
  696. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MD,
  697. CTRL, 1001, 1);
  698. }
  699. if (htt_tlv_filter->enable_mo) {
  700. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  701. CTRL, 0000, 1);
  702. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  703. CTRL, 0001, 1);
  704. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  705. CTRL, 0010, 1);
  706. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  707. CTRL, 0011, 1);
  708. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  709. CTRL, 0100, 1);
  710. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  711. CTRL, 0101, 1);
  712. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  713. CTRL, 0110, 1);
  714. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  715. CTRL, 0111, 1);
  716. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  717. CTRL, 1000, 1);
  718. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG2, MO,
  719. CTRL, 1001, 1);
  720. }
  721. /* word 5 */
  722. msg_word++;
  723. *msg_word = 0;
  724. if (htt_tlv_filter->enable_fp) {
  725. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  726. CTRL, 1010, 1);
  727. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  728. CTRL, 1011, 1);
  729. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  730. CTRL, 1100, 1);
  731. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  732. CTRL, 1101, 1);
  733. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  734. CTRL, 1110, 1);
  735. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  736. CTRL, 1111, 1);
  737. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  738. DATA, MCAST, 1);
  739. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  740. DATA, UCAST, 1);
  741. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, FP,
  742. DATA, NULL, 1);
  743. }
  744. if (htt_tlv_filter->enable_md) {
  745. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  746. CTRL, 1010, 1);
  747. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  748. CTRL, 1011, 1);
  749. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  750. CTRL, 1100, 1);
  751. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  752. CTRL, 1101, 1);
  753. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  754. CTRL, 1110, 1);
  755. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  756. CTRL, 1111, 1);
  757. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  758. DATA, MCAST, 1);
  759. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  760. DATA, UCAST, 1);
  761. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MD,
  762. DATA, NULL, 1);
  763. }
  764. if (htt_tlv_filter->enable_mo) {
  765. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  766. CTRL, 1010, 1);
  767. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  768. CTRL, 1011, 1);
  769. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  770. CTRL, 1100, 1);
  771. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  772. CTRL, 1101, 1);
  773. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  774. CTRL, 1110, 1);
  775. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  776. CTRL, 1111, 1);
  777. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  778. DATA, MCAST, 1);
  779. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  780. DATA, UCAST, 1);
  781. htt_rx_ring_pkt_enable_subtype_set(*msg_word, FLAG3, MO,
  782. DATA, NULL, 1);
  783. }
  784. /* word 6 */
  785. msg_word++;
  786. *msg_word = 0;
  787. tlv_filter = 0;
  788. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MPDU_START,
  789. htt_tlv_filter->mpdu_start);
  790. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MSDU_START,
  791. htt_tlv_filter->msdu_start);
  792. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PACKET,
  793. htt_tlv_filter->packet);
  794. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MSDU_END,
  795. htt_tlv_filter->msdu_end);
  796. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, MPDU_END,
  797. htt_tlv_filter->mpdu_end);
  798. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PACKET_HEADER,
  799. htt_tlv_filter->packet_header);
  800. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, ATTENTION,
  801. htt_tlv_filter->attention);
  802. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_START,
  803. htt_tlv_filter->ppdu_start);
  804. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_END,
  805. htt_tlv_filter->ppdu_end);
  806. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_END_USER_STATS,
  807. htt_tlv_filter->ppdu_end_user_stats);
  808. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter,
  809. PPDU_END_USER_STATS_EXT,
  810. htt_tlv_filter->ppdu_end_user_stats_ext);
  811. htt_rx_ring_tlv_filter_in_enable_set(tlv_filter, PPDU_END_STATUS_DONE,
  812. htt_tlv_filter->ppdu_end_status_done);
  813. HTT_RX_RING_SELECTION_CFG_TLV_FILTER_IN_FLAG_SET(*msg_word, tlv_filter);
  814. /* "response_required" field should be set if a HTT response message is
  815. * required after setting up the ring.
  816. */
  817. pkt = htt_htc_pkt_alloc(soc);
  818. if (!pkt)
  819. goto fail1;
  820. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  821. SET_HTC_PACKET_INFO_TX(
  822. &pkt->htc_pkt,
  823. dp_htt_h2t_send_complete_free_netbuf,
  824. qdf_nbuf_data(htt_msg),
  825. qdf_nbuf_len(htt_msg),
  826. soc->htc_endpoint,
  827. 1); /* tag - not relevant here */
  828. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, htt_msg);
  829. htc_send_pkt(soc->htc_soc, &pkt->htc_pkt);
  830. return QDF_STATUS_SUCCESS;
  831. fail1:
  832. qdf_nbuf_free(htt_msg);
  833. fail0:
  834. return QDF_STATUS_E_FAILURE;
  835. }
  836. /**
  837. * dp_process_htt_stat_msg(): Process the list of buffers of HTT EXT stats
  838. * @soc: DP SOC handle
  839. *
  840. * The FW sends the HTT EXT STATS as a stream of T2H messages. Each T2H message
  841. * contains sub messages which are identified by a TLV header.
  842. * In this function we will process the stream of T2H messages and read all the
  843. * TLV contained in the message.
  844. *
  845. * THe following cases have been taken care of
  846. * Case 1: When the tlv_remain_length <= msg_remain_length of HTT MSG buffer
  847. * In this case the buffer will contain multiple tlvs.
  848. * Case 2: When the tlv_remain_length > msg_remain_length of HTT MSG buffer.
  849. * Only one tlv will be contained in the HTT message and this tag
  850. * will extend onto the next buffer.
  851. * Case 3: When the buffer is the continuation of the previous message
  852. * Case 4: tlv length is 0. which will indicate the end of message
  853. *
  854. * return: void
  855. */
  856. static inline void dp_process_htt_stat_msg(struct dp_soc *soc)
  857. {
  858. htt_tlv_tag_t tlv_type = 0xff;
  859. qdf_nbuf_t htt_msg = NULL;
  860. uint32_t *msg_word;
  861. uint8_t *tlv_buf_head = NULL;
  862. uint8_t *tlv_buf_tail = NULL;
  863. uint32_t msg_remain_len = 0;
  864. uint32_t tlv_remain_len = 0;
  865. uint32_t *tlv_start;
  866. /* Process node in the HTT message queue */
  867. while ((htt_msg = qdf_nbuf_queue_remove(&soc->htt_stats_msg)) != NULL) {
  868. msg_word = (uint32_t *) qdf_nbuf_data(htt_msg);
  869. /* read 5th word */
  870. msg_word = msg_word + 4;
  871. msg_remain_len = qdf_min(soc->htt_msg_len,
  872. (uint32_t)DP_EXT_MSG_LENGTH);
  873. /* Keep processing the node till node length is 0 */
  874. while (msg_remain_len) {
  875. /*
  876. * if message is not a continuation of previous message
  877. * read the tlv type and tlv length
  878. */
  879. if (!tlv_buf_head) {
  880. tlv_type = HTT_STATS_TLV_TAG_GET(
  881. *msg_word);
  882. tlv_remain_len = HTT_STATS_TLV_LENGTH_GET(
  883. *msg_word);
  884. }
  885. if (tlv_remain_len == 0) {
  886. msg_remain_len = 0;
  887. if (tlv_buf_head) {
  888. qdf_mem_free(tlv_buf_head);
  889. tlv_buf_head = NULL;
  890. tlv_buf_tail = NULL;
  891. }
  892. goto error;
  893. }
  894. tlv_remain_len += HTT_TLV_HDR_LEN;
  895. if ((tlv_remain_len <= msg_remain_len)) {
  896. /* Case 3 */
  897. if (tlv_buf_head) {
  898. qdf_mem_copy(tlv_buf_tail,
  899. (uint8_t *)msg_word,
  900. tlv_remain_len);
  901. tlv_start = (uint32_t *)tlv_buf_head;
  902. } else {
  903. /* Case 1 */
  904. tlv_start = msg_word;
  905. }
  906. dp_htt_stats_print_tag(tlv_type, tlv_start);
  907. msg_remain_len -= tlv_remain_len;
  908. msg_word = (uint32_t *)
  909. (((uint8_t *)msg_word) +
  910. tlv_remain_len);
  911. tlv_remain_len = 0;
  912. if (tlv_buf_head) {
  913. qdf_mem_free(tlv_buf_head);
  914. tlv_buf_head = NULL;
  915. tlv_buf_tail = NULL;
  916. }
  917. } else { /* tlv_remain_len > msg_remain_len */
  918. /* Case 2 & 3 */
  919. if (!tlv_buf_head) {
  920. tlv_buf_head = qdf_mem_malloc(
  921. tlv_remain_len);
  922. if (!tlv_buf_head) {
  923. QDF_TRACE(QDF_MODULE_ID_TXRX,
  924. QDF_TRACE_LEVEL_ERROR,
  925. "Alloc failed");
  926. goto error;
  927. }
  928. tlv_buf_tail = tlv_buf_head;
  929. }
  930. qdf_mem_copy(tlv_buf_tail, (uint8_t *)msg_word,
  931. msg_remain_len);
  932. tlv_remain_len -= msg_remain_len;
  933. tlv_buf_tail += msg_remain_len;
  934. msg_remain_len = 0;
  935. }
  936. }
  937. if (soc->htt_msg_len >= DP_EXT_MSG_LENGTH) {
  938. soc->htt_msg_len -= DP_EXT_MSG_LENGTH;
  939. }
  940. qdf_nbuf_free(htt_msg);
  941. }
  942. soc->htt_msg_len = 0;
  943. return;
  944. error:
  945. qdf_nbuf_free(htt_msg);
  946. soc->htt_msg_len = 0;
  947. while ((htt_msg = qdf_nbuf_queue_remove(&soc->htt_stats_msg))
  948. != NULL)
  949. qdf_nbuf_free(htt_msg);
  950. }
  951. /**
  952. * dp_txrx_fw_stats_handler():Function to process HTT EXT stats
  953. * @soc: DP SOC handle
  954. * @htt_t2h_msg: HTT message nbuf
  955. *
  956. * return:void
  957. */
  958. static inline void dp_txrx_fw_stats_handler(struct dp_soc *soc,
  959. qdf_nbuf_t htt_t2h_msg)
  960. {
  961. uint32_t length;
  962. uint8_t done;
  963. qdf_nbuf_t msg_copy;
  964. uint32_t *msg_word;
  965. msg_word = (uint32_t *) qdf_nbuf_data(htt_t2h_msg);
  966. msg_word = msg_word + 3;
  967. done = 0;
  968. length = HTT_T2H_EXT_STATS_CONF_TLV_LENGTH_GET(*msg_word);
  969. done = HTT_T2H_EXT_STATS_CONF_TLV_DONE_GET(*msg_word);
  970. /*
  971. * HTT EXT stats response comes as stream of TLVs which span over
  972. * multiple T2H messages.
  973. * The first message will carry length of the response.
  974. * For rest of the messages length will be zero.
  975. */
  976. if (soc->htt_msg_len && length)
  977. goto error;
  978. if (length)
  979. soc->htt_msg_len = length;
  980. /*
  981. * Clone the T2H message buffer and store it in a list to process
  982. * it later.
  983. *
  984. * The original T2H message buffers gets freed in the T2H HTT event
  985. * handler
  986. */
  987. msg_copy = qdf_nbuf_clone(htt_t2h_msg);
  988. if (!msg_copy) {
  989. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  990. "T2H messge clone failed for HTT EXT STATS");
  991. soc->htt_msg_len = 0;
  992. goto error;
  993. }
  994. qdf_nbuf_queue_add(&soc->htt_stats_msg, msg_copy);
  995. /*
  996. * Done bit signifies that this is the last T2H buffer in the stream of
  997. * HTT EXT STATS message
  998. */
  999. if (done)
  1000. dp_process_htt_stat_msg(soc);
  1001. return;
  1002. error:
  1003. while ((msg_copy = qdf_nbuf_queue_remove(&soc->htt_stats_msg))
  1004. != NULL) {
  1005. qdf_nbuf_free(msg_copy);
  1006. }
  1007. return;
  1008. }
  1009. /*
  1010. * htt_soc_attach_target() - SOC level HTT setup
  1011. * @htt_soc: HTT SOC handle
  1012. *
  1013. * Return: 0 on success; error code on failure
  1014. */
  1015. int htt_soc_attach_target(void *htt_soc)
  1016. {
  1017. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  1018. return htt_h2t_ver_req_msg(soc);
  1019. }
  1020. /*
  1021. * dp_htt_t2h_msg_handler() - Generic Target to host Msg/event handler
  1022. * @context: Opaque context (HTT SOC handle)
  1023. * @pkt: HTC packet
  1024. */
  1025. static void dp_htt_t2h_msg_handler(void *context, HTC_PACKET *pkt)
  1026. {
  1027. struct htt_soc *soc = (struct htt_soc *) context;
  1028. qdf_nbuf_t htt_t2h_msg = (qdf_nbuf_t) pkt->pPktContext;
  1029. u_int32_t *msg_word;
  1030. enum htt_t2h_msg_type msg_type;
  1031. /* check for successful message reception */
  1032. if (pkt->Status != QDF_STATUS_SUCCESS) {
  1033. if (pkt->Status != QDF_STATUS_E_CANCELED)
  1034. soc->stats.htc_err_cnt++;
  1035. qdf_nbuf_free(htt_t2h_msg);
  1036. return;
  1037. }
  1038. /* TODO: Check if we should pop the HTC/HTT header alignment padding */
  1039. msg_word = (u_int32_t *) qdf_nbuf_data(htt_t2h_msg);
  1040. msg_type = HTT_T2H_MSG_TYPE_GET(*msg_word);
  1041. switch (msg_type) {
  1042. case HTT_T2H_MSG_TYPE_PEER_MAP:
  1043. {
  1044. u_int8_t mac_addr_deswizzle_buf[HTT_MAC_ADDR_LEN];
  1045. u_int8_t *peer_mac_addr;
  1046. u_int16_t peer_id;
  1047. u_int16_t hw_peer_id;
  1048. u_int8_t vdev_id;
  1049. peer_id = HTT_RX_PEER_MAP_PEER_ID_GET(*msg_word);
  1050. hw_peer_id =
  1051. HTT_RX_PEER_MAP_HW_PEER_ID_GET(*(msg_word+2));
  1052. vdev_id = HTT_RX_PEER_MAP_VDEV_ID_GET(*msg_word);
  1053. peer_mac_addr = htt_t2h_mac_addr_deswizzle(
  1054. (u_int8_t *) (msg_word+1),
  1055. &mac_addr_deswizzle_buf[0]);
  1056. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1057. QDF_TRACE_LEVEL_INFO,
  1058. "HTT_T2H_MSG_TYPE_PEER_MAP msg for peer id %d vdev id %d n",
  1059. peer_id, vdev_id);
  1060. dp_rx_peer_map_handler(soc->dp_soc, peer_id, hw_peer_id,
  1061. vdev_id, peer_mac_addr);
  1062. break;
  1063. }
  1064. case HTT_T2H_MSG_TYPE_PEER_UNMAP:
  1065. {
  1066. u_int16_t peer_id;
  1067. peer_id = HTT_RX_PEER_UNMAP_PEER_ID_GET(*msg_word);
  1068. dp_rx_peer_unmap_handler(soc->dp_soc, peer_id);
  1069. break;
  1070. }
  1071. case HTT_T2H_MSG_TYPE_SEC_IND:
  1072. {
  1073. u_int16_t peer_id;
  1074. enum htt_sec_type sec_type;
  1075. int is_unicast;
  1076. peer_id = HTT_SEC_IND_PEER_ID_GET(*msg_word);
  1077. sec_type = HTT_SEC_IND_SEC_TYPE_GET(*msg_word);
  1078. is_unicast = HTT_SEC_IND_UNICAST_GET(*msg_word);
  1079. /* point to the first part of the Michael key */
  1080. msg_word++;
  1081. dp_rx_sec_ind_handler(
  1082. soc->dp_soc, peer_id, sec_type, is_unicast,
  1083. msg_word, msg_word + 2);
  1084. break;
  1085. }
  1086. #if defined(CONFIG_WIN) && WDI_EVENT_ENABLE
  1087. #ifndef REMOVE_PKT_LOG
  1088. case HTT_T2H_MSG_TYPE_PKTLOG:
  1089. {
  1090. u_int32_t *pl_hdr;
  1091. pl_hdr = (msg_word + 1);
  1092. dp_wdi_event_handler(WDI_EVENT_OFFLOAD_ALL, soc->dp_soc,
  1093. (void *)pl_hdr, HTT_INVALID_PEER, WDI_NO_VAL, 0);
  1094. break;
  1095. }
  1096. case HTT_T2H_MSG_TYPE_PPDU_STATS_IND:
  1097. {
  1098. qdf_nbuf_set_pktlen(htt_t2h_msg, HTT_T2H_MAX_MSG_SIZE);
  1099. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  1100. "received HTT_T2H_MSG_TYPE_PPDU_STATS_IND\n");
  1101. dp_wdi_event_handler(WDI_EVENT_LITE_T2H, soc->dp_soc,
  1102. htt_t2h_msg, HTT_INVALID_PEER, WDI_NO_VAL, 0);
  1103. break;
  1104. }
  1105. #endif
  1106. #endif
  1107. case HTT_T2H_MSG_TYPE_VERSION_CONF:
  1108. {
  1109. soc->tgt_ver.major = HTT_VER_CONF_MAJOR_GET(*msg_word);
  1110. soc->tgt_ver.minor = HTT_VER_CONF_MINOR_GET(*msg_word);
  1111. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  1112. "target uses HTT version %d.%d; host uses %d.%d\n",
  1113. soc->tgt_ver.major, soc->tgt_ver.minor,
  1114. HTT_CURRENT_VERSION_MAJOR,
  1115. HTT_CURRENT_VERSION_MINOR);
  1116. if (soc->tgt_ver.major != HTT_CURRENT_VERSION_MAJOR) {
  1117. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1118. QDF_TRACE_LEVEL_ERROR,
  1119. "*** Incompatible host/target HTT versions!\n");
  1120. }
  1121. /* abort if the target is incompatible with the host */
  1122. qdf_assert(soc->tgt_ver.major ==
  1123. HTT_CURRENT_VERSION_MAJOR);
  1124. if (soc->tgt_ver.minor != HTT_CURRENT_VERSION_MINOR) {
  1125. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1126. QDF_TRACE_LEVEL_WARN,
  1127. "*** Warning: host/target HTT versions"
  1128. " are different, though compatible!\n");
  1129. }
  1130. break;
  1131. }
  1132. case HTT_T2H_MSG_TYPE_RX_ADDBA:
  1133. {
  1134. uint16_t peer_id;
  1135. uint8_t tid;
  1136. uint8_t win_sz;
  1137. uint16_t status;
  1138. struct dp_peer *peer;
  1139. /*
  1140. * Update REO Queue Desc with new values
  1141. */
  1142. peer_id = HTT_RX_ADDBA_PEER_ID_GET(*msg_word);
  1143. tid = HTT_RX_ADDBA_TID_GET(*msg_word);
  1144. win_sz = HTT_RX_ADDBA_WIN_SIZE_GET(*msg_word);
  1145. peer = dp_peer_find_by_id(soc->dp_soc, peer_id);
  1146. /*
  1147. * Window size needs to be incremented by 1
  1148. * since fw needs to represent a value of 256
  1149. * using just 8 bits
  1150. */
  1151. if (peer) {
  1152. status = dp_addba_requestprocess_wifi3(peer,
  1153. 0, tid, 0, win_sz + 1, 0xffff);
  1154. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1155. QDF_TRACE_LEVEL_INFO,
  1156. FL("PeerID %d BAW %d TID %d stat %d\n"),
  1157. peer_id, win_sz, tid, status);
  1158. } else {
  1159. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1160. QDF_TRACE_LEVEL_ERROR,
  1161. FL("Peer not found peer id %d\n"),
  1162. peer_id);
  1163. }
  1164. break;
  1165. }
  1166. case HTT_T2H_MSG_TYPE_EXT_STATS_CONF:
  1167. {
  1168. dp_txrx_fw_stats_handler(soc->dp_soc, htt_t2h_msg);
  1169. break;
  1170. }
  1171. default:
  1172. break;
  1173. };
  1174. /* Free the indication buffer */
  1175. qdf_nbuf_free(htt_t2h_msg);
  1176. }
  1177. /*
  1178. * dp_htt_h2t_full() - Send full handler (called from HTC)
  1179. * @context: Opaque context (HTT SOC handle)
  1180. * @pkt: HTC packet
  1181. *
  1182. * Return: enum htc_send_full_action
  1183. */
  1184. static enum htc_send_full_action
  1185. dp_htt_h2t_full(void *context, HTC_PACKET *pkt)
  1186. {
  1187. return HTC_SEND_FULL_KEEP;
  1188. }
  1189. /*
  1190. * htt_htc_soc_attach() - Register SOC level HTT instance with HTC
  1191. * @htt_soc: HTT SOC handle
  1192. *
  1193. * Return: 0 on success; error code on failure
  1194. */
  1195. static int
  1196. htt_htc_soc_attach(struct htt_soc *soc)
  1197. {
  1198. struct htc_service_connect_req connect;
  1199. struct htc_service_connect_resp response;
  1200. A_STATUS status;
  1201. qdf_mem_set(&connect, sizeof(connect), 0);
  1202. qdf_mem_set(&response, sizeof(response), 0);
  1203. connect.pMetaData = NULL;
  1204. connect.MetaDataLength = 0;
  1205. connect.EpCallbacks.pContext = soc;
  1206. connect.EpCallbacks.EpTxComplete = dp_htt_h2t_send_complete;
  1207. connect.EpCallbacks.EpTxCompleteMultiple = NULL;
  1208. connect.EpCallbacks.EpRecv = dp_htt_t2h_msg_handler;
  1209. /* rx buffers currently are provided by HIF, not by EpRecvRefill */
  1210. connect.EpCallbacks.EpRecvRefill = NULL;
  1211. /* N/A, fill is done by HIF */
  1212. connect.EpCallbacks.RecvRefillWaterMark = 1;
  1213. connect.EpCallbacks.EpSendFull = dp_htt_h2t_full;
  1214. /*
  1215. * Specify how deep to let a queue get before htc_send_pkt will
  1216. * call the EpSendFull function due to excessive send queue depth.
  1217. */
  1218. connect.MaxSendQueueDepth = DP_HTT_MAX_SEND_QUEUE_DEPTH;
  1219. /* disable flow control for HTT data message service */
  1220. connect.ConnectionFlags |= HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL;
  1221. /* connect to control service */
  1222. connect.service_id = HTT_DATA_MSG_SVC;
  1223. status = htc_connect_service(soc->htc_soc, &connect, &response);
  1224. if (status != A_OK)
  1225. return QDF_STATUS_E_FAILURE;
  1226. soc->htc_endpoint = response.Endpoint;
  1227. return 0; /* success */
  1228. }
  1229. /*
  1230. * htt_soc_attach() - SOC level HTT initialization
  1231. * @dp_soc: Opaque Data path SOC handle
  1232. * @osif_soc: Opaque OSIF SOC handle
  1233. * @htc_soc: SOC level HTC handle
  1234. * @hal_soc: Opaque HAL SOC handle
  1235. * @osdev: QDF device
  1236. *
  1237. * Return: HTT handle on success; NULL on failure
  1238. */
  1239. void *
  1240. htt_soc_attach(void *dp_soc, void *osif_soc, HTC_HANDLE htc_soc,
  1241. void *hal_soc, qdf_device_t osdev)
  1242. {
  1243. struct htt_soc *soc;
  1244. int i;
  1245. soc = qdf_mem_malloc(sizeof(*soc));
  1246. if (!soc)
  1247. goto fail1;
  1248. soc->osdev = osdev;
  1249. soc->osif_soc = osif_soc;
  1250. soc->dp_soc = dp_soc;
  1251. soc->htc_soc = htc_soc;
  1252. soc->hal_soc = hal_soc;
  1253. /* TODO: See if any NSS related context is requred in htt_soc */
  1254. soc->htt_htc_pkt_freelist = NULL;
  1255. if (htt_htc_soc_attach(soc))
  1256. goto fail2;
  1257. /* TODO: See if any Rx data specific intialization is required. For
  1258. * MCL use cases, the data will be received as single packet and
  1259. * should not required any descriptor or reorder handling
  1260. */
  1261. HTT_TX_MUTEX_INIT(&soc->htt_tx_mutex);
  1262. /* pre-allocate some HTC_PACKET objects */
  1263. for (i = 0; i < HTT_HTC_PKT_POOL_INIT_SIZE; i++) {
  1264. struct dp_htt_htc_pkt_union *pkt;
  1265. pkt = qdf_mem_malloc(sizeof(*pkt));
  1266. if (!pkt)
  1267. break;
  1268. htt_htc_pkt_free(soc, &pkt->u.pkt);
  1269. }
  1270. return soc;
  1271. fail2:
  1272. qdf_mem_free(soc);
  1273. fail1:
  1274. return NULL;
  1275. }
  1276. /*
  1277. * htt_soc_detach() - Detach SOC level HTT
  1278. * @htt_soc: HTT SOC handle
  1279. */
  1280. void
  1281. htt_soc_detach(void *htt_soc)
  1282. {
  1283. struct htt_soc *soc = (struct htt_soc *)htt_soc;
  1284. htt_htc_pkt_pool_free(soc);
  1285. HTT_TX_MUTEX_DESTROY(&soc->htt_tx_mutex);
  1286. qdf_mem_free(soc);
  1287. }
  1288. /**
  1289. * dp_h2t_ext_stats_msg_send(): function to contruct HTT message to pass to FW
  1290. * @pdev: DP PDEV handle
  1291. * @stats_type_upload_mask: stats type requested by user
  1292. * @config_param_0: extra configuration parameters
  1293. * @config_param_1: extra configuration parameters
  1294. * @config_param_2: extra configuration parameters
  1295. * @config_param_3: extra configuration parameters
  1296. *
  1297. * return: QDF STATUS
  1298. */
  1299. QDF_STATUS dp_h2t_ext_stats_msg_send(struct dp_pdev *pdev,
  1300. uint32_t stats_type_upload_mask, uint32_t config_param_0,
  1301. uint32_t config_param_1, uint32_t config_param_2,
  1302. uint32_t config_param_3)
  1303. {
  1304. struct htt_soc *soc = pdev->soc->htt_handle;
  1305. struct dp_htt_htc_pkt *pkt;
  1306. qdf_nbuf_t msg;
  1307. uint32_t *msg_word;
  1308. uint8_t pdev_mask;
  1309. msg = qdf_nbuf_alloc(
  1310. soc->osdev,
  1311. HTT_MSG_BUF_SIZE(HTT_H2T_EXT_STATS_REQ_MSG_SZ),
  1312. HTC_HEADER_LEN + HTC_HDR_ALIGNMENT_PADDING, 4, TRUE);
  1313. if (!msg)
  1314. return QDF_STATUS_E_NOMEM;
  1315. /*TODO:Add support for SOC stats
  1316. * Bit 0: SOC Stats
  1317. * Bit 1: Pdev stats for pdev id 0
  1318. * Bit 2: Pdev stats for pdev id 1
  1319. * Bit 3: Pdev stats for pdev id 2
  1320. */
  1321. pdev_mask = 1 << (pdev->pdev_id + 1);
  1322. /*
  1323. * Set the length of the message.
  1324. * The contribution from the HTC_HDR_ALIGNMENT_PADDING is added
  1325. * separately during the below call to qdf_nbuf_push_head.
  1326. * The contribution from the HTC header is added separately inside HTC.
  1327. */
  1328. if (qdf_nbuf_put_tail(msg, HTT_H2T_EXT_STATS_REQ_MSG_SZ) == NULL) {
  1329. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1330. "Failed to expand head for HTT_EXT_STATS");
  1331. qdf_nbuf_free(msg);
  1332. return QDF_STATUS_E_FAILURE;
  1333. }
  1334. msg_word = (uint32_t *) qdf_nbuf_data(msg);
  1335. qdf_nbuf_push_head(msg, HTC_HDR_ALIGNMENT_PADDING);
  1336. *msg_word = 0;
  1337. HTT_H2T_MSG_TYPE_SET(*msg_word, HTT_H2T_MSG_TYPE_EXT_STATS_REQ);
  1338. HTT_H2T_EXT_STATS_REQ_PDEV_MASK_SET(*msg_word, pdev_mask);
  1339. HTT_H2T_EXT_STATS_REQ_STATS_TYPE_SET(*msg_word, stats_type_upload_mask);
  1340. /* word 1 */
  1341. msg_word++;
  1342. *msg_word = 0;
  1343. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_0);
  1344. /* word 2 */
  1345. msg_word++;
  1346. *msg_word = 0;
  1347. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_1);
  1348. /* word 3 */
  1349. msg_word++;
  1350. *msg_word = 0;
  1351. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_2);
  1352. /* word 4 */
  1353. msg_word++;
  1354. *msg_word = 0;
  1355. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, config_param_3);
  1356. HTT_H2T_EXT_STATS_REQ_CONFIG_PARAM_SET(*msg_word, 0);
  1357. pkt = htt_htc_pkt_alloc(soc);
  1358. if (!pkt) {
  1359. qdf_nbuf_free(msg);
  1360. return QDF_STATUS_E_NOMEM;
  1361. }
  1362. pkt->soc_ctxt = NULL; /* not used during send-done callback */
  1363. SET_HTC_PACKET_INFO_TX(&pkt->htc_pkt,
  1364. dp_htt_h2t_send_complete_free_netbuf,
  1365. qdf_nbuf_data(msg), qdf_nbuf_len(msg),
  1366. soc->htc_endpoint,
  1367. 1); /* tag - not relevant here */
  1368. SET_HTC_PACKET_NET_BUF_CONTEXT(&pkt->htc_pkt, msg);
  1369. return htc_send_pkt(soc->htc_soc, &pkt->htc_pkt);
  1370. }