xref: /wlan-dirver/qca-wifi-host-cmn/wmi/src/wmi_unified_concurrency_tlv.c (revision 1397a33f48ea6455be40871470b286e535820eb8)
1 /*
2  * Copyright (c) 2013-2018 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 #include <osdep.h>
20 #include <wmi.h>
21 #include <wmi_unified_priv.h>
22 #include <wmi_unified_concurrency_api.h>
23 
24 /**
25  * send_set_enable_disable_mcc_adaptive_scheduler_cmd_tlv() -enable/disable
26  *							     mcc scheduler
27  * @wmi_handle: wmi handle
28  * @mcc_adaptive_scheduler: enable/disable
29  *
30  * This function enable/disable mcc adaptive scheduler in fw.
31  *
32  * Return: QDF_STATUS_SUCCESS for success or error code
33  */
34 static QDF_STATUS send_set_enable_disable_mcc_adaptive_scheduler_cmd_tlv(
35 		wmi_unified_t wmi_handle, uint32_t mcc_adaptive_scheduler,
36 		uint32_t pdev_id)
37 {
38 	QDF_STATUS ret;
39 	wmi_buf_t buf = 0;
40 	wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param *cmd = NULL;
41 	uint16_t len =
42 		sizeof(wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param);
43 
44 	buf = wmi_buf_alloc(wmi_handle, len);
45 	if (!buf) {
46 		return QDF_STATUS_E_NOMEM;
47 	}
48 	cmd = (wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param *)
49 		wmi_buf_data(buf);
50 
51 	WMITLV_SET_HDR(&cmd->tlv_header,
52 		       WMITLV_TAG_STRUC_wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param,
53 		       WMITLV_GET_STRUCT_TLVLEN
54 			       (wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param));
55 	cmd->enable = mcc_adaptive_scheduler;
56 	cmd->pdev_id = wmi_handle->ops->convert_pdev_id_host_to_target(pdev_id);
57 
58 	wmi_mtrace(WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID, NO_SESSION, 0);
59 	ret = wmi_unified_cmd_send(wmi_handle, buf, len,
60 				   WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID);
61 	if (QDF_IS_STATUS_ERROR(ret)) {
62 		WMI_LOGP("%s: Failed to send enable/disable MCC"
63 			 " adaptive scheduler command", __func__);
64 		wmi_buf_free(buf);
65 	}
66 
67 	return ret;
68 }
69 
70 /**
71  * send_set_mcc_channel_time_latency_cmd_tlv() -set MCC channel time latency
72  * @wmi: wmi handle
73  * @mcc_channel: mcc channel
74  * @mcc_channel_time_latency: MCC channel time latency.
75  *
76  * Currently used to set time latency for an MCC vdev/adapter using operating
77  * channel of it and channel number. The info is provided run time using
78  * iwpriv command: iwpriv <wlan0 | p2p0> setMccLatency <latency in ms>.
79  *
80  * Return: CDF status
81  */
82 static QDF_STATUS send_set_mcc_channel_time_latency_cmd_tlv(
83 					wmi_unified_t wmi_handle,
84 					uint32_t mcc_channel_freq,
85 					uint32_t mcc_channel_time_latency)
86 {
87 	QDF_STATUS ret;
88 	wmi_buf_t buf = 0;
89 	wmi_resmgr_set_chan_latency_cmd_fixed_param *cmdTL = NULL;
90 	uint16_t len = 0;
91 	uint8_t *buf_ptr = NULL;
92 	wmi_resmgr_chan_latency chan_latency;
93 	/* Note: we only support MCC time latency for a single channel */
94 	uint32_t num_channels = 1;
95 	uint32_t chan1_freq = mcc_channel_freq;
96 	uint32_t latency_chan1 = mcc_channel_time_latency;
97 
98 	/* If 0ms latency is provided, then FW will set to a default.
99 	 * Otherwise, latency must be at least 30ms.
100 	 */
101 	if ((latency_chan1 > 0) &&
102 	    (latency_chan1 < WMI_MCC_MIN_NON_ZERO_CHANNEL_LATENCY)) {
103 		WMI_LOGE("%s: Invalid time latency for Channel #1 = %dms "
104 			 "Minimum is 30ms (or 0 to use default value by "
105 			 "firmware)", __func__, latency_chan1);
106 		return QDF_STATUS_E_INVAL;
107 	}
108 
109 	/*   Set WMI CMD for channel time latency here */
110 	len = sizeof(wmi_resmgr_set_chan_latency_cmd_fixed_param) +
111 	      WMI_TLV_HDR_SIZE +  /*Place holder for chan_time_latency array */
112 	      num_channels * sizeof(wmi_resmgr_chan_latency);
113 	buf = wmi_buf_alloc(wmi_handle, len);
114 	if (!buf) {
115 		return QDF_STATUS_E_NOMEM;
116 	}
117 	buf_ptr = (uint8_t *) wmi_buf_data(buf);
118 	cmdTL = (wmi_resmgr_set_chan_latency_cmd_fixed_param *)
119 		wmi_buf_data(buf);
120 	WMITLV_SET_HDR(&cmdTL->tlv_header,
121 		WMITLV_TAG_STRUC_wmi_resmgr_set_chan_latency_cmd_fixed_param,
122 		       WMITLV_GET_STRUCT_TLVLEN
123 		       (wmi_resmgr_set_chan_latency_cmd_fixed_param));
124 	cmdTL->num_chans = num_channels;
125 	/* Update channel time latency information for home channel(s) */
126 	buf_ptr += sizeof(*cmdTL);
127 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE,
128 		       num_channels * sizeof(wmi_resmgr_chan_latency));
129 	buf_ptr += WMI_TLV_HDR_SIZE;
130 	chan_latency.chan_mhz = chan1_freq;
131 	chan_latency.latency = latency_chan1;
132 	qdf_mem_copy(buf_ptr, &chan_latency, sizeof(chan_latency));
133 	wmi_mtrace(WMI_RESMGR_SET_CHAN_LATENCY_CMDID, NO_SESSION, 0);
134 	ret = wmi_unified_cmd_send(wmi_handle, buf, len,
135 				   WMI_RESMGR_SET_CHAN_LATENCY_CMDID);
136 	if (QDF_IS_STATUS_ERROR(ret)) {
137 		WMI_LOGE("%s: Failed to send MCC Channel Time Latency command",
138 			 __func__);
139 		wmi_buf_free(buf);
140 		QDF_ASSERT(0);
141 	}
142 
143 	return ret;
144 }
145 
146 /**
147  * send_set_mcc_channel_time_quota_cmd_tlv() -set MCC channel time quota
148  * @wmi: wmi handle
149  * @adapter_1_chan_number: adapter 1 channel number
150  * @adapter_1_quota: adapter 1 quota
151  * @adapter_2_chan_number: adapter 2 channel number
152  *
153  * Return: CDF status
154  */
155 static QDF_STATUS send_set_mcc_channel_time_quota_cmd_tlv(
156 					wmi_unified_t wmi_handle,
157 					uint32_t adapter_1_chan_freq,
158 					uint32_t adapter_1_quota,
159 					uint32_t adapter_2_chan_freq)
160 {
161 	QDF_STATUS ret;
162 	wmi_buf_t buf = 0;
163 	uint16_t len = 0;
164 	uint8_t *buf_ptr = NULL;
165 	wmi_resmgr_set_chan_time_quota_cmd_fixed_param *cmdTQ = NULL;
166 	wmi_resmgr_chan_time_quota chan_quota;
167 	uint32_t quota_chan1 = adapter_1_quota;
168 	/* Knowing quota of 1st chan., derive quota for 2nd chan. */
169 	uint32_t quota_chan2 = 100 - quota_chan1;
170 	/* Note: setting time quota for MCC requires info for 2 channels */
171 	uint32_t num_channels = 2;
172 	uint32_t chan1_freq = adapter_1_chan_freq;
173 	uint32_t chan2_freq = adapter_2_chan_freq;
174 
175 	WMI_LOGD("%s: freq1:%dMHz, Quota1:%dms, "
176 		 "freq2:%dMHz, Quota2:%dms", __func__,
177 		 chan1_freq, quota_chan1, chan2_freq,
178 		 quota_chan2);
179 
180 	/*
181 	 * Perform sanity check on time quota values provided.
182 	 */
183 	if (quota_chan1 < WMI_MCC_MIN_CHANNEL_QUOTA ||
184 	    quota_chan1 > WMI_MCC_MAX_CHANNEL_QUOTA) {
185 		WMI_LOGE("%s: Invalid time quota for Channel #1=%dms. Minimum "
186 			 "is 20ms & maximum is 80ms", __func__, quota_chan1);
187 		return QDF_STATUS_E_INVAL;
188 	}
189 	/* Set WMI CMD for channel time quota here */
190 	len = sizeof(wmi_resmgr_set_chan_time_quota_cmd_fixed_param) +
191 	      WMI_TLV_HDR_SIZE +       /* Place holder for chan_time_quota array */
192 	      num_channels * sizeof(wmi_resmgr_chan_time_quota);
193 	buf = wmi_buf_alloc(wmi_handle, len);
194 	if (!buf) {
195 		return QDF_STATUS_E_NOMEM;
196 	}
197 	buf_ptr = (uint8_t *) wmi_buf_data(buf);
198 	cmdTQ = (wmi_resmgr_set_chan_time_quota_cmd_fixed_param *)
199 		wmi_buf_data(buf);
200 	WMITLV_SET_HDR(&cmdTQ->tlv_header,
201 		       WMITLV_TAG_STRUC_wmi_resmgr_set_chan_time_quota_cmd_fixed_param,
202 		       WMITLV_GET_STRUCT_TLVLEN
203 			       (wmi_resmgr_set_chan_time_quota_cmd_fixed_param));
204 	cmdTQ->num_chans = num_channels;
205 
206 	/* Update channel time quota information for home channel(s) */
207 	buf_ptr += sizeof(*cmdTQ);
208 	WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE,
209 		       num_channels * sizeof(wmi_resmgr_chan_time_quota));
210 	buf_ptr += WMI_TLV_HDR_SIZE;
211 	chan_quota.chan_mhz = chan1_freq;
212 	chan_quota.channel_time_quota = quota_chan1;
213 	qdf_mem_copy(buf_ptr, &chan_quota, sizeof(chan_quota));
214 	/* Construct channel and quota record for the 2nd MCC mode. */
215 	buf_ptr += sizeof(chan_quota);
216 	chan_quota.chan_mhz = chan2_freq;
217 	chan_quota.channel_time_quota = quota_chan2;
218 	qdf_mem_copy(buf_ptr, &chan_quota, sizeof(chan_quota));
219 
220 	wmi_mtrace(WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID, NO_SESSION, 0);
221 	ret = wmi_unified_cmd_send(wmi_handle, buf, len,
222 				   WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID);
223 	if (QDF_IS_STATUS_ERROR(ret)) {
224 		WMI_LOGE("Failed to send MCC Channel Time Quota command");
225 		wmi_buf_free(buf);
226 		QDF_ASSERT(0);
227 	}
228 
229 	return ret;
230 }
231 
232 void wmi_concurrency_attach_tlv(wmi_unified_t wmi_handle)
233 {
234 	struct wmi_ops *ops = wmi_handle->ops;
235 
236 	ops->send_set_enable_disable_mcc_adaptive_scheduler_cmd =
237 		send_set_enable_disable_mcc_adaptive_scheduler_cmd_tlv;
238 	ops->send_set_mcc_channel_time_latency_cmd =
239 		send_set_mcc_channel_time_latency_cmd_tlv;
240 	ops->send_set_mcc_channel_time_quota_cmd =
241 		send_set_mcc_channel_time_quota_cmd_tlv;
242 }
243