coex.c 32 KB

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