[ARM] pxa: Gumstix Verdex PCMCIA support
[linux-2.6/verdex.git] / drivers / staging / vt6656 / mib.c
blob910e610b7cc08a5d4f096c0302a4c80e166d5d67
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 --------------------------*/
62 * Description: Clear All Statistic Counter
64 * Parameters:
65 * In:
66 * pStatistic - Pointer to Statistic Counter Data Structure
67 * Out:
68 * none
70 * Return Value: none
73 void STAvClearAllCounter (PSStatCounter pStatistic)
75 // set memory to zero
76 memset(pStatistic, 0, sizeof(SStatCounter));
81 * Description: Update Isr Statistic Counter
83 * Parameters:
84 * In:
85 * pStatistic - Pointer to Statistic Counter Data Structure
86 * wisr - Interrupt status
87 * Out:
88 * none
90 * Return Value: none
93 void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, BYTE byIsr0, BYTE byIsr1)
95 /**********************/
96 /* ABNORMAL interrupt */
97 /**********************/
98 // not any IMR bit invoke irq
99 if (byIsr0 == 0) {
100 pStatistic->ISRStat.dwIsrUnknown++;
101 return;
105 if (byIsr0 & ISR_ACTX) // ISR, bit0
106 pStatistic->ISRStat.dwIsrTx0OK++; // TXDMA0 successful
108 if (byIsr0 & ISR_BNTX) // ISR, bit2
109 pStatistic->ISRStat.dwIsrBeaconTxOK++; // BeaconTx successful
111 if (byIsr0 & ISR_RXDMA0) // ISR, bit3
112 pStatistic->ISRStat.dwIsrRx0OK++; // Rx0 successful
114 if (byIsr0 & ISR_TBTT) // ISR, bit4
115 pStatistic->ISRStat.dwIsrTBTTInt++; // TBTT successful
117 if (byIsr0 & ISR_SOFTTIMER) // ISR, bit6
118 pStatistic->ISRStat.dwIsrSTIMERInt++;
120 if (byIsr0 & ISR_WATCHDOG) // ISR, bit7
121 pStatistic->ISRStat.dwIsrWatchDog++;
124 if (byIsr1 & ISR_FETALERR) // ISR, bit8
125 pStatistic->ISRStat.dwIsrUnrecoverableError++;
127 if (byIsr1 & ISR_SOFTINT) // ISR, bit9
128 pStatistic->ISRStat.dwIsrSoftInterrupt++; // software interrupt
130 if (byIsr1 & ISR_MIBNEARFULL) // ISR, bit10
131 pStatistic->ISRStat.dwIsrMIBNearfull++;
133 if (byIsr1 & ISR_RXNOBUF) // ISR, bit11
134 pStatistic->ISRStat.dwIsrRxNoBuf++; // Rx No Buff
140 * Description: Update Rx Statistic Counter
142 * Parameters:
143 * In:
144 * pStatistic - Pointer to Statistic Counter Data Structure
145 * byRSR - Rx Status
146 * byNewRSR - Rx Status
147 * pbyBuffer - Rx Buffer
148 * cbFrameLength - Rx Length
149 * Out:
150 * none
152 * Return Value: none
155 void STAvUpdateRDStatCounter (PSStatCounter pStatistic,
156 BYTE byRSR, BYTE byNewRSR, BYTE byRxSts, BYTE byRxRate,
157 PBYTE pbyBuffer, UINT cbFrameLength)
159 //need change
160 PS802_11Header pHeader = (PS802_11Header)pbyBuffer;
162 if (byRSR & RSR_ADDROK)
163 pStatistic->dwRsrADDROk++;
164 if (byRSR & RSR_CRCOK) {
165 pStatistic->dwRsrCRCOk++;
167 pStatistic->ullRsrOK++;
169 if (cbFrameLength >= U_ETHER_ADDR_LEN) {
170 // update counters in case that successful transmit
171 if (byRSR & RSR_ADDRBROAD) {
172 pStatistic->ullRxBroadcastFrames++;
173 pStatistic->ullRxBroadcastBytes += (ULONGLONG)cbFrameLength;
175 else if (byRSR & RSR_ADDRMULTI) {
176 pStatistic->ullRxMulticastFrames++;
177 pStatistic->ullRxMulticastBytes += (ULONGLONG)cbFrameLength;
179 else {
180 pStatistic->ullRxDirectedFrames++;
181 pStatistic->ullRxDirectedBytes += (ULONGLONG)cbFrameLength;
186 if(byRxRate==22) {
187 pStatistic->CustomStat.ullRsr11M++;
188 if(byRSR & RSR_CRCOK) {
189 pStatistic->CustomStat.ullRsr11MCRCOk++;
191 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"11M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr11M, (INT)pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
193 else if(byRxRate==11) {
194 pStatistic->CustomStat.ullRsr5M++;
195 if(byRSR & RSR_CRCOK) {
196 pStatistic->CustomStat.ullRsr5MCRCOk++;
198 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);
207 else if(byRxRate==2){
208 pStatistic->CustomStat.ullRsr1M++;
209 if(byRSR & RSR_CRCOK) {
210 pStatistic->CustomStat.ullRsr1MCRCOk++;
212 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 1M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr1M, (INT)pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
214 else if(byRxRate==12){
215 pStatistic->CustomStat.ullRsr6M++;
216 if(byRSR & RSR_CRCOK) {
217 pStatistic->CustomStat.ullRsr6MCRCOk++;
219 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 6M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr6M, (INT)pStatistic->CustomStat.ullRsr6MCRCOk);
221 else if(byRxRate==18){
222 pStatistic->CustomStat.ullRsr9M++;
223 if(byRSR & RSR_CRCOK) {
224 pStatistic->CustomStat.ullRsr9MCRCOk++;
226 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 9M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr9M, (INT)pStatistic->CustomStat.ullRsr9MCRCOk);
228 else if(byRxRate==24){
229 pStatistic->CustomStat.ullRsr12M++;
230 if(byRSR & RSR_CRCOK) {
231 pStatistic->CustomStat.ullRsr12MCRCOk++;
233 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"12M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr12M, (INT)pStatistic->CustomStat.ullRsr12MCRCOk);
235 else if(byRxRate==36){
236 pStatistic->CustomStat.ullRsr18M++;
237 if(byRSR & RSR_CRCOK) {
238 pStatistic->CustomStat.ullRsr18MCRCOk++;
240 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"18M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr18M, (INT)pStatistic->CustomStat.ullRsr18MCRCOk);
242 else if(byRxRate==48){
243 pStatistic->CustomStat.ullRsr24M++;
244 if(byRSR & RSR_CRCOK) {
245 pStatistic->CustomStat.ullRsr24MCRCOk++;
247 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"24M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr24M, (INT)pStatistic->CustomStat.ullRsr24MCRCOk);
249 else if(byRxRate==72){
250 pStatistic->CustomStat.ullRsr36M++;
251 if(byRSR & RSR_CRCOK) {
252 pStatistic->CustomStat.ullRsr36MCRCOk++;
254 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"36M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr36M, (INT)pStatistic->CustomStat.ullRsr36MCRCOk);
256 else if(byRxRate==96){
257 pStatistic->CustomStat.ullRsr48M++;
258 if(byRSR & RSR_CRCOK) {
259 pStatistic->CustomStat.ullRsr48MCRCOk++;
261 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"48M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr48M, (INT)pStatistic->CustomStat.ullRsr48MCRCOk);
263 else if(byRxRate==108){
264 pStatistic->CustomStat.ullRsr54M++;
265 if(byRSR & RSR_CRCOK) {
266 pStatistic->CustomStat.ullRsr54MCRCOk++;
268 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"54M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr54M, (INT)pStatistic->CustomStat.ullRsr54MCRCOk);
270 else {
271 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Unknown: Total[%d], CRCOK[%d]\n", (INT)pStatistic->dwRsrRxPacket+1, (INT)pStatistic->dwRsrCRCOk);
274 if (byRSR & RSR_BSSIDOK)
275 pStatistic->dwRsrBSSIDOk++;
277 if (byRSR & RSR_BCNSSIDOK)
278 pStatistic->dwRsrBCNSSIDOk++;
279 if (byRSR & RSR_IVLDLEN) //invalid len (> 2312 byte)
280 pStatistic->dwRsrLENErr++;
281 if (byRSR & RSR_IVLDTYP) //invalid packet type
282 pStatistic->dwRsrTYPErr++;
283 if ((byRSR & (RSR_IVLDTYP | RSR_IVLDLEN)) || !(byRSR & RSR_CRCOK))
284 pStatistic->dwRsrErr++;
286 if (byNewRSR & NEWRSR_DECRYPTOK)
287 pStatistic->dwNewRsrDECRYPTOK++;
288 if (byNewRSR & NEWRSR_CFPIND)
289 pStatistic->dwNewRsrCFP++;
290 if (byNewRSR & NEWRSR_HWUTSF)
291 pStatistic->dwNewRsrUTSF++;
292 if (byNewRSR & NEWRSR_BCNHITAID)
293 pStatistic->dwNewRsrHITAID++;
294 if (byNewRSR & NEWRSR_BCNHITAID0)
295 pStatistic->dwNewRsrHITAID0++;
297 // increase rx packet count
298 pStatistic->dwRsrRxPacket++;
299 pStatistic->dwRsrRxOctet += cbFrameLength;
302 if (IS_TYPE_DATA(pbyBuffer)) {
303 pStatistic->dwRsrRxData++;
304 } else if (IS_TYPE_MGMT(pbyBuffer)){
305 pStatistic->dwRsrRxManage++;
306 } else if (IS_TYPE_CONTROL(pbyBuffer)){
307 pStatistic->dwRsrRxControl++;
310 if (byRSR & RSR_ADDRBROAD)
311 pStatistic->dwRsrBroadcast++;
312 else if (byRSR & RSR_ADDRMULTI)
313 pStatistic->dwRsrMulticast++;
314 else
315 pStatistic->dwRsrDirected++;
317 if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
318 pStatistic->dwRsrRxFragment++;
320 if (cbFrameLength < MIN_PACKET_LEN + 4) {
321 pStatistic->dwRsrRunt++;
323 else if (cbFrameLength == MIN_PACKET_LEN + 4) {
324 pStatistic->dwRsrRxFrmLen64++;
326 else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
327 pStatistic->dwRsrRxFrmLen65_127++;
329 else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
330 pStatistic->dwRsrRxFrmLen128_255++;
332 else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
333 pStatistic->dwRsrRxFrmLen256_511++;
335 else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023)) {
336 pStatistic->dwRsrRxFrmLen512_1023++;
338 else if ((1024 <= cbFrameLength) && (cbFrameLength <= MAX_PACKET_LEN + 4)) {
339 pStatistic->dwRsrRxFrmLen1024_1518++;
340 } else if (cbFrameLength > MAX_PACKET_LEN + 4) {
341 pStatistic->dwRsrLong++;
349 * Description: Update Rx Statistic Counter and copy Rx buffer
351 * Parameters:
352 * In:
353 * pStatistic - Pointer to Statistic Counter Data Structure
354 * byRSR - Rx Status
355 * byNewRSR - Rx Status
356 * pbyBuffer - Rx Buffer
357 * cbFrameLength - Rx Length
358 * Out:
359 * none
361 * Return Value: none
365 void
366 STAvUpdateRDStatCounterEx (
367 PSStatCounter pStatistic,
368 BYTE byRSR,
369 BYTE byNewRSR,
370 BYTE byRxSts,
371 BYTE byRxRate,
372 PBYTE pbyBuffer,
373 UINT cbFrameLength
376 STAvUpdateRDStatCounter(
377 pStatistic,
378 byRSR,
379 byNewRSR,
380 byRxSts,
381 byRxRate,
382 pbyBuffer,
383 cbFrameLength
386 // rx length
387 pStatistic->dwCntRxFrmLength = cbFrameLength;
388 // rx pattern, we just see 10 bytes for sample
389 memcpy(pStatistic->abyCntRxPattern, (PBYTE)pbyBuffer, 10);
394 * Description: Update Tx Statistic Counter
396 * Parameters:
397 * In:
398 * pStatistic - Pointer to Statistic Counter Data Structure
399 * byTSR0 - Tx Status
400 * byTSR1 - Tx Status
401 * pbyBuffer - Tx Buffer
402 * cbFrameLength - Tx Length
403 * uIdx - Index of Tx DMA
404 * Out:
405 * none
407 * Return Value: none
410 void
411 STAvUpdateTDStatCounter (
412 PSStatCounter pStatistic,
413 BYTE byPktNum,
414 BYTE byRate,
415 BYTE byTSR
418 BYTE byRetyCnt;
419 // increase tx packet count
420 pStatistic->dwTsrTxPacket++;
422 byRetyCnt = (byTSR & 0xF0) >> 4;
423 if (byRetyCnt != 0) {
424 pStatistic->dwTsrRetry++;
425 pStatistic->dwTsrTotalRetry += byRetyCnt;
426 pStatistic->dwTxFail[byRate]+= byRetyCnt;
427 pStatistic->dwTxFail[MAX_RATE] += byRetyCnt;
429 if ( byRetyCnt == 0x1)
430 pStatistic->dwTsrOnceRetry++;
431 else
432 pStatistic->dwTsrMoreThanOnceRetry++;
434 if (byRetyCnt <= 8)
435 pStatistic->dwTxRetryCount[byRetyCnt-1]++;
438 if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
440 #ifdef Calcu_LinkQual
441 if (byRetyCnt < 2)
442 pStatistic->TxNoRetryOkCount ++;
443 else
444 pStatistic->TxRetryOkCount ++;
445 #endif
447 pStatistic->ullTsrOK++;
448 pStatistic->CustomStat.ullTsrAllOK++;
449 // update counters in case that successful transmit
450 pStatistic->dwTxOk[byRate]++;
451 pStatistic->dwTxOk[MAX_RATE]++;
453 if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_BROAD ) {
454 pStatistic->ullTxBroadcastFrames++;
455 pStatistic->ullTxBroadcastBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
456 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_MULTI ) {
457 pStatistic->ullTxMulticastFrames++;
458 pStatistic->ullTxMulticastBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
459 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_UNI ) {
460 pStatistic->ullTxDirectedFrames++;
461 pStatistic->ullTxDirectedBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
464 else {
466 #ifdef Calcu_LinkQual
467 pStatistic->TxFailCount ++;
468 #endif
470 pStatistic->dwTsrErr++;
471 if (byTSR & TSR_RETRYTMO)
472 pStatistic->dwTsrRetryTimeout++;
473 if (byTSR & TSR_TMO)
474 pStatistic->dwTsrTransmitTimeout++;
477 if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_BROAD ) {
478 pStatistic->dwTsrBroadcast++;
479 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_MULTI ) {
480 pStatistic->dwTsrMulticast++;
481 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_UNI ) {
482 pStatistic->dwTsrDirected++;
489 * Description: Update 802.11 mib counter
491 * Parameters:
492 * In:
493 * p802_11Counter - Pointer to 802.11 mib counter
494 * pStatistic - Pointer to Statistic Counter Data Structure
495 * dwCounter - hardware counter for 802.11 mib
496 * Out:
497 * none
499 * Return Value: none
502 void
503 STAvUpdate802_11Counter(
504 PSDot11Counters p802_11Counter,
505 PSStatCounter pStatistic,
506 BYTE byRTSSuccess,
507 BYTE byRTSFail,
508 BYTE byACKFail,
509 BYTE byFCSErr
512 //p802_11Counter->TransmittedFragmentCount
513 p802_11Counter->MulticastTransmittedFrameCount = (ULONGLONG) (pStatistic->dwTsrBroadcast +
514 pStatistic->dwTsrMulticast);
515 p802_11Counter->FailedCount = (ULONGLONG) (pStatistic->dwTsrErr);
516 p802_11Counter->RetryCount = (ULONGLONG) (pStatistic->dwTsrRetry);
517 p802_11Counter->MultipleRetryCount = (ULONGLONG) (pStatistic->dwTsrMoreThanOnceRetry);
518 //p802_11Counter->FrameDuplicateCount
519 p802_11Counter->RTSSuccessCount += (ULONGLONG) byRTSSuccess;
520 p802_11Counter->RTSFailureCount += (ULONGLONG) byRTSFail;
521 p802_11Counter->ACKFailureCount += (ULONGLONG) byACKFail;
522 p802_11Counter->FCSErrorCount += (ULONGLONG) byFCSErr;
523 //p802_11Counter->ReceivedFragmentCount
524 p802_11Counter->MulticastReceivedFrameCount = (ULONGLONG) (pStatistic->dwRsrBroadcast +
525 pStatistic->dwRsrMulticast);
529 * Description: Clear 802.11 mib counter
531 * Parameters:
532 * In:
533 * p802_11Counter - Pointer to 802.11 mib counter
534 * Out:
535 * none
537 * Return Value: none
540 void
541 STAvClear802_11Counter(PSDot11Counters p802_11Counter)
543 // set memory to zero
544 memset(p802_11Counter, 0, sizeof(SDot11Counters));
548 * Description: Clear 802.11 mib counter
550 * Parameters:
551 * In:
552 * pUsbCounter - Pointer to USB mib counter
553 * ntStatus - URB status
554 * Out:
555 * none
557 * Return Value: none
561 void
562 STAvUpdateUSBCounter(PSUSBCounter pUsbCounter,
563 NTSTATUS ntStatus
567 // if ( ntStatus == USBD_STATUS_CRC ) {
568 pUsbCounter->dwCrc++;
569 // }