dp_htt.c 41 KB

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