coex_legacy.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  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. enum iwl_bt_kill_msk {
  280. BT_KILL_MSK_DEFAULT,
  281. BT_KILL_MSK_NEVER,
  282. BT_KILL_MSK_ALWAYS,
  283. BT_KILL_MSK_MAX,
  284. };
  285. static const u32 iwl_bt_ctl_kill_msk[BT_KILL_MSK_MAX] = {
  286. [BT_KILL_MSK_DEFAULT] = 0xfffffc00,
  287. [BT_KILL_MSK_NEVER] = 0xffffffff,
  288. [BT_KILL_MSK_ALWAYS] = 0,
  289. };
  290. static const u8 iwl_bt_cts_kill_msk[BT_MAX_AG][BT_COEX_MAX_LUT] = {
  291. {
  292. BT_KILL_MSK_ALWAYS,
  293. BT_KILL_MSK_ALWAYS,
  294. BT_KILL_MSK_ALWAYS,
  295. },
  296. {
  297. BT_KILL_MSK_NEVER,
  298. BT_KILL_MSK_NEVER,
  299. BT_KILL_MSK_NEVER,
  300. },
  301. {
  302. BT_KILL_MSK_NEVER,
  303. BT_KILL_MSK_NEVER,
  304. BT_KILL_MSK_NEVER,
  305. },
  306. {
  307. BT_KILL_MSK_DEFAULT,
  308. BT_KILL_MSK_NEVER,
  309. BT_KILL_MSK_DEFAULT,
  310. },
  311. };
  312. static const u8 iwl_bt_ack_kill_msk[BT_MAX_AG][BT_COEX_MAX_LUT] = {
  313. {
  314. BT_KILL_MSK_ALWAYS,
  315. BT_KILL_MSK_ALWAYS,
  316. BT_KILL_MSK_ALWAYS,
  317. },
  318. {
  319. BT_KILL_MSK_ALWAYS,
  320. BT_KILL_MSK_ALWAYS,
  321. BT_KILL_MSK_ALWAYS,
  322. },
  323. {
  324. BT_KILL_MSK_ALWAYS,
  325. BT_KILL_MSK_ALWAYS,
  326. BT_KILL_MSK_ALWAYS,
  327. },
  328. {
  329. BT_KILL_MSK_DEFAULT,
  330. BT_KILL_MSK_ALWAYS,
  331. BT_KILL_MSK_DEFAULT,
  332. },
  333. };
  334. struct corunning_block_luts {
  335. u8 range;
  336. __le32 lut20[BT_COEX_CORUN_LUT_SIZE];
  337. };
  338. /*
  339. * Ranges for the antenna coupling calibration / co-running block LUT:
  340. * LUT0: [ 0, 12[
  341. * LUT1: [12, 20[
  342. * LUT2: [20, 21[
  343. * LUT3: [21, 23[
  344. * LUT4: [23, 27[
  345. * LUT5: [27, 30[
  346. * LUT6: [30, 32[
  347. * LUT7: [32, 33[
  348. * LUT8: [33, - [
  349. */
  350. static const struct corunning_block_luts antenna_coupling_ranges[] = {
  351. {
  352. .range = 0,
  353. .lut20 = {
  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. 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. },
  371. },
  372. {
  373. .range = 12,
  374. .lut20 = {
  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. 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. },
  392. },
  393. {
  394. .range = 20,
  395. .lut20 = {
  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. 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. },
  413. },
  414. {
  415. .range = 21,
  416. .lut20 = {
  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. 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. },
  434. },
  435. {
  436. .range = 23,
  437. .lut20 = {
  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. 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. },
  455. },
  456. {
  457. .range = 27,
  458. .lut20 = {
  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. 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. },
  476. },
  477. {
  478. .range = 30,
  479. .lut20 = {
  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. 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. },
  497. },
  498. {
  499. .range = 32,
  500. .lut20 = {
  501. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  502. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  503. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  504. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  505. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  506. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  507. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  508. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  509. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  510. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  511. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  512. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  513. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  514. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  515. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  516. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  517. },
  518. },
  519. {
  520. .range = 33,
  521. .lut20 = {
  522. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  523. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  524. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  525. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  526. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  527. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  528. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  529. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  530. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  531. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  532. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  533. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  534. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  535. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  536. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  537. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  538. },
  539. },
  540. };
  541. static enum iwl_bt_coex_lut_type
  542. iwl_get_coex_type(struct iwl_mvm *mvm, const struct ieee80211_vif *vif)
  543. {
  544. struct ieee80211_chanctx_conf *chanctx_conf;
  545. enum iwl_bt_coex_lut_type ret;
  546. u16 phy_ctx_id;
  547. /*
  548. * Checking that we hold mvm->mutex is a good idea, but the rate
  549. * control can't acquire the mutex since it runs in Tx path.
  550. * So this is racy in that case, but in the worst case, the AMPDU
  551. * size limit will be wrong for a short time which is not a big
  552. * issue.
  553. */
  554. rcu_read_lock();
  555. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  556. if (!chanctx_conf ||
  557. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ) {
  558. rcu_read_unlock();
  559. return BT_COEX_INVALID_LUT;
  560. }
  561. ret = BT_COEX_TX_DIS_LUT;
  562. if (mvm->cfg->bt_shared_single_ant) {
  563. rcu_read_unlock();
  564. return ret;
  565. }
  566. phy_ctx_id = *((u16 *)chanctx_conf->drv_priv);
  567. if (mvm->last_bt_ci_cmd_old.primary_ch_phy_id == phy_ctx_id)
  568. ret = le32_to_cpu(mvm->last_bt_notif_old.primary_ch_lut);
  569. else if (mvm->last_bt_ci_cmd_old.secondary_ch_phy_id == phy_ctx_id)
  570. ret = le32_to_cpu(mvm->last_bt_notif_old.secondary_ch_lut);
  571. /* else - default = TX TX disallowed */
  572. rcu_read_unlock();
  573. return ret;
  574. }
  575. int iwl_send_bt_init_conf_old(struct iwl_mvm *mvm)
  576. {
  577. struct iwl_bt_coex_cmd_old *bt_cmd;
  578. struct iwl_host_cmd cmd = {
  579. .id = BT_CONFIG,
  580. .len = { sizeof(*bt_cmd), },
  581. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  582. };
  583. int ret;
  584. u32 flags;
  585. ret = iwl_send_bt_prio_tbl(mvm);
  586. if (ret)
  587. return ret;
  588. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  589. if (!bt_cmd)
  590. return -ENOMEM;
  591. cmd.data[0] = bt_cmd;
  592. lockdep_assert_held(&mvm->mutex);
  593. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) {
  594. switch (mvm->bt_force_ant_mode) {
  595. case BT_FORCE_ANT_AUTO:
  596. flags = BT_COEX_AUTO_OLD;
  597. break;
  598. case BT_FORCE_ANT_BT:
  599. flags = BT_COEX_BT_OLD;
  600. break;
  601. case BT_FORCE_ANT_WIFI:
  602. flags = BT_COEX_WIFI_OLD;
  603. break;
  604. default:
  605. WARN_ON(1);
  606. flags = 0;
  607. }
  608. bt_cmd->flags = cpu_to_le32(flags);
  609. bt_cmd->valid_bit_msk = cpu_to_le32(BT_VALID_ENABLE);
  610. goto send_cmd;
  611. }
  612. bt_cmd->max_kill = 5;
  613. bt_cmd->bt4_antenna_isolation_thr =
  614. IWL_MVM_BT_COEX_ANTENNA_COUPLING_THRS;
  615. bt_cmd->bt4_antenna_isolation = iwlwifi_mod_params.ant_coupling;
  616. bt_cmd->bt4_tx_tx_delta_freq_thr = 15;
  617. bt_cmd->bt4_tx_rx_max_freq0 = 15;
  618. bt_cmd->override_primary_lut = BT_COEX_INVALID_LUT;
  619. bt_cmd->override_secondary_lut = BT_COEX_INVALID_LUT;
  620. flags = iwlwifi_mod_params.bt_coex_active ?
  621. BT_COEX_NW_OLD : BT_COEX_DISABLE_OLD;
  622. bt_cmd->flags = cpu_to_le32(flags);
  623. bt_cmd->valid_bit_msk = cpu_to_le32(BT_VALID_ENABLE |
  624. BT_VALID_BT_PRIO_BOOST |
  625. BT_VALID_MAX_KILL |
  626. BT_VALID_3W_TMRS |
  627. BT_VALID_KILL_ACK |
  628. BT_VALID_KILL_CTS |
  629. BT_VALID_REDUCED_TX_POWER |
  630. BT_VALID_LUT |
  631. BT_VALID_WIFI_RX_SW_PRIO_BOOST |
  632. BT_VALID_WIFI_TX_SW_PRIO_BOOST |
  633. BT_VALID_ANT_ISOLATION |
  634. BT_VALID_ANT_ISOLATION_THRS |
  635. BT_VALID_TXTX_DELTA_FREQ_THRS |
  636. BT_VALID_TXRX_MAX_FREQ_0 |
  637. BT_VALID_SYNC_TO_SCO |
  638. BT_VALID_TTC |
  639. BT_VALID_RRC);
  640. if (IWL_MVM_BT_COEX_SYNC2SCO)
  641. bt_cmd->flags |= cpu_to_le32(BT_COEX_SYNC2SCO);
  642. if (iwl_mvm_bt_is_plcr_supported(mvm)) {
  643. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_CORUN_LUT_20 |
  644. BT_VALID_CORUN_LUT_40);
  645. bt_cmd->flags |= cpu_to_le32(BT_COEX_CORUNNING);
  646. }
  647. if (IWL_MVM_BT_COEX_MPLUT) {
  648. bt_cmd->flags |= cpu_to_le32(BT_COEX_MPLUT);
  649. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_MULTI_PRIO_LUT);
  650. }
  651. if (IWL_MVM_BT_COEX_TTC)
  652. bt_cmd->flags |= cpu_to_le32(BT_COEX_TTC);
  653. if (iwl_mvm_bt_is_rrc_supported(mvm))
  654. bt_cmd->flags |= cpu_to_le32(BT_COEX_RRC);
  655. if (mvm->cfg->bt_shared_single_ant)
  656. memcpy(&bt_cmd->decision_lut, iwl_single_shared_ant,
  657. sizeof(iwl_single_shared_ant));
  658. else
  659. memcpy(&bt_cmd->decision_lut, iwl_combined_lookup,
  660. sizeof(iwl_combined_lookup));
  661. /* Take first Co-running block LUT to get started */
  662. memcpy(bt_cmd->bt4_corun_lut20, antenna_coupling_ranges[0].lut20,
  663. sizeof(bt_cmd->bt4_corun_lut20));
  664. memcpy(bt_cmd->bt4_corun_lut40, antenna_coupling_ranges[0].lut20,
  665. sizeof(bt_cmd->bt4_corun_lut40));
  666. memcpy(&bt_cmd->bt_prio_boost, iwl_bt_prio_boost,
  667. sizeof(iwl_bt_prio_boost));
  668. bt_cmd->bt4_multiprio_lut[0] = cpu_to_le32(IWL_MVM_BT_COEX_MPLUT_REG0);
  669. bt_cmd->bt4_multiprio_lut[1] = cpu_to_le32(IWL_MVM_BT_COEX_MPLUT_REG1);
  670. send_cmd:
  671. memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
  672. memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
  673. ret = iwl_mvm_send_cmd(mvm, &cmd);
  674. kfree(bt_cmd);
  675. return ret;
  676. }
  677. static int iwl_mvm_bt_udpate_ctrl_kill_msk(struct iwl_mvm *mvm)
  678. {
  679. struct iwl_bt_coex_profile_notif_old *notif = &mvm->last_bt_notif_old;
  680. u32 primary_lut = le32_to_cpu(notif->primary_ch_lut);
  681. u32 ag = le32_to_cpu(notif->bt_activity_grading);
  682. struct iwl_bt_coex_cmd_old *bt_cmd;
  683. u8 ack_kill_msk, cts_kill_msk;
  684. struct iwl_host_cmd cmd = {
  685. .id = BT_CONFIG,
  686. .data[0] = &bt_cmd,
  687. .len = { sizeof(*bt_cmd), },
  688. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  689. };
  690. int ret = 0;
  691. lockdep_assert_held(&mvm->mutex);
  692. ack_kill_msk = iwl_bt_ack_kill_msk[ag][primary_lut];
  693. cts_kill_msk = iwl_bt_cts_kill_msk[ag][primary_lut];
  694. if (mvm->bt_ack_kill_msk[0] == ack_kill_msk &&
  695. mvm->bt_cts_kill_msk[0] == cts_kill_msk)
  696. return 0;
  697. mvm->bt_ack_kill_msk[0] = ack_kill_msk;
  698. mvm->bt_cts_kill_msk[0] = cts_kill_msk;
  699. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  700. if (!bt_cmd)
  701. return -ENOMEM;
  702. cmd.data[0] = bt_cmd;
  703. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  704. bt_cmd->kill_ack_msk = cpu_to_le32(iwl_bt_ctl_kill_msk[ack_kill_msk]);
  705. bt_cmd->kill_cts_msk = cpu_to_le32(iwl_bt_ctl_kill_msk[cts_kill_msk]);
  706. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_ENABLE |
  707. BT_VALID_KILL_ACK |
  708. BT_VALID_KILL_CTS);
  709. ret = iwl_mvm_send_cmd(mvm, &cmd);
  710. kfree(bt_cmd);
  711. return ret;
  712. }
  713. static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id,
  714. bool enable)
  715. {
  716. struct iwl_bt_coex_cmd_old *bt_cmd;
  717. /* Send ASYNC since this can be sent from an atomic context */
  718. struct iwl_host_cmd cmd = {
  719. .id = BT_CONFIG,
  720. .len = { sizeof(*bt_cmd), },
  721. .dataflags = { IWL_HCMD_DFL_DUP, },
  722. .flags = CMD_ASYNC,
  723. };
  724. struct iwl_mvm_sta *mvmsta;
  725. int ret;
  726. mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
  727. if (!mvmsta)
  728. return 0;
  729. /* nothing to do */
  730. if (mvmsta->bt_reduced_txpower == enable)
  731. return 0;
  732. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_ATOMIC);
  733. if (!bt_cmd)
  734. return -ENOMEM;
  735. cmd.data[0] = bt_cmd;
  736. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  737. bt_cmd->valid_bit_msk =
  738. cpu_to_le32(BT_VALID_ENABLE | BT_VALID_REDUCED_TX_POWER);
  739. bt_cmd->bt_reduced_tx_power = sta_id;
  740. if (enable)
  741. bt_cmd->bt_reduced_tx_power |= BT_REDUCED_TX_POWER_BIT;
  742. IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n",
  743. enable ? "en" : "dis", sta_id);
  744. mvmsta->bt_reduced_txpower = enable;
  745. ret = iwl_mvm_send_cmd(mvm, &cmd);
  746. kfree(bt_cmd);
  747. return ret;
  748. }
  749. struct iwl_bt_iterator_data {
  750. struct iwl_bt_coex_profile_notif_old *notif;
  751. struct iwl_mvm *mvm;
  752. struct ieee80211_chanctx_conf *primary;
  753. struct ieee80211_chanctx_conf *secondary;
  754. bool primary_ll;
  755. };
  756. static inline
  757. void iwl_mvm_bt_coex_enable_rssi_event(struct iwl_mvm *mvm,
  758. struct ieee80211_vif *vif,
  759. bool enable, int rssi)
  760. {
  761. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  762. mvmvif->bf_data.last_bt_coex_event = rssi;
  763. mvmvif->bf_data.bt_coex_max_thold =
  764. enable ? -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH : 0;
  765. mvmvif->bf_data.bt_coex_min_thold =
  766. enable ? -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH : 0;
  767. }
  768. /* must be called under rcu_read_lock */
  769. static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac,
  770. struct ieee80211_vif *vif)
  771. {
  772. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  773. struct iwl_bt_iterator_data *data = _data;
  774. struct iwl_mvm *mvm = data->mvm;
  775. struct ieee80211_chanctx_conf *chanctx_conf;
  776. enum ieee80211_smps_mode smps_mode;
  777. u32 bt_activity_grading;
  778. int ave_rssi;
  779. lockdep_assert_held(&mvm->mutex);
  780. switch (vif->type) {
  781. case NL80211_IFTYPE_STATION:
  782. /* default smps_mode for BSS / P2P client is AUTOMATIC */
  783. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  784. break;
  785. case NL80211_IFTYPE_AP:
  786. if (!mvmvif->ap_ibss_active)
  787. return;
  788. break;
  789. default:
  790. return;
  791. }
  792. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  793. /* If channel context is invalid or not on 2.4GHz .. */
  794. if ((!chanctx_conf ||
  795. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ)) {
  796. if (vif->type == NL80211_IFTYPE_STATION) {
  797. /* ... relax constraints and disable rssi events */
  798. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  799. smps_mode);
  800. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  801. false);
  802. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  803. }
  804. return;
  805. }
  806. bt_activity_grading = le32_to_cpu(data->notif->bt_activity_grading);
  807. if (bt_activity_grading >= BT_HIGH_TRAFFIC)
  808. smps_mode = IEEE80211_SMPS_STATIC;
  809. else if (bt_activity_grading >= BT_LOW_TRAFFIC)
  810. smps_mode = vif->type == NL80211_IFTYPE_AP ?
  811. IEEE80211_SMPS_OFF :
  812. IEEE80211_SMPS_DYNAMIC;
  813. /* relax SMPS contraints for next association */
  814. if (!vif->bss_conf.assoc)
  815. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  816. if (mvmvif->phy_ctxt &&
  817. data->notif->rrc_enabled & BIT(mvmvif->phy_ctxt->id))
  818. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  819. IWL_DEBUG_COEX(data->mvm,
  820. "mac %d: bt_status %d bt_activity_grading %d smps_req %d\n",
  821. mvmvif->id, data->notif->bt_status, bt_activity_grading,
  822. smps_mode);
  823. if (vif->type == NL80211_IFTYPE_STATION)
  824. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  825. smps_mode);
  826. /* low latency is always primary */
  827. if (iwl_mvm_vif_low_latency(mvmvif)) {
  828. data->primary_ll = true;
  829. data->secondary = data->primary;
  830. data->primary = chanctx_conf;
  831. }
  832. if (vif->type == NL80211_IFTYPE_AP) {
  833. if (!mvmvif->ap_ibss_active)
  834. return;
  835. if (chanctx_conf == data->primary)
  836. return;
  837. if (!data->primary_ll) {
  838. /*
  839. * downgrade the current primary no matter what its
  840. * type is.
  841. */
  842. data->secondary = data->primary;
  843. data->primary = chanctx_conf;
  844. } else {
  845. /* there is low latency vif - we will be secondary */
  846. data->secondary = chanctx_conf;
  847. }
  848. return;
  849. }
  850. /*
  851. * STA / P2P Client, try to be primary if first vif. If we are in low
  852. * latency mode, we are already in primary and just don't do much
  853. */
  854. if (!data->primary || data->primary == chanctx_conf)
  855. data->primary = chanctx_conf;
  856. else if (!data->secondary)
  857. /* if secondary is not NULL, it might be a GO */
  858. data->secondary = chanctx_conf;
  859. /*
  860. * don't reduce the Tx power if one of these is true:
  861. * we are in LOOSE
  862. * single share antenna product
  863. * BT is active
  864. * we are associated
  865. */
  866. if (iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT ||
  867. mvm->cfg->bt_shared_single_ant || !vif->bss_conf.assoc ||
  868. !data->notif->bt_status) {
  869. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false);
  870. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  871. return;
  872. }
  873. /* try to get the avg rssi from fw */
  874. ave_rssi = mvmvif->bf_data.ave_beacon_signal;
  875. /* if the RSSI isn't valid, fake it is very low */
  876. if (!ave_rssi)
  877. ave_rssi = -100;
  878. if (ave_rssi > -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH) {
  879. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true))
  880. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  881. } else if (ave_rssi < -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH) {
  882. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
  883. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  884. }
  885. /* Begin to monitor the RSSI: it may influence the reduced Tx power */
  886. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, true, ave_rssi);
  887. }
  888. static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm)
  889. {
  890. struct iwl_bt_iterator_data data = {
  891. .mvm = mvm,
  892. .notif = &mvm->last_bt_notif_old,
  893. };
  894. struct iwl_bt_coex_ci_cmd_old cmd = {};
  895. u8 ci_bw_idx;
  896. /* Ignore updates if we are in force mode */
  897. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  898. return;
  899. rcu_read_lock();
  900. ieee80211_iterate_active_interfaces_atomic(
  901. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  902. iwl_mvm_bt_notif_iterator, &data);
  903. if (data.primary) {
  904. struct ieee80211_chanctx_conf *chan = data.primary;
  905. if (WARN_ON(!chan->def.chan)) {
  906. rcu_read_unlock();
  907. return;
  908. }
  909. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  910. ci_bw_idx = 0;
  911. cmd.co_run_bw_primary = 0;
  912. } else {
  913. cmd.co_run_bw_primary = 1;
  914. if (chan->def.center_freq1 >
  915. chan->def.chan->center_freq)
  916. ci_bw_idx = 2;
  917. else
  918. ci_bw_idx = 1;
  919. }
  920. cmd.bt_primary_ci =
  921. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  922. cmd.primary_ch_phy_id = *((u16 *)data.primary->drv_priv);
  923. }
  924. if (data.secondary) {
  925. struct ieee80211_chanctx_conf *chan = data.secondary;
  926. if (WARN_ON(!data.secondary->def.chan)) {
  927. rcu_read_unlock();
  928. return;
  929. }
  930. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  931. ci_bw_idx = 0;
  932. cmd.co_run_bw_secondary = 0;
  933. } else {
  934. cmd.co_run_bw_secondary = 1;
  935. if (chan->def.center_freq1 >
  936. chan->def.chan->center_freq)
  937. ci_bw_idx = 2;
  938. else
  939. ci_bw_idx = 1;
  940. }
  941. cmd.bt_secondary_ci =
  942. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  943. cmd.secondary_ch_phy_id = *((u16 *)data.secondary->drv_priv);
  944. }
  945. rcu_read_unlock();
  946. /* Don't spam the fw with the same command over and over */
  947. if (memcmp(&cmd, &mvm->last_bt_ci_cmd_old, sizeof(cmd))) {
  948. if (iwl_mvm_send_cmd_pdu(mvm, BT_COEX_CI, 0,
  949. sizeof(cmd), &cmd))
  950. IWL_ERR(mvm, "Failed to send BT_CI cmd\n");
  951. memcpy(&mvm->last_bt_ci_cmd_old, &cmd, sizeof(cmd));
  952. }
  953. if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm))
  954. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  955. }
  956. void iwl_mvm_rx_bt_coex_notif_old(struct iwl_mvm *mvm,
  957. struct iwl_rx_cmd_buffer *rxb)
  958. {
  959. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  960. struct iwl_bt_coex_profile_notif_old *notif = (void *)pkt->data;
  961. IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n");
  962. IWL_DEBUG_COEX(mvm, "\tBT status: %s\n",
  963. notif->bt_status ? "ON" : "OFF");
  964. IWL_DEBUG_COEX(mvm, "\tBT open conn %d\n", notif->bt_open_conn);
  965. IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n", notif->bt_ci_compliance);
  966. IWL_DEBUG_COEX(mvm, "\tBT primary_ch_lut %d\n",
  967. le32_to_cpu(notif->primary_ch_lut));
  968. IWL_DEBUG_COEX(mvm, "\tBT secondary_ch_lut %d\n",
  969. le32_to_cpu(notif->secondary_ch_lut));
  970. IWL_DEBUG_COEX(mvm, "\tBT activity grading %d\n",
  971. le32_to_cpu(notif->bt_activity_grading));
  972. IWL_DEBUG_COEX(mvm, "\tBT agg traffic load %d\n",
  973. notif->bt_agg_traffic_load);
  974. /* remember this notification for future use: rssi fluctuations */
  975. memcpy(&mvm->last_bt_notif_old, notif, sizeof(mvm->last_bt_notif_old));
  976. iwl_mvm_bt_coex_notif_handle(mvm);
  977. }
  978. static void iwl_mvm_bt_rssi_iterator(void *_data, u8 *mac,
  979. struct ieee80211_vif *vif)
  980. {
  981. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  982. struct iwl_bt_iterator_data *data = _data;
  983. struct iwl_mvm *mvm = data->mvm;
  984. struct ieee80211_sta *sta;
  985. struct iwl_mvm_sta *mvmsta;
  986. struct ieee80211_chanctx_conf *chanctx_conf;
  987. rcu_read_lock();
  988. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  989. /* If channel context is invalid or not on 2.4GHz - don't count it */
  990. if (!chanctx_conf ||
  991. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ) {
  992. rcu_read_unlock();
  993. return;
  994. }
  995. rcu_read_unlock();
  996. if (vif->type != NL80211_IFTYPE_STATION ||
  997. mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  998. return;
  999. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
  1000. lockdep_is_held(&mvm->mutex));
  1001. /* This can happen if the station has been removed right now */
  1002. if (IS_ERR_OR_NULL(sta))
  1003. return;
  1004. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  1005. }
  1006. void iwl_mvm_bt_rssi_event_old(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  1007. enum ieee80211_rssi_event_data rssi_event)
  1008. {
  1009. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1010. struct iwl_bt_iterator_data data = {
  1011. .mvm = mvm,
  1012. };
  1013. int ret;
  1014. lockdep_assert_held(&mvm->mutex);
  1015. /* Ignore updates if we are in force mode */
  1016. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  1017. return;
  1018. /*
  1019. * Rssi update while not associated - can happen since the statistics
  1020. * are handled asynchronously
  1021. */
  1022. if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  1023. return;
  1024. /* No BT - reports should be disabled */
  1025. if (!mvm->last_bt_notif_old.bt_status)
  1026. return;
  1027. IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid,
  1028. rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW");
  1029. /*
  1030. * Check if rssi is good enough for reduced Tx power, but not in loose
  1031. * scheme.
  1032. */
  1033. if (rssi_event == RSSI_EVENT_LOW || mvm->cfg->bt_shared_single_ant ||
  1034. iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT)
  1035. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  1036. false);
  1037. else
  1038. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true);
  1039. if (ret)
  1040. IWL_ERR(mvm, "couldn't send BT_CONFIG HCMD upon RSSI event\n");
  1041. ieee80211_iterate_active_interfaces_atomic(
  1042. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  1043. iwl_mvm_bt_rssi_iterator, &data);
  1044. if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm))
  1045. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  1046. }
  1047. #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000)
  1048. #define LINK_QUAL_AGG_TIME_LIMIT_BT_ACT (1200)
  1049. u16 iwl_mvm_coex_agg_time_limit_old(struct iwl_mvm *mvm,
  1050. struct ieee80211_sta *sta)
  1051. {
  1052. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  1053. enum iwl_bt_coex_lut_type lut_type;
  1054. if (le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading) <
  1055. BT_HIGH_TRAFFIC)
  1056. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  1057. if (mvm->last_bt_notif_old.ttc_enabled)
  1058. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  1059. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  1060. if (lut_type == BT_COEX_LOOSE_LUT || lut_type == BT_COEX_INVALID_LUT)
  1061. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  1062. /* tight coex, high bt traffic, reduce AGG time limit */
  1063. return LINK_QUAL_AGG_TIME_LIMIT_BT_ACT;
  1064. }
  1065. bool iwl_mvm_bt_coex_is_mimo_allowed_old(struct iwl_mvm *mvm,
  1066. struct ieee80211_sta *sta)
  1067. {
  1068. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  1069. enum iwl_bt_coex_lut_type lut_type;
  1070. if (mvm->last_bt_notif_old.ttc_enabled)
  1071. return true;
  1072. if (le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading) <
  1073. BT_HIGH_TRAFFIC)
  1074. return true;
  1075. /*
  1076. * In Tight / TxTxDis, BT can't Rx while we Tx, so use both antennas
  1077. * since BT is already killed.
  1078. * In Loose, BT can Rx while we Tx, so forbid MIMO to let BT Rx while
  1079. * we Tx.
  1080. * When we are in 5GHz, we'll get BT_COEX_INVALID_LUT allowing MIMO.
  1081. */
  1082. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  1083. return lut_type != BT_COEX_LOOSE_LUT;
  1084. }
  1085. bool iwl_mvm_bt_coex_is_shared_ant_avail_old(struct iwl_mvm *mvm)
  1086. {
  1087. u32 ag = le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading);
  1088. return ag < BT_HIGH_TRAFFIC;
  1089. }
  1090. bool iwl_mvm_bt_coex_is_tpc_allowed_old(struct iwl_mvm *mvm,
  1091. enum ieee80211_band band)
  1092. {
  1093. u32 bt_activity =
  1094. le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading);
  1095. if (band != IEEE80211_BAND_2GHZ)
  1096. return false;
  1097. return bt_activity >= BT_LOW_TRAFFIC;
  1098. }
  1099. void iwl_mvm_bt_coex_vif_change_old(struct iwl_mvm *mvm)
  1100. {
  1101. iwl_mvm_bt_coex_notif_handle(mvm);
  1102. }
  1103. void iwl_mvm_rx_ant_coupling_notif_old(struct iwl_mvm *mvm,
  1104. struct iwl_rx_cmd_buffer *rxb)
  1105. {
  1106. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1107. u32 ant_isolation = le32_to_cpup((void *)pkt->data);
  1108. u8 __maybe_unused lower_bound, upper_bound;
  1109. u8 lut;
  1110. struct iwl_bt_coex_cmd_old *bt_cmd;
  1111. struct iwl_host_cmd cmd = {
  1112. .id = BT_CONFIG,
  1113. .len = { sizeof(*bt_cmd), },
  1114. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  1115. };
  1116. if (!iwl_mvm_bt_is_plcr_supported(mvm))
  1117. return;
  1118. lockdep_assert_held(&mvm->mutex);
  1119. /* Ignore updates if we are in force mode */
  1120. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  1121. return;
  1122. if (ant_isolation == mvm->last_ant_isol)
  1123. return;
  1124. for (lut = 0; lut < ARRAY_SIZE(antenna_coupling_ranges) - 1; lut++)
  1125. if (ant_isolation < antenna_coupling_ranges[lut + 1].range)
  1126. break;
  1127. lower_bound = antenna_coupling_ranges[lut].range;
  1128. if (lut < ARRAY_SIZE(antenna_coupling_ranges) - 1)
  1129. upper_bound = antenna_coupling_ranges[lut + 1].range;
  1130. else
  1131. upper_bound = antenna_coupling_ranges[lut].range;
  1132. IWL_DEBUG_COEX(mvm, "Antenna isolation=%d in range [%d,%d[, lut=%d\n",
  1133. ant_isolation, lower_bound, upper_bound, lut);
  1134. mvm->last_ant_isol = ant_isolation;
  1135. if (mvm->last_corun_lut == lut)
  1136. return;
  1137. mvm->last_corun_lut = lut;
  1138. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  1139. if (!bt_cmd)
  1140. return;
  1141. cmd.data[0] = bt_cmd;
  1142. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  1143. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_ENABLE |
  1144. BT_VALID_CORUN_LUT_20 |
  1145. BT_VALID_CORUN_LUT_40);
  1146. /* For the moment, use the same LUT for 20GHz and 40GHz */
  1147. memcpy(bt_cmd->bt4_corun_lut20, antenna_coupling_ranges[lut].lut20,
  1148. sizeof(bt_cmd->bt4_corun_lut20));
  1149. memcpy(bt_cmd->bt4_corun_lut40, antenna_coupling_ranges[lut].lut20,
  1150. sizeof(bt_cmd->bt4_corun_lut40));
  1151. if (iwl_mvm_send_cmd(mvm, &cmd))
  1152. IWL_ERR(mvm, "failed to send BT_CONFIG command\n");
  1153. kfree(bt_cmd);
  1154. }