coex_legacy.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  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. struct corunning_block_luts {
  280. u8 range;
  281. __le32 lut20[BT_COEX_CORUN_LUT_SIZE];
  282. };
  283. /*
  284. * Ranges for the antenna coupling calibration / co-running block LUT:
  285. * LUT0: [ 0, 12[
  286. * LUT1: [12, 20[
  287. * LUT2: [20, 21[
  288. * LUT3: [21, 23[
  289. * LUT4: [23, 27[
  290. * LUT5: [27, 30[
  291. * LUT6: [30, 32[
  292. * LUT7: [32, 33[
  293. * LUT8: [33, - [
  294. */
  295. static const struct corunning_block_luts antenna_coupling_ranges[] = {
  296. {
  297. .range = 0,
  298. .lut20 = {
  299. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  300. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  301. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  302. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  303. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  304. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  305. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  306. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  307. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  308. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  309. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  310. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  311. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  312. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  313. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  314. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  315. },
  316. },
  317. {
  318. .range = 12,
  319. .lut20 = {
  320. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  321. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  322. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  323. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  324. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  325. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  326. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  327. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  328. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  329. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  330. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  331. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  332. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  333. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  334. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  335. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  336. },
  337. },
  338. {
  339. .range = 20,
  340. .lut20 = {
  341. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  342. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  343. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  344. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  345. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  346. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  347. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  348. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  349. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  350. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  351. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  352. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  353. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  358. },
  359. {
  360. .range = 21,
  361. .lut20 = {
  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. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  372. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  373. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  374. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  379. },
  380. {
  381. .range = 23,
  382. .lut20 = {
  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. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  393. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  394. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  395. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  400. },
  401. {
  402. .range = 27,
  403. .lut20 = {
  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. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  414. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  415. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  416. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  421. },
  422. {
  423. .range = 30,
  424. .lut20 = {
  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. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  435. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  436. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  437. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  442. },
  443. {
  444. .range = 32,
  445. .lut20 = {
  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. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  456. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  457. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  458. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  463. },
  464. {
  465. .range = 33,
  466. .lut20 = {
  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. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  477. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  478. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  479. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  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. },
  484. },
  485. };
  486. static enum iwl_bt_coex_lut_type
  487. iwl_get_coex_type(struct iwl_mvm *mvm, const struct ieee80211_vif *vif)
  488. {
  489. struct ieee80211_chanctx_conf *chanctx_conf;
  490. enum iwl_bt_coex_lut_type ret;
  491. u16 phy_ctx_id;
  492. /*
  493. * Checking that we hold mvm->mutex is a good idea, but the rate
  494. * control can't acquire the mutex since it runs in Tx path.
  495. * So this is racy in that case, but in the worst case, the AMPDU
  496. * size limit will be wrong for a short time which is not a big
  497. * issue.
  498. */
  499. rcu_read_lock();
  500. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  501. if (!chanctx_conf ||
  502. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ) {
  503. rcu_read_unlock();
  504. return BT_COEX_INVALID_LUT;
  505. }
  506. ret = BT_COEX_TX_DIS_LUT;
  507. if (mvm->cfg->bt_shared_single_ant) {
  508. rcu_read_unlock();
  509. return ret;
  510. }
  511. phy_ctx_id = *((u16 *)chanctx_conf->drv_priv);
  512. if (mvm->last_bt_ci_cmd_old.primary_ch_phy_id == phy_ctx_id)
  513. ret = le32_to_cpu(mvm->last_bt_notif_old.primary_ch_lut);
  514. else if (mvm->last_bt_ci_cmd_old.secondary_ch_phy_id == phy_ctx_id)
  515. ret = le32_to_cpu(mvm->last_bt_notif_old.secondary_ch_lut);
  516. /* else - default = TX TX disallowed */
  517. rcu_read_unlock();
  518. return ret;
  519. }
  520. int iwl_send_bt_init_conf_old(struct iwl_mvm *mvm)
  521. {
  522. struct iwl_bt_coex_cmd_old *bt_cmd;
  523. struct iwl_host_cmd cmd = {
  524. .id = BT_CONFIG,
  525. .len = { sizeof(*bt_cmd), },
  526. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  527. };
  528. int ret;
  529. u32 flags;
  530. ret = iwl_send_bt_prio_tbl(mvm);
  531. if (ret)
  532. return ret;
  533. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  534. if (!bt_cmd)
  535. return -ENOMEM;
  536. cmd.data[0] = bt_cmd;
  537. lockdep_assert_held(&mvm->mutex);
  538. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) {
  539. switch (mvm->bt_force_ant_mode) {
  540. case BT_FORCE_ANT_AUTO:
  541. flags = BT_COEX_AUTO_OLD;
  542. break;
  543. case BT_FORCE_ANT_BT:
  544. flags = BT_COEX_BT_OLD;
  545. break;
  546. case BT_FORCE_ANT_WIFI:
  547. flags = BT_COEX_WIFI_OLD;
  548. break;
  549. default:
  550. WARN_ON(1);
  551. flags = 0;
  552. }
  553. bt_cmd->flags = cpu_to_le32(flags);
  554. bt_cmd->valid_bit_msk = cpu_to_le32(BT_VALID_ENABLE);
  555. goto send_cmd;
  556. }
  557. bt_cmd->max_kill = 5;
  558. bt_cmd->bt4_antenna_isolation_thr =
  559. IWL_MVM_BT_COEX_ANTENNA_COUPLING_THRS;
  560. bt_cmd->bt4_antenna_isolation = iwlwifi_mod_params.ant_coupling;
  561. bt_cmd->bt4_tx_tx_delta_freq_thr = 15;
  562. bt_cmd->bt4_tx_rx_max_freq0 = 15;
  563. bt_cmd->override_primary_lut = BT_COEX_INVALID_LUT;
  564. bt_cmd->override_secondary_lut = BT_COEX_INVALID_LUT;
  565. flags = iwlwifi_mod_params.bt_coex_active ?
  566. BT_COEX_NW_OLD : BT_COEX_DISABLE_OLD;
  567. bt_cmd->flags = cpu_to_le32(flags);
  568. bt_cmd->valid_bit_msk = cpu_to_le32(BT_VALID_ENABLE |
  569. BT_VALID_BT_PRIO_BOOST |
  570. BT_VALID_MAX_KILL |
  571. BT_VALID_3W_TMRS |
  572. BT_VALID_KILL_ACK |
  573. BT_VALID_KILL_CTS |
  574. BT_VALID_REDUCED_TX_POWER |
  575. BT_VALID_LUT |
  576. BT_VALID_WIFI_RX_SW_PRIO_BOOST |
  577. BT_VALID_WIFI_TX_SW_PRIO_BOOST |
  578. BT_VALID_ANT_ISOLATION |
  579. BT_VALID_ANT_ISOLATION_THRS |
  580. BT_VALID_TXTX_DELTA_FREQ_THRS |
  581. BT_VALID_TXRX_MAX_FREQ_0 |
  582. BT_VALID_SYNC_TO_SCO |
  583. BT_VALID_TTC |
  584. BT_VALID_RRC);
  585. if (IWL_MVM_BT_COEX_SYNC2SCO)
  586. bt_cmd->flags |= cpu_to_le32(BT_COEX_SYNC2SCO);
  587. if (iwl_mvm_bt_is_plcr_supported(mvm)) {
  588. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_CORUN_LUT_20 |
  589. BT_VALID_CORUN_LUT_40);
  590. bt_cmd->flags |= cpu_to_le32(BT_COEX_CORUNNING);
  591. }
  592. if (IWL_MVM_BT_COEX_MPLUT) {
  593. bt_cmd->flags |= cpu_to_le32(BT_COEX_MPLUT);
  594. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_MULTI_PRIO_LUT);
  595. }
  596. if (IWL_MVM_BT_COEX_TTC)
  597. bt_cmd->flags |= cpu_to_le32(BT_COEX_TTC);
  598. if (IWL_MVM_BT_COEX_RRC)
  599. bt_cmd->flags |= cpu_to_le32(BT_COEX_RRC);
  600. if (mvm->cfg->bt_shared_single_ant)
  601. memcpy(&bt_cmd->decision_lut, iwl_single_shared_ant,
  602. sizeof(iwl_single_shared_ant));
  603. else
  604. memcpy(&bt_cmd->decision_lut, iwl_combined_lookup,
  605. sizeof(iwl_combined_lookup));
  606. /* Take first Co-running block LUT to get started */
  607. memcpy(bt_cmd->bt4_corun_lut20, antenna_coupling_ranges[0].lut20,
  608. sizeof(bt_cmd->bt4_corun_lut20));
  609. memcpy(bt_cmd->bt4_corun_lut40, antenna_coupling_ranges[0].lut20,
  610. sizeof(bt_cmd->bt4_corun_lut40));
  611. memcpy(&bt_cmd->bt_prio_boost, iwl_bt_prio_boost,
  612. sizeof(iwl_bt_prio_boost));
  613. bt_cmd->bt4_multiprio_lut[0] = cpu_to_le32(IWL_MVM_BT_COEX_MPLUT_REG0);
  614. bt_cmd->bt4_multiprio_lut[1] = cpu_to_le32(IWL_MVM_BT_COEX_MPLUT_REG1);
  615. send_cmd:
  616. memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
  617. memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
  618. ret = iwl_mvm_send_cmd(mvm, &cmd);
  619. kfree(bt_cmd);
  620. return ret;
  621. }
  622. static int iwl_mvm_bt_udpate_ctrl_kill_msk(struct iwl_mvm *mvm)
  623. {
  624. struct iwl_bt_coex_profile_notif_old *notif = &mvm->last_bt_notif_old;
  625. u32 primary_lut = le32_to_cpu(notif->primary_ch_lut);
  626. u32 ag = le32_to_cpu(notif->bt_activity_grading);
  627. struct iwl_bt_coex_cmd_old *bt_cmd;
  628. u8 ack_kill_msk, cts_kill_msk;
  629. struct iwl_host_cmd cmd = {
  630. .id = BT_CONFIG,
  631. .data[0] = &bt_cmd,
  632. .len = { sizeof(*bt_cmd), },
  633. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  634. };
  635. int ret = 0;
  636. lockdep_assert_held(&mvm->mutex);
  637. ack_kill_msk = iwl_bt_ack_kill_msk[ag][primary_lut];
  638. cts_kill_msk = iwl_bt_cts_kill_msk[ag][primary_lut];
  639. if (mvm->bt_ack_kill_msk[0] == ack_kill_msk &&
  640. mvm->bt_cts_kill_msk[0] == cts_kill_msk)
  641. return 0;
  642. mvm->bt_ack_kill_msk[0] = ack_kill_msk;
  643. mvm->bt_cts_kill_msk[0] = cts_kill_msk;
  644. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  645. if (!bt_cmd)
  646. return -ENOMEM;
  647. cmd.data[0] = bt_cmd;
  648. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  649. bt_cmd->kill_ack_msk = cpu_to_le32(iwl_bt_ctl_kill_msk[ack_kill_msk]);
  650. bt_cmd->kill_cts_msk = cpu_to_le32(iwl_bt_ctl_kill_msk[cts_kill_msk]);
  651. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_ENABLE |
  652. BT_VALID_KILL_ACK |
  653. BT_VALID_KILL_CTS);
  654. ret = iwl_mvm_send_cmd(mvm, &cmd);
  655. kfree(bt_cmd);
  656. return ret;
  657. }
  658. static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id,
  659. bool enable)
  660. {
  661. struct iwl_bt_coex_cmd_old *bt_cmd;
  662. /* Send ASYNC since this can be sent from an atomic context */
  663. struct iwl_host_cmd cmd = {
  664. .id = BT_CONFIG,
  665. .len = { sizeof(*bt_cmd), },
  666. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  667. .flags = CMD_ASYNC,
  668. };
  669. struct iwl_mvm_sta *mvmsta;
  670. int ret;
  671. mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
  672. if (!mvmsta)
  673. return 0;
  674. /* nothing to do */
  675. if (mvmsta->bt_reduced_txpower == enable)
  676. return 0;
  677. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_ATOMIC);
  678. if (!bt_cmd)
  679. return -ENOMEM;
  680. cmd.data[0] = bt_cmd;
  681. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  682. bt_cmd->valid_bit_msk =
  683. cpu_to_le32(BT_VALID_ENABLE | BT_VALID_REDUCED_TX_POWER);
  684. bt_cmd->bt_reduced_tx_power = sta_id;
  685. if (enable)
  686. bt_cmd->bt_reduced_tx_power |= BT_REDUCED_TX_POWER_BIT;
  687. IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n",
  688. enable ? "en" : "dis", sta_id);
  689. mvmsta->bt_reduced_txpower = enable;
  690. ret = iwl_mvm_send_cmd(mvm, &cmd);
  691. kfree(bt_cmd);
  692. return ret;
  693. }
  694. struct iwl_bt_iterator_data {
  695. struct iwl_bt_coex_profile_notif_old *notif;
  696. struct iwl_mvm *mvm;
  697. struct ieee80211_chanctx_conf *primary;
  698. struct ieee80211_chanctx_conf *secondary;
  699. bool primary_ll;
  700. };
  701. static inline
  702. void iwl_mvm_bt_coex_enable_rssi_event(struct iwl_mvm *mvm,
  703. struct ieee80211_vif *vif,
  704. bool enable, int rssi)
  705. {
  706. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  707. mvmvif->bf_data.last_bt_coex_event = rssi;
  708. mvmvif->bf_data.bt_coex_max_thold =
  709. enable ? -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH : 0;
  710. mvmvif->bf_data.bt_coex_min_thold =
  711. enable ? -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH : 0;
  712. }
  713. /* must be called under rcu_read_lock */
  714. static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac,
  715. struct ieee80211_vif *vif)
  716. {
  717. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  718. struct iwl_bt_iterator_data *data = _data;
  719. struct iwl_mvm *mvm = data->mvm;
  720. struct ieee80211_chanctx_conf *chanctx_conf;
  721. enum ieee80211_smps_mode smps_mode;
  722. u32 bt_activity_grading;
  723. int ave_rssi;
  724. lockdep_assert_held(&mvm->mutex);
  725. switch (vif->type) {
  726. case NL80211_IFTYPE_STATION:
  727. /* default smps_mode for BSS / P2P client is AUTOMATIC */
  728. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  729. break;
  730. case NL80211_IFTYPE_AP:
  731. if (!mvmvif->ap_ibss_active)
  732. return;
  733. break;
  734. default:
  735. return;
  736. }
  737. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  738. /* If channel context is invalid or not on 2.4GHz .. */
  739. if ((!chanctx_conf ||
  740. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ)) {
  741. if (vif->type == NL80211_IFTYPE_STATION) {
  742. /* ... relax constraints and disable rssi events */
  743. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  744. smps_mode);
  745. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  746. false);
  747. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  748. }
  749. return;
  750. }
  751. bt_activity_grading = le32_to_cpu(data->notif->bt_activity_grading);
  752. if (bt_activity_grading >= BT_HIGH_TRAFFIC)
  753. smps_mode = IEEE80211_SMPS_STATIC;
  754. else if (bt_activity_grading >= BT_LOW_TRAFFIC)
  755. smps_mode = vif->type == NL80211_IFTYPE_AP ?
  756. IEEE80211_SMPS_OFF :
  757. IEEE80211_SMPS_DYNAMIC;
  758. /* relax SMPS contraints for next association */
  759. if (!vif->bss_conf.assoc)
  760. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  761. if (mvmvif->phy_ctxt &&
  762. data->notif->rrc_enabled & BIT(mvmvif->phy_ctxt->id))
  763. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  764. IWL_DEBUG_COEX(data->mvm,
  765. "mac %d: bt_status %d bt_activity_grading %d smps_req %d\n",
  766. mvmvif->id, data->notif->bt_status, bt_activity_grading,
  767. smps_mode);
  768. if (vif->type == NL80211_IFTYPE_STATION)
  769. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  770. smps_mode);
  771. /* low latency is always primary */
  772. if (iwl_mvm_vif_low_latency(mvmvif)) {
  773. data->primary_ll = true;
  774. data->secondary = data->primary;
  775. data->primary = chanctx_conf;
  776. }
  777. if (vif->type == NL80211_IFTYPE_AP) {
  778. if (!mvmvif->ap_ibss_active)
  779. return;
  780. if (chanctx_conf == data->primary)
  781. return;
  782. if (!data->primary_ll) {
  783. /*
  784. * downgrade the current primary no matter what its
  785. * type is.
  786. */
  787. data->secondary = data->primary;
  788. data->primary = chanctx_conf;
  789. } else {
  790. /* there is low latency vif - we will be secondary */
  791. data->secondary = chanctx_conf;
  792. }
  793. return;
  794. }
  795. /*
  796. * STA / P2P Client, try to be primary if first vif. If we are in low
  797. * latency mode, we are already in primary and just don't do much
  798. */
  799. if (!data->primary || data->primary == chanctx_conf)
  800. data->primary = chanctx_conf;
  801. else if (!data->secondary)
  802. /* if secondary is not NULL, it might be a GO */
  803. data->secondary = chanctx_conf;
  804. /*
  805. * don't reduce the Tx power if one of these is true:
  806. * we are in LOOSE
  807. * single share antenna product
  808. * BT is active
  809. * we are associated
  810. */
  811. if (iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT ||
  812. mvm->cfg->bt_shared_single_ant || !vif->bss_conf.assoc ||
  813. !data->notif->bt_status) {
  814. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false);
  815. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  816. return;
  817. }
  818. /* try to get the avg rssi from fw */
  819. ave_rssi = mvmvif->bf_data.ave_beacon_signal;
  820. /* if the RSSI isn't valid, fake it is very low */
  821. if (!ave_rssi)
  822. ave_rssi = -100;
  823. if (ave_rssi > -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH) {
  824. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true))
  825. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  826. } else if (ave_rssi < -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH) {
  827. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
  828. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  829. }
  830. /* Begin to monitor the RSSI: it may influence the reduced Tx power */
  831. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, true, ave_rssi);
  832. }
  833. static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm)
  834. {
  835. struct iwl_bt_iterator_data data = {
  836. .mvm = mvm,
  837. .notif = &mvm->last_bt_notif_old,
  838. };
  839. struct iwl_bt_coex_ci_cmd_old cmd = {};
  840. u8 ci_bw_idx;
  841. /* Ignore updates if we are in force mode */
  842. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  843. return;
  844. rcu_read_lock();
  845. ieee80211_iterate_active_interfaces_atomic(
  846. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  847. iwl_mvm_bt_notif_iterator, &data);
  848. if (data.primary) {
  849. struct ieee80211_chanctx_conf *chan = data.primary;
  850. if (WARN_ON(!chan->def.chan)) {
  851. rcu_read_unlock();
  852. return;
  853. }
  854. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  855. ci_bw_idx = 0;
  856. cmd.co_run_bw_primary = 0;
  857. } else {
  858. cmd.co_run_bw_primary = 1;
  859. if (chan->def.center_freq1 >
  860. chan->def.chan->center_freq)
  861. ci_bw_idx = 2;
  862. else
  863. ci_bw_idx = 1;
  864. }
  865. cmd.bt_primary_ci =
  866. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  867. cmd.primary_ch_phy_id = *((u16 *)data.primary->drv_priv);
  868. }
  869. if (data.secondary) {
  870. struct ieee80211_chanctx_conf *chan = data.secondary;
  871. if (WARN_ON(!data.secondary->def.chan)) {
  872. rcu_read_unlock();
  873. return;
  874. }
  875. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  876. ci_bw_idx = 0;
  877. cmd.co_run_bw_secondary = 0;
  878. } else {
  879. cmd.co_run_bw_secondary = 1;
  880. if (chan->def.center_freq1 >
  881. chan->def.chan->center_freq)
  882. ci_bw_idx = 2;
  883. else
  884. ci_bw_idx = 1;
  885. }
  886. cmd.bt_secondary_ci =
  887. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  888. cmd.secondary_ch_phy_id = *((u16 *)data.secondary->drv_priv);
  889. }
  890. rcu_read_unlock();
  891. /* Don't spam the fw with the same command over and over */
  892. if (memcmp(&cmd, &mvm->last_bt_ci_cmd_old, sizeof(cmd))) {
  893. if (iwl_mvm_send_cmd_pdu(mvm, BT_COEX_CI, 0,
  894. sizeof(cmd), &cmd))
  895. IWL_ERR(mvm, "Failed to send BT_CI cmd\n");
  896. memcpy(&mvm->last_bt_ci_cmd_old, &cmd, sizeof(cmd));
  897. }
  898. if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm))
  899. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  900. }
  901. int iwl_mvm_rx_bt_coex_notif_old(struct iwl_mvm *mvm,
  902. struct iwl_rx_cmd_buffer *rxb,
  903. struct iwl_device_cmd *dev_cmd)
  904. {
  905. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  906. struct iwl_bt_coex_profile_notif_old *notif = (void *)pkt->data;
  907. IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n");
  908. IWL_DEBUG_COEX(mvm, "\tBT status: %s\n",
  909. notif->bt_status ? "ON" : "OFF");
  910. IWL_DEBUG_COEX(mvm, "\tBT open conn %d\n", notif->bt_open_conn);
  911. IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n", notif->bt_ci_compliance);
  912. IWL_DEBUG_COEX(mvm, "\tBT primary_ch_lut %d\n",
  913. le32_to_cpu(notif->primary_ch_lut));
  914. IWL_DEBUG_COEX(mvm, "\tBT secondary_ch_lut %d\n",
  915. le32_to_cpu(notif->secondary_ch_lut));
  916. IWL_DEBUG_COEX(mvm, "\tBT activity grading %d\n",
  917. le32_to_cpu(notif->bt_activity_grading));
  918. IWL_DEBUG_COEX(mvm, "\tBT agg traffic load %d\n",
  919. notif->bt_agg_traffic_load);
  920. /* remember this notification for future use: rssi fluctuations */
  921. memcpy(&mvm->last_bt_notif_old, notif, sizeof(mvm->last_bt_notif_old));
  922. iwl_mvm_bt_coex_notif_handle(mvm);
  923. /*
  924. * This is an async handler for a notification, returning anything other
  925. * than 0 doesn't make sense even if HCMD failed.
  926. */
  927. return 0;
  928. }
  929. static void iwl_mvm_bt_rssi_iterator(void *_data, u8 *mac,
  930. struct ieee80211_vif *vif)
  931. {
  932. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  933. struct iwl_bt_iterator_data *data = _data;
  934. struct iwl_mvm *mvm = data->mvm;
  935. struct ieee80211_sta *sta;
  936. struct iwl_mvm_sta *mvmsta;
  937. struct ieee80211_chanctx_conf *chanctx_conf;
  938. rcu_read_lock();
  939. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  940. /* If channel context is invalid or not on 2.4GHz - don't count it */
  941. if (!chanctx_conf ||
  942. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ) {
  943. rcu_read_unlock();
  944. return;
  945. }
  946. rcu_read_unlock();
  947. if (vif->type != NL80211_IFTYPE_STATION ||
  948. mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  949. return;
  950. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
  951. lockdep_is_held(&mvm->mutex));
  952. /* This can happen if the station has been removed right now */
  953. if (IS_ERR_OR_NULL(sta))
  954. return;
  955. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  956. }
  957. void iwl_mvm_bt_rssi_event_old(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  958. enum ieee80211_rssi_event rssi_event)
  959. {
  960. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  961. struct iwl_bt_iterator_data data = {
  962. .mvm = mvm,
  963. };
  964. int ret;
  965. lockdep_assert_held(&mvm->mutex);
  966. /* Ignore updates if we are in force mode */
  967. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  968. return;
  969. /*
  970. * Rssi update while not associated - can happen since the statistics
  971. * are handled asynchronously
  972. */
  973. if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  974. return;
  975. /* No BT - reports should be disabled */
  976. if (!mvm->last_bt_notif_old.bt_status)
  977. return;
  978. IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid,
  979. rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW");
  980. /*
  981. * Check if rssi is good enough for reduced Tx power, but not in loose
  982. * scheme.
  983. */
  984. if (rssi_event == RSSI_EVENT_LOW || mvm->cfg->bt_shared_single_ant ||
  985. iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT)
  986. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  987. false);
  988. else
  989. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true);
  990. if (ret)
  991. IWL_ERR(mvm, "couldn't send BT_CONFIG HCMD upon RSSI event\n");
  992. ieee80211_iterate_active_interfaces_atomic(
  993. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  994. iwl_mvm_bt_rssi_iterator, &data);
  995. if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm))
  996. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  997. }
  998. #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000)
  999. #define LINK_QUAL_AGG_TIME_LIMIT_BT_ACT (1200)
  1000. u16 iwl_mvm_coex_agg_time_limit_old(struct iwl_mvm *mvm,
  1001. struct ieee80211_sta *sta)
  1002. {
  1003. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  1004. enum iwl_bt_coex_lut_type lut_type;
  1005. if (le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading) <
  1006. BT_HIGH_TRAFFIC)
  1007. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  1008. if (mvm->last_bt_notif_old.ttc_enabled)
  1009. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  1010. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  1011. if (lut_type == BT_COEX_LOOSE_LUT || lut_type == BT_COEX_INVALID_LUT)
  1012. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  1013. /* tight coex, high bt traffic, reduce AGG time limit */
  1014. return LINK_QUAL_AGG_TIME_LIMIT_BT_ACT;
  1015. }
  1016. bool iwl_mvm_bt_coex_is_mimo_allowed_old(struct iwl_mvm *mvm,
  1017. struct ieee80211_sta *sta)
  1018. {
  1019. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  1020. enum iwl_bt_coex_lut_type lut_type;
  1021. if (mvm->last_bt_notif_old.ttc_enabled)
  1022. return true;
  1023. if (le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading) <
  1024. BT_HIGH_TRAFFIC)
  1025. return true;
  1026. /*
  1027. * In Tight / TxTxDis, BT can't Rx while we Tx, so use both antennas
  1028. * since BT is already killed.
  1029. * In Loose, BT can Rx while we Tx, so forbid MIMO to let BT Rx while
  1030. * we Tx.
  1031. * When we are in 5GHz, we'll get BT_COEX_INVALID_LUT allowing MIMO.
  1032. */
  1033. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  1034. return lut_type != BT_COEX_LOOSE_LUT;
  1035. }
  1036. bool iwl_mvm_bt_coex_is_shared_ant_avail_old(struct iwl_mvm *mvm)
  1037. {
  1038. u32 ag = le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading);
  1039. return ag < BT_HIGH_TRAFFIC;
  1040. }
  1041. bool iwl_mvm_bt_coex_is_tpc_allowed_old(struct iwl_mvm *mvm,
  1042. enum ieee80211_band band)
  1043. {
  1044. u32 bt_activity =
  1045. le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading);
  1046. if (band != IEEE80211_BAND_2GHZ)
  1047. return false;
  1048. return bt_activity >= BT_LOW_TRAFFIC;
  1049. }
  1050. void iwl_mvm_bt_coex_vif_change_old(struct iwl_mvm *mvm)
  1051. {
  1052. iwl_mvm_bt_coex_notif_handle(mvm);
  1053. }
  1054. int iwl_mvm_rx_ant_coupling_notif_old(struct iwl_mvm *mvm,
  1055. struct iwl_rx_cmd_buffer *rxb,
  1056. struct iwl_device_cmd *dev_cmd)
  1057. {
  1058. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1059. u32 ant_isolation = le32_to_cpup((void *)pkt->data);
  1060. u8 __maybe_unused lower_bound, upper_bound;
  1061. int ret;
  1062. u8 lut;
  1063. struct iwl_bt_coex_cmd_old *bt_cmd;
  1064. struct iwl_host_cmd cmd = {
  1065. .id = BT_CONFIG,
  1066. .len = { sizeof(*bt_cmd), },
  1067. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  1068. };
  1069. if (!iwl_mvm_bt_is_plcr_supported(mvm))
  1070. return 0;
  1071. lockdep_assert_held(&mvm->mutex);
  1072. /* Ignore updates if we are in force mode */
  1073. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  1074. return 0;
  1075. if (ant_isolation == mvm->last_ant_isol)
  1076. return 0;
  1077. for (lut = 0; lut < ARRAY_SIZE(antenna_coupling_ranges) - 1; lut++)
  1078. if (ant_isolation < antenna_coupling_ranges[lut + 1].range)
  1079. break;
  1080. lower_bound = antenna_coupling_ranges[lut].range;
  1081. if (lut < ARRAY_SIZE(antenna_coupling_ranges) - 1)
  1082. upper_bound = antenna_coupling_ranges[lut + 1].range;
  1083. else
  1084. upper_bound = antenna_coupling_ranges[lut].range;
  1085. IWL_DEBUG_COEX(mvm, "Antenna isolation=%d in range [%d,%d[, lut=%d\n",
  1086. ant_isolation, lower_bound, upper_bound, lut);
  1087. mvm->last_ant_isol = ant_isolation;
  1088. if (mvm->last_corun_lut == lut)
  1089. return 0;
  1090. mvm->last_corun_lut = lut;
  1091. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  1092. if (!bt_cmd)
  1093. return 0;
  1094. cmd.data[0] = bt_cmd;
  1095. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  1096. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_ENABLE |
  1097. BT_VALID_CORUN_LUT_20 |
  1098. BT_VALID_CORUN_LUT_40);
  1099. /* For the moment, use the same LUT for 20GHz and 40GHz */
  1100. memcpy(bt_cmd->bt4_corun_lut20, antenna_coupling_ranges[lut].lut20,
  1101. sizeof(bt_cmd->bt4_corun_lut20));
  1102. memcpy(bt_cmd->bt4_corun_lut40, antenna_coupling_ranges[lut].lut20,
  1103. sizeof(bt_cmd->bt4_corun_lut40));
  1104. ret = iwl_mvm_send_cmd(mvm, &cmd);
  1105. kfree(bt_cmd);
  1106. return ret;
  1107. }