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 18 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) 19 20 #if (RTL8723D_SUPPORT == 1) 21 22 /* ******************************************* 23 * The following is for 8723D 1ANT BT Co-exist definition 24 * ******************************************* */ 25 #define BT_8723D_1ANT_COEX_DBG 0 26 #define BT_AUTO_REPORT_ONLY_8723D_1ANT 1 27 28 #define BT_INFO_8723D_1ANT_B_FTP BIT(7) 29 #define BT_INFO_8723D_1ANT_B_A2DP BIT(6) 30 #define BT_INFO_8723D_1ANT_B_HID BIT(5) 31 #define BT_INFO_8723D_1ANT_B_SCO_BUSY BIT(4) 32 #define BT_INFO_8723D_1ANT_B_ACL_BUSY BIT(3) 33 #define BT_INFO_8723D_1ANT_B_INQ_PAGE BIT(2) 34 #define BT_INFO_8723D_1ANT_B_SCO_ESCO BIT(1) 35 #define BT_INFO_8723D_1ANT_B_CONNECTION BIT(0) 36 37 #define BT_INFO_8723D_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ 38 (((_BT_INFO_EXT_&BIT(0))) ? TRUE : FALSE) 39 40 #define BTC_RSSI_COEX_THRESH_TOL_8723D_1ANT 2 41 42 #define BT_8723D_1ANT_WIFI_NOISY_THRESH 30 /*max: 255*/ 43 #define BT_8723D_1ANT_DEFAULT_ISOLATION 15 /*unit: dB*/ 44 45 46 /* for Antenna detection */ 47 #define BT_8723D_1ANT_ANTDET_PSDTHRES_BACKGROUND 50 48 #define BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70 49 #define BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION 55 50 #define BT_8723D_1ANT_ANTDET_PSDTHRES_1ANT 35 51 #define BT_8723D_1ANT_ANTDET_RETRY_INTERVAL 10 52 #define BT_8723D_1ANT_ANTDET_SWEEPPOINT_DELAY 60000 53 #define BT_8723D_1ANT_ANTDET_ENABLE 0 54 #define BT_8723D_1ANT_ANTDET_BTTXTIME 100 55 #define BT_8723D_1ANT_ANTDET_BTTXCHANNEL 39 56 #define BT_8723D_1ANT_ANTDET_PSD_SWWEEPCOUNT 50 57 58 #define BT_8723D_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT 30000 59 60 enum bt_8723d_1ant_signal_state { 61 BT_8723D_1ANT_SIG_STA_SET_TO_LOW = 0x0, 62 BT_8723D_1ANT_SIG_STA_SET_BY_HW = 0x0, 63 BT_8723D_1ANT_SIG_STA_SET_TO_HIGH = 0x1, 64 BT_8723D_1ANT_SIG_STA_MAX 65 }; 66 67 enum bt_8723d_1ant_path_ctrl_owner { 68 BT_8723D_1ANT_PCO_BTSIDE = 0x0, 69 BT_8723D_1ANT_PCO_WLSIDE = 0x1, 70 BT_8723D_1ANT_PCO_MAX 71 }; 72 73 enum bt_8723d_1ant_gnt_ctrl_type { 74 BT_8723D_1ANT_GNT_TYPE_CTRL_BY_PTA = 0x0, 75 BT_8723D_1ANT_GNT_TYPE_CTRL_BY_SW = 0x1, 76 BT_8723D_1ANT_GNT_TYPE_MAX 77 }; 78 79 enum bt_8723d_1ant_gnt_ctrl_block { 80 BT_8723D_1ANT_GNT_BLOCK_RFC_BB = 0x0, 81 BT_8723D_1ANT_GNT_BLOCK_RFC = 0x1, 82 BT_8723D_1ANT_GNT_BLOCK_BB = 0x2, 83 BT_8723D_1ANT_GNT_BLOCK_MAX 84 }; 85 86 enum bt_8723d_1ant_lte_coex_table_type { 87 BT_8723D_1ANT_CTT_WL_VS_LTE = 0x0, 88 BT_8723D_1ANT_CTT_BT_VS_LTE = 0x1, 89 BT_8723D_1ANT_CTT_MAX 90 }; 91 92 enum bt_8723d_1ant_lte_break_table_type { 93 BT_8723D_1ANT_LBTT_WL_BREAK_LTE = 0x0, 94 BT_8723D_1ANT_LBTT_BT_BREAK_LTE = 0x1, 95 BT_8723D_1ANT_LBTT_LTE_BREAK_WL = 0x2, 96 BT_8723D_1ANT_LBTT_LTE_BREAK_BT = 0x3, 97 BT_8723D_1ANT_LBTT_MAX 98 }; 99 100 enum bt_info_src_8723d_1ant { 101 BT_INFO_SRC_8723D_1ANT_WIFI_FW = 0x0, 102 BT_INFO_SRC_8723D_1ANT_BT_RSP = 0x1, 103 BT_INFO_SRC_8723D_1ANT_BT_ACTIVE_SEND = 0x2, 104 BT_INFO_SRC_8723D_1ANT_MAX 105 }; 106 107 enum bt_8723d_1ant_bt_status { 108 BT_8723D_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, 109 BT_8723D_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1, 110 BT_8723D_1ANT_BT_STATUS_INQ_PAGE = 0x2, 111 BT_8723D_1ANT_BT_STATUS_ACL_BUSY = 0x3, 112 BT_8723D_1ANT_BT_STATUS_SCO_BUSY = 0x4, 113 BT_8723D_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, 114 BT_8723D_1ANT_BT_STATUS_MAX 115 }; 116 117 enum bt_8723d_1ant_wifi_status { 118 BT_8723D_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0, 119 BT_8723D_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1, 120 BT_8723D_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2, 121 BT_8723D_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT = 0x3, 122 BT_8723D_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4, 123 BT_8723D_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5, 124 BT_8723D_1ANT_WIFI_STATUS_MAX 125 }; 126 127 enum bt_8723d_1ant_coex_algo { 128 BT_8723D_1ANT_COEX_ALGO_UNDEFINED = 0x0, 129 BT_8723D_1ANT_COEX_ALGO_SCO = 0x1, 130 BT_8723D_1ANT_COEX_ALGO_HID = 0x2, 131 BT_8723D_1ANT_COEX_ALGO_A2DP = 0x3, 132 BT_8723D_1ANT_COEX_ALGO_A2DP_PANHS = 0x4, 133 BT_8723D_1ANT_COEX_ALGO_PANEDR = 0x5, 134 BT_8723D_1ANT_COEX_ALGO_PANHS = 0x6, 135 BT_8723D_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7, 136 BT_8723D_1ANT_COEX_ALGO_PANEDR_HID = 0x8, 137 BT_8723D_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, 138 BT_8723D_1ANT_COEX_ALGO_HID_A2DP = 0xa, 139 BT_8723D_1ANT_COEX_ALGO_MAX = 0xb, 140 }; 141 142 enum bt_8723d_1ant_phase { 143 BT_8723D_1ANT_PHASE_COEX_INIT = 0x0, 144 BT_8723D_1ANT_PHASE_WLANONLY_INIT = 0x1, 145 BT_8723D_1ANT_PHASE_WLAN_OFF = 0x2, 146 BT_8723D_1ANT_PHASE_2G_RUNTIME = 0x3, 147 BT_8723D_1ANT_PHASE_5G_RUNTIME = 0x4, 148 BT_8723D_1ANT_PHASE_BTMPMODE = 0x5, 149 BT_8723D_1ANT_PHASE_ANTENNA_DET = 0x6, 150 BT_8723D_1ANT_PHASE_COEX_POWERON = 0x7, 151 BT_8723D_1ANT_PHASE_MAX 152 }; 153 154 enum bt_8723d_1ant_Scoreboard { 155 BT_8723D_1ANT_SCOREBOARD_ACTIVE = BIT(0), 156 BT_8723D_1ANT_SCOREBOARD_ONOFF = BIT(1), 157 BT_8723D_1ANT_SCOREBOARD_SCAN = BIT(2), 158 BT_8723D_1ANT_SCOREBOARD_UNDERTEST = BIT(3), 159 BT_8723D_1ANT_SCOREBOARD_RXGAIN = BIT(4), 160 BT_8723D_1ANT_SCOREBOARD_DKTOPP2M = BIT(5), 161 BT_8723D_1ANT_SCOREBOARD_WLBUSY = BIT(6), 162 BT_8723D_1ANT_SCOREBOARD_TDMA = BIT(9), 163 }; 164 165 struct coex_dm_8723d_1ant { 166 /* hw setting */ 167 u8 pre_ant_pos_type; 168 u8 cur_ant_pos_type; 169 /* fw mechanism */ 170 boolean cur_ignore_wlan_act; 171 boolean pre_ignore_wlan_act; 172 u8 cur_ps_tdma; 173 u8 ps_tdma_para[5]; 174 u8 ps_tdma_du_adj_type; 175 boolean cur_ps_tdma_on; 176 boolean pre_bt_auto_report; 177 boolean cur_bt_auto_report; 178 u8 pre_lps; 179 u8 cur_lps; 180 u8 pre_rpwm; 181 u8 cur_rpwm; 182 183 /* sw mechanism */ 184 boolean pre_low_penalty_ra; 185 boolean cur_low_penalty_ra; 186 u32 cur_val0x6c0; 187 u32 cur_val0x6c4; 188 u32 cur_val0x6c8; 189 u8 cur_val0x6cc; 190 boolean limited_dig; 191 192 u32 backup_arfr_cnt1; 193 u32 backup_arfr_cnt2; 194 u16 backup_retry_limit; 195 u8 backup_ampdu_max_time; 196 197 /* algorithm related */ 198 u8 pre_algorithm; 199 u8 cur_algorithm; 200 u8 bt_status; 201 u8 wifi_chnl_info[3]; 202 203 u32 pre_ra_mask; 204 u32 cur_ra_mask; 205 u8 pre_arfr_type; 206 u8 cur_arfr_type; 207 u8 pre_retry_limit_type; 208 u8 cur_retry_limit_type; 209 u8 pre_ampdu_time_type; 210 u8 cur_ampdu_time_type; 211 u32 arp_cnt; 212 213 u8 error_condition; 214 u32 setting_tdma; 215 }; 216 217 struct coex_sta_8723d_1ant { 218 boolean bt_disabled; 219 boolean bt_link_exist; 220 boolean sco_exist; 221 boolean a2dp_exist; 222 boolean hid_exist; 223 boolean pan_exist; 224 boolean bt_hi_pri_link_exist; 225 u8 num_of_profile; 226 227 boolean under_lps; 228 boolean under_ips; 229 u32 specific_pkt_period_cnt; 230 u8 connect_ap_period_cnt; 231 u8 pnp_awake_period_cnt; 232 u32 high_priority_tx; 233 u32 high_priority_rx; 234 u32 low_priority_tx; 235 u32 low_priority_rx; 236 boolean bt_ctr_ok; 237 boolean is_hipri_rx_overhead; 238 s8 bt_rssi; 239 boolean bt_tx_rx_mask; 240 boolean bt_mesh_on; 241 u8 pre_bt_rssi_state; 242 u8 pre_wifi_rssi_state[4]; 243 u8 bt_info_c2h[BT_INFO_SRC_8723D_1ANT_MAX][10]; 244 u32 bt_info_c2h_cnt[BT_INFO_SRC_8723D_1ANT_MAX]; 245 boolean bt_whck_test; 246 boolean c2h_bt_inquiry_page; 247 boolean bt_inq_page_pre; 248 boolean bt_inq_page_remain; 249 boolean c2h_bt_remote_name_req; 250 boolean c2h_bt_page; 251 boolean wifi_is_high_pri_task; 252 boolean wifi_in_scan_task; 253 u8 bt_retry_cnt; 254 u8 bt_info_ext; 255 u8 bt_info_ext2; 256 u32 pop_event_cnt; 257 u8 scan_ap_num; 258 259 u32 crc_ok_cck; 260 u32 crc_ok_11g; 261 u32 crc_ok_11n; 262 u32 crc_ok_11n_vht; 263 264 u32 crc_err_cck; 265 u32 crc_err_11g; 266 u32 crc_err_11n; 267 u32 crc_err_11n_vht; 268 269 boolean cck_lock; 270 boolean cck_lock_ever; 271 boolean cck_lock_warn; 272 273 u8 coex_table_type; 274 boolean force_lps_ctrl; 275 boolean concurrent_rx_mode_on; 276 277 u16 score_board; 278 u8 isolation_btween_wb; /* 0~ 50 */ 279 280 u8 a2dp_bit_pool; 281 u8 kt_ver; 282 boolean acl_busy; 283 boolean bt_create_connection; 284 285 u32 bt_coex_supported_feature; 286 u32 bt_coex_supported_version; 287 288 u8 bt_ble_scan_type; 289 u32 bt_ble_scan_para[3]; 290 291 boolean run_time_state; 292 boolean freeze_coexrun_by_btinfo; 293 294 boolean is_A2DP_3M; 295 boolean voice_over_HOGP; 296 u8 bt_info; 297 u8 forbidden_slot; 298 u8 hid_busy_num; 299 u8 hid_pair_cnt; 300 301 u32 cnt_remotenamereq; 302 u32 cnt_setuplink; 303 u32 cnt_reinit; 304 u32 cnt_ignwlanact; 305 u32 cnt_page; 306 u32 cnt_roleswitch; 307 308 u16 bt_reg_vendor_ac; 309 u16 bt_reg_vendor_ae; 310 311 boolean is_setup_link; 312 u8 wl_noisy_level; 313 u32 gnt_error_cnt; 314 315 u8 bt_afh_map[10]; 316 u8 bt_relink_downcount; 317 u8 bt_inq_page_downcount; 318 boolean is_tdma_btautoslot; 319 boolean is_tdma_btautoslot_hang; 320 321 boolean is_rf_state_off; 322 323 boolean is_hid_low_pri_tx_overhead; 324 boolean is_bt_multi_link; 325 boolean is_bt_a2dp_sink; 326 boolean is_bt_mesh_ver; 327 328 u8 wl_fw_dbg_info[10]; 329 u8 wl_rx_rate; 330 u8 wl_rts_rx_rate; 331 332 u16 score_board_WB; 333 334 boolean is_hid_rcu; 335 boolean is_ble_scan_en; 336 337 u16 legacy_forbidden_slot; 338 u16 le_forbidden_slot; 339 u8 bt_a2dp_vendor_id; 340 u32 bt_a2dp_device_name; 341 boolean is_bt_opp_exist; 342 boolean is_no_wl_5ms_extend; 343 344 u16 wl_0x42a_backup; 345 u32 wl_0x430_backup; 346 u32 wl_0x434_backup; 347 u8 wl_0x456_backup; 348 349 boolean wl_tx_limit_en; 350 boolean wl_ampdu_limit_en; 351 boolean wl_rxagg_limit_en; 352 u8 wl_rxagg_size; 353 354 u8 tdma_timer_base; 355 u8 wl_iot_peer; 356 357 }; 358 359 #define BT_8723D_1ANT_ANTDET_PSD_POINTS 256 360 #define BT_8723D_1ANT_ANTDET_PSD_AVGNUM 1 361 #define BT_8723D_1ANT_ANTDET_BUF_LEN 16 362 363 struct psdscan_sta_8723d_1ant { 364 365 u32 ant_det_bt_le_channel; /* BT LE Channel ex:2412 */ 366 u32 ant_det_bt_tx_time; 367 u32 ant_det_pre_psdscan_peak_val; 368 boolean ant_det_is_ant_det_available; 369 u32 ant_det_psd_scan_peak_val; 370 boolean ant_det_is_btreply_available; 371 u32 ant_det_psd_scan_peak_freq; 372 373 u8 ant_det_result; 374 u8 ant_det_peak_val[BT_8723D_1ANT_ANTDET_BUF_LEN]; 375 u8 ant_det_peak_freq[BT_8723D_1ANT_ANTDET_BUF_LEN]; 376 u32 ant_det_try_count; 377 u32 ant_det_fail_count; 378 u32 ant_det_inteval_count; 379 u32 ant_det_thres_offset; 380 381 u32 real_cent_freq; 382 s32 real_offset; 383 u32 real_span; 384 385 u32 psd_band_width; 386 u32 psd_point; 387 u32 psd_report[1024]; 388 u32 psd_report_max_hold[1024]; 389 u32 psd_start_point; 390 u32 psd_stop_point; 391 u32 psd_max_value_point; 392 u32 psd_max_value; 393 u32 psd_max_value2; 394 u32 psd_avg_value; 395 u32 psd_loop_max_value[BT_8723D_1ANT_ANTDET_PSD_SWWEEPCOUNT]; 396 u32 psd_start_base; 397 u32 psd_avg_num; /* 1/8/16/32 */ 398 u32 psd_gen_count; 399 boolean is_antdet_running; 400 boolean is_psd_show_max_only; 401 }; 402 403 /* ******************************************* 404 * The following is interface which will notify coex module. 405 * ******************************************* */ 406 void ex_halbtc8723d1ant_power_on_setting(IN struct btc_coexist *btcoexist); 407 void ex_halbtc8723d1ant_pre_load_firmware(IN struct btc_coexist *btcoexist); 408 void ex_halbtc8723d1ant_init_hw_config(IN struct btc_coexist *btcoexist, 409 IN boolean wifi_only); 410 void ex_halbtc8723d1ant_init_coex_dm(IN struct btc_coexist *btcoexist); 411 void ex_halbtc8723d1ant_ips_notify(IN struct btc_coexist *btcoexist, 412 IN u8 type); 413 void ex_halbtc8723d1ant_lps_notify(IN struct btc_coexist *btcoexist, 414 IN u8 type); 415 void ex_halbtc8723d1ant_scan_notify(IN struct btc_coexist *btcoexist, 416 IN u8 type); 417 void ex_halbtc8723d1ant_connect_notify(IN struct btc_coexist *btcoexist, 418 IN u8 type); 419 void ex_halbtc8723d1ant_media_status_notify(IN struct btc_coexist *btcoexist, 420 IN u8 type); 421 void ex_halbtc8723d1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, 422 IN u8 type); 423 void ex_halbtc8723d1ant_bt_info_notify(IN struct btc_coexist *btcoexist, 424 IN u8 *tmp_buf, IN u8 length); 425 void ex_halbtc8723d1ant_wl_fwdbginfo_notify(IN struct btc_coexist *btcoexist, 426 IN u8 *tmp_buf, IN u8 length); 427 void ex_halbtc8723d1ant_rx_rate_change_notify(IN struct btc_coexist *btcoexist, 428 IN BOOLEAN is_data_frame, IN u8 btc_rate_id); 429 void ex_halbtc8723d1ant_rf_status_notify(IN struct btc_coexist *btcoexist, 430 IN u8 type); 431 void ex_halbtc8723d1ant_halt_notify(IN struct btc_coexist *btcoexist); 432 void ex_halbtc8723d1ant_pnp_notify(IN struct btc_coexist *btcoexist, 433 IN u8 pnp_state); 434 void ex_halbtc8723d1ant_coex_dm_reset(IN struct btc_coexist *btcoexist); 435 void ex_halbtc8723d1ant_periodical(IN struct btc_coexist *btcoexist); 436 void ex_halbtc8723d1ant_set_antenna_notify(IN struct btc_coexist *btcoexist, 437 IN u8 type); 438 void ex_halbtc8723d1ant_display_coex_info(IN struct btc_coexist *btcoexist); 439 void ex_halbtc8723d1ant_antenna_detection(IN struct btc_coexist *btcoexist, 440 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); 441 void ex_halbtc8723d1ant_antenna_isolation(IN struct btc_coexist *btcoexist, 442 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); 443 444 void ex_halbtc8723d1ant_psd_scan(IN struct btc_coexist *btcoexist, 445 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); 446 void ex_halbtc8723d1ant_display_ant_detection(IN struct btc_coexist *btcoexist); 447 448 #else 449 #define ex_halbtc8723d1ant_power_on_setting(btcoexist) 450 #define ex_halbtc8723d1ant_pre_load_firmware(btcoexist) 451 #define ex_halbtc8723d1ant_init_hw_config(btcoexist, wifi_only) 452 #define ex_halbtc8723d1ant_init_coex_dm(btcoexist) 453 #define ex_halbtc8723d1ant_ips_notify(btcoexist, type) 454 #define ex_halbtc8723d1ant_lps_notify(btcoexist, type) 455 #define ex_halbtc8723d1ant_scan_notify(btcoexist, type) 456 #define ex_halbtc8723d1ant_connect_notify(btcoexist, type) 457 #define ex_halbtc8723d1ant_media_status_notify(btcoexist, type) 458 #define ex_halbtc8723d1ant_specific_packet_notify(btcoexist, type) 459 #define ex_halbtc8723d1ant_bt_info_notify(btcoexist, tmp_buf, length) 460 #define ex_halbtc8723d1ant_wl_fwdbginfo_notify(btcoexist, tmp_buf, length) 461 #define ex_halbtc8723d1ant_rx_rate_change_notify(btcoexist, is_data_frame, btc_rate_id) 462 #define ex_halbtc8723d1ant_rf_status_notify(btcoexist, type) 463 #define ex_halbtc8723d1ant_halt_notify(btcoexist) 464 #define ex_halbtc8723d1ant_pnp_notify(btcoexist, pnp_state) 465 #define ex_halbtc8723d1ant_coex_dm_reset(btcoexist) 466 #define ex_halbtc8723d1ant_periodical(btcoexist) 467 #define ex_halbtc8723d1ant_display_coex_info(btcoexist) 468 #define ex_halbtc8723d1ant_set_antenna_notify(btcoexist, type) 469 #define ex_halbtc8723d1ant_antenna_detection(btcoexist, cent_freq, offset, span, seconds) 470 #define ex_halbtc8723d1ant_antenna_isolation(btcoexist, cent_freq, offset, span, seconds) 471 #define ex_halbtc8723d1ant_psd_scan(btcoexist, cent_freq, offset, span, seconds) 472 #define ex_halbtc8723d1ant_display_ant_detection(btcoexist) 473 #endif 474 475 #endif 476 477