Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 4 | * redistributing this file, you may do so under either license. |
| 5 | * |
| 6 | * GPL LICENSE SUMMARY |
| 7 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 8 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8b4139d | 2014-07-24 14:05:26 +0200 | [diff] [blame] | 9 | * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH |
Johannes Berg | a80c1cf | 2016-01-13 15:01:00 +0100 | [diff] [blame] | 10 | * Copyright(c) 2016 Intel Deutschland GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of version 2 of the GNU General Public License as |
| 14 | * published by the Free Software Foundation. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 24 | * USA |
| 25 | * |
| 26 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 27 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 28 | * |
| 29 | * Contact Information: |
Emmanuel Grumbach | cb2f827 | 2015-11-17 15:39:56 +0200 | [diff] [blame] | 30 | * Intel Linux Wireless <linuxwifi@intel.com> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 31 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 32 | * |
| 33 | * BSD LICENSE |
| 34 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 35 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8b4139d | 2014-07-24 14:05:26 +0200 | [diff] [blame] | 36 | * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH |
Johannes Berg | a80c1cf | 2016-01-13 15:01:00 +0100 | [diff] [blame] | 37 | * Copyright(c) 2016 Intel Deutschland GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 38 | * All rights reserved. |
| 39 | * |
| 40 | * Redistribution and use in source and binary forms, with or without |
| 41 | * modification, are permitted provided that the following conditions |
| 42 | * are met: |
| 43 | * |
| 44 | * * Redistributions of source code must retain the above copyright |
| 45 | * notice, this list of conditions and the following disclaimer. |
| 46 | * * Redistributions in binary form must reproduce the above copyright |
| 47 | * notice, this list of conditions and the following disclaimer in |
| 48 | * the documentation and/or other materials provided with the |
| 49 | * distribution. |
| 50 | * * Neither the name Intel Corporation nor the names of its |
| 51 | * contributors may be used to endorse or promote products derived |
| 52 | * from this software without specific prior written permission. |
| 53 | * |
| 54 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 55 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 56 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 57 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 58 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 59 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 60 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 61 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 62 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 63 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 64 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 65 | * |
| 66 | *****************************************************************************/ |
| 67 | |
| 68 | #include <net/mac80211.h> |
| 69 | #include "fw-api.h" |
| 70 | #include "mvm.h" |
| 71 | |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 72 | #define QUOTA_100 IWL_MVM_MAX_QUOTA |
| 73 | #define QUOTA_LOWLAT_MIN ((QUOTA_100 * IWL_MVM_LOWLAT_QUOTA_MIN_PERCENT) / 100) |
| 74 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 75 | struct iwl_mvm_quota_iterator_data { |
| 76 | int n_interfaces[MAX_BINDINGS]; |
| 77 | int colors[MAX_BINDINGS]; |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 78 | int low_latency[MAX_BINDINGS]; |
Johannes Berg | a80c1cf | 2016-01-13 15:01:00 +0100 | [diff] [blame] | 79 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 80 | int dbgfs_min[MAX_BINDINGS]; |
| 81 | #endif |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 82 | int n_low_latency_bindings; |
Johannes Berg | 0166230 | 2014-06-06 15:18:45 +0200 | [diff] [blame] | 83 | struct ieee80211_vif *disabled_vif; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | static void iwl_mvm_quota_iterator(void *_data, u8 *mac, |
| 87 | struct ieee80211_vif *vif) |
| 88 | { |
| 89 | struct iwl_mvm_quota_iterator_data *data = _data; |
| 90 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 91 | u16 id; |
| 92 | |
Johannes Berg | 0166230 | 2014-06-06 15:18:45 +0200 | [diff] [blame] | 93 | /* skip disabled interfaces here immediately */ |
| 94 | if (vif == data->disabled_vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 95 | return; |
| 96 | |
| 97 | if (!mvmvif->phy_ctxt) |
| 98 | return; |
| 99 | |
| 100 | /* currently, PHY ID == binding ID */ |
| 101 | id = mvmvif->phy_ctxt->id; |
| 102 | |
| 103 | /* need at least one binding per PHY */ |
| 104 | BUILD_BUG_ON(NUM_PHY_CTX > MAX_BINDINGS); |
| 105 | |
| 106 | if (WARN_ON_ONCE(id >= MAX_BINDINGS)) |
| 107 | return; |
| 108 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 109 | switch (vif->type) { |
| 110 | case NL80211_IFTYPE_STATION: |
| 111 | if (vif->bss_conf.assoc) |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 112 | break; |
| 113 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 114 | case NL80211_IFTYPE_AP: |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 115 | case NL80211_IFTYPE_ADHOC: |
| 116 | if (mvmvif->ap_ibss_active) |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 117 | break; |
| 118 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 119 | case NL80211_IFTYPE_MONITOR: |
Ilan Peer | 1e1391c | 2013-03-13 14:52:04 +0200 | [diff] [blame] | 120 | if (mvmvif->monitor_active) |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 121 | break; |
| 122 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 123 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 124 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 125 | default: |
| 126 | WARN_ON_ONCE(1); |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 127 | return; |
| 128 | } |
| 129 | |
Johannes Berg | 63faceb | 2014-05-23 16:15:11 +0200 | [diff] [blame] | 130 | if (data->colors[id] < 0) |
| 131 | data->colors[id] = mvmvif->phy_ctxt->color; |
| 132 | else |
| 133 | WARN_ON_ONCE(data->colors[id] != mvmvif->phy_ctxt->color); |
| 134 | |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 135 | data->n_interfaces[id]++; |
| 136 | |
Johannes Berg | a80c1cf | 2016-01-13 15:01:00 +0100 | [diff] [blame] | 137 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 138 | if (mvmvif->dbgfs_quota_min) |
| 139 | data->dbgfs_min[id] = max(data->dbgfs_min[id], |
| 140 | mvmvif->dbgfs_quota_min); |
| 141 | #endif |
| 142 | |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 143 | if (iwl_mvm_vif_low_latency(mvmvif) && !data->low_latency[id]) { |
| 144 | data->n_low_latency_bindings++; |
| 145 | data->low_latency[id] = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 149 | static void iwl_mvm_adjust_quota_for_noa(struct iwl_mvm *mvm, |
| 150 | struct iwl_time_quota_cmd *cmd) |
| 151 | { |
| 152 | #ifdef CONFIG_NL80211_TESTMODE |
| 153 | struct iwl_mvm_vif *mvmvif; |
| 154 | int i, phy_id = -1, beacon_int = 0; |
| 155 | |
| 156 | if (!mvm->noa_duration || !mvm->noa_vif) |
| 157 | return; |
| 158 | |
| 159 | mvmvif = iwl_mvm_vif_from_mac80211(mvm->noa_vif); |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 160 | if (!mvmvif->ap_ibss_active) |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 161 | return; |
| 162 | |
| 163 | phy_id = mvmvif->phy_ctxt->id; |
| 164 | beacon_int = mvm->noa_vif->bss_conf.beacon_int; |
| 165 | |
| 166 | for (i = 0; i < MAX_BINDINGS; i++) { |
| 167 | u32 id_n_c = le32_to_cpu(cmd->quotas[i].id_and_color); |
| 168 | u32 id = (id_n_c & FW_CTXT_ID_MSK) >> FW_CTXT_ID_POS; |
| 169 | u32 quota = le32_to_cpu(cmd->quotas[i].quota); |
| 170 | |
| 171 | if (id != phy_id) |
| 172 | continue; |
| 173 | |
David Spinadel | 246dd99 | 2013-10-17 09:49:12 +0300 | [diff] [blame] | 174 | quota *= (beacon_int - mvm->noa_duration); |
| 175 | quota /= beacon_int; |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 176 | |
Johannes Berg | a43ad46 | 2014-08-04 16:39:54 +0200 | [diff] [blame] | 177 | IWL_DEBUG_QUOTA(mvm, "quota: adjust for NoA from %d to %d\n", |
| 178 | le32_to_cpu(cmd->quotas[i].quota), quota); |
| 179 | |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 180 | cmd->quotas[i].quota = cpu_to_le32(quota); |
| 181 | } |
| 182 | #endif |
| 183 | } |
| 184 | |
Johannes Berg | 0166230 | 2014-06-06 15:18:45 +0200 | [diff] [blame] | 185 | int iwl_mvm_update_quotas(struct iwl_mvm *mvm, |
Emmanuel Grumbach | 7754ae7 | 2015-02-26 15:14:35 +0200 | [diff] [blame] | 186 | bool force_update, |
Johannes Berg | 0166230 | 2014-06-06 15:18:45 +0200 | [diff] [blame] | 187 | struct ieee80211_vif *disabled_vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 188 | { |
Johannes Berg | f5e45f2 | 2013-07-25 22:36:27 +0200 | [diff] [blame] | 189 | struct iwl_time_quota_cmd cmd = {}; |
Johannes Berg | b2b7875 | 2014-09-08 16:42:54 +0200 | [diff] [blame] | 190 | int i, idx, err, num_active_macs, quota, quota_rem, n_non_lowlat; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 191 | struct iwl_mvm_quota_iterator_data data = { |
| 192 | .n_interfaces = {}, |
| 193 | .colors = { -1, -1, -1, -1 }, |
Johannes Berg | 0166230 | 2014-06-06 15:18:45 +0200 | [diff] [blame] | 194 | .disabled_vif = disabled_vif, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 195 | }; |
Johannes Berg | b2b7875 | 2014-09-08 16:42:54 +0200 | [diff] [blame] | 196 | struct iwl_time_quota_cmd *last = &mvm->last_quota_cmd; |
| 197 | bool send = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 198 | |
Johannes Berg | f5e45f2 | 2013-07-25 22:36:27 +0200 | [diff] [blame] | 199 | lockdep_assert_held(&mvm->mutex); |
| 200 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 201 | /* update all upon completion */ |
| 202 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
| 203 | return 0; |
| 204 | |
Johannes Berg | f5e45f2 | 2013-07-25 22:36:27 +0200 | [diff] [blame] | 205 | /* iterator data above must match */ |
| 206 | BUILD_BUG_ON(MAX_BINDINGS != 4); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 207 | |
| 208 | ieee80211_iterate_active_interfaces_atomic( |
| 209 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 210 | iwl_mvm_quota_iterator, &data); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 211 | |
Ilan Peer | 35adfd6 | 2013-02-04 13:16:24 +0200 | [diff] [blame] | 212 | /* |
| 213 | * The FW's scheduling session consists of |
| 214 | * IWL_MVM_MAX_QUOTA fragments. Divide these fragments |
| 215 | * equally between all the bindings that require quota |
| 216 | */ |
Johannes Berg | 7b8359c | 2013-07-10 12:59:38 +0200 | [diff] [blame] | 217 | num_active_macs = 0; |
Ilan Peer | 35adfd6 | 2013-02-04 13:16:24 +0200 | [diff] [blame] | 218 | for (i = 0; i < MAX_BINDINGS; i++) { |
| 219 | cmd.quotas[i].id_and_color = cpu_to_le32(FW_CTXT_INVALID); |
Johannes Berg | 7b8359c | 2013-07-10 12:59:38 +0200 | [diff] [blame] | 220 | num_active_macs += data.n_interfaces[i]; |
Ilan Peer | 35adfd6 | 2013-02-04 13:16:24 +0200 | [diff] [blame] | 221 | } |
| 222 | |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 223 | n_non_lowlat = num_active_macs; |
| 224 | |
| 225 | if (data.n_low_latency_bindings == 1) { |
| 226 | for (i = 0; i < MAX_BINDINGS; i++) { |
| 227 | if (data.low_latency[i]) { |
| 228 | n_non_lowlat -= data.n_interfaces[i]; |
| 229 | break; |
| 230 | } |
| 231 | } |
Ilan Peer | 7b4fe06 | 2014-01-19 11:38:39 +0200 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | if (data.n_low_latency_bindings == 1 && n_non_lowlat) { |
| 235 | /* |
| 236 | * Reserve quota for the low latency binding in case that |
| 237 | * there are several data bindings but only a single |
| 238 | * low latency one. Split the rest of the quota equally |
| 239 | * between the other data interfaces. |
| 240 | */ |
| 241 | quota = (QUOTA_100 - QUOTA_LOWLAT_MIN) / n_non_lowlat; |
| 242 | quota_rem = QUOTA_100 - n_non_lowlat * quota - |
| 243 | QUOTA_LOWLAT_MIN; |
Johannes Berg | a43ad46 | 2014-08-04 16:39:54 +0200 | [diff] [blame] | 244 | IWL_DEBUG_QUOTA(mvm, |
| 245 | "quota: low-latency binding active, remaining quota per other binding: %d\n", |
| 246 | quota); |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 247 | } else if (num_active_macs) { |
Ilan Peer | 7b4fe06 | 2014-01-19 11:38:39 +0200 | [diff] [blame] | 248 | /* |
| 249 | * There are 0 or more than 1 low latency bindings, or all the |
| 250 | * data interfaces belong to the single low latency binding. |
| 251 | * Split the quota equally between the data interfaces. |
| 252 | */ |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 253 | quota = QUOTA_100 / num_active_macs; |
| 254 | quota_rem = QUOTA_100 % num_active_macs; |
Johannes Berg | a43ad46 | 2014-08-04 16:39:54 +0200 | [diff] [blame] | 255 | IWL_DEBUG_QUOTA(mvm, |
| 256 | "quota: splitting evenly per binding: %d\n", |
| 257 | quota); |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 258 | } else { |
| 259 | /* values don't really matter - won't be used */ |
| 260 | quota = 0; |
| 261 | quota_rem = 0; |
Ilan Peer | 8d683b7 | 2013-05-30 07:31:01 +0300 | [diff] [blame] | 262 | } |
Ilan Peer | 35adfd6 | 2013-02-04 13:16:24 +0200 | [diff] [blame] | 263 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 264 | for (idx = 0, i = 0; i < MAX_BINDINGS; i++) { |
Ilan Peer | 8d683b7 | 2013-05-30 07:31:01 +0300 | [diff] [blame] | 265 | if (data.colors[i] < 0) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 266 | continue; |
| 267 | |
| 268 | cmd.quotas[idx].id_and_color = |
| 269 | cpu_to_le32(FW_CMD_ID_AND_COLOR(i, data.colors[i])); |
Ilan Peer | 8d683b7 | 2013-05-30 07:31:01 +0300 | [diff] [blame] | 270 | |
Johannes Berg | 1fb184b | 2013-11-12 22:18:45 +0100 | [diff] [blame] | 271 | if (data.n_interfaces[i] <= 0) |
Ilan Peer | 8d683b7 | 2013-05-30 07:31:01 +0300 | [diff] [blame] | 272 | cmd.quotas[idx].quota = cpu_to_le32(0); |
Johannes Berg | a80c1cf | 2016-01-13 15:01:00 +0100 | [diff] [blame] | 273 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 274 | else if (data.dbgfs_min[i]) |
| 275 | cmd.quotas[idx].quota = |
| 276 | cpu_to_le32(data.dbgfs_min[i] * QUOTA_100 / 100); |
| 277 | #endif |
Johannes Berg | 1fb184b | 2013-11-12 22:18:45 +0100 | [diff] [blame] | 278 | else if (data.n_low_latency_bindings == 1 && n_non_lowlat && |
| 279 | data.low_latency[i]) |
Ilan Peer | 7b4fe06 | 2014-01-19 11:38:39 +0200 | [diff] [blame] | 280 | /* |
| 281 | * There is more than one binding, but only one of the |
| 282 | * bindings is in low latency. For this case, allocate |
| 283 | * the minimal required quota for the low latency |
| 284 | * binding. |
| 285 | */ |
Johannes Berg | 6ca40d6 | 2013-12-18 15:56:28 +0100 | [diff] [blame] | 286 | cmd.quotas[idx].quota = cpu_to_le32(QUOTA_LOWLAT_MIN); |
Johannes Berg | 1fb184b | 2013-11-12 22:18:45 +0100 | [diff] [blame] | 287 | else |
Johannes Berg | 7b8359c | 2013-07-10 12:59:38 +0200 | [diff] [blame] | 288 | cmd.quotas[idx].quota = |
| 289 | cpu_to_le32(quota * data.n_interfaces[i]); |
Johannes Berg | 1fb184b | 2013-11-12 22:18:45 +0100 | [diff] [blame] | 290 | |
Ilan Peer | 7b4fe06 | 2014-01-19 11:38:39 +0200 | [diff] [blame] | 291 | WARN_ONCE(le32_to_cpu(cmd.quotas[idx].quota) > QUOTA_100, |
| 292 | "Binding=%d, quota=%u > max=%u\n", |
| 293 | idx, le32_to_cpu(cmd.quotas[idx].quota), QUOTA_100); |
| 294 | |
Johannes Berg | 65d6662 | 2014-03-17 09:34:29 +0100 | [diff] [blame] | 295 | cmd.quotas[idx].max_duration = cpu_to_le32(0); |
Johannes Berg | 1fb184b | 2013-11-12 22:18:45 +0100 | [diff] [blame] | 296 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 297 | idx++; |
| 298 | } |
| 299 | |
Ilan Peer | 2d675e5 | 2014-01-19 11:46:52 +0200 | [diff] [blame] | 300 | /* Give the remainder of the session to the first data binding */ |
| 301 | for (i = 0; i < MAX_BINDINGS; i++) { |
| 302 | if (le32_to_cpu(cmd.quotas[i].quota) != 0) { |
| 303 | le32_add_cpu(&cmd.quotas[i].quota, quota_rem); |
Johannes Berg | a43ad46 | 2014-08-04 16:39:54 +0200 | [diff] [blame] | 304 | IWL_DEBUG_QUOTA(mvm, |
| 305 | "quota: giving remainder of %d to binding %d\n", |
| 306 | quota_rem, i); |
Ilan Peer | 2d675e5 | 2014-01-19 11:46:52 +0200 | [diff] [blame] | 307 | break; |
| 308 | } |
| 309 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 310 | |
David Spinadel | 507cadf | 2013-07-31 18:07:21 +0300 | [diff] [blame] | 311 | iwl_mvm_adjust_quota_for_noa(mvm, &cmd); |
| 312 | |
Johannes Berg | 99a1230 | 2014-05-23 16:13:57 +0200 | [diff] [blame] | 313 | /* check that we have non-zero quota for all valid bindings */ |
| 314 | for (i = 0; i < MAX_BINDINGS; i++) { |
Johannes Berg | b2b7875 | 2014-09-08 16:42:54 +0200 | [diff] [blame] | 315 | if (cmd.quotas[i].id_and_color != last->quotas[i].id_and_color) |
| 316 | send = true; |
| 317 | if (cmd.quotas[i].max_duration != last->quotas[i].max_duration) |
| 318 | send = true; |
| 319 | if (abs((int)le32_to_cpu(cmd.quotas[i].quota) - |
| 320 | (int)le32_to_cpu(last->quotas[i].quota)) |
| 321 | > IWL_MVM_QUOTA_THRESHOLD) |
| 322 | send = true; |
Johannes Berg | 99a1230 | 2014-05-23 16:13:57 +0200 | [diff] [blame] | 323 | if (cmd.quotas[i].id_and_color == cpu_to_le32(FW_CTXT_INVALID)) |
| 324 | continue; |
| 325 | WARN_ONCE(cmd.quotas[i].quota == 0, |
| 326 | "zero quota on binding %d\n", i); |
| 327 | } |
| 328 | |
Emmanuel Grumbach | 7754ae7 | 2015-02-26 15:14:35 +0200 | [diff] [blame] | 329 | if (!send && !force_update) { |
Johannes Berg | b2b7875 | 2014-09-08 16:42:54 +0200 | [diff] [blame] | 330 | /* don't send a practically unchanged command, the firmware has |
| 331 | * to re-initialize a lot of state and that can have an adverse |
| 332 | * impact on it |
| 333 | */ |
Johannes Berg | 3d4060d | 2014-09-11 14:12:06 +0200 | [diff] [blame] | 334 | return 0; |
Johannes Berg | b2b7875 | 2014-09-08 16:42:54 +0200 | [diff] [blame] | 335 | } |
| 336 | |
Johannes Berg | 3d4060d | 2014-09-11 14:12:06 +0200 | [diff] [blame] | 337 | err = iwl_mvm_send_cmd_pdu(mvm, TIME_QUOTA_CMD, 0, sizeof(cmd), &cmd); |
| 338 | |
Johannes Berg | b2b7875 | 2014-09-08 16:42:54 +0200 | [diff] [blame] | 339 | if (err) |
| 340 | IWL_ERR(mvm, "Failed to send quota: %d\n", err); |
| 341 | else |
| 342 | mvm->last_quota_cmd = cmd; |
| 343 | return err; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 344 | } |