blob: 3f7a11edb82a77dedcfdc5f38fa4c6c832e9579e [file] [log] [blame]
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +05301/*
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
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +053017#include <linux/dma-mapping.h>
18#include <linux/slab.h>
19
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053020#include "ath9k.h"
21#include "mci.h"
22
Rajkumar Manoharana197b762012-06-12 10:13:54 +053023static const u8 ath_mci_duty_cycle[] = { 55, 50, 60, 70, 80, 85, 90, 95, 98 };
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053024
25static struct ath_mci_profile_info*
26ath_mci_find_profile(struct ath_mci_profile *mci,
27 struct ath_mci_profile_info *info)
28{
29 struct ath_mci_profile_info *entry;
30
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +053031 if (list_empty(&mci->info))
32 return NULL;
33
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053034 list_for_each_entry(entry, &mci->info, list) {
35 if (entry->conn_handle == info->conn_handle)
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +053036 return entry;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053037 }
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +053038 return NULL;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053039}
40
41static bool ath_mci_add_profile(struct ath_common *common,
42 struct ath_mci_profile *mci,
43 struct ath_mci_profile_info *info)
44{
45 struct ath_mci_profile_info *entry;
Rajkumar Manoharandb604282012-10-12 14:07:23 +053046 u8 voice_priority[] = { 110, 110, 110, 112, 110, 110, 114, 116, 118 };
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053047
48 if ((mci->num_sco == ATH_MCI_MAX_SCO_PROFILE) &&
Sujith Manoharan682dd042012-02-22 14:43:52 +053049 (info->type == MCI_GPM_COEX_PROFILE_VOICE))
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053050 return false;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053051
52 if (((NUM_PROF(mci) - mci->num_sco) == ATH_MCI_MAX_ACL_PROFILE) &&
Sujith Manoharan682dd042012-02-22 14:43:52 +053053 (info->type != MCI_GPM_COEX_PROFILE_VOICE))
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053054 return false;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053055
Rajkumar Manoharan3c7992e2012-06-12 10:13:53 +053056 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +053057 if (!entry)
58 return false;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053059
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +053060 memcpy(entry, info, 10);
61 INC_PROF(mci, info);
62 list_add_tail(&entry->list, &mci->info);
Rajkumar Manoharandb604282012-10-12 14:07:23 +053063 if (info->type == MCI_GPM_COEX_PROFILE_VOICE) {
64 if (info->voice_type < sizeof(voice_priority))
65 mci->voice_priority = voice_priority[info->voice_type];
66 else
67 mci->voice_priority = 110;
68 }
Sujith Manoharan682dd042012-02-22 14:43:52 +053069
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053070 return true;
71}
72
73static void ath_mci_del_profile(struct ath_common *common,
74 struct ath_mci_profile *mci,
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +053075 struct ath_mci_profile_info *entry)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053076{
Sujith Manoharan682dd042012-02-22 14:43:52 +053077 if (!entry)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053078 return;
Sujith Manoharan682dd042012-02-22 14:43:52 +053079
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053080 DEC_PROF(mci, entry);
81 list_del(&entry->list);
82 kfree(entry);
83}
84
85void ath_mci_flush_profile(struct ath_mci_profile *mci)
86{
87 struct ath_mci_profile_info *info, *tinfo;
88
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +053089 mci->aggr_limit = 0;
Rajkumar Manoharand92bb982012-09-12 18:59:21 +053090 mci->num_mgmt = 0;
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +053091
92 if (list_empty(&mci->info))
93 return;
94
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053095 list_for_each_entry_safe(info, tinfo, &mci->info, list) {
96 list_del(&info->list);
97 DEC_PROF(mci, info);
98 kfree(info);
99 }
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530100}
101
102static void ath_mci_adjust_aggr_limit(struct ath_btcoex *btcoex)
103{
104 struct ath_mci_profile *mci = &btcoex->mci;
105 u32 wlan_airtime = btcoex->btcoex_period *
106 (100 - btcoex->duty_cycle) / 100;
107
108 /*
109 * Scale: wlan_airtime is in ms, aggr_limit is in 0.25 ms.
110 * When wlan_airtime is less than 4ms, aggregation limit has to be
111 * adjusted half of wlan_airtime to ensure that the aggregation can fit
112 * without collision with BT traffic.
113 */
114 if ((wlan_airtime <= 4) &&
115 (!mci->aggr_limit || (mci->aggr_limit > (2 * wlan_airtime))))
116 mci->aggr_limit = 2 * wlan_airtime;
117}
118
119static void ath_mci_update_scheme(struct ath_softc *sc)
120{
121 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
122 struct ath_btcoex *btcoex = &sc->btcoex;
123 struct ath_mci_profile *mci = &btcoex->mci;
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530124 struct ath9k_hw_mci *mci_hw = &sc->sc_ah->btcoex_hw.mci;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530125 struct ath_mci_profile_info *info;
126 u32 num_profile = NUM_PROF(mci);
127
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530128 if (mci_hw->config & ATH_MCI_CONFIG_DISABLE_TUNING)
129 goto skip_tuning;
130
Rajkumar Manoharan9e628172012-09-12 18:59:22 +0530131 mci->aggr_limit = 0;
Rajkumar Manoharana197b762012-06-12 10:13:54 +0530132 btcoex->duty_cycle = ath_mci_duty_cycle[num_profile];
Rajkumar Manoharan9e628172012-09-12 18:59:22 +0530133 btcoex->btcoex_period = ATH_MCI_DEF_BT_PERIOD;
134 if (NUM_PROF(mci))
135 btcoex->bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
136 else
137 btcoex->bt_stomp_type = mci->num_mgmt ? ATH_BTCOEX_STOMP_ALL :
138 ATH_BTCOEX_STOMP_LOW;
Rajkumar Manoharana197b762012-06-12 10:13:54 +0530139
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530140 if (num_profile == 1) {
141 info = list_first_entry(&mci->info,
142 struct ath_mci_profile_info,
143 list);
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530144 if (mci->num_sco) {
145 if (info->T == 12)
146 mci->aggr_limit = 8;
147 else if (info->T == 6) {
148 mci->aggr_limit = 6;
149 btcoex->duty_cycle = 30;
Rajkumar Manoharan9e628172012-09-12 18:59:22 +0530150 } else
151 mci->aggr_limit = 6;
Joe Perchesd2182b62011-12-15 14:55:53 -0800152 ath_dbg(common, MCI,
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530153 "Single SCO, aggregation limit %d 1/4 ms\n",
154 mci->aggr_limit);
155 } else if (mci->num_pan || mci->num_other_acl) {
156 /*
157 * For single PAN/FTP profile, allocate 35% for BT
158 * to improve WLAN throughput.
159 */
Rajkumar Manoharanf9401b12012-10-15 15:29:54 +0530160 btcoex->duty_cycle = AR_SREV_9565(sc->sc_ah) ? 40 : 35;
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530161 btcoex->btcoex_period = 53;
Joe Perchesd2182b62011-12-15 14:55:53 -0800162 ath_dbg(common, MCI,
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530163 "Single PAN/FTP bt period %d ms dutycycle %d\n",
164 btcoex->duty_cycle, btcoex->btcoex_period);
165 } else if (mci->num_hid) {
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530166 btcoex->duty_cycle = 30;
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530167 mci->aggr_limit = 6;
Joe Perchesd2182b62011-12-15 14:55:53 -0800168 ath_dbg(common, MCI,
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530169 "Multiple attempt/timeout single HID "
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530170 "aggregation limit 1.5 ms dutycycle 30%%\n");
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530171 }
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530172 } else if (num_profile == 2) {
173 if (mci->num_hid == 2)
174 btcoex->duty_cycle = 30;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530175 mci->aggr_limit = 6;
Joe Perchesd2182b62011-12-15 14:55:53 -0800176 ath_dbg(common, MCI,
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530177 "Two BT profiles aggr limit 1.5 ms dutycycle %d%%\n",
178 btcoex->duty_cycle);
179 } else if (num_profile >= 3) {
180 mci->aggr_limit = 4;
181 ath_dbg(common, MCI,
182 "Three or more profiles aggregation limit 1 ms\n");
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530183 }
184
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530185skip_tuning:
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530186 if (IS_CHAN_2GHZ(sc->sc_ah->curchan)) {
187 if (IS_CHAN_HT(sc->sc_ah->curchan))
188 ath_mci_adjust_aggr_limit(btcoex);
189 else
190 btcoex->btcoex_period >>= 1;
191 }
192
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530193 ath9k_btcoex_timer_pause(sc);
Mohammed Shafi Shajakhanc32cdbd2012-07-06 20:09:32 +0530194 ath9k_hw_btcoex_disable(sc->sc_ah);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530195
196 if (IS_CHAN_5GHZ(sc->sc_ah->curchan))
197 return;
198
Rajkumar Manoharana197b762012-06-12 10:13:54 +0530199 btcoex->duty_cycle += (mci->num_bdr ? ATH_MCI_BDR_DUTY_CYCLE : 0);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530200 if (btcoex->duty_cycle > ATH_MCI_MAX_DUTY_CYCLE)
201 btcoex->duty_cycle = ATH_MCI_MAX_DUTY_CYCLE;
202
Felix Fietkau168c6f82013-12-14 18:03:37 +0100203 btcoex->btcoex_no_stomp = btcoex->btcoex_period *
Sujith Manoharan682dd042012-02-22 14:43:52 +0530204 (100 - btcoex->duty_cycle) / 100;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530205
206 ath9k_hw_btcoex_enable(sc->sc_ah);
207 ath9k_btcoex_timer_resume(sc);
208}
209
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530210static void ath_mci_cal_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload)
211{
212 struct ath_hw *ah = sc->sc_ah;
213 struct ath_common *common = ath9k_hw_common(ah);
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530214 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530215 u32 payload[4] = {0, 0, 0, 0};
216
217 switch (opcode) {
218 case MCI_GPM_BT_CAL_REQ:
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530219 if (mci_hw->bt_state == MCI_BT_AWAKE) {
Mohammed Shafi Shajakhan46533562012-08-24 16:27:06 +0530220 mci_hw->bt_state = MCI_BT_CAL_START;
Rajkumar Manoharanb88083b2012-11-20 18:30:00 +0530221 ath9k_queue_reset(sc, RESET_TYPE_MCI);
Sujith Manoharan682dd042012-02-22 14:43:52 +0530222 }
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530223 ath_dbg(common, MCI, "MCI State : %d\n", mci_hw->bt_state);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530224 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530225 case MCI_GPM_BT_CAL_GRANT:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530226 MCI_GPM_SET_CAL_TYPE(payload, MCI_GPM_WLAN_CAL_DONE);
227 ar9003_mci_send_message(sc->sc_ah, MCI_GPM, 0, payload,
228 16, false, true);
229 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530230 default:
Sujith Manoharan682dd042012-02-22 14:43:52 +0530231 ath_dbg(common, MCI, "Unknown GPM CAL message\n");
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530232 break;
233 }
234}
235
Rajkumar Manoharan3c7992e2012-06-12 10:13:53 +0530236static void ath9k_mci_work(struct work_struct *work)
237{
238 struct ath_softc *sc = container_of(work, struct ath_softc, mci_work);
239
240 ath_mci_update_scheme(sc);
241}
242
Rajkumar Manoharandb604282012-10-12 14:07:23 +0530243static void ath_mci_update_stomp_txprio(u8 cur_txprio, u8 *stomp_prio)
244{
245 if (cur_txprio < stomp_prio[ATH_BTCOEX_STOMP_NONE])
246 stomp_prio[ATH_BTCOEX_STOMP_NONE] = cur_txprio;
247
248 if (cur_txprio > stomp_prio[ATH_BTCOEX_STOMP_ALL])
249 stomp_prio[ATH_BTCOEX_STOMP_ALL] = cur_txprio;
250
251 if ((cur_txprio > ATH_MCI_HI_PRIO) &&
252 (cur_txprio < stomp_prio[ATH_BTCOEX_STOMP_LOW]))
253 stomp_prio[ATH_BTCOEX_STOMP_LOW] = cur_txprio;
254}
255
256static void ath_mci_set_concur_txprio(struct ath_softc *sc)
257{
258 struct ath_btcoex *btcoex = &sc->btcoex;
259 struct ath_mci_profile *mci = &btcoex->mci;
Rajkumar Manoharand6144d82012-11-27 13:51:32 +0530260 u8 stomp_txprio[ATH_BTCOEX_STOMP_MAX];
Rajkumar Manoharandb604282012-10-12 14:07:23 +0530261
Rajkumar Manoharand6144d82012-11-27 13:51:32 +0530262 memset(stomp_txprio, 0, sizeof(stomp_txprio));
Rajkumar Manoharandb604282012-10-12 14:07:23 +0530263 if (mci->num_mgmt) {
264 stomp_txprio[ATH_BTCOEX_STOMP_ALL] = ATH_MCI_INQUIRY_PRIO;
265 if (!mci->num_pan && !mci->num_other_acl)
266 stomp_txprio[ATH_BTCOEX_STOMP_NONE] =
267 ATH_MCI_INQUIRY_PRIO;
268 } else {
269 u8 prof_prio[] = { 50, 90, 94, 52 };/* RFCOMM, A2DP, HID, PAN */
270
271 stomp_txprio[ATH_BTCOEX_STOMP_LOW] =
272 stomp_txprio[ATH_BTCOEX_STOMP_NONE] = 0xff;
273
274 if (mci->num_sco)
275 ath_mci_update_stomp_txprio(mci->voice_priority,
276 stomp_txprio);
277 if (mci->num_other_acl)
278 ath_mci_update_stomp_txprio(prof_prio[0], stomp_txprio);
279 if (mci->num_a2dp)
280 ath_mci_update_stomp_txprio(prof_prio[1], stomp_txprio);
281 if (mci->num_hid)
282 ath_mci_update_stomp_txprio(prof_prio[2], stomp_txprio);
283 if (mci->num_pan)
284 ath_mci_update_stomp_txprio(prof_prio[3], stomp_txprio);
285
286 if (stomp_txprio[ATH_BTCOEX_STOMP_NONE] == 0xff)
287 stomp_txprio[ATH_BTCOEX_STOMP_NONE] = 0;
288
289 if (stomp_txprio[ATH_BTCOEX_STOMP_LOW] == 0xff)
290 stomp_txprio[ATH_BTCOEX_STOMP_LOW] = 0;
291 }
292 ath9k_hw_btcoex_set_concur_txprio(sc->sc_ah, stomp_txprio);
293}
294
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530295static u8 ath_mci_process_profile(struct ath_softc *sc,
296 struct ath_mci_profile_info *info)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530297{
298 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
299 struct ath_btcoex *btcoex = &sc->btcoex;
300 struct ath_mci_profile *mci = &btcoex->mci;
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +0530301 struct ath_mci_profile_info *entry = NULL;
302
303 entry = ath_mci_find_profile(mci, info);
Bala Shanmugam305dd09f2012-06-18 11:36:58 +0530304 if (entry) {
305 /*
306 * Two MCI interrupts are generated while connecting to
307 * headset and A2DP profile, but only one MCI interrupt
308 * is generated with last added profile type while disconnecting
309 * both profiles.
310 * So while adding second profile type decrement
311 * the first one.
312 */
313 if (entry->type != info->type) {
314 DEC_PROF(mci, entry);
315 INC_PROF(mci, info);
316 }
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +0530317 memcpy(entry, info, 10);
Bala Shanmugam305dd09f2012-06-18 11:36:58 +0530318 }
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530319
320 if (info->start) {
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +0530321 if (!entry && !ath_mci_add_profile(common, mci, info))
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530322 return 0;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530323 } else
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +0530324 ath_mci_del_profile(common, mci, entry);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530325
Rajkumar Manoharandb604282012-10-12 14:07:23 +0530326 ath_mci_set_concur_txprio(sc);
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530327 return 1;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530328}
329
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530330static u8 ath_mci_process_status(struct ath_softc *sc,
331 struct ath_mci_profile_status *status)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530332{
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530333 struct ath_btcoex *btcoex = &sc->btcoex;
334 struct ath_mci_profile *mci = &btcoex->mci;
335 struct ath_mci_profile_info info;
336 int i = 0, old_num_mgmt = mci->num_mgmt;
337
338 /* Link status type are not handled */
Sujith Manoharan682dd042012-02-22 14:43:52 +0530339 if (status->is_link)
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530340 return 0;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530341
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530342 info.conn_handle = status->conn_handle;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530343 if (ath_mci_find_profile(mci, &info))
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530344 return 0;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530345
346 if (status->conn_handle >= ATH_MCI_MAX_PROFILE)
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530347 return 0;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530348
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530349 if (status->is_critical)
350 __set_bit(status->conn_handle, mci->status);
351 else
352 __clear_bit(status->conn_handle, mci->status);
353
354 mci->num_mgmt = 0;
355 do {
356 if (test_bit(i, mci->status))
357 mci->num_mgmt++;
358 } while (++i < ATH_MCI_MAX_PROFILE);
359
Rajkumar Manoharandb604282012-10-12 14:07:23 +0530360 ath_mci_set_concur_txprio(sc);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530361 if (old_num_mgmt != mci->num_mgmt)
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530362 return 1;
363
364 return 0;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530365}
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530366
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530367static void ath_mci_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload)
368{
369 struct ath_hw *ah = sc->sc_ah;
370 struct ath_mci_profile_info profile_info;
371 struct ath_mci_profile_status profile_status;
372 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530373 u8 major, minor, update_scheme = 0;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530374 u32 seq_num;
375
Rajkumar Manoharand92bb982012-09-12 18:59:21 +0530376 if (ar9003_mci_state(ah, MCI_STATE_NEED_FLUSH_BT_INFO) &&
377 ar9003_mci_state(ah, MCI_STATE_ENABLE)) {
378 ath_dbg(common, MCI, "(MCI) Need to flush BT profiles\n");
379 ath_mci_flush_profile(&sc->btcoex.mci);
380 ar9003_mci_state(ah, MCI_STATE_SEND_STATUS_QUERY);
381 }
382
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530383 switch (opcode) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530384 case MCI_GPM_COEX_VERSION_QUERY:
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530385 ar9003_mci_state(ah, MCI_STATE_SEND_WLAN_COEX_VERSION);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530386 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530387 case MCI_GPM_COEX_VERSION_RESPONSE:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530388 major = *(rx_payload + MCI_GPM_COEX_B_MAJOR_VERSION);
389 minor = *(rx_payload + MCI_GPM_COEX_B_MINOR_VERSION);
Rajkumar Manoharane1763d32012-06-12 20:18:17 +0530390 ar9003_mci_set_bt_version(ah, major, minor);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530391 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530392 case MCI_GPM_COEX_STATUS_QUERY:
Rajkumar Manoharan2d340ac2012-06-12 20:18:18 +0530393 ar9003_mci_send_wlan_channels(ah);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530394 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530395 case MCI_GPM_COEX_BT_PROFILE_INFO:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530396 memcpy(&profile_info,
397 (rx_payload + MCI_GPM_COEX_B_PROFILE_TYPE), 10);
398
Sujith Manoharan682dd042012-02-22 14:43:52 +0530399 if ((profile_info.type == MCI_GPM_COEX_PROFILE_UNKNOWN) ||
400 (profile_info.type >= MCI_GPM_COEX_PROFILE_MAX)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800401 ath_dbg(common, MCI,
Sujith Manoharan682dd042012-02-22 14:43:52 +0530402 "Illegal profile type = %d, state = %d\n",
Joe Perchesd2182b62011-12-15 14:55:53 -0800403 profile_info.type,
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530404 profile_info.start);
405 break;
406 }
407
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530408 update_scheme += ath_mci_process_profile(sc, &profile_info);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530409 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530410 case MCI_GPM_COEX_BT_STATUS_UPDATE:
411 profile_status.is_link = *(rx_payload +
412 MCI_GPM_COEX_B_STATUS_TYPE);
413 profile_status.conn_handle = *(rx_payload +
414 MCI_GPM_COEX_B_STATUS_LINKID);
415 profile_status.is_critical = *(rx_payload +
416 MCI_GPM_COEX_B_STATUS_STATE);
417
418 seq_num = *((u32 *)(rx_payload + 12));
Joe Perchesd2182b62011-12-15 14:55:53 -0800419 ath_dbg(common, MCI,
Mohammed Shafi Shajakhand8fffb42012-06-27 20:00:27 +0530420 "BT_Status_Update: is_link=%d, linkId=%d, state=%d, SEQ=%u\n",
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530421 profile_status.is_link, profile_status.conn_handle,
422 profile_status.is_critical, seq_num);
423
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530424 update_scheme += ath_mci_process_status(sc, &profile_status);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530425 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530426 default:
Sujith Manoharan682dd042012-02-22 14:43:52 +0530427 ath_dbg(common, MCI, "Unknown GPM COEX message = 0x%02x\n", opcode);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530428 break;
429 }
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530430 if (update_scheme)
431 ieee80211_queue_work(sc->hw, &sc->mci_work);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530432}
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530433
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530434int ath_mci_setup(struct ath_softc *sc)
435{
436 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
437 struct ath_mci_coex *mci = &sc->mci_coex;
Sujith Manoharanea510e42012-02-22 12:40:09 +0530438 struct ath_mci_buf *buf = &mci->sched_buf;
Sujith Manoharan69c6ac62012-09-26 07:54:43 +0530439 int ret;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530440
Felix Fietkaub81950b12012-12-12 13:14:22 +0100441 buf->bf_addr = dmam_alloc_coherent(sc->dev,
Sujith Manoharanea510e42012-02-22 12:40:09 +0530442 ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE,
443 &buf->bf_paddr, GFP_KERNEL);
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530444
Sujith Manoharanea510e42012-02-22 12:40:09 +0530445 if (buf->bf_addr == NULL) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800446 ath_dbg(common, FATAL, "MCI buffer alloc failed\n");
Sujith Manoharanea510e42012-02-22 12:40:09 +0530447 return -ENOMEM;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530448 }
449
Sujith Manoharanea510e42012-02-22 12:40:09 +0530450 memset(buf->bf_addr, MCI_GPM_RSVD_PATTERN,
451 ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE);
452
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530453 mci->sched_buf.bf_len = ATH_MCI_SCHED_BUF_SIZE;
454
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530455 mci->gpm_buf.bf_len = ATH_MCI_GPM_BUF_SIZE;
Sujith Manoharanea510e42012-02-22 12:40:09 +0530456 mci->gpm_buf.bf_addr = (u8 *)mci->sched_buf.bf_addr + mci->sched_buf.bf_len;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530457 mci->gpm_buf.bf_paddr = mci->sched_buf.bf_paddr + mci->sched_buf.bf_len;
458
Sujith Manoharan69c6ac62012-09-26 07:54:43 +0530459 ret = ar9003_mci_setup(sc->sc_ah, mci->gpm_buf.bf_paddr,
460 mci->gpm_buf.bf_addr, (mci->gpm_buf.bf_len >> 4),
461 mci->sched_buf.bf_paddr);
462 if (ret) {
463 ath_err(common, "Failed to initialize MCI\n");
464 return ret;
465 }
Sujith Manoharanea510e42012-02-22 12:40:09 +0530466
Rajkumar Manoharan3c7992e2012-06-12 10:13:53 +0530467 INIT_WORK(&sc->mci_work, ath9k_mci_work);
Sujith Manoharanea510e42012-02-22 12:40:09 +0530468 ath_dbg(common, MCI, "MCI Initialized\n");
469
470 return 0;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530471}
472
473void ath_mci_cleanup(struct ath_softc *sc)
474{
Sujith Manoharanea510e42012-02-22 12:40:09 +0530475 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530476 struct ath_hw *ah = sc->sc_ah;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530477
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530478 ar9003_mci_cleanup(ah);
Sujith Manoharanea510e42012-02-22 12:40:09 +0530479
480 ath_dbg(common, MCI, "MCI De-Initialized\n");
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530481}
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530482
483void ath_mci_intr(struct ath_softc *sc)
484{
485 struct ath_mci_coex *mci = &sc->mci_coex;
486 struct ath_hw *ah = sc->sc_ah;
487 struct ath_common *common = ath9k_hw_common(ah);
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530488 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530489 u32 mci_int, mci_int_rxmsg;
490 u32 offset, subtype, opcode;
491 u32 *pgpm;
492 u32 more_data = MCI_GPM_MORE;
493 bool skip_gpm = false;
494
495 ar9003_mci_get_interrupt(sc->sc_ah, &mci_int, &mci_int_rxmsg);
496
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530497 if (ar9003_mci_state(ah, MCI_STATE_ENABLE) == 0) {
Rajkumar Manoharan506847a2012-06-12 20:18:16 +0530498 ar9003_mci_get_next_gpm_offset(ah, true, NULL);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530499 return;
500 }
501
502 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE) {
503 u32 payload[4] = { 0xffffffff, 0xffffffff,
504 0xffffffff, 0xffffff00};
505
506 /*
507 * The following REMOTE_RESET and SYS_WAKING used to sent
508 * only when BT wake up. Now they are always sent, as a
509 * recovery method to reset BT MCI's RX alignment.
510 */
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530511 ar9003_mci_send_message(ah, MCI_REMOTE_RESET, 0,
512 payload, 16, true, false);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530513 ar9003_mci_send_message(ah, MCI_SYS_WAKING, 0,
514 NULL, 0, true, false);
515
516 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE;
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530517 ar9003_mci_state(ah, MCI_STATE_RESET_REQ_WAKE);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530518
519 /*
520 * always do this for recovery and 2G/5G toggling and LNA_TRANS
521 */
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530522 ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530523 }
524
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530525 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING) {
526 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING;
527
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530528 if ((mci_hw->bt_state == MCI_BT_SLEEP) &&
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530529 (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP) !=
530 MCI_BT_SLEEP))
531 ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530532 }
533
534 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530535 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING;
536
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530537 if ((mci_hw->bt_state == MCI_BT_AWAKE) &&
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530538 (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP) !=
539 MCI_BT_AWAKE))
Rajkumar Manoharan93309692012-06-12 20:18:23 +0530540 mci_hw->bt_state = MCI_BT_SLEEP;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530541 }
542
543 if ((mci_int & AR_MCI_INTERRUPT_RX_INVALID_HDR) ||
544 (mci_int & AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT)) {
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530545 ar9003_mci_state(ah, MCI_STATE_RECOVER_RX);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530546 skip_gpm = true;
547 }
548
549 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530550 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO;
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530551 offset = ar9003_mci_state(ah, MCI_STATE_LAST_SCHD_MSG_OFFSET);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530552 }
553
554 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_GPM) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530555 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_GPM;
556
557 while (more_data == MCI_GPM_MORE) {
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100558 if (test_bit(ATH_OP_HW_RESET, &common->op_flags))
Rajkumar Manoharanb88083b2012-11-20 18:30:00 +0530559 return;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530560
561 pgpm = mci->gpm_buf.bf_addr;
Rajkumar Manoharan506847a2012-06-12 20:18:16 +0530562 offset = ar9003_mci_get_next_gpm_offset(ah, false,
563 &more_data);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530564
565 if (offset == MCI_GPM_INVALID)
566 break;
567
568 pgpm += (offset >> 2);
569
570 /*
571 * The first dword is timer.
572 * The real data starts from 2nd dword.
573 */
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530574 subtype = MCI_GPM_TYPE(pgpm);
575 opcode = MCI_GPM_OPCODE(pgpm);
576
Sujith Manoharan682dd042012-02-22 14:43:52 +0530577 if (skip_gpm)
578 goto recycle;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530579
Sujith Manoharan682dd042012-02-22 14:43:52 +0530580 if (MCI_GPM_IS_CAL_TYPE(subtype)) {
581 ath_mci_cal_msg(sc, subtype, (u8 *)pgpm);
582 } else {
583 switch (subtype) {
584 case MCI_GPM_COEX_AGENT:
585 ath_mci_msg(sc, opcode, (u8 *)pgpm);
586 break;
587 default:
588 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530589 }
590 }
Sujith Manoharan682dd042012-02-22 14:43:52 +0530591 recycle:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530592 MCI_GPM_RECYCLE(pgpm);
593 }
594 }
595
596 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_HW_MSG_MASK) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530597 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_LNA_CONTROL)
598 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_LNA_CONTROL;
599
Sujith Manoharan682dd042012-02-22 14:43:52 +0530600 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_LNA_INFO)
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530601 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_LNA_INFO;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530602
603 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_INFO) {
Rajkumar Manoharan26e942b2012-06-12 20:18:22 +0530604 int value_dbm = MS(mci_hw->cont_status,
605 AR_MCI_CONT_RSSI_POWER);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530606
607 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_INFO;
608
Rajkumar Manoharan26e942b2012-06-12 20:18:22 +0530609 ath_dbg(common, MCI,
610 "MCI CONT_INFO: (%s) pri = %d pwr = %d dBm\n",
611 MS(mci_hw->cont_status, AR_MCI_CONT_TXRX) ?
612 "tx" : "rx",
613 MS(mci_hw->cont_status, AR_MCI_CONT_PRIORITY),
614 value_dbm);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530615 }
616
Sujith Manoharan682dd042012-02-22 14:43:52 +0530617 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_NACK)
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530618 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_NACK;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530619
Sujith Manoharan682dd042012-02-22 14:43:52 +0530620 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_RST)
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530621 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_RST;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530622 }
623
624 if ((mci_int & AR_MCI_INTERRUPT_RX_INVALID_HDR) ||
Rajkumar Manoharand92bb982012-09-12 18:59:21 +0530625 (mci_int & AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT)) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530626 mci_int &= ~(AR_MCI_INTERRUPT_RX_INVALID_HDR |
627 AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT);
Rajkumar Manoharand92bb982012-09-12 18:59:21 +0530628 ath_mci_msg(sc, MCI_GPM_COEX_NOOP, NULL);
629 }
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530630}
Sujith Manoharane270e772012-06-04 16:27:19 +0530631
632void ath_mci_enable(struct ath_softc *sc)
633{
634 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
635
636 if (!common->btcoex_enabled)
637 return;
638
639 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
640 sc->sc_ah->imask |= ATH9K_INT_MCI;
641}
Rajkumar Manoharan50072eb2012-10-12 14:07:22 +0530642
643void ath9k_mci_update_wlan_channels(struct ath_softc *sc, bool allow_all)
644{
645 struct ath_hw *ah = sc->sc_ah;
646 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
647 struct ath9k_channel *chan = ah->curchan;
648 u32 channelmap[] = {0x00000000, 0xffff0000, 0xffffffff, 0x7fffffff};
649 int i;
650 s16 chan_start, chan_end;
651 u16 wlan_chan;
652
653 if (!chan || !IS_CHAN_2GHZ(chan))
654 return;
655
656 if (allow_all)
657 goto send_wlan_chan;
658
659 wlan_chan = chan->channel - 2402;
660
661 chan_start = wlan_chan - 10;
662 chan_end = wlan_chan + 10;
663
Felix Fietkau88969342013-10-11 23:30:53 +0200664 if (IS_CHAN_HT40PLUS(chan))
Rajkumar Manoharan50072eb2012-10-12 14:07:22 +0530665 chan_end += 20;
Felix Fietkau88969342013-10-11 23:30:53 +0200666 else if (IS_CHAN_HT40MINUS(chan))
Rajkumar Manoharan50072eb2012-10-12 14:07:22 +0530667 chan_start -= 20;
668
669 /* adjust side band */
670 chan_start -= 7;
671 chan_end += 7;
672
673 if (chan_start <= 0)
674 chan_start = 0;
675 if (chan_end >= ATH_MCI_NUM_BT_CHANNELS)
676 chan_end = ATH_MCI_NUM_BT_CHANNELS - 1;
677
678 ath_dbg(ath9k_hw_common(ah), MCI,
679 "WLAN current channel %d mask BT channel %d - %d\n",
680 wlan_chan, chan_start, chan_end);
681
682 for (i = chan_start; i < chan_end; i++)
683 MCI_GPM_CLR_CHANNEL_BIT(&channelmap, i);
684
685send_wlan_chan:
686 /* update and send wlan channels info to BT */
687 for (i = 0; i < 4; i++)
688 mci->wlan_channels[i] = channelmap[i];
689 ar9003_mci_send_wlan_channels(ah);
690 ar9003_mci_state(ah, MCI_STATE_SEND_VERSION_QUERY);
691}
Rajkumar Manoharane82cb032012-10-12 14:07:25 +0530692
693void ath9k_mci_set_txpower(struct ath_softc *sc, bool setchannel,
694 bool concur_tx)
695{
696 struct ath_hw *ah = sc->sc_ah;
697 struct ath9k_hw_mci *mci_hw = &sc->sc_ah->btcoex_hw.mci;
698 bool old_concur_tx = mci_hw->concur_tx;
699
700 if (!(mci_hw->config & ATH_MCI_CONFIG_CONCUR_TX)) {
701 mci_hw->concur_tx = false;
702 return;
703 }
704
705 if (!IS_CHAN_2GHZ(ah->curchan))
706 return;
707
708 if (setchannel) {
Felix Fietkaub01459e2014-06-11 16:17:59 +0530709 struct ath9k_hw_cal_data *caldata = &sc->cur_chan->caldata;
Felix Fietkau88969342013-10-11 23:30:53 +0200710 if (IS_CHAN_HT40PLUS(ah->curchan) &&
Rajkumar Manoharane82cb032012-10-12 14:07:25 +0530711 (ah->curchan->channel > caldata->channel) &&
712 (ah->curchan->channel <= caldata->channel + 20))
713 return;
Felix Fietkau88969342013-10-11 23:30:53 +0200714 if (IS_CHAN_HT40MINUS(ah->curchan) &&
Rajkumar Manoharane82cb032012-10-12 14:07:25 +0530715 (ah->curchan->channel < caldata->channel) &&
716 (ah->curchan->channel >= caldata->channel - 20))
717 return;
718 mci_hw->concur_tx = false;
719 } else
720 mci_hw->concur_tx = concur_tx;
721
722 if (old_concur_tx != mci_hw->concur_tx)
Felix Fietkaubc7e1be2014-06-11 16:17:50 +0530723 ath9k_hw_set_txpowerlimit(ah, sc->cur_chan->txpower, false);
Rajkumar Manoharane82cb032012-10-12 14:07:25 +0530724}
725
Rajkumar Manoharan28845612012-11-20 18:30:01 +0530726static void ath9k_mci_stomp_audio(struct ath_softc *sc)
727{
728 struct ath_hw *ah = sc->sc_ah;
729 struct ath_btcoex *btcoex = &sc->btcoex;
730 struct ath_mci_profile *mci = &btcoex->mci;
731
732 if (!mci->num_sco && !mci->num_a2dp)
733 return;
734
735 if (ah->stats.avgbrssi > 25) {
736 btcoex->stomp_audio = 0;
737 return;
738 }
739
740 btcoex->stomp_audio++;
741}
Rajkumar Manoharane82cb032012-10-12 14:07:25 +0530742void ath9k_mci_update_rssi(struct ath_softc *sc)
743{
744 struct ath_hw *ah = sc->sc_ah;
745 struct ath_btcoex *btcoex = &sc->btcoex;
746 struct ath9k_hw_mci *mci_hw = &sc->sc_ah->btcoex_hw.mci;
747
Rajkumar Manoharan28845612012-11-20 18:30:01 +0530748 ath9k_mci_stomp_audio(sc);
749
Rajkumar Manoharane82cb032012-10-12 14:07:25 +0530750 if (!(mci_hw->config & ATH_MCI_CONFIG_CONCUR_TX))
751 return;
752
753 if (ah->stats.avgbrssi >= 40) {
754 if (btcoex->rssi_count < 0)
755 btcoex->rssi_count = 0;
756 if (++btcoex->rssi_count >= ATH_MCI_CONCUR_TX_SWITCH) {
757 btcoex->rssi_count = 0;
758 ath9k_mci_set_txpower(sc, false, true);
759 }
760 } else {
761 if (btcoex->rssi_count > 0)
762 btcoex->rssi_count = 0;
763 if (--btcoex->rssi_count <= -ATH_MCI_CONCUR_TX_SWITCH) {
764 btcoex->rssi_count = 0;
765 ath9k_mci_set_txpower(sc, false, false);
766 }
767 }
768}