Merge tag 'pwm/for-4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry...
[linux-2.6-microblaze.git] / drivers / staging / rtlwifi / btcoexist / halbtcoutsrc.c
1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
5  *
6  * Contact Information:
7  * wlanfae <wlanfae@realtek.com>
8  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
9  * Hsinchu 300, Taiwan.
10  *
11  * Larry Finger <Larry.Finger@lwfinger.net>
12  *
13  ******************************************************************************/
14
15 #include "halbt_precomp.h"
16
17 /***************************************************
18  *              Debug related function
19  ***************************************************/
20
21 static const char *const gl_btc_wifi_bw_string[] = {
22         "11bg",
23         "HT20",
24         "HT40",
25         "HT80",
26         "HT160"
27 };
28
29 static const char *const gl_btc_wifi_freq_string[] = {
30         "2.4G",
31         "5G"
32 };
33
34 static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
35 {
36         if (!btcoexist->binded || NULL == btcoexist->adapter)
37                 return false;
38
39         return true;
40 }
41
42 static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
43 {
44         if (rtlpriv->link_info.busytraffic)
45                 return true;
46         else
47                 return false;
48 }
49
50 static void halbtc_dbg_init(void)
51 {
52 }
53
54 /***************************************************
55  *              helper function
56  ***************************************************/
57 static bool is_any_client_connect_to_ap(struct btc_coexist *btcoexist)
58 {
59         struct rtl_priv *rtlpriv = btcoexist->adapter;
60         struct rtl_mac *mac = rtl_mac(rtlpriv);
61         struct rtl_sta_info *drv_priv;
62         u8 cnt = 0;
63
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,
69                                             list) {
70                                 cnt++;
71                         }
72                 } else {
73                         spin_lock_bh(&rtlpriv->locks.entry_list_lock);
74                         list_for_each_entry(drv_priv, &rtlpriv->entry_list,
75                                             list) {
76                                 cnt++;
77                         }
78                         spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
79                 }
80         }
81         if (cnt > 0)
82                 return true;
83         else
84                 return false;
85 }
86
87 static bool halbtc_legacy(struct rtl_priv *adapter)
88 {
89         struct rtl_priv *rtlpriv = adapter;
90         struct rtl_mac *mac = rtl_mac(rtlpriv);
91
92         bool is_legacy = false;
93
94         if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G))
95                 is_legacy = true;
96
97         return is_legacy;
98 }
99
100 bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
101 {
102         struct rtl_priv *rtlpriv = adapter;
103
104         if (rtlpriv->link_info.tx_busy_traffic)
105                 return true;
106         else
107                 return false;
108 }
109
110 static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
111 {
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;
116
117         if (halbtc_legacy(rtlpriv)) {
118                 wifi_bw = BTC_WIFI_BW_LEGACY;
119         } else {
120                 switch (rtlphy->current_chan_bw) {
121                 case HT_CHANNEL_WIDTH_20:
122                         wifi_bw = BTC_WIFI_BW_HT20;
123                         break;
124                 case HT_CHANNEL_WIDTH_20_40:
125                         wifi_bw = BTC_WIFI_BW_HT40;
126                         break;
127                 case HT_CHANNEL_WIDTH_80:
128                         wifi_bw = BTC_WIFI_BW_HT80;
129                         break;
130                 }
131         }
132
133         return wifi_bw;
134 }
135
136 static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
137 {
138         struct rtl_priv *rtlpriv = btcoexist->adapter;
139         struct rtl_phy  *rtlphy = &rtlpriv->phy;
140         u8 chnl = 1;
141
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);
146         return chnl;
147 }
148
149 static u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv)
150 {
151         return rtlpriv->btcoexist.btc_info.single_ant_path;
152 }
153
154 static u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
155 {
156         return rtlpriv->btcoexist.btc_info.bt_type;
157 }
158
159 static u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
160 {
161         u8 num;
162
163         if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
164                 num = 2;
165         else
166                 num = 1;
167
168         return num;
169 }
170
171 static u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv)
172 {
173         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
174
175         return rtlhal->package_type;
176 }
177
178 static
179 u8 rtl_get_hwpg_rfe_type(struct rtl_priv *rtlpriv)
180 {
181         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
182
183         return rtlhal->rfe_type;
184 }
185
186 /* ************************************
187  *         Hal helper function
188  * ************************************
189  */
190 static
191 bool halbtc_is_hw_mailbox_exist(struct btc_coexist *btcoexist)
192 {
193         if (IS_HARDWARE_TYPE_8812(btcoexist->adapter))
194                 return false;
195         else
196                 return true;
197 }
198
199 static
200 bool halbtc_send_bt_mp_operation(struct btc_coexist *btcoexist, u8 op_code,
201                                  u8 *cmd, u32 len, unsigned long wait_ms)
202 {
203         struct rtl_priv *rtlpriv;
204         const u8 oper_ver = 0;
205         u8 req_num;
206
207         if (!halbtc_is_hw_mailbox_exist(btcoexist))
208                 return false;
209
210         if (wait_ms)    /* before h2c to avoid race condition */
211                 reinit_completion(&btcoexist->bt_mp_comp);
212
213         rtlpriv = btcoexist->adapter;
214
215         /*
216          * fill req_num by op_code, and rtl_btc_btmpinfo_notify() use it
217          * to know message type
218          */
219         switch (op_code) {
220         case BT_OP_GET_BT_VERSION:
221                 req_num = BT_SEQ_GET_BT_VERSION;
222                 break;
223         case BT_OP_GET_AFH_MAP_L:
224                 req_num = BT_SEQ_GET_AFH_MAP_L;
225                 break;
226         case BT_OP_GET_AFH_MAP_M:
227                 req_num = BT_SEQ_GET_AFH_MAP_M;
228                 break;
229         case BT_OP_GET_AFH_MAP_H:
230                 req_num = BT_SEQ_GET_AFH_MAP_H;
231                 break;
232         case BT_OP_GET_BT_COEX_SUPPORTED_FEATURE:
233                 req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_FEATURE;
234                 break;
235         case BT_OP_GET_BT_COEX_SUPPORTED_VERSION:
236                 req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_VERSION;
237                 break;
238         case BT_OP_GET_BT_ANT_DET_VAL:
239                 req_num = BT_SEQ_GET_BT_ANT_DET_VAL;
240                 break;
241         case BT_OP_GET_BT_BLE_SCAN_PARA:
242                 req_num = BT_SEQ_GET_BT_BLE_SCAN_PARA;
243                 break;
244         case BT_OP_GET_BT_BLE_SCAN_TYPE:
245                 req_num = BT_SEQ_GET_BT_BLE_SCAN_TYPE;
246                 break;
247         case BT_OP_WRITE_REG_ADDR:
248         case BT_OP_WRITE_REG_VALUE:
249         case BT_OP_READ_REG:
250         default:
251                 req_num = BT_SEQ_DONT_CARE;
252                 break;
253         }
254
255         cmd[0] |= (oper_ver & 0x0f);            /* Set OperVer */
256         cmd[0] |= ((req_num << 4) & 0xf0);      /* Set ReqNum */
257         cmd[1] = op_code;
258         rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, len, cmd);
259
260         /* wait? */
261         if (!wait_ms)
262                 return true;
263
264         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
265                  "btmpinfo wait req_num=%d wait=%ld\n", req_num, wait_ms);
266
267         if (in_interrupt())
268                 return false;
269
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);
274
275                 return false;   /* timeout */
276         }
277
278         return true;
279 }
280
281 static void halbtc_leave_lps(struct btc_coexist *btcoexist)
282 {
283         struct rtl_priv *rtlpriv;
284         bool ap_enable = false;
285
286         rtlpriv = btcoexist->adapter;
287
288         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
289                            &ap_enable);
290
291         if (ap_enable) {
292                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
293                          "%s()<--dont leave lps under AP mode\n", __func__);
294                 return;
295         }
296
297         btcoexist->bt_info.bt_ctrl_lps = true;
298         btcoexist->bt_info.bt_lps_on = false;
299         rtl_lps_leave(rtlpriv->mac80211.hw);
300 }
301
302 static void halbtc_enter_lps(struct btc_coexist *btcoexist)
303 {
304         struct rtl_priv *rtlpriv;
305         bool ap_enable = false;
306
307         rtlpriv = btcoexist->adapter;
308
309         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
310                            &ap_enable);
311
312         if (ap_enable) {
313                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
314                          "%s()<--dont enter lps under AP mode\n", __func__);
315                 return;
316         }
317
318         btcoexist->bt_info.bt_ctrl_lps = true;
319         btcoexist->bt_info.bt_lps_on = true;
320         rtl_lps_enter(rtlpriv->mac80211.hw);
321 }
322
323 static void halbtc_normal_lps(struct btc_coexist *btcoexist)
324 {
325         struct rtl_priv *rtlpriv;
326
327         rtlpriv = btcoexist->adapter;
328
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;
333         }
334 }
335
336 static void halbtc_leave_low_power(struct btc_coexist *btcoexist)
337 {
338 }
339
340 static void halbtc_normal_low_power(struct btc_coexist *btcoexist)
341 {
342 }
343
344 static void halbtc_disable_low_power(struct btc_coexist *btcoexist,
345                                      bool low_pwr_disable)
346 {
347         /* TODO: original/leave 32k low power */
348         btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable;
349 }
350
351 static void halbtc_aggregation_check(struct btc_coexist *btcoexist)
352 {
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;
357
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
361          */
362
363         cur_time = jiffies;
364         if (jiffies_to_msecs(cur_time - pre_time) <= 8000) {
365                 /* over 8 seconds you can execute this function again. */
366                 return;
367         }
368         pre_time = cur_time;
369
370         if (btcoexist->bt_info.reject_agg_pkt) {
371                 need_to_act = true;
372                 btcoexist->bt_info.pre_reject_agg_pkt =
373                         btcoexist->bt_info.reject_agg_pkt;
374         } else {
375                 if (btcoexist->bt_info.pre_reject_agg_pkt) {
376                         need_to_act = true;
377                         btcoexist->bt_info.pre_reject_agg_pkt =
378                                 btcoexist->bt_info.reject_agg_pkt;
379                 }
380
381                 if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
382                     btcoexist->bt_info.bt_ctrl_agg_buf_size) {
383                         need_to_act = true;
384                         btcoexist->bt_info.pre_bt_ctrl_agg_buf_size =
385                                 btcoexist->bt_info.bt_ctrl_agg_buf_size;
386                 }
387
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) {
391                                 need_to_act = true;
392                         }
393                         btcoexist->bt_info.pre_agg_buf_size =
394                                 btcoexist->bt_info.agg_buf_size;
395                 }
396
397                 if (need_to_act)
398                         rtl_rx_ampdu_apply(rtlpriv);
399         }
400 }
401
402 static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
403 {
404         u8 cmd_buffer[4] = {0};
405
406         if (btcoexist->bt_info.bt_real_fw_ver)
407                 goto label_done;
408
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,
411                                     cmd_buffer, 4, 200);
412
413 label_done:
414         return btcoexist->bt_info.bt_real_fw_ver;
415 }
416
417 static u32 halbtc_get_bt_coex_supported_feature(void *btc_context)
418 {
419         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
420         u8 cmd_buffer[4] = {0};
421
422         if (btcoexist->bt_info.bt_supported_feature)
423                 goto label_done;
424
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,
428                                     cmd_buffer, 4, 200);
429
430 label_done:
431         return btcoexist->bt_info.bt_supported_feature;
432 }
433
434 static u32 halbtc_get_bt_coex_supported_version(void *btc_context)
435 {
436         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
437         u8 cmd_buffer[4] = {0};
438
439         if (btcoexist->bt_info.bt_supported_version)
440                 goto label_done;
441
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,
445                                     cmd_buffer, 4, 200);
446
447 label_done:
448         return btcoexist->bt_info.bt_supported_version;
449 }
450
451 static u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist)
452 {
453         /* return value:
454          * [31:16] => connected port number
455          * [15:0]  => port connected bit define
456          */
457         struct rtl_priv *rtlpriv = btcoexist->adapter;
458         struct rtl_mac *mac = rtl_mac(rtlpriv);
459         u32 ret_val = 0;
460         u32 port_connected_status = 0, num_of_connected_port = 0;
461
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++;
466         }
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++;
471         }
472         /* TODO: P2P Connected Status */
473
474         ret_val = (num_of_connected_port << 16) | port_connected_status;
475
476         return ret_val;
477 }
478
479 static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv)
480 {
481         int undec_sm_pwdb = 0;
482
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;
488 }
489
490 static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
491 {
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;
501         bool tmp = false;
502         bool ret = true;
503
504         if (!halbtc_is_bt_coexist_available(btcoexist))
505                 return false;
506
507         switch (get_type) {
508         case BTC_GET_BL_HS_OPERATION:
509                 *bool_tmp = false;
510                 ret = false;
511                 break;
512         case BTC_GET_BL_HS_CONNECTING:
513                 *bool_tmp = false;
514                 ret = false;
515                 break;
516         case BTC_GET_BL_WIFI_CONNECTED:
517                 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
518                     rtlpriv->mac80211.link_state >= MAC80211_LINKED)
519                         tmp = true;
520                 if (is_any_client_connect_to_ap(btcoexist))
521                         tmp = true;
522                 *bool_tmp = tmp;
523                 break;
524         case BTC_GET_BL_WIFI_BUSY:
525                 if (halbtc_is_wifi_busy(rtlpriv))
526                         *bool_tmp = true;
527                 else
528                         *bool_tmp = false;
529                 break;
530         case BTC_GET_BL_WIFI_SCAN:
531                 if (mac->act_scanning)
532                         *bool_tmp = true;
533                 else
534                         *bool_tmp = false;
535                 break;
536         case BTC_GET_BL_WIFI_LINK:
537                 if (mac->link_state == MAC80211_LINKING)
538                         *bool_tmp = true;
539                 else
540                         *bool_tmp = false;
541                 break;
542         case BTC_GET_BL_WIFI_ROAM:
543                 if (mac->link_state == MAC80211_LINKING)
544                         *bool_tmp = true;
545                 else
546                         *bool_tmp = false;
547                 break;
548         case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
549                 *bool_tmp = rtlpriv->btcoexist.btc_info.in_4way;
550                 break;
551         case BTC_GET_BL_WIFI_UNDER_5G:
552                 if (rtlhal->current_bandtype == BAND_ON_5G)
553                         *bool_tmp = true;
554                 else
555                         *bool_tmp = false;
556                 break;
557         case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
558                 if (mac->opmode == NL80211_IFTYPE_AP)
559                         *bool_tmp = true;
560                 else
561                         *bool_tmp = false;
562                 break;
563         case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
564                 if (rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION)
565                         *bool_tmp = false;
566                 else
567                         *bool_tmp = true;
568                 break;
569         case BTC_GET_BL_WIFI_UNDER_B_MODE:
570                 if (rtlpriv->mac80211.mode == WIRELESS_MODE_B)
571                         *bool_tmp = true;
572                 else
573                         *bool_tmp = false;
574                 break;
575         case BTC_GET_BL_EXT_SWITCH:
576                 *bool_tmp = false;
577                 break;
578         case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
579                 *bool_tmp = false;
580                 break;
581         case BTC_GET_BL_IS_ASUS_8723B:
582                 *bool_tmp = false;
583                 break;
584         case BTC_GET_BL_RF4CE_CONNECTED:
585                 *bool_tmp = false;
586                 break;
587         case BTC_GET_S4_WIFI_RSSI:
588                 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
589                 break;
590         case BTC_GET_S4_HS_RSSI:
591                 *s32_tmp = 0;
592                 ret = false;
593                 break;
594         case BTC_GET_U4_WIFI_BW:
595                 *u32_tmp = halbtc_get_wifi_bw(btcoexist);
596                 break;
597         case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
598                 if (halbtc_is_wifi_uplink(rtlpriv))
599                         *u32_tmp = BTC_WIFI_TRAFFIC_TX;
600                 else
601                         *u32_tmp = BTC_WIFI_TRAFFIC_RX;
602                 break;
603         case BTC_GET_U4_WIFI_FW_VER:
604                 *u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion;
605                 break;
606         case BTC_GET_U4_WIFI_LINK_STATUS:
607                 *u32_tmp = halbtc_get_wifi_link_status(btcoexist);
608                 break;
609         case BTC_GET_U4_BT_PATCH_VER:
610                 *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
611                 break;
612         case BTC_GET_U4_VENDOR:
613                 *u32_tmp = BTC_VENDOR_OTHER;
614                 break;
615         case BTC_GET_U4_SUPPORTED_VERSION:
616                 *u32_tmp = halbtc_get_bt_coex_supported_version(btcoexist);
617                 break;
618         case BTC_GET_U4_SUPPORTED_FEATURE:
619                 *u32_tmp = halbtc_get_bt_coex_supported_feature(btcoexist);
620                 break;
621         case BTC_GET_U4_WIFI_IQK_TOTAL:
622                 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
623                                                                   "IQK_TOTAL");
624                 break;
625         case BTC_GET_U4_WIFI_IQK_OK:
626                 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
627                                                                   "IQK_OK");
628                 break;
629         case BTC_GET_U4_WIFI_IQK_FAIL:
630                 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
631                                                                   "IQK_FAIL");
632                 break;
633         case BTC_GET_U1_WIFI_DOT11_CHNL:
634                 *u8_tmp = rtlphy->current_channel;
635                 break;
636         case BTC_GET_U1_WIFI_CENTRAL_CHNL:
637                 *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
638                 break;
639         case BTC_GET_U1_WIFI_HS_CHNL:
640                 *u8_tmp = 0;
641                 ret = false;
642                 break;
643         case BTC_GET_U1_AP_NUM:
644                 *u8_tmp = rtlpriv->btcoexist.btc_info.ap_num;
645                 break;
646         case BTC_GET_U1_ANT_TYPE:
647                 *u8_tmp = (u8)BTC_ANT_TYPE_0;
648                 break;
649         case BTC_GET_U1_IOT_PEER:
650                 *u8_tmp = 0;
651                 break;
652
653                 /************* 1Ant **************/
654         case BTC_GET_U1_LPS_MODE:
655                 *u8_tmp = btcoexist->pwr_mode_val[0];
656                 break;
657
658         default:
659                 ret = false;
660                 break;
661         }
662
663         return ret;
664 }
665
666 static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
667 {
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;
672         bool ret = true;
673
674         if (!halbtc_is_bt_coexist_available(btcoexist))
675                 return false;
676
677         switch (set_type) {
678         /* set some bool type variables. */
679         case BTC_SET_BL_BT_DISABLE:
680                 btcoexist->bt_info.bt_disabled = *bool_tmp;
681                 break;
682         case BTC_SET_BL_BT_TRAFFIC_BUSY:
683                 btcoexist->bt_info.bt_busy = *bool_tmp;
684                 break;
685         case BTC_SET_BL_BT_LIMITED_DIG:
686                 btcoexist->bt_info.limited_dig = *bool_tmp;
687                 break;
688         case BTC_SET_BL_FORCE_TO_ROAM:
689                 btcoexist->bt_info.force_to_roam = *bool_tmp;
690                 break;
691         case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
692                 btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
693                 break;
694         case BTC_SET_BL_BT_CTRL_AGG_SIZE:
695                 btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp;
696                 break;
697         case BTC_SET_BL_INC_SCAN_DEV_NUM:
698                 btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
699                 break;
700         case BTC_SET_BL_BT_TX_RX_MASK:
701                 btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp;
702                 break;
703         case BTC_SET_BL_MIRACAST_PLUS_BT:
704                 btcoexist->bt_info.miracast_plus_bt = *bool_tmp;
705                 break;
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;
709                 break;
710         case BTC_SET_U1_AGG_BUF_SIZE:
711                 btcoexist->bt_info.agg_buf_size = *u8_tmp;
712                 break;
713
714         /* the following are some action which will be triggered */
715         case BTC_SET_ACT_GET_BT_RSSI:
716                 ret = false;
717                 break;
718         case BTC_SET_ACT_AGGREGATE_CTRL:
719                 halbtc_aggregation_check(btcoexist);
720                 break;
721
722         /* 1Ant */
723         case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
724                 btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
725                 break;
726         case BTC_SET_UI_SCAN_SIG_COMPENSATION:
727                 break;
728         case BTC_SET_U1_LPS_VAL:
729                 btcoexist->bt_info.lps_val = *u8_tmp;
730                 break;
731         case BTC_SET_U1_RPWM_VAL:
732                 btcoexist->bt_info.rpwm_val = *u8_tmp;
733                 break;
734         /* the following are some action which will be triggered  */
735         case BTC_SET_ACT_LEAVE_LPS:
736                 halbtc_leave_lps(btcoexist);
737                 break;
738         case BTC_SET_ACT_ENTER_LPS:
739                 halbtc_enter_lps(btcoexist);
740                 break;
741         case BTC_SET_ACT_NORMAL_LPS:
742                 halbtc_normal_lps(btcoexist);
743                 break;
744         case BTC_SET_ACT_DISABLE_LOW_POWER:
745                 halbtc_disable_low_power(btcoexist, *bool_tmp);
746                 break;
747         case BTC_SET_ACT_UPDATE_RAMASK:
748                 btcoexist->bt_info.ra_mask = *u32_tmp;
749                 break;
750         case BTC_SET_ACT_SEND_MIMO_PS:
751                 break;
752         case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
753                 break;
754         case BTC_SET_ACT_CTRL_BT_COEX:
755                 break;
756         case BTC_SET_ACT_CTRL_8723B_ANT:
757                 break;
758         default:
759                 break;
760         }
761
762         return ret;
763 }
764
765 static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist,
766                                            struct seq_file *m)
767 {
768 }
769
770 static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist,
771                                         struct seq_file *m)
772 {
773 }
774
775 static void halbtc_display_wifi_status(struct btc_coexist *btcoexist,
776                                        struct seq_file *m)
777 {
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;
789         u8 ap_num = 0;
790
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));
799
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);
806
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);
812
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",
818                    link, roam, scan);
819
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,
824                            &wifi_traffic_dir);
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,
828                            &wifi_under_b_mode);
829
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" :
837                                              "downlink")),
838                    ap_num);
839
840         /* power status  */
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",
846                    "Power Status",
847                    (dc_mode ? "DC mode" : "AC mode"),
848                    (under_ips ? ", IPS ON" : ""),
849                    (under_lps ? ", LPS ON" : ""),
850                    (low_power ? ", 32k" : ""));
851
852         seq_printf(m,
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);
860 }
861
862 /************************************************************
863  *              IO related function
864  ************************************************************/
865 static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
866 {
867         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
868         struct rtl_priv *rtlpriv = btcoexist->adapter;
869
870         return  rtl_read_byte(rtlpriv, reg_addr);
871 }
872
873 static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
874 {
875         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
876         struct rtl_priv *rtlpriv = btcoexist->adapter;
877
878         return  rtl_read_word(rtlpriv, reg_addr);
879 }
880
881 static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
882 {
883         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
884         struct rtl_priv *rtlpriv = btcoexist->adapter;
885
886         return  rtl_read_dword(rtlpriv, reg_addr);
887 }
888
889 static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data)
890 {
891         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
892         struct rtl_priv *rtlpriv = btcoexist->adapter;
893
894         rtl_write_byte(rtlpriv, reg_addr, data);
895 }
896
897 static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
898                                        u32 bit_mask, u8 data)
899 {
900         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
901         struct rtl_priv *rtlpriv = btcoexist->adapter;
902         u8 original_value, bit_shift = 0;
903         u8 i;
904
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)
909                                 break;
910                 }
911                 bit_shift = i;
912                 data = (original_value & (~bit_mask)) |
913                         ((data << bit_shift) & bit_mask);
914         }
915         rtl_write_byte(rtlpriv, reg_addr, data);
916 }
917
918 static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
919 {
920         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
921         struct rtl_priv *rtlpriv = btcoexist->adapter;
922
923         rtl_write_word(rtlpriv, reg_addr, data);
924 }
925
926 static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
927 {
928         struct btc_coexist *btcoexist =
929                 (struct btc_coexist *)bt_context;
930         struct rtl_priv *rtlpriv = btcoexist->adapter;
931
932         rtl_write_dword(rtlpriv, reg_addr, data);
933 }
934
935 static void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr,
936                                          u8 data)
937 {
938         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
939         struct rtl_priv *rtlpriv = btcoexist->adapter;
940
941         if (btcoexist->chip_interface == BTC_INTF_SDIO)
942                 ;
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);
947 }
948
949 static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
950                              u32 data)
951 {
952         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
953         struct rtl_priv *rtlpriv = btcoexist->adapter;
954
955         rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
956 }
957
958 static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
959 {
960         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
961         struct rtl_priv *rtlpriv = btcoexist->adapter;
962
963         return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
964 }
965
966 static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
967                              u32 bit_mask, u32 data)
968 {
969         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
970         struct rtl_priv *rtlpriv = btcoexist->adapter;
971
972         rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
973 }
974
975 static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
976                             u32 bit_mask)
977 {
978         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
979         struct rtl_priv *rtlpriv = btcoexist->adapter;
980
981         return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
982 }
983
984 static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
985                                 u32 cmd_len, u8 *cmd_buf)
986 {
987         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
988         struct rtl_priv *rtlpriv = btcoexist->adapter;
989
990         rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
991                                         cmd_len, cmd_buf);
992 }
993
994 static void halbtc_send_wifi_port_id_cmd(void *bt_context)
995 {
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 */
999
1000         rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x71, 1,
1001                                         cmd_buf);
1002 }
1003
1004 static void halbtc_set_default_port_id_cmd(void *bt_context)
1005 {
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;
1009
1010         if (!rtlpriv->cfg->ops->set_default_port_id_cmd)
1011                 return;
1012
1013         rtlpriv->cfg->ops->set_default_port_id_cmd(hw);
1014 }
1015
1016 static
1017 void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val)
1018 {
1019         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1020         u8 cmd_buffer1[4] = {0};
1021         u8 cmd_buffer2[4] = {0};
1022
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))
1027                 return;
1028
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);
1034 }
1035
1036 static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type,
1037                                    struct seq_file *m)
1038 {
1039         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1040
1041         switch (disp_type) {
1042         case BTC_DBG_DISP_COEX_STATISTICS:
1043                 halbtc_display_coex_statistics(btcoexist, m);
1044                 break;
1045         case BTC_DBG_DISP_BT_LINK_INFO:
1046                 halbtc_display_bt_link_info(btcoexist, m);
1047                 break;
1048         case BTC_DBG_DISP_WIFI_STATUS:
1049                 halbtc_display_wifi_status(btcoexist, m);
1050                 break;
1051         default:
1052                 break;
1053         }
1054 }
1055
1056 static u32 halbtc_get_bt_reg(void *btc_context, u8 reg_type, u32 offset)
1057 {
1058         return 0;
1059 }
1060
1061 static
1062 u32 halbtc_get_phydm_version(void *btc_context)
1063 {
1064         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1065         struct rtl_priv *rtlpriv = btcoexist->adapter;
1066
1067         if (rtlpriv->phydm.ops)
1068                 return rtlpriv->phydm.ops->phydm_get_version(rtlpriv);
1069
1070         return 0;
1071 }
1072
1073 static
1074 void halbtc_phydm_modify_ra_pcr_threshold(void *btc_context,
1075                                           u8 ra_offset_direction,
1076                                           u8 ra_threshold_offset)
1077 {
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;
1081
1082         if (phydm_ops)
1083                 phydm_ops->phydm_modify_ra_pcr_threshold(rtlpriv,
1084                                                          ra_offset_direction,
1085                                                          ra_threshold_offset);
1086 }
1087
1088 static
1089 u32 halbtc_phydm_query_phy_counter(void *btc_context, const char *info_type)
1090 {
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
1095          */
1096
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;
1100
1101         if (phydm_ops)
1102                 return phydm_ops->phydm_query_counter(rtlpriv, info_type);
1103
1104         return 0;
1105 }
1106
1107 static u8 halbtc_get_ant_det_val_from_bt(void *btc_context)
1108 {
1109         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1110         u8 cmd_buffer[4] = {0};
1111
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);
1115
1116         /* need wait completion to return correct value */
1117
1118         return btcoexist->bt_info.bt_ant_det_val;
1119 }
1120
1121 static u8 halbtc_get_ble_scan_type_from_bt(void *btc_context)
1122 {
1123         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1124         u8 cmd_buffer[4] = {0};
1125
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);
1129
1130         /* need wait completion to return correct value */
1131
1132         return btcoexist->bt_info.bt_ble_scan_type;
1133 }
1134
1135 static u32 halbtc_get_ble_scan_para_from_bt(void *btc_context, u8 scan_type)
1136 {
1137         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1138         u8 cmd_buffer[4] = {0};
1139
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);
1143
1144         /* need wait completion to return correct value */
1145
1146         return btcoexist->bt_info.bt_ble_scan_para;
1147 }
1148
1149 static bool halbtc_get_bt_afh_map_from_bt(void *btc_context, u8 map_type,
1150                                           u8 *afh_map)
1151 {
1152         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1153         u8 cmd_buffer[2] = {0};
1154         bool ret;
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);
1158
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);
1162         if (!ret)
1163                 goto exit;
1164
1165         *afh_map_l = btcoexist->bt_info.afh_map_l;
1166
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);
1170         if (!ret)
1171                 goto exit;
1172
1173         *afh_map_m = btcoexist->bt_info.afh_map_m;
1174
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);
1178         if (!ret)
1179                 goto exit;
1180
1181         *afh_map_h = btcoexist->bt_info.afh_map_h;
1182
1183 exit:
1184         return ret;
1185 }
1186
1187 /*****************************************************************
1188  *         Extern functions called by other module
1189  *****************************************************************/
1190 bool exhalbtc_initlize_variables(struct rtl_priv *rtlpriv)
1191 {
1192         struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1193
1194         if (!btcoexist)
1195                 return false;
1196
1197         halbtc_dbg_init();
1198
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;
1207
1208         btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
1209         btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
1210
1211         btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
1212         btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
1213
1214         btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
1215         btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
1216
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;
1221
1222         btcoexist->bt_info.bt_ctrl_buf_size = false;
1223         btcoexist->bt_info.agg_buf_size = 5;
1224
1225         btcoexist->bt_info.increase_scan_dev_num = false;
1226
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;
1242
1243         init_completion(&btcoexist->bt_mp_comp);
1244
1245         return true;
1246 }
1247
1248 bool exhalbtc_initlize_variables_wifi_only(struct rtl_priv *rtlpriv)
1249 {
1250         struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
1251         struct wifi_only_haldata *wifionly_haldata;
1252
1253         if (!wifionly_cfg)
1254                 return false;
1255
1256         wifionly_cfg->adapter = rtlpriv;
1257
1258         switch (rtlpriv->rtlhal.interface) {
1259         case INTF_PCI:
1260                 wifionly_cfg->chip_interface = WIFIONLY_INTF_PCI;
1261                 break;
1262         case INTF_USB:
1263                 wifionly_cfg->chip_interface = WIFIONLY_INTF_USB;
1264                 break;
1265         default:
1266                 wifionly_cfg->chip_interface = WIFIONLY_INTF_UNKNOWN;
1267                 break;
1268         }
1269
1270         wifionly_haldata = &wifionly_cfg->haldata_info;
1271
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;
1278
1279         return true;
1280 }
1281
1282 bool exhalbtc_bind_bt_coex_withadapter(void *adapter)
1283 {
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;
1287
1288         if (!btcoexist)
1289                 return false;
1290
1291         if (btcoexist->binded)
1292                 return false;
1293
1294         switch (rtlpriv->rtlhal.interface) {
1295         case INTF_PCI:
1296                 btcoexist->chip_interface = BTC_INTF_PCI;
1297                 break;
1298         case INTF_USB:
1299                 btcoexist->chip_interface = BTC_INTF_USB;
1300                 break;
1301         default:
1302                 btcoexist->chip_interface = BTC_INTF_UNKNOWN;
1303                 break;
1304         }
1305
1306         btcoexist->binded = true;
1307         btcoexist->statistics.cnt_bind++;
1308
1309         btcoexist->adapter = adapter;
1310
1311         btcoexist->stack_info.profile_notified = false;
1312
1313         btcoexist->bt_info.bt_ctrl_agg_buf_size = false;
1314         btcoexist->bt_info.agg_buf_size = 5;
1315
1316         btcoexist->bt_info.increase_scan_dev_num = false;
1317         btcoexist->bt_info.miracast_plus_bt = false;
1318
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);
1323
1324         /* set default antenna position to main  port */
1325         btcoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
1326
1327         single_ant_path = rtl_get_hwpg_single_ant_path(rtlpriv);
1328         exhalbtc_set_single_ant_path(btcoexist, single_ant_path);
1329
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;
1334         else
1335                 btcoexist->board_info.tfbga_package = true;
1336
1337         if (btcoexist->board_info.tfbga_package)
1338                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1339                          "[BTCoex], Package Type = TFBGA\n");
1340         else
1341                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1342                          "[BTCoex], Package Type = Non-TFBGA\n");
1343
1344         btcoexist->board_info.rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1345         btcoexist->board_info.ant_div_cfg = 0;
1346
1347         return true;
1348 }
1349
1350 void exhalbtc_power_on_setting(struct btc_coexist *btcoexist)
1351 {
1352         if (!halbtc_is_bt_coexist_available(btcoexist))
1353                 return;
1354
1355         btcoexist->statistics.cnt_power_on++;
1356
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);
1362         }
1363 }
1364
1365 void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist)
1366 {
1367         if (!halbtc_is_bt_coexist_available(btcoexist))
1368                 return;
1369
1370         btcoexist->statistics.cnt_pre_load_firmware++;
1371
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);
1377         }
1378 }
1379
1380 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only)
1381 {
1382         if (!halbtc_is_bt_coexist_available(btcoexist))
1383                 return;
1384
1385         btcoexist->statistics.cnt_init_hw_config++;
1386
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);
1392
1393                 halbtc_set_default_port_id_cmd(btcoexist);
1394                 halbtc_send_wifi_port_id_cmd(btcoexist);
1395         }
1396 }
1397
1398 void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg)
1399 {
1400         if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1401                 ex_hal8822b_wifi_only_hw_config(wifionly_cfg);
1402 }
1403
1404 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
1405 {
1406         if (!halbtc_is_bt_coexist_available(btcoexist))
1407                 return;
1408
1409         btcoexist->statistics.cnt_init_coex_dm++;
1410
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);
1416         }
1417
1418         btcoexist->initilized = true;
1419 }
1420
1421 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
1422 {
1423         u8 ips_type;
1424
1425         if (!halbtc_is_bt_coexist_available(btcoexist))
1426                 return;
1427         btcoexist->statistics.cnt_ips_notify++;
1428         if (btcoexist->manual_control)
1429                 return;
1430
1431         if (type == ERFOFF)
1432                 ips_type = BTC_IPS_ENTER;
1433         else
1434                 ips_type = BTC_IPS_LEAVE;
1435
1436         halbtc_leave_low_power(btcoexist);
1437
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);
1443         }
1444
1445         halbtc_normal_low_power(btcoexist);
1446 }
1447
1448 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
1449 {
1450         u8 lps_type;
1451
1452         if (!halbtc_is_bt_coexist_available(btcoexist))
1453                 return;
1454         btcoexist->statistics.cnt_lps_notify++;
1455         if (btcoexist->manual_control)
1456                 return;
1457
1458         if (type == EACTIVE)
1459                 lps_type = BTC_LPS_DISABLE;
1460         else
1461                 lps_type = BTC_LPS_ENABLE;
1462
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);
1468         }
1469 }
1470
1471 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
1472 {
1473         u8 scan_type;
1474
1475         if (!halbtc_is_bt_coexist_available(btcoexist))
1476                 return;
1477         btcoexist->statistics.cnt_scan_notify++;
1478         if (btcoexist->manual_control)
1479                 return;
1480
1481         if (type)
1482                 scan_type = BTC_SCAN_START;
1483         else
1484                 scan_type = BTC_SCAN_FINISH;
1485
1486         halbtc_leave_low_power(btcoexist);
1487
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);
1493         }
1494
1495         halbtc_normal_low_power(btcoexist);
1496 }
1497
1498 void exhalbtc_scan_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1499                                     u8 is_5g)
1500 {
1501         if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1502                 ex_hal8822b_wifi_only_scannotify(wifionly_cfg, is_5g);
1503 }
1504
1505 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
1506 {
1507         u8 asso_type;
1508
1509         if (!halbtc_is_bt_coexist_available(btcoexist))
1510                 return;
1511         btcoexist->statistics.cnt_connect_notify++;
1512         if (btcoexist->manual_control)
1513                 return;
1514
1515         if (action)
1516                 asso_type = BTC_ASSOCIATE_START;
1517         else
1518                 asso_type = BTC_ASSOCIATE_FINISH;
1519
1520         halbtc_leave_low_power(btcoexist);
1521
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);
1527         }
1528
1529         halbtc_normal_low_power(btcoexist);
1530 }
1531
1532 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
1533                                  enum rt_media_status media_status)
1534 {
1535         u8 status;
1536
1537         if (!halbtc_is_bt_coexist_available(btcoexist))
1538                 return;
1539         btcoexist->statistics.cnt_media_status_notify++;
1540         if (btcoexist->manual_control)
1541                 return;
1542
1543         if (media_status == RT_MEDIA_CONNECT)
1544                 status = BTC_MEDIA_CONNECT;
1545         else
1546                 status = BTC_MEDIA_DISCONNECT;
1547
1548         halbtc_leave_low_power(btcoexist);
1549
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);
1555         }
1556
1557         halbtc_normal_low_power(btcoexist);
1558 }
1559
1560 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
1561 {
1562         u8 packet_type;
1563
1564         if (!halbtc_is_bt_coexist_available(btcoexist))
1565                 return;
1566         btcoexist->statistics.cnt_special_packet_notify++;
1567         if (btcoexist->manual_control)
1568                 return;
1569
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;
1576         } else {
1577                 packet_type = BTC_PACKET_UNKNOWN;
1578                 return;
1579         }
1580
1581         halbtc_leave_low_power(btcoexist);
1582
1583         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1584                 if (btcoexist->board_info.btdm_ant_num == 1)
1585                         ex_btc8822b1ant_specific_packet_notify(btcoexist,
1586                                                                packet_type);
1587                 else if (btcoexist->board_info.btdm_ant_num == 2)
1588                         ex_btc8822b2ant_specific_packet_notify(btcoexist,
1589                                                                packet_type);
1590         }
1591
1592         halbtc_normal_low_power(btcoexist);
1593 }
1594
1595 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
1596                              u8 *tmp_buf, u8 length)
1597 {
1598         if (!halbtc_is_bt_coexist_available(btcoexist))
1599                 return;
1600         btcoexist->statistics.cnt_bt_info_notify++;
1601
1602         halbtc_leave_low_power(btcoexist);
1603
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,
1607                                                        length);
1608                 else if (btcoexist->board_info.btdm_ant_num == 2)
1609                         ex_btc8822b2ant_bt_info_notify(btcoexist, tmp_buf,
1610                                                        length);
1611         }
1612
1613         halbtc_normal_low_power(btcoexist);
1614 }
1615
1616 void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
1617 {
1618         if (!halbtc_is_bt_coexist_available(btcoexist))
1619                 return;
1620
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);
1626         }
1627 }
1628
1629 void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
1630 {
1631         if (!halbtc_is_bt_coexist_available(btcoexist))
1632                 return;
1633         btcoexist->statistics.cnt_stack_operation_notify++;
1634 }
1635
1636 void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
1637 {
1638         if (!halbtc_is_bt_coexist_available(btcoexist))
1639                 return;
1640
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);
1646         }
1647
1648         btcoexist->binded = false;
1649 }
1650
1651 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
1652 {
1653         if (!halbtc_is_bt_coexist_available(btcoexist))
1654                 return;
1655
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.
1659          */
1660
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);
1666         }
1667 }
1668
1669 void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist)
1670 {
1671         if (!halbtc_is_bt_coexist_available(btcoexist))
1672                 return;
1673         btcoexist->statistics.cnt_coex_dm_switch++;
1674
1675         halbtc_leave_low_power(btcoexist);
1676
1677         halbtc_normal_low_power(btcoexist);
1678 }
1679
1680 void exhalbtc_periodical(struct btc_coexist *btcoexist)
1681 {
1682         if (!halbtc_is_bt_coexist_available(btcoexist))
1683                 return;
1684         btcoexist->statistics.cnt_periodical++;
1685
1686         halbtc_leave_low_power(btcoexist);
1687
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);
1693         }
1694
1695         halbtc_normal_low_power(btcoexist);
1696 }
1697
1698 void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
1699                           u8 code, u8 len, u8 *data)
1700 {
1701         if (!halbtc_is_bt_coexist_available(btcoexist))
1702                 return;
1703         btcoexist->statistics.cnt_dbg_ctrl++;
1704
1705         halbtc_leave_low_power(btcoexist);
1706
1707         halbtc_normal_low_power(btcoexist);
1708 }
1709
1710 void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq,
1711                                 u32 offset, u32 span, u32 seconds)
1712 {
1713         if (!halbtc_is_bt_coexist_available(btcoexist))
1714                 return;
1715 }
1716
1717 void exhalbtc_stack_update_profile_info(void)
1718 {
1719 }
1720
1721 void exhalbtc_update_min_bt_rssi(struct btc_coexist *btcoexist, s8 bt_rssi)
1722 {
1723         if (!halbtc_is_bt_coexist_available(btcoexist))
1724                 return;
1725
1726         btcoexist->stack_info.min_bt_rssi = bt_rssi;
1727 }
1728
1729 void exhalbtc_set_hci_version(struct btc_coexist *btcoexist, u16 hci_version)
1730 {
1731         if (!halbtc_is_bt_coexist_available(btcoexist))
1732                 return;
1733
1734         btcoexist->stack_info.hci_version = hci_version;
1735 }
1736
1737 void exhalbtc_set_bt_patch_version(struct btc_coexist *btcoexist,
1738                                    u16 bt_hci_version, u16 bt_patch_version)
1739 {
1740         if (!halbtc_is_bt_coexist_available(btcoexist))
1741                 return;
1742
1743         btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
1744         btcoexist->bt_info.bt_hci_ver = bt_hci_version;
1745 }
1746
1747 void exhalbtc_set_chip_type(struct btc_coexist *btcoexist, u8 chip_type)
1748 {
1749         switch (chip_type) {
1750         default:
1751         case BT_2WIRE:
1752         case BT_ISSC_3WIRE:
1753         case BT_ACCEL:
1754         case BT_RTL8756:
1755                 btcoexist->board_info.bt_chip_type = BTC_CHIP_UNDEF;
1756                 break;
1757         case BT_CSR_BC4:
1758                 btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
1759                 break;
1760         case BT_CSR_BC8:
1761                 btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
1762                 break;
1763         case BT_RTL8723A:
1764                 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723A;
1765                 break;
1766         case BT_RTL8821A:
1767                 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8821;
1768                 break;
1769         case BT_RTL8723B:
1770                 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723B;
1771                 break;
1772         }
1773 }
1774
1775 void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num)
1776 {
1777         struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1778
1779         if (!btcoexist)
1780                 return;
1781
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;
1792                 else
1793                         btcoexist->board_info.btdm_ant_pos =
1794                                 BTC_ANTENNA_AT_MAIN_PORT;
1795         }
1796 }
1797
1798 /* Currently used by 8723b only, S0 or S1 */
1799 void exhalbtc_set_single_ant_path(struct btc_coexist *btcoexist,
1800                                   u8 single_ant_path)
1801 {
1802         btcoexist->board_info.single_ant_path = single_ant_path;
1803 }
1804
1805 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist,
1806                                    struct seq_file *m)
1807 {
1808         if (!halbtc_is_bt_coexist_available(btcoexist))
1809                 return;
1810
1811         halbtc_leave_low_power(btcoexist);
1812
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);
1818         }
1819
1820         halbtc_normal_low_power(btcoexist);
1821 }
1822
1823 void exhalbtc_switch_band_notify(struct btc_coexist *btcoexist, u8 type)
1824 {
1825         if (!halbtc_is_bt_coexist_available(btcoexist))
1826                 return;
1827
1828         if (btcoexist->manual_control)
1829                 return;
1830
1831         halbtc_leave_low_power(btcoexist);
1832
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);
1838         }
1839
1840         halbtc_normal_low_power(btcoexist);
1841 }
1842
1843 void exhalbtc_switch_band_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1844                                            u8 is_5g)
1845 {
1846         if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1847                 ex_hal8822b_wifi_only_switchbandnotify(wifionly_cfg, is_5g);
1848 }