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 OS_IF layer
19 */
20 #include <qdf_trace.h>
21 #include <spatial_reuse_ucfg_api.h>
22 #include <spatial_reuse_api.h>
23 #include <wlan_policy_mgr_api.h>
24
ucfg_spatial_reuse_register_cb(struct wlan_objmgr_psoc * psoc,sr_osif_event_cb cb)25 void ucfg_spatial_reuse_register_cb(struct wlan_objmgr_psoc *psoc,
26 sr_osif_event_cb cb)
27 {
28 wlan_sr_register_callback(psoc, cb);
29 }
30
ucfg_spatial_reuse_get_sr_config(struct wlan_objmgr_vdev * vdev,uint8_t * sr_ctrl,uint8_t * non_srg_max_pd_offset,bool * he_spr_enabled)31 void ucfg_spatial_reuse_get_sr_config(struct wlan_objmgr_vdev *vdev,
32 uint8_t *sr_ctrl,
33 uint8_t *non_srg_max_pd_offset,
34 bool *he_spr_enabled)
35 {
36 *sr_ctrl = wlan_vdev_mlme_get_sr_ctrl(vdev);
37 *non_srg_max_pd_offset = wlan_vdev_mlme_get_non_srg_pd_offset(vdev);
38 *he_spr_enabled = wlan_vdev_mlme_get_he_spr_enabled(vdev);
39 }
40
ucfg_spatial_reuse_set_sr_config(struct wlan_objmgr_vdev * vdev,uint8_t sr_ctrl,uint8_t non_srg_max_pd_offset)41 void ucfg_spatial_reuse_set_sr_config(struct wlan_objmgr_vdev *vdev,
42 uint8_t sr_ctrl,
43 uint8_t non_srg_max_pd_offset)
44 {
45 wlan_vdev_mlme_set_sr_ctrl(vdev, sr_ctrl);
46 wlan_vdev_mlme_set_non_srg_pd_offset(vdev, non_srg_max_pd_offset);
47 }
48
ucfg_spatial_reuse_is_sr_disabled_due_conc(struct wlan_objmgr_vdev * vdev)49 bool ucfg_spatial_reuse_is_sr_disabled_due_conc(struct wlan_objmgr_vdev *vdev)
50 {
51 return wlan_vdev_mlme_is_sr_disable_due_conc(vdev);
52 }
53
ucfg_spatial_reuse_set_sr_conc_stat(struct wlan_objmgr_vdev * vdev,bool sr_conc_disabled)54 void ucfg_spatial_reuse_set_sr_conc_stat(struct wlan_objmgr_vdev *vdev,
55 bool sr_conc_disabled)
56 {
57 wlan_vdev_mlme_set_sr_disable_due_conc(vdev, sr_conc_disabled);
58 }
59
ucfg_spatial_reuse_send_sr_config(struct wlan_objmgr_vdev * vdev,bool enable)60 void ucfg_spatial_reuse_send_sr_config(struct wlan_objmgr_vdev *vdev,
61 bool enable)
62 {
63 uint8_t sr_ctrl = 0;
64 /* Disabled PD Threshold */
65 uint8_t non_srg_max_pd_offset = 0x80;
66
67 /* SR feature itself is disabled by user */
68 if (!wlan_vdev_mlme_get_he_spr_enabled(vdev))
69 return;
70 /* SR is disabled due to conccurrency */
71 if (ucfg_spatial_reuse_is_sr_disabled_due_conc(vdev))
72 return;
73
74 if (enable) {
75 sr_ctrl = wlan_vdev_mlme_get_sr_ctrl(vdev);
76 non_srg_max_pd_offset =
77 wlan_vdev_mlme_get_non_srg_pd_offset(vdev);
78 if (sr_ctrl && non_srg_max_pd_offset)
79 wlan_spatial_reuse_config_set(vdev, sr_ctrl,
80 non_srg_max_pd_offset);
81 } else {
82 wlan_spatial_reuse_config_set(vdev, sr_ctrl,
83 non_srg_max_pd_offset);
84 }
85 }
86
ucfg_spatial_reuse_set_sr_enable(struct wlan_objmgr_vdev * vdev,bool enable)87 void ucfg_spatial_reuse_set_sr_enable(struct wlan_objmgr_vdev *vdev,
88 bool enable)
89 {
90 wlan_vdev_mlme_set_he_spr_enabled(vdev, enable);
91 }
92
ucfg_spatial_reuse_send_sr_prohibit(struct wlan_objmgr_vdev * vdev,bool enable_he_siga_val15_prohibit)93 QDF_STATUS ucfg_spatial_reuse_send_sr_prohibit(
94 struct wlan_objmgr_vdev *vdev,
95 bool enable_he_siga_val15_prohibit)
96 {
97 QDF_STATUS status = QDF_STATUS_SUCCESS;
98 bool sr_enabled = wlan_vdev_mlme_get_he_spr_enabled(vdev);
99 bool sr_prohibited = wlan_vdev_mlme_is_sr_prohibit_en(vdev);
100 uint8_t sr_ctrl = wlan_vdev_mlme_get_sr_ctrl(vdev);
101
102 /* Enable PD prohibit only when it is allowed by the AP,
103 * Check if it is not enabled already, then only enable it
104 */
105 if (sr_enabled && (sr_ctrl & WLAN_HE_SIGA_SR_VAL15_ALLOWED) &&
106 sr_prohibited != enable_he_siga_val15_prohibit) {
107 status = wlan_spatial_reuse_he_siga_val15_allowed_set
108 (vdev,
109 enable_he_siga_val15_prohibit);
110
111 if (QDF_IS_STATUS_SUCCESS(status))
112 wlan_vdev_mlme_set_sr_prohibit_en
113 (vdev,
114 enable_he_siga_val15_prohibit);
115 } else {
116 mlme_debug("Prohibit command can not be sent sr_enabled %d, sr_ctrl %d , sr_prohibited %d",
117 sr_enabled,
118 sr_ctrl,
119 sr_prohibited);
120
121 return QDF_STATUS_E_FAILURE;
122 }
123 return status;
124 }
125
126 QDF_STATUS
ucfg_spatial_reuse_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)127 ucfg_spatial_reuse_setup_req(struct wlan_objmgr_vdev *vdev,
128 struct wlan_objmgr_pdev *pdev,
129 bool is_sr_enable, int32_t srg_pd_threshold,
130 int32_t non_srg_pd_threshold)
131 {
132 return wlan_sr_setup_req(vdev, pdev, is_sr_enable,
133 srg_pd_threshold, non_srg_pd_threshold);
134 }
135
ucfg_spatial_reuse_operation_allowed(struct wlan_objmgr_psoc * psoc,struct wlan_objmgr_vdev * vdev)136 QDF_STATUS ucfg_spatial_reuse_operation_allowed(struct wlan_objmgr_psoc *psoc,
137 struct wlan_objmgr_vdev *vdev)
138 {
139 uint32_t conc_vdev_id;
140 uint8_t vdev_id, mac_id;
141 QDF_STATUS status = QDF_STATUS_SUCCESS;
142
143 if (!vdev || !psoc)
144 return QDF_STATUS_E_NULL_VALUE;
145
146 vdev_id = wlan_vdev_get_id(vdev);
147 if (!policy_mgr_get_connection_count(psoc)) {
148 mlme_debug("No active vdev");
149 return status;
150 }
151 status = policy_mgr_get_mac_id_by_session_id(psoc, vdev_id, &mac_id);
152 if (QDF_IS_STATUS_ERROR(status))
153 return status;
154 conc_vdev_id = policy_mgr_get_conc_vdev_on_same_mac(psoc, vdev_id,
155 mac_id);
156 if (conc_vdev_id != WLAN_INVALID_VDEV_ID &&
157 !policy_mgr_sr_same_mac_conc_enabled(psoc))
158 return QDF_STATUS_E_NOSUPPORT;
159 return status;
160 }
161