blob: 770b0e2a9b46c36cf334105965f8c498f21dc668 [file] [log] [blame]
Emmanuel Grumbach931d4162013-01-17 09:42:25 +02001/******************************************************************************
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 Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +02009 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Emmanuel Grumbach931d4162013-01-17 09:42:25 +020010 *
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
26 * in the file called COPYING.
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 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020034 * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +020035 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Emmanuel Grumbach931d4162013-01-17 09:42:25 +020036 * 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
Emmanuel Grumbachee7bea52014-03-06 10:30:49 +020066#include <linux/ieee80211.h>
67#include <linux/etherdevice.h>
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +020068#include <net/mac80211.h>
69
Emmanuel Grumbach5b7ff612014-03-11 19:27:45 +020070#include "fw-api-coex.h"
Emmanuel Grumbach931d4162013-01-17 09:42:25 +020071#include "iwl-modparams.h"
72#include "mvm.h"
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +020073#include "iwl-debug.h"
Emmanuel Grumbach931d4162013-01-17 09:42:25 +020074
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +030075/* 20MHz / 40MHz below / 40Mhz above*/
76static const __le64 iwl_ci_mask[][3] = {
77 /* dummy entry for channel 0 */
78 {cpu_to_le64(0), cpu_to_le64(0), cpu_to_le64(0)},
79 {
80 cpu_to_le64(0x0000001FFFULL),
81 cpu_to_le64(0x0ULL),
82 cpu_to_le64(0x00007FFFFFULL),
83 },
84 {
85 cpu_to_le64(0x000000FFFFULL),
86 cpu_to_le64(0x0ULL),
87 cpu_to_le64(0x0003FFFFFFULL),
88 },
89 {
90 cpu_to_le64(0x000003FFFCULL),
91 cpu_to_le64(0x0ULL),
92 cpu_to_le64(0x000FFFFFFCULL),
93 },
94 {
95 cpu_to_le64(0x00001FFFE0ULL),
96 cpu_to_le64(0x0ULL),
97 cpu_to_le64(0x007FFFFFE0ULL),
98 },
99 {
100 cpu_to_le64(0x00007FFF80ULL),
101 cpu_to_le64(0x00007FFFFFULL),
102 cpu_to_le64(0x01FFFFFF80ULL),
103 },
104 {
105 cpu_to_le64(0x0003FFFC00ULL),
106 cpu_to_le64(0x0003FFFFFFULL),
107 cpu_to_le64(0x0FFFFFFC00ULL),
108 },
109 {
110 cpu_to_le64(0x000FFFF000ULL),
111 cpu_to_le64(0x000FFFFFFCULL),
112 cpu_to_le64(0x3FFFFFF000ULL),
113 },
114 {
115 cpu_to_le64(0x007FFF8000ULL),
116 cpu_to_le64(0x007FFFFFE0ULL),
117 cpu_to_le64(0xFFFFFF8000ULL),
118 },
119 {
120 cpu_to_le64(0x01FFFE0000ULL),
121 cpu_to_le64(0x01FFFFFF80ULL),
122 cpu_to_le64(0xFFFFFE0000ULL),
123 },
124 {
125 cpu_to_le64(0x0FFFF00000ULL),
126 cpu_to_le64(0x0FFFFFFC00ULL),
127 cpu_to_le64(0x0ULL),
128 },
129 {
130 cpu_to_le64(0x3FFFC00000ULL),
131 cpu_to_le64(0x3FFFFFF000ULL),
132 cpu_to_le64(0x0)
133 },
134 {
135 cpu_to_le64(0xFFFE000000ULL),
136 cpu_to_le64(0xFFFFFF8000ULL),
137 cpu_to_le64(0x0)
138 },
139 {
140 cpu_to_le64(0xFFF8000000ULL),
141 cpu_to_le64(0xFFFFFE0000ULL),
142 cpu_to_le64(0x0)
143 },
144 {
Emmanuel Grumbachd2ccc902013-12-24 10:55:24 +0200145 cpu_to_le64(0xFFC0000000ULL),
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300146 cpu_to_le64(0x0ULL),
Emmanuel Grumbachd2ccc902013-12-24 10:55:24 +0200147 cpu_to_le64(0x0ULL)
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300148 },
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200149};
150
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +0200151struct corunning_block_luts {
152 u8 range;
153 __le32 lut20[BT_COEX_CORUN_LUT_SIZE];
154};
155
156/*
157 * Ranges for the antenna coupling calibration / co-running block LUT:
158 * LUT0: [ 0, 12[
159 * LUT1: [12, 20[
160 * LUT2: [20, 21[
161 * LUT3: [21, 23[
162 * LUT4: [23, 27[
163 * LUT5: [27, 30[
164 * LUT6: [30, 32[
165 * LUT7: [32, 33[
166 * LUT8: [33, - [
167 */
168static const struct corunning_block_luts antenna_coupling_ranges[] = {
169 {
170 .range = 0,
171 .lut20 = {
172 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
173 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
174 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
175 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
176 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
177 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
178 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
179 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
180 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
181 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
182 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
183 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
184 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
185 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
186 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
187 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
188 },
189 },
190 {
191 .range = 12,
192 .lut20 = {
Emmanuel Grumbache583b502015-01-22 15:14:38 +0200193 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +0200194 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
195 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
196 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
197 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
198 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
199 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
200 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
201 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
202 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
203 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
204 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
205 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
206 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
207 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
208 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
209 },
210 },
211 {
212 .range = 20,
213 .lut20 = {
Emmanuel Grumbache583b502015-01-22 15:14:38 +0200214 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +0200215 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
216 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
217 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
218 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
219 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
220 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
221 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
222 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
223 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
224 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
225 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
226 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
227 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
228 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
229 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
230 },
231 },
232 {
233 .range = 21,
234 .lut20 = {
Emmanuel Grumbache583b502015-01-22 15:14:38 +0200235 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +0200236 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
237 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
238 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
239 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
240 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
241 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
242 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
243 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
244 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
245 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
246 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
247 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
248 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
249 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
250 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
251 },
252 },
253 {
254 .range = 23,
255 .lut20 = {
Emmanuel Grumbache583b502015-01-22 15:14:38 +0200256 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +0200257 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
258 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
259 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
260 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
261 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
262 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
263 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
264 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
265 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
266 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
267 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
268 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
269 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
270 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
271 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
272 },
273 },
274 {
275 .range = 27,
276 .lut20 = {
Emmanuel Grumbache583b502015-01-22 15:14:38 +0200277 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +0200278 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
279 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
280 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
281 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
282 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
283 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
284 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
285 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
286 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
287 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
288 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
289 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
290 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
291 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
292 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
293 },
294 },
295 {
296 .range = 30,
297 .lut20 = {
Emmanuel Grumbache583b502015-01-22 15:14:38 +0200298 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +0200299 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
300 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
301 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
302 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
303 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
304 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
305 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
306 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
307 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
308 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
309 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
310 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
311 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
312 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
313 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
314 },
315 },
316 {
317 .range = 32,
318 .lut20 = {
Emmanuel Grumbache583b502015-01-22 15:14:38 +0200319 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +0200320 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
321 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
322 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
323 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
324 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
325 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
326 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
327 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
328 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
329 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
330 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
331 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
332 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
333 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
334 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
335 },
336 },
337 {
338 .range = 33,
339 .lut20 = {
Emmanuel Grumbache583b502015-01-22 15:14:38 +0200340 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +0200341 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
342 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
343 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
344 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
345 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
346 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
347 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
348 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
349 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
350 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
351 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
352 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
353 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
354 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
355 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
356 },
357 },
358};
359
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300360static enum iwl_bt_coex_lut_type
361iwl_get_coex_type(struct iwl_mvm *mvm, const struct ieee80211_vif *vif)
362{
363 struct ieee80211_chanctx_conf *chanctx_conf;
364 enum iwl_bt_coex_lut_type ret;
365 u16 phy_ctx_id;
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300366 u32 primary_ch_phy_id, secondary_ch_phy_id;
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300367
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300368 /*
369 * Checking that we hold mvm->mutex is a good idea, but the rate
370 * control can't acquire the mutex since it runs in Tx path.
371 * So this is racy in that case, but in the worst case, the AMPDU
372 * size limit will be wrong for a short time which is not a big
373 * issue.
374 */
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300375
376 rcu_read_lock();
377
378 chanctx_conf = rcu_dereference(vif->chanctx_conf);
379
380 if (!chanctx_conf ||
381 chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ) {
382 rcu_read_unlock();
Emmanuel Grumbach7fa4fa02014-05-25 13:58:31 +0300383 return BT_COEX_INVALID_LUT;
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300384 }
385
386 ret = BT_COEX_TX_DIS_LUT;
387
Emmanuel Grumbach39149912013-07-14 13:40:21 +0300388 if (mvm->cfg->bt_shared_single_ant) {
389 rcu_read_unlock();
390 return ret;
391 }
392
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300393 phy_ctx_id = *((u16 *)chanctx_conf->drv_priv);
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300394 primary_ch_phy_id = le32_to_cpu(mvm->last_bt_ci_cmd.primary_ch_phy_id);
395 secondary_ch_phy_id =
396 le32_to_cpu(mvm->last_bt_ci_cmd.secondary_ch_phy_id);
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300397
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300398 if (primary_ch_phy_id == phy_ctx_id)
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300399 ret = le32_to_cpu(mvm->last_bt_notif.primary_ch_lut);
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300400 else if (secondary_ch_phy_id == phy_ctx_id)
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300401 ret = le32_to_cpu(mvm->last_bt_notif.secondary_ch_lut);
402 /* else - default = TX TX disallowed */
403
404 rcu_read_unlock();
405
406 return ret;
407}
408
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200409int iwl_send_bt_init_conf(struct iwl_mvm *mvm)
410{
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300411 struct iwl_bt_coex_cmd *bt_cmd;
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300412 struct iwl_host_cmd cmd = {
413 .id = BT_CONFIG,
414 .len = { sizeof(*bt_cmd), },
415 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200416 };
417 int ret;
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300418 u32 mode;
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300419
Emmanuel Grumbach0ea8d042014-04-02 09:31:36 +0300420 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
421 return iwl_send_bt_init_conf_old(mvm);
422
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300423 bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
424 if (!bt_cmd)
425 return -ENOMEM;
426 cmd.data[0] = bt_cmd;
427
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300428 lockdep_assert_held(&mvm->mutex);
429
430 if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) {
431 switch (mvm->bt_force_ant_mode) {
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300432 case BT_FORCE_ANT_BT:
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300433 mode = BT_COEX_BT;
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300434 break;
435 case BT_FORCE_ANT_WIFI:
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300436 mode = BT_COEX_WIFI;
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300437 break;
438 default:
439 WARN_ON(1);
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300440 mode = 0;
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300441 }
442
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300443 bt_cmd->mode = cpu_to_le32(mode);
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300444 goto send_cmd;
445 }
446
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300447 mode = iwlwifi_mod_params.bt_coex_active ? BT_COEX_NW : BT_COEX_DISABLE;
448 bt_cmd->mode = cpu_to_le32(mode);
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300449
Emmanuel Grumbach741e7032014-01-27 12:12:50 +0200450 if (IWL_MVM_BT_COEX_SYNC2SCO)
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300451 bt_cmd->enabled_modules |=
452 cpu_to_le32(BT_COEX_SYNC2SCO_ENABLED);
Emmanuel Grumbach741e7032014-01-27 12:12:50 +0200453
Emmanuel Grumbach05225882015-02-12 12:33:09 +0200454 if (iwl_mvm_bt_is_plcr_supported(mvm))
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300455 bt_cmd->enabled_modules |= cpu_to_le32(BT_COEX_CORUN_ENABLED);
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +0200456
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +0200457 if (IWL_MVM_BT_COEX_MPLUT) {
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300458 bt_cmd->enabled_modules |= cpu_to_le32(BT_COEX_MPLUT_ENABLED);
459 bt_cmd->enabled_modules |=
460 cpu_to_le32(BT_COEX_MPLUT_BOOST_ENABLED);
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +0200461 }
462
Emmanuel Grumbach261c0ec2014-06-11 15:37:25 +0300463 bt_cmd->enabled_modules |= cpu_to_le32(BT_COEX_HIGH_BAND_RET);
464
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300465send_cmd:
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300466 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300467 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300468
469 ret = iwl_mvm_send_cmd(mvm, &cmd);
470
471 kfree(bt_cmd);
472 return ret;
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200473}
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200474
Emmanuel Grumbach1fa477c2014-05-20 13:54:27 +0300475static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id,
476 bool enable)
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200477{
Emmanuel Grumbach455e7ac2014-05-22 12:48:27 +0300478 struct iwl_bt_coex_reduced_txp_update_cmd cmd = {};
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200479 struct iwl_mvm_sta *mvmsta;
Emmanuel Grumbach455e7ac2014-05-22 12:48:27 +0300480 u32 value;
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300481 int ret;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200482
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200483 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
484 if (!mvmsta)
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200485 return 0;
486
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200487 /* nothing to do */
Emmanuel Grumbach1fa477c2014-05-20 13:54:27 +0300488 if (mvmsta->bt_reduced_txpower == enable)
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200489 return 0;
490
Emmanuel Grumbach455e7ac2014-05-22 12:48:27 +0300491 value = mvmsta->sta_id;
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300492
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200493 if (enable)
Emmanuel Grumbach455e7ac2014-05-22 12:48:27 +0300494 value |= BT_REDUCED_TX_POWER_BIT;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200495
496 IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n",
497 enable ? "en" : "dis", sta_id);
498
Emmanuel Grumbach455e7ac2014-05-22 12:48:27 +0300499 cmd.reduced_txp = cpu_to_le32(value);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200500 mvmsta->bt_reduced_txpower = enable;
501
Emmanuel Grumbach455e7ac2014-05-22 12:48:27 +0300502 ret = iwl_mvm_send_cmd_pdu(mvm, BT_COEX_UPDATE_REDUCED_TXP, CMD_ASYNC,
503 sizeof(cmd), &cmd);
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300504
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300505 return ret;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200506}
507
508struct iwl_bt_iterator_data {
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300509 struct iwl_bt_coex_profile_notif *notif;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200510 struct iwl_mvm *mvm;
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300511 struct ieee80211_chanctx_conf *primary;
512 struct ieee80211_chanctx_conf *secondary;
Emmanuel Grumbach0ee5bcd2014-01-15 16:57:54 +0200513 bool primary_ll;
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200514};
515
Emmanuel Grumbachf6fc5772013-09-08 08:57:15 +0300516static inline
517void iwl_mvm_bt_coex_enable_rssi_event(struct iwl_mvm *mvm,
518 struct ieee80211_vif *vif,
519 bool enable, int rssi)
520{
521 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
522
523 mvmvif->bf_data.last_bt_coex_event = rssi;
524 mvmvif->bf_data.bt_coex_max_thold =
Emmanuel Grumbach8286d9f2014-05-27 22:54:18 +0300525 enable ? -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH : 0;
Emmanuel Grumbachf6fc5772013-09-08 08:57:15 +0300526 mvmvif->bf_data.bt_coex_min_thold =
Emmanuel Grumbach8286d9f2014-05-27 22:54:18 +0300527 enable ? -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH : 0;
Emmanuel Grumbachf6fc5772013-09-08 08:57:15 +0300528}
529
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300530/* must be called under rcu_read_lock */
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200531static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac,
532 struct ieee80211_vif *vif)
533{
534 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200535 struct iwl_bt_iterator_data *data = _data;
536 struct iwl_mvm *mvm = data->mvm;
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200537 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg582de302014-08-21 19:08:44 +0200538 /* default smps_mode is AUTOMATIC - only used for client modes */
539 enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_AUTOMATIC;
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200540 u32 bt_activity_grading;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200541 int ave_rssi;
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200542
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300543 lockdep_assert_held(&mvm->mutex);
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200544
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200545 switch (vif->type) {
546 case NL80211_IFTYPE_STATION:
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200547 break;
548 case NL80211_IFTYPE_AP:
Emmanuel Grumbach45bbb2c2014-07-07 14:38:39 +0300549 if (!mvmvif->ap_ibss_active)
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200550 return;
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200551 break;
552 default:
553 return;
554 }
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200555
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300556 chanctx_conf = rcu_dereference(vif->chanctx_conf);
557
558 /* If channel context is invalid or not on 2.4GHz .. */
559 if ((!chanctx_conf ||
560 chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ)) {
Emmanuel Grumbach0f618e62014-05-20 15:48:18 +0300561 if (vif->type == NL80211_IFTYPE_STATION) {
Emmanuel Grumbach45bbb2c2014-07-07 14:38:39 +0300562 /* ... relax constraints and disable rssi events */
563 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
564 smps_mode);
Emmanuel Grumbach0f618e62014-05-20 15:48:18 +0300565 iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
566 false);
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200567 iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
Emmanuel Grumbach0f618e62014-05-20 15:48:18 +0300568 }
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300569 return;
570 }
571
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200572 bt_activity_grading = le32_to_cpu(data->notif->bt_activity_grading);
573 if (bt_activity_grading >= BT_HIGH_TRAFFIC)
574 smps_mode = IEEE80211_SMPS_STATIC;
575 else if (bt_activity_grading >= BT_LOW_TRAFFIC)
Emmanuel Grumbach45bbb2c2014-07-07 14:38:39 +0300576 smps_mode = IEEE80211_SMPS_DYNAMIC;
Emmanuel Grumbach4d664492014-04-30 18:09:59 +0300577
Johannes Berg582de302014-08-21 19:08:44 +0200578 /* relax SMPS constraints for next association */
Emmanuel Grumbach4d664492014-04-30 18:09:59 +0300579 if (!vif->bss_conf.assoc)
580 smps_mode = IEEE80211_SMPS_AUTOMATIC;
581
Emmanuel Grumbach4cd4b502015-03-05 13:43:15 +0200582 if (mvmvif->phy_ctxt &&
583 IWL_COEX_IS_RRC_ON(mvm->last_bt_notif.ttc_rrc_status,
Emmanuel Grumbach4c86f932014-06-30 10:26:02 +0300584 mvmvif->phy_ctxt->id))
585 smps_mode = IEEE80211_SMPS_AUTOMATIC;
586
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200587 IWL_DEBUG_COEX(data->mvm,
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300588 "mac %d: bt_activity_grading %d smps_req %d\n",
589 mvmvif->id, bt_activity_grading, smps_mode);
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200590
Emmanuel Grumbach45bbb2c2014-07-07 14:38:39 +0300591 if (vif->type == NL80211_IFTYPE_STATION)
592 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
593 smps_mode);
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200594
Emmanuel Grumbach0ee5bcd2014-01-15 16:57:54 +0200595 /* low latency is always primary */
596 if (iwl_mvm_vif_low_latency(mvmvif)) {
597 data->primary_ll = true;
598
599 data->secondary = data->primary;
600 data->primary = chanctx_conf;
601 }
602
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300603 if (vif->type == NL80211_IFTYPE_AP) {
Johannes Berg5023d962013-07-31 14:07:43 +0200604 if (!mvmvif->ap_ibss_active)
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300605 return;
606
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300607 if (chanctx_conf == data->primary)
608 return;
609
Emmanuel Grumbach0ee5bcd2014-01-15 16:57:54 +0200610 if (!data->primary_ll) {
611 /*
612 * downgrade the current primary no matter what its
613 * type is.
614 */
615 data->secondary = data->primary;
616 data->primary = chanctx_conf;
617 } else {
618 /* there is low latency vif - we will be secondary */
619 data->secondary = chanctx_conf;
620 }
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300621 return;
622 }
623
Emmanuel Grumbach0ee5bcd2014-01-15 16:57:54 +0200624 /*
625 * STA / P2P Client, try to be primary if first vif. If we are in low
626 * latency mode, we are already in primary and just don't do much
627 */
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300628 if (!data->primary || data->primary == chanctx_conf)
629 data->primary = chanctx_conf;
630 else if (!data->secondary)
631 /* if secondary is not NULL, it might be a GO */
632 data->secondary = chanctx_conf;
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200633
Emmanuel Grumbach4d664492014-04-30 18:09:59 +0300634 /*
635 * don't reduce the Tx power if one of these is true:
636 * we are in LOOSE
637 * single share antenna product
638 * BT is active
639 * we are associated
640 */
Emmanuel Grumbach39149912013-07-14 13:40:21 +0300641 if (iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT ||
Emmanuel Grumbach4d664492014-04-30 18:09:59 +0300642 mvm->cfg->bt_shared_single_ant || !vif->bss_conf.assoc ||
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300643 le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF) {
Emmanuel Grumbach0f618e62014-05-20 15:48:18 +0300644 iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false);
Emmanuel Grumbachf6fc5772013-09-08 08:57:15 +0300645 iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200646 return;
Emmanuel Grumbach39149912013-07-14 13:40:21 +0300647 }
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200648
Andrei Otcheretianski911222b2013-07-21 17:37:19 +0300649 /* try to get the avg rssi from fw */
650 ave_rssi = mvmvif->bf_data.ave_beacon_signal;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200651
652 /* if the RSSI isn't valid, fake it is very low */
653 if (!ave_rssi)
654 ave_rssi = -100;
Emmanuel Grumbach8286d9f2014-05-27 22:54:18 +0300655 if (ave_rssi > -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH) {
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200656 if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true))
657 IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
Emmanuel Grumbach8286d9f2014-05-27 22:54:18 +0300658 } else if (ave_rssi < -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH) {
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200659 if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
660 IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200661 }
662
663 /* Begin to monitor the RSSI: it may influence the reduced Tx power */
Emmanuel Grumbachf6fc5772013-09-08 08:57:15 +0300664 iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, true, ave_rssi);
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200665}
666
Emmanuel Grumbachd37cac92013-03-29 14:56:19 +0300667static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm)
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200668{
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200669 struct iwl_bt_iterator_data data = {
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200670 .mvm = mvm,
Emmanuel Grumbachd37cac92013-03-29 14:56:19 +0300671 .notif = &mvm->last_bt_notif,
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200672 };
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300673 struct iwl_bt_coex_ci_cmd cmd = {};
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300674 u8 ci_bw_idx;
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200675
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300676 /* Ignore updates if we are in force mode */
677 if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
678 return;
679
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300680 rcu_read_lock();
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200681 ieee80211_iterate_active_interfaces_atomic(
682 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
683 iwl_mvm_bt_notif_iterator, &data);
684
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300685 if (data.primary) {
686 struct ieee80211_chanctx_conf *chan = data.primary;
687 if (WARN_ON(!chan->def.chan)) {
688 rcu_read_unlock();
689 return;
690 }
691
692 if (chan->def.width < NL80211_CHAN_WIDTH_40) {
693 ci_bw_idx = 0;
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300694 } else {
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300695 if (chan->def.center_freq1 >
696 chan->def.chan->center_freq)
697 ci_bw_idx = 2;
698 else
699 ci_bw_idx = 1;
700 }
701
702 cmd.bt_primary_ci =
703 iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300704 cmd.primary_ch_phy_id =
705 cpu_to_le32(*((u16 *)data.primary->drv_priv));
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300706 }
707
708 if (data.secondary) {
709 struct ieee80211_chanctx_conf *chan = data.secondary;
710 if (WARN_ON(!data.secondary->def.chan)) {
711 rcu_read_unlock();
712 return;
713 }
714
715 if (chan->def.width < NL80211_CHAN_WIDTH_40) {
716 ci_bw_idx = 0;
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300717 } else {
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300718 if (chan->def.center_freq1 >
719 chan->def.chan->center_freq)
720 ci_bw_idx = 2;
721 else
722 ci_bw_idx = 1;
723 }
724
725 cmd.bt_secondary_ci =
726 iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300727 cmd.secondary_ch_phy_id =
728 cpu_to_le32(*((u16 *)data.secondary->drv_priv));
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300729 }
730
731 rcu_read_unlock();
732
733 /* Don't spam the fw with the same command over and over */
734 if (memcmp(&cmd, &mvm->last_bt_ci_cmd, sizeof(cmd))) {
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300735 if (iwl_mvm_send_cmd_pdu(mvm, BT_COEX_CI, 0,
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300736 sizeof(cmd), &cmd))
Johannes Berg3c6acb62014-05-07 11:47:53 +0200737 IWL_ERR(mvm, "Failed to send BT_CI cmd\n");
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300738 memcpy(&mvm->last_bt_ci_cmd, &cmd, sizeof(cmd));
739 }
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200740}
741
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200742int iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm,
743 struct iwl_rx_cmd_buffer *rxb,
744 struct iwl_device_cmd *dev_cmd)
745{
746 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Emmanuel Grumbachdf878f32014-04-02 12:23:09 +0300747 struct iwl_bt_coex_profile_notif *notif = (void *)pkt->data;
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200748
Emmanuel Grumbach0ea8d042014-04-02 09:31:36 +0300749 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
750 return iwl_mvm_rx_bt_coex_notif_old(mvm, rxb, dev_cmd);
751
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200752 IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n");
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300753 IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n", notif->bt_ci_compliance);
754 IWL_DEBUG_COEX(mvm, "\tBT primary_ch_lut %d\n",
755 le32_to_cpu(notif->primary_ch_lut));
756 IWL_DEBUG_COEX(mvm, "\tBT secondary_ch_lut %d\n",
757 le32_to_cpu(notif->secondary_ch_lut));
758 IWL_DEBUG_COEX(mvm, "\tBT activity grading %d\n",
759 le32_to_cpu(notif->bt_activity_grading));
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200760
Emmanuel Grumbachd37cac92013-03-29 14:56:19 +0300761 /* remember this notification for future use: rssi fluctuations */
762 memcpy(&mvm->last_bt_notif, notif, sizeof(mvm->last_bt_notif));
763
764 iwl_mvm_bt_coex_notif_handle(mvm);
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200765
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200766 /*
767 * This is an async handler for a notification, returning anything other
768 * than 0 doesn't make sense even if HCMD failed.
769 */
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200770 return 0;
771}
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200772
773static void iwl_mvm_bt_rssi_iterator(void *_data, u8 *mac,
774 struct ieee80211_vif *vif)
775{
Johannes Berg5b530e92014-12-23 16:00:17 +0100776 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200777 struct iwl_bt_iterator_data *data = _data;
778 struct iwl_mvm *mvm = data->mvm;
779
780 struct ieee80211_sta *sta;
781 struct iwl_mvm_sta *mvmsta;
782
Emmanuel Grumbachf6fc5772013-09-08 08:57:15 +0300783 struct ieee80211_chanctx_conf *chanctx_conf;
784
785 rcu_read_lock();
786 chanctx_conf = rcu_dereference(vif->chanctx_conf);
787 /* If channel context is invalid or not on 2.4GHz - don't count it */
788 if (!chanctx_conf ||
789 chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ) {
790 rcu_read_unlock();
791 return;
792 }
793 rcu_read_unlock();
794
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200795 if (vif->type != NL80211_IFTYPE_STATION ||
796 mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
797 return;
798
799 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
800 lockdep_is_held(&mvm->mutex));
Emmanuel Grumbach56c07a92013-10-21 11:03:53 +0300801
802 /* This can happen if the station has been removed right now */
803 if (IS_ERR_OR_NULL(sta))
804 return;
805
Johannes Berg5b577a92013-11-14 18:20:04 +0100806 mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200807}
808
809void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
810 enum ieee80211_rssi_event rssi_event)
811{
Johannes Berg5b530e92014-12-23 16:00:17 +0100812 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200813 struct iwl_bt_iterator_data data = {
814 .mvm = mvm,
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200815 };
816 int ret;
817
Emmanuel Grumbach0ea8d042014-04-02 09:31:36 +0300818 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
819 iwl_mvm_bt_rssi_event_old(mvm, vif, rssi_event);
820 return;
821 }
822
Johannes Berg3dd1cd22013-10-02 12:05:24 +0200823 lockdep_assert_held(&mvm->mutex);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200824
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300825 /* Ignore updates if we are in force mode */
826 if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
827 return;
828
Emmanuel Grumbach1e929192014-03-04 10:28:23 +0200829 /*
830 * Rssi update while not associated - can happen since the statistics
831 * are handled asynchronously
832 */
833 if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
Johannes Berg3dd1cd22013-10-02 12:05:24 +0200834 return;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200835
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300836 /* No BT - reports should be disabled */
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300837 if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF)
Johannes Berg3dd1cd22013-10-02 12:05:24 +0200838 return;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200839
840 IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid,
841 rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW");
842
843 /*
844 * Check if rssi is good enough for reduced Tx power, but not in loose
845 * scheme.
846 */
Emmanuel Grumbach39149912013-07-14 13:40:21 +0300847 if (rssi_event == RSSI_EVENT_LOW || mvm->cfg->bt_shared_single_ant ||
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300848 iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT)
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200849 ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
850 false);
851 else
852 ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true);
853
854 if (ret)
855 IWL_ERR(mvm, "couldn't send BT_CONFIG HCMD upon RSSI event\n");
856
857 ieee80211_iterate_active_interfaces_atomic(
858 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
859 iwl_mvm_bt_rssi_iterator, &data);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200860}
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200861
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300862#define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000)
863#define LINK_QUAL_AGG_TIME_LIMIT_BT_ACT (1200)
864
Emmanuel Grumbach5b7ff612014-03-11 19:27:45 +0200865u16 iwl_mvm_coex_agg_time_limit(struct iwl_mvm *mvm,
866 struct ieee80211_sta *sta)
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300867{
Johannes Berg5b577a92013-11-14 18:20:04 +0100868 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbach4c86f932014-06-30 10:26:02 +0300869 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
870 struct iwl_mvm_phy_ctxt *phy_ctxt = mvmvif->phy_ctxt;
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300871 enum iwl_bt_coex_lut_type lut_type;
872
Emmanuel Grumbach0ea8d042014-04-02 09:31:36 +0300873 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
874 return iwl_mvm_coex_agg_time_limit_old(mvm, sta);
875
Emmanuel Grumbach4c86f932014-06-30 10:26:02 +0300876 if (IWL_COEX_IS_TTC_ON(mvm->last_bt_notif.ttc_rrc_status, phy_ctxt->id))
877 return LINK_QUAL_AGG_TIME_LIMIT_DEF;
878
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300879 if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) <
Emmanuel Grumbachc2119352013-11-13 22:00:30 +0200880 BT_HIGH_TRAFFIC)
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300881 return LINK_QUAL_AGG_TIME_LIMIT_DEF;
Emmanuel Grumbach35fbf5d2014-06-02 16:18:42 +0300882
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300883 lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
884
Emmanuel Grumbach7fa4fa02014-05-25 13:58:31 +0300885 if (lut_type == BT_COEX_LOOSE_LUT || lut_type == BT_COEX_INVALID_LUT)
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300886 return LINK_QUAL_AGG_TIME_LIMIT_DEF;
887
888 /* tight coex, high bt traffic, reduce AGG time limit */
889 return LINK_QUAL_AGG_TIME_LIMIT_BT_ACT;
890}
891
Emmanuel Grumbachffa6c702013-10-06 11:41:20 +0300892bool iwl_mvm_bt_coex_is_mimo_allowed(struct iwl_mvm *mvm,
893 struct ieee80211_sta *sta)
894{
Johannes Berg5b577a92013-11-14 18:20:04 +0100895 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbach4c86f932014-06-30 10:26:02 +0300896 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
897 struct iwl_mvm_phy_ctxt *phy_ctxt = mvmvif->phy_ctxt;
Emmanuel Grumbach7fa4fa02014-05-25 13:58:31 +0300898 enum iwl_bt_coex_lut_type lut_type;
Emmanuel Grumbachffa6c702013-10-06 11:41:20 +0300899
Emmanuel Grumbach0ea8d042014-04-02 09:31:36 +0300900 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
Emmanuel Grumbach5fc7d862014-07-08 08:44:31 +0300901 return iwl_mvm_bt_coex_is_mimo_allowed_old(mvm, sta);
Emmanuel Grumbach0ea8d042014-04-02 09:31:36 +0300902
Emmanuel Grumbach4c86f932014-06-30 10:26:02 +0300903 if (IWL_COEX_IS_TTC_ON(mvm->last_bt_notif.ttc_rrc_status, phy_ctxt->id))
Emmanuel Grumbach35fbf5d2014-06-02 16:18:42 +0300904 return true;
905
Emmanuel Grumbachffa6c702013-10-06 11:41:20 +0300906 if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) <
907 BT_HIGH_TRAFFIC)
908 return true;
909
910 /*
Emmanuel Grumbach7fa4fa02014-05-25 13:58:31 +0300911 * In Tight / TxTxDis, BT can't Rx while we Tx, so use both antennas
912 * since BT is already killed.
913 * In Loose, BT can Rx while we Tx, so forbid MIMO to let BT Rx while
914 * we Tx.
915 * When we are in 5GHz, we'll get BT_COEX_INVALID_LUT allowing MIMO.
Emmanuel Grumbachffa6c702013-10-06 11:41:20 +0300916 */
Emmanuel Grumbach7fa4fa02014-05-25 13:58:31 +0300917 lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
918 return lut_type != BT_COEX_LOOSE_LUT;
Emmanuel Grumbachffa6c702013-10-06 11:41:20 +0300919}
920
Emmanuel Grumbach219fb662014-10-30 11:59:40 +0200921bool iwl_mvm_bt_coex_is_ant_avail(struct iwl_mvm *mvm, u8 ant)
922{
923 /* there is no other antenna, shared antenna is always available */
924 if (mvm->cfg->bt_shared_single_ant)
925 return true;
926
927 if (ant & mvm->cfg->non_shared_ant)
928 return true;
929
930 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
931 return iwl_mvm_bt_coex_is_shared_ant_avail_old(mvm);
932
933 return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) <
934 BT_HIGH_TRAFFIC;
935}
936
Emmanuel Grumbach34c8b242014-05-28 21:53:39 +0300937bool iwl_mvm_bt_coex_is_shared_ant_avail(struct iwl_mvm *mvm)
938{
Emmanuel Grumbachbbab7582014-09-10 11:00:16 +0300939 /* there is no other antenna, shared antenna is always available */
940 if (mvm->cfg->bt_shared_single_ant)
941 return true;
942
Emmanuel Grumbach0ea8d042014-04-02 09:31:36 +0300943 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
944 return iwl_mvm_bt_coex_is_shared_ant_avail_old(mvm);
945
Emmanuel Grumbach34c8b242014-05-28 21:53:39 +0300946 return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF;
947}
948
Eliad Peller2fd647f2014-03-13 17:21:36 +0200949bool iwl_mvm_bt_coex_is_tpc_allowed(struct iwl_mvm *mvm,
950 enum ieee80211_band band)
951{
952 u32 bt_activity = le32_to_cpu(mvm->last_bt_notif.bt_activity_grading);
953
Emmanuel Grumbach0ea8d042014-04-02 09:31:36 +0300954 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
955 return iwl_mvm_bt_coex_is_tpc_allowed_old(mvm, band);
956
Eliad Peller2fd647f2014-03-13 17:21:36 +0200957 if (band != IEEE80211_BAND_2GHZ)
958 return false;
959
960 return bt_activity >= BT_LOW_TRAFFIC;
961}
962
Emmanuel Grumbachee7bea52014-03-06 10:30:49 +0200963u8 iwl_mvm_bt_coex_tx_prio(struct iwl_mvm *mvm, struct ieee80211_hdr *hdr,
Emmanuel Grumbachb797e3f2014-03-06 14:49:36 +0200964 struct ieee80211_tx_info *info, u8 ac)
Emmanuel Grumbachee7bea52014-03-06 10:30:49 +0200965{
966 __le16 fc = hdr->frame_control;
967
Emmanuel Grumbachb797e3f2014-03-06 14:49:36 +0200968 if (info->band != IEEE80211_BAND_2GHZ)
969 return 0;
970
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +0200971 if (unlikely(mvm->bt_tx_prio))
972 return mvm->bt_tx_prio - 1;
973
Emmanuel Grumbachee7bea52014-03-06 10:30:49 +0200974 /* High prio packet (wrt. BT coex) if it is EAPOL, MCAST or MGMT */
Emmanuel Grumbachb797e3f2014-03-06 14:49:36 +0200975 if (info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO ||
Emmanuel Grumbachee7bea52014-03-06 10:30:49 +0200976 is_multicast_ether_addr(hdr->addr1) ||
Emmanuel Grumbachb797e3f2014-03-06 14:49:36 +0200977 ieee80211_is_ctl(fc) || ieee80211_is_mgmt(fc) ||
978 ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc))
979 return 3;
980
981 switch (ac) {
982 case IEEE80211_AC_BE:
983 return 1;
984 case IEEE80211_AC_VO:
985 return 3;
986 case IEEE80211_AC_VI:
Emmanuel Grumbachee7bea52014-03-06 10:30:49 +0200987 return 2;
Emmanuel Grumbachb797e3f2014-03-06 14:49:36 +0200988 default:
989 break;
990 }
Emmanuel Grumbachee7bea52014-03-06 10:30:49 +0200991
992 return 0;
993}
994
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +0300995void iwl_mvm_bt_coex_vif_change(struct iwl_mvm *mvm)
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200996{
Emmanuel Grumbach0ea8d042014-04-02 09:31:36 +0300997 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
998 iwl_mvm_bt_coex_vif_change_old(mvm);
999 return;
1000 }
1001
Emmanuel Grumbachd37cac92013-03-29 14:56:19 +03001002 iwl_mvm_bt_coex_notif_handle(mvm);
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +02001003}
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +02001004
1005int iwl_mvm_rx_ant_coupling_notif(struct iwl_mvm *mvm,
1006 struct iwl_rx_cmd_buffer *rxb,
1007 struct iwl_device_cmd *dev_cmd)
1008{
1009 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1010 u32 ant_isolation = le32_to_cpup((void *)pkt->data);
Emmanuel Grumbach704602a2014-04-02 12:23:09 +03001011 struct iwl_bt_coex_corun_lut_update_cmd cmd = {};
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +02001012 u8 __maybe_unused lower_bound, upper_bound;
1013 u8 lut;
1014
Emmanuel Grumbach0ea8d042014-04-02 09:31:36 +03001015 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
1016 return iwl_mvm_rx_ant_coupling_notif_old(mvm, rxb, dev_cmd);
1017
Emmanuel Grumbach05225882015-02-12 12:33:09 +02001018 if (!iwl_mvm_bt_is_plcr_supported(mvm))
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +02001019 return 0;
1020
1021 lockdep_assert_held(&mvm->mutex);
1022
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +03001023 /* Ignore updates if we are in force mode */
1024 if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
1025 return 0;
1026
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +02001027 if (ant_isolation == mvm->last_ant_isol)
1028 return 0;
1029
1030 for (lut = 0; lut < ARRAY_SIZE(antenna_coupling_ranges) - 1; lut++)
1031 if (ant_isolation < antenna_coupling_ranges[lut + 1].range)
1032 break;
1033
1034 lower_bound = antenna_coupling_ranges[lut].range;
1035
1036 if (lut < ARRAY_SIZE(antenna_coupling_ranges) - 1)
1037 upper_bound = antenna_coupling_ranges[lut + 1].range;
1038 else
1039 upper_bound = antenna_coupling_ranges[lut].range;
1040
1041 IWL_DEBUG_COEX(mvm, "Antenna isolation=%d in range [%d,%d[, lut=%d\n",
1042 ant_isolation, lower_bound, upper_bound, lut);
1043
1044 mvm->last_ant_isol = ant_isolation;
1045
1046 if (mvm->last_corun_lut == lut)
1047 return 0;
1048
1049 mvm->last_corun_lut = lut;
1050
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +02001051 /* For the moment, use the same LUT for 20GHz and 40GHz */
Emmanuel Grumbach704602a2014-04-02 12:23:09 +03001052 memcpy(&cmd.corun_lut20, antenna_coupling_ranges[lut].lut20,
1053 sizeof(cmd.corun_lut20));
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +02001054
Emmanuel Grumbach704602a2014-04-02 12:23:09 +03001055 memcpy(&cmd.corun_lut40, antenna_coupling_ranges[lut].lut20,
1056 sizeof(cmd.corun_lut40));
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +02001057
Emmanuel Grumbach704602a2014-04-02 12:23:09 +03001058 return iwl_mvm_send_cmd_pdu(mvm, BT_COEX_UPDATE_CORUN_LUT, 0,
1059 sizeof(cmd), &cmd);
Emmanuel Grumbachb9fae2d2014-02-17 11:24:10 +02001060}