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 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 8 | * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved. |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 9 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Emmanuel Grumbach | fbfe378 | 2017-07-23 13:59:47 +0300 | [diff] [blame] | 10 | * Copyright(c) 2017 Intel Deutschland GmbH |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 11 | * |
| 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 Grumbach | cb2f827 | 2015-11-17 15:39:56 +0200 | [diff] [blame] | 30 | * Intel Linux Wireless <linuxwifi@intel.com> |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 31 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 32 | * |
| 33 | * BSD LICENSE |
| 34 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 35 | * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved. |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 36 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Emmanuel Grumbach | fbfe378 | 2017-07-23 13:59:47 +0300 | [diff] [blame] | 37 | * Copyright(c) 2017 Intel Deutschland GmbH |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 38 | * 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 Grumbach | ee7bea5 | 2014-03-06 10:30:49 +0200 | [diff] [blame] | 68 | #include <linux/ieee80211.h> |
| 69 | #include <linux/etherdevice.h> |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 70 | #include <net/mac80211.h> |
| 71 | |
Johannes Berg | d172a5e | 2017-06-02 15:15:53 +0200 | [diff] [blame] | 72 | #include "fw/api/coex.h" |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 73 | #include "iwl-modparams.h" |
| 74 | #include "mvm.h" |
Emmanuel Grumbach | f421f9c | 2013-01-17 14:20:29 +0200 | [diff] [blame] | 75 | #include "iwl-debug.h" |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 76 | |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 77 | /* 20MHz / 40MHz below / 40Mhz above*/ |
| 78 | static 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 Grumbach | ad17b1d | 2016-06-22 10:51:31 +0300 | [diff] [blame] | 147 | cpu_to_le64(0xFE00000000ULL), |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 148 | cpu_to_le64(0x0ULL), |
Emmanuel Grumbach | d2ccc90 | 2013-12-24 10:55:24 +0200 | [diff] [blame] | 149 | cpu_to_le64(0x0ULL) |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 150 | }, |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 151 | }; |
| 152 | |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 153 | static enum iwl_bt_coex_lut_type |
| 154 | iwl_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 Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 159 | u32 primary_ch_phy_id, secondary_ch_phy_id; |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 160 | |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 161 | /* |
| 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 Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 168 | |
| 169 | rcu_read_lock(); |
| 170 | |
| 171 | chanctx_conf = rcu_dereference(vif->chanctx_conf); |
| 172 | |
| 173 | if (!chanctx_conf || |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 174 | chanctx_conf->def.chan->band != NL80211_BAND_2GHZ) { |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 175 | rcu_read_unlock(); |
Emmanuel Grumbach | 7fa4fa0 | 2014-05-25 13:58:31 +0300 | [diff] [blame] | 176 | return BT_COEX_INVALID_LUT; |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | ret = BT_COEX_TX_DIS_LUT; |
| 180 | |
Emmanuel Grumbach | 3914991 | 2013-07-14 13:40:21 +0300 | [diff] [blame] | 181 | if (mvm->cfg->bt_shared_single_ant) { |
| 182 | rcu_read_unlock(); |
| 183 | return ret; |
| 184 | } |
| 185 | |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 186 | phy_ctx_id = *((u16 *)chanctx_conf->drv_priv); |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 187 | 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 Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 190 | |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 191 | if (primary_ch_phy_id == phy_ctx_id) |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 192 | ret = le32_to_cpu(mvm->last_bt_notif.primary_ch_lut); |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 193 | else if (secondary_ch_phy_id == phy_ctx_id) |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 194 | 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 Grumbach | b3de3ef | 2017-05-29 14:01:06 +0300 | [diff] [blame] | 202 | int iwl_mvm_send_bt_init_conf(struct iwl_mvm *mvm) |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 203 | { |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 204 | struct iwl_bt_coex_cmd bt_cmd = {}; |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 205 | u32 mode; |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 206 | |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 207 | 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 Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 211 | case BT_FORCE_ANT_BT: |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 212 | mode = BT_COEX_BT; |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 213 | break; |
| 214 | case BT_FORCE_ANT_WIFI: |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 215 | mode = BT_COEX_WIFI; |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 216 | break; |
| 217 | default: |
| 218 | WARN_ON(1); |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 219 | mode = 0; |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 220 | } |
| 221 | |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 222 | bt_cmd.mode = cpu_to_le32(mode); |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 223 | goto send_cmd; |
| 224 | } |
| 225 | |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 226 | mode = iwlwifi_mod_params.bt_coex_active ? BT_COEX_NW : BT_COEX_DISABLE; |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 227 | bt_cmd.mode = cpu_to_le32(mode); |
Emmanuel Grumbach | 03e304e | 2013-06-26 15:54:34 +0300 | [diff] [blame] | 228 | |
Emmanuel Grumbach | 741e703 | 2014-01-27 12:12:50 +0200 | [diff] [blame] | 229 | if (IWL_MVM_BT_COEX_SYNC2SCO) |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 230 | bt_cmd.enabled_modules |= |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 231 | cpu_to_le32(BT_COEX_SYNC2SCO_ENABLED); |
Emmanuel Grumbach | 741e703 | 2014-01-27 12:12:50 +0200 | [diff] [blame] | 232 | |
Avri Altman | e7c2e1f | 2015-10-29 16:50:57 +0200 | [diff] [blame] | 233 | if (iwl_mvm_is_mplut_supported(mvm)) |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 234 | bt_cmd.enabled_modules |= cpu_to_le32(BT_COEX_MPLUT_ENABLED); |
Emmanuel Grumbach | cdb0056 | 2014-03-16 21:55:43 +0200 | [diff] [blame] | 235 | |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 236 | bt_cmd.enabled_modules |= cpu_to_le32(BT_COEX_HIGH_BAND_RET); |
Emmanuel Grumbach | 261c0ec | 2014-06-11 15:37:25 +0300 | [diff] [blame] | 237 | |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 238 | send_cmd: |
Emmanuel Grumbach | 03e304e | 2013-06-26 15:54:34 +0300 | [diff] [blame] | 239 | memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 240 | memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd)); |
Emmanuel Grumbach | 03e304e | 2013-06-26 15:54:34 +0300 | [diff] [blame] | 241 | |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 242 | return iwl_mvm_send_cmd_pdu(mvm, BT_CONFIG, 0, sizeof(bt_cmd), &bt_cmd); |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 243 | } |
Emmanuel Grumbach | f421f9c | 2013-01-17 14:20:29 +0200 | [diff] [blame] | 244 | |
Emmanuel Grumbach | 1fa477c | 2014-05-20 13:54:27 +0300 | [diff] [blame] | 245 | static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id, |
| 246 | bool enable) |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 247 | { |
Emmanuel Grumbach | 455e7ac | 2014-05-22 12:48:27 +0300 | [diff] [blame] | 248 | struct iwl_bt_coex_reduced_txp_update_cmd cmd = {}; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 249 | struct iwl_mvm_sta *mvmsta; |
Emmanuel Grumbach | 455e7ac | 2014-05-22 12:48:27 +0300 | [diff] [blame] | 250 | u32 value; |
Emmanuel Grumbach | 03e304e | 2013-06-26 15:54:34 +0300 | [diff] [blame] | 251 | int ret; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 252 | |
Emmanuel Grumbach | f327b04 | 2014-01-14 08:30:32 +0200 | [diff] [blame] | 253 | mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id); |
| 254 | if (!mvmsta) |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 255 | return 0; |
| 256 | |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 257 | /* nothing to do */ |
Emmanuel Grumbach | 1fa477c | 2014-05-20 13:54:27 +0300 | [diff] [blame] | 258 | if (mvmsta->bt_reduced_txpower == enable) |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 259 | return 0; |
| 260 | |
Emmanuel Grumbach | 455e7ac | 2014-05-22 12:48:27 +0300 | [diff] [blame] | 261 | value = mvmsta->sta_id; |
Emmanuel Grumbach | 03e304e | 2013-06-26 15:54:34 +0300 | [diff] [blame] | 262 | |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 263 | if (enable) |
Emmanuel Grumbach | 455e7ac | 2014-05-22 12:48:27 +0300 | [diff] [blame] | 264 | value |= BT_REDUCED_TX_POWER_BIT; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 265 | |
| 266 | IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n", |
| 267 | enable ? "en" : "dis", sta_id); |
| 268 | |
Emmanuel Grumbach | 455e7ac | 2014-05-22 12:48:27 +0300 | [diff] [blame] | 269 | cmd.reduced_txp = cpu_to_le32(value); |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 270 | mvmsta->bt_reduced_txpower = enable; |
| 271 | |
Emmanuel Grumbach | 455e7ac | 2014-05-22 12:48:27 +0300 | [diff] [blame] | 272 | ret = iwl_mvm_send_cmd_pdu(mvm, BT_COEX_UPDATE_REDUCED_TXP, CMD_ASYNC, |
| 273 | sizeof(cmd), &cmd); |
Emmanuel Grumbach | 03e304e | 2013-06-26 15:54:34 +0300 | [diff] [blame] | 274 | |
Emmanuel Grumbach | 03e304e | 2013-06-26 15:54:34 +0300 | [diff] [blame] | 275 | return ret; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | struct iwl_bt_iterator_data { |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 279 | struct iwl_bt_coex_profile_notif *notif; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 280 | struct iwl_mvm *mvm; |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 281 | struct ieee80211_chanctx_conf *primary; |
| 282 | struct ieee80211_chanctx_conf *secondary; |
Emmanuel Grumbach | 0ee5bcd | 2014-01-15 16:57:54 +0200 | [diff] [blame] | 283 | bool primary_ll; |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 284 | }; |
| 285 | |
Emmanuel Grumbach | f6fc577 | 2013-09-08 08:57:15 +0300 | [diff] [blame] | 286 | static inline |
| 287 | void 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 Grumbach | 8286d9f | 2014-05-27 22:54:18 +0300 | [diff] [blame] | 295 | enable ? -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH : 0; |
Emmanuel Grumbach | f6fc577 | 2013-09-08 08:57:15 +0300 | [diff] [blame] | 296 | mvmvif->bf_data.bt_coex_min_thold = |
Emmanuel Grumbach | 8286d9f | 2014-05-27 22:54:18 +0300 | [diff] [blame] | 297 | enable ? -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH : 0; |
Emmanuel Grumbach | f6fc577 | 2013-09-08 08:57:15 +0300 | [diff] [blame] | 298 | } |
| 299 | |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 300 | /* must be called under rcu_read_lock */ |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 301 | static 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 Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 305 | struct iwl_bt_iterator_data *data = _data; |
| 306 | struct iwl_mvm *mvm = data->mvm; |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 307 | struct ieee80211_chanctx_conf *chanctx_conf; |
Johannes Berg | 582de30 | 2014-08-21 19:08:44 +0200 | [diff] [blame] | 308 | /* default smps_mode is AUTOMATIC - only used for client modes */ |
| 309 | enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_AUTOMATIC; |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 310 | u32 bt_activity_grading; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 311 | int ave_rssi; |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 312 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 313 | lockdep_assert_held(&mvm->mutex); |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 314 | |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 315 | switch (vif->type) { |
| 316 | case NL80211_IFTYPE_STATION: |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 317 | break; |
| 318 | case NL80211_IFTYPE_AP: |
Emmanuel Grumbach | 45bbb2c | 2014-07-07 14:38:39 +0300 | [diff] [blame] | 319 | if (!mvmvif->ap_ibss_active) |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 320 | return; |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 321 | break; |
| 322 | default: |
| 323 | return; |
| 324 | } |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 325 | |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 326 | chanctx_conf = rcu_dereference(vif->chanctx_conf); |
| 327 | |
| 328 | /* If channel context is invalid or not on 2.4GHz .. */ |
| 329 | if ((!chanctx_conf || |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 330 | chanctx_conf->def.chan->band != NL80211_BAND_2GHZ)) { |
Emmanuel Grumbach | 0f618e6 | 2014-05-20 15:48:18 +0300 | [diff] [blame] | 331 | if (vif->type == NL80211_IFTYPE_STATION) { |
Emmanuel Grumbach | 45bbb2c | 2014-07-07 14:38:39 +0300 | [diff] [blame] | 332 | /* ... relax constraints and disable rssi events */ |
| 333 | iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX, |
| 334 | smps_mode); |
Emmanuel Grumbach | 0f618e6 | 2014-05-20 15:48:18 +0300 | [diff] [blame] | 335 | iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, |
| 336 | false); |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 337 | iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0); |
Emmanuel Grumbach | 0f618e6 | 2014-05-20 15:48:18 +0300 | [diff] [blame] | 338 | } |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 339 | return; |
| 340 | } |
| 341 | |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 342 | 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 Grumbach | 45bbb2c | 2014-07-07 14:38:39 +0300 | [diff] [blame] | 346 | smps_mode = IEEE80211_SMPS_DYNAMIC; |
Emmanuel Grumbach | 4d66449 | 2014-04-30 18:09:59 +0300 | [diff] [blame] | 347 | |
Johannes Berg | 582de30 | 2014-08-21 19:08:44 +0200 | [diff] [blame] | 348 | /* relax SMPS constraints for next association */ |
Emmanuel Grumbach | 4d66449 | 2014-04-30 18:09:59 +0300 | [diff] [blame] | 349 | if (!vif->bss_conf.assoc) |
| 350 | smps_mode = IEEE80211_SMPS_AUTOMATIC; |
| 351 | |
Emmanuel Grumbach | 4cd4b50 | 2015-03-05 13:43:15 +0200 | [diff] [blame] | 352 | if (mvmvif->phy_ctxt && |
Emmanuel Grumbach | 88c5f47 | 2017-07-23 12:53:46 +0300 | [diff] [blame] | 353 | (mvm->last_bt_notif.rrc_status & BIT(mvmvif->phy_ctxt->id))) |
Emmanuel Grumbach | 4c86f93 | 2014-06-30 10:26:02 +0300 | [diff] [blame] | 354 | smps_mode = IEEE80211_SMPS_AUTOMATIC; |
| 355 | |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 356 | IWL_DEBUG_COEX(data->mvm, |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 357 | "mac %d: bt_activity_grading %d smps_req %d\n", |
| 358 | mvmvif->id, bt_activity_grading, smps_mode); |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 359 | |
Emmanuel Grumbach | 45bbb2c | 2014-07-07 14:38:39 +0300 | [diff] [blame] | 360 | if (vif->type == NL80211_IFTYPE_STATION) |
| 361 | iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX, |
| 362 | smps_mode); |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 363 | |
Emmanuel Grumbach | 0ee5bcd | 2014-01-15 16:57:54 +0200 | [diff] [blame] | 364 | /* 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 Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 372 | if (vif->type == NL80211_IFTYPE_AP) { |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 373 | if (!mvmvif->ap_ibss_active) |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 374 | return; |
| 375 | |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 376 | if (chanctx_conf == data->primary) |
| 377 | return; |
| 378 | |
Emmanuel Grumbach | 0ee5bcd | 2014-01-15 16:57:54 +0200 | [diff] [blame] | 379 | 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 Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 390 | return; |
| 391 | } |
| 392 | |
Emmanuel Grumbach | 0ee5bcd | 2014-01-15 16:57:54 +0200 | [diff] [blame] | 393 | /* |
| 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 Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 397 | 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 Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 402 | |
Emmanuel Grumbach | 4d66449 | 2014-04-30 18:09:59 +0300 | [diff] [blame] | 403 | /* |
| 404 | * don't reduce the Tx power if one of these is true: |
| 405 | * we are in LOOSE |
| 406 | * single share antenna product |
Emmanuel Grumbach | c934bce | 2016-06-20 09:40:40 +0300 | [diff] [blame] | 407 | * BT is inactive |
| 408 | * we are not associated |
Emmanuel Grumbach | 4d66449 | 2014-04-30 18:09:59 +0300 | [diff] [blame] | 409 | */ |
Emmanuel Grumbach | 3914991 | 2013-07-14 13:40:21 +0300 | [diff] [blame] | 410 | if (iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT || |
Emmanuel Grumbach | 4d66449 | 2014-04-30 18:09:59 +0300 | [diff] [blame] | 411 | mvm->cfg->bt_shared_single_ant || !vif->bss_conf.assoc || |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 412 | le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF) { |
Emmanuel Grumbach | 0f618e6 | 2014-05-20 15:48:18 +0300 | [diff] [blame] | 413 | iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false); |
Emmanuel Grumbach | f6fc577 | 2013-09-08 08:57:15 +0300 | [diff] [blame] | 414 | iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0); |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 415 | return; |
Emmanuel Grumbach | 3914991 | 2013-07-14 13:40:21 +0300 | [diff] [blame] | 416 | } |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 417 | |
Andrei Otcheretianski | 911222b | 2013-07-21 17:37:19 +0300 | [diff] [blame] | 418 | /* try to get the avg rssi from fw */ |
| 419 | ave_rssi = mvmvif->bf_data.ave_beacon_signal; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 420 | |
| 421 | /* if the RSSI isn't valid, fake it is very low */ |
| 422 | if (!ave_rssi) |
| 423 | ave_rssi = -100; |
Emmanuel Grumbach | 8286d9f | 2014-05-27 22:54:18 +0300 | [diff] [blame] | 424 | if (ave_rssi > -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH) { |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 425 | 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 Grumbach | 8286d9f | 2014-05-27 22:54:18 +0300 | [diff] [blame] | 427 | } else if (ave_rssi < -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH) { |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 428 | 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 Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /* Begin to monitor the RSSI: it may influence the reduced Tx power */ |
Emmanuel Grumbach | f6fc577 | 2013-09-08 08:57:15 +0300 | [diff] [blame] | 433 | iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, true, ave_rssi); |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 434 | } |
| 435 | |
Emmanuel Grumbach | d37cac9 | 2013-03-29 14:56:19 +0300 | [diff] [blame] | 436 | static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm) |
Emmanuel Grumbach | f421f9c | 2013-01-17 14:20:29 +0200 | [diff] [blame] | 437 | { |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 438 | struct iwl_bt_iterator_data data = { |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 439 | .mvm = mvm, |
Emmanuel Grumbach | d37cac9 | 2013-03-29 14:56:19 +0300 | [diff] [blame] | 440 | .notif = &mvm->last_bt_notif, |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 441 | }; |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 442 | struct iwl_bt_coex_ci_cmd cmd = {}; |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 443 | u8 ci_bw_idx; |
Emmanuel Grumbach | f421f9c | 2013-01-17 14:20:29 +0200 | [diff] [blame] | 444 | |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 445 | /* Ignore updates if we are in force mode */ |
| 446 | if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) |
| 447 | return; |
| 448 | |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 449 | rcu_read_lock(); |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 450 | ieee80211_iterate_active_interfaces_atomic( |
| 451 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 452 | iwl_mvm_bt_notif_iterator, &data); |
| 453 | |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 454 | 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 Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 463 | } else { |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 464 | 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 Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 473 | cmd.primary_ch_phy_id = |
| 474 | cpu_to_le32(*((u16 *)data.primary->drv_priv)); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 475 | } |
| 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 Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 486 | } else { |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 487 | 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 Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 496 | cmd.secondary_ch_phy_id = |
| 497 | cpu_to_le32(*((u16 *)data.secondary->drv_priv)); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 498 | } |
| 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 Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 504 | if (iwl_mvm_send_cmd_pdu(mvm, BT_COEX_CI, 0, |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 505 | sizeof(cmd), &cmd)) |
Johannes Berg | 3c6acb6 | 2014-05-07 11:47:53 +0200 | [diff] [blame] | 506 | IWL_ERR(mvm, "Failed to send BT_CI cmd\n"); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 507 | memcpy(&mvm->last_bt_ci_cmd, &cmd, sizeof(cmd)); |
| 508 | } |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 509 | } |
| 510 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 511 | void iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm, |
| 512 | struct iwl_rx_cmd_buffer *rxb) |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 513 | { |
| 514 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Emmanuel Grumbach | df878f3 | 2014-04-02 12:23:09 +0300 | [diff] [blame] | 515 | struct iwl_bt_coex_profile_notif *notif = (void *)pkt->data; |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 516 | |
Emmanuel Grumbach | fbfe378 | 2017-07-23 13:59:47 +0300 | [diff] [blame] | 517 | if (!iwl_mvm_has_new_ats_coex_api(mvm)) { |
| 518 | struct iwl_bt_coex_profile_notif_v4 *v4 = (void *)pkt->data; |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 519 | |
Emmanuel Grumbach | fbfe378 | 2017-07-23 13:59:47 +0300 | [diff] [blame] | 520 | 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 Grumbach | d37cac9 | 2013-03-29 14:56:19 +0300 | [diff] [blame] | 547 | |
| 548 | iwl_mvm_bt_coex_notif_handle(mvm); |
Emmanuel Grumbach | f421f9c | 2013-01-17 14:20:29 +0200 | [diff] [blame] | 549 | } |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 550 | |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 551 | void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
Emmanuel Grumbach | a818292 | 2015-03-16 23:23:34 +0200 | [diff] [blame] | 552 | enum ieee80211_rssi_event_data rssi_event) |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 553 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 554 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 555 | int ret; |
| 556 | |
Johannes Berg | 3dd1cd2 | 2013-10-02 12:05:24 +0200 | [diff] [blame] | 557 | lockdep_assert_held(&mvm->mutex); |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 558 | |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 559 | /* Ignore updates if we are in force mode */ |
| 560 | if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) |
| 561 | return; |
| 562 | |
Emmanuel Grumbach | 1e92919 | 2014-03-04 10:28:23 +0200 | [diff] [blame] | 563 | /* |
| 564 | * Rssi update while not associated - can happen since the statistics |
| 565 | * are handled asynchronously |
| 566 | */ |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 567 | if (mvmvif->ap_sta_id == IWL_MVM_INVALID_STA) |
Johannes Berg | 3dd1cd2 | 2013-10-02 12:05:24 +0200 | [diff] [blame] | 568 | return; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 569 | |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 570 | /* No BT - reports should be disabled */ |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 571 | if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF) |
Johannes Berg | 3dd1cd2 | 2013-10-02 12:05:24 +0200 | [diff] [blame] | 572 | return; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 573 | |
| 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 Grumbach | 3914991 | 2013-07-14 13:40:21 +0300 | [diff] [blame] | 581 | if (rssi_event == RSSI_EVENT_LOW || mvm->cfg->bt_shared_single_ant || |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 582 | iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT) |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 583 | 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 Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 590 | } |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 591 | |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 592 | #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000) |
| 593 | #define LINK_QUAL_AGG_TIME_LIMIT_BT_ACT (1200) |
| 594 | |
Emmanuel Grumbach | 5b7ff61 | 2014-03-11 19:27:45 +0200 | [diff] [blame] | 595 | u16 iwl_mvm_coex_agg_time_limit(struct iwl_mvm *mvm, |
| 596 | struct ieee80211_sta *sta) |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 597 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 598 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | 4c86f93 | 2014-06-30 10:26:02 +0300 | [diff] [blame] | 599 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif); |
| 600 | struct iwl_mvm_phy_ctxt *phy_ctxt = mvmvif->phy_ctxt; |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 601 | enum iwl_bt_coex_lut_type lut_type; |
| 602 | |
Emmanuel Grumbach | 88c5f47 | 2017-07-23 12:53:46 +0300 | [diff] [blame] | 603 | if (mvm->last_bt_notif.ttc_status & BIT(phy_ctxt->id)) |
Emmanuel Grumbach | 4c86f93 | 2014-06-30 10:26:02 +0300 | [diff] [blame] | 604 | return LINK_QUAL_AGG_TIME_LIMIT_DEF; |
| 605 | |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 606 | if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) < |
Emmanuel Grumbach | c211935 | 2013-11-13 22:00:30 +0200 | [diff] [blame] | 607 | BT_HIGH_TRAFFIC) |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 608 | return LINK_QUAL_AGG_TIME_LIMIT_DEF; |
Emmanuel Grumbach | 35fbf5d | 2014-06-02 16:18:42 +0300 | [diff] [blame] | 609 | |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 610 | lut_type = iwl_get_coex_type(mvm, mvmsta->vif); |
| 611 | |
Emmanuel Grumbach | 7fa4fa0 | 2014-05-25 13:58:31 +0300 | [diff] [blame] | 612 | if (lut_type == BT_COEX_LOOSE_LUT || lut_type == BT_COEX_INVALID_LUT) |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 613 | 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 Grumbach | ffa6c70 | 2013-10-06 11:41:20 +0300 | [diff] [blame] | 619 | bool iwl_mvm_bt_coex_is_mimo_allowed(struct iwl_mvm *mvm, |
| 620 | struct ieee80211_sta *sta) |
| 621 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 622 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | 4c86f93 | 2014-06-30 10:26:02 +0300 | [diff] [blame] | 623 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif); |
| 624 | struct iwl_mvm_phy_ctxt *phy_ctxt = mvmvif->phy_ctxt; |
Emmanuel Grumbach | 7fa4fa0 | 2014-05-25 13:58:31 +0300 | [diff] [blame] | 625 | enum iwl_bt_coex_lut_type lut_type; |
Emmanuel Grumbach | ffa6c70 | 2013-10-06 11:41:20 +0300 | [diff] [blame] | 626 | |
Emmanuel Grumbach | 88c5f47 | 2017-07-23 12:53:46 +0300 | [diff] [blame] | 627 | if (mvm->last_bt_notif.ttc_status & BIT(phy_ctxt->id)) |
Emmanuel Grumbach | 35fbf5d | 2014-06-02 16:18:42 +0300 | [diff] [blame] | 628 | return true; |
| 629 | |
Emmanuel Grumbach | ffa6c70 | 2013-10-06 11:41:20 +0300 | [diff] [blame] | 630 | if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) < |
| 631 | BT_HIGH_TRAFFIC) |
| 632 | return true; |
| 633 | |
| 634 | /* |
Emmanuel Grumbach | 7fa4fa0 | 2014-05-25 13:58:31 +0300 | [diff] [blame] | 635 | * 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 Grumbach | ffa6c70 | 2013-10-06 11:41:20 +0300 | [diff] [blame] | 640 | */ |
Emmanuel Grumbach | 7fa4fa0 | 2014-05-25 13:58:31 +0300 | [diff] [blame] | 641 | lut_type = iwl_get_coex_type(mvm, mvmsta->vif); |
| 642 | return lut_type != BT_COEX_LOOSE_LUT; |
Emmanuel Grumbach | ffa6c70 | 2013-10-06 11:41:20 +0300 | [diff] [blame] | 643 | } |
| 644 | |
Emmanuel Grumbach | 219fb66 | 2014-10-30 11:59:40 +0200 | [diff] [blame] | 645 | bool 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 Grumbach | 219fb66 | 2014-10-30 11:59:40 +0200 | [diff] [blame] | 654 | return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) < |
| 655 | BT_HIGH_TRAFFIC; |
| 656 | } |
| 657 | |
Emmanuel Grumbach | 34c8b24 | 2014-05-28 21:53:39 +0300 | [diff] [blame] | 658 | bool iwl_mvm_bt_coex_is_shared_ant_avail(struct iwl_mvm *mvm) |
| 659 | { |
Emmanuel Grumbach | bbab758 | 2014-09-10 11:00:16 +0300 | [diff] [blame] | 660 | /* there is no other antenna, shared antenna is always available */ |
| 661 | if (mvm->cfg->bt_shared_single_ant) |
| 662 | return true; |
| 663 | |
Emmanuel Grumbach | cb97e41 | 2015-05-16 22:47:56 +0300 | [diff] [blame] | 664 | return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) < BT_HIGH_TRAFFIC; |
Emmanuel Grumbach | 34c8b24 | 2014-05-28 21:53:39 +0300 | [diff] [blame] | 665 | } |
| 666 | |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 667 | bool iwl_mvm_bt_coex_is_tpc_allowed(struct iwl_mvm *mvm, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 668 | enum nl80211_band band) |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 669 | { |
| 670 | u32 bt_activity = le32_to_cpu(mvm->last_bt_notif.bt_activity_grading); |
| 671 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 672 | if (band != NL80211_BAND_2GHZ) |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 673 | return false; |
| 674 | |
| 675 | return bt_activity >= BT_LOW_TRAFFIC; |
| 676 | } |
| 677 | |
Emmanuel Grumbach | ee7bea5 | 2014-03-06 10:30:49 +0200 | [diff] [blame] | 678 | u8 iwl_mvm_bt_coex_tx_prio(struct iwl_mvm *mvm, struct ieee80211_hdr *hdr, |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 679 | struct ieee80211_tx_info *info, u8 ac) |
Emmanuel Grumbach | ee7bea5 | 2014-03-06 10:30:49 +0200 | [diff] [blame] | 680 | { |
| 681 | __le16 fc = hdr->frame_control; |
Avri Altman | 6e36510 | 2015-11-02 14:16:07 +0200 | [diff] [blame] | 682 | bool mplut_enabled = iwl_mvm_is_mplut_supported(mvm); |
Emmanuel Grumbach | ee7bea5 | 2014-03-06 10:30:49 +0200 | [diff] [blame] | 683 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 684 | if (info->band != NL80211_BAND_2GHZ) |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 685 | return 0; |
| 686 | |
Emmanuel Grumbach | cdb0056 | 2014-03-16 21:55:43 +0200 | [diff] [blame] | 687 | if (unlikely(mvm->bt_tx_prio)) |
| 688 | return mvm->bt_tx_prio - 1; |
| 689 | |
Avri Altman | 6e36510 | 2015-11-02 14:16:07 +0200 | [diff] [blame] | 690 | 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 Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 710 | return 3; |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 711 | } |
Emmanuel Grumbach | ee7bea5 | 2014-03-06 10:30:49 +0200 | [diff] [blame] | 712 | |
| 713 | return 0; |
| 714 | } |
| 715 | |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame] | 716 | void iwl_mvm_bt_coex_vif_change(struct iwl_mvm *mvm) |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 717 | { |
Emmanuel Grumbach | d37cac9 | 2013-03-29 14:56:19 +0300 | [diff] [blame] | 718 | iwl_mvm_bt_coex_notif_handle(mvm); |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 719 | } |