1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 ******************************************************************************/
15 #define _HAL_INIT_C_
16
17 #include <linux/firmware.h>
18 #include <drv_types.h>
19 #include <rtw_efuse.h>
20
21 #include <rtl8723a_hal.h>
22 #include <usb_ops_linux.h>
23
_FWDownloadEnable(struct rtw_adapter * padapter,bool enable)24 static void _FWDownloadEnable(struct rtw_adapter *padapter, bool enable)
25 {
26 u8 tmp;
27
28 if (enable) {
29 /* 8051 enable */
30 tmp = rtl8723au_read8(padapter, REG_SYS_FUNC_EN + 1);
31 rtl8723au_write8(padapter, REG_SYS_FUNC_EN + 1, tmp | 0x04);
32
33 /* MCU firmware download enable. */
34 tmp = rtl8723au_read8(padapter, REG_MCUFWDL);
35 rtl8723au_write8(padapter, REG_MCUFWDL, tmp | 0x01);
36
37 /* 8051 reset */
38 tmp = rtl8723au_read8(padapter, REG_MCUFWDL + 2);
39 rtl8723au_write8(padapter, REG_MCUFWDL + 2, tmp & 0xf7);
40 } else {
41 /* MCU firmware download disable. */
42 tmp = rtl8723au_read8(padapter, REG_MCUFWDL);
43 rtl8723au_write8(padapter, REG_MCUFWDL, tmp & 0xfe);
44
45 /* Reserved for fw extension. */
46 rtl8723au_write8(padapter, REG_MCUFWDL + 1, 0x00);
47 }
48 }
49
_BlockWrite(struct rtw_adapter * padapter,void * buffer,u32 buffSize)50 static int _BlockWrite(struct rtw_adapter *padapter, void *buffer, u32 buffSize)
51 {
52 int ret;
53
54 if (buffSize > MAX_PAGE_SIZE)
55 return _FAIL;
56
57 ret = rtl8723au_writeN(padapter, FW_8723A_START_ADDRESS,
58 buffSize, buffer);
59
60 return ret;
61 }
62
63 static int
_PageWrite(struct rtw_adapter * padapter,u32 page,void * buffer,u32 size)64 _PageWrite(struct rtw_adapter *padapter, u32 page, void *buffer, u32 size)
65 {
66 u8 value8;
67 u8 u8Page = (u8) (page & 0x07);
68
69 value8 = (rtl8723au_read8(padapter, REG_MCUFWDL + 2) & 0xF8) | u8Page;
70 rtl8723au_write8(padapter, REG_MCUFWDL + 2, value8);
71
72 return _BlockWrite(padapter, buffer, size);
73 }
74
_WriteFW(struct rtw_adapter * padapter,void * buffer,u32 size)75 static int _WriteFW(struct rtw_adapter *padapter, void *buffer, u32 size)
76 {
77 /* Since we need dynamic decide method of dwonload fw, so we
78 call this function to get chip version. */
79 /* We can remove _ReadChipVersion from ReadpadapterInfo8192C later. */
80 int ret = _SUCCESS;
81 u32 pageNums, remainSize;
82 u32 page, offset;
83 u8 *bufferPtr = (u8 *) buffer;
84
85 pageNums = size / MAX_PAGE_SIZE;
86 /* RT_ASSERT((pageNums <= 4),
87 ("Page numbers should not greater then 4 \n")); */
88 remainSize = size % MAX_PAGE_SIZE;
89
90 for (page = 0; page < pageNums; page++) {
91 offset = page * MAX_PAGE_SIZE;
92 ret = _PageWrite(padapter, page, bufferPtr + offset,
93 MAX_PAGE_SIZE);
94
95 if (ret == _FAIL)
96 goto exit;
97 }
98 if (remainSize) {
99 offset = pageNums * MAX_PAGE_SIZE;
100 page = pageNums;
101 ret = _PageWrite(padapter, page, bufferPtr + offset,
102 remainSize);
103
104 if (ret == _FAIL)
105 goto exit;
106 }
107 RT_TRACE(_module_hal_init_c_, _drv_info_,
108 ("_WriteFW Done- for Normal chip.\n"));
109
110 exit:
111 return ret;
112 }
113
_FWFreeToGo(struct rtw_adapter * padapter)114 static int _FWFreeToGo(struct rtw_adapter *padapter)
115 {
116 u32 counter = 0;
117 u32 value32;
118
119 /* polling CheckSum report */
120 do {
121 value32 = rtl8723au_read32(padapter, REG_MCUFWDL);
122 if (value32 & FWDL_ChkSum_rpt)
123 break;
124 } while (counter++ < POLLING_READY_TIMEOUT_COUNT);
125
126 if (counter >= POLLING_READY_TIMEOUT_COUNT) {
127 RT_TRACE(_module_hal_init_c_, _drv_err_,
128 ("%s: chksum report fail! REG_MCUFWDL:0x%08x\n",
129 __func__, value32));
130 return _FAIL;
131 }
132 RT_TRACE(_module_hal_init_c_, _drv_info_,
133 ("%s: Checksum report OK! REG_MCUFWDL:0x%08x\n", __func__,
134 value32));
135
136 value32 = rtl8723au_read32(padapter, REG_MCUFWDL);
137 value32 |= MCUFWDL_RDY;
138 value32 &= ~WINTINI_RDY;
139 rtl8723au_write32(padapter, REG_MCUFWDL, value32);
140
141 /* polling for FW ready */
142 counter = 0;
143 do {
144 value32 = rtl8723au_read32(padapter, REG_MCUFWDL);
145 if (value32 & WINTINI_RDY) {
146 RT_TRACE(_module_hal_init_c_, _drv_info_,
147 ("%s: Polling FW ready success!! "
148 "REG_MCUFWDL:0x%08x\n",
149 __func__, value32));
150 return _SUCCESS;
151 }
152 udelay(5);
153 } while (counter++ < POLLING_READY_TIMEOUT_COUNT);
154
155 RT_TRACE(_module_hal_init_c_, _drv_err_,
156 ("%s: Polling FW ready fail!! REG_MCUFWDL:0x%08x\n",
157 __func__, value32));
158 return _FAIL;
159 }
160
161 #define IS_FW_81xxC(padapter) (((GET_HAL_DATA(padapter))->FirmwareSignature & 0xFFF0) == 0x88C0)
162
rtl8723a_FirmwareSelfReset(struct rtw_adapter * padapter)163 void rtl8723a_FirmwareSelfReset(struct rtw_adapter *padapter)
164 {
165 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
166 u8 u1bTmp;
167 u8 Delay = 100;
168
169 if (!(IS_FW_81xxC(padapter) &&
170 ((pHalData->FirmwareVersion < 0x21) ||
171 (pHalData->FirmwareVersion == 0x21 &&
172 pHalData->FirmwareSubVersion < 0x01)))) {
173 /* after 88C Fw v33.1 */
174 /* 0x1cf = 0x20. Inform 8051 to reset. 2009.12.25. tynli_test */
175 rtl8723au_write8(padapter, REG_HMETFR + 3, 0x20);
176
177 u1bTmp = rtl8723au_read8(padapter, REG_SYS_FUNC_EN + 1);
178 while (u1bTmp & BIT(2)) {
179 Delay--;
180 if (Delay == 0)
181 break;
182 udelay(50);
183 u1bTmp = rtl8723au_read8(padapter, REG_SYS_FUNC_EN + 1);
184 }
185 RT_TRACE(_module_hal_init_c_, _drv_info_,
186 ("-%s: 8051 reset success (%d)\n", __func__,
187 Delay));
188
189 if ((Delay == 0)) {
190 /* force firmware reset */
191 u1bTmp = rtl8723au_read8(padapter, REG_SYS_FUNC_EN + 1);
192 rtl8723au_write8(padapter, REG_SYS_FUNC_EN + 1,
193 u1bTmp & ~BIT(2));
194 }
195 }
196 }
197
198 /* */
199 /* Description: */
200 /* Download 8192C firmware code. */
201 /* */
202 /* */
rtl8723a_FirmwareDownload(struct rtw_adapter * padapter)203 int rtl8723a_FirmwareDownload(struct rtw_adapter *padapter)
204 {
205 int rtStatus = _SUCCESS;
206 u8 writeFW_retry = 0;
207 unsigned long fwdl_start_time;
208 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
209 struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
210 struct device *device = dvobj_to_dev(dvobj);
211 struct rt_8723a_firmware_hdr *pFwHdr = NULL;
212 const struct firmware *fw;
213 char *fw_name;
214 u8 *firmware_buf = NULL;
215 u8 *buf;
216 int fw_size;
217 static int log_version;
218
219 RT_TRACE(_module_hal_init_c_, _drv_info_, ("+%s\n", __func__));
220
221 if (IS_8723A_A_CUT(pHalData->VersionID)) {
222 fw_name = "rtlwifi/rtl8723aufw_A.bin";
223 RT_TRACE(_module_hal_init_c_, _drv_info_,
224 ("rtl8723a_FirmwareDownload: R8723FwImageArray_UMC "
225 "for RTL8723A A CUT\n"));
226 } else if (IS_8723A_B_CUT(pHalData->VersionID)) {
227 /* WLAN Fw. */
228 if (padapter->registrypriv.wifi_spec == 1) {
229 fw_name = "rtlwifi/rtl8723aufw_B_NoBT.bin";
230 DBG_8723A(" Rtl8723_FwUMCBCutImageArrayWithoutBT for "
231 "RTL8723A B CUT\n");
232 } else {
233 if (rtl8723a_BT_coexist(padapter)) {
234 fw_name = "rtlwifi/rtl8723aufw_B.bin";
235 DBG_8723A(" Rtl8723_FwUMCBCutImageArrayWithBT "
236 "for RTL8723A B CUT\n");
237 } else {
238 fw_name = "rtlwifi/rtl8723aufw_B_NoBT.bin";
239 DBG_8723A(" Rtl8723_FwUMCBCutImageArrayWithout "
240 "BT for RTL8723A B CUT\n");
241 }
242 }
243 } else {
244 /* <Roger_TODO> We should download proper RAM Code here
245 to match the ROM code. */
246 RT_TRACE(_module_hal_init_c_, _drv_err_,
247 ("%s: unknow version!\n", __func__));
248 rtStatus = _FAIL;
249 goto Exit;
250 }
251
252 pr_info("rtl8723au: Loading firmware %s\n", fw_name);
253 if (request_firmware(&fw, fw_name, device)) {
254 pr_err("rtl8723au: request_firmware load failed\n");
255 rtStatus = _FAIL;
256 goto Exit;
257 }
258 if (!fw) {
259 pr_err("rtl8723au: Firmware %s not available\n", fw_name);
260 rtStatus = _FAIL;
261 goto Exit;
262 }
263 firmware_buf = kmemdup(fw->data, fw->size, GFP_KERNEL);
264 if (!firmware_buf) {
265 rtStatus = _FAIL;
266 goto Exit;
267 }
268 buf = firmware_buf;
269 fw_size = fw->size;
270 release_firmware(fw);
271
272 /* To Check Fw header. Added by tynli. 2009.12.04. */
273 pFwHdr = (struct rt_8723a_firmware_hdr *)firmware_buf;
274
275 pHalData->FirmwareVersion = le16_to_cpu(pFwHdr->Version);
276 pHalData->FirmwareSubVersion = pFwHdr->Subversion;
277 pHalData->FirmwareSignature = le16_to_cpu(pFwHdr->Signature);
278
279 DBG_8723A("%s: fw_ver =%d fw_subver =%d sig = 0x%x\n",
280 __func__, pHalData->FirmwareVersion,
281 pHalData->FirmwareSubVersion, pHalData->FirmwareSignature);
282
283 if (!log_version++)
284 pr_info("%sFirmware Version %d, SubVersion %d, Signature "
285 "0x%x\n", DRIVER_PREFIX, pHalData->FirmwareVersion,
286 pHalData->FirmwareSubVersion,
287 pHalData->FirmwareSignature);
288
289 if (IS_FW_HEADER_EXIST(pFwHdr)) {
290 /* Shift 32 bytes for FW header */
291 buf = buf + 32;
292 fw_size = fw_size - 32;
293 }
294
295 /* Suggested by Filen. If 8051 is running in RAM code, driver should
296 inform Fw to reset by itself, */
297 /* or it will cause download Fw fail. 2010.02.01. by tynli. */
298 if (rtl8723au_read8(padapter, REG_MCUFWDL) & RAM_DL_SEL) {
299 /* 8051 RAM code */
300 rtl8723a_FirmwareSelfReset(padapter);
301 rtl8723au_write8(padapter, REG_MCUFWDL, 0x00);
302 }
303
304 _FWDownloadEnable(padapter, true);
305 fwdl_start_time = jiffies;
306 while (1) {
307 /* reset the FWDL chksum */
308 rtl8723au_write8(padapter, REG_MCUFWDL,
309 rtl8723au_read8(padapter, REG_MCUFWDL) |
310 FWDL_ChkSum_rpt);
311
312 rtStatus = _WriteFW(padapter, buf, fw_size);
313
314 if (rtStatus == _SUCCESS ||
315 (jiffies_to_msecs(jiffies - fwdl_start_time) > 500 &&
316 writeFW_retry++ >= 3))
317 break;
318
319 DBG_8723A("%s writeFW_retry:%u, time after fwdl_start_time:"
320 "%ums\n", __func__, writeFW_retry,
321 jiffies_to_msecs(jiffies - fwdl_start_time));
322 }
323 _FWDownloadEnable(padapter, false);
324 if (_SUCCESS != rtStatus) {
325 DBG_8723A("DL Firmware failed!\n");
326 goto Exit;
327 }
328
329 rtStatus = _FWFreeToGo(padapter);
330 if (_SUCCESS != rtStatus) {
331 RT_TRACE(_module_hal_init_c_, _drv_err_,
332 ("DL Firmware failed!\n"));
333 goto Exit;
334 }
335 RT_TRACE(_module_hal_init_c_, _drv_info_,
336 ("Firmware is ready to run!\n"));
337
338 Exit:
339 kfree(firmware_buf);
340 return rtStatus;
341 }
342
rtl8723a_InitializeFirmwareVars(struct rtw_adapter * padapter)343 void rtl8723a_InitializeFirmwareVars(struct rtw_adapter *padapter)
344 {
345 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
346
347 /* Init Fw LPS related. */
348 padapter->pwrctrlpriv.bFwCurrentInPSMode = false;
349
350 /* Init H2C counter. by tynli. 2009.12.09. */
351 pHalData->LastHMEBoxNum = 0;
352 }
353
354 /* */
355 /* Efuse related code */
356 /* */
357 static u8
hal_EfuseSwitchToBank(struct rtw_adapter * padapter,u8 bank)358 hal_EfuseSwitchToBank(struct rtw_adapter *padapter, u8 bank)
359 {
360 u8 bRet = false;
361 u32 value32 = 0;
362
363 DBG_8723A("%s: Efuse switch bank to %d\n", __func__, bank);
364 value32 = rtl8723au_read32(padapter, EFUSE_TEST);
365 bRet = true;
366 switch (bank) {
367 case 0:
368 value32 = (value32 & ~EFUSE_SEL_MASK) |
369 EFUSE_SEL(EFUSE_WIFI_SEL_0);
370 break;
371 case 1:
372 value32 = (value32 & ~EFUSE_SEL_MASK) |
373 EFUSE_SEL(EFUSE_BT_SEL_0);
374 break;
375 case 2:
376 value32 = (value32 & ~EFUSE_SEL_MASK) |
377 EFUSE_SEL(EFUSE_BT_SEL_1);
378 break;
379 case 3:
380 value32 = (value32 & ~EFUSE_SEL_MASK) |
381 EFUSE_SEL(EFUSE_BT_SEL_2);
382 break;
383 default:
384 value32 = (value32 & ~EFUSE_SEL_MASK) |
385 EFUSE_SEL(EFUSE_WIFI_SEL_0);
386 bRet = false;
387 break;
388 }
389 rtl8723au_write32(padapter, EFUSE_TEST, value32);
390
391 return bRet;
392 }
393
394 static void
hal_ReadEFuse_WiFi(struct rtw_adapter * padapter,u16 _offset,u16 _size_byte,u8 * pbuf)395 hal_ReadEFuse_WiFi(struct rtw_adapter *padapter,
396 u16 _offset, u16 _size_byte, u8 *pbuf)
397 {
398 u8 *efuseTbl = NULL;
399 u16 eFuse_Addr = 0;
400 u8 offset, wden;
401 u8 efuseHeader, efuseExtHdr, efuseData;
402 u16 i, total, used;
403 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
404
405 /* Do NOT excess total size of EFuse table.
406 Added by Roger, 2008.11.10. */
407 if ((_offset + _size_byte) > EFUSE_MAP_LEN_8723A) {
408 DBG_8723A("%s: Invalid offset(%#x) with read bytes(%#x)!!\n",
409 __func__, _offset, _size_byte);
410 return;
411 }
412
413 efuseTbl = kmalloc(EFUSE_MAP_LEN_8723A, GFP_KERNEL);
414 if (efuseTbl == NULL) {
415 DBG_8723A("%s: alloc efuseTbl fail!\n", __func__);
416 return;
417 }
418 /* 0xff will be efuse default value instead of 0x00. */
419 memset(efuseTbl, 0xFF, EFUSE_MAP_LEN_8723A);
420
421 /* switch bank back to bank 0 for later BT and wifi use. */
422 hal_EfuseSwitchToBank(padapter, 0);
423
424 while (AVAILABLE_EFUSE_ADDR(eFuse_Addr)) {
425 ReadEFuseByte23a(padapter, eFuse_Addr++, &efuseHeader);
426 if (efuseHeader == 0xFF) {
427 DBG_8723A("%s: data end at address =%#x\n", __func__,
428 eFuse_Addr);
429 break;
430 }
431
432 /* Check PG header for section num. */
433 if (EXT_HEADER(efuseHeader)) { /* extended header */
434 offset = GET_HDR_OFFSET_2_0(efuseHeader);
435
436 ReadEFuseByte23a(padapter, eFuse_Addr++, &efuseExtHdr);
437 if (ALL_WORDS_DISABLED(efuseExtHdr)) {
438 continue;
439 }
440
441 offset |= ((efuseExtHdr & 0xF0) >> 1);
442 wden = (efuseExtHdr & 0x0F);
443 } else {
444 offset = ((efuseHeader >> 4) & 0x0f);
445 wden = (efuseHeader & 0x0f);
446 }
447
448 if (offset < EFUSE_MAX_SECTION_8723A) {
449 u16 addr;
450 /* Get word enable value from PG header */
451
452 addr = offset * PGPKT_DATA_SIZE;
453 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
454 /* Check word enable condition in the section */
455 if (!(wden & (0x01 << i))) {
456 ReadEFuseByte23a(padapter, eFuse_Addr++,
457 &efuseData);
458 efuseTbl[addr] = efuseData;
459
460 ReadEFuseByte23a(padapter, eFuse_Addr++,
461 &efuseData);
462 efuseTbl[addr + 1] = efuseData;
463 }
464 addr += 2;
465 }
466 } else {
467 DBG_8723A(KERN_ERR "%s: offset(%d) is illegal!!\n",
468 __func__, offset);
469 eFuse_Addr += Efuse_CalculateWordCnts23a(wden) * 2;
470 }
471 }
472
473 /* Copy from Efuse map to output pointer memory!!! */
474 for (i = 0; i < _size_byte; i++)
475 pbuf[i] = efuseTbl[_offset + i];
476
477 /* Calculate Efuse utilization */
478 EFUSE_GetEfuseDefinition23a(padapter, EFUSE_WIFI,
479 TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, &total);
480 used = eFuse_Addr - 1;
481 pHalData->EfuseUsedBytes = used;
482
483 kfree(efuseTbl);
484 }
485
486 static void
hal_ReadEFuse_BT(struct rtw_adapter * padapter,u16 _offset,u16 _size_byte,u8 * pbuf)487 hal_ReadEFuse_BT(struct rtw_adapter *padapter,
488 u16 _offset, u16 _size_byte, u8 *pbuf)
489 {
490 u8 *efuseTbl;
491 u8 bank;
492 u16 eFuse_Addr;
493 u8 efuseHeader, efuseExtHdr, efuseData;
494 u8 offset, wden;
495 u16 i, total, used;
496 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
497
498 /* Do NOT excess total size of EFuse table.
499 Added by Roger, 2008.11.10. */
500 if ((_offset + _size_byte) > EFUSE_BT_MAP_LEN) {
501 DBG_8723A("%s: Invalid offset(%#x) with read bytes(%#x)!!\n",
502 __func__, _offset, _size_byte);
503 return;
504 }
505
506 efuseTbl = kmalloc(EFUSE_BT_MAP_LEN, GFP_KERNEL);
507 if (efuseTbl == NULL) {
508 DBG_8723A("%s: efuseTbl malloc fail!\n", __func__);
509 return;
510 }
511 /* 0xff will be efuse default value instead of 0x00. */
512 memset(efuseTbl, 0xFF, EFUSE_BT_MAP_LEN);
513
514 EFUSE_GetEfuseDefinition23a(padapter, EFUSE_BT,
515 TYPE_AVAILABLE_EFUSE_BYTES_BANK, &total);
516
517 for (bank = 1; bank < EFUSE_MAX_BANK; bank++) {
518 if (hal_EfuseSwitchToBank(padapter, bank) == false) {
519 DBG_8723A("%s: hal_EfuseSwitchToBank Fail!!\n",
520 __func__);
521 goto exit;
522 }
523
524 eFuse_Addr = 0;
525
526 while (AVAILABLE_EFUSE_ADDR(eFuse_Addr)) {
527 ReadEFuseByte23a(padapter, eFuse_Addr++, &efuseHeader);
528 if (efuseHeader == 0xFF)
529 break;
530
531 /* Check PG header for section num. */
532 if (EXT_HEADER(efuseHeader)) { /* extended header */
533 offset = GET_HDR_OFFSET_2_0(efuseHeader);
534
535 ReadEFuseByte23a(padapter, eFuse_Addr++,
536 &efuseExtHdr);
537 if (ALL_WORDS_DISABLED(efuseExtHdr)) {
538 continue;
539 }
540
541 offset |= ((efuseExtHdr & 0xF0) >> 1);
542 wden = (efuseExtHdr & 0x0F);
543 } else {
544 offset = ((efuseHeader >> 4) & 0x0f);
545 wden = (efuseHeader & 0x0f);
546 }
547
548 if (offset < EFUSE_BT_MAX_SECTION) {
549 u16 addr;
550
551 /* Get word enable value from PG header */
552
553 addr = offset * PGPKT_DATA_SIZE;
554 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
555 /* Check word enable condition in
556 the section */
557 if (!(wden & (0x01 << i))) {
558 ReadEFuseByte23a(padapter,
559 eFuse_Addr++,
560 &efuseData);
561 efuseTbl[addr] = efuseData;
562
563 ReadEFuseByte23a(padapter,
564 eFuse_Addr++,
565 &efuseData);
566 efuseTbl[addr + 1] = efuseData;
567 }
568 addr += 2;
569 }
570 } else {
571 DBG_8723A(KERN_ERR
572 "%s: offset(%d) is illegal!!\n",
573 __func__, offset);
574 eFuse_Addr += Efuse_CalculateWordCnts23a(wden) * 2;
575 }
576 }
577
578 if ((eFuse_Addr - 1) < total) {
579 DBG_8723A("%s: bank(%d) data end at %#x\n",
580 __func__, bank, eFuse_Addr - 1);
581 break;
582 }
583 }
584
585 /* switch bank back to bank 0 for later BT and wifi use. */
586 hal_EfuseSwitchToBank(padapter, 0);
587
588 /* Copy from Efuse map to output pointer memory!!! */
589 for (i = 0; i < _size_byte; i++)
590 pbuf[i] = efuseTbl[_offset + i];
591
592 /* */
593 /* Calculate Efuse utilization. */
594 /* */
595 EFUSE_GetEfuseDefinition23a(padapter, EFUSE_BT,
596 TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, &total);
597 used = (EFUSE_BT_REAL_BANK_CONTENT_LEN * (bank - 1)) + eFuse_Addr - 1;
598 pHalData->BTEfuseUsedBytes = used;
599
600 exit:
601 kfree(efuseTbl);
602 }
603
604 void
rtl8723a_readefuse(struct rtw_adapter * padapter,u8 efuseType,u16 _offset,u16 _size_byte,u8 * pbuf)605 rtl8723a_readefuse(struct rtw_adapter *padapter,
606 u8 efuseType, u16 _offset, u16 _size_byte, u8 *pbuf)
607 {
608 if (efuseType == EFUSE_WIFI)
609 hal_ReadEFuse_WiFi(padapter, _offset, _size_byte, pbuf);
610 else
611 hal_ReadEFuse_BT(padapter, _offset, _size_byte, pbuf);
612 }
613
rtl8723a_EfuseGetCurrentSize_WiFi(struct rtw_adapter * padapter)614 u16 rtl8723a_EfuseGetCurrentSize_WiFi(struct rtw_adapter *padapter)
615 {
616 u16 efuse_addr = 0;
617 u8 hoffset = 0, hworden = 0;
618 u8 efuse_data, word_cnts = 0;
619 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
620
621 efuse_addr = pHalData->EfuseUsedBytes;
622
623 DBG_8723A("%s: start_efuse_addr = 0x%X\n", __func__, efuse_addr);
624
625 /* switch bank back to bank 0 for later BT and wifi use. */
626 hal_EfuseSwitchToBank(padapter, 0);
627
628 while (AVAILABLE_EFUSE_ADDR(efuse_addr)) {
629 if (efuse_OneByteRead23a(padapter, efuse_addr, &efuse_data) ==
630 _FAIL) {
631 DBG_8723A(KERN_ERR "%s: efuse_OneByteRead23a Fail! "
632 "addr = 0x%X !!\n", __func__, efuse_addr);
633 break;
634 }
635
636 if (efuse_data == 0xFF)
637 break;
638
639 if (EXT_HEADER(efuse_data)) {
640 hoffset = GET_HDR_OFFSET_2_0(efuse_data);
641 efuse_addr++;
642 efuse_OneByteRead23a(padapter, efuse_addr, &efuse_data);
643 if (ALL_WORDS_DISABLED(efuse_data)) {
644 continue;
645 }
646
647 hoffset |= ((efuse_data & 0xF0) >> 1);
648 hworden = efuse_data & 0x0F;
649 } else {
650 hoffset = (efuse_data >> 4) & 0x0F;
651 hworden = efuse_data & 0x0F;
652 }
653
654 word_cnts = Efuse_CalculateWordCnts23a(hworden);
655 efuse_addr += (word_cnts * 2) + 1;
656 }
657
658 pHalData->EfuseUsedBytes = efuse_addr;
659
660 DBG_8723A("%s: CurrentSize =%d\n", __func__, efuse_addr);
661
662 return efuse_addr;
663 }
664
rtl8723a_EfuseGetCurrentSize_BT(struct rtw_adapter * padapter)665 u16 rtl8723a_EfuseGetCurrentSize_BT(struct rtw_adapter *padapter)
666 {
667 u16 btusedbytes;
668 u16 efuse_addr;
669 u8 bank, startBank;
670 u8 hoffset = 0, hworden = 0;
671 u8 efuse_data, word_cnts = 0;
672 u16 retU2 = 0;
673 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
674
675 btusedbytes = pHalData->BTEfuseUsedBytes;
676
677 efuse_addr = (u16) ((btusedbytes % EFUSE_BT_REAL_BANK_CONTENT_LEN));
678 startBank = (u8) (1 + (btusedbytes / EFUSE_BT_REAL_BANK_CONTENT_LEN));
679
680 DBG_8723A("%s: start from bank =%d addr = 0x%X\n", __func__, startBank,
681 efuse_addr);
682
683 EFUSE_GetEfuseDefinition23a(padapter, EFUSE_BT,
684 TYPE_AVAILABLE_EFUSE_BYTES_BANK, &retU2);
685
686 for (bank = startBank; bank < EFUSE_MAX_BANK; bank++) {
687 if (hal_EfuseSwitchToBank(padapter, bank) == false) {
688 DBG_8723A(KERN_ERR "%s: switch bank(%d) Fail!!\n",
689 __func__, bank);
690 bank = EFUSE_MAX_BANK;
691 break;
692 }
693
694 /* only when bank is switched we have to reset
695 the efuse_addr. */
696 if (bank != startBank)
697 efuse_addr = 0;
698
699 while (AVAILABLE_EFUSE_ADDR(efuse_addr)) {
700 if (efuse_OneByteRead23a(padapter, efuse_addr,
701 &efuse_data) == _FAIL) {
702 DBG_8723A(KERN_ERR "%s: efuse_OneByteRead23a Fail!"
703 " addr = 0x%X !!\n",
704 __func__, efuse_addr);
705 bank = EFUSE_MAX_BANK;
706 break;
707 }
708
709 if (efuse_data == 0xFF)
710 break;
711
712 if (EXT_HEADER(efuse_data)) {
713 hoffset = GET_HDR_OFFSET_2_0(efuse_data);
714 efuse_addr++;
715 efuse_OneByteRead23a(padapter, efuse_addr,
716 &efuse_data);
717 if (ALL_WORDS_DISABLED(efuse_data)) {
718 efuse_addr++;
719 continue;
720 }
721
722 hoffset |= ((efuse_data & 0xF0) >> 1);
723 hworden = efuse_data & 0x0F;
724 } else {
725 hoffset = (efuse_data >> 4) & 0x0F;
726 hworden = efuse_data & 0x0F;
727 }
728 word_cnts = Efuse_CalculateWordCnts23a(hworden);
729 /* read next header */
730 efuse_addr += (word_cnts * 2) + 1;
731 }
732
733 /* Check if we need to check next bank efuse */
734 if (efuse_addr < retU2) {
735 break; /* don't need to check next bank. */
736 }
737 }
738
739 retU2 = ((bank - 1) * EFUSE_BT_REAL_BANK_CONTENT_LEN) + efuse_addr;
740 pHalData->BTEfuseUsedBytes = retU2;
741
742 DBG_8723A("%s: CurrentSize =%d\n", __func__, retU2);
743 return retU2;
744 }
745
746 bool
rtl8723a_EfusePgPacketRead(struct rtw_adapter * padapter,u8 offset,u8 * data)747 rtl8723a_EfusePgPacketRead(struct rtw_adapter *padapter, u8 offset, u8 *data)
748 {
749 u8 efuse_data, word_cnts = 0;
750 u16 efuse_addr = 0;
751 u8 hoffset = 0, hworden = 0;
752 u8 i;
753 u8 max_section = 0;
754 s32 ret;
755
756 if (data == NULL)
757 return false;
758
759 EFUSE_GetEfuseDefinition23a(padapter, EFUSE_WIFI, TYPE_EFUSE_MAX_SECTION,
760 &max_section);
761 if (offset > max_section) {
762 DBG_8723A("%s: Packet offset(%d) is illegal(>%d)!\n",
763 __func__, offset, max_section);
764 return false;
765 }
766
767 memset(data, 0xFF, PGPKT_DATA_SIZE);
768 ret = true;
769
770 /* */
771 /* <Roger_TODO> Efuse has been pre-programmed dummy 5Bytes at the
772 end of Efuse by CP. */
773 /* Skip dummy parts to prevent unexpected data read from Efuse. */
774 /* By pass right now. 2009.02.19. */
775 /* */
776 while (AVAILABLE_EFUSE_ADDR(efuse_addr)) {
777 if (efuse_OneByteRead23a(padapter, efuse_addr++, &efuse_data) ==
778 _FAIL) {
779 ret = false;
780 break;
781 }
782
783 if (efuse_data == 0xFF)
784 break;
785
786 if (EXT_HEADER(efuse_data)) {
787 hoffset = GET_HDR_OFFSET_2_0(efuse_data);
788 efuse_OneByteRead23a(padapter, efuse_addr++, &efuse_data);
789 if (ALL_WORDS_DISABLED(efuse_data)) {
790 DBG_8723A("%s: Error!! All words disabled!\n",
791 __func__);
792 continue;
793 }
794
795 hoffset |= ((efuse_data & 0xF0) >> 1);
796 hworden = efuse_data & 0x0F;
797 } else {
798 hoffset = (efuse_data >> 4) & 0x0F;
799 hworden = efuse_data & 0x0F;
800 }
801
802 if (hoffset == offset) {
803 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
804 /* Check word enable condition in the section */
805 if (!(hworden & (0x01 << i))) {
806 ReadEFuseByte23a(padapter, efuse_addr++,
807 &efuse_data);
808 data[i * 2] = efuse_data;
809
810 ReadEFuseByte23a(padapter, efuse_addr++,
811 &efuse_data);
812 data[(i * 2) + 1] = efuse_data;
813 }
814 }
815 } else {
816 word_cnts = Efuse_CalculateWordCnts23a(hworden);
817 efuse_addr += word_cnts * 2;
818 }
819 }
820
821 return ret;
822 }
823
rtl8723a_read_chip_version(struct rtw_adapter * padapter)824 void rtl8723a_read_chip_version(struct rtw_adapter *padapter)
825 {
826 u32 value32;
827 struct hal_version ChipVersion;
828 struct hal_data_8723a *pHalData;
829
830 pHalData = GET_HAL_DATA(padapter);
831
832 value32 = rtl8723au_read32(padapter, REG_SYS_CFG);
833 ChipVersion.ICType = CHIP_8723A;
834 ChipVersion.ChipType = ((value32 & RTL_ID) ? TEST_CHIP : NORMAL_CHIP);
835 ChipVersion.RFType = RF_TYPE_1T1R;
836 ChipVersion.VendorType =
837 ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : CHIP_VENDOR_TSMC);
838 ChipVersion.CUTVersion = (value32 & CHIP_VER_RTL_MASK) >> CHIP_VER_RTL_SHIFT; /* IC version (CUT) */
839
840 /* For regulator mode. by tynli. 2011.01.14 */
841 pHalData->RegulatorMode = ((value32 & SPS_SEL) ?
842 RT_LDO_REGULATOR : RT_SWITCHING_REGULATOR);
843
844 value32 = rtl8723au_read32(padapter, REG_GPIO_OUTSTS);
845 /* ROM code version. */
846 ChipVersion.ROMVer = ((value32 & RF_RL_ID) >> 20);
847
848 /* For multi-function consideration. Added by Roger, 2010.10.06. */
849 pHalData->MultiFunc = RT_MULTI_FUNC_NONE;
850 value32 = rtl8723au_read32(padapter, REG_MULTI_FUNC_CTRL);
851 pHalData->MultiFunc |=
852 ((value32 & WL_FUNC_EN) ? RT_MULTI_FUNC_WIFI : 0);
853 pHalData->MultiFunc |= ((value32 & BT_FUNC_EN) ? RT_MULTI_FUNC_BT : 0);
854 pHalData->MultiFunc |=
855 ((value32 & GPS_FUNC_EN) ? RT_MULTI_FUNC_GPS : 0);
856 pHalData->PolarityCtl =
857 ((value32 & WL_HWPDN_SL) ? RT_POLARITY_HIGH_ACT :
858 RT_POLARITY_LOW_ACT);
859 dump_chip_info23a(ChipVersion);
860 pHalData->VersionID = ChipVersion;
861
862 if (IS_1T2R(ChipVersion))
863 pHalData->rf_type = RF_1T2R;
864 else if (IS_2T2R(ChipVersion))
865 pHalData->rf_type = RF_2T2R;
866 else
867 pHalData->rf_type = RF_1T1R;
868
869 MSG_8723A("RF_Type is %x!!\n", pHalData->rf_type);
870 }
871
872 /* */
873 /* */
874 /* 20100209 Joseph: */
875 /* This function is used only for 92C to set REG_BCN_CTRL(0x550) register. */
876 /* We just reserve the value of the register in variable
877 pHalData->RegBcnCtrlVal and then operate */
878 /* the value of the register via atomic operation. */
879 /* This prevents from race condition when setting this register. */
880 /* The value of pHalData->RegBcnCtrlVal is initialized in
881 HwConfigureRTL8192CE() function. */
882 /* */
SetBcnCtrlReg23a(struct rtw_adapter * padapter,u8 SetBits,u8 ClearBits)883 void SetBcnCtrlReg23a(struct rtw_adapter *padapter, u8 SetBits, u8 ClearBits)
884 {
885 u8 val8;
886
887 val8 = rtl8723au_read8(padapter, REG_BCN_CTRL);
888 val8 |= SetBits;
889 val8 &= ~ClearBits;
890
891 rtl8723au_write8(padapter, REG_BCN_CTRL, val8);
892 }
893
rtl8723a_InitBeaconParameters(struct rtw_adapter * padapter)894 void rtl8723a_InitBeaconParameters(struct rtw_adapter *padapter)
895 {
896 rtl8723au_write16(padapter, REG_BCN_CTRL, 0x1010);
897
898 /* TODO: Remove these magic number */
899 rtl8723au_write16(padapter, REG_TBTT_PROHIBIT, 0x6404); /* ms */
900 /* Firmware will control REG_DRVERLYINT when power saving is enable, */
901 /* so don't set this register on STA mode. */
902 if (check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE) == false)
903 rtl8723au_write8(padapter, REG_DRVERLYINT,
904 DRIVER_EARLY_INT_TIME);
905 /* 2ms */
906 rtl8723au_write8(padapter, REG_BCNDMATIM, BCN_DMA_ATIME_INT_TIME);
907
908 /* Suggested by designer timchen. Change beacon AIFS to the
909 largest number beacause test chip does not contension before
910 sending beacon. by tynli. 2009.11.03 */
911 rtl8723au_write16(padapter, REG_BCNTCFG, 0x660F);
912 }
913
ResumeTxBeacon(struct rtw_adapter * padapter)914 static void ResumeTxBeacon(struct rtw_adapter *padapter)
915 {
916 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
917
918 /* 2010.03.01. Marked by tynli. No need to call workitem beacause
919 we record the value */
920 /* which should be read from register to a global variable. */
921
922 RT_TRACE(_module_hci_hal_init_c_, _drv_info_, ("+ResumeTxBeacon\n"));
923
924 pHalData->RegFwHwTxQCtrl |= BIT(6);
925 rtl8723au_write8(padapter, REG_FWHW_TXQ_CTRL + 2,
926 pHalData->RegFwHwTxQCtrl);
927 rtl8723au_write8(padapter, REG_TBTT_PROHIBIT + 1, 0xff);
928 pHalData->RegReg542 |= BIT(0);
929 rtl8723au_write8(padapter, REG_TBTT_PROHIBIT + 2, pHalData->RegReg542);
930 }
931
StopTxBeacon(struct rtw_adapter * padapter)932 static void StopTxBeacon(struct rtw_adapter *padapter)
933 {
934 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
935
936 /* 2010.03.01. Marked by tynli. No need to call workitem beacause
937 we record the value */
938 /* which should be read from register to a global variable. */
939
940 RT_TRACE(_module_hci_hal_init_c_, _drv_info_, ("+StopTxBeacon\n"));
941
942 pHalData->RegFwHwTxQCtrl &= ~BIT(6);
943 rtl8723au_write8(padapter, REG_FWHW_TXQ_CTRL + 2,
944 pHalData->RegFwHwTxQCtrl);
945 rtl8723au_write8(padapter, REG_TBTT_PROHIBIT + 1, 0x64);
946 pHalData->RegReg542 &= ~BIT(0);
947 rtl8723au_write8(padapter, REG_TBTT_PROHIBIT + 2, pHalData->RegReg542);
948 }
949
_BeaconFunctionEnable(struct rtw_adapter * padapter,u8 Enable,u8 Linked)950 static void _BeaconFunctionEnable(struct rtw_adapter *padapter, u8 Enable,
951 u8 Linked)
952 {
953 SetBcnCtrlReg23a(padapter, DIS_TSF_UDT | EN_BCN_FUNCTION | DIS_BCNQ_SUB,
954 0);
955 rtl8723au_write8(padapter, REG_RD_CTRL + 1, 0x6F);
956 }
957
rtl8723a_SetBeaconRelatedRegisters(struct rtw_adapter * padapter)958 void rtl8723a_SetBeaconRelatedRegisters(struct rtw_adapter *padapter)
959 {
960 u32 value32;
961 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
962 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
963
964 /* reset TSF, enable update TSF, correcting TSF On Beacon */
965
966 /* REG_BCN_INTERVAL */
967 /* REG_BCNDMATIM */
968 /* REG_ATIMWND */
969 /* REG_TBTT_PROHIBIT */
970 /* REG_DRVERLYINT */
971 /* REG_BCN_MAX_ERR */
972 /* REG_BCNTCFG (0x510) */
973 /* REG_DUAL_TSF_RST */
974 /* REG_BCN_CTRL (0x550) */
975
976 /* */
977 /* ATIM window */
978 /* */
979 rtl8723au_write16(padapter, REG_ATIMWND, 2);
980
981 /* */
982 /* Beacon interval (in unit of TU). */
983 /* */
984 rtl8723au_write16(padapter, REG_BCN_INTERVAL, pmlmeinfo->bcn_interval);
985
986 rtl8723a_InitBeaconParameters(padapter);
987
988 rtl8723au_write8(padapter, REG_SLOT, 0x09);
989
990 /* */
991 /* Reset TSF Timer to zero, added by Roger. 2008.06.24 */
992 /* */
993 value32 = rtl8723au_read32(padapter, REG_TCR);
994 value32 &= ~TSFRST;
995 rtl8723au_write32(padapter, REG_TCR, value32);
996
997 value32 |= TSFRST;
998 rtl8723au_write32(padapter, REG_TCR, value32);
999
1000 /* NOTE: Fix test chip's bug (about contention windows's randomness) */
1001 if (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE |
1002 WIFI_ADHOC_MASTER_STATE | WIFI_AP_STATE) == true) {
1003 rtl8723au_write8(padapter, REG_RXTSF_OFFSET_CCK, 0x50);
1004 rtl8723au_write8(padapter, REG_RXTSF_OFFSET_OFDM, 0x50);
1005 }
1006
1007 _BeaconFunctionEnable(padapter, true, true);
1008
1009 ResumeTxBeacon(padapter);
1010 SetBcnCtrlReg23a(padapter, DIS_BCNQ_SUB, 0);
1011 }
1012
rtl8723a_SetHalODMVar(struct rtw_adapter * Adapter,enum hal_odm_variable eVariable,void * pValue1,bool bSet)1013 void rtl8723a_SetHalODMVar(struct rtw_adapter *Adapter,
1014 enum hal_odm_variable eVariable,
1015 void *pValue1, bool bSet)
1016 {
1017 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
1018 struct dm_odm_t *podmpriv = &pHalData->odmpriv;
1019 switch (eVariable) {
1020 case HAL_ODM_STA_INFO:
1021 {
1022 struct sta_info *psta = (struct sta_info *)pValue1;
1023
1024 if (bSet) {
1025 DBG_8723A("Set STA_(%d) info\n", psta->mac_id);
1026 ODM_CmnInfoPtrArrayHook23a(podmpriv,
1027 ODM_CMNINFO_STA_STATUS,
1028 psta->mac_id, psta);
1029 } else {
1030 DBG_8723A("Clean STA_(%d) info\n", psta->mac_id);
1031 ODM_CmnInfoPtrArrayHook23a(podmpriv,
1032 ODM_CMNINFO_STA_STATUS,
1033 psta->mac_id, NULL);
1034 }
1035 }
1036 break;
1037 case HAL_ODM_P2P_STATE:
1038 ODM_CmnInfoUpdate23a(podmpriv, ODM_CMNINFO_WIFI_DIRECT, bSet);
1039 break;
1040 case HAL_ODM_WIFI_DISPLAY_STATE:
1041 ODM_CmnInfoUpdate23a(podmpriv, ODM_CMNINFO_WIFI_DISPLAY, bSet);
1042 break;
1043 default:
1044 break;
1045 }
1046 }
1047
rtl8723a_notch_filter(struct rtw_adapter * adapter,bool enable)1048 void rtl8723a_notch_filter(struct rtw_adapter *adapter, bool enable)
1049 {
1050 if (enable) {
1051 DBG_8723A("Enable notch filter\n");
1052 rtl8723au_write8(adapter, rOFDM0_RxDSP + 1,
1053 rtl8723au_read8(adapter, rOFDM0_RxDSP + 1) |
1054 BIT(1));
1055 } else {
1056 DBG_8723A("Disable notch filter\n");
1057 rtl8723au_write8(adapter, rOFDM0_RxDSP + 1,
1058 rtl8723au_read8(adapter, rOFDM0_RxDSP + 1) &
1059 ~BIT(1));
1060 }
1061 }
1062
c2h_id_filter_ccx_8723a(u8 id)1063 bool c2h_id_filter_ccx_8723a(u8 id)
1064 {
1065 bool ret = false;
1066 if (id == C2H_CCX_TX_RPT)
1067 ret = true;
1068
1069 return ret;
1070 }
1071
c2h_handler_8723a(struct rtw_adapter * padapter,struct c2h_evt_hdr * c2h_evt)1072 int c2h_handler_8723a(struct rtw_adapter *padapter, struct c2h_evt_hdr *c2h_evt)
1073 {
1074 int ret = _SUCCESS;
1075 u8 i = 0;
1076
1077 if (c2h_evt == NULL) {
1078 DBG_8723A("%s c2h_evt is NULL\n", __func__);
1079 ret = _FAIL;
1080 goto exit;
1081 }
1082
1083 switch (c2h_evt->id) {
1084 case C2H_DBG:
1085 RT_TRACE(_module_hal_init_c_, _drv_info_,
1086 ("C2HCommandHandler: %s\n", c2h_evt->payload));
1087 break;
1088
1089 case C2H_CCX_TX_RPT:
1090 handle_txrpt_ccx_8723a(padapter, c2h_evt->payload);
1091 break;
1092 case C2H_EXT_RA_RPT:
1093 break;
1094 case C2H_HW_INFO_EXCH:
1095 RT_TRACE(_module_hal_init_c_, _drv_info_,
1096 ("[BT], C2H_HW_INFO_EXCH\n"));
1097 for (i = 0; i < c2h_evt->plen; i++) {
1098 RT_TRACE(_module_hal_init_c_, _drv_info_,
1099 ("[BT], tmpBuf[%d]= 0x%x\n", i,
1100 c2h_evt->payload[i]));
1101 }
1102 break;
1103
1104 case C2H_C2H_H2C_TEST:
1105 RT_TRACE(_module_hal_init_c_, _drv_info_,
1106 ("[BT], C2H_H2C_TEST\n"));
1107 RT_TRACE(_module_hal_init_c_, _drv_info_,
1108 ("[BT], tmpBuf[0]/[1]/[2]/[3]/[4]= 0x%x/ 0x%x/ "
1109 "0x%x/ 0x%x/ 0x%x\n", c2h_evt->payload[0],
1110 c2h_evt->payload[1], c2h_evt->payload[2],
1111 c2h_evt->payload[3], c2h_evt->payload[4]));
1112 break;
1113
1114 case C2H_BT_INFO:
1115 DBG_8723A("%s , Got C2H_BT_INFO \n", __func__);
1116 rtl8723a_fw_c2h_BT_info(padapter,
1117 c2h_evt->payload, c2h_evt->plen);
1118 break;
1119
1120 default:
1121 ret = _FAIL;
1122 break;
1123 }
1124
1125 exit:
1126 return ret;
1127 }
1128
rtl8723a_InitAntenna_Selection(struct rtw_adapter * padapter)1129 void rtl8723a_InitAntenna_Selection(struct rtw_adapter *padapter)
1130 {
1131 u8 val;
1132
1133 val = rtl8723au_read8(padapter, REG_LEDCFG2);
1134 /* Let 8051 take control antenna settting */
1135 val |= BIT(7); /* DPDT_SEL_EN, 0x4C[23] */
1136 rtl8723au_write8(padapter, REG_LEDCFG2, val);
1137 }
1138
rtl8723a_CheckAntenna_Selection(struct rtw_adapter * padapter)1139 void rtl8723a_CheckAntenna_Selection(struct rtw_adapter *padapter)
1140 {
1141 u8 val;
1142
1143 val = rtl8723au_read8(padapter, REG_LEDCFG2);
1144 /* Let 8051 take control antenna settting */
1145 if (!(val & BIT(7))) {
1146 val |= BIT(7); /* DPDT_SEL_EN, 0x4C[23] */
1147 rtl8723au_write8(padapter, REG_LEDCFG2, val);
1148 }
1149 }
1150
rtl8723a_DeinitAntenna_Selection(struct rtw_adapter * padapter)1151 void rtl8723a_DeinitAntenna_Selection(struct rtw_adapter *padapter)
1152 {
1153 u8 val;
1154
1155 val = rtl8723au_read8(padapter, REG_LEDCFG2);
1156 /* Let 8051 take control antenna settting */
1157 val &= ~BIT(7); /* DPDT_SEL_EN, clear 0x4C[23] */
1158 rtl8723au_write8(padapter, REG_LEDCFG2, val);
1159 }
1160
rtl8723a_init_default_value(struct rtw_adapter * padapter)1161 void rtl8723a_init_default_value(struct rtw_adapter *padapter)
1162 {
1163 struct hal_data_8723a *pHalData;
1164 struct dm_priv *pdmpriv;
1165 u8 i;
1166
1167 pHalData = GET_HAL_DATA(padapter);
1168 pdmpriv = &pHalData->dmpriv;
1169
1170 /* init default value */
1171 pHalData->fw_ractrl = false;
1172 pHalData->bIQKInitialized = false;
1173 if (!padapter->pwrctrlpriv.bkeepfwalive)
1174 pHalData->LastHMEBoxNum = 0;
1175
1176 pHalData->bIQKInitialized = false;
1177
1178 /* init dm default value */
1179 pdmpriv->TM_Trigger = 0; /* for IQK */
1180 /* pdmpriv->binitialized = false; */
1181 /* pdmpriv->prv_traffic_idx = 3; */
1182 /* pdmpriv->initialize = 0; */
1183
1184 pdmpriv->ThermalValue_HP_index = 0;
1185 for (i = 0; i < HP_THERMAL_NUM; i++)
1186 pdmpriv->ThermalValue_HP[i] = 0;
1187
1188 /* init Efuse variables */
1189 pHalData->EfuseUsedBytes = 0;
1190 pHalData->BTEfuseUsedBytes = 0;
1191 }
1192
GetEEPROMSize8723A(struct rtw_adapter * padapter)1193 u8 GetEEPROMSize8723A(struct rtw_adapter *padapter)
1194 {
1195 u8 size = 0;
1196 u32 cr;
1197
1198 cr = rtl8723au_read16(padapter, REG_9346CR);
1199 /* 6: EEPROM used is 93C46, 4: boot from E-Fuse. */
1200 size = (cr & BOOT_FROM_EEPROM) ? 6 : 4;
1201
1202 MSG_8723A("EEPROM type is %s\n", size == 4 ? "E-FUSE" : "93C46");
1203
1204 return size;
1205 }
1206
1207 /* */
1208 /* */
1209 /* LLT R/W/Init function */
1210 /* */
1211 /* */
_LLTWrite(struct rtw_adapter * padapter,u32 address,u32 data)1212 static int _LLTWrite(struct rtw_adapter *padapter, u32 address, u32 data)
1213 {
1214 int status = _SUCCESS;
1215 s32 count = 0;
1216 u32 value = _LLT_INIT_ADDR(address) | _LLT_INIT_DATA(data) |
1217 _LLT_OP(_LLT_WRITE_ACCESS);
1218 u16 LLTReg = REG_LLT_INIT;
1219
1220 rtl8723au_write32(padapter, LLTReg, value);
1221
1222 /* polling */
1223 do {
1224 value = rtl8723au_read32(padapter, LLTReg);
1225 if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value)) {
1226 break;
1227 }
1228
1229 if (count > POLLING_LLT_THRESHOLD) {
1230 RT_TRACE(_module_hal_init_c_, _drv_err_,
1231 ("Failed to polling write LLT done at "
1232 "address %d!\n", address));
1233 status = _FAIL;
1234 break;
1235 }
1236 } while (count++);
1237
1238 return status;
1239 }
1240
InitLLTTable23a(struct rtw_adapter * padapter,u32 boundary)1241 int InitLLTTable23a(struct rtw_adapter *padapter, u32 boundary)
1242 {
1243 int status = _SUCCESS;
1244 u32 i;
1245 u32 txpktbuf_bndy = boundary;
1246 u32 Last_Entry_Of_TxPktBuf = LAST_ENTRY_OF_TX_PKT_BUFFER;
1247
1248 for (i = 0; i < (txpktbuf_bndy - 1); i++) {
1249 status = _LLTWrite(padapter, i, i + 1);
1250 if (status != _SUCCESS) {
1251 return status;
1252 }
1253 }
1254
1255 /* end of list */
1256 status = _LLTWrite(padapter, (txpktbuf_bndy - 1), 0xFF);
1257 if (status != _SUCCESS) {
1258 return status;
1259 }
1260
1261 /* Make the other pages as ring buffer */
1262 /* This ring buffer is used as beacon buffer if we config this
1263 MAC as two MAC transfer. */
1264 /* Otherwise used as local loopback buffer. */
1265 for (i = txpktbuf_bndy; i < Last_Entry_Of_TxPktBuf; i++) {
1266 status = _LLTWrite(padapter, i, (i + 1));
1267 if (_SUCCESS != status) {
1268 return status;
1269 }
1270 }
1271
1272 /* Let last entry point to the start entry of ring buffer */
1273 status = _LLTWrite(padapter, Last_Entry_Of_TxPktBuf, txpktbuf_bndy);
1274 if (status != _SUCCESS) {
1275 return status;
1276 }
1277
1278 return status;
1279 }
1280
_DisableGPIO(struct rtw_adapter * padapter)1281 static void _DisableGPIO(struct rtw_adapter *padapter)
1282 {
1283 /***************************************
1284 j. GPIO_PIN_CTRL 0x44[31:0]= 0x000
1285 k.Value = GPIO_PIN_CTRL[7:0]
1286 l. GPIO_PIN_CTRL 0x44[31:0] = 0x00FF0000 | (value <<8); write external PIN level
1287 m. GPIO_MUXCFG 0x42 [15:0] = 0x0780
1288 n. LEDCFG 0x4C[15:0] = 0x8080
1289 ***************************************/
1290 u32 value32;
1291 u32 u4bTmp;
1292
1293 /* 1. Disable GPIO[7:0] */
1294 rtl8723au_write16(padapter, REG_GPIO_PIN_CTRL + 2, 0x0000);
1295 value32 = rtl8723au_read32(padapter, REG_GPIO_PIN_CTRL) & 0xFFFF00FF;
1296 u4bTmp = value32 & 0x000000FF;
1297 value32 |= ((u4bTmp << 8) | 0x00FF0000);
1298 rtl8723au_write32(padapter, REG_GPIO_PIN_CTRL, value32);
1299
1300 /* */
1301 /* <Roger_Notes> For RTL8723u multi-function configuration which
1302 was autoload from Efuse offset 0x0a and 0x0b, */
1303 /* WLAN HW GPIO[9], GPS HW GPIO[10] and BT HW GPIO[11]. */
1304 /* Added by Roger, 2010.10.07. */
1305 /* */
1306 /* 2. Disable GPIO[8] and GPIO[12] */
1307
1308 /* Configure all pins as input mode. */
1309 rtl8723au_write16(padapter, REG_GPIO_IO_SEL_2, 0x0000);
1310 value32 = rtl8723au_read32(padapter, REG_GPIO_PIN_CTRL_2) & 0xFFFF001F;
1311 u4bTmp = value32 & 0x0000001F;
1312 /* Set pin 8, 10, 11 and pin 12 to output mode. */
1313 value32 |= ((u4bTmp << 8) | 0x001D0000);
1314 rtl8723au_write32(padapter, REG_GPIO_PIN_CTRL_2, value32);
1315
1316 /* 3. Disable LED0 & 1 */
1317 rtl8723au_write16(padapter, REG_LEDCFG0, 0x8080);
1318 } /* end of _DisableGPIO() */
1319
_DisableRFAFEAndResetBB8192C(struct rtw_adapter * padapter)1320 static void _DisableRFAFEAndResetBB8192C(struct rtw_adapter *padapter)
1321 {
1322 /**************************************
1323 a. TXPAUSE 0x522[7:0] = 0xFF Pause MAC TX queue
1324 b. RF path 0 offset 0x00 = 0x00 disable RF
1325 c. APSD_CTRL 0x600[7:0] = 0x40
1326 d. SYS_FUNC_EN 0x02[7:0] = 0x16 reset BB state machine
1327 e. SYS_FUNC_EN 0x02[7:0] = 0x14 reset BB state machine
1328 ***************************************/
1329 u8 eRFPath = 0, value8 = 0;
1330
1331 rtl8723au_write8(padapter, REG_TXPAUSE, 0xFF);
1332
1333 PHY_SetRFReg(padapter, (enum RF_RADIO_PATH) eRFPath, 0x0, bMaskByte0, 0x0);
1334
1335 value8 |= APSDOFF;
1336 rtl8723au_write8(padapter, REG_APSD_CTRL, value8); /* 0x40 */
1337
1338 /* Set BB reset at first */
1339 value8 = 0;
1340 value8 |= (FEN_USBD | FEN_USBA | FEN_BB_GLB_RSTn);
1341 rtl8723au_write8(padapter, REG_SYS_FUNC_EN, value8); /* 0x16 */
1342
1343 /* Set global reset. */
1344 value8 &= ~FEN_BB_GLB_RSTn;
1345 rtl8723au_write8(padapter, REG_SYS_FUNC_EN, value8); /* 0x14 */
1346
1347 /* 2010/08/12 MH We need to set BB/GLBAL reset to save power
1348 for SS mode. */
1349
1350 /* RT_TRACE(COMP_INIT, DBG_LOUD, ("======> RF off and reset BB.\n")); */
1351 }
1352
_DisableRFAFEAndResetBB(struct rtw_adapter * padapter)1353 static void _DisableRFAFEAndResetBB(struct rtw_adapter *padapter)
1354 {
1355 _DisableRFAFEAndResetBB8192C(padapter);
1356 }
1357
_ResetDigitalProcedure1_92C(struct rtw_adapter * padapter,bool bWithoutHWSM)1358 static void _ResetDigitalProcedure1_92C(struct rtw_adapter *padapter,
1359 bool bWithoutHWSM)
1360 {
1361 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
1362
1363 if (IS_FW_81xxC(padapter) && (pHalData->FirmwareVersion <= 0x20)) {
1364 /*****************************
1365 f. MCUFWDL 0x80[7:0]= 0 reset MCU ready status
1366 g. SYS_FUNC_EN 0x02[10]= 0 reset MCU register, (8051 reset)
1367 h. SYS_FUNC_EN 0x02[15-12]= 5 reset MAC register, DCORE
1368 i. SYS_FUNC_EN 0x02[10]= 1 enable MCU register,
1369 (8051 enable)
1370 ******************************/
1371 u16 valu16 = 0;
1372 rtl8723au_write8(padapter, REG_MCUFWDL, 0);
1373
1374 valu16 = rtl8723au_read16(padapter, REG_SYS_FUNC_EN);
1375 /* reset MCU , 8051 */
1376 rtl8723au_write16(padapter, REG_SYS_FUNC_EN,
1377 valu16 & (~FEN_CPUEN));
1378
1379 valu16 = rtl8723au_read16(padapter, REG_SYS_FUNC_EN) & 0x0FFF;
1380 /* reset MAC */
1381 rtl8723au_write16(padapter, REG_SYS_FUNC_EN,
1382 valu16 | (FEN_HWPDN | FEN_ELDR));
1383
1384 valu16 = rtl8723au_read16(padapter, REG_SYS_FUNC_EN);
1385 /* enable MCU , 8051 */
1386 rtl8723au_write16(padapter, REG_SYS_FUNC_EN,
1387 valu16 | FEN_CPUEN);
1388 } else {
1389 u8 retry_cnts = 0;
1390
1391 /* 2010/08/12 MH For USB SS, we can not stop 8051 when we
1392 are trying to enter IPS/HW&SW radio off. For
1393 S3/S4/S5/Disable, we can stop 8051 because */
1394 /* we will init FW when power on again. */
1395 /* If we want to SS mode, we can not reset 8051. */
1396 if (rtl8723au_read8(padapter, REG_MCUFWDL) & BIT(1)) {
1397 /* IF fw in RAM code, do reset */
1398 if (padapter->bFWReady) {
1399 /* 2010/08/25 MH Accordign to RD alfred's
1400 suggestion, we need to disable other */
1401 /* HRCV INT to influence 8051 reset. */
1402 rtl8723au_write8(padapter, REG_FWIMR, 0x20);
1403 /* 2011/02/15 MH According to Alex's
1404 suggestion, close mask to prevent
1405 incorrect FW write operation. */
1406 rtl8723au_write8(padapter, REG_FTIMR, 0x00);
1407 rtl8723au_write8(padapter, REG_FSIMR, 0x00);
1408
1409 /* 8051 reset by self */
1410 rtl8723au_write8(padapter, REG_HMETFR + 3,
1411 0x20);
1412
1413 while ((retry_cnts++ < 100) &&
1414 (FEN_CPUEN &
1415 rtl8723au_read16(padapter,
1416 REG_SYS_FUNC_EN))) {
1417 udelay(50); /* us */
1418 }
1419
1420 if (retry_cnts >= 100) {
1421 /* Reset MAC and Enable 8051 */
1422 rtl8723au_write8(padapter,
1423 REG_SYS_FUNC_EN + 1,
1424 0x50);
1425 mdelay(10);
1426 }
1427 }
1428 }
1429 /* Reset MAC and Enable 8051 */
1430 rtl8723au_write8(padapter, REG_SYS_FUNC_EN + 1, 0x54);
1431 rtl8723au_write8(padapter, REG_MCUFWDL, 0);
1432 }
1433
1434 if (bWithoutHWSM) {
1435 /*****************************
1436 Without HW auto state machine
1437 g. SYS_CLKR 0x08[15:0] = 0x30A3 disable MAC clock
1438 h. AFE_PLL_CTRL 0x28[7:0] = 0x80 disable AFE PLL
1439 i. AFE_XTAL_CTRL 0x24[15:0] = 0x880F gated AFE DIG_CLOCK
1440 j. SYS_ISO_CTRL 0x00[7:0] = 0xF9 isolated digital to PON
1441 ******************************/
1442 /* modify to 0x70A3 by Scott. */
1443 rtl8723au_write16(padapter, REG_SYS_CLKR, 0x70A3);
1444 rtl8723au_write8(padapter, REG_AFE_PLL_CTRL, 0x80);
1445 rtl8723au_write16(padapter, REG_AFE_XTAL_CTRL, 0x880F);
1446 rtl8723au_write8(padapter, REG_SYS_ISO_CTRL, 0xF9);
1447 } else {
1448 /* Disable all RF/BB power */
1449 rtl8723au_write8(padapter, REG_RF_CTRL, 0x00);
1450 }
1451 }
1452
_ResetDigitalProcedure1(struct rtw_adapter * padapter,bool bWithoutHWSM)1453 static void _ResetDigitalProcedure1(struct rtw_adapter *padapter,
1454 bool bWithoutHWSM)
1455 {
1456 _ResetDigitalProcedure1_92C(padapter, bWithoutHWSM);
1457 }
1458
_ResetDigitalProcedure2(struct rtw_adapter * padapter)1459 static void _ResetDigitalProcedure2(struct rtw_adapter *padapter)
1460 {
1461 /*****************************
1462 k. SYS_FUNC_EN 0x03[7:0] = 0x44 disable ELDR runction
1463 l. SYS_CLKR 0x08[15:0] = 0x3083 disable ELDR clock
1464 m. SYS_ISO_CTRL 0x01[7:0] = 0x83 isolated ELDR to PON
1465 ******************************/
1466 /* modify to 0x70a3 by Scott. */
1467 rtl8723au_write16(padapter, REG_SYS_CLKR, 0x70a3);
1468 /* modify to 0x82 by Scott. */
1469 rtl8723au_write8(padapter, REG_SYS_ISO_CTRL + 1, 0x82);
1470 }
1471
_DisableAnalog(struct rtw_adapter * padapter,bool bWithoutHWSM)1472 static void _DisableAnalog(struct rtw_adapter *padapter, bool bWithoutHWSM)
1473 {
1474 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
1475 u16 value16 = 0;
1476 u8 value8 = 0;
1477
1478 if (bWithoutHWSM) {
1479 /*****************************
1480 n. LDOA15_CTRL 0x20[7:0] = 0x04 disable A15 power
1481 o. LDOV12D_CTRL 0x21[7:0] = 0x54 disable digital core power
1482 r. When driver call disable, the ASIC will turn off remaining
1483 clock automatically
1484 ******************************/
1485
1486 rtl8723au_write8(padapter, REG_LDOA15_CTRL, 0x04);
1487 /* rtl8723au_write8(padapter, REG_LDOV12D_CTRL, 0x54); */
1488
1489 value8 = rtl8723au_read8(padapter, REG_LDOV12D_CTRL);
1490 value8 &= (~LDV12_EN);
1491 rtl8723au_write8(padapter, REG_LDOV12D_CTRL, value8);
1492 /* RT_TRACE(COMP_INIT, DBG_LOUD,
1493 (" REG_LDOV12D_CTRL Reg0x21:0x%02x.\n", value8)); */
1494 }
1495
1496 /*****************************
1497 h. SPS0_CTRL 0x11[7:0] = 0x23 enter PFM mode
1498 i. APS_FSMCO 0x04[15:0] = 0x4802 set USB suspend
1499 ******************************/
1500 value8 = 0x23;
1501 if (IS_81xxC_VENDOR_UMC_B_CUT(pHalData->VersionID))
1502 value8 |= BIT(3);
1503
1504 rtl8723au_write8(padapter, REG_SPS0_CTRL, value8);
1505
1506 if (bWithoutHWSM) {
1507 /* value16 |= (APDM_HOST | FSM_HSUS |/PFM_ALDN); */
1508 /* 2010/08/31 According to Filen description, we need to
1509 use HW to shut down 8051 automatically. */
1510 /* Becasue suspend operatione need the asistance of 8051
1511 to wait for 3ms. */
1512 value16 |= (APDM_HOST | AFSM_HSUS | PFM_ALDN);
1513 } else {
1514 value16 |= (APDM_HOST | AFSM_HSUS | PFM_ALDN);
1515 }
1516
1517 rtl8723au_write16(padapter, REG_APS_FSMCO, value16); /* 0x4802 */
1518
1519 rtl8723au_write8(padapter, REG_RSV_CTRL, 0x0e);
1520 }
1521
1522 /* HW Auto state machine */
CardDisableHWSM(struct rtw_adapter * padapter,u8 resetMCU)1523 int CardDisableHWSM(struct rtw_adapter *padapter, u8 resetMCU)
1524 {
1525 int rtStatus = _SUCCESS;
1526
1527 if (padapter->bSurpriseRemoved) {
1528 return rtStatus;
1529 }
1530 /* RF Off Sequence ==== */
1531 _DisableRFAFEAndResetBB(padapter);
1532
1533 /* ==== Reset digital sequence ====== */
1534 _ResetDigitalProcedure1(padapter, false);
1535
1536 /* ==== Pull GPIO PIN to balance level and LED control ====== */
1537 _DisableGPIO(padapter);
1538
1539 /* ==== Disable analog sequence === */
1540 _DisableAnalog(padapter, false);
1541
1542 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
1543 ("======> Card disable finished.\n"));
1544
1545 return rtStatus;
1546 }
1547
1548 /* without HW Auto state machine */
CardDisableWithoutHWSM(struct rtw_adapter * padapter)1549 int CardDisableWithoutHWSM(struct rtw_adapter *padapter)
1550 {
1551 int rtStatus = _SUCCESS;
1552
1553 /* RT_TRACE(COMP_INIT, DBG_LOUD,
1554 ("======> Card Disable Without HWSM .\n")); */
1555 if (padapter->bSurpriseRemoved) {
1556 return rtStatus;
1557 }
1558
1559 /* RF Off Sequence ==== */
1560 _DisableRFAFEAndResetBB(padapter);
1561
1562 /* ==== Reset digital sequence ====== */
1563 _ResetDigitalProcedure1(padapter, true);
1564
1565 /* ==== Pull GPIO PIN to balance level and LED control ====== */
1566 _DisableGPIO(padapter);
1567
1568 /* ==== Reset digital sequence ====== */
1569 _ResetDigitalProcedure2(padapter);
1570
1571 /* ==== Disable analog sequence === */
1572 _DisableAnalog(padapter, true);
1573
1574 /* RT_TRACE(COMP_INIT, DBG_LOUD,
1575 ("<====== Card Disable Without HWSM .\n")); */
1576 return rtStatus;
1577 }
1578
Hal_InitPGData(struct rtw_adapter * padapter,u8 * PROMContent)1579 void Hal_InitPGData(struct rtw_adapter *padapter, u8 *PROMContent)
1580 {
1581 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
1582
1583 if (false == pEEPROM->bautoload_fail_flag) { /* autoload OK. */
1584 if (!pEEPROM->EepromOrEfuse) {
1585 /* Read EFUSE real map to shadow. */
1586 EFUSE_ShadowMapUpdate23a(padapter, EFUSE_WIFI);
1587 memcpy((void *)PROMContent,
1588 (void *)pEEPROM->efuse_eeprom_data,
1589 HWSET_MAX_SIZE);
1590 }
1591 } else { /* autoload fail */
1592 RT_TRACE(_module_hci_hal_init_c_, _drv_notice_,
1593 ("AutoLoad Fail reported from CR9346!!\n"));
1594 /* pHalData->AutoloadFailFlag = true; */
1595 /* update to default value 0xFF */
1596 if (false == pEEPROM->EepromOrEfuse)
1597 EFUSE_ShadowMapUpdate23a(padapter, EFUSE_WIFI);
1598 memcpy((void *)PROMContent, (void *)pEEPROM->efuse_eeprom_data,
1599 HWSET_MAX_SIZE);
1600 }
1601 }
1602
Hal_EfuseParseIDCode(struct rtw_adapter * padapter,u8 * hwinfo)1603 void Hal_EfuseParseIDCode(struct rtw_adapter *padapter, u8 *hwinfo)
1604 {
1605 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
1606 /* struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter); */
1607 u16 EEPROMId;
1608
1609 /* Checl 0x8129 again for making sure autoload status!! */
1610 EEPROMId = le16_to_cpu(*((u16 *) hwinfo));
1611 if (EEPROMId != RTL_EEPROM_ID) {
1612 DBG_8723A("EEPROM ID(%#x) is invalid!!\n", EEPROMId);
1613 pEEPROM->bautoload_fail_flag = true;
1614 } else {
1615 pEEPROM->bautoload_fail_flag = false;
1616 }
1617
1618 RT_TRACE(_module_hal_init_c_, _drv_info_,
1619 ("EEPROM ID = 0x%04x\n", EEPROMId));
1620 }
1621
Hal_EEValueCheck(u8 EEType,void * pInValue,void * pOutValue)1622 static void Hal_EEValueCheck(u8 EEType, void *pInValue, void *pOutValue)
1623 {
1624 switch (EEType) {
1625 case EETYPE_TX_PWR:
1626 {
1627 u8 *pIn, *pOut;
1628 pIn = (u8 *) pInValue;
1629 pOut = (u8 *) pOutValue;
1630 if (*pIn <= 63)
1631 *pOut = *pIn;
1632 else {
1633 RT_TRACE(_module_hci_hal_init_c_, _drv_err_,
1634 ("EETYPE_TX_PWR, value =%d is invalid, set "
1635 "to default = 0x%x\n",
1636 *pIn, EEPROM_Default_TxPowerLevel));
1637 *pOut = EEPROM_Default_TxPowerLevel;
1638 }
1639 }
1640 break;
1641 default:
1642 break;
1643 }
1644 }
1645
1646 static void
Hal_ReadPowerValueFromPROM_8723A(struct txpowerinfo * pwrInfo,u8 * PROMContent,bool AutoLoadFail)1647 Hal_ReadPowerValueFromPROM_8723A(struct txpowerinfo *pwrInfo,
1648 u8 *PROMContent, bool AutoLoadFail)
1649 {
1650 u32 rfPath, eeAddr, group, rfPathMax = 1;
1651
1652 memset(pwrInfo, 0, sizeof(*pwrInfo));
1653
1654 if (AutoLoadFail) {
1655 for (group = 0; group < MAX_CHNL_GROUP; group++) {
1656 for (rfPath = 0; rfPath < rfPathMax; rfPath++) {
1657 pwrInfo->CCKIndex[rfPath][group] =
1658 EEPROM_Default_TxPowerLevel;
1659 pwrInfo->HT40_1SIndex[rfPath][group] =
1660 EEPROM_Default_TxPowerLevel;
1661 pwrInfo->HT40_2SIndexDiff[rfPath][group] =
1662 EEPROM_Default_HT40_2SDiff;
1663 pwrInfo->HT20IndexDiff[rfPath][group] =
1664 EEPROM_Default_HT20_Diff;
1665 pwrInfo->OFDMIndexDiff[rfPath][group] =
1666 EEPROM_Default_LegacyHTTxPowerDiff;
1667 pwrInfo->HT40MaxOffset[rfPath][group] =
1668 EEPROM_Default_HT40_PwrMaxOffset;
1669 pwrInfo->HT20MaxOffset[rfPath][group] =
1670 EEPROM_Default_HT20_PwrMaxOffset;
1671 }
1672 }
1673 pwrInfo->TSSI_A[0] = EEPROM_Default_TSSI;
1674 return;
1675 }
1676
1677 for (rfPath = 0; rfPath < rfPathMax; rfPath++) {
1678 for (group = 0; group < MAX_CHNL_GROUP; group++) {
1679 eeAddr =
1680 EEPROM_CCK_TX_PWR_INX_8723A + (rfPath * 3) + group;
1681 /* pwrInfo->CCKIndex[rfPath][group] =
1682 PROMContent[eeAddr]; */
1683 Hal_EEValueCheck(EETYPE_TX_PWR, &PROMContent[eeAddr],
1684 &pwrInfo->CCKIndex[rfPath][group]);
1685 eeAddr = EEPROM_HT40_1S_TX_PWR_INX_8723A +
1686 (rfPath * 3) + group;
1687 /* pwrInfo->HT40_1SIndex[rfPath][group] =
1688 PROMContent[eeAddr]; */
1689 Hal_EEValueCheck(EETYPE_TX_PWR, &PROMContent[eeAddr],
1690 &pwrInfo->HT40_1SIndex[rfPath][group]);
1691 }
1692 }
1693
1694 for (group = 0; group < MAX_CHNL_GROUP; group++) {
1695 for (rfPath = 0; rfPath < rfPathMax; rfPath++) {
1696 pwrInfo->HT40_2SIndexDiff[rfPath][group] = 0;
1697 pwrInfo->HT20IndexDiff[rfPath][group] =
1698 (PROMContent
1699 [EEPROM_HT20_TX_PWR_INX_DIFF_8723A +
1700 group] >> (rfPath * 4)) & 0xF;
1701 /* 4bit sign number to 8 bit sign number */
1702 if (pwrInfo->HT20IndexDiff[rfPath][group] & BIT(3))
1703 pwrInfo->HT20IndexDiff[rfPath][group] |= 0xF0;
1704
1705 pwrInfo->OFDMIndexDiff[rfPath][group] =
1706 (PROMContent[EEPROM_OFDM_TX_PWR_INX_DIFF_8723A +
1707 group] >> (rfPath * 4)) & 0xF;
1708
1709 pwrInfo->HT40MaxOffset[rfPath][group] =
1710 (PROMContent[EEPROM_HT40_MAX_PWR_OFFSET_8723A +
1711 group] >> (rfPath * 4)) & 0xF;
1712
1713 pwrInfo->HT20MaxOffset[rfPath][group] =
1714 (PROMContent[EEPROM_HT20_MAX_PWR_OFFSET_8723A +
1715 group] >> (rfPath * 4)) & 0xF;
1716 }
1717 }
1718
1719 pwrInfo->TSSI_A[0] = PROMContent[EEPROM_TSSI_A_8723A];
1720 }
1721
Hal_GetChnlGroup(u8 chnl)1722 static u8 Hal_GetChnlGroup(u8 chnl)
1723 {
1724 u8 group = 0;
1725
1726 if (chnl < 3) /* Cjanel 1-3 */
1727 group = 0;
1728 else if (chnl < 9) /* Channel 4-9 */
1729 group = 1;
1730 else /* Channel 10-14 */
1731 group = 2;
1732
1733 return group;
1734 }
1735
1736 void
Hal_EfuseParsetxpowerinfo_8723A(struct rtw_adapter * padapter,u8 * PROMContent,bool AutoLoadFail)1737 Hal_EfuseParsetxpowerinfo_8723A(struct rtw_adapter *padapter,
1738 u8 *PROMContent, bool AutoLoadFail)
1739 {
1740 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
1741 struct txpowerinfo pwrInfo;
1742 u8 rfPath, ch, group, rfPathMax = 1;
1743 u8 pwr, diff;
1744
1745 Hal_ReadPowerValueFromPROM_8723A(&pwrInfo, PROMContent, AutoLoadFail);
1746 for (rfPath = 0; rfPath < rfPathMax; rfPath++) {
1747 for (ch = 0; ch < CHANNEL_MAX_NUMBER; ch++) {
1748 group = Hal_GetChnlGroup(ch);
1749
1750 pHalData->TxPwrLevelCck[rfPath][ch] =
1751 pwrInfo.CCKIndex[rfPath][group];
1752 pHalData->TxPwrLevelHT40_1S[rfPath][ch] =
1753 pwrInfo.HT40_1SIndex[rfPath][group];
1754
1755 pHalData->TxPwrHt20Diff[rfPath][ch] =
1756 pwrInfo.HT20IndexDiff[rfPath][group];
1757 pHalData->TxPwrLegacyHtDiff[rfPath][ch] =
1758 pwrInfo.OFDMIndexDiff[rfPath][group];
1759 pHalData->PwrGroupHT20[rfPath][ch] =
1760 pwrInfo.HT20MaxOffset[rfPath][group];
1761 pHalData->PwrGroupHT40[rfPath][ch] =
1762 pwrInfo.HT40MaxOffset[rfPath][group];
1763
1764 pwr = pwrInfo.HT40_1SIndex[rfPath][group];
1765 diff = pwrInfo.HT40_2SIndexDiff[rfPath][group];
1766
1767 pHalData->TxPwrLevelHT40_2S[rfPath][ch] =
1768 (pwr > diff) ? (pwr - diff) : 0;
1769 }
1770 }
1771 for (rfPath = 0; rfPath < RF_PATH_MAX; rfPath++) {
1772 for (ch = 0; ch < CHANNEL_MAX_NUMBER; ch++) {
1773 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
1774 ("RF(%u)-Ch(%u) [CCK / HT40_1S / HT40_2S] = "
1775 "[0x%x / 0x%x / 0x%x]\n",
1776 rfPath, ch,
1777 pHalData->TxPwrLevelCck[rfPath][ch],
1778 pHalData->TxPwrLevelHT40_1S[rfPath][ch],
1779 pHalData->TxPwrLevelHT40_2S[rfPath][ch]));
1780
1781 }
1782 }
1783 for (ch = 0; ch < CHANNEL_MAX_NUMBER; ch++) {
1784 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
1785 ("RF-A Ht20 to HT40 Diff[%u] = 0x%x(%d)\n", ch,
1786 pHalData->TxPwrHt20Diff[RF_PATH_A][ch],
1787 pHalData->TxPwrHt20Diff[RF_PATH_A][ch]));
1788 }
1789 for (ch = 0; ch < CHANNEL_MAX_NUMBER; ch++)
1790 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
1791 ("RF-A Legacy to Ht40 Diff[%u] = 0x%x\n", ch,
1792 pHalData->TxPwrLegacyHtDiff[RF_PATH_A][ch]));
1793 for (ch = 0; ch < CHANNEL_MAX_NUMBER; ch++) {
1794 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
1795 ("RF-B Ht20 to HT40 Diff[%u] = 0x%x(%d)\n", ch,
1796 pHalData->TxPwrHt20Diff[RF_PATH_B][ch],
1797 pHalData->TxPwrHt20Diff[RF_PATH_B][ch]));
1798 }
1799 for (ch = 0; ch < CHANNEL_MAX_NUMBER; ch++)
1800 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
1801 ("RF-B Legacy to HT40 Diff[%u] = 0x%x\n", ch,
1802 pHalData->TxPwrLegacyHtDiff[RF_PATH_B][ch]));
1803 if (!AutoLoadFail) {
1804 struct registry_priv *registry_par = &padapter->registrypriv;
1805 if (registry_par->regulatory_tid == 0xff) {
1806 if (PROMContent[RF_OPTION1_8723A] == 0xff)
1807 pHalData->EEPROMRegulatory = 0;
1808 else
1809 pHalData->EEPROMRegulatory =
1810 PROMContent[RF_OPTION1_8723A] & 0x7;
1811 } else {
1812 pHalData->EEPROMRegulatory =
1813 registry_par->regulatory_tid;
1814 }
1815 } else {
1816 pHalData->EEPROMRegulatory = 0;
1817 }
1818 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
1819 ("EEPROMRegulatory = 0x%x\n", pHalData->EEPROMRegulatory));
1820
1821 if (!AutoLoadFail)
1822 pHalData->bTXPowerDataReadFromEEPORM = true;
1823 }
1824
1825 void
Hal_EfuseParseBTCoexistInfo_8723A(struct rtw_adapter * padapter,u8 * hwinfo,bool AutoLoadFail)1826 Hal_EfuseParseBTCoexistInfo_8723A(struct rtw_adapter *padapter,
1827 u8 *hwinfo, bool AutoLoadFail)
1828 {
1829 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
1830 u8 tempval;
1831 u32 tmpu4;
1832
1833 if (!AutoLoadFail) {
1834 tmpu4 = rtl8723au_read32(padapter, REG_MULTI_FUNC_CTRL);
1835 if (tmpu4 & BT_FUNC_EN)
1836 pHalData->EEPROMBluetoothCoexist = 1;
1837 else
1838 pHalData->EEPROMBluetoothCoexist = 0;
1839 pHalData->EEPROMBluetoothType = BT_RTL8723A;
1840
1841 /* The following need to be checked with newer version of */
1842 /* eeprom spec */
1843 tempval = hwinfo[RF_OPTION4_8723A];
1844 pHalData->EEPROMBluetoothAntNum = (tempval & 0x1);
1845 pHalData->EEPROMBluetoothAntIsolation = ((tempval & 0x10) >> 4);
1846 pHalData->EEPROMBluetoothRadioShared = ((tempval & 0x20) >> 5);
1847 } else {
1848 pHalData->EEPROMBluetoothCoexist = 0;
1849 pHalData->EEPROMBluetoothType = BT_RTL8723A;
1850 pHalData->EEPROMBluetoothAntNum = Ant_x2;
1851 pHalData->EEPROMBluetoothAntIsolation = 0;
1852 pHalData->EEPROMBluetoothRadioShared = BT_Radio_Shared;
1853 }
1854
1855 rtl8723a_BT_init_hal_vars(padapter);
1856 }
1857
1858 void
Hal_EfuseParseEEPROMVer(struct rtw_adapter * padapter,u8 * hwinfo,bool AutoLoadFail)1859 Hal_EfuseParseEEPROMVer(struct rtw_adapter *padapter,
1860 u8 *hwinfo, bool AutoLoadFail)
1861 {
1862 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
1863
1864 if (!AutoLoadFail)
1865 pHalData->EEPROMVersion = hwinfo[EEPROM_VERSION_8723A];
1866 else
1867 pHalData->EEPROMVersion = 1;
1868 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
1869 ("Hal_EfuseParseEEPROMVer(), EEVer = %d\n",
1870 pHalData->EEPROMVersion));
1871 }
1872
1873 void
rtl8723a_EfuseParseChnlPlan(struct rtw_adapter * padapter,u8 * hwinfo,bool AutoLoadFail)1874 rtl8723a_EfuseParseChnlPlan(struct rtw_adapter *padapter,
1875 u8 *hwinfo, bool AutoLoadFail)
1876 {
1877 padapter->mlmepriv.ChannelPlan =
1878 hal_com_get_channel_plan23a(padapter, hwinfo ?
1879 hwinfo[EEPROM_ChannelPlan_8723A]:0xFF,
1880 padapter->registrypriv.channel_plan,
1881 RT_CHANNEL_DOMAIN_WORLD_WIDE_13,
1882 AutoLoadFail);
1883
1884 DBG_8723A("mlmepriv.ChannelPlan = 0x%02x\n",
1885 padapter->mlmepriv.ChannelPlan);
1886 }
1887
1888 void
Hal_EfuseParseCustomerID(struct rtw_adapter * padapter,u8 * hwinfo,bool AutoLoadFail)1889 Hal_EfuseParseCustomerID(struct rtw_adapter *padapter,
1890 u8 *hwinfo, bool AutoLoadFail)
1891 {
1892 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
1893
1894 if (!AutoLoadFail) {
1895 pHalData->EEPROMCustomerID = hwinfo[EEPROM_CustomID_8723A];
1896 pHalData->EEPROMSubCustomerID =
1897 hwinfo[EEPROM_SubCustomID_8723A];
1898 } else {
1899 pHalData->EEPROMCustomerID = 0;
1900 pHalData->EEPROMSubCustomerID = 0;
1901 }
1902 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
1903 ("EEPROM Customer ID: 0x%2x\n", pHalData->EEPROMCustomerID));
1904 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
1905 ("EEPROM SubCustomer ID: 0x%02x\n",
1906 pHalData->EEPROMSubCustomerID));
1907 }
1908
1909 void
Hal_EfuseParseAntennaDiversity(struct rtw_adapter * padapter,u8 * hwinfo,bool AutoLoadFail)1910 Hal_EfuseParseAntennaDiversity(struct rtw_adapter *padapter,
1911 u8 *hwinfo, bool AutoLoadFail)
1912 {
1913 }
1914
1915 void
Hal_EfuseParseRateIndicationOption(struct rtw_adapter * padapter,u8 * hwinfo,bool AutoLoadFail)1916 Hal_EfuseParseRateIndicationOption(struct rtw_adapter *padapter,
1917 u8 *hwinfo, bool AutoLoadFail)
1918 {
1919 }
1920
1921 void
Hal_EfuseParseXtal_8723A(struct rtw_adapter * pAdapter,u8 * hwinfo,u8 AutoLoadFail)1922 Hal_EfuseParseXtal_8723A(struct rtw_adapter *pAdapter,
1923 u8 *hwinfo, u8 AutoLoadFail)
1924 {
1925 struct hal_data_8723a *pHalData = GET_HAL_DATA(pAdapter);
1926
1927 if (!AutoLoadFail) {
1928 pHalData->CrystalCap = hwinfo[EEPROM_XTAL_K_8723A];
1929 if (pHalData->CrystalCap == 0xFF)
1930 pHalData->CrystalCap = EEPROM_Default_CrystalCap_8723A;
1931 } else {
1932 pHalData->CrystalCap = EEPROM_Default_CrystalCap_8723A;
1933 }
1934 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
1935 ("%s: CrystalCap = 0x%2x\n", __func__,
1936 pHalData->CrystalCap));
1937 }
1938
1939 void
Hal_EfuseParseThermalMeter_8723A(struct rtw_adapter * padapter,u8 * PROMContent,bool AutoloadFail)1940 Hal_EfuseParseThermalMeter_8723A(struct rtw_adapter *padapter,
1941 u8 *PROMContent, bool AutoloadFail)
1942 {
1943 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
1944
1945 /* */
1946 /* ThermalMeter from EEPROM */
1947 /* */
1948 if (AutoloadFail == false)
1949 pHalData->EEPROMThermalMeter =
1950 PROMContent[EEPROM_THERMAL_METER_8723A];
1951 else
1952 pHalData->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
1953
1954 if ((pHalData->EEPROMThermalMeter == 0xff) || (AutoloadFail == true)) {
1955 pHalData->bAPKThermalMeterIgnore = true;
1956 pHalData->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
1957 }
1958
1959 DBG_8723A("%s: ThermalMeter = 0x%x\n", __func__,
1960 pHalData->EEPROMThermalMeter);
1961 }
1962
Hal_InitChannelPlan23a(struct rtw_adapter * padapter)1963 void Hal_InitChannelPlan23a(struct rtw_adapter *padapter)
1964 {
1965 }
1966
rtl8723a_cal_txdesc_chksum(struct tx_desc * ptxdesc)1967 static void rtl8723a_cal_txdesc_chksum(struct tx_desc *ptxdesc)
1968 {
1969 u16 *usPtr = (u16 *) ptxdesc;
1970 u32 count = 16; /* (32 bytes / 2 bytes per XOR) => 16 times */
1971 u32 index;
1972 u16 checksum = 0;
1973
1974 /* Clear first */
1975 ptxdesc->txdw7 &= cpu_to_le32(0xffff0000);
1976
1977 for (index = 0; index < count; index++) {
1978 checksum ^= le16_to_cpu(*(usPtr + index));
1979 }
1980
1981 ptxdesc->txdw7 |= cpu_to_le32(checksum & 0x0000ffff);
1982 }
1983
fill_txdesc_sectype(struct pkt_attrib * pattrib,struct txdesc_8723a * ptxdesc)1984 static void fill_txdesc_sectype(struct pkt_attrib *pattrib,
1985 struct txdesc_8723a *ptxdesc)
1986 {
1987 if ((pattrib->encrypt > 0) && !pattrib->bswenc) {
1988 switch (pattrib->encrypt) {
1989 /* SEC_TYPE */
1990 case WLAN_CIPHER_SUITE_WEP40:
1991 case WLAN_CIPHER_SUITE_WEP104:
1992 case WLAN_CIPHER_SUITE_TKIP:
1993 ptxdesc->sectype = 1;
1994 break;
1995
1996 case WLAN_CIPHER_SUITE_CCMP:
1997 ptxdesc->sectype = 3;
1998 break;
1999
2000 case 0:
2001 default:
2002 break;
2003 }
2004 }
2005 }
2006
fill_txdesc_vcs(struct pkt_attrib * pattrib,struct txdesc_8723a * ptxdesc)2007 static void fill_txdesc_vcs(struct pkt_attrib *pattrib,
2008 struct txdesc_8723a *ptxdesc)
2009 {
2010 /* DBG_8723A("cvs_mode =%d\n", pattrib->vcs_mode); */
2011
2012 switch (pattrib->vcs_mode) {
2013 case RTS_CTS:
2014 ptxdesc->rtsen = 1;
2015 break;
2016
2017 case CTS_TO_SELF:
2018 ptxdesc->cts2self = 1;
2019 break;
2020
2021 case NONE_VCS:
2022 default:
2023 break;
2024 }
2025
2026 if (pattrib->vcs_mode) {
2027 ptxdesc->hw_rts_en = 1; /* ENABLE HW RTS */
2028
2029 /* Set RTS BW */
2030 if (pattrib->ht_en) {
2031 if (pattrib->bwmode & HT_CHANNEL_WIDTH_40)
2032 ptxdesc->rts_bw = 1;
2033
2034 switch (pattrib->ch_offset) {
2035 case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
2036 ptxdesc->rts_sc = 0;
2037 break;
2038
2039 case HAL_PRIME_CHNL_OFFSET_LOWER:
2040 ptxdesc->rts_sc = 1;
2041 break;
2042
2043 case HAL_PRIME_CHNL_OFFSET_UPPER:
2044 ptxdesc->rts_sc = 2;
2045 break;
2046
2047 default:
2048 ptxdesc->rts_sc = 3; /* Duplicate */
2049 break;
2050 }
2051 }
2052 }
2053 }
2054
fill_txdesc_phy(struct pkt_attrib * pattrib,struct txdesc_8723a * ptxdesc)2055 static void fill_txdesc_phy(struct pkt_attrib *pattrib,
2056 struct txdesc_8723a *ptxdesc)
2057 {
2058 if (pattrib->ht_en) {
2059 if (pattrib->bwmode & HT_CHANNEL_WIDTH_40)
2060 ptxdesc->data_bw = 1;
2061
2062 switch (pattrib->ch_offset) {
2063 case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
2064 ptxdesc->data_sc = 0;
2065 break;
2066
2067 case HAL_PRIME_CHNL_OFFSET_LOWER:
2068 ptxdesc->data_sc = 1;
2069 break;
2070
2071 case HAL_PRIME_CHNL_OFFSET_UPPER:
2072 ptxdesc->data_sc = 2;
2073 break;
2074
2075 default:
2076 ptxdesc->data_sc = 3; /* Duplicate */
2077 break;
2078 }
2079 }
2080 }
2081
rtl8723a_fill_default_txdesc(struct xmit_frame * pxmitframe,u8 * pbuf)2082 static void rtl8723a_fill_default_txdesc(struct xmit_frame *pxmitframe,
2083 u8 *pbuf)
2084 {
2085 struct rtw_adapter *padapter;
2086 struct hal_data_8723a *pHalData;
2087 struct dm_priv *pdmpriv;
2088 struct mlme_ext_priv *pmlmeext;
2089 struct mlme_ext_info *pmlmeinfo;
2090 struct pkt_attrib *pattrib;
2091 struct txdesc_8723a *ptxdesc;
2092 s32 bmcst;
2093
2094 padapter = pxmitframe->padapter;
2095 pHalData = GET_HAL_DATA(padapter);
2096 pdmpriv = &pHalData->dmpriv;
2097 pmlmeext = &padapter->mlmeextpriv;
2098 pmlmeinfo = &pmlmeext->mlmext_info;
2099
2100 pattrib = &pxmitframe->attrib;
2101 bmcst = is_multicast_ether_addr(pattrib->ra);
2102
2103 ptxdesc = (struct txdesc_8723a *)pbuf;
2104
2105 if (pxmitframe->frame_tag == DATA_FRAMETAG) {
2106 ptxdesc->macid = pattrib->mac_id; /* CAM_ID(MAC_ID) */
2107
2108 if (pattrib->ampdu_en == true)
2109 ptxdesc->agg_en = 1; /* AGG EN */
2110 else
2111 ptxdesc->bk = 1; /* AGG BK */
2112
2113 ptxdesc->qsel = pattrib->qsel;
2114 ptxdesc->rate_id = pattrib->raid;
2115
2116 fill_txdesc_sectype(pattrib, ptxdesc);
2117
2118 ptxdesc->seq = pattrib->seqnum;
2119
2120 if ((pattrib->ether_type != 0x888e) &&
2121 (pattrib->ether_type != 0x0806) &&
2122 (pattrib->dhcp_pkt != 1)) {
2123 /* Non EAP & ARP & DHCP type data packet */
2124
2125 fill_txdesc_vcs(pattrib, ptxdesc);
2126 fill_txdesc_phy(pattrib, ptxdesc);
2127
2128 ptxdesc->rtsrate = 8; /* RTS Rate = 24M */
2129 ptxdesc->data_ratefb_lmt = 0x1F;
2130 ptxdesc->rts_ratefb_lmt = 0xF;
2131
2132 /* use REG_INIDATA_RATE_SEL value */
2133 ptxdesc->datarate =
2134 pdmpriv->INIDATA_RATE[pattrib->mac_id];
2135
2136 } else {
2137 /* EAP data packet and ARP packet. */
2138 /* Use the 1M data rate to send the EAP/ARP packet. */
2139 /* This will maybe make the handshake smooth. */
2140
2141 ptxdesc->bk = 1; /* AGG BK */
2142 ptxdesc->userate = 1; /* driver uses rate */
2143 if (pmlmeinfo->preamble_mode == PREAMBLE_SHORT)
2144 ptxdesc->data_short = 1;
2145 ptxdesc->datarate = MRateToHwRate23a(pmlmeext->tx_rate);
2146 }
2147 } else if (pxmitframe->frame_tag == MGNT_FRAMETAG) {
2148 /* RT_TRACE(_module_hal_xmit_c_, _drv_notice_,
2149 ("%s: MGNT_FRAMETAG\n", __func__)); */
2150
2151 ptxdesc->macid = pattrib->mac_id; /* CAM_ID(MAC_ID) */
2152 ptxdesc->qsel = pattrib->qsel;
2153 ptxdesc->rate_id = pattrib->raid; /* Rate ID */
2154 ptxdesc->seq = pattrib->seqnum;
2155 ptxdesc->userate = 1; /* driver uses rate, 1M */
2156 ptxdesc->rty_lmt_en = 1; /* retry limit enable */
2157 ptxdesc->data_rt_lmt = 6; /* retry limit = 6 */
2158
2159 /* CCX-TXRPT ack for xmit mgmt frames. */
2160 if (pxmitframe->ack_report)
2161 ptxdesc->ccx = 1;
2162
2163 ptxdesc->datarate = MRateToHwRate23a(pmlmeext->tx_rate);
2164 } else if (pxmitframe->frame_tag == TXAGG_FRAMETAG) {
2165 RT_TRACE(_module_hal_xmit_c_, _drv_warning_,
2166 ("%s: TXAGG_FRAMETAG\n", __func__));
2167 } else {
2168 RT_TRACE(_module_hal_xmit_c_, _drv_warning_,
2169 ("%s: frame_tag = 0x%x\n", __func__,
2170 pxmitframe->frame_tag));
2171
2172 ptxdesc->macid = 4; /* CAM_ID(MAC_ID) */
2173 ptxdesc->rate_id = 6; /* Rate ID */
2174 ptxdesc->seq = pattrib->seqnum;
2175 ptxdesc->userate = 1; /* driver uses rate */
2176 ptxdesc->datarate = MRateToHwRate23a(pmlmeext->tx_rate);
2177 }
2178
2179 ptxdesc->pktlen = pattrib->last_txcmdsz;
2180 ptxdesc->offset = TXDESC_SIZE + OFFSET_SZ;
2181 if (bmcst)
2182 ptxdesc->bmc = 1;
2183 ptxdesc->ls = 1;
2184 ptxdesc->fs = 1;
2185 ptxdesc->own = 1;
2186
2187 /* 2009.11.05. tynli_test. Suggested by SD4 Filen for FW LPS. */
2188 /* (1) The sequence number of each non-Qos frame / broadcast /
2189 * multicast / mgnt frame should be controled by Hw because Fw
2190 * will also send null data which we cannot control when Fw LPS enable.
2191 * --> default enable non-Qos data sequense number.
2192 2010.06.23. by tynli. */
2193 /* (2) Enable HW SEQ control for beacon packet,
2194 * because we use Hw beacon. */
2195 /* (3) Use HW Qos SEQ to control the seq num of Ext port
2196 * non-Qos packets. */
2197 /* 2010.06.23. Added by tynli. */
2198 if (!pattrib->qos_en) {
2199 /* Hw set sequence number */
2200 ptxdesc->hwseq_en = 1; /* HWSEQ_EN */
2201 ptxdesc->hwseq_sel = 0; /* HWSEQ_SEL */
2202 }
2203 }
2204
2205 /*
2206 * Description:
2207 *
2208 * Parameters:
2209 * pxmitframe xmitframe
2210 * pbuf where to fill tx desc
2211 */
rtl8723a_update_txdesc(struct xmit_frame * pxmitframe,u8 * pbuf)2212 void rtl8723a_update_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf)
2213 {
2214 struct tx_desc *pdesc;
2215
2216 pdesc = (struct tx_desc *)pbuf;
2217 memset(pdesc, 0, sizeof(struct tx_desc));
2218
2219 rtl8723a_fill_default_txdesc(pxmitframe, pbuf);
2220
2221 pdesc->txdw0 = cpu_to_le32(pdesc->txdw0);
2222 pdesc->txdw1 = cpu_to_le32(pdesc->txdw1);
2223 pdesc->txdw2 = cpu_to_le32(pdesc->txdw2);
2224 pdesc->txdw3 = cpu_to_le32(pdesc->txdw3);
2225 pdesc->txdw4 = cpu_to_le32(pdesc->txdw4);
2226 pdesc->txdw5 = cpu_to_le32(pdesc->txdw5);
2227 pdesc->txdw6 = cpu_to_le32(pdesc->txdw6);
2228 pdesc->txdw7 = cpu_to_le32(pdesc->txdw7);
2229 rtl8723a_cal_txdesc_chksum(pdesc);
2230 }
2231
2232 /*
2233 * Description: In normal chip, we should send some packet to Hw which
2234 * will be used by Fw in FW LPS mode. The function is to fill the Tx
2235 * descriptor of this packets, then
2236 */
2237 /* Fw can tell Hw to send these packet derectly. */
2238 /* Added by tynli. 2009.10.15. */
2239 /* */
rtl8723a_fill_fake_txdesc(struct rtw_adapter * padapter,u8 * pDesc,u32 BufferLen,u8 IsPsPoll,u8 IsBTQosNull)2240 void rtl8723a_fill_fake_txdesc(struct rtw_adapter *padapter, u8 *pDesc,
2241 u32 BufferLen, u8 IsPsPoll, u8 IsBTQosNull)
2242 {
2243 struct tx_desc *ptxdesc;
2244
2245 /* Clear all status */
2246 ptxdesc = (struct tx_desc *)pDesc;
2247 memset(pDesc, 0, TXDESC_SIZE);
2248
2249 /* offset 0 */
2250 /* own, bFirstSeg, bLastSeg; */
2251 ptxdesc->txdw0 |= cpu_to_le32(OWN | FSG | LSG);
2252
2253 /* 32 bytes for TX Desc */
2254 ptxdesc->txdw0 |= cpu_to_le32(((TXDESC_SIZE + OFFSET_SZ) <<
2255 OFFSET_SHT) & 0x00ff0000);
2256
2257 /* Buffer size + command header */
2258 ptxdesc->txdw0 |= cpu_to_le32(BufferLen & 0x0000ffff);
2259
2260 /* offset 4 */
2261 /* Fixed queue of Mgnt queue */
2262 ptxdesc->txdw1 |= cpu_to_le32((QSLT_MGNT << QSEL_SHT) & 0x00001f00);
2263
2264 /* Set NAVUSEHDR to prevent Ps-poll AId filed to be changed
2265 to error vlaue by Hw. */
2266 if (IsPsPoll) {
2267 ptxdesc->txdw1 |= cpu_to_le32(NAVUSEHDR);
2268 } else {
2269 /* Hw set sequence number */
2270 ptxdesc->txdw4 |= cpu_to_le32(BIT(7));
2271 /* set bit3 to 1. Suugested by TimChen. 2009.12.29. */
2272 ptxdesc->txdw3 |= cpu_to_le32((8 << 28));
2273 }
2274
2275 if (true == IsBTQosNull) {
2276 ptxdesc->txdw2 |= cpu_to_le32(BIT(23)); /* BT NULL */
2277 }
2278
2279 /* offset 16 */
2280 ptxdesc->txdw4 |= cpu_to_le32(BIT(8)); /* driver uses rate */
2281
2282 /* USB interface drop packet if the checksum of descriptor isn't
2283 correct. */
2284 /* Using this checksum can let hardware recovery from packet bulk
2285 out error (e.g. Cancel URC, Bulk out error.). */
2286 rtl8723a_cal_txdesc_chksum(ptxdesc);
2287 }
2288
hw_var_set_opmode(struct rtw_adapter * padapter,u8 mode)2289 void hw_var_set_opmode(struct rtw_adapter *padapter, u8 mode)
2290 {
2291 u8 val8;
2292
2293 if (mode == MSR_INFRA || mode == MSR_NOLINK) {
2294 StopTxBeacon(padapter);
2295
2296 /* disable atim wnd */
2297 val8 = DIS_TSF_UDT | EN_BCN_FUNCTION | DIS_ATIM;
2298 SetBcnCtrlReg23a(padapter, val8, ~val8);
2299 } else if (mode == MSR_ADHOC) {
2300 ResumeTxBeacon(padapter);
2301
2302 val8 = DIS_TSF_UDT | EN_BCN_FUNCTION | DIS_BCNQ_SUB;
2303 SetBcnCtrlReg23a(padapter, val8, ~val8);
2304 } else if (mode == MSR_AP) {
2305 /* add NULL Data and BT NULL Data Packets to FW RSVD Page */
2306 rtl8723a_set_BTCoex_AP_mode_FwRsvdPkt_cmd(padapter);
2307
2308 ResumeTxBeacon(padapter);
2309
2310 val8 = DIS_TSF_UDT | DIS_BCNQ_SUB;
2311 SetBcnCtrlReg23a(padapter, val8, ~val8);
2312
2313 /* Set RCR */
2314 /* rtl8723au_write32(padapter, REG_RCR, 0x70002a8e);
2315 CBSSID_DATA must set to 0 */
2316 /* CBSSID_DATA must set to 0 */
2317 rtl8723au_write32(padapter, REG_RCR, 0x7000228e);
2318 /* enable to rx data frame */
2319 rtl8723au_write16(padapter, REG_RXFLTMAP2, 0xFFFF);
2320 /* enable to rx ps-poll */
2321 rtl8723au_write16(padapter, REG_RXFLTMAP1, 0x0400);
2322
2323 /* Beacon Control related register for first time */
2324 /* 2ms */
2325 rtl8723au_write8(padapter, REG_BCNDMATIM, 0x02);
2326 /* 5ms */
2327 rtl8723au_write8(padapter, REG_DRVERLYINT, 0x05);
2328 /* 10ms for port0 */
2329 rtl8723au_write8(padapter, REG_ATIMWND, 0x0a);
2330 rtl8723au_write16(padapter, REG_BCNTCFG, 0x00);
2331 rtl8723au_write16(padapter, REG_TBTT_PROHIBIT, 0xff04);
2332 /* +32767 (~32ms) */
2333 rtl8723au_write16(padapter, REG_TSFTR_SYN_OFFSET, 0x7fff);
2334
2335 /* reset TSF */
2336 rtl8723au_write8(padapter, REG_DUAL_TSF_RST, BIT(0));
2337
2338 /* enable BCN Function */
2339 /* don't enable update TSF (due to TSF update when
2340 beacon/probe rsp are received) */
2341 val8 = DIS_TSF_UDT | EN_BCN_FUNCTION |
2342 EN_TXBCN_RPT | DIS_BCNQ_SUB;
2343 SetBcnCtrlReg23a(padapter, val8, ~val8);
2344 }
2345
2346 val8 = rtl8723au_read8(padapter, MSR);
2347 val8 = (val8 & 0xC) | mode;
2348 rtl8723au_write8(padapter, MSR, val8);
2349 }
2350
hw_var_set_macaddr(struct rtw_adapter * padapter,u8 * val)2351 void hw_var_set_macaddr(struct rtw_adapter *padapter, u8 *val)
2352 {
2353 u8 idx = 0;
2354 u32 reg_macid;
2355
2356 reg_macid = REG_MACID;
2357
2358 for (idx = 0; idx < 6; idx++)
2359 rtl8723au_write8(padapter, (reg_macid + idx), val[idx]);
2360 }
2361
hw_var_set_bssid(struct rtw_adapter * padapter,u8 * val)2362 void hw_var_set_bssid(struct rtw_adapter *padapter, u8 *val)
2363 {
2364 u8 idx = 0;
2365 u32 reg_bssid;
2366
2367 reg_bssid = REG_BSSID;
2368
2369 for (idx = 0; idx < 6; idx++)
2370 rtl8723au_write8(padapter, (reg_bssid + idx), val[idx]);
2371 }
2372
hw_var_set_correct_tsf(struct rtw_adapter * padapter)2373 void hw_var_set_correct_tsf(struct rtw_adapter *padapter)
2374 {
2375 u64 tsf;
2376 u32 reg_tsftr;
2377 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2378 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
2379
2380 /* tsf = pmlmeext->TSFValue - ((u32)pmlmeext->TSFValue %
2381 (pmlmeinfo->bcn_interval*1024)) - 1024; us */
2382 tsf = pmlmeext->TSFValue -
2383 do_div(pmlmeext->TSFValue,
2384 (pmlmeinfo->bcn_interval * 1024)) - 1024; /* us */
2385
2386 if (((pmlmeinfo->state & 0x03) == MSR_ADHOC) ||
2387 ((pmlmeinfo->state & 0x03) == MSR_AP)) {
2388 /* pHalData->RegTxPause |= STOP_BCNQ;BIT(6) */
2389 /* rtl8723au_write8(padapter, REG_TXPAUSE,
2390 (rtl8723au_read8(Adapter, REG_TXPAUSE)|BIT(6))); */
2391 StopTxBeacon(padapter);
2392 }
2393
2394 reg_tsftr = REG_TSFTR;
2395
2396 /* disable related TSF function */
2397 SetBcnCtrlReg23a(padapter, 0, EN_BCN_FUNCTION);
2398
2399 rtl8723au_write32(padapter, reg_tsftr, tsf);
2400 rtl8723au_write32(padapter, reg_tsftr + 4, tsf >> 32);
2401
2402 /* enable related TSF function */
2403 SetBcnCtrlReg23a(padapter, EN_BCN_FUNCTION, 0);
2404
2405 if (((pmlmeinfo->state & 0x03) == MSR_ADHOC) ||
2406 ((pmlmeinfo->state & 0x03) == MSR_AP))
2407 ResumeTxBeacon(padapter);
2408 }
2409
hw_var_set_mlme_disconnect(struct rtw_adapter * padapter)2410 void hw_var_set_mlme_disconnect(struct rtw_adapter *padapter)
2411 {
2412 /* reject all data frames */
2413 rtl8723au_write16(padapter, REG_RXFLTMAP2, 0);
2414
2415 /* reset TSF */
2416 rtl8723au_write8(padapter, REG_DUAL_TSF_RST, BIT(0));
2417
2418 /* disable update TSF */
2419 SetBcnCtrlReg23a(padapter, DIS_TSF_UDT, 0);
2420 }
2421
hw_var_set_mlme_join(struct rtw_adapter * padapter,u8 type)2422 void hw_var_set_mlme_join(struct rtw_adapter *padapter, u8 type)
2423 {
2424 u8 RetryLimit = 0x30;
2425
2426 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
2427 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2428
2429 if (type == 0) { /* prepare to join */
2430 u32 v32;
2431
2432 /* enable to rx data frame.Accept all data frame */
2433 /* rtl8723au_write32(padapter, REG_RCR,
2434 rtl8723au_read32(padapter, REG_RCR)|RCR_ADF); */
2435 rtl8723au_write16(padapter, REG_RXFLTMAP2, 0xFFFF);
2436
2437 v32 = rtl8723au_read32(padapter, REG_RCR);
2438 v32 |= RCR_CBSSID_DATA | RCR_CBSSID_BCN;
2439 rtl8723au_write32(padapter, REG_RCR, v32);
2440
2441 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true)
2442 RetryLimit =
2443 (pHalData->CustomerID == RT_CID_CCX) ? 7 : 48;
2444 else /* Ad-hoc Mode */
2445 RetryLimit = 0x7;
2446 } else if (type == 1) { /* joinbss_event callback when join res < 0 */
2447 /* config RCR to receive different BSSID & not to
2448 receive data frame during linking */
2449 rtl8723au_write16(padapter, REG_RXFLTMAP2, 0);
2450 } else if (type == 2) { /* sta add event callback */
2451 /* enable update TSF */
2452 SetBcnCtrlReg23a(padapter, 0, DIS_TSF_UDT);
2453
2454 if (check_fwstate(pmlmepriv,
2455 WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE)) {
2456 /* fixed beacon issue for 8191su........... */
2457 rtl8723au_write8(padapter, 0x542, 0x02);
2458 RetryLimit = 0x7;
2459 }
2460 }
2461
2462 rtl8723au_write16(padapter, REG_RL,
2463 RetryLimit << RETRY_LIMIT_SHORT_SHIFT | RetryLimit <<
2464 RETRY_LIMIT_LONG_SHIFT);
2465
2466 switch (type) {
2467 case 0:
2468 /* prepare to join */
2469 rtl8723a_BT_wifiassociate_notify(padapter, true);
2470 break;
2471 case 1:
2472 /* joinbss_event callback when join res < 0 */
2473 rtl8723a_BT_wifiassociate_notify(padapter, false);
2474 break;
2475 case 2:
2476 /* sta add event callback */
2477 /* BT_WifiMediaStatusNotify(padapter, RT_MEDIA_CONNECT); */
2478 break;
2479 }
2480 }
2481