forked from morrownr/88x2bu-20210702
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhal_btcoex.c
6651 lines (5540 loc) · 182 KB
/
hal_btcoex.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
*
* Copyright(c) 2013 - 2019 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#define __HAL_BTCOEX_C__
#ifdef CONFIG_BT_COEXIST
#include <hal_data.h>
#include <hal_btcoex.h>
#include "btc/mp_precomp.h"
/* ************************************
* Global variables
* ************************************ */
const char *const BtProfileString[] = {
"NONE",
"A2DP",
"PAN",
"HID",
"SCO",
};
const char *const BtSpecString[] = {
"1.0b",
"1.1",
"1.2",
"2.0+EDR",
"2.1+EDR",
"3.0+HS",
"4.0",
};
const char *const BtLinkRoleString[] = {
"Master",
"Slave",
};
const char *const h2cStaString[] = {
"successful",
"h2c busy",
"rf off",
"fw not read",
};
const char *const ioStaString[] = {
"success",
"can not IO",
"rf off",
"fw not read",
"wait io timeout",
"invalid len",
"idle Q empty",
"insert waitQ fail",
"unknown fail",
"wrong level",
"h2c stopped",
};
const char *const GLBtcWifiBwString[] = {
"11bg",
"HT20",
"HT40",
"VHT80",
"VHT160"
};
const char *const GLBtcWifiFreqString[] = {
"2.4G",
"5G",
"2.4G+5G"
};
const char *const GLBtcIotPeerString[] = {
"UNKNOWN",
"REALTEK",
"REALTEK_92SE",
"BROADCOM",
"RALINK",
"ATHEROS",
"CISCO",
"MERU",
"MARVELL",
"REALTEK_SOFTAP", /* peer is RealTek SOFT_AP, by Bohn, 2009.12.17 */
"SELF_SOFTAP", /* Self is SoftAP */
"AIRGO",
"INTEL",
"RTK_APCLIENT",
"REALTEK_81XX",
"REALTEK_WOW",
"REALTEK_JAGUAR_BCUTAP",
"REALTEK_JAGUAR_CCUTAP"
};
const char *const coexOpcodeString[] = {
"Wifi status notify",
"Wifi progress",
"Wifi info",
"Power state",
"Set Control",
"Get Control"
};
const char *const coexIndTypeString[] = {
"bt info",
"pstdma",
"limited tx/rx",
"coex table",
"request"
};
const char *const coexH2cResultString[] = {
"ok",
"unknown",
"un opcode",
"opVer MM",
"par Err",
"par OoR",
"reqNum MM",
"halMac Fail",
"h2c TimeOut",
"Invalid c2h Len",
"data overflow"
};
#define HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS 8000
struct btc_coexist GLBtCoexist;
BTC_OFFLOAD gl_coex_offload;
u8 GLBtcWiFiInScanState;
u8 GLBtcWiFiInIQKState;
u8 GLBtcWiFiInIPS;
u8 GLBtcWiFiInLPS;
u8 GLBtcBtCoexAliveRegistered;
/*
* BT control H2C/C2H
*/
/* EXT_EID */
typedef enum _bt_ext_eid {
C2H_WIFI_FW_ACTIVE_RSP = 0,
C2H_TRIG_BY_BT_FW
} BT_EXT_EID;
/* C2H_STATUS */
typedef enum _bt_c2h_status {
BT_STATUS_OK = 0,
BT_STATUS_VERSION_MISMATCH,
BT_STATUS_UNKNOWN_OPCODE,
BT_STATUS_ERROR_PARAMETER
} BT_C2H_STATUS;
/* C2H BT OP CODES */
typedef enum _bt_op_code {
BT_OP_GET_BT_VERSION = 0x00,
BT_OP_WRITE_REG_ADDR = 0x0c,
BT_OP_WRITE_REG_VALUE = 0x0d,
BT_OP_READ_REG = 0x11,
BT_LO_OP_GET_AFH_MAP_L = 0x1e,
BT_LO_OP_GET_AFH_MAP_M = 0x1f,
BT_LO_OP_GET_AFH_MAP_H = 0x20,
BT_OP_SET_BT_TRX_MASK = 0x29,
BT_OP_GET_BT_COEX_SUPPORTED_FEATURE = 0x2a,
BT_OP_GET_BT_COEX_SUPPORTED_VERSION = 0x2b,
BT_OP_GET_BT_ANT_DET_VAL = 0x2c,
BT_OP_GET_BT_BLE_SCAN_TYPE = 0x2d,
BT_OP_GET_BT_BLE_SCAN_PARA = 0x2e,
BT_OP_GET_BT_DEVICE_INFO = 0x30,
BT_OP_GET_BT_FORBIDDEN_SLOT_VAL = 0x31,
BT_OP_SET_BT_LANCONSTRAIN_LEVEL = 0x32,
BT_OP_SET_BT_TEST_MODE_VAL = 0x33,
BT_OP_MAX
} BT_OP_CODE;
#define BTC_MPOPER_TIMEOUT 50 /* unit: ms */
#define C2H_MAX_SIZE 16
u8 GLBtcBtMpOperSeq;
_mutex GLBtcBtMpOperLock;
_timer GLBtcBtMpOperTimer;
_sema GLBtcBtMpRptSema;
u8 GLBtcBtMpRptSeq;
u8 GLBtcBtMpRptStatus;
u8 GLBtcBtMpRptRsp[C2H_MAX_SIZE];
u8 GLBtcBtMpRptRspSize;
u8 GLBtcBtMpRptWait;
u8 GLBtcBtMpRptWiFiOK;
u8 GLBtcBtMpRptBTOK;
/*
* Debug
*/
u32 GLBtcDbgType[COMP_MAX];
u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];
u8 gl_btc_trace_buf[BT_TMP_BUF_SIZE];
typedef struct _btcoexdbginfo {
u8 *info;
u32 size; /* buffer total size */
u32 len; /* now used length */
} BTCDBGINFO, *PBTCDBGINFO;
BTCDBGINFO GLBtcDbgInfo;
#define BT_Operation(Adapter) _FALSE
static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)
{
if (NULL == pinfo)
return;
_rtw_memset(pinfo, 0, sizeof(BTCDBGINFO));
if (pbuf && size) {
pinfo->info = pbuf;
pinfo->size = size;
}
}
void DBG_BT_INFO(u8 *dbgmsg)
{
PBTCDBGINFO pinfo;
u32 msglen, buflen;
u8 *pbuf;
pinfo = &GLBtcDbgInfo;
if (NULL == pinfo->info)
return;
msglen = strlen(dbgmsg);
if (pinfo->len + msglen > pinfo->size)
return;
pbuf = pinfo->info + pinfo->len;
_rtw_memcpy(pbuf, dbgmsg, msglen);
pinfo->len += msglen;
}
/* ************************************
* Debug related function
* ************************************ */
static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
{
if (!pBtCoexist->bBinded ||
NULL == pBtCoexist->Adapter)
return _FALSE;
return _TRUE;
}
static void halbtcoutsrc_DbgInit(void)
{
u8 i;
for (i = 0; i < COMP_MAX; i++)
GLBtcDbgType[i] = 0;
}
static void halbtcoutsrc_EnterPwrLock(PBTC_COEXIST pBtCoexist)
{
struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter);
struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
_enter_pwrlock(&pwrpriv->lock);
}
static void halbtcoutsrc_ExitPwrLock(PBTC_COEXIST pBtCoexist)
{
struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter);
struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
_exit_pwrlock(&pwrpriv->lock);
}
static u8 halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)
{
if (pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC4
|| pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC8
)
return _FALSE;
else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
return _FALSE;
else
return _TRUE;
}
static u8 halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
padapter = pBtCoexist->Adapter;
pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;
pBtCoexist->bt_info.bt_lps_on = _FALSE;
return rtw_btcoex_LPS_Leave(padapter);
}
void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
padapter = pBtCoexist->Adapter;
if (pBtCoexist->bdontenterLPS == _FALSE) {
pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;
pBtCoexist->bt_info.bt_lps_on = _TRUE;
rtw_btcoex_LPS_Enter(padapter);
}
}
void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
padapter = pBtCoexist->Adapter;
if (pBtCoexist->bt_info.bt_ctrl_lps) {
pBtCoexist->bt_info.bt_lps_on = _FALSE;
rtw_btcoex_LPS_Leave(padapter);
pBtCoexist->bt_info.bt_ctrl_lps = _FALSE;
/* recover the LPS state to the original */
#if 0
padapter->hal_func.UpdateLPSStatusHandler(
padapter,
pPSC->RegLeisurePsMode,
pPSC->RegPowerSaveMode);
#endif
}
}
void halbtcoutsrc_Pre_NormalLps(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
padapter = pBtCoexist->Adapter;
if (pBtCoexist->bt_info.bt_ctrl_lps) {
pBtCoexist->bt_info.bt_lps_on = _FALSE;
rtw_btcoex_LPS_Leave(padapter);
}
}
void halbtcoutsrc_Post_NormalLps(PBTC_COEXIST pBtCoexist)
{
if (pBtCoexist->bt_info.bt_ctrl_lps)
pBtCoexist->bt_info.bt_ctrl_lps = _FALSE;
}
/*
* Constraint:
* 1. this function will request pwrctrl->lock
*/
void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
{
#ifdef CONFIG_LPS_LCLK
PADAPTER padapter;
PHAL_DATA_TYPE pHalData;
struct pwrctrl_priv *pwrctrl;
s32 ready;
systime stime;
s32 utime;
u32 timeout; /* unit: ms */
padapter = pBtCoexist->Adapter;
pHalData = GET_HAL_DATA(padapter);
pwrctrl = adapter_to_pwrctl(padapter);
ready = _FAIL;
#ifdef LPS_RPWM_WAIT_MS
timeout = LPS_RPWM_WAIT_MS;
#else /* !LPS_RPWM_WAIT_MS */
timeout = 30;
#endif /* !LPS_RPWM_WAIT_MS */
if (GLBtcBtCoexAliveRegistered == _TRUE)
return;
stime = rtw_get_current_time();
do {
ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
if (_SUCCESS == ready)
break;
utime = rtw_get_passing_time_ms(stime);
if (utime > timeout)
break;
rtw_msleep_os(1);
} while (1);
GLBtcBtCoexAliveRegistered = _TRUE;
#endif /* CONFIG_LPS_LCLK */
}
/*
* Constraint:
* 1. this function will request pwrctrl->lock
*/
void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
{
#ifdef CONFIG_LPS_LCLK
PADAPTER padapter;
if (GLBtcBtCoexAliveRegistered == _FALSE)
return;
padapter = pBtCoexist->Adapter;
rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
GLBtcBtCoexAliveRegistered = _FALSE;
#endif /* CONFIG_LPS_LCLK */
}
void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
{
pBtCoexist->bt_info.bt_disable_low_pwr = bLowPwrDisable;
if (bLowPwrDisable)
halbtcoutsrc_LeaveLowPower(pBtCoexist); /* leave 32k low power. */
else
halbtcoutsrc_NormalLowPower(pBtCoexist); /* original 32k low power behavior. */
}
void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
BOOLEAN bNeedToAct = _FALSE;
static u32 preTime = 0;
u32 curTime = 0;
padapter = pBtCoexist->Adapter;
/* ===================================== */
/* To void continuous deleteBA=>addBA=>deleteBA=>addBA */
/* This function is not allowed to continuous called. */
/* It can only be called after 8 seconds. */
/* ===================================== */
curTime = rtw_systime_to_ms(rtw_get_current_time());
if ((curTime - preTime) < HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS) /* over 8 seconds you can execute this function again. */
return;
else
preTime = curTime;
if (pBtCoexist->bt_info.reject_agg_pkt) {
bNeedToAct = _TRUE;
pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;
} else {
if (pBtCoexist->bt_info.pre_reject_agg_pkt) {
bNeedToAct = _TRUE;
pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;
}
if (pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {
bNeedToAct = _TRUE;
pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size = pBtCoexist->bt_info.bt_ctrl_agg_buf_size;
}
if (pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {
if (pBtCoexist->bt_info.pre_agg_buf_size !=
pBtCoexist->bt_info.agg_buf_size)
bNeedToAct = _TRUE;
pBtCoexist->bt_info.pre_agg_buf_size = pBtCoexist->bt_info.agg_buf_size;
}
}
if (bNeedToAct)
rtw_btcoex_rx_ampdu_apply(padapter);
}
u8 halbtcoutsrc_is_autoload_fail(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
PHAL_DATA_TYPE pHalData;
padapter = pBtCoexist->Adapter;
pHalData = GET_HAL_DATA(padapter);
return pHalData->bautoload_fail_flag;
}
u8 halbtcoutsrc_is_fw_ready(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
padapter = pBtCoexist->Adapter;
return GET_HAL_DATA(padapter)->bFWReady;
}
u8 halbtcoutsrc_IsDualBandConnected(PADAPTER padapter)
{
u8 ret = BTC_MULTIPORT_SCC;
#ifdef CONFIG_MCC_MODE
if (MCC_EN(padapter) && (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))) {
struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
struct mcc_obj_priv *mccobjpriv = &(dvobj->mcc_objpriv);
u8 band0 = mccobjpriv->iface[0]->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
u8 band1 = mccobjpriv->iface[1]->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
if (band0 != band1)
ret = BTC_MULTIPORT_MCC_DUAL_BAND;
else
ret = BTC_MULTIPORT_MCC_DUAL_CHANNEL;
}
#endif
return ret;
}
u8 halbtcoutsrc_IsWifiBusy(PADAPTER padapter)
{
if (rtw_mi_check_status(padapter, MI_AP_ASSOC))
return _TRUE;
if (rtw_mi_busy_traffic_check(padapter))
return _TRUE;
return _FALSE;
}
static u32 _halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)
{
struct mlme_priv *pmlmepriv;
u8 bp2p;
u32 portConnectedStatus;
pmlmepriv = &padapter->mlmepriv;
bp2p = _FALSE;
portConnectedStatus = 0;
#ifdef CONFIG_P2P
if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))
bp2p = _TRUE;
#endif /* CONFIG_P2P */
if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) {
if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
if (_TRUE == bp2p)
portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
else
portConnectedStatus |= WIFI_AP_CONNECTED;
} else {
if (_TRUE == bp2p)
portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
else
portConnectedStatus |= WIFI_STA_CONNECTED;
}
}
return portConnectedStatus;
}
u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
{
/* ================================= */
/* return value: */
/* [31:16]=> connected port number */
/* [15:0]=> port connected bit define */
/* ================================ */
PADAPTER padapter;
u32 retVal;
u32 portConnectedStatus, numOfConnectedPort;
struct dvobj_priv *dvobj;
_adapter *iface;
int i;
padapter = pBtCoexist->Adapter;
retVal = 0;
portConnectedStatus = 0;
numOfConnectedPort = 0;
dvobj = adapter_to_dvobj(padapter);
for (i = 0; i < dvobj->iface_nums; i++) {
iface = dvobj->padapters[i];
if ((iface) && rtw_is_adapter_up(iface)) {
retVal = _halbtcoutsrc_GetWifiLinkStatus(iface);
if (retVal) {
portConnectedStatus |= retVal;
numOfConnectedPort++;
}
}
}
retVal = (numOfConnectedPort << 16) | portConnectedStatus;
return retVal;
}
struct btc_wifi_link_info halbtcoutsrc_getwifilinkinfo(PBTC_COEXIST pBtCoexist)
{
u8 n_assoc_iface = 0, i =0, mcc_en = _FALSE;
PADAPTER adapter = NULL;
PADAPTER iface = NULL;
PADAPTER sta_iface = NULL, p2p_iface = NULL, ap_iface = NULL;
BTC_LINK_MODE btc_link_moe = BTC_LINK_MAX;
struct dvobj_priv *dvobj = NULL;
struct mlme_ext_priv *mlmeext = NULL;
struct btc_wifi_link_info wifi_link_info;
adapter = (PADAPTER)pBtCoexist->Adapter;
dvobj = adapter_to_dvobj(adapter);
n_assoc_iface = rtw_mi_get_assoc_if_num(adapter);
/* init value */
wifi_link_info.link_mode = BTC_LINK_NONE;
wifi_link_info.sta_center_channel = 0;
wifi_link_info.p2p_center_channel = 0;
wifi_link_info.bany_client_join_go = _FALSE;
wifi_link_info.benable_noa = _FALSE;
wifi_link_info.bhotspot = _FALSE;
for (i = 0; i < dvobj->iface_nums; i++) {
iface = dvobj->padapters[i];
if (!iface)
continue;
mlmeext = &iface->mlmeextpriv;
if (MLME_IS_GO(iface)) {
wifi_link_info.link_mode = BTC_LINK_ONLY_GO;
wifi_link_info.p2p_center_channel =
rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
p2p_iface = iface;
if (rtw_linked_check(iface))
wifi_link_info.bany_client_join_go = _TRUE;
} else if (MLME_IS_GC(iface)) {
wifi_link_info.link_mode = BTC_LINK_ONLY_GC;
wifi_link_info.p2p_center_channel =
rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
p2p_iface = iface;
} else if (MLME_IS_AP(iface)) {
wifi_link_info.link_mode = BTC_LINK_ONLY_AP;
ap_iface = iface;
wifi_link_info.p2p_center_channel =
rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
} else if (MLME_IS_STA(iface) && rtw_linked_check(iface)) {
wifi_link_info.link_mode = BTC_LINK_ONLY_STA;
wifi_link_info.sta_center_channel =
rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
sta_iface = iface;
}
}
#ifdef CONFIG_MCC_MODE
if (MCC_EN(adapter)) {
if (rtw_hal_check_mcc_status(adapter, MCC_STATUS_DOING_MCC))
mcc_en = _TRUE;
}
#endif/* CONFIG_MCC_MODE */
if (n_assoc_iface == 0) {
wifi_link_info.link_mode = BTC_LINK_NONE;
} else if (n_assoc_iface == 1) {
/* by pass */
} else if (n_assoc_iface == 2) {
if (sta_iface && p2p_iface) {
u8 band_sta = sta_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
u8 band_p2p = p2p_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
if (band_sta == band_p2p) {
switch (band_sta) {
case BAND_ON_2_4G:
if (MLME_IS_GO(p2p_iface)) {
#ifdef CONFIG_MCC_MODE
wifi_link_info.link_mode =
mcc_en == _TRUE ? BTC_LINK_2G_MCC_GO_STA : BTC_LINK_2G_SCC_GO_STA;
#else /* !CONFIG_MCC_MODE */
wifi_link_info.link_mode = BTC_LINK_2G_SCC_GO_STA;
#endif /* CONFIG_MCC_MODE */
} else if (MLME_IS_GC(p2p_iface)) {
#ifdef CONFIG_MCC_MODE
wifi_link_info.link_mode =
mcc_en == _TRUE ? BTC_LINK_2G_MCC_GC_STA : BTC_LINK_2G_SCC_GC_STA;
#else /* !CONFIG_MCC_MODE */
wifi_link_info.link_mode = BTC_LINK_2G_SCC_GC_STA;
#endif /* CONFIG_MCC_MODE */
}
break;
case BAND_ON_5G:
if (MLME_IS_GO(p2p_iface)) {
#ifdef CONFIG_MCC_MODE
wifi_link_info.link_mode =
mcc_en == _TRUE ? BTC_LINK_5G_MCC_GO_STA : BTC_LINK_5G_SCC_GO_STA;
#else /* !CONFIG_MCC_MODE */
wifi_link_info.link_mode = BTC_LINK_5G_SCC_GO_STA;
#endif /* CONFIG_MCC_MODE */
} else if (MLME_IS_GC(p2p_iface)) {
#ifdef CONFIG_MCC_MODE
wifi_link_info.link_mode =
mcc_en == _TRUE ? BTC_LINK_5G_MCC_GC_STA : BTC_LINK_5G_SCC_GC_STA;
#else /* !CONFIG_MCC_MODE */
wifi_link_info.link_mode = BTC_LINK_5G_SCC_GC_STA;
#endif /* CONFIG_MCC_MODE */
}
break;
}
} else {
if (MLME_IS_GO(p2p_iface))
wifi_link_info.link_mode = BTC_LINK_25G_MCC_GO_STA;
else if (MLME_IS_GC(p2p_iface))
wifi_link_info.link_mode = BTC_LINK_25G_MCC_GC_STA;
}
}
if (sta_iface && ap_iface) {
u8 band_sta = sta_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
u8 band_ap = ap_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
if (band_sta == band_ap) {
switch (band_sta) {
case BAND_ON_2_4G:
#ifdef CONFIG_MCC_MODE
wifi_link_info.link_mode =
mcc_en == _TRUE ? BTC_LINK_2G_MCC_GO_STA : BTC_LINK_2G_SCC_GO_STA;
#else /* !CONFIG_MCC_MODE */
wifi_link_info.link_mode = BTC_LINK_2G_SCC_GO_STA;
#endif /* CONFIG_MCC_MODE */
break;
case BAND_ON_5G:
#ifdef CONFIG_MCC_MODE
wifi_link_info.link_mode =
mcc_en == _TRUE ? BTC_LINK_5G_MCC_GO_STA : BTC_LINK_5G_SCC_GO_STA;
#else /* !CONFIG_MCC_MODE */
wifi_link_info.link_mode = BTC_LINK_5G_SCC_GO_STA;
#endif /* CONFIG_MCC_MODE */
break;
}
} else {
wifi_link_info.link_mode = BTC_LINK_25G_MCC_GO_STA;
}
}
} else {
if (pBtCoexist->board_info.btdm_ant_num == 1)
RTW_ERR("%s do not support n_assoc_iface > 2 (ant_num == 1)", __func__);
}
return wifi_link_info;
}
static void _btmpoper_timer_hdl(void *p)
{
if (GLBtcBtMpRptWait == _TRUE) {
GLBtcBtMpRptWait = _FALSE;
_rtw_up_sema(&GLBtcBtMpRptSema);
}
}
/*
* !IMPORTANT!
* Before call this function, caller should acquire "GLBtcBtMpOperLock"!
* Othrewise there will be racing problem and something may go wrong.
*/
static u8 _btmpoper_cmd(PBTC_COEXIST pBtCoexist, u8 opcode, u8 opcodever, u8 *cmd, u8 size)
{
PADAPTER padapter;
u8 buf[H2C_BTMP_OPER_LEN] = {0};
u8 buflen;
u8 seq;
s32 ret;
if (!cmd && size)
size = 0;
if ((size + 2) > H2C_BTMP_OPER_LEN)
return BT_STATUS_H2C_LENGTH_EXCEEDED;
buflen = size + 2;
seq = GLBtcBtMpOperSeq & 0xF;
GLBtcBtMpOperSeq++;
buf[0] = (opcodever & 0xF) | (seq << 4);
buf[1] = opcode;
if (cmd && size)
_rtw_memcpy(buf + 2, cmd, size);
GLBtcBtMpRptWait = _TRUE;
GLBtcBtMpRptWiFiOK = _FALSE;
GLBtcBtMpRptBTOK = _FALSE;
GLBtcBtMpRptStatus = 0;
padapter = pBtCoexist->Adapter;
_set_timer(&GLBtcBtMpOperTimer, BTC_MPOPER_TIMEOUT);
if (rtw_hal_fill_h2c_cmd(padapter, H2C_BT_MP_OPER, buflen, buf) == _FAIL) {
_cancel_timer_ex(&GLBtcBtMpOperTimer);
ret = BT_STATUS_H2C_FAIL;
goto exit;
}
_rtw_down_sema(&GLBtcBtMpRptSema);
/* GLBtcBtMpRptWait should be _FALSE here*/
if (GLBtcBtMpRptWiFiOK == _FALSE) {
RTW_DBG("%s: Didn't get H2C Rsp Event!\n", __FUNCTION__);
ret = BT_STATUS_H2C_TIMTOUT;
goto exit;
}
if (GLBtcBtMpRptBTOK == _FALSE) {
RTW_DBG("%s: Didn't get BT response!\n", __FUNCTION__);
ret = BT_STATUS_H2C_BT_NO_RSP;
goto exit;
}
if (seq != GLBtcBtMpRptSeq) {
RTW_ERR("%s: Sequence number not match!(%d!=%d)!\n",
__FUNCTION__, seq, GLBtcBtMpRptSeq);
ret = BT_STATUS_C2H_REQNUM_MISMATCH;
goto exit;
}
switch (GLBtcBtMpRptStatus) {
/* Examine the status reported from C2H */
case BT_STATUS_OK:
ret = BT_STATUS_BT_OP_SUCCESS;
RTW_DBG("%s: C2H status = BT_STATUS_BT_OP_SUCCESS\n", __FUNCTION__);
break;
case BT_STATUS_VERSION_MISMATCH:
ret = BT_STATUS_OPCODE_L_VERSION_MISMATCH;
RTW_DBG("%s: C2H status = BT_STATUS_OPCODE_L_VERSION_MISMATCH\n", __FUNCTION__);
break;
case BT_STATUS_UNKNOWN_OPCODE:
ret = BT_STATUS_UNKNOWN_OPCODE_L;
RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_OPCODE_L\n", __FUNCTION__);
break;
case BT_STATUS_ERROR_PARAMETER:
ret = BT_STATUS_PARAMETER_FORMAT_ERROR_L;
RTW_DBG("%s: C2H status = MP_BT_STATUS_PARAMETER_FORMAT_ERROR_L\n", __FUNCTION__);
break;
default:
ret = BT_STATUS_UNKNOWN_STATUS_L;
RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_STATUS_L\n", __FUNCTION__);
break;
}
exit:
return ret;
}
u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
{
if (pBtCoexist->bt_info.get_bt_fw_ver_cnt <= 5) {
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
_irqL irqL;
u8 ret;
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
ret = _btmpoper_cmd(pBtCoexist, BT_OP_GET_BT_VERSION, 0, NULL, 0);
if (BT_STATUS_BT_OP_SUCCESS == ret) {
pBtCoexist->bt_info.bt_real_fw_ver = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
pBtCoexist->bt_info.get_bt_fw_ver_cnt++;
}
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else {
#ifdef CONFIG_BT_COEXIST_SOCKET_TRX
u8 dataLen = 2;
u8 buf[4] = {0};
buf[0] = 0x0; /* OP_Code */
buf[1] = 0x0; /* OP_Code_Length */
BT_SendEventExtBtCoexControl(pBtCoexist->Adapter, _FALSE, dataLen, &buf[0]);
#endif /* !CONFIG_BT_COEXIST_SOCKET_TRX */
}
}
return pBtCoexist->bt_info.bt_real_fw_ver;
}
s32 halbtcoutsrc_GetWifiRssi(PADAPTER padapter)
{
return rtw_dm_get_min_rssi(padapter);
}
u32 halbtcoutsrc_GetBtCoexSupportedFeature(void *pBtcContext)
{
PBTC_COEXIST pBtCoexist;
u32 ret = BT_STATUS_BT_OP_SUCCESS;
u32 data = 0;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
u8 buf[3] = {0};
_irqL irqL;
u8 op_code;
u8 status;
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
op_code = BT_OP_GET_BT_COEX_SUPPORTED_FEATURE;
status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
if (status == BT_STATUS_BT_OP_SUCCESS)
data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
else
ret = SET_BT_MP_OPER_RET(op_code, status);
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else
ret = BT_STATUS_NOT_IMPLEMENT;
return data;
}
u32 halbtcoutsrc_GetBtCoexSupportedVersion(void *pBtcContext)
{
PBTC_COEXIST pBtCoexist;
u32 ret = BT_STATUS_BT_OP_SUCCESS;
u32 data = 0xFFFF;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
u8 buf[3] = {0};
_irqL irqL;
u8 op_code;
u8 status;
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
op_code = BT_OP_GET_BT_COEX_SUPPORTED_VERSION;
status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
if (status == BT_STATUS_BT_OP_SUCCESS)
data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
else
ret = SET_BT_MP_OPER_RET(op_code, status);
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else
ret = BT_STATUS_NOT_IMPLEMENT;
return data;
}
u32 halbtcoutsrc_GetBtDeviceInfo(void *pBtcContext)
{
PBTC_COEXIST pBtCoexist;
u32 ret = BT_STATUS_BT_OP_SUCCESS;
u32 btDeviceInfo = 0;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
u8 buf[3] = {0};
_irqL irqL;
u8 op_code;
u8 status;
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
op_code = BT_OP_GET_BT_DEVICE_INFO;
status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
if (status == BT_STATUS_BT_OP_SUCCESS)
btDeviceInfo = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
else
ret = SET_BT_MP_OPER_RET(op_code, status);
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else
ret = BT_STATUS_NOT_IMPLEMENT;
return btDeviceInfo;
}
u32 halbtcoutsrc_GetBtForbiddenSlotVal(void *pBtcContext)
{
PBTC_COEXIST pBtCoexist;
u32 ret = BT_STATUS_BT_OP_SUCCESS;
u32 btForbiddenSlotVal = 0;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
u8 buf[3] = {0};
_irqL irqL;
u8 op_code;
u8 status;