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 | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of version 2 of the GNU General Public License as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 23 | * USA |
| 24 | * |
| 25 | * The full GNU General Public License is included in this distribution |
| 26 | * in the file called COPYING. |
| 27 | * |
| 28 | * Contact Information: |
Emmanuel Grumbach | cb2f827 | 2015-11-17 15:39:56 +0200 | [diff] [blame] | 29 | * Intel Linux Wireless <linuxwifi@intel.com> |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 30 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 31 | * |
| 32 | * BSD LICENSE |
| 33 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 34 | * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved. |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 35 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 36 | * All rights reserved. |
| 37 | * |
| 38 | * Redistribution and use in source and binary forms, with or without |
| 39 | * modification, are permitted provided that the following conditions |
| 40 | * are met: |
| 41 | * |
| 42 | * * Redistributions of source code must retain the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer. |
| 44 | * * Redistributions in binary form must reproduce the above copyright |
| 45 | * notice, this list of conditions and the following disclaimer in |
| 46 | * the documentation and/or other materials provided with the |
| 47 | * distribution. |
| 48 | * * Neither the name Intel Corporation nor the names of its |
| 49 | * contributors may be used to endorse or promote products derived |
| 50 | * from this software without specific prior written permission. |
| 51 | * |
| 52 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 53 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 54 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 55 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 56 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 57 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 58 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 59 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 60 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 61 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 62 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 63 | * |
| 64 | *****************************************************************************/ |
| 65 | |
Emmanuel Grumbach | ee7bea5 | 2014-03-06 10:30:49 +0200 | [diff] [blame] | 66 | #include <linux/ieee80211.h> |
| 67 | #include <linux/etherdevice.h> |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 68 | #include <net/mac80211.h> |
| 69 | |
Emmanuel Grumbach | 5b7ff61 | 2014-03-11 19:27:45 +0200 | [diff] [blame] | 70 | #include "fw-api-coex.h" |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 71 | #include "iwl-modparams.h" |
| 72 | #include "mvm.h" |
Emmanuel Grumbach | f421f9c | 2013-01-17 14:20:29 +0200 | [diff] [blame] | 73 | #include "iwl-debug.h" |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 74 | |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 75 | /* 20MHz / 40MHz below / 40Mhz above*/ |
| 76 | static const __le64 iwl_ci_mask[][3] = { |
| 77 | /* dummy entry for channel 0 */ |
| 78 | {cpu_to_le64(0), cpu_to_le64(0), cpu_to_le64(0)}, |
| 79 | { |
| 80 | cpu_to_le64(0x0000001FFFULL), |
| 81 | cpu_to_le64(0x0ULL), |
| 82 | cpu_to_le64(0x00007FFFFFULL), |
| 83 | }, |
| 84 | { |
| 85 | cpu_to_le64(0x000000FFFFULL), |
| 86 | cpu_to_le64(0x0ULL), |
| 87 | cpu_to_le64(0x0003FFFFFFULL), |
| 88 | }, |
| 89 | { |
| 90 | cpu_to_le64(0x000003FFFCULL), |
| 91 | cpu_to_le64(0x0ULL), |
| 92 | cpu_to_le64(0x000FFFFFFCULL), |
| 93 | }, |
| 94 | { |
| 95 | cpu_to_le64(0x00001FFFE0ULL), |
| 96 | cpu_to_le64(0x0ULL), |
| 97 | cpu_to_le64(0x007FFFFFE0ULL), |
| 98 | }, |
| 99 | { |
| 100 | cpu_to_le64(0x00007FFF80ULL), |
| 101 | cpu_to_le64(0x00007FFFFFULL), |
| 102 | cpu_to_le64(0x01FFFFFF80ULL), |
| 103 | }, |
| 104 | { |
| 105 | cpu_to_le64(0x0003FFFC00ULL), |
| 106 | cpu_to_le64(0x0003FFFFFFULL), |
| 107 | cpu_to_le64(0x0FFFFFFC00ULL), |
| 108 | }, |
| 109 | { |
| 110 | cpu_to_le64(0x000FFFF000ULL), |
| 111 | cpu_to_le64(0x000FFFFFFCULL), |
| 112 | cpu_to_le64(0x3FFFFFF000ULL), |
| 113 | }, |
| 114 | { |
| 115 | cpu_to_le64(0x007FFF8000ULL), |
| 116 | cpu_to_le64(0x007FFFFFE0ULL), |
| 117 | cpu_to_le64(0xFFFFFF8000ULL), |
| 118 | }, |
| 119 | { |
| 120 | cpu_to_le64(0x01FFFE0000ULL), |
| 121 | cpu_to_le64(0x01FFFFFF80ULL), |
| 122 | cpu_to_le64(0xFFFFFE0000ULL), |
| 123 | }, |
| 124 | { |
| 125 | cpu_to_le64(0x0FFFF00000ULL), |
| 126 | cpu_to_le64(0x0FFFFFFC00ULL), |
| 127 | cpu_to_le64(0x0ULL), |
| 128 | }, |
| 129 | { |
| 130 | cpu_to_le64(0x3FFFC00000ULL), |
| 131 | cpu_to_le64(0x3FFFFFF000ULL), |
| 132 | cpu_to_le64(0x0) |
| 133 | }, |
| 134 | { |
| 135 | cpu_to_le64(0xFFFE000000ULL), |
| 136 | cpu_to_le64(0xFFFFFF8000ULL), |
| 137 | cpu_to_le64(0x0) |
| 138 | }, |
| 139 | { |
| 140 | cpu_to_le64(0xFFF8000000ULL), |
| 141 | cpu_to_le64(0xFFFFFE0000ULL), |
| 142 | cpu_to_le64(0x0) |
| 143 | }, |
| 144 | { |
Emmanuel Grumbach | ad17b1d | 2016-06-22 10:51:31 +0300 | [diff] [blame] | 145 | cpu_to_le64(0xFE00000000ULL), |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 146 | cpu_to_le64(0x0ULL), |
Emmanuel Grumbach | d2ccc90 | 2013-12-24 10:55:24 +0200 | [diff] [blame] | 147 | cpu_to_le64(0x0ULL) |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 148 | }, |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 149 | }; |
| 150 | |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 151 | struct corunning_block_luts { |
| 152 | u8 range; |
| 153 | __le32 lut20[BT_COEX_CORUN_LUT_SIZE]; |
| 154 | }; |
| 155 | |
| 156 | /* |
| 157 | * Ranges for the antenna coupling calibration / co-running block LUT: |
| 158 | * LUT0: [ 0, 12[ |
| 159 | * LUT1: [12, 20[ |
| 160 | * LUT2: [20, 21[ |
| 161 | * LUT3: [21, 23[ |
| 162 | * LUT4: [23, 27[ |
| 163 | * LUT5: [27, 30[ |
| 164 | * LUT6: [30, 32[ |
| 165 | * LUT7: [32, 33[ |
| 166 | * LUT8: [33, - [ |
| 167 | */ |
| 168 | static const struct corunning_block_luts antenna_coupling_ranges[] = { |
| 169 | { |
| 170 | .range = 0, |
| 171 | .lut20 = { |
| 172 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 173 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 174 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 175 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 176 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 177 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 178 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 179 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 180 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 181 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 182 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 183 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 184 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 185 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 186 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 187 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 188 | }, |
| 189 | }, |
| 190 | { |
| 191 | .range = 12, |
| 192 | .lut20 = { |
Emmanuel Grumbach | e583b50 | 2015-01-22 15:14:38 +0200 | [diff] [blame] | 193 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 194 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 195 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 196 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 197 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 198 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 199 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 200 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 201 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 202 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 203 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 204 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 205 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 206 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 207 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 208 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 209 | }, |
| 210 | }, |
| 211 | { |
| 212 | .range = 20, |
| 213 | .lut20 = { |
Emmanuel Grumbach | e583b50 | 2015-01-22 15:14:38 +0200 | [diff] [blame] | 214 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 215 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 216 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 217 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 218 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 219 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 220 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 221 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 222 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 223 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 224 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 225 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 226 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 227 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 228 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 229 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 230 | }, |
| 231 | }, |
| 232 | { |
| 233 | .range = 21, |
| 234 | .lut20 = { |
Emmanuel Grumbach | e583b50 | 2015-01-22 15:14:38 +0200 | [diff] [blame] | 235 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 236 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 237 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 238 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 239 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 240 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 241 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 242 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 243 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 244 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 245 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 246 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 247 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 248 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 249 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 250 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 251 | }, |
| 252 | }, |
| 253 | { |
| 254 | .range = 23, |
| 255 | .lut20 = { |
Emmanuel Grumbach | e583b50 | 2015-01-22 15:14:38 +0200 | [diff] [blame] | 256 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 257 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 258 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 259 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 260 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 261 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 262 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 263 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 264 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 265 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 266 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 267 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 268 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 269 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 270 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 271 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 272 | }, |
| 273 | }, |
| 274 | { |
| 275 | .range = 27, |
| 276 | .lut20 = { |
Emmanuel Grumbach | e583b50 | 2015-01-22 15:14:38 +0200 | [diff] [blame] | 277 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 278 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 279 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 280 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 281 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 282 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 283 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 284 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 285 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 286 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 287 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 288 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 289 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 290 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 291 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 292 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 293 | }, |
| 294 | }, |
| 295 | { |
| 296 | .range = 30, |
| 297 | .lut20 = { |
Emmanuel Grumbach | e583b50 | 2015-01-22 15:14:38 +0200 | [diff] [blame] | 298 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 299 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 300 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 301 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 302 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 303 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 304 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 305 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 306 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 307 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 308 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 309 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 310 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 311 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 312 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 313 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 314 | }, |
| 315 | }, |
| 316 | { |
| 317 | .range = 32, |
| 318 | .lut20 = { |
Emmanuel Grumbach | e583b50 | 2015-01-22 15:14:38 +0200 | [diff] [blame] | 319 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 320 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 321 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 322 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 323 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 324 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 325 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 326 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 327 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 328 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 329 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 330 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 331 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 332 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 333 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 334 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 335 | }, |
| 336 | }, |
| 337 | { |
| 338 | .range = 33, |
| 339 | .lut20 = { |
Emmanuel Grumbach | e583b50 | 2015-01-22 15:14:38 +0200 | [diff] [blame] | 340 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 341 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 342 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 343 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 344 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 345 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 346 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 347 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 348 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 349 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 350 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 351 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 352 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 353 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 354 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 355 | cpu_to_le32(0x00000000), cpu_to_le32(0x00000000), |
| 356 | }, |
| 357 | }, |
| 358 | }; |
| 359 | |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 360 | static enum iwl_bt_coex_lut_type |
| 361 | iwl_get_coex_type(struct iwl_mvm *mvm, const struct ieee80211_vif *vif) |
| 362 | { |
| 363 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 364 | enum iwl_bt_coex_lut_type ret; |
| 365 | u16 phy_ctx_id; |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 366 | u32 primary_ch_phy_id, secondary_ch_phy_id; |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 367 | |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 368 | /* |
| 369 | * Checking that we hold mvm->mutex is a good idea, but the rate |
| 370 | * control can't acquire the mutex since it runs in Tx path. |
| 371 | * So this is racy in that case, but in the worst case, the AMPDU |
| 372 | * size limit will be wrong for a short time which is not a big |
| 373 | * issue. |
| 374 | */ |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 375 | |
| 376 | rcu_read_lock(); |
| 377 | |
| 378 | chanctx_conf = rcu_dereference(vif->chanctx_conf); |
| 379 | |
| 380 | if (!chanctx_conf || |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 381 | chanctx_conf->def.chan->band != NL80211_BAND_2GHZ) { |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 382 | rcu_read_unlock(); |
Emmanuel Grumbach | 7fa4fa0 | 2014-05-25 13:58:31 +0300 | [diff] [blame] | 383 | return BT_COEX_INVALID_LUT; |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | ret = BT_COEX_TX_DIS_LUT; |
| 387 | |
Emmanuel Grumbach | 3914991 | 2013-07-14 13:40:21 +0300 | [diff] [blame] | 388 | if (mvm->cfg->bt_shared_single_ant) { |
| 389 | rcu_read_unlock(); |
| 390 | return ret; |
| 391 | } |
| 392 | |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 393 | phy_ctx_id = *((u16 *)chanctx_conf->drv_priv); |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 394 | primary_ch_phy_id = le32_to_cpu(mvm->last_bt_ci_cmd.primary_ch_phy_id); |
| 395 | secondary_ch_phy_id = |
| 396 | le32_to_cpu(mvm->last_bt_ci_cmd.secondary_ch_phy_id); |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 397 | |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 398 | if (primary_ch_phy_id == phy_ctx_id) |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 399 | ret = le32_to_cpu(mvm->last_bt_notif.primary_ch_lut); |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 400 | else if (secondary_ch_phy_id == phy_ctx_id) |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 401 | ret = le32_to_cpu(mvm->last_bt_notif.secondary_ch_lut); |
| 402 | /* else - default = TX TX disallowed */ |
| 403 | |
| 404 | rcu_read_unlock(); |
| 405 | |
| 406 | return ret; |
| 407 | } |
| 408 | |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 409 | int iwl_send_bt_init_conf(struct iwl_mvm *mvm) |
| 410 | { |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 411 | struct iwl_bt_coex_cmd bt_cmd = {}; |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 412 | u32 mode; |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 413 | |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 414 | lockdep_assert_held(&mvm->mutex); |
| 415 | |
| 416 | if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) { |
| 417 | switch (mvm->bt_force_ant_mode) { |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 418 | case BT_FORCE_ANT_BT: |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 419 | mode = BT_COEX_BT; |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 420 | break; |
| 421 | case BT_FORCE_ANT_WIFI: |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 422 | mode = BT_COEX_WIFI; |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 423 | break; |
| 424 | default: |
| 425 | WARN_ON(1); |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 426 | mode = 0; |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 427 | } |
| 428 | |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 429 | bt_cmd.mode = cpu_to_le32(mode); |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 430 | goto send_cmd; |
| 431 | } |
| 432 | |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 433 | 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] | 434 | bt_cmd.mode = cpu_to_le32(mode); |
Emmanuel Grumbach | 03e304e | 2013-06-26 15:54:34 +0300 | [diff] [blame] | 435 | |
Emmanuel Grumbach | 741e703 | 2014-01-27 12:12:50 +0200 | [diff] [blame] | 436 | if (IWL_MVM_BT_COEX_SYNC2SCO) |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 437 | bt_cmd.enabled_modules |= |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 438 | cpu_to_le32(BT_COEX_SYNC2SCO_ENABLED); |
Emmanuel Grumbach | 741e703 | 2014-01-27 12:12:50 +0200 | [diff] [blame] | 439 | |
Emmanuel Grumbach | 0522588 | 2015-02-12 12:33:09 +0200 | [diff] [blame] | 440 | if (iwl_mvm_bt_is_plcr_supported(mvm)) |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 441 | bt_cmd.enabled_modules |= cpu_to_le32(BT_COEX_CORUN_ENABLED); |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 442 | |
Avri Altman | e7c2e1f | 2015-10-29 16:50:57 +0200 | [diff] [blame] | 443 | if (iwl_mvm_is_mplut_supported(mvm)) |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 444 | bt_cmd.enabled_modules |= cpu_to_le32(BT_COEX_MPLUT_ENABLED); |
Emmanuel Grumbach | cdb0056 | 2014-03-16 21:55:43 +0200 | [diff] [blame] | 445 | |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 446 | bt_cmd.enabled_modules |= cpu_to_le32(BT_COEX_HIGH_BAND_RET); |
Emmanuel Grumbach | 261c0ec | 2014-06-11 15:37:25 +0300 | [diff] [blame] | 447 | |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 448 | send_cmd: |
Emmanuel Grumbach | 03e304e | 2013-06-26 15:54:34 +0300 | [diff] [blame] | 449 | memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 450 | 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] | 451 | |
Emmanuel Grumbach | 741c4cf | 2015-05-11 09:05:25 +0300 | [diff] [blame] | 452 | 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] | 453 | } |
Emmanuel Grumbach | f421f9c | 2013-01-17 14:20:29 +0200 | [diff] [blame] | 454 | |
Emmanuel Grumbach | 1fa477c | 2014-05-20 13:54:27 +0300 | [diff] [blame] | 455 | static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id, |
| 456 | bool enable) |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 457 | { |
Emmanuel Grumbach | 455e7ac | 2014-05-22 12:48:27 +0300 | [diff] [blame] | 458 | struct iwl_bt_coex_reduced_txp_update_cmd cmd = {}; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 459 | struct iwl_mvm_sta *mvmsta; |
Emmanuel Grumbach | 455e7ac | 2014-05-22 12:48:27 +0300 | [diff] [blame] | 460 | u32 value; |
Emmanuel Grumbach | 03e304e | 2013-06-26 15:54:34 +0300 | [diff] [blame] | 461 | int ret; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 462 | |
Emmanuel Grumbach | f327b04 | 2014-01-14 08:30:32 +0200 | [diff] [blame] | 463 | mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id); |
| 464 | if (!mvmsta) |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 465 | return 0; |
| 466 | |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 467 | /* nothing to do */ |
Emmanuel Grumbach | 1fa477c | 2014-05-20 13:54:27 +0300 | [diff] [blame] | 468 | if (mvmsta->bt_reduced_txpower == enable) |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 469 | return 0; |
| 470 | |
Emmanuel Grumbach | 455e7ac | 2014-05-22 12:48:27 +0300 | [diff] [blame] | 471 | value = mvmsta->sta_id; |
Emmanuel Grumbach | 03e304e | 2013-06-26 15:54:34 +0300 | [diff] [blame] | 472 | |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 473 | if (enable) |
Emmanuel Grumbach | 455e7ac | 2014-05-22 12:48:27 +0300 | [diff] [blame] | 474 | value |= BT_REDUCED_TX_POWER_BIT; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 475 | |
| 476 | IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n", |
| 477 | enable ? "en" : "dis", sta_id); |
| 478 | |
Emmanuel Grumbach | 455e7ac | 2014-05-22 12:48:27 +0300 | [diff] [blame] | 479 | cmd.reduced_txp = cpu_to_le32(value); |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 480 | mvmsta->bt_reduced_txpower = enable; |
| 481 | |
Emmanuel Grumbach | 455e7ac | 2014-05-22 12:48:27 +0300 | [diff] [blame] | 482 | ret = iwl_mvm_send_cmd_pdu(mvm, BT_COEX_UPDATE_REDUCED_TXP, CMD_ASYNC, |
| 483 | sizeof(cmd), &cmd); |
Emmanuel Grumbach | 03e304e | 2013-06-26 15:54:34 +0300 | [diff] [blame] | 484 | |
Emmanuel Grumbach | 03e304e | 2013-06-26 15:54:34 +0300 | [diff] [blame] | 485 | return ret; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | struct iwl_bt_iterator_data { |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 489 | struct iwl_bt_coex_profile_notif *notif; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 490 | struct iwl_mvm *mvm; |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 491 | struct ieee80211_chanctx_conf *primary; |
| 492 | struct ieee80211_chanctx_conf *secondary; |
Emmanuel Grumbach | 0ee5bcd | 2014-01-15 16:57:54 +0200 | [diff] [blame] | 493 | bool primary_ll; |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 494 | }; |
| 495 | |
Emmanuel Grumbach | f6fc577 | 2013-09-08 08:57:15 +0300 | [diff] [blame] | 496 | static inline |
| 497 | void iwl_mvm_bt_coex_enable_rssi_event(struct iwl_mvm *mvm, |
| 498 | struct ieee80211_vif *vif, |
| 499 | bool enable, int rssi) |
| 500 | { |
| 501 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 502 | |
| 503 | mvmvif->bf_data.last_bt_coex_event = rssi; |
| 504 | mvmvif->bf_data.bt_coex_max_thold = |
Emmanuel Grumbach | 8286d9f | 2014-05-27 22:54:18 +0300 | [diff] [blame] | 505 | enable ? -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH : 0; |
Emmanuel Grumbach | f6fc577 | 2013-09-08 08:57:15 +0300 | [diff] [blame] | 506 | mvmvif->bf_data.bt_coex_min_thold = |
Emmanuel Grumbach | 8286d9f | 2014-05-27 22:54:18 +0300 | [diff] [blame] | 507 | enable ? -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH : 0; |
Emmanuel Grumbach | f6fc577 | 2013-09-08 08:57:15 +0300 | [diff] [blame] | 508 | } |
| 509 | |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 510 | /* must be called under rcu_read_lock */ |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 511 | static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac, |
| 512 | struct ieee80211_vif *vif) |
| 513 | { |
| 514 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 515 | struct iwl_bt_iterator_data *data = _data; |
| 516 | struct iwl_mvm *mvm = data->mvm; |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 517 | struct ieee80211_chanctx_conf *chanctx_conf; |
Johannes Berg | 582de30 | 2014-08-21 19:08:44 +0200 | [diff] [blame] | 518 | /* default smps_mode is AUTOMATIC - only used for client modes */ |
| 519 | enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_AUTOMATIC; |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 520 | u32 bt_activity_grading; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 521 | int ave_rssi; |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 522 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 523 | lockdep_assert_held(&mvm->mutex); |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 524 | |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 525 | switch (vif->type) { |
| 526 | case NL80211_IFTYPE_STATION: |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 527 | break; |
| 528 | case NL80211_IFTYPE_AP: |
Emmanuel Grumbach | 45bbb2c | 2014-07-07 14:38:39 +0300 | [diff] [blame] | 529 | if (!mvmvif->ap_ibss_active) |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 530 | return; |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 531 | break; |
| 532 | default: |
| 533 | return; |
| 534 | } |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 535 | |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 536 | chanctx_conf = rcu_dereference(vif->chanctx_conf); |
| 537 | |
| 538 | /* If channel context is invalid or not on 2.4GHz .. */ |
| 539 | if ((!chanctx_conf || |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 540 | chanctx_conf->def.chan->band != NL80211_BAND_2GHZ)) { |
Emmanuel Grumbach | 0f618e6 | 2014-05-20 15:48:18 +0300 | [diff] [blame] | 541 | if (vif->type == NL80211_IFTYPE_STATION) { |
Emmanuel Grumbach | 45bbb2c | 2014-07-07 14:38:39 +0300 | [diff] [blame] | 542 | /* ... relax constraints and disable rssi events */ |
| 543 | iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX, |
| 544 | smps_mode); |
Emmanuel Grumbach | 0f618e6 | 2014-05-20 15:48:18 +0300 | [diff] [blame] | 545 | iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, |
| 546 | false); |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 547 | iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0); |
Emmanuel Grumbach | 0f618e6 | 2014-05-20 15:48:18 +0300 | [diff] [blame] | 548 | } |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 549 | return; |
| 550 | } |
| 551 | |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 552 | bt_activity_grading = le32_to_cpu(data->notif->bt_activity_grading); |
| 553 | if (bt_activity_grading >= BT_HIGH_TRAFFIC) |
| 554 | smps_mode = IEEE80211_SMPS_STATIC; |
| 555 | else if (bt_activity_grading >= BT_LOW_TRAFFIC) |
Emmanuel Grumbach | 45bbb2c | 2014-07-07 14:38:39 +0300 | [diff] [blame] | 556 | smps_mode = IEEE80211_SMPS_DYNAMIC; |
Emmanuel Grumbach | 4d66449 | 2014-04-30 18:09:59 +0300 | [diff] [blame] | 557 | |
Johannes Berg | 582de30 | 2014-08-21 19:08:44 +0200 | [diff] [blame] | 558 | /* relax SMPS constraints for next association */ |
Emmanuel Grumbach | 4d66449 | 2014-04-30 18:09:59 +0300 | [diff] [blame] | 559 | if (!vif->bss_conf.assoc) |
| 560 | smps_mode = IEEE80211_SMPS_AUTOMATIC; |
| 561 | |
Emmanuel Grumbach | 4cd4b50 | 2015-03-05 13:43:15 +0200 | [diff] [blame] | 562 | if (mvmvif->phy_ctxt && |
| 563 | IWL_COEX_IS_RRC_ON(mvm->last_bt_notif.ttc_rrc_status, |
Emmanuel Grumbach | 4c86f93 | 2014-06-30 10:26:02 +0300 | [diff] [blame] | 564 | mvmvif->phy_ctxt->id)) |
| 565 | smps_mode = IEEE80211_SMPS_AUTOMATIC; |
| 566 | |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 567 | IWL_DEBUG_COEX(data->mvm, |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 568 | "mac %d: bt_activity_grading %d smps_req %d\n", |
| 569 | mvmvif->id, bt_activity_grading, smps_mode); |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 570 | |
Emmanuel Grumbach | 45bbb2c | 2014-07-07 14:38:39 +0300 | [diff] [blame] | 571 | if (vif->type == NL80211_IFTYPE_STATION) |
| 572 | iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX, |
| 573 | smps_mode); |
Emmanuel Grumbach | f6415f6 | 2013-12-26 15:32:40 +0200 | [diff] [blame] | 574 | |
Emmanuel Grumbach | 0ee5bcd | 2014-01-15 16:57:54 +0200 | [diff] [blame] | 575 | /* low latency is always primary */ |
| 576 | if (iwl_mvm_vif_low_latency(mvmvif)) { |
| 577 | data->primary_ll = true; |
| 578 | |
| 579 | data->secondary = data->primary; |
| 580 | data->primary = chanctx_conf; |
| 581 | } |
| 582 | |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 583 | if (vif->type == NL80211_IFTYPE_AP) { |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 584 | if (!mvmvif->ap_ibss_active) |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 585 | return; |
| 586 | |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 587 | if (chanctx_conf == data->primary) |
| 588 | return; |
| 589 | |
Emmanuel Grumbach | 0ee5bcd | 2014-01-15 16:57:54 +0200 | [diff] [blame] | 590 | if (!data->primary_ll) { |
| 591 | /* |
| 592 | * downgrade the current primary no matter what its |
| 593 | * type is. |
| 594 | */ |
| 595 | data->secondary = data->primary; |
| 596 | data->primary = chanctx_conf; |
| 597 | } else { |
| 598 | /* there is low latency vif - we will be secondary */ |
| 599 | data->secondary = chanctx_conf; |
| 600 | } |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 601 | return; |
| 602 | } |
| 603 | |
Emmanuel Grumbach | 0ee5bcd | 2014-01-15 16:57:54 +0200 | [diff] [blame] | 604 | /* |
| 605 | * STA / P2P Client, try to be primary if first vif. If we are in low |
| 606 | * latency mode, we are already in primary and just don't do much |
| 607 | */ |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 608 | if (!data->primary || data->primary == chanctx_conf) |
| 609 | data->primary = chanctx_conf; |
| 610 | else if (!data->secondary) |
| 611 | /* if secondary is not NULL, it might be a GO */ |
| 612 | data->secondary = chanctx_conf; |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 613 | |
Emmanuel Grumbach | 4d66449 | 2014-04-30 18:09:59 +0300 | [diff] [blame] | 614 | /* |
| 615 | * don't reduce the Tx power if one of these is true: |
| 616 | * we are in LOOSE |
| 617 | * single share antenna product |
Emmanuel Grumbach | c934bce | 2016-06-20 09:40:40 +0300 | [diff] [blame] | 618 | * BT is inactive |
| 619 | * we are not associated |
Emmanuel Grumbach | 4d66449 | 2014-04-30 18:09:59 +0300 | [diff] [blame] | 620 | */ |
Emmanuel Grumbach | 3914991 | 2013-07-14 13:40:21 +0300 | [diff] [blame] | 621 | if (iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT || |
Emmanuel Grumbach | 4d66449 | 2014-04-30 18:09:59 +0300 | [diff] [blame] | 622 | mvm->cfg->bt_shared_single_ant || !vif->bss_conf.assoc || |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 623 | le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF) { |
Emmanuel Grumbach | 0f618e6 | 2014-05-20 15:48:18 +0300 | [diff] [blame] | 624 | iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false); |
Emmanuel Grumbach | f6fc577 | 2013-09-08 08:57:15 +0300 | [diff] [blame] | 625 | iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0); |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 626 | return; |
Emmanuel Grumbach | 3914991 | 2013-07-14 13:40:21 +0300 | [diff] [blame] | 627 | } |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 628 | |
Andrei Otcheretianski | 911222b | 2013-07-21 17:37:19 +0300 | [diff] [blame] | 629 | /* try to get the avg rssi from fw */ |
| 630 | ave_rssi = mvmvif->bf_data.ave_beacon_signal; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 631 | |
| 632 | /* if the RSSI isn't valid, fake it is very low */ |
| 633 | if (!ave_rssi) |
| 634 | ave_rssi = -100; |
Emmanuel Grumbach | 8286d9f | 2014-05-27 22:54:18 +0300 | [diff] [blame] | 635 | if (ave_rssi > -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH) { |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 636 | if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true)) |
| 637 | IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n"); |
Emmanuel Grumbach | 8286d9f | 2014-05-27 22:54:18 +0300 | [diff] [blame] | 638 | } else if (ave_rssi < -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH) { |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 639 | if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false)) |
| 640 | IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n"); |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | /* Begin to monitor the RSSI: it may influence the reduced Tx power */ |
Emmanuel Grumbach | f6fc577 | 2013-09-08 08:57:15 +0300 | [diff] [blame] | 644 | iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, true, ave_rssi); |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 645 | } |
| 646 | |
Emmanuel Grumbach | d37cac9 | 2013-03-29 14:56:19 +0300 | [diff] [blame] | 647 | static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm) |
Emmanuel Grumbach | f421f9c | 2013-01-17 14:20:29 +0200 | [diff] [blame] | 648 | { |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 649 | struct iwl_bt_iterator_data data = { |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 650 | .mvm = mvm, |
Emmanuel Grumbach | d37cac9 | 2013-03-29 14:56:19 +0300 | [diff] [blame] | 651 | .notif = &mvm->last_bt_notif, |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 652 | }; |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 653 | struct iwl_bt_coex_ci_cmd cmd = {}; |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 654 | u8 ci_bw_idx; |
Emmanuel Grumbach | f421f9c | 2013-01-17 14:20:29 +0200 | [diff] [blame] | 655 | |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 656 | /* Ignore updates if we are in force mode */ |
| 657 | if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) |
| 658 | return; |
| 659 | |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 660 | rcu_read_lock(); |
Emmanuel Grumbach | 7da052b | 2013-02-10 17:06:17 +0200 | [diff] [blame] | 661 | ieee80211_iterate_active_interfaces_atomic( |
| 662 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 663 | iwl_mvm_bt_notif_iterator, &data); |
| 664 | |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 665 | if (data.primary) { |
| 666 | struct ieee80211_chanctx_conf *chan = data.primary; |
| 667 | if (WARN_ON(!chan->def.chan)) { |
| 668 | rcu_read_unlock(); |
| 669 | return; |
| 670 | } |
| 671 | |
| 672 | if (chan->def.width < NL80211_CHAN_WIDTH_40) { |
| 673 | ci_bw_idx = 0; |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 674 | } else { |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 675 | if (chan->def.center_freq1 > |
| 676 | chan->def.chan->center_freq) |
| 677 | ci_bw_idx = 2; |
| 678 | else |
| 679 | ci_bw_idx = 1; |
| 680 | } |
| 681 | |
| 682 | cmd.bt_primary_ci = |
| 683 | iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx]; |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 684 | cmd.primary_ch_phy_id = |
| 685 | cpu_to_le32(*((u16 *)data.primary->drv_priv)); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | if (data.secondary) { |
| 689 | struct ieee80211_chanctx_conf *chan = data.secondary; |
| 690 | if (WARN_ON(!data.secondary->def.chan)) { |
| 691 | rcu_read_unlock(); |
| 692 | return; |
| 693 | } |
| 694 | |
| 695 | if (chan->def.width < NL80211_CHAN_WIDTH_40) { |
| 696 | ci_bw_idx = 0; |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 697 | } else { |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 698 | if (chan->def.center_freq1 > |
| 699 | chan->def.chan->center_freq) |
| 700 | ci_bw_idx = 2; |
| 701 | else |
| 702 | ci_bw_idx = 1; |
| 703 | } |
| 704 | |
| 705 | cmd.bt_secondary_ci = |
| 706 | iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx]; |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 707 | cmd.secondary_ch_phy_id = |
| 708 | cpu_to_le32(*((u16 *)data.secondary->drv_priv)); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | rcu_read_unlock(); |
| 712 | |
| 713 | /* Don't spam the fw with the same command over and over */ |
| 714 | if (memcmp(&cmd, &mvm->last_bt_ci_cmd, sizeof(cmd))) { |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 715 | if (iwl_mvm_send_cmd_pdu(mvm, BT_COEX_CI, 0, |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 716 | sizeof(cmd), &cmd)) |
Johannes Berg | 3c6acb6 | 2014-05-07 11:47:53 +0200 | [diff] [blame] | 717 | IWL_ERR(mvm, "Failed to send BT_CI cmd\n"); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 718 | memcpy(&mvm->last_bt_ci_cmd, &cmd, sizeof(cmd)); |
| 719 | } |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 720 | } |
| 721 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 722 | void iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm, |
| 723 | struct iwl_rx_cmd_buffer *rxb) |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 724 | { |
| 725 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Emmanuel Grumbach | df878f3 | 2014-04-02 12:23:09 +0300 | [diff] [blame] | 726 | struct iwl_bt_coex_profile_notif *notif = (void *)pkt->data; |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 727 | |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 728 | IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n"); |
Emmanuel Grumbach | dac94da | 2013-06-18 07:35:27 +0300 | [diff] [blame] | 729 | IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n", notif->bt_ci_compliance); |
| 730 | IWL_DEBUG_COEX(mvm, "\tBT primary_ch_lut %d\n", |
| 731 | le32_to_cpu(notif->primary_ch_lut)); |
| 732 | IWL_DEBUG_COEX(mvm, "\tBT secondary_ch_lut %d\n", |
| 733 | le32_to_cpu(notif->secondary_ch_lut)); |
| 734 | IWL_DEBUG_COEX(mvm, "\tBT activity grading %d\n", |
| 735 | le32_to_cpu(notif->bt_activity_grading)); |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 736 | |
Emmanuel Grumbach | d37cac9 | 2013-03-29 14:56:19 +0300 | [diff] [blame] | 737 | /* remember this notification for future use: rssi fluctuations */ |
| 738 | memcpy(&mvm->last_bt_notif, notif, sizeof(mvm->last_bt_notif)); |
| 739 | |
| 740 | iwl_mvm_bt_coex_notif_handle(mvm); |
Emmanuel Grumbach | f421f9c | 2013-01-17 14:20:29 +0200 | [diff] [blame] | 741 | } |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 742 | |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 743 | 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] | 744 | enum ieee80211_rssi_event_data rssi_event) |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 745 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 746 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 747 | int ret; |
| 748 | |
Johannes Berg | 3dd1cd2 | 2013-10-02 12:05:24 +0200 | [diff] [blame] | 749 | lockdep_assert_held(&mvm->mutex); |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 750 | |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 751 | /* Ignore updates if we are in force mode */ |
| 752 | if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) |
| 753 | return; |
| 754 | |
Emmanuel Grumbach | 1e92919 | 2014-03-04 10:28:23 +0200 | [diff] [blame] | 755 | /* |
| 756 | * Rssi update while not associated - can happen since the statistics |
| 757 | * are handled asynchronously |
| 758 | */ |
| 759 | if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT) |
Johannes Berg | 3dd1cd2 | 2013-10-02 12:05:24 +0200 | [diff] [blame] | 760 | return; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 761 | |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 762 | /* No BT - reports should be disabled */ |
Emmanuel Grumbach | 430a3bb | 2014-04-02 09:55:16 +0300 | [diff] [blame] | 763 | 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] | 764 | return; |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 765 | |
| 766 | IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid, |
| 767 | rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW"); |
| 768 | |
| 769 | /* |
| 770 | * Check if rssi is good enough for reduced Tx power, but not in loose |
| 771 | * scheme. |
| 772 | */ |
Emmanuel Grumbach | 3914991 | 2013-07-14 13:40:21 +0300 | [diff] [blame] | 773 | if (rssi_event == RSSI_EVENT_LOW || mvm->cfg->bt_shared_single_ant || |
Emmanuel Grumbach | 4515f30 | 2013-06-30 07:51:54 +0300 | [diff] [blame] | 774 | iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT) |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 775 | ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, |
| 776 | false); |
| 777 | else |
| 778 | ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true); |
| 779 | |
| 780 | if (ret) |
| 781 | 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] | 782 | } |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 783 | |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 784 | #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000) |
| 785 | #define LINK_QUAL_AGG_TIME_LIMIT_BT_ACT (1200) |
| 786 | |
Emmanuel Grumbach | 5b7ff61 | 2014-03-11 19:27:45 +0200 | [diff] [blame] | 787 | u16 iwl_mvm_coex_agg_time_limit(struct iwl_mvm *mvm, |
| 788 | struct ieee80211_sta *sta) |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 789 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 790 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | 4c86f93 | 2014-06-30 10:26:02 +0300 | [diff] [blame] | 791 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif); |
| 792 | struct iwl_mvm_phy_ctxt *phy_ctxt = mvmvif->phy_ctxt; |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 793 | enum iwl_bt_coex_lut_type lut_type; |
| 794 | |
Emmanuel Grumbach | 4c86f93 | 2014-06-30 10:26:02 +0300 | [diff] [blame] | 795 | if (IWL_COEX_IS_TTC_ON(mvm->last_bt_notif.ttc_rrc_status, phy_ctxt->id)) |
| 796 | return LINK_QUAL_AGG_TIME_LIMIT_DEF; |
| 797 | |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 798 | if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) < |
Emmanuel Grumbach | c211935 | 2013-11-13 22:00:30 +0200 | [diff] [blame] | 799 | BT_HIGH_TRAFFIC) |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 800 | return LINK_QUAL_AGG_TIME_LIMIT_DEF; |
Emmanuel Grumbach | 35fbf5d | 2014-06-02 16:18:42 +0300 | [diff] [blame] | 801 | |
Emmanuel Grumbach | 9145d15 | 2013-07-18 08:45:41 +0300 | [diff] [blame] | 802 | lut_type = iwl_get_coex_type(mvm, mvmsta->vif); |
| 803 | |
Emmanuel Grumbach | 7fa4fa0 | 2014-05-25 13:58:31 +0300 | [diff] [blame] | 804 | 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] | 805 | return LINK_QUAL_AGG_TIME_LIMIT_DEF; |
| 806 | |
| 807 | /* tight coex, high bt traffic, reduce AGG time limit */ |
| 808 | return LINK_QUAL_AGG_TIME_LIMIT_BT_ACT; |
| 809 | } |
| 810 | |
Emmanuel Grumbach | ffa6c70 | 2013-10-06 11:41:20 +0300 | [diff] [blame] | 811 | bool iwl_mvm_bt_coex_is_mimo_allowed(struct iwl_mvm *mvm, |
| 812 | struct ieee80211_sta *sta) |
| 813 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 814 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | 4c86f93 | 2014-06-30 10:26:02 +0300 | [diff] [blame] | 815 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif); |
| 816 | struct iwl_mvm_phy_ctxt *phy_ctxt = mvmvif->phy_ctxt; |
Emmanuel Grumbach | 7fa4fa0 | 2014-05-25 13:58:31 +0300 | [diff] [blame] | 817 | enum iwl_bt_coex_lut_type lut_type; |
Emmanuel Grumbach | ffa6c70 | 2013-10-06 11:41:20 +0300 | [diff] [blame] | 818 | |
Emmanuel Grumbach | 4c86f93 | 2014-06-30 10:26:02 +0300 | [diff] [blame] | 819 | if (IWL_COEX_IS_TTC_ON(mvm->last_bt_notif.ttc_rrc_status, phy_ctxt->id)) |
Emmanuel Grumbach | 35fbf5d | 2014-06-02 16:18:42 +0300 | [diff] [blame] | 820 | return true; |
| 821 | |
Emmanuel Grumbach | ffa6c70 | 2013-10-06 11:41:20 +0300 | [diff] [blame] | 822 | if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) < |
| 823 | BT_HIGH_TRAFFIC) |
| 824 | return true; |
| 825 | |
| 826 | /* |
Emmanuel Grumbach | 7fa4fa0 | 2014-05-25 13:58:31 +0300 | [diff] [blame] | 827 | * In Tight / TxTxDis, BT can't Rx while we Tx, so use both antennas |
| 828 | * since BT is already killed. |
| 829 | * In Loose, BT can Rx while we Tx, so forbid MIMO to let BT Rx while |
| 830 | * we Tx. |
| 831 | * 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] | 832 | */ |
Emmanuel Grumbach | 7fa4fa0 | 2014-05-25 13:58:31 +0300 | [diff] [blame] | 833 | lut_type = iwl_get_coex_type(mvm, mvmsta->vif); |
| 834 | return lut_type != BT_COEX_LOOSE_LUT; |
Emmanuel Grumbach | ffa6c70 | 2013-10-06 11:41:20 +0300 | [diff] [blame] | 835 | } |
| 836 | |
Emmanuel Grumbach | 219fb66 | 2014-10-30 11:59:40 +0200 | [diff] [blame] | 837 | bool iwl_mvm_bt_coex_is_ant_avail(struct iwl_mvm *mvm, u8 ant) |
| 838 | { |
| 839 | /* there is no other antenna, shared antenna is always available */ |
| 840 | if (mvm->cfg->bt_shared_single_ant) |
| 841 | return true; |
| 842 | |
| 843 | if (ant & mvm->cfg->non_shared_ant) |
| 844 | return true; |
| 845 | |
Emmanuel Grumbach | 219fb66 | 2014-10-30 11:59:40 +0200 | [diff] [blame] | 846 | return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) < |
| 847 | BT_HIGH_TRAFFIC; |
| 848 | } |
| 849 | |
Emmanuel Grumbach | 34c8b24 | 2014-05-28 21:53:39 +0300 | [diff] [blame] | 850 | bool iwl_mvm_bt_coex_is_shared_ant_avail(struct iwl_mvm *mvm) |
| 851 | { |
Emmanuel Grumbach | bbab758 | 2014-09-10 11:00:16 +0300 | [diff] [blame] | 852 | /* there is no other antenna, shared antenna is always available */ |
| 853 | if (mvm->cfg->bt_shared_single_ant) |
| 854 | return true; |
| 855 | |
Emmanuel Grumbach | cb97e41 | 2015-05-16 22:47:56 +0300 | [diff] [blame] | 856 | 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] | 857 | } |
| 858 | |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 859 | bool iwl_mvm_bt_coex_is_tpc_allowed(struct iwl_mvm *mvm, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 860 | enum nl80211_band band) |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 861 | { |
| 862 | u32 bt_activity = le32_to_cpu(mvm->last_bt_notif.bt_activity_grading); |
| 863 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 864 | if (band != NL80211_BAND_2GHZ) |
Eliad Peller | 2fd647f | 2014-03-13 17:21:36 +0200 | [diff] [blame] | 865 | return false; |
| 866 | |
| 867 | return bt_activity >= BT_LOW_TRAFFIC; |
| 868 | } |
| 869 | |
Emmanuel Grumbach | ee7bea5 | 2014-03-06 10:30:49 +0200 | [diff] [blame] | 870 | 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] | 871 | struct ieee80211_tx_info *info, u8 ac) |
Emmanuel Grumbach | ee7bea5 | 2014-03-06 10:30:49 +0200 | [diff] [blame] | 872 | { |
| 873 | __le16 fc = hdr->frame_control; |
Avri Altman | 6e36510 | 2015-11-02 14:16:07 +0200 | [diff] [blame] | 874 | bool mplut_enabled = iwl_mvm_is_mplut_supported(mvm); |
Emmanuel Grumbach | ee7bea5 | 2014-03-06 10:30:49 +0200 | [diff] [blame] | 875 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 876 | if (info->band != NL80211_BAND_2GHZ) |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 877 | return 0; |
| 878 | |
Emmanuel Grumbach | cdb0056 | 2014-03-16 21:55:43 +0200 | [diff] [blame] | 879 | if (unlikely(mvm->bt_tx_prio)) |
| 880 | return mvm->bt_tx_prio - 1; |
| 881 | |
Avri Altman | 6e36510 | 2015-11-02 14:16:07 +0200 | [diff] [blame] | 882 | if (likely(ieee80211_is_data(fc))) { |
| 883 | if (likely(ieee80211_is_data_qos(fc))) { |
| 884 | switch (ac) { |
| 885 | case IEEE80211_AC_BE: |
| 886 | return mplut_enabled ? 1 : 0; |
| 887 | case IEEE80211_AC_VI: |
| 888 | return mplut_enabled ? 2 : 3; |
| 889 | case IEEE80211_AC_VO: |
| 890 | return 3; |
| 891 | default: |
| 892 | return 0; |
| 893 | } |
| 894 | } else if (is_multicast_ether_addr(hdr->addr1)) { |
| 895 | return 3; |
| 896 | } else |
| 897 | return 0; |
| 898 | } else if (ieee80211_is_mgmt(fc)) { |
| 899 | return ieee80211_is_disassoc(fc) ? 0 : 3; |
| 900 | } else if (ieee80211_is_ctl(fc)) { |
| 901 | /* ignore cfend and cfendack frames as we never send those */ |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 902 | return 3; |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 903 | } |
Emmanuel Grumbach | ee7bea5 | 2014-03-06 10:30:49 +0200 | [diff] [blame] | 904 | |
| 905 | return 0; |
| 906 | } |
| 907 | |
Emmanuel Grumbach | 8e484f0 | 2013-10-02 15:02:25 +0300 | [diff] [blame] | 908 | void iwl_mvm_bt_coex_vif_change(struct iwl_mvm *mvm) |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 909 | { |
Emmanuel Grumbach | d37cac9 | 2013-03-29 14:56:19 +0300 | [diff] [blame] | 910 | iwl_mvm_bt_coex_notif_handle(mvm); |
Emmanuel Grumbach | 9166b1e | 2013-03-20 15:28:27 +0200 | [diff] [blame] | 911 | } |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 912 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 913 | void iwl_mvm_rx_ant_coupling_notif(struct iwl_mvm *mvm, |
| 914 | struct iwl_rx_cmd_buffer *rxb) |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 915 | { |
| 916 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 917 | u32 ant_isolation = le32_to_cpup((void *)pkt->data); |
Emmanuel Grumbach | 704602a | 2014-04-02 12:23:09 +0300 | [diff] [blame] | 918 | struct iwl_bt_coex_corun_lut_update_cmd cmd = {}; |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 919 | u8 __maybe_unused lower_bound, upper_bound; |
| 920 | u8 lut; |
| 921 | |
Emmanuel Grumbach | 0522588 | 2015-02-12 12:33:09 +0200 | [diff] [blame] | 922 | if (!iwl_mvm_bt_is_plcr_supported(mvm)) |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 923 | return; |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 924 | |
| 925 | lockdep_assert_held(&mvm->mutex); |
| 926 | |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 927 | /* Ignore updates if we are in force mode */ |
| 928 | if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 929 | return; |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 930 | |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 931 | if (ant_isolation == mvm->last_ant_isol) |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 932 | return; |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 933 | |
| 934 | for (lut = 0; lut < ARRAY_SIZE(antenna_coupling_ranges) - 1; lut++) |
| 935 | if (ant_isolation < antenna_coupling_ranges[lut + 1].range) |
| 936 | break; |
| 937 | |
| 938 | lower_bound = antenna_coupling_ranges[lut].range; |
| 939 | |
| 940 | if (lut < ARRAY_SIZE(antenna_coupling_ranges) - 1) |
| 941 | upper_bound = antenna_coupling_ranges[lut + 1].range; |
| 942 | else |
| 943 | upper_bound = antenna_coupling_ranges[lut].range; |
| 944 | |
| 945 | IWL_DEBUG_COEX(mvm, "Antenna isolation=%d in range [%d,%d[, lut=%d\n", |
| 946 | ant_isolation, lower_bound, upper_bound, lut); |
| 947 | |
| 948 | mvm->last_ant_isol = ant_isolation; |
| 949 | |
| 950 | if (mvm->last_corun_lut == lut) |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 951 | return; |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 952 | |
| 953 | mvm->last_corun_lut = lut; |
| 954 | |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 955 | /* For the moment, use the same LUT for 20GHz and 40GHz */ |
Emmanuel Grumbach | 704602a | 2014-04-02 12:23:09 +0300 | [diff] [blame] | 956 | memcpy(&cmd.corun_lut20, antenna_coupling_ranges[lut].lut20, |
| 957 | sizeof(cmd.corun_lut20)); |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 958 | |
Emmanuel Grumbach | 704602a | 2014-04-02 12:23:09 +0300 | [diff] [blame] | 959 | memcpy(&cmd.corun_lut40, antenna_coupling_ranges[lut].lut20, |
| 960 | sizeof(cmd.corun_lut40)); |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 961 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 962 | if (iwl_mvm_send_cmd_pdu(mvm, BT_COEX_UPDATE_CORUN_LUT, 0, |
| 963 | sizeof(cmd), &cmd)) |
| 964 | IWL_ERR(mvm, |
| 965 | "failed to send BT_COEX_UPDATE_CORUN_LUT command\n"); |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 966 | } |