coex.c 38 KB

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