dp_wdi_event.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include "dp_internal.h"
  20. #include "qdf_mem.h" /* qdf_mem_malloc,free */
  21. #ifdef WIFI_MONITOR_SUPPORT
  22. #include "dp_htt.h"
  23. #include <dp_mon.h>
  24. #endif
  25. #include <qdf_module.h>
  26. #ifdef WDI_EVENT_ENABLE
  27. /*
  28. * dp_wdi_event_next_sub() - Return handle for Next WDI event
  29. * @wdi_sub: WDI Event handle
  30. *
  31. * Return handle for next WDI event in list
  32. *
  33. * Return: Next WDI event to be subscribe
  34. */
  35. static inline wdi_event_subscribe *
  36. dp_wdi_event_next_sub(wdi_event_subscribe *wdi_sub)
  37. {
  38. if (!wdi_sub) {
  39. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  40. "Invalid subscriber in %s", __func__);
  41. return NULL;
  42. }
  43. return wdi_sub->priv.next;
  44. }
  45. /*
  46. * dp_wdi_event_del_subs() -Delete Event subscription
  47. * @wdi_sub: WDI Event handle
  48. * @event_index: Event index from list
  49. *
  50. * This API will delete subscribed event from list
  51. * Return: None
  52. */
  53. static inline void
  54. dp_wdi_event_del_subs(wdi_event_subscribe *wdi_sub, int event_index)
  55. {
  56. /* Subscribers should take care of deletion */
  57. }
  58. /*
  59. * dp_wdi_event_iter_sub() - Iterate through all WDI event in the list
  60. * and pass WDI event to callback function
  61. * @pdev: DP pdev handle
  62. * @event_index: Event index in list
  63. * @wdi_event: WDI event handle
  64. * @data: pointer to data
  65. * @peer_id: peer id number
  66. * @status: HTT rx status
  67. *
  68. *
  69. * Return: None
  70. */
  71. static inline void
  72. dp_wdi_event_iter_sub(
  73. struct dp_pdev *pdev,
  74. uint32_t event_index,
  75. wdi_event_subscribe *wdi_sub,
  76. void *data,
  77. uint16_t peer_id,
  78. int status)
  79. {
  80. enum WDI_EVENT event = event_index + WDI_EVENT_BASE;
  81. if (wdi_sub) {
  82. do {
  83. wdi_sub->callback(wdi_sub->context, event, data,
  84. peer_id, status);
  85. } while ((wdi_sub = dp_wdi_event_next_sub(wdi_sub)));
  86. }
  87. }
  88. /*
  89. * dp_wdi_event_handler() - Event handler for WDI event
  90. * @event: wdi event number
  91. * @soc: soc handle
  92. * @data: pointer to data
  93. * @peer_id: peer id number
  94. * @status: HTT rx status
  95. * @pdev_id: id of pdev
  96. *
  97. * It will be called to register WDI event
  98. *
  99. * Return: None
  100. */
  101. void
  102. dp_wdi_event_handler(
  103. enum WDI_EVENT event,
  104. struct dp_soc *soc,
  105. void *data,
  106. uint16_t peer_id,
  107. int status, uint8_t pdev_id)
  108. {
  109. uint32_t event_index;
  110. wdi_event_subscribe *wdi_sub;
  111. struct dp_pdev *txrx_pdev;
  112. struct dp_soc *soc_t = (struct dp_soc *)soc;
  113. txrx_pdev = dp_get_pdev_for_mac_id(soc_t, pdev_id);
  114. if (!event) {
  115. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  116. "Invalid WDI event in %s", __func__);
  117. return;
  118. }
  119. if (!txrx_pdev || txrx_pdev->pdev_deinit) {
  120. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  121. "Invalid pdev in WDI event handler");
  122. return;
  123. }
  124. /*
  125. * There can be NULL data, so no validation for the data
  126. * Subscribers must do the sanity based on the requirements
  127. */
  128. event_index = event - WDI_EVENT_BASE;
  129. DP_STATS_INC(txrx_pdev, wdi_event[event_index], 1);
  130. wdi_sub = txrx_pdev->wdi_event_list[event_index];
  131. /* Find the subscriber */
  132. dp_wdi_event_iter_sub(txrx_pdev, event_index, wdi_sub, data,
  133. peer_id, status);
  134. }
  135. qdf_export_symbol(dp_wdi_event_handler);
  136. /*
  137. * dp_wdi_event_sub() - Subscribe WDI event
  138. * @soc: soc handle
  139. * @pdev_id: id of pdev
  140. * @event_cb_sub_handle: subscribe event handle
  141. * @event: Event to be subscribe
  142. *
  143. * Return: 0 for success. nonzero for failure.
  144. */
  145. int
  146. dp_wdi_event_sub(
  147. struct cdp_soc_t *soc, uint8_t pdev_id,
  148. wdi_event_subscribe *event_cb_sub_handle,
  149. uint32_t event)
  150. {
  151. uint32_t event_index;
  152. wdi_event_subscribe *wdi_sub;
  153. wdi_event_subscribe *wdi_sub_itr;
  154. struct dp_pdev *txrx_pdev =
  155. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  156. pdev_id);
  157. wdi_event_subscribe *event_cb_sub =
  158. (wdi_event_subscribe *) event_cb_sub_handle;
  159. if (!txrx_pdev) {
  160. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  161. "Invalid txrx_pdev in %s", __func__);
  162. return -EINVAL;
  163. }
  164. if (!event_cb_sub) {
  165. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  166. "Invalid callback in %s", __func__);
  167. return -EINVAL;
  168. }
  169. if ((!event) || (event >= WDI_EVENT_LAST) || (event < WDI_EVENT_BASE)) {
  170. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  171. "Invalid event in %s", __func__);
  172. return -EINVAL;
  173. }
  174. dp_monitor_set_pktlog_wifi3(txrx_pdev, event, true);
  175. event_index = event - WDI_EVENT_BASE;
  176. wdi_sub = txrx_pdev->wdi_event_list[event_index];
  177. /*
  178. * Check if it is the first subscriber of the event
  179. */
  180. if (!wdi_sub) {
  181. wdi_sub = event_cb_sub;
  182. wdi_sub->priv.next = NULL;
  183. wdi_sub->priv.prev = NULL;
  184. txrx_pdev->wdi_event_list[event_index] = wdi_sub;
  185. return 0;
  186. }
  187. /* Check if event is already subscribed */
  188. wdi_sub_itr = wdi_sub;
  189. do {
  190. if (wdi_sub_itr == event_cb_sub) {
  191. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  192. "Duplicate wdi subscribe event detected %s", __func__);
  193. return 0;
  194. }
  195. } while ((wdi_sub_itr = dp_wdi_event_next_sub(wdi_sub_itr)));
  196. event_cb_sub->priv.next = wdi_sub;
  197. event_cb_sub->priv.prev = NULL;
  198. wdi_sub->priv.prev = event_cb_sub;
  199. txrx_pdev->wdi_event_list[event_index] = event_cb_sub;
  200. return 0;
  201. }
  202. /*
  203. * dp_wdi_event_unsub() - WDI event unsubscribe
  204. * @soc: soc handle
  205. * @pdev_id: id of pdev
  206. * @event_cb_sub_handle: subscribed event handle
  207. * @event: Event to be unsubscribe
  208. *
  209. *
  210. * Return: 0 for success. nonzero for failure.
  211. */
  212. int
  213. dp_wdi_event_unsub(
  214. struct cdp_soc_t *soc, uint8_t pdev_id,
  215. wdi_event_subscribe *event_cb_sub_handle,
  216. uint32_t event)
  217. {
  218. uint32_t event_index = event - WDI_EVENT_BASE;
  219. struct dp_pdev *txrx_pdev =
  220. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  221. pdev_id);
  222. wdi_event_subscribe *event_cb_sub =
  223. (wdi_event_subscribe *) event_cb_sub_handle;
  224. if (!txrx_pdev || !event_cb_sub) {
  225. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  226. "Invalid callback or pdev in %s", __func__);
  227. return -EINVAL;
  228. }
  229. dp_monitor_set_pktlog_wifi3(txrx_pdev, event, false);
  230. if (!event_cb_sub->priv.prev) {
  231. txrx_pdev->wdi_event_list[event_index] = event_cb_sub->priv.next;
  232. } else {
  233. event_cb_sub->priv.prev->priv.next = event_cb_sub->priv.next;
  234. }
  235. if (event_cb_sub->priv.next) {
  236. event_cb_sub->priv.next->priv.prev = event_cb_sub->priv.prev;
  237. }
  238. /* Reset susbscribe event list elems */
  239. event_cb_sub->priv.next = NULL;
  240. event_cb_sub->priv.prev = NULL;
  241. return 0;
  242. }
  243. /*
  244. * dp_wdi_event_attach() - Attach wdi event
  245. * @txrx_pdev: DP pdev handle
  246. *
  247. * Return: 0 for success. nonzero for failure.
  248. */
  249. int
  250. dp_wdi_event_attach(struct dp_pdev *txrx_pdev)
  251. {
  252. if (!txrx_pdev) {
  253. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  254. "Invalid device in %s\nWDI event attach failed",
  255. __func__);
  256. return -EINVAL;
  257. }
  258. /* Separate subscriber list for each event */
  259. txrx_pdev->wdi_event_list = (wdi_event_subscribe **)
  260. qdf_mem_malloc(
  261. sizeof(wdi_event_subscribe *) * WDI_NUM_EVENTS);
  262. if (!txrx_pdev->wdi_event_list) {
  263. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  264. "Insufficient memory for the WDI event lists");
  265. return -EINVAL;
  266. }
  267. return 0;
  268. }
  269. /*
  270. * dp_wdi_event_detach() - Detach WDI event
  271. * @txrx_pdev: DP pdev handle
  272. *
  273. * Return: 0 for success. nonzero for failure.
  274. */
  275. int
  276. dp_wdi_event_detach(struct dp_pdev *txrx_pdev)
  277. {
  278. int i;
  279. wdi_event_subscribe *wdi_sub;
  280. if (!txrx_pdev) {
  281. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  282. "Invalid device in %s\nWDI attach failed", __func__);
  283. return -EINVAL;
  284. }
  285. if (!txrx_pdev->wdi_event_list) {
  286. return -EINVAL;
  287. }
  288. for (i = 0; i < WDI_NUM_EVENTS; i++) {
  289. wdi_sub = txrx_pdev->wdi_event_list[i];
  290. /* Delete all the subscribers */
  291. dp_wdi_event_del_subs(wdi_sub, i);
  292. }
  293. qdf_mem_free(txrx_pdev->wdi_event_list);
  294. return 0;
  295. }
  296. #endif /* CONFIG_WIN */