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