1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
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.
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
14 ******************************************************************************/
17 #include <linux/firmware.h>
18 #include <drv_types.h>
19 #include <rtw_efuse.h>
21 #include <rtl8723a_hal.h>
22 #include <usb_ops_linux.h>
24 static void _FWDownloadEnable(struct rtw_adapter
*padapter
, bool enable
)
30 tmp
= rtl8723au_read8(padapter
, REG_SYS_FUNC_EN
+ 1);
31 rtl8723au_write8(padapter
, REG_SYS_FUNC_EN
+ 1, tmp
| 0x04);
33 /* MCU firmware download enable. */
34 tmp
= rtl8723au_read8(padapter
, REG_MCUFWDL
);
35 rtl8723au_write8(padapter
, REG_MCUFWDL
, tmp
| 0x01);
38 tmp
= rtl8723au_read8(padapter
, REG_MCUFWDL
+ 2);
39 rtl8723au_write8(padapter
, REG_MCUFWDL
+ 2, tmp
& 0xf7);
41 /* MCU firmware download disable. */
42 tmp
= rtl8723au_read8(padapter
, REG_MCUFWDL
);
43 rtl8723au_write8(padapter
, REG_MCUFWDL
, tmp
& 0xfe);
45 /* Reserved for fw extension. */
46 rtl8723au_write8(padapter
, REG_MCUFWDL
+ 1, 0x00);
50 static int _BlockWrite(struct rtw_adapter
*padapter
, void *buffer
, u32 buffSize
)
53 /* (Default) Phase #1 : PCI muse use 4-byte write to download FW */
55 /* Phase #2 : Use 8-byte, if Phase#1 use big size to write FW. */
57 /* Phase #3 : Use 1-byte, the remnant of FW image. */
59 u32 blockCount_p1
= 0, blockCount_p2
= 0, blockCount_p3
= 0;
60 u32 remainSize_p1
= 0, remainSize_p2
= 0;
61 u8
*bufferPtr
= (u8
*) buffer
;
62 u32 i
= 0, offset
= 0;
67 blockCount_p1
= buffSize
/ blockSize_p1
;
68 remainSize_p1
= buffSize
% blockSize_p1
;
71 RT_TRACE(_module_hal_init_c_
, _drv_notice_
,
72 ("_BlockWrite: [P1] buffSize(%d) blockSize_p1(%d) "
73 "blockCount_p1(%d) remainSize_p1(%d)\n",
74 buffSize
, blockSize_p1
, blockCount_p1
,
78 for (i
= 0; i
< blockCount_p1
; i
++) {
79 ret
= rtl8723au_writeN(padapter
, (FW_8723A_START_ADDRESS
+
82 (bufferPtr
+ i
* blockSize_p1
));
89 offset
= blockCount_p1
* blockSize_p1
;
91 blockCount_p2
= remainSize_p1
/ blockSize_p2
;
92 remainSize_p2
= remainSize_p1
% blockSize_p2
;
95 RT_TRACE(_module_hal_init_c_
, _drv_notice_
,
96 ("_BlockWrite: [P2] buffSize_p2(%d) "
97 "blockSize_p2(%d) blockCount_p2(%d) "
98 "remainSize_p2(%d)\n",
99 (buffSize
- offset
), blockSize_p2
,
100 blockCount_p2
, remainSize_p2
));
103 for (i
= 0; i
< blockCount_p2
; i
++) {
104 ret
= rtl8723au_writeN(padapter
,
105 (FW_8723A_START_ADDRESS
+
106 offset
+ i
* blockSize_p2
),
108 (bufferPtr
+ offset
+
118 offset
= (blockCount_p1
* blockSize_p1
) +
119 (blockCount_p2
* blockSize_p2
);
121 blockCount_p3
= remainSize_p2
/ blockSize_p3
;
123 RT_TRACE(_module_hal_init_c_
, _drv_notice_
,
124 ("_BlockWrite: [P3] buffSize_p3(%d) blockSize_p3(%d) "
125 "blockCount_p3(%d)\n",
126 (buffSize
- offset
), blockSize_p3
, blockCount_p3
));
128 for (i
= 0; i
< blockCount_p3
; i
++) {
129 ret
= rtl8723au_write8(padapter
,
130 (FW_8723A_START_ADDRESS
+ offset
+ i
),
131 *(bufferPtr
+ offset
+ i
));
143 _PageWrite(struct rtw_adapter
*padapter
, u32 page
, void *buffer
, u32 size
)
146 u8 u8Page
= (u8
) (page
& 0x07);
148 value8
= (rtl8723au_read8(padapter
, REG_MCUFWDL
+ 2) & 0xF8) | u8Page
;
149 rtl8723au_write8(padapter
, REG_MCUFWDL
+ 2, value8
);
151 return _BlockWrite(padapter
, buffer
, size
);
154 static int _WriteFW(struct rtw_adapter
*padapter
, void *buffer
, u32 size
)
156 /* Since we need dynamic decide method of dwonload fw, so we
157 call this function to get chip version. */
158 /* We can remove _ReadChipVersion from ReadpadapterInfo8192C later. */
160 u32 pageNums
, remainSize
;
162 u8
*bufferPtr
= (u8
*) buffer
;
164 pageNums
= size
/ MAX_PAGE_SIZE
;
165 /* RT_ASSERT((pageNums <= 4),
166 ("Page numbers should not greater then 4 \n")); */
167 remainSize
= size
% MAX_PAGE_SIZE
;
169 for (page
= 0; page
< pageNums
; page
++) {
170 offset
= page
* MAX_PAGE_SIZE
;
171 ret
= _PageWrite(padapter
, page
, bufferPtr
+ offset
,
178 offset
= pageNums
* MAX_PAGE_SIZE
;
180 ret
= _PageWrite(padapter
, page
, bufferPtr
+ offset
,
186 RT_TRACE(_module_hal_init_c_
, _drv_info_
,
187 ("_WriteFW Done- for Normal chip.\n"));
193 static int _FWFreeToGo(struct rtw_adapter
*padapter
)
198 /* polling CheckSum report */
200 value32
= rtl8723au_read32(padapter
, REG_MCUFWDL
);
201 if (value32
& FWDL_ChkSum_rpt
)
203 } while (counter
++ < POLLING_READY_TIMEOUT_COUNT
);
205 if (counter
>= POLLING_READY_TIMEOUT_COUNT
) {
206 RT_TRACE(_module_hal_init_c_
, _drv_err_
,
207 ("%s: chksum report fail! REG_MCUFWDL:0x%08x\n",
211 RT_TRACE(_module_hal_init_c_
, _drv_info_
,
212 ("%s: Checksum report OK! REG_MCUFWDL:0x%08x\n", __func__
,
215 value32
= rtl8723au_read32(padapter
, REG_MCUFWDL
);
216 value32
|= MCUFWDL_RDY
;
217 value32
&= ~WINTINI_RDY
;
218 rtl8723au_write32(padapter
, REG_MCUFWDL
, value32
);
220 /* polling for FW ready */
223 value32
= rtl8723au_read32(padapter
, REG_MCUFWDL
);
224 if (value32
& WINTINI_RDY
) {
225 RT_TRACE(_module_hal_init_c_
, _drv_info_
,
226 ("%s: Polling FW ready success!! "
227 "REG_MCUFWDL:0x%08x\n",
232 } while (counter
++ < POLLING_READY_TIMEOUT_COUNT
);
234 RT_TRACE(_module_hal_init_c_
, _drv_err_
,
235 ("%s: Polling FW ready fail!! REG_MCUFWDL:0x%08x\n",
240 #define IS_FW_81xxC(padapter) (((GET_HAL_DATA(padapter))->FirmwareSignature & 0xFFF0) == 0x88C0)
242 void rtl8723a_FirmwareSelfReset(struct rtw_adapter
*padapter
)
244 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
248 if (!(IS_FW_81xxC(padapter
) &&
249 ((pHalData
->FirmwareVersion
< 0x21) ||
250 (pHalData
->FirmwareVersion
== 0x21 &&
251 pHalData
->FirmwareSubVersion
< 0x01)))) {
252 /* after 88C Fw v33.1 */
253 /* 0x1cf = 0x20. Inform 8051 to reset. 2009.12.25. tynli_test */
254 rtl8723au_write8(padapter
, REG_HMETFR
+ 3, 0x20);
256 u1bTmp
= rtl8723au_read8(padapter
, REG_SYS_FUNC_EN
+ 1);
257 while (u1bTmp
& BIT(2)) {
262 u1bTmp
= rtl8723au_read8(padapter
, REG_SYS_FUNC_EN
+ 1);
264 RT_TRACE(_module_hal_init_c_
, _drv_info_
,
265 ("-%s: 8051 reset success (%d)\n", __func__
,
269 /* force firmware reset */
270 u1bTmp
= rtl8723au_read8(padapter
, REG_SYS_FUNC_EN
+ 1);
271 rtl8723au_write8(padapter
, REG_SYS_FUNC_EN
+ 1,
279 /* Download 8192C firmware code. */
282 int rtl8723a_FirmwareDownload(struct rtw_adapter
*padapter
)
284 int rtStatus
= _SUCCESS
;
285 u8 writeFW_retry
= 0;
286 unsigned long fwdl_start_time
;
287 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
288 struct dvobj_priv
*dvobj
= adapter_to_dvobj(padapter
);
289 struct device
*device
= dvobj_to_dev(dvobj
);
290 struct rt_8723a_firmware_hdr
*pFwHdr
= NULL
;
291 const struct firmware
*fw
;
293 u8
*firmware_buf
= NULL
;
296 static int log_version
;
298 RT_TRACE(_module_hal_init_c_
, _drv_info_
, ("+%s\n", __func__
));
300 if (IS_8723A_A_CUT(pHalData
->VersionID
)) {
301 fw_name
= "rtlwifi/rtl8723aufw_A.bin";
302 RT_TRACE(_module_hal_init_c_
, _drv_info_
,
303 ("rtl8723a_FirmwareDownload: R8723FwImageArray_UMC "
304 "for RTL8723A A CUT\n"));
305 } else if (IS_8723A_B_CUT(pHalData
->VersionID
)) {
307 if (padapter
->registrypriv
.wifi_spec
== 1) {
308 fw_name
= "rtlwifi/rtl8723aufw_B_NoBT.bin";
309 DBG_8723A(" Rtl8723_FwUMCBCutImageArrayWithoutBT for "
312 if (rtl8723a_BT_coexist(padapter
)) {
313 fw_name
= "rtlwifi/rtl8723aufw_B.bin";
314 DBG_8723A(" Rtl8723_FwUMCBCutImageArrayWithBT "
315 "for RTL8723A B CUT\n");
317 fw_name
= "rtlwifi/rtl8723aufw_B_NoBT.bin";
318 DBG_8723A(" Rtl8723_FwUMCBCutImageArrayWithout "
319 "BT for RTL8723A B CUT\n");
323 /* <Roger_TODO> We should download proper RAM Code here
324 to match the ROM code. */
325 RT_TRACE(_module_hal_init_c_
, _drv_err_
,
326 ("%s: unknow version!\n", __func__
));
331 pr_info("rtl8723au: Loading firmware %s\n", fw_name
);
332 if (request_firmware(&fw
, fw_name
, device
)) {
333 pr_err("rtl8723au: request_firmware load failed\n");
338 pr_err("rtl8723au: Firmware %s not available\n", fw_name
);
342 firmware_buf
= kmemdup(fw
->data
, fw
->size
, GFP_KERNEL
);
349 release_firmware(fw
);
351 /* To Check Fw header. Added by tynli. 2009.12.04. */
352 pFwHdr
= (struct rt_8723a_firmware_hdr
*)firmware_buf
;
354 pHalData
->FirmwareVersion
= le16_to_cpu(pFwHdr
->Version
);
355 pHalData
->FirmwareSubVersion
= pFwHdr
->Subversion
;
356 pHalData
->FirmwareSignature
= le16_to_cpu(pFwHdr
->Signature
);
358 DBG_8723A("%s: fw_ver =%d fw_subver =%d sig = 0x%x\n",
359 __func__
, pHalData
->FirmwareVersion
,
360 pHalData
->FirmwareSubVersion
, pHalData
->FirmwareSignature
);
363 pr_info("%sFirmware Version %d, SubVersion %d, Signature "
364 "0x%x\n", DRIVER_PREFIX
, pHalData
->FirmwareVersion
,
365 pHalData
->FirmwareSubVersion
,
366 pHalData
->FirmwareSignature
);
368 if (IS_FW_HEADER_EXIST(pFwHdr
)) {
369 /* Shift 32 bytes for FW header */
371 fw_size
= fw_size
- 32;
374 /* Suggested by Filen. If 8051 is running in RAM code, driver should
375 inform Fw to reset by itself, */
376 /* or it will cause download Fw fail. 2010.02.01. by tynli. */
377 if (rtl8723au_read8(padapter
, REG_MCUFWDL
) & RAM_DL_SEL
) {
379 rtl8723a_FirmwareSelfReset(padapter
);
380 rtl8723au_write8(padapter
, REG_MCUFWDL
, 0x00);
383 _FWDownloadEnable(padapter
, true);
384 fwdl_start_time
= jiffies
;
386 /* reset the FWDL chksum */
387 rtl8723au_write8(padapter
, REG_MCUFWDL
,
388 rtl8723au_read8(padapter
, REG_MCUFWDL
) |
391 rtStatus
= _WriteFW(padapter
, buf
, fw_size
);
393 if (rtStatus
== _SUCCESS
||
394 (jiffies_to_msecs(jiffies
- fwdl_start_time
) > 500 &&
395 writeFW_retry
++ >= 3))
398 DBG_8723A("%s writeFW_retry:%u, time after fwdl_start_time:"
399 "%ums\n", __func__
, writeFW_retry
,
400 jiffies_to_msecs(jiffies
- fwdl_start_time
));
402 _FWDownloadEnable(padapter
, false);
403 if (_SUCCESS
!= rtStatus
) {
404 DBG_8723A("DL Firmware failed!\n");
408 rtStatus
= _FWFreeToGo(padapter
);
409 if (_SUCCESS
!= rtStatus
) {
410 RT_TRACE(_module_hal_init_c_
, _drv_err_
,
411 ("DL Firmware failed!\n"));
414 RT_TRACE(_module_hal_init_c_
, _drv_info_
,
415 ("Firmware is ready to run!\n"));
422 void rtl8723a_InitializeFirmwareVars(struct rtw_adapter
*padapter
)
424 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
426 /* Init Fw LPS related. */
427 padapter
->pwrctrlpriv
.bFwCurrentInPSMode
= false;
429 /* Init H2C counter. by tynli. 2009.12.09. */
430 pHalData
->LastHMEBoxNum
= 0;
434 /* Efuse related code */
437 hal_EfuseSwitchToBank(struct rtw_adapter
*padapter
, u8 bank
)
442 DBG_8723A("%s: Efuse switch bank to %d\n", __func__
, bank
);
443 value32
= rtl8723au_read32(padapter
, EFUSE_TEST
);
447 value32
= (value32
& ~EFUSE_SEL_MASK
) |
448 EFUSE_SEL(EFUSE_WIFI_SEL_0
);
451 value32
= (value32
& ~EFUSE_SEL_MASK
) |
452 EFUSE_SEL(EFUSE_BT_SEL_0
);
455 value32
= (value32
& ~EFUSE_SEL_MASK
) |
456 EFUSE_SEL(EFUSE_BT_SEL_1
);
459 value32
= (value32
& ~EFUSE_SEL_MASK
) |
460 EFUSE_SEL(EFUSE_BT_SEL_2
);
463 value32
= (value32
& ~EFUSE_SEL_MASK
) |
464 EFUSE_SEL(EFUSE_WIFI_SEL_0
);
468 rtl8723au_write32(padapter
, EFUSE_TEST
, value32
);
474 hal_ReadEFuse_WiFi(struct rtw_adapter
*padapter
,
475 u16 _offset
, u16 _size_byte
, u8
*pbuf
)
480 u8 efuseHeader
, efuseExtHdr
, efuseData
;
482 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
484 /* Do NOT excess total size of EFuse table.
485 Added by Roger, 2008.11.10. */
486 if ((_offset
+ _size_byte
) > EFUSE_MAP_LEN_8723A
) {
487 DBG_8723A("%s: Invalid offset(%#x) with read bytes(%#x)!!\n",
488 __func__
, _offset
, _size_byte
);
492 efuseTbl
= kmalloc(EFUSE_MAP_LEN_8723A
, GFP_KERNEL
);
493 if (efuseTbl
== NULL
) {
494 DBG_8723A("%s: alloc efuseTbl fail!\n", __func__
);
497 /* 0xff will be efuse default value instead of 0x00. */
498 memset(efuseTbl
, 0xFF, EFUSE_MAP_LEN_8723A
);
500 /* switch bank back to bank 0 for later BT and wifi use. */
501 hal_EfuseSwitchToBank(padapter
, 0);
503 while (AVAILABLE_EFUSE_ADDR(eFuse_Addr
)) {
504 ReadEFuseByte23a(padapter
, eFuse_Addr
++, &efuseHeader
);
505 if (efuseHeader
== 0xFF) {
506 DBG_8723A("%s: data end at address =%#x\n", __func__
,
511 /* Check PG header for section num. */
512 if (EXT_HEADER(efuseHeader
)) { /* extended header */
513 offset
= GET_HDR_OFFSET_2_0(efuseHeader
);
515 ReadEFuseByte23a(padapter
, eFuse_Addr
++, &efuseExtHdr
);
516 if (ALL_WORDS_DISABLED(efuseExtHdr
)) {
520 offset
|= ((efuseExtHdr
& 0xF0) >> 1);
521 wden
= (efuseExtHdr
& 0x0F);
523 offset
= ((efuseHeader
>> 4) & 0x0f);
524 wden
= (efuseHeader
& 0x0f);
527 if (offset
< EFUSE_MAX_SECTION_8723A
) {
529 /* Get word enable value from PG header */
531 addr
= offset
* PGPKT_DATA_SIZE
;
532 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++) {
533 /* Check word enable condition in the section */
534 if (!(wden
& (0x01 << i
))) {
535 ReadEFuseByte23a(padapter
, eFuse_Addr
++,
537 efuseTbl
[addr
] = efuseData
;
539 ReadEFuseByte23a(padapter
, eFuse_Addr
++,
541 efuseTbl
[addr
+ 1] = efuseData
;
546 DBG_8723A(KERN_ERR
"%s: offset(%d) is illegal!!\n",
548 eFuse_Addr
+= Efuse_CalculateWordCnts23a(wden
) * 2;
552 /* Copy from Efuse map to output pointer memory!!! */
553 for (i
= 0; i
< _size_byte
; i
++)
554 pbuf
[i
] = efuseTbl
[_offset
+ i
];
556 /* Calculate Efuse utilization */
557 EFUSE_GetEfuseDefinition23a(padapter
, EFUSE_WIFI
,
558 TYPE_AVAILABLE_EFUSE_BYTES_TOTAL
, &total
);
559 used
= eFuse_Addr
- 1;
560 pHalData
->EfuseUsedBytes
= used
;
566 hal_ReadEFuse_BT(struct rtw_adapter
*padapter
,
567 u16 _offset
, u16 _size_byte
, u8
*pbuf
)
572 u8 efuseHeader
, efuseExtHdr
, efuseData
;
575 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
577 /* Do NOT excess total size of EFuse table.
578 Added by Roger, 2008.11.10. */
579 if ((_offset
+ _size_byte
) > EFUSE_BT_MAP_LEN
) {
580 DBG_8723A("%s: Invalid offset(%#x) with read bytes(%#x)!!\n",
581 __func__
, _offset
, _size_byte
);
585 efuseTbl
= kmalloc(EFUSE_BT_MAP_LEN
, GFP_KERNEL
);
586 if (efuseTbl
== NULL
) {
587 DBG_8723A("%s: efuseTbl malloc fail!\n", __func__
);
590 /* 0xff will be efuse default value instead of 0x00. */
591 memset(efuseTbl
, 0xFF, EFUSE_BT_MAP_LEN
);
593 EFUSE_GetEfuseDefinition23a(padapter
, EFUSE_BT
,
594 TYPE_AVAILABLE_EFUSE_BYTES_BANK
, &total
);
596 for (bank
= 1; bank
< EFUSE_MAX_BANK
; bank
++) {
597 if (hal_EfuseSwitchToBank(padapter
, bank
) == false) {
598 DBG_8723A("%s: hal_EfuseSwitchToBank Fail!!\n",
605 while (AVAILABLE_EFUSE_ADDR(eFuse_Addr
)) {
606 ReadEFuseByte23a(padapter
, eFuse_Addr
++, &efuseHeader
);
607 if (efuseHeader
== 0xFF)
610 /* Check PG header for section num. */
611 if (EXT_HEADER(efuseHeader
)) { /* extended header */
612 offset
= GET_HDR_OFFSET_2_0(efuseHeader
);
614 ReadEFuseByte23a(padapter
, eFuse_Addr
++,
616 if (ALL_WORDS_DISABLED(efuseExtHdr
)) {
620 offset
|= ((efuseExtHdr
& 0xF0) >> 1);
621 wden
= (efuseExtHdr
& 0x0F);
623 offset
= ((efuseHeader
>> 4) & 0x0f);
624 wden
= (efuseHeader
& 0x0f);
627 if (offset
< EFUSE_BT_MAX_SECTION
) {
630 /* Get word enable value from PG header */
632 addr
= offset
* PGPKT_DATA_SIZE
;
633 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++) {
634 /* Check word enable condition in
636 if (!(wden
& (0x01 << i
))) {
637 ReadEFuseByte23a(padapter
,
640 efuseTbl
[addr
] = efuseData
;
642 ReadEFuseByte23a(padapter
,
645 efuseTbl
[addr
+ 1] = efuseData
;
651 "%s: offset(%d) is illegal!!\n",
653 eFuse_Addr
+= Efuse_CalculateWordCnts23a(wden
) * 2;
657 if ((eFuse_Addr
- 1) < total
) {
658 DBG_8723A("%s: bank(%d) data end at %#x\n",
659 __func__
, bank
, eFuse_Addr
- 1);
664 /* switch bank back to bank 0 for later BT and wifi use. */
665 hal_EfuseSwitchToBank(padapter
, 0);
667 /* Copy from Efuse map to output pointer memory!!! */
668 for (i
= 0; i
< _size_byte
; i
++)
669 pbuf
[i
] = efuseTbl
[_offset
+ i
];
672 /* Calculate Efuse utilization. */
674 EFUSE_GetEfuseDefinition23a(padapter
, EFUSE_BT
,
675 TYPE_AVAILABLE_EFUSE_BYTES_TOTAL
, &total
);
676 used
= (EFUSE_BT_REAL_BANK_CONTENT_LEN
* (bank
- 1)) + eFuse_Addr
- 1;
677 pHalData
->BTEfuseUsedBytes
= used
;
684 rtl8723a_readefuse(struct rtw_adapter
*padapter
,
685 u8 efuseType
, u16 _offset
, u16 _size_byte
, u8
*pbuf
)
687 if (efuseType
== EFUSE_WIFI
)
688 hal_ReadEFuse_WiFi(padapter
, _offset
, _size_byte
, pbuf
);
690 hal_ReadEFuse_BT(padapter
, _offset
, _size_byte
, pbuf
);
693 u16
rtl8723a_EfuseGetCurrentSize_WiFi(struct rtw_adapter
*padapter
)
696 u8 hoffset
= 0, hworden
= 0;
697 u8 efuse_data
, word_cnts
= 0;
698 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
700 efuse_addr
= pHalData
->EfuseUsedBytes
;
702 DBG_8723A("%s: start_efuse_addr = 0x%X\n", __func__
, efuse_addr
);
704 /* switch bank back to bank 0 for later BT and wifi use. */
705 hal_EfuseSwitchToBank(padapter
, 0);
707 while (AVAILABLE_EFUSE_ADDR(efuse_addr
)) {
708 if (efuse_OneByteRead23a(padapter
, efuse_addr
, &efuse_data
) ==
710 DBG_8723A(KERN_ERR
"%s: efuse_OneByteRead23a Fail! "
711 "addr = 0x%X !!\n", __func__
, efuse_addr
);
715 if (efuse_data
== 0xFF)
718 if (EXT_HEADER(efuse_data
)) {
719 hoffset
= GET_HDR_OFFSET_2_0(efuse_data
);
721 efuse_OneByteRead23a(padapter
, efuse_addr
, &efuse_data
);
722 if (ALL_WORDS_DISABLED(efuse_data
)) {
726 hoffset
|= ((efuse_data
& 0xF0) >> 1);
727 hworden
= efuse_data
& 0x0F;
729 hoffset
= (efuse_data
>> 4) & 0x0F;
730 hworden
= efuse_data
& 0x0F;
733 word_cnts
= Efuse_CalculateWordCnts23a(hworden
);
734 efuse_addr
+= (word_cnts
* 2) + 1;
737 pHalData
->EfuseUsedBytes
= efuse_addr
;
739 DBG_8723A("%s: CurrentSize =%d\n", __func__
, efuse_addr
);
744 u16
rtl8723a_EfuseGetCurrentSize_BT(struct rtw_adapter
*padapter
)
749 u8 hoffset
= 0, hworden
= 0;
750 u8 efuse_data
, word_cnts
= 0;
752 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
754 btusedbytes
= pHalData
->BTEfuseUsedBytes
;
756 efuse_addr
= (u16
) ((btusedbytes
% EFUSE_BT_REAL_BANK_CONTENT_LEN
));
757 startBank
= (u8
) (1 + (btusedbytes
/ EFUSE_BT_REAL_BANK_CONTENT_LEN
));
759 DBG_8723A("%s: start from bank =%d addr = 0x%X\n", __func__
, startBank
,
762 EFUSE_GetEfuseDefinition23a(padapter
, EFUSE_BT
,
763 TYPE_AVAILABLE_EFUSE_BYTES_BANK
, &retU2
);
765 for (bank
= startBank
; bank
< EFUSE_MAX_BANK
; bank
++) {
766 if (hal_EfuseSwitchToBank(padapter
, bank
) == false) {
767 DBG_8723A(KERN_ERR
"%s: switch bank(%d) Fail!!\n",
769 bank
= EFUSE_MAX_BANK
;
773 /* only when bank is switched we have to reset
775 if (bank
!= startBank
)
778 while (AVAILABLE_EFUSE_ADDR(efuse_addr
)) {
779 if (efuse_OneByteRead23a(padapter
, efuse_addr
,
780 &efuse_data
) == _FAIL
) {
781 DBG_8723A(KERN_ERR
"%s: efuse_OneByteRead23a Fail!"
783 __func__
, efuse_addr
);
784 bank
= EFUSE_MAX_BANK
;
788 if (efuse_data
== 0xFF)
791 if (EXT_HEADER(efuse_data
)) {
792 hoffset
= GET_HDR_OFFSET_2_0(efuse_data
);
794 efuse_OneByteRead23a(padapter
, efuse_addr
,
796 if (ALL_WORDS_DISABLED(efuse_data
)) {
801 hoffset
|= ((efuse_data
& 0xF0) >> 1);
802 hworden
= efuse_data
& 0x0F;
804 hoffset
= (efuse_data
>> 4) & 0x0F;
805 hworden
= efuse_data
& 0x0F;
807 word_cnts
= Efuse_CalculateWordCnts23a(hworden
);
808 /* read next header */
809 efuse_addr
+= (word_cnts
* 2) + 1;
812 /* Check if we need to check next bank efuse */
813 if (efuse_addr
< retU2
) {
814 break; /* don't need to check next bank. */
818 retU2
= ((bank
- 1) * EFUSE_BT_REAL_BANK_CONTENT_LEN
) + efuse_addr
;
819 pHalData
->BTEfuseUsedBytes
= retU2
;
821 DBG_8723A("%s: CurrentSize =%d\n", __func__
, retU2
);
826 rtl8723a_EfusePgPacketRead(struct rtw_adapter
*padapter
, u8 offset
, u8
*data
)
828 u8 efuse_data
, word_cnts
= 0;
830 u8 hoffset
= 0, hworden
= 0;
838 EFUSE_GetEfuseDefinition23a(padapter
, EFUSE_WIFI
, TYPE_EFUSE_MAX_SECTION
,
840 if (offset
> max_section
) {
841 DBG_8723A("%s: Packet offset(%d) is illegal(>%d)!\n",
842 __func__
, offset
, max_section
);
846 memset(data
, 0xFF, PGPKT_DATA_SIZE
);
850 /* <Roger_TODO> Efuse has been pre-programmed dummy 5Bytes at the
851 end of Efuse by CP. */
852 /* Skip dummy parts to prevent unexpected data read from Efuse. */
853 /* By pass right now. 2009.02.19. */
855 while (AVAILABLE_EFUSE_ADDR(efuse_addr
)) {
856 if (efuse_OneByteRead23a(padapter
, efuse_addr
++, &efuse_data
) ==
862 if (efuse_data
== 0xFF)
865 if (EXT_HEADER(efuse_data
)) {
866 hoffset
= GET_HDR_OFFSET_2_0(efuse_data
);
867 efuse_OneByteRead23a(padapter
, efuse_addr
++, &efuse_data
);
868 if (ALL_WORDS_DISABLED(efuse_data
)) {
869 DBG_8723A("%s: Error!! All words disabled!\n",
874 hoffset
|= ((efuse_data
& 0xF0) >> 1);
875 hworden
= efuse_data
& 0x0F;
877 hoffset
= (efuse_data
>> 4) & 0x0F;
878 hworden
= efuse_data
& 0x0F;
881 if (hoffset
== offset
) {
882 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++) {
883 /* Check word enable condition in the section */
884 if (!(hworden
& (0x01 << i
))) {
885 ReadEFuseByte23a(padapter
, efuse_addr
++,
887 data
[i
* 2] = efuse_data
;
889 ReadEFuseByte23a(padapter
, efuse_addr
++,
891 data
[(i
* 2) + 1] = efuse_data
;
895 word_cnts
= Efuse_CalculateWordCnts23a(hworden
);
896 efuse_addr
+= word_cnts
* 2;
903 void rtl8723a_read_chip_version(struct rtw_adapter
*padapter
)
906 struct hal_version ChipVersion
;
907 struct hal_data_8723a
*pHalData
;
909 pHalData
= GET_HAL_DATA(padapter
);
911 value32
= rtl8723au_read32(padapter
, REG_SYS_CFG
);
912 ChipVersion
.ICType
= CHIP_8723A
;
913 ChipVersion
.ChipType
= ((value32
& RTL_ID
) ? TEST_CHIP
: NORMAL_CHIP
);
914 ChipVersion
.RFType
= RF_TYPE_1T1R
;
915 ChipVersion
.VendorType
=
916 ((value32
& VENDOR_ID
) ? CHIP_VENDOR_UMC
: CHIP_VENDOR_TSMC
);
917 ChipVersion
.CUTVersion
= (value32
& CHIP_VER_RTL_MASK
) >> CHIP_VER_RTL_SHIFT
; /* IC version (CUT) */
919 /* For regulator mode. by tynli. 2011.01.14 */
920 pHalData
->RegulatorMode
= ((value32
& SPS_SEL
) ?
921 RT_LDO_REGULATOR
: RT_SWITCHING_REGULATOR
);
923 value32
= rtl8723au_read32(padapter
, REG_GPIO_OUTSTS
);
924 /* ROM code version. */
925 ChipVersion
.ROMVer
= ((value32
& RF_RL_ID
) >> 20);
927 /* For multi-function consideration. Added by Roger, 2010.10.06. */
928 pHalData
->MultiFunc
= RT_MULTI_FUNC_NONE
;
929 value32
= rtl8723au_read32(padapter
, REG_MULTI_FUNC_CTRL
);
930 pHalData
->MultiFunc
|=
931 ((value32
& WL_FUNC_EN
) ? RT_MULTI_FUNC_WIFI
: 0);
932 pHalData
->MultiFunc
|= ((value32
& BT_FUNC_EN
) ? RT_MULTI_FUNC_BT
: 0);
933 pHalData
->MultiFunc
|=
934 ((value32
& GPS_FUNC_EN
) ? RT_MULTI_FUNC_GPS
: 0);
935 pHalData
->PolarityCtl
=
936 ((value32
& WL_HWPDN_SL
) ? RT_POLARITY_HIGH_ACT
:
937 RT_POLARITY_LOW_ACT
);
938 dump_chip_info23a(ChipVersion
);
939 pHalData
->VersionID
= ChipVersion
;
941 if (IS_1T2R(ChipVersion
))
942 pHalData
->rf_type
= RF_1T2R
;
943 else if (IS_2T2R(ChipVersion
))
944 pHalData
->rf_type
= RF_2T2R
;
946 pHalData
->rf_type
= RF_1T1R
;
948 MSG_8723A("RF_Type is %x!!\n", pHalData
->rf_type
);
953 /* 20100209 Joseph: */
954 /* This function is used only for 92C to set REG_BCN_CTRL(0x550) register. */
955 /* We just reserve the value of the register in variable
956 pHalData->RegBcnCtrlVal and then operate */
957 /* the value of the register via atomic operation. */
958 /* This prevents from race condition when setting this register. */
959 /* The value of pHalData->RegBcnCtrlVal is initialized in
960 HwConfigureRTL8192CE() function. */
962 void SetBcnCtrlReg23a(struct rtw_adapter
*padapter
, u8 SetBits
, u8 ClearBits
)
964 struct hal_data_8723a
*pHalData
;
968 pHalData
= GET_HAL_DATA(padapter
);
969 pRegBcnCtrlVal
= (u8
*)&pHalData
->RegBcnCtrlVal
;
973 *pRegBcnCtrlVal
= rtl8723au_read8(padapter
, addr
);
974 *pRegBcnCtrlVal
|= SetBits
;
975 *pRegBcnCtrlVal
&= ~ClearBits
;
977 rtl8723au_write8(padapter
, addr
, *pRegBcnCtrlVal
);
980 void rtl8723a_InitBeaconParameters(struct rtw_adapter
*padapter
)
982 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
984 rtl8723au_write16(padapter
, REG_BCN_CTRL
, 0x1010);
985 pHalData
->RegBcnCtrlVal
= 0x1010;
987 /* TODO: Remove these magic number */
988 rtl8723au_write16(padapter
, REG_TBTT_PROHIBIT
, 0x6404); /* ms */
989 /* Firmware will control REG_DRVERLYINT when power saving is enable, */
990 /* so don't set this register on STA mode. */
991 if (check_fwstate(&padapter
->mlmepriv
, WIFI_STATION_STATE
) == false)
992 rtl8723au_write8(padapter
, REG_DRVERLYINT
,
993 DRIVER_EARLY_INT_TIME
);
995 rtl8723au_write8(padapter
, REG_BCNDMATIM
, BCN_DMA_ATIME_INT_TIME
);
997 /* Suggested by designer timchen. Change beacon AIFS to the
998 largest number beacause test chip does not contension before
999 sending beacon. by tynli. 2009.11.03 */
1000 rtl8723au_write16(padapter
, REG_BCNTCFG
, 0x660F);
1003 static void ResumeTxBeacon(struct rtw_adapter
*padapter
)
1005 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
1007 /* 2010.03.01. Marked by tynli. No need to call workitem beacause
1008 we record the value */
1009 /* which should be read from register to a global variable. */
1011 RT_TRACE(_module_hci_hal_init_c_
, _drv_info_
, ("+ResumeTxBeacon\n"));
1013 pHalData
->RegFwHwTxQCtrl
|= BIT(6);
1014 rtl8723au_write8(padapter
, REG_FWHW_TXQ_CTRL
+ 2,
1015 pHalData
->RegFwHwTxQCtrl
);
1016 rtl8723au_write8(padapter
, REG_TBTT_PROHIBIT
+ 1, 0xff);
1017 pHalData
->RegReg542
|= BIT(0);
1018 rtl8723au_write8(padapter
, REG_TBTT_PROHIBIT
+ 2, pHalData
->RegReg542
);
1021 static void StopTxBeacon(struct rtw_adapter
*padapter
)
1023 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
1025 /* 2010.03.01. Marked by tynli. No need to call workitem beacause
1026 we record the value */
1027 /* which should be read from register to a global variable. */
1029 RT_TRACE(_module_hci_hal_init_c_
, _drv_info_
, ("+StopTxBeacon\n"));
1031 pHalData
->RegFwHwTxQCtrl
&= ~BIT(6);
1032 rtl8723au_write8(padapter
, REG_FWHW_TXQ_CTRL
+ 2,
1033 pHalData
->RegFwHwTxQCtrl
);
1034 rtl8723au_write8(padapter
, REG_TBTT_PROHIBIT
+ 1, 0x64);
1035 pHalData
->RegReg542
&= ~BIT(0);
1036 rtl8723au_write8(padapter
, REG_TBTT_PROHIBIT
+ 2, pHalData
->RegReg542
);
1039 static void _BeaconFunctionEnable(struct rtw_adapter
*padapter
, u8 Enable
,
1042 SetBcnCtrlReg23a(padapter
, DIS_TSF_UDT
| EN_BCN_FUNCTION
| DIS_BCNQ_SUB
,
1044 rtl8723au_write8(padapter
, REG_RD_CTRL
+ 1, 0x6F);
1047 void rtl8723a_SetBeaconRelatedRegisters(struct rtw_adapter
*padapter
)
1050 struct mlme_ext_priv
*pmlmeext
= &padapter
->mlmeextpriv
;
1051 struct mlme_ext_info
*pmlmeinfo
= &pmlmeext
->mlmext_info
;
1053 /* reset TSF, enable update TSF, correcting TSF On Beacon */
1055 /* REG_BCN_INTERVAL */
1058 /* REG_TBTT_PROHIBIT */
1059 /* REG_DRVERLYINT */
1060 /* REG_BCN_MAX_ERR */
1061 /* REG_BCNTCFG (0x510) */
1062 /* REG_DUAL_TSF_RST */
1063 /* REG_BCN_CTRL (0x550) */
1068 rtl8723au_write16(padapter
, REG_ATIMWND
, 2);
1071 /* Beacon interval (in unit of TU). */
1073 rtl8723au_write16(padapter
, REG_BCN_INTERVAL
, pmlmeinfo
->bcn_interval
);
1075 rtl8723a_InitBeaconParameters(padapter
);
1077 rtl8723au_write8(padapter
, REG_SLOT
, 0x09);
1080 /* Reset TSF Timer to zero, added by Roger. 2008.06.24 */
1082 value32
= rtl8723au_read32(padapter
, REG_TCR
);
1084 rtl8723au_write32(padapter
, REG_TCR
, value32
);
1087 rtl8723au_write32(padapter
, REG_TCR
, value32
);
1089 /* NOTE: Fix test chip's bug (about contention windows's randomness) */
1090 if (check_fwstate(&padapter
->mlmepriv
, WIFI_ADHOC_STATE
|
1091 WIFI_ADHOC_MASTER_STATE
| WIFI_AP_STATE
) == true) {
1092 rtl8723au_write8(padapter
, REG_RXTSF_OFFSET_CCK
, 0x50);
1093 rtl8723au_write8(padapter
, REG_RXTSF_OFFSET_OFDM
, 0x50);
1096 _BeaconFunctionEnable(padapter
, true, true);
1098 ResumeTxBeacon(padapter
);
1099 SetBcnCtrlReg23a(padapter
, DIS_BCNQ_SUB
, 0);
1102 void rtl8723a_SetHalODMVar(struct rtw_adapter
*Adapter
,
1103 enum hal_odm_variable eVariable
,
1104 void *pValue1
, bool bSet
)
1106 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(Adapter
);
1107 struct dm_odm_t
*podmpriv
= &pHalData
->odmpriv
;
1108 switch (eVariable
) {
1109 case HAL_ODM_STA_INFO
:
1111 struct sta_info
*psta
= (struct sta_info
*)pValue1
;
1114 DBG_8723A("Set STA_(%d) info\n", psta
->mac_id
);
1115 ODM_CmnInfoPtrArrayHook23a(podmpriv
,
1116 ODM_CMNINFO_STA_STATUS
,
1117 psta
->mac_id
, psta
);
1119 DBG_8723A("Clean STA_(%d) info\n", psta
->mac_id
);
1120 ODM_CmnInfoPtrArrayHook23a(podmpriv
,
1121 ODM_CMNINFO_STA_STATUS
,
1122 psta
->mac_id
, NULL
);
1126 case HAL_ODM_P2P_STATE
:
1127 ODM_CmnInfoUpdate23a(podmpriv
, ODM_CMNINFO_WIFI_DIRECT
, bSet
);
1129 case HAL_ODM_WIFI_DISPLAY_STATE
:
1130 ODM_CmnInfoUpdate23a(podmpriv
, ODM_CMNINFO_WIFI_DISPLAY
, bSet
);
1137 void rtl8723a_notch_filter(struct rtw_adapter
*adapter
, bool enable
)
1140 DBG_8723A("Enable notch filter\n");
1141 rtl8723au_write8(adapter
, rOFDM0_RxDSP
+ 1,
1142 rtl8723au_read8(adapter
, rOFDM0_RxDSP
+ 1) |
1145 DBG_8723A("Disable notch filter\n");
1146 rtl8723au_write8(adapter
, rOFDM0_RxDSP
+ 1,
1147 rtl8723au_read8(adapter
, rOFDM0_RxDSP
+ 1) &
1152 bool c2h_id_filter_ccx_8723a(u8 id
)
1155 if (id
== C2H_CCX_TX_RPT
)
1161 int c2h_handler_8723a(struct rtw_adapter
*padapter
, struct c2h_evt_hdr
*c2h_evt
)
1166 if (c2h_evt
== NULL
) {
1167 DBG_8723A("%s c2h_evt is NULL\n", __func__
);
1172 switch (c2h_evt
->id
) {
1174 RT_TRACE(_module_hal_init_c_
, _drv_info_
,
1175 ("C2HCommandHandler: %s\n", c2h_evt
->payload
));
1178 case C2H_CCX_TX_RPT
:
1179 handle_txrpt_ccx_8723a(padapter
, c2h_evt
->payload
);
1181 case C2H_EXT_RA_RPT
:
1183 case C2H_HW_INFO_EXCH
:
1184 RT_TRACE(_module_hal_init_c_
, _drv_info_
,
1185 ("[BT], C2H_HW_INFO_EXCH\n"));
1186 for (i
= 0; i
< c2h_evt
->plen
; i
++) {
1187 RT_TRACE(_module_hal_init_c_
, _drv_info_
,
1188 ("[BT], tmpBuf[%d]= 0x%x\n", i
,
1189 c2h_evt
->payload
[i
]));
1193 case C2H_C2H_H2C_TEST
:
1194 RT_TRACE(_module_hal_init_c_
, _drv_info_
,
1195 ("[BT], C2H_H2C_TEST\n"));
1196 RT_TRACE(_module_hal_init_c_
, _drv_info_
,
1197 ("[BT], tmpBuf[0]/[1]/[2]/[3]/[4]= 0x%x/ 0x%x/ "
1198 "0x%x/ 0x%x/ 0x%x\n", c2h_evt
->payload
[0],
1199 c2h_evt
->payload
[1], c2h_evt
->payload
[2],
1200 c2h_evt
->payload
[3], c2h_evt
->payload
[4]));
1204 DBG_8723A("%s , Got C2H_BT_INFO \n", __func__
);
1205 rtl8723a_fw_c2h_BT_info(padapter
,
1206 c2h_evt
->payload
, c2h_evt
->plen
);
1218 void rtl8723a_InitAntenna_Selection(struct rtw_adapter
*padapter
)
1222 val
= rtl8723au_read8(padapter
, REG_LEDCFG2
);
1223 /* Let 8051 take control antenna settting */
1224 val
|= BIT(7); /* DPDT_SEL_EN, 0x4C[23] */
1225 rtl8723au_write8(padapter
, REG_LEDCFG2
, val
);
1228 void rtl8723a_CheckAntenna_Selection(struct rtw_adapter
*padapter
)
1232 val
= rtl8723au_read8(padapter
, REG_LEDCFG2
);
1233 /* Let 8051 take control antenna settting */
1234 if (!(val
& BIT(7))) {
1235 val
|= BIT(7); /* DPDT_SEL_EN, 0x4C[23] */
1236 rtl8723au_write8(padapter
, REG_LEDCFG2
, val
);
1240 void rtl8723a_DeinitAntenna_Selection(struct rtw_adapter
*padapter
)
1244 val
= rtl8723au_read8(padapter
, REG_LEDCFG2
);
1245 /* Let 8051 take control antenna settting */
1246 val
&= ~BIT(7); /* DPDT_SEL_EN, clear 0x4C[23] */
1247 rtl8723au_write8(padapter
, REG_LEDCFG2
, val
);
1250 void rtl8723a_init_default_value(struct rtw_adapter
*padapter
)
1252 struct hal_data_8723a
*pHalData
;
1253 struct dm_priv
*pdmpriv
;
1256 pHalData
= GET_HAL_DATA(padapter
);
1257 pdmpriv
= &pHalData
->dmpriv
;
1259 /* init default value */
1260 pHalData
->fw_ractrl
= false;
1261 pHalData
->bIQKInitialized
= false;
1262 if (!padapter
->pwrctrlpriv
.bkeepfwalive
)
1263 pHalData
->LastHMEBoxNum
= 0;
1265 pHalData
->bIQKInitialized
= false;
1267 /* init dm default value */
1268 pdmpriv
->TM_Trigger
= 0; /* for IQK */
1269 /* pdmpriv->binitialized = false; */
1270 /* pdmpriv->prv_traffic_idx = 3; */
1271 /* pdmpriv->initialize = 0; */
1273 pdmpriv
->ThermalValue_HP_index
= 0;
1274 for (i
= 0; i
< HP_THERMAL_NUM
; i
++)
1275 pdmpriv
->ThermalValue_HP
[i
] = 0;
1277 /* init Efuse variables */
1278 pHalData
->EfuseUsedBytes
= 0;
1279 pHalData
->BTEfuseUsedBytes
= 0;
1282 u8
GetEEPROMSize8723A(struct rtw_adapter
*padapter
)
1287 cr
= rtl8723au_read16(padapter
, REG_9346CR
);
1288 /* 6: EEPROM used is 93C46, 4: boot from E-Fuse. */
1289 size
= (cr
& BOOT_FROM_EEPROM
) ? 6 : 4;
1291 MSG_8723A("EEPROM type is %s\n", size
== 4 ? "E-FUSE" : "93C46");
1298 /* LLT R/W/Init function */
1301 static int _LLTWrite(struct rtw_adapter
*padapter
, u32 address
, u32 data
)
1303 int status
= _SUCCESS
;
1305 u32 value
= _LLT_INIT_ADDR(address
) | _LLT_INIT_DATA(data
) |
1306 _LLT_OP(_LLT_WRITE_ACCESS
);
1307 u16 LLTReg
= REG_LLT_INIT
;
1309 rtl8723au_write32(padapter
, LLTReg
, value
);
1313 value
= rtl8723au_read32(padapter
, LLTReg
);
1314 if (_LLT_NO_ACTIVE
== _LLT_OP_VALUE(value
)) {
1318 if (count
> POLLING_LLT_THRESHOLD
) {
1319 RT_TRACE(_module_hal_init_c_
, _drv_err_
,
1320 ("Failed to polling write LLT done at "
1321 "address %d!\n", address
));
1330 int InitLLTTable23a(struct rtw_adapter
*padapter
, u32 boundary
)
1332 int status
= _SUCCESS
;
1334 u32 txpktbuf_bndy
= boundary
;
1335 u32 Last_Entry_Of_TxPktBuf
= LAST_ENTRY_OF_TX_PKT_BUFFER
;
1337 for (i
= 0; i
< (txpktbuf_bndy
- 1); i
++) {
1338 status
= _LLTWrite(padapter
, i
, i
+ 1);
1339 if (status
!= _SUCCESS
) {
1345 status
= _LLTWrite(padapter
, (txpktbuf_bndy
- 1), 0xFF);
1346 if (status
!= _SUCCESS
) {
1350 /* Make the other pages as ring buffer */
1351 /* This ring buffer is used as beacon buffer if we config this
1352 MAC as two MAC transfer. */
1353 /* Otherwise used as local loopback buffer. */
1354 for (i
= txpktbuf_bndy
; i
< Last_Entry_Of_TxPktBuf
; i
++) {
1355 status
= _LLTWrite(padapter
, i
, (i
+ 1));
1356 if (_SUCCESS
!= status
) {
1361 /* Let last entry point to the start entry of ring buffer */
1362 status
= _LLTWrite(padapter
, Last_Entry_Of_TxPktBuf
, txpktbuf_bndy
);
1363 if (status
!= _SUCCESS
) {
1370 static void _DisableGPIO(struct rtw_adapter
*padapter
)
1372 /***************************************
1373 j. GPIO_PIN_CTRL 0x44[31:0]= 0x000
1374 k.Value = GPIO_PIN_CTRL[7:0]
1375 l. GPIO_PIN_CTRL 0x44[31:0] = 0x00FF0000 | (value <<8); write external PIN level
1376 m. GPIO_MUXCFG 0x42 [15:0] = 0x0780
1377 n. LEDCFG 0x4C[15:0] = 0x8080
1378 ***************************************/
1382 /* 1. Disable GPIO[7:0] */
1383 rtl8723au_write16(padapter
, REG_GPIO_PIN_CTRL
+ 2, 0x0000);
1384 value32
= rtl8723au_read32(padapter
, REG_GPIO_PIN_CTRL
) & 0xFFFF00FF;
1385 u4bTmp
= value32
& 0x000000FF;
1386 value32
|= ((u4bTmp
<< 8) | 0x00FF0000);
1387 rtl8723au_write32(padapter
, REG_GPIO_PIN_CTRL
, value32
);
1390 /* <Roger_Notes> For RTL8723u multi-function configuration which
1391 was autoload from Efuse offset 0x0a and 0x0b, */
1392 /* WLAN HW GPIO[9], GPS HW GPIO[10] and BT HW GPIO[11]. */
1393 /* Added by Roger, 2010.10.07. */
1395 /* 2. Disable GPIO[8] and GPIO[12] */
1397 /* Configure all pins as input mode. */
1398 rtl8723au_write16(padapter
, REG_GPIO_IO_SEL_2
, 0x0000);
1399 value32
= rtl8723au_read32(padapter
, REG_GPIO_PIN_CTRL_2
) & 0xFFFF001F;
1400 u4bTmp
= value32
& 0x0000001F;
1401 /* Set pin 8, 10, 11 and pin 12 to output mode. */
1402 value32
|= ((u4bTmp
<< 8) | 0x001D0000);
1403 rtl8723au_write32(padapter
, REG_GPIO_PIN_CTRL_2
, value32
);
1405 /* 3. Disable LED0 & 1 */
1406 rtl8723au_write16(padapter
, REG_LEDCFG0
, 0x8080);
1407 } /* end of _DisableGPIO() */
1409 static void _DisableRFAFEAndResetBB8192C(struct rtw_adapter
*padapter
)
1411 /**************************************
1412 a. TXPAUSE 0x522[7:0] = 0xFF Pause MAC TX queue
1413 b. RF path 0 offset 0x00 = 0x00 disable RF
1414 c. APSD_CTRL 0x600[7:0] = 0x40
1415 d. SYS_FUNC_EN 0x02[7:0] = 0x16 reset BB state machine
1416 e. SYS_FUNC_EN 0x02[7:0] = 0x14 reset BB state machine
1417 ***************************************/
1418 u8 eRFPath
= 0, value8
= 0;
1420 rtl8723au_write8(padapter
, REG_TXPAUSE
, 0xFF);
1422 PHY_SetRFReg(padapter
, (enum RF_RADIO_PATH
) eRFPath
, 0x0, bMaskByte0
, 0x0);
1425 rtl8723au_write8(padapter
, REG_APSD_CTRL
, value8
); /* 0x40 */
1427 /* Set BB reset at first */
1429 value8
|= (FEN_USBD
| FEN_USBA
| FEN_BB_GLB_RSTn
);
1430 rtl8723au_write8(padapter
, REG_SYS_FUNC_EN
, value8
); /* 0x16 */
1432 /* Set global reset. */
1433 value8
&= ~FEN_BB_GLB_RSTn
;
1434 rtl8723au_write8(padapter
, REG_SYS_FUNC_EN
, value8
); /* 0x14 */
1436 /* 2010/08/12 MH We need to set BB/GLBAL reset to save power
1439 /* RT_TRACE(COMP_INIT, DBG_LOUD, ("======> RF off and reset BB.\n")); */
1442 static void _DisableRFAFEAndResetBB(struct rtw_adapter
*padapter
)
1444 _DisableRFAFEAndResetBB8192C(padapter
);
1447 static void _ResetDigitalProcedure1_92C(struct rtw_adapter
*padapter
,
1450 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
1452 if (IS_FW_81xxC(padapter
) && (pHalData
->FirmwareVersion
<= 0x20)) {
1453 /*****************************
1454 f. MCUFWDL 0x80[7:0]= 0 reset MCU ready status
1455 g. SYS_FUNC_EN 0x02[10]= 0 reset MCU register, (8051 reset)
1456 h. SYS_FUNC_EN 0x02[15-12]= 5 reset MAC register, DCORE
1457 i. SYS_FUNC_EN 0x02[10]= 1 enable MCU register,
1459 ******************************/
1461 rtl8723au_write8(padapter
, REG_MCUFWDL
, 0);
1463 valu16
= rtl8723au_read16(padapter
, REG_SYS_FUNC_EN
);
1464 /* reset MCU , 8051 */
1465 rtl8723au_write16(padapter
, REG_SYS_FUNC_EN
,
1466 valu16
& (~FEN_CPUEN
));
1468 valu16
= rtl8723au_read16(padapter
, REG_SYS_FUNC_EN
) & 0x0FFF;
1470 rtl8723au_write16(padapter
, REG_SYS_FUNC_EN
,
1471 valu16
| (FEN_HWPDN
| FEN_ELDR
));
1473 valu16
= rtl8723au_read16(padapter
, REG_SYS_FUNC_EN
);
1474 /* enable MCU , 8051 */
1475 rtl8723au_write16(padapter
, REG_SYS_FUNC_EN
,
1476 valu16
| FEN_CPUEN
);
1480 /* 2010/08/12 MH For USB SS, we can not stop 8051 when we
1481 are trying to enter IPS/HW&SW radio off. For
1482 S3/S4/S5/Disable, we can stop 8051 because */
1483 /* we will init FW when power on again. */
1484 /* If we want to SS mode, we can not reset 8051. */
1485 if (rtl8723au_read8(padapter
, REG_MCUFWDL
) & BIT(1)) {
1486 /* IF fw in RAM code, do reset */
1487 if (padapter
->bFWReady
) {
1488 /* 2010/08/25 MH Accordign to RD alfred's
1489 suggestion, we need to disable other */
1490 /* HRCV INT to influence 8051 reset. */
1491 rtl8723au_write8(padapter
, REG_FWIMR
, 0x20);
1492 /* 2011/02/15 MH According to Alex's
1493 suggestion, close mask to prevent
1494 incorrect FW write operation. */
1495 rtl8723au_write8(padapter
, REG_FTIMR
, 0x00);
1496 rtl8723au_write8(padapter
, REG_FSIMR
, 0x00);
1498 /* 8051 reset by self */
1499 rtl8723au_write8(padapter
, REG_HMETFR
+ 3,
1502 while ((retry_cnts
++ < 100) &&
1504 rtl8723au_read16(padapter
,
1505 REG_SYS_FUNC_EN
))) {
1506 udelay(50); /* us */
1509 if (retry_cnts
>= 100) {
1510 /* Reset MAC and Enable 8051 */
1511 rtl8723au_write8(padapter
,
1512 REG_SYS_FUNC_EN
+ 1,
1518 /* Reset MAC and Enable 8051 */
1519 rtl8723au_write8(padapter
, REG_SYS_FUNC_EN
+ 1, 0x54);
1520 rtl8723au_write8(padapter
, REG_MCUFWDL
, 0);
1524 /*****************************
1525 Without HW auto state machine
1526 g. SYS_CLKR 0x08[15:0] = 0x30A3 disable MAC clock
1527 h. AFE_PLL_CTRL 0x28[7:0] = 0x80 disable AFE PLL
1528 i. AFE_XTAL_CTRL 0x24[15:0] = 0x880F gated AFE DIG_CLOCK
1529 j. SYS_ISO_CTRL 0x00[7:0] = 0xF9 isolated digital to PON
1530 ******************************/
1531 /* modify to 0x70A3 by Scott. */
1532 rtl8723au_write16(padapter
, REG_SYS_CLKR
, 0x70A3);
1533 rtl8723au_write8(padapter
, REG_AFE_PLL_CTRL
, 0x80);
1534 rtl8723au_write16(padapter
, REG_AFE_XTAL_CTRL
, 0x880F);
1535 rtl8723au_write8(padapter
, REG_SYS_ISO_CTRL
, 0xF9);
1537 /* Disable all RF/BB power */
1538 rtl8723au_write8(padapter
, REG_RF_CTRL
, 0x00);
1542 static void _ResetDigitalProcedure1(struct rtw_adapter
*padapter
,
1545 _ResetDigitalProcedure1_92C(padapter
, bWithoutHWSM
);
1548 static void _ResetDigitalProcedure2(struct rtw_adapter
*padapter
)
1550 /*****************************
1551 k. SYS_FUNC_EN 0x03[7:0] = 0x44 disable ELDR runction
1552 l. SYS_CLKR 0x08[15:0] = 0x3083 disable ELDR clock
1553 m. SYS_ISO_CTRL 0x01[7:0] = 0x83 isolated ELDR to PON
1554 ******************************/
1555 /* modify to 0x70a3 by Scott. */
1556 rtl8723au_write16(padapter
, REG_SYS_CLKR
, 0x70a3);
1557 /* modify to 0x82 by Scott. */
1558 rtl8723au_write8(padapter
, REG_SYS_ISO_CTRL
+ 1, 0x82);
1561 static void _DisableAnalog(struct rtw_adapter
*padapter
, bool bWithoutHWSM
)
1563 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
1568 /*****************************
1569 n. LDOA15_CTRL 0x20[7:0] = 0x04 disable A15 power
1570 o. LDOV12D_CTRL 0x21[7:0] = 0x54 disable digital core power
1571 r. When driver call disable, the ASIC will turn off remaining
1573 ******************************/
1575 rtl8723au_write8(padapter
, REG_LDOA15_CTRL
, 0x04);
1576 /* rtl8723au_write8(padapter, REG_LDOV12D_CTRL, 0x54); */
1578 value8
= rtl8723au_read8(padapter
, REG_LDOV12D_CTRL
);
1579 value8
&= (~LDV12_EN
);
1580 rtl8723au_write8(padapter
, REG_LDOV12D_CTRL
, value8
);
1581 /* RT_TRACE(COMP_INIT, DBG_LOUD,
1582 (" REG_LDOV12D_CTRL Reg0x21:0x%02x.\n", value8)); */
1585 /*****************************
1586 h. SPS0_CTRL 0x11[7:0] = 0x23 enter PFM mode
1587 i. APS_FSMCO 0x04[15:0] = 0x4802 set USB suspend
1588 ******************************/
1590 if (IS_81xxC_VENDOR_UMC_B_CUT(pHalData
->VersionID
))
1593 rtl8723au_write8(padapter
, REG_SPS0_CTRL
, value8
);
1596 /* value16 |= (APDM_HOST | FSM_HSUS |/PFM_ALDN); */
1597 /* 2010/08/31 According to Filen description, we need to
1598 use HW to shut down 8051 automatically. */
1599 /* Becasue suspend operatione need the asistance of 8051
1601 value16
|= (APDM_HOST
| AFSM_HSUS
| PFM_ALDN
);
1603 value16
|= (APDM_HOST
| AFSM_HSUS
| PFM_ALDN
);
1606 rtl8723au_write16(padapter
, REG_APS_FSMCO
, value16
); /* 0x4802 */
1608 rtl8723au_write8(padapter
, REG_RSV_CTRL
, 0x0e);
1611 /* HW Auto state machine */
1612 int CardDisableHWSM(struct rtw_adapter
*padapter
, u8 resetMCU
)
1614 int rtStatus
= _SUCCESS
;
1616 if (padapter
->bSurpriseRemoved
) {
1619 /* RF Off Sequence ==== */
1620 _DisableRFAFEAndResetBB(padapter
);
1622 /* ==== Reset digital sequence ====== */
1623 _ResetDigitalProcedure1(padapter
, false);
1625 /* ==== Pull GPIO PIN to balance level and LED control ====== */
1626 _DisableGPIO(padapter
);
1628 /* ==== Disable analog sequence === */
1629 _DisableAnalog(padapter
, false);
1631 RT_TRACE(_module_hci_hal_init_c_
, _drv_info_
,
1632 ("======> Card disable finished.\n"));
1637 /* without HW Auto state machine */
1638 int CardDisableWithoutHWSM(struct rtw_adapter
*padapter
)
1640 int rtStatus
= _SUCCESS
;
1642 /* RT_TRACE(COMP_INIT, DBG_LOUD,
1643 ("======> Card Disable Without HWSM .\n")); */
1644 if (padapter
->bSurpriseRemoved
) {
1648 /* RF Off Sequence ==== */
1649 _DisableRFAFEAndResetBB(padapter
);
1651 /* ==== Reset digital sequence ====== */
1652 _ResetDigitalProcedure1(padapter
, true);
1654 /* ==== Pull GPIO PIN to balance level and LED control ====== */
1655 _DisableGPIO(padapter
);
1657 /* ==== Reset digital sequence ====== */
1658 _ResetDigitalProcedure2(padapter
);
1660 /* ==== Disable analog sequence === */
1661 _DisableAnalog(padapter
, true);
1663 /* RT_TRACE(COMP_INIT, DBG_LOUD,
1664 ("<====== Card Disable Without HWSM .\n")); */
1668 void Hal_InitPGData(struct rtw_adapter
*padapter
, u8
*PROMContent
)
1670 struct eeprom_priv
*pEEPROM
= GET_EEPROM_EFUSE_PRIV(padapter
);
1672 if (false == pEEPROM
->bautoload_fail_flag
) { /* autoload OK. */
1673 if (!pEEPROM
->EepromOrEfuse
) {
1674 /* Read EFUSE real map to shadow. */
1675 EFUSE_ShadowMapUpdate23a(padapter
, EFUSE_WIFI
);
1676 memcpy((void *)PROMContent
,
1677 (void *)pEEPROM
->efuse_eeprom_data
,
1680 } else { /* autoload fail */
1681 RT_TRACE(_module_hci_hal_init_c_
, _drv_notice_
,
1682 ("AutoLoad Fail reported from CR9346!!\n"));
1683 /* pHalData->AutoloadFailFlag = true; */
1684 /* update to default value 0xFF */
1685 if (false == pEEPROM
->EepromOrEfuse
)
1686 EFUSE_ShadowMapUpdate23a(padapter
, EFUSE_WIFI
);
1687 memcpy((void *)PROMContent
, (void *)pEEPROM
->efuse_eeprom_data
,
1692 void Hal_EfuseParseIDCode(struct rtw_adapter
*padapter
, u8
*hwinfo
)
1694 struct eeprom_priv
*pEEPROM
= GET_EEPROM_EFUSE_PRIV(padapter
);
1695 /* struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter); */
1698 /* Checl 0x8129 again for making sure autoload status!! */
1699 EEPROMId
= le16_to_cpu(*((u16
*) hwinfo
));
1700 if (EEPROMId
!= RTL_EEPROM_ID
) {
1701 DBG_8723A("EEPROM ID(%#x) is invalid!!\n", EEPROMId
);
1702 pEEPROM
->bautoload_fail_flag
= true;
1704 pEEPROM
->bautoload_fail_flag
= false;
1707 RT_TRACE(_module_hal_init_c_
, _drv_info_
,
1708 ("EEPROM ID = 0x%04x\n", EEPROMId
));
1711 static void Hal_EEValueCheck(u8 EEType
, void *pInValue
, void *pOutValue
)
1717 pIn
= (u8
*) pInValue
;
1718 pOut
= (u8
*) pOutValue
;
1722 RT_TRACE(_module_hci_hal_init_c_
, _drv_err_
,
1723 ("EETYPE_TX_PWR, value =%d is invalid, set "
1724 "to default = 0x%x\n",
1725 *pIn
, EEPROM_Default_TxPowerLevel
));
1726 *pOut
= EEPROM_Default_TxPowerLevel
;
1736 Hal_ReadPowerValueFromPROM_8723A(struct txpowerinfo
*pwrInfo
,
1737 u8
*PROMContent
, bool AutoLoadFail
)
1739 u32 rfPath
, eeAddr
, group
, rfPathMax
= 1;
1741 memset(pwrInfo
, 0, sizeof(*pwrInfo
));
1744 for (group
= 0; group
< MAX_CHNL_GROUP
; group
++) {
1745 for (rfPath
= 0; rfPath
< rfPathMax
; rfPath
++) {
1746 pwrInfo
->CCKIndex
[rfPath
][group
] =
1747 EEPROM_Default_TxPowerLevel
;
1748 pwrInfo
->HT40_1SIndex
[rfPath
][group
] =
1749 EEPROM_Default_TxPowerLevel
;
1750 pwrInfo
->HT40_2SIndexDiff
[rfPath
][group
] =
1751 EEPROM_Default_HT40_2SDiff
;
1752 pwrInfo
->HT20IndexDiff
[rfPath
][group
] =
1753 EEPROM_Default_HT20_Diff
;
1754 pwrInfo
->OFDMIndexDiff
[rfPath
][group
] =
1755 EEPROM_Default_LegacyHTTxPowerDiff
;
1756 pwrInfo
->HT40MaxOffset
[rfPath
][group
] =
1757 EEPROM_Default_HT40_PwrMaxOffset
;
1758 pwrInfo
->HT20MaxOffset
[rfPath
][group
] =
1759 EEPROM_Default_HT20_PwrMaxOffset
;
1762 pwrInfo
->TSSI_A
[0] = EEPROM_Default_TSSI
;
1766 for (rfPath
= 0; rfPath
< rfPathMax
; rfPath
++) {
1767 for (group
= 0; group
< MAX_CHNL_GROUP
; group
++) {
1769 EEPROM_CCK_TX_PWR_INX_8723A
+ (rfPath
* 3) + group
;
1770 /* pwrInfo->CCKIndex[rfPath][group] =
1771 PROMContent[eeAddr]; */
1772 Hal_EEValueCheck(EETYPE_TX_PWR
, &PROMContent
[eeAddr
],
1773 &pwrInfo
->CCKIndex
[rfPath
][group
]);
1774 eeAddr
= EEPROM_HT40_1S_TX_PWR_INX_8723A
+
1775 (rfPath
* 3) + group
;
1776 /* pwrInfo->HT40_1SIndex[rfPath][group] =
1777 PROMContent[eeAddr]; */
1778 Hal_EEValueCheck(EETYPE_TX_PWR
, &PROMContent
[eeAddr
],
1779 &pwrInfo
->HT40_1SIndex
[rfPath
][group
]);
1783 for (group
= 0; group
< MAX_CHNL_GROUP
; group
++) {
1784 for (rfPath
= 0; rfPath
< rfPathMax
; rfPath
++) {
1785 pwrInfo
->HT40_2SIndexDiff
[rfPath
][group
] = 0;
1786 pwrInfo
->HT20IndexDiff
[rfPath
][group
] =
1788 [EEPROM_HT20_TX_PWR_INX_DIFF_8723A
+
1789 group
] >> (rfPath
* 4)) & 0xF;
1790 /* 4bit sign number to 8 bit sign number */
1791 if (pwrInfo
->HT20IndexDiff
[rfPath
][group
] & BIT(3))
1792 pwrInfo
->HT20IndexDiff
[rfPath
][group
] |= 0xF0;
1794 pwrInfo
->OFDMIndexDiff
[rfPath
][group
] =
1795 (PROMContent
[EEPROM_OFDM_TX_PWR_INX_DIFF_8723A
+
1796 group
] >> (rfPath
* 4)) & 0xF;
1798 pwrInfo
->HT40MaxOffset
[rfPath
][group
] =
1799 (PROMContent
[EEPROM_HT40_MAX_PWR_OFFSET_8723A
+
1800 group
] >> (rfPath
* 4)) & 0xF;
1802 pwrInfo
->HT20MaxOffset
[rfPath
][group
] =
1803 (PROMContent
[EEPROM_HT20_MAX_PWR_OFFSET_8723A
+
1804 group
] >> (rfPath
* 4)) & 0xF;
1808 pwrInfo
->TSSI_A
[0] = PROMContent
[EEPROM_TSSI_A_8723A
];
1811 static u8
Hal_GetChnlGroup(u8 chnl
)
1815 if (chnl
< 3) /* Cjanel 1-3 */
1817 else if (chnl
< 9) /* Channel 4-9 */
1819 else /* Channel 10-14 */
1826 Hal_EfuseParsetxpowerinfo_8723A(struct rtw_adapter
*padapter
,
1827 u8
*PROMContent
, bool AutoLoadFail
)
1829 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
1830 struct txpowerinfo pwrInfo
;
1831 u8 rfPath
, ch
, group
, rfPathMax
= 1;
1834 Hal_ReadPowerValueFromPROM_8723A(&pwrInfo
, PROMContent
, AutoLoadFail
);
1835 for (rfPath
= 0; rfPath
< rfPathMax
; rfPath
++) {
1836 for (ch
= 0; ch
< CHANNEL_MAX_NUMBER
; ch
++) {
1837 group
= Hal_GetChnlGroup(ch
);
1839 pHalData
->TxPwrLevelCck
[rfPath
][ch
] =
1840 pwrInfo
.CCKIndex
[rfPath
][group
];
1841 pHalData
->TxPwrLevelHT40_1S
[rfPath
][ch
] =
1842 pwrInfo
.HT40_1SIndex
[rfPath
][group
];
1844 pHalData
->TxPwrHt20Diff
[rfPath
][ch
] =
1845 pwrInfo
.HT20IndexDiff
[rfPath
][group
];
1846 pHalData
->TxPwrLegacyHtDiff
[rfPath
][ch
] =
1847 pwrInfo
.OFDMIndexDiff
[rfPath
][group
];
1848 pHalData
->PwrGroupHT20
[rfPath
][ch
] =
1849 pwrInfo
.HT20MaxOffset
[rfPath
][group
];
1850 pHalData
->PwrGroupHT40
[rfPath
][ch
] =
1851 pwrInfo
.HT40MaxOffset
[rfPath
][group
];
1853 pwr
= pwrInfo
.HT40_1SIndex
[rfPath
][group
];
1854 diff
= pwrInfo
.HT40_2SIndexDiff
[rfPath
][group
];
1856 pHalData
->TxPwrLevelHT40_2S
[rfPath
][ch
] =
1857 (pwr
> diff
) ? (pwr
- diff
) : 0;
1860 for (rfPath
= 0; rfPath
< RF_PATH_MAX
; rfPath
++) {
1861 for (ch
= 0; ch
< CHANNEL_MAX_NUMBER
; ch
++) {
1862 RT_TRACE(_module_hci_hal_init_c_
, _drv_info_
,
1863 ("RF(%u)-Ch(%u) [CCK / HT40_1S / HT40_2S] = "
1864 "[0x%x / 0x%x / 0x%x]\n",
1866 pHalData
->TxPwrLevelCck
[rfPath
][ch
],
1867 pHalData
->TxPwrLevelHT40_1S
[rfPath
][ch
],
1868 pHalData
->TxPwrLevelHT40_2S
[rfPath
][ch
]));
1872 for (ch
= 0; ch
< CHANNEL_MAX_NUMBER
; ch
++) {
1873 RT_TRACE(_module_hci_hal_init_c_
, _drv_info_
,
1874 ("RF-A Ht20 to HT40 Diff[%u] = 0x%x(%d)\n", ch
,
1875 pHalData
->TxPwrHt20Diff
[RF_PATH_A
][ch
],
1876 pHalData
->TxPwrHt20Diff
[RF_PATH_A
][ch
]));
1878 for (ch
= 0; ch
< CHANNEL_MAX_NUMBER
; ch
++)
1879 RT_TRACE(_module_hci_hal_init_c_
, _drv_info_
,
1880 ("RF-A Legacy to Ht40 Diff[%u] = 0x%x\n", ch
,
1881 pHalData
->TxPwrLegacyHtDiff
[RF_PATH_A
][ch
]));
1882 for (ch
= 0; ch
< CHANNEL_MAX_NUMBER
; ch
++) {
1883 RT_TRACE(_module_hci_hal_init_c_
, _drv_info_
,
1884 ("RF-B Ht20 to HT40 Diff[%u] = 0x%x(%d)\n", ch
,
1885 pHalData
->TxPwrHt20Diff
[RF_PATH_B
][ch
],
1886 pHalData
->TxPwrHt20Diff
[RF_PATH_B
][ch
]));
1888 for (ch
= 0; ch
< CHANNEL_MAX_NUMBER
; ch
++)
1889 RT_TRACE(_module_hci_hal_init_c_
, _drv_info_
,
1890 ("RF-B Legacy to HT40 Diff[%u] = 0x%x\n", ch
,
1891 pHalData
->TxPwrLegacyHtDiff
[RF_PATH_B
][ch
]));
1892 if (!AutoLoadFail
) {
1893 struct registry_priv
*registry_par
= &padapter
->registrypriv
;
1894 if (registry_par
->regulatory_tid
== 0xff) {
1895 if (PROMContent
[RF_OPTION1_8723A
] == 0xff)
1896 pHalData
->EEPROMRegulatory
= 0;
1898 pHalData
->EEPROMRegulatory
=
1899 PROMContent
[RF_OPTION1_8723A
] & 0x7;
1901 pHalData
->EEPROMRegulatory
=
1902 registry_par
->regulatory_tid
;
1905 pHalData
->EEPROMRegulatory
= 0;
1907 RT_TRACE(_module_hci_hal_init_c_
, _drv_info_
,
1908 ("EEPROMRegulatory = 0x%x\n", pHalData
->EEPROMRegulatory
));
1911 pHalData
->bTXPowerDataReadFromEEPORM
= true;
1915 Hal_EfuseParseBTCoexistInfo_8723A(struct rtw_adapter
*padapter
,
1916 u8
*hwinfo
, bool AutoLoadFail
)
1918 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
1922 if (!AutoLoadFail
) {
1923 tmpu4
= rtl8723au_read32(padapter
, REG_MULTI_FUNC_CTRL
);
1924 if (tmpu4
& BT_FUNC_EN
)
1925 pHalData
->EEPROMBluetoothCoexist
= 1;
1927 pHalData
->EEPROMBluetoothCoexist
= 0;
1928 pHalData
->EEPROMBluetoothType
= BT_RTL8723A
;
1930 /* The following need to be checked with newer version of */
1932 tempval
= hwinfo
[RF_OPTION4_8723A
];
1933 pHalData
->EEPROMBluetoothAntNum
= (tempval
& 0x1);
1934 pHalData
->EEPROMBluetoothAntIsolation
= ((tempval
& 0x10) >> 4);
1935 pHalData
->EEPROMBluetoothRadioShared
= ((tempval
& 0x20) >> 5);
1937 pHalData
->EEPROMBluetoothCoexist
= 0;
1938 pHalData
->EEPROMBluetoothType
= BT_RTL8723A
;
1939 pHalData
->EEPROMBluetoothAntNum
= Ant_x2
;
1940 pHalData
->EEPROMBluetoothAntIsolation
= 0;
1941 pHalData
->EEPROMBluetoothRadioShared
= BT_Radio_Shared
;
1944 rtl8723a_BT_init_hal_vars(padapter
);
1948 Hal_EfuseParseEEPROMVer(struct rtw_adapter
*padapter
,
1949 u8
*hwinfo
, bool AutoLoadFail
)
1951 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
1954 pHalData
->EEPROMVersion
= hwinfo
[EEPROM_VERSION_8723A
];
1956 pHalData
->EEPROMVersion
= 1;
1957 RT_TRACE(_module_hci_hal_init_c_
, _drv_info_
,
1958 ("Hal_EfuseParseEEPROMVer(), EEVer = %d\n",
1959 pHalData
->EEPROMVersion
));
1963 rtl8723a_EfuseParseChnlPlan(struct rtw_adapter
*padapter
,
1964 u8
*hwinfo
, bool AutoLoadFail
)
1966 padapter
->mlmepriv
.ChannelPlan
=
1967 hal_com_get_channel_plan23a(padapter
, hwinfo
?
1968 hwinfo
[EEPROM_ChannelPlan_8723A
]:0xFF,
1969 padapter
->registrypriv
.channel_plan
,
1970 RT_CHANNEL_DOMAIN_WORLD_WIDE_13
,
1973 DBG_8723A("mlmepriv.ChannelPlan = 0x%02x\n",
1974 padapter
->mlmepriv
.ChannelPlan
);
1978 Hal_EfuseParseCustomerID(struct rtw_adapter
*padapter
,
1979 u8
*hwinfo
, bool AutoLoadFail
)
1981 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
1983 if (!AutoLoadFail
) {
1984 pHalData
->EEPROMCustomerID
= hwinfo
[EEPROM_CustomID_8723A
];
1985 pHalData
->EEPROMSubCustomerID
=
1986 hwinfo
[EEPROM_SubCustomID_8723A
];
1988 pHalData
->EEPROMCustomerID
= 0;
1989 pHalData
->EEPROMSubCustomerID
= 0;
1991 RT_TRACE(_module_hci_hal_init_c_
, _drv_info_
,
1992 ("EEPROM Customer ID: 0x%2x\n", pHalData
->EEPROMCustomerID
));
1993 RT_TRACE(_module_hci_hal_init_c_
, _drv_info_
,
1994 ("EEPROM SubCustomer ID: 0x%02x\n",
1995 pHalData
->EEPROMSubCustomerID
));
1999 Hal_EfuseParseAntennaDiversity(struct rtw_adapter
*padapter
,
2000 u8
*hwinfo
, bool AutoLoadFail
)
2005 Hal_EfuseParseRateIndicationOption(struct rtw_adapter
*padapter
,
2006 u8
*hwinfo
, bool AutoLoadFail
)
2011 Hal_EfuseParseXtal_8723A(struct rtw_adapter
*pAdapter
,
2012 u8
*hwinfo
, u8 AutoLoadFail
)
2014 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(pAdapter
);
2016 if (!AutoLoadFail
) {
2017 pHalData
->CrystalCap
= hwinfo
[EEPROM_XTAL_K_8723A
];
2018 if (pHalData
->CrystalCap
== 0xFF)
2019 pHalData
->CrystalCap
= EEPROM_Default_CrystalCap_8723A
;
2021 pHalData
->CrystalCap
= EEPROM_Default_CrystalCap_8723A
;
2023 RT_TRACE(_module_hci_hal_init_c_
, _drv_info_
,
2024 ("%s: CrystalCap = 0x%2x\n", __func__
,
2025 pHalData
->CrystalCap
));
2029 Hal_EfuseParseThermalMeter_8723A(struct rtw_adapter
*padapter
,
2030 u8
*PROMContent
, bool AutoloadFail
)
2032 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
2035 /* ThermalMeter from EEPROM */
2037 if (AutoloadFail
== false)
2038 pHalData
->EEPROMThermalMeter
=
2039 PROMContent
[EEPROM_THERMAL_METER_8723A
];
2041 pHalData
->EEPROMThermalMeter
= EEPROM_Default_ThermalMeter
;
2043 if ((pHalData
->EEPROMThermalMeter
== 0xff) || (AutoloadFail
== true)) {
2044 pHalData
->bAPKThermalMeterIgnore
= true;
2045 pHalData
->EEPROMThermalMeter
= EEPROM_Default_ThermalMeter
;
2048 DBG_8723A("%s: ThermalMeter = 0x%x\n", __func__
,
2049 pHalData
->EEPROMThermalMeter
);
2052 void Hal_InitChannelPlan23a(struct rtw_adapter
*padapter
)
2056 static void rtl8723a_cal_txdesc_chksum(struct tx_desc
*ptxdesc
)
2058 u16
*usPtr
= (u16
*) ptxdesc
;
2059 u32 count
= 16; /* (32 bytes / 2 bytes per XOR) => 16 times */
2064 ptxdesc
->txdw7
&= cpu_to_le32(0xffff0000);
2066 for (index
= 0; index
< count
; index
++) {
2067 checksum
^= le16_to_cpu(*(usPtr
+ index
));
2070 ptxdesc
->txdw7
|= cpu_to_le32(checksum
& 0x0000ffff);
2073 static void fill_txdesc_sectype(struct pkt_attrib
*pattrib
,
2074 struct txdesc_8723a
*ptxdesc
)
2076 if ((pattrib
->encrypt
> 0) && !pattrib
->bswenc
) {
2077 switch (pattrib
->encrypt
) {
2079 case WLAN_CIPHER_SUITE_WEP40
:
2080 case WLAN_CIPHER_SUITE_WEP104
:
2081 case WLAN_CIPHER_SUITE_TKIP
:
2082 ptxdesc
->sectype
= 1;
2085 case WLAN_CIPHER_SUITE_CCMP
:
2086 ptxdesc
->sectype
= 3;
2096 static void fill_txdesc_vcs(struct pkt_attrib
*pattrib
,
2097 struct txdesc_8723a
*ptxdesc
)
2099 /* DBG_8723A("cvs_mode =%d\n", pattrib->vcs_mode); */
2101 switch (pattrib
->vcs_mode
) {
2107 ptxdesc
->cts2self
= 1;
2115 if (pattrib
->vcs_mode
) {
2116 ptxdesc
->hw_rts_en
= 1; /* ENABLE HW RTS */
2119 if (pattrib
->ht_en
) {
2120 if (pattrib
->bwmode
& HT_CHANNEL_WIDTH_40
)
2121 ptxdesc
->rts_bw
= 1;
2123 switch (pattrib
->ch_offset
) {
2124 case HAL_PRIME_CHNL_OFFSET_DONT_CARE
:
2125 ptxdesc
->rts_sc
= 0;
2128 case HAL_PRIME_CHNL_OFFSET_LOWER
:
2129 ptxdesc
->rts_sc
= 1;
2132 case HAL_PRIME_CHNL_OFFSET_UPPER
:
2133 ptxdesc
->rts_sc
= 2;
2137 ptxdesc
->rts_sc
= 3; /* Duplicate */
2144 static void fill_txdesc_phy(struct pkt_attrib
*pattrib
,
2145 struct txdesc_8723a
*ptxdesc
)
2147 if (pattrib
->ht_en
) {
2148 if (pattrib
->bwmode
& HT_CHANNEL_WIDTH_40
)
2149 ptxdesc
->data_bw
= 1;
2151 switch (pattrib
->ch_offset
) {
2152 case HAL_PRIME_CHNL_OFFSET_DONT_CARE
:
2153 ptxdesc
->data_sc
= 0;
2156 case HAL_PRIME_CHNL_OFFSET_LOWER
:
2157 ptxdesc
->data_sc
= 1;
2160 case HAL_PRIME_CHNL_OFFSET_UPPER
:
2161 ptxdesc
->data_sc
= 2;
2165 ptxdesc
->data_sc
= 3; /* Duplicate */
2171 static void rtl8723a_fill_default_txdesc(struct xmit_frame
*pxmitframe
,
2174 struct rtw_adapter
*padapter
;
2175 struct hal_data_8723a
*pHalData
;
2176 struct dm_priv
*pdmpriv
;
2177 struct mlme_ext_priv
*pmlmeext
;
2178 struct mlme_ext_info
*pmlmeinfo
;
2179 struct pkt_attrib
*pattrib
;
2180 struct txdesc_8723a
*ptxdesc
;
2183 padapter
= pxmitframe
->padapter
;
2184 pHalData
= GET_HAL_DATA(padapter
);
2185 pdmpriv
= &pHalData
->dmpriv
;
2186 pmlmeext
= &padapter
->mlmeextpriv
;
2187 pmlmeinfo
= &pmlmeext
->mlmext_info
;
2189 pattrib
= &pxmitframe
->attrib
;
2190 bmcst
= is_multicast_ether_addr(pattrib
->ra
);
2192 ptxdesc
= (struct txdesc_8723a
*)pbuf
;
2194 if (pxmitframe
->frame_tag
== DATA_FRAMETAG
) {
2195 ptxdesc
->macid
= pattrib
->mac_id
; /* CAM_ID(MAC_ID) */
2197 if (pattrib
->ampdu_en
== true)
2198 ptxdesc
->agg_en
= 1; /* AGG EN */
2200 ptxdesc
->bk
= 1; /* AGG BK */
2202 ptxdesc
->qsel
= pattrib
->qsel
;
2203 ptxdesc
->rate_id
= pattrib
->raid
;
2205 fill_txdesc_sectype(pattrib
, ptxdesc
);
2207 ptxdesc
->seq
= pattrib
->seqnum
;
2209 if ((pattrib
->ether_type
!= 0x888e) &&
2210 (pattrib
->ether_type
!= 0x0806) &&
2211 (pattrib
->dhcp_pkt
!= 1)) {
2212 /* Non EAP & ARP & DHCP type data packet */
2214 fill_txdesc_vcs(pattrib
, ptxdesc
);
2215 fill_txdesc_phy(pattrib
, ptxdesc
);
2217 ptxdesc
->rtsrate
= 8; /* RTS Rate = 24M */
2218 ptxdesc
->data_ratefb_lmt
= 0x1F;
2219 ptxdesc
->rts_ratefb_lmt
= 0xF;
2221 /* use REG_INIDATA_RATE_SEL value */
2223 pdmpriv
->INIDATA_RATE
[pattrib
->mac_id
];
2226 /* EAP data packet and ARP packet. */
2227 /* Use the 1M data rate to send the EAP/ARP packet. */
2228 /* This will maybe make the handshake smooth. */
2230 ptxdesc
->bk
= 1; /* AGG BK */
2231 ptxdesc
->userate
= 1; /* driver uses rate */
2232 if (pmlmeinfo
->preamble_mode
== PREAMBLE_SHORT
)
2233 ptxdesc
->data_short
= 1;
2234 ptxdesc
->datarate
= MRateToHwRate23a(pmlmeext
->tx_rate
);
2236 } else if (pxmitframe
->frame_tag
== MGNT_FRAMETAG
) {
2237 /* RT_TRACE(_module_hal_xmit_c_, _drv_notice_,
2238 ("%s: MGNT_FRAMETAG\n", __func__)); */
2240 ptxdesc
->macid
= pattrib
->mac_id
; /* CAM_ID(MAC_ID) */
2241 ptxdesc
->qsel
= pattrib
->qsel
;
2242 ptxdesc
->rate_id
= pattrib
->raid
; /* Rate ID */
2243 ptxdesc
->seq
= pattrib
->seqnum
;
2244 ptxdesc
->userate
= 1; /* driver uses rate, 1M */
2245 ptxdesc
->rty_lmt_en
= 1; /* retry limit enable */
2246 ptxdesc
->data_rt_lmt
= 6; /* retry limit = 6 */
2248 /* CCX-TXRPT ack for xmit mgmt frames. */
2249 if (pxmitframe
->ack_report
)
2252 ptxdesc
->datarate
= MRateToHwRate23a(pmlmeext
->tx_rate
);
2253 } else if (pxmitframe
->frame_tag
== TXAGG_FRAMETAG
) {
2254 RT_TRACE(_module_hal_xmit_c_
, _drv_warning_
,
2255 ("%s: TXAGG_FRAMETAG\n", __func__
));
2257 RT_TRACE(_module_hal_xmit_c_
, _drv_warning_
,
2258 ("%s: frame_tag = 0x%x\n", __func__
,
2259 pxmitframe
->frame_tag
));
2261 ptxdesc
->macid
= 4; /* CAM_ID(MAC_ID) */
2262 ptxdesc
->rate_id
= 6; /* Rate ID */
2263 ptxdesc
->seq
= pattrib
->seqnum
;
2264 ptxdesc
->userate
= 1; /* driver uses rate */
2265 ptxdesc
->datarate
= MRateToHwRate23a(pmlmeext
->tx_rate
);
2268 ptxdesc
->pktlen
= pattrib
->last_txcmdsz
;
2269 ptxdesc
->offset
= TXDESC_SIZE
+ OFFSET_SZ
;
2276 /* 2009.11.05. tynli_test. Suggested by SD4 Filen for FW LPS. */
2277 /* (1) The sequence number of each non-Qos frame / broadcast /
2278 * multicast / mgnt frame should be controled by Hw because Fw
2279 * will also send null data which we cannot control when Fw LPS enable.
2280 * --> default enable non-Qos data sequense number.
2281 2010.06.23. by tynli. */
2282 /* (2) Enable HW SEQ control for beacon packet,
2283 * because we use Hw beacon. */
2284 /* (3) Use HW Qos SEQ to control the seq num of Ext port
2285 * non-Qos packets. */
2286 /* 2010.06.23. Added by tynli. */
2287 if (!pattrib
->qos_en
) {
2288 /* Hw set sequence number */
2289 ptxdesc
->hwseq_en
= 1; /* HWSEQ_EN */
2290 ptxdesc
->hwseq_sel
= 0; /* HWSEQ_SEL */
2298 * pxmitframe xmitframe
2299 * pbuf where to fill tx desc
2301 void rtl8723a_update_txdesc(struct xmit_frame
*pxmitframe
, u8
*pbuf
)
2303 struct tx_desc
*pdesc
;
2305 pdesc
= (struct tx_desc
*)pbuf
;
2306 memset(pdesc
, 0, sizeof(struct tx_desc
));
2308 rtl8723a_fill_default_txdesc(pxmitframe
, pbuf
);
2310 pdesc
->txdw0
= cpu_to_le32(pdesc
->txdw0
);
2311 pdesc
->txdw1
= cpu_to_le32(pdesc
->txdw1
);
2312 pdesc
->txdw2
= cpu_to_le32(pdesc
->txdw2
);
2313 pdesc
->txdw3
= cpu_to_le32(pdesc
->txdw3
);
2314 pdesc
->txdw4
= cpu_to_le32(pdesc
->txdw4
);
2315 pdesc
->txdw5
= cpu_to_le32(pdesc
->txdw5
);
2316 pdesc
->txdw6
= cpu_to_le32(pdesc
->txdw6
);
2317 pdesc
->txdw7
= cpu_to_le32(pdesc
->txdw7
);
2318 rtl8723a_cal_txdesc_chksum(pdesc
);
2322 * Description: In normal chip, we should send some packet to Hw which
2323 * will be used by Fw in FW LPS mode. The function is to fill the Tx
2324 * descriptor of this packets, then
2326 /* Fw can tell Hw to send these packet derectly. */
2327 /* Added by tynli. 2009.10.15. */
2329 void rtl8723a_fill_fake_txdesc(struct rtw_adapter
*padapter
, u8
*pDesc
,
2330 u32 BufferLen
, u8 IsPsPoll
, u8 IsBTQosNull
)
2332 struct tx_desc
*ptxdesc
;
2334 /* Clear all status */
2335 ptxdesc
= (struct tx_desc
*)pDesc
;
2336 memset(pDesc
, 0, TXDESC_SIZE
);
2339 /* own, bFirstSeg, bLastSeg; */
2340 ptxdesc
->txdw0
|= cpu_to_le32(OWN
| FSG
| LSG
);
2342 /* 32 bytes for TX Desc */
2343 ptxdesc
->txdw0
|= cpu_to_le32(((TXDESC_SIZE
+ OFFSET_SZ
) <<
2344 OFFSET_SHT
) & 0x00ff0000);
2346 /* Buffer size + command header */
2347 ptxdesc
->txdw0
|= cpu_to_le32(BufferLen
& 0x0000ffff);
2350 /* Fixed queue of Mgnt queue */
2351 ptxdesc
->txdw1
|= cpu_to_le32((QSLT_MGNT
<< QSEL_SHT
) & 0x00001f00);
2353 /* Set NAVUSEHDR to prevent Ps-poll AId filed to be changed
2354 to error vlaue by Hw. */
2356 ptxdesc
->txdw1
|= cpu_to_le32(NAVUSEHDR
);
2358 /* Hw set sequence number */
2359 ptxdesc
->txdw4
|= cpu_to_le32(BIT(7));
2360 /* set bit3 to 1. Suugested by TimChen. 2009.12.29. */
2361 ptxdesc
->txdw3
|= cpu_to_le32((8 << 28));
2364 if (true == IsBTQosNull
) {
2365 ptxdesc
->txdw2
|= cpu_to_le32(BIT(23)); /* BT NULL */
2369 ptxdesc
->txdw4
|= cpu_to_le32(BIT(8)); /* driver uses rate */
2371 /* USB interface drop packet if the checksum of descriptor isn't
2373 /* Using this checksum can let hardware recovery from packet bulk
2374 out error (e.g. Cancel URC, Bulk out error.). */
2375 rtl8723a_cal_txdesc_chksum(ptxdesc
);
2378 void hw_var_set_opmode(struct rtw_adapter
*padapter
, u8 mode
)
2382 if ((mode
== _HW_STATE_STATION_
) || (mode
== _HW_STATE_NOLINK_
)) {
2383 StopTxBeacon(padapter
);
2385 /* disable atim wnd */
2386 val8
= DIS_TSF_UDT
| EN_BCN_FUNCTION
| DIS_ATIM
;
2387 SetBcnCtrlReg23a(padapter
, val8
, ~val8
);
2388 } else if ((mode
== _HW_STATE_ADHOC_
) /*|| (mode == _HW_STATE_AP_) */) {
2389 ResumeTxBeacon(padapter
);
2391 val8
= DIS_TSF_UDT
| EN_BCN_FUNCTION
| DIS_BCNQ_SUB
;
2392 SetBcnCtrlReg23a(padapter
, val8
, ~val8
);
2393 } else if (mode
== _HW_STATE_AP_
) {
2394 /* add NULL Data and BT NULL Data Packets to FW RSVD Page */
2395 rtl8723a_set_BTCoex_AP_mode_FwRsvdPkt_cmd(padapter
);
2397 ResumeTxBeacon(padapter
);
2399 val8
= DIS_TSF_UDT
| DIS_BCNQ_SUB
;
2400 SetBcnCtrlReg23a(padapter
, val8
, ~val8
);
2403 /* rtl8723au_write32(padapter, REG_RCR, 0x70002a8e);
2404 CBSSID_DATA must set to 0 */
2405 /* CBSSID_DATA must set to 0 */
2406 rtl8723au_write32(padapter
, REG_RCR
, 0x7000228e);
2407 /* enable to rx data frame */
2408 rtl8723au_write16(padapter
, REG_RXFLTMAP2
, 0xFFFF);
2409 /* enable to rx ps-poll */
2410 rtl8723au_write16(padapter
, REG_RXFLTMAP1
, 0x0400);
2412 /* Beacon Control related register for first time */
2414 rtl8723au_write8(padapter
, REG_BCNDMATIM
, 0x02);
2416 rtl8723au_write8(padapter
, REG_DRVERLYINT
, 0x05);
2417 /* 10ms for port0 */
2418 rtl8723au_write8(padapter
, REG_ATIMWND
, 0x0a);
2419 rtl8723au_write16(padapter
, REG_BCNTCFG
, 0x00);
2420 rtl8723au_write16(padapter
, REG_TBTT_PROHIBIT
, 0xff04);
2421 /* +32767 (~32ms) */
2422 rtl8723au_write16(padapter
, REG_TSFTR_SYN_OFFSET
, 0x7fff);
2425 rtl8723au_write8(padapter
, REG_DUAL_TSF_RST
, BIT(0));
2427 /* enable BCN Function */
2428 /* don't enable update TSF (due to TSF update when
2429 beacon/probe rsp are received) */
2430 val8
= DIS_TSF_UDT
| EN_BCN_FUNCTION
|
2431 EN_TXBCN_RPT
| DIS_BCNQ_SUB
;
2432 SetBcnCtrlReg23a(padapter
, val8
, ~val8
);
2435 val8
= rtl8723au_read8(padapter
, MSR
);
2436 val8
= (val8
& 0xC) | mode
;
2437 rtl8723au_write8(padapter
, MSR
, val8
);
2440 void hw_var_set_macaddr(struct rtw_adapter
*padapter
, u8
*val
)
2445 reg_macid
= REG_MACID
;
2447 for (idx
= 0; idx
< 6; idx
++)
2448 rtl8723au_write8(padapter
, (reg_macid
+ idx
), val
[idx
]);
2451 void hw_var_set_bssid(struct rtw_adapter
*padapter
, u8
*val
)
2456 reg_bssid
= REG_BSSID
;
2458 for (idx
= 0; idx
< 6; idx
++)
2459 rtl8723au_write8(padapter
, (reg_bssid
+ idx
), val
[idx
]);
2462 void hw_var_set_correct_tsf(struct rtw_adapter
*padapter
)
2466 struct mlme_ext_priv
*pmlmeext
= &padapter
->mlmeextpriv
;
2467 struct mlme_ext_info
*pmlmeinfo
= &pmlmeext
->mlmext_info
;
2469 /* tsf = pmlmeext->TSFValue - ((u32)pmlmeext->TSFValue %
2470 (pmlmeinfo->bcn_interval*1024)) - 1024; us */
2471 tsf
= pmlmeext
->TSFValue
-
2472 do_div(pmlmeext
->TSFValue
,
2473 (pmlmeinfo
->bcn_interval
* 1024)) - 1024; /* us */
2475 if (((pmlmeinfo
->state
& 0x03) == WIFI_FW_ADHOC_STATE
) ||
2476 ((pmlmeinfo
->state
& 0x03) == WIFI_FW_AP_STATE
)) {
2477 /* pHalData->RegTxPause |= STOP_BCNQ;BIT(6) */
2478 /* rtl8723au_write8(padapter, REG_TXPAUSE,
2479 (rtl8723au_read8(Adapter, REG_TXPAUSE)|BIT(6))); */
2480 StopTxBeacon(padapter
);
2483 reg_tsftr
= REG_TSFTR
;
2485 /* disable related TSF function */
2486 SetBcnCtrlReg23a(padapter
, 0, EN_BCN_FUNCTION
);
2488 rtl8723au_write32(padapter
, reg_tsftr
, tsf
);
2489 rtl8723au_write32(padapter
, reg_tsftr
+ 4, tsf
>> 32);
2491 /* enable related TSF function */
2492 SetBcnCtrlReg23a(padapter
, EN_BCN_FUNCTION
, 0);
2494 if (((pmlmeinfo
->state
& 0x03) == WIFI_FW_ADHOC_STATE
) ||
2495 ((pmlmeinfo
->state
& 0x03) == WIFI_FW_AP_STATE
))
2496 ResumeTxBeacon(padapter
);
2499 void hw_var_set_mlme_disconnect(struct rtw_adapter
*padapter
)
2501 /* reject all data frames */
2502 rtl8723au_write16(padapter
, REG_RXFLTMAP2
, 0);
2505 rtl8723au_write8(padapter
, REG_DUAL_TSF_RST
, BIT(0));
2507 /* disable update TSF */
2508 SetBcnCtrlReg23a(padapter
, DIS_TSF_UDT
, 0);
2511 void hw_var_set_mlme_join(struct rtw_adapter
*padapter
, u8 type
)
2513 u8 RetryLimit
= 0x30;
2515 struct hal_data_8723a
*pHalData
= GET_HAL_DATA(padapter
);
2516 struct mlme_priv
*pmlmepriv
= &padapter
->mlmepriv
;
2518 if (type
== 0) { /* prepare to join */
2521 /* enable to rx data frame.Accept all data frame */
2522 /* rtl8723au_write32(padapter, REG_RCR,
2523 rtl8723au_read32(padapter, REG_RCR)|RCR_ADF); */
2524 rtl8723au_write16(padapter
, REG_RXFLTMAP2
, 0xFFFF);
2526 v32
= rtl8723au_read32(padapter
, REG_RCR
);
2527 v32
|= RCR_CBSSID_DATA
| RCR_CBSSID_BCN
;
2528 rtl8723au_write32(padapter
, REG_RCR
, v32
);
2530 if (check_fwstate(pmlmepriv
, WIFI_STATION_STATE
) == true)
2532 (pHalData
->CustomerID
== RT_CID_CCX
) ? 7 : 48;
2533 else /* Ad-hoc Mode */
2535 } else if (type
== 1) { /* joinbss_event callback when join res < 0 */
2536 /* config RCR to receive different BSSID & not to
2537 receive data frame during linking */
2538 rtl8723au_write16(padapter
, REG_RXFLTMAP2
, 0);
2539 } else if (type
== 2) { /* sta add event callback */
2540 /* enable update TSF */
2541 SetBcnCtrlReg23a(padapter
, 0, DIS_TSF_UDT
);
2543 if (check_fwstate(pmlmepriv
,
2544 WIFI_ADHOC_STATE
| WIFI_ADHOC_MASTER_STATE
)) {
2545 /* fixed beacon issue for 8191su........... */
2546 rtl8723au_write8(padapter
, 0x542, 0x02);
2551 rtl8723au_write16(padapter
, REG_RL
,
2552 RetryLimit
<< RETRY_LIMIT_SHORT_SHIFT
| RetryLimit
<<
2553 RETRY_LIMIT_LONG_SHIFT
);
2557 /* prepare to join */
2558 rtl8723a_BT_wifiassociate_notify(padapter
, true);
2561 /* joinbss_event callback when join res < 0 */
2562 rtl8723a_BT_wifiassociate_notify(padapter
, false);
2565 /* sta add event callback */
2566 /* BT_WifiMediaStatusNotify(padapter, RT_MEDIA_CONNECT); */