xref: /wlan-dirver/qca-wifi-host-cmn/target_if/wifi_pos/src/target_if_wifi_pos_rx_ops.c (revision 87ce989ee0b2172d08cfc0e040cdb9ca3fcce1e8)
1 /*
2  * Copyright (c) 2013-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-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 
20 /**
21  * DOC: target_if_wifi_pos_rx_ops.c
22  * This file defines the functions pertinent to wifi positioning component's
23  * target if layer.
24  */
25 #include "wifi_pos_utils_pub.h"
26 
27 #include "wmi_unified_api.h"
28 #include "wlan_lmac_if_def.h"
29 #include "target_if_wifi_pos.h"
30 #include "target_if_wifi_pos_rx_ops.h"
31 #include "wifi_pos_utils_i.h"
32 #include "target_if.h"
33 
34 static inline struct wlan_lmac_if_wifi_pos_rx_ops *
35 target_if_wifi_pos_get_rxops(struct wlan_objmgr_psoc *psoc)
36 {
37 	struct wlan_lmac_if_rx_ops *rx_ops;
38 
39 	if (!psoc) {
40 		target_if_err("passed psoc is NULL");
41 		return NULL;
42 	}
43 
44 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
45 	if (!rx_ops) {
46 		target_if_err("rx_ops is NULL");
47 		return NULL;
48 	}
49 
50 	return &rx_ops->wifi_pos_rx_ops;
51 }
52 
53 int target_if_wifi_pos_oem_rsp_ev_handler(ol_scn_t scn,
54 					  uint8_t *data_buf,
55 					  uint32_t data_len)
56 {
57 	int ret;
58 	uint8_t ring_idx = 0;
59 	QDF_STATUS status;
60 	uint32_t cookie = 0;
61 	struct wmi_host_oem_indirect_data *indirect;
62 	struct oem_data_rsp oem_rsp = {0};
63 	struct wifi_pos_psoc_priv_obj *priv_obj;
64 	struct wlan_objmgr_psoc *psoc;
65 	struct wlan_lmac_if_wifi_pos_rx_ops *wifi_pos_rx_ops;
66 	struct wmi_oem_response_param oem_resp_param = {0};
67 	wmi_unified_t wmi_handle;
68 
69 	psoc = target_if_get_psoc_from_scn_hdl(scn);
70 	if (!psoc) {
71 		target_if_err("psoc is null");
72 		return QDF_STATUS_NOT_INITIALIZED;
73 	}
74 
75 	wlan_objmgr_psoc_get_ref(psoc, WLAN_WIFI_POS_TGT_IF_ID);
76 
77 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
78 	if (!wmi_handle) {
79 		target_if_err("wmi_handle is null");
80 		wlan_objmgr_psoc_release_ref(psoc, WLAN_WIFI_POS_TGT_IF_ID);
81 		return QDF_STATUS_NOT_INITIALIZED;
82 	}
83 
84 	priv_obj = wifi_pos_get_psoc_priv_obj(wifi_pos_get_psoc());
85 	if (!priv_obj) {
86 		target_if_err("priv_obj is null");
87 		wlan_objmgr_psoc_release_ref(psoc, WLAN_WIFI_POS_TGT_IF_ID);
88 		return QDF_STATUS_NOT_INITIALIZED;
89 	}
90 
91 	wifi_pos_rx_ops = target_if_wifi_pos_get_rxops(psoc);
92 	if (!wifi_pos_rx_ops || !wifi_pos_rx_ops->oem_rsp_event_rx) {
93 		wlan_objmgr_psoc_release_ref(psoc, WLAN_WIFI_POS_TGT_IF_ID);
94 		target_if_err("lmac callbacks not registered");
95 		return QDF_STATUS_NOT_INITIALIZED;
96 	}
97 
98 	ret = wmi_extract_oem_response_param(wmi_handle,
99 					     data_buf,
100 					     &oem_resp_param);
101 
102 	oem_rsp.rsp_len_1 = oem_resp_param.num_data1;
103 	oem_rsp.data_1    = oem_resp_param.data_1;
104 
105 	if (oem_resp_param.num_data2) {
106 		oem_rsp.rsp_len_2 = oem_resp_param.num_data2;
107 		oem_rsp.data_2    = oem_resp_param.data_2;
108 	}
109 
110 	indirect = &oem_resp_param.indirect_data;
111 	status = target_if_wifi_pos_get_indirect_data(priv_obj, indirect,
112 						      &oem_rsp, &cookie);
113 	if (QDF_IS_STATUS_ERROR(status)) {
114 		target_if_err("get indirect data failed status: %d", status);
115 		wlan_objmgr_psoc_release_ref(psoc, WLAN_WIFI_POS_TGT_IF_ID);
116 		return QDF_STATUS_E_INVAL;
117 	}
118 
119 	ret = wifi_pos_rx_ops->oem_rsp_event_rx(psoc, &oem_rsp);
120 	if (indirect)
121 		ring_idx = indirect->pdev_id - 1;
122 	status = target_if_wifi_pos_replenish_ring(priv_obj, ring_idx,
123 						   oem_rsp.vaddr, cookie);
124 	if (QDF_IS_STATUS_ERROR(status)) {
125 		target_if_err("replenish failed status: %d", status);
126 		ret = QDF_STATUS_E_FAILURE;
127 	}
128 
129 	wlan_objmgr_psoc_release_ref(psoc, WLAN_WIFI_POS_TGT_IF_ID);
130 
131 	return ret;
132 }
133 
134 int wifi_pos_oem_cap_ev_handler(ol_scn_t scn, uint8_t *buf, uint32_t len)
135 {
136 	/* TBD */
137 	return 0;
138 }
139 
140 int wifi_pos_oem_meas_rpt_ev_handler(ol_scn_t scn, uint8_t *buf,
141 				     uint32_t len)
142 {
143 	/* TBD */
144 	return 0;
145 }
146 
147 int wifi_pos_oem_err_rpt_ev_handler(ol_scn_t scn, uint8_t *buf,
148 				    uint32_t len)
149 {
150 	/* TBD */
151 	return 0;
152 }
153