1 /****************************************************************************** 2 * 3 * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved. 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 #include "halbt_precomp.h" 27 28 /*************************************************** 29 * Debug related function 30 ***************************************************/ 31 32 static const char *const gl_btc_wifi_bw_string[] = { 33 "11bg", 34 "HT20", 35 "HT40", 36 "HT80", 37 "HT160" 38 }; 39 40 static const char *const gl_btc_wifi_freq_string[] = { 41 "2.4G", 42 "5G" 43 }; 44 45 static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist) 46 { 47 if (!btcoexist->binded || NULL == btcoexist->adapter) 48 return false; 49 50 return true; 51 } 52 53 static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv) 54 { 55 if (rtlpriv->link_info.busytraffic) 56 return true; 57 else 58 return false; 59 } 60 61 static void halbtc_dbg_init(void) 62 { 63 } 64 65 /*************************************************** 66 * helper function 67 ***************************************************/ 68 static bool is_any_client_connect_to_ap(struct btc_coexist *btcoexist) 69 { 70 struct rtl_priv *rtlpriv = btcoexist->adapter; 71 struct rtl_mac *mac = rtl_mac(rtlpriv); 72 struct rtl_sta_info *drv_priv; 73 u8 cnt = 0; 74 75 if (mac->opmode == NL80211_IFTYPE_ADHOC || 76 mac->opmode == NL80211_IFTYPE_MESH_POINT || 77 mac->opmode == NL80211_IFTYPE_AP) { 78 if (in_interrupt() > 0) { 79 list_for_each_entry(drv_priv, &rtlpriv->entry_list, 80 list) { 81 cnt++; 82 } 83 } else { 84 spin_lock_bh(&rtlpriv->locks.entry_list_lock); 85 list_for_each_entry(drv_priv, &rtlpriv->entry_list, 86 list) { 87 cnt++; 88 } 89 spin_unlock_bh(&rtlpriv->locks.entry_list_lock); 90 } 91 } 92 if (cnt > 0) 93 return true; 94 else 95 return false; 96 } 97 98 static bool halbtc_legacy(struct rtl_priv *adapter) 99 { 100 struct rtl_priv *rtlpriv = adapter; 101 struct rtl_mac *mac = rtl_mac(rtlpriv); 102 103 bool is_legacy = false; 104 105 if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G)) 106 is_legacy = true; 107 108 return is_legacy; 109 } 110 111 bool halbtc_is_wifi_uplink(struct rtl_priv *adapter) 112 { 113 struct rtl_priv *rtlpriv = adapter; 114 115 if (rtlpriv->link_info.tx_busy_traffic) 116 return true; 117 else 118 return false; 119 } 120 121 static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist) 122 { 123 struct rtl_priv *rtlpriv = btcoexist->adapter; 124 struct rtl_phy *rtlphy = &rtlpriv->phy; 125 u32 wifi_bw = BTC_WIFI_BW_HT20; 126 127 if (halbtc_legacy(rtlpriv)) { 128 wifi_bw = BTC_WIFI_BW_LEGACY; 129 } else { 130 switch (rtlphy->current_chan_bw) { 131 case HT_CHANNEL_WIDTH_20: 132 wifi_bw = BTC_WIFI_BW_HT20; 133 break; 134 case HT_CHANNEL_WIDTH_20_40: 135 wifi_bw = BTC_WIFI_BW_HT40; 136 break; 137 case HT_CHANNEL_WIDTH_80: 138 wifi_bw = BTC_WIFI_BW_HT80; 139 break; 140 } 141 } 142 143 return wifi_bw; 144 } 145 146 static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist) 147 { 148 struct rtl_priv *rtlpriv = btcoexist->adapter; 149 struct rtl_phy *rtlphy = &(rtlpriv->phy); 150 u8 chnl = 1; 151 152 if (rtlphy->current_channel != 0) 153 chnl = rtlphy->current_channel; 154 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 155 "static halbtc_get_wifi_central_chnl:%d\n", chnl); 156 return chnl; 157 } 158 159 static u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv) 160 { 161 struct rtl_mod_params *mod_params = rtlpriv->cfg->mod_params; 162 163 /* override ant_num / ant_path */ 164 if (mod_params->ant_sel) { 165 rtlpriv->btcoexist.btc_info.ant_num = 166 (mod_params->ant_sel == 1 ? ANT_X2 : ANT_X1); 167 168 rtlpriv->btcoexist.btc_info.single_ant_path = 169 (mod_params->ant_sel == 1 ? 0 : 1); 170 } 171 return rtlpriv->btcoexist.btc_info.single_ant_path; 172 } 173 174 static u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv) 175 { 176 return rtlpriv->btcoexist.btc_info.bt_type; 177 } 178 179 static u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv) 180 { 181 struct rtl_mod_params *mod_params = rtlpriv->cfg->mod_params; 182 u8 num; 183 184 if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2) 185 num = 2; 186 else 187 num = 1; 188 189 /* override ant_num / ant_path */ 190 if (mod_params->ant_sel) 191 num = (mod_params->ant_sel == 1 ? ANT_X2 : ANT_X1) + 1; 192 193 return num; 194 } 195 196 static u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv) 197 { 198 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 199 200 return rtlhal->package_type; 201 } 202 203 static 204 u8 rtl_get_hwpg_rfe_type(struct rtl_priv *rtlpriv) 205 { 206 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 207 208 return rtlhal->rfe_type; 209 } 210 211 static 212 bool halbtc_is_hw_mailbox_exist(struct btc_coexist *btcoexist) 213 { 214 if (IS_HARDWARE_TYPE_8812(btcoexist->adapter)) 215 return false; 216 else 217 return true; 218 } 219 220 static 221 bool halbtc_send_bt_mp_operation(struct btc_coexist *btcoexist, u8 op_code, 222 u8 *cmd, u32 len, unsigned long wait_ms) 223 { 224 struct rtl_priv *rtlpriv; 225 const u8 oper_ver = 0; 226 u8 req_num; 227 228 if (!halbtc_is_hw_mailbox_exist(btcoexist)) 229 return false; 230 231 if (wait_ms) /* before h2c to avoid race condition */ 232 reinit_completion(&btcoexist->bt_mp_comp); 233 234 rtlpriv = btcoexist->adapter; 235 236 /* fill req_num by op_code, and rtl_btc_btmpinfo_notify() use it 237 * to know message type 238 */ 239 switch (op_code) { 240 case BT_OP_GET_BT_VERSION: 241 req_num = BT_SEQ_GET_BT_VERSION; 242 break; 243 case BT_OP_GET_AFH_MAP_L: 244 req_num = BT_SEQ_GET_AFH_MAP_L; 245 break; 246 case BT_OP_GET_AFH_MAP_M: 247 req_num = BT_SEQ_GET_AFH_MAP_M; 248 break; 249 case BT_OP_GET_AFH_MAP_H: 250 req_num = BT_SEQ_GET_AFH_MAP_H; 251 break; 252 case BT_OP_GET_BT_COEX_SUPPORTED_FEATURE: 253 req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_FEATURE; 254 break; 255 case BT_OP_GET_BT_COEX_SUPPORTED_VERSION: 256 req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_VERSION; 257 break; 258 case BT_OP_GET_BT_ANT_DET_VAL: 259 req_num = BT_SEQ_GET_BT_ANT_DET_VAL; 260 break; 261 case BT_OP_GET_BT_BLE_SCAN_PARA: 262 req_num = BT_SEQ_GET_BT_BLE_SCAN_PARA; 263 break; 264 case BT_OP_GET_BT_BLE_SCAN_TYPE: 265 req_num = BT_SEQ_GET_BT_BLE_SCAN_TYPE; 266 break; 267 case BT_OP_GET_BT_DEVICE_INFO: 268 req_num = BT_SEQ_GET_BT_DEVICE_INFO; 269 break; 270 case BT_OP_GET_BT_FORBIDDEN_SLOT_VAL: 271 req_num = BT_SEQ_GET_BT_FORB_SLOT_VAL; 272 break; 273 case BT_OP_WRITE_REG_ADDR: 274 case BT_OP_WRITE_REG_VALUE: 275 case BT_OP_READ_REG: 276 default: 277 req_num = BT_SEQ_DONT_CARE; 278 break; 279 } 280 281 cmd[0] |= (oper_ver & 0x0f); /* Set OperVer */ 282 cmd[0] |= ((req_num << 4) & 0xf0); /* Set ReqNum */ 283 cmd[1] = op_code; 284 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, len, cmd); 285 286 /* wait? */ 287 if (!wait_ms) 288 return true; 289 290 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 291 "btmpinfo wait req_num=%d wait=%ld\n", req_num, wait_ms); 292 293 if (in_interrupt()) 294 return false; 295 296 if (wait_for_completion_timeout(&btcoexist->bt_mp_comp, 297 msecs_to_jiffies(wait_ms)) == 0) { 298 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG, 299 "btmpinfo wait (req_num=%d) timeout\n", req_num); 300 301 return false; /* timeout */ 302 } 303 304 return true; 305 } 306 307 static void halbtc_leave_lps(struct btc_coexist *btcoexist) 308 { 309 struct rtl_priv *rtlpriv; 310 struct rtl_ps_ctl *ppsc; 311 bool ap_enable = false; 312 313 rtlpriv = btcoexist->adapter; 314 ppsc = rtl_psc(rtlpriv); 315 316 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, 317 &ap_enable); 318 319 if (ap_enable) { 320 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG, 321 "%s()<--dont leave lps under AP mode\n", __func__); 322 return; 323 } 324 325 btcoexist->bt_info.bt_ctrl_lps = true; 326 btcoexist->bt_info.bt_lps_on = false; 327 rtl_lps_leave(rtlpriv->mac80211.hw); 328 } 329 330 static void halbtc_enter_lps(struct btc_coexist *btcoexist) 331 { 332 struct rtl_priv *rtlpriv; 333 struct rtl_ps_ctl *ppsc; 334 bool ap_enable = false; 335 336 rtlpriv = btcoexist->adapter; 337 ppsc = rtl_psc(rtlpriv); 338 339 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, 340 &ap_enable); 341 342 if (ap_enable) { 343 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG, 344 "%s()<--dont enter lps under AP mode\n", __func__); 345 return; 346 } 347 348 btcoexist->bt_info.bt_ctrl_lps = true; 349 btcoexist->bt_info.bt_lps_on = true; 350 rtl_lps_enter(rtlpriv->mac80211.hw); 351 } 352 353 static void halbtc_normal_lps(struct btc_coexist *btcoexist) 354 { 355 struct rtl_priv *rtlpriv; 356 357 rtlpriv = btcoexist->adapter; 358 359 if (btcoexist->bt_info.bt_ctrl_lps) { 360 btcoexist->bt_info.bt_lps_on = false; 361 rtl_lps_leave(rtlpriv->mac80211.hw); 362 btcoexist->bt_info.bt_ctrl_lps = false; 363 } 364 } 365 366 static void halbtc_leave_low_power(struct btc_coexist *btcoexist) 367 { 368 } 369 370 static void halbtc_normal_low_power(struct btc_coexist *btcoexist) 371 { 372 } 373 374 static void halbtc_disable_low_power(struct btc_coexist *btcoexist, 375 bool low_pwr_disable) 376 { 377 /* TODO: original/leave 32k low power */ 378 btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable; 379 } 380 381 static void halbtc_aggregation_check(struct btc_coexist *btcoexist) 382 { 383 bool need_to_act = false; 384 static unsigned long pre_time; 385 unsigned long cur_time = 0; 386 struct rtl_priv *rtlpriv = btcoexist->adapter; 387 388 /* To void continuous deleteBA=>addBA=>deleteBA=>addBA 389 * This function is not allowed to continuous called 390 * It can only be called after 8 seconds 391 */ 392 393 cur_time = jiffies; 394 if (jiffies_to_msecs(cur_time - pre_time) <= 8000) { 395 /* over 8 seconds you can execute this function again. */ 396 return; 397 } 398 pre_time = cur_time; 399 400 if (btcoexist->bt_info.reject_agg_pkt) { 401 need_to_act = true; 402 btcoexist->bt_info.pre_reject_agg_pkt = 403 btcoexist->bt_info.reject_agg_pkt; 404 } else { 405 if (btcoexist->bt_info.pre_reject_agg_pkt) { 406 need_to_act = true; 407 btcoexist->bt_info.pre_reject_agg_pkt = 408 btcoexist->bt_info.reject_agg_pkt; 409 } 410 411 if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size != 412 btcoexist->bt_info.bt_ctrl_agg_buf_size) { 413 need_to_act = true; 414 btcoexist->bt_info.pre_bt_ctrl_agg_buf_size = 415 btcoexist->bt_info.bt_ctrl_agg_buf_size; 416 } 417 418 if (btcoexist->bt_info.bt_ctrl_agg_buf_size) { 419 if (btcoexist->bt_info.pre_agg_buf_size != 420 btcoexist->bt_info.agg_buf_size) { 421 need_to_act = true; 422 } 423 btcoexist->bt_info.pre_agg_buf_size = 424 btcoexist->bt_info.agg_buf_size; 425 } 426 427 if (need_to_act) 428 rtl_rx_ampdu_apply(rtlpriv); 429 } 430 } 431 432 static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist) 433 { 434 u8 cmd_buffer[4] = {0}; 435 436 if (btcoexist->bt_info.bt_real_fw_ver) 437 goto label_done; 438 439 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */ 440 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_VERSION, 441 cmd_buffer, 4, 200); 442 443 label_done: 444 return btcoexist->bt_info.bt_real_fw_ver; 445 } 446 447 static u32 halbtc_get_bt_coex_supported_feature(void *btc_context) 448 { 449 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context; 450 u8 cmd_buffer[4] = {0}; 451 452 if (btcoexist->bt_info.bt_supported_feature) 453 goto label_done; 454 455 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */ 456 halbtc_send_bt_mp_operation(btcoexist, 457 BT_OP_GET_BT_COEX_SUPPORTED_FEATURE, 458 cmd_buffer, 4, 200); 459 460 label_done: 461 return btcoexist->bt_info.bt_supported_feature; 462 } 463 464 static u32 halbtc_get_bt_coex_supported_version(void *btc_context) 465 { 466 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context; 467 u8 cmd_buffer[4] = {0}; 468 469 if (btcoexist->bt_info.bt_supported_version) 470 goto label_done; 471 472 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */ 473 halbtc_send_bt_mp_operation(btcoexist, 474 BT_OP_GET_BT_COEX_SUPPORTED_VERSION, 475 cmd_buffer, 4, 200); 476 477 label_done: 478 return btcoexist->bt_info.bt_supported_version; 479 } 480 481 static u32 halbtc_get_bt_device_info(void *btc_context) 482 { 483 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context; 484 u8 cmd_buffer[4] = {0}; 485 486 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */ 487 halbtc_send_bt_mp_operation(btcoexist, 488 BT_OP_GET_BT_DEVICE_INFO, 489 cmd_buffer, 4, 200); 490 491 return btcoexist->bt_info.bt_device_info; 492 } 493 494 static u32 halbtc_get_bt_forbidden_slot_val(void *btc_context) 495 { 496 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context; 497 u8 cmd_buffer[4] = {0}; 498 499 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */ 500 halbtc_send_bt_mp_operation(btcoexist, 501 BT_OP_GET_BT_FORBIDDEN_SLOT_VAL, 502 cmd_buffer, 4, 200); 503 504 return btcoexist->bt_info.bt_forb_slot_val; 505 } 506 507 static u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist) 508 { 509 /* return value: 510 * [31:16] => connected port number 511 * [15:0] => port connected bit define 512 */ 513 struct rtl_priv *rtlpriv = btcoexist->adapter; 514 struct rtl_mac *mac = rtl_mac(rtlpriv); 515 u32 ret_val = 0; 516 u32 port_connected_status = 0, num_of_connected_port = 0; 517 518 if (mac->opmode == NL80211_IFTYPE_STATION && 519 mac->link_state >= MAC80211_LINKED) { 520 port_connected_status |= WIFI_STA_CONNECTED; 521 num_of_connected_port++; 522 } 523 /* AP & ADHOC & MESH */ 524 if (is_any_client_connect_to_ap(btcoexist)) { 525 port_connected_status |= WIFI_AP_CONNECTED; 526 num_of_connected_port++; 527 } 528 /* TODO: P2P Connected Status */ 529 530 ret_val = (num_of_connected_port << 16) | port_connected_status; 531 532 return ret_val; 533 } 534 535 static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv) 536 { 537 int undec_sm_pwdb = 0; 538 539 if (rtlpriv->mac80211.link_state >= MAC80211_LINKED) 540 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb; 541 else /* associated entry pwdb */ 542 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb; 543 return undec_sm_pwdb; 544 } 545 546 static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf) 547 { 548 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist; 549 struct rtl_priv *rtlpriv = btcoexist->adapter; 550 struct rtl_phy *rtlphy = &(rtlpriv->phy); 551 struct rtl_mac *mac = rtl_mac(rtlpriv); 552 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 553 bool *bool_tmp = (bool *)out_buf; 554 int *s32_tmp = (int *)out_buf; 555 u32 *u32_tmp = (u32 *)out_buf; 556 u8 *u8_tmp = (u8 *)out_buf; 557 bool tmp = false; 558 bool ret = true; 559 560 if (!halbtc_is_bt_coexist_available(btcoexist)) 561 return false; 562 563 switch (get_type) { 564 case BTC_GET_BL_HS_OPERATION: 565 *bool_tmp = false; 566 ret = false; 567 break; 568 case BTC_GET_BL_HS_CONNECTING: 569 *bool_tmp = false; 570 ret = false; 571 break; 572 case BTC_GET_BL_WIFI_CONNECTED: 573 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION && 574 rtlpriv->mac80211.link_state >= MAC80211_LINKED) 575 tmp = true; 576 if (is_any_client_connect_to_ap(btcoexist)) 577 tmp = true; 578 *bool_tmp = tmp; 579 break; 580 case BTC_GET_BL_WIFI_BUSY: 581 if (halbtc_is_wifi_busy(rtlpriv)) 582 *bool_tmp = true; 583 else 584 *bool_tmp = false; 585 break; 586 case BTC_GET_BL_WIFI_SCAN: 587 if (mac->act_scanning) 588 *bool_tmp = true; 589 else 590 *bool_tmp = false; 591 break; 592 case BTC_GET_BL_WIFI_LINK: 593 if (mac->link_state == MAC80211_LINKING) 594 *bool_tmp = true; 595 else 596 *bool_tmp = false; 597 break; 598 case BTC_GET_BL_WIFI_ROAM: 599 if (mac->link_state == MAC80211_LINKING) 600 *bool_tmp = true; 601 else 602 *bool_tmp = false; 603 break; 604 case BTC_GET_BL_WIFI_4_WAY_PROGRESS: 605 *bool_tmp = rtlpriv->btcoexist.btc_info.in_4way; 606 break; 607 case BTC_GET_BL_WIFI_UNDER_5G: 608 if (rtlhal->current_bandtype == BAND_ON_5G) 609 *bool_tmp = true; 610 else 611 *bool_tmp = false; 612 break; 613 case BTC_GET_BL_WIFI_AP_MODE_ENABLE: 614 if (mac->opmode == NL80211_IFTYPE_AP) 615 *bool_tmp = true; 616 else 617 *bool_tmp = false; 618 break; 619 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION: 620 if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm) 621 *bool_tmp = false; 622 else 623 *bool_tmp = true; 624 break; 625 case BTC_GET_BL_WIFI_UNDER_B_MODE: 626 if (rtlpriv->mac80211.mode == WIRELESS_MODE_B) 627 *bool_tmp = true; 628 else 629 *bool_tmp = false; 630 break; 631 case BTC_GET_BL_EXT_SWITCH: 632 *bool_tmp = false; 633 break; 634 case BTC_GET_BL_WIFI_IS_IN_MP_MODE: 635 *bool_tmp = false; 636 break; 637 case BTC_GET_BL_IS_ASUS_8723B: 638 *bool_tmp = false; 639 break; 640 case BTC_GET_S4_WIFI_RSSI: 641 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv); 642 break; 643 case BTC_GET_S4_HS_RSSI: 644 *s32_tmp = 0; 645 ret = false; 646 break; 647 case BTC_GET_U4_WIFI_BW: 648 *u32_tmp = halbtc_get_wifi_bw(btcoexist); 649 break; 650 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION: 651 if (halbtc_is_wifi_uplink(rtlpriv)) 652 *u32_tmp = BTC_WIFI_TRAFFIC_TX; 653 else 654 *u32_tmp = BTC_WIFI_TRAFFIC_RX; 655 break; 656 case BTC_GET_U4_WIFI_FW_VER: 657 *u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion; 658 break; 659 case BTC_GET_U4_WIFI_LINK_STATUS: 660 *u32_tmp = halbtc_get_wifi_link_status(btcoexist); 661 break; 662 case BTC_GET_U4_BT_PATCH_VER: 663 *u32_tmp = halbtc_get_bt_patch_version(btcoexist); 664 break; 665 case BTC_GET_U4_VENDOR: 666 *u32_tmp = BTC_VENDOR_OTHER; 667 break; 668 case BTC_GET_U4_SUPPORTED_VERSION: 669 *u32_tmp = halbtc_get_bt_coex_supported_version(btcoexist); 670 break; 671 case BTC_GET_U4_SUPPORTED_FEATURE: 672 *u32_tmp = halbtc_get_bt_coex_supported_feature(btcoexist); 673 break; 674 case BTC_GET_U4_BT_DEVICE_INFO: 675 *u32_tmp = halbtc_get_bt_device_info(btcoexist); 676 break; 677 case BTC_GET_U4_BT_FORBIDDEN_SLOT_VAL: 678 *u32_tmp = halbtc_get_bt_forbidden_slot_val(btcoexist); 679 break; 680 case BTC_GET_U1_WIFI_DOT11_CHNL: 681 *u8_tmp = rtlphy->current_channel; 682 break; 683 case BTC_GET_U1_WIFI_CENTRAL_CHNL: 684 *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist); 685 break; 686 case BTC_GET_U1_WIFI_HS_CHNL: 687 *u8_tmp = 0; 688 ret = false; 689 break; 690 case BTC_GET_U1_AP_NUM: 691 *u8_tmp = rtlpriv->btcoexist.btc_info.ap_num; 692 break; 693 case BTC_GET_U1_ANT_TYPE: 694 *u8_tmp = (u8)BTC_ANT_TYPE_0; 695 break; 696 case BTC_GET_U1_IOT_PEER: 697 *u8_tmp = 0; 698 break; 699 700 /************* 1Ant **************/ 701 case BTC_GET_U1_LPS_MODE: 702 *u8_tmp = btcoexist->pwr_mode_val[0]; 703 break; 704 705 default: 706 ret = false; 707 break; 708 } 709 710 return ret; 711 } 712 713 static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf) 714 { 715 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist; 716 bool *bool_tmp = (bool *)in_buf; 717 u8 *u8_tmp = (u8 *)in_buf; 718 u32 *u32_tmp = (u32 *)in_buf; 719 bool ret = true; 720 721 if (!halbtc_is_bt_coexist_available(btcoexist)) 722 return false; 723 724 switch (set_type) { 725 /* set some bool type variables. */ 726 case BTC_SET_BL_BT_DISABLE: 727 btcoexist->bt_info.bt_disabled = *bool_tmp; 728 break; 729 case BTC_SET_BL_BT_TRAFFIC_BUSY: 730 btcoexist->bt_info.bt_busy = *bool_tmp; 731 break; 732 case BTC_SET_BL_BT_LIMITED_DIG: 733 btcoexist->bt_info.limited_dig = *bool_tmp; 734 break; 735 case BTC_SET_BL_FORCE_TO_ROAM: 736 btcoexist->bt_info.force_to_roam = *bool_tmp; 737 break; 738 case BTC_SET_BL_TO_REJ_AP_AGG_PKT: 739 btcoexist->bt_info.reject_agg_pkt = *bool_tmp; 740 break; 741 case BTC_SET_BL_BT_CTRL_AGG_SIZE: 742 btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp; 743 break; 744 case BTC_SET_BL_INC_SCAN_DEV_NUM: 745 btcoexist->bt_info.increase_scan_dev_num = *bool_tmp; 746 break; 747 case BTC_SET_BL_BT_TX_RX_MASK: 748 btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp; 749 break; 750 case BTC_SET_BL_MIRACAST_PLUS_BT: 751 btcoexist->bt_info.miracast_plus_bt = *bool_tmp; 752 break; 753 /* set some u1Byte type variables. */ 754 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON: 755 btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp; 756 break; 757 case BTC_SET_U1_AGG_BUF_SIZE: 758 btcoexist->bt_info.agg_buf_size = *u8_tmp; 759 break; 760 761 /* the following are some action which will be triggered */ 762 case BTC_SET_ACT_GET_BT_RSSI: 763 ret = false; 764 break; 765 case BTC_SET_ACT_AGGREGATE_CTRL: 766 halbtc_aggregation_check(btcoexist); 767 break; 768 769 /* 1Ant */ 770 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE: 771 btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp; 772 break; 773 case BTC_SET_UI_SCAN_SIG_COMPENSATION: 774 break; 775 case BTC_SET_U1_LPS_VAL: 776 btcoexist->bt_info.lps_val = *u8_tmp; 777 break; 778 case BTC_SET_U1_RPWM_VAL: 779 btcoexist->bt_info.rpwm_val = *u8_tmp; 780 break; 781 /* the following are some action which will be triggered */ 782 case BTC_SET_ACT_LEAVE_LPS: 783 halbtc_leave_lps(btcoexist); 784 break; 785 case BTC_SET_ACT_ENTER_LPS: 786 halbtc_enter_lps(btcoexist); 787 break; 788 case BTC_SET_ACT_NORMAL_LPS: 789 halbtc_normal_lps(btcoexist); 790 break; 791 case BTC_SET_ACT_DISABLE_LOW_POWER: 792 halbtc_disable_low_power(btcoexist, *bool_tmp); 793 break; 794 case BTC_SET_ACT_UPDATE_RAMASK: 795 btcoexist->bt_info.ra_mask = *u32_tmp; 796 break; 797 case BTC_SET_ACT_SEND_MIMO_PS: 798 break; 799 case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/ 800 break; 801 case BTC_SET_ACT_CTRL_BT_COEX: 802 break; 803 case BTC_SET_ACT_CTRL_8723B_ANT: 804 break; 805 default: 806 break; 807 } 808 809 return ret; 810 } 811 812 static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist, 813 struct seq_file *m) 814 { 815 } 816 817 static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist, 818 struct seq_file *m) 819 { 820 } 821 822 static void halbtc_display_wifi_status(struct btc_coexist *btcoexist, 823 struct seq_file *m) 824 { 825 struct rtl_priv *rtlpriv = btcoexist->adapter; 826 s32 wifi_rssi = 0, bt_hs_rssi = 0; 827 bool scan = false, link = false, roam = false, wifi_busy = false; 828 bool wifi_under_b_mode = false; 829 bool wifi_under_5g = false; 830 u32 wifi_bw = BTC_WIFI_BW_HT20; 831 u32 wifi_traffic_dir = BTC_WIFI_TRAFFIC_TX; 832 u32 wifi_freq = BTC_FREQ_2_4G; 833 u32 wifi_link_status = 0x0; 834 bool bt_hs_on = false, under_ips = false, under_lps = false; 835 bool low_power = false, dc_mode = false; 836 u8 wifi_chnl = 0, wifi_hs_chnl = 0; 837 u8 ap_num = 0; 838 839 wifi_link_status = halbtc_get_wifi_link_status(btcoexist); 840 seq_printf(m, "\n %-35s = %d/ %d/ %d/ %d/ %d", 841 "STA/vWifi/HS/p2pGo/p2pGc", 842 ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0), 843 ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0), 844 ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0), 845 ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0), 846 ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0)); 847 848 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 849 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_chnl); 850 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl); 851 seq_printf(m, "\n %-35s = %d / %d(%d)", 852 "Dot11 channel / HsChnl(High Speed)", 853 wifi_chnl, wifi_hs_chnl, bt_hs_on); 854 855 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); 856 btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi); 857 seq_printf(m, "\n %-35s = %d/ %d", 858 "Wifi rssi/ HS rssi", 859 wifi_rssi - 100, bt_hs_rssi - 100); 860 861 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); 862 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); 863 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); 864 seq_printf(m, "\n %-35s = %d/ %d/ %d ", 865 "Wifi link/ roam/ scan", 866 link, roam, scan); 867 868 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); 869 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 870 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 871 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, 872 &wifi_traffic_dir); 873 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num); 874 wifi_freq = (wifi_under_5g ? BTC_FREQ_5G : BTC_FREQ_2_4G); 875 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, 876 &wifi_under_b_mode); 877 878 seq_printf(m, "\n %-35s = %s / %s/ %s/ AP=%d ", 879 "Wifi freq/ bw/ traffic", 880 gl_btc_wifi_freq_string[wifi_freq], 881 ((wifi_under_b_mode) ? "11b" : 882 gl_btc_wifi_bw_string[wifi_bw]), 883 ((!wifi_busy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX == 884 wifi_traffic_dir) ? "uplink" : 885 "downlink")), 886 ap_num); 887 888 /* power status */ 889 dc_mode = true; /*TODO*/ 890 under_ips = rtlpriv->psc.inactive_pwrstate == ERFOFF ? 1 : 0; 891 under_lps = rtlpriv->psc.dot11_psmode == EACTIVE ? 0 : 1; 892 low_power = 0; /*TODO*/ 893 seq_printf(m, "\n %-35s = %s%s%s%s", 894 "Power Status", 895 (dc_mode ? "DC mode" : "AC mode"), 896 (under_ips ? ", IPS ON" : ""), 897 (under_lps ? ", LPS ON" : ""), 898 (low_power ? ", 32k" : "")); 899 900 seq_printf(m, 901 "\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)", 902 "Power mode cmd(lps/rpwm)", 903 btcoexist->pwr_mode_val[0], btcoexist->pwr_mode_val[1], 904 btcoexist->pwr_mode_val[2], btcoexist->pwr_mode_val[3], 905 btcoexist->pwr_mode_val[4], btcoexist->pwr_mode_val[5], 906 btcoexist->bt_info.lps_val, 907 btcoexist->bt_info.rpwm_val); 908 } 909 910 /************************************************************ 911 * IO related function 912 ************************************************************/ 913 static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr) 914 { 915 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 916 struct rtl_priv *rtlpriv = btcoexist->adapter; 917 918 return rtl_read_byte(rtlpriv, reg_addr); 919 } 920 921 static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr) 922 { 923 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 924 struct rtl_priv *rtlpriv = btcoexist->adapter; 925 926 return rtl_read_word(rtlpriv, reg_addr); 927 } 928 929 static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr) 930 { 931 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 932 struct rtl_priv *rtlpriv = btcoexist->adapter; 933 934 return rtl_read_dword(rtlpriv, reg_addr); 935 } 936 937 static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data) 938 { 939 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 940 struct rtl_priv *rtlpriv = btcoexist->adapter; 941 942 rtl_write_byte(rtlpriv, reg_addr, data); 943 } 944 945 static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr, 946 u32 bit_mask, u8 data) 947 { 948 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 949 struct rtl_priv *rtlpriv = btcoexist->adapter; 950 u8 original_value, bit_shift = 0; 951 u8 i; 952 953 if (bit_mask != MASKDWORD) {/*if not "double word" write*/ 954 original_value = rtl_read_byte(rtlpriv, reg_addr); 955 for (i = 0; i <= 7; i++) { 956 if ((bit_mask>>i) & 0x1) 957 break; 958 } 959 bit_shift = i; 960 data = (original_value & (~bit_mask)) | 961 ((data << bit_shift) & bit_mask); 962 } 963 rtl_write_byte(rtlpriv, reg_addr, data); 964 } 965 966 static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data) 967 { 968 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 969 struct rtl_priv *rtlpriv = btcoexist->adapter; 970 971 rtl_write_word(rtlpriv, reg_addr, data); 972 } 973 974 static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data) 975 { 976 struct btc_coexist *btcoexist = 977 (struct btc_coexist *)bt_context; 978 struct rtl_priv *rtlpriv = btcoexist->adapter; 979 980 rtl_write_dword(rtlpriv, reg_addr, data); 981 } 982 983 static void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr, 984 u8 data) 985 { 986 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context; 987 struct rtl_priv *rtlpriv = btcoexist->adapter; 988 989 if (btcoexist->chip_interface == BTC_INTF_SDIO) 990 ; 991 else if (btcoexist->chip_interface == BTC_INTF_PCI) 992 rtl_write_byte(rtlpriv, reg_addr, data); 993 else if (btcoexist->chip_interface == BTC_INTF_USB) 994 rtl_write_byte(rtlpriv, reg_addr, data); 995 } 996 997 static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask, 998 u32 data) 999 { 1000 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 1001 struct rtl_priv *rtlpriv = btcoexist->adapter; 1002 1003 rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data); 1004 } 1005 1006 static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask) 1007 { 1008 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 1009 struct rtl_priv *rtlpriv = btcoexist->adapter; 1010 1011 return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask); 1012 } 1013 1014 static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr, 1015 u32 bit_mask, u32 data) 1016 { 1017 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 1018 struct rtl_priv *rtlpriv = btcoexist->adapter; 1019 1020 rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data); 1021 } 1022 1023 static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr, 1024 u32 bit_mask) 1025 { 1026 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 1027 struct rtl_priv *rtlpriv = btcoexist->adapter; 1028 1029 return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask); 1030 } 1031 1032 static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id, 1033 u32 cmd_len, u8 *cmd_buf) 1034 { 1035 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 1036 struct rtl_priv *rtlpriv = btcoexist->adapter; 1037 1038 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id, 1039 cmd_len, cmd_buf); 1040 } 1041 1042 static 1043 void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val) 1044 { 1045 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context; 1046 u8 cmd_buffer1[4] = {0}; 1047 u8 cmd_buffer2[4] = {0}; 1048 1049 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */ 1050 *((__le16 *)&cmd_buffer1[2]) = cpu_to_le16((u16)set_val); 1051 if (!halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_VALUE, 1052 cmd_buffer1, 4, 200)) 1053 return; 1054 1055 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */ 1056 cmd_buffer2[2] = reg_type; 1057 *((u8 *)&cmd_buffer2[3]) = (u8)offset; 1058 halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_ADDR, 1059 cmd_buffer2, 4, 200); 1060 } 1061 1062 static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type, 1063 struct seq_file *m) 1064 { 1065 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 1066 1067 switch (disp_type) { 1068 case BTC_DBG_DISP_COEX_STATISTICS: 1069 halbtc_display_coex_statistics(btcoexist, m); 1070 break; 1071 case BTC_DBG_DISP_BT_LINK_INFO: 1072 halbtc_display_bt_link_info(btcoexist, m); 1073 break; 1074 case BTC_DBG_DISP_WIFI_STATUS: 1075 halbtc_display_wifi_status(btcoexist, m); 1076 break; 1077 default: 1078 break; 1079 } 1080 } 1081 1082 static bool halbtc_under_ips(struct btc_coexist *btcoexist) 1083 { 1084 struct rtl_priv *rtlpriv = btcoexist->adapter; 1085 struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv); 1086 enum rf_pwrstate rtstate; 1087 1088 if (ppsc->inactiveps) { 1089 rtstate = ppsc->rfpwr_state; 1090 1091 if (rtstate != ERFON && 1092 ppsc->rfoff_reason == RF_CHANGE_BY_IPS) { 1093 return true; 1094 } 1095 } 1096 1097 return false; 1098 } 1099 1100 static u8 halbtc_get_ant_det_val_from_bt(void *btc_context) 1101 { 1102 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context; 1103 u8 cmd_buffer[4] = {0}; 1104 1105 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */ 1106 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_ANT_DET_VAL, 1107 cmd_buffer, 4, 200); 1108 1109 /* need wait completion to return correct value */ 1110 1111 return btcoexist->bt_info.bt_ant_det_val; 1112 } 1113 1114 static u8 halbtc_get_ble_scan_type_from_bt(void *btc_context) 1115 { 1116 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context; 1117 u8 cmd_buffer[4] = {0}; 1118 1119 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */ 1120 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_TYPE, 1121 cmd_buffer, 4, 200); 1122 1123 /* need wait completion to return correct value */ 1124 1125 return btcoexist->bt_info.bt_ble_scan_type; 1126 } 1127 1128 static u32 halbtc_get_ble_scan_para_from_bt(void *btc_context, u8 scan_type) 1129 { 1130 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context; 1131 u8 cmd_buffer[4] = {0}; 1132 1133 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */ 1134 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_PARA, 1135 cmd_buffer, 4, 200); 1136 1137 /* need wait completion to return correct value */ 1138 1139 return btcoexist->bt_info.bt_ble_scan_para; 1140 } 1141 1142 static bool halbtc_get_bt_afh_map_from_bt(void *btc_context, u8 map_type, 1143 u8 *afh_map) 1144 { 1145 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context; 1146 u8 cmd_buffer[2] = {0}; 1147 bool ret; 1148 u32 *afh_map_l = (u32 *)afh_map; 1149 u32 *afh_map_m = (u32 *)(afh_map + 4); 1150 u16 *afh_map_h = (u16 *)(afh_map + 8); 1151 1152 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */ 1153 ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_L, 1154 cmd_buffer, 2, 200); 1155 if (!ret) 1156 goto exit; 1157 1158 *afh_map_l = btcoexist->bt_info.afh_map_l; 1159 1160 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */ 1161 ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_M, 1162 cmd_buffer, 2, 200); 1163 if (!ret) 1164 goto exit; 1165 1166 *afh_map_m = btcoexist->bt_info.afh_map_m; 1167 1168 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */ 1169 ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_H, 1170 cmd_buffer, 2, 200); 1171 if (!ret) 1172 goto exit; 1173 1174 *afh_map_h = btcoexist->bt_info.afh_map_h; 1175 1176 exit: 1177 return ret; 1178 } 1179 1180 /***************************************************************** 1181 * Extern functions called by other module 1182 *****************************************************************/ 1183 bool exhalbtc_initlize_variables(struct rtl_priv *rtlpriv) 1184 { 1185 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv); 1186 1187 if (!btcoexist) 1188 return false; 1189 1190 halbtc_dbg_init(); 1191 1192 btcoexist->btc_read_1byte = halbtc_read_1byte; 1193 btcoexist->btc_write_1byte = halbtc_write_1byte; 1194 btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte; 1195 btcoexist->btc_read_2byte = halbtc_read_2byte; 1196 btcoexist->btc_write_2byte = halbtc_write_2byte; 1197 btcoexist->btc_read_4byte = halbtc_read_4byte; 1198 btcoexist->btc_write_4byte = halbtc_write_4byte; 1199 btcoexist->btc_write_local_reg_1byte = halbtc_write_local_reg_1byte; 1200 1201 btcoexist->btc_set_bb_reg = halbtc_set_bbreg; 1202 btcoexist->btc_get_bb_reg = halbtc_get_bbreg; 1203 1204 btcoexist->btc_set_rf_reg = halbtc_set_rfreg; 1205 btcoexist->btc_get_rf_reg = halbtc_get_rfreg; 1206 1207 btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd; 1208 btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg; 1209 1210 btcoexist->btc_get = halbtc_get; 1211 btcoexist->btc_set = halbtc_set; 1212 btcoexist->btc_set_bt_reg = halbtc_set_bt_reg; 1213 1214 btcoexist->bt_info.bt_ctrl_buf_size = false; 1215 btcoexist->bt_info.agg_buf_size = 5; 1216 1217 btcoexist->bt_info.increase_scan_dev_num = false; 1218 1219 btcoexist->btc_get_bt_coex_supported_feature = 1220 halbtc_get_bt_coex_supported_feature; 1221 btcoexist->btc_get_bt_coex_supported_version = 1222 halbtc_get_bt_coex_supported_version; 1223 btcoexist->btc_get_ant_det_val_from_bt = halbtc_get_ant_det_val_from_bt; 1224 btcoexist->btc_get_ble_scan_type_from_bt = 1225 halbtc_get_ble_scan_type_from_bt; 1226 btcoexist->btc_get_ble_scan_para_from_bt = 1227 halbtc_get_ble_scan_para_from_bt; 1228 btcoexist->btc_get_bt_afh_map_from_bt = 1229 halbtc_get_bt_afh_map_from_bt; 1230 1231 init_completion(&btcoexist->bt_mp_comp); 1232 1233 return true; 1234 } 1235 1236 bool exhalbtc_initlize_variables_wifi_only(struct rtl_priv *rtlpriv) 1237 { 1238 struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv); 1239 struct wifi_only_haldata *wifionly_haldata; 1240 1241 if (!wifionly_cfg) 1242 return false; 1243 1244 wifionly_cfg->adapter = rtlpriv; 1245 1246 switch (rtlpriv->rtlhal.interface) { 1247 case INTF_PCI: 1248 wifionly_cfg->chip_interface = BTC_INTF_PCI; 1249 break; 1250 case INTF_USB: 1251 wifionly_cfg->chip_interface = BTC_INTF_USB; 1252 break; 1253 default: 1254 wifionly_cfg->chip_interface = BTC_INTF_UNKNOWN; 1255 break; 1256 } 1257 1258 wifionly_haldata = &wifionly_cfg->haldata_info; 1259 1260 wifionly_haldata->customer_id = CUSTOMER_NORMAL; 1261 wifionly_haldata->efuse_pg_antnum = rtl_get_hwpg_ant_num(rtlpriv); 1262 wifionly_haldata->efuse_pg_antpath = 1263 rtl_get_hwpg_single_ant_path(rtlpriv); 1264 wifionly_haldata->rfe_type = rtl_get_hwpg_rfe_type(rtlpriv); 1265 wifionly_haldata->ant_div_cfg = 0; 1266 1267 return true; 1268 } 1269 1270 bool exhalbtc_bind_bt_coex_withadapter(void *adapter) 1271 { 1272 struct rtl_priv *rtlpriv = adapter; 1273 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv); 1274 u8 ant_num = 2, chip_type, single_ant_path = 0; 1275 1276 if (!btcoexist) 1277 return false; 1278 1279 if (btcoexist->binded) 1280 return false; 1281 1282 switch (rtlpriv->rtlhal.interface) { 1283 case INTF_PCI: 1284 btcoexist->chip_interface = BTC_INTF_PCI; 1285 break; 1286 case INTF_USB: 1287 btcoexist->chip_interface = BTC_INTF_USB; 1288 break; 1289 default: 1290 btcoexist->chip_interface = BTC_INTF_UNKNOWN; 1291 break; 1292 } 1293 1294 btcoexist->binded = true; 1295 btcoexist->statistics.cnt_bind++; 1296 1297 btcoexist->adapter = adapter; 1298 1299 btcoexist->stack_info.profile_notified = false; 1300 1301 btcoexist->bt_info.bt_ctrl_agg_buf_size = false; 1302 btcoexist->bt_info.agg_buf_size = 5; 1303 1304 btcoexist->bt_info.increase_scan_dev_num = false; 1305 btcoexist->bt_info.miracast_plus_bt = false; 1306 1307 chip_type = rtl_get_hwpg_bt_type(rtlpriv); 1308 exhalbtc_set_chip_type(btcoexist, chip_type); 1309 ant_num = rtl_get_hwpg_ant_num(rtlpriv); 1310 exhalbtc_set_ant_num(rtlpriv, BT_COEX_ANT_TYPE_PG, ant_num); 1311 1312 /* set default antenna position to main port */ 1313 btcoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; 1314 1315 single_ant_path = rtl_get_hwpg_single_ant_path(rtlpriv); 1316 exhalbtc_set_single_ant_path(btcoexist, single_ant_path); 1317 1318 if (rtl_get_hwpg_package_type(rtlpriv) == 0) 1319 btcoexist->board_info.tfbga_package = false; 1320 else if (rtl_get_hwpg_package_type(rtlpriv) == 1) 1321 btcoexist->board_info.tfbga_package = false; 1322 else 1323 btcoexist->board_info.tfbga_package = true; 1324 1325 if (btcoexist->board_info.tfbga_package) 1326 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1327 "[BTCoex], Package Type = TFBGA\n"); 1328 else 1329 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1330 "[BTCoex], Package Type = Non-TFBGA\n"); 1331 1332 btcoexist->board_info.rfe_type = rtl_get_hwpg_rfe_type(rtlpriv); 1333 btcoexist->board_info.ant_div_cfg = 0; 1334 1335 return true; 1336 } 1337 1338 void exhalbtc_power_on_setting(struct btc_coexist *btcoexist) 1339 { 1340 if (!halbtc_is_bt_coexist_available(btcoexist)) 1341 return; 1342 1343 btcoexist->statistics.cnt_power_on++; 1344 1345 if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1346 if (btcoexist->board_info.btdm_ant_num == 2) 1347 ex_btc8723b2ant_power_on_setting(btcoexist); 1348 else if (btcoexist->board_info.btdm_ant_num == 1) 1349 ex_btc8723b1ant_power_on_setting(btcoexist); 1350 } 1351 } 1352 1353 void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist) 1354 { 1355 if (!halbtc_is_bt_coexist_available(btcoexist)) 1356 return; 1357 1358 btcoexist->statistics.cnt_pre_load_firmware++; 1359 1360 if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1361 if (btcoexist->board_info.btdm_ant_num == 2) 1362 ex_btc8723b2ant_pre_load_firmware(btcoexist); 1363 } 1364 } 1365 1366 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only) 1367 { 1368 if (!halbtc_is_bt_coexist_available(btcoexist)) 1369 return; 1370 1371 btcoexist->statistics.cnt_init_hw_config++; 1372 1373 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1374 if (btcoexist->board_info.btdm_ant_num == 2) 1375 ex_btc8821a2ant_init_hwconfig(btcoexist); 1376 else if (btcoexist->board_info.btdm_ant_num == 1) 1377 ex_btc8821a1ant_init_hwconfig(btcoexist, wifi_only); 1378 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1379 if (btcoexist->board_info.btdm_ant_num == 2) 1380 ex_btc8723b2ant_init_hwconfig(btcoexist); 1381 else if (btcoexist->board_info.btdm_ant_num == 1) 1382 ex_btc8723b1ant_init_hwconfig(btcoexist, wifi_only); 1383 } else if (IS_HARDWARE_TYPE_8723A(btcoexist->adapter)) { 1384 /* 8723A has no this function */ 1385 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1386 if (btcoexist->board_info.btdm_ant_num == 2) 1387 ex_btc8192e2ant_init_hwconfig(btcoexist); 1388 } 1389 } 1390 1391 void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg) 1392 { 1393 } 1394 1395 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist) 1396 { 1397 if (!halbtc_is_bt_coexist_available(btcoexist)) 1398 return; 1399 1400 btcoexist->statistics.cnt_init_coex_dm++; 1401 1402 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1403 if (btcoexist->board_info.btdm_ant_num == 2) 1404 ex_btc8821a2ant_init_coex_dm(btcoexist); 1405 else if (btcoexist->board_info.btdm_ant_num == 1) 1406 ex_btc8821a1ant_init_coex_dm(btcoexist); 1407 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1408 if (btcoexist->board_info.btdm_ant_num == 2) 1409 ex_btc8723b2ant_init_coex_dm(btcoexist); 1410 else if (btcoexist->board_info.btdm_ant_num == 1) 1411 ex_btc8723b1ant_init_coex_dm(btcoexist); 1412 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1413 if (btcoexist->board_info.btdm_ant_num == 2) 1414 ex_btc8192e2ant_init_coex_dm(btcoexist); 1415 } 1416 1417 btcoexist->initilized = true; 1418 } 1419 1420 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type) 1421 { 1422 u8 ips_type; 1423 1424 if (!halbtc_is_bt_coexist_available(btcoexist)) 1425 return; 1426 btcoexist->statistics.cnt_ips_notify++; 1427 if (btcoexist->manual_control) 1428 return; 1429 1430 if (ERFOFF == type) 1431 ips_type = BTC_IPS_ENTER; 1432 else 1433 ips_type = BTC_IPS_LEAVE; 1434 1435 halbtc_leave_low_power(btcoexist); 1436 1437 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1438 if (btcoexist->board_info.btdm_ant_num == 2) 1439 ex_btc8821a2ant_ips_notify(btcoexist, ips_type); 1440 else if (btcoexist->board_info.btdm_ant_num == 1) 1441 ex_btc8821a1ant_ips_notify(btcoexist, ips_type); 1442 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1443 if (btcoexist->board_info.btdm_ant_num == 2) 1444 ex_btc8723b2ant_ips_notify(btcoexist, ips_type); 1445 else if (btcoexist->board_info.btdm_ant_num == 1) 1446 ex_btc8723b1ant_ips_notify(btcoexist, ips_type); 1447 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1448 if (btcoexist->board_info.btdm_ant_num == 2) 1449 ex_btc8192e2ant_ips_notify(btcoexist, ips_type); 1450 } 1451 1452 halbtc_normal_low_power(btcoexist); 1453 } 1454 1455 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type) 1456 { 1457 u8 lps_type; 1458 1459 if (!halbtc_is_bt_coexist_available(btcoexist)) 1460 return; 1461 btcoexist->statistics.cnt_lps_notify++; 1462 if (btcoexist->manual_control) 1463 return; 1464 1465 if (EACTIVE == type) 1466 lps_type = BTC_LPS_DISABLE; 1467 else 1468 lps_type = BTC_LPS_ENABLE; 1469 1470 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1471 if (btcoexist->board_info.btdm_ant_num == 2) 1472 ex_btc8821a2ant_lps_notify(btcoexist, lps_type); 1473 else if (btcoexist->board_info.btdm_ant_num == 1) 1474 ex_btc8821a1ant_lps_notify(btcoexist, lps_type); 1475 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1476 if (btcoexist->board_info.btdm_ant_num == 2) 1477 ex_btc8723b2ant_lps_notify(btcoexist, lps_type); 1478 else if (btcoexist->board_info.btdm_ant_num == 1) 1479 ex_btc8723b1ant_lps_notify(btcoexist, lps_type); 1480 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1481 if (btcoexist->board_info.btdm_ant_num == 2) 1482 ex_btc8192e2ant_lps_notify(btcoexist, lps_type); 1483 } 1484 } 1485 1486 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type) 1487 { 1488 u8 scan_type; 1489 1490 if (!halbtc_is_bt_coexist_available(btcoexist)) 1491 return; 1492 btcoexist->statistics.cnt_scan_notify++; 1493 if (btcoexist->manual_control) 1494 return; 1495 1496 if (type) 1497 scan_type = BTC_SCAN_START; 1498 else 1499 scan_type = BTC_SCAN_FINISH; 1500 1501 halbtc_leave_low_power(btcoexist); 1502 1503 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1504 if (btcoexist->board_info.btdm_ant_num == 2) 1505 ex_btc8821a2ant_scan_notify(btcoexist, scan_type); 1506 else if (btcoexist->board_info.btdm_ant_num == 1) 1507 ex_btc8821a1ant_scan_notify(btcoexist, scan_type); 1508 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1509 if (btcoexist->board_info.btdm_ant_num == 2) 1510 ex_btc8723b2ant_scan_notify(btcoexist, scan_type); 1511 else if (btcoexist->board_info.btdm_ant_num == 1) 1512 ex_btc8723b1ant_scan_notify(btcoexist, scan_type); 1513 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1514 if (btcoexist->board_info.btdm_ant_num == 2) 1515 ex_btc8192e2ant_scan_notify(btcoexist, scan_type); 1516 } 1517 1518 halbtc_normal_low_power(btcoexist); 1519 } 1520 1521 void exhalbtc_scan_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg, 1522 u8 is_5g) 1523 { 1524 } 1525 1526 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action) 1527 { 1528 u8 asso_type; 1529 1530 if (!halbtc_is_bt_coexist_available(btcoexist)) 1531 return; 1532 btcoexist->statistics.cnt_connect_notify++; 1533 if (btcoexist->manual_control) 1534 return; 1535 1536 if (action) 1537 asso_type = BTC_ASSOCIATE_START; 1538 else 1539 asso_type = BTC_ASSOCIATE_FINISH; 1540 1541 halbtc_leave_low_power(btcoexist); 1542 1543 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1544 if (btcoexist->board_info.btdm_ant_num == 2) 1545 ex_btc8821a2ant_connect_notify(btcoexist, asso_type); 1546 else if (btcoexist->board_info.btdm_ant_num == 1) 1547 ex_btc8821a1ant_connect_notify(btcoexist, asso_type); 1548 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1549 if (btcoexist->board_info.btdm_ant_num == 2) 1550 ex_btc8723b2ant_connect_notify(btcoexist, asso_type); 1551 else if (btcoexist->board_info.btdm_ant_num == 1) 1552 ex_btc8723b1ant_connect_notify(btcoexist, asso_type); 1553 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1554 if (btcoexist->board_info.btdm_ant_num == 2) 1555 ex_btc8192e2ant_connect_notify(btcoexist, asso_type); 1556 } 1557 1558 halbtc_normal_low_power(btcoexist); 1559 } 1560 1561 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist, 1562 enum rt_media_status media_status) 1563 { 1564 u8 status; 1565 1566 if (!halbtc_is_bt_coexist_available(btcoexist)) 1567 return; 1568 btcoexist->statistics.cnt_media_status_notify++; 1569 if (btcoexist->manual_control) 1570 return; 1571 1572 if (RT_MEDIA_CONNECT == media_status) 1573 status = BTC_MEDIA_CONNECT; 1574 else 1575 status = BTC_MEDIA_DISCONNECT; 1576 1577 halbtc_leave_low_power(btcoexist); 1578 1579 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1580 if (btcoexist->board_info.btdm_ant_num == 2) 1581 ex_btc8821a2ant_media_status_notify(btcoexist, status); 1582 else if (btcoexist->board_info.btdm_ant_num == 1) 1583 ex_btc8821a1ant_media_status_notify(btcoexist, status); 1584 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1585 if (btcoexist->board_info.btdm_ant_num == 2) 1586 ex_btc8723b2ant_media_status_notify(btcoexist, status); 1587 else if (btcoexist->board_info.btdm_ant_num == 1) 1588 ex_btc8723b1ant_media_status_notify(btcoexist, status); 1589 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1590 if (btcoexist->board_info.btdm_ant_num == 2) 1591 ex_btc8192e2ant_media_status_notify(btcoexist, status); 1592 } 1593 1594 halbtc_normal_low_power(btcoexist); 1595 } 1596 1597 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type) 1598 { 1599 u8 packet_type; 1600 1601 if (!halbtc_is_bt_coexist_available(btcoexist)) 1602 return; 1603 btcoexist->statistics.cnt_special_packet_notify++; 1604 if (btcoexist->manual_control) 1605 return; 1606 1607 if (pkt_type == PACKET_DHCP) { 1608 packet_type = BTC_PACKET_DHCP; 1609 } else if (pkt_type == PACKET_EAPOL) { 1610 packet_type = BTC_PACKET_EAPOL; 1611 } else if (pkt_type == PACKET_ARP) { 1612 packet_type = BTC_PACKET_ARP; 1613 } else { 1614 packet_type = BTC_PACKET_UNKNOWN; 1615 return; 1616 } 1617 1618 halbtc_leave_low_power(btcoexist); 1619 1620 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1621 if (btcoexist->board_info.btdm_ant_num == 2) 1622 ex_btc8821a2ant_special_packet_notify(btcoexist, 1623 packet_type); 1624 else if (btcoexist->board_info.btdm_ant_num == 1) 1625 ex_btc8821a1ant_special_packet_notify(btcoexist, 1626 packet_type); 1627 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1628 if (btcoexist->board_info.btdm_ant_num == 2) 1629 ex_btc8723b2ant_special_packet_notify(btcoexist, 1630 packet_type); 1631 else if (btcoexist->board_info.btdm_ant_num == 1) 1632 ex_btc8723b1ant_special_packet_notify(btcoexist, 1633 packet_type); 1634 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1635 if (btcoexist->board_info.btdm_ant_num == 2) 1636 ex_btc8192e2ant_special_packet_notify(btcoexist, 1637 packet_type); 1638 } 1639 1640 halbtc_normal_low_power(btcoexist); 1641 } 1642 1643 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist, 1644 u8 *tmp_buf, u8 length) 1645 { 1646 if (!halbtc_is_bt_coexist_available(btcoexist)) 1647 return; 1648 btcoexist->statistics.cnt_bt_info_notify++; 1649 1650 halbtc_leave_low_power(btcoexist); 1651 1652 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1653 if (btcoexist->board_info.btdm_ant_num == 2) 1654 ex_btc8821a2ant_bt_info_notify(btcoexist, tmp_buf, 1655 length); 1656 else if (btcoexist->board_info.btdm_ant_num == 1) 1657 ex_btc8821a1ant_bt_info_notify(btcoexist, tmp_buf, 1658 length); 1659 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1660 if (btcoexist->board_info.btdm_ant_num == 2) 1661 ex_btc8723b2ant_bt_info_notify(btcoexist, tmp_buf, 1662 length); 1663 else if (btcoexist->board_info.btdm_ant_num == 1) 1664 ex_btc8723b1ant_bt_info_notify(btcoexist, tmp_buf, 1665 length); 1666 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1667 if (btcoexist->board_info.btdm_ant_num == 2) 1668 ex_btc8192e2ant_bt_info_notify(btcoexist, tmp_buf, 1669 length); 1670 } 1671 1672 halbtc_normal_low_power(btcoexist); 1673 } 1674 1675 void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type) 1676 { 1677 if (!halbtc_is_bt_coexist_available(btcoexist)) 1678 return; 1679 1680 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1681 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1682 if (btcoexist->board_info.btdm_ant_num == 1) 1683 ex_btc8723b1ant_rf_status_notify(btcoexist, type); 1684 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1685 } 1686 } 1687 1688 void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type) 1689 { 1690 u8 stack_op_type; 1691 1692 if (!halbtc_is_bt_coexist_available(btcoexist)) 1693 return; 1694 btcoexist->statistics.cnt_stack_operation_notify++; 1695 if (btcoexist->manual_control) 1696 return; 1697 1698 if ((type == HCI_BT_OP_INQUIRY_START) || 1699 (type == HCI_BT_OP_PAGING_START) || 1700 (type == HCI_BT_OP_PAIRING_START)) { 1701 stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_START; 1702 } else if ((type == HCI_BT_OP_INQUIRY_FINISH) || 1703 (type == HCI_BT_OP_PAGING_SUCCESS) || 1704 (type == HCI_BT_OP_PAGING_UNSUCCESS) || 1705 (type == HCI_BT_OP_PAIRING_FINISH)) { 1706 stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH; 1707 } else { 1708 stack_op_type = BTC_STACK_OP_NONE; 1709 } 1710 } 1711 1712 void exhalbtc_halt_notify(struct btc_coexist *btcoexist) 1713 { 1714 if (!halbtc_is_bt_coexist_available(btcoexist)) 1715 return; 1716 1717 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1718 if (btcoexist->board_info.btdm_ant_num == 2) 1719 ex_btc8821a2ant_halt_notify(btcoexist); 1720 else if (btcoexist->board_info.btdm_ant_num == 1) 1721 ex_btc8821a1ant_halt_notify(btcoexist); 1722 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1723 if (btcoexist->board_info.btdm_ant_num == 2) 1724 ex_btc8723b2ant_halt_notify(btcoexist); 1725 else if (btcoexist->board_info.btdm_ant_num == 1) 1726 ex_btc8723b1ant_halt_notify(btcoexist); 1727 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1728 if (btcoexist->board_info.btdm_ant_num == 2) 1729 ex_btc8192e2ant_halt_notify(btcoexist); 1730 } 1731 1732 btcoexist->binded = false; 1733 } 1734 1735 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state) 1736 { 1737 if (!halbtc_is_bt_coexist_available(btcoexist)) 1738 return; 1739 1740 /* currently only 1ant we have to do the notification, 1741 * once pnp is notified to sleep state, we have to leave LPS that 1742 * we can sleep normally. 1743 */ 1744 1745 if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1746 if (btcoexist->board_info.btdm_ant_num == 1) 1747 ex_btc8723b1ant_pnp_notify(btcoexist, pnp_state); 1748 else if (btcoexist->board_info.btdm_ant_num == 2) 1749 ex_btc8723b2ant_pnp_notify(btcoexist, pnp_state); 1750 } else if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1751 if (btcoexist->board_info.btdm_ant_num == 1) 1752 ex_btc8821a1ant_pnp_notify(btcoexist, pnp_state); 1753 else if (btcoexist->board_info.btdm_ant_num == 2) 1754 ex_btc8821a2ant_pnp_notify(btcoexist, pnp_state); 1755 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1756 } 1757 } 1758 1759 void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist) 1760 { 1761 struct rtl_priv *rtlpriv = btcoexist->adapter; 1762 1763 if (!halbtc_is_bt_coexist_available(btcoexist)) 1764 return; 1765 btcoexist->statistics.cnt_coex_dm_switch++; 1766 1767 halbtc_leave_low_power(btcoexist); 1768 1769 if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1770 if (btcoexist->board_info.btdm_ant_num == 1) { 1771 btcoexist->stop_coex_dm = true; 1772 ex_btc8723b1ant_coex_dm_reset(btcoexist); 1773 exhalbtc_set_ant_num(rtlpriv, 1774 BT_COEX_ANT_TYPE_DETECTED, 2); 1775 ex_btc8723b2ant_init_hwconfig(btcoexist); 1776 ex_btc8723b2ant_init_coex_dm(btcoexist); 1777 btcoexist->stop_coex_dm = false; 1778 } 1779 } 1780 1781 halbtc_normal_low_power(btcoexist); 1782 } 1783 1784 void exhalbtc_periodical(struct btc_coexist *btcoexist) 1785 { 1786 if (!halbtc_is_bt_coexist_available(btcoexist)) 1787 return; 1788 btcoexist->statistics.cnt_periodical++; 1789 1790 halbtc_leave_low_power(btcoexist); 1791 1792 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1793 if (btcoexist->board_info.btdm_ant_num == 2) 1794 ex_btc8821a2ant_periodical(btcoexist); 1795 else if (btcoexist->board_info.btdm_ant_num == 1) 1796 if (!halbtc_under_ips(btcoexist)) 1797 ex_btc8821a1ant_periodical(btcoexist); 1798 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1799 if (btcoexist->board_info.btdm_ant_num == 2) 1800 ex_btc8723b2ant_periodical(btcoexist); 1801 else if (btcoexist->board_info.btdm_ant_num == 1) 1802 ex_btc8723b1ant_periodical(btcoexist); 1803 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1804 if (btcoexist->board_info.btdm_ant_num == 2) 1805 ex_btc8192e2ant_periodical(btcoexist); 1806 } 1807 1808 halbtc_normal_low_power(btcoexist); 1809 } 1810 1811 void exhalbtc_dbg_control(struct btc_coexist *btcoexist, 1812 u8 code, u8 len, u8 *data) 1813 { 1814 if (!halbtc_is_bt_coexist_available(btcoexist)) 1815 return; 1816 btcoexist->statistics.cnt_dbg_ctrl++; 1817 1818 halbtc_leave_low_power(btcoexist); 1819 1820 halbtc_normal_low_power(btcoexist); 1821 } 1822 1823 void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq, 1824 u32 offset, u32 span, u32 seconds) 1825 { 1826 if (!halbtc_is_bt_coexist_available(btcoexist)) 1827 return; 1828 } 1829 1830 void exhalbtc_stack_update_profile_info(void) 1831 { 1832 } 1833 1834 void exhalbtc_update_min_bt_rssi(struct btc_coexist *btcoexist, s8 bt_rssi) 1835 { 1836 if (!halbtc_is_bt_coexist_available(btcoexist)) 1837 return; 1838 1839 btcoexist->stack_info.min_bt_rssi = bt_rssi; 1840 } 1841 1842 void exhalbtc_set_hci_version(struct btc_coexist *btcoexist, u16 hci_version) 1843 { 1844 if (!halbtc_is_bt_coexist_available(btcoexist)) 1845 return; 1846 1847 btcoexist->stack_info.hci_version = hci_version; 1848 } 1849 1850 void exhalbtc_set_bt_patch_version(struct btc_coexist *btcoexist, 1851 u16 bt_hci_version, u16 bt_patch_version) 1852 { 1853 if (!halbtc_is_bt_coexist_available(btcoexist)) 1854 return; 1855 1856 btcoexist->bt_info.bt_real_fw_ver = bt_patch_version; 1857 btcoexist->bt_info.bt_hci_ver = bt_hci_version; 1858 } 1859 1860 void exhalbtc_set_chip_type(struct btc_coexist *btcoexist, u8 chip_type) 1861 { 1862 switch (chip_type) { 1863 default: 1864 case BT_2WIRE: 1865 case BT_ISSC_3WIRE: 1866 case BT_ACCEL: 1867 case BT_RTL8756: 1868 btcoexist->board_info.bt_chip_type = BTC_CHIP_UNDEF; 1869 break; 1870 case BT_CSR_BC4: 1871 btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC4; 1872 break; 1873 case BT_CSR_BC8: 1874 btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC8; 1875 break; 1876 case BT_RTL8723A: 1877 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723A; 1878 break; 1879 case BT_RTL8821A: 1880 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8821; 1881 break; 1882 case BT_RTL8723B: 1883 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723B; 1884 break; 1885 } 1886 } 1887 1888 void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num) 1889 { 1890 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv); 1891 1892 if (!btcoexist) 1893 return; 1894 1895 if (BT_COEX_ANT_TYPE_PG == type) { 1896 btcoexist->board_info.pg_ant_num = ant_num; 1897 btcoexist->board_info.btdm_ant_num = ant_num; 1898 } else if (BT_COEX_ANT_TYPE_ANTDIV == type) { 1899 btcoexist->board_info.btdm_ant_num = ant_num; 1900 } else if (type == BT_COEX_ANT_TYPE_DETECTED) { 1901 btcoexist->board_info.btdm_ant_num = ant_num; 1902 if (rtlpriv->cfg->mod_params->ant_sel == 1) 1903 btcoexist->board_info.btdm_ant_pos = 1904 BTC_ANTENNA_AT_AUX_PORT; 1905 else 1906 btcoexist->board_info.btdm_ant_pos = 1907 BTC_ANTENNA_AT_MAIN_PORT; 1908 } 1909 } 1910 1911 /* Currently used by 8723b only, S0 or S1 */ 1912 void exhalbtc_set_single_ant_path(struct btc_coexist *btcoexist, 1913 u8 single_ant_path) 1914 { 1915 btcoexist->board_info.single_ant_path = single_ant_path; 1916 } 1917 1918 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist, 1919 struct seq_file *m) 1920 { 1921 if (!halbtc_is_bt_coexist_available(btcoexist)) 1922 return; 1923 1924 halbtc_leave_low_power(btcoexist); 1925 1926 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1927 if (btcoexist->board_info.btdm_ant_num == 2) 1928 ex_btc8821a2ant_display_coex_info(btcoexist, m); 1929 else if (btcoexist->board_info.btdm_ant_num == 1) 1930 ex_btc8821a1ant_display_coex_info(btcoexist, m); 1931 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1932 if (btcoexist->board_info.btdm_ant_num == 2) 1933 ex_btc8723b2ant_display_coex_info(btcoexist, m); 1934 else if (btcoexist->board_info.btdm_ant_num == 1) 1935 ex_btc8723b1ant_display_coex_info(btcoexist, m); 1936 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1937 if (btcoexist->board_info.btdm_ant_num == 2) 1938 ex_btc8192e2ant_display_coex_info(btcoexist, m); 1939 } 1940 1941 halbtc_normal_low_power(btcoexist); 1942 } 1943 1944 void exhalbtc_switch_band_notify(struct btc_coexist *btcoexist, u8 type) 1945 { 1946 if (!halbtc_is_bt_coexist_available(btcoexist)) 1947 return; 1948 1949 if (btcoexist->manual_control) 1950 return; 1951 1952 halbtc_leave_low_power(btcoexist); 1953 1954 halbtc_normal_low_power(btcoexist); 1955 } 1956 1957 void exhalbtc_switch_band_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg, 1958 u8 is_5g) 1959 { 1960 } 1961