coex.c 31 KB

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