bt-coex.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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(0xaeaaaaaa),
  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. int iwl_send_bt_init_conf(struct iwl_mvm *mvm)
  187. {
  188. struct iwl_bt_coex_cmd cmd = {
  189. .max_kill = 5,
  190. .bt3_time_t7_value = 1,
  191. .bt3_prio_sample_time = 2,
  192. .bt3_timer_t2_value = 0xc,
  193. };
  194. int ret;
  195. cmd.flags = iwlwifi_mod_params.bt_coex_active ?
  196. BT_COEX_NW : BT_COEX_DISABLE;
  197. cmd.flags |= BT_CH_PRIMARY_EN | BT_SYNC_2_BT_DISABLE;
  198. cmd.valid_bit_msk = cpu_to_le16(BT_VALID_ENABLE |
  199. BT_VALID_BT_PRIO_BOOST |
  200. BT_VALID_MAX_KILL |
  201. BT_VALID_3W_TMRS |
  202. BT_VALID_KILL_ACK |
  203. BT_VALID_KILL_CTS |
  204. BT_VALID_REDUCED_TX_POWER |
  205. BT_VALID_LUT);
  206. if (is_loose_coex())
  207. memcpy(&cmd.decision_lut, iwl_loose_lookup,
  208. sizeof(iwl_tight_lookup));
  209. else
  210. memcpy(&cmd.decision_lut, iwl_tight_lookup,
  211. sizeof(iwl_tight_lookup));
  212. cmd.bt_prio_boost = cpu_to_le32(IWL_BT_DEFAULT_BOOST);
  213. cmd.kill_ack_msk =
  214. cpu_to_le32(iwl_bt_ack_kill_msk[BT_KILL_MSK_DEFAULT]);
  215. cmd.kill_cts_msk =
  216. cpu_to_le32(iwl_bt_cts_kill_msk[BT_KILL_MSK_DEFAULT]);
  217. memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
  218. /* go to CALIB state in internal BT-Coex state machine */
  219. ret = iwl_send_bt_env(mvm, BT_COEX_ENV_OPEN,
  220. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  221. if (ret)
  222. return ret;
  223. ret = iwl_send_bt_env(mvm, BT_COEX_ENV_CLOSE,
  224. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  225. if (ret)
  226. return ret;
  227. return iwl_mvm_send_cmd_pdu(mvm, BT_CONFIG, CMD_SYNC,
  228. sizeof(cmd), &cmd);
  229. }
  230. static int iwl_mvm_bt_udpate_ctrl_kill_msk(struct iwl_mvm *mvm,
  231. bool reduced_tx_power)
  232. {
  233. enum iwl_bt_kill_msk bt_kill_msk;
  234. struct iwl_bt_coex_cmd cmd = {};
  235. struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
  236. lockdep_assert_held(&mvm->mutex);
  237. if (reduced_tx_power) {
  238. /* Reduced Tx power has precedence on the type of the profile */
  239. bt_kill_msk = BT_KILL_MSK_REDUCED_TXPOW;
  240. } else {
  241. /* Low latency BT profile is active: give higher prio to BT */
  242. if (BT_MBOX_MSG(notif, 3, SCO_STATE) ||
  243. BT_MBOX_MSG(notif, 3, A2DP_STATE) ||
  244. BT_MBOX_MSG(notif, 3, SNIFF_STATE))
  245. bt_kill_msk = BT_KILL_MSK_SCO_HID_A2DP;
  246. else
  247. bt_kill_msk = BT_KILL_MSK_DEFAULT;
  248. }
  249. IWL_DEBUG_COEX(mvm,
  250. "Update kill_msk: %d - SCO %sactive A2DP %sactive SNIFF %sactive\n",
  251. bt_kill_msk,
  252. BT_MBOX_MSG(notif, 3, SCO_STATE) ? "" : "in",
  253. BT_MBOX_MSG(notif, 3, A2DP_STATE) ? "" : "in",
  254. BT_MBOX_MSG(notif, 3, SNIFF_STATE) ? "" : "in");
  255. /* Don't send HCMD if there is no update */
  256. if (bt_kill_msk == mvm->bt_kill_msk)
  257. return 0;
  258. mvm->bt_kill_msk = bt_kill_msk;
  259. cmd.kill_ack_msk = cpu_to_le32(iwl_bt_ack_kill_msk[bt_kill_msk]);
  260. cmd.kill_cts_msk = cpu_to_le32(iwl_bt_cts_kill_msk[bt_kill_msk]);
  261. cmd.valid_bit_msk = cpu_to_le16(BT_VALID_KILL_ACK | BT_VALID_KILL_CTS);
  262. IWL_DEBUG_COEX(mvm, "bt_kill_msk = %d\n", bt_kill_msk);
  263. return iwl_mvm_send_cmd_pdu(mvm, BT_CONFIG, CMD_SYNC,
  264. sizeof(cmd), &cmd);
  265. }
  266. static int iwl_mvm_bt_coex_reduced_txp(struct iwl_mvm *mvm, u8 sta_id,
  267. bool enable)
  268. {
  269. struct iwl_bt_coex_cmd cmd = {
  270. .valid_bit_msk = cpu_to_le16(BT_VALID_REDUCED_TX_POWER),
  271. .bt_reduced_tx_power = sta_id,
  272. };
  273. struct ieee80211_sta *sta;
  274. struct iwl_mvm_sta *mvmsta;
  275. /* This can happen if the station has been removed right now */
  276. if (sta_id == IWL_MVM_STATION_COUNT)
  277. return 0;
  278. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
  279. lockdep_is_held(&mvm->mutex));
  280. mvmsta = (void *)sta->drv_priv;
  281. /* nothing to do */
  282. if (mvmsta->bt_reduced_txpower == enable)
  283. return 0;
  284. if (enable)
  285. cmd.bt_reduced_tx_power |= BT_REDUCED_TX_POWER_BIT;
  286. IWL_DEBUG_COEX(mvm, "%sable reduced Tx Power for sta %d\n",
  287. enable ? "en" : "dis", sta_id);
  288. mvmsta->bt_reduced_txpower = enable;
  289. /* Send ASYNC since this can be sent from an atomic context */
  290. return iwl_mvm_send_cmd_pdu(mvm, BT_CONFIG, CMD_ASYNC,
  291. sizeof(cmd), &cmd);
  292. }
  293. struct iwl_bt_iterator_data {
  294. struct iwl_bt_coex_profile_notif *notif;
  295. struct iwl_mvm *mvm;
  296. u32 num_bss_ifaces;
  297. bool reduced_tx_power;
  298. };
  299. static void iwl_mvm_bt_notif_iterator(void *_data, u8 *mac,
  300. struct ieee80211_vif *vif)
  301. {
  302. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  303. struct iwl_bt_iterator_data *data = _data;
  304. struct iwl_mvm *mvm = data->mvm;
  305. struct ieee80211_chanctx_conf *chanctx_conf;
  306. enum ieee80211_smps_mode smps_mode;
  307. enum ieee80211_band band;
  308. int ave_rssi;
  309. if (vif->type != NL80211_IFTYPE_STATION)
  310. return;
  311. rcu_read_lock();
  312. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  313. if (chanctx_conf && chanctx_conf->def.chan)
  314. band = chanctx_conf->def.chan->band;
  315. else
  316. band = -1;
  317. rcu_read_unlock();
  318. smps_mode = IEEE80211_SMPS_AUTOMATIC;
  319. if (band != IEEE80211_BAND_2GHZ) {
  320. ieee80211_request_smps(vif, smps_mode);
  321. return;
  322. }
  323. if (data->notif->bt_status)
  324. smps_mode = IEEE80211_SMPS_DYNAMIC;
  325. if (data->notif->bt_traffic_load >= IWL_BT_LOAD_FORCE_SISO_THRESHOLD)
  326. smps_mode = IEEE80211_SMPS_STATIC;
  327. IWL_DEBUG_COEX(data->mvm,
  328. "mac %d: bt_status %d traffic_load %d smps_req %d\n",
  329. mvmvif->id, data->notif->bt_status,
  330. data->notif->bt_traffic_load, smps_mode);
  331. ieee80211_request_smps(vif, smps_mode);
  332. /* don't reduce the Tx power if in loose scheme */
  333. if (is_loose_coex())
  334. return;
  335. data->num_bss_ifaces++;
  336. /* reduced Txpower only if there are open BT connections, so ...*/
  337. if (!BT_MBOX_MSG(data->notif, 3, OPEN_CON_2)) {
  338. /* ... cancel reduced Tx power ... */
  339. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
  340. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  341. data->reduced_tx_power = false;
  342. /* ... and there is no need to get reports on RSSI any more. */
  343. ieee80211_disable_rssi_reports(vif);
  344. return;
  345. }
  346. ave_rssi = ieee80211_ave_rssi(vif);
  347. /* if the RSSI isn't valid, fake it is very low */
  348. if (!ave_rssi)
  349. ave_rssi = -100;
  350. if (ave_rssi > BT_ENABLE_REDUCED_TXPOWER_THRESHOLD) {
  351. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true))
  352. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  353. /*
  354. * bt_kill_msk can be BT_KILL_MSK_REDUCED_TXPOW only if all the
  355. * BSS / P2P clients have rssi above threshold.
  356. * We set the bt_kill_msk to BT_KILL_MSK_REDUCED_TXPOW before
  357. * the iteration, if one interface's rssi isn't good enough,
  358. * bt_kill_msk will be set to default values.
  359. */
  360. } else if (ave_rssi < BT_DISABLE_REDUCED_TXPOWER_THRESHOLD) {
  361. if (iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, false))
  362. IWL_ERR(mvm, "Couldn't send BT_CONFIG cmd\n");
  363. /*
  364. * One interface hasn't rssi above threshold, bt_kill_msk must
  365. * be set to default values.
  366. */
  367. data->reduced_tx_power = false;
  368. }
  369. /* Begin to monitor the RSSI: it may influence the reduced Tx power */
  370. ieee80211_enable_rssi_reports(vif, BT_DISABLE_REDUCED_TXPOWER_THRESHOLD,
  371. BT_ENABLE_REDUCED_TXPOWER_THRESHOLD);
  372. }
  373. static void iwl_mvm_bt_coex_notif_handle(struct iwl_mvm *mvm)
  374. {
  375. struct iwl_bt_iterator_data data = {
  376. .mvm = mvm,
  377. .notif = &mvm->last_bt_notif,
  378. .reduced_tx_power = true,
  379. };
  380. ieee80211_iterate_active_interfaces_atomic(
  381. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  382. iwl_mvm_bt_notif_iterator, &data);
  383. /*
  384. * If there are no BSS / P2P client interfaces, reduced Tx Power is
  385. * irrelevant since it is based on the RSSI coming from the beacon.
  386. * Use BT_KILL_MSK_DEFAULT in that case.
  387. */
  388. data.reduced_tx_power = data.reduced_tx_power && data.num_bss_ifaces;
  389. if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm, data.reduced_tx_power))
  390. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  391. }
  392. /* upon association, the fw will send in BT Coex notification */
  393. int iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm,
  394. struct iwl_rx_cmd_buffer *rxb,
  395. struct iwl_device_cmd *dev_cmd)
  396. {
  397. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  398. struct iwl_bt_coex_profile_notif *notif = (void *)pkt->data;
  399. IWL_DEBUG_COEX(mvm, "BT Coex Notification received\n");
  400. IWL_DEBUG_COEX(mvm, "\tBT %salive\n", notif->bt_status ? "" : "not ");
  401. IWL_DEBUG_COEX(mvm, "\tBT open conn %d\n", notif->bt_open_conn);
  402. IWL_DEBUG_COEX(mvm, "\tBT traffic load %d\n", notif->bt_traffic_load);
  403. IWL_DEBUG_COEX(mvm, "\tBT agg traffic load %d\n",
  404. notif->bt_agg_traffic_load);
  405. IWL_DEBUG_COEX(mvm, "\tBT ci compliance %d\n", notif->bt_ci_compliance);
  406. /* remember this notification for future use: rssi fluctuations */
  407. memcpy(&mvm->last_bt_notif, notif, sizeof(mvm->last_bt_notif));
  408. iwl_mvm_bt_coex_notif_handle(mvm);
  409. /*
  410. * This is an async handler for a notification, returning anything other
  411. * than 0 doesn't make sense even if HCMD failed.
  412. */
  413. return 0;
  414. }
  415. static void iwl_mvm_bt_rssi_iterator(void *_data, u8 *mac,
  416. struct ieee80211_vif *vif)
  417. {
  418. struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv;
  419. struct iwl_bt_iterator_data *data = _data;
  420. struct iwl_mvm *mvm = data->mvm;
  421. struct ieee80211_sta *sta;
  422. struct iwl_mvm_sta *mvmsta;
  423. if (vif->type != NL80211_IFTYPE_STATION ||
  424. mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
  425. return;
  426. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
  427. lockdep_is_held(&mvm->mutex));
  428. mvmsta = (void *)sta->drv_priv;
  429. /*
  430. * This interface doesn't support reduced Tx power (because of low
  431. * RSSI probably), then set bt_kill_msk to default values.
  432. */
  433. if (!mvmsta->bt_reduced_txpower)
  434. data->reduced_tx_power = false;
  435. /* else - possibly leave it to BT_KILL_MSK_REDUCED_TXPOW */
  436. }
  437. void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  438. enum ieee80211_rssi_event rssi_event)
  439. {
  440. struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv;
  441. struct iwl_bt_iterator_data data = {
  442. .mvm = mvm,
  443. .reduced_tx_power = true,
  444. };
  445. int ret;
  446. mutex_lock(&mvm->mutex);
  447. /* Rssi update while not associated ?! */
  448. if (WARN_ON_ONCE(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT))
  449. goto out_unlock;
  450. /* No open connection - reports should be disabled */
  451. if (!BT_MBOX_MSG(&mvm->last_bt_notif, 3, OPEN_CON_2))
  452. goto out_unlock;
  453. IWL_DEBUG_COEX(mvm, "RSSI for %pM is now %s\n", vif->bss_conf.bssid,
  454. rssi_event == RSSI_EVENT_HIGH ? "HIGH" : "LOW");
  455. /*
  456. * Check if rssi is good enough for reduced Tx power, but not in loose
  457. * scheme.
  458. */
  459. if (rssi_event == RSSI_EVENT_LOW || is_loose_coex())
  460. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id,
  461. false);
  462. else
  463. ret = iwl_mvm_bt_coex_reduced_txp(mvm, mvmvif->ap_sta_id, true);
  464. if (ret)
  465. IWL_ERR(mvm, "couldn't send BT_CONFIG HCMD upon RSSI event\n");
  466. ieee80211_iterate_active_interfaces_atomic(
  467. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  468. iwl_mvm_bt_rssi_iterator, &data);
  469. /*
  470. * If there are no BSS / P2P client interfaces, reduced Tx Power is
  471. * irrelevant since it is based on the RSSI coming from the beacon.
  472. * Use BT_KILL_MSK_DEFAULT in that case.
  473. */
  474. data.reduced_tx_power = data.reduced_tx_power && data.num_bss_ifaces;
  475. if (iwl_mvm_bt_udpate_ctrl_kill_msk(mvm, data.reduced_tx_power))
  476. IWL_ERR(mvm, "Failed to update the ctrl_kill_msk\n");
  477. out_unlock:
  478. mutex_unlock(&mvm->mutex);
  479. }
  480. void iwl_mvm_bt_coex_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  481. {
  482. struct ieee80211_chanctx_conf *chanctx_conf;
  483. enum ieee80211_band band;
  484. rcu_read_lock();
  485. chanctx_conf = rcu_dereference(vif->chanctx_conf);
  486. if (chanctx_conf && chanctx_conf->def.chan)
  487. band = chanctx_conf->def.chan->band;
  488. else
  489. band = -1;
  490. rcu_read_unlock();
  491. /* if we are in 2GHz we will get a notification from the fw */
  492. if (band == IEEE80211_BAND_2GHZ)
  493. return;
  494. /* else, we can remove all the constraints */
  495. memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
  496. iwl_mvm_bt_coex_notif_handle(mvm);
  497. }