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) 2013 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
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.
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.
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,
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
28 * Contact Information:
29 * Intel Linux Wireless <linuxwifi@intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
34 * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
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
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.
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.
64 *****************************************************************************/
66 #include <linux/ieee80211.h>
67 #include <linux/etherdevice.h>
68 #include <net/mac80211.h>
70 #include "fw-api-coex.h"
71 #include "iwl-modparams.h"
73 #include "iwl-debug.h"
75 /* 20MHz / 40MHz below / 40Mhz above*/
76 static 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)},
80 cpu_to_le64(0x0000001FFFULL
),
82 cpu_to_le64(0x00007FFFFFULL
),
85 cpu_to_le64(0x000000FFFFULL
),
87 cpu_to_le64(0x0003FFFFFFULL
),
90 cpu_to_le64(0x000003FFFCULL
),
92 cpu_to_le64(0x000FFFFFFCULL
),
95 cpu_to_le64(0x00001FFFE0ULL
),
97 cpu_to_le64(0x007FFFFFE0ULL
),
100 cpu_to_le64(0x00007FFF80ULL
),
101 cpu_to_le64(0x00007FFFFFULL
),
102 cpu_to_le64(0x01FFFFFF80ULL
),
105 cpu_to_le64(0x0003FFFC00ULL
),
106 cpu_to_le64(0x0003FFFFFFULL
),
107 cpu_to_le64(0x0FFFFFFC00ULL
),
110 cpu_to_le64(0x000FFFF000ULL
),
111 cpu_to_le64(0x000FFFFFFCULL
),
112 cpu_to_le64(0x3FFFFFF000ULL
),
115 cpu_to_le64(0x007FFF8000ULL
),
116 cpu_to_le64(0x007FFFFFE0ULL
),
117 cpu_to_le64(0xFFFFFF8000ULL
),
120 cpu_to_le64(0x01FFFE0000ULL
),
121 cpu_to_le64(0x01FFFFFF80ULL
),
122 cpu_to_le64(0xFFFFFE0000ULL
),
125 cpu_to_le64(0x0FFFF00000ULL
),
126 cpu_to_le64(0x0FFFFFFC00ULL
),
130 cpu_to_le64(0x3FFFC00000ULL
),
131 cpu_to_le64(0x3FFFFFF000ULL
),
135 cpu_to_le64(0xFFFE000000ULL
),
136 cpu_to_le64(0xFFFFFF8000ULL
),
140 cpu_to_le64(0xFFF8000000ULL
),
141 cpu_to_le64(0xFFFFFE0000ULL
),
145 cpu_to_le64(0xFFC0000000ULL
),
151 struct corunning_block_luts
{
153 __le32 lut20
[BT_COEX_CORUN_LUT_SIZE
];
157 * Ranges for the antenna coupling calibration / co-running block LUT:
168 static const struct corunning_block_luts antenna_coupling_ranges
[] = {
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),
193 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
194 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),
214 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
215 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),
235 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
236 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),
256 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
257 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),
277 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
278 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),
298 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
299 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),
319 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
320 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),
340 cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
341 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),
360 static enum iwl_bt_coex_lut_type
361 iwl_get_coex_type(struct iwl_mvm
*mvm
, const struct ieee80211_vif
*vif
)
363 struct ieee80211_chanctx_conf
*chanctx_conf
;
364 enum iwl_bt_coex_lut_type ret
;
366 u32 primary_ch_phy_id
, secondary_ch_phy_id
;
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
378 chanctx_conf
= rcu_dereference(vif
->chanctx_conf
);
381 chanctx_conf
->def
.chan
->band
!= NL80211_BAND_2GHZ
) {
383 return BT_COEX_INVALID_LUT
;
386 ret
= BT_COEX_TX_DIS_LUT
;
388 if (mvm
->cfg
->bt_shared_single_ant
) {
393 phy_ctx_id
= *((u16
*)chanctx_conf
->drv_priv
);
394 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
);
398 if (primary_ch_phy_id
== phy_ctx_id
)
399 ret
= le32_to_cpu(mvm
->last_bt_notif
.primary_ch_lut
);
400 else if (secondary_ch_phy_id
== phy_ctx_id
)
401 ret
= le32_to_cpu(mvm
->last_bt_notif
.secondary_ch_lut
);
402 /* else - default = TX TX disallowed */
409 int iwl_send_bt_init_conf(struct iwl_mvm
*mvm
)
411 struct iwl_bt_coex_cmd bt_cmd
= {};
414 lockdep_assert_held(&mvm
->mutex
);
416 if (unlikely(mvm
->bt_force_ant_mode
!= BT_FORCE_ANT_DIS
)) {
417 switch (mvm
->bt_force_ant_mode
) {
418 case BT_FORCE_ANT_BT
:
421 case BT_FORCE_ANT_WIFI
:
429 bt_cmd
.mode
= cpu_to_le32(mode
);
433 mode
= iwlwifi_mod_params
.bt_coex_active
? BT_COEX_NW
: BT_COEX_DISABLE
;
434 bt_cmd
.mode
= cpu_to_le32(mode
);
436 if (IWL_MVM_BT_COEX_SYNC2SCO
)
437 bt_cmd
.enabled_modules
|=
438 cpu_to_le32(BT_COEX_SYNC2SCO_ENABLED
);
440 if (iwl_mvm_bt_is_plcr_supported(mvm
))
441 bt_cmd
.enabled_modules
|= cpu_to_le32(BT_COEX_CORUN_ENABLED
);
443 if (iwl_mvm_is_mplut_supported(mvm
))
444 bt_cmd
.enabled_modules
|= cpu_to_le32(BT_COEX_MPLUT_ENABLED
);
446 bt_cmd
.enabled_modules
|= cpu_to_le32(BT_COEX_HIGH_BAND_RET
);
449 memset(&mvm
->last_bt_notif
, 0, sizeof(mvm
->last_bt_notif
));
450 memset(&mvm
->last_bt_ci_cmd
, 0, sizeof(mvm
->last_bt_ci_cmd
));
452 return iwl_mvm_send_cmd_pdu(mvm
, BT_CONFIG
, 0, sizeof(bt_cmd
), &bt_cmd
);
455 static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm
*mvm
, u8 sta_id
,
458 struct iwl_bt_coex_reduced_txp_update_cmd cmd
= {};
459 struct iwl_mvm_sta
*mvmsta
;
463 mvmsta
= iwl_mvm_sta_from_staid_protected(mvm
, sta_id
);
468 if (mvmsta
->bt_reduced_txpower
== enable
)
471 value
= mvmsta
->sta_id
;
474 value
|= BT_REDUCED_TX_POWER_BIT
;
476 IWL_DEBUG_COEX(mvm
, "%sable reduced Tx Power for sta %d\n",
477 enable
? "en" : "dis", sta_id
);
479 cmd
.reduced_txp
= cpu_to_le32(value
);
480 mvmsta
->bt_reduced_txpower
= enable
;
482 ret
= iwl_mvm_send_cmd_pdu(mvm
, BT_COEX_UPDATE_REDUCED_TXP
, CMD_ASYNC
,
488 struct iwl_bt_iterator_data
{
489 struct iwl_bt_coex_profile_notif
*notif
;
491 struct ieee80211_chanctx_conf
*primary
;
492 struct ieee80211_chanctx_conf
*secondary
;
497 void iwl_mvm_bt_coex_enable_rssi_event(struct iwl_mvm
*mvm
,
498 struct ieee80211_vif
*vif
,
499 bool enable
, int rssi
)
501 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
503 mvmvif
->bf_data
.last_bt_coex_event
= rssi
;
504 mvmvif
->bf_data
.bt_coex_max_thold
=
505 enable
? -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH
: 0;
506 mvmvif
->bf_data
.bt_coex_min_thold
=
507 enable
? -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH
: 0;
510 /* must be called under rcu_read_lock */
511 static void iwl_mvm_bt_notif_iterator(void *_data
, u8
*mac
,
512 struct ieee80211_vif
*vif
)
514 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
515 struct iwl_bt_iterator_data
*data
= _data
;
516 struct iwl_mvm
*mvm
= data
->mvm
;
517 struct ieee80211_chanctx_conf
*chanctx_conf
;
518 /* default smps_mode is AUTOMATIC - only used for client modes */
519 enum ieee80211_smps_mode smps_mode
= IEEE80211_SMPS_AUTOMATIC
;
520 u32 bt_activity_grading
;
523 lockdep_assert_held(&mvm
->mutex
);
526 case NL80211_IFTYPE_STATION
:
528 case NL80211_IFTYPE_AP
:
529 if (!mvmvif
->ap_ibss_active
)
536 chanctx_conf
= rcu_dereference(vif
->chanctx_conf
);
538 /* If channel context is invalid or not on 2.4GHz .. */
539 if ((!chanctx_conf
||
540 chanctx_conf
->def
.chan
->band
!= NL80211_BAND_2GHZ
)) {
541 if (vif
->type
== NL80211_IFTYPE_STATION
) {
542 /* ... relax constraints and disable rssi events */
543 iwl_mvm_update_smps(mvm
, vif
, IWL_MVM_SMPS_REQ_BT_COEX
,
545 iwl_mvm_bt_coex_reduced_txp(mvm
, mvmvif
->ap_sta_id
,
547 iwl_mvm_bt_coex_enable_rssi_event(mvm
, vif
, false, 0);
552 bt_activity_grading
= le32_to_cpu(data
->notif
->bt_activity_grading
);
553 if (bt_activity_grading
>= BT_HIGH_TRAFFIC
)
554 smps_mode
= IEEE80211_SMPS_STATIC
;
555 else if (bt_activity_grading
>= BT_LOW_TRAFFIC
)
556 smps_mode
= IEEE80211_SMPS_DYNAMIC
;
558 /* relax SMPS constraints for next association */
559 if (!vif
->bss_conf
.assoc
)
560 smps_mode
= IEEE80211_SMPS_AUTOMATIC
;
562 if (mvmvif
->phy_ctxt
&&
563 IWL_COEX_IS_RRC_ON(mvm
->last_bt_notif
.ttc_rrc_status
,
564 mvmvif
->phy_ctxt
->id
))
565 smps_mode
= IEEE80211_SMPS_AUTOMATIC
;
567 IWL_DEBUG_COEX(data
->mvm
,
568 "mac %d: bt_activity_grading %d smps_req %d\n",
569 mvmvif
->id
, bt_activity_grading
, smps_mode
);
571 if (vif
->type
== NL80211_IFTYPE_STATION
)
572 iwl_mvm_update_smps(mvm
, vif
, IWL_MVM_SMPS_REQ_BT_COEX
,
575 /* low latency is always primary */
576 if (iwl_mvm_vif_low_latency(mvmvif
)) {
577 data
->primary_ll
= true;
579 data
->secondary
= data
->primary
;
580 data
->primary
= chanctx_conf
;
583 if (vif
->type
== NL80211_IFTYPE_AP
) {
584 if (!mvmvif
->ap_ibss_active
)
587 if (chanctx_conf
== data
->primary
)
590 if (!data
->primary_ll
) {
592 * downgrade the current primary no matter what its
595 data
->secondary
= data
->primary
;
596 data
->primary
= chanctx_conf
;
598 /* there is low latency vif - we will be secondary */
599 data
->secondary
= chanctx_conf
;
605 * STA / P2P Client, try to be primary if first vif. If we are in low
606 * latency mode, we are already in primary and just don't do much
608 if (!data
->primary
|| data
->primary
== chanctx_conf
)
609 data
->primary
= chanctx_conf
;
610 else if (!data
->secondary
)
611 /* if secondary is not NULL, it might be a GO */
612 data
->secondary
= chanctx_conf
;
615 * don't reduce the Tx power if one of these is true:
617 * single share antenna product
621 if (iwl_get_coex_type(mvm
, vif
) == BT_COEX_LOOSE_LUT
||
622 mvm
->cfg
->bt_shared_single_ant
|| !vif
->bss_conf
.assoc
||
623 le32_to_cpu(mvm
->last_bt_notif
.bt_activity_grading
) == BT_OFF
) {
624 iwl_mvm_bt_coex_reduced_txp(mvm
, mvmvif
->ap_sta_id
, false);
625 iwl_mvm_bt_coex_enable_rssi_event(mvm
, vif
, false, 0);
629 /* try to get the avg rssi from fw */
630 ave_rssi
= mvmvif
->bf_data
.ave_beacon_signal
;
632 /* if the RSSI isn't valid, fake it is very low */
635 if (ave_rssi
> -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH
) {
636 if (iwl_mvm_bt_coex_reduced_txp(mvm
, mvmvif
->ap_sta_id
, true))
637 IWL_ERR(mvm
, "Couldn't send BT_CONFIG cmd\n");
638 } else if (ave_rssi
< -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH
) {
639 if (iwl_mvm_bt_coex_reduced_txp(mvm
, mvmvif
->ap_sta_id
, false))
640 IWL_ERR(mvm
, "Couldn't send BT_CONFIG cmd\n");
643 /* Begin to monitor the RSSI: it may influence the reduced Tx power */
644 iwl_mvm_bt_coex_enable_rssi_event(mvm
, vif
, true, ave_rssi
);
647 static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm
*mvm
)
649 struct iwl_bt_iterator_data data
= {
651 .notif
= &mvm
->last_bt_notif
,
653 struct iwl_bt_coex_ci_cmd cmd
= {};
656 /* Ignore updates if we are in force mode */
657 if (unlikely(mvm
->bt_force_ant_mode
!= BT_FORCE_ANT_DIS
))
661 ieee80211_iterate_active_interfaces_atomic(
662 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
663 iwl_mvm_bt_notif_iterator
, &data
);
666 struct ieee80211_chanctx_conf
*chan
= data
.primary
;
667 if (WARN_ON(!chan
->def
.chan
)) {
672 if (chan
->def
.width
< NL80211_CHAN_WIDTH_40
) {
675 if (chan
->def
.center_freq1
>
676 chan
->def
.chan
->center_freq
)
683 iwl_ci_mask
[chan
->def
.chan
->hw_value
][ci_bw_idx
];
684 cmd
.primary_ch_phy_id
=
685 cpu_to_le32(*((u16
*)data
.primary
->drv_priv
));
688 if (data
.secondary
) {
689 struct ieee80211_chanctx_conf
*chan
= data
.secondary
;
690 if (WARN_ON(!data
.secondary
->def
.chan
)) {
695 if (chan
->def
.width
< NL80211_CHAN_WIDTH_40
) {
698 if (chan
->def
.center_freq1
>
699 chan
->def
.chan
->center_freq
)
705 cmd
.bt_secondary_ci
=
706 iwl_ci_mask
[chan
->def
.chan
->hw_value
][ci_bw_idx
];
707 cmd
.secondary_ch_phy_id
=
708 cpu_to_le32(*((u16
*)data
.secondary
->drv_priv
));
713 /* Don't spam the fw with the same command over and over */
714 if (memcmp(&cmd
, &mvm
->last_bt_ci_cmd
, sizeof(cmd
))) {
715 if (iwl_mvm_send_cmd_pdu(mvm
, BT_COEX_CI
, 0,
717 IWL_ERR(mvm
, "Failed to send BT_CI cmd\n");
718 memcpy(&mvm
->last_bt_ci_cmd
, &cmd
, sizeof(cmd
));
722 void iwl_mvm_rx_bt_coex_notif(struct iwl_mvm
*mvm
,
723 struct iwl_rx_cmd_buffer
*rxb
)
725 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
726 struct iwl_bt_coex_profile_notif
*notif
= (void *)pkt
->data
;
728 IWL_DEBUG_COEX(mvm
, "BT Coex Notification received\n");
729 IWL_DEBUG_COEX(mvm
, "\tBT ci compliance %d\n", notif
->bt_ci_compliance
);
730 IWL_DEBUG_COEX(mvm
, "\tBT primary_ch_lut %d\n",
731 le32_to_cpu(notif
->primary_ch_lut
));
732 IWL_DEBUG_COEX(mvm
, "\tBT secondary_ch_lut %d\n",
733 le32_to_cpu(notif
->secondary_ch_lut
));
734 IWL_DEBUG_COEX(mvm
, "\tBT activity grading %d\n",
735 le32_to_cpu(notif
->bt_activity_grading
));
737 /* remember this notification for future use: rssi fluctuations */
738 memcpy(&mvm
->last_bt_notif
, notif
, sizeof(mvm
->last_bt_notif
));
740 iwl_mvm_bt_coex_notif_handle(mvm
);
743 void iwl_mvm_bt_rssi_event(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
744 enum ieee80211_rssi_event_data rssi_event
)
746 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
749 lockdep_assert_held(&mvm
->mutex
);
751 /* Ignore updates if we are in force mode */
752 if (unlikely(mvm
->bt_force_ant_mode
!= BT_FORCE_ANT_DIS
))
756 * Rssi update while not associated - can happen since the statistics
757 * are handled asynchronously
759 if (mvmvif
->ap_sta_id
== IWL_MVM_STATION_COUNT
)
762 /* No BT - reports should be disabled */
763 if (le32_to_cpu(mvm
->last_bt_notif
.bt_activity_grading
) == BT_OFF
)
766 IWL_DEBUG_COEX(mvm
, "RSSI for %pM is now %s\n", vif
->bss_conf
.bssid
,
767 rssi_event
== RSSI_EVENT_HIGH
? "HIGH" : "LOW");
770 * Check if rssi is good enough for reduced Tx power, but not in loose
773 if (rssi_event
== RSSI_EVENT_LOW
|| mvm
->cfg
->bt_shared_single_ant
||
774 iwl_get_coex_type(mvm
, vif
) == BT_COEX_LOOSE_LUT
)
775 ret
= iwl_mvm_bt_coex_reduced_txp(mvm
, mvmvif
->ap_sta_id
,
778 ret
= iwl_mvm_bt_coex_reduced_txp(mvm
, mvmvif
->ap_sta_id
, true);
781 IWL_ERR(mvm
, "couldn't send BT_CONFIG HCMD upon RSSI event\n");
784 #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000)
785 #define LINK_QUAL_AGG_TIME_LIMIT_BT_ACT (1200)
787 u16
iwl_mvm_coex_agg_time_limit(struct iwl_mvm
*mvm
,
788 struct ieee80211_sta
*sta
)
790 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
791 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(mvmsta
->vif
);
792 struct iwl_mvm_phy_ctxt
*phy_ctxt
= mvmvif
->phy_ctxt
;
793 enum iwl_bt_coex_lut_type lut_type
;
795 if (IWL_COEX_IS_TTC_ON(mvm
->last_bt_notif
.ttc_rrc_status
, phy_ctxt
->id
))
796 return LINK_QUAL_AGG_TIME_LIMIT_DEF
;
798 if (le32_to_cpu(mvm
->last_bt_notif
.bt_activity_grading
) <
800 return LINK_QUAL_AGG_TIME_LIMIT_DEF
;
802 lut_type
= iwl_get_coex_type(mvm
, mvmsta
->vif
);
804 if (lut_type
== BT_COEX_LOOSE_LUT
|| lut_type
== BT_COEX_INVALID_LUT
)
805 return LINK_QUAL_AGG_TIME_LIMIT_DEF
;
807 /* tight coex, high bt traffic, reduce AGG time limit */
808 return LINK_QUAL_AGG_TIME_LIMIT_BT_ACT
;
811 bool iwl_mvm_bt_coex_is_mimo_allowed(struct iwl_mvm
*mvm
,
812 struct ieee80211_sta
*sta
)
814 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
815 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(mvmsta
->vif
);
816 struct iwl_mvm_phy_ctxt
*phy_ctxt
= mvmvif
->phy_ctxt
;
817 enum iwl_bt_coex_lut_type lut_type
;
819 if (IWL_COEX_IS_TTC_ON(mvm
->last_bt_notif
.ttc_rrc_status
, phy_ctxt
->id
))
822 if (le32_to_cpu(mvm
->last_bt_notif
.bt_activity_grading
) <
827 * In Tight / TxTxDis, BT can't Rx while we Tx, so use both antennas
828 * since BT is already killed.
829 * In Loose, BT can Rx while we Tx, so forbid MIMO to let BT Rx while
831 * When we are in 5GHz, we'll get BT_COEX_INVALID_LUT allowing MIMO.
833 lut_type
= iwl_get_coex_type(mvm
, mvmsta
->vif
);
834 return lut_type
!= BT_COEX_LOOSE_LUT
;
837 bool iwl_mvm_bt_coex_is_ant_avail(struct iwl_mvm
*mvm
, u8 ant
)
839 /* there is no other antenna, shared antenna is always available */
840 if (mvm
->cfg
->bt_shared_single_ant
)
843 if (ant
& mvm
->cfg
->non_shared_ant
)
846 return le32_to_cpu(mvm
->last_bt_notif
.bt_activity_grading
) <
850 bool iwl_mvm_bt_coex_is_shared_ant_avail(struct iwl_mvm
*mvm
)
852 /* there is no other antenna, shared antenna is always available */
853 if (mvm
->cfg
->bt_shared_single_ant
)
856 return le32_to_cpu(mvm
->last_bt_notif
.bt_activity_grading
) < BT_HIGH_TRAFFIC
;
859 bool iwl_mvm_bt_coex_is_tpc_allowed(struct iwl_mvm
*mvm
,
860 enum nl80211_band band
)
862 u32 bt_activity
= le32_to_cpu(mvm
->last_bt_notif
.bt_activity_grading
);
864 if (band
!= NL80211_BAND_2GHZ
)
867 return bt_activity
>= BT_LOW_TRAFFIC
;
870 u8
iwl_mvm_bt_coex_tx_prio(struct iwl_mvm
*mvm
, struct ieee80211_hdr
*hdr
,
871 struct ieee80211_tx_info
*info
, u8 ac
)
873 __le16 fc
= hdr
->frame_control
;
874 bool mplut_enabled
= iwl_mvm_is_mplut_supported(mvm
);
876 if (info
->band
!= NL80211_BAND_2GHZ
)
879 if (unlikely(mvm
->bt_tx_prio
))
880 return mvm
->bt_tx_prio
- 1;
882 if (likely(ieee80211_is_data(fc
))) {
883 if (likely(ieee80211_is_data_qos(fc
))) {
885 case IEEE80211_AC_BE
:
886 return mplut_enabled
? 1 : 0;
887 case IEEE80211_AC_VI
:
888 return mplut_enabled
? 2 : 3;
889 case IEEE80211_AC_VO
:
894 } else if (is_multicast_ether_addr(hdr
->addr1
)) {
898 } else if (ieee80211_is_mgmt(fc
)) {
899 return ieee80211_is_disassoc(fc
) ? 0 : 3;
900 } else if (ieee80211_is_ctl(fc
)) {
901 /* ignore cfend and cfendack frames as we never send those */
908 void iwl_mvm_bt_coex_vif_change(struct iwl_mvm
*mvm
)
910 iwl_mvm_bt_coex_notif_handle(mvm
);
913 void iwl_mvm_rx_ant_coupling_notif(struct iwl_mvm
*mvm
,
914 struct iwl_rx_cmd_buffer
*rxb
)
916 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
917 u32 ant_isolation
= le32_to_cpup((void *)pkt
->data
);
918 struct iwl_bt_coex_corun_lut_update_cmd cmd
= {};
919 u8 __maybe_unused lower_bound
, upper_bound
;
922 if (!iwl_mvm_bt_is_plcr_supported(mvm
))
925 lockdep_assert_held(&mvm
->mutex
);
927 /* Ignore updates if we are in force mode */
928 if (unlikely(mvm
->bt_force_ant_mode
!= BT_FORCE_ANT_DIS
))
931 if (ant_isolation
== mvm
->last_ant_isol
)
934 for (lut
= 0; lut
< ARRAY_SIZE(antenna_coupling_ranges
) - 1; lut
++)
935 if (ant_isolation
< antenna_coupling_ranges
[lut
+ 1].range
)
938 lower_bound
= antenna_coupling_ranges
[lut
].range
;
940 if (lut
< ARRAY_SIZE(antenna_coupling_ranges
) - 1)
941 upper_bound
= antenna_coupling_ranges
[lut
+ 1].range
;
943 upper_bound
= antenna_coupling_ranges
[lut
].range
;
945 IWL_DEBUG_COEX(mvm
, "Antenna isolation=%d in range [%d,%d[, lut=%d\n",
946 ant_isolation
, lower_bound
, upper_bound
, lut
);
948 mvm
->last_ant_isol
= ant_isolation
;
950 if (mvm
->last_corun_lut
== lut
)
953 mvm
->last_corun_lut
= lut
;
955 /* For the moment, use the same LUT for 20GHz and 40GHz */
956 memcpy(&cmd
.corun_lut20
, antenna_coupling_ranges
[lut
].lut20
,
957 sizeof(cmd
.corun_lut20
));
959 memcpy(&cmd
.corun_lut40
, antenna_coupling_ranges
[lut
].lut20
,
960 sizeof(cmd
.corun_lut40
));
962 if (iwl_mvm_send_cmd_pdu(mvm
, BT_COEX_UPDATE_CORUN_LUT
, 0,
965 "failed to send BT_COEX_UPDATE_CORUN_LUT command\n");