fix a kmap leak in virtio_console
[linux/fpc-iii.git] / drivers / staging / vt6655 / mib.c
blob6a59652052b652f1d558f88fad1f152967e7922e
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
19 * File: mib.c
21 * Purpose: Implement MIB Data Structure
23 * Author: Tevin Chen
25 * Date: May 21, 1996
27 * Functions:
28 * STAvClearAllCounter - Clear All MIB Counter
29 * STAvUpdateIstStatCounter - Update ISR statistic counter
30 * STAvUpdateRDStatCounter - Update Rx statistic counter
31 * STAvUpdateRDStatCounterEx - Update Rx statistic counter and copy rcv data
32 * STAvUpdateTDStatCounter - Update Tx statistic counter
33 * STAvUpdateTDStatCounterEx - Update Tx statistic counter and copy tx data
34 * STAvUpdate802_11Counter - Update 802.11 mib counter
36 * Revision History:
40 #include "upc.h"
41 #include "mac.h"
42 #include "tether.h"
43 #include "mib.h"
44 #include "wctl.h"
45 #include "baseband.h"
47 /*--------------------- Static Definitions -------------------------*/
48 static int msglevel = MSG_LEVEL_INFO;
49 /*--------------------- Static Classes ----------------------------*/
51 /*--------------------- Static Variables --------------------------*/
53 /*--------------------- Static Functions --------------------------*/
55 /*--------------------- Export Variables --------------------------*/
57 /*--------------------- Export Functions --------------------------*/
60 * Description: Clear All Statistic Counter
62 * Parameters:
63 * In:
64 * pStatistic - Pointer to Statistic Counter Data Structure
65 * Out:
66 * none
68 * Return Value: none
71 void STAvClearAllCounter(PSStatCounter pStatistic)
73 // set memory to zero
74 memset(pStatistic, 0, sizeof(SStatCounter));
78 * Description: Update Isr Statistic Counter
80 * Parameters:
81 * In:
82 * pStatistic - Pointer to Statistic Counter Data Structure
83 * wisr - Interrupt status
84 * Out:
85 * none
87 * Return Value: none
90 void STAvUpdateIsrStatCounter(PSStatCounter pStatistic, unsigned long dwIsr)
92 /**********************/
93 /* ABNORMAL interrupt */
94 /**********************/
95 // not any IMR bit invoke irq
97 if (dwIsr == 0) {
98 pStatistic->ISRStat.dwIsrUnknown++;
99 return;
102 //Added by Kyle
103 if (dwIsr & ISR_TXDMA0) // ISR, bit0
104 pStatistic->ISRStat.dwIsrTx0OK++; // TXDMA0 successful
106 if (dwIsr & ISR_AC0DMA) // ISR, bit1
107 pStatistic->ISRStat.dwIsrAC0TxOK++; // AC0DMA successful
109 if (dwIsr & ISR_BNTX) // ISR, bit2
110 pStatistic->ISRStat.dwIsrBeaconTxOK++; // BeaconTx successful
112 if (dwIsr & ISR_RXDMA0) // ISR, bit3
113 pStatistic->ISRStat.dwIsrRx0OK++; // Rx0 successful
115 if (dwIsr & ISR_TBTT) // ISR, bit4
116 pStatistic->ISRStat.dwIsrTBTTInt++; // TBTT successful
118 if (dwIsr & ISR_SOFTTIMER) // ISR, bit6
119 pStatistic->ISRStat.dwIsrSTIMERInt++;
121 if (dwIsr & ISR_WATCHDOG) // ISR, bit7
122 pStatistic->ISRStat.dwIsrWatchDog++;
124 if (dwIsr & ISR_FETALERR) // ISR, bit8
125 pStatistic->ISRStat.dwIsrUnrecoverableError++;
127 if (dwIsr & ISR_SOFTINT) // ISR, bit9
128 pStatistic->ISRStat.dwIsrSoftInterrupt++; // software interrupt
130 if (dwIsr & ISR_MIBNEARFULL) // ISR, bit10
131 pStatistic->ISRStat.dwIsrMIBNearfull++;
133 if (dwIsr & ISR_RXNOBUF) // ISR, bit11
134 pStatistic->ISRStat.dwIsrRxNoBuf++; // Rx No Buff
136 if (dwIsr & ISR_RXDMA1) // ISR, bit12
137 pStatistic->ISRStat.dwIsrRx1OK++; // Rx1 successful
139 if (dwIsr & ISR_SOFTTIMER1) // ISR, bit21
140 pStatistic->ISRStat.dwIsrSTIMER1Int++;
144 * Description: Update Rx Statistic Counter
146 * Parameters:
147 * In:
148 * pStatistic - Pointer to Statistic Counter Data Structure
149 * byRSR - Rx Status
150 * byNewRSR - Rx Status
151 * pbyBuffer - Rx Buffer
152 * cbFrameLength - Rx Length
153 * Out:
154 * none
156 * Return Value: none
159 void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
160 unsigned char byRSR, unsigned char byNewRSR, unsigned char byRxRate,
161 unsigned char *pbyBuffer, unsigned int cbFrameLength)
163 //need change
164 PS802_11Header pHeader = (PS802_11Header)pbyBuffer;
166 if (byRSR & RSR_ADDROK)
167 pStatistic->dwRsrADDROk++;
168 if (byRSR & RSR_CRCOK) {
169 pStatistic->dwRsrCRCOk++;
171 pStatistic->ullRsrOK++;
173 if (cbFrameLength >= ETH_ALEN) {
174 // update counters in case of successful transmit
175 if (byRSR & RSR_ADDRBROAD) {
176 pStatistic->ullRxBroadcastFrames++;
177 pStatistic->ullRxBroadcastBytes += (unsigned long long) cbFrameLength;
178 } else if (byRSR & RSR_ADDRMULTI) {
179 pStatistic->ullRxMulticastFrames++;
180 pStatistic->ullRxMulticastBytes += (unsigned long long) cbFrameLength;
181 } else {
182 pStatistic->ullRxDirectedFrames++;
183 pStatistic->ullRxDirectedBytes += (unsigned long long) cbFrameLength;
188 if (byRxRate == 22) {
189 pStatistic->CustomStat.ullRsr11M++;
190 if (byRSR & RSR_CRCOK) {
191 pStatistic->CustomStat.ullRsr11MCRCOk++;
193 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "11M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr11M, (int)pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
194 } else if (byRxRate == 11) {
195 pStatistic->CustomStat.ullRsr5M++;
196 if (byRSR & RSR_CRCOK) {
197 pStatistic->CustomStat.ullRsr5MCRCOk++;
199 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 5M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr5M, (int)pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
200 } else if (byRxRate == 4) {
201 pStatistic->CustomStat.ullRsr2M++;
202 if (byRSR & RSR_CRCOK) {
203 pStatistic->CustomStat.ullRsr2MCRCOk++;
205 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 2M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr2M, (int)pStatistic->CustomStat.ullRsr2MCRCOk, byRSR);
206 } else if (byRxRate == 2) {
207 pStatistic->CustomStat.ullRsr1M++;
208 if (byRSR & RSR_CRCOK) {
209 pStatistic->CustomStat.ullRsr1MCRCOk++;
211 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 1M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr1M, (int)pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
212 } else if (byRxRate == 12) {
213 pStatistic->CustomStat.ullRsr6M++;
214 if (byRSR & RSR_CRCOK) {
215 pStatistic->CustomStat.ullRsr6MCRCOk++;
217 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 6M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr6M, (int)pStatistic->CustomStat.ullRsr6MCRCOk);
218 } else if (byRxRate == 18) {
219 pStatistic->CustomStat.ullRsr9M++;
220 if (byRSR & RSR_CRCOK) {
221 pStatistic->CustomStat.ullRsr9MCRCOk++;
223 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 9M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr9M, (int)pStatistic->CustomStat.ullRsr9MCRCOk);
224 } else if (byRxRate == 24) {
225 pStatistic->CustomStat.ullRsr12M++;
226 if (byRSR & RSR_CRCOK) {
227 pStatistic->CustomStat.ullRsr12MCRCOk++;
229 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "12M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr12M, (int)pStatistic->CustomStat.ullRsr12MCRCOk);
230 } else if (byRxRate == 36) {
231 pStatistic->CustomStat.ullRsr18M++;
232 if (byRSR & RSR_CRCOK) {
233 pStatistic->CustomStat.ullRsr18MCRCOk++;
235 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "18M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr18M, (int)pStatistic->CustomStat.ullRsr18MCRCOk);
236 } else if (byRxRate == 48) {
237 pStatistic->CustomStat.ullRsr24M++;
238 if (byRSR & RSR_CRCOK) {
239 pStatistic->CustomStat.ullRsr24MCRCOk++;
241 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "24M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr24M, (int)pStatistic->CustomStat.ullRsr24MCRCOk);
242 } else if (byRxRate == 72) {
243 pStatistic->CustomStat.ullRsr36M++;
244 if (byRSR & RSR_CRCOK) {
245 pStatistic->CustomStat.ullRsr36MCRCOk++;
247 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "36M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr36M, (int)pStatistic->CustomStat.ullRsr36MCRCOk);
248 } else if (byRxRate == 96) {
249 pStatistic->CustomStat.ullRsr48M++;
250 if (byRSR & RSR_CRCOK) {
251 pStatistic->CustomStat.ullRsr48MCRCOk++;
253 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "48M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr48M, (int)pStatistic->CustomStat.ullRsr48MCRCOk);
254 } else if (byRxRate == 108) {
255 pStatistic->CustomStat.ullRsr54M++;
256 if (byRSR & RSR_CRCOK) {
257 pStatistic->CustomStat.ullRsr54MCRCOk++;
259 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "54M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr54M, (int)pStatistic->CustomStat.ullRsr54MCRCOk);
260 } else {
261 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Unknown: Total[%d], CRCOK[%d]\n", (int)pStatistic->dwRsrRxPacket+1, (int)pStatistic->dwRsrCRCOk);
264 if (byRSR & RSR_BSSIDOK)
265 pStatistic->dwRsrBSSIDOk++;
267 if (byRSR & RSR_BCNSSIDOK)
268 pStatistic->dwRsrBCNSSIDOk++;
269 if (byRSR & RSR_IVLDLEN) //invalid len (> 2312 byte)
270 pStatistic->dwRsrLENErr++;
271 if (byRSR & RSR_IVLDTYP) //invalid packet type
272 pStatistic->dwRsrTYPErr++;
273 if (byRSR & (RSR_IVLDTYP | RSR_IVLDLEN))
274 pStatistic->dwRsrErr++;
276 if (byNewRSR & NEWRSR_DECRYPTOK)
277 pStatistic->dwNewRsrDECRYPTOK++;
278 if (byNewRSR & NEWRSR_CFPIND)
279 pStatistic->dwNewRsrCFP++;
280 if (byNewRSR & NEWRSR_HWUTSF)
281 pStatistic->dwNewRsrUTSF++;
282 if (byNewRSR & NEWRSR_BCNHITAID)
283 pStatistic->dwNewRsrHITAID++;
284 if (byNewRSR & NEWRSR_BCNHITAID0)
285 pStatistic->dwNewRsrHITAID0++;
287 // increase rx packet count
288 pStatistic->dwRsrRxPacket++;
289 pStatistic->dwRsrRxOctet += cbFrameLength;
291 if (IS_TYPE_DATA(pbyBuffer)) {
292 pStatistic->dwRsrRxData++;
293 } else if (IS_TYPE_MGMT(pbyBuffer)) {
294 pStatistic->dwRsrRxManage++;
295 } else if (IS_TYPE_CONTROL(pbyBuffer)) {
296 pStatistic->dwRsrRxControl++;
299 if (byRSR & RSR_ADDRBROAD)
300 pStatistic->dwRsrBroadcast++;
301 else if (byRSR & RSR_ADDRMULTI)
302 pStatistic->dwRsrMulticast++;
303 else
304 pStatistic->dwRsrDirected++;
306 if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
307 pStatistic->dwRsrRxFragment++;
309 if (cbFrameLength < ETH_ZLEN + 4) {
310 pStatistic->dwRsrRunt++;
311 } else if (cbFrameLength == ETH_ZLEN + 4) {
312 pStatistic->dwRsrRxFrmLen64++;
313 } else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
314 pStatistic->dwRsrRxFrmLen65_127++;
315 } else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
316 pStatistic->dwRsrRxFrmLen128_255++;
317 } else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
318 pStatistic->dwRsrRxFrmLen256_511++;
319 } else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023)) {
320 pStatistic->dwRsrRxFrmLen512_1023++;
321 } else if ((1024 <= cbFrameLength) && (cbFrameLength <= ETH_FRAME_LEN + 4)) {
322 pStatistic->dwRsrRxFrmLen1024_1518++;
323 } else if (cbFrameLength > ETH_FRAME_LEN + 4) {
324 pStatistic->dwRsrLong++;
329 * Description: Update Rx Statistic Counter and copy Rx buffer
331 * Parameters:
332 * In:
333 * pStatistic - Pointer to Statistic Counter Data Structure
334 * byRSR - Rx Status
335 * byNewRSR - Rx Status
336 * pbyBuffer - Rx Buffer
337 * cbFrameLength - Rx Length
338 * Out:
339 * none
341 * Return Value: none
345 void
346 STAvUpdateRDStatCounterEx(
347 PSStatCounter pStatistic,
348 unsigned char byRSR,
349 unsigned char byNewRSR,
350 unsigned char byRxRate,
351 unsigned char *pbyBuffer,
352 unsigned int cbFrameLength
355 STAvUpdateRDStatCounter(
356 pStatistic,
357 byRSR,
358 byNewRSR,
359 byRxRate,
360 pbyBuffer,
361 cbFrameLength
364 // rx length
365 pStatistic->dwCntRxFrmLength = cbFrameLength;
366 // rx pattern, we just see 10 bytes for sample
367 memcpy(pStatistic->abyCntRxPattern, (unsigned char *)pbyBuffer, 10);
371 * Description: Update Tx Statistic Counter
373 * Parameters:
374 * In:
375 * pStatistic - Pointer to Statistic Counter Data Structure
376 * byTSR0 - Tx Status
377 * byTSR1 - Tx Status
378 * pbyBuffer - Tx Buffer
379 * cbFrameLength - Tx Length
380 * uIdx - Index of Tx DMA
381 * Out:
382 * none
384 * Return Value: none
387 void
388 STAvUpdateTDStatCounter(
389 PSStatCounter pStatistic,
390 unsigned char byTSR0,
391 unsigned char byTSR1,
392 unsigned char *pbyBuffer,
393 unsigned int cbFrameLength,
394 unsigned int uIdx
397 PWLAN_80211HDR_A4 pHeader;
398 unsigned char *pbyDestAddr;
399 unsigned char byTSR0_NCR = byTSR0 & TSR0_NCR;
401 pHeader = (PWLAN_80211HDR_A4) pbyBuffer;
402 if (WLAN_GET_FC_TODS(pHeader->wFrameCtl) == 0) {
403 pbyDestAddr = &(pHeader->abyAddr1[0]);
404 } else {
405 pbyDestAddr = &(pHeader->abyAddr3[0]);
407 // increase tx packet count
408 pStatistic->dwTsrTxPacket[uIdx]++;
409 pStatistic->dwTsrTxOctet[uIdx] += cbFrameLength;
411 if (byTSR0_NCR != 0) {
412 pStatistic->dwTsrRetry[uIdx]++;
413 pStatistic->dwTsrTotalRetry[uIdx] += byTSR0_NCR;
415 if (byTSR0_NCR == 1)
416 pStatistic->dwTsrOnceRetry[uIdx]++;
417 else
418 pStatistic->dwTsrMoreThanOnceRetry[uIdx]++;
421 if ((byTSR1&(TSR1_TERR|TSR1_RETRYTMO|TSR1_TMO|ACK_DATA)) == 0) {
422 pStatistic->ullTsrOK[uIdx]++;
423 pStatistic->CustomStat.ullTsrAllOK =
424 (pStatistic->ullTsrOK[TYPE_AC0DMA] + pStatistic->ullTsrOK[TYPE_TXDMA0]);
425 // update counters in case that successful transmit
426 if (is_broadcast_ether_addr(pbyDestAddr)) {
427 pStatistic->ullTxBroadcastFrames[uIdx]++;
428 pStatistic->ullTxBroadcastBytes[uIdx] += (unsigned long long) cbFrameLength;
429 } else if (is_multicast_ether_addr(pbyDestAddr)) {
430 pStatistic->ullTxMulticastFrames[uIdx]++;
431 pStatistic->ullTxMulticastBytes[uIdx] += (unsigned long long) cbFrameLength;
432 } else {
433 pStatistic->ullTxDirectedFrames[uIdx]++;
434 pStatistic->ullTxDirectedBytes[uIdx] += (unsigned long long) cbFrameLength;
436 } else {
437 if (byTSR1 & TSR1_TERR)
438 pStatistic->dwTsrErr[uIdx]++;
439 if (byTSR1 & TSR1_RETRYTMO)
440 pStatistic->dwTsrRetryTimeout[uIdx]++;
441 if (byTSR1 & TSR1_TMO)
442 pStatistic->dwTsrTransmitTimeout[uIdx]++;
443 if (byTSR1 & ACK_DATA)
444 pStatistic->dwTsrACKData[uIdx]++;
447 if (is_broadcast_ether_addr(pbyDestAddr))
448 pStatistic->dwTsrBroadcast[uIdx]++;
449 else if (is_multicast_ether_addr(pbyDestAddr))
450 pStatistic->dwTsrMulticast[uIdx]++;
451 else
452 pStatistic->dwTsrDirected[uIdx]++;
456 * Description: Update Tx Statistic Counter and copy Tx buffer
458 * Parameters:
459 * In:
460 * pStatistic - Pointer to Statistic Counter Data Structure
461 * pbyBuffer - Tx Buffer
462 * cbFrameLength - Tx Length
463 * Out:
464 * none
466 * Return Value: none
469 void
470 STAvUpdateTDStatCounterEx(
471 PSStatCounter pStatistic,
472 unsigned char *pbyBuffer,
473 unsigned long cbFrameLength
476 unsigned int uPktLength;
478 uPktLength = (unsigned int)cbFrameLength;
480 // tx length
481 pStatistic->dwCntTxBufLength = uPktLength;
482 // tx pattern, we just see 16 bytes for sample
483 memcpy(pStatistic->abyCntTxPattern, pbyBuffer, 16);
487 * Description: Update 802.11 mib counter
489 * Parameters:
490 * In:
491 * p802_11Counter - Pointer to 802.11 mib counter
492 * pStatistic - Pointer to Statistic Counter Data Structure
493 * dwCounter - hardware counter for 802.11 mib
494 * Out:
495 * none
497 * Return Value: none
500 void
501 STAvUpdate802_11Counter(
502 PSDot11Counters p802_11Counter,
503 PSStatCounter pStatistic,
504 unsigned long dwCounter
507 //p802_11Counter->TransmittedFragmentCount
508 p802_11Counter->MulticastTransmittedFrameCount = (unsigned long long) (pStatistic->dwTsrBroadcast[TYPE_AC0DMA] +
509 pStatistic->dwTsrBroadcast[TYPE_TXDMA0] +
510 pStatistic->dwTsrMulticast[TYPE_AC0DMA] +
511 pStatistic->dwTsrMulticast[TYPE_TXDMA0]);
512 p802_11Counter->FailedCount = (unsigned long long) (pStatistic->dwTsrErr[TYPE_AC0DMA] + pStatistic->dwTsrErr[TYPE_TXDMA0]);
513 p802_11Counter->RetryCount = (unsigned long long) (pStatistic->dwTsrRetry[TYPE_AC0DMA] + pStatistic->dwTsrRetry[TYPE_TXDMA0]);
514 p802_11Counter->MultipleRetryCount = (unsigned long long) (pStatistic->dwTsrMoreThanOnceRetry[TYPE_AC0DMA] +
515 pStatistic->dwTsrMoreThanOnceRetry[TYPE_TXDMA0]);
516 //p802_11Counter->FrameDuplicateCount
517 p802_11Counter->RTSSuccessCount += (unsigned long long) (dwCounter & 0x000000ff);
518 p802_11Counter->RTSFailureCount += (unsigned long long) ((dwCounter & 0x0000ff00) >> 8);
519 p802_11Counter->ACKFailureCount += (unsigned long long) ((dwCounter & 0x00ff0000) >> 16);
520 p802_11Counter->FCSErrorCount += (unsigned long long) ((dwCounter & 0xff000000) >> 24);
521 //p802_11Counter->ReceivedFragmentCount
522 p802_11Counter->MulticastReceivedFrameCount = (unsigned long long) (pStatistic->dwRsrBroadcast +
523 pStatistic->dwRsrMulticast);
527 * Description: Clear 802.11 mib counter
529 * Parameters:
530 * In:
531 * p802_11Counter - Pointer to 802.11 mib counter
532 * Out:
533 * none
535 * Return Value: none
538 void
539 STAvClear802_11Counter(PSDot11Counters p802_11Counter)
541 // set memory to zero
542 memset(p802_11Counter, 0, sizeof(SDot11Counters));