1 /****************************************************************************** 2 * 3 * Copyright(c) 2016 - 2017 Realtek Corporation. 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of version 2 of the GNU General Public License as 7 * published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * more details. 13 * 14 *****************************************************************************/ 15 16 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) 17 18 #if (RTL8821C_SUPPORT == 1) 19 20 /* ******************************************* 21 * The following is for 8821C 2Ant BT Co-exist definition 22 * ******************************************* */ 23 #define BT_8821C_2ANT_COEX_DBG 0 24 #define BT_AUTO_REPORT_ONLY_8821C_2ANT 1 25 26 #define BT_INFO_8821C_2ANT_B_FTP BIT(7) 27 #define BT_INFO_8821C_2ANT_B_A2DP BIT(6) 28 #define BT_INFO_8821C_2ANT_B_HID BIT(5) 29 #define BT_INFO_8821C_2ANT_B_SCO_BUSY BIT(4) 30 #define BT_INFO_8821C_2ANT_B_ACL_BUSY BIT(3) 31 #define BT_INFO_8821C_2ANT_B_INQ_PAGE BIT(2) 32 #define BT_INFO_8821C_2ANT_B_SCO_ESCO BIT(1) 33 #define BT_INFO_8821C_2ANT_B_CONNECTION BIT(0) 34 35 #define BTC_RSSI_COEX_THRESH_TOL_8821C_2ANT 2 36 37 #define BT_8821C_2ANT_WIFI_RSSI_COEXSWITCH_THRES1 80 38 #define BT_8821C_2ANT_BT_RSSI_COEXSWITCH_THRES1 80 39 #define BT_8821C_2ANT_WIFI_RSSI_COEXSWITCH_THRES2 80 40 #define BT_8821C_2ANT_BT_RSSI_COEXSWITCH_THRES2 80 41 #define BT_8821C_2ANT_DEFAULT_ISOLATION 15 42 #define BT_8821C_2ANT_WIFI_MAX_TX_POWER 15 43 #define BT_8821C_2ANT_BT_MAX_TX_POWER 3 44 #define BT_8821C_2ANT_WIFI_SIR_THRES1 -15 45 #define BT_8821C_2ANT_WIFI_SIR_THRES2 -30 46 #define BT_8821C_2ANT_BT_SIR_THRES1 -15 47 #define BT_8821C_2ANT_BT_SIR_THRES2 -30 48 49 enum bt_8821c_2ant_signal_state { 50 BT_8821C_2ANT_GNT_SET_TO_LOW = 0x0, 51 BT_8821C_2ANT_GNT_SET_TO_HIGH = 0x1, 52 BT_8821C_2ANT_GNT_SET_BY_HW = 0x2, 53 BT_8821C_2ANT_GNT_SET_MAX 54 }; 55 56 enum bt_8821c_2ant_path_ctrl_owner { 57 BT_8821C_2ANT_PCO_BTSIDE = 0x0, 58 BT_8821C_2ANT_PCO_WLSIDE = 0x1, 59 BT_8821C_2ANT_PCO_MAX 60 }; 61 62 enum bt_8821c_2ant_gnt_ctrl_type { 63 BT_8821C_2ANT_GNT_TYPE_CTRL_BY_PTA = 0x0, 64 BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW = 0x1, 65 BT_8821C_2ANT_GNT_TYPE_MAX 66 }; 67 68 enum bt_8821c_2ant_gnt_ctrl_block { 69 BT_8821C_2ANT_GNT_BLOCK_RFC_BB = 0x0, 70 BT_8821C_2ANT_GNT_BLOCK_RFC = 0x1, 71 BT_8821C_2ANT_GNT_BLOCK_BB = 0x2, 72 BT_8821C_2ANT_GNT_BLOCK_MAX 73 }; 74 75 enum bt_8821c_2ant_lte_coex_table_type { 76 BT_8821C_2ANT_CTT_WL_VS_LTE = 0x0, 77 BT_8821C_2ANT_CTT_BT_VS_LTE = 0x1, 78 BT_8821C_2ANT_CTT_MAX 79 }; 80 81 enum bt_8821c_2ant_lte_break_table_type { 82 BT_8821C_2ANT_LBTT_WL_BREAK_LTE = 0x0, 83 BT_8821C_2ANT_LBTT_BT_BREAK_LTE = 0x1, 84 BT_8821C_2ANT_LBTT_LTE_BREAK_WL = 0x2, 85 BT_8821C_2ANT_LBTT_LTE_BREAK_BT = 0x3, 86 BT_8821C_2ANT_LBTT_MAX 87 }; 88 89 enum bt_info_src_8821c_2ant { 90 BT_8821C_2ANT_INFO_SRC_WIFI_FW = 0x0, 91 BT_8821C_2ANT_INFO_SRC_BT_RSP = 0x1, 92 BT_8821C_2ANT_INFO_SRC_BT_ACT = 0x2, 93 BT_8821C_2ANT_INFO_SRC_MAX 94 }; 95 96 enum bt_8821c_2ant_bt_status { 97 BT_8821C_2ANT_BSTATUS_NCON_IDLE = 0x0, 98 BT_8821C_2ANT_BSTATUS_CON_IDLE = 0x1, 99 BT_8821C_2ANT_BSTATUS_INQ_PAGE = 0x2, 100 BT_8821C_2ANT_BSTATUS_ACL_BUSY = 0x3, 101 BT_8821C_2ANT_BSTATUS_SCO_BUSY = 0x4, 102 BT_8821C_2ANT_BSTATUS_ACL_SCO_BUSY = 0x5, 103 BT_8821C_2ANT_BSTATUS_MAX 104 }; 105 106 enum bt_8821c_2ant_coex_algo { 107 BT_8821C_2ANT_COEX_UNDEFINED = 0x0, 108 BT_8821C_2ANT_COEX_SCO = 0x1, 109 BT_8821C_2ANT_COEX_HID = 0x2, 110 BT_8821C_2ANT_COEX_A2DP = 0x3, 111 BT_8821C_2ANT_COEX_A2DP_PANHS = 0x4, 112 BT_8821C_2ANT_COEX_PAN = 0x5, 113 BT_8821C_2ANT_COEX_PANHS = 0x6, 114 BT_8821C_2ANT_COEX_PAN_A2DP = 0x7, 115 BT_8821C_2ANT_COEX_PAN_HID = 0x8, 116 BT_8821C_2ANT_COEX_HID_A2DP_PAN = 0x9, 117 BT_8821C_2ANT_COEX_HID_A2DP = 0xa, 118 BT_8821C_2ANT_COEX_NOPROFILEBUSY = 0xb, 119 BT_8821C_2ANT_COEX_A2DPSINK = 0xc, 120 BT_8821C_2ANT_COEX_MAX 121 }; 122 123 enum bt_8821c_2ant_ext_ant_switch_type { 124 BT_8821C_2ANT_USE_DPDT = 0x0, 125 BT_8821C_2ANT_USE_SPDT = 0x1, 126 BT_8821C_2ANT_SWITCH_NONE = 0x2, 127 BT_8821C_2ANT_SWITCH_MAX 128 }; 129 130 enum bt_8821c_2ant_ext_ant_switch_ctrl_type { 131 BT_8821C_2ANT_CTRL_BY_BBSW = 0x0, 132 BT_8821C_2ANT_CTRL_BY_PTA = 0x1, 133 BT_8821C_2ANT_CTRL_BY_ANTDIV = 0x2, 134 BT_8821C_2ANT_CTRL_BY_MAC = 0x3, 135 BT_8821C_2ANT_CTRL_BY_BT = 0x4, 136 BT_8821C_2ANT_CTRL_BY_FW = 0x5, 137 BT_8821C_2ANT_CTRL_MAX 138 }; 139 140 enum bt_8821c_2ant_ext_ant_switch_pos_type { 141 BT_8821C_2ANT_TO_BT = 0x0, 142 BT_8821C_2ANT_TO_WLG = 0x1, 143 BT_8821C_2ANT_TO_WLA = 0x2, 144 BT_8821C_2ANT_TO_NOCARE = 0x3, 145 BT_8821C_2ANT_TO_MAX 146 }; 147 148 enum bt_8821c_2ant_phase { 149 BT_8821C_2ANT_PHASE_INIT = 0x0, 150 BT_8821C_2ANT_PHASE_WONLY = 0x1, 151 BT_8821C_2ANT_PHASE_WOFF = 0x2, 152 BT_8821C_2ANT_PHASE_2G = 0x3, 153 BT_8821C_2ANT_PHASE_5G = 0x4, 154 BT_8821C_2ANT_PHASE_BTMP = 0x5, 155 BT_8821C_2ANT_PHASE_ANTDET = 0x6, 156 BT_8821C_2ANT_PHASE_POWERON = 0x7, 157 BT_8821C_2ANT_PHASE_MAX 158 }; 159 160 enum bt_8821c_2ant_scoreboard { 161 BT_8821C_2ANT_SCBD_ACTIVE = BIT(0), 162 BT_8821C_2ANT_SCBD_ONOFF = BIT(1), 163 BT_8821C_2ANT_SCBD_SCAN = BIT(2), 164 BT_8821C_2ANT_SCBD_UNDERTEST = BIT(3), 165 BT_8821C_2ANT_SCBD_RXGAIN = BIT(4), 166 BT_8821C_2ANT_SCBD_WLBUSY = BIT(6), 167 BT_8821C_2ANT_SCBD_TDMA = BIT(9), 168 BT_8821C_2ANT_SCBD_BTCQDDR = BIT(10), 169 BT_8821C_2ANT_SCBD_ALL = 0xffff 170 }; 171 172 enum bt_8821c_2ant_RUNREASON { 173 BT_8821C_2ANT_RSN_2GSCANSTART = 0x0, 174 BT_8821C_2ANT_RSN_5GSCANSTART = 0x1, 175 BT_8821C_2ANT_RSN_SCANFINISH = 0x2, 176 BT_8821C_2ANT_RSN_2GSWITCHBAND = 0x3, 177 BT_8821C_2ANT_RSN_5GSWITCHBAND = 0x4, 178 BT_8821C_2ANT_RSN_2GCONSTART = 0x5, 179 BT_8821C_2ANT_RSN_5GCONSTART = 0x6, 180 BT_8821C_2ANT_RSN_2GCONFINISH = 0x7, 181 BT_8821C_2ANT_RSN_5GCONFINISH = 0x8, 182 BT_8821C_2ANT_RSN_2GMEDIA = 0x9, 183 BT_8821C_2ANT_RSN_5GMEDIA = 0xa, 184 BT_8821C_2ANT_RSN_MEDIADISCON = 0xb, 185 BT_8821C_2ANT_RSN_2GSPECIALPKT = 0xc, 186 BT_8821C_2ANT_RSN_5GSPECIALPKT = 0xd, 187 BT_8821C_2ANT_RSN_BTINFO = 0xe, 188 BT_8821C_2ANT_RSN_PERIODICAL = 0xf, 189 BT_8821C_2ANT_RSN_PNP = 0x10, 190 BT_8821C_2ANT_RSN_LPS = 0x11, 191 BT_8821C_2ANT_RSN_MAX 192 }; 193 194 enum bt_8821c_2ant_WL_LINK_MODE { 195 BT_8821C_2ANT_WLINK_2G1PORT = 0x0, 196 BT_8821C_2ANT_WLINK_2GMPORT = 0x1, 197 BT_8821C_2ANT_WLINK_25GMPORT = 0x2, 198 BT_8821C_2ANT_WLINK_5G = 0x3, 199 BT_8821C_2ANT_WLINK_2GGO = 0x4, 200 BT_8821C_2ANT_WLINK_BTMR = 0x5, 201 BT_8821C_2ANT_WLINK_MAX 202 }; 203 204 struct coex_dm_8821c_2ant { 205 /* hw setting */ 206 u32 cur_ant_pos_type; 207 /* fw mechanism */ 208 209 u8 cur_bt_pwr_lvl; 210 u8 cur_wl_pwr_lvl; 211 212 boolean cur_ignore_wlan_act; 213 214 u8 cur_ps_tdma; 215 u8 ps_tdma_para[5]; 216 boolean reset_tdma_adjust; 217 boolean cur_ps_tdma_on; 218 boolean cur_bt_auto_report; 219 220 /* sw mechanism */ 221 boolean cur_low_penalty_ra; 222 223 u32 cur_val0x6c0; 224 u32 cur_val0x6c4; 225 u32 cur_val0x6c8; 226 u8 cur_val0x6cc; 227 228 /* algorithm related */ 229 u8 cur_algorithm; 230 u8 bt_status; 231 u8 wifi_chnl_info[3]; 232 233 u8 cur_lps; 234 u8 cur_rpwm; 235 236 u32 arp_cnt; 237 238 u32 cur_ext_ant_switch_status; 239 240 u8 cur_antdiv_type; 241 u32 setting_tdma; 242 }; 243 244 struct coex_sta_8821c_2ant { 245 boolean bt_disabled; 246 boolean bt_link_exist; 247 boolean sco_exist; 248 boolean a2dp_exist; 249 boolean hid_exist; 250 boolean pan_exist; 251 boolean msft_mr_exist; 252 boolean bt_a2dp_active; 253 254 boolean under_lps; 255 boolean under_ips; 256 u32 high_priority_tx; 257 u32 high_priority_rx; 258 u32 low_priority_tx; 259 u32 low_priority_rx; 260 boolean bt_ctr_ok; 261 boolean is_hi_pri_rx_overhead; 262 u8 bt_rssi; 263 u8 pre_bt_rssi_state; 264 u8 pre_wifi_rssi_state[4]; 265 u8 bt_info_c2h[BT_8821C_2ANT_INFO_SRC_MAX][BTC_BTINFO_LENGTH_MAX]; 266 u32 bt_info_c2h_cnt[BT_8821C_2ANT_INFO_SRC_MAX]; 267 boolean bt_whck_test; 268 boolean c2h_bt_inquiry_page; 269 boolean bt_inq_page_pre; 270 boolean bt_inq_page_remain; 271 boolean c2h_bt_remote_name_req; 272 273 u8 bt_info_lb2; 274 u8 bt_info_lb3; 275 u8 bt_info_hb0; 276 u8 bt_info_hb1; 277 u8 bt_info_hb2; 278 u8 bt_info_hb3; 279 280 u32 pop_event_cnt; 281 u8 scan_ap_num; 282 u8 bt_retry_cnt; 283 284 u32 crc_ok_cck; 285 u32 crc_ok_11g; 286 u32 crc_ok_11n; 287 u32 crc_ok_11n_vht; 288 u32 crc_err_cck; 289 u32 crc_err_11g; 290 u32 crc_err_11n; 291 u32 crc_err_11n_vht; 292 u32 cnt_crcok_max_in_10s; 293 294 boolean cck_lock; 295 boolean cck_lock_ever; 296 boolean cck_lock_warn; 297 298 u8 coex_table_type; 299 boolean force_lps_ctrl; 300 301 u8 dis_ver_info_cnt; 302 303 u8 a2dp_bit_pool; 304 u8 kt_ver; 305 306 boolean concurrent_rx_mode_on; 307 308 u16 score_board; 309 u8 isolation_btween_wb; /* 0~ 50 */ 310 u8 wifi_coex_thres; 311 u8 bt_coex_thres; 312 u8 wifi_coex_thres2; 313 u8 bt_coex_thres2; 314 315 u8 num_of_profile; 316 boolean acl_busy; 317 boolean bt_create_connection; 318 319 boolean wifi_high_pri_task1; 320 boolean wifi_high_pri_task2; 321 322 u32 specific_pkt_period_cnt; 323 u32 bt_coex_supported_feature; 324 u32 bt_coex_supported_version; 325 326 u8 bt_ble_scan_type; 327 u32 bt_ble_scan_para[3]; 328 329 boolean run_time_state; 330 boolean freeze_coexrun_by_btinfo; 331 332 boolean is_A2DP_3M; 333 boolean voice_over_HOGP; 334 boolean bt_418_hid_exist; 335 boolean bt_ble_hid_exist; 336 u8 forbidden_slot; 337 u8 hid_busy_num; 338 u8 hid_pair_cnt; 339 340 u32 cnt_remote_name_req; 341 u32 cnt_setup_link; 342 u32 cnt_reinit; 343 u32 cnt_ign_wlan_act; 344 u32 cnt_page; 345 u32 cnt_role_switch; 346 u32 cnt_wl_fw_notify; 347 348 u16 bt_reg_vendor_ac; 349 u16 bt_reg_vendor_ae; 350 351 boolean is_setup_link; 352 u8 wl_noisy_level; 353 u32 gnt_error_cnt; 354 355 u8 bt_afh_map[10]; 356 u8 bt_relink_downcount; 357 u8 bt_inq_page_downcount; 358 boolean is_tdma_btautoslot; 359 360 boolean is_esco_mode; 361 u8 switch_band_notify_to; 362 363 boolean is_hid_low_pri_tx_overhead; 364 boolean is_bt_multi_link; 365 boolean is_bt_a2dp_sink; 366 boolean is_set_ps_state_fail; 367 u8 cnt_set_ps_state_fail; 368 369 u8 wl_fw_dbg_info[10]; 370 u8 wl_rx_rate; 371 u8 wl_tx_rate; 372 u8 wl_rts_rx_rate; 373 u8 wl_center_channel; 374 u8 wl_tx_macid; 375 u8 wl_tx_retry_ratio; 376 377 u16 score_board_WB; 378 boolean is_hid_rcu; 379 u8 bt_a2dp_vendor_id; 380 u32 bt_a2dp_device_name; 381 u32 bt_a2dp_flush_time; 382 boolean is_ble_scan_en; 383 384 boolean is_bt_opp_exist; 385 boolean gl_wifi_busy; 386 u8 connect_ap_period_cnt; 387 388 boolean is_bt_reenable; 389 u8 cnt_bt_reenable; 390 boolean is_wifi_linkscan_process; 391 u8 wl_coex_mode; 392 u8 wl_pnp_wakeup_downcnt; 393 u32 coex_run_cnt; 394 boolean is_no_wl_5ms_extend; 395 396 u16 wl_0x42a_backup; 397 u32 wl_0x430_backup; 398 u32 wl_0x434_backup; 399 u8 wl_0x455_backup; 400 401 boolean wl_tx_limit_en; 402 boolean wl_ampdu_limit_en; 403 boolean wl_rxagg_limit_en; 404 u8 wl_rxagg_size; 405 u8 coex_run_reason; 406 407 u8 tdma_timer_base; 408 boolean wl_slot_toggle; 409 boolean wl_slot_toggle_change; /* if toggle to no-toggle */ 410 u8 wl_iot_peer; 411 }; 412 413 #define BT_8821C_2ANT_EXT_BAND_SWITCH_USE_DPDT 0 414 #define BT_8821C_2ANT_EXT_BAND_SWITCH_USE_SPDT 1 415 416 struct rfe_type_8821c_2ant { 417 u8 rfe_module_type; 418 boolean ext_ant_switch_exist; 419 /* 0:DPDT, 1:SPDT */ 420 u8 ext_ant_switch_type; 421 /* iF 0: DPDT_P=0, DPDT_N=1 => BTG to Main, WL_A+G to Aux */ 422 u8 ext_ant_switch_ctrl_polarity; 423 424 boolean ext_band_switch_exist; 425 /* 0:DPDT, 1:SPDT */ 426 u8 ext_band_switch_type; 427 u8 ext_band_switch_ctrl_polarity; 428 429 boolean ant_at_main_port; 430 431 /* If TRUE: WLG at BTG, If FALSE: WLG at WLAG */ 432 boolean wlg_locate_at_btg; 433 434 /* If diversity on */ 435 boolean ext_ant_switch_diversity; 436 }; 437 438 struct wifi_link_info_8821c_2ant { 439 u8 num_of_active_port; 440 u32 port_connect_status; 441 boolean is_all_under_5g; 442 boolean is_mcc_25g; 443 boolean is_p2p_connected; 444 boolean is_connected; 445 }; 446 447 /* ******************************************* 448 * The following is interface which will notify coex module. 449 * ******************************************* */ 450 void ex_halbtc8821c2ant_power_on_setting(struct btc_coexist *btc); 451 void ex_halbtc8821c2ant_pre_load_firmware(struct btc_coexist *btc); 452 void ex_halbtc8821c2ant_init_hw_config(struct btc_coexist *btc, 453 boolean wifi_only); 454 void ex_halbtc8821c2ant_init_coex_dm(struct btc_coexist *btc); 455 void ex_halbtc8821c2ant_ips_notify(struct btc_coexist *btc, 456 u8 type); 457 void ex_halbtc8821c2ant_lps_notify(struct btc_coexist *btc, 458 u8 type); 459 void ex_halbtc8821c2ant_scan_notify(struct btc_coexist *btc, 460 u8 type); 461 void ex_halbtc8821c2ant_switchband_notify(struct btc_coexist *btc, 462 u8 type); 463 void ex_halbtc8821c2ant_connect_notify(struct btc_coexist *btc, 464 u8 type); 465 void ex_halbtc8821c2ant_media_status_notify(struct btc_coexist *btc, 466 u8 type); 467 void ex_halbtc8821c2ant_specific_packet_notify(struct btc_coexist *btc, 468 u8 type); 469 void ex_halbtc8821c2ant_bt_info_notify(struct btc_coexist *btc, 470 u8 *tmp_buf, u8 length); 471 void ex_halbtc8821c2ant_wl_fwdbginfo_notify(struct btc_coexist *btc, 472 u8 *tmp_buf, u8 length); 473 void ex_halbtc8821c2ant_rx_rate_change_notify(struct btc_coexist *btc, 474 BOOLEAN is_data_frame, 475 u8 btc_rate_id); 476 void ex_halbtc8821c2ant_tx_rate_change_notify(struct btc_coexist *btc, 477 u8 tx_rate, 478 u8 tx_retry_ratio, u8 macid); 479 void ex_halbtc8821c2ant_rf_status_notify(struct btc_coexist *btc, 480 u8 type); 481 void ex_halbtc8821c2ant_halt_notify(struct btc_coexist *btc); 482 void ex_halbtc8821c2ant_pnp_notify(struct btc_coexist *btc, 483 u8 pnp_state); 484 void ex_halbtc8821c2ant_periodical(struct btc_coexist *btc); 485 void ex_halbtc8821c2ant_display_simple_coex_info(struct btc_coexist *btc); 486 void ex_halbtc8821c2ant_display_coex_info(struct btc_coexist *btc); 487 488 #else 489 #define ex_halbtc8821c2ant_power_on_setting(btc) 490 #define ex_halbtc8821c2ant_pre_load_firmware(btc) 491 #define ex_halbtc8821c2ant_init_hw_config(btc, wifi_only) 492 #define ex_halbtc8821c2ant_init_coex_dm(btc) 493 #define ex_halbtc8821c2ant_ips_notify(btc, type) 494 #define ex_halbtc8821c2ant_lps_notify(btc, type) 495 #define ex_halbtc8821c2ant_scan_notify(btc, type) 496 #define ex_halbtc8821c2ant_switchband_notify(btc, type) 497 #define ex_halbtc8821c2ant_connect_notify(btc, type) 498 #define ex_halbtc8821c2ant_media_status_notify(btc, type) 499 #define ex_halbtc8821c2ant_specific_packet_notify(btc, type) 500 #define ex_halbtc8821c2ant_bt_info_notify(btc, tmp_buf, length) 501 #define ex_halbtc8821c2ant_wl_fwdbginfo_notify(btc, tmp_buf, length) 502 #define ex_halbtc8821c2ant_rx_rate_change_notify(btc, is_data_frame, \ 503 btc_rate_id) 504 #define ex_halbtc8821c2ant_tx_rate_change_notify(btcoexist, tx_rate, \ 505 tx_retry_ratio, macid) 506 #define ex_halbtc8821c2ant_rf_status_notify(btc, type) 507 #define ex_halbtc8821c2ant_halt_notify(btc) 508 #define ex_halbtc8821c2ant_pnp_notify(btc, pnp_state) 509 #define ex_halbtc8821c2ant_periodical(btc) 510 #define ex_halbtc8821c2ant_display_simple_coex_info(btc) 511 #define ex_halbtc8821c2ant_display_coex_info(btc) 512 #endif 513 514 #endif 515 516 517