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