coex.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  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:
  29. * Intel Linux Wireless <ilw@linux.intel.com>
  30. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  31. *
  32. * BSD LICENSE
  33. *
  34. * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
  35. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  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. #include <linux/ieee80211.h>
  66. #include <linux/etherdevice.h>
  67. #include <net/mac80211.h>
  68. #include "fw-api-coex.h"
  69. #include "iwl-modparams.h"
  70. #include "mvm.h"
  71. #include "iwl-debug.h"
  72. /* 20MHz / 40MHz below / 40Mhz above*/
  73. static const __le64 iwl_ci_mask[][3] = {
  74. /* dummy entry for channel 0 */
  75. {cpu_to_le64(0), cpu_to_le64(0), cpu_to_le64(0)},
  76. {
  77. cpu_to_le64(0x0000001FFFULL),
  78. cpu_to_le64(0x0ULL),
  79. cpu_to_le64(0x00007FFFFFULL),
  80. },
  81. {
  82. cpu_to_le64(0x000000FFFFULL),
  83. cpu_to_le64(0x0ULL),
  84. cpu_to_le64(0x0003FFFFFFULL),
  85. },
  86. {
  87. cpu_to_le64(0x000003FFFCULL),
  88. cpu_to_le64(0x0ULL),
  89. cpu_to_le64(0x000FFFFFFCULL),
  90. },
  91. {
  92. cpu_to_le64(0x00001FFFE0ULL),
  93. cpu_to_le64(0x0ULL),
  94. cpu_to_le64(0x007FFFFFE0ULL),
  95. },
  96. {
  97. cpu_to_le64(0x00007FFF80ULL),
  98. cpu_to_le64(0x00007FFFFFULL),
  99. cpu_to_le64(0x01FFFFFF80ULL),
  100. },
  101. {
  102. cpu_to_le64(0x0003FFFC00ULL),
  103. cpu_to_le64(0x0003FFFFFFULL),
  104. cpu_to_le64(0x0FFFFFFC00ULL),
  105. },
  106. {
  107. cpu_to_le64(0x000FFFF000ULL),
  108. cpu_to_le64(0x000FFFFFFCULL),
  109. cpu_to_le64(0x3FFFFFF000ULL),
  110. },
  111. {
  112. cpu_to_le64(0x007FFF8000ULL),
  113. cpu_to_le64(0x007FFFFFE0ULL),
  114. cpu_to_le64(0xFFFFFF8000ULL),
  115. },
  116. {
  117. cpu_to_le64(0x01FFFE0000ULL),
  118. cpu_to_le64(0x01FFFFFF80ULL),
  119. cpu_to_le64(0xFFFFFE0000ULL),
  120. },
  121. {
  122. cpu_to_le64(0x0FFFF00000ULL),
  123. cpu_to_le64(0x0FFFFFFC00ULL),
  124. cpu_to_le64(0x0ULL),
  125. },
  126. {
  127. cpu_to_le64(0x3FFFC00000ULL),
  128. cpu_to_le64(0x3FFFFFF000ULL),
  129. cpu_to_le64(0x0)
  130. },
  131. {
  132. cpu_to_le64(0xFFFE000000ULL),
  133. cpu_to_le64(0xFFFFFF8000ULL),
  134. cpu_to_le64(0x0)
  135. },
  136. {
  137. cpu_to_le64(0xFFF8000000ULL),
  138. cpu_to_le64(0xFFFFFE0000ULL),
  139. cpu_to_le64(0x0)
  140. },
  141. {
  142. cpu_to_le64(0xFFC0000000ULL),
  143. cpu_to_le64(0x0ULL),
  144. cpu_to_le64(0x0ULL)
  145. },
  146. };
  147. struct corunning_block_luts {
  148. u8 range;
  149. __le32 lut20[BT_COEX_CORUN_LUT_SIZE];
  150. };
  151. /*
  152. * Ranges for the antenna coupling calibration / co-running block LUT:
  153. * LUT0: [ 0, 12[
  154. * LUT1: [12, 20[
  155. * LUT2: [20, 21[
  156. * LUT3: [21, 23[
  157. * LUT4: [23, 27[
  158. * LUT5: [27, 30[
  159. * LUT6: [30, 32[
  160. * LUT7: [32, 33[
  161. * LUT8: [33, - [
  162. */
  163. static const struct corunning_block_luts antenna_coupling_ranges[] = {
  164. {
  165. .range = 0,
  166. .lut20 = {
  167. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  168. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  169. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  170. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  171. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  184. },
  185. {
  186. .range = 12,
  187. .lut20 = {
  188. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  189. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  190. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  191. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  192. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  193. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  205. },
  206. {
  207. .range = 20,
  208. .lut20 = {
  209. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  210. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  211. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  212. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  213. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  214. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  226. },
  227. {
  228. .range = 21,
  229. .lut20 = {
  230. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  231. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  232. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  233. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  234. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  235. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  247. },
  248. {
  249. .range = 23,
  250. .lut20 = {
  251. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  252. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  253. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  254. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  255. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  256. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  268. },
  269. {
  270. .range = 27,
  271. .lut20 = {
  272. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  273. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  274. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  275. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  276. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  277. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  289. },
  290. {
  291. .range = 30,
  292. .lut20 = {
  293. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  294. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  295. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  296. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  297. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  298. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  310. },
  311. {
  312. .range = 32,
  313. .lut20 = {
  314. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  315. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  316. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  317. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  318. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  319. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  331. },
  332. {
  333. .range = 33,
  334. .lut20 = {
  335. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  336. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  337. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  338. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  339. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  340. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  352. },
  353. };
  354. static enum iwl_bt_coex_lut_type
  355. iwl_get_coex_type(struct iwl_mvm *mvm, const struct ieee80211_vif *vif)
  356. {
  357. struct ieee80211_chanctx_conf *chanctx_conf;
  358. enum iwl_bt_coex_lut_type ret;
  359. u16 phy_ctx_id;
  360. u32 primary_ch_phy_id, secondary_ch_phy_id;
  361. /*
  362. * Checking that we hold mvm->mutex is a good idea, but the rate
  363. * control can't acquire the mutex since it runs in Tx path.
  364. * So this is racy in that case, but in the worst case, the AMPDU
  365. * size limit will be wrong for a short time which is not a big
  366. * issue.
  367. */
  368. rcu_read_lock();
  369. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  370. if (!chanctx_conf ||
  371. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ) {
  372. rcu_read_unlock();
  373. return BT_COEX_INVALID_LUT;
  374. }
  375. ret = BT_COEX_TX_DIS_LUT;
  376. if (mvm->cfg->bt_shared_single_ant) {
  377. rcu_read_unlock();
  378. return ret;
  379. }
  380. phy_ctx_id = *((u16 *)chanctx_conf->drv_priv);
  381. primary_ch_phy_id = le32_to_cpu(mvm->last_bt_ci_cmd.primary_ch_phy_id);
  382. secondary_ch_phy_id =
  383. le32_to_cpu(mvm->last_bt_ci_cmd.secondary_ch_phy_id);
  384. if (primary_ch_phy_id == phy_ctx_id)
  385. ret = le32_to_cpu(mvm->last_bt_notif.primary_ch_lut);
  386. else if (secondary_ch_phy_id == phy_ctx_id)
  387. ret = le32_to_cpu(mvm->last_bt_notif.secondary_ch_lut);
  388. /* else - default = TX TX disallowed */
  389. rcu_read_unlock();
  390. return ret;
  391. }
  392. int iwl_send_bt_init_conf(struct iwl_mvm *mvm)
  393. {
  394. struct iwl_bt_coex_cmd bt_cmd = {};
  395. u32 mode;
  396. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  397. return iwl_send_bt_init_conf_old(mvm);
  398. lockdep_assert_held(&mvm->mutex);
  399. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) {
  400. switch (mvm->bt_force_ant_mode) {
  401. case BT_FORCE_ANT_BT:
  402. mode = BT_COEX_BT;
  403. break;
  404. case BT_FORCE_ANT_WIFI:
  405. mode = BT_COEX_WIFI;
  406. break;
  407. default:
  408. WARN_ON(1);
  409. mode = 0;
  410. }
  411. bt_cmd.mode = cpu_to_le32(mode);
  412. goto send_cmd;
  413. }
  414. mode = iwlwifi_mod_params.bt_coex_active ? BT_COEX_NW : BT_COEX_DISABLE;
  415. bt_cmd.mode = cpu_to_le32(mode);
  416. if (IWL_MVM_BT_COEX_SYNC2SCO)
  417. bt_cmd.enabled_modules |=
  418. cpu_to_le32(BT_COEX_SYNC2SCO_ENABLED);
  419. if (iwl_mvm_bt_is_plcr_supported(mvm))
  420. bt_cmd.enabled_modules |= cpu_to_le32(BT_COEX_CORUN_ENABLED);
  421. if (IWL_MVM_BT_COEX_MPLUT) {
  422. bt_cmd.enabled_modules |= cpu_to_le32(BT_COEX_MPLUT_ENABLED);
  423. bt_cmd.enabled_modules |=
  424. cpu_to_le32(BT_COEX_MPLUT_BOOST_ENABLED);
  425. }
  426. bt_cmd.enabled_modules |= cpu_to_le32(BT_COEX_HIGH_BAND_RET);
  427. send_cmd:
  428. memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
  429. memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
  430. return iwl_mvm_send_cmd_pdu(mvm, BT_CONFIG, 0, sizeof(bt_cmd), &bt_cmd);
  431. }
  432. static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id,
  433. bool enable)
  434. {
  435. struct iwl_bt_coex_reduced_txp_update_cmd cmd = {};
  436. struct iwl_mvm_sta *mvmsta;
  437. u32 value;
  438. int ret;
  439. mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
  440. if (!mvmsta)
  441. return 0;
  442. /* nothing to do */
  443. if (mvmsta->bt_reduced_txpower == enable)
  444. return 0;
  445. value = mvmsta->sta_id;
  446. if (enable)
  447. value |= BT_REDUCED_TX_POWER_BIT;
  448. IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n",
  449. enable ? "en" : "dis", sta_id);
  450. cmd.reduced_txp = cpu_to_le32(value);
  451. mvmsta->bt_reduced_txpower = enable;
  452. ret = iwl_mvm_send_cmd_pdu(mvm, BT_COEX_UPDATE_REDUCED_TXP, CMD_ASYNC,
  453. sizeof(cmd), &cmd);
  454. return ret;
  455. }
  456. struct iwl_bt_iterator_data {
  457. struct iwl_bt_coex_profile_notif *notif;
  458. struct iwl_mvm *mvm;
  459. struct ieee80211_chanctx_conf *primary;
  460. struct ieee80211_chanctx_conf *secondary;
  461. bool primary_ll;
  462. };
  463. static inline
  464. void iwl_mvm_bt_coex_enable_rssi_event(struct iwl_mvm *mvm,
  465. struct ieee80211_vif *vif,
  466. bool enable, int rssi)
  467. {
  468. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  469. mvmvif->bf_data.last_bt_coex_event = rssi;
  470. mvmvif->bf_data.bt_coex_max_thold =
  471. enable ? -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH : 0;
  472. mvmvif->bf_data.bt_coex_min_thold =
  473. enable ? -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH : 0;
  474. }
  475. /* must be called under rcu_read_lock */
  476. static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac,
  477. struct ieee80211_vif *vif)
  478. {
  479. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  480. struct iwl_bt_iterator_data *data = _data;
  481. struct iwl_mvm *mvm = data->mvm;
  482. struct ieee80211_chanctx_conf *chanctx_conf;
  483. /* default smps_mode is AUTOMATIC - only used for client modes */
  484. enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_AUTOMATIC;
  485. u32 bt_activity_grading;
  486. int ave_rssi;
  487. lockdep_assert_held(&mvm->mutex);
  488. switch (vif->type) {
  489. case NL80211_IFTYPE_STATION:
  490. break;
  491. case NL80211_IFTYPE_AP:
  492. if (!mvmvif->ap_ibss_active)
  493. return;
  494. break;
  495. default:
  496. return;
  497. }
  498. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  499. /* If channel context is invalid or not on 2.4GHz .. */
  500. if ((!chanctx_conf ||
  501. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ)) {
  502. if (vif->type == NL80211_IFTYPE_STATION) {
  503. /* ... relax constraints and disable rssi events */
  504. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  505. smps_mode);
  506. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  507. false);
  508. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  509. }
  510. return;
  511. }
  512. bt_activity_grading = le32_to_cpu(data->notif->bt_activity_grading);
  513. if (bt_activity_grading >= BT_HIGH_TRAFFIC)
  514. smps_mode = IEEE80211_SMPS_STATIC;
  515. else if (bt_activity_grading >= BT_LOW_TRAFFIC)
  516. smps_mode = IEEE80211_SMPS_DYNAMIC;
  517. /* relax SMPS constraints for next association */
  518. if (!vif->bss_conf.assoc)
  519. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  520. if (mvmvif->phy_ctxt &&
  521. IWL_COEX_IS_RRC_ON(mvm->last_bt_notif.ttc_rrc_status,
  522. mvmvif->phy_ctxt->id))
  523. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  524. IWL_DEBUG_COEX(data->mvm,
  525. "mac %d: bt_activity_grading %d smps_req %d\n",
  526. mvmvif->id, bt_activity_grading, smps_mode);
  527. if (vif->type == NL80211_IFTYPE_STATION)
  528. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  529. smps_mode);
  530. /* low latency is always primary */
  531. if (iwl_mvm_vif_low_latency(mvmvif)) {
  532. data->primary_ll = true;
  533. data->secondary = data->primary;
  534. data->primary = chanctx_conf;
  535. }
  536. if (vif->type == NL80211_IFTYPE_AP) {
  537. if (!mvmvif->ap_ibss_active)
  538. return;
  539. if (chanctx_conf == data->primary)
  540. return;
  541. if (!data->primary_ll) {
  542. /*
  543. * downgrade the current primary no matter what its
  544. * type is.
  545. */
  546. data->secondary = data->primary;
  547. data->primary = chanctx_conf;
  548. } else {
  549. /* there is low latency vif - we will be secondary */
  550. data->secondary = chanctx_conf;
  551. }
  552. return;
  553. }
  554. /*
  555. * STA / P2P Client, try to be primary if first vif. If we are in low
  556. * latency mode, we are already in primary and just don't do much
  557. */
  558. if (!data->primary || data->primary == chanctx_conf)
  559. data->primary = chanctx_conf;
  560. else if (!data->secondary)
  561. /* if secondary is not NULL, it might be a GO */
  562. data->secondary = chanctx_conf;
  563. /*
  564. * don't reduce the Tx power if one of these is true:
  565. * we are in LOOSE
  566. * single share antenna product
  567. * BT is active
  568. * we are associated
  569. */
  570. if (iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT ||
  571. mvm->cfg->bt_shared_single_ant || !vif->bss_conf.assoc ||
  572. le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF) {
  573. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false);
  574. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  575. return;
  576. }
  577. /* try to get the avg rssi from fw */
  578. ave_rssi = mvmvif->bf_data.ave_beacon_signal;
  579. /* if the RSSI isn't valid, fake it is very low */
  580. if (!ave_rssi)
  581. ave_rssi = -100;
  582. if (ave_rssi > -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH) {
  583. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true))
  584. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  585. } else if (ave_rssi < -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH) {
  586. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
  587. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  588. }
  589. /* Begin to monitor the RSSI: it may influence the reduced Tx power */
  590. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, true, ave_rssi);
  591. }
  592. static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm)
  593. {
  594. struct iwl_bt_iterator_data data = {
  595. .mvm = mvm,
  596. .notif = &mvm->last_bt_notif,
  597. };
  598. struct iwl_bt_coex_ci_cmd cmd = {};
  599. u8 ci_bw_idx;
  600. /* Ignore updates if we are in force mode */
  601. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  602. return;
  603. rcu_read_lock();
  604. ieee80211_iterate_active_interfaces_atomic(
  605. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  606. iwl_mvm_bt_notif_iterator, &data);
  607. if (data.primary) {
  608. struct ieee80211_chanctx_conf *chan = data.primary;
  609. if (WARN_ON(!chan->def.chan)) {
  610. rcu_read_unlock();
  611. return;
  612. }
  613. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  614. ci_bw_idx = 0;
  615. } else {
  616. if (chan->def.center_freq1 >
  617. chan->def.chan->center_freq)
  618. ci_bw_idx = 2;
  619. else
  620. ci_bw_idx = 1;
  621. }
  622. cmd.bt_primary_ci =
  623. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  624. cmd.primary_ch_phy_id =
  625. cpu_to_le32(*((u16 *)data.primary->drv_priv));
  626. }
  627. if (data.secondary) {
  628. struct ieee80211_chanctx_conf *chan = data.secondary;
  629. if (WARN_ON(!data.secondary->def.chan)) {
  630. rcu_read_unlock();
  631. return;
  632. }
  633. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  634. ci_bw_idx = 0;
  635. } else {
  636. if (chan->def.center_freq1 >
  637. chan->def.chan->center_freq)
  638. ci_bw_idx = 2;
  639. else
  640. ci_bw_idx = 1;
  641. }
  642. cmd.bt_secondary_ci =
  643. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  644. cmd.secondary_ch_phy_id =
  645. cpu_to_le32(*((u16 *)data.secondary->drv_priv));
  646. }
  647. rcu_read_unlock();
  648. /* Don't spam the fw with the same command over and over */
  649. if (memcmp(&cmd, &mvm->last_bt_ci_cmd, sizeof(cmd))) {
  650. if (iwl_mvm_send_cmd_pdu(mvm, BT_COEX_CI, 0,
  651. sizeof(cmd), &cmd))
  652. IWL_ERR(mvm, "Failed to send BT_CI cmd\n");
  653. memcpy(&mvm->last_bt_ci_cmd, &cmd, sizeof(cmd));
  654. }
  655. }
  656. int iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm,
  657. struct iwl_rx_cmd_buffer *rxb,
  658. struct iwl_device_cmd *dev_cmd)
  659. {
  660. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  661. struct iwl_bt_coex_profile_notif *notif = (void *)pkt->data;
  662. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  663. return iwl_mvm_rx_bt_coex_notif_old(mvm, rxb, dev_cmd);
  664. IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n");
  665. IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n", notif->bt_ci_compliance);
  666. IWL_DEBUG_COEX(mvm, "\tBT primary_ch_lut %d\n",
  667. le32_to_cpu(notif->primary_ch_lut));
  668. IWL_DEBUG_COEX(mvm, "\tBT secondary_ch_lut %d\n",
  669. le32_to_cpu(notif->secondary_ch_lut));
  670. IWL_DEBUG_COEX(mvm, "\tBT activity grading %d\n",
  671. le32_to_cpu(notif->bt_activity_grading));
  672. /* remember this notification for future use: rssi fluctuations */
  673. memcpy(&mvm->last_bt_notif, notif, sizeof(mvm->last_bt_notif));
  674. iwl_mvm_bt_coex_notif_handle(mvm);
  675. /*
  676. * This is an async handler for a notification, returning anything other
  677. * than 0 doesn't make sense even if HCMD failed.
  678. */
  679. return 0;
  680. }
  681. void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  682. enum ieee80211_rssi_event_data rssi_event)
  683. {
  684. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  685. int ret;
  686. if (!fw_has_api(&mvm->fw->ucode_capa,
  687. IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
  688. iwl_mvm_bt_rssi_event_old(mvm, vif, rssi_event);
  689. return;
  690. }
  691. lockdep_assert_held(&mvm->mutex);
  692. /* Ignore updates if we are in force mode */
  693. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  694. return;
  695. /*
  696. * Rssi update while not associated - can happen since the statistics
  697. * are handled asynchronously
  698. */
  699. if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  700. return;
  701. /* No BT - reports should be disabled */
  702. if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF)
  703. return;
  704. IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid,
  705. rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW");
  706. /*
  707. * Check if rssi is good enough for reduced Tx power, but not in loose
  708. * scheme.
  709. */
  710. if (rssi_event == RSSI_EVENT_LOW || mvm->cfg->bt_shared_single_ant ||
  711. iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT)
  712. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  713. false);
  714. else
  715. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true);
  716. if (ret)
  717. IWL_ERR(mvm, "couldn't send BT_CONFIG HCMD upon RSSI event\n");
  718. }
  719. #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000)
  720. #define LINK_QUAL_AGG_TIME_LIMIT_BT_ACT (1200)
  721. u16 iwl_mvm_coex_agg_time_limit(struct iwl_mvm *mvm,
  722. struct ieee80211_sta *sta)
  723. {
  724. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  725. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
  726. struct iwl_mvm_phy_ctxt *phy_ctxt = mvmvif->phy_ctxt;
  727. enum iwl_bt_coex_lut_type lut_type;
  728. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  729. return iwl_mvm_coex_agg_time_limit_old(mvm, sta);
  730. if (IWL_COEX_IS_TTC_ON(mvm->last_bt_notif.ttc_rrc_status, phy_ctxt->id))
  731. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  732. if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) <
  733. BT_HIGH_TRAFFIC)
  734. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  735. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  736. if (lut_type == BT_COEX_LOOSE_LUT || lut_type == BT_COEX_INVALID_LUT)
  737. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  738. /* tight coex, high bt traffic, reduce AGG time limit */
  739. return LINK_QUAL_AGG_TIME_LIMIT_BT_ACT;
  740. }
  741. bool iwl_mvm_bt_coex_is_mimo_allowed(struct iwl_mvm *mvm,
  742. struct ieee80211_sta *sta)
  743. {
  744. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  745. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
  746. struct iwl_mvm_phy_ctxt *phy_ctxt = mvmvif->phy_ctxt;
  747. enum iwl_bt_coex_lut_type lut_type;
  748. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  749. return iwl_mvm_bt_coex_is_mimo_allowed_old(mvm, sta);
  750. if (IWL_COEX_IS_TTC_ON(mvm->last_bt_notif.ttc_rrc_status, phy_ctxt->id))
  751. return true;
  752. if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) <
  753. BT_HIGH_TRAFFIC)
  754. return true;
  755. /*
  756. * In Tight / TxTxDis, BT can't Rx while we Tx, so use both antennas
  757. * since BT is already killed.
  758. * In Loose, BT can Rx while we Tx, so forbid MIMO to let BT Rx while
  759. * we Tx.
  760. * When we are in 5GHz, we'll get BT_COEX_INVALID_LUT allowing MIMO.
  761. */
  762. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  763. return lut_type != BT_COEX_LOOSE_LUT;
  764. }
  765. bool iwl_mvm_bt_coex_is_ant_avail(struct iwl_mvm *mvm, u8 ant)
  766. {
  767. /* there is no other antenna, shared antenna is always available */
  768. if (mvm->cfg->bt_shared_single_ant)
  769. return true;
  770. if (ant & mvm->cfg->non_shared_ant)
  771. return true;
  772. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  773. return iwl_mvm_bt_coex_is_shared_ant_avail_old(mvm);
  774. return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) <
  775. BT_HIGH_TRAFFIC;
  776. }
  777. bool iwl_mvm_bt_coex_is_shared_ant_avail(struct iwl_mvm *mvm)
  778. {
  779. /* there is no other antenna, shared antenna is always available */
  780. if (mvm->cfg->bt_shared_single_ant)
  781. return true;
  782. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  783. return iwl_mvm_bt_coex_is_shared_ant_avail_old(mvm);
  784. return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) < BT_HIGH_TRAFFIC;
  785. }
  786. bool iwl_mvm_bt_coex_is_tpc_allowed(struct iwl_mvm *mvm,
  787. enum ieee80211_band band)
  788. {
  789. u32 bt_activity = le32_to_cpu(mvm->last_bt_notif.bt_activity_grading);
  790. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  791. return iwl_mvm_bt_coex_is_tpc_allowed_old(mvm, band);
  792. if (band != IEEE80211_BAND_2GHZ)
  793. return false;
  794. return bt_activity >= BT_LOW_TRAFFIC;
  795. }
  796. u8 iwl_mvm_bt_coex_tx_prio(struct iwl_mvm *mvm, struct ieee80211_hdr *hdr,
  797. struct ieee80211_tx_info *info, u8 ac)
  798. {
  799. __le16 fc = hdr->frame_control;
  800. if (info->band != IEEE80211_BAND_2GHZ)
  801. return 0;
  802. if (unlikely(mvm->bt_tx_prio))
  803. return mvm->bt_tx_prio - 1;
  804. /* High prio packet (wrt. BT coex) if it is EAPOL, MCAST or MGMT */
  805. if (info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO ||
  806. is_multicast_ether_addr(hdr->addr1) ||
  807. ieee80211_is_ctl(fc) || ieee80211_is_mgmt(fc) ||
  808. ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc))
  809. return 3;
  810. switch (ac) {
  811. case IEEE80211_AC_BE:
  812. return 1;
  813. case IEEE80211_AC_VO:
  814. return 3;
  815. case IEEE80211_AC_VI:
  816. return 2;
  817. default:
  818. break;
  819. }
  820. return 0;
  821. }
  822. void iwl_mvm_bt_coex_vif_change(struct iwl_mvm *mvm)
  823. {
  824. if (!fw_has_api(&mvm->fw->ucode_capa,
  825. IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
  826. iwl_mvm_bt_coex_vif_change_old(mvm);
  827. return;
  828. }
  829. iwl_mvm_bt_coex_notif_handle(mvm);
  830. }
  831. int iwl_mvm_rx_ant_coupling_notif(struct iwl_mvm *mvm,
  832. struct iwl_rx_cmd_buffer *rxb,
  833. struct iwl_device_cmd *dev_cmd)
  834. {
  835. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  836. u32 ant_isolation = le32_to_cpup((void *)pkt->data);
  837. struct iwl_bt_coex_corun_lut_update_cmd cmd = {};
  838. u8 __maybe_unused lower_bound, upper_bound;
  839. u8 lut;
  840. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  841. return iwl_mvm_rx_ant_coupling_notif_old(mvm, rxb, dev_cmd);
  842. if (!iwl_mvm_bt_is_plcr_supported(mvm))
  843. return 0;
  844. lockdep_assert_held(&mvm->mutex);
  845. /* Ignore updates if we are in force mode */
  846. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  847. return 0;
  848. if (ant_isolation == mvm->last_ant_isol)
  849. return 0;
  850. for (lut = 0; lut < ARRAY_SIZE(antenna_coupling_ranges) - 1; lut++)
  851. if (ant_isolation < antenna_coupling_ranges[lut + 1].range)
  852. break;
  853. lower_bound = antenna_coupling_ranges[lut].range;
  854. if (lut < ARRAY_SIZE(antenna_coupling_ranges) - 1)
  855. upper_bound = antenna_coupling_ranges[lut + 1].range;
  856. else
  857. upper_bound = antenna_coupling_ranges[lut].range;
  858. IWL_DEBUG_COEX(mvm, "Antenna isolation=%d in range [%d,%d[, lut=%d\n",
  859. ant_isolation, lower_bound, upper_bound, lut);
  860. mvm->last_ant_isol = ant_isolation;
  861. if (mvm->last_corun_lut == lut)
  862. return 0;
  863. mvm->last_corun_lut = lut;
  864. /* For the moment, use the same LUT for 20GHz and 40GHz */
  865. memcpy(&cmd.corun_lut20, antenna_coupling_ranges[lut].lut20,
  866. sizeof(cmd.corun_lut20));
  867. memcpy(&cmd.corun_lut40, antenna_coupling_ranges[lut].lut20,
  868. sizeof(cmd.corun_lut40));
  869. return iwl_mvm_send_cmd_pdu(mvm, BT_COEX_UPDATE_CORUN_LUT, 0,
  870. sizeof(cmd), &cmd);
  871. }