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 bool ap_enable = false;
286 rtlpriv = btcoexist->adapter;
288 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
292 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
293 "%s()<--dont leave lps under AP mode\n", __func__);
297 btcoexist->bt_info.bt_ctrl_lps = true;
298 btcoexist->bt_info.bt_lps_on = false;
299 rtl_lps_leave(rtlpriv->mac80211.hw);
302 static void halbtc_enter_lps(struct btc_coexist *btcoexist)
304 struct rtl_priv *rtlpriv;
305 bool ap_enable = false;
307 rtlpriv = btcoexist->adapter;
309 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
313 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
314 "%s()<--dont enter lps under AP mode\n", __func__);
318 btcoexist->bt_info.bt_ctrl_lps = true;
319 btcoexist->bt_info.bt_lps_on = true;
320 rtl_lps_enter(rtlpriv->mac80211.hw);
323 static void halbtc_normal_lps(struct btc_coexist *btcoexist)
325 struct rtl_priv *rtlpriv;
327 rtlpriv = btcoexist->adapter;
329 if (btcoexist->bt_info.bt_ctrl_lps) {
330 btcoexist->bt_info.bt_lps_on = false;
331 rtl_lps_leave(rtlpriv->mac80211.hw);
332 btcoexist->bt_info.bt_ctrl_lps = false;
336 static void halbtc_leave_low_power(struct btc_coexist *btcoexist)
340 static void halbtc_normal_low_power(struct btc_coexist *btcoexist)
344 static void halbtc_disable_low_power(struct btc_coexist *btcoexist,
345 bool low_pwr_disable)
347 /* TODO: original/leave 32k low power */
348 btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable;
351 static void halbtc_aggregation_check(struct btc_coexist *btcoexist)
353 bool need_to_act = false;
354 static unsigned long pre_time;
355 unsigned long cur_time = 0;
356 struct rtl_priv *rtlpriv = btcoexist->adapter;
358 /* To void continuous deleteBA=>addBA=>deleteBA=>addBA
359 * This function is not allowed to continuous called
360 * It can only be called after 8 seconds
364 if (jiffies_to_msecs(cur_time - pre_time) <= 8000) {
365 /* over 8 seconds you can execute this function again. */
370 if (btcoexist->bt_info.reject_agg_pkt) {
372 btcoexist->bt_info.pre_reject_agg_pkt =
373 btcoexist->bt_info.reject_agg_pkt;
375 if (btcoexist->bt_info.pre_reject_agg_pkt) {
377 btcoexist->bt_info.pre_reject_agg_pkt =
378 btcoexist->bt_info.reject_agg_pkt;
381 if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
382 btcoexist->bt_info.bt_ctrl_agg_buf_size) {
384 btcoexist->bt_info.pre_bt_ctrl_agg_buf_size =
385 btcoexist->bt_info.bt_ctrl_agg_buf_size;
388 if (btcoexist->bt_info.bt_ctrl_agg_buf_size) {
389 if (btcoexist->bt_info.pre_agg_buf_size !=
390 btcoexist->bt_info.agg_buf_size) {
393 btcoexist->bt_info.pre_agg_buf_size =
394 btcoexist->bt_info.agg_buf_size;
398 rtl_rx_ampdu_apply(rtlpriv);
402 static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
404 u8 cmd_buffer[4] = {0};
406 if (btcoexist->bt_info.bt_real_fw_ver)
409 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
410 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_VERSION,
414 return btcoexist->bt_info.bt_real_fw_ver;
417 static u32 halbtc_get_bt_coex_supported_feature(void *btc_context)
419 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
420 u8 cmd_buffer[4] = {0};
422 if (btcoexist->bt_info.bt_supported_feature)
425 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
426 halbtc_send_bt_mp_operation(btcoexist,
427 BT_OP_GET_BT_COEX_SUPPORTED_FEATURE,
431 return btcoexist->bt_info.bt_supported_feature;
434 static u32 halbtc_get_bt_coex_supported_version(void *btc_context)
436 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
437 u8 cmd_buffer[4] = {0};
439 if (btcoexist->bt_info.bt_supported_version)
442 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
443 halbtc_send_bt_mp_operation(btcoexist,
444 BT_OP_GET_BT_COEX_SUPPORTED_VERSION,
448 return btcoexist->bt_info.bt_supported_version;
451 static u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist)
454 * [31:16] => connected port number
455 * [15:0] => port connected bit define
457 struct rtl_priv *rtlpriv = btcoexist->adapter;
458 struct rtl_mac *mac = rtl_mac(rtlpriv);
460 u32 port_connected_status = 0, num_of_connected_port = 0;
462 if (mac->opmode == NL80211_IFTYPE_STATION &&
463 mac->link_state >= MAC80211_LINKED) {
464 port_connected_status |= WIFI_STA_CONNECTED;
465 num_of_connected_port++;
467 /* AP & ADHOC & MESH */
468 if (is_any_client_connect_to_ap(btcoexist)) {
469 port_connected_status |= WIFI_AP_CONNECTED;
470 num_of_connected_port++;
472 /* TODO: P2P Connected Status */
474 ret_val = (num_of_connected_port << 16) | port_connected_status;
479 static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv)
481 int undec_sm_pwdb = 0;
483 if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
484 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
485 else /* associated entry pwdb */
486 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
487 return undec_sm_pwdb;
490 static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
492 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
493 struct rtl_priv *rtlpriv = btcoexist->adapter;
494 struct rtl_phy *rtlphy = &rtlpriv->phy;
495 struct rtl_mac *mac = rtl_mac(rtlpriv);
496 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
497 bool *bool_tmp = (bool *)out_buf;
498 int *s32_tmp = (int *)out_buf;
499 u32 *u32_tmp = (u32 *)out_buf;
500 u8 *u8_tmp = (u8 *)out_buf;
504 if (!halbtc_is_bt_coexist_available(btcoexist))
508 case BTC_GET_BL_HS_OPERATION:
512 case BTC_GET_BL_HS_CONNECTING:
516 case BTC_GET_BL_WIFI_CONNECTED:
517 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
518 rtlpriv->mac80211.link_state >= MAC80211_LINKED)
520 if (is_any_client_connect_to_ap(btcoexist))
524 case BTC_GET_BL_WIFI_BUSY:
525 if (halbtc_is_wifi_busy(rtlpriv))
530 case BTC_GET_BL_WIFI_SCAN:
531 if (mac->act_scanning)
536 case BTC_GET_BL_WIFI_LINK:
537 if (mac->link_state == MAC80211_LINKING)
542 case BTC_GET_BL_WIFI_ROAM:
543 if (mac->link_state == MAC80211_LINKING)
548 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
549 *bool_tmp = rtlpriv->btcoexist.btc_info.in_4way;
551 case BTC_GET_BL_WIFI_UNDER_5G:
552 if (rtlhal->current_bandtype == BAND_ON_5G)
557 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
558 if (mac->opmode == NL80211_IFTYPE_AP)
563 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
564 if (rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION)
569 case BTC_GET_BL_WIFI_UNDER_B_MODE:
570 if (rtlpriv->mac80211.mode == WIRELESS_MODE_B)
575 case BTC_GET_BL_EXT_SWITCH:
578 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
581 case BTC_GET_BL_IS_ASUS_8723B:
584 case BTC_GET_BL_RF4CE_CONNECTED:
587 case BTC_GET_S4_WIFI_RSSI:
588 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
590 case BTC_GET_S4_HS_RSSI:
594 case BTC_GET_U4_WIFI_BW:
595 *u32_tmp = halbtc_get_wifi_bw(btcoexist);
597 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
598 if (halbtc_is_wifi_uplink(rtlpriv))
599 *u32_tmp = BTC_WIFI_TRAFFIC_TX;
601 *u32_tmp = BTC_WIFI_TRAFFIC_RX;
603 case BTC_GET_U4_WIFI_FW_VER:
604 *u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion;
606 case BTC_GET_U4_WIFI_LINK_STATUS:
607 *u32_tmp = halbtc_get_wifi_link_status(btcoexist);
609 case BTC_GET_U4_BT_PATCH_VER:
610 *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
612 case BTC_GET_U4_VENDOR:
613 *u32_tmp = BTC_VENDOR_OTHER;
615 case BTC_GET_U4_SUPPORTED_VERSION:
616 *u32_tmp = halbtc_get_bt_coex_supported_version(btcoexist);
618 case BTC_GET_U4_SUPPORTED_FEATURE:
619 *u32_tmp = halbtc_get_bt_coex_supported_feature(btcoexist);
621 case BTC_GET_U4_WIFI_IQK_TOTAL:
622 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
625 case BTC_GET_U4_WIFI_IQK_OK:
626 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
629 case BTC_GET_U4_WIFI_IQK_FAIL:
630 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
633 case BTC_GET_U1_WIFI_DOT11_CHNL:
634 *u8_tmp = rtlphy->current_channel;
636 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
637 *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
639 case BTC_GET_U1_WIFI_HS_CHNL:
643 case BTC_GET_U1_AP_NUM:
644 *u8_tmp = rtlpriv->btcoexist.btc_info.ap_num;
646 case BTC_GET_U1_ANT_TYPE:
647 *u8_tmp = (u8)BTC_ANT_TYPE_0;
649 case BTC_GET_U1_IOT_PEER:
653 /************* 1Ant **************/
654 case BTC_GET_U1_LPS_MODE:
655 *u8_tmp = btcoexist->pwr_mode_val[0];
666 static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
668 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
669 bool *bool_tmp = (bool *)in_buf;
670 u8 *u8_tmp = (u8 *)in_buf;
671 u32 *u32_tmp = (u32 *)in_buf;
674 if (!halbtc_is_bt_coexist_available(btcoexist))
678 /* set some bool type variables. */
679 case BTC_SET_BL_BT_DISABLE:
680 btcoexist->bt_info.bt_disabled = *bool_tmp;
682 case BTC_SET_BL_BT_TRAFFIC_BUSY:
683 btcoexist->bt_info.bt_busy = *bool_tmp;
685 case BTC_SET_BL_BT_LIMITED_DIG:
686 btcoexist->bt_info.limited_dig = *bool_tmp;
688 case BTC_SET_BL_FORCE_TO_ROAM:
689 btcoexist->bt_info.force_to_roam = *bool_tmp;
691 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
692 btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
694 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
695 btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp;
697 case BTC_SET_BL_INC_SCAN_DEV_NUM:
698 btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
700 case BTC_SET_BL_BT_TX_RX_MASK:
701 btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp;
703 case BTC_SET_BL_MIRACAST_PLUS_BT:
704 btcoexist->bt_info.miracast_plus_bt = *bool_tmp;
706 /* set some u1Byte type variables. */
707 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
708 btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
710 case BTC_SET_U1_AGG_BUF_SIZE:
711 btcoexist->bt_info.agg_buf_size = *u8_tmp;
714 /* the following are some action which will be triggered */
715 case BTC_SET_ACT_GET_BT_RSSI:
718 case BTC_SET_ACT_AGGREGATE_CTRL:
719 halbtc_aggregation_check(btcoexist);
723 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
724 btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
726 case BTC_SET_UI_SCAN_SIG_COMPENSATION:
728 case BTC_SET_U1_LPS_VAL:
729 btcoexist->bt_info.lps_val = *u8_tmp;
731 case BTC_SET_U1_RPWM_VAL:
732 btcoexist->bt_info.rpwm_val = *u8_tmp;
734 /* the following are some action which will be triggered */
735 case BTC_SET_ACT_LEAVE_LPS:
736 halbtc_leave_lps(btcoexist);
738 case BTC_SET_ACT_ENTER_LPS:
739 halbtc_enter_lps(btcoexist);
741 case BTC_SET_ACT_NORMAL_LPS:
742 halbtc_normal_lps(btcoexist);
744 case BTC_SET_ACT_DISABLE_LOW_POWER:
745 halbtc_disable_low_power(btcoexist, *bool_tmp);
747 case BTC_SET_ACT_UPDATE_RAMASK:
748 btcoexist->bt_info.ra_mask = *u32_tmp;
750 case BTC_SET_ACT_SEND_MIMO_PS:
752 case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
754 case BTC_SET_ACT_CTRL_BT_COEX:
756 case BTC_SET_ACT_CTRL_8723B_ANT:
765 static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist,
770 static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist,
775 static void halbtc_display_wifi_status(struct btc_coexist *btcoexist,
778 struct rtl_priv *rtlpriv = btcoexist->adapter;
779 s32 wifi_rssi = 0, bt_hs_rssi = 0;
780 bool scan = false, link = false, roam = false, wifi_busy = false;
781 bool wifi_under_b_mode = false, wifi_under_5g = false;
782 u32 wifi_bw = BTC_WIFI_BW_HT20;
783 u32 wifi_traffic_dir = BTC_WIFI_TRAFFIC_TX;
784 u32 wifi_freq = BTC_FREQ_2_4G;
785 u32 wifi_link_status = 0x0;
786 bool bt_hs_on = false, under_ips = false, under_lps = false;
787 bool low_power = false, dc_mode = false;
788 u8 wifi_chnl = 0, wifi_hs_chnl = 0;
791 wifi_link_status = halbtc_get_wifi_link_status(btcoexist);
792 seq_printf(m, "\n %-35s = %d/ %d/ %d/ %d/ %d",
793 "STA/vWifi/HS/p2pGo/p2pGc",
794 ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0),
795 ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0),
796 ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0),
797 ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
798 ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
800 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
801 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_chnl);
802 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
803 seq_printf(m, "\n %-35s = %d / %d(%d)",
804 "Dot11 channel / HsChnl(High Speed)",
805 wifi_chnl, wifi_hs_chnl, bt_hs_on);
807 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
808 btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
809 seq_printf(m, "\n %-35s = %d/ %d",
810 "Wifi rssi/ HS rssi",
811 wifi_rssi - 100, bt_hs_rssi - 100);
813 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
814 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
815 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
816 seq_printf(m, "\n %-35s = %d/ %d/ %d ",
817 "Wifi link/ roam/ scan",
820 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
821 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
822 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
823 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
825 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
826 wifi_freq = (wifi_under_5g ? BTC_FREQ_5G : BTC_FREQ_2_4G);
827 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
830 seq_printf(m, "\n %-35s = %s / %s/ %s/ AP=%d ",
831 "Wifi freq/ bw/ traffic",
832 gl_btc_wifi_freq_string[wifi_freq],
833 ((wifi_under_b_mode) ? "11b" :
834 gl_btc_wifi_bw_string[wifi_bw]),
835 ((!wifi_busy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX ==
836 wifi_traffic_dir) ? "uplink" :
841 dc_mode = true; /*TODO*/
842 under_ips = rtlpriv->psc.inactive_pwrstate == ERFOFF ? 1 : 0;
843 under_lps = rtlpriv->psc.dot11_psmode == EACTIVE ? 0 : 1;
844 low_power = 0; /*TODO*/
845 seq_printf(m, "\n %-35s = %s%s%s%s",
847 (dc_mode ? "DC mode" : "AC mode"),
848 (under_ips ? ", IPS ON" : ""),
849 (under_lps ? ", LPS ON" : ""),
850 (low_power ? ", 32k" : ""));
853 "\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)",
854 "Power mode cmd(lps/rpwm)",
855 btcoexist->pwr_mode_val[0], btcoexist->pwr_mode_val[1],
856 btcoexist->pwr_mode_val[2], btcoexist->pwr_mode_val[3],
857 btcoexist->pwr_mode_val[4], btcoexist->pwr_mode_val[5],
858 btcoexist->bt_info.lps_val,
859 btcoexist->bt_info.rpwm_val);
862 /************************************************************
863 * IO related function
864 ************************************************************/
865 static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
867 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
868 struct rtl_priv *rtlpriv = btcoexist->adapter;
870 return rtl_read_byte(rtlpriv, reg_addr);
873 static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
875 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
876 struct rtl_priv *rtlpriv = btcoexist->adapter;
878 return rtl_read_word(rtlpriv, reg_addr);
881 static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
883 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
884 struct rtl_priv *rtlpriv = btcoexist->adapter;
886 return rtl_read_dword(rtlpriv, reg_addr);
889 static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data)
891 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
892 struct rtl_priv *rtlpriv = btcoexist->adapter;
894 rtl_write_byte(rtlpriv, reg_addr, data);
897 static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
898 u32 bit_mask, u8 data)
900 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
901 struct rtl_priv *rtlpriv = btcoexist->adapter;
902 u8 original_value, bit_shift = 0;
905 if (bit_mask != MASKDWORD) {/*if not "double word" write*/
906 original_value = rtl_read_byte(rtlpriv, reg_addr);
907 for (i = 0; i <= 7; i++) {
908 if ((bit_mask >> i) & 0x1)
912 data = (original_value & (~bit_mask)) |
913 ((data << bit_shift) & bit_mask);
915 rtl_write_byte(rtlpriv, reg_addr, data);
918 static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
920 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
921 struct rtl_priv *rtlpriv = btcoexist->adapter;
923 rtl_write_word(rtlpriv, reg_addr, data);
926 static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
928 struct btc_coexist *btcoexist =
929 (struct btc_coexist *)bt_context;
930 struct rtl_priv *rtlpriv = btcoexist->adapter;
932 rtl_write_dword(rtlpriv, reg_addr, data);
935 static void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr,
938 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
939 struct rtl_priv *rtlpriv = btcoexist->adapter;
941 if (btcoexist->chip_interface == BTC_INTF_SDIO)
943 else if (btcoexist->chip_interface == BTC_INTF_PCI)
944 rtl_write_byte(rtlpriv, reg_addr, data);
945 else if (btcoexist->chip_interface == BTC_INTF_USB)
946 rtl_write_byte(rtlpriv, reg_addr, data);
949 static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
952 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
953 struct rtl_priv *rtlpriv = btcoexist->adapter;
955 rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
958 static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
960 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
961 struct rtl_priv *rtlpriv = btcoexist->adapter;
963 return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
966 static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
967 u32 bit_mask, u32 data)
969 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
970 struct rtl_priv *rtlpriv = btcoexist->adapter;
972 rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
975 static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
978 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
979 struct rtl_priv *rtlpriv = btcoexist->adapter;
981 return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
984 static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
985 u32 cmd_len, u8 *cmd_buf)
987 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
988 struct rtl_priv *rtlpriv = btcoexist->adapter;
990 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
994 static void halbtc_send_wifi_port_id_cmd(void *bt_context)
996 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
997 struct rtl_priv *rtlpriv = btcoexist->adapter;
998 u8 cmd_buf[1] = {0}; /* port id [2:0] = 0 */
1000 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x71, 1,
1004 static void halbtc_set_default_port_id_cmd(void *bt_context)
1006 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1007 struct rtl_priv *rtlpriv = btcoexist->adapter;
1008 struct ieee80211_hw *hw = rtlpriv->mac80211.hw;
1010 if (!rtlpriv->cfg->ops->set_default_port_id_cmd)
1013 rtlpriv->cfg->ops->set_default_port_id_cmd(hw);
1017 void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val)
1019 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1020 u8 cmd_buffer1[4] = {0};
1021 u8 cmd_buffer2[4] = {0};
1023 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1024 *((__le16 *)&cmd_buffer1[2]) = cpu_to_le16((u16)set_val);
1025 if (!halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_VALUE,
1026 cmd_buffer1, 4, 200))
1029 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1030 cmd_buffer2[2] = reg_type;
1031 *((u8 *)&cmd_buffer2[3]) = (u8)offset;
1032 halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_ADDR,
1033 cmd_buffer2, 4, 200);
1036 static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type,
1039 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1041 switch (disp_type) {
1042 case BTC_DBG_DISP_COEX_STATISTICS:
1043 halbtc_display_coex_statistics(btcoexist, m);
1045 case BTC_DBG_DISP_BT_LINK_INFO:
1046 halbtc_display_bt_link_info(btcoexist, m);
1048 case BTC_DBG_DISP_WIFI_STATUS:
1049 halbtc_display_wifi_status(btcoexist, m);
1056 static u32 halbtc_get_bt_reg(void *btc_context, u8 reg_type, u32 offset)
1062 u32 halbtc_get_phydm_version(void *btc_context)
1064 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1065 struct rtl_priv *rtlpriv = btcoexist->adapter;
1067 if (rtlpriv->phydm.ops)
1068 return rtlpriv->phydm.ops->phydm_get_version(rtlpriv);
1074 void halbtc_phydm_modify_ra_pcr_threshold(void *btc_context,
1075 u8 ra_offset_direction,
1076 u8 ra_threshold_offset)
1078 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1079 struct rtl_priv *rtlpriv = btcoexist->adapter;
1080 struct rtl_phydm_ops *phydm_ops = rtlpriv->phydm.ops;
1083 phydm_ops->phydm_modify_ra_pcr_threshold(rtlpriv,
1084 ra_offset_direction,
1085 ra_threshold_offset);
1089 u32 halbtc_phydm_query_phy_counter(void *btc_context, const char *info_type)
1091 /* info_type may be strings below:
1092 * PHYDM_INFO_FA_OFDM, PHYDM_INFO_FA_CCK, PHYDM_INFO_CCA_OFDM,
1093 * PHYDM_INFO_CCA_CCK
1094 * IQK_TOTAL, IQK_OK, IQK_FAIL
1097 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1098 struct rtl_priv *rtlpriv = btcoexist->adapter;
1099 struct rtl_phydm_ops *phydm_ops = rtlpriv->phydm.ops;
1102 return phydm_ops->phydm_query_counter(rtlpriv, info_type);
1107 static u8 halbtc_get_ant_det_val_from_bt(void *btc_context)
1109 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1110 u8 cmd_buffer[4] = {0};
1112 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1113 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_ANT_DET_VAL,
1114 cmd_buffer, 4, 200);
1116 /* need wait completion to return correct value */
1118 return btcoexist->bt_info.bt_ant_det_val;
1121 static u8 halbtc_get_ble_scan_type_from_bt(void *btc_context)
1123 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1124 u8 cmd_buffer[4] = {0};
1126 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1127 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_TYPE,
1128 cmd_buffer, 4, 200);
1130 /* need wait completion to return correct value */
1132 return btcoexist->bt_info.bt_ble_scan_type;
1135 static u32 halbtc_get_ble_scan_para_from_bt(void *btc_context, u8 scan_type)
1137 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1138 u8 cmd_buffer[4] = {0};
1140 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1141 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_PARA,
1142 cmd_buffer, 4, 200);
1144 /* need wait completion to return correct value */
1146 return btcoexist->bt_info.bt_ble_scan_para;
1149 static bool halbtc_get_bt_afh_map_from_bt(void *btc_context, u8 map_type,
1152 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1153 u8 cmd_buffer[2] = {0};
1155 u32 *afh_map_l = (u32 *)afh_map;
1156 u32 *afh_map_m = (u32 *)(afh_map + 4);
1157 u16 *afh_map_h = (u16 *)(afh_map + 8);
1159 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1160 ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_L,
1161 cmd_buffer, 2, 200);
1165 *afh_map_l = btcoexist->bt_info.afh_map_l;
1167 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1168 ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_M,
1169 cmd_buffer, 2, 200);
1173 *afh_map_m = btcoexist->bt_info.afh_map_m;
1175 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1176 ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_H,
1177 cmd_buffer, 2, 200);
1181 *afh_map_h = btcoexist->bt_info.afh_map_h;
1187 /*****************************************************************
1188 * Extern functions called by other module
1189 *****************************************************************/
1190 bool exhalbtc_initlize_variables(struct rtl_priv *rtlpriv)
1192 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1199 btcoexist->btc_read_1byte = halbtc_read_1byte;
1200 btcoexist->btc_write_1byte = halbtc_write_1byte;
1201 btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
1202 btcoexist->btc_read_2byte = halbtc_read_2byte;
1203 btcoexist->btc_write_2byte = halbtc_write_2byte;
1204 btcoexist->btc_read_4byte = halbtc_read_4byte;
1205 btcoexist->btc_write_4byte = halbtc_write_4byte;
1206 btcoexist->btc_write_local_reg_1byte = halbtc_write_local_reg_1byte;
1208 btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
1209 btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
1211 btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
1212 btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
1214 btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
1215 btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
1217 btcoexist->btc_get = halbtc_get;
1218 btcoexist->btc_set = halbtc_set;
1219 btcoexist->btc_set_bt_reg = halbtc_set_bt_reg;
1220 btcoexist->btc_get_bt_reg = halbtc_get_bt_reg;
1222 btcoexist->bt_info.bt_ctrl_buf_size = false;
1223 btcoexist->bt_info.agg_buf_size = 5;
1225 btcoexist->bt_info.increase_scan_dev_num = false;
1227 btcoexist->btc_get_bt_coex_supported_feature =
1228 halbtc_get_bt_coex_supported_feature;
1229 btcoexist->btc_get_bt_coex_supported_version =
1230 halbtc_get_bt_coex_supported_version;
1231 btcoexist->btc_get_bt_phydm_version = halbtc_get_phydm_version;
1232 btcoexist->btc_phydm_modify_ra_pcr_threshold =
1233 halbtc_phydm_modify_ra_pcr_threshold;
1234 btcoexist->btc_phydm_query_phy_counter = halbtc_phydm_query_phy_counter;
1235 btcoexist->btc_get_ant_det_val_from_bt = halbtc_get_ant_det_val_from_bt;
1236 btcoexist->btc_get_ble_scan_type_from_bt =
1237 halbtc_get_ble_scan_type_from_bt;
1238 btcoexist->btc_get_ble_scan_para_from_bt =
1239 halbtc_get_ble_scan_para_from_bt;
1240 btcoexist->btc_get_bt_afh_map_from_bt =
1241 halbtc_get_bt_afh_map_from_bt;
1243 init_completion(&btcoexist->bt_mp_comp);
1248 bool exhalbtc_initlize_variables_wifi_only(struct rtl_priv *rtlpriv)
1250 struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
1251 struct wifi_only_haldata *wifionly_haldata;
1256 wifionly_cfg->adapter = rtlpriv;
1258 switch (rtlpriv->rtlhal.interface) {
1260 wifionly_cfg->chip_interface = WIFIONLY_INTF_PCI;
1263 wifionly_cfg->chip_interface = WIFIONLY_INTF_USB;
1266 wifionly_cfg->chip_interface = WIFIONLY_INTF_UNKNOWN;
1270 wifionly_haldata = &wifionly_cfg->haldata_info;
1272 wifionly_haldata->customer_id = CUSTOMER_NORMAL;
1273 wifionly_haldata->efuse_pg_antnum = rtl_get_hwpg_ant_num(rtlpriv);
1274 wifionly_haldata->efuse_pg_antpath =
1275 rtl_get_hwpg_single_ant_path(rtlpriv);
1276 wifionly_haldata->rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1277 wifionly_haldata->ant_div_cfg = 0;
1282 bool exhalbtc_bind_bt_coex_withadapter(void *adapter)
1284 struct rtl_priv *rtlpriv = adapter;
1285 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1286 u8 ant_num = 2, chip_type, single_ant_path = 0;
1291 if (btcoexist->binded)
1294 switch (rtlpriv->rtlhal.interface) {
1296 btcoexist->chip_interface = BTC_INTF_PCI;
1299 btcoexist->chip_interface = BTC_INTF_USB;
1302 btcoexist->chip_interface = BTC_INTF_UNKNOWN;
1306 btcoexist->binded = true;
1307 btcoexist->statistics.cnt_bind++;
1309 btcoexist->adapter = adapter;
1311 btcoexist->stack_info.profile_notified = false;
1313 btcoexist->bt_info.bt_ctrl_agg_buf_size = false;
1314 btcoexist->bt_info.agg_buf_size = 5;
1316 btcoexist->bt_info.increase_scan_dev_num = false;
1317 btcoexist->bt_info.miracast_plus_bt = false;
1319 chip_type = rtl_get_hwpg_bt_type(rtlpriv);
1320 exhalbtc_set_chip_type(btcoexist, chip_type);
1321 ant_num = rtl_get_hwpg_ant_num(rtlpriv);
1322 exhalbtc_set_ant_num(rtlpriv, BT_COEX_ANT_TYPE_PG, ant_num);
1324 /* set default antenna position to main port */
1325 btcoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
1327 single_ant_path = rtl_get_hwpg_single_ant_path(rtlpriv);
1328 exhalbtc_set_single_ant_path(btcoexist, single_ant_path);
1330 if (rtl_get_hwpg_package_type(rtlpriv) == 0)
1331 btcoexist->board_info.tfbga_package = false;
1332 else if (rtl_get_hwpg_package_type(rtlpriv) == 1)
1333 btcoexist->board_info.tfbga_package = false;
1335 btcoexist->board_info.tfbga_package = true;
1337 if (btcoexist->board_info.tfbga_package)
1338 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1339 "[BTCoex], Package Type = TFBGA\n");
1341 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1342 "[BTCoex], Package Type = Non-TFBGA\n");
1344 btcoexist->board_info.rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1345 btcoexist->board_info.ant_div_cfg = 0;
1350 void exhalbtc_power_on_setting(struct btc_coexist *btcoexist)
1352 if (!halbtc_is_bt_coexist_available(btcoexist))
1355 btcoexist->statistics.cnt_power_on++;
1357 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1358 if (btcoexist->board_info.btdm_ant_num == 1)
1359 ex_btc8822b1ant_power_on_setting(btcoexist);
1360 else if (btcoexist->board_info.btdm_ant_num == 2)
1361 ex_btc8822b2ant_power_on_setting(btcoexist);
1365 void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist)
1367 if (!halbtc_is_bt_coexist_available(btcoexist))
1370 btcoexist->statistics.cnt_pre_load_firmware++;
1372 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1373 if (btcoexist->board_info.btdm_ant_num == 1)
1374 ex_btc8822b1ant_pre_load_firmware(btcoexist);
1375 else if (btcoexist->board_info.btdm_ant_num == 2)
1376 ex_btc8822b2ant_pre_load_firmware(btcoexist);
1380 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only)
1382 if (!halbtc_is_bt_coexist_available(btcoexist))
1385 btcoexist->statistics.cnt_init_hw_config++;
1387 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1388 if (btcoexist->board_info.btdm_ant_num == 1)
1389 ex_btc8822b1ant_init_hw_config(btcoexist, wifi_only);
1390 else if (btcoexist->board_info.btdm_ant_num == 2)
1391 ex_btc8822b2ant_init_hw_config(btcoexist, wifi_only);
1393 halbtc_set_default_port_id_cmd(btcoexist);
1394 halbtc_send_wifi_port_id_cmd(btcoexist);
1398 void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg)
1400 if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1401 ex_hal8822b_wifi_only_hw_config(wifionly_cfg);
1404 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
1406 if (!halbtc_is_bt_coexist_available(btcoexist))
1409 btcoexist->statistics.cnt_init_coex_dm++;
1411 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1412 if (btcoexist->board_info.btdm_ant_num == 1)
1413 ex_btc8822b1ant_init_coex_dm(btcoexist);
1414 else if (btcoexist->board_info.btdm_ant_num == 2)
1415 ex_btc8822b2ant_init_coex_dm(btcoexist);
1418 btcoexist->initilized = true;
1421 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
1425 if (!halbtc_is_bt_coexist_available(btcoexist))
1427 btcoexist->statistics.cnt_ips_notify++;
1428 if (btcoexist->manual_control)
1432 ips_type = BTC_IPS_ENTER;
1434 ips_type = BTC_IPS_LEAVE;
1436 halbtc_leave_low_power(btcoexist);
1438 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1439 if (btcoexist->board_info.btdm_ant_num == 1)
1440 ex_btc8822b1ant_ips_notify(btcoexist, ips_type);
1441 else if (btcoexist->board_info.btdm_ant_num == 2)
1442 ex_btc8822b2ant_ips_notify(btcoexist, ips_type);
1445 halbtc_normal_low_power(btcoexist);
1448 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
1452 if (!halbtc_is_bt_coexist_available(btcoexist))
1454 btcoexist->statistics.cnt_lps_notify++;
1455 if (btcoexist->manual_control)
1458 if (type == EACTIVE)
1459 lps_type = BTC_LPS_DISABLE;
1461 lps_type = BTC_LPS_ENABLE;
1463 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1464 if (btcoexist->board_info.btdm_ant_num == 1)
1465 ex_btc8822b1ant_lps_notify(btcoexist, lps_type);
1466 else if (btcoexist->board_info.btdm_ant_num == 2)
1467 ex_btc8822b2ant_lps_notify(btcoexist, lps_type);
1471 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
1475 if (!halbtc_is_bt_coexist_available(btcoexist))
1477 btcoexist->statistics.cnt_scan_notify++;
1478 if (btcoexist->manual_control)
1482 scan_type = BTC_SCAN_START;
1484 scan_type = BTC_SCAN_FINISH;
1486 halbtc_leave_low_power(btcoexist);
1488 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1489 if (btcoexist->board_info.btdm_ant_num == 1)
1490 ex_btc8822b1ant_scan_notify(btcoexist, scan_type);
1491 else if (btcoexist->board_info.btdm_ant_num == 2)
1492 ex_btc8822b2ant_scan_notify(btcoexist, scan_type);
1495 halbtc_normal_low_power(btcoexist);
1498 void exhalbtc_scan_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1501 if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1502 ex_hal8822b_wifi_only_scannotify(wifionly_cfg, is_5g);
1505 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
1509 if (!halbtc_is_bt_coexist_available(btcoexist))
1511 btcoexist->statistics.cnt_connect_notify++;
1512 if (btcoexist->manual_control)
1516 asso_type = BTC_ASSOCIATE_START;
1518 asso_type = BTC_ASSOCIATE_FINISH;
1520 halbtc_leave_low_power(btcoexist);
1522 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1523 if (btcoexist->board_info.btdm_ant_num == 1)
1524 ex_btc8822b1ant_connect_notify(btcoexist, asso_type);
1525 else if (btcoexist->board_info.btdm_ant_num == 2)
1526 ex_btc8822b2ant_connect_notify(btcoexist, asso_type);
1529 halbtc_normal_low_power(btcoexist);
1532 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
1533 enum rt_media_status media_status)
1537 if (!halbtc_is_bt_coexist_available(btcoexist))
1539 btcoexist->statistics.cnt_media_status_notify++;
1540 if (btcoexist->manual_control)
1543 if (media_status == RT_MEDIA_CONNECT)
1544 status = BTC_MEDIA_CONNECT;
1546 status = BTC_MEDIA_DISCONNECT;
1548 halbtc_leave_low_power(btcoexist);
1550 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1551 if (btcoexist->board_info.btdm_ant_num == 1)
1552 ex_btc8822b1ant_media_status_notify(btcoexist, status);
1553 else if (btcoexist->board_info.btdm_ant_num == 2)
1554 ex_btc8822b2ant_media_status_notify(btcoexist, status);
1557 halbtc_normal_low_power(btcoexist);
1560 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
1564 if (!halbtc_is_bt_coexist_available(btcoexist))
1566 btcoexist->statistics.cnt_special_packet_notify++;
1567 if (btcoexist->manual_control)
1570 if (pkt_type == PACKET_DHCP) {
1571 packet_type = BTC_PACKET_DHCP;
1572 } else if (pkt_type == PACKET_EAPOL) {
1573 packet_type = BTC_PACKET_EAPOL;
1574 } else if (pkt_type == PACKET_ARP) {
1575 packet_type = BTC_PACKET_ARP;
1577 packet_type = BTC_PACKET_UNKNOWN;
1581 halbtc_leave_low_power(btcoexist);
1583 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1584 if (btcoexist->board_info.btdm_ant_num == 1)
1585 ex_btc8822b1ant_specific_packet_notify(btcoexist,
1587 else if (btcoexist->board_info.btdm_ant_num == 2)
1588 ex_btc8822b2ant_specific_packet_notify(btcoexist,
1592 halbtc_normal_low_power(btcoexist);
1595 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
1596 u8 *tmp_buf, u8 length)
1598 if (!halbtc_is_bt_coexist_available(btcoexist))
1600 btcoexist->statistics.cnt_bt_info_notify++;
1602 halbtc_leave_low_power(btcoexist);
1604 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1605 if (btcoexist->board_info.btdm_ant_num == 1)
1606 ex_btc8822b1ant_bt_info_notify(btcoexist, tmp_buf,
1608 else if (btcoexist->board_info.btdm_ant_num == 2)
1609 ex_btc8822b2ant_bt_info_notify(btcoexist, tmp_buf,
1613 halbtc_normal_low_power(btcoexist);
1616 void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
1618 if (!halbtc_is_bt_coexist_available(btcoexist))
1621 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1622 if (btcoexist->board_info.btdm_ant_num == 1)
1623 ex_btc8822b1ant_rf_status_notify(btcoexist, type);
1624 else if (btcoexist->board_info.btdm_ant_num == 2)
1625 ex_btc8822b2ant_rf_status_notify(btcoexist, type);
1629 void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
1631 if (!halbtc_is_bt_coexist_available(btcoexist))
1633 btcoexist->statistics.cnt_stack_operation_notify++;
1636 void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
1638 if (!halbtc_is_bt_coexist_available(btcoexist))
1641 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1642 if (btcoexist->board_info.btdm_ant_num == 1)
1643 ex_btc8822b1ant_halt_notify(btcoexist);
1644 else if (btcoexist->board_info.btdm_ant_num == 2)
1645 ex_btc8822b2ant_halt_notify(btcoexist);
1648 btcoexist->binded = false;
1651 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
1653 if (!halbtc_is_bt_coexist_available(btcoexist))
1656 /* currently only 1ant we have to do the notification,
1657 * once pnp is notified to sleep state, we have to leave LPS that
1658 * we can sleep normally.
1661 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1662 if (btcoexist->board_info.btdm_ant_num == 1)
1663 ex_btc8822b1ant_pnp_notify(btcoexist, pnp_state);
1664 else if (btcoexist->board_info.btdm_ant_num == 2)
1665 ex_btc8822b2ant_pnp_notify(btcoexist, pnp_state);
1669 void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist)
1671 if (!halbtc_is_bt_coexist_available(btcoexist))
1673 btcoexist->statistics.cnt_coex_dm_switch++;
1675 halbtc_leave_low_power(btcoexist);
1677 halbtc_normal_low_power(btcoexist);
1680 void exhalbtc_periodical(struct btc_coexist *btcoexist)
1682 if (!halbtc_is_bt_coexist_available(btcoexist))
1684 btcoexist->statistics.cnt_periodical++;
1686 halbtc_leave_low_power(btcoexist);
1688 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1689 if (btcoexist->board_info.btdm_ant_num == 1)
1690 ex_btc8822b1ant_periodical(btcoexist);
1691 else if (btcoexist->board_info.btdm_ant_num == 2)
1692 ex_btc8822b2ant_periodical(btcoexist);
1695 halbtc_normal_low_power(btcoexist);
1698 void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
1699 u8 code, u8 len, u8 *data)
1701 if (!halbtc_is_bt_coexist_available(btcoexist))
1703 btcoexist->statistics.cnt_dbg_ctrl++;
1705 halbtc_leave_low_power(btcoexist);
1707 halbtc_normal_low_power(btcoexist);
1710 void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq,
1711 u32 offset, u32 span, u32 seconds)
1713 if (!halbtc_is_bt_coexist_available(btcoexist))
1717 void exhalbtc_stack_update_profile_info(void)
1721 void exhalbtc_update_min_bt_rssi(struct btc_coexist *btcoexist, s8 bt_rssi)
1723 if (!halbtc_is_bt_coexist_available(btcoexist))
1726 btcoexist->stack_info.min_bt_rssi = bt_rssi;
1729 void exhalbtc_set_hci_version(struct btc_coexist *btcoexist, u16 hci_version)
1731 if (!halbtc_is_bt_coexist_available(btcoexist))
1734 btcoexist->stack_info.hci_version = hci_version;
1737 void exhalbtc_set_bt_patch_version(struct btc_coexist *btcoexist,
1738 u16 bt_hci_version, u16 bt_patch_version)
1740 if (!halbtc_is_bt_coexist_available(btcoexist))
1743 btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
1744 btcoexist->bt_info.bt_hci_ver = bt_hci_version;
1747 void exhalbtc_set_chip_type(struct btc_coexist *btcoexist, u8 chip_type)
1749 switch (chip_type) {
1755 btcoexist->board_info.bt_chip_type = BTC_CHIP_UNDEF;
1758 btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
1761 btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
1764 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723A;
1767 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8821;
1770 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723B;
1775 void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num)
1777 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1782 if (type == BT_COEX_ANT_TYPE_PG) {
1783 btcoexist->board_info.pg_ant_num = ant_num;
1784 btcoexist->board_info.btdm_ant_num = ant_num;
1785 } else if (type == BT_COEX_ANT_TYPE_ANTDIV) {
1786 btcoexist->board_info.btdm_ant_num = ant_num;
1787 } else if (type == BT_COEX_ANT_TYPE_DETECTED) {
1788 btcoexist->board_info.btdm_ant_num = ant_num;
1789 if (rtlpriv->cfg->mod_params->ant_sel == 1)
1790 btcoexist->board_info.btdm_ant_pos =
1791 BTC_ANTENNA_AT_AUX_PORT;
1793 btcoexist->board_info.btdm_ant_pos =
1794 BTC_ANTENNA_AT_MAIN_PORT;
1798 /* Currently used by 8723b only, S0 or S1 */
1799 void exhalbtc_set_single_ant_path(struct btc_coexist *btcoexist,
1802 btcoexist->board_info.single_ant_path = single_ant_path;
1805 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist,
1808 if (!halbtc_is_bt_coexist_available(btcoexist))
1811 halbtc_leave_low_power(btcoexist);
1813 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1814 if (btcoexist->board_info.btdm_ant_num == 1)
1815 ex_btc8822b1ant_display_coex_info(btcoexist, m);
1816 else if (btcoexist->board_info.btdm_ant_num == 2)
1817 ex_btc8822b2ant_display_coex_info(btcoexist, m);
1820 halbtc_normal_low_power(btcoexist);
1823 void exhalbtc_switch_band_notify(struct btc_coexist *btcoexist, u8 type)
1825 if (!halbtc_is_bt_coexist_available(btcoexist))
1828 if (btcoexist->manual_control)
1831 halbtc_leave_low_power(btcoexist);
1833 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1834 if (btcoexist->board_info.btdm_ant_num == 1)
1835 ex_btc8822b1ant_switchband_notify(btcoexist, type);
1836 else if (btcoexist->board_info.btdm_ant_num == 2)
1837 ex_btc8822b2ant_switchband_notify(btcoexist, type);
1840 halbtc_normal_low_power(btcoexist);
1843 void exhalbtc_switch_band_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1846 if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1847 ex_hal8822b_wifi_only_switchbandnotify(wifionly_cfg, is_5g);