blob: e83d7200f762eff22895ede3d69a5f1118685b12 [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;
83
84 if (list_empty(&mci->info))
85 return;
86
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053087 list_for_each_entry_safe(info, tinfo, &mci->info, list) {
88 list_del(&info->list);
89 DEC_PROF(mci, info);
90 kfree(info);
91 }
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +053092}
93
94static void ath_mci_adjust_aggr_limit(struct ath_btcoex *btcoex)
95{
96 struct ath_mci_profile *mci = &btcoex->mci;
97 u32 wlan_airtime = btcoex->btcoex_period *
98 (100 - btcoex->duty_cycle) / 100;
99
100 /*
101 * Scale: wlan_airtime is in ms, aggr_limit is in 0.25 ms.
102 * When wlan_airtime is less than 4ms, aggregation limit has to be
103 * adjusted half of wlan_airtime to ensure that the aggregation can fit
104 * without collision with BT traffic.
105 */
106 if ((wlan_airtime <= 4) &&
107 (!mci->aggr_limit || (mci->aggr_limit > (2 * wlan_airtime))))
108 mci->aggr_limit = 2 * wlan_airtime;
109}
110
111static void ath_mci_update_scheme(struct ath_softc *sc)
112{
113 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
114 struct ath_btcoex *btcoex = &sc->btcoex;
115 struct ath_mci_profile *mci = &btcoex->mci;
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530116 struct ath9k_hw_mci *mci_hw = &sc->sc_ah->btcoex_hw.mci;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530117 struct ath_mci_profile_info *info;
118 u32 num_profile = NUM_PROF(mci);
119
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530120 if (mci_hw->config & ATH_MCI_CONFIG_DISABLE_TUNING)
121 goto skip_tuning;
122
Rajkumar Manoharana197b762012-06-12 10:13:54 +0530123 btcoex->duty_cycle = ath_mci_duty_cycle[num_profile];
124
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530125 if (num_profile == 1) {
126 info = list_first_entry(&mci->info,
127 struct ath_mci_profile_info,
128 list);
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530129 if (mci->num_sco) {
130 if (info->T == 12)
131 mci->aggr_limit = 8;
132 else if (info->T == 6) {
133 mci->aggr_limit = 6;
134 btcoex->duty_cycle = 30;
135 }
Joe Perchesd2182b62011-12-15 14:55:53 -0800136 ath_dbg(common, MCI,
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530137 "Single SCO, aggregation limit %d 1/4 ms\n",
138 mci->aggr_limit);
139 } else if (mci->num_pan || mci->num_other_acl) {
140 /*
141 * For single PAN/FTP profile, allocate 35% for BT
142 * to improve WLAN throughput.
143 */
144 btcoex->duty_cycle = 35;
145 btcoex->btcoex_period = 53;
Joe Perchesd2182b62011-12-15 14:55:53 -0800146 ath_dbg(common, MCI,
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530147 "Single PAN/FTP bt period %d ms dutycycle %d\n",
148 btcoex->duty_cycle, btcoex->btcoex_period);
149 } else if (mci->num_hid) {
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530150 btcoex->duty_cycle = 30;
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530151 mci->aggr_limit = 6;
Joe Perchesd2182b62011-12-15 14:55:53 -0800152 ath_dbg(common, MCI,
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530153 "Multiple attempt/timeout single HID "
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530154 "aggregation limit 1.5 ms dutycycle 30%%\n");
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530155 }
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530156 } else if (num_profile == 2) {
157 if (mci->num_hid == 2)
158 btcoex->duty_cycle = 30;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530159 mci->aggr_limit = 6;
Joe Perchesd2182b62011-12-15 14:55:53 -0800160 ath_dbg(common, MCI,
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530161 "Two BT profiles aggr limit 1.5 ms dutycycle %d%%\n",
162 btcoex->duty_cycle);
163 } else if (num_profile >= 3) {
164 mci->aggr_limit = 4;
165 ath_dbg(common, MCI,
166 "Three or more profiles aggregation limit 1 ms\n");
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530167 }
168
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530169skip_tuning:
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530170 if (IS_CHAN_2GHZ(sc->sc_ah->curchan)) {
171 if (IS_CHAN_HT(sc->sc_ah->curchan))
172 ath_mci_adjust_aggr_limit(btcoex);
173 else
174 btcoex->btcoex_period >>= 1;
175 }
176
177 ath9k_hw_btcoex_disable(sc->sc_ah);
178 ath9k_btcoex_timer_pause(sc);
179
180 if (IS_CHAN_5GHZ(sc->sc_ah->curchan))
181 return;
182
Rajkumar Manoharana197b762012-06-12 10:13:54 +0530183 btcoex->duty_cycle += (mci->num_bdr ? ATH_MCI_BDR_DUTY_CYCLE : 0);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530184 if (btcoex->duty_cycle > ATH_MCI_MAX_DUTY_CYCLE)
185 btcoex->duty_cycle = ATH_MCI_MAX_DUTY_CYCLE;
186
Rajkumar Manoharandfd05872012-06-11 12:19:37 +0530187 btcoex->btcoex_no_stomp = btcoex->btcoex_period * 1000 *
Sujith Manoharan682dd042012-02-22 14:43:52 +0530188 (100 - btcoex->duty_cycle) / 100;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530189
190 ath9k_hw_btcoex_enable(sc->sc_ah);
191 ath9k_btcoex_timer_resume(sc);
192}
193
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530194static void ath_mci_cal_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload)
195{
196 struct ath_hw *ah = sc->sc_ah;
197 struct ath_common *common = ath9k_hw_common(ah);
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530198 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530199 u32 payload[4] = {0, 0, 0, 0};
200
201 switch (opcode) {
202 case MCI_GPM_BT_CAL_REQ:
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530203 if (mci_hw->bt_state == MCI_BT_AWAKE) {
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530204 ar9003_mci_state(ah, MCI_STATE_SET_BT_CAL_START);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530205 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
Sujith Manoharan682dd042012-02-22 14:43:52 +0530206 }
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530207 ath_dbg(common, MCI, "MCI State : %d\n", mci_hw->bt_state);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530208 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530209 case MCI_GPM_BT_CAL_GRANT:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530210 MCI_GPM_SET_CAL_TYPE(payload, MCI_GPM_WLAN_CAL_DONE);
211 ar9003_mci_send_message(sc->sc_ah, MCI_GPM, 0, payload,
212 16, false, true);
213 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530214 default:
Sujith Manoharan682dd042012-02-22 14:43:52 +0530215 ath_dbg(common, MCI, "Unknown GPM CAL message\n");
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530216 break;
217 }
218}
219
Rajkumar Manoharan3c7992e2012-06-12 10:13:53 +0530220static void ath9k_mci_work(struct work_struct *work)
221{
222 struct ath_softc *sc = container_of(work, struct ath_softc, mci_work);
223
224 ath_mci_update_scheme(sc);
225}
226
Felix Fietkaue5f0a272011-12-10 22:11:19 +0100227static void ath_mci_process_profile(struct ath_softc *sc,
228 struct ath_mci_profile_info *info)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530229{
230 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
231 struct ath_btcoex *btcoex = &sc->btcoex;
232 struct ath_mci_profile *mci = &btcoex->mci;
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +0530233 struct ath_mci_profile_info *entry = NULL;
234
235 entry = ath_mci_find_profile(mci, info);
236 if (entry)
237 memcpy(entry, info, 10);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530238
239 if (info->start) {
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +0530240 if (!entry && !ath_mci_add_profile(common, mci, info))
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530241 return;
242 } else
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +0530243 ath_mci_del_profile(common, mci, entry);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530244
245 btcoex->btcoex_period = ATH_MCI_DEF_BT_PERIOD;
246 mci->aggr_limit = mci->num_sco ? 6 : 0;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530247
Rajkumar Manoharana197b762012-06-12 10:13:54 +0530248 btcoex->duty_cycle = ath_mci_duty_cycle[NUM_PROF(mci)];
249 if (NUM_PROF(mci))
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530250 btcoex->bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
Rajkumar Manoharana197b762012-06-12 10:13:54 +0530251 else
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530252 btcoex->bt_stomp_type = mci->num_mgmt ? ATH_BTCOEX_STOMP_ALL :
253 ATH_BTCOEX_STOMP_LOW;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530254
Rajkumar Manoharan3c7992e2012-06-12 10:13:53 +0530255 ieee80211_queue_work(sc->hw, &sc->mci_work);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530256}
257
Felix Fietkaue5f0a272011-12-10 22:11:19 +0100258static void ath_mci_process_status(struct ath_softc *sc,
259 struct ath_mci_profile_status *status)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530260{
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530261 struct ath_btcoex *btcoex = &sc->btcoex;
262 struct ath_mci_profile *mci = &btcoex->mci;
263 struct ath_mci_profile_info info;
264 int i = 0, old_num_mgmt = mci->num_mgmt;
265
266 /* Link status type are not handled */
Sujith Manoharan682dd042012-02-22 14:43:52 +0530267 if (status->is_link)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530268 return;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530269
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530270 info.conn_handle = status->conn_handle;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530271 if (ath_mci_find_profile(mci, &info))
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530272 return;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530273
274 if (status->conn_handle >= ATH_MCI_MAX_PROFILE)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530275 return;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530276
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530277 if (status->is_critical)
278 __set_bit(status->conn_handle, mci->status);
279 else
280 __clear_bit(status->conn_handle, mci->status);
281
282 mci->num_mgmt = 0;
283 do {
284 if (test_bit(i, mci->status))
285 mci->num_mgmt++;
286 } while (++i < ATH_MCI_MAX_PROFILE);
287
288 if (old_num_mgmt != mci->num_mgmt)
Rajkumar Manoharan3c7992e2012-06-12 10:13:53 +0530289 ieee80211_queue_work(sc->hw, &sc->mci_work);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530290}
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530291
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530292static void ath_mci_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload)
293{
294 struct ath_hw *ah = sc->sc_ah;
295 struct ath_mci_profile_info profile_info;
296 struct ath_mci_profile_status profile_status;
297 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Rajkumar Manoharane1763d32012-06-12 20:18:17 +0530298 u8 major, minor;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530299 u32 seq_num;
300
301 switch (opcode) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530302 case MCI_GPM_COEX_VERSION_QUERY:
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530303 ar9003_mci_state(ah, MCI_STATE_SEND_WLAN_COEX_VERSION);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530304 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530305 case MCI_GPM_COEX_VERSION_RESPONSE:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530306 major = *(rx_payload + MCI_GPM_COEX_B_MAJOR_VERSION);
307 minor = *(rx_payload + MCI_GPM_COEX_B_MINOR_VERSION);
Rajkumar Manoharane1763d32012-06-12 20:18:17 +0530308 ar9003_mci_set_bt_version(ah, major, minor);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530309 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530310 case MCI_GPM_COEX_STATUS_QUERY:
Rajkumar Manoharan2d340ac2012-06-12 20:18:18 +0530311 ar9003_mci_send_wlan_channels(ah);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530312 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530313 case MCI_GPM_COEX_BT_PROFILE_INFO:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530314 memcpy(&profile_info,
315 (rx_payload + MCI_GPM_COEX_B_PROFILE_TYPE), 10);
316
Sujith Manoharan682dd042012-02-22 14:43:52 +0530317 if ((profile_info.type == MCI_GPM_COEX_PROFILE_UNKNOWN) ||
318 (profile_info.type >= MCI_GPM_COEX_PROFILE_MAX)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800319 ath_dbg(common, MCI,
Sujith Manoharan682dd042012-02-22 14:43:52 +0530320 "Illegal profile type = %d, state = %d\n",
Joe Perchesd2182b62011-12-15 14:55:53 -0800321 profile_info.type,
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530322 profile_info.start);
323 break;
324 }
325
326 ath_mci_process_profile(sc, &profile_info);
327 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530328 case MCI_GPM_COEX_BT_STATUS_UPDATE:
329 profile_status.is_link = *(rx_payload +
330 MCI_GPM_COEX_B_STATUS_TYPE);
331 profile_status.conn_handle = *(rx_payload +
332 MCI_GPM_COEX_B_STATUS_LINKID);
333 profile_status.is_critical = *(rx_payload +
334 MCI_GPM_COEX_B_STATUS_STATE);
335
336 seq_num = *((u32 *)(rx_payload + 12));
Joe Perchesd2182b62011-12-15 14:55:53 -0800337 ath_dbg(common, MCI,
Sujith Manoharan682dd042012-02-22 14:43:52 +0530338 "BT_Status_Update: is_link=%d, linkId=%d, state=%d, SEQ=%d\n",
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530339 profile_status.is_link, profile_status.conn_handle,
340 profile_status.is_critical, seq_num);
341
342 ath_mci_process_status(sc, &profile_status);
343 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530344 default:
Sujith Manoharan682dd042012-02-22 14:43:52 +0530345 ath_dbg(common, MCI, "Unknown GPM COEX message = 0x%02x\n", opcode);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530346 break;
347 }
348}
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530349
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530350int ath_mci_setup(struct ath_softc *sc)
351{
352 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
353 struct ath_mci_coex *mci = &sc->mci_coex;
Sujith Manoharanea510e42012-02-22 12:40:09 +0530354 struct ath_mci_buf *buf = &mci->sched_buf;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530355
Sujith Manoharanea510e42012-02-22 12:40:09 +0530356 buf->bf_addr = dma_alloc_coherent(sc->dev,
357 ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE,
358 &buf->bf_paddr, GFP_KERNEL);
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530359
Sujith Manoharanea510e42012-02-22 12:40:09 +0530360 if (buf->bf_addr == NULL) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800361 ath_dbg(common, FATAL, "MCI buffer alloc failed\n");
Sujith Manoharanea510e42012-02-22 12:40:09 +0530362 return -ENOMEM;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530363 }
364
Sujith Manoharanea510e42012-02-22 12:40:09 +0530365 memset(buf->bf_addr, MCI_GPM_RSVD_PATTERN,
366 ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE);
367
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530368 mci->sched_buf.bf_len = ATH_MCI_SCHED_BUF_SIZE;
369
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530370 mci->gpm_buf.bf_len = ATH_MCI_GPM_BUF_SIZE;
Sujith Manoharanea510e42012-02-22 12:40:09 +0530371 mci->gpm_buf.bf_addr = (u8 *)mci->sched_buf.bf_addr + mci->sched_buf.bf_len;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530372 mci->gpm_buf.bf_paddr = mci->sched_buf.bf_paddr + mci->sched_buf.bf_len;
373
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530374 ar9003_mci_setup(sc->sc_ah, mci->gpm_buf.bf_paddr,
375 mci->gpm_buf.bf_addr, (mci->gpm_buf.bf_len >> 4),
376 mci->sched_buf.bf_paddr);
Sujith Manoharanea510e42012-02-22 12:40:09 +0530377
Rajkumar Manoharan3c7992e2012-06-12 10:13:53 +0530378 INIT_WORK(&sc->mci_work, ath9k_mci_work);
Sujith Manoharanea510e42012-02-22 12:40:09 +0530379 ath_dbg(common, MCI, "MCI Initialized\n");
380
381 return 0;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530382}
383
384void ath_mci_cleanup(struct ath_softc *sc)
385{
Sujith Manoharanea510e42012-02-22 12:40:09 +0530386 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530387 struct ath_hw *ah = sc->sc_ah;
388 struct ath_mci_coex *mci = &sc->mci_coex;
Sujith Manoharanea510e42012-02-22 12:40:09 +0530389 struct ath_mci_buf *buf = &mci->sched_buf;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530390
Sujith Manoharanea510e42012-02-22 12:40:09 +0530391 if (buf->bf_addr)
392 dma_free_coherent(sc->dev,
393 ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE,
394 buf->bf_addr, buf->bf_paddr);
395
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530396 ar9003_mci_cleanup(ah);
Sujith Manoharanea510e42012-02-22 12:40:09 +0530397
398 ath_dbg(common, MCI, "MCI De-Initialized\n");
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530399}
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530400
401void ath_mci_intr(struct ath_softc *sc)
402{
403 struct ath_mci_coex *mci = &sc->mci_coex;
404 struct ath_hw *ah = sc->sc_ah;
405 struct ath_common *common = ath9k_hw_common(ah);
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530406 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530407 u32 mci_int, mci_int_rxmsg;
408 u32 offset, subtype, opcode;
409 u32 *pgpm;
410 u32 more_data = MCI_GPM_MORE;
411 bool skip_gpm = false;
412
413 ar9003_mci_get_interrupt(sc->sc_ah, &mci_int, &mci_int_rxmsg);
414
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530415 if (ar9003_mci_state(ah, MCI_STATE_ENABLE) == 0) {
Rajkumar Manoharan506847a2012-06-12 20:18:16 +0530416 ar9003_mci_get_next_gpm_offset(ah, true, NULL);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530417 return;
418 }
419
420 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE) {
421 u32 payload[4] = { 0xffffffff, 0xffffffff,
422 0xffffffff, 0xffffff00};
423
424 /*
425 * The following REMOTE_RESET and SYS_WAKING used to sent
426 * only when BT wake up. Now they are always sent, as a
427 * recovery method to reset BT MCI's RX alignment.
428 */
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530429 ar9003_mci_send_message(ah, MCI_REMOTE_RESET, 0,
430 payload, 16, true, false);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530431 ar9003_mci_send_message(ah, MCI_SYS_WAKING, 0,
432 NULL, 0, true, false);
433
434 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE;
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530435 ar9003_mci_state(ah, MCI_STATE_RESET_REQ_WAKE);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530436
437 /*
438 * always do this for recovery and 2G/5G toggling and LNA_TRANS
439 */
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530440 ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530441 }
442
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530443 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING) {
444 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING;
445
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530446 if ((mci_hw->bt_state == MCI_BT_SLEEP) &&
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530447 (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP) !=
448 MCI_BT_SLEEP))
449 ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530450 }
451
452 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530453 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING;
454
Rajkumar Manoharan6d97be42012-06-12 20:18:21 +0530455 if ((mci_hw->bt_state == MCI_BT_AWAKE) &&
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530456 (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP) !=
457 MCI_BT_AWAKE))
458 ar9003_mci_state(ah, MCI_STATE_SET_BT_SLEEP);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530459 }
460
461 if ((mci_int & AR_MCI_INTERRUPT_RX_INVALID_HDR) ||
462 (mci_int & AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT)) {
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530463 ar9003_mci_state(ah, MCI_STATE_RECOVER_RX);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530464 skip_gpm = true;
465 }
466
467 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530468 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO;
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530469 offset = ar9003_mci_state(ah, MCI_STATE_LAST_SCHD_MSG_OFFSET);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530470 }
471
472 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_GPM) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530473 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_GPM;
474
475 while (more_data == MCI_GPM_MORE) {
476
477 pgpm = mci->gpm_buf.bf_addr;
Rajkumar Manoharan506847a2012-06-12 20:18:16 +0530478 offset = ar9003_mci_get_next_gpm_offset(ah, false,
479 &more_data);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530480
481 if (offset == MCI_GPM_INVALID)
482 break;
483
484 pgpm += (offset >> 2);
485
486 /*
487 * The first dword is timer.
488 * The real data starts from 2nd dword.
489 */
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530490 subtype = MCI_GPM_TYPE(pgpm);
491 opcode = MCI_GPM_OPCODE(pgpm);
492
Sujith Manoharan682dd042012-02-22 14:43:52 +0530493 if (skip_gpm)
494 goto recycle;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530495
Sujith Manoharan682dd042012-02-22 14:43:52 +0530496 if (MCI_GPM_IS_CAL_TYPE(subtype)) {
497 ath_mci_cal_msg(sc, subtype, (u8 *)pgpm);
498 } else {
499 switch (subtype) {
500 case MCI_GPM_COEX_AGENT:
501 ath_mci_msg(sc, opcode, (u8 *)pgpm);
502 break;
503 default:
504 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530505 }
506 }
Sujith Manoharan682dd042012-02-22 14:43:52 +0530507 recycle:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530508 MCI_GPM_RECYCLE(pgpm);
509 }
510 }
511
512 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_HW_MSG_MASK) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530513 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_LNA_CONTROL)
514 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_LNA_CONTROL;
515
Sujith Manoharan682dd042012-02-22 14:43:52 +0530516 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_LNA_INFO)
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530517 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_LNA_INFO;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530518
519 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_INFO) {
Rajkumar Manoharan26e942b2012-06-12 20:18:22 +0530520 int value_dbm = MS(mci_hw->cont_status,
521 AR_MCI_CONT_RSSI_POWER);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530522
523 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_INFO;
524
Rajkumar Manoharan26e942b2012-06-12 20:18:22 +0530525 ath_dbg(common, MCI,
526 "MCI CONT_INFO: (%s) pri = %d pwr = %d dBm\n",
527 MS(mci_hw->cont_status, AR_MCI_CONT_TXRX) ?
528 "tx" : "rx",
529 MS(mci_hw->cont_status, AR_MCI_CONT_PRIORITY),
530 value_dbm);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530531 }
532
Sujith Manoharan682dd042012-02-22 14:43:52 +0530533 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_NACK)
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530534 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_NACK;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530535
Sujith Manoharan682dd042012-02-22 14:43:52 +0530536 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_RST)
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530537 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_RST;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530538 }
539
540 if ((mci_int & AR_MCI_INTERRUPT_RX_INVALID_HDR) ||
541 (mci_int & AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT))
542 mci_int &= ~(AR_MCI_INTERRUPT_RX_INVALID_HDR |
543 AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530544}
Sujith Manoharane270e772012-06-04 16:27:19 +0530545
546void ath_mci_enable(struct ath_softc *sc)
547{
548 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
549
550 if (!common->btcoex_enabled)
551 return;
552
553 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
554 sc->sc_ah->imask |= ATH9K_INT_MCI;
555}