1 /******************************************************************************
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.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 *****************************************************************************/
64 #include <net/mac80211.h>
68 #define QUOTA_100 IWL_MVM_MAX_QUOTA
69 #define QUOTA_LOWLAT_MIN ((QUOTA_100 * IWL_MVM_LOWLAT_QUOTA_MIN_PERCENT) / 100)
71 struct iwl_mvm_quota_iterator_data {
72 int n_interfaces[MAX_BINDINGS];
73 int colors[MAX_BINDINGS];
74 int low_latency[MAX_BINDINGS];
75 int n_low_latency_bindings;
76 struct ieee80211_vif *new_vif;
79 static void iwl_mvm_quota_iterator(void *_data, u8 *mac,
80 struct ieee80211_vif *vif)
82 struct iwl_mvm_quota_iterator_data *data = _data;
83 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
87 * We'll account for the new interface (if any) below,
88 * skip it here in case we're not called from within
89 * the add_interface callback (otherwise it won't show
92 if (vif == data->new_vif)
95 if (!mvmvif->phy_ctxt)
98 /* currently, PHY ID == binding ID */
99 id = mvmvif->phy_ctxt->id;
101 /* need at least one binding per PHY */
102 BUILD_BUG_ON(NUM_PHY_CTX > MAX_BINDINGS);
104 if (WARN_ON_ONCE(id >= MAX_BINDINGS))
107 if (data->colors[id] < 0)
108 data->colors[id] = mvmvif->phy_ctxt->color;
110 WARN_ON_ONCE(data->colors[id] != mvmvif->phy_ctxt->color);
113 case NL80211_IFTYPE_STATION:
114 if (vif->bss_conf.assoc)
117 case NL80211_IFTYPE_AP:
118 case NL80211_IFTYPE_ADHOC:
119 if (mvmvif->ap_ibss_active)
122 case NL80211_IFTYPE_MONITOR:
123 if (mvmvif->monitor_active)
126 case NL80211_IFTYPE_P2P_DEVICE:
133 data->n_interfaces[id]++;
135 if (iwl_mvm_vif_low_latency(mvmvif) && !data->low_latency[id]) {
136 data->n_low_latency_bindings++;
137 data->low_latency[id] = true;
141 static void iwl_mvm_adjust_quota_for_noa(struct iwl_mvm *mvm,
142 struct iwl_time_quota_cmd *cmd)
144 #ifdef CONFIG_NL80211_TESTMODE
145 struct iwl_mvm_vif *mvmvif;
146 int i, phy_id = -1, beacon_int = 0;
148 if (!mvm->noa_duration || !mvm->noa_vif)
151 mvmvif = iwl_mvm_vif_from_mac80211(mvm->noa_vif);
152 if (!mvmvif->ap_ibss_active)
155 phy_id = mvmvif->phy_ctxt->id;
156 beacon_int = mvm->noa_vif->bss_conf.beacon_int;
158 for (i = 0; i < MAX_BINDINGS; i++) {
159 u32 id_n_c = le32_to_cpu(cmd->quotas[i].id_and_color);
160 u32 id = (id_n_c & FW_CTXT_ID_MSK) >> FW_CTXT_ID_POS;
161 u32 quota = le32_to_cpu(cmd->quotas[i].quota);
166 quota *= (beacon_int - mvm->noa_duration);
169 cmd->quotas[i].quota = cpu_to_le32(quota);
174 int iwl_mvm_update_quotas(struct iwl_mvm *mvm, struct ieee80211_vif *newvif)
176 struct iwl_time_quota_cmd cmd = {};
177 int i, idx, ret, num_active_macs, quota, quota_rem, n_non_lowlat;
178 struct iwl_mvm_quota_iterator_data data = {
180 .colors = { -1, -1, -1, -1 },
185 lockdep_assert_held(&mvm->mutex);
187 /* update all upon completion */
188 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
191 /* iterator data above must match */
192 BUILD_BUG_ON(MAX_BINDINGS != 4);
194 ieee80211_iterate_active_interfaces_atomic(
195 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
196 iwl_mvm_quota_iterator, &data);
199 iwl_mvm_quota_iterator(&data, newvif->addr, newvif);
202 switch (data.n_low_latency_bindings) {
203 case 0: /* no low latency - use default */
206 case 1: /* SingleBindingLowLatencyMode */
207 ll_max_duration = IWL_MVM_LOWLAT_SINGLE_BINDING_MAXDUR;
209 case 2: /* DualBindingLowLatencyMode */
210 ll_max_duration = IWL_MVM_LOWLAT_DUAL_BINDING_MAXDUR;
212 default: /* MultiBindingLowLatencyMode */
218 * The FW's scheduling session consists of
219 * IWL_MVM_MAX_QUOTA fragments. Divide these fragments
220 * equally between all the bindings that require quota
223 for (i = 0; i < MAX_BINDINGS; i++) {
224 cmd.quotas[i].id_and_color = cpu_to_le32(FW_CTXT_INVALID);
225 num_active_macs += data.n_interfaces[i];
228 n_non_lowlat = num_active_macs;
230 if (data.n_low_latency_bindings == 1) {
231 for (i = 0; i < MAX_BINDINGS; i++) {
232 if (data.low_latency[i]) {
233 n_non_lowlat -= data.n_interfaces[i];
238 quota = (QUOTA_100 - QUOTA_LOWLAT_MIN) / n_non_lowlat;
239 quota_rem = QUOTA_100 - n_non_lowlat * quota -
245 } else if (num_active_macs) {
246 quota = QUOTA_100 / num_active_macs;
247 quota_rem = QUOTA_100 % num_active_macs;
249 /* values don't really matter - won't be used */
254 for (idx = 0, i = 0; i < MAX_BINDINGS; i++) {
255 if (data.colors[i] < 0)
258 cmd.quotas[idx].id_and_color =
259 cpu_to_le32(FW_CMD_ID_AND_COLOR(i, data.colors[i]));
261 if (data.n_interfaces[i] <= 0)
262 cmd.quotas[idx].quota = cpu_to_le32(0);
263 else if (data.n_low_latency_bindings == 1 && n_non_lowlat &&
265 cmd.quotas[idx].quota = cpu_to_le32(QUOTA_LOWLAT_MIN);
267 cmd.quotas[idx].quota =
268 cpu_to_le32(quota * data.n_interfaces[i]);
270 if (data.n_interfaces[i] && !data.low_latency[i])
271 cmd.quotas[idx].max_duration =
272 cpu_to_le32(ll_max_duration);
274 cmd.quotas[idx].max_duration = cpu_to_le32(0);
279 /* Give the remainder of the session to the first binding */
280 le32_add_cpu(&cmd.quotas[0].quota, quota_rem);
282 iwl_mvm_adjust_quota_for_noa(mvm, &cmd);
284 ret = iwl_mvm_send_cmd_pdu(mvm, TIME_QUOTA_CMD, CMD_SYNC,
287 IWL_ERR(mvm, "Failed to send quota: %d\n", ret);