htt.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/slab.h>
  18. #include <linux/if_ether.h>
  19. #include "htt.h"
  20. #include "core.h"
  21. #include "debug.h"
  22. static const enum htt_t2h_msg_type htt_main_t2h_msg_types[] = {
  23. [HTT_MAIN_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF,
  24. [HTT_MAIN_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND,
  25. [HTT_MAIN_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH,
  26. [HTT_MAIN_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP,
  27. [HTT_MAIN_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP,
  28. [HTT_MAIN_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA,
  29. [HTT_MAIN_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA,
  30. [HTT_MAIN_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND,
  31. [HTT_MAIN_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG,
  32. [HTT_MAIN_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF,
  33. [HTT_MAIN_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND,
  34. [HTT_MAIN_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND,
  35. [HTT_MAIN_T2H_MSG_TYPE_TX_INSPECT_IND] =
  36. HTT_T2H_MSG_TYPE_TX_INSPECT_IND,
  37. [HTT_MAIN_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] =
  38. HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION,
  39. [HTT_MAIN_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND] =
  40. HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND,
  41. [HTT_MAIN_T2H_MSG_TYPE_RX_PN_IND] = HTT_T2H_MSG_TYPE_RX_PN_IND,
  42. [HTT_MAIN_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND] =
  43. HTT_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND,
  44. [HTT_MAIN_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST,
  45. };
  46. static const enum htt_t2h_msg_type htt_10x_t2h_msg_types[] = {
  47. [HTT_10X_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF,
  48. [HTT_10X_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND,
  49. [HTT_10X_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH,
  50. [HTT_10X_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP,
  51. [HTT_10X_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP,
  52. [HTT_10X_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA,
  53. [HTT_10X_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA,
  54. [HTT_10X_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND,
  55. [HTT_10X_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG,
  56. [HTT_10X_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF,
  57. [HTT_10X_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND,
  58. [HTT_10X_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND,
  59. [HTT_10X_T2H_MSG_TYPE_RC_UPDATE_IND] = HTT_T2H_MSG_TYPE_RC_UPDATE_IND,
  60. [HTT_10X_T2H_MSG_TYPE_TX_INSPECT_IND] = HTT_T2H_MSG_TYPE_TX_INSPECT_IND,
  61. [HTT_10X_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST,
  62. [HTT_10X_T2H_MSG_TYPE_CHAN_CHANGE] = HTT_T2H_MSG_TYPE_CHAN_CHANGE,
  63. [HTT_10X_T2H_MSG_TYPE_AGGR_CONF] = HTT_T2H_MSG_TYPE_AGGR_CONF,
  64. [HTT_10X_T2H_MSG_TYPE_STATS_NOUPLOAD] = HTT_T2H_MSG_TYPE_STATS_NOUPLOAD,
  65. [HTT_10X_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] =
  66. HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION,
  67. };
  68. static const enum htt_t2h_msg_type htt_tlv_t2h_msg_types[] = {
  69. [HTT_TLV_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF,
  70. [HTT_TLV_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND,
  71. [HTT_TLV_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH,
  72. [HTT_TLV_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP,
  73. [HTT_TLV_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP,
  74. [HTT_TLV_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA,
  75. [HTT_TLV_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA,
  76. [HTT_TLV_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND,
  77. [HTT_TLV_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG,
  78. [HTT_TLV_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF,
  79. [HTT_TLV_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND,
  80. [HTT_TLV_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND,
  81. [HTT_TLV_T2H_MSG_TYPE_RC_UPDATE_IND] = HTT_T2H_MSG_TYPE_RC_UPDATE_IND,
  82. [HTT_TLV_T2H_MSG_TYPE_TX_INSPECT_IND] = HTT_T2H_MSG_TYPE_TX_INSPECT_IND,
  83. [HTT_TLV_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] =
  84. HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION,
  85. [HTT_TLV_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND] =
  86. HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND,
  87. [HTT_TLV_T2H_MSG_TYPE_RX_PN_IND] = HTT_T2H_MSG_TYPE_RX_PN_IND,
  88. [HTT_TLV_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND] =
  89. HTT_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND,
  90. [HTT_TLV_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND] =
  91. HTT_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND,
  92. [HTT_TLV_T2H_MSG_TYPE_WDI_IPA_OP_RESPONSE] =
  93. HTT_T2H_MSG_TYPE_WDI_IPA_OP_RESPONSE,
  94. [HTT_TLV_T2H_MSG_TYPE_CHAN_CHANGE] = HTT_T2H_MSG_TYPE_CHAN_CHANGE,
  95. [HTT_TLV_T2H_MSG_TYPE_RX_OFLD_PKT_ERR] =
  96. HTT_T2H_MSG_TYPE_RX_OFLD_PKT_ERR,
  97. [HTT_TLV_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST,
  98. };
  99. static const enum htt_t2h_msg_type htt_10_4_t2h_msg_types[] = {
  100. [HTT_10_4_T2H_MSG_TYPE_VERSION_CONF] = HTT_T2H_MSG_TYPE_VERSION_CONF,
  101. [HTT_10_4_T2H_MSG_TYPE_RX_IND] = HTT_T2H_MSG_TYPE_RX_IND,
  102. [HTT_10_4_T2H_MSG_TYPE_RX_FLUSH] = HTT_T2H_MSG_TYPE_RX_FLUSH,
  103. [HTT_10_4_T2H_MSG_TYPE_PEER_MAP] = HTT_T2H_MSG_TYPE_PEER_MAP,
  104. [HTT_10_4_T2H_MSG_TYPE_PEER_UNMAP] = HTT_T2H_MSG_TYPE_PEER_UNMAP,
  105. [HTT_10_4_T2H_MSG_TYPE_RX_ADDBA] = HTT_T2H_MSG_TYPE_RX_ADDBA,
  106. [HTT_10_4_T2H_MSG_TYPE_RX_DELBA] = HTT_T2H_MSG_TYPE_RX_DELBA,
  107. [HTT_10_4_T2H_MSG_TYPE_TX_COMPL_IND] = HTT_T2H_MSG_TYPE_TX_COMPL_IND,
  108. [HTT_10_4_T2H_MSG_TYPE_PKTLOG] = HTT_T2H_MSG_TYPE_PKTLOG,
  109. [HTT_10_4_T2H_MSG_TYPE_STATS_CONF] = HTT_T2H_MSG_TYPE_STATS_CONF,
  110. [HTT_10_4_T2H_MSG_TYPE_RX_FRAG_IND] = HTT_T2H_MSG_TYPE_RX_FRAG_IND,
  111. [HTT_10_4_T2H_MSG_TYPE_SEC_IND] = HTT_T2H_MSG_TYPE_SEC_IND,
  112. [HTT_10_4_T2H_MSG_TYPE_RC_UPDATE_IND] = HTT_T2H_MSG_TYPE_RC_UPDATE_IND,
  113. [HTT_10_4_T2H_MSG_TYPE_TX_INSPECT_IND] =
  114. HTT_T2H_MSG_TYPE_TX_INSPECT_IND,
  115. [HTT_10_4_T2H_MSG_TYPE_MGMT_TX_COMPL_IND] =
  116. HTT_T2H_MSG_TYPE_MGMT_TX_COMPLETION,
  117. [HTT_10_4_T2H_MSG_TYPE_CHAN_CHANGE] = HTT_T2H_MSG_TYPE_CHAN_CHANGE,
  118. [HTT_10_4_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND] =
  119. HTT_T2H_MSG_TYPE_TX_CREDIT_UPDATE_IND,
  120. [HTT_10_4_T2H_MSG_TYPE_RX_PN_IND] = HTT_T2H_MSG_TYPE_RX_PN_IND,
  121. [HTT_10_4_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND] =
  122. HTT_T2H_MSG_TYPE_RX_OFFLOAD_DELIVER_IND,
  123. [HTT_10_4_T2H_MSG_TYPE_TEST] = HTT_T2H_MSG_TYPE_TEST,
  124. [HTT_10_4_T2H_MSG_TYPE_EN_STATS] = HTT_T2H_MSG_TYPE_EN_STATS,
  125. [HTT_10_4_T2H_MSG_TYPE_AGGR_CONF] = HTT_T2H_MSG_TYPE_AGGR_CONF,
  126. [HTT_10_4_T2H_MSG_TYPE_TX_FETCH_IND] =
  127. HTT_T2H_MSG_TYPE_TX_FETCH_IND,
  128. [HTT_10_4_T2H_MSG_TYPE_TX_FETCH_CONF] =
  129. HTT_T2H_MSG_TYPE_TX_FETCH_CONF,
  130. [HTT_10_4_T2H_MSG_TYPE_STATS_NOUPLOAD] =
  131. HTT_T2H_MSG_TYPE_STATS_NOUPLOAD,
  132. [HTT_10_4_T2H_MSG_TYPE_TX_LOW_LATENCY_IND] =
  133. HTT_T2H_MSG_TYPE_TX_LOW_LATENCY_IND,
  134. };
  135. int ath10k_htt_connect(struct ath10k_htt *htt)
  136. {
  137. struct ath10k_htc_svc_conn_req conn_req;
  138. struct ath10k_htc_svc_conn_resp conn_resp;
  139. int status;
  140. memset(&conn_req, 0, sizeof(conn_req));
  141. memset(&conn_resp, 0, sizeof(conn_resp));
  142. conn_req.ep_ops.ep_tx_complete = ath10k_htt_htc_tx_complete;
  143. conn_req.ep_ops.ep_rx_complete = ath10k_htt_t2h_msg_handler;
  144. /* connect to control service */
  145. conn_req.service_id = ATH10K_HTC_SVC_ID_HTT_DATA_MSG;
  146. status = ath10k_htc_connect_service(&htt->ar->htc, &conn_req,
  147. &conn_resp);
  148. if (status)
  149. return status;
  150. htt->eid = conn_resp.eid;
  151. return 0;
  152. }
  153. int ath10k_htt_init(struct ath10k *ar)
  154. {
  155. struct ath10k_htt *htt = &ar->htt;
  156. htt->ar = ar;
  157. /*
  158. * Prefetch enough data to satisfy target
  159. * classification engine.
  160. * This is for LL chips. HL chips will probably
  161. * transfer all frame in the tx fragment.
  162. */
  163. htt->prefetch_len =
  164. 36 + /* 802.11 + qos + ht */
  165. 4 + /* 802.1q */
  166. 8 + /* llc snap */
  167. 2; /* ip4 dscp or ip6 priority */
  168. switch (ar->htt.op_version) {
  169. case ATH10K_FW_HTT_OP_VERSION_10_4:
  170. ar->htt.t2h_msg_types = htt_10_4_t2h_msg_types;
  171. ar->htt.t2h_msg_types_max = HTT_10_4_T2H_NUM_MSGS;
  172. break;
  173. case ATH10K_FW_HTT_OP_VERSION_10_1:
  174. ar->htt.t2h_msg_types = htt_10x_t2h_msg_types;
  175. ar->htt.t2h_msg_types_max = HTT_10X_T2H_NUM_MSGS;
  176. break;
  177. case ATH10K_FW_HTT_OP_VERSION_TLV:
  178. ar->htt.t2h_msg_types = htt_tlv_t2h_msg_types;
  179. ar->htt.t2h_msg_types_max = HTT_TLV_T2H_NUM_MSGS;
  180. break;
  181. case ATH10K_FW_HTT_OP_VERSION_MAIN:
  182. ar->htt.t2h_msg_types = htt_main_t2h_msg_types;
  183. ar->htt.t2h_msg_types_max = HTT_MAIN_T2H_NUM_MSGS;
  184. break;
  185. case ATH10K_FW_HTT_OP_VERSION_MAX:
  186. case ATH10K_FW_HTT_OP_VERSION_UNSET:
  187. WARN_ON(1);
  188. return -EINVAL;
  189. }
  190. return 0;
  191. }
  192. #define HTT_TARGET_VERSION_TIMEOUT_HZ (3*HZ)
  193. static int ath10k_htt_verify_version(struct ath10k_htt *htt)
  194. {
  195. struct ath10k *ar = htt->ar;
  196. ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt target version %d.%d\n",
  197. htt->target_version_major, htt->target_version_minor);
  198. if (htt->target_version_major != 2 &&
  199. htt->target_version_major != 3) {
  200. ath10k_err(ar, "unsupported htt major version %d. supported versions are 2 and 3\n",
  201. htt->target_version_major);
  202. return -ENOTSUPP;
  203. }
  204. return 0;
  205. }
  206. int ath10k_htt_setup(struct ath10k_htt *htt)
  207. {
  208. struct ath10k *ar = htt->ar;
  209. int status;
  210. init_completion(&htt->target_version_received);
  211. status = ath10k_htt_h2t_ver_req_msg(htt);
  212. if (status)
  213. return status;
  214. status = wait_for_completion_timeout(&htt->target_version_received,
  215. HTT_TARGET_VERSION_TIMEOUT_HZ);
  216. if (status == 0) {
  217. ath10k_warn(ar, "htt version request timed out\n");
  218. return -ETIMEDOUT;
  219. }
  220. status = ath10k_htt_verify_version(htt);
  221. if (status) {
  222. ath10k_warn(ar, "failed to verify htt version: %d\n",
  223. status);
  224. return status;
  225. }
  226. status = ath10k_htt_send_frag_desc_bank_cfg(htt);
  227. if (status)
  228. return status;
  229. status = ath10k_htt_send_rx_ring_cfg_ll(htt);
  230. if (status) {
  231. ath10k_warn(ar, "failed to setup rx ring: %d\n",
  232. status);
  233. return status;
  234. }
  235. status = ath10k_htt_h2t_aggr_cfg_msg(htt,
  236. htt->max_num_ampdu,
  237. htt->max_num_amsdu);
  238. if (status) {
  239. ath10k_warn(ar, "failed to setup amsdu/ampdu limit: %d\n",
  240. status);
  241. return status;
  242. }
  243. return 0;
  244. }