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 any
5*5113495bSYour Name * purpose with or without fee is hereby granted, provided that the above
6*5113495bSYour Name * copyright notice and this permission notice appear in all copies.
7*5113495bSYour Name *
8*5113495bSYour Name * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*5113495bSYour Name * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*5113495bSYour Name * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11*5113495bSYour Name * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*5113495bSYour Name * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13*5113495bSYour Name * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14*5113495bSYour Name * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*5113495bSYour Name */
16*5113495bSYour Name
17*5113495bSYour Name /**
18*5113495bSYour Name * DOC: target_if_twt.c
19*5113495bSYour Name * This file contains twt component's target related function definitions
20*5113495bSYour Name */
21*5113495bSYour Name #include <target_if_twt.h>
22*5113495bSYour Name #include <target_if_twt_cmd.h>
23*5113495bSYour Name #include <target_if_twt_evt.h>
24*5113495bSYour Name #include <target_if_ext_twt.h>
25*5113495bSYour Name #include "twt/core/src/wlan_twt_common.h"
26*5113495bSYour Name #include "twt/core/src/wlan_twt_priv.h"
27*5113495bSYour Name
28*5113495bSYour Name QDF_STATUS
target_if_twt_register_events(struct wlan_objmgr_psoc * psoc)29*5113495bSYour Name target_if_twt_register_events(struct wlan_objmgr_psoc *psoc)
30*5113495bSYour Name {
31*5113495bSYour Name QDF_STATUS status;
32*5113495bSYour Name struct wmi_unified *wmi_handle;
33*5113495bSYour Name
34*5113495bSYour Name wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
35*5113495bSYour Name if (!wmi_handle) {
36*5113495bSYour Name target_if_err("wmi_handle is null!");
37*5113495bSYour Name return QDF_STATUS_E_INVAL;
38*5113495bSYour Name }
39*5113495bSYour Name
40*5113495bSYour Name status = wmi_unified_register_event_handler(wmi_handle,
41*5113495bSYour Name wmi_twt_enable_complete_event_id,
42*5113495bSYour Name target_if_twt_en_complete_event_handler,
43*5113495bSYour Name WMI_RX_WORK_CTX);
44*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
45*5113495bSYour Name target_if_err("Failed to register twt enable event cb");
46*5113495bSYour Name if (status == QDF_STATUS_E_NOSUPPORT)
47*5113495bSYour Name status = QDF_STATUS_SUCCESS;
48*5113495bSYour Name return status;
49*5113495bSYour Name }
50*5113495bSYour Name
51*5113495bSYour Name status = wmi_unified_register_event_handler(wmi_handle,
52*5113495bSYour Name wmi_twt_disable_complete_event_id,
53*5113495bSYour Name target_if_twt_disable_comp_event_handler,
54*5113495bSYour Name WMI_RX_WORK_CTX);
55*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
56*5113495bSYour Name target_if_err("Failed to register twt disable event cb");
57*5113495bSYour Name if (status == QDF_STATUS_E_NOSUPPORT)
58*5113495bSYour Name status = QDF_STATUS_SUCCESS;
59*5113495bSYour Name return status;
60*5113495bSYour Name }
61*5113495bSYour Name
62*5113495bSYour Name status = target_if_twt_register_ext_events(psoc);
63*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
64*5113495bSYour Name target_if_err("Failed to register twt ext events");
65*5113495bSYour Name if (status == QDF_STATUS_E_NOSUPPORT)
66*5113495bSYour Name status = QDF_STATUS_SUCCESS;
67*5113495bSYour Name return status;
68*5113495bSYour Name }
69*5113495bSYour Name
70*5113495bSYour Name return status;
71*5113495bSYour Name }
72*5113495bSYour Name
73*5113495bSYour Name QDF_STATUS
target_if_twt_deregister_events(struct wlan_objmgr_psoc * psoc)74*5113495bSYour Name target_if_twt_deregister_events(struct wlan_objmgr_psoc *psoc)
75*5113495bSYour Name {
76*5113495bSYour Name QDF_STATUS status;
77*5113495bSYour Name struct wmi_unified *wmi_handle;
78*5113495bSYour Name
79*5113495bSYour Name if (!psoc) {
80*5113495bSYour Name target_if_err("psoc is NULL!");
81*5113495bSYour Name return QDF_STATUS_E_INVAL;
82*5113495bSYour Name }
83*5113495bSYour Name
84*5113495bSYour Name wmi_handle = get_wmi_unified_hdl_from_psoc(psoc);
85*5113495bSYour Name if (!wmi_handle) {
86*5113495bSYour Name target_if_err("wmi_handle is null");
87*5113495bSYour Name return QDF_STATUS_E_NULL_VALUE;
88*5113495bSYour Name }
89*5113495bSYour Name
90*5113495bSYour Name status = wmi_unified_unregister_event_handler(wmi_handle,
91*5113495bSYour Name wmi_twt_enable_complete_event_id);
92*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
93*5113495bSYour Name target_if_err("Failed to deregister twt enable event cb");
94*5113495bSYour Name if (status == QDF_STATUS_E_NOSUPPORT)
95*5113495bSYour Name status = QDF_STATUS_SUCCESS;
96*5113495bSYour Name return status;
97*5113495bSYour Name }
98*5113495bSYour Name
99*5113495bSYour Name status = wmi_unified_unregister_event_handler(wmi_handle,
100*5113495bSYour Name wmi_twt_disable_complete_event_id);
101*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
102*5113495bSYour Name target_if_err("Failed to deregister twt disable event cb");
103*5113495bSYour Name if (status == QDF_STATUS_E_NOSUPPORT)
104*5113495bSYour Name status = QDF_STATUS_SUCCESS;
105*5113495bSYour Name return status;
106*5113495bSYour Name }
107*5113495bSYour Name
108*5113495bSYour Name status = target_if_twt_deregister_ext_events(psoc);
109*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
110*5113495bSYour Name target_if_err("Failed to deregister twt ext events");
111*5113495bSYour Name if (status == QDF_STATUS_E_NOSUPPORT)
112*5113495bSYour Name status = QDF_STATUS_SUCCESS;
113*5113495bSYour Name return status;
114*5113495bSYour Name }
115*5113495bSYour Name
116*5113495bSYour Name return status;
117*5113495bSYour Name }
118*5113495bSYour Name
119*5113495bSYour Name QDF_STATUS
target_if_twt_register_tx_ops(struct wlan_lmac_if_tx_ops * tx_ops)120*5113495bSYour Name target_if_twt_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
121*5113495bSYour Name {
122*5113495bSYour Name struct wlan_lmac_if_twt_tx_ops *twt_tx_ops;
123*5113495bSYour Name QDF_STATUS status;
124*5113495bSYour Name
125*5113495bSYour Name if (!tx_ops) {
126*5113495bSYour Name target_if_err("txops is NULL");
127*5113495bSYour Name return QDF_STATUS_E_FAILURE;
128*5113495bSYour Name }
129*5113495bSYour Name
130*5113495bSYour Name twt_tx_ops = &tx_ops->twt_tx_ops;
131*5113495bSYour Name twt_tx_ops->enable_req = target_if_twt_enable_req;
132*5113495bSYour Name twt_tx_ops->disable_req = target_if_twt_disable_req;
133*5113495bSYour Name twt_tx_ops->register_events = target_if_twt_register_events;
134*5113495bSYour Name twt_tx_ops->deregister_events = target_if_twt_deregister_events;
135*5113495bSYour Name
136*5113495bSYour Name status = target_if_twt_register_ext_tx_ops(twt_tx_ops);
137*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
138*5113495bSYour Name target_if_err("Failed to register twt ext tx ops");
139*5113495bSYour Name return status;
140*5113495bSYour Name }
141*5113495bSYour Name
142*5113495bSYour Name return status;
143*5113495bSYour Name }
144*5113495bSYour Name
145*5113495bSYour Name QDF_STATUS
target_if_twt_set_twt_ack_support(struct wlan_objmgr_psoc * psoc,bool val)146*5113495bSYour Name target_if_twt_set_twt_ack_support(struct wlan_objmgr_psoc *psoc,
147*5113495bSYour Name bool val)
148*5113495bSYour Name {
149*5113495bSYour Name struct twt_psoc_priv_obj *twt_psoc =
150*5113495bSYour Name wlan_objmgr_psoc_get_comp_private_obj(psoc, WLAN_UMAC_COMP_TWT);
151*5113495bSYour Name if (!twt_psoc) {
152*5113495bSYour Name target_if_err("null twt psoc priv obj");
153*5113495bSYour Name return QDF_STATUS_E_FAILURE;
154*5113495bSYour Name }
155*5113495bSYour Name
156*5113495bSYour Name twt_psoc->twt_caps.twt_ack_supported = val;
157*5113495bSYour Name return QDF_STATUS_SUCCESS;
158*5113495bSYour Name }
159*5113495bSYour Name
160*5113495bSYour Name QDF_STATUS
target_if_twt_fill_tgt_caps(struct wlan_objmgr_psoc * psoc,wmi_unified_t wmi_handle)161*5113495bSYour Name target_if_twt_fill_tgt_caps(struct wlan_objmgr_psoc *psoc,
162*5113495bSYour Name wmi_unified_t wmi_handle)
163*5113495bSYour Name {
164*5113495bSYour Name struct twt_psoc_priv_obj *twt_psoc;
165*5113495bSYour Name struct twt_tgt_caps *caps = NULL;
166*5113495bSYour Name
167*5113495bSYour Name if (!psoc || !wmi_handle) {
168*5113495bSYour Name target_if_err("null wmi_handle or psoc");
169*5113495bSYour Name return QDF_STATUS_E_FAILURE;
170*5113495bSYour Name }
171*5113495bSYour Name
172*5113495bSYour Name twt_psoc = wlan_objmgr_psoc_get_comp_private_obj(psoc,
173*5113495bSYour Name WLAN_UMAC_COMP_TWT);
174*5113495bSYour Name if (!twt_psoc) {
175*5113495bSYour Name target_if_err("null twt psoc priv obj");
176*5113495bSYour Name return QDF_STATUS_E_FAILURE;
177*5113495bSYour Name }
178*5113495bSYour Name
179*5113495bSYour Name caps = &twt_psoc->twt_caps;
180*5113495bSYour Name
181*5113495bSYour Name if (wmi_service_enabled(wmi_handle, wmi_service_twt_requestor))
182*5113495bSYour Name caps->twt_requestor = true;
183*5113495bSYour Name else
184*5113495bSYour Name caps->twt_requestor = false;
185*5113495bSYour Name
186*5113495bSYour Name if (wmi_service_enabled(wmi_handle, wmi_service_twt_responder))
187*5113495bSYour Name caps->twt_responder = true;
188*5113495bSYour Name else
189*5113495bSYour Name caps->twt_responder = false;
190*5113495bSYour Name
191*5113495bSYour Name if (wmi_service_enabled(wmi_handle, wmi_service_bcast_twt_support))
192*5113495bSYour Name caps->legacy_bcast_twt_support = true;
193*5113495bSYour Name else
194*5113495bSYour Name caps->legacy_bcast_twt_support = false;
195*5113495bSYour Name
196*5113495bSYour Name if (wmi_service_enabled(wmi_handle, wmi_service_twt_bcast_req_support))
197*5113495bSYour Name caps->twt_bcast_req_support = true;
198*5113495bSYour Name else
199*5113495bSYour Name caps->twt_bcast_req_support = false;
200*5113495bSYour Name
201*5113495bSYour Name if (wmi_service_enabled(wmi_handle, wmi_service_twt_bcast_resp_support))
202*5113495bSYour Name caps->twt_bcast_res_support = true;
203*5113495bSYour Name else
204*5113495bSYour Name caps->twt_bcast_res_support = false;
205*5113495bSYour Name
206*5113495bSYour Name if (wmi_service_enabled(wmi_handle, wmi_service_twt_nudge))
207*5113495bSYour Name caps->twt_nudge_enabled = true;
208*5113495bSYour Name else
209*5113495bSYour Name caps->twt_nudge_enabled = false;
210*5113495bSYour Name
211*5113495bSYour Name if (wmi_service_enabled(wmi_handle, wmi_service_all_twt))
212*5113495bSYour Name caps->all_twt_enabled = true;
213*5113495bSYour Name else
214*5113495bSYour Name caps->all_twt_enabled = false;
215*5113495bSYour Name
216*5113495bSYour Name if (wmi_service_enabled(wmi_handle, wmi_service_twt_statistics))
217*5113495bSYour Name caps->twt_stats_enabled = true;
218*5113495bSYour Name else
219*5113495bSYour Name caps->twt_stats_enabled = false;
220*5113495bSYour Name
221*5113495bSYour Name if (wmi_service_enabled(wmi_handle, wmi_service_restricted_twt))
222*5113495bSYour Name caps->restricted_twt_support = true;
223*5113495bSYour Name else
224*5113495bSYour Name caps->restricted_twt_support = false;
225*5113495bSYour Name
226*5113495bSYour Name target_if_debug("req:%d res:%d legacy_bcast_twt_support:%d",
227*5113495bSYour Name caps->twt_requestor,
228*5113495bSYour Name caps->twt_responder,
229*5113495bSYour Name caps->legacy_bcast_twt_support);
230*5113495bSYour Name target_if_debug("twt_bcast_req_support:%d twt_bcast_res_support:%d",
231*5113495bSYour Name caps->twt_bcast_req_support,
232*5113495bSYour Name caps->twt_bcast_res_support);
233*5113495bSYour Name target_if_debug("nudge_enabled:%d all_twt_enabled:%d stats_enabled:%d",
234*5113495bSYour Name caps->twt_nudge_enabled,
235*5113495bSYour Name caps->all_twt_enabled,
236*5113495bSYour Name caps->twt_stats_enabled);
237*5113495bSYour Name target_if_debug("restricted_twt_support:%d",
238*5113495bSYour Name caps->restricted_twt_support);
239*5113495bSYour Name return QDF_STATUS_SUCCESS;
240*5113495bSYour Name }
241*5113495bSYour Name
242