1 /******************************************************************************
2 *
3 * Copyright(c) 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 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/
20 #define __HAL_BTCOEX_C__
21
22 #ifdef CONFIG_BT_COEXIST
23
24 #include <hal_data.h>
25 #include <hal_btcoex.h>
26 #include <Mp_Precomp.h>
27
28 /* ************************************
29 * Global variables
30 * ************************************ */
31 const char *const BtProfileString[] = {
32 "NONE",
33 "A2DP",
34 "PAN",
35 "HID",
36 "SCO",
37 };
38
39 const char *const BtSpecString[] = {
40 "1.0b",
41 "1.1",
42 "1.2",
43 "2.0+EDR",
44 "2.1+EDR",
45 "3.0+HS",
46 "4.0",
47 };
48
49 const char *const BtLinkRoleString[] = {
50 "Master",
51 "Slave",
52 };
53
54 const char *const h2cStaString[] = {
55 "successful",
56 "h2c busy",
57 "rf off",
58 "fw not read",
59 };
60
61 const char *const ioStaString[] = {
62 "success",
63 "can not IO",
64 "rf off",
65 "fw not read",
66 "wait io timeout",
67 "invalid len",
68 "idle Q empty",
69 "insert waitQ fail",
70 "unknown fail",
71 "wrong level",
72 "h2c stopped",
73 };
74
75 const char *const GLBtcWifiBwString[] = {
76 "11bg",
77 "HT20",
78 "HT40",
79 "HT80",
80 "HT160"
81 };
82
83 const char *const GLBtcWifiFreqString[] = {
84 "2.4G",
85 "5G"
86 };
87
88 const char *const GLBtcIotPeerString[] = {
89 "UNKNOWN",
90 "REALTEK",
91 "REALTEK_92SE",
92 "BROADCOM",
93 "RALINK",
94 "ATHEROS",
95 "CISCO",
96 "MERU",
97 "MARVELL",
98 "REALTEK_SOFTAP", /* peer is RealTek SOFT_AP, by Bohn, 2009.12.17 */
99 "SELF_SOFTAP", /* Self is SoftAP */
100 "AIRGO",
101 "INTEL",
102 "RTK_APCLIENT",
103 "REALTEK_81XX",
104 "REALTEK_WOW",
105 "REALTEK_JAGUAR_BCUTAP",
106 "REALTEK_JAGUAR_CCUTAP"
107 };
108
109 const char *const coexOpcodeString[] = {
110 "Wifi status notify",
111 "Wifi progress",
112 "Wifi info",
113 "Power state",
114 "Set Control",
115 "Get Control"
116 };
117
118 const char *const coexIndTypeString[] = {
119 "bt info",
120 "pstdma",
121 "limited tx/rx",
122 "coex table",
123 "request"
124 };
125
126 const char *const coexH2cResultString[] = {
127 "ok",
128 "unknown",
129 "un opcode",
130 "opVer MM",
131 "par Err",
132 "par OoR",
133 "reqNum MM",
134 "halMac Fail",
135 "h2c TimeOut",
136 "Invalid c2h Len",
137 "data overflow"
138 };
139
140 #define HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS 8000
141
142 struct btc_coexist GLBtCoexist;
143 BTC_OFFLOAD gl_coex_offload;
144 u8 GLBtcWiFiInScanState;
145 u8 GLBtcWiFiInIQKState;
146 u8 GLBtcWiFiInIPS;
147 u8 GLBtcWiFiInLPS;
148 u8 GLBtcBtCoexAliveRegistered;
149
150 /*
151 * BT control H2C/C2H
152 */
153 /* EXT_EID */
154 typedef enum _bt_ext_eid {
155 C2H_WIFI_FW_ACTIVE_RSP = 0,
156 C2H_TRIG_BY_BT_FW
157 } BT_EXT_EID;
158
159 /* C2H_STATUS */
160 typedef enum _bt_c2h_status {
161 BT_STATUS_OK = 0,
162 BT_STATUS_VERSION_MISMATCH,
163 BT_STATUS_UNKNOWN_OPCODE,
164 BT_STATUS_ERROR_PARAMETER
165 } BT_C2H_STATUS;
166
167 /* C2H BT OP CODES */
168 typedef enum _bt_op_code {
169 BT_OP_GET_BT_VERSION = 0,
170 BT_OP_WRITE_REG_ADDR = 12,
171 BT_OP_WRITE_REG_VALUE,
172 BT_OP_READ_REG = 17,
173 BT_OP_GET_BT_COEX_SUPPORTED_FEATURE = 42,
174 BT_OP_GET_BT_COEX_SUPPORTED_VERSION = 43,
175 BT_OP_GET_BT_ANT_DET_VAL = 44,
176 BT_OP_GET_BT_BLE_SCAN_PARA = 45,
177 BT_OP_GET_BT_BLE_SCAN_TYPE = 46,
178 BT_OP_MAX
179 } BT_OP_CODE;
180
181 #define BTC_MPOPER_TIMEOUT 50 /* unit: ms */
182
183 #define C2H_MAX_SIZE 16
184 u8 GLBtcBtMpOperSeq;
185 _mutex GLBtcBtMpOperLock;
186 _timer GLBtcBtMpOperTimer;
187 _sema GLBtcBtMpRptSema;
188 u8 GLBtcBtMpRptSeq;
189 u8 GLBtcBtMpRptStatus;
190 u8 GLBtcBtMpRptRsp[C2H_MAX_SIZE];
191 u8 GLBtcBtMpRptRspSize;
192 u8 GLBtcBtMpRptWait;
193 u8 GLBtcBtMpRptWiFiOK;
194 u8 GLBtcBtMpRptBTOK;
195
196 /*
197 * Debug
198 */
199 u32 GLBtcDbgType[COMP_MAX];
200 u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];
201 u1Byte gl_btc_trace_buf[BT_TMP_BUF_SIZE];
202
203 typedef struct _btcoexdbginfo {
204 u8 *info;
205 u32 size; /* buffer total size */
206 u32 len; /* now used length */
207 } BTCDBGINFO, *PBTCDBGINFO;
208
209 BTCDBGINFO GLBtcDbgInfo;
210
211 #define BT_Operation(Adapter) _FALSE
212
DBG_BT_INFO_INIT(PBTCDBGINFO pinfo,u8 * pbuf,u32 size)213 static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)
214 {
215 if (NULL == pinfo)
216 return;
217
218 _rtw_memset(pinfo, 0, sizeof(BTCDBGINFO));
219
220 if (pbuf && size) {
221 pinfo->info = pbuf;
222 pinfo->size = size;
223 }
224 }
225
DBG_BT_INFO(u8 * dbgmsg)226 void DBG_BT_INFO(u8 *dbgmsg)
227 {
228 PBTCDBGINFO pinfo;
229 u32 msglen, buflen;
230 u8 *pbuf;
231
232
233 pinfo = &GLBtcDbgInfo;
234
235 if (NULL == pinfo->info)
236 return;
237
238 msglen = strlen(dbgmsg);
239 if (pinfo->len + msglen > pinfo->size)
240 return;
241
242 pbuf = pinfo->info + pinfo->len;
243 _rtw_memcpy(pbuf, dbgmsg, msglen);
244 pinfo->len += msglen;
245 }
246
247 /* ************************************
248 * Debug related function
249 * ************************************ */
halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)250 static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
251 {
252 if (!pBtCoexist->bBinded ||
253 NULL == pBtCoexist->Adapter)
254 return _FALSE;
255 return _TRUE;
256 }
257
halbtcoutsrc_DbgInit(void)258 static void halbtcoutsrc_DbgInit(void)
259 {
260 u8 i;
261
262 for (i = 0; i < COMP_MAX; i++)
263 GLBtcDbgType[i] = 0;
264 }
265
halbtcoutsrc_IsCsrBtCoex(PBTC_COEXIST pBtCoexist)266 static u8 halbtcoutsrc_IsCsrBtCoex(PBTC_COEXIST pBtCoexist)
267 {
268 if (pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC4
269 || pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC8
270 )
271 return _TRUE;
272 return _FALSE;
273 }
274
halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)275 static u8 halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)
276 {
277 if (pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC4
278 || pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC8
279 )
280 return _FALSE;
281 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
282 return _FALSE;
283 else
284 return _TRUE;
285 }
286
halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)287 static void halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
288 {
289 PADAPTER padapter;
290
291
292 padapter = pBtCoexist->Adapter;
293
294 pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;
295 pBtCoexist->bt_info.bt_lps_on = _FALSE;
296
297 rtw_btcoex_LPS_Leave(padapter);
298 }
299
halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)300 void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
301 {
302 PADAPTER padapter;
303
304
305 padapter = pBtCoexist->Adapter;
306
307 if (pBtCoexist->bdontenterLPS == _FALSE) {
308 pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;
309 pBtCoexist->bt_info.bt_lps_on = _TRUE;
310
311 rtw_btcoex_LPS_Enter(padapter);
312 }
313 }
314
halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)315 void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
316 {
317 PADAPTER padapter;
318
319
320 padapter = pBtCoexist->Adapter;
321
322 if (pBtCoexist->bt_info.bt_ctrl_lps) {
323 pBtCoexist->bt_info.bt_lps_on = _FALSE;
324 rtw_btcoex_LPS_Leave(padapter);
325 pBtCoexist->bt_info.bt_ctrl_lps = _FALSE;
326
327 /* recover the LPS state to the original */
328 #if 0
329 padapter->HalFunc.UpdateLPSStatusHandler(
330 padapter,
331 pPSC->RegLeisurePsMode,
332 pPSC->RegPowerSaveMode);
333 #endif
334 }
335 }
336
337 /*
338 * Constraint:
339 * 1. this function will request pwrctrl->lock
340 */
halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)341 void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
342 {
343 #ifdef CONFIG_LPS_LCLK
344 PADAPTER padapter;
345 PHAL_DATA_TYPE pHalData;
346 struct pwrctrl_priv *pwrctrl;
347 s32 ready;
348 u32 stime;
349 s32 utime;
350 u32 timeout; /* unit: ms */
351
352
353 padapter = pBtCoexist->Adapter;
354 pHalData = GET_HAL_DATA(padapter);
355 pwrctrl = adapter_to_pwrctl(padapter);
356 ready = _FAIL;
357 #ifdef LPS_RPWM_WAIT_MS
358 timeout = LPS_RPWM_WAIT_MS;
359 #else /* !LPS_RPWM_WAIT_MS */
360 timeout = 30;
361 #endif /* !LPS_RPWM_WAIT_MS */
362
363 if (GLBtcBtCoexAliveRegistered == _TRUE)
364 return;
365
366 stime = rtw_get_current_time();
367 do {
368 ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
369 if (_SUCCESS == ready)
370 break;
371
372 utime = rtw_get_passing_time_ms(stime);
373 if (utime > timeout)
374 break;
375
376 rtw_msleep_os(1);
377 } while (1);
378
379 GLBtcBtCoexAliveRegistered = _TRUE;
380 #endif /* CONFIG_LPS_LCLK */
381 }
382
383 /*
384 * Constraint:
385 * 1. this function will request pwrctrl->lock
386 */
halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)387 void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
388 {
389 #ifdef CONFIG_LPS_LCLK
390 PADAPTER padapter;
391
392 if (GLBtcBtCoexAliveRegistered == _FALSE)
393 return;
394
395 padapter = pBtCoexist->Adapter;
396 rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
397
398 GLBtcBtCoexAliveRegistered = _FALSE;
399 #endif /* CONFIG_LPS_LCLK */
400 }
401
halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist,u8 bLowPwrDisable)402 void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
403 {
404 pBtCoexist->bt_info.bt_disable_low_pwr = bLowPwrDisable;
405 if (bLowPwrDisable)
406 halbtcoutsrc_LeaveLowPower(pBtCoexist); /* leave 32k low power. */
407 else
408 halbtcoutsrc_NormalLowPower(pBtCoexist); /* original 32k low power behavior. */
409 }
410
halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)411 void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
412 {
413 PADAPTER padapter;
414 BOOLEAN bNeedToAct = _FALSE;
415 static u32 preTime = 0;
416 u32 curTime = 0;
417
418 padapter = pBtCoexist->Adapter;
419
420 /* ===================================== */
421 /* To void continuous deleteBA=>addBA=>deleteBA=>addBA */
422 /* This function is not allowed to continuous called. */
423 /* It can only be called after 8 seconds. */
424 /* ===================================== */
425
426 curTime = rtw_systime_to_ms(rtw_get_current_time());
427 if ((curTime - preTime) < HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS) /* over 8 seconds you can execute this function again. */
428 return;
429 else
430 preTime = curTime;
431
432 if (pBtCoexist->bt_info.reject_agg_pkt) {
433 bNeedToAct = _TRUE;
434 pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;
435 } else {
436 if (pBtCoexist->bt_info.pre_reject_agg_pkt) {
437 bNeedToAct = _TRUE;
438 pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;
439 }
440
441 if (pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
442 pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {
443 bNeedToAct = _TRUE;
444 pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size = pBtCoexist->bt_info.bt_ctrl_agg_buf_size;
445 }
446
447 if (pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {
448 if (pBtCoexist->bt_info.pre_agg_buf_size !=
449 pBtCoexist->bt_info.agg_buf_size)
450 bNeedToAct = _TRUE;
451 pBtCoexist->bt_info.pre_agg_buf_size = pBtCoexist->bt_info.agg_buf_size;
452 }
453 }
454
455 if (bNeedToAct)
456 rtw_btcoex_rx_ampdu_apply(padapter);
457 }
458
halbtcoutsrc_is_autoload_fail(PBTC_COEXIST pBtCoexist)459 u8 halbtcoutsrc_is_autoload_fail(PBTC_COEXIST pBtCoexist)
460 {
461 PADAPTER padapter;
462 PHAL_DATA_TYPE pHalData;
463
464 padapter = pBtCoexist->Adapter;
465 pHalData = GET_HAL_DATA(padapter);
466
467 return pHalData->bautoload_fail_flag;
468 }
469
halbtcoutsrc_is_fw_ready(PBTC_COEXIST pBtCoexist)470 u8 halbtcoutsrc_is_fw_ready(PBTC_COEXIST pBtCoexist)
471 {
472 PADAPTER padapter;
473
474 padapter = pBtCoexist->Adapter;
475
476 return padapter->bFWReady;
477 }
478
halbtcoutsrc_IsWifiBusy(PADAPTER padapter)479 u8 halbtcoutsrc_IsWifiBusy(PADAPTER padapter)
480 {
481 if (rtw_mi_check_status(padapter, MI_AP_MODE))
482 return _TRUE;
483 if (rtw_mi_busy_traffic_check(padapter, _FALSE))
484 return _TRUE;
485
486 return _FALSE;
487 }
488
halbtcoutsrc_IsRF4CEConnected(PADAPTER padapter)489 u8 halbtcoutsrc_IsRF4CEConnected(PADAPTER padapter)
490 {
491 #ifdef CONFIG_RF4CE_COEXIST
492 return GLBtCoexist.rf4ce_info.link_state;
493 #else
494 return _FALSE;
495 #endif
496 }
497
498
_halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)499 static u32 _halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)
500 {
501 struct mlme_priv *pmlmepriv;
502 u8 bp2p;
503 u32 portConnectedStatus;
504
505
506 pmlmepriv = &padapter->mlmepriv;
507 bp2p = _FALSE;
508 portConnectedStatus = 0;
509
510 #ifdef CONFIG_P2P
511 if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))
512 bp2p = _TRUE;
513 #endif /* CONFIG_P2P */
514
515 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) {
516 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
517 if (_TRUE == bp2p)
518 portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
519 else
520 portConnectedStatus |= WIFI_AP_CONNECTED;
521 } else {
522 if (_TRUE == bp2p)
523 portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
524 else
525 portConnectedStatus |= WIFI_STA_CONNECTED;
526 }
527 }
528
529 return portConnectedStatus;
530 }
531
halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)532 u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
533 {
534 /* ================================= */
535 /* return value: */
536 /* [31:16]=> connected port number */
537 /* [15:0]=> port connected bit define */
538 /* ================================ */
539
540 PADAPTER padapter;
541 u32 retVal;
542 u32 portConnectedStatus, numOfConnectedPort;
543 struct dvobj_priv *dvobj;
544 _adapter *iface;
545 int i;
546
547 padapter = pBtCoexist->Adapter;
548 retVal = 0;
549 portConnectedStatus = 0;
550 numOfConnectedPort = 0;
551 dvobj = adapter_to_dvobj(padapter);
552
553 for (i = 0; i < dvobj->iface_nums; i++) {
554 iface = dvobj->padapters[i];
555 if ((iface) && rtw_is_adapter_up(iface)) {
556 retVal = _halbtcoutsrc_GetWifiLinkStatus(iface);
557 if (retVal) {
558 portConnectedStatus |= retVal;
559 numOfConnectedPort++;
560 }
561 }
562 }
563 retVal = (numOfConnectedPort << 16) | portConnectedStatus;
564
565 return retVal;
566 }
567
_btmpoper_timer_hdl(void * p)568 static void _btmpoper_timer_hdl(void *p)
569 {
570 if (GLBtcBtMpRptWait) {
571 GLBtcBtMpRptWait = 0;
572 _rtw_up_sema(&GLBtcBtMpRptSema);
573 }
574 }
575
576 /*
577 * !IMPORTANT!
578 * Before call this function, caller should acquire "GLBtcBtMpOperLock"!
579 * Othrewise there will be racing problem and something may go wrong.
580 */
_btmpoper_cmd(PBTC_COEXIST pBtCoexist,u8 opcode,u8 opcodever,u8 * cmd,u8 size)581 static u8 _btmpoper_cmd(PBTC_COEXIST pBtCoexist, u8 opcode, u8 opcodever, u8 *cmd, u8 size)
582 {
583 PADAPTER padapter;
584 u8 buf[H2C_BTMP_OPER_LEN] = {0};
585 u8 buflen;
586 u8 seq;
587 u8 timer_cancelled;
588 s32 ret;
589
590
591 if (!cmd && size)
592 size = 0;
593 if ((size + 2) > H2C_BTMP_OPER_LEN)
594 return BT_STATUS_H2C_LENGTH_EXCEEDED;
595 buflen = size + 2;
596
597 seq = GLBtcBtMpOperSeq & 0xF;
598 GLBtcBtMpOperSeq++;
599
600 buf[0] = (opcodever & 0xF) | (seq << 4);
601 buf[1] = opcode;
602 if (cmd && size)
603 _rtw_memcpy(buf + 2, cmd, size);
604
605 GLBtcBtMpRptWait = 1;
606 GLBtcBtMpRptWiFiOK = 0;
607 GLBtcBtMpRptBTOK = 0;
608 GLBtcBtMpRptStatus = 0;
609 padapter = pBtCoexist->Adapter;
610 _set_timer(&GLBtcBtMpOperTimer, BTC_MPOPER_TIMEOUT);
611 if (rtw_hal_fill_h2c_cmd(padapter, H2C_BT_MP_OPER, buflen, buf) == _FAIL) {
612 _cancel_timer(&GLBtcBtMpOperTimer, &timer_cancelled);
613 ret = BT_STATUS_H2C_FAIL;
614 goto exit;
615 }
616
617 _rtw_down_sema(&GLBtcBtMpRptSema);
618 /* GLBtcBtMpRptWait should be 0 here*/
619
620 if (!GLBtcBtMpRptWiFiOK) {
621 RTW_INFO("%s: Didn't get H2C Rsp Event!\n", __FUNCTION__);
622 ret = BT_STATUS_H2C_TIMTOUT;
623 goto exit;
624 }
625 if (!GLBtcBtMpRptBTOK) {
626 RTW_INFO("%s: Didn't get BT response!\n", __FUNCTION__);
627 ret = BT_STATUS_H2C_BT_NO_RSP;
628 goto exit;
629 }
630 if (seq != GLBtcBtMpRptSeq) {
631 RTW_INFO("%s: Sequence number not match!(%d!=%d)!\n",
632 __FUNCTION__, seq, GLBtcBtMpRptSeq);
633 ret = BT_STATUS_C2H_REQNUM_MISMATCH;
634 goto exit;
635 }
636
637 switch (GLBtcBtMpRptStatus) {
638 /* Examine the status reported from C2H */
639 case BT_STATUS_OK:
640 ret = BT_STATUS_BT_OP_SUCCESS;
641 RTW_INFO("%s: C2H status = BT_STATUS_BT_OP_SUCCESS\n", __FUNCTION__);
642 break;
643 case BT_STATUS_VERSION_MISMATCH:
644 ret = BT_STATUS_OPCODE_L_VERSION_MISMATCH;
645 RTW_INFO("%s: C2H status = BT_STATUS_OPCODE_L_VERSION_MISMATCH\n", __FUNCTION__);
646 break;
647 case BT_STATUS_UNKNOWN_OPCODE:
648 ret = BT_STATUS_UNKNOWN_OPCODE_L;
649 RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_OPCODE_L\n", __FUNCTION__);
650 break;
651 case BT_STATUS_ERROR_PARAMETER:
652 ret = BT_STATUS_PARAMETER_FORMAT_ERROR_L;
653 RTW_INFO("%s: C2H status = MP_BT_STATUS_PARAMETER_FORMAT_ERROR_L\n", __FUNCTION__);
654 break;
655 default:
656 ret = BT_STATUS_UNKNOWN_STATUS_L;
657 RTW_INFO("%s: C2H status = MP_BT_STATUS_UNKNOWN_STATUS_L\n", __FUNCTION__);
658 break;
659 }
660
661 exit:
662 return ret;
663 }
664
halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)665 u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
666 {
667 if (pBtCoexist->bt_info.get_bt_fw_ver_cnt <= 5) {
668 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
669 _irqL irqL;
670 u8 ret;
671
672 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
673
674 ret = _btmpoper_cmd(pBtCoexist, BT_OP_GET_BT_VERSION, 0, NULL, 0);
675 if (BT_STATUS_BT_OP_SUCCESS == ret) {
676 pBtCoexist->bt_info.bt_real_fw_ver = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
677 pBtCoexist->bt_info.bt_fw_ver = *(GLBtcBtMpRptRsp + 2);
678 }
679 pBtCoexist->bt_info.get_bt_fw_ver_cnt++;
680
681 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
682 } else {
683 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
684 u1Byte dataLen = 2;
685 u1Byte buf[4] = {0};
686
687 buf[0] = 0x0; /* OP_Code */
688 buf[1] = 0x0; /* OP_Code_Length */
689 BT_SendEventExtBtCoexControl(pBtCoexist->Adapter, _FALSE, dataLen, &buf[0]);
690 #endif /* !CONFIG_BT_COEXIST_SOCKET_TRX */
691 }
692 }
693
694 exit:
695 return pBtCoexist->bt_info.bt_real_fw_ver;
696 }
697
halbtcoutsrc_GetWifiRssi(PADAPTER padapter)698 s32 halbtcoutsrc_GetWifiRssi(PADAPTER padapter)
699 {
700 PHAL_DATA_TYPE pHalData;
701 s32 UndecoratedSmoothedPWDB = 0;
702
703 pHalData = GET_HAL_DATA(padapter);
704
705 UndecoratedSmoothedPWDB = pHalData->EntryMinUndecoratedSmoothedPWDB;
706
707 return UndecoratedSmoothedPWDB;
708 }
709
halbtcoutsrc_GetBtCoexSupportedFeature(void * pBtcContext)710 u32 halbtcoutsrc_GetBtCoexSupportedFeature(void *pBtcContext)
711 {
712 PBTC_COEXIST pBtCoexist;
713 u32 ret = BT_STATUS_BT_OP_SUCCESS;
714 u32 data = 0;
715
716 pBtCoexist = (PBTC_COEXIST)pBtcContext;
717
718 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
719 u8 buf[3] = {0};
720 _irqL irqL;
721 u8 op_code;
722 u8 status;
723
724 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
725
726 op_code = BT_OP_GET_BT_COEX_SUPPORTED_FEATURE;
727 status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
728 if (status == BT_STATUS_BT_OP_SUCCESS)
729 data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
730 else
731 ret = SET_BT_MP_OPER_RET(op_code, status);
732
733 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
734
735 } else
736 ret = BT_STATUS_NOT_IMPLEMENT;
737
738 return data;
739 }
740
halbtcoutsrc_GetBtCoexSupportedVersion(void * pBtcContext)741 u32 halbtcoutsrc_GetBtCoexSupportedVersion(void *pBtcContext)
742 {
743 PBTC_COEXIST pBtCoexist;
744 u32 ret = BT_STATUS_BT_OP_SUCCESS;
745 u32 data = 0xFFFF;
746
747 pBtCoexist = (PBTC_COEXIST)pBtcContext;
748
749 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
750 u8 buf[3] = {0};
751 _irqL irqL;
752 u8 op_code;
753 u8 status;
754
755 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
756
757 op_code = BT_OP_GET_BT_COEX_SUPPORTED_VERSION;
758 status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
759 if (status == BT_STATUS_BT_OP_SUCCESS)
760 data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
761 else
762 ret = SET_BT_MP_OPER_RET(op_code, status);
763
764 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
765
766 } else
767 ret = BT_STATUS_NOT_IMPLEMENT;
768
769 return data;
770 }
771
halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)772 static u8 halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)
773 {
774 struct mlme_priv *pmlmepriv;
775 struct mlme_ext_priv *pmlmeext;
776 static u8 scan_AP_num = 0;
777
778
779 pmlmepriv = &padapter->mlmepriv;
780 pmlmeext = &padapter->mlmeextpriv;
781
782 if (GLBtcWiFiInScanState == _FALSE) {
783 if (pmlmepriv->num_of_scanned > 0xFF)
784 scan_AP_num = 0xFF;
785 else
786 scan_AP_num = (u8)pmlmepriv->num_of_scanned;
787 }
788
789 return scan_AP_num;
790 }
791
halbtcoutsrc_Get(void * pBtcContext,u8 getType,void * pOutBuf)792 u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
793 {
794 PBTC_COEXIST pBtCoexist;
795 PADAPTER padapter;
796 PHAL_DATA_TYPE pHalData;
797 struct mlme_ext_priv *mlmeext;
798 u8 bSoftApExist, bVwifiExist;
799 u8 *pu8;
800 s32 *pS4Tmp;
801 u32 *pU4Tmp;
802 u8 *pU1Tmp;
803 u8 ret;
804
805
806 pBtCoexist = (PBTC_COEXIST)pBtcContext;
807 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
808 return _FALSE;
809
810 padapter = pBtCoexist->Adapter;
811 pHalData = GET_HAL_DATA(padapter);
812 mlmeext = &padapter->mlmeextpriv;
813 bSoftApExist = _FALSE;
814 bVwifiExist = _FALSE;
815 pu8 = (u8 *)pOutBuf;
816 pS4Tmp = (s32 *)pOutBuf;
817 pU4Tmp = (u32 *)pOutBuf;
818 pU1Tmp = (u8 *)pOutBuf;
819 ret = _TRUE;
820
821 switch (getType) {
822 case BTC_GET_BL_HS_OPERATION:
823 *pu8 = _FALSE;
824 ret = _FALSE;
825 break;
826
827 case BTC_GET_BL_HS_CONNECTING:
828 *pu8 = _FALSE;
829 ret = _FALSE;
830 break;
831
832 case BTC_GET_BL_WIFI_FW_READY:
833 *pu8 = halbtcoutsrc_is_fw_ready(pBtCoexist);
834 break;
835
836 case BTC_GET_BL_WIFI_CONNECTED:
837 *pu8 = (rtw_mi_check_status(padapter, MI_LINKED)) ? _TRUE : _FALSE;
838 break;
839
840 case BTC_GET_BL_WIFI_BUSY:
841 *pu8 = halbtcoutsrc_IsWifiBusy(padapter);
842 break;
843
844 case BTC_GET_BL_RF4CE_CONNECTED:
845 *pu8 = halbtcoutsrc_IsRF4CEConnected(padapter);
846 break;
847
848 case BTC_GET_BL_WIFI_SCAN:
849 #if 0
850 *pu8 = (rtw_mi_check_fwstate(padapter, WIFI_SITE_MONITOR)) ? _TRUE : _FALSE;
851 #else
852 /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag
853 WIFI_SITE_MONITOR in fwstate may not be cleared in time */
854 *pu8 = GLBtcWiFiInScanState;
855 #endif
856 break;
857
858 case BTC_GET_BL_WIFI_LINK:
859 *pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE;
860 break;
861
862 case BTC_GET_BL_WIFI_ROAM:
863 *pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE;
864 break;
865
866 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
867 *pu8 = _FALSE;
868 break;
869
870 case BTC_GET_BL_WIFI_UNDER_5G:
871 *pu8 = (pHalData->CurrentBandType == 1) ? _TRUE : _FALSE;
872 break;
873
874 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
875 *pu8 = (rtw_mi_check_status(padapter, MI_AP_MODE)) ? _TRUE : _FALSE;
876 break;
877
878 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
879 *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0 ? _FALSE : _TRUE;
880 break;
881
882 case BTC_GET_BL_WIFI_UNDER_B_MODE:
883 if (mlmeext->cur_wireless_mode == WIRELESS_11B)
884 *pu8 = _TRUE;
885 else
886 *pu8 = _FALSE;
887 break;
888
889 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
890 if (padapter->registrypriv.mp_mode == 0)
891 *pu8 = _FALSE;
892 else
893 *pu8 = _TRUE;
894 break;
895
896 case BTC_GET_BL_EXT_SWITCH:
897 *pu8 = _FALSE;
898 break;
899 case BTC_GET_BL_IS_ASUS_8723B:
900 /* Always return FALSE in linux driver since this case is added only for windows driver */
901 *pu8 = _FALSE;
902 break;
903
904 case BTC_GET_S4_WIFI_RSSI:
905 *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
906 break;
907
908 case BTC_GET_S4_HS_RSSI:
909 *pS4Tmp = 0;
910 ret = _FALSE;
911 break;
912
913 case BTC_GET_U4_WIFI_BW:
914 if (IsLegacyOnly(mlmeext->cur_wireless_mode))
915 *pU4Tmp = BTC_WIFI_BW_LEGACY;
916 else {
917 switch (pHalData->CurrentChannelBW) {
918 case CHANNEL_WIDTH_20:
919 *pU4Tmp = BTC_WIFI_BW_HT20;
920 break;
921 case CHANNEL_WIDTH_40:
922 *pU4Tmp = BTC_WIFI_BW_HT40;
923 break;
924 case CHANNEL_WIDTH_80:
925 *pU4Tmp = BTC_WIFI_BW_HT80;
926 break;
927 case CHANNEL_WIDTH_160:
928 *pU4Tmp = BTC_WIFI_BW_HT160;
929 break;
930 default:
931 RTW_INFO("[BTCOEX] unkown bandwidth(%d)\n", pHalData->CurrentChannelBW);
932 *pU4Tmp = BTC_WIFI_BW_HT40;
933 break;
934 }
935
936 }
937 break;
938
939 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION: {
940 PRT_LINK_DETECT_T plinkinfo;
941 plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
942
943 if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
944 *pU4Tmp = BTC_WIFI_TRAFFIC_TX;
945 else
946 *pU4Tmp = BTC_WIFI_TRAFFIC_RX;
947 }
948 break;
949
950 case BTC_GET_U4_WIFI_FW_VER:
951 *pU4Tmp = pHalData->FirmwareVersion << 16;
952 *pU4Tmp |= pHalData->FirmwareSubVersion;
953 break;
954
955 case BTC_GET_U4_WIFI_LINK_STATUS:
956 *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
957 break;
958
959 case BTC_GET_U4_BT_PATCH_VER:
960 *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
961 break;
962
963 case BTC_GET_U4_VENDOR:
964 *pU4Tmp = BTC_VENDOR_OTHER;
965 break;
966
967 case BTC_GET_U4_SUPPORTED_VERSION:
968 *pU4Tmp = halbtcoutsrc_GetBtCoexSupportedVersion(pBtCoexist);
969 break;
970 case BTC_GET_U4_SUPPORTED_FEATURE:
971 *pU4Tmp = halbtcoutsrc_GetBtCoexSupportedFeature(pBtCoexist);
972 break;
973
974 case BTC_GET_U4_WIFI_IQK_TOTAL:
975 *pU4Tmp = pHalData->odmpriv.nIQK_Cnt;
976 break;
977
978 case BTC_GET_U4_WIFI_IQK_OK:
979 *pU4Tmp = pHalData->odmpriv.nIQK_OK_Cnt;
980 break;
981
982 case BTC_GET_U4_WIFI_IQK_FAIL:
983 *pU4Tmp = pHalData->odmpriv.nIQK_Fail_Cnt;
984 break;
985
986 case BTC_GET_U1_WIFI_DOT11_CHNL:
987 *pU1Tmp = padapter->mlmeextpriv.cur_channel;
988 break;
989
990 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
991 *pU1Tmp = pHalData->CurrentChannel;
992 break;
993
994 case BTC_GET_U1_WIFI_HS_CHNL:
995 *pU1Tmp = 0;
996 ret = _FALSE;
997 break;
998
999 case BTC_GET_U1_WIFI_P2P_CHNL:
1000 #ifdef CONFIG_P2P
1001 {
1002 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1003
1004 *pU1Tmp = pwdinfo->operating_channel;
1005 }
1006 #else
1007 *pU1Tmp = 0;
1008 #endif
1009 break;
1010
1011 case BTC_GET_U1_MAC_PHY_MODE:
1012 /* *pU1Tmp = BTC_SMSP;
1013 * *pU1Tmp = BTC_DMSP;
1014 * *pU1Tmp = BTC_DMDP;
1015 * *pU1Tmp = BTC_MP_UNKNOWN; */
1016 break;
1017
1018 case BTC_GET_U1_AP_NUM:
1019 *pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);
1020 break;
1021 case BTC_GET_U1_ANT_TYPE:
1022 switch (pHalData->bt_coexist.btAntisolation) {
1023 case 0:
1024 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_0;
1025 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_0;
1026 break;
1027 case 1:
1028 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_1;
1029 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_1;
1030 break;
1031 case 2:
1032 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_2;
1033 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_2;
1034 break;
1035 case 3:
1036 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_3;
1037 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_3;
1038 break;
1039 case 4:
1040 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_4;
1041 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_4;
1042 break;
1043 }
1044 break;
1045 case BTC_GET_U1_IOT_PEER:
1046 *pU1Tmp = mlmeext->mlmext_info.assoc_AP_vendor;
1047 break;
1048
1049 /* =======1Ant=========== */
1050 case BTC_GET_U1_LPS_MODE:
1051 *pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;
1052 break;
1053
1054 default:
1055 ret = _FALSE;
1056 break;
1057 }
1058
1059 return ret;
1060 }
1061
halbtcoutsrc_Set(void * pBtcContext,u8 setType,void * pInBuf)1062 u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
1063 {
1064 PBTC_COEXIST pBtCoexist;
1065 PADAPTER padapter;
1066 PHAL_DATA_TYPE pHalData;
1067 u8 *pu8;
1068 u8 *pU1Tmp;
1069 u32 *pU4Tmp;
1070 u8 ret;
1071
1072
1073 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1074 padapter = pBtCoexist->Adapter;
1075 pHalData = GET_HAL_DATA(padapter);
1076 pu8 = (u8 *)pInBuf;
1077 pU1Tmp = (u8 *)pInBuf;
1078 pU4Tmp = (u32 *)pInBuf;
1079 ret = _TRUE;
1080
1081 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1082 return _FALSE;
1083
1084 switch (setType) {
1085 /* set some u8 type variables. */
1086 case BTC_SET_BL_BT_DISABLE:
1087 pBtCoexist->bt_info.bt_disabled = *pu8;
1088 break;
1089
1090 case BTC_SET_BL_BT_ENABLE_DISABLE_CHANGE:
1091 pBtCoexist->bt_info.bt_enable_disable_change = *pu8;
1092 break;
1093
1094 case BTC_SET_BL_BT_TRAFFIC_BUSY:
1095 pBtCoexist->bt_info.bt_busy = *pu8;
1096 break;
1097
1098 case BTC_SET_BL_BT_LIMITED_DIG:
1099 pBtCoexist->bt_info.limited_dig = *pu8;
1100 break;
1101
1102 case BTC_SET_BL_FORCE_TO_ROAM:
1103 pBtCoexist->bt_info.force_to_roam = *pu8;
1104 break;
1105
1106 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
1107 pBtCoexist->bt_info.reject_agg_pkt = *pu8;
1108 break;
1109
1110 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
1111 pBtCoexist->bt_info.bt_ctrl_agg_buf_size = *pu8;
1112 break;
1113
1114 case BTC_SET_BL_INC_SCAN_DEV_NUM:
1115 pBtCoexist->bt_info.increase_scan_dev_num = *pu8;
1116 break;
1117
1118 case BTC_SET_BL_BT_TX_RX_MASK:
1119 pBtCoexist->bt_info.bt_tx_rx_mask = *pu8;
1120 break;
1121
1122 case BTC_SET_BL_MIRACAST_PLUS_BT:
1123 pBtCoexist->bt_info.miracast_plus_bt = *pu8;
1124 break;
1125
1126 /* set some u8 type variables. */
1127 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
1128 pBtCoexist->bt_info.rssi_adjust_for_agc_table_on = *pU1Tmp;
1129 break;
1130
1131 case BTC_SET_U1_AGG_BUF_SIZE:
1132 pBtCoexist->bt_info.agg_buf_size = *pU1Tmp;
1133 break;
1134
1135 /* the following are some action which will be triggered */
1136 case BTC_SET_ACT_GET_BT_RSSI:
1137 #if 0
1138 BT_SendGetBtRssiEvent(padapter);
1139 #else
1140 ret = _FALSE;
1141 #endif
1142 break;
1143
1144 case BTC_SET_ACT_AGGREGATE_CTRL:
1145 halbtcoutsrc_AggregationCheck(pBtCoexist);
1146 break;
1147
1148 /* =======1Ant=========== */
1149 /* set some u8 type variables. */
1150 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
1151 pBtCoexist->bt_info.rssi_adjust_for_1ant_coex_type = *pU1Tmp;
1152 break;
1153
1154 case BTC_SET_U1_LPS_VAL:
1155 pBtCoexist->bt_info.lps_val = *pU1Tmp;
1156 break;
1157
1158 case BTC_SET_U1_RPWM_VAL:
1159 pBtCoexist->bt_info.rpwm_val = *pU1Tmp;
1160 break;
1161
1162 /* the following are some action which will be triggered */
1163 case BTC_SET_ACT_LEAVE_LPS:
1164 halbtcoutsrc_LeaveLps(pBtCoexist);
1165 break;
1166
1167 case BTC_SET_ACT_ENTER_LPS:
1168 halbtcoutsrc_EnterLps(pBtCoexist);
1169 break;
1170
1171 case BTC_SET_ACT_NORMAL_LPS:
1172 halbtcoutsrc_NormalLps(pBtCoexist);
1173 break;
1174
1175 case BTC_SET_ACT_DISABLE_LOW_POWER:
1176 halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
1177 break;
1178
1179 case BTC_SET_ACT_UPDATE_RAMASK:
1180 pBtCoexist->bt_info.ra_mask = *pU4Tmp;
1181
1182 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _TRUE) {
1183 struct sta_info *psta;
1184 PWLAN_BSSID_EX cur_network;
1185
1186 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
1187 psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress);
1188 rtw_hal_update_ra_mask(psta, 0);
1189 }
1190 break;
1191
1192 case BTC_SET_ACT_SEND_MIMO_PS: {
1193 u8 newMimoPsMode = 3;
1194 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1195 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1196
1197 /* *pU1Tmp = 0 use SM_PS static type */
1198 /* *pU1Tmp = 1 disable SM_PS */
1199 if (*pU1Tmp == 0)
1200 newMimoPsMode = WLAN_HT_CAP_SM_PS_STATIC;
1201 else if (*pU1Tmp == 1)
1202 newMimoPsMode = WLAN_HT_CAP_SM_PS_DISABLED;
1203
1204 if (check_fwstate(&padapter->mlmepriv , WIFI_ASOC_STATE) == _TRUE) {
1205 /* issue_action_SM_PS(padapter, get_my_bssid(&(pmlmeinfo->network)), newMimoPsMode); */
1206 issue_action_SM_PS_wait_ack(padapter , get_my_bssid(&(pmlmeinfo->network)) , newMimoPsMode, 3 , 1);
1207 }
1208 }
1209 break;
1210
1211 case BTC_SET_ACT_CTRL_BT_INFO:
1212 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
1213 {
1214 u8 dataLen = *pU1Tmp;
1215 u8 tmpBuf[BTC_TMP_BUF_SHORT];
1216 if (dataLen)
1217 _rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen);
1218 BT_SendEventExtBtInfoControl(padapter, dataLen, &tmpBuf[0]);
1219 }
1220 #else /* !CONFIG_BT_COEXIST_SOCKET_TRX */
1221 ret = _FALSE;
1222 #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
1223 break;
1224
1225 case BTC_SET_ACT_CTRL_BT_COEX:
1226 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
1227 {
1228 u8 dataLen = *pU1Tmp;
1229 u8 tmpBuf[BTC_TMP_BUF_SHORT];
1230 if (dataLen)
1231 _rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen);
1232 BT_SendEventExtBtCoexControl(padapter, _FALSE, dataLen, &tmpBuf[0]);
1233 }
1234 #else /* !CONFIG_BT_COEXIST_SOCKET_TRX */
1235 ret = _FALSE;
1236 #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
1237 break;
1238 case BTC_SET_ACT_CTRL_8723B_ANT:
1239 #if 0
1240 {
1241 u1Byte dataLen = *pU1Tmp;
1242 u1Byte tmpBuf[BTC_TMP_BUF_SHORT];
1243 if (dataLen)
1244 PlatformMoveMemory(&tmpBuf[0], pU1Tmp + 1, dataLen);
1245 BT_Set8723bAnt(Adapter, dataLen, &tmpBuf[0]);
1246 }
1247 #else
1248 ret = _FALSE;
1249 #endif
1250 break;
1251 /* ===================== */
1252 default:
1253 ret = _FALSE;
1254 break;
1255 }
1256
1257 return ret;
1258 }
1259
halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)1260 u8 halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)
1261 {
1262 PADAPTER padapter;
1263 struct pwrctrl_priv *pwrpriv;
1264 u8 bMacPwrCtrlOn;
1265
1266 padapter = pBtCoexist->Adapter;
1267 pwrpriv = &padapter->dvobj->pwrctl_priv;
1268 bMacPwrCtrlOn = _FALSE;
1269
1270 if ((_TRUE == pwrpriv->bips_processing)
1271 && (IPS_NONE != pwrpriv->ips_mode_req)
1272 )
1273 return _TRUE;
1274
1275 if (rf_off == pwrpriv->rf_pwrstate)
1276 return _TRUE;
1277
1278 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
1279 if (_FALSE == bMacPwrCtrlOn)
1280 return _TRUE;
1281
1282 return _FALSE;
1283 }
1284
halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)1285 u8 halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)
1286 {
1287 return GLBtcWiFiInLPS;
1288 }
1289
halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)1290 u8 halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)
1291 {
1292 /* todo: the method to check whether wifi is under 32K or not */
1293 return _FALSE;
1294 }
1295
halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)1296 void halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)
1297 {
1298 #if 0
1299 PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1300 PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1301 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
1302 u8 *cliBuf = pBtCoexist->cliBuf;
1303 u1Byte i, j;
1304 u1Byte tmpbuf[BTC_TMP_BUF_SHORT];
1305
1306
1307 if (gl_coex_offload.cnt_h2c_sent) {
1308 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex h2c notify]============");
1309 CL_PRINTF(cliBuf);
1310
1311 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = H2c(%d)/Ack(%d)", "Coex h2c/c2h overall statistics",
1312 gl_coex_offload.cnt_h2c_sent, gl_coex_offload.cnt_c2h_ack);
1313 for (j = 0; j < COL_STATUS_MAX; j++) {
1314 if (gl_coex_offload.status[j]) {
1315 CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.status[j]);
1316 CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
1317 }
1318 }
1319 CL_PRINTF(cliBuf);
1320 }
1321 for (i = 0; i < COL_OP_WIFI_OPCODE_MAX; i++) {
1322 if (gl_coex_offload.h2c_record[i].count) {
1323 /*==========================================*/
1324 /* H2C result statistics*/
1325 /*==========================================*/
1326 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = total:%d", coexOpcodeString[i], gl_coex_offload.h2c_record[i].count);
1327 for (j = 0; j < COL_STATUS_MAX; j++) {
1328 if (gl_coex_offload.h2c_record[i].status[j]) {
1329 CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.h2c_record[i].status[j]);
1330 CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
1331 }
1332 }
1333 CL_PRINTF(cliBuf);
1334 /*==========================================*/
1335 /* H2C/C2H content*/
1336 /*==========================================*/
1337 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = ", "H2C / C2H content");
1338 for (j = 0; j < gl_coex_offload.h2c_record[i].h2c_len; j++) {
1339 CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.h2c_record[i].h2c_buf[j]);
1340 CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
1341 }
1342 if (gl_coex_offload.h2c_record[i].c2h_ack_len) {
1343 CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, "/ ", 2);
1344 for (j = 0; j < gl_coex_offload.h2c_record[i].c2h_ack_len; j++) {
1345 CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.h2c_record[i].c2h_ack_buf[j]);
1346 CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
1347 }
1348 }
1349 CL_PRINTF(cliBuf);
1350 /*==========================================*/
1351 }
1352 }
1353
1354 if (gl_coex_offload.cnt_c2h_ind) {
1355 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex c2h indication]============");
1356 CL_PRINTF(cliBuf);
1357
1358 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = Ind(%d)", "C2H indication statistics",
1359 gl_coex_offload.cnt_c2h_ind);
1360 for (j = 0; j < COL_STATUS_MAX; j++) {
1361 if (gl_coex_offload.c2h_ind_status[j]) {
1362 CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.c2h_ind_status[j]);
1363 CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
1364 }
1365 }
1366 CL_PRINTF(cliBuf);
1367 }
1368 for (i = 0; i < COL_IND_MAX; i++) {
1369 if (gl_coex_offload.c2h_ind_record[i].count) {
1370 /*==========================================*/
1371 /* H2C result statistics*/
1372 /*==========================================*/
1373 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = total:%d", coexIndTypeString[i], gl_coex_offload.c2h_ind_record[i].count);
1374 for (j = 0; j < COL_STATUS_MAX; j++) {
1375 if (gl_coex_offload.c2h_ind_record[i].status[j]) {
1376 CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.c2h_ind_record[i].status[j]);
1377 CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
1378 }
1379 }
1380 CL_PRINTF(cliBuf);
1381 /*==========================================*/
1382 /* content*/
1383 /*==========================================*/
1384 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = ", "C2H indication content");
1385 for (j = 0; j < gl_coex_offload.c2h_ind_record[i].ind_len; j++) {
1386 CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.c2h_ind_record[i].ind_buf[j]);
1387 CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
1388 }
1389 CL_PRINTF(cliBuf);
1390 /*==========================================*/
1391 }
1392 }
1393
1394 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Statistics]============");
1395 CL_PRINTF(cliBuf);
1396
1397 #if (H2C_USE_IO_THREAD != 1)
1398 for (i = 0; i < H2C_STATUS_MAX; i++) {
1399 if (pHalData->h2cStatistics[i]) {
1400 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1401 h2cStaString[i], pHalData->h2cStatistics[i]);
1402 CL_PRINTF(cliBuf);
1403 }
1404 }
1405 #else
1406 for (i = 0; i < IO_STATUS_MAX; i++) {
1407 if (Adapter->ioComStr.ioH2cStatistics[i]) {
1408 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1409 ioStaString[i], Adapter->ioComStr.ioH2cStatistics[i]);
1410 CL_PRINTF(cliBuf);
1411 }
1412 }
1413 #endif
1414 #if 0
1415 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
1416 pHalData->LastHMEBoxNum);
1417 CL_PRINTF(cliBuf);
1418 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "LastOkH2c/FirstFailH2c(fwNotRead)", \
1419 pHalData->lastSuccessH2cEid, pHalData->firstFailedH2cEid);
1420 CL_PRINTF(cliBuf);
1421
1422 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "c2hIsr/c2hIntr/clr1AF/noRdy/noBuf", \
1423 pHalData->InterruptLog.nIMR_C2HCMD, DBG_Var.c2hInterruptCnt, DBG_Var.c2hClrReadC2hCnt,
1424 DBG_Var.c2hNotReadyCnt, DBG_Var.c2hBufAlloFailCnt);
1425 CL_PRINTF(cliBuf);
1426
1427 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "c2hPacket", \
1428 DBG_Var.c2hPacketCnt);
1429 CL_PRINTF(cliBuf);
1430 #endif
1431 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Periodical/ DbgCtrl", \
1432 pBtCoexist->statistics.cntPeriodical, pBtCoexist->statistics.cntDbgCtrl);
1433 CL_PRINTF(cliBuf);
1434 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "PowerOn/InitHw/InitCoexDm/RfStatus", \
1435 pBtCoexist->statistics.cntPowerOn, pBtCoexist->statistics.cntInitHwConfig, pBtCoexist->statistics.cntInitCoexDm,
1436 pBtCoexist->statistics.cntRfStatusNotify);
1437 CL_PRINTF(cliBuf);
1438 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "Ips/Lps/Scan/Connect/Mstatus", \
1439 pBtCoexist->statistics.cntIpsNotify, pBtCoexist->statistics.cntLpsNotify,
1440 pBtCoexist->statistics.cntScanNotify, pBtCoexist->statistics.cntConnectNotify,
1441 pBtCoexist->statistics.cntMediaStatusNotify);
1442 CL_PRINTF(cliBuf);
1443 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Special pkt/Bt info/ bind",
1444 pBtCoexist->statistics.cntSpecialPacketNotify, pBtCoexist->statistics.cntBtInfoNotify,
1445 pBtCoexist->statistics.cntBind);
1446 CL_PRINTF(cliBuf);
1447 #endif
1448 PADAPTER padapter = pBtCoexist->Adapter;
1449 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
1450 u8 *cliBuf = pBtCoexist->cli_buf;
1451
1452 if (pHalData->EEPROMBluetoothCoexist == 1) {
1453 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex Status]============");
1454 CL_PRINTF(cliBuf);
1455 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtDisabled", rtw_btcoex_IsBtDisabled(padapter));
1456 CL_PRINTF(cliBuf);
1457 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtControlLps", rtw_btcoex_IsBtControlLps(padapter));
1458 CL_PRINTF(cliBuf);
1459 }
1460 }
1461
halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)1462 void halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)
1463 {
1464 #if 0
1465 PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1466 PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1467 u8 *cliBuf = pBtCoexist->cliBuf;
1468 u8 i;
1469
1470
1471 if (pBtCoexist->stack_info.profile_notified) {
1472 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfACL; i++) {
1473 if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
1474 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role", \
1475 BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1476 BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec],
1477 BtLinkRoleString[pBtMgnt->ExtConfig.aclLink[i].linkRole]);
1478 CL_PRINTF(cliBuf);
1479 } else {
1480 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
1481 BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1482 BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec]);
1483 CL_PRINTF(cliBuf);
1484 }
1485 }
1486 }
1487 #endif
1488 }
1489
halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)1490 void halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)
1491 {
1492 PADAPTER padapter = pBtCoexist->Adapter;
1493 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1494 u8 *cliBuf = pBtCoexist->cli_buf;
1495 s32 wifiRssi = 0, btHsRssi = 0;
1496 BOOLEAN bScan = _FALSE, bLink = _FALSE, bRoam = _FALSE, bWifiBusy = _FALSE, bWifiUnderBMode = _FALSE;
1497 BOOLEAN bRf4CEConnected = _FALSE;
1498 u32 wifiBw = BTC_WIFI_BW_HT20, wifiTrafficDir = BTC_WIFI_TRAFFIC_TX, wifiFreq = BTC_FREQ_2_4G;
1499 u32 wifiLinkStatus = 0x0;
1500 BOOLEAN bBtHsOn = _FALSE, bLowPower = _FALSE;
1501 u8 wifiChnl = 0, wifiP2PChnl = 0, nScanAPNum = 0, FwPSState;
1502 u32 iqk_cnt_total = 0, iqk_cnt_ok = 0, iqk_cnt_fail = 0;
1503
1504 wifiLinkStatus = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
1505 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "STA/vWifi/HS/p2pGo/p2pGc", \
1506 ((wifiLinkStatus & WIFI_STA_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_AP_CONNECTED) ? 1 : 0),
1507 ((wifiLinkStatus & WIFI_HS_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
1508 ((wifiLinkStatus & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
1509 CL_PRINTF(cliBuf);
1510
1511 pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
1512 pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
1513 pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
1514 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Link/ Roam/ Scan", \
1515 bLink, bRoam, bScan);
1516 CL_PRINTF(cliBuf);
1517
1518 pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_TOTAL, &iqk_cnt_total);
1519 pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_OK, &iqk_cnt_ok);
1520 pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_FAIL, &iqk_cnt_fail);
1521 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d %s %s",
1522 "IQK All/ OK/ Fail/AutoLoad/FWDL", iqk_cnt_total, iqk_cnt_ok, iqk_cnt_fail,
1523 ((halbtcoutsrc_is_autoload_fail(pBtCoexist) == _TRUE) ? "fail":"ok"), ((halbtcoutsrc_is_fw_ready(pBtCoexist) == _TRUE) ? "ok":"fail"));
1524 CL_PRINTF(cliBuf);
1525
1526 if (wifiLinkStatus & WIFI_STA_CONNECTED) {
1527 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "IOT Peer", GLBtcIotPeerString[padapter->mlmeextpriv.mlmext_info.assoc_AP_vendor]);
1528 CL_PRINTF(cliBuf);
1529 }
1530
1531 pBtCoexist->btc_get(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
1532 pBtCoexist->btc_get(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiChnl);
1533 if ((wifiLinkStatus & WIFI_P2P_GO_CONNECTED) || (wifiLinkStatus & WIFI_P2P_GC_CONNECTED))
1534 pBtCoexist->btc_get(pBtCoexist, BTC_GET_U1_WIFI_P2P_CHNL, &wifiP2PChnl);
1535 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dBm/ %d/ %d", "RSSI/ STA_Chnl/ P2P_Chnl", \
1536 wifiRssi -100, wifiChnl, wifiP2PChnl);
1537 CL_PRINTF(cliBuf);
1538
1539 pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifiFreq);
1540 pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1541 pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1542 pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
1543 pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
1544 pBtCoexist->btc_get(pBtCoexist, BTC_GET_U1_AP_NUM, &nScanAPNum);
1545 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s/ %d ", "Band/ BW/ Traffic/ APCnt", \
1546 GLBtcWifiFreqString[wifiFreq], ((bWifiUnderBMode) ? "11b" : GLBtcWifiBwString[wifiBw]),
1547 ((!bWifiBusy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX == wifiTrafficDir) ? "uplink" : "downlink")),
1548 nScanAPNum);
1549 CL_PRINTF(cliBuf);
1550
1551 #ifdef CONFIG_RF4CE_COEXIST
1552 /* RF4CE ZigBee Status */
1553 pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_RF4CE_CONNECTED, &bRf4CEConnected);
1554 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "RF4CE", bRf4CEConnected?"ON":"idle");
1555 CL_PRINTF(cliBuf);
1556 #endif
1557
1558 /* power status */
1559 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s%s%s", "Power Status", \
1560 ((halbtcoutsrc_UnderIps(pBtCoexist) == _TRUE) ? "IPS ON" : "IPS OFF"),
1561 ((halbtcoutsrc_UnderLps(pBtCoexist) == _TRUE) ? ", LPS ON" : ", LPS OFF"),
1562 ((halbtcoutsrc_Under32K(pBtCoexist) == _TRUE) ? ", 32k" : ""));
1563 CL_PRINTF(cliBuf);
1564
1565 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)", "Power mode cmd(lps/rpwm)", \
1566 pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1],
1567 pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3],
1568 pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5],
1569 pBtCoexist->bt_info.lps_val,
1570 pBtCoexist->bt_info.rpwm_val);
1571 CL_PRINTF(cliBuf);
1572 }
1573
halbtcoutsrc_DisplayDbgMsg(void * pBtcContext,u8 dispType)1574 void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)
1575 {
1576 PBTC_COEXIST pBtCoexist;
1577
1578
1579 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1580 switch (dispType) {
1581 case BTC_DBG_DISP_COEX_STATISTICS:
1582 halbtcoutsrc_DisplayCoexStatistics(pBtCoexist);
1583 break;
1584 case BTC_DBG_DISP_BT_LINK_INFO:
1585 halbtcoutsrc_DisplayBtLinkInfo(pBtCoexist);
1586 break;
1587 case BTC_DBG_DISP_WIFI_STATUS:
1588 halbtcoutsrc_DisplayWifiStatus(pBtCoexist);
1589 break;
1590 default:
1591 break;
1592 }
1593 }
1594
1595 /* ************************************
1596 * IO related function
1597 * ************************************ */
halbtcoutsrc_Read1Byte(void * pBtcContext,u32 RegAddr)1598 u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
1599 {
1600 PBTC_COEXIST pBtCoexist;
1601 PADAPTER padapter;
1602
1603
1604 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1605 padapter = pBtCoexist->Adapter;
1606
1607 return rtw_read8(padapter, RegAddr);
1608 }
1609
halbtcoutsrc_Read2Byte(void * pBtcContext,u32 RegAddr)1610 u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
1611 {
1612 PBTC_COEXIST pBtCoexist;
1613 PADAPTER padapter;
1614
1615
1616 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1617 padapter = pBtCoexist->Adapter;
1618
1619 return rtw_read16(padapter, RegAddr);
1620 }
1621
halbtcoutsrc_Read4Byte(void * pBtcContext,u32 RegAddr)1622 u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
1623 {
1624 PBTC_COEXIST pBtCoexist;
1625 PADAPTER padapter;
1626
1627
1628 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1629 padapter = pBtCoexist->Adapter;
1630
1631 return rtw_read32(padapter, RegAddr);
1632 }
1633
halbtcoutsrc_Write1Byte(void * pBtcContext,u32 RegAddr,u8 Data)1634 void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1635 {
1636 PBTC_COEXIST pBtCoexist;
1637 PADAPTER padapter;
1638
1639
1640 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1641 padapter = pBtCoexist->Adapter;
1642
1643 rtw_write8(padapter, RegAddr, Data);
1644 }
1645
halbtcoutsrc_BitMaskWrite1Byte(void * pBtcContext,u32 regAddr,u8 bitMask,u8 data1b)1646 void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
1647 {
1648 PBTC_COEXIST pBtCoexist;
1649 PADAPTER padapter;
1650 u8 originalValue, bitShift;
1651 u8 i;
1652
1653
1654 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1655 padapter = pBtCoexist->Adapter;
1656 originalValue = 0;
1657 bitShift = 0;
1658
1659 if (bitMask != 0xff) {
1660 originalValue = rtw_read8(padapter, regAddr);
1661
1662 for (i = 0; i <= 7; i++) {
1663 if ((bitMask >> i) & 0x1)
1664 break;
1665 }
1666 bitShift = i;
1667
1668 data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
1669 }
1670
1671 rtw_write8(padapter, regAddr, data1b);
1672 }
1673
halbtcoutsrc_Write2Byte(void * pBtcContext,u32 RegAddr,u16 Data)1674 void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
1675 {
1676 PBTC_COEXIST pBtCoexist;
1677 PADAPTER padapter;
1678
1679
1680 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1681 padapter = pBtCoexist->Adapter;
1682
1683 rtw_write16(padapter, RegAddr, Data);
1684 }
1685
halbtcoutsrc_Write4Byte(void * pBtcContext,u32 RegAddr,u32 Data)1686 void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
1687 {
1688 PBTC_COEXIST pBtCoexist;
1689 PADAPTER padapter;
1690
1691
1692 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1693 padapter = pBtCoexist->Adapter;
1694
1695 rtw_write32(padapter, RegAddr, Data);
1696 }
1697
halbtcoutsrc_WriteLocalReg1Byte(void * pBtcContext,u32 RegAddr,u8 Data)1698 void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1699 {
1700 PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext;
1701 PADAPTER Adapter = pBtCoexist->Adapter;
1702
1703 if (BTC_INTF_SDIO == pBtCoexist->chip_interface)
1704 rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
1705 else
1706 rtw_write8(Adapter, RegAddr, Data);
1707 }
1708
halbtcoutsrc_SetBbReg(void * pBtcContext,u32 RegAddr,u32 BitMask,u32 Data)1709 void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
1710 {
1711 PBTC_COEXIST pBtCoexist;
1712 PADAPTER padapter;
1713
1714
1715 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1716 padapter = pBtCoexist->Adapter;
1717
1718 PHY_SetBBReg(padapter, RegAddr, BitMask, Data);
1719 }
1720
1721
halbtcoutsrc_GetBbReg(void * pBtcContext,u32 RegAddr,u32 BitMask)1722 u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
1723 {
1724 PBTC_COEXIST pBtCoexist;
1725 PADAPTER padapter;
1726
1727
1728 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1729 padapter = pBtCoexist->Adapter;
1730
1731 return PHY_QueryBBReg(padapter, RegAddr, BitMask);
1732 }
1733
halbtcoutsrc_SetRfReg(void * pBtcContext,u8 eRFPath,u32 RegAddr,u32 BitMask,u32 Data)1734 void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
1735 {
1736 PBTC_COEXIST pBtCoexist;
1737 PADAPTER padapter;
1738
1739
1740 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1741 padapter = pBtCoexist->Adapter;
1742
1743 PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data);
1744 }
1745
halbtcoutsrc_GetRfReg(void * pBtcContext,u8 eRFPath,u32 RegAddr,u32 BitMask)1746 u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
1747 {
1748 PBTC_COEXIST pBtCoexist;
1749 PADAPTER padapter;
1750
1751
1752 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1753 padapter = pBtCoexist->Adapter;
1754
1755 return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask);
1756 }
1757
halbtcoutsrc_SetBtReg(void * pBtcContext,u8 RegType,u32 RegAddr,u32 Data)1758 u16 halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
1759 {
1760 PBTC_COEXIST pBtCoexist;
1761 u16 ret = BT_STATUS_BT_OP_SUCCESS;
1762
1763 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1764
1765 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
1766 u8 buf[3] = {0};
1767 _irqL irqL;
1768 u8 op_code;
1769 u8 status;
1770
1771 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1772
1773 Data = cpu_to_le32(Data);
1774 op_code = BT_OP_WRITE_REG_VALUE;
1775 status = _btmpoper_cmd(pBtCoexist, op_code, 0, (u8 *)&Data, 3);
1776 if (status != BT_STATUS_BT_OP_SUCCESS)
1777 ret = SET_BT_MP_OPER_RET(op_code, status);
1778 else {
1779 buf[0] = RegType;
1780 *(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr);
1781 op_code = BT_OP_WRITE_REG_ADDR;
1782 status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);
1783 if (status != BT_STATUS_BT_OP_SUCCESS)
1784 ret = SET_BT_MP_OPER_RET(op_code, status);
1785 }
1786
1787 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1788 } else
1789 ret = BT_STATUS_NOT_IMPLEMENT;
1790
1791 return ret;
1792 }
1793
halbtcoutsrc_SetBtAntDetection(void * pBtcContext,u8 txTime,u8 btChnl)1794 u8 halbtcoutsrc_SetBtAntDetection(void *pBtcContext, u8 txTime, u8 btChnl)
1795 {
1796 /* Always return _FALSE since we don't implement this yet */
1797 #if 0
1798 PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext;
1799 PADAPTER Adapter = pBtCoexist->Adapter;
1800 u1Byte btCanTx = 0;
1801 BOOLEAN bStatus = FALSE;
1802
1803 bStatus = NDBG_SetBtAntDetection(Adapter, txTime, btChnl, &btCanTx);
1804 if (bStatus && btCanTx)
1805 return _TRUE;
1806 else
1807 return _FALSE;
1808 #else
1809 return _FALSE;
1810 #endif
1811 }
1812
1813 BOOLEAN
halbtcoutsrc_SetBtTRXMASK(IN PVOID pBtcContext,IN u1Byte bt_trx_mask)1814 halbtcoutsrc_SetBtTRXMASK(
1815 IN PVOID pBtcContext,
1816 IN u1Byte bt_trx_mask
1817 )
1818 {
1819 /* Always return _FALSE since we don't implement this yet */
1820 #if 0
1821 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
1822 PADAPTER Adapter = pBtCoexist->Adapter;
1823 BOOLEAN bStatus = FALSE;
1824 u1Byte btCanTx = 0;
1825
1826 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter) || IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)
1827 || IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
1828
1829 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1830 bStatus = NDBG_SetBtTRXMASK(Adapter, 1, bt_trx_mask, &btCanTx);
1831 else
1832 bStatus = NDBG_SetBtTRXMASK(Adapter, 2, bt_trx_mask, &btCanTx);
1833 }
1834
1835
1836 if (bStatus)
1837 return TRUE;
1838 else
1839 return FALSE;
1840 #else
1841 return _FALSE;
1842 #endif
1843 }
1844
halbtcoutsrc_GetBtReg_with_status(void * pBtcContext,u8 RegType,u32 RegAddr,u32 * data)1845 u16 halbtcoutsrc_GetBtReg_with_status(void *pBtcContext, u8 RegType, u32 RegAddr, u32 *data)
1846 {
1847 PBTC_COEXIST pBtCoexist;
1848 u16 ret = BT_STATUS_BT_OP_SUCCESS;
1849
1850 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1851
1852 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
1853 u8 buf[3] = {0};
1854 _irqL irqL;
1855 u8 op_code;
1856 u8 status;
1857
1858 buf[0] = RegType;
1859 *(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr);
1860
1861 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1862
1863 op_code = BT_OP_READ_REG;
1864 status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);
1865 if (status == BT_STATUS_BT_OP_SUCCESS)
1866 *data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
1867 else
1868 ret = SET_BT_MP_OPER_RET(op_code, status);
1869
1870 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1871
1872 } else
1873 ret = BT_STATUS_NOT_IMPLEMENT;
1874
1875 return ret;
1876 }
1877
halbtcoutsrc_GetBtReg(void * pBtcContext,u8 RegType,u32 RegAddr)1878 u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
1879 {
1880 u32 regVal;
1881
1882 return (BT_STATUS_BT_OP_SUCCESS == halbtcoutsrc_GetBtReg_with_status(pBtcContext, RegType, RegAddr, ®Val)) ? regVal : 0xffffffff;
1883 }
1884
halbtcoutsrc_FillH2cCmd(void * pBtcContext,u8 elementId,u32 cmdLen,u8 * pCmdBuffer)1885 void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
1886 {
1887 PBTC_COEXIST pBtCoexist;
1888 PADAPTER padapter;
1889
1890
1891 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1892 padapter = pBtCoexist->Adapter;
1893
1894 rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
1895 }
1896
halbtcoutsrc_coex_offload_init(void)1897 static void halbtcoutsrc_coex_offload_init(void)
1898 {
1899 u1Byte i;
1900
1901 gl_coex_offload.h2c_req_num = 0;
1902 gl_coex_offload.cnt_h2c_sent = 0;
1903 gl_coex_offload.cnt_c2h_ack = 0;
1904 gl_coex_offload.cnt_c2h_ind = 0;
1905
1906 for (i = 0; i < COL_MAX_H2C_REQ_NUM; i++)
1907 init_completion(&gl_coex_offload.c2h_event[i]);
1908 }
1909
halbtcoutsrc_send_h2c(PADAPTER Adapter,PCOL_H2C pcol_h2c,u16 h2c_cmd_len)1910 static COL_H2C_STATUS halbtcoutsrc_send_h2c(PADAPTER Adapter, PCOL_H2C pcol_h2c, u16 h2c_cmd_len)
1911 {
1912 COL_H2C_STATUS h2c_status = COL_STATUS_C2H_OK;
1913 u8 i;
1914
1915 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
1916 reinit_completion(&gl_coex_offload.c2h_event[pcol_h2c->req_num]); /* set event to un signaled state */
1917 #else
1918 INIT_COMPLETION(gl_coex_offload.c2h_event[pcol_h2c->req_num]);
1919 #endif
1920
1921 if (TRUE) {
1922 #if 0 /*(USE_HAL_MAC_API == 1) */
1923 if (RT_STATUS_SUCCESS == HAL_MAC_Send_BT_COEX(&GET_HAL_MAC_INFO(Adapter), (pu1Byte)(pcol_h2c), (u4Byte)h2c_cmd_len, 1)) {
1924 if (!wait_for_completion_timeout(&gl_coex_offload.c2h_event[pcol_h2c->req_num], 20)) {
1925 h2c_status = COL_STATUS_H2C_TIMTOUT;
1926 }
1927 } else {
1928 h2c_status = COL_STATUS_H2C_HALMAC_FAIL;
1929 }
1930 #endif
1931 }
1932
1933 return h2c_status;
1934 }
1935
halbtcoutsrc_check_c2h_ack(PADAPTER Adapter,PCOL_SINGLE_H2C_RECORD pH2cRecord)1936 static COL_H2C_STATUS halbtcoutsrc_check_c2h_ack(PADAPTER Adapter, PCOL_SINGLE_H2C_RECORD pH2cRecord)
1937 {
1938 COL_H2C_STATUS c2h_status = COL_STATUS_C2H_OK;
1939 PCOL_H2C p_h2c_cmd = (PCOL_H2C)&pH2cRecord->h2c_buf[0];
1940 u8 req_num = p_h2c_cmd->req_num;
1941 PCOL_C2H_ACK p_c2h_ack = (PCOL_C2H_ACK)&gl_coex_offload.c2h_ack_buf[req_num];
1942
1943
1944 if ((COL_C2H_ACK_HDR_LEN + p_c2h_ack->ret_len) > gl_coex_offload.c2h_ack_len[req_num]) {
1945 c2h_status = COL_STATUS_COEX_DATA_OVERFLOW;
1946 return c2h_status;
1947 }
1948 /* else */
1949 {
1950 _rtw_memmove(&pH2cRecord->c2h_ack_buf[0], &gl_coex_offload.c2h_ack_buf[req_num], gl_coex_offload.c2h_ack_len[req_num]);
1951 pH2cRecord->c2h_ack_len = gl_coex_offload.c2h_ack_len[req_num];
1952 }
1953
1954
1955 if (p_c2h_ack->req_num != p_h2c_cmd->req_num) {
1956 c2h_status = COL_STATUS_C2H_REQ_NUM_MISMATCH;
1957 } else if (p_c2h_ack->opcode_ver != p_h2c_cmd->opcode_ver) {
1958 c2h_status = COL_STATUS_C2H_OPCODE_VER_MISMATCH;
1959 } else {
1960 c2h_status = p_c2h_ack->status;
1961 }
1962
1963 return c2h_status;
1964 }
1965
halbtcoutsrc_CoexH2cProcess(void * pBtCoexist,u8 opcode,u8 opcode_ver,u8 * ph2c_par,u8 h2c_par_len)1966 COL_H2C_STATUS halbtcoutsrc_CoexH2cProcess(void *pBtCoexist,
1967 u8 opcode, u8 opcode_ver, u8 *ph2c_par, u8 h2c_par_len)
1968 {
1969 PADAPTER Adapter = ((struct btc_coexist *)pBtCoexist)->Adapter;
1970 u8 H2C_Parameter[BTC_TMP_BUF_SHORT] = {0};
1971 PCOL_H2C pcol_h2c = (PCOL_H2C)&H2C_Parameter[0];
1972 u16 paraLen = 0;
1973 COL_H2C_STATUS h2c_status = COL_STATUS_C2H_OK, c2h_status = COL_STATUS_C2H_OK;
1974 COL_H2C_STATUS ret_status = COL_STATUS_C2H_OK;
1975 u16 i, col_h2c_len = 0;
1976
1977 pcol_h2c->opcode = opcode;
1978 pcol_h2c->opcode_ver = opcode_ver;
1979 pcol_h2c->req_num = gl_coex_offload.h2c_req_num;
1980 gl_coex_offload.h2c_req_num++;
1981 gl_coex_offload.h2c_req_num %= 16;
1982
1983 _rtw_memmove(&pcol_h2c->buf[0], ph2c_par, h2c_par_len);
1984
1985
1986 col_h2c_len = h2c_par_len + 2; /* 2=sizeof(OPCode, OPCode_version and Request number) */
1987 BT_PrintData(Adapter, "[COL], H2C cmd: ", col_h2c_len, H2C_Parameter);
1988
1989 gl_coex_offload.cnt_h2c_sent++;
1990
1991 gl_coex_offload.h2c_record[opcode].count++;
1992 gl_coex_offload.h2c_record[opcode].h2c_len = col_h2c_len;
1993 _rtw_memmove((PVOID)&gl_coex_offload.h2c_record[opcode].h2c_buf[0], (PVOID)pcol_h2c, col_h2c_len);
1994
1995 h2c_status = halbtcoutsrc_send_h2c(Adapter, pcol_h2c, col_h2c_len);
1996
1997 gl_coex_offload.h2c_record[opcode].c2h_ack_len = 0;
1998
1999 if (COL_STATUS_C2H_OK == h2c_status) {
2000 /* if reach here, it means H2C get the correct c2h response, */
2001 c2h_status = halbtcoutsrc_check_c2h_ack(Adapter, &gl_coex_offload.h2c_record[opcode]);
2002 ret_status = c2h_status;
2003 } else {
2004 /* check h2c status error, return error status code to upper layer. */
2005 ret_status = h2c_status;
2006 }
2007 gl_coex_offload.h2c_record[opcode].status[ret_status]++;
2008 gl_coex_offload.status[ret_status]++;
2009
2010 return ret_status;
2011 }
2012
halbtcoutsrc_GetAntDetValFromBt(void * pBtcContext)2013 u8 halbtcoutsrc_GetAntDetValFromBt(void *pBtcContext)
2014 {
2015 /* Always return 0 since we don't implement this yet */
2016 #if 0
2017 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2018 PADAPTER Adapter = pBtCoexist->Adapter;
2019 u1Byte AntDetVal = 0x0;
2020 u1Byte opcodeVer = 1;
2021 BOOLEAN status = false;
2022
2023 status = NDBG_GetAntDetValFromBt(Adapter, opcodeVer, &AntDetVal);
2024
2025 RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$ halbtcoutsrc_GetAntDetValFromBt(): status = %d, feature = %x\n", status, AntDetVal));
2026
2027 return AntDetVal;
2028 #else
2029 return 0;
2030 #endif
2031 }
2032
halbtcoutsrc_GetBleScanTypeFromBt(void * pBtcContext)2033 u8 halbtcoutsrc_GetBleScanTypeFromBt(void *pBtcContext)
2034 {
2035 PBTC_COEXIST pBtCoexist;
2036 u32 ret = BT_STATUS_BT_OP_SUCCESS;
2037 u8 data = 0;
2038
2039 pBtCoexist = (PBTC_COEXIST)pBtcContext;
2040
2041 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
2042 u8 buf[3] = {0};
2043 _irqL irqL;
2044 u8 op_code;
2045 u8 status;
2046
2047
2048 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2049
2050 op_code = BT_OP_GET_BT_BLE_SCAN_TYPE;
2051 status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
2052 if (status == BT_STATUS_BT_OP_SUCCESS)
2053 data = *(u8 *)GLBtcBtMpRptRsp;
2054 else
2055 ret = SET_BT_MP_OPER_RET(op_code, status);
2056
2057 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2058
2059 } else
2060 ret = BT_STATUS_NOT_IMPLEMENT;
2061
2062 return data;
2063 }
2064
halbtcoutsrc_GetBleScanParaFromBt(void * pBtcContext,u8 scanType)2065 u32 halbtcoutsrc_GetBleScanParaFromBt(void *pBtcContext, u8 scanType)
2066 {
2067 PBTC_COEXIST pBtCoexist;
2068 u32 ret = BT_STATUS_BT_OP_SUCCESS;
2069 u32 data = 0;
2070
2071 pBtCoexist = (PBTC_COEXIST)pBtcContext;
2072
2073 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
2074 u8 buf[3] = {0};
2075 _irqL irqL;
2076 u8 op_code;
2077 u8 status;
2078
2079
2080 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2081
2082 op_code = BT_OP_GET_BT_BLE_SCAN_PARA;
2083 status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
2084 if (status == BT_STATUS_BT_OP_SUCCESS)
2085 data = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
2086 else
2087 ret = SET_BT_MP_OPER_RET(op_code, status);
2088
2089 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2090
2091 } else
2092 ret = BT_STATUS_NOT_IMPLEMENT;
2093
2094 return data;
2095 }
2096
halbtcoutsrc_GetPhydmVersion(void * pBtcContext)2097 u32 halbtcoutsrc_GetPhydmVersion(void *pBtcContext)
2098 {
2099 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2100 PADAPTER Adapter = pBtCoexist->Adapter;
2101
2102 #ifdef CONFIG_RTL8192E
2103 return RELEASE_VERSION_8192E;
2104 #endif
2105
2106 #ifdef CONFIG_RTL8821A
2107 return RELEASE_VERSION_8821A;
2108 #endif
2109
2110 #ifdef CONFIG_RTL8723B
2111 return RELEASE_VERSION_8723B;
2112 #endif
2113
2114 #ifdef CONFIG_RTL8812A
2115 return RELEASE_VERSION_8812A;
2116 #endif
2117
2118 #ifdef CONFIG_RTL8703B
2119 return RELEASE_VERSION_8703B;
2120 #endif
2121
2122 #ifdef CONFIG_RTL8822B
2123 return RELEASE_VERSION_8822B;
2124 #endif
2125
2126 #ifdef CONFIG_RTL8723D
2127 return RELEASE_VERSION_8723D;
2128 #endif
2129
2130 }
2131
halbtcoutsrc_phydm_modify_RA_PCR_threshold(void * pBtcContext,u8 RA_offset_direction,u8 RA_threshold_offset)2132 void halbtcoutsrc_phydm_modify_RA_PCR_threshold(void *pBtcContext, u8 RA_offset_direction, u8 RA_threshold_offset)
2133 {
2134 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2135
2136 /* switch to #if 0 in case the phydm version does not provide the function */
2137 #if 0
2138 phydm_modify_RA_PCR_threshold(pBtCoexist->odm_priv, RA_offset_direction, RA_threshold_offset);
2139 #endif
2140 }
2141
2142 #if 0
2143 static void BT_CoexOffloadRecordErrC2hAck(PADAPTER Adapter)
2144 {
2145 PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter);
2146
2147 if (pDefaultAdapter != Adapter)
2148 return;
2149
2150 if (!hal_btcoex_IsBtExist(Adapter))
2151 return;
2152
2153 gl_coex_offload.cnt_c2h_ack++;
2154
2155 gl_coex_offload.status[COL_STATUS_INVALID_C2H_LEN]++;
2156 }
2157
2158 static void BT_CoexOffloadC2hAckCheck(PADAPTER Adapter, u8 *tmpBuf, u8 length)
2159 {
2160 PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter);
2161 PCOL_C2H_ACK p_c2h_ack = NULL;
2162 u8 req_num = 0xff;
2163
2164 if (pDefaultAdapter != Adapter)
2165 return;
2166
2167 if (!hal_btcoex_IsBtExist(Adapter))
2168 return;
2169
2170 gl_coex_offload.cnt_c2h_ack++;
2171
2172 if (length < COL_C2H_ACK_HDR_LEN) { /* c2h ack length must >= 3 (status, opcode_ver, req_num and ret_len) */
2173 gl_coex_offload.status[COL_STATUS_INVALID_C2H_LEN]++;
2174 } else {
2175 BT_PrintData(Adapter, "[COL], c2h ack:", length, tmpBuf);
2176
2177 p_c2h_ack = (PCOL_C2H_ACK)tmpBuf;
2178 req_num = p_c2h_ack->req_num;
2179
2180 _rtw_memmove(&gl_coex_offload.c2h_ack_buf[req_num][0], tmpBuf, length);
2181 gl_coex_offload.c2h_ack_len[req_num] = length;
2182
2183 complete(&gl_coex_offload.c2h_event[req_num]);
2184 }
2185 }
2186
2187 static void BT_CoexOffloadC2hIndCheck(PADAPTER Adapter, u8 *tmpBuf, u8 length)
2188 {
2189 PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter);
2190 PCOL_C2H_IND p_c2h_ind = NULL;
2191 u8 ind_type = 0, ind_version = 0, ind_length = 0;
2192
2193 if (pDefaultAdapter != Adapter)
2194 return;
2195
2196 if (!hal_btcoex_IsBtExist(Adapter))
2197 return;
2198
2199 gl_coex_offload.cnt_c2h_ind++;
2200
2201 if (length < COL_C2H_IND_HDR_LEN) { /* c2h indication length must >= 3 (type, version and length) */
2202 gl_coex_offload.c2h_ind_status[COL_STATUS_INVALID_C2H_LEN]++;
2203 } else {
2204 BT_PrintData(Adapter, "[COL], c2h indication:", length, tmpBuf);
2205
2206 p_c2h_ind = (PCOL_C2H_IND)tmpBuf;
2207 ind_type = p_c2h_ind->type;
2208 ind_version = p_c2h_ind->version;
2209 ind_length = p_c2h_ind->length;
2210
2211 _rtw_memmove(&gl_coex_offload.c2h_ind_buf[0], tmpBuf, length);
2212 gl_coex_offload.c2h_ind_len = length;
2213
2214 /* log */
2215 gl_coex_offload.c2h_ind_record[ind_type].count++;
2216 gl_coex_offload.c2h_ind_record[ind_type].status[COL_STATUS_C2H_OK]++;
2217 _rtw_memmove(&gl_coex_offload.c2h_ind_record[ind_type].ind_buf[0], tmpBuf, length);
2218 gl_coex_offload.c2h_ind_record[ind_type].ind_len = length;
2219
2220 gl_coex_offload.c2h_ind_status[COL_STATUS_C2H_OK]++;
2221 /*TODO: need to check c2h indication length*/
2222 /* TODO: Notification */
2223 }
2224 }
2225
2226 void BT_CoexOffloadC2hCheck(PADAPTER Adapter, u8 *Buffer, u8 Length)
2227 {
2228 #if 0 /*(USE_HAL_MAC_API == 1)*/
2229 u8 c2hSubCmdId = 0, c2hAckLen = 0, h2cCmdId = 0, h2cSubCmdId = 0, c2hIndLen = 0;
2230
2231 BT_PrintData(Adapter, "[COL], c2h packet:", Length - 2, Buffer + 2);
2232 c2hSubCmdId = (u1Byte)C2H_HDR_GET_C2H_SUB_CMD_ID(Buffer);
2233
2234 if (c2hSubCmdId == C2H_SUB_CMD_ID_H2C_ACK_HDR ||
2235 c2hSubCmdId == C2H_SUB_CMD_ID_BT_COEX_INFO) {
2236 if (c2hSubCmdId == C2H_SUB_CMD_ID_H2C_ACK_HDR) {
2237 /* coex c2h ack */
2238 h2cCmdId = (u1Byte)H2C_ACK_HDR_GET_H2C_CMD_ID(Buffer);
2239 h2cSubCmdId = (u1Byte)H2C_ACK_HDR_GET_H2C_SUB_CMD_ID(Buffer);
2240 if (h2cCmdId == 0xff && h2cSubCmdId == 0x60) {
2241 c2hAckLen = (u1Byte)C2H_HDR_GET_LEN(Buffer);
2242 if (c2hAckLen >= 8)
2243 BT_CoexOffloadC2hAckCheck(Adapter, &Buffer[12], (u1Byte)(c2hAckLen - 8));
2244 else
2245 BT_CoexOffloadRecordErrC2hAck(Adapter);
2246 }
2247 } else if (c2hSubCmdId == C2H_SUB_CMD_ID_BT_COEX_INFO) {
2248 /* coex c2h indication */
2249 c2hIndLen = (u1Byte)C2H_HDR_GET_LEN(Buffer);
2250 BT_CoexOffloadC2hIndCheck(Adapter, &Buffer[4], (u1Byte)c2hIndLen);
2251 }
2252 }
2253 #endif
2254 }
2255 #endif
2256
2257 /* ************************************
2258 * Extern functions called by other module
2259 * ************************************ */
EXhalbtcoutsrc_BindBtCoexWithAdapter(void * padapter)2260 u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
2261 {
2262 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2263 u8 antNum = 1, chipType = 0, singleAntPath = 0;
2264 HAL_DATA_TYPE *pHalData = GET_HAL_DATA((PADAPTER)padapter);
2265
2266 if (pBtCoexist->bBinded)
2267 return _FALSE;
2268 else
2269 pBtCoexist->bBinded = _TRUE;
2270
2271 pBtCoexist->statistics.cnt_bind++;
2272
2273 pBtCoexist->Adapter = padapter;
2274 pBtCoexist->odm_priv = (PVOID)&(pHalData->odmpriv);
2275
2276 pBtCoexist->stack_info.profile_notified = _FALSE;
2277
2278 pBtCoexist->bt_info.bt_ctrl_agg_buf_size = _FALSE;
2279 pBtCoexist->bt_info.agg_buf_size = 5;
2280
2281 pBtCoexist->bt_info.increase_scan_dev_num = _FALSE;
2282 pBtCoexist->bt_info.miracast_plus_bt = _FALSE;
2283
2284 antNum = rtw_btcoex_get_pg_ant_num((PADAPTER)padapter);
2285 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
2286
2287 if (antNum == 1) {
2288 singleAntPath = rtw_btcoex_get_pg_single_ant_path((PADAPTER)padapter);
2289 EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
2290 }
2291
2292 /* set default antenna position to main port */
2293 pBtCoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
2294
2295 pBtCoexist->board_info.btdm_ant_det_finish = _FALSE;
2296 pBtCoexist->board_info.btdm_ant_num_by_ant_det = 1;
2297
2298 pBtCoexist->board_info.tfbga_package = rtw_btcoex_is_tfbga_package_type((PADAPTER)padapter);
2299
2300 pBtCoexist->board_info.rfe_type = rtw_btcoex_get_pg_rfe_type((PADAPTER)padapter);
2301
2302 pBtCoexist->board_info.ant_div_cfg = rtw_btcoex_get_ant_div_cfg((PADAPTER)padapter);
2303
2304 return _TRUE;
2305 }
2306
EXhalbtcoutsrc_InitlizeVariables(void * padapter)2307 u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)
2308 {
2309 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2310
2311 /* pBtCoexist->statistics.cntBind++; */
2312
2313 halbtcoutsrc_DbgInit();
2314
2315 halbtcoutsrc_coex_offload_init();
2316
2317 #ifdef CONFIG_PCI_HCI
2318 pBtCoexist->chip_interface = BTC_INTF_PCI;
2319 #elif defined(CONFIG_USB_HCI)
2320 pBtCoexist->chip_interface = BTC_INTF_USB;
2321 #elif defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
2322 pBtCoexist->chip_interface = BTC_INTF_SDIO;
2323 #else
2324 pBtCoexist->chip_interface = BTC_INTF_UNKNOWN;
2325 #endif
2326
2327 EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
2328
2329 pBtCoexist->btc_read_1byte = halbtcoutsrc_Read1Byte;
2330 pBtCoexist->btc_write_1byte = halbtcoutsrc_Write1Byte;
2331 pBtCoexist->btc_write_1byte_bitmask = halbtcoutsrc_BitMaskWrite1Byte;
2332 pBtCoexist->btc_read_2byte = halbtcoutsrc_Read2Byte;
2333 pBtCoexist->btc_write_2byte = halbtcoutsrc_Write2Byte;
2334 pBtCoexist->btc_read_4byte = halbtcoutsrc_Read4Byte;
2335 pBtCoexist->btc_write_4byte = halbtcoutsrc_Write4Byte;
2336 pBtCoexist->btc_write_local_reg_1byte = halbtcoutsrc_WriteLocalReg1Byte;
2337
2338 pBtCoexist->btc_set_bb_reg = halbtcoutsrc_SetBbReg;
2339 pBtCoexist->btc_get_bb_reg = halbtcoutsrc_GetBbReg;
2340
2341 pBtCoexist->btc_set_rf_reg = halbtcoutsrc_SetRfReg;
2342 pBtCoexist->btc_get_rf_reg = halbtcoutsrc_GetRfReg;
2343
2344 pBtCoexist->btc_fill_h2c = halbtcoutsrc_FillH2cCmd;
2345 pBtCoexist->btc_disp_dbg_msg = halbtcoutsrc_DisplayDbgMsg;
2346
2347 pBtCoexist->btc_get = halbtcoutsrc_Get;
2348 pBtCoexist->btc_set = halbtcoutsrc_Set;
2349 pBtCoexist->btc_get_bt_reg = halbtcoutsrc_GetBtReg;
2350 pBtCoexist->btc_set_bt_reg = halbtcoutsrc_SetBtReg;
2351 pBtCoexist->btc_set_bt_ant_detection = halbtcoutsrc_SetBtAntDetection;
2352 pBtCoexist->btc_set_bt_trx_mask = halbtcoutsrc_SetBtTRXMASK;
2353 pBtCoexist->btc_coex_h2c_process = halbtcoutsrc_CoexH2cProcess;
2354 pBtCoexist->btc_get_bt_coex_supported_feature = halbtcoutsrc_GetBtCoexSupportedFeature;
2355 pBtCoexist->btc_get_bt_coex_supported_version= halbtcoutsrc_GetBtCoexSupportedVersion;
2356 pBtCoexist->btc_get_ant_det_val_from_bt = halbtcoutsrc_GetAntDetValFromBt;
2357 pBtCoexist->btc_get_ble_scan_type_from_bt = halbtcoutsrc_GetBleScanTypeFromBt;
2358 pBtCoexist->btc_get_ble_scan_para_from_bt = halbtcoutsrc_GetBleScanParaFromBt;
2359 pBtCoexist->btc_get_bt_phydm_version = halbtcoutsrc_GetPhydmVersion;
2360 pBtCoexist->btc_phydm_modify_RA_PCR_threshold = halbtcoutsrc_phydm_modify_RA_PCR_threshold;
2361
2362 pBtCoexist->cli_buf = &GLBtcDbgBuf[0];
2363
2364 GLBtcWiFiInScanState = _FALSE;
2365
2366 GLBtcWiFiInIQKState = _FALSE;
2367
2368 GLBtcWiFiInIPS = _FALSE;
2369
2370 GLBtcWiFiInLPS = _FALSE;
2371
2372 GLBtcBtCoexAliveRegistered = _FALSE;
2373
2374 /* BT Control H2C/C2H*/
2375 GLBtcBtMpOperSeq = 0;
2376 _rtw_mutex_init(&GLBtcBtMpOperLock);
2377 _init_timer(&GLBtcBtMpOperTimer, ((PADAPTER)padapter)->pnetdev, _btmpoper_timer_hdl, pBtCoexist);
2378 _rtw_init_sema(&GLBtcBtMpRptSema, 0);
2379 GLBtcBtMpRptSeq = 0;
2380 GLBtcBtMpRptStatus = 0;
2381 _rtw_memset(GLBtcBtMpRptRsp, 0, C2H_MAX_SIZE);
2382 GLBtcBtMpRptRspSize = 0;
2383 GLBtcBtMpRptWait = 0;
2384 GLBtcBtMpRptWiFiOK = 0;
2385 GLBtcBtMpRptBTOK = 0;
2386
2387 return _TRUE;
2388 }
2389
EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)2390 void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)
2391 {
2392 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2393 return;
2394
2395 /* Power on setting function is only added in 8723B currently */
2396 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2397 if (pBtCoexist->board_info.btdm_ant_num == 2)
2398 ex_halbtc8723b2ant_power_on_setting(pBtCoexist);
2399 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2400 ex_halbtc8723b1ant_power_on_setting(pBtCoexist);
2401 }
2402
2403 if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2404 if (pBtCoexist->board_info.btdm_ant_num == 2)
2405 ex_halbtc8723d2ant_power_on_setting(pBtCoexist);
2406 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2407 ex_halbtc8723d1ant_power_on_setting(pBtCoexist);
2408 }
2409
2410 if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2411 if (pBtCoexist->board_info.btdm_ant_num == 1)
2412 ex_halbtc8822b1ant_power_on_setting(pBtCoexist);
2413 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2414 ex_halbtc8822b2ant_power_on_setting(pBtCoexist);
2415 }
2416 }
2417
EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist)2418 void EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist)
2419 {
2420 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2421 return;
2422
2423 pBtCoexist->statistics.cnt_pre_load_firmware++;
2424
2425 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2426 if (pBtCoexist->board_info.btdm_ant_num == 2)
2427 ex_halbtc8723b2ant_pre_load_firmware(pBtCoexist);
2428 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2429 ex_halbtc8723b1ant_pre_load_firmware(pBtCoexist);
2430 }
2431
2432 if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2433 if (pBtCoexist->board_info.btdm_ant_num == 2)
2434 ex_halbtc8723d2ant_pre_load_firmware(pBtCoexist);
2435 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2436 ex_halbtc8723d1ant_pre_load_firmware(pBtCoexist);
2437 }
2438 }
2439
EXhalbtcoutsrc_init_hw_config(PBTC_COEXIST pBtCoexist,u8 bWifiOnly)2440 void EXhalbtcoutsrc_init_hw_config(PBTC_COEXIST pBtCoexist, u8 bWifiOnly)
2441 {
2442 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2443 return;
2444
2445 pBtCoexist->statistics.cnt_init_hw_config++;
2446
2447 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2448 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2449 ex_halbtc8821aCsr2ant_init_hw_config(pBtCoexist, bWifiOnly);
2450 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2451 ex_halbtc8821a2ant_init_hw_config(pBtCoexist, bWifiOnly);
2452 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2453 ex_halbtc8821a1ant_init_hw_config(pBtCoexist, bWifiOnly);
2454 } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2455 if (pBtCoexist->board_info.btdm_ant_num == 2)
2456 ex_halbtc8723b2ant_init_hw_config(pBtCoexist, bWifiOnly);
2457 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2458 ex_halbtc8723b1ant_init_hw_config(pBtCoexist, bWifiOnly);
2459 } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2460 if (pBtCoexist->board_info.btdm_ant_num == 1)
2461 ex_halbtc8703b1ant_init_hw_config(pBtCoexist, bWifiOnly);
2462 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2463 if (pBtCoexist->board_info.btdm_ant_num == 2)
2464 ex_halbtc8723d2ant_init_hw_config(pBtCoexist, bWifiOnly);
2465 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2466 ex_halbtc8723d1ant_init_hw_config(pBtCoexist, bWifiOnly);
2467 } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2468 if (pBtCoexist->board_info.btdm_ant_num == 2)
2469 ex_halbtc8192e2ant_init_hw_config(pBtCoexist, bWifiOnly);
2470 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2471 ex_halbtc8192e1ant_init_hw_config(pBtCoexist, bWifiOnly);
2472 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2473 if (pBtCoexist->board_info.btdm_ant_num == 2)
2474 ex_halbtc8812a2ant_init_hw_config(pBtCoexist, bWifiOnly);
2475 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2476 ex_halbtc8812a1ant_init_hw_config(pBtCoexist, bWifiOnly);
2477 } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2478 rtw_hal_set_wifi_port_id_cmd(pBtCoexist->Adapter);
2479
2480 if (pBtCoexist->board_info.btdm_ant_num == 1)
2481 ex_halbtc8822b1ant_init_hw_config(pBtCoexist, bWifiOnly);
2482 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2483 ex_halbtc8822b2ant_init_hw_config(pBtCoexist, bWifiOnly);
2484 }
2485 }
2486
EXhalbtcoutsrc_init_coex_dm(PBTC_COEXIST pBtCoexist)2487 void EXhalbtcoutsrc_init_coex_dm(PBTC_COEXIST pBtCoexist)
2488 {
2489 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2490 return;
2491
2492 pBtCoexist->statistics.cnt_init_coex_dm++;
2493
2494 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2495 #if 0
2496 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2497 ex_halbtc8821aCsr2ant_init_coex_dm(pBtCoexist);
2498 else
2499 #endif
2500 if (pBtCoexist->board_info.btdm_ant_num == 2)
2501 ex_halbtc8821a2ant_init_coex_dm(pBtCoexist);
2502 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2503 ex_halbtc8821a1ant_init_coex_dm(pBtCoexist);
2504 } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2505 if (pBtCoexist->board_info.btdm_ant_num == 2)
2506 ex_halbtc8723b2ant_init_coex_dm(pBtCoexist);
2507 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2508 ex_halbtc8723b1ant_init_coex_dm(pBtCoexist);
2509 } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2510 if (pBtCoexist->board_info.btdm_ant_num == 1)
2511 ex_halbtc8703b1ant_init_coex_dm(pBtCoexist);
2512 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2513 if (pBtCoexist->board_info.btdm_ant_num == 2)
2514 ex_halbtc8723d2ant_init_coex_dm(pBtCoexist);
2515 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2516 ex_halbtc8723d1ant_init_coex_dm(pBtCoexist);
2517 } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2518 if (pBtCoexist->board_info.btdm_ant_num == 2)
2519 ex_halbtc8192e2ant_init_coex_dm(pBtCoexist);
2520 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2521 ex_halbtc8192e1ant_init_coex_dm(pBtCoexist);
2522 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2523 if (pBtCoexist->board_info.btdm_ant_num == 2)
2524 ex_halbtc8812a2ant_init_coex_dm(pBtCoexist);
2525 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2526 ex_halbtc8812a1ant_init_coex_dm(pBtCoexist);
2527 } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2528 if (pBtCoexist->board_info.btdm_ant_num == 1)
2529 ex_halbtc8822b1ant_init_coex_dm(pBtCoexist);
2530 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2531 ex_halbtc8822b2ant_init_coex_dm(pBtCoexist);
2532 }
2533
2534 pBtCoexist->initilized = _TRUE;
2535 }
2536
EXhalbtcoutsrc_ips_notify(PBTC_COEXIST pBtCoexist,u8 type)2537 void EXhalbtcoutsrc_ips_notify(PBTC_COEXIST pBtCoexist, u8 type)
2538 {
2539 u8 ipsType;
2540
2541 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2542 return;
2543
2544 pBtCoexist->statistics.cnt_ips_notify++;
2545 if (pBtCoexist->manual_control)
2546 return;
2547
2548 if (IPS_NONE == type) {
2549 ipsType = BTC_IPS_LEAVE;
2550 GLBtcWiFiInIPS = _FALSE;
2551 } else {
2552 ipsType = BTC_IPS_ENTER;
2553 GLBtcWiFiInIPS = _TRUE;
2554 }
2555
2556 /* All notify is called in cmd thread, don't need to leave low power again
2557 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
2558
2559 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2560 #if 0
2561 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2562 ex_halbtc8821aCsr2ant_ips_notify(pBtCoexist, ipsType);
2563 else
2564 #endif
2565 if (pBtCoexist->board_info.btdm_ant_num == 2)
2566 ex_halbtc8821a2ant_ips_notify(pBtCoexist, ipsType);
2567 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2568 ex_halbtc8821a1ant_ips_notify(pBtCoexist, ipsType);
2569 } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2570 if (pBtCoexist->board_info.btdm_ant_num == 2)
2571 ex_halbtc8723b2ant_ips_notify(pBtCoexist, ipsType);
2572 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2573 ex_halbtc8723b1ant_ips_notify(pBtCoexist, ipsType);
2574 } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2575 if (pBtCoexist->board_info.btdm_ant_num == 1)
2576 ex_halbtc8703b1ant_ips_notify(pBtCoexist, ipsType);
2577 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2578 if (pBtCoexist->board_info.btdm_ant_num == 2)
2579 ex_halbtc8723d2ant_ips_notify(pBtCoexist, ipsType);
2580 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2581 ex_halbtc8723d1ant_ips_notify(pBtCoexist, ipsType);
2582 } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2583 if (pBtCoexist->board_info.btdm_ant_num == 2)
2584 ex_halbtc8192e2ant_ips_notify(pBtCoexist, ipsType);
2585 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2586 ex_halbtc8192e1ant_ips_notify(pBtCoexist, ipsType);
2587 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2588 if (pBtCoexist->board_info.btdm_ant_num == 2)
2589 ex_halbtc8812a2ant_ips_notify(pBtCoexist, ipsType);
2590 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2591 ex_halbtc8812a1ant_ips_notify(pBtCoexist, ipsType);
2592 } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2593 if (pBtCoexist->board_info.btdm_ant_num == 1)
2594 ex_halbtc8822b1ant_ips_notify(pBtCoexist, ipsType);
2595 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2596 ex_halbtc8822b2ant_ips_notify(pBtCoexist, ipsType);
2597 }
2598
2599 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
2600 }
2601
EXhalbtcoutsrc_lps_notify(PBTC_COEXIST pBtCoexist,u8 type)2602 void EXhalbtcoutsrc_lps_notify(PBTC_COEXIST pBtCoexist, u8 type)
2603 {
2604 u8 lpsType;
2605
2606
2607 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2608 return;
2609
2610 pBtCoexist->statistics.cnt_lps_notify++;
2611 if (pBtCoexist->manual_control)
2612 return;
2613
2614 if (PS_MODE_ACTIVE == type) {
2615 lpsType = BTC_LPS_DISABLE;
2616 GLBtcWiFiInLPS = _FALSE;
2617 } else {
2618 lpsType = BTC_LPS_ENABLE;
2619 GLBtcWiFiInLPS = _TRUE;
2620 }
2621
2622 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2623 #if 0
2624 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2625 ex_halbtc8821aCsr2ant_lps_notify(pBtCoexist, lpsType);
2626 else
2627 #endif
2628 if (pBtCoexist->board_info.btdm_ant_num == 2)
2629 ex_halbtc8821a2ant_lps_notify(pBtCoexist, lpsType);
2630 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2631 ex_halbtc8821a1ant_lps_notify(pBtCoexist, lpsType);
2632 } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2633 if (pBtCoexist->board_info.btdm_ant_num == 2)
2634 ex_halbtc8723b2ant_lps_notify(pBtCoexist, lpsType);
2635 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2636 ex_halbtc8723b1ant_lps_notify(pBtCoexist, lpsType);
2637 } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2638 if (pBtCoexist->board_info.btdm_ant_num == 1)
2639 ex_halbtc8703b1ant_lps_notify(pBtCoexist, lpsType);
2640 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2641 if (pBtCoexist->board_info.btdm_ant_num == 2)
2642 ex_halbtc8723d2ant_lps_notify(pBtCoexist, lpsType);
2643 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2644 ex_halbtc8723d1ant_lps_notify(pBtCoexist, lpsType);
2645 } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2646 if (pBtCoexist->board_info.btdm_ant_num == 2)
2647 ex_halbtc8192e2ant_lps_notify(pBtCoexist, lpsType);
2648 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2649 ex_halbtc8192e1ant_lps_notify(pBtCoexist, lpsType);
2650 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2651 if (pBtCoexist->board_info.btdm_ant_num == 2)
2652 ex_halbtc8812a2ant_lps_notify(pBtCoexist, lpsType);
2653 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2654 ex_halbtc8812a1ant_lps_notify(pBtCoexist, lpsType);
2655 } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2656 if (pBtCoexist->board_info.btdm_ant_num == 1)
2657 ex_halbtc8822b1ant_lps_notify(pBtCoexist, lpsType);
2658 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2659 ex_halbtc8822b2ant_lps_notify(pBtCoexist, lpsType);
2660 }
2661 }
2662
EXhalbtcoutsrc_scan_notify(PBTC_COEXIST pBtCoexist,u8 type)2663 void EXhalbtcoutsrc_scan_notify(PBTC_COEXIST pBtCoexist, u8 type)
2664 {
2665 u8 scanType;
2666
2667 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2668 return;
2669 pBtCoexist->statistics.cnt_scan_notify++;
2670 if (pBtCoexist->manual_control)
2671 return;
2672
2673 if (type) {
2674 scanType = BTC_SCAN_START;
2675 GLBtcWiFiInScanState = _TRUE;
2676 } else {
2677 scanType = BTC_SCAN_FINISH;
2678 GLBtcWiFiInScanState = _FALSE;
2679 }
2680
2681 /* All notify is called in cmd thread, don't need to leave low power again
2682 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
2683
2684 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2685 #if 0
2686 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2687 ex_halbtc8821aCsr2ant_scan_notify(pBtCoexist, scanType);
2688 else
2689 #endif
2690 if (pBtCoexist->board_info.btdm_ant_num == 2)
2691 ex_halbtc8821a2ant_scan_notify(pBtCoexist, scanType);
2692 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2693 ex_halbtc8821a1ant_scan_notify(pBtCoexist, scanType);
2694 } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2695 if (pBtCoexist->board_info.btdm_ant_num == 2)
2696 ex_halbtc8723b2ant_scan_notify(pBtCoexist, scanType);
2697 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2698 ex_halbtc8723b1ant_scan_notify(pBtCoexist, scanType);
2699 } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2700 if (pBtCoexist->board_info.btdm_ant_num == 1)
2701 ex_halbtc8703b1ant_scan_notify(pBtCoexist, scanType);
2702 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2703 if (pBtCoexist->board_info.btdm_ant_num == 2)
2704 ex_halbtc8723d2ant_scan_notify(pBtCoexist, scanType);
2705 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2706 ex_halbtc8723d1ant_scan_notify(pBtCoexist, scanType);
2707 } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2708 if (pBtCoexist->board_info.btdm_ant_num == 2)
2709 ex_halbtc8192e2ant_scan_notify(pBtCoexist, scanType);
2710 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2711 ex_halbtc8192e1ant_scan_notify(pBtCoexist, scanType);
2712 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2713 if (pBtCoexist->board_info.btdm_ant_num == 2)
2714 ex_halbtc8812a2ant_scan_notify(pBtCoexist, scanType);
2715 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2716 ex_halbtc8812a1ant_scan_notify(pBtCoexist, scanType);
2717 } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2718 if (pBtCoexist->board_info.btdm_ant_num == 1)
2719 ex_halbtc8822b1ant_scan_notify(pBtCoexist, scanType);
2720 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2721 ex_halbtc8822b2ant_scan_notify(pBtCoexist, scanType);
2722 }
2723
2724 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
2725 }
2726
EXhalbtcoutsrc_SetAntennaPathNotify(PBTC_COEXIST pBtCoexist,u8 type)2727 void EXhalbtcoutsrc_SetAntennaPathNotify(PBTC_COEXIST pBtCoexist, u8 type)
2728 {
2729 #if 0
2730 u8 switchType;
2731
2732 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2733 return;
2734
2735 if (pBtCoexist->manual_control)
2736 return;
2737
2738 halbtcoutsrc_LeaveLowPower(pBtCoexist);
2739
2740 switchType = type;
2741
2742 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2743 if (pBtCoexist->board_info.btdm_ant_num == 1)
2744 ex_halbtc8723b1ant_set_antenna_notify(pBtCoexist, type);
2745 }
2746 if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2747 if (pBtCoexist->board_info.btdm_ant_num == 1)
2748 ex_halbtc8723d1ant_set_antenna_notify(pBtCoexist, type);
2749 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2750 ex_halbtc8723d2ant_set_antenna_notify(pBtCoexist, type);
2751 }
2752
2753 halbtcoutsrc_NormalLowPower(pBtCoexist);
2754 #endif
2755 }
2756
EXhalbtcoutsrc_connect_notify(PBTC_COEXIST pBtCoexist,u8 action)2757 void EXhalbtcoutsrc_connect_notify(PBTC_COEXIST pBtCoexist, u8 action)
2758 {
2759 u8 assoType;
2760
2761 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2762 return;
2763 pBtCoexist->statistics.cnt_connect_notify++;
2764 if (pBtCoexist->manual_control)
2765 return;
2766
2767 if (action)
2768 assoType = BTC_ASSOCIATE_START;
2769 else
2770 assoType = BTC_ASSOCIATE_FINISH;
2771
2772 /* All notify is called in cmd thread, don't need to leave low power again
2773 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
2774
2775 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2776 #if 0
2777 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2778 ex_halbtc8821aCsr2ant_connect_notify(pBtCoexist, assoType);
2779 else
2780 #endif
2781 if (pBtCoexist->board_info.btdm_ant_num == 2)
2782 ex_halbtc8821a2ant_connect_notify(pBtCoexist, assoType);
2783 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2784 ex_halbtc8821a1ant_connect_notify(pBtCoexist, assoType);
2785 } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2786 if (pBtCoexist->board_info.btdm_ant_num == 2)
2787 ex_halbtc8723b2ant_connect_notify(pBtCoexist, assoType);
2788 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2789 ex_halbtc8723b1ant_connect_notify(pBtCoexist, assoType);
2790 } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2791 if (pBtCoexist->board_info.btdm_ant_num == 1)
2792 ex_halbtc8703b1ant_connect_notify(pBtCoexist, assoType);
2793 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2794 if (pBtCoexist->board_info.btdm_ant_num == 2)
2795 ex_halbtc8723d2ant_connect_notify(pBtCoexist, assoType);
2796 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2797 ex_halbtc8723d1ant_connect_notify(pBtCoexist, assoType);
2798 } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2799 if (pBtCoexist->board_info.btdm_ant_num == 2)
2800 ex_halbtc8192e2ant_connect_notify(pBtCoexist, assoType);
2801 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2802 ex_halbtc8192e1ant_connect_notify(pBtCoexist, assoType);
2803 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2804 if (pBtCoexist->board_info.btdm_ant_num == 2)
2805 ex_halbtc8812a2ant_connect_notify(pBtCoexist, assoType);
2806 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2807 ex_halbtc8812a1ant_connect_notify(pBtCoexist, assoType);
2808 } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2809 if (pBtCoexist->board_info.btdm_ant_num == 1)
2810 ex_halbtc8822b1ant_connect_notify(pBtCoexist, assoType);
2811 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2812 ex_halbtc8822b2ant_connect_notify(pBtCoexist, assoType);
2813 }
2814
2815 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
2816 }
2817
EXhalbtcoutsrc_media_status_notify(PBTC_COEXIST pBtCoexist,RT_MEDIA_STATUS mediaStatus)2818 void EXhalbtcoutsrc_media_status_notify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus)
2819 {
2820 u8 mStatus;
2821
2822 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2823 return;
2824
2825 pBtCoexist->statistics.cnt_media_status_notify++;
2826 if (pBtCoexist->manual_control)
2827 return;
2828
2829 if (RT_MEDIA_CONNECT == mediaStatus)
2830 mStatus = BTC_MEDIA_CONNECT;
2831 else
2832 mStatus = BTC_MEDIA_DISCONNECT;
2833
2834 /* All notify is called in cmd thread, don't need to leave low power again
2835 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
2836
2837 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2838 #if 0
2839 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2840 ex_halbtc8821aCsr2ant_media_status_notify(pBtCoexist, mStatus);
2841 else
2842 #endif
2843 if (pBtCoexist->board_info.btdm_ant_num == 2)
2844 ex_halbtc8821a2ant_media_status_notify(pBtCoexist, mStatus);
2845 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2846 ex_halbtc8821a1ant_media_status_notify(pBtCoexist, mStatus);
2847 } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2848 if (pBtCoexist->board_info.btdm_ant_num == 2)
2849 ex_halbtc8723b2ant_media_status_notify(pBtCoexist, mStatus);
2850 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2851 ex_halbtc8723b1ant_media_status_notify(pBtCoexist, mStatus);
2852 } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2853 if (pBtCoexist->board_info.btdm_ant_num == 1)
2854 ex_halbtc8703b1ant_media_status_notify(pBtCoexist, mStatus);
2855 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2856 if (pBtCoexist->board_info.btdm_ant_num == 2)
2857 ex_halbtc8723d2ant_media_status_notify(pBtCoexist, mStatus);
2858 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2859 ex_halbtc8723d1ant_media_status_notify(pBtCoexist, mStatus);
2860 } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2861 if (pBtCoexist->board_info.btdm_ant_num == 2)
2862 ex_halbtc8192e2ant_media_status_notify(pBtCoexist, mStatus);
2863 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2864 ex_halbtc8192e1ant_media_status_notify(pBtCoexist, mStatus);
2865 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2866 if (pBtCoexist->board_info.btdm_ant_num == 2)
2867 ex_halbtc8812a2ant_media_status_notify(pBtCoexist, mStatus);
2868 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2869 ex_halbtc8812a1ant_media_status_notify(pBtCoexist, mStatus);
2870 } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2871 if (pBtCoexist->board_info.btdm_ant_num == 1)
2872 ex_halbtc8822b1ant_media_status_notify(pBtCoexist, mStatus);
2873 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2874 ex_halbtc8822b2ant_media_status_notify(pBtCoexist, mStatus);
2875 }
2876
2877 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
2878 }
2879
EXhalbtcoutsrc_specific_packet_notify(PBTC_COEXIST pBtCoexist,u8 pktType)2880 void EXhalbtcoutsrc_specific_packet_notify(PBTC_COEXIST pBtCoexist, u8 pktType)
2881 {
2882 u8 packetType;
2883
2884 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2885 return;
2886 pBtCoexist->statistics.cnt_specific_packet_notify++;
2887 if (pBtCoexist->manual_control)
2888 return;
2889
2890 if (PACKET_DHCP == pktType)
2891 packetType = BTC_PACKET_DHCP;
2892 else if (PACKET_EAPOL == pktType)
2893 packetType = BTC_PACKET_EAPOL;
2894 else if (PACKET_ARP == pktType)
2895 packetType = BTC_PACKET_ARP;
2896 else {
2897 packetType = BTC_PACKET_UNKNOWN;
2898 return;
2899 }
2900
2901 /* All notify is called in cmd thread, don't need to leave low power again
2902 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
2903
2904 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2905 #if 0
2906 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2907 ex_halbtc8821aCsr2ant_specific_packet_notify(pBtCoexist, packetType);
2908 else
2909 #endif
2910 if (pBtCoexist->board_info.btdm_ant_num == 2)
2911 ex_halbtc8821a2ant_specific_packet_notify(pBtCoexist, packetType);
2912 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2913 ex_halbtc8821a1ant_specific_packet_notify(pBtCoexist, packetType);
2914 } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2915 if (pBtCoexist->board_info.btdm_ant_num == 2)
2916 ex_halbtc8723b2ant_specific_packet_notify(pBtCoexist, packetType);
2917 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2918 ex_halbtc8723b1ant_specific_packet_notify(pBtCoexist, packetType);
2919 } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2920 if (pBtCoexist->board_info.btdm_ant_num == 1)
2921 ex_halbtc8703b1ant_specific_packet_notify(pBtCoexist, packetType);
2922 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2923 if (pBtCoexist->board_info.btdm_ant_num == 2)
2924 ex_halbtc8723d2ant_specific_packet_notify(pBtCoexist, packetType);
2925 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2926 ex_halbtc8723d1ant_specific_packet_notify(pBtCoexist, packetType);
2927 } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2928 if (pBtCoexist->board_info.btdm_ant_num == 2)
2929 ex_halbtc8192e2ant_specific_packet_notify(pBtCoexist, packetType);
2930 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2931 ex_halbtc8192e1ant_specific_packet_notify(pBtCoexist, packetType);
2932 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2933 if (pBtCoexist->board_info.btdm_ant_num == 2)
2934 ex_halbtc8812a2ant_specific_packet_notify(pBtCoexist, packetType);
2935 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2936 ex_halbtc8812a1ant_specific_packet_notify(pBtCoexist, packetType);
2937 } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2938 if (pBtCoexist->board_info.btdm_ant_num == 1)
2939 ex_halbtc8822b1ant_specific_packet_notify(pBtCoexist, packetType);
2940 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2941 ex_halbtc8822b2ant_specific_packet_notify(pBtCoexist, packetType);
2942 }
2943
2944 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
2945 }
2946
EXhalbtcoutsrc_bt_info_notify(PBTC_COEXIST pBtCoexist,u8 * tmpBuf,u8 length)2947 void EXhalbtcoutsrc_bt_info_notify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
2948 {
2949 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2950 return;
2951
2952 pBtCoexist->statistics.cnt_bt_info_notify++;
2953
2954 /* All notify is called in cmd thread, don't need to leave low power again
2955 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
2956
2957 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2958 #if 0
2959 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2960 ex_halbtc8821aCsr2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
2961 else
2962 #endif
2963 if (pBtCoexist->board_info.btdm_ant_num == 2)
2964 ex_halbtc8821a2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
2965 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2966 ex_halbtc8821a1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
2967 } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2968 if (pBtCoexist->board_info.btdm_ant_num == 2)
2969 ex_halbtc8723b2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
2970 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2971 ex_halbtc8723b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
2972 } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2973 if (pBtCoexist->board_info.btdm_ant_num == 1)
2974 ex_halbtc8703b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
2975 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2976 if (pBtCoexist->board_info.btdm_ant_num == 2)
2977 ex_halbtc8723d2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
2978 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2979 ex_halbtc8723d1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
2980 } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2981 if (pBtCoexist->board_info.btdm_ant_num == 2)
2982 ex_halbtc8192e2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
2983 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2984 ex_halbtc8192e1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
2985 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2986 if (pBtCoexist->board_info.btdm_ant_num == 2)
2987 ex_halbtc8812a2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
2988 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2989 ex_halbtc8812a1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
2990 } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2991 if (pBtCoexist->board_info.btdm_ant_num == 1)
2992 ex_halbtc8822b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
2993 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2994 ex_halbtc8822b2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
2995 }
2996
2997 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
2998 }
2999
3000 VOID
EXhalbtcoutsrc_RfStatusNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)3001 EXhalbtcoutsrc_RfStatusNotify(
3002 IN PBTC_COEXIST pBtCoexist,
3003 IN u1Byte type
3004 )
3005 {
3006 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3007 return;
3008 pBtCoexist->statistics.cnt_rf_status_notify++;
3009
3010 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3011 } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3012 if (pBtCoexist->board_info.btdm_ant_num == 1)
3013 ex_halbtc8723b1ant_rf_status_notify(pBtCoexist, type);
3014 } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3015 if (pBtCoexist->board_info.btdm_ant_num == 1)
3016 ex_halbtc8703b1ant_rf_status_notify(pBtCoexist, type);
3017 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3018 if (pBtCoexist->board_info.btdm_ant_num == 1)
3019 ex_halbtc8723d1ant_rf_status_notify(pBtCoexist, type);
3020 } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3021 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3022 } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3023 if (pBtCoexist->board_info.btdm_ant_num == 1)
3024 ex_halbtc8822b1ant_rf_status_notify(pBtCoexist, type);
3025 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3026 ex_halbtc8822b2ant_rf_status_notify(pBtCoexist, type);
3027 }
3028 }
3029
EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist,u8 type)3030 void EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist, u8 type)
3031 {
3032 #if 0
3033 u8 stackOpType;
3034
3035 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3036 return;
3037 pBtCoexist->statistics.cntStackOperationNotify++;
3038 if (pBtCoexist->manual_control)
3039 return;
3040
3041 if ((HCI_BT_OP_INQUIRY_START == type) ||
3042 (HCI_BT_OP_PAGING_START == type) ||
3043 (HCI_BT_OP_PAIRING_START == type))
3044 stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_START;
3045 else if ((HCI_BT_OP_INQUIRY_FINISH == type) ||
3046 (HCI_BT_OP_PAGING_SUCCESS == type) ||
3047 (HCI_BT_OP_PAGING_UNSUCCESS == type) ||
3048 (HCI_BT_OP_PAIRING_FINISH == type))
3049 stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
3050 else
3051 stackOpType = BTC_STACK_OP_NONE;
3052
3053 #endif
3054 }
3055
EXhalbtcoutsrc_halt_notify(PBTC_COEXIST pBtCoexist)3056 void EXhalbtcoutsrc_halt_notify(PBTC_COEXIST pBtCoexist)
3057 {
3058 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3059 return;
3060
3061 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3062 #if 0
3063 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3064 ex_halbtc8821aCsr2ant_halt_notify(pBtCoexist);
3065 else
3066 #endif
3067 if (pBtCoexist->board_info.btdm_ant_num == 2)
3068 ex_halbtc8821a2ant_halt_notify(pBtCoexist);
3069 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3070 ex_halbtc8821a1ant_halt_notify(pBtCoexist);
3071 } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3072 if (pBtCoexist->board_info.btdm_ant_num == 2)
3073 ex_halbtc8723b2ant_halt_notify(pBtCoexist);
3074 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3075 ex_halbtc8723b1ant_halt_notify(pBtCoexist);
3076 } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3077 if (pBtCoexist->board_info.btdm_ant_num == 1)
3078 ex_halbtc8703b1ant_halt_notify(pBtCoexist);
3079 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3080 if (pBtCoexist->board_info.btdm_ant_num == 2)
3081 ex_halbtc8723d2ant_halt_notify(pBtCoexist);
3082 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3083 ex_halbtc8723d1ant_halt_notify(pBtCoexist);
3084 } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3085 if (pBtCoexist->board_info.btdm_ant_num == 2)
3086 ex_halbtc8192e2ant_halt_notify(pBtCoexist);
3087 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3088 ex_halbtc8192e1ant_halt_notify(pBtCoexist);
3089 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3090 if (pBtCoexist->board_info.btdm_ant_num == 2)
3091 ex_halbtc8812a2ant_halt_notify(pBtCoexist);
3092 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3093 ex_halbtc8812a1ant_halt_notify(pBtCoexist);
3094 } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3095 if (pBtCoexist->board_info.btdm_ant_num == 1)
3096 ex_halbtc8822b1ant_halt_notify(pBtCoexist);
3097 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3098 ex_halbtc8822b2ant_halt_notify(pBtCoexist);
3099 }
3100 }
3101
EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist)3102 void EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist)
3103 {
3104 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3105 if (pBtCoexist->board_info.btdm_ant_num == 2) {
3106 halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x01); /* BT goto standby while GNT_BT 1-->0 */
3107 } else if (pBtCoexist->board_info.btdm_ant_num == 1) {
3108 halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x15); /* BT goto standby while GNT_BT 1-->0 */
3109 }
3110 }
3111 }
3112
EXhalbtcoutsrc_pnp_notify(PBTC_COEXIST pBtCoexist,u8 pnpState)3113 void EXhalbtcoutsrc_pnp_notify(PBTC_COEXIST pBtCoexist, u8 pnpState)
3114 {
3115 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3116 return;
3117
3118 /* */
3119 /* currently only 1ant we have to do the notification, */
3120 /* once pnp is notified to sleep state, we have to leave LPS that we can sleep normally. */
3121 /* */
3122
3123 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3124 if (pBtCoexist->board_info.btdm_ant_num == 1)
3125 ex_halbtc8723b1ant_pnp_notify(pBtCoexist, pnpState);
3126 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3127 ex_halbtc8723b2ant_pnp_notify(pBtCoexist, pnpState);
3128 } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3129 if (pBtCoexist->board_info.btdm_ant_num == 1)
3130 ex_halbtc8703b1ant_pnp_notify(pBtCoexist, pnpState);
3131 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3132 if (pBtCoexist->board_info.btdm_ant_num == 1)
3133 ex_halbtc8723d1ant_pnp_notify(pBtCoexist, pnpState);
3134 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3135 ex_halbtc8723d2ant_pnp_notify(pBtCoexist, pnpState);
3136 } else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3137 #if 0
3138 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3139 ex_halbtc8821aCsr2ant_pnp_notify(pBtCoexist, pnpState);
3140 else
3141 #endif
3142 if (pBtCoexist->board_info.btdm_ant_num == 1)
3143 ex_halbtc8821a1ant_pnp_notify(pBtCoexist, pnpState);
3144 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3145 ex_halbtc8821a2ant_pnp_notify(pBtCoexist, pnpState);
3146 } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3147 if (pBtCoexist->board_info.btdm_ant_num == 1)
3148 ex_halbtc8192e1ant_pnp_notify(pBtCoexist, pnpState);
3149 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3150 if (pBtCoexist->board_info.btdm_ant_num == 1)
3151 ex_halbtc8812a1ant_pnp_notify(pBtCoexist, pnpState);
3152 } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3153 if (pBtCoexist->board_info.btdm_ant_num == 1)
3154 ex_halbtc8822b1ant_pnp_notify(pBtCoexist, pnpState);
3155 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3156 ex_halbtc8822b2ant_pnp_notify(pBtCoexist, pnpState);
3157 }
3158 }
3159
EXhalbtcoutsrc_ScoreBoardStatusNotify(PBTC_COEXIST pBtCoexist,u8 * tmpBuf,u8 length)3160 void EXhalbtcoutsrc_ScoreBoardStatusNotify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
3161 {
3162 #if 0
3163 if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3164 if (pBtCoexist->board_info.btdm_ant_num == 1)
3165 ex_halbtc8703b1ant_ScoreBoardStatusNotify(pBtCoexist, tmpBuf, length);
3166 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3167 if (pBtCoexist->board_info.btdm_ant_num == 1)
3168 ;/*ex_halbtc8723d1ant_ScoreBoardStatusNotify(pBtCoexist, tmpBuf, length);*/
3169 }
3170 #endif
3171 }
3172
EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist)3173 void EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist)
3174 {
3175 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3176 return;
3177 pBtCoexist->statistics.cnt_coex_dm_switch++;
3178
3179 halbtcoutsrc_LeaveLowPower(pBtCoexist);
3180
3181 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3182 if (pBtCoexist->board_info.btdm_ant_num == 1) {
3183 pBtCoexist->stop_coex_dm = TRUE;
3184 ex_halbtc8723b1ant_coex_dm_reset(pBtCoexist);
3185 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);
3186 ex_halbtc8723b2ant_init_hw_config(pBtCoexist, FALSE);
3187 ex_halbtc8723b2ant_init_coex_dm(pBtCoexist);
3188 pBtCoexist->stop_coex_dm = FALSE;
3189 }
3190 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3191 if (pBtCoexist->board_info.btdm_ant_num == 1) {
3192 pBtCoexist->stop_coex_dm = TRUE;
3193 ex_halbtc8723d1ant_coex_dm_reset(pBtCoexist);
3194 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);
3195 ex_halbtc8723d2ant_init_hw_config(pBtCoexist, FALSE);
3196 ex_halbtc8723d2ant_init_coex_dm(pBtCoexist);
3197 pBtCoexist->stop_coex_dm = FALSE;
3198 }
3199 }
3200
3201 halbtcoutsrc_NormalLowPower(pBtCoexist);
3202 }
3203
EXhalbtcoutsrc_periodical(PBTC_COEXIST pBtCoexist)3204 void EXhalbtcoutsrc_periodical(PBTC_COEXIST pBtCoexist)
3205 {
3206 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3207 return;
3208 pBtCoexist->statistics.cnt_periodical++;
3209
3210 /* Periodical should be called in cmd thread, */
3211 /* don't need to leave low power again
3212 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3213
3214 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3215 #if 0
3216 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3217 ex_halbtc8821aCsr2ant_periodical(pBtCoexist);
3218 else
3219 #endif
3220 if (pBtCoexist->board_info.btdm_ant_num == 2)
3221 ex_halbtc8821a2ant_periodical(pBtCoexist);
3222 else if (pBtCoexist->board_info.btdm_ant_num == 1) {
3223 if (!halbtcoutsrc_UnderIps(pBtCoexist))
3224 ex_halbtc8821a1ant_periodical(pBtCoexist);
3225 }
3226 } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3227 if (pBtCoexist->board_info.btdm_ant_num == 2)
3228 ex_halbtc8723b2ant_periodical(pBtCoexist);
3229 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3230 ex_halbtc8723b1ant_periodical(pBtCoexist);
3231 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3232 if (pBtCoexist->board_info.btdm_ant_num == 2)
3233 ex_halbtc8723d2ant_periodical(pBtCoexist);
3234 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3235 ex_halbtc8723d1ant_periodical(pBtCoexist);
3236 } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3237 if (pBtCoexist->board_info.btdm_ant_num == 1)
3238 ex_halbtc8703b1ant_periodical(pBtCoexist);
3239 } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3240 if (pBtCoexist->board_info.btdm_ant_num == 2)
3241 ex_halbtc8192e2ant_periodical(pBtCoexist);
3242 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3243 ex_halbtc8192e1ant_periodical(pBtCoexist);
3244 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3245 if (pBtCoexist->board_info.btdm_ant_num == 2)
3246 ex_halbtc8812a2ant_periodical(pBtCoexist);
3247 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3248 ex_halbtc8812a1ant_periodical(pBtCoexist);
3249 } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3250 if (pBtCoexist->board_info.btdm_ant_num == 1)
3251 ex_halbtc8822b1ant_periodical(pBtCoexist);
3252 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3253 ex_halbtc8822b2ant_periodical(pBtCoexist);
3254 }
3255
3256 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
3257 }
3258
EXhalbtcoutsrc_dbg_control(PBTC_COEXIST pBtCoexist,u8 opCode,u8 opLen,u8 * pData)3259 void EXhalbtcoutsrc_dbg_control(PBTC_COEXIST pBtCoexist, u8 opCode, u8 opLen, u8 *pData)
3260 {
3261 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3262 return;
3263
3264 pBtCoexist->statistics.cnt_dbg_ctrl++;
3265
3266 /* This function doesn't be called yet, */
3267 /* default no need to leave low power to avoid deadlock
3268 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3269
3270 if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3271 if (pBtCoexist->board_info.btdm_ant_num == 1)
3272 ex_halbtc8192e1ant_dbg_control(pBtCoexist, opCode, opLen, pData);
3273 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3274 if (pBtCoexist->board_info.btdm_ant_num == 2)
3275 ex_halbtc8812a2ant_dbg_control(pBtCoexist, opCode, opLen, pData);
3276 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3277 ex_halbtc8812a1ant_dbg_control(pBtCoexist, opCode, opLen, pData);
3278 } else if(IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter))
3279 if(pBtCoexist->board_info.btdm_ant_num == 1)
3280 ex_halbtc8822b1ant_dbg_control(pBtCoexist, opCode, opLen, pData);
3281
3282 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
3283 }
3284
3285 #if 0
3286 VOID
3287 EXhalbtcoutsrc_AntennaDetection(
3288 IN PBTC_COEXIST pBtCoexist,
3289 IN u4Byte centFreq,
3290 IN u4Byte offset,
3291 IN u4Byte span,
3292 IN u4Byte seconds
3293 )
3294 {
3295 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3296 return;
3297
3298 /* Need to refine the following power save operations to enable this function in the future */
3299 #if 0
3300 IPSDisable(pBtCoexist->Adapter, FALSE, 0);
3301 LeisurePSLeave(pBtCoexist->Adapter, LPS_DISABLE_BT_COEX);
3302 #endif
3303
3304 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3305 if (pBtCoexist->board_info.btdm_ant_num == 1)
3306 ex_halbtc8723b1ant_AntennaDetection(pBtCoexist, centFreq, offset, span, seconds);
3307 }
3308
3309 /* IPSReturn(pBtCoexist->Adapter, 0xff); */
3310 }
3311 #endif
3312
EXhalbtcoutsrc_StackUpdateProfileInfo(void)3313 void EXhalbtcoutsrc_StackUpdateProfileInfo(void)
3314 {
3315 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
3316 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
3317 PADAPTER padapter = (PADAPTER)GLBtCoexist.Adapter;
3318 PBT_MGNT pBtMgnt = &padapter->coex_info.BtMgnt;
3319 u8 i;
3320
3321 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3322 return;
3323
3324 pBtCoexist->stack_info.profile_notified = _TRUE;
3325
3326 pBtCoexist->stack_info.num_of_link =
3327 pBtMgnt->ExtConfig.NumberOfACL + pBtMgnt->ExtConfig.NumberOfSCO;
3328
3329 /* reset first */
3330 pBtCoexist->stack_info.bt_link_exist = _FALSE;
3331 pBtCoexist->stack_info.sco_exist = _FALSE;
3332 pBtCoexist->stack_info.acl_exist = _FALSE;
3333 pBtCoexist->stack_info.a2dp_exist = _FALSE;
3334 pBtCoexist->stack_info.hid_exist = _FALSE;
3335 pBtCoexist->stack_info.num_of_hid = 0;
3336 pBtCoexist->stack_info.pan_exist = _FALSE;
3337
3338 if (!pBtMgnt->ExtConfig.NumberOfACL)
3339 pBtCoexist->stack_info.min_bt_rssi = 0;
3340
3341 if (pBtCoexist->stack_info.num_of_link) {
3342 pBtCoexist->stack_info.bt_link_exist = _TRUE;
3343 if (pBtMgnt->ExtConfig.NumberOfSCO)
3344 pBtCoexist->stack_info.sco_exist = _TRUE;
3345 if (pBtMgnt->ExtConfig.NumberOfACL)
3346 pBtCoexist->stack_info.acl_exist = _TRUE;
3347 }
3348
3349 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfACL; i++) {
3350 if (BT_PROFILE_A2DP == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
3351 pBtCoexist->stack_info.a2dp_exist = _TRUE;
3352 else if (BT_PROFILE_PAN == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
3353 pBtCoexist->stack_info.pan_exist = _TRUE;
3354 else if (BT_PROFILE_HID == pBtMgnt->ExtConfig.aclLink[i].BTProfile) {
3355 pBtCoexist->stack_info.hid_exist = _TRUE;
3356 pBtCoexist->stack_info.num_of_hid++;
3357 } else
3358 pBtCoexist->stack_info.unknown_acl_exist = _TRUE;
3359 }
3360 #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
3361 }
3362
EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi)3363 void EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi)
3364 {
3365 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
3366
3367 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3368 return;
3369
3370 pBtCoexist->stack_info.min_bt_rssi = btRssi;
3371 }
3372
EXhalbtcoutsrc_SetHciVersion(u16 hciVersion)3373 void EXhalbtcoutsrc_SetHciVersion(u16 hciVersion)
3374 {
3375 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
3376
3377 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3378 return;
3379
3380 pBtCoexist->stack_info.hci_version = hciVersion;
3381 }
3382
EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion,u16 btPatchVersion)3383 void EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion, u16 btPatchVersion)
3384 {
3385 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
3386
3387 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3388 return;
3389
3390 pBtCoexist->bt_info.bt_real_fw_ver = btPatchVersion;
3391 pBtCoexist->bt_info.bt_hci_ver = btHciVersion;
3392 }
3393
3394 #if 0
3395 void EXhalbtcoutsrc_SetBtExist(u8 bBtExist)
3396 {
3397 GLBtCoexist.boardInfo.bBtExist = bBtExist;
3398 }
3399 #endif
EXhalbtcoutsrc_SetChipType(u8 chipType)3400 void EXhalbtcoutsrc_SetChipType(u8 chipType)
3401 {
3402 switch (chipType) {
3403 default:
3404 case BT_2WIRE:
3405 case BT_ISSC_3WIRE:
3406 case BT_ACCEL:
3407 case BT_RTL8756:
3408 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_UNDEF;
3409 break;
3410 case BT_CSR_BC4:
3411 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
3412 break;
3413 case BT_CSR_BC8:
3414 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
3415 break;
3416 case BT_RTL8723A:
3417 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A;
3418 break;
3419 case BT_RTL8821:
3420 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8821;
3421 break;
3422 case BT_RTL8723B:
3423 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B;
3424 break;
3425 }
3426 }
3427
EXhalbtcoutsrc_SetAntNum(u8 type,u8 antNum)3428 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
3429 {
3430 if (BT_COEX_ANT_TYPE_PG == type) {
3431 GLBtCoexist.board_info.pg_ant_num = antNum;
3432 GLBtCoexist.board_info.btdm_ant_num = antNum;
3433 #if 0
3434 /* The antenna position: Main (default) or Aux for pgAntNum=2 && btdmAntNum =1 */
3435 /* The antenna position should be determined by auto-detect mechanism */
3436 /* The following is assumed to main, and those must be modified if y auto-detect mechanism is ready */
3437 if ((GLBtCoexist.board_info.pg_ant_num == 2) && (GLBtCoexist.board_info.btdm_ant_num == 1))
3438 GLBtCoexist.board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
3439 else
3440 GLBtCoexist.board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
3441 #endif
3442 } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
3443 GLBtCoexist.board_info.btdm_ant_num = antNum;
3444 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
3445 } else if (BT_COEX_ANT_TYPE_DETECTED == type) {
3446 GLBtCoexist.board_info.btdm_ant_num = antNum;
3447 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
3448 }
3449 }
3450
3451 /*
3452 * Currently used by 8723b only, S0 or S1
3453 * */
EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)3454 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
3455 {
3456 GLBtCoexist.board_info.single_ant_path = singleAntPath;
3457 }
3458
EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)3459 void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)
3460 {
3461 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3462 return;
3463
3464 halbtcoutsrc_LeaveLowPower(pBtCoexist);
3465
3466 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3467 #if 0
3468 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3469 ex_halbtc8821aCsr2ant_display_coex_info(pBtCoexist);
3470 else
3471 #endif
3472 if (pBtCoexist->board_info.btdm_ant_num == 2)
3473 ex_halbtc8821a2ant_display_coex_info(pBtCoexist);
3474 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3475 ex_halbtc8821a1ant_display_coex_info(pBtCoexist);
3476 } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3477 if (pBtCoexist->board_info.btdm_ant_num == 2)
3478 ex_halbtc8723b2ant_display_coex_info(pBtCoexist);
3479 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3480 ex_halbtc8723b1ant_display_coex_info(pBtCoexist);
3481 } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3482 if (pBtCoexist->board_info.btdm_ant_num == 1)
3483 ex_halbtc8703b1ant_display_coex_info(pBtCoexist);
3484 } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3485 if (pBtCoexist->board_info.btdm_ant_num == 2)
3486 ex_halbtc8723d2ant_display_coex_info(pBtCoexist);
3487 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3488 ex_halbtc8723d1ant_display_coex_info(pBtCoexist);
3489 } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3490 if (pBtCoexist->board_info.btdm_ant_num == 2)
3491 ex_halbtc8192e2ant_display_coex_info(pBtCoexist);
3492 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3493 ex_halbtc8192e1ant_display_coex_info(pBtCoexist);
3494 } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3495 if (pBtCoexist->board_info.btdm_ant_num == 2)
3496 ex_halbtc8812a2ant_display_coex_info(pBtCoexist);
3497 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3498 ex_halbtc8812a1ant_display_coex_info(pBtCoexist);
3499 } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3500 if (pBtCoexist->board_info.btdm_ant_num == 1)
3501 ex_halbtc8822b1ant_display_coex_info(pBtCoexist);
3502 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3503 ex_halbtc8822b2ant_display_coex_info(pBtCoexist);
3504 }
3505
3506 halbtcoutsrc_NormalLowPower(pBtCoexist);
3507 }
3508
EXhalbtcoutsrc_DisplayAntDetection(PBTC_COEXIST pBtCoexist)3509 void EXhalbtcoutsrc_DisplayAntDetection(PBTC_COEXIST pBtCoexist)
3510 {
3511 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3512 return;
3513
3514 halbtcoutsrc_LeaveLowPower(pBtCoexist);
3515
3516 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3517 if (pBtCoexist->board_info.btdm_ant_num == 1)
3518 ex_halbtc8723b1ant_display_ant_detection(pBtCoexist);
3519 }
3520
3521 halbtcoutsrc_NormalLowPower(pBtCoexist);
3522 }
3523
EXhalbtcoutsrc_BTOffOnNotify(PBTC_COEXIST pBtCoexist,u8 bBTON)3524 void EXhalbtcoutsrc_BTOffOnNotify(PBTC_COEXIST pBtCoexist, u8 bBTON)
3525 {
3526 #if 0 /* Jenyu Need commit to windows' SVN */
3527 if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3528 if (pBtCoexist->board_info.btdm_ant_num == 2)
3529 ex_halbtc8812a2ant_bt_off_on_notify(pBtCoexist, (bBTON == _TRUE) ? BTC_BT_ON : BTC_BT_OFF);
3530 }
3531 #endif
3532 }
3533
EXhalbtcoutsrc_set_rfe_type(u8 type)3534 void EXhalbtcoutsrc_set_rfe_type(u8 type)
3535 {
3536 GLBtCoexist.board_info.rfe_type= type;
3537 }
3538
3539 #ifdef CONFIG_RF4CE_COEXIST
EXhalbtcoutsrc_set_rf4ce_link_state(u8 state)3540 void EXhalbtcoutsrc_set_rf4ce_link_state(u8 state)
3541 {
3542 GLBtCoexist.rf4ce_info.link_state = state;
3543 }
3544
EXhalbtcoutsrc_get_rf4ce_link_state(void)3545 u8 EXhalbtcoutsrc_get_rf4ce_link_state(void)
3546 {
3547 return GLBtCoexist.rf4ce_info.link_state;
3548 }
3549
EXhalbtcoutsrc_set_rf4ce_voice_state(u8 state)3550 void EXhalbtcoutsrc_set_rf4ce_voice_state(u8 state)
3551 {
3552 GLBtCoexist.rf4ce_info.voice_state = state;
3553 }
3554
EXhalbtcoutsrc_get_rf4ce_voice_state(void)3555 u8 EXhalbtcoutsrc_get_rf4ce_voice_state(void)
3556 {
3557 return GLBtCoexist.rf4ce_info.voice_state;
3558 }
3559 #endif
3560
EXhalbtcoutsrc_switchband_notify(struct btc_coexist * pBtCoexist,u8 type)3561 void EXhalbtcoutsrc_switchband_notify(struct btc_coexist *pBtCoexist, u8 type)
3562 {
3563 if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3564 return;
3565
3566 if(pBtCoexist->manual_control)
3567 return;
3568
3569
3570 halbtcoutsrc_LeaveLowPower(pBtCoexist);
3571
3572 if(IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3573 if(pBtCoexist->board_info.btdm_ant_num == 1)
3574 ex_halbtc8822b1ant_switchband_notify(pBtCoexist, type);
3575 else if(pBtCoexist->board_info.btdm_ant_num == 2)
3576 ex_halbtc8822b2ant_switchband_notify(pBtCoexist, type);
3577 }
3578
3579 halbtcoutsrc_NormalLowPower(pBtCoexist);
3580 }
3581
halbt_init_hw_config92C(PADAPTER padapter)3582 static void halbt_init_hw_config92C(PADAPTER padapter)
3583 {
3584 PHAL_DATA_TYPE pHalData;
3585 u8 u1Tmp;
3586
3587
3588 pHalData = GET_HAL_DATA(padapter);
3589 if ((pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
3590 (pHalData->bt_coexist.btChipType == BT_CSR_BC8)) {
3591 if (pHalData->rf_type == RF_1T1R) {
3592 /* Config to 1T1R */
3593 u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
3594 u1Tmp &= ~BIT(1);
3595 rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
3596 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
3597
3598 u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
3599 u1Tmp &= ~BIT(1);
3600 rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
3601 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
3602 }
3603 }
3604 }
3605
halbt_init_hw_config92D(PADAPTER padapter)3606 static void halbt_init_hw_config92D(PADAPTER padapter)
3607 {
3608 PHAL_DATA_TYPE pHalData;
3609 u8 u1Tmp;
3610
3611 pHalData = GET_HAL_DATA(padapter);
3612 if ((pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
3613 (pHalData->bt_coexist.btChipType == BT_CSR_BC8)) {
3614 if (pHalData->rf_type == RF_1T1R) {
3615 /* Config to 1T1R */
3616 u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
3617 u1Tmp &= ~BIT(1);
3618 rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
3619 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
3620
3621 u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
3622 u1Tmp &= ~BIT(1);
3623 rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
3624 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
3625 }
3626 }
3627 }
3628
3629 /*
3630 * Description:
3631 * Run BT-Coexist mechansim or not
3632 *
3633 */
hal_btcoex_SetBTCoexist(PADAPTER padapter,u8 bBtExist)3634 void hal_btcoex_SetBTCoexist(PADAPTER padapter, u8 bBtExist)
3635 {
3636 PHAL_DATA_TYPE pHalData;
3637
3638
3639 pHalData = GET_HAL_DATA(padapter);
3640 pHalData->bt_coexist.bBtExist = bBtExist;
3641 }
3642
3643 /*
3644 * Dewcription:
3645 * Check is co-exist mechanism enabled or not
3646 *
3647 * Return:
3648 * _TRUE Enable BT co-exist mechanism
3649 * _FALSE Disable BT co-exist mechanism
3650 */
hal_btcoex_IsBtExist(PADAPTER padapter)3651 u8 hal_btcoex_IsBtExist(PADAPTER padapter)
3652 {
3653 PHAL_DATA_TYPE pHalData;
3654
3655
3656 pHalData = GET_HAL_DATA(padapter);
3657 return pHalData->bt_coexist.bBtExist;
3658 }
3659
hal_btcoex_IsBtDisabled(PADAPTER padapter)3660 u8 hal_btcoex_IsBtDisabled(PADAPTER padapter)
3661 {
3662 if (!hal_btcoex_IsBtExist(padapter))
3663 return _TRUE;
3664
3665 if (GLBtCoexist.bt_info.bt_disabled)
3666 return _TRUE;
3667 else
3668 return _FALSE;
3669 }
3670
hal_btcoex_SetChipType(PADAPTER padapter,u8 chipType)3671 void hal_btcoex_SetChipType(PADAPTER padapter, u8 chipType)
3672 {
3673 PHAL_DATA_TYPE pHalData;
3674
3675 pHalData = GET_HAL_DATA(padapter);
3676 pHalData->bt_coexist.btChipType = chipType;
3677 }
3678
hal_btcoex_SetPgAntNum(PADAPTER padapter,u8 antNum)3679 void hal_btcoex_SetPgAntNum(PADAPTER padapter, u8 antNum)
3680 {
3681 PHAL_DATA_TYPE pHalData;
3682
3683 pHalData = GET_HAL_DATA(padapter);
3684
3685 pHalData->bt_coexist.btTotalAntNum = antNum;
3686 }
3687
hal_btcoex_Initialize(PADAPTER padapter)3688 u8 hal_btcoex_Initialize(PADAPTER padapter)
3689 {
3690 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
3691 u8 ret;
3692
3693 _rtw_memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
3694
3695 hal_btcoex_SetBTCoexist(padapter, rtw_btcoex_get_bt_coexist(padapter));
3696 hal_btcoex_SetChipType(padapter, rtw_btcoex_get_chip_type(padapter));
3697 hal_btcoex_SetPgAntNum(padapter, rtw_btcoex_get_pg_ant_num(padapter));
3698
3699 ret = EXhalbtcoutsrc_InitlizeVariables((void *)padapter);
3700
3701 return ret;
3702 }
3703
hal_btcoex_PowerOnSetting(PADAPTER padapter)3704 void hal_btcoex_PowerOnSetting(PADAPTER padapter)
3705 {
3706 EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
3707 }
3708
hal_btcoex_PreLoadFirmware(PADAPTER padapter)3709 void hal_btcoex_PreLoadFirmware(PADAPTER padapter)
3710 {
3711 EXhalbtcoutsrc_PreLoadFirmware(&GLBtCoexist);
3712 }
3713
hal_btcoex_InitHwConfig(PADAPTER padapter,u8 bWifiOnly)3714 void hal_btcoex_InitHwConfig(PADAPTER padapter, u8 bWifiOnly)
3715 {
3716 if (!hal_btcoex_IsBtExist(padapter))
3717 return;
3718
3719 EXhalbtcoutsrc_init_hw_config(&GLBtCoexist, bWifiOnly);
3720 EXhalbtcoutsrc_init_coex_dm(&GLBtCoexist);
3721 }
3722
hal_btcoex_IpsNotify(PADAPTER padapter,u8 type)3723 void hal_btcoex_IpsNotify(PADAPTER padapter, u8 type)
3724 {
3725 EXhalbtcoutsrc_ips_notify(&GLBtCoexist, type);
3726 }
3727
hal_btcoex_LpsNotify(PADAPTER padapter,u8 type)3728 void hal_btcoex_LpsNotify(PADAPTER padapter, u8 type)
3729 {
3730 EXhalbtcoutsrc_lps_notify(&GLBtCoexist, type);
3731 }
3732
hal_btcoex_ScanNotify(PADAPTER padapter,u8 type)3733 void hal_btcoex_ScanNotify(PADAPTER padapter, u8 type)
3734 {
3735 EXhalbtcoutsrc_scan_notify(&GLBtCoexist, type);
3736 }
3737
hal_btcoex_ConnectNotify(PADAPTER padapter,u8 action)3738 void hal_btcoex_ConnectNotify(PADAPTER padapter, u8 action)
3739 {
3740 EXhalbtcoutsrc_connect_notify(&GLBtCoexist, action);
3741 }
3742
hal_btcoex_MediaStatusNotify(PADAPTER padapter,u8 mediaStatus)3743 void hal_btcoex_MediaStatusNotify(PADAPTER padapter, u8 mediaStatus)
3744 {
3745 EXhalbtcoutsrc_media_status_notify(&GLBtCoexist, mediaStatus);
3746 }
3747
hal_btcoex_SpecialPacketNotify(PADAPTER padapter,u8 pktType)3748 void hal_btcoex_SpecialPacketNotify(PADAPTER padapter, u8 pktType)
3749 {
3750 EXhalbtcoutsrc_specific_packet_notify(&GLBtCoexist, pktType);
3751 }
3752
hal_btcoex_IQKNotify(PADAPTER padapter,u8 state)3753 void hal_btcoex_IQKNotify(PADAPTER padapter, u8 state)
3754 {
3755 GLBtcWiFiInIQKState = state;
3756 }
3757
hal_btcoex_BtInfoNotify(PADAPTER padapter,u8 length,u8 * tmpBuf)3758 void hal_btcoex_BtInfoNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
3759 {
3760 if (GLBtcWiFiInIQKState == _TRUE)
3761 return;
3762
3763 EXhalbtcoutsrc_bt_info_notify(&GLBtCoexist, tmpBuf, length);
3764 }
3765
hal_btcoex_BtMpRptNotify(PADAPTER padapter,u8 length,u8 * tmpBuf)3766 void hal_btcoex_BtMpRptNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
3767 {
3768 u8 extid, status, len, seq;
3769
3770
3771 if (!GLBtcBtMpRptWait)
3772 return;
3773
3774 if ((length < 3) || (!tmpBuf))
3775 return;
3776
3777 extid = tmpBuf[0];
3778 /* not response from BT FW then exit*/
3779 switch (extid) {
3780 case C2H_WIFI_FW_ACTIVE_RSP:
3781 GLBtcBtMpRptWiFiOK = 1;
3782 return;
3783
3784 case C2H_TRIG_BY_BT_FW:
3785 _cancel_timer_ex(&GLBtcBtMpOperTimer);
3786 GLBtcBtMpRptWait = 0;
3787 GLBtcBtMpRptBTOK = 1;
3788 break;
3789
3790 default:
3791 return;
3792 }
3793
3794 status = tmpBuf[1] & 0xF;
3795 len = length - 3;
3796 seq = tmpBuf[2] >> 4;
3797
3798 GLBtcBtMpRptSeq = seq;
3799 GLBtcBtMpRptStatus = status;
3800 _rtw_memcpy(GLBtcBtMpRptRsp, tmpBuf + 3, len);
3801 GLBtcBtMpRptRspSize = len;
3802 _rtw_up_sema(&GLBtcBtMpRptSema);
3803 }
3804
hal_btcoex_SuspendNotify(PADAPTER padapter,u8 state)3805 void hal_btcoex_SuspendNotify(PADAPTER padapter, u8 state)
3806 {
3807 switch (state) {
3808 case BTCOEX_SUSPEND_STATE_SUSPEND:
3809 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP);
3810 break;
3811 case BTCOEX_SUSPEND_STATE_SUSPEND_KEEP_ANT:
3812 /* should switch to "#if 1" once all ICs' coex. revision are upgraded to support the KEEP_ANT case */
3813 #if 0
3814 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP_KEEP_ANT);
3815 #else
3816 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP);
3817 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP_KEEP_ANT);
3818 #endif
3819 break;
3820 case BTCOEX_SUSPEND_STATE_RESUME:
3821 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_WAKE_UP);
3822 break;
3823 }
3824 }
3825
hal_btcoex_HaltNotify(PADAPTER padapter,u8 do_halt)3826 void hal_btcoex_HaltNotify(PADAPTER padapter, u8 do_halt)
3827 {
3828 if (do_halt == 1)
3829 EXhalbtcoutsrc_halt_notify(&GLBtCoexist);
3830
3831 GLBtCoexist.bBinded = _FALSE;
3832 GLBtCoexist.Adapter = NULL;
3833 }
3834
hal_btcoex_ScoreBoardStatusNotify(PADAPTER padapter,u8 length,u8 * tmpBuf)3835 void hal_btcoex_ScoreBoardStatusNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
3836 {
3837 EXhalbtcoutsrc_ScoreBoardStatusNotify(&GLBtCoexist, tmpBuf, length);
3838 }
3839
hal_btcoex_SwitchBtTRxMask(PADAPTER padapter)3840 void hal_btcoex_SwitchBtTRxMask(PADAPTER padapter)
3841 {
3842 EXhalbtcoutsrc_SwitchBtTRxMask(&GLBtCoexist);
3843 }
3844
hal_btcoex_Hanlder(PADAPTER padapter)3845 void hal_btcoex_Hanlder(PADAPTER padapter)
3846 {
3847 u32 bt_patch_ver;
3848
3849 EXhalbtcoutsrc_periodical(&GLBtCoexist);
3850
3851 if (GLBtCoexist.bt_info.bt_get_fw_ver == 0) {
3852 GLBtCoexist.btc_get(&GLBtCoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
3853 GLBtCoexist.bt_info.bt_get_fw_ver = bt_patch_ver;
3854 }
3855 }
3856
hal_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter)3857 s32 hal_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter)
3858 {
3859 return (s32)GLBtCoexist.bt_info.reject_agg_pkt;
3860 }
3861
hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)3862 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)
3863 {
3864 return (s32)GLBtCoexist.bt_info.bt_ctrl_agg_buf_size;
3865 }
3866
hal_btcoex_GetAMPDUSize(PADAPTER padapter)3867 u32 hal_btcoex_GetAMPDUSize(PADAPTER padapter)
3868 {
3869 return (u32)GLBtCoexist.bt_info.agg_buf_size;
3870 }
3871
hal_btcoex_SetManualControl(PADAPTER padapter,u8 bmanual)3872 void hal_btcoex_SetManualControl(PADAPTER padapter, u8 bmanual)
3873 {
3874 GLBtCoexist.manual_control = bmanual;
3875 }
3876
hal_btcoex_1Ant(PADAPTER padapter)3877 u8 hal_btcoex_1Ant(PADAPTER padapter)
3878 {
3879 if (hal_btcoex_IsBtExist(padapter) == _FALSE)
3880 return _FALSE;
3881
3882 if (GLBtCoexist.board_info.btdm_ant_num == 1)
3883 return _TRUE;
3884
3885 return _FALSE;
3886 }
3887
hal_btcoex_IsBtControlLps(PADAPTER padapter)3888 u8 hal_btcoex_IsBtControlLps(PADAPTER padapter)
3889 {
3890 if (GLBtCoexist.bdontenterLPS == _TRUE)
3891 return _TRUE;
3892
3893 if (hal_btcoex_IsBtExist(padapter) == _FALSE)
3894 return _FALSE;
3895
3896 if (GLBtCoexist.bt_info.bt_disabled)
3897 return _FALSE;
3898
3899 if (GLBtCoexist.bt_info.bt_ctrl_lps)
3900 return _TRUE;
3901
3902 return _FALSE;
3903 }
3904
hal_btcoex_IsLpsOn(PADAPTER padapter)3905 u8 hal_btcoex_IsLpsOn(PADAPTER padapter)
3906 {
3907 if (GLBtCoexist.bdontenterLPS == _TRUE)
3908 return _FALSE;
3909
3910 if (hal_btcoex_IsBtExist(padapter) == _FALSE)
3911 return _FALSE;
3912
3913 if (GLBtCoexist.bt_info.bt_disabled)
3914 return _FALSE;
3915
3916 if (GLBtCoexist.bt_info.bt_lps_on)
3917 return _TRUE;
3918
3919 return _FALSE;
3920 }
3921
hal_btcoex_RpwmVal(PADAPTER padapter)3922 u8 hal_btcoex_RpwmVal(PADAPTER padapter)
3923 {
3924 return GLBtCoexist.bt_info.rpwm_val;
3925 }
3926
hal_btcoex_LpsVal(PADAPTER padapter)3927 u8 hal_btcoex_LpsVal(PADAPTER padapter)
3928 {
3929 return GLBtCoexist.bt_info.lps_val;
3930 }
3931
hal_btcoex_GetRaMask(PADAPTER padapter)3932 u32 hal_btcoex_GetRaMask(PADAPTER padapter)
3933 {
3934 if (!hal_btcoex_IsBtExist(padapter))
3935 return 0;
3936
3937 if (GLBtCoexist.bt_info.bt_disabled)
3938 return 0;
3939
3940 /* Modify by YiWei , suggest by Cosa and Jenyu
3941 * Remove the limit antenna number , because 2 antenna case (ex: 8192eu)also want to get BT coex report rate mask.
3942 */
3943 /*if (GLBtCoexist.board_info.btdm_ant_num != 1)
3944 return 0;*/
3945
3946 return GLBtCoexist.bt_info.ra_mask;
3947 }
3948
hal_btcoex_RecordPwrMode(PADAPTER padapter,u8 * pCmdBuf,u8 cmdLen)3949 void hal_btcoex_RecordPwrMode(PADAPTER padapter, u8 *pCmdBuf, u8 cmdLen)
3950 {
3951
3952 _rtw_memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
3953 }
3954
hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter,u8 * pbuf,u32 bufsize)3955 void hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter, u8 *pbuf, u32 bufsize)
3956 {
3957 PBTCDBGINFO pinfo;
3958
3959
3960 pinfo = &GLBtcDbgInfo;
3961 DBG_BT_INFO_INIT(pinfo, pbuf, bufsize);
3962 EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist);
3963 DBG_BT_INFO_INIT(pinfo, NULL, 0);
3964 }
3965
hal_btcoex_SetDBG(PADAPTER padapter,u32 * pDbgModule)3966 void hal_btcoex_SetDBG(PADAPTER padapter, u32 *pDbgModule)
3967 {
3968 u32 i;
3969
3970
3971 if (NULL == pDbgModule)
3972 return;
3973
3974 for (i = 0; i < COMP_MAX; i++)
3975 GLBtcDbgType[i] = pDbgModule[i];
3976 }
3977
hal_btcoex_GetDBG(PADAPTER padapter,u8 * pStrBuf,u32 bufSize)3978 u32 hal_btcoex_GetDBG(PADAPTER padapter, u8 *pStrBuf, u32 bufSize)
3979 {
3980 s32 count;
3981 u8 *pstr;
3982 u32 leftSize;
3983
3984
3985 if ((NULL == pStrBuf) || (0 == bufSize))
3986 return 0;
3987
3988 count = 0;
3989 pstr = pStrBuf;
3990 leftSize = bufSize;
3991 /* RTW_INFO(FUNC_ADPT_FMT ": bufsize=%d\n", FUNC_ADPT_ARG(padapter), bufSize); */
3992
3993 count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG);
3994 if ((count < 0) || (count >= leftSize))
3995 goto exit;
3996 pstr += count;
3997 leftSize -= count;
3998
3999 count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n");
4000 if ((count < 0) || (count >= leftSize))
4001 goto exit;
4002 pstr += count;
4003 leftSize -= count;
4004
4005 count = rtw_sprintf(pstr, leftSize,
4006 "COMP_COEX: 0x%08X\n\n",
4007 GLBtcDbgType[COMP_COEX]);
4008 if ((count < 0) || (count >= leftSize))
4009 goto exit;
4010 pstr += count;
4011 leftSize -= count;
4012
4013 #if 0
4014 count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n");
4015 if ((count < 0) || (count >= leftSize))
4016 goto exit;
4017 pstr += count;
4018 leftSize -= count;
4019 count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for INTF_INIT\n",
4020 GLBtcDbgType[BTC_MSG_INTERFACE] & INTF_INIT ? 1 : 0);
4021 if ((count < 0) || (count >= leftSize))
4022 goto exit;
4023 pstr += count;
4024 leftSize -= count;
4025 count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for INTF_NOTIFY\n\n",
4026 GLBtcDbgType[BTC_MSG_INTERFACE] & INTF_NOTIFY ? 1 : 0);
4027 if ((count < 0) || (count >= leftSize))
4028 goto exit;
4029 pstr += count;
4030 leftSize -= count;
4031
4032 count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n");
4033 if ((count < 0) || (count >= leftSize))
4034 goto exit;
4035 pstr += count;
4036 leftSize -= count;
4037 count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for BT_RSSI_STATE\n",
4038 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_BT_RSSI_STATE ? 1 : 0);
4039 if ((count < 0) || (count >= leftSize))
4040 goto exit;
4041 pstr += count;
4042 leftSize -= count;
4043 count = rtw_sprintf(pstr, leftSize, "\tbit[1]=%d for WIFI_RSSI_STATE\n",
4044 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_WIFI_RSSI_STATE ? 1 : 0);
4045 if ((count < 0) || (count >= leftSize))
4046 goto exit;
4047 pstr += count;
4048 leftSize -= count;
4049 count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for BT_MONITOR\n",
4050 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_BT_MONITOR ? 1 : 0);
4051 if ((count < 0) || (count >= leftSize))
4052 goto exit;
4053 pstr += count;
4054 leftSize -= count;
4055 count = rtw_sprintf(pstr, leftSize, "\tbit[3]=%d for TRACE\n",
4056 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE ? 1 : 0);
4057 if ((count < 0) || (count >= leftSize))
4058 goto exit;
4059 pstr += count;
4060 leftSize -= count;
4061 count = rtw_sprintf(pstr, leftSize, "\tbit[4]=%d for TRACE_FW\n",
4062 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW ? 1 : 0);
4063 if ((count < 0) || (count >= leftSize))
4064 goto exit;
4065 pstr += count;
4066 leftSize -= count;
4067 count = rtw_sprintf(pstr, leftSize, "\tbit[5]=%d for TRACE_FW_DETAIL\n",
4068 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW_DETAIL ? 1 : 0);
4069 if ((count < 0) || (count >= leftSize))
4070 goto exit;
4071 pstr += count;
4072 leftSize -= count;
4073 count = rtw_sprintf(pstr, leftSize, "\tbit[6]=%d for TRACE_FW_EXEC\n",
4074 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW_EXEC ? 1 : 0);
4075 if ((count < 0) || (count >= leftSize))
4076 goto exit;
4077 pstr += count;
4078 leftSize -= count;
4079 count = rtw_sprintf(pstr, leftSize, "\tbit[7]=%d for TRACE_SW\n",
4080 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW ? 1 : 0);
4081 if ((count < 0) || (count >= leftSize))
4082 goto exit;
4083 pstr += count;
4084 leftSize -= count;
4085 count = rtw_sprintf(pstr, leftSize, "\tbit[8]=%d for TRACE_SW_DETAIL\n",
4086 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW_DETAIL ? 1 : 0);
4087 if ((count < 0) || (count >= leftSize))
4088 goto exit;
4089 pstr += count;
4090 leftSize -= count;
4091 count = rtw_sprintf(pstr, leftSize, "\tbit[9]=%d for TRACE_SW_EXEC\n",
4092 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW_EXEC ? 1 : 0);
4093 if ((count < 0) || (count >= leftSize))
4094 goto exit;
4095 pstr += count;
4096 leftSize -= count;
4097 #endif
4098
4099 exit:
4100 count = pstr - pStrBuf;
4101 /* RTW_INFO(FUNC_ADPT_FMT ": usedsize=%d\n", FUNC_ADPT_ARG(padapter), count); */
4102
4103 return count;
4104 }
4105
hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)4106 u8 hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)
4107 {
4108 if (!hal_btcoex_IsBtExist(padapter))
4109 return _FALSE;
4110
4111 if (GLBtCoexist.bt_info.increase_scan_dev_num)
4112 return _TRUE;
4113
4114 return _FALSE;
4115 }
4116
hal_btcoex_IsBtLinkExist(PADAPTER padapter)4117 u8 hal_btcoex_IsBtLinkExist(PADAPTER padapter)
4118 {
4119 if (GLBtCoexist.bt_link_info.bt_link_exist)
4120 return _TRUE;
4121
4122 return _FALSE;
4123 }
4124
hal_btcoex_SetBtPatchVersion(PADAPTER padapter,u16 btHciVer,u16 btPatchVer)4125 void hal_btcoex_SetBtPatchVersion(PADAPTER padapter, u16 btHciVer, u16 btPatchVer)
4126 {
4127 EXhalbtcoutsrc_SetBtPatchVersion(btHciVer, btPatchVer);
4128 }
4129
hal_btcoex_SetHciVersion(PADAPTER padapter,u16 hciVersion)4130 void hal_btcoex_SetHciVersion(PADAPTER padapter, u16 hciVersion)
4131 {
4132 EXhalbtcoutsrc_SetHciVersion(hciVersion);
4133 }
4134
hal_btcoex_StackUpdateProfileInfo(void)4135 void hal_btcoex_StackUpdateProfileInfo(void)
4136 {
4137 EXhalbtcoutsrc_StackUpdateProfileInfo();
4138 }
4139
hal_btcoex_BTOffOnNotify(PADAPTER padapter,u8 bBTON)4140 void hal_btcoex_BTOffOnNotify(PADAPTER padapter, u8 bBTON)
4141 {
4142 EXhalbtcoutsrc_BTOffOnNotify(&GLBtCoexist, bBTON);
4143 }
4144
4145 /*
4146 * Description:
4147 * Setting BT coex antenna isolation type .
4148 * coex mechanisn/ spital stream/ best throughput
4149 * anttype = 0 , PSTDMA / 2SS / 0.5T , bad isolation , WiFi/BT ANT Distance<15cm , (<20dB) for 2,3 antenna
4150 * anttype = 1 , PSTDMA / 1SS / 0.5T , normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 2 antenna
4151 * anttype = 2 , TDMA / 2SS / T , normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 3 antenna
4152 * anttype = 3 , no TDMA / 1SS / 0.5T , good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 2 antenna
4153 * anttype = 4 , no TDMA / 2SS / T , good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 3 antenna
4154 * wifi only throughput ~ T
4155 * wifi/BT share one antenna with SPDT
4156 */
hal_btcoex_SetAntIsolationType(PADAPTER padapter,u8 anttype)4157 void hal_btcoex_SetAntIsolationType(PADAPTER padapter, u8 anttype)
4158 {
4159 PHAL_DATA_TYPE pHalData;
4160 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
4161
4162 /*RTW_INFO("####%s , anttype = %d , %d\n" , __func__ , anttype , __LINE__); */
4163 pHalData = GET_HAL_DATA(padapter);
4164
4165
4166 pHalData->bt_coexist.btAntisolation = anttype;
4167
4168 switch (pHalData->bt_coexist.btAntisolation) {
4169 case 0:
4170 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_0;
4171 break;
4172 case 1:
4173 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_1;
4174 break;
4175 case 2:
4176 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_2;
4177 break;
4178 case 3:
4179 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_3;
4180 break;
4181 case 4:
4182 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_4;
4183 break;
4184 }
4185
4186 }
4187
4188 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
4189 int
hal_btcoex_ParseAntIsolationConfigFile(PADAPTER Adapter,char * buffer)4190 hal_btcoex_ParseAntIsolationConfigFile(
4191 PADAPTER Adapter,
4192 char *buffer
4193 )
4194 {
4195 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
4196 u32 i = 0 , j = 0;
4197 char *szLine , *ptmp;
4198 int rtStatus = _SUCCESS;
4199 char param_value_string[10];
4200 u8 param_value;
4201 u8 anttype = 4;
4202
4203 u8 ant_num = 3 , ant_distance = 50 , rfe_type = 1;
4204
4205 typedef struct ant_isolation {
4206 char *param_name; /* antenna isolation config parameter name */
4207 u8 *value; /* antenna isolation config parameter value */
4208 } ANT_ISOLATION;
4209
4210 ANT_ISOLATION ant_isolation_param[] = {
4211 {"ANT_NUMBER" , &ant_num},
4212 {"ANT_DISTANCE" , &ant_distance},
4213 {"RFE_TYPE" , &rfe_type},
4214 {NULL , 0}
4215 };
4216
4217
4218
4219 /* RTW_INFO("===>Hal_ParseAntIsolationConfigFile()\n" ); */
4220
4221 ptmp = buffer;
4222 for (szLine = GetLineFromBuffer(ptmp) ; szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
4223 /* skip comment */
4224 if (IsCommentString(szLine))
4225 continue;
4226
4227 /* RTW_INFO("%s : szLine = %s , strlen(szLine) = %d\n" , __func__ , szLine , strlen(szLine));*/
4228 for (j = 0 ; ant_isolation_param[j].param_name != NULL ; j++) {
4229 if (strstr(szLine , ant_isolation_param[j].param_name) != NULL) {
4230 i = 0;
4231 while (i < strlen(szLine)) {
4232 if (szLine[i] != '"')
4233 ++i;
4234 else {
4235 /* skip only has one " */
4236 if (strpbrk(szLine , "\"") == strrchr(szLine , '"')) {
4237 RTW_INFO("Fail to parse parameters , format error!\n");
4238 break;
4239 }
4240 _rtw_memset((PVOID)param_value_string , 0 , 10);
4241 if (!ParseQualifiedString(szLine , &i , param_value_string , '"' , '"')) {
4242 RTW_INFO("Fail to parse parameters\n");
4243 return _FAIL;
4244 } else if (!GetU1ByteIntegerFromStringInDecimal(param_value_string , ant_isolation_param[j].value))
4245 RTW_INFO("Fail to GetU1ByteIntegerFromStringInDecimal\n");
4246
4247 break;
4248 }
4249 }
4250 }
4251 }
4252 }
4253
4254 /* YiWei 20140716 , for BT coex antenna isolation control */
4255 /* rfe_type = 0 was SPDT , rfe_type = 1 was coupler */
4256 if (ant_num == 3 && ant_distance >= 50)
4257 anttype = 3;
4258 else if (ant_num == 2 && ant_distance >= 50 && rfe_type == 1)
4259 anttype = 2;
4260 else if (ant_num == 3 && ant_distance >= 15 && ant_distance < 50)
4261 anttype = 2;
4262 else if (ant_num == 2 && ant_distance >= 15 && ant_distance < 50 && rfe_type == 1)
4263 anttype = 2;
4264 else if ((ant_num == 2 && ant_distance < 15 && rfe_type == 1) || (ant_num == 3 && ant_distance < 15))
4265 anttype = 1;
4266 else if (ant_num == 2 && rfe_type == 0)
4267 anttype = 0;
4268 else
4269 anttype = 0;
4270
4271 hal_btcoex_SetAntIsolationType(Adapter, anttype);
4272
4273 RTW_INFO("%s : ant_num = %d\n" , __func__ , ant_num);
4274 RTW_INFO("%s : ant_distance = %d\n" , __func__ , ant_distance);
4275 RTW_INFO("%s : rfe_type = %d\n" , __func__ , rfe_type);
4276 /* RTW_INFO("<===Hal_ParseAntIsolationConfigFile()\n"); */
4277 return rtStatus;
4278 }
4279
4280
4281 int
hal_btcoex_AntIsolationConfig_ParaFile(IN PADAPTER Adapter,IN char * pFileName)4282 hal_btcoex_AntIsolationConfig_ParaFile(
4283 IN PADAPTER Adapter,
4284 IN char *pFileName
4285 )
4286 {
4287 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
4288 int rlen = 0 , rtStatus = _FAIL;
4289
4290 _rtw_memset(pHalData->para_file_buf , 0 , MAX_PARA_FILE_BUF_LEN);
4291
4292
4293 rtw_merge_string(rtw_phy_para_file_path, PATH_LENGTH_MAX, rtw_phy_file_path, pFileName);
4294
4295 if (rtw_is_file_readable(rtw_phy_para_file_path) == _TRUE) {
4296 rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
4297 if (rlen > 0)
4298 rtStatus = _SUCCESS;
4299 }
4300
4301
4302 if (rtStatus == _SUCCESS) {
4303 /*RTW_INFO("%s(): read %s ok\n", __func__ , pFileName);*/
4304 rtStatus = hal_btcoex_ParseAntIsolationConfigFile(Adapter , pHalData->para_file_buf);
4305 } else
4306 RTW_INFO("%s(): No File %s, Load from *** Array!\n" , __func__ , pFileName);
4307
4308 return rtStatus;
4309 }
4310 #endif /* CONFIG_LOAD_PHY_PARA_FROM_FILE */
4311
hal_btcoex_btreg_read(PADAPTER padapter,u8 type,u16 addr,u32 * data)4312 u16 hal_btcoex_btreg_read(PADAPTER padapter, u8 type, u16 addr, u32 *data)
4313 {
4314 u16 ret = 0;
4315
4316 halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
4317
4318 ret = halbtcoutsrc_GetBtReg_with_status(&GLBtCoexist, type, addr, data);
4319
4320 halbtcoutsrc_NormalLowPower(&GLBtCoexist);
4321
4322 return ret;
4323 }
4324
hal_btcoex_btreg_write(PADAPTER padapter,u8 type,u16 addr,u16 val)4325 u16 hal_btcoex_btreg_write(PADAPTER padapter, u8 type, u16 addr, u16 val)
4326 {
4327 u16 ret = 0;
4328
4329 halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
4330
4331 ret = halbtcoutsrc_SetBtReg(&GLBtCoexist, type, addr, val);
4332
4333 halbtcoutsrc_NormalLowPower(&GLBtCoexist);
4334
4335 return ret;
4336 }
4337
hal_btcoex_set_rfe_type(u8 type)4338 void hal_btcoex_set_rfe_type(u8 type)
4339 {
4340 EXhalbtcoutsrc_set_rfe_type(type);
4341 }
hal_btcoex_switchband_notify(u8 under_scan,u8 band_type)4342 void hal_btcoex_switchband_notify(u8 under_scan, u8 band_type)
4343 {
4344 switch (band_type) {
4345 case BAND_ON_2_4G:
4346 if (under_scan)
4347 EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_24G);
4348 else
4349 EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_24G_NOFORSCAN);
4350 break;
4351 case BAND_ON_5G:
4352 EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_5G);
4353 break;
4354 default:
4355 RTW_INFO("[BTCOEX] unkown switch band type\n");
4356 break;
4357 }
4358 }
4359
4360 #ifdef CONFIG_RF4CE_COEXIST
hal_btcoex_set_rf4ce_link_state(u8 state)4361 void hal_btcoex_set_rf4ce_link_state(u8 state)
4362 {
4363 EXhalbtcoutsrc_set_rf4ce_link_state(state);
4364 }
4365
hal_btcoex_get_rf4ce_link_state(void)4366 u8 hal_btcoex_get_rf4ce_link_state(void)
4367 {
4368 return EXhalbtcoutsrc_get_rf4ce_link_state();
4369 }
4370
hal_btcoex_set_rf4ce_voice_state(u8 state)4371 void hal_btcoex_set_rf4ce_voice_state(u8 state)
4372 {
4373 EXhalbtcoutsrc_set_rf4ce_voice_state(state);
4374 }
4375
hal_btcoex_get_rf4ce_voice_state(void)4376 u8 hal_btcoex_get_rf4ce_voice_state(void)
4377 {
4378 return EXhalbtcoutsrc_get_rf4ce_voice_state();
4379 }
4380 #endif /* CONFIG_RF4CE_COEXIST */
4381 #endif /* CONFIG_BT_COEXIST */
4382