1*5113495bSYour Name /*
2*5113495bSYour Name * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. 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 * DOC: wlan_twt_api.c
20*5113495bSYour Name * This file defines the APIs of TWT component.
21*5113495bSYour Name */
22*5113495bSYour Name #include <wlan_twt_api.h>
23*5113495bSYour Name #include "twt/core/src/wlan_twt_objmgr_handler.h"
24*5113495bSYour Name #include "twt/core/src/wlan_twt_common.h"
25*5113495bSYour Name #ifdef WLAN_POWER_MANAGEMENT_OFFLOAD
26*5113495bSYour Name #include <wlan_pmo_obj_mgmt_api.h>
27*5113495bSYour Name #endif
28*5113495bSYour Name
29*5113495bSYour Name struct wlan_lmac_if_twt_tx_ops *
wlan_twt_get_tx_ops(struct wlan_objmgr_psoc * psoc)30*5113495bSYour Name wlan_twt_get_tx_ops(struct wlan_objmgr_psoc *psoc)
31*5113495bSYour Name {
32*5113495bSYour Name struct wlan_lmac_if_tx_ops *tx_ops;
33*5113495bSYour Name
34*5113495bSYour Name tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
35*5113495bSYour Name if (!tx_ops) {
36*5113495bSYour Name twt_err("tx_ops is NULL");
37*5113495bSYour Name return NULL;
38*5113495bSYour Name }
39*5113495bSYour Name
40*5113495bSYour Name return &tx_ops->twt_tx_ops;
41*5113495bSYour Name }
42*5113495bSYour Name
43*5113495bSYour Name struct wlan_lmac_if_twt_rx_ops *
wlan_twt_get_rx_ops(struct wlan_objmgr_psoc * psoc)44*5113495bSYour Name wlan_twt_get_rx_ops(struct wlan_objmgr_psoc *psoc)
45*5113495bSYour Name {
46*5113495bSYour Name struct wlan_lmac_if_rx_ops *rx_ops;
47*5113495bSYour Name
48*5113495bSYour Name rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
49*5113495bSYour Name if (!rx_ops) {
50*5113495bSYour Name twt_err("rx_ops is NULL");
51*5113495bSYour Name return NULL;
52*5113495bSYour Name }
53*5113495bSYour Name
54*5113495bSYour Name return &rx_ops->twt_rx_ops;
55*5113495bSYour Name }
56*5113495bSYour Name
57*5113495bSYour Name struct twt_psoc_priv_obj*
wlan_twt_psoc_get_comp_private_obj(struct wlan_objmgr_psoc * psoc)58*5113495bSYour Name wlan_twt_psoc_get_comp_private_obj(struct wlan_objmgr_psoc *psoc)
59*5113495bSYour Name {
60*5113495bSYour Name struct twt_psoc_priv_obj *twt_psoc;
61*5113495bSYour Name
62*5113495bSYour Name twt_psoc = wlan_objmgr_psoc_get_comp_private_obj(psoc,
63*5113495bSYour Name WLAN_UMAC_COMP_TWT);
64*5113495bSYour Name if (!twt_psoc) {
65*5113495bSYour Name twt_err("TWT PSOC component object is NULL");
66*5113495bSYour Name return NULL;
67*5113495bSYour Name }
68*5113495bSYour Name
69*5113495bSYour Name return twt_psoc;
70*5113495bSYour Name }
71*5113495bSYour Name
72*5113495bSYour Name #ifdef WLAN_POWER_MANAGEMENT_OFFLOAD
73*5113495bSYour Name static QDF_STATUS
wlan_twt_suspend_handler(struct wlan_objmgr_psoc * psoc,void * arg)74*5113495bSYour Name wlan_twt_suspend_handler(struct wlan_objmgr_psoc *psoc, void *arg)
75*5113495bSYour Name {
76*5113495bSYour Name wlan_twt_psoc_set_pmo_disable(psoc, REASON_PMO_SUSPEND);
77*5113495bSYour Name return QDF_STATUS_SUCCESS;
78*5113495bSYour Name }
79*5113495bSYour Name
80*5113495bSYour Name static QDF_STATUS
wlan_twt_resume_handler(struct wlan_objmgr_psoc * psoc,void * arg)81*5113495bSYour Name wlan_twt_resume_handler(struct wlan_objmgr_psoc *psoc, void *arg)
82*5113495bSYour Name {
83*5113495bSYour Name wlan_twt_psoc_set_pmo_enable(psoc, REASON_PMO_SUSPEND);
84*5113495bSYour Name return QDF_STATUS_SUCCESS;
85*5113495bSYour Name }
86*5113495bSYour Name
87*5113495bSYour Name static void
wlan_twt_register_pmo_handler(void)88*5113495bSYour Name wlan_twt_register_pmo_handler(void)
89*5113495bSYour Name {
90*5113495bSYour Name pmo_register_suspend_handler(WLAN_UMAC_COMP_TWT,
91*5113495bSYour Name wlan_twt_suspend_handler, NULL);
92*5113495bSYour Name pmo_register_resume_handler(WLAN_UMAC_COMP_TWT,
93*5113495bSYour Name wlan_twt_resume_handler, NULL);
94*5113495bSYour Name }
95*5113495bSYour Name
96*5113495bSYour Name static inline void
wlan_twt_unregister_pmo_handler(void)97*5113495bSYour Name wlan_twt_unregister_pmo_handler(void)
98*5113495bSYour Name {
99*5113495bSYour Name pmo_unregister_suspend_handler(WLAN_UMAC_COMP_TWT,
100*5113495bSYour Name wlan_twt_suspend_handler);
101*5113495bSYour Name pmo_unregister_resume_handler(WLAN_UMAC_COMP_TWT,
102*5113495bSYour Name wlan_twt_resume_handler);
103*5113495bSYour Name }
104*5113495bSYour Name
105*5113495bSYour Name #else
106*5113495bSYour Name static void
wlan_twt_register_pmo_handler(void)107*5113495bSYour Name wlan_twt_register_pmo_handler(void)
108*5113495bSYour Name {
109*5113495bSYour Name }
110*5113495bSYour Name
111*5113495bSYour Name static inline void
wlan_twt_unregister_pmo_handler(void)112*5113495bSYour Name wlan_twt_unregister_pmo_handler(void)
113*5113495bSYour Name {
114*5113495bSYour Name }
115*5113495bSYour Name
116*5113495bSYour Name #endif
117*5113495bSYour Name
wlan_twt_init(void)118*5113495bSYour Name QDF_STATUS wlan_twt_init(void)
119*5113495bSYour Name {
120*5113495bSYour Name QDF_STATUS status = QDF_STATUS_E_FAILURE;
121*5113495bSYour Name
122*5113495bSYour Name status = wlan_objmgr_register_psoc_create_handler
123*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
124*5113495bSYour Name wlan_twt_psoc_obj_create_handler,
125*5113495bSYour Name NULL);
126*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
127*5113495bSYour Name twt_err("Failed to register psoc create handler");
128*5113495bSYour Name goto wlan_twt_psoc_init_fail1;
129*5113495bSYour Name }
130*5113495bSYour Name
131*5113495bSYour Name status = wlan_objmgr_register_psoc_destroy_handler
132*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
133*5113495bSYour Name wlan_twt_psoc_obj_destroy_handler,
134*5113495bSYour Name NULL);
135*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
136*5113495bSYour Name twt_err("Failed to register psoc destroy handler");
137*5113495bSYour Name goto wlan_twt_psoc_init_fail2;
138*5113495bSYour Name }
139*5113495bSYour Name
140*5113495bSYour Name status = wlan_objmgr_register_vdev_create_handler
141*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
142*5113495bSYour Name wlan_twt_vdev_obj_create_handler,
143*5113495bSYour Name NULL);
144*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
145*5113495bSYour Name twt_err("Failed to register vdev create handler");
146*5113495bSYour Name goto wlan_twt_vdev_init_fail1;
147*5113495bSYour Name }
148*5113495bSYour Name
149*5113495bSYour Name status = wlan_objmgr_register_vdev_destroy_handler
150*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
151*5113495bSYour Name wlan_twt_vdev_obj_destroy_handler,
152*5113495bSYour Name NULL);
153*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
154*5113495bSYour Name twt_err("Failed to register vdev destroy handler");
155*5113495bSYour Name goto wlan_twt_vdev_init_fail2;
156*5113495bSYour Name }
157*5113495bSYour Name
158*5113495bSYour Name status = wlan_objmgr_register_peer_create_handler
159*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
160*5113495bSYour Name wlan_twt_peer_obj_create_handler,
161*5113495bSYour Name NULL);
162*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
163*5113495bSYour Name twt_err("Failed to register peer create handler");
164*5113495bSYour Name goto wlan_twt_peer_init_fail1;
165*5113495bSYour Name }
166*5113495bSYour Name
167*5113495bSYour Name status = wlan_objmgr_register_peer_destroy_handler
168*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
169*5113495bSYour Name wlan_twt_peer_obj_destroy_handler,
170*5113495bSYour Name NULL);
171*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
172*5113495bSYour Name twt_err("Failed to register peer destroy handler");
173*5113495bSYour Name goto wlan_twt_peer_init_fail2;
174*5113495bSYour Name }
175*5113495bSYour Name
176*5113495bSYour Name return QDF_STATUS_SUCCESS;
177*5113495bSYour Name
178*5113495bSYour Name wlan_twt_peer_init_fail2:
179*5113495bSYour Name wlan_objmgr_unregister_peer_create_handler
180*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
181*5113495bSYour Name wlan_twt_peer_obj_create_handler,
182*5113495bSYour Name NULL);
183*5113495bSYour Name wlan_twt_peer_init_fail1:
184*5113495bSYour Name wlan_objmgr_unregister_vdev_destroy_handler
185*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
186*5113495bSYour Name wlan_twt_vdev_obj_destroy_handler,
187*5113495bSYour Name NULL);
188*5113495bSYour Name wlan_twt_vdev_init_fail2:
189*5113495bSYour Name wlan_objmgr_unregister_vdev_create_handler
190*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
191*5113495bSYour Name wlan_twt_vdev_obj_create_handler,
192*5113495bSYour Name NULL);
193*5113495bSYour Name wlan_twt_vdev_init_fail1:
194*5113495bSYour Name wlan_objmgr_unregister_psoc_destroy_handler
195*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
196*5113495bSYour Name wlan_twt_psoc_obj_destroy_handler,
197*5113495bSYour Name NULL);
198*5113495bSYour Name wlan_twt_psoc_init_fail2:
199*5113495bSYour Name wlan_objmgr_unregister_psoc_create_handler
200*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
201*5113495bSYour Name wlan_twt_psoc_obj_create_handler,
202*5113495bSYour Name NULL);
203*5113495bSYour Name wlan_twt_psoc_init_fail1:
204*5113495bSYour Name return status;
205*5113495bSYour Name }
206*5113495bSYour Name
wlan_twt_deinit(void)207*5113495bSYour Name QDF_STATUS wlan_twt_deinit(void)
208*5113495bSYour Name {
209*5113495bSYour Name QDF_STATUS status = QDF_STATUS_E_FAILURE;
210*5113495bSYour Name
211*5113495bSYour Name status = wlan_objmgr_unregister_psoc_create_handler
212*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
213*5113495bSYour Name wlan_twt_psoc_obj_create_handler,
214*5113495bSYour Name NULL);
215*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status))
216*5113495bSYour Name twt_err("Failed to unregister psoc create handler");
217*5113495bSYour Name
218*5113495bSYour Name status = wlan_objmgr_unregister_psoc_destroy_handler
219*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
220*5113495bSYour Name wlan_twt_psoc_obj_destroy_handler,
221*5113495bSYour Name NULL);
222*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status))
223*5113495bSYour Name twt_err("Failed to unregister psoc destroy handler");
224*5113495bSYour Name
225*5113495bSYour Name status = wlan_objmgr_unregister_vdev_create_handler
226*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
227*5113495bSYour Name wlan_twt_vdev_obj_create_handler,
228*5113495bSYour Name NULL);
229*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status))
230*5113495bSYour Name twt_err("Failed to unregister vdev create handler");
231*5113495bSYour Name
232*5113495bSYour Name status = wlan_objmgr_unregister_vdev_destroy_handler
233*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
234*5113495bSYour Name wlan_twt_vdev_obj_destroy_handler,
235*5113495bSYour Name NULL);
236*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status))
237*5113495bSYour Name twt_err("Failed to unregister vdev destroy handler");
238*5113495bSYour Name
239*5113495bSYour Name status = wlan_objmgr_unregister_peer_create_handler
240*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
241*5113495bSYour Name wlan_twt_peer_obj_create_handler,
242*5113495bSYour Name NULL);
243*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status))
244*5113495bSYour Name twt_err("Failed to unregister peer create handler");
245*5113495bSYour Name
246*5113495bSYour Name status = wlan_objmgr_unregister_peer_destroy_handler
247*5113495bSYour Name (WLAN_UMAC_COMP_TWT,
248*5113495bSYour Name wlan_twt_peer_obj_destroy_handler,
249*5113495bSYour Name NULL);
250*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status))
251*5113495bSYour Name twt_err("Failed to unregister peer destroy handler");
252*5113495bSYour Name
253*5113495bSYour Name return status;
254*5113495bSYour Name }
255*5113495bSYour Name
twt_psoc_enable(struct wlan_objmgr_psoc * psoc)256*5113495bSYour Name QDF_STATUS twt_psoc_enable(struct wlan_objmgr_psoc *psoc)
257*5113495bSYour Name {
258*5113495bSYour Name QDF_STATUS status = QDF_STATUS_E_NULL_VALUE;
259*5113495bSYour Name struct wlan_lmac_if_twt_tx_ops *tx_ops;
260*5113495bSYour Name
261*5113495bSYour Name tx_ops = wlan_twt_get_tx_ops(psoc);
262*5113495bSYour Name if (!tx_ops || !tx_ops->register_events) {
263*5113495bSYour Name twt_err("%s is null", !tx_ops ? "tx_ops" : "register_events");
264*5113495bSYour Name return QDF_STATUS_E_NULL_VALUE;
265*5113495bSYour Name }
266*5113495bSYour Name
267*5113495bSYour Name status = tx_ops->register_events(psoc);
268*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status))
269*5113495bSYour Name twt_err("twt_register_events failed (status=%d)", status);
270*5113495bSYour Name
271*5113495bSYour Name wlan_twt_register_pmo_handler();
272*5113495bSYour Name
273*5113495bSYour Name return status;
274*5113495bSYour Name }
275*5113495bSYour Name
twt_psoc_disable(struct wlan_objmgr_psoc * psoc)276*5113495bSYour Name QDF_STATUS twt_psoc_disable(struct wlan_objmgr_psoc *psoc)
277*5113495bSYour Name {
278*5113495bSYour Name QDF_STATUS status = QDF_STATUS_E_NULL_VALUE;
279*5113495bSYour Name struct wlan_lmac_if_twt_tx_ops *tx_ops;
280*5113495bSYour Name
281*5113495bSYour Name tx_ops = wlan_twt_get_tx_ops(psoc);
282*5113495bSYour Name if (!tx_ops || !tx_ops->deregister_events) {
283*5113495bSYour Name twt_err("%s is null", !tx_ops ? "tx_ops" : "deregister_events");
284*5113495bSYour Name return QDF_STATUS_E_NULL_VALUE;
285*5113495bSYour Name }
286*5113495bSYour Name
287*5113495bSYour Name status = tx_ops->deregister_events(psoc);
288*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status))
289*5113495bSYour Name twt_err("twt_deregister_events failed (status=%d)",
290*5113495bSYour Name status);
291*5113495bSYour Name
292*5113495bSYour Name wlan_twt_unregister_pmo_handler();
293*5113495bSYour Name
294*5113495bSYour Name return status;
295*5113495bSYour Name }
296*5113495bSYour Name
297*5113495bSYour Name QDF_STATUS
wlan_set_peer_twt_capabilities(struct wlan_objmgr_psoc * psoc,struct qdf_mac_addr * peer_mac,uint8_t peer_cap)298*5113495bSYour Name wlan_set_peer_twt_capabilities(struct wlan_objmgr_psoc *psoc,
299*5113495bSYour Name struct qdf_mac_addr *peer_mac,
300*5113495bSYour Name uint8_t peer_cap)
301*5113495bSYour Name {
302*5113495bSYour Name return wlan_twt_set_peer_capabilities(psoc, peer_mac, peer_cap);
303*5113495bSYour Name }
304*5113495bSYour Name
305