2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: Handles the auto fallback & data rates functions
28 * RATEvParseMaxRate - Parsing the highest basic & support rate in rate field of frame
29 * RATEvTxRateFallBack - Rate fallback Algorithm Implementaion
30 * RATEuSetIE- Set rate IE field.
46 /* static int msglevel = MSG_LEVEL_DEBUG; */
47 static int msglevel
= MSG_LEVEL_INFO
;
48 static const u8 acbyIERate
[MAX_RATE
] = {0x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18,
49 0x24, 0x30, 0x48, 0x60, 0x6C};
51 #define AUTORATE_TXOK_CNT 0x0400
52 #define AUTORATE_TXFAIL_CNT 0x0064
53 #define AUTORATE_TIMEOUT 10
55 void s_vResetCounter(PKnownNodeDB psNodeDBTable
);
57 void s_vResetCounter(PKnownNodeDB psNodeDBTable
)
61 /* clear statistics counter for auto_rate */
62 for (ii
= 0; ii
<= MAX_RATE
; ii
++) {
63 psNodeDBTable
->uTxOk
[ii
] = 0;
64 psNodeDBTable
->uTxFail
[ii
] = 0;
70 * Routine Description:
71 * Rate fallback Algorithm Implementaion
75 * pDevice - Pointer to the adapter
76 * psNodeDBTable - Pointer to Node Data Base
83 #define AUTORATE_TXCNT_THRESHOLD 20
84 #define AUTORATE_INC_THRESHOLD 30
89 * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE
93 * u8 - Rate value in SuppRates IE or ExtSuppRates IE
97 * Return Value: RateIdx
100 u16
RATEwGetRateIdx(u8 byRate
)
104 /* erase BasicRate flag */
105 byRate
= byRate
& 0x7F;
107 for (ii
= 0; ii
< MAX_RATE
; ii
++) {
108 if (acbyIERate
[ii
] == byRate
)
117 * Parsing the highest basic & support rate in rate field of frame.
121 * pDevice - Pointer to the adapter
122 * pItemRates - Pointer to Rate field defined in 802.11 spec.
123 * pItemExtRates - Pointer to Extended Rate field defined in 802.11 spec.
125 * pwMaxBasicRate - Maximum Basic Rate
126 * pwMaxSuppRate - Maximum Supported Rate
127 * pbyTopCCKRate - Maximum Basic Rate in CCK mode
128 * pbyTopOFDMRate - Maximum Basic Rate in OFDM mode
134 void RATEvParseMaxRate(struct vnt_private
*pDevice
,
135 PWLAN_IE_SUPP_RATES pItemRates
, PWLAN_IE_SUPP_RATES pItemExtRates
,
136 int bUpdateBasicRate
, u16
*pwMaxBasicRate
, u16
*pwMaxSuppRate
,
137 u16
*pwSuppRate
, u8
*pbyTopCCKRate
, u8
*pbyTopOFDMRate
)
140 u8 byHighSuppRate
= 0, byRate
= 0;
141 u16 wOldBasicRate
= pDevice
->wBasicRate
;
144 if (pItemRates
== NULL
)
148 uRateLen
= pItemRates
->len
;
150 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ParseMaxRate Len: %d\n", uRateLen
);
151 if (pDevice
->byBBType
!= BB_TYPE_11B
) {
152 if (uRateLen
> WLAN_RATES_MAXLEN
)
153 uRateLen
= WLAN_RATES_MAXLEN
;
155 if (uRateLen
> WLAN_RATES_MAXLEN_11B
)
156 uRateLen
= WLAN_RATES_MAXLEN_11B
;
159 for (ii
= 0; ii
< uRateLen
; ii
++) {
160 byRate
= (u8
)(pItemRates
->abyRates
[ii
]);
161 if (WLAN_MGMT_IS_BASICRATE(byRate
) &&
162 (bUpdateBasicRate
== true)) {
164 * add to basic rate set, update pDevice->byTopCCKBasicRate and
165 * pDevice->byTopOFDMBasicRate
167 CARDbAddBasicRate((void *)pDevice
, RATEwGetRateIdx(byRate
));
168 DBG_PRT(MSG_LEVEL_DEBUG
,
169 KERN_INFO
"ParseMaxRate AddBasicRate: %d\n",
170 RATEwGetRateIdx(byRate
));
172 byRate
= (u8
)(pItemRates
->abyRates
[ii
]&0x7F);
173 if (byHighSuppRate
== 0)
174 byHighSuppRate
= byRate
;
175 if (byRate
> byHighSuppRate
)
176 byHighSuppRate
= byRate
;
177 *pwSuppRate
|= (1<<RATEwGetRateIdx(byRate
));
179 if ((pItemExtRates
!= NULL
) && (pItemExtRates
->byElementID
== WLAN_EID_EXTSUPP_RATES
) &&
180 (pDevice
->byBBType
!= BB_TYPE_11B
)) {
182 unsigned int uExtRateLen
= pItemExtRates
->len
;
184 if (uExtRateLen
> WLAN_RATES_MAXLEN
)
185 uExtRateLen
= WLAN_RATES_MAXLEN
;
187 for (ii
= 0; ii
< uExtRateLen
; ii
++) {
188 byRate
= (u8
)(pItemExtRates
->abyRates
[ii
]);
189 /* select highest basic rate */
190 if (WLAN_MGMT_IS_BASICRATE(pItemExtRates
->abyRates
[ii
])) {
192 * add to basic rate set, update pDevice->byTopCCKBasicRate and
193 * pDevice->byTopOFDMBasicRate
195 CARDbAddBasicRate((void *)pDevice
, RATEwGetRateIdx(byRate
));
196 DBG_PRT(MSG_LEVEL_DEBUG
,
197 KERN_INFO
"ParseMaxRate AddBasicRate: %d\n",
198 RATEwGetRateIdx(byRate
));
200 byRate
= (u8
)(pItemExtRates
->abyRates
[ii
]&0x7F);
201 if (byHighSuppRate
== 0)
202 byHighSuppRate
= byRate
;
203 if (byRate
> byHighSuppRate
)
204 byHighSuppRate
= byRate
;
205 *pwSuppRate
|= (1<<RATEwGetRateIdx(byRate
));
207 /* DBG_PRN_GRP09(("ParseMaxRate : HighSuppRate: %d, %X\n",
208 * RATEwGetRateIdx(byRate), byRate));
213 if ((pDevice
->byPacketType
== PK_TYPE_11GB
)
214 && CARDbIsOFDMinBasicRate((void *)pDevice
)) {
215 pDevice
->byPacketType
= PK_TYPE_11GA
;
218 *pbyTopCCKRate
= pDevice
->byTopCCKBasicRate
;
219 *pbyTopOFDMRate
= pDevice
->byTopOFDMBasicRate
;
220 *pwMaxSuppRate
= RATEwGetRateIdx(byHighSuppRate
);
221 if ((pDevice
->byPacketType
== PK_TYPE_11B
) || (pDevice
->byPacketType
== PK_TYPE_11GB
))
222 *pwMaxBasicRate
= pDevice
->byTopCCKBasicRate
;
224 *pwMaxBasicRate
= pDevice
->byTopOFDMBasicRate
;
225 if (wOldBasicRate
!= pDevice
->wBasicRate
)
226 CARDvSetRSPINF((void *)pDevice
, pDevice
->byBBType
);
228 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Exit ParseMaxRate\n");
233 * Routine Description:
234 * Rate fallback Algorithm Implementaion
238 * pDevice - Pointer to the adapter
239 * psNodeDBTable - Pointer to Node Data Base
246 #define AUTORATE_TXCNT_THRESHOLD 20
247 #define AUTORATE_INC_THRESHOLD 30
249 void RATEvTxRateFallBack(struct vnt_private
*pDevice
,
250 PKnownNodeDB psNodeDBTable
)
252 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
253 u16 wIdxDownRate
= 0;
255 int bAutoRate
[MAX_RATE
] = {true, true, true, true, false, false, true,
256 true, true, true, true, true};
257 u32 dwThroughputTbl
[MAX_RATE
] = {10, 20, 55, 110, 60, 90, 120, 180,
259 u32 dwThroughput
= 0;
263 if (pMgmt
->eScanState
!= WMAC_NO_SCANNING
)
264 return; /* Don't do Fallback when scanning Channel */
266 psNodeDBTable
->uTimeCount
++;
268 if (psNodeDBTable
->uTxFail
[MAX_RATE
] > psNodeDBTable
->uTxOk
[MAX_RATE
])
269 dwTxDiff
= psNodeDBTable
->uTxFail
[MAX_RATE
] - psNodeDBTable
->uTxOk
[MAX_RATE
];
271 if ((psNodeDBTable
->uTxOk
[MAX_RATE
] < AUTORATE_TXOK_CNT
) &&
272 (dwTxDiff
< AUTORATE_TXFAIL_CNT
) &&
273 (psNodeDBTable
->uTimeCount
< AUTORATE_TIMEOUT
)) {
277 if (psNodeDBTable
->uTimeCount
>= AUTORATE_TIMEOUT
)
278 psNodeDBTable
->uTimeCount
= 0;
280 for (ii
= 0; ii
< MAX_RATE
; ii
++) {
281 if (psNodeDBTable
->wSuppRate
& (0x0001<<ii
)) {
282 if (bAutoRate
[ii
] == true)
283 wIdxUpRate
= (u16
) ii
;
285 bAutoRate
[ii
] = false;
289 for (ii
= 0; ii
<= psNodeDBTable
->wTxDataRate
; ii
++) {
290 if ((psNodeDBTable
->uTxOk
[ii
] != 0) ||
291 (psNodeDBTable
->uTxFail
[ii
] != 0)) {
292 dwThroughputTbl
[ii
] *= psNodeDBTable
->uTxOk
[ii
];
294 psNodeDBTable
->uTxFail
[ii
] *= 4;
295 dwThroughputTbl
[ii
] /= (psNodeDBTable
->uTxOk
[ii
] + psNodeDBTable
->uTxFail
[ii
]);
297 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Rate %d,Ok: %d, Fail:%d, Throughput:%d\n",
298 ii
, (int)psNodeDBTable
->uTxOk
[ii
], (int)psNodeDBTable
->uTxFail
[ii
], (int)dwThroughputTbl
[ii
]);
300 dwThroughput
= dwThroughputTbl
[psNodeDBTable
->wTxDataRate
];
302 wIdxDownRate
= psNodeDBTable
->wTxDataRate
;
303 for (ii
= psNodeDBTable
->wTxDataRate
; ii
> 0;) {
305 if ((dwThroughputTbl
[ii
] > dwThroughput
) &&
306 (bAutoRate
[ii
] == true)) {
307 dwThroughput
= dwThroughputTbl
[ii
];
308 wIdxDownRate
= (u16
) ii
;
311 psNodeDBTable
->wTxDataRate
= wIdxDownRate
;
312 if (psNodeDBTable
->uTxOk
[MAX_RATE
]) {
313 if (psNodeDBTable
->uTxOk
[MAX_RATE
] >
314 (psNodeDBTable
->uTxFail
[MAX_RATE
] * 4)) {
315 psNodeDBTable
->wTxDataRate
= wIdxUpRate
;
317 } else { /* adhoc, if uTxOk(total) == 0 & uTxFail(total) == 0 */
318 if (psNodeDBTable
->uTxFail
[MAX_RATE
] == 0)
319 psNodeDBTable
->wTxDataRate
= wIdxUpRate
;
322 if (pDevice
->byBBType
== BB_TYPE_11A
) {
323 if (psNodeDBTable
->wTxDataRate
<= RATE_11M
)
324 psNodeDBTable
->wTxDataRate
= RATE_6M
;
326 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"uTxOk[MAX_RATE] %d, uTxFail[MAX_RATE]:%d\n", (int)psNodeDBTable
->uTxOk
[MAX_RATE
], (int)psNodeDBTable
->uTxFail
[MAX_RATE
]);
327 s_vResetCounter(psNodeDBTable
);
328 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Rate: %d, U:%d, D:%d\n", (int)psNodeDBTable
->wTxDataRate
, (int)wIdxUpRate
, (int)wIdxDownRate
);
335 * This routine is used to assemble available Rate IE.
345 u8
RATEuSetIE(PWLAN_IE_SUPP_RATES pSrcRates
, PWLAN_IE_SUPP_RATES pDstRates
,
346 unsigned int uRateLen
)
348 unsigned int ii
, uu
, uRateCnt
= 0;
350 if ((pSrcRates
== NULL
) || (pDstRates
== NULL
))
353 if (pSrcRates
->len
== 0)
356 for (ii
= 0; ii
< uRateLen
; ii
++) {
357 for (uu
= 0; uu
< pSrcRates
->len
; uu
++) {
358 if ((pSrcRates
->abyRates
[uu
] & 0x7F) == acbyIERate
[ii
]) {
359 pDstRates
->abyRates
[uRateCnt
++] = pSrcRates
->abyRates
[uu
];