x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / staging / vt6656 / mib.c
blob12333cdcbc6a0d22285615723d317dec42605a42
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 * 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
34 * Revision History:
38 #include "mac.h"
39 #include "tether.h"
40 #include "mib.h"
41 #include "wctl.h"
42 #include "baseband.h"
44 static int msglevel =MSG_LEVEL_INFO;
47 * Description: Update Isr Statistic Counter
49 * Parameters:
50 * In:
51 * pStatistic - Pointer to Statistic Counter Data Structure
52 * wisr - Interrupt status
53 * Out:
54 * none
56 * Return Value: none
59 void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, u8 byIsr0, u8 byIsr1)
61 /**********************/
62 /* ABNORMAL interrupt */
63 /**********************/
64 // not any IMR bit invoke irq
65 if (byIsr0 == 0) {
66 pStatistic->ISRStat.dwIsrUnknown++;
67 return;
70 if (byIsr0 & ISR_ACTX) // ISR, bit0
71 pStatistic->ISRStat.dwIsrTx0OK++; // TXDMA0 successful
73 if (byIsr0 & ISR_BNTX) // ISR, bit2
74 pStatistic->ISRStat.dwIsrBeaconTxOK++; // BeaconTx successful
76 if (byIsr0 & ISR_RXDMA0) // ISR, bit3
77 pStatistic->ISRStat.dwIsrRx0OK++; // Rx0 successful
79 if (byIsr0 & ISR_TBTT) // ISR, bit4
80 pStatistic->ISRStat.dwIsrTBTTInt++; // TBTT successful
82 if (byIsr0 & ISR_SOFTTIMER) // ISR, bit6
83 pStatistic->ISRStat.dwIsrSTIMERInt++;
85 if (byIsr0 & ISR_WATCHDOG) // ISR, bit7
86 pStatistic->ISRStat.dwIsrWatchDog++;
88 if (byIsr1 & ISR_FETALERR) // ISR, bit8
89 pStatistic->ISRStat.dwIsrUnrecoverableError++;
91 if (byIsr1 & ISR_SOFTINT) // ISR, bit9
92 pStatistic->ISRStat.dwIsrSoftInterrupt++; // software interrupt
94 if (byIsr1 & ISR_MIBNEARFULL) // ISR, bit10
95 pStatistic->ISRStat.dwIsrMIBNearfull++;
97 if (byIsr1 & ISR_RXNOBUF) // ISR, bit11
98 pStatistic->ISRStat.dwIsrRxNoBuf++; // Rx No Buff
103 * Description: Update Rx Statistic Counter
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
115 * Return Value: none
118 void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
119 u8 byRSR, u8 byNewRSR,
120 u8 byRxSts, u8 byRxRate,
121 u8 * pbyBuffer, unsigned int cbFrameLength)
123 /* need change */
124 struct ieee80211_hdr *pHeader = (struct ieee80211_hdr *)pbyBuffer;
126 if (byRSR & RSR_ADDROK)
127 pStatistic->dwRsrADDROk++;
128 if (byRSR & RSR_CRCOK) {
129 pStatistic->dwRsrCRCOk++;
130 pStatistic->ullRsrOK++;
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;
139 else if (byRSR & RSR_ADDRMULTI) {
140 pStatistic->ullRxMulticastFrames++;
141 pStatistic->ullRxMulticastBytes +=
142 (unsigned long long) cbFrameLength;
144 else {
145 pStatistic->ullRxDirectedFrames++;
146 pStatistic->ullRxDirectedBytes +=
147 (unsigned long long) cbFrameLength;
152 if(byRxRate==22) {
153 pStatistic->CustomStat.ullRsr11M++;
154 if(byRSR & RSR_CRCOK) {
155 pStatistic->CustomStat.ullRsr11MCRCOk++;
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);
161 else if(byRxRate==11) {
162 pStatistic->CustomStat.ullRsr5M++;
163 if(byRSR & RSR_CRCOK) {
164 pStatistic->CustomStat.ullRsr5MCRCOk++;
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);
170 else if(byRxRate==4) {
171 pStatistic->CustomStat.ullRsr2M++;
172 if(byRSR & RSR_CRCOK) {
173 pStatistic->CustomStat.ullRsr2MCRCOk++;
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);
179 else if(byRxRate==2){
180 pStatistic->CustomStat.ullRsr1M++;
181 if(byRSR & RSR_CRCOK) {
182 pStatistic->CustomStat.ullRsr1MCRCOk++;
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);
188 else if(byRxRate==12){
189 pStatistic->CustomStat.ullRsr6M++;
190 if(byRSR & RSR_CRCOK) {
191 pStatistic->CustomStat.ullRsr6MCRCOk++;
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);
197 else if(byRxRate==18){
198 pStatistic->CustomStat.ullRsr9M++;
199 if(byRSR & RSR_CRCOK) {
200 pStatistic->CustomStat.ullRsr9MCRCOk++;
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);
206 else if(byRxRate==24){
207 pStatistic->CustomStat.ullRsr12M++;
208 if(byRSR & RSR_CRCOK) {
209 pStatistic->CustomStat.ullRsr12MCRCOk++;
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);
215 else if(byRxRate==36){
216 pStatistic->CustomStat.ullRsr18M++;
217 if(byRSR & RSR_CRCOK) {
218 pStatistic->CustomStat.ullRsr18MCRCOk++;
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);
224 else if(byRxRate==48){
225 pStatistic->CustomStat.ullRsr24M++;
226 if(byRSR & RSR_CRCOK) {
227 pStatistic->CustomStat.ullRsr24MCRCOk++;
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);
233 else if(byRxRate==72){
234 pStatistic->CustomStat.ullRsr36M++;
235 if(byRSR & RSR_CRCOK) {
236 pStatistic->CustomStat.ullRsr36MCRCOk++;
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);
242 else if(byRxRate==96){
243 pStatistic->CustomStat.ullRsr48M++;
244 if(byRSR & RSR_CRCOK) {
245 pStatistic->CustomStat.ullRsr48MCRCOk++;
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);
251 else if(byRxRate==108){
252 pStatistic->CustomStat.ullRsr54M++;
253 if(byRSR & RSR_CRCOK) {
254 pStatistic->CustomStat.ullRsr54MCRCOk++;
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);
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);
267 if (byRSR & RSR_BSSIDOK)
268 pStatistic->dwRsrBSSIDOk++;
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++;
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++;
290 // increase rx packet count
291 pStatistic->dwRsrRxPacket++;
292 pStatistic->dwRsrRxOctet += cbFrameLength;
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++;
302 if (byRSR & RSR_ADDRBROAD)
303 pStatistic->dwRsrBroadcast++;
304 else if (byRSR & RSR_ADDRMULTI)
305 pStatistic->dwRsrMulticast++;
306 else
307 pStatistic->dwRsrDirected++;
309 if (WLAN_GET_FC_MOREFRAG(pHeader->frame_control))
310 pStatistic->dwRsrRxFragment++;
312 if (cbFrameLength < ETH_ZLEN + 4) {
313 pStatistic->dwRsrRunt++;
314 } else if (cbFrameLength == ETH_ZLEN + 4) {
315 pStatistic->dwRsrRxFrmLen64++;
317 else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
318 pStatistic->dwRsrRxFrmLen65_127++;
320 else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
321 pStatistic->dwRsrRxFrmLen128_255++;
323 else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
324 pStatistic->dwRsrRxFrmLen256_511++;
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++;
337 * Description: Update Tx Statistic Counter
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
350 * Return Value: none
353 void
354 STAvUpdateTDStatCounter (
355 PSStatCounter pStatistic,
356 u8 byPktNum,
357 u8 byRate,
358 u8 byTSR
361 u8 byRetyCnt;
362 // increase tx packet count
363 pStatistic->dwTsrTxPacket++;
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;
372 if ( byRetyCnt == 0x1)
373 pStatistic->dwTsrOnceRetry++;
374 else
375 pStatistic->dwTsrMoreThanOnceRetry++;
377 if (byRetyCnt <= 8)
378 pStatistic->dwTxRetryCount[byRetyCnt-1]++;
381 if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
383 if (byRetyCnt < 2)
384 pStatistic->TxNoRetryOkCount ++;
385 else
386 pStatistic->TxRetryOkCount ++;
388 pStatistic->ullTsrOK++;
389 pStatistic->CustomStat.ullTsrAllOK++;
390 // update counters in case that successful transmit
391 pStatistic->dwTxOk[byRate]++;
392 pStatistic->dwTxOk[MAX_RATE]++;
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;
405 else {
407 pStatistic->TxFailCount ++;
409 pStatistic->dwTsrErr++;
410 if (byTSR & TSR_RETRYTMO)
411 pStatistic->dwTsrRetryTimeout++;
412 if (byTSR & TSR_TMO)
413 pStatistic->dwTsrTransmitTimeout++;
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++;
426 * Description: Update 802.11 mib counter
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
436 * Return Value: none
439 void
440 STAvUpdate802_11Counter(
441 PSDot11Counters p802_11Counter,
442 PSStatCounter pStatistic,
443 u8 byRTSSuccess,
444 u8 byRTSFail,
445 u8 byACKFail,
446 u8 byFCSErr
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);
469 * Description: Clear 802.11 mib counter
471 * Parameters:
472 * In:
473 * pUsbCounter - Pointer to USB mib counter
474 * ntStatus - URB status
475 * Out:
476 * none
478 * Return Value: none
482 void STAvUpdateUSBCounter(PSUSBCounter pUsbCounter, int ntStatus)
485 // if ( ntStatus == USBD_STATUS_CRC ) {
486 pUsbCounter->dwCrc++;
487 // }