coex_legacy.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  23. * USA
  24. *
  25. * The full GNU General Public License is included in this distribution
  26. * in the file called COPYING.
  27. *
  28. * Contact Information:
  29. * Intel Linux Wireless <ilw@linux.intel.com>
  30. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  31. *
  32. * BSD LICENSE
  33. *
  34. * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
  35. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
  36. * All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. *
  42. * * Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * * Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in
  46. * the documentation and/or other materials provided with the
  47. * distribution.
  48. * * Neither the name Intel Corporation nor the names of its
  49. * contributors may be used to endorse or promote products derived
  50. * from this software without specific prior written permission.
  51. *
  52. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  53. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  55. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  56. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  57. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  58. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  59. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  60. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  61. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  62. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  63. *
  64. *****************************************************************************/
  65. #include <linux/ieee80211.h>
  66. #include <linux/etherdevice.h>
  67. #include <net/mac80211.h>
  68. #include "fw-api-coex.h"
  69. #include "iwl-modparams.h"
  70. #include "mvm.h"
  71. #include "iwl-debug.h"
  72. #define EVENT_PRIO_ANT(_evt, _prio, _shrd_ant) \
  73. [(_evt)] = (((_prio) << BT_COEX_PRIO_TBL_PRIO_POS) | \
  74. ((_shrd_ant) << BT_COEX_PRIO_TBL_SHRD_ANT_POS))
  75. static const u8 iwl_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = {
  76. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_INIT_CALIB1,
  77. BT_COEX_PRIO_TBL_PRIO_BYPASS, 0),
  78. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_INIT_CALIB2,
  79. BT_COEX_PRIO_TBL_PRIO_BYPASS, 1),
  80. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_LOW1,
  81. BT_COEX_PRIO_TBL_PRIO_LOW, 0),
  82. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_LOW2,
  83. BT_COEX_PRIO_TBL_PRIO_LOW, 1),
  84. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_HIGH1,
  85. BT_COEX_PRIO_TBL_PRIO_HIGH, 0),
  86. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_HIGH2,
  87. BT_COEX_PRIO_TBL_PRIO_HIGH, 1),
  88. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_DTIM,
  89. BT_COEX_PRIO_TBL_DISABLED, 0),
  90. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_SCAN52,
  91. BT_COEX_PRIO_TBL_PRIO_COEX_OFF, 0),
  92. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_SCAN24,
  93. BT_COEX_PRIO_TBL_PRIO_COEX_ON, 0),
  94. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_IDLE,
  95. BT_COEX_PRIO_TBL_PRIO_COEX_IDLE, 0),
  96. 0, 0, 0, 0, 0, 0,
  97. };
  98. #undef EVENT_PRIO_ANT
  99. static int iwl_send_bt_prio_tbl(struct iwl_mvm *mvm)
  100. {
  101. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  102. return 0;
  103. return iwl_mvm_send_cmd_pdu(mvm, BT_COEX_PRIO_TABLE, 0,
  104. sizeof(struct iwl_bt_coex_prio_tbl_cmd),
  105. &iwl_bt_prio_tbl);
  106. }
  107. static const __le32 iwl_bt_prio_boost[BT_COEX_BOOST_SIZE] = {
  108. cpu_to_le32(0xf0f0f0f0), /* 50% */
  109. cpu_to_le32(0xc0c0c0c0), /* 25% */
  110. cpu_to_le32(0xfcfcfcfc), /* 75% */
  111. cpu_to_le32(0xfefefefe), /* 87.5% */
  112. };
  113. static const __le32 iwl_single_shared_ant[BT_COEX_MAX_LUT][BT_COEX_LUT_SIZE] = {
  114. {
  115. cpu_to_le32(0x40000000),
  116. cpu_to_le32(0x00000000),
  117. cpu_to_le32(0x44000000),
  118. cpu_to_le32(0x00000000),
  119. cpu_to_le32(0x40000000),
  120. cpu_to_le32(0x00000000),
  121. cpu_to_le32(0x44000000),
  122. cpu_to_le32(0x00000000),
  123. cpu_to_le32(0xc0004000),
  124. cpu_to_le32(0xf0005000),
  125. cpu_to_le32(0xc0004000),
  126. cpu_to_le32(0xf0005000),
  127. },
  128. {
  129. cpu_to_le32(0x40000000),
  130. cpu_to_le32(0x00000000),
  131. cpu_to_le32(0x44000000),
  132. cpu_to_le32(0x00000000),
  133. cpu_to_le32(0x40000000),
  134. cpu_to_le32(0x00000000),
  135. cpu_to_le32(0x44000000),
  136. cpu_to_le32(0x00000000),
  137. cpu_to_le32(0xc0004000),
  138. cpu_to_le32(0xf0005000),
  139. cpu_to_le32(0xc0004000),
  140. cpu_to_le32(0xf0005000),
  141. },
  142. {
  143. cpu_to_le32(0x40000000),
  144. cpu_to_le32(0x00000000),
  145. cpu_to_le32(0x44000000),
  146. cpu_to_le32(0x00000000),
  147. cpu_to_le32(0x40000000),
  148. cpu_to_le32(0x00000000),
  149. cpu_to_le32(0x44000000),
  150. cpu_to_le32(0x00000000),
  151. cpu_to_le32(0xc0004000),
  152. cpu_to_le32(0xf0005000),
  153. cpu_to_le32(0xc0004000),
  154. cpu_to_le32(0xf0005000),
  155. },
  156. };
  157. static const __le32 iwl_combined_lookup[BT_COEX_MAX_LUT][BT_COEX_LUT_SIZE] = {
  158. {
  159. /* Tight */
  160. cpu_to_le32(0xaaaaaaaa),
  161. cpu_to_le32(0xaaaaaaaa),
  162. cpu_to_le32(0xaeaaaaaa),
  163. cpu_to_le32(0xaaaaaaaa),
  164. cpu_to_le32(0xcc00ff28),
  165. cpu_to_le32(0x0000aaaa),
  166. cpu_to_le32(0xcc00aaaa),
  167. cpu_to_le32(0x0000aaaa),
  168. cpu_to_le32(0xc0004000),
  169. cpu_to_le32(0x00004000),
  170. cpu_to_le32(0xf0005000),
  171. cpu_to_le32(0xf0005000),
  172. },
  173. {
  174. /* Loose */
  175. cpu_to_le32(0xaaaaaaaa),
  176. cpu_to_le32(0xaaaaaaaa),
  177. cpu_to_le32(0xaaaaaaaa),
  178. cpu_to_le32(0xaaaaaaaa),
  179. cpu_to_le32(0xcc00ff28),
  180. cpu_to_le32(0x0000aaaa),
  181. cpu_to_le32(0xcc00aaaa),
  182. cpu_to_le32(0x0000aaaa),
  183. cpu_to_le32(0x00000000),
  184. cpu_to_le32(0x00000000),
  185. cpu_to_le32(0xf0005000),
  186. cpu_to_le32(0xf0005000),
  187. },
  188. {
  189. /* Tx Tx disabled */
  190. cpu_to_le32(0xaaaaaaaa),
  191. cpu_to_le32(0xaaaaaaaa),
  192. cpu_to_le32(0xeeaaaaaa),
  193. cpu_to_le32(0xaaaaaaaa),
  194. cpu_to_le32(0xcc00ff28),
  195. cpu_to_le32(0x0000aaaa),
  196. cpu_to_le32(0xcc00aaaa),
  197. cpu_to_le32(0x0000aaaa),
  198. cpu_to_le32(0xc0004000),
  199. cpu_to_le32(0xc0004000),
  200. cpu_to_le32(0xf0005000),
  201. cpu_to_le32(0xf0005000),
  202. },
  203. };
  204. /* 20MHz / 40MHz below / 40Mhz above*/
  205. static const __le64 iwl_ci_mask[][3] = {
  206. /* dummy entry for channel 0 */
  207. {cpu_to_le64(0), cpu_to_le64(0), cpu_to_le64(0)},
  208. {
  209. cpu_to_le64(0x0000001FFFULL),
  210. cpu_to_le64(0x0ULL),
  211. cpu_to_le64(0x00007FFFFFULL),
  212. },
  213. {
  214. cpu_to_le64(0x000000FFFFULL),
  215. cpu_to_le64(0x0ULL),
  216. cpu_to_le64(0x0003FFFFFFULL),
  217. },
  218. {
  219. cpu_to_le64(0x000003FFFCULL),
  220. cpu_to_le64(0x0ULL),
  221. cpu_to_le64(0x000FFFFFFCULL),
  222. },
  223. {
  224. cpu_to_le64(0x00001FFFE0ULL),
  225. cpu_to_le64(0x0ULL),
  226. cpu_to_le64(0x007FFFFFE0ULL),
  227. },
  228. {
  229. cpu_to_le64(0x00007FFF80ULL),
  230. cpu_to_le64(0x00007FFFFFULL),
  231. cpu_to_le64(0x01FFFFFF80ULL),
  232. },
  233. {
  234. cpu_to_le64(0x0003FFFC00ULL),
  235. cpu_to_le64(0x0003FFFFFFULL),
  236. cpu_to_le64(0x0FFFFFFC00ULL),
  237. },
  238. {
  239. cpu_to_le64(0x000FFFF000ULL),
  240. cpu_to_le64(0x000FFFFFFCULL),
  241. cpu_to_le64(0x3FFFFFF000ULL),
  242. },
  243. {
  244. cpu_to_le64(0x007FFF8000ULL),
  245. cpu_to_le64(0x007FFFFFE0ULL),
  246. cpu_to_le64(0xFFFFFF8000ULL),
  247. },
  248. {
  249. cpu_to_le64(0x01FFFE0000ULL),
  250. cpu_to_le64(0x01FFFFFF80ULL),
  251. cpu_to_le64(0xFFFFFE0000ULL),
  252. },
  253. {
  254. cpu_to_le64(0x0FFFF00000ULL),
  255. cpu_to_le64(0x0FFFFFFC00ULL),
  256. cpu_to_le64(0x0ULL),
  257. },
  258. {
  259. cpu_to_le64(0x3FFFC00000ULL),
  260. cpu_to_le64(0x3FFFFFF000ULL),
  261. cpu_to_le64(0x0)
  262. },
  263. {
  264. cpu_to_le64(0xFFFE000000ULL),
  265. cpu_to_le64(0xFFFFFF8000ULL),
  266. cpu_to_le64(0x0)
  267. },
  268. {
  269. cpu_to_le64(0xFFF8000000ULL),
  270. cpu_to_le64(0xFFFFFE0000ULL),
  271. cpu_to_le64(0x0)
  272. },
  273. {
  274. cpu_to_le64(0xFFC0000000ULL),
  275. cpu_to_le64(0x0ULL),
  276. cpu_to_le64(0x0ULL)
  277. },
  278. };
  279. enum iwl_bt_kill_msk {
  280. BT_KILL_MSK_DEFAULT,
  281. BT_KILL_MSK_NEVER,
  282. BT_KILL_MSK_ALWAYS,
  283. BT_KILL_MSK_MAX,
  284. };
  285. static const u32 iwl_bt_ctl_kill_msk[BT_KILL_MSK_MAX] = {
  286. [BT_KILL_MSK_DEFAULT] = 0xfffffc00,
  287. [BT_KILL_MSK_NEVER] = 0xffffffff,
  288. [BT_KILL_MSK_ALWAYS] = 0,
  289. };
  290. static const u8 iwl_bt_cts_kill_msk[BT_MAX_AG][BT_COEX_MAX_LUT] = {
  291. {
  292. BT_KILL_MSK_ALWAYS,
  293. BT_KILL_MSK_ALWAYS,
  294. BT_KILL_MSK_ALWAYS,
  295. },
  296. {
  297. BT_KILL_MSK_NEVER,
  298. BT_KILL_MSK_NEVER,
  299. BT_KILL_MSK_NEVER,
  300. },
  301. {
  302. BT_KILL_MSK_NEVER,
  303. BT_KILL_MSK_NEVER,
  304. BT_KILL_MSK_NEVER,
  305. },
  306. {
  307. BT_KILL_MSK_DEFAULT,
  308. BT_KILL_MSK_NEVER,
  309. BT_KILL_MSK_DEFAULT,
  310. },
  311. };
  312. static const u8 iwl_bt_ack_kill_msk[BT_MAX_AG][BT_COEX_MAX_LUT] = {
  313. {
  314. BT_KILL_MSK_ALWAYS,
  315. BT_KILL_MSK_ALWAYS,
  316. BT_KILL_MSK_ALWAYS,
  317. },
  318. {
  319. BT_KILL_MSK_ALWAYS,
  320. BT_KILL_MSK_ALWAYS,
  321. BT_KILL_MSK_ALWAYS,
  322. },
  323. {
  324. BT_KILL_MSK_ALWAYS,
  325. BT_KILL_MSK_ALWAYS,
  326. BT_KILL_MSK_ALWAYS,
  327. },
  328. {
  329. BT_KILL_MSK_DEFAULT,
  330. BT_KILL_MSK_ALWAYS,
  331. BT_KILL_MSK_DEFAULT,
  332. },
  333. };
  334. struct corunning_block_luts {
  335. u8 range;
  336. __le32 lut20[BT_COEX_CORUN_LUT_SIZE];
  337. };
  338. /*
  339. * Ranges for the antenna coupling calibration / co-running block LUT:
  340. * LUT0: [ 0, 12[
  341. * LUT1: [12, 20[
  342. * LUT2: [20, 21[
  343. * LUT3: [21, 23[
  344. * LUT4: [23, 27[
  345. * LUT5: [27, 30[
  346. * LUT6: [30, 32[
  347. * LUT7: [32, 33[
  348. * LUT8: [33, - [
  349. */
  350. static const struct corunning_block_luts antenna_coupling_ranges[] = {
  351. {
  352. .range = 0,
  353. .lut20 = {
  354. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  355. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  356. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  357. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  358. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  359. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  360. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  361. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  362. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  363. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  364. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  365. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  366. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  367. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  368. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  369. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  370. },
  371. },
  372. {
  373. .range = 12,
  374. .lut20 = {
  375. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  376. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  377. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  378. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  379. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  380. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  381. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  382. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  383. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  384. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  385. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  386. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  387. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  388. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  389. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  390. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  391. },
  392. },
  393. {
  394. .range = 20,
  395. .lut20 = {
  396. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  397. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  398. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  399. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  400. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  401. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  402. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  403. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  404. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  405. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  406. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  407. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  408. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  409. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  410. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  411. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  412. },
  413. },
  414. {
  415. .range = 21,
  416. .lut20 = {
  417. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  418. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  419. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  420. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  421. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  422. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  423. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  424. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  425. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  426. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  427. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  428. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  429. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  430. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  431. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  432. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  433. },
  434. },
  435. {
  436. .range = 23,
  437. .lut20 = {
  438. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  439. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  440. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  441. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  442. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  443. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  444. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  445. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  446. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  447. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  448. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  449. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  450. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  451. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  452. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  453. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  454. },
  455. },
  456. {
  457. .range = 27,
  458. .lut20 = {
  459. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  460. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  461. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  462. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  463. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  464. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  465. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  466. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  467. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  468. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  469. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  470. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  471. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  472. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  473. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  474. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  475. },
  476. },
  477. {
  478. .range = 30,
  479. .lut20 = {
  480. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  481. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  482. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  483. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  484. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  485. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  486. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  487. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  488. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  489. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  490. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  491. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  492. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  493. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  494. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  495. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  496. },
  497. },
  498. {
  499. .range = 32,
  500. .lut20 = {
  501. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  502. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  503. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  504. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  505. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  506. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  507. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  508. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  509. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  510. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  511. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  512. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  513. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  514. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  515. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  516. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  517. },
  518. },
  519. {
  520. .range = 33,
  521. .lut20 = {
  522. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  523. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  524. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  525. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  526. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  527. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  528. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  529. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  530. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  531. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  532. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  533. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  534. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  535. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  536. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  537. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  538. },
  539. },
  540. };
  541. static enum iwl_bt_coex_lut_type
  542. iwl_get_coex_type(struct iwl_mvm *mvm, const struct ieee80211_vif *vif)
  543. {
  544. struct ieee80211_chanctx_conf *chanctx_conf;
  545. enum iwl_bt_coex_lut_type ret;
  546. u16 phy_ctx_id;
  547. /*
  548. * Checking that we hold mvm->mutex is a good idea, but the rate
  549. * control can't acquire the mutex since it runs in Tx path.
  550. * So this is racy in that case, but in the worst case, the AMPDU
  551. * size limit will be wrong for a short time which is not a big
  552. * issue.
  553. */
  554. rcu_read_lock();
  555. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  556. if (!chanctx_conf ||
  557. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ) {
  558. rcu_read_unlock();
  559. return BT_COEX_INVALID_LUT;
  560. }
  561. ret = BT_COEX_TX_DIS_LUT;
  562. if (mvm->cfg->bt_shared_single_ant) {
  563. rcu_read_unlock();
  564. return ret;
  565. }
  566. phy_ctx_id = *((u16 *)chanctx_conf->drv_priv);
  567. if (mvm->last_bt_ci_cmd_old.primary_ch_phy_id == phy_ctx_id)
  568. ret = le32_to_cpu(mvm->last_bt_notif_old.primary_ch_lut);
  569. else if (mvm->last_bt_ci_cmd_old.secondary_ch_phy_id == phy_ctx_id)
  570. ret = le32_to_cpu(mvm->last_bt_notif_old.secondary_ch_lut);
  571. /* else - default = TX TX disallowed */
  572. rcu_read_unlock();
  573. return ret;
  574. }
  575. int iwl_send_bt_init_conf_old(struct iwl_mvm *mvm)
  576. {
  577. struct iwl_bt_coex_cmd_old *bt_cmd;
  578. struct iwl_host_cmd cmd = {
  579. .id = BT_CONFIG,
  580. .len = { sizeof(*bt_cmd), },
  581. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  582. };
  583. int ret;
  584. u32 flags;
  585. ret = iwl_send_bt_prio_tbl(mvm);
  586. if (ret)
  587. return ret;
  588. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  589. if (!bt_cmd)
  590. return -ENOMEM;
  591. cmd.data[0] = bt_cmd;
  592. lockdep_assert_held(&mvm->mutex);
  593. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) {
  594. switch (mvm->bt_force_ant_mode) {
  595. case BT_FORCE_ANT_AUTO:
  596. flags = BT_COEX_AUTO_OLD;
  597. break;
  598. case BT_FORCE_ANT_BT:
  599. flags = BT_COEX_BT_OLD;
  600. break;
  601. case BT_FORCE_ANT_WIFI:
  602. flags = BT_COEX_WIFI_OLD;
  603. break;
  604. default:
  605. WARN_ON(1);
  606. flags = 0;
  607. }
  608. bt_cmd->flags = cpu_to_le32(flags);
  609. bt_cmd->valid_bit_msk = cpu_to_le32(BT_VALID_ENABLE);
  610. goto send_cmd;
  611. }
  612. bt_cmd->max_kill = 5;
  613. bt_cmd->bt4_antenna_isolation_thr =
  614. IWL_MVM_BT_COEX_ANTENNA_COUPLING_THRS;
  615. bt_cmd->bt4_antenna_isolation = iwlwifi_mod_params.ant_coupling;
  616. bt_cmd->bt4_tx_tx_delta_freq_thr = 15;
  617. bt_cmd->bt4_tx_rx_max_freq0 = 15;
  618. bt_cmd->override_primary_lut = BT_COEX_INVALID_LUT;
  619. bt_cmd->override_secondary_lut = BT_COEX_INVALID_LUT;
  620. flags = iwlwifi_mod_params.bt_coex_active ?
  621. BT_COEX_NW_OLD : BT_COEX_DISABLE_OLD;
  622. bt_cmd->flags = cpu_to_le32(flags);
  623. bt_cmd->valid_bit_msk = cpu_to_le32(BT_VALID_ENABLE |
  624. BT_VALID_BT_PRIO_BOOST |
  625. BT_VALID_MAX_KILL |
  626. BT_VALID_3W_TMRS |
  627. BT_VALID_KILL_ACK |
  628. BT_VALID_KILL_CTS |
  629. BT_VALID_REDUCED_TX_POWER |
  630. BT_VALID_LUT |
  631. BT_VALID_WIFI_RX_SW_PRIO_BOOST |
  632. BT_VALID_WIFI_TX_SW_PRIO_BOOST |
  633. BT_VALID_ANT_ISOLATION |
  634. BT_VALID_ANT_ISOLATION_THRS |
  635. BT_VALID_TXTX_DELTA_FREQ_THRS |
  636. BT_VALID_TXRX_MAX_FREQ_0 |
  637. BT_VALID_SYNC_TO_SCO |
  638. BT_VALID_TTC |
  639. BT_VALID_RRC);
  640. if (IWL_MVM_BT_COEX_SYNC2SCO)
  641. bt_cmd->flags |= cpu_to_le32(BT_COEX_SYNC2SCO);
  642. if (iwl_mvm_bt_is_plcr_supported(mvm)) {
  643. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_CORUN_LUT_20 |
  644. BT_VALID_CORUN_LUT_40);
  645. bt_cmd->flags |= cpu_to_le32(BT_COEX_CORUNNING);
  646. }
  647. if (IWL_MVM_BT_COEX_MPLUT) {
  648. bt_cmd->flags |= cpu_to_le32(BT_COEX_MPLUT);
  649. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_MULTI_PRIO_LUT);
  650. }
  651. if (IWL_MVM_BT_COEX_TTC)
  652. bt_cmd->flags |= cpu_to_le32(BT_COEX_TTC);
  653. if (iwl_mvm_bt_is_rrc_supported(mvm))
  654. bt_cmd->flags |= cpu_to_le32(BT_COEX_RRC);
  655. if (mvm->cfg->bt_shared_single_ant)
  656. memcpy(&bt_cmd->decision_lut, iwl_single_shared_ant,
  657. sizeof(iwl_single_shared_ant));
  658. else
  659. memcpy(&bt_cmd->decision_lut, iwl_combined_lookup,
  660. sizeof(iwl_combined_lookup));
  661. /* Take first Co-running block LUT to get started */
  662. memcpy(bt_cmd->bt4_corun_lut20, antenna_coupling_ranges[0].lut20,
  663. sizeof(bt_cmd->bt4_corun_lut20));
  664. memcpy(bt_cmd->bt4_corun_lut40, antenna_coupling_ranges[0].lut20,
  665. sizeof(bt_cmd->bt4_corun_lut40));
  666. memcpy(&bt_cmd->bt_prio_boost, iwl_bt_prio_boost,
  667. sizeof(iwl_bt_prio_boost));
  668. bt_cmd->bt4_multiprio_lut[0] = cpu_to_le32(IWL_MVM_BT_COEX_MPLUT_REG0);
  669. bt_cmd->bt4_multiprio_lut[1] = cpu_to_le32(IWL_MVM_BT_COEX_MPLUT_REG1);
  670. send_cmd:
  671. memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
  672. memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
  673. ret = iwl_mvm_send_cmd(mvm, &cmd);
  674. kfree(bt_cmd);
  675. return ret;
  676. }
  677. static int iwl_mvm_bt_udpate_ctrl_kill_msk(struct iwl_mvm *mvm)
  678. {
  679. struct iwl_bt_coex_profile_notif_old *notif = &mvm->last_bt_notif_old;
  680. u32 primary_lut = le32_to_cpu(notif->primary_ch_lut);
  681. u32 ag = le32_to_cpu(notif->bt_activity_grading);
  682. struct iwl_bt_coex_cmd_old *bt_cmd;
  683. u8 ack_kill_msk, cts_kill_msk;
  684. struct iwl_host_cmd cmd = {
  685. .id = BT_CONFIG,
  686. .data[0] = &bt_cmd,
  687. .len = { sizeof(*bt_cmd), },
  688. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  689. };
  690. int ret = 0;
  691. lockdep_assert_held(&mvm->mutex);
  692. ack_kill_msk = iwl_bt_ack_kill_msk[ag][primary_lut];
  693. cts_kill_msk = iwl_bt_cts_kill_msk[ag][primary_lut];
  694. if (mvm->bt_ack_kill_msk[0] == ack_kill_msk &&
  695. mvm->bt_cts_kill_msk[0] == cts_kill_msk)
  696. return 0;
  697. mvm->bt_ack_kill_msk[0] = ack_kill_msk;
  698. mvm->bt_cts_kill_msk[0] = cts_kill_msk;
  699. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  700. if (!bt_cmd)
  701. return -ENOMEM;
  702. cmd.data[0] = bt_cmd;
  703. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  704. bt_cmd->kill_ack_msk = cpu_to_le32(iwl_bt_ctl_kill_msk[ack_kill_msk]);
  705. bt_cmd->kill_cts_msk = cpu_to_le32(iwl_bt_ctl_kill_msk[cts_kill_msk]);
  706. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_ENABLE |
  707. BT_VALID_KILL_ACK |
  708. BT_VALID_KILL_CTS);
  709. ret = iwl_mvm_send_cmd(mvm, &cmd);
  710. kfree(bt_cmd);
  711. return ret;
  712. }
  713. static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id,
  714. bool enable)
  715. {
  716. struct iwl_bt_coex_cmd_old *bt_cmd;
  717. /* Send ASYNC since this can be sent from an atomic context */
  718. struct iwl_host_cmd cmd = {
  719. .id = BT_CONFIG,
  720. .len = { sizeof(*bt_cmd), },
  721. .dataflags = { IWL_HCMD_DFL_DUP, },
  722. .flags = CMD_ASYNC,
  723. };
  724. struct iwl_mvm_sta *mvmsta;
  725. int ret;
  726. mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
  727. if (!mvmsta)
  728. return 0;
  729. /* nothing to do */
  730. if (mvmsta->bt_reduced_txpower == enable)
  731. return 0;
  732. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_ATOMIC);
  733. if (!bt_cmd)
  734. return -ENOMEM;
  735. cmd.data[0] = bt_cmd;
  736. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  737. bt_cmd->valid_bit_msk =
  738. cpu_to_le32(BT_VALID_ENABLE | BT_VALID_REDUCED_TX_POWER);
  739. bt_cmd->bt_reduced_tx_power = sta_id;
  740. if (enable)
  741. bt_cmd->bt_reduced_tx_power |= BT_REDUCED_TX_POWER_BIT;
  742. IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n",
  743. enable ? "en" : "dis", sta_id);
  744. mvmsta->bt_reduced_txpower = enable;
  745. ret = iwl_mvm_send_cmd(mvm, &cmd);
  746. kfree(bt_cmd);
  747. return ret;
  748. }
  749. struct iwl_bt_iterator_data {
  750. struct iwl_bt_coex_profile_notif_old *notif;
  751. struct iwl_mvm *mvm;
  752. struct ieee80211_chanctx_conf *primary;
  753. struct ieee80211_chanctx_conf *secondary;
  754. bool primary_ll;
  755. };
  756. static inline
  757. void iwl_mvm_bt_coex_enable_rssi_event(struct iwl_mvm *mvm,
  758. struct ieee80211_vif *vif,
  759. bool enable, int rssi)
  760. {
  761. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  762. mvmvif->bf_data.last_bt_coex_event = rssi;
  763. mvmvif->bf_data.bt_coex_max_thold =
  764. enable ? -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH : 0;
  765. mvmvif->bf_data.bt_coex_min_thold =
  766. enable ? -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH : 0;
  767. }
  768. /* must be called under rcu_read_lock */
  769. static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac,
  770. struct ieee80211_vif *vif)
  771. {
  772. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  773. struct iwl_bt_iterator_data *data = _data;
  774. struct iwl_mvm *mvm = data->mvm;
  775. struct ieee80211_chanctx_conf *chanctx_conf;
  776. enum ieee80211_smps_mode smps_mode;
  777. u32 bt_activity_grading;
  778. int ave_rssi;
  779. lockdep_assert_held(&mvm->mutex);
  780. switch (vif->type) {
  781. case NL80211_IFTYPE_STATION:
  782. /* default smps_mode for BSS / P2P client is AUTOMATIC */
  783. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  784. break;
  785. case NL80211_IFTYPE_AP:
  786. if (!mvmvif->ap_ibss_active)
  787. return;
  788. break;
  789. default:
  790. return;
  791. }
  792. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  793. /* If channel context is invalid or not on 2.4GHz .. */
  794. if ((!chanctx_conf ||
  795. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ)) {
  796. if (vif->type == NL80211_IFTYPE_STATION) {
  797. /* ... relax constraints and disable rssi events */
  798. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  799. smps_mode);
  800. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  801. false);
  802. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  803. }
  804. return;
  805. }
  806. bt_activity_grading = le32_to_cpu(data->notif->bt_activity_grading);
  807. if (bt_activity_grading >= BT_HIGH_TRAFFIC)
  808. smps_mode = IEEE80211_SMPS_STATIC;
  809. else if (bt_activity_grading >= BT_LOW_TRAFFIC)
  810. smps_mode = vif->type == NL80211_IFTYPE_AP ?
  811. IEEE80211_SMPS_OFF :
  812. IEEE80211_SMPS_DYNAMIC;
  813. /* relax SMPS contraints for next association */
  814. if (!vif->bss_conf.assoc)
  815. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  816. if (mvmvif->phy_ctxt &&
  817. data->notif->rrc_enabled & BIT(mvmvif->phy_ctxt->id))
  818. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  819. IWL_DEBUG_COEX(data->mvm,
  820. "mac %d: bt_status %d bt_activity_grading %d smps_req %d\n",
  821. mvmvif->id, data->notif->bt_status, bt_activity_grading,
  822. smps_mode);
  823. if (vif->type == NL80211_IFTYPE_STATION)
  824. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  825. smps_mode);
  826. /* low latency is always primary */
  827. if (iwl_mvm_vif_low_latency(mvmvif)) {
  828. data->primary_ll = true;
  829. data->secondary = data->primary;
  830. data->primary = chanctx_conf;
  831. }
  832. if (vif->type == NL80211_IFTYPE_AP) {
  833. if (!mvmvif->ap_ibss_active)
  834. return;
  835. if (chanctx_conf == data->primary)
  836. return;
  837. if (!data->primary_ll) {
  838. /*
  839. * downgrade the current primary no matter what its
  840. * type is.
  841. */
  842. data->secondary = data->primary;
  843. data->primary = chanctx_conf;
  844. } else {
  845. /* there is low latency vif - we will be secondary */
  846. data->secondary = chanctx_conf;
  847. }
  848. return;
  849. }
  850. /*
  851. * STA / P2P Client, try to be primary if first vif. If we are in low
  852. * latency mode, we are already in primary and just don't do much
  853. */
  854. if (!data->primary || data->primary == chanctx_conf)
  855. data->primary = chanctx_conf;
  856. else if (!data->secondary)
  857. /* if secondary is not NULL, it might be a GO */
  858. data->secondary = chanctx_conf;
  859. /*
  860. * don't reduce the Tx power if one of these is true:
  861. * we are in LOOSE
  862. * single share antenna product
  863. * BT is active
  864. * we are associated
  865. */
  866. if (iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT ||
  867. mvm->cfg->bt_shared_single_ant || !vif->bss_conf.assoc ||
  868. !data->notif->bt_status) {
  869. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false);
  870. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  871. return;
  872. }
  873. /* try to get the avg rssi from fw */
  874. ave_rssi = mvmvif->bf_data.ave_beacon_signal;
  875. /* if the RSSI isn't valid, fake it is very low */
  876. if (!ave_rssi)
  877. ave_rssi = -100;
  878. if (ave_rssi > -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH) {
  879. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true))
  880. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  881. } else if (ave_rssi < -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH) {
  882. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
  883. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  884. }
  885. /* Begin to monitor the RSSI: it may influence the reduced Tx power */
  886. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, true, ave_rssi);
  887. }
  888. static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm)
  889. {
  890. struct iwl_bt_iterator_data data = {
  891. .mvm = mvm,
  892. .notif = &mvm->last_bt_notif_old,
  893. };
  894. struct iwl_bt_coex_ci_cmd_old cmd = {};
  895. u8 ci_bw_idx;
  896. /* Ignore updates if we are in force mode */
  897. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  898. return;
  899. rcu_read_lock();
  900. ieee80211_iterate_active_interfaces_atomic(
  901. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  902. iwl_mvm_bt_notif_iterator, &data);
  903. if (data.primary) {
  904. struct ieee80211_chanctx_conf *chan = data.primary;
  905. if (WARN_ON(!chan->def.chan)) {
  906. rcu_read_unlock();
  907. return;
  908. }
  909. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  910. ci_bw_idx = 0;
  911. cmd.co_run_bw_primary = 0;
  912. } else {
  913. cmd.co_run_bw_primary = 1;
  914. if (chan->def.center_freq1 >
  915. chan->def.chan->center_freq)
  916. ci_bw_idx = 2;
  917. else
  918. ci_bw_idx = 1;
  919. }
  920. cmd.bt_primary_ci =
  921. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  922. cmd.primary_ch_phy_id = *((u16 *)data.primary->drv_priv);
  923. }
  924. if (data.secondary) {
  925. struct ieee80211_chanctx_conf *chan = data.secondary;
  926. if (WARN_ON(!data.secondary->def.chan)) {
  927. rcu_read_unlock();
  928. return;
  929. }
  930. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  931. ci_bw_idx = 0;
  932. cmd.co_run_bw_secondary = 0;
  933. } else {
  934. cmd.co_run_bw_secondary = 1;
  935. if (chan->def.center_freq1 >
  936. chan->def.chan->center_freq)
  937. ci_bw_idx = 2;
  938. else
  939. ci_bw_idx = 1;
  940. }
  941. cmd.bt_secondary_ci =
  942. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  943. cmd.secondary_ch_phy_id = *((u16 *)data.secondary->drv_priv);
  944. }
  945. rcu_read_unlock();
  946. /* Don't spam the fw with the same command over and over */
  947. if (memcmp(&cmd, &mvm->last_bt_ci_cmd_old, sizeof(cmd))) {
  948. if (iwl_mvm_send_cmd_pdu(mvm, BT_COEX_CI, 0,
  949. sizeof(cmd), &cmd))
  950. IWL_ERR(mvm, "Failed to send BT_CI cmd\n");
  951. memcpy(&mvm->last_bt_ci_cmd_old, &cmd, sizeof(cmd));
  952. }
  953. if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm))
  954. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  955. }
  956. int iwl_mvm_rx_bt_coex_notif_old(struct iwl_mvm *mvm,
  957. struct iwl_rx_cmd_buffer *rxb,
  958. struct iwl_device_cmd *dev_cmd)
  959. {
  960. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  961. struct iwl_bt_coex_profile_notif_old *notif = (void *)pkt->data;
  962. IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n");
  963. IWL_DEBUG_COEX(mvm, "\tBT status: %s\n",
  964. notif->bt_status ? "ON" : "OFF");
  965. IWL_DEBUG_COEX(mvm, "\tBT open conn %d\n", notif->bt_open_conn);
  966. IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n", notif->bt_ci_compliance);
  967. IWL_DEBUG_COEX(mvm, "\tBT primary_ch_lut %d\n",
  968. le32_to_cpu(notif->primary_ch_lut));
  969. IWL_DEBUG_COEX(mvm, "\tBT secondary_ch_lut %d\n",
  970. le32_to_cpu(notif->secondary_ch_lut));
  971. IWL_DEBUG_COEX(mvm, "\tBT activity grading %d\n",
  972. le32_to_cpu(notif->bt_activity_grading));
  973. IWL_DEBUG_COEX(mvm, "\tBT agg traffic load %d\n",
  974. notif->bt_agg_traffic_load);
  975. /* remember this notification for future use: rssi fluctuations */
  976. memcpy(&mvm->last_bt_notif_old, notif, sizeof(mvm->last_bt_notif_old));
  977. iwl_mvm_bt_coex_notif_handle(mvm);
  978. /*
  979. * This is an async handler for a notification, returning anything other
  980. * than 0 doesn't make sense even if HCMD failed.
  981. */
  982. return 0;
  983. }
  984. static void iwl_mvm_bt_rssi_iterator(void *_data, u8 *mac,
  985. struct ieee80211_vif *vif)
  986. {
  987. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  988. struct iwl_bt_iterator_data *data = _data;
  989. struct iwl_mvm *mvm = data->mvm;
  990. struct ieee80211_sta *sta;
  991. struct iwl_mvm_sta *mvmsta;
  992. struct ieee80211_chanctx_conf *chanctx_conf;
  993. rcu_read_lock();
  994. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  995. /* If channel context is invalid or not on 2.4GHz - don't count it */
  996. if (!chanctx_conf ||
  997. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ) {
  998. rcu_read_unlock();
  999. return;
  1000. }
  1001. rcu_read_unlock();
  1002. if (vif->type != NL80211_IFTYPE_STATION ||
  1003. mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  1004. return;
  1005. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
  1006. lockdep_is_held(&mvm->mutex));
  1007. /* This can happen if the station has been removed right now */
  1008. if (IS_ERR_OR_NULL(sta))
  1009. return;
  1010. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  1011. }
  1012. void iwl_mvm_bt_rssi_event_old(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  1013. enum ieee80211_rssi_event_data rssi_event)
  1014. {
  1015. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1016. struct iwl_bt_iterator_data data = {
  1017. .mvm = mvm,
  1018. };
  1019. int ret;
  1020. lockdep_assert_held(&mvm->mutex);
  1021. /* Ignore updates if we are in force mode */
  1022. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  1023. return;
  1024. /*
  1025. * Rssi update while not associated - can happen since the statistics
  1026. * are handled asynchronously
  1027. */
  1028. if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  1029. return;
  1030. /* No BT - reports should be disabled */
  1031. if (!mvm->last_bt_notif_old.bt_status)
  1032. return;
  1033. IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid,
  1034. rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW");
  1035. /*
  1036. * Check if rssi is good enough for reduced Tx power, but not in loose
  1037. * scheme.
  1038. */
  1039. if (rssi_event == RSSI_EVENT_LOW || mvm->cfg->bt_shared_single_ant ||
  1040. iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT)
  1041. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  1042. false);
  1043. else
  1044. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true);
  1045. if (ret)
  1046. IWL_ERR(mvm, "couldn't send BT_CONFIG HCMD upon RSSI event\n");
  1047. ieee80211_iterate_active_interfaces_atomic(
  1048. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  1049. iwl_mvm_bt_rssi_iterator, &data);
  1050. if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm))
  1051. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  1052. }
  1053. #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000)
  1054. #define LINK_QUAL_AGG_TIME_LIMIT_BT_ACT (1200)
  1055. u16 iwl_mvm_coex_agg_time_limit_old(struct iwl_mvm *mvm,
  1056. struct ieee80211_sta *sta)
  1057. {
  1058. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  1059. enum iwl_bt_coex_lut_type lut_type;
  1060. if (le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading) <
  1061. BT_HIGH_TRAFFIC)
  1062. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  1063. if (mvm->last_bt_notif_old.ttc_enabled)
  1064. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  1065. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  1066. if (lut_type == BT_COEX_LOOSE_LUT || lut_type == BT_COEX_INVALID_LUT)
  1067. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  1068. /* tight coex, high bt traffic, reduce AGG time limit */
  1069. return LINK_QUAL_AGG_TIME_LIMIT_BT_ACT;
  1070. }
  1071. bool iwl_mvm_bt_coex_is_mimo_allowed_old(struct iwl_mvm *mvm,
  1072. struct ieee80211_sta *sta)
  1073. {
  1074. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  1075. enum iwl_bt_coex_lut_type lut_type;
  1076. if (mvm->last_bt_notif_old.ttc_enabled)
  1077. return true;
  1078. if (le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading) <
  1079. BT_HIGH_TRAFFIC)
  1080. return true;
  1081. /*
  1082. * In Tight / TxTxDis, BT can't Rx while we Tx, so use both antennas
  1083. * since BT is already killed.
  1084. * In Loose, BT can Rx while we Tx, so forbid MIMO to let BT Rx while
  1085. * we Tx.
  1086. * When we are in 5GHz, we'll get BT_COEX_INVALID_LUT allowing MIMO.
  1087. */
  1088. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  1089. return lut_type != BT_COEX_LOOSE_LUT;
  1090. }
  1091. bool iwl_mvm_bt_coex_is_shared_ant_avail_old(struct iwl_mvm *mvm)
  1092. {
  1093. u32 ag = le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading);
  1094. return ag < BT_HIGH_TRAFFIC;
  1095. }
  1096. bool iwl_mvm_bt_coex_is_tpc_allowed_old(struct iwl_mvm *mvm,
  1097. enum ieee80211_band band)
  1098. {
  1099. u32 bt_activity =
  1100. le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading);
  1101. if (band != IEEE80211_BAND_2GHZ)
  1102. return false;
  1103. return bt_activity >= BT_LOW_TRAFFIC;
  1104. }
  1105. void iwl_mvm_bt_coex_vif_change_old(struct iwl_mvm *mvm)
  1106. {
  1107. iwl_mvm_bt_coex_notif_handle(mvm);
  1108. }
  1109. int iwl_mvm_rx_ant_coupling_notif_old(struct iwl_mvm *mvm,
  1110. struct iwl_rx_cmd_buffer *rxb,
  1111. struct iwl_device_cmd *dev_cmd)
  1112. {
  1113. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1114. u32 ant_isolation = le32_to_cpup((void *)pkt->data);
  1115. u8 __maybe_unused lower_bound, upper_bound;
  1116. int ret;
  1117. u8 lut;
  1118. struct iwl_bt_coex_cmd_old *bt_cmd;
  1119. struct iwl_host_cmd cmd = {
  1120. .id = BT_CONFIG,
  1121. .len = { sizeof(*bt_cmd), },
  1122. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  1123. };
  1124. if (!iwl_mvm_bt_is_plcr_supported(mvm))
  1125. return 0;
  1126. lockdep_assert_held(&mvm->mutex);
  1127. /* Ignore updates if we are in force mode */
  1128. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  1129. return 0;
  1130. if (ant_isolation == mvm->last_ant_isol)
  1131. return 0;
  1132. for (lut = 0; lut < ARRAY_SIZE(antenna_coupling_ranges) - 1; lut++)
  1133. if (ant_isolation < antenna_coupling_ranges[lut + 1].range)
  1134. break;
  1135. lower_bound = antenna_coupling_ranges[lut].range;
  1136. if (lut < ARRAY_SIZE(antenna_coupling_ranges) - 1)
  1137. upper_bound = antenna_coupling_ranges[lut + 1].range;
  1138. else
  1139. upper_bound = antenna_coupling_ranges[lut].range;
  1140. IWL_DEBUG_COEX(mvm, "Antenna isolation=%d in range [%d,%d[, lut=%d\n",
  1141. ant_isolation, lower_bound, upper_bound, lut);
  1142. mvm->last_ant_isol = ant_isolation;
  1143. if (mvm->last_corun_lut == lut)
  1144. return 0;
  1145. mvm->last_corun_lut = lut;
  1146. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  1147. if (!bt_cmd)
  1148. return 0;
  1149. cmd.data[0] = bt_cmd;
  1150. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  1151. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_ENABLE |
  1152. BT_VALID_CORUN_LUT_20 |
  1153. BT_VALID_CORUN_LUT_40);
  1154. /* For the moment, use the same LUT for 20GHz and 40GHz */
  1155. memcpy(bt_cmd->bt4_corun_lut20, antenna_coupling_ranges[lut].lut20,
  1156. sizeof(bt_cmd->bt4_corun_lut20));
  1157. memcpy(bt_cmd->bt4_corun_lut40, antenna_coupling_ranges[lut].lut20,
  1158. sizeof(bt_cmd->bt4_corun_lut40));
  1159. ret = iwl_mvm_send_cmd(mvm, &cmd);
  1160. kfree(bt_cmd);
  1161. return ret;
  1162. }