xref: /wlan-dirver/qca-wifi-host-cmn/umac/green_ap/dispatcher/src/wlan_green_ap_ucfg_api.c (revision dd4dc88b837a295134aa9869114a2efee0f4894b)
1 /*
2  * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: This file contains green ap north bound interface definitions
21  */
22 
23 #include <qdf_status.h>
24 #include <wlan_green_ap_ucfg_api.h>
25 #include <../../core/src/wlan_green_ap_main_i.h>
26 
27 QDF_STATUS ucfg_green_ap_enable_egap(struct wlan_objmgr_pdev *pdev)
28 {
29 	struct wlan_pdev_green_ap_ctx *green_ap_ctx;
30 	struct wlan_lmac_if_green_ap_tx_ops *green_ap_tx_ops;
31 
32 	if (!pdev) {
33 		green_ap_err("pdev context passed is NULL");
34 		return QDF_STATUS_E_INVAL;
35 	}
36 
37 	green_ap_ctx = wlan_objmgr_pdev_get_comp_private_obj(
38 			pdev, WLAN_UMAC_COMP_GREEN_AP);
39 	if (!green_ap_ctx) {
40 		green_ap_err("green ap context obtained is NULL");
41 		return QDF_STATUS_E_FAILURE;
42 	}
43 
44 	green_ap_tx_ops = wlan_psoc_get_green_ap_tx_ops(green_ap_ctx);
45 	if (!green_ap_tx_ops) {
46 		green_ap_err("green ap tx ops obtained are NULL");
47 		return  QDF_STATUS_E_FAILURE;
48 	}
49 
50 	if (!green_ap_tx_ops->enable_egap) {
51 		green_ap_err("tx op for sending enbale/disable green ap is NULL");
52 		return QDF_STATUS_E_FAILURE;
53 	}
54 
55 	return green_ap_tx_ops->enable_egap(pdev, &green_ap_ctx->egap_params);
56 }
57 
58 QDF_STATUS ucfg_green_ap_set_ps_config(struct wlan_objmgr_pdev *pdev,
59 				       uint8_t value)
60 {
61 	struct wlan_pdev_green_ap_ctx *green_ap_ctx;
62 
63 	if (!pdev) {
64 		green_ap_err("pdev context passed is NULL");
65 		return QDF_STATUS_E_INVAL;
66 	}
67 
68 	green_ap_ctx = wlan_objmgr_pdev_get_comp_private_obj(
69 			pdev, WLAN_UMAC_COMP_GREEN_AP);
70 	if (!green_ap_ctx) {
71 		green_ap_err("green ap context obtained is NULL");
72 		return QDF_STATUS_E_FAILURE;
73 	}
74 
75 	qdf_spin_lock_bh(&green_ap_ctx->lock);
76 	if (wlan_is_egap_enabled(green_ap_ctx)) {
77 		qdf_spin_unlock_bh(&green_ap_ctx->lock);
78 		return QDF_STATUS_SUCCESS;
79 	}
80 
81 	green_ap_ctx->ps_enable = value;
82 	if (value == WLAN_GREEN_AP_MODE_NUM_STREAM)
83 		green_ap_ctx->ps_mode = WLAN_GREEN_AP_MODE_NUM_STREAM;
84 	else
85 		green_ap_ctx->ps_mode = WLAN_GREEN_AP_MODE_NO_STA;
86 
87 	qdf_spin_unlock_bh(&green_ap_ctx->lock);
88 
89 	return QDF_STATUS_SUCCESS;
90 }
91 
92 QDF_STATUS ucfg_green_ap_get_ps_config(struct wlan_objmgr_pdev *pdev,
93 				       uint8_t *ps_enable)
94 {
95 	struct wlan_pdev_green_ap_ctx *green_ap_ctx;
96 
97 	if (!pdev) {
98 		green_ap_err("pdev context passed is NULL");
99 		return QDF_STATUS_E_INVAL;
100 	}
101 
102 	green_ap_ctx = wlan_objmgr_pdev_get_comp_private_obj(
103 				pdev, WLAN_UMAC_COMP_GREEN_AP);
104 
105 	if (!green_ap_ctx) {
106 		green_ap_err("green ap context obtained is NULL");
107 		return QDF_STATUS_E_FAILURE;
108 	}
109 
110 	qdf_spin_lock_bh(&green_ap_ctx->lock);
111 	if (wlan_is_egap_enabled(green_ap_ctx)) {
112 		qdf_spin_unlock_bh(&green_ap_ctx->lock);
113 		return QDF_STATUS_SUCCESS;
114 	}
115 
116 	*ps_enable = green_ap_ctx->ps_enable;
117 	qdf_spin_unlock_bh(&green_ap_ctx->lock);
118 
119 	return QDF_STATUS_SUCCESS;
120 }
121 
122 QDF_STATUS ucfg_green_ap_set_transition_time(struct wlan_objmgr_pdev *pdev,
123 					     uint32_t val)
124 {
125 	struct wlan_pdev_green_ap_ctx *green_ap_ctx;
126 
127 	if (!pdev) {
128 		green_ap_err("pdev context passed is NULL");
129 		return QDF_STATUS_E_INVAL;
130 	}
131 
132 	green_ap_ctx = wlan_objmgr_pdev_get_comp_private_obj(
133 			pdev, WLAN_UMAC_COMP_GREEN_AP);
134 
135 	if (!green_ap_ctx) {
136 		green_ap_err("green ap context obtained is NULL");
137 		return QDF_STATUS_E_FAILURE;
138 	}
139 
140 	qdf_spin_lock_bh(&green_ap_ctx->lock);
141 	if (wlan_is_egap_enabled(green_ap_ctx)) {
142 		qdf_spin_unlock_bh(&green_ap_ctx->lock);
143 		return QDF_STATUS_SUCCESS;
144 	}
145 
146 	green_ap_ctx->ps_trans_time = val;
147 	qdf_spin_unlock_bh(&green_ap_ctx->lock);
148 
149 	return QDF_STATUS_SUCCESS;
150 }
151 
152 QDF_STATUS ucfg_green_ap_get_transition_time(struct wlan_objmgr_pdev *pdev,
153 					     uint32_t *ps_trans_time)
154 {
155 	struct wlan_pdev_green_ap_ctx *green_ap_ctx;
156 
157 	if (!pdev) {
158 		green_ap_err("pdev context passed is NULL");
159 		return QDF_STATUS_E_INVAL;
160 	}
161 
162 	green_ap_ctx = wlan_objmgr_pdev_get_comp_private_obj(
163 			pdev, WLAN_UMAC_COMP_GREEN_AP);
164 
165 	if (!green_ap_ctx) {
166 		green_ap_err("green ap context obtained is NULL");
167 		return QDF_STATUS_E_FAILURE;
168 	}
169 
170 	qdf_spin_lock_bh(&green_ap_ctx->lock);
171 	if (wlan_is_egap_enabled(green_ap_ctx)) {
172 		qdf_spin_unlock_bh(&green_ap_ctx->lock);
173 		return QDF_STATUS_SUCCESS;
174 	}
175 
176 	*ps_trans_time = green_ap_ctx->ps_trans_time;
177 	qdf_spin_unlock_bh(&green_ap_ctx->lock);
178 
179 	return QDF_STATUS_SUCCESS;
180 }
181 
182 QDF_STATUS ucfg_green_ap_config(struct wlan_objmgr_pdev *pdev, uint8_t val)
183 {
184 
185 	uint8_t flag;
186 
187 	if (wlan_green_ap_get_capab(pdev) == QDF_STATUS_E_NOSUPPORT) {
188 		green_ap_err("GreenAP not supported on radio\n");
189 		return QDF_STATUS_E_NOSUPPORT;
190 	}
191 
192 	if (val) {
193 		struct wlan_pdev_green_ap_ctx *green_ap_ctx;
194 
195 		wlan_objmgr_pdev_iterate_obj_list(pdev,
196 					WLAN_VDEV_OP,
197 					wlan_green_ap_check_mode,
198 					&flag, 0, WLAN_GREEN_AP_ID);
199 		if (flag == 1) {
200 			green_ap_err("Radio not in AP mode."
201 					"Feature not supported");
202 			return QDF_STATUS_E_NOSUPPORT;
203 		}
204 
205 		green_ap_ctx = wlan_objmgr_pdev_get_comp_private_obj(pdev,
206 					WLAN_UMAC_COMP_GREEN_AP);
207 
208 		if (!green_ap_ctx) {
209 			green_ap_err("green ap context obtained is NULL");
210 			return QDF_STATUS_E_NOSUPPORT;
211 		}
212 
213 		ucfg_green_ap_set_ps_config(pdev, val);
214 
215 		if (wlan_util_is_vdev_active(pdev, WLAN_GREEN_AP_ID) ==
216 					    QDF_STATUS_SUCCESS)
217 			wlan_green_ap_start(pdev);
218 	} else {
219 		wlan_green_ap_stop(pdev);
220 	}
221 
222 	return QDF_STATUS_SUCCESS;
223 }
224 
225 void ucfg_green_ap_enable_debug_prints(struct wlan_objmgr_pdev *pdev,
226 				uint32_t val)
227 {
228 	struct wlan_pdev_green_ap_ctx *green_ap_ctx;
229 
230 	green_ap_ctx = wlan_objmgr_pdev_get_comp_private_obj(
231 			pdev, WLAN_UMAC_COMP_GREEN_AP);
232 
233 	if (!green_ap_ctx) {
234 		green_ap_err("green ap context obtained is NULL");
235 		return;
236 	}
237 
238 	green_ap_ctx->dbg_enable = val;
239 }
240 
241 bool ucfg_green_ap_get_debug_prints(struct wlan_objmgr_pdev *pdev)
242 {
243 	struct wlan_pdev_green_ap_ctx *green_ap_ctx;
244 
245 	green_ap_ctx = wlan_objmgr_pdev_get_comp_private_obj(
246 			pdev, WLAN_UMAC_COMP_GREEN_AP);
247 
248 	if (!green_ap_ctx) {
249 		green_ap_err("green ap context obtained is NULL");
250 		return false;
251 	}
252 
253 	return green_ap_ctx->dbg_enable;
254 }
255 
256