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 1ANT BT Co-exist definition 22 * ******************************************* */ 23 #define BT_8821C_1ANT_COEX_DBG 0 24 #define BT_AUTO_REPORT_ONLY_8821C_1ANT 1 25 26 #define BT_INFO_8821C_1ANT_B_FTP BIT(7) 27 #define BT_INFO_8821C_1ANT_B_A2DP BIT(6) 28 #define BT_INFO_8821C_1ANT_B_HID BIT(5) 29 #define BT_INFO_8821C_1ANT_B_SCO_BUSY BIT(4) 30 #define BT_INFO_8821C_1ANT_B_ACL_BUSY BIT(3) 31 #define BT_INFO_8821C_1ANT_B_INQ_PAGE BIT(2) 32 #define BT_INFO_8821C_1ANT_B_SCO_ESCO BIT(1) 33 #define BT_INFO_8821C_1ANT_B_CONNECTION BIT(0) 34 35 #define BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT 2 36 37 #define BT_8821C_1ANT_WIFI_NOISY_THRESH 30 38 #define BT_8821C_1ANT_DEFAULT_ISOLATION 15 39 40 enum bt_8821c_1ant_signal_state { 41 BT_8821C_1ANT_GNT_SET_TO_LOW = 0x0, 42 BT_8821C_1ANT_GNT_SET_TO_HIGH = 0x1, 43 BT_8821C_1ANT_GNT_SET_BY_HW = 0x2, 44 BT_8821C_1ANT_GNT_SET_MAX 45 }; 46 47 enum bt_8821c_1ant_path_ctrl_owner { 48 BT_8821C_1ANT_PCO_BTSIDE = 0x0, 49 BT_8821C_1ANT_PCO_WLSIDE = 0x1, 50 BT_8821C_1ANT_PCO_MAX 51 }; 52 53 enum bt_8821c_1ant_gnt_ctrl_type { 54 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA = 0x0, 55 BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW = 0x1, 56 BT_8821C_1ANT_GNT_TYPE_MAX 57 }; 58 59 enum bt_8821c_1ant_gnt_ctrl_block { 60 BT_8821C_1ANT_GNT_BLOCK_RFC_BB = 0x0, 61 BT_8821C_1ANT_GNT_BLOCK_RFC = 0x1, 62 BT_8821C_1ANT_GNT_BLOCK_BB = 0x2, 63 BT_8821C_1ANT_GNT_BLOCK_MAX 64 }; 65 66 enum bt_8821c_1ant_lte_coex_table_type { 67 BT_8821C_1ANT_CTT_WL_VS_LTE = 0x0, 68 BT_8821C_1ANT_CTT_BT_VS_LTE = 0x1, 69 BT_8821C_1ANT_CTT_MAX 70 }; 71 72 enum bt_8821c_1ant_lte_break_table_type { 73 BT_8821C_1ANT_LBTT_WL_BREAK_LTE = 0x0, 74 BT_8821C_1ANT_LBTT_BT_BREAK_LTE = 0x1, 75 BT_8821C_1ANT_LBTT_LTE_BREAK_WL = 0x2, 76 BT_8821C_1ANT_LBTT_LTE_BREAK_BT = 0x3, 77 BT_8821C_1ANT_LBTT_MAX 78 }; 79 80 enum bt_info_src_8821c_1ant { 81 BT_8821C_1ANT_INFO_SRC_WIFI_FW = 0x0, 82 BT_8821C_1ANT_INFO_SRC_BT_RSP = 0x1, 83 BT_8821C_1ANT_INFO_SRC_BT_ACT = 0x2, 84 BT_8821C_1ANT_INFO_SRC_MAX 85 }; 86 87 enum bt_8821c_1ant_bt_status { 88 BT_8821C_1ANT_BSTATUS_NCON_IDLE = 0x0, 89 BT_8821C_1ANT_BSTATUS_CON_IDLE = 0x1, 90 BT_8821C_1ANT_BSTATUS_INQ_PAGE = 0x2, 91 BT_8821C_1ANT_BSTATUS_ACL_BUSY = 0x3, 92 BT_8821C_1ANT_BSTATUS_SCO_BUSY = 0x4, 93 BT_8821C_1ANT_BSTATUS_ACL_SCO_BUSY = 0x5, 94 BT_8821C_1ANT_BSTATUS_MAX 95 }; 96 97 enum bt_8821c_1ant_wifi_status { 98 BT_8821C_1ANT_WSTATUS_NCON_IDLE = 0x0, 99 BT_8821C_1ANT_WSTATUS_NCON_SCAN = 0x1, 100 BT_8821C_1ANT_WSTATUS_CON_SCAN = 0x2, 101 BT_8821C_1ANT_WSTATUS_CON_SPECPKT = 0x3, 102 BT_8821C_1ANT_WSTATUS_CON_IDLE = 0x4, 103 BT_8821C_1ANT_WSTATUS_CON_BUSY = 0x5, 104 BT_8821C_1ANT_WSTATUS_MAX 105 }; 106 107 enum bt_8821c_1ant_coex_algo { 108 BT_8821C_1ANT_COEX_UNDEFINED = 0x0, 109 BT_8821C_1ANT_COEX_SCO = 0x1, 110 BT_8821C_1ANT_COEX_HID = 0x2, 111 BT_8821C_1ANT_COEX_A2DP = 0x3, 112 BT_8821C_1ANT_COEX_A2DP_PANHS = 0x4, 113 BT_8821C_1ANT_COEX_PAN = 0x5, 114 BT_8821C_1ANT_COEX_PANHS = 0x6, 115 BT_8821C_1ANT_COEX_PAN_A2DP = 0x7, 116 BT_8821C_1ANT_COEX_PAN_HID = 0x8, 117 BT_8821C_1ANT_COEX_HID_A2DP_PAN = 0x9, 118 BT_8821C_1ANT_COEX_HID_A2DP = 0xa, 119 BT_8821C_1ANT_COEX_MAX = 0xb, 120 }; 121 122 enum bt_8821c_1ant_ext_ant_switch_type { 123 BT_8821C_1ANT_USE_DPDT = 0x0, 124 BT_8821C_1ANT_USE_SPDT = 0x1, 125 BT_8821C_1ANT_SWITCH_NONE = 0x2, 126 BT_8821C_1ANT_SWITCH_MAX 127 }; 128 129 130 enum bt_8821c_1ant_ext_ant_switch_ctrl_type { 131 BT_8821C_1ANT_CTRL_BY_BBSW = 0x0, 132 BT_8821C_1ANT_CTRL_BY_PTA = 0x1, 133 BT_8821C_1ANT_CTRL_BY_ANTDIV = 0x2, 134 BT_8821C_1ANT_CTRL_BY_MAC = 0x3, 135 BT_8821C_1ANT_CTRL_BY_BT = 0x4, 136 BT_8821C_1ANT_CTRL_BY_FW = 0x5, 137 BT_8821C_1ANT_CTRL_MAX 138 }; 139 140 enum bt_8821c_1ant_ext_ant_switch_pos_type { 141 BT_8821C_1ANT_TO_BT = 0x0, 142 BT_8821C_1ANT_TO_WLG = 0x1, 143 BT_8821C_1ANT_TO_WLA = 0x2, 144 BT_8821C_1ANT_TO_NOCARE = 0x3, 145 BT_8821C_1ANT_TO_MAX 146 }; 147 148 enum bt_8821c_1ant_phase { 149 BT_8821C_1ANT_PHASE_INIT = 0x0, 150 BT_8821C_1ANT_PHASE_WONLY = 0x1, 151 BT_8821C_1ANT_PHASE_WOFF = 0x2, 152 BT_8821C_1ANT_PHASE_2G = 0x3, 153 BT_8821C_1ANT_PHASE_5G = 0x4, 154 BT_8821C_1ANT_PHASE_BTMP = 0x5, 155 BT_8821C_1ANT_PHASE_ANTDET = 0x6, 156 BT_8821C_1ANT_PHASE_POWERON = 0x7, 157 BT_8821C_1ANT_PHASE_MCC = 0x8, 158 BT_8821C_1ANT_PHASE_MAX 159 }; 160 161 enum bt_8821c_1ant_scoreboard { 162 BT_8821C_1ANT_SCBD_ACTIVE = BIT(0), 163 BT_8821C_1ANT_SCBD_ONOFF = BIT(1), 164 BT_8821C_1ANT_SCBD_SCAN = BIT(2), 165 BT_8821C_1ANT_SCBD_UNDERTEST = BIT(3), 166 BT_8821C_1ANT_SCBD_WLBUSY = BIT(6), 167 BT_8821C_1ANT_SCBD_TDMA = BIT(9), 168 BT_8821C_1ANT_SCBD_BTCQDDR = BIT(10), 169 BT_8821C_1ANT_SCBD_ALL = 0xffff 170 }; 171 172 enum bt_8821c_1ant_RUNREASON { 173 BT_8821C_1ANT_RSN_2GSCANSTART = 0x0, 174 BT_8821C_1ANT_RSN_5GSCANSTART = 0x1, 175 BT_8821C_1ANT_RSN_SCANFINISH = 0x2, 176 BT_8821C_1ANT_RSN_2GSWITCHBAND = 0x3, 177 BT_8821C_1ANT_RSN_5GSWITCHBAND = 0x4, 178 BT_8821C_1ANT_RSN_2GCONSTART = 0x5, 179 BT_8821C_1ANT_RSN_5GCONSTART = 0x6, 180 BT_8821C_1ANT_RSN_2GCONFINISH = 0x7, 181 BT_8821C_1ANT_RSN_5GCONFINISH = 0x8, 182 BT_8821C_1ANT_RSN_2GMEDIA = 0x9, 183 BT_8821C_1ANT_RSN_5GMEDIA = 0xa, 184 BT_8821C_1ANT_RSN_MEDIADISCON = 0xb, 185 BT_8821C_1ANT_RSN_2GSPECIALPKT = 0xc, 186 BT_8821C_1ANT_RSN_5GSPECIALPKT = 0xd, 187 BT_8821C_1ANT_RSN_BTINFO = 0xe, 188 BT_8821C_1ANT_RSN_PERIODICAL = 0xf, 189 BT_8821C_1ANT_RSN_PNP = 0x10, 190 BT_8821C_1ANT_RSN_LPS = 0x11, 191 BT_8821C_1ANT_RSN_MAX 192 }; 193 194 enum bt_8821c_1ant_WL_LINK_MODE { 195 BT_8821C_1ANT_WLINK_2G1PORT = 0x0, 196 BT_8821C_1ANT_WLINK_2GMPORT = 0x1, 197 BT_8821C_1ANT_WLINK_25GMPORT = 0x2, 198 BT_8821C_1ANT_WLINK_5G = 0x3, 199 BT_8821C_1ANT_WLINK_2GGO = 0x4, 200 BT_8821C_1ANT_WLINK_BTMR = 0x5, 201 BT_8821C_1ANT_WLINK_MAX 202 }; 203 204 struct coex_dm_8821c_1ant { 205 /* hw setting */ 206 u32 cur_ant_pos_type; 207 208 /* fw mechanism */ 209 boolean cur_ignore_wlan_act; 210 211 u8 cur_ps_tdma; 212 u8 ps_tdma_para[5]; 213 boolean cur_ps_tdma_on; 214 215 boolean cur_bt_auto_report; 216 u8 cur_lps; 217 u8 cur_rpwm; 218 219 /* sw mechanism */ 220 boolean cur_low_penalty_ra; 221 222 u32 cur_val0x6c0; 223 u32 cur_val0x6c4; 224 u32 cur_val0x6c8; 225 u8 cur_val0x6cc; 226 227 /* algorithm related */ 228 u8 cur_algorithm; 229 u8 bt_status; 230 u8 wifi_chnl_info[3]; 231 232 u32 arp_cnt; 233 234 u32 cur_ext_ant_switch_status; 235 u32 setting_tdma; 236 }; 237 238 struct coex_sta_8821c_1ant { 239 boolean bt_disabled; 240 boolean bt_link_exist; 241 boolean sco_exist; 242 boolean a2dp_exist; 243 boolean hid_exist; 244 boolean pan_exist; 245 boolean msft_mr_exist; 246 boolean bt_a2dp_active; 247 u8 num_of_profile; 248 249 boolean under_lps; 250 boolean under_ips; 251 u32 specific_pkt_period_cnt; 252 u32 high_priority_tx; 253 u32 high_priority_rx; 254 u32 low_priority_tx; 255 u32 low_priority_rx; 256 boolean bt_ctr_ok; 257 boolean is_hi_pri_rx_overhead; 258 s8 bt_rssi; 259 u8 pre_bt_rssi_state; 260 u8 pre_wifi_rssi_state[4]; 261 u8 bt_info_c2h[BT_8821C_1ANT_INFO_SRC_MAX][BTC_BTINFO_LENGTH_MAX]; 262 u32 bt_info_c2h_cnt[BT_8821C_1ANT_INFO_SRC_MAX]; 263 boolean bt_whck_test; 264 boolean c2h_bt_inquiry_page; 265 boolean bt_inq_page_pre; 266 boolean bt_inq_page_remain; 267 boolean c2h_bt_remote_name_req; 268 boolean c2h_bt_page; 269 boolean bt_a2dp_active_pre; 270 boolean bt_a2dp_active_remain; 271 272 boolean wifi_high_pri_task1; 273 boolean wifi_high_pri_task2; 274 275 u8 bt_info_lb2; 276 u8 bt_info_lb3; 277 u8 bt_info_hb0; 278 u8 bt_info_hb1; 279 u8 bt_info_hb2; 280 u8 bt_info_hb3; 281 282 u32 pop_event_cnt; 283 u8 scan_ap_num; 284 u8 bt_retry_cnt; 285 286 u32 crc_ok_cck; 287 u32 crc_ok_11g; 288 u32 crc_ok_11n; 289 u32 crc_ok_11n_vht; 290 291 u32 crc_err_cck; 292 u32 crc_err_11g; 293 u32 crc_err_11n; 294 u32 crc_err_11n_vht; 295 296 boolean cck_lock; 297 boolean cck_lock_ever; 298 boolean cck_lock_warn; 299 300 u8 coex_table_type; 301 boolean force_lps_ctrl; 302 boolean concurrent_rx_mode_on; 303 u16 score_board; 304 u8 isolation_btween_wb; /* 0~ 50 */ 305 306 u8 a2dp_bit_pool; 307 u8 kt_ver; 308 boolean acl_busy; 309 boolean bt_create_connection; 310 311 u32 bt_coex_supported_feature; 312 u32 bt_coex_supported_version; 313 314 u8 bt_ble_scan_type; 315 u32 bt_ble_scan_para[3]; 316 317 boolean run_time_state; 318 boolean freeze_coexrun_by_btinfo; 319 320 boolean is_A2DP_3M; 321 boolean voice_over_HOGP; 322 boolean bt_418_hid_exist; 323 boolean bt_ble_hid_exist; 324 u8 forbidden_slot; 325 u8 hid_busy_num; 326 u8 hid_pair_cnt; 327 328 u32 cnt_remote_name_req; 329 u32 cnt_setup_link; 330 u32 cnt_reinit; 331 u32 cnt_ign_wlan_act; 332 u32 cnt_page; 333 u32 cnt_role_switch; 334 u32 cnt_wl_fw_notify; 335 336 u16 bt_reg_vendor_ac; 337 u16 bt_reg_vendor_ae; 338 339 boolean is_setup_link; 340 u8 wl_noisy_level; 341 u32 gnt_error_cnt; 342 343 u8 bt_afh_map[10]; 344 u8 bt_relink_downcount; 345 u8 bt_inq_page_downcount; 346 u8 bt_a2dp_active_downcount; 347 boolean is_tdma_btautoslot; 348 349 u8 switch_band_notify_to; 350 351 boolean is_hid_low_pri_tx_overhead; 352 boolean is_bt_multi_link; 353 boolean is_bt_a2dp_sink; 354 boolean is_set_ps_state_fail; 355 u8 cnt_set_ps_state_fail; 356 357 u8 wl_fw_dbg_info[10]; 358 u8 wl_rx_rate; 359 u8 wl_tx_rate; 360 u8 wl_rts_rx_rate; 361 u8 wl_center_channel; 362 u8 wl_tx_macid; 363 u8 wl_tx_retry_ratio; 364 365 u16 score_board_WB; 366 boolean is_hid_rcu; 367 u8 bt_a2dp_vendor_id; 368 u32 bt_a2dp_device_name; 369 u32 bt_a2dp_flush_time; 370 boolean is_ble_scan_en; 371 372 boolean is_bt_opp_exist; 373 boolean gl_wifi_busy; 374 u8 connect_ap_period_cnt; 375 376 boolean is_bt_reenable; 377 u8 cnt_bt_reenable; 378 boolean is_wifi_linkscan_process; 379 u8 wl_coex_mode; 380 u8 wl_pnp_wakeup_downcnt; 381 u32 coex_run_cnt; 382 boolean is_no_wl_5ms_extend; 383 384 u16 wl_0x42a_backup; 385 u32 wl_0x430_backup; 386 u32 wl_0x434_backup; 387 u8 wl_0x455_backup; 388 389 boolean wl_tx_limit_en; 390 boolean wl_ampdu_limit_en; 391 boolean wl_rxagg_limit_en; 392 u8 wl_rxagg_size; 393 u8 coex_run_reason; 394 395 u8 tdma_timer_base; 396 boolean wl_slot_toggle; 397 boolean wl_slot_toggle_change; /* if toggle to no-toggle */ 398 u8 wl_iot_peer; 399 }; 400 401 402 #define BT_8821C_1ANT_EXT_BAND_SWITCH_USE_DPDT 0 403 #define BT_8821C_1ANT_EXT_BAND_SWITCH_USE_SPDT 1 404 405 struct rfe_type_8821c_1ant { 406 u8 rfe_module_type; 407 boolean ext_ant_switch_exist; 408 /* 0:DPDT, 1:SPDT */ 409 u8 ext_ant_switch_type; 410 /* iF 0: DPDT_P=0, DPDT_N=1 => BTG to Main, WL_A+G to Aux */ 411 u8 ext_ant_switch_ctrl_polarity; 412 413 boolean ext_band_switch_exist; 414 /* 0:DPDT, 1:SPDT */ 415 u8 ext_band_switch_type; 416 u8 ext_band_switch_ctrl_polarity; 417 boolean ant_at_main_port; 418 419 /* If TRUE: WLG at BTG, If FALSE: WLG at WLAG */ 420 boolean wlg_locate_at_btg; 421 422 /* If diversity on */ 423 boolean ext_ant_switch_diversity; 424 }; 425 426 struct wifi_link_info_8821c_1ant { 427 u8 num_of_active_port; 428 u32 port_connect_status; 429 boolean is_all_under_5g; 430 boolean is_mcc_25g; 431 boolean is_p2p_connected; 432 boolean is_connected; 433 }; 434 435 /* ******************************************* 436 * The following is interface which will notify coex module. 437 * ******************************************* */ 438 void ex_halbtc8821c1ant_power_on_setting(struct btc_coexist *btc); 439 void ex_halbtc8821c1ant_pre_load_firmware(struct btc_coexist *btc); 440 void ex_halbtc8821c1ant_init_hw_config(struct btc_coexist *btc, 441 boolean wifi_only); 442 void ex_halbtc8821c1ant_init_coex_dm(struct btc_coexist *btc); 443 void ex_halbtc8821c1ant_ips_notify(struct btc_coexist *btc, 444 u8 type); 445 void ex_halbtc8821c1ant_lps_notify(struct btc_coexist *btc, 446 u8 type); 447 void ex_halbtc8821c1ant_scan_notify(struct btc_coexist *btc, 448 u8 type); 449 void ex_halbtc8821c1ant_switchband_notify(struct btc_coexist *btc, 450 u8 type); 451 void ex_halbtc8821c1ant_connect_notify(struct btc_coexist *btc, 452 u8 type); 453 void ex_halbtc8821c1ant_media_status_notify(struct btc_coexist *btc, 454 u8 type); 455 void ex_halbtc8821c1ant_specific_packet_notify(struct btc_coexist *btc, 456 u8 type); 457 void ex_halbtc8821c1ant_bt_info_notify(struct btc_coexist *btc, 458 u8 *tmp_buf, u8 length); 459 void ex_halbtc8821c1ant_wl_fwdbginfo_notify(struct btc_coexist *btc, 460 u8 *tmp_buf, u8 length); 461 void ex_halbtc8821c1ant_rx_rate_change_notify(struct btc_coexist *btc, 462 BOOLEAN is_data_frame, 463 u8 btc_rate_id); 464 void ex_halbtc8821c1ant_tx_rate_change_notify(struct btc_coexist *btc, 465 u8 tx_rate, 466 u8 tx_retry_ratio, u8 macid); 467 void ex_halbtc8821c1ant_rf_status_notify(struct btc_coexist *btc, 468 u8 type); 469 void ex_halbtc8821c1ant_halt_notify(struct btc_coexist *btc); 470 void ex_halbtc8821c1ant_pnp_notify(struct btc_coexist *btc, 471 u8 pnp_state); 472 void ex_halbtc8821c1ant_coex_dm_reset(struct btc_coexist *btc); 473 void ex_halbtc8821c1ant_periodical(struct btc_coexist *btc); 474 void ex_halbtc8821c1ant_display_simple_coex_info(struct btc_coexist *btc); 475 void ex_halbtc8821c1ant_display_coex_info(struct btc_coexist *btc); 476 477 #else 478 #define ex_halbtc8821c1ant_power_on_setting(btc) 479 #define ex_halbtc8821c1ant_pre_load_firmware(btc) 480 #define ex_halbtc8821c1ant_init_hw_config(btc, wifi_only) 481 #define ex_halbtc8821c1ant_init_coex_dm(btc) 482 #define ex_halbtc8821c1ant_ips_notify(btc, type) 483 #define ex_halbtc8821c1ant_lps_notify(btc, type) 484 #define ex_halbtc8821c1ant_scan_notify(btc, type) 485 #define ex_halbtc8821c1ant_switchband_notify(btc, type) 486 #define ex_halbtc8821c1ant_connect_notify(btc, type) 487 #define ex_halbtc8821c1ant_media_status_notify(btc, type) 488 #define ex_halbtc8821c1ant_specific_packet_notify(btc, type) 489 #define ex_halbtc8821c1ant_bt_info_notify(btc, tmp_buf, length) 490 #define ex_halbtc8821c1ant_wl_fwdbginfo_notify(btc, tmp_buf, length) 491 #define ex_halbtc8821c1ant_rx_rate_change_notify(btc, is_data_frame, \ 492 btc_rate_id) 493 #define ex_halbtc8821c1ant_tx_rate_change_notify(btcoexist, tx_rate, \ 494 tx_retry_ratio, macid) 495 #define ex_halbtc8821c1ant_rf_status_notify(btc, type) 496 #define ex_halbtc8821c1ant_halt_notify(btc) 497 #define ex_halbtc8821c1ant_pnp_notify(btc, pnp_state) 498 #define ex_halbtc8821c1ant_coex_dm_reset(btc) 499 #define ex_halbtc8821c1ant_periodical(btc) 500 #define ex_halbtc8821c1ant_display_simple_coex_info(btc) 501 #define ex_halbtc8821c1ant_display_coex_info(btc) 502 #endif 503 504 #endif 505 506 507