1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
7 * wlanfae <wlanfae@realtek.com>
8 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
11 * Larry Finger <Larry.Finger@lwfinger.net>
13 ******************************************************************************/
15 #include "halbt_precomp.h"
17 /***************************************************
18 * Debug related function
19 ***************************************************/
21 static const char *const gl_btc_wifi_bw_string[] = {
29 static const char *const gl_btc_wifi_freq_string[] = {
34 static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
36 if (!btcoexist->binded || NULL == btcoexist->adapter)
42 static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
44 if (rtlpriv->link_info.busytraffic)
50 static void halbtc_dbg_init(void)
54 /***************************************************
56 ***************************************************/
57 static bool is_any_client_connect_to_ap(struct btc_coexist *btcoexist)
59 struct rtl_priv *rtlpriv = btcoexist->adapter;
60 struct rtl_mac *mac = rtl_mac(rtlpriv);
61 struct rtl_sta_info *drv_priv;
64 if (mac->opmode == NL80211_IFTYPE_ADHOC ||
65 mac->opmode == NL80211_IFTYPE_MESH_POINT ||
66 mac->opmode == NL80211_IFTYPE_AP) {
67 if (in_interrupt() > 0) {
68 list_for_each_entry(drv_priv, &rtlpriv->entry_list,
73 spin_lock_bh(&rtlpriv->locks.entry_list_lock);
74 list_for_each_entry(drv_priv, &rtlpriv->entry_list,
78 spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
87 static bool halbtc_legacy(struct rtl_priv *adapter)
89 struct rtl_priv *rtlpriv = adapter;
90 struct rtl_mac *mac = rtl_mac(rtlpriv);
92 bool is_legacy = false;
94 if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G))
100 bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
102 struct rtl_priv *rtlpriv = adapter;
104 if (rtlpriv->link_info.tx_busy_traffic)
110 static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
112 struct rtl_priv *rtlpriv =
113 (struct rtl_priv *)btcoexist->adapter;
114 struct rtl_phy *rtlphy = &rtlpriv->phy;
115 u32 wifi_bw = BTC_WIFI_BW_HT20;
117 if (halbtc_legacy(rtlpriv)) {
118 wifi_bw = BTC_WIFI_BW_LEGACY;
120 switch (rtlphy->current_chan_bw) {
121 case HT_CHANNEL_WIDTH_20:
122 wifi_bw = BTC_WIFI_BW_HT20;
124 case HT_CHANNEL_WIDTH_20_40:
125 wifi_bw = BTC_WIFI_BW_HT40;
127 case HT_CHANNEL_WIDTH_80:
128 wifi_bw = BTC_WIFI_BW_HT80;
136 static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
138 struct rtl_priv *rtlpriv = btcoexist->adapter;
139 struct rtl_phy *rtlphy = &rtlpriv->phy;
142 if (rtlphy->current_channel != 0)
143 chnl = rtlphy->current_channel;
144 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
145 "%s:%d\n", __func__, chnl);
149 static u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv)
151 return rtlpriv->btcoexist.btc_info.single_ant_path;
154 static u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
156 return rtlpriv->btcoexist.btc_info.bt_type;
159 static u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
163 if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
171 static u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv)
173 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
175 return rtlhal->package_type;
179 u8 rtl_get_hwpg_rfe_type(struct rtl_priv *rtlpriv)
181 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
183 return rtlhal->rfe_type;
186 /* ************************************
187 * Hal helper function
188 * ************************************
191 bool halbtc_is_hw_mailbox_exist(struct btc_coexist *btcoexist)
193 if (IS_HARDWARE_TYPE_8812(btcoexist->adapter))
200 bool halbtc_send_bt_mp_operation(struct btc_coexist *btcoexist, u8 op_code,
201 u8 *cmd, u32 len, unsigned long wait_ms)
203 struct rtl_priv *rtlpriv;
204 const u8 oper_ver = 0;
207 if (!halbtc_is_hw_mailbox_exist(btcoexist))
210 if (wait_ms) /* before h2c to avoid race condition */
211 reinit_completion(&btcoexist->bt_mp_comp);
213 rtlpriv = btcoexist->adapter;
216 * fill req_num by op_code, and rtl_btc_btmpinfo_notify() use it
217 * to know message type
220 case BT_OP_GET_BT_VERSION:
221 req_num = BT_SEQ_GET_BT_VERSION;
223 case BT_OP_GET_AFH_MAP_L:
224 req_num = BT_SEQ_GET_AFH_MAP_L;
226 case BT_OP_GET_AFH_MAP_M:
227 req_num = BT_SEQ_GET_AFH_MAP_M;
229 case BT_OP_GET_AFH_MAP_H:
230 req_num = BT_SEQ_GET_AFH_MAP_H;
232 case BT_OP_GET_BT_COEX_SUPPORTED_FEATURE:
233 req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_FEATURE;
235 case BT_OP_GET_BT_COEX_SUPPORTED_VERSION:
236 req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_VERSION;
238 case BT_OP_GET_BT_ANT_DET_VAL:
239 req_num = BT_SEQ_GET_BT_ANT_DET_VAL;
241 case BT_OP_GET_BT_BLE_SCAN_PARA:
242 req_num = BT_SEQ_GET_BT_BLE_SCAN_PARA;
244 case BT_OP_GET_BT_BLE_SCAN_TYPE:
245 req_num = BT_SEQ_GET_BT_BLE_SCAN_TYPE;
247 case BT_OP_WRITE_REG_ADDR:
248 case BT_OP_WRITE_REG_VALUE:
251 req_num = BT_SEQ_DONT_CARE;
255 cmd[0] |= (oper_ver & 0x0f); /* Set OperVer */
256 cmd[0] |= ((req_num << 4) & 0xf0); /* Set ReqNum */
258 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, len, cmd);
264 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
265 "btmpinfo wait req_num=%d wait=%ld\n", req_num, wait_ms);
270 if (wait_for_completion_timeout(&btcoexist->bt_mp_comp,
271 msecs_to_jiffies(wait_ms)) == 0) {
272 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
273 "btmpinfo wait (req_num=%d) timeout\n", req_num);
275 return false; /* timeout */
281 static void halbtc_leave_lps(struct btc_coexist *btcoexist)
283 struct rtl_priv *rtlpriv;
284 struct rtl_ps_ctl *ppsc;
285 bool ap_enable = false;
287 rtlpriv = btcoexist->adapter;
288 ppsc = rtl_psc(rtlpriv);
290 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
294 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
295 "%s()<--dont leave lps under AP mode\n", __func__);
299 btcoexist->bt_info.bt_ctrl_lps = true;
300 btcoexist->bt_info.bt_lps_on = false;
301 rtl_lps_leave(rtlpriv->mac80211.hw);
304 static void halbtc_enter_lps(struct btc_coexist *btcoexist)
306 struct rtl_priv *rtlpriv;
307 struct rtl_ps_ctl *ppsc;
308 bool ap_enable = false;
310 rtlpriv = btcoexist->adapter;
311 ppsc = rtl_psc(rtlpriv);
313 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
317 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
318 "%s()<--dont enter lps under AP mode\n", __func__);
322 btcoexist->bt_info.bt_ctrl_lps = true;
323 btcoexist->bt_info.bt_lps_on = true;
324 rtl_lps_enter(rtlpriv->mac80211.hw);
327 static void halbtc_normal_lps(struct btc_coexist *btcoexist)
329 struct rtl_priv *rtlpriv;
331 rtlpriv = btcoexist->adapter;
333 if (btcoexist->bt_info.bt_ctrl_lps) {
334 btcoexist->bt_info.bt_lps_on = false;
335 rtl_lps_leave(rtlpriv->mac80211.hw);
336 btcoexist->bt_info.bt_ctrl_lps = false;
340 static void halbtc_leave_low_power(struct btc_coexist *btcoexist)
344 static void halbtc_normal_low_power(struct btc_coexist *btcoexist)
348 static void halbtc_disable_low_power(struct btc_coexist *btcoexist,
349 bool low_pwr_disable)
351 /* TODO: original/leave 32k low power */
352 btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable;
355 static void halbtc_aggregation_check(struct btc_coexist *btcoexist)
357 bool need_to_act = false;
358 static unsigned long pre_time;
359 unsigned long cur_time = 0;
360 struct rtl_priv *rtlpriv = btcoexist->adapter;
362 /* To void continuous deleteBA=>addBA=>deleteBA=>addBA
363 * This function is not allowed to continuous called
364 * It can only be called after 8 seconds
368 if (jiffies_to_msecs(cur_time - pre_time) <= 8000) {
369 /* over 8 seconds you can execute this function again. */
374 if (btcoexist->bt_info.reject_agg_pkt) {
376 btcoexist->bt_info.pre_reject_agg_pkt =
377 btcoexist->bt_info.reject_agg_pkt;
379 if (btcoexist->bt_info.pre_reject_agg_pkt) {
381 btcoexist->bt_info.pre_reject_agg_pkt =
382 btcoexist->bt_info.reject_agg_pkt;
385 if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
386 btcoexist->bt_info.bt_ctrl_agg_buf_size) {
388 btcoexist->bt_info.pre_bt_ctrl_agg_buf_size =
389 btcoexist->bt_info.bt_ctrl_agg_buf_size;
392 if (btcoexist->bt_info.bt_ctrl_agg_buf_size) {
393 if (btcoexist->bt_info.pre_agg_buf_size !=
394 btcoexist->bt_info.agg_buf_size) {
397 btcoexist->bt_info.pre_agg_buf_size =
398 btcoexist->bt_info.agg_buf_size;
402 rtl_rx_ampdu_apply(rtlpriv);
406 static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
408 u8 cmd_buffer[4] = {0};
410 if (btcoexist->bt_info.bt_real_fw_ver)
413 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
414 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_VERSION,
418 return btcoexist->bt_info.bt_real_fw_ver;
421 static u32 halbtc_get_bt_coex_supported_feature(void *btc_context)
423 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
424 u8 cmd_buffer[4] = {0};
426 if (btcoexist->bt_info.bt_supported_feature)
429 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
430 halbtc_send_bt_mp_operation(btcoexist,
431 BT_OP_GET_BT_COEX_SUPPORTED_FEATURE,
435 return btcoexist->bt_info.bt_supported_feature;
438 static u32 halbtc_get_bt_coex_supported_version(void *btc_context)
440 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
441 u8 cmd_buffer[4] = {0};
443 if (btcoexist->bt_info.bt_supported_version)
446 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
447 halbtc_send_bt_mp_operation(btcoexist,
448 BT_OP_GET_BT_COEX_SUPPORTED_VERSION,
452 return btcoexist->bt_info.bt_supported_version;
455 static u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist)
458 * [31:16] => connected port number
459 * [15:0] => port connected bit define
461 struct rtl_priv *rtlpriv = btcoexist->adapter;
462 struct rtl_mac *mac = rtl_mac(rtlpriv);
464 u32 port_connected_status = 0, num_of_connected_port = 0;
466 if (mac->opmode == NL80211_IFTYPE_STATION &&
467 mac->link_state >= MAC80211_LINKED) {
468 port_connected_status |= WIFI_STA_CONNECTED;
469 num_of_connected_port++;
471 /* AP & ADHOC & MESH */
472 if (is_any_client_connect_to_ap(btcoexist)) {
473 port_connected_status |= WIFI_AP_CONNECTED;
474 num_of_connected_port++;
476 /* TODO: P2P Connected Status */
478 ret_val = (num_of_connected_port << 16) | port_connected_status;
483 static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv)
485 int undec_sm_pwdb = 0;
487 if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
488 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
489 else /* associated entry pwdb */
490 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
491 return undec_sm_pwdb;
494 static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
496 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
497 struct rtl_priv *rtlpriv = btcoexist->adapter;
498 struct rtl_phy *rtlphy = &rtlpriv->phy;
499 struct rtl_mac *mac = rtl_mac(rtlpriv);
500 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
501 bool *bool_tmp = (bool *)out_buf;
502 int *s32_tmp = (int *)out_buf;
503 u32 *u32_tmp = (u32 *)out_buf;
504 u8 *u8_tmp = (u8 *)out_buf;
508 if (!halbtc_is_bt_coexist_available(btcoexist))
512 case BTC_GET_BL_HS_OPERATION:
516 case BTC_GET_BL_HS_CONNECTING:
520 case BTC_GET_BL_WIFI_CONNECTED:
521 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
522 rtlpriv->mac80211.link_state >= MAC80211_LINKED)
524 if (is_any_client_connect_to_ap(btcoexist))
528 case BTC_GET_BL_WIFI_BUSY:
529 if (halbtc_is_wifi_busy(rtlpriv))
534 case BTC_GET_BL_WIFI_SCAN:
535 if (mac->act_scanning)
540 case BTC_GET_BL_WIFI_LINK:
541 if (mac->link_state == MAC80211_LINKING)
546 case BTC_GET_BL_WIFI_ROAM:
547 if (mac->link_state == MAC80211_LINKING)
552 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
553 *bool_tmp = rtlpriv->btcoexist.btc_info.in_4way;
555 case BTC_GET_BL_WIFI_UNDER_5G:
556 if (rtlhal->current_bandtype == BAND_ON_5G)
561 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
562 if (mac->opmode == NL80211_IFTYPE_AP)
567 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
568 if (rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION)
573 case BTC_GET_BL_WIFI_UNDER_B_MODE:
574 if (rtlpriv->mac80211.mode == WIRELESS_MODE_B)
579 case BTC_GET_BL_EXT_SWITCH:
582 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
585 case BTC_GET_BL_IS_ASUS_8723B:
588 case BTC_GET_BL_RF4CE_CONNECTED:
591 case BTC_GET_S4_WIFI_RSSI:
592 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
594 case BTC_GET_S4_HS_RSSI:
598 case BTC_GET_U4_WIFI_BW:
599 *u32_tmp = halbtc_get_wifi_bw(btcoexist);
601 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
602 if (halbtc_is_wifi_uplink(rtlpriv))
603 *u32_tmp = BTC_WIFI_TRAFFIC_TX;
605 *u32_tmp = BTC_WIFI_TRAFFIC_RX;
607 case BTC_GET_U4_WIFI_FW_VER:
608 *u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion;
610 case BTC_GET_U4_WIFI_LINK_STATUS:
611 *u32_tmp = halbtc_get_wifi_link_status(btcoexist);
613 case BTC_GET_U4_BT_PATCH_VER:
614 *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
616 case BTC_GET_U4_VENDOR:
617 *u32_tmp = BTC_VENDOR_OTHER;
619 case BTC_GET_U4_SUPPORTED_VERSION:
620 *u32_tmp = halbtc_get_bt_coex_supported_version(btcoexist);
622 case BTC_GET_U4_SUPPORTED_FEATURE:
623 *u32_tmp = halbtc_get_bt_coex_supported_feature(btcoexist);
625 case BTC_GET_U4_WIFI_IQK_TOTAL:
626 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
629 case BTC_GET_U4_WIFI_IQK_OK:
630 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
633 case BTC_GET_U4_WIFI_IQK_FAIL:
634 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
637 case BTC_GET_U1_WIFI_DOT11_CHNL:
638 *u8_tmp = rtlphy->current_channel;
640 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
641 *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
643 case BTC_GET_U1_WIFI_HS_CHNL:
647 case BTC_GET_U1_AP_NUM:
648 *u8_tmp = rtlpriv->btcoexist.btc_info.ap_num;
650 case BTC_GET_U1_ANT_TYPE:
651 *u8_tmp = (u8)BTC_ANT_TYPE_0;
653 case BTC_GET_U1_IOT_PEER:
657 /************* 1Ant **************/
658 case BTC_GET_U1_LPS_MODE:
659 *u8_tmp = btcoexist->pwr_mode_val[0];
670 static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
672 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
673 bool *bool_tmp = (bool *)in_buf;
674 u8 *u8_tmp = (u8 *)in_buf;
675 u32 *u32_tmp = (u32 *)in_buf;
678 if (!halbtc_is_bt_coexist_available(btcoexist))
682 /* set some bool type variables. */
683 case BTC_SET_BL_BT_DISABLE:
684 btcoexist->bt_info.bt_disabled = *bool_tmp;
686 case BTC_SET_BL_BT_TRAFFIC_BUSY:
687 btcoexist->bt_info.bt_busy = *bool_tmp;
689 case BTC_SET_BL_BT_LIMITED_DIG:
690 btcoexist->bt_info.limited_dig = *bool_tmp;
692 case BTC_SET_BL_FORCE_TO_ROAM:
693 btcoexist->bt_info.force_to_roam = *bool_tmp;
695 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
696 btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
698 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
699 btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp;
701 case BTC_SET_BL_INC_SCAN_DEV_NUM:
702 btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
704 case BTC_SET_BL_BT_TX_RX_MASK:
705 btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp;
707 case BTC_SET_BL_MIRACAST_PLUS_BT:
708 btcoexist->bt_info.miracast_plus_bt = *bool_tmp;
710 /* set some u1Byte type variables. */
711 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
712 btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
714 case BTC_SET_U1_AGG_BUF_SIZE:
715 btcoexist->bt_info.agg_buf_size = *u8_tmp;
718 /* the following are some action which will be triggered */
719 case BTC_SET_ACT_GET_BT_RSSI:
722 case BTC_SET_ACT_AGGREGATE_CTRL:
723 halbtc_aggregation_check(btcoexist);
727 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
728 btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
730 case BTC_SET_UI_SCAN_SIG_COMPENSATION:
732 case BTC_SET_U1_LPS_VAL:
733 btcoexist->bt_info.lps_val = *u8_tmp;
735 case BTC_SET_U1_RPWM_VAL:
736 btcoexist->bt_info.rpwm_val = *u8_tmp;
738 /* the following are some action which will be triggered */
739 case BTC_SET_ACT_LEAVE_LPS:
740 halbtc_leave_lps(btcoexist);
742 case BTC_SET_ACT_ENTER_LPS:
743 halbtc_enter_lps(btcoexist);
745 case BTC_SET_ACT_NORMAL_LPS:
746 halbtc_normal_lps(btcoexist);
748 case BTC_SET_ACT_DISABLE_LOW_POWER:
749 halbtc_disable_low_power(btcoexist, *bool_tmp);
751 case BTC_SET_ACT_UPDATE_RAMASK:
752 btcoexist->bt_info.ra_mask = *u32_tmp;
754 case BTC_SET_ACT_SEND_MIMO_PS:
756 case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
758 case BTC_SET_ACT_CTRL_BT_COEX:
760 case BTC_SET_ACT_CTRL_8723B_ANT:
769 static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist,
774 static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist,
779 static void halbtc_display_wifi_status(struct btc_coexist *btcoexist,
782 struct rtl_priv *rtlpriv = btcoexist->adapter;
783 s32 wifi_rssi = 0, bt_hs_rssi = 0;
784 bool scan = false, link = false, roam = false, wifi_busy = false;
785 bool wifi_under_b_mode = false, wifi_under_5g = false;
786 u32 wifi_bw = BTC_WIFI_BW_HT20;
787 u32 wifi_traffic_dir = BTC_WIFI_TRAFFIC_TX;
788 u32 wifi_freq = BTC_FREQ_2_4G;
789 u32 wifi_link_status = 0x0;
790 bool bt_hs_on = false, under_ips = false, under_lps = false;
791 bool low_power = false, dc_mode = false;
792 u8 wifi_chnl = 0, wifi_hs_chnl = 0;
795 wifi_link_status = halbtc_get_wifi_link_status(btcoexist);
796 seq_printf(m, "\n %-35s = %d/ %d/ %d/ %d/ %d",
797 "STA/vWifi/HS/p2pGo/p2pGc",
798 ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0),
799 ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0),
800 ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0),
801 ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
802 ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
804 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
805 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_chnl);
806 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
807 seq_printf(m, "\n %-35s = %d / %d(%d)",
808 "Dot11 channel / HsChnl(High Speed)",
809 wifi_chnl, wifi_hs_chnl, bt_hs_on);
811 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
812 btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
813 seq_printf(m, "\n %-35s = %d/ %d",
814 "Wifi rssi/ HS rssi",
815 wifi_rssi - 100, bt_hs_rssi - 100);
817 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
818 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
819 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
820 seq_printf(m, "\n %-35s = %d/ %d/ %d ",
821 "Wifi link/ roam/ scan",
824 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
825 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
826 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
827 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
829 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
830 wifi_freq = (wifi_under_5g ? BTC_FREQ_5G : BTC_FREQ_2_4G);
831 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
834 seq_printf(m, "\n %-35s = %s / %s/ %s/ AP=%d ",
835 "Wifi freq/ bw/ traffic",
836 gl_btc_wifi_freq_string[wifi_freq],
837 ((wifi_under_b_mode) ? "11b" :
838 gl_btc_wifi_bw_string[wifi_bw]),
839 ((!wifi_busy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX ==
840 wifi_traffic_dir) ? "uplink" :
845 dc_mode = true; /*TODO*/
846 under_ips = rtlpriv->psc.inactive_pwrstate == ERFOFF ? 1 : 0;
847 under_lps = rtlpriv->psc.dot11_psmode == EACTIVE ? 0 : 1;
848 low_power = 0; /*TODO*/
849 seq_printf(m, "\n %-35s = %s%s%s%s",
851 (dc_mode ? "DC mode" : "AC mode"),
852 (under_ips ? ", IPS ON" : ""),
853 (under_lps ? ", LPS ON" : ""),
854 (low_power ? ", 32k" : ""));
857 "\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)",
858 "Power mode cmd(lps/rpwm)",
859 btcoexist->pwr_mode_val[0], btcoexist->pwr_mode_val[1],
860 btcoexist->pwr_mode_val[2], btcoexist->pwr_mode_val[3],
861 btcoexist->pwr_mode_val[4], btcoexist->pwr_mode_val[5],
862 btcoexist->bt_info.lps_val,
863 btcoexist->bt_info.rpwm_val);
866 /************************************************************
867 * IO related function
868 ************************************************************/
869 static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
871 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
872 struct rtl_priv *rtlpriv = btcoexist->adapter;
874 return rtl_read_byte(rtlpriv, reg_addr);
877 static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
879 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
880 struct rtl_priv *rtlpriv = btcoexist->adapter;
882 return rtl_read_word(rtlpriv, reg_addr);
885 static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
887 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
888 struct rtl_priv *rtlpriv = btcoexist->adapter;
890 return rtl_read_dword(rtlpriv, reg_addr);
893 static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data)
895 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
896 struct rtl_priv *rtlpriv = btcoexist->adapter;
898 rtl_write_byte(rtlpriv, reg_addr, data);
901 static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
902 u32 bit_mask, u8 data)
904 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
905 struct rtl_priv *rtlpriv = btcoexist->adapter;
906 u8 original_value, bit_shift = 0;
909 if (bit_mask != MASKDWORD) {/*if not "double word" write*/
910 original_value = rtl_read_byte(rtlpriv, reg_addr);
911 for (i = 0; i <= 7; i++) {
912 if ((bit_mask >> i) & 0x1)
916 data = (original_value & (~bit_mask)) |
917 ((data << bit_shift) & bit_mask);
919 rtl_write_byte(rtlpriv, reg_addr, data);
922 static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
924 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
925 struct rtl_priv *rtlpriv = btcoexist->adapter;
927 rtl_write_word(rtlpriv, reg_addr, data);
930 static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
932 struct btc_coexist *btcoexist =
933 (struct btc_coexist *)bt_context;
934 struct rtl_priv *rtlpriv = btcoexist->adapter;
936 rtl_write_dword(rtlpriv, reg_addr, data);
939 static void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr,
942 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
943 struct rtl_priv *rtlpriv = btcoexist->adapter;
945 if (btcoexist->chip_interface == BTC_INTF_SDIO)
947 else if (btcoexist->chip_interface == BTC_INTF_PCI)
948 rtl_write_byte(rtlpriv, reg_addr, data);
949 else if (btcoexist->chip_interface == BTC_INTF_USB)
950 rtl_write_byte(rtlpriv, reg_addr, data);
953 static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
956 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
957 struct rtl_priv *rtlpriv = btcoexist->adapter;
959 rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
962 static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
964 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
965 struct rtl_priv *rtlpriv = btcoexist->adapter;
967 return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
970 static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
971 u32 bit_mask, u32 data)
973 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
974 struct rtl_priv *rtlpriv = btcoexist->adapter;
976 rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
979 static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
982 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
983 struct rtl_priv *rtlpriv = btcoexist->adapter;
985 return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
988 static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
989 u32 cmd_len, u8 *cmd_buf)
991 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
992 struct rtl_priv *rtlpriv = btcoexist->adapter;
994 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
998 static void halbtc_send_wifi_port_id_cmd(void *bt_context)
1000 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1001 struct rtl_priv *rtlpriv = btcoexist->adapter;
1002 u8 cmd_buf[1] = {0}; /* port id [2:0] = 0 */
1004 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x71, 1,
1008 static void halbtc_set_default_port_id_cmd(void *bt_context)
1010 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1011 struct rtl_priv *rtlpriv = btcoexist->adapter;
1012 struct ieee80211_hw *hw = rtlpriv->mac80211.hw;
1014 if (!rtlpriv->cfg->ops->set_default_port_id_cmd)
1017 rtlpriv->cfg->ops->set_default_port_id_cmd(hw);
1021 void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val)
1023 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1024 u8 cmd_buffer1[4] = {0};
1025 u8 cmd_buffer2[4] = {0};
1027 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1028 *((__le16 *)&cmd_buffer1[2]) = cpu_to_le16((u16)set_val);
1029 if (!halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_VALUE,
1030 cmd_buffer1, 4, 200))
1033 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1034 cmd_buffer2[2] = reg_type;
1035 *((u8 *)&cmd_buffer2[3]) = (u8)offset;
1036 halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_ADDR,
1037 cmd_buffer2, 4, 200);
1040 static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type,
1043 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1045 switch (disp_type) {
1046 case BTC_DBG_DISP_COEX_STATISTICS:
1047 halbtc_display_coex_statistics(btcoexist, m);
1049 case BTC_DBG_DISP_BT_LINK_INFO:
1050 halbtc_display_bt_link_info(btcoexist, m);
1052 case BTC_DBG_DISP_WIFI_STATUS:
1053 halbtc_display_wifi_status(btcoexist, m);
1060 static u32 halbtc_get_bt_reg(void *btc_context, u8 reg_type, u32 offset)
1066 u32 halbtc_get_phydm_version(void *btc_context)
1068 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1069 struct rtl_priv *rtlpriv = btcoexist->adapter;
1071 if (rtlpriv->phydm.ops)
1072 return rtlpriv->phydm.ops->phydm_get_version(rtlpriv);
1078 void halbtc_phydm_modify_ra_pcr_threshold(void *btc_context,
1079 u8 ra_offset_direction,
1080 u8 ra_threshold_offset)
1082 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1083 struct rtl_priv *rtlpriv = btcoexist->adapter;
1084 struct rtl_phydm_ops *phydm_ops = rtlpriv->phydm.ops;
1087 phydm_ops->phydm_modify_ra_pcr_threshold(rtlpriv,
1088 ra_offset_direction,
1089 ra_threshold_offset);
1093 u32 halbtc_phydm_query_phy_counter(void *btc_context, const char *info_type)
1095 /* info_type may be strings below:
1096 * PHYDM_INFO_FA_OFDM, PHYDM_INFO_FA_CCK, PHYDM_INFO_CCA_OFDM,
1097 * PHYDM_INFO_CCA_CCK
1098 * IQK_TOTAL, IQK_OK, IQK_FAIL
1101 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1102 struct rtl_priv *rtlpriv = btcoexist->adapter;
1103 struct rtl_phydm_ops *phydm_ops = rtlpriv->phydm.ops;
1106 return phydm_ops->phydm_query_counter(rtlpriv, info_type);
1111 static u8 halbtc_get_ant_det_val_from_bt(void *btc_context)
1113 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1114 u8 cmd_buffer[4] = {0};
1116 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1117 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_ANT_DET_VAL,
1118 cmd_buffer, 4, 200);
1120 /* need wait completion to return correct value */
1122 return btcoexist->bt_info.bt_ant_det_val;
1125 static u8 halbtc_get_ble_scan_type_from_bt(void *btc_context)
1127 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1128 u8 cmd_buffer[4] = {0};
1130 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1131 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_TYPE,
1132 cmd_buffer, 4, 200);
1134 /* need wait completion to return correct value */
1136 return btcoexist->bt_info.bt_ble_scan_type;
1139 static u32 halbtc_get_ble_scan_para_from_bt(void *btc_context, u8 scan_type)
1141 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1142 u8 cmd_buffer[4] = {0};
1144 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1145 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_PARA,
1146 cmd_buffer, 4, 200);
1148 /* need wait completion to return correct value */
1150 return btcoexist->bt_info.bt_ble_scan_para;
1153 static bool halbtc_get_bt_afh_map_from_bt(void *btc_context, u8 map_type,
1156 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1157 u8 cmd_buffer[2] = {0};
1159 u32 *afh_map_l = (u32 *)afh_map;
1160 u32 *afh_map_m = (u32 *)(afh_map + 4);
1161 u16 *afh_map_h = (u16 *)(afh_map + 8);
1163 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1164 ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_L,
1165 cmd_buffer, 2, 200);
1169 *afh_map_l = btcoexist->bt_info.afh_map_l;
1171 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1172 ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_M,
1173 cmd_buffer, 2, 200);
1177 *afh_map_m = btcoexist->bt_info.afh_map_m;
1179 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1180 ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_H,
1181 cmd_buffer, 2, 200);
1185 *afh_map_h = btcoexist->bt_info.afh_map_h;
1191 /*****************************************************************
1192 * Extern functions called by other module
1193 *****************************************************************/
1194 bool exhalbtc_initlize_variables(struct rtl_priv *rtlpriv)
1196 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1203 btcoexist->btc_read_1byte = halbtc_read_1byte;
1204 btcoexist->btc_write_1byte = halbtc_write_1byte;
1205 btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
1206 btcoexist->btc_read_2byte = halbtc_read_2byte;
1207 btcoexist->btc_write_2byte = halbtc_write_2byte;
1208 btcoexist->btc_read_4byte = halbtc_read_4byte;
1209 btcoexist->btc_write_4byte = halbtc_write_4byte;
1210 btcoexist->btc_write_local_reg_1byte = halbtc_write_local_reg_1byte;
1212 btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
1213 btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
1215 btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
1216 btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
1218 btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
1219 btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
1221 btcoexist->btc_get = halbtc_get;
1222 btcoexist->btc_set = halbtc_set;
1223 btcoexist->btc_set_bt_reg = halbtc_set_bt_reg;
1224 btcoexist->btc_get_bt_reg = halbtc_get_bt_reg;
1226 btcoexist->bt_info.bt_ctrl_buf_size = false;
1227 btcoexist->bt_info.agg_buf_size = 5;
1229 btcoexist->bt_info.increase_scan_dev_num = false;
1231 btcoexist->btc_get_bt_coex_supported_feature =
1232 halbtc_get_bt_coex_supported_feature;
1233 btcoexist->btc_get_bt_coex_supported_version =
1234 halbtc_get_bt_coex_supported_version;
1235 btcoexist->btc_get_bt_phydm_version = halbtc_get_phydm_version;
1236 btcoexist->btc_phydm_modify_ra_pcr_threshold =
1237 halbtc_phydm_modify_ra_pcr_threshold;
1238 btcoexist->btc_phydm_query_phy_counter = halbtc_phydm_query_phy_counter;
1239 btcoexist->btc_get_ant_det_val_from_bt = halbtc_get_ant_det_val_from_bt;
1240 btcoexist->btc_get_ble_scan_type_from_bt =
1241 halbtc_get_ble_scan_type_from_bt;
1242 btcoexist->btc_get_ble_scan_para_from_bt =
1243 halbtc_get_ble_scan_para_from_bt;
1244 btcoexist->btc_get_bt_afh_map_from_bt =
1245 halbtc_get_bt_afh_map_from_bt;
1247 init_completion(&btcoexist->bt_mp_comp);
1252 bool exhalbtc_initlize_variables_wifi_only(struct rtl_priv *rtlpriv)
1254 struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
1255 struct wifi_only_haldata *wifionly_haldata;
1260 wifionly_cfg->adapter = rtlpriv;
1262 switch (rtlpriv->rtlhal.interface) {
1264 wifionly_cfg->chip_interface = BTC_INTF_PCI;
1267 wifionly_cfg->chip_interface = BTC_INTF_USB;
1270 wifionly_cfg->chip_interface = BTC_INTF_UNKNOWN;
1274 wifionly_haldata = &wifionly_cfg->haldata_info;
1276 wifionly_haldata->customer_id = CUSTOMER_NORMAL;
1277 wifionly_haldata->efuse_pg_antnum = rtl_get_hwpg_ant_num(rtlpriv);
1278 wifionly_haldata->efuse_pg_antpath =
1279 rtl_get_hwpg_single_ant_path(rtlpriv);
1280 wifionly_haldata->rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1281 wifionly_haldata->ant_div_cfg = 0;
1286 bool exhalbtc_bind_bt_coex_withadapter(void *adapter)
1288 struct rtl_priv *rtlpriv = adapter;
1289 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1290 u8 ant_num = 2, chip_type, single_ant_path = 0;
1295 if (btcoexist->binded)
1298 switch (rtlpriv->rtlhal.interface) {
1300 btcoexist->chip_interface = BTC_INTF_PCI;
1303 btcoexist->chip_interface = BTC_INTF_USB;
1306 btcoexist->chip_interface = BTC_INTF_UNKNOWN;
1310 btcoexist->binded = true;
1311 btcoexist->statistics.cnt_bind++;
1313 btcoexist->adapter = adapter;
1315 btcoexist->stack_info.profile_notified = false;
1317 btcoexist->bt_info.bt_ctrl_agg_buf_size = false;
1318 btcoexist->bt_info.agg_buf_size = 5;
1320 btcoexist->bt_info.increase_scan_dev_num = false;
1321 btcoexist->bt_info.miracast_plus_bt = false;
1323 chip_type = rtl_get_hwpg_bt_type(rtlpriv);
1324 exhalbtc_set_chip_type(btcoexist, chip_type);
1325 ant_num = rtl_get_hwpg_ant_num(rtlpriv);
1326 exhalbtc_set_ant_num(rtlpriv, BT_COEX_ANT_TYPE_PG, ant_num);
1328 /* set default antenna position to main port */
1329 btcoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
1331 single_ant_path = rtl_get_hwpg_single_ant_path(rtlpriv);
1332 exhalbtc_set_single_ant_path(btcoexist, single_ant_path);
1334 if (rtl_get_hwpg_package_type(rtlpriv) == 0)
1335 btcoexist->board_info.tfbga_package = false;
1336 else if (rtl_get_hwpg_package_type(rtlpriv) == 1)
1337 btcoexist->board_info.tfbga_package = false;
1339 btcoexist->board_info.tfbga_package = true;
1341 if (btcoexist->board_info.tfbga_package)
1342 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1343 "[BTCoex], Package Type = TFBGA\n");
1345 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1346 "[BTCoex], Package Type = Non-TFBGA\n");
1348 btcoexist->board_info.rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1349 btcoexist->board_info.ant_div_cfg = 0;
1354 void exhalbtc_power_on_setting(struct btc_coexist *btcoexist)
1356 if (!halbtc_is_bt_coexist_available(btcoexist))
1359 btcoexist->statistics.cnt_power_on++;
1361 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1362 if (btcoexist->board_info.btdm_ant_num == 1)
1363 ex_btc8822b1ant_power_on_setting(btcoexist);
1364 else if (btcoexist->board_info.btdm_ant_num == 2)
1365 ex_btc8822b2ant_power_on_setting(btcoexist);
1369 void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist)
1371 if (!halbtc_is_bt_coexist_available(btcoexist))
1374 btcoexist->statistics.cnt_pre_load_firmware++;
1376 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1377 if (btcoexist->board_info.btdm_ant_num == 1)
1378 ex_btc8822b1ant_pre_load_firmware(btcoexist);
1379 else if (btcoexist->board_info.btdm_ant_num == 2)
1380 ex_btc8822b2ant_pre_load_firmware(btcoexist);
1384 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only)
1386 if (!halbtc_is_bt_coexist_available(btcoexist))
1389 btcoexist->statistics.cnt_init_hw_config++;
1391 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1392 if (btcoexist->board_info.btdm_ant_num == 1)
1393 ex_btc8822b1ant_init_hw_config(btcoexist, wifi_only);
1394 else if (btcoexist->board_info.btdm_ant_num == 2)
1395 ex_btc8822b2ant_init_hw_config(btcoexist, wifi_only);
1397 halbtc_set_default_port_id_cmd(btcoexist);
1398 halbtc_send_wifi_port_id_cmd(btcoexist);
1402 void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg)
1404 if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1405 ex_hal8822b_wifi_only_hw_config(wifionly_cfg);
1408 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
1410 if (!halbtc_is_bt_coexist_available(btcoexist))
1413 btcoexist->statistics.cnt_init_coex_dm++;
1415 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1416 if (btcoexist->board_info.btdm_ant_num == 1)
1417 ex_btc8822b1ant_init_coex_dm(btcoexist);
1418 else if (btcoexist->board_info.btdm_ant_num == 2)
1419 ex_btc8822b2ant_init_coex_dm(btcoexist);
1422 btcoexist->initilized = true;
1425 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
1429 if (!halbtc_is_bt_coexist_available(btcoexist))
1431 btcoexist->statistics.cnt_ips_notify++;
1432 if (btcoexist->manual_control)
1436 ips_type = BTC_IPS_ENTER;
1438 ips_type = BTC_IPS_LEAVE;
1440 halbtc_leave_low_power(btcoexist);
1442 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1443 if (btcoexist->board_info.btdm_ant_num == 1)
1444 ex_btc8822b1ant_ips_notify(btcoexist, ips_type);
1445 else if (btcoexist->board_info.btdm_ant_num == 2)
1446 ex_btc8822b2ant_ips_notify(btcoexist, ips_type);
1449 halbtc_normal_low_power(btcoexist);
1452 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
1456 if (!halbtc_is_bt_coexist_available(btcoexist))
1458 btcoexist->statistics.cnt_lps_notify++;
1459 if (btcoexist->manual_control)
1462 if (type == EACTIVE)
1463 lps_type = BTC_LPS_DISABLE;
1465 lps_type = BTC_LPS_ENABLE;
1467 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1468 if (btcoexist->board_info.btdm_ant_num == 1)
1469 ex_btc8822b1ant_lps_notify(btcoexist, lps_type);
1470 else if (btcoexist->board_info.btdm_ant_num == 2)
1471 ex_btc8822b2ant_lps_notify(btcoexist, lps_type);
1475 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
1479 if (!halbtc_is_bt_coexist_available(btcoexist))
1481 btcoexist->statistics.cnt_scan_notify++;
1482 if (btcoexist->manual_control)
1486 scan_type = BTC_SCAN_START;
1488 scan_type = BTC_SCAN_FINISH;
1490 halbtc_leave_low_power(btcoexist);
1492 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1493 if (btcoexist->board_info.btdm_ant_num == 1)
1494 ex_btc8822b1ant_scan_notify(btcoexist, scan_type);
1495 else if (btcoexist->board_info.btdm_ant_num == 2)
1496 ex_btc8822b2ant_scan_notify(btcoexist, scan_type);
1499 halbtc_normal_low_power(btcoexist);
1502 void exhalbtc_scan_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1505 if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1506 ex_hal8822b_wifi_only_scannotify(wifionly_cfg, is_5g);
1509 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
1513 if (!halbtc_is_bt_coexist_available(btcoexist))
1515 btcoexist->statistics.cnt_connect_notify++;
1516 if (btcoexist->manual_control)
1520 asso_type = BTC_ASSOCIATE_START;
1522 asso_type = BTC_ASSOCIATE_FINISH;
1524 halbtc_leave_low_power(btcoexist);
1526 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1527 if (btcoexist->board_info.btdm_ant_num == 1)
1528 ex_btc8822b1ant_connect_notify(btcoexist, asso_type);
1529 else if (btcoexist->board_info.btdm_ant_num == 2)
1530 ex_btc8822b2ant_connect_notify(btcoexist, asso_type);
1533 halbtc_normal_low_power(btcoexist);
1536 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
1537 enum rt_media_status media_status)
1541 if (!halbtc_is_bt_coexist_available(btcoexist))
1543 btcoexist->statistics.cnt_media_status_notify++;
1544 if (btcoexist->manual_control)
1547 if (media_status == RT_MEDIA_CONNECT)
1548 status = BTC_MEDIA_CONNECT;
1550 status = BTC_MEDIA_DISCONNECT;
1552 halbtc_leave_low_power(btcoexist);
1554 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1555 if (btcoexist->board_info.btdm_ant_num == 1)
1556 ex_btc8822b1ant_media_status_notify(btcoexist, status);
1557 else if (btcoexist->board_info.btdm_ant_num == 2)
1558 ex_btc8822b2ant_media_status_notify(btcoexist, status);
1561 halbtc_normal_low_power(btcoexist);
1564 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
1568 if (!halbtc_is_bt_coexist_available(btcoexist))
1570 btcoexist->statistics.cnt_special_packet_notify++;
1571 if (btcoexist->manual_control)
1574 if (pkt_type == PACKET_DHCP) {
1575 packet_type = BTC_PACKET_DHCP;
1576 } else if (pkt_type == PACKET_EAPOL) {
1577 packet_type = BTC_PACKET_EAPOL;
1578 } else if (pkt_type == PACKET_ARP) {
1579 packet_type = BTC_PACKET_ARP;
1581 packet_type = BTC_PACKET_UNKNOWN;
1585 halbtc_leave_low_power(btcoexist);
1587 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1588 if (btcoexist->board_info.btdm_ant_num == 1)
1589 ex_btc8822b1ant_specific_packet_notify(btcoexist,
1591 else if (btcoexist->board_info.btdm_ant_num == 2)
1592 ex_btc8822b2ant_specific_packet_notify(btcoexist,
1596 halbtc_normal_low_power(btcoexist);
1599 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
1600 u8 *tmp_buf, u8 length)
1602 if (!halbtc_is_bt_coexist_available(btcoexist))
1604 btcoexist->statistics.cnt_bt_info_notify++;
1606 halbtc_leave_low_power(btcoexist);
1608 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1609 if (btcoexist->board_info.btdm_ant_num == 1)
1610 ex_btc8822b1ant_bt_info_notify(btcoexist, tmp_buf,
1612 else if (btcoexist->board_info.btdm_ant_num == 2)
1613 ex_btc8822b2ant_bt_info_notify(btcoexist, tmp_buf,
1617 halbtc_normal_low_power(btcoexist);
1620 void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
1622 if (!halbtc_is_bt_coexist_available(btcoexist))
1625 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1626 if (btcoexist->board_info.btdm_ant_num == 1)
1627 ex_btc8822b1ant_rf_status_notify(btcoexist, type);
1628 else if (btcoexist->board_info.btdm_ant_num == 2)
1629 ex_btc8822b2ant_rf_status_notify(btcoexist, type);
1633 void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
1635 if (!halbtc_is_bt_coexist_available(btcoexist))
1637 btcoexist->statistics.cnt_stack_operation_notify++;
1640 void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
1642 if (!halbtc_is_bt_coexist_available(btcoexist))
1645 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1646 if (btcoexist->board_info.btdm_ant_num == 1)
1647 ex_btc8822b1ant_halt_notify(btcoexist);
1648 else if (btcoexist->board_info.btdm_ant_num == 2)
1649 ex_btc8822b2ant_halt_notify(btcoexist);
1652 btcoexist->binded = false;
1655 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
1657 if (!halbtc_is_bt_coexist_available(btcoexist))
1660 /* currently only 1ant we have to do the notification,
1661 * once pnp is notified to sleep state, we have to leave LPS that
1662 * we can sleep normally.
1665 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1666 if (btcoexist->board_info.btdm_ant_num == 1)
1667 ex_btc8822b1ant_pnp_notify(btcoexist, pnp_state);
1668 else if (btcoexist->board_info.btdm_ant_num == 2)
1669 ex_btc8822b2ant_pnp_notify(btcoexist, pnp_state);
1673 void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist)
1675 if (!halbtc_is_bt_coexist_available(btcoexist))
1677 btcoexist->statistics.cnt_coex_dm_switch++;
1679 halbtc_leave_low_power(btcoexist);
1681 halbtc_normal_low_power(btcoexist);
1684 void exhalbtc_periodical(struct btc_coexist *btcoexist)
1686 if (!halbtc_is_bt_coexist_available(btcoexist))
1688 btcoexist->statistics.cnt_periodical++;
1690 halbtc_leave_low_power(btcoexist);
1692 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1693 if (btcoexist->board_info.btdm_ant_num == 1)
1694 ex_btc8822b1ant_periodical(btcoexist);
1695 else if (btcoexist->board_info.btdm_ant_num == 2)
1696 ex_btc8822b2ant_periodical(btcoexist);
1699 halbtc_normal_low_power(btcoexist);
1702 void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
1703 u8 code, u8 len, u8 *data)
1705 if (!halbtc_is_bt_coexist_available(btcoexist))
1707 btcoexist->statistics.cnt_dbg_ctrl++;
1709 halbtc_leave_low_power(btcoexist);
1711 halbtc_normal_low_power(btcoexist);
1714 void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq,
1715 u32 offset, u32 span, u32 seconds)
1717 if (!halbtc_is_bt_coexist_available(btcoexist))
1721 void exhalbtc_stack_update_profile_info(void)
1725 void exhalbtc_update_min_bt_rssi(struct btc_coexist *btcoexist, s8 bt_rssi)
1727 if (!halbtc_is_bt_coexist_available(btcoexist))
1730 btcoexist->stack_info.min_bt_rssi = bt_rssi;
1733 void exhalbtc_set_hci_version(struct btc_coexist *btcoexist, u16 hci_version)
1735 if (!halbtc_is_bt_coexist_available(btcoexist))
1738 btcoexist->stack_info.hci_version = hci_version;
1741 void exhalbtc_set_bt_patch_version(struct btc_coexist *btcoexist,
1742 u16 bt_hci_version, u16 bt_patch_version)
1744 if (!halbtc_is_bt_coexist_available(btcoexist))
1747 btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
1748 btcoexist->bt_info.bt_hci_ver = bt_hci_version;
1751 void exhalbtc_set_chip_type(struct btc_coexist *btcoexist, u8 chip_type)
1753 switch (chip_type) {
1759 btcoexist->board_info.bt_chip_type = BTC_CHIP_UNDEF;
1762 btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
1765 btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
1768 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723A;
1771 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8821;
1774 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723B;
1779 void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num)
1781 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1786 if (type == BT_COEX_ANT_TYPE_PG) {
1787 btcoexist->board_info.pg_ant_num = ant_num;
1788 btcoexist->board_info.btdm_ant_num = ant_num;
1789 } else if (type == BT_COEX_ANT_TYPE_ANTDIV) {
1790 btcoexist->board_info.btdm_ant_num = ant_num;
1791 } else if (type == BT_COEX_ANT_TYPE_DETECTED) {
1792 btcoexist->board_info.btdm_ant_num = ant_num;
1793 if (rtlpriv->cfg->mod_params->ant_sel == 1)
1794 btcoexist->board_info.btdm_ant_pos =
1795 BTC_ANTENNA_AT_AUX_PORT;
1797 btcoexist->board_info.btdm_ant_pos =
1798 BTC_ANTENNA_AT_MAIN_PORT;
1802 /* Currently used by 8723b only, S0 or S1 */
1803 void exhalbtc_set_single_ant_path(struct btc_coexist *btcoexist,
1806 btcoexist->board_info.single_ant_path = single_ant_path;
1809 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist,
1812 if (!halbtc_is_bt_coexist_available(btcoexist))
1815 halbtc_leave_low_power(btcoexist);
1817 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1818 if (btcoexist->board_info.btdm_ant_num == 1)
1819 ex_btc8822b1ant_display_coex_info(btcoexist, m);
1820 else if (btcoexist->board_info.btdm_ant_num == 2)
1821 ex_btc8822b2ant_display_coex_info(btcoexist, m);
1824 halbtc_normal_low_power(btcoexist);
1827 void exhalbtc_switch_band_notify(struct btc_coexist *btcoexist, u8 type)
1829 if (!halbtc_is_bt_coexist_available(btcoexist))
1832 if (btcoexist->manual_control)
1835 halbtc_leave_low_power(btcoexist);
1837 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1838 if (btcoexist->board_info.btdm_ant_num == 1)
1839 ex_btc8822b1ant_switchband_notify(btcoexist, type);
1840 else if (btcoexist->board_info.btdm_ant_num == 2)
1841 ex_btc8822b2ant_switchband_notify(btcoexist, type);
1844 halbtc_normal_low_power(btcoexist);
1847 void exhalbtc_switch_band_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1850 if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1851 ex_hal8822b_wifi_only_switchbandnotify(wifionly_cfg, is_5g);