e1000e: cleanup PARENTHESIS_ALIGNMENT checkpatch checks
[linux/fpc-iii.git] / drivers / staging / vt6656 / mib.c
blobd4c7b0cc7ecd9826566c4f08f6dee74e2c08d0e9
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 "mac.h"
41 #include "tether.h"
42 #include "mib.h"
43 #include "wctl.h"
44 #include "baseband.h"
46 /*--------------------- Static Definitions -------------------------*/
47 static int msglevel =MSG_LEVEL_INFO;
48 /*--------------------- Static Classes ----------------------------*/
50 /*--------------------- Static Variables --------------------------*/
52 /*--------------------- Static Functions --------------------------*/
54 /*--------------------- Export Variables --------------------------*/
56 /*--------------------- Export Functions --------------------------*/
61 * Description: Clear All Statistic Counter
63 * Parameters:
64 * In:
65 * pStatistic - Pointer to Statistic Counter Data Structure
66 * Out:
67 * none
69 * Return Value: none
72 void STAvClearAllCounter (PSStatCounter pStatistic)
74 // set memory to zero
75 memset(pStatistic, 0, sizeof(SStatCounter));
80 * Description: Update Isr Statistic Counter
82 * Parameters:
83 * In:
84 * pStatistic - Pointer to Statistic Counter Data Structure
85 * wisr - Interrupt status
86 * Out:
87 * none
89 * Return Value: none
92 void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, BYTE byIsr0, BYTE byIsr1)
94 /**********************/
95 /* ABNORMAL interrupt */
96 /**********************/
97 // not any IMR bit invoke irq
98 if (byIsr0 == 0) {
99 pStatistic->ISRStat.dwIsrUnknown++;
100 return;
104 if (byIsr0 & ISR_ACTX) // ISR, bit0
105 pStatistic->ISRStat.dwIsrTx0OK++; // TXDMA0 successful
107 if (byIsr0 & ISR_BNTX) // ISR, bit2
108 pStatistic->ISRStat.dwIsrBeaconTxOK++; // BeaconTx successful
110 if (byIsr0 & ISR_RXDMA0) // ISR, bit3
111 pStatistic->ISRStat.dwIsrRx0OK++; // Rx0 successful
113 if (byIsr0 & ISR_TBTT) // ISR, bit4
114 pStatistic->ISRStat.dwIsrTBTTInt++; // TBTT successful
116 if (byIsr0 & ISR_SOFTTIMER) // ISR, bit6
117 pStatistic->ISRStat.dwIsrSTIMERInt++;
119 if (byIsr0 & ISR_WATCHDOG) // ISR, bit7
120 pStatistic->ISRStat.dwIsrWatchDog++;
123 if (byIsr1 & ISR_FETALERR) // ISR, bit8
124 pStatistic->ISRStat.dwIsrUnrecoverableError++;
126 if (byIsr1 & ISR_SOFTINT) // ISR, bit9
127 pStatistic->ISRStat.dwIsrSoftInterrupt++; // software interrupt
129 if (byIsr1 & ISR_MIBNEARFULL) // ISR, bit10
130 pStatistic->ISRStat.dwIsrMIBNearfull++;
132 if (byIsr1 & ISR_RXNOBUF) // ISR, bit11
133 pStatistic->ISRStat.dwIsrRxNoBuf++; // Rx No Buff
139 * Description: Update Rx Statistic Counter
141 * Parameters:
142 * In:
143 * pStatistic - Pointer to Statistic Counter Data Structure
144 * byRSR - Rx Status
145 * byNewRSR - Rx Status
146 * pbyBuffer - Rx Buffer
147 * cbFrameLength - Rx Length
148 * Out:
149 * none
151 * Return Value: none
154 void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
155 BYTE byRSR, BYTE byNewRSR,
156 BYTE byRxSts, BYTE byRxRate,
157 PBYTE pbyBuffer, unsigned int 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++;
166 pStatistic->ullRsrOK++;
168 if (cbFrameLength >= ETH_ALEN) {
169 /* update counters in case of successful transmission */
170 if (byRSR & RSR_ADDRBROAD) {
171 pStatistic->ullRxBroadcastFrames++;
172 pStatistic->ullRxBroadcastBytes +=
173 (unsigned long long) cbFrameLength;
175 else if (byRSR & RSR_ADDRMULTI) {
176 pStatistic->ullRxMulticastFrames++;
177 pStatistic->ullRxMulticastBytes +=
178 (unsigned long long) cbFrameLength;
180 else {
181 pStatistic->ullRxDirectedFrames++;
182 pStatistic->ullRxDirectedBytes +=
183 (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",
194 (signed int) pStatistic->CustomStat.ullRsr11M,
195 (signed int) pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
197 else if(byRxRate==11) {
198 pStatistic->CustomStat.ullRsr5M++;
199 if(byRSR & RSR_CRCOK) {
200 pStatistic->CustomStat.ullRsr5MCRCOk++;
202 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 5M: ALL[%d], OK[%d]:[%02x]\n",
203 (signed int) pStatistic->CustomStat.ullRsr5M,
204 (signed int) pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
206 else if(byRxRate==4) {
207 pStatistic->CustomStat.ullRsr2M++;
208 if(byRSR & RSR_CRCOK) {
209 pStatistic->CustomStat.ullRsr2MCRCOk++;
211 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 2M: ALL[%d], OK[%d]:[%02x]\n",
212 (signed int) pStatistic->CustomStat.ullRsr2M,
213 (signed int) pStatistic->CustomStat.ullRsr2MCRCOk, byRSR);
215 else if(byRxRate==2){
216 pStatistic->CustomStat.ullRsr1M++;
217 if(byRSR & RSR_CRCOK) {
218 pStatistic->CustomStat.ullRsr1MCRCOk++;
220 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 1M: ALL[%d], OK[%d]:[%02x]\n",
221 (signed int) pStatistic->CustomStat.ullRsr1M,
222 (signed int) pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
224 else if(byRxRate==12){
225 pStatistic->CustomStat.ullRsr6M++;
226 if(byRSR & RSR_CRCOK) {
227 pStatistic->CustomStat.ullRsr6MCRCOk++;
229 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 6M: ALL[%d], OK[%d]\n",
230 (signed int) pStatistic->CustomStat.ullRsr6M,
231 (signed int) pStatistic->CustomStat.ullRsr6MCRCOk);
233 else if(byRxRate==18){
234 pStatistic->CustomStat.ullRsr9M++;
235 if(byRSR & RSR_CRCOK) {
236 pStatistic->CustomStat.ullRsr9MCRCOk++;
238 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 9M: ALL[%d], OK[%d]\n",
239 (signed int) pStatistic->CustomStat.ullRsr9M,
240 (signed int) pStatistic->CustomStat.ullRsr9MCRCOk);
242 else if(byRxRate==24){
243 pStatistic->CustomStat.ullRsr12M++;
244 if(byRSR & RSR_CRCOK) {
245 pStatistic->CustomStat.ullRsr12MCRCOk++;
247 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "12M: ALL[%d], OK[%d]\n",
248 (signed int) pStatistic->CustomStat.ullRsr12M,
249 (signed int) pStatistic->CustomStat.ullRsr12MCRCOk);
251 else if(byRxRate==36){
252 pStatistic->CustomStat.ullRsr18M++;
253 if(byRSR & RSR_CRCOK) {
254 pStatistic->CustomStat.ullRsr18MCRCOk++;
256 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "18M: ALL[%d], OK[%d]\n",
257 (signed int) pStatistic->CustomStat.ullRsr18M,
258 (signed int) pStatistic->CustomStat.ullRsr18MCRCOk);
260 else if(byRxRate==48){
261 pStatistic->CustomStat.ullRsr24M++;
262 if(byRSR & RSR_CRCOK) {
263 pStatistic->CustomStat.ullRsr24MCRCOk++;
265 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "24M: ALL[%d], OK[%d]\n",
266 (signed int) pStatistic->CustomStat.ullRsr24M,
267 (signed int) pStatistic->CustomStat.ullRsr24MCRCOk);
269 else if(byRxRate==72){
270 pStatistic->CustomStat.ullRsr36M++;
271 if(byRSR & RSR_CRCOK) {
272 pStatistic->CustomStat.ullRsr36MCRCOk++;
274 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "36M: ALL[%d], OK[%d]\n",
275 (signed int) pStatistic->CustomStat.ullRsr36M,
276 (signed int) pStatistic->CustomStat.ullRsr36MCRCOk);
278 else if(byRxRate==96){
279 pStatistic->CustomStat.ullRsr48M++;
280 if(byRSR & RSR_CRCOK) {
281 pStatistic->CustomStat.ullRsr48MCRCOk++;
283 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "48M: ALL[%d], OK[%d]\n",
284 (signed int) pStatistic->CustomStat.ullRsr48M,
285 (signed int) pStatistic->CustomStat.ullRsr48MCRCOk);
287 else if(byRxRate==108){
288 pStatistic->CustomStat.ullRsr54M++;
289 if(byRSR & RSR_CRCOK) {
290 pStatistic->CustomStat.ullRsr54MCRCOk++;
292 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "54M: ALL[%d], OK[%d]\n",
293 (signed int) pStatistic->CustomStat.ullRsr54M,
294 (signed int) pStatistic->CustomStat.ullRsr54MCRCOk);
296 else {
297 DBG_PRT(MSG_LEVEL_DEBUG,
298 KERN_INFO "Unknown: Total[%d], CRCOK[%d]\n",
299 (signed int) pStatistic->dwRsrRxPacket+1,
300 (signed int)pStatistic->dwRsrCRCOk);
303 if (byRSR & RSR_BSSIDOK)
304 pStatistic->dwRsrBSSIDOk++;
306 if (byRSR & RSR_BCNSSIDOK)
307 pStatistic->dwRsrBCNSSIDOk++;
308 if (byRSR & RSR_IVLDLEN) //invalid len (> 2312 byte)
309 pStatistic->dwRsrLENErr++;
310 if (byRSR & RSR_IVLDTYP) //invalid packet type
311 pStatistic->dwRsrTYPErr++;
312 if ((byRSR & (RSR_IVLDTYP | RSR_IVLDLEN)) || !(byRSR & RSR_CRCOK))
313 pStatistic->dwRsrErr++;
315 if (byNewRSR & NEWRSR_DECRYPTOK)
316 pStatistic->dwNewRsrDECRYPTOK++;
317 if (byNewRSR & NEWRSR_CFPIND)
318 pStatistic->dwNewRsrCFP++;
319 if (byNewRSR & NEWRSR_HWUTSF)
320 pStatistic->dwNewRsrUTSF++;
321 if (byNewRSR & NEWRSR_BCNHITAID)
322 pStatistic->dwNewRsrHITAID++;
323 if (byNewRSR & NEWRSR_BCNHITAID0)
324 pStatistic->dwNewRsrHITAID0++;
326 // increase rx packet count
327 pStatistic->dwRsrRxPacket++;
328 pStatistic->dwRsrRxOctet += cbFrameLength;
331 if (IS_TYPE_DATA(pbyBuffer)) {
332 pStatistic->dwRsrRxData++;
333 } else if (IS_TYPE_MGMT(pbyBuffer)){
334 pStatistic->dwRsrRxManage++;
335 } else if (IS_TYPE_CONTROL(pbyBuffer)){
336 pStatistic->dwRsrRxControl++;
339 if (byRSR & RSR_ADDRBROAD)
340 pStatistic->dwRsrBroadcast++;
341 else if (byRSR & RSR_ADDRMULTI)
342 pStatistic->dwRsrMulticast++;
343 else
344 pStatistic->dwRsrDirected++;
346 if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
347 pStatistic->dwRsrRxFragment++;
349 if (cbFrameLength < ETH_ZLEN + 4) {
350 pStatistic->dwRsrRunt++;
351 } else if (cbFrameLength == ETH_ZLEN + 4) {
352 pStatistic->dwRsrRxFrmLen64++;
354 else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
355 pStatistic->dwRsrRxFrmLen65_127++;
357 else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
358 pStatistic->dwRsrRxFrmLen128_255++;
360 else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
361 pStatistic->dwRsrRxFrmLen256_511++;
363 else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023)) {
364 pStatistic->dwRsrRxFrmLen512_1023++;
365 } else if ((1024 <= cbFrameLength) &&
366 (cbFrameLength <= ETH_FRAME_LEN + 4)) {
367 pStatistic->dwRsrRxFrmLen1024_1518++;
368 } else if (cbFrameLength > ETH_FRAME_LEN + 4) {
369 pStatistic->dwRsrLong++;
374 * Description: Update Rx Statistic Counter and copy Rx buffer
376 * Parameters:
377 * In:
378 * pStatistic - Pointer to Statistic Counter Data Structure
379 * byRSR - Rx Status
380 * byNewRSR - Rx Status
381 * pbyBuffer - Rx Buffer
382 * cbFrameLength - Rx Length
383 * Out:
384 * none
386 * Return Value: none
390 void
391 STAvUpdateRDStatCounterEx (
392 PSStatCounter pStatistic,
393 BYTE byRSR,
394 BYTE byNewRSR,
395 BYTE byRxSts,
396 BYTE byRxRate,
397 PBYTE pbyBuffer,
398 unsigned int cbFrameLength
401 STAvUpdateRDStatCounter(
402 pStatistic,
403 byRSR,
404 byNewRSR,
405 byRxSts,
406 byRxRate,
407 pbyBuffer,
408 cbFrameLength
411 // rx length
412 pStatistic->dwCntRxFrmLength = cbFrameLength;
413 // rx pattern, we just see 10 bytes for sample
414 memcpy(pStatistic->abyCntRxPattern, (PBYTE)pbyBuffer, 10);
419 * Description: Update Tx Statistic Counter
421 * Parameters:
422 * In:
423 * pStatistic - Pointer to Statistic Counter Data Structure
424 * byTSR0 - Tx Status
425 * byTSR1 - Tx Status
426 * pbyBuffer - Tx Buffer
427 * cbFrameLength - Tx Length
428 * uIdx - Index of Tx DMA
429 * Out:
430 * none
432 * Return Value: none
435 void
436 STAvUpdateTDStatCounter (
437 PSStatCounter pStatistic,
438 BYTE byPktNum,
439 BYTE byRate,
440 BYTE byTSR
443 BYTE byRetyCnt;
444 // increase tx packet count
445 pStatistic->dwTsrTxPacket++;
447 byRetyCnt = (byTSR & 0xF0) >> 4;
448 if (byRetyCnt != 0) {
449 pStatistic->dwTsrRetry++;
450 pStatistic->dwTsrTotalRetry += byRetyCnt;
451 pStatistic->dwTxFail[byRate]+= byRetyCnt;
452 pStatistic->dwTxFail[MAX_RATE] += byRetyCnt;
454 if ( byRetyCnt == 0x1)
455 pStatistic->dwTsrOnceRetry++;
456 else
457 pStatistic->dwTsrMoreThanOnceRetry++;
459 if (byRetyCnt <= 8)
460 pStatistic->dwTxRetryCount[byRetyCnt-1]++;
463 if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
465 if (byRetyCnt < 2)
466 pStatistic->TxNoRetryOkCount ++;
467 else
468 pStatistic->TxRetryOkCount ++;
470 pStatistic->ullTsrOK++;
471 pStatistic->CustomStat.ullTsrAllOK++;
472 // update counters in case that successful transmit
473 pStatistic->dwTxOk[byRate]++;
474 pStatistic->dwTxOk[MAX_RATE]++;
476 if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_BROAD ) {
477 pStatistic->ullTxBroadcastFrames++;
478 pStatistic->ullTxBroadcastBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
479 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_MULTI ) {
480 pStatistic->ullTxMulticastFrames++;
481 pStatistic->ullTxMulticastBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
482 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_UNI ) {
483 pStatistic->ullTxDirectedFrames++;
484 pStatistic->ullTxDirectedBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
487 else {
489 pStatistic->TxFailCount ++;
491 pStatistic->dwTsrErr++;
492 if (byTSR & TSR_RETRYTMO)
493 pStatistic->dwTsrRetryTimeout++;
494 if (byTSR & TSR_TMO)
495 pStatistic->dwTsrTransmitTimeout++;
498 if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_BROAD ) {
499 pStatistic->dwTsrBroadcast++;
500 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_MULTI ) {
501 pStatistic->dwTsrMulticast++;
502 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_UNI ) {
503 pStatistic->dwTsrDirected++;
510 * Description: Update 802.11 mib counter
512 * Parameters:
513 * In:
514 * p802_11Counter - Pointer to 802.11 mib counter
515 * pStatistic - Pointer to Statistic Counter Data Structure
516 * dwCounter - hardware counter for 802.11 mib
517 * Out:
518 * none
520 * Return Value: none
523 void
524 STAvUpdate802_11Counter(
525 PSDot11Counters p802_11Counter,
526 PSStatCounter pStatistic,
527 BYTE byRTSSuccess,
528 BYTE byRTSFail,
529 BYTE byACKFail,
530 BYTE byFCSErr
533 //p802_11Counter->TransmittedFragmentCount
534 p802_11Counter->MulticastTransmittedFrameCount =
535 (unsigned long long) (pStatistic->dwTsrBroadcast +
536 pStatistic->dwTsrMulticast);
537 p802_11Counter->FailedCount = (unsigned long long) (pStatistic->dwTsrErr);
538 p802_11Counter->RetryCount = (unsigned long long) (pStatistic->dwTsrRetry);
539 p802_11Counter->MultipleRetryCount =
540 (unsigned long long) (pStatistic->dwTsrMoreThanOnceRetry);
541 //p802_11Counter->FrameDuplicateCount
542 p802_11Counter->RTSSuccessCount += (unsigned long long) byRTSSuccess;
543 p802_11Counter->RTSFailureCount += (unsigned long long) byRTSFail;
544 p802_11Counter->ACKFailureCount += (unsigned long long) byACKFail;
545 p802_11Counter->FCSErrorCount += (unsigned long long) byFCSErr;
546 //p802_11Counter->ReceivedFragmentCount
547 p802_11Counter->MulticastReceivedFrameCount =
548 (unsigned long long) (pStatistic->dwRsrBroadcast +
549 pStatistic->dwRsrMulticast);
553 * Description: Clear 802.11 mib counter
555 * Parameters:
556 * In:
557 * p802_11Counter - Pointer to 802.11 mib counter
558 * Out:
559 * none
561 * Return Value: none
564 void
565 STAvClear802_11Counter(PSDot11Counters p802_11Counter)
567 // set memory to zero
568 memset(p802_11Counter, 0, sizeof(SDot11Counters));
572 * Description: Clear 802.11 mib counter
574 * Parameters:
575 * In:
576 * pUsbCounter - Pointer to USB mib counter
577 * ntStatus - URB status
578 * Out:
579 * none
581 * Return Value: none
585 void STAvUpdateUSBCounter(PSUSBCounter pUsbCounter, int ntStatus)
588 // if ( ntStatus == USBD_STATUS_CRC ) {
589 pUsbCounter->dwCrc++;
590 // }