GNU Linux-libre 4.19.286-gnu1
[releases.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         struct rtl_ps_ctl *ppsc;
285         bool ap_enable = false;
286
287         rtlpriv = btcoexist->adapter;
288         ppsc = rtl_psc(rtlpriv);
289
290         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
291                            &ap_enable);
292
293         if (ap_enable) {
294                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
295                          "%s()<--dont leave lps under AP mode\n", __func__);
296                 return;
297         }
298
299         btcoexist->bt_info.bt_ctrl_lps = true;
300         btcoexist->bt_info.bt_lps_on = false;
301         rtl_lps_leave(rtlpriv->mac80211.hw);
302 }
303
304 static void halbtc_enter_lps(struct btc_coexist *btcoexist)
305 {
306         struct rtl_priv *rtlpriv;
307         struct rtl_ps_ctl *ppsc;
308         bool ap_enable = false;
309
310         rtlpriv = btcoexist->adapter;
311         ppsc = rtl_psc(rtlpriv);
312
313         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
314                            &ap_enable);
315
316         if (ap_enable) {
317                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
318                          "%s()<--dont enter lps under AP mode\n", __func__);
319                 return;
320         }
321
322         btcoexist->bt_info.bt_ctrl_lps = true;
323         btcoexist->bt_info.bt_lps_on = true;
324         rtl_lps_enter(rtlpriv->mac80211.hw);
325 }
326
327 static void halbtc_normal_lps(struct btc_coexist *btcoexist)
328 {
329         struct rtl_priv *rtlpriv;
330
331         rtlpriv = btcoexist->adapter;
332
333         if (btcoexist->bt_info.bt_ctrl_lps) {
334                 btcoexist->bt_info.bt_lps_on = false;
335                 rtl_lps_leave(rtlpriv->mac80211.hw);
336                 btcoexist->bt_info.bt_ctrl_lps = false;
337         }
338 }
339
340 static void halbtc_leave_low_power(struct btc_coexist *btcoexist)
341 {
342 }
343
344 static void halbtc_normal_low_power(struct btc_coexist *btcoexist)
345 {
346 }
347
348 static void halbtc_disable_low_power(struct btc_coexist *btcoexist,
349                                      bool low_pwr_disable)
350 {
351         /* TODO: original/leave 32k low power */
352         btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable;
353 }
354
355 static void halbtc_aggregation_check(struct btc_coexist *btcoexist)
356 {
357         bool need_to_act = false;
358         static unsigned long pre_time;
359         unsigned long cur_time = 0;
360         struct rtl_priv *rtlpriv = btcoexist->adapter;
361
362         /* To void continuous deleteBA=>addBA=>deleteBA=>addBA
363          * This function is not allowed to continuous called
364          * It can only be called after 8 seconds
365          */
366
367         cur_time = jiffies;
368         if (jiffies_to_msecs(cur_time - pre_time) <= 8000) {
369                 /* over 8 seconds you can execute this function again. */
370                 return;
371         }
372         pre_time = cur_time;
373
374         if (btcoexist->bt_info.reject_agg_pkt) {
375                 need_to_act = true;
376                 btcoexist->bt_info.pre_reject_agg_pkt =
377                         btcoexist->bt_info.reject_agg_pkt;
378         } else {
379                 if (btcoexist->bt_info.pre_reject_agg_pkt) {
380                         need_to_act = true;
381                         btcoexist->bt_info.pre_reject_agg_pkt =
382                                 btcoexist->bt_info.reject_agg_pkt;
383                 }
384
385                 if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
386                     btcoexist->bt_info.bt_ctrl_agg_buf_size) {
387                         need_to_act = true;
388                         btcoexist->bt_info.pre_bt_ctrl_agg_buf_size =
389                                 btcoexist->bt_info.bt_ctrl_agg_buf_size;
390                 }
391
392                 if (btcoexist->bt_info.bt_ctrl_agg_buf_size) {
393                         if (btcoexist->bt_info.pre_agg_buf_size !=
394                             btcoexist->bt_info.agg_buf_size) {
395                                 need_to_act = true;
396                         }
397                         btcoexist->bt_info.pre_agg_buf_size =
398                                 btcoexist->bt_info.agg_buf_size;
399                 }
400
401                 if (need_to_act)
402                         rtl_rx_ampdu_apply(rtlpriv);
403         }
404 }
405
406 static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
407 {
408         u8 cmd_buffer[4] = {0};
409
410         if (btcoexist->bt_info.bt_real_fw_ver)
411                 goto label_done;
412
413         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
414         halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_VERSION,
415                                     cmd_buffer, 4, 200);
416
417 label_done:
418         return btcoexist->bt_info.bt_real_fw_ver;
419 }
420
421 static u32 halbtc_get_bt_coex_supported_feature(void *btc_context)
422 {
423         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
424         u8 cmd_buffer[4] = {0};
425
426         if (btcoexist->bt_info.bt_supported_feature)
427                 goto label_done;
428
429         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
430         halbtc_send_bt_mp_operation(btcoexist,
431                                     BT_OP_GET_BT_COEX_SUPPORTED_FEATURE,
432                                     cmd_buffer, 4, 200);
433
434 label_done:
435         return btcoexist->bt_info.bt_supported_feature;
436 }
437
438 static u32 halbtc_get_bt_coex_supported_version(void *btc_context)
439 {
440         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
441         u8 cmd_buffer[4] = {0};
442
443         if (btcoexist->bt_info.bt_supported_version)
444                 goto label_done;
445
446         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
447         halbtc_send_bt_mp_operation(btcoexist,
448                                     BT_OP_GET_BT_COEX_SUPPORTED_VERSION,
449                                     cmd_buffer, 4, 200);
450
451 label_done:
452         return btcoexist->bt_info.bt_supported_version;
453 }
454
455 static u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist)
456 {
457         /* return value:
458          * [31:16] => connected port number
459          * [15:0]  => port connected bit define
460          */
461         struct rtl_priv *rtlpriv = btcoexist->adapter;
462         struct rtl_mac *mac = rtl_mac(rtlpriv);
463         u32 ret_val = 0;
464         u32 port_connected_status = 0, num_of_connected_port = 0;
465
466         if (mac->opmode == NL80211_IFTYPE_STATION &&
467             mac->link_state >= MAC80211_LINKED) {
468                 port_connected_status |= WIFI_STA_CONNECTED;
469                 num_of_connected_port++;
470         }
471         /* AP & ADHOC & MESH */
472         if (is_any_client_connect_to_ap(btcoexist)) {
473                 port_connected_status |= WIFI_AP_CONNECTED;
474                 num_of_connected_port++;
475         }
476         /* TODO: P2P Connected Status */
477
478         ret_val = (num_of_connected_port << 16) | port_connected_status;
479
480         return ret_val;
481 }
482
483 static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv)
484 {
485         int undec_sm_pwdb = 0;
486
487         if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
488                 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
489         else /* associated entry pwdb */
490                 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
491         return undec_sm_pwdb;
492 }
493
494 static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
495 {
496         struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
497         struct rtl_priv *rtlpriv = btcoexist->adapter;
498         struct rtl_phy *rtlphy = &rtlpriv->phy;
499         struct rtl_mac *mac = rtl_mac(rtlpriv);
500         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
501         bool *bool_tmp = (bool *)out_buf;
502         int *s32_tmp = (int *)out_buf;
503         u32 *u32_tmp = (u32 *)out_buf;
504         u8 *u8_tmp = (u8 *)out_buf;
505         bool tmp = false;
506         bool ret = true;
507
508         if (!halbtc_is_bt_coexist_available(btcoexist))
509                 return false;
510
511         switch (get_type) {
512         case BTC_GET_BL_HS_OPERATION:
513                 *bool_tmp = false;
514                 ret = false;
515                 break;
516         case BTC_GET_BL_HS_CONNECTING:
517                 *bool_tmp = false;
518                 ret = false;
519                 break;
520         case BTC_GET_BL_WIFI_CONNECTED:
521                 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
522                     rtlpriv->mac80211.link_state >= MAC80211_LINKED)
523                         tmp = true;
524                 if (is_any_client_connect_to_ap(btcoexist))
525                         tmp = true;
526                 *bool_tmp = tmp;
527                 break;
528         case BTC_GET_BL_WIFI_BUSY:
529                 if (halbtc_is_wifi_busy(rtlpriv))
530                         *bool_tmp = true;
531                 else
532                         *bool_tmp = false;
533                 break;
534         case BTC_GET_BL_WIFI_SCAN:
535                 if (mac->act_scanning)
536                         *bool_tmp = true;
537                 else
538                         *bool_tmp = false;
539                 break;
540         case BTC_GET_BL_WIFI_LINK:
541                 if (mac->link_state == MAC80211_LINKING)
542                         *bool_tmp = true;
543                 else
544                         *bool_tmp = false;
545                 break;
546         case BTC_GET_BL_WIFI_ROAM:
547                 if (mac->link_state == MAC80211_LINKING)
548                         *bool_tmp = true;
549                 else
550                         *bool_tmp = false;
551                 break;
552         case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
553                 *bool_tmp = rtlpriv->btcoexist.btc_info.in_4way;
554                 break;
555         case BTC_GET_BL_WIFI_UNDER_5G:
556                 if (rtlhal->current_bandtype == BAND_ON_5G)
557                         *bool_tmp = true;
558                 else
559                         *bool_tmp = false;
560                 break;
561         case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
562                 if (mac->opmode == NL80211_IFTYPE_AP)
563                         *bool_tmp = true;
564                 else
565                         *bool_tmp = false;
566                 break;
567         case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
568                 if (rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION)
569                         *bool_tmp = false;
570                 else
571                         *bool_tmp = true;
572                 break;
573         case BTC_GET_BL_WIFI_UNDER_B_MODE:
574                 if (rtlpriv->mac80211.mode == WIRELESS_MODE_B)
575                         *bool_tmp = true;
576                 else
577                         *bool_tmp = false;
578                 break;
579         case BTC_GET_BL_EXT_SWITCH:
580                 *bool_tmp = false;
581                 break;
582         case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
583                 *bool_tmp = false;
584                 break;
585         case BTC_GET_BL_IS_ASUS_8723B:
586                 *bool_tmp = false;
587                 break;
588         case BTC_GET_BL_RF4CE_CONNECTED:
589                 *bool_tmp = false;
590                 break;
591         case BTC_GET_S4_WIFI_RSSI:
592                 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
593                 break;
594         case BTC_GET_S4_HS_RSSI:
595                 *s32_tmp = 0;
596                 ret = false;
597                 break;
598         case BTC_GET_U4_WIFI_BW:
599                 *u32_tmp = halbtc_get_wifi_bw(btcoexist);
600                 break;
601         case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
602                 if (halbtc_is_wifi_uplink(rtlpriv))
603                         *u32_tmp = BTC_WIFI_TRAFFIC_TX;
604                 else
605                         *u32_tmp = BTC_WIFI_TRAFFIC_RX;
606                 break;
607         case BTC_GET_U4_WIFI_FW_VER:
608                 *u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion;
609                 break;
610         case BTC_GET_U4_WIFI_LINK_STATUS:
611                 *u32_tmp = halbtc_get_wifi_link_status(btcoexist);
612                 break;
613         case BTC_GET_U4_BT_PATCH_VER:
614                 *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
615                 break;
616         case BTC_GET_U4_VENDOR:
617                 *u32_tmp = BTC_VENDOR_OTHER;
618                 break;
619         case BTC_GET_U4_SUPPORTED_VERSION:
620                 *u32_tmp = halbtc_get_bt_coex_supported_version(btcoexist);
621                 break;
622         case BTC_GET_U4_SUPPORTED_FEATURE:
623                 *u32_tmp = halbtc_get_bt_coex_supported_feature(btcoexist);
624                 break;
625         case BTC_GET_U4_WIFI_IQK_TOTAL:
626                 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
627                                                                   "IQK_TOTAL");
628                 break;
629         case BTC_GET_U4_WIFI_IQK_OK:
630                 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
631                                                                   "IQK_OK");
632                 break;
633         case BTC_GET_U4_WIFI_IQK_FAIL:
634                 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
635                                                                   "IQK_FAIL");
636                 break;
637         case BTC_GET_U1_WIFI_DOT11_CHNL:
638                 *u8_tmp = rtlphy->current_channel;
639                 break;
640         case BTC_GET_U1_WIFI_CENTRAL_CHNL:
641                 *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
642                 break;
643         case BTC_GET_U1_WIFI_HS_CHNL:
644                 *u8_tmp = 0;
645                 ret = false;
646                 break;
647         case BTC_GET_U1_AP_NUM:
648                 *u8_tmp = rtlpriv->btcoexist.btc_info.ap_num;
649                 break;
650         case BTC_GET_U1_ANT_TYPE:
651                 *u8_tmp = (u8)BTC_ANT_TYPE_0;
652                 break;
653         case BTC_GET_U1_IOT_PEER:
654                 *u8_tmp = 0;
655                 break;
656
657                 /************* 1Ant **************/
658         case BTC_GET_U1_LPS_MODE:
659                 *u8_tmp = btcoexist->pwr_mode_val[0];
660                 break;
661
662         default:
663                 ret = false;
664                 break;
665         }
666
667         return ret;
668 }
669
670 static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
671 {
672         struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
673         bool *bool_tmp = (bool *)in_buf;
674         u8 *u8_tmp = (u8 *)in_buf;
675         u32 *u32_tmp = (u32 *)in_buf;
676         bool ret = true;
677
678         if (!halbtc_is_bt_coexist_available(btcoexist))
679                 return false;
680
681         switch (set_type) {
682         /* set some bool type variables. */
683         case BTC_SET_BL_BT_DISABLE:
684                 btcoexist->bt_info.bt_disabled = *bool_tmp;
685                 break;
686         case BTC_SET_BL_BT_TRAFFIC_BUSY:
687                 btcoexist->bt_info.bt_busy = *bool_tmp;
688                 break;
689         case BTC_SET_BL_BT_LIMITED_DIG:
690                 btcoexist->bt_info.limited_dig = *bool_tmp;
691                 break;
692         case BTC_SET_BL_FORCE_TO_ROAM:
693                 btcoexist->bt_info.force_to_roam = *bool_tmp;
694                 break;
695         case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
696                 btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
697                 break;
698         case BTC_SET_BL_BT_CTRL_AGG_SIZE:
699                 btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp;
700                 break;
701         case BTC_SET_BL_INC_SCAN_DEV_NUM:
702                 btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
703                 break;
704         case BTC_SET_BL_BT_TX_RX_MASK:
705                 btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp;
706                 break;
707         case BTC_SET_BL_MIRACAST_PLUS_BT:
708                 btcoexist->bt_info.miracast_plus_bt = *bool_tmp;
709                 break;
710                 /* set some u1Byte type variables. */
711         case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
712                 btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
713                 break;
714         case BTC_SET_U1_AGG_BUF_SIZE:
715                 btcoexist->bt_info.agg_buf_size = *u8_tmp;
716                 break;
717
718         /* the following are some action which will be triggered */
719         case BTC_SET_ACT_GET_BT_RSSI:
720                 ret = false;
721                 break;
722         case BTC_SET_ACT_AGGREGATE_CTRL:
723                 halbtc_aggregation_check(btcoexist);
724                 break;
725
726         /* 1Ant */
727         case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
728                 btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
729                 break;
730         case BTC_SET_UI_SCAN_SIG_COMPENSATION:
731                 break;
732         case BTC_SET_U1_LPS_VAL:
733                 btcoexist->bt_info.lps_val = *u8_tmp;
734                 break;
735         case BTC_SET_U1_RPWM_VAL:
736                 btcoexist->bt_info.rpwm_val = *u8_tmp;
737                 break;
738         /* the following are some action which will be triggered  */
739         case BTC_SET_ACT_LEAVE_LPS:
740                 halbtc_leave_lps(btcoexist);
741                 break;
742         case BTC_SET_ACT_ENTER_LPS:
743                 halbtc_enter_lps(btcoexist);
744                 break;
745         case BTC_SET_ACT_NORMAL_LPS:
746                 halbtc_normal_lps(btcoexist);
747                 break;
748         case BTC_SET_ACT_DISABLE_LOW_POWER:
749                 halbtc_disable_low_power(btcoexist, *bool_tmp);
750                 break;
751         case BTC_SET_ACT_UPDATE_RAMASK:
752                 btcoexist->bt_info.ra_mask = *u32_tmp;
753                 break;
754         case BTC_SET_ACT_SEND_MIMO_PS:
755                 break;
756         case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
757                 break;
758         case BTC_SET_ACT_CTRL_BT_COEX:
759                 break;
760         case BTC_SET_ACT_CTRL_8723B_ANT:
761                 break;
762         default:
763                 break;
764         }
765
766         return ret;
767 }
768
769 static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist,
770                                            struct seq_file *m)
771 {
772 }
773
774 static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist,
775                                         struct seq_file *m)
776 {
777 }
778
779 static void halbtc_display_wifi_status(struct btc_coexist *btcoexist,
780                                        struct seq_file *m)
781 {
782         struct rtl_priv *rtlpriv = btcoexist->adapter;
783         s32 wifi_rssi = 0, bt_hs_rssi = 0;
784         bool scan = false, link = false, roam = false, wifi_busy = false;
785         bool wifi_under_b_mode = false, wifi_under_5g = false;
786         u32 wifi_bw = BTC_WIFI_BW_HT20;
787         u32 wifi_traffic_dir = BTC_WIFI_TRAFFIC_TX;
788         u32 wifi_freq = BTC_FREQ_2_4G;
789         u32 wifi_link_status = 0x0;
790         bool bt_hs_on = false, under_ips = false, under_lps = false;
791         bool low_power = false, dc_mode = false;
792         u8 wifi_chnl = 0, wifi_hs_chnl = 0;
793         u8 ap_num = 0;
794
795         wifi_link_status = halbtc_get_wifi_link_status(btcoexist);
796         seq_printf(m, "\n %-35s = %d/ %d/ %d/ %d/ %d",
797                    "STA/vWifi/HS/p2pGo/p2pGc",
798                    ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0),
799                    ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0),
800                    ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0),
801                    ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
802                    ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
803
804         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
805         btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_chnl);
806         btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
807         seq_printf(m, "\n %-35s = %d / %d(%d)",
808                    "Dot11 channel / HsChnl(High Speed)",
809                    wifi_chnl, wifi_hs_chnl, bt_hs_on);
810
811         btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
812         btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
813         seq_printf(m, "\n %-35s = %d/ %d",
814                    "Wifi rssi/ HS rssi",
815                    wifi_rssi - 100, bt_hs_rssi - 100);
816
817         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
818         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
819         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
820         seq_printf(m, "\n %-35s = %d/ %d/ %d ",
821                    "Wifi link/ roam/ scan",
822                    link, roam, scan);
823
824         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
825         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
826         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
827         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
828                            &wifi_traffic_dir);
829         btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
830         wifi_freq = (wifi_under_5g ? BTC_FREQ_5G : BTC_FREQ_2_4G);
831         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
832                            &wifi_under_b_mode);
833
834         seq_printf(m, "\n %-35s = %s / %s/ %s/ AP=%d ",
835                    "Wifi freq/ bw/ traffic",
836                    gl_btc_wifi_freq_string[wifi_freq],
837                    ((wifi_under_b_mode) ? "11b" :
838                     gl_btc_wifi_bw_string[wifi_bw]),
839                    ((!wifi_busy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX ==
840                                               wifi_traffic_dir) ? "uplink" :
841                                              "downlink")),
842                    ap_num);
843
844         /* power status  */
845         dc_mode = true; /*TODO*/
846         under_ips = rtlpriv->psc.inactive_pwrstate == ERFOFF ? 1 : 0;
847         under_lps = rtlpriv->psc.dot11_psmode == EACTIVE ? 0 : 1;
848         low_power = 0; /*TODO*/
849         seq_printf(m, "\n %-35s = %s%s%s%s",
850                    "Power Status",
851                    (dc_mode ? "DC mode" : "AC mode"),
852                    (under_ips ? ", IPS ON" : ""),
853                    (under_lps ? ", LPS ON" : ""),
854                    (low_power ? ", 32k" : ""));
855
856         seq_printf(m,
857                    "\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)",
858                    "Power mode cmd(lps/rpwm)",
859                    btcoexist->pwr_mode_val[0], btcoexist->pwr_mode_val[1],
860                    btcoexist->pwr_mode_val[2], btcoexist->pwr_mode_val[3],
861                    btcoexist->pwr_mode_val[4], btcoexist->pwr_mode_val[5],
862                    btcoexist->bt_info.lps_val,
863                    btcoexist->bt_info.rpwm_val);
864 }
865
866 /************************************************************
867  *              IO related function
868  ************************************************************/
869 static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
870 {
871         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
872         struct rtl_priv *rtlpriv = btcoexist->adapter;
873
874         return  rtl_read_byte(rtlpriv, reg_addr);
875 }
876
877 static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
878 {
879         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
880         struct rtl_priv *rtlpriv = btcoexist->adapter;
881
882         return  rtl_read_word(rtlpriv, reg_addr);
883 }
884
885 static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
886 {
887         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
888         struct rtl_priv *rtlpriv = btcoexist->adapter;
889
890         return  rtl_read_dword(rtlpriv, reg_addr);
891 }
892
893 static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data)
894 {
895         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
896         struct rtl_priv *rtlpriv = btcoexist->adapter;
897
898         rtl_write_byte(rtlpriv, reg_addr, data);
899 }
900
901 static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
902                                        u32 bit_mask, u8 data)
903 {
904         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
905         struct rtl_priv *rtlpriv = btcoexist->adapter;
906         u8 original_value, bit_shift = 0;
907         u8 i;
908
909         if (bit_mask != MASKDWORD) {/*if not "double word" write*/
910                 original_value = rtl_read_byte(rtlpriv, reg_addr);
911                 for (i = 0; i <= 7; i++) {
912                         if ((bit_mask >> i) & 0x1)
913                                 break;
914                 }
915                 bit_shift = i;
916                 data = (original_value & (~bit_mask)) |
917                         ((data << bit_shift) & bit_mask);
918         }
919         rtl_write_byte(rtlpriv, reg_addr, data);
920 }
921
922 static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
923 {
924         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
925         struct rtl_priv *rtlpriv = btcoexist->adapter;
926
927         rtl_write_word(rtlpriv, reg_addr, data);
928 }
929
930 static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
931 {
932         struct btc_coexist *btcoexist =
933                 (struct btc_coexist *)bt_context;
934         struct rtl_priv *rtlpriv = btcoexist->adapter;
935
936         rtl_write_dword(rtlpriv, reg_addr, data);
937 }
938
939 static void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr,
940                                          u8 data)
941 {
942         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
943         struct rtl_priv *rtlpriv = btcoexist->adapter;
944
945         if (btcoexist->chip_interface == BTC_INTF_SDIO)
946                 ;
947         else if (btcoexist->chip_interface == BTC_INTF_PCI)
948                 rtl_write_byte(rtlpriv, reg_addr, data);
949         else if (btcoexist->chip_interface == BTC_INTF_USB)
950                 rtl_write_byte(rtlpriv, reg_addr, data);
951 }
952
953 static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
954                              u32 data)
955 {
956         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
957         struct rtl_priv *rtlpriv = btcoexist->adapter;
958
959         rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
960 }
961
962 static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
963 {
964         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
965         struct rtl_priv *rtlpriv = btcoexist->adapter;
966
967         return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
968 }
969
970 static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
971                              u32 bit_mask, u32 data)
972 {
973         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
974         struct rtl_priv *rtlpriv = btcoexist->adapter;
975
976         rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
977 }
978
979 static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
980                             u32 bit_mask)
981 {
982         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
983         struct rtl_priv *rtlpriv = btcoexist->adapter;
984
985         return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
986 }
987
988 static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
989                                 u32 cmd_len, u8 *cmd_buf)
990 {
991         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
992         struct rtl_priv *rtlpriv = btcoexist->adapter;
993
994         rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
995                                         cmd_len, cmd_buf);
996 }
997
998 static void halbtc_send_wifi_port_id_cmd(void *bt_context)
999 {
1000         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1001         struct rtl_priv *rtlpriv = btcoexist->adapter;
1002         u8 cmd_buf[1] = {0};    /* port id [2:0] = 0 */
1003
1004         rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x71, 1,
1005                                         cmd_buf);
1006 }
1007
1008 static void halbtc_set_default_port_id_cmd(void *bt_context)
1009 {
1010         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1011         struct rtl_priv *rtlpriv = btcoexist->adapter;
1012         struct ieee80211_hw *hw = rtlpriv->mac80211.hw;
1013
1014         if (!rtlpriv->cfg->ops->set_default_port_id_cmd)
1015                 return;
1016
1017         rtlpriv->cfg->ops->set_default_port_id_cmd(hw);
1018 }
1019
1020 static
1021 void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val)
1022 {
1023         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1024         u8 cmd_buffer1[4] = {0};
1025         u8 cmd_buffer2[4] = {0};
1026
1027         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1028         *((__le16 *)&cmd_buffer1[2]) = cpu_to_le16((u16)set_val);
1029         if (!halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_VALUE,
1030                                          cmd_buffer1, 4, 200))
1031                 return;
1032
1033         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1034         cmd_buffer2[2] = reg_type;
1035         *((u8 *)&cmd_buffer2[3]) = (u8)offset;
1036         halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_ADDR,
1037                                     cmd_buffer2, 4, 200);
1038 }
1039
1040 static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type,
1041                                    struct seq_file *m)
1042 {
1043         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1044
1045         switch (disp_type) {
1046         case BTC_DBG_DISP_COEX_STATISTICS:
1047                 halbtc_display_coex_statistics(btcoexist, m);
1048                 break;
1049         case BTC_DBG_DISP_BT_LINK_INFO:
1050                 halbtc_display_bt_link_info(btcoexist, m);
1051                 break;
1052         case BTC_DBG_DISP_WIFI_STATUS:
1053                 halbtc_display_wifi_status(btcoexist, m);
1054                 break;
1055         default:
1056                 break;
1057         }
1058 }
1059
1060 static u32 halbtc_get_bt_reg(void *btc_context, u8 reg_type, u32 offset)
1061 {
1062         return 0;
1063 }
1064
1065 static
1066 u32 halbtc_get_phydm_version(void *btc_context)
1067 {
1068         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1069         struct rtl_priv *rtlpriv = btcoexist->adapter;
1070
1071         if (rtlpriv->phydm.ops)
1072                 return rtlpriv->phydm.ops->phydm_get_version(rtlpriv);
1073
1074         return 0;
1075 }
1076
1077 static
1078 void halbtc_phydm_modify_ra_pcr_threshold(void *btc_context,
1079                                           u8 ra_offset_direction,
1080                                           u8 ra_threshold_offset)
1081 {
1082         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1083         struct rtl_priv *rtlpriv = btcoexist->adapter;
1084         struct rtl_phydm_ops *phydm_ops = rtlpriv->phydm.ops;
1085
1086         if (phydm_ops)
1087                 phydm_ops->phydm_modify_ra_pcr_threshold(rtlpriv,
1088                                                          ra_offset_direction,
1089                                                          ra_threshold_offset);
1090 }
1091
1092 static
1093 u32 halbtc_phydm_query_phy_counter(void *btc_context, const char *info_type)
1094 {
1095         /* info_type may be strings below:
1096          * PHYDM_INFO_FA_OFDM, PHYDM_INFO_FA_CCK, PHYDM_INFO_CCA_OFDM,
1097          * PHYDM_INFO_CCA_CCK
1098          * IQK_TOTAL, IQK_OK, IQK_FAIL
1099          */
1100
1101         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1102         struct rtl_priv *rtlpriv = btcoexist->adapter;
1103         struct rtl_phydm_ops *phydm_ops = rtlpriv->phydm.ops;
1104
1105         if (phydm_ops)
1106                 return phydm_ops->phydm_query_counter(rtlpriv, info_type);
1107
1108         return 0;
1109 }
1110
1111 static u8 halbtc_get_ant_det_val_from_bt(void *btc_context)
1112 {
1113         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1114         u8 cmd_buffer[4] = {0};
1115
1116         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1117         halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_ANT_DET_VAL,
1118                                     cmd_buffer, 4, 200);
1119
1120         /* need wait completion to return correct value */
1121
1122         return btcoexist->bt_info.bt_ant_det_val;
1123 }
1124
1125 static u8 halbtc_get_ble_scan_type_from_bt(void *btc_context)
1126 {
1127         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1128         u8 cmd_buffer[4] = {0};
1129
1130         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1131         halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_TYPE,
1132                                     cmd_buffer, 4, 200);
1133
1134         /* need wait completion to return correct value */
1135
1136         return btcoexist->bt_info.bt_ble_scan_type;
1137 }
1138
1139 static u32 halbtc_get_ble_scan_para_from_bt(void *btc_context, u8 scan_type)
1140 {
1141         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1142         u8 cmd_buffer[4] = {0};
1143
1144         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1145         halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_PARA,
1146                                     cmd_buffer, 4, 200);
1147
1148         /* need wait completion to return correct value */
1149
1150         return btcoexist->bt_info.bt_ble_scan_para;
1151 }
1152
1153 static bool halbtc_get_bt_afh_map_from_bt(void *btc_context, u8 map_type,
1154                                           u8 *afh_map)
1155 {
1156         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1157         u8 cmd_buffer[2] = {0};
1158         bool ret;
1159         u32 *afh_map_l = (u32 *)afh_map;
1160         u32 *afh_map_m = (u32 *)(afh_map + 4);
1161         u16 *afh_map_h = (u16 *)(afh_map + 8);
1162
1163         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1164         ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_L,
1165                                           cmd_buffer, 2, 200);
1166         if (!ret)
1167                 goto exit;
1168
1169         *afh_map_l = btcoexist->bt_info.afh_map_l;
1170
1171         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1172         ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_M,
1173                                           cmd_buffer, 2, 200);
1174         if (!ret)
1175                 goto exit;
1176
1177         *afh_map_m = btcoexist->bt_info.afh_map_m;
1178
1179         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1180         ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_H,
1181                                           cmd_buffer, 2, 200);
1182         if (!ret)
1183                 goto exit;
1184
1185         *afh_map_h = btcoexist->bt_info.afh_map_h;
1186
1187 exit:
1188         return ret;
1189 }
1190
1191 /*****************************************************************
1192  *         Extern functions called by other module
1193  *****************************************************************/
1194 bool exhalbtc_initlize_variables(struct rtl_priv *rtlpriv)
1195 {
1196         struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1197
1198         if (!btcoexist)
1199                 return false;
1200
1201         halbtc_dbg_init();
1202
1203         btcoexist->btc_read_1byte = halbtc_read_1byte;
1204         btcoexist->btc_write_1byte = halbtc_write_1byte;
1205         btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
1206         btcoexist->btc_read_2byte = halbtc_read_2byte;
1207         btcoexist->btc_write_2byte = halbtc_write_2byte;
1208         btcoexist->btc_read_4byte = halbtc_read_4byte;
1209         btcoexist->btc_write_4byte = halbtc_write_4byte;
1210         btcoexist->btc_write_local_reg_1byte = halbtc_write_local_reg_1byte;
1211
1212         btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
1213         btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
1214
1215         btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
1216         btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
1217
1218         btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
1219         btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
1220
1221         btcoexist->btc_get = halbtc_get;
1222         btcoexist->btc_set = halbtc_set;
1223         btcoexist->btc_set_bt_reg = halbtc_set_bt_reg;
1224         btcoexist->btc_get_bt_reg = halbtc_get_bt_reg;
1225
1226         btcoexist->bt_info.bt_ctrl_buf_size = false;
1227         btcoexist->bt_info.agg_buf_size = 5;
1228
1229         btcoexist->bt_info.increase_scan_dev_num = false;
1230
1231         btcoexist->btc_get_bt_coex_supported_feature =
1232                                         halbtc_get_bt_coex_supported_feature;
1233         btcoexist->btc_get_bt_coex_supported_version =
1234                                         halbtc_get_bt_coex_supported_version;
1235         btcoexist->btc_get_bt_phydm_version = halbtc_get_phydm_version;
1236         btcoexist->btc_phydm_modify_ra_pcr_threshold =
1237                                         halbtc_phydm_modify_ra_pcr_threshold;
1238         btcoexist->btc_phydm_query_phy_counter = halbtc_phydm_query_phy_counter;
1239         btcoexist->btc_get_ant_det_val_from_bt = halbtc_get_ant_det_val_from_bt;
1240         btcoexist->btc_get_ble_scan_type_from_bt =
1241                                         halbtc_get_ble_scan_type_from_bt;
1242         btcoexist->btc_get_ble_scan_para_from_bt =
1243                                         halbtc_get_ble_scan_para_from_bt;
1244         btcoexist->btc_get_bt_afh_map_from_bt =
1245                                         halbtc_get_bt_afh_map_from_bt;
1246
1247         init_completion(&btcoexist->bt_mp_comp);
1248
1249         return true;
1250 }
1251
1252 bool exhalbtc_initlize_variables_wifi_only(struct rtl_priv *rtlpriv)
1253 {
1254         struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
1255         struct wifi_only_haldata *wifionly_haldata;
1256
1257         if (!wifionly_cfg)
1258                 return false;
1259
1260         wifionly_cfg->adapter = rtlpriv;
1261
1262         switch (rtlpriv->rtlhal.interface) {
1263         case INTF_PCI:
1264                 wifionly_cfg->chip_interface = BTC_INTF_PCI;
1265                 break;
1266         case INTF_USB:
1267                 wifionly_cfg->chip_interface = BTC_INTF_USB;
1268                 break;
1269         default:
1270                 wifionly_cfg->chip_interface = BTC_INTF_UNKNOWN;
1271                 break;
1272         }
1273
1274         wifionly_haldata = &wifionly_cfg->haldata_info;
1275
1276         wifionly_haldata->customer_id = CUSTOMER_NORMAL;
1277         wifionly_haldata->efuse_pg_antnum = rtl_get_hwpg_ant_num(rtlpriv);
1278         wifionly_haldata->efuse_pg_antpath =
1279                                         rtl_get_hwpg_single_ant_path(rtlpriv);
1280         wifionly_haldata->rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1281         wifionly_haldata->ant_div_cfg = 0;
1282
1283         return true;
1284 }
1285
1286 bool exhalbtc_bind_bt_coex_withadapter(void *adapter)
1287 {
1288         struct rtl_priv *rtlpriv = adapter;
1289         struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1290         u8 ant_num = 2, chip_type, single_ant_path = 0;
1291
1292         if (!btcoexist)
1293                 return false;
1294
1295         if (btcoexist->binded)
1296                 return false;
1297
1298         switch (rtlpriv->rtlhal.interface) {
1299         case INTF_PCI:
1300                 btcoexist->chip_interface = BTC_INTF_PCI;
1301                 break;
1302         case INTF_USB:
1303                 btcoexist->chip_interface = BTC_INTF_USB;
1304                 break;
1305         default:
1306                 btcoexist->chip_interface = BTC_INTF_UNKNOWN;
1307                 break;
1308         }
1309
1310         btcoexist->binded = true;
1311         btcoexist->statistics.cnt_bind++;
1312
1313         btcoexist->adapter = adapter;
1314
1315         btcoexist->stack_info.profile_notified = false;
1316
1317         btcoexist->bt_info.bt_ctrl_agg_buf_size = false;
1318         btcoexist->bt_info.agg_buf_size = 5;
1319
1320         btcoexist->bt_info.increase_scan_dev_num = false;
1321         btcoexist->bt_info.miracast_plus_bt = false;
1322
1323         chip_type = rtl_get_hwpg_bt_type(rtlpriv);
1324         exhalbtc_set_chip_type(btcoexist, chip_type);
1325         ant_num = rtl_get_hwpg_ant_num(rtlpriv);
1326         exhalbtc_set_ant_num(rtlpriv, BT_COEX_ANT_TYPE_PG, ant_num);
1327
1328         /* set default antenna position to main  port */
1329         btcoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
1330
1331         single_ant_path = rtl_get_hwpg_single_ant_path(rtlpriv);
1332         exhalbtc_set_single_ant_path(btcoexist, single_ant_path);
1333
1334         if (rtl_get_hwpg_package_type(rtlpriv) == 0)
1335                 btcoexist->board_info.tfbga_package = false;
1336         else if (rtl_get_hwpg_package_type(rtlpriv) == 1)
1337                 btcoexist->board_info.tfbga_package = false;
1338         else
1339                 btcoexist->board_info.tfbga_package = true;
1340
1341         if (btcoexist->board_info.tfbga_package)
1342                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1343                          "[BTCoex], Package Type = TFBGA\n");
1344         else
1345                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1346                          "[BTCoex], Package Type = Non-TFBGA\n");
1347
1348         btcoexist->board_info.rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1349         btcoexist->board_info.ant_div_cfg = 0;
1350
1351         return true;
1352 }
1353
1354 void exhalbtc_power_on_setting(struct btc_coexist *btcoexist)
1355 {
1356         if (!halbtc_is_bt_coexist_available(btcoexist))
1357                 return;
1358
1359         btcoexist->statistics.cnt_power_on++;
1360
1361         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1362                 if (btcoexist->board_info.btdm_ant_num == 1)
1363                         ex_btc8822b1ant_power_on_setting(btcoexist);
1364                 else if (btcoexist->board_info.btdm_ant_num == 2)
1365                         ex_btc8822b2ant_power_on_setting(btcoexist);
1366         }
1367 }
1368
1369 void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist)
1370 {
1371         if (!halbtc_is_bt_coexist_available(btcoexist))
1372                 return;
1373
1374         btcoexist->statistics.cnt_pre_load_firmware++;
1375
1376         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1377                 if (btcoexist->board_info.btdm_ant_num == 1)
1378                         ex_btc8822b1ant_pre_load_firmware(btcoexist);
1379                 else if (btcoexist->board_info.btdm_ant_num == 2)
1380                         ex_btc8822b2ant_pre_load_firmware(btcoexist);
1381         }
1382 }
1383
1384 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only)
1385 {
1386         if (!halbtc_is_bt_coexist_available(btcoexist))
1387                 return;
1388
1389         btcoexist->statistics.cnt_init_hw_config++;
1390
1391         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1392                 if (btcoexist->board_info.btdm_ant_num == 1)
1393                         ex_btc8822b1ant_init_hw_config(btcoexist, wifi_only);
1394                 else if (btcoexist->board_info.btdm_ant_num == 2)
1395                         ex_btc8822b2ant_init_hw_config(btcoexist, wifi_only);
1396
1397                 halbtc_set_default_port_id_cmd(btcoexist);
1398                 halbtc_send_wifi_port_id_cmd(btcoexist);
1399         }
1400 }
1401
1402 void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg)
1403 {
1404         if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1405                 ex_hal8822b_wifi_only_hw_config(wifionly_cfg);
1406 }
1407
1408 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
1409 {
1410         if (!halbtc_is_bt_coexist_available(btcoexist))
1411                 return;
1412
1413         btcoexist->statistics.cnt_init_coex_dm++;
1414
1415         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1416                 if (btcoexist->board_info.btdm_ant_num == 1)
1417                         ex_btc8822b1ant_init_coex_dm(btcoexist);
1418                 else if (btcoexist->board_info.btdm_ant_num == 2)
1419                         ex_btc8822b2ant_init_coex_dm(btcoexist);
1420         }
1421
1422         btcoexist->initilized = true;
1423 }
1424
1425 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
1426 {
1427         u8 ips_type;
1428
1429         if (!halbtc_is_bt_coexist_available(btcoexist))
1430                 return;
1431         btcoexist->statistics.cnt_ips_notify++;
1432         if (btcoexist->manual_control)
1433                 return;
1434
1435         if (type == ERFOFF)
1436                 ips_type = BTC_IPS_ENTER;
1437         else
1438                 ips_type = BTC_IPS_LEAVE;
1439
1440         halbtc_leave_low_power(btcoexist);
1441
1442         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1443                 if (btcoexist->board_info.btdm_ant_num == 1)
1444                         ex_btc8822b1ant_ips_notify(btcoexist, ips_type);
1445                 else if (btcoexist->board_info.btdm_ant_num == 2)
1446                         ex_btc8822b2ant_ips_notify(btcoexist, ips_type);
1447         }
1448
1449         halbtc_normal_low_power(btcoexist);
1450 }
1451
1452 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
1453 {
1454         u8 lps_type;
1455
1456         if (!halbtc_is_bt_coexist_available(btcoexist))
1457                 return;
1458         btcoexist->statistics.cnt_lps_notify++;
1459         if (btcoexist->manual_control)
1460                 return;
1461
1462         if (type == EACTIVE)
1463                 lps_type = BTC_LPS_DISABLE;
1464         else
1465                 lps_type = BTC_LPS_ENABLE;
1466
1467         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1468                 if (btcoexist->board_info.btdm_ant_num == 1)
1469                         ex_btc8822b1ant_lps_notify(btcoexist, lps_type);
1470                 else if (btcoexist->board_info.btdm_ant_num == 2)
1471                         ex_btc8822b2ant_lps_notify(btcoexist, lps_type);
1472         }
1473 }
1474
1475 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
1476 {
1477         u8 scan_type;
1478
1479         if (!halbtc_is_bt_coexist_available(btcoexist))
1480                 return;
1481         btcoexist->statistics.cnt_scan_notify++;
1482         if (btcoexist->manual_control)
1483                 return;
1484
1485         if (type)
1486                 scan_type = BTC_SCAN_START;
1487         else
1488                 scan_type = BTC_SCAN_FINISH;
1489
1490         halbtc_leave_low_power(btcoexist);
1491
1492         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1493                 if (btcoexist->board_info.btdm_ant_num == 1)
1494                         ex_btc8822b1ant_scan_notify(btcoexist, scan_type);
1495                 else if (btcoexist->board_info.btdm_ant_num == 2)
1496                         ex_btc8822b2ant_scan_notify(btcoexist, scan_type);
1497         }
1498
1499         halbtc_normal_low_power(btcoexist);
1500 }
1501
1502 void exhalbtc_scan_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1503                                     u8 is_5g)
1504 {
1505         if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1506                 ex_hal8822b_wifi_only_scannotify(wifionly_cfg, is_5g);
1507 }
1508
1509 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
1510 {
1511         u8 asso_type;
1512
1513         if (!halbtc_is_bt_coexist_available(btcoexist))
1514                 return;
1515         btcoexist->statistics.cnt_connect_notify++;
1516         if (btcoexist->manual_control)
1517                 return;
1518
1519         if (action)
1520                 asso_type = BTC_ASSOCIATE_START;
1521         else
1522                 asso_type = BTC_ASSOCIATE_FINISH;
1523
1524         halbtc_leave_low_power(btcoexist);
1525
1526         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1527                 if (btcoexist->board_info.btdm_ant_num == 1)
1528                         ex_btc8822b1ant_connect_notify(btcoexist, asso_type);
1529                 else if (btcoexist->board_info.btdm_ant_num == 2)
1530                         ex_btc8822b2ant_connect_notify(btcoexist, asso_type);
1531         }
1532
1533         halbtc_normal_low_power(btcoexist);
1534 }
1535
1536 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
1537                                  enum rt_media_status media_status)
1538 {
1539         u8 status;
1540
1541         if (!halbtc_is_bt_coexist_available(btcoexist))
1542                 return;
1543         btcoexist->statistics.cnt_media_status_notify++;
1544         if (btcoexist->manual_control)
1545                 return;
1546
1547         if (media_status == RT_MEDIA_CONNECT)
1548                 status = BTC_MEDIA_CONNECT;
1549         else
1550                 status = BTC_MEDIA_DISCONNECT;
1551
1552         halbtc_leave_low_power(btcoexist);
1553
1554         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1555                 if (btcoexist->board_info.btdm_ant_num == 1)
1556                         ex_btc8822b1ant_media_status_notify(btcoexist, status);
1557                 else if (btcoexist->board_info.btdm_ant_num == 2)
1558                         ex_btc8822b2ant_media_status_notify(btcoexist, status);
1559         }
1560
1561         halbtc_normal_low_power(btcoexist);
1562 }
1563
1564 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
1565 {
1566         u8 packet_type;
1567
1568         if (!halbtc_is_bt_coexist_available(btcoexist))
1569                 return;
1570         btcoexist->statistics.cnt_special_packet_notify++;
1571         if (btcoexist->manual_control)
1572                 return;
1573
1574         if (pkt_type == PACKET_DHCP) {
1575                 packet_type = BTC_PACKET_DHCP;
1576         } else if (pkt_type == PACKET_EAPOL) {
1577                 packet_type = BTC_PACKET_EAPOL;
1578         } else if (pkt_type == PACKET_ARP) {
1579                 packet_type = BTC_PACKET_ARP;
1580         } else {
1581                 packet_type = BTC_PACKET_UNKNOWN;
1582                 return;
1583         }
1584
1585         halbtc_leave_low_power(btcoexist);
1586
1587         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1588                 if (btcoexist->board_info.btdm_ant_num == 1)
1589                         ex_btc8822b1ant_specific_packet_notify(btcoexist,
1590                                                                packet_type);
1591                 else if (btcoexist->board_info.btdm_ant_num == 2)
1592                         ex_btc8822b2ant_specific_packet_notify(btcoexist,
1593                                                                packet_type);
1594         }
1595
1596         halbtc_normal_low_power(btcoexist);
1597 }
1598
1599 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
1600                              u8 *tmp_buf, u8 length)
1601 {
1602         if (!halbtc_is_bt_coexist_available(btcoexist))
1603                 return;
1604         btcoexist->statistics.cnt_bt_info_notify++;
1605
1606         halbtc_leave_low_power(btcoexist);
1607
1608         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1609                 if (btcoexist->board_info.btdm_ant_num == 1)
1610                         ex_btc8822b1ant_bt_info_notify(btcoexist, tmp_buf,
1611                                                        length);
1612                 else if (btcoexist->board_info.btdm_ant_num == 2)
1613                         ex_btc8822b2ant_bt_info_notify(btcoexist, tmp_buf,
1614                                                        length);
1615         }
1616
1617         halbtc_normal_low_power(btcoexist);
1618 }
1619
1620 void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
1621 {
1622         if (!halbtc_is_bt_coexist_available(btcoexist))
1623                 return;
1624
1625         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1626                 if (btcoexist->board_info.btdm_ant_num == 1)
1627                         ex_btc8822b1ant_rf_status_notify(btcoexist, type);
1628                 else if (btcoexist->board_info.btdm_ant_num == 2)
1629                         ex_btc8822b2ant_rf_status_notify(btcoexist, type);
1630         }
1631 }
1632
1633 void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
1634 {
1635         if (!halbtc_is_bt_coexist_available(btcoexist))
1636                 return;
1637         btcoexist->statistics.cnt_stack_operation_notify++;
1638 }
1639
1640 void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
1641 {
1642         if (!halbtc_is_bt_coexist_available(btcoexist))
1643                 return;
1644
1645         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1646                 if (btcoexist->board_info.btdm_ant_num == 1)
1647                         ex_btc8822b1ant_halt_notify(btcoexist);
1648                 else if (btcoexist->board_info.btdm_ant_num == 2)
1649                         ex_btc8822b2ant_halt_notify(btcoexist);
1650         }
1651
1652         btcoexist->binded = false;
1653 }
1654
1655 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
1656 {
1657         if (!halbtc_is_bt_coexist_available(btcoexist))
1658                 return;
1659
1660         /* currently only 1ant we have to do the notification,
1661          * once pnp is notified to sleep state, we have to leave LPS that
1662          * we can sleep normally.
1663          */
1664
1665         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1666                 if (btcoexist->board_info.btdm_ant_num == 1)
1667                         ex_btc8822b1ant_pnp_notify(btcoexist, pnp_state);
1668                 else if (btcoexist->board_info.btdm_ant_num == 2)
1669                         ex_btc8822b2ant_pnp_notify(btcoexist, pnp_state);
1670         }
1671 }
1672
1673 void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist)
1674 {
1675         if (!halbtc_is_bt_coexist_available(btcoexist))
1676                 return;
1677         btcoexist->statistics.cnt_coex_dm_switch++;
1678
1679         halbtc_leave_low_power(btcoexist);
1680
1681         halbtc_normal_low_power(btcoexist);
1682 }
1683
1684 void exhalbtc_periodical(struct btc_coexist *btcoexist)
1685 {
1686         if (!halbtc_is_bt_coexist_available(btcoexist))
1687                 return;
1688         btcoexist->statistics.cnt_periodical++;
1689
1690         halbtc_leave_low_power(btcoexist);
1691
1692         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1693                 if (btcoexist->board_info.btdm_ant_num == 1)
1694                         ex_btc8822b1ant_periodical(btcoexist);
1695                 else if (btcoexist->board_info.btdm_ant_num == 2)
1696                         ex_btc8822b2ant_periodical(btcoexist);
1697         }
1698
1699         halbtc_normal_low_power(btcoexist);
1700 }
1701
1702 void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
1703                           u8 code, u8 len, u8 *data)
1704 {
1705         if (!halbtc_is_bt_coexist_available(btcoexist))
1706                 return;
1707         btcoexist->statistics.cnt_dbg_ctrl++;
1708
1709         halbtc_leave_low_power(btcoexist);
1710
1711         halbtc_normal_low_power(btcoexist);
1712 }
1713
1714 void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq,
1715                                 u32 offset, u32 span, u32 seconds)
1716 {
1717         if (!halbtc_is_bt_coexist_available(btcoexist))
1718                 return;
1719 }
1720
1721 void exhalbtc_stack_update_profile_info(void)
1722 {
1723 }
1724
1725 void exhalbtc_update_min_bt_rssi(struct btc_coexist *btcoexist, s8 bt_rssi)
1726 {
1727         if (!halbtc_is_bt_coexist_available(btcoexist))
1728                 return;
1729
1730         btcoexist->stack_info.min_bt_rssi = bt_rssi;
1731 }
1732
1733 void exhalbtc_set_hci_version(struct btc_coexist *btcoexist, u16 hci_version)
1734 {
1735         if (!halbtc_is_bt_coexist_available(btcoexist))
1736                 return;
1737
1738         btcoexist->stack_info.hci_version = hci_version;
1739 }
1740
1741 void exhalbtc_set_bt_patch_version(struct btc_coexist *btcoexist,
1742                                    u16 bt_hci_version, u16 bt_patch_version)
1743 {
1744         if (!halbtc_is_bt_coexist_available(btcoexist))
1745                 return;
1746
1747         btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
1748         btcoexist->bt_info.bt_hci_ver = bt_hci_version;
1749 }
1750
1751 void exhalbtc_set_chip_type(struct btc_coexist *btcoexist, u8 chip_type)
1752 {
1753         switch (chip_type) {
1754         default:
1755         case BT_2WIRE:
1756         case BT_ISSC_3WIRE:
1757         case BT_ACCEL:
1758         case BT_RTL8756:
1759                 btcoexist->board_info.bt_chip_type = BTC_CHIP_UNDEF;
1760                 break;
1761         case BT_CSR_BC4:
1762                 btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
1763                 break;
1764         case BT_CSR_BC8:
1765                 btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
1766                 break;
1767         case BT_RTL8723A:
1768                 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723A;
1769                 break;
1770         case BT_RTL8821A:
1771                 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8821;
1772                 break;
1773         case BT_RTL8723B:
1774                 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723B;
1775                 break;
1776         }
1777 }
1778
1779 void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num)
1780 {
1781         struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1782
1783         if (!btcoexist)
1784                 return;
1785
1786         if (type == BT_COEX_ANT_TYPE_PG) {
1787                 btcoexist->board_info.pg_ant_num = ant_num;
1788                 btcoexist->board_info.btdm_ant_num = ant_num;
1789         } else if (type == BT_COEX_ANT_TYPE_ANTDIV) {
1790                 btcoexist->board_info.btdm_ant_num = ant_num;
1791         } else if (type == BT_COEX_ANT_TYPE_DETECTED) {
1792                 btcoexist->board_info.btdm_ant_num = ant_num;
1793                 if (rtlpriv->cfg->mod_params->ant_sel == 1)
1794                         btcoexist->board_info.btdm_ant_pos =
1795                                 BTC_ANTENNA_AT_AUX_PORT;
1796                 else
1797                         btcoexist->board_info.btdm_ant_pos =
1798                                 BTC_ANTENNA_AT_MAIN_PORT;
1799         }
1800 }
1801
1802 /* Currently used by 8723b only, S0 or S1 */
1803 void exhalbtc_set_single_ant_path(struct btc_coexist *btcoexist,
1804                                   u8 single_ant_path)
1805 {
1806         btcoexist->board_info.single_ant_path = single_ant_path;
1807 }
1808
1809 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist,
1810                                    struct seq_file *m)
1811 {
1812         if (!halbtc_is_bt_coexist_available(btcoexist))
1813                 return;
1814
1815         halbtc_leave_low_power(btcoexist);
1816
1817         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1818                 if (btcoexist->board_info.btdm_ant_num == 1)
1819                         ex_btc8822b1ant_display_coex_info(btcoexist, m);
1820                 else if (btcoexist->board_info.btdm_ant_num == 2)
1821                         ex_btc8822b2ant_display_coex_info(btcoexist, m);
1822         }
1823
1824         halbtc_normal_low_power(btcoexist);
1825 }
1826
1827 void exhalbtc_switch_band_notify(struct btc_coexist *btcoexist, u8 type)
1828 {
1829         if (!halbtc_is_bt_coexist_available(btcoexist))
1830                 return;
1831
1832         if (btcoexist->manual_control)
1833                 return;
1834
1835         halbtc_leave_low_power(btcoexist);
1836
1837         if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1838                 if (btcoexist->board_info.btdm_ant_num == 1)
1839                         ex_btc8822b1ant_switchband_notify(btcoexist, type);
1840                 else if (btcoexist->board_info.btdm_ant_num == 2)
1841                         ex_btc8822b2ant_switchband_notify(btcoexist, type);
1842         }
1843
1844         halbtc_normal_low_power(btcoexist);
1845 }
1846
1847 void exhalbtc_switch_band_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1848                                            u8 is_5g)
1849 {
1850         if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1851                 ex_hal8822b_wifi_only_switchbandnotify(wifionly_cfg, is_5g);
1852 }