mci.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * Copyright (c) 2010-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "ath9k.h"
  17. #include "mci.h"
  18. u8 ath_mci_duty_cycle[] = { 0, 50, 60, 70, 80, 85, 90, 95, 98 };
  19. static struct ath_mci_profile_info*
  20. ath_mci_find_profile(struct ath_mci_profile *mci,
  21. struct ath_mci_profile_info *info)
  22. {
  23. struct ath_mci_profile_info *entry;
  24. list_for_each_entry(entry, &mci->info, list) {
  25. if (entry->conn_handle == info->conn_handle)
  26. break;
  27. }
  28. return entry;
  29. }
  30. static bool ath_mci_add_profile(struct ath_common *common,
  31. struct ath_mci_profile *mci,
  32. struct ath_mci_profile_info *info)
  33. {
  34. struct ath_mci_profile_info *entry;
  35. if ((mci->num_sco == ATH_MCI_MAX_SCO_PROFILE) &&
  36. (info->type == MCI_GPM_COEX_PROFILE_VOICE)) {
  37. ath_dbg(common, ATH_DBG_MCI,
  38. "Too many SCO profile, failed to add new profile\n");
  39. return false;
  40. }
  41. if (((NUM_PROF(mci) - mci->num_sco) == ATH_MCI_MAX_ACL_PROFILE) &&
  42. (info->type != MCI_GPM_COEX_PROFILE_VOICE)) {
  43. ath_dbg(common, ATH_DBG_MCI,
  44. "Too many ACL profile, failed to add new profile\n");
  45. return false;
  46. }
  47. entry = ath_mci_find_profile(mci, info);
  48. if (entry)
  49. memcpy(entry, info, 10);
  50. else {
  51. entry = kzalloc(sizeof(*entry), GFP_KERNEL);
  52. if (!entry)
  53. return false;
  54. memcpy(entry, info, 10);
  55. INC_PROF(mci, info);
  56. list_add_tail(&info->list, &mci->info);
  57. }
  58. return true;
  59. }
  60. static void ath_mci_del_profile(struct ath_common *common,
  61. struct ath_mci_profile *mci,
  62. struct ath_mci_profile_info *info)
  63. {
  64. struct ath_mci_profile_info *entry;
  65. entry = ath_mci_find_profile(mci, info);
  66. if (!entry) {
  67. ath_dbg(common, ATH_DBG_MCI,
  68. "Profile to be deleted not found\n");
  69. return;
  70. }
  71. DEC_PROF(mci, entry);
  72. list_del(&entry->list);
  73. kfree(entry);
  74. }
  75. void ath_mci_flush_profile(struct ath_mci_profile *mci)
  76. {
  77. struct ath_mci_profile_info *info, *tinfo;
  78. list_for_each_entry_safe(info, tinfo, &mci->info, list) {
  79. list_del(&info->list);
  80. DEC_PROF(mci, info);
  81. kfree(info);
  82. }
  83. mci->aggr_limit = 0;
  84. }
  85. static void ath_mci_adjust_aggr_limit(struct ath_btcoex *btcoex)
  86. {
  87. struct ath_mci_profile *mci = &btcoex->mci;
  88. u32 wlan_airtime = btcoex->btcoex_period *
  89. (100 - btcoex->duty_cycle) / 100;
  90. /*
  91. * Scale: wlan_airtime is in ms, aggr_limit is in 0.25 ms.
  92. * When wlan_airtime is less than 4ms, aggregation limit has to be
  93. * adjusted half of wlan_airtime to ensure that the aggregation can fit
  94. * without collision with BT traffic.
  95. */
  96. if ((wlan_airtime <= 4) &&
  97. (!mci->aggr_limit || (mci->aggr_limit > (2 * wlan_airtime))))
  98. mci->aggr_limit = 2 * wlan_airtime;
  99. }
  100. static void ath_mci_update_scheme(struct ath_softc *sc)
  101. {
  102. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  103. struct ath_btcoex *btcoex = &sc->btcoex;
  104. struct ath_mci_profile *mci = &btcoex->mci;
  105. struct ath_mci_profile_info *info;
  106. u32 num_profile = NUM_PROF(mci);
  107. if (num_profile == 1) {
  108. info = list_first_entry(&mci->info,
  109. struct ath_mci_profile_info,
  110. list);
  111. if (mci->num_sco && info->T == 12) {
  112. mci->aggr_limit = 8;
  113. ath_dbg(common, ATH_DBG_MCI,
  114. "Single SCO, aggregation limit 2 ms\n");
  115. } else if ((info->type == MCI_GPM_COEX_PROFILE_BNEP) &&
  116. !info->master) {
  117. btcoex->btcoex_period = 60;
  118. ath_dbg(common, ATH_DBG_MCI,
  119. "Single slave PAN/FTP, bt period 60 ms\n");
  120. } else if ((info->type == MCI_GPM_COEX_PROFILE_HID) &&
  121. (info->T > 0 && info->T < 50) &&
  122. (info->A > 1 || info->W > 1)) {
  123. btcoex->duty_cycle = 30;
  124. mci->aggr_limit = 8;
  125. ath_dbg(common, ATH_DBG_MCI,
  126. "Multiple attempt/timeout single HID "
  127. "aggregation limit 2 ms dutycycle 30%%\n");
  128. }
  129. } else if ((num_profile == 2) && (mci->num_hid == 2)) {
  130. btcoex->duty_cycle = 30;
  131. mci->aggr_limit = 8;
  132. ath_dbg(common, ATH_DBG_MCI,
  133. "Two HIDs aggregation limit 2 ms dutycycle 30%%\n");
  134. } else if (num_profile > 3) {
  135. mci->aggr_limit = 6;
  136. ath_dbg(common, ATH_DBG_MCI,
  137. "Three or more profiles aggregation limit 1.5 ms\n");
  138. }
  139. if (IS_CHAN_2GHZ(sc->sc_ah->curchan)) {
  140. if (IS_CHAN_HT(sc->sc_ah->curchan))
  141. ath_mci_adjust_aggr_limit(btcoex);
  142. else
  143. btcoex->btcoex_period >>= 1;
  144. }
  145. ath9k_hw_btcoex_disable(sc->sc_ah);
  146. ath9k_btcoex_timer_pause(sc);
  147. if (IS_CHAN_5GHZ(sc->sc_ah->curchan))
  148. return;
  149. btcoex->duty_cycle += (mci->num_bdr ? ATH_MCI_MAX_DUTY_CYCLE : 0);
  150. if (btcoex->duty_cycle > ATH_MCI_MAX_DUTY_CYCLE)
  151. btcoex->duty_cycle = ATH_MCI_MAX_DUTY_CYCLE;
  152. btcoex->btcoex_period *= 1000;
  153. btcoex->btcoex_no_stomp = btcoex->btcoex_period *
  154. (100 - btcoex->duty_cycle) / 100;
  155. ath9k_hw_btcoex_enable(sc->sc_ah);
  156. ath9k_btcoex_timer_resume(sc);
  157. }
  158. void ath_mci_process_profile(struct ath_softc *sc,
  159. struct ath_mci_profile_info *info)
  160. {
  161. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  162. struct ath_btcoex *btcoex = &sc->btcoex;
  163. struct ath_mci_profile *mci = &btcoex->mci;
  164. if (info->start) {
  165. if (!ath_mci_add_profile(common, mci, info))
  166. return;
  167. } else
  168. ath_mci_del_profile(common, mci, info);
  169. btcoex->btcoex_period = ATH_MCI_DEF_BT_PERIOD;
  170. mci->aggr_limit = mci->num_sco ? 6 : 0;
  171. if (NUM_PROF(mci)) {
  172. btcoex->bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
  173. btcoex->duty_cycle = ath_mci_duty_cycle[NUM_PROF(mci)];
  174. } else {
  175. btcoex->bt_stomp_type = mci->num_mgmt ? ATH_BTCOEX_STOMP_ALL :
  176. ATH_BTCOEX_STOMP_LOW;
  177. btcoex->duty_cycle = ATH_BTCOEX_DEF_DUTY_CYCLE;
  178. }
  179. ath_mci_update_scheme(sc);
  180. }
  181. void ath_mci_process_status(struct ath_softc *sc,
  182. struct ath_mci_profile_status *status)
  183. {
  184. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  185. struct ath_btcoex *btcoex = &sc->btcoex;
  186. struct ath_mci_profile *mci = &btcoex->mci;
  187. struct ath_mci_profile_info info;
  188. int i = 0, old_num_mgmt = mci->num_mgmt;
  189. /* Link status type are not handled */
  190. if (status->is_link) {
  191. ath_dbg(common, ATH_DBG_MCI,
  192. "Skip link type status update\n");
  193. return;
  194. }
  195. memset(&info, 0, sizeof(struct ath_mci_profile_info));
  196. info.conn_handle = status->conn_handle;
  197. if (ath_mci_find_profile(mci, &info)) {
  198. ath_dbg(common, ATH_DBG_MCI,
  199. "Skip non link state update for existing profile %d\n",
  200. status->conn_handle);
  201. return;
  202. }
  203. if (status->conn_handle >= ATH_MCI_MAX_PROFILE) {
  204. ath_dbg(common, ATH_DBG_MCI,
  205. "Ignore too many non-link update\n");
  206. return;
  207. }
  208. if (status->is_critical)
  209. __set_bit(status->conn_handle, mci->status);
  210. else
  211. __clear_bit(status->conn_handle, mci->status);
  212. mci->num_mgmt = 0;
  213. do {
  214. if (test_bit(i, mci->status))
  215. mci->num_mgmt++;
  216. } while (++i < ATH_MCI_MAX_PROFILE);
  217. if (old_num_mgmt != mci->num_mgmt)
  218. ath_mci_update_scheme(sc);
  219. }