target_if_dfs.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /*
  2. * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
  3. *
  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. /**
  20. * DOC: target_if_dfs.c
  21. * This file contains dfs target interface
  22. */
  23. #include <target_if.h>
  24. #include <qdf_types.h>
  25. #include <qdf_status.h>
  26. #include <target_if_dfs.h>
  27. #include <wlan_module_ids.h>
  28. #include <wmi_unified_api.h>
  29. #include <wlan_lmac_if_def.h>
  30. #include <wmi_unified_priv.h>
  31. #include <wlan_scan_tgt_api.h>
  32. #include <wmi_unified_param.h>
  33. #include <wmi_unified_dfs_api.h>
  34. #include "wlan_dfs_tgt_api.h"
  35. #include "target_type.h"
  36. #include <init_deinit_lmac.h>
  37. #include <wlan_reg_ucfg_api.h>
  38. #include <target_if_dfs_full_offload.h>
  39. #include <target_if_dfs_partial_offload.h>
  40. /**
  41. * target_if_dfs_register_host_status_check_event() - Register host dfs
  42. * confirmation event.
  43. * @psoc: pointer to psoc.
  44. *
  45. * Return: QDF_STATUS.
  46. */
  47. #if defined(WLAN_DFS_PARTIAL_OFFLOAD) && defined(HOST_DFS_SPOOF_TEST)
  48. static QDF_STATUS target_if_dfs_register_host_status_check_event(
  49. struct wlan_objmgr_psoc *psoc)
  50. {
  51. wmi_unified_t wmi_handle;
  52. QDF_STATUS retval;
  53. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  54. if (!wmi_handle) {
  55. target_if_err("null wmi_handle");
  56. return QDF_STATUS_E_FAILURE;
  57. }
  58. retval = wmi_unified_register_event(wmi_handle,
  59. wmi_host_dfs_status_check_event_id,
  60. target_if_dfs_status_check_event_handler);
  61. if (QDF_IS_STATUS_ERROR(retval))
  62. target_if_err("wmi_dfs_radar_detection_event_id ret=%d",
  63. retval);
  64. return retval;
  65. }
  66. #else
  67. static QDF_STATUS target_if_dfs_register_host_status_check_event(
  68. struct wlan_objmgr_psoc *psoc)
  69. {
  70. return QDF_STATUS_SUCCESS;
  71. }
  72. #endif
  73. /**
  74. * target_if_is_dfs_3() - Is dfs3 support or not
  75. * @target_type: target type being used.
  76. *
  77. * Return: true if dfs3 is supported, false otherwise.
  78. */
  79. static bool target_if_is_dfs_3(uint32_t target_type)
  80. {
  81. bool is_dfs_3;
  82. switch (target_type) {
  83. case TARGET_TYPE_AR6320:
  84. is_dfs_3 = false;
  85. break;
  86. case TARGET_TYPE_ADRASTEA:
  87. is_dfs_3 = true;
  88. break;
  89. default:
  90. is_dfs_3 = true;
  91. }
  92. return is_dfs_3;
  93. }
  94. #ifdef MOBILE_DFS_SUPPORT
  95. /**
  96. * target_if_radar_event_handler() - handle radar event when
  97. * phyerr filter offload is enabled.
  98. * @scn: Handle to HIF context
  99. * @data: radar event buffer
  100. * @datalen: radar event buffer length
  101. *
  102. * Return: 0 on success; error code otherwise
  103. */
  104. static int target_if_radar_event_handler(
  105. ol_scn_t scn, uint8_t *data, uint32_t datalen)
  106. {
  107. struct radar_event_info wlan_radar_event;
  108. struct wlan_objmgr_psoc *psoc;
  109. struct wlan_objmgr_pdev *pdev;
  110. struct wlan_lmac_if_dfs_rx_ops *dfs_rx_ops;
  111. struct wmi_unified *wmi_handle;
  112. if (!scn || !data) {
  113. target_if_err("scn: %pK, data: %pK", scn, data);
  114. return -EINVAL;
  115. }
  116. psoc = target_if_get_psoc_from_scn_hdl(scn);
  117. if (!psoc) {
  118. target_if_err("null psoc");
  119. return -EINVAL;
  120. }
  121. dfs_rx_ops = target_if_dfs_get_rx_ops(psoc);
  122. if (!dfs_rx_ops || !dfs_rx_ops->dfs_process_phyerr_filter_offload) {
  123. target_if_err("Invalid dfs_rx_ops: %pK", dfs_rx_ops);
  124. return -EINVAL;
  125. }
  126. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  127. if (!wmi_handle) {
  128. target_if_err("Invalid WMI context");
  129. return -EINVAL;
  130. }
  131. if (QDF_IS_STATUS_ERROR(wmi_extract_wlan_radar_event_info(
  132. wmi_handle, data,
  133. &wlan_radar_event, datalen))) {
  134. target_if_err("failed to extract wlan radar event");
  135. return -EFAULT;
  136. }
  137. pdev = wlan_objmgr_get_pdev_by_id(psoc, wlan_radar_event.pdev_id,
  138. WLAN_DFS_ID);
  139. if (!pdev) {
  140. target_if_err("null pdev");
  141. return -EINVAL;
  142. }
  143. dfs_rx_ops->dfs_process_phyerr_filter_offload(pdev,
  144. &wlan_radar_event);
  145. wlan_objmgr_pdev_release_ref(pdev, WLAN_DFS_ID);
  146. return 0;
  147. }
  148. /**
  149. * target_if_reg_phyerr_events() - register dfs phyerr radar event.
  150. * @psoc: pointer to psoc.
  151. * @pdev: pointer to pdev.
  152. *
  153. * Return: QDF_STATUS.
  154. */
  155. static QDF_STATUS target_if_reg_phyerr_events_dfs2(
  156. struct wlan_objmgr_psoc *psoc)
  157. {
  158. QDF_STATUS ret;
  159. wmi_unified_t wmi_handle;
  160. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  161. if (!wmi_handle) {
  162. target_if_err("null wmi_handle");
  163. return QDF_STATUS_E_INVAL;
  164. }
  165. ret = wmi_unified_register_event(wmi_handle,
  166. wmi_dfs_radar_event_id,
  167. target_if_radar_event_handler);
  168. if (QDF_IS_STATUS_ERROR(ret)) {
  169. target_if_err("failed to register wmi_dfs_radar_event_id");
  170. return QDF_STATUS_E_FAILURE;
  171. }
  172. return QDF_STATUS_SUCCESS;
  173. }
  174. #else
  175. static QDF_STATUS target_if_reg_phyerr_events_dfs2(
  176. struct wlan_objmgr_psoc *psoc)
  177. {
  178. return QDF_STATUS_SUCCESS;
  179. }
  180. #endif
  181. static bool target_if_dfs_offload(struct wlan_objmgr_psoc *psoc)
  182. {
  183. wmi_unified_t wmi_handle;
  184. wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
  185. if (!wmi_handle) {
  186. target_if_err("null wmi_handle");
  187. return false;
  188. }
  189. return wmi_service_enabled(wmi_handle,
  190. wmi_service_dfs_phyerr_offload);
  191. }
  192. static QDF_STATUS target_if_dfs_get_target_type(struct wlan_objmgr_pdev *pdev,
  193. uint32_t *target_type)
  194. {
  195. struct wlan_objmgr_psoc *psoc;
  196. struct target_psoc_info *tgt_psoc_info;
  197. psoc = wlan_pdev_get_psoc(pdev);
  198. if (!psoc) {
  199. target_if_err("null psoc");
  200. return QDF_STATUS_E_FAILURE;
  201. }
  202. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  203. if (!tgt_psoc_info) {
  204. target_if_err("null tgt_psoc_info");
  205. return QDF_STATUS_E_FAILURE;
  206. }
  207. *target_type = target_psoc_get_target_type(tgt_psoc_info);
  208. return QDF_STATUS_SUCCESS;
  209. }
  210. static QDF_STATUS target_if_dfs_register_event_handler(
  211. struct wlan_objmgr_psoc *psoc)
  212. {
  213. struct target_psoc_info *tgt_psoc_info;
  214. if (!psoc) {
  215. target_if_err("null psoc");
  216. return QDF_STATUS_E_FAILURE;
  217. }
  218. if (!target_if_dfs_offload(psoc)) {
  219. tgt_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
  220. if (!tgt_psoc_info) {
  221. target_if_err("null tgt_psoc_info");
  222. return QDF_STATUS_E_FAILURE;
  223. }
  224. target_if_dfs_register_host_status_check_event(psoc);
  225. if (target_if_is_dfs_3(
  226. target_psoc_get_target_type(tgt_psoc_info)))
  227. return target_if_dfs_reg_phyerr_events(psoc);
  228. else
  229. return target_if_reg_phyerr_events_dfs2(psoc);
  230. } else {
  231. return target_if_dfs_reg_offload_events(psoc);
  232. }
  233. }
  234. static QDF_STATUS target_if_dfs_is_pdev_5ghz(struct wlan_objmgr_pdev *pdev,
  235. bool *is_5ghz)
  236. {
  237. struct wlan_objmgr_psoc *psoc;
  238. uint8_t pdev_id;
  239. struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap_ptr;
  240. psoc = wlan_pdev_get_psoc(pdev);
  241. if (!psoc) {
  242. target_if_err("dfs: null psoc");
  243. return QDF_STATUS_E_FAILURE;
  244. }
  245. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  246. reg_cap_ptr = ucfg_reg_get_hal_reg_cap(psoc);
  247. if (!reg_cap_ptr) {
  248. target_if_err("dfs: reg cap null");
  249. return QDF_STATUS_E_FAILURE;
  250. }
  251. if (reg_cap_ptr[pdev_id].wireless_modes &
  252. WMI_HOST_REGDMN_MODE_11A)
  253. *is_5ghz = true;
  254. else
  255. *is_5ghz = false;
  256. return QDF_STATUS_SUCCESS;
  257. }
  258. #ifdef MOBILE_DFS_SUPPORT
  259. /**
  260. * target_if_dfs_set_phyerr_filter_offload() - config phyerr filter offload.
  261. * @pdev: Pointer to DFS pdev object.
  262. * @dfs_phyerr_filter_offload: Phyerr filter offload value.
  263. *
  264. * Return: QDF_STATUS
  265. */
  266. static QDF_STATUS target_if_dfs_set_phyerr_filter_offload(
  267. struct wlan_objmgr_pdev *pdev,
  268. bool dfs_phyerr_filter_offload)
  269. {
  270. QDF_STATUS status;
  271. wmi_unified_t wmi_handle;
  272. if (!pdev) {
  273. target_if_err("null pdev");
  274. return QDF_STATUS_E_FAILURE;
  275. }
  276. wmi_handle = GET_WMI_HDL_FROM_PDEV(pdev);
  277. if (!wmi_handle) {
  278. target_if_err("null wmi_handle");
  279. return QDF_STATUS_E_FAILURE;
  280. }
  281. status = wmi_unified_dfs_phyerr_filter_offload_en_cmd(wmi_handle,
  282. dfs_phyerr_filter_offload);
  283. if (QDF_IS_STATUS_ERROR(status))
  284. target_if_err("phyerr filter offload %d set fail: %d",
  285. dfs_phyerr_filter_offload, status);
  286. return status;
  287. }
  288. #else
  289. static QDF_STATUS target_if_dfs_set_phyerr_filter_offload(
  290. struct wlan_objmgr_pdev *pdev,
  291. bool dfs_phyerr_filter_offload)
  292. {
  293. return QDF_STATUS_SUCCESS;
  294. }
  295. #endif
  296. static QDF_STATUS target_send_dfs_offload_enable_cmd(
  297. struct wlan_objmgr_pdev *pdev, bool enable)
  298. {
  299. QDF_STATUS status = QDF_STATUS_SUCCESS;
  300. uint8_t pdev_id;
  301. void *wmi_hdl;
  302. if (!pdev) {
  303. target_if_err("null pdev");
  304. return QDF_STATUS_E_FAILURE;
  305. }
  306. wmi_hdl = GET_WMI_HDL_FROM_PDEV(pdev);
  307. if (!wmi_hdl) {
  308. target_if_err("null wmi_hdl");
  309. return QDF_STATUS_E_FAILURE;
  310. }
  311. pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
  312. if (enable)
  313. status = wmi_unified_dfs_phyerr_offload_en_cmd(wmi_hdl,
  314. pdev_id);
  315. else
  316. status = wmi_unified_dfs_phyerr_offload_dis_cmd(wmi_hdl,
  317. pdev_id);
  318. if (QDF_IS_STATUS_ERROR(status))
  319. target_if_err("dfs: dfs offload cmd failed, enable:%d, pdev:%d",
  320. enable, pdev_id);
  321. else
  322. target_if_debug("dfs: sent dfs offload cmd, enable:%d, pdev:%d",
  323. enable, pdev_id);
  324. return status;
  325. }
  326. QDF_STATUS target_if_register_dfs_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
  327. {
  328. struct wlan_lmac_if_dfs_tx_ops *dfs_tx_ops;
  329. if (!tx_ops) {
  330. target_if_err("invalid tx_ops");
  331. return QDF_STATUS_E_FAILURE;
  332. }
  333. dfs_tx_ops = &tx_ops->dfs_tx_ops;
  334. dfs_tx_ops->dfs_reg_ev_handler = &target_if_dfs_register_event_handler;
  335. dfs_tx_ops->dfs_process_emulate_bang_radar_cmd =
  336. &target_process_bang_radar_cmd;
  337. dfs_tx_ops->dfs_agile_ch_cfg_cmd =
  338. &target_send_agile_ch_cfg_cmd;
  339. dfs_tx_ops->dfs_ocac_abort_cmd =
  340. &target_send_ocac_abort_cmd;
  341. dfs_tx_ops->dfs_is_pdev_5ghz = &target_if_dfs_is_pdev_5ghz;
  342. dfs_tx_ops->dfs_send_offload_enable_cmd =
  343. &target_send_dfs_offload_enable_cmd;
  344. dfs_tx_ops->dfs_set_phyerr_filter_offload =
  345. &target_if_dfs_set_phyerr_filter_offload;
  346. dfs_tx_ops->dfs_get_caps = &target_if_dfs_get_caps;
  347. dfs_tx_ops->dfs_send_avg_radar_params_to_fw =
  348. &target_if_dfs_send_avg_params_to_fw;
  349. dfs_tx_ops->dfs_is_tgt_offload = &target_if_dfs_offload;
  350. dfs_tx_ops->dfs_send_usenol_pdev_param =
  351. &target_send_usenol_pdev_param;
  352. dfs_tx_ops->dfs_send_subchan_marking_pdev_param =
  353. &target_send_subchan_marking_pdev_param;
  354. dfs_tx_ops->dfs_get_target_type = &target_if_dfs_get_target_type;
  355. return QDF_STATUS_SUCCESS;
  356. }