Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
[linux-2.6-microblaze.git] / drivers / net / wireless / realtek / rtlwifi / btcoexist / halbtcoutsrc.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * The full GNU General Public License is included in this distribution in the
15  * file called LICENSE.
16  *
17  * Contact Information:
18  * wlanfae <wlanfae@realtek.com>
19  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20  * Hsinchu 300, Taiwan.
21  *
22  * Larry Finger <Larry.Finger@lwfinger.net>
23  *
24  ******************************************************************************/
25
26 #include "halbt_precomp.h"
27
28 /***************************************************
29  *              Debug related function
30  ***************************************************/
31
32 static const char *const gl_btc_wifi_bw_string[] = {
33         "11bg",
34         "HT20",
35         "HT40",
36         "HT80",
37         "HT160"
38 };
39
40 static const char *const gl_btc_wifi_freq_string[] = {
41         "2.4G",
42         "5G"
43 };
44
45 static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
46 {
47         if (!btcoexist->binded || NULL == btcoexist->adapter)
48                 return false;
49
50         return true;
51 }
52
53 static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
54 {
55         if (rtlpriv->link_info.busytraffic)
56                 return true;
57         else
58                 return false;
59 }
60
61 static void halbtc_dbg_init(void)
62 {
63 }
64
65 /***************************************************
66  *              helper function
67  ***************************************************/
68 static bool is_any_client_connect_to_ap(struct btc_coexist *btcoexist)
69 {
70         struct rtl_priv *rtlpriv = btcoexist->adapter;
71         struct rtl_mac *mac = rtl_mac(rtlpriv);
72         struct rtl_sta_info *drv_priv;
73         u8 cnt = 0;
74
75         if (mac->opmode == NL80211_IFTYPE_ADHOC ||
76             mac->opmode == NL80211_IFTYPE_MESH_POINT ||
77             mac->opmode == NL80211_IFTYPE_AP) {
78                 if (in_interrupt() > 0) {
79                         list_for_each_entry(drv_priv, &rtlpriv->entry_list,
80                                             list) {
81                                 cnt++;
82                         }
83                 } else {
84                         spin_lock_bh(&rtlpriv->locks.entry_list_lock);
85                         list_for_each_entry(drv_priv, &rtlpriv->entry_list,
86                                             list) {
87                                 cnt++;
88                         }
89                         spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
90                 }
91         }
92         if (cnt > 0)
93                 return true;
94         else
95                 return false;
96 }
97
98 static bool halbtc_legacy(struct rtl_priv *adapter)
99 {
100         struct rtl_priv *rtlpriv = adapter;
101         struct rtl_mac *mac = rtl_mac(rtlpriv);
102
103         bool is_legacy = false;
104
105         if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G))
106                 is_legacy = true;
107
108         return is_legacy;
109 }
110
111 bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
112 {
113         struct rtl_priv *rtlpriv = adapter;
114
115         if (rtlpriv->link_info.tx_busy_traffic)
116                 return true;
117         else
118                 return false;
119 }
120
121 static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
122 {
123         struct rtl_priv *rtlpriv = btcoexist->adapter;
124         struct rtl_phy *rtlphy = &rtlpriv->phy;
125         u32 wifi_bw = BTC_WIFI_BW_HT20;
126
127         if (halbtc_legacy(rtlpriv)) {
128                 wifi_bw = BTC_WIFI_BW_LEGACY;
129         } else {
130                 switch (rtlphy->current_chan_bw) {
131                 case HT_CHANNEL_WIDTH_20:
132                         wifi_bw = BTC_WIFI_BW_HT20;
133                         break;
134                 case HT_CHANNEL_WIDTH_20_40:
135                         wifi_bw = BTC_WIFI_BW_HT40;
136                         break;
137                 case HT_CHANNEL_WIDTH_80:
138                         wifi_bw = BTC_WIFI_BW_HT80;
139                         break;
140                 }
141         }
142
143         return wifi_bw;
144 }
145
146 static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
147 {
148         struct rtl_priv *rtlpriv = btcoexist->adapter;
149         struct rtl_phy  *rtlphy = &(rtlpriv->phy);
150         u8 chnl = 1;
151
152         if (rtlphy->current_channel != 0)
153                 chnl = rtlphy->current_channel;
154         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
155                  "static halbtc_get_wifi_central_chnl:%d\n", chnl);
156         return chnl;
157 }
158
159 static u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv)
160 {
161         return rtlpriv->btcoexist.btc_info.single_ant_path;
162 }
163
164 static u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
165 {
166         return rtlpriv->btcoexist.btc_info.bt_type;
167 }
168
169 static u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
170 {
171         u8 num;
172
173         if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
174                 num = 2;
175         else
176                 num = 1;
177
178         return num;
179 }
180
181 static u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv)
182 {
183         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
184
185         return rtlhal->package_type;
186 }
187
188 static
189 u8 rtl_get_hwpg_rfe_type(struct rtl_priv *rtlpriv)
190 {
191         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
192
193         return rtlhal->rfe_type;
194 }
195
196 static
197 bool halbtc_is_hw_mailbox_exist(struct btc_coexist *btcoexist)
198 {
199         if (IS_HARDWARE_TYPE_8812(btcoexist->adapter))
200                 return false;
201         else
202                 return true;
203 }
204
205 static
206 bool halbtc_send_bt_mp_operation(struct btc_coexist *btcoexist, u8 op_code,
207                                  u8 *cmd, u32 len, unsigned long wait_ms)
208 {
209         struct rtl_priv *rtlpriv;
210         const u8 oper_ver = 0;
211         u8 req_num;
212
213         if (!halbtc_is_hw_mailbox_exist(btcoexist))
214                 return false;
215
216         if (wait_ms)    /* before h2c to avoid race condition */
217                 reinit_completion(&btcoexist->bt_mp_comp);
218
219         rtlpriv = btcoexist->adapter;
220
221         /* fill req_num by op_code, and rtl_btc_btmpinfo_notify() use it
222          * to know message type
223          */
224         switch (op_code) {
225         case BT_OP_GET_BT_VERSION:
226                 req_num = BT_SEQ_GET_BT_VERSION;
227                 break;
228         case BT_OP_GET_AFH_MAP_L:
229                 req_num = BT_SEQ_GET_AFH_MAP_L;
230                 break;
231         case BT_OP_GET_AFH_MAP_M:
232                 req_num = BT_SEQ_GET_AFH_MAP_M;
233                 break;
234         case BT_OP_GET_AFH_MAP_H:
235                 req_num = BT_SEQ_GET_AFH_MAP_H;
236                 break;
237         case BT_OP_GET_BT_COEX_SUPPORTED_FEATURE:
238                 req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_FEATURE;
239                 break;
240         case BT_OP_GET_BT_COEX_SUPPORTED_VERSION:
241                 req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_VERSION;
242                 break;
243         case BT_OP_GET_BT_ANT_DET_VAL:
244                 req_num = BT_SEQ_GET_BT_ANT_DET_VAL;
245                 break;
246         case BT_OP_GET_BT_BLE_SCAN_PARA:
247                 req_num = BT_SEQ_GET_BT_BLE_SCAN_PARA;
248                 break;
249         case BT_OP_GET_BT_BLE_SCAN_TYPE:
250                 req_num = BT_SEQ_GET_BT_BLE_SCAN_TYPE;
251                 break;
252         case BT_OP_GET_BT_DEVICE_INFO:
253                 req_num = BT_SEQ_GET_BT_DEVICE_INFO;
254                 break;
255         case BT_OP_GET_BT_FORBIDDEN_SLOT_VAL:
256                 req_num = BT_SEQ_GET_BT_FORB_SLOT_VAL;
257                 break;
258         case BT_OP_WRITE_REG_ADDR:
259         case BT_OP_WRITE_REG_VALUE:
260         case BT_OP_READ_REG:
261         default:
262                 req_num = BT_SEQ_DONT_CARE;
263                 break;
264         }
265
266         cmd[0] |= (oper_ver & 0x0f);            /* Set OperVer */
267         cmd[0] |= ((req_num << 4) & 0xf0);      /* Set ReqNum */
268         cmd[1] = op_code;
269         rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, len, cmd);
270
271         /* wait? */
272         if (!wait_ms)
273                 return true;
274
275         RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
276                  "btmpinfo wait req_num=%d wait=%ld\n", req_num, wait_ms);
277
278         if (in_interrupt())
279                 return false;
280
281         if (wait_for_completion_timeout(&btcoexist->bt_mp_comp,
282                                         msecs_to_jiffies(wait_ms)) == 0) {
283                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
284                          "btmpinfo wait (req_num=%d) timeout\n", req_num);
285
286                 return false;   /* timeout */
287         }
288
289         return true;
290 }
291
292 static void halbtc_leave_lps(struct btc_coexist *btcoexist)
293 {
294         struct rtl_priv *rtlpriv;
295         bool ap_enable = false;
296
297         rtlpriv = btcoexist->adapter;
298
299         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
300                            &ap_enable);
301
302         if (ap_enable) {
303                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
304                          "%s()<--dont leave lps under AP mode\n", __func__);
305                 return;
306         }
307
308         btcoexist->bt_info.bt_ctrl_lps = true;
309         btcoexist->bt_info.bt_lps_on = false;
310         rtl_lps_leave(rtlpriv->mac80211.hw);
311 }
312
313 static void halbtc_enter_lps(struct btc_coexist *btcoexist)
314 {
315         struct rtl_priv *rtlpriv;
316         bool ap_enable = false;
317
318         rtlpriv = btcoexist->adapter;
319
320         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
321                            &ap_enable);
322
323         if (ap_enable) {
324                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
325                          "%s()<--dont enter lps under AP mode\n", __func__);
326                 return;
327         }
328
329         btcoexist->bt_info.bt_ctrl_lps = true;
330         btcoexist->bt_info.bt_lps_on = true;
331         rtl_lps_enter(rtlpriv->mac80211.hw);
332 }
333
334 static void halbtc_normal_lps(struct btc_coexist *btcoexist)
335 {
336         struct rtl_priv *rtlpriv;
337
338         rtlpriv = btcoexist->adapter;
339
340         if (btcoexist->bt_info.bt_ctrl_lps) {
341                 btcoexist->bt_info.bt_lps_on = false;
342                 rtl_lps_leave(rtlpriv->mac80211.hw);
343                 btcoexist->bt_info.bt_ctrl_lps = false;
344         }
345 }
346
347 static void halbtc_pre_normal_lps(struct btc_coexist *btcoexist)
348 {
349         struct rtl_priv *rtlpriv = btcoexist->adapter;
350
351         if (btcoexist->bt_info.bt_ctrl_lps) {
352                 btcoexist->bt_info.bt_lps_on = false;
353                 rtl_lps_leave(rtlpriv->mac80211.hw);
354         }
355 }
356
357 static void halbtc_post_normal_lps(struct btc_coexist *btcoexist)
358 {
359         if (btcoexist->bt_info.bt_ctrl_lps)
360                 btcoexist->bt_info.bt_ctrl_lps = false;
361 }
362
363 static void halbtc_leave_low_power(struct btc_coexist *btcoexist)
364 {
365 }
366
367 static void halbtc_normal_low_power(struct btc_coexist *btcoexist)
368 {
369 }
370
371 static void halbtc_disable_low_power(struct btc_coexist *btcoexist,
372                                      bool low_pwr_disable)
373 {
374         /* TODO: original/leave 32k low power */
375         btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable;
376 }
377
378 static void halbtc_aggregation_check(struct btc_coexist *btcoexist)
379 {
380         bool need_to_act = false;
381         static unsigned long pre_time;
382         unsigned long cur_time = 0;
383         struct rtl_priv *rtlpriv = btcoexist->adapter;
384
385         /* To void continuous deleteBA=>addBA=>deleteBA=>addBA
386          * This function is not allowed to continuous called
387          * It can only be called after 8 seconds
388          */
389
390         cur_time = jiffies;
391         if (jiffies_to_msecs(cur_time - pre_time) <= 8000) {
392                 /* over 8 seconds you can execute this function again. */
393                 return;
394         }
395         pre_time = cur_time;
396
397         if (btcoexist->bt_info.reject_agg_pkt) {
398                 need_to_act = true;
399                 btcoexist->bt_info.pre_reject_agg_pkt =
400                         btcoexist->bt_info.reject_agg_pkt;
401         } else {
402                 if (btcoexist->bt_info.pre_reject_agg_pkt) {
403                         need_to_act = true;
404                         btcoexist->bt_info.pre_reject_agg_pkt =
405                                 btcoexist->bt_info.reject_agg_pkt;
406                 }
407
408                 if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
409                     btcoexist->bt_info.bt_ctrl_agg_buf_size) {
410                         need_to_act = true;
411                         btcoexist->bt_info.pre_bt_ctrl_agg_buf_size =
412                                 btcoexist->bt_info.bt_ctrl_agg_buf_size;
413                 }
414
415                 if (btcoexist->bt_info.bt_ctrl_agg_buf_size) {
416                         if (btcoexist->bt_info.pre_agg_buf_size !=
417                             btcoexist->bt_info.agg_buf_size) {
418                                 need_to_act = true;
419                         }
420                         btcoexist->bt_info.pre_agg_buf_size =
421                                 btcoexist->bt_info.agg_buf_size;
422                 }
423
424                 if (need_to_act)
425                         rtl_rx_ampdu_apply(rtlpriv);
426         }
427 }
428
429 static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
430 {
431         u8 cmd_buffer[4] = {0};
432
433         if (btcoexist->bt_info.bt_real_fw_ver)
434                 goto label_done;
435
436         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
437         halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_VERSION,
438                                     cmd_buffer, 4, 200);
439
440 label_done:
441         return btcoexist->bt_info.bt_real_fw_ver;
442 }
443
444 static u32 halbtc_get_bt_coex_supported_feature(void *btc_context)
445 {
446         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
447         u8 cmd_buffer[4] = {0};
448
449         if (btcoexist->bt_info.bt_supported_feature)
450                 goto label_done;
451
452         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
453         halbtc_send_bt_mp_operation(btcoexist,
454                                     BT_OP_GET_BT_COEX_SUPPORTED_FEATURE,
455                                     cmd_buffer, 4, 200);
456
457 label_done:
458         return btcoexist->bt_info.bt_supported_feature;
459 }
460
461 static u32 halbtc_get_bt_coex_supported_version(void *btc_context)
462 {
463         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
464         u8 cmd_buffer[4] = {0};
465
466         if (btcoexist->bt_info.bt_supported_version)
467                 goto label_done;
468
469         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
470         halbtc_send_bt_mp_operation(btcoexist,
471                                     BT_OP_GET_BT_COEX_SUPPORTED_VERSION,
472                                     cmd_buffer, 4, 200);
473
474 label_done:
475         return btcoexist->bt_info.bt_supported_version;
476 }
477
478 static u32 halbtc_get_bt_device_info(void *btc_context)
479 {
480         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
481         u8 cmd_buffer[4] = {0};
482
483         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
484         halbtc_send_bt_mp_operation(btcoexist,
485                                     BT_OP_GET_BT_DEVICE_INFO,
486                                     cmd_buffer, 4, 200);
487
488         return btcoexist->bt_info.bt_device_info;
489 }
490
491 static u32 halbtc_get_bt_forbidden_slot_val(void *btc_context)
492 {
493         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
494         u8 cmd_buffer[4] = {0};
495
496         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
497         halbtc_send_bt_mp_operation(btcoexist,
498                                     BT_OP_GET_BT_FORBIDDEN_SLOT_VAL,
499                                     cmd_buffer, 4, 200);
500
501         return btcoexist->bt_info.bt_forb_slot_val;
502 }
503
504 static u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist)
505 {
506         /* return value:
507          * [31:16] => connected port number
508          * [15:0]  => port connected bit define
509          */
510         struct rtl_priv *rtlpriv = btcoexist->adapter;
511         struct rtl_mac *mac = rtl_mac(rtlpriv);
512         u32 ret_val = 0;
513         u32 port_connected_status = 0, num_of_connected_port = 0;
514
515         if (mac->opmode == NL80211_IFTYPE_STATION &&
516             mac->link_state >= MAC80211_LINKED) {
517                 port_connected_status |= WIFI_STA_CONNECTED;
518                 num_of_connected_port++;
519         }
520         /* AP & ADHOC & MESH */
521         if (is_any_client_connect_to_ap(btcoexist)) {
522                 port_connected_status |= WIFI_AP_CONNECTED;
523                 num_of_connected_port++;
524         }
525         /* TODO: P2P Connected Status */
526
527         ret_val = (num_of_connected_port << 16) | port_connected_status;
528
529         return ret_val;
530 }
531
532 static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv)
533 {
534         int undec_sm_pwdb = 0;
535
536         if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
537                 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
538         else /* associated entry pwdb */
539                 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
540         return undec_sm_pwdb;
541 }
542
543 static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
544 {
545         struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
546         struct rtl_priv *rtlpriv = btcoexist->adapter;
547         struct rtl_phy *rtlphy = &(rtlpriv->phy);
548         struct rtl_mac *mac = rtl_mac(rtlpriv);
549         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
550         bool *bool_tmp = (bool *)out_buf;
551         int *s32_tmp = (int *)out_buf;
552         u32 *u32_tmp = (u32 *)out_buf;
553         u8 *u8_tmp = (u8 *)out_buf;
554         bool tmp = false;
555         bool ret = true;
556
557         if (!halbtc_is_bt_coexist_available(btcoexist))
558                 return false;
559
560         switch (get_type) {
561         case BTC_GET_BL_HS_OPERATION:
562                 *bool_tmp = false;
563                 ret = false;
564                 break;
565         case BTC_GET_BL_HS_CONNECTING:
566                 *bool_tmp = false;
567                 ret = false;
568                 break;
569         case BTC_GET_BL_WIFI_CONNECTED:
570                 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
571                     rtlpriv->mac80211.link_state >= MAC80211_LINKED)
572                         tmp = true;
573                 if (is_any_client_connect_to_ap(btcoexist))
574                         tmp = true;
575                 *bool_tmp = tmp;
576                 break;
577         case BTC_GET_BL_WIFI_DUAL_BAND_CONNECTED:
578                 *u8_tmp = BTC_MULTIPORT_SCC;
579                 break;
580         case BTC_GET_BL_WIFI_BUSY:
581                 if (halbtc_is_wifi_busy(rtlpriv))
582                         *bool_tmp = true;
583                 else
584                         *bool_tmp = false;
585                 break;
586         case BTC_GET_BL_WIFI_SCAN:
587                 if (mac->act_scanning)
588                         *bool_tmp = true;
589                 else
590                         *bool_tmp = false;
591                 break;
592         case BTC_GET_BL_WIFI_LINK:
593                 if (mac->link_state == MAC80211_LINKING)
594                         *bool_tmp = true;
595                 else
596                         *bool_tmp = false;
597                 break;
598         case BTC_GET_BL_WIFI_ROAM:
599                 if (mac->link_state == MAC80211_LINKING)
600                         *bool_tmp = true;
601                 else
602                         *bool_tmp = false;
603                 break;
604         case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
605                 *bool_tmp = rtlpriv->btcoexist.btc_info.in_4way;
606                 break;
607         case BTC_GET_BL_WIFI_UNDER_5G:
608                 if (rtlhal->current_bandtype == BAND_ON_5G)
609                         *bool_tmp = true;
610                 else
611                         *bool_tmp = false;
612                 break;
613         case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
614                 if (mac->opmode == NL80211_IFTYPE_AP)
615                         *bool_tmp = true;
616                 else
617                         *bool_tmp = false;
618                 break;
619         case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
620                 if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm)
621                         *bool_tmp = false;
622                 else
623                         *bool_tmp = true;
624                 break;
625         case BTC_GET_BL_WIFI_UNDER_B_MODE:
626                 if (rtlpriv->mac80211.mode == WIRELESS_MODE_B)
627                         *bool_tmp = true;
628                 else
629                         *bool_tmp = false;
630                 break;
631         case BTC_GET_BL_EXT_SWITCH:
632                 *bool_tmp = false;
633                 break;
634         case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
635                 *bool_tmp = false;
636                 break;
637         case BTC_GET_BL_IS_ASUS_8723B:
638                 *bool_tmp = false;
639                 break;
640         case BTC_GET_BL_RF4CE_CONNECTED:
641                 *bool_tmp = false;
642                 break;
643         case BTC_GET_S4_WIFI_RSSI:
644                 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
645                 break;
646         case BTC_GET_S4_HS_RSSI:
647                 *s32_tmp = 0;
648                 ret = false;
649                 break;
650         case BTC_GET_U4_WIFI_BW:
651                 *u32_tmp = halbtc_get_wifi_bw(btcoexist);
652                 break;
653         case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
654                 if (halbtc_is_wifi_uplink(rtlpriv))
655                         *u32_tmp = BTC_WIFI_TRAFFIC_TX;
656                 else
657                         *u32_tmp = BTC_WIFI_TRAFFIC_RX;
658                 break;
659         case BTC_GET_U4_WIFI_FW_VER:
660                 *u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion;
661                 break;
662         case BTC_GET_U4_WIFI_LINK_STATUS:
663                 *u32_tmp = halbtc_get_wifi_link_status(btcoexist);
664                 break;
665         case BTC_GET_U4_BT_PATCH_VER:
666                 *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
667                 break;
668         case BTC_GET_U4_VENDOR:
669                 *u32_tmp = BTC_VENDOR_OTHER;
670                 break;
671         case BTC_GET_U4_SUPPORTED_VERSION:
672                 *u32_tmp = halbtc_get_bt_coex_supported_version(btcoexist);
673                 break;
674         case BTC_GET_U4_SUPPORTED_FEATURE:
675                 *u32_tmp = halbtc_get_bt_coex_supported_feature(btcoexist);
676                 break;
677         case BTC_GET_U4_BT_DEVICE_INFO:
678                 *u32_tmp = halbtc_get_bt_device_info(btcoexist);
679                 break;
680         case BTC_GET_U4_BT_FORBIDDEN_SLOT_VAL:
681                 *u32_tmp = halbtc_get_bt_forbidden_slot_val(btcoexist);
682                 break;
683         case BTC_GET_U4_WIFI_IQK_TOTAL:
684                 *u32_tmp =
685                         btcoexist->btc_phydm_query_phy_counter(btcoexist,
686                                                                DM_INFO_IQK_ALL);
687                 break;
688         case BTC_GET_U4_WIFI_IQK_OK:
689                 *u32_tmp =
690                         btcoexist->btc_phydm_query_phy_counter(btcoexist,
691                                                                DM_INFO_IQK_OK);
692                 break;
693         case BTC_GET_U4_WIFI_IQK_FAIL:
694                 *u32_tmp =
695                         btcoexist->btc_phydm_query_phy_counter(btcoexist,
696                                                                DM_INFO_IQK_NG);
697                 break;
698         case BTC_GET_U1_WIFI_DOT11_CHNL:
699                 *u8_tmp = rtlphy->current_channel;
700                 break;
701         case BTC_GET_U1_WIFI_CENTRAL_CHNL:
702                 *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
703                 break;
704         case BTC_GET_U1_WIFI_HS_CHNL:
705                 *u8_tmp = 0;
706                 ret = false;
707                 break;
708         case BTC_GET_U1_AP_NUM:
709                 *u8_tmp = rtlpriv->btcoexist.btc_info.ap_num;
710                 break;
711         case BTC_GET_U1_ANT_TYPE:
712                 *u8_tmp = (u8)BTC_ANT_TYPE_0;
713                 break;
714         case BTC_GET_U1_IOT_PEER:
715                 *u8_tmp = 0;
716                 break;
717
718                 /************* 1Ant **************/
719         case BTC_GET_U1_LPS_MODE:
720                 *u8_tmp = btcoexist->pwr_mode_val[0];
721                 break;
722
723         default:
724                 ret = false;
725                 break;
726         }
727
728         return ret;
729 }
730
731 static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
732 {
733         struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
734         bool *bool_tmp = (bool *)in_buf;
735         u8 *u8_tmp = (u8 *)in_buf;
736         u32 *u32_tmp = (u32 *)in_buf;
737         bool ret = true;
738
739         if (!halbtc_is_bt_coexist_available(btcoexist))
740                 return false;
741
742         switch (set_type) {
743         /* set some bool type variables. */
744         case BTC_SET_BL_BT_DISABLE:
745                 btcoexist->bt_info.bt_disabled = *bool_tmp;
746                 break;
747         case BTC_SET_BL_BT_TRAFFIC_BUSY:
748                 btcoexist->bt_info.bt_busy = *bool_tmp;
749                 break;
750         case BTC_SET_BL_BT_LIMITED_DIG:
751                 btcoexist->bt_info.limited_dig = *bool_tmp;
752                 break;
753         case BTC_SET_BL_FORCE_TO_ROAM:
754                 btcoexist->bt_info.force_to_roam = *bool_tmp;
755                 break;
756         case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
757                 btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
758                 break;
759         case BTC_SET_BL_BT_CTRL_AGG_SIZE:
760                 btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp;
761                 break;
762         case BTC_SET_BL_INC_SCAN_DEV_NUM:
763                 btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
764                 break;
765         case BTC_SET_BL_BT_TX_RX_MASK:
766                 btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp;
767                 break;
768         case BTC_SET_BL_MIRACAST_PLUS_BT:
769                 btcoexist->bt_info.miracast_plus_bt = *bool_tmp;
770                 break;
771                 /* set some u1Byte type variables. */
772         case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
773                 btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
774                 break;
775         case BTC_SET_U1_AGG_BUF_SIZE:
776                 btcoexist->bt_info.agg_buf_size = *u8_tmp;
777                 break;
778
779         /* the following are some action which will be triggered */
780         case BTC_SET_ACT_GET_BT_RSSI:
781                 ret = false;
782                 break;
783         case BTC_SET_ACT_AGGREGATE_CTRL:
784                 halbtc_aggregation_check(btcoexist);
785                 break;
786
787         /* 1Ant */
788         case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
789                 btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
790                 break;
791         case BTC_SET_UI_SCAN_SIG_COMPENSATION:
792                 break;
793         case BTC_SET_U1_LPS_VAL:
794                 btcoexist->bt_info.lps_val = *u8_tmp;
795                 break;
796         case BTC_SET_U1_RPWM_VAL:
797                 btcoexist->bt_info.rpwm_val = *u8_tmp;
798                 break;
799         /* the following are some action which will be triggered  */
800         case BTC_SET_ACT_LEAVE_LPS:
801                 halbtc_leave_lps(btcoexist);
802                 break;
803         case BTC_SET_ACT_ENTER_LPS:
804                 halbtc_enter_lps(btcoexist);
805                 break;
806         case BTC_SET_ACT_NORMAL_LPS:
807                 halbtc_normal_lps(btcoexist);
808                 break;
809         case BTC_SET_ACT_PRE_NORMAL_LPS:
810                 halbtc_pre_normal_lps(btcoexist);
811                 break;
812         case BTC_SET_ACT_POST_NORMAL_LPS:
813                 halbtc_post_normal_lps(btcoexist);
814                 break;
815         case BTC_SET_ACT_DISABLE_LOW_POWER:
816                 halbtc_disable_low_power(btcoexist, *bool_tmp);
817                 break;
818         case BTC_SET_ACT_UPDATE_RAMASK:
819                 btcoexist->bt_info.ra_mask = *u32_tmp;
820                 break;
821         case BTC_SET_ACT_SEND_MIMO_PS:
822                 break;
823         case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
824                 break;
825         case BTC_SET_ACT_CTRL_BT_COEX:
826                 break;
827         case BTC_SET_ACT_CTRL_8723B_ANT:
828                 break;
829         default:
830                 break;
831         }
832
833         return ret;
834 }
835
836 static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist,
837                                            struct seq_file *m)
838 {
839 }
840
841 static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist,
842                                         struct seq_file *m)
843 {
844 }
845
846 static void halbtc_display_wifi_status(struct btc_coexist *btcoexist,
847                                        struct seq_file *m)
848 {
849         struct rtl_priv *rtlpriv = btcoexist->adapter;
850         s32 wifi_rssi = 0, bt_hs_rssi = 0;
851         bool scan = false, link = false, roam = false, wifi_busy = false;
852         bool wifi_under_b_mode = false;
853         bool wifi_under_5g = false;
854         u32 wifi_bw = BTC_WIFI_BW_HT20;
855         u32 wifi_traffic_dir = BTC_WIFI_TRAFFIC_TX;
856         u32 wifi_freq = BTC_FREQ_2_4G;
857         u32 wifi_link_status = 0x0;
858         bool bt_hs_on = false, under_ips = false, under_lps = false;
859         bool low_power = false, dc_mode = false;
860         u8 wifi_chnl = 0, wifi_hs_chnl = 0;
861         u8 ap_num = 0;
862
863         wifi_link_status = halbtc_get_wifi_link_status(btcoexist);
864         seq_printf(m, "\n %-35s = %d/ %d/ %d/ %d/ %d",
865                    "STA/vWifi/HS/p2pGo/p2pGc",
866                    ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0),
867                    ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0),
868                    ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0),
869                    ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
870                    ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
871
872         btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
873         btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_chnl);
874         btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
875         seq_printf(m, "\n %-35s = %d / %d(%d)",
876                    "Dot11 channel / HsChnl(High Speed)",
877                    wifi_chnl, wifi_hs_chnl, bt_hs_on);
878
879         btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
880         btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
881         seq_printf(m, "\n %-35s = %d/ %d",
882                    "Wifi rssi/ HS rssi",
883                    wifi_rssi - 100, bt_hs_rssi - 100);
884
885         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
886         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
887         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
888         seq_printf(m, "\n %-35s = %d/ %d/ %d ",
889                    "Wifi link/ roam/ scan",
890                    link, roam, scan);
891
892         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
893         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
894         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
895         btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
896                            &wifi_traffic_dir);
897         btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
898         wifi_freq = (wifi_under_5g ? BTC_FREQ_5G : BTC_FREQ_2_4G);
899         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
900                            &wifi_under_b_mode);
901
902         seq_printf(m, "\n %-35s = %s / %s/ %s/ AP=%d ",
903                    "Wifi freq/ bw/ traffic",
904                    gl_btc_wifi_freq_string[wifi_freq],
905                    ((wifi_under_b_mode) ? "11b" :
906                     gl_btc_wifi_bw_string[wifi_bw]),
907                    ((!wifi_busy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX ==
908                                               wifi_traffic_dir) ? "uplink" :
909                                              "downlink")),
910                    ap_num);
911
912         /* power status  */
913         dc_mode = true; /*TODO*/
914         under_ips = rtlpriv->psc.inactive_pwrstate == ERFOFF ? 1 : 0;
915         under_lps = rtlpriv->psc.dot11_psmode == EACTIVE ? 0 : 1;
916         low_power = 0; /*TODO*/
917         seq_printf(m, "\n %-35s = %s%s%s%s",
918                    "Power Status",
919                    (dc_mode ? "DC mode" : "AC mode"),
920                    (under_ips ? ", IPS ON" : ""),
921                    (under_lps ? ", LPS ON" : ""),
922                    (low_power ? ", 32k" : ""));
923
924         seq_printf(m,
925                    "\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)",
926                    "Power mode cmd(lps/rpwm)",
927                    btcoexist->pwr_mode_val[0], btcoexist->pwr_mode_val[1],
928                    btcoexist->pwr_mode_val[2], btcoexist->pwr_mode_val[3],
929                    btcoexist->pwr_mode_val[4], btcoexist->pwr_mode_val[5],
930                    btcoexist->bt_info.lps_val,
931                    btcoexist->bt_info.rpwm_val);
932 }
933
934 /************************************************************
935  *              IO related function
936  ************************************************************/
937 static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
938 {
939         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
940         struct rtl_priv *rtlpriv = btcoexist->adapter;
941
942         return  rtl_read_byte(rtlpriv, reg_addr);
943 }
944
945 static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
946 {
947         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
948         struct rtl_priv *rtlpriv = btcoexist->adapter;
949
950         return  rtl_read_word(rtlpriv, reg_addr);
951 }
952
953 static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
954 {
955         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
956         struct rtl_priv *rtlpriv = btcoexist->adapter;
957
958         return  rtl_read_dword(rtlpriv, reg_addr);
959 }
960
961 static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data)
962 {
963         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
964         struct rtl_priv *rtlpriv = btcoexist->adapter;
965
966         rtl_write_byte(rtlpriv, reg_addr, data);
967 }
968
969 static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
970                                        u32 bit_mask, u8 data)
971 {
972         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
973         struct rtl_priv *rtlpriv = btcoexist->adapter;
974         u8 original_value, bit_shift = 0;
975         u8 i;
976
977         if (bit_mask != MASKDWORD) {/*if not "double word" write*/
978                 original_value = rtl_read_byte(rtlpriv, reg_addr);
979                 for (i = 0; i <= 7; i++) {
980                         if ((bit_mask>>i) & 0x1)
981                                 break;
982                 }
983                 bit_shift = i;
984                 data = (original_value & (~bit_mask)) |
985                         ((data << bit_shift) & bit_mask);
986         }
987         rtl_write_byte(rtlpriv, reg_addr, data);
988 }
989
990 static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
991 {
992         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
993         struct rtl_priv *rtlpriv = btcoexist->adapter;
994
995         rtl_write_word(rtlpriv, reg_addr, data);
996 }
997
998 static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
999 {
1000         struct btc_coexist *btcoexist =
1001                 (struct btc_coexist *)bt_context;
1002         struct rtl_priv *rtlpriv = btcoexist->adapter;
1003
1004         rtl_write_dword(rtlpriv, reg_addr, data);
1005 }
1006
1007 static void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr,
1008                                          u8 data)
1009 {
1010         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1011         struct rtl_priv *rtlpriv = btcoexist->adapter;
1012
1013         if (btcoexist->chip_interface == BTC_INTF_SDIO)
1014                 ;
1015         else if (btcoexist->chip_interface == BTC_INTF_PCI)
1016                 rtl_write_byte(rtlpriv, reg_addr, data);
1017         else if (btcoexist->chip_interface == BTC_INTF_USB)
1018                 rtl_write_byte(rtlpriv, reg_addr, data);
1019 }
1020
1021 static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
1022                              u32 data)
1023 {
1024         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1025         struct rtl_priv *rtlpriv = btcoexist->adapter;
1026
1027         rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
1028 }
1029
1030 static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
1031 {
1032         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1033         struct rtl_priv *rtlpriv = btcoexist->adapter;
1034
1035         return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
1036 }
1037
1038 static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
1039                              u32 bit_mask, u32 data)
1040 {
1041         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1042         struct rtl_priv *rtlpriv = btcoexist->adapter;
1043
1044         rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
1045 }
1046
1047 static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
1048                             u32 bit_mask)
1049 {
1050         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1051         struct rtl_priv *rtlpriv = btcoexist->adapter;
1052
1053         return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
1054 }
1055
1056 static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
1057                                 u32 cmd_len, u8 *cmd_buf)
1058 {
1059         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1060         struct rtl_priv *rtlpriv = btcoexist->adapter;
1061
1062         rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
1063                                         cmd_len, cmd_buf);
1064 }
1065
1066 void halbtc_send_wifi_port_id_cmd(void *bt_context)
1067 {
1068         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1069         struct rtl_priv *rtlpriv = btcoexist->adapter;
1070         u8 cmd_buf[1] = {0};    /* port id [2:0] = 0 */
1071
1072         rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, H2C_BT_PORT_ID,
1073                                         1, cmd_buf);
1074 }
1075
1076 void halbtc_set_default_port_id_cmd(void *bt_context)
1077 {
1078         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1079         struct rtl_priv *rtlpriv = btcoexist->adapter;
1080         struct ieee80211_hw *hw = rtlpriv->mac80211.hw;
1081
1082         if (!rtlpriv->cfg->ops->set_default_port_id_cmd)
1083                 return;
1084
1085         rtlpriv->cfg->ops->set_default_port_id_cmd(hw);
1086 }
1087
1088 static
1089 void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val)
1090 {
1091         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1092         u8 cmd_buffer1[4] = {0};
1093         u8 cmd_buffer2[4] = {0};
1094
1095         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1096         *((__le16 *)&cmd_buffer1[2]) = cpu_to_le16((u16)set_val);
1097         if (!halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_VALUE,
1098                                          cmd_buffer1, 4, 200))
1099                 return;
1100
1101         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1102         cmd_buffer2[2] = reg_type;
1103         *((u8 *)&cmd_buffer2[3]) = (u8)offset;
1104         halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_ADDR,
1105                                     cmd_buffer2, 4, 200);
1106 }
1107
1108 static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type,
1109                                    struct seq_file *m)
1110 {
1111         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1112
1113         switch (disp_type) {
1114         case BTC_DBG_DISP_COEX_STATISTICS:
1115                 halbtc_display_coex_statistics(btcoexist, m);
1116                 break;
1117         case BTC_DBG_DISP_BT_LINK_INFO:
1118                 halbtc_display_bt_link_info(btcoexist, m);
1119                 break;
1120         case BTC_DBG_DISP_WIFI_STATUS:
1121                 halbtc_display_wifi_status(btcoexist, m);
1122                 break;
1123         default:
1124                 break;
1125         }
1126 }
1127
1128 static u32 halbtc_get_bt_reg(void *btc_context, u8 reg_type, u32 offset)
1129 {
1130         return 0;
1131 }
1132
1133 static bool halbtc_under_ips(struct btc_coexist *btcoexist)
1134 {
1135         struct rtl_priv *rtlpriv = btcoexist->adapter;
1136         struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
1137         enum rf_pwrstate rtstate;
1138
1139         if (ppsc->inactiveps) {
1140                 rtstate = ppsc->rfpwr_state;
1141
1142                 if (rtstate != ERFON &&
1143                     ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
1144                         return true;
1145                 }
1146         }
1147
1148         return false;
1149 }
1150
1151 static
1152 u32 halbtc_get_phydm_version(void *btc_context)
1153 {
1154         return 0;
1155 }
1156
1157 static
1158 void halbtc_phydm_modify_ra_pcr_threshold(void *btc_context,
1159                                           u8 ra_offset_direction,
1160                                           u8 ra_threshold_offset)
1161 {
1162 }
1163
1164 static
1165 u32 halbtc_phydm_query_phy_counter(void *btc_context, enum dm_info_query dm_id)
1166 {
1167         return 0;
1168 }
1169
1170 static u8 halbtc_get_ant_det_val_from_bt(void *btc_context)
1171 {
1172         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1173         u8 cmd_buffer[4] = {0};
1174
1175         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1176         halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_ANT_DET_VAL,
1177                                     cmd_buffer, 4, 200);
1178
1179         /* need wait completion to return correct value */
1180
1181         return btcoexist->bt_info.bt_ant_det_val;
1182 }
1183
1184 static u8 halbtc_get_ble_scan_type_from_bt(void *btc_context)
1185 {
1186         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1187         u8 cmd_buffer[4] = {0};
1188
1189         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1190         halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_TYPE,
1191                                     cmd_buffer, 4, 200);
1192
1193         /* need wait completion to return correct value */
1194
1195         return btcoexist->bt_info.bt_ble_scan_type;
1196 }
1197
1198 static u32 halbtc_get_ble_scan_para_from_bt(void *btc_context, u8 scan_type)
1199 {
1200         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1201         u8 cmd_buffer[4] = {0};
1202
1203         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1204         halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_PARA,
1205                                     cmd_buffer, 4, 200);
1206
1207         /* need wait completion to return correct value */
1208
1209         return btcoexist->bt_info.bt_ble_scan_para;
1210 }
1211
1212 static bool halbtc_get_bt_afh_map_from_bt(void *btc_context, u8 map_type,
1213                                           u8 *afh_map)
1214 {
1215         struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1216         u8 cmd_buffer[2] = {0};
1217         bool ret;
1218         u32 *afh_map_l = (u32 *)afh_map;
1219         u32 *afh_map_m = (u32 *)(afh_map + 4);
1220         u16 *afh_map_h = (u16 *)(afh_map + 8);
1221
1222         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1223         ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_L,
1224                                           cmd_buffer, 2, 200);
1225         if (!ret)
1226                 goto exit;
1227
1228         *afh_map_l = btcoexist->bt_info.afh_map_l;
1229
1230         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1231         ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_M,
1232                                           cmd_buffer, 2, 200);
1233         if (!ret)
1234                 goto exit;
1235
1236         *afh_map_m = btcoexist->bt_info.afh_map_m;
1237
1238         /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1239         ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_H,
1240                                           cmd_buffer, 2, 200);
1241         if (!ret)
1242                 goto exit;
1243
1244         *afh_map_h = btcoexist->bt_info.afh_map_h;
1245
1246 exit:
1247         return ret;
1248 }
1249
1250 /*****************************************************************
1251  *         Extern functions called by other module
1252  *****************************************************************/
1253 bool exhalbtc_initlize_variables(struct rtl_priv *rtlpriv)
1254 {
1255         struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1256
1257         if (!btcoexist)
1258                 return false;
1259
1260         halbtc_dbg_init();
1261
1262         btcoexist->btc_read_1byte = halbtc_read_1byte;
1263         btcoexist->btc_write_1byte = halbtc_write_1byte;
1264         btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
1265         btcoexist->btc_read_2byte = halbtc_read_2byte;
1266         btcoexist->btc_write_2byte = halbtc_write_2byte;
1267         btcoexist->btc_read_4byte = halbtc_read_4byte;
1268         btcoexist->btc_write_4byte = halbtc_write_4byte;
1269         btcoexist->btc_write_local_reg_1byte = halbtc_write_local_reg_1byte;
1270
1271         btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
1272         btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
1273
1274         btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
1275         btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
1276
1277         btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
1278         btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
1279
1280         btcoexist->btc_get = halbtc_get;
1281         btcoexist->btc_set = halbtc_set;
1282         btcoexist->btc_set_bt_reg = halbtc_set_bt_reg;
1283         btcoexist->btc_get_bt_reg = halbtc_get_bt_reg;
1284
1285         btcoexist->bt_info.bt_ctrl_buf_size = false;
1286         btcoexist->bt_info.agg_buf_size = 5;
1287
1288         btcoexist->bt_info.increase_scan_dev_num = false;
1289
1290         btcoexist->btc_get_bt_coex_supported_feature =
1291                                         halbtc_get_bt_coex_supported_feature;
1292         btcoexist->btc_get_bt_coex_supported_version =
1293                                         halbtc_get_bt_coex_supported_version;
1294         btcoexist->btc_get_bt_phydm_version = halbtc_get_phydm_version;
1295         btcoexist->btc_phydm_modify_ra_pcr_threshold =
1296                                         halbtc_phydm_modify_ra_pcr_threshold;
1297         btcoexist->btc_phydm_query_phy_counter = halbtc_phydm_query_phy_counter;
1298         btcoexist->btc_get_ant_det_val_from_bt = halbtc_get_ant_det_val_from_bt;
1299         btcoexist->btc_get_ble_scan_type_from_bt =
1300                                         halbtc_get_ble_scan_type_from_bt;
1301         btcoexist->btc_get_ble_scan_para_from_bt =
1302                                         halbtc_get_ble_scan_para_from_bt;
1303         btcoexist->btc_get_bt_afh_map_from_bt =
1304                                         halbtc_get_bt_afh_map_from_bt;
1305
1306         init_completion(&btcoexist->bt_mp_comp);
1307
1308         return true;
1309 }
1310
1311 bool exhalbtc_initlize_variables_wifi_only(struct rtl_priv *rtlpriv)
1312 {
1313         struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
1314         struct wifi_only_haldata *wifionly_haldata;
1315
1316         if (!wifionly_cfg)
1317                 return false;
1318
1319         wifionly_cfg->adapter = rtlpriv;
1320
1321         switch (rtlpriv->rtlhal.interface) {
1322         case INTF_PCI:
1323                 wifionly_cfg->chip_interface = WIFIONLY_INTF_PCI;
1324                 break;
1325         case INTF_USB:
1326                 wifionly_cfg->chip_interface = WIFIONLY_INTF_USB;
1327                 break;
1328         default:
1329                 wifionly_cfg->chip_interface = WIFIONLY_INTF_UNKNOWN;
1330                 break;
1331         }
1332
1333         wifionly_haldata = &wifionly_cfg->haldata_info;
1334
1335         wifionly_haldata->customer_id = CUSTOMER_NORMAL;
1336         wifionly_haldata->efuse_pg_antnum = rtl_get_hwpg_ant_num(rtlpriv);
1337         wifionly_haldata->efuse_pg_antpath =
1338                                         rtl_get_hwpg_single_ant_path(rtlpriv);
1339         wifionly_haldata->rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1340         wifionly_haldata->ant_div_cfg = 0;
1341
1342         return true;
1343 }
1344
1345 bool exhalbtc_bind_bt_coex_withadapter(void *adapter)
1346 {
1347         struct rtl_priv *rtlpriv = adapter;
1348         struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1349         u8 ant_num = 2, chip_type, single_ant_path = 0;
1350
1351         if (!btcoexist)
1352                 return false;
1353
1354         if (btcoexist->binded)
1355                 return false;
1356
1357         switch (rtlpriv->rtlhal.interface) {
1358         case INTF_PCI:
1359                 btcoexist->chip_interface = BTC_INTF_PCI;
1360                 break;
1361         case INTF_USB:
1362                 btcoexist->chip_interface = BTC_INTF_USB;
1363                 break;
1364         default:
1365                 btcoexist->chip_interface = BTC_INTF_UNKNOWN;
1366                 break;
1367         }
1368
1369         btcoexist->binded = true;
1370         btcoexist->statistics.cnt_bind++;
1371
1372         btcoexist->adapter = adapter;
1373
1374         btcoexist->stack_info.profile_notified = false;
1375
1376         btcoexist->bt_info.bt_ctrl_agg_buf_size = false;
1377         btcoexist->bt_info.agg_buf_size = 5;
1378
1379         btcoexist->bt_info.increase_scan_dev_num = false;
1380         btcoexist->bt_info.miracast_plus_bt = false;
1381
1382         chip_type = rtl_get_hwpg_bt_type(rtlpriv);
1383         exhalbtc_set_chip_type(btcoexist, chip_type);
1384         ant_num = rtl_get_hwpg_ant_num(rtlpriv);
1385         exhalbtc_set_ant_num(rtlpriv, BT_COEX_ANT_TYPE_PG, ant_num);
1386
1387         /* set default antenna position to main  port */
1388         btcoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
1389
1390         single_ant_path = rtl_get_hwpg_single_ant_path(rtlpriv);
1391         exhalbtc_set_single_ant_path(btcoexist, single_ant_path);
1392
1393         if (rtl_get_hwpg_package_type(rtlpriv) == 0)
1394                 btcoexist->board_info.tfbga_package = false;
1395         else if (rtl_get_hwpg_package_type(rtlpriv) == 1)
1396                 btcoexist->board_info.tfbga_package = false;
1397         else
1398                 btcoexist->board_info.tfbga_package = true;
1399
1400         if (btcoexist->board_info.tfbga_package)
1401                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1402                          "[BTCoex], Package Type = TFBGA\n");
1403         else
1404                 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1405                          "[BTCoex], Package Type = Non-TFBGA\n");
1406
1407         btcoexist->board_info.rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1408         btcoexist->board_info.ant_div_cfg = 0;
1409
1410         return true;
1411 }
1412
1413 void exhalbtc_power_on_setting(struct btc_coexist *btcoexist)
1414 {
1415         if (!halbtc_is_bt_coexist_available(btcoexist))
1416                 return;
1417
1418         btcoexist->statistics.cnt_power_on++;
1419
1420         if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1421                 if (btcoexist->board_info.btdm_ant_num == 2)
1422                         ex_btc8723b2ant_power_on_setting(btcoexist);
1423                 else if (btcoexist->board_info.btdm_ant_num == 1)
1424                         ex_btc8723b1ant_power_on_setting(btcoexist);
1425         }
1426 }
1427
1428 void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist)
1429 {
1430         if (!halbtc_is_bt_coexist_available(btcoexist))
1431                 return;
1432
1433         btcoexist->statistics.cnt_pre_load_firmware++;
1434
1435         if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1436                 if (btcoexist->board_info.btdm_ant_num == 2)
1437                         ex_btc8723b2ant_pre_load_firmware(btcoexist);
1438         }
1439 }
1440
1441 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only)
1442 {
1443         if (!halbtc_is_bt_coexist_available(btcoexist))
1444                 return;
1445
1446         btcoexist->statistics.cnt_init_hw_config++;
1447
1448         if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1449                 if (btcoexist->board_info.btdm_ant_num == 2)
1450                         ex_btc8821a2ant_init_hwconfig(btcoexist);
1451                 else if (btcoexist->board_info.btdm_ant_num == 1)
1452                         ex_btc8821a1ant_init_hwconfig(btcoexist, wifi_only);
1453         } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1454                 if (btcoexist->board_info.btdm_ant_num == 2)
1455                         ex_btc8723b2ant_init_hwconfig(btcoexist);
1456                 else if (btcoexist->board_info.btdm_ant_num == 1)
1457                         ex_btc8723b1ant_init_hwconfig(btcoexist, wifi_only);
1458         } else if (IS_HARDWARE_TYPE_8723A(btcoexist->adapter)) {
1459                 /* 8723A has no this function */
1460         } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1461                 if (btcoexist->board_info.btdm_ant_num == 2)
1462                         ex_btc8192e2ant_init_hwconfig(btcoexist);
1463         }
1464 }
1465
1466 void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg)
1467 {
1468 }
1469
1470 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
1471 {
1472         if (!halbtc_is_bt_coexist_available(btcoexist))
1473                 return;
1474
1475         btcoexist->statistics.cnt_init_coex_dm++;
1476
1477         if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1478                 if (btcoexist->board_info.btdm_ant_num == 2)
1479                         ex_btc8821a2ant_init_coex_dm(btcoexist);
1480                 else if (btcoexist->board_info.btdm_ant_num == 1)
1481                         ex_btc8821a1ant_init_coex_dm(btcoexist);
1482         } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1483                 if (btcoexist->board_info.btdm_ant_num == 2)
1484                         ex_btc8723b2ant_init_coex_dm(btcoexist);
1485                 else if (btcoexist->board_info.btdm_ant_num == 1)
1486                         ex_btc8723b1ant_init_coex_dm(btcoexist);
1487         } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1488                 if (btcoexist->board_info.btdm_ant_num == 2)
1489                         ex_btc8192e2ant_init_coex_dm(btcoexist);
1490         }
1491
1492         btcoexist->initilized = true;
1493 }
1494
1495 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
1496 {
1497         u8 ips_type;
1498
1499         if (!halbtc_is_bt_coexist_available(btcoexist))
1500                 return;
1501         btcoexist->statistics.cnt_ips_notify++;
1502         if (btcoexist->manual_control)
1503                 return;
1504
1505         if (ERFOFF == type)
1506                 ips_type = BTC_IPS_ENTER;
1507         else
1508                 ips_type = BTC_IPS_LEAVE;
1509
1510         halbtc_leave_low_power(btcoexist);
1511
1512         if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1513                 if (btcoexist->board_info.btdm_ant_num == 2)
1514                         ex_btc8821a2ant_ips_notify(btcoexist, ips_type);
1515                 else if (btcoexist->board_info.btdm_ant_num == 1)
1516                         ex_btc8821a1ant_ips_notify(btcoexist, ips_type);
1517         } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1518                 if (btcoexist->board_info.btdm_ant_num == 2)
1519                         ex_btc8723b2ant_ips_notify(btcoexist, ips_type);
1520                 else if (btcoexist->board_info.btdm_ant_num == 1)
1521                         ex_btc8723b1ant_ips_notify(btcoexist, ips_type);
1522         } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1523                 if (btcoexist->board_info.btdm_ant_num == 2)
1524                         ex_btc8192e2ant_ips_notify(btcoexist, ips_type);
1525         }
1526
1527         halbtc_normal_low_power(btcoexist);
1528 }
1529
1530 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
1531 {
1532         u8 lps_type;
1533
1534         if (!halbtc_is_bt_coexist_available(btcoexist))
1535                 return;
1536         btcoexist->statistics.cnt_lps_notify++;
1537         if (btcoexist->manual_control)
1538                 return;
1539
1540         if (EACTIVE == type)
1541                 lps_type = BTC_LPS_DISABLE;
1542         else
1543                 lps_type = BTC_LPS_ENABLE;
1544
1545         if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1546                 if (btcoexist->board_info.btdm_ant_num == 2)
1547                         ex_btc8821a2ant_lps_notify(btcoexist, lps_type);
1548                 else if (btcoexist->board_info.btdm_ant_num == 1)
1549                         ex_btc8821a1ant_lps_notify(btcoexist, lps_type);
1550         } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1551                 if (btcoexist->board_info.btdm_ant_num == 2)
1552                         ex_btc8723b2ant_lps_notify(btcoexist, lps_type);
1553                 else if (btcoexist->board_info.btdm_ant_num == 1)
1554                         ex_btc8723b1ant_lps_notify(btcoexist, lps_type);
1555         } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1556                 if (btcoexist->board_info.btdm_ant_num == 2)
1557                         ex_btc8192e2ant_lps_notify(btcoexist, lps_type);
1558         }
1559 }
1560
1561 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
1562 {
1563         u8 scan_type;
1564
1565         if (!halbtc_is_bt_coexist_available(btcoexist))
1566                 return;
1567         btcoexist->statistics.cnt_scan_notify++;
1568         if (btcoexist->manual_control)
1569                 return;
1570
1571         if (type)
1572                 scan_type = BTC_SCAN_START;
1573         else
1574                 scan_type = BTC_SCAN_FINISH;
1575
1576         halbtc_leave_low_power(btcoexist);
1577
1578         if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1579                 if (btcoexist->board_info.btdm_ant_num == 2)
1580                         ex_btc8821a2ant_scan_notify(btcoexist, scan_type);
1581                 else if (btcoexist->board_info.btdm_ant_num == 1)
1582                         ex_btc8821a1ant_scan_notify(btcoexist, scan_type);
1583         } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1584                 if (btcoexist->board_info.btdm_ant_num == 2)
1585                         ex_btc8723b2ant_scan_notify(btcoexist, scan_type);
1586                 else if (btcoexist->board_info.btdm_ant_num == 1)
1587                         ex_btc8723b1ant_scan_notify(btcoexist, scan_type);
1588         } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1589                 if (btcoexist->board_info.btdm_ant_num == 2)
1590                         ex_btc8192e2ant_scan_notify(btcoexist, scan_type);
1591         }
1592
1593         halbtc_normal_low_power(btcoexist);
1594 }
1595
1596 void exhalbtc_scan_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1597                                     u8 is_5g)
1598 {
1599 }
1600
1601 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
1602 {
1603         u8 asso_type, asso_type_v2;
1604         bool wifi_under_5g;
1605
1606         if (!halbtc_is_bt_coexist_available(btcoexist))
1607                 return;
1608         btcoexist->statistics.cnt_connect_notify++;
1609         if (btcoexist->manual_control)
1610                 return;
1611
1612         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
1613
1614         if (action) {
1615                 asso_type = BTC_ASSOCIATE_START;
1616                 asso_type_v2 = wifi_under_5g ? BTC_ASSOCIATE_5G_START :
1617                                                BTC_ASSOCIATE_START;
1618         } else {
1619                 asso_type = BTC_ASSOCIATE_FINISH;
1620                 asso_type_v2 = wifi_under_5g ? BTC_ASSOCIATE_5G_FINISH :
1621                                                BTC_ASSOCIATE_FINISH;
1622         }
1623
1624         halbtc_leave_low_power(btcoexist);
1625
1626         if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1627                 if (btcoexist->board_info.btdm_ant_num == 2)
1628                         ex_btc8821a2ant_connect_notify(btcoexist, asso_type);
1629                 else if (btcoexist->board_info.btdm_ant_num == 1)
1630                         ex_btc8821a1ant_connect_notify(btcoexist, asso_type);
1631         } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1632                 if (btcoexist->board_info.btdm_ant_num == 2)
1633                         ex_btc8723b2ant_connect_notify(btcoexist, asso_type);
1634                 else if (btcoexist->board_info.btdm_ant_num == 1)
1635                         ex_btc8723b1ant_connect_notify(btcoexist, asso_type);
1636         } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1637                 if (btcoexist->board_info.btdm_ant_num == 2)
1638                         ex_btc8192e2ant_connect_notify(btcoexist, asso_type);
1639         }
1640
1641         halbtc_normal_low_power(btcoexist);
1642 }
1643
1644 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
1645                                  enum rt_media_status media_status)
1646 {
1647         u8 status;
1648
1649         if (!halbtc_is_bt_coexist_available(btcoexist))
1650                 return;
1651         btcoexist->statistics.cnt_media_status_notify++;
1652         if (btcoexist->manual_control)
1653                 return;
1654
1655         if (RT_MEDIA_CONNECT == media_status)
1656                 status = BTC_MEDIA_CONNECT;
1657         else
1658                 status = BTC_MEDIA_DISCONNECT;
1659
1660         halbtc_leave_low_power(btcoexist);
1661
1662         if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1663                 if (btcoexist->board_info.btdm_ant_num == 2)
1664                         ex_btc8821a2ant_media_status_notify(btcoexist, status);
1665                 else if (btcoexist->board_info.btdm_ant_num == 1)
1666                         ex_btc8821a1ant_media_status_notify(btcoexist, status);
1667         } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1668                 if (btcoexist->board_info.btdm_ant_num == 2)
1669                         ex_btc8723b2ant_media_status_notify(btcoexist, status);
1670                 else if (btcoexist->board_info.btdm_ant_num == 1)
1671                         ex_btc8723b1ant_media_status_notify(btcoexist, status);
1672         } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1673                 if (btcoexist->board_info.btdm_ant_num == 2)
1674                         ex_btc8192e2ant_media_status_notify(btcoexist, status);
1675         }
1676
1677         halbtc_normal_low_power(btcoexist);
1678 }
1679
1680 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
1681 {
1682         u8 packet_type;
1683
1684         if (!halbtc_is_bt_coexist_available(btcoexist))
1685                 return;
1686         btcoexist->statistics.cnt_special_packet_notify++;
1687         if (btcoexist->manual_control)
1688                 return;
1689
1690         if (pkt_type == PACKET_DHCP) {
1691                 packet_type = BTC_PACKET_DHCP;
1692         } else if (pkt_type == PACKET_EAPOL) {
1693                 packet_type = BTC_PACKET_EAPOL;
1694         } else if (pkt_type == PACKET_ARP) {
1695                 packet_type = BTC_PACKET_ARP;
1696         } else {
1697                 packet_type = BTC_PACKET_UNKNOWN;
1698                 return;
1699         }
1700
1701         halbtc_leave_low_power(btcoexist);
1702
1703         if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1704                 if (btcoexist->board_info.btdm_ant_num == 2)
1705                         ex_btc8821a2ant_special_packet_notify(btcoexist,
1706                                                               packet_type);
1707                 else if (btcoexist->board_info.btdm_ant_num == 1)
1708                         ex_btc8821a1ant_special_packet_notify(btcoexist,
1709                                                               packet_type);
1710         } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1711                 if (btcoexist->board_info.btdm_ant_num == 2)
1712                         ex_btc8723b2ant_special_packet_notify(btcoexist,
1713                                                               packet_type);
1714                 else if (btcoexist->board_info.btdm_ant_num == 1)
1715                         ex_btc8723b1ant_special_packet_notify(btcoexist,
1716                                                               packet_type);
1717         } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1718                 if (btcoexist->board_info.btdm_ant_num == 2)
1719                         ex_btc8192e2ant_special_packet_notify(btcoexist,
1720                                                               packet_type);
1721         }
1722
1723         halbtc_normal_low_power(btcoexist);
1724 }
1725
1726 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
1727                              u8 *tmp_buf, u8 length)
1728 {
1729         if (!halbtc_is_bt_coexist_available(btcoexist))
1730                 return;
1731         btcoexist->statistics.cnt_bt_info_notify++;
1732
1733         halbtc_leave_low_power(btcoexist);
1734
1735         if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1736                 if (btcoexist->board_info.btdm_ant_num == 2)
1737                         ex_btc8821a2ant_bt_info_notify(btcoexist, tmp_buf,
1738                                                        length);
1739                 else if (btcoexist->board_info.btdm_ant_num == 1)
1740                         ex_btc8821a1ant_bt_info_notify(btcoexist, tmp_buf,
1741                                                        length);
1742         } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1743                 if (btcoexist->board_info.btdm_ant_num == 2)
1744                         ex_btc8723b2ant_bt_info_notify(btcoexist, tmp_buf,
1745                                                        length);
1746                 else if (btcoexist->board_info.btdm_ant_num == 1)
1747                         ex_btc8723b1ant_bt_info_notify(btcoexist, tmp_buf,
1748                                                        length);
1749         } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1750                 if (btcoexist->board_info.btdm_ant_num == 2)
1751                         ex_btc8192e2ant_bt_info_notify(btcoexist, tmp_buf,
1752                                                        length);
1753         }
1754
1755         halbtc_normal_low_power(btcoexist);
1756 }
1757
1758 void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
1759 {
1760         if (!halbtc_is_bt_coexist_available(btcoexist))
1761                 return;
1762
1763         if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1764         } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1765                 if (btcoexist->board_info.btdm_ant_num == 1)
1766                         ex_btc8723b1ant_rf_status_notify(btcoexist, type);
1767         } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1768         }
1769 }
1770
1771 void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
1772 {
1773         u8 stack_op_type;
1774
1775         if (!halbtc_is_bt_coexist_available(btcoexist))
1776                 return;
1777         btcoexist->statistics.cnt_stack_operation_notify++;
1778         if (btcoexist->manual_control)
1779                 return;
1780
1781         if ((type == HCI_BT_OP_INQUIRY_START) ||
1782             (type == HCI_BT_OP_PAGING_START) ||
1783             (type == HCI_BT_OP_PAIRING_START)) {
1784                 stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_START;
1785         } else if ((type == HCI_BT_OP_INQUIRY_FINISH) ||
1786                    (type == HCI_BT_OP_PAGING_SUCCESS) ||
1787                    (type == HCI_BT_OP_PAGING_UNSUCCESS) ||
1788                    (type == HCI_BT_OP_PAIRING_FINISH)) {
1789                 stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
1790         } else {
1791                 stack_op_type = BTC_STACK_OP_NONE;
1792         }
1793 }
1794
1795 void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
1796 {
1797         if (!halbtc_is_bt_coexist_available(btcoexist))
1798                 return;
1799
1800         if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1801                 if (btcoexist->board_info.btdm_ant_num == 2)
1802                         ex_btc8821a2ant_halt_notify(btcoexist);
1803                 else if (btcoexist->board_info.btdm_ant_num == 1)
1804                         ex_btc8821a1ant_halt_notify(btcoexist);
1805         } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1806                 if (btcoexist->board_info.btdm_ant_num == 2)
1807                         ex_btc8723b2ant_halt_notify(btcoexist);
1808                 else if (btcoexist->board_info.btdm_ant_num == 1)
1809                         ex_btc8723b1ant_halt_notify(btcoexist);
1810         } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1811                 if (btcoexist->board_info.btdm_ant_num == 2)
1812                         ex_btc8192e2ant_halt_notify(btcoexist);
1813         }
1814
1815         btcoexist->binded = false;
1816 }
1817
1818 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
1819 {
1820         if (!halbtc_is_bt_coexist_available(btcoexist))
1821                 return;
1822
1823         /* currently only 1ant we have to do the notification,
1824          * once pnp is notified to sleep state, we have to leave LPS that
1825          * we can sleep normally.
1826          */
1827
1828         if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1829                 if (btcoexist->board_info.btdm_ant_num == 1)
1830                         ex_btc8723b1ant_pnp_notify(btcoexist, pnp_state);
1831                 else if (btcoexist->board_info.btdm_ant_num == 2)
1832                         ex_btc8723b2ant_pnp_notify(btcoexist, pnp_state);
1833         } else if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1834                 if (btcoexist->board_info.btdm_ant_num == 1)
1835                         ex_btc8821a1ant_pnp_notify(btcoexist, pnp_state);
1836                 else if (btcoexist->board_info.btdm_ant_num == 2)
1837                         ex_btc8821a2ant_pnp_notify(btcoexist, pnp_state);
1838         } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1839         }
1840 }
1841
1842 void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist)
1843 {
1844         struct rtl_priv *rtlpriv = btcoexist->adapter;
1845
1846         if (!halbtc_is_bt_coexist_available(btcoexist))
1847                 return;
1848         btcoexist->statistics.cnt_coex_dm_switch++;
1849
1850         halbtc_leave_low_power(btcoexist);
1851
1852         if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1853                 if (btcoexist->board_info.btdm_ant_num == 1) {
1854                         btcoexist->stop_coex_dm = true;
1855                         ex_btc8723b1ant_coex_dm_reset(btcoexist);
1856                         exhalbtc_set_ant_num(rtlpriv,
1857                                              BT_COEX_ANT_TYPE_DETECTED, 2);
1858                         ex_btc8723b2ant_init_hwconfig(btcoexist);
1859                         ex_btc8723b2ant_init_coex_dm(btcoexist);
1860                         btcoexist->stop_coex_dm = false;
1861                 }
1862         }
1863
1864         halbtc_normal_low_power(btcoexist);
1865 }
1866
1867 void exhalbtc_periodical(struct btc_coexist *btcoexist)
1868 {
1869         if (!halbtc_is_bt_coexist_available(btcoexist))
1870                 return;
1871         btcoexist->statistics.cnt_periodical++;
1872
1873         halbtc_leave_low_power(btcoexist);
1874
1875         if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1876                 if (btcoexist->board_info.btdm_ant_num == 2)
1877                         ex_btc8821a2ant_periodical(btcoexist);
1878                 else if (btcoexist->board_info.btdm_ant_num == 1)
1879                         if (!halbtc_under_ips(btcoexist))
1880                                 ex_btc8821a1ant_periodical(btcoexist);
1881         } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1882                 if (btcoexist->board_info.btdm_ant_num == 2)
1883                         ex_btc8723b2ant_periodical(btcoexist);
1884                 else if (btcoexist->board_info.btdm_ant_num == 1)
1885                         ex_btc8723b1ant_periodical(btcoexist);
1886         } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1887                 if (btcoexist->board_info.btdm_ant_num == 2)
1888                         ex_btc8192e2ant_periodical(btcoexist);
1889         }
1890
1891         halbtc_normal_low_power(btcoexist);
1892 }
1893
1894 void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
1895                           u8 code, u8 len, u8 *data)
1896 {
1897         if (!halbtc_is_bt_coexist_available(btcoexist))
1898                 return;
1899         btcoexist->statistics.cnt_dbg_ctrl++;
1900
1901         halbtc_leave_low_power(btcoexist);
1902
1903         halbtc_normal_low_power(btcoexist);
1904 }
1905
1906 void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq,
1907                                 u32 offset, u32 span, u32 seconds)
1908 {
1909         if (!halbtc_is_bt_coexist_available(btcoexist))
1910                 return;
1911 }
1912
1913 void exhalbtc_stack_update_profile_info(void)
1914 {
1915 }
1916
1917 void exhalbtc_update_min_bt_rssi(struct btc_coexist *btcoexist, s8 bt_rssi)
1918 {
1919         if (!halbtc_is_bt_coexist_available(btcoexist))
1920                 return;
1921
1922         btcoexist->stack_info.min_bt_rssi = bt_rssi;
1923 }
1924
1925 void exhalbtc_set_hci_version(struct btc_coexist *btcoexist, u16 hci_version)
1926 {
1927         if (!halbtc_is_bt_coexist_available(btcoexist))
1928                 return;
1929
1930         btcoexist->stack_info.hci_version = hci_version;
1931 }
1932
1933 void exhalbtc_set_bt_patch_version(struct btc_coexist *btcoexist,
1934                                    u16 bt_hci_version, u16 bt_patch_version)
1935 {
1936         if (!halbtc_is_bt_coexist_available(btcoexist))
1937                 return;
1938
1939         btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
1940         btcoexist->bt_info.bt_hci_ver = bt_hci_version;
1941 }
1942
1943 void exhalbtc_set_chip_type(struct btc_coexist *btcoexist, u8 chip_type)
1944 {
1945         switch (chip_type) {
1946         default:
1947         case BT_2WIRE:
1948         case BT_ISSC_3WIRE:
1949         case BT_ACCEL:
1950         case BT_RTL8756:
1951                 btcoexist->board_info.bt_chip_type = BTC_CHIP_UNDEF;
1952                 break;
1953         case BT_CSR_BC4:
1954                 btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
1955                 break;
1956         case BT_CSR_BC8:
1957                 btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
1958                 break;
1959         case BT_RTL8723A:
1960                 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723A;
1961                 break;
1962         case BT_RTL8821A:
1963                 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8821;
1964                 break;
1965         case BT_RTL8723B:
1966                 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723B;
1967                 break;
1968         }
1969 }
1970
1971 void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num)
1972 {
1973         struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1974
1975         if (!btcoexist)
1976                 return;
1977
1978         if (BT_COEX_ANT_TYPE_PG == type) {
1979                 btcoexist->board_info.pg_ant_num = ant_num;
1980                 btcoexist->board_info.btdm_ant_num = ant_num;
1981         } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1982                 btcoexist->board_info.btdm_ant_num = ant_num;
1983         } else if (type == BT_COEX_ANT_TYPE_DETECTED) {
1984                 btcoexist->board_info.btdm_ant_num = ant_num;
1985                 if (rtlpriv->cfg->mod_params->ant_sel == 1)
1986                         btcoexist->board_info.btdm_ant_pos =
1987                                 BTC_ANTENNA_AT_AUX_PORT;
1988                 else
1989                         btcoexist->board_info.btdm_ant_pos =
1990                                 BTC_ANTENNA_AT_MAIN_PORT;
1991         }
1992 }
1993
1994 /* Currently used by 8723b only, S0 or S1 */
1995 void exhalbtc_set_single_ant_path(struct btc_coexist *btcoexist,
1996                                   u8 single_ant_path)
1997 {
1998         btcoexist->board_info.single_ant_path = single_ant_path;
1999 }
2000
2001 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist,
2002                                    struct seq_file *m)
2003 {
2004         if (!halbtc_is_bt_coexist_available(btcoexist))
2005                 return;
2006
2007         halbtc_leave_low_power(btcoexist);
2008
2009         if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
2010                 if (btcoexist->board_info.btdm_ant_num == 2)
2011                         ex_btc8821a2ant_display_coex_info(btcoexist, m);
2012                 else if (btcoexist->board_info.btdm_ant_num == 1)
2013                         ex_btc8821a1ant_display_coex_info(btcoexist, m);
2014         } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
2015                 if (btcoexist->board_info.btdm_ant_num == 2)
2016                         ex_btc8723b2ant_display_coex_info(btcoexist, m);
2017                 else if (btcoexist->board_info.btdm_ant_num == 1)
2018                         ex_btc8723b1ant_display_coex_info(btcoexist, m);
2019         } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
2020                 if (btcoexist->board_info.btdm_ant_num == 2)
2021                         ex_btc8192e2ant_display_coex_info(btcoexist, m);
2022         }
2023
2024         halbtc_normal_low_power(btcoexist);
2025 }
2026
2027 void exhalbtc_switch_band_notify(struct btc_coexist *btcoexist, u8 type)
2028 {
2029         if (!halbtc_is_bt_coexist_available(btcoexist))
2030                 return;
2031
2032         if (btcoexist->manual_control)
2033                 return;
2034
2035         halbtc_leave_low_power(btcoexist);
2036
2037         halbtc_normal_low_power(btcoexist);
2038 }
2039
2040 void exhalbtc_switch_band_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
2041                                            u8 is_5g)
2042 {
2043 }