blob: 79c80f181f7d55031d5a5bc1cb3b3ae7291586f6 [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.
Emmanuel Grumbach741c4cf2015-05-11 09:05:25 +03009 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Emmanuel Grumbachfbfe3782017-07-23 13:59:47 +030010 * Copyright(c) 2017 Intel Deutschland GmbH
Emmanuel Grumbach931d4162013-01-17 09:42:25 +020011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * USA
25 *
26 * The full GNU General Public License is included in this distribution
27 * in the file called COPYING.
28 *
29 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020030 * Intel Linux Wireless <linuxwifi@intel.com>
Emmanuel Grumbach931d4162013-01-17 09:42:25 +020031 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020035 * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
Emmanuel Grumbach741c4cf2015-05-11 09:05:25 +030036 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Emmanuel Grumbachfbfe3782017-07-23 13:59:47 +030037 * Copyright(c) 2017 Intel Deutschland GmbH
Emmanuel Grumbach931d4162013-01-17 09:42:25 +020038 * All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 *
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * * Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in
48 * the documentation and/or other materials provided with the
49 * distribution.
50 * * Neither the name Intel Corporation nor the names of its
51 * contributors may be used to endorse or promote products derived
52 * from this software without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 *
66 *****************************************************************************/
67
Emmanuel Grumbachee7bea52014-03-06 10:30:49 +020068#include <linux/ieee80211.h>
69#include <linux/etherdevice.h>
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +020070#include <net/mac80211.h>
71
Johannes Bergd172a5e2017-06-02 15:15:53 +020072#include "fw/api/coex.h"
Emmanuel Grumbach931d4162013-01-17 09:42:25 +020073#include "iwl-modparams.h"
74#include "mvm.h"
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +020075#include "iwl-debug.h"
Emmanuel Grumbach931d4162013-01-17 09:42:25 +020076
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +030077/* 20MHz / 40MHz below / 40Mhz above*/
78static const __le64 iwl_ci_mask[][3] = {
79 /* dummy entry for channel 0 */
80 {cpu_to_le64(0), cpu_to_le64(0), cpu_to_le64(0)},
81 {
82 cpu_to_le64(0x0000001FFFULL),
83 cpu_to_le64(0x0ULL),
84 cpu_to_le64(0x00007FFFFFULL),
85 },
86 {
87 cpu_to_le64(0x000000FFFFULL),
88 cpu_to_le64(0x0ULL),
89 cpu_to_le64(0x0003FFFFFFULL),
90 },
91 {
92 cpu_to_le64(0x000003FFFCULL),
93 cpu_to_le64(0x0ULL),
94 cpu_to_le64(0x000FFFFFFCULL),
95 },
96 {
97 cpu_to_le64(0x00001FFFE0ULL),
98 cpu_to_le64(0x0ULL),
99 cpu_to_le64(0x007FFFFFE0ULL),
100 },
101 {
102 cpu_to_le64(0x00007FFF80ULL),
103 cpu_to_le64(0x00007FFFFFULL),
104 cpu_to_le64(0x01FFFFFF80ULL),
105 },
106 {
107 cpu_to_le64(0x0003FFFC00ULL),
108 cpu_to_le64(0x0003FFFFFFULL),
109 cpu_to_le64(0x0FFFFFFC00ULL),
110 },
111 {
112 cpu_to_le64(0x000FFFF000ULL),
113 cpu_to_le64(0x000FFFFFFCULL),
114 cpu_to_le64(0x3FFFFFF000ULL),
115 },
116 {
117 cpu_to_le64(0x007FFF8000ULL),
118 cpu_to_le64(0x007FFFFFE0ULL),
119 cpu_to_le64(0xFFFFFF8000ULL),
120 },
121 {
122 cpu_to_le64(0x01FFFE0000ULL),
123 cpu_to_le64(0x01FFFFFF80ULL),
124 cpu_to_le64(0xFFFFFE0000ULL),
125 },
126 {
127 cpu_to_le64(0x0FFFF00000ULL),
128 cpu_to_le64(0x0FFFFFFC00ULL),
129 cpu_to_le64(0x0ULL),
130 },
131 {
132 cpu_to_le64(0x3FFFC00000ULL),
133 cpu_to_le64(0x3FFFFFF000ULL),
134 cpu_to_le64(0x0)
135 },
136 {
137 cpu_to_le64(0xFFFE000000ULL),
138 cpu_to_le64(0xFFFFFF8000ULL),
139 cpu_to_le64(0x0)
140 },
141 {
142 cpu_to_le64(0xFFF8000000ULL),
143 cpu_to_le64(0xFFFFFE0000ULL),
144 cpu_to_le64(0x0)
145 },
146 {
Emmanuel Grumbachad17b1d2016-06-22 10:51:31 +0300147 cpu_to_le64(0xFE00000000ULL),
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300148 cpu_to_le64(0x0ULL),
Emmanuel Grumbachd2ccc902013-12-24 10:55:24 +0200149 cpu_to_le64(0x0ULL)
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300150 },
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200151};
152
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300153static enum iwl_bt_coex_lut_type
154iwl_get_coex_type(struct iwl_mvm *mvm, const struct ieee80211_vif *vif)
155{
156 struct ieee80211_chanctx_conf *chanctx_conf;
157 enum iwl_bt_coex_lut_type ret;
158 u16 phy_ctx_id;
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300159 u32 primary_ch_phy_id, secondary_ch_phy_id;
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300160
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300161 /*
162 * Checking that we hold mvm->mutex is a good idea, but the rate
163 * control can't acquire the mutex since it runs in Tx path.
164 * So this is racy in that case, but in the worst case, the AMPDU
165 * size limit will be wrong for a short time which is not a big
166 * issue.
167 */
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300168
169 rcu_read_lock();
170
171 chanctx_conf = rcu_dereference(vif->chanctx_conf);
172
173 if (!chanctx_conf ||
Johannes Berg57fbcce2016-04-12 15:56:15 +0200174 chanctx_conf->def.chan->band != NL80211_BAND_2GHZ) {
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300175 rcu_read_unlock();
Emmanuel Grumbach7fa4fa02014-05-25 13:58:31 +0300176 return BT_COEX_INVALID_LUT;
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300177 }
178
179 ret = BT_COEX_TX_DIS_LUT;
180
Emmanuel Grumbach39149912013-07-14 13:40:21 +0300181 if (mvm->cfg->bt_shared_single_ant) {
182 rcu_read_unlock();
183 return ret;
184 }
185
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300186 phy_ctx_id = *((u16 *)chanctx_conf->drv_priv);
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300187 primary_ch_phy_id = le32_to_cpu(mvm->last_bt_ci_cmd.primary_ch_phy_id);
188 secondary_ch_phy_id =
189 le32_to_cpu(mvm->last_bt_ci_cmd.secondary_ch_phy_id);
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300190
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300191 if (primary_ch_phy_id == phy_ctx_id)
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300192 ret = le32_to_cpu(mvm->last_bt_notif.primary_ch_lut);
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300193 else if (secondary_ch_phy_id == phy_ctx_id)
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300194 ret = le32_to_cpu(mvm->last_bt_notif.secondary_ch_lut);
195 /* else - default = TX TX disallowed */
196
197 rcu_read_unlock();
198
199 return ret;
200}
201
Emmanuel Grumbachb3de3ef2017-05-29 14:01:06 +0300202int iwl_mvm_send_bt_init_conf(struct iwl_mvm *mvm)
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200203{
Emmanuel Grumbach741c4cf2015-05-11 09:05:25 +0300204 struct iwl_bt_coex_cmd bt_cmd = {};
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300205 u32 mode;
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300206
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300207 lockdep_assert_held(&mvm->mutex);
208
209 if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) {
210 switch (mvm->bt_force_ant_mode) {
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300211 case BT_FORCE_ANT_BT:
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300212 mode = BT_COEX_BT;
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300213 break;
214 case BT_FORCE_ANT_WIFI:
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300215 mode = BT_COEX_WIFI;
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300216 break;
217 default:
218 WARN_ON(1);
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300219 mode = 0;
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300220 }
221
Emmanuel Grumbach741c4cf2015-05-11 09:05:25 +0300222 bt_cmd.mode = cpu_to_le32(mode);
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300223 goto send_cmd;
224 }
225
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300226 mode = iwlwifi_mod_params.bt_coex_active ? BT_COEX_NW : BT_COEX_DISABLE;
Emmanuel Grumbach741c4cf2015-05-11 09:05:25 +0300227 bt_cmd.mode = cpu_to_le32(mode);
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300228
Emmanuel Grumbach741e7032014-01-27 12:12:50 +0200229 if (IWL_MVM_BT_COEX_SYNC2SCO)
Emmanuel Grumbach741c4cf2015-05-11 09:05:25 +0300230 bt_cmd.enabled_modules |=
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300231 cpu_to_le32(BT_COEX_SYNC2SCO_ENABLED);
Emmanuel Grumbach741e7032014-01-27 12:12:50 +0200232
Avri Altmane7c2e1f2015-10-29 16:50:57 +0200233 if (iwl_mvm_is_mplut_supported(mvm))
Emmanuel Grumbach741c4cf2015-05-11 09:05:25 +0300234 bt_cmd.enabled_modules |= cpu_to_le32(BT_COEX_MPLUT_ENABLED);
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +0200235
Emmanuel Grumbach741c4cf2015-05-11 09:05:25 +0300236 bt_cmd.enabled_modules |= cpu_to_le32(BT_COEX_HIGH_BAND_RET);
Emmanuel Grumbach261c0ec2014-06-11 15:37:25 +0300237
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300238send_cmd:
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300239 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300240 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300241
Emmanuel Grumbach741c4cf2015-05-11 09:05:25 +0300242 return iwl_mvm_send_cmd_pdu(mvm, BT_CONFIG, 0, sizeof(bt_cmd), &bt_cmd);
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200243}
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200244
Emmanuel Grumbach1fa477c2014-05-20 13:54:27 +0300245static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id,
246 bool enable)
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200247{
Emmanuel Grumbach455e7ac2014-05-22 12:48:27 +0300248 struct iwl_bt_coex_reduced_txp_update_cmd cmd = {};
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200249 struct iwl_mvm_sta *mvmsta;
Emmanuel Grumbach455e7ac2014-05-22 12:48:27 +0300250 u32 value;
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300251 int ret;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200252
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200253 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
254 if (!mvmsta)
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200255 return 0;
256
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200257 /* nothing to do */
Emmanuel Grumbach1fa477c2014-05-20 13:54:27 +0300258 if (mvmsta->bt_reduced_txpower == enable)
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200259 return 0;
260
Emmanuel Grumbach455e7ac2014-05-22 12:48:27 +0300261 value = mvmsta->sta_id;
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300262
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200263 if (enable)
Emmanuel Grumbach455e7ac2014-05-22 12:48:27 +0300264 value |= BT_REDUCED_TX_POWER_BIT;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200265
266 IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n",
267 enable ? "en" : "dis", sta_id);
268
Emmanuel Grumbach455e7ac2014-05-22 12:48:27 +0300269 cmd.reduced_txp = cpu_to_le32(value);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200270 mvmsta->bt_reduced_txpower = enable;
271
Emmanuel Grumbach455e7ac2014-05-22 12:48:27 +0300272 ret = iwl_mvm_send_cmd_pdu(mvm, BT_COEX_UPDATE_REDUCED_TXP, CMD_ASYNC,
273 sizeof(cmd), &cmd);
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300274
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300275 return ret;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200276}
277
278struct iwl_bt_iterator_data {
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300279 struct iwl_bt_coex_profile_notif *notif;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200280 struct iwl_mvm *mvm;
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300281 struct ieee80211_chanctx_conf *primary;
282 struct ieee80211_chanctx_conf *secondary;
Emmanuel Grumbach0ee5bcd2014-01-15 16:57:54 +0200283 bool primary_ll;
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200284};
285
Emmanuel Grumbachf6fc5772013-09-08 08:57:15 +0300286static inline
287void iwl_mvm_bt_coex_enable_rssi_event(struct iwl_mvm *mvm,
288 struct ieee80211_vif *vif,
289 bool enable, int rssi)
290{
291 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
292
293 mvmvif->bf_data.last_bt_coex_event = rssi;
294 mvmvif->bf_data.bt_coex_max_thold =
Emmanuel Grumbach8286d9f2014-05-27 22:54:18 +0300295 enable ? -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH : 0;
Emmanuel Grumbachf6fc5772013-09-08 08:57:15 +0300296 mvmvif->bf_data.bt_coex_min_thold =
Emmanuel Grumbach8286d9f2014-05-27 22:54:18 +0300297 enable ? -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH : 0;
Emmanuel Grumbachf6fc5772013-09-08 08:57:15 +0300298}
299
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300300/* must be called under rcu_read_lock */
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200301static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac,
302 struct ieee80211_vif *vif)
303{
304 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200305 struct iwl_bt_iterator_data *data = _data;
306 struct iwl_mvm *mvm = data->mvm;
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200307 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg582de302014-08-21 19:08:44 +0200308 /* default smps_mode is AUTOMATIC - only used for client modes */
309 enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_AUTOMATIC;
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200310 u32 bt_activity_grading;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200311 int ave_rssi;
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200312
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300313 lockdep_assert_held(&mvm->mutex);
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200314
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200315 switch (vif->type) {
316 case NL80211_IFTYPE_STATION:
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200317 break;
318 case NL80211_IFTYPE_AP:
Emmanuel Grumbach45bbb2c2014-07-07 14:38:39 +0300319 if (!mvmvif->ap_ibss_active)
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200320 return;
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200321 break;
322 default:
323 return;
324 }
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200325
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300326 chanctx_conf = rcu_dereference(vif->chanctx_conf);
327
328 /* If channel context is invalid or not on 2.4GHz .. */
329 if ((!chanctx_conf ||
Johannes Berg57fbcce2016-04-12 15:56:15 +0200330 chanctx_conf->def.chan->band != NL80211_BAND_2GHZ)) {
Emmanuel Grumbach0f618e62014-05-20 15:48:18 +0300331 if (vif->type == NL80211_IFTYPE_STATION) {
Emmanuel Grumbach45bbb2c2014-07-07 14:38:39 +0300332 /* ... relax constraints and disable rssi events */
333 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
334 smps_mode);
Emmanuel Grumbach0f618e62014-05-20 15:48:18 +0300335 iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
336 false);
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200337 iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
Emmanuel Grumbach0f618e62014-05-20 15:48:18 +0300338 }
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300339 return;
340 }
341
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200342 bt_activity_grading = le32_to_cpu(data->notif->bt_activity_grading);
343 if (bt_activity_grading >= BT_HIGH_TRAFFIC)
344 smps_mode = IEEE80211_SMPS_STATIC;
345 else if (bt_activity_grading >= BT_LOW_TRAFFIC)
Emmanuel Grumbach45bbb2c2014-07-07 14:38:39 +0300346 smps_mode = IEEE80211_SMPS_DYNAMIC;
Emmanuel Grumbach4d664492014-04-30 18:09:59 +0300347
Johannes Berg582de302014-08-21 19:08:44 +0200348 /* relax SMPS constraints for next association */
Emmanuel Grumbach4d664492014-04-30 18:09:59 +0300349 if (!vif->bss_conf.assoc)
350 smps_mode = IEEE80211_SMPS_AUTOMATIC;
351
Emmanuel Grumbach4cd4b502015-03-05 13:43:15 +0200352 if (mvmvif->phy_ctxt &&
Emmanuel Grumbach88c5f472017-07-23 12:53:46 +0300353 (mvm->last_bt_notif.rrc_status & BIT(mvmvif->phy_ctxt->id)))
Emmanuel Grumbach4c86f932014-06-30 10:26:02 +0300354 smps_mode = IEEE80211_SMPS_AUTOMATIC;
355
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200356 IWL_DEBUG_COEX(data->mvm,
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300357 "mac %d: bt_activity_grading %d smps_req %d\n",
358 mvmvif->id, bt_activity_grading, smps_mode);
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200359
Emmanuel Grumbach45bbb2c2014-07-07 14:38:39 +0300360 if (vif->type == NL80211_IFTYPE_STATION)
361 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
362 smps_mode);
Emmanuel Grumbachf6415f62013-12-26 15:32:40 +0200363
Emmanuel Grumbach0ee5bcd2014-01-15 16:57:54 +0200364 /* low latency is always primary */
365 if (iwl_mvm_vif_low_latency(mvmvif)) {
366 data->primary_ll = true;
367
368 data->secondary = data->primary;
369 data->primary = chanctx_conf;
370 }
371
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300372 if (vif->type == NL80211_IFTYPE_AP) {
Johannes Berg5023d962013-07-31 14:07:43 +0200373 if (!mvmvif->ap_ibss_active)
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300374 return;
375
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300376 if (chanctx_conf == data->primary)
377 return;
378
Emmanuel Grumbach0ee5bcd2014-01-15 16:57:54 +0200379 if (!data->primary_ll) {
380 /*
381 * downgrade the current primary no matter what its
382 * type is.
383 */
384 data->secondary = data->primary;
385 data->primary = chanctx_conf;
386 } else {
387 /* there is low latency vif - we will be secondary */
388 data->secondary = chanctx_conf;
389 }
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300390 return;
391 }
392
Emmanuel Grumbach0ee5bcd2014-01-15 16:57:54 +0200393 /*
394 * STA / P2P Client, try to be primary if first vif. If we are in low
395 * latency mode, we are already in primary and just don't do much
396 */
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300397 if (!data->primary || data->primary == chanctx_conf)
398 data->primary = chanctx_conf;
399 else if (!data->secondary)
400 /* if secondary is not NULL, it might be a GO */
401 data->secondary = chanctx_conf;
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200402
Emmanuel Grumbach4d664492014-04-30 18:09:59 +0300403 /*
404 * don't reduce the Tx power if one of these is true:
405 * we are in LOOSE
406 * single share antenna product
Emmanuel Grumbachc934bce2016-06-20 09:40:40 +0300407 * BT is inactive
408 * we are not associated
Emmanuel Grumbach4d664492014-04-30 18:09:59 +0300409 */
Emmanuel Grumbach39149912013-07-14 13:40:21 +0300410 if (iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT ||
Emmanuel Grumbach4d664492014-04-30 18:09:59 +0300411 mvm->cfg->bt_shared_single_ant || !vif->bss_conf.assoc ||
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300412 le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF) {
Emmanuel Grumbach0f618e62014-05-20 15:48:18 +0300413 iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false);
Emmanuel Grumbachf6fc5772013-09-08 08:57:15 +0300414 iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200415 return;
Emmanuel Grumbach39149912013-07-14 13:40:21 +0300416 }
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200417
Andrei Otcheretianski911222b2013-07-21 17:37:19 +0300418 /* try to get the avg rssi from fw */
419 ave_rssi = mvmvif->bf_data.ave_beacon_signal;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200420
421 /* if the RSSI isn't valid, fake it is very low */
422 if (!ave_rssi)
423 ave_rssi = -100;
Emmanuel Grumbach8286d9f2014-05-27 22:54:18 +0300424 if (ave_rssi > -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH) {
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200425 if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true))
426 IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
Emmanuel Grumbach8286d9f2014-05-27 22:54:18 +0300427 } else if (ave_rssi < -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH) {
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200428 if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
429 IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200430 }
431
432 /* Begin to monitor the RSSI: it may influence the reduced Tx power */
Emmanuel Grumbachf6fc5772013-09-08 08:57:15 +0300433 iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, true, ave_rssi);
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200434}
435
Emmanuel Grumbachd37cac92013-03-29 14:56:19 +0300436static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm)
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200437{
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200438 struct iwl_bt_iterator_data data = {
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200439 .mvm = mvm,
Emmanuel Grumbachd37cac92013-03-29 14:56:19 +0300440 .notif = &mvm->last_bt_notif,
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200441 };
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300442 struct iwl_bt_coex_ci_cmd cmd = {};
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300443 u8 ci_bw_idx;
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200444
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300445 /* Ignore updates if we are in force mode */
446 if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
447 return;
448
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300449 rcu_read_lock();
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200450 ieee80211_iterate_active_interfaces_atomic(
451 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
452 iwl_mvm_bt_notif_iterator, &data);
453
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300454 if (data.primary) {
455 struct ieee80211_chanctx_conf *chan = data.primary;
456 if (WARN_ON(!chan->def.chan)) {
457 rcu_read_unlock();
458 return;
459 }
460
461 if (chan->def.width < NL80211_CHAN_WIDTH_40) {
462 ci_bw_idx = 0;
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300463 } else {
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300464 if (chan->def.center_freq1 >
465 chan->def.chan->center_freq)
466 ci_bw_idx = 2;
467 else
468 ci_bw_idx = 1;
469 }
470
471 cmd.bt_primary_ci =
472 iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300473 cmd.primary_ch_phy_id =
474 cpu_to_le32(*((u16 *)data.primary->drv_priv));
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300475 }
476
477 if (data.secondary) {
478 struct ieee80211_chanctx_conf *chan = data.secondary;
479 if (WARN_ON(!data.secondary->def.chan)) {
480 rcu_read_unlock();
481 return;
482 }
483
484 if (chan->def.width < NL80211_CHAN_WIDTH_40) {
485 ci_bw_idx = 0;
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300486 } else {
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300487 if (chan->def.center_freq1 >
488 chan->def.chan->center_freq)
489 ci_bw_idx = 2;
490 else
491 ci_bw_idx = 1;
492 }
493
494 cmd.bt_secondary_ci =
495 iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300496 cmd.secondary_ch_phy_id =
497 cpu_to_le32(*((u16 *)data.secondary->drv_priv));
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300498 }
499
500 rcu_read_unlock();
501
502 /* Don't spam the fw with the same command over and over */
503 if (memcmp(&cmd, &mvm->last_bt_ci_cmd, sizeof(cmd))) {
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300504 if (iwl_mvm_send_cmd_pdu(mvm, BT_COEX_CI, 0,
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300505 sizeof(cmd), &cmd))
Johannes Berg3c6acb62014-05-07 11:47:53 +0200506 IWL_ERR(mvm, "Failed to send BT_CI cmd\n");
Emmanuel Grumbachdac94da2013-06-18 07:35:27 +0300507 memcpy(&mvm->last_bt_ci_cmd, &cmd, sizeof(cmd));
508 }
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200509}
510
Johannes Berg04168412015-06-23 21:22:09 +0200511void iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm,
512 struct iwl_rx_cmd_buffer *rxb)
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200513{
514 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Emmanuel Grumbachdf878f32014-04-02 12:23:09 +0300515 struct iwl_bt_coex_profile_notif *notif = (void *)pkt->data;
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200516
Emmanuel Grumbachfbfe3782017-07-23 13:59:47 +0300517 if (!iwl_mvm_has_new_ats_coex_api(mvm)) {
518 struct iwl_bt_coex_profile_notif_v4 *v4 = (void *)pkt->data;
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200519
Emmanuel Grumbachfbfe3782017-07-23 13:59:47 +0300520 mvm->last_bt_notif.mbox_msg[0] = v4->mbox_msg[0];
521 mvm->last_bt_notif.mbox_msg[1] = v4->mbox_msg[1];
522 mvm->last_bt_notif.mbox_msg[2] = v4->mbox_msg[2];
523 mvm->last_bt_notif.mbox_msg[3] = v4->mbox_msg[3];
524 mvm->last_bt_notif.msg_idx = v4->msg_idx;
525 mvm->last_bt_notif.bt_ci_compliance = v4->bt_ci_compliance;
526 mvm->last_bt_notif.primary_ch_lut = v4->primary_ch_lut;
527 mvm->last_bt_notif.secondary_ch_lut = v4->secondary_ch_lut;
528 mvm->last_bt_notif.bt_activity_grading =
529 v4->bt_activity_grading;
530 mvm->last_bt_notif.ttc_status = v4->ttc_status;
531 mvm->last_bt_notif.rrc_status = v4->rrc_status;
532 } else {
533 /* save this notification for future use: rssi fluctuations */
534 memcpy(&mvm->last_bt_notif, notif, sizeof(mvm->last_bt_notif));
535 }
536
537 IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n");
538 IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n",
539 mvm->last_bt_notif.bt_ci_compliance);
540 IWL_DEBUG_COEX(mvm, "\tBT primary_ch_lut %d\n",
541 le32_to_cpu(mvm->last_bt_notif.primary_ch_lut));
542 IWL_DEBUG_COEX(mvm, "\tBT secondary_ch_lut %d\n",
543 le32_to_cpu(mvm->last_bt_notif.secondary_ch_lut));
544 IWL_DEBUG_COEX(mvm, "\tBT activity grading %d\n",
545 le32_to_cpu(mvm->last_bt_notif.bt_activity_grading));
546
Emmanuel Grumbachd37cac92013-03-29 14:56:19 +0300547
548 iwl_mvm_bt_coex_notif_handle(mvm);
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200549}
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200550
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200551void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
Emmanuel Grumbacha8182922015-03-16 23:23:34 +0200552 enum ieee80211_rssi_event_data rssi_event)
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200553{
Johannes Berg5b530e92014-12-23 16:00:17 +0100554 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200555 int ret;
556
Johannes Berg3dd1cd22013-10-02 12:05:24 +0200557 lockdep_assert_held(&mvm->mutex);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200558
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300559 /* Ignore updates if we are in force mode */
560 if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
561 return;
562
Emmanuel Grumbach1e929192014-03-04 10:28:23 +0200563 /*
564 * Rssi update while not associated - can happen since the statistics
565 * are handled asynchronously
566 */
Sara Sharon0ae98812017-01-04 14:53:58 +0200567 if (mvmvif->ap_sta_id == IWL_MVM_INVALID_STA)
Johannes Berg3dd1cd22013-10-02 12:05:24 +0200568 return;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200569
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300570 /* No BT - reports should be disabled */
Emmanuel Grumbach430a3bb2014-04-02 09:55:16 +0300571 if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF)
Johannes Berg3dd1cd22013-10-02 12:05:24 +0200572 return;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200573
574 IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid,
575 rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW");
576
577 /*
578 * Check if rssi is good enough for reduced Tx power, but not in loose
579 * scheme.
580 */
Emmanuel Grumbach39149912013-07-14 13:40:21 +0300581 if (rssi_event == RSSI_EVENT_LOW || mvm->cfg->bt_shared_single_ant ||
Emmanuel Grumbach4515f302013-06-30 07:51:54 +0300582 iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT)
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200583 ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
584 false);
585 else
586 ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true);
587
588 if (ret)
589 IWL_ERR(mvm, "couldn't send BT_CONFIG HCMD upon RSSI event\n");
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200590}
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200591
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300592#define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000)
593#define LINK_QUAL_AGG_TIME_LIMIT_BT_ACT (1200)
594
Emmanuel Grumbach5b7ff612014-03-11 19:27:45 +0200595u16 iwl_mvm_coex_agg_time_limit(struct iwl_mvm *mvm,
596 struct ieee80211_sta *sta)
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300597{
Johannes Berg5b577a92013-11-14 18:20:04 +0100598 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbach4c86f932014-06-30 10:26:02 +0300599 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
600 struct iwl_mvm_phy_ctxt *phy_ctxt = mvmvif->phy_ctxt;
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300601 enum iwl_bt_coex_lut_type lut_type;
602
Emmanuel Grumbach88c5f472017-07-23 12:53:46 +0300603 if (mvm->last_bt_notif.ttc_status & BIT(phy_ctxt->id))
Emmanuel Grumbach4c86f932014-06-30 10:26:02 +0300604 return LINK_QUAL_AGG_TIME_LIMIT_DEF;
605
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300606 if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) <
Emmanuel Grumbachc2119352013-11-13 22:00:30 +0200607 BT_HIGH_TRAFFIC)
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300608 return LINK_QUAL_AGG_TIME_LIMIT_DEF;
Emmanuel Grumbach35fbf5d2014-06-02 16:18:42 +0300609
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300610 lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
611
Emmanuel Grumbach7fa4fa02014-05-25 13:58:31 +0300612 if (lut_type == BT_COEX_LOOSE_LUT || lut_type == BT_COEX_INVALID_LUT)
Emmanuel Grumbach9145d152013-07-18 08:45:41 +0300613 return LINK_QUAL_AGG_TIME_LIMIT_DEF;
614
615 /* tight coex, high bt traffic, reduce AGG time limit */
616 return LINK_QUAL_AGG_TIME_LIMIT_BT_ACT;
617}
618
Emmanuel Grumbachffa6c702013-10-06 11:41:20 +0300619bool iwl_mvm_bt_coex_is_mimo_allowed(struct iwl_mvm *mvm,
620 struct ieee80211_sta *sta)
621{
Johannes Berg5b577a92013-11-14 18:20:04 +0100622 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbach4c86f932014-06-30 10:26:02 +0300623 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
624 struct iwl_mvm_phy_ctxt *phy_ctxt = mvmvif->phy_ctxt;
Emmanuel Grumbach7fa4fa02014-05-25 13:58:31 +0300625 enum iwl_bt_coex_lut_type lut_type;
Emmanuel Grumbachffa6c702013-10-06 11:41:20 +0300626
Emmanuel Grumbach88c5f472017-07-23 12:53:46 +0300627 if (mvm->last_bt_notif.ttc_status & BIT(phy_ctxt->id))
Emmanuel Grumbach35fbf5d2014-06-02 16:18:42 +0300628 return true;
629
Emmanuel Grumbachffa6c702013-10-06 11:41:20 +0300630 if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) <
631 BT_HIGH_TRAFFIC)
632 return true;
633
634 /*
Emmanuel Grumbach7fa4fa02014-05-25 13:58:31 +0300635 * In Tight / TxTxDis, BT can't Rx while we Tx, so use both antennas
636 * since BT is already killed.
637 * In Loose, BT can Rx while we Tx, so forbid MIMO to let BT Rx while
638 * we Tx.
639 * When we are in 5GHz, we'll get BT_COEX_INVALID_LUT allowing MIMO.
Emmanuel Grumbachffa6c702013-10-06 11:41:20 +0300640 */
Emmanuel Grumbach7fa4fa02014-05-25 13:58:31 +0300641 lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
642 return lut_type != BT_COEX_LOOSE_LUT;
Emmanuel Grumbachffa6c702013-10-06 11:41:20 +0300643}
644
Emmanuel Grumbach219fb662014-10-30 11:59:40 +0200645bool iwl_mvm_bt_coex_is_ant_avail(struct iwl_mvm *mvm, u8 ant)
646{
647 /* there is no other antenna, shared antenna is always available */
648 if (mvm->cfg->bt_shared_single_ant)
649 return true;
650
651 if (ant & mvm->cfg->non_shared_ant)
652 return true;
653
Emmanuel Grumbach219fb662014-10-30 11:59:40 +0200654 return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) <
655 BT_HIGH_TRAFFIC;
656}
657
Emmanuel Grumbach34c8b242014-05-28 21:53:39 +0300658bool iwl_mvm_bt_coex_is_shared_ant_avail(struct iwl_mvm *mvm)
659{
Emmanuel Grumbachbbab7582014-09-10 11:00:16 +0300660 /* there is no other antenna, shared antenna is always available */
661 if (mvm->cfg->bt_shared_single_ant)
662 return true;
663
Emmanuel Grumbachcb97e412015-05-16 22:47:56 +0300664 return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) < BT_HIGH_TRAFFIC;
Emmanuel Grumbach34c8b242014-05-28 21:53:39 +0300665}
666
Eliad Peller2fd647f2014-03-13 17:21:36 +0200667bool iwl_mvm_bt_coex_is_tpc_allowed(struct iwl_mvm *mvm,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200668 enum nl80211_band band)
Eliad Peller2fd647f2014-03-13 17:21:36 +0200669{
670 u32 bt_activity = le32_to_cpu(mvm->last_bt_notif.bt_activity_grading);
671
Johannes Berg57fbcce2016-04-12 15:56:15 +0200672 if (band != NL80211_BAND_2GHZ)
Eliad Peller2fd647f2014-03-13 17:21:36 +0200673 return false;
674
675 return bt_activity >= BT_LOW_TRAFFIC;
676}
677
Emmanuel Grumbachee7bea52014-03-06 10:30:49 +0200678u8 iwl_mvm_bt_coex_tx_prio(struct iwl_mvm *mvm, struct ieee80211_hdr *hdr,
Emmanuel Grumbachb797e3f2014-03-06 14:49:36 +0200679 struct ieee80211_tx_info *info, u8 ac)
Emmanuel Grumbachee7bea52014-03-06 10:30:49 +0200680{
681 __le16 fc = hdr->frame_control;
Avri Altman6e365102015-11-02 14:16:07 +0200682 bool mplut_enabled = iwl_mvm_is_mplut_supported(mvm);
Emmanuel Grumbachee7bea52014-03-06 10:30:49 +0200683
Johannes Berg57fbcce2016-04-12 15:56:15 +0200684 if (info->band != NL80211_BAND_2GHZ)
Emmanuel Grumbachb797e3f2014-03-06 14:49:36 +0200685 return 0;
686
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +0200687 if (unlikely(mvm->bt_tx_prio))
688 return mvm->bt_tx_prio - 1;
689
Avri Altman6e365102015-11-02 14:16:07 +0200690 if (likely(ieee80211_is_data(fc))) {
691 if (likely(ieee80211_is_data_qos(fc))) {
692 switch (ac) {
693 case IEEE80211_AC_BE:
694 return mplut_enabled ? 1 : 0;
695 case IEEE80211_AC_VI:
696 return mplut_enabled ? 2 : 3;
697 case IEEE80211_AC_VO:
698 return 3;
699 default:
700 return 0;
701 }
702 } else if (is_multicast_ether_addr(hdr->addr1)) {
703 return 3;
704 } else
705 return 0;
706 } else if (ieee80211_is_mgmt(fc)) {
707 return ieee80211_is_disassoc(fc) ? 0 : 3;
708 } else if (ieee80211_is_ctl(fc)) {
709 /* ignore cfend and cfendack frames as we never send those */
Emmanuel Grumbachb797e3f2014-03-06 14:49:36 +0200710 return 3;
Emmanuel Grumbachb797e3f2014-03-06 14:49:36 +0200711 }
Emmanuel Grumbachee7bea52014-03-06 10:30:49 +0200712
713 return 0;
714}
715
Emmanuel Grumbach8e484f02013-10-02 15:02:25 +0300716void iwl_mvm_bt_coex_vif_change(struct iwl_mvm *mvm)
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200717{
Emmanuel Grumbachd37cac92013-03-29 14:56:19 +0300718 iwl_mvm_bt_coex_notif_handle(mvm);
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200719}