htt.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. // SPDX-License-Identifier: ISC
  2. /*
  3. * Copyright (c) 2005-2011 Atheros Communications Inc.
  4. * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
  5. * Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
  6. */
  7. #include <linux/slab.h>
  8. #include <linux/if_ether.h>
  9. #include "htt.h"
  10. #include "core.h"
  11. #include "debug.h"
  12. #include "hif.h"
  13. static const enum htt_t2h_msg_type htt_main_t2h_msg_types[] = {
  14. [HTT_MAIN_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF,
  15. [HTT_MAIN_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND,
  16. [HTT_MAIN_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH,
  17. [HTT_MAIN_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP,
  18. [HTT_MAIN_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP,
  19. [HTT_MAIN_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA,
  20. [HTT_MAIN_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA,
  21. [HTT_MAIN_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND,
  22. [HTT_MAIN_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG,
  23. [HTT_MAIN_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF,
  24. [HTT_MAIN_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND,
  25. [HTT_MAIN_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND,
  26. [HTT_MAIN_T2H_MSG_TYPE_TX_INSPECT_IND] =
  27. HTT_T2H_MSG_TYPE_TX_INSPECT_IND,
  28. [HTT_MAIN_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] =
  29. HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION,
  30. [HTT_MAIN_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND] =
  31. HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND,
  32. [HTT_MAIN_T2H_MSG_TYPE_RX_PN_IND] = HTT_T2H_MSG_TYPE_RX_PN_IND,
  33. [HTT_MAIN_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND] =
  34. HTT_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND,
  35. [HTT_MAIN_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST,
  36. };
  37. static const enum htt_t2h_msg_type htt_10x_t2h_msg_types[] = {
  38. [HTT_10X_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF,
  39. [HTT_10X_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND,
  40. [HTT_10X_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH,
  41. [HTT_10X_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP,
  42. [HTT_10X_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP,
  43. [HTT_10X_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA,
  44. [HTT_10X_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA,
  45. [HTT_10X_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND,
  46. [HTT_10X_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG,
  47. [HTT_10X_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF,
  48. [HTT_10X_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND,
  49. [HTT_10X_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND,
  50. [HTT_10X_T2H_MSG_TYPE_RC_UPDATE_IND] = HTT_T2H_MSG_TYPE_RC_UPDATE_IND,
  51. [HTT_10X_T2H_MSG_TYPE_TX_INSPECT_IND] = HTT_T2H_MSG_TYPE_TX_INSPECT_IND,
  52. [HTT_10X_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST,
  53. [HTT_10X_T2H_MSG_TYPE_CHAN_CHANGE] = HTT_T2H_MSG_TYPE_CHAN_CHANGE,
  54. [HTT_10X_T2H_MSG_TYPE_AGGR_CONF] = HTT_T2H_MSG_TYPE_AGGR_CONF,
  55. [HTT_10X_T2H_MSG_TYPE_STATS_NOUPLOAD] = HTT_T2H_MSG_TYPE_STATS_NOUPLOAD,
  56. [HTT_10X_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] =
  57. HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION,
  58. };
  59. static const enum htt_t2h_msg_type htt_tlv_t2h_msg_types[] = {
  60. [HTT_TLV_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF,
  61. [HTT_TLV_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND,
  62. [HTT_TLV_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH,
  63. [HTT_TLV_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP,
  64. [HTT_TLV_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP,
  65. [HTT_TLV_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA,
  66. [HTT_TLV_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA,
  67. [HTT_TLV_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND,
  68. [HTT_TLV_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG,
  69. [HTT_TLV_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF,
  70. [HTT_TLV_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND,
  71. [HTT_TLV_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND,
  72. [HTT_TLV_T2H_MSG_TYPE_RC_UPDATE_IND] = HTT_T2H_MSG_TYPE_RC_UPDATE_IND,
  73. [HTT_TLV_T2H_MSG_TYPE_TX_INSPECT_IND] = HTT_T2H_MSG_TYPE_TX_INSPECT_IND,
  74. [HTT_TLV_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] =
  75. HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION,
  76. [HTT_TLV_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND] =
  77. HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND,
  78. [HTT_TLV_T2H_MSG_TYPE_RX_PN_IND] = HTT_T2H_MSG_TYPE_RX_PN_IND,
  79. [HTT_TLV_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND] =
  80. HTT_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND,
  81. [HTT_TLV_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND] =
  82. HTT_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND,
  83. [HTT_TLV_T2H_MSG_TYPE_WDI_IPA_OP_RESPONSE] =
  84. HTT_T2H_MSG_TYPE_WDI_IPA_OP_RESPONSE,
  85. [HTT_TLV_T2H_MSG_TYPE_CHAN_CHANGE] = HTT_T2H_MSG_TYPE_CHAN_CHANGE,
  86. [HTT_TLV_T2H_MSG_TYPE_RX_OFLD_PKT_ERR] =
  87. HTT_T2H_MSG_TYPE_RX_OFLD_PKT_ERR,
  88. [HTT_TLV_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST,
  89. };
  90. static const enum htt_t2h_msg_type htt_10_4_t2h_msg_types[] = {
  91. [HTT_10_4_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF,
  92. [HTT_10_4_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND,
  93. [HTT_10_4_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH,
  94. [HTT_10_4_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP,
  95. [HTT_10_4_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP,
  96. [HTT_10_4_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA,
  97. [HTT_10_4_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA,
  98. [HTT_10_4_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND,
  99. [HTT_10_4_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG,
  100. [HTT_10_4_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF,
  101. [HTT_10_4_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND,
  102. [HTT_10_4_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND,
  103. [HTT_10_4_T2H_MSG_TYPE_RC_UPDATE_IND] = HTT_T2H_MSG_TYPE_RC_UPDATE_IND,
  104. [HTT_10_4_T2H_MSG_TYPE_TX_INSPECT_IND] =
  105. HTT_T2H_MSG_TYPE_TX_INSPECT_IND,
  106. [HTT_10_4_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] =
  107. HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION,
  108. [HTT_10_4_T2H_MSG_TYPE_CHAN_CHANGE] = HTT_T2H_MSG_TYPE_CHAN_CHANGE,
  109. [HTT_10_4_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND] =
  110. HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND,
  111. [HTT_10_4_T2H_MSG_TYPE_RX_PN_IND] = HTT_T2H_MSG_TYPE_RX_PN_IND,
  112. [HTT_10_4_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND] =
  113. HTT_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND,
  114. [HTT_10_4_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST,
  115. [HTT_10_4_T2H_MSG_TYPE_EN_STATS] = HTT_T2H_MSG_TYPE_EN_STATS,
  116. [HTT_10_4_T2H_MSG_TYPE_AGGR_CONF] = HTT_T2H_MSG_TYPE_AGGR_CONF,
  117. [HTT_10_4_T2H_MSG_TYPE_TX_FETCH_IND] =
  118. HTT_T2H_MSG_TYPE_TX_FETCH_IND,
  119. [HTT_10_4_T2H_MSG_TYPE_TX_FETCH_CONFIRM] =
  120. HTT_T2H_MSG_TYPE_TX_FETCH_CONFIRM,
  121. [HTT_10_4_T2H_MSG_TYPE_STATS_NOUPLOAD] =
  122. HTT_T2H_MSG_TYPE_STATS_NOUPLOAD,
  123. [HTT_10_4_T2H_MSG_TYPE_TX_MODE_SWITCH_IND] =
  124. HTT_T2H_MSG_TYPE_TX_MODE_SWITCH_IND,
  125. [HTT_10_4_T2H_MSG_TYPE_PEER_STATS] =
  126. HTT_T2H_MSG_TYPE_PEER_STATS,
  127. };
  128. const struct ath10k_htt_rx_desc_ops qca988x_rx_desc_ops = {
  129. .rx_desc_size = sizeof(struct htt_rx_desc_v1),
  130. .rx_desc_msdu_payload_offset = offsetof(struct htt_rx_desc_v1, msdu_payload)
  131. };
  132. static int ath10k_qca99x0_rx_desc_get_l3_pad_bytes(struct htt_rx_desc *rxd)
  133. {
  134. struct htt_rx_desc_v1 *rx_desc = container_of(rxd,
  135. struct htt_rx_desc_v1,
  136. base);
  137. return MS(__le32_to_cpu(rx_desc->msdu_end.qca99x0.info1),
  138. RX_MSDU_END_INFO1_L3_HDR_PAD);
  139. }
  140. static bool ath10k_qca99x0_rx_desc_msdu_limit_error(struct htt_rx_desc *rxd)
  141. {
  142. struct htt_rx_desc_v1 *rx_desc = container_of(rxd,
  143. struct htt_rx_desc_v1,
  144. base);
  145. return !!(rx_desc->msdu_end.common.info0 &
  146. __cpu_to_le32(RX_MSDU_END_INFO0_MSDU_LIMIT_ERR));
  147. }
  148. const struct ath10k_htt_rx_desc_ops qca99x0_rx_desc_ops = {
  149. .rx_desc_size = sizeof(struct htt_rx_desc_v1),
  150. .rx_desc_msdu_payload_offset = offsetof(struct htt_rx_desc_v1, msdu_payload),
  151. .rx_desc_get_l3_pad_bytes = ath10k_qca99x0_rx_desc_get_l3_pad_bytes,
  152. .rx_desc_get_msdu_limit_error = ath10k_qca99x0_rx_desc_msdu_limit_error,
  153. };
  154. static void ath10k_rx_desc_wcn3990_get_offsets(struct htt_rx_ring_rx_desc_offsets *off)
  155. {
  156. #define desc_offset(x) (offsetof(struct htt_rx_desc_v2, x) / 4)
  157. off->mac80211_hdr_offset = __cpu_to_le16(desc_offset(rx_hdr_status));
  158. off->msdu_payload_offset = __cpu_to_le16(desc_offset(msdu_payload));
  159. off->ppdu_start_offset = __cpu_to_le16(desc_offset(ppdu_start));
  160. off->ppdu_end_offset = __cpu_to_le16(desc_offset(ppdu_end));
  161. off->mpdu_start_offset = __cpu_to_le16(desc_offset(mpdu_start));
  162. off->mpdu_end_offset = __cpu_to_le16(desc_offset(mpdu_end));
  163. off->msdu_start_offset = __cpu_to_le16(desc_offset(msdu_start));
  164. off->msdu_end_offset = __cpu_to_le16(desc_offset(msdu_end));
  165. off->rx_attention_offset = __cpu_to_le16(desc_offset(attention));
  166. off->frag_info_offset = __cpu_to_le16(desc_offset(frag_info));
  167. #undef desc_offset
  168. }
  169. static struct htt_rx_desc *
  170. ath10k_rx_desc_wcn3990_from_raw_buffer(void *buff)
  171. {
  172. return &((struct htt_rx_desc_v2 *)buff)->base;
  173. }
  174. static struct rx_attention *
  175. ath10k_rx_desc_wcn3990_get_attention(struct htt_rx_desc *rxd)
  176. {
  177. struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base);
  178. return &rx_desc->attention;
  179. }
  180. static struct rx_frag_info_common *
  181. ath10k_rx_desc_wcn3990_get_frag_info(struct htt_rx_desc *rxd)
  182. {
  183. struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base);
  184. return &rx_desc->frag_info.common;
  185. }
  186. static struct rx_mpdu_start *
  187. ath10k_rx_desc_wcn3990_get_mpdu_start(struct htt_rx_desc *rxd)
  188. {
  189. struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base);
  190. return &rx_desc->mpdu_start;
  191. }
  192. static struct rx_mpdu_end *
  193. ath10k_rx_desc_wcn3990_get_mpdu_end(struct htt_rx_desc *rxd)
  194. {
  195. struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base);
  196. return &rx_desc->mpdu_end;
  197. }
  198. static struct rx_msdu_start_common *
  199. ath10k_rx_desc_wcn3990_get_msdu_start(struct htt_rx_desc *rxd)
  200. {
  201. struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base);
  202. return &rx_desc->msdu_start.common;
  203. }
  204. static struct rx_msdu_end_common *
  205. ath10k_rx_desc_wcn3990_get_msdu_end(struct htt_rx_desc *rxd)
  206. {
  207. struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base);
  208. return &rx_desc->msdu_end.common;
  209. }
  210. static struct rx_ppdu_start *
  211. ath10k_rx_desc_wcn3990_get_ppdu_start(struct htt_rx_desc *rxd)
  212. {
  213. struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base);
  214. return &rx_desc->ppdu_start;
  215. }
  216. static struct rx_ppdu_end_common *
  217. ath10k_rx_desc_wcn3990_get_ppdu_end(struct htt_rx_desc *rxd)
  218. {
  219. struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base);
  220. return &rx_desc->ppdu_end.common;
  221. }
  222. static u8 *
  223. ath10k_rx_desc_wcn3990_get_rx_hdr_status(struct htt_rx_desc *rxd)
  224. {
  225. struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base);
  226. return rx_desc->rx_hdr_status;
  227. }
  228. static u8 *
  229. ath10k_rx_desc_wcn3990_get_msdu_payload(struct htt_rx_desc *rxd)
  230. {
  231. struct htt_rx_desc_v2 *rx_desc = container_of(rxd, struct htt_rx_desc_v2, base);
  232. return rx_desc->msdu_payload;
  233. }
  234. const struct ath10k_htt_rx_desc_ops wcn3990_rx_desc_ops = {
  235. .rx_desc_size = sizeof(struct htt_rx_desc_v2),
  236. .rx_desc_msdu_payload_offset = offsetof(struct htt_rx_desc_v2, msdu_payload),
  237. .rx_desc_from_raw_buffer = ath10k_rx_desc_wcn3990_from_raw_buffer,
  238. .rx_desc_get_offsets = ath10k_rx_desc_wcn3990_get_offsets,
  239. .rx_desc_get_attention = ath10k_rx_desc_wcn3990_get_attention,
  240. .rx_desc_get_frag_info = ath10k_rx_desc_wcn3990_get_frag_info,
  241. .rx_desc_get_mpdu_start = ath10k_rx_desc_wcn3990_get_mpdu_start,
  242. .rx_desc_get_mpdu_end = ath10k_rx_desc_wcn3990_get_mpdu_end,
  243. .rx_desc_get_msdu_start = ath10k_rx_desc_wcn3990_get_msdu_start,
  244. .rx_desc_get_msdu_end = ath10k_rx_desc_wcn3990_get_msdu_end,
  245. .rx_desc_get_ppdu_start = ath10k_rx_desc_wcn3990_get_ppdu_start,
  246. .rx_desc_get_ppdu_end = ath10k_rx_desc_wcn3990_get_ppdu_end,
  247. .rx_desc_get_rx_hdr_status = ath10k_rx_desc_wcn3990_get_rx_hdr_status,
  248. .rx_desc_get_msdu_payload = ath10k_rx_desc_wcn3990_get_msdu_payload,
  249. };
  250. int ath10k_htt_connect(struct ath10k_htt *htt)
  251. {
  252. struct ath10k_htc_svc_conn_req conn_req;
  253. struct ath10k_htc_svc_conn_resp conn_resp;
  254. struct ath10k *ar = htt->ar;
  255. struct ath10k_htc_ep *ep;
  256. int status;
  257. memset(&conn_req, 0, sizeof(conn_req));
  258. memset(&conn_resp, 0, sizeof(conn_resp));
  259. conn_req.ep_ops.ep_tx_complete = ath10k_htt_htc_tx_complete;
  260. conn_req.ep_ops.ep_rx_complete = ath10k_htt_htc_t2h_msg_handler;
  261. conn_req.ep_ops.ep_tx_credits = ath10k_htt_op_ep_tx_credits;
  262. /* connect to control service */
  263. conn_req.service_id = ATH10K_HTC_SVC_ID_HTT_DATA_MSG;
  264. status = ath10k_htc_connect_service(&htt->ar->htc, &conn_req,
  265. &conn_resp);
  266. if (status)
  267. return status;
  268. htt->eid = conn_resp.eid;
  269. if (ar->bus_param.dev_type == ATH10K_DEV_TYPE_HL) {
  270. ep = &ar->htc.endpoint[htt->eid];
  271. ath10k_htc_setup_tx_req(ep);
  272. }
  273. htt->disable_tx_comp = ath10k_hif_get_htt_tx_complete(htt->ar);
  274. if (htt->disable_tx_comp)
  275. ath10k_htc_change_tx_credit_flow(&htt->ar->htc, htt->eid, true);
  276. return 0;
  277. }
  278. int ath10k_htt_init(struct ath10k *ar)
  279. {
  280. struct ath10k_htt *htt = &ar->htt;
  281. htt->ar = ar;
  282. /*
  283. * Prefetch enough data to satisfy target
  284. * classification engine.
  285. * This is for LL chips. HL chips will probably
  286. * transfer all frame in the tx fragment.
  287. */
  288. htt->prefetch_len =
  289. 36 + /* 802.11 + qos + ht */
  290. 4 + /* 802.1q */
  291. 8 + /* llc snap */
  292. 2; /* ip4 dscp or ip6 priority */
  293. switch (ar->running_fw->fw_file.htt_op_version) {
  294. case ATH10K_FW_HTT_OP_VERSION_10_4:
  295. ar->htt.t2h_msg_types = htt_10_4_t2h_msg_types;
  296. ar->htt.t2h_msg_types_max = HTT_10_4_T2H_NUM_MSGS;
  297. break;
  298. case ATH10K_FW_HTT_OP_VERSION_10_1:
  299. ar->htt.t2h_msg_types = htt_10x_t2h_msg_types;
  300. ar->htt.t2h_msg_types_max = HTT_10X_T2H_NUM_MSGS;
  301. break;
  302. case ATH10K_FW_HTT_OP_VERSION_TLV:
  303. ar->htt.t2h_msg_types = htt_tlv_t2h_msg_types;
  304. ar->htt.t2h_msg_types_max = HTT_TLV_T2H_NUM_MSGS;
  305. break;
  306. case ATH10K_FW_HTT_OP_VERSION_MAIN:
  307. ar->htt.t2h_msg_types = htt_main_t2h_msg_types;
  308. ar->htt.t2h_msg_types_max = HTT_MAIN_T2H_NUM_MSGS;
  309. break;
  310. case ATH10K_FW_HTT_OP_VERSION_MAX:
  311. case ATH10K_FW_HTT_OP_VERSION_UNSET:
  312. WARN_ON(1);
  313. return -EINVAL;
  314. }
  315. ath10k_htt_set_tx_ops(htt);
  316. ath10k_htt_set_rx_ops(htt);
  317. return 0;
  318. }
  319. #define HTT_TARGET_VERSION_TIMEOUT_HZ (3 * HZ)
  320. static int ath10k_htt_verify_version(struct ath10k_htt *htt)
  321. {
  322. struct ath10k *ar = htt->ar;
  323. ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt target version %d.%d\n",
  324. htt->target_version_major, htt->target_version_minor);
  325. if (htt->target_version_major != 2 &&
  326. htt->target_version_major != 3) {
  327. ath10k_err(ar, "unsupported htt major version %d. supported versions are 2 and 3\n",
  328. htt->target_version_major);
  329. return -EOPNOTSUPP;
  330. }
  331. return 0;
  332. }
  333. int ath10k_htt_setup(struct ath10k_htt *htt)
  334. {
  335. struct ath10k *ar = htt->ar;
  336. int status;
  337. init_completion(&htt->target_version_received);
  338. status = ath10k_htt_h2t_ver_req_msg(htt);
  339. if (status)
  340. return status;
  341. status = wait_for_completion_timeout(&htt->target_version_received,
  342. HTT_TARGET_VERSION_TIMEOUT_HZ);
  343. if (status == 0) {
  344. ath10k_warn(ar, "htt version request timed out\n");
  345. return -ETIMEDOUT;
  346. }
  347. status = ath10k_htt_verify_version(htt);
  348. if (status) {
  349. ath10k_warn(ar, "failed to verify htt version: %d\n",
  350. status);
  351. return status;
  352. }
  353. status = ath10k_htt_send_frag_desc_bank_cfg(htt);
  354. if (status)
  355. return status;
  356. status = ath10k_htt_send_rx_ring_cfg(htt);
  357. if (status) {
  358. ath10k_warn(ar, "failed to setup rx ring: %d\n",
  359. status);
  360. return status;
  361. }
  362. status = ath10k_htt_h2t_aggr_cfg_msg(htt,
  363. htt->max_num_ampdu,
  364. htt->max_num_amsdu);
  365. if (status) {
  366. ath10k_warn(ar, "failed to setup amsdu/ampdu limit: %d\n",
  367. status);
  368. return status;
  369. }
  370. return 0;
  371. }