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 * Global variables
30 ***********************************************/
31
32 struct btc_coexist gl_bt_coexist;
33
34 u32 btc_dbg_type[BTC_MSG_MAX];
35
36 /***************************************************
37 * Debug related function
38 ***************************************************/
39
40 const char *const gl_btc_wifi_bw_string[] = {
41 "11bg",
42 "HT20",
43 "HT40",
44 "HT80",
45 "HT160"
46 };
47
48 const char *const gl_btc_wifi_freq_string[] = {
49 "2.4G",
50 "5G"
51 };
52
halbtc_is_bt_coexist_available(struct btc_coexist * btcoexist)53 static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
54 {
55 if (!btcoexist->binded || NULL == btcoexist->adapter)
56 return false;
57
58 return true;
59 }
60
halbtc_is_wifi_busy(struct rtl_priv * rtlpriv)61 static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
62 {
63 if (rtlpriv->link_info.busytraffic)
64 return true;
65 else
66 return false;
67 }
68
halbtc_dbg_init(void)69 static void halbtc_dbg_init(void)
70 {
71 }
72
73 /***************************************************
74 * helper function
75 ***************************************************/
is_any_client_connect_to_ap(struct btc_coexist * btcoexist)76 static bool is_any_client_connect_to_ap(struct btc_coexist *btcoexist)
77 {
78 struct rtl_priv *rtlpriv = btcoexist->adapter;
79 struct rtl_mac *mac = rtl_mac(rtlpriv);
80 struct rtl_sta_info *drv_priv;
81 u8 cnt = 0;
82
83 if (mac->opmode == NL80211_IFTYPE_ADHOC ||
84 mac->opmode == NL80211_IFTYPE_MESH_POINT ||
85 mac->opmode == NL80211_IFTYPE_AP) {
86 if (in_interrupt() > 0) {
87 list_for_each_entry(drv_priv, &rtlpriv->entry_list,
88 list) {
89 cnt++;
90 }
91 } else {
92 spin_lock_bh(&rtlpriv->locks.entry_list_lock);
93 list_for_each_entry(drv_priv, &rtlpriv->entry_list,
94 list) {
95 cnt++;
96 }
97 spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
98 }
99 }
100 if (cnt > 0)
101 return true;
102 else
103 return false;
104 }
105
halbtc_is_bt40(struct rtl_priv * adapter)106 static bool halbtc_is_bt40(struct rtl_priv *adapter)
107 {
108 struct rtl_priv *rtlpriv = adapter;
109 struct rtl_phy *rtlphy = &(rtlpriv->phy);
110 bool is_ht40 = true;
111 enum ht_channel_width bw = rtlphy->current_chan_bw;
112
113 if (bw == HT_CHANNEL_WIDTH_20)
114 is_ht40 = false;
115 else if (bw == HT_CHANNEL_WIDTH_20_40)
116 is_ht40 = true;
117
118 return is_ht40;
119 }
120
halbtc_legacy(struct rtl_priv * adapter)121 static bool halbtc_legacy(struct rtl_priv *adapter)
122 {
123 struct rtl_priv *rtlpriv = adapter;
124 struct rtl_mac *mac = rtl_mac(rtlpriv);
125
126 bool is_legacy = false;
127
128 if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G))
129 is_legacy = true;
130
131 return is_legacy;
132 }
133
halbtc_is_wifi_uplink(struct rtl_priv * adapter)134 bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
135 {
136 struct rtl_priv *rtlpriv = adapter;
137
138 if (rtlpriv->link_info.tx_busy_traffic)
139 return true;
140 else
141 return false;
142 }
143
halbtc_get_wifi_bw(struct btc_coexist * btcoexist)144 static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
145 {
146 struct rtl_priv *rtlpriv =
147 (struct rtl_priv *)btcoexist->adapter;
148 u32 wifi_bw = BTC_WIFI_BW_HT20;
149
150 if (halbtc_is_bt40(rtlpriv)) {
151 wifi_bw = BTC_WIFI_BW_HT40;
152 } else {
153 if (halbtc_legacy(rtlpriv))
154 wifi_bw = BTC_WIFI_BW_LEGACY;
155 else
156 wifi_bw = BTC_WIFI_BW_HT20;
157 }
158 return wifi_bw;
159 }
160
halbtc_get_wifi_central_chnl(struct btc_coexist * btcoexist)161 static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
162 {
163 struct rtl_priv *rtlpriv = btcoexist->adapter;
164 struct rtl_phy *rtlphy = &(rtlpriv->phy);
165 u8 chnl = 1;
166
167 if (rtlphy->current_channel != 0)
168 chnl = rtlphy->current_channel;
169 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
170 "static halbtc_get_wifi_central_chnl:%d\n", chnl);
171 return chnl;
172 }
173
rtl_get_hwpg_single_ant_path(struct rtl_priv * rtlpriv)174 u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv)
175 {
176 return rtlpriv->btcoexist.btc_info.single_ant_path;
177 }
178
rtl_get_hwpg_bt_type(struct rtl_priv * rtlpriv)179 u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
180 {
181 return rtlpriv->btcoexist.btc_info.bt_type;
182 }
183
rtl_get_hwpg_ant_num(struct rtl_priv * rtlpriv)184 u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
185 {
186 u8 num;
187
188 if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
189 num = 2;
190 else
191 num = 1;
192
193 return num;
194 }
195
rtl_get_hwpg_package_type(struct rtl_priv * rtlpriv)196 u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv)
197 {
198 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
199
200 return rtlhal->package_type;
201 }
202
halbtc_leave_lps(struct btc_coexist * btcoexist)203 static void halbtc_leave_lps(struct btc_coexist *btcoexist)
204 {
205 struct rtl_priv *rtlpriv;
206 struct rtl_ps_ctl *ppsc;
207 bool ap_enable = false;
208
209 rtlpriv = btcoexist->adapter;
210 ppsc = rtl_psc(rtlpriv);
211
212 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
213 &ap_enable);
214
215 if (ap_enable) {
216 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
217 "%s()<--dont leave lps under AP mode\n", __func__);
218 return;
219 }
220
221 btcoexist->bt_info.bt_ctrl_lps = true;
222 btcoexist->bt_info.bt_lps_on = false;
223 rtl_lps_leave(rtlpriv->mac80211.hw);
224 }
225
halbtc_enter_lps(struct btc_coexist * btcoexist)226 static void halbtc_enter_lps(struct btc_coexist *btcoexist)
227 {
228 struct rtl_priv *rtlpriv;
229 struct rtl_ps_ctl *ppsc;
230 bool ap_enable = false;
231
232 rtlpriv = btcoexist->adapter;
233 ppsc = rtl_psc(rtlpriv);
234
235 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
236 &ap_enable);
237
238 if (ap_enable) {
239 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
240 "%s()<--dont enter lps under AP mode\n", __func__);
241 return;
242 }
243
244 btcoexist->bt_info.bt_ctrl_lps = true;
245 btcoexist->bt_info.bt_lps_on = true;
246 rtl_lps_enter(rtlpriv->mac80211.hw);
247 }
248
halbtc_normal_lps(struct btc_coexist * btcoexist)249 static void halbtc_normal_lps(struct btc_coexist *btcoexist)
250 {
251 struct rtl_priv *rtlpriv;
252
253 rtlpriv = btcoexist->adapter;
254
255 if (btcoexist->bt_info.bt_ctrl_lps) {
256 btcoexist->bt_info.bt_lps_on = false;
257 rtl_lps_leave(rtlpriv->mac80211.hw);
258 btcoexist->bt_info.bt_ctrl_lps = false;
259 }
260 }
261
halbtc_leave_low_power(struct btc_coexist * btcoexist)262 static void halbtc_leave_low_power(struct btc_coexist *btcoexist)
263 {
264 }
265
halbtc_normal_low_power(struct btc_coexist * btcoexist)266 static void halbtc_normal_low_power(struct btc_coexist *btcoexist)
267 {
268 }
269
halbtc_disable_low_power(struct btc_coexist * btcoexist,bool low_pwr_disable)270 static void halbtc_disable_low_power(struct btc_coexist *btcoexist,
271 bool low_pwr_disable)
272 {
273 /* TODO: original/leave 32k low power */
274 btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable;
275 }
276
halbtc_aggregation_check(struct btc_coexist * btcoexist)277 static void halbtc_aggregation_check(struct btc_coexist *btcoexist)
278 {
279 bool need_to_act = false;
280 static unsigned long pre_time;
281 unsigned long cur_time = 0;
282 struct rtl_priv *rtlpriv = btcoexist->adapter;
283
284 /* To void continuous deleteBA=>addBA=>deleteBA=>addBA
285 * This function is not allowed to continuous called
286 * It can only be called after 8 seconds
287 */
288
289 cur_time = jiffies;
290 if (jiffies_to_msecs(cur_time - pre_time) <= 8000) {
291 /* over 8 seconds you can execute this function again. */
292 return;
293 }
294 pre_time = cur_time;
295
296 if (btcoexist->bt_info.reject_agg_pkt) {
297 need_to_act = true;
298 btcoexist->bt_info.pre_reject_agg_pkt =
299 btcoexist->bt_info.reject_agg_pkt;
300 } else {
301 if (btcoexist->bt_info.pre_reject_agg_pkt) {
302 need_to_act = true;
303 btcoexist->bt_info.pre_reject_agg_pkt =
304 btcoexist->bt_info.reject_agg_pkt;
305 }
306
307 if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
308 btcoexist->bt_info.bt_ctrl_agg_buf_size) {
309 need_to_act = true;
310 btcoexist->bt_info.pre_bt_ctrl_agg_buf_size =
311 btcoexist->bt_info.bt_ctrl_agg_buf_size;
312 }
313
314 if (btcoexist->bt_info.bt_ctrl_agg_buf_size) {
315 if (btcoexist->bt_info.pre_agg_buf_size !=
316 btcoexist->bt_info.agg_buf_size) {
317 need_to_act = true;
318 }
319 btcoexist->bt_info.pre_agg_buf_size =
320 btcoexist->bt_info.agg_buf_size;
321 }
322
323 if (need_to_act)
324 rtl_rx_ampdu_apply(rtlpriv);
325 }
326 }
327
halbtc_get_bt_patch_version(struct btc_coexist * btcoexist)328 static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
329 {
330 struct rtl_priv *rtlpriv = btcoexist->adapter;
331 u8 cmd_buffer[4] = {0};
332 u8 oper_ver = 0;
333 u8 req_num = 0x0E;
334
335 if (btcoexist->bt_info.bt_real_fw_ver)
336 goto label_done;
337
338 cmd_buffer[0] |= (oper_ver & 0x0f); /* Set OperVer */
339 cmd_buffer[0] |= ((req_num << 4) & 0xf0); /* Set ReqNum */
340 cmd_buffer[1] = 0; /* BT_OP_GET_BT_VERSION = 0 */
341 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, 4,
342 &cmd_buffer[0]);
343
344 label_done:
345 return btcoexist->bt_info.bt_real_fw_ver;
346 }
347
halbtc_get_wifi_link_status(struct btc_coexist * btcoexist)348 u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist)
349 {
350 /* return value:
351 * [31:16] => connected port number
352 * [15:0] => port connected bit define
353 */
354 struct rtl_priv *rtlpriv = btcoexist->adapter;
355 struct rtl_mac *mac = rtl_mac(rtlpriv);
356 u32 ret_val = 0;
357 u32 port_connected_status = 0, num_of_connected_port = 0;
358
359 if (mac->opmode == NL80211_IFTYPE_STATION &&
360 mac->link_state >= MAC80211_LINKED) {
361 port_connected_status |= WIFI_STA_CONNECTED;
362 num_of_connected_port++;
363 }
364 /* AP & ADHOC & MESH */
365 if (is_any_client_connect_to_ap(btcoexist)) {
366 port_connected_status |= WIFI_AP_CONNECTED;
367 num_of_connected_port++;
368 }
369 /* TODO: P2P Connected Status */
370
371 ret_val = (num_of_connected_port << 16) | port_connected_status;
372
373 return ret_val;
374 }
375
halbtc_get_wifi_rssi(struct rtl_priv * rtlpriv)376 static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv)
377 {
378 int undec_sm_pwdb = 0;
379
380 if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
381 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
382 else /* associated entry pwdb */
383 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
384 return undec_sm_pwdb;
385 }
386
halbtc_get(void * void_btcoexist,u8 get_type,void * out_buf)387 static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
388 {
389 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
390 struct rtl_priv *rtlpriv = btcoexist->adapter;
391 struct rtl_phy *rtlphy = &(rtlpriv->phy);
392 struct rtl_mac *mac = rtl_mac(rtlpriv);
393 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
394 bool *bool_tmp = (bool *)out_buf;
395 int *s32_tmp = (int *)out_buf;
396 u32 *u32_tmp = (u32 *)out_buf;
397 u8 *u8_tmp = (u8 *)out_buf;
398 bool tmp = false;
399 bool ret = true;
400
401 if (!halbtc_is_bt_coexist_available(btcoexist))
402 return false;
403
404 switch (get_type) {
405 case BTC_GET_BL_HS_OPERATION:
406 *bool_tmp = false;
407 ret = false;
408 break;
409 case BTC_GET_BL_HS_CONNECTING:
410 *bool_tmp = false;
411 ret = false;
412 break;
413 case BTC_GET_BL_WIFI_CONNECTED:
414 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
415 rtlpriv->mac80211.link_state >= MAC80211_LINKED)
416 tmp = true;
417 if (is_any_client_connect_to_ap(btcoexist))
418 tmp = true;
419 *bool_tmp = tmp;
420 break;
421 case BTC_GET_BL_WIFI_BUSY:
422 if (halbtc_is_wifi_busy(rtlpriv))
423 *bool_tmp = true;
424 else
425 *bool_tmp = false;
426 break;
427 case BTC_GET_BL_WIFI_SCAN:
428 if (mac->act_scanning)
429 *bool_tmp = true;
430 else
431 *bool_tmp = false;
432 break;
433 case BTC_GET_BL_WIFI_LINK:
434 if (mac->link_state == MAC80211_LINKING)
435 *bool_tmp = true;
436 else
437 *bool_tmp = false;
438 break;
439 case BTC_GET_BL_WIFI_ROAM:
440 if (mac->link_state == MAC80211_LINKING)
441 *bool_tmp = true;
442 else
443 *bool_tmp = false;
444 break;
445 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
446 *bool_tmp = rtlpriv->btcoexist.btc_info.in_4way;
447 break;
448 case BTC_GET_BL_WIFI_UNDER_5G:
449 if (rtlhal->current_bandtype == BAND_ON_5G)
450 *bool_tmp = true;
451 else
452 *bool_tmp = false;
453 break;
454 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
455 if (mac->opmode == NL80211_IFTYPE_AP)
456 *bool_tmp = true;
457 else
458 *bool_tmp = false;
459 break;
460 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
461 if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm)
462 *bool_tmp = false;
463 else
464 *bool_tmp = true;
465 break;
466 case BTC_GET_BL_WIFI_UNDER_B_MODE:
467 if (rtlpriv->mac80211.mode == WIRELESS_MODE_B)
468 *bool_tmp = true;
469 else
470 *bool_tmp = false;
471 break;
472 case BTC_GET_BL_EXT_SWITCH:
473 *bool_tmp = false;
474 break;
475 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
476 *bool_tmp = false;
477 break;
478 case BTC_GET_BL_IS_ASUS_8723B:
479 *bool_tmp = false;
480 break;
481 case BTC_GET_S4_WIFI_RSSI:
482 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
483 break;
484 case BTC_GET_S4_HS_RSSI:
485 *s32_tmp = 0;
486 ret = false;
487 break;
488 case BTC_GET_U4_WIFI_BW:
489 *u32_tmp = halbtc_get_wifi_bw(btcoexist);
490 break;
491 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
492 if (halbtc_is_wifi_uplink(rtlpriv))
493 *u32_tmp = BTC_WIFI_TRAFFIC_TX;
494 else
495 *u32_tmp = BTC_WIFI_TRAFFIC_RX;
496 break;
497 case BTC_GET_U4_WIFI_FW_VER:
498 *u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion;
499 break;
500 case BTC_GET_U4_WIFI_LINK_STATUS:
501 *u32_tmp = halbtc_get_wifi_link_status(btcoexist);
502 break;
503 case BTC_GET_U4_BT_PATCH_VER:
504 *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
505 break;
506 case BTC_GET_U4_VENDOR:
507 *u32_tmp = BTC_VENDOR_OTHER;
508 break;
509 case BTC_GET_U1_WIFI_DOT11_CHNL:
510 *u8_tmp = rtlphy->current_channel;
511 break;
512 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
513 *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
514 break;
515 case BTC_GET_U1_WIFI_HS_CHNL:
516 *u8_tmp = 0;
517 ret = false;
518 break;
519 case BTC_GET_U1_AP_NUM:
520 *u8_tmp = rtlpriv->btcoexist.btc_info.ap_num;
521 break;
522 case BTC_GET_U1_ANT_TYPE:
523 *u8_tmp = (u8)BTC_ANT_TYPE_0;
524 break;
525 case BTC_GET_U1_IOT_PEER:
526 *u8_tmp = 0;
527 break;
528
529 /************* 1Ant **************/
530 case BTC_GET_U1_LPS_MODE:
531 *u8_tmp = btcoexist->pwr_mode_val[0];
532 break;
533
534 default:
535 ret = false;
536 break;
537 }
538
539 return ret;
540 }
541
halbtc_set(void * void_btcoexist,u8 set_type,void * in_buf)542 static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
543 {
544 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
545 bool *bool_tmp = (bool *)in_buf;
546 u8 *u8_tmp = (u8 *)in_buf;
547 u32 *u32_tmp = (u32 *)in_buf;
548 bool ret = true;
549
550 if (!halbtc_is_bt_coexist_available(btcoexist))
551 return false;
552
553 switch (set_type) {
554 /* set some bool type variables. */
555 case BTC_SET_BL_BT_DISABLE:
556 btcoexist->bt_info.bt_disabled = *bool_tmp;
557 break;
558 case BTC_SET_BL_BT_TRAFFIC_BUSY:
559 btcoexist->bt_info.bt_busy = *bool_tmp;
560 break;
561 case BTC_SET_BL_BT_LIMITED_DIG:
562 btcoexist->bt_info.limited_dig = *bool_tmp;
563 break;
564 case BTC_SET_BL_FORCE_TO_ROAM:
565 btcoexist->bt_info.force_to_roam = *bool_tmp;
566 break;
567 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
568 btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
569 break;
570 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
571 btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp;
572 break;
573 case BTC_SET_BL_INC_SCAN_DEV_NUM:
574 btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
575 break;
576 case BTC_SET_BL_BT_TX_RX_MASK:
577 btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp;
578 break;
579 case BTC_SET_BL_MIRACAST_PLUS_BT:
580 btcoexist->bt_info.miracast_plus_bt = *bool_tmp;
581 break;
582 /* set some u1Byte type variables. */
583 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
584 btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
585 break;
586 case BTC_SET_U1_AGG_BUF_SIZE:
587 btcoexist->bt_info.agg_buf_size = *u8_tmp;
588 break;
589
590 /* the following are some action which will be triggered */
591 case BTC_SET_ACT_GET_BT_RSSI:
592 ret = false;
593 break;
594 case BTC_SET_ACT_AGGREGATE_CTRL:
595 halbtc_aggregation_check(btcoexist);
596 break;
597
598 /* 1Ant */
599 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
600 btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
601 break;
602 case BTC_SET_UI_SCAN_SIG_COMPENSATION:
603 break;
604 case BTC_SET_U1_LPS_VAL:
605 btcoexist->bt_info.lps_val = *u8_tmp;
606 break;
607 case BTC_SET_U1_RPWM_VAL:
608 btcoexist->bt_info.rpwm_val = *u8_tmp;
609 break;
610 /* the following are some action which will be triggered */
611 case BTC_SET_ACT_LEAVE_LPS:
612 halbtc_leave_lps(btcoexist);
613 break;
614 case BTC_SET_ACT_ENTER_LPS:
615 halbtc_enter_lps(btcoexist);
616 break;
617 case BTC_SET_ACT_NORMAL_LPS:
618 halbtc_normal_lps(btcoexist);
619 break;
620 case BTC_SET_ACT_DISABLE_LOW_POWER:
621 halbtc_disable_low_power(btcoexist, *bool_tmp);
622 break;
623 case BTC_SET_ACT_UPDATE_RAMASK:
624 btcoexist->bt_info.ra_mask = *u32_tmp;
625 break;
626 case BTC_SET_ACT_SEND_MIMO_PS:
627 break;
628 case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
629 break;
630 case BTC_SET_ACT_CTRL_BT_COEX:
631 break;
632 case BTC_SET_ACT_CTRL_8723B_ANT:
633 break;
634 default:
635 break;
636 }
637
638 return ret;
639 }
640
641 /************************************************************
642 * IO related function
643 ************************************************************/
halbtc_read_1byte(void * bt_context,u32 reg_addr)644 static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
645 {
646 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
647 struct rtl_priv *rtlpriv = btcoexist->adapter;
648
649 return rtl_read_byte(rtlpriv, reg_addr);
650 }
651
halbtc_read_2byte(void * bt_context,u32 reg_addr)652 static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
653 {
654 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
655 struct rtl_priv *rtlpriv = btcoexist->adapter;
656
657 return rtl_read_word(rtlpriv, reg_addr);
658 }
659
halbtc_read_4byte(void * bt_context,u32 reg_addr)660 static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
661 {
662 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
663 struct rtl_priv *rtlpriv = btcoexist->adapter;
664
665 return rtl_read_dword(rtlpriv, reg_addr);
666 }
667
halbtc_write_1byte(void * bt_context,u32 reg_addr,u32 data)668 static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data)
669 {
670 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
671 struct rtl_priv *rtlpriv = btcoexist->adapter;
672
673 rtl_write_byte(rtlpriv, reg_addr, data);
674 }
675
halbtc_bitmask_write_1byte(void * bt_context,u32 reg_addr,u32 bit_mask,u8 data)676 static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
677 u32 bit_mask, u8 data)
678 {
679 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
680 struct rtl_priv *rtlpriv = btcoexist->adapter;
681 u8 original_value, bit_shift = 0;
682 u8 i;
683
684 if (bit_mask != MASKDWORD) {/*if not "double word" write*/
685 original_value = rtl_read_byte(rtlpriv, reg_addr);
686 for (i = 0; i <= 7; i++) {
687 if ((bit_mask>>i) & 0x1)
688 break;
689 }
690 bit_shift = i;
691 data = (original_value & (~bit_mask)) |
692 ((data << bit_shift) & bit_mask);
693 }
694 rtl_write_byte(rtlpriv, reg_addr, data);
695 }
696
halbtc_write_2byte(void * bt_context,u32 reg_addr,u16 data)697 static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
698 {
699 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
700 struct rtl_priv *rtlpriv = btcoexist->adapter;
701
702 rtl_write_word(rtlpriv, reg_addr, data);
703 }
704
halbtc_write_4byte(void * bt_context,u32 reg_addr,u32 data)705 static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
706 {
707 struct btc_coexist *btcoexist =
708 (struct btc_coexist *)bt_context;
709 struct rtl_priv *rtlpriv = btcoexist->adapter;
710
711 rtl_write_dword(rtlpriv, reg_addr, data);
712 }
713
halbtc_write_local_reg_1byte(void * btc_context,u32 reg_addr,u8 data)714 void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr, u8 data)
715 {
716 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
717 struct rtl_priv *rtlpriv = btcoexist->adapter;
718
719 if (btcoexist->chip_interface == BTC_INTF_SDIO)
720 ;
721 else if (btcoexist->chip_interface == BTC_INTF_PCI)
722 rtl_write_byte(rtlpriv, reg_addr, data);
723 else if (btcoexist->chip_interface == BTC_INTF_USB)
724 rtl_write_byte(rtlpriv, reg_addr, data);
725 }
726
halbtc_set_macreg(void * btc_context,u32 reg_addr,u32 bit_mask,u32 data)727 void halbtc_set_macreg(void *btc_context, u32 reg_addr, u32 bit_mask, u32 data)
728 {
729 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
730 struct rtl_priv *rtlpriv = btcoexist->adapter;
731
732 rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
733 }
734
halbtc_get_macreg(void * btc_context,u32 reg_addr,u32 bit_mask)735 u32 halbtc_get_macreg(void *btc_context, u32 reg_addr, u32 bit_mask)
736 {
737 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
738 struct rtl_priv *rtlpriv = btcoexist->adapter;
739
740 return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
741 }
742
halbtc_set_bbreg(void * bt_context,u32 reg_addr,u32 bit_mask,u32 data)743 static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
744 u32 data)
745 {
746 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
747 struct rtl_priv *rtlpriv = btcoexist->adapter;
748
749 rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
750 }
751
halbtc_get_bbreg(void * bt_context,u32 reg_addr,u32 bit_mask)752 static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
753 {
754 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
755 struct rtl_priv *rtlpriv = btcoexist->adapter;
756
757 return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
758 }
759
halbtc_set_rfreg(void * bt_context,u8 rf_path,u32 reg_addr,u32 bit_mask,u32 data)760 static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
761 u32 bit_mask, u32 data)
762 {
763 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
764 struct rtl_priv *rtlpriv = btcoexist->adapter;
765
766 rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
767 }
768
halbtc_get_rfreg(void * bt_context,u8 rf_path,u32 reg_addr,u32 bit_mask)769 static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
770 u32 bit_mask)
771 {
772 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
773 struct rtl_priv *rtlpriv = btcoexist->adapter;
774
775 return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
776 }
777
halbtc_fill_h2c_cmd(void * bt_context,u8 element_id,u32 cmd_len,u8 * cmd_buf)778 static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
779 u32 cmd_len, u8 *cmd_buf)
780 {
781 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
782 struct rtl_priv *rtlpriv = btcoexist->adapter;
783
784 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
785 cmd_len, cmd_buf);
786 }
787
halbtc_set_bt_reg(void * btc_context,u8 reg_type,u32 offset,u32 set_val)788 void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val)
789 {
790 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
791 struct rtl_priv *rtlpriv = btcoexist->adapter;
792 u8 cmd_buffer1[4] = {0};
793 u8 cmd_buffer2[4] = {0};
794 u8 *addr_to_set = (u8 *)&offset;
795 u8 *value_to_set = (u8 *)&set_val;
796 u8 oper_ver = 0;
797 u8 req_num = 0;
798
799 if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
800 cmd_buffer1[0] |= (oper_ver & 0x0f); /* Set OperVer */
801 cmd_buffer1[0] |= ((req_num << 4) & 0xf0); /* Set ReqNum */
802 cmd_buffer1[1] = 0x0d; /* OpCode: BT_LO_OP_WRITE_REG_VALUE */
803 cmd_buffer1[2] = value_to_set[0]; /* Set WriteRegValue */
804 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, 4,
805 &cmd_buffer1[0]);
806
807 msleep(200);
808 req_num++;
809
810 cmd_buffer2[0] |= (oper_ver & 0x0f); /* Set OperVer */
811 cmd_buffer2[0] |= ((req_num << 4) & 0xf0); /* Set ReqNum */
812 cmd_buffer2[1] = 0x0c; /* OpCode: BT_LO_OP_WRITE_REG_ADDR */
813 cmd_buffer2[3] = addr_to_set[0]; /* Set WriteRegAddr */
814 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, 4,
815 &cmd_buffer2[0]);
816 }
817 }
818
halbtc_under_ips(struct btc_coexist * btcoexist)819 bool halbtc_under_ips(struct btc_coexist *btcoexist)
820 {
821 struct rtl_priv *rtlpriv = btcoexist->adapter;
822 struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
823 enum rf_pwrstate rtstate;
824
825 if (ppsc->inactiveps) {
826 rtstate = ppsc->rfpwr_state;
827
828 if (rtstate != ERFON &&
829 ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
830 return true;
831 }
832 }
833
834 return false;
835 }
836
837 /*****************************************************************
838 * Extern functions called by other module
839 *****************************************************************/
exhalbtc_initlize_variables(void)840 bool exhalbtc_initlize_variables(void)
841 {
842 struct btc_coexist *btcoexist = &gl_bt_coexist;
843
844 halbtc_dbg_init();
845
846 btcoexist->btc_read_1byte = halbtc_read_1byte;
847 btcoexist->btc_write_1byte = halbtc_write_1byte;
848 btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
849 btcoexist->btc_read_2byte = halbtc_read_2byte;
850 btcoexist->btc_write_2byte = halbtc_write_2byte;
851 btcoexist->btc_read_4byte = halbtc_read_4byte;
852 btcoexist->btc_write_4byte = halbtc_write_4byte;
853 btcoexist->btc_write_local_reg_1byte = halbtc_write_local_reg_1byte;
854
855 btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
856 btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
857
858 btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
859 btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
860
861 btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
862
863 btcoexist->btc_get = halbtc_get;
864 btcoexist->btc_set = halbtc_set;
865 btcoexist->btc_set_bt_reg = halbtc_set_bt_reg;
866
867
868 btcoexist->bt_info.bt_ctrl_buf_size = false;
869 btcoexist->bt_info.agg_buf_size = 5;
870
871 btcoexist->bt_info.increase_scan_dev_num = false;
872 return true;
873 }
874
exhalbtc_bind_bt_coex_withadapter(void * adapter)875 bool exhalbtc_bind_bt_coex_withadapter(void *adapter)
876 {
877 struct btc_coexist *btcoexist = &gl_bt_coexist;
878 struct rtl_priv *rtlpriv = adapter;
879 u8 ant_num = 2, chip_type;
880
881 if (btcoexist->binded)
882 return false;
883
884 switch (rtlpriv->rtlhal.interface) {
885 case INTF_PCI:
886 btcoexist->chip_interface = BTC_INTF_PCI;
887 break;
888 case INTF_USB:
889 btcoexist->chip_interface = BTC_INTF_USB;
890 break;
891 default:
892 btcoexist->chip_interface = BTC_INTF_UNKNOWN;
893 break;
894 }
895
896 btcoexist->binded = true;
897 btcoexist->statistics.cnt_bind++;
898
899 btcoexist->adapter = adapter;
900
901 btcoexist->stack_info.profile_notified = false;
902
903 btcoexist->bt_info.bt_ctrl_agg_buf_size = false;
904 btcoexist->bt_info.agg_buf_size = 5;
905
906 btcoexist->bt_info.increase_scan_dev_num = false;
907 btcoexist->bt_info.miracast_plus_bt = false;
908
909 chip_type = rtl_get_hwpg_bt_type(rtlpriv);
910 exhalbtc_set_chip_type(chip_type);
911 ant_num = rtl_get_hwpg_ant_num(rtlpriv);
912 exhalbtc_set_ant_num(rtlpriv, BT_COEX_ANT_TYPE_PG, ant_num);
913
914 if (rtl_get_hwpg_package_type(rtlpriv) == 0)
915 btcoexist->board_info.tfbga_package = false;
916 else if (rtl_get_hwpg_package_type(rtlpriv) == 1)
917 btcoexist->board_info.tfbga_package = false;
918 else
919 btcoexist->board_info.tfbga_package = true;
920
921 if (btcoexist->board_info.tfbga_package)
922 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
923 "[BTCoex], Package Type = TFBGA\n");
924 else
925 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
926 "[BTCoex], Package Type = Non-TFBGA\n");
927
928 return true;
929 }
930
exhalbtc_power_on_setting(struct btc_coexist * btcoexist)931 void exhalbtc_power_on_setting(struct btc_coexist *btcoexist)
932 {
933 if (!halbtc_is_bt_coexist_available(btcoexist))
934 return;
935
936 btcoexist->statistics.cnt_power_on++;
937
938 if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
939 if (btcoexist->board_info.btdm_ant_num == 2)
940 ex_btc8723b2ant_power_on_setting(btcoexist);
941 else if (btcoexist->board_info.btdm_ant_num == 1)
942 ex_btc8723b1ant_power_on_setting(btcoexist);
943 }
944 }
945
exhalbtc_pre_load_firmware(struct btc_coexist * btcoexist)946 void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist)
947 {
948 if (!halbtc_is_bt_coexist_available(btcoexist))
949 return;
950
951 btcoexist->statistics.cnt_pre_load_firmware++;
952
953 if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
954 if (btcoexist->board_info.btdm_ant_num == 2)
955 ex_btc8723b2ant_pre_load_firmware(btcoexist);
956 }
957 }
958
exhalbtc_init_hw_config(struct btc_coexist * btcoexist,bool wifi_only)959 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only)
960 {
961 if (!halbtc_is_bt_coexist_available(btcoexist))
962 return;
963
964 btcoexist->statistics.cnt_init_hw_config++;
965
966 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
967 if (btcoexist->board_info.btdm_ant_num == 2)
968 ex_btc8821a2ant_init_hwconfig(btcoexist);
969 else if (btcoexist->board_info.btdm_ant_num == 1)
970 ex_btc8821a1ant_init_hwconfig(btcoexist, wifi_only);
971 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
972 if (btcoexist->board_info.btdm_ant_num == 2)
973 ex_btc8723b2ant_init_hwconfig(btcoexist);
974 else if (btcoexist->board_info.btdm_ant_num == 1)
975 ex_btc8723b1ant_init_hwconfig(btcoexist, wifi_only);
976 } else if (IS_HARDWARE_TYPE_8723A(btcoexist->adapter)) {
977 /* 8723A has no this function */
978 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
979 if (btcoexist->board_info.btdm_ant_num == 2)
980 ex_btc8192e2ant_init_hwconfig(btcoexist);
981 }
982 }
983
exhalbtc_init_coex_dm(struct btc_coexist * btcoexist)984 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
985 {
986 if (!halbtc_is_bt_coexist_available(btcoexist))
987 return;
988
989 btcoexist->statistics.cnt_init_coex_dm++;
990
991 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
992 if (btcoexist->board_info.btdm_ant_num == 2)
993 ex_btc8821a2ant_init_coex_dm(btcoexist);
994 else if (btcoexist->board_info.btdm_ant_num == 1)
995 ex_btc8821a1ant_init_coex_dm(btcoexist);
996 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
997 if (btcoexist->board_info.btdm_ant_num == 2)
998 ex_btc8723b2ant_init_coex_dm(btcoexist);
999 else if (btcoexist->board_info.btdm_ant_num == 1)
1000 ex_btc8723b1ant_init_coex_dm(btcoexist);
1001 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1002 if (btcoexist->board_info.btdm_ant_num == 2)
1003 ex_btc8192e2ant_init_coex_dm(btcoexist);
1004 }
1005
1006 btcoexist->initilized = true;
1007 }
1008
exhalbtc_ips_notify(struct btc_coexist * btcoexist,u8 type)1009 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
1010 {
1011 u8 ips_type;
1012
1013 if (!halbtc_is_bt_coexist_available(btcoexist))
1014 return;
1015 btcoexist->statistics.cnt_ips_notify++;
1016 if (btcoexist->manual_control)
1017 return;
1018
1019 if (ERFOFF == type)
1020 ips_type = BTC_IPS_ENTER;
1021 else
1022 ips_type = BTC_IPS_LEAVE;
1023
1024 halbtc_leave_low_power(btcoexist);
1025
1026 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1027 if (btcoexist->board_info.btdm_ant_num == 2)
1028 ex_btc8821a2ant_ips_notify(btcoexist, ips_type);
1029 else if (btcoexist->board_info.btdm_ant_num == 1)
1030 ex_btc8821a1ant_ips_notify(btcoexist, ips_type);
1031 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1032 if (btcoexist->board_info.btdm_ant_num == 2)
1033 ex_btc8723b2ant_ips_notify(btcoexist, ips_type);
1034 else if (btcoexist->board_info.btdm_ant_num == 1)
1035 ex_btc8723b1ant_ips_notify(btcoexist, ips_type);
1036 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1037 if (btcoexist->board_info.btdm_ant_num == 2)
1038 ex_btc8192e2ant_ips_notify(btcoexist, ips_type);
1039 }
1040
1041 halbtc_normal_low_power(btcoexist);
1042 }
1043
exhalbtc_lps_notify(struct btc_coexist * btcoexist,u8 type)1044 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
1045 {
1046 u8 lps_type;
1047
1048 if (!halbtc_is_bt_coexist_available(btcoexist))
1049 return;
1050 btcoexist->statistics.cnt_lps_notify++;
1051 if (btcoexist->manual_control)
1052 return;
1053
1054 if (EACTIVE == type)
1055 lps_type = BTC_LPS_DISABLE;
1056 else
1057 lps_type = BTC_LPS_ENABLE;
1058
1059 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1060 if (btcoexist->board_info.btdm_ant_num == 2)
1061 ex_btc8821a2ant_lps_notify(btcoexist, lps_type);
1062 else if (btcoexist->board_info.btdm_ant_num == 1)
1063 ex_btc8821a1ant_lps_notify(btcoexist, lps_type);
1064 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1065 if (btcoexist->board_info.btdm_ant_num == 2)
1066 ex_btc8723b2ant_lps_notify(btcoexist, lps_type);
1067 else if (btcoexist->board_info.btdm_ant_num == 1)
1068 ex_btc8723b1ant_lps_notify(btcoexist, lps_type);
1069 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1070 if (btcoexist->board_info.btdm_ant_num == 2)
1071 ex_btc8192e2ant_lps_notify(btcoexist, lps_type);
1072 }
1073 }
1074
exhalbtc_scan_notify(struct btc_coexist * btcoexist,u8 type)1075 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
1076 {
1077 u8 scan_type;
1078
1079 if (!halbtc_is_bt_coexist_available(btcoexist))
1080 return;
1081 btcoexist->statistics.cnt_scan_notify++;
1082 if (btcoexist->manual_control)
1083 return;
1084
1085 if (type)
1086 scan_type = BTC_SCAN_START;
1087 else
1088 scan_type = BTC_SCAN_FINISH;
1089
1090 halbtc_leave_low_power(btcoexist);
1091
1092 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1093 if (btcoexist->board_info.btdm_ant_num == 2)
1094 ex_btc8821a2ant_scan_notify(btcoexist, scan_type);
1095 else if (btcoexist->board_info.btdm_ant_num == 1)
1096 ex_btc8821a1ant_scan_notify(btcoexist, scan_type);
1097 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1098 if (btcoexist->board_info.btdm_ant_num == 2)
1099 ex_btc8723b2ant_scan_notify(btcoexist, scan_type);
1100 else if (btcoexist->board_info.btdm_ant_num == 1)
1101 ex_btc8723b1ant_scan_notify(btcoexist, scan_type);
1102 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1103 if (btcoexist->board_info.btdm_ant_num == 2)
1104 ex_btc8192e2ant_scan_notify(btcoexist, scan_type);
1105 }
1106
1107 halbtc_normal_low_power(btcoexist);
1108 }
1109
exhalbtc_connect_notify(struct btc_coexist * btcoexist,u8 action)1110 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
1111 {
1112 u8 asso_type;
1113
1114 if (!halbtc_is_bt_coexist_available(btcoexist))
1115 return;
1116 btcoexist->statistics.cnt_connect_notify++;
1117 if (btcoexist->manual_control)
1118 return;
1119
1120 if (action)
1121 asso_type = BTC_ASSOCIATE_START;
1122 else
1123 asso_type = BTC_ASSOCIATE_FINISH;
1124
1125 halbtc_leave_low_power(btcoexist);
1126
1127 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1128 if (btcoexist->board_info.btdm_ant_num == 2)
1129 ex_btc8821a2ant_connect_notify(btcoexist, asso_type);
1130 else if (btcoexist->board_info.btdm_ant_num == 1)
1131 ex_btc8821a1ant_connect_notify(btcoexist, asso_type);
1132 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1133 if (btcoexist->board_info.btdm_ant_num == 2)
1134 ex_btc8723b2ant_connect_notify(btcoexist, asso_type);
1135 else if (btcoexist->board_info.btdm_ant_num == 1)
1136 ex_btc8723b1ant_connect_notify(btcoexist, asso_type);
1137 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1138 if (btcoexist->board_info.btdm_ant_num == 2)
1139 ex_btc8192e2ant_connect_notify(btcoexist, asso_type);
1140 }
1141
1142 halbtc_normal_low_power(btcoexist);
1143 }
1144
exhalbtc_mediastatus_notify(struct btc_coexist * btcoexist,enum rt_media_status media_status)1145 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
1146 enum rt_media_status media_status)
1147 {
1148 u8 status;
1149
1150 if (!halbtc_is_bt_coexist_available(btcoexist))
1151 return;
1152 btcoexist->statistics.cnt_media_status_notify++;
1153 if (btcoexist->manual_control)
1154 return;
1155
1156 if (RT_MEDIA_CONNECT == media_status)
1157 status = BTC_MEDIA_CONNECT;
1158 else
1159 status = BTC_MEDIA_DISCONNECT;
1160
1161 halbtc_leave_low_power(btcoexist);
1162
1163 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1164 if (btcoexist->board_info.btdm_ant_num == 2)
1165 ex_btc8821a2ant_media_status_notify(btcoexist, status);
1166 else if (btcoexist->board_info.btdm_ant_num == 1)
1167 ex_btc8821a1ant_media_status_notify(btcoexist, status);
1168 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1169 if (btcoexist->board_info.btdm_ant_num == 2)
1170 ex_btc8723b2ant_media_status_notify(btcoexist, status);
1171 else if (btcoexist->board_info.btdm_ant_num == 1)
1172 ex_btc8723b1ant_media_status_notify(btcoexist, status);
1173 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1174 if (btcoexist->board_info.btdm_ant_num == 2)
1175 ex_btc8192e2ant_media_status_notify(btcoexist, status);
1176 }
1177
1178 halbtc_normal_low_power(btcoexist);
1179 }
1180
exhalbtc_special_packet_notify(struct btc_coexist * btcoexist,u8 pkt_type)1181 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
1182 {
1183 u8 packet_type;
1184
1185 if (!halbtc_is_bt_coexist_available(btcoexist))
1186 return;
1187 btcoexist->statistics.cnt_special_packet_notify++;
1188 if (btcoexist->manual_control)
1189 return;
1190
1191 if (pkt_type == PACKET_DHCP) {
1192 packet_type = BTC_PACKET_DHCP;
1193 } else if (pkt_type == PACKET_EAPOL) {
1194 packet_type = BTC_PACKET_EAPOL;
1195 } else if (pkt_type == PACKET_ARP) {
1196 packet_type = BTC_PACKET_ARP;
1197 } else {
1198 packet_type = BTC_PACKET_UNKNOWN;
1199 return;
1200 }
1201
1202 halbtc_leave_low_power(btcoexist);
1203
1204 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1205 if (btcoexist->board_info.btdm_ant_num == 2)
1206 ex_btc8821a2ant_special_packet_notify(btcoexist,
1207 packet_type);
1208 else if (btcoexist->board_info.btdm_ant_num == 1)
1209 ex_btc8821a1ant_special_packet_notify(btcoexist,
1210 packet_type);
1211 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1212 if (btcoexist->board_info.btdm_ant_num == 2)
1213 ex_btc8723b2ant_special_packet_notify(btcoexist,
1214 packet_type);
1215 else if (btcoexist->board_info.btdm_ant_num == 1)
1216 ex_btc8723b1ant_special_packet_notify(btcoexist,
1217 packet_type);
1218 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1219 if (btcoexist->board_info.btdm_ant_num == 2)
1220 ex_btc8192e2ant_special_packet_notify(btcoexist,
1221 packet_type);
1222 }
1223
1224 halbtc_normal_low_power(btcoexist);
1225 }
1226
exhalbtc_bt_info_notify(struct btc_coexist * btcoexist,u8 * tmp_buf,u8 length)1227 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
1228 u8 *tmp_buf, u8 length)
1229 {
1230 if (!halbtc_is_bt_coexist_available(btcoexist))
1231 return;
1232 btcoexist->statistics.cnt_bt_info_notify++;
1233
1234 halbtc_leave_low_power(btcoexist);
1235
1236 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1237 if (btcoexist->board_info.btdm_ant_num == 2)
1238 ex_btc8821a2ant_bt_info_notify(btcoexist, tmp_buf,
1239 length);
1240 else if (btcoexist->board_info.btdm_ant_num == 1)
1241 ex_btc8821a1ant_bt_info_notify(btcoexist, tmp_buf,
1242 length);
1243 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1244 if (btcoexist->board_info.btdm_ant_num == 2)
1245 ex_btc8723b2ant_bt_info_notify(btcoexist, tmp_buf,
1246 length);
1247 else if (btcoexist->board_info.btdm_ant_num == 1)
1248 ex_btc8723b1ant_bt_info_notify(btcoexist, tmp_buf,
1249 length);
1250 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1251 if (btcoexist->board_info.btdm_ant_num == 2)
1252 ex_btc8192e2ant_bt_info_notify(btcoexist, tmp_buf,
1253 length);
1254 }
1255
1256 halbtc_normal_low_power(btcoexist);
1257 }
1258
exhalbtc_rf_status_notify(struct btc_coexist * btcoexist,u8 type)1259 void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
1260 {
1261 if (!halbtc_is_bt_coexist_available(btcoexist))
1262 return;
1263
1264 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1265 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1266 if (btcoexist->board_info.btdm_ant_num == 1)
1267 ex_btc8723b1ant_rf_status_notify(btcoexist, type);
1268 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1269 }
1270 }
1271
exhalbtc_stack_operation_notify(struct btc_coexist * btcoexist,u8 type)1272 void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
1273 {
1274 u8 stack_op_type;
1275
1276 if (!halbtc_is_bt_coexist_available(btcoexist))
1277 return;
1278 btcoexist->statistics.cnt_stack_operation_notify++;
1279 if (btcoexist->manual_control)
1280 return;
1281
1282 if ((type == HCI_BT_OP_INQUIRY_START) ||
1283 (type == HCI_BT_OP_PAGING_START) ||
1284 (type == HCI_BT_OP_PAIRING_START)) {
1285 stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_START;
1286 } else if ((type == HCI_BT_OP_INQUIRY_FINISH) ||
1287 (type == HCI_BT_OP_PAGING_SUCCESS) ||
1288 (type == HCI_BT_OP_PAGING_UNSUCCESS) ||
1289 (type == HCI_BT_OP_PAIRING_FINISH)) {
1290 stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
1291 } else {
1292 stack_op_type = BTC_STACK_OP_NONE;
1293 }
1294 }
1295
exhalbtc_halt_notify(struct btc_coexist * btcoexist)1296 void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
1297 {
1298 if (!halbtc_is_bt_coexist_available(btcoexist))
1299 return;
1300
1301 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1302 if (btcoexist->board_info.btdm_ant_num == 2)
1303 ex_btc8821a2ant_halt_notify(btcoexist);
1304 else if (btcoexist->board_info.btdm_ant_num == 1)
1305 ex_btc8821a1ant_halt_notify(btcoexist);
1306 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1307 if (btcoexist->board_info.btdm_ant_num == 2)
1308 ex_btc8723b2ant_halt_notify(btcoexist);
1309 else if (btcoexist->board_info.btdm_ant_num == 1)
1310 ex_btc8723b1ant_halt_notify(btcoexist);
1311 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1312 if (btcoexist->board_info.btdm_ant_num == 2)
1313 ex_btc8192e2ant_halt_notify(btcoexist);
1314 }
1315
1316 btcoexist->binded = false;
1317 }
1318
exhalbtc_pnp_notify(struct btc_coexist * btcoexist,u8 pnp_state)1319 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
1320 {
1321 if (!halbtc_is_bt_coexist_available(btcoexist))
1322 return;
1323
1324 /* currently only 1ant we have to do the notification,
1325 * once pnp is notified to sleep state, we have to leave LPS that
1326 * we can sleep normally.
1327 */
1328
1329 if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1330 if (btcoexist->board_info.btdm_ant_num == 1)
1331 ex_btc8723b1ant_pnp_notify(btcoexist, pnp_state);
1332 else if (btcoexist->board_info.btdm_ant_num == 2)
1333 ex_btc8723b2ant_pnp_notify(btcoexist, pnp_state);
1334 } else if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1335 if (btcoexist->board_info.btdm_ant_num == 1)
1336 ex_btc8821a1ant_pnp_notify(btcoexist, pnp_state);
1337 else if (btcoexist->board_info.btdm_ant_num == 2)
1338 ex_btc8821a2ant_pnp_notify(btcoexist, pnp_state);
1339 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1340 }
1341 }
1342
exhalbtc_coex_dm_switch(struct btc_coexist * btcoexist)1343 void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist)
1344 {
1345 struct rtl_priv *rtlpriv = btcoexist->adapter;
1346
1347 if (!halbtc_is_bt_coexist_available(btcoexist))
1348 return;
1349 btcoexist->statistics.cnt_coex_dm_switch++;
1350
1351 halbtc_leave_low_power(btcoexist);
1352
1353 if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1354 if (btcoexist->board_info.btdm_ant_num == 1) {
1355 btcoexist->stop_coex_dm = true;
1356 ex_btc8723b1ant_coex_dm_reset(btcoexist);
1357 exhalbtc_set_ant_num(rtlpriv,
1358 BT_COEX_ANT_TYPE_DETECTED, 2);
1359 ex_btc8723b2ant_init_hwconfig(btcoexist);
1360 ex_btc8723b2ant_init_coex_dm(btcoexist);
1361 btcoexist->stop_coex_dm = false;
1362 }
1363 }
1364
1365 halbtc_normal_low_power(btcoexist);
1366 }
1367
exhalbtc_periodical(struct btc_coexist * btcoexist)1368 void exhalbtc_periodical(struct btc_coexist *btcoexist)
1369 {
1370 if (!halbtc_is_bt_coexist_available(btcoexist))
1371 return;
1372 btcoexist->statistics.cnt_periodical++;
1373
1374 halbtc_leave_low_power(btcoexist);
1375
1376 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1377 if (btcoexist->board_info.btdm_ant_num == 2)
1378 ex_btc8821a2ant_periodical(btcoexist);
1379 else if (btcoexist->board_info.btdm_ant_num == 1)
1380 if (!halbtc_under_ips(btcoexist))
1381 ex_btc8821a1ant_periodical(btcoexist);
1382 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1383 if (btcoexist->board_info.btdm_ant_num == 2)
1384 ex_btc8723b2ant_periodical(btcoexist);
1385 else if (btcoexist->board_info.btdm_ant_num == 1)
1386 ex_btc8723b1ant_periodical(btcoexist);
1387 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1388 if (btcoexist->board_info.btdm_ant_num == 2)
1389 ex_btc8192e2ant_periodical(btcoexist);
1390 }
1391
1392 halbtc_normal_low_power(btcoexist);
1393 }
1394
exhalbtc_dbg_control(struct btc_coexist * btcoexist,u8 code,u8 len,u8 * data)1395 void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
1396 u8 code, u8 len, u8 *data)
1397 {
1398 if (!halbtc_is_bt_coexist_available(btcoexist))
1399 return;
1400 btcoexist->statistics.cnt_dbg_ctrl++;
1401
1402 halbtc_leave_low_power(btcoexist);
1403
1404 halbtc_normal_low_power(btcoexist);
1405 }
1406
exhalbtc_antenna_detection(struct btc_coexist * btcoexist,u32 cent_freq,u32 offset,u32 span,u32 seconds)1407 void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq,
1408 u32 offset, u32 span, u32 seconds)
1409 {
1410 if (!halbtc_is_bt_coexist_available(btcoexist))
1411 return;
1412 }
1413
exhalbtc_stack_update_profile_info(void)1414 void exhalbtc_stack_update_profile_info(void)
1415 {
1416 }
1417
exhalbtc_update_min_bt_rssi(s8 bt_rssi)1418 void exhalbtc_update_min_bt_rssi(s8 bt_rssi)
1419 {
1420 struct btc_coexist *btcoexist = &gl_bt_coexist;
1421
1422 if (!halbtc_is_bt_coexist_available(btcoexist))
1423 return;
1424
1425 btcoexist->stack_info.min_bt_rssi = bt_rssi;
1426 }
1427
exhalbtc_set_hci_version(u16 hci_version)1428 void exhalbtc_set_hci_version(u16 hci_version)
1429 {
1430 struct btc_coexist *btcoexist = &gl_bt_coexist;
1431
1432 if (!halbtc_is_bt_coexist_available(btcoexist))
1433 return;
1434
1435 btcoexist->stack_info.hci_version = hci_version;
1436 }
1437
exhalbtc_set_bt_patch_version(u16 bt_hci_version,u16 bt_patch_version)1438 void exhalbtc_set_bt_patch_version(u16 bt_hci_version, u16 bt_patch_version)
1439 {
1440 struct btc_coexist *btcoexist = &gl_bt_coexist;
1441
1442 if (!halbtc_is_bt_coexist_available(btcoexist))
1443 return;
1444
1445 btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
1446 btcoexist->bt_info.bt_hci_ver = bt_hci_version;
1447 }
1448
exhalbtc_set_chip_type(u8 chip_type)1449 void exhalbtc_set_chip_type(u8 chip_type)
1450 {
1451 switch (chip_type) {
1452 default:
1453 case BT_2WIRE:
1454 case BT_ISSC_3WIRE:
1455 case BT_ACCEL:
1456 case BT_RTL8756:
1457 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_UNDEF;
1458 break;
1459 case BT_CSR_BC4:
1460 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
1461 break;
1462 case BT_CSR_BC8:
1463 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
1464 break;
1465 case BT_RTL8723A:
1466 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A;
1467 break;
1468 case BT_RTL8821A:
1469 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8821;
1470 break;
1471 case BT_RTL8723B:
1472 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B;
1473 break;
1474 }
1475 }
1476
exhalbtc_set_ant_num(struct rtl_priv * rtlpriv,u8 type,u8 ant_num)1477 void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num)
1478 {
1479 if (BT_COEX_ANT_TYPE_PG == type) {
1480 gl_bt_coexist.board_info.pg_ant_num = ant_num;
1481 gl_bt_coexist.board_info.btdm_ant_num = ant_num;
1482 } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1483 gl_bt_coexist.board_info.btdm_ant_num = ant_num;
1484 } else if (type == BT_COEX_ANT_TYPE_DETECTED) {
1485 gl_bt_coexist.board_info.btdm_ant_num = ant_num;
1486 if (rtlpriv->cfg->mod_params->ant_sel == 1)
1487 gl_bt_coexist.board_info.btdm_ant_pos =
1488 BTC_ANTENNA_AT_AUX_PORT;
1489 else
1490 gl_bt_coexist.board_info.btdm_ant_pos =
1491 BTC_ANTENNA_AT_MAIN_PORT;
1492 }
1493 }
1494
1495 /* Currently used by 8723b only, S0 or S1 */
exhalbtc_set_single_ant_path(u8 single_ant_path)1496 void exhalbtc_set_single_ant_path(u8 single_ant_path)
1497 {
1498 gl_bt_coexist.board_info.single_ant_path = single_ant_path;
1499 }
1500
exhalbtc_display_bt_coex_info(struct btc_coexist * btcoexist)1501 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist)
1502 {
1503 if (!halbtc_is_bt_coexist_available(btcoexist))
1504 return;
1505
1506 halbtc_leave_low_power(btcoexist);
1507
1508 if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1509 if (btcoexist->board_info.btdm_ant_num == 2)
1510 ex_btc8821a2ant_display_coex_info(btcoexist);
1511 else if (btcoexist->board_info.btdm_ant_num == 1)
1512 ex_btc8821a1ant_display_coex_info(btcoexist);
1513 } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1514 if (btcoexist->board_info.btdm_ant_num == 2)
1515 ex_btc8723b2ant_display_coex_info(btcoexist);
1516 else if (btcoexist->board_info.btdm_ant_num == 1)
1517 ex_btc8723b1ant_display_coex_info(btcoexist);
1518 } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1519 if (btcoexist->board_info.btdm_ant_num == 2)
1520 ex_btc8192e2ant_display_coex_info(btcoexist);
1521 }
1522
1523 halbtc_normal_low_power(btcoexist);
1524 }
1525