1 /*
2  * Copyright (c) 2022-2023 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: contains interface prototypes for spatial_reuse api
19  */
20 #include <spatial_reuse_api.h>
21 #include <target_if_spatial_reuse.h>
22 
23 struct sr_cb {
24 	sr_osif_event_cb send_osif_event;
25 } sr_cb;
26 
wlan_spatial_reuse_config_set(struct wlan_objmgr_vdev * vdev,uint8_t sr_ctrl,uint8_t non_srg_max_pd_offset)27 QDF_STATUS wlan_spatial_reuse_config_set(struct wlan_objmgr_vdev *vdev,
28 					 uint8_t sr_ctrl,
29 					 uint8_t non_srg_max_pd_offset)
30 {
31 	struct wlan_lmac_if_tx_ops *tx_ops;
32 	struct wlan_objmgr_psoc *psoc = wlan_vdev_get_psoc(vdev);
33 
34 	if (!psoc)
35 		return QDF_STATUS_E_NULL_VALUE;
36 
37 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
38 	if (!tx_ops)
39 		return QDF_STATUS_E_NULL_VALUE;
40 
41 	if (tx_ops->spatial_reuse_tx_ops.send_cfg)
42 		return tx_ops->spatial_reuse_tx_ops.send_cfg(vdev, sr_ctrl,
43 							non_srg_max_pd_offset);
44 
45 	return QDF_STATUS_E_NULL_VALUE;
46 }
47 
wlan_spatial_reuse_he_siga_val15_allowed_set(struct wlan_objmgr_vdev * vdev,bool he_siga_va15_allowed)48 QDF_STATUS wlan_spatial_reuse_he_siga_val15_allowed_set(
49 					struct wlan_objmgr_vdev *vdev,
50 					bool he_siga_va15_allowed)
51 {
52 	struct wlan_lmac_if_tx_ops *tx_ops;
53 	struct wlan_objmgr_psoc *psoc = wlan_vdev_get_psoc(vdev);
54 
55 	if (!psoc)
56 		return QDF_STATUS_E_NULL_VALUE;
57 
58 	tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
59 	if (!tx_ops)
60 		return QDF_STATUS_E_NULL_VALUE;
61 
62 	if (tx_ops->spatial_reuse_tx_ops.send_sr_prohibit_cfg)
63 		return tx_ops->spatial_reuse_tx_ops.send_sr_prohibit_cfg(
64 							vdev,
65 							he_siga_va15_allowed);
66 	return QDF_STATUS_E_NULL_VALUE;
67 }
68 
69 QDF_STATUS
wlan_sr_setup_req(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)70 wlan_sr_setup_req(struct wlan_objmgr_vdev *vdev, struct wlan_objmgr_pdev *pdev,
71 		  bool is_sr_enable, int32_t srg_pd_threshold,
72 		  int32_t non_srg_pd_threshold) {
73 	struct wlan_lmac_if_tx_ops *tx_ops;
74 	QDF_STATUS status = QDF_STATUS_E_FAILURE;
75 
76 	tx_ops = wlan_psoc_get_lmac_if_txops(wlan_pdev_get_psoc(pdev));
77 	if (tx_ops &&
78 	    tx_ops->spatial_reuse_tx_ops.target_if_set_sr_enable_disable) {
79 		status =
80 		tx_ops->spatial_reuse_tx_ops.target_if_set_sr_enable_disable(
81 					vdev, pdev, is_sr_enable,
82 					srg_pd_threshold, non_srg_pd_threshold);
83 		return status;
84 	}
85 	return status;
86 }
87 
wlan_sr_register_callback(struct wlan_objmgr_psoc * psoc,sr_osif_event_cb cb)88 void wlan_sr_register_callback(struct wlan_objmgr_psoc *psoc,
89 			       sr_osif_event_cb cb)
90 {
91 	if (!psoc)
92 		return;
93 	sr_cb.send_osif_event = cb;
94 }
95 
wlan_spatial_reuse_osif_event(struct wlan_objmgr_vdev * vdev,enum sr_osif_operation sr_osif_oper,enum sr_osif_reason_code sr_osif_rc)96 void wlan_spatial_reuse_osif_event(struct wlan_objmgr_vdev *vdev,
97 				   enum sr_osif_operation sr_osif_oper,
98 				   enum sr_osif_reason_code sr_osif_rc)
99 {
100 	if (sr_cb.send_osif_event)
101 		sr_cb.send_osif_event(vdev, sr_osif_oper, sr_osif_rc);
102 }
103