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