dp_reo.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * Copyright (c) 2016-2019 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 "dp_types.h"
  19. #include "hal_reo.h"
  20. #include "dp_internal.h"
  21. #include <qdf_time.h>
  22. #ifdef WLAN_FEATURE_DP_EVENT_HISTORY
  23. /**
  24. * dp_reo_cmd_srng_event_record() - Record reo cmds posted
  25. * to the reo cmd ring
  26. * @soc: dp soc handle
  27. * @type: reo cmd type
  28. * @post_status: command error status
  29. *
  30. * Return: None
  31. */
  32. static
  33. void dp_reo_cmd_srng_event_record(struct dp_soc *soc,
  34. enum hal_reo_cmd_type type,
  35. int post_status)
  36. {
  37. struct reo_cmd_event_history *cmd_event_history =
  38. &soc->stats.cmd_event_history;
  39. struct reo_cmd_event_record *record = cmd_event_history->cmd_record;
  40. int record_index;
  41. record_index = (qdf_atomic_inc_return(&cmd_event_history->index)) &
  42. (REO_CMD_EVENT_HIST_MAX - 1);
  43. record[record_index].cmd_type = type;
  44. record[record_index].cmd_return_status = post_status;
  45. record[record_index].timestamp = qdf_get_log_timestamp();
  46. }
  47. #else
  48. static inline
  49. void dp_reo_cmd_srng_event_record(struct dp_soc *soc,
  50. enum hal_reo_cmd_type type,
  51. int post_status)
  52. {
  53. }
  54. #endif /*WLAN_FEATURE_DP_EVENT_HISTORY */
  55. QDF_STATUS dp_reo_send_cmd(struct dp_soc *soc, enum hal_reo_cmd_type type,
  56. struct hal_reo_cmd_params *params,
  57. void (*callback_fn), void *data)
  58. {
  59. struct dp_reo_cmd_info *reo_cmd;
  60. int num;
  61. switch (type) {
  62. case CMD_GET_QUEUE_STATS:
  63. num = hal_reo_cmd_queue_stats(soc->reo_cmd_ring.hal_srng,
  64. soc->hal_soc, params);
  65. break;
  66. case CMD_FLUSH_QUEUE:
  67. num = hal_reo_cmd_flush_queue(soc->reo_cmd_ring.hal_srng,
  68. soc->hal_soc, params);
  69. break;
  70. case CMD_FLUSH_CACHE:
  71. num = hal_reo_cmd_flush_cache(soc->reo_cmd_ring.hal_srng,
  72. soc->hal_soc, params);
  73. break;
  74. case CMD_UNBLOCK_CACHE:
  75. num = hal_reo_cmd_unblock_cache(soc->reo_cmd_ring.hal_srng,
  76. soc->hal_soc, params);
  77. break;
  78. case CMD_FLUSH_TIMEOUT_LIST:
  79. num = hal_reo_cmd_flush_timeout_list(soc->reo_cmd_ring.hal_srng,
  80. soc->hal_soc, params);
  81. break;
  82. case CMD_UPDATE_RX_REO_QUEUE:
  83. num = hal_reo_cmd_update_rx_queue(soc->reo_cmd_ring.hal_srng,
  84. soc->hal_soc, params);
  85. break;
  86. default:
  87. dp_err_log("Invalid REO command type: %d", type);
  88. return QDF_STATUS_E_FAILURE;
  89. };
  90. dp_reo_cmd_srng_event_record(soc, type, num);
  91. if (num < 0) {
  92. dp_err_log("Error with sending REO command type: %d", type);
  93. return QDF_STATUS_E_FAILURE;
  94. }
  95. if (callback_fn) {
  96. reo_cmd = qdf_mem_malloc(sizeof(*reo_cmd));
  97. if (!reo_cmd) {
  98. dp_err_log("alloc failed for REO cmd:%d!!",
  99. type);
  100. return QDF_STATUS_E_NOMEM;
  101. }
  102. reo_cmd->cmd = num;
  103. reo_cmd->cmd_type = type;
  104. reo_cmd->handler = callback_fn;
  105. reo_cmd->data = data;
  106. qdf_spin_lock_bh(&soc->rx.reo_cmd_lock);
  107. TAILQ_INSERT_TAIL(&soc->rx.reo_cmd_list, reo_cmd,
  108. reo_cmd_list_elem);
  109. qdf_spin_unlock_bh(&soc->rx.reo_cmd_lock);
  110. }
  111. return QDF_STATUS_SUCCESS;
  112. }
  113. uint32_t dp_reo_status_ring_handler(struct dp_intr *int_ctx, struct dp_soc *soc)
  114. {
  115. uint32_t *reo_desc;
  116. struct dp_reo_cmd_info *reo_cmd = NULL;
  117. union hal_reo_status reo_status;
  118. int num;
  119. int processed_count = 0;
  120. if (dp_srng_access_start(int_ctx, soc, soc->reo_status_ring.hal_srng)) {
  121. return processed_count;
  122. }
  123. reo_desc = hal_srng_dst_get_next(soc->hal_soc,
  124. soc->reo_status_ring.hal_srng);
  125. while (reo_desc) {
  126. uint16_t tlv = HAL_GET_TLV(reo_desc);
  127. processed_count++;
  128. switch (tlv) {
  129. case HAL_REO_QUEUE_STATS_STATUS_TLV:
  130. hal_reo_queue_stats_status(reo_desc,
  131. &reo_status.queue_status,
  132. soc->hal_soc);
  133. num = reo_status.queue_status.header.cmd_num;
  134. break;
  135. case HAL_REO_FLUSH_QUEUE_STATUS_TLV:
  136. hal_reo_flush_queue_status(reo_desc,
  137. &reo_status.fl_queue_status,
  138. soc->hal_soc);
  139. num = reo_status.fl_queue_status.header.cmd_num;
  140. break;
  141. case HAL_REO_FLUSH_CACHE_STATUS_TLV:
  142. hal_reo_flush_cache_status(reo_desc,
  143. &reo_status.fl_cache_status,
  144. soc->hal_soc);
  145. num = reo_status.fl_cache_status.header.cmd_num;
  146. break;
  147. case HAL_REO_UNBLK_CACHE_STATUS_TLV:
  148. hal_reo_unblock_cache_status(reo_desc, soc->hal_soc,
  149. &reo_status.unblk_cache_status);
  150. num = reo_status.unblk_cache_status.header.cmd_num;
  151. break;
  152. case HAL_REO_TIMOUT_LIST_STATUS_TLV:
  153. hal_reo_flush_timeout_list_status(reo_desc,
  154. &reo_status.fl_timeout_status,
  155. soc->hal_soc);
  156. num = reo_status.fl_timeout_status.header.cmd_num;
  157. break;
  158. case HAL_REO_DESC_THRES_STATUS_TLV:
  159. hal_reo_desc_thres_reached_status(reo_desc,
  160. &reo_status.thres_status,
  161. soc->hal_soc);
  162. num = reo_status.thres_status.header.cmd_num;
  163. break;
  164. case HAL_REO_UPDATE_RX_QUEUE_STATUS_TLV:
  165. hal_reo_rx_update_queue_status(reo_desc,
  166. &reo_status.rx_queue_status,
  167. soc->hal_soc);
  168. num = reo_status.rx_queue_status.header.cmd_num;
  169. break;
  170. default:
  171. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_WARN,
  172. "%s, no handler for TLV:%d", __func__, tlv);
  173. goto next;
  174. } /* switch */
  175. qdf_spin_lock_bh(&soc->rx.reo_cmd_lock);
  176. TAILQ_FOREACH(reo_cmd, &soc->rx.reo_cmd_list,
  177. reo_cmd_list_elem) {
  178. if (reo_cmd->cmd == num) {
  179. TAILQ_REMOVE(&soc->rx.reo_cmd_list, reo_cmd,
  180. reo_cmd_list_elem);
  181. break;
  182. }
  183. }
  184. qdf_spin_unlock_bh(&soc->rx.reo_cmd_lock);
  185. if (reo_cmd) {
  186. reo_cmd->handler(soc, reo_cmd->data,
  187. &reo_status);
  188. qdf_mem_free(reo_cmd);
  189. }
  190. next:
  191. reo_desc = hal_srng_dst_get_next(soc,
  192. soc->reo_status_ring.hal_srng);
  193. } /* while */
  194. dp_srng_access_end(int_ctx, soc, soc->reo_status_ring.hal_srng);
  195. return processed_count;
  196. }
  197. /**
  198. * dp_reo_cmdlist_destroy - Free REO commands in the queue
  199. * @soc: DP SoC hanle
  200. *
  201. */
  202. void dp_reo_cmdlist_destroy(struct dp_soc *soc)
  203. {
  204. struct dp_reo_cmd_info *reo_cmd = NULL;
  205. struct dp_reo_cmd_info *tmp_cmd = NULL;
  206. union hal_reo_status reo_status;
  207. reo_status.queue_status.header.status =
  208. HAL_REO_CMD_DRAIN;
  209. qdf_spin_lock_bh(&soc->rx.reo_cmd_lock);
  210. TAILQ_FOREACH_SAFE(reo_cmd, &soc->rx.reo_cmd_list,
  211. reo_cmd_list_elem, tmp_cmd) {
  212. TAILQ_REMOVE(&soc->rx.reo_cmd_list, reo_cmd,
  213. reo_cmd_list_elem);
  214. reo_cmd->handler(soc, reo_cmd->data, &reo_status);
  215. qdf_mem_free(reo_cmd);
  216. }
  217. qdf_spin_unlock_bh(&soc->rx.reo_cmd_lock);
  218. }