bt-coex.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  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 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called COPYING.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2013 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *
  62. *****************************************************************************/
  63. #include <net/mac80211.h>
  64. #include "fw-api-bt-coex.h"
  65. #include "iwl-modparams.h"
  66. #include "mvm.h"
  67. #include "iwl-debug.h"
  68. #define EVENT_PRIO_ANT(_evt, _prio, _shrd_ant) \
  69. [(_evt)] = (((_prio) << BT_COEX_PRIO_TBL_PRIO_POS) | \
  70. ((_shrd_ant) << BT_COEX_PRIO_TBL_SHRD_ANT_POS))
  71. static const u8 iwl_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = {
  72. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_INIT_CALIB1,
  73. BT_COEX_PRIO_TBL_PRIO_BYPASS, 0),
  74. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_INIT_CALIB2,
  75. BT_COEX_PRIO_TBL_PRIO_BYPASS, 1),
  76. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_LOW1,
  77. BT_COEX_PRIO_TBL_PRIO_LOW, 0),
  78. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_LOW2,
  79. BT_COEX_PRIO_TBL_PRIO_LOW, 1),
  80. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_HIGH1,
  81. BT_COEX_PRIO_TBL_PRIO_HIGH, 0),
  82. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_HIGH2,
  83. BT_COEX_PRIO_TBL_PRIO_HIGH, 1),
  84. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_DTIM,
  85. BT_COEX_PRIO_TBL_DISABLED, 0),
  86. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_SCAN52,
  87. BT_COEX_PRIO_TBL_PRIO_COEX_OFF, 0),
  88. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_SCAN24,
  89. BT_COEX_PRIO_TBL_PRIO_COEX_ON, 0),
  90. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_IDLE,
  91. BT_COEX_PRIO_TBL_PRIO_COEX_IDLE, 0),
  92. 0, 0, 0, 0, 0, 0,
  93. };
  94. #undef EVENT_PRIO_ANT
  95. /* BT Antenna Coupling Threshold (dB) */
  96. #define IWL_BT_ANTENNA_COUPLING_THRESHOLD (35)
  97. #define IWL_BT_LOAD_FORCE_SISO_THRESHOLD (3)
  98. #define BT_ENABLE_REDUCED_TXPOWER_THRESHOLD (-62)
  99. #define BT_DISABLE_REDUCED_TXPOWER_THRESHOLD (-65)
  100. #define BT_REDUCED_TX_POWER_BIT BIT(7)
  101. static inline bool is_loose_coex(void)
  102. {
  103. return iwlwifi_mod_params.ant_coupling >
  104. IWL_BT_ANTENNA_COUPLING_THRESHOLD;
  105. }
  106. int iwl_send_bt_prio_tbl(struct iwl_mvm *mvm)
  107. {
  108. return iwl_mvm_send_cmd_pdu(mvm, BT_COEX_PRIO_TABLE, CMD_SYNC,
  109. sizeof(struct iwl_bt_coex_prio_tbl_cmd),
  110. &iwl_bt_prio_tbl);
  111. }
  112. static int iwl_send_bt_env(struct iwl_mvm *mvm, u8 action, u8 type)
  113. {
  114. struct iwl_bt_coex_prot_env_cmd env_cmd;
  115. int ret;
  116. env_cmd.action = action;
  117. env_cmd.type = type;
  118. ret = iwl_mvm_send_cmd_pdu(mvm, BT_COEX_PROT_ENV, CMD_SYNC,
  119. sizeof(env_cmd), &env_cmd);
  120. if (ret)
  121. IWL_ERR(mvm, "failed to send BT env command\n");
  122. return ret;
  123. }
  124. enum iwl_bt_kill_msk {
  125. BT_KILL_MSK_DEFAULT,
  126. BT_KILL_MSK_SCO_HID_A2DP,
  127. BT_KILL_MSK_REDUCED_TXPOW,
  128. BT_KILL_MSK_MAX,
  129. };
  130. static const u32 iwl_bt_ack_kill_msk[BT_KILL_MSK_MAX] = {
  131. [BT_KILL_MSK_DEFAULT] = 0xffff0000,
  132. [BT_KILL_MSK_SCO_HID_A2DP] = 0xffffffff,
  133. [BT_KILL_MSK_REDUCED_TXPOW] = 0,
  134. };
  135. static const u32 iwl_bt_cts_kill_msk[BT_KILL_MSK_MAX] = {
  136. [BT_KILL_MSK_DEFAULT] = 0xffff0000,
  137. [BT_KILL_MSK_SCO_HID_A2DP] = 0xffffffff,
  138. [BT_KILL_MSK_REDUCED_TXPOW] = 0,
  139. };
  140. #define IWL_BT_DEFAULT_BOOST (0xf0f0f0f0)
  141. /* Tight Coex */
  142. static const __le32 iwl_tight_lookup[BT_COEX_LUT_SIZE] = {
  143. cpu_to_le32(0xaaaaaaaa),
  144. cpu_to_le32(0xaaaaaaaa),
  145. cpu_to_le32(0xaeaaaaaa),
  146. cpu_to_le32(0xaaaaaaaa),
  147. cpu_to_le32(0xcc00ff28),
  148. cpu_to_le32(0x0000aaaa),
  149. cpu_to_le32(0xcc00aaaa),
  150. cpu_to_le32(0x0000aaaa),
  151. cpu_to_le32(0xc0004000),
  152. cpu_to_le32(0x00000000),
  153. cpu_to_le32(0xf0005000),
  154. cpu_to_le32(0xf0005000),
  155. };
  156. /* Loose Coex */
  157. static const __le32 iwl_loose_lookup[BT_COEX_LUT_SIZE] = {
  158. cpu_to_le32(0xaaaaaaaa),
  159. cpu_to_le32(0xaaaaaaaa),
  160. cpu_to_le32(0xaaaaaaaa),
  161. cpu_to_le32(0xaaaaaaaa),
  162. cpu_to_le32(0xcc00ff28),
  163. cpu_to_le32(0x0000aaaa),
  164. cpu_to_le32(0xcc00aaaa),
  165. cpu_to_le32(0x0000aaaa),
  166. cpu_to_le32(0x00000000),
  167. cpu_to_le32(0x00000000),
  168. cpu_to_le32(0xf0005000),
  169. cpu_to_le32(0xf0005000),
  170. };
  171. /* Full concurrency */
  172. static const __le32 iwl_concurrent_lookup[BT_COEX_LUT_SIZE] = {
  173. cpu_to_le32(0xaaaaaaaa),
  174. cpu_to_le32(0xaaaaaaaa),
  175. cpu_to_le32(0xaaaaaaaa),
  176. cpu_to_le32(0xaaaaaaaa),
  177. cpu_to_le32(0xaaaaaaaa),
  178. cpu_to_le32(0xaaaaaaaa),
  179. cpu_to_le32(0xaaaaaaaa),
  180. cpu_to_le32(0xaaaaaaaa),
  181. cpu_to_le32(0x00000000),
  182. cpu_to_le32(0x00000000),
  183. cpu_to_le32(0x00000000),
  184. cpu_to_le32(0x00000000),
  185. };
  186. /* single shared antenna */
  187. static const __le32 iwl_single_shared_ant_lookup[BT_COEX_LUT_SIZE] = {
  188. cpu_to_le32(0x40000000),
  189. cpu_to_le32(0x00000000),
  190. cpu_to_le32(0x44000000),
  191. cpu_to_le32(0x00000000),
  192. cpu_to_le32(0x40000000),
  193. cpu_to_le32(0x00000000),
  194. cpu_to_le32(0x44000000),
  195. cpu_to_le32(0x00000000),
  196. cpu_to_le32(0xC0004000),
  197. cpu_to_le32(0xF0005000),
  198. cpu_to_le32(0xC0004000),
  199. cpu_to_le32(0xF0005000),
  200. };
  201. int iwl_send_bt_init_conf(struct iwl_mvm *mvm)
  202. {
  203. struct iwl_bt_coex_cmd cmd = {
  204. .max_kill = 5,
  205. .bt3_time_t7_value = 1,
  206. .bt3_prio_sample_time = 2,
  207. .bt3_timer_t2_value = 0xc,
  208. };
  209. int ret;
  210. cmd.flags = iwlwifi_mod_params.bt_coex_active ?
  211. BT_COEX_NW : BT_COEX_DISABLE;
  212. cmd.flags |= BT_CH_PRIMARY_EN | BT_SYNC_2_BT_DISABLE;
  213. cmd.valid_bit_msk = cpu_to_le16(BT_VALID_ENABLE |
  214. BT_VALID_BT_PRIO_BOOST |
  215. BT_VALID_MAX_KILL |
  216. BT_VALID_3W_TMRS |
  217. BT_VALID_KILL_ACK |
  218. BT_VALID_KILL_CTS |
  219. BT_VALID_REDUCED_TX_POWER |
  220. BT_VALID_LUT);
  221. if (mvm->cfg->bt_shared_single_ant)
  222. memcpy(&cmd.decision_lut, iwl_single_shared_ant_lookup,
  223. sizeof(iwl_single_shared_ant_lookup));
  224. else if (is_loose_coex())
  225. memcpy(&cmd.decision_lut, iwl_loose_lookup,
  226. sizeof(iwl_tight_lookup));
  227. else
  228. memcpy(&cmd.decision_lut, iwl_tight_lookup,
  229. sizeof(iwl_tight_lookup));
  230. cmd.bt_prio_boost = cpu_to_le32(IWL_BT_DEFAULT_BOOST);
  231. cmd.kill_ack_msk =
  232. cpu_to_le32(iwl_bt_ack_kill_msk[BT_KILL_MSK_DEFAULT]);
  233. cmd.kill_cts_msk =
  234. cpu_to_le32(iwl_bt_cts_kill_msk[BT_KILL_MSK_DEFAULT]);
  235. memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
  236. /* go to CALIB state in internal BT-Coex state machine */
  237. ret = iwl_send_bt_env(mvm, BT_COEX_ENV_OPEN,
  238. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  239. if (ret)
  240. return ret;
  241. ret = iwl_send_bt_env(mvm, BT_COEX_ENV_CLOSE,
  242. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  243. if (ret)
  244. return ret;
  245. return iwl_mvm_send_cmd_pdu(mvm, BT_CONFIG, CMD_SYNC,
  246. sizeof(cmd), &cmd);
  247. }
  248. static int iwl_mvm_bt_udpate_ctrl_kill_msk(struct iwl_mvm *mvm,
  249. bool reduced_tx_power)
  250. {
  251. enum iwl_bt_kill_msk bt_kill_msk;
  252. struct iwl_bt_coex_cmd cmd = {};
  253. struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
  254. lockdep_assert_held(&mvm->mutex);
  255. if (reduced_tx_power) {
  256. /* Reduced Tx power has precedence on the type of the profile */
  257. bt_kill_msk = BT_KILL_MSK_REDUCED_TXPOW;
  258. } else {
  259. /* Low latency BT profile is active: give higher prio to BT */
  260. if (BT_MBOX_MSG(notif, 3, SCO_STATE) ||
  261. BT_MBOX_MSG(notif, 3, A2DP_STATE) ||
  262. BT_MBOX_MSG(notif, 3, SNIFF_STATE))
  263. bt_kill_msk = BT_KILL_MSK_SCO_HID_A2DP;
  264. else
  265. bt_kill_msk = BT_KILL_MSK_DEFAULT;
  266. }
  267. IWL_DEBUG_COEX(mvm,
  268. "Update kill_msk: %d - SCO %sactive A2DP %sactive SNIFF %sactive\n",
  269. bt_kill_msk,
  270. BT_MBOX_MSG(notif, 3, SCO_STATE) ? "" : "in",
  271. BT_MBOX_MSG(notif, 3, A2DP_STATE) ? "" : "in",
  272. BT_MBOX_MSG(notif, 3, SNIFF_STATE) ? "" : "in");
  273. /* Don't send HCMD if there is no update */
  274. if (bt_kill_msk == mvm->bt_kill_msk)
  275. return 0;
  276. mvm->bt_kill_msk = bt_kill_msk;
  277. cmd.kill_ack_msk = cpu_to_le32(iwl_bt_ack_kill_msk[bt_kill_msk]);
  278. cmd.kill_cts_msk = cpu_to_le32(iwl_bt_cts_kill_msk[bt_kill_msk]);
  279. cmd.valid_bit_msk = cpu_to_le16(BT_VALID_KILL_ACK | BT_VALID_KILL_CTS);
  280. IWL_DEBUG_COEX(mvm, "bt_kill_msk = %d\n", bt_kill_msk);
  281. return iwl_mvm_send_cmd_pdu(mvm, BT_CONFIG, CMD_SYNC,
  282. sizeof(cmd), &cmd);
  283. }
  284. static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id,
  285. bool enable)
  286. {
  287. struct iwl_bt_coex_cmd cmd = {
  288. .valid_bit_msk = cpu_to_le16(BT_VALID_REDUCED_TX_POWER),
  289. .bt_reduced_tx_power = sta_id,
  290. };
  291. struct ieee80211_sta *sta;
  292. struct iwl_mvm_sta *mvmsta;
  293. /* This can happen if the station has been removed right now */
  294. if (sta_id == IWL_MVM_STATION_COUNT)
  295. return 0;
  296. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
  297. lockdep_is_held(&mvm->mutex));
  298. mvmsta = (void *)sta->drv_priv;
  299. /* nothing to do */
  300. if (mvmsta->bt_reduced_txpower == enable)
  301. return 0;
  302. if (enable)
  303. cmd.bt_reduced_tx_power |= BT_REDUCED_TX_POWER_BIT;
  304. IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n",
  305. enable ? "en" : "dis", sta_id);
  306. mvmsta->bt_reduced_txpower = enable;
  307. /* Send ASYNC since this can be sent from an atomic context */
  308. return iwl_mvm_send_cmd_pdu(mvm, BT_CONFIG, CMD_ASYNC,
  309. sizeof(cmd), &cmd);
  310. }
  311. struct iwl_bt_iterator_data {
  312. struct iwl_bt_coex_profile_notif *notif;
  313. struct iwl_mvm *mvm;
  314. u32 num_bss_ifaces;
  315. bool reduced_tx_power;
  316. };
  317. static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac,
  318. struct ieee80211_vif *vif)
  319. {
  320. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  321. struct iwl_bt_iterator_data *data = _data;
  322. struct iwl_mvm *mvm = data->mvm;
  323. struct ieee80211_chanctx_conf *chanctx_conf;
  324. enum ieee80211_smps_mode smps_mode;
  325. enum ieee80211_band band;
  326. int ave_rssi;
  327. lockdep_assert_held(&mvm->mutex);
  328. if (vif->type != NL80211_IFTYPE_STATION)
  329. return;
  330. rcu_read_lock();
  331. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  332. if (chanctx_conf && chanctx_conf->def.chan)
  333. band = chanctx_conf->def.chan->band;
  334. else
  335. band = -1;
  336. rcu_read_unlock();
  337. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  338. if (band != IEEE80211_BAND_2GHZ) {
  339. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX,
  340. smps_mode);
  341. return;
  342. }
  343. if (data->notif->bt_status)
  344. smps_mode = IEEE80211_SMPS_DYNAMIC;
  345. if (data->notif->bt_traffic_load >= IWL_BT_LOAD_FORCE_SISO_THRESHOLD)
  346. smps_mode = IEEE80211_SMPS_STATIC;
  347. IWL_DEBUG_COEX(data->mvm,
  348. "mac %d: bt_status %d traffic_load %d smps_req %d\n",
  349. mvmvif->id, data->notif->bt_status,
  350. data->notif->bt_traffic_load, smps_mode);
  351. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_BT_COEX, smps_mode);
  352. /* don't reduce the Tx power if in loose scheme */
  353. if (is_loose_coex())
  354. return;
  355. data->num_bss_ifaces++;
  356. /* reduced Txpower only if there are open BT connections, so ...*/
  357. if (!BT_MBOX_MSG(data->notif, 3, OPEN_CON_2)) {
  358. /* ... cancel reduced Tx power ... */
  359. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
  360. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  361. data->reduced_tx_power = false;
  362. /* ... and there is no need to get reports on RSSI any more. */
  363. ieee80211_disable_rssi_reports(vif);
  364. return;
  365. }
  366. ave_rssi = ieee80211_ave_rssi(vif);
  367. /* if the RSSI isn't valid, fake it is very low */
  368. if (!ave_rssi)
  369. ave_rssi = -100;
  370. if (ave_rssi > BT_ENABLE_REDUCED_TXPOWER_THRESHOLD) {
  371. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true))
  372. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  373. /*
  374. * bt_kill_msk can be BT_KILL_MSK_REDUCED_TXPOW only if all the
  375. * BSS / P2P clients have rssi above threshold.
  376. * We set the bt_kill_msk to BT_KILL_MSK_REDUCED_TXPOW before
  377. * the iteration, if one interface's rssi isn't good enough,
  378. * bt_kill_msk will be set to default values.
  379. */
  380. } else if (ave_rssi < BT_DISABLE_REDUCED_TXPOWER_THRESHOLD) {
  381. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
  382. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  383. /*
  384. * One interface hasn't rssi above threshold, bt_kill_msk must
  385. * be set to default values.
  386. */
  387. data->reduced_tx_power = false;
  388. }
  389. /* Begin to monitor the RSSI: it may influence the reduced Tx power */
  390. ieee80211_enable_rssi_reports(vif, BT_DISABLE_REDUCED_TXPOWER_THRESHOLD,
  391. BT_ENABLE_REDUCED_TXPOWER_THRESHOLD);
  392. }
  393. static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm)
  394. {
  395. struct iwl_bt_iterator_data data = {
  396. .mvm = mvm,
  397. .notif = &mvm->last_bt_notif,
  398. .reduced_tx_power = true,
  399. };
  400. ieee80211_iterate_active_interfaces_atomic(
  401. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  402. iwl_mvm_bt_notif_iterator, &data);
  403. /*
  404. * If there are no BSS / P2P client interfaces, reduced Tx Power is
  405. * irrelevant since it is based on the RSSI coming from the beacon.
  406. * Use BT_KILL_MSK_DEFAULT in that case.
  407. */
  408. data.reduced_tx_power = data.reduced_tx_power && data.num_bss_ifaces;
  409. if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm, data.reduced_tx_power))
  410. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  411. }
  412. /* upon association, the fw will send in BT Coex notification */
  413. int iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm,
  414. struct iwl_rx_cmd_buffer *rxb,
  415. struct iwl_device_cmd *dev_cmd)
  416. {
  417. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  418. struct iwl_bt_coex_profile_notif *notif = (void *)pkt->data;
  419. IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n");
  420. IWL_DEBUG_COEX(mvm, "\tBT %salive\n", notif->bt_status ? "" : "not ");
  421. IWL_DEBUG_COEX(mvm, "\tBT open conn %d\n", notif->bt_open_conn);
  422. IWL_DEBUG_COEX(mvm, "\tBT traffic load %d\n", notif->bt_traffic_load);
  423. IWL_DEBUG_COEX(mvm, "\tBT agg traffic load %d\n",
  424. notif->bt_agg_traffic_load);
  425. IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n", notif->bt_ci_compliance);
  426. /* remember this notification for future use: rssi fluctuations */
  427. memcpy(&mvm->last_bt_notif, notif, sizeof(mvm->last_bt_notif));
  428. iwl_mvm_bt_coex_notif_handle(mvm);
  429. /*
  430. * This is an async handler for a notification, returning anything other
  431. * than 0 doesn't make sense even if HCMD failed.
  432. */
  433. return 0;
  434. }
  435. static void iwl_mvm_bt_rssi_iterator(void *_data, u8 *mac,
  436. struct ieee80211_vif *vif)
  437. {
  438. struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv;
  439. struct iwl_bt_iterator_data *data = _data;
  440. struct iwl_mvm *mvm = data->mvm;
  441. struct ieee80211_sta *sta;
  442. struct iwl_mvm_sta *mvmsta;
  443. if (vif->type != NL80211_IFTYPE_STATION ||
  444. mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  445. return;
  446. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
  447. lockdep_is_held(&mvm->mutex));
  448. mvmsta = (void *)sta->drv_priv;
  449. /*
  450. * This interface doesn't support reduced Tx power (because of low
  451. * RSSI probably), then set bt_kill_msk to default values.
  452. */
  453. if (!mvmsta->bt_reduced_txpower)
  454. data->reduced_tx_power = false;
  455. /* else - possibly leave it to BT_KILL_MSK_REDUCED_TXPOW */
  456. }
  457. void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  458. enum ieee80211_rssi_event rssi_event)
  459. {
  460. struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv;
  461. struct iwl_bt_iterator_data data = {
  462. .mvm = mvm,
  463. .reduced_tx_power = true,
  464. };
  465. int ret;
  466. mutex_lock(&mvm->mutex);
  467. /* Rssi update while not associated ?! */
  468. if (WARN_ON_ONCE(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT))
  469. goto out_unlock;
  470. /* No open connection - reports should be disabled */
  471. if (!BT_MBOX_MSG(&mvm->last_bt_notif, 3, OPEN_CON_2))
  472. goto out_unlock;
  473. IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid,
  474. rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW");
  475. /*
  476. * Check if rssi is good enough for reduced Tx power, but not in loose
  477. * scheme.
  478. */
  479. if (rssi_event == RSSI_EVENT_LOW || is_loose_coex())
  480. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  481. false);
  482. else
  483. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true);
  484. if (ret)
  485. IWL_ERR(mvm, "couldn't send BT_CONFIG HCMD upon RSSI event\n");
  486. ieee80211_iterate_active_interfaces_atomic(
  487. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  488. iwl_mvm_bt_rssi_iterator, &data);
  489. /*
  490. * If there are no BSS / P2P client interfaces, reduced Tx Power is
  491. * irrelevant since it is based on the RSSI coming from the beacon.
  492. * Use BT_KILL_MSK_DEFAULT in that case.
  493. */
  494. data.reduced_tx_power = data.reduced_tx_power && data.num_bss_ifaces;
  495. if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm, data.reduced_tx_power))
  496. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  497. out_unlock:
  498. mutex_unlock(&mvm->mutex);
  499. }
  500. void iwl_mvm_bt_coex_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  501. {
  502. struct ieee80211_chanctx_conf *chanctx_conf;
  503. enum ieee80211_band band;
  504. rcu_read_lock();
  505. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  506. if (chanctx_conf && chanctx_conf->def.chan)
  507. band = chanctx_conf->def.chan->band;
  508. else
  509. band = -1;
  510. rcu_read_unlock();
  511. /* if we are in 2GHz we will get a notification from the fw */
  512. if (band == IEEE80211_BAND_2GHZ)
  513. return;
  514. /* else, we can remove all the constraints */
  515. memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
  516. iwl_mvm_bt_coex_notif_handle(mvm);
  517. }