dp_htt.c 41 KB

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