xref: /wlan-driver/qcacld-3.0/components/target_if/ocb/src/target_if_ocb.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2018, 2020 The Linux Foundation. All rights reserved.
3*5113495bSYour Name  *
4*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for
5*5113495bSYour Name  * any purpose with or without fee is hereby granted, provided that the
6*5113495bSYour Name  * above copyright notice and this permission notice appear in all
7*5113495bSYour Name  * copies.
8*5113495bSYour Name  *
9*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10*5113495bSYour Name  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11*5113495bSYour Name  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12*5113495bSYour Name  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13*5113495bSYour Name  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14*5113495bSYour Name  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15*5113495bSYour Name  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16*5113495bSYour Name  * PERFORMANCE OF THIS SOFTWARE.
17*5113495bSYour Name  */
18*5113495bSYour Name 
19*5113495bSYour Name /**
20*5113495bSYour Name  * DOC: offload lmac interface APIs for ocb
21*5113495bSYour Name  *
22*5113495bSYour Name  */
23*5113495bSYour Name 
24*5113495bSYour Name #include <qdf_mem.h>
25*5113495bSYour Name #include <target_if.h>
26*5113495bSYour Name #include <qdf_status.h>
27*5113495bSYour Name #include <wmi_unified_api.h>
28*5113495bSYour Name #include <wmi_unified_priv.h>
29*5113495bSYour Name #include <wmi_unified_param.h>
30*5113495bSYour Name #include <wlan_objmgr_psoc_obj.h>
31*5113495bSYour Name #include <wlan_utility.h>
32*5113495bSYour Name #include <wlan_defs.h>
33*5113495bSYour Name #include <wlan_ocb_public_structs.h>
34*5113495bSYour Name #include <wlan_ocb_main.h>
35*5113495bSYour Name #include <target_if_ocb.h>
36*5113495bSYour Name 
37*5113495bSYour Name /**
38*5113495bSYour Name  * target_if_ocb_get_rx_ops() - get target interface RX operations
39*5113495bSYour Name  * @pdev: pdev handle
40*5113495bSYour Name  *
41*5113495bSYour Name  * Return: fp to target interface RX operations
42*5113495bSYour Name  */
43*5113495bSYour Name static inline struct wlan_ocb_rx_ops *
target_if_ocb_get_rx_ops(struct wlan_objmgr_pdev * pdev)44*5113495bSYour Name target_if_ocb_get_rx_ops(struct wlan_objmgr_pdev *pdev)
45*5113495bSYour Name {
46*5113495bSYour Name 	struct ocb_pdev_obj *ocb_obj;
47*5113495bSYour Name 
48*5113495bSYour Name 	ocb_obj = wlan_get_pdev_ocb_obj(pdev);
49*5113495bSYour Name 
50*5113495bSYour Name 	return &ocb_obj->ocb_rxops;
51*5113495bSYour Name }
52*5113495bSYour Name 
53*5113495bSYour Name /**
54*5113495bSYour Name  * target_if_ocb_set_config() - send the OCB config to the FW
55*5113495bSYour Name  * @psoc: pointer to PSOC object
56*5113495bSYour Name  * @config: OCB channel configuration
57*5113495bSYour Name  *
58*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS on success
59*5113495bSYour Name  */
target_if_ocb_set_config(struct wlan_objmgr_psoc * psoc,struct ocb_config * config)60*5113495bSYour Name static QDF_STATUS target_if_ocb_set_config(struct wlan_objmgr_psoc *psoc,
61*5113495bSYour Name 					   struct ocb_config *config)
62*5113495bSYour Name {
63*5113495bSYour Name 	QDF_STATUS status;
64*5113495bSYour Name 
65*5113495bSYour Name 	status = wmi_unified_ocb_set_config(get_wmi_unified_hdl_from_psoc(psoc),
66*5113495bSYour Name 					    config);
67*5113495bSYour Name 	if (status)
68*5113495bSYour Name 		target_if_err("Failed to set OCB config %d", status);
69*5113495bSYour Name 
70*5113495bSYour Name 	return status;
71*5113495bSYour Name }
72*5113495bSYour Name 
73*5113495bSYour Name /**
74*5113495bSYour Name  * target_if_ocb_set_utc_time() - send the UTC time to the firmware
75*5113495bSYour Name  * @psoc: pointer to PSOC object
76*5113495bSYour Name  * @utc: pointer to the UTC time structure
77*5113495bSYour Name  *
78*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS on success
79*5113495bSYour Name  */
target_if_ocb_set_utc_time(struct wlan_objmgr_psoc * psoc,struct ocb_utc_param * utc)80*5113495bSYour Name static QDF_STATUS target_if_ocb_set_utc_time(struct wlan_objmgr_psoc *psoc,
81*5113495bSYour Name 					     struct ocb_utc_param *utc)
82*5113495bSYour Name {
83*5113495bSYour Name 	QDF_STATUS status;
84*5113495bSYour Name 
85*5113495bSYour Name 	status = wmi_unified_ocb_set_utc_time_cmd(
86*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc), utc);
87*5113495bSYour Name 	if (status)
88*5113495bSYour Name 		target_if_err("Failed to set OCB UTC time %d", status);
89*5113495bSYour Name 
90*5113495bSYour Name 	return status;
91*5113495bSYour Name }
92*5113495bSYour Name 
93*5113495bSYour Name /**
94*5113495bSYour Name  * target_if_ocb_start_timing_advert() - start sending the timing
95*5113495bSYour Name  *  advertisement frame on a channel
96*5113495bSYour Name  * @psoc: pointer to PSOC object
97*5113495bSYour Name  * @ta: pointer to the timing advertisement
98*5113495bSYour Name  *
99*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS on success
100*5113495bSYour Name  */
101*5113495bSYour Name static QDF_STATUS
target_if_ocb_start_timing_advert(struct wlan_objmgr_psoc * psoc,struct ocb_timing_advert_param * ta)102*5113495bSYour Name target_if_ocb_start_timing_advert(struct wlan_objmgr_psoc *psoc,
103*5113495bSYour Name 				  struct ocb_timing_advert_param *ta)
104*5113495bSYour Name {
105*5113495bSYour Name 	QDF_STATUS status;
106*5113495bSYour Name 
107*5113495bSYour Name 	status = wmi_unified_ocb_start_timing_advert(
108*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc), ta);
109*5113495bSYour Name 	if (status)
110*5113495bSYour Name 		target_if_err("Failed to start OCB timing advert %d", status);
111*5113495bSYour Name 
112*5113495bSYour Name 	return status;
113*5113495bSYour Name }
114*5113495bSYour Name 
115*5113495bSYour Name /**
116*5113495bSYour Name  * target_if_ocb_stop_timing_advert() - stop sending the timing
117*5113495bSYour Name  *   advertisement frame on a channel
118*5113495bSYour Name  * @psoc: pointer to PSOC object
119*5113495bSYour Name  * @ta: pointer to the timing advertisement
120*5113495bSYour Name  *
121*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS on success
122*5113495bSYour Name  */
123*5113495bSYour Name static QDF_STATUS
target_if_ocb_stop_timing_advert(struct wlan_objmgr_psoc * psoc,struct ocb_timing_advert_param * ta)124*5113495bSYour Name target_if_ocb_stop_timing_advert(struct wlan_objmgr_psoc *psoc,
125*5113495bSYour Name 				 struct ocb_timing_advert_param *ta)
126*5113495bSYour Name {
127*5113495bSYour Name 	QDF_STATUS status;
128*5113495bSYour Name 
129*5113495bSYour Name 	status =
130*5113495bSYour Name 		wmi_unified_ocb_stop_timing_advert(
131*5113495bSYour Name 				get_wmi_unified_hdl_from_psoc(psoc), ta);
132*5113495bSYour Name 	if (status)
133*5113495bSYour Name 		target_if_err("Failed to stop OCB timing advert %d", status);
134*5113495bSYour Name 
135*5113495bSYour Name 	return status;
136*5113495bSYour Name }
137*5113495bSYour Name 
138*5113495bSYour Name /**
139*5113495bSYour Name  * target_if_ocb_get_tsf_timer() - get tsf timer
140*5113495bSYour Name  * @psoc: pointer to PSOC object
141*5113495bSYour Name  * @request: pointer to the request
142*5113495bSYour Name  *
143*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS on success
144*5113495bSYour Name  */
145*5113495bSYour Name static QDF_STATUS
target_if_ocb_get_tsf_timer(struct wlan_objmgr_psoc * psoc,struct ocb_get_tsf_timer_param * request)146*5113495bSYour Name target_if_ocb_get_tsf_timer(struct wlan_objmgr_psoc *psoc,
147*5113495bSYour Name 			    struct ocb_get_tsf_timer_param *request)
148*5113495bSYour Name {
149*5113495bSYour Name 	QDF_STATUS status;
150*5113495bSYour Name 
151*5113495bSYour Name 	status = wmi_unified_ocb_get_tsf_timer(
152*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc), request);
153*5113495bSYour Name 	if (status)
154*5113495bSYour Name 		target_if_err("Failed to send get tsf timer cmd: %d", status);
155*5113495bSYour Name 
156*5113495bSYour Name 	return status;
157*5113495bSYour Name }
158*5113495bSYour Name 
159*5113495bSYour Name /**
160*5113495bSYour Name  * target_if_dcc_get_stats() - get the DCC channel stats
161*5113495bSYour Name  * @psoc: pointer to PSOC object
162*5113495bSYour Name  * @get_stats_param: pointer to the dcc stats request
163*5113495bSYour Name  *
164*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS on success
165*5113495bSYour Name  */
166*5113495bSYour Name static QDF_STATUS
target_if_dcc_get_stats(struct wlan_objmgr_psoc * psoc,struct ocb_dcc_get_stats_param * get_stats_param)167*5113495bSYour Name target_if_dcc_get_stats(struct wlan_objmgr_psoc *psoc,
168*5113495bSYour Name 			struct ocb_dcc_get_stats_param *get_stats_param)
169*5113495bSYour Name {
170*5113495bSYour Name 	QDF_STATUS status;
171*5113495bSYour Name 
172*5113495bSYour Name 	status = wmi_unified_dcc_get_stats_cmd(
173*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc), get_stats_param);
174*5113495bSYour Name 	if (status)
175*5113495bSYour Name 		target_if_err("Failed to send get DCC stats cmd: %d", status);
176*5113495bSYour Name 
177*5113495bSYour Name 	return status;
178*5113495bSYour Name }
179*5113495bSYour Name 
180*5113495bSYour Name /**
181*5113495bSYour Name  * target_if_dcc_clear_stats() - send command to clear the DCC stats
182*5113495bSYour Name  * @psoc: pointer to PSOC object
183*5113495bSYour Name  * @clear_stats_param: parameters to the command
184*5113495bSYour Name  *
185*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS on success
186*5113495bSYour Name  */
187*5113495bSYour Name static QDF_STATUS
target_if_dcc_clear_stats(struct wlan_objmgr_psoc * psoc,struct ocb_dcc_clear_stats_param * clear_stats_param)188*5113495bSYour Name target_if_dcc_clear_stats(struct wlan_objmgr_psoc *psoc,
189*5113495bSYour Name 			  struct ocb_dcc_clear_stats_param *clear_stats_param)
190*5113495bSYour Name {
191*5113495bSYour Name 	QDF_STATUS status;
192*5113495bSYour Name 
193*5113495bSYour Name 	status = wmi_unified_dcc_clear_stats(
194*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc), clear_stats_param);
195*5113495bSYour Name 	if (status)
196*5113495bSYour Name 		target_if_err("Failed to send clear DCC stats cmd: %d", status);
197*5113495bSYour Name 
198*5113495bSYour Name 	return status;
199*5113495bSYour Name }
200*5113495bSYour Name 
201*5113495bSYour Name /**
202*5113495bSYour Name  * target_if_dcc_update_ndl() - command to update the NDL data
203*5113495bSYour Name  * @psoc: pointer to PSOC object
204*5113495bSYour Name  * @update_ndl_param: pointer to the request parameters
205*5113495bSYour Name  *
206*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS on success
207*5113495bSYour Name  */
208*5113495bSYour Name static QDF_STATUS
target_if_dcc_update_ndl(struct wlan_objmgr_psoc * psoc,struct ocb_dcc_update_ndl_param * update_ndl_param)209*5113495bSYour Name target_if_dcc_update_ndl(struct wlan_objmgr_psoc *psoc,
210*5113495bSYour Name 			 struct ocb_dcc_update_ndl_param *update_ndl_param)
211*5113495bSYour Name {
212*5113495bSYour Name 	QDF_STATUS status;
213*5113495bSYour Name 
214*5113495bSYour Name 	/* Send the WMI command */
215*5113495bSYour Name 	status = wmi_unified_dcc_update_ndl(get_wmi_unified_hdl_from_psoc(psoc),
216*5113495bSYour Name 					    update_ndl_param);
217*5113495bSYour Name 	if (status)
218*5113495bSYour Name 		target_if_err("Failed to send NDL update cmd: %d", status);
219*5113495bSYour Name 
220*5113495bSYour Name 	return status;
221*5113495bSYour Name }
222*5113495bSYour Name 
223*5113495bSYour Name /**
224*5113495bSYour Name  * target_if_ocb_set_config_resp() - handler for channel config response
225*5113495bSYour Name  * @scn: scn handle
226*5113495bSYour Name  * @event_buf: pointer to the event buffer
227*5113495bSYour Name  * @len: length of the buffer
228*5113495bSYour Name  *
229*5113495bSYour Name  * Return: 0 on success
230*5113495bSYour Name  */
231*5113495bSYour Name static int
target_if_ocb_set_config_resp(ol_scn_t scn,uint8_t * event_buf,uint32_t len)232*5113495bSYour Name target_if_ocb_set_config_resp(ol_scn_t scn, uint8_t *event_buf,
233*5113495bSYour Name 			      uint32_t len)
234*5113495bSYour Name {
235*5113495bSYour Name 	int rc;
236*5113495bSYour Name 	QDF_STATUS status;
237*5113495bSYour Name 	uint32_t resp;
238*5113495bSYour Name 	struct wlan_objmgr_pdev *pdev;
239*5113495bSYour Name 	struct wlan_objmgr_psoc *psoc;
240*5113495bSYour Name 	struct wlan_ocb_rx_ops *ocb_rx_ops;
241*5113495bSYour Name 
242*5113495bSYour Name 	target_if_debug("scn:%pK, data:%pK, datalen:%d",
243*5113495bSYour Name 			scn, event_buf, len);
244*5113495bSYour Name 	if (!scn || !event_buf) {
245*5113495bSYour Name 		target_if_err("scn: 0x%pK, data: 0x%pK", scn, event_buf);
246*5113495bSYour Name 		return -EINVAL;
247*5113495bSYour Name 	}
248*5113495bSYour Name 
249*5113495bSYour Name 	psoc = target_if_get_psoc_from_scn_hdl(scn);
250*5113495bSYour Name 	if (!psoc) {
251*5113495bSYour Name 		target_if_err("null psoc");
252*5113495bSYour Name 		return -EINVAL;
253*5113495bSYour Name 	}
254*5113495bSYour Name 
255*5113495bSYour Name 	pdev = wlan_objmgr_get_pdev_by_id(psoc, 0,
256*5113495bSYour Name 					  WLAN_OCB_SB_ID);
257*5113495bSYour Name 	if (!pdev) {
258*5113495bSYour Name 		target_if_err("pdev is NULL");
259*5113495bSYour Name 		return -EINVAL;
260*5113495bSYour Name 	}
261*5113495bSYour Name 
262*5113495bSYour Name 	ocb_rx_ops = target_if_ocb_get_rx_ops(pdev);
263*5113495bSYour Name 	if (ocb_rx_ops->ocb_set_config_status) {
264*5113495bSYour Name 		status = wmi_extract_ocb_set_channel_config_resp(
265*5113495bSYour Name 					get_wmi_unified_hdl_from_psoc(psoc),
266*5113495bSYour Name 					event_buf, &resp);
267*5113495bSYour Name 		if (QDF_IS_STATUS_ERROR(status)) {
268*5113495bSYour Name 			target_if_err("Failed to extract config status");
269*5113495bSYour Name 			rc = -EINVAL;
270*5113495bSYour Name 			goto exit;
271*5113495bSYour Name 		}
272*5113495bSYour Name 		status = ocb_rx_ops->ocb_set_config_status(psoc, resp);
273*5113495bSYour Name 		if (status != QDF_STATUS_SUCCESS) {
274*5113495bSYour Name 			target_if_err("ocb_set_config_status failed.");
275*5113495bSYour Name 			rc = -EINVAL;
276*5113495bSYour Name 			goto exit;
277*5113495bSYour Name 		}
278*5113495bSYour Name 		rc = 0;
279*5113495bSYour Name 	} else {
280*5113495bSYour Name 		target_if_fatal("No ocb_set_config_status callback");
281*5113495bSYour Name 		rc = -EINVAL;
282*5113495bSYour Name 	}
283*5113495bSYour Name exit:
284*5113495bSYour Name 	wlan_objmgr_pdev_release_ref(pdev, WLAN_OCB_SB_ID);
285*5113495bSYour Name 
286*5113495bSYour Name 	return rc;
287*5113495bSYour Name };
288*5113495bSYour Name 
289*5113495bSYour Name /**
290*5113495bSYour Name  * target_if_ocb_get_tsf_timer_resp() - handler for TSF timer response
291*5113495bSYour Name  * @scn: scn handle
292*5113495bSYour Name  * @event_buf: pointer to the event buffer
293*5113495bSYour Name  * @len: length of the buffer
294*5113495bSYour Name  *
295*5113495bSYour Name  * Return: 0 on success
296*5113495bSYour Name  */
target_if_ocb_get_tsf_timer_resp(ol_scn_t scn,uint8_t * event_buf,uint32_t len)297*5113495bSYour Name static int target_if_ocb_get_tsf_timer_resp(ol_scn_t scn,
298*5113495bSYour Name 					    uint8_t *event_buf,
299*5113495bSYour Name 					    uint32_t len)
300*5113495bSYour Name {
301*5113495bSYour Name 	int rc;
302*5113495bSYour Name 	QDF_STATUS status;
303*5113495bSYour Name 	struct wlan_objmgr_pdev *pdev;
304*5113495bSYour Name 	struct wlan_objmgr_psoc *psoc;
305*5113495bSYour Name 	struct ocb_get_tsf_timer_response response;
306*5113495bSYour Name 	struct wlan_ocb_rx_ops *ocb_rx_ops;
307*5113495bSYour Name 
308*5113495bSYour Name 	target_if_debug("scn:%pK, data:%pK, datalen:%d",
309*5113495bSYour Name 			scn, event_buf, len);
310*5113495bSYour Name 
311*5113495bSYour Name 	if (!scn || !event_buf) {
312*5113495bSYour Name 		target_if_err("scn: 0x%pK, data: 0x%pK", scn, event_buf);
313*5113495bSYour Name 		return -EINVAL;
314*5113495bSYour Name 	}
315*5113495bSYour Name 
316*5113495bSYour Name 	psoc = target_if_get_psoc_from_scn_hdl(scn);
317*5113495bSYour Name 	if (!psoc) {
318*5113495bSYour Name 		target_if_err("null psoc");
319*5113495bSYour Name 		return -EINVAL;
320*5113495bSYour Name 	}
321*5113495bSYour Name 
322*5113495bSYour Name 	pdev = wlan_objmgr_get_pdev_by_id(psoc, 0,
323*5113495bSYour Name 					  WLAN_OCB_SB_ID);
324*5113495bSYour Name 	if (!pdev) {
325*5113495bSYour Name 		target_if_err("pdev is NULL");
326*5113495bSYour Name 		return -EINVAL;
327*5113495bSYour Name 	}
328*5113495bSYour Name 
329*5113495bSYour Name 	ocb_rx_ops = target_if_ocb_get_rx_ops(pdev);
330*5113495bSYour Name 	if (ocb_rx_ops->ocb_tsf_timer) {
331*5113495bSYour Name 		status = wmi_extract_ocb_tsf_timer(
332*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc),
333*5113495bSYour Name 			event_buf, &response);
334*5113495bSYour Name 		if (QDF_IS_STATUS_ERROR(status)) {
335*5113495bSYour Name 			target_if_err("Failed to extract tsf timer");
336*5113495bSYour Name 			rc = -EINVAL;
337*5113495bSYour Name 			goto exit;
338*5113495bSYour Name 		}
339*5113495bSYour Name 		status = ocb_rx_ops->ocb_tsf_timer(psoc, &response);
340*5113495bSYour Name 		if (status != QDF_STATUS_SUCCESS) {
341*5113495bSYour Name 			target_if_err("ocb_tsf_timer failed.");
342*5113495bSYour Name 			rc = -EINVAL;
343*5113495bSYour Name 			goto exit;
344*5113495bSYour Name 		}
345*5113495bSYour Name 		rc = 0;
346*5113495bSYour Name 	} else {
347*5113495bSYour Name 		target_if_fatal("No ocb_tsf_timer callback");
348*5113495bSYour Name 		rc = -EINVAL;
349*5113495bSYour Name 	}
350*5113495bSYour Name exit:
351*5113495bSYour Name 	wlan_objmgr_pdev_release_ref(pdev, WLAN_OCB_SB_ID);
352*5113495bSYour Name 
353*5113495bSYour Name 	return rc;
354*5113495bSYour Name }
355*5113495bSYour Name 
356*5113495bSYour Name /**
357*5113495bSYour Name  * target_if_dcc_update_ndl_resp() - handler for update NDL response
358*5113495bSYour Name  * @scn: scn handle
359*5113495bSYour Name  * @event_buf: pointer to the event buffer
360*5113495bSYour Name  * @len: length of the buffer
361*5113495bSYour Name  *
362*5113495bSYour Name  * Return: 0 on success
363*5113495bSYour Name  */
target_if_dcc_update_ndl_resp(ol_scn_t scn,uint8_t * event_buf,uint32_t len)364*5113495bSYour Name static int target_if_dcc_update_ndl_resp(ol_scn_t scn,
365*5113495bSYour Name 					 uint8_t *event_buf,
366*5113495bSYour Name 					 uint32_t len)
367*5113495bSYour Name {
368*5113495bSYour Name 	int rc;
369*5113495bSYour Name 	QDF_STATUS status;
370*5113495bSYour Name 	struct wlan_objmgr_pdev *pdev;
371*5113495bSYour Name 	struct wlan_objmgr_psoc *psoc;
372*5113495bSYour Name 	struct ocb_dcc_update_ndl_response *resp;
373*5113495bSYour Name 	struct wlan_ocb_rx_ops *ocb_rx_ops;
374*5113495bSYour Name 
375*5113495bSYour Name 	target_if_debug("scn:%pK, data:%pK, datalen:%d",
376*5113495bSYour Name 			scn, event_buf, len);
377*5113495bSYour Name 
378*5113495bSYour Name 	if (!scn || !event_buf) {
379*5113495bSYour Name 		target_if_err("scn: 0x%pK, data: 0x%pK", scn, event_buf);
380*5113495bSYour Name 		return -EINVAL;
381*5113495bSYour Name 	}
382*5113495bSYour Name 
383*5113495bSYour Name 	psoc = target_if_get_psoc_from_scn_hdl(scn);
384*5113495bSYour Name 	if (!psoc) {
385*5113495bSYour Name 		target_if_err("null psoc");
386*5113495bSYour Name 		return -EINVAL;
387*5113495bSYour Name 	}
388*5113495bSYour Name 	pdev = wlan_objmgr_get_pdev_by_id(psoc, 0,
389*5113495bSYour Name 					  WLAN_OCB_SB_ID);
390*5113495bSYour Name 	if (!pdev) {
391*5113495bSYour Name 		target_if_err("pdev is NULL");
392*5113495bSYour Name 		return -EINVAL;
393*5113495bSYour Name 	}
394*5113495bSYour Name 
395*5113495bSYour Name 	/* Allocate and populate the response */
396*5113495bSYour Name 	resp = qdf_mem_malloc(sizeof(*resp));
397*5113495bSYour Name 	if (!resp) {
398*5113495bSYour Name 		rc = -ENOMEM;
399*5113495bSYour Name 		goto exit;
400*5113495bSYour Name 	}
401*5113495bSYour Name 
402*5113495bSYour Name 	ocb_rx_ops = target_if_ocb_get_rx_ops(pdev);
403*5113495bSYour Name 	if (ocb_rx_ops->ocb_dcc_ndl_update) {
404*5113495bSYour Name 		status = wmi_extract_dcc_update_ndl_resp(
405*5113495bSYour Name 					get_wmi_unified_hdl_from_psoc(psoc),
406*5113495bSYour Name 					event_buf, resp);
407*5113495bSYour Name 		if (QDF_IS_STATUS_ERROR(status)) {
408*5113495bSYour Name 			target_if_err("Failed to extract ndl status");
409*5113495bSYour Name 			rc = -EINVAL;
410*5113495bSYour Name 			goto exit;
411*5113495bSYour Name 		}
412*5113495bSYour Name 		status = ocb_rx_ops->ocb_dcc_ndl_update(psoc, resp);
413*5113495bSYour Name 		if (status != QDF_STATUS_SUCCESS) {
414*5113495bSYour Name 			target_if_err("dcc_ndl_update failed.");
415*5113495bSYour Name 			rc = -EINVAL;
416*5113495bSYour Name 			goto exit;
417*5113495bSYour Name 		}
418*5113495bSYour Name 		rc = 0;
419*5113495bSYour Name 	} else {
420*5113495bSYour Name 		target_if_fatal("No dcc_ndl_update callback");
421*5113495bSYour Name 		rc = -EINVAL;
422*5113495bSYour Name 	}
423*5113495bSYour Name exit:
424*5113495bSYour Name 	wlan_objmgr_pdev_release_ref(pdev, WLAN_OCB_SB_ID);
425*5113495bSYour Name 	if (resp)
426*5113495bSYour Name 		qdf_mem_free(resp);
427*5113495bSYour Name 
428*5113495bSYour Name 	return rc;
429*5113495bSYour Name }
430*5113495bSYour Name 
431*5113495bSYour Name /**
432*5113495bSYour Name  * target_if_dcc_get_stats_resp() - handler for get stats response
433*5113495bSYour Name  * @scn: scn handle
434*5113495bSYour Name  * @event_buf: pointer to the event buffer
435*5113495bSYour Name  * @len: length of the buffer
436*5113495bSYour Name  *
437*5113495bSYour Name  * Return: 0 on success
438*5113495bSYour Name  */
target_if_dcc_get_stats_resp(ol_scn_t scn,uint8_t * event_buf,uint32_t len)439*5113495bSYour Name static int target_if_dcc_get_stats_resp(ol_scn_t scn,
440*5113495bSYour Name 					uint8_t *event_buf,
441*5113495bSYour Name 					uint32_t len)
442*5113495bSYour Name {
443*5113495bSYour Name 	int rc;
444*5113495bSYour Name 	QDF_STATUS status;
445*5113495bSYour Name 	struct wlan_objmgr_pdev *pdev;
446*5113495bSYour Name 	struct wlan_objmgr_psoc *psoc;
447*5113495bSYour Name 	struct ocb_dcc_get_stats_response *response;
448*5113495bSYour Name 	struct wlan_ocb_rx_ops *ocb_rx_ops;
449*5113495bSYour Name 
450*5113495bSYour Name 	target_if_debug("scn:%pK, data:%pK, datalen:%d",
451*5113495bSYour Name 			scn, event_buf, len);
452*5113495bSYour Name 
453*5113495bSYour Name 	if (!scn || !event_buf) {
454*5113495bSYour Name 		target_if_err("scn: 0x%pK, data: 0x%pK", scn, event_buf);
455*5113495bSYour Name 		return -EINVAL;
456*5113495bSYour Name 	}
457*5113495bSYour Name 
458*5113495bSYour Name 	psoc = target_if_get_psoc_from_scn_hdl(scn);
459*5113495bSYour Name 	if (!psoc) {
460*5113495bSYour Name 		target_if_err("null psoc");
461*5113495bSYour Name 		return -EINVAL;
462*5113495bSYour Name 	}
463*5113495bSYour Name 
464*5113495bSYour Name 	pdev = wlan_objmgr_get_pdev_by_id(psoc, 0,
465*5113495bSYour Name 					  WLAN_OCB_SB_ID);
466*5113495bSYour Name 	if (!pdev) {
467*5113495bSYour Name 		target_if_err("pdev is NULL");
468*5113495bSYour Name 		return -EINVAL;
469*5113495bSYour Name 	}
470*5113495bSYour Name 
471*5113495bSYour Name 	ocb_rx_ops = target_if_ocb_get_rx_ops(pdev);
472*5113495bSYour Name 	if (ocb_rx_ops->ocb_dcc_stats_indicate) {
473*5113495bSYour Name 		status = wmi_extract_dcc_stats(
474*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc),
475*5113495bSYour Name 			event_buf, &response);
476*5113495bSYour Name 		if (!response || QDF_IS_STATUS_ERROR(status)) {
477*5113495bSYour Name 			target_if_err("Cannot get DCC stats");
478*5113495bSYour Name 			rc = -ENOMEM;
479*5113495bSYour Name 			goto exit;
480*5113495bSYour Name 		}
481*5113495bSYour Name 
482*5113495bSYour Name 		status = ocb_rx_ops->ocb_dcc_stats_indicate(psoc,
483*5113495bSYour Name 							    response,
484*5113495bSYour Name 							    true);
485*5113495bSYour Name 		if (QDF_IS_STATUS_ERROR(status)) {
486*5113495bSYour Name 			target_if_err("dcc_stats_indicate failed.");
487*5113495bSYour Name 			rc = -EINVAL;
488*5113495bSYour Name 			goto exit;
489*5113495bSYour Name 		}
490*5113495bSYour Name 		rc = 0;
491*5113495bSYour Name 	} else {
492*5113495bSYour Name 		target_if_fatal("No dcc_stats_indicate callback");
493*5113495bSYour Name 		rc = -EINVAL;
494*5113495bSYour Name 	}
495*5113495bSYour Name exit:
496*5113495bSYour Name 	wlan_objmgr_pdev_release_ref(pdev, WLAN_OCB_SB_ID);
497*5113495bSYour Name 	if (response)
498*5113495bSYour Name 		qdf_mem_free(response);
499*5113495bSYour Name 
500*5113495bSYour Name 	return rc;
501*5113495bSYour Name }
502*5113495bSYour Name 
503*5113495bSYour Name /**
504*5113495bSYour Name  * target_if_dcc_stats_resp() - handler for DCC stats indication event
505*5113495bSYour Name  * @scn: scn handle
506*5113495bSYour Name  * @event_buf: pointer to the event buffer
507*5113495bSYour Name  * @len: length of the buffer
508*5113495bSYour Name  *
509*5113495bSYour Name  * Return: 0 on success
510*5113495bSYour Name  */
target_if_dcc_stats_resp(ol_scn_t scn,uint8_t * event_buf,uint32_t len)511*5113495bSYour Name static int target_if_dcc_stats_resp(ol_scn_t scn, uint8_t *event_buf,
512*5113495bSYour Name 				    uint32_t len)
513*5113495bSYour Name {
514*5113495bSYour Name 	int rc;
515*5113495bSYour Name 	QDF_STATUS status;
516*5113495bSYour Name 	struct wlan_objmgr_pdev *pdev;
517*5113495bSYour Name 	struct wlan_objmgr_psoc *psoc;
518*5113495bSYour Name 	struct ocb_dcc_get_stats_response *response;
519*5113495bSYour Name 	struct wlan_ocb_rx_ops *ocb_rx_ops;
520*5113495bSYour Name 
521*5113495bSYour Name 	target_if_debug("scn:%pK, data:%pK, datalen:%d",
522*5113495bSYour Name 			scn, event_buf, len);
523*5113495bSYour Name 
524*5113495bSYour Name 	if (!scn || !event_buf) {
525*5113495bSYour Name 		target_if_err("scn: 0x%pK, data: 0x%pK", scn, event_buf);
526*5113495bSYour Name 		return -EINVAL;
527*5113495bSYour Name 	}
528*5113495bSYour Name 
529*5113495bSYour Name 	psoc = target_if_get_psoc_from_scn_hdl(scn);
530*5113495bSYour Name 	if (!psoc) {
531*5113495bSYour Name 		target_if_err("null psoc");
532*5113495bSYour Name 		return -EINVAL;
533*5113495bSYour Name 	}
534*5113495bSYour Name 
535*5113495bSYour Name 	pdev = wlan_objmgr_get_pdev_by_id(psoc, 0,
536*5113495bSYour Name 					  WLAN_OCB_SB_ID);
537*5113495bSYour Name 	if (!pdev) {
538*5113495bSYour Name 		target_if_err("pdev is NULL");
539*5113495bSYour Name 		return -EINVAL;
540*5113495bSYour Name 	}
541*5113495bSYour Name 
542*5113495bSYour Name 	ocb_rx_ops = target_if_ocb_get_rx_ops(pdev);
543*5113495bSYour Name 	if (ocb_rx_ops->ocb_dcc_stats_indicate) {
544*5113495bSYour Name 		status = wmi_extract_dcc_stats(
545*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc),
546*5113495bSYour Name 			event_buf, &response);
547*5113495bSYour Name 		if (!response || QDF_IS_STATUS_ERROR(status)) {
548*5113495bSYour Name 			target_if_err("Cannot get DCC stats");
549*5113495bSYour Name 			rc = -ENOMEM;
550*5113495bSYour Name 			goto exit;
551*5113495bSYour Name 		}
552*5113495bSYour Name 		status = ocb_rx_ops->ocb_dcc_stats_indicate(psoc,
553*5113495bSYour Name 							    response,
554*5113495bSYour Name 							    false);
555*5113495bSYour Name 		if (QDF_IS_STATUS_ERROR(status)) {
556*5113495bSYour Name 			target_if_err("dcc_stats_indicate failed.");
557*5113495bSYour Name 			rc = -EINVAL;
558*5113495bSYour Name 			goto exit;
559*5113495bSYour Name 		}
560*5113495bSYour Name 		rc = 0;
561*5113495bSYour Name 	} else {
562*5113495bSYour Name 		target_if_fatal("dcc_stats_indicate failed.");
563*5113495bSYour Name 		response = NULL;
564*5113495bSYour Name 		rc = -EINVAL;
565*5113495bSYour Name 	}
566*5113495bSYour Name exit:
567*5113495bSYour Name 	wlan_objmgr_pdev_release_ref(pdev, WLAN_OCB_SB_ID);
568*5113495bSYour Name 	if (response)
569*5113495bSYour Name 		qdf_mem_free(response);
570*5113495bSYour Name 
571*5113495bSYour Name 	return rc;
572*5113495bSYour Name }
573*5113495bSYour Name 
target_if_ocb_register_event_handler(struct wlan_objmgr_psoc * psoc,void * arg)574*5113495bSYour Name QDF_STATUS target_if_ocb_register_event_handler(struct wlan_objmgr_psoc *psoc,
575*5113495bSYour Name 						void *arg)
576*5113495bSYour Name {
577*5113495bSYour Name 	QDF_STATUS rc;
578*5113495bSYour Name 
579*5113495bSYour Name 	/* Initialize the members in WMA used by wma_ocb */
580*5113495bSYour Name 	rc = wmi_unified_register_event(get_wmi_unified_hdl_from_psoc(psoc),
581*5113495bSYour Name 			wmi_ocb_set_config_resp_event_id,
582*5113495bSYour Name 			target_if_ocb_set_config_resp);
583*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(rc)) {
584*5113495bSYour Name 		target_if_err("Failed to register OCB config resp event cb");
585*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
586*5113495bSYour Name 	}
587*5113495bSYour Name 
588*5113495bSYour Name 	rc = wmi_unified_register_event(
589*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc),
590*5113495bSYour Name 			wmi_ocb_get_tsf_timer_resp_event_id,
591*5113495bSYour Name 			target_if_ocb_get_tsf_timer_resp);
592*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(rc)) {
593*5113495bSYour Name 		target_if_err("Failed to register OCB TSF resp event cb");
594*5113495bSYour Name 		goto unreg_set_config;
595*5113495bSYour Name 	}
596*5113495bSYour Name 
597*5113495bSYour Name 	rc = wmi_unified_register_event(
598*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc),
599*5113495bSYour Name 			wmi_dcc_get_stats_resp_event_id,
600*5113495bSYour Name 			target_if_dcc_get_stats_resp);
601*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(rc)) {
602*5113495bSYour Name 		target_if_err("Failed to register DCC get stats resp event cb");
603*5113495bSYour Name 		goto unreg_tsf_timer;
604*5113495bSYour Name 	}
605*5113495bSYour Name 
606*5113495bSYour Name 	rc = wmi_unified_register_event(
607*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc),
608*5113495bSYour Name 			wmi_dcc_update_ndl_resp_event_id,
609*5113495bSYour Name 			target_if_dcc_update_ndl_resp);
610*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(rc)) {
611*5113495bSYour Name 		target_if_err("Failed to register NDL update event cb");
612*5113495bSYour Name 		goto unreg_get_stats;
613*5113495bSYour Name 	}
614*5113495bSYour Name 
615*5113495bSYour Name 	rc = wmi_unified_register_event(get_wmi_unified_hdl_from_psoc(psoc),
616*5113495bSYour Name 			wmi_dcc_stats_event_id,
617*5113495bSYour Name 			target_if_dcc_stats_resp);
618*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(rc)) {
619*5113495bSYour Name 		target_if_err("Failed to register DCC stats event cb");
620*5113495bSYour Name 		goto unreg_ndl;
621*5113495bSYour Name 	}
622*5113495bSYour Name 
623*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
624*5113495bSYour Name 
625*5113495bSYour Name unreg_ndl:
626*5113495bSYour Name 	wmi_unified_unregister_event_handler(
627*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc),
628*5113495bSYour Name 			wmi_dcc_update_ndl_resp_event_id);
629*5113495bSYour Name unreg_get_stats:
630*5113495bSYour Name 	wmi_unified_unregister_event_handler(
631*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc),
632*5113495bSYour Name 			wmi_dcc_get_stats_resp_event_id);
633*5113495bSYour Name unreg_tsf_timer:
634*5113495bSYour Name 	wmi_unified_unregister_event_handler(
635*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc),
636*5113495bSYour Name 			wmi_ocb_get_tsf_timer_resp_event_id);
637*5113495bSYour Name unreg_set_config:
638*5113495bSYour Name 	wmi_unified_unregister_event(get_wmi_unified_hdl_from_psoc(psoc),
639*5113495bSYour Name 			wmi_ocb_set_config_resp_event_id);
640*5113495bSYour Name 
641*5113495bSYour Name 	return QDF_STATUS_E_FAILURE;
642*5113495bSYour Name }
643*5113495bSYour Name 
644*5113495bSYour Name QDF_STATUS
target_if_ocb_unregister_event_handler(struct wlan_objmgr_psoc * psoc,void * arg)645*5113495bSYour Name target_if_ocb_unregister_event_handler(struct wlan_objmgr_psoc *psoc,
646*5113495bSYour Name 				       void *arg)
647*5113495bSYour Name {
648*5113495bSYour Name 	QDF_STATUS rc;
649*5113495bSYour Name 
650*5113495bSYour Name 	rc = wmi_unified_unregister_event_handler(
651*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc),
652*5113495bSYour Name 			wmi_dcc_stats_event_id);
653*5113495bSYour Name 
654*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(rc))
655*5113495bSYour Name 		target_if_err("Failed to unregister DCC stats event cb");
656*5113495bSYour Name 
657*5113495bSYour Name 	rc = wmi_unified_unregister_event_handler(
658*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc),
659*5113495bSYour Name 			wmi_dcc_update_ndl_resp_event_id);
660*5113495bSYour Name 
661*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(rc))
662*5113495bSYour Name 		target_if_err("Failed to unregister NDL update event cb");
663*5113495bSYour Name 
664*5113495bSYour Name 	rc = wmi_unified_unregister_event_handler(
665*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc),
666*5113495bSYour Name 			wmi_dcc_get_stats_resp_event_id);
667*5113495bSYour Name 
668*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(rc))
669*5113495bSYour Name 		target_if_err("Failed to unregister DCC get stats resp cb");
670*5113495bSYour Name 
671*5113495bSYour Name 	rc = wmi_unified_unregister_event_handler(
672*5113495bSYour Name 			get_wmi_unified_hdl_from_psoc(psoc),
673*5113495bSYour Name 			wmi_ocb_get_tsf_timer_resp_event_id);
674*5113495bSYour Name 
675*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(rc))
676*5113495bSYour Name 		target_if_err("Failed to unregister OCB TSF resp event cb");
677*5113495bSYour Name 
678*5113495bSYour Name 	rc = wmi_unified_unregister_event(get_wmi_unified_hdl_from_psoc(psoc),
679*5113495bSYour Name 			wmi_ocb_set_config_resp_event_id);
680*5113495bSYour Name 
681*5113495bSYour Name 	if (QDF_IS_STATUS_ERROR(rc))
682*5113495bSYour Name 		target_if_err("Failed to unregister OCB config resp event cb");
683*5113495bSYour Name 
684*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
685*5113495bSYour Name }
686*5113495bSYour Name 
687*5113495bSYour Name QDF_STATUS
target_if_ocb_register_tx_ops(struct wlan_ocb_tx_ops * ocb_txops)688*5113495bSYour Name target_if_ocb_register_tx_ops(struct wlan_ocb_tx_ops *ocb_txops)
689*5113495bSYour Name {
690*5113495bSYour Name 	ocb_txops->ocb_set_config = target_if_ocb_set_config;
691*5113495bSYour Name 	ocb_txops->ocb_set_utc_time = target_if_ocb_set_utc_time;
692*5113495bSYour Name 	ocb_txops->ocb_start_timing_advert = target_if_ocb_start_timing_advert;
693*5113495bSYour Name 	ocb_txops->ocb_stop_timing_advert = target_if_ocb_stop_timing_advert;
694*5113495bSYour Name 	ocb_txops->ocb_get_tsf_timer = target_if_ocb_get_tsf_timer;
695*5113495bSYour Name 	ocb_txops->ocb_dcc_get_stats = target_if_dcc_get_stats;
696*5113495bSYour Name 	ocb_txops->ocb_dcc_clear_stats = target_if_dcc_clear_stats;
697*5113495bSYour Name 	ocb_txops->ocb_dcc_update_ndl = target_if_dcc_update_ndl;
698*5113495bSYour Name 	ocb_txops->ocb_reg_ev_handler = target_if_ocb_register_event_handler;
699*5113495bSYour Name 	ocb_txops->ocb_unreg_ev_handler =
700*5113495bSYour Name 			target_if_ocb_unregister_event_handler;
701*5113495bSYour Name 
702*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
703*5113495bSYour Name }
704