xref: /wlan-driver/qca-wifi-host-cmn/target_if/twt/src/target_if_twt_evt.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. 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 /**
18  *  DOC: target_if_twt_evt.c
19  *  This file contains twt component's target related function definitions
20  */
21 #include <target_if_twt.h>
22 #include <target_if_twt_evt.h>
23 #include <target_if_ext_twt.h>
24 #include "twt/core/src/wlan_twt_priv.h"
25 #include <wlan_twt_api.h>
26 #include <wmi_unified_twt_api.h>
27 
28 int
target_if_twt_en_complete_event_handler(ol_scn_t scn,uint8_t * data,uint32_t datalen)29 target_if_twt_en_complete_event_handler(ol_scn_t scn,
30 					uint8_t *data, uint32_t datalen)
31 {
32 	wmi_unified_t wmi_handle;
33 	struct wlan_objmgr_psoc *psoc;
34 	struct wlan_lmac_if_rx_ops *rx_ops;
35 	struct wlan_lmac_if_twt_rx_ops *twt_rx_ops;
36 	struct twt_enable_complete_event_param event;
37 	QDF_STATUS status;
38 
39 	TARGET_IF_ENTER();
40 
41 	if (!scn || !data) {
42 		target_if_err("scn: 0x%pK, data: 0x%pK", scn, data);
43 		return -EINVAL;
44 	}
45 
46 	psoc = target_if_get_psoc_from_scn_hdl(scn);
47 	if (!psoc) {
48 		target_if_err("psoc is null");
49 		return -EINVAL;
50 	}
51 
52 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
53 	if (!rx_ops) {
54 		target_if_err("rx_ops is NULL");
55 		return -EINVAL;
56 	}
57 	twt_rx_ops =  &rx_ops->twt_rx_ops;
58 	if (!twt_rx_ops || !twt_rx_ops->twt_enable_comp_cb) {
59 		target_if_err("TWT rx_ops comp_cb is NULL");
60 		return -EINVAL;
61 	}
62 
63 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
64 	if (!wmi_handle) {
65 		target_if_err("wmi_handle is null");
66 		return -EINVAL;
67 	}
68 
69 	status = wmi_extract_twt_enable_comp_event(wmi_handle, data, &event);
70 	if (QDF_IS_STATUS_ERROR(status)) {
71 		target_if_err("TWT enable extract event failed(status=%d)",
72 				status);
73 		goto end;
74 	}
75 
76 	status = twt_rx_ops->twt_enable_comp_cb(psoc, &event);
77 
78 end:
79 	return qdf_status_to_os_return(status);
80 }
81 
82 int
target_if_twt_disable_comp_event_handler(ol_scn_t scn,uint8_t * data,uint32_t datalen)83 target_if_twt_disable_comp_event_handler(ol_scn_t scn,
84 					 uint8_t *data, uint32_t datalen)
85 {
86 	wmi_unified_t wmi_handle;
87 	struct wlan_objmgr_psoc *psoc;
88 	struct wlan_lmac_if_rx_ops *rx_ops;
89 	struct wlan_lmac_if_twt_rx_ops *twt_rx_ops;
90 	struct twt_disable_complete_event_param event;
91 	QDF_STATUS status;
92 
93 	TARGET_IF_ENTER();
94 
95 	if (!scn || !data) {
96 		target_if_err("scn: 0x%pK, data: 0x%pK", scn, data);
97 		return -EINVAL;
98 	}
99 
100 	psoc = target_if_get_psoc_from_scn_hdl(scn);
101 	if (!psoc) {
102 		target_if_err("psoc is null");
103 		return -EINVAL;
104 	}
105 
106 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
107 	if (!rx_ops) {
108 		target_if_err("rx_ops is NULL");
109 		return -EINVAL;
110 	}
111 	twt_rx_ops =  &rx_ops->twt_rx_ops;
112 	if (!twt_rx_ops || !twt_rx_ops->twt_disable_comp_cb) {
113 		target_if_err("TWT rx_ops comp_cb is NULL");
114 		return -EINVAL;
115 	}
116 
117 	wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
118 	if (!wmi_handle) {
119 		target_if_err("wmi_handle is null");
120 		return -EINVAL;
121 	}
122 
123 	status = wmi_extract_twt_disable_comp_event(wmi_handle, data, &event);
124 	if (QDF_IS_STATUS_ERROR(status)) {
125 		target_if_err("TWT disable extract event failed(status=%d)",
126 				status);
127 		goto end;
128 	}
129 
130 	status = twt_rx_ops->twt_disable_comp_cb(psoc, &event);
131 
132 end:
133 	return qdf_status_to_os_return(status);
134 }
135 
136