blob: bba5947fd652fa681db91278aa0723d37ddb92e6 [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 *
8 * Copyright(c) 2013 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2013 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +020064#include <net/mac80211.h>
65
Emmanuel Grumbach931d4162013-01-17 09:42:25 +020066#include "fw-api-bt-coex.h"
67#include "iwl-modparams.h"
68#include "mvm.h"
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +020069#include "iwl-debug.h"
Emmanuel Grumbach931d4162013-01-17 09:42:25 +020070
71#define EVENT_PRIO_ANT(_evt, _prio, _shrd_ant) \
72 [(_evt)] = (((_prio) << BT_COEX_PRIO_TBL_PRIO_POS) | \
73 ((_shrd_ant) << BT_COEX_PRIO_TBL_SHRD_ANT_POS))
74
75static const u8 iwl_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = {
76 EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_INIT_CALIB1,
77 BT_COEX_PRIO_TBL_PRIO_BYPASS, 0),
78 EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_INIT_CALIB2,
79 BT_COEX_PRIO_TBL_PRIO_BYPASS, 1),
80 EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_LOW1,
81 BT_COEX_PRIO_TBL_PRIO_LOW, 0),
82 EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_LOW2,
83 BT_COEX_PRIO_TBL_PRIO_LOW, 1),
84 EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_HIGH1,
85 BT_COEX_PRIO_TBL_PRIO_HIGH, 0),
86 EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_HIGH2,
87 BT_COEX_PRIO_TBL_PRIO_HIGH, 1),
88 EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_DTIM,
89 BT_COEX_PRIO_TBL_DISABLED, 0),
90 EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_SCAN52,
91 BT_COEX_PRIO_TBL_PRIO_COEX_OFF, 0),
92 EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_SCAN24,
93 BT_COEX_PRIO_TBL_PRIO_COEX_ON, 0),
94 EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_IDLE,
95 BT_COEX_PRIO_TBL_PRIO_COEX_IDLE, 0),
96 0, 0, 0, 0, 0, 0,
97};
98
99#undef EVENT_PRIO_ANT
100
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200101/* BT Antenna Coupling Threshold (dB) */
102#define IWL_BT_ANTENNA_COUPLING_THRESHOLD (35)
103#define IWL_BT_LOAD_FORCE_SISO_THRESHOLD (3)
104
105#define BT_ENABLE_REDUCED_TXPOWER_THRESHOLD (-62)
106#define BT_DISABLE_REDUCED_TXPOWER_THRESHOLD (-65)
107#define BT_REDUCED_TX_POWER_BIT BIT(7)
108
109static inline bool is_loose_coex(void)
110{
111 return iwlwifi_mod_params.ant_coupling >
112 IWL_BT_ANTENNA_COUPLING_THRESHOLD;
113}
114
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200115int iwl_send_bt_prio_tbl(struct iwl_mvm *mvm)
116{
117 return iwl_mvm_send_cmd_pdu(mvm, BT_COEX_PRIO_TABLE, CMD_SYNC,
118 sizeof(struct iwl_bt_coex_prio_tbl_cmd),
119 &iwl_bt_prio_tbl);
120}
121
122static int iwl_send_bt_env(struct iwl_mvm *mvm, u8 action, u8 type)
123{
124 struct iwl_bt_coex_prot_env_cmd env_cmd;
125 int ret;
126
127 env_cmd.action = action;
128 env_cmd.type = type;
129 ret = iwl_mvm_send_cmd_pdu(mvm, BT_COEX_PROT_ENV, CMD_SYNC,
130 sizeof(env_cmd), &env_cmd);
131 if (ret)
132 IWL_ERR(mvm, "failed to send BT env command\n");
133 return ret;
134}
135
136enum iwl_bt_kill_msk {
137 BT_KILL_MSK_DEFAULT,
138 BT_KILL_MSK_SCO_HID_A2DP,
139 BT_KILL_MSK_REDUCED_TXPOW,
140 BT_KILL_MSK_MAX,
141};
142
143static const u32 iwl_bt_ack_kill_msk[BT_KILL_MSK_MAX] = {
Emmanuel Grumbach5b7e6622013-03-10 20:15:24 +0200144 [BT_KILL_MSK_DEFAULT] = 0xffff0000,
145 [BT_KILL_MSK_SCO_HID_A2DP] = 0xffffffff,
146 [BT_KILL_MSK_REDUCED_TXPOW] = 0,
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200147};
148
149static const u32 iwl_bt_cts_kill_msk[BT_KILL_MSK_MAX] = {
Emmanuel Grumbach5b7e6622013-03-10 20:15:24 +0200150 [BT_KILL_MSK_DEFAULT] = 0xffff0000,
151 [BT_KILL_MSK_SCO_HID_A2DP] = 0xffffffff,
152 [BT_KILL_MSK_REDUCED_TXPOW] = 0,
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200153};
154
155#define IWL_BT_DEFAULT_BOOST (0xf0f0f0f0)
156
157/* Tight Coex */
158static const __le32 iwl_tight_lookup[BT_COEX_LUT_SIZE] = {
159 cpu_to_le32(0xaaaaaaaa),
160 cpu_to_le32(0xaaaaaaaa),
161 cpu_to_le32(0xaeaaaaaa),
162 cpu_to_le32(0xaaaaaaaa),
163 cpu_to_le32(0xcc00ff28),
164 cpu_to_le32(0x0000aaaa),
165 cpu_to_le32(0xcc00aaaa),
166 cpu_to_le32(0x0000aaaa),
167 cpu_to_le32(0xc0004000),
168 cpu_to_le32(0x00000000),
169 cpu_to_le32(0xf0005000),
170 cpu_to_le32(0xf0005000),
171};
172
173/* Loose Coex */
174static const __le32 iwl_loose_lookup[BT_COEX_LUT_SIZE] = {
175 cpu_to_le32(0xaaaaaaaa),
176 cpu_to_le32(0xaaaaaaaa),
Emmanuel Grumbach67675832013-05-29 09:09:30 +0300177 cpu_to_le32(0xaaaaaaaa),
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200178 cpu_to_le32(0xaaaaaaaa),
179 cpu_to_le32(0xcc00ff28),
180 cpu_to_le32(0x0000aaaa),
181 cpu_to_le32(0xcc00aaaa),
182 cpu_to_le32(0x0000aaaa),
183 cpu_to_le32(0x00000000),
184 cpu_to_le32(0x00000000),
185 cpu_to_le32(0xf0005000),
186 cpu_to_le32(0xf0005000),
187};
188
189/* Full concurrency */
190static const __le32 iwl_concurrent_lookup[BT_COEX_LUT_SIZE] = {
191 cpu_to_le32(0xaaaaaaaa),
192 cpu_to_le32(0xaaaaaaaa),
193 cpu_to_le32(0xaaaaaaaa),
194 cpu_to_le32(0xaaaaaaaa),
195 cpu_to_le32(0xaaaaaaaa),
196 cpu_to_le32(0xaaaaaaaa),
197 cpu_to_le32(0xaaaaaaaa),
198 cpu_to_le32(0xaaaaaaaa),
199 cpu_to_le32(0x00000000),
200 cpu_to_le32(0x00000000),
201 cpu_to_le32(0x00000000),
202 cpu_to_le32(0x00000000),
203};
204
Emmanuel Grumbache715c3a2013-06-18 05:34:58 +0300205/* single shared antenna */
206static const __le32 iwl_single_shared_ant_lookup[BT_COEX_LUT_SIZE] = {
207 cpu_to_le32(0x40000000),
208 cpu_to_le32(0x00000000),
209 cpu_to_le32(0x44000000),
210 cpu_to_le32(0x00000000),
211 cpu_to_le32(0x40000000),
212 cpu_to_le32(0x00000000),
213 cpu_to_le32(0x44000000),
214 cpu_to_le32(0x00000000),
215 cpu_to_le32(0xC0004000),
216 cpu_to_le32(0xF0005000),
217 cpu_to_le32(0xC0004000),
218 cpu_to_le32(0xF0005000),
219};
220
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200221int iwl_send_bt_init_conf(struct iwl_mvm *mvm)
222{
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300223 struct iwl_bt_coex_cmd *bt_cmd;
224 struct iwl_host_cmd cmd = {
225 .id = BT_CONFIG,
226 .len = { sizeof(*bt_cmd), },
227 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
228 .flags = CMD_SYNC,
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200229 };
230 int ret;
231
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200232 /* go to CALIB state in internal BT-Coex state machine */
233 ret = iwl_send_bt_env(mvm, BT_COEX_ENV_OPEN,
234 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
235 if (ret)
236 return ret;
237
238 ret = iwl_send_bt_env(mvm, BT_COEX_ENV_CLOSE,
239 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
240 if (ret)
241 return ret;
242
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300243 bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
244 if (!bt_cmd)
245 return -ENOMEM;
246 cmd.data[0] = bt_cmd;
247
248 bt_cmd->max_kill = 5;
249 bt_cmd->bt3_time_t7_value = 1;
250 bt_cmd->bt3_prio_sample_time = 2;
251 bt_cmd->bt3_timer_t2_value = 0xc;
252
253 bt_cmd->flags = iwlwifi_mod_params.bt_coex_active ?
254 BT_COEX_NW : BT_COEX_DISABLE;
255 bt_cmd->flags |= BT_CH_PRIMARY_EN | BT_SYNC_2_BT_DISABLE;
256
257 bt_cmd->valid_bit_msk = cpu_to_le16(BT_VALID_ENABLE |
258 BT_VALID_BT_PRIO_BOOST |
259 BT_VALID_MAX_KILL |
260 BT_VALID_3W_TMRS |
261 BT_VALID_KILL_ACK |
262 BT_VALID_KILL_CTS |
263 BT_VALID_REDUCED_TX_POWER |
264 BT_VALID_LUT);
265
266 if (mvm->cfg->bt_shared_single_ant)
267 memcpy(&bt_cmd->decision_lut, iwl_single_shared_ant_lookup,
268 sizeof(iwl_single_shared_ant_lookup));
269 else if (is_loose_coex())
270 memcpy(&bt_cmd->decision_lut, iwl_loose_lookup,
271 sizeof(iwl_tight_lookup));
272 else
273 memcpy(&bt_cmd->decision_lut, iwl_tight_lookup,
274 sizeof(iwl_tight_lookup));
275
276 bt_cmd->bt_prio_boost = cpu_to_le32(IWL_BT_DEFAULT_BOOST);
277 bt_cmd->kill_ack_msk =
278 cpu_to_le32(iwl_bt_ack_kill_msk[BT_KILL_MSK_DEFAULT]);
279 bt_cmd->kill_cts_msk =
280 cpu_to_le32(iwl_bt_cts_kill_msk[BT_KILL_MSK_DEFAULT]);
281
282 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
283
284 ret = iwl_mvm_send_cmd(mvm, &cmd);
285
286 kfree(bt_cmd);
287 return ret;
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200288}
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200289
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200290static int iwl_mvm_bt_udpate_ctrl_kill_msk(struct iwl_mvm *mvm,
291 bool reduced_tx_power)
292{
293 enum iwl_bt_kill_msk bt_kill_msk;
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300294 struct iwl_bt_coex_cmd *bt_cmd;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200295 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300296 struct iwl_host_cmd cmd = {
297 .id = BT_CONFIG,
298 .data[0] = &bt_cmd,
299 .len = { sizeof(*bt_cmd), },
300 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
301 .flags = CMD_SYNC,
302 };
303 int ret = 0;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200304
305 lockdep_assert_held(&mvm->mutex);
306
307 if (reduced_tx_power) {
308 /* Reduced Tx power has precedence on the type of the profile */
309 bt_kill_msk = BT_KILL_MSK_REDUCED_TXPOW;
310 } else {
311 /* Low latency BT profile is active: give higher prio to BT */
312 if (BT_MBOX_MSG(notif, 3, SCO_STATE) ||
313 BT_MBOX_MSG(notif, 3, A2DP_STATE) ||
314 BT_MBOX_MSG(notif, 3, SNIFF_STATE))
315 bt_kill_msk = BT_KILL_MSK_SCO_HID_A2DP;
316 else
317 bt_kill_msk = BT_KILL_MSK_DEFAULT;
318 }
319
320 IWL_DEBUG_COEX(mvm,
321 "Update kill_msk: %d - SCO %sactive A2DP %sactive SNIFF %sactive\n",
322 bt_kill_msk,
323 BT_MBOX_MSG(notif, 3, SCO_STATE) ? "" : "in",
324 BT_MBOX_MSG(notif, 3, A2DP_STATE) ? "" : "in",
325 BT_MBOX_MSG(notif, 3, SNIFF_STATE) ? "" : "in");
326
327 /* Don't send HCMD if there is no update */
328 if (bt_kill_msk == mvm->bt_kill_msk)
329 return 0;
330
331 mvm->bt_kill_msk = bt_kill_msk;
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300332
333 bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
334 if (!bt_cmd)
335 return -ENOMEM;
336 cmd.data[0] = bt_cmd;
337
338 bt_cmd->kill_ack_msk = cpu_to_le32(iwl_bt_ack_kill_msk[bt_kill_msk]);
339 bt_cmd->kill_cts_msk = cpu_to_le32(iwl_bt_cts_kill_msk[bt_kill_msk]);
340 bt_cmd->valid_bit_msk =
341 cpu_to_le16(BT_VALID_KILL_ACK | BT_VALID_KILL_CTS);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200342
343 IWL_DEBUG_COEX(mvm, "bt_kill_msk = %d\n", bt_kill_msk);
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300344
345 ret = iwl_mvm_send_cmd(mvm, &cmd);
346
347 kfree(bt_cmd);
348 return ret;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200349}
350
351static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id,
352 bool enable)
353{
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300354 struct iwl_bt_coex_cmd *bt_cmd;
355 /* Send ASYNC since this can be sent from an atomic context */
356 struct iwl_host_cmd cmd = {
357 .id = BT_CONFIG,
358 .len = { sizeof(*bt_cmd), },
359 .dataflags = { IWL_HCMD_DFL_DUP, },
360 .flags = CMD_ASYNC,
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200361 };
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300362
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200363 struct ieee80211_sta *sta;
364 struct iwl_mvm_sta *mvmsta;
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300365 int ret;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200366
367 /* This can happen if the station has been removed right now */
368 if (sta_id == IWL_MVM_STATION_COUNT)
369 return 0;
370
371 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
372 lockdep_is_held(&mvm->mutex));
373 mvmsta = (void *)sta->drv_priv;
374
375 /* nothing to do */
376 if (mvmsta->bt_reduced_txpower == enable)
377 return 0;
378
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300379 bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_ATOMIC);
380 if (!bt_cmd)
381 return -ENOMEM;
382 cmd.data[0] = bt_cmd;
383
384 bt_cmd->valid_bit_msk = cpu_to_le16(BT_VALID_REDUCED_TX_POWER),
385 bt_cmd->bt_reduced_tx_power = sta_id;
386
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200387 if (enable)
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300388 bt_cmd->bt_reduced_tx_power |= BT_REDUCED_TX_POWER_BIT;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200389
390 IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n",
391 enable ? "en" : "dis", sta_id);
392
393 mvmsta->bt_reduced_txpower = enable;
394
Emmanuel Grumbach03e304e2013-06-26 15:54:34 +0300395 ret = iwl_mvm_send_cmd(mvm, &cmd);
396
397 kfree(bt_cmd);
398 return ret;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200399}
400
401struct iwl_bt_iterator_data {
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200402 struct iwl_bt_coex_profile_notif *notif;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200403 struct iwl_mvm *mvm;
404 u32 num_bss_ifaces;
Emmanuel Grumbach9e511c32013-03-29 14:52:17 +0300405 bool reduced_tx_power;
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200406};
407
408static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac,
409 struct ieee80211_vif *vif)
410{
411 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200412 struct iwl_bt_iterator_data *data = _data;
413 struct iwl_mvm *mvm = data->mvm;
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200414 struct ieee80211_chanctx_conf *chanctx_conf;
415 enum ieee80211_smps_mode smps_mode;
416 enum ieee80211_band band;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200417 int ave_rssi;
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200418
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300419 lockdep_assert_held(&mvm->mutex);
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200420 if (vif->type != NL80211_IFTYPE_STATION)
421 return;
422
423 rcu_read_lock();
424 chanctx_conf = rcu_dereference(vif->chanctx_conf);
425 if (chanctx_conf && chanctx_conf->def.chan)
426 band = chanctx_conf->def.chan->band;
427 else
428 band = -1;
429 rcu_read_unlock();
430
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200431 smps_mode = IEEE80211_SMPS_AUTOMATIC;
432
Emmanuel Grumbach41069b42013-06-25 21:49:19 +0300433 /* non associated BSSes aren't to be considered */
434 if (!vif->bss_conf.assoc)
435 return;
436
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200437 if (band != IEEE80211_BAND_2GHZ) {
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300438 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
439 smps_mode);
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200440 return;
441 }
442
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200443 if (data->notif->bt_status)
444 smps_mode = IEEE80211_SMPS_DYNAMIC;
445
Emmanuel Grumbachb9269262013-03-19 14:40:38 +0200446 if (data->notif->bt_traffic_load >= IWL_BT_LOAD_FORCE_SISO_THRESHOLD)
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200447 smps_mode = IEEE80211_SMPS_STATIC;
448
449 IWL_DEBUG_COEX(data->mvm,
450 "mac %d: bt_status %d traffic_load %d smps_req %d\n",
451 mvmvif->id, data->notif->bt_status,
452 data->notif->bt_traffic_load, smps_mode);
453
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300454 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX, smps_mode);
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200455
456 /* don't reduce the Tx power if in loose scheme */
457 if (is_loose_coex())
458 return;
459
460 data->num_bss_ifaces++;
461
462 /* reduced Txpower only if there are open BT connections, so ...*/
463 if (!BT_MBOX_MSG(data->notif, 3, OPEN_CON_2)) {
464 /* ... cancel reduced Tx power ... */
465 if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
466 IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
Emmanuel Grumbach9e511c32013-03-29 14:52:17 +0300467 data->reduced_tx_power = false;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200468
469 /* ... and there is no need to get reports on RSSI any more. */
Andrei Otcheretianski911222b2013-07-21 17:37:19 +0300470 mvmvif->bf_data.last_bt_coex_event = 0;
471 mvmvif->bf_data.bt_coex_max_thold = 0;
472 mvmvif->bf_data.bt_coex_min_thold = 0;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200473 return;
474 }
475
Andrei Otcheretianski911222b2013-07-21 17:37:19 +0300476 /* try to get the avg rssi from fw */
477 ave_rssi = mvmvif->bf_data.ave_beacon_signal;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200478
479 /* if the RSSI isn't valid, fake it is very low */
480 if (!ave_rssi)
481 ave_rssi = -100;
482 if (ave_rssi > BT_ENABLE_REDUCED_TXPOWER_THRESHOLD) {
483 if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true))
484 IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
485
486 /*
487 * bt_kill_msk can be BT_KILL_MSK_REDUCED_TXPOW only if all the
488 * BSS / P2P clients have rssi above threshold.
489 * We set the bt_kill_msk to BT_KILL_MSK_REDUCED_TXPOW before
490 * the iteration, if one interface's rssi isn't good enough,
491 * bt_kill_msk will be set to default values.
492 */
493 } else if (ave_rssi < BT_DISABLE_REDUCED_TXPOWER_THRESHOLD) {
494 if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
495 IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
496
497 /*
498 * One interface hasn't rssi above threshold, bt_kill_msk must
499 * be set to default values.
500 */
Emmanuel Grumbach9e511c32013-03-29 14:52:17 +0300501 data->reduced_tx_power = false;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200502 }
503
504 /* Begin to monitor the RSSI: it may influence the reduced Tx power */
Andrei Otcheretianski911222b2013-07-21 17:37:19 +0300505
506 /* reset previous bt coex event tracking */
507 mvmvif->bf_data.last_bt_coex_event = 0;
508 mvmvif->bf_data.bt_coex_max_thold =
509 BT_ENABLE_REDUCED_TXPOWER_THRESHOLD;
510 mvmvif->bf_data.bt_coex_min_thold =
511 BT_DISABLE_REDUCED_TXPOWER_THRESHOLD;
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200512}
513
Emmanuel Grumbachd37cac92013-03-29 14:56:19 +0300514static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm)
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200515{
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200516 struct iwl_bt_iterator_data data = {
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200517 .mvm = mvm,
Emmanuel Grumbachd37cac92013-03-29 14:56:19 +0300518 .notif = &mvm->last_bt_notif,
Emmanuel Grumbach9e511c32013-03-29 14:52:17 +0300519 .reduced_tx_power = true,
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200520 };
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200521
Emmanuel Grumbach7da052b2013-02-10 17:06:17 +0200522 ieee80211_iterate_active_interfaces_atomic(
523 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
524 iwl_mvm_bt_notif_iterator, &data);
525
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200526 /*
527 * If there are no BSS / P2P client interfaces, reduced Tx Power is
528 * irrelevant since it is based on the RSSI coming from the beacon.
529 * Use BT_KILL_MSK_DEFAULT in that case.
530 */
Emmanuel Grumbach9e511c32013-03-29 14:52:17 +0300531 data.reduced_tx_power = data.reduced_tx_power && data.num_bss_ifaces;
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200532
Emmanuel Grumbach9e511c32013-03-29 14:52:17 +0300533 if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm, data.reduced_tx_power))
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200534 IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200535}
536
537/* upon association, the fw will send in BT Coex notification */
538int iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm,
539 struct iwl_rx_cmd_buffer *rxb,
540 struct iwl_device_cmd *dev_cmd)
541{
542 struct iwl_rx_packet *pkt = rxb_addr(rxb);
543 struct iwl_bt_coex_profile_notif *notif = (void *)pkt->data;
544
545
546 IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n");
547 IWL_DEBUG_COEX(mvm, "\tBT %salive\n", notif->bt_status ? "" : "not ");
548 IWL_DEBUG_COEX(mvm, "\tBT open conn %d\n", notif->bt_open_conn);
549 IWL_DEBUG_COEX(mvm, "\tBT traffic load %d\n", notif->bt_traffic_load);
550 IWL_DEBUG_COEX(mvm, "\tBT agg traffic load %d\n",
551 notif->bt_agg_traffic_load);
552 IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n", notif->bt_ci_compliance);
553
Emmanuel Grumbachd37cac92013-03-29 14:56:19 +0300554 /* remember this notification for future use: rssi fluctuations */
555 memcpy(&mvm->last_bt_notif, notif, sizeof(mvm->last_bt_notif));
556
557 iwl_mvm_bt_coex_notif_handle(mvm);
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200558
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200559 /*
560 * This is an async handler for a notification, returning anything other
561 * than 0 doesn't make sense even if HCMD failed.
562 */
Emmanuel Grumbachf421f9c2013-01-17 14:20:29 +0200563 return 0;
564}
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200565
566static void iwl_mvm_bt_rssi_iterator(void *_data, u8 *mac,
567 struct ieee80211_vif *vif)
568{
569 struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv;
570 struct iwl_bt_iterator_data *data = _data;
571 struct iwl_mvm *mvm = data->mvm;
572
573 struct ieee80211_sta *sta;
574 struct iwl_mvm_sta *mvmsta;
575
576 if (vif->type != NL80211_IFTYPE_STATION ||
577 mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
578 return;
579
580 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
581 lockdep_is_held(&mvm->mutex));
582 mvmsta = (void *)sta->drv_priv;
583
Emmanuel Grumbach8e0366f2013-06-25 21:57:08 +0300584 data->num_bss_ifaces++;
585
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200586 /*
587 * This interface doesn't support reduced Tx power (because of low
588 * RSSI probably), then set bt_kill_msk to default values.
589 */
590 if (!mvmsta->bt_reduced_txpower)
Emmanuel Grumbach9e511c32013-03-29 14:52:17 +0300591 data->reduced_tx_power = false;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200592 /* else - possibly leave it to BT_KILL_MSK_REDUCED_TXPOW */
593}
594
595void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
596 enum ieee80211_rssi_event rssi_event)
597{
598 struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200599 struct iwl_bt_iterator_data data = {
600 .mvm = mvm,
Emmanuel Grumbach9e511c32013-03-29 14:52:17 +0300601 .reduced_tx_power = true,
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200602 };
603 int ret;
604
605 mutex_lock(&mvm->mutex);
606
607 /* Rssi update while not associated ?! */
608 if (WARN_ON_ONCE(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT))
609 goto out_unlock;
610
611 /* No open connection - reports should be disabled */
612 if (!BT_MBOX_MSG(&mvm->last_bt_notif, 3, OPEN_CON_2))
613 goto out_unlock;
614
615 IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid,
616 rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW");
617
618 /*
619 * Check if rssi is good enough for reduced Tx power, but not in loose
620 * scheme.
621 */
622 if (rssi_event == RSSI_EVENT_LOW || is_loose_coex())
623 ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
624 false);
625 else
626 ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true);
627
628 if (ret)
629 IWL_ERR(mvm, "couldn't send BT_CONFIG HCMD upon RSSI event\n");
630
631 ieee80211_iterate_active_interfaces_atomic(
632 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
633 iwl_mvm_bt_rssi_iterator, &data);
634
635 /*
636 * If there are no BSS / P2P client interfaces, reduced Tx Power is
637 * irrelevant since it is based on the RSSI coming from the beacon.
638 * Use BT_KILL_MSK_DEFAULT in that case.
639 */
Emmanuel Grumbach9e511c32013-03-29 14:52:17 +0300640 data.reduced_tx_power = data.reduced_tx_power && data.num_bss_ifaces;
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200641
Emmanuel Grumbach9e511c32013-03-29 14:52:17 +0300642 if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm, data.reduced_tx_power))
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200643 IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
644
645 out_unlock:
646 mutex_unlock(&mvm->mutex);
647}
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200648
649void iwl_mvm_bt_coex_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
650{
Emmanuel Grumbachd37cac92013-03-29 14:56:19 +0300651 iwl_mvm_bt_coex_notif_handle(mvm);
Emmanuel Grumbach9166b1e2013-03-20 15:28:27 +0200652}