blob: e279c34b3fc6eef0626432bcc4bb12fbf7a3f388 [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
16#include "odm_precomp.h"
Jes Sorensen050abc42014-05-16 10:05:08 +020017#include "usb_ops_linux.h"
Larry Fingerf7c92d22014-03-28 21:37:39 -050018
19static const u16 dB_Invert_Table[8][12] = {
20 {1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4},
21 {4, 5, 6, 6, 7, 8, 9, 10, 11, 13, 14, 16},
22 {18, 20, 22, 25, 28, 32, 35, 40, 45, 50, 56, 63},
23 {71, 79, 89, 100, 112, 126, 141, 158, 178, 200, 224, 251},
24 {282, 316, 355, 398, 447, 501, 562, 631, 708, 794, 891, 1000},
25 {1122, 1259, 1413, 1585, 1778, 1995, 2239, 2512, 2818, 3162, 3548, 3981},
26 {4467, 5012, 5623, 6310, 7079, 7943, 8913, 10000, 11220, 12589, 14125, 15849},
27 {17783, 19953, 22387, 25119, 28184, 31623, 35481, 39811, 44668, 50119, 56234, 65535}
28};
29
30static u32 EDCAParam[HT_IOT_PEER_MAX][3] = { /* UL DL */
31 {0x5ea42b, 0x5ea42b, 0x5ea42b}, /* 0:unknown AP */
32 {0xa44f, 0x5ea44f, 0x5e431c}, /* 1:realtek AP */
33 {0x5ea42b, 0x5ea42b, 0x5ea42b}, /* 2:unknown AP => realtek_92SE */
34 {0x5ea32b, 0x5ea42b, 0x5e4322}, /* 3:broadcom AP */
35 {0x5ea422, 0x00a44f, 0x00a44f}, /* 4:ralink AP */
36 {0x5ea322, 0x00a630, 0x00a44f}, /* 5:atheros AP */
37 {0x5e4322, 0x5e4322, 0x5e4322},/* 6:cisco AP */
38 {0x5ea44f, 0x00a44f, 0x5ea42b}, /* 8:marvell AP */
39 {0x5ea42b, 0x5ea42b, 0x5ea42b}, /* 10:unknown AP => 92U AP */
40 {0x5ea42b, 0xa630, 0x5e431c}, /* 11:airgocap AP */
41};
42
Carlos E. Garcia69e98df2015-04-24 09:40:42 -040043/* EDCA Parameter for AP/ADSL by Mingzhi 2011-11-22 */
Larry Fingerf7c92d22014-03-28 21:37:39 -050044
45/* Global var */
46u32 OFDMSwingTable23A[OFDM_TABLE_SIZE_92D] = {
47 0x7f8001fe, /* 0, +6.0dB */
48 0x788001e2, /* 1, +5.5dB */
49 0x71c001c7, /* 2, +5.0dB */
50 0x6b8001ae, /* 3, +4.5dB */
51 0x65400195, /* 4, +4.0dB */
52 0x5fc0017f, /* 5, +3.5dB */
53 0x5a400169, /* 6, +3.0dB */
54 0x55400155, /* 7, +2.5dB */
55 0x50800142, /* 8, +2.0dB */
56 0x4c000130, /* 9, +1.5dB */
57 0x47c0011f, /* 10, +1.0dB */
58 0x43c0010f, /* 11, +0.5dB */
59 0x40000100, /* 12, +0dB */
60 0x3c8000f2, /* 13, -0.5dB */
61 0x390000e4, /* 14, -1.0dB */
62 0x35c000d7, /* 15, -1.5dB */
63 0x32c000cb, /* 16, -2.0dB */
64 0x300000c0, /* 17, -2.5dB */
65 0x2d4000b5, /* 18, -3.0dB */
66 0x2ac000ab, /* 19, -3.5dB */
67 0x288000a2, /* 20, -4.0dB */
68 0x26000098, /* 21, -4.5dB */
69 0x24000090, /* 22, -5.0dB */
70 0x22000088, /* 23, -5.5dB */
71 0x20000080, /* 24, -6.0dB */
72 0x1e400079, /* 25, -6.5dB */
73 0x1c800072, /* 26, -7.0dB */
74 0x1b00006c, /* 27. -7.5dB */
75 0x19800066, /* 28, -8.0dB */
76 0x18000060, /* 29, -8.5dB */
77 0x16c0005b, /* 30, -9.0dB */
78 0x15800056, /* 31, -9.5dB */
79 0x14400051, /* 32, -10.0dB */
80 0x1300004c, /* 33, -10.5dB */
81 0x12000048, /* 34, -11.0dB */
82 0x11000044, /* 35, -11.5dB */
83 0x10000040, /* 36, -12.0dB */
84 0x0f00003c,/* 37, -12.5dB */
85 0x0e400039,/* 38, -13.0dB */
86 0x0d800036,/* 39, -13.5dB */
87 0x0cc00033,/* 40, -14.0dB */
88 0x0c000030,/* 41, -14.5dB */
89 0x0b40002d,/* 42, -15.0dB */
90};
91
92u8 CCKSwingTable_Ch1_Ch1323A[CCK_TABLE_SIZE][8] = {
93 {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, /* 0, +0dB */
94 {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /* 1, -0.5dB */
95 {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 2, -1.0dB */
96 {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /* 3, -1.5dB */
97 {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 4, -2.0dB */
98 {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /* 5, -2.5dB */
99 {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 6, -3.0dB */
100 {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /* 7, -3.5dB */
101 {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 8, -4.0dB */
102 {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /* 9, -4.5dB */
103 {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 10, -5.0dB */
104 {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /* 11, -5.5dB */
105 {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /* 12, -6.0dB */
106 {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /* 13, -6.5dB */
107 {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 14, -7.0dB */
108 {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /* 15, -7.5dB */
109 {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 16, -8.0dB */
110 {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /* 17, -8.5dB */
111 {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 18, -9.0dB */
112 {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 19, -9.5dB */
113 {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 20, -10.0dB */
114 {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 21, -10.5dB */
115 {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 22, -11.0dB */
116 {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /* 23, -11.5dB */
117 {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /* 24, -12.0dB */
118 {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /* 25, -12.5dB */
119 {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /* 26, -13.0dB */
120 {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 27, -13.5dB */
121 {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 28, -14.0dB */
122 {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 29, -14.5dB */
123 {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 30, -15.0dB */
124 {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /* 31, -15.5dB */
125 {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01} /* 32, -16.0dB */
126};
127
128u8 CCKSwingTable_Ch1423A[CCK_TABLE_SIZE][8] = {
129 {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, /* 0, +0dB */
130 {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /* 1, -0.5dB */
131 {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 2, -1.0dB */
132 {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /* 3, -1.5dB */
133 {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 4, -2.0dB */
134 {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /* 5, -2.5dB */
135 {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 6, -3.0dB */
136 {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /* 7, -3.5dB */
137 {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 8, -4.0dB */
138 {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /* 9, -4.5dB */
139 {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 10, -5.0dB */
140 {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 11, -5.5dB */
141 {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 12, -6.0dB */
142 {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /* 13, -6.5dB */
143 {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 14, -7.0dB */
144 {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 15, -7.5dB */
145 {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 16, -8.0dB */
146 {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 17, -8.5dB */
147 {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 18, -9.0dB */
148 {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 19, -9.5dB */
149 {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 20, -10.0dB */
150 {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 21, -10.5dB */
151 {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 22, -11.0dB */
152 {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 23, -11.5dB */
153 {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 24, -12.0dB */
154 {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 25, -12.5dB */
155 {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 26, -13.0dB */
156 {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 27, -13.5dB */
157 {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 28, -14.0dB */
158 {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 29, -14.5dB */
159 {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 30, -15.0dB */
160 {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 31, -15.5dB */
161 {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00} /* 32, -16.0dB */
162};
163
164/* Local Function predefine. */
165
166/* START------------COMMON INFO RELATED--------------- */
167void odm_CommonInfoSelfInit23a(struct dm_odm_t *pDM_Odm);
168
Jes Sorensen91a29162014-07-21 11:24:56 +0200169static void odm_CommonInfoSelfUpdate(struct hal_data_8723a *pHalData);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500170
171void odm_CmnInfoInit_Debug23a(struct dm_odm_t *pDM_Odm);
172
Larry Fingerf7c92d22014-03-28 21:37:39 -0500173void odm_CmnInfoUpdate_Debug23a(struct dm_odm_t *pDM_Odm);
174
175/* START---------------DIG--------------------------- */
176void odm_FalseAlarmCounterStatistics23a(struct dm_odm_t *pDM_Odm);
177
178void odm_DIG23aInit(struct dm_odm_t *pDM_Odm);
179
Jes Sorensen1a573d22014-07-21 11:24:59 +0200180void odm_DIG23a(struct rtw_adapter *adapter);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500181
182void odm_CCKPacketDetectionThresh23a(struct dm_odm_t *pDM_Odm);
183/* END---------------DIG--------------------------- */
184
185/* START-------BB POWER SAVE----------------------- */
186void odm23a_DynBBPSInit(struct dm_odm_t *pDM_Odm);
187
Larry Fingerf7c92d22014-03-28 21:37:39 -0500188
Larry Fingerf7c92d22014-03-28 21:37:39 -0500189/* END---------BB POWER SAVE----------------------- */
190
Larry Fingerf7c92d22014-03-28 21:37:39 -0500191void odm_DynamicTxPower23aInit(struct dm_odm_t *pDM_Odm);
192
Jes Sorensen04b74662015-03-02 15:24:59 -0500193static void odm_RSSIMonitorCheck(struct dm_odm_t *pDM_Odm);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500194void odm_DynamicTxPower23a(struct dm_odm_t *pDM_Odm);
195
Jes Sorensenb58298e2015-03-02 15:25:01 -0500196static void odm_RefreshRateAdaptiveMask(struct dm_odm_t *pDM_Odm);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500197
Larry Fingerf7c92d22014-03-28 21:37:39 -0500198void odm_RateAdaptiveMaskInit23a(struct dm_odm_t *pDM_Odm);
199
Jes Sorensendef0c452015-03-05 14:24:36 -0500200static void odm_TXPowerTrackingInit(struct dm_odm_t *pDM_Odm);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500201
Jes Sorensen4d1def6b2014-07-21 11:24:42 +0200202static void odm_EdcaTurboCheck23a(struct dm_odm_t *pDM_Odm);
203static void ODM_EdcaTurboInit23a(struct dm_odm_t *pDM_Odm);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500204
Larry Fingerf7c92d22014-03-28 21:37:39 -0500205#define RxDefaultAnt1 0x65a9
206#define RxDefaultAnt2 0x569a
207
Larry Fingerf7c92d22014-03-28 21:37:39 -0500208bool odm_StaDefAntSel(struct dm_odm_t *pDM_Odm,
Melike Yurtogluef37b772015-02-26 08:51:03 +0200209 u32 OFDM_Ant1_Cnt,
210 u32 OFDM_Ant2_Cnt,
211 u32 CCK_Ant1_Cnt,
212 u32 CCK_Ant2_Cnt,
213 u8 *pDefAnt
Larry Fingerf7c92d22014-03-28 21:37:39 -0500214 );
215
216void odm_SetRxIdleAnt(struct dm_odm_t *pDM_Odm,
217 u8 Ant,
Melike Yurtogluef37b772015-02-26 08:51:03 +0200218 bool bDualPath
Larry Fingerf7c92d22014-03-28 21:37:39 -0500219);
220
Larry Fingerf7c92d22014-03-28 21:37:39 -0500221/* 3 Export Interface */
222
223/* 2011/09/21 MH Add to describe different team necessary resource allocate?? */
224void ODM23a_DMInit(struct dm_odm_t *pDM_Odm)
225{
226 /* For all IC series */
227 odm_CommonInfoSelfInit23a(pDM_Odm);
228 odm_CmnInfoInit_Debug23a(pDM_Odm);
229 odm_DIG23aInit(pDM_Odm);
230 odm_RateAdaptiveMaskInit23a(pDM_Odm);
231
Jes Sorensen344af822014-07-17 22:59:55 +0200232 odm23a_DynBBPSInit(pDM_Odm);
233 odm_DynamicTxPower23aInit(pDM_Odm);
Jes Sorensendef0c452015-03-05 14:24:36 -0500234 odm_TXPowerTrackingInit(pDM_Odm);
Jes Sorensen344af822014-07-17 22:59:55 +0200235 ODM_EdcaTurboInit23a(pDM_Odm);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500236}
237
238/* 2011/09/20 MH This is the entry pointer for all team to execute HW out source DM. */
239/* You can not add any dummy function here, be care, you can only use DM structure */
240/* to perform any new ODM_DM. */
Jes Sorensen1a573d22014-07-21 11:24:59 +0200241void ODM_DMWatchdog23a(struct rtw_adapter *adapter)
Larry Fingerf7c92d22014-03-28 21:37:39 -0500242{
Jes Sorensen1a573d22014-07-21 11:24:59 +0200243 struct hal_data_8723a *pHalData = GET_HAL_DATA(adapter);
Jes Sorensenec8884f2014-07-21 11:24:55 +0200244 struct dm_odm_t *pDM_Odm = &pHalData->odmpriv;
Jes Sorensen638847c2014-07-21 11:25:00 +0200245 struct pwrctrl_priv *pwrctrlpriv = &adapter->pwrctrlpriv;
Jes Sorensenec8884f2014-07-21 11:24:55 +0200246
Larry Fingerf7c92d22014-03-28 21:37:39 -0500247 /* 2012.05.03 Luke: For all IC series */
Larry Fingerf7c92d22014-03-28 21:37:39 -0500248 odm_CmnInfoUpdate_Debug23a(pDM_Odm);
Jes Sorensen91a29162014-07-21 11:24:56 +0200249 odm_CommonInfoSelfUpdate(pHalData);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500250 odm_FalseAlarmCounterStatistics23a(pDM_Odm);
Jes Sorensen04b74662015-03-02 15:24:59 -0500251 odm_RSSIMonitorCheck(pDM_Odm);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500252
253 /* 8723A or 8189ES platform */
254 /* NeilChen--2012--08--24-- */
255 /* Fix Leave LPS issue */
256 if ((pDM_Odm->Adapter->pwrctrlpriv.pwr_mode != PS_MODE_ACTIVE) &&/* in LPS mode */
Jes Sorensen344af822014-07-17 22:59:55 +0200257 (pDM_Odm->SupportICType & ODM_RTL8723A)) {
Larry Fingerf7c92d22014-03-28 21:37:39 -0500258 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("----Step1: odm_DIG23a is in LPS mode\n"));
259 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("---Step2: 8723AS is in LPS mode\n"));
260 odm_DIG23abyRSSI_LPS(pDM_Odm);
261 } else {
Jes Sorensen1a573d22014-07-21 11:24:59 +0200262 odm_DIG23a(adapter);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500263 }
264
265 odm_CCKPacketDetectionThresh23a(pDM_Odm);
266
Jes Sorensen638847c2014-07-21 11:25:00 +0200267 if (pwrctrlpriv->bpower_saving)
Larry Fingerf7c92d22014-03-28 21:37:39 -0500268 return;
269
Jes Sorensenb58298e2015-03-02 15:25:01 -0500270 odm_RefreshRateAdaptiveMask(pDM_Odm);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500271
Larry Fingerf7c92d22014-03-28 21:37:39 -0500272
Jes Sorensen344af822014-07-17 22:59:55 +0200273 odm_EdcaTurboCheck23a(pDM_Odm);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500274}
275
276/* */
277/* Init /.. Fixed HW value. Only init time. */
278/* */
279void ODM_CmnInfoInit23a(struct dm_odm_t *pDM_Odm,
280 enum odm_cmninfo CmnInfo,
281 u32 Value
282 )
283{
284 /* ODM_RT_TRACE(pDM_Odm,); */
285
286 /* */
287 /* This section is used for init value */
288 /* */
289 switch (CmnInfo) {
290 /* Fixed ODM value. */
Larry Fingerf7c92d22014-03-28 21:37:39 -0500291 case ODM_CMNINFO_MP_TEST_CHIP:
292 pDM_Odm->bIsMPChip = (u8)Value;
293 break;
294 case ODM_CMNINFO_IC_TYPE:
295 pDM_Odm->SupportICType = Value;
296 break;
297 case ODM_CMNINFO_CUT_VER:
298 pDM_Odm->CutVersion = (u8)Value;
299 break;
300 case ODM_CMNINFO_FAB_VER:
301 pDM_Odm->FabVersion = (u8)Value;
302 break;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500303 case ODM_CMNINFO_BOARD_TYPE:
304 pDM_Odm->BoardType = (u8)Value;
305 break;
306 case ODM_CMNINFO_EXT_LNA:
307 pDM_Odm->ExtLNA = (u8)Value;
308 break;
309 case ODM_CMNINFO_EXT_PA:
310 pDM_Odm->ExtPA = (u8)Value;
311 break;
312 case ODM_CMNINFO_EXT_TRSW:
313 pDM_Odm->ExtTRSW = (u8)Value;
314 break;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500315 case ODM_CMNINFO_BINHCT_TEST:
316 pDM_Odm->bInHctTest = (bool)Value;
317 break;
318 case ODM_CMNINFO_BWIFI_TEST:
319 pDM_Odm->bWIFITest = (bool)Value;
320 break;
321 case ODM_CMNINFO_SMART_CONCURRENT:
322 pDM_Odm->bDualMacSmartConcurrent = (bool)Value;
323 break;
324 /* To remove the compiler warning, must add an empty default statement to handle the other values. */
325 default:
326 /* do nothing */
327 break;
328 }
Larry Fingerf7c92d22014-03-28 21:37:39 -0500329}
330
Larry Fingerf7c92d22014-03-28 21:37:39 -0500331void ODM_CmnInfoPtrArrayHook23a(struct dm_odm_t *pDM_Odm, enum odm_cmninfo CmnInfo,
332 u16 Index, void *pValue)
333{
334 /* Hook call by reference pointer. */
335 switch (CmnInfo) {
336 /* Dynamic call by reference pointer. */
337 case ODM_CMNINFO_STA_STATUS:
338 pDM_Odm->pODM_StaInfo[Index] = (struct sta_info *)pValue;
339 break;
340 /* To remove the compiler warning, must add an empty default statement to handle the other values. */
341 default:
342 /* do nothing */
343 break;
344 }
345}
346
347/* Update Band/CHannel/.. The values are dynamic but non-per-packet. */
348void ODM_CmnInfoUpdate23a(struct dm_odm_t *pDM_Odm, u32 CmnInfo, u64 Value)
349{
350 /* This init variable may be changed in run time. */
351 switch (CmnInfo) {
Larry Fingerf7c92d22014-03-28 21:37:39 -0500352 case ODM_CMNINFO_WIFI_DIRECT:
353 pDM_Odm->bWIFI_Direct = (bool)Value;
354 break;
355 case ODM_CMNINFO_WIFI_DISPLAY:
356 pDM_Odm->bWIFI_Display = (bool)Value;
357 break;
358 case ODM_CMNINFO_LINK:
359 pDM_Odm->bLinked = (bool)Value;
360 break;
361 case ODM_CMNINFO_RSSI_MIN:
362 pDM_Odm->RSSI_Min = (u8)Value;
363 break;
364 case ODM_CMNINFO_DBG_COMP:
365 pDM_Odm->DebugComponents = Value;
366 break;
367 case ODM_CMNINFO_DBG_LEVEL:
368 pDM_Odm->DebugLevel = (u32)Value;
369 break;
370 case ODM_CMNINFO_RA_THRESHOLD_HIGH:
371 pDM_Odm->RateAdaptive.HighRSSIThresh = (u8)Value;
372 break;
373 case ODM_CMNINFO_RA_THRESHOLD_LOW:
374 pDM_Odm->RateAdaptive.LowRSSIThresh = (u8)Value;
375 break;
376 }
377
378}
379
Jes Sorensen3f9cb6a2015-03-05 14:24:48 -0500380void odm_CommonInfoSelfInit23a(struct dm_odm_t *pDM_Odm)
Larry Fingerf7c92d22014-03-28 21:37:39 -0500381{
Jes Sorensen3f9cb6a2015-03-05 14:24:48 -0500382 u32 val32;
383
384 val32 = rtl8723au_read32(pDM_Odm->Adapter, rFPGA0_XA_HSSIParameter2);
385 if (val32 & BIT(9))
386 pDM_Odm->bCckHighPower = true;
387 else
388 pDM_Odm->bCckHighPower = false;
Edward Lipinsky95829dc2015-04-18 09:35:19 -0700389
Jes Sorensen36cf7c72014-07-21 11:25:04 +0200390 pDM_Odm->RFPathRxEnable =
Jes Sorensen3f9cb6a2015-03-05 14:24:48 -0500391 rtl8723au_read32(pDM_Odm->Adapter, rOFDM0_TRxPathEnable) & 0x0F;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500392
393 ODM_InitDebugSetting23a(pDM_Odm);
394}
395
Jes Sorensen91a29162014-07-21 11:24:56 +0200396static void odm_CommonInfoSelfUpdate(struct hal_data_8723a *pHalData)
Larry Fingerf7c92d22014-03-28 21:37:39 -0500397{
Jes Sorensen91a29162014-07-21 11:24:56 +0200398 struct dm_odm_t *pDM_Odm = &pHalData->odmpriv;
399 struct sta_info *pEntry;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500400 u8 EntryCnt = 0;
401 u8 i;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500402
Larry Fingerf7c92d22014-03-28 21:37:39 -0500403 for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
404 pEntry = pDM_Odm->pODM_StaInfo[i];
Jes Sorensen2e8d47e2014-07-17 22:59:57 +0200405 if (pEntry)
Larry Fingerf7c92d22014-03-28 21:37:39 -0500406 EntryCnt++;
407 }
408 if (EntryCnt == 1)
409 pDM_Odm->bOneEntryOnly = true;
410 else
411 pDM_Odm->bOneEntryOnly = false;
412}
413
414void odm_CmnInfoInit_Debug23a(struct dm_odm_t *pDM_Odm)
415{
416 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("odm_CmnInfoInit_Debug23a ==>\n"));
417 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("SupportAbility = 0x%x\n", pDM_Odm->SupportAbility));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500418 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("SupportICType = 0x%x\n", pDM_Odm->SupportICType));
419 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("CutVersion =%d\n", pDM_Odm->CutVersion));
420 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("FabVersion =%d\n", pDM_Odm->FabVersion));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500421 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("BoardType =%d\n", pDM_Odm->BoardType));
422 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("ExtLNA =%d\n", pDM_Odm->ExtLNA));
423 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("ExtPA =%d\n", pDM_Odm->ExtPA));
424 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("ExtTRSW =%d\n", pDM_Odm->ExtTRSW));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500425 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("bInHctTest =%d\n", pDM_Odm->bInHctTest));
426 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("bWIFITest =%d\n", pDM_Odm->bWIFITest));
427 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("bDualMacSmartConcurrent =%d\n", pDM_Odm->bDualMacSmartConcurrent));
428
429}
430
Larry Fingerf7c92d22014-03-28 21:37:39 -0500431void odm_CmnInfoUpdate_Debug23a(struct dm_odm_t *pDM_Odm)
432{
433 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("odm_CmnInfoUpdate_Debug23a ==>\n"));
434 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("bWIFI_Direct =%d\n", pDM_Odm->bWIFI_Direct));
435 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("bWIFI_Display =%d\n", pDM_Odm->bWIFI_Display));
436 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("bLinked =%d\n", pDM_Odm->bLinked));
437 ODM_RT_TRACE(pDM_Odm, ODM_COMP_COMMON, ODM_DBG_LOUD, ("RSSI_Min =%d\n", pDM_Odm->RSSI_Min));
438}
439
Jes Sorensenc335da52015-03-02 15:25:02 -0500440void ODM_Write_DIG23a(struct dm_odm_t *pDM_Odm, u8 CurrentIGI)
Larry Fingerf7c92d22014-03-28 21:37:39 -0500441{
Jes Sorensen2635f192015-03-05 14:24:49 -0500442 struct rtw_adapter *adapter = pDM_Odm->Adapter;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500443 struct dig_t *pDM_DigTable = &pDM_Odm->DM_DigTable;
Jes Sorensen2635f192015-03-05 14:24:49 -0500444 u32 val32;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500445
446 if (pDM_DigTable->CurIGValue != CurrentIGI) {
Jes Sorensen2635f192015-03-05 14:24:49 -0500447 val32 = rtl8723au_read32(adapter, ODM_REG_IGI_A_11N);
448 val32 &= ~ODM_BIT_IGI_11N;
449 val32 |= CurrentIGI;
450 rtl8723au_write32(adapter, ODM_REG_IGI_A_11N, val32);
Jes Sorensenc335da52015-03-02 15:25:02 -0500451 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD,
452 ("CurrentIGI(0x%02x). \n", CurrentIGI));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500453 pDM_DigTable->CurIGValue = CurrentIGI;
454 }
455 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD,
456 ("ODM_Write_DIG23a():CurrentIGI = 0x%x \n", CurrentIGI));
457}
458
459/* Need LPS mode for CE platform --2012--08--24--- */
460/* 8723AS/8189ES */
461void odm_DIG23abyRSSI_LPS(struct dm_odm_t *pDM_Odm)
462{
463 struct rtw_adapter *pAdapter = pDM_Odm->Adapter;
464 struct false_alarm_stats *pFalseAlmCnt = &pDM_Odm->FalseAlmCnt;
465 u8 RSSI_Lower = DM_DIG_MIN_NIC; /* 0x1E or 0x1C */
466 u8 bFwCurrentInPSMode = false;
467 u8 CurrentIGI = pDM_Odm->RSSI_Min;
468
Jes Sorensen344af822014-07-17 22:59:55 +0200469 if (!(pDM_Odm->SupportICType & ODM_RTL8723A))
Larry Fingerf7c92d22014-03-28 21:37:39 -0500470 return;
471
472 CurrentIGI = CurrentIGI+RSSI_OFFSET_DIG;
473 bFwCurrentInPSMode = pAdapter->pwrctrlpriv.bFwCurrentInPSMode;
474
Larry Fingerf7c92d22014-03-28 21:37:39 -0500475 /* Using FW PS mode to make IGI */
476 if (bFwCurrentInPSMode) {
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500477 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD,
478 ("---Neil---odm_DIG23a is in LPS mode\n"));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500479 /* Adjust by FA in LPS MODE */
480 if (pFalseAlmCnt->Cnt_all > DM_DIG_FA_TH2_LPS)
481 CurrentIGI = CurrentIGI+2;
482 else if (pFalseAlmCnt->Cnt_all > DM_DIG_FA_TH1_LPS)
483 CurrentIGI = CurrentIGI+1;
484 else if (pFalseAlmCnt->Cnt_all < DM_DIG_FA_TH0_LPS)
485 CurrentIGI = CurrentIGI-1;
486 } else {
487 CurrentIGI = RSSI_Lower;
488 }
489
490 /* Lower bound checking */
491
492 /* RSSI Lower bound check */
493 if ((pDM_Odm->RSSI_Min-10) > DM_DIG_MIN_NIC)
494 RSSI_Lower = (pDM_Odm->RSSI_Min-10);
495 else
496 RSSI_Lower = DM_DIG_MIN_NIC;
497
498 /* Upper and Lower Bound checking */
499 if (CurrentIGI > DM_DIG_MAX_NIC)
500 CurrentIGI = DM_DIG_MAX_NIC;
501 else if (CurrentIGI < RSSI_Lower)
502 CurrentIGI = RSSI_Lower;
503
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500504 ODM_Write_DIG23a(pDM_Odm, CurrentIGI);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500505}
506
507void odm_DIG23aInit(struct dm_odm_t *pDM_Odm)
508{
509 struct dig_t *pDM_DigTable = &pDM_Odm->DM_DigTable;
Jes Sorensen3f9cb6a2015-03-05 14:24:48 -0500510 u32 val32;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500511
Jes Sorensen3f9cb6a2015-03-05 14:24:48 -0500512 val32 = rtl8723au_read32(pDM_Odm->Adapter, ODM_REG_IGI_A_11N);
513 pDM_DigTable->CurIGValue = val32 & ODM_BIT_IGI_11N;
514
Larry Fingerf7c92d22014-03-28 21:37:39 -0500515 pDM_DigTable->RssiLowThresh = DM_DIG_THRESH_LOW;
516 pDM_DigTable->RssiHighThresh = DM_DIG_THRESH_HIGH;
517 pDM_DigTable->FALowThresh = DM_FALSEALARM_THRESH_LOW;
518 pDM_DigTable->FAHighThresh = DM_FALSEALARM_THRESH_HIGH;
519 if (pDM_Odm->BoardType == ODM_BOARD_HIGHPWR) {
520 pDM_DigTable->rx_gain_range_max = DM_DIG_MAX_NIC;
521 pDM_DigTable->rx_gain_range_min = DM_DIG_MIN_NIC;
522 } else {
523 pDM_DigTable->rx_gain_range_max = DM_DIG_MAX_NIC;
524 pDM_DigTable->rx_gain_range_min = DM_DIG_MIN_NIC;
525 }
526 pDM_DigTable->BackoffVal = DM_DIG_BACKOFF_DEFAULT;
527 pDM_DigTable->BackoffVal_range_max = DM_DIG_BACKOFF_MAX;
528 pDM_DigTable->BackoffVal_range_min = DM_DIG_BACKOFF_MIN;
529 pDM_DigTable->PreCCK_CCAThres = 0xFF;
530 pDM_DigTable->CurCCK_CCAThres = 0x83;
531 pDM_DigTable->ForbiddenIGI = DM_DIG_MIN_NIC;
532 pDM_DigTable->LargeFAHit = 0;
533 pDM_DigTable->Recover_cnt = 0;
534 pDM_DigTable->DIG_Dynamic_MIN_0 = DM_DIG_MIN_NIC;
535 pDM_DigTable->DIG_Dynamic_MIN_1 = DM_DIG_MIN_NIC;
536 pDM_DigTable->bMediaConnect_0 = false;
537 pDM_DigTable->bMediaConnect_1 = false;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500538}
539
Jes Sorensen1a573d22014-07-21 11:24:59 +0200540void odm_DIG23a(struct rtw_adapter *adapter)
Larry Fingerf7c92d22014-03-28 21:37:39 -0500541{
Jes Sorensen1a573d22014-07-21 11:24:59 +0200542 struct hal_data_8723a *pHalData = GET_HAL_DATA(adapter);
543 struct dm_odm_t *pDM_Odm = &pHalData->odmpriv;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500544 struct dig_t *pDM_DigTable = &pDM_Odm->DM_DigTable;
545 struct false_alarm_stats *pFalseAlmCnt = &pDM_Odm->FalseAlmCnt;
546 u8 DIG_Dynamic_MIN;
547 u8 DIG_MaxOfMin;
548 bool FirstConnect, FirstDisConnect;
549 u8 dm_dig_max, dm_dig_min;
550 u8 CurrentIGI = pDM_DigTable->CurIGValue;
551
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500552 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD,
553 ("odm_DIG23a() ==>\n"));
Jes Sorensen1a573d22014-07-21 11:24:59 +0200554 if (adapter->mlmepriv.bScanInProcess) {
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500555 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD,
556 ("odm_DIG23a() Return: In Scan Progress \n"));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500557 return;
558 }
559
Larry Fingerf7c92d22014-03-28 21:37:39 -0500560 DIG_Dynamic_MIN = pDM_DigTable->DIG_Dynamic_MIN_0;
561 FirstConnect = (pDM_Odm->bLinked) && (!pDM_DigTable->bMediaConnect_0);
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500562 FirstDisConnect = (!pDM_Odm->bLinked) &&
563 (pDM_DigTable->bMediaConnect_0);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500564
565 /* 1 Boundary Decision */
Jes Sorensen344af822014-07-17 22:59:55 +0200566 if ((pDM_Odm->SupportICType & ODM_RTL8723A) &&
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500567 (pDM_Odm->BoardType == ODM_BOARD_HIGHPWR || pDM_Odm->ExtLNA)) {
Larry Fingerf7c92d22014-03-28 21:37:39 -0500568 dm_dig_max = DM_DIG_MAX_NIC_HP;
569 dm_dig_min = DM_DIG_MIN_NIC_HP;
570 DIG_MaxOfMin = DM_DIG_MAX_AP_HP;
571 } else {
572 dm_dig_max = DM_DIG_MAX_NIC;
573 dm_dig_min = DM_DIG_MIN_NIC;
574 DIG_MaxOfMin = DM_DIG_MAX_AP;
575 }
576
577 if (pDM_Odm->bLinked) {
578 /* 2 8723A Series, offset need to be 10 */
Jes Sorensen344af822014-07-17 22:59:55 +0200579 if (pDM_Odm->SupportICType == ODM_RTL8723A) {
Larry Fingerf7c92d22014-03-28 21:37:39 -0500580 /* 2 Upper Bound */
581 if ((pDM_Odm->RSSI_Min + 10) > DM_DIG_MAX_NIC)
582 pDM_DigTable->rx_gain_range_max = DM_DIG_MAX_NIC;
583 else if ((pDM_Odm->RSSI_Min + 10) < DM_DIG_MIN_NIC)
584 pDM_DigTable->rx_gain_range_max = DM_DIG_MIN_NIC;
585 else
586 pDM_DigTable->rx_gain_range_max = pDM_Odm->RSSI_Min + 10;
587
588 /* 2 If BT is Concurrent, need to set Lower Bound */
589 DIG_Dynamic_MIN = DM_DIG_MIN_NIC;
590 } else {
591 /* 2 Modify DIG upper bound */
592 if ((pDM_Odm->RSSI_Min + 20) > dm_dig_max)
593 pDM_DigTable->rx_gain_range_max = dm_dig_max;
594 else if ((pDM_Odm->RSSI_Min + 20) < dm_dig_min)
595 pDM_DigTable->rx_gain_range_max = dm_dig_min;
596 else
597 pDM_DigTable->rx_gain_range_max = pDM_Odm->RSSI_Min + 20;
598
599 /* 2 Modify DIG lower bound */
600 if (pDM_Odm->bOneEntryOnly) {
601 if (pDM_Odm->RSSI_Min < dm_dig_min)
602 DIG_Dynamic_MIN = dm_dig_min;
603 else if (pDM_Odm->RSSI_Min > DIG_MaxOfMin)
604 DIG_Dynamic_MIN = DIG_MaxOfMin;
605 else
606 DIG_Dynamic_MIN = pDM_Odm->RSSI_Min;
607 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD,
608 ("odm_DIG23a() : bOneEntryOnly = true, DIG_Dynamic_MIN = 0x%x\n",
609 DIG_Dynamic_MIN));
610 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD,
611 ("odm_DIG23a() : pDM_Odm->RSSI_Min =%d\n",
612 pDM_Odm->RSSI_Min));
613 } else {
614 DIG_Dynamic_MIN = dm_dig_min;
615 }
616 }
617 } else {
618 pDM_DigTable->rx_gain_range_max = dm_dig_max;
619 DIG_Dynamic_MIN = dm_dig_min;
620 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG23a() : No Link\n"));
621 }
622
623 /* 1 Modify DIG lower bound, deal with abnormally large false alarm */
624 if (pFalseAlmCnt->Cnt_all > 10000) {
625 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD,
626 ("dm_DIG(): Abnornally false alarm case. \n"));
627
628 if (pDM_DigTable->LargeFAHit != 3)
629 pDM_DigTable->LargeFAHit++;
630 if (pDM_DigTable->ForbiddenIGI < CurrentIGI) {
631 pDM_DigTable->ForbiddenIGI = CurrentIGI;
632 pDM_DigTable->LargeFAHit = 1;
633 }
634
635 if (pDM_DigTable->LargeFAHit >= 3) {
636 if ((pDM_DigTable->ForbiddenIGI+1) > pDM_DigTable->rx_gain_range_max)
637 pDM_DigTable->rx_gain_range_min = pDM_DigTable->rx_gain_range_max;
638 else
639 pDM_DigTable->rx_gain_range_min = (pDM_DigTable->ForbiddenIGI + 1);
640 pDM_DigTable->Recover_cnt = 3600; /* 3600 = 2hr */
641 }
642 } else {
643 /* Recovery mechanism for IGI lower bound */
644 if (pDM_DigTable->Recover_cnt != 0) {
645 pDM_DigTable->Recover_cnt--;
646 } else {
647 if (pDM_DigTable->LargeFAHit < 3) {
648 if ((pDM_DigTable->ForbiddenIGI - 1) < DIG_Dynamic_MIN) {
649 pDM_DigTable->ForbiddenIGI = DIG_Dynamic_MIN; /* DM_DIG_MIN; */
650 pDM_DigTable->rx_gain_range_min = DIG_Dynamic_MIN; /* DM_DIG_MIN; */
651 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD,
652 ("odm_DIG23a(): Normal Case: At Lower Bound\n"));
653 } else {
654 pDM_DigTable->ForbiddenIGI--;
655 pDM_DigTable->rx_gain_range_min = (pDM_DigTable->ForbiddenIGI + 1);
656 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD,
657 ("odm_DIG23a(): Normal Case: Approach Lower Bound\n"));
658 }
659 } else {
660 pDM_DigTable->LargeFAHit = 0;
661 }
662 }
663 }
664 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG23a(): pDM_DigTable->LargeFAHit =%d\n", pDM_DigTable->LargeFAHit));
665
666 /* 1 Adjust initial gain by false alarm */
667 if (pDM_Odm->bLinked) {
668 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG23a(): DIG AfterLink\n"));
669 if (FirstConnect) {
670 CurrentIGI = pDM_Odm->RSSI_Min;
671 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("DIG: First Connect\n"));
672 } else {
673 if (pFalseAlmCnt->Cnt_all > DM_DIG_FA_TH2)
674 CurrentIGI = CurrentIGI + 4;/* pDM_DigTable->CurIGValue = pDM_DigTable->PreIGValue+2; */
675 else if (pFalseAlmCnt->Cnt_all > DM_DIG_FA_TH1)
676 CurrentIGI = CurrentIGI + 2;/* pDM_DigTable->CurIGValue = pDM_DigTable->PreIGValue+1; */
677 else if (pFalseAlmCnt->Cnt_all < DM_DIG_FA_TH0)
678 CurrentIGI = CurrentIGI - 2;/* pDM_DigTable->CurIGValue = pDM_DigTable->PreIGValue-1; */
679 }
680 } else {
681 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG23a(): DIG BeforeLink\n"));
682 if (FirstDisConnect) {
683 CurrentIGI = pDM_DigTable->rx_gain_range_min;
684 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG23a(): First DisConnect \n"));
685 } else {
686 /* 2012.03.30 LukeLee: enable DIG before link but with very high thresholds */
687 if (pFalseAlmCnt->Cnt_all > 10000)
688 CurrentIGI = CurrentIGI + 2;/* pDM_DigTable->CurIGValue = pDM_DigTable->PreIGValue+2; */
689 else if (pFalseAlmCnt->Cnt_all > 8000)
690 CurrentIGI = CurrentIGI + 1;/* pDM_DigTable->CurIGValue = pDM_DigTable->PreIGValue+1; */
691 else if (pFalseAlmCnt->Cnt_all < 500)
692 CurrentIGI = CurrentIGI - 1;/* pDM_DigTable->CurIGValue = pDM_DigTable->PreIGValue-1; */
693 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG23a(): England DIG \n"));
694 }
695 }
696 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG23a(): DIG End Adjust IGI\n"));
697 /* 1 Check initial gain by upper/lower bound */
698 if (CurrentIGI > pDM_DigTable->rx_gain_range_max)
699 CurrentIGI = pDM_DigTable->rx_gain_range_max;
700 if (CurrentIGI < pDM_DigTable->rx_gain_range_min)
701 CurrentIGI = pDM_DigTable->rx_gain_range_min;
702
703 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG23a(): rx_gain_range_max = 0x%x, rx_gain_range_min = 0x%x\n",
704 pDM_DigTable->rx_gain_range_max, pDM_DigTable->rx_gain_range_min));
705 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG23a(): TotalFA =%d\n", pFalseAlmCnt->Cnt_all));
706 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG23a(): CurIGValue = 0x%x\n", CurrentIGI));
707
708 /* 2 High power RSSI threshold */
709
710 ODM_Write_DIG23a(pDM_Odm, CurrentIGI);/* ODM_Write_DIG23a(pDM_Odm, pDM_DigTable->CurIGValue); */
711 pDM_DigTable->bMediaConnect_0 = pDM_Odm->bLinked;
712 pDM_DigTable->DIG_Dynamic_MIN_0 = DIG_Dynamic_MIN;
713}
714
715/* 3 ============================================================ */
716/* 3 FASLE ALARM CHECK */
717/* 3 ============================================================ */
718
719void odm_FalseAlarmCounterStatistics23a(struct dm_odm_t *pDM_Odm)
720{
Jes Sorensena39bd1f2015-03-05 14:24:42 -0500721 struct rtw_adapter *adapter = pDM_Odm->Adapter;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500722 struct false_alarm_stats *FalseAlmCnt = &pDM_Odm->FalseAlmCnt;
Jes Sorensen2635f192015-03-05 14:24:49 -0500723 u32 ret_value, val32;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500724
Jes Sorensen344af822014-07-17 22:59:55 +0200725 /* hold ofdm counter */
Jes Sorensena39bd1f2015-03-05 14:24:42 -0500726 /* hold page C counter */
Jes Sorensen2635f192015-03-05 14:24:49 -0500727 val32 = rtl8723au_read32(adapter, ODM_REG_OFDM_FA_HOLDC_11N);
728 val32 |= BIT(31);
729 rtl8723au_write32(adapter, ODM_REG_OFDM_FA_HOLDC_11N, val32);
Jes Sorensen344af822014-07-17 22:59:55 +0200730 /* hold page D counter */
Jes Sorensen2635f192015-03-05 14:24:49 -0500731 val32 = rtl8723au_read32(adapter, ODM_REG_OFDM_FA_RSTD_11N);
732 val32 |= BIT(31);
733 rtl8723au_write32(adapter, ODM_REG_OFDM_FA_RSTD_11N, val32);
Jes Sorensena39bd1f2015-03-05 14:24:42 -0500734 ret_value = rtl8723au_read32(adapter, ODM_REG_OFDM_FA_TYPE1_11N);
Jes Sorensen344af822014-07-17 22:59:55 +0200735 FalseAlmCnt->Cnt_Fast_Fsync = (ret_value&0xffff);
Aya Mahfouze1bc88f2015-03-04 07:34:07 +0200736 FalseAlmCnt->Cnt_SB_Search_fail = (ret_value & 0xffff0000)>>16;
Jes Sorensena39bd1f2015-03-05 14:24:42 -0500737 ret_value = rtl8723au_read32(adapter, ODM_REG_OFDM_FA_TYPE2_11N);
Jes Sorensen344af822014-07-17 22:59:55 +0200738 FalseAlmCnt->Cnt_OFDM_CCA = (ret_value&0xffff);
Aya Mahfouze1bc88f2015-03-04 07:34:07 +0200739 FalseAlmCnt->Cnt_Parity_Fail = (ret_value & 0xffff0000)>>16;
Jes Sorensena39bd1f2015-03-05 14:24:42 -0500740 ret_value = rtl8723au_read32(adapter, ODM_REG_OFDM_FA_TYPE3_11N);
Jes Sorensen344af822014-07-17 22:59:55 +0200741 FalseAlmCnt->Cnt_Rate_Illegal = (ret_value&0xffff);
Aya Mahfouze1bc88f2015-03-04 07:34:07 +0200742 FalseAlmCnt->Cnt_Crc8_fail = (ret_value & 0xffff0000)>>16;
Jes Sorensena39bd1f2015-03-05 14:24:42 -0500743 ret_value = rtl8723au_read32(adapter, ODM_REG_OFDM_FA_TYPE4_11N);
Jes Sorensen344af822014-07-17 22:59:55 +0200744 FalseAlmCnt->Cnt_Mcs_fail = (ret_value&0xffff);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500745
Jes Sorensen344af822014-07-17 22:59:55 +0200746 FalseAlmCnt->Cnt_Ofdm_fail = FalseAlmCnt->Cnt_Parity_Fail +
747 FalseAlmCnt->Cnt_Rate_Illegal +
748 FalseAlmCnt->Cnt_Crc8_fail +
749 FalseAlmCnt->Cnt_Mcs_fail +
750 FalseAlmCnt->Cnt_Fast_Fsync +
751 FalseAlmCnt->Cnt_SB_Search_fail;
752 /* hold cck counter */
Jes Sorensen2635f192015-03-05 14:24:49 -0500753 val32 = rtl8723au_read32(adapter, ODM_REG_CCK_FA_RST_11N);
754 val32 |= (BIT(12) | BIT(14));
755 rtl8723au_write32(adapter, ODM_REG_CCK_FA_RST_11N, val32);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500756
Jes Sorensen3f9cb6a2015-03-05 14:24:48 -0500757 ret_value = rtl8723au_read32(adapter, ODM_REG_CCK_FA_LSB_11N) & 0xff;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500758 FalseAlmCnt->Cnt_Cck_fail = ret_value;
Jes Sorensen3f9cb6a2015-03-05 14:24:48 -0500759 ret_value = rtl8723au_read32(adapter, ODM_REG_CCK_FA_MSB_11N) >> 16;
760 FalseAlmCnt->Cnt_Cck_fail += (ret_value & 0xff00);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500761
Jes Sorensena39bd1f2015-03-05 14:24:42 -0500762 ret_value = rtl8723au_read32(adapter, ODM_REG_CCK_CCA_CNT_11N);
Jes Sorensen344af822014-07-17 22:59:55 +0200763 FalseAlmCnt->Cnt_CCK_CCA =
764 ((ret_value&0xFF)<<8) | ((ret_value&0xFF00)>>8);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500765
766 FalseAlmCnt->Cnt_all = (FalseAlmCnt->Cnt_Fast_Fsync +
767 FalseAlmCnt->Cnt_SB_Search_fail +
768 FalseAlmCnt->Cnt_Parity_Fail +
769 FalseAlmCnt->Cnt_Rate_Illegal +
770 FalseAlmCnt->Cnt_Crc8_fail +
771 FalseAlmCnt->Cnt_Mcs_fail +
772 FalseAlmCnt->Cnt_Cck_fail);
773
Jes Sorensen344af822014-07-17 22:59:55 +0200774 FalseAlmCnt->Cnt_CCA_all =
775 FalseAlmCnt->Cnt_OFDM_CCA + FalseAlmCnt->Cnt_CCK_CCA;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500776
777 if (pDM_Odm->SupportICType >= ODM_RTL8723A) {
778 /* reset false alarm counter registers */
Jes Sorensen2635f192015-03-05 14:24:49 -0500779 val32 = rtl8723au_read32(adapter, ODM_REG_OFDM_FA_RSTC_11N);
780 val32 |= BIT(31);
781 rtl8723au_write32(adapter, ODM_REG_OFDM_FA_RSTC_11N, val32);
782 val32 = rtl8723au_read32(adapter, ODM_REG_OFDM_FA_RSTC_11N);
783 val32 &= ~BIT(31);
784 rtl8723au_write32(adapter, ODM_REG_OFDM_FA_RSTC_11N, val32);
Jes Sorensen18f576f2015-03-22 19:09:42 -0400785
Jes Sorensen2635f192015-03-05 14:24:49 -0500786 val32 = rtl8723au_read32(adapter, ODM_REG_OFDM_FA_RSTD_11N);
787 val32 |= BIT(27);
788 rtl8723au_write32(adapter, ODM_REG_OFDM_FA_RSTD_11N, val32);
789 val32 = rtl8723au_read32(adapter, ODM_REG_OFDM_FA_RSTD_11N);
790 val32 &= ~BIT(27);
791 rtl8723au_write32(adapter, ODM_REG_OFDM_FA_RSTD_11N, val32);
792
Larry Fingerf7c92d22014-03-28 21:37:39 -0500793 /* update ofdm counter */
Jes Sorensen344af822014-07-17 22:59:55 +0200794 /* update page C counter */
Jes Sorensen2635f192015-03-05 14:24:49 -0500795 val32 = rtl8723au_read32(adapter, ODM_REG_OFDM_FA_HOLDC_11N);
796 val32 &= ~BIT(31);
797 rtl8723au_write32(adapter, ODM_REG_OFDM_FA_HOLDC_11N, val32);
798
Jes Sorensen344af822014-07-17 22:59:55 +0200799 /* update page D counter */
Jes Sorensen2635f192015-03-05 14:24:49 -0500800 val32 = rtl8723au_read32(adapter, ODM_REG_OFDM_FA_RSTD_11N);
801 val32 &= ~BIT(31);
802 rtl8723au_write32(adapter, ODM_REG_OFDM_FA_RSTD_11N, val32);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500803
804 /* reset CCK CCA counter */
Jes Sorensen2635f192015-03-05 14:24:49 -0500805 val32 = rtl8723au_read32(adapter, ODM_REG_CCK_FA_RST_11N);
806 val32 &= ~(BIT(12) | BIT(13) | BIT(14) | BIT(15));
807 rtl8723au_write32(adapter, ODM_REG_CCK_FA_RST_11N, val32);
808
809 val32 = rtl8723au_read32(adapter, ODM_REG_CCK_FA_RST_11N);
810 val32 |= (BIT(13) | BIT(15));
811 rtl8723au_write32(adapter, ODM_REG_CCK_FA_RST_11N, val32);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500812 }
813
Jes Sorensen344af822014-07-17 22:59:55 +0200814 ODM_RT_TRACE(pDM_Odm, ODM_COMP_FA_CNT, ODM_DBG_LOUD,
815 ("Enter odm_FalseAlarmCounterStatistics23a\n"));
816 ODM_RT_TRACE(pDM_Odm, ODM_COMP_FA_CNT, ODM_DBG_LOUD,
817 ("Cnt_Fast_Fsync =%d, Cnt_SB_Search_fail =%d\n",
818 FalseAlmCnt->Cnt_Fast_Fsync,
819 FalseAlmCnt->Cnt_SB_Search_fail));
820 ODM_RT_TRACE(pDM_Odm, ODM_COMP_FA_CNT, ODM_DBG_LOUD,
821 ("Cnt_Parity_Fail =%d, Cnt_Rate_Illegal =%d\n",
822 FalseAlmCnt->Cnt_Parity_Fail,
823 FalseAlmCnt->Cnt_Rate_Illegal));
824 ODM_RT_TRACE(pDM_Odm, ODM_COMP_FA_CNT, ODM_DBG_LOUD,
825 ("Cnt_Crc8_fail =%d, Cnt_Mcs_fail =%d\n",
826 FalseAlmCnt->Cnt_Crc8_fail, FalseAlmCnt->Cnt_Mcs_fail));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500827
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500828 ODM_RT_TRACE(pDM_Odm, ODM_COMP_FA_CNT, ODM_DBG_LOUD,
829 ("Cnt_Cck_fail =%d\n", FalseAlmCnt->Cnt_Cck_fail));
830 ODM_RT_TRACE(pDM_Odm, ODM_COMP_FA_CNT, ODM_DBG_LOUD,
831 ("Cnt_Ofdm_fail =%d\n", FalseAlmCnt->Cnt_Ofdm_fail));
832 ODM_RT_TRACE(pDM_Odm, ODM_COMP_FA_CNT, ODM_DBG_LOUD,
833 ("Total False Alarm =%d\n", FalseAlmCnt->Cnt_all));
Larry Fingerf7c92d22014-03-28 21:37:39 -0500834}
835
836/* 3 ============================================================ */
837/* 3 CCK Packet Detect Threshold */
838/* 3 ============================================================ */
839
840void odm_CCKPacketDetectionThresh23a(struct dm_odm_t *pDM_Odm)
841{
842 struct false_alarm_stats *FalseAlmCnt = &pDM_Odm->FalseAlmCnt;
843 u8 CurCCK_CCAThres;
844
Larry Fingerf7c92d22014-03-28 21:37:39 -0500845 if (pDM_Odm->ExtLNA)
846 return;
847
848 if (pDM_Odm->bLinked) {
849 if (pDM_Odm->RSSI_Min > 25) {
850 CurCCK_CCAThres = 0xcd;
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500851 } else if (pDM_Odm->RSSI_Min <= 25 && pDM_Odm->RSSI_Min > 10) {
Larry Fingerf7c92d22014-03-28 21:37:39 -0500852 CurCCK_CCAThres = 0x83;
853 } else {
854 if (FalseAlmCnt->Cnt_Cck_fail > 1000)
855 CurCCK_CCAThres = 0x83;
856 else
857 CurCCK_CCAThres = 0x40;
858 }
859 } else {
860 if (FalseAlmCnt->Cnt_Cck_fail > 1000)
861 CurCCK_CCAThres = 0x83;
862 else
863 CurCCK_CCAThres = 0x40;
864 }
865
866 ODM_Write_CCK_CCA_Thres23a(pDM_Odm, CurCCK_CCAThres);
867}
868
869void ODM_Write_CCK_CCA_Thres23a(struct dm_odm_t *pDM_Odm, u8 CurCCK_CCAThres)
870{
871 struct dig_t *pDM_DigTable = &pDM_Odm->DM_DigTable;
872
873 if (pDM_DigTable->CurCCK_CCAThres != CurCCK_CCAThres)
Jes Sorensen4f092cc2015-03-05 14:24:45 -0500874 rtl8723au_write8(pDM_Odm->Adapter, ODM_REG(CCK_CCA, pDM_Odm),
875 CurCCK_CCAThres);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500876 pDM_DigTable->PreCCK_CCAThres = pDM_DigTable->CurCCK_CCAThres;
877 pDM_DigTable->CurCCK_CCAThres = CurCCK_CCAThres;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500878}
879
880/* 3 ============================================================ */
881/* 3 BB Power Save */
882/* 3 ============================================================ */
883void odm23a_DynBBPSInit(struct dm_odm_t *pDM_Odm)
884{
885 struct dynamic_pwr_sav *pDM_PSTable = &pDM_Odm->DM_PSTable;
886
887 pDM_PSTable->PreCCAState = CCA_MAX;
888 pDM_PSTable->CurCCAState = CCA_MAX;
889 pDM_PSTable->PreRFState = RF_MAX;
890 pDM_PSTable->CurRFState = RF_MAX;
891 pDM_PSTable->Rssi_val_min = 0;
892 pDM_PSTable->initialize = 0;
893}
894
Larry Fingerf7c92d22014-03-28 21:37:39 -0500895
Larry Fingerf7c92d22014-03-28 21:37:39 -0500896void ODM_RF_Saving23a(struct dm_odm_t *pDM_Odm, u8 bForceInNormal)
897{
898 struct dynamic_pwr_sav *pDM_PSTable = &pDM_Odm->DM_PSTable;
Jes Sorensena39bd1f2015-03-05 14:24:42 -0500899 struct rtw_adapter *adapter = pDM_Odm->Adapter;
Jes Sorensen2635f192015-03-05 14:24:49 -0500900 u32 val32;
Anjana Sasindran9d55c8142014-12-04 19:20:30 +0530901 u8 Rssi_Up_bound = 30;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500902 u8 Rssi_Low_bound = 25;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500903 if (pDM_PSTable->initialize == 0) {
904
Jes Sorensena39bd1f2015-03-05 14:24:42 -0500905 pDM_PSTable->Reg874 =
Jes Sorensen6725e522015-03-05 14:24:50 -0500906 rtl8723au_read32(adapter, 0x874) & 0x1CC000;
Jes Sorensenfc8b7c82014-05-16 10:03:50 +0200907 pDM_PSTable->RegC70 =
Jes Sorensen6725e522015-03-05 14:24:50 -0500908 rtl8723au_read32(adapter, 0xc70) & BIT(3);
Jes Sorensena39bd1f2015-03-05 14:24:42 -0500909 pDM_PSTable->Reg85C =
Jes Sorensen6725e522015-03-05 14:24:50 -0500910 rtl8723au_read32(adapter, 0x85c) & 0xFF000000;
911 pDM_PSTable->RegA74 = rtl8723au_read32(adapter, 0xa74) & 0xF000;
Larry Fingerf7c92d22014-03-28 21:37:39 -0500912 pDM_PSTable->initialize = 1;
913 }
914
915 if (!bForceInNormal) {
916 if (pDM_Odm->RSSI_Min != 0xFF) {
917 if (pDM_PSTable->PreRFState == RF_Normal) {
918 if (pDM_Odm->RSSI_Min >= Rssi_Up_bound)
919 pDM_PSTable->CurRFState = RF_Save;
920 else
921 pDM_PSTable->CurRFState = RF_Normal;
922 } else {
923 if (pDM_Odm->RSSI_Min <= Rssi_Low_bound)
924 pDM_PSTable->CurRFState = RF_Normal;
925 else
926 pDM_PSTable->CurRFState = RF_Save;
927 }
928 } else {
929 pDM_PSTable->CurRFState = RF_MAX;
930 }
931 } else {
932 pDM_PSTable->CurRFState = RF_Normal;
933 }
934
935 if (pDM_PSTable->PreRFState != pDM_PSTable->CurRFState) {
936 if (pDM_PSTable->CurRFState == RF_Save) {
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500937 /* <tynli_note> 8723 RSSI report will be wrong.
938 * Set 0x874[5]= 1 when enter BB power saving mode. */
Larry Fingerf7c92d22014-03-28 21:37:39 -0500939 /* Suggested by SD3 Yu-Nan. 2011.01.20. */
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500940 /* Reg874[5]= 1b'1 */
Jes Sorensen2635f192015-03-05 14:24:49 -0500941 if (pDM_Odm->SupportICType == ODM_RTL8723A) {
942 val32 = rtl8723au_read32(adapter, 0x874);
943 val32 |= BIT(5);
944 rtl8723au_write32(adapter, 0x874, val32);
945 }
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500946 /* Reg874[20:18]= 3'b010 */
Jes Sorensen2635f192015-03-05 14:24:49 -0500947 val32 = rtl8723au_read32(adapter, 0x874);
948 val32 &= ~(BIT(18) | BIT(20));
949 val32 |= BIT(19);
950 rtl8723au_write32(adapter, 0x874, val32);
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500951 /* RegC70[3]= 1'b0 */
Jes Sorensen2635f192015-03-05 14:24:49 -0500952 val32 = rtl8723au_read32(adapter, 0xc70);
953 val32 &= ~BIT(3);
954 rtl8723au_write32(adapter, 0xc70, val32);
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500955 /* Reg85C[31:24]= 0x63 */
Jes Sorensen2635f192015-03-05 14:24:49 -0500956 val32 = rtl8723au_read32(adapter, 0x85c);
957 val32 &= 0x00ffffff;
958 val32 |= 0x63000000;
959 rtl8723au_write32(adapter, 0x85c, val32);
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500960 /* Reg874[15:14]= 2'b10 */
Jes Sorensen2635f192015-03-05 14:24:49 -0500961 val32 = rtl8723au_read32(adapter, 0x874);
962 val32 &= ~BIT(14);
963 val32 |= BIT(15);
964 rtl8723au_write32(adapter, 0x874, val32);
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500965 /* RegA75[7:4]= 0x3 */
Jes Sorensen2635f192015-03-05 14:24:49 -0500966 val32 = rtl8723au_read32(adapter, 0xa74);
967 val32 &= ~(BIT(14) | BIT(15));
968 val32 |= (BIT(12) | BIT(13));
969 rtl8723au_write32(adapter, 0xa74, val32);
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500970 /* Reg818[28]= 1'b0 */
Jes Sorensen2635f192015-03-05 14:24:49 -0500971 val32 = rtl8723au_read32(adapter, 0x818);
972 val32 &= ~BIT(28);
973 rtl8723au_write32(adapter, 0x818, val32);
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500974 /* Reg818[28]= 1'b1 */
Jes Sorensen2635f192015-03-05 14:24:49 -0500975 val32 = rtl8723au_read32(adapter, 0x818);
976 val32 |= BIT(28);
977 rtl8723au_write32(adapter, 0x818, val32);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500978 } else {
Jes Sorensen6725e522015-03-05 14:24:50 -0500979 val32 = rtl8723au_read32(adapter, 0x874);
980 val32 |= pDM_PSTable->Reg874;
981 rtl8723au_write32(adapter, 0x874, val32);
Joglekar Tejasedeafb92015-06-20 12:46:16 +0000982
Jes Sorensen6725e522015-03-05 14:24:50 -0500983 val32 = rtl8723au_read32(adapter, 0xc70);
984 val32 |= pDM_PSTable->RegC70;
985 rtl8723au_write32(adapter, 0xc70, val32);
986
987 val32 = rtl8723au_read32(adapter, 0x85c);
988 val32 |= pDM_PSTable->Reg85C;
989 rtl8723au_write32(adapter, 0x85c, val32);
990
991 val32 = rtl8723au_read32(adapter, 0xa74);
992 val32 |= pDM_PSTable->RegA74;
993 rtl8723au_write32(adapter, 0xa74, val32);
994
Jes Sorensen2635f192015-03-05 14:24:49 -0500995 val32 = rtl8723au_read32(adapter, 0x818);
996 val32 &= ~BIT(28);
997 rtl8723au_write32(adapter, 0x818, val32);
Larry Fingerf7c92d22014-03-28 21:37:39 -0500998
Jes Sorensenfe6e0192015-03-02 15:25:03 -0500999 /* Reg874[5]= 1b'0 */
Jes Sorensen2635f192015-03-05 14:24:49 -05001000 if (pDM_Odm->SupportICType == ODM_RTL8723A) {
1001 val32 = rtl8723au_read32(adapter, 0x874);
1002 val32 &= ~BIT(5);
1003 rtl8723au_write32(adapter, 0x874, val32);
1004 }
Larry Fingerf7c92d22014-03-28 21:37:39 -05001005 }
1006 pDM_PSTable->PreRFState = pDM_PSTable->CurRFState;
1007 }
1008}
1009
1010/* 3 ============================================================ */
1011/* 3 RATR MASK */
1012/* 3 ============================================================ */
1013/* 3 ============================================================ */
1014/* 3 Rate Adaptive */
1015/* 3 ============================================================ */
1016
1017void odm_RateAdaptiveMaskInit23a(struct dm_odm_t *pDM_Odm)
1018{
1019 struct odm_rate_adapt *pOdmRA = &pDM_Odm->RateAdaptive;
1020
1021 pOdmRA->Type = DM_Type_ByDriver;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001022
1023 pOdmRA->RATRState = DM_RATR_STA_INIT;
1024 pOdmRA->HighRSSIThresh = 50;
1025 pOdmRA->LowRSSIThresh = 20;
1026}
1027
Jes Sorensen301fc632014-07-21 11:24:57 +02001028u32 ODM_Get_Rate_Bitmap23a(struct hal_data_8723a *pHalData, u32 macid,
1029 u32 ra_mask, u8 rssi_level)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001030{
Jes Sorensen301fc632014-07-21 11:24:57 +02001031 struct dm_odm_t *pDM_Odm = &pHalData->odmpriv;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001032 struct sta_info *pEntry;
1033 u32 rate_bitmap = 0x0fffffff;
1034 u8 WirelessMode;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001035
1036 pEntry = pDM_Odm->pODM_StaInfo[macid];
Jes Sorensen2e8d47e2014-07-17 22:59:57 +02001037 if (!pEntry)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001038 return ra_mask;
1039
1040 WirelessMode = pEntry->wireless_mode;
1041
1042 switch (WirelessMode) {
1043 case ODM_WM_B:
1044 if (ra_mask & 0x0000000c) /* 11M or 5.5M enable */
1045 rate_bitmap = 0x0000000d;
1046 else
1047 rate_bitmap = 0x0000000f;
1048 break;
1049 case (ODM_WM_A|ODM_WM_G):
1050 if (rssi_level == DM_RATR_STA_HIGH)
1051 rate_bitmap = 0x00000f00;
1052 else
1053 rate_bitmap = 0x00000ff0;
1054 break;
1055 case (ODM_WM_B|ODM_WM_G):
1056 if (rssi_level == DM_RATR_STA_HIGH)
1057 rate_bitmap = 0x00000f00;
1058 else if (rssi_level == DM_RATR_STA_MIDDLE)
1059 rate_bitmap = 0x00000ff0;
1060 else
1061 rate_bitmap = 0x00000ff5;
1062 break;
1063 case (ODM_WM_B|ODM_WM_G|ODM_WM_N24G):
1064 case (ODM_WM_A|ODM_WM_B|ODM_WM_G|ODM_WM_N24G):
Jes Sorensen16290462015-02-27 15:45:30 -05001065 if (pHalData->rf_type == RF_1T2R ||
1066 pHalData->rf_type == RF_1T1R) {
Larry Fingerf7c92d22014-03-28 21:37:39 -05001067 if (rssi_level == DM_RATR_STA_HIGH) {
1068 rate_bitmap = 0x000f0000;
1069 } else if (rssi_level == DM_RATR_STA_MIDDLE) {
1070 rate_bitmap = 0x000ff000;
1071 } else {
Jes Sorensen301fc632014-07-21 11:24:57 +02001072 if (pHalData->CurrentChannelBW ==
1073 HT_CHANNEL_WIDTH_40)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001074 rate_bitmap = 0x000ff015;
1075 else
1076 rate_bitmap = 0x000ff005;
1077 }
1078 } else {
1079 if (rssi_level == DM_RATR_STA_HIGH) {
1080 rate_bitmap = 0x0f8f0000;
1081 } else if (rssi_level == DM_RATR_STA_MIDDLE) {
1082 rate_bitmap = 0x0f8ff000;
1083 } else {
Jes Sorensen301fc632014-07-21 11:24:57 +02001084 if (pHalData->CurrentChannelBW ==
1085 HT_CHANNEL_WIDTH_40)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001086 rate_bitmap = 0x0f8ff015;
1087 else
1088 rate_bitmap = 0x0f8ff005;
1089 }
1090 }
1091 break;
1092 default:
1093 /* case WIRELESS_11_24N: */
1094 /* case WIRELESS_11_5N: */
Jes Sorensen16290462015-02-27 15:45:30 -05001095 if (pHalData->rf_type == RF_1T2R)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001096 rate_bitmap = 0x000fffff;
1097 else
1098 rate_bitmap = 0x0fffffff;
1099 break;
1100 }
1101
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001102 ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD,
1103 (" ==> rssi_level:0x%02x, WirelessMode:0x%02x, rate_bitmap:0x%08x \n",
1104 rssi_level, WirelessMode, rate_bitmap));
Larry Fingerf7c92d22014-03-28 21:37:39 -05001105
1106 return rate_bitmap;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001107}
1108
1109/*-----------------------------------------------------------------------------
Jes Sorensenb58298e2015-03-02 15:25:01 -05001110 * Function: odm_RefreshRateAdaptiveMask()
Larry Fingerf7c92d22014-03-28 21:37:39 -05001111 *
1112 * Overview: Update rate table mask according to rssi
1113 *
1114 * Input: NONE
1115 *
1116 * Output: NONE
1117 *
1118 * Return: NONE
1119 *
1120 * Revised History:
1121 *When Who Remark
1122 *05/27/2009 hpfan Create Version 0.
1123 *
1124 *---------------------------------------------------------------------------*/
Jes Sorensenb58298e2015-03-02 15:25:01 -05001125static void odm_RefreshRateAdaptiveMask(struct dm_odm_t *pDM_Odm)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001126{
Jes Sorensenb58298e2015-03-02 15:25:01 -05001127 struct rtw_adapter *pAdapter = pDM_Odm->Adapter;
1128 u32 smoothed;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001129 u8 i;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001130
1131 if (pAdapter->bDriverStopped) {
1132 ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_TRACE,
Jes Sorensen79afea12015-03-02 15:24:39 -05001133 ("<---- %s: driver is going to unload\n",
1134 __func__));
Larry Fingerf7c92d22014-03-28 21:37:39 -05001135 return;
1136 }
1137
Larry Fingerf7c92d22014-03-28 21:37:39 -05001138 for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
1139 struct sta_info *pstat = pDM_Odm->pODM_StaInfo[i];
Jes Sorensen2e8d47e2014-07-17 22:59:57 +02001140 if (pstat) {
Jes Sorensenb58298e2015-03-02 15:25:01 -05001141 smoothed = pstat->rssi_stat.UndecoratedSmoothedPWDB;
1142 if (ODM_RAStateCheck23a(pDM_Odm, smoothed, false,
1143 &pstat->rssi_level)) {
1144 ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK,
1145 ODM_DBG_LOUD,
Larry Fingerf7c92d22014-03-28 21:37:39 -05001146 ("RSSI:%d, RSSI_LEVEL:%d\n",
Jes Sorensenb58298e2015-03-02 15:25:01 -05001147 smoothed,
1148 pstat->rssi_level));
1149 rtw_hal_update_ra_mask23a(pstat,
1150 pstat->rssi_level);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001151 }
Larry Fingerf7c92d22014-03-28 21:37:39 -05001152 }
1153 }
Larry Fingerf7c92d22014-03-28 21:37:39 -05001154}
1155
Larry Fingerf7c92d22014-03-28 21:37:39 -05001156/* Return Value: bool */
1157/* - true: RATRState is changed. */
1158bool ODM_RAStateCheck23a(struct dm_odm_t *pDM_Odm, s32 RSSI, bool bForceUpdate,
1159 u8 *pRATRState)
1160{
1161 struct odm_rate_adapt *pRA = &pDM_Odm->RateAdaptive;
1162 const u8 GoUpGap = 5;
1163 u8 HighRSSIThreshForRA = pRA->HighRSSIThresh;
1164 u8 LowRSSIThreshForRA = pRA->LowRSSIThresh;
1165 u8 RATRState;
1166
1167 /* Threshold Adjustment: */
1168 /* when RSSI state trends to go up one or two levels, make sure RSSI is high enough. */
1169 /* Here GoUpGap is added to solve the boundary's level alternation issue. */
1170 switch (*pRATRState) {
1171 case DM_RATR_STA_INIT:
1172 case DM_RATR_STA_HIGH:
1173 break;
1174 case DM_RATR_STA_MIDDLE:
1175 HighRSSIThreshForRA += GoUpGap;
1176 break;
1177 case DM_RATR_STA_LOW:
1178 HighRSSIThreshForRA += GoUpGap;
1179 LowRSSIThreshForRA += GoUpGap;
1180 break;
1181 default:
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001182 ODM_RT_ASSERT(pDM_Odm, false, ("wrong rssi level setting %d !",
1183 *pRATRState));
Larry Fingerf7c92d22014-03-28 21:37:39 -05001184 break;
1185 }
1186
1187 /* Decide RATRState by RSSI. */
1188 if (RSSI > HighRSSIThreshForRA)
1189 RATRState = DM_RATR_STA_HIGH;
1190 else if (RSSI > LowRSSIThreshForRA)
1191 RATRState = DM_RATR_STA_MIDDLE;
1192 else
1193 RATRState = DM_RATR_STA_LOW;
1194
1195 if (*pRATRState != RATRState || bForceUpdate) {
1196 ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD,
1197 ("RSSI Level %d -> %d\n", *pRATRState, RATRState));
1198 *pRATRState = RATRState;
1199 return true;
1200 }
1201 return false;
1202}
1203
1204/* 3 ============================================================ */
1205/* 3 Dynamic Tx Power */
1206/* 3 ============================================================ */
1207
1208void odm_DynamicTxPower23aInit(struct dm_odm_t *pDM_Odm)
1209{
1210 struct rtw_adapter *Adapter = pDM_Odm->Adapter;
1211 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
1212 struct dm_priv *pdmpriv = &pHalData->dmpriv;
1213
Jes Sorensen13b2beb2014-05-16 10:05:13 +02001214 /*
1215 * This is never changed, so we should be able to clean up the
1216 * code checking for different values in rtl8723a_rf6052.c
1217 */
Larry Fingerf7c92d22014-03-28 21:37:39 -05001218 pdmpriv->DynamicTxHighPowerLvl = TxHighPwrLevel_Normal;
1219}
1220
Larry Fingerf7c92d22014-03-28 21:37:39 -05001221static void
Jes Sorensen0305d272015-03-02 15:25:00 -05001222FindMinimumRSSI(struct rtw_adapter *pAdapter)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001223{
1224 struct hal_data_8723a *pHalData = GET_HAL_DATA(pAdapter);
1225 struct dm_priv *pdmpriv = &pHalData->dmpriv;
1226 struct dm_odm_t *pDM_Odm = &pHalData->odmpriv;
1227
1228 /* 1 1.Determine the minimum RSSI */
1229
Jes Sorensen0305d272015-03-02 15:25:00 -05001230 if (!pDM_Odm->bLinked && !pdmpriv->EntryMinUndecoratedSmoothedPWDB)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001231 pdmpriv->MinUndecoratedPWDBForDM = 0;
1232 else
Jes Sorensen0305d272015-03-02 15:25:00 -05001233 pdmpriv->MinUndecoratedPWDBForDM =
1234 pdmpriv->EntryMinUndecoratedSmoothedPWDB;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001235}
1236
Jes Sorensen04b74662015-03-02 15:24:59 -05001237static void odm_RSSIMonitorCheck(struct dm_odm_t *pDM_Odm)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001238{
1239 struct rtw_adapter *Adapter = pDM_Odm->Adapter;
1240 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
1241 struct dm_priv *pdmpriv = &pHalData->dmpriv;
Jes Sorensen04b74662015-03-02 15:24:59 -05001242 int i;
1243 int MaxDB = 0, MinDB = 0xff;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001244 u8 sta_cnt = 0;
Jes Sorensen04b74662015-03-02 15:24:59 -05001245 u32 tmpdb;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001246 u32 PWDB_rssi[NUM_STA] = {0};/* 0~15]:MACID, [16~31]:PWDB_rssi */
1247 struct sta_info *psta;
1248
1249 if (!pDM_Odm->bLinked)
1250 return;
1251
1252 for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
1253 psta = pDM_Odm->pODM_StaInfo[i];
Jes Sorensen2e8d47e2014-07-17 22:59:57 +02001254 if (psta) {
Jes Sorensen04b74662015-03-02 15:24:59 -05001255 if (psta->rssi_stat.UndecoratedSmoothedPWDB < MinDB)
1256 MinDB = psta->rssi_stat.UndecoratedSmoothedPWDB;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001257
Jes Sorensen04b74662015-03-02 15:24:59 -05001258 if (psta->rssi_stat.UndecoratedSmoothedPWDB > MaxDB)
1259 MaxDB = psta->rssi_stat.UndecoratedSmoothedPWDB;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001260
Jes Sorensen04b74662015-03-02 15:24:59 -05001261 if (psta->rssi_stat.UndecoratedSmoothedPWDB != -1) {
1262 tmpdb = psta->rssi_stat.UndecoratedSmoothedPWDB;
1263 PWDB_rssi[sta_cnt++] = psta->mac_id |
1264 (tmpdb << 16);
1265 }
Larry Fingerf7c92d22014-03-28 21:37:39 -05001266 }
1267 }
1268
1269 for (i = 0; i < sta_cnt; i++) {
Jes Sorensen04b74662015-03-02 15:24:59 -05001270 if (PWDB_rssi[i] != (0))
Anatoly Stepanov485b0992015-12-17 16:47:36 +03001271 rtl8723a_set_rssi_cmd(Adapter, PWDB_rssi[i]);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001272 }
1273
Jes Sorensen04b74662015-03-02 15:24:59 -05001274 pdmpriv->EntryMaxUndecoratedSmoothedPWDB = MaxDB;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001275
Jes Sorensen04b74662015-03-02 15:24:59 -05001276 if (MinDB != 0xff) /* If associated entry is found */
1277 pdmpriv->EntryMinUndecoratedSmoothedPWDB = MinDB;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001278 else
1279 pdmpriv->EntryMinUndecoratedSmoothedPWDB = 0;
1280
1281 FindMinimumRSSI(Adapter);/* get pdmpriv->MinUndecoratedPWDBForDM */
1282
Jes Sorensen04b74662015-03-02 15:24:59 -05001283 ODM_CmnInfoUpdate23a(&pHalData->odmpriv, ODM_CMNINFO_RSSI_MIN,
1284 pdmpriv->MinUndecoratedPWDBForDM);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001285}
1286
Larry Fingerf7c92d22014-03-28 21:37:39 -05001287/* endif */
1288/* 3 ============================================================ */
1289/* 3 Tx Power Tracking */
1290/* 3 ============================================================ */
1291
Jes Sorensendef0c452015-03-05 14:24:36 -05001292static void odm_TXPowerTrackingInit(struct dm_odm_t *pDM_Odm)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001293{
1294 struct rtw_adapter *Adapter = pDM_Odm->Adapter;
1295 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
1296 struct dm_priv *pdmpriv = &pHalData->dmpriv;
1297
1298 pdmpriv->bTXPowerTracking = true;
1299 pdmpriv->TXPowercount = 0;
1300 pdmpriv->bTXPowerTrackingInit = false;
1301 pdmpriv->TxPowerTrackControl = true;
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001302 MSG_8723A("pdmpriv->TxPowerTrackControl = %d\n",
1303 pdmpriv->TxPowerTrackControl);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001304
1305 pDM_Odm->RFCalibrateInfo.TxPowerTrackControl = true;
1306}
1307
Larry Fingerf7c92d22014-03-28 21:37:39 -05001308/* EDCA Turbo */
Jes Sorensen4d1def6b2014-07-21 11:24:42 +02001309static void ODM_EdcaTurboInit23a(struct dm_odm_t *pDM_Odm)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001310{
Larry Fingerf7c92d22014-03-28 21:37:39 -05001311 struct rtw_adapter *Adapter = pDM_Odm->Adapter;
Anjana Sasindran0dc48722014-12-04 18:11:13 +05301312
Larry Fingerf7c92d22014-03-28 21:37:39 -05001313 pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA = false;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001314 Adapter->recvpriv.bIsAnyNonBEPkts = false;
1315
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001316 ODM_RT_TRACE(pDM_Odm, ODM_COMP_EDCA_TURBO, ODM_DBG_LOUD,
1317 ("Orginial VO PARAM: 0x%x\n",
Jes Sorensen53de9942015-03-05 14:24:47 -05001318 rtl8723au_read32(Adapter, ODM_EDCA_VO_PARAM)));
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001319 ODM_RT_TRACE(pDM_Odm, ODM_COMP_EDCA_TURBO, ODM_DBG_LOUD,
1320 ("Orginial VI PARAM: 0x%x\n",
Jes Sorensen53de9942015-03-05 14:24:47 -05001321 rtl8723au_read32(Adapter, ODM_EDCA_VI_PARAM)));
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001322 ODM_RT_TRACE(pDM_Odm, ODM_COMP_EDCA_TURBO, ODM_DBG_LOUD,
1323 ("Orginial BE PARAM: 0x%x\n",
Jes Sorensen53de9942015-03-05 14:24:47 -05001324 rtl8723au_read32(Adapter, ODM_EDCA_BE_PARAM)));
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001325 ODM_RT_TRACE(pDM_Odm, ODM_COMP_EDCA_TURBO, ODM_DBG_LOUD,
1326 ("Orginial BK PARAM: 0x%x\n",
Jes Sorensen53de9942015-03-05 14:24:47 -05001327 rtl8723au_read32(Adapter, ODM_EDCA_BK_PARAM)));
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001328}
Larry Fingerf7c92d22014-03-28 21:37:39 -05001329
Jes Sorensen4d1def6b2014-07-21 11:24:42 +02001330static void odm_EdcaTurboCheck23a(struct dm_odm_t *pDM_Odm)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001331{
Larry Fingerf7c92d22014-03-28 21:37:39 -05001332 struct rtw_adapter *Adapter = pDM_Odm->Adapter;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001333 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
1334 struct xmit_priv *pxmitpriv = &Adapter->xmitpriv;
1335 struct recv_priv *precvpriv = &Adapter->recvpriv;
1336 struct registry_priv *pregpriv = &Adapter->registrypriv;
1337 struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
1338 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
Jes Sorensen9ea3b822014-07-21 11:24:41 +02001339 u32 trafficIndex;
1340 u32 edca_param;
Jes Sorensen4b4431c2015-03-02 15:24:37 -05001341 u64 cur_tx_bytes;
1342 u64 cur_rx_bytes;
Jes Sorensen9ea3b822014-07-21 11:24:41 +02001343
1344 /* For AP/ADSL use struct rtl8723a_priv * */
1345 /* For CE/NIC use struct rtw_adapter * */
1346
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001347 /*
1348 * 2011/09/29 MH In HW integration first stage, we provide 4
1349 * different handle to operate at the same time. In the stage2/3,
1350 * we need to prive universal interface and merge all HW dynamic
1351 * mechanism.
1352 */
Jes Sorensen9ea3b822014-07-21 11:24:41 +02001353
Larry Fingerf7c92d22014-03-28 21:37:39 -05001354 if ((pregpriv->wifi_spec == 1))/* (pmlmeinfo->HT_enable == 0)) */
1355 goto dm_CheckEdcaTurbo_EXIT;
1356
1357 if (pmlmeinfo->assoc_AP_vendor >= HT_IOT_PEER_MAX)
1358 goto dm_CheckEdcaTurbo_EXIT;
1359
Jes Sorensendddeff32014-05-25 22:43:37 +02001360 if (rtl8723a_BT_disable_EDCA_turbo(Adapter))
Larry Fingerf7c92d22014-03-28 21:37:39 -05001361 goto dm_CheckEdcaTurbo_EXIT;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001362
1363 /* Check if the status needs to be changed. */
Jes Sorensendaa656b2015-03-02 15:24:36 -05001364 if (!precvpriv->bIsAnyNonBEPkts) {
Larry Fingerf7c92d22014-03-28 21:37:39 -05001365 cur_tx_bytes = pxmitpriv->tx_bytes - pxmitpriv->last_tx_bytes;
1366 cur_rx_bytes = precvpriv->rx_bytes - precvpriv->last_rx_bytes;
1367
1368 /* traffic, TX or RX */
1369 if ((pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_RALINK) ||
1370 (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_ATHEROS)) {
1371 if (cur_tx_bytes > (cur_rx_bytes << 2)) {
1372 /* Uplink TP is present. */
1373 trafficIndex = UP_LINK;
1374 } else { /* Balance TP is present. */
1375 trafficIndex = DOWN_LINK;
1376 }
1377 } else {
1378 if (cur_rx_bytes > (cur_tx_bytes << 2)) {
1379 /* Downlink TP is present. */
1380 trafficIndex = DOWN_LINK;
1381 } else { /* Balance TP is present. */
1382 trafficIndex = UP_LINK;
1383 }
1384 }
1385
1386 if ((pDM_Odm->DM_EDCA_Table.prv_traffic_idx != trafficIndex) ||
1387 (!pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA)) {
1388 if ((pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_CISCO) &&
1389 (pmlmeext->cur_wireless_mode & WIRELESS_11_24N))
1390 edca_param = EDCAParam[pmlmeinfo->assoc_AP_vendor][trafficIndex];
1391 else
1392 edca_param = EDCAParam[HT_IOT_PEER_UNKNOWN][trafficIndex];
Jes Sorensenedbfd672014-05-16 10:05:09 +02001393 rtl8723au_write32(Adapter, REG_EDCA_BE_PARAM,
1394 edca_param);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001395
1396 pDM_Odm->DM_EDCA_Table.prv_traffic_idx = trafficIndex;
1397 }
1398
1399 pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA = true;
1400 } else {
1401 /* Turn Off EDCA turbo here. */
1402 /* Restore original EDCA according to the declaration of AP. */
1403 if (pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA) {
Jes Sorensenedbfd672014-05-16 10:05:09 +02001404 rtl8723au_write32(Adapter, REG_EDCA_BE_PARAM,
1405 pHalData->AcParam_BE);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001406 pDM_Odm->DM_EDCA_Table.bCurrentTurboEDCA = false;
1407 }
1408 }
1409
1410dm_CheckEdcaTurbo_EXIT:
1411 /* Set variables for next time. */
1412 precvpriv->bIsAnyNonBEPkts = false;
1413 pxmitpriv->last_tx_bytes = pxmitpriv->tx_bytes;
1414 precvpriv->last_rx_bytes = precvpriv->rx_bytes;
1415}
1416
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001417u32 GetPSDData(struct dm_odm_t *pDM_Odm, unsigned int point,
1418 u8 initial_gain_psd)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001419{
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001420 struct rtw_adapter *adapter = pDM_Odm->Adapter;
Jes Sorensen2635f192015-03-05 14:24:49 -05001421 u32 psd_report, val32;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001422
1423 /* Set DCO frequency index, offset = (40MHz/SamplePts)*point */
Jes Sorensen2635f192015-03-05 14:24:49 -05001424 val32 = rtl8723au_read32(adapter, 0x808);
1425 val32 &= ~0x3ff;
1426 val32 |= (point & 0x3ff);
1427 rtl8723au_write32(adapter, 0x808, val32);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001428
1429 /* Start PSD calculation, Reg808[22]= 0->1 */
Jes Sorensen2635f192015-03-05 14:24:49 -05001430 val32 = rtl8723au_read32(adapter, 0x808);
1431 val32 |= BIT(22);
1432 rtl8723au_write32(adapter, 0x808, val32);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001433 /* Need to wait for HW PSD report */
1434 udelay(30);
Jes Sorensen2635f192015-03-05 14:24:49 -05001435 val32 = rtl8723au_read32(adapter, 0x808);
1436 val32 &= ~BIT(22);
1437 rtl8723au_write32(adapter, 0x808, val32);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001438 /* Read PSD report, Reg8B4[15:0] */
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001439 psd_report = rtl8723au_read32(adapter, 0x8B4) & 0x0000FFFF;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001440
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001441 psd_report = (u32)(ConvertTo_dB23a(psd_report)) +
1442 (u32)(initial_gain_psd-0x1c);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001443
1444 return psd_report;
1445}
1446
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001447u32 ConvertTo_dB23a(u32 Value)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001448{
1449 u8 i;
1450 u8 j;
1451 u32 dB;
1452
1453 Value = Value & 0xFFFF;
1454
1455 for (i = 0; i < 8; i++) {
1456 if (Value <= dB_Invert_Table[i][11])
1457 break;
1458 }
1459
1460 if (i >= 8)
1461 return 96; /* maximum 96 dB */
1462
1463 for (j = 0; j < 12; j++) {
1464 if (Value <= dB_Invert_Table[i][j])
1465 break;
1466 }
1467
1468 dB = i*12 + j + 1;
1469
1470 return dB;
1471}
1472
1473/* */
Larry Fingerf7c92d22014-03-28 21:37:39 -05001474/* Description: */
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001475/* Set Single/Dual Antenna default setting for products that do not
1476 * do detection in advance. */
Larry Fingerf7c92d22014-03-28 21:37:39 -05001477/* */
1478/* Added by Joseph, 2012.03.22 */
1479/* */
1480void ODM_SingleDualAntennaDefaultSetting(struct dm_odm_t *pDM_Odm)
1481{
1482 struct sw_ant_sw *pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
Anjana Sasindran0dc48722014-12-04 18:11:13 +05301483
Larry Fingerf7c92d22014-03-28 21:37:39 -05001484 pDM_SWAT_Table->ANTA_ON = true;
1485 pDM_SWAT_Table->ANTB_ON = true;
1486}
1487
1488/* 2 8723A ANT DETECT */
1489
Jes Sorensen8cba07d2015-03-02 15:24:49 -05001490static void odm_PHY_SaveAFERegisters(struct dm_odm_t *pDM_Odm, u32 *AFEReg,
1491 u32 *AFEBackup, u32 RegisterNum)
Larry Fingerf7c92d22014-03-28 21:37:39 -05001492{
1493 u32 i;
1494
Larry Fingerf7c92d22014-03-28 21:37:39 -05001495 for (i = 0 ; i < RegisterNum ; i++)
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001496 AFEBackup[i] = rtl8723au_read32(pDM_Odm->Adapter, AFEReg[i]);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001497}
1498
1499static void odm_PHY_ReloadAFERegisters(struct dm_odm_t *pDM_Odm, u32 *AFEReg,
1500 u32 *AFEBackup, u32 RegiesterNum)
1501{
1502 u32 i;
1503
1504 for (i = 0 ; i < RegiesterNum; i++)
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001505 rtl8723au_write32(pDM_Odm->Adapter, AFEReg[i], AFEBackup[i]);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001506}
1507
1508/* 2 8723A ANT DETECT */
1509/* Description: */
1510/* Implement IQK single tone for RF DPK loopback and BB PSD scanning. */
1511/* This function is cooperated with BB team Neil. */
1512bool ODM_SingleDualAntennaDetection(struct dm_odm_t *pDM_Odm, u8 mode)
1513{
1514 struct sw_ant_sw *pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001515 struct rtw_adapter *adapter = pDM_Odm->Adapter;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001516 u32 CurrentChannel, RfLoopReg;
1517 u8 n;
Jes Sorensen2635f192015-03-05 14:24:49 -05001518 u32 Reg88c, Regc08, Reg874, Regc50, val32;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001519 u8 initial_gain = 0x5a;
1520 u32 PSD_report_tmp;
1521 u32 AntA_report = 0x0, AntB_report = 0x0, AntO_report = 0x0;
1522 bool bResult = true;
1523 u32 AFE_Backup[16];
1524 u32 AFE_REG_8723A[16] = {
1525 rRx_Wait_CCA, rTx_CCK_RFON,
1526 rTx_CCK_BBON, rTx_OFDM_RFON,
1527 rTx_OFDM_BBON, rTx_To_Rx,
1528 rTx_To_Tx, rRx_CCK,
1529 rRx_OFDM, rRx_Wait_RIFS,
1530 rRx_TO_Rx, rStandby,
1531 rSleep, rPMPD_ANAEN,
1532 rFPGA0_XCD_SwitchControl, rBlue_Tooth};
1533
Jes Sorensen344af822014-07-17 22:59:55 +02001534 if (!(pDM_Odm->SupportICType & ODM_RTL8723A))
Larry Fingerf7c92d22014-03-28 21:37:39 -05001535 return bResult;
1536
1537 if (!(pDM_Odm->SupportAbility&ODM_BB_ANT_DIV))
1538 return bResult;
1539 /* 1 Backup Current RF/BB Settings */
1540
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001541 CurrentChannel = ODM_GetRFReg(pDM_Odm, RF_PATH_A, ODM_CHANNEL,
1542 bRFRegOffsetMask);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001543 RfLoopReg = ODM_GetRFReg(pDM_Odm, RF_PATH_A, 0x00, bRFRegOffsetMask);
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001544 /* change to Antenna A */
Jes Sorensen2635f192015-03-05 14:24:49 -05001545 val32 = rtl8723au_read32(adapter, rFPGA0_XA_RFInterfaceOE);
1546 val32 &= ~0x300;
1547 val32 |= 0x100; /* Enable antenna A */
1548 rtl8723au_write32(adapter, rFPGA0_XA_RFInterfaceOE, val32);
1549
Larry Fingerf7c92d22014-03-28 21:37:39 -05001550 /* Step 1: USE IQK to transmitter single tone */
1551
1552 udelay(10);
1553
1554 /* Store A Path Register 88c, c08, 874, c50 */
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001555 Reg88c = rtl8723au_read32(adapter, rFPGA0_AnalogParameter4);
1556 Regc08 = rtl8723au_read32(adapter, rOFDM0_TRMuxPar);
1557 Reg874 = rtl8723au_read32(adapter, rFPGA0_XCD_RFInterfaceSW);
1558 Regc50 = rtl8723au_read32(adapter, rOFDM0_XAAGCCore1);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001559
1560 /* Store AFE Registers */
1561 odm_PHY_SaveAFERegisters(pDM_Odm, AFE_REG_8723A, AFE_Backup, 16);
1562
1563 /* Set PSD 128 pts */
Jes Sorensen2635f192015-03-05 14:24:49 -05001564 val32 = rtl8723au_read32(adapter, rFPGA0_PSDFunction);
1565 val32 &= ~(BIT(14) | BIT(15));
1566 rtl8723au_write32(adapter, rFPGA0_PSDFunction, val32);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001567
1568 /* To SET CH1 to do */
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001569 ODM_SetRFReg(pDM_Odm, RF_PATH_A, ODM_CHANNEL, bRFRegOffsetMask, 0x01);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001570
1571 /* AFE all on step */
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001572 rtl8723au_write32(adapter, rRx_Wait_CCA, 0x6FDB25A4);
1573 rtl8723au_write32(adapter, rTx_CCK_RFON, 0x6FDB25A4);
1574 rtl8723au_write32(adapter, rTx_CCK_BBON, 0x6FDB25A4);
1575 rtl8723au_write32(adapter, rTx_OFDM_RFON, 0x6FDB25A4);
1576 rtl8723au_write32(adapter, rTx_OFDM_BBON, 0x6FDB25A4);
1577 rtl8723au_write32(adapter, rTx_To_Rx, 0x6FDB25A4);
1578 rtl8723au_write32(adapter, rTx_To_Tx, 0x6FDB25A4);
1579 rtl8723au_write32(adapter, rRx_CCK, 0x6FDB25A4);
1580 rtl8723au_write32(adapter, rRx_OFDM, 0x6FDB25A4);
1581 rtl8723au_write32(adapter, rRx_Wait_RIFS, 0x6FDB25A4);
1582 rtl8723au_write32(adapter, rRx_TO_Rx, 0x6FDB25A4);
1583 rtl8723au_write32(adapter, rStandby, 0x6FDB25A4);
1584 rtl8723au_write32(adapter, rSleep, 0x6FDB25A4);
1585 rtl8723au_write32(adapter, rPMPD_ANAEN, 0x6FDB25A4);
1586 rtl8723au_write32(adapter, rFPGA0_XCD_SwitchControl, 0x6FDB25A4);
1587 rtl8723au_write32(adapter, rBlue_Tooth, 0x6FDB25A4);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001588
1589 /* 3 wire Disable */
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001590 rtl8723au_write32(adapter, rFPGA0_AnalogParameter4, 0xCCF000C0);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001591
1592 /* BB IQK Setting */
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001593 rtl8723au_write32(adapter, rOFDM0_TRMuxPar, 0x000800E4);
1594 rtl8723au_write32(adapter, rFPGA0_XCD_RFInterfaceSW, 0x22208000);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001595
1596 /* IQK setting tone@ 4.34Mhz */
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001597 rtl8723au_write32(adapter, rTx_IQK_Tone_A, 0x10008C1C);
1598 rtl8723au_write32(adapter, rTx_IQK, 0x01007c00);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001599
1600 /* Page B init */
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001601 rtl8723au_write32(adapter, rConfig_AntA, 0x00080000);
1602 rtl8723au_write32(adapter, rConfig_AntA, 0x0f600000);
1603 rtl8723au_write32(adapter, rRx_IQK, 0x01004800);
1604 rtl8723au_write32(adapter, rRx_IQK_Tone_A, 0x10008c1f);
1605 rtl8723au_write32(adapter, rTx_IQK_PI_A, 0x82150008);
1606 rtl8723au_write32(adapter, rRx_IQK_PI_A, 0x28150008);
1607 rtl8723au_write32(adapter, rIQK_AGC_Rsp, 0x001028d0);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001608
1609 /* RF loop Setting */
1610 ODM_SetRFReg(pDM_Odm, RF_PATH_A, 0x0, 0xFFFFF, 0x50008);
1611
1612 /* IQK Single tone start */
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001613 rtl8723au_write32(adapter, rFPGA0_IQK, 0x80800000);
1614 rtl8723au_write32(adapter, rIQK_AGC_Pts, 0xf8000000);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001615 udelay(1000);
1616 PSD_report_tmp = 0x0;
1617
1618 for (n = 0; n < 2; n++) {
1619 PSD_report_tmp = GetPSDData(pDM_Odm, 14, initial_gain);
1620 if (PSD_report_tmp > AntA_report)
1621 AntA_report = PSD_report_tmp;
1622 }
1623
1624 PSD_report_tmp = 0x0;
1625
Jes Sorensen2635f192015-03-05 14:24:49 -05001626 val32 = rtl8723au_read32(adapter, rFPGA0_XA_RFInterfaceOE);
1627 val32 &= ~0x300;
1628 val32 |= 0x200; /* Enable antenna B */
1629 rtl8723au_write32(adapter, rFPGA0_XA_RFInterfaceOE, val32);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001630 udelay(10);
1631
1632 for (n = 0; n < 2; n++) {
1633 PSD_report_tmp = GetPSDData(pDM_Odm, 14, initial_gain);
1634 if (PSD_report_tmp > AntB_report)
1635 AntB_report = PSD_report_tmp;
1636 }
1637
1638 /* change to open case */
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001639 /* change to Ant A and B all open case */
Jes Sorensen2635f192015-03-05 14:24:49 -05001640 val32 = rtl8723au_read32(adapter, rFPGA0_XA_RFInterfaceOE);
1641 val32 &= ~0x300;
1642 rtl8723au_write32(adapter, rFPGA0_XA_RFInterfaceOE, val32);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001643 udelay(10);
1644
1645 for (n = 0; n < 2; n++) {
1646 PSD_report_tmp = GetPSDData(pDM_Odm, 14, initial_gain);
1647 if (PSD_report_tmp > AntO_report)
1648 AntO_report = PSD_report_tmp;
1649 }
1650
1651 /* Close IQK Single Tone function */
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001652 rtl8723au_write32(adapter, rFPGA0_IQK, 0x00000000);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001653 PSD_report_tmp = 0x0;
1654
1655 /* 1 Return to antanna A */
Jes Sorensen2635f192015-03-05 14:24:49 -05001656 val32 = rtl8723au_read32(adapter, rFPGA0_XA_RFInterfaceOE);
1657 val32 &= ~0x300;
1658 val32 |= 0x100; /* Enable antenna A */
1659 rtl8723au_write32(adapter, rFPGA0_XA_RFInterfaceOE, val32);
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001660 rtl8723au_write32(adapter, rFPGA0_AnalogParameter4, Reg88c);
1661 rtl8723au_write32(adapter, rOFDM0_TRMuxPar, Regc08);
1662 rtl8723au_write32(adapter, rFPGA0_XCD_RFInterfaceSW, Reg874);
Jes Sorensen2635f192015-03-05 14:24:49 -05001663 val32 = rtl8723au_read32(adapter, rOFDM0_XAAGCCore1);
1664 val32 &= ~0x7f;
1665 val32 |= 0x40;
1666 rtl8723au_write32(adapter, rOFDM0_XAAGCCore1, val32);
1667
Jes Sorensenbfd83bb2015-03-05 14:24:37 -05001668 rtl8723au_write32(adapter, rOFDM0_XAAGCCore1, Regc50);
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001669 ODM_SetRFReg(pDM_Odm, RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask,
1670 CurrentChannel);
Larry Fingerf7c92d22014-03-28 21:37:39 -05001671 ODM_SetRFReg(pDM_Odm, RF_PATH_A, 0x00, bRFRegOffsetMask, RfLoopReg);
1672
1673 /* Reload AFE Registers */
1674 odm_PHY_ReloadAFERegisters(pDM_Odm, AFE_REG_8723A, AFE_Backup, 16);
1675
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001676 ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
1677 ("psd_report_A[%d]= %d \n", 2416, AntA_report));
1678 ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
1679 ("psd_report_B[%d]= %d \n", 2416, AntB_report));
1680 ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
1681 ("psd_report_O[%d]= %d \n", 2416, AntO_report));
Larry Fingerf7c92d22014-03-28 21:37:39 -05001682
1683 /* 2 Test Ant B based on Ant A is ON */
1684 if (mode == ANTTESTB) {
1685 if (AntA_report >= 100) {
1686 if (AntB_report > (AntA_report+1)) {
1687 pDM_SWAT_Table->ANTB_ON = false;
1688 ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("ODM_SingleDualAntennaDetection(): Single Antenna A\n"));
1689 } else {
1690 pDM_SWAT_Table->ANTB_ON = true;
1691 ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("ODM_SingleDualAntennaDetection(): Dual Antenna is A and B\n"));
1692 }
1693 } else {
1694 ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, ("ODM_SingleDualAntennaDetection(): Need to check again\n"));
1695 pDM_SWAT_Table->ANTB_ON = false; /* Set Antenna B off as default */
1696 bResult = false;
1697 }
1698 } else if (mode == ANTTESTALL) {
1699 /* 2 Test Ant A and B based on DPDT Open */
1700 if ((AntO_report >= 100) & (AntO_report < 118)) {
1701 if (AntA_report > (AntO_report+1)) {
1702 pDM_SWAT_Table->ANTA_ON = false;
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001703 ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,
1704 ODM_DBG_LOUD, ("Ant A is OFF"));
Larry Fingerf7c92d22014-03-28 21:37:39 -05001705 } else {
1706 pDM_SWAT_Table->ANTA_ON = true;
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001707 ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,
1708 ODM_DBG_LOUD, ("Ant A is ON"));
Larry Fingerf7c92d22014-03-28 21:37:39 -05001709 }
1710
1711 if (AntB_report > (AntO_report+2)) {
1712 pDM_SWAT_Table->ANTB_ON = false;
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001713 ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,
1714 ODM_DBG_LOUD, ("Ant B is OFF"));
Larry Fingerf7c92d22014-03-28 21:37:39 -05001715 } else {
1716 pDM_SWAT_Table->ANTB_ON = true;
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001717 ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV,
1718 ODM_DBG_LOUD, ("Ant B is ON"));
Larry Fingerf7c92d22014-03-28 21:37:39 -05001719 }
1720 }
1721 } else {
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001722 ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
1723 ("ODM_SingleDualAntennaDetection(): Need to check again\n"));
1724 /* Set Antenna A on as default */
1725 pDM_SWAT_Table->ANTA_ON = true;
1726 /* Set Antenna B off as default */
1727 pDM_SWAT_Table->ANTB_ON = false;
Larry Fingerf7c92d22014-03-28 21:37:39 -05001728 bResult = false;
1729 }
Jes Sorensenfe6e0192015-03-02 15:25:03 -05001730
Larry Fingerf7c92d22014-03-28 21:37:39 -05001731 return bResult;
1732}