18c2ecf20Sopenharmony_ci/****************************************************************************** 28c2ecf20Sopenharmony_ci * 38c2ecf20Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license. When using or 48c2ecf20Sopenharmony_ci * redistributing this file, you may do so under either license. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * GPL LICENSE SUMMARY 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 98c2ecf20Sopenharmony_ci * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 108c2ecf20Sopenharmony_ci * Copyright(c) 2016 - 2017 Intel Deutschland GmbH 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 138c2ecf20Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as 148c2ecf20Sopenharmony_ci * published by the Free Software Foundation. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, but 178c2ecf20Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of 188c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 198c2ecf20Sopenharmony_ci * General Public License for more details. 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * The full GNU General Public License is included in this distribution 228c2ecf20Sopenharmony_ci * in the file called COPYING. 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * Contact Information: 258c2ecf20Sopenharmony_ci * Intel Linux Wireless <linuxwifi@intel.com> 268c2ecf20Sopenharmony_ci * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * BSD LICENSE 298c2ecf20Sopenharmony_ci * 308c2ecf20Sopenharmony_ci * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 318c2ecf20Sopenharmony_ci * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 328c2ecf20Sopenharmony_ci * Copyright(c) 2016 - 2017 Intel Deutschland GmbH 338c2ecf20Sopenharmony_ci * All rights reserved. 348c2ecf20Sopenharmony_ci * 358c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 368c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 378c2ecf20Sopenharmony_ci * are met: 388c2ecf20Sopenharmony_ci * 398c2ecf20Sopenharmony_ci * * Redistributions of source code must retain the above copyright 408c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 418c2ecf20Sopenharmony_ci * * Redistributions in binary form must reproduce the above copyright 428c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in 438c2ecf20Sopenharmony_ci * the documentation and/or other materials provided with the 448c2ecf20Sopenharmony_ci * distribution. 458c2ecf20Sopenharmony_ci * * Neither the name Intel Corporation nor the names of its 468c2ecf20Sopenharmony_ci * contributors may be used to endorse or promote products derived 478c2ecf20Sopenharmony_ci * from this software without specific prior written permission. 488c2ecf20Sopenharmony_ci * 498c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 508c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 518c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 528c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 538c2ecf20Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 548c2ecf20Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 558c2ecf20Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 568c2ecf20Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 578c2ecf20Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 588c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 598c2ecf20Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 608c2ecf20Sopenharmony_ci * 618c2ecf20Sopenharmony_ci *****************************************************************************/ 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#include <net/mac80211.h> 648c2ecf20Sopenharmony_ci#include "fw-api.h" 658c2ecf20Sopenharmony_ci#include "mvm.h" 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#define QUOTA_100 IWL_MVM_MAX_QUOTA 688c2ecf20Sopenharmony_ci#define QUOTA_LOWLAT_MIN ((QUOTA_100 * IWL_MVM_LOWLAT_QUOTA_MIN_PERCENT) / 100) 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistruct iwl_mvm_quota_iterator_data { 718c2ecf20Sopenharmony_ci int n_interfaces[MAX_BINDINGS]; 728c2ecf20Sopenharmony_ci int colors[MAX_BINDINGS]; 738c2ecf20Sopenharmony_ci int low_latency[MAX_BINDINGS]; 748c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUGFS 758c2ecf20Sopenharmony_ci int dbgfs_min[MAX_BINDINGS]; 768c2ecf20Sopenharmony_ci#endif 778c2ecf20Sopenharmony_ci int n_low_latency_bindings; 788c2ecf20Sopenharmony_ci struct ieee80211_vif *disabled_vif; 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cistatic void iwl_mvm_quota_iterator(void *_data, u8 *mac, 828c2ecf20Sopenharmony_ci struct ieee80211_vif *vif) 838c2ecf20Sopenharmony_ci{ 848c2ecf20Sopenharmony_ci struct iwl_mvm_quota_iterator_data *data = _data; 858c2ecf20Sopenharmony_ci struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 868c2ecf20Sopenharmony_ci u16 id; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci /* skip disabled interfaces here immediately */ 898c2ecf20Sopenharmony_ci if (vif == data->disabled_vif) 908c2ecf20Sopenharmony_ci return; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci if (!mvmvif->phy_ctxt) 938c2ecf20Sopenharmony_ci return; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci /* currently, PHY ID == binding ID */ 968c2ecf20Sopenharmony_ci id = mvmvif->phy_ctxt->id; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci /* need at least one binding per PHY */ 998c2ecf20Sopenharmony_ci BUILD_BUG_ON(NUM_PHY_CTX > MAX_BINDINGS); 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci if (WARN_ON_ONCE(id >= MAX_BINDINGS)) 1028c2ecf20Sopenharmony_ci return; 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci switch (vif->type) { 1058c2ecf20Sopenharmony_ci case NL80211_IFTYPE_STATION: 1068c2ecf20Sopenharmony_ci if (vif->bss_conf.assoc) 1078c2ecf20Sopenharmony_ci break; 1088c2ecf20Sopenharmony_ci return; 1098c2ecf20Sopenharmony_ci case NL80211_IFTYPE_AP: 1108c2ecf20Sopenharmony_ci case NL80211_IFTYPE_ADHOC: 1118c2ecf20Sopenharmony_ci if (mvmvif->ap_ibss_active) 1128c2ecf20Sopenharmony_ci break; 1138c2ecf20Sopenharmony_ci return; 1148c2ecf20Sopenharmony_ci case NL80211_IFTYPE_MONITOR: 1158c2ecf20Sopenharmony_ci if (mvmvif->monitor_active) 1168c2ecf20Sopenharmony_ci break; 1178c2ecf20Sopenharmony_ci return; 1188c2ecf20Sopenharmony_ci case NL80211_IFTYPE_P2P_DEVICE: 1198c2ecf20Sopenharmony_ci return; 1208c2ecf20Sopenharmony_ci default: 1218c2ecf20Sopenharmony_ci WARN_ON_ONCE(1); 1228c2ecf20Sopenharmony_ci return; 1238c2ecf20Sopenharmony_ci } 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci if (data->colors[id] < 0) 1268c2ecf20Sopenharmony_ci data->colors[id] = mvmvif->phy_ctxt->color; 1278c2ecf20Sopenharmony_ci else 1288c2ecf20Sopenharmony_ci WARN_ON_ONCE(data->colors[id] != mvmvif->phy_ctxt->color); 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci data->n_interfaces[id]++; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUGFS 1338c2ecf20Sopenharmony_ci if (mvmvif->dbgfs_quota_min) 1348c2ecf20Sopenharmony_ci data->dbgfs_min[id] = max(data->dbgfs_min[id], 1358c2ecf20Sopenharmony_ci mvmvif->dbgfs_quota_min); 1368c2ecf20Sopenharmony_ci#endif 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci if (iwl_mvm_vif_low_latency(mvmvif) && !data->low_latency[id]) { 1398c2ecf20Sopenharmony_ci data->n_low_latency_bindings++; 1408c2ecf20Sopenharmony_ci data->low_latency[id] = true; 1418c2ecf20Sopenharmony_ci } 1428c2ecf20Sopenharmony_ci} 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_cistatic void iwl_mvm_adjust_quota_for_noa(struct iwl_mvm *mvm, 1458c2ecf20Sopenharmony_ci struct iwl_time_quota_cmd *cmd) 1468c2ecf20Sopenharmony_ci{ 1478c2ecf20Sopenharmony_ci#ifdef CONFIG_NL80211_TESTMODE 1488c2ecf20Sopenharmony_ci struct iwl_mvm_vif *mvmvif; 1498c2ecf20Sopenharmony_ci int i, phy_id = -1, beacon_int = 0; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci if (!mvm->noa_duration || !mvm->noa_vif) 1528c2ecf20Sopenharmony_ci return; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci mvmvif = iwl_mvm_vif_from_mac80211(mvm->noa_vif); 1558c2ecf20Sopenharmony_ci if (!mvmvif->ap_ibss_active) 1568c2ecf20Sopenharmony_ci return; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci phy_id = mvmvif->phy_ctxt->id; 1598c2ecf20Sopenharmony_ci beacon_int = mvm->noa_vif->bss_conf.beacon_int; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci for (i = 0; i < MAX_BINDINGS; i++) { 1628c2ecf20Sopenharmony_ci struct iwl_time_quota_data *data = 1638c2ecf20Sopenharmony_ci iwl_mvm_quota_cmd_get_quota(mvm, cmd, 1648c2ecf20Sopenharmony_ci i); 1658c2ecf20Sopenharmony_ci u32 id_n_c = le32_to_cpu(data->id_and_color); 1668c2ecf20Sopenharmony_ci u32 id = (id_n_c & FW_CTXT_ID_MSK) >> FW_CTXT_ID_POS; 1678c2ecf20Sopenharmony_ci u32 quota = le32_to_cpu(data->quota); 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci if (id != phy_id) 1708c2ecf20Sopenharmony_ci continue; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci quota *= (beacon_int - mvm->noa_duration); 1738c2ecf20Sopenharmony_ci quota /= beacon_int; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci IWL_DEBUG_QUOTA(mvm, "quota: adjust for NoA from %d to %d\n", 1768c2ecf20Sopenharmony_ci le32_to_cpu(data->quota), quota); 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci data->quota = cpu_to_le32(quota); 1798c2ecf20Sopenharmony_ci } 1808c2ecf20Sopenharmony_ci#endif 1818c2ecf20Sopenharmony_ci} 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ciint iwl_mvm_update_quotas(struct iwl_mvm *mvm, 1848c2ecf20Sopenharmony_ci bool force_update, 1858c2ecf20Sopenharmony_ci struct ieee80211_vif *disabled_vif) 1868c2ecf20Sopenharmony_ci{ 1878c2ecf20Sopenharmony_ci struct iwl_time_quota_cmd cmd = {}; 1888c2ecf20Sopenharmony_ci int i, idx, err, num_active_macs, quota, quota_rem, n_non_lowlat; 1898c2ecf20Sopenharmony_ci struct iwl_mvm_quota_iterator_data data = { 1908c2ecf20Sopenharmony_ci .n_interfaces = {}, 1918c2ecf20Sopenharmony_ci .colors = { -1, -1, -1, -1 }, 1928c2ecf20Sopenharmony_ci .disabled_vif = disabled_vif, 1938c2ecf20Sopenharmony_ci }; 1948c2ecf20Sopenharmony_ci struct iwl_time_quota_cmd *last = &mvm->last_quota_cmd; 1958c2ecf20Sopenharmony_ci struct iwl_time_quota_data *qdata, *last_data; 1968c2ecf20Sopenharmony_ci bool send = false; 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci lockdep_assert_held(&mvm->mutex); 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci if (fw_has_capa(&mvm->fw->ucode_capa, 2018c2ecf20Sopenharmony_ci IWL_UCODE_TLV_CAPA_DYNAMIC_QUOTA)) 2028c2ecf20Sopenharmony_ci return 0; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci /* update all upon completion */ 2058c2ecf20Sopenharmony_ci if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 2068c2ecf20Sopenharmony_ci return 0; 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci /* iterator data above must match */ 2098c2ecf20Sopenharmony_ci BUILD_BUG_ON(MAX_BINDINGS != 4); 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci ieee80211_iterate_active_interfaces_atomic( 2128c2ecf20Sopenharmony_ci mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 2138c2ecf20Sopenharmony_ci iwl_mvm_quota_iterator, &data); 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci /* 2168c2ecf20Sopenharmony_ci * The FW's scheduling session consists of 2178c2ecf20Sopenharmony_ci * IWL_MVM_MAX_QUOTA fragments. Divide these fragments 2188c2ecf20Sopenharmony_ci * equally between all the bindings that require quota 2198c2ecf20Sopenharmony_ci */ 2208c2ecf20Sopenharmony_ci num_active_macs = 0; 2218c2ecf20Sopenharmony_ci for (i = 0; i < MAX_BINDINGS; i++) { 2228c2ecf20Sopenharmony_ci qdata = iwl_mvm_quota_cmd_get_quota(mvm, &cmd, i); 2238c2ecf20Sopenharmony_ci qdata->id_and_color = cpu_to_le32(FW_CTXT_INVALID); 2248c2ecf20Sopenharmony_ci num_active_macs += data.n_interfaces[i]; 2258c2ecf20Sopenharmony_ci } 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci n_non_lowlat = num_active_macs; 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci if (data.n_low_latency_bindings == 1) { 2308c2ecf20Sopenharmony_ci for (i = 0; i < MAX_BINDINGS; i++) { 2318c2ecf20Sopenharmony_ci if (data.low_latency[i]) { 2328c2ecf20Sopenharmony_ci n_non_lowlat -= data.n_interfaces[i]; 2338c2ecf20Sopenharmony_ci break; 2348c2ecf20Sopenharmony_ci } 2358c2ecf20Sopenharmony_ci } 2368c2ecf20Sopenharmony_ci } 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci if (data.n_low_latency_bindings == 1 && n_non_lowlat) { 2398c2ecf20Sopenharmony_ci /* 2408c2ecf20Sopenharmony_ci * Reserve quota for the low latency binding in case that 2418c2ecf20Sopenharmony_ci * there are several data bindings but only a single 2428c2ecf20Sopenharmony_ci * low latency one. Split the rest of the quota equally 2438c2ecf20Sopenharmony_ci * between the other data interfaces. 2448c2ecf20Sopenharmony_ci */ 2458c2ecf20Sopenharmony_ci quota = (QUOTA_100 - QUOTA_LOWLAT_MIN) / n_non_lowlat; 2468c2ecf20Sopenharmony_ci quota_rem = QUOTA_100 - n_non_lowlat * quota - 2478c2ecf20Sopenharmony_ci QUOTA_LOWLAT_MIN; 2488c2ecf20Sopenharmony_ci IWL_DEBUG_QUOTA(mvm, 2498c2ecf20Sopenharmony_ci "quota: low-latency binding active, remaining quota per other binding: %d\n", 2508c2ecf20Sopenharmony_ci quota); 2518c2ecf20Sopenharmony_ci } else if (num_active_macs) { 2528c2ecf20Sopenharmony_ci /* 2538c2ecf20Sopenharmony_ci * There are 0 or more than 1 low latency bindings, or all the 2548c2ecf20Sopenharmony_ci * data interfaces belong to the single low latency binding. 2558c2ecf20Sopenharmony_ci * Split the quota equally between the data interfaces. 2568c2ecf20Sopenharmony_ci */ 2578c2ecf20Sopenharmony_ci quota = QUOTA_100 / num_active_macs; 2588c2ecf20Sopenharmony_ci quota_rem = QUOTA_100 % num_active_macs; 2598c2ecf20Sopenharmony_ci IWL_DEBUG_QUOTA(mvm, 2608c2ecf20Sopenharmony_ci "quota: splitting evenly per binding: %d\n", 2618c2ecf20Sopenharmony_ci quota); 2628c2ecf20Sopenharmony_ci } else { 2638c2ecf20Sopenharmony_ci /* values don't really matter - won't be used */ 2648c2ecf20Sopenharmony_ci quota = 0; 2658c2ecf20Sopenharmony_ci quota_rem = 0; 2668c2ecf20Sopenharmony_ci } 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci for (idx = 0, i = 0; i < MAX_BINDINGS; i++) { 2698c2ecf20Sopenharmony_ci if (data.colors[i] < 0) 2708c2ecf20Sopenharmony_ci continue; 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci qdata = iwl_mvm_quota_cmd_get_quota(mvm, &cmd, idx); 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci qdata->id_and_color = 2758c2ecf20Sopenharmony_ci cpu_to_le32(FW_CMD_ID_AND_COLOR(i, data.colors[i])); 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci if (data.n_interfaces[i] <= 0) 2788c2ecf20Sopenharmony_ci qdata->quota = cpu_to_le32(0); 2798c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUGFS 2808c2ecf20Sopenharmony_ci else if (data.dbgfs_min[i]) 2818c2ecf20Sopenharmony_ci qdata->quota = 2828c2ecf20Sopenharmony_ci cpu_to_le32(data.dbgfs_min[i] * QUOTA_100 / 100); 2838c2ecf20Sopenharmony_ci#endif 2848c2ecf20Sopenharmony_ci else if (data.n_low_latency_bindings == 1 && n_non_lowlat && 2858c2ecf20Sopenharmony_ci data.low_latency[i]) 2868c2ecf20Sopenharmony_ci /* 2878c2ecf20Sopenharmony_ci * There is more than one binding, but only one of the 2888c2ecf20Sopenharmony_ci * bindings is in low latency. For this case, allocate 2898c2ecf20Sopenharmony_ci * the minimal required quota for the low latency 2908c2ecf20Sopenharmony_ci * binding. 2918c2ecf20Sopenharmony_ci */ 2928c2ecf20Sopenharmony_ci qdata->quota = cpu_to_le32(QUOTA_LOWLAT_MIN); 2938c2ecf20Sopenharmony_ci else 2948c2ecf20Sopenharmony_ci qdata->quota = 2958c2ecf20Sopenharmony_ci cpu_to_le32(quota * data.n_interfaces[i]); 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci WARN_ONCE(le32_to_cpu(qdata->quota) > QUOTA_100, 2988c2ecf20Sopenharmony_ci "Binding=%d, quota=%u > max=%u\n", 2998c2ecf20Sopenharmony_ci idx, le32_to_cpu(qdata->quota), QUOTA_100); 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci qdata->max_duration = cpu_to_le32(0); 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci idx++; 3048c2ecf20Sopenharmony_ci } 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci /* Give the remainder of the session to the first data binding */ 3078c2ecf20Sopenharmony_ci for (i = 0; i < MAX_BINDINGS; i++) { 3088c2ecf20Sopenharmony_ci qdata = iwl_mvm_quota_cmd_get_quota(mvm, &cmd, i); 3098c2ecf20Sopenharmony_ci if (le32_to_cpu(qdata->quota) != 0) { 3108c2ecf20Sopenharmony_ci le32_add_cpu(&qdata->quota, quota_rem); 3118c2ecf20Sopenharmony_ci IWL_DEBUG_QUOTA(mvm, 3128c2ecf20Sopenharmony_ci "quota: giving remainder of %d to binding %d\n", 3138c2ecf20Sopenharmony_ci quota_rem, i); 3148c2ecf20Sopenharmony_ci break; 3158c2ecf20Sopenharmony_ci } 3168c2ecf20Sopenharmony_ci } 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci iwl_mvm_adjust_quota_for_noa(mvm, &cmd); 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci /* check that we have non-zero quota for all valid bindings */ 3218c2ecf20Sopenharmony_ci for (i = 0; i < MAX_BINDINGS; i++) { 3228c2ecf20Sopenharmony_ci qdata = iwl_mvm_quota_cmd_get_quota(mvm, &cmd, i); 3238c2ecf20Sopenharmony_ci last_data = iwl_mvm_quota_cmd_get_quota(mvm, last, i); 3248c2ecf20Sopenharmony_ci if (qdata->id_and_color != last_data->id_and_color) 3258c2ecf20Sopenharmony_ci send = true; 3268c2ecf20Sopenharmony_ci if (qdata->max_duration != last_data->max_duration) 3278c2ecf20Sopenharmony_ci send = true; 3288c2ecf20Sopenharmony_ci if (abs((int)le32_to_cpu(qdata->quota) - 3298c2ecf20Sopenharmony_ci (int)le32_to_cpu(last_data->quota)) 3308c2ecf20Sopenharmony_ci > IWL_MVM_QUOTA_THRESHOLD) 3318c2ecf20Sopenharmony_ci send = true; 3328c2ecf20Sopenharmony_ci if (qdata->id_and_color == cpu_to_le32(FW_CTXT_INVALID)) 3338c2ecf20Sopenharmony_ci continue; 3348c2ecf20Sopenharmony_ci WARN_ONCE(qdata->quota == 0, 3358c2ecf20Sopenharmony_ci "zero quota on binding %d\n", i); 3368c2ecf20Sopenharmony_ci } 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci if (!send && !force_update) { 3398c2ecf20Sopenharmony_ci /* don't send a practically unchanged command, the firmware has 3408c2ecf20Sopenharmony_ci * to re-initialize a lot of state and that can have an adverse 3418c2ecf20Sopenharmony_ci * impact on it 3428c2ecf20Sopenharmony_ci */ 3438c2ecf20Sopenharmony_ci return 0; 3448c2ecf20Sopenharmony_ci } 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci err = iwl_mvm_send_cmd_pdu(mvm, TIME_QUOTA_CMD, 0, 3478c2ecf20Sopenharmony_ci iwl_mvm_quota_cmd_size(mvm), &cmd); 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci if (err) 3508c2ecf20Sopenharmony_ci IWL_ERR(mvm, "Failed to send quota: %d\n", err); 3518c2ecf20Sopenharmony_ci else 3528c2ecf20Sopenharmony_ci mvm->last_quota_cmd = cmd; 3538c2ecf20Sopenharmony_ci return err; 3548c2ecf20Sopenharmony_ci} 355