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