coex.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  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 - 2015 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 <linuxwifi@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 - 2015 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. u32 mode;
  396. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  397. return iwl_send_bt_init_conf_old(mvm);
  398. lockdep_assert_held(&mvm->mutex);
  399. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) {
  400. switch (mvm->bt_force_ant_mode) {
  401. case BT_FORCE_ANT_BT:
  402. mode = BT_COEX_BT;
  403. break;
  404. case BT_FORCE_ANT_WIFI:
  405. mode = BT_COEX_WIFI;
  406. break;
  407. default:
  408. WARN_ON(1);
  409. mode = 0;
  410. }
  411. bt_cmd.mode = cpu_to_le32(mode);
  412. goto send_cmd;
  413. }
  414. mode = iwlwifi_mod_params.bt_coex_active ? BT_COEX_NW : BT_COEX_DISABLE;
  415. bt_cmd.mode = cpu_to_le32(mode);
  416. if (IWL_MVM_BT_COEX_SYNC2SCO)
  417. bt_cmd.enabled_modules |=
  418. cpu_to_le32(BT_COEX_SYNC2SCO_ENABLED);
  419. if (iwl_mvm_bt_is_plcr_supported(mvm))
  420. bt_cmd.enabled_modules |= cpu_to_le32(BT_COEX_CORUN_ENABLED);
  421. if (iwl_mvm_is_mplut_supported(mvm))
  422. bt_cmd.enabled_modules |= cpu_to_le32(BT_COEX_MPLUT_ENABLED);
  423. bt_cmd.enabled_modules |= cpu_to_le32(BT_COEX_HIGH_BAND_RET);
  424. send_cmd:
  425. memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
  426. memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
  427. return iwl_mvm_send_cmd_pdu(mvm, BT_CONFIG, 0, sizeof(bt_cmd), &bt_cmd);
  428. }
  429. static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id,
  430. bool enable)
  431. {
  432. struct iwl_bt_coex_reduced_txp_update_cmd cmd = {};
  433. struct iwl_mvm_sta *mvmsta;
  434. u32 value;
  435. int ret;
  436. mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
  437. if (!mvmsta)
  438. return 0;
  439. /* nothing to do */
  440. if (mvmsta->bt_reduced_txpower == enable)
  441. return 0;
  442. value = mvmsta->sta_id;
  443. if (enable)
  444. value |= BT_REDUCED_TX_POWER_BIT;
  445. IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n",
  446. enable ? "en" : "dis", sta_id);
  447. cmd.reduced_txp = cpu_to_le32(value);
  448. mvmsta->bt_reduced_txpower = enable;
  449. ret = iwl_mvm_send_cmd_pdu(mvm, BT_COEX_UPDATE_REDUCED_TXP, CMD_ASYNC,
  450. sizeof(cmd), &cmd);
  451. return ret;
  452. }
  453. struct iwl_bt_iterator_data {
  454. struct iwl_bt_coex_profile_notif *notif;
  455. struct iwl_mvm *mvm;
  456. struct ieee80211_chanctx_conf *primary;
  457. struct ieee80211_chanctx_conf *secondary;
  458. bool primary_ll;
  459. };
  460. static inline
  461. void iwl_mvm_bt_coex_enable_rssi_event(struct iwl_mvm *mvm,
  462. struct ieee80211_vif *vif,
  463. bool enable, int rssi)
  464. {
  465. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  466. mvmvif->bf_data.last_bt_coex_event = rssi;
  467. mvmvif->bf_data.bt_coex_max_thold =
  468. enable ? -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH : 0;
  469. mvmvif->bf_data.bt_coex_min_thold =
  470. enable ? -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH : 0;
  471. }
  472. /* must be called under rcu_read_lock */
  473. static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac,
  474. struct ieee80211_vif *vif)
  475. {
  476. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  477. struct iwl_bt_iterator_data *data = _data;
  478. struct iwl_mvm *mvm = data->mvm;
  479. struct ieee80211_chanctx_conf *chanctx_conf;
  480. /* default smps_mode is AUTOMATIC - only used for client modes */
  481. enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_AUTOMATIC;
  482. u32 bt_activity_grading;
  483. int ave_rssi;
  484. lockdep_assert_held(&mvm->mutex);
  485. switch (vif->type) {
  486. case NL80211_IFTYPE_STATION:
  487. break;
  488. case NL80211_IFTYPE_AP:
  489. if (!mvmvif->ap_ibss_active)
  490. return;
  491. break;
  492. default:
  493. return;
  494. }
  495. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  496. /* If channel context is invalid or not on 2.4GHz .. */
  497. if ((!chanctx_conf ||
  498. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ)) {
  499. if (vif->type == NL80211_IFTYPE_STATION) {
  500. /* ... relax constraints and disable rssi events */
  501. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  502. smps_mode);
  503. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  504. false);
  505. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  506. }
  507. return;
  508. }
  509. bt_activity_grading = le32_to_cpu(data->notif->bt_activity_grading);
  510. if (bt_activity_grading >= BT_HIGH_TRAFFIC)
  511. smps_mode = IEEE80211_SMPS_STATIC;
  512. else if (bt_activity_grading >= BT_LOW_TRAFFIC)
  513. smps_mode = IEEE80211_SMPS_DYNAMIC;
  514. /* relax SMPS constraints for next association */
  515. if (!vif->bss_conf.assoc)
  516. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  517. if (mvmvif->phy_ctxt &&
  518. IWL_COEX_IS_RRC_ON(mvm->last_bt_notif.ttc_rrc_status,
  519. mvmvif->phy_ctxt->id))
  520. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  521. IWL_DEBUG_COEX(data->mvm,
  522. "mac %d: bt_activity_grading %d smps_req %d\n",
  523. mvmvif->id, bt_activity_grading, smps_mode);
  524. if (vif->type == NL80211_IFTYPE_STATION)
  525. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  526. smps_mode);
  527. /* low latency is always primary */
  528. if (iwl_mvm_vif_low_latency(mvmvif)) {
  529. data->primary_ll = true;
  530. data->secondary = data->primary;
  531. data->primary = chanctx_conf;
  532. }
  533. if (vif->type == NL80211_IFTYPE_AP) {
  534. if (!mvmvif->ap_ibss_active)
  535. return;
  536. if (chanctx_conf == data->primary)
  537. return;
  538. if (!data->primary_ll) {
  539. /*
  540. * downgrade the current primary no matter what its
  541. * type is.
  542. */
  543. data->secondary = data->primary;
  544. data->primary = chanctx_conf;
  545. } else {
  546. /* there is low latency vif - we will be secondary */
  547. data->secondary = chanctx_conf;
  548. }
  549. return;
  550. }
  551. /*
  552. * STA / P2P Client, try to be primary if first vif. If we are in low
  553. * latency mode, we are already in primary and just don't do much
  554. */
  555. if (!data->primary || data->primary == chanctx_conf)
  556. data->primary = chanctx_conf;
  557. else if (!data->secondary)
  558. /* if secondary is not NULL, it might be a GO */
  559. data->secondary = chanctx_conf;
  560. /*
  561. * don't reduce the Tx power if one of these is true:
  562. * we are in LOOSE
  563. * single share antenna product
  564. * BT is active
  565. * we are associated
  566. */
  567. if (iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT ||
  568. mvm->cfg->bt_shared_single_ant || !vif->bss_conf.assoc ||
  569. le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF) {
  570. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false);
  571. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  572. return;
  573. }
  574. /* try to get the avg rssi from fw */
  575. ave_rssi = mvmvif->bf_data.ave_beacon_signal;
  576. /* if the RSSI isn't valid, fake it is very low */
  577. if (!ave_rssi)
  578. ave_rssi = -100;
  579. if (ave_rssi > -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH) {
  580. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true))
  581. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  582. } else if (ave_rssi < -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH) {
  583. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
  584. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  585. }
  586. /* Begin to monitor the RSSI: it may influence the reduced Tx power */
  587. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, true, ave_rssi);
  588. }
  589. static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm)
  590. {
  591. struct iwl_bt_iterator_data data = {
  592. .mvm = mvm,
  593. .notif = &mvm->last_bt_notif,
  594. };
  595. struct iwl_bt_coex_ci_cmd cmd = {};
  596. u8 ci_bw_idx;
  597. /* Ignore updates if we are in force mode */
  598. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  599. return;
  600. rcu_read_lock();
  601. ieee80211_iterate_active_interfaces_atomic(
  602. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  603. iwl_mvm_bt_notif_iterator, &data);
  604. if (data.primary) {
  605. struct ieee80211_chanctx_conf *chan = data.primary;
  606. if (WARN_ON(!chan->def.chan)) {
  607. rcu_read_unlock();
  608. return;
  609. }
  610. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  611. ci_bw_idx = 0;
  612. } else {
  613. if (chan->def.center_freq1 >
  614. chan->def.chan->center_freq)
  615. ci_bw_idx = 2;
  616. else
  617. ci_bw_idx = 1;
  618. }
  619. cmd.bt_primary_ci =
  620. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  621. cmd.primary_ch_phy_id =
  622. cpu_to_le32(*((u16 *)data.primary->drv_priv));
  623. }
  624. if (data.secondary) {
  625. struct ieee80211_chanctx_conf *chan = data.secondary;
  626. if (WARN_ON(!data.secondary->def.chan)) {
  627. rcu_read_unlock();
  628. return;
  629. }
  630. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  631. ci_bw_idx = 0;
  632. } else {
  633. if (chan->def.center_freq1 >
  634. chan->def.chan->center_freq)
  635. ci_bw_idx = 2;
  636. else
  637. ci_bw_idx = 1;
  638. }
  639. cmd.bt_secondary_ci =
  640. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  641. cmd.secondary_ch_phy_id =
  642. cpu_to_le32(*((u16 *)data.secondary->drv_priv));
  643. }
  644. rcu_read_unlock();
  645. /* Don't spam the fw with the same command over and over */
  646. if (memcmp(&cmd, &mvm->last_bt_ci_cmd, sizeof(cmd))) {
  647. if (iwl_mvm_send_cmd_pdu(mvm, BT_COEX_CI, 0,
  648. sizeof(cmd), &cmd))
  649. IWL_ERR(mvm, "Failed to send BT_CI cmd\n");
  650. memcpy(&mvm->last_bt_ci_cmd, &cmd, sizeof(cmd));
  651. }
  652. }
  653. void iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm,
  654. struct iwl_rx_cmd_buffer *rxb)
  655. {
  656. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  657. struct iwl_bt_coex_profile_notif *notif = (void *)pkt->data;
  658. if (!fw_has_api(&mvm->fw->ucode_capa,
  659. IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
  660. iwl_mvm_rx_bt_coex_notif_old(mvm, rxb);
  661. return;
  662. }
  663. IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n");
  664. IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n", notif->bt_ci_compliance);
  665. IWL_DEBUG_COEX(mvm, "\tBT primary_ch_lut %d\n",
  666. le32_to_cpu(notif->primary_ch_lut));
  667. IWL_DEBUG_COEX(mvm, "\tBT secondary_ch_lut %d\n",
  668. le32_to_cpu(notif->secondary_ch_lut));
  669. IWL_DEBUG_COEX(mvm, "\tBT activity grading %d\n",
  670. le32_to_cpu(notif->bt_activity_grading));
  671. /* remember this notification for future use: rssi fluctuations */
  672. memcpy(&mvm->last_bt_notif, notif, sizeof(mvm->last_bt_notif));
  673. iwl_mvm_bt_coex_notif_handle(mvm);
  674. }
  675. void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  676. enum ieee80211_rssi_event_data rssi_event)
  677. {
  678. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  679. int ret;
  680. if (!fw_has_api(&mvm->fw->ucode_capa,
  681. IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
  682. iwl_mvm_bt_rssi_event_old(mvm, vif, rssi_event);
  683. return;
  684. }
  685. lockdep_assert_held(&mvm->mutex);
  686. /* Ignore updates if we are in force mode */
  687. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  688. return;
  689. /*
  690. * Rssi update while not associated - can happen since the statistics
  691. * are handled asynchronously
  692. */
  693. if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  694. return;
  695. /* No BT - reports should be disabled */
  696. if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) == BT_OFF)
  697. return;
  698. IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid,
  699. rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW");
  700. /*
  701. * Check if rssi is good enough for reduced Tx power, but not in loose
  702. * scheme.
  703. */
  704. if (rssi_event == RSSI_EVENT_LOW || mvm->cfg->bt_shared_single_ant ||
  705. iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT)
  706. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  707. false);
  708. else
  709. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true);
  710. if (ret)
  711. IWL_ERR(mvm, "couldn't send BT_CONFIG HCMD upon RSSI event\n");
  712. }
  713. #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000)
  714. #define LINK_QUAL_AGG_TIME_LIMIT_BT_ACT (1200)
  715. u16 iwl_mvm_coex_agg_time_limit(struct iwl_mvm *mvm,
  716. struct ieee80211_sta *sta)
  717. {
  718. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  719. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
  720. struct iwl_mvm_phy_ctxt *phy_ctxt = mvmvif->phy_ctxt;
  721. enum iwl_bt_coex_lut_type lut_type;
  722. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  723. return iwl_mvm_coex_agg_time_limit_old(mvm, sta);
  724. if (IWL_COEX_IS_TTC_ON(mvm->last_bt_notif.ttc_rrc_status, phy_ctxt->id))
  725. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  726. if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) <
  727. BT_HIGH_TRAFFIC)
  728. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  729. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  730. if (lut_type == BT_COEX_LOOSE_LUT || lut_type == BT_COEX_INVALID_LUT)
  731. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  732. /* tight coex, high bt traffic, reduce AGG time limit */
  733. return LINK_QUAL_AGG_TIME_LIMIT_BT_ACT;
  734. }
  735. bool iwl_mvm_bt_coex_is_mimo_allowed(struct iwl_mvm *mvm,
  736. struct ieee80211_sta *sta)
  737. {
  738. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  739. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
  740. struct iwl_mvm_phy_ctxt *phy_ctxt = mvmvif->phy_ctxt;
  741. enum iwl_bt_coex_lut_type lut_type;
  742. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  743. return iwl_mvm_bt_coex_is_mimo_allowed_old(mvm, sta);
  744. if (IWL_COEX_IS_TTC_ON(mvm->last_bt_notif.ttc_rrc_status, phy_ctxt->id))
  745. return true;
  746. if (le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) <
  747. BT_HIGH_TRAFFIC)
  748. return true;
  749. /*
  750. * In Tight / TxTxDis, BT can't Rx while we Tx, so use both antennas
  751. * since BT is already killed.
  752. * In Loose, BT can Rx while we Tx, so forbid MIMO to let BT Rx while
  753. * we Tx.
  754. * When we are in 5GHz, we'll get BT_COEX_INVALID_LUT allowing MIMO.
  755. */
  756. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  757. return lut_type != BT_COEX_LOOSE_LUT;
  758. }
  759. bool iwl_mvm_bt_coex_is_ant_avail(struct iwl_mvm *mvm, u8 ant)
  760. {
  761. /* there is no other antenna, shared antenna is always available */
  762. if (mvm->cfg->bt_shared_single_ant)
  763. return true;
  764. if (ant & mvm->cfg->non_shared_ant)
  765. return true;
  766. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  767. return iwl_mvm_bt_coex_is_shared_ant_avail_old(mvm);
  768. return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) <
  769. BT_HIGH_TRAFFIC;
  770. }
  771. bool iwl_mvm_bt_coex_is_shared_ant_avail(struct iwl_mvm *mvm)
  772. {
  773. /* there is no other antenna, shared antenna is always available */
  774. if (mvm->cfg->bt_shared_single_ant)
  775. return true;
  776. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  777. return iwl_mvm_bt_coex_is_shared_ant_avail_old(mvm);
  778. return le32_to_cpu(mvm->last_bt_notif.bt_activity_grading) < BT_HIGH_TRAFFIC;
  779. }
  780. bool iwl_mvm_bt_coex_is_tpc_allowed(struct iwl_mvm *mvm,
  781. enum ieee80211_band band)
  782. {
  783. u32 bt_activity = le32_to_cpu(mvm->last_bt_notif.bt_activity_grading);
  784. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_BT_COEX_SPLIT))
  785. return iwl_mvm_bt_coex_is_tpc_allowed_old(mvm, band);
  786. if (band != IEEE80211_BAND_2GHZ)
  787. return false;
  788. return bt_activity >= BT_LOW_TRAFFIC;
  789. }
  790. u8 iwl_mvm_bt_coex_tx_prio(struct iwl_mvm *mvm, struct ieee80211_hdr *hdr,
  791. struct ieee80211_tx_info *info, u8 ac)
  792. {
  793. __le16 fc = hdr->frame_control;
  794. bool mplut_enabled = iwl_mvm_is_mplut_supported(mvm);
  795. if (info->band != IEEE80211_BAND_2GHZ)
  796. return 0;
  797. if (unlikely(mvm->bt_tx_prio))
  798. return mvm->bt_tx_prio - 1;
  799. if (likely(ieee80211_is_data(fc))) {
  800. if (likely(ieee80211_is_data_qos(fc))) {
  801. switch (ac) {
  802. case IEEE80211_AC_BE:
  803. return mplut_enabled ? 1 : 0;
  804. case IEEE80211_AC_VI:
  805. return mplut_enabled ? 2 : 3;
  806. case IEEE80211_AC_VO:
  807. return 3;
  808. default:
  809. return 0;
  810. }
  811. } else if (is_multicast_ether_addr(hdr->addr1)) {
  812. return 3;
  813. } else
  814. return 0;
  815. } else if (ieee80211_is_mgmt(fc)) {
  816. return ieee80211_is_disassoc(fc) ? 0 : 3;
  817. } else if (ieee80211_is_ctl(fc)) {
  818. /* ignore cfend and cfendack frames as we never send those */
  819. return 3;
  820. }
  821. return 0;
  822. }
  823. void iwl_mvm_bt_coex_vif_change(struct iwl_mvm *mvm)
  824. {
  825. if (!fw_has_api(&mvm->fw->ucode_capa,
  826. IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
  827. iwl_mvm_bt_coex_vif_change_old(mvm);
  828. return;
  829. }
  830. iwl_mvm_bt_coex_notif_handle(mvm);
  831. }
  832. void iwl_mvm_rx_ant_coupling_notif(struct iwl_mvm *mvm,
  833. struct iwl_rx_cmd_buffer *rxb)
  834. {
  835. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  836. u32 ant_isolation = le32_to_cpup((void *)pkt->data);
  837. struct iwl_bt_coex_corun_lut_update_cmd cmd = {};
  838. u8 __maybe_unused lower_bound, upper_bound;
  839. u8 lut;
  840. if (!fw_has_api(&mvm->fw->ucode_capa,
  841. IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
  842. iwl_mvm_rx_ant_coupling_notif_old(mvm, rxb);
  843. return;
  844. }
  845. if (!iwl_mvm_bt_is_plcr_supported(mvm))
  846. return;
  847. lockdep_assert_held(&mvm->mutex);
  848. /* Ignore updates if we are in force mode */
  849. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  850. return;
  851. if (ant_isolation == mvm->last_ant_isol)
  852. return;
  853. for (lut = 0; lut < ARRAY_SIZE(antenna_coupling_ranges) - 1; lut++)
  854. if (ant_isolation < antenna_coupling_ranges[lut + 1].range)
  855. break;
  856. lower_bound = antenna_coupling_ranges[lut].range;
  857. if (lut < ARRAY_SIZE(antenna_coupling_ranges) - 1)
  858. upper_bound = antenna_coupling_ranges[lut + 1].range;
  859. else
  860. upper_bound = antenna_coupling_ranges[lut].range;
  861. IWL_DEBUG_COEX(mvm, "Antenna isolation=%d in range [%d,%d[, lut=%d\n",
  862. ant_isolation, lower_bound, upper_bound, lut);
  863. mvm->last_ant_isol = ant_isolation;
  864. if (mvm->last_corun_lut == lut)
  865. return;
  866. mvm->last_corun_lut = lut;
  867. /* For the moment, use the same LUT for 20GHz and 40GHz */
  868. memcpy(&cmd.corun_lut20, antenna_coupling_ranges[lut].lut20,
  869. sizeof(cmd.corun_lut20));
  870. memcpy(&cmd.corun_lut40, antenna_coupling_ranges[lut].lut20,
  871. sizeof(cmd.corun_lut40));
  872. if (iwl_mvm_send_cmd_pdu(mvm, BT_COEX_UPDATE_CORUN_LUT, 0,
  873. sizeof(cmd), &cmd))
  874. IWL_ERR(mvm,
  875. "failed to send BT_COEX_UPDATE_CORUN_LUT command\n");
  876. }