blob: fa47aebf8b98ce2c7e19ce37e4c8a83ffc98927c [file] [log] [blame]
Larry Fingerf7c92d22014-03-28 21:37:39 -05001/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2011 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 _HCI_HAL_INIT_C_
16
17#include <osdep_service.h>
18#include <drv_types.h>
19#include <rtw_efuse.h>
20
21#include <HalPwrSeqCmd.h>
22#include <Hal8723PwrSeq.h>
23#include <rtl8723a_hal.h>
Larry Fingerf7c92d22014-03-28 21:37:39 -050024#include <linux/ieee80211.h>
25
26#include <usb_ops.h>
Larry Fingerf7c92d22014-03-28 21:37:39 -050027
Jes Sorensen0e316c22014-11-30 16:05:05 -050028static void phy_SsPwrSwitch92CU(struct rtw_adapter *Adapter,
Jes Sorensenb0247932014-11-30 16:05:06 -050029 enum rt_rf_power_state eRFPowerState);
Jes Sorensen0e316c22014-11-30 16:05:05 -050030
Larry Fingerf7c92d22014-03-28 21:37:39 -050031static void
32_ConfigChipOutEP(struct rtw_adapter *pAdapter, u8 NumOutPipe)
33{
34 u8 value8;
35 struct hal_data_8723a *pHalData = GET_HAL_DATA(pAdapter);
36
37 pHalData->OutEpQueueSel = 0;
38 pHalData->OutEpNumber = 0;
39
40 /* Normal and High queue */
Jes Sorensen050abc42014-05-16 10:05:08 +020041 value8 = rtl8723au_read8(pAdapter, (REG_NORMAL_SIE_EP + 1));
Larry Fingerf7c92d22014-03-28 21:37:39 -050042
43 if (value8 & USB_NORMAL_SIE_EP_MASK) {
44 pHalData->OutEpQueueSel |= TX_SELE_HQ;
45 pHalData->OutEpNumber++;
46 }
47
48 if ((value8 >> USB_NORMAL_SIE_EP_SHIFT) & USB_NORMAL_SIE_EP_MASK) {
49 pHalData->OutEpQueueSel |= TX_SELE_NQ;
50 pHalData->OutEpNumber++;
51 }
52
53 /* Low queue */
Jes Sorensen050abc42014-05-16 10:05:08 +020054 value8 = rtl8723au_read8(pAdapter, (REG_NORMAL_SIE_EP + 2));
Larry Fingerf7c92d22014-03-28 21:37:39 -050055 if (value8 & USB_NORMAL_SIE_EP_MASK) {
56 pHalData->OutEpQueueSel |= TX_SELE_LQ;
57 pHalData->OutEpNumber++;
58 }
59
60 /* TODO: Error recovery for this case */
61 /* RT_ASSERT((NumOutPipe == pHalData->OutEpNumber),
62 ("Out EP number isn't match! %d(Descriptor) != %d (SIE reg)\n",
63 (u32)NumOutPipe, (u32)pHalData->OutEpNumber)); */
64}
65
Jes Sorensen4a293152014-11-30 16:05:00 -050066bool rtl8723au_chip_configure(struct rtw_adapter *padapter)
Larry Fingerf7c92d22014-03-28 21:37:39 -050067{
Jes Sorensen4a293152014-11-30 16:05:00 -050068 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
69 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
70 u8 NumInPipe = pdvobjpriv->RtNumInPipes;
71 u8 NumOutPipe = pdvobjpriv->RtNumOutPipes;
Larry Fingerf7c92d22014-03-28 21:37:39 -050072
Jes Sorensen4a293152014-11-30 16:05:00 -050073 _ConfigChipOutEP(padapter, NumOutPipe);
Larry Fingerf7c92d22014-03-28 21:37:39 -050074
75 /* Normal chip with one IN and one OUT doesn't have interrupt IN EP. */
76 if (pHalData->OutEpNumber == 1) {
77 if (NumInPipe != 1)
Jes Sorensen4a293152014-11-30 16:05:00 -050078 return false;
Larry Fingerf7c92d22014-03-28 21:37:39 -050079 }
80
Jes Sorensen4a293152014-11-30 16:05:00 -050081 return Hal_MappingOutPipe23a(padapter, NumOutPipe);
Larry Fingerf7c92d22014-03-28 21:37:39 -050082}
83
Jes Sorensene04cd3f2014-05-16 10:04:44 +020084static int _InitPowerOn(struct rtw_adapter *padapter)
Larry Fingerf7c92d22014-03-28 21:37:39 -050085{
Jes Sorensena1cfeeb2014-11-30 16:05:01 -050086 u16 value16;
87 u8 value8;
Larry Fingerf7c92d22014-03-28 21:37:39 -050088
89 /* RSV_CTRL 0x1C[7:0] = 0x00
90 unlock ISO/CLK/Power control register */
Jes Sorensenedbfd672014-05-16 10:05:09 +020091 rtl8723au_write8(padapter, REG_RSV_CTRL, 0x0);
Larry Fingerf7c92d22014-03-28 21:37:39 -050092
93 /* HW Power on sequence */
94 if (!HalPwrSeqCmdParsing23a(padapter, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
95 PWR_INTF_USB_MSK, rtl8723AU_card_enable_flow))
96 return _FAIL;
97
98 /* 0x04[19] = 1, suggest by Jackie 2011.05.09, reset 8051 */
Jes Sorensen050abc42014-05-16 10:05:08 +020099 value8 = rtl8723au_read8(padapter, REG_APS_FSMCO+2);
Jes Sorensenedbfd672014-05-16 10:05:09 +0200100 rtl8723au_write8(padapter, REG_APS_FSMCO + 2, value8 | BIT(3));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500101
102 /* Enable MAC DMA/WMAC/SCHEDULE/SEC block */
103 /* Set CR bit10 to enable 32k calibration. Suggested by SD1 Gimmy.
104 Added by tynli. 2011.08.31. */
Jes Sorensen050abc42014-05-16 10:05:08 +0200105 value16 = rtl8723au_read16(padapter, REG_CR);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500106 value16 |= (HCI_TXDMA_EN | HCI_RXDMA_EN | TXDMA_EN | RXDMA_EN |
107 PROTOCOL_EN | SCHEDULE_EN | MACTXEN | MACRXEN |
108 ENSEC | CALTMR_EN);
Jes Sorensenedbfd672014-05-16 10:05:09 +0200109 rtl8723au_write16(padapter, REG_CR, value16);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500110
111 /* for Efuse PG, suggest by Jackie 2011.11.23 */
Jes Sorensen05f07e72014-05-16 10:03:44 +0200112 PHY_SetBBReg(padapter, REG_EFUSE_CTRL, BIT(28)|BIT(29)|BIT(30), 0x06);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500113
Jes Sorensena1cfeeb2014-11-30 16:05:01 -0500114 return _SUCCESS;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500115}
116
117/* Shall USB interface init this? */
118static void _InitInterrupt(struct rtw_adapter *Adapter)
119{
120 u32 value32;
121
122 /* HISR - turn all on */
123 value32 = 0xFFFFFFFF;
Jes Sorensenedbfd672014-05-16 10:05:09 +0200124 rtl8723au_write32(Adapter, REG_HISR, value32);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500125
126 /* HIMR - turn all on */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200127 rtl8723au_write32(Adapter, REG_HIMR, value32);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500128}
129
130static void _InitQueueReservedPage(struct rtw_adapter *Adapter)
131{
132 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
133 struct registry_priv *pregistrypriv = &Adapter->registrypriv;
134 u32 numHQ = 0;
135 u32 numLQ = 0;
136 u32 numNQ = 0;
137 u32 numPubQ;
138 u32 value32;
139 u8 value8;
140 bool bWiFiConfig = pregistrypriv->wifi_spec;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500141
Jes Sorensenef71c9b2014-05-25 22:43:48 +0200142 /* RT_ASSERT((outEPNum>= 2), ("for WMM , number of out-ep "
143 "must more than or equal to 2!\n")); */
Larry Fingerf7c92d22014-03-28 21:37:39 -0500144
Jes Sorensenef71c9b2014-05-25 22:43:48 +0200145 numPubQ = bWiFiConfig ? WMM_NORMAL_PAGE_NUM_PUBQ : NORMAL_PAGE_NUM_PUBQ;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500146
Jes Sorensenef71c9b2014-05-25 22:43:48 +0200147 if (pHalData->OutEpQueueSel & TX_SELE_HQ) {
148 numHQ = bWiFiConfig ?
149 WMM_NORMAL_PAGE_NUM_HPQ : NORMAL_PAGE_NUM_HPQ;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500150 }
151
Jes Sorensenef71c9b2014-05-25 22:43:48 +0200152 if (pHalData->OutEpQueueSel & TX_SELE_LQ) {
153 numLQ = bWiFiConfig ?
154 WMM_NORMAL_PAGE_NUM_LPQ : NORMAL_PAGE_NUM_LPQ;
155 }
156 /* NOTE: This step shall be proceed before
157 writting REG_RQPN. */
158 if (pHalData->OutEpQueueSel & TX_SELE_NQ) {
159 numNQ = bWiFiConfig ?
160 WMM_NORMAL_PAGE_NUM_NPQ : NORMAL_PAGE_NUM_NPQ;
161 }
162 value8 = (u8)_NPQ(numNQ);
163 rtl8723au_write8(Adapter, REG_RQPN_NPQ, value8);
164
Larry Fingerf7c92d22014-03-28 21:37:39 -0500165 /* TX DMA */
166 value32 = _HPQ(numHQ) | _LPQ(numLQ) | _PUBQ(numPubQ) | LD_RQPN;
Jes Sorensenedbfd672014-05-16 10:05:09 +0200167 rtl8723au_write32(Adapter, REG_RQPN, value32);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500168}
169
170static void _InitTxBufferBoundary(struct rtw_adapter *Adapter)
171{
172 struct registry_priv *pregistrypriv = &Adapter->registrypriv;
173
174 u8 txpktbuf_bndy;
175
176 if (!pregistrypriv->wifi_spec)
177 txpktbuf_bndy = TX_PAGE_BOUNDARY;
178 else /* for WMM */
179 txpktbuf_bndy = WMM_NORMAL_TX_PAGE_BOUNDARY;
180
Jes Sorensenedbfd672014-05-16 10:05:09 +0200181 rtl8723au_write8(Adapter, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy);
182 rtl8723au_write8(Adapter, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy);
183 rtl8723au_write8(Adapter, REG_TXPKTBUF_WMAC_LBK_BF_HD, txpktbuf_bndy);
184 rtl8723au_write8(Adapter, REG_TRXFF_BNDY, txpktbuf_bndy);
185 rtl8723au_write8(Adapter, REG_TDECTRL+1, txpktbuf_bndy);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500186}
187
188static void _InitPageBoundary(struct rtw_adapter *Adapter)
189{
190 /* RX Page Boundary */
191 /* srand(static_cast<unsigned int>(time(NULL))); */
192 u16 rxff_bndy = 0x27FF;/* rand() % 1) ? 0x27FF : 0x23FF; */
193
Jes Sorensenedbfd672014-05-16 10:05:09 +0200194 rtl8723au_write16(Adapter, (REG_TRXFF_BNDY + 2), rxff_bndy);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500195
196 /* TODO: ?? shall we set tx boundary? */
197}
198
199static void
200_InitNormalChipRegPriority(struct rtw_adapter *Adapter, u16 beQ, u16 bkQ,
201 u16 viQ, u16 voQ, u16 mgtQ, u16 hiQ)
202{
Jes Sorensen050abc42014-05-16 10:05:08 +0200203 u16 value16 = rtl8723au_read16(Adapter, REG_TRXDMA_CTRL) & 0x7;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500204
205 value16 |= _TXDMA_BEQ_MAP(beQ) | _TXDMA_BKQ_MAP(bkQ) |
206 _TXDMA_VIQ_MAP(viQ) | _TXDMA_VOQ_MAP(voQ) |
207 _TXDMA_MGQ_MAP(mgtQ) | _TXDMA_HIQ_MAP(hiQ);
208
Jes Sorensenedbfd672014-05-16 10:05:09 +0200209 rtl8723au_write16(Adapter, REG_TRXDMA_CTRL, value16);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500210}
211
212static void _InitNormalChipOneOutEpPriority(struct rtw_adapter *Adapter)
213{
214 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
215 u16 value = 0;
216
217 switch (pHalData->OutEpQueueSel) {
218 case TX_SELE_HQ:
219 value = QUEUE_HIGH;
220 break;
221 case TX_SELE_LQ:
222 value = QUEUE_LOW;
223 break;
224 case TX_SELE_NQ:
225 value = QUEUE_NORMAL;
226 break;
227 default:
228 /* RT_ASSERT(false, ("Shall not reach here!\n")); */
229 break;
230 }
231
232 _InitNormalChipRegPriority(Adapter, value, value, value,
233 value, value, value);
234}
235
236static void _InitNormalChipTwoOutEpPriority(struct rtw_adapter *Adapter)
237{
238 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
239 struct registry_priv *pregistrypriv = &Adapter->registrypriv;
240 u16 beQ, bkQ, viQ, voQ, mgtQ, hiQ;
241 u16 valueHi = 0;
242 u16 valueLow = 0;
243
244 switch (pHalData->OutEpQueueSel) {
245 case (TX_SELE_HQ | TX_SELE_LQ):
246 valueHi = QUEUE_HIGH;
247 valueLow = QUEUE_LOW;
248 break;
249 case (TX_SELE_NQ | TX_SELE_LQ):
250 valueHi = QUEUE_NORMAL;
251 valueLow = QUEUE_LOW;
252 break;
253 case (TX_SELE_HQ | TX_SELE_NQ):
254 valueHi = QUEUE_HIGH;
255 valueLow = QUEUE_NORMAL;
256 break;
257 default:
258 /* RT_ASSERT(false, ("Shall not reach here!\n")); */
259 break;
260 }
261
262 if (!pregistrypriv->wifi_spec) {
263 beQ = valueLow;
264 bkQ = valueLow;
265 viQ = valueHi;
266 voQ = valueHi;
267 mgtQ = valueHi;
268 hiQ = valueHi;
269 } else {/* for WMM , CONFIG_OUT_EP_WIFI_MODE */
270 beQ = valueLow;
271 bkQ = valueHi;
272 viQ = valueHi;
273 voQ = valueLow;
274 mgtQ = valueHi;
275 hiQ = valueHi;
276 }
277
278 _InitNormalChipRegPriority(Adapter, beQ, bkQ, viQ, voQ, mgtQ, hiQ);
279}
280
281static void _InitNormalChipThreeOutEpPriority(struct rtw_adapter *Adapter)
282{
283 struct registry_priv *pregistrypriv = &Adapter->registrypriv;
284 u16 beQ, bkQ, viQ, voQ, mgtQ, hiQ;
285
286 if (!pregistrypriv->wifi_spec) {/* typical setting */
287 beQ = QUEUE_LOW;
288 bkQ = QUEUE_LOW;
289 viQ = QUEUE_NORMAL;
290 voQ = QUEUE_HIGH;
291 mgtQ = QUEUE_HIGH;
292 hiQ = QUEUE_HIGH;
293 } else {/* for WMM */
294 beQ = QUEUE_LOW;
295 bkQ = QUEUE_NORMAL;
296 viQ = QUEUE_NORMAL;
297 voQ = QUEUE_HIGH;
298 mgtQ = QUEUE_HIGH;
299 hiQ = QUEUE_HIGH;
300 }
301 _InitNormalChipRegPriority(Adapter, beQ, bkQ, viQ, voQ, mgtQ, hiQ);
302}
303
Jes Sorensenbacdcb82014-11-30 16:05:02 -0500304static void _InitQueuePriority(struct rtw_adapter *Adapter)
Larry Fingerf7c92d22014-03-28 21:37:39 -0500305{
306 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
307
308 switch (pHalData->OutEpNumber) {
309 case 1:
310 _InitNormalChipOneOutEpPriority(Adapter);
311 break;
312 case 2:
313 _InitNormalChipTwoOutEpPriority(Adapter);
314 break;
315 case 3:
316 _InitNormalChipThreeOutEpPriority(Adapter);
317 break;
318 default:
319 /* RT_ASSERT(false, ("Shall not reach here!\n")); */
320 break;
321 }
322}
323
Larry Fingerf7c92d22014-03-28 21:37:39 -0500324static void _InitTransferPageSize(struct rtw_adapter *Adapter)
325{
326 /* Tx page size is always 128. */
327
328 u8 value8;
329 value8 = _PSRX(PBP_128) | _PSTX(PBP_128);
Jes Sorensenedbfd672014-05-16 10:05:09 +0200330 rtl8723au_write8(Adapter, REG_PBP, value8);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500331}
332
333static void _InitDriverInfoSize(struct rtw_adapter *Adapter, u8 drvInfoSize)
334{
Jes Sorensenedbfd672014-05-16 10:05:09 +0200335 rtl8723au_write8(Adapter, REG_RX_DRVINFO_SZ, drvInfoSize);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500336}
337
338static void _InitWMACSetting(struct rtw_adapter *Adapter)
339{
340 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
341
342 /* don't turn on AAP, it will allow all packets to driver */
343 pHalData->ReceiveConfig = RCR_APM | RCR_AM | RCR_AB | RCR_CBSSID_DATA |
344 RCR_CBSSID_BCN | RCR_APP_ICV | RCR_AMF |
345 RCR_HTC_LOC_CTRL | RCR_APP_MIC |
346 RCR_APP_PHYSTS;
347
348 /* some REG_RCR will be modified later by
349 phy_ConfigMACWithHeaderFile() */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200350 rtl8723au_write32(Adapter, REG_RCR, pHalData->ReceiveConfig);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500351
352 /* Accept all multicast address */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200353 rtl8723au_write32(Adapter, REG_MAR, 0xFFFFFFFF);
354 rtl8723au_write32(Adapter, REG_MAR + 4, 0xFFFFFFFF);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500355
356 /* Accept all data frames */
357 /* value16 = 0xFFFF; */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200358 /* rtl8723au_write16(Adapter, REG_RXFLTMAP2, value16); */
Larry Fingerf7c92d22014-03-28 21:37:39 -0500359
360 /* 2010.09.08 hpfan */
361 /* Since ADF is removed from RCR, ps-poll will not be indicate
362 to driver, */
Carlos E. Garcia69e98df2015-04-24 09:40:42 -0400363 /* RxFilterMap should mask ps-poll to guarantee AP mode can
Larry Fingerf7c92d22014-03-28 21:37:39 -0500364 rx ps-poll. */
365 /* value16 = 0x400; */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200366 /* rtl8723au_write16(Adapter, REG_RXFLTMAP1, value16); */
Larry Fingerf7c92d22014-03-28 21:37:39 -0500367
368 /* Accept all management frames */
369 /* value16 = 0xFFFF; */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200370 /* rtl8723au_write16(Adapter, REG_RXFLTMAP0, value16); */
Larry Fingerf7c92d22014-03-28 21:37:39 -0500371
372 /* enable RX_SHIFT bits */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200373 /* rtl8723au_write8(Adapter, REG_TRXDMA_CTRL, rtl8723au_read8(Adapter,
Larry Fingerf7c92d22014-03-28 21:37:39 -0500374 REG_TRXDMA_CTRL)|BIT(1)); */
375}
376
377static void _InitAdaptiveCtrl(struct rtw_adapter *Adapter)
378{
379 u16 value16;
380 u32 value32;
381
382 /* Response Rate Set */
Jes Sorensen050abc42014-05-16 10:05:08 +0200383 value32 = rtl8723au_read32(Adapter, REG_RRSR);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500384 value32 &= ~RATE_BITMAP_ALL;
385 value32 |= RATE_RRSR_CCK_ONLY_1M;
Jes Sorensenedbfd672014-05-16 10:05:09 +0200386 rtl8723au_write32(Adapter, REG_RRSR, value32);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500387
388 /* CF-END Threshold */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200389 /* m_spIoBase->rtl8723au_write8(REG_CFEND_TH, 0x1); */
Larry Fingerf7c92d22014-03-28 21:37:39 -0500390
391 /* SIFS (used in NAV) */
392 value16 = _SPEC_SIFS_CCK(0x10) | _SPEC_SIFS_OFDM(0x10);
Jes Sorensenedbfd672014-05-16 10:05:09 +0200393 rtl8723au_write16(Adapter, REG_SPEC_SIFS, value16);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500394
395 /* Retry Limit */
396 value16 = _LRL(0x30) | _SRL(0x30);
Jes Sorensenedbfd672014-05-16 10:05:09 +0200397 rtl8723au_write16(Adapter, REG_RL, value16);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500398}
399
400static void _InitRateFallback(struct rtw_adapter *Adapter)
401{
402 /* Set Data Auto Rate Fallback Retry Count register. */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200403 rtl8723au_write32(Adapter, REG_DARFRC, 0x00000000);
404 rtl8723au_write32(Adapter, REG_DARFRC+4, 0x10080404);
405 rtl8723au_write32(Adapter, REG_RARFRC, 0x04030201);
406 rtl8723au_write32(Adapter, REG_RARFRC+4, 0x08070605);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500407}
408
409static void _InitEDCA(struct rtw_adapter *Adapter)
410{
411 /* Set Spec SIFS (used in NAV) */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200412 rtl8723au_write16(Adapter, REG_SPEC_SIFS, 0x100a);
413 rtl8723au_write16(Adapter, REG_MAC_SPEC_SIFS, 0x100a);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500414
415 /* Set SIFS for CCK */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200416 rtl8723au_write16(Adapter, REG_SIFS_CTX, 0x100a);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500417
418 /* Set SIFS for OFDM */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200419 rtl8723au_write16(Adapter, REG_SIFS_TRX, 0x100a);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500420
421 /* TXOP */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200422 rtl8723au_write32(Adapter, REG_EDCA_BE_PARAM, 0x005EA42B);
423 rtl8723au_write32(Adapter, REG_EDCA_BK_PARAM, 0x0000A44F);
424 rtl8723au_write32(Adapter, REG_EDCA_VI_PARAM, 0x005EA324);
425 rtl8723au_write32(Adapter, REG_EDCA_VO_PARAM, 0x002FA226);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500426}
427
Larry Fingerf7c92d22014-03-28 21:37:39 -0500428static void _InitRDGSetting(struct rtw_adapter *Adapter)
429{
Jes Sorensenedbfd672014-05-16 10:05:09 +0200430 rtl8723au_write8(Adapter, REG_RD_CTRL, 0xFF);
431 rtl8723au_write16(Adapter, REG_RD_NAV_NXT, 0x200);
432 rtl8723au_write8(Adapter, REG_RD_RESP_PKT_TH, 0x05);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500433}
434
435static void _InitRetryFunction(struct rtw_adapter *Adapter)
436{
437 u8 value8;
438
Jes Sorensen050abc42014-05-16 10:05:08 +0200439 value8 = rtl8723au_read8(Adapter, REG_FWHW_TXQ_CTRL);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500440 value8 |= EN_AMPDU_RTY_NEW;
Jes Sorensenedbfd672014-05-16 10:05:09 +0200441 rtl8723au_write8(Adapter, REG_FWHW_TXQ_CTRL, value8);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500442
443 /* Set ACK timeout */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200444 rtl8723au_write8(Adapter, REG_ACKTO, 0x40);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500445}
446
Larry Fingerf7c92d22014-03-28 21:37:39 -0500447static void _InitRFType(struct rtw_adapter *Adapter)
448{
449 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500450
Jes Sorensen277c7222015-02-27 15:45:32 -0500451 pHalData->rf_type = RF_1T1R;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500452}
453
454/* Set CCK and OFDM Block "ON" */
455static void _BBTurnOnBlock(struct rtw_adapter *Adapter)
456{
457 PHY_SetBBReg(Adapter, rFPGA0_RFMOD, bCCKEn, 0x1);
458 PHY_SetBBReg(Adapter, rFPGA0_RFMOD, bOFDMEn, 0x1);
459}
460
461#define MgntActSet_RF_State(...)
462static void _RfPowerSave(struct rtw_adapter *padapter)
463{
464}
465
466enum {
467 Antenna_Lfet = 1,
468 Antenna_Right = 2,
469};
470
471enum rt_rf_power_state RfOnOffDetect23a(struct rtw_adapter *pAdapter)
472{
473 /* struct hal_data_8723a *pHalData = GET_HAL_DATA(pAdapter); */
474 u8 val8;
475 enum rt_rf_power_state rfpowerstate = rf_off;
476
Jes Sorensen06736c22014-07-31 10:36:43 +0200477 rtl8723au_write8(pAdapter, REG_MAC_PINMUX_CFG,
478 rtl8723au_read8(pAdapter,
479 REG_MAC_PINMUX_CFG) & ~BIT(3));
480 val8 = rtl8723au_read8(pAdapter, REG_GPIO_IO_SEL);
481 DBG_8723A("GPIO_IN =%02x\n", val8);
482 rfpowerstate = (val8 & BIT(3)) ? rf_on : rf_off;
483
Larry Fingerf7c92d22014-03-28 21:37:39 -0500484 return rfpowerstate;
Jes Sorensen06736c22014-07-31 10:36:43 +0200485}
Larry Fingerf7c92d22014-03-28 21:37:39 -0500486
Jes Sorensendc20d1d2014-07-21 11:25:07 +0200487int rtl8723au_hal_init(struct rtw_adapter *Adapter)
Larry Fingerf7c92d22014-03-28 21:37:39 -0500488{
Larry Fingerf7c92d22014-03-28 21:37:39 -0500489 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
490 struct pwrctrl_priv *pwrctrlpriv = &Adapter->pwrctrlpriv;
491 struct registry_priv *pregistrypriv = &Adapter->registrypriv;
Jes Sorensen4405ef42014-11-30 16:05:07 -0500492 u8 val8 = 0;
493 u32 boundary;
494 int status = _SUCCESS;
495 bool mac_on;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500496
497 unsigned long init_start_time = jiffies;
498
Jes Sorensendc20d1d2014-07-21 11:25:07 +0200499 Adapter->hw_init_completed = false;
500
Larry Fingerf7c92d22014-03-28 21:37:39 -0500501 if (Adapter->pwrctrlpriv.bkeepfwalive) {
Jes Sorensenb0247932014-11-30 16:05:06 -0500502 phy_SsPwrSwitch92CU(Adapter, rf_on);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500503
504 if (pHalData->bIQKInitialized) {
505 rtl8723a_phy_iq_calibrate(Adapter, true);
506 } else {
507 rtl8723a_phy_iq_calibrate(Adapter, false);
508 pHalData->bIQKInitialized = true;
509 }
510 rtl8723a_odm_check_tx_power_tracking(Adapter);
511 rtl8723a_phy_lc_calibrate(Adapter);
512
513 goto exit;
514 }
515
516 /* Check if MAC has already power on. by tynli. 2011.05.27. */
Jes Sorensen050abc42014-05-16 10:05:08 +0200517 val8 = rtl8723au_read8(Adapter, REG_CR);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500518 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
Joe Perches90403aa2015-03-24 16:06:44 -0700519 "%s: REG_CR 0x100 = 0x%02x\n", __func__, val8);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500520 /* Fix 92DU-VC S3 hang with the reason is that secondary mac is not
521 initialized. */
522 /* 0x100 value of first mac is 0xEA while 0x100 value of secondary
523 is 0x00 */
524 if (val8 == 0xEA) {
Jes Sorensen4405ef42014-11-30 16:05:07 -0500525 mac_on = false;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500526 } else {
Jes Sorensen4405ef42014-11-30 16:05:07 -0500527 mac_on = true;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500528 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
Joe Perches90403aa2015-03-24 16:06:44 -0700529 "%s: MAC has already power on\n", __func__);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500530 }
531
Larry Fingerf7c92d22014-03-28 21:37:39 -0500532 status = _InitPowerOn(Adapter);
533 if (status == _FAIL) {
534 RT_TRACE(_module_hci_hal_init_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -0700535 "Failed to init power on!\n");
Larry Fingerf7c92d22014-03-28 21:37:39 -0500536 goto exit;
537 }
538
Larry Fingerf7c92d22014-03-28 21:37:39 -0500539 if (!pregistrypriv->wifi_spec) {
540 boundary = TX_PAGE_BOUNDARY;
541 } else {
542 /* for WMM */
543 boundary = WMM_NORMAL_TX_PAGE_BOUNDARY;
544 }
545
Jes Sorensen4405ef42014-11-30 16:05:07 -0500546 if (!mac_on) {
Larry Fingerf7c92d22014-03-28 21:37:39 -0500547 status = InitLLTTable23a(Adapter, boundary);
548 if (status == _FAIL) {
549 RT_TRACE(_module_hci_hal_init_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -0700550 "Failed to init LLT table\n");
Larry Fingerf7c92d22014-03-28 21:37:39 -0500551 goto exit;
552 }
553 }
554
Larry Fingerf7c92d22014-03-28 21:37:39 -0500555 if (pHalData->bRDGEnable)
556 _InitRDGSetting(Adapter);
557
Larry Fingerf7c92d22014-03-28 21:37:39 -0500558 status = rtl8723a_FirmwareDownload(Adapter);
559 if (status != _SUCCESS) {
560 Adapter->bFWReady = false;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500561 DBG_8723A("fw download fail!\n");
562 goto exit;
563 } else {
564 Adapter->bFWReady = true;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500565 DBG_8723A("fw download ok!\n");
566 }
567
568 rtl8723a_InitializeFirmwareVars(Adapter);
569
570 if (pwrctrlpriv->reg_rfoff == true) {
571 pwrctrlpriv->rf_pwrstate = rf_off;
572 }
573
574 /* 2010/08/09 MH We need to check if we need to turnon or off RF after detecting */
575 /* HW GPIO pin. Before PHY_RFConfig8192C. */
576 /* HalDetectPwrDownMode(Adapter); */
577 /* 2010/08/26 MH If Efuse does not support sective suspend then disable the function. */
578 /* HalDetectSelectiveSuspendMode(Adapter); */
579
580 /* Set RF type for BB/RF configuration */
581 _InitRFType(Adapter);/* _ReadRFType() */
582
583 /* Save target channel */
584 /* <Roger_Notes> Current Channel will be updated again later. */
585 pHalData->CurrentChannel = 6;/* default set to 6 */
586
Larry Fingerf7c92d22014-03-28 21:37:39 -0500587 status = PHY_MACConfig8723A(Adapter);
588 if (status == _FAIL) {
589 DBG_8723A("PHY_MACConfig8723A fault !!\n");
590 goto exit;
591 }
592
Larry Fingerf7c92d22014-03-28 21:37:39 -0500593 /* */
594 /* d. Initialize BB related configurations. */
595 /* */
596 status = PHY_BBConfig8723A(Adapter);
597 if (status == _FAIL) {
598 DBG_8723A("PHY_BBConfig8723A fault !!\n");
599 goto exit;
600 }
601
602 /* Add for tx power by rate fine tune. We need to call the function after BB config. */
603 /* Because the tx power by rate table is inited in BB config. */
604
Jes Sorensenf6a71252014-07-13 09:32:10 +0200605 status = PHY_RF6052_Config8723A(Adapter);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500606 if (status == _FAIL) {
Jes Sorensenf6a71252014-07-13 09:32:10 +0200607 DBG_8723A("PHY_RF6052_Config8723A failed!!\n");
Larry Fingerf7c92d22014-03-28 21:37:39 -0500608 goto exit;
609 }
610
611 /* reducing 80M spur */
Jes Sorensen2c177a82015-03-05 14:24:41 -0500612 rtl8723au_write32(Adapter, REG_AFE_XTAL_CTRL, 0x0381808d);
613 rtl8723au_write32(Adapter, REG_AFE_PLL_CTRL, 0xf0ffff83);
614 rtl8723au_write32(Adapter, REG_AFE_PLL_CTRL, 0xf0ffff82);
615 rtl8723au_write32(Adapter, REG_AFE_PLL_CTRL, 0xf0ffff83);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500616
617 /* RFSW Control */
Jes Sorensen2c177a82015-03-05 14:24:41 -0500618 /* 0x804[14]= 0 */
619 rtl8723au_write32(Adapter, rFPGA0_TxInfo, 0x00000003);
620 /* 0x870[6:5]= b'11 */
621 rtl8723au_write32(Adapter, rFPGA0_XAB_RFInterfaceSW, 0x07000760);
622 /* 0x860[6:5]= b'00 */
623 rtl8723au_write32(Adapter, rFPGA0_XA_RFInterfaceOE, 0x66F60210);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500624
Jes Sorensen2c177a82015-03-05 14:24:41 -0500625 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
Joe Perches90403aa2015-03-24 16:06:44 -0700626 "%s: 0x870 = value 0x%x\n", __func__,
627 rtl8723au_read32(Adapter, 0x870));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500628
629 /* */
630 /* Joseph Note: Keep RfRegChnlVal for later use. */
631 /* */
Jes Sorensenbb583c52014-12-04 16:15:45 -0500632 pHalData->RfRegChnlVal[0] = PHY_QueryRFReg(Adapter, RF_PATH_A,
633 RF_CHNLBW, bRFRegOffsetMask);
634 pHalData->RfRegChnlVal[1] = PHY_QueryRFReg(Adapter, RF_PATH_B,
635 RF_CHNLBW, bRFRegOffsetMask);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500636
Jes Sorensen4405ef42014-11-30 16:05:07 -0500637 if (!mac_on) {
Larry Fingerf7c92d22014-03-28 21:37:39 -0500638 _InitQueueReservedPage(Adapter);
639 _InitTxBufferBoundary(Adapter);
640 }
641 _InitQueuePriority(Adapter);
642 _InitPageBoundary(Adapter);
643 _InitTransferPageSize(Adapter);
644
645 /* Get Rx PHY status in order to report RSSI and others. */
646 _InitDriverInfoSize(Adapter, DRVINFO_SZ);
647
648 _InitInterrupt(Adapter);
Jes Sorensen3c5660e2014-04-09 23:20:19 +0200649 hw_var_set_macaddr(Adapter, Adapter->eeprompriv.mac_addr);
Jes Sorensendf72ac92014-07-17 22:59:47 +0200650 rtl8723a_set_media_status(Adapter, MSR_INFRA);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500651 _InitWMACSetting(Adapter);
652 _InitAdaptiveCtrl(Adapter);
653 _InitEDCA(Adapter);
654 _InitRateFallback(Adapter);
655 _InitRetryFunction(Adapter);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500656 rtl8723a_InitBeaconParameters(Adapter);
657
Larry Fingerf7c92d22014-03-28 21:37:39 -0500658 _BBTurnOnBlock(Adapter);
659 /* NicIFSetMacAddress(padapter, padapter->PermanentAddress); */
660
Jes Sorensen2a3bc8a2014-07-17 22:59:53 +0200661 rtl8723a_cam_invalidate_all(Adapter);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500662
Larry Fingerf7c92d22014-03-28 21:37:39 -0500663 /* 2010/12/17 MH We need to set TX power according to EFUSE content at first. */
664 PHY_SetTxPowerLevel8723A(Adapter, pHalData->CurrentChannel);
665
666 rtl8723a_InitAntenna_Selection(Adapter);
667
668 /* HW SEQ CTRL */
669 /* set 0x0 to 0xFF by tynli. Default enable HW SEQ NUM. */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200670 rtl8723au_write8(Adapter, REG_HWSEQ_CTRL, 0xFF);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500671
672 /* */
673 /* Disable BAR, suggested by Scott */
674 /* 2010.04.09 add by hpfan */
675 /* */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200676 rtl8723au_write32(Adapter, REG_BAR_MODE_CTRL, 0x0201ffff);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500677
678 if (pregistrypriv->wifi_spec)
Jes Sorensenedbfd672014-05-16 10:05:09 +0200679 rtl8723au_write16(Adapter, REG_FAST_EDCA_CTRL, 0);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500680
681 /* Move by Neo for USB SS from above setp */
682 _RfPowerSave(Adapter);
683
Jes Sorensen13055652014-05-25 22:43:40 +0200684 /* 2010/08/26 MH Merge from 8192CE. */
685 /* sherry masked that it has been done in _RfPowerSave */
686 /* 20110927 */
687 /* recovery for 8192cu and 9723Au 20111017 */
688 if (pwrctrlpriv->rf_pwrstate == rf_on) {
689 if (pHalData->bIQKInitialized) {
690 rtl8723a_phy_iq_calibrate(Adapter, true);
691 } else {
692 rtl8723a_phy_iq_calibrate(Adapter, false);
693 pHalData->bIQKInitialized = true;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500694 }
695
Jes Sorensen13055652014-05-25 22:43:40 +0200696 rtl8723a_odm_check_tx_power_tracking(Adapter);
697
698 rtl8723a_phy_lc_calibrate(Adapter);
699
700 rtl8723a_dual_antenna_detection(Adapter);
701 }
702
703 /* fixed USB interface interference issue */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200704 rtl8723au_write8(Adapter, 0xfe40, 0xe0);
705 rtl8723au_write8(Adapter, 0xfe41, 0x8d);
706 rtl8723au_write8(Adapter, 0xfe42, 0x80);
707 rtl8723au_write32(Adapter, 0x20c, 0xfd0320);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500708 /* Solve too many protocol error on USB bus */
709 if (!IS_81xxC_VENDOR_UMC_A_CUT(pHalData->VersionID)) {
710 /* 0xE6 = 0x94 */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200711 rtl8723au_write8(Adapter, 0xFE40, 0xE6);
712 rtl8723au_write8(Adapter, 0xFE41, 0x94);
713 rtl8723au_write8(Adapter, 0xFE42, 0x80);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500714
715 /* 0xE0 = 0x19 */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200716 rtl8723au_write8(Adapter, 0xFE40, 0xE0);
717 rtl8723au_write8(Adapter, 0xFE41, 0x19);
718 rtl8723au_write8(Adapter, 0xFE42, 0x80);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500719
720 /* 0xE5 = 0x91 */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200721 rtl8723au_write8(Adapter, 0xFE40, 0xE5);
722 rtl8723au_write8(Adapter, 0xFE41, 0x91);
723 rtl8723au_write8(Adapter, 0xFE42, 0x80);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500724
725 /* 0xE2 = 0x81 */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200726 rtl8723au_write8(Adapter, 0xFE40, 0xE2);
727 rtl8723au_write8(Adapter, 0xFE41, 0x81);
728 rtl8723au_write8(Adapter, 0xFE42, 0x80);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500729
730 }
731
Larry Fingerf7c92d22014-03-28 21:37:39 -0500732/* _InitPABias(Adapter); */
733
Jes Sorensen00e8b242014-05-25 22:43:39 +0200734 /* Init BT hw config. */
735 rtl8723a_BT_init_hwconfig(Adapter);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500736
Larry Fingerf7c92d22014-03-28 21:37:39 -0500737 rtl8723a_InitHalDm(Adapter);
738
Bhaktipriya Shridhar3c2f78f2016-03-08 23:28:13 +0530739 val8 = DIV_ROUND_UP(WiFiNavUpperUs, HAL_8723A_NAV_UPPER_UNIT);
Jes Sorensend0b39f82014-07-21 11:25:06 +0200740 rtl8723au_write8(Adapter, REG_NAV_UPPER, val8);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500741
742 /* 2011/03/09 MH debug only, UMC-B cut pass 2500 S5 test, but we need to fin root cause. */
Jes Sorensen050abc42014-05-16 10:05:08 +0200743 if (((rtl8723au_read32(Adapter, rFPGA0_RFMOD) & 0xFF000000) !=
744 0x83000000)) {
Larry Fingerf7c92d22014-03-28 21:37:39 -0500745 PHY_SetBBReg(Adapter, rFPGA0_RFMOD, BIT(24), 1);
Joe Perches90403aa2015-03-24 16:06:44 -0700746 RT_TRACE(_module_hci_hal_init_c_, _drv_err_,
747 "%s: IQK fail recover\n", __func__);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500748 }
749
750 /* ack for xmit mgmt frames. */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200751 rtl8723au_write32(Adapter, REG_FWHW_TXQ_CTRL,
752 rtl8723au_read32(Adapter, REG_FWHW_TXQ_CTRL)|BIT(12));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500753
754exit:
Jes Sorensendc20d1d2014-07-21 11:25:07 +0200755 if (status == _SUCCESS) {
756 Adapter->hw_init_completed = true;
757
758 if (Adapter->registrypriv.notch_filter == 1)
759 rtl8723a_notch_filter(Adapter, 1);
760 }
761
Larry Fingerf7c92d22014-03-28 21:37:39 -0500762 DBG_8723A("%s in %dms\n", __func__,
763 jiffies_to_msecs(jiffies - init_start_time));
764 return status;
765}
766
767static void phy_SsPwrSwitch92CU(struct rtw_adapter *Adapter,
Jes Sorensenb0247932014-11-30 16:05:06 -0500768 enum rt_rf_power_state eRFPowerState)
Larry Fingerf7c92d22014-03-28 21:37:39 -0500769{
770 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
Jes Sorensenb0247932014-11-30 16:05:06 -0500771 u8 sps0;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500772
Jes Sorensen6e1c29fd2014-11-30 16:05:04 -0500773 sps0 = rtl8723au_read8(Adapter, REG_SPS0_CTRL);
774
Larry Fingerf7c92d22014-03-28 21:37:39 -0500775 switch (eRFPowerState) {
776 case rf_on:
Jes Sorensenb0247932014-11-30 16:05:06 -0500777 /* 1. Enable MAC Clock. Can not be enabled now. */
778 /* WriteXBYTE(REG_SYS_CLKR+1,
779 ReadXBYTE(REG_SYS_CLKR+1) | BIT(3)); */
Larry Fingerf7c92d22014-03-28 21:37:39 -0500780
Jes Sorensenb0247932014-11-30 16:05:06 -0500781 /* 2. Force PWM, Enable SPS18_LDO_Marco_Block */
782 rtl8723au_write8(Adapter, REG_SPS0_CTRL,
783 sps0 | BIT(0) | BIT(3));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500784
Jes Sorensenb0247932014-11-30 16:05:06 -0500785 /* 3. restore BB, AFE control register. */
786 /* RF */
787 if (pHalData->rf_type == RF_2T2R)
788 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter,
789 0x380038, 1);
790 else
791 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter,
792 0x38, 1);
793 PHY_SetBBReg(Adapter, rOFDM0_TRxPathEnable, 0xf0, 1);
794 PHY_SetBBReg(Adapter, rFPGA0_RFMOD, BIT(1), 0);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500795
Jes Sorensenb0247932014-11-30 16:05:06 -0500796 /* AFE */
797 if (pHalData->rf_type == RF_2T2R)
Jes Sorensen2c177a82015-03-05 14:24:41 -0500798 rtl8723au_write32(Adapter, rRx_Wait_CCA, 0x63DB25A0);
Jes Sorensenb0247932014-11-30 16:05:06 -0500799 else if (pHalData->rf_type == RF_1T1R)
Jes Sorensen2c177a82015-03-05 14:24:41 -0500800 rtl8723au_write32(Adapter, rRx_Wait_CCA, 0x631B25A0);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500801
Jes Sorensenb0247932014-11-30 16:05:06 -0500802 /* 4. issue 3-wire command that RF set to Rx idle
803 mode. This is used to re-write the RX idle mode. */
804 /* We can only prvide a usual value instead and then
805 HW will modify the value by itself. */
Jes Sorensen250944682015-02-09 17:52:16 -0500806 PHY_SetRFReg(Adapter, RF_PATH_A, RF_AC,
807 bRFRegOffsetMask, 0x32D95);
Jes Sorensenb0247932014-11-30 16:05:06 -0500808 if (pHalData->rf_type == RF_2T2R) {
Jes Sorensen250944682015-02-09 17:52:16 -0500809 PHY_SetRFReg(Adapter, RF_PATH_B, RF_AC,
Larry Fingerf7c92d22014-03-28 21:37:39 -0500810 bRFRegOffsetMask, 0x32D95);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500811 }
812 break;
813 case rf_sleep:
814 case rf_off:
Larry Fingerf7c92d22014-03-28 21:37:39 -0500815 if (IS_81xxC_VENDOR_UMC_B_CUT(pHalData->VersionID))
Jes Sorensen6e1c29fd2014-11-30 16:05:04 -0500816 sps0 &= ~BIT(0);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500817 else
Jes Sorensen6e1c29fd2014-11-30 16:05:04 -0500818 sps0 &= ~(BIT(0) | BIT(3));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500819
Joe Perches90403aa2015-03-24 16:06:44 -0700820 RT_TRACE(_module_hal_init_c_, _drv_err_, "SS LVL1\n");
Jes Sorensenb0247932014-11-30 16:05:06 -0500821 /* Disable RF and BB only for SelectSuspend. */
Larry Fingerf7c92d22014-03-28 21:37:39 -0500822
Jes Sorensenb0247932014-11-30 16:05:06 -0500823 /* 1. Set BB/RF to shutdown. */
824 /* (1) Reg878[5:3]= 0 RF rx_code for
825 preamble power saving */
826 /* (2)Reg878[21:19]= 0 Turn off RF-B */
827 /* (3) RegC04[7:4]= 0 Turn off all paths
828 for packet detection */
829 /* (4) Reg800[1] = 1 enable preamble power saving */
830 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_RF0] =
Jes Sorensen2c177a82015-03-05 14:24:41 -0500831 rtl8723au_read32(Adapter, rFPGA0_XAB_RFParameter);
Jes Sorensenb0247932014-11-30 16:05:06 -0500832 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_RF1] =
Jes Sorensen2c177a82015-03-05 14:24:41 -0500833 rtl8723au_read32(Adapter, rOFDM0_TRxPathEnable);
Jes Sorensenb0247932014-11-30 16:05:06 -0500834 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_RF2] =
Jes Sorensen2c177a82015-03-05 14:24:41 -0500835 rtl8723au_read32(Adapter, rFPGA0_RFMOD);
Shraddha Barke12d27372015-09-05 18:58:19 +0530836 if (pHalData->rf_type == RF_2T2R)
Jes Sorensenb0247932014-11-30 16:05:06 -0500837 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter,
838 0x380038, 0);
Shraddha Barke12d27372015-09-05 18:58:19 +0530839 else if (pHalData->rf_type == RF_1T1R)
Jes Sorensenb0247932014-11-30 16:05:06 -0500840 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter, 0x38, 0);
Jes Sorensenb0247932014-11-30 16:05:06 -0500841 PHY_SetBBReg(Adapter, rOFDM0_TRxPathEnable, 0xf0, 0);
842 PHY_SetBBReg(Adapter, rFPGA0_RFMOD, BIT(1), 1);
843
844 /* 2 .AFE control register to power down. bit[30:22] */
845 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_AFE0] =
Jes Sorensen2c177a82015-03-05 14:24:41 -0500846 rtl8723au_read32(Adapter, rRx_Wait_CCA);
Jes Sorensenb0247932014-11-30 16:05:06 -0500847 if (pHalData->rf_type == RF_2T2R)
Jes Sorensen2c177a82015-03-05 14:24:41 -0500848 rtl8723au_write32(Adapter, rRx_Wait_CCA, 0x00DB25A0);
Jes Sorensenb0247932014-11-30 16:05:06 -0500849 else if (pHalData->rf_type == RF_1T1R)
Jes Sorensen2c177a82015-03-05 14:24:41 -0500850 rtl8723au_write32(Adapter, rRx_Wait_CCA, 0x001B25A0);
Jes Sorensenb0247932014-11-30 16:05:06 -0500851
852 /* 3. issue 3-wire command that RF set to power down.*/
Jes Sorensen250944682015-02-09 17:52:16 -0500853 PHY_SetRFReg(Adapter, RF_PATH_A, RF_AC, bRFRegOffsetMask, 0);
Jes Sorensenb0247932014-11-30 16:05:06 -0500854 if (pHalData->rf_type == RF_2T2R)
Jes Sorensen250944682015-02-09 17:52:16 -0500855 PHY_SetRFReg(Adapter, RF_PATH_B, RF_AC,
Jes Sorensenb0247932014-11-30 16:05:06 -0500856 bRFRegOffsetMask, 0);
857
858 /* 4. Force PFM , disable SPS18_LDO_Marco_Block */
859 rtl8723au_write8(Adapter, REG_SPS0_CTRL, sps0);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500860 break;
861 default:
862 break;
863 }
Jes Sorensenb0247932014-11-30 16:05:06 -0500864}
Larry Fingerf7c92d22014-03-28 21:37:39 -0500865
Larry Fingerf7c92d22014-03-28 21:37:39 -0500866static void CardDisableRTL8723U(struct rtw_adapter *Adapter)
867{
868 u8 u1bTmp;
869
870 DBG_8723A("CardDisableRTL8723U\n");
871 /* USB-MF Card Disable Flow */
872 /* 1. Run LPS WL RFOFF flow */
873 HalPwrSeqCmdParsing23a(Adapter, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
874 PWR_INTF_USB_MSK, rtl8723AU_enter_lps_flow);
875
876 /* 2. 0x1F[7:0] = 0 turn off RF */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200877 rtl8723au_write8(Adapter, REG_RF_CTRL, 0x00);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500878
879 /* ==== Reset digital sequence ====== */
Jes Sorensen050abc42014-05-16 10:05:08 +0200880 if ((rtl8723au_read8(Adapter, REG_MCUFWDL) & BIT(7)) &&
Larry Fingerf7c92d22014-03-28 21:37:39 -0500881 Adapter->bFWReady) /* 8051 RAM code */
882 rtl8723a_FirmwareSelfReset(Adapter);
883
884 /* Reset MCU. Suggested by Filen. 2011.01.26. by tynli. */
Jes Sorensen050abc42014-05-16 10:05:08 +0200885 u1bTmp = rtl8723au_read8(Adapter, REG_SYS_FUNC_EN+1);
Jes Sorensenedbfd672014-05-16 10:05:09 +0200886 rtl8723au_write8(Adapter, REG_SYS_FUNC_EN+1, u1bTmp & ~BIT(2));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500887
888 /* g. MCUFWDL 0x80[1:0]= 0 reset MCU ready status */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200889 rtl8723au_write8(Adapter, REG_MCUFWDL, 0x00);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500890
891 /* ==== Reset digital sequence end ====== */
892 /* Card disable power action flow */
893 HalPwrSeqCmdParsing23a(Adapter, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
894 PWR_INTF_USB_MSK,
895 rtl8723AU_card_disable_flow);
896
897 /* Reset MCU IO Wrapper, added by Roger, 2011.08.30. */
Jes Sorensen050abc42014-05-16 10:05:08 +0200898 u1bTmp = rtl8723au_read8(Adapter, REG_RSV_CTRL + 1);
Jes Sorensenedbfd672014-05-16 10:05:09 +0200899 rtl8723au_write8(Adapter, REG_RSV_CTRL+1, u1bTmp & ~BIT(0));
Jes Sorensen050abc42014-05-16 10:05:08 +0200900 u1bTmp = rtl8723au_read8(Adapter, REG_RSV_CTRL + 1);
Jes Sorensenedbfd672014-05-16 10:05:09 +0200901 rtl8723au_write8(Adapter, REG_RSV_CTRL+1, u1bTmp | BIT(0));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500902
903 /* 7. RSV_CTRL 0x1C[7:0] = 0x0E lock ISO/CLK/Power control register */
Jes Sorensenedbfd672014-05-16 10:05:09 +0200904 rtl8723au_write8(Adapter, REG_RSV_CTRL, 0x0e);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500905}
906
Jes Sorensendc20d1d2014-07-21 11:25:07 +0200907int rtl8723au_hal_deinit(struct rtw_adapter *padapter)
Larry Fingerf7c92d22014-03-28 21:37:39 -0500908{
909 DBG_8723A("==> %s\n", __func__);
910
911#ifdef CONFIG_8723AU_BT_COEXIST
912 BT_HaltProcess(padapter);
913#endif
914 /* 2011/02/18 To Fix RU LNA power leakage problem. We need to
915 execute below below in Adapter init and halt sequence.
916 According to EEchou's opinion, we can enable the ability for all */
917 /* IC. Accord to johnny's opinion, only RU need the support. */
918 CardDisableRTL8723U(padapter);
919
Jes Sorensendc20d1d2014-07-21 11:25:07 +0200920 padapter->hw_init_completed = false;
921
Larry Fingerf7c92d22014-03-28 21:37:39 -0500922 return _SUCCESS;
923}
924
Jes Sorensen1aaa3762014-05-16 10:04:05 +0200925int rtl8723au_inirp_init(struct rtw_adapter *Adapter)
Larry Fingerf7c92d22014-03-28 21:37:39 -0500926{
927 u8 i;
928 struct recv_buf *precvbuf;
Jes Sorensen1aaa3762014-05-16 10:04:05 +0200929 int status;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500930 struct recv_priv *precvpriv = &Adapter->recvpriv;
Jes Sorensenad899b12014-05-16 10:04:31 +0200931 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500932
Larry Fingerf7c92d22014-03-28 21:37:39 -0500933 status = _SUCCESS;
934
Joe Perches90403aa2015-03-24 16:06:44 -0700935 RT_TRACE(_module_hci_hal_init_c_, _drv_info_, "===> usb_inirp_init\n");
Larry Fingerf7c92d22014-03-28 21:37:39 -0500936
Larry Fingerf7c92d22014-03-28 21:37:39 -0500937 /* issue Rx irp to receive data */
938 precvbuf = (struct recv_buf *)precvpriv->precv_buf;
939 for (i = 0; i < NR_RECVBUFF; i++) {
Jes Sorensenb1f43bd2014-11-30 16:05:08 -0500940 if (rtl8723au_read_port(Adapter, 0, precvbuf) == _FAIL) {
Larry Fingerf7c92d22014-03-28 21:37:39 -0500941 RT_TRACE(_module_hci_hal_init_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -0700942 "usb_rx_init: usb_read_port error\n");
Larry Fingerf7c92d22014-03-28 21:37:39 -0500943 status = _FAIL;
944 goto exit;
945 }
946 precvbuf++;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500947 }
Jes Sorensenc6419a62014-11-30 16:05:09 -0500948 if (rtl8723au_read_interrupt(Adapter) == _FAIL) {
Larry Fingerf7c92d22014-03-28 21:37:39 -0500949 RT_TRACE(_module_hci_hal_init_c_, _drv_err_,
Joe Perches90403aa2015-03-24 16:06:44 -0700950 "%s: usb_read_interrupt error\n", __func__);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500951 status = _FAIL;
952 }
Jes Sorensen050abc42014-05-16 10:05:08 +0200953 pHalData->IntrMask[0] = rtl8723au_read32(Adapter, REG_USB_HIMR);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500954 MSG_8723A("pHalData->IntrMask = 0x%04x\n", pHalData->IntrMask[0]);
955 pHalData->IntrMask[0] |= UHIMR_C2HCMD|UHIMR_CPWM;
Jes Sorensenedbfd672014-05-16 10:05:09 +0200956 rtl8723au_write32(Adapter, REG_USB_HIMR, pHalData->IntrMask[0]);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500957exit:
958 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
Joe Perches90403aa2015-03-24 16:06:44 -0700959 "<=== usb_inirp_init\n");
Larry Fingerf7c92d22014-03-28 21:37:39 -0500960 return status;
961}
962
Jes Sorensen1aaa3762014-05-16 10:04:05 +0200963int rtl8723au_inirp_deinit(struct rtw_adapter *Adapter)
Larry Fingerf7c92d22014-03-28 21:37:39 -0500964{
965 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
966
967 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
Joe Perches90403aa2015-03-24 16:06:44 -0700968 "===> usb_rx_deinit\n");
Jes Sorensen68552a92014-05-16 10:05:10 +0200969 rtl8723au_read_port_cancel(Adapter);
Jes Sorensen050abc42014-05-16 10:05:08 +0200970 pHalData->IntrMask[0] = rtl8723au_read32(Adapter, REG_USB_HIMR);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500971 MSG_8723A("%s pHalData->IntrMask = 0x%04x\n", __func__,
972 pHalData->IntrMask[0]);
973 pHalData->IntrMask[0] = 0x0;
Jes Sorensenedbfd672014-05-16 10:05:09 +0200974 rtl8723au_write32(Adapter, REG_USB_HIMR, pHalData->IntrMask[0]);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500975 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
Joe Perches90403aa2015-03-24 16:06:44 -0700976 "<=== usb_rx_deinit\n");
Larry Fingerf7c92d22014-03-28 21:37:39 -0500977 return _SUCCESS;
978}
979
980static void _ReadBoardType(struct rtw_adapter *Adapter, u8 *PROMContent,
981 bool AutoloadFail)
982{
983 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
984 u8 boardType = BOARD_USB_DONGLE;
985
986 if (AutoloadFail) {
987 if (IS_8723_SERIES(pHalData->VersionID))
988 pHalData->rf_type = RF_1T1R;
989 else
990 pHalData->rf_type = RF_2T2R;
991 pHalData->BoardType = boardType;
992 return;
993 }
994
995 boardType = PROMContent[EEPROM_NORMAL_BoardType];
996 boardType &= BOARD_TYPE_NORMAL_MASK;/* bit[7:5] */
997 boardType >>= 5;
998
999 pHalData->BoardType = boardType;
1000 MSG_8723A("_ReadBoardType(%x)\n", pHalData->BoardType);
1001
1002 if (boardType == BOARD_USB_High_PA)
1003 pHalData->ExternalPA = 1;
1004}
1005
Larry Fingerf7c92d22014-03-28 21:37:39 -05001006static void Hal_EfuseParseMACAddr_8723AU(struct rtw_adapter *padapter,
1007 u8 *hwinfo, bool AutoLoadFail)
1008{
1009 u16 i;
1010 u8 sMacAddr[ETH_ALEN] = {0x00, 0xE0, 0x4C, 0x87, 0x23, 0x00};
1011 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
1012
1013 if (AutoLoadFail) {
1014 for (i = 0; i < 6; i++)
1015 pEEPROM->mac_addr[i] = sMacAddr[i];
1016 } else {
1017 /* Read Permanent MAC address */
1018 memcpy(pEEPROM->mac_addr, &hwinfo[EEPROM_MAC_ADDR_8723AU],
1019 ETH_ALEN);
1020 }
1021
1022 RT_TRACE(_module_hci_hal_init_c_, _drv_notice_,
Daniil Leshchev78f73d92015-12-31 15:36:42 +03001023 "Hal_EfuseParseMACAddr_8723AU: Permanent Address =%pM\n",
1024 pEEPROM->mac_addr);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001025}
1026
1027static void readAdapterInfo(struct rtw_adapter *padapter)
1028{
1029 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
1030 /* struct hal_data_8723a * pHalData = GET_HAL_DATA(padapter); */
1031 u8 hwinfo[HWSET_MAX_SIZE];
1032
1033 Hal_InitPGData(padapter, hwinfo);
1034 Hal_EfuseParseIDCode(padapter, hwinfo);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001035 Hal_EfuseParseEEPROMVer(padapter, hwinfo,
1036 pEEPROM->bautoload_fail_flag);
1037 Hal_EfuseParseMACAddr_8723AU(padapter, hwinfo,
1038 pEEPROM->bautoload_fail_flag);
1039 Hal_EfuseParsetxpowerinfo_8723A(padapter, hwinfo,
1040 pEEPROM->bautoload_fail_flag);
1041 _ReadBoardType(padapter, hwinfo, pEEPROM->bautoload_fail_flag);
1042 Hal_EfuseParseBTCoexistInfo_8723A(padapter, hwinfo,
1043 pEEPROM->bautoload_fail_flag);
1044
1045 rtl8723a_EfuseParseChnlPlan(padapter, hwinfo,
1046 pEEPROM->bautoload_fail_flag);
1047 Hal_EfuseParseThermalMeter_8723A(padapter, hwinfo,
1048 pEEPROM->bautoload_fail_flag);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001049/* _ReadRFSetting(Adapter, PROMContent, pEEPROM->bautoload_fail_flag); */
1050/* _ReadPSSetting(Adapter, PROMContent, pEEPROM->bautoload_fail_flag); */
1051 Hal_EfuseParseAntennaDiversity(padapter, hwinfo,
1052 pEEPROM->bautoload_fail_flag);
1053
1054 Hal_EfuseParseEEPROMVer(padapter, hwinfo, pEEPROM->bautoload_fail_flag);
1055 Hal_EfuseParseCustomerID(padapter, hwinfo,
1056 pEEPROM->bautoload_fail_flag);
1057 Hal_EfuseParseRateIndicationOption(padapter, hwinfo,
1058 pEEPROM->bautoload_fail_flag);
1059 Hal_EfuseParseXtal_8723A(padapter, hwinfo,
1060 pEEPROM->bautoload_fail_flag);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001061
1062 /* hal_CustomizedBehavior_8723U(Adapter); */
1063
1064/* Adapter->bDongle = (PROMContent[EEPROM_EASY_REPLACEMENT] == 1)? 0: 1; */
1065 DBG_8723A("%s(): REPLACEMENT = %x\n", __func__, padapter->bDongle);
1066}
1067
1068static void _ReadPROMContent(struct rtw_adapter *Adapter)
1069{
1070 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(Adapter);
1071 u8 eeValue;
1072
Jes Sorensen050abc42014-05-16 10:05:08 +02001073 eeValue = rtl8723au_read8(Adapter, REG_9346CR);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001074 /* To check system boot selection. */
1075 pEEPROM->EepromOrEfuse = (eeValue & BOOT_FROM_EEPROM) ? true : false;
1076 pEEPROM->bautoload_fail_flag = (eeValue & EEPROM_EN) ? false : true;
1077
1078 DBG_8723A("Boot from %s, Autoload %s !\n",
1079 (pEEPROM->EepromOrEfuse ? "EEPROM" : "EFUSE"),
1080 (pEEPROM->bautoload_fail_flag ? "Fail" : "OK"));
1081
1082 readAdapterInfo(Adapter);
1083}
1084
Larry Fingerf7c92d22014-03-28 21:37:39 -05001085/* */
1086/* Description: */
1087/* We should set Efuse cell selection to WiFi cell in default. */
1088/* */
1089/* Assumption: */
1090/* PASSIVE_LEVEL */
1091/* */
1092/* Added by Roger, 2010.11.23. */
1093/* */
1094static void hal_EfuseCellSel(struct rtw_adapter *Adapter)
1095{
1096 u32 value32;
1097
Jes Sorensen050abc42014-05-16 10:05:08 +02001098 value32 = rtl8723au_read32(Adapter, EFUSE_TEST);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001099 value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_WIFI_SEL_0);
Jes Sorensenedbfd672014-05-16 10:05:09 +02001100 rtl8723au_write32(Adapter, EFUSE_TEST, value32);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001101}
1102
Jes Sorensen1f4746f2014-05-16 10:03:58 +02001103void rtl8723a_read_adapter_info(struct rtw_adapter *Adapter)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001104{
Larry Fingerf7c92d22014-03-28 21:37:39 -05001105 unsigned long start = jiffies;
1106
Jes Sorensen1f4746f2014-05-16 10:03:58 +02001107 /* Read EEPROM size before call any EEPROM function */
1108 Adapter->EepromAddressSize = GetEEPROMSize8723A(Adapter);
1109
Larry Fingerf7c92d22014-03-28 21:37:39 -05001110 MSG_8723A("====> _ReadAdapterInfo8723AU\n");
1111
1112 hal_EfuseCellSel(Adapter);
1113
Larry Fingerf7c92d22014-03-28 21:37:39 -05001114 _ReadPROMContent(Adapter);
1115
Larry Fingerf7c92d22014-03-28 21:37:39 -05001116 MSG_8723A("<==== _ReadAdapterInfo8723AU in %d ms\n",
1117 jiffies_to_msecs(jiffies - start));
Larry Fingerf7c92d22014-03-28 21:37:39 -05001118}
1119
Larry Fingerf7c92d22014-03-28 21:37:39 -05001120/* */
1121/* Description: */
1122/* Query setting of specified variable. */
1123/* */
Jes Sorensen39f1a8e2014-05-16 10:04:20 +02001124int GetHalDefVar8192CUsb(struct rtw_adapter *Adapter,
1125 enum hal_def_variable eVariable, void *pValue)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001126{
Jes Sorensen39f1a8e2014-05-16 10:04:20 +02001127 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
1128 int bResult = _SUCCESS;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001129
1130 switch (eVariable) {
1131 case HAL_DEF_UNDERCORATEDSMOOTHEDPWDB:
1132 *((int *)pValue) = pHalData->dmpriv.UndecoratedSmoothedPWDB;
1133 break;
1134 case HAL_DEF_IS_SUPPORT_ANT_DIV:
1135 break;
1136 case HAL_DEF_CURRENT_ANTENNA:
1137 break;
1138 case HAL_DEF_DRVINFO_SZ:
1139 *((u32 *)pValue) = DRVINFO_SZ;
1140 break;
1141 case HAL_DEF_MAX_RECVBUF_SZ:
1142 *((u32 *)pValue) = MAX_RECVBUF_SZ;
1143 break;
1144 case HAL_DEF_RX_PACKET_OFFSET:
1145 *((u32 *)pValue) = RXDESC_SIZE + DRVINFO_SZ;
1146 break;
1147 case HAL_DEF_DBG_DUMP_RXPKT:
1148 *((u8 *)pValue) = pHalData->bDumpRxPkt;
1149 break;
1150 case HAL_DEF_DBG_DM_FUNC:
1151 *((u32 *)pValue) = pHalData->odmpriv.SupportAbility;
1152 break;
1153 case HW_VAR_MAX_RX_AMPDU_FACTOR:
1154 *((u32 *)pValue) = IEEE80211_HT_MAX_AMPDU_64K;
1155 break;
1156 case HW_DEF_ODM_DBG_FLAG:
1157 {
1158 struct dm_odm_t *pDM_Odm = &pHalData->odmpriv;
1159 printk("pDM_Odm->DebugComponents = 0x%llx\n",
1160 pDM_Odm->DebugComponents);
1161 }
1162 break;
1163 default:
Larry Fingerf7c92d22014-03-28 21:37:39 -05001164 bResult = _FAIL;
1165 break;
1166 }
1167
1168 return bResult;
1169}
1170
Jes Sorensenac4cbc62014-05-16 10:04:19 +02001171void rtl8723a_update_ramask(struct rtw_adapter *padapter,
1172 u32 mac_id, u8 rssi_level)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001173{
Larry Fingerf7c92d22014-03-28 21:37:39 -05001174 struct sta_info *psta;
Jes Sorensen36318bd2014-11-30 16:05:11 -05001175 struct FW_Sta_Info *fw_sta;
1176 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
1177 struct dm_priv *pdmpriv = &pHalData->dmpriv;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001178 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1179 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1180 struct wlan_bssid_ex *cur_network = &pmlmeinfo->network;
Jes Sorensenb1e4d2f2015-02-09 17:52:17 -05001181 u8 init_rate, networkType, raid, arg;
Jes Sorensen36318bd2014-11-30 16:05:11 -05001182 u32 mask, rate_bitmap;
1183 u8 shortGIrate = false;
1184 int supportRateNum;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001185
1186 if (mac_id >= NUM_STA) /* CAM_SIZE */
1187 return;
1188
1189 psta = pmlmeinfo->FW_sta_info[mac_id].psta;
1190 if (psta == NULL)
1191 return;
1192
1193 switch (mac_id) {
1194 case 0:/* for infra mode */
1195 supportRateNum =
1196 rtw_get_rateset_len23a(cur_network->SupportedRates);
1197 networkType = judge_network_type23a(padapter,
1198 cur_network->SupportedRates,
1199 supportRateNum) & 0xf;
1200 /* pmlmeext->cur_wireless_mode = networkType; */
1201 raid = networktype_to_raid23a(networkType);
1202
1203 mask = update_supported_rate23a(cur_network->SupportedRates,
1204 supportRateNum);
1205 mask |= (pmlmeinfo->HT_enable) ?
Jes Sorensen65be27d2014-05-31 18:05:11 +02001206 update_MSC_rate23a(&pmlmeinfo->ht_cap) : 0;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001207
Jes Sorensen65be27d2014-05-31 18:05:11 +02001208 if (support_short_GI23a(padapter, &pmlmeinfo->ht_cap))
Larry Fingerf7c92d22014-03-28 21:37:39 -05001209 shortGIrate = true;
1210 break;
1211
1212 case 1:/* for broadcast/multicast */
Jes Sorensen36318bd2014-11-30 16:05:11 -05001213 fw_sta = &pmlmeinfo->FW_sta_info[mac_id];
1214 supportRateNum = rtw_get_rateset_len23a(fw_sta->SupportedRates);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001215 if (pmlmeext->cur_wireless_mode & WIRELESS_11B)
1216 networkType = WIRELESS_11B;
1217 else
1218 networkType = WIRELESS_11G;
1219 raid = networktype_to_raid23a(networkType);
1220
1221 mask = update_basic_rate23a(cur_network->SupportedRates,
1222 supportRateNum);
1223 break;
1224
1225 default: /* for each sta in IBSS */
Jes Sorensen36318bd2014-11-30 16:05:11 -05001226 fw_sta = &pmlmeinfo->FW_sta_info[mac_id];
1227 supportRateNum = rtw_get_rateset_len23a(fw_sta->SupportedRates);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001228 networkType = judge_network_type23a(padapter,
Jes Sorensen36318bd2014-11-30 16:05:11 -05001229 fw_sta->SupportedRates,
1230 supportRateNum) & 0xf;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001231 /* pmlmeext->cur_wireless_mode = networkType; */
1232 raid = networktype_to_raid23a(networkType);
1233
1234 mask = update_supported_rate23a(cur_network->SupportedRates,
Jes Sorensen36318bd2014-11-30 16:05:11 -05001235 supportRateNum);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001236
1237 /* todo: support HT in IBSS */
1238 break;
1239 }
1240
1241 /* mask &= 0x0fffffff; */
Jes Sorensen301fc632014-07-21 11:24:57 +02001242 rate_bitmap = ODM_Get_Rate_Bitmap23a(pHalData, mac_id, mask,
1243 rssi_level);
Jes Sorensen316f6212014-05-21 09:38:03 +02001244 DBG_8723A("%s => mac_id:%d, networkType:0x%02x, "
1245 "mask:0x%08x\n\t ==> rssi_level:%d, rate_bitmap:0x%08x\n",
1246 __func__, mac_id, networkType, mask, rssi_level, rate_bitmap);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001247
1248 mask &= rate_bitmap;
Jes Sorensen36318bd2014-11-30 16:05:11 -05001249 mask |= ((raid << 28) & 0xf0000000);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001250
Jes Sorensen36318bd2014-11-30 16:05:11 -05001251 init_rate = get_highest_rate_idx23a(mask) & 0x3f;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001252
Jes Sorensenb1e4d2f2015-02-09 17:52:17 -05001253 arg = mac_id & 0x1f;/* MACID */
1254 arg |= BIT(7);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001255
Jes Sorensenb1e4d2f2015-02-09 17:52:17 -05001256 if (shortGIrate == true)
1257 arg |= BIT(5);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001258
Jes Sorensenb1e4d2f2015-02-09 17:52:17 -05001259 DBG_8723A("update raid entry, mask = 0x%x, arg = 0x%x\n", mask, arg);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001260
Jes Sorensenb1e4d2f2015-02-09 17:52:17 -05001261 rtl8723a_set_raid_cmd(padapter, mask, arg);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001262
1263 /* set ra_id */
1264 psta->raid = raid;
1265 psta->init_rate = init_rate;
1266
1267 /* set correct initial date rate for each mac_id */
1268 pdmpriv->INIDATA_RATE[mac_id] = init_rate;
1269}