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