Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 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 | |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 17 | #include <linux/dma-mapping.h> |
| 18 | #include <linux/slab.h> |
| 19 | |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 20 | #include "ath9k.h" |
| 21 | #include "mci.h" |
| 22 | |
Luis R. Rodriguez | 6ec414f | 2011-12-21 09:27:01 -0800 | [diff] [blame] | 23 | static const u8 ath_mci_duty_cycle[] = { 0, 50, 60, 70, 80, 85, 90, 95, 98 }; |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 24 | |
| 25 | static struct ath_mci_profile_info* |
| 26 | ath_mci_find_profile(struct ath_mci_profile *mci, |
| 27 | struct ath_mci_profile_info *info) |
| 28 | { |
| 29 | struct ath_mci_profile_info *entry; |
| 30 | |
| 31 | list_for_each_entry(entry, &mci->info, list) { |
| 32 | if (entry->conn_handle == info->conn_handle) |
| 33 | break; |
| 34 | } |
| 35 | return entry; |
| 36 | } |
| 37 | |
| 38 | static bool ath_mci_add_profile(struct ath_common *common, |
| 39 | struct ath_mci_profile *mci, |
| 40 | struct ath_mci_profile_info *info) |
| 41 | { |
| 42 | struct ath_mci_profile_info *entry; |
| 43 | |
| 44 | if ((mci->num_sco == ATH_MCI_MAX_SCO_PROFILE) && |
| 45 | (info->type == MCI_GPM_COEX_PROFILE_VOICE)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 46 | ath_dbg(common, MCI, |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 47 | "Too many SCO profile, failed to add new profile\n"); |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | if (((NUM_PROF(mci) - mci->num_sco) == ATH_MCI_MAX_ACL_PROFILE) && |
| 52 | (info->type != MCI_GPM_COEX_PROFILE_VOICE)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 53 | ath_dbg(common, MCI, |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 54 | "Too many ACL profile, failed to add new profile\n"); |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | entry = ath_mci_find_profile(mci, info); |
| 59 | |
| 60 | if (entry) |
| 61 | memcpy(entry, info, 10); |
| 62 | else { |
| 63 | entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
| 64 | if (!entry) |
| 65 | return false; |
| 66 | |
| 67 | memcpy(entry, info, 10); |
| 68 | INC_PROF(mci, info); |
| 69 | list_add_tail(&info->list, &mci->info); |
| 70 | } |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | static void ath_mci_del_profile(struct ath_common *common, |
| 75 | struct ath_mci_profile *mci, |
| 76 | struct ath_mci_profile_info *info) |
| 77 | { |
| 78 | struct ath_mci_profile_info *entry; |
| 79 | |
| 80 | entry = ath_mci_find_profile(mci, info); |
| 81 | |
| 82 | if (!entry) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 83 | ath_dbg(common, MCI, "Profile to be deleted not found\n"); |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 84 | return; |
| 85 | } |
| 86 | DEC_PROF(mci, entry); |
| 87 | list_del(&entry->list); |
| 88 | kfree(entry); |
| 89 | } |
| 90 | |
| 91 | void ath_mci_flush_profile(struct ath_mci_profile *mci) |
| 92 | { |
| 93 | struct ath_mci_profile_info *info, *tinfo; |
| 94 | |
| 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 | } |
| 100 | mci->aggr_limit = 0; |
| 101 | } |
| 102 | |
| 103 | static void ath_mci_adjust_aggr_limit(struct ath_btcoex *btcoex) |
| 104 | { |
| 105 | struct ath_mci_profile *mci = &btcoex->mci; |
| 106 | u32 wlan_airtime = btcoex->btcoex_period * |
| 107 | (100 - btcoex->duty_cycle) / 100; |
| 108 | |
| 109 | /* |
| 110 | * Scale: wlan_airtime is in ms, aggr_limit is in 0.25 ms. |
| 111 | * When wlan_airtime is less than 4ms, aggregation limit has to be |
| 112 | * adjusted half of wlan_airtime to ensure that the aggregation can fit |
| 113 | * without collision with BT traffic. |
| 114 | */ |
| 115 | if ((wlan_airtime <= 4) && |
| 116 | (!mci->aggr_limit || (mci->aggr_limit > (2 * wlan_airtime)))) |
| 117 | mci->aggr_limit = 2 * wlan_airtime; |
| 118 | } |
| 119 | |
| 120 | static void ath_mci_update_scheme(struct ath_softc *sc) |
| 121 | { |
| 122 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 123 | struct ath_btcoex *btcoex = &sc->btcoex; |
| 124 | struct ath_mci_profile *mci = &btcoex->mci; |
| 125 | struct ath_mci_profile_info *info; |
| 126 | u32 num_profile = NUM_PROF(mci); |
| 127 | |
| 128 | if (num_profile == 1) { |
| 129 | info = list_first_entry(&mci->info, |
| 130 | struct ath_mci_profile_info, |
| 131 | list); |
| 132 | if (mci->num_sco && info->T == 12) { |
| 133 | mci->aggr_limit = 8; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 134 | ath_dbg(common, MCI, |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 135 | "Single SCO, aggregation limit 2 ms\n"); |
| 136 | } else if ((info->type == MCI_GPM_COEX_PROFILE_BNEP) && |
| 137 | !info->master) { |
| 138 | btcoex->btcoex_period = 60; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 139 | ath_dbg(common, MCI, |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 140 | "Single slave PAN/FTP, bt period 60 ms\n"); |
| 141 | } else if ((info->type == MCI_GPM_COEX_PROFILE_HID) && |
| 142 | (info->T > 0 && info->T < 50) && |
| 143 | (info->A > 1 || info->W > 1)) { |
| 144 | btcoex->duty_cycle = 30; |
| 145 | mci->aggr_limit = 8; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 146 | ath_dbg(common, MCI, |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 147 | "Multiple attempt/timeout single HID " |
| 148 | "aggregation limit 2 ms dutycycle 30%%\n"); |
| 149 | } |
| 150 | } else if ((num_profile == 2) && (mci->num_hid == 2)) { |
| 151 | btcoex->duty_cycle = 30; |
| 152 | mci->aggr_limit = 8; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 153 | ath_dbg(common, MCI, |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 154 | "Two HIDs aggregation limit 2 ms dutycycle 30%%\n"); |
| 155 | } else if (num_profile > 3) { |
| 156 | mci->aggr_limit = 6; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 157 | ath_dbg(common, MCI, |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 158 | "Three or more profiles aggregation limit 1.5 ms\n"); |
| 159 | } |
| 160 | |
| 161 | if (IS_CHAN_2GHZ(sc->sc_ah->curchan)) { |
| 162 | if (IS_CHAN_HT(sc->sc_ah->curchan)) |
| 163 | ath_mci_adjust_aggr_limit(btcoex); |
| 164 | else |
| 165 | btcoex->btcoex_period >>= 1; |
| 166 | } |
| 167 | |
| 168 | ath9k_hw_btcoex_disable(sc->sc_ah); |
| 169 | ath9k_btcoex_timer_pause(sc); |
| 170 | |
| 171 | if (IS_CHAN_5GHZ(sc->sc_ah->curchan)) |
| 172 | return; |
| 173 | |
| 174 | btcoex->duty_cycle += (mci->num_bdr ? ATH_MCI_MAX_DUTY_CYCLE : 0); |
| 175 | if (btcoex->duty_cycle > ATH_MCI_MAX_DUTY_CYCLE) |
| 176 | btcoex->duty_cycle = ATH_MCI_MAX_DUTY_CYCLE; |
| 177 | |
| 178 | btcoex->btcoex_period *= 1000; |
| 179 | btcoex->btcoex_no_stomp = btcoex->btcoex_period * |
| 180 | (100 - btcoex->duty_cycle) / 100; |
| 181 | |
| 182 | ath9k_hw_btcoex_enable(sc->sc_ah); |
| 183 | ath9k_btcoex_timer_resume(sc); |
| 184 | } |
| 185 | |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 186 | |
| 187 | static void ath_mci_cal_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload) |
| 188 | { |
| 189 | struct ath_hw *ah = sc->sc_ah; |
| 190 | struct ath_common *common = ath9k_hw_common(ah); |
| 191 | u32 payload[4] = {0, 0, 0, 0}; |
| 192 | |
| 193 | switch (opcode) { |
| 194 | case MCI_GPM_BT_CAL_REQ: |
| 195 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 196 | ath_dbg(common, MCI, "MCI received BT_CAL_REQ\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 197 | |
| 198 | if (ar9003_mci_state(ah, MCI_STATE_BT, NULL) == MCI_BT_AWAKE) { |
| 199 | ar9003_mci_state(ah, MCI_STATE_SET_BT_CAL_START, NULL); |
| 200 | ieee80211_queue_work(sc->hw, &sc->hw_reset_work); |
| 201 | } else |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 202 | ath_dbg(common, MCI, "MCI State mismatches: %d\n", |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 203 | ar9003_mci_state(ah, MCI_STATE_BT, NULL)); |
| 204 | |
| 205 | break; |
| 206 | |
| 207 | case MCI_GPM_BT_CAL_DONE: |
| 208 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 209 | ath_dbg(common, MCI, "MCI received BT_CAL_DONE\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 210 | |
| 211 | if (ar9003_mci_state(ah, MCI_STATE_BT, NULL) == MCI_BT_CAL) |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 212 | ath_dbg(common, MCI, "MCI error illegal!\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 213 | else |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 214 | ath_dbg(common, MCI, "MCI BT not in CAL state\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 215 | |
| 216 | break; |
| 217 | |
| 218 | case MCI_GPM_BT_CAL_GRANT: |
| 219 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 220 | ath_dbg(common, MCI, "MCI received BT_CAL_GRANT\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 221 | |
| 222 | /* Send WLAN_CAL_DONE for now */ |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 223 | ath_dbg(common, MCI, "MCI send WLAN_CAL_DONE\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 224 | MCI_GPM_SET_CAL_TYPE(payload, MCI_GPM_WLAN_CAL_DONE); |
| 225 | ar9003_mci_send_message(sc->sc_ah, MCI_GPM, 0, payload, |
| 226 | 16, false, true); |
| 227 | break; |
| 228 | |
| 229 | default: |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 230 | ath_dbg(common, MCI, "MCI Unknown GPM CAL message\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 231 | break; |
| 232 | } |
| 233 | } |
| 234 | |
Felix Fietkau | e5f0a27 | 2011-12-10 22:11:19 +0100 | [diff] [blame] | 235 | static void ath_mci_process_profile(struct ath_softc *sc, |
| 236 | struct ath_mci_profile_info *info) |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 237 | { |
| 238 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 239 | struct ath_btcoex *btcoex = &sc->btcoex; |
| 240 | struct ath_mci_profile *mci = &btcoex->mci; |
| 241 | |
| 242 | if (info->start) { |
| 243 | if (!ath_mci_add_profile(common, mci, info)) |
| 244 | return; |
| 245 | } else |
| 246 | ath_mci_del_profile(common, mci, info); |
| 247 | |
| 248 | btcoex->btcoex_period = ATH_MCI_DEF_BT_PERIOD; |
| 249 | mci->aggr_limit = mci->num_sco ? 6 : 0; |
| 250 | 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 | |
| 259 | ath_mci_update_scheme(sc); |
| 260 | } |
| 261 | |
Felix Fietkau | e5f0a27 | 2011-12-10 22:11:19 +0100 | [diff] [blame] | 262 | static void ath_mci_process_status(struct ath_softc *sc, |
| 263 | struct ath_mci_profile_status *status) |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 264 | { |
| 265 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 266 | struct ath_btcoex *btcoex = &sc->btcoex; |
| 267 | struct ath_mci_profile *mci = &btcoex->mci; |
| 268 | struct ath_mci_profile_info info; |
| 269 | int i = 0, old_num_mgmt = mci->num_mgmt; |
| 270 | |
| 271 | /* Link status type are not handled */ |
| 272 | if (status->is_link) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 273 | ath_dbg(common, MCI, "Skip link type status update\n"); |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 274 | return; |
| 275 | } |
| 276 | |
| 277 | memset(&info, 0, sizeof(struct ath_mci_profile_info)); |
| 278 | |
| 279 | info.conn_handle = status->conn_handle; |
| 280 | if (ath_mci_find_profile(mci, &info)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 281 | ath_dbg(common, MCI, |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 282 | "Skip non link state update for existing profile %d\n", |
| 283 | status->conn_handle); |
| 284 | return; |
| 285 | } |
| 286 | if (status->conn_handle >= ATH_MCI_MAX_PROFILE) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 287 | ath_dbg(common, MCI, "Ignore too many non-link update\n"); |
Rajkumar Manoharan | 7dc181c | 2011-10-24 18:19:49 +0530 | [diff] [blame] | 288 | return; |
| 289 | } |
| 290 | if (status->is_critical) |
| 291 | __set_bit(status->conn_handle, mci->status); |
| 292 | else |
| 293 | __clear_bit(status->conn_handle, mci->status); |
| 294 | |
| 295 | mci->num_mgmt = 0; |
| 296 | do { |
| 297 | if (test_bit(i, mci->status)) |
| 298 | mci->num_mgmt++; |
| 299 | } while (++i < ATH_MCI_MAX_PROFILE); |
| 300 | |
| 301 | if (old_num_mgmt != mci->num_mgmt) |
| 302 | ath_mci_update_scheme(sc); |
| 303 | } |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 304 | |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 305 | static void ath_mci_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload) |
| 306 | { |
| 307 | struct ath_hw *ah = sc->sc_ah; |
| 308 | struct ath_mci_profile_info profile_info; |
| 309 | struct ath_mci_profile_status profile_status; |
| 310 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 311 | u32 version; |
| 312 | u8 major; |
| 313 | u8 minor; |
| 314 | u32 seq_num; |
| 315 | |
| 316 | switch (opcode) { |
| 317 | |
| 318 | case MCI_GPM_COEX_VERSION_QUERY: |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 319 | ath_dbg(common, MCI, "MCI Recv GPM COEX Version Query\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 320 | version = ar9003_mci_state(ah, |
| 321 | MCI_STATE_SEND_WLAN_COEX_VERSION, NULL); |
| 322 | break; |
| 323 | |
| 324 | case MCI_GPM_COEX_VERSION_RESPONSE: |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 325 | ath_dbg(common, MCI, "MCI Recv GPM COEX Version Response\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 326 | major = *(rx_payload + MCI_GPM_COEX_B_MAJOR_VERSION); |
| 327 | minor = *(rx_payload + MCI_GPM_COEX_B_MINOR_VERSION); |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 328 | ath_dbg(common, MCI, "MCI BT Coex version: %d.%d\n", |
| 329 | major, minor); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 330 | version = (major << 8) + minor; |
| 331 | version = ar9003_mci_state(ah, |
| 332 | MCI_STATE_SET_BT_COEX_VERSION, &version); |
| 333 | break; |
| 334 | |
| 335 | case MCI_GPM_COEX_STATUS_QUERY: |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 336 | ath_dbg(common, MCI, |
| 337 | "MCI Recv GPM COEX Status Query = 0x%02x\n", |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 338 | *(rx_payload + MCI_GPM_COEX_B_WLAN_BITMAP)); |
| 339 | ar9003_mci_state(ah, |
| 340 | MCI_STATE_SEND_WLAN_CHANNELS, NULL); |
| 341 | break; |
| 342 | |
| 343 | case MCI_GPM_COEX_BT_PROFILE_INFO: |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 344 | ath_dbg(common, MCI, "MCI Recv GPM Coex BT profile info\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 345 | memcpy(&profile_info, |
| 346 | (rx_payload + MCI_GPM_COEX_B_PROFILE_TYPE), 10); |
| 347 | |
| 348 | if ((profile_info.type == MCI_GPM_COEX_PROFILE_UNKNOWN) |
| 349 | || (profile_info.type >= |
| 350 | MCI_GPM_COEX_PROFILE_MAX)) { |
| 351 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 352 | ath_dbg(common, MCI, |
| 353 | "illegal profile type = %d, state = %d\n", |
| 354 | profile_info.type, |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 355 | profile_info.start); |
| 356 | break; |
| 357 | } |
| 358 | |
| 359 | ath_mci_process_profile(sc, &profile_info); |
| 360 | break; |
| 361 | |
| 362 | case MCI_GPM_COEX_BT_STATUS_UPDATE: |
| 363 | profile_status.is_link = *(rx_payload + |
| 364 | MCI_GPM_COEX_B_STATUS_TYPE); |
| 365 | profile_status.conn_handle = *(rx_payload + |
| 366 | MCI_GPM_COEX_B_STATUS_LINKID); |
| 367 | profile_status.is_critical = *(rx_payload + |
| 368 | MCI_GPM_COEX_B_STATUS_STATE); |
| 369 | |
| 370 | seq_num = *((u32 *)(rx_payload + 12)); |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 371 | ath_dbg(common, MCI, |
| 372 | "MCI Recv GPM COEX BT_Status_Update: is_link=%d, linkId=%d, state=%d, SEQ=%d\n", |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 373 | profile_status.is_link, profile_status.conn_handle, |
| 374 | profile_status.is_critical, seq_num); |
| 375 | |
| 376 | ath_mci_process_status(sc, &profile_status); |
| 377 | break; |
| 378 | |
| 379 | default: |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 380 | ath_dbg(common, MCI, "MCI Unknown GPM COEX message = 0x%02x\n", |
| 381 | opcode); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 382 | break; |
| 383 | } |
| 384 | } |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 385 | |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 386 | int ath_mci_setup(struct ath_softc *sc) |
| 387 | { |
| 388 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 389 | struct ath_mci_coex *mci = &sc->mci_coex; |
Sujith Manoharan | ea510e4 | 2012-02-22 12:40:09 +0530 | [diff] [blame^] | 390 | struct ath_mci_buf *buf = &mci->sched_buf; |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 391 | |
Felix Fietkau | 8a30930 | 2011-12-17 16:47:56 +0100 | [diff] [blame] | 392 | if (!ATH9K_HW_CAP_MCI) |
| 393 | return 0; |
| 394 | |
Sujith Manoharan | ea510e4 | 2012-02-22 12:40:09 +0530 | [diff] [blame^] | 395 | buf->bf_addr = dma_alloc_coherent(sc->dev, |
| 396 | ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE, |
| 397 | &buf->bf_paddr, GFP_KERNEL); |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 398 | |
Sujith Manoharan | ea510e4 | 2012-02-22 12:40:09 +0530 | [diff] [blame^] | 399 | if (buf->bf_addr == NULL) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 400 | ath_dbg(common, FATAL, "MCI buffer alloc failed\n"); |
Sujith Manoharan | ea510e4 | 2012-02-22 12:40:09 +0530 | [diff] [blame^] | 401 | return -ENOMEM; |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 402 | } |
| 403 | |
Sujith Manoharan | ea510e4 | 2012-02-22 12:40:09 +0530 | [diff] [blame^] | 404 | memset(buf->bf_addr, MCI_GPM_RSVD_PATTERN, |
| 405 | ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE); |
| 406 | |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 407 | mci->sched_buf.bf_len = ATH_MCI_SCHED_BUF_SIZE; |
| 408 | |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 409 | mci->gpm_buf.bf_len = ATH_MCI_GPM_BUF_SIZE; |
Sujith Manoharan | ea510e4 | 2012-02-22 12:40:09 +0530 | [diff] [blame^] | 410 | mci->gpm_buf.bf_addr = (u8 *)mci->sched_buf.bf_addr + mci->sched_buf.bf_len; |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 411 | mci->gpm_buf.bf_paddr = mci->sched_buf.bf_paddr + mci->sched_buf.bf_len; |
| 412 | |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 413 | ar9003_mci_setup(sc->sc_ah, mci->gpm_buf.bf_paddr, |
| 414 | mci->gpm_buf.bf_addr, (mci->gpm_buf.bf_len >> 4), |
| 415 | mci->sched_buf.bf_paddr); |
Sujith Manoharan | ea510e4 | 2012-02-22 12:40:09 +0530 | [diff] [blame^] | 416 | |
| 417 | ath_dbg(common, MCI, "MCI Initialized\n"); |
| 418 | |
| 419 | return 0; |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | void ath_mci_cleanup(struct ath_softc *sc) |
| 423 | { |
Sujith Manoharan | ea510e4 | 2012-02-22 12:40:09 +0530 | [diff] [blame^] | 424 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 425 | struct ath_hw *ah = sc->sc_ah; |
| 426 | struct ath_mci_coex *mci = &sc->mci_coex; |
Sujith Manoharan | ea510e4 | 2012-02-22 12:40:09 +0530 | [diff] [blame^] | 427 | struct ath_mci_buf *buf = &mci->sched_buf; |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 428 | |
Felix Fietkau | 8a30930 | 2011-12-17 16:47:56 +0100 | [diff] [blame] | 429 | if (!ATH9K_HW_CAP_MCI) |
| 430 | return; |
| 431 | |
Sujith Manoharan | ea510e4 | 2012-02-22 12:40:09 +0530 | [diff] [blame^] | 432 | if (buf->bf_addr) |
| 433 | dma_free_coherent(sc->dev, |
| 434 | ATH_MCI_SCHED_BUF_SIZE + ATH_MCI_GPM_BUF_SIZE, |
| 435 | buf->bf_addr, buf->bf_paddr); |
| 436 | |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 437 | ar9003_mci_cleanup(ah); |
Sujith Manoharan | ea510e4 | 2012-02-22 12:40:09 +0530 | [diff] [blame^] | 438 | |
| 439 | ath_dbg(common, MCI, "MCI De-Initialized\n"); |
Mohammed Shafi Shajakhan | 9e25365 | 2011-11-30 10:41:23 +0530 | [diff] [blame] | 440 | } |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 441 | |
| 442 | void ath_mci_intr(struct ath_softc *sc) |
| 443 | { |
| 444 | struct ath_mci_coex *mci = &sc->mci_coex; |
| 445 | struct ath_hw *ah = sc->sc_ah; |
| 446 | struct ath_common *common = ath9k_hw_common(ah); |
| 447 | u32 mci_int, mci_int_rxmsg; |
| 448 | u32 offset, subtype, opcode; |
| 449 | u32 *pgpm; |
| 450 | u32 more_data = MCI_GPM_MORE; |
| 451 | bool skip_gpm = false; |
| 452 | |
Felix Fietkau | 8a30930 | 2011-12-17 16:47:56 +0100 | [diff] [blame] | 453 | if (!ATH9K_HW_CAP_MCI) |
| 454 | return; |
| 455 | |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 456 | ar9003_mci_get_interrupt(sc->sc_ah, &mci_int, &mci_int_rxmsg); |
| 457 | |
| 458 | if (ar9003_mci_state(ah, MCI_STATE_ENABLE, NULL) == 0) { |
| 459 | |
| 460 | ar9003_mci_state(sc->sc_ah, MCI_STATE_INIT_GPM_OFFSET, NULL); |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 461 | ath_dbg(common, MCI, "MCI interrupt but MCI disabled\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 462 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 463 | ath_dbg(common, MCI, |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 464 | "MCI interrupt: intr = 0x%x, intr_rxmsg = 0x%x\n", |
| 465 | mci_int, mci_int_rxmsg); |
| 466 | return; |
| 467 | } |
| 468 | |
| 469 | if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE) { |
| 470 | u32 payload[4] = { 0xffffffff, 0xffffffff, |
| 471 | 0xffffffff, 0xffffff00}; |
| 472 | |
| 473 | /* |
| 474 | * The following REMOTE_RESET and SYS_WAKING used to sent |
| 475 | * only when BT wake up. Now they are always sent, as a |
| 476 | * recovery method to reset BT MCI's RX alignment. |
| 477 | */ |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 478 | ath_dbg(common, MCI, "MCI interrupt send REMOTE_RESET\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 479 | |
| 480 | ar9003_mci_send_message(ah, MCI_REMOTE_RESET, 0, |
| 481 | payload, 16, true, false); |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 482 | ath_dbg(common, MCI, "MCI interrupt send SYS_WAKING\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 483 | ar9003_mci_send_message(ah, MCI_SYS_WAKING, 0, |
| 484 | NULL, 0, true, false); |
| 485 | |
| 486 | mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE; |
| 487 | ar9003_mci_state(ah, MCI_STATE_RESET_REQ_WAKE, NULL); |
| 488 | |
| 489 | /* |
| 490 | * always do this for recovery and 2G/5G toggling and LNA_TRANS |
| 491 | */ |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 492 | ath_dbg(common, MCI, "MCI Set BT state to AWAKE\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 493 | ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE, NULL); |
| 494 | } |
| 495 | |
| 496 | /* Processing SYS_WAKING/SYS_SLEEPING */ |
| 497 | if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING) { |
| 498 | mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING; |
| 499 | |
| 500 | if (ar9003_mci_state(ah, MCI_STATE_BT, NULL) == MCI_BT_SLEEP) { |
| 501 | |
| 502 | if (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP, NULL) |
| 503 | == MCI_BT_SLEEP) |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 504 | ath_dbg(common, MCI, |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 505 | "MCI BT stays in sleep mode\n"); |
| 506 | else { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 507 | ath_dbg(common, MCI, |
| 508 | "MCI Set BT state to AWAKE\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 509 | ar9003_mci_state(ah, |
| 510 | MCI_STATE_SET_BT_AWAKE, NULL); |
| 511 | } |
| 512 | } else |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 513 | ath_dbg(common, MCI, "MCI BT stays in AWAKE mode\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING) { |
| 517 | |
| 518 | mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING; |
| 519 | |
| 520 | if (ar9003_mci_state(ah, MCI_STATE_BT, NULL) == MCI_BT_AWAKE) { |
| 521 | |
| 522 | if (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP, NULL) |
| 523 | == MCI_BT_AWAKE) |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 524 | ath_dbg(common, MCI, |
| 525 | "MCI BT stays in AWAKE mode\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 526 | else { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 527 | ath_dbg(common, MCI, |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 528 | "MCI SetBT state to SLEEP\n"); |
| 529 | ar9003_mci_state(ah, MCI_STATE_SET_BT_SLEEP, |
| 530 | NULL); |
| 531 | } |
| 532 | } else |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 533 | ath_dbg(common, MCI, "MCI BT stays in SLEEP mode\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | if ((mci_int & AR_MCI_INTERRUPT_RX_INVALID_HDR) || |
| 537 | (mci_int & AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT)) { |
| 538 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 539 | ath_dbg(common, MCI, "MCI RX broken, skip GPM msgs\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 540 | ar9003_mci_state(ah, MCI_STATE_RECOVER_RX, NULL); |
| 541 | skip_gpm = true; |
| 542 | } |
| 543 | |
| 544 | if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO) { |
| 545 | |
| 546 | mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO; |
| 547 | offset = ar9003_mci_state(ah, MCI_STATE_LAST_SCHD_MSG_OFFSET, |
| 548 | NULL); |
| 549 | } |
| 550 | |
| 551 | if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_GPM) { |
| 552 | |
| 553 | mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_GPM; |
| 554 | |
| 555 | while (more_data == MCI_GPM_MORE) { |
| 556 | |
| 557 | pgpm = mci->gpm_buf.bf_addr; |
| 558 | offset = ar9003_mci_state(ah, |
| 559 | MCI_STATE_NEXT_GPM_OFFSET, &more_data); |
| 560 | |
| 561 | if (offset == MCI_GPM_INVALID) |
| 562 | break; |
| 563 | |
| 564 | pgpm += (offset >> 2); |
| 565 | |
| 566 | /* |
| 567 | * The first dword is timer. |
| 568 | * The real data starts from 2nd dword. |
| 569 | */ |
| 570 | |
| 571 | subtype = MCI_GPM_TYPE(pgpm); |
| 572 | opcode = MCI_GPM_OPCODE(pgpm); |
| 573 | |
| 574 | if (!skip_gpm) { |
| 575 | |
| 576 | if (MCI_GPM_IS_CAL_TYPE(subtype)) |
| 577 | ath_mci_cal_msg(sc, subtype, |
| 578 | (u8 *) pgpm); |
| 579 | else { |
| 580 | switch (subtype) { |
| 581 | case MCI_GPM_COEX_AGENT: |
| 582 | ath_mci_msg(sc, opcode, |
| 583 | (u8 *) pgpm); |
| 584 | break; |
| 585 | default: |
| 586 | break; |
| 587 | } |
| 588 | } |
| 589 | } |
| 590 | MCI_GPM_RECYCLE(pgpm); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_HW_MSG_MASK) { |
| 595 | |
| 596 | if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_LNA_CONTROL) |
| 597 | mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_LNA_CONTROL; |
| 598 | |
| 599 | if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_LNA_INFO) { |
| 600 | mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_LNA_INFO; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 601 | ath_dbg(common, MCI, "MCI LNA_INFO\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_INFO) { |
| 605 | |
| 606 | int value_dbm = ar9003_mci_state(ah, |
| 607 | MCI_STATE_CONT_RSSI_POWER, NULL); |
| 608 | |
| 609 | mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_INFO; |
| 610 | |
| 611 | if (ar9003_mci_state(ah, MCI_STATE_CONT_TXRX, NULL)) |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 612 | ath_dbg(common, MCI, |
| 613 | "MCI CONT_INFO: (tx) pri = %d, pwr = %d dBm\n", |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 614 | ar9003_mci_state(ah, |
| 615 | MCI_STATE_CONT_PRIORITY, NULL), |
| 616 | value_dbm); |
| 617 | else |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 618 | ath_dbg(common, MCI, |
| 619 | "MCI CONT_INFO: (rx) pri = %d,pwr = %d dBm\n", |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 620 | ar9003_mci_state(ah, |
| 621 | MCI_STATE_CONT_PRIORITY, NULL), |
| 622 | value_dbm); |
| 623 | } |
| 624 | |
| 625 | if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_NACK) { |
| 626 | mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_NACK; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 627 | ath_dbg(common, MCI, "MCI CONT_NACK\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_RST) { |
| 631 | mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_RST; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 632 | ath_dbg(common, MCI, "MCI CONT_RST\n"); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | |
| 636 | if ((mci_int & AR_MCI_INTERRUPT_RX_INVALID_HDR) || |
| 637 | (mci_int & AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT)) |
| 638 | mci_int &= ~(AR_MCI_INTERRUPT_RX_INVALID_HDR | |
| 639 | AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT); |
| 640 | |
| 641 | if (mci_int_rxmsg & 0xfffffffe) |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 642 | ath_dbg(common, MCI, "MCI not processed mci_int_rxmsg = 0x%x\n", |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 643 | mci_int_rxmsg); |
| 644 | } |