coex_legacy.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  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(0x00000001), 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(0x00000002), 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(0x00000003), 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(0x00000004), 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(0x00000005), 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(0x00000006), 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(0x00000007), 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(0x00000008), 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. if (IWL_MVM_BT_COEX_SYNC2SCO)
  584. bt_cmd->flags |= cpu_to_le32(BT_COEX_SYNC2SCO);
  585. if (IWL_MVM_BT_COEX_CORUNNING) {
  586. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_CORUN_LUT_20 |
  587. BT_VALID_CORUN_LUT_40);
  588. bt_cmd->flags |= cpu_to_le32(BT_COEX_CORUNNING);
  589. }
  590. if (IWL_MVM_BT_COEX_MPLUT) {
  591. bt_cmd->flags |= cpu_to_le32(BT_COEX_MPLUT);
  592. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_MULTI_PRIO_LUT);
  593. }
  594. if (mvm->cfg->bt_shared_single_ant)
  595. memcpy(&bt_cmd->decision_lut, iwl_single_shared_ant,
  596. sizeof(iwl_single_shared_ant));
  597. else
  598. memcpy(&bt_cmd->decision_lut, iwl_combined_lookup,
  599. sizeof(iwl_combined_lookup));
  600. /* Take first Co-running block LUT to get started */
  601. memcpy(bt_cmd->bt4_corun_lut20, antenna_coupling_ranges[0].lut20,
  602. sizeof(bt_cmd->bt4_corun_lut20));
  603. memcpy(bt_cmd->bt4_corun_lut40, antenna_coupling_ranges[0].lut20,
  604. sizeof(bt_cmd->bt4_corun_lut40));
  605. memcpy(&bt_cmd->bt_prio_boost, iwl_bt_prio_boost,
  606. sizeof(iwl_bt_prio_boost));
  607. bt_cmd->bt4_multiprio_lut[0] = cpu_to_le32(IWL_MVM_BT_COEX_MPLUT_REG0);
  608. bt_cmd->bt4_multiprio_lut[1] = cpu_to_le32(IWL_MVM_BT_COEX_MPLUT_REG1);
  609. send_cmd:
  610. memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
  611. memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
  612. ret = iwl_mvm_send_cmd(mvm, &cmd);
  613. kfree(bt_cmd);
  614. return ret;
  615. }
  616. static int iwl_mvm_bt_udpate_ctrl_kill_msk(struct iwl_mvm *mvm)
  617. {
  618. struct iwl_bt_coex_profile_notif_old *notif = &mvm->last_bt_notif_old;
  619. u32 primary_lut = le32_to_cpu(notif->primary_ch_lut);
  620. u32 ag = le32_to_cpu(notif->bt_activity_grading);
  621. struct iwl_bt_coex_cmd_old *bt_cmd;
  622. u8 ack_kill_msk, cts_kill_msk;
  623. struct iwl_host_cmd cmd = {
  624. .id = BT_CONFIG,
  625. .data[0] = &bt_cmd,
  626. .len = { sizeof(*bt_cmd), },
  627. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  628. };
  629. int ret = 0;
  630. lockdep_assert_held(&mvm->mutex);
  631. ack_kill_msk = iwl_bt_ack_kill_msk[ag][primary_lut];
  632. cts_kill_msk = iwl_bt_cts_kill_msk[ag][primary_lut];
  633. if (mvm->bt_ack_kill_msk[0] == ack_kill_msk &&
  634. mvm->bt_cts_kill_msk[0] == cts_kill_msk)
  635. return 0;
  636. mvm->bt_ack_kill_msk[0] = ack_kill_msk;
  637. mvm->bt_cts_kill_msk[0] = cts_kill_msk;
  638. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  639. if (!bt_cmd)
  640. return -ENOMEM;
  641. cmd.data[0] = bt_cmd;
  642. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  643. bt_cmd->kill_ack_msk = cpu_to_le32(iwl_bt_ctl_kill_msk[ack_kill_msk]);
  644. bt_cmd->kill_cts_msk = cpu_to_le32(iwl_bt_ctl_kill_msk[cts_kill_msk]);
  645. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_ENABLE |
  646. BT_VALID_KILL_ACK |
  647. BT_VALID_KILL_CTS);
  648. ret = iwl_mvm_send_cmd(mvm, &cmd);
  649. kfree(bt_cmd);
  650. return ret;
  651. }
  652. static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id,
  653. bool enable)
  654. {
  655. struct iwl_bt_coex_cmd_old *bt_cmd;
  656. /* Send ASYNC since this can be sent from an atomic context */
  657. struct iwl_host_cmd cmd = {
  658. .id = BT_CONFIG,
  659. .len = { sizeof(*bt_cmd), },
  660. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  661. .flags = CMD_ASYNC,
  662. };
  663. struct iwl_mvm_sta *mvmsta;
  664. int ret;
  665. mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
  666. if (!mvmsta)
  667. return 0;
  668. /* nothing to do */
  669. if (mvmsta->bt_reduced_txpower == enable)
  670. return 0;
  671. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_ATOMIC);
  672. if (!bt_cmd)
  673. return -ENOMEM;
  674. cmd.data[0] = bt_cmd;
  675. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  676. bt_cmd->valid_bit_msk =
  677. cpu_to_le32(BT_VALID_ENABLE | BT_VALID_REDUCED_TX_POWER);
  678. bt_cmd->bt_reduced_tx_power = sta_id;
  679. if (enable)
  680. bt_cmd->bt_reduced_tx_power |= BT_REDUCED_TX_POWER_BIT;
  681. IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n",
  682. enable ? "en" : "dis", sta_id);
  683. mvmsta->bt_reduced_txpower = enable;
  684. ret = iwl_mvm_send_cmd(mvm, &cmd);
  685. kfree(bt_cmd);
  686. return ret;
  687. }
  688. struct iwl_bt_iterator_data {
  689. struct iwl_bt_coex_profile_notif_old *notif;
  690. struct iwl_mvm *mvm;
  691. struct ieee80211_chanctx_conf *primary;
  692. struct ieee80211_chanctx_conf *secondary;
  693. bool primary_ll;
  694. };
  695. static inline
  696. void iwl_mvm_bt_coex_enable_rssi_event(struct iwl_mvm *mvm,
  697. struct ieee80211_vif *vif,
  698. bool enable, int rssi)
  699. {
  700. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  701. mvmvif->bf_data.last_bt_coex_event = rssi;
  702. mvmvif->bf_data.bt_coex_max_thold =
  703. enable ? -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH : 0;
  704. mvmvif->bf_data.bt_coex_min_thold =
  705. enable ? -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH : 0;
  706. }
  707. /* must be called under rcu_read_lock */
  708. static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac,
  709. struct ieee80211_vif *vif)
  710. {
  711. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  712. struct iwl_bt_iterator_data *data = _data;
  713. struct iwl_mvm *mvm = data->mvm;
  714. struct ieee80211_chanctx_conf *chanctx_conf;
  715. enum ieee80211_smps_mode smps_mode;
  716. u32 bt_activity_grading;
  717. int ave_rssi;
  718. lockdep_assert_held(&mvm->mutex);
  719. switch (vif->type) {
  720. case NL80211_IFTYPE_STATION:
  721. /* default smps_mode for BSS / P2P client is AUTOMATIC */
  722. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  723. break;
  724. case NL80211_IFTYPE_AP:
  725. if (!mvmvif->ap_ibss_active)
  726. return;
  727. break;
  728. default:
  729. return;
  730. }
  731. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  732. /* If channel context is invalid or not on 2.4GHz .. */
  733. if ((!chanctx_conf ||
  734. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ)) {
  735. if (vif->type == NL80211_IFTYPE_STATION) {
  736. /* ... relax constraints and disable rssi events */
  737. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  738. smps_mode);
  739. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  740. false);
  741. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  742. }
  743. return;
  744. }
  745. bt_activity_grading = le32_to_cpu(data->notif->bt_activity_grading);
  746. if (bt_activity_grading >= BT_HIGH_TRAFFIC)
  747. smps_mode = IEEE80211_SMPS_STATIC;
  748. else if (bt_activity_grading >= BT_LOW_TRAFFIC)
  749. smps_mode = vif->type == NL80211_IFTYPE_AP ?
  750. IEEE80211_SMPS_OFF :
  751. IEEE80211_SMPS_DYNAMIC;
  752. /* relax SMPS contraints for next association */
  753. if (!vif->bss_conf.assoc)
  754. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  755. IWL_DEBUG_COEX(data->mvm,
  756. "mac %d: bt_status %d bt_activity_grading %d smps_req %d\n",
  757. mvmvif->id, data->notif->bt_status, bt_activity_grading,
  758. smps_mode);
  759. if (vif->type == NL80211_IFTYPE_STATION)
  760. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  761. smps_mode);
  762. /* low latency is always primary */
  763. if (iwl_mvm_vif_low_latency(mvmvif)) {
  764. data->primary_ll = true;
  765. data->secondary = data->primary;
  766. data->primary = chanctx_conf;
  767. }
  768. if (vif->type == NL80211_IFTYPE_AP) {
  769. if (!mvmvif->ap_ibss_active)
  770. return;
  771. if (chanctx_conf == data->primary)
  772. return;
  773. if (!data->primary_ll) {
  774. /*
  775. * downgrade the current primary no matter what its
  776. * type is.
  777. */
  778. data->secondary = data->primary;
  779. data->primary = chanctx_conf;
  780. } else {
  781. /* there is low latency vif - we will be secondary */
  782. data->secondary = chanctx_conf;
  783. }
  784. return;
  785. }
  786. /*
  787. * STA / P2P Client, try to be primary if first vif. If we are in low
  788. * latency mode, we are already in primary and just don't do much
  789. */
  790. if (!data->primary || data->primary == chanctx_conf)
  791. data->primary = chanctx_conf;
  792. else if (!data->secondary)
  793. /* if secondary is not NULL, it might be a GO */
  794. data->secondary = chanctx_conf;
  795. /*
  796. * don't reduce the Tx power if one of these is true:
  797. * we are in LOOSE
  798. * single share antenna product
  799. * BT is active
  800. * we are associated
  801. */
  802. if (iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT ||
  803. mvm->cfg->bt_shared_single_ant || !vif->bss_conf.assoc ||
  804. !data->notif->bt_status) {
  805. iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false);
  806. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, false, 0);
  807. return;
  808. }
  809. /* try to get the avg rssi from fw */
  810. ave_rssi = mvmvif->bf_data.ave_beacon_signal;
  811. /* if the RSSI isn't valid, fake it is very low */
  812. if (!ave_rssi)
  813. ave_rssi = -100;
  814. if (ave_rssi > -IWL_MVM_BT_COEX_EN_RED_TXP_THRESH) {
  815. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true))
  816. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  817. } else if (ave_rssi < -IWL_MVM_BT_COEX_DIS_RED_TXP_THRESH) {
  818. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
  819. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  820. }
  821. /* Begin to monitor the RSSI: it may influence the reduced Tx power */
  822. iwl_mvm_bt_coex_enable_rssi_event(mvm, vif, true, ave_rssi);
  823. }
  824. static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm)
  825. {
  826. struct iwl_bt_iterator_data data = {
  827. .mvm = mvm,
  828. .notif = &mvm->last_bt_notif_old,
  829. };
  830. struct iwl_bt_coex_ci_cmd_old cmd = {};
  831. u8 ci_bw_idx;
  832. /* Ignore updates if we are in force mode */
  833. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  834. return;
  835. rcu_read_lock();
  836. ieee80211_iterate_active_interfaces_atomic(
  837. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  838. iwl_mvm_bt_notif_iterator, &data);
  839. if (data.primary) {
  840. struct ieee80211_chanctx_conf *chan = data.primary;
  841. if (WARN_ON(!chan->def.chan)) {
  842. rcu_read_unlock();
  843. return;
  844. }
  845. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  846. ci_bw_idx = 0;
  847. cmd.co_run_bw_primary = 0;
  848. } else {
  849. cmd.co_run_bw_primary = 1;
  850. if (chan->def.center_freq1 >
  851. chan->def.chan->center_freq)
  852. ci_bw_idx = 2;
  853. else
  854. ci_bw_idx = 1;
  855. }
  856. cmd.bt_primary_ci =
  857. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  858. cmd.primary_ch_phy_id = *((u16 *)data.primary->drv_priv);
  859. }
  860. if (data.secondary) {
  861. struct ieee80211_chanctx_conf *chan = data.secondary;
  862. if (WARN_ON(!data.secondary->def.chan)) {
  863. rcu_read_unlock();
  864. return;
  865. }
  866. if (chan->def.width < NL80211_CHAN_WIDTH_40) {
  867. ci_bw_idx = 0;
  868. cmd.co_run_bw_secondary = 0;
  869. } else {
  870. cmd.co_run_bw_secondary = 1;
  871. if (chan->def.center_freq1 >
  872. chan->def.chan->center_freq)
  873. ci_bw_idx = 2;
  874. else
  875. ci_bw_idx = 1;
  876. }
  877. cmd.bt_secondary_ci =
  878. iwl_ci_mask[chan->def.chan->hw_value][ci_bw_idx];
  879. cmd.secondary_ch_phy_id = *((u16 *)data.secondary->drv_priv);
  880. }
  881. rcu_read_unlock();
  882. /* Don't spam the fw with the same command over and over */
  883. if (memcmp(&cmd, &mvm->last_bt_ci_cmd_old, sizeof(cmd))) {
  884. if (iwl_mvm_send_cmd_pdu(mvm, BT_COEX_CI, 0,
  885. sizeof(cmd), &cmd))
  886. IWL_ERR(mvm, "Failed to send BT_CI cmd\n");
  887. memcpy(&mvm->last_bt_ci_cmd_old, &cmd, sizeof(cmd));
  888. }
  889. if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm))
  890. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  891. }
  892. int iwl_mvm_rx_bt_coex_notif_old(struct iwl_mvm *mvm,
  893. struct iwl_rx_cmd_buffer *rxb,
  894. struct iwl_device_cmd *dev_cmd)
  895. {
  896. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  897. struct iwl_bt_coex_profile_notif_old *notif = (void *)pkt->data;
  898. IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n");
  899. IWL_DEBUG_COEX(mvm, "\tBT status: %s\n",
  900. notif->bt_status ? "ON" : "OFF");
  901. IWL_DEBUG_COEX(mvm, "\tBT open conn %d\n", notif->bt_open_conn);
  902. IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n", notif->bt_ci_compliance);
  903. IWL_DEBUG_COEX(mvm, "\tBT primary_ch_lut %d\n",
  904. le32_to_cpu(notif->primary_ch_lut));
  905. IWL_DEBUG_COEX(mvm, "\tBT secondary_ch_lut %d\n",
  906. le32_to_cpu(notif->secondary_ch_lut));
  907. IWL_DEBUG_COEX(mvm, "\tBT activity grading %d\n",
  908. le32_to_cpu(notif->bt_activity_grading));
  909. IWL_DEBUG_COEX(mvm, "\tBT agg traffic load %d\n",
  910. notif->bt_agg_traffic_load);
  911. /* remember this notification for future use: rssi fluctuations */
  912. memcpy(&mvm->last_bt_notif_old, notif, sizeof(mvm->last_bt_notif_old));
  913. iwl_mvm_bt_coex_notif_handle(mvm);
  914. /*
  915. * This is an async handler for a notification, returning anything other
  916. * than 0 doesn't make sense even if HCMD failed.
  917. */
  918. return 0;
  919. }
  920. static void iwl_mvm_bt_rssi_iterator(void *_data, u8 *mac,
  921. struct ieee80211_vif *vif)
  922. {
  923. struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv;
  924. struct iwl_bt_iterator_data *data = _data;
  925. struct iwl_mvm *mvm = data->mvm;
  926. struct ieee80211_sta *sta;
  927. struct iwl_mvm_sta *mvmsta;
  928. struct ieee80211_chanctx_conf *chanctx_conf;
  929. rcu_read_lock();
  930. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  931. /* If channel context is invalid or not on 2.4GHz - don't count it */
  932. if (!chanctx_conf ||
  933. chanctx_conf->def.chan->band != IEEE80211_BAND_2GHZ) {
  934. rcu_read_unlock();
  935. return;
  936. }
  937. rcu_read_unlock();
  938. if (vif->type != NL80211_IFTYPE_STATION ||
  939. mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  940. return;
  941. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
  942. lockdep_is_held(&mvm->mutex));
  943. /* This can happen if the station has been removed right now */
  944. if (IS_ERR_OR_NULL(sta))
  945. return;
  946. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  947. }
  948. void iwl_mvm_bt_rssi_event_old(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  949. enum ieee80211_rssi_event rssi_event)
  950. {
  951. struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv;
  952. struct iwl_bt_iterator_data data = {
  953. .mvm = mvm,
  954. };
  955. int ret;
  956. lockdep_assert_held(&mvm->mutex);
  957. /* Ignore updates if we are in force mode */
  958. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  959. return;
  960. /*
  961. * Rssi update while not associated - can happen since the statistics
  962. * are handled asynchronously
  963. */
  964. if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  965. return;
  966. /* No BT - reports should be disabled */
  967. if (!mvm->last_bt_notif_old.bt_status)
  968. return;
  969. IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid,
  970. rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW");
  971. /*
  972. * Check if rssi is good enough for reduced Tx power, but not in loose
  973. * scheme.
  974. */
  975. if (rssi_event == RSSI_EVENT_LOW || mvm->cfg->bt_shared_single_ant ||
  976. iwl_get_coex_type(mvm, vif) == BT_COEX_LOOSE_LUT)
  977. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  978. false);
  979. else
  980. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true);
  981. if (ret)
  982. IWL_ERR(mvm, "couldn't send BT_CONFIG HCMD upon RSSI event\n");
  983. ieee80211_iterate_active_interfaces_atomic(
  984. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  985. iwl_mvm_bt_rssi_iterator, &data);
  986. if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm))
  987. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  988. }
  989. #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000)
  990. #define LINK_QUAL_AGG_TIME_LIMIT_BT_ACT (1200)
  991. u16 iwl_mvm_coex_agg_time_limit_old(struct iwl_mvm *mvm,
  992. struct ieee80211_sta *sta)
  993. {
  994. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  995. enum iwl_bt_coex_lut_type lut_type;
  996. if (le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading) <
  997. BT_HIGH_TRAFFIC)
  998. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  999. if (mvm->last_bt_notif_old.ttc_enabled)
  1000. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  1001. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  1002. if (lut_type == BT_COEX_LOOSE_LUT || lut_type == BT_COEX_INVALID_LUT)
  1003. return LINK_QUAL_AGG_TIME_LIMIT_DEF;
  1004. /* tight coex, high bt traffic, reduce AGG time limit */
  1005. return LINK_QUAL_AGG_TIME_LIMIT_BT_ACT;
  1006. }
  1007. bool iwl_mvm_bt_coex_is_mimo_allowed_old(struct iwl_mvm *mvm,
  1008. struct ieee80211_sta *sta)
  1009. {
  1010. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  1011. enum iwl_bt_coex_lut_type lut_type;
  1012. if (mvm->last_bt_notif_old.ttc_enabled)
  1013. return true;
  1014. if (le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading) <
  1015. BT_HIGH_TRAFFIC)
  1016. return true;
  1017. /*
  1018. * In Tight / TxTxDis, BT can't Rx while we Tx, so use both antennas
  1019. * since BT is already killed.
  1020. * In Loose, BT can Rx while we Tx, so forbid MIMO to let BT Rx while
  1021. * we Tx.
  1022. * When we are in 5GHz, we'll get BT_COEX_INVALID_LUT allowing MIMO.
  1023. */
  1024. lut_type = iwl_get_coex_type(mvm, mvmsta->vif);
  1025. return lut_type != BT_COEX_LOOSE_LUT;
  1026. }
  1027. bool iwl_mvm_bt_coex_is_shared_ant_avail_old(struct iwl_mvm *mvm)
  1028. {
  1029. u32 ag = le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading);
  1030. return ag == BT_OFF;
  1031. }
  1032. bool iwl_mvm_bt_coex_is_tpc_allowed_old(struct iwl_mvm *mvm,
  1033. enum ieee80211_band band)
  1034. {
  1035. u32 bt_activity =
  1036. le32_to_cpu(mvm->last_bt_notif_old.bt_activity_grading);
  1037. if (band != IEEE80211_BAND_2GHZ)
  1038. return false;
  1039. return bt_activity >= BT_LOW_TRAFFIC;
  1040. }
  1041. void iwl_mvm_bt_coex_vif_change_old(struct iwl_mvm *mvm)
  1042. {
  1043. iwl_mvm_bt_coex_notif_handle(mvm);
  1044. }
  1045. int iwl_mvm_rx_ant_coupling_notif_old(struct iwl_mvm *mvm,
  1046. struct iwl_rx_cmd_buffer *rxb,
  1047. struct iwl_device_cmd *dev_cmd)
  1048. {
  1049. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1050. u32 ant_isolation = le32_to_cpup((void *)pkt->data);
  1051. u8 __maybe_unused lower_bound, upper_bound;
  1052. int ret;
  1053. u8 lut;
  1054. struct iwl_bt_coex_cmd_old *bt_cmd;
  1055. struct iwl_host_cmd cmd = {
  1056. .id = BT_CONFIG,
  1057. .len = { sizeof(*bt_cmd), },
  1058. .dataflags = { IWL_HCMD_DFL_NOCOPY, },
  1059. };
  1060. if (!IWL_MVM_BT_COEX_CORUNNING)
  1061. return 0;
  1062. lockdep_assert_held(&mvm->mutex);
  1063. /* Ignore updates if we are in force mode */
  1064. if (unlikely(mvm->bt_force_ant_mode != BT_FORCE_ANT_DIS))
  1065. return 0;
  1066. if (ant_isolation == mvm->last_ant_isol)
  1067. return 0;
  1068. for (lut = 0; lut < ARRAY_SIZE(antenna_coupling_ranges) - 1; lut++)
  1069. if (ant_isolation < antenna_coupling_ranges[lut + 1].range)
  1070. break;
  1071. lower_bound = antenna_coupling_ranges[lut].range;
  1072. if (lut < ARRAY_SIZE(antenna_coupling_ranges) - 1)
  1073. upper_bound = antenna_coupling_ranges[lut + 1].range;
  1074. else
  1075. upper_bound = antenna_coupling_ranges[lut].range;
  1076. IWL_DEBUG_COEX(mvm, "Antenna isolation=%d in range [%d,%d[, lut=%d\n",
  1077. ant_isolation, lower_bound, upper_bound, lut);
  1078. mvm->last_ant_isol = ant_isolation;
  1079. if (mvm->last_corun_lut == lut)
  1080. return 0;
  1081. mvm->last_corun_lut = lut;
  1082. bt_cmd = kzalloc(sizeof(*bt_cmd), GFP_KERNEL);
  1083. if (!bt_cmd)
  1084. return 0;
  1085. cmd.data[0] = bt_cmd;
  1086. bt_cmd->flags = cpu_to_le32(BT_COEX_NW_OLD);
  1087. bt_cmd->valid_bit_msk |= cpu_to_le32(BT_VALID_ENABLE |
  1088. BT_VALID_CORUN_LUT_20 |
  1089. BT_VALID_CORUN_LUT_40);
  1090. /* For the moment, use the same LUT for 20GHz and 40GHz */
  1091. memcpy(bt_cmd->bt4_corun_lut20, antenna_coupling_ranges[lut].lut20,
  1092. sizeof(bt_cmd->bt4_corun_lut20));
  1093. memcpy(bt_cmd->bt4_corun_lut40, antenna_coupling_ranges[lut].lut20,
  1094. sizeof(bt_cmd->bt4_corun_lut40));
  1095. ret = iwl_mvm_send_cmd(mvm, &cmd);
  1096. kfree(bt_cmd);
  1097. return ret;
  1098. }