dp_htt.c 51 KB

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