dp_htt.c 49 KB

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