Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright(c) 2007-2013  Realtek Corporation.*/
0003 
0004 #include "halbt_precomp.h"
0005 
0006 /***************************************************
0007  *      Debug related function
0008  ***************************************************/
0009 
0010 static const char *const gl_btc_wifi_bw_string[] = {
0011     "11bg",
0012     "HT20",
0013     "HT40",
0014     "HT80",
0015     "HT160"
0016 };
0017 
0018 static const char *const gl_btc_wifi_freq_string[] = {
0019     "2.4G",
0020     "5G"
0021 };
0022 
0023 static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
0024 {
0025     if (!btcoexist->binded || NULL == btcoexist->adapter)
0026         return false;
0027 
0028     return true;
0029 }
0030 
0031 static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
0032 {
0033     if (rtlpriv->link_info.busytraffic)
0034         return true;
0035     else
0036         return false;
0037 }
0038 
0039 static void halbtc_dbg_init(void)
0040 {
0041 }
0042 
0043 /***************************************************
0044  *      helper function
0045  ***************************************************/
0046 static bool is_any_client_connect_to_ap(struct btc_coexist *btcoexist)
0047 {
0048     struct rtl_priv *rtlpriv = btcoexist->adapter;
0049     struct rtl_mac *mac = rtl_mac(rtlpriv);
0050     bool ret = false;
0051 
0052     if (mac->opmode == NL80211_IFTYPE_ADHOC ||
0053         mac->opmode == NL80211_IFTYPE_MESH_POINT ||
0054         mac->opmode == NL80211_IFTYPE_AP) {
0055         spin_lock_bh(&rtlpriv->locks.entry_list_lock);
0056         if (!list_empty(&rtlpriv->entry_list))
0057             ret = true;
0058         spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
0059     }
0060     return ret;
0061 }
0062 
0063 static bool halbtc_legacy(struct rtl_priv *adapter)
0064 {
0065     struct rtl_priv *rtlpriv = adapter;
0066     struct rtl_mac *mac = rtl_mac(rtlpriv);
0067 
0068     bool is_legacy = false;
0069 
0070     if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G))
0071         is_legacy = true;
0072 
0073     return is_legacy;
0074 }
0075 
0076 bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
0077 {
0078     struct rtl_priv *rtlpriv = adapter;
0079 
0080     if (rtlpriv->link_info.tx_busy_traffic)
0081         return true;
0082     else
0083         return false;
0084 }
0085 
0086 static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
0087 {
0088     struct rtl_priv *rtlpriv = btcoexist->adapter;
0089     struct rtl_phy *rtlphy = &rtlpriv->phy;
0090     u32 wifi_bw = BTC_WIFI_BW_HT20;
0091 
0092     if (halbtc_legacy(rtlpriv)) {
0093         wifi_bw = BTC_WIFI_BW_LEGACY;
0094     } else {
0095         switch (rtlphy->current_chan_bw) {
0096         case HT_CHANNEL_WIDTH_20:
0097             wifi_bw = BTC_WIFI_BW_HT20;
0098             break;
0099         case HT_CHANNEL_WIDTH_20_40:
0100             wifi_bw = BTC_WIFI_BW_HT40;
0101             break;
0102         case HT_CHANNEL_WIDTH_80:
0103             wifi_bw = BTC_WIFI_BW_HT80;
0104             break;
0105         }
0106     }
0107 
0108     return wifi_bw;
0109 }
0110 
0111 static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
0112 {
0113     struct rtl_priv *rtlpriv = btcoexist->adapter;
0114     struct rtl_phy  *rtlphy = &(rtlpriv->phy);
0115     u8 chnl = 1;
0116 
0117     if (rtlphy->current_channel != 0)
0118         chnl = rtlphy->current_channel;
0119     rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
0120         "%s:%d\n", __func__, chnl);
0121     return chnl;
0122 }
0123 
0124 static u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv)
0125 {
0126     return rtlpriv->btcoexist.btc_info.single_ant_path;
0127 }
0128 
0129 static u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
0130 {
0131     return rtlpriv->btcoexist.btc_info.bt_type;
0132 }
0133 
0134 static u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
0135 {
0136     u8 num;
0137 
0138     if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
0139         num = 2;
0140     else
0141         num = 1;
0142 
0143     return num;
0144 }
0145 
0146 static u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv)
0147 {
0148     struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
0149 
0150     return rtlhal->package_type;
0151 }
0152 
0153 static
0154 u8 rtl_get_hwpg_rfe_type(struct rtl_priv *rtlpriv)
0155 {
0156     struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
0157 
0158     return rtlhal->rfe_type;
0159 }
0160 
0161 static
0162 bool halbtc_is_hw_mailbox_exist(struct btc_coexist *btcoexist)
0163 {
0164     if (IS_HARDWARE_TYPE_8812(btcoexist->adapter))
0165         return false;
0166     else
0167         return true;
0168 }
0169 
0170 static
0171 bool halbtc_send_bt_mp_operation(struct btc_coexist *btcoexist, u8 op_code,
0172                  u8 *cmd, u32 len, unsigned long wait_ms)
0173 {
0174     struct rtl_priv *rtlpriv;
0175     const u8 oper_ver = 0;
0176     u8 req_num;
0177 
0178     if (!halbtc_is_hw_mailbox_exist(btcoexist))
0179         return false;
0180 
0181     if (wait_ms)    /* before h2c to avoid race condition */
0182         reinit_completion(&btcoexist->bt_mp_comp);
0183 
0184     rtlpriv = btcoexist->adapter;
0185 
0186     /* fill req_num by op_code, and rtl_btc_btmpinfo_notify() use it
0187      * to know message type
0188      */
0189     switch (op_code) {
0190     case BT_OP_GET_BT_VERSION:
0191         req_num = BT_SEQ_GET_BT_VERSION;
0192         break;
0193     case BT_OP_GET_AFH_MAP_L:
0194         req_num = BT_SEQ_GET_AFH_MAP_L;
0195         break;
0196     case BT_OP_GET_AFH_MAP_M:
0197         req_num = BT_SEQ_GET_AFH_MAP_M;
0198         break;
0199     case BT_OP_GET_AFH_MAP_H:
0200         req_num = BT_SEQ_GET_AFH_MAP_H;
0201         break;
0202     case BT_OP_GET_BT_COEX_SUPPORTED_FEATURE:
0203         req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_FEATURE;
0204         break;
0205     case BT_OP_GET_BT_COEX_SUPPORTED_VERSION:
0206         req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_VERSION;
0207         break;
0208     case BT_OP_GET_BT_ANT_DET_VAL:
0209         req_num = BT_SEQ_GET_BT_ANT_DET_VAL;
0210         break;
0211     case BT_OP_GET_BT_BLE_SCAN_PARA:
0212         req_num = BT_SEQ_GET_BT_BLE_SCAN_PARA;
0213         break;
0214     case BT_OP_GET_BT_BLE_SCAN_TYPE:
0215         req_num = BT_SEQ_GET_BT_BLE_SCAN_TYPE;
0216         break;
0217     case BT_OP_GET_BT_DEVICE_INFO:
0218         req_num = BT_SEQ_GET_BT_DEVICE_INFO;
0219         break;
0220     case BT_OP_GET_BT_FORBIDDEN_SLOT_VAL:
0221         req_num = BT_SEQ_GET_BT_FORB_SLOT_VAL;
0222         break;
0223     case BT_OP_WRITE_REG_ADDR:
0224     case BT_OP_WRITE_REG_VALUE:
0225     case BT_OP_READ_REG:
0226     default:
0227         req_num = BT_SEQ_DONT_CARE;
0228         break;
0229     }
0230 
0231     cmd[0] |= (oper_ver & 0x0f);        /* Set OperVer */
0232     cmd[0] |= ((req_num << 4) & 0xf0);  /* Set ReqNum */
0233     cmd[1] = op_code;
0234     rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, len, cmd);
0235 
0236     /* wait? */
0237     if (!wait_ms)
0238         return true;
0239 
0240     rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
0241         "btmpinfo wait req_num=%d wait=%ld\n", req_num, wait_ms);
0242 
0243     if (wait_for_completion_timeout(&btcoexist->bt_mp_comp,
0244                     msecs_to_jiffies(wait_ms)) == 0) {
0245         rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
0246             "btmpinfo wait (req_num=%d) timeout\n", req_num);
0247 
0248         return false;   /* timeout */
0249     }
0250 
0251     return true;
0252 }
0253 
0254 static void halbtc_leave_lps(struct btc_coexist *btcoexist)
0255 {
0256     struct rtl_priv *rtlpriv;
0257     bool ap_enable = false;
0258 
0259     rtlpriv = btcoexist->adapter;
0260 
0261     btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
0262                &ap_enable);
0263 
0264     if (ap_enable) {
0265         rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
0266             "%s()<--dont leave lps under AP mode\n", __func__);
0267         return;
0268     }
0269 
0270     btcoexist->bt_info.bt_ctrl_lps = true;
0271     btcoexist->bt_info.bt_lps_on = false;
0272     /* FIXME: Context is unclear. Is it allowed to block? */
0273     rtl_lps_leave(rtlpriv->mac80211.hw, false);
0274 }
0275 
0276 static void halbtc_enter_lps(struct btc_coexist *btcoexist)
0277 {
0278     struct rtl_priv *rtlpriv;
0279     bool ap_enable = false;
0280 
0281     rtlpriv = btcoexist->adapter;
0282 
0283     btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
0284                &ap_enable);
0285 
0286     if (ap_enable) {
0287         rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
0288             "%s()<--dont enter lps under AP mode\n", __func__);
0289         return;
0290     }
0291 
0292     btcoexist->bt_info.bt_ctrl_lps = true;
0293     btcoexist->bt_info.bt_lps_on = true;
0294     /* FIXME: Context is unclear. Is it allowed to block? */
0295     rtl_lps_enter(rtlpriv->mac80211.hw, false);
0296 }
0297 
0298 static void halbtc_normal_lps(struct btc_coexist *btcoexist)
0299 {
0300     struct rtl_priv *rtlpriv;
0301 
0302     rtlpriv = btcoexist->adapter;
0303 
0304     if (btcoexist->bt_info.bt_ctrl_lps) {
0305         btcoexist->bt_info.bt_lps_on = false;
0306         /* FIXME: Context is unclear. Is it allowed to block? */
0307         rtl_lps_leave(rtlpriv->mac80211.hw, false);
0308         btcoexist->bt_info.bt_ctrl_lps = false;
0309     }
0310 }
0311 
0312 static void halbtc_pre_normal_lps(struct btc_coexist *btcoexist)
0313 {
0314     struct rtl_priv *rtlpriv = btcoexist->adapter;
0315 
0316     if (btcoexist->bt_info.bt_ctrl_lps) {
0317         btcoexist->bt_info.bt_lps_on = false;
0318         /* FIXME: Context is unclear. Is it allowed to block? */
0319         rtl_lps_leave(rtlpriv->mac80211.hw, false);
0320     }
0321 }
0322 
0323 static void halbtc_post_normal_lps(struct btc_coexist *btcoexist)
0324 {
0325     if (btcoexist->bt_info.bt_ctrl_lps)
0326         btcoexist->bt_info.bt_ctrl_lps = false;
0327 }
0328 
0329 static void halbtc_leave_low_power(struct btc_coexist *btcoexist)
0330 {
0331 }
0332 
0333 static void halbtc_normal_low_power(struct btc_coexist *btcoexist)
0334 {
0335 }
0336 
0337 static void halbtc_disable_low_power(struct btc_coexist *btcoexist,
0338                      bool low_pwr_disable)
0339 {
0340     /* TODO: original/leave 32k low power */
0341     btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable;
0342 }
0343 
0344 static void halbtc_aggregation_check(struct btc_coexist *btcoexist)
0345 {
0346     bool need_to_act = false;
0347     static unsigned long pre_time;
0348     unsigned long cur_time = 0;
0349     struct rtl_priv *rtlpriv = btcoexist->adapter;
0350 
0351     /* To void continuous deleteBA=>addBA=>deleteBA=>addBA
0352      * This function is not allowed to continuous called
0353      * It can only be called after 8 seconds
0354      */
0355 
0356     cur_time = jiffies;
0357     if (jiffies_to_msecs(cur_time - pre_time) <= 8000) {
0358         /* over 8 seconds you can execute this function again. */
0359         return;
0360     }
0361     pre_time = cur_time;
0362 
0363     if (btcoexist->bt_info.reject_agg_pkt) {
0364         need_to_act = true;
0365         btcoexist->bt_info.pre_reject_agg_pkt =
0366             btcoexist->bt_info.reject_agg_pkt;
0367     } else {
0368         if (btcoexist->bt_info.pre_reject_agg_pkt) {
0369             need_to_act = true;
0370             btcoexist->bt_info.pre_reject_agg_pkt =
0371                 btcoexist->bt_info.reject_agg_pkt;
0372         }
0373 
0374         if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
0375             btcoexist->bt_info.bt_ctrl_agg_buf_size) {
0376             need_to_act = true;
0377             btcoexist->bt_info.pre_bt_ctrl_agg_buf_size =
0378                 btcoexist->bt_info.bt_ctrl_agg_buf_size;
0379         }
0380 
0381         if (btcoexist->bt_info.bt_ctrl_agg_buf_size) {
0382             if (btcoexist->bt_info.pre_agg_buf_size !=
0383                 btcoexist->bt_info.agg_buf_size) {
0384                 need_to_act = true;
0385             }
0386             btcoexist->bt_info.pre_agg_buf_size =
0387                 btcoexist->bt_info.agg_buf_size;
0388         }
0389 
0390         if (need_to_act)
0391             rtl_rx_ampdu_apply(rtlpriv);
0392     }
0393 }
0394 
0395 static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
0396 {
0397     u8 cmd_buffer[4] = {0};
0398 
0399     if (btcoexist->bt_info.bt_real_fw_ver)
0400         goto label_done;
0401 
0402     /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
0403     halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_VERSION,
0404                     cmd_buffer, 4, 200);
0405 
0406 label_done:
0407     return btcoexist->bt_info.bt_real_fw_ver;
0408 }
0409 
0410 static u32 halbtc_get_bt_coex_supported_feature(void *btc_context)
0411 {
0412     struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
0413     u8 cmd_buffer[4] = {0};
0414 
0415     if (btcoexist->bt_info.bt_supported_feature)
0416         goto label_done;
0417 
0418     /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
0419     halbtc_send_bt_mp_operation(btcoexist,
0420                     BT_OP_GET_BT_COEX_SUPPORTED_FEATURE,
0421                     cmd_buffer, 4, 200);
0422 
0423 label_done:
0424     return btcoexist->bt_info.bt_supported_feature;
0425 }
0426 
0427 static u32 halbtc_get_bt_coex_supported_version(void *btc_context)
0428 {
0429     struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
0430     u8 cmd_buffer[4] = {0};
0431 
0432     if (btcoexist->bt_info.bt_supported_version)
0433         goto label_done;
0434 
0435     /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
0436     halbtc_send_bt_mp_operation(btcoexist,
0437                     BT_OP_GET_BT_COEX_SUPPORTED_VERSION,
0438                     cmd_buffer, 4, 200);
0439 
0440 label_done:
0441     return btcoexist->bt_info.bt_supported_version;
0442 }
0443 
0444 static u32 halbtc_get_bt_device_info(void *btc_context)
0445 {
0446     struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
0447     u8 cmd_buffer[4] = {0};
0448 
0449     /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
0450     halbtc_send_bt_mp_operation(btcoexist,
0451                     BT_OP_GET_BT_DEVICE_INFO,
0452                     cmd_buffer, 4, 200);
0453 
0454     return btcoexist->bt_info.bt_device_info;
0455 }
0456 
0457 static u32 halbtc_get_bt_forbidden_slot_val(void *btc_context)
0458 {
0459     struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
0460     u8 cmd_buffer[4] = {0};
0461 
0462     /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
0463     halbtc_send_bt_mp_operation(btcoexist,
0464                     BT_OP_GET_BT_FORBIDDEN_SLOT_VAL,
0465                     cmd_buffer, 4, 200);
0466 
0467     return btcoexist->bt_info.bt_forb_slot_val;
0468 }
0469 
0470 static u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist)
0471 {
0472     /* return value:
0473      * [31:16] => connected port number
0474      * [15:0]  => port connected bit define
0475      */
0476     struct rtl_priv *rtlpriv = btcoexist->adapter;
0477     struct rtl_mac *mac = rtl_mac(rtlpriv);
0478     u32 ret_val = 0;
0479     u32 port_connected_status = 0, num_of_connected_port = 0;
0480 
0481     if (mac->opmode == NL80211_IFTYPE_STATION &&
0482         mac->link_state >= MAC80211_LINKED) {
0483         port_connected_status |= WIFI_STA_CONNECTED;
0484         num_of_connected_port++;
0485     }
0486     /* AP & ADHOC & MESH */
0487     if (is_any_client_connect_to_ap(btcoexist)) {
0488         port_connected_status |= WIFI_AP_CONNECTED;
0489         num_of_connected_port++;
0490     }
0491     /* TODO: P2P Connected Status */
0492 
0493     ret_val = (num_of_connected_port << 16) | port_connected_status;
0494 
0495     return ret_val;
0496 }
0497 
0498 static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv)
0499 {
0500     return rtlpriv->dm.undec_sm_pwdb;
0501 }
0502 
0503 static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
0504 {
0505     struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
0506     struct rtl_priv *rtlpriv = btcoexist->adapter;
0507     struct rtl_phy *rtlphy = &(rtlpriv->phy);
0508     struct rtl_mac *mac = rtl_mac(rtlpriv);
0509     struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
0510     bool *bool_tmp = (bool *)out_buf;
0511     int *s32_tmp = (int *)out_buf;
0512     u32 *u32_tmp = (u32 *)out_buf;
0513     u8 *u8_tmp = (u8 *)out_buf;
0514     bool tmp = false;
0515     bool ret = true;
0516 
0517     if (!halbtc_is_bt_coexist_available(btcoexist))
0518         return false;
0519 
0520     switch (get_type) {
0521     case BTC_GET_BL_HS_OPERATION:
0522         *bool_tmp = false;
0523         ret = false;
0524         break;
0525     case BTC_GET_BL_HS_CONNECTING:
0526         *bool_tmp = false;
0527         ret = false;
0528         break;
0529     case BTC_GET_BL_WIFI_CONNECTED:
0530         if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
0531             rtlpriv->mac80211.link_state >= MAC80211_LINKED)
0532             tmp = true;
0533         if (is_any_client_connect_to_ap(btcoexist))
0534             tmp = true;
0535         *bool_tmp = tmp;
0536         break;
0537     case BTC_GET_BL_WIFI_DUAL_BAND_CONNECTED:
0538         *u8_tmp = BTC_MULTIPORT_SCC;
0539         break;
0540     case BTC_GET_BL_WIFI_BUSY:
0541         if (halbtc_is_wifi_busy(rtlpriv))
0542             *bool_tmp = true;
0543         else
0544             *bool_tmp = false;
0545         break;
0546     case BTC_GET_BL_WIFI_SCAN:
0547         if (mac->act_scanning)
0548             *bool_tmp = true;
0549         else
0550             *bool_tmp = false;
0551         break;
0552     case BTC_GET_BL_WIFI_LINK:
0553         if (mac->link_state == MAC80211_LINKING)
0554             *bool_tmp = true;
0555         else
0556             *bool_tmp = false;
0557         break;
0558     case BTC_GET_BL_WIFI_ROAM:
0559         if (mac->link_state == MAC80211_LINKING)
0560             *bool_tmp = true;
0561         else
0562             *bool_tmp = false;
0563         break;
0564     case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
0565         *bool_tmp = rtlpriv->btcoexist.btc_info.in_4way;
0566         break;
0567     case BTC_GET_BL_WIFI_UNDER_5G:
0568         if (rtlhal->current_bandtype == BAND_ON_5G)
0569             *bool_tmp = true;
0570         else
0571             *bool_tmp = false;
0572         break;
0573     case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
0574         if (mac->opmode == NL80211_IFTYPE_AP)
0575             *bool_tmp = true;
0576         else
0577             *bool_tmp = false;
0578         break;
0579     case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
0580         if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm)
0581             *bool_tmp = false;
0582         else
0583             *bool_tmp = true;
0584         break;
0585     case BTC_GET_BL_WIFI_UNDER_B_MODE:
0586         if (rtlpriv->mac80211.mode == WIRELESS_MODE_B)
0587             *bool_tmp = true;
0588         else
0589             *bool_tmp = false;
0590         break;
0591     case BTC_GET_BL_EXT_SWITCH:
0592         *bool_tmp = false;
0593         break;
0594     case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
0595         *bool_tmp = false;
0596         break;
0597     case BTC_GET_BL_IS_ASUS_8723B:
0598         *bool_tmp = false;
0599         break;
0600     case BTC_GET_BL_RF4CE_CONNECTED:
0601         *bool_tmp = false;
0602         break;
0603     case BTC_GET_S4_WIFI_RSSI:
0604         *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
0605         break;
0606     case BTC_GET_S4_HS_RSSI:
0607         *s32_tmp = 0;
0608         ret = false;
0609         break;
0610     case BTC_GET_U4_WIFI_BW:
0611         *u32_tmp = halbtc_get_wifi_bw(btcoexist);
0612         break;
0613     case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
0614         if (halbtc_is_wifi_uplink(rtlpriv))
0615             *u32_tmp = BTC_WIFI_TRAFFIC_TX;
0616         else
0617             *u32_tmp = BTC_WIFI_TRAFFIC_RX;
0618         break;
0619     case BTC_GET_U4_WIFI_FW_VER:
0620         *u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion;
0621         break;
0622     case BTC_GET_U4_WIFI_LINK_STATUS:
0623         *u32_tmp = halbtc_get_wifi_link_status(btcoexist);
0624         break;
0625     case BTC_GET_U4_BT_PATCH_VER:
0626         *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
0627         break;
0628     case BTC_GET_U4_VENDOR:
0629         *u32_tmp = BTC_VENDOR_OTHER;
0630         break;
0631     case BTC_GET_U4_SUPPORTED_VERSION:
0632         *u32_tmp = halbtc_get_bt_coex_supported_version(btcoexist);
0633         break;
0634     case BTC_GET_U4_SUPPORTED_FEATURE:
0635         *u32_tmp = halbtc_get_bt_coex_supported_feature(btcoexist);
0636         break;
0637     case BTC_GET_U4_BT_DEVICE_INFO:
0638         *u32_tmp = halbtc_get_bt_device_info(btcoexist);
0639         break;
0640     case BTC_GET_U4_BT_FORBIDDEN_SLOT_VAL:
0641         *u32_tmp = halbtc_get_bt_forbidden_slot_val(btcoexist);
0642         break;
0643     case BTC_GET_U4_WIFI_IQK_TOTAL:
0644         *u32_tmp =
0645             btcoexist->btc_phydm_query_phy_counter(btcoexist,
0646                                    DM_INFO_IQK_ALL);
0647         break;
0648     case BTC_GET_U4_WIFI_IQK_OK:
0649         *u32_tmp =
0650             btcoexist->btc_phydm_query_phy_counter(btcoexist,
0651                                    DM_INFO_IQK_OK);
0652         break;
0653     case BTC_GET_U4_WIFI_IQK_FAIL:
0654         *u32_tmp =
0655             btcoexist->btc_phydm_query_phy_counter(btcoexist,
0656                                    DM_INFO_IQK_NG);
0657         break;
0658     case BTC_GET_U1_WIFI_DOT11_CHNL:
0659         *u8_tmp = rtlphy->current_channel;
0660         break;
0661     case BTC_GET_U1_WIFI_CENTRAL_CHNL:
0662         *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
0663         break;
0664     case BTC_GET_U1_WIFI_HS_CHNL:
0665         *u8_tmp = 0;
0666         ret = false;
0667         break;
0668     case BTC_GET_U1_AP_NUM:
0669         *u8_tmp = rtlpriv->btcoexist.btc_info.ap_num;
0670         break;
0671     case BTC_GET_U1_ANT_TYPE:
0672         *u8_tmp = (u8)BTC_ANT_TYPE_0;
0673         break;
0674     case BTC_GET_U1_IOT_PEER:
0675         *u8_tmp = 0;
0676         break;
0677 
0678         /************* 1Ant **************/
0679     case BTC_GET_U1_LPS_MODE:
0680         *u8_tmp = btcoexist->pwr_mode_val[0];
0681         break;
0682 
0683     default:
0684         ret = false;
0685         break;
0686     }
0687 
0688     return ret;
0689 }
0690 
0691 static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
0692 {
0693     struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
0694     bool *bool_tmp = (bool *)in_buf;
0695     u8 *u8_tmp = (u8 *)in_buf;
0696     u32 *u32_tmp = (u32 *)in_buf;
0697     bool ret = true;
0698 
0699     if (!halbtc_is_bt_coexist_available(btcoexist))
0700         return false;
0701 
0702     switch (set_type) {
0703     /* set some bool type variables. */
0704     case BTC_SET_BL_BT_DISABLE:
0705         btcoexist->bt_info.bt_disabled = *bool_tmp;
0706         break;
0707     case BTC_SET_BL_BT_TRAFFIC_BUSY:
0708         btcoexist->bt_info.bt_busy = *bool_tmp;
0709         break;
0710     case BTC_SET_BL_BT_LIMITED_DIG:
0711         btcoexist->bt_info.limited_dig = *bool_tmp;
0712         break;
0713     case BTC_SET_BL_FORCE_TO_ROAM:
0714         btcoexist->bt_info.force_to_roam = *bool_tmp;
0715         break;
0716     case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
0717         btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
0718         break;
0719     case BTC_SET_BL_BT_CTRL_AGG_SIZE:
0720         btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp;
0721         break;
0722     case BTC_SET_BL_INC_SCAN_DEV_NUM:
0723         btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
0724         break;
0725     case BTC_SET_BL_BT_TX_RX_MASK:
0726         btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp;
0727         break;
0728     case BTC_SET_BL_MIRACAST_PLUS_BT:
0729         btcoexist->bt_info.miracast_plus_bt = *bool_tmp;
0730         break;
0731         /* set some u1Byte type variables. */
0732     case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
0733         btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
0734         break;
0735     case BTC_SET_U1_AGG_BUF_SIZE:
0736         btcoexist->bt_info.agg_buf_size = *u8_tmp;
0737         break;
0738 
0739     /* the following are some action which will be triggered */
0740     case BTC_SET_ACT_GET_BT_RSSI:
0741         ret = false;
0742         break;
0743     case BTC_SET_ACT_AGGREGATE_CTRL:
0744         halbtc_aggregation_check(btcoexist);
0745         break;
0746 
0747     /* 1Ant */
0748     case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
0749         btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
0750         break;
0751     case BTC_SET_UI_SCAN_SIG_COMPENSATION:
0752         break;
0753     case BTC_SET_U1_LPS_VAL:
0754         btcoexist->bt_info.lps_val = *u8_tmp;
0755         break;
0756     case BTC_SET_U1_RPWM_VAL:
0757         btcoexist->bt_info.rpwm_val = *u8_tmp;
0758         break;
0759     /* the following are some action which will be triggered  */
0760     case BTC_SET_ACT_LEAVE_LPS:
0761         halbtc_leave_lps(btcoexist);
0762         break;
0763     case BTC_SET_ACT_ENTER_LPS:
0764         halbtc_enter_lps(btcoexist);
0765         break;
0766     case BTC_SET_ACT_NORMAL_LPS:
0767         halbtc_normal_lps(btcoexist);
0768         break;
0769     case BTC_SET_ACT_PRE_NORMAL_LPS:
0770         halbtc_pre_normal_lps(btcoexist);
0771         break;
0772     case BTC_SET_ACT_POST_NORMAL_LPS:
0773         halbtc_post_normal_lps(btcoexist);
0774         break;
0775     case BTC_SET_ACT_DISABLE_LOW_POWER:
0776         halbtc_disable_low_power(btcoexist, *bool_tmp);
0777         break;
0778     case BTC_SET_ACT_UPDATE_RAMASK:
0779         btcoexist->bt_info.ra_mask = *u32_tmp;
0780         break;
0781     case BTC_SET_ACT_SEND_MIMO_PS:
0782         break;
0783     case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
0784         break;
0785     case BTC_SET_ACT_CTRL_BT_COEX:
0786         break;
0787     case BTC_SET_ACT_CTRL_8723B_ANT:
0788         break;
0789     default:
0790         break;
0791     }
0792 
0793     return ret;
0794 }
0795 
0796 static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist,
0797                        struct seq_file *m)
0798 {
0799 }
0800 
0801 static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist,
0802                     struct seq_file *m)
0803 {
0804 }
0805 
0806 static void halbtc_display_wifi_status(struct btc_coexist *btcoexist,
0807                        struct seq_file *m)
0808 {
0809     struct rtl_priv *rtlpriv = btcoexist->adapter;
0810     s32 wifi_rssi = 0, bt_hs_rssi = 0;
0811     bool scan = false, link = false, roam = false, wifi_busy = false;
0812     bool wifi_under_b_mode = false;
0813     bool wifi_under_5g = false;
0814     u32 wifi_bw = BTC_WIFI_BW_HT20;
0815     u32 wifi_traffic_dir = BTC_WIFI_TRAFFIC_TX;
0816     u32 wifi_freq = BTC_FREQ_2_4G;
0817     u32 wifi_link_status = 0x0;
0818     bool bt_hs_on = false, under_ips = false, under_lps = false;
0819     bool low_power = false, dc_mode = false;
0820     u8 wifi_chnl = 0, wifi_hs_chnl = 0;
0821     u8 ap_num = 0;
0822 
0823     wifi_link_status = halbtc_get_wifi_link_status(btcoexist);
0824     seq_printf(m, "\n %-35s = %d/ %d/ %d/ %d/ %d",
0825            "STA/vWifi/HS/p2pGo/p2pGc",
0826            ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0),
0827            ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0),
0828            ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0),
0829            ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
0830            ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
0831 
0832     btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
0833     btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_chnl);
0834     btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
0835     seq_printf(m, "\n %-35s = %d / %d(%d)",
0836            "Dot11 channel / HsChnl(High Speed)",
0837            wifi_chnl, wifi_hs_chnl, bt_hs_on);
0838 
0839     btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
0840     btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
0841     seq_printf(m, "\n %-35s = %d/ %d",
0842            "Wifi rssi/ HS rssi",
0843            wifi_rssi - 100, bt_hs_rssi - 100);
0844 
0845     btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
0846     btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
0847     btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
0848     seq_printf(m, "\n %-35s = %d/ %d/ %d ",
0849            "Wifi link/ roam/ scan",
0850            link, roam, scan);
0851 
0852     btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
0853     btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
0854     btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
0855     btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
0856                &wifi_traffic_dir);
0857     btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
0858     wifi_freq = (wifi_under_5g ? BTC_FREQ_5G : BTC_FREQ_2_4G);
0859     btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
0860                &wifi_under_b_mode);
0861 
0862     seq_printf(m, "\n %-35s = %s / %s/ %s/ AP=%d ",
0863            "Wifi freq/ bw/ traffic",
0864            gl_btc_wifi_freq_string[wifi_freq],
0865            ((wifi_under_b_mode) ? "11b" :
0866             gl_btc_wifi_bw_string[wifi_bw]),
0867            ((!wifi_busy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX ==
0868                           wifi_traffic_dir) ? "uplink" :
0869                          "downlink")),
0870            ap_num);
0871 
0872     /* power status  */
0873     dc_mode = true; /*TODO*/
0874     under_ips = rtlpriv->psc.inactive_pwrstate == ERFOFF ? 1 : 0;
0875     under_lps = rtlpriv->psc.dot11_psmode == EACTIVE ? 0 : 1;
0876     low_power = 0; /*TODO*/
0877     seq_printf(m, "\n %-35s = %s%s%s%s",
0878            "Power Status",
0879            (dc_mode ? "DC mode" : "AC mode"),
0880            (under_ips ? ", IPS ON" : ""),
0881            (under_lps ? ", LPS ON" : ""),
0882            (low_power ? ", 32k" : ""));
0883 
0884     seq_printf(m,
0885            "\n %-35s = %6ph (0x%x/0x%x)",
0886            "Power mode cmd(lps/rpwm)",
0887            btcoexist->pwr_mode_val,
0888            btcoexist->bt_info.lps_val,
0889            btcoexist->bt_info.rpwm_val);
0890 }
0891 
0892 /************************************************************
0893  *      IO related function
0894  ************************************************************/
0895 static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
0896 {
0897     struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
0898     struct rtl_priv *rtlpriv = btcoexist->adapter;
0899 
0900     return  rtl_read_byte(rtlpriv, reg_addr);
0901 }
0902 
0903 static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
0904 {
0905     struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
0906     struct rtl_priv *rtlpriv = btcoexist->adapter;
0907 
0908     return  rtl_read_word(rtlpriv, reg_addr);
0909 }
0910 
0911 static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
0912 {
0913     struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
0914     struct rtl_priv *rtlpriv = btcoexist->adapter;
0915 
0916     return  rtl_read_dword(rtlpriv, reg_addr);
0917 }
0918 
0919 static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data)
0920 {
0921     struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
0922     struct rtl_priv *rtlpriv = btcoexist->adapter;
0923 
0924     rtl_write_byte(rtlpriv, reg_addr, data);
0925 }
0926 
0927 static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
0928                        u32 bit_mask, u8 data)
0929 {
0930     struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
0931     struct rtl_priv *rtlpriv = btcoexist->adapter;
0932     u8 original_value, bit_shift = 0;
0933     u8 i;
0934 
0935     if (bit_mask != MASKDWORD) {/*if not "double word" write*/
0936         original_value = rtl_read_byte(rtlpriv, reg_addr);
0937         for (i = 0; i <= 7; i++) {
0938             if ((bit_mask>>i) & 0x1)
0939                 break;
0940         }
0941         bit_shift = i;
0942         data = (original_value & (~bit_mask)) |
0943             ((data << bit_shift) & bit_mask);
0944     }
0945     rtl_write_byte(rtlpriv, reg_addr, data);
0946 }
0947 
0948 static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
0949 {
0950     struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
0951     struct rtl_priv *rtlpriv = btcoexist->adapter;
0952 
0953     rtl_write_word(rtlpriv, reg_addr, data);
0954 }
0955 
0956 static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
0957 {
0958     struct btc_coexist *btcoexist =
0959         (struct btc_coexist *)bt_context;
0960     struct rtl_priv *rtlpriv = btcoexist->adapter;
0961 
0962     rtl_write_dword(rtlpriv, reg_addr, data);
0963 }
0964 
0965 static void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr,
0966                      u8 data)
0967 {
0968     struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
0969     struct rtl_priv *rtlpriv = btcoexist->adapter;
0970 
0971     if (btcoexist->chip_interface == BTC_INTF_SDIO)
0972         ;
0973     else if (btcoexist->chip_interface == BTC_INTF_PCI)
0974         rtl_write_byte(rtlpriv, reg_addr, data);
0975     else if (btcoexist->chip_interface == BTC_INTF_USB)
0976         rtl_write_byte(rtlpriv, reg_addr, data);
0977 }
0978 
0979 static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
0980                  u32 data)
0981 {
0982     struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
0983     struct rtl_priv *rtlpriv = btcoexist->adapter;
0984 
0985     rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
0986 }
0987 
0988 static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
0989 {
0990     struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
0991     struct rtl_priv *rtlpriv = btcoexist->adapter;
0992 
0993     return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
0994 }
0995 
0996 static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
0997                  u32 bit_mask, u32 data)
0998 {
0999     struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1000     struct rtl_priv *rtlpriv = btcoexist->adapter;
1001 
1002     rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
1003 }
1004 
1005 static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
1006                 u32 bit_mask)
1007 {
1008     struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1009     struct rtl_priv *rtlpriv = btcoexist->adapter;
1010 
1011     return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
1012 }
1013 
1014 static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
1015                 u32 cmd_len, u8 *cmd_buf)
1016 {
1017     struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1018     struct rtl_priv *rtlpriv = btcoexist->adapter;
1019 
1020     rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
1021                     cmd_len, cmd_buf);
1022 }
1023 
1024 void halbtc_send_wifi_port_id_cmd(void *bt_context)
1025 {
1026     struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1027     struct rtl_priv *rtlpriv = btcoexist->adapter;
1028     u8 cmd_buf[1] = {0};    /* port id [2:0] = 0 */
1029 
1030     rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, H2C_BT_PORT_ID,
1031                     1, cmd_buf);
1032 }
1033 
1034 void halbtc_set_default_port_id_cmd(void *bt_context)
1035 {
1036     struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1037     struct rtl_priv *rtlpriv = btcoexist->adapter;
1038     struct ieee80211_hw *hw = rtlpriv->mac80211.hw;
1039 
1040     if (!rtlpriv->cfg->ops->set_default_port_id_cmd)
1041         return;
1042 
1043     rtlpriv->cfg->ops->set_default_port_id_cmd(hw);
1044 }
1045 
1046 static
1047 void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val)
1048 {
1049     struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1050     u8 cmd_buffer1[4] = {0};
1051     u8 cmd_buffer2[4] = {0};
1052 
1053     /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1054     *((__le16 *)&cmd_buffer1[2]) = cpu_to_le16((u16)set_val);
1055     if (!halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_VALUE,
1056                      cmd_buffer1, 4, 200))
1057         return;
1058 
1059     /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1060     cmd_buffer2[2] = reg_type;
1061     *((u8 *)&cmd_buffer2[3]) = (u8)offset;
1062     halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_ADDR,
1063                     cmd_buffer2, 4, 200);
1064 }
1065 
1066 static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type,
1067                    struct seq_file *m)
1068 {
1069     struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1070 
1071     switch (disp_type) {
1072     case BTC_DBG_DISP_COEX_STATISTICS:
1073         halbtc_display_coex_statistics(btcoexist, m);
1074         break;
1075     case BTC_DBG_DISP_BT_LINK_INFO:
1076         halbtc_display_bt_link_info(btcoexist, m);
1077         break;
1078     case BTC_DBG_DISP_WIFI_STATUS:
1079         halbtc_display_wifi_status(btcoexist, m);
1080         break;
1081     default:
1082         break;
1083     }
1084 }
1085 
1086 static u32 halbtc_get_bt_reg(void *btc_context, u8 reg_type, u32 offset)
1087 {
1088     return 0;
1089 }
1090 
1091 static bool halbtc_under_ips(struct btc_coexist *btcoexist)
1092 {
1093     struct rtl_priv *rtlpriv = btcoexist->adapter;
1094     struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
1095     enum rf_pwrstate rtstate;
1096 
1097     if (ppsc->inactiveps) {
1098         rtstate = ppsc->rfpwr_state;
1099 
1100         if (rtstate != ERFON &&
1101             ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
1102             return true;
1103         }
1104     }
1105 
1106     return false;
1107 }
1108 
1109 static
1110 u32 halbtc_get_phydm_version(void *btc_context)
1111 {
1112     return 0;
1113 }
1114 
1115 static
1116 void halbtc_phydm_modify_ra_pcr_threshold(void *btc_context,
1117                       u8 ra_offset_direction,
1118                       u8 ra_threshold_offset)
1119 {
1120 }
1121 
1122 static
1123 u32 halbtc_phydm_query_phy_counter(void *btc_context, enum dm_info_query dm_id)
1124 {
1125     return 0;
1126 }
1127 
1128 static u8 halbtc_get_ant_det_val_from_bt(void *btc_context)
1129 {
1130     struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1131     u8 cmd_buffer[4] = {0};
1132 
1133     /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1134     halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_ANT_DET_VAL,
1135                     cmd_buffer, 4, 200);
1136 
1137     /* need wait completion to return correct value */
1138 
1139     return btcoexist->bt_info.bt_ant_det_val;
1140 }
1141 
1142 static u8 halbtc_get_ble_scan_type_from_bt(void *btc_context)
1143 {
1144     struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1145     u8 cmd_buffer[4] = {0};
1146 
1147     /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1148     halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_TYPE,
1149                     cmd_buffer, 4, 200);
1150 
1151     /* need wait completion to return correct value */
1152 
1153     return btcoexist->bt_info.bt_ble_scan_type;
1154 }
1155 
1156 static u32 halbtc_get_ble_scan_para_from_bt(void *btc_context, u8 scan_type)
1157 {
1158     struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1159     u8 cmd_buffer[4] = {0};
1160 
1161     /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1162     halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_PARA,
1163                     cmd_buffer, 4, 200);
1164 
1165     /* need wait completion to return correct value */
1166 
1167     return btcoexist->bt_info.bt_ble_scan_para;
1168 }
1169 
1170 static bool halbtc_get_bt_afh_map_from_bt(void *btc_context, u8 map_type,
1171                       u8 *afh_map)
1172 {
1173     struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1174     u8 cmd_buffer[2] = {0};
1175     bool ret;
1176     u32 *afh_map_l = (u32 *)afh_map;
1177     u32 *afh_map_m = (u32 *)(afh_map + 4);
1178     u16 *afh_map_h = (u16 *)(afh_map + 8);
1179 
1180     /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1181     ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_L,
1182                       cmd_buffer, 2, 200);
1183     if (!ret)
1184         goto exit;
1185 
1186     *afh_map_l = btcoexist->bt_info.afh_map_l;
1187 
1188     /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1189     ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_M,
1190                       cmd_buffer, 2, 200);
1191     if (!ret)
1192         goto exit;
1193 
1194     *afh_map_m = btcoexist->bt_info.afh_map_m;
1195 
1196     /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1197     ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_H,
1198                       cmd_buffer, 2, 200);
1199     if (!ret)
1200         goto exit;
1201 
1202     *afh_map_h = btcoexist->bt_info.afh_map_h;
1203 
1204 exit:
1205     return ret;
1206 }
1207 
1208 /*****************************************************************
1209  *         Extern functions called by other module
1210  *****************************************************************/
1211 bool exhalbtc_initlize_variables(struct rtl_priv *rtlpriv)
1212 {
1213     struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1214 
1215     if (!btcoexist)
1216         return false;
1217 
1218     halbtc_dbg_init();
1219 
1220     btcoexist->btc_read_1byte = halbtc_read_1byte;
1221     btcoexist->btc_write_1byte = halbtc_write_1byte;
1222     btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
1223     btcoexist->btc_read_2byte = halbtc_read_2byte;
1224     btcoexist->btc_write_2byte = halbtc_write_2byte;
1225     btcoexist->btc_read_4byte = halbtc_read_4byte;
1226     btcoexist->btc_write_4byte = halbtc_write_4byte;
1227     btcoexist->btc_write_local_reg_1byte = halbtc_write_local_reg_1byte;
1228 
1229     btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
1230     btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
1231 
1232     btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
1233     btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
1234 
1235     btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
1236     btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
1237 
1238     btcoexist->btc_get = halbtc_get;
1239     btcoexist->btc_set = halbtc_set;
1240     btcoexist->btc_set_bt_reg = halbtc_set_bt_reg;
1241     btcoexist->btc_get_bt_reg = halbtc_get_bt_reg;
1242 
1243     btcoexist->bt_info.bt_ctrl_buf_size = false;
1244     btcoexist->bt_info.agg_buf_size = 5;
1245 
1246     btcoexist->bt_info.increase_scan_dev_num = false;
1247 
1248     btcoexist->btc_get_bt_coex_supported_feature =
1249                     halbtc_get_bt_coex_supported_feature;
1250     btcoexist->btc_get_bt_coex_supported_version =
1251                     halbtc_get_bt_coex_supported_version;
1252     btcoexist->btc_get_bt_phydm_version = halbtc_get_phydm_version;
1253     btcoexist->btc_phydm_modify_ra_pcr_threshold =
1254                     halbtc_phydm_modify_ra_pcr_threshold;
1255     btcoexist->btc_phydm_query_phy_counter = halbtc_phydm_query_phy_counter;
1256     btcoexist->btc_get_ant_det_val_from_bt = halbtc_get_ant_det_val_from_bt;
1257     btcoexist->btc_get_ble_scan_type_from_bt =
1258                     halbtc_get_ble_scan_type_from_bt;
1259     btcoexist->btc_get_ble_scan_para_from_bt =
1260                     halbtc_get_ble_scan_para_from_bt;
1261     btcoexist->btc_get_bt_afh_map_from_bt =
1262                     halbtc_get_bt_afh_map_from_bt;
1263 
1264     init_completion(&btcoexist->bt_mp_comp);
1265 
1266     return true;
1267 }
1268 
1269 bool exhalbtc_initlize_variables_wifi_only(struct rtl_priv *rtlpriv)
1270 {
1271     struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
1272     struct wifi_only_haldata *wifionly_haldata;
1273 
1274     if (!wifionly_cfg)
1275         return false;
1276 
1277     wifionly_cfg->adapter = rtlpriv;
1278 
1279     switch (rtlpriv->rtlhal.interface) {
1280     case INTF_PCI:
1281         wifionly_cfg->chip_interface = WIFIONLY_INTF_PCI;
1282         break;
1283     case INTF_USB:
1284         wifionly_cfg->chip_interface = WIFIONLY_INTF_USB;
1285         break;
1286     default:
1287         wifionly_cfg->chip_interface = WIFIONLY_INTF_UNKNOWN;
1288         break;
1289     }
1290 
1291     wifionly_haldata = &wifionly_cfg->haldata_info;
1292 
1293     wifionly_haldata->customer_id = CUSTOMER_NORMAL;
1294     wifionly_haldata->efuse_pg_antnum = rtl_get_hwpg_ant_num(rtlpriv);
1295     wifionly_haldata->efuse_pg_antpath =
1296                     rtl_get_hwpg_single_ant_path(rtlpriv);
1297     wifionly_haldata->rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1298     wifionly_haldata->ant_div_cfg = 0;
1299 
1300     return true;
1301 }
1302 
1303 bool exhalbtc_bind_bt_coex_withadapter(void *adapter)
1304 {
1305     struct rtl_priv *rtlpriv = adapter;
1306     struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1307     u8 ant_num, chip_type, single_ant_path;
1308 
1309     if (!btcoexist)
1310         return false;
1311 
1312     if (btcoexist->binded)
1313         return false;
1314 
1315     switch (rtlpriv->rtlhal.interface) {
1316     case INTF_PCI:
1317         btcoexist->chip_interface = BTC_INTF_PCI;
1318         break;
1319     case INTF_USB:
1320         btcoexist->chip_interface = BTC_INTF_USB;
1321         break;
1322     default:
1323         btcoexist->chip_interface = BTC_INTF_UNKNOWN;
1324         break;
1325     }
1326 
1327     btcoexist->binded = true;
1328     btcoexist->statistics.cnt_bind++;
1329 
1330     btcoexist->adapter = adapter;
1331 
1332     btcoexist->stack_info.profile_notified = false;
1333 
1334     btcoexist->bt_info.bt_ctrl_agg_buf_size = false;
1335     btcoexist->bt_info.agg_buf_size = 5;
1336 
1337     btcoexist->bt_info.increase_scan_dev_num = false;
1338     btcoexist->bt_info.miracast_plus_bt = false;
1339 
1340     chip_type = rtl_get_hwpg_bt_type(rtlpriv);
1341     exhalbtc_set_chip_type(btcoexist, chip_type);
1342     ant_num = rtl_get_hwpg_ant_num(rtlpriv);
1343     exhalbtc_set_ant_num(rtlpriv, BT_COEX_ANT_TYPE_PG, ant_num);
1344 
1345     /* set default antenna position to main  port */
1346     btcoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
1347 
1348     single_ant_path = rtl_get_hwpg_single_ant_path(rtlpriv);
1349     exhalbtc_set_single_ant_path(btcoexist, single_ant_path);
1350 
1351     if (rtl_get_hwpg_package_type(rtlpriv) == 0)
1352         btcoexist->board_info.tfbga_package = false;
1353     else if (rtl_get_hwpg_package_type(rtlpriv) == 1)
1354         btcoexist->board_info.tfbga_package = false;
1355     else
1356         btcoexist->board_info.tfbga_package = true;
1357 
1358     if (btcoexist->board_info.tfbga_package)
1359         rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1360             "[BTCoex], Package Type = TFBGA\n");
1361     else
1362         rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1363             "[BTCoex], Package Type = Non-TFBGA\n");
1364 
1365     btcoexist->board_info.rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1366     btcoexist->board_info.ant_div_cfg = 0;
1367 
1368     return true;
1369 }
1370 
1371 void exhalbtc_power_on_setting(struct btc_coexist *btcoexist)
1372 {
1373     if (!halbtc_is_bt_coexist_available(btcoexist))
1374         return;
1375 
1376     btcoexist->statistics.cnt_power_on++;
1377 
1378     if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1379         if (btcoexist->board_info.btdm_ant_num == 2)
1380             ex_btc8723b2ant_power_on_setting(btcoexist);
1381         else if (btcoexist->board_info.btdm_ant_num == 1)
1382             ex_btc8723b1ant_power_on_setting(btcoexist);
1383     }
1384 }
1385 
1386 void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist)
1387 {
1388     if (!halbtc_is_bt_coexist_available(btcoexist))
1389         return;
1390 
1391     btcoexist->statistics.cnt_pre_load_firmware++;
1392 
1393     if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1394         if (btcoexist->board_info.btdm_ant_num == 2)
1395             ex_btc8723b2ant_pre_load_firmware(btcoexist);
1396     }
1397 }
1398 
1399 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only)
1400 {
1401     if (!halbtc_is_bt_coexist_available(btcoexist))
1402         return;
1403 
1404     btcoexist->statistics.cnt_init_hw_config++;
1405 
1406     if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1407         if (btcoexist->board_info.btdm_ant_num == 2)
1408             ex_btc8821a2ant_init_hwconfig(btcoexist);
1409         else if (btcoexist->board_info.btdm_ant_num == 1)
1410             ex_btc8821a1ant_init_hwconfig(btcoexist, wifi_only);
1411     } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1412         if (btcoexist->board_info.btdm_ant_num == 2)
1413             ex_btc8723b2ant_init_hwconfig(btcoexist);
1414         else if (btcoexist->board_info.btdm_ant_num == 1)
1415             ex_btc8723b1ant_init_hwconfig(btcoexist, wifi_only);
1416     } else if (IS_HARDWARE_TYPE_8723A(btcoexist->adapter)) {
1417         /* 8723A has no this function */
1418     } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1419         if (btcoexist->board_info.btdm_ant_num == 2)
1420             ex_btc8192e2ant_init_hwconfig(btcoexist);
1421     }
1422 }
1423 
1424 void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg)
1425 {
1426 }
1427 
1428 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
1429 {
1430     if (!halbtc_is_bt_coexist_available(btcoexist))
1431         return;
1432 
1433     btcoexist->statistics.cnt_init_coex_dm++;
1434 
1435     if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1436         if (btcoexist->board_info.btdm_ant_num == 2)
1437             ex_btc8821a2ant_init_coex_dm(btcoexist);
1438         else if (btcoexist->board_info.btdm_ant_num == 1)
1439             ex_btc8821a1ant_init_coex_dm(btcoexist);
1440     } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1441         if (btcoexist->board_info.btdm_ant_num == 2)
1442             ex_btc8723b2ant_init_coex_dm(btcoexist);
1443         else if (btcoexist->board_info.btdm_ant_num == 1)
1444             ex_btc8723b1ant_init_coex_dm(btcoexist);
1445     } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1446         if (btcoexist->board_info.btdm_ant_num == 2)
1447             ex_btc8192e2ant_init_coex_dm(btcoexist);
1448     }
1449 
1450     btcoexist->initialized = true;
1451 }
1452 
1453 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
1454 {
1455     u8 ips_type;
1456 
1457     if (!halbtc_is_bt_coexist_available(btcoexist))
1458         return;
1459     btcoexist->statistics.cnt_ips_notify++;
1460     if (btcoexist->manual_control)
1461         return;
1462 
1463     if (ERFOFF == type)
1464         ips_type = BTC_IPS_ENTER;
1465     else
1466         ips_type = BTC_IPS_LEAVE;
1467 
1468     halbtc_leave_low_power(btcoexist);
1469 
1470     if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1471         if (btcoexist->board_info.btdm_ant_num == 2)
1472             ex_btc8821a2ant_ips_notify(btcoexist, ips_type);
1473         else if (btcoexist->board_info.btdm_ant_num == 1)
1474             ex_btc8821a1ant_ips_notify(btcoexist, ips_type);
1475     } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1476         if (btcoexist->board_info.btdm_ant_num == 2)
1477             ex_btc8723b2ant_ips_notify(btcoexist, ips_type);
1478         else if (btcoexist->board_info.btdm_ant_num == 1)
1479             ex_btc8723b1ant_ips_notify(btcoexist, ips_type);
1480     } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1481         if (btcoexist->board_info.btdm_ant_num == 2)
1482             ex_btc8192e2ant_ips_notify(btcoexist, ips_type);
1483     }
1484 
1485     halbtc_normal_low_power(btcoexist);
1486 }
1487 
1488 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
1489 {
1490     u8 lps_type;
1491 
1492     if (!halbtc_is_bt_coexist_available(btcoexist))
1493         return;
1494     btcoexist->statistics.cnt_lps_notify++;
1495     if (btcoexist->manual_control)
1496         return;
1497 
1498     if (EACTIVE == type)
1499         lps_type = BTC_LPS_DISABLE;
1500     else
1501         lps_type = BTC_LPS_ENABLE;
1502 
1503     if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1504         if (btcoexist->board_info.btdm_ant_num == 2)
1505             ex_btc8821a2ant_lps_notify(btcoexist, lps_type);
1506         else if (btcoexist->board_info.btdm_ant_num == 1)
1507             ex_btc8821a1ant_lps_notify(btcoexist, lps_type);
1508     } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1509         if (btcoexist->board_info.btdm_ant_num == 2)
1510             ex_btc8723b2ant_lps_notify(btcoexist, lps_type);
1511         else if (btcoexist->board_info.btdm_ant_num == 1)
1512             ex_btc8723b1ant_lps_notify(btcoexist, lps_type);
1513     } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1514         if (btcoexist->board_info.btdm_ant_num == 2)
1515             ex_btc8192e2ant_lps_notify(btcoexist, lps_type);
1516     }
1517 }
1518 
1519 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
1520 {
1521     u8 scan_type;
1522 
1523     if (!halbtc_is_bt_coexist_available(btcoexist))
1524         return;
1525     btcoexist->statistics.cnt_scan_notify++;
1526     if (btcoexist->manual_control)
1527         return;
1528 
1529     if (type)
1530         scan_type = BTC_SCAN_START;
1531     else
1532         scan_type = BTC_SCAN_FINISH;
1533 
1534     halbtc_leave_low_power(btcoexist);
1535 
1536     if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1537         if (btcoexist->board_info.btdm_ant_num == 2)
1538             ex_btc8821a2ant_scan_notify(btcoexist, scan_type);
1539         else if (btcoexist->board_info.btdm_ant_num == 1)
1540             ex_btc8821a1ant_scan_notify(btcoexist, scan_type);
1541     } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1542         if (btcoexist->board_info.btdm_ant_num == 2)
1543             ex_btc8723b2ant_scan_notify(btcoexist, scan_type);
1544         else if (btcoexist->board_info.btdm_ant_num == 1)
1545             ex_btc8723b1ant_scan_notify(btcoexist, scan_type);
1546     } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1547         if (btcoexist->board_info.btdm_ant_num == 2)
1548             ex_btc8192e2ant_scan_notify(btcoexist, scan_type);
1549     }
1550 
1551     halbtc_normal_low_power(btcoexist);
1552 }
1553 
1554 void exhalbtc_scan_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1555                     u8 is_5g)
1556 {
1557 }
1558 
1559 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
1560 {
1561     u8 asso_type;
1562     bool wifi_under_5g;
1563 
1564     if (!halbtc_is_bt_coexist_available(btcoexist))
1565         return;
1566     btcoexist->statistics.cnt_connect_notify++;
1567     if (btcoexist->manual_control)
1568         return;
1569 
1570     btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
1571 
1572     if (action)
1573         asso_type = BTC_ASSOCIATE_START;
1574     else
1575         asso_type = BTC_ASSOCIATE_FINISH;
1576 
1577     halbtc_leave_low_power(btcoexist);
1578 
1579     if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1580         if (btcoexist->board_info.btdm_ant_num == 2)
1581             ex_btc8821a2ant_connect_notify(btcoexist, asso_type);
1582         else if (btcoexist->board_info.btdm_ant_num == 1)
1583             ex_btc8821a1ant_connect_notify(btcoexist, asso_type);
1584     } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1585         if (btcoexist->board_info.btdm_ant_num == 2)
1586             ex_btc8723b2ant_connect_notify(btcoexist, asso_type);
1587         else if (btcoexist->board_info.btdm_ant_num == 1)
1588             ex_btc8723b1ant_connect_notify(btcoexist, asso_type);
1589     } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1590         if (btcoexist->board_info.btdm_ant_num == 2)
1591             ex_btc8192e2ant_connect_notify(btcoexist, asso_type);
1592     }
1593 
1594     halbtc_normal_low_power(btcoexist);
1595 }
1596 
1597 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
1598                  enum rt_media_status media_status)
1599 {
1600     u8 status;
1601 
1602     if (!halbtc_is_bt_coexist_available(btcoexist))
1603         return;
1604     btcoexist->statistics.cnt_media_status_notify++;
1605     if (btcoexist->manual_control)
1606         return;
1607 
1608     if (RT_MEDIA_CONNECT == media_status)
1609         status = BTC_MEDIA_CONNECT;
1610     else
1611         status = BTC_MEDIA_DISCONNECT;
1612 
1613     halbtc_leave_low_power(btcoexist);
1614 
1615     if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1616         if (btcoexist->board_info.btdm_ant_num == 2)
1617             ex_btc8821a2ant_media_status_notify(btcoexist, status);
1618         else if (btcoexist->board_info.btdm_ant_num == 1)
1619             ex_btc8821a1ant_media_status_notify(btcoexist, status);
1620     } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1621         if (btcoexist->board_info.btdm_ant_num == 2)
1622             ex_btc8723b2ant_media_status_notify(btcoexist, status);
1623         else if (btcoexist->board_info.btdm_ant_num == 1)
1624             ex_btc8723b1ant_media_status_notify(btcoexist, status);
1625     } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1626         if (btcoexist->board_info.btdm_ant_num == 2)
1627             ex_btc8192e2ant_media_status_notify(btcoexist, status);
1628     }
1629 
1630     halbtc_normal_low_power(btcoexist);
1631 }
1632 
1633 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
1634 {
1635     u8 packet_type;
1636 
1637     if (!halbtc_is_bt_coexist_available(btcoexist))
1638         return;
1639     btcoexist->statistics.cnt_special_packet_notify++;
1640     if (btcoexist->manual_control)
1641         return;
1642 
1643     if (pkt_type == PACKET_DHCP) {
1644         packet_type = BTC_PACKET_DHCP;
1645     } else if (pkt_type == PACKET_EAPOL) {
1646         packet_type = BTC_PACKET_EAPOL;
1647     } else if (pkt_type == PACKET_ARP) {
1648         packet_type = BTC_PACKET_ARP;
1649     } else {
1650         packet_type = BTC_PACKET_UNKNOWN;
1651         return;
1652     }
1653 
1654     halbtc_leave_low_power(btcoexist);
1655 
1656     if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1657         if (btcoexist->board_info.btdm_ant_num == 2)
1658             ex_btc8821a2ant_special_packet_notify(btcoexist,
1659                                   packet_type);
1660         else if (btcoexist->board_info.btdm_ant_num == 1)
1661             ex_btc8821a1ant_special_packet_notify(btcoexist,
1662                                   packet_type);
1663     } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1664         if (btcoexist->board_info.btdm_ant_num == 2)
1665             ex_btc8723b2ant_special_packet_notify(btcoexist,
1666                                   packet_type);
1667         else if (btcoexist->board_info.btdm_ant_num == 1)
1668             ex_btc8723b1ant_special_packet_notify(btcoexist,
1669                                   packet_type);
1670     } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1671         if (btcoexist->board_info.btdm_ant_num == 2)
1672             ex_btc8192e2ant_special_packet_notify(btcoexist,
1673                                   packet_type);
1674     }
1675 
1676     halbtc_normal_low_power(btcoexist);
1677 }
1678 
1679 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
1680                  u8 *tmp_buf, u8 length)
1681 {
1682     if (!halbtc_is_bt_coexist_available(btcoexist))
1683         return;
1684     btcoexist->statistics.cnt_bt_info_notify++;
1685 
1686     halbtc_leave_low_power(btcoexist);
1687 
1688     if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1689         if (btcoexist->board_info.btdm_ant_num == 2)
1690             ex_btc8821a2ant_bt_info_notify(btcoexist, tmp_buf,
1691                                length);
1692         else if (btcoexist->board_info.btdm_ant_num == 1)
1693             ex_btc8821a1ant_bt_info_notify(btcoexist, tmp_buf,
1694                                length);
1695     } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1696         if (btcoexist->board_info.btdm_ant_num == 2)
1697             ex_btc8723b2ant_bt_info_notify(btcoexist, tmp_buf,
1698                                length);
1699         else if (btcoexist->board_info.btdm_ant_num == 1)
1700             ex_btc8723b1ant_bt_info_notify(btcoexist, tmp_buf,
1701                                length);
1702     } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1703         if (btcoexist->board_info.btdm_ant_num == 2)
1704             ex_btc8192e2ant_bt_info_notify(btcoexist, tmp_buf,
1705                                length);
1706     }
1707 
1708     halbtc_normal_low_power(btcoexist);
1709 }
1710 
1711 void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
1712 {
1713     if (!halbtc_is_bt_coexist_available(btcoexist))
1714         return;
1715 
1716     if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1717     } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1718         if (btcoexist->board_info.btdm_ant_num == 1)
1719             ex_btc8723b1ant_rf_status_notify(btcoexist, type);
1720     } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1721     }
1722 }
1723 
1724 void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
1725 {
1726     if (!halbtc_is_bt_coexist_available(btcoexist))
1727         return;
1728 
1729     if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1730         if (btcoexist->board_info.btdm_ant_num == 2)
1731             ex_btc8821a2ant_halt_notify(btcoexist);
1732         else if (btcoexist->board_info.btdm_ant_num == 1)
1733             ex_btc8821a1ant_halt_notify(btcoexist);
1734     } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1735         if (btcoexist->board_info.btdm_ant_num == 2)
1736             ex_btc8723b2ant_halt_notify(btcoexist);
1737         else if (btcoexist->board_info.btdm_ant_num == 1)
1738             ex_btc8723b1ant_halt_notify(btcoexist);
1739     } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1740         if (btcoexist->board_info.btdm_ant_num == 2)
1741             ex_btc8192e2ant_halt_notify(btcoexist);
1742     }
1743 
1744     btcoexist->binded = false;
1745 }
1746 
1747 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
1748 {
1749     if (!halbtc_is_bt_coexist_available(btcoexist))
1750         return;
1751 
1752     /* currently only 1ant we have to do the notification,
1753      * once pnp is notified to sleep state, we have to leave LPS that
1754      * we can sleep normally.
1755      */
1756 
1757     if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1758         if (btcoexist->board_info.btdm_ant_num == 1)
1759             ex_btc8723b1ant_pnp_notify(btcoexist, pnp_state);
1760         else if (btcoexist->board_info.btdm_ant_num == 2)
1761             ex_btc8723b2ant_pnp_notify(btcoexist, pnp_state);
1762     } else if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1763         if (btcoexist->board_info.btdm_ant_num == 1)
1764             ex_btc8821a1ant_pnp_notify(btcoexist, pnp_state);
1765         else if (btcoexist->board_info.btdm_ant_num == 2)
1766             ex_btc8821a2ant_pnp_notify(btcoexist, pnp_state);
1767     } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1768     }
1769 }
1770 
1771 void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist)
1772 {
1773     struct rtl_priv *rtlpriv = btcoexist->adapter;
1774 
1775     if (!halbtc_is_bt_coexist_available(btcoexist))
1776         return;
1777     btcoexist->statistics.cnt_coex_dm_switch++;
1778 
1779     halbtc_leave_low_power(btcoexist);
1780 
1781     if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1782         if (btcoexist->board_info.btdm_ant_num == 1) {
1783             btcoexist->stop_coex_dm = true;
1784             ex_btc8723b1ant_coex_dm_reset(btcoexist);
1785             exhalbtc_set_ant_num(rtlpriv,
1786                          BT_COEX_ANT_TYPE_DETECTED, 2);
1787             ex_btc8723b2ant_init_hwconfig(btcoexist);
1788             ex_btc8723b2ant_init_coex_dm(btcoexist);
1789             btcoexist->stop_coex_dm = false;
1790         }
1791     }
1792 
1793     halbtc_normal_low_power(btcoexist);
1794 }
1795 
1796 void exhalbtc_periodical(struct btc_coexist *btcoexist)
1797 {
1798     if (!halbtc_is_bt_coexist_available(btcoexist))
1799         return;
1800     btcoexist->statistics.cnt_periodical++;
1801 
1802     halbtc_leave_low_power(btcoexist);
1803 
1804     if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1805         if (btcoexist->board_info.btdm_ant_num == 2)
1806             ex_btc8821a2ant_periodical(btcoexist);
1807         else if (btcoexist->board_info.btdm_ant_num == 1)
1808             if (!halbtc_under_ips(btcoexist))
1809                 ex_btc8821a1ant_periodical(btcoexist);
1810     } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1811         if (btcoexist->board_info.btdm_ant_num == 2)
1812             ex_btc8723b2ant_periodical(btcoexist);
1813         else if (btcoexist->board_info.btdm_ant_num == 1)
1814             ex_btc8723b1ant_periodical(btcoexist);
1815     } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1816         if (btcoexist->board_info.btdm_ant_num == 2)
1817             ex_btc8192e2ant_periodical(btcoexist);
1818     }
1819 
1820     halbtc_normal_low_power(btcoexist);
1821 }
1822 
1823 void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
1824               u8 code, u8 len, u8 *data)
1825 {
1826     if (!halbtc_is_bt_coexist_available(btcoexist))
1827         return;
1828     btcoexist->statistics.cnt_dbg_ctrl++;
1829 
1830     halbtc_leave_low_power(btcoexist);
1831 
1832     halbtc_normal_low_power(btcoexist);
1833 }
1834 
1835 void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq,
1836                 u32 offset, u32 span, u32 seconds)
1837 {
1838     if (!halbtc_is_bt_coexist_available(btcoexist))
1839         return;
1840 }
1841 
1842 void exhalbtc_stack_update_profile_info(void)
1843 {
1844 }
1845 
1846 void exhalbtc_update_min_bt_rssi(struct btc_coexist *btcoexist, s8 bt_rssi)
1847 {
1848     if (!halbtc_is_bt_coexist_available(btcoexist))
1849         return;
1850 
1851     btcoexist->stack_info.min_bt_rssi = bt_rssi;
1852 }
1853 
1854 void exhalbtc_set_hci_version(struct btc_coexist *btcoexist, u16 hci_version)
1855 {
1856     if (!halbtc_is_bt_coexist_available(btcoexist))
1857         return;
1858 
1859     btcoexist->stack_info.hci_version = hci_version;
1860 }
1861 
1862 void exhalbtc_set_bt_patch_version(struct btc_coexist *btcoexist,
1863                    u16 bt_hci_version, u16 bt_patch_version)
1864 {
1865     if (!halbtc_is_bt_coexist_available(btcoexist))
1866         return;
1867 
1868     btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
1869     btcoexist->bt_info.bt_hci_ver = bt_hci_version;
1870 }
1871 
1872 void exhalbtc_set_chip_type(struct btc_coexist *btcoexist, u8 chip_type)
1873 {
1874     switch (chip_type) {
1875     default:
1876     case BT_2WIRE:
1877     case BT_ISSC_3WIRE:
1878     case BT_ACCEL:
1879     case BT_RTL8756:
1880         btcoexist->board_info.bt_chip_type = BTC_CHIP_UNDEF;
1881         break;
1882     case BT_CSR_BC4:
1883         btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
1884         break;
1885     case BT_CSR_BC8:
1886         btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
1887         break;
1888     case BT_RTL8723A:
1889         btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723A;
1890         break;
1891     case BT_RTL8821A:
1892         btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8821;
1893         break;
1894     case BT_RTL8723B:
1895         btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723B;
1896         break;
1897     }
1898 }
1899 
1900 void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num)
1901 {
1902     struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1903 
1904     if (!btcoexist)
1905         return;
1906 
1907     if (BT_COEX_ANT_TYPE_PG == type) {
1908         btcoexist->board_info.pg_ant_num = ant_num;
1909         btcoexist->board_info.btdm_ant_num = ant_num;
1910     } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1911         btcoexist->board_info.btdm_ant_num = ant_num;
1912     } else if (type == BT_COEX_ANT_TYPE_DETECTED) {
1913         btcoexist->board_info.btdm_ant_num = ant_num;
1914         if (rtlpriv->cfg->mod_params->ant_sel == 1)
1915             btcoexist->board_info.btdm_ant_pos =
1916                 BTC_ANTENNA_AT_AUX_PORT;
1917         else
1918             btcoexist->board_info.btdm_ant_pos =
1919                 BTC_ANTENNA_AT_MAIN_PORT;
1920     }
1921 }
1922 
1923 /* Currently used by 8723b only, S0 or S1 */
1924 void exhalbtc_set_single_ant_path(struct btc_coexist *btcoexist,
1925                   u8 single_ant_path)
1926 {
1927     btcoexist->board_info.single_ant_path = single_ant_path;
1928 }
1929 
1930 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist,
1931                    struct seq_file *m)
1932 {
1933     if (!halbtc_is_bt_coexist_available(btcoexist))
1934         return;
1935 
1936     halbtc_leave_low_power(btcoexist);
1937 
1938     if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1939         if (btcoexist->board_info.btdm_ant_num == 2)
1940             ex_btc8821a2ant_display_coex_info(btcoexist, m);
1941         else if (btcoexist->board_info.btdm_ant_num == 1)
1942             ex_btc8821a1ant_display_coex_info(btcoexist, m);
1943     } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1944         if (btcoexist->board_info.btdm_ant_num == 2)
1945             ex_btc8723b2ant_display_coex_info(btcoexist, m);
1946         else if (btcoexist->board_info.btdm_ant_num == 1)
1947             ex_btc8723b1ant_display_coex_info(btcoexist, m);
1948     } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1949         if (btcoexist->board_info.btdm_ant_num == 2)
1950             ex_btc8192e2ant_display_coex_info(btcoexist, m);
1951     }
1952 
1953     halbtc_normal_low_power(btcoexist);
1954 }
1955 
1956 void exhalbtc_switch_band_notify(struct btc_coexist *btcoexist, u8 type)
1957 {
1958     if (!halbtc_is_bt_coexist_available(btcoexist))
1959         return;
1960 
1961     if (btcoexist->manual_control)
1962         return;
1963 
1964     halbtc_leave_low_power(btcoexist);
1965 
1966     halbtc_normal_low_power(btcoexist);
1967 }
1968 
1969 void exhalbtc_switch_band_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1970                        u8 is_5g)
1971 {
1972 }