ssb: extif: fix compile errors
[deliverable/linux.git] / drivers / net / wireless / ath / ath9k / mci.c
CommitLineData
7dc181c2
RM
1/*
2 * Copyright (c) 2010-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
9e25365f
MSS
17#include <linux/dma-mapping.h>
18#include <linux/slab.h>
19
7dc181c2
RM
20#include "ath9k.h"
21#include "mci.h"
22
a197b76c 23static const u8 ath_mci_duty_cycle[] = { 55, 50, 60, 70, 80, 85, 90, 95, 98 };
7dc181c2
RM
24
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
9e2e0c84
RM
31 if (list_empty(&mci->info))
32 return NULL;
33
7dc181c2
RM
34 list_for_each_entry(entry, &mci->info, list) {
35 if (entry->conn_handle == info->conn_handle)
9e2e0c84 36 return entry;
7dc181c2 37 }
9e2e0c84 38 return NULL;
7dc181c2
RM
39}
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;
db60428b 46 u8 voice_priority[] = { 110, 110, 110, 112, 110, 110, 114, 116, 118 };
7dc181c2
RM
47
48 if ((mci->num_sco == ATH_MCI_MAX_SCO_PROFILE) &&
682dd04b 49 (info->type == MCI_GPM_COEX_PROFILE_VOICE))
7dc181c2 50 return false;
7dc181c2
RM
51
52 if (((NUM_PROF(mci) - mci->num_sco) == ATH_MCI_MAX_ACL_PROFILE) &&
682dd04b 53 (info->type != MCI_GPM_COEX_PROFILE_VOICE))
7dc181c2 54 return false;
7dc181c2 55
3c7992e3 56 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
9e2e0c84
RM
57 if (!entry)
58 return false;
7dc181c2 59
9e2e0c84
RM
60 memcpy(entry, info, 10);
61 INC_PROF(mci, info);
62 list_add_tail(&entry->list, &mci->info);
db60428b
RM
63 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 }
682dd04b 69
7dc181c2
RM
70 return true;
71}
72
73static void ath_mci_del_profile(struct ath_common *common,
74 struct ath_mci_profile *mci,
9e2e0c84 75 struct ath_mci_profile_info *entry)
7dc181c2 76{
682dd04b 77 if (!entry)
7dc181c2 78 return;
682dd04b 79
7dc181c2
RM
80 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
9e2e0c84 89 mci->aggr_limit = 0;
d92bb98f 90 mci->num_mgmt = 0;
9e2e0c84
RM
91
92 if (list_empty(&mci->info))
93 return;
94
7dc181c2
RM
95 list_for_each_entry_safe(info, tinfo, &mci->info, list) {
96 list_del(&info->list);
97 DEC_PROF(mci, info);
98 kfree(info);
99 }
7dc181c2
RM
100}
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;
0603143e 124 struct ath9k_hw_mci *mci_hw = &sc->sc_ah->btcoex_hw.mci;
7dc181c2
RM
125 struct ath_mci_profile_info *info;
126 u32 num_profile = NUM_PROF(mci);
127
0603143e
RM
128 if (mci_hw->config & ATH_MCI_CONFIG_DISABLE_TUNING)
129 goto skip_tuning;
130
9e62817b 131 mci->aggr_limit = 0;
a197b76c 132 btcoex->duty_cycle = ath_mci_duty_cycle[num_profile];
9e62817b
RM
133 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;
a197b76c 139
7dc181c2
RM
140 if (num_profile == 1) {
141 info = list_first_entry(&mci->info,
142 struct ath_mci_profile_info,
143 list);
0603143e
RM
144 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;
9e62817b
RM
150 } else
151 mci->aggr_limit = 6;
d2182b69 152 ath_dbg(common, MCI,
0603143e
RM
153 "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 */
f9401b1e 160 btcoex->duty_cycle = AR_SREV_9565(sc->sc_ah) ? 40 : 35;
0603143e 161 btcoex->btcoex_period = 53;
d2182b69 162 ath_dbg(common, MCI,
0603143e
RM
163 "Single PAN/FTP bt period %d ms dutycycle %d\n",
164 btcoex->duty_cycle, btcoex->btcoex_period);
165 } else if (mci->num_hid) {
7dc181c2 166 btcoex->duty_cycle = 30;
0603143e 167 mci->aggr_limit = 6;
d2182b69 168 ath_dbg(common, MCI,
7dc181c2 169 "Multiple attempt/timeout single HID "
0603143e 170 "aggregation limit 1.5 ms dutycycle 30%%\n");
7dc181c2 171 }
0603143e
RM
172 } else if (num_profile == 2) {
173 if (mci->num_hid == 2)
174 btcoex->duty_cycle = 30;
7dc181c2 175 mci->aggr_limit = 6;
d2182b69 176 ath_dbg(common, MCI,
0603143e
RM
177 "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");
7dc181c2
RM
183 }
184
0603143e 185skip_tuning:
7dc181c2
RM
186 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
7dc181c2 193 ath9k_btcoex_timer_pause(sc);
c32cdbd8 194 ath9k_hw_btcoex_disable(sc->sc_ah);
7dc181c2
RM
195
196 if (IS_CHAN_5GHZ(sc->sc_ah->curchan))
197 return;
198
a197b76c 199 btcoex->duty_cycle += (mci->num_bdr ? ATH_MCI_BDR_DUTY_CYCLE : 0);
7dc181c2
RM
200 if (btcoex->duty_cycle > ATH_MCI_MAX_DUTY_CYCLE)
201 btcoex->duty_cycle = ATH_MCI_MAX_DUTY_CYCLE;
202
dfd0587a 203 btcoex->btcoex_no_stomp = btcoex->btcoex_period * 1000 *
682dd04b 204 (100 - btcoex->duty_cycle) / 100;
7dc181c2
RM
205
206 ath9k_hw_btcoex_enable(sc->sc_ah);
207 ath9k_btcoex_timer_resume(sc);
208}
209
19686ddf
MSS
210static 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);
6d97be48 214 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
19686ddf
MSS
215 u32 payload[4] = {0, 0, 0, 0};
216
217 switch (opcode) {
218 case MCI_GPM_BT_CAL_REQ:
6d97be48 219 if (mci_hw->bt_state == MCI_BT_AWAKE) {
4653356f 220 mci_hw->bt_state = MCI_BT_CAL_START;
b88083bf 221 ath9k_queue_reset(sc, RESET_TYPE_MCI);
682dd04b 222 }
6d97be48 223 ath_dbg(common, MCI, "MCI State : %d\n", mci_hw->bt_state);
19686ddf 224 break;
19686ddf 225 case MCI_GPM_BT_CAL_GRANT:
19686ddf
MSS
226 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;
19686ddf 230 default:
682dd04b 231 ath_dbg(common, MCI, "Unknown GPM CAL message\n");
19686ddf
MSS
232 break;
233 }
234}
235
3c7992e3
RM
236static 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
db60428b
RM
243static 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;
260 u8 stomp_txprio[] = { 0, 0, 0, 0 }; /* all, low, none, low_ftp */
261
262 if (mci->num_mgmt) {
263 stomp_txprio[ATH_BTCOEX_STOMP_ALL] = ATH_MCI_INQUIRY_PRIO;
264 if (!mci->num_pan && !mci->num_other_acl)
265 stomp_txprio[ATH_BTCOEX_STOMP_NONE] =
266 ATH_MCI_INQUIRY_PRIO;
267 } else {
268 u8 prof_prio[] = { 50, 90, 94, 52 };/* RFCOMM, A2DP, HID, PAN */
269
270 stomp_txprio[ATH_BTCOEX_STOMP_LOW] =
271 stomp_txprio[ATH_BTCOEX_STOMP_NONE] = 0xff;
272
273 if (mci->num_sco)
274 ath_mci_update_stomp_txprio(mci->voice_priority,
275 stomp_txprio);
276 if (mci->num_other_acl)
277 ath_mci_update_stomp_txprio(prof_prio[0], stomp_txprio);
278 if (mci->num_a2dp)
279 ath_mci_update_stomp_txprio(prof_prio[1], stomp_txprio);
280 if (mci->num_hid)
281 ath_mci_update_stomp_txprio(prof_prio[2], stomp_txprio);
282 if (mci->num_pan)
283 ath_mci_update_stomp_txprio(prof_prio[3], stomp_txprio);
284
285 if (stomp_txprio[ATH_BTCOEX_STOMP_NONE] == 0xff)
286 stomp_txprio[ATH_BTCOEX_STOMP_NONE] = 0;
287
288 if (stomp_txprio[ATH_BTCOEX_STOMP_LOW] == 0xff)
289 stomp_txprio[ATH_BTCOEX_STOMP_LOW] = 0;
290 }
291 ath9k_hw_btcoex_set_concur_txprio(sc->sc_ah, stomp_txprio);
292}
293
7a034146
RM
294static u8 ath_mci_process_profile(struct ath_softc *sc,
295 struct ath_mci_profile_info *info)
7dc181c2
RM
296{
297 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
298 struct ath_btcoex *btcoex = &sc->btcoex;
299 struct ath_mci_profile *mci = &btcoex->mci;
9e2e0c84
RM
300 struct ath_mci_profile_info *entry = NULL;
301
302 entry = ath_mci_find_profile(mci, info);
305dd09f
BS
303 if (entry) {
304 /*
305 * Two MCI interrupts are generated while connecting to
306 * headset and A2DP profile, but only one MCI interrupt
307 * is generated with last added profile type while disconnecting
308 * both profiles.
309 * So while adding second profile type decrement
310 * the first one.
311 */
312 if (entry->type != info->type) {
313 DEC_PROF(mci, entry);
314 INC_PROF(mci, info);
315 }
9e2e0c84 316 memcpy(entry, info, 10);
305dd09f 317 }
7dc181c2
RM
318
319 if (info->start) {
9e2e0c84 320 if (!entry && !ath_mci_add_profile(common, mci, info))
7a034146 321 return 0;
7dc181c2 322 } else
9e2e0c84 323 ath_mci_del_profile(common, mci, entry);
7dc181c2 324
db60428b 325 ath_mci_set_concur_txprio(sc);
7a034146 326 return 1;
7dc181c2
RM
327}
328
7a034146
RM
329static u8 ath_mci_process_status(struct ath_softc *sc,
330 struct ath_mci_profile_status *status)
7dc181c2 331{
7dc181c2
RM
332 struct ath_btcoex *btcoex = &sc->btcoex;
333 struct ath_mci_profile *mci = &btcoex->mci;
334 struct ath_mci_profile_info info;
335 int i = 0, old_num_mgmt = mci->num_mgmt;
336
337 /* Link status type are not handled */
682dd04b 338 if (status->is_link)
7a034146 339 return 0;
7dc181c2 340
7dc181c2 341 info.conn_handle = status->conn_handle;
682dd04b 342 if (ath_mci_find_profile(mci, &info))
7a034146 343 return 0;
682dd04b
SM
344
345 if (status->conn_handle >= ATH_MCI_MAX_PROFILE)
7a034146 346 return 0;
682dd04b 347
7dc181c2
RM
348 if (status->is_critical)
349 __set_bit(status->conn_handle, mci->status);
350 else
351 __clear_bit(status->conn_handle, mci->status);
352
353 mci->num_mgmt = 0;
354 do {
355 if (test_bit(i, mci->status))
356 mci->num_mgmt++;
357 } while (++i < ATH_MCI_MAX_PROFILE);
358
db60428b 359 ath_mci_set_concur_txprio(sc);
7dc181c2 360 if (old_num_mgmt != mci->num_mgmt)
7a034146
RM
361 return 1;
362
363 return 0;
7dc181c2 364}
9e25365f 365
19686ddf
MSS
366static void ath_mci_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload)
367{
368 struct ath_hw *ah = sc->sc_ah;
369 struct ath_mci_profile_info profile_info;
370 struct ath_mci_profile_status profile_status;
371 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
7a034146 372 u8 major, minor, update_scheme = 0;
19686ddf
MSS
373 u32 seq_num;
374
d92bb98f
RM
375 if (ar9003_mci_state(ah, MCI_STATE_NEED_FLUSH_BT_INFO) &&
376 ar9003_mci_state(ah, MCI_STATE_ENABLE)) {
377 ath_dbg(common, MCI, "(MCI) Need to flush BT profiles\n");
378 ath_mci_flush_profile(&sc->btcoex.mci);
379 ar9003_mci_state(ah, MCI_STATE_SEND_STATUS_QUERY);
380 }
381
19686ddf 382 switch (opcode) {
19686ddf 383 case MCI_GPM_COEX_VERSION_QUERY:
b98ccec0 384 ar9003_mci_state(ah, MCI_STATE_SEND_WLAN_COEX_VERSION);
19686ddf 385 break;
19686ddf 386 case MCI_GPM_COEX_VERSION_RESPONSE:
19686ddf
MSS
387 major = *(rx_payload + MCI_GPM_COEX_B_MAJOR_VERSION);
388 minor = *(rx_payload + MCI_GPM_COEX_B_MINOR_VERSION);
e1763d3f 389 ar9003_mci_set_bt_version(ah, major, minor);
19686ddf 390 break;
19686ddf 391 case MCI_GPM_COEX_STATUS_QUERY:
2d340ac8 392 ar9003_mci_send_wlan_channels(ah);
19686ddf 393 break;
19686ddf 394 case MCI_GPM_COEX_BT_PROFILE_INFO:
19686ddf
MSS
395 memcpy(&profile_info,
396 (rx_payload + MCI_GPM_COEX_B_PROFILE_TYPE), 10);
397
682dd04b
SM
398 if ((profile_info.type == MCI_GPM_COEX_PROFILE_UNKNOWN) ||
399 (profile_info.type >= MCI_GPM_COEX_PROFILE_MAX)) {
d2182b69 400 ath_dbg(common, MCI,
682dd04b 401 "Illegal profile type = %d, state = %d\n",
d2182b69 402 profile_info.type,
19686ddf
MSS
403 profile_info.start);
404 break;
405 }
406
7a034146 407 update_scheme += ath_mci_process_profile(sc, &profile_info);
19686ddf 408 break;
19686ddf
MSS
409 case MCI_GPM_COEX_BT_STATUS_UPDATE:
410 profile_status.is_link = *(rx_payload +
411 MCI_GPM_COEX_B_STATUS_TYPE);
412 profile_status.conn_handle = *(rx_payload +
413 MCI_GPM_COEX_B_STATUS_LINKID);
414 profile_status.is_critical = *(rx_payload +
415 MCI_GPM_COEX_B_STATUS_STATE);
416
417 seq_num = *((u32 *)(rx_payload + 12));
d2182b69 418 ath_dbg(common, MCI,
d8fffb4a 419 "BT_Status_Update: is_link=%d, linkId=%d, state=%d, SEQ=%u\n",
19686ddf
MSS
420 profile_status.is_link, profile_status.conn_handle,
421 profile_status.is_critical, seq_num);
422
7a034146 423 update_scheme += ath_mci_process_status(sc, &profile_status);
19686ddf 424 break;
19686ddf 425 default:
682dd04b 426 ath_dbg(common, MCI, "Unknown GPM COEX message = 0x%02x\n", opcode);
19686ddf
MSS
427 break;
428 }
7a034146
RM
429 if (update_scheme)
430 ieee80211_queue_work(sc->hw, &sc->mci_work);
19686ddf 431}
9e25365f 432
9e25365f
MSS
433int ath_mci_setup(struct ath_softc *sc)
434{
435 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
436 struct ath_mci_coex *mci = &sc->mci_coex;
ea510e4b 437 struct ath_mci_buf *buf = &mci->sched_buf;
69c6ac60 438 int ret;
9e25365f 439
ea510e4b
SM
440 buf->bf_addr = dma_alloc_coherent(sc->dev,
441 ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE,
442 &buf->bf_paddr, GFP_KERNEL);
9e25365f 443
ea510e4b 444 if (buf->bf_addr == NULL) {
d2182b69 445 ath_dbg(common, FATAL, "MCI buffer alloc failed\n");
ea510e4b 446 return -ENOMEM;
9e25365f
MSS
447 }
448
ea510e4b
SM
449 memset(buf->bf_addr, MCI_GPM_RSVD_PATTERN,
450 ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE);
9e25365f 451
ea510e4b 452 mci->sched_buf.bf_len = ATH_MCI_SCHED_BUF_SIZE;
9e25365f
MSS
453
454 mci->gpm_buf.bf_len = ATH_MCI_GPM_BUF_SIZE;
ea510e4b 455 mci->gpm_buf.bf_addr = (u8 *)mci->sched_buf.bf_addr + mci->sched_buf.bf_len;
9e25365f
MSS
456 mci->gpm_buf.bf_paddr = mci->sched_buf.bf_paddr + mci->sched_buf.bf_len;
457
69c6ac60
SM
458 ret = ar9003_mci_setup(sc->sc_ah, mci->gpm_buf.bf_paddr,
459 mci->gpm_buf.bf_addr, (mci->gpm_buf.bf_len >> 4),
460 mci->sched_buf.bf_paddr);
461 if (ret) {
462 ath_err(common, "Failed to initialize MCI\n");
463 return ret;
464 }
ea510e4b 465
3c7992e3 466 INIT_WORK(&sc->mci_work, ath9k_mci_work);
ea510e4b
SM
467 ath_dbg(common, MCI, "MCI Initialized\n");
468
469 return 0;
9e25365f
MSS
470}
471
472void ath_mci_cleanup(struct ath_softc *sc)
473{
ea510e4b 474 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
9e25365f
MSS
475 struct ath_hw *ah = sc->sc_ah;
476 struct ath_mci_coex *mci = &sc->mci_coex;
ea510e4b 477 struct ath_mci_buf *buf = &mci->sched_buf;
9e25365f 478
ea510e4b
SM
479 if (buf->bf_addr)
480 dma_free_coherent(sc->dev,
481 ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE,
482 buf->bf_addr, buf->bf_paddr);
483
9e25365f 484 ar9003_mci_cleanup(ah);
ea510e4b
SM
485
486 ath_dbg(common, MCI, "MCI De-Initialized\n");
9e25365f 487}
19686ddf
MSS
488
489void ath_mci_intr(struct ath_softc *sc)
490{
491 struct ath_mci_coex *mci = &sc->mci_coex;
492 struct ath_hw *ah = sc->sc_ah;
493 struct ath_common *common = ath9k_hw_common(ah);
6d97be48 494 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
19686ddf
MSS
495 u32 mci_int, mci_int_rxmsg;
496 u32 offset, subtype, opcode;
497 u32 *pgpm;
498 u32 more_data = MCI_GPM_MORE;
499 bool skip_gpm = false;
500
501 ar9003_mci_get_interrupt(sc->sc_ah, &mci_int, &mci_int_rxmsg);
502
b98ccec0 503 if (ar9003_mci_state(ah, MCI_STATE_ENABLE) == 0) {
506847ad 504 ar9003_mci_get_next_gpm_offset(ah, true, NULL);
19686ddf
MSS
505 return;
506 }
507
508 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE) {
509 u32 payload[4] = { 0xffffffff, 0xffffffff,
510 0xffffffff, 0xffffff00};
511
512 /*
513 * The following REMOTE_RESET and SYS_WAKING used to sent
514 * only when BT wake up. Now they are always sent, as a
515 * recovery method to reset BT MCI's RX alignment.
516 */
19686ddf
MSS
517 ar9003_mci_send_message(ah, MCI_REMOTE_RESET, 0,
518 payload, 16, true, false);
19686ddf
MSS
519 ar9003_mci_send_message(ah, MCI_SYS_WAKING, 0,
520 NULL, 0, true, false);
521
522 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE;
b98ccec0 523 ar9003_mci_state(ah, MCI_STATE_RESET_REQ_WAKE);
19686ddf
MSS
524
525 /*
526 * always do this for recovery and 2G/5G toggling and LNA_TRANS
527 */
b98ccec0 528 ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE);
19686ddf
MSS
529 }
530
19686ddf
MSS
531 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING) {
532 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING;
533
6d97be48 534 if ((mci_hw->bt_state == MCI_BT_SLEEP) &&
b98ccec0
RM
535 (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP) !=
536 MCI_BT_SLEEP))
537 ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE);
19686ddf
MSS
538 }
539
540 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING) {
19686ddf
MSS
541 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING;
542
6d97be48 543 if ((mci_hw->bt_state == MCI_BT_AWAKE) &&
b98ccec0
RM
544 (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP) !=
545 MCI_BT_AWAKE))
9330969b 546 mci_hw->bt_state = MCI_BT_SLEEP;
19686ddf
MSS
547 }
548
549 if ((mci_int & AR_MCI_INTERRUPT_RX_INVALID_HDR) ||
550 (mci_int & AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT)) {
b98ccec0 551 ar9003_mci_state(ah, MCI_STATE_RECOVER_RX);
19686ddf
MSS
552 skip_gpm = true;
553 }
554
555 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO) {
19686ddf 556 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO;
b98ccec0 557 offset = ar9003_mci_state(ah, MCI_STATE_LAST_SCHD_MSG_OFFSET);
19686ddf
MSS
558 }
559
560 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_GPM) {
19686ddf
MSS
561 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_GPM;
562
563 while (more_data == MCI_GPM_MORE) {
b88083bf
RM
564 if (test_bit(SC_OP_HW_RESET, &sc->sc_flags))
565 return;
19686ddf
MSS
566
567 pgpm = mci->gpm_buf.bf_addr;
506847ad
RM
568 offset = ar9003_mci_get_next_gpm_offset(ah, false,
569 &more_data);
19686ddf
MSS
570
571 if (offset == MCI_GPM_INVALID)
572 break;
573
574 pgpm += (offset >> 2);
575
576 /*
577 * The first dword is timer.
578 * The real data starts from 2nd dword.
579 */
19686ddf
MSS
580 subtype = MCI_GPM_TYPE(pgpm);
581 opcode = MCI_GPM_OPCODE(pgpm);
582
682dd04b
SM
583 if (skip_gpm)
584 goto recycle;
585
586 if (MCI_GPM_IS_CAL_TYPE(subtype)) {
587 ath_mci_cal_msg(sc, subtype, (u8 *)pgpm);
588 } else {
589 switch (subtype) {
590 case MCI_GPM_COEX_AGENT:
591 ath_mci_msg(sc, opcode, (u8 *)pgpm);
592 break;
593 default:
594 break;
19686ddf
MSS
595 }
596 }
682dd04b 597 recycle:
19686ddf
MSS
598 MCI_GPM_RECYCLE(pgpm);
599 }
600 }
601
602 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_HW_MSG_MASK) {
19686ddf
MSS
603 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_LNA_CONTROL)
604 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_LNA_CONTROL;
605
682dd04b 606 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_LNA_INFO)
19686ddf 607 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_LNA_INFO;
19686ddf
MSS
608
609 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_INFO) {
26e942b7
RM
610 int value_dbm = MS(mci_hw->cont_status,
611 AR_MCI_CONT_RSSI_POWER);
19686ddf
MSS
612
613 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_INFO;
614
26e942b7
RM
615 ath_dbg(common, MCI,
616 "MCI CONT_INFO: (%s) pri = %d pwr = %d dBm\n",
617 MS(mci_hw->cont_status, AR_MCI_CONT_TXRX) ?
618 "tx" : "rx",
619 MS(mci_hw->cont_status, AR_MCI_CONT_PRIORITY),
620 value_dbm);
19686ddf
MSS
621 }
622
682dd04b 623 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_NACK)
19686ddf 624 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_NACK;
19686ddf 625
682dd04b 626 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_RST)
19686ddf 627 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_RST;
19686ddf
MSS
628 }
629
630 if ((mci_int & AR_MCI_INTERRUPT_RX_INVALID_HDR) ||
d92bb98f 631 (mci_int & AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT)) {
19686ddf
MSS
632 mci_int &= ~(AR_MCI_INTERRUPT_RX_INVALID_HDR |
633 AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT);
d92bb98f
RM
634 ath_mci_msg(sc, MCI_GPM_COEX_NOOP, NULL);
635 }
19686ddf 636}
e270e776
SM
637
638void ath_mci_enable(struct ath_softc *sc)
639{
640 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
641
642 if (!common->btcoex_enabled)
643 return;
644
645 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
646 sc->sc_ah->imask |= ATH9K_INT_MCI;
647}
50072ebc
RM
648
649void ath9k_mci_update_wlan_channels(struct ath_softc *sc, bool allow_all)
650{
651 struct ath_hw *ah = sc->sc_ah;
652 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
653 struct ath9k_channel *chan = ah->curchan;
654 u32 channelmap[] = {0x00000000, 0xffff0000, 0xffffffff, 0x7fffffff};
655 int i;
656 s16 chan_start, chan_end;
657 u16 wlan_chan;
658
659 if (!chan || !IS_CHAN_2GHZ(chan))
660 return;
661
662 if (allow_all)
663 goto send_wlan_chan;
664
665 wlan_chan = chan->channel - 2402;
666
667 chan_start = wlan_chan - 10;
668 chan_end = wlan_chan + 10;
669
670 if (chan->chanmode == CHANNEL_G_HT40PLUS)
671 chan_end += 20;
672 else if (chan->chanmode == CHANNEL_G_HT40MINUS)
673 chan_start -= 20;
674
675 /* adjust side band */
676 chan_start -= 7;
677 chan_end += 7;
678
679 if (chan_start <= 0)
680 chan_start = 0;
681 if (chan_end >= ATH_MCI_NUM_BT_CHANNELS)
682 chan_end = ATH_MCI_NUM_BT_CHANNELS - 1;
683
684 ath_dbg(ath9k_hw_common(ah), MCI,
685 "WLAN current channel %d mask BT channel %d - %d\n",
686 wlan_chan, chan_start, chan_end);
687
688 for (i = chan_start; i < chan_end; i++)
689 MCI_GPM_CLR_CHANNEL_BIT(&channelmap, i);
690
691send_wlan_chan:
692 /* update and send wlan channels info to BT */
693 for (i = 0; i < 4; i++)
694 mci->wlan_channels[i] = channelmap[i];
695 ar9003_mci_send_wlan_channels(ah);
696 ar9003_mci_state(ah, MCI_STATE_SEND_VERSION_QUERY);
697}
e82cb03f
RM
698
699void ath9k_mci_set_txpower(struct ath_softc *sc, bool setchannel,
700 bool concur_tx)
701{
702 struct ath_hw *ah = sc->sc_ah;
703 struct ath9k_hw_mci *mci_hw = &sc->sc_ah->btcoex_hw.mci;
704 bool old_concur_tx = mci_hw->concur_tx;
705
706 if (!(mci_hw->config & ATH_MCI_CONFIG_CONCUR_TX)) {
707 mci_hw->concur_tx = false;
708 return;
709 }
710
711 if (!IS_CHAN_2GHZ(ah->curchan))
712 return;
713
714 if (setchannel) {
715 struct ath9k_hw_cal_data *caldata = &sc->caldata;
716 if ((caldata->chanmode == CHANNEL_G_HT40PLUS) &&
717 (ah->curchan->channel > caldata->channel) &&
718 (ah->curchan->channel <= caldata->channel + 20))
719 return;
720 if ((caldata->chanmode == CHANNEL_G_HT40MINUS) &&
721 (ah->curchan->channel < caldata->channel) &&
722 (ah->curchan->channel >= caldata->channel - 20))
723 return;
724 mci_hw->concur_tx = false;
725 } else
726 mci_hw->concur_tx = concur_tx;
727
728 if (old_concur_tx != mci_hw->concur_tx)
729 ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit, false);
730}
731
2884561a
RM
732static void ath9k_mci_stomp_audio(struct ath_softc *sc)
733{
734 struct ath_hw *ah = sc->sc_ah;
735 struct ath_btcoex *btcoex = &sc->btcoex;
736 struct ath_mci_profile *mci = &btcoex->mci;
737
738 if (!mci->num_sco && !mci->num_a2dp)
739 return;
740
741 if (ah->stats.avgbrssi > 25) {
742 btcoex->stomp_audio = 0;
743 return;
744 }
745
746 btcoex->stomp_audio++;
747}
e82cb03f
RM
748void ath9k_mci_update_rssi(struct ath_softc *sc)
749{
750 struct ath_hw *ah = sc->sc_ah;
751 struct ath_btcoex *btcoex = &sc->btcoex;
752 struct ath9k_hw_mci *mci_hw = &sc->sc_ah->btcoex_hw.mci;
753
2884561a
RM
754 ath9k_mci_stomp_audio(sc);
755
e82cb03f
RM
756 if (!(mci_hw->config & ATH_MCI_CONFIG_CONCUR_TX))
757 return;
758
759 if (ah->stats.avgbrssi >= 40) {
760 if (btcoex->rssi_count < 0)
761 btcoex->rssi_count = 0;
762 if (++btcoex->rssi_count >= ATH_MCI_CONCUR_TX_SWITCH) {
763 btcoex->rssi_count = 0;
764 ath9k_mci_set_txpower(sc, false, true);
765 }
766 } else {
767 if (btcoex->rssi_count > 0)
768 btcoex->rssi_count = 0;
769 if (--btcoex->rssi_count <= -ATH_MCI_CONCUR_TX_SWITCH) {
770 btcoex->rssi_count = 0;
771 ath9k_mci_set_txpower(sc, false, false);
772 }
773 }
774}
This page took 0.223917 seconds and 5 git commands to generate.