xref: /wlan-driver/qca-wifi-host-cmn/target_if/spatial_reuse/src/target_if_spatial_reuse.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
3*5113495bSYour Name  *
4*5113495bSYour Name  *
5*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for
6*5113495bSYour Name  * any purpose with or without fee is hereby granted, provided that the
7*5113495bSYour Name  * above copyright notice and this permission notice appear in all
8*5113495bSYour Name  * copies.
9*5113495bSYour Name  *
10*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11*5113495bSYour Name  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12*5113495bSYour Name  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13*5113495bSYour Name  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14*5113495bSYour Name  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15*5113495bSYour Name  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16*5113495bSYour Name  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17*5113495bSYour Name  * PERFORMANCE OF THIS SOFTWARE.
18*5113495bSYour Name  */
19*5113495bSYour Name #include <target_if_spatial_reuse.h>
20*5113495bSYour Name #include <wlan_lmac_if_def.h>
21*5113495bSYour Name #include <wmi_unified_api.h>
22*5113495bSYour Name #include <wmi_unified_vdev_api.h>
23*5113495bSYour Name #include <target_if_vdev_mgr_tx_ops.h>
24*5113495bSYour Name #include <init_deinit_lmac.h>
25*5113495bSYour Name #include <wlan_vdev_mlme_api.h>
26*5113495bSYour Name 
spatial_reuse_send_cfg(struct wlan_objmgr_vdev * vdev,uint8_t sr_ctrl,uint8_t non_srg_max_pd_offset)27*5113495bSYour Name static QDF_STATUS spatial_reuse_send_cfg(struct wlan_objmgr_vdev *vdev,
28*5113495bSYour Name 					 uint8_t sr_ctrl,
29*5113495bSYour Name 					 uint8_t non_srg_max_pd_offset)
30*5113495bSYour Name {
31*5113495bSYour Name 	struct pdev_params pparam;
32*5113495bSYour Name 	wmi_unified_t wmi_handle;
33*5113495bSYour Name 
34*5113495bSYour Name 	wmi_handle = target_if_vdev_mgr_wmi_handle_get(vdev);
35*5113495bSYour Name 	if (!wmi_handle) {
36*5113495bSYour Name 		mlme_err("Failed to get WMI handle!");
37*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
38*5113495bSYour Name 	}
39*5113495bSYour Name 
40*5113495bSYour Name 	qdf_mem_zero(&pparam, sizeof(pparam));
41*5113495bSYour Name 	pparam.param_id = WMI_PDEV_PARAM_SET_CMD_OBSS_PD_THRESHOLD;
42*5113495bSYour Name 	if (!(sr_ctrl & NON_SRG_PD_SR_DISALLOWED) &&
43*5113495bSYour Name 	    (sr_ctrl & NON_SRG_OFFSET_PRESENT)) {
44*5113495bSYour Name 		QDF_SET_BITS(pparam.param_value, NON_SRG_SPR_ENABLE_POS,
45*5113495bSYour Name 			     NON_SRG_SPR_ENABLE_SIZE, NON_SRG_SPR_ENABLE);
46*5113495bSYour Name 		QDF_SET_BITS(pparam.param_value, SR_PARAM_VAL_DBM_POS,
47*5113495bSYour Name 			     NON_SRG_PARAM_VAL_DBM_SIZE,
48*5113495bSYour Name 			     SR_PARAM_VAL_DBM_UNIT);
49*5113495bSYour Name 		QDF_SET_BITS(pparam.param_value, NON_SRG_MAX_PD_OFFSET_POS,
50*5113495bSYour Name 			     NON_SRG_MAX_PD_OFFSET_SIZE,
51*5113495bSYour Name 			     non_srg_max_pd_offset);
52*5113495bSYour Name 	}
53*5113495bSYour Name 
54*5113495bSYour Name 	return wmi_unified_pdev_param_send(wmi_handle, &pparam,
55*5113495bSYour Name 					   WILDCARD_PDEV_ID);
56*5113495bSYour Name }
57*5113495bSYour Name 
58*5113495bSYour Name static QDF_STATUS
spatial_reuse_send_sr_prohibit_cfg(struct wlan_objmgr_vdev * vdev,bool he_siga_va15_allowed)59*5113495bSYour Name spatial_reuse_send_sr_prohibit_cfg(struct wlan_objmgr_vdev *vdev,
60*5113495bSYour Name 				   bool he_siga_va15_allowed)
61*5113495bSYour Name {
62*5113495bSYour Name 	struct sr_prohibit_param srp_param;
63*5113495bSYour Name 	wmi_unified_t wmi_handle;
64*5113495bSYour Name 
65*5113495bSYour Name 	wmi_handle = target_if_vdev_mgr_wmi_handle_get(vdev);
66*5113495bSYour Name 	if (!wmi_handle) {
67*5113495bSYour Name 		mlme_err("Failed to get WMI handle!");
68*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
69*5113495bSYour Name 	}
70*5113495bSYour Name 
71*5113495bSYour Name 	srp_param.vdev_id = wlan_vdev_get_id(vdev);
72*5113495bSYour Name 	srp_param.sr_he_siga_val15_allowed = he_siga_va15_allowed;
73*5113495bSYour Name 
74*5113495bSYour Name 	return wmi_unified_vdev_param_sr_prohibit_send(wmi_handle, &srp_param);
75*5113495bSYour Name }
76*5113495bSYour Name 
77*5113495bSYour Name #ifdef OBSS_PD
78*5113495bSYour Name static QDF_STATUS
spatial_reuse_send_bss_color_bit_map(struct wlan_objmgr_vdev * vdev,struct wlan_objmgr_pdev * pdev)79*5113495bSYour Name spatial_reuse_send_bss_color_bit_map(struct wlan_objmgr_vdev *vdev,
80*5113495bSYour Name 				     struct wlan_objmgr_pdev *pdev)
81*5113495bSYour Name {
82*5113495bSYour Name 	uint64_t srg_color_bit_map = 0;
83*5113495bSYour Name 	uint32_t bit_map_0 = 0;
84*5113495bSYour Name 	uint32_t bit_map_1 = 0;
85*5113495bSYour Name 	struct wmi_unified *wmi_handle;
86*5113495bSYour Name 	QDF_STATUS status = QDF_STATUS_SUCCESS;
87*5113495bSYour Name 
88*5113495bSYour Name 	wmi_handle = lmac_get_pdev_wmi_handle(pdev);
89*5113495bSYour Name 	if (!wmi_handle)
90*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
91*5113495bSYour Name 
92*5113495bSYour Name 	wlan_vdev_obj_lock(vdev);
93*5113495bSYour Name 	wlan_vdev_mlme_get_srg_bss_color_bit_map(vdev, &srg_color_bit_map);
94*5113495bSYour Name 	wlan_vdev_obj_unlock(vdev);
95*5113495bSYour Name 	bit_map_0 = (uint32_t) srg_color_bit_map;
96*5113495bSYour Name 	bit_map_1 = (uint32_t) (srg_color_bit_map >> 32);
97*5113495bSYour Name 
98*5113495bSYour Name 	status = wmi_unified_send_self_srg_bss_color_bitmap_set_cmd(
99*5113495bSYour Name 					wmi_handle, bit_map_0, bit_map_1,
100*5113495bSYour Name 					pdev->pdev_objmgr.wlan_pdev_id);
101*5113495bSYour Name 	return status;
102*5113495bSYour Name }
103*5113495bSYour Name 
104*5113495bSYour Name static QDF_STATUS
spatial_reuse_send_partial_bssid_bit_map(struct wlan_objmgr_vdev * vdev,struct wlan_objmgr_pdev * pdev)105*5113495bSYour Name spatial_reuse_send_partial_bssid_bit_map(struct wlan_objmgr_vdev *vdev,
106*5113495bSYour Name 					 struct wlan_objmgr_pdev *pdev)
107*5113495bSYour Name {
108*5113495bSYour Name 	uint64_t partial_bssid_bit_map = 0;
109*5113495bSYour Name 	uint32_t bit_map_0 = 0;
110*5113495bSYour Name 	uint32_t bit_map_1 = 0;
111*5113495bSYour Name 	struct wmi_unified *wmi_handle;
112*5113495bSYour Name 	QDF_STATUS status = QDF_STATUS_SUCCESS;
113*5113495bSYour Name 
114*5113495bSYour Name 	wmi_handle = lmac_get_pdev_wmi_handle(pdev);
115*5113495bSYour Name 	if (!wmi_handle)
116*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
117*5113495bSYour Name 
118*5113495bSYour Name 	wlan_vdev_obj_lock(vdev);
119*5113495bSYour Name 	wlan_vdev_mlme_get_srg_partial_bssid_bit_map(vdev,
120*5113495bSYour Name 						     &partial_bssid_bit_map);
121*5113495bSYour Name 	wlan_vdev_obj_unlock(vdev);
122*5113495bSYour Name 	bit_map_0 = (uint32_t) partial_bssid_bit_map;
123*5113495bSYour Name 	bit_map_1 = (uint32_t) (partial_bssid_bit_map >> 32);
124*5113495bSYour Name 
125*5113495bSYour Name 	status = wmi_unified_send_self_srg_partial_bssid_bitmap_set_cmd(
126*5113495bSYour Name 					wmi_handle, bit_map_0, bit_map_1,
127*5113495bSYour Name 					pdev->pdev_objmgr.wlan_pdev_id);
128*5113495bSYour Name 	return status;
129*5113495bSYour Name }
130*5113495bSYour Name #else
131*5113495bSYour Name static QDF_STATUS
spatial_reuse_send_bss_color_bit_map(struct wlan_objmgr_vdev * vdev,struct wlan_objmgr_pdev * pdev)132*5113495bSYour Name spatial_reuse_send_bss_color_bit_map(struct wlan_objmgr_vdev *vdev,
133*5113495bSYour Name 				     struct wlan_objmgr_pdev *pdev)
134*5113495bSYour Name {
135*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
136*5113495bSYour Name }
137*5113495bSYour Name 
138*5113495bSYour Name static QDF_STATUS
spatial_reuse_send_partial_bssid_bit_map(struct wlan_objmgr_vdev * vdev,struct wlan_objmgr_pdev * pdev)139*5113495bSYour Name spatial_reuse_send_partial_bssid_bit_map(struct wlan_objmgr_vdev *vdev,
140*5113495bSYour Name 					 struct wlan_objmgr_pdev *pdev)
141*5113495bSYour Name {
142*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
143*5113495bSYour Name }
144*5113495bSYour Name #endif
145*5113495bSYour Name 
146*5113495bSYour Name static QDF_STATUS
spatial_reuse_send_pd_threshold(struct wlan_objmgr_pdev * pdev,uint8_t vdev_id,uint32_t val)147*5113495bSYour Name spatial_reuse_send_pd_threshold(struct wlan_objmgr_pdev *pdev,
148*5113495bSYour Name 				uint8_t vdev_id,
149*5113495bSYour Name 				uint32_t val)
150*5113495bSYour Name {
151*5113495bSYour Name 	struct vdev_set_params vdev_param;
152*5113495bSYour Name 	struct wmi_unified *wmi_handle;
153*5113495bSYour Name 	bool sr_supported;
154*5113495bSYour Name 
155*5113495bSYour Name 	wmi_handle = lmac_get_pdev_wmi_handle(pdev);
156*5113495bSYour Name 	if (!wmi_handle)
157*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
158*5113495bSYour Name 
159*5113495bSYour Name 	sr_supported =
160*5113495bSYour Name 		wmi_service_enabled(wmi_handle,
161*5113495bSYour Name 				    wmi_service_srg_srp_spatial_reuse_support);
162*5113495bSYour Name 
163*5113495bSYour Name 	if (sr_supported) {
164*5113495bSYour Name 		qdf_mem_zero(&vdev_param, sizeof(vdev_param));
165*5113495bSYour Name 		vdev_param.vdev_id = vdev_id;
166*5113495bSYour Name 		vdev_param.param_id = wmi_vdev_param_set_cmd_obss_pd_threshold;
167*5113495bSYour Name 		vdev_param.param_value = val;
168*5113495bSYour Name 		return wmi_unified_vdev_set_param_send(wmi_handle, &vdev_param);
169*5113495bSYour Name 	} else {
170*5113495bSYour Name 		mlme_debug("Target doesn't support SR operations");
171*5113495bSYour Name 	}
172*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
173*5113495bSYour Name }
174*5113495bSYour Name 
175*5113495bSYour Name /**
176*5113495bSYour Name  * spatial_reuse_set_sr_enable_disable: To send wmi command to enable/disable SR
177*5113495bSYour Name  * @vdev: object manager vdev
178*5113495bSYour Name  * @pdev: object manager pdev
179*5113495bSYour Name  * @is_sr_enable: sr enable/disable
180*5113495bSYour Name  * @srg_pd_threshold: SRG pd threshold
181*5113495bSYour Name  * @non_srg_pd_threshold: NON-SRG pd threshold
182*5113495bSYour Name  *
183*5113495bSYour Name  * Return: Success/Failure
184*5113495bSYour Name  */
185*5113495bSYour Name static QDF_STATUS
spatial_reuse_set_sr_enable_disable(struct wlan_objmgr_vdev * vdev,struct wlan_objmgr_pdev * pdev,bool is_sr_enable,int32_t srg_pd_threshold,int32_t non_srg_pd_threshold)186*5113495bSYour Name spatial_reuse_set_sr_enable_disable(struct wlan_objmgr_vdev *vdev,
187*5113495bSYour Name 				    struct wlan_objmgr_pdev *pdev,
188*5113495bSYour Name 				    bool is_sr_enable, int32_t srg_pd_threshold,
189*5113495bSYour Name 				    int32_t non_srg_pd_threshold)
190*5113495bSYour Name {
191*5113495bSYour Name 	uint32_t val = 0;
192*5113495bSYour Name 	struct wlan_objmgr_psoc *psoc;
193*5113495bSYour Name 	QDF_STATUS status = QDF_STATUS_SUCCESS;
194*5113495bSYour Name 
195*5113495bSYour Name 	psoc = wlan_pdev_get_psoc(pdev);
196*5113495bSYour Name 	if (!psoc)
197*5113495bSYour Name 		return QDF_STATUS_E_NOENT;
198*5113495bSYour Name 
199*5113495bSYour Name 	if (is_sr_enable) {
200*5113495bSYour Name 		wlan_mlme_update_sr_data(vdev, &val, srg_pd_threshold,
201*5113495bSYour Name 					 non_srg_pd_threshold,
202*5113495bSYour Name 					 is_sr_enable);
203*5113495bSYour Name 		wlan_vdev_obj_lock(vdev);
204*5113495bSYour Name 		wlan_vdev_mlme_set_he_spr_enabled(vdev, true);
205*5113495bSYour Name 		wlan_vdev_obj_unlock(vdev);
206*5113495bSYour Name 	} else {
207*5113495bSYour Name 		wlan_vdev_obj_lock(vdev);
208*5113495bSYour Name 		wlan_vdev_mlme_set_he_spr_enabled(vdev, false);
209*5113495bSYour Name 		wlan_vdev_obj_unlock(vdev);
210*5113495bSYour Name 	}
211*5113495bSYour Name 
212*5113495bSYour Name 	mlme_debug("srp param val: %x, enable: %d",
213*5113495bSYour Name 		   val, is_sr_enable);
214*5113495bSYour Name 	if (is_sr_enable) {
215*5113495bSYour Name 		status = spatial_reuse_send_bss_color_bit_map(vdev, pdev);
216*5113495bSYour Name 		if (status != QDF_STATUS_SUCCESS)
217*5113495bSYour Name 			return status;
218*5113495bSYour Name 		status = spatial_reuse_send_partial_bssid_bit_map(vdev, pdev);
219*5113495bSYour Name 		if (status != QDF_STATUS_SUCCESS)
220*5113495bSYour Name 			return status;
221*5113495bSYour Name 	}
222*5113495bSYour Name 	status = spatial_reuse_send_pd_threshold(pdev,
223*5113495bSYour Name 						 vdev->vdev_objmgr.vdev_id,
224*5113495bSYour Name 						 val);
225*5113495bSYour Name 	if (status != QDF_STATUS_SUCCESS)
226*5113495bSYour Name 		return status;
227*5113495bSYour Name 
228*5113495bSYour Name 	return status;
229*5113495bSYour Name }
230*5113495bSYour Name 
target_if_spatial_reuse_register_tx_ops(struct wlan_lmac_if_tx_ops * tx_ops)231*5113495bSYour Name void target_if_spatial_reuse_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
232*5113495bSYour Name {
233*5113495bSYour Name 	tx_ops->spatial_reuse_tx_ops.send_cfg = spatial_reuse_send_cfg;
234*5113495bSYour Name 	tx_ops->spatial_reuse_tx_ops.send_sr_prohibit_cfg =
235*5113495bSYour Name 					spatial_reuse_send_sr_prohibit_cfg;
236*5113495bSYour Name 	tx_ops->spatial_reuse_tx_ops.target_if_set_sr_enable_disable =
237*5113495bSYour Name 					spatial_reuse_set_sr_enable_disable;
238*5113495bSYour Name 	tx_ops->spatial_reuse_tx_ops.target_if_sr_update =
239*5113495bSYour Name 					spatial_reuse_send_pd_threshold;
240*5113495bSYour Name }
241