coex.c 38 KB

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