coex_legacy.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  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. #define BT_ANTENNA_COUPLING_THRESHOLD (30)
  100. static int iwl_send_bt_prio_tbl(struct iwl_mvm *mvm)
  101. {
  102. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  103. return 0;
  104. return iwl_mvm_send_cmd_pdu(mvm, BT_COEX_PRIO_TABLE, 0,
  105. sizeof(struct iwl_bt_coex_prio_tbl_cmd),
  106. &iwl_bt_prio_tbl);
  107. }
  108. static const __le32 iwl_bt_prio_boost[BT_COEX_BOOST_SIZE] = {
  109. cpu_to_le32(0xf0f0f0f0), /* 50% */
  110. cpu_to_le32(0xc0c0c0c0), /* 25% */
  111. cpu_to_le32(0xfcfcfcfc), /* 75% */
  112. cpu_to_le32(0xfefefefe), /* 87.5% */
  113. };
  114. static const __le32 iwl_single_shared_ant[BT_COEX_MAX_LUT][BT_COEX_LUT_SIZE] = {
  115. {
  116. cpu_to_le32(0x40000000),
  117. cpu_to_le32(0x00000000),
  118. cpu_to_le32(0x44000000),
  119. cpu_to_le32(0x00000000),
  120. cpu_to_le32(0x40000000),
  121. cpu_to_le32(0x00000000),
  122. cpu_to_le32(0x44000000),
  123. cpu_to_le32(0x00000000),
  124. cpu_to_le32(0xc0004000),
  125. cpu_to_le32(0xf0005000),
  126. cpu_to_le32(0xc0004000),
  127. cpu_to_le32(0xf0005000),
  128. },
  129. {
  130. cpu_to_le32(0x40000000),
  131. cpu_to_le32(0x00000000),
  132. cpu_to_le32(0x44000000),
  133. cpu_to_le32(0x00000000),
  134. cpu_to_le32(0x40000000),
  135. cpu_to_le32(0x00000000),
  136. cpu_to_le32(0x44000000),
  137. cpu_to_le32(0x00000000),
  138. cpu_to_le32(0xc0004000),
  139. cpu_to_le32(0xf0005000),
  140. cpu_to_le32(0xc0004000),
  141. cpu_to_le32(0xf0005000),
  142. },
  143. {
  144. cpu_to_le32(0x40000000),
  145. cpu_to_le32(0x00000000),
  146. cpu_to_le32(0x44000000),
  147. cpu_to_le32(0x00000000),
  148. cpu_to_le32(0x40000000),
  149. cpu_to_le32(0x00000000),
  150. cpu_to_le32(0x44000000),
  151. cpu_to_le32(0x00000000),
  152. cpu_to_le32(0xc0004000),
  153. cpu_to_le32(0xf0005000),
  154. cpu_to_le32(0xc0004000),
  155. cpu_to_le32(0xf0005000),
  156. },
  157. };
  158. static const __le32 iwl_combined_lookup[BT_COEX_MAX_LUT][BT_COEX_LUT_SIZE] = {
  159. {
  160. /* Tight */
  161. cpu_to_le32(0xaaaaaaaa),
  162. cpu_to_le32(0xaaaaaaaa),
  163. cpu_to_le32(0xaeaaaaaa),
  164. cpu_to_le32(0xaaaaaaaa),
  165. cpu_to_le32(0xcc00ff28),
  166. cpu_to_le32(0x0000aaaa),
  167. cpu_to_le32(0xcc00aaaa),
  168. cpu_to_le32(0x0000aaaa),
  169. cpu_to_le32(0xc0004000),
  170. cpu_to_le32(0x00004000),
  171. cpu_to_le32(0xf0005000),
  172. cpu_to_le32(0xf0005000),
  173. },
  174. {
  175. /* Loose */
  176. cpu_to_le32(0xaaaaaaaa),
  177. cpu_to_le32(0xaaaaaaaa),
  178. cpu_to_le32(0xaaaaaaaa),
  179. cpu_to_le32(0xaaaaaaaa),
  180. cpu_to_le32(0xcc00ff28),
  181. cpu_to_le32(0x0000aaaa),
  182. cpu_to_le32(0xcc00aaaa),
  183. cpu_to_le32(0x0000aaaa),
  184. cpu_to_le32(0x00000000),
  185. cpu_to_le32(0x00000000),
  186. cpu_to_le32(0xf0005000),
  187. cpu_to_le32(0xf0005000),
  188. },
  189. {
  190. /* Tx Tx disabled */
  191. cpu_to_le32(0xaaaaaaaa),
  192. cpu_to_le32(0xaaaaaaaa),
  193. cpu_to_le32(0xeeaaaaaa),
  194. cpu_to_le32(0xaaaaaaaa),
  195. cpu_to_le32(0xcc00ff28),
  196. cpu_to_le32(0x0000aaaa),
  197. cpu_to_le32(0xcc00aaaa),
  198. cpu_to_le32(0x0000aaaa),
  199. cpu_to_le32(0xc0004000),
  200. cpu_to_le32(0xc0004000),
  201. cpu_to_le32(0xf0005000),
  202. cpu_to_le32(0xf0005000),
  203. },
  204. };
  205. /* 20MHz / 40MHz below / 40Mhz above*/
  206. static const __le64 iwl_ci_mask[][3] = {
  207. /* dummy entry for channel 0 */
  208. {cpu_to_le64(0), cpu_to_le64(0), cpu_to_le64(0)},
  209. {
  210. cpu_to_le64(0x0000001FFFULL),
  211. cpu_to_le64(0x0ULL),
  212. cpu_to_le64(0x00007FFFFFULL),
  213. },
  214. {
  215. cpu_to_le64(0x000000FFFFULL),
  216. cpu_to_le64(0x0ULL),
  217. cpu_to_le64(0x0003FFFFFFULL),
  218. },
  219. {
  220. cpu_to_le64(0x000003FFFCULL),
  221. cpu_to_le64(0x0ULL),
  222. cpu_to_le64(0x000FFFFFFCULL),
  223. },
  224. {
  225. cpu_to_le64(0x00001FFFE0ULL),
  226. cpu_to_le64(0x0ULL),
  227. cpu_to_le64(0x007FFFFFE0ULL),
  228. },
  229. {
  230. cpu_to_le64(0x00007FFF80ULL),
  231. cpu_to_le64(0x00007FFFFFULL),
  232. cpu_to_le64(0x01FFFFFF80ULL),
  233. },
  234. {
  235. cpu_to_le64(0x0003FFFC00ULL),
  236. cpu_to_le64(0x0003FFFFFFULL),
  237. cpu_to_le64(0x0FFFFFFC00ULL),
  238. },
  239. {
  240. cpu_to_le64(0x000FFFF000ULL),
  241. cpu_to_le64(0x000FFFFFFCULL),
  242. cpu_to_le64(0x3FFFFFF000ULL),
  243. },
  244. {
  245. cpu_to_le64(0x007FFF8000ULL),
  246. cpu_to_le64(0x007FFFFFE0ULL),
  247. cpu_to_le64(0xFFFFFF8000ULL),
  248. },
  249. {
  250. cpu_to_le64(0x01FFFE0000ULL),
  251. cpu_to_le64(0x01FFFFFF80ULL),
  252. cpu_to_le64(0xFFFFFE0000ULL),
  253. },
  254. {
  255. cpu_to_le64(0x0FFFF00000ULL),
  256. cpu_to_le64(0x0FFFFFFC00ULL),
  257. cpu_to_le64(0x0ULL),
  258. },
  259. {
  260. cpu_to_le64(0x3FFFC00000ULL),
  261. cpu_to_le64(0x3FFFFFF000ULL),
  262. cpu_to_le64(0x0)
  263. },
  264. {
  265. cpu_to_le64(0xFFFE000000ULL),
  266. cpu_to_le64(0xFFFFFF8000ULL),
  267. cpu_to_le64(0x0)
  268. },
  269. {
  270. cpu_to_le64(0xFFF8000000ULL),
  271. cpu_to_le64(0xFFFFFE0000ULL),
  272. cpu_to_le64(0x0)
  273. },
  274. {
  275. cpu_to_le64(0xFFC0000000ULL),
  276. cpu_to_le64(0x0ULL),
  277. cpu_to_le64(0x0ULL)
  278. },
  279. };
  280. static const __le32 iwl_bt_mprio_lut[BT_COEX_MULTI_PRIO_LUT_SIZE] = {
  281. cpu_to_le32(0x2e402280),
  282. cpu_to_le32(0x7711a751),
  283. };
  284. struct corunning_block_luts {
  285. u8 range;
  286. __le32 lut20[BT_COEX_CORUN_LUT_SIZE];
  287. };
  288. /*
  289. * Ranges for the antenna coupling calibration / co-running block LUT:
  290. * LUT0: [ 0, 12[
  291. * LUT1: [12, 20[
  292. * LUT2: [20, 21[
  293. * LUT3: [21, 23[
  294. * LUT4: [23, 27[
  295. * LUT5: [27, 30[
  296. * LUT6: [30, 32[
  297. * LUT7: [32, 33[
  298. * LUT8: [33, - [
  299. */
  300. static const struct corunning_block_luts antenna_coupling_ranges[] = {
  301. {
  302. .range = 0,
  303. .lut20 = {
  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. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  316. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  317. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  318. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  319. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  320. },
  321. },
  322. {
  323. .range = 12,
  324. .lut20 = {
  325. cpu_to_le32(0x00000001), 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. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  337. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  338. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  339. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  340. cpu_to_le32(0x00000000), cpu_to_le32(0x00000000),
  341. },
  342. },
  343. {
  344. .range = 20,
  345. .lut20 = {
  346. cpu_to_le32(0x00000002), 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. 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. },
  363. },
  364. {
  365. .range = 21,
  366. .lut20 = {
  367. cpu_to_le32(0x00000003), 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. 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. },
  384. },
  385. {
  386. .range = 23,
  387. .lut20 = {
  388. cpu_to_le32(0x00000004), 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. 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. },
  405. },
  406. {
  407. .range = 27,
  408. .lut20 = {
  409. cpu_to_le32(0x00000005), 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. 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. },
  426. },
  427. {
  428. .range = 30,
  429. .lut20 = {
  430. cpu_to_le32(0x00000006), 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. 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. },
  447. },
  448. {
  449. .range = 32,
  450. .lut20 = {
  451. cpu_to_le32(0x00000007), 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. 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. },
  468. },
  469. {
  470. .range = 33,
  471. .lut20 = {
  472. cpu_to_le32(0x00000008), 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. 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. },
  489. },
  490. };
  491. static enum iwl_bt_coex_lut_type
  492. iwl_get_coex_type(struct iwl_mvm *mvm, const struct ieee80211_vif *vif)
  493. {
  494. struct ieee80211_chanctx_conf *chanctx_conf;
  495. enum iwl_bt_coex_lut_type ret;
  496. u16 phy_ctx_id;
  497. /*
  498. * Checking that we hold mvm->mutex is a good idea, but the rate
  499. * control can't acquire the mutex since it runs in Tx path.
  500. * So this is racy in that case, but in the worst case, the AMPDU
  501. * size limit will be wrong for a short time which is not a big
  502. * issue.
  503. */
  504. rcu_read_lock();
  505. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  506. if (!chanctx_conf ||
  507. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ) {
  508. rcu_read_unlock();
  509. return BT_COEX_INVALID_LUT;
  510. }
  511. ret = BT_COEX_TX_DIS_LUT;
  512. if (mvm->cfg->bt_shared_single_ant) {
  513. rcu_read_unlock();
  514. return ret;
  515. }
  516. phy_ctx_id = *((u16 *)chanctx_conf->drv_priv);
  517. if (mvm->last_bt_ci_cmd_old.primary_ch_phy_id == phy_ctx_id)
  518. ret = le32_to_cpu(mvm->last_bt_notif_old.primary_ch_lut);
  519. else if (mvm->last_bt_ci_cmd_old.secondary_ch_phy_id == phy_ctx_id)
  520. ret = le32_to_cpu(mvm->last_bt_notif_old.secondary_ch_lut);
  521. /* else - default = TX TX disallowed */
  522. rcu_read_unlock();
  523. return ret;
  524. }
  525. int iwl_send_bt_init_conf_old(struct iwl_mvm *mvm)
  526. {
  527. struct iwl_bt_coex_cmd_old *bt_cmd;
  528. struct iwl_host_cmd cmd = {
  529. .id = BT_CONFIG,
  530. .len = { sizeof(*bt_cmd), },
  531. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  532. };
  533. int ret;
  534. u32 flags;
  535. ret = iwl_send_bt_prio_tbl(mvm);
  536. if (ret)
  537. return ret;
  538. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  539. if (!bt_cmd)
  540. return -ENOMEM;
  541. cmd.data[0] = bt_cmd;
  542. lockdep_assert_held(&mvm->mutex);
  543. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS)) {
  544. switch (mvm->bt_force_ant_mode) {
  545. case BT_FORCE_ANT_AUTO:
  546. flags = BT_COEX_AUTO_OLD;
  547. break;
  548. case BT_FORCE_ANT_BT:
  549. flags = BT_COEX_BT_OLD;
  550. break;
  551. case BT_FORCE_ANT_WIFI:
  552. flags = BT_COEX_WIFI_OLD;
  553. break;
  554. default:
  555. WARN_ON(1);
  556. flags = 0;
  557. }
  558. bt_cmd->flags = cpu_to_le32(flags);
  559. bt_cmd->valid_bit_msk = cpu_to_le32(BT_VALID_ENABLE);
  560. goto send_cmd;
  561. }
  562. bt_cmd->max_kill = 5;
  563. bt_cmd->bt4_antenna_isolation_thr = BT_ANTENNA_COUPLING_THRESHOLD;
  564. bt_cmd->bt4_antenna_isolation = iwlwifi_mod_params.ant_coupling;
  565. bt_cmd->bt4_tx_tx_delta_freq_thr = 15;
  566. bt_cmd->bt4_tx_rx_max_freq0 = 15;
  567. bt_cmd->override_primary_lut = BT_COEX_INVALID_LUT;
  568. bt_cmd->override_secondary_lut = BT_COEX_INVALID_LUT;
  569. flags = iwlwifi_mod_params.bt_coex_active ?
  570. BT_COEX_NW_OLD : BT_COEX_DISABLE_OLD;
  571. bt_cmd->flags = cpu_to_le32(flags);
  572. bt_cmd->valid_bit_msk = cpu_to_le32(BT_VALID_ENABLE |
  573. BT_VALID_BT_PRIO_BOOST |
  574. BT_VALID_MAX_KILL |
  575. BT_VALID_3W_TMRS |
  576. BT_VALID_KILL_ACK |
  577. BT_VALID_KILL_CTS |
  578. BT_VALID_REDUCED_TX_POWER |
  579. BT_VALID_LUT |
  580. BT_VALID_WIFI_RX_SW_PRIO_BOOST |
  581. BT_VALID_WIFI_TX_SW_PRIO_BOOST |
  582. BT_VALID_ANT_ISOLATION |
  583. BT_VALID_ANT_ISOLATION_THRS |
  584. BT_VALID_TXTX_DELTA_FREQ_THRS |
  585. BT_VALID_TXRX_MAX_FREQ_0 |
  586. BT_VALID_SYNC_TO_SCO);
  587. if (IWL_MVM_BT_COEX_SYNC2SCO)
  588. bt_cmd->flags |= cpu_to_le32(BT_COEX_SYNC2SCO);
  589. if (IWL_MVM_BT_COEX_CORUNNING) {
  590. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_CORUN_LUT_20 |
  591. BT_VALID_CORUN_LUT_40);
  592. bt_cmd->flags |= cpu_to_le32(BT_COEX_CORUNNING);
  593. }
  594. if (IWL_MVM_BT_COEX_MPLUT) {
  595. bt_cmd->flags |= cpu_to_le32(BT_COEX_MPLUT);
  596. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_MULTI_PRIO_LUT);
  597. }
  598. if (mvm->cfg->bt_shared_single_ant)
  599. memcpy(&bt_cmd->decision_lut, iwl_single_shared_ant,
  600. sizeof(iwl_single_shared_ant));
  601. else
  602. memcpy(&bt_cmd->decision_lut, iwl_combined_lookup,
  603. sizeof(iwl_combined_lookup));
  604. /* Take first Co-running block LUT to get started */
  605. memcpy(bt_cmd->bt4_corun_lut20, antenna_coupling_ranges[0].lut20,
  606. sizeof(bt_cmd->bt4_corun_lut20));
  607. memcpy(bt_cmd->bt4_corun_lut40, antenna_coupling_ranges[0].lut20,
  608. sizeof(bt_cmd->bt4_corun_lut40));
  609. memcpy(&bt_cmd->bt_prio_boost, iwl_bt_prio_boost,
  610. sizeof(iwl_bt_prio_boost));
  611. memcpy(&bt_cmd->bt4_multiprio_lut, iwl_bt_mprio_lut,
  612. sizeof(iwl_bt_mprio_lut));
  613. send_cmd:
  614. memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
  615. memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
  616. ret = iwl_mvm_send_cmd(mvm, &cmd);
  617. kfree(bt_cmd);
  618. return ret;
  619. }
  620. static int iwl_mvm_bt_udpate_ctrl_kill_msk(struct iwl_mvm *mvm)
  621. {
  622. struct iwl_bt_coex_profile_notif_old *notif = &mvm->last_bt_notif_old;
  623. u32 primary_lut = le32_to_cpu(notif->primary_ch_lut);
  624. u32 ag = le32_to_cpu(notif->bt_activity_grading);
  625. struct iwl_bt_coex_cmd_old *bt_cmd;
  626. u8 ack_kill_msk, cts_kill_msk;
  627. struct iwl_host_cmd cmd = {
  628. .id = BT_CONFIG,
  629. .data[0] = &bt_cmd,
  630. .len = { sizeof(*bt_cmd), },
  631. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  632. };
  633. int ret = 0;
  634. lockdep_assert_held(&mvm->mutex);
  635. ack_kill_msk = iwl_bt_ack_kill_msk[ag][primary_lut];
  636. cts_kill_msk = iwl_bt_cts_kill_msk[ag][primary_lut];
  637. if (mvm->bt_ack_kill_msk[0] == ack_kill_msk &&
  638. mvm->bt_cts_kill_msk[0] == cts_kill_msk)
  639. return 0;
  640. mvm->bt_ack_kill_msk[0] = ack_kill_msk;
  641. mvm->bt_cts_kill_msk[0] = cts_kill_msk;
  642. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  643. if (!bt_cmd)
  644. return -ENOMEM;
  645. cmd.data[0] = bt_cmd;
  646. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  647. bt_cmd->kill_ack_msk = cpu_to_le32(iwl_bt_ctl_kill_msk[ack_kill_msk]);
  648. bt_cmd->kill_cts_msk = cpu_to_le32(iwl_bt_ctl_kill_msk[cts_kill_msk]);
  649. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_ENABLE |
  650. BT_VALID_KILL_ACK |
  651. BT_VALID_KILL_CTS);
  652. ret = iwl_mvm_send_cmd(mvm, &cmd);
  653. kfree(bt_cmd);
  654. return ret;
  655. }
  656. static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id,
  657. bool enable)
  658. {
  659. struct iwl_bt_coex_cmd_old *bt_cmd;
  660. /* Send ASYNC since this can be sent from an atomic context */
  661. struct iwl_host_cmd cmd = {
  662. .id = BT_CONFIG,
  663. .len = { sizeof(*bt_cmd), },
  664. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  665. .flags = CMD_ASYNC,
  666. };
  667. struct iwl_mvm_sta *mvmsta;
  668. int ret;
  669. mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
  670. if (!mvmsta)
  671. return 0;
  672. /* nothing to do */
  673. if (mvmsta->bt_reduced_txpower == enable)
  674. return 0;
  675. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_ATOMIC);
  676. if (!bt_cmd)
  677. return -ENOMEM;
  678. cmd.data[0] = bt_cmd;
  679. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  680. bt_cmd->valid_bit_msk =
  681. cpu_to_le32(BT_VALID_ENABLE | BT_VALID_REDUCED_TX_POWER);
  682. bt_cmd->bt_reduced_tx_power = sta_id;
  683. if (enable)
  684. bt_cmd->bt_reduced_tx_power |= BT_REDUCED_TX_POWER_BIT;
  685. IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n",
  686. enable ? "en" : "dis", sta_id);
  687. mvmsta->bt_reduced_txpower = enable;
  688. ret = iwl_mvm_send_cmd(mvm, &cmd);
  689. kfree(bt_cmd);
  690. return ret;
  691. }
  692. struct iwl_bt_iterator_data {
  693. struct iwl_bt_coex_profile_notif_old *notif;
  694. struct iwl_mvm *mvm;
  695. struct ieee80211_chanctx_conf *primary;
  696. struct ieee80211_chanctx_conf *secondary;
  697. bool primary_ll;
  698. };
  699. static inline
  700. void iwl_mvm_bt_coex_enable_rssi_event(struct iwl_mvm *mvm,
  701. struct ieee80211_vif *vif,
  702. bool enable, int rssi)
  703. {
  704. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  705. mvmvif->bf_data.last_bt_coex_event = rssi;
  706. mvmvif->bf_data.bt_coex_max_thold =
  707. enable ? -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH : 0;
  708. mvmvif->bf_data.bt_coex_min_thold =
  709. enable ? -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH : 0;
  710. }
  711. /* must be called under rcu_read_lock */
  712. static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac,
  713. struct ieee80211_vif *vif)
  714. {
  715. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  716. struct iwl_bt_iterator_data *data = _data;
  717. struct iwl_mvm *mvm = data->mvm;
  718. struct ieee80211_chanctx_conf *chanctx_conf;
  719. enum ieee80211_smps_mode smps_mode;
  720. u32 bt_activity_grading;
  721. int ave_rssi;
  722. lockdep_assert_held(&mvm->mutex);
  723. switch (vif->type) {
  724. case NL80211_IFTYPE_STATION:
  725. /* default smps_mode for BSS / P2P client is AUTOMATIC */
  726. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  727. break;
  728. case NL80211_IFTYPE_AP:
  729. if (!mvmvif->ap_ibss_active)
  730. return;
  731. break;
  732. default:
  733. return;
  734. }
  735. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  736. /* If channel context is invalid or not on 2.4GHz .. */
  737. if ((!chanctx_conf ||
  738. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ)) {
  739. if (vif->type == NL80211_IFTYPE_STATION) {
  740. /* ... relax constraints and disable rssi events */
  741. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  742. smps_mode);
  743. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  744. false);
  745. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  746. }
  747. return;
  748. }
  749. bt_activity_grading = le32_to_cpu(data->notif->bt_activity_grading);
  750. if (bt_activity_grading >= BT_HIGH_TRAFFIC)
  751. smps_mode = IEEE80211_SMPS_STATIC;
  752. else if (bt_activity_grading >= BT_LOW_TRAFFIC)
  753. smps_mode = vif->type == NL80211_IFTYPE_AP ?
  754. IEEE80211_SMPS_OFF :
  755. IEEE80211_SMPS_DYNAMIC;
  756. /* relax SMPS contraints for next association */
  757. if (!vif->bss_conf.assoc)
  758. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  759. IWL_DEBUG_COEX(data->mvm,
  760. "mac %d: bt_status %d bt_activity_grading %d smps_req %d\n",
  761. mvmvif->id, data->notif->bt_status, bt_activity_grading,
  762. smps_mode);
  763. if (vif->type == NL80211_IFTYPE_STATION)
  764. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  765. smps_mode);
  766. /* low latency is always primary */
  767. if (iwl_mvm_vif_low_latency(mvmvif)) {
  768. data->primary_ll = true;
  769. data->secondary = data->primary;
  770. data->primary = chanctx_conf;
  771. }
  772. if (vif->type == NL80211_IFTYPE_AP) {
  773. if (!mvmvif->ap_ibss_active)
  774. return;
  775. if (chanctx_conf == data->primary)
  776. return;
  777. if (!data->primary_ll) {
  778. /*
  779. * downgrade the current primary no matter what its
  780. * type is.
  781. */
  782. data->secondary = data->primary;
  783. data->primary = chanctx_conf;
  784. } else {
  785. /* there is low latency vif - we will be secondary */
  786. data->secondary = chanctx_conf;
  787. }
  788. return;
  789. }
  790. /*
  791. * STA / P2P Client, try to be primary if first vif. If we are in low
  792. * latency mode, we are already in primary and just don't do much
  793. */
  794. if (!data->primary || data->primary == chanctx_conf)
  795. data->primary = chanctx_conf;
  796. else if (!data->secondary)
  797. /* if secondary is not NULL, it might be a GO */
  798. data->secondary = chanctx_conf;
  799. /*
  800. * don't reduce the Tx power if one of these is true:
  801. * we are in LOOSE
  802. * single share antenna product
  803. * BT is active
  804. * we are associated
  805. */
  806. if (iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT ||
  807. mvm->cfg->bt_shared_single_ant || !vif->bss_conf.assoc ||
  808. !data->notif->bt_status) {
  809. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false);
  810. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  811. return;
  812. }
  813. /* try to get the avg rssi from fw */
  814. ave_rssi = mvmvif->bf_data.ave_beacon_signal;
  815. /* if the RSSI isn't valid, fake it is very low */
  816. if (!ave_rssi)
  817. ave_rssi = -100;
  818. if (ave_rssi > -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH) {
  819. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true))
  820. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  821. } else if (ave_rssi < -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH) {
  822. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
  823. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  824. }
  825. /* Begin to monitor the RSSI: it may influence the reduced Tx power */
  826. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, true, ave_rssi);
  827. }
  828. static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm)
  829. {
  830. struct iwl_bt_iterator_data data = {
  831. .mvm = mvm,
  832. .notif = &mvm->last_bt_notif_old,
  833. };
  834. struct iwl_bt_coex_ci_cmd_old cmd = {};
  835. u8 ci_bw_idx;
  836. /* Ignore updates if we are in force mode */
  837. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  838. return;
  839. rcu_read_lock();
  840. ieee80211_iterate_active_interfaces_atomic(
  841. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  842. iwl_mvm_bt_notif_iterator, &data);
  843. if (data.primary) {
  844. struct ieee80211_chanctx_conf *chan = data.primary;
  845. if (WARN_ON(!chan->def.chan)) {
  846. rcu_read_unlock();
  847. return;
  848. }
  849. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  850. ci_bw_idx = 0;
  851. cmd.co_run_bw_primary = 0;
  852. } else {
  853. cmd.co_run_bw_primary = 1;
  854. if (chan->def.center_freq1 >
  855. chan->def.chan->center_freq)
  856. ci_bw_idx = 2;
  857. else
  858. ci_bw_idx = 1;
  859. }
  860. cmd.bt_primary_ci =
  861. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  862. cmd.primary_ch_phy_id = *((u16 *)data.primary->drv_priv);
  863. }
  864. if (data.secondary) {
  865. struct ieee80211_chanctx_conf *chan = data.secondary;
  866. if (WARN_ON(!data.secondary->def.chan)) {
  867. rcu_read_unlock();
  868. return;
  869. }
  870. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  871. ci_bw_idx = 0;
  872. cmd.co_run_bw_secondary = 0;
  873. } else {
  874. cmd.co_run_bw_secondary = 1;
  875. if (chan->def.center_freq1 >
  876. chan->def.chan->center_freq)
  877. ci_bw_idx = 2;
  878. else
  879. ci_bw_idx = 1;
  880. }
  881. cmd.bt_secondary_ci =
  882. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  883. cmd.secondary_ch_phy_id = *((u16 *)data.secondary->drv_priv);
  884. }
  885. rcu_read_unlock();
  886. /* Don't spam the fw with the same command over and over */
  887. if (memcmp(&cmd, &mvm->last_bt_ci_cmd_old, sizeof(cmd))) {
  888. if (iwl_mvm_send_cmd_pdu(mvm, BT_COEX_CI, 0,
  889. sizeof(cmd), &cmd))
  890. IWL_ERR(mvm, "Failed to send BT_CI cmd\n");
  891. memcpy(&mvm->last_bt_ci_cmd_old, &cmd, sizeof(cmd));
  892. }
  893. if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm))
  894. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  895. }
  896. int iwl_mvm_rx_bt_coex_notif_old(struct iwl_mvm *mvm,
  897. struct iwl_rx_cmd_buffer *rxb,
  898. struct iwl_device_cmd *dev_cmd)
  899. {
  900. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  901. struct iwl_bt_coex_profile_notif_old *notif = (void *)pkt->data;
  902. IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n");
  903. IWL_DEBUG_COEX(mvm, "\tBT status: %s\n",
  904. notif->bt_status ? "ON" : "OFF");
  905. IWL_DEBUG_COEX(mvm, "\tBT open conn %d\n", notif->bt_open_conn);
  906. IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n", notif->bt_ci_compliance);
  907. IWL_DEBUG_COEX(mvm, "\tBT primary_ch_lut %d\n",
  908. le32_to_cpu(notif->primary_ch_lut));
  909. IWL_DEBUG_COEX(mvm, "\tBT secondary_ch_lut %d\n",
  910. le32_to_cpu(notif->secondary_ch_lut));
  911. IWL_DEBUG_COEX(mvm, "\tBT activity grading %d\n",
  912. le32_to_cpu(notif->bt_activity_grading));
  913. IWL_DEBUG_COEX(mvm, "\tBT agg traffic load %d\n",
  914. notif->bt_agg_traffic_load);
  915. /* remember this notification for future use: rssi fluctuations */
  916. memcpy(&mvm->last_bt_notif_old, notif, sizeof(mvm->last_bt_notif_old));
  917. iwl_mvm_bt_coex_notif_handle(mvm);
  918. /*
  919. * This is an async handler for a notification, returning anything other
  920. * than 0 doesn't make sense even if HCMD failed.
  921. */
  922. return 0;
  923. }
  924. static void iwl_mvm_bt_rssi_iterator(void *_data, u8 *mac,
  925. struct ieee80211_vif *vif)
  926. {
  927. struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv;
  928. struct iwl_bt_iterator_data *data = _data;
  929. struct iwl_mvm *mvm = data->mvm;
  930. struct ieee80211_sta *sta;
  931. struct iwl_mvm_sta *mvmsta;
  932. struct ieee80211_chanctx_conf *chanctx_conf;
  933. rcu_read_lock();
  934. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  935. /* If channel context is invalid or not on 2.4GHz - don't count it */
  936. if (!chanctx_conf ||
  937. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ) {
  938. rcu_read_unlock();
  939. return;
  940. }
  941. rcu_read_unlock();
  942. if (vif->type != NL80211_IFTYPE_STATION ||
  943. mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  944. return;
  945. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
  946. lockdep_is_held(&mvm->mutex));
  947. /* This can happen if the station has been removed right now */
  948. if (IS_ERR_OR_NULL(sta))
  949. return;
  950. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  951. }
  952. void iwl_mvm_bt_rssi_event_old(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  953. enum ieee80211_rssi_event rssi_event)
  954. {
  955. struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv;
  956. struct iwl_bt_iterator_data data = {
  957. .mvm = mvm,
  958. };
  959. int ret;
  960. lockdep_assert_held(&mvm->mutex);
  961. /* Ignore updates if we are in force mode */
  962. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  963. return;
  964. /*
  965. * Rssi update while not associated - can happen since the statistics
  966. * are handled asynchronously
  967. */
  968. if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  969. return;
  970. /* No BT - reports should be disabled */
  971. if (!mvm->last_bt_notif_old.bt_status)
  972. return;
  973. IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid,
  974. rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW");
  975. /*
  976. * Check if rssi is good enough for reduced Tx power, but not in loose
  977. * scheme.
  978. */
  979. if (rssi_event == RSSI_EVENT_LOW || mvm->cfg->bt_shared_single_ant ||
  980. iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT)
  981. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  982. false);
  983. else
  984. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true);
  985. if (ret)
  986. IWL_ERR(mvm, "couldn't send BT_CONFIG HCMD upon RSSI event\n");
  987. ieee80211_iterate_active_interfaces_atomic(
  988. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  989. iwl_mvm_bt_rssi_iterator, &data);
  990. if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm))
  991. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  992. }
  993. #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000)
  994. #define LINK_QUAL_AGG_TIME_LIMIT_BT_ACT (1200)
  995. u16 iwl_mvm_coex_agg_time_limit_old(struct iwl_mvm *mvm,
  996. struct ieee80211_sta *sta)
  997. {
  998. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  999. enum iwl_bt_coex_lut_type lut_type;
  1000. if (le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading) <
  1001. BT_HIGH_TRAFFIC)
  1002. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  1003. if (mvm->last_bt_notif_old.ttc_enabled)
  1004. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  1005. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  1006. if (lut_type == BT_COEX_LOOSE_LUT || lut_type == BT_COEX_INVALID_LUT)
  1007. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  1008. /* tight coex, high bt traffic, reduce AGG time limit */
  1009. return LINK_QUAL_AGG_TIME_LIMIT_BT_ACT;
  1010. }
  1011. bool iwl_mvm_bt_coex_is_mimo_allowed_old(struct iwl_mvm *mvm,
  1012. struct ieee80211_sta *sta)
  1013. {
  1014. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  1015. enum iwl_bt_coex_lut_type lut_type;
  1016. if (mvm->last_bt_notif_old.ttc_enabled)
  1017. return true;
  1018. if (le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading) <
  1019. BT_HIGH_TRAFFIC)
  1020. return true;
  1021. /*
  1022. * In Tight / TxTxDis, BT can't Rx while we Tx, so use both antennas
  1023. * since BT is already killed.
  1024. * In Loose, BT can Rx while we Tx, so forbid MIMO to let BT Rx while
  1025. * we Tx.
  1026. * When we are in 5GHz, we'll get BT_COEX_INVALID_LUT allowing MIMO.
  1027. */
  1028. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  1029. return lut_type != BT_COEX_LOOSE_LUT;
  1030. }
  1031. bool iwl_mvm_bt_coex_is_shared_ant_avail_old(struct iwl_mvm *mvm)
  1032. {
  1033. u32 ag = le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading);
  1034. return ag == BT_OFF;
  1035. }
  1036. bool iwl_mvm_bt_coex_is_tpc_allowed_old(struct iwl_mvm *mvm,
  1037. enum ieee80211_band band)
  1038. {
  1039. u32 bt_activity =
  1040. le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading);
  1041. if (band != IEEE80211_BAND_2GHZ)
  1042. return false;
  1043. return bt_activity >= BT_LOW_TRAFFIC;
  1044. }
  1045. void iwl_mvm_bt_coex_vif_change_old(struct iwl_mvm *mvm)
  1046. {
  1047. iwl_mvm_bt_coex_notif_handle(mvm);
  1048. }
  1049. int iwl_mvm_rx_ant_coupling_notif_old(struct iwl_mvm *mvm,
  1050. struct iwl_rx_cmd_buffer *rxb,
  1051. struct iwl_device_cmd *dev_cmd)
  1052. {
  1053. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1054. u32 ant_isolation = le32_to_cpup((void *)pkt->data);
  1055. u8 __maybe_unused lower_bound, upper_bound;
  1056. int ret;
  1057. u8 lut;
  1058. struct iwl_bt_coex_cmd_old *bt_cmd;
  1059. struct iwl_host_cmd cmd = {
  1060. .id = BT_CONFIG,
  1061. .len = { sizeof(*bt_cmd), },
  1062. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  1063. };
  1064. if (!IWL_MVM_BT_COEX_CORUNNING)
  1065. return 0;
  1066. lockdep_assert_held(&mvm->mutex);
  1067. /* Ignore updates if we are in force mode */
  1068. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  1069. return 0;
  1070. if (ant_isolation == mvm->last_ant_isol)
  1071. return 0;
  1072. for (lut = 0; lut < ARRAY_SIZE(antenna_coupling_ranges) - 1; lut++)
  1073. if (ant_isolation < antenna_coupling_ranges[lut + 1].range)
  1074. break;
  1075. lower_bound = antenna_coupling_ranges[lut].range;
  1076. if (lut < ARRAY_SIZE(antenna_coupling_ranges) - 1)
  1077. upper_bound = antenna_coupling_ranges[lut + 1].range;
  1078. else
  1079. upper_bound = antenna_coupling_ranges[lut].range;
  1080. IWL_DEBUG_COEX(mvm, "Antenna isolation=%d in range [%d,%d[, lut=%d\n",
  1081. ant_isolation, lower_bound, upper_bound, lut);
  1082. mvm->last_ant_isol = ant_isolation;
  1083. if (mvm->last_corun_lut == lut)
  1084. return 0;
  1085. mvm->last_corun_lut = lut;
  1086. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  1087. if (!bt_cmd)
  1088. return 0;
  1089. cmd.data[0] = bt_cmd;
  1090. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  1091. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_ENABLE |
  1092. BT_VALID_CORUN_LUT_20 |
  1093. BT_VALID_CORUN_LUT_40);
  1094. /* For the moment, use the same LUT for 20GHz and 40GHz */
  1095. memcpy(bt_cmd->bt4_corun_lut20, antenna_coupling_ranges[lut].lut20,
  1096. sizeof(bt_cmd->bt4_corun_lut20));
  1097. memcpy(bt_cmd->bt4_corun_lut40, antenna_coupling_ranges[lut].lut20,
  1098. sizeof(bt_cmd->bt4_corun_lut40));
  1099. ret = iwl_mvm_send_cmd(mvm, &cmd);
  1100. kfree(bt_cmd);
  1101. return ret;
  1102. }