2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
21 * Purpose: Implement MIB Data Structure
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
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
64 * pStatistic - Pointer to Statistic Counter Data Structure
71 void STAvClearAllCounter(PSStatCounter pStatistic
)
74 memset(pStatistic
, 0, sizeof(SStatCounter
));
78 * Description: Update Isr Statistic Counter
82 * pStatistic - Pointer to Statistic Counter Data Structure
83 * wisr - Interrupt status
90 void STAvUpdateIsrStatCounter(PSStatCounter pStatistic
, unsigned long dwIsr
)
92 /**********************/
93 /* ABNORMAL interrupt */
94 /**********************/
95 // not any IMR bit invoke irq
98 pStatistic
->ISRStat
.dwIsrUnknown
++;
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
148 * pStatistic - Pointer to Statistic Counter Data Structure
150 * byNewRSR - Rx Status
151 * pbyBuffer - Rx Buffer
152 * cbFrameLength - Rx Length
159 void STAvUpdateRDStatCounter(PSStatCounter pStatistic
,
160 unsigned char byRSR
, unsigned char byNewRSR
, unsigned char byRxRate
,
161 unsigned char *pbyBuffer
, unsigned int cbFrameLength
)
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
;
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
);
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
++;
298 if (byRSR
& RSR_ADDRBROAD
)
299 pStatistic
->dwRsrBroadcast
++;
300 else if (byRSR
& RSR_ADDRMULTI
)
301 pStatistic
->dwRsrMulticast
++;
303 pStatistic
->dwRsrDirected
++;
305 if (WLAN_GET_FC_MOREFRAG(pHeader
->wFrameCtl
))
306 pStatistic
->dwRsrRxFragment
++;
308 if (cbFrameLength
< ETH_ZLEN
+ 4)
309 pStatistic
->dwRsrRunt
++;
310 else if (cbFrameLength
== ETH_ZLEN
+ 4)
311 pStatistic
->dwRsrRxFrmLen64
++;
312 else if ((65 <= cbFrameLength
) && (cbFrameLength
<= 127))
313 pStatistic
->dwRsrRxFrmLen65_127
++;
314 else if ((128 <= cbFrameLength
) && (cbFrameLength
<= 255))
315 pStatistic
->dwRsrRxFrmLen128_255
++;
316 else if ((256 <= cbFrameLength
) && (cbFrameLength
<= 511))
317 pStatistic
->dwRsrRxFrmLen256_511
++;
318 else if ((512 <= cbFrameLength
) && (cbFrameLength
<= 1023))
319 pStatistic
->dwRsrRxFrmLen512_1023
++;
320 else if ((1024 <= cbFrameLength
) && (cbFrameLength
<= ETH_FRAME_LEN
+ 4))
321 pStatistic
->dwRsrRxFrmLen1024_1518
++;
322 else if (cbFrameLength
> ETH_FRAME_LEN
+ 4)
323 pStatistic
->dwRsrLong
++;
327 * Description: Update Rx Statistic Counter and copy Rx buffer
331 * pStatistic - Pointer to Statistic Counter Data Structure
333 * byNewRSR - Rx Status
334 * pbyBuffer - Rx Buffer
335 * cbFrameLength - Rx Length
344 STAvUpdateRDStatCounterEx(
345 PSStatCounter pStatistic
,
347 unsigned char byNewRSR
,
348 unsigned char byRxRate
,
349 unsigned char *pbyBuffer
,
350 unsigned int cbFrameLength
353 STAvUpdateRDStatCounter(
363 pStatistic
->dwCntRxFrmLength
= cbFrameLength
;
364 // rx pattern, we just see 10 bytes for sample
365 memcpy(pStatistic
->abyCntRxPattern
, (unsigned char *)pbyBuffer
, 10);
369 * Description: Update Tx Statistic Counter
373 * pStatistic - Pointer to Statistic Counter Data Structure
376 * pbyBuffer - Tx Buffer
377 * cbFrameLength - Tx Length
378 * uIdx - Index of Tx DMA
386 STAvUpdateTDStatCounter(
387 PSStatCounter pStatistic
,
388 unsigned char byTSR0
,
389 unsigned char byTSR1
,
390 unsigned char *pbyBuffer
,
391 unsigned int cbFrameLength
,
395 PWLAN_80211HDR_A4 pHeader
;
396 unsigned char *pbyDestAddr
;
397 unsigned char byTSR0_NCR
= byTSR0
& TSR0_NCR
;
399 pHeader
= (PWLAN_80211HDR_A4
) pbyBuffer
;
400 if (WLAN_GET_FC_TODS(pHeader
->wFrameCtl
) == 0)
401 pbyDestAddr
= &(pHeader
->abyAddr1
[0]);
403 pbyDestAddr
= &(pHeader
->abyAddr3
[0]);
405 // increase tx packet count
406 pStatistic
->dwTsrTxPacket
[uIdx
]++;
407 pStatistic
->dwTsrTxOctet
[uIdx
] += cbFrameLength
;
409 if (byTSR0_NCR
!= 0) {
410 pStatistic
->dwTsrRetry
[uIdx
]++;
411 pStatistic
->dwTsrTotalRetry
[uIdx
] += byTSR0_NCR
;
414 pStatistic
->dwTsrOnceRetry
[uIdx
]++;
416 pStatistic
->dwTsrMoreThanOnceRetry
[uIdx
]++;
419 if ((byTSR1
&(TSR1_TERR
|TSR1_RETRYTMO
|TSR1_TMO
|ACK_DATA
)) == 0) {
420 pStatistic
->ullTsrOK
[uIdx
]++;
421 pStatistic
->CustomStat
.ullTsrAllOK
=
422 (pStatistic
->ullTsrOK
[TYPE_AC0DMA
] + pStatistic
->ullTsrOK
[TYPE_TXDMA0
]);
423 // update counters in case that successful transmit
424 if (is_broadcast_ether_addr(pbyDestAddr
)) {
425 pStatistic
->ullTxBroadcastFrames
[uIdx
]++;
426 pStatistic
->ullTxBroadcastBytes
[uIdx
] += (unsigned long long) cbFrameLength
;
427 } else if (is_multicast_ether_addr(pbyDestAddr
)) {
428 pStatistic
->ullTxMulticastFrames
[uIdx
]++;
429 pStatistic
->ullTxMulticastBytes
[uIdx
] += (unsigned long long) cbFrameLength
;
431 pStatistic
->ullTxDirectedFrames
[uIdx
]++;
432 pStatistic
->ullTxDirectedBytes
[uIdx
] += (unsigned long long) cbFrameLength
;
435 if (byTSR1
& TSR1_TERR
)
436 pStatistic
->dwTsrErr
[uIdx
]++;
437 if (byTSR1
& TSR1_RETRYTMO
)
438 pStatistic
->dwTsrRetryTimeout
[uIdx
]++;
439 if (byTSR1
& TSR1_TMO
)
440 pStatistic
->dwTsrTransmitTimeout
[uIdx
]++;
441 if (byTSR1
& ACK_DATA
)
442 pStatistic
->dwTsrACKData
[uIdx
]++;
445 if (is_broadcast_ether_addr(pbyDestAddr
))
446 pStatistic
->dwTsrBroadcast
[uIdx
]++;
447 else if (is_multicast_ether_addr(pbyDestAddr
))
448 pStatistic
->dwTsrMulticast
[uIdx
]++;
450 pStatistic
->dwTsrDirected
[uIdx
]++;
454 * Description: Update Tx Statistic Counter and copy Tx buffer
458 * pStatistic - Pointer to Statistic Counter Data Structure
459 * pbyBuffer - Tx Buffer
460 * cbFrameLength - Tx Length
468 STAvUpdateTDStatCounterEx(
469 PSStatCounter pStatistic
,
470 unsigned char *pbyBuffer
,
471 unsigned long cbFrameLength
474 unsigned int uPktLength
;
476 uPktLength
= (unsigned int)cbFrameLength
;
479 pStatistic
->dwCntTxBufLength
= uPktLength
;
480 // tx pattern, we just see 16 bytes for sample
481 memcpy(pStatistic
->abyCntTxPattern
, pbyBuffer
, 16);
485 * Description: Update 802.11 mib counter
489 * p802_11Counter - Pointer to 802.11 mib counter
490 * pStatistic - Pointer to Statistic Counter Data Structure
491 * dwCounter - hardware counter for 802.11 mib
499 STAvUpdate802_11Counter(
500 PSDot11Counters p802_11Counter
,
501 PSStatCounter pStatistic
,
502 unsigned long dwCounter
505 p802_11Counter
->MulticastTransmittedFrameCount
= (unsigned long long) (pStatistic
->dwTsrBroadcast
[TYPE_AC0DMA
] +
506 pStatistic
->dwTsrBroadcast
[TYPE_TXDMA0
] +
507 pStatistic
->dwTsrMulticast
[TYPE_AC0DMA
] +
508 pStatistic
->dwTsrMulticast
[TYPE_TXDMA0
]);
509 p802_11Counter
->FailedCount
= (unsigned long long) (pStatistic
->dwTsrErr
[TYPE_AC0DMA
] + pStatistic
->dwTsrErr
[TYPE_TXDMA0
]);
510 p802_11Counter
->RetryCount
= (unsigned long long) (pStatistic
->dwTsrRetry
[TYPE_AC0DMA
] + pStatistic
->dwTsrRetry
[TYPE_TXDMA0
]);
511 p802_11Counter
->MultipleRetryCount
= (unsigned long long) (pStatistic
->dwTsrMoreThanOnceRetry
[TYPE_AC0DMA
] +
512 pStatistic
->dwTsrMoreThanOnceRetry
[TYPE_TXDMA0
]);
513 p802_11Counter
->RTSSuccessCount
+= (unsigned long long) (dwCounter
& 0x000000ff);
514 p802_11Counter
->RTSFailureCount
+= (unsigned long long) ((dwCounter
& 0x0000ff00) >> 8);
515 p802_11Counter
->ACKFailureCount
+= (unsigned long long) ((dwCounter
& 0x00ff0000) >> 16);
516 p802_11Counter
->FCSErrorCount
+= (unsigned long long) ((dwCounter
& 0xff000000) >> 24);
517 p802_11Counter
->MulticastReceivedFrameCount
= (unsigned long long) (pStatistic
->dwRsrBroadcast
+
518 pStatistic
->dwRsrMulticast
);
522 * Description: Clear 802.11 mib counter
526 * p802_11Counter - Pointer to 802.11 mib counter
534 STAvClear802_11Counter(PSDot11Counters p802_11Counter
)
536 // set memory to zero
537 memset(p802_11Counter
, 0, sizeof(SDot11Counters
));