blob: 1733a5ac3279d6d152a1f1a575a316af0ca72ada [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;
46
47 if ((mci->num_sco == ATH_MCI_MAX_SCO_PROFILE) &&
Sujith Manoharan682dd042012-02-22 14:43:52 +053048 (info->type == MCI_GPM_COEX_PROFILE_VOICE))
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053049 return false;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053050
51 if (((NUM_PROF(mci) - mci->num_sco) == ATH_MCI_MAX_ACL_PROFILE) &&
Sujith Manoharan682dd042012-02-22 14:43:52 +053052 (info->type != MCI_GPM_COEX_PROFILE_VOICE))
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053053 return false;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053054
Rajkumar Manoharan3c7992e2012-06-12 10:13:53 +053055 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +053056 if (!entry)
57 return false;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053058
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +053059 memcpy(entry, info, 10);
60 INC_PROF(mci, info);
61 list_add_tail(&entry->list, &mci->info);
Sujith Manoharan682dd042012-02-22 14:43:52 +053062
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053063 return true;
64}
65
66static void ath_mci_del_profile(struct ath_common *common,
67 struct ath_mci_profile *mci,
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +053068 struct ath_mci_profile_info *entry)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053069{
Sujith Manoharan682dd042012-02-22 14:43:52 +053070 if (!entry)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053071 return;
Sujith Manoharan682dd042012-02-22 14:43:52 +053072
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053073 DEC_PROF(mci, entry);
74 list_del(&entry->list);
75 kfree(entry);
76}
77
78void ath_mci_flush_profile(struct ath_mci_profile *mci)
79{
80 struct ath_mci_profile_info *info, *tinfo;
81
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +053082 mci->aggr_limit = 0;
Rajkumar Manoharand92bb982012-09-12 18:59:21 +053083 mci->num_mgmt = 0;
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +053084
85 if (list_empty(&mci->info))
86 return;
87
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053088 list_for_each_entry_safe(info, tinfo, &mci->info, list) {
89 list_del(&info->list);
90 DEC_PROF(mci, info);
91 kfree(info);
92 }
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053093}
94
95static void ath_mci_adjust_aggr_limit(struct ath_btcoex *btcoex)
96{
97 struct ath_mci_profile *mci = &btcoex->mci;
98 u32 wlan_airtime = btcoex->btcoex_period *
99 (100 - btcoex->duty_cycle) / 100;
100
101 /*
102 * Scale: wlan_airtime is in ms, aggr_limit is in 0.25 ms.
103 * When wlan_airtime is less than 4ms, aggregation limit has to be
104 * adjusted half of wlan_airtime to ensure that the aggregation can fit
105 * without collision with BT traffic.
106 */
107 if ((wlan_airtime <= 4) &&
108 (!mci->aggr_limit || (mci->aggr_limit > (2 * wlan_airtime))))
109 mci->aggr_limit = 2 * wlan_airtime;
110}
111
112static void ath_mci_update_scheme(struct ath_softc *sc)
113{
114 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
115 struct ath_btcoex *btcoex = &sc->btcoex;
116 struct ath_mci_profile *mci = &btcoex->mci;
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530117 struct ath9k_hw_mci *mci_hw = &sc->sc_ah->btcoex_hw.mci;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530118 struct ath_mci_profile_info *info;
119 u32 num_profile = NUM_PROF(mci);
120
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530121 if (mci_hw->config & ATH_MCI_CONFIG_DISABLE_TUNING)
122 goto skip_tuning;
123
Rajkumar Manoharan9e628172012-09-12 18:59:22 +0530124 mci->aggr_limit = 0;
Rajkumar Manoharana197b762012-06-12 10:13:54 +0530125 btcoex->duty_cycle = ath_mci_duty_cycle[num_profile];
Rajkumar Manoharan9e628172012-09-12 18:59:22 +0530126 btcoex->btcoex_period = ATH_MCI_DEF_BT_PERIOD;
127 if (NUM_PROF(mci))
128 btcoex->bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
129 else
130 btcoex->bt_stomp_type = mci->num_mgmt ? ATH_BTCOEX_STOMP_ALL :
131 ATH_BTCOEX_STOMP_LOW;
Rajkumar Manoharana197b762012-06-12 10:13:54 +0530132
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530133 if (num_profile == 1) {
134 info = list_first_entry(&mci->info,
135 struct ath_mci_profile_info,
136 list);
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530137 if (mci->num_sco) {
138 if (info->T == 12)
139 mci->aggr_limit = 8;
140 else if (info->T == 6) {
141 mci->aggr_limit = 6;
142 btcoex->duty_cycle = 30;
Rajkumar Manoharan9e628172012-09-12 18:59:22 +0530143 } else
144 mci->aggr_limit = 6;
Joe Perchesd2182b62011-12-15 14:55:53 -0800145 ath_dbg(common, MCI,
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530146 "Single SCO, aggregation limit %d 1/4 ms\n",
147 mci->aggr_limit);
148 } else if (mci->num_pan || mci->num_other_acl) {
149 /*
150 * For single PAN/FTP profile, allocate 35% for BT
151 * to improve WLAN throughput.
152 */
153 btcoex->duty_cycle = 35;
154 btcoex->btcoex_period = 53;
Joe Perchesd2182b62011-12-15 14:55:53 -0800155 ath_dbg(common, MCI,
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530156 "Single PAN/FTP bt period %d ms dutycycle %d\n",
157 btcoex->duty_cycle, btcoex->btcoex_period);
158 } else if (mci->num_hid) {
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530159 btcoex->duty_cycle = 30;
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530160 mci->aggr_limit = 6;
Joe Perchesd2182b62011-12-15 14:55:53 -0800161 ath_dbg(common, MCI,
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530162 "Multiple attempt/timeout single HID "
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530163 "aggregation limit 1.5 ms dutycycle 30%%\n");
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530164 }
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530165 } else if (num_profile == 2) {
166 if (mci->num_hid == 2)
167 btcoex->duty_cycle = 30;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530168 mci->aggr_limit = 6;
Joe Perchesd2182b62011-12-15 14:55:53 -0800169 ath_dbg(common, MCI,
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530170 "Two BT profiles aggr limit 1.5 ms dutycycle %d%%\n",
171 btcoex->duty_cycle);
172 } else if (num_profile >= 3) {
173 mci->aggr_limit = 4;
174 ath_dbg(common, MCI,
175 "Three or more profiles aggregation limit 1 ms\n");
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530176 }
177
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530178skip_tuning:
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530179 if (IS_CHAN_2GHZ(sc->sc_ah->curchan)) {
180 if (IS_CHAN_HT(sc->sc_ah->curchan))
181 ath_mci_adjust_aggr_limit(btcoex);
182 else
183 btcoex->btcoex_period >>= 1;
184 }
185
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530186 ath9k_btcoex_timer_pause(sc);
Mohammed Shafi Shajakhanc32cdbd2012-07-06 20:09:32 +0530187 ath9k_hw_btcoex_disable(sc->sc_ah);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530188
189 if (IS_CHAN_5GHZ(sc->sc_ah->curchan))
190 return;
191
Rajkumar Manoharana197b762012-06-12 10:13:54 +0530192 btcoex->duty_cycle += (mci->num_bdr ? ATH_MCI_BDR_DUTY_CYCLE : 0);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530193 if (btcoex->duty_cycle > ATH_MCI_MAX_DUTY_CYCLE)
194 btcoex->duty_cycle = ATH_MCI_MAX_DUTY_CYCLE;
195
Rajkumar Manoharandfd05872012-06-11 12:19:37 +0530196 btcoex->btcoex_no_stomp = btcoex->btcoex_period * 1000 *
Sujith Manoharan682dd042012-02-22 14:43:52 +0530197 (100 - btcoex->duty_cycle) / 100;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530198
199 ath9k_hw_btcoex_enable(sc->sc_ah);
200 ath9k_btcoex_timer_resume(sc);
201}
202
Rajkumar Manoharan83ad49a2012-09-10 17:05:09 +0530203static void ath_mci_wait_btcal_done(struct ath_softc *sc)
204{
205 struct ath_hw *ah = sc->sc_ah;
206
207 /* Stop tx & rx */
208 ieee80211_stop_queues(sc->hw);
209 ath_stoprecv(sc);
210 ath_drain_all_txq(sc, false);
211
212 /* Wait for cal done */
213 ar9003_mci_start_reset(ah, ah->curchan);
214
215 /* Resume tx & rx */
216 ath_startrecv(sc);
217 ieee80211_wake_queues(sc->hw);
218}
219
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530220static void ath_mci_cal_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload)
221{
222 struct ath_hw *ah = sc->sc_ah;
223 struct ath_common *common = ath9k_hw_common(ah);
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530224 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530225 u32 payload[4] = {0, 0, 0, 0};
226
227 switch (opcode) {
228 case MCI_GPM_BT_CAL_REQ:
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530229 if (mci_hw->bt_state == MCI_BT_AWAKE) {
Mohammed Shafi Shajakhan46533562012-08-24 16:27:06 +0530230 mci_hw->bt_state = MCI_BT_CAL_START;
Rajkumar Manoharan83ad49a2012-09-10 17:05:09 +0530231 ath_mci_wait_btcal_done(sc);
Sujith Manoharan682dd042012-02-22 14:43:52 +0530232 }
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530233 ath_dbg(common, MCI, "MCI State : %d\n", mci_hw->bt_state);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530234 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530235 case MCI_GPM_BT_CAL_GRANT:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530236 MCI_GPM_SET_CAL_TYPE(payload, MCI_GPM_WLAN_CAL_DONE);
237 ar9003_mci_send_message(sc->sc_ah, MCI_GPM, 0, payload,
238 16, false, true);
239 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530240 default:
Sujith Manoharan682dd042012-02-22 14:43:52 +0530241 ath_dbg(common, MCI, "Unknown GPM CAL message\n");
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530242 break;
243 }
244}
245
Rajkumar Manoharan3c7992e2012-06-12 10:13:53 +0530246static void ath9k_mci_work(struct work_struct *work)
247{
248 struct ath_softc *sc = container_of(work, struct ath_softc, mci_work);
249
250 ath_mci_update_scheme(sc);
251}
252
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530253static u8 ath_mci_process_profile(struct ath_softc *sc,
254 struct ath_mci_profile_info *info)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530255{
256 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
257 struct ath_btcoex *btcoex = &sc->btcoex;
258 struct ath_mci_profile *mci = &btcoex->mci;
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +0530259 struct ath_mci_profile_info *entry = NULL;
260
261 entry = ath_mci_find_profile(mci, info);
Bala Shanmugam305dd09f2012-06-18 11:36:58 +0530262 if (entry) {
263 /*
264 * Two MCI interrupts are generated while connecting to
265 * headset and A2DP profile, but only one MCI interrupt
266 * is generated with last added profile type while disconnecting
267 * both profiles.
268 * So while adding second profile type decrement
269 * the first one.
270 */
271 if (entry->type != info->type) {
272 DEC_PROF(mci, entry);
273 INC_PROF(mci, info);
274 }
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +0530275 memcpy(entry, info, 10);
Bala Shanmugam305dd09f2012-06-18 11:36:58 +0530276 }
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530277
278 if (info->start) {
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +0530279 if (!entry && !ath_mci_add_profile(common, mci, info))
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530280 return 0;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530281 } else
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +0530282 ath_mci_del_profile(common, mci, entry);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530283
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530284 return 1;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530285}
286
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530287static u8 ath_mci_process_status(struct ath_softc *sc,
288 struct ath_mci_profile_status *status)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530289{
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530290 struct ath_btcoex *btcoex = &sc->btcoex;
291 struct ath_mci_profile *mci = &btcoex->mci;
292 struct ath_mci_profile_info info;
293 int i = 0, old_num_mgmt = mci->num_mgmt;
294
295 /* Link status type are not handled */
Sujith Manoharan682dd042012-02-22 14:43:52 +0530296 if (status->is_link)
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530297 return 0;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530298
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530299 info.conn_handle = status->conn_handle;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530300 if (ath_mci_find_profile(mci, &info))
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530301 return 0;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530302
303 if (status->conn_handle >= ATH_MCI_MAX_PROFILE)
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530304 return 0;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530305
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530306 if (status->is_critical)
307 __set_bit(status->conn_handle, mci->status);
308 else
309 __clear_bit(status->conn_handle, mci->status);
310
311 mci->num_mgmt = 0;
312 do {
313 if (test_bit(i, mci->status))
314 mci->num_mgmt++;
315 } while (++i < ATH_MCI_MAX_PROFILE);
316
317 if (old_num_mgmt != mci->num_mgmt)
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530318 return 1;
319
320 return 0;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530321}
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530322
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530323static void ath_mci_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload)
324{
325 struct ath_hw *ah = sc->sc_ah;
326 struct ath_mci_profile_info profile_info;
327 struct ath_mci_profile_status profile_status;
328 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530329 u8 major, minor, update_scheme = 0;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530330 u32 seq_num;
331
Rajkumar Manoharand92bb982012-09-12 18:59:21 +0530332 if (ar9003_mci_state(ah, MCI_STATE_NEED_FLUSH_BT_INFO) &&
333 ar9003_mci_state(ah, MCI_STATE_ENABLE)) {
334 ath_dbg(common, MCI, "(MCI) Need to flush BT profiles\n");
335 ath_mci_flush_profile(&sc->btcoex.mci);
336 ar9003_mci_state(ah, MCI_STATE_SEND_STATUS_QUERY);
337 }
338
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530339 switch (opcode) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530340 case MCI_GPM_COEX_VERSION_QUERY:
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530341 ar9003_mci_state(ah, MCI_STATE_SEND_WLAN_COEX_VERSION);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530342 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530343 case MCI_GPM_COEX_VERSION_RESPONSE:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530344 major = *(rx_payload + MCI_GPM_COEX_B_MAJOR_VERSION);
345 minor = *(rx_payload + MCI_GPM_COEX_B_MINOR_VERSION);
Rajkumar Manoharane1763d32012-06-12 20:18:17 +0530346 ar9003_mci_set_bt_version(ah, major, minor);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530347 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530348 case MCI_GPM_COEX_STATUS_QUERY:
Rajkumar Manoharan2d340ac2012-06-12 20:18:18 +0530349 ar9003_mci_send_wlan_channels(ah);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530350 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530351 case MCI_GPM_COEX_BT_PROFILE_INFO:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530352 memcpy(&profile_info,
353 (rx_payload + MCI_GPM_COEX_B_PROFILE_TYPE), 10);
354
Sujith Manoharan682dd042012-02-22 14:43:52 +0530355 if ((profile_info.type == MCI_GPM_COEX_PROFILE_UNKNOWN) ||
356 (profile_info.type >= MCI_GPM_COEX_PROFILE_MAX)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800357 ath_dbg(common, MCI,
Sujith Manoharan682dd042012-02-22 14:43:52 +0530358 "Illegal profile type = %d, state = %d\n",
Joe Perchesd2182b62011-12-15 14:55:53 -0800359 profile_info.type,
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530360 profile_info.start);
361 break;
362 }
363
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530364 update_scheme += ath_mci_process_profile(sc, &profile_info);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530365 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530366 case MCI_GPM_COEX_BT_STATUS_UPDATE:
367 profile_status.is_link = *(rx_payload +
368 MCI_GPM_COEX_B_STATUS_TYPE);
369 profile_status.conn_handle = *(rx_payload +
370 MCI_GPM_COEX_B_STATUS_LINKID);
371 profile_status.is_critical = *(rx_payload +
372 MCI_GPM_COEX_B_STATUS_STATE);
373
374 seq_num = *((u32 *)(rx_payload + 12));
Joe Perchesd2182b62011-12-15 14:55:53 -0800375 ath_dbg(common, MCI,
Mohammed Shafi Shajakhand8fffb42012-06-27 20:00:27 +0530376 "BT_Status_Update: is_link=%d, linkId=%d, state=%d, SEQ=%u\n",
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530377 profile_status.is_link, profile_status.conn_handle,
378 profile_status.is_critical, seq_num);
379
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530380 update_scheme += ath_mci_process_status(sc, &profile_status);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530381 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530382 default:
Sujith Manoharan682dd042012-02-22 14:43:52 +0530383 ath_dbg(common, MCI, "Unknown GPM COEX message = 0x%02x\n", opcode);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530384 break;
385 }
Rajkumar Manoharan7a034142012-09-12 18:59:24 +0530386 if (update_scheme)
387 ieee80211_queue_work(sc->hw, &sc->mci_work);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530388}
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530389
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530390int ath_mci_setup(struct ath_softc *sc)
391{
392 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
393 struct ath_mci_coex *mci = &sc->mci_coex;
Sujith Manoharanea510e42012-02-22 12:40:09 +0530394 struct ath_mci_buf *buf = &mci->sched_buf;
Sujith Manoharan69c6ac62012-09-26 07:54:43 +0530395 int ret;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530396
Sujith Manoharanea510e42012-02-22 12:40:09 +0530397 buf->bf_addr = dma_alloc_coherent(sc->dev,
398 ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE,
399 &buf->bf_paddr, GFP_KERNEL);
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530400
Sujith Manoharanea510e42012-02-22 12:40:09 +0530401 if (buf->bf_addr == NULL) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800402 ath_dbg(common, FATAL, "MCI buffer alloc failed\n");
Sujith Manoharanea510e42012-02-22 12:40:09 +0530403 return -ENOMEM;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530404 }
405
Sujith Manoharanea510e42012-02-22 12:40:09 +0530406 memset(buf->bf_addr, MCI_GPM_RSVD_PATTERN,
407 ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE);
408
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530409 mci->sched_buf.bf_len = ATH_MCI_SCHED_BUF_SIZE;
410
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530411 mci->gpm_buf.bf_len = ATH_MCI_GPM_BUF_SIZE;
Sujith Manoharanea510e42012-02-22 12:40:09 +0530412 mci->gpm_buf.bf_addr = (u8 *)mci->sched_buf.bf_addr + mci->sched_buf.bf_len;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530413 mci->gpm_buf.bf_paddr = mci->sched_buf.bf_paddr + mci->sched_buf.bf_len;
414
Sujith Manoharan69c6ac62012-09-26 07:54:43 +0530415 ret = ar9003_mci_setup(sc->sc_ah, mci->gpm_buf.bf_paddr,
416 mci->gpm_buf.bf_addr, (mci->gpm_buf.bf_len >> 4),
417 mci->sched_buf.bf_paddr);
418 if (ret) {
419 ath_err(common, "Failed to initialize MCI\n");
420 return ret;
421 }
Sujith Manoharanea510e42012-02-22 12:40:09 +0530422
Rajkumar Manoharan3c7992e2012-06-12 10:13:53 +0530423 INIT_WORK(&sc->mci_work, ath9k_mci_work);
Sujith Manoharanea510e42012-02-22 12:40:09 +0530424 ath_dbg(common, MCI, "MCI Initialized\n");
425
426 return 0;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530427}
428
429void ath_mci_cleanup(struct ath_softc *sc)
430{
Sujith Manoharanea510e42012-02-22 12:40:09 +0530431 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530432 struct ath_hw *ah = sc->sc_ah;
433 struct ath_mci_coex *mci = &sc->mci_coex;
Sujith Manoharanea510e42012-02-22 12:40:09 +0530434 struct ath_mci_buf *buf = &mci->sched_buf;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530435
Sujith Manoharanea510e42012-02-22 12:40:09 +0530436 if (buf->bf_addr)
437 dma_free_coherent(sc->dev,
438 ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE,
439 buf->bf_addr, buf->bf_paddr);
440
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530441 ar9003_mci_cleanup(ah);
Sujith Manoharanea510e42012-02-22 12:40:09 +0530442
443 ath_dbg(common, MCI, "MCI De-Initialized\n");
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530444}
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530445
446void ath_mci_intr(struct ath_softc *sc)
447{
448 struct ath_mci_coex *mci = &sc->mci_coex;
449 struct ath_hw *ah = sc->sc_ah;
450 struct ath_common *common = ath9k_hw_common(ah);
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530451 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530452 u32 mci_int, mci_int_rxmsg;
453 u32 offset, subtype, opcode;
454 u32 *pgpm;
455 u32 more_data = MCI_GPM_MORE;
456 bool skip_gpm = false;
457
458 ar9003_mci_get_interrupt(sc->sc_ah, &mci_int, &mci_int_rxmsg);
459
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530460 if (ar9003_mci_state(ah, MCI_STATE_ENABLE) == 0) {
Rajkumar Manoharan506847a2012-06-12 20:18:16 +0530461 ar9003_mci_get_next_gpm_offset(ah, true, NULL);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530462 return;
463 }
464
465 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE) {
466 u32 payload[4] = { 0xffffffff, 0xffffffff,
467 0xffffffff, 0xffffff00};
468
469 /*
470 * The following REMOTE_RESET and SYS_WAKING used to sent
471 * only when BT wake up. Now they are always sent, as a
472 * recovery method to reset BT MCI's RX alignment.
473 */
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530474 ar9003_mci_send_message(ah, MCI_REMOTE_RESET, 0,
475 payload, 16, true, false);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530476 ar9003_mci_send_message(ah, MCI_SYS_WAKING, 0,
477 NULL, 0, true, false);
478
479 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE;
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530480 ar9003_mci_state(ah, MCI_STATE_RESET_REQ_WAKE);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530481
482 /*
483 * always do this for recovery and 2G/5G toggling and LNA_TRANS
484 */
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530485 ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530486 }
487
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530488 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING) {
489 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING;
490
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530491 if ((mci_hw->bt_state == MCI_BT_SLEEP) &&
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530492 (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP) !=
493 MCI_BT_SLEEP))
494 ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530495 }
496
497 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530498 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING;
499
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530500 if ((mci_hw->bt_state == MCI_BT_AWAKE) &&
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530501 (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP) !=
502 MCI_BT_AWAKE))
Rajkumar Manoharan93309692012-06-12 20:18:23 +0530503 mci_hw->bt_state = MCI_BT_SLEEP;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530504 }
505
506 if ((mci_int & AR_MCI_INTERRUPT_RX_INVALID_HDR) ||
507 (mci_int & AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT)) {
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530508 ar9003_mci_state(ah, MCI_STATE_RECOVER_RX);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530509 skip_gpm = true;
510 }
511
512 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530513 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO;
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530514 offset = ar9003_mci_state(ah, MCI_STATE_LAST_SCHD_MSG_OFFSET);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530515 }
516
517 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_GPM) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530518 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_GPM;
519
520 while (more_data == MCI_GPM_MORE) {
521
522 pgpm = mci->gpm_buf.bf_addr;
Rajkumar Manoharan506847a2012-06-12 20:18:16 +0530523 offset = ar9003_mci_get_next_gpm_offset(ah, false,
524 &more_data);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530525
526 if (offset == MCI_GPM_INVALID)
527 break;
528
529 pgpm += (offset >> 2);
530
531 /*
532 * The first dword is timer.
533 * The real data starts from 2nd dword.
534 */
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530535 subtype = MCI_GPM_TYPE(pgpm);
536 opcode = MCI_GPM_OPCODE(pgpm);
537
Sujith Manoharan682dd042012-02-22 14:43:52 +0530538 if (skip_gpm)
539 goto recycle;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530540
Sujith Manoharan682dd042012-02-22 14:43:52 +0530541 if (MCI_GPM_IS_CAL_TYPE(subtype)) {
542 ath_mci_cal_msg(sc, subtype, (u8 *)pgpm);
543 } else {
544 switch (subtype) {
545 case MCI_GPM_COEX_AGENT:
546 ath_mci_msg(sc, opcode, (u8 *)pgpm);
547 break;
548 default:
549 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530550 }
551 }
Sujith Manoharan682dd042012-02-22 14:43:52 +0530552 recycle:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530553 MCI_GPM_RECYCLE(pgpm);
554 }
555 }
556
557 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_HW_MSG_MASK) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530558 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_LNA_CONTROL)
559 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_LNA_CONTROL;
560
Sujith Manoharan682dd042012-02-22 14:43:52 +0530561 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_LNA_INFO)
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530562 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_LNA_INFO;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530563
564 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_INFO) {
Rajkumar Manoharan26e942b2012-06-12 20:18:22 +0530565 int value_dbm = MS(mci_hw->cont_status,
566 AR_MCI_CONT_RSSI_POWER);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530567
568 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_INFO;
569
Rajkumar Manoharan26e942b2012-06-12 20:18:22 +0530570 ath_dbg(common, MCI,
571 "MCI CONT_INFO: (%s) pri = %d pwr = %d dBm\n",
572 MS(mci_hw->cont_status, AR_MCI_CONT_TXRX) ?
573 "tx" : "rx",
574 MS(mci_hw->cont_status, AR_MCI_CONT_PRIORITY),
575 value_dbm);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530576 }
577
Sujith Manoharan682dd042012-02-22 14:43:52 +0530578 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_NACK)
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530579 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_NACK;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530580
Sujith Manoharan682dd042012-02-22 14:43:52 +0530581 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_RST)
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530582 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_RST;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530583 }
584
585 if ((mci_int & AR_MCI_INTERRUPT_RX_INVALID_HDR) ||
Rajkumar Manoharand92bb982012-09-12 18:59:21 +0530586 (mci_int & AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT)) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530587 mci_int &= ~(AR_MCI_INTERRUPT_RX_INVALID_HDR |
588 AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT);
Rajkumar Manoharand92bb982012-09-12 18:59:21 +0530589 ath_mci_msg(sc, MCI_GPM_COEX_NOOP, NULL);
590 }
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530591}
Sujith Manoharane270e772012-06-04 16:27:19 +0530592
593void ath_mci_enable(struct ath_softc *sc)
594{
595 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
596
597 if (!common->btcoex_enabled)
598 return;
599
600 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
601 sc->sc_ah->imask |= ATH9K_INT_MCI;
602}
Rajkumar Manoharan50072eb2012-10-12 14:07:22 +0530603
604void ath9k_mci_update_wlan_channels(struct ath_softc *sc, bool allow_all)
605{
606 struct ath_hw *ah = sc->sc_ah;
607 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
608 struct ath9k_channel *chan = ah->curchan;
609 u32 channelmap[] = {0x00000000, 0xffff0000, 0xffffffff, 0x7fffffff};
610 int i;
611 s16 chan_start, chan_end;
612 u16 wlan_chan;
613
614 if (!chan || !IS_CHAN_2GHZ(chan))
615 return;
616
617 if (allow_all)
618 goto send_wlan_chan;
619
620 wlan_chan = chan->channel - 2402;
621
622 chan_start = wlan_chan - 10;
623 chan_end = wlan_chan + 10;
624
625 if (chan->chanmode == CHANNEL_G_HT40PLUS)
626 chan_end += 20;
627 else if (chan->chanmode == CHANNEL_G_HT40MINUS)
628 chan_start -= 20;
629
630 /* adjust side band */
631 chan_start -= 7;
632 chan_end += 7;
633
634 if (chan_start <= 0)
635 chan_start = 0;
636 if (chan_end >= ATH_MCI_NUM_BT_CHANNELS)
637 chan_end = ATH_MCI_NUM_BT_CHANNELS - 1;
638
639 ath_dbg(ath9k_hw_common(ah), MCI,
640 "WLAN current channel %d mask BT channel %d - %d\n",
641 wlan_chan, chan_start, chan_end);
642
643 for (i = chan_start; i < chan_end; i++)
644 MCI_GPM_CLR_CHANNEL_BIT(&channelmap, i);
645
646send_wlan_chan:
647 /* update and send wlan channels info to BT */
648 for (i = 0; i < 4; i++)
649 mci->wlan_channels[i] = channelmap[i];
650 ar9003_mci_send_wlan_channels(ah);
651 ar9003_mci_state(ah, MCI_STATE_SEND_VERSION_QUERY);
652}