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