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