target_if_dcs.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /**
  17. * DOC: target_if_dcs.c
  18. *
  19. * This file provide definition for APIs registered through lmac Tx Ops
  20. */
  21. #include <wmi_unified_api.h>
  22. #include <wmi_unified_priv.h>
  23. #include <wmi_unified_dcs_api.h>
  24. #include <init_deinit_lmac.h>
  25. #include "wlan_dcs_tgt_api.h"
  26. #include "target_if_dcs.h"
  27. /**
  28. * target_if_dcs_interference_event_handler() - function to handle dcs event
  29. * from firmware.
  30. * @scn: scn handle
  31. * @data: data buffer for event
  32. * @datalen: data length
  33. *
  34. * Return: status of operation.
  35. */
  36. static int target_if_dcs_interference_event_handler(ol_scn_t scn,
  37. uint8_t *data,
  38. uint32_t datalen)
  39. {
  40. QDF_STATUS status;
  41. struct dcs_stats_event ev;
  42. struct wlan_objmgr_psoc *psoc;
  43. struct wmi_unified *wmi_handle;
  44. struct wlan_target_if_dcs_rx_ops *rx_ops;
  45. if (!scn || !data) {
  46. target_if_err("scn: 0x%pK, data: 0x%pK", scn, data);
  47. return -EINVAL;
  48. }
  49. psoc = target_if_get_psoc_from_scn_hdl(scn);
  50. if (!psoc) {
  51. target_if_err("null psoc");
  52. return -EINVAL;
  53. }
  54. rx_ops = target_if_dcs_get_rx_ops(psoc);
  55. if (!rx_ops || !rx_ops->process_dcs_event) {
  56. target_if_err("callback not registered");
  57. return -EINVAL;
  58. }
  59. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  60. if (!wmi_handle) {
  61. target_if_err("wmi_handle is null");
  62. return -EINVAL;
  63. }
  64. if (wmi_extract_dcs_interference_type(wmi_handle, data,
  65. &ev.dcs_param) !=
  66. QDF_STATUS_SUCCESS) {
  67. target_if_err("Unable to extract dcs interference type");
  68. return -EINVAL;
  69. }
  70. if (wmi_extract_dcs_im_tgt_stats(wmi_handle, data, &ev.wlan_stat) !=
  71. QDF_STATUS_SUCCESS) {
  72. target_if_err("Unable to extract WLAN IM stats");
  73. return -EINVAL;
  74. }
  75. status = rx_ops->process_dcs_event(psoc, &ev);
  76. return qdf_status_to_os_return(status);
  77. }
  78. static QDF_STATUS
  79. target_if_dcs_register_event_handler(struct wlan_objmgr_psoc *psoc)
  80. {
  81. int ret_val;
  82. struct wmi_unified *wmi_handle;
  83. if (!psoc) {
  84. target_if_err("PSOC is NULL!");
  85. return QDF_STATUS_E_NULL_VALUE;
  86. }
  87. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  88. if (!wmi_handle) {
  89. target_if_err("wmi_handle is null");
  90. return QDF_STATUS_E_INVAL;
  91. }
  92. ret_val = wmi_unified_register_event_handler(
  93. wmi_handle,
  94. wmi_dcs_interference_event_id,
  95. target_if_dcs_interference_event_handler,
  96. WMI_RX_WORK_CTX);
  97. if (ret_val)
  98. target_if_err("Failed to register dcs interference event cb");
  99. return qdf_status_from_os_return(ret_val);
  100. }
  101. static QDF_STATUS
  102. target_if_dcs_unregister_event_handler(struct wlan_objmgr_psoc *psoc)
  103. {
  104. struct wmi_unified *wmi_handle;
  105. if (!psoc) {
  106. target_if_err("PSOC is NULL!");
  107. return QDF_STATUS_E_INVAL;
  108. }
  109. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  110. if (!wmi_handle) {
  111. target_if_err("wmi_handle is null");
  112. return QDF_STATUS_E_INVAL;
  113. }
  114. wmi_unified_unregister_event_handler(wmi_handle,
  115. wmi_dcs_interference_event_id);
  116. return QDF_STATUS_SUCCESS;
  117. }
  118. /**
  119. * target_if_dcs_cmd_send() - Send WMI command for dcs requests
  120. * @psoc: psoc pointer
  121. * @pdev_id: pdev_id
  122. * @is_target_pdev_id: pdev_id is target pdev_id or not
  123. * @dcs_enable: dcs enable or not
  124. *
  125. * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_** on error
  126. */
  127. static QDF_STATUS
  128. target_if_dcs_cmd_send(struct wlan_objmgr_psoc *psoc, uint32_t pdev_id,
  129. bool is_target_pdev_id, uint32_t dcs_enable)
  130. {
  131. QDF_STATUS ret;
  132. struct wmi_unified *wmi_handle;
  133. if (!psoc) {
  134. target_if_err("null psoc");
  135. return QDF_STATUS_E_FAILURE;
  136. }
  137. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  138. if (!wmi_handle) {
  139. target_if_err("null handle");
  140. return QDF_STATUS_E_FAILURE;
  141. }
  142. ret = wmi_send_dcs_pdev_param(wmi_handle, pdev_id,
  143. is_target_pdev_id, dcs_enable);
  144. if (QDF_IS_STATUS_ERROR(ret))
  145. target_if_err("wmi dcs cmd send failed, ret: %d", ret);
  146. return ret;
  147. }
  148. QDF_STATUS
  149. target_if_dcs_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  150. {
  151. struct wlan_target_if_dcs_tx_ops *dcs_tx_ops;
  152. if (!tx_ops) {
  153. target_if_err("lmac tx ops is NULL!");
  154. return QDF_STATUS_E_INVAL;
  155. }
  156. dcs_tx_ops = &tx_ops->dcs_tx_ops;
  157. if (!dcs_tx_ops) {
  158. target_if_err("lmac tx ops is NULL!");
  159. return QDF_STATUS_E_FAILURE;
  160. }
  161. dcs_tx_ops->dcs_attach =
  162. target_if_dcs_register_event_handler;
  163. dcs_tx_ops->dcs_detach =
  164. target_if_dcs_unregister_event_handler;
  165. dcs_tx_ops->dcs_cmd_send = target_if_dcs_cmd_send;
  166. return QDF_STATUS_SUCCESS;
  167. }