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 * Global variables 30 ***********************************************/ 31 32 struct btc_coexist gl_bt_coexist; 33 34 u32 btc_dbg_type[BTC_MSG_MAX]; 35 36 /*************************************************** 37 * Debug related function 38 ***************************************************/ 39 static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist) 40 { 41 if (!btcoexist->binded || NULL == btcoexist->adapter) 42 return false; 43 44 return true; 45 } 46 47 static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv) 48 { 49 if (rtlpriv->link_info.busytraffic) 50 return true; 51 else 52 return false; 53 } 54 55 static void halbtc_dbg_init(void) 56 { 57 u8 i; 58 59 for (i = 0; i < BTC_MSG_MAX; i++) 60 btc_dbg_type[i] = 0; 61 62 btc_dbg_type[BTC_MSG_INTERFACE] = 63 /* INTF_INIT | */ 64 /* INTF_NOTIFY | */ 65 0; 66 67 btc_dbg_type[BTC_MSG_ALGORITHM] = 68 /* ALGO_BT_RSSI_STATE | */ 69 /* ALGO_WIFI_RSSI_STATE | */ 70 /* ALGO_BT_MONITOR | */ 71 /* ALGO_TRACE | */ 72 /* ALGO_TRACE_FW | */ 73 /* ALGO_TRACE_FW_DETAIL | */ 74 /* ALGO_TRACE_FW_EXEC | */ 75 /* ALGO_TRACE_SW | */ 76 /* ALGO_TRACE_SW_DETAIL | */ 77 /* ALGO_TRACE_SW_EXEC | */ 78 0; 79 } 80 81 static bool halbtc_is_bt40(struct rtl_priv *adapter) 82 { 83 struct rtl_priv *rtlpriv = adapter; 84 struct rtl_phy *rtlphy = &(rtlpriv->phy); 85 bool is_ht40 = true; 86 enum ht_channel_width bw = rtlphy->current_chan_bw; 87 88 if (bw == HT_CHANNEL_WIDTH_20) 89 is_ht40 = false; 90 else if (bw == HT_CHANNEL_WIDTH_20_40) 91 is_ht40 = true; 92 93 return is_ht40; 94 } 95 96 static bool halbtc_legacy(struct rtl_priv *adapter) 97 { 98 struct rtl_priv *rtlpriv = adapter; 99 struct rtl_mac *mac = rtl_mac(rtlpriv); 100 101 bool is_legacy = false; 102 103 if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G)) 104 is_legacy = true; 105 106 return is_legacy; 107 } 108 109 bool halbtc_is_wifi_uplink(struct rtl_priv *adapter) 110 { 111 struct rtl_priv *rtlpriv = adapter; 112 113 if (rtlpriv->link_info.tx_busy_traffic) 114 return true; 115 else 116 return false; 117 } 118 119 static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist) 120 { 121 struct rtl_priv *rtlpriv = 122 (struct rtl_priv *)btcoexist->adapter; 123 u32 wifi_bw = BTC_WIFI_BW_HT20; 124 125 if (halbtc_is_bt40(rtlpriv)) { 126 wifi_bw = BTC_WIFI_BW_HT40; 127 } else { 128 if (halbtc_legacy(rtlpriv)) 129 wifi_bw = BTC_WIFI_BW_LEGACY; 130 else 131 wifi_bw = BTC_WIFI_BW_HT20; 132 } 133 return wifi_bw; 134 } 135 136 static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist) 137 { 138 struct rtl_priv *rtlpriv = btcoexist->adapter; 139 struct rtl_phy *rtlphy = &(rtlpriv->phy); 140 u8 chnl = 1; 141 142 if (rtlphy->current_channel != 0) 143 chnl = rtlphy->current_channel; 144 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 145 "static halbtc_get_wifi_central_chnl:%d\n", chnl); 146 return chnl; 147 } 148 149 u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv) 150 { 151 return rtlpriv->btcoexist.btc_info.single_ant_path; 152 } 153 154 u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv) 155 { 156 return rtlpriv->btcoexist.btc_info.bt_type; 157 } 158 159 u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv) 160 { 161 u8 num; 162 163 if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2) 164 num = 2; 165 else 166 num = 1; 167 168 return num; 169 } 170 171 u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv) 172 { 173 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 174 175 return rtlhal->package_type; 176 } 177 178 static void halbtc_leave_lps(struct btc_coexist *btcoexist) 179 { 180 struct rtl_priv *rtlpriv; 181 struct rtl_ps_ctl *ppsc; 182 bool ap_enable = false; 183 184 rtlpriv = btcoexist->adapter; 185 ppsc = rtl_psc(rtlpriv); 186 187 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, 188 &ap_enable); 189 190 if (ap_enable) { 191 pr_info("halbtc_leave_lps()<--dont leave lps under AP mode\n"); 192 return; 193 } 194 195 btcoexist->bt_info.bt_ctrl_lps = true; 196 btcoexist->bt_info.bt_lps_on = false; 197 } 198 199 static void halbtc_enter_lps(struct btc_coexist *btcoexist) 200 { 201 struct rtl_priv *rtlpriv; 202 struct rtl_ps_ctl *ppsc; 203 bool ap_enable = false; 204 205 rtlpriv = btcoexist->adapter; 206 ppsc = rtl_psc(rtlpriv); 207 208 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, 209 &ap_enable); 210 211 if (ap_enable) { 212 pr_info("halbtc_enter_lps()<--dont enter lps under AP mode\n"); 213 return; 214 } 215 216 btcoexist->bt_info.bt_ctrl_lps = true; 217 btcoexist->bt_info.bt_lps_on = false; 218 } 219 220 static void halbtc_normal_lps(struct btc_coexist *btcoexist) 221 { 222 if (btcoexist->bt_info.bt_ctrl_lps) { 223 btcoexist->bt_info.bt_lps_on = false; 224 btcoexist->bt_info.bt_ctrl_lps = false; 225 } 226 } 227 228 static void halbtc_leave_low_power(void) 229 { 230 } 231 232 static void halbtc_nomal_low_power(void) 233 { 234 } 235 236 static void halbtc_disable_low_power(void) 237 { 238 } 239 240 static void halbtc_aggregation_check(void) 241 { 242 } 243 244 static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist) 245 { 246 return 0; 247 } 248 249 static s32 halbtc_get_wifi_rssi(struct rtl_priv *adapter) 250 { 251 struct rtl_priv *rtlpriv = adapter; 252 s32 undec_sm_pwdb = 0; 253 254 if (rtlpriv->mac80211.link_state >= MAC80211_LINKED) 255 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb; 256 else /* associated entry pwdb */ 257 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb; 258 return undec_sm_pwdb; 259 } 260 261 static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf) 262 { 263 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist; 264 struct rtl_priv *rtlpriv = btcoexist->adapter; 265 struct rtl_phy *rtlphy = &(rtlpriv->phy); 266 struct rtl_mac *mac = rtl_mac(rtlpriv); 267 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 268 bool *bool_tmp = (bool *)out_buf; 269 int *s32_tmp = (int *)out_buf; 270 u32 *u32_tmp = (u32 *)out_buf; 271 u8 *u8_tmp = (u8 *)out_buf; 272 bool tmp = false; 273 274 if (!halbtc_is_bt_coexist_available(btcoexist)) 275 return false; 276 277 switch (get_type) { 278 case BTC_GET_BL_HS_OPERATION: 279 *bool_tmp = false; 280 break; 281 case BTC_GET_BL_HS_CONNECTING: 282 *bool_tmp = false; 283 break; 284 case BTC_GET_BL_WIFI_CONNECTED: 285 if (rtlpriv->mac80211.link_state >= MAC80211_LINKED) 286 tmp = true; 287 *bool_tmp = tmp; 288 break; 289 case BTC_GET_BL_WIFI_BUSY: 290 if (halbtc_is_wifi_busy(rtlpriv)) 291 *bool_tmp = true; 292 else 293 *bool_tmp = false; 294 break; 295 case BTC_GET_BL_WIFI_SCAN: 296 if (mac->act_scanning) 297 *bool_tmp = true; 298 else 299 *bool_tmp = false; 300 break; 301 case BTC_GET_BL_WIFI_LINK: 302 if (mac->link_state == MAC80211_LINKING) 303 *bool_tmp = true; 304 else 305 *bool_tmp = false; 306 break; 307 case BTC_GET_BL_WIFI_ROAM: /*TODO*/ 308 if (mac->link_state == MAC80211_LINKING) 309 *bool_tmp = true; 310 else 311 *bool_tmp = false; 312 break; 313 case BTC_GET_BL_WIFI_4_WAY_PROGRESS: /*TODO*/ 314 *bool_tmp = false; 315 316 break; 317 case BTC_GET_BL_WIFI_UNDER_5G: 318 *bool_tmp = false; /*TODO*/ 319 320 case BTC_GET_BL_WIFI_DHCP: /*TODO*/ 321 break; 322 case BTC_GET_BL_WIFI_SOFTAP_IDLE: 323 *bool_tmp = true; 324 break; 325 case BTC_GET_BL_WIFI_SOFTAP_LINKING: 326 *bool_tmp = false; 327 break; 328 case BTC_GET_BL_WIFI_IN_EARLY_SUSPEND: 329 *bool_tmp = false; 330 break; 331 case BTC_GET_BL_WIFI_AP_MODE_ENABLE: 332 *bool_tmp = false; 333 break; 334 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION: 335 if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm) 336 *bool_tmp = false; 337 else 338 *bool_tmp = true; 339 break; 340 case BTC_GET_BL_WIFI_UNDER_B_MODE: 341 *bool_tmp = false; /*TODO*/ 342 break; 343 case BTC_GET_BL_EXT_SWITCH: 344 *bool_tmp = false; 345 break; 346 case BTC_GET_S4_WIFI_RSSI: 347 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv); 348 break; 349 case BTC_GET_S4_HS_RSSI: /*TODO*/ 350 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv); 351 break; 352 case BTC_GET_U4_WIFI_BW: 353 *u32_tmp = halbtc_get_wifi_bw(btcoexist); 354 break; 355 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION: 356 if (halbtc_is_wifi_uplink(rtlpriv)) 357 *u32_tmp = BTC_WIFI_TRAFFIC_TX; 358 else 359 *u32_tmp = BTC_WIFI_TRAFFIC_RX; 360 break; 361 case BTC_GET_U4_WIFI_FW_VER: 362 *u32_tmp = rtlhal->fw_version; 363 break; 364 case BTC_GET_U4_BT_PATCH_VER: 365 *u32_tmp = halbtc_get_bt_patch_version(btcoexist); 366 break; 367 case BTC_GET_U4_VENDOR: 368 *u32_tmp = BTC_VENDOR_OTHER; 369 break; 370 case BTC_GET_U1_WIFI_DOT11_CHNL: 371 *u8_tmp = rtlphy->current_channel; 372 break; 373 case BTC_GET_U1_WIFI_CENTRAL_CHNL: 374 *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist); 375 break; 376 case BTC_GET_U1_WIFI_HS_CHNL: 377 *u8_tmp = 1;/*BT_OperateChnl(rtlpriv);*/ 378 break; 379 case BTC_GET_U1_MAC_PHY_MODE: 380 *u8_tmp = BTC_MP_UNKNOWN; 381 break; 382 383 /************* 1Ant **************/ 384 case BTC_GET_U1_LPS_MODE: 385 *u8_tmp = btcoexist->pwr_mode_val[0]; 386 break; 387 388 default: 389 break; 390 } 391 392 return true; 393 } 394 395 static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf) 396 { 397 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist; 398 bool *bool_tmp = (bool *)in_buf; 399 u8 *u8_tmp = (u8 *)in_buf; 400 u32 *u32_tmp = (u32 *)in_buf; 401 402 if (!halbtc_is_bt_coexist_available(btcoexist)) 403 return false; 404 405 switch (set_type) { 406 /* set some bool type variables. */ 407 case BTC_SET_BL_BT_DISABLE: 408 btcoexist->bt_info.bt_disabled = *bool_tmp; 409 break; 410 case BTC_SET_BL_BT_TRAFFIC_BUSY: 411 btcoexist->bt_info.bt_busy = *bool_tmp; 412 break; 413 case BTC_SET_BL_BT_LIMITED_DIG: 414 btcoexist->bt_info.limited_dig = *bool_tmp; 415 break; 416 case BTC_SET_BL_FORCE_TO_ROAM: 417 btcoexist->bt_info.force_to_roam = *bool_tmp; 418 break; 419 case BTC_SET_BL_TO_REJ_AP_AGG_PKT: 420 btcoexist->bt_info.reject_agg_pkt = *bool_tmp; 421 break; 422 case BTC_SET_BL_BT_CTRL_AGG_SIZE: 423 btcoexist->bt_info.bt_ctrl_buf_size = *bool_tmp; 424 break; 425 case BTC_SET_BL_INC_SCAN_DEV_NUM: 426 btcoexist->bt_info.increase_scan_dev_num = *bool_tmp; 427 break; 428 /* set some u1Byte type variables. */ 429 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON: 430 btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp; 431 break; 432 case BTC_SET_U1_AGG_BUF_SIZE: 433 btcoexist->bt_info.agg_buf_size = *u8_tmp; 434 break; 435 /* the following are some action which will be triggered */ 436 case BTC_SET_ACT_GET_BT_RSSI: 437 /*BTHCI_SendGetBtRssiEvent(rtlpriv);*/ 438 break; 439 case BTC_SET_ACT_AGGREGATE_CTRL: 440 halbtc_aggregation_check(); 441 break; 442 443 /* 1Ant */ 444 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE: 445 btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp; 446 break; 447 case BTC_SET_UI_SCAN_SIG_COMPENSATION: 448 /* rtlpriv->mlmepriv.scan_compensation = *u8_tmp; */ 449 break; 450 case BTC_SET_U1_1ANT_LPS: 451 btcoexist->bt_info.lps_val = *u8_tmp; 452 break; 453 case BTC_SET_U1_1ANT_RPWM: 454 btcoexist->bt_info.rpwm_val = *u8_tmp; 455 break; 456 /* the following are some action which will be triggered */ 457 case BTC_SET_ACT_LEAVE_LPS: 458 halbtc_leave_lps(btcoexist); 459 break; 460 case BTC_SET_ACT_ENTER_LPS: 461 halbtc_enter_lps(btcoexist); 462 break; 463 case BTC_SET_ACT_NORMAL_LPS: 464 halbtc_normal_lps(btcoexist); 465 break; 466 case BTC_SET_ACT_DISABLE_LOW_POWER: 467 halbtc_disable_low_power(); 468 break; 469 case BTC_SET_ACT_UPDATE_RAMASK: 470 btcoexist->bt_info.ra_mask = *u32_tmp; 471 break; 472 case BTC_SET_ACT_SEND_MIMO_PS: 473 break; 474 case BTC_SET_ACT_INC_FORCE_EXEC_PWR_CMD_CNT: 475 btcoexist->bt_info.force_exec_pwr_cmd_cnt++; 476 break; 477 case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/ 478 break; 479 case BTC_SET_ACT_CTRL_BT_COEX: 480 break; 481 default: 482 break; 483 } 484 485 return true; 486 } 487 488 static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist) 489 { 490 } 491 492 static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist) 493 { 494 } 495 496 static void halbtc_display_bt_fw_info(struct btc_coexist *btcoexist) 497 { 498 } 499 500 static void halbtc_display_fw_pwr_mode_cmd(struct btc_coexist *btcoexist) 501 { 502 } 503 504 /************************************************************ 505 * IO related function 506 ************************************************************/ 507 static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr) 508 { 509 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 510 struct rtl_priv *rtlpriv = btcoexist->adapter; 511 512 return rtl_read_byte(rtlpriv, reg_addr); 513 } 514 515 static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr) 516 { 517 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 518 struct rtl_priv *rtlpriv = btcoexist->adapter; 519 520 return rtl_read_word(rtlpriv, reg_addr); 521 } 522 523 static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr) 524 { 525 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 526 struct rtl_priv *rtlpriv = btcoexist->adapter; 527 528 return rtl_read_dword(rtlpriv, reg_addr); 529 } 530 531 static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data) 532 { 533 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 534 struct rtl_priv *rtlpriv = btcoexist->adapter; 535 536 rtl_write_byte(rtlpriv, reg_addr, data); 537 } 538 539 static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr, 540 u32 bit_mask, u8 data) 541 { 542 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 543 struct rtl_priv *rtlpriv = btcoexist->adapter; 544 u8 original_value, bit_shift = 0; 545 u8 i; 546 547 if (bit_mask != MASKDWORD) {/*if not "double word" write*/ 548 original_value = rtl_read_byte(rtlpriv, reg_addr); 549 for (i = 0; i <= 7; i++) { 550 if ((bit_mask>>i) & 0x1) 551 break; 552 } 553 bit_shift = i; 554 data = (original_value & (~bit_mask)) | 555 ((data << bit_shift) & bit_mask); 556 } 557 rtl_write_byte(rtlpriv, reg_addr, data); 558 } 559 560 static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data) 561 { 562 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 563 struct rtl_priv *rtlpriv = btcoexist->adapter; 564 565 rtl_write_word(rtlpriv, reg_addr, data); 566 } 567 568 static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data) 569 { 570 struct btc_coexist *btcoexist = 571 (struct btc_coexist *)bt_context; 572 struct rtl_priv *rtlpriv = btcoexist->adapter; 573 574 rtl_write_dword(rtlpriv, reg_addr, data); 575 } 576 577 static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask, 578 u32 data) 579 { 580 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 581 struct rtl_priv *rtlpriv = btcoexist->adapter; 582 583 rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data); 584 } 585 586 static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask) 587 { 588 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 589 struct rtl_priv *rtlpriv = btcoexist->adapter; 590 591 return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask); 592 } 593 594 static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr, 595 u32 bit_mask, u32 data) 596 { 597 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 598 struct rtl_priv *rtlpriv = btcoexist->adapter; 599 600 rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data); 601 } 602 603 static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr, 604 u32 bit_mask) 605 { 606 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 607 struct rtl_priv *rtlpriv = btcoexist->adapter; 608 609 return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask); 610 } 611 612 static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id, 613 u32 cmd_len, u8 *cmd_buf) 614 { 615 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 616 struct rtl_priv *rtlpriv = btcoexist->adapter; 617 618 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id, 619 cmd_len, cmd_buf); 620 } 621 622 static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type) 623 { 624 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 625 switch (disp_type) { 626 case BTC_DBG_DISP_COEX_STATISTICS: 627 halbtc_display_coex_statistics(btcoexist); 628 break; 629 case BTC_DBG_DISP_BT_LINK_INFO: 630 halbtc_display_bt_link_info(btcoexist); 631 break; 632 case BTC_DBG_DISP_BT_FW_VER: 633 halbtc_display_bt_fw_info(btcoexist); 634 break; 635 case BTC_DBG_DISP_FW_PWR_MODE_CMD: 636 halbtc_display_fw_pwr_mode_cmd(btcoexist); 637 break; 638 default: 639 break; 640 } 641 } 642 643 /***************************************************************** 644 * Extern functions called by other module 645 *****************************************************************/ 646 bool exhalbtc_initlize_variables(struct rtl_priv *adapter) 647 { 648 struct btc_coexist *btcoexist = &gl_bt_coexist; 649 650 btcoexist->statistics.cnt_bind++; 651 652 halbtc_dbg_init(); 653 654 if (btcoexist->binded) 655 return false; 656 else 657 btcoexist->binded = true; 658 659 btcoexist->chip_interface = BTC_INTF_UNKNOWN; 660 661 if (NULL == btcoexist->adapter) 662 btcoexist->adapter = adapter; 663 664 btcoexist->stack_info.profile_notified = false; 665 666 btcoexist->btc_read_1byte = halbtc_read_1byte; 667 btcoexist->btc_write_1byte = halbtc_write_1byte; 668 btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte; 669 btcoexist->btc_read_2byte = halbtc_read_2byte; 670 btcoexist->btc_write_2byte = halbtc_write_2byte; 671 btcoexist->btc_read_4byte = halbtc_read_4byte; 672 btcoexist->btc_write_4byte = halbtc_write_4byte; 673 674 btcoexist->btc_set_bb_reg = halbtc_set_bbreg; 675 btcoexist->btc_get_bb_reg = halbtc_get_bbreg; 676 677 btcoexist->btc_set_rf_reg = halbtc_set_rfreg; 678 btcoexist->btc_get_rf_reg = halbtc_get_rfreg; 679 680 btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd; 681 btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg; 682 683 btcoexist->btc_get = halbtc_get; 684 btcoexist->btc_set = halbtc_set; 685 686 btcoexist->bt_info.bt_ctrl_buf_size = false; 687 btcoexist->bt_info.agg_buf_size = 5; 688 689 btcoexist->bt_info.increase_scan_dev_num = false; 690 return true; 691 } 692 693 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist) 694 { 695 struct rtl_priv *rtlpriv = btcoexist->adapter; 696 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 697 698 if (!halbtc_is_bt_coexist_available(btcoexist)) 699 return; 700 701 btcoexist->statistics.cnt_init_hw_config++; 702 703 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) 704 ex_btc8723b2ant_init_hwconfig(btcoexist); 705 } 706 707 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist) 708 { 709 struct rtl_priv *rtlpriv = btcoexist->adapter; 710 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 711 712 if (!halbtc_is_bt_coexist_available(btcoexist)) 713 return; 714 715 btcoexist->statistics.cnt_init_coex_dm++; 716 717 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) 718 ex_btc8723b2ant_init_coex_dm(btcoexist); 719 720 btcoexist->initilized = true; 721 } 722 723 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type) 724 { 725 struct rtl_priv *rtlpriv = btcoexist->adapter; 726 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 727 u8 ips_type; 728 729 if (!halbtc_is_bt_coexist_available(btcoexist)) 730 return; 731 btcoexist->statistics.cnt_ips_notify++; 732 if (btcoexist->manual_control) 733 return; 734 735 if (ERFOFF == type) 736 ips_type = BTC_IPS_ENTER; 737 else 738 ips_type = BTC_IPS_LEAVE; 739 740 halbtc_leave_low_power(); 741 742 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) 743 ex_btc8723b2ant_ips_notify(btcoexist, ips_type); 744 745 halbtc_nomal_low_power(); 746 } 747 748 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type) 749 { 750 struct rtl_priv *rtlpriv = btcoexist->adapter; 751 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 752 u8 lps_type; 753 754 if (!halbtc_is_bt_coexist_available(btcoexist)) 755 return; 756 btcoexist->statistics.cnt_lps_notify++; 757 if (btcoexist->manual_control) 758 return; 759 760 if (EACTIVE == type) 761 lps_type = BTC_LPS_DISABLE; 762 else 763 lps_type = BTC_LPS_ENABLE; 764 765 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) 766 ex_btc8723b2ant_lps_notify(btcoexist, lps_type); 767 } 768 769 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type) 770 { 771 struct rtl_priv *rtlpriv = btcoexist->adapter; 772 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 773 u8 scan_type; 774 775 if (!halbtc_is_bt_coexist_available(btcoexist)) 776 return; 777 btcoexist->statistics.cnt_scan_notify++; 778 if (btcoexist->manual_control) 779 return; 780 781 if (type) 782 scan_type = BTC_SCAN_START; 783 else 784 scan_type = BTC_SCAN_FINISH; 785 786 halbtc_leave_low_power(); 787 788 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) 789 ex_btc8723b2ant_scan_notify(btcoexist, scan_type); 790 791 halbtc_nomal_low_power(); 792 } 793 794 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action) 795 { 796 struct rtl_priv *rtlpriv = btcoexist->adapter; 797 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 798 u8 asso_type; 799 800 if (!halbtc_is_bt_coexist_available(btcoexist)) 801 return; 802 btcoexist->statistics.cnt_connect_notify++; 803 if (btcoexist->manual_control) 804 return; 805 806 if (action) 807 asso_type = BTC_ASSOCIATE_START; 808 else 809 asso_type = BTC_ASSOCIATE_FINISH; 810 811 halbtc_leave_low_power(); 812 813 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) 814 ex_btc8723b2ant_connect_notify(btcoexist, asso_type); 815 } 816 817 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist, 818 enum rt_media_status media_status) 819 { 820 u8 status; 821 822 if (!halbtc_is_bt_coexist_available(btcoexist)) 823 return; 824 btcoexist->statistics.cnt_media_status_notify++; 825 if (btcoexist->manual_control) 826 return; 827 828 if (RT_MEDIA_CONNECT == media_status) 829 status = BTC_MEDIA_CONNECT; 830 else 831 status = BTC_MEDIA_DISCONNECT; 832 833 halbtc_leave_low_power(); 834 835 halbtc_nomal_low_power(); 836 } 837 838 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type) 839 { 840 struct rtl_priv *rtlpriv = btcoexist->adapter; 841 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 842 u8 packet_type; 843 844 if (!halbtc_is_bt_coexist_available(btcoexist)) 845 return; 846 btcoexist->statistics.cnt_special_packet_notify++; 847 if (btcoexist->manual_control) 848 return; 849 850 packet_type = BTC_PACKET_DHCP; 851 852 halbtc_leave_low_power(); 853 854 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) 855 ex_btc8723b2ant_special_packet_notify(btcoexist, 856 packet_type); 857 858 halbtc_nomal_low_power(); 859 } 860 861 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist, 862 u8 *tmp_buf, u8 length) 863 { 864 struct rtl_priv *rtlpriv = btcoexist->adapter; 865 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 866 if (!halbtc_is_bt_coexist_available(btcoexist)) 867 return; 868 btcoexist->statistics.cnt_bt_info_notify++; 869 870 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) 871 ex_btc8723b2ant_bt_info_notify(btcoexist, tmp_buf, length); 872 } 873 874 void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type) 875 { 876 u8 stack_op_type; 877 878 if (!halbtc_is_bt_coexist_available(btcoexist)) 879 return; 880 btcoexist->statistics.cnt_stack_operation_notify++; 881 if (btcoexist->manual_control) 882 return; 883 884 stack_op_type = BTC_STACK_OP_NONE; 885 886 halbtc_leave_low_power(); 887 888 halbtc_nomal_low_power(); 889 } 890 891 void exhalbtc_halt_notify(struct btc_coexist *btcoexist) 892 { 893 struct rtl_priv *rtlpriv = btcoexist->adapter; 894 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 895 if (!halbtc_is_bt_coexist_available(btcoexist)) 896 return; 897 898 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) 899 ex_btc8723b2ant_halt_notify(btcoexist); 900 } 901 902 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state) 903 { 904 if (!halbtc_is_bt_coexist_available(btcoexist)) 905 return; 906 } 907 908 void exhalbtc_periodical(struct btc_coexist *btcoexist) 909 { 910 struct rtl_priv *rtlpriv = btcoexist->adapter; 911 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 912 if (!halbtc_is_bt_coexist_available(btcoexist)) 913 return; 914 btcoexist->statistics.cnt_periodical++; 915 916 halbtc_leave_low_power(); 917 918 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) 919 ex_btc8723b2ant_periodical(btcoexist); 920 921 halbtc_nomal_low_power(); 922 } 923 924 void exhalbtc_dbg_control(struct btc_coexist *btcoexist, 925 u8 code, u8 len, u8 *data) 926 { 927 if (!halbtc_is_bt_coexist_available(btcoexist)) 928 return; 929 btcoexist->statistics.cnt_dbg_ctrl++; 930 } 931 932 void exhalbtc_stack_update_profile_info(void) 933 { 934 } 935 936 void exhalbtc_update_min_bt_rssi(s8 bt_rssi) 937 { 938 struct btc_coexist *btcoexist = &gl_bt_coexist; 939 940 if (!halbtc_is_bt_coexist_available(btcoexist)) 941 return; 942 943 btcoexist->stack_info.min_bt_rssi = bt_rssi; 944 } 945 946 void exhalbtc_set_hci_version(u16 hci_version) 947 { 948 struct btc_coexist *btcoexist = &gl_bt_coexist; 949 950 if (!halbtc_is_bt_coexist_available(btcoexist)) 951 return; 952 953 btcoexist->stack_info.hci_version = hci_version; 954 } 955 956 void exhalbtc_set_bt_patch_version(u16 bt_hci_version, u16 bt_patch_version) 957 { 958 struct btc_coexist *btcoexist = &gl_bt_coexist; 959 960 if (!halbtc_is_bt_coexist_available(btcoexist)) 961 return; 962 963 btcoexist->bt_info.bt_real_fw_ver = bt_patch_version; 964 btcoexist->bt_info.bt_hci_ver = bt_hci_version; 965 } 966 967 void exhalbtc_set_bt_exist(bool bt_exist) 968 { 969 gl_bt_coexist.board_info.bt_exist = bt_exist; 970 } 971 972 void exhalbtc_set_chip_type(u8 chip_type) 973 { 974 switch (chip_type) { 975 default: 976 case BT_2WIRE: 977 case BT_ISSC_3WIRE: 978 case BT_ACCEL: 979 case BT_RTL8756: 980 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_UNDEF; 981 break; 982 case BT_CSR_BC4: 983 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4; 984 break; 985 case BT_CSR_BC8: 986 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8; 987 break; 988 case BT_RTL8723A: 989 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A; 990 break; 991 case BT_RTL8821A: 992 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8821; 993 break; 994 case BT_RTL8723B: 995 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B; 996 break; 997 } 998 } 999 1000 void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num) 1001 { 1002 if (BT_COEX_ANT_TYPE_PG == type) { 1003 gl_bt_coexist.board_info.pg_ant_num = ant_num; 1004 gl_bt_coexist.board_info.btdm_ant_num = ant_num; 1005 /* The antenna position: 1006 * Main (default) or Aux for pgAntNum=2 && btdmAntNum =1. 1007 * The antenna position should be determined by 1008 * auto-detect mechanism. 1009 * The following is assumed to main, 1010 * and those must be modified 1011 * if y auto-detect mechanism is ready 1012 */ 1013 if ((gl_bt_coexist.board_info.pg_ant_num == 2) && 1014 (gl_bt_coexist.board_info.btdm_ant_num == 1)) 1015 gl_bt_coexist.board_info.btdm_ant_pos = 1016 BTC_ANTENNA_AT_MAIN_PORT; 1017 else 1018 gl_bt_coexist.board_info.btdm_ant_pos = 1019 BTC_ANTENNA_AT_MAIN_PORT; 1020 } else if (BT_COEX_ANT_TYPE_ANTDIV == type) { 1021 gl_bt_coexist.board_info.btdm_ant_num = ant_num; 1022 gl_bt_coexist.board_info.btdm_ant_pos = 1023 BTC_ANTENNA_AT_MAIN_PORT; 1024 } else if (type == BT_COEX_ANT_TYPE_DETECTED) { 1025 gl_bt_coexist.board_info.btdm_ant_num = ant_num; 1026 if (rtlpriv->cfg->mod_params->ant_sel == 1) 1027 gl_bt_coexist.board_info.btdm_ant_pos = 1028 BTC_ANTENNA_AT_AUX_PORT; 1029 else 1030 gl_bt_coexist.board_info.btdm_ant_pos = 1031 BTC_ANTENNA_AT_MAIN_PORT; 1032 } 1033 } 1034 1035 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist) 1036 { 1037 struct rtl_priv *rtlpriv = btcoexist->adapter; 1038 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 1039 if (!halbtc_is_bt_coexist_available(btcoexist)) 1040 return; 1041 1042 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) 1043 ex_btc8723b2ant_display_coex_info(btcoexist); 1044 } 1045