Commit | Line | Data |
---|---|---|
931d4160 EG |
1 | /****************************************************************************** |
2 | * | |
3 | * This file is provided under a dual BSD/GPLv2 license. When using or | |
4 | * redistributing this file, you may do so under either license. | |
5 | * | |
6 | * GPL LICENSE SUMMARY | |
7 | * | |
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 | ||
2b76ef13 EG |
64 | #include <net/mac80211.h> |
65 | ||
931d4160 EG |
66 | #include "fw-api-bt-coex.h" |
67 | #include "iwl-modparams.h" | |
68 | #include "mvm.h" | |
f421f9c3 | 69 | #include "iwl-debug.h" |
931d4160 EG |
70 | |
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 | ||
75 | static 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 | ||
2b76ef13 EG |
101 | /* 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 | ||
109 | static inline bool is_loose_coex(void) | |
110 | { | |
111 | return iwlwifi_mod_params.ant_coupling > | |
112 | IWL_BT_ANTENNA_COUPLING_THRESHOLD; | |
113 | } | |
114 | ||
931d4160 EG |
115 | int 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 | ||
122 | static 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 | ||
136 | enum 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 | ||
143 | static const u32 iwl_bt_ack_kill_msk[BT_KILL_MSK_MAX] = { | |
5b7e662b EG |
144 | [BT_KILL_MSK_DEFAULT] = 0xffff0000, |
145 | [BT_KILL_MSK_SCO_HID_A2DP] = 0xffffffff, | |
146 | [BT_KILL_MSK_REDUCED_TXPOW] = 0, | |
931d4160 EG |
147 | }; |
148 | ||
149 | static const u32 iwl_bt_cts_kill_msk[BT_KILL_MSK_MAX] = { | |
5b7e662b EG |
150 | [BT_KILL_MSK_DEFAULT] = 0xffff0000, |
151 | [BT_KILL_MSK_SCO_HID_A2DP] = 0xffffffff, | |
152 | [BT_KILL_MSK_REDUCED_TXPOW] = 0, | |
931d4160 EG |
153 | }; |
154 | ||
155 | #define IWL_BT_DEFAULT_BOOST (0xf0f0f0f0) | |
156 | ||
157 | /* Tight Coex */ | |
158 | static 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 */ | |
174 | static const __le32 iwl_loose_lookup[BT_COEX_LUT_SIZE] = { | |
175 | cpu_to_le32(0xaaaaaaaa), | |
176 | cpu_to_le32(0xaaaaaaaa), | |
177 | cpu_to_le32(0xaeaaaaaa), | |
178 | 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 */ | |
190 | static 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 | ||
931d4160 EG |
205 | int iwl_send_bt_init_conf(struct iwl_mvm *mvm) |
206 | { | |
207 | struct iwl_bt_coex_cmd cmd = { | |
208 | .max_kill = 5, | |
209 | .bt3_time_t7_value = 1, | |
210 | .bt3_prio_sample_time = 2, | |
211 | .bt3_timer_t2_value = 0xc, | |
212 | }; | |
213 | int ret; | |
214 | ||
215 | cmd.flags = iwlwifi_mod_params.bt_coex_active ? | |
216 | BT_COEX_NW : BT_COEX_DISABLE; | |
cf69d757 | 217 | cmd.flags |= BT_CH_PRIMARY_EN | BT_SYNC_2_BT_DISABLE; |
931d4160 EG |
218 | |
219 | cmd.valid_bit_msk = cpu_to_le16(BT_VALID_ENABLE | | |
220 | BT_VALID_BT_PRIO_BOOST | | |
221 | BT_VALID_MAX_KILL | | |
222 | BT_VALID_3W_TMRS | | |
223 | BT_VALID_KILL_ACK | | |
224 | BT_VALID_KILL_CTS | | |
225 | BT_VALID_REDUCED_TX_POWER | | |
226 | BT_VALID_LUT); | |
227 | ||
2b76ef13 | 228 | if (is_loose_coex()) |
931d4160 EG |
229 | memcpy(&cmd.decision_lut, iwl_loose_lookup, |
230 | sizeof(iwl_tight_lookup)); | |
231 | else | |
232 | memcpy(&cmd.decision_lut, iwl_tight_lookup, | |
233 | sizeof(iwl_tight_lookup)); | |
234 | ||
235 | cmd.bt_prio_boost = cpu_to_le32(IWL_BT_DEFAULT_BOOST); | |
236 | cmd.kill_ack_msk = | |
237 | cpu_to_le32(iwl_bt_ack_kill_msk[BT_KILL_MSK_DEFAULT]); | |
238 | cmd.kill_cts_msk = | |
239 | cpu_to_le32(iwl_bt_cts_kill_msk[BT_KILL_MSK_DEFAULT]); | |
240 | ||
2b76ef13 EG |
241 | memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); |
242 | ||
931d4160 EG |
243 | /* go to CALIB state in internal BT-Coex state machine */ |
244 | ret = iwl_send_bt_env(mvm, BT_COEX_ENV_OPEN, | |
245 | BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); | |
246 | if (ret) | |
247 | return ret; | |
248 | ||
249 | ret = iwl_send_bt_env(mvm, BT_COEX_ENV_CLOSE, | |
250 | BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); | |
251 | if (ret) | |
252 | return ret; | |
253 | ||
254 | return iwl_mvm_send_cmd_pdu(mvm, BT_CONFIG, CMD_SYNC, | |
255 | sizeof(cmd), &cmd); | |
256 | } | |
f421f9c3 | 257 | |
2b76ef13 EG |
258 | static int iwl_mvm_bt_udpate_ctrl_kill_msk(struct iwl_mvm *mvm, |
259 | bool reduced_tx_power) | |
260 | { | |
261 | enum iwl_bt_kill_msk bt_kill_msk; | |
262 | struct iwl_bt_coex_cmd cmd = {}; | |
263 | struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif; | |
264 | ||
265 | lockdep_assert_held(&mvm->mutex); | |
266 | ||
267 | if (reduced_tx_power) { | |
268 | /* Reduced Tx power has precedence on the type of the profile */ | |
269 | bt_kill_msk = BT_KILL_MSK_REDUCED_TXPOW; | |
270 | } else { | |
271 | /* Low latency BT profile is active: give higher prio to BT */ | |
272 | if (BT_MBOX_MSG(notif, 3, SCO_STATE) || | |
273 | BT_MBOX_MSG(notif, 3, A2DP_STATE) || | |
274 | BT_MBOX_MSG(notif, 3, SNIFF_STATE)) | |
275 | bt_kill_msk = BT_KILL_MSK_SCO_HID_A2DP; | |
276 | else | |
277 | bt_kill_msk = BT_KILL_MSK_DEFAULT; | |
278 | } | |
279 | ||
280 | IWL_DEBUG_COEX(mvm, | |
281 | "Update kill_msk: %d - SCO %sactive A2DP %sactive SNIFF %sactive\n", | |
282 | bt_kill_msk, | |
283 | BT_MBOX_MSG(notif, 3, SCO_STATE) ? "" : "in", | |
284 | BT_MBOX_MSG(notif, 3, A2DP_STATE) ? "" : "in", | |
285 | BT_MBOX_MSG(notif, 3, SNIFF_STATE) ? "" : "in"); | |
286 | ||
287 | /* Don't send HCMD if there is no update */ | |
288 | if (bt_kill_msk == mvm->bt_kill_msk) | |
289 | return 0; | |
290 | ||
291 | mvm->bt_kill_msk = bt_kill_msk; | |
292 | cmd.kill_ack_msk = cpu_to_le32(iwl_bt_ack_kill_msk[bt_kill_msk]); | |
293 | cmd.kill_cts_msk = cpu_to_le32(iwl_bt_cts_kill_msk[bt_kill_msk]); | |
294 | cmd.valid_bit_msk = cpu_to_le16(BT_VALID_KILL_ACK | BT_VALID_KILL_CTS); | |
295 | ||
296 | IWL_DEBUG_COEX(mvm, "bt_kill_msk = %d\n", bt_kill_msk); | |
297 | return iwl_mvm_send_cmd_pdu(mvm, BT_CONFIG, CMD_SYNC, | |
298 | sizeof(cmd), &cmd); | |
299 | } | |
300 | ||
301 | static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id, | |
302 | bool enable) | |
303 | { | |
304 | struct iwl_bt_coex_cmd cmd = { | |
305 | .valid_bit_msk = cpu_to_le16(BT_VALID_REDUCED_TX_POWER), | |
306 | .bt_reduced_tx_power = sta_id, | |
307 | }; | |
308 | struct ieee80211_sta *sta; | |
309 | struct iwl_mvm_sta *mvmsta; | |
310 | ||
311 | /* This can happen if the station has been removed right now */ | |
312 | if (sta_id == IWL_MVM_STATION_COUNT) | |
313 | return 0; | |
314 | ||
315 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
316 | lockdep_is_held(&mvm->mutex)); | |
317 | mvmsta = (void *)sta->drv_priv; | |
318 | ||
319 | /* nothing to do */ | |
320 | if (mvmsta->bt_reduced_txpower == enable) | |
321 | return 0; | |
322 | ||
323 | if (enable) | |
324 | cmd.bt_reduced_tx_power |= BT_REDUCED_TX_POWER_BIT; | |
325 | ||
326 | IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n", | |
327 | enable ? "en" : "dis", sta_id); | |
328 | ||
329 | mvmsta->bt_reduced_txpower = enable; | |
330 | ||
331 | /* Send ASYNC since this can be sent from an atomic context */ | |
332 | return iwl_mvm_send_cmd_pdu(mvm, BT_CONFIG, CMD_ASYNC, | |
333 | sizeof(cmd), &cmd); | |
334 | } | |
335 | ||
336 | struct iwl_bt_iterator_data { | |
7da052b8 | 337 | struct iwl_bt_coex_profile_notif *notif; |
2b76ef13 EG |
338 | struct iwl_mvm *mvm; |
339 | u32 num_bss_ifaces; | |
9e511c31 | 340 | bool reduced_tx_power; |
7da052b8 EG |
341 | }; |
342 | ||
343 | static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac, | |
344 | struct ieee80211_vif *vif) | |
345 | { | |
346 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
2b76ef13 EG |
347 | struct iwl_bt_iterator_data *data = _data; |
348 | struct iwl_mvm *mvm = data->mvm; | |
7da052b8 EG |
349 | struct ieee80211_chanctx_conf *chanctx_conf; |
350 | enum ieee80211_smps_mode smps_mode; | |
351 | enum ieee80211_band band; | |
2b76ef13 | 352 | int ave_rssi; |
7da052b8 EG |
353 | |
354 | if (vif->type != NL80211_IFTYPE_STATION) | |
355 | return; | |
356 | ||
357 | rcu_read_lock(); | |
358 | chanctx_conf = rcu_dereference(vif->chanctx_conf); | |
359 | if (chanctx_conf && chanctx_conf->def.chan) | |
360 | band = chanctx_conf->def.chan->band; | |
361 | else | |
362 | band = -1; | |
363 | rcu_read_unlock(); | |
364 | ||
7da052b8 EG |
365 | smps_mode = IEEE80211_SMPS_AUTOMATIC; |
366 | ||
9166b1ee EG |
367 | if (band != IEEE80211_BAND_2GHZ) { |
368 | ieee80211_request_smps(vif, smps_mode); | |
369 | return; | |
370 | } | |
371 | ||
7da052b8 EG |
372 | if (data->notif->bt_status) |
373 | smps_mode = IEEE80211_SMPS_DYNAMIC; | |
374 | ||
b9269262 | 375 | if (data->notif->bt_traffic_load >= IWL_BT_LOAD_FORCE_SISO_THRESHOLD) |
7da052b8 EG |
376 | smps_mode = IEEE80211_SMPS_STATIC; |
377 | ||
378 | IWL_DEBUG_COEX(data->mvm, | |
379 | "mac %d: bt_status %d traffic_load %d smps_req %d\n", | |
380 | mvmvif->id, data->notif->bt_status, | |
381 | data->notif->bt_traffic_load, smps_mode); | |
382 | ||
383 | ieee80211_request_smps(vif, smps_mode); | |
2b76ef13 EG |
384 | |
385 | /* don't reduce the Tx power if in loose scheme */ | |
386 | if (is_loose_coex()) | |
387 | return; | |
388 | ||
389 | data->num_bss_ifaces++; | |
390 | ||
391 | /* reduced Txpower only if there are open BT connections, so ...*/ | |
392 | if (!BT_MBOX_MSG(data->notif, 3, OPEN_CON_2)) { | |
393 | /* ... cancel reduced Tx power ... */ | |
394 | if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false)) | |
395 | IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n"); | |
9e511c31 | 396 | data->reduced_tx_power = false; |
2b76ef13 EG |
397 | |
398 | /* ... and there is no need to get reports on RSSI any more. */ | |
399 | ieee80211_disable_rssi_reports(vif); | |
400 | return; | |
401 | } | |
402 | ||
403 | ave_rssi = ieee80211_ave_rssi(vif); | |
404 | ||
405 | /* if the RSSI isn't valid, fake it is very low */ | |
406 | if (!ave_rssi) | |
407 | ave_rssi = -100; | |
408 | if (ave_rssi > BT_ENABLE_REDUCED_TXPOWER_THRESHOLD) { | |
409 | if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true)) | |
410 | IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n"); | |
411 | ||
412 | /* | |
413 | * bt_kill_msk can be BT_KILL_MSK_REDUCED_TXPOW only if all the | |
414 | * BSS / P2P clients have rssi above threshold. | |
415 | * We set the bt_kill_msk to BT_KILL_MSK_REDUCED_TXPOW before | |
416 | * the iteration, if one interface's rssi isn't good enough, | |
417 | * bt_kill_msk will be set to default values. | |
418 | */ | |
419 | } else if (ave_rssi < BT_DISABLE_REDUCED_TXPOWER_THRESHOLD) { | |
420 | if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false)) | |
421 | IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n"); | |
422 | ||
423 | /* | |
424 | * One interface hasn't rssi above threshold, bt_kill_msk must | |
425 | * be set to default values. | |
426 | */ | |
9e511c31 | 427 | data->reduced_tx_power = false; |
2b76ef13 EG |
428 | } |
429 | ||
430 | /* Begin to monitor the RSSI: it may influence the reduced Tx power */ | |
431 | ieee80211_enable_rssi_reports(vif, BT_DISABLE_REDUCED_TXPOWER_THRESHOLD, | |
432 | BT_ENABLE_REDUCED_TXPOWER_THRESHOLD); | |
7da052b8 EG |
433 | } |
434 | ||
9166b1ee EG |
435 | static void iwl_mvm_new_bt_coex_notif(struct iwl_mvm *mvm, |
436 | struct iwl_bt_coex_profile_notif *notif) | |
f421f9c3 | 437 | { |
2b76ef13 | 438 | struct iwl_bt_iterator_data data = { |
7da052b8 EG |
439 | .mvm = mvm, |
440 | .notif = notif, | |
9e511c31 | 441 | .reduced_tx_power = true, |
7da052b8 | 442 | }; |
f421f9c3 | 443 | |
10942342 EG |
444 | /* remember this notification for future use: rssi fluctuations */ |
445 | memcpy(&mvm->last_bt_notif, notif, sizeof(mvm->last_bt_notif)); | |
446 | ||
7da052b8 EG |
447 | ieee80211_iterate_active_interfaces_atomic( |
448 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
449 | iwl_mvm_bt_notif_iterator, &data); | |
450 | ||
2b76ef13 EG |
451 | /* |
452 | * If there are no BSS / P2P client interfaces, reduced Tx Power is | |
453 | * irrelevant since it is based on the RSSI coming from the beacon. | |
454 | * Use BT_KILL_MSK_DEFAULT in that case. | |
455 | */ | |
9e511c31 | 456 | data.reduced_tx_power = data.reduced_tx_power && data.num_bss_ifaces; |
2b76ef13 | 457 | |
9e511c31 | 458 | if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm, data.reduced_tx_power)) |
2b76ef13 | 459 | IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n"); |
9166b1ee EG |
460 | } |
461 | ||
462 | /* upon association, the fw will send in BT Coex notification */ | |
463 | int iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm, | |
464 | struct iwl_rx_cmd_buffer *rxb, | |
465 | struct iwl_device_cmd *dev_cmd) | |
466 | { | |
467 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
468 | struct iwl_bt_coex_profile_notif *notif = (void *)pkt->data; | |
469 | ||
470 | ||
471 | IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n"); | |
472 | IWL_DEBUG_COEX(mvm, "\tBT %salive\n", notif->bt_status ? "" : "not "); | |
473 | IWL_DEBUG_COEX(mvm, "\tBT open conn %d\n", notif->bt_open_conn); | |
474 | IWL_DEBUG_COEX(mvm, "\tBT traffic load %d\n", notif->bt_traffic_load); | |
475 | IWL_DEBUG_COEX(mvm, "\tBT agg traffic load %d\n", | |
476 | notif->bt_agg_traffic_load); | |
477 | IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n", notif->bt_ci_compliance); | |
478 | ||
479 | iwl_mvm_new_bt_coex_notif(mvm, notif); | |
2b76ef13 EG |
480 | |
481 | /* | |
482 | * This is an async handler for a notification, returning anything other | |
483 | * than 0 doesn't make sense even if HCMD failed. | |
484 | */ | |
485 | return 0; | |
486 | } | |
487 | ||
488 | static void iwl_mvm_bt_rssi_iterator(void *_data, u8 *mac, | |
489 | struct ieee80211_vif *vif) | |
490 | { | |
491 | struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv; | |
492 | struct iwl_bt_iterator_data *data = _data; | |
493 | struct iwl_mvm *mvm = data->mvm; | |
494 | ||
495 | struct ieee80211_sta *sta; | |
496 | struct iwl_mvm_sta *mvmsta; | |
497 | ||
498 | if (vif->type != NL80211_IFTYPE_STATION || | |
499 | mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT) | |
500 | return; | |
501 | ||
502 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id], | |
503 | lockdep_is_held(&mvm->mutex)); | |
504 | mvmsta = (void *)sta->drv_priv; | |
505 | ||
506 | /* | |
507 | * This interface doesn't support reduced Tx power (because of low | |
508 | * RSSI probably), then set bt_kill_msk to default values. | |
509 | */ | |
510 | if (!mvmsta->bt_reduced_txpower) | |
9e511c31 | 511 | data->reduced_tx_power = false; |
2b76ef13 EG |
512 | /* else - possibly leave it to BT_KILL_MSK_REDUCED_TXPOW */ |
513 | } | |
514 | ||
515 | void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif, | |
516 | enum ieee80211_rssi_event rssi_event) | |
517 | { | |
518 | struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv; | |
2b76ef13 EG |
519 | struct iwl_bt_iterator_data data = { |
520 | .mvm = mvm, | |
9e511c31 | 521 | .reduced_tx_power = true, |
2b76ef13 EG |
522 | }; |
523 | int ret; | |
524 | ||
525 | mutex_lock(&mvm->mutex); | |
526 | ||
527 | /* Rssi update while not associated ?! */ | |
528 | if (WARN_ON_ONCE(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)) | |
529 | goto out_unlock; | |
530 | ||
531 | /* No open connection - reports should be disabled */ | |
532 | if (!BT_MBOX_MSG(&mvm->last_bt_notif, 3, OPEN_CON_2)) | |
533 | goto out_unlock; | |
534 | ||
535 | IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid, | |
536 | rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW"); | |
537 | ||
538 | /* | |
539 | * Check if rssi is good enough for reduced Tx power, but not in loose | |
540 | * scheme. | |
541 | */ | |
542 | if (rssi_event == RSSI_EVENT_LOW || is_loose_coex()) | |
543 | ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, | |
544 | false); | |
f421f9c3 | 545 | else |
2b76ef13 | 546 | ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true); |
f421f9c3 | 547 | |
2b76ef13 EG |
548 | if (ret) |
549 | IWL_ERR(mvm, "couldn't send BT_CONFIG HCMD upon RSSI event\n"); | |
f421f9c3 | 550 | |
2b76ef13 EG |
551 | ieee80211_iterate_active_interfaces_atomic( |
552 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
553 | iwl_mvm_bt_rssi_iterator, &data); | |
f421f9c3 | 554 | |
2b76ef13 EG |
555 | /* |
556 | * If there are no BSS / P2P client interfaces, reduced Tx Power is | |
557 | * irrelevant since it is based on the RSSI coming from the beacon. | |
558 | * Use BT_KILL_MSK_DEFAULT in that case. | |
559 | */ | |
9e511c31 | 560 | data.reduced_tx_power = data.reduced_tx_power && data.num_bss_ifaces; |
f421f9c3 | 561 | |
9e511c31 | 562 | if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm, data.reduced_tx_power)) |
2b76ef13 | 563 | IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n"); |
f421f9c3 | 564 | |
2b76ef13 EG |
565 | out_unlock: |
566 | mutex_unlock(&mvm->mutex); | |
f421f9c3 | 567 | } |
9166b1ee EG |
568 | |
569 | void iwl_mvm_bt_coex_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif) | |
570 | { | |
571 | struct ieee80211_chanctx_conf *chanctx_conf; | |
572 | enum ieee80211_band band; | |
573 | ||
574 | rcu_read_lock(); | |
575 | chanctx_conf = rcu_dereference(vif->chanctx_conf); | |
576 | if (chanctx_conf && chanctx_conf->def.chan) | |
577 | band = chanctx_conf->def.chan->band; | |
578 | else | |
579 | band = -1; | |
580 | rcu_read_unlock(); | |
581 | ||
582 | /* if we are in 2GHz we will get a notification from the fw */ | |
583 | if (band == IEEE80211_BAND_2GHZ) | |
584 | return; | |
585 | ||
586 | /* else, we can remove all the constraints */ | |
587 | memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); | |
588 | ||
589 | iwl_mvm_new_bt_coex_notif(mvm, &mvm->last_bt_notif); | |
590 | } |