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 RTL8723B 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_8723b_1ant glcoex_dm_8723b_1ant; 44 static struct coex_dm_8723b_1ant *coex_dm = &glcoex_dm_8723b_1ant; 45 static struct coex_sta_8723b_1ant glcoex_sta_8723b_1ant; 46 static struct coex_sta_8723b_1ant *coex_sta = &glcoex_sta_8723b_1ant; 47 48 static const char *const glbt_info_src_8723b_1ant[] = { 49 "BT Info[wifi fw]", 50 "BT Info[bt rsp]", 51 "BT Info[bt auto report]", 52 }; 53 54 static u32 glcoex_ver_date_8723b_1ant = 20130918; 55 static u32 glcoex_ver_8723b_1ant = 0x47; 56 57 /*************************************************************** 58 * local function proto type if needed 59 ***************************************************************/ 60 /*************************************************************** 61 * local function start with halbtc8723b1ant_ 62 ***************************************************************/ 63 64 static void halbtc8723b1ant_updatera_mask(struct btc_coexist *btcoexist, 65 bool force_exec, u32 dis_rate_mask) 66 { 67 coex_dm->curra_mask = dis_rate_mask; 68 69 if (force_exec || (coex_dm->prera_mask != coex_dm->curra_mask)) 70 btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK, 71 &coex_dm->curra_mask); 72 73 coex_dm->prera_mask = coex_dm->curra_mask; 74 } 75 76 static void btc8723b1ant_auto_rate_fb_retry(struct btc_coexist *btcoexist, 77 bool force_exec, u8 type) 78 { 79 bool wifi_under_bmode = false; 80 81 coex_dm->cur_arfr_type = type; 82 83 if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) { 84 switch (coex_dm->cur_arfr_type) { 85 case 0: /* normal mode */ 86 btcoexist->btc_write_4byte(btcoexist, 0x430, 87 coex_dm->backup_arfr_cnt1); 88 btcoexist->btc_write_4byte(btcoexist, 0x434, 89 coex_dm->backup_arfr_cnt2); 90 break; 91 case 1: 92 btcoexist->btc_get(btcoexist, 93 BTC_GET_BL_WIFI_UNDER_B_MODE, 94 &wifi_under_bmode); 95 if (wifi_under_bmode) { 96 btcoexist->btc_write_4byte(btcoexist, 97 0x430, 0x0); 98 btcoexist->btc_write_4byte(btcoexist, 99 0x434, 0x01010101); 100 } else { 101 btcoexist->btc_write_4byte(btcoexist, 102 0x430, 0x0); 103 btcoexist->btc_write_4byte(btcoexist, 104 0x434, 0x04030201); 105 } 106 break; 107 default: 108 break; 109 } 110 } 111 112 coex_dm->pre_arfr_type = coex_dm->cur_arfr_type; 113 } 114 115 static void halbtc8723b1ant_retry_limit(struct btc_coexist *btcoexist, 116 bool force_exec, u8 type) 117 { 118 coex_dm->cur_retry_limit_type = type; 119 120 if (force_exec || (coex_dm->pre_retry_limit_type != 121 coex_dm->cur_retry_limit_type)) { 122 switch (coex_dm->cur_retry_limit_type) { 123 case 0: /* normal mode */ 124 btcoexist->btc_write_2byte(btcoexist, 0x42a, 125 coex_dm->backup_retry_limit); 126 break; 127 case 1: /* retry limit = 8 */ 128 btcoexist->btc_write_2byte(btcoexist, 0x42a, 0x0808); 129 break; 130 default: 131 break; 132 } 133 } 134 135 coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type; 136 } 137 138 static void halbtc8723b1ant_ampdu_maxtime(struct btc_coexist *btcoexist, 139 bool force_exec, u8 type) 140 { 141 coex_dm->cur_ampdu_time_type = type; 142 143 if (force_exec || (coex_dm->pre_ampdu_time_type != 144 coex_dm->cur_ampdu_time_type)) { 145 switch (coex_dm->cur_ampdu_time_type) { 146 case 0: /* normal mode */ 147 btcoexist->btc_write_1byte(btcoexist, 0x456, 148 coex_dm->backup_ampdu_max_time); 149 break; 150 case 1: /* AMPDU timw = 0x38 * 32us */ 151 btcoexist->btc_write_1byte(btcoexist, 0x456, 0x38); 152 break; 153 default: 154 break; 155 } 156 } 157 158 coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type; 159 } 160 161 static void halbtc8723b1ant_limited_tx(struct btc_coexist *btcoexist, 162 bool force_exec, u8 ra_masktype, 163 u8 arfr_type, u8 retry_limit_type, 164 u8 ampdu_time_type) 165 { 166 switch (ra_masktype) { 167 case 0: /* normal mode */ 168 halbtc8723b1ant_updatera_mask(btcoexist, force_exec, 0x0); 169 break; 170 case 1: /* disable cck 1/2 */ 171 halbtc8723b1ant_updatera_mask(btcoexist, force_exec, 172 0x00000003); 173 break; 174 /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */ 175 case 2: 176 halbtc8723b1ant_updatera_mask(btcoexist, force_exec, 177 0x0001f1f7); 178 break; 179 default: 180 break; 181 } 182 183 btc8723b1ant_auto_rate_fb_retry(btcoexist, force_exec, arfr_type); 184 halbtc8723b1ant_retry_limit(btcoexist, force_exec, retry_limit_type); 185 halbtc8723b1ant_ampdu_maxtime(btcoexist, force_exec, ampdu_time_type); 186 } 187 188 static void halbtc8723b1ant_limited_rx(struct btc_coexist *btcoexist, 189 bool force_exec, bool rej_ap_agg_pkt, 190 bool bt_ctrl_agg_buf_size, 191 u8 agg_buf_size) 192 { 193 bool reject_rx_agg = rej_ap_agg_pkt; 194 bool bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; 195 u8 rxaggsize = agg_buf_size; 196 197 /********************************************** 198 * Rx Aggregation related setting 199 **********************************************/ 200 btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, 201 &reject_rx_agg); 202 /* decide BT control aggregation buf size or not */ 203 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, 204 &bt_ctrl_rx_agg_size); 205 /* aggregation buf size, only work 206 * when BT control Rx aggregation size. 207 */ 208 btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxaggsize); 209 /* real update aggregation setting */ 210 btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); 211 } 212 213 static void halbtc8723b1ant_query_bt_info(struct btc_coexist *btcoexist) 214 { 215 u8 h2c_parameter[1] = {0}; 216 217 coex_sta->c2h_bt_info_req_sent = true; 218 219 /* trigger */ 220 h2c_parameter[0] |= BIT(0); 221 222 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); 223 } 224 225 static void halbtc8723b1ant_monitor_bt_ctr(struct btc_coexist *btcoexist) 226 { 227 u32 reg_hp_txrx, reg_lp_txrx, u32tmp; 228 u32 reg_hp_tx = 0, reg_hp_rx = 0; 229 u32 reg_lp_tx = 0, reg_lp_rx = 0; 230 static u32 num_of_bt_counter_chk; 231 232 reg_hp_txrx = 0x770; 233 reg_lp_txrx = 0x774; 234 235 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); 236 reg_hp_tx = u32tmp & MASKLWORD; 237 reg_hp_rx = (u32tmp & MASKHWORD) >> 16; 238 239 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); 240 reg_lp_tx = u32tmp & MASKLWORD; 241 reg_lp_rx = (u32tmp & MASKHWORD) >> 16; 242 243 coex_sta->high_priority_tx = reg_hp_tx; 244 coex_sta->high_priority_rx = reg_hp_rx; 245 coex_sta->low_priority_tx = reg_lp_tx; 246 coex_sta->low_priority_rx = reg_lp_rx; 247 248 if ((coex_sta->low_priority_tx > 1050) && 249 (!coex_sta->c2h_bt_inquiry_page)) 250 coex_sta->pop_event_cnt++; 251 252 /* reset counter */ 253 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); 254 255 /* This part is for wifi FW and driver to update BT's status as 256 * disabled. 257 * 258 * The flow is as the following 259 * 1. disable BT 260 * 2. if all BT Tx/Rx counter = 0, after 6 sec we query bt info 261 * 3. Because BT will not rsp from mailbox, so wifi fw will know BT is 262 * disabled 263 * 264 * 4. FW will rsp c2h for BT that driver will know BT is disabled. 265 */ 266 if ((reg_hp_tx == 0) && (reg_hp_rx == 0) && (reg_lp_tx == 0) && 267 (reg_lp_rx == 0)) { 268 num_of_bt_counter_chk++; 269 if (num_of_bt_counter_chk == 3) 270 halbtc8723b1ant_query_bt_info(btcoexist); 271 } else { 272 num_of_bt_counter_chk = 0; 273 } 274 } 275 276 static void halbtc8723b1ant_monitor_wifi_ctr(struct btc_coexist *btcoexist) 277 { 278 s32 wifi_rssi = 0; 279 bool wifi_busy = false, wifi_under_b_mode = false; 280 static u8 cck_lock_counter; 281 u32 total_cnt; 282 283 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 284 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); 285 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, 286 &wifi_under_b_mode); 287 288 if (coex_sta->under_ips) { 289 coex_sta->crc_ok_cck = 0; 290 coex_sta->crc_ok_11g = 0; 291 coex_sta->crc_ok_11n = 0; 292 coex_sta->crc_ok_11n_agg = 0; 293 294 coex_sta->crc_err_cck = 0; 295 coex_sta->crc_err_11g = 0; 296 coex_sta->crc_err_11n = 0; 297 coex_sta->crc_err_11n_agg = 0; 298 } else { 299 coex_sta->crc_ok_cck = 300 btcoexist->btc_read_4byte(btcoexist, 0xf88); 301 coex_sta->crc_ok_11g = 302 btcoexist->btc_read_2byte(btcoexist, 0xf94); 303 coex_sta->crc_ok_11n = 304 btcoexist->btc_read_2byte(btcoexist, 0xf90); 305 coex_sta->crc_ok_11n_agg = 306 btcoexist->btc_read_2byte(btcoexist, 0xfb8); 307 308 coex_sta->crc_err_cck = 309 btcoexist->btc_read_4byte(btcoexist, 0xf84); 310 coex_sta->crc_err_11g = 311 btcoexist->btc_read_2byte(btcoexist, 0xf96); 312 coex_sta->crc_err_11n = 313 btcoexist->btc_read_2byte(btcoexist, 0xf92); 314 coex_sta->crc_err_11n_agg = 315 btcoexist->btc_read_2byte(btcoexist, 0xfba); 316 } 317 318 /* reset counter */ 319 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x1); 320 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x0); 321 322 if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) { 323 total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g + 324 coex_sta->crc_ok_11n + coex_sta->crc_ok_11n_agg; 325 326 if ((coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) || 327 (coex_dm->bt_status == 328 BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) || 329 (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_SCO_BUSY)) { 330 if (coex_sta->crc_ok_cck > 331 (total_cnt - coex_sta->crc_ok_cck)) { 332 if (cck_lock_counter < 3) 333 cck_lock_counter++; 334 } else { 335 if (cck_lock_counter > 0) 336 cck_lock_counter--; 337 } 338 339 } else { 340 if (cck_lock_counter > 0) 341 cck_lock_counter--; 342 } 343 } else { 344 if (cck_lock_counter > 0) 345 cck_lock_counter--; 346 } 347 348 if (!coex_sta->pre_ccklock) { 349 if (cck_lock_counter >= 3) 350 coex_sta->cck_lock = true; 351 else 352 coex_sta->cck_lock = false; 353 } else { 354 if (cck_lock_counter == 0) 355 coex_sta->cck_lock = false; 356 else 357 coex_sta->cck_lock = true; 358 } 359 360 if (coex_sta->cck_lock) 361 coex_sta->cck_ever_lock = true; 362 363 coex_sta->pre_ccklock = coex_sta->cck_lock; 364 } 365 366 static bool btc8723b1ant_is_wifi_status_changed(struct btc_coexist *btcoexist) 367 { 368 static bool pre_wifi_busy; 369 static bool pre_under_4way, pre_bt_hs_on; 370 bool wifi_busy = false, under_4way = false, bt_hs_on = false; 371 bool wifi_connected = false; 372 373 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 374 &wifi_connected); 375 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 376 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 377 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, 378 &under_4way); 379 380 if (wifi_connected) { 381 if (wifi_busy != pre_wifi_busy) { 382 pre_wifi_busy = wifi_busy; 383 return true; 384 } 385 if (under_4way != pre_under_4way) { 386 pre_under_4way = under_4way; 387 return true; 388 } 389 if (bt_hs_on != pre_bt_hs_on) { 390 pre_bt_hs_on = bt_hs_on; 391 return true; 392 } 393 } 394 395 return false; 396 } 397 398 static void halbtc8723b1ant_update_bt_link_info(struct btc_coexist *btcoexist) 399 { 400 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 401 bool bt_hs_on = false; 402 403 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 404 405 bt_link_info->bt_link_exist = coex_sta->bt_link_exist; 406 bt_link_info->sco_exist = coex_sta->sco_exist; 407 bt_link_info->a2dp_exist = coex_sta->a2dp_exist; 408 bt_link_info->pan_exist = coex_sta->pan_exist; 409 bt_link_info->hid_exist = coex_sta->hid_exist; 410 bt_link_info->bt_hi_pri_link_exist = coex_sta->bt_hi_pri_link_exist; 411 412 /* work around for HS mode. */ 413 if (bt_hs_on) { 414 bt_link_info->pan_exist = true; 415 bt_link_info->bt_link_exist = true; 416 } 417 418 /* check if Sco only */ 419 if (bt_link_info->sco_exist && !bt_link_info->a2dp_exist && 420 !bt_link_info->pan_exist && !bt_link_info->hid_exist) 421 bt_link_info->sco_only = true; 422 else 423 bt_link_info->sco_only = false; 424 425 /* check if A2dp only */ 426 if (!bt_link_info->sco_exist && bt_link_info->a2dp_exist && 427 !bt_link_info->pan_exist && !bt_link_info->hid_exist) 428 bt_link_info->a2dp_only = true; 429 else 430 bt_link_info->a2dp_only = false; 431 432 /* check if Pan only */ 433 if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist && 434 bt_link_info->pan_exist && !bt_link_info->hid_exist) 435 bt_link_info->pan_only = true; 436 else 437 bt_link_info->pan_only = false; 438 439 /* check if Hid only */ 440 if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist && 441 !bt_link_info->pan_exist && bt_link_info->hid_exist) 442 bt_link_info->hid_only = true; 443 else 444 bt_link_info->hid_only = false; 445 } 446 447 static void halbtc8723b1ant_set_bt_auto_report(struct btc_coexist *btcoexist, 448 bool enable_auto_report) 449 { 450 u8 h2c_parameter[1] = {0}; 451 452 h2c_parameter[0] = 0; 453 454 if (enable_auto_report) 455 h2c_parameter[0] |= BIT(0); 456 457 btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); 458 } 459 460 static void halbtc8723b1ant_bt_auto_report(struct btc_coexist *btcoexist, 461 bool force_exec, 462 bool enable_auto_report) 463 { 464 coex_dm->cur_bt_auto_report = enable_auto_report; 465 466 if (!force_exec) { 467 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) 468 return; 469 } 470 halbtc8723b1ant_set_bt_auto_report(btcoexist, 471 coex_dm->cur_bt_auto_report); 472 473 coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; 474 } 475 476 static void btc8723b1ant_set_sw_pen_tx_rate_adapt(struct btc_coexist *btcoexist, 477 bool low_penalty_ra) 478 { 479 struct rtl_priv *rtlpriv = btcoexist->adapter; 480 u8 h2c_parameter[6] = {0}; 481 482 h2c_parameter[0] = 0x6; /* opCode, 0x6= Retry_Penalty */ 483 484 if (low_penalty_ra) { 485 h2c_parameter[1] |= BIT0; 486 /* normal rate except MCS7/6/5, OFDM54/48/36 */ 487 h2c_parameter[2] = 0x00; 488 h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */ 489 h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */ 490 h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */ 491 } 492 493 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 494 "[BTCoex], set WiFi Low-Penalty Retry: %s", 495 (low_penalty_ra ? "ON!!" : "OFF!!")); 496 497 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter); 498 } 499 500 static void halbtc8723b1ant_low_penalty_ra(struct btc_coexist *btcoexist, 501 bool force_exec, bool low_penalty_ra) 502 { 503 coex_dm->cur_low_penalty_ra = low_penalty_ra; 504 505 if (!force_exec) { 506 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra) 507 return; 508 } 509 btc8723b1ant_set_sw_pen_tx_rate_adapt(btcoexist, 510 coex_dm->cur_low_penalty_ra); 511 512 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; 513 } 514 515 static void halbtc8723b1ant_set_coex_table(struct btc_coexist *btcoexist, 516 u32 val0x6c0, u32 val0x6c4, 517 u32 val0x6c8, u8 val0x6cc) 518 { 519 struct rtl_priv *rtlpriv = btcoexist->adapter; 520 521 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 522 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0); 523 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); 524 525 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 526 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4); 527 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); 528 529 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 530 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8); 531 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); 532 533 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 534 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc); 535 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); 536 } 537 538 static void halbtc8723b1ant_coex_table(struct btc_coexist *btcoexist, 539 bool force_exec, u32 val0x6c0, 540 u32 val0x6c4, u32 val0x6c8, 541 u8 val0x6cc) 542 { 543 struct rtl_priv *rtlpriv = btcoexist->adapter; 544 545 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 546 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6cc = 0x%x\n", 547 (force_exec ? "force to" : ""), 548 val0x6c0, val0x6c4, val0x6cc); 549 coex_dm->cur_val0x6c0 = val0x6c0; 550 coex_dm->cur_val0x6c4 = val0x6c4; 551 coex_dm->cur_val0x6c8 = val0x6c8; 552 coex_dm->cur_val0x6cc = val0x6cc; 553 554 if (!force_exec) { 555 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && 556 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && 557 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && 558 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) 559 return; 560 } 561 halbtc8723b1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, 562 val0x6c8, val0x6cc); 563 564 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; 565 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; 566 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; 567 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; 568 } 569 570 static void halbtc8723b1ant_coex_table_with_type(struct btc_coexist *btcoexist, 571 bool force_exec, u8 type) 572 { 573 coex_sta->coex_table_type = type; 574 575 switch (type) { 576 case 0: 577 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555, 578 0x55555555, 0xffffff, 0x3); 579 break; 580 case 1: 581 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555, 582 0x5a5a5a5a, 0xffffff, 0x3); 583 break; 584 case 2: 585 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a, 586 0x5a5a5a5a, 0xffffff, 0x3); 587 break; 588 case 3: 589 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555, 590 0x5a5a5a5a, 0xffffff, 0x3); 591 break; 592 case 4: 593 if ((coex_sta->cck_ever_lock) && (coex_sta->scan_ap_num <= 5)) 594 halbtc8723b1ant_coex_table(btcoexist, force_exec, 595 0x55555555, 0xaaaa5a5a, 596 0xffffff, 0x3); 597 else 598 halbtc8723b1ant_coex_table(btcoexist, force_exec, 599 0x55555555, 0x5a5a5a5a, 600 0xffffff, 0x3); 601 break; 602 case 5: 603 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a, 604 0x5aaa5a5a, 0xffffff, 0x3); 605 break; 606 case 6: 607 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555, 608 0xaaaaaaaa, 0xffffff, 0x3); 609 break; 610 case 7: 611 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0xaaaaaaaa, 612 0xaaaaaaaa, 0xffffff, 0x3); 613 break; 614 case 8: 615 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55dd55dd, 616 0x5ada5ada, 0xffffff, 0x3); 617 break; 618 case 9: 619 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55dd55dd, 620 0x5ada5ada, 0xffffff, 0x3); 621 break; 622 case 10: 623 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55dd55dd, 624 0x5ada5ada, 0xffffff, 0x3); 625 break; 626 case 11: 627 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55dd55dd, 628 0x5ada5ada, 0xffffff, 0x3); 629 break; 630 case 12: 631 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55dd55dd, 632 0x5ada5ada, 0xffffff, 0x3); 633 break; 634 case 13: 635 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x5fff5fff, 636 0xaaaaaaaa, 0xffffff, 0x3); 637 break; 638 case 14: 639 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x5fff5fff, 640 0x5ada5ada, 0xffffff, 0x3); 641 break; 642 case 15: 643 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55dd55dd, 644 0xaaaaaaaa, 0xffffff, 0x3); 645 break; 646 default: 647 break; 648 } 649 } 650 651 static void 652 halbtc8723b1ant_set_fw_ignore_wlan_act(struct btc_coexist *btcoexist, 653 bool enable) 654 { 655 struct rtl_priv *rtlpriv = btcoexist->adapter; 656 u8 h2c_parameter[1] = {0}; 657 658 if (enable) 659 h2c_parameter[0] |= BIT0; /* function enable */ 660 661 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 662 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n", 663 h2c_parameter[0]); 664 665 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); 666 } 667 668 static void halbtc8723b1ant_ignore_wlan_act(struct btc_coexist *btcoexist, 669 bool force_exec, bool enable) 670 { 671 struct rtl_priv *rtlpriv = btcoexist->adapter; 672 673 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 674 "[BTCoex], %s turn Ignore WlanAct %s\n", 675 (force_exec ? "force to" : ""), (enable ? "ON" : "OFF")); 676 coex_dm->cur_ignore_wlan_act = enable; 677 678 if (!force_exec) { 679 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 680 "[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n", 681 coex_dm->pre_ignore_wlan_act, 682 coex_dm->cur_ignore_wlan_act); 683 684 if (coex_dm->pre_ignore_wlan_act == 685 coex_dm->cur_ignore_wlan_act) 686 return; 687 } 688 halbtc8723b1ant_set_fw_ignore_wlan_act(btcoexist, enable); 689 690 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; 691 } 692 693 static void halbtc8723b1ant_set_fw_ps_tdma(struct btc_coexist *btcoexist, 694 u8 byte1, u8 byte2, u8 byte3, 695 u8 byte4, u8 byte5) 696 { 697 struct rtl_priv *rtlpriv = btcoexist->adapter; 698 u8 h2c_parameter[5] = {0}; 699 u8 real_byte1 = byte1, real_byte5 = byte5; 700 bool ap_enable = false; 701 702 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, 703 &ap_enable); 704 705 if (ap_enable) { 706 if ((byte1 & BIT4) && !(byte1 & BIT5)) { 707 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 708 "[BTCoex], FW for 1Ant AP mode\n"); 709 real_byte1 &= ~BIT4; 710 real_byte1 |= BIT5; 711 712 real_byte5 |= BIT5; 713 real_byte5 &= ~BIT6; 714 } 715 } 716 717 h2c_parameter[0] = real_byte1; 718 h2c_parameter[1] = byte2; 719 h2c_parameter[2] = byte3; 720 h2c_parameter[3] = byte4; 721 h2c_parameter[4] = real_byte5; 722 723 coex_dm->ps_tdma_para[0] = real_byte1; 724 coex_dm->ps_tdma_para[1] = byte2; 725 coex_dm->ps_tdma_para[2] = byte3; 726 coex_dm->ps_tdma_para[3] = byte4; 727 coex_dm->ps_tdma_para[4] = real_byte5; 728 729 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 730 "[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n", 731 h2c_parameter[0], 732 h2c_parameter[1] << 24 | 733 h2c_parameter[2] << 16 | 734 h2c_parameter[3] << 8 | 735 h2c_parameter[4]); 736 737 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); 738 } 739 740 static void halbtc8723b1ant_set_lps_rpwm(struct btc_coexist *btcoexist, 741 u8 lps_val, u8 rpwm_val) 742 { 743 u8 lps = lps_val; 744 u8 rpwm = rpwm_val; 745 746 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); 747 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); 748 } 749 750 static void halbtc8723b1ant_lps_rpwm(struct btc_coexist *btcoexist, 751 bool force_exec, 752 u8 lps_val, u8 rpwm_val) 753 { 754 struct rtl_priv *rtlpriv = btcoexist->adapter; 755 756 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 757 "[BTCoex], %s set lps/rpwm = 0x%x/0x%x\n", 758 (force_exec ? "force to" : ""), lps_val, rpwm_val); 759 coex_dm->cur_lps = lps_val; 760 coex_dm->cur_rpwm = rpwm_val; 761 762 if (!force_exec) { 763 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 764 "[BTCoex], LPS-RxBeaconMode = 0x%x , LPS-RPWM = 0x%x!!\n", 765 coex_dm->cur_lps, coex_dm->cur_rpwm); 766 767 if ((coex_dm->pre_lps == coex_dm->cur_lps) && 768 (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) { 769 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 770 "[BTCoex], LPS-RPWM_Last = 0x%x , LPS-RPWM_Now = 0x%x!!\n", 771 coex_dm->pre_rpwm, coex_dm->cur_rpwm); 772 773 return; 774 } 775 } 776 halbtc8723b1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); 777 778 coex_dm->pre_lps = coex_dm->cur_lps; 779 coex_dm->pre_rpwm = coex_dm->cur_rpwm; 780 } 781 782 static void halbtc8723b1ant_sw_mechanism(struct btc_coexist *btcoexist, 783 bool low_penalty_ra) 784 { 785 struct rtl_priv *rtlpriv = btcoexist->adapter; 786 787 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 788 "[BTCoex], SM[LpRA] = %d\n", low_penalty_ra); 789 790 halbtc8723b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); 791 } 792 793 static void halbtc8723b1ant_set_ant_path(struct btc_coexist *btcoexist, 794 u8 ant_pos_type, bool force_exec, 795 bool init_hw_cfg, bool wifi_off) 796 { 797 struct rtl_priv *rtlpriv = btcoexist->adapter; 798 struct btc_board_info *board_info = &btcoexist->board_info; 799 u32 fw_ver = 0, u32tmp = 0, cnt_bt_cal_chk = 0; 800 bool pg_ext_switch = false; 801 bool use_ext_switch = false; 802 bool is_in_mp_mode = false; 803 u8 h2c_parameter[2] = {0}, u8tmp = 0; 804 805 coex_dm->cur_ant_pos_type = ant_pos_type; 806 807 btcoexist->btc_get(btcoexist, BTC_GET_BL_EXT_SWITCH, &pg_ext_switch); 808 /* [31:16] = fw ver, [15:0] = fw sub ver */ 809 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); 810 811 if ((fw_ver < 0xc0000) || pg_ext_switch) 812 use_ext_switch = true; 813 814 if (init_hw_cfg) { 815 /* WiFi TRx Mask on */ 816 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 817 0x780); 818 /* remove due to interrupt is disabled that polling c2h will 819 * fail and delay 100ms. 820 */ 821 822 if (fw_ver >= 0x180000) { 823 /* Use H2C to set GNT_BT to HIGH */ 824 h2c_parameter[0] = 1; 825 btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, 826 h2c_parameter); 827 } else { 828 /* set grant_bt to high */ 829 btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18); 830 } 831 /* set wlan_act control by PTA */ 832 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); 833 834 /* BT select s0/s1 is controlled by BT */ 835 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x0); 836 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x39, 0x8, 0x1); 837 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff); 838 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x944, 0x3, 0x3); 839 btcoexist->btc_write_1byte(btcoexist, 0x930, 0x77); 840 } else if (wifi_off) { 841 if (fw_ver >= 0x180000) { 842 /* Use H2C to set GNT_BT to HIGH */ 843 h2c_parameter[0] = 1; 844 btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, 845 h2c_parameter); 846 } else { 847 /* set grant_bt to high */ 848 btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18); 849 } 850 /* set wlan_act to always low */ 851 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); 852 853 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, 854 &is_in_mp_mode); 855 if (!is_in_mp_mode) 856 /* BT select s0/s1 is controlled by BT */ 857 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 858 0x20, 0x0); 859 else 860 /* BT select s0/s1 is controlled by WiFi */ 861 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 862 0x20, 0x1); 863 864 /* 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL 865 * BT Vendor 0xac=0xf002 866 */ 867 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); 868 u32tmp &= ~BIT23; 869 u32tmp &= ~BIT24; 870 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); 871 } else { 872 /* Use H2C to set GNT_BT to LOW */ 873 if (fw_ver >= 0x180000) { 874 if (btcoexist->btc_read_1byte(btcoexist, 0x765) != 0) { 875 h2c_parameter[0] = 0; 876 btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, 877 h2c_parameter); 878 } 879 } else { 880 /* BT calibration check */ 881 while (cnt_bt_cal_chk <= 20) { 882 u8tmp = btcoexist->btc_read_1byte(btcoexist, 883 0x49d); 884 cnt_bt_cal_chk++; 885 if (u8tmp & BIT(0)) { 886 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 887 DBG_LOUD, 888 "[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n", 889 cnt_bt_cal_chk); 890 mdelay(50); 891 } else { 892 RT_TRACE(rtlpriv, COMP_BT_COEXIST, 893 DBG_LOUD, 894 "[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n", 895 cnt_bt_cal_chk); 896 break; 897 } 898 } 899 900 /* set grant_bt to PTA */ 901 btcoexist->btc_write_1byte(btcoexist, 0x765, 0x0); 902 } 903 904 if (btcoexist->btc_read_1byte(btcoexist, 0x76e) != 0xc) { 905 /* set wlan_act control by PTA */ 906 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); 907 } 908 909 btcoexist->btc_write_1byte_bitmask( 910 btcoexist, 0x67, 0x20, 911 0x1); /* BT select s0/s1 is controlled by WiFi */ 912 } 913 914 if (use_ext_switch) { 915 if (init_hw_cfg) { 916 /* 0x4c[23] = 0, 0x4c[24] = 1 917 * Antenna control by WL/BT 918 */ 919 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); 920 u32tmp &= ~BIT23; 921 u32tmp |= BIT24; 922 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); 923 924 /* fixed internal switch S1->WiFi, S0->BT */ 925 btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0); 926 927 if (board_info->btdm_ant_pos == 928 BTC_ANTENNA_AT_MAIN_PORT) { 929 /* tell firmware "no antenna inverse" */ 930 h2c_parameter[0] = 0; 931 /* ext switch type */ 932 h2c_parameter[1] = 1; 933 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, 934 h2c_parameter); 935 } else { 936 /* tell firmware "antenna inverse" */ 937 h2c_parameter[0] = 1; 938 /* ext switch type */ 939 h2c_parameter[1] = 1; 940 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, 941 h2c_parameter); 942 } 943 } 944 945 if (force_exec || 946 (coex_dm->cur_ant_pos_type != coex_dm->pre_ant_pos_type)) { 947 /* ext switch setting */ 948 switch (ant_pos_type) { 949 case BTC_ANT_PATH_WIFI: 950 if (board_info->btdm_ant_pos == 951 BTC_ANTENNA_AT_MAIN_PORT) 952 btcoexist->btc_write_1byte_bitmask( 953 btcoexist, 0x92c, 0x3, 0x1); 954 else 955 btcoexist->btc_write_1byte_bitmask( 956 btcoexist, 0x92c, 0x3, 0x2); 957 break; 958 case BTC_ANT_PATH_BT: 959 if (board_info->btdm_ant_pos == 960 BTC_ANTENNA_AT_MAIN_PORT) 961 btcoexist->btc_write_1byte_bitmask( 962 btcoexist, 0x92c, 0x3, 0x2); 963 else 964 btcoexist->btc_write_1byte_bitmask( 965 btcoexist, 0x92c, 0x3, 0x1); 966 break; 967 default: 968 case BTC_ANT_PATH_PTA: 969 if (board_info->btdm_ant_pos == 970 BTC_ANTENNA_AT_MAIN_PORT) 971 btcoexist->btc_write_1byte_bitmask( 972 btcoexist, 0x92c, 0x3, 0x1); 973 else 974 btcoexist->btc_write_1byte_bitmask( 975 btcoexist, 0x92c, 0x3, 0x2); 976 break; 977 } 978 } 979 } else { 980 if (init_hw_cfg) { 981 /* 0x4c[23] = 1, 0x4c[24] = 0, 982 * Antenna control by 0x64 983 */ 984 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); 985 u32tmp |= BIT23; 986 u32tmp &= ~BIT24; 987 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); 988 989 /* Fix Ext switch Main->S1, Aux->S0 */ 990 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 991 0x0); 992 993 if (board_info->btdm_ant_pos == 994 BTC_ANTENNA_AT_MAIN_PORT) { 995 /* tell firmware "no antenna inverse" */ 996 h2c_parameter[0] = 0; 997 /* internal switch type */ 998 h2c_parameter[1] = 0; 999 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, 1000 h2c_parameter); 1001 } else { 1002 /* tell firmware "antenna inverse" */ 1003 h2c_parameter[0] = 1; 1004 /* internal switch type */ 1005 h2c_parameter[1] = 0; 1006 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, 1007 h2c_parameter); 1008 } 1009 } 1010 1011 if (force_exec || 1012 (coex_dm->cur_ant_pos_type != coex_dm->pre_ant_pos_type)) { 1013 /* internal switch setting */ 1014 switch (ant_pos_type) { 1015 case BTC_ANT_PATH_WIFI: 1016 if (board_info->btdm_ant_pos == 1017 BTC_ANTENNA_AT_MAIN_PORT) 1018 btcoexist->btc_write_4byte(btcoexist, 1019 0x948, 0x0); 1020 else 1021 btcoexist->btc_write_4byte(btcoexist, 1022 0x948, 0x280); 1023 break; 1024 case BTC_ANT_PATH_BT: 1025 if (board_info->btdm_ant_pos == 1026 BTC_ANTENNA_AT_MAIN_PORT) 1027 btcoexist->btc_write_4byte(btcoexist, 1028 0x948, 0x280); 1029 else 1030 btcoexist->btc_write_4byte(btcoexist, 1031 0x948, 0x0); 1032 break; 1033 default: 1034 case BTC_ANT_PATH_PTA: 1035 if (board_info->btdm_ant_pos == 1036 BTC_ANTENNA_AT_MAIN_PORT) 1037 btcoexist->btc_write_4byte(btcoexist, 1038 0x948, 0x200); 1039 else 1040 btcoexist->btc_write_4byte(btcoexist, 1041 0x948, 0x80); 1042 break; 1043 } 1044 } 1045 } 1046 1047 coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type; 1048 } 1049 1050 static void halbtc8723b1ant_ps_tdma(struct btc_coexist *btcoexist, 1051 bool force_exec, bool turn_on, u8 type) 1052 { 1053 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1054 bool wifi_busy = false; 1055 u8 rssi_adjust_val = 0; 1056 u8 ps_tdma_byte0_val = 0x51; 1057 u8 ps_tdma_byte3_val = 0x10; 1058 u8 ps_tdma_byte4_val = 0x50; 1059 s8 wifi_duration_adjust = 0x0; 1060 static bool pre_wifi_busy; 1061 1062 coex_dm->cur_ps_tdma_on = turn_on; 1063 coex_dm->cur_ps_tdma = type; 1064 1065 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 1066 1067 if (wifi_busy != pre_wifi_busy) { 1068 force_exec = true; 1069 pre_wifi_busy = wifi_busy; 1070 } 1071 1072 if (!force_exec) { 1073 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && 1074 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) 1075 return; 1076 } 1077 1078 if (coex_sta->scan_ap_num <= 5) { 1079 wifi_duration_adjust = 5; 1080 1081 if (coex_sta->a2dp_bit_pool >= 35) 1082 wifi_duration_adjust = -10; 1083 else if (coex_sta->a2dp_bit_pool >= 45) 1084 wifi_duration_adjust = -15; 1085 } else if (coex_sta->scan_ap_num >= 40) { 1086 wifi_duration_adjust = -15; 1087 1088 if (coex_sta->a2dp_bit_pool < 35) 1089 wifi_duration_adjust = -5; 1090 else if (coex_sta->a2dp_bit_pool < 45) 1091 wifi_duration_adjust = -10; 1092 } else if (coex_sta->scan_ap_num >= 20) { 1093 wifi_duration_adjust = -10; 1094 1095 if (coex_sta->a2dp_bit_pool >= 45) 1096 wifi_duration_adjust = -15; 1097 } else { 1098 wifi_duration_adjust = 0; 1099 1100 if (coex_sta->a2dp_bit_pool >= 35) 1101 wifi_duration_adjust = -10; 1102 else if (coex_sta->a2dp_bit_pool >= 45) 1103 wifi_duration_adjust = -15; 1104 } 1105 1106 if ((type == 1) || (type == 2) || (type == 9) || (type == 11) || 1107 (type == 101) || (type == 102) || (type == 109) || (type == 101)) { 1108 if (!coex_sta->force_lps_on) { 1109 /* Native power save TDMA, only for A2DP-only case 1110 * 1/2/9/11 while wifi noisy threshold > 30 1111 */ 1112 1113 /* no null-pkt */ 1114 ps_tdma_byte0_val = 0x61; 1115 /* no tx-pause at BT-slot */ 1116 ps_tdma_byte3_val = 0x11; 1117 /* 0x778 = d/1 toggle, no dynamic slot */ 1118 ps_tdma_byte4_val = 0x10; 1119 } else { 1120 /* null-pkt */ 1121 ps_tdma_byte0_val = 0x51; 1122 /* tx-pause at BT-slot */ 1123 ps_tdma_byte3_val = 0x10; 1124 /* 0x778 = d/1 toggle, dynamic slot */ 1125 ps_tdma_byte4_val = 0x50; 1126 } 1127 } else if ((type == 3) || (type == 13) || (type == 14) || 1128 (type == 103) || (type == 113) || (type == 114)) { 1129 /* null-pkt */ 1130 ps_tdma_byte0_val = 0x51; 1131 /* tx-pause at BT-slot */ 1132 ps_tdma_byte3_val = 0x10; 1133 /* 0x778 = d/1 toggle, no dynamic slot */ 1134 ps_tdma_byte4_val = 0x10; 1135 } else { /* native power save case */ 1136 /* no null-pkt */ 1137 ps_tdma_byte0_val = 0x61; 1138 /* no tx-pause at BT-slot */ 1139 ps_tdma_byte3_val = 0x11; 1140 /* 0x778 = d/1 toggle, no dynamic slot */ 1141 ps_tdma_byte4_val = 0x11; 1142 /* psTdmaByte4Va is not define for 0x778 = d/1, 1/1 case */ 1143 } 1144 1145 /* if (bt_link_info->slave_role) */ 1146 if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist)) 1147 /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ 1148 ps_tdma_byte4_val = ps_tdma_byte4_val | 0x1; 1149 1150 if (type > 100) { 1151 /* set antenna control by SW */ 1152 ps_tdma_byte0_val = ps_tdma_byte0_val | 0x82; 1153 /* set antenna no toggle, control by antenna diversity */ 1154 ps_tdma_byte3_val = ps_tdma_byte3_val | 0x60; 1155 } 1156 1157 if (turn_on) { 1158 switch (type) { 1159 default: 1160 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x1a, 1161 0x1a, 0x0, 1162 ps_tdma_byte4_val); 1163 break; 1164 case 1: 1165 halbtc8723b1ant_set_fw_ps_tdma( 1166 btcoexist, ps_tdma_byte0_val, 1167 0x3a + wifi_duration_adjust, 0x03, 1168 ps_tdma_byte3_val, ps_tdma_byte4_val); 1169 1170 rssi_adjust_val = 11; 1171 break; 1172 case 2: 1173 halbtc8723b1ant_set_fw_ps_tdma( 1174 btcoexist, ps_tdma_byte0_val, 1175 0x2d + wifi_duration_adjust, 0x03, 1176 ps_tdma_byte3_val, ps_tdma_byte4_val); 1177 break; 1178 case 3: 1179 halbtc8723b1ant_set_fw_ps_tdma( 1180 btcoexist, ps_tdma_byte0_val, 0x30, 0x03, 1181 ps_tdma_byte3_val, ps_tdma_byte4_val); 1182 break; 1183 case 4: 1184 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x15, 1185 0x3, 0x14, 0x0); 1186 break; 1187 case 5: 1188 halbtc8723b1ant_set_fw_ps_tdma( 1189 btcoexist, ps_tdma_byte0_val, 0x1f, 0x3, 1190 ps_tdma_byte3_val, 0x11); 1191 break; 1192 case 6: 1193 halbtc8723b1ant_set_fw_ps_tdma( 1194 btcoexist, ps_tdma_byte0_val, 0x20, 0x3, 1195 ps_tdma_byte3_val, 0x11); 1196 break; 1197 case 7: 1198 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xc, 1199 0x5, 0x0, 0x0); 1200 break; 1201 case 8: 1202 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x25, 1203 0x3, 0x10, 0x0); 1204 break; 1205 case 9: 1206 halbtc8723b1ant_set_fw_ps_tdma( 1207 btcoexist, ps_tdma_byte0_val, 0x21, 0x3, 1208 ps_tdma_byte3_val, ps_tdma_byte4_val); 1209 break; 1210 case 10: 1211 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa, 1212 0xa, 0x0, 0x40); 1213 break; 1214 case 11: 1215 halbtc8723b1ant_set_fw_ps_tdma( 1216 btcoexist, ps_tdma_byte0_val, 0x21, 0x03, 1217 ps_tdma_byte3_val, ps_tdma_byte4_val); 1218 break; 1219 case 12: 1220 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x0a, 1221 0x0a, 0x0, 0x50); 1222 break; 1223 case 13: 1224 if (coex_sta->scan_ap_num <= 3) 1225 halbtc8723b1ant_set_fw_ps_tdma( 1226 btcoexist, ps_tdma_byte0_val, 0x40, 0x3, 1227 ps_tdma_byte3_val, ps_tdma_byte4_val); 1228 else 1229 halbtc8723b1ant_set_fw_ps_tdma( 1230 btcoexist, ps_tdma_byte0_val, 0x21, 0x3, 1231 ps_tdma_byte3_val, ps_tdma_byte4_val); 1232 break; 1233 case 14: 1234 if (coex_sta->scan_ap_num <= 3) 1235 halbtc8723b1ant_set_fw_ps_tdma( 1236 btcoexist, 0x51, 0x30, 0x3, 0x10, 0x50); 1237 else 1238 halbtc8723b1ant_set_fw_ps_tdma( 1239 btcoexist, ps_tdma_byte0_val, 0x21, 0x3, 1240 ps_tdma_byte3_val, ps_tdma_byte4_val); 1241 break; 1242 case 15: 1243 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa, 1244 0x3, 0x8, 0x0); 1245 break; 1246 case 16: 1247 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x15, 1248 0x3, 0x10, 0x0); 1249 break; 1250 case 18: 1251 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x25, 1252 0x3, 0x10, 0x0); 1253 break; 1254 case 20: 1255 halbtc8723b1ant_set_fw_ps_tdma( 1256 btcoexist, ps_tdma_byte0_val, 0x3f, 0x03, 1257 ps_tdma_byte3_val, 0x10); 1258 break; 1259 case 21: 1260 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x25, 1261 0x03, 0x11, 0x11); 1262 break; 1263 case 22: 1264 halbtc8723b1ant_set_fw_ps_tdma( 1265 btcoexist, ps_tdma_byte0_val, 0x25, 0x03, 1266 ps_tdma_byte3_val, 0x10); 1267 break; 1268 case 23: 1269 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25, 1270 0x3, 0x31, 0x18); 1271 break; 1272 case 24: 1273 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x15, 1274 0x3, 0x31, 0x18); 1275 break; 1276 case 25: 1277 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa, 1278 0x3, 0x31, 0x18); 1279 break; 1280 case 26: 1281 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa, 1282 0x3, 0x31, 0x18); 1283 break; 1284 case 27: 1285 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25, 1286 0x3, 0x31, 0x98); 1287 break; 1288 case 28: 1289 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x69, 0x25, 1290 0x3, 0x31, 0x0); 1291 break; 1292 case 29: 1293 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xab, 0x1a, 1294 0x1a, 0x1, 0x10); 1295 break; 1296 case 30: 1297 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x30, 1298 0x3, 0x10, 0x10); 1299 break; 1300 case 31: 1301 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x1a, 1302 0x1a, 0, 0x58); 1303 break; 1304 case 32: 1305 halbtc8723b1ant_set_fw_ps_tdma( 1306 btcoexist, ps_tdma_byte0_val, 0x35, 0x3, 1307 ps_tdma_byte3_val, ps_tdma_byte4_val); 1308 break; 1309 case 33: 1310 halbtc8723b1ant_set_fw_ps_tdma( 1311 btcoexist, ps_tdma_byte0_val, 0x35, 0x3, 1312 ps_tdma_byte3_val, 0x10); 1313 break; 1314 case 34: 1315 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x53, 0x1a, 1316 0x1a, 0x0, 0x10); 1317 break; 1318 case 35: 1319 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x63, 0x1a, 1320 0x1a, 0x0, 0x10); 1321 break; 1322 case 36: 1323 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x12, 1324 0x3, 0x14, 0x50); 1325 break; 1326 case 40: 1327 /* SoftAP only with no sta associated,BT disable ,TDMA 1328 * mode for power saving 1329 * 1330 * here softap mode screen off will cost 70-80mA for 1331 * phone 1332 */ 1333 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x23, 0x18, 1334 0x00, 0x10, 0x24); 1335 break; 1336 1337 case 101: 1338 /* for 1-Ant translate to 2-Ant */ 1339 halbtc8723b1ant_set_fw_ps_tdma( 1340 btcoexist, ps_tdma_byte0_val, 1341 0x3a + wifi_duration_adjust, 0x03, 1342 ps_tdma_byte3_val, ps_tdma_byte4_val); 1343 break; 1344 case 102: 1345 halbtc8723b1ant_set_fw_ps_tdma( 1346 btcoexist, ps_tdma_byte0_val, 1347 0x2d + wifi_duration_adjust, 0x03, 1348 ps_tdma_byte3_val, ps_tdma_byte4_val); 1349 break; 1350 case 103: 1351 halbtc8723b1ant_set_fw_ps_tdma( 1352 btcoexist, ps_tdma_byte0_val, 0x3a, 0x03, 1353 ps_tdma_byte3_val, ps_tdma_byte4_val); 1354 break; 1355 case 105: 1356 halbtc8723b1ant_set_fw_ps_tdma( 1357 btcoexist, ps_tdma_byte0_val, 0x15, 0x3, 1358 ps_tdma_byte3_val, 0x11); 1359 break; 1360 case 106: 1361 halbtc8723b1ant_set_fw_ps_tdma( 1362 btcoexist, ps_tdma_byte0_val, 0x20, 0x3, 1363 ps_tdma_byte3_val, 0x11); 1364 break; 1365 case 109: 1366 halbtc8723b1ant_set_fw_ps_tdma( 1367 btcoexist, ps_tdma_byte0_val, 0x21, 0x3, 1368 ps_tdma_byte3_val, ps_tdma_byte4_val); 1369 break; 1370 case 111: 1371 halbtc8723b1ant_set_fw_ps_tdma( 1372 btcoexist, ps_tdma_byte0_val, 0x21, 0x03, 1373 ps_tdma_byte3_val, ps_tdma_byte4_val); 1374 break; 1375 case 113: 1376 halbtc8723b1ant_set_fw_ps_tdma( 1377 btcoexist, ps_tdma_byte0_val, 0x21, 0x3, 1378 ps_tdma_byte3_val, ps_tdma_byte4_val); 1379 break; 1380 case 114: 1381 halbtc8723b1ant_set_fw_ps_tdma( 1382 btcoexist, ps_tdma_byte0_val, 0x21, 0x3, 1383 ps_tdma_byte3_val, ps_tdma_byte4_val); 1384 break; 1385 case 120: 1386 halbtc8723b1ant_set_fw_ps_tdma( 1387 btcoexist, ps_tdma_byte0_val, 0x3f, 0x03, 1388 ps_tdma_byte3_val, 0x10); 1389 break; 1390 case 122: 1391 halbtc8723b1ant_set_fw_ps_tdma( 1392 btcoexist, ps_tdma_byte0_val, 0x25, 0x03, 1393 ps_tdma_byte3_val, 0x10); 1394 break; 1395 case 132: 1396 halbtc8723b1ant_set_fw_ps_tdma( 1397 btcoexist, ps_tdma_byte0_val, 0x25, 0x03, 1398 ps_tdma_byte3_val, ps_tdma_byte4_val); 1399 break; 1400 case 133: 1401 halbtc8723b1ant_set_fw_ps_tdma( 1402 btcoexist, ps_tdma_byte0_val, 0x25, 0x03, 1403 ps_tdma_byte3_val, 0x11); 1404 break; 1405 } 1406 } else { 1407 /* disable PS tdma */ 1408 switch (type) { 1409 case 8: /* PTA Control */ 1410 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x8, 0x0, 1411 0x0, 0x0, 0x0); 1412 halbtc8723b1ant_set_ant_path(btcoexist, 1413 BTC_ANT_PATH_PTA, 1414 FORCE_EXEC, 1415 false, false); 1416 break; 1417 case 0: 1418 default: 1419 /* Software control, Antenna at BT side */ 1420 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 1421 0x0, 0x0, 0x0); 1422 break; 1423 case 1: /* 2-Ant, 0x778=3, antenna control by ant diversity */ 1424 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0, 1425 0x48, 0x0); 1426 break; 1427 } 1428 } 1429 rssi_adjust_val = 0; 1430 btcoexist->btc_set(btcoexist, 1431 BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, 1432 &rssi_adjust_val); 1433 1434 /* update pre state */ 1435 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; 1436 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; 1437 } 1438 1439 void btc8723b1ant_tdma_dur_adj_for_acl(struct btc_coexist *btcoexist, 1440 u8 wifi_status) 1441 { 1442 struct rtl_priv *rtlpriv = btcoexist->adapter; 1443 static s32 up, dn, m, n, wait_count; 1444 /* 0: no change, +1: increase WiFi duration, 1445 * -1: decrease WiFi duration 1446 */ 1447 s32 result; 1448 u8 retry_count = 0, bt_info_ext; 1449 bool wifi_busy = false; 1450 1451 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1452 "[BTCoex], TdmaDurationAdjustForAcl()\n"); 1453 1454 if (wifi_status == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY) 1455 wifi_busy = true; 1456 else 1457 wifi_busy = false; 1458 1459 if ((wifi_status == 1460 BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN) || 1461 (wifi_status == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN) || 1462 (wifi_status == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT)) { 1463 if (coex_dm->cur_ps_tdma != 1 && coex_dm->cur_ps_tdma != 2 && 1464 coex_dm->cur_ps_tdma != 3 && coex_dm->cur_ps_tdma != 9) { 1465 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1466 true, 9); 1467 coex_dm->ps_tdma_du_adj_type = 9; 1468 1469 up = 0; 1470 dn = 0; 1471 m = 1; 1472 n = 3; 1473 result = 0; 1474 wait_count = 0; 1475 } 1476 return; 1477 } 1478 1479 if (!coex_dm->auto_tdma_adjust) { 1480 coex_dm->auto_tdma_adjust = true; 1481 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1482 "[BTCoex], first run TdmaDurationAdjust()!!\n"); 1483 1484 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2); 1485 coex_dm->ps_tdma_du_adj_type = 2; 1486 1487 up = 0; 1488 dn = 0; 1489 m = 1; 1490 n = 3; 1491 result = 0; 1492 wait_count = 0; 1493 } else { 1494 /* acquire the BT TRx retry count from BT_Info byte2 */ 1495 retry_count = coex_sta->bt_retry_cnt; 1496 bt_info_ext = coex_sta->bt_info_ext; 1497 1498 if ((coex_sta->low_priority_tx) > 1050 || 1499 (coex_sta->low_priority_rx) > 1250) 1500 retry_count++; 1501 1502 result = 0; 1503 wait_count++; 1504 /* no retry in the last 2-second duration */ 1505 if (retry_count == 0) { 1506 up++; 1507 dn--; 1508 1509 if (dn <= 0) 1510 dn = 0; 1511 1512 if (up >= n) { 1513 /* if retry count during continuous n*2 seconds 1514 * is 0, enlarge WiFi duration 1515 */ 1516 wait_count = 0; 1517 n = 3; 1518 up = 0; 1519 dn = 0; 1520 result = 1; 1521 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1522 "[BTCoex], Increase wifi duration!!\n"); 1523 } 1524 } else if (retry_count <= 3) { 1525 /* <=3 retry in the last 2-second duration */ 1526 up--; 1527 dn++; 1528 1529 if (up <= 0) 1530 up = 0; 1531 1532 if (dn == 2) { 1533 /* if continuous 2 retry count(every 2 seconds) 1534 * >0 and < 3, reduce WiFi duration 1535 */ 1536 if (wait_count <= 2) 1537 /* avoid loop between the two levels */ 1538 m++; 1539 else 1540 m = 1; 1541 1542 if (m >= 20) 1543 /* maximum of m = 20 ' will recheck if 1544 * need to adjust wifi duration in 1545 * maximum time interval 120 seconds 1546 */ 1547 m = 20; 1548 1549 n = 3 * m; 1550 up = 0; 1551 dn = 0; 1552 wait_count = 0; 1553 result = -1; 1554 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1555 "[BTCoex], Decrease wifi duration for retryCounter<3!!\n"); 1556 } 1557 } else { 1558 /* retry count > 3, once retry count > 3, to reduce 1559 * WiFi duration 1560 */ 1561 if (wait_count == 1) 1562 /* to avoid loop between the two levels */ 1563 m++; 1564 else 1565 m = 1; 1566 1567 if (m >= 20) 1568 /* maximum of m = 20 ' will recheck if need to 1569 * adjust wifi duration in maximum time interval 1570 * 120 seconds 1571 */ 1572 m = 20; 1573 1574 n = 3 * m; 1575 up = 0; 1576 dn = 0; 1577 wait_count = 0; 1578 result = -1; 1579 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1580 "[BTCoex], Decrease wifi duration for retryCounter>3!!\n"); 1581 } 1582 1583 if (result == -1) { 1584 if (coex_dm->cur_ps_tdma == 1) { 1585 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1586 true, 2); 1587 coex_dm->ps_tdma_du_adj_type = 2; 1588 } else if (coex_dm->cur_ps_tdma == 2) { 1589 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1590 true, 9); 1591 coex_dm->ps_tdma_du_adj_type = 9; 1592 } else if (coex_dm->cur_ps_tdma == 9) { 1593 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1594 true, 11); 1595 coex_dm->ps_tdma_du_adj_type = 11; 1596 } 1597 } else if (result == 1) { 1598 if (coex_dm->cur_ps_tdma == 11) { 1599 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1600 true, 9); 1601 coex_dm->ps_tdma_du_adj_type = 9; 1602 } else if (coex_dm->cur_ps_tdma == 9) { 1603 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1604 true, 2); 1605 coex_dm->ps_tdma_du_adj_type = 2; 1606 } else if (coex_dm->cur_ps_tdma == 2) { 1607 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1608 true, 1); 1609 coex_dm->ps_tdma_du_adj_type = 1; 1610 } 1611 } 1612 1613 if (coex_dm->cur_ps_tdma != 1 && coex_dm->cur_ps_tdma != 2 && 1614 coex_dm->cur_ps_tdma != 9 && coex_dm->cur_ps_tdma != 11) { 1615 /* recover to previous adjust type */ 1616 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1617 coex_dm->ps_tdma_du_adj_type); 1618 } 1619 } 1620 } 1621 1622 static void halbtc8723b1ant_ps_tdma_chk_pwr_save(struct btc_coexist *btcoexist, 1623 bool new_ps_state) 1624 { 1625 u8 lps_mode = 0x0; 1626 1627 btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); 1628 1629 if (lps_mode) { 1630 /* already under LPS state */ 1631 if (new_ps_state) { 1632 /* keep state under LPS, do nothing. */ 1633 } else { 1634 /* will leave LPS state, turn off psTdma first */ 1635 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1636 false, 0); 1637 } 1638 } else { 1639 /* NO PS state */ 1640 if (new_ps_state) { 1641 /* will enter LPS state, turn off psTdma first */ 1642 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1643 false, 0); 1644 } else { 1645 /* keep state under NO PS state, do nothing. */ 1646 } 1647 } 1648 } 1649 1650 static void halbtc8723b1ant_power_save_state(struct btc_coexist *btcoexist, 1651 u8 ps_type, u8 lps_val, 1652 u8 rpwm_val) 1653 { 1654 bool low_pwr_disable = false; 1655 1656 switch (ps_type) { 1657 case BTC_PS_WIFI_NATIVE: 1658 /* recover to original 32k low power setting */ 1659 low_pwr_disable = false; 1660 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER, 1661 &low_pwr_disable); 1662 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, NULL); 1663 coex_sta->force_lps_on = false; 1664 break; 1665 case BTC_PS_LPS_ON: 1666 halbtc8723b1ant_ps_tdma_chk_pwr_save(btcoexist, true); 1667 halbtc8723b1ant_lps_rpwm(btcoexist, NORMAL_EXEC, lps_val, 1668 rpwm_val); 1669 /* when coex force to enter LPS, do not enter 32k low power */ 1670 low_pwr_disable = true; 1671 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER, 1672 &low_pwr_disable); 1673 /* power save must executed before psTdma */ 1674 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, NULL); 1675 coex_sta->force_lps_on = true; 1676 break; 1677 case BTC_PS_LPS_OFF: 1678 halbtc8723b1ant_ps_tdma_chk_pwr_save(btcoexist, false); 1679 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, NULL); 1680 coex_sta->force_lps_on = false; 1681 break; 1682 default: 1683 break; 1684 } 1685 } 1686 1687 static void halbtc8723b1ant_action_wifi_only(struct btc_coexist *btcoexist) 1688 { 1689 halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); 1690 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); 1691 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, 1692 FORCE_EXEC, false, false); 1693 } 1694 1695 /* check if BT is disabled */ 1696 static void halbtc8723b1ant_monitor_bt_enable_disable(struct btc_coexist 1697 *btcoexist) 1698 { 1699 struct rtl_priv *rtlpriv = btcoexist->adapter; 1700 static u32 bt_disable_cnt; 1701 bool bt_active = true, bt_disabled = false; 1702 1703 if (coex_sta->high_priority_tx == 0 && 1704 coex_sta->high_priority_rx == 0 && coex_sta->low_priority_tx == 0 && 1705 coex_sta->low_priority_rx == 0) 1706 bt_active = false; 1707 if (coex_sta->high_priority_tx == 0xffff && 1708 coex_sta->high_priority_rx == 0xffff && 1709 coex_sta->low_priority_tx == 0xffff && 1710 coex_sta->low_priority_rx == 0xffff) 1711 bt_active = false; 1712 if (bt_active) { 1713 bt_disable_cnt = 0; 1714 bt_disabled = false; 1715 } else { 1716 bt_disable_cnt++; 1717 if (bt_disable_cnt >= 2) 1718 bt_disabled = true; 1719 } 1720 if (coex_sta->bt_disabled != bt_disabled) { 1721 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1722 "[BTCoex], BT is from %s to %s!!\n", 1723 (coex_sta->bt_disabled ? "disabled" : "enabled"), 1724 (bt_disabled ? "disabled" : "enabled")); 1725 1726 coex_sta->bt_disabled = bt_disabled; 1727 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, 1728 &bt_disabled); 1729 if (bt_disabled) { 1730 halbtc8723b1ant_action_wifi_only(btcoexist); 1731 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, 1732 NULL); 1733 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, 1734 NULL); 1735 } 1736 } 1737 } 1738 1739 /***************************************************** 1740 * 1741 * Non-Software Coex Mechanism start 1742 * 1743 *****************************************************/ 1744 1745 static void halbtc8723b1ant_action_bt_whck_test(struct btc_coexist *btcoexist) 1746 { 1747 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 1748 0x0); 1749 1750 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 1751 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, 1752 false, false); 1753 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); 1754 } 1755 1756 static void halbtc8723b1ant_action_wifi_multiport(struct btc_coexist *btcoexist) 1757 { 1758 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1759 0x0, 0x0); 1760 1761 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 1762 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, 1763 false, false); 1764 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); 1765 } 1766 1767 static void halbtc8723b1ant_action_hs(struct btc_coexist *btcoexist) 1768 { 1769 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); 1770 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); 1771 } 1772 1773 static void halbtc8723b1ant_action_bt_inquiry(struct btc_coexist *btcoexist) 1774 { 1775 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1776 bool wifi_connected = false, ap_enable = false; 1777 bool wifi_busy = false, bt_busy = false; 1778 1779 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, 1780 &ap_enable); 1781 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 1782 &wifi_connected); 1783 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 1784 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); 1785 1786 if (coex_sta->bt_abnormal_scan) { 1787 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33); 1788 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); 1789 } else if (!wifi_connected && !coex_sta->wifi_is_high_pri_task) { 1790 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1791 0x0, 0x0); 1792 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 1793 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, 1794 NORMAL_EXEC, false, false); 1795 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); 1796 } else if (bt_link_info->sco_exist || bt_link_info->hid_exist || 1797 bt_link_info->a2dp_exist) { 1798 /* SCO/HID/A2DP busy */ 1799 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1800 0x0, 0x0); 1801 if (coex_sta->c2h_bt_remote_name_req) 1802 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1803 33); 1804 else 1805 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1806 32); 1807 1808 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); 1809 } else if (bt_link_info->pan_exist || wifi_busy) { 1810 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1811 0x0, 0x0); 1812 if (coex_sta->c2h_bt_remote_name_req) 1813 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1814 33); 1815 else 1816 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1817 32); 1818 1819 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); 1820 } else { 1821 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1822 0x0, 0x0); 1823 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 1824 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, 1825 NORMAL_EXEC, false, false); 1826 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); 1827 } 1828 } 1829 1830 static void btc8723b1ant_act_bt_sco_hid_only_busy(struct btc_coexist *btcoexist, 1831 u8 wifi_status) 1832 { 1833 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1834 bool wifi_connected = false; 1835 1836 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 1837 &wifi_connected); 1838 1839 /* tdma and coex table */ 1840 if (bt_link_info->sco_exist) { 1841 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); 1842 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); 1843 } else { 1844 /* HID */ 1845 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6); 1846 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); 1847 } 1848 } 1849 1850 static void halbtc8723b1ant_action_wifi_connected_bt_acl_busy( 1851 struct btc_coexist *btcoexist, 1852 u8 wifi_status) 1853 { 1854 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1855 1856 if ((coex_sta->low_priority_rx >= 950) && (!coex_sta->under_ips)) 1857 bt_link_info->slave_role = true; 1858 else 1859 bt_link_info->slave_role = false; 1860 1861 if (bt_link_info->hid_only) { /* HID */ 1862 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist, wifi_status); 1863 coex_dm->auto_tdma_adjust = false; 1864 return; 1865 } else if (bt_link_info->a2dp_only) { /* A2DP */ 1866 if (wifi_status == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE) { 1867 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1868 true, 32); 1869 halbtc8723b1ant_coex_table_with_type(btcoexist, 1870 NORMAL_EXEC, 4); 1871 coex_dm->auto_tdma_adjust = false; 1872 } else { 1873 btc8723b1ant_tdma_dur_adj_for_acl(btcoexist, 1874 wifi_status); 1875 halbtc8723b1ant_coex_table_with_type(btcoexist, 1876 NORMAL_EXEC, 1); 1877 coex_dm->auto_tdma_adjust = true; 1878 } 1879 } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) || 1880 (bt_link_info->hid_exist && bt_link_info->a2dp_exist && 1881 bt_link_info->pan_exist)) { 1882 /* A2DP + PAN(OPP,FTP), HID + A2DP + PAN(OPP,FTP) */ 1883 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13); 1884 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); 1885 coex_dm->auto_tdma_adjust = false; 1886 } else if (bt_link_info->hid_exist && bt_link_info->a2dp_exist) { 1887 /* HID + A2DP */ 1888 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14); 1889 coex_dm->auto_tdma_adjust = false; 1890 1891 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); 1892 } else if (bt_link_info->pan_only || 1893 (bt_link_info->hid_exist && bt_link_info->pan_exist)) { 1894 /* PAN(OPP,FTP), HID + PAN(OPP,FTP) */ 1895 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3); 1896 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); 1897 coex_dm->auto_tdma_adjust = false; 1898 } else { 1899 /* BT no-profile busy (0x9) */ 1900 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33); 1901 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); 1902 coex_dm->auto_tdma_adjust = false; 1903 } 1904 } 1905 1906 static void btc8723b1ant_action_wifi_not_conn(struct btc_coexist *btcoexist) 1907 { 1908 /* power save state */ 1909 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1910 0x0, 0x0); 1911 1912 /* tdma and coex table */ 1913 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); 1914 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, 1915 false, false); 1916 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); 1917 } 1918 1919 static void 1920 btc8723b1ant_action_wifi_not_conn_scan(struct btc_coexist *btcoexist) 1921 { 1922 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1923 1924 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1925 0x0, 0x0); 1926 1927 /* tdma and coex table */ 1928 if (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) { 1929 if (bt_link_info->a2dp_exist) { 1930 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1931 true, 32); 1932 halbtc8723b1ant_coex_table_with_type(btcoexist, 1933 NORMAL_EXEC, 4); 1934 } else if (bt_link_info->a2dp_exist) { 1935 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1936 true, 22); 1937 halbtc8723b1ant_coex_table_with_type(btcoexist, 1938 NORMAL_EXEC, 4); 1939 } else { 1940 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1941 true, 20); 1942 halbtc8723b1ant_coex_table_with_type(btcoexist, 1943 NORMAL_EXEC, 1); 1944 } 1945 } else if (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_SCO_BUSY || 1946 coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY){ 1947 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist, 1948 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN); 1949 } else { 1950 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 1951 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, 1952 NORMAL_EXEC, false, false); 1953 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); 1954 } 1955 } 1956 1957 static void 1958 btc8723b1ant_act_wifi_not_conn_asso_auth(struct btc_coexist *btcoexist) 1959 { 1960 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1961 1962 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1963 0x0, 0x0); 1964 1965 /* tdma and coex table */ 1966 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) || 1967 (bt_link_info->a2dp_exist)) { 1968 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); 1969 halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4); 1970 } else if (bt_link_info->pan_exist) { 1971 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); 1972 halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4); 1973 } else { 1974 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 1975 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, 1976 NORMAL_EXEC, false, false); 1977 halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 2); 1978 } 1979 } 1980 1981 static void btc8723b1ant_action_wifi_conn_scan(struct btc_coexist *btcoexist) 1982 { 1983 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1984 1985 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1986 0x0, 0x0); 1987 1988 /* tdma and coex table */ 1989 if (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) { 1990 if (bt_link_info->a2dp_exist) { 1991 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1992 true, 32); 1993 halbtc8723b1ant_coex_table_with_type(btcoexist, 1994 NORMAL_EXEC, 4); 1995 } else if (bt_link_info->a2dp_exist && 1996 bt_link_info->pan_exist) { 1997 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 1998 true, 22); 1999 halbtc8723b1ant_coex_table_with_type(btcoexist, 2000 NORMAL_EXEC, 4); 2001 } else { 2002 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 2003 true, 20); 2004 halbtc8723b1ant_coex_table_with_type(btcoexist, 2005 NORMAL_EXEC, 4); 2006 } 2007 } else if (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_SCO_BUSY || 2008 coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) { 2009 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist, 2010 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN); 2011 } else { 2012 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 2013 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, 2014 NORMAL_EXEC, false, false); 2015 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); 2016 } 2017 } 2018 2019 static void halbtc8723b1ant_action_wifi_connected_special_packet( 2020 struct btc_coexist *btcoexist) 2021 { 2022 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 2023 bool wifi_busy = false; 2024 2025 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 2026 2027 /* no special packet process for both WiFi and BT very busy */ 2028 if ((wifi_busy) && 2029 ((bt_link_info->pan_exist) || (coex_sta->num_of_profile >= 2))) 2030 return; 2031 2032 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 2033 0x0, 0x0); 2034 2035 /* tdma and coex table */ 2036 if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) { 2037 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); 2038 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); 2039 } else if (bt_link_info->a2dp_exist) { 2040 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); 2041 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); 2042 } else if (bt_link_info->pan_exist) { 2043 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); 2044 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); 2045 } else { 2046 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); 2047 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, 2048 NORMAL_EXEC, false, false); 2049 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); 2050 } 2051 } 2052 2053 static void halbtc8723b1ant_action_wifi_connected(struct btc_coexist *btcoexist) 2054 { 2055 struct rtl_priv *rtlpriv = btcoexist->adapter; 2056 bool wifi_busy = false; 2057 bool scan = false, link = false, roam = false; 2058 bool under_4way = false, ap_enable = false; 2059 2060 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2061 "[BTCoex], CoexForWifiConnect()===>\n"); 2062 2063 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, 2064 &under_4way); 2065 if (under_4way) { 2066 halbtc8723b1ant_action_wifi_connected_special_packet(btcoexist); 2067 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2068 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"); 2069 return; 2070 } 2071 2072 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); 2073 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); 2074 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); 2075 2076 if (scan || link || roam) { 2077 if (scan) 2078 btc8723b1ant_action_wifi_conn_scan(btcoexist); 2079 else 2080 halbtc8723b1ant_action_wifi_connected_special_packet( 2081 btcoexist); 2082 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2083 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"); 2084 return; 2085 } 2086 2087 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, 2088 &ap_enable); 2089 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 2090 /* power save state */ 2091 if (!ap_enable && 2092 coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY && 2093 !btcoexist->bt_link_info.hid_only) { 2094 if (btcoexist->bt_link_info.a2dp_only) { 2095 if (!wifi_busy) { 2096 halbtc8723b1ant_power_save_state(btcoexist, 2097 BTC_PS_WIFI_NATIVE, 2098 0x0, 0x0); 2099 } else { /* busy */ 2100 if (coex_sta->scan_ap_num >= 2101 BT_8723B_1ANT_WIFI_NOISY_THRESH) 2102 /* no force LPS, no PS-TDMA, 2103 * use pure TDMA 2104 */ 2105 halbtc8723b1ant_power_save_state( 2106 btcoexist, BTC_PS_WIFI_NATIVE, 2107 0x0, 0x0); 2108 else 2109 halbtc8723b1ant_power_save_state( 2110 btcoexist, BTC_PS_LPS_ON, 0x50, 2111 0x4); 2112 } 2113 } else if ((!coex_sta->pan_exist) && (!coex_sta->a2dp_exist) && 2114 (!coex_sta->hid_exist)) 2115 halbtc8723b1ant_power_save_state( 2116 btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); 2117 else 2118 halbtc8723b1ant_power_save_state(btcoexist, 2119 BTC_PS_LPS_ON, 2120 0x50, 0x4); 2121 } else { 2122 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 2123 0x0, 0x0); 2124 } 2125 /* tdma and coex table */ 2126 if (!wifi_busy) { 2127 if (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) { 2128 halbtc8723b1ant_action_wifi_connected_bt_acl_busy( 2129 btcoexist, 2130 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE); 2131 } else if (coex_dm->bt_status == 2132 BT_8723B_1ANT_BT_STATUS_SCO_BUSY || 2133 coex_dm->bt_status == 2134 BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) { 2135 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist, 2136 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE); 2137 } else { 2138 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 2139 false, 8); 2140 halbtc8723b1ant_set_ant_path(btcoexist, 2141 BTC_ANT_PATH_PTA, 2142 NORMAL_EXEC, false, false); 2143 halbtc8723b1ant_coex_table_with_type(btcoexist, 2144 NORMAL_EXEC, 2); 2145 } 2146 } else { 2147 if (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) { 2148 halbtc8723b1ant_action_wifi_connected_bt_acl_busy( 2149 btcoexist, 2150 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY); 2151 } else if (coex_dm->bt_status == 2152 BT_8723B_1ANT_BT_STATUS_SCO_BUSY || 2153 coex_dm->bt_status == 2154 BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) { 2155 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist, 2156 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY); 2157 } else { 2158 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, 2159 true, 32); 2160 halbtc8723b1ant_set_ant_path(btcoexist, 2161 BTC_ANT_PATH_PTA, 2162 NORMAL_EXEC, false, false); 2163 halbtc8723b1ant_coex_table_with_type(btcoexist, 2164 NORMAL_EXEC, 4); 2165 } 2166 } 2167 } 2168 2169 static void halbtc8723b1ant_run_coexist_mechanism(struct btc_coexist *btcoexist) 2170 { 2171 struct rtl_priv *rtlpriv = btcoexist->adapter; 2172 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 2173 bool wifi_connected = false, bt_hs_on = false, wifi_busy = false; 2174 bool increase_scan_dev_num = false; 2175 bool bt_ctrl_agg_buf_size = false; 2176 bool miracast_plus_bt = false; 2177 u8 agg_buf_size = 5; 2178 u8 iot_peer = BTC_IOT_PEER_UNKNOWN; 2179 u32 wifi_link_status = 0; 2180 u32 num_of_wifi_link = 0; 2181 u32 wifi_bw; 2182 2183 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2184 "[BTCoex], RunCoexistMechanism()===>\n"); 2185 2186 if (btcoexist->manual_control) { 2187 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2188 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); 2189 return; 2190 } 2191 2192 if (btcoexist->stop_coex_dm) { 2193 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2194 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"); 2195 return; 2196 } 2197 2198 if (coex_sta->under_ips) { 2199 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2200 "[BTCoex], wifi is under IPS !!!\n"); 2201 return; 2202 } 2203 2204 if (coex_sta->bt_whck_test) { 2205 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2206 "[BTCoex], wifi is under IPS !!!\n"); 2207 halbtc8723b1ant_action_bt_whck_test(btcoexist); 2208 return; 2209 } 2210 2211 if (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY || 2212 coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_SCO_BUSY || 2213 coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) 2214 increase_scan_dev_num = true; 2215 2216 btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, 2217 &increase_scan_dev_num); 2218 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 2219 &wifi_connected); 2220 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 2221 2222 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, 2223 &wifi_link_status); 2224 num_of_wifi_link = wifi_link_status >> 16; 2225 2226 if (num_of_wifi_link >= 2 || 2227 wifi_link_status & WIFI_P2P_GO_CONNECTED) { 2228 if (bt_link_info->bt_link_exist) { 2229 halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 2230 0, 1); 2231 miracast_plus_bt = true; 2232 } else { 2233 halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 2234 0, 0); 2235 miracast_plus_bt = false; 2236 } 2237 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, 2238 &miracast_plus_bt); 2239 halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, 2240 bt_ctrl_agg_buf_size, agg_buf_size); 2241 2242 if ((bt_link_info->a2dp_exist || wifi_busy) && 2243 (coex_sta->c2h_bt_inquiry_page)) 2244 halbtc8723b1ant_action_bt_inquiry(btcoexist); 2245 else 2246 halbtc8723b1ant_action_wifi_multiport(btcoexist); 2247 2248 return; 2249 } 2250 2251 miracast_plus_bt = false; 2252 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, 2253 &miracast_plus_bt); 2254 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 2255 2256 if (bt_link_info->bt_link_exist && wifi_connected) { 2257 halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1); 2258 2259 btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer); 2260 2261 if (iot_peer != BTC_IOT_PEER_CISCO && 2262 iot_peer != BTC_IOT_PEER_BROADCOM) { 2263 bool sco_exist = bt_link_info->sco_exist; 2264 2265 halbtc8723b1ant_limited_rx(btcoexist, 2266 NORMAL_EXEC, sco_exist, 2267 false, 0x5); 2268 } else { 2269 if (bt_link_info->sco_exist) { 2270 halbtc8723b1ant_limited_rx(btcoexist, 2271 NORMAL_EXEC, true, 2272 false, 0x5); 2273 } else { 2274 if (wifi_bw == BTC_WIFI_BW_HT40) 2275 halbtc8723b1ant_limited_rx( 2276 btcoexist, NORMAL_EXEC, false, 2277 true, 0x10); 2278 else 2279 halbtc8723b1ant_limited_rx( 2280 btcoexist, NORMAL_EXEC, false, 2281 true, 0x8); 2282 } 2283 } 2284 2285 halbtc8723b1ant_sw_mechanism(btcoexist, true); 2286 } else { 2287 halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); 2288 2289 halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 2290 0x5); 2291 2292 halbtc8723b1ant_sw_mechanism(btcoexist, false); 2293 } 2294 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 2295 2296 if (coex_sta->c2h_bt_inquiry_page) { 2297 halbtc8723b1ant_action_bt_inquiry(btcoexist); 2298 return; 2299 } else if (bt_hs_on) { 2300 halbtc8723b1ant_action_hs(btcoexist); 2301 return; 2302 } 2303 2304 if (!wifi_connected) { 2305 bool scan = false, link = false, roam = false; 2306 2307 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2308 "[BTCoex], wifi is non connected-idle !!!\n"); 2309 2310 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); 2311 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); 2312 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); 2313 2314 if (scan || link || roam) { 2315 if (scan) 2316 btc8723b1ant_action_wifi_not_conn_scan( 2317 btcoexist); 2318 else 2319 btc8723b1ant_act_wifi_not_conn_asso_auth( 2320 btcoexist); 2321 } else { 2322 btc8723b1ant_action_wifi_not_conn(btcoexist); 2323 } 2324 } else { /* wifi LPS/Busy */ 2325 halbtc8723b1ant_action_wifi_connected(btcoexist); 2326 } 2327 } 2328 2329 /* force coex mechanism to reset */ 2330 static void halbtc8723b1ant_init_coex_dm(struct btc_coexist *btcoexist) 2331 { 2332 /* sw all off */ 2333 halbtc8723b1ant_sw_mechanism(btcoexist, false); 2334 2335 coex_sta->pop_event_cnt = 0; 2336 } 2337 2338 static void halbtc8723b1ant_init_hw_config(struct btc_coexist *btcoexist, 2339 bool backup, bool wifi_only) 2340 { 2341 struct rtl_priv *rtlpriv = btcoexist->adapter; 2342 u32 u32tmp = 0; 2343 u8 u8tmpa = 0, u8tmpb = 0; 2344 2345 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2346 "[BTCoex], 1Ant Init HW Config!!\n"); 2347 2348 /* 0xf0[15:12] --> Chip Cut information */ 2349 coex_sta->cut_version = 2350 (btcoexist->btc_read_1byte(btcoexist, 0xf1) & 0xf0) >> 4; 2351 /* enable TBTT interrupt */ 2352 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, 0x1); 2353 2354 /* 0x790[5:0] = 0x5 */ 2355 btcoexist->btc_write_1byte(btcoexist, 0x790, 0x5); 2356 2357 /* Enable counter statistics */ 2358 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1); 2359 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1); 2360 2361 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); 2362 2363 /* Antenna config */ 2364 if (wifi_only) 2365 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI, 2366 FORCE_EXEC, true, false); 2367 else 2368 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, 2369 FORCE_EXEC, true, false); 2370 2371 /* PTA parameter */ 2372 halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); 2373 2374 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948); 2375 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); 2376 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67); 2377 2378 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2379 "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n", 2380 u32tmp, u8tmpa, u8tmpb); 2381 } 2382 2383 /************************************************************** 2384 * extern function start with ex_btc8723b1ant_ 2385 **************************************************************/ 2386 void ex_btc8723b1ant_power_on_setting(struct btc_coexist *btcoexist) 2387 { 2388 struct rtl_priv *rtlpriv = btcoexist->adapter; 2389 struct btc_board_info *board_info = &btcoexist->board_info; 2390 u8 u8tmp = 0x0; 2391 u16 u16tmp = 0x0; 2392 u32 value; 2393 2394 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2395 "xxxxxxxxxxxxxxxx Execute 8723b 1-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n"); 2396 2397 btcoexist->stop_coex_dm = true; 2398 2399 btcoexist->btc_write_1byte(btcoexist, 0x67, 0x20); 2400 2401 /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */ 2402 u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2); 2403 btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT0 | BIT1); 2404 2405 /* set GRAN_BT = 1 */ 2406 btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18); 2407 /* set WLAN_ACT = 0 */ 2408 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); 2409 2410 /* S0 or S1 setting and Local register setting(By the setting fw can get 2411 * ant number, S0/S1, ... info) 2412 * 2413 * Local setting bit define 2414 * BIT0: "0" for no antenna inverse; "1" for antenna inverse 2415 * BIT1: "0" for internal switch; "1" for external switch 2416 * BIT2: "0" for one antenna; "1" for two antenna 2417 * NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and 2418 * BIT2 = 0 2419 */ 2420 if (btcoexist->chip_interface == BTC_INTF_USB) { 2421 /* fixed at S0 for USB interface */ 2422 btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0); 2423 2424 u8tmp |= 0x1; /* antenna inverse */ 2425 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); 2426 2427 board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; 2428 } else { 2429 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */ 2430 if (board_info->single_ant_path == 0) { 2431 /* set to S1 */ 2432 btcoexist->btc_write_4byte(btcoexist, 0x948, 0x280); 2433 board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; 2434 value = 1; 2435 } else if (board_info->single_ant_path == 1) { 2436 /* set to S0 */ 2437 btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0); 2438 u8tmp |= 0x1; /* antenna inverse */ 2439 board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; 2440 value = 0; 2441 } 2442 2443 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ANTPOSREGRISTRY_CTRL, 2444 &value); 2445 2446 if (btcoexist->chip_interface == BTC_INTF_PCI) 2447 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x384, 2448 u8tmp); 2449 else if (btcoexist->chip_interface == BTC_INTF_SDIO) 2450 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, 2451 u8tmp); 2452 } 2453 } 2454 2455 2456 void ex_btc8723b1ant_init_hwconfig(struct btc_coexist *btcoexist, 2457 bool wifi_only) 2458 { 2459 halbtc8723b1ant_init_hw_config(btcoexist, true, wifi_only); 2460 btcoexist->stop_coex_dm = false; 2461 } 2462 2463 void ex_btc8723b1ant_init_coex_dm(struct btc_coexist *btcoexist) 2464 { 2465 struct rtl_priv *rtlpriv = btcoexist->adapter; 2466 2467 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2468 "[BTCoex], Coex Mechanism Init!!\n"); 2469 2470 btcoexist->stop_coex_dm = false; 2471 2472 halbtc8723b1ant_init_coex_dm(btcoexist); 2473 2474 halbtc8723b1ant_query_bt_info(btcoexist); 2475 } 2476 2477 void ex_btc8723b1ant_display_coex_info(struct btc_coexist *btcoexist) 2478 { 2479 struct btc_board_info *board_info = &btcoexist->board_info; 2480 struct btc_stack_info *stack_info = &btcoexist->stack_info; 2481 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 2482 struct rtl_priv *rtlpriv = btcoexist->adapter; 2483 u8 u8tmp[4], i, bt_info_ext, pstdmacase = 0; 2484 u16 u16tmp[4]; 2485 u32 u32tmp[4]; 2486 bool roam = false, scan = false; 2487 bool link = false, wifi_under_5g = false; 2488 bool bt_hs_on = false, wifi_busy = false; 2489 s32 wifi_rssi = 0, bt_hs_rssi = 0; 2490 u32 wifi_bw, wifi_traffic_dir, fa_ofdm, fa_cck, wifi_link_status; 2491 u8 wifi_dot11_chnl, wifi_hs_chnl; 2492 u32 fw_ver = 0, bt_patch_ver = 0; 2493 2494 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2495 "\r\n ============[BT Coexist info]============"); 2496 2497 if (btcoexist->manual_control) { 2498 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2499 "\r\n ============[Under Manual Control]=========="); 2500 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2501 "\r\n =========================================="); 2502 } 2503 if (btcoexist->stop_coex_dm) { 2504 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2505 "\r\n ============[Coex is STOPPED]============"); 2506 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2507 "\r\n =========================================="); 2508 } 2509 2510 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d", 2511 "Ant PG Num/ Ant Mech/ Ant Pos:", 2512 board_info->pg_ant_num, board_info->btdm_ant_num, 2513 board_info->btdm_ant_pos); 2514 2515 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s / %d", 2516 "BT stack/ hci ext ver", 2517 ((stack_info->profile_notified) ? "Yes" : "No"), 2518 stack_info->hci_version); 2519 2520 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); 2521 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); 2522 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2523 "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", 2524 "CoexVer/ FwVer/ PatchVer", 2525 glcoex_ver_date_8723b_1ant, glcoex_ver_8723b_1ant, 2526 fw_ver, bt_patch_ver, bt_patch_ver); 2527 2528 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 2529 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL, 2530 &wifi_dot11_chnl); 2531 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl); 2532 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d / %d(%d)", 2533 "Dot11 channel / HsChnl(HsMode)", 2534 wifi_dot11_chnl, wifi_hs_chnl, bt_hs_on); 2535 2536 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %3ph ", 2537 "H2C Wifi inform bt chnl Info", 2538 coex_dm->wifi_chnl_info); 2539 2540 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); 2541 btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi); 2542 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d", 2543 "Wifi rssi/ HS rssi", wifi_rssi, bt_hs_rssi); 2544 2545 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); 2546 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); 2547 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); 2548 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d ", 2549 "Wifi link/ roam/ scan", link, roam, scan); 2550 2551 btcoexist->btc_get(btcoexist , BTC_GET_BL_WIFI_UNDER_5G, 2552 &wifi_under_5g); 2553 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 2554 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 2555 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, 2556 &wifi_traffic_dir); 2557 2558 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s / %s/ %s ", 2559 "Wifi status", (wifi_under_5g ? "5G" : "2.4G"), 2560 ((wifi_bw == BTC_WIFI_BW_LEGACY) ? "Legacy" : 2561 ((wifi_bw == BTC_WIFI_BW_HT40) ? "HT40" : "HT20")), 2562 ((!wifi_busy) ? "idle" : 2563 ((wifi_traffic_dir == BTC_WIFI_TRAFFIC_TX) ? 2564 "uplink" : "downlink"))); 2565 2566 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, 2567 &wifi_link_status); 2568 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", 2569 "sta/vwifi/hs/p2pGo/p2pGc", 2570 ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0), 2571 ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0), 2572 ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0), 2573 ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0), 2574 ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0)); 2575 2576 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = [%s/ %d/ %d] ", 2577 "BT [status/ rssi/ retryCnt]", 2578 ((coex_sta->bt_disabled) ? ("disabled") : 2579 ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") : 2580 ((BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == 2581 coex_dm->bt_status) ? 2582 "non-connected idle" : 2583 ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == 2584 coex_dm->bt_status) ? 2585 "connected-idle" : "busy")))), 2586 coex_sta->bt_rssi, coex_sta->bt_retry_cnt); 2587 2588 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2589 "\r\n %-35s = %d / %d / %d / %d", 2590 "SCO/HID/PAN/A2DP", bt_link_info->sco_exist, 2591 bt_link_info->hid_exist, bt_link_info->pan_exist, 2592 bt_link_info->a2dp_exist); 2593 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO); 2594 2595 bt_info_ext = coex_sta->bt_info_ext; 2596 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s", 2597 "BT Info A2DP rate", 2598 (bt_info_ext & BIT0) ? "Basic rate" : "EDR rate"); 2599 2600 for (i = 0; i < BT_INFO_SRC_8723B_1ANT_MAX; i++) { 2601 if (coex_sta->bt_info_c2h_cnt[i]) { 2602 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2603 "\r\n %-35s = %7ph(%d)", 2604 glbt_info_src_8723b_1ant[i], 2605 coex_sta->bt_info_c2h[i], 2606 coex_sta->bt_info_c2h_cnt[i]); 2607 } 2608 } 2609 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2610 "\r\n %-35s = %s/%s, (0x%x/0x%x)", 2611 "PS state, IPS/LPS, (lps/rpwm)", 2612 ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")), 2613 ((coex_sta->under_lps ? "LPS ON" : "LPS OFF")), 2614 btcoexist->bt_info.lps_val, 2615 btcoexist->bt_info.rpwm_val); 2616 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD); 2617 2618 if (!btcoexist->manual_control) { 2619 /* Sw mechanism */ 2620 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s", 2621 "============[Sw mechanism]============"); 2622 2623 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/", 2624 "SM[LowPenaltyRA]", coex_dm->cur_low_penalty_ra); 2625 2626 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s/ %s/ %d ", 2627 "DelBA/ BtCtrlAgg/ AggSize", 2628 (btcoexist->bt_info.reject_agg_pkt ? "Yes" : "No"), 2629 (btcoexist->bt_info.bt_ctrl_buf_size ? "Yes" : "No"), 2630 btcoexist->bt_info.agg_buf_size); 2631 2632 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x ", 2633 "Rate Mask", btcoexist->bt_info.ra_mask); 2634 2635 /* Fw mechanism */ 2636 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s", 2637 "============[Fw mechanism]============"); 2638 2639 pstdmacase = coex_dm->cur_ps_tdma; 2640 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2641 "\r\n %-35s = %5ph case-%d (auto:%d)", 2642 "PS TDMA", coex_dm->ps_tdma_para, 2643 pstdmacase, coex_dm->auto_tdma_adjust); 2644 2645 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d ", 2646 "IgnWlanAct", coex_dm->cur_ignore_wlan_act); 2647 2648 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x ", 2649 "Latest error condition(should be 0)", 2650 coex_dm->error_condition); 2651 } 2652 2653 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d", 2654 "Coex Table Type", coex_sta->coex_table_type); 2655 2656 /* Hw setting */ 2657 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s", 2658 "============[Hw setting]============"); 2659 2660 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", 2661 "backup ARFR1/ARFR2/RL/AMaxTime", coex_dm->backup_arfr_cnt1, 2662 coex_dm->backup_arfr_cnt2, coex_dm->backup_retry_limit, 2663 coex_dm->backup_ampdu_max_time); 2664 2665 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430); 2666 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434); 2667 u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a); 2668 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456); 2669 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", 2670 "0x430/0x434/0x42a/0x456", 2671 u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]); 2672 2673 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); 2674 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc); 2675 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x880); 2676 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", 2677 "0x778/0x6cc/0x880[29:25]", u8tmp[0], u32tmp[0], 2678 (u32tmp[1] & 0x3e000000) >> 25); 2679 2680 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x948); 2681 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x67); 2682 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x765); 2683 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", 2684 "0x948/ 0x67[5] / 0x765", 2685 u32tmp[0], ((u8tmp[0] & 0x20) >> 5), u8tmp[1]); 2686 2687 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x92c); 2688 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x930); 2689 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x944); 2690 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", 2691 "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]", 2692 u32tmp[0] & 0x3, u32tmp[1] & 0xff, u32tmp[2] & 0x3); 2693 2694 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x39); 2695 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40); 2696 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c); 2697 u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64); 2698 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 2699 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", 2700 "0x38[11]/0x40/0x4c[24:23]/0x64[0]", 2701 ((u8tmp[0] & 0x8) >> 3), u8tmp[1], 2702 ((u32tmp[0] & 0x01800000) >> 23), u8tmp[2] & 0x1); 2703 2704 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); 2705 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); 2706 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x", 2707 "0x550(bcn ctrl)/0x522", u32tmp[0], u8tmp[0]); 2708 2709 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50); 2710 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x49c); 2711 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x", 2712 "0xc50(dig)/0x49c(null-drop)", u32tmp[0] & 0xff, u8tmp[0]); 2713 2714 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xda0); 2715 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xda4); 2716 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0xda8); 2717 u32tmp[3] = btcoexist->btc_read_4byte(btcoexist, 0xcf0); 2718 2719 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b); 2720 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c); 2721 2722 fa_ofdm = ((u32tmp[0] & 0xffff0000) >> 16) + 2723 ((u32tmp[1] & 0xffff0000) >> 16) + 2724 (u32tmp[1] & 0xffff) + 2725 (u32tmp[2] & 0xffff) + 2726 ((u32tmp[3] & 0xffff0000) >> 16) + 2727 (u32tmp[3] & 0xffff); 2728 fa_cck = (u8tmp[0] << 8) + u8tmp[1]; 2729 2730 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", 2731 "OFDM-CCA/OFDM-FA/CCK-FA", 2732 u32tmp[0] & 0xffff, fa_ofdm, fa_cck); 2733 2734 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); 2735 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); 2736 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); 2737 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", 2738 "0x6c0/0x6c4/0x6c8(coexTable)", 2739 u32tmp[0], u32tmp[1], u32tmp[2]); 2740 2741 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d", 2742 "0x770(high-pri rx/tx)", coex_sta->high_priority_rx, 2743 coex_sta->high_priority_tx); 2744 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d", 2745 "0x774(low-pri rx/tx)", coex_sta->low_priority_rx, 2746 coex_sta->low_priority_tx); 2747 if (btcoexist->auto_report_1ant) 2748 halbtc8723b1ant_monitor_bt_ctr(btcoexist); 2749 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); 2750 } 2751 2752 void ex_btc8723b1ant_ips_notify(struct btc_coexist *btcoexist, u8 type) 2753 { 2754 struct rtl_priv *rtlpriv = btcoexist->adapter; 2755 2756 if (btcoexist->manual_control || btcoexist->stop_coex_dm) 2757 return; 2758 2759 if (BTC_IPS_ENTER == type) { 2760 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2761 "[BTCoex], IPS ENTER notify\n"); 2762 coex_sta->under_ips = true; 2763 2764 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, 2765 FORCE_EXEC, false, true); 2766 /* set PTA control */ 2767 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); 2768 halbtc8723b1ant_coex_table_with_type(btcoexist, 2769 NORMAL_EXEC, 0); 2770 } else if (BTC_IPS_LEAVE == type) { 2771 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2772 "[BTCoex], IPS LEAVE notify\n"); 2773 coex_sta->under_ips = false; 2774 2775 halbtc8723b1ant_init_hw_config(btcoexist, false, false); 2776 halbtc8723b1ant_init_coex_dm(btcoexist); 2777 halbtc8723b1ant_query_bt_info(btcoexist); 2778 } 2779 } 2780 2781 void ex_btc8723b1ant_lps_notify(struct btc_coexist *btcoexist, u8 type) 2782 { 2783 struct rtl_priv *rtlpriv = btcoexist->adapter; 2784 2785 if (btcoexist->manual_control || btcoexist->stop_coex_dm) 2786 return; 2787 2788 if (BTC_LPS_ENABLE == type) { 2789 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2790 "[BTCoex], LPS ENABLE notify\n"); 2791 coex_sta->under_lps = true; 2792 } else if (BTC_LPS_DISABLE == type) { 2793 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2794 "[BTCoex], LPS DISABLE notify\n"); 2795 coex_sta->under_lps = false; 2796 } 2797 } 2798 2799 void ex_btc8723b1ant_scan_notify(struct btc_coexist *btcoexist, u8 type) 2800 { 2801 struct rtl_priv *rtlpriv = btcoexist->adapter; 2802 bool wifi_connected = false, bt_hs_on = false; 2803 u8 u8tmpa, u8tmpb; 2804 u32 u32tmp; 2805 u32 wifi_link_status = 0; 2806 u32 num_of_wifi_link = 0; 2807 bool bt_ctrl_agg_buf_size = false; 2808 u8 agg_buf_size = 5; 2809 2810 if (btcoexist->manual_control || btcoexist->stop_coex_dm) 2811 return; 2812 2813 if (type == BTC_SCAN_START) { 2814 coex_sta->wifi_is_high_pri_task = true; 2815 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2816 "[BTCoex], SCAN START notify\n"); 2817 /* Force antenna setup for no scan result issue */ 2818 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); 2819 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, 2820 FORCE_EXEC, false, false); 2821 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948); 2822 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); 2823 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67); 2824 2825 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2826 "[BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n", 2827 u32tmp, u8tmpa, u8tmpb); 2828 } else { 2829 coex_sta->wifi_is_high_pri_task = false; 2830 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2831 "[BTCoex], SCAN FINISH notify\n"); 2832 2833 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, 2834 &coex_sta->scan_ap_num); 2835 } 2836 2837 if (coex_sta->bt_disabled) 2838 return; 2839 2840 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 2841 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 2842 &wifi_connected); 2843 2844 halbtc8723b1ant_query_bt_info(btcoexist); 2845 2846 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, 2847 &wifi_link_status); 2848 num_of_wifi_link = wifi_link_status >> 16; 2849 if (num_of_wifi_link >= 2) { 2850 halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); 2851 halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, 2852 bt_ctrl_agg_buf_size, agg_buf_size); 2853 halbtc8723b1ant_action_wifi_multiport(btcoexist); 2854 return; 2855 } 2856 2857 if (coex_sta->c2h_bt_inquiry_page) { 2858 halbtc8723b1ant_action_bt_inquiry(btcoexist); 2859 return; 2860 } else if (bt_hs_on) { 2861 halbtc8723b1ant_action_hs(btcoexist); 2862 return; 2863 } 2864 2865 if (BTC_SCAN_START == type) { 2866 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2867 "[BTCoex], SCAN START notify\n"); 2868 if (!wifi_connected) 2869 /* non-connected scan */ 2870 btc8723b1ant_action_wifi_not_conn_scan(btcoexist); 2871 else 2872 /* wifi is connected */ 2873 btc8723b1ant_action_wifi_conn_scan(btcoexist); 2874 } else if (BTC_SCAN_FINISH == type) { 2875 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2876 "[BTCoex], SCAN FINISH notify\n"); 2877 if (!wifi_connected) 2878 /* non-connected scan */ 2879 btc8723b1ant_action_wifi_not_conn(btcoexist); 2880 else 2881 halbtc8723b1ant_action_wifi_connected(btcoexist); 2882 } 2883 } 2884 2885 void ex_btc8723b1ant_connect_notify(struct btc_coexist *btcoexist, u8 type) 2886 { 2887 struct rtl_priv *rtlpriv = btcoexist->adapter; 2888 bool wifi_connected = false, bt_hs_on = false; 2889 u32 wifi_link_status = 0; 2890 u32 num_of_wifi_link = 0; 2891 bool bt_ctrl_agg_buf_size = false, under_4way = false; 2892 u8 agg_buf_size = 5; 2893 2894 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, 2895 &under_4way); 2896 2897 if (btcoexist->manual_control || btcoexist->stop_coex_dm || 2898 coex_sta->bt_disabled) 2899 return; 2900 2901 if (type == BTC_ASSOCIATE_START) { 2902 coex_sta->wifi_is_high_pri_task = true; 2903 2904 /* Force antenna setup for no scan result issue */ 2905 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); 2906 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, 2907 FORCE_EXEC, false, false); 2908 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2909 "[BTCoex], CONNECT START notify\n"); 2910 coex_dm->arp_cnt = 0; 2911 } else { 2912 coex_sta->wifi_is_high_pri_task = false; 2913 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2914 "[BTCoex], CONNECT FINISH notify\n"); 2915 } 2916 2917 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, 2918 &wifi_link_status); 2919 num_of_wifi_link = wifi_link_status>>16; 2920 if (num_of_wifi_link >= 2) { 2921 halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); 2922 halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, 2923 bt_ctrl_agg_buf_size, agg_buf_size); 2924 halbtc8723b1ant_action_wifi_multiport(btcoexist); 2925 return; 2926 } 2927 2928 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 2929 if (coex_sta->c2h_bt_inquiry_page) { 2930 halbtc8723b1ant_action_bt_inquiry(btcoexist); 2931 return; 2932 } else if (bt_hs_on) { 2933 halbtc8723b1ant_action_hs(btcoexist); 2934 return; 2935 } 2936 2937 if (BTC_ASSOCIATE_START == type) { 2938 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2939 "[BTCoex], CONNECT START notify\n"); 2940 btc8723b1ant_act_wifi_not_conn_asso_auth(btcoexist); 2941 } else if (BTC_ASSOCIATE_FINISH == type) { 2942 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2943 "[BTCoex], CONNECT FINISH notify\n"); 2944 2945 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 2946 &wifi_connected); 2947 if (!wifi_connected) 2948 /* non-connected scan */ 2949 btc8723b1ant_action_wifi_not_conn(btcoexist); 2950 else 2951 halbtc8723b1ant_action_wifi_connected(btcoexist); 2952 } 2953 } 2954 2955 void ex_btc8723b1ant_media_status_notify(struct btc_coexist *btcoexist, 2956 u8 type) 2957 { 2958 struct rtl_priv *rtlpriv = btcoexist->adapter; 2959 u8 h2c_parameter[3] = {0}; 2960 u32 wifi_bw; 2961 u8 wifi_central_chnl; 2962 bool wifi_under_b_mode = false; 2963 2964 if (btcoexist->manual_control || btcoexist->stop_coex_dm || 2965 coex_sta->bt_disabled) 2966 return; 2967 2968 if (type == BTC_MEDIA_CONNECT) { 2969 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2970 "[BTCoex], MEDIA connect notify\n"); 2971 /* Force antenna setup for no scan result issue */ 2972 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); 2973 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, 2974 FORCE_EXEC, false, false); 2975 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, 2976 &wifi_under_b_mode); 2977 2978 /* Set CCK Tx/Rx high Pri except 11b mode */ 2979 if (wifi_under_b_mode) { 2980 btcoexist->btc_write_1byte(btcoexist, 0x6cd, 2981 0x00); /* CCK Tx */ 2982 btcoexist->btc_write_1byte(btcoexist, 0x6cf, 2983 0x00); /* CCK Rx */ 2984 } else { 2985 btcoexist->btc_write_1byte(btcoexist, 0x6cd, 2986 0x00); /* CCK Tx */ 2987 btcoexist->btc_write_1byte(btcoexist, 0x6cf, 2988 0x10); /* CCK Rx */ 2989 } 2990 2991 coex_dm->backup_arfr_cnt1 = 2992 btcoexist->btc_read_4byte(btcoexist, 0x430); 2993 coex_dm->backup_arfr_cnt2 = 2994 btcoexist->btc_read_4byte(btcoexist, 0x434); 2995 coex_dm->backup_retry_limit = 2996 btcoexist->btc_read_2byte(btcoexist, 0x42a); 2997 coex_dm->backup_ampdu_max_time = 2998 btcoexist->btc_read_1byte(btcoexist, 0x456); 2999 } else { 3000 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3001 "[BTCoex], MEDIA disconnect notify\n"); 3002 coex_dm->arp_cnt = 0; 3003 3004 btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */ 3005 btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */ 3006 3007 coex_sta->cck_ever_lock = false; 3008 } 3009 3010 /* only 2.4G we need to inform bt the chnl mask */ 3011 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, 3012 &wifi_central_chnl); 3013 3014 if (type == BTC_MEDIA_CONNECT && wifi_central_chnl <= 14) { 3015 h2c_parameter[0] = 0x0; 3016 h2c_parameter[1] = wifi_central_chnl; 3017 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 3018 if (BTC_WIFI_BW_HT40 == wifi_bw) 3019 h2c_parameter[2] = 0x30; 3020 else 3021 h2c_parameter[2] = 0x20; 3022 } 3023 3024 coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; 3025 coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; 3026 coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; 3027 3028 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3029 "[BTCoex], FW write 0x66 = 0x%x\n", 3030 h2c_parameter[0] << 16 | h2c_parameter[1] << 8 | 3031 h2c_parameter[2]); 3032 3033 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); 3034 } 3035 3036 void ex_btc8723b1ant_special_packet_notify(struct btc_coexist *btcoexist, 3037 u8 type) 3038 { 3039 struct rtl_priv *rtlpriv = btcoexist->adapter; 3040 bool bt_hs_on = false; 3041 u32 wifi_link_status = 0; 3042 u32 num_of_wifi_link = 0; 3043 bool bt_ctrl_agg_buf_size = false, under_4way = false; 3044 u8 agg_buf_size = 5; 3045 3046 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, 3047 &under_4way); 3048 3049 if (btcoexist->manual_control || btcoexist->stop_coex_dm || 3050 coex_sta->bt_disabled) 3051 return; 3052 3053 if (type == BTC_PACKET_DHCP || type == BTC_PACKET_EAPOL || 3054 type == BTC_PACKET_ARP) { 3055 if (type == BTC_PACKET_ARP) { 3056 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3057 "[BTCoex], special Packet ARP notify\n"); 3058 3059 coex_dm->arp_cnt++; 3060 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3061 "[BTCoex], ARP Packet Count = %d\n", 3062 coex_dm->arp_cnt); 3063 3064 if ((coex_dm->arp_cnt >= 10) && (!under_4way)) 3065 /* if APR PKT > 10 after connect, do not go to 3066 * ActionWifiConnectedSpecificPacket(btcoexist) 3067 */ 3068 coex_sta->wifi_is_high_pri_task = false; 3069 else 3070 coex_sta->wifi_is_high_pri_task = true; 3071 } else { 3072 coex_sta->wifi_is_high_pri_task = true; 3073 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3074 "[BTCoex], special Packet DHCP or EAPOL notify\n"); 3075 } 3076 } else { 3077 coex_sta->wifi_is_high_pri_task = false; 3078 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3079 "[BTCoex], special Packet [Type = %d] notify\n", 3080 type); 3081 } 3082 3083 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, 3084 &wifi_link_status); 3085 num_of_wifi_link = wifi_link_status >> 16; 3086 if (num_of_wifi_link >= 2) { 3087 halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); 3088 halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, 3089 bt_ctrl_agg_buf_size, agg_buf_size); 3090 halbtc8723b1ant_action_wifi_multiport(btcoexist); 3091 return; 3092 } 3093 3094 coex_sta->special_pkt_period_cnt = 0; 3095 3096 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 3097 if (coex_sta->c2h_bt_inquiry_page) { 3098 halbtc8723b1ant_action_bt_inquiry(btcoexist); 3099 return; 3100 } else if (bt_hs_on) { 3101 halbtc8723b1ant_action_hs(btcoexist); 3102 return; 3103 } 3104 3105 if (BTC_PACKET_DHCP == type || 3106 BTC_PACKET_EAPOL == type) { 3107 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3108 "[BTCoex], special Packet(%d) notify\n", type); 3109 halbtc8723b1ant_action_wifi_connected_special_packet(btcoexist); 3110 } 3111 } 3112 3113 void ex_btc8723b1ant_bt_info_notify(struct btc_coexist *btcoexist, 3114 u8 *tmp_buf, u8 length) 3115 { 3116 struct rtl_priv *rtlpriv = btcoexist->adapter; 3117 u8 bt_info = 0; 3118 u8 i, rsp_source = 0; 3119 bool wifi_connected = false; 3120 bool bt_busy = false; 3121 3122 coex_sta->c2h_bt_info_req_sent = false; 3123 3124 rsp_source = tmp_buf[0] & 0xf; 3125 if (rsp_source >= BT_INFO_SRC_8723B_1ANT_MAX) 3126 rsp_source = BT_INFO_SRC_8723B_1ANT_WIFI_FW; 3127 coex_sta->bt_info_c2h_cnt[rsp_source]++; 3128 3129 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3130 "[BTCoex], Bt info[%d], length=%d, hex data = [", 3131 rsp_source, length); 3132 for (i = 0; i < length; i++) { 3133 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; 3134 if (i == 1) 3135 bt_info = tmp_buf[i]; 3136 if (i == length - 1) 3137 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3138 "0x%02x]\n", tmp_buf[i]); 3139 else 3140 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3141 "0x%02x, ", tmp_buf[i]); 3142 } 3143 3144 /* if 0xff, it means BT is under WHCK test */ 3145 if (bt_info == 0xff) 3146 coex_sta->bt_whck_test = true; 3147 else 3148 coex_sta->bt_whck_test = false; 3149 3150 if (rsp_source != BT_INFO_SRC_8723B_1ANT_WIFI_FW) { 3151 coex_sta->bt_retry_cnt = /* [3:0] */ 3152 coex_sta->bt_info_c2h[rsp_source][2] & 0xf; 3153 3154 if (coex_sta->bt_retry_cnt >= 1) 3155 coex_sta->pop_event_cnt++; 3156 3157 if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20) 3158 coex_sta->c2h_bt_remote_name_req = true; 3159 else 3160 coex_sta->c2h_bt_remote_name_req = false; 3161 3162 coex_sta->bt_rssi = 3163 coex_sta->bt_info_c2h[rsp_source][3] * 2 - 90; 3164 3165 coex_sta->bt_info_ext = 3166 coex_sta->bt_info_c2h[rsp_source][4]; 3167 3168 if (coex_sta->bt_info_c2h[rsp_source][1] == 0x49) { 3169 coex_sta->a2dp_bit_pool = 3170 coex_sta->bt_info_c2h[rsp_source][6]; 3171 } else { 3172 coex_sta->a2dp_bit_pool = 0; 3173 } 3174 3175 coex_sta->bt_tx_rx_mask = 3176 (coex_sta->bt_info_c2h[rsp_source][2] & 0x40); 3177 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK, 3178 &coex_sta->bt_tx_rx_mask); 3179 3180 if (!coex_sta->bt_tx_rx_mask) { 3181 /* BT into is responded by BT FW and BT RF REG 3182 * 0x3C != 0x15 => Need to switch BT TRx Mask 3183 */ 3184 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3185 "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n"); 3186 btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF, 3187 0x3c, 0x15); 3188 3189 /* BT TRx Mask lock 0x2c[0], 0x30[0] = 0 */ 3190 btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF, 3191 0x2c, 0x7c44); 3192 btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF, 3193 0x30, 0x7c44); 3194 } 3195 3196 /* Here we need to resend some wifi info to BT 3197 * because bt is reset and loss of the info. 3198 */ 3199 if (coex_sta->bt_info_ext & BIT1) { 3200 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3201 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); 3202 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 3203 &wifi_connected); 3204 if (wifi_connected) 3205 ex_btc8723b1ant_media_status_notify(btcoexist, 3206 BTC_MEDIA_CONNECT); 3207 else 3208 ex_btc8723b1ant_media_status_notify(btcoexist, 3209 BTC_MEDIA_DISCONNECT); 3210 } 3211 3212 if (coex_sta->bt_info_ext & BIT3) { 3213 if (!btcoexist->manual_control && 3214 !btcoexist->stop_coex_dm) { 3215 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3216 "[BTCoex], BT ext info bit3 check, set BT NOT ignore Wlan active!!\n"); 3217 halbtc8723b1ant_ignore_wlan_act(btcoexist, 3218 FORCE_EXEC, 3219 false); 3220 } 3221 } else { 3222 /* BT already NOT ignore Wlan active, do nothing here.*/ 3223 } 3224 if (!btcoexist->auto_report_1ant) { 3225 if (coex_sta->bt_info_ext & BIT4) { 3226 /* BT auto report already enabled, do nothing */ 3227 } else { 3228 halbtc8723b1ant_bt_auto_report(btcoexist, 3229 FORCE_EXEC, 3230 true); 3231 } 3232 } 3233 } 3234 3235 /* check BIT2 first ==> check if bt is under inquiry or page scan */ 3236 if (bt_info & BT_INFO_8723B_1ANT_B_INQ_PAGE) 3237 coex_sta->c2h_bt_inquiry_page = true; 3238 else 3239 coex_sta->c2h_bt_inquiry_page = false; 3240 3241 coex_sta->num_of_profile = 0; 3242 3243 /* set link exist status */ 3244 if (!(bt_info & BT_INFO_8723B_1ANT_B_CONNECTION)) { 3245 coex_sta->bt_link_exist = false; 3246 coex_sta->pan_exist = false; 3247 coex_sta->a2dp_exist = false; 3248 coex_sta->hid_exist = false; 3249 coex_sta->sco_exist = false; 3250 3251 coex_sta->bt_hi_pri_link_exist = false; 3252 } else { 3253 /* connection exists */ 3254 coex_sta->bt_link_exist = true; 3255 if (bt_info & BT_INFO_8723B_1ANT_B_FTP) { 3256 coex_sta->pan_exist = true; 3257 coex_sta->num_of_profile++; 3258 } else { 3259 coex_sta->pan_exist = false; 3260 } 3261 if (bt_info & BT_INFO_8723B_1ANT_B_A2DP) { 3262 coex_sta->a2dp_exist = true; 3263 coex_sta->num_of_profile++; 3264 } else { 3265 coex_sta->a2dp_exist = false; 3266 } 3267 if (bt_info & BT_INFO_8723B_1ANT_B_HID) { 3268 coex_sta->hid_exist = true; 3269 coex_sta->num_of_profile++; 3270 } else { 3271 coex_sta->hid_exist = false; 3272 } 3273 if (bt_info & BT_INFO_8723B_1ANT_B_SCO_ESCO) { 3274 coex_sta->sco_exist = true; 3275 coex_sta->num_of_profile++; 3276 } else { 3277 coex_sta->sco_exist = false; 3278 } 3279 3280 if ((!coex_sta->hid_exist) && 3281 (!coex_sta->c2h_bt_inquiry_page) && 3282 (!coex_sta->sco_exist)) { 3283 if (coex_sta->high_priority_tx + 3284 coex_sta->high_priority_rx >= 3285 160) { 3286 coex_sta->hid_exist = true; 3287 coex_sta->wrong_profile_notification++; 3288 coex_sta->num_of_profile++; 3289 bt_info = bt_info | 0x28; 3290 } 3291 } 3292 3293 /* Add Hi-Pri Tx/Rx counter to avoid false detection */ 3294 if (((coex_sta->hid_exist) || (coex_sta->sco_exist)) && 3295 (coex_sta->high_priority_tx + coex_sta->high_priority_rx >= 3296 160) && 3297 (!coex_sta->c2h_bt_inquiry_page)) 3298 coex_sta->bt_hi_pri_link_exist = true; 3299 3300 if ((bt_info & BT_INFO_8723B_1ANT_B_ACL_BUSY) && 3301 (coex_sta->num_of_profile == 0)) { 3302 if (coex_sta->low_priority_tx + 3303 coex_sta->low_priority_rx >= 3304 160) { 3305 coex_sta->pan_exist = true; 3306 coex_sta->num_of_profile++; 3307 coex_sta->wrong_profile_notification++; 3308 bt_info = bt_info | 0x88; 3309 } 3310 } 3311 } 3312 3313 halbtc8723b1ant_update_bt_link_info(btcoexist); 3314 3315 /* mask profile bit for connect-ilde identification 3316 * ( for CSR case: A2DP idle --> 0x41) 3317 */ 3318 bt_info = bt_info & 0x1f; 3319 3320 if (!(bt_info & BT_INFO_8723B_1ANT_B_CONNECTION)) { 3321 coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE; 3322 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3323 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!\n"); 3324 /* connection exists but no busy */ 3325 } else if (bt_info == BT_INFO_8723B_1ANT_B_CONNECTION) { 3326 coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE; 3327 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3328 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); 3329 } else if ((bt_info & BT_INFO_8723B_1ANT_B_SCO_ESCO) || 3330 (bt_info & BT_INFO_8723B_1ANT_B_SCO_BUSY)) { 3331 coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_SCO_BUSY; 3332 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3333 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); 3334 } else if (bt_info & BT_INFO_8723B_1ANT_B_ACL_BUSY) { 3335 if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status) 3336 coex_dm->auto_tdma_adjust = false; 3337 3338 coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_ACL_BUSY; 3339 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3340 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); 3341 } else { 3342 coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_MAX; 3343 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3344 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!\n"); 3345 } 3346 3347 if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || 3348 (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || 3349 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) 3350 bt_busy = true; 3351 else 3352 bt_busy = false; 3353 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); 3354 3355 halbtc8723b1ant_run_coexist_mechanism(btcoexist); 3356 } 3357 3358 void ex_btc8723b1ant_rf_status_notify(struct btc_coexist *btcoexist, u8 type) 3359 { 3360 struct rtl_priv *rtlpriv = btcoexist->adapter; 3361 u32 u32tmp; 3362 u8 u8tmpa, u8tmpb, u8tmpc; 3363 3364 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3365 "[BTCoex], RF Status notify\n"); 3366 3367 if (type == BTC_RF_ON) { 3368 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3369 "[BTCoex], RF is turned ON!!\n"); 3370 btcoexist->stop_coex_dm = false; 3371 } else if (type == BTC_RF_OFF) { 3372 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3373 "[BTCoex], RF is turned OFF!!\n"); 3374 3375 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 3376 0x0, 0x0); 3377 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); 3378 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, 3379 FORCE_EXEC, false, true); 3380 3381 halbtc8723b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); 3382 btcoexist->stop_coex_dm = true; 3383 3384 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948); 3385 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); 3386 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67); 3387 u8tmpc = btcoexist->btc_read_1byte(btcoexist, 0x76e); 3388 3389 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3390 "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x, 0x76e=0x%x\n", 3391 u32tmp, u8tmpa, u8tmpb, u8tmpc); 3392 } 3393 } 3394 3395 void ex_btc8723b1ant_halt_notify(struct btc_coexist *btcoexist) 3396 { 3397 struct rtl_priv *rtlpriv = btcoexist->adapter; 3398 3399 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Halt notify\n"); 3400 3401 btcoexist->stop_coex_dm = true; 3402 3403 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, FORCE_EXEC, 3404 false, true); 3405 3406 halbtc8723b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); 3407 3408 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 3409 0x0, 0x0); 3410 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); 3411 3412 ex_btc8723b1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); 3413 3414 btcoexist->stop_coex_dm = true; 3415 } 3416 3417 void ex_btc8723b1ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state) 3418 { 3419 struct rtl_priv *rtlpriv = btcoexist->adapter; 3420 3421 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Pnp notify\n"); 3422 3423 if (BTC_WIFI_PNP_SLEEP == pnp_state) { 3424 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3425 "[BTCoex], Pnp notify to SLEEP\n"); 3426 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, 3427 FORCE_EXEC, false, true); 3428 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 3429 0x0, 0x0); 3430 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); 3431 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); 3432 3433 /* Driver do not leave IPS/LPS when driver is going to sleep, so 3434 * BTCoexistence think wifi is still under IPS/LPS 3435 * 3436 * BT should clear UnderIPS/UnderLPS state to avoid mismatch 3437 * state after wakeup. 3438 */ 3439 coex_sta->under_ips = false; 3440 coex_sta->under_lps = false; 3441 btcoexist->stop_coex_dm = true; 3442 } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { 3443 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3444 "[BTCoex], Pnp notify to WAKE UP\n"); 3445 btcoexist->stop_coex_dm = false; 3446 halbtc8723b1ant_init_hw_config(btcoexist, false, false); 3447 halbtc8723b1ant_init_coex_dm(btcoexist); 3448 halbtc8723b1ant_query_bt_info(btcoexist); 3449 } 3450 } 3451 3452 void ex_btc8723b1ant_coex_dm_reset(struct btc_coexist *btcoexist) 3453 { 3454 struct rtl_priv *rtlpriv = btcoexist->adapter; 3455 3456 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3457 "[BTCoex], *****************Coex DM Reset****************\n"); 3458 3459 halbtc8723b1ant_init_hw_config(btcoexist, false, false); 3460 halbtc8723b1ant_init_coex_dm(btcoexist); 3461 } 3462 3463 void ex_btc8723b1ant_periodical(struct btc_coexist *btcoexist) 3464 { 3465 struct rtl_priv *rtlpriv = btcoexist->adapter; 3466 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 3467 3468 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3469 "[BTCoex], ==========================Periodical===========================\n"); 3470 3471 if (!btcoexist->auto_report_1ant) { 3472 halbtc8723b1ant_query_bt_info(btcoexist); 3473 halbtc8723b1ant_monitor_bt_enable_disable(btcoexist); 3474 } else { 3475 halbtc8723b1ant_monitor_bt_ctr(btcoexist); 3476 halbtc8723b1ant_monitor_wifi_ctr(btcoexist); 3477 3478 if ((coex_sta->high_priority_tx + coex_sta->high_priority_rx < 50) && 3479 bt_link_info->hid_exist) 3480 bt_link_info->hid_exist = false; 3481 3482 if (btc8723b1ant_is_wifi_status_changed(btcoexist) || 3483 coex_dm->auto_tdma_adjust) { 3484 halbtc8723b1ant_run_coexist_mechanism(btcoexist); 3485 } 3486 coex_sta->special_pkt_period_cnt++; 3487 } 3488 } 3489