dp_wdi_event.c 8.1 KB

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