dp_wdi_event.c 8.2 KB

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