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