1 /****************************************************************************** 2 * 3 * Copyright(c) 2012 Realtek Corporation. 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of version 2 of the GNU General Public License as 7 * published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * more details. 13 * 14 * The full GNU General Public License is included in this distribution in the 15 * file called LICENSE. 16 * 17 * Contact Information: 18 * wlanfae <wlanfae@realtek.com> 19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, 20 * Hsinchu 300, Taiwan. 21 * 22 * Larry Finger <Larry.Finger@lwfinger.net> 23 * 24 *****************************************************************************/ 25 26 /************************************************************** 27 * Description: 28 * 29 * This file is for RTL8821A Co-exist mechanism 30 * 31 * History 32 * 2012/11/15 Cosa first check in. 33 * 34 **************************************************************/ 35 36 /************************************************************** 37 * include files 38 **************************************************************/ 39 #include "halbt_precomp.h" 40 /************************************************************** 41 * Global variables, these are static variables 42 **************************************************************/ 43 static struct coex_dm_8821a_1ant glcoex_dm_8821a_1ant; 44 static struct coex_dm_8821a_1ant *coex_dm = &glcoex_dm_8821a_1ant; 45 static struct coex_sta_8821a_1ant glcoex_sta_8821a_1ant; 46 static struct coex_sta_8821a_1ant *coex_sta = &glcoex_sta_8821a_1ant; 47 static void btc8821a1ant_act_bt_sco_hid_only_busy(struct btc_coexist *btcoexist, 48 u8 wifi_status); 49 50 static const char *const glbt_info_src_8821a_1ant[] = { 51 "BT Info[wifi fw]", 52 "BT Info[bt rsp]", 53 "BT Info[bt auto report]", 54 }; 55 56 static u32 glcoex_ver_date_8821a_1ant = 20130816; 57 static u32 glcoex_ver_8821a_1ant = 0x41; 58 59 /************************************************************** 60 * local function proto type if needed 61 * 62 * local function start with btc8821a1ant_ 63 **************************************************************/ 64 static u8 btc8821a1ant_bt_rssi_state(struct btc_coexist *btcoexist, 65 u8 level_num, u8 rssi_thresh, 66 u8 rssi_thresh1) 67 { 68 struct rtl_priv *rtlpriv = btcoexist->adapter; 69 long bt_rssi = 0; 70 u8 bt_rssi_state = coex_sta->pre_bt_rssi_state; 71 72 bt_rssi = coex_sta->bt_rssi; 73 74 if (level_num == 2) { 75 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || 76 (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { 77 if (bt_rssi >= (rssi_thresh + 78 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) { 79 bt_rssi_state = BTC_RSSI_STATE_HIGH; 80 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 81 "[BTCoex], BT Rssi state switch to High\n"); 82 } else { 83 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; 84 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 85 "[BTCoex], BT Rssi state stay at Low\n"); 86 } 87 } else { 88 if (bt_rssi < rssi_thresh) { 89 bt_rssi_state = BTC_RSSI_STATE_LOW; 90 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 91 "[BTCoex], BT Rssi state switch to Low\n"); 92 } else { 93 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; 94 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 95 "[BTCoex], BT Rssi state stay at High\n"); 96 } 97 } 98 } else if (level_num == 3) { 99 if (rssi_thresh > rssi_thresh1) { 100 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 101 "[BTCoex], BT Rssi thresh error!!\n"); 102 return coex_sta->pre_bt_rssi_state; 103 } 104 105 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || 106 (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { 107 if (bt_rssi >= (rssi_thresh + 108 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) { 109 bt_rssi_state = BTC_RSSI_STATE_MEDIUM; 110 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 111 "[BTCoex], BT Rssi state switch to Medium\n"); 112 } else { 113 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; 114 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 115 "[BTCoex], BT Rssi state stay at Low\n"); 116 } 117 } else if ((coex_sta->pre_bt_rssi_state == 118 BTC_RSSI_STATE_MEDIUM) || 119 (coex_sta->pre_bt_rssi_state == 120 BTC_RSSI_STATE_STAY_MEDIUM)) { 121 if (bt_rssi >= (rssi_thresh1 + 122 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) { 123 bt_rssi_state = BTC_RSSI_STATE_HIGH; 124 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 125 "[BTCoex], BT Rssi state switch to High\n"); 126 } else if (bt_rssi < rssi_thresh) { 127 bt_rssi_state = BTC_RSSI_STATE_LOW; 128 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 129 "[BTCoex], BT Rssi state switch to Low\n"); 130 } else { 131 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; 132 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 133 "[BTCoex], BT Rssi state stay at Medium\n"); 134 } 135 } else { 136 if (bt_rssi < rssi_thresh1) { 137 bt_rssi_state = BTC_RSSI_STATE_MEDIUM; 138 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 139 "[BTCoex], BT Rssi state switch to Medium\n"); 140 } else { 141 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; 142 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 143 "[BTCoex], BT Rssi state stay at High\n"); 144 } 145 } 146 } 147 coex_sta->pre_bt_rssi_state = bt_rssi_state; 148 149 return bt_rssi_state; 150 } 151 152 static u8 btc8821a1ant_wifi_rssi_state(struct btc_coexist *btcoexist, 153 u8 index, u8 level_num, u8 rssi_thresh, 154 u8 rssi_thresh1) 155 { 156 struct rtl_priv *rtlpriv = btcoexist->adapter; 157 long wifi_rssi = 0; 158 u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index]; 159 160 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); 161 162 if (level_num == 2) { 163 if ((coex_sta->pre_wifi_rssi_state[index] == 164 BTC_RSSI_STATE_LOW) || 165 (coex_sta->pre_wifi_rssi_state[index] == 166 BTC_RSSI_STATE_STAY_LOW)) { 167 if (wifi_rssi >= (rssi_thresh + 168 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) { 169 wifi_rssi_state = BTC_RSSI_STATE_HIGH; 170 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 171 "[BTCoex], wifi RSSI state switch to High\n"); 172 } else { 173 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; 174 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 175 "[BTCoex], wifi RSSI state stay at Low\n"); 176 } 177 } else { 178 if (wifi_rssi < rssi_thresh) { 179 wifi_rssi_state = BTC_RSSI_STATE_LOW; 180 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 181 "[BTCoex], wifi RSSI state switch to Low\n"); 182 } else { 183 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; 184 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 185 "[BTCoex], wifi RSSI state stay at High\n"); 186 } 187 } 188 } else if (level_num == 3) { 189 if (rssi_thresh > rssi_thresh1) { 190 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 191 "[BTCoex], wifi RSSI thresh error!!\n"); 192 return coex_sta->pre_wifi_rssi_state[index]; 193 } 194 195 if ((coex_sta->pre_wifi_rssi_state[index] == 196 BTC_RSSI_STATE_LOW) || 197 (coex_sta->pre_wifi_rssi_state[index] == 198 BTC_RSSI_STATE_STAY_LOW)) { 199 if (wifi_rssi >= (rssi_thresh + 200 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) { 201 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; 202 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 203 "[BTCoex], wifi RSSI state switch to Medium\n"); 204 } else { 205 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; 206 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 207 "[BTCoex], wifi RSSI state stay at Low\n"); 208 } 209 } else if ((coex_sta->pre_wifi_rssi_state[index] == 210 BTC_RSSI_STATE_MEDIUM) || 211 (coex_sta->pre_wifi_rssi_state[index] == 212 BTC_RSSI_STATE_STAY_MEDIUM)) { 213 if (wifi_rssi >= (rssi_thresh1 + 214 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) { 215 wifi_rssi_state = BTC_RSSI_STATE_HIGH; 216 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 217 "[BTCoex], wifi RSSI state switch to High\n"); 218 } else if (wifi_rssi < rssi_thresh) { 219 wifi_rssi_state = BTC_RSSI_STATE_LOW; 220 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 221 "[BTCoex], wifi RSSI state switch to Low\n"); 222 } else { 223 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; 224 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 225 "[BTCoex], wifi RSSI state stay at Medium\n"); 226 } 227 } else { 228 if (wifi_rssi < rssi_thresh1) { 229 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; 230 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 231 "[BTCoex], wifi RSSI state switch to Medium\n"); 232 } else { 233 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; 234 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 235 "[BTCoex], wifi RSSI state stay at High\n"); 236 } 237 } 238 } 239 coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state; 240 241 return wifi_rssi_state; 242 } 243 244 static void btc8821a1ant_update_ra_mask(struct btc_coexist *btcoexist, 245 bool force_exec, u32 dis_rate_mask) 246 { 247 coex_dm->cur_ra_mask = dis_rate_mask; 248 249 if (force_exec || 250 (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask)) { 251 btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK, 252 &coex_dm->cur_ra_mask); 253 } 254 coex_dm->pre_ra_mask = coex_dm->cur_ra_mask; 255 } 256 257 static void btc8821a1ant_auto_rate_fb_retry(struct btc_coexist *btcoexist, 258 bool force_exec, u8 type) 259 { 260 bool wifi_under_b_mode = false; 261 262 coex_dm->cur_arfr_type = type; 263 264 if (force_exec || 265 (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) { 266 switch (coex_dm->cur_arfr_type) { 267 case 0: /* normal mode */ 268 btcoexist->btc_write_4byte(btcoexist, 0x430, 269 coex_dm->backup_arfr_cnt1); 270 btcoexist->btc_write_4byte(btcoexist, 0x434, 271 coex_dm->backup_arfr_cnt2); 272 break; 273 case 1: 274 btcoexist->btc_get(btcoexist, 275 BTC_GET_BL_WIFI_UNDER_B_MODE, 276 &wifi_under_b_mode); 277 if (wifi_under_b_mode) { 278 btcoexist->btc_write_4byte(btcoexist, 0x430, 279 0x0); 280 btcoexist->btc_write_4byte(btcoexist, 0x434, 281 0x01010101); 282 } else { 283 btcoexist->btc_write_4byte(btcoexist, 0x430, 284 0x0); 285 btcoexist->btc_write_4byte(btcoexist, 0x434, 286 0x04030201); 287 } 288 break; 289 default: 290 break; 291 } 292 } 293 294 coex_dm->pre_arfr_type = coex_dm->cur_arfr_type; 295 } 296 297 static void btc8821a1ant_retry_limit(struct btc_coexist *btcoexist, 298 bool force_exec, u8 type) 299 { 300 coex_dm->cur_retry_limit_type = type; 301 302 if (force_exec || 303 (coex_dm->pre_retry_limit_type != coex_dm->cur_retry_limit_type)) { 304 switch (coex_dm->cur_retry_limit_type) { 305 case 0: /* normal mode */ 306 btcoexist->btc_write_2byte(btcoexist, 0x42a, 307 coex_dm->backup_retry_limit); 308 break; 309 case 1: /* retry limit = 8 */ 310 btcoexist->btc_write_2byte(btcoexist, 0x42a, 0x0808); 311 break; 312 default: 313 break; 314 } 315 } 316 coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type; 317 } 318 319 static void btc8821a1ant_ampdu_max_time(struct btc_coexist *btcoexist, 320 bool force_exec, u8 type) 321 { 322 coex_dm->cur_ampdu_time_type = type; 323 324 if (force_exec || 325 (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) { 326 switch (coex_dm->cur_ampdu_time_type) { 327 case 0: /* normal mode */ 328 btcoexist->btc_write_1byte(btcoexist, 0x456, 329 coex_dm->backup_ampdu_max_time); 330 break; 331 case 1: /* AMPDU time = 0x38 * 32us */ 332 btcoexist->btc_write_1byte(btcoexist, 0x456, 0x38); 333 break; 334 default: 335 break; 336 } 337 } 338 339 coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type; 340 } 341 342 static void btc8821a1ant_limited_tx(struct btc_coexist *btcoexist, 343 bool force_exec, u8 ra_mask_type, 344 u8 arfr_type, u8 retry_limit_type, 345 u8 ampdu_time_type) 346 { 347 switch (ra_mask_type) { 348 case 0: /* normal mode */ 349 btc8821a1ant_update_ra_mask(btcoexist, force_exec, 0x0); 350 break; 351 case 1: /* disable cck 1/2 */ 352 btc8821a1ant_update_ra_mask(btcoexist, force_exec, 353 0x00000003); 354 break; 355 case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */ 356 btc8821a1ant_update_ra_mask(btcoexist, force_exec, 357 0x0001f1f7); 358 break; 359 default: 360 break; 361 } 362 363 btc8821a1ant_auto_rate_fb_retry(btcoexist, force_exec, arfr_type); 364 btc8821a1ant_retry_limit(btcoexist, force_exec, retry_limit_type); 365 btc8821a1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type); 366 } 367 368 static void btc8821a1ant_limited_rx(struct btc_coexist *btcoexist, 369 bool force_exec, bool rej_ap_agg_pkt, 370 bool bt_ctrl_agg_buf_size, u8 agg_buf_size) 371 { 372 bool reject_rx_agg = rej_ap_agg_pkt; 373 bool bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; 374 u8 rx_agg_size = agg_buf_size; 375 376 /* Rx Aggregation related setting */ 377 btcoexist->btc_set(btcoexist, 378 BTC_SET_BL_TO_REJ_AP_AGG_PKT, &reject_rx_agg); 379 /* decide BT control aggregation buf size or not */ 380 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, 381 &bt_ctrl_rx_agg_size); 382 /* aggregation buf size, only work when BT control Rx agg size */ 383 btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); 384 /* real update aggregation setting */ 385 btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); 386 } 387 388 static void btc8821a1ant_monitor_bt_ctr(struct btc_coexist *btcoexist) 389 { 390 u32 reg_hp_tx_rx, reg_lp_tx_rx, u4_tmp; 391 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; 392 393 reg_hp_tx_rx = 0x770; 394 reg_lp_tx_rx = 0x774; 395 396 u4_tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_tx_rx); 397 reg_hp_tx = u4_tmp & MASKLWORD; 398 reg_hp_rx = (u4_tmp & MASKHWORD) >> 16; 399 400 u4_tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_tx_rx); 401 reg_lp_tx = u4_tmp & MASKLWORD; 402 reg_lp_rx = (u4_tmp & MASKHWORD) >> 16; 403 404 coex_sta->high_priority_tx = reg_hp_tx; 405 coex_sta->high_priority_rx = reg_hp_rx; 406 coex_sta->low_priority_tx = reg_lp_tx; 407 coex_sta->low_priority_rx = reg_lp_rx; 408 409 /* reset counter */ 410 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); 411 } 412 413 static void btc8821a1ant_query_bt_info(struct btc_coexist *btcoexist) 414 { 415 struct rtl_priv *rtlpriv = btcoexist->adapter; 416 u8 h2c_parameter[1] = {0}; 417 418 coex_sta->c2h_bt_info_req_sent = true; 419 420 h2c_parameter[0] |= BIT0; /* trigger */ 421 422 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 423 "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n", 424 h2c_parameter[0]); 425 426 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); 427 } 428 429 bool btc8821a1ant_is_wifi_status_changed(struct btc_coexist *btcoexist) 430 { 431 static bool pre_wifi_busy = true; 432 static bool pre_under_4way = true; 433 static bool pre_bt_hs_on = true; 434 bool wifi_busy = false, under_4way = false, bt_hs_on = false; 435 bool wifi_connected = false; 436 437 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 438 &wifi_connected); 439 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 440 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 441 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, 442 &under_4way); 443 444 if (wifi_connected) { 445 if (wifi_busy != pre_wifi_busy) { 446 pre_wifi_busy = wifi_busy; 447 return true; 448 } 449 if (under_4way != pre_under_4way) { 450 pre_under_4way = under_4way; 451 return true; 452 } 453 if (bt_hs_on != pre_bt_hs_on) { 454 pre_bt_hs_on = bt_hs_on; 455 return true; 456 } 457 } 458 459 return false; 460 } 461 462 static void btc8821a1ant_update_bt_link_info(struct btc_coexist *btcoexist) 463 { 464 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 465 bool bt_hs_on = false; 466 467 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 468 469 bt_link_info->bt_link_exist = coex_sta->bt_link_exist; 470 bt_link_info->sco_exist = coex_sta->sco_exist; 471 bt_link_info->a2dp_exist = coex_sta->a2dp_exist; 472 bt_link_info->pan_exist = coex_sta->pan_exist; 473 bt_link_info->hid_exist = coex_sta->hid_exist; 474 475 /* work around for HS mode */ 476 if (bt_hs_on) { 477 bt_link_info->pan_exist = true; 478 bt_link_info->bt_link_exist = true; 479 } 480 481 /* check if Sco only */ 482 if (bt_link_info->sco_exist && 483 !bt_link_info->a2dp_exist && 484 !bt_link_info->pan_exist && 485 !bt_link_info->hid_exist) 486 bt_link_info->sco_only = true; 487 else 488 bt_link_info->sco_only = false; 489 490 /* check if A2dp only */ 491 if (!bt_link_info->sco_exist && 492 bt_link_info->a2dp_exist && 493 !bt_link_info->pan_exist && 494 !bt_link_info->hid_exist) 495 bt_link_info->a2dp_only = true; 496 else 497 bt_link_info->a2dp_only = false; 498 499 /* check if Pan only */ 500 if (!bt_link_info->sco_exist && 501 !bt_link_info->a2dp_exist && 502 bt_link_info->pan_exist && 503 !bt_link_info->hid_exist) 504 bt_link_info->pan_only = true; 505 else 506 bt_link_info->pan_only = false; 507 508 /* check if Hid only */ 509 if (!bt_link_info->sco_exist && 510 !bt_link_info->a2dp_exist && 511 !bt_link_info->pan_exist && 512 bt_link_info->hid_exist) 513 bt_link_info->hid_only = true; 514 else 515 bt_link_info->hid_only = false; 516 } 517 518 static u8 btc8821a1ant_action_algorithm(struct btc_coexist *btcoexist) 519 { 520 struct rtl_priv *rtlpriv = btcoexist->adapter; 521 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 522 bool bt_hs_on = false; 523 u8 algorithm = BT_8821A_1ANT_COEX_ALGO_UNDEFINED; 524 u8 num_of_diff_profile = 0; 525 526 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 527 528 if (!bt_link_info->bt_link_exist) { 529 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 530 "[BTCoex], No BT link exists!!!\n"); 531 return algorithm; 532 } 533 534 if (bt_link_info->sco_exist) 535 num_of_diff_profile++; 536 if (bt_link_info->hid_exist) 537 num_of_diff_profile++; 538 if (bt_link_info->pan_exist) 539 num_of_diff_profile++; 540 if (bt_link_info->a2dp_exist) 541 num_of_diff_profile++; 542 543 if (num_of_diff_profile == 1) { 544 if (bt_link_info->sco_exist) { 545 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 546 "[BTCoex], BT Profile = SCO only\n"); 547 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO; 548 } else { 549 if (bt_link_info->hid_exist) { 550 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 551 "[BTCoex], BT Profile = HID only\n"); 552 algorithm = BT_8821A_1ANT_COEX_ALGO_HID; 553 } else if (bt_link_info->a2dp_exist) { 554 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 555 "[BTCoex], BT Profile = A2DP only\n"); 556 algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP; 557 } else if (bt_link_info->pan_exist) { 558 if (bt_hs_on) { 559 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 560 DBG_LOUD, 561 "[BTCoex], BT Profile = PAN(HS) only\n"); 562 algorithm = BT_8821A_1ANT_COEX_ALGO_PANHS; 563 } else { 564 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 565 DBG_LOUD, 566 "[BTCoex], BT Profile = PAN(EDR) only\n"); 567 algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR; 568 } 569 } 570 } 571 } else if (num_of_diff_profile == 2) { 572 if (bt_link_info->sco_exist) { 573 if (bt_link_info->hid_exist) { 574 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 575 "[BTCoex], BT Profile = SCO + HID\n"); 576 algorithm = BT_8821A_1ANT_COEX_ALGO_HID; 577 } else if (bt_link_info->a2dp_exist) { 578 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 579 "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"); 580 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO; 581 } else if (bt_link_info->pan_exist) { 582 if (bt_hs_on) { 583 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 584 DBG_LOUD, 585 "[BTCoex], BT Profile = SCO + PAN(HS)\n"); 586 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO; 587 } else { 588 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 589 DBG_LOUD, 590 "[BTCoex], BT Profile = SCO + PAN(EDR)\n"); 591 algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID; 592 } 593 } 594 } else { 595 if (bt_link_info->hid_exist && 596 bt_link_info->a2dp_exist) { 597 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 598 "[BTCoex], BT Profile = HID + A2DP\n"); 599 algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP; 600 } else if (bt_link_info->hid_exist && 601 bt_link_info->pan_exist) { 602 if (bt_hs_on) { 603 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 604 DBG_LOUD, 605 "[BTCoex], BT Profile = HID + PAN(HS)\n"); 606 algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP; 607 } else { 608 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 609 DBG_LOUD, 610 "[BTCoex], BT Profile = HID + PAN(EDR)\n"); 611 algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID; 612 } 613 } else if (bt_link_info->pan_exist && 614 bt_link_info->a2dp_exist) { 615 if (bt_hs_on) { 616 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 617 DBG_LOUD, 618 "[BTCoex], BT Profile = A2DP + PAN(HS)\n"); 619 algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS; 620 } else { 621 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 622 DBG_LOUD, 623 "[BTCoex], BT Profile = A2DP + PAN(EDR)\n"); 624 algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP; 625 } 626 } 627 } 628 } else if (num_of_diff_profile == 3) { 629 if (bt_link_info->sco_exist) { 630 if (bt_link_info->hid_exist && 631 bt_link_info->a2dp_exist) { 632 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 633 "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"); 634 algorithm = BT_8821A_1ANT_COEX_ALGO_HID; 635 } else if (bt_link_info->hid_exist && 636 bt_link_info->pan_exist) { 637 if (bt_hs_on) { 638 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 639 DBG_LOUD, 640 "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"); 641 algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP; 642 } else { 643 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 644 DBG_LOUD, 645 "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"); 646 algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID; 647 } 648 } else if (bt_link_info->pan_exist && 649 bt_link_info->a2dp_exist) { 650 if (bt_hs_on) { 651 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 652 DBG_LOUD, 653 "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"); 654 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO; 655 } else { 656 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 657 DBG_LOUD, 658 "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"); 659 algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID; 660 } 661 } 662 } else { 663 if (bt_link_info->hid_exist && 664 bt_link_info->pan_exist && 665 bt_link_info->a2dp_exist) { 666 if (bt_hs_on) { 667 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 668 DBG_LOUD, 669 "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"); 670 algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP; 671 } else { 672 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 673 DBG_LOUD, 674 "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"); 675 algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR; 676 } 677 } 678 } 679 } else if (num_of_diff_profile >= 3) { 680 if (bt_link_info->sco_exist) { 681 if (bt_link_info->hid_exist && 682 bt_link_info->pan_exist && 683 bt_link_info->a2dp_exist) { 684 if (bt_hs_on) { 685 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 686 DBG_LOUD, 687 "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"); 688 689 } else { 690 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 691 DBG_LOUD, 692 "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); 693 algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID; 694 } 695 } 696 } 697 } 698 return algorithm; 699 } 700 701 static void btc8821a1ant_set_sw_penalty_tx_rate(struct btc_coexist *btcoexist, 702 bool low_penalty_ra) 703 { 704 struct rtl_priv *rtlpriv = btcoexist->adapter; 705 u8 h2c_parameter[6] = {0}; 706 707 h2c_parameter[0] = 0x6; /* opCode, 0x6= Retry_Penalty*/ 708 709 if (low_penalty_ra) { 710 h2c_parameter[1] |= BIT0; 711 /* normal rate except MCS7/6/5, OFDM54/48/36 */ 712 h2c_parameter[2] = 0x00; 713 h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */ 714 h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */ 715 h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */ 716 } 717 718 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 719 "[BTCoex], set WiFi Low-Penalty Retry: %s", 720 (low_penalty_ra ? "ON!!" : "OFF!!")); 721 722 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter); 723 } 724 725 static void btc8821a1ant_low_penalty_ra(struct btc_coexist *btcoexist, 726 bool force_exec, bool low_penalty_ra) 727 { 728 coex_dm->cur_low_penalty_ra = low_penalty_ra; 729 730 if (!force_exec) { 731 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra) 732 return; 733 } 734 btc8821a1ant_set_sw_penalty_tx_rate(btcoexist, 735 coex_dm->cur_low_penalty_ra); 736 737 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; 738 } 739 740 static void btc8821a1ant_set_coex_table(struct btc_coexist *btcoexist, 741 u32 val0x6c0, u32 val0x6c4, 742 u32 val0x6c8, u8 val0x6cc) 743 { 744 struct rtl_priv *rtlpriv = btcoexist->adapter; 745 746 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 747 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0); 748 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); 749 750 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 751 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4); 752 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); 753 754 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 755 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8); 756 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); 757 758 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 759 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc); 760 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); 761 } 762 763 static void btc8821a1ant_coex_table(struct btc_coexist *btcoexist, 764 bool force_exec, u32 val0x6c0, u32 val0x6c4, 765 u32 val0x6c8, u8 val0x6cc) 766 { 767 struct rtl_priv *rtlpriv = btcoexist->adapter; 768 769 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 770 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n", 771 (force_exec ? "force to" : ""), val0x6c0, val0x6c4, 772 val0x6c8, val0x6cc); 773 coex_dm->cur_val_0x6c0 = val0x6c0; 774 coex_dm->cur_val_0x6c4 = val0x6c4; 775 coex_dm->cur_val_0x6c8 = val0x6c8; 776 coex_dm->cur_val_0x6cc = val0x6cc; 777 778 if (!force_exec) { 779 if ((coex_dm->pre_val_0x6c0 == coex_dm->cur_val_0x6c0) && 780 (coex_dm->pre_val_0x6c4 == coex_dm->cur_val_0x6c4) && 781 (coex_dm->pre_val_0x6c8 == coex_dm->cur_val_0x6c8) && 782 (coex_dm->pre_val_0x6cc == coex_dm->cur_val_0x6cc)) 783 return; 784 } 785 btc8821a1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, 786 val0x6c8, val0x6cc); 787 788 coex_dm->pre_val_0x6c0 = coex_dm->cur_val_0x6c0; 789 coex_dm->pre_val_0x6c4 = coex_dm->cur_val_0x6c4; 790 coex_dm->pre_val_0x6c8 = coex_dm->cur_val_0x6c8; 791 coex_dm->pre_val_0x6cc = coex_dm->cur_val_0x6cc; 792 } 793 794 static void btc8821a1ant_coex_table_with_type(struct btc_coexist *btcoexist, 795 bool force_exec, u8 type) 796 { 797 switch (type) { 798 case 0: 799 btc8821a1ant_coex_table(btcoexist, force_exec, 0x55555555, 800 0x55555555, 0xffffff, 0x3); 801 break; 802 case 1: 803 btc8821a1ant_coex_table(btcoexist, force_exec, 0x55555555, 804 0x5a5a5a5a, 0xffffff, 0x3); 805 break; 806 case 2: 807 btc8821a1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a, 808 0x5a5a5a5a, 0xffffff, 0x3); 809 break; 810 case 3: 811 btc8821a1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a, 812 0xaaaaaaaa, 0xffffff, 0x3); 813 break; 814 case 4: 815 btc8821a1ant_coex_table(btcoexist, force_exec, 0x55555555, 816 0x5a5a5a5a, 0xffffff, 0x3); 817 break; 818 case 5: 819 btc8821a1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a, 820 0xaaaa5a5a, 0xffffff, 0x3); 821 break; 822 case 6: 823 btc8821a1ant_coex_table(btcoexist, force_exec, 0x55555555, 824 0xaaaa5a5a, 0xffffff, 0x3); 825 break; 826 case 7: 827 btc8821a1ant_coex_table(btcoexist, force_exec, 0xaaaaaaaa, 828 0xaaaaaaaa, 0xffffff, 0x3); 829 break; 830 default: 831 break; 832 } 833 } 834 835 static void btc8821a1ant_set_fw_ignore_wlan_act(struct btc_coexist *btcoexist, 836 bool enable) 837 { 838 struct rtl_priv *rtlpriv = btcoexist->adapter; 839 u8 h2c_parameter[1] = {0}; 840 841 if (enable) 842 h2c_parameter[0] |= BIT0; /* function enable */ 843 844 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 845 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n", 846 h2c_parameter[0]); 847 848 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); 849 } 850 851 static void btc8821a1ant_ignore_wlan_act(struct btc_coexist *btcoexist, 852 bool force_exec, bool enable) 853 { 854 struct rtl_priv *rtlpriv = btcoexist->adapter; 855 856 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 857 "[BTCoex], %s turn Ignore WlanAct %s\n", 858 (force_exec ? "force to" : ""), (enable ? "ON" : "OFF")); 859 coex_dm->cur_ignore_wlan_act = enable; 860 861 if (!force_exec) { 862 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 863 "[BTCoex], pre_ignore_wlan_act = %d, cur_ignore_wlan_act = %d!!\n", 864 coex_dm->pre_ignore_wlan_act, 865 coex_dm->cur_ignore_wlan_act); 866 867 if (coex_dm->pre_ignore_wlan_act == 868 coex_dm->cur_ignore_wlan_act) 869 return; 870 } 871 btc8821a1ant_set_fw_ignore_wlan_act(btcoexist, enable); 872 873 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; 874 } 875 876 static void btc8821a1ant_set_fw_ps_tdma(struct btc_coexist *btcoexist, u8 byte1, 877 u8 byte2, u8 byte3, u8 byte4, u8 byte5) 878 { 879 struct rtl_priv *rtlpriv = btcoexist->adapter; 880 u8 h2c_parameter[5] = {0}; 881 u8 real_byte1 = byte1, real_byte5 = byte5; 882 bool ap_enable = false; 883 884 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, 885 &ap_enable); 886 887 if (ap_enable) { 888 if (byte1 & BIT4 && !(byte1 & BIT5)) { 889 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 890 "[BTCoex], FW for 1Ant AP mode\n"); 891 real_byte1 &= ~BIT4; 892 real_byte1 |= BIT5; 893 894 real_byte5 |= BIT5; 895 real_byte5 &= ~BIT6; 896 } 897 } 898 899 h2c_parameter[0] = real_byte1; 900 h2c_parameter[1] = byte2; 901 h2c_parameter[2] = byte3; 902 h2c_parameter[3] = byte4; 903 h2c_parameter[4] = real_byte5; 904 905 coex_dm->ps_tdma_para[0] = real_byte1; 906 coex_dm->ps_tdma_para[1] = byte2; 907 coex_dm->ps_tdma_para[2] = byte3; 908 coex_dm->ps_tdma_para[3] = byte4; 909 coex_dm->ps_tdma_para[4] = real_byte5; 910 911 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 912 "[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n", 913 h2c_parameter[0], 914 h2c_parameter[1] << 24 | 915 h2c_parameter[2] << 16 | 916 h2c_parameter[3] << 8 | 917 h2c_parameter[4]); 918 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); 919 } 920 921 static void btc8821a1ant_set_lps_rpwm(struct btc_coexist *btcoexist, 922 u8 lps_val, u8 rpwm_val) 923 { 924 u8 lps = lps_val; 925 u8 rpwm = rpwm_val; 926 927 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); 928 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); 929 } 930 931 static void btc8821a1ant_lps_rpwm(struct btc_coexist *btcoexist, 932 bool force_exec, u8 lps_val, u8 rpwm_val) 933 { 934 struct rtl_priv *rtlpriv = btcoexist->adapter; 935 936 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 937 "[BTCoex], %s set lps/rpwm = 0x%x/0x%x\n", 938 (force_exec ? "force to" : ""), lps_val, rpwm_val); 939 coex_dm->cur_lps = lps_val; 940 coex_dm->cur_rpwm = rpwm_val; 941 942 if (!force_exec) { 943 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 944 "[BTCoex], LPS-RxBeaconMode = 0x%x, LPS-RPWM = 0x%x!!\n", 945 coex_dm->cur_lps, coex_dm->cur_rpwm); 946 947 if ((coex_dm->pre_lps == coex_dm->cur_lps) && 948 (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) { 949 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 950 "[BTCoex], LPS-RPWM_Last = 0x%x, LPS-RPWM_Now = 0x%x!!\n", 951 coex_dm->pre_rpwm, coex_dm->cur_rpwm); 952 953 return; 954 } 955 } 956 btc8821a1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); 957 958 coex_dm->pre_lps = coex_dm->cur_lps; 959 coex_dm->pre_rpwm = coex_dm->cur_rpwm; 960 } 961 962 static void btc8821a1ant_sw_mechanism(struct btc_coexist *btcoexist, 963 bool low_penalty_ra) 964 { 965 struct rtl_priv *rtlpriv = btcoexist->adapter; 966 967 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 968 "[BTCoex], SM[LpRA] = %d\n", low_penalty_ra); 969 970 btc8821a1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); 971 } 972 973 static void btc8821a1ant_set_ant_path(struct btc_coexist *btcoexist, 974 u8 ant_pos_type, bool init_hw_cfg, 975 bool wifi_off) 976 { 977 struct btc_board_info *board_info = &btcoexist->board_info; 978 u32 u4_tmp = 0; 979 u8 h2c_parameter[2] = {0}; 980 981 if (init_hw_cfg) { 982 /* 0x4c[23] = 0, 0x4c[24] = 1 Antenna control by WL/BT */ 983 u4_tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); 984 u4_tmp &= ~BIT23; 985 u4_tmp |= BIT24; 986 btcoexist->btc_write_4byte(btcoexist, 0x4c, u4_tmp); 987 988 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x975, 0x3, 0x3); 989 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77); 990 991 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) { 992 /* tell firmware "antenna inverse" 993 * WRONG firmware antenna control code, need fw to fix 994 */ 995 h2c_parameter[0] = 1; 996 h2c_parameter[1] = 1; 997 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, 998 h2c_parameter); 999 } else { 1000 /* tell firmware "no antenna inverse" 1001 * WRONG firmware antenna control code, need fw to fix 1002 */ 1003 h2c_parameter[0] = 0; 1004 h2c_parameter[1] = 1; 1005 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, 1006 h2c_parameter); 1007 } 1008 } else if (wifi_off) { 1009 /* 0x4c[24:23] = 00, Set Antenna control 1010 * by BT_RFE_CTRL BT Vendor 0xac = 0xf002 1011 */ 1012 u4_tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); 1013 u4_tmp &= ~BIT23; 1014 u4_tmp &= ~BIT24; 1015 btcoexist->btc_write_4byte(btcoexist, 0x4c, u4_tmp); 1016 1017 /* 0x765 = 0x18 */ 1018 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3); 1019 } else { 1020 /* 0x765 = 0x0 */ 1021 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x0); 1022 } 1023 1024 /* ext switch setting */ 1025 switch (ant_pos_type) { 1026 case BTC_ANT_PATH_WIFI: 1027 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77); 1028 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) 1029 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, 1030 0x30, 0x1); 1031 else 1032 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, 1033 0x30, 0x2); 1034 break; 1035 case BTC_ANT_PATH_BT: 1036 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77); 1037 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) 1038 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, 1039 0x30, 0x2); 1040 else 1041 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, 1042 0x30, 0x1); 1043 break; 1044 default: 1045 case BTC_ANT_PATH_PTA: 1046 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x66); 1047 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) 1048 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, 1049 0x30, 0x1); 1050 else 1051 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, 1052 0x30, 0x2); 1053 break; 1054 } 1055 } 1056 1057 static void btc8821a1ant_ps_tdma(struct btc_coexist *btcoexist, 1058 bool force_exec, bool turn_on, u8 type) 1059 { 1060 struct rtl_priv *rtlpriv = btcoexist->adapter; 1061 u8 rssi_adjust_val = 0; 1062 1063 coex_dm->cur_ps_tdma_on = turn_on; 1064 coex_dm->cur_ps_tdma = type; 1065 1066 if (!force_exec) { 1067 if (coex_dm->cur_ps_tdma_on) { 1068 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1069 "[BTCoex], ********** TDMA(on, %d) **********\n", 1070 coex_dm->cur_ps_tdma); 1071 } else { 1072 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1073 "[BTCoex], ********** TDMA(off, %d) **********\n", 1074 coex_dm->cur_ps_tdma); 1075 } 1076 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && 1077 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) 1078 return; 1079 } 1080 if (turn_on) { 1081 switch (type) { 1082 default: 1083 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x1a, 1084 0x1a, 0x0, 0x50); 1085 break; 1086 case 1: 1087 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x3a, 1088 0x03, 0x10, 0x50); 1089 rssi_adjust_val = 11; 1090 break; 1091 case 2: 1092 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x2b, 1093 0x03, 0x10, 0x50); 1094 rssi_adjust_val = 14; 1095 break; 1096 case 3: 1097 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x1d, 1098 0x1d, 0x0, 0x10); 1099 break; 1100 case 4: 1101 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x15, 1102 0x3, 0x14, 0x0); 1103 rssi_adjust_val = 17; 1104 break; 1105 case 5: 1106 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x15, 1107 0x3, 0x11, 0x10); 1108 break; 1109 case 6: 1110 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa, 1111 0x3, 0x0, 0x0); 1112 break; 1113 case 7: 1114 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xc, 1115 0x5, 0x0, 0x0); 1116 break; 1117 case 8: 1118 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x25, 1119 0x3, 0x10, 0x0); 1120 break; 1121 case 9: 1122 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x21, 1123 0x3, 0x10, 0x50); 1124 rssi_adjust_val = 18; 1125 break; 1126 case 10: 1127 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa, 1128 0xa, 0x0, 0x40); 1129 break; 1130 case 11: 1131 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x14, 1132 0x03, 0x10, 0x10); 1133 rssi_adjust_val = 20; 1134 break; 1135 case 12: 1136 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x0a, 1137 0x0a, 0x0, 0x50); 1138 break; 1139 case 13: 1140 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x18, 1141 0x18, 0x0, 0x10); 1142 break; 1143 case 14: 1144 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x1e, 1145 0x3, 0x10, 0x14); 1146 break; 1147 case 15: 1148 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa, 1149 0x3, 0x8, 0x0); 1150 break; 1151 case 16: 1152 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x15, 1153 0x3, 0x10, 0x0); 1154 rssi_adjust_val = 18; 1155 break; 1156 case 18: 1157 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x25, 1158 0x3, 0x10, 0x0); 1159 rssi_adjust_val = 14; 1160 break; 1161 case 20: 1162 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x35, 1163 0x03, 0x11, 0x10); 1164 break; 1165 case 21: 1166 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x15, 1167 0x03, 0x11, 0x10); 1168 break; 1169 case 22: 1170 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x25, 1171 0x03, 0x11, 0x10); 1172 break; 1173 case 23: 1174 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25, 1175 0x3, 0x31, 0x18); 1176 rssi_adjust_val = 22; 1177 break; 1178 case 24: 1179 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x15, 1180 0x3, 0x31, 0x18); 1181 rssi_adjust_val = 22; 1182 break; 1183 case 25: 1184 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa, 1185 0x3, 0x31, 0x18); 1186 rssi_adjust_val = 22; 1187 break; 1188 case 26: 1189 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa, 1190 0x3, 0x31, 0x18); 1191 rssi_adjust_val = 22; 1192 break; 1193 case 27: 1194 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25, 1195 0x3, 0x31, 0x98); 1196 rssi_adjust_val = 22; 1197 break; 1198 case 28: 1199 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x69, 0x25, 1200 0x3, 0x31, 0x0); 1201 break; 1202 case 29: 1203 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xab, 0x1a, 1204 0x1a, 0x1, 0x10); 1205 break; 1206 case 30: 1207 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x14, 1208 0x3, 0x10, 0x50); 1209 break; 1210 case 31: 1211 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x1a, 1212 0x1a, 0, 0x58); 1213 break; 1214 case 32: 1215 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x61, 0xa, 1216 0x3, 0x10, 0x0); 1217 break; 1218 case 33: 1219 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xa3, 0x25, 1220 0x3, 0x30, 0x90); 1221 break; 1222 case 34: 1223 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x53, 0x1a, 1224 0x1a, 0x0, 0x10); 1225 break; 1226 case 35: 1227 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x63, 0x1a, 1228 0x1a, 0x0, 0x10); 1229 break; 1230 case 36: 1231 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x12, 1232 0x3, 0x14, 0x50); 1233 break; 1234 } 1235 } else { 1236 /* disable PS tdma */ 1237 switch (type) { 1238 case 8: 1239 /* PTA Control */ 1240 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x8, 0x0, 0x0, 1241 0x0, 0x0); 1242 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, 1243 false, false); 1244 break; 1245 case 0: 1246 default: 1247 /* Software control, Antenna at BT side */ 1248 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0, 1249 0x0, 0x0); 1250 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, 1251 false, false); 1252 break; 1253 case 9: 1254 /* Software control, Antenna at WiFi side */ 1255 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0, 1256 0x0, 0x0); 1257 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI, 1258 false, false); 1259 break; 1260 case 10: 1261 /* under 5G */ 1262 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0, 1263 0x8, 0x0); 1264 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, 1265 false, false); 1266 break; 1267 } 1268 } 1269 rssi_adjust_val = 0; 1270 btcoexist->btc_set(btcoexist, 1271 BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val); 1272 1273 /* update pre state */ 1274 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; 1275 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; 1276 } 1277 1278 static bool btc8821a1ant_is_common_action(struct btc_coexist *btcoexist) 1279 { 1280 struct rtl_priv *rtlpriv = btcoexist->adapter; 1281 bool common = false, wifi_connected = false, wifi_busy = false; 1282 1283 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 1284 &wifi_connected); 1285 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 1286 1287 if (!wifi_connected && 1288 BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == 1289 coex_dm->bt_status) { 1290 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1291 "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"); 1292 btc8821a1ant_sw_mechanism(btcoexist, false); 1293 1294 common = true; 1295 } else if (wifi_connected && 1296 (BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == 1297 coex_dm->bt_status)) { 1298 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1299 "[BTCoex], Wifi connected + BT non connected-idle!!\n"); 1300 btc8821a1ant_sw_mechanism(btcoexist, false); 1301 1302 common = true; 1303 } else if (!wifi_connected && 1304 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == 1305 coex_dm->bt_status)) { 1306 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1307 "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"); 1308 btc8821a1ant_sw_mechanism(btcoexist, false); 1309 1310 common = true; 1311 } else if (wifi_connected && 1312 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == 1313 coex_dm->bt_status)) { 1314 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1315 "[BTCoex], Wifi connected + BT connected-idle!!\n"); 1316 btc8821a1ant_sw_mechanism(btcoexist, false); 1317 1318 common = true; 1319 } else if (!wifi_connected && 1320 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE != 1321 coex_dm->bt_status)) { 1322 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1323 "[BTCoex], Wifi non connected-idle + BT Busy!!\n"); 1324 btc8821a1ant_sw_mechanism(btcoexist, false); 1325 1326 common = true; 1327 } else { 1328 if (wifi_busy) { 1329 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1330 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n"); 1331 } else { 1332 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1333 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n"); 1334 } 1335 1336 common = false; 1337 } 1338 1339 return common; 1340 } 1341 1342 static void btc8821a1ant_ps_tdma_check_for_pwr_save(struct btc_coexist *btcoex, 1343 bool new_ps_state) 1344 { 1345 u8 lps_mode = 0x0; 1346 1347 btcoex->btc_get(btcoex, BTC_GET_U1_LPS_MODE, &lps_mode); 1348 1349 if (lps_mode) { 1350 /* already under LPS state */ 1351 if (new_ps_state) { 1352 /* keep state under LPS, do nothing */ 1353 } else { 1354 /* will leave LPS state, turn off psTdma first */ 1355 btc8821a1ant_ps_tdma(btcoex, NORMAL_EXEC, false, 0); 1356 } 1357 } else { 1358 /* NO PS state*/ 1359 if (new_ps_state) { 1360 /* will enter LPS state, turn off psTdma first */ 1361 btc8821a1ant_ps_tdma(btcoex, NORMAL_EXEC, false, 0); 1362 } else { 1363 /* keep state under NO PS state, do nothing */ 1364 } 1365 } 1366 } 1367 1368 static void btc8821a1ant_power_save_state(struct btc_coexist *btcoexist, 1369 u8 ps_type, u8 lps_val, u8 rpwm_val) 1370 { 1371 bool low_pwr_disable = false; 1372 1373 switch (ps_type) { 1374 case BTC_PS_WIFI_NATIVE: 1375 /* recover to original 32k low power setting */ 1376 low_pwr_disable = false; 1377 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER, 1378 &low_pwr_disable); 1379 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, NULL); 1380 break; 1381 case BTC_PS_LPS_ON: 1382 btc8821a1ant_ps_tdma_check_for_pwr_save(btcoexist, 1383 true); 1384 btc8821a1ant_lps_rpwm(btcoexist, NORMAL_EXEC, lps_val, 1385 rpwm_val); 1386 /* when coex force to enter LPS, do not enter 32k low power */ 1387 low_pwr_disable = true; 1388 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER, 1389 &low_pwr_disable); 1390 /* power save must executed before psTdma */ 1391 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, NULL); 1392 break; 1393 case BTC_PS_LPS_OFF: 1394 btc8821a1ant_ps_tdma_check_for_pwr_save(btcoexist, false); 1395 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, NULL); 1396 break; 1397 default: 1398 break; 1399 } 1400 } 1401 1402 static void btc8821a1ant_coex_under_5g(struct btc_coexist *btcoexist) 1403 { 1404 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1405 0x0, 0x0); 1406 btc8821a1ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true); 1407 1408 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 10); 1409 1410 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); 1411 1412 btc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); 1413 1414 btc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 5); 1415 } 1416 1417 /*********************************************** 1418 * 1419 * Software Coex Mechanism start 1420 * 1421 ***********************************************/ 1422 1423 /* SCO only or SCO+PAN(HS) */ 1424 static void btc8821a1ant_action_sco(struct btc_coexist *btcoexist) 1425 { 1426 btc8821a1ant_sw_mechanism(btcoexist, true); 1427 } 1428 1429 static void btc8821a1ant_action_hid(struct btc_coexist *btcoexist) 1430 { 1431 btc8821a1ant_sw_mechanism(btcoexist, true); 1432 } 1433 1434 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */ 1435 static void btc8821a1ant_action_a2dp(struct btc_coexist *btcoexist) 1436 { 1437 btc8821a1ant_sw_mechanism(btcoexist, false); 1438 } 1439 1440 static void btc8821a1ant_action_a2dp_pan_hs(struct btc_coexist *btcoexist) 1441 { 1442 btc8821a1ant_sw_mechanism(btcoexist, false); 1443 } 1444 1445 static void btc8821a1ant_action_pan_edr(struct btc_coexist *btcoexist) 1446 { 1447 btc8821a1ant_sw_mechanism(btcoexist, false); 1448 } 1449 1450 /* PAN(HS) only */ 1451 static void btc8821a1ant_action_pan_hs(struct btc_coexist *btcoexist) 1452 { 1453 btc8821a1ant_sw_mechanism(btcoexist, false); 1454 } 1455 1456 /* PAN(EDR)+A2DP */ 1457 static void btc8821a1ant_action_pan_edr_a2dp(struct btc_coexist *btcoexist) 1458 { 1459 btc8821a1ant_sw_mechanism(btcoexist, false); 1460 } 1461 1462 static void btc8821a1ant_action_pan_edr_hid(struct btc_coexist *btcoexist) 1463 { 1464 btc8821a1ant_sw_mechanism(btcoexist, true); 1465 } 1466 1467 /* HID+A2DP+PAN(EDR) */ 1468 static void btc8821a1ant_action_hid_a2dp_pan_edr(struct btc_coexist *btcoexist) 1469 { 1470 btc8821a1ant_sw_mechanism(btcoexist, true); 1471 } 1472 1473 static void btc8821a1ant_action_hid_a2dp(struct btc_coexist *btcoexist) 1474 { 1475 btc8821a1ant_sw_mechanism(btcoexist, true); 1476 } 1477 1478 /*********************************************** 1479 * 1480 * Non-Software Coex Mechanism start 1481 * 1482 ***********************************************/ 1483 static 1484 void btc8821a1ant_action_wifi_multi_port(struct btc_coexist *btcoexist) 1485 { 1486 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1487 1488 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); 1489 /* tdma and coex table */ 1490 if (coex_dm->bt_status == BT_8821A_1ANT_BT_STATUS_ACL_BUSY) { 1491 if (bt_link_info->a2dp_exist) { 1492 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14); 1493 btc8821a1ant_coex_table_with_type(btcoexist, 1494 NORMAL_EXEC, 1); 1495 } else if (bt_link_info->a2dp_exist && 1496 bt_link_info->pan_exist) { 1497 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 1498 btc8821a1ant_coex_table_with_type(btcoexist, 1499 NORMAL_EXEC, 4); 1500 } else { 1501 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); 1502 btc8821a1ant_coex_table_with_type(btcoexist, 1503 NORMAL_EXEC, 4); 1504 } 1505 } else if ((coex_dm->bt_status == BT_8821A_1ANT_BT_STATUS_SCO_BUSY) || 1506 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == 1507 coex_dm->bt_status)) { 1508 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist, 1509 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN); 1510 } else { 1511 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 1512 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); 1513 } 1514 } 1515 1516 static 1517 void btc8821a1ant_action_wifi_not_connected_asso_auth( 1518 struct btc_coexist *btcoexist) 1519 { 1520 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1521 1522 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 1523 0x0); 1524 1525 /* tdma and coex table */ 1526 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) { 1527 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14); 1528 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); 1529 } else if ((bt_link_info->a2dp_exist) || (bt_link_info->pan_exist)) { 1530 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); 1531 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); 1532 } else { 1533 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 1534 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); 1535 } 1536 } 1537 1538 1539 static void btc8821a1ant_action_hs(struct btc_coexist *btcoexist) 1540 { 1541 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); 1542 btc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 2); 1543 } 1544 1545 static void btc8821a1ant_action_bt_inquiry(struct btc_coexist *btcoexist) 1546 { 1547 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1548 bool wifi_connected = false; 1549 bool ap_enable = false; 1550 bool wifi_busy = false, bt_busy = false; 1551 1552 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 1553 &wifi_connected); 1554 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, 1555 &ap_enable); 1556 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 1557 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); 1558 1559 if (!wifi_connected && !coex_sta->wifi_is_high_pri_task) { 1560 btc8821a1ant_power_save_state(btcoexist, 1561 BTC_PS_WIFI_NATIVE, 0x0, 0x0); 1562 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 1563 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); 1564 } else if ((bt_link_info->sco_exist) || (bt_link_info->a2dp_exist) || 1565 (bt_link_info->hid_only)) { 1566 /* SCO/HID-only busy */ 1567 btc8821a1ant_power_save_state(btcoexist, 1568 BTC_PS_WIFI_NATIVE, 0x0, 0x0); 1569 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); 1570 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); 1571 } else if ((bt_link_info->a2dp_exist) && (bt_link_info->hid_exist)) { 1572 /* A2DP+HID busy */ 1573 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1574 0x0, 0x0); 1575 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14); 1576 1577 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); 1578 } else if ((bt_link_info->pan_exist) || (wifi_busy)) { 1579 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1580 0x0, 0x0); 1581 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); 1582 1583 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); 1584 } else { 1585 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1586 0x0, 0x0); 1587 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 1588 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); 1589 } 1590 } 1591 1592 static void btc8821a1ant_act_bt_sco_hid_only_busy(struct btc_coexist *btcoexist, 1593 u8 wifi_status) 1594 { 1595 /* tdma and coex table */ 1596 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); 1597 1598 if (BT_8821A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == 1599 wifi_status) 1600 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); 1601 else 1602 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); 1603 } 1604 1605 static void btc8821a1ant_act_wifi_con_bt_acl_busy(struct btc_coexist *btcoexist, 1606 u8 wifi_status) 1607 { 1608 u8 bt_rssi_state; 1609 1610 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1611 1612 bt_rssi_state = btc8821a1ant_bt_rssi_state(btcoexist, 2, 28, 0); 1613 1614 if (bt_link_info->hid_only) { 1615 /* HID */ 1616 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist, 1617 wifi_status); 1618 coex_dm->auto_tdma_adjust = false; 1619 return; 1620 } else if (bt_link_info->a2dp_only) { 1621 /* A2DP */ 1622 if ((bt_rssi_state != BTC_RSSI_STATE_HIGH) && 1623 (bt_rssi_state != BTC_RSSI_STATE_STAY_HIGH)) { 1624 /* for low BT RSSI */ 1625 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1626 true, 11); 1627 coex_dm->auto_tdma_adjust = false; 1628 } 1629 1630 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); 1631 } else if (bt_link_info->hid_exist && bt_link_info->a2dp_exist) { 1632 /* HID+A2DP */ 1633 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || 1634 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { 1635 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1636 true, 14); 1637 coex_dm->auto_tdma_adjust = false; 1638 } else { 1639 /*for low BT RSSI*/ 1640 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1641 true, 11); 1642 coex_dm->auto_tdma_adjust = false; 1643 } 1644 1645 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); 1646 } else if ((bt_link_info->pan_only) || 1647 (bt_link_info->hid_exist && bt_link_info->pan_exist)) { 1648 /* PAN(OPP, FTP), HID+PAN(OPP, FTP) */ 1649 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3); 1650 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); 1651 coex_dm->auto_tdma_adjust = false; 1652 } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) || 1653 (bt_link_info->hid_exist && bt_link_info->a2dp_exist && 1654 bt_link_info->pan_exist)) { 1655 /* A2DP+PAN(OPP, FTP), HID+A2DP+PAN(OPP, FTP) */ 1656 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13); 1657 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); 1658 coex_dm->auto_tdma_adjust = false; 1659 } else { 1660 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11); 1661 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); 1662 coex_dm->auto_tdma_adjust = false; 1663 } 1664 } 1665 1666 static 1667 void btc8821a1ant_action_wifi_not_connected(struct btc_coexist *btcoexist) 1668 { 1669 /* power save state */ 1670 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); 1671 1672 /* tdma and coex table */ 1673 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 1674 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); 1675 } 1676 1677 static void btc8821a1ant_act_wifi_not_conn_scan(struct btc_coexist *btcoexist) 1678 { 1679 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1680 1681 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); 1682 1683 /* tdma and coex table */ 1684 if (coex_dm->bt_status == BT_8821A_1ANT_BT_STATUS_ACL_BUSY) { 1685 if (bt_link_info->a2dp_exist) { 1686 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14); 1687 btc8821a1ant_coex_table_with_type(btcoexist, 1688 NORMAL_EXEC, 1); 1689 } else if (bt_link_info->a2dp_exist && 1690 bt_link_info->pan_exist) { 1691 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); 1692 btc8821a1ant_coex_table_with_type(btcoexist, 1693 NORMAL_EXEC, 4); 1694 } else { 1695 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); 1696 btc8821a1ant_coex_table_with_type(btcoexist, 1697 NORMAL_EXEC, 4); 1698 } 1699 } else if ((coex_dm->bt_status == BT_8821A_1ANT_BT_STATUS_SCO_BUSY) || 1700 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == 1701 coex_dm->bt_status)) { 1702 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist, 1703 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN); 1704 } else { 1705 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 1706 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); 1707 } 1708 } 1709 1710 static 1711 void btc8821a1ant_action_wifi_connected_scan(struct btc_coexist *btcoexist) 1712 { 1713 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1714 1715 /* power save state */ 1716 btc8821a1ant_power_save_state(btcoexist, 1717 BTC_PS_WIFI_NATIVE, 0x0, 0x0); 1718 1719 /* tdma and coex table */ 1720 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { 1721 if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) { 1722 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); 1723 btc8821a1ant_coex_table_with_type(btcoexist, 1724 NORMAL_EXEC, 1); 1725 } else { 1726 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); 1727 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); 1728 } 1729 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == 1730 coex_dm->bt_status) || 1731 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == 1732 coex_dm->bt_status)) { 1733 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist, 1734 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN); 1735 } else { 1736 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); 1737 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); 1738 } 1739 } 1740 1741 static void btc8821a1ant_act_wifi_conn_sp_pkt(struct btc_coexist *btcoexist) 1742 { 1743 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1744 bool hs_connecting = false; 1745 1746 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_CONNECTING, &hs_connecting); 1747 1748 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1749 0x0, 0x0); 1750 1751 /* tdma and coex table */ 1752 if (coex_dm->bt_status == BT_8821A_1ANT_BT_STATUS_ACL_BUSY) { 1753 if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) { 1754 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1755 true, 22); 1756 btc8821a1ant_coex_table_with_type(btcoexist, 1757 NORMAL_EXEC, 1); 1758 } else { 1759 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1760 true, 20); 1761 btc8821a1ant_coex_table_with_type(btcoexist, 1762 NORMAL_EXEC, 1); 1763 } 1764 } else { 1765 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); 1766 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); 1767 } 1768 } 1769 1770 static void btc8821a1ant_action_wifi_connected(struct btc_coexist *btcoexist) 1771 { 1772 struct rtl_priv *rtlpriv = btcoexist->adapter; 1773 bool wifi_busy = false; 1774 bool scan = false, link = false, roam = false; 1775 bool under_4way = false; 1776 1777 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1778 "[BTCoex], CoexForWifiConnect()===>\n"); 1779 1780 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, 1781 &under_4way); 1782 if (under_4way) { 1783 btc8821a1ant_act_wifi_conn_sp_pkt(btcoexist); 1784 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1785 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"); 1786 return; 1787 } 1788 1789 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); 1790 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); 1791 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); 1792 if (scan || link || roam) { 1793 btc8821a1ant_action_wifi_connected_scan(btcoexist); 1794 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1795 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"); 1796 return; 1797 } 1798 1799 /* power save state*/ 1800 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == 1801 coex_dm->bt_status && !btcoexist->bt_link_info.hid_only) 1802 btc8821a1ant_power_save_state(btcoexist, 1803 BTC_PS_LPS_ON, 0x50, 0x4); 1804 else 1805 btc8821a1ant_power_save_state(btcoexist, 1806 BTC_PS_WIFI_NATIVE, 1807 0x0, 0x0); 1808 1809 /* tdma and coex table */ 1810 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 1811 if (!wifi_busy) { 1812 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { 1813 btc8821a1ant_act_wifi_con_bt_acl_busy(btcoexist, 1814 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE); 1815 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == 1816 coex_dm->bt_status) || 1817 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == 1818 coex_dm->bt_status)) { 1819 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist, 1820 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE); 1821 } else { 1822 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1823 true, 5); 1824 btc8821a1ant_coex_table_with_type(btcoexist, 1825 NORMAL_EXEC, 2); 1826 } 1827 } else { 1828 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { 1829 btc8821a1ant_act_wifi_con_bt_acl_busy(btcoexist, 1830 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY); 1831 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == 1832 coex_dm->bt_status) || 1833 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == 1834 coex_dm->bt_status)) { 1835 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist, 1836 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY); 1837 } else { 1838 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); 1839 btc8821a1ant_coex_table_with_type(btcoexist, 1840 NORMAL_EXEC, 2); 1841 } 1842 } 1843 } 1844 1845 static void btc8821a1ant_run_sw_coex_mech(struct btc_coexist *btcoexist) 1846 { 1847 struct rtl_priv *rtlpriv = btcoexist->adapter; 1848 u8 algorithm = 0; 1849 1850 algorithm = btc8821a1ant_action_algorithm(btcoexist); 1851 coex_dm->cur_algorithm = algorithm; 1852 1853 if (!btc8821a1ant_is_common_action(btcoexist)) { 1854 switch (coex_dm->cur_algorithm) { 1855 case BT_8821A_1ANT_COEX_ALGO_SCO: 1856 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1857 "[BTCoex], Action algorithm = SCO\n"); 1858 btc8821a1ant_action_sco(btcoexist); 1859 break; 1860 case BT_8821A_1ANT_COEX_ALGO_HID: 1861 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1862 "[BTCoex], Action algorithm = HID\n"); 1863 btc8821a1ant_action_hid(btcoexist); 1864 break; 1865 case BT_8821A_1ANT_COEX_ALGO_A2DP: 1866 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1867 "[BTCoex], Action algorithm = A2DP\n"); 1868 btc8821a1ant_action_a2dp(btcoexist); 1869 break; 1870 case BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS: 1871 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1872 "[BTCoex], Action algorithm = A2DP+PAN(HS)\n"); 1873 btc8821a1ant_action_a2dp_pan_hs(btcoexist); 1874 break; 1875 case BT_8821A_1ANT_COEX_ALGO_PANEDR: 1876 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1877 "[BTCoex], Action algorithm = PAN(EDR)\n"); 1878 btc8821a1ant_action_pan_edr(btcoexist); 1879 break; 1880 case BT_8821A_1ANT_COEX_ALGO_PANHS: 1881 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1882 "[BTCoex], Action algorithm = HS mode\n"); 1883 btc8821a1ant_action_pan_hs(btcoexist); 1884 break; 1885 case BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP: 1886 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1887 "[BTCoex], Action algorithm = PAN+A2DP\n"); 1888 btc8821a1ant_action_pan_edr_a2dp(btcoexist); 1889 break; 1890 case BT_8821A_1ANT_COEX_ALGO_PANEDR_HID: 1891 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1892 "[BTCoex], Action algorithm = PAN(EDR)+HID\n"); 1893 btc8821a1ant_action_pan_edr_hid(btcoexist); 1894 break; 1895 case BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR: 1896 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1897 "[BTCoex], Action algorithm = HID+A2DP+PAN\n"); 1898 btc8821a1ant_action_hid_a2dp_pan_edr(btcoexist); 1899 break; 1900 case BT_8821A_1ANT_COEX_ALGO_HID_A2DP: 1901 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1902 "[BTCoex], Action algorithm = HID+A2DP\n"); 1903 btc8821a1ant_action_hid_a2dp(btcoexist); 1904 break; 1905 default: 1906 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1907 "[BTCoex], Action algorithm = coexist All Off!!\n"); 1908 /*btc8821a1ant_coex_all_off(btcoexist);*/ 1909 break; 1910 } 1911 coex_dm->pre_algorithm = coex_dm->cur_algorithm; 1912 } 1913 } 1914 1915 static void btc8821a1ant_run_coexist_mechanism(struct btc_coexist *btcoexist) 1916 { 1917 struct rtl_priv *rtlpriv = btcoexist->adapter; 1918 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1919 bool wifi_connected = false, bt_hs_on = false; 1920 bool increase_scan_dev_num = false; 1921 bool bt_ctrl_agg_buf_size = false; 1922 u8 agg_buf_size = 5; 1923 u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH; 1924 u32 wifi_link_status = 0; 1925 u32 num_of_wifi_link = 0; 1926 bool wifi_under_5g = false; 1927 1928 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1929 "[BTCoex], RunCoexistMechanism()===>\n"); 1930 1931 if (btcoexist->manual_control) { 1932 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1933 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); 1934 return; 1935 } 1936 1937 if (btcoexist->stop_coex_dm) { 1938 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1939 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"); 1940 return; 1941 } 1942 1943 if (coex_sta->under_ips) { 1944 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1945 "[BTCoex], wifi is under IPS !!!\n"); 1946 return; 1947 } 1948 1949 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); 1950 if (wifi_under_5g) { 1951 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1952 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); 1953 btc8821a1ant_coex_under_5g(btcoexist); 1954 return; 1955 } 1956 1957 if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || 1958 (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || 1959 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) 1960 increase_scan_dev_num = true; 1961 1962 btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, 1963 &increase_scan_dev_num); 1964 1965 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 1966 &wifi_connected); 1967 1968 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, 1969 &wifi_link_status); 1970 num_of_wifi_link = wifi_link_status >> 16; 1971 if ((num_of_wifi_link >= 2) || 1972 (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { 1973 btc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); 1974 btc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, 1975 bt_ctrl_agg_buf_size, agg_buf_size); 1976 btc8821a1ant_action_wifi_multi_port(btcoexist); 1977 return; 1978 } 1979 1980 if (!bt_link_info->sco_exist && !bt_link_info->hid_exist) { 1981 btc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); 1982 } else { 1983 if (wifi_connected) { 1984 wifi_rssi_state = 1985 btc8821a1ant_wifi_rssi_state(btcoexist, 1, 2, 1986 30, 0); 1987 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || 1988 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { 1989 btc8821a1ant_limited_tx(btcoexist, 1990 NORMAL_EXEC, 1, 1, 1991 1, 1); 1992 } else { 1993 btc8821a1ant_limited_tx(btcoexist, 1994 NORMAL_EXEC, 1, 1, 1995 1, 1); 1996 } 1997 } else { 1998 btc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1999 0, 0, 0, 0); 2000 } 2001 } 2002 2003 if (bt_link_info->sco_exist) { 2004 bt_ctrl_agg_buf_size = true; 2005 agg_buf_size = 0x3; 2006 } else if (bt_link_info->hid_exist) { 2007 bt_ctrl_agg_buf_size = true; 2008 agg_buf_size = 0x5; 2009 } else if (bt_link_info->a2dp_exist || bt_link_info->pan_exist) { 2010 bt_ctrl_agg_buf_size = true; 2011 agg_buf_size = 0x8; 2012 } 2013 btc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, 2014 bt_ctrl_agg_buf_size, agg_buf_size); 2015 2016 btc8821a1ant_run_sw_coex_mech(btcoexist); 2017 2018 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 2019 if (coex_sta->c2h_bt_inquiry_page) { 2020 btc8821a1ant_action_bt_inquiry(btcoexist); 2021 return; 2022 } else if (bt_hs_on) { 2023 btc8821a1ant_action_hs(btcoexist); 2024 return; 2025 } 2026 2027 if (!wifi_connected) { 2028 bool scan = false, link = false, roam = false; 2029 2030 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2031 "[BTCoex], wifi is non connected-idle !!!\n"); 2032 2033 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); 2034 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); 2035 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); 2036 2037 if (scan || link || roam) { 2038 if (scan) 2039 btc8821a1ant_act_wifi_not_conn_scan(btcoexist); 2040 else 2041 btc8821a1ant_action_wifi_not_connected_asso_auth( 2042 btcoexist); 2043 } else { 2044 btc8821a1ant_action_wifi_not_connected(btcoexist); 2045 } 2046 } else { 2047 /* wifi LPS/Busy */ 2048 btc8821a1ant_action_wifi_connected(btcoexist); 2049 } 2050 } 2051 2052 static void btc8821a1ant_init_coex_dm(struct btc_coexist *btcoexist) 2053 { 2054 /* force to reset coex mechanism 2055 * sw all off 2056 */ 2057 btc8821a1ant_sw_mechanism(btcoexist, false); 2058 2059 btc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); 2060 btc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); 2061 } 2062 2063 static void btc8821a1ant_init_hw_config(struct btc_coexist *btcoexist, 2064 bool back_up, bool wifi_only) 2065 { 2066 struct rtl_priv *rtlpriv = btcoexist->adapter; 2067 u8 u1_tmp = 0; 2068 bool wifi_under_5g = false; 2069 2070 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2071 "[BTCoex], 1Ant Init HW Config!!\n"); 2072 2073 if (wifi_only) 2074 return; 2075 2076 if (back_up) { 2077 coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist, 2078 0x430); 2079 coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist, 2080 0x434); 2081 coex_dm->backup_retry_limit = 2082 btcoexist->btc_read_2byte(btcoexist, 0x42a); 2083 coex_dm->backup_ampdu_max_time = 2084 btcoexist->btc_read_1byte(btcoexist, 0x456); 2085 } 2086 2087 /* 0x790[5:0] = 0x5 */ 2088 u1_tmp = btcoexist->btc_read_1byte(btcoexist, 0x790); 2089 u1_tmp &= 0xc0; 2090 u1_tmp |= 0x5; 2091 btcoexist->btc_write_1byte(btcoexist, 0x790, u1_tmp); 2092 2093 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); 2094 2095 /* Antenna config */ 2096 if (wifi_under_5g) 2097 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, 2098 true, false); 2099 else 2100 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, 2101 true, false); 2102 /* PTA parameter */ 2103 btc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); 2104 2105 /* Enable counter statistics 2106 * 0x76e[3] =1, WLAN_Act control by PTA 2107 */ 2108 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); 2109 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3); 2110 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1); 2111 } 2112 2113 /************************************************************** 2114 * extern function start with ex_btc8821a1ant_ 2115 **************************************************************/ 2116 void ex_btc8821a1ant_init_hwconfig(struct btc_coexist *btcoexist, bool wifionly) 2117 { 2118 btc8821a1ant_init_hw_config(btcoexist, true, wifionly); 2119 } 2120 2121 void ex_btc8821a1ant_init_coex_dm(struct btc_coexist *btcoexist) 2122 { 2123 struct rtl_priv *rtlpriv = btcoexist->adapter; 2124 2125 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2126 "[BTCoex], Coex Mechanism Init!!\n"); 2127 2128 btcoexist->stop_coex_dm = false; 2129 2130 btc8821a1ant_init_coex_dm(btcoexist); 2131 2132 btc8821a1ant_query_bt_info(btcoexist); 2133 } 2134 2135 void ex_btc8821a1ant_display_coex_info(struct btc_coexist *btcoexist) 2136 { 2137 struct btc_board_info *board_info = &btcoexist->board_info; 2138 struct btc_stack_info *stack_info = &btcoexist->stack_info; 2139 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 2140 struct rtl_priv *rtlpriv = btcoexist->adapter; 2141 u8 u1_tmp[4], i, bt_info_ext, ps_tdma_case = 0; 2142 u16 u2_tmp[4]; 2143 u32 u4_tmp[4]; 2144 bool roam = false, scan = false, link = false, wifi_under_5g = false; 2145 bool bt_hs_on = false, wifi_busy = false; 2146 long wifi_rssi = 0, bt_hs_rssi = 0; 2147 u32 wifi_bw, wifi_traffic_dir; 2148 u8 wifi_dot11_chnl, wifi_hs_chnl; 2149 u32 fw_ver = 0, bt_patch_ver = 0; 2150 2151 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2152 "\r\n ============[BT Coexist info]============"); 2153 2154 if (btcoexist->manual_control) { 2155 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2156 "\r\n ============[Under Manual Control]============"); 2157 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2158 "\r\n =========================================="); 2159 } 2160 if (btcoexist->stop_coex_dm) { 2161 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2162 "\r\n ============[Coex is STOPPED]============"); 2163 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2164 "\r\n =========================================="); 2165 } 2166 2167 if (!board_info->bt_exist) { 2168 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n BT not exists !!!"); 2169 return; 2170 } 2171 2172 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2173 "\r\n %-35s = %d/ %d/ %d", 2174 "Ant PG Num/ Ant Mech/ Ant Pos:", 2175 board_info->pg_ant_num, 2176 board_info->btdm_ant_num, 2177 board_info->btdm_ant_pos); 2178 2179 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2180 "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", 2181 ((stack_info->profile_notified) ? "Yes" : "No"), 2182 stack_info->hci_version); 2183 2184 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, 2185 &bt_patch_ver); 2186 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); 2187 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2188 "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", 2189 "CoexVer/ FwVer/ PatchVer", 2190 glcoex_ver_date_8821a_1ant, 2191 glcoex_ver_8821a_1ant, 2192 fw_ver, bt_patch_ver, 2193 bt_patch_ver); 2194 2195 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, 2196 &bt_hs_on); 2197 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL, 2198 &wifi_dot11_chnl); 2199 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, 2200 &wifi_hs_chnl); 2201 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2202 "\r\n %-35s = %d / %d(%d)", 2203 "Dot11 channel / HsChnl(HsMode)", 2204 wifi_dot11_chnl, wifi_hs_chnl, bt_hs_on); 2205 2206 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2207 "\r\n %-35s = %3ph ", 2208 "H2C Wifi inform bt chnl Info", 2209 coex_dm->wifi_chnl_info); 2210 2211 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); 2212 btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi); 2213 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2214 "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi", 2215 (int)wifi_rssi, (int)bt_hs_rssi); 2216 2217 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); 2218 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); 2219 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); 2220 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2221 "\r\n %-35s = %d/ %d/ %d ", "Wifi link/ roam/ scan", 2222 link, roam, scan); 2223 2224 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, 2225 &wifi_under_5g); 2226 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, 2227 &wifi_bw); 2228 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, 2229 &wifi_busy); 2230 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, 2231 &wifi_traffic_dir); 2232 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2233 "\r\n %-35s = %s / %s/ %s ", "Wifi status", 2234 (wifi_under_5g ? "5G" : "2.4G"), 2235 ((wifi_bw == BTC_WIFI_BW_LEGACY) ? "Legacy" : 2236 (((wifi_bw == BTC_WIFI_BW_HT40) ? "HT40" : "HT20"))), 2237 ((!wifi_busy) ? "idle" : 2238 ((wifi_traffic_dir == BTC_WIFI_TRAFFIC_TX) ? 2239 "uplink" : "downlink"))); 2240 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2241 "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", 2242 ((coex_sta->bt_disabled) ? ("disabled") : 2243 ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") : 2244 ((BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == 2245 coex_dm->bt_status) ? 2246 "non-connected idle" : 2247 ((BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == 2248 coex_dm->bt_status) ? 2249 "connected-idle" : "busy")))), 2250 coex_sta->bt_rssi, coex_sta->bt_retry_cnt); 2251 2252 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2253 "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", 2254 bt_link_info->sco_exist, 2255 bt_link_info->hid_exist, 2256 bt_link_info->pan_exist, 2257 bt_link_info->a2dp_exist); 2258 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO); 2259 2260 bt_info_ext = coex_sta->bt_info_ext; 2261 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2262 "\r\n %-35s = %s", 2263 "BT Info A2DP rate", 2264 (bt_info_ext & BIT0) ? 2265 "Basic rate" : "EDR rate"); 2266 2267 for (i = 0; i < BT_INFO_SRC_8821A_1ANT_MAX; i++) { 2268 if (coex_sta->bt_info_c2h_cnt[i]) { 2269 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2270 "\r\n %-35s = %7ph(%d)", 2271 glbt_info_src_8821a_1ant[i], 2272 coex_sta->bt_info_c2h[i], 2273 coex_sta->bt_info_c2h_cnt[i]); 2274 } 2275 } 2276 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2277 "\r\n %-35s = %s/%s, (0x%x/0x%x)", 2278 "PS state, IPS/LPS, (lps/rpwm)", 2279 ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")), 2280 ((coex_sta->under_lps ? "LPS ON" : "LPS OFF")), 2281 btcoexist->bt_info.lps_val, 2282 btcoexist->bt_info.rpwm_val); 2283 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD); 2284 2285 if (!btcoexist->manual_control) { 2286 /* Sw mechanism*/ 2287 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2288 "\r\n %-35s", 2289 "============[Sw mechanism]============"); 2290 2291 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2292 "\r\n %-35s = %d", "SM[LowPenaltyRA]", 2293 coex_dm->cur_low_penalty_ra); 2294 2295 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2296 "\r\n %-35s = %s/ %s/ %d ", 2297 "DelBA/ BtCtrlAgg/ AggSize", 2298 (btcoexist->bt_info.reject_agg_pkt ? "Yes" : "No"), 2299 (btcoexist->bt_info.bt_ctrl_buf_size ? "Yes" : "No"), 2300 btcoexist->bt_info.agg_buf_size); 2301 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2302 "\r\n %-35s = 0x%x ", "Rate Mask", 2303 btcoexist->bt_info.ra_mask); 2304 2305 /* Fw mechanism */ 2306 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s", 2307 "============[Fw mechanism]============"); 2308 2309 ps_tdma_case = coex_dm->cur_ps_tdma; 2310 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2311 "\r\n %-35s = %5ph case-%d (auto:%d)", 2312 "PS TDMA", 2313 coex_dm->ps_tdma_para, 2314 ps_tdma_case, 2315 coex_dm->auto_tdma_adjust); 2316 2317 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2318 "\r\n %-35s = 0x%x ", 2319 "Latest error condition(should be 0)", 2320 coex_dm->error_condition); 2321 2322 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2323 "\r\n %-35s = %d ", "IgnWlanAct", 2324 coex_dm->cur_ignore_wlan_act); 2325 } 2326 2327 /* Hw setting */ 2328 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2329 "\r\n %-35s", "============[Hw setting]============"); 2330 2331 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2332 "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", 2333 "backup ARFR1/ARFR2/RL/AMaxTime", 2334 coex_dm->backup_arfr_cnt1, 2335 coex_dm->backup_arfr_cnt2, 2336 coex_dm->backup_retry_limit, 2337 coex_dm->backup_ampdu_max_time); 2338 2339 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430); 2340 u4_tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434); 2341 u2_tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a); 2342 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456); 2343 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2344 "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", 2345 "0x430/0x434/0x42a/0x456", 2346 u4_tmp[0], u4_tmp[1], u2_tmp[0], u1_tmp[0]); 2347 2348 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); 2349 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc58); 2350 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2351 "\r\n %-35s = 0x%x/ 0x%x", "0x778/ 0xc58[29:25]", 2352 u1_tmp[0], (u4_tmp[0] & 0x3e000000) >> 25); 2353 2354 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db); 2355 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2356 "\r\n %-35s = 0x%x", "0x8db[6:5]", 2357 ((u1_tmp[0] & 0x60) >> 5)); 2358 2359 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x975); 2360 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4); 2361 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2362 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", 2363 "0xcb4[29:28]/0xcb4[7:0]/0x974[9:8]", 2364 (u4_tmp[0] & 0x30000000) >> 28, 2365 u4_tmp[0] & 0xff, 2366 u1_tmp[0] & 0x3); 2367 2368 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40); 2369 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c); 2370 u1_tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x64); 2371 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2372 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", 2373 "0x40/0x4c[24:23]/0x64[0]", 2374 u1_tmp[0], ((u4_tmp[0] & 0x01800000) >> 23), u1_tmp[1] & 0x1); 2375 2376 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); 2377 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); 2378 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2379 "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", 2380 u4_tmp[0], u1_tmp[0]); 2381 2382 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50); 2383 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2384 "\r\n %-35s = 0x%x", "0xc50(dig)", 2385 u4_tmp[0] & 0xff); 2386 2387 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xf48); 2388 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5d); 2389 u1_tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c); 2390 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2391 "\r\n %-35s = 0x%x/ 0x%x", "OFDM-FA/ CCK-FA", 2392 u4_tmp[0], (u1_tmp[0] << 8) + u1_tmp[1]); 2393 2394 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); 2395 u4_tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); 2396 u4_tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); 2397 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc); 2398 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2399 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", 2400 "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", 2401 u4_tmp[0], u4_tmp[1], u4_tmp[2], u1_tmp[0]); 2402 2403 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2404 "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", 2405 coex_sta->high_priority_rx, coex_sta->high_priority_tx); 2406 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2407 "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", 2408 coex_sta->low_priority_rx, coex_sta->low_priority_tx); 2409 #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 1) 2410 btc8821a1ant_monitor_bt_ctr(btcoexist); 2411 #endif 2412 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); 2413 } 2414 2415 void ex_btc8821a1ant_ips_notify(struct btc_coexist *btcoexist, u8 type) 2416 { 2417 struct rtl_priv *rtlpriv = btcoexist->adapter; 2418 bool wifi_under_5g = false; 2419 2420 if (btcoexist->manual_control || btcoexist->stop_coex_dm) 2421 return; 2422 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); 2423 if (wifi_under_5g) { 2424 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2425 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); 2426 btc8821a1ant_coex_under_5g(btcoexist); 2427 return; 2428 } 2429 2430 if (BTC_IPS_ENTER == type) { 2431 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2432 "[BTCoex], IPS ENTER notify\n"); 2433 coex_sta->under_ips = true; 2434 btc8821a1ant_set_ant_path(btcoexist, 2435 BTC_ANT_PATH_BT, false, true); 2436 /* set PTA control */ 2437 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 2438 btc8821a1ant_coex_table_with_type(btcoexist, 2439 NORMAL_EXEC, 0); 2440 } else if (BTC_IPS_LEAVE == type) { 2441 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2442 "[BTCoex], IPS LEAVE notify\n"); 2443 coex_sta->under_ips = false; 2444 2445 btc8821a1ant_run_coexist_mechanism(btcoexist); 2446 } 2447 } 2448 2449 void ex_btc8821a1ant_lps_notify(struct btc_coexist *btcoexist, u8 type) 2450 { 2451 struct rtl_priv *rtlpriv = btcoexist->adapter; 2452 2453 if (btcoexist->manual_control || btcoexist->stop_coex_dm) 2454 return; 2455 2456 if (BTC_LPS_ENABLE == type) { 2457 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2458 "[BTCoex], LPS ENABLE notify\n"); 2459 coex_sta->under_lps = true; 2460 } else if (BTC_LPS_DISABLE == type) { 2461 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2462 "[BTCoex], LPS DISABLE notify\n"); 2463 coex_sta->under_lps = false; 2464 } 2465 } 2466 2467 void ex_btc8821a1ant_scan_notify(struct btc_coexist *btcoexist, u8 type) 2468 { 2469 struct rtl_priv *rtlpriv = btcoexist->adapter; 2470 bool wifi_connected = false, bt_hs_on = false; 2471 bool bt_ctrl_agg_buf_size = false; 2472 bool wifi_under_5g = false; 2473 u32 wifi_link_status = 0; 2474 u32 num_of_wifi_link = 0; 2475 u8 agg_buf_size = 5; 2476 2477 if (btcoexist->manual_control || btcoexist->stop_coex_dm) 2478 return; 2479 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); 2480 if (wifi_under_5g) { 2481 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2482 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); 2483 btc8821a1ant_coex_under_5g(btcoexist); 2484 return; 2485 } 2486 2487 if (coex_sta->bt_disabled) 2488 return; 2489 2490 btcoexist->btc_get(btcoexist, 2491 BTC_GET_BL_HS_OPERATION, &bt_hs_on); 2492 btcoexist->btc_get(btcoexist, 2493 BTC_GET_BL_WIFI_CONNECTED, &wifi_connected); 2494 2495 btc8821a1ant_query_bt_info(btcoexist); 2496 2497 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, 2498 &wifi_link_status); 2499 num_of_wifi_link = wifi_link_status >> 16; 2500 if (num_of_wifi_link >= 2) { 2501 btc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); 2502 btc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, 2503 bt_ctrl_agg_buf_size, agg_buf_size); 2504 btc8821a1ant_action_wifi_multi_port(btcoexist); 2505 return; 2506 } 2507 2508 if (coex_sta->c2h_bt_inquiry_page) { 2509 btc8821a1ant_action_bt_inquiry(btcoexist); 2510 return; 2511 } else if (bt_hs_on) { 2512 btc8821a1ant_action_hs(btcoexist); 2513 return; 2514 } 2515 2516 if (BTC_SCAN_START == type) { 2517 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2518 "[BTCoex], SCAN START notify\n"); 2519 if (!wifi_connected) { 2520 /* non-connected scan */ 2521 btc8821a1ant_act_wifi_not_conn_scan(btcoexist); 2522 } else { 2523 /* wifi is connected */ 2524 btc8821a1ant_action_wifi_connected_scan(btcoexist); 2525 } 2526 } else if (BTC_SCAN_FINISH == type) { 2527 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2528 "[BTCoex], SCAN FINISH notify\n"); 2529 if (!wifi_connected) { 2530 /* non-connected scan */ 2531 btc8821a1ant_action_wifi_not_connected(btcoexist); 2532 } else { 2533 btc8821a1ant_action_wifi_connected(btcoexist); 2534 } 2535 } 2536 } 2537 2538 void ex_btc8821a1ant_connect_notify(struct btc_coexist *btcoexist, u8 type) 2539 { 2540 struct rtl_priv *rtlpriv = btcoexist->adapter; 2541 bool wifi_connected = false, bt_hs_on = false; 2542 u32 wifi_link_status = 0; 2543 u32 num_of_wifi_link = 0; 2544 bool bt_ctrl_agg_buf_size = false; 2545 bool wifi_under_5g = false; 2546 u8 agg_buf_size = 5; 2547 2548 if (btcoexist->manual_control || btcoexist->stop_coex_dm || 2549 coex_sta->bt_disabled) 2550 return; 2551 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); 2552 if (wifi_under_5g) { 2553 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2554 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); 2555 btc8821a1ant_coex_under_5g(btcoexist); 2556 return; 2557 } 2558 2559 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, 2560 &wifi_link_status); 2561 num_of_wifi_link = wifi_link_status >> 16; 2562 if (num_of_wifi_link >= 2) { 2563 btc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); 2564 btc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, 2565 bt_ctrl_agg_buf_size, agg_buf_size); 2566 btc8821a1ant_action_wifi_multi_port(btcoexist); 2567 return; 2568 } 2569 2570 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 2571 if (coex_sta->c2h_bt_inquiry_page) { 2572 btc8821a1ant_action_bt_inquiry(btcoexist); 2573 return; 2574 } else if (bt_hs_on) { 2575 btc8821a1ant_action_hs(btcoexist); 2576 return; 2577 } 2578 2579 if (BTC_ASSOCIATE_START == type) { 2580 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2581 "[BTCoex], CONNECT START notify\n"); 2582 btc8821a1ant_act_wifi_not_conn_scan(btcoexist); 2583 } else if (BTC_ASSOCIATE_FINISH == type) { 2584 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2585 "[BTCoex], CONNECT FINISH notify\n"); 2586 2587 btcoexist->btc_get(btcoexist, 2588 BTC_GET_BL_WIFI_CONNECTED, &wifi_connected); 2589 if (!wifi_connected) { 2590 /* non-connected scan */ 2591 btc8821a1ant_action_wifi_not_connected(btcoexist); 2592 } else { 2593 btc8821a1ant_action_wifi_connected(btcoexist); 2594 } 2595 } 2596 } 2597 2598 void ex_btc8821a1ant_media_status_notify(struct btc_coexist *btcoexist, 2599 u8 type) 2600 { 2601 struct rtl_priv *rtlpriv = btcoexist->adapter; 2602 u8 h2c_parameter[3] = {0}; 2603 u32 wifi_bw; 2604 u8 wifi_central_chnl; 2605 bool wifi_under_5g = false; 2606 2607 if (btcoexist->manual_control || btcoexist->stop_coex_dm || 2608 coex_sta->bt_disabled) 2609 return; 2610 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); 2611 if (wifi_under_5g) { 2612 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2613 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); 2614 btc8821a1ant_coex_under_5g(btcoexist); 2615 return; 2616 } 2617 2618 if (BTC_MEDIA_CONNECT == type) { 2619 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2620 "[BTCoex], MEDIA connect notify\n"); 2621 } else { 2622 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2623 "[BTCoex], MEDIA disconnect notify\n"); 2624 } 2625 2626 /* only 2.4G we need to inform bt the chnl mask */ 2627 btcoexist->btc_get(btcoexist, 2628 BTC_GET_U1_WIFI_CENTRAL_CHNL, 2629 &wifi_central_chnl); 2630 if ((type == BTC_MEDIA_CONNECT) && 2631 (wifi_central_chnl <= 14)) { 2632 h2c_parameter[0] = 0x0; 2633 h2c_parameter[1] = wifi_central_chnl; 2634 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 2635 if (wifi_bw == BTC_WIFI_BW_HT40) 2636 h2c_parameter[2] = 0x30; 2637 else 2638 h2c_parameter[2] = 0x20; 2639 } 2640 2641 coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; 2642 coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; 2643 coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; 2644 2645 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2646 "[BTCoex], FW write 0x66 = 0x%x\n", 2647 h2c_parameter[0] << 16 | 2648 h2c_parameter[1] << 8 | 2649 h2c_parameter[2]); 2650 2651 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); 2652 } 2653 2654 void ex_btc8821a1ant_special_packet_notify(struct btc_coexist *btcoexist, 2655 u8 type) 2656 { 2657 struct rtl_priv *rtlpriv = btcoexist->adapter; 2658 bool bt_hs_on = false; 2659 bool bt_ctrl_agg_buf_size = false; 2660 bool wifi_under_5g = false; 2661 u32 wifi_link_status = 0; 2662 u32 num_of_wifi_link = 0; 2663 u8 agg_buf_size = 5; 2664 2665 if (btcoexist->manual_control || btcoexist->stop_coex_dm || 2666 coex_sta->bt_disabled) 2667 return; 2668 2669 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); 2670 if (wifi_under_5g) { 2671 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2672 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); 2673 btc8821a1ant_coex_under_5g(btcoexist); 2674 return; 2675 } 2676 2677 coex_sta->special_pkt_period_cnt = 0; 2678 2679 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, 2680 &wifi_link_status); 2681 num_of_wifi_link = wifi_link_status >> 16; 2682 if (num_of_wifi_link >= 2) { 2683 btc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); 2684 btc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, 2685 bt_ctrl_agg_buf_size, agg_buf_size); 2686 btc8821a1ant_action_wifi_multi_port(btcoexist); 2687 return; 2688 } 2689 2690 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 2691 if (coex_sta->c2h_bt_inquiry_page) { 2692 btc8821a1ant_action_bt_inquiry(btcoexist); 2693 return; 2694 } else if (bt_hs_on) { 2695 btc8821a1ant_action_hs(btcoexist); 2696 return; 2697 } 2698 2699 if (BTC_PACKET_DHCP == type || 2700 BTC_PACKET_EAPOL == type) { 2701 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2702 "[BTCoex], special Packet(%d) notify\n", type); 2703 btc8821a1ant_act_wifi_conn_sp_pkt(btcoexist); 2704 } 2705 } 2706 2707 void ex_btc8821a1ant_bt_info_notify(struct btc_coexist *btcoexist, 2708 u8 *tmp_buf, u8 length) 2709 { 2710 struct rtl_priv *rtlpriv = btcoexist->adapter; 2711 u8 i; 2712 u8 bt_info = 0; 2713 u8 rsp_source = 0; 2714 bool wifi_connected = false; 2715 bool bt_busy = false; 2716 bool wifi_under_5g = false; 2717 2718 coex_sta->c2h_bt_info_req_sent = false; 2719 2720 btcoexist->btc_get(btcoexist, 2721 BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); 2722 2723 rsp_source = tmp_buf[0] & 0xf; 2724 if (rsp_source >= BT_INFO_SRC_8821A_1ANT_MAX) 2725 rsp_source = BT_INFO_SRC_8821A_1ANT_WIFI_FW; 2726 coex_sta->bt_info_c2h_cnt[rsp_source]++; 2727 2728 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2729 "[BTCoex], Bt info[%d], length = %d, hex data = [", 2730 rsp_source, length); 2731 for (i = 0; i < length; i++) { 2732 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; 2733 if (i == 1) 2734 bt_info = tmp_buf[i]; 2735 if (i == length - 1) { 2736 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2737 "0x%02x]\n", tmp_buf[i]); 2738 } else { 2739 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2740 "0x%02x, ", tmp_buf[i]); 2741 } 2742 } 2743 2744 if (BT_INFO_SRC_8821A_1ANT_WIFI_FW != rsp_source) { 2745 coex_sta->bt_retry_cnt = /* [3:0]*/ 2746 coex_sta->bt_info_c2h[rsp_source][2]&0xf; 2747 2748 coex_sta->bt_rssi = 2749 coex_sta->bt_info_c2h[rsp_source][3]*2+10; 2750 2751 coex_sta->bt_info_ext = 2752 coex_sta->bt_info_c2h[rsp_source][4]; 2753 2754 /* Here we need to resend some wifi info to BT 2755 * because bt is reset and lost the info 2756 */ 2757 if (coex_sta->bt_info_ext & BIT1) { 2758 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2759 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); 2760 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 2761 &wifi_connected); 2762 if (wifi_connected) { 2763 ex_btc8821a1ant_media_status_notify(btcoexist, 2764 BTC_MEDIA_CONNECT); 2765 } else { 2766 ex_btc8821a1ant_media_status_notify(btcoexist, 2767 BTC_MEDIA_DISCONNECT); 2768 } 2769 } 2770 2771 if ((coex_sta->bt_info_ext & BIT3) && !wifi_under_5g) { 2772 if (!btcoexist->manual_control && 2773 !btcoexist->stop_coex_dm) { 2774 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2775 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); 2776 btc8821a1ant_ignore_wlan_act(btcoexist, 2777 FORCE_EXEC, 2778 false); 2779 } 2780 } 2781 } 2782 2783 /* check BIT2 first ==> check if bt is under inquiry or page scan */ 2784 if (bt_info & BT_INFO_8821A_1ANT_B_INQ_PAGE) 2785 coex_sta->c2h_bt_inquiry_page = true; 2786 else 2787 coex_sta->c2h_bt_inquiry_page = false; 2788 2789 /* set link exist status */ 2790 if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) { 2791 coex_sta->bt_link_exist = false; 2792 coex_sta->pan_exist = false; 2793 coex_sta->a2dp_exist = false; 2794 coex_sta->hid_exist = false; 2795 coex_sta->sco_exist = false; 2796 } else { 2797 /* connection exists */ 2798 coex_sta->bt_link_exist = true; 2799 if (bt_info & BT_INFO_8821A_1ANT_B_FTP) 2800 coex_sta->pan_exist = true; 2801 else 2802 coex_sta->pan_exist = false; 2803 if (bt_info & BT_INFO_8821A_1ANT_B_A2DP) 2804 coex_sta->a2dp_exist = true; 2805 else 2806 coex_sta->a2dp_exist = false; 2807 if (bt_info & BT_INFO_8821A_1ANT_B_HID) 2808 coex_sta->hid_exist = true; 2809 else 2810 coex_sta->hid_exist = false; 2811 if (bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO) 2812 coex_sta->sco_exist = true; 2813 else 2814 coex_sta->sco_exist = false; 2815 } 2816 2817 btc8821a1ant_update_bt_link_info(btcoexist); 2818 2819 /* mask profile bit for connect-ilde identification 2820 * (for CSR case: A2DP idle --> 0x41) 2821 */ 2822 bt_info = bt_info & 0x1f; 2823 2824 if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) { 2825 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE; 2826 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2827 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); 2828 } else if (bt_info == BT_INFO_8821A_1ANT_B_CONNECTION) { 2829 /* connection exists but no busy */ 2830 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE; 2831 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2832 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); 2833 } else if ((bt_info&BT_INFO_8821A_1ANT_B_SCO_ESCO) || 2834 (bt_info&BT_INFO_8821A_1ANT_B_SCO_BUSY)) { 2835 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_SCO_BUSY; 2836 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2837 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); 2838 } else if (bt_info&BT_INFO_8821A_1ANT_B_ACL_BUSY) { 2839 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status) 2840 coex_dm->auto_tdma_adjust = false; 2841 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_ACL_BUSY; 2842 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2843 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); 2844 } else { 2845 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_MAX; 2846 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2847 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); 2848 } 2849 2850 if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || 2851 (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || 2852 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) 2853 bt_busy = true; 2854 else 2855 bt_busy = false; 2856 btcoexist->btc_set(btcoexist, 2857 BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); 2858 2859 btc8821a1ant_run_coexist_mechanism(btcoexist); 2860 } 2861 2862 void ex_btc8821a1ant_halt_notify(struct btc_coexist *btcoexist) 2863 { 2864 struct rtl_priv *rtlpriv = btcoexist->adapter; 2865 bool wifi_under_5g = false; 2866 2867 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2868 "[BTCoex], Halt notify\n"); 2869 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); 2870 if (wifi_under_5g) { 2871 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2872 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); 2873 btc8821a1ant_coex_under_5g(btcoexist); 2874 return; 2875 } 2876 2877 2878 btcoexist->stop_coex_dm = true; 2879 2880 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true); 2881 btc8821a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); 2882 2883 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); 2884 btc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); 2885 2886 ex_btc8821a1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); 2887 } 2888 2889 void ex_btc8821a1ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state) 2890 { 2891 struct rtl_priv *rtlpriv = btcoexist->adapter; 2892 bool wifi_under_5g = false; 2893 2894 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); 2895 if (wifi_under_5g) { 2896 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2897 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); 2898 btc8821a1ant_coex_under_5g(btcoexist); 2899 return; 2900 } 2901 2902 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2903 "[BTCoex], Pnp notify\n"); 2904 2905 if (BTC_WIFI_PNP_SLEEP == pnp_state) { 2906 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2907 "[BTCoex], Pnp notify to SLEEP\n"); 2908 /* BT should clear UnderIPS/UnderLPS state to avoid mismatch 2909 * state after wakeup. 2910 */ 2911 coex_sta->under_ips = false; 2912 coex_sta->under_lps = false; 2913 btcoexist->stop_coex_dm = true; 2914 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 2915 0x0, 0x0); 2916 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); 2917 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); 2918 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, 2919 true); 2920 } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { 2921 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2922 "[BTCoex], Pnp notify to WAKE UP\n"); 2923 btcoexist->stop_coex_dm = false; 2924 btc8821a1ant_init_hw_config(btcoexist, false, false); 2925 btc8821a1ant_init_coex_dm(btcoexist); 2926 btc8821a1ant_query_bt_info(btcoexist); 2927 } 2928 } 2929 2930 void ex_btc8821a1ant_periodical(struct btc_coexist *btcoexist) 2931 { 2932 struct rtl_priv *rtlpriv = btcoexist->adapter; 2933 static u8 dis_ver_info_cnt; 2934 u32 fw_ver = 0, bt_patch_ver = 0; 2935 struct btc_board_info *board_info = &btcoexist->board_info; 2936 struct btc_stack_info *stack_info = &btcoexist->stack_info; 2937 2938 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2939 "[BTCoex], ==========================Periodical===========================\n"); 2940 2941 if (dis_ver_info_cnt <= 5) { 2942 dis_ver_info_cnt += 1; 2943 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2944 "[BTCoex], ****************************************************************\n"); 2945 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2946 "[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n", 2947 board_info->pg_ant_num, 2948 board_info->btdm_ant_num, 2949 board_info->btdm_ant_pos); 2950 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2951 "[BTCoex], BT stack/ hci ext ver = %s / %d\n", 2952 stack_info->profile_notified ? "Yes" : "No", 2953 stack_info->hci_version); 2954 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, 2955 &bt_patch_ver); 2956 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); 2957 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2958 "[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n", 2959 glcoex_ver_date_8821a_1ant, 2960 glcoex_ver_8821a_1ant, 2961 fw_ver, bt_patch_ver, 2962 bt_patch_ver); 2963 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2964 "[BTCoex], ****************************************************************\n"); 2965 } 2966 2967 #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0) 2968 btc8821a1ant_query_bt_info(btcoexist); 2969 btc8821a1ant_monitor_bt_ctr(btcoexist); 2970 #else 2971 coex_sta->special_pkt_period_cnt++; 2972 #endif 2973 } 2974