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