ce_bmi.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /*
  2. * Copyright (c) 2015-2018 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 "targcfg.h"
  19. #include "qdf_lock.h"
  20. #include "qdf_status.h"
  21. #include "qdf_status.h"
  22. #include <qdf_atomic.h> /* qdf_atomic_read */
  23. #include <targaddrs.h>
  24. #include "hif_io32.h"
  25. #include <hif.h>
  26. #include "regtable.h"
  27. #define ATH_MODULE_NAME hif
  28. #include <a_debug.h>
  29. #include "hif_main.h"
  30. #include "ce_api.h"
  31. #include "ce_bmi.h"
  32. #include "qdf_trace.h"
  33. #include "hif_debug.h"
  34. #include "bmi_msg.h"
  35. #include "qdf_module.h"
  36. /* Track a BMI transaction that is in progress */
  37. #ifndef BIT
  38. #define BIT(n) (1 << (n))
  39. #endif
  40. enum {
  41. BMI_REQ_SEND_DONE = BIT(0), /* the bmi tx completion */
  42. BMI_RESP_RECV_DONE = BIT(1), /* the bmi respond is received */
  43. };
  44. struct BMI_transaction {
  45. struct HIF_CE_state *hif_state;
  46. qdf_semaphore_t bmi_transaction_sem;
  47. uint8_t *bmi_request_host; /* Req BMI msg in Host addr space */
  48. qdf_dma_addr_t bmi_request_CE; /* Req BMI msg in CE addr space */
  49. uint32_t bmi_request_length; /* Length of BMI request */
  50. uint8_t *bmi_response_host; /* Rsp BMI msg in Host addr space */
  51. qdf_dma_addr_t bmi_response_CE; /* Rsp BMI msg in CE addr space */
  52. unsigned int bmi_response_length; /* Length of received response */
  53. unsigned int bmi_timeout_ms;
  54. uint32_t bmi_transaction_flags; /* flags for the transcation */
  55. };
  56. /*
  57. * send/recv completion functions for BMI.
  58. * NB: The "net_buf" parameter is actually just a
  59. * straight buffer, not an sk_buff.
  60. */
  61. void hif_bmi_send_done(struct CE_handle *copyeng, void *ce_context,
  62. void *transfer_context, qdf_dma_addr_t data,
  63. unsigned int nbytes,
  64. unsigned int transfer_id, unsigned int sw_index,
  65. unsigned int hw_index, uint32_t toeplitz_hash_result)
  66. {
  67. struct BMI_transaction *transaction =
  68. (struct BMI_transaction *)transfer_context;
  69. #ifdef BMI_RSP_POLLING
  70. /*
  71. * Fix EV118783, Release a semaphore after sending
  72. * no matter whether a response is been expecting now.
  73. */
  74. qdf_semaphore_release(&transaction->bmi_transaction_sem);
  75. #else
  76. /*
  77. * If a response is anticipated, we'll complete the
  78. * transaction if the response has been received.
  79. * If no response is anticipated, complete the
  80. * transaction now.
  81. */
  82. transaction->bmi_transaction_flags |= BMI_REQ_SEND_DONE;
  83. /* resp is't needed or has already been received,
  84. * never assume resp comes later then this
  85. */
  86. if (!transaction->bmi_response_CE ||
  87. (transaction->bmi_transaction_flags & BMI_RESP_RECV_DONE)) {
  88. qdf_semaphore_release(&transaction->bmi_transaction_sem);
  89. }
  90. #endif
  91. }
  92. #ifndef BMI_RSP_POLLING
  93. void hif_bmi_recv_data(struct CE_handle *copyeng, void *ce_context,
  94. void *transfer_context, qdf_dma_addr_t data,
  95. unsigned int nbytes,
  96. unsigned int transfer_id, unsigned int flags)
  97. {
  98. struct BMI_transaction *transaction =
  99. (struct BMI_transaction *)transfer_context;
  100. transaction->bmi_response_length = nbytes;
  101. transaction->bmi_transaction_flags |= BMI_RESP_RECV_DONE;
  102. /* when both send/recv are done, the sem can be released */
  103. if (transaction->bmi_transaction_flags & BMI_REQ_SEND_DONE)
  104. qdf_semaphore_release(&transaction->bmi_transaction_sem);
  105. }
  106. #endif
  107. QDF_STATUS hif_exchange_bmi_msg(struct hif_opaque_softc *hif_ctx,
  108. qdf_dma_addr_t bmi_cmd_da,
  109. qdf_dma_addr_t bmi_rsp_da,
  110. uint8_t *bmi_request,
  111. uint32_t request_length,
  112. uint8_t *bmi_response,
  113. uint32_t *bmi_response_lengthp,
  114. uint32_t TimeoutMS)
  115. {
  116. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  117. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  118. struct HIF_CE_pipe_info *send_pipe_info =
  119. &(hif_state->pipe_info[BMI_CE_NUM_TO_TARG]);
  120. struct CE_handle *ce_send_hdl = send_pipe_info->ce_hdl;
  121. qdf_dma_addr_t CE_request, CE_response = 0;
  122. struct BMI_transaction *transaction = NULL;
  123. int status = QDF_STATUS_SUCCESS;
  124. struct HIF_CE_pipe_info *recv_pipe_info =
  125. &(hif_state->pipe_info[BMI_CE_NUM_TO_HOST]);
  126. struct CE_handle *ce_recv = recv_pipe_info->ce_hdl;
  127. unsigned int mux_id = 0;
  128. unsigned int transaction_id = 0xffff;
  129. unsigned int user_flags = 0;
  130. #ifdef BMI_RSP_POLLING
  131. qdf_dma_addr_t buf;
  132. unsigned int completed_nbytes, id, flags;
  133. int i;
  134. #endif
  135. transaction =
  136. (struct BMI_transaction *)qdf_mem_malloc(sizeof(*transaction));
  137. if (unlikely(!transaction)) {
  138. HIF_ERROR("%s: no memory", __func__);
  139. return QDF_STATUS_E_NOMEM;
  140. }
  141. transaction_id = (mux_id & MUX_ID_MASK) |
  142. (transaction_id & TRANSACTION_ID_MASK);
  143. #ifdef QCA_WIFI_3_0
  144. user_flags &= DESC_DATA_FLAG_MASK;
  145. #endif
  146. A_TARGET_ACCESS_LIKELY(scn);
  147. /* Initialize bmi_transaction_sem to block */
  148. qdf_semaphore_init(&transaction->bmi_transaction_sem);
  149. qdf_semaphore_acquire(&transaction->bmi_transaction_sem);
  150. transaction->hif_state = hif_state;
  151. transaction->bmi_request_host = bmi_request;
  152. transaction->bmi_request_length = request_length;
  153. transaction->bmi_response_length = 0;
  154. transaction->bmi_timeout_ms = TimeoutMS;
  155. transaction->bmi_transaction_flags = 0;
  156. /*
  157. * CE_request = dma_map_single(dev,
  158. * (void *)bmi_request, request_length, DMA_TO_DEVICE);
  159. */
  160. CE_request = bmi_cmd_da;
  161. transaction->bmi_request_CE = CE_request;
  162. if (bmi_response) {
  163. /*
  164. * CE_response = dma_map_single(dev, bmi_response,
  165. * BMI_DATASZ_MAX, DMA_FROM_DEVICE);
  166. */
  167. CE_response = bmi_rsp_da;
  168. transaction->bmi_response_host = bmi_response;
  169. transaction->bmi_response_CE = CE_response;
  170. /* dma_cache_sync(dev, bmi_response,
  171. * BMI_DATASZ_MAX, DMA_FROM_DEVICE);
  172. */
  173. qdf_mem_dma_sync_single_for_device(scn->qdf_dev,
  174. CE_response,
  175. BMI_DATASZ_MAX,
  176. DMA_FROM_DEVICE);
  177. ce_recv_buf_enqueue(ce_recv, transaction,
  178. transaction->bmi_response_CE);
  179. /* NB: see HIF_BMI_recv_done */
  180. } else {
  181. transaction->bmi_response_host = NULL;
  182. transaction->bmi_response_CE = 0;
  183. }
  184. /* dma_cache_sync(dev, bmi_request, request_length, DMA_TO_DEVICE); */
  185. qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_request,
  186. request_length, DMA_TO_DEVICE);
  187. status =
  188. ce_send(ce_send_hdl, transaction,
  189. CE_request, request_length,
  190. transaction_id, 0, user_flags);
  191. ASSERT(status == QDF_STATUS_SUCCESS);
  192. /* NB: see hif_bmi_send_done */
  193. /* TBDXXX: handle timeout */
  194. /* Wait for BMI request/response transaction to complete */
  195. /* Always just wait for BMI request here if
  196. * BMI_RSP_POLLING is defined
  197. */
  198. while (qdf_semaphore_acquire
  199. (&transaction->bmi_transaction_sem)) {
  200. /*need some break out condition(time out?) */
  201. }
  202. if (bmi_response) {
  203. #ifdef BMI_RSP_POLLING
  204. /* Fix EV118783, do not wait a semaphore for the BMI response
  205. * since the relative interruption may be lost.
  206. * poll the BMI response instead.
  207. */
  208. i = 0;
  209. while (ce_completed_recv_next(
  210. ce_recv, NULL, NULL, &buf,
  211. &completed_nbytes, &id,
  212. &flags) != QDF_STATUS_SUCCESS) {
  213. if (i++ > BMI_RSP_TO_MILLISEC) {
  214. HIF_ERROR("%s:error, can't get bmi response",
  215. __func__);
  216. status = QDF_STATUS_E_BUSY;
  217. break;
  218. }
  219. OS_DELAY(1000);
  220. }
  221. if ((status == QDF_STATUS_SUCCESS) && bmi_response_lengthp)
  222. *bmi_response_lengthp = completed_nbytes;
  223. #else
  224. if ((status == QDF_STATUS_SUCCESS) && bmi_response_lengthp) {
  225. *bmi_response_lengthp =
  226. transaction->bmi_response_length;
  227. }
  228. #endif
  229. }
  230. /* dma_unmap_single(dev, transaction->bmi_request_CE,
  231. * request_length, DMA_TO_DEVICE);
  232. * bus_unmap_single(scn->sc_osdev,
  233. * transaction->bmi_request_CE,
  234. * request_length, BUS_DMA_TODEVICE);
  235. */
  236. if (status != QDF_STATUS_SUCCESS) {
  237. qdf_dma_addr_t unused_buffer;
  238. unsigned int unused_nbytes;
  239. unsigned int unused_id;
  240. unsigned int toeplitz_hash_result;
  241. ce_cancel_send_next(ce_send_hdl,
  242. NULL, NULL, &unused_buffer,
  243. &unused_nbytes, &unused_id,
  244. &toeplitz_hash_result);
  245. }
  246. A_TARGET_ACCESS_UNLIKELY(scn);
  247. qdf_mem_free(transaction);
  248. return status;
  249. }
  250. qdf_export_symbol(hif_exchange_bmi_msg);
  251. #ifdef BMI_RSP_POLLING
  252. #define BMI_RSP_CB_REGISTER 0
  253. #else
  254. #define BMI_RSP_CB_REGISTER 1
  255. #endif
  256. /**
  257. * hif_register_bmi_callbacks() - register bmi callbacks
  258. * @hif_sc: hif context
  259. *
  260. * Bmi phase uses different copy complete callbacks than mission mode.
  261. */
  262. void hif_register_bmi_callbacks(struct hif_softc *hif_sc)
  263. {
  264. struct HIF_CE_pipe_info *pipe_info;
  265. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
  266. /*
  267. * Initially, establish CE completion handlers for use with BMI.
  268. * These are overwritten with generic handlers after we exit BMI phase.
  269. */
  270. pipe_info = &hif_state->pipe_info[BMI_CE_NUM_TO_TARG];
  271. ce_send_cb_register(pipe_info->ce_hdl, hif_bmi_send_done, pipe_info, 0);
  272. if (BMI_RSP_CB_REGISTER) {
  273. pipe_info = &hif_state->pipe_info[BMI_CE_NUM_TO_HOST];
  274. ce_recv_cb_register(
  275. pipe_info->ce_hdl, hif_bmi_recv_data, pipe_info, 0);
  276. }
  277. }