]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/vt6656/mib.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[karo-tx-linux.git] / drivers / staging / vt6656 / mib.c
1 /*
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: mib.c
20  *
21  * Purpose: Implement MIB Data Structure
22  *
23  * Author: Tevin Chen
24  *
25  * Date: May 21, 1996
26  *
27  * Functions:
28  *      STAvUpdateIstStatCounter - Update ISR statistic counter
29  *      STAvUpdateRDStatCounter - Update Rx statistic counter
30  *      STAvUpdateTDStatCounter - Update Tx statistic counter
31  *      STAvUpdateTDStatCounterEx - Update Tx statistic counter and copy tx data
32  *      STAvUpdate802_11Counter - Update 802.11 mib counter
33  *
34  * Revision History:
35  *
36  */
37
38 #include "mac.h"
39 #include "tether.h"
40 #include "mib.h"
41 #include "wctl.h"
42 #include "baseband.h"
43
44 static int          msglevel                =MSG_LEVEL_INFO;
45
46 /*
47  * Description: Update Isr Statistic Counter
48  *
49  * Parameters:
50  *  In:
51  *      pStatistic  - Pointer to Statistic Counter Data Structure
52  *      wisr        - Interrupt status
53  *  Out:
54  *      none
55  *
56  * Return Value: none
57  *
58  */
59 void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, u8 byIsr0, u8 byIsr1)
60 {
61     /**********************/
62     /* ABNORMAL interrupt */
63     /**********************/
64     // not any IMR bit invoke irq
65     if (byIsr0 == 0) {
66         pStatistic->ISRStat.dwIsrUnknown++;
67         return;
68     }
69
70     if (byIsr0 & ISR_ACTX)              // ISR, bit0
71         pStatistic->ISRStat.dwIsrTx0OK++;           // TXDMA0 successful
72
73     if (byIsr0 & ISR_BNTX)              // ISR, bit2
74         pStatistic->ISRStat.dwIsrBeaconTxOK++;      // BeaconTx successful
75
76     if (byIsr0 & ISR_RXDMA0)            // ISR, bit3
77         pStatistic->ISRStat.dwIsrRx0OK++;           // Rx0 successful
78
79     if (byIsr0 & ISR_TBTT)              // ISR, bit4
80         pStatistic->ISRStat.dwIsrTBTTInt++;         // TBTT successful
81
82     if (byIsr0 & ISR_SOFTTIMER)         // ISR, bit6
83         pStatistic->ISRStat.dwIsrSTIMERInt++;
84
85     if (byIsr0 & ISR_WATCHDOG)          // ISR, bit7
86         pStatistic->ISRStat.dwIsrWatchDog++;
87
88     if (byIsr1 & ISR_FETALERR)              // ISR, bit8
89         pStatistic->ISRStat.dwIsrUnrecoverableError++;
90
91     if (byIsr1 & ISR_SOFTINT)               // ISR, bit9
92         pStatistic->ISRStat.dwIsrSoftInterrupt++;       // software interrupt
93
94     if (byIsr1 & ISR_MIBNEARFULL)           // ISR, bit10
95         pStatistic->ISRStat.dwIsrMIBNearfull++;
96
97     if (byIsr1 & ISR_RXNOBUF)               // ISR, bit11
98         pStatistic->ISRStat.dwIsrRxNoBuf++;             // Rx No Buff
99
100 }
101
102 /*
103  * Description: Update Rx Statistic Counter
104  *
105  * Parameters:
106  *  In:
107  *      pStatistic      - Pointer to Statistic Counter Data Structure
108  *      byRSR           - Rx Status
109  *      byNewRSR        - Rx Status
110  *      pbyBuffer       - Rx Buffer
111  *      cbFrameLength   - Rx Length
112  *  Out:
113  *      none
114  *
115  * Return Value: none
116  *
117  */
118 void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
119                              u8 byRSR, u8 byNewRSR,
120                              u8 byRxSts, u8 byRxRate,
121                              u8 * pbyBuffer, unsigned int cbFrameLength)
122 {
123         /* need change */
124         struct ieee80211_hdr *pHeader = (struct ieee80211_hdr *)pbyBuffer;
125
126         if (byRSR & RSR_ADDROK)
127                 pStatistic->dwRsrADDROk++;
128         if (byRSR & RSR_CRCOK) {
129                 pStatistic->dwRsrCRCOk++;
130                 pStatistic->ullRsrOK++;
131
132                 if (cbFrameLength >= ETH_ALEN) {
133                         /* update counters in case of successful transmission */
134             if (byRSR & RSR_ADDRBROAD) {
135                 pStatistic->ullRxBroadcastFrames++;
136                 pStatistic->ullRxBroadcastBytes +=
137                   (unsigned long long) cbFrameLength;
138             }
139             else if (byRSR & RSR_ADDRMULTI) {
140                 pStatistic->ullRxMulticastFrames++;
141                 pStatistic->ullRxMulticastBytes +=
142                   (unsigned long long) cbFrameLength;
143             }
144             else {
145                 pStatistic->ullRxDirectedFrames++;
146                 pStatistic->ullRxDirectedBytes +=
147                   (unsigned long long) cbFrameLength;
148             }
149         }
150     }
151
152     if(byRxRate==22) {
153         pStatistic->CustomStat.ullRsr11M++;
154         if(byRSR & RSR_CRCOK) {
155             pStatistic->CustomStat.ullRsr11MCRCOk++;
156         }
157         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "11M: ALL[%d], OK[%d]:[%02x]\n",
158                 (signed int) pStatistic->CustomStat.ullRsr11M,
159                 (signed int) pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
160     }
161     else if(byRxRate==11) {
162         pStatistic->CustomStat.ullRsr5M++;
163         if(byRSR & RSR_CRCOK) {
164             pStatistic->CustomStat.ullRsr5MCRCOk++;
165         }
166         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 5M: ALL[%d], OK[%d]:[%02x]\n",
167                 (signed int) pStatistic->CustomStat.ullRsr5M,
168                 (signed int) pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
169     }
170     else if(byRxRate==4) {
171         pStatistic->CustomStat.ullRsr2M++;
172         if(byRSR & RSR_CRCOK) {
173             pStatistic->CustomStat.ullRsr2MCRCOk++;
174         }
175         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 2M: ALL[%d], OK[%d]:[%02x]\n",
176                 (signed int) pStatistic->CustomStat.ullRsr2M,
177                 (signed int) pStatistic->CustomStat.ullRsr2MCRCOk, byRSR);
178     }
179     else if(byRxRate==2){
180         pStatistic->CustomStat.ullRsr1M++;
181         if(byRSR & RSR_CRCOK) {
182             pStatistic->CustomStat.ullRsr1MCRCOk++;
183         }
184         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 1M: ALL[%d], OK[%d]:[%02x]\n",
185                 (signed int) pStatistic->CustomStat.ullRsr1M,
186                 (signed int) pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
187     }
188     else if(byRxRate==12){
189         pStatistic->CustomStat.ullRsr6M++;
190         if(byRSR & RSR_CRCOK) {
191             pStatistic->CustomStat.ullRsr6MCRCOk++;
192         }
193         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 6M: ALL[%d], OK[%d]\n",
194                 (signed int) pStatistic->CustomStat.ullRsr6M,
195                 (signed int) pStatistic->CustomStat.ullRsr6MCRCOk);
196     }
197     else if(byRxRate==18){
198         pStatistic->CustomStat.ullRsr9M++;
199         if(byRSR & RSR_CRCOK) {
200             pStatistic->CustomStat.ullRsr9MCRCOk++;
201         }
202         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 9M: ALL[%d], OK[%d]\n",
203                 (signed int) pStatistic->CustomStat.ullRsr9M,
204                 (signed int) pStatistic->CustomStat.ullRsr9MCRCOk);
205     }
206     else if(byRxRate==24){
207         pStatistic->CustomStat.ullRsr12M++;
208         if(byRSR & RSR_CRCOK) {
209             pStatistic->CustomStat.ullRsr12MCRCOk++;
210         }
211         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "12M: ALL[%d], OK[%d]\n",
212                 (signed int) pStatistic->CustomStat.ullRsr12M,
213                 (signed int) pStatistic->CustomStat.ullRsr12MCRCOk);
214     }
215     else if(byRxRate==36){
216         pStatistic->CustomStat.ullRsr18M++;
217         if(byRSR & RSR_CRCOK) {
218             pStatistic->CustomStat.ullRsr18MCRCOk++;
219         }
220         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "18M: ALL[%d], OK[%d]\n",
221                 (signed int) pStatistic->CustomStat.ullRsr18M,
222                 (signed int) pStatistic->CustomStat.ullRsr18MCRCOk);
223     }
224     else if(byRxRate==48){
225         pStatistic->CustomStat.ullRsr24M++;
226         if(byRSR & RSR_CRCOK) {
227             pStatistic->CustomStat.ullRsr24MCRCOk++;
228         }
229         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "24M: ALL[%d], OK[%d]\n",
230                 (signed int) pStatistic->CustomStat.ullRsr24M,
231                 (signed int) pStatistic->CustomStat.ullRsr24MCRCOk);
232     }
233     else if(byRxRate==72){
234         pStatistic->CustomStat.ullRsr36M++;
235         if(byRSR & RSR_CRCOK) {
236             pStatistic->CustomStat.ullRsr36MCRCOk++;
237         }
238         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "36M: ALL[%d], OK[%d]\n",
239                 (signed int) pStatistic->CustomStat.ullRsr36M,
240                 (signed int) pStatistic->CustomStat.ullRsr36MCRCOk);
241     }
242     else if(byRxRate==96){
243         pStatistic->CustomStat.ullRsr48M++;
244         if(byRSR & RSR_CRCOK) {
245             pStatistic->CustomStat.ullRsr48MCRCOk++;
246         }
247         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "48M: ALL[%d], OK[%d]\n",
248                 (signed int) pStatistic->CustomStat.ullRsr48M,
249                 (signed int) pStatistic->CustomStat.ullRsr48MCRCOk);
250     }
251     else if(byRxRate==108){
252         pStatistic->CustomStat.ullRsr54M++;
253         if(byRSR & RSR_CRCOK) {
254             pStatistic->CustomStat.ullRsr54MCRCOk++;
255         }
256         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "54M: ALL[%d], OK[%d]\n",
257                 (signed int) pStatistic->CustomStat.ullRsr54M,
258                 (signed int) pStatistic->CustomStat.ullRsr54MCRCOk);
259     }
260     else {
261             DBG_PRT(MSG_LEVEL_DEBUG,
262                     KERN_INFO "Unknown: Total[%d], CRCOK[%d]\n",
263                     (signed int) pStatistic->dwRsrRxPacket+1,
264                     (signed int)pStatistic->dwRsrCRCOk);
265     }
266
267     if (byRSR & RSR_BSSIDOK)
268         pStatistic->dwRsrBSSIDOk++;
269
270     if (byRSR & RSR_BCNSSIDOK)
271         pStatistic->dwRsrBCNSSIDOk++;
272     if (byRSR & RSR_IVLDLEN)  //invalid len (> 2312 byte)
273         pStatistic->dwRsrLENErr++;
274     if (byRSR & RSR_IVLDTYP)  //invalid packet type
275         pStatistic->dwRsrTYPErr++;
276     if ((byRSR & (RSR_IVLDTYP | RSR_IVLDLEN)) || !(byRSR & RSR_CRCOK))
277         pStatistic->dwRsrErr++;
278
279     if (byNewRSR & NEWRSR_DECRYPTOK)
280         pStatistic->dwNewRsrDECRYPTOK++;
281     if (byNewRSR & NEWRSR_CFPIND)
282         pStatistic->dwNewRsrCFP++;
283     if (byNewRSR & NEWRSR_HWUTSF)
284         pStatistic->dwNewRsrUTSF++;
285     if (byNewRSR & NEWRSR_BCNHITAID)
286         pStatistic->dwNewRsrHITAID++;
287     if (byNewRSR & NEWRSR_BCNHITAID0)
288         pStatistic->dwNewRsrHITAID0++;
289
290     // increase rx packet count
291     pStatistic->dwRsrRxPacket++;
292     pStatistic->dwRsrRxOctet += cbFrameLength;
293
294     if (IS_TYPE_DATA(pbyBuffer)) {
295         pStatistic->dwRsrRxData++;
296     } else if (IS_TYPE_MGMT(pbyBuffer)){
297         pStatistic->dwRsrRxManage++;
298     } else if (IS_TYPE_CONTROL(pbyBuffer)){
299         pStatistic->dwRsrRxControl++;
300     }
301
302     if (byRSR & RSR_ADDRBROAD)
303         pStatistic->dwRsrBroadcast++;
304     else if (byRSR & RSR_ADDRMULTI)
305         pStatistic->dwRsrMulticast++;
306     else
307         pStatistic->dwRsrDirected++;
308
309     if (WLAN_GET_FC_MOREFRAG(pHeader->frame_control))
310         pStatistic->dwRsrRxFragment++;
311
312     if (cbFrameLength < ETH_ZLEN + 4) {
313         pStatistic->dwRsrRunt++;
314     } else if (cbFrameLength == ETH_ZLEN + 4) {
315         pStatistic->dwRsrRxFrmLen64++;
316     }
317     else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
318         pStatistic->dwRsrRxFrmLen65_127++;
319     }
320     else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
321         pStatistic->dwRsrRxFrmLen128_255++;
322     }
323     else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
324         pStatistic->dwRsrRxFrmLen256_511++;
325     }
326     else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023)) {
327         pStatistic->dwRsrRxFrmLen512_1023++;
328     } else if ((1024 <= cbFrameLength) &&
329                (cbFrameLength <= ETH_FRAME_LEN + 4)) {
330         pStatistic->dwRsrRxFrmLen1024_1518++;
331     } else if (cbFrameLength > ETH_FRAME_LEN + 4) {
332         pStatistic->dwRsrLong++;
333     }
334 }
335
336 /*
337  * Description: Update Tx Statistic Counter
338  *
339  * Parameters:
340  *  In:
341  *      pStatistic      - Pointer to Statistic Counter Data Structure
342  *      byTSR0          - Tx Status
343  *      byTSR1          - Tx Status
344  *      pbyBuffer       - Tx Buffer
345  *      cbFrameLength   - Tx Length
346  *      uIdx            - Index of Tx DMA
347  *  Out:
348  *      none
349  *
350  * Return Value: none
351  *
352  */
353 void
354 STAvUpdateTDStatCounter (
355     PSStatCounter   pStatistic,
356     u8            byPktNum,
357     u8            byRate,
358     u8            byTSR
359     )
360 {
361     u8    byRetyCnt;
362     // increase tx packet count
363     pStatistic->dwTsrTxPacket++;
364
365     byRetyCnt = (byTSR & 0xF0) >> 4;
366     if (byRetyCnt != 0) {
367         pStatistic->dwTsrRetry++;
368         pStatistic->dwTsrTotalRetry += byRetyCnt;
369         pStatistic->dwTxFail[byRate]+= byRetyCnt;
370         pStatistic->dwTxFail[MAX_RATE] += byRetyCnt;
371
372         if ( byRetyCnt == 0x1)
373             pStatistic->dwTsrOnceRetry++;
374         else
375             pStatistic->dwTsrMoreThanOnceRetry++;
376
377         if (byRetyCnt <= 8)
378             pStatistic->dwTxRetryCount[byRetyCnt-1]++;
379
380     }
381     if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
382
383    if (byRetyCnt < 2)
384         pStatistic->TxNoRetryOkCount ++;
385    else
386         pStatistic->TxRetryOkCount ++;
387
388         pStatistic->ullTsrOK++;
389         pStatistic->CustomStat.ullTsrAllOK++;
390         // update counters in case that successful transmit
391         pStatistic->dwTxOk[byRate]++;
392         pStatistic->dwTxOk[MAX_RATE]++;
393
394         if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_BROAD )  {
395             pStatistic->ullTxBroadcastFrames++;
396             pStatistic->ullTxBroadcastBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
397         } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_MULTI ) {
398             pStatistic->ullTxMulticastFrames++;
399             pStatistic->ullTxMulticastBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
400         } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_UNI ) {
401             pStatistic->ullTxDirectedFrames++;
402             pStatistic->ullTxDirectedBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
403         }
404     }
405     else {
406
407         pStatistic->TxFailCount ++;
408
409         pStatistic->dwTsrErr++;
410         if (byTSR & TSR_RETRYTMO)
411             pStatistic->dwTsrRetryTimeout++;
412         if (byTSR & TSR_TMO)
413             pStatistic->dwTsrTransmitTimeout++;
414     }
415
416     if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_BROAD )  {
417         pStatistic->dwTsrBroadcast++;
418     } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_MULTI ) {
419         pStatistic->dwTsrMulticast++;
420     } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_UNI ) {
421         pStatistic->dwTsrDirected++;
422     }
423 }
424
425 /*
426  * Description: Update 802.11 mib counter
427  *
428  * Parameters:
429  *  In:
430  *      p802_11Counter  - Pointer to 802.11 mib counter
431  *      pStatistic      - Pointer to Statistic Counter Data Structure
432  *      dwCounter       - hardware counter for 802.11 mib
433  *  Out:
434  *      none
435  *
436  * Return Value: none
437  *
438  */
439 void
440 STAvUpdate802_11Counter(
441     PSDot11Counters         p802_11Counter,
442     PSStatCounter           pStatistic,
443     u8                    byRTSSuccess,
444     u8                    byRTSFail,
445     u8                    byACKFail,
446     u8                    byFCSErr
447     )
448 {
449     //p802_11Counter->TransmittedFragmentCount
450     p802_11Counter->MulticastTransmittedFrameCount =
451       (unsigned long long) (pStatistic->dwTsrBroadcast +
452                             pStatistic->dwTsrMulticast);
453     p802_11Counter->FailedCount = (unsigned long long) (pStatistic->dwTsrErr);
454     p802_11Counter->RetryCount = (unsigned long long) (pStatistic->dwTsrRetry);
455     p802_11Counter->MultipleRetryCount =
456       (unsigned long long) (pStatistic->dwTsrMoreThanOnceRetry);
457     //p802_11Counter->FrameDuplicateCount
458     p802_11Counter->RTSSuccessCount += (unsigned long long) byRTSSuccess;
459     p802_11Counter->RTSFailureCount += (unsigned long long) byRTSFail;
460     p802_11Counter->ACKFailureCount += (unsigned long long) byACKFail;
461     p802_11Counter->FCSErrorCount +=   (unsigned long long) byFCSErr;
462     //p802_11Counter->ReceivedFragmentCount
463     p802_11Counter->MulticastReceivedFrameCount =
464       (unsigned long long) (pStatistic->dwRsrBroadcast +
465                             pStatistic->dwRsrMulticast);
466 }
467
468 /*
469  * Description: Clear 802.11 mib counter
470  *
471  * Parameters:
472  *  In:
473  *      pUsbCounter  - Pointer to USB mib counter
474  *      ntStatus - URB status
475  *  Out:
476  *      none
477  *
478  * Return Value: none
479  *
480  */
481
482 void STAvUpdateUSBCounter(PSUSBCounter pUsbCounter, int ntStatus)
483 {
484
485 //    if ( ntStatus == USBD_STATUS_CRC ) {
486         pUsbCounter->dwCrc++;
487 //    }
488
489 }