blob: 22071984346ec62684e67c60ee2f8850ecdf10ec [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
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.
9 *
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.
14 *
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.
18 *
19 * File: datarate.c
20 *
21 * Purpose: Handles the auto fallback & data rates functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: July 17, 2002
26 *
27 * 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.
31 *
32 * Revision History:
33 *
34 */
35
Forest Bond92b96792009-06-13 07:38:31 -040036#include "tmacro.h"
Forest Bond92b96792009-06-13 07:38:31 -040037#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040038#include "80211mgr.h"
Forest Bond92b96792009-06-13 07:38:31 -040039#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040040#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040041#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040042#include "baseband.h"
Forest Bond92b96792009-06-13 07:38:31 -040043#include "srom.h"
Forest Bond92b96792009-06-13 07:38:31 -040044#include "rf.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070045
Andres More84cf5fc2013-01-31 15:20:42 -050046/* static int msglevel = MSG_LEVEL_DEBUG; */
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +053047static int msglevel = MSG_LEVEL_INFO;
48const u8 acbyIERate[MAX_RATE] = {0x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18,
49 0x24, 0x30, 0x48, 0x60, 0x6C};
Forest Bond92b96792009-06-13 07:38:31 -040050
51#define AUTORATE_TXOK_CNT 0x0400
52#define AUTORATE_TXFAIL_CNT 0x0064
53#define AUTORATE_TIMEOUT 10
54
Andres More8611a292010-05-01 14:25:00 -030055void s_vResetCounter(PKnownNodeDB psNodeDBTable);
Forest Bond92b96792009-06-13 07:38:31 -040056
Andres More8611a292010-05-01 14:25:00 -030057void s_vResetCounter(PKnownNodeDB psNodeDBTable)
Forest Bond92b96792009-06-13 07:38:31 -040058{
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +053059 u8 ii;
Forest Bond92b96792009-06-13 07:38:31 -040060
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +053061 /* clear statistics counter for auto_rate */
62 for (ii = 0; ii <= MAX_RATE; ii++) {
63 psNodeDBTable->uTxOk[ii] = 0;
64 psNodeDBTable->uTxFail[ii] = 0;
65 }
Forest Bond92b96792009-06-13 07:38:31 -040066}
67
Forest Bond92b96792009-06-13 07:38:31 -040068/*+
69 *
70 * Routine Description:
71 * Rate fallback Algorithm Implementaion
72 *
73 * Parameters:
74 * In:
75 * pDevice - Pointer to the adapter
76 * psNodeDBTable - Pointer to Node Data Base
77 * Out:
78 * none
79 *
80 * Return Value: none
81 *
82-*/
83#define AUTORATE_TXCNT_THRESHOLD 20
84#define AUTORATE_INC_THRESHOLD 30
85
Forest Bond92b96792009-06-13 07:38:31 -040086/*+
87 *
88 * Description:
89 * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE
90 *
91 * Parameters:
92 * In:
Andres Moreb902fbf2013-02-25 20:32:51 -050093 * u8 - Rate value in SuppRates IE or ExtSuppRates IE
Forest Bond92b96792009-06-13 07:38:31 -040094 * Out:
95 * none
96 *
97 * Return Value: RateIdx
98 *
99-*/
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530100u16 RATEwGetRateIdx(u8 byRate)
Forest Bond92b96792009-06-13 07:38:31 -0400101{
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530102 u16 ii;
Forest Bond92b96792009-06-13 07:38:31 -0400103
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530104 /* erase BasicRate flag */
105 byRate = byRate & 0x7F;
Forest Bond92b96792009-06-13 07:38:31 -0400106
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530107 for (ii = 0; ii < MAX_RATE; ii++) {
108 if (acbyIERate[ii] == byRate)
109 return ii;
110 }
111 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400112}
113
114/*+
115 *
116 * Description:
117 * Parsing the highest basic & support rate in rate field of frame.
118 *
119 * Parameters:
120 * In:
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.
124 * Out:
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
129 *
130 * Return Value: none
131 *
132-*/
Malcolm Priestley45c73bb2013-01-17 23:17:21 +0000133
134void 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)
Forest Bond92b96792009-06-13 07:38:31 -0400138{
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530139 int ii;
Malcolm Priestley45c73bb2013-01-17 23:17:21 +0000140 u8 byHighSuppRate = 0, byRate = 0;
141 u16 wOldBasicRate = pDevice->wBasicRate;
142 u32 uRateLen;
Forest Bond92b96792009-06-13 07:38:31 -0400143
Malcolm Priestley45c73bb2013-01-17 23:17:21 +0000144 if (pItemRates == NULL)
145 return;
Forest Bond92b96792009-06-13 07:38:31 -0400146
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530147 *pwSuppRate = 0;
148 uRateLen = pItemRates->len;
Forest Bond92b96792009-06-13 07:38:31 -0400149
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530150 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;
154 } else {
155 if (uRateLen > WLAN_RATES_MAXLEN_11B)
156 uRateLen = WLAN_RATES_MAXLEN_11B;
157 }
Forest Bond92b96792009-06-13 07:38:31 -0400158
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530159 for (ii = 0; ii < uRateLen; ii++) {
160 byRate = (u8)(pItemRates->abyRates[ii]);
161 if (WLAN_MGMT_IS_BASICRATE(byRate) &&
162 (bUpdateBasicRate == true)) {
163 /*
164 * add to basic rate set, update pDevice->byTopCCKBasicRate and
165 * pDevice->byTopOFDMBasicRate
166 */
167 CARDbAddBasicRate((void *)pDevice, RATEwGetRateIdx(byRate));
168 DBG_PRT(MSG_LEVEL_DEBUG,
169 KERN_INFO"ParseMaxRate AddBasicRate: %d\n",
170 RATEwGetRateIdx(byRate));
171 }
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));
178 }
179 if ((pItemExtRates != NULL) && (pItemExtRates->byElementID == WLAN_EID_EXTSUPP_RATES) &&
180 (pDevice->byBBType != BB_TYPE_11B)) {
Forest Bond92b96792009-06-13 07:38:31 -0400181
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530182 unsigned int uExtRateLen = pItemExtRates->len;
Forest Bond92b96792009-06-13 07:38:31 -0400183
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530184 if (uExtRateLen > WLAN_RATES_MAXLEN)
185 uExtRateLen = WLAN_RATES_MAXLEN;
Forest Bond92b96792009-06-13 07:38:31 -0400186
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530187 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])) {
191 /*
192 * add to basic rate set, update pDevice->byTopCCKBasicRate and
193 * pDevice->byTopOFDMBasicRate
194 */
195 CARDbAddBasicRate((void *)pDevice, RATEwGetRateIdx(byRate));
196 DBG_PRT(MSG_LEVEL_DEBUG,
197 KERN_INFO"ParseMaxRate AddBasicRate: %d\n",
198 RATEwGetRateIdx(byRate));
199 }
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));
Andres More84cf5fc2013-01-31 15:20:42 -0500206
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530207 /* DBG_PRN_GRP09(("ParseMaxRate : HighSuppRate: %d, %X\n",
208 * RATEwGetRateIdx(byRate), byRate));
209 */
210 }
211 }
Forest Bond92b96792009-06-13 07:38:31 -0400212
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530213 if ((pDevice->byPacketType == PK_TYPE_11GB)
214 && CARDbIsOFDMinBasicRate((void *)pDevice)) {
215 pDevice->byPacketType = PK_TYPE_11GA;
216 }
Forest Bond92b96792009-06-13 07:38:31 -0400217
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530218 *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;
223 else
224 *pwMaxBasicRate = pDevice->byTopOFDMBasicRate;
225 if (wOldBasicRate != pDevice->wBasicRate)
226 CARDvSetRSPINF((void *)pDevice, pDevice->byBBType);
Forest Bond92b96792009-06-13 07:38:31 -0400227
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530228 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Exit ParseMaxRate\n");
Forest Bond92b96792009-06-13 07:38:31 -0400229}
230
Forest Bond92b96792009-06-13 07:38:31 -0400231/*+
232 *
233 * Routine Description:
234 * Rate fallback Algorithm Implementaion
235 *
236 * Parameters:
237 * In:
238 * pDevice - Pointer to the adapter
239 * psNodeDBTable - Pointer to Node Data Base
240 * Out:
241 * none
242 *
243 * Return Value: none
244 *
245-*/
246#define AUTORATE_TXCNT_THRESHOLD 20
247#define AUTORATE_INC_THRESHOLD 30
248
Malcolm Priestley45c73bb2013-01-17 23:17:21 +0000249void RATEvTxRateFallBack(struct vnt_private *pDevice,
250 PKnownNodeDB psNodeDBTable)
Forest Bond92b96792009-06-13 07:38:31 -0400251{
Malcolm Priestley45c73bb2013-01-17 23:17:21 +0000252 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
253 u16 wIdxDownRate = 0;
254 int ii;
Andres More4e9b5e22013-02-12 20:36:30 -0500255 int bAutoRate[MAX_RATE] = {true, true, true, true, false, false, true,
256 true, true, true, true, true};
Malcolm Priestley45c73bb2013-01-17 23:17:21 +0000257 u32 dwThroughputTbl[MAX_RATE] = {10, 20, 55, 110, 60, 90, 120, 180,
258 240, 360, 480, 540};
259 u32 dwThroughput = 0;
260 u16 wIdxUpRate = 0;
261 u32 dwTxDiff = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400262
Malcolm Priestley45c73bb2013-01-17 23:17:21 +0000263 if (pMgmt->eScanState != WMAC_NO_SCANNING)
264 return; /* Don't do Fallback when scanning Channel */
265
266 psNodeDBTable->uTimeCount++;
Forest Bond92b96792009-06-13 07:38:31 -0400267
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530268 if (psNodeDBTable->uTxFail[MAX_RATE] > psNodeDBTable->uTxOk[MAX_RATE])
269 dwTxDiff = psNodeDBTable->uTxFail[MAX_RATE] - psNodeDBTable->uTxOk[MAX_RATE];
Forest Bond92b96792009-06-13 07:38:31 -0400270
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530271 if ((psNodeDBTable->uTxOk[MAX_RATE] < AUTORATE_TXOK_CNT) &&
272 (dwTxDiff < AUTORATE_TXFAIL_CNT) &&
273 (psNodeDBTable->uTimeCount < AUTORATE_TIMEOUT)) {
274 return;
275 }
Forest Bond92b96792009-06-13 07:38:31 -0400276
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530277 if (psNodeDBTable->uTimeCount >= AUTORATE_TIMEOUT) {
278 psNodeDBTable->uTimeCount = 0;
279 }
Forest Bond92b96792009-06-13 07:38:31 -0400280
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530281 for (ii = 0; ii < MAX_RATE; ii++) {
282 if (psNodeDBTable->wSuppRate & (0x0001<<ii)) {
283 if (bAutoRate[ii] == true) {
284 wIdxUpRate = (u16) ii;
285 }
286 } else {
287 bAutoRate[ii] = false;
288 }
289 }
Forest Bond92b96792009-06-13 07:38:31 -0400290
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530291 for (ii = 0; ii <= psNodeDBTable->wTxDataRate; ii++) {
292 if ((psNodeDBTable->uTxOk[ii] != 0) ||
293 (psNodeDBTable->uTxFail[ii] != 0)) {
294 dwThroughputTbl[ii] *= psNodeDBTable->uTxOk[ii];
295 if (ii < RATE_11M) {
296 psNodeDBTable->uTxFail[ii] *= 4;
297 }
298 dwThroughputTbl[ii] /= (psNodeDBTable->uTxOk[ii] + psNodeDBTable->uTxFail[ii]);
299 }
300 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rate %d,Ok: %d, Fail:%d, Throughput:%d\n",
301 ii, (int)psNodeDBTable->uTxOk[ii], (int)psNodeDBTable->uTxFail[ii], (int)dwThroughputTbl[ii]);
302 }
303 dwThroughput = dwThroughputTbl[psNodeDBTable->wTxDataRate];
Forest Bond92b96792009-06-13 07:38:31 -0400304
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530305 wIdxDownRate = psNodeDBTable->wTxDataRate;
306 for (ii = psNodeDBTable->wTxDataRate; ii > 0;) {
307 ii--;
308 if ((dwThroughputTbl[ii] > dwThroughput) &&
309 (bAutoRate[ii] == true)) {
310 dwThroughput = dwThroughputTbl[ii];
311 wIdxDownRate = (u16) ii;
312 }
313 }
314 psNodeDBTable->wTxDataRate = wIdxDownRate;
315 if (psNodeDBTable->uTxOk[MAX_RATE]) {
316 if (psNodeDBTable->uTxOk[MAX_RATE] >
317 (psNodeDBTable->uTxFail[MAX_RATE] * 4)) {
318 psNodeDBTable->wTxDataRate = wIdxUpRate;
319 }
320 } else { /* adhoc, if uTxOk(total) == 0 & uTxFail(total) == 0 */
321 if (psNodeDBTable->uTxFail[MAX_RATE] == 0)
322 psNodeDBTable->wTxDataRate = wIdxUpRate;
323 }
Forest Bond92b96792009-06-13 07:38:31 -0400324
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530325 if (pDevice->byBBType == BB_TYPE_11A) {
326 if (psNodeDBTable->wTxDataRate <= RATE_11M)
327 psNodeDBTable->wTxDataRate = RATE_6M;
328 }
329 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]);
330 s_vResetCounter(psNodeDBTable);
331 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rate: %d, U:%d, D:%d\n", (int)psNodeDBTable->wTxDataRate, (int)wIdxUpRate, (int)wIdxDownRate);
332 return;
Forest Bond92b96792009-06-13 07:38:31 -0400333}
334
335/*+
336 *
337 * Description:
338 * This routine is used to assemble available Rate IE.
339 *
340 * Parameters:
341 * In:
342 * pDevice
343 * Out:
344 *
345 * Return Value: None
346 *
347-*/
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530348u8 RATEuSetIE(PWLAN_IE_SUPP_RATES pSrcRates, PWLAN_IE_SUPP_RATES pDstRates,
349 unsigned int uRateLen)
Forest Bond92b96792009-06-13 07:38:31 -0400350{
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530351 unsigned int ii, uu, uRateCnt = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400352
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530353 if ((pSrcRates == NULL) || (pDstRates == NULL))
354 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400355
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530356 if (pSrcRates->len == 0)
357 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400358
Nandini Hanumanthagowda3cef1a22013-10-24 00:20:11 +0530359 for (ii = 0; ii < uRateLen; ii++) {
360 for (uu = 0; uu < pSrcRates->len; uu++) {
361 if ((pSrcRates->abyRates[uu] & 0x7F) == acbyIERate[ii]) {
362 pDstRates->abyRates[uRateCnt++] = pSrcRates->abyRates[uu];
363 break;
364 }
365 }
366 }
367 return (u8)uRateCnt;
Forest Bond92b96792009-06-13 07:38:31 -0400368}