blob: e53df86dfce5c0a76fb21ae8219a078274f16b43 [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
Luis R. Rodriguez6ec414f2011-12-21 09:27:01 -080023static const u8 ath_mci_duty_cycle[] = { 0, 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 Manoharan7dc181c2011-10-24 18:19:49 +0530123 if (num_profile == 1) {
124 info = list_first_entry(&mci->info,
125 struct ath_mci_profile_info,
126 list);
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530127 if (mci->num_sco) {
128 if (info->T == 12)
129 mci->aggr_limit = 8;
130 else if (info->T == 6) {
131 mci->aggr_limit = 6;
132 btcoex->duty_cycle = 30;
133 }
Joe Perchesd2182b62011-12-15 14:55:53 -0800134 ath_dbg(common, MCI,
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530135 "Single SCO, aggregation limit %d 1/4 ms\n",
136 mci->aggr_limit);
137 } else if (mci->num_pan || mci->num_other_acl) {
138 /*
139 * For single PAN/FTP profile, allocate 35% for BT
140 * to improve WLAN throughput.
141 */
142 btcoex->duty_cycle = 35;
143 btcoex->btcoex_period = 53;
Joe Perchesd2182b62011-12-15 14:55:53 -0800144 ath_dbg(common, MCI,
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530145 "Single PAN/FTP bt period %d ms dutycycle %d\n",
146 btcoex->duty_cycle, btcoex->btcoex_period);
147 } else if (mci->num_hid) {
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530148 btcoex->duty_cycle = 30;
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530149 mci->aggr_limit = 6;
Joe Perchesd2182b62011-12-15 14:55:53 -0800150 ath_dbg(common, MCI,
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530151 "Multiple attempt/timeout single HID "
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530152 "aggregation limit 1.5 ms dutycycle 30%%\n");
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530153 }
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530154 } else if (num_profile == 2) {
155 if (mci->num_hid == 2)
156 btcoex->duty_cycle = 30;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530157 mci->aggr_limit = 6;
Joe Perchesd2182b62011-12-15 14:55:53 -0800158 ath_dbg(common, MCI,
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530159 "Two BT profiles aggr limit 1.5 ms dutycycle %d%%\n",
160 btcoex->duty_cycle);
161 } else if (num_profile >= 3) {
162 mci->aggr_limit = 4;
163 ath_dbg(common, MCI,
164 "Three or more profiles aggregation limit 1 ms\n");
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530165 }
166
Rajkumar Manoharan06031432012-06-04 16:28:36 +0530167skip_tuning:
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530168 if (IS_CHAN_2GHZ(sc->sc_ah->curchan)) {
169 if (IS_CHAN_HT(sc->sc_ah->curchan))
170 ath_mci_adjust_aggr_limit(btcoex);
171 else
172 btcoex->btcoex_period >>= 1;
173 }
174
175 ath9k_hw_btcoex_disable(sc->sc_ah);
176 ath9k_btcoex_timer_pause(sc);
177
178 if (IS_CHAN_5GHZ(sc->sc_ah->curchan))
179 return;
180
181 btcoex->duty_cycle += (mci->num_bdr ? ATH_MCI_MAX_DUTY_CYCLE : 0);
182 if (btcoex->duty_cycle > ATH_MCI_MAX_DUTY_CYCLE)
183 btcoex->duty_cycle = ATH_MCI_MAX_DUTY_CYCLE;
184
Rajkumar Manoharandfd05872012-06-11 12:19:37 +0530185 btcoex->btcoex_no_stomp = btcoex->btcoex_period * 1000 *
Sujith Manoharan682dd042012-02-22 14:43:52 +0530186 (100 - btcoex->duty_cycle) / 100;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530187
188 ath9k_hw_btcoex_enable(sc->sc_ah);
189 ath9k_btcoex_timer_resume(sc);
190}
191
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530192static void ath_mci_cal_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload)
193{
194 struct ath_hw *ah = sc->sc_ah;
195 struct ath_common *common = ath9k_hw_common(ah);
196 u32 payload[4] = {0, 0, 0, 0};
197
198 switch (opcode) {
199 case MCI_GPM_BT_CAL_REQ:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530200 if (ar9003_mci_state(ah, MCI_STATE_BT, NULL) == MCI_BT_AWAKE) {
201 ar9003_mci_state(ah, MCI_STATE_SET_BT_CAL_START, NULL);
202 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
Sujith Manoharan682dd042012-02-22 14:43:52 +0530203 } else {
204 ath_dbg(common, MCI, "MCI State mismatch: %d\n",
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530205 ar9003_mci_state(ah, MCI_STATE_BT, NULL));
Sujith Manoharan682dd042012-02-22 14:43:52 +0530206 }
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530207 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530208 case MCI_GPM_BT_CAL_DONE:
Sujith Manoharan682dd042012-02-22 14:43:52 +0530209 ar9003_mci_state(ah, MCI_STATE_BT, NULL);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530210 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530211 case MCI_GPM_BT_CAL_GRANT:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530212 MCI_GPM_SET_CAL_TYPE(payload, MCI_GPM_WLAN_CAL_DONE);
213 ar9003_mci_send_message(sc->sc_ah, MCI_GPM, 0, payload,
214 16, false, true);
215 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530216 default:
Sujith Manoharan682dd042012-02-22 14:43:52 +0530217 ath_dbg(common, MCI, "Unknown GPM CAL message\n");
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530218 break;
219 }
220}
221
Rajkumar Manoharan3c7992e2012-06-12 10:13:53 +0530222static void ath9k_mci_work(struct work_struct *work)
223{
224 struct ath_softc *sc = container_of(work, struct ath_softc, mci_work);
225
226 ath_mci_update_scheme(sc);
227}
228
Felix Fietkaue5f0a272011-12-10 22:11:19 +0100229static void ath_mci_process_profile(struct ath_softc *sc,
230 struct ath_mci_profile_info *info)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530231{
232 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
233 struct ath_btcoex *btcoex = &sc->btcoex;
234 struct ath_mci_profile *mci = &btcoex->mci;
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +0530235 struct ath_mci_profile_info *entry = NULL;
236
237 entry = ath_mci_find_profile(mci, info);
238 if (entry)
239 memcpy(entry, info, 10);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530240
241 if (info->start) {
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +0530242 if (!entry && !ath_mci_add_profile(common, mci, info))
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530243 return;
244 } else
Rajkumar Manoharan9e2e0c82012-06-11 12:19:36 +0530245 ath_mci_del_profile(common, mci, entry);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530246
247 btcoex->btcoex_period = ATH_MCI_DEF_BT_PERIOD;
248 mci->aggr_limit = mci->num_sco ? 6 : 0;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530249
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530250 if (NUM_PROF(mci)) {
251 btcoex->bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
252 btcoex->duty_cycle = ath_mci_duty_cycle[NUM_PROF(mci)];
253 } else {
254 btcoex->bt_stomp_type = mci->num_mgmt ? ATH_BTCOEX_STOMP_ALL :
255 ATH_BTCOEX_STOMP_LOW;
256 btcoex->duty_cycle = ATH_BTCOEX_DEF_DUTY_CYCLE;
257 }
258
Rajkumar Manoharan3c7992e2012-06-12 10:13:53 +0530259 ieee80211_queue_work(sc->hw, &sc->mci_work);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530260}
261
Felix Fietkaue5f0a272011-12-10 22:11:19 +0100262static void ath_mci_process_status(struct ath_softc *sc,
263 struct ath_mci_profile_status *status)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530264{
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530265 struct ath_btcoex *btcoex = &sc->btcoex;
266 struct ath_mci_profile *mci = &btcoex->mci;
267 struct ath_mci_profile_info info;
268 int i = 0, old_num_mgmt = mci->num_mgmt;
269
270 /* Link status type are not handled */
Sujith Manoharan682dd042012-02-22 14:43:52 +0530271 if (status->is_link)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530272 return;
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530273
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530274 info.conn_handle = status->conn_handle;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530275 if (ath_mci_find_profile(mci, &info))
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530276 return;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530277
278 if (status->conn_handle >= ATH_MCI_MAX_PROFILE)
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530279 return;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530280
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530281 if (status->is_critical)
282 __set_bit(status->conn_handle, mci->status);
283 else
284 __clear_bit(status->conn_handle, mci->status);
285
286 mci->num_mgmt = 0;
287 do {
288 if (test_bit(i, mci->status))
289 mci->num_mgmt++;
290 } while (++i < ATH_MCI_MAX_PROFILE);
291
292 if (old_num_mgmt != mci->num_mgmt)
Rajkumar Manoharan3c7992e2012-06-12 10:13:53 +0530293 ieee80211_queue_work(sc->hw, &sc->mci_work);
Rajkumar Manoharan7dc181c2011-10-24 18:19:49 +0530294}
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530295
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530296static void ath_mci_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload)
297{
298 struct ath_hw *ah = sc->sc_ah;
299 struct ath_mci_profile_info profile_info;
300 struct ath_mci_profile_status profile_status;
301 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
302 u32 version;
303 u8 major;
304 u8 minor;
305 u32 seq_num;
306
307 switch (opcode) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530308 case MCI_GPM_COEX_VERSION_QUERY:
Sujith Manoharan682dd042012-02-22 14:43:52 +0530309 version = ar9003_mci_state(ah, MCI_STATE_SEND_WLAN_COEX_VERSION,
310 NULL);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530311 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530312 case MCI_GPM_COEX_VERSION_RESPONSE:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530313 major = *(rx_payload + MCI_GPM_COEX_B_MAJOR_VERSION);
314 minor = *(rx_payload + MCI_GPM_COEX_B_MINOR_VERSION);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530315 version = (major << 8) + minor;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530316 version = ar9003_mci_state(ah, MCI_STATE_SET_BT_COEX_VERSION,
317 &version);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530318 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530319 case MCI_GPM_COEX_STATUS_QUERY:
Sujith Manoharan682dd042012-02-22 14:43:52 +0530320 ar9003_mci_state(ah, MCI_STATE_SEND_WLAN_CHANNELS, NULL);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530321 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530322 case MCI_GPM_COEX_BT_PROFILE_INFO:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530323 memcpy(&profile_info,
324 (rx_payload + MCI_GPM_COEX_B_PROFILE_TYPE), 10);
325
Sujith Manoharan682dd042012-02-22 14:43:52 +0530326 if ((profile_info.type == MCI_GPM_COEX_PROFILE_UNKNOWN) ||
327 (profile_info.type >= MCI_GPM_COEX_PROFILE_MAX)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800328 ath_dbg(common, MCI,
Sujith Manoharan682dd042012-02-22 14:43:52 +0530329 "Illegal profile type = %d, state = %d\n",
Joe Perchesd2182b62011-12-15 14:55:53 -0800330 profile_info.type,
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530331 profile_info.start);
332 break;
333 }
334
335 ath_mci_process_profile(sc, &profile_info);
336 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530337 case MCI_GPM_COEX_BT_STATUS_UPDATE:
338 profile_status.is_link = *(rx_payload +
339 MCI_GPM_COEX_B_STATUS_TYPE);
340 profile_status.conn_handle = *(rx_payload +
341 MCI_GPM_COEX_B_STATUS_LINKID);
342 profile_status.is_critical = *(rx_payload +
343 MCI_GPM_COEX_B_STATUS_STATE);
344
345 seq_num = *((u32 *)(rx_payload + 12));
Joe Perchesd2182b62011-12-15 14:55:53 -0800346 ath_dbg(common, MCI,
Sujith Manoharan682dd042012-02-22 14:43:52 +0530347 "BT_Status_Update: is_link=%d, linkId=%d, state=%d, SEQ=%d\n",
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530348 profile_status.is_link, profile_status.conn_handle,
349 profile_status.is_critical, seq_num);
350
351 ath_mci_process_status(sc, &profile_status);
352 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530353 default:
Sujith Manoharan682dd042012-02-22 14:43:52 +0530354 ath_dbg(common, MCI, "Unknown GPM COEX message = 0x%02x\n", opcode);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530355 break;
356 }
357}
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530358
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530359int ath_mci_setup(struct ath_softc *sc)
360{
361 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
362 struct ath_mci_coex *mci = &sc->mci_coex;
Sujith Manoharanea510e42012-02-22 12:40:09 +0530363 struct ath_mci_buf *buf = &mci->sched_buf;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530364
Sujith Manoharanea510e42012-02-22 12:40:09 +0530365 buf->bf_addr = dma_alloc_coherent(sc->dev,
366 ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE,
367 &buf->bf_paddr, GFP_KERNEL);
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530368
Sujith Manoharanea510e42012-02-22 12:40:09 +0530369 if (buf->bf_addr == NULL) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800370 ath_dbg(common, FATAL, "MCI buffer alloc failed\n");
Sujith Manoharanea510e42012-02-22 12:40:09 +0530371 return -ENOMEM;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530372 }
373
Sujith Manoharanea510e42012-02-22 12:40:09 +0530374 memset(buf->bf_addr, MCI_GPM_RSVD_PATTERN,
375 ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE);
376
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530377 mci->sched_buf.bf_len = ATH_MCI_SCHED_BUF_SIZE;
378
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530379 mci->gpm_buf.bf_len = ATH_MCI_GPM_BUF_SIZE;
Sujith Manoharanea510e42012-02-22 12:40:09 +0530380 mci->gpm_buf.bf_addr = (u8 *)mci->sched_buf.bf_addr + mci->sched_buf.bf_len;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530381 mci->gpm_buf.bf_paddr = mci->sched_buf.bf_paddr + mci->sched_buf.bf_len;
382
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530383 ar9003_mci_setup(sc->sc_ah, mci->gpm_buf.bf_paddr,
384 mci->gpm_buf.bf_addr, (mci->gpm_buf.bf_len >> 4),
385 mci->sched_buf.bf_paddr);
Sujith Manoharanea510e42012-02-22 12:40:09 +0530386
Rajkumar Manoharan3c7992e2012-06-12 10:13:53 +0530387 INIT_WORK(&sc->mci_work, ath9k_mci_work);
Sujith Manoharanea510e42012-02-22 12:40:09 +0530388 ath_dbg(common, MCI, "MCI Initialized\n");
389
390 return 0;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530391}
392
393void ath_mci_cleanup(struct ath_softc *sc)
394{
Sujith Manoharanea510e42012-02-22 12:40:09 +0530395 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530396 struct ath_hw *ah = sc->sc_ah;
397 struct ath_mci_coex *mci = &sc->mci_coex;
Sujith Manoharanea510e42012-02-22 12:40:09 +0530398 struct ath_mci_buf *buf = &mci->sched_buf;
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530399
Sujith Manoharanea510e42012-02-22 12:40:09 +0530400 if (buf->bf_addr)
401 dma_free_coherent(sc->dev,
402 ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE,
403 buf->bf_addr, buf->bf_paddr);
404
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530405 ar9003_mci_cleanup(ah);
Sujith Manoharanea510e42012-02-22 12:40:09 +0530406
407 ath_dbg(common, MCI, "MCI De-Initialized\n");
Mohammed Shafi Shajakhan9e253652011-11-30 10:41:23 +0530408}
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530409
410void ath_mci_intr(struct ath_softc *sc)
411{
412 struct ath_mci_coex *mci = &sc->mci_coex;
413 struct ath_hw *ah = sc->sc_ah;
414 struct ath_common *common = ath9k_hw_common(ah);
415 u32 mci_int, mci_int_rxmsg;
416 u32 offset, subtype, opcode;
417 u32 *pgpm;
418 u32 more_data = MCI_GPM_MORE;
419 bool skip_gpm = false;
420
421 ar9003_mci_get_interrupt(sc->sc_ah, &mci_int, &mci_int_rxmsg);
422
423 if (ar9003_mci_state(ah, MCI_STATE_ENABLE, NULL) == 0) {
Sujith Manoharan682dd042012-02-22 14:43:52 +0530424 ar9003_mci_state(ah, MCI_STATE_INIT_GPM_OFFSET, NULL);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530425 return;
426 }
427
428 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE) {
429 u32 payload[4] = { 0xffffffff, 0xffffffff,
430 0xffffffff, 0xffffff00};
431
432 /*
433 * The following REMOTE_RESET and SYS_WAKING used to sent
434 * only when BT wake up. Now they are always sent, as a
435 * recovery method to reset BT MCI's RX alignment.
436 */
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530437 ar9003_mci_send_message(ah, MCI_REMOTE_RESET, 0,
438 payload, 16, true, false);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530439 ar9003_mci_send_message(ah, MCI_SYS_WAKING, 0,
440 NULL, 0, true, false);
441
442 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE;
443 ar9003_mci_state(ah, MCI_STATE_RESET_REQ_WAKE, NULL);
444
445 /*
446 * always do this for recovery and 2G/5G toggling and LNA_TRANS
447 */
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530448 ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE, NULL);
449 }
450
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530451 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING) {
452 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING;
453
454 if (ar9003_mci_state(ah, MCI_STATE_BT, NULL) == MCI_BT_SLEEP) {
Sujith Manoharan682dd042012-02-22 14:43:52 +0530455 if (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP, NULL) !=
456 MCI_BT_SLEEP)
457 ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE,
458 NULL);
459 }
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530460 }
461
462 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530463 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING;
464
465 if (ar9003_mci_state(ah, MCI_STATE_BT, NULL) == MCI_BT_AWAKE) {
Sujith Manoharan682dd042012-02-22 14:43:52 +0530466 if (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP, NULL) !=
467 MCI_BT_AWAKE)
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530468 ar9003_mci_state(ah, MCI_STATE_SET_BT_SLEEP,
469 NULL);
Sujith Manoharan682dd042012-02-22 14:43:52 +0530470 }
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530471 }
472
473 if ((mci_int & AR_MCI_INTERRUPT_RX_INVALID_HDR) ||
474 (mci_int & AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT)) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530475 ar9003_mci_state(ah, MCI_STATE_RECOVER_RX, NULL);
476 skip_gpm = true;
477 }
478
479 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530480 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO;
481 offset = ar9003_mci_state(ah, MCI_STATE_LAST_SCHD_MSG_OFFSET,
482 NULL);
483 }
484
485 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_GPM) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530486 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_GPM;
487
488 while (more_data == MCI_GPM_MORE) {
489
490 pgpm = mci->gpm_buf.bf_addr;
Sujith Manoharan682dd042012-02-22 14:43:52 +0530491 offset = ar9003_mci_state(ah, MCI_STATE_NEXT_GPM_OFFSET,
492 &more_data);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530493
494 if (offset == MCI_GPM_INVALID)
495 break;
496
497 pgpm += (offset >> 2);
498
499 /*
500 * The first dword is timer.
501 * The real data starts from 2nd dword.
502 */
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530503 subtype = MCI_GPM_TYPE(pgpm);
504 opcode = MCI_GPM_OPCODE(pgpm);
505
Sujith Manoharan682dd042012-02-22 14:43:52 +0530506 if (skip_gpm)
507 goto recycle;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530508
Sujith Manoharan682dd042012-02-22 14:43:52 +0530509 if (MCI_GPM_IS_CAL_TYPE(subtype)) {
510 ath_mci_cal_msg(sc, subtype, (u8 *)pgpm);
511 } else {
512 switch (subtype) {
513 case MCI_GPM_COEX_AGENT:
514 ath_mci_msg(sc, opcode, (u8 *)pgpm);
515 break;
516 default:
517 break;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530518 }
519 }
Sujith Manoharan682dd042012-02-22 14:43:52 +0530520 recycle:
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530521 MCI_GPM_RECYCLE(pgpm);
522 }
523 }
524
525 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_HW_MSG_MASK) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530526 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_LNA_CONTROL)
527 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_LNA_CONTROL;
528
Sujith Manoharan682dd042012-02-22 14:43:52 +0530529 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_LNA_INFO)
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530530 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_LNA_INFO;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530531
532 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_INFO) {
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530533 int value_dbm = ar9003_mci_state(ah,
Sujith Manoharan682dd042012-02-22 14:43:52 +0530534 MCI_STATE_CONT_RSSI_POWER, NULL);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530535
536 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_INFO;
537
538 if (ar9003_mci_state(ah, MCI_STATE_CONT_TXRX, NULL))
Joe Perchesd2182b62011-12-15 14:55:53 -0800539 ath_dbg(common, MCI,
540 "MCI CONT_INFO: (tx) pri = %d, pwr = %d dBm\n",
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530541 ar9003_mci_state(ah,
Sujith Manoharan682dd042012-02-22 14:43:52 +0530542 MCI_STATE_CONT_PRIORITY, NULL),
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530543 value_dbm);
544 else
Joe Perchesd2182b62011-12-15 14:55:53 -0800545 ath_dbg(common, MCI,
546 "MCI CONT_INFO: (rx) pri = %d,pwr = %d dBm\n",
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530547 ar9003_mci_state(ah,
Sujith Manoharan682dd042012-02-22 14:43:52 +0530548 MCI_STATE_CONT_PRIORITY, NULL),
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530549 value_dbm);
550 }
551
Sujith Manoharan682dd042012-02-22 14:43:52 +0530552 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_NACK)
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530553 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_NACK;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530554
Sujith Manoharan682dd042012-02-22 14:43:52 +0530555 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_RST)
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530556 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_RST;
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530557 }
558
559 if ((mci_int & AR_MCI_INTERRUPT_RX_INVALID_HDR) ||
560 (mci_int & AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT))
561 mci_int &= ~(AR_MCI_INTERRUPT_RX_INVALID_HDR |
562 AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530563}
Sujith Manoharane270e772012-06-04 16:27:19 +0530564
565void ath_mci_enable(struct ath_softc *sc)
566{
567 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
568
569 if (!common->btcoex_enabled)
570 return;
571
572 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
573 sc->sc_ah->imask |= ATH9K_INT_MCI;
574}