bt-coex.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 "fw-api-bt-coex.h"
  64. #include "iwl-modparams.h"
  65. #include "mvm.h"
  66. #define EVENT_PRIO_ANT(_evt, _prio, _shrd_ant) \
  67. [(_evt)] = (((_prio) << BT_COEX_PRIO_TBL_PRIO_POS) | \
  68. ((_shrd_ant) << BT_COEX_PRIO_TBL_SHRD_ANT_POS))
  69. static const u8 iwl_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = {
  70. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_INIT_CALIB1,
  71. BT_COEX_PRIO_TBL_PRIO_BYPASS, 0),
  72. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_INIT_CALIB2,
  73. BT_COEX_PRIO_TBL_PRIO_BYPASS, 1),
  74. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_LOW1,
  75. BT_COEX_PRIO_TBL_PRIO_LOW, 0),
  76. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_LOW2,
  77. BT_COEX_PRIO_TBL_PRIO_LOW, 1),
  78. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_HIGH1,
  79. BT_COEX_PRIO_TBL_PRIO_HIGH, 0),
  80. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_HIGH2,
  81. BT_COEX_PRIO_TBL_PRIO_HIGH, 1),
  82. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_DTIM,
  83. BT_COEX_PRIO_TBL_DISABLED, 0),
  84. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_SCAN52,
  85. BT_COEX_PRIO_TBL_PRIO_COEX_OFF, 0),
  86. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_SCAN24,
  87. BT_COEX_PRIO_TBL_PRIO_COEX_ON, 0),
  88. EVENT_PRIO_ANT(BT_COEX_PRIO_TBL_EVT_IDLE,
  89. BT_COEX_PRIO_TBL_PRIO_COEX_IDLE, 0),
  90. 0, 0, 0, 0, 0, 0,
  91. };
  92. #undef EVENT_PRIO_ANT
  93. int iwl_send_bt_prio_tbl(struct iwl_mvm *mvm)
  94. {
  95. return iwl_mvm_send_cmd_pdu(mvm, BT_COEX_PRIO_TABLE, CMD_SYNC,
  96. sizeof(struct iwl_bt_coex_prio_tbl_cmd),
  97. &iwl_bt_prio_tbl);
  98. }
  99. static int iwl_send_bt_env(struct iwl_mvm *mvm, u8 action, u8 type)
  100. {
  101. struct iwl_bt_coex_prot_env_cmd env_cmd;
  102. int ret;
  103. env_cmd.action = action;
  104. env_cmd.type = type;
  105. ret = iwl_mvm_send_cmd_pdu(mvm, BT_COEX_PROT_ENV, CMD_SYNC,
  106. sizeof(env_cmd), &env_cmd);
  107. if (ret)
  108. IWL_ERR(mvm, "failed to send BT env command\n");
  109. return ret;
  110. }
  111. enum iwl_bt_kill_msk {
  112. BT_KILL_MSK_DEFAULT,
  113. BT_KILL_MSK_SCO_HID_A2DP,
  114. BT_KILL_MSK_REDUCED_TXPOW,
  115. BT_KILL_MSK_MAX,
  116. };
  117. static const u32 iwl_bt_ack_kill_msk[BT_KILL_MSK_MAX] = {
  118. 0xffffffff,
  119. 0xfffffc00,
  120. 0,
  121. };
  122. static const u32 iwl_bt_cts_kill_msk[BT_KILL_MSK_MAX] = {
  123. 0xffffffff,
  124. 0xfffffc00,
  125. 0,
  126. };
  127. #define IWL_BT_DEFAULT_BOOST (0xf0f0f0f0)
  128. /* Tight Coex */
  129. static const __le32 iwl_tight_lookup[BT_COEX_LUT_SIZE] = {
  130. cpu_to_le32(0xaaaaaaaa),
  131. cpu_to_le32(0xaaaaaaaa),
  132. cpu_to_le32(0xaeaaaaaa),
  133. cpu_to_le32(0xaaaaaaaa),
  134. cpu_to_le32(0xcc00ff28),
  135. cpu_to_le32(0x0000aaaa),
  136. cpu_to_le32(0xcc00aaaa),
  137. cpu_to_le32(0x0000aaaa),
  138. cpu_to_le32(0xc0004000),
  139. cpu_to_le32(0x00000000),
  140. cpu_to_le32(0xf0005000),
  141. cpu_to_le32(0xf0005000),
  142. };
  143. /* Loose Coex */
  144. static const __le32 iwl_loose_lookup[BT_COEX_LUT_SIZE] = {
  145. cpu_to_le32(0xaaaaaaaa),
  146. cpu_to_le32(0xaaaaaaaa),
  147. cpu_to_le32(0xaeaaaaaa),
  148. cpu_to_le32(0xaaaaaaaa),
  149. cpu_to_le32(0xcc00ff28),
  150. cpu_to_le32(0x0000aaaa),
  151. cpu_to_le32(0xcc00aaaa),
  152. cpu_to_le32(0x0000aaaa),
  153. cpu_to_le32(0x00000000),
  154. cpu_to_le32(0x00000000),
  155. cpu_to_le32(0xf0005000),
  156. cpu_to_le32(0xf0005000),
  157. };
  158. /* Full concurrency */
  159. static const __le32 iwl_concurrent_lookup[BT_COEX_LUT_SIZE] = {
  160. cpu_to_le32(0xaaaaaaaa),
  161. cpu_to_le32(0xaaaaaaaa),
  162. cpu_to_le32(0xaaaaaaaa),
  163. cpu_to_le32(0xaaaaaaaa),
  164. cpu_to_le32(0xaaaaaaaa),
  165. cpu_to_le32(0xaaaaaaaa),
  166. cpu_to_le32(0xaaaaaaaa),
  167. cpu_to_le32(0xaaaaaaaa),
  168. cpu_to_le32(0x00000000),
  169. cpu_to_le32(0x00000000),
  170. cpu_to_le32(0x00000000),
  171. cpu_to_le32(0x00000000),
  172. };
  173. /* BT Antenna Coupling Threshold (dB) */
  174. #define IWL_BT_ANTENNA_COUPLING_THRESHOLD (35)
  175. int iwl_send_bt_init_conf(struct iwl_mvm *mvm)
  176. {
  177. struct iwl_bt_coex_cmd cmd = {
  178. .max_kill = 5,
  179. .bt3_time_t7_value = 1,
  180. .bt3_prio_sample_time = 2,
  181. .bt3_timer_t2_value = 0xc,
  182. };
  183. int ret;
  184. cmd.flags = iwlwifi_mod_params.bt_coex_active ?
  185. BT_COEX_NW : BT_COEX_DISABLE;
  186. cmd.flags |= iwlwifi_mod_params.bt_ch_announce ?
  187. BT_CH_PRIMARY_EN | BT_CH_SECONDARY_EN : 0;
  188. cmd.flags |= BT_SYNC_2_BT_DISABLE;
  189. cmd.valid_bit_msk = cpu_to_le16(BT_VALID_ENABLE |
  190. BT_VALID_BT_PRIO_BOOST |
  191. BT_VALID_MAX_KILL |
  192. BT_VALID_3W_TMRS |
  193. BT_VALID_KILL_ACK |
  194. BT_VALID_KILL_CTS |
  195. BT_VALID_REDUCED_TX_POWER |
  196. BT_VALID_LUT);
  197. if (iwlwifi_mod_params.ant_coupling > IWL_BT_ANTENNA_COUPLING_THRESHOLD)
  198. memcpy(&cmd.decision_lut, iwl_loose_lookup,
  199. sizeof(iwl_tight_lookup));
  200. else
  201. memcpy(&cmd.decision_lut, iwl_tight_lookup,
  202. sizeof(iwl_tight_lookup));
  203. cmd.bt_prio_boost = cpu_to_le32(IWL_BT_DEFAULT_BOOST);
  204. cmd.kill_ack_msk =
  205. cpu_to_le32(iwl_bt_ack_kill_msk[BT_KILL_MSK_DEFAULT]);
  206. cmd.kill_cts_msk =
  207. cpu_to_le32(iwl_bt_cts_kill_msk[BT_KILL_MSK_DEFAULT]);
  208. /* go to CALIB state in internal BT-Coex state machine */
  209. ret = iwl_send_bt_env(mvm, BT_COEX_ENV_OPEN,
  210. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  211. if (ret)
  212. return ret;
  213. ret = iwl_send_bt_env(mvm, BT_COEX_ENV_CLOSE,
  214. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  215. if (ret)
  216. return ret;
  217. return iwl_mvm_send_cmd_pdu(mvm, BT_CONFIG, CMD_SYNC,
  218. sizeof(cmd), &cmd);
  219. }