-
Notifications
You must be signed in to change notification settings - Fork 430
Expand file tree
/
Copy pathrtl8812a_hal_init.c
More file actions
6405 lines (5384 loc) · 187 KB
/
rtl8812a_hal_init.c
File metadata and controls
6405 lines (5384 loc) · 187 KB
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) 2007 - 2011 Realtek Corporation. All rights reserved.
*
* 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.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*
*
******************************************************************************/
#define _RTL8812A_HAL_INIT_C_
//#include <drv_types.h>
#include <rtl8812a_hal.h>
//-------------------------------------------------------------------------
//
// LLT R/W/Init function
//
//-------------------------------------------------------------------------
s32
_LLTWrite_8812A(
IN PADAPTER Adapter,
IN u32 address,
IN u32 data
)
{
u32 status = _SUCCESS;
s32 count = 0;
u32 value = _LLT_INIT_ADDR(address) | _LLT_INIT_DATA(data) | _LLT_OP(_LLT_WRITE_ACCESS);
rtw_write32(Adapter, REG_LLT_INIT, value);
//polling
do {
value = rtw_read32(Adapter, REG_LLT_INIT);
if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value)) {
break;
}
if (count > POLLING_LLT_THRESHOLD) {
RT_TRACE(_module_hal_init_c_, _drv_err_, ("Failed to polling write LLT done at address %d!\n", address));
status = _FAIL;
break;
}
} while (++count);
return status;
}
static inline u8 _LLTRead_8812A(
IN PADAPTER Adapter,
IN u32 address
)
{
u32 count = 0;
u32 value = _LLT_INIT_ADDR(address) | _LLT_OP(_LLT_READ_ACCESS);
u16 LLTReg = REG_LLT_INIT;
rtw_write32(Adapter, LLTReg, value);
//polling and get value
do {
value = rtw_read32(Adapter, LLTReg);
if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value)) {
return (u8)value;
}
if (count > POLLING_LLT_THRESHOLD) {
RT_TRACE(_module_hal_init_c_, _drv_err_, ("Failed to polling read LLT done at address %d!\n", address));
break;
}
} while (++count);
return 0xFF;
}
s32 InitLLTTable8812A(PADAPTER padapter, u8 txpktbuf_bndy)
{
s32 status = _FAIL;
u32 i;
u32 Last_Entry_Of_TxPktBuf = LAST_ENTRY_OF_TX_PKT_BUFFER_8812;
//HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
for (i = 0; i < (txpktbuf_bndy - 1); i++) {
status = _LLTWrite_8812A(padapter, i, i + 1);
if (_SUCCESS != status) {
return status;
}
}
// end of list
status = _LLTWrite_8812A(padapter, (txpktbuf_bndy - 1), 0xFF);
if (_SUCCESS != status) {
return status;
}
// Make the other pages as ring buffer
// This ring buffer is used as beacon buffer if we config this MAC as two MAC transfer.
// Otherwise used as local loopback buffer.
for (i = txpktbuf_bndy; i < Last_Entry_Of_TxPktBuf; i++) {
status = _LLTWrite_8812A(padapter, i, (i + 1));
if (_SUCCESS != status) {
return status;
}
}
// Let last entry point to the start entry of ring buffer
status = _LLTWrite_8812A(padapter, Last_Entry_Of_TxPktBuf, txpktbuf_bndy);
if (_SUCCESS != status) {
return status;
}
return status;
}
BOOLEAN HalDetectPwrDownMode8812(PADAPTER Adapter)
{
u8 tmpvalue = 0;
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(Adapter);
EFUSE_ShadowRead(Adapter, 1, EEPROM_RF_OPT3_92C, (u32 *)&tmpvalue);
// 2010/08/25 MH INF priority > PDN Efuse value.
if(tmpvalue & BIT(4) && pwrctrlpriv->reg_pdnmode) {
pHalData->pwrdown = _TRUE;
} else {
pHalData->pwrdown = _FALSE;
}
DBG_8192C("HalDetectPwrDownMode(): PDN=%d\n", pHalData->pwrdown);
return pHalData->pwrdown;
} // HalDetectPwrDownMode
#ifdef CONFIG_WOWLAN
void Hal_DetectWoWMode(PADAPTER pAdapter)
{
adapter_to_pwrctl(pAdapter)->bSupportRemoteWakeup = _TRUE;
DBG_871X("%s\n", __func__);
}
#endif
//====================================================================================
//
// 20100209 Joseph:
// This function is used only for 92C to set REG_BCN_CTRL(0x550) register.
// We just reserve the value of the register in variable pHalData->RegBcnCtrlVal and then operate
// the value of the register via atomic operation.
// This prevents from race condition when setting this register.
// The value of pHalData->RegBcnCtrlVal is initialized in HwConfigureRTL8192CE() function.
//
void SetBcnCtrlReg(
PADAPTER padapter,
u8 SetBits,
u8 ClearBits)
{
PHAL_DATA_TYPE pHalData;
pHalData = GET_HAL_DATA(padapter);
pHalData->RegBcnCtrlVal |= SetBits;
pHalData->RegBcnCtrlVal &= ~ClearBits;
#if 0
//#ifdef CONFIG_SDIO_HCI
if (pHalData->sdio_himr & (SDIO_HIMR_TXBCNOK_MSK | SDIO_HIMR_TXBCNERR_MSK))
pHalData->RegBcnCtrlVal |= EN_TXBCN_RPT;
#endif
rtw_write8(padapter, REG_BCN_CTRL, (u8)pHalData->RegBcnCtrlVal);
}
static VOID
_FWDownloadEnable_8812(
IN PADAPTER padapter,
IN BOOLEAN enable
)
{
u8 tmp;
if(enable) {
// MCU firmware download enable.
tmp = rtw_read8(padapter, REG_MCUFWDL);
rtw_write8(padapter, REG_MCUFWDL, tmp|0x01);
// 8051 reset
tmp = rtw_read8(padapter, REG_MCUFWDL+2);
rtw_write8(padapter, REG_MCUFWDL+2, tmp&0xf7);
} else {
// MCU firmware download disable.
tmp = rtw_read8(padapter, REG_MCUFWDL);
rtw_write8(padapter, REG_MCUFWDL, tmp&0xfe);
}
}
#define MAX_REG_BOLCK_SIZE 196
static int
_BlockWrite_8812(
IN PADAPTER padapter,
IN PVOID buffer,
IN u32 buffSize
)
{
int ret = _SUCCESS;
u32 blockSize_p1 = 4; // (Default) Phase #1 : PCI muse use 4-byte write to download FW
u32 blockSize_p2 = 8; // Phase #2 : Use 8-byte, if Phase#1 use big size to write FW.
u32 blockSize_p3 = 1; // Phase #3 : Use 1-byte, the remnant of FW image.
u32 blockCount_p1 = 0, blockCount_p2 = 0, blockCount_p3 = 0;
u32 remainSize_p1 = 0, remainSize_p2 = 0;
u8 *bufferPtr = (u8*)buffer;
u32 i=0, offset=0;
#ifdef CONFIG_PCI_HCI
u8 remainFW[4] = {0, 0, 0, 0};
u8 *p = NULL;
#endif
#ifdef CONFIG_USB_HCI
blockSize_p1 = MAX_REG_BOLCK_SIZE;
#endif
//3 Phase #1
blockCount_p1 = buffSize / blockSize_p1;
remainSize_p1 = buffSize % blockSize_p1;
if (blockCount_p1) {
RT_TRACE(_module_hal_init_c_, _drv_notice_,
("_BlockWrite: [P1] buffSize(%d) blockSize_p1(%d) blockCount_p1(%d) remainSize_p1(%d)\n",
buffSize, blockSize_p1, blockCount_p1, remainSize_p1));
}
for (i = 0; i < blockCount_p1; i++) {
#ifdef CONFIG_USB_HCI
ret = rtw_writeN(padapter, (FW_START_ADDRESS + i * blockSize_p1), blockSize_p1, (bufferPtr + i * blockSize_p1));
#else
ret = rtw_write32(padapter, (FW_START_ADDRESS + i * blockSize_p1), le32_to_cpu(*((u32*)(bufferPtr + i * blockSize_p1))));
#endif
if(ret == _FAIL)
goto exit;
}
#ifdef CONFIG_PCI_HCI
p = (u8*)((u32*)(bufferPtr + blockCount_p1 * blockSize_p1));
if (remainSize_p1) {
switch (remainSize_p1) {
case 0:
break;
case 3:
remainFW[2]=*(p+2);
case 2:
remainFW[1]=*(p+1);
case 1:
remainFW[0]=*(p);
ret = rtw_write32(padapter, (FW_START_ADDRESS + blockCount_p1 * blockSize_p1),
le32_to_cpu(*(u32*)remainFW));
}
return ret;
}
#endif
//3 Phase #2
if (remainSize_p1) {
offset = blockCount_p1 * blockSize_p1;
blockCount_p2 = remainSize_p1/blockSize_p2;
remainSize_p2 = remainSize_p1%blockSize_p2;
if (blockCount_p2) {
RT_TRACE(_module_hal_init_c_, _drv_notice_,
("_BlockWrite: [P2] buffSize_p2(%d) blockSize_p2(%d) blockCount_p2(%d) remainSize_p2(%d)\n",
(buffSize-offset), blockSize_p2 ,blockCount_p2, remainSize_p2));
}
#ifdef CONFIG_USB_HCI
for (i = 0; i < blockCount_p2; i++) {
ret = rtw_writeN(padapter, (FW_START_ADDRESS + offset + i*blockSize_p2), blockSize_p2, (bufferPtr + offset + i*blockSize_p2));
if(ret == _FAIL)
goto exit;
}
#endif
}
//3 Phase #3
if (remainSize_p2) {
offset = (blockCount_p1 * blockSize_p1) + (blockCount_p2 * blockSize_p2);
blockCount_p3 = remainSize_p2 / blockSize_p3;
RT_TRACE(_module_hal_init_c_, _drv_notice_,
("_BlockWrite: [P3] buffSize_p3(%d) blockSize_p3(%d) blockCount_p3(%d)\n",
(buffSize-offset), blockSize_p3, blockCount_p3));
for(i = 0 ; i < blockCount_p3 ; i++) {
ret =rtw_write8(padapter, (FW_START_ADDRESS + offset + i), *(bufferPtr + offset + i));
if(ret == _FAIL)
goto exit;
}
}
exit:
return ret;
}
static int
_PageWrite_8812(
IN PADAPTER padapter,
IN u32 page,
IN PVOID buffer,
IN u32 size
)
{
u8 value8;
u8 u8Page = (u8) (page & 0x07) ;
value8 = (rtw_read8(padapter, REG_MCUFWDL+2) & 0xF8) | u8Page ;
rtw_write8(padapter, REG_MCUFWDL+2,value8);
return _BlockWrite_8812(padapter,buffer,size);
}
static inline VOID _FillDummy_8812(
u8* pFwBuf,
u32* pFwLen
)
{
u32 FwLen = *pFwLen;
u8 remain = (u8)(FwLen%4);
remain = (remain==0)?0:(4-remain);
while(remain>0) {
pFwBuf[FwLen] = 0;
FwLen++;
remain--;
}
*pFwLen = FwLen;
}
static int
_WriteFW_8812(
IN PADAPTER padapter,
IN PVOID buffer,
IN u32 size
)
{
// Since we need dynamic decide method of dwonload fw, so we call this function to get chip version.
// We can remove _ReadChipVersion from ReadpadapterInfo8192C later.
int ret = _SUCCESS;
u32 pageNums,remainSize ;
u32 page, offset;
u8 *bufferPtr = (u8*)buffer;
#ifdef CONFIG_PCI_HCI
// 20100120 Joseph: Add for 88CE normal chip.
// Fill in zero to make firmware image to dword alignment.
// _FillDummy(bufferPtr, &size);
#endif
pageNums = size / MAX_DLFW_PAGE_SIZE ;
//RT_ASSERT((pageNums <= 4), ("Page numbers should not greater then 4 \n"));
remainSize = size % MAX_DLFW_PAGE_SIZE;
for (page = 0; page < pageNums; page++) {
offset = page * MAX_DLFW_PAGE_SIZE;
ret = _PageWrite_8812(padapter, page, bufferPtr+offset, MAX_DLFW_PAGE_SIZE);
if(ret == _FAIL)
goto exit;
}
if (remainSize) {
offset = pageNums * MAX_DLFW_PAGE_SIZE;
page = pageNums;
ret = _PageWrite_8812(padapter, page, bufferPtr+offset, remainSize);
if(ret == _FAIL)
goto exit;
}
RT_TRACE(_module_hal_init_c_, _drv_info_, ("_WriteFW Done- for Normal chip.\n"));
exit:
return ret;
}
void _8051Reset8812(PADAPTER padapter)
{
u8 u1bTmp, u1bTmp2;
// Reset MCU IO Wrapper- sugggest by SD1-Gimmy
if(IS_HARDWARE_TYPE_8812(padapter)) {
u1bTmp2 = rtw_read8(padapter, REG_RSV_CTRL);
rtw_write8(padapter, REG_RSV_CTRL, u1bTmp2&(~BIT1));
u1bTmp2 = rtw_read8(padapter, REG_RSV_CTRL+1);
rtw_write8(padapter, REG_RSV_CTRL+1, u1bTmp2&(~BIT3));
} else if(IS_HARDWARE_TYPE_8821(padapter)) {
u1bTmp2 = rtw_read8(padapter, REG_RSV_CTRL);
rtw_write8(padapter, REG_RSV_CTRL, u1bTmp2&(~BIT1));
u1bTmp2 = rtw_read8(padapter, REG_RSV_CTRL+1);
rtw_write8(padapter, REG_RSV_CTRL+1, u1bTmp2&(~BIT0));
}
u1bTmp = rtw_read8(padapter, REG_SYS_FUNC_EN+1);
rtw_write8(padapter, REG_SYS_FUNC_EN+1, u1bTmp&(~BIT2));
// Enable MCU IO Wrapper
if(IS_HARDWARE_TYPE_8812(padapter)) {
u1bTmp2 = rtw_read8(padapter, REG_RSV_CTRL);
rtw_write8(padapter, REG_RSV_CTRL, u1bTmp2&(~BIT1));
u1bTmp2 = rtw_read8(padapter, REG_RSV_CTRL+1);
rtw_write8(padapter, REG_RSV_CTRL+1, u1bTmp2 |(BIT3));
} else if(IS_HARDWARE_TYPE_8821(padapter)) {
u1bTmp2 = rtw_read8(padapter, REG_RSV_CTRL);
rtw_write8(padapter, REG_RSV_CTRL, u1bTmp2&(~BIT1));
u1bTmp2 = rtw_read8(padapter, REG_RSV_CTRL+1);
rtw_write8(padapter, REG_RSV_CTRL+1, u1bTmp2|(BIT0));
}
rtw_write8(padapter, REG_SYS_FUNC_EN+1, u1bTmp|(BIT2));
DBG_871X("=====> _8051Reset8812(): 8051 reset success .\n");
}
static s32 polling_fwdl_chksum(_adapter *adapter, u32 min_cnt, u32 timeout_ms)
{
s32 ret = _FAIL;
u32 value32;
u32 start = rtw_get_current_time();
u32 cnt = 0;
/* polling CheckSum report */
do {
cnt++;
value32 = rtw_read32(adapter, REG_MCUFWDL);
if (value32 & FWDL_ChkSum_rpt || adapter->bSurpriseRemoved || adapter->bDriverStopped)
break;
rtw_yield_os();
} while (rtw_get_passing_time_ms(start) < timeout_ms || cnt < min_cnt);
if (!(value32 & FWDL_ChkSum_rpt)) {
goto exit;
}
if (rtw_fwdl_test_trigger_chksum_fail())
goto exit;
ret = _SUCCESS;
exit:
DBG_871X("%s: Checksum report %s! (%u, %dms), REG_MCUFWDL:0x%08x\n", __FUNCTION__
, (ret==_SUCCESS)?"OK":"Fail", cnt, rtw_get_passing_time_ms(start), value32);
return ret;
}
static s32 _FWFreeToGo8812(_adapter *adapter, u32 min_cnt, u32 timeout_ms)
{
s32 ret = _FAIL;
u32 value32;
u32 start = rtw_get_current_time();
u32 cnt = 0;
value32 = rtw_read32(adapter, REG_MCUFWDL);
value32 |= MCUFWDL_RDY;
value32 &= ~WINTINI_RDY;
rtw_write32(adapter, REG_MCUFWDL, value32);
_8051Reset8812(adapter);
/* polling for FW ready */
do {
cnt++;
value32 = rtw_read32(adapter, REG_MCUFWDL);
if (value32 & WINTINI_RDY || adapter->bSurpriseRemoved || adapter->bDriverStopped)
break;
rtw_yield_os();
} while (rtw_get_passing_time_ms(start) < timeout_ms || cnt < min_cnt);
if (!(value32 & WINTINI_RDY)) {
goto exit;
}
if (rtw_fwdl_test_trigger_wintint_rdy_fail())
goto exit;
ret = _SUCCESS;
exit:
DBG_871X("%s: Polling FW ready %s! (%u, %dms), REG_MCUFWDL:0x%08x\n", __FUNCTION__
, (ret==_SUCCESS)?"OK":"Fail", cnt, rtw_get_passing_time_ms(start), value32);
return ret;
}
#ifdef CONFIG_FILE_FWIMG
extern char *rtw_fw_file_path;
u8 FwBuffer8812[FW_SIZE_8812];
#ifdef CONFIG_MP_INCLUDED
extern char *rtw_fw_mp_bt_file_path;
#endif // CONFIG_MP_INCLUDED
u8 FwBuffer[FW_SIZE_8812];
#endif //CONFIG_FILE_FWIMG
s32
FirmwareDownload8812(
IN PADAPTER Adapter,
IN BOOLEAN bUsedWoWLANFw
)
{
s32 rtStatus = _SUCCESS;
u8 write_fw = 0;
u32 fwdl_start_time;
PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
//u8 *pFwImageFileName;
//u8 *pucMappedFile = NULL;
PRT_FIRMWARE_8812 pFirmware = NULL;
u8 *pFwHdr = NULL;
u8 *pFirmwareBuf;
u32 FirmwareLen;
RT_TRACE(_module_hal_init_c_, _drv_info_, ("+%s\n", __FUNCTION__));
pFirmware = (PRT_FIRMWARE_8812)rtw_zmalloc(sizeof(RT_FIRMWARE_8812));
if(!pFirmware) {
rtStatus = _FAIL;
goto exit;
}
#ifdef CONFIG_FILE_FWIMG
if(rtw_is_file_readable(rtw_fw_file_path) == _TRUE) {
DBG_871X("%s accquire FW from file:%s\n", __FUNCTION__, rtw_fw_file_path);
pFirmware->eFWSource = FW_SOURCE_IMG_FILE;
} else
#endif //CONFIG_FILE_FWIMG
{
DBG_871X("%s fw source from Header\n", __FUNCTION__);
pFirmware->eFWSource = FW_SOURCE_HEADER_FILE;
}
switch(pFirmware->eFWSource) {
case FW_SOURCE_IMG_FILE:
#ifdef CONFIG_FILE_FWIMG
rtStatus = rtw_retrive_from_file(rtw_fw_file_path, FwBuffer8812, FW_SIZE_8812);
pFirmware->ulFwLength = rtStatus>=0?rtStatus:0;
pFirmware->szFwBuffer = FwBuffer8812;
#endif //CONFIG_FILE_FWIMG
break;
case FW_SOURCE_HEADER_FILE:
#ifdef CONFIG_WOWLAN
if (bUsedWoWLANFw) {
ODM_ConfigFWWithHeaderFile(&pHalData->odmpriv, CONFIG_FW_WoWLAN, (u8 *)&(pFirmware->szFwBuffer), &(pFirmware->ulFwLength));
DBG_871X("%s fw:%s, size: %d\n", __FUNCTION__, "WoWLAN", pFirmware->ulFwLength);
} else
#endif /* CONFIG_WOWLAN */
#ifdef CONFIG_BT_COEXIST
if (pHalData->EEPROMBluetoothCoexist == _TRUE) {
ODM_ConfigFWWithHeaderFile(&pHalData->odmpriv, CONFIG_FW_BT, (u8 *)&(pFirmware->szFwBuffer), &(pFirmware->ulFwLength));
DBG_871X("%s fw:%s, size: %d\n", __FUNCTION__, "NIC-BTCOEX", pFirmware->ulFwLength);
} else
#endif /* CONFIG_BT_COEXIST */
{
ODM_ConfigFWWithHeaderFile(&pHalData->odmpriv, CONFIG_FW_NIC, (u8 *)&(pFirmware->szFwBuffer), &(pFirmware->ulFwLength));
DBG_871X("%s fw:%s, size: %d\n", __FUNCTION__, "NIC", pFirmware->ulFwLength);
}
break;
}
if (pFirmware->ulFwLength > FW_SIZE_8812) {
rtStatus = _FAIL;
DBG_871X_LEVEL(_drv_emerg_, "Firmware size:%u exceed %u\n", pFirmware->ulFwLength, FW_SIZE_8812);
goto exit;
}
pFirmwareBuf = pFirmware->szFwBuffer;
FirmwareLen = pFirmware->ulFwLength;
pFwHdr = (u8 *)pFirmware->szFwBuffer;
pHalData->FirmwareVersion = (u16)GET_FIRMWARE_HDR_VERSION_8812(pFwHdr);
pHalData->FirmwareSubVersion = (u16)GET_FIRMWARE_HDR_SUB_VER_8812(pFwHdr);
pHalData->FirmwareSignature = (u16)GET_FIRMWARE_HDR_SIGNATURE_8812(pFwHdr);
DBG_871X ("%s: fw_ver=%d fw_subver=%d sig=0x%x\n",
__FUNCTION__, pHalData->FirmwareVersion, pHalData->FirmwareSubVersion, pHalData->FirmwareSignature);
if (IS_FW_HEADER_EXIST_8812(pFwHdr) || IS_FW_HEADER_EXIST_8821(pFwHdr)) {
// Shift 32 bytes for FW header
pFirmwareBuf = pFirmwareBuf + 32;
FirmwareLen = FirmwareLen - 32;
}
// Suggested by Filen. If 8051 is running in RAM code, driver should inform Fw to reset by itself,
// or it will cause download Fw fail. 2010.02.01. by tynli.
if (rtw_read8(Adapter, REG_MCUFWDL) & BIT7) { //8051 RAM code
rtw_write8(Adapter, REG_MCUFWDL, 0x00);
_8051Reset8812(Adapter);
}
_FWDownloadEnable_8812(Adapter, _TRUE);
fwdl_start_time = rtw_get_current_time();
while(!Adapter->bDriverStopped && !Adapter->bSurpriseRemoved
&& (write_fw++ < 3 || rtw_get_passing_time_ms(fwdl_start_time) < 500)) {
/* reset FWDL chksum */
rtw_write8(Adapter, REG_MCUFWDL, rtw_read8(Adapter, REG_MCUFWDL)|FWDL_ChkSum_rpt);
rtStatus = _WriteFW_8812(Adapter, pFirmwareBuf, FirmwareLen);
if (rtStatus != _SUCCESS)
continue;
rtStatus = polling_fwdl_chksum(Adapter, 5, 50);
if (rtStatus == _SUCCESS)
break;
}
_FWDownloadEnable_8812(Adapter, _FALSE);
if(_SUCCESS != rtStatus)
goto fwdl_stat;
rtStatus = _FWFreeToGo8812(Adapter, 10, 200);
if (_SUCCESS != rtStatus)
goto fwdl_stat;
if(IS_HARDWARE_TYPE_8821(Adapter)) {
//to do download BT
}
fwdl_stat:
DBG_871X("FWDL %s. write_fw:%u, %dms\n"
, (rtStatus == _SUCCESS)?"success":"fail"
, write_fw
, rtw_get_passing_time_ms(fwdl_start_time)
);
exit:
if (pFirmware)
rtw_mfree((u8*)pFirmware, sizeof(RT_FIRMWARE_8812));
#ifdef CONFIG_WOWLAN
if (adapter_to_pwrctl(Adapter)->wowlan_mode)
InitializeFirmwareVars8812(Adapter);
else
DBG_871X_LEVEL(_drv_always_, "%s: wowland_mode:%d wowlan_wake_reason:%d\n",
__func__, adapter_to_pwrctl(Adapter)->wowlan_mode,
adapter_to_pwrctl(Adapter)->wowlan_wake_reason);
#endif
return rtStatus;
}
void InitializeFirmwareVars8812(PADAPTER padapter)
{
PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
// Init Fw LPS related.
pwrpriv->bFwCurrentInPSMode = _FALSE;
// Init H2C counter. by tynli. 2009.12.09.
pHalData->LastHMEBoxNum = 0;
}
//
// Description: Determine the contents of H2C BT_FW_PATCH Command sent to FW.
// 2013.01.23 by tynli
// Porting from 8723B. 2013.04.01
//
VOID
SetFwBTFwPatchCmd_8821(
IN PADAPTER Adapter,
IN u2Byte FwSize
)
{
u1Byte u1BTFwPatchParm[6]= {0};
DBG_871X("SetFwBTFwPatchCmd_8821(): FwSize = %d\n", FwSize);
//SET_8812_H2CCMD_BT_FW_PATCH_ENABLE(u1BTFwPatchParm, 1);
SET_8812_H2CCMD_BT_FW_PATCH_SIZE(u1BTFwPatchParm, FwSize);
SET_8812_H2CCMD_BT_FW_PATCH_ADDR0(u1BTFwPatchParm, 0);
SET_8812_H2CCMD_BT_FW_PATCH_ADDR1(u1BTFwPatchParm, 0xa0);
SET_8812_H2CCMD_BT_FW_PATCH_ADDR2(u1BTFwPatchParm, 0x10);
SET_8812_H2CCMD_BT_FW_PATCH_ADDR3(u1BTFwPatchParm, 0x80);
FillH2CCmd_8812(Adapter, H2C_8812_BT_FW_PATCH, 6 , u1BTFwPatchParm);
}
int _CheckWLANFwPatchBTFwReady_8821A( PADAPTER Adapter )
{
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
u4Byte count=0;
u1Byte u1bTmp;
int ret = _FAIL;
#if (DEV_BUS_TYPE == RT_SDIO_INTERFACE)
u4Byte txpktbuf_bndy;
#endif
//---------------------------------------------------------
// Check if BT FW patch procedure is ready.
//---------------------------------------------------------
do {
u1bTmp = PlatformEFIORead1Byte(Adapter, REG_FW_DRV_MSG_8812);
if((u1bTmp&BIT6) || (u1bTmp&BIT7)) {
ret = _SUCCESS;
break;
}
count++;
RT_TRACE(_module_mp_, _drv_info_,("0x81=%x, wait for 50 ms (%d) times.\n",
u1bTmp, count));
rtw_msleep_os(50); // 50ms
} while(!((u1bTmp&BIT6) || (u1bTmp&BIT7)) && count < 50);
RT_TRACE(_module_mp_, _drv_notice_,("_CheckWLANFwPatchBTFwReady():"
" Polling ready bit 0x88[6:7] for %d times.\n", count));
if(count >= 50) {
DBG_871X("_CheckWLANFwPatchBTFwReady():"
" Polling ready bit 0x88[6:7] FAIL!!\n");
}
//---------------------------------------------------------
// Reset beacon setting to the initial value.
//---------------------------------------------------------
#if (DEV_BUS_TYPE == RT_SDIO_INTERFACE)
#if 0
if(!Adapter->MgntInfo.bWiFiConfg) {
txpktbuf_bndy = TX_PAGE_BOUNDARY_8821;
} else
#endif
{
// for WMM
txpktbuf_bndy = WMM_NORMAL_TX_PAGE_BOUNDARY_8821;
}
ret = InitLLTTable8812A(Adapter, txpktbuf_bndy);
if(_SUCCESS != ret) {
DBG_871X("_CheckWLANFwPatchBTFwReady_8821A(): Failed to init LLT!\n");
}
// Init Tx boundary.
PlatformEFIOWrite1Byte(Adapter, REG_TDECTRL+1, (u1Byte)txpktbuf_bndy);
#endif
SetBcnCtrlReg(Adapter, BIT3, 0);
SetBcnCtrlReg(Adapter, 0, BIT4);
PlatformEFIOWrite1Byte(Adapter, REG_FWHW_TXQ_CTRL+2, (pHalData->RegFwHwTxQCtrl|BIT6));
pHalData->RegFwHwTxQCtrl |= BIT6;
u1bTmp = PlatformEFIORead1Byte(Adapter, REG_CR+1);
PlatformEFIOWrite1Byte(Adapter, REG_CR+1, (u1bTmp&(~BIT0)));
return ret;
}
int _WriteBTFWtoTxPktBuf8812(
PADAPTER Adapter,
PVOID buffer,
u4Byte FwBufLen,
u1Byte times
)
{
int rtStatus = _SUCCESS;
//u4Byte value32;
//u1Byte numHQ, numLQ, numPubQ;//, txpktbuf_bndy;
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
//PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
u1Byte BcnValidReg;
u1Byte count=0, DLBcnCount=0;
pu1Byte FwbufferPtr = (pu1Byte)buffer;
//PRT_TCB pTcb, ptempTcb;
//PRT_TX_LOCAL_BUFFER pBuf;
BOOLEAN bRecover=_FALSE;
pu1Byte ReservedPagePacket = NULL;
pu1Byte pGenBufReservedPagePacket = NULL;
u4Byte TotalPktLen;
//u1Byte tmpReg422;
//u1Byte u1bTmp;
//u8 *pframe;
struct xmit_priv *pxmitpriv = &(Adapter->xmitpriv);
struct xmit_frame *pmgntframe;
struct pkt_attrib *pattrib;
u8 txdesc_offset = TXDESC_OFFSET;
u8 val8;
#if 1//(DEV_BUS_TYPE == RT_PCI_INTERFACE)
TotalPktLen = FwBufLen;
#else
TotalPktLen = FwBufLen+pHalData->HWDescHeadLength;
#endif
if((TotalPktLen+TXDESC_OFFSET) > MAX_CMDBUF_SZ) {
DBG_871X(" WARNING %s => Total packet len = %d over MAX_CMDBUF_SZ:%d \n"
,__FUNCTION__,(TotalPktLen+TXDESC_OFFSET),MAX_CMDBUF_SZ);
return _FAIL;
}
pGenBufReservedPagePacket = rtw_zmalloc(TotalPktLen);//GetGenTempBuffer (Adapter, TotalPktLen);
if (!pGenBufReservedPagePacket)
return _FAIL;
ReservedPagePacket = (u1Byte *)pGenBufReservedPagePacket;
_rtw_memset(ReservedPagePacket, 0, TotalPktLen);
#if 1//(DEV_BUS_TYPE == RT_PCI_INTERFACE)
_rtw_memcpy(ReservedPagePacket, FwbufferPtr, FwBufLen);
#else
PlatformMoveMemory(ReservedPagePacket+Adapter->HWDescHeadLength , FwbufferPtr, FwBufLen);
#endif
//---------------------------------------------------------
// 1. Pause BCN
//---------------------------------------------------------
//Set REG_CR bit 8. DMA beacon by SW.
#if 0//(DEV_BUS_TYPE == RT_PCI_INTERFACE)
u1bTmp = PlatformEFIORead1Byte(Adapter, REG_CR+1);
PlatformEFIOWrite1Byte(Adapter, REG_CR+1, (u1bTmp|BIT0));
#else
// Remove for temparaily because of the code on v2002 is not sync to MERGE_TMEP for USB/SDIO.
// De not remove this part on MERGE_TEMP. by tynli.
//pHalData->RegCR_1 |= (BIT0);
//PlatformEFIOWrite1Byte(Adapter, REG_CR+1, pHalData->RegCR_1);
#endif
// Disable Hw protection for a time which revserd for Hw sending beacon.
// Fix download reserved page packet fail that access collision with the protection time.
// 2010.05.11. Added by tynli.
val8 = rtw_read8(Adapter, REG_BCN_CTRL);
val8 &= ~BIT(3);
val8 |= BIT(4);
rtw_write8(Adapter, REG_BCN_CTRL, val8);
#if 0//(DEV_BUS_TYPE == RT_PCI_INTERFACE)
tmpReg422 = PlatformEFIORead1Byte(Adapter, REG_FWHW_TXQ_CTRL+2);
if( tmpReg422&BIT6)
bRecover = TRUE;
PlatformEFIOWrite1Byte(Adapter, REG_FWHW_TXQ_CTRL+2, tmpReg422&(~BIT6));
#else
// Set FWHW_TXQ_CTRL 0x422[6]=0 to tell Hw the packet is not a real beacon frame.
if(pHalData->RegFwHwTxQCtrl & BIT(6))
bRecover=_TRUE;
PlatformEFIOWrite1Byte(Adapter, REG_FWHW_TXQ_CTRL+2, (pHalData->RegFwHwTxQCtrl&(~BIT(6))));
pHalData->RegFwHwTxQCtrl &= (~ BIT(6));
#endif
//---------------------------------------------------------
// 2. Adjust LLT table to an even boundary.
//---------------------------------------------------------
#if 0//(DEV_BUS_TYPE == RT_SDIO_INTERFACE)
txpktbuf_bndy = 10; // rsvd page start address should be an even value.
rtStatus = InitLLTTable8723BS(Adapter, txpktbuf_bndy);
if(RT_STATUS_SUCCESS != rtStatus) {
DBG_8192C("_CheckWLANFwPatchBTFwReady_8723B(): Failed to init LLT!\n");
return RT_STATUS_FAILURE;
}
// Init Tx boundary.
PlatformEFIOWrite1Byte(Adapter, REG_DWBCN0_CTRL_8723B+1, (u1Byte)txpktbuf_bndy);
#endif
//---------------------------------------------------------
// 3. Write Fw to Tx packet buffer by reseverd page.
//---------------------------------------------------------
do {
// download rsvd page.
// Clear beacon valid check bit.
BcnValidReg = PlatformEFIORead1Byte(Adapter, REG_TDECTRL+2);
PlatformEFIOWrite1Byte(Adapter, REG_TDECTRL+2, BcnValidReg&(~BIT(0)));
//BT patch is big, we should set 0x209 < 0x40 suggested from Gimmy
RT_TRACE(_module_mp_, _drv_info_,("0x209:%x\n",
PlatformEFIORead1Byte(Adapter, REG_TDECTRL+1)));//209 < 0x40
PlatformEFIOWrite1Byte(Adapter, REG_TDECTRL+1, (0x90-0x20*(times-1)));
DBG_871X("0x209:0x%x\n", PlatformEFIORead1Byte(Adapter, REG_TDECTRL+1));
RT_TRACE(_module_mp_, _drv_info_,("0x209:%x\n",
PlatformEFIORead1Byte(Adapter, REG_TDECTRL+1)));
#if 0
// Acquice TX spin lock before GetFwBuf and send the packet to prevent system deadlock.
// Advertised by Roger. Added by tynli. 2010.02.22.
PlatformAcquireSpinLock(Adapter, RT_TX_SPINLOCK);
if(MgntGetFWBuffer(Adapter, &pTcb, &pBuf)) {
PlatformMoveMemory(pBuf->Buffer.VirtualAddress, ReservedPagePacket, TotalPktLen);
CmdSendPacket(Adapter, pTcb, pBuf, TotalPktLen, DESC_PACKET_TYPE_NORMAL, FALSE);
} else
dbgdump("SetFwRsvdPagePkt(): MgntGetFWBuffer FAIL!!!!!!!!.\n");
PlatformReleaseSpinLock(Adapter, RT_TX_SPINLOCK);
#else
/*---------------------------------------------------------
tx reserved_page_packet
----------------------------------------------------------*/
if ((pmgntframe = rtw_alloc_cmdxmitframe(pxmitpriv)) == NULL) {
rtStatus = _FAIL;
goto exit;
}
//update attribute
pattrib = &pmgntframe->attrib;
update_mgntframe_attrib(Adapter, pattrib);
pattrib->qsel = QSLT_BEACON;
pattrib->pktlen = pattrib->last_txcmdsz = FwBufLen ;
//_rtw_memset(pmgntframe->buf_addr, 0, TotalPktLen+txdesc_size);
//pmgntframe->buf_addr = ReservedPagePacket ;
_rtw_memcpy( (u8*) (pmgntframe->buf_addr + txdesc_offset), ReservedPagePacket, FwBufLen);
DBG_871X("[%d]===>TotalPktLen + TXDESC_OFFSET TotalPacketLen:%d \n", DLBcnCount, (FwBufLen + txdesc_offset));
#ifdef CONFIG_PCI_HCI
dump_mgntframe(Adapter, pmgntframe);
#else
dump_mgntframe_and_wait(Adapter, pmgntframe, 100);
#endif
#endif
#if 1
// check rsvd page download OK.
BcnValidReg = PlatformEFIORead1Byte(Adapter, REG_TDECTRL+2);
while(!(BcnValidReg & BIT(0)) && count <200) {
count++;
//PlatformSleepUs(10);
rtw_msleep_os(1);
BcnValidReg = PlatformEFIORead1Byte(Adapter, REG_TDECTRL+2);
RT_TRACE(_module_mp_, _drv_notice_,("Poll 0x20A = %x\n", BcnValidReg));
}
DLBcnCount++;
//DBG_871X("##0x208:%08x,0x210=%08x\n",PlatformEFIORead4Byte(Adapter, REG_TDECTRL),PlatformEFIORead4Byte(Adapter, 0x210));
PlatformEFIOWrite1Byte(Adapter, REG_TDECTRL+2,BcnValidReg);
} while((!(BcnValidReg&BIT(0))) && DLBcnCount<5);
#endif
if(DLBcnCount >=5) {
DBG_871X(" check rsvd page download OK DLBcnCount =%d \n",DLBcnCount);
rtStatus = _FAIL;
goto exit;
}
if(!(BcnValidReg&BIT(0))) {
DBG_871X("_WriteFWtoTxPktBuf(): 1 Download RSVD page failed!\n");
rtStatus = _FAIL;
goto exit;
}
//---------------------------------------------------------
// 4. Set Tx boundary to the initial value
//---------------------------------------------------------
//---------------------------------------------------------
// 5. Reset beacon setting to the initial value.
// After _CheckWLANFwPatchBTFwReady().
//---------------------------------------------------------
exit:
if(pGenBufReservedPagePacket) {
DBG_871X("_WriteBTFWtoTxPktBuf8723B => rtw_mfree pGenBufReservedPagePacket!\n");
rtw_mfree((u8*)pGenBufReservedPagePacket, TotalPktLen);
}
return rtStatus;
}
int ReservedPage_Compare(PADAPTER Adapter,PRT_MP_FIRMWARE pFirmware,u32 BTPatchSize)
{
u8 temp,ret,lastBTsz;
u32 u1bTmp=0,address_start=0,count=0,i=0;
u8 *myBTFwBuffer = NULL;
myBTFwBuffer = rtw_zmalloc(BTPatchSize);
if (myBTFwBuffer == NULL) {
DBG_871X("%s can't be executed due to the failed malloc.\n", __FUNCTION__);
Adapter->mppriv.bTxBufCkFail=_TRUE;
return _FALSE;
}
temp=rtw_read8(Adapter,0x209);