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