coex.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  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 - 2014 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 - 2014 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. #define BT_ANTENNA_COUPLING_THRESHOLD (30)
  73. const u32 iwl_bt_ctl_kill_msk[BT_KILL_MSK_MAX] = {
  74. [BT_KILL_MSK_DEFAULT] = 0xfffffc00,
  75. [BT_KILL_MSK_NEVER] = 0xffffffff,
  76. [BT_KILL_MSK_ALWAYS] = 0,
  77. };
  78. const u8 iwl_bt_cts_kill_msk[BT_MAX_AG][BT_COEX_MAX_LUT] = {
  79. {
  80. BT_KILL_MSK_ALWAYS,
  81. BT_KILL_MSK_ALWAYS,
  82. BT_KILL_MSK_ALWAYS,
  83. },
  84. {
  85. BT_KILL_MSK_NEVER,
  86. BT_KILL_MSK_NEVER,
  87. BT_KILL_MSK_NEVER,
  88. },
  89. {
  90. BT_KILL_MSK_NEVER,
  91. BT_KILL_MSK_NEVER,
  92. BT_KILL_MSK_NEVER,
  93. },
  94. {
  95. BT_KILL_MSK_DEFAULT,
  96. BT_KILL_MSK_NEVER,
  97. BT_KILL_MSK_DEFAULT,
  98. },
  99. };
  100. const u8 iwl_bt_ack_kill_msk[BT_MAX_AG][BT_COEX_MAX_LUT] = {
  101. {
  102. BT_KILL_MSK_ALWAYS,
  103. BT_KILL_MSK_ALWAYS,
  104. BT_KILL_MSK_ALWAYS,
  105. },
  106. {
  107. BT_KILL_MSK_ALWAYS,
  108. BT_KILL_MSK_ALWAYS,
  109. BT_KILL_MSK_ALWAYS,
  110. },
  111. {
  112. BT_KILL_MSK_ALWAYS,
  113. BT_KILL_MSK_ALWAYS,
  114. BT_KILL_MSK_ALWAYS,
  115. },
  116. {
  117. BT_KILL_MSK_DEFAULT,
  118. BT_KILL_MSK_ALWAYS,
  119. BT_KILL_MSK_DEFAULT,
  120. },
  121. };
  122. static const __le32 iwl_bt_prio_boost[BT_COEX_BOOST_SIZE] = {
  123. cpu_to_le32(0xf0f0f0f0), /* 50% */
  124. cpu_to_le32(0xc0c0c0c0), /* 25% */
  125. cpu_to_le32(0xfcfcfcfc), /* 75% */
  126. cpu_to_le32(0xfefefefe), /* 87.5% */
  127. };
  128. static const __le32 iwl_single_shared_ant[BT_COEX_MAX_LUT][BT_COEX_LUT_SIZE] = {
  129. {
  130. cpu_to_le32(0x40000000),
  131. cpu_to_le32(0x00000000),
  132. cpu_to_le32(0x44000000),
  133. cpu_to_le32(0x00000000),
  134. cpu_to_le32(0x40000000),
  135. cpu_to_le32(0x00000000),
  136. cpu_to_le32(0x44000000),
  137. cpu_to_le32(0x00000000),
  138. cpu_to_le32(0xc0004000),
  139. cpu_to_le32(0xf0005000),
  140. cpu_to_le32(0xc0004000),
  141. cpu_to_le32(0xf0005000),
  142. },
  143. {
  144. cpu_to_le32(0x40000000),
  145. cpu_to_le32(0x00000000),
  146. cpu_to_le32(0x44000000),
  147. cpu_to_le32(0x00000000),
  148. cpu_to_le32(0x40000000),
  149. cpu_to_le32(0x00000000),
  150. cpu_to_le32(0x44000000),
  151. cpu_to_le32(0x00000000),
  152. cpu_to_le32(0xc0004000),
  153. cpu_to_le32(0xf0005000),
  154. cpu_to_le32(0xc0004000),
  155. cpu_to_le32(0xf0005000),
  156. },
  157. {
  158. cpu_to_le32(0x40000000),
  159. cpu_to_le32(0x00000000),
  160. cpu_to_le32(0x44000000),
  161. cpu_to_le32(0x00000000),
  162. cpu_to_le32(0x40000000),
  163. cpu_to_le32(0x00000000),
  164. cpu_to_le32(0x44000000),
  165. cpu_to_le32(0x00000000),
  166. cpu_to_le32(0xc0004000),
  167. cpu_to_le32(0xf0005000),
  168. cpu_to_le32(0xc0004000),
  169. cpu_to_le32(0xf0005000),
  170. },
  171. };
  172. static const __le32 iwl_combined_lookup[BT_COEX_MAX_LUT][BT_COEX_LUT_SIZE] = {
  173. {
  174. /* Tight */
  175. cpu_to_le32(0xaaaaaaaa),
  176. cpu_to_le32(0xaaaaaaaa),
  177. cpu_to_le32(0xaeaaaaaa),
  178. cpu_to_le32(0xaaaaaaaa),
  179. cpu_to_le32(0xcc00ff28),
  180. cpu_to_le32(0x0000aaaa),
  181. cpu_to_le32(0xcc00aaaa),
  182. cpu_to_le32(0x0000aaaa),
  183. cpu_to_le32(0xc0004000),
  184. cpu_to_le32(0x00004000),
  185. cpu_to_le32(0xf0005000),
  186. cpu_to_le32(0xf0005000),
  187. },
  188. {
  189. /* Loose */
  190. cpu_to_le32(0xaaaaaaaa),
  191. cpu_to_le32(0xaaaaaaaa),
  192. cpu_to_le32(0xaaaaaaaa),
  193. cpu_to_le32(0xaaaaaaaa),
  194. cpu_to_le32(0xcc00ff28),
  195. cpu_to_le32(0x0000aaaa),
  196. cpu_to_le32(0xcc00aaaa),
  197. cpu_to_le32(0x0000aaaa),
  198. cpu_to_le32(0x00000000),
  199. cpu_to_le32(0x00000000),
  200. cpu_to_le32(0xf0005000),
  201. cpu_to_le32(0xf0005000),
  202. },
  203. {
  204. /* Tx Tx disabled */
  205. cpu_to_le32(0xaaaaaaaa),
  206. cpu_to_le32(0xaaaaaaaa),
  207. cpu_to_le32(0xeeaaaaaa),
  208. cpu_to_le32(0xaaaaaaaa),
  209. cpu_to_le32(0xcc00ff28),
  210. cpu_to_le32(0x0000aaaa),
  211. cpu_to_le32(0xcc00aaaa),
  212. cpu_to_le32(0x0000aaaa),
  213. cpu_to_le32(0xc0004000),
  214. cpu_to_le32(0xc0004000),
  215. cpu_to_le32(0xf0005000),
  216. cpu_to_le32(0xf0005000),
  217. },
  218. };
  219. /* 20MHz / 40MHz below / 40Mhz above*/
  220. static const __le64 iwl_ci_mask[][3] = {
  221. /* dummy entry for channel 0 */
  222. {cpu_to_le64(0), cpu_to_le64(0), cpu_to_le64(0)},
  223. {
  224. cpu_to_le64(0x0000001FFFULL),
  225. cpu_to_le64(0x0ULL),
  226. cpu_to_le64(0x00007FFFFFULL),
  227. },
  228. {
  229. cpu_to_le64(0x000000FFFFULL),
  230. cpu_to_le64(0x0ULL),
  231. cpu_to_le64(0x0003FFFFFFULL),
  232. },
  233. {
  234. cpu_to_le64(0x000003FFFCULL),
  235. cpu_to_le64(0x0ULL),
  236. cpu_to_le64(0x000FFFFFFCULL),
  237. },
  238. {
  239. cpu_to_le64(0x00001FFFE0ULL),
  240. cpu_to_le64(0x0ULL),
  241. cpu_to_le64(0x007FFFFFE0ULL),
  242. },
  243. {
  244. cpu_to_le64(0x00007FFF80ULL),
  245. cpu_to_le64(0x00007FFFFFULL),
  246. cpu_to_le64(0x01FFFFFF80ULL),
  247. },
  248. {
  249. cpu_to_le64(0x0003FFFC00ULL),
  250. cpu_to_le64(0x0003FFFFFFULL),
  251. cpu_to_le64(0x0FFFFFFC00ULL),
  252. },
  253. {
  254. cpu_to_le64(0x000FFFF000ULL),
  255. cpu_to_le64(0x000FFFFFFCULL),
  256. cpu_to_le64(0x3FFFFFF000ULL),
  257. },
  258. {
  259. cpu_to_le64(0x007FFF8000ULL),
  260. cpu_to_le64(0x007FFFFFE0ULL),
  261. cpu_to_le64(0xFFFFFF8000ULL),
  262. },
  263. {
  264. cpu_to_le64(0x01FFFE0000ULL),
  265. cpu_to_le64(0x01FFFFFF80ULL),
  266. cpu_to_le64(0xFFFFFE0000ULL),
  267. },
  268. {
  269. cpu_to_le64(0x0FFFF00000ULL),
  270. cpu_to_le64(0x0FFFFFFC00ULL),
  271. cpu_to_le64(0x0ULL),
  272. },
  273. {
  274. cpu_to_le64(0x3FFFC00000ULL),
  275. cpu_to_le64(0x3FFFFFF000ULL),
  276. cpu_to_le64(0x0)
  277. },
  278. {
  279. cpu_to_le64(0xFFFE000000ULL),
  280. cpu_to_le64(0xFFFFFF8000ULL),
  281. cpu_to_le64(0x0)
  282. },
  283. {
  284. cpu_to_le64(0xFFF8000000ULL),
  285. cpu_to_le64(0xFFFFFE0000ULL),
  286. cpu_to_le64(0x0)
  287. },
  288. {
  289. cpu_to_le64(0xFFC0000000ULL),
  290. cpu_to_le64(0x0ULL),
  291. cpu_to_le64(0x0ULL)
  292. },
  293. };
  294. static const __le32 iwl_bt_mprio_lut[BT_COEX_MULTI_PRIO_LUT_SIZE] = {
  295. cpu_to_le32(0x2e402280),
  296. cpu_to_le32(0x7711a751),
  297. };
  298. struct corunning_block_luts {
  299. u8 range;
  300. __le32 lut20[BT_COEX_CORUN_LUT_SIZE];
  301. };
  302. /*
  303. * Ranges for the antenna coupling calibration / co-running block LUT:
  304. * LUT0: [ 0, 12[
  305. * LUT1: [12, 20[
  306. * LUT2: [20, 21[
  307. * LUT3: [21, 23[
  308. * LUT4: [23, 27[
  309. * LUT5: [27, 30[
  310. * LUT6: [30, 32[
  311. * LUT7: [32, 33[
  312. * LUT8: [33, - [
  313. */
  314. static const struct corunning_block_luts antenna_coupling_ranges[] = {
  315. {
  316. .range = 0,
  317. .lut20 = {
  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. 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. },
  335. },
  336. {
  337. .range = 12,
  338. .lut20 = {
  339. cpu_to_le32(0x00000001), 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. 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. },
  356. },
  357. {
  358. .range = 20,
  359. .lut20 = {
  360. cpu_to_le32(0x00000002), cpu_to_le32(0x00000000),
  361. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  362. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  363. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  364. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  365. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  366. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  367. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  368. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  369. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  370. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  371. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  372. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  373. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  374. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  375. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  376. },
  377. },
  378. {
  379. .range = 21,
  380. .lut20 = {
  381. cpu_to_le32(0x00000003), cpu_to_le32(0x00000000),
  382. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  383. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  384. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  385. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  386. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  387. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  388. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  389. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  390. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  391. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  392. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  393. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  394. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  395. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  396. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  397. },
  398. },
  399. {
  400. .range = 23,
  401. .lut20 = {
  402. cpu_to_le32(0x00000004), cpu_to_le32(0x00000000),
  403. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  404. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  405. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  406. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  407. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  408. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  409. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  410. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  411. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  412. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  413. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  414. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  415. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  416. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  417. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  418. },
  419. },
  420. {
  421. .range = 27,
  422. .lut20 = {
  423. cpu_to_le32(0x00000005), cpu_to_le32(0x00000000),
  424. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  425. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  426. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  427. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  428. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  429. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  430. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  431. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  432. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  433. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  434. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  435. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  436. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  437. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  438. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  439. },
  440. },
  441. {
  442. .range = 30,
  443. .lut20 = {
  444. cpu_to_le32(0x00000006), cpu_to_le32(0x00000000),
  445. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  446. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  447. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  448. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  449. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  450. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  451. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  452. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  453. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  454. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  455. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  456. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  457. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  458. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  459. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  460. },
  461. },
  462. {
  463. .range = 32,
  464. .lut20 = {
  465. cpu_to_le32(0x00000007), cpu_to_le32(0x00000000),
  466. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  467. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  468. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  469. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  470. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  471. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  472. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  473. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  474. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  475. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  476. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  477. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  478. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  479. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  480. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  481. },
  482. },
  483. {
  484. .range = 33,
  485. .lut20 = {
  486. cpu_to_le32(0x00000008), cpu_to_le32(0x00000000),
  487. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  488. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  489. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  490. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  491. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  492. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  493. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  494. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  495. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  496. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  497. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  498. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  499. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  500. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  501. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  502. },
  503. },
  504. };
  505. static enum iwl_bt_coex_lut_type
  506. iwl_get_coex_type(struct iwl_mvm *mvm, const struct ieee80211_vif *vif)
  507. {
  508. struct ieee80211_chanctx_conf *chanctx_conf;
  509. enum iwl_bt_coex_lut_type ret;
  510. u16 phy_ctx_id;
  511. u32 primary_ch_phy_id, secondary_ch_phy_id;
  512. /*
  513. * Checking that we hold mvm->mutex is a good idea, but the rate
  514. * control can't acquire the mutex since it runs in Tx path.
  515. * So this is racy in that case, but in the worst case, the AMPDU
  516. * size limit will be wrong for a short time which is not a big
  517. * issue.
  518. */
  519. rcu_read_lock();
  520. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  521. if (!chanctx_conf ||
  522. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ) {
  523. rcu_read_unlock();
  524. return BT_COEX_INVALID_LUT;
  525. }
  526. ret = BT_COEX_TX_DIS_LUT;
  527. if (mvm->cfg->bt_shared_single_ant) {
  528. rcu_read_unlock();
  529. return ret;
  530. }
  531. phy_ctx_id = *((u16 *)chanctx_conf->drv_priv);
  532. primary_ch_phy_id = le32_to_cpu(mvm->last_bt_ci_cmd.primary_ch_phy_id);
  533. secondary_ch_phy_id =
  534. le32_to_cpu(mvm->last_bt_ci_cmd.secondary_ch_phy_id);
  535. if (primary_ch_phy_id == phy_ctx_id)
  536. ret = le32_to_cpu(mvm->last_bt_notif.primary_ch_lut);
  537. else if (secondary_ch_phy_id == phy_ctx_id)
  538. ret = le32_to_cpu(mvm->last_bt_notif.secondary_ch_lut);
  539. /* else - default = TX TX disallowed */
  540. rcu_read_unlock();
  541. return ret;
  542. }
  543. int iwl_send_bt_init_conf(struct iwl_mvm *mvm)
  544. {
  545. struct iwl_bt_coex_cmd *bt_cmd;
  546. struct iwl_host_cmd cmd = {
  547. .id = BT_CONFIG,
  548. .len = { sizeof(*bt_cmd), },
  549. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  550. };
  551. int ret;
  552. u32 mode;
  553. if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  554. return iwl_send_bt_init_conf_old(mvm);
  555. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  556. if (!bt_cmd)
  557. return -ENOMEM;
  558. cmd.data[0] = bt_cmd;
  559. lockdep_assert_held(&mvm->mutex);
  560. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) {
  561. switch (mvm->bt_force_ant_mode) {
  562. case BT_FORCE_ANT_BT:
  563. mode = BT_COEX_BT;
  564. break;
  565. case BT_FORCE_ANT_WIFI:
  566. mode = BT_COEX_WIFI;
  567. break;
  568. default:
  569. WARN_ON(1);
  570. mode = 0;
  571. }
  572. bt_cmd->mode = cpu_to_le32(mode);
  573. goto send_cmd;
  574. }
  575. bt_cmd->max_kill = cpu_to_le32(5);
  576. bt_cmd->bt4_antenna_isolation_thr =
  577. cpu_to_le32(BT_ANTENNA_COUPLING_THRESHOLD);
  578. bt_cmd->bt4_tx_tx_delta_freq_thr = cpu_to_le32(15);
  579. bt_cmd->bt4_tx_rx_max_freq0 = cpu_to_le32(15);
  580. bt_cmd->override_primary_lut = cpu_to_le32(BT_COEX_INVALID_LUT);
  581. bt_cmd->override_secondary_lut = cpu_to_le32(BT_COEX_INVALID_LUT);
  582. mode = iwlwifi_mod_params.bt_coex_active ? BT_COEX_NW : BT_COEX_DISABLE;
  583. bt_cmd->mode = cpu_to_le32(mode);
  584. if (IWL_MVM_BT_COEX_SYNC2SCO)
  585. bt_cmd->enabled_modules |=
  586. cpu_to_le32(BT_COEX_SYNC2SCO_ENABLED);
  587. if (IWL_MVM_BT_COEX_CORUNNING)
  588. bt_cmd->enabled_modules |= cpu_to_le32(BT_COEX_CORUN_ENABLED);
  589. if (IWL_MVM_BT_COEX_MPLUT) {
  590. bt_cmd->enabled_modules |= cpu_to_le32(BT_COEX_MPLUT_ENABLED);
  591. bt_cmd->enabled_modules |=
  592. cpu_to_le32(BT_COEX_MPLUT_BOOST_ENABLED);
  593. }
  594. bt_cmd->enabled_modules |= cpu_to_le32(BT_COEX_HIGH_BAND_RET);
  595. if (mvm->cfg->bt_shared_single_ant)
  596. memcpy(&bt_cmd->decision_lut, iwl_single_shared_ant,
  597. sizeof(iwl_single_shared_ant));
  598. else
  599. memcpy(&bt_cmd->decision_lut, iwl_combined_lookup,
  600. sizeof(iwl_combined_lookup));
  601. memcpy(&bt_cmd->mplut_prio_boost, iwl_bt_prio_boost,
  602. sizeof(iwl_bt_prio_boost));
  603. memcpy(&bt_cmd->multiprio_lut, iwl_bt_mprio_lut,
  604. sizeof(iwl_bt_mprio_lut));
  605. send_cmd:
  606. memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
  607. memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
  608. ret = iwl_mvm_send_cmd(mvm, &cmd);
  609. kfree(bt_cmd);
  610. return ret;
  611. }
  612. static int iwl_mvm_bt_udpate_sw_boost(struct iwl_mvm *mvm)
  613. {
  614. struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
  615. u32 primary_lut = le32_to_cpu(notif->primary_ch_lut);
  616. u32 secondary_lut = le32_to_cpu(notif->secondary_ch_lut);
  617. u32 ag = le32_to_cpu(notif->bt_activity_grading);
  618. struct iwl_bt_coex_sw_boost_update_cmd cmd = {};
  619. u8 ack_kill_msk[NUM_PHY_CTX] = {};
  620. u8 cts_kill_msk[NUM_PHY_CTX] = {};
  621. int i;
  622. lockdep_assert_held(&mvm->mutex);
  623. ack_kill_msk[0] = iwl_bt_ack_kill_msk[ag][primary_lut];
  624. cts_kill_msk[0] = iwl_bt_cts_kill_msk[ag][primary_lut];
  625. ack_kill_msk[1] = iwl_bt_ack_kill_msk[ag][secondary_lut];
  626. cts_kill_msk[1] = iwl_bt_cts_kill_msk[ag][secondary_lut];
  627. /* Don't send HCMD if there is no update */
  628. if (!memcmp(ack_kill_msk, mvm->bt_ack_kill_msk, sizeof(ack_kill_msk)) ||
  629. !memcmp(cts_kill_msk, mvm->bt_cts_kill_msk, sizeof(cts_kill_msk)))
  630. return 0;
  631. memcpy(mvm->bt_ack_kill_msk, ack_kill_msk,
  632. sizeof(mvm->bt_ack_kill_msk));
  633. memcpy(mvm->bt_cts_kill_msk, cts_kill_msk,
  634. sizeof(mvm->bt_cts_kill_msk));
  635. BUILD_BUG_ON(ARRAY_SIZE(ack_kill_msk) < ARRAY_SIZE(cmd.boost_values));
  636. for (i = 0; i < ARRAY_SIZE(cmd.boost_values); i++) {
  637. cmd.boost_values[i].kill_ack_msk =
  638. cpu_to_le32(iwl_bt_ctl_kill_msk[ack_kill_msk[i]]);
  639. cmd.boost_values[i].kill_cts_msk =
  640. cpu_to_le32(iwl_bt_ctl_kill_msk[cts_kill_msk[i]]);
  641. }
  642. return iwl_mvm_send_cmd_pdu(mvm, BT_COEX_UPDATE_SW_BOOST, 0,
  643. sizeof(cmd), &cmd);
  644. }
  645. static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id,
  646. bool enable)
  647. {
  648. struct iwl_bt_coex_reduced_txp_update_cmd cmd = {};
  649. struct iwl_mvm_sta *mvmsta;
  650. u32 value;
  651. int ret;
  652. mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
  653. if (!mvmsta)
  654. return 0;
  655. /* nothing to do */
  656. if (mvmsta->bt_reduced_txpower == enable)
  657. return 0;
  658. value = mvmsta->sta_id;
  659. if (enable)
  660. value |= BT_REDUCED_TX_POWER_BIT;
  661. IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n",
  662. enable ? "en" : "dis", sta_id);
  663. cmd.reduced_txp = cpu_to_le32(value);
  664. mvmsta->bt_reduced_txpower = enable;
  665. ret = iwl_mvm_send_cmd_pdu(mvm, BT_COEX_UPDATE_REDUCED_TXP, CMD_ASYNC,
  666. sizeof(cmd), &cmd);
  667. return ret;
  668. }
  669. struct iwl_bt_iterator_data {
  670. struct iwl_bt_coex_profile_notif *notif;
  671. struct iwl_mvm *mvm;
  672. struct ieee80211_chanctx_conf *primary;
  673. struct ieee80211_chanctx_conf *secondary;
  674. bool primary_ll;
  675. };
  676. static inline
  677. void iwl_mvm_bt_coex_enable_rssi_event(struct iwl_mvm *mvm,
  678. struct ieee80211_vif *vif,
  679. bool enable, int rssi)
  680. {
  681. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  682. mvmvif->bf_data.last_bt_coex_event = rssi;
  683. mvmvif->bf_data.bt_coex_max_thold =
  684. enable ? -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH : 0;
  685. mvmvif->bf_data.bt_coex_min_thold =
  686. enable ? -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH : 0;
  687. }
  688. /* must be called under rcu_read_lock */
  689. static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac,
  690. struct ieee80211_vif *vif)
  691. {
  692. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  693. struct iwl_bt_iterator_data *data = _data;
  694. struct iwl_mvm *mvm = data->mvm;
  695. struct ieee80211_chanctx_conf *chanctx_conf;
  696. /* default smps_mode is AUTOMATIC - only used for client modes */
  697. enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_AUTOMATIC;
  698. u32 bt_activity_grading;
  699. int ave_rssi;
  700. lockdep_assert_held(&mvm->mutex);
  701. switch (vif->type) {
  702. case NL80211_IFTYPE_STATION:
  703. break;
  704. case NL80211_IFTYPE_AP:
  705. if (!mvmvif->ap_ibss_active)
  706. return;
  707. break;
  708. default:
  709. return;
  710. }
  711. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  712. /* If channel context is invalid or not on 2.4GHz .. */
  713. if ((!chanctx_conf ||
  714. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ)) {
  715. if (vif->type == NL80211_IFTYPE_STATION) {
  716. /* ... relax constraints and disable rssi events */
  717. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  718. smps_mode);
  719. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  720. false);
  721. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  722. }
  723. return;
  724. }
  725. bt_activity_grading = le32_to_cpu(data->notif->bt_activity_grading);
  726. if (bt_activity_grading >= BT_HIGH_TRAFFIC)
  727. smps_mode = IEEE80211_SMPS_STATIC;
  728. else if (bt_activity_grading >= BT_LOW_TRAFFIC)
  729. smps_mode = IEEE80211_SMPS_DYNAMIC;
  730. /* relax SMPS constraints for next association */
  731. if (!vif->bss_conf.assoc)
  732. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  733. if (IWL_COEX_IS_RRC_ON(mvm->last_bt_notif.ttc_rrc_status,
  734. mvmvif->phy_ctxt->id))
  735. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  736. IWL_DEBUG_COEX(data->mvm,
  737. "mac %d: bt_activity_grading %d smps_req %d\n",
  738. mvmvif->id, bt_activity_grading, smps_mode);
  739. if (vif->type == NL80211_IFTYPE_STATION)
  740. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  741. smps_mode);
  742. /* low latency is always primary */
  743. if (iwl_mvm_vif_low_latency(mvmvif)) {
  744. data->primary_ll = true;
  745. data->secondary = data->primary;
  746. data->primary = chanctx_conf;
  747. }
  748. if (vif->type == NL80211_IFTYPE_AP) {
  749. if (!mvmvif->ap_ibss_active)
  750. return;
  751. if (chanctx_conf == data->primary)
  752. return;
  753. if (!data->primary_ll) {
  754. /*
  755. * downgrade the current primary no matter what its
  756. * type is.
  757. */
  758. data->secondary = data->primary;
  759. data->primary = chanctx_conf;
  760. } else {
  761. /* there is low latency vif - we will be secondary */
  762. data->secondary = chanctx_conf;
  763. }
  764. return;
  765. }
  766. /*
  767. * STA / P2P Client, try to be primary if first vif. If we are in low
  768. * latency mode, we are already in primary and just don't do much
  769. */
  770. if (!data->primary || data->primary == chanctx_conf)
  771. data->primary = chanctx_conf;
  772. else if (!data->secondary)
  773. /* if secondary is not NULL, it might be a GO */
  774. data->secondary = chanctx_conf;
  775. /*
  776. * don't reduce the Tx power if one of these is true:
  777. * we are in LOOSE
  778. * single share antenna product
  779. * BT is active
  780. * we are associated
  781. */
  782. if (iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT ||
  783. mvm->cfg->bt_shared_single_ant || !vif->bss_conf.assoc ||
  784. le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF) {
  785. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false);
  786. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  787. return;
  788. }
  789. /* try to get the avg rssi from fw */
  790. ave_rssi = mvmvif->bf_data.ave_beacon_signal;
  791. /* if the RSSI isn't valid, fake it is very low */
  792. if (!ave_rssi)
  793. ave_rssi = -100;
  794. if (ave_rssi > -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH) {
  795. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true))
  796. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  797. } else if (ave_rssi < -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH) {
  798. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
  799. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  800. }
  801. /* Begin to monitor the RSSI: it may influence the reduced Tx power */
  802. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, true, ave_rssi);
  803. }
  804. static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm)
  805. {
  806. struct iwl_bt_iterator_data data = {
  807. .mvm = mvm,
  808. .notif = &mvm->last_bt_notif,
  809. };
  810. struct iwl_bt_coex_ci_cmd cmd = {};
  811. u8 ci_bw_idx;
  812. /* Ignore updates if we are in force mode */
  813. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  814. return;
  815. rcu_read_lock();
  816. ieee80211_iterate_active_interfaces_atomic(
  817. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  818. iwl_mvm_bt_notif_iterator, &data);
  819. if (data.primary) {
  820. struct ieee80211_chanctx_conf *chan = data.primary;
  821. if (WARN_ON(!chan->def.chan)) {
  822. rcu_read_unlock();
  823. return;
  824. }
  825. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  826. ci_bw_idx = 0;
  827. } else {
  828. if (chan->def.center_freq1 >
  829. chan->def.chan->center_freq)
  830. ci_bw_idx = 2;
  831. else
  832. ci_bw_idx = 1;
  833. }
  834. cmd.bt_primary_ci =
  835. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  836. cmd.primary_ch_phy_id =
  837. cpu_to_le32(*((u16 *)data.primary->drv_priv));
  838. }
  839. if (data.secondary) {
  840. struct ieee80211_chanctx_conf *chan = data.secondary;
  841. if (WARN_ON(!data.secondary->def.chan)) {
  842. rcu_read_unlock();
  843. return;
  844. }
  845. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  846. ci_bw_idx = 0;
  847. } else {
  848. if (chan->def.center_freq1 >
  849. chan->def.chan->center_freq)
  850. ci_bw_idx = 2;
  851. else
  852. ci_bw_idx = 1;
  853. }
  854. cmd.bt_secondary_ci =
  855. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  856. cmd.secondary_ch_phy_id =
  857. cpu_to_le32(*((u16 *)data.secondary->drv_priv));
  858. }
  859. rcu_read_unlock();
  860. /* Don't spam the fw with the same command over and over */
  861. if (memcmp(&cmd, &mvm->last_bt_ci_cmd, sizeof(cmd))) {
  862. if (iwl_mvm_send_cmd_pdu(mvm, BT_COEX_CI, 0,
  863. sizeof(cmd), &cmd))
  864. IWL_ERR(mvm, "Failed to send BT_CI cmd\n");
  865. memcpy(&mvm->last_bt_ci_cmd, &cmd, sizeof(cmd));
  866. }
  867. if (iwl_mvm_bt_udpate_sw_boost(mvm))
  868. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  869. }
  870. int iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm,
  871. struct iwl_rx_cmd_buffer *rxb,
  872. struct iwl_device_cmd *dev_cmd)
  873. {
  874. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  875. struct iwl_bt_coex_profile_notif *notif = (void *)pkt->data;
  876. if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  877. return iwl_mvm_rx_bt_coex_notif_old(mvm, rxb, dev_cmd);
  878. IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n");
  879. IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n", notif->bt_ci_compliance);
  880. IWL_DEBUG_COEX(mvm, "\tBT primary_ch_lut %d\n",
  881. le32_to_cpu(notif->primary_ch_lut));
  882. IWL_DEBUG_COEX(mvm, "\tBT secondary_ch_lut %d\n",
  883. le32_to_cpu(notif->secondary_ch_lut));
  884. IWL_DEBUG_COEX(mvm, "\tBT activity grading %d\n",
  885. le32_to_cpu(notif->bt_activity_grading));
  886. /* remember this notification for future use: rssi fluctuations */
  887. memcpy(&mvm->last_bt_notif, notif, sizeof(mvm->last_bt_notif));
  888. iwl_mvm_bt_coex_notif_handle(mvm);
  889. /*
  890. * This is an async handler for a notification, returning anything other
  891. * than 0 doesn't make sense even if HCMD failed.
  892. */
  893. return 0;
  894. }
  895. static void iwl_mvm_bt_rssi_iterator(void *_data, u8 *mac,
  896. struct ieee80211_vif *vif)
  897. {
  898. struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv;
  899. struct iwl_bt_iterator_data *data = _data;
  900. struct iwl_mvm *mvm = data->mvm;
  901. struct ieee80211_sta *sta;
  902. struct iwl_mvm_sta *mvmsta;
  903. struct ieee80211_chanctx_conf *chanctx_conf;
  904. rcu_read_lock();
  905. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  906. /* If channel context is invalid or not on 2.4GHz - don't count it */
  907. if (!chanctx_conf ||
  908. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ) {
  909. rcu_read_unlock();
  910. return;
  911. }
  912. rcu_read_unlock();
  913. if (vif->type != NL80211_IFTYPE_STATION ||
  914. mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  915. return;
  916. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
  917. lockdep_is_held(&mvm->mutex));
  918. /* This can happen if the station has been removed right now */
  919. if (IS_ERR_OR_NULL(sta))
  920. return;
  921. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  922. }
  923. void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  924. enum ieee80211_rssi_event rssi_event)
  925. {
  926. struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv;
  927. struct iwl_bt_iterator_data data = {
  928. .mvm = mvm,
  929. };
  930. int ret;
  931. if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
  932. iwl_mvm_bt_rssi_event_old(mvm, vif, rssi_event);
  933. return;
  934. }
  935. lockdep_assert_held(&mvm->mutex);
  936. /* Ignore updates if we are in force mode */
  937. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  938. return;
  939. /*
  940. * Rssi update while not associated - can happen since the statistics
  941. * are handled asynchronously
  942. */
  943. if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  944. return;
  945. /* No BT - reports should be disabled */
  946. if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF)
  947. return;
  948. IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid,
  949. rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW");
  950. /*
  951. * Check if rssi is good enough for reduced Tx power, but not in loose
  952. * scheme.
  953. */
  954. if (rssi_event == RSSI_EVENT_LOW || mvm->cfg->bt_shared_single_ant ||
  955. iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT)
  956. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  957. false);
  958. else
  959. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true);
  960. if (ret)
  961. IWL_ERR(mvm, "couldn't send BT_CONFIG HCMD upon RSSI event\n");
  962. ieee80211_iterate_active_interfaces_atomic(
  963. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  964. iwl_mvm_bt_rssi_iterator, &data);
  965. if (iwl_mvm_bt_udpate_sw_boost(mvm))
  966. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  967. }
  968. #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000)
  969. #define LINK_QUAL_AGG_TIME_LIMIT_BT_ACT (1200)
  970. u16 iwl_mvm_coex_agg_time_limit(struct iwl_mvm *mvm,
  971. struct ieee80211_sta *sta)
  972. {
  973. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  974. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
  975. struct iwl_mvm_phy_ctxt *phy_ctxt = mvmvif->phy_ctxt;
  976. enum iwl_bt_coex_lut_type lut_type;
  977. if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  978. return iwl_mvm_coex_agg_time_limit_old(mvm, sta);
  979. if (IWL_COEX_IS_TTC_ON(mvm->last_bt_notif.ttc_rrc_status, phy_ctxt->id))
  980. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  981. if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) <
  982. BT_HIGH_TRAFFIC)
  983. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  984. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  985. if (lut_type == BT_COEX_LOOSE_LUT || lut_type == BT_COEX_INVALID_LUT)
  986. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  987. /* tight coex, high bt traffic, reduce AGG time limit */
  988. return LINK_QUAL_AGG_TIME_LIMIT_BT_ACT;
  989. }
  990. bool iwl_mvm_bt_coex_is_mimo_allowed(struct iwl_mvm *mvm,
  991. struct ieee80211_sta *sta)
  992. {
  993. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  994. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
  995. struct iwl_mvm_phy_ctxt *phy_ctxt = mvmvif->phy_ctxt;
  996. enum iwl_bt_coex_lut_type lut_type;
  997. if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  998. return iwl_mvm_bt_coex_is_mimo_allowed_old(mvm, sta);
  999. if (IWL_COEX_IS_TTC_ON(mvm->last_bt_notif.ttc_rrc_status, phy_ctxt->id))
  1000. return true;
  1001. if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) <
  1002. BT_HIGH_TRAFFIC)
  1003. return true;
  1004. /*
  1005. * In Tight / TxTxDis, BT can't Rx while we Tx, so use both antennas
  1006. * since BT is already killed.
  1007. * In Loose, BT can Rx while we Tx, so forbid MIMO to let BT Rx while
  1008. * we Tx.
  1009. * When we are in 5GHz, we'll get BT_COEX_INVALID_LUT allowing MIMO.
  1010. */
  1011. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  1012. return lut_type != BT_COEX_LOOSE_LUT;
  1013. }
  1014. bool iwl_mvm_bt_coex_is_shared_ant_avail(struct iwl_mvm *mvm)
  1015. {
  1016. /* there is no other antenna, shared antenna is always available */
  1017. if (mvm->cfg->bt_shared_single_ant)
  1018. return true;
  1019. if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  1020. return iwl_mvm_bt_coex_is_shared_ant_avail_old(mvm);
  1021. return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF;
  1022. }
  1023. bool iwl_mvm_bt_coex_is_tpc_allowed(struct iwl_mvm *mvm,
  1024. enum ieee80211_band band)
  1025. {
  1026. u32 bt_activity = le32_to_cpu(mvm->last_bt_notif.bt_activity_grading);
  1027. if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  1028. return iwl_mvm_bt_coex_is_tpc_allowed_old(mvm, band);
  1029. if (band != IEEE80211_BAND_2GHZ)
  1030. return false;
  1031. return bt_activity >= BT_LOW_TRAFFIC;
  1032. }
  1033. u8 iwl_mvm_bt_coex_tx_prio(struct iwl_mvm *mvm, struct ieee80211_hdr *hdr,
  1034. struct ieee80211_tx_info *info, u8 ac)
  1035. {
  1036. __le16 fc = hdr->frame_control;
  1037. if (info->band != IEEE80211_BAND_2GHZ)
  1038. return 0;
  1039. if (unlikely(mvm->bt_tx_prio))
  1040. return mvm->bt_tx_prio - 1;
  1041. /* High prio packet (wrt. BT coex) if it is EAPOL, MCAST or MGMT */
  1042. if (info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO ||
  1043. is_multicast_ether_addr(hdr->addr1) ||
  1044. ieee80211_is_ctl(fc) || ieee80211_is_mgmt(fc) ||
  1045. ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc))
  1046. return 3;
  1047. switch (ac) {
  1048. case IEEE80211_AC_BE:
  1049. return 1;
  1050. case IEEE80211_AC_VO:
  1051. return 3;
  1052. case IEEE80211_AC_VI:
  1053. return 2;
  1054. default:
  1055. break;
  1056. }
  1057. return 0;
  1058. }
  1059. void iwl_mvm_bt_coex_vif_change(struct iwl_mvm *mvm)
  1060. {
  1061. if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
  1062. iwl_mvm_bt_coex_vif_change_old(mvm);
  1063. return;
  1064. }
  1065. iwl_mvm_bt_coex_notif_handle(mvm);
  1066. }
  1067. int iwl_mvm_rx_ant_coupling_notif(struct iwl_mvm *mvm,
  1068. struct iwl_rx_cmd_buffer *rxb,
  1069. struct iwl_device_cmd *dev_cmd)
  1070. {
  1071. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1072. u32 ant_isolation = le32_to_cpup((void *)pkt->data);
  1073. struct iwl_bt_coex_corun_lut_update_cmd cmd = {};
  1074. u8 __maybe_unused lower_bound, upper_bound;
  1075. u8 lut;
  1076. if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  1077. return iwl_mvm_rx_ant_coupling_notif_old(mvm, rxb, dev_cmd);
  1078. if (!IWL_MVM_BT_COEX_CORUNNING)
  1079. return 0;
  1080. lockdep_assert_held(&mvm->mutex);
  1081. /* Ignore updates if we are in force mode */
  1082. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  1083. return 0;
  1084. if (ant_isolation == mvm->last_ant_isol)
  1085. return 0;
  1086. for (lut = 0; lut < ARRAY_SIZE(antenna_coupling_ranges) - 1; lut++)
  1087. if (ant_isolation < antenna_coupling_ranges[lut + 1].range)
  1088. break;
  1089. lower_bound = antenna_coupling_ranges[lut].range;
  1090. if (lut < ARRAY_SIZE(antenna_coupling_ranges) - 1)
  1091. upper_bound = antenna_coupling_ranges[lut + 1].range;
  1092. else
  1093. upper_bound = antenna_coupling_ranges[lut].range;
  1094. IWL_DEBUG_COEX(mvm, "Antenna isolation=%d in range [%d,%d[, lut=%d\n",
  1095. ant_isolation, lower_bound, upper_bound, lut);
  1096. mvm->last_ant_isol = ant_isolation;
  1097. if (mvm->last_corun_lut == lut)
  1098. return 0;
  1099. mvm->last_corun_lut = lut;
  1100. /* For the moment, use the same LUT for 20GHz and 40GHz */
  1101. memcpy(&cmd.corun_lut20, antenna_coupling_ranges[lut].lut20,
  1102. sizeof(cmd.corun_lut20));
  1103. memcpy(&cmd.corun_lut40, antenna_coupling_ranges[lut].lut20,
  1104. sizeof(cmd.corun_lut40));
  1105. return iwl_mvm_send_cmd_pdu(mvm, BT_COEX_UPDATE_CORUN_LUT, 0,
  1106. sizeof(cmd), &cmd);
  1107. }