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
41 #if !defined(__UPC_H__)
44 #if !defined(__MAC_H__)
47 #if !defined(__TBIT_H__)
50 #if !defined(__TETHER_H__)
53 #if !defined(__MIB_H__)
56 #if !defined(__WCTL_H__)
59 #if !defined(__UMEM_H__)
62 #if !defined(__BASEBAND_H__)
66 /*--------------------- Static Definitions -------------------------*/
67 static int msglevel =MSG_LEVEL_INFO;
68 /*--------------------- Static Classes ----------------------------*/
70 /*--------------------- Static Variables --------------------------*/
72 /*--------------------- Static Functions --------------------------*/
74 /*--------------------- Export Variables --------------------------*/
76 /*--------------------- Export Functions --------------------------*/
81 * Description: Clear All Statistic Counter
85 * pStatistic - Pointer to Statistic Counter Data Structure
92 void STAvClearAllCounter (PSStatCounter pStatistic)
95 ZERO_MEMORY(pStatistic, sizeof(SStatCounter));
100 * Description: Update Isr Statistic Counter
104 * pStatistic - Pointer to Statistic Counter Data Structure
105 * wisr - Interrupt status
112 void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, DWORD dwIsr)
114 /**********************/
115 /* ABNORMAL interrupt */
116 /**********************/
117 // not any IMR bit invoke irq
120 pStatistic->ISRStat.dwIsrUnknown++;
125 if (BITbIsBitOn(dwIsr, ISR_TXDMA0)) // ISR, bit0
126 pStatistic->ISRStat.dwIsrTx0OK++; // TXDMA0 successful
128 if (BITbIsBitOn(dwIsr, ISR_AC0DMA)) // ISR, bit1
129 pStatistic->ISRStat.dwIsrAC0TxOK++; // AC0DMA successful
131 if (BITbIsBitOn(dwIsr, ISR_BNTX)) // ISR, bit2
132 pStatistic->ISRStat.dwIsrBeaconTxOK++; // BeaconTx successful
134 if (BITbIsBitOn(dwIsr, ISR_RXDMA0)) // ISR, bit3
135 pStatistic->ISRStat.dwIsrRx0OK++; // Rx0 successful
137 if (BITbIsBitOn(dwIsr, ISR_TBTT)) // ISR, bit4
138 pStatistic->ISRStat.dwIsrTBTTInt++; // TBTT successful
140 if (BITbIsBitOn(dwIsr, ISR_SOFTTIMER)) // ISR, bit6
141 pStatistic->ISRStat.dwIsrSTIMERInt++;
143 if (BITbIsBitOn(dwIsr, ISR_WATCHDOG)) // ISR, bit7
144 pStatistic->ISRStat.dwIsrWatchDog++;
146 if (BITbIsBitOn(dwIsr, ISR_FETALERR)) // ISR, bit8
147 pStatistic->ISRStat.dwIsrUnrecoverableError++;
149 if (BITbIsBitOn(dwIsr, ISR_SOFTINT)) // ISR, bit9
150 pStatistic->ISRStat.dwIsrSoftInterrupt++; // software interrupt
152 if (BITbIsBitOn(dwIsr, ISR_MIBNEARFULL)) // ISR, bit10
153 pStatistic->ISRStat.dwIsrMIBNearfull++;
155 if (BITbIsBitOn(dwIsr, ISR_RXNOBUF)) // ISR, bit11
156 pStatistic->ISRStat.dwIsrRxNoBuf++; // Rx No Buff
158 if (BITbIsBitOn(dwIsr, ISR_RXDMA1)) // ISR, bit12
159 pStatistic->ISRStat.dwIsrRx1OK++; // Rx1 successful
161 // if (BITbIsBitOn(dwIsr, ISR_ATIMTX)) // ISR, bit13
162 // pStatistic->ISRStat.dwIsrATIMTxOK++; // ATIMTX successful
164 // if (BITbIsBitOn(dwIsr, ISR_SYNCTX)) // ISR, bit14
165 // pStatistic->ISRStat.dwIsrSYNCTxOK++; // SYNCTX successful
167 // if (BITbIsBitOn(dwIsr, ISR_CFPEND)) // ISR, bit18
168 // pStatistic->ISRStat.dwIsrCFPEnd++;
170 // if (BITbIsBitOn(dwIsr, ISR_ATIMEND)) // ISR, bit19
171 // pStatistic->ISRStat.dwIsrATIMEnd++;
173 // if (BITbIsBitOn(dwIsr, ISR_SYNCFLUSHOK)) // ISR, bit20
174 // pStatistic->ISRStat.dwIsrSYNCFlushOK++;
176 if (BITbIsBitOn(dwIsr, ISR_SOFTTIMER1)) // ISR, bit21
177 pStatistic->ISRStat.dwIsrSTIMER1Int++;
183 * Description: Update Rx Statistic Counter
187 * pStatistic - Pointer to Statistic Counter Data Structure
189 * byNewRSR - Rx Status
190 * pbyBuffer - Rx Buffer
191 * cbFrameLength - Rx Length
198 void STAvUpdateRDStatCounter (PSStatCounter pStatistic,
199 BYTE byRSR, BYTE byNewRSR, BYTE byRxRate,
200 PBYTE pbyBuffer, UINT cbFrameLength)
203 PS802_11Header pHeader = (PS802_11Header)pbyBuffer;
205 if (BITbIsBitOn(byRSR, RSR_ADDROK))
206 pStatistic->dwRsrADDROk++;
207 if (BITbIsBitOn(byRSR, RSR_CRCOK)) {
208 pStatistic->dwRsrCRCOk++;
210 pStatistic->ullRsrOK++;
212 if (cbFrameLength >= U_ETHER_ADDR_LEN) {
213 // update counters in case that successful transmit
214 if (BITbIsBitOn(byRSR, RSR_ADDRBROAD)) {
215 pStatistic->ullRxBroadcastFrames++;
216 pStatistic->ullRxBroadcastBytes += (ULONGLONG)cbFrameLength;
218 else if (BITbIsBitOn(byRSR, RSR_ADDRMULTI)) {
219 pStatistic->ullRxMulticastFrames++;
220 pStatistic->ullRxMulticastBytes += (ULONGLONG)cbFrameLength;
223 pStatistic->ullRxDirectedFrames++;
224 pStatistic->ullRxDirectedBytes += (ULONGLONG)cbFrameLength;
230 pStatistic->CustomStat.ullRsr11M++;
231 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
232 pStatistic->CustomStat.ullRsr11MCRCOk++;
234 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"11M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr11M, (INT)pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
236 else if(byRxRate==11) {
237 pStatistic->CustomStat.ullRsr5M++;
238 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
239 pStatistic->CustomStat.ullRsr5MCRCOk++;
241 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 5M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr5M, (INT)pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
243 else if(byRxRate==4) {
244 pStatistic->CustomStat.ullRsr2M++;
245 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
246 pStatistic->CustomStat.ullRsr2MCRCOk++;
248 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 2M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr2M, (INT)pStatistic->CustomStat.ullRsr2MCRCOk, byRSR);
250 else if(byRxRate==2){
251 pStatistic->CustomStat.ullRsr1M++;
252 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
253 pStatistic->CustomStat.ullRsr1MCRCOk++;
255 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 1M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr1M, (INT)pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
257 else if(byRxRate==12){
258 pStatistic->CustomStat.ullRsr6M++;
259 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
260 pStatistic->CustomStat.ullRsr6MCRCOk++;
262 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 6M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr6M, (INT)pStatistic->CustomStat.ullRsr6MCRCOk);
264 else if(byRxRate==18){
265 pStatistic->CustomStat.ullRsr9M++;
266 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
267 pStatistic->CustomStat.ullRsr9MCRCOk++;
269 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 9M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr9M, (INT)pStatistic->CustomStat.ullRsr9MCRCOk);
271 else if(byRxRate==24){
272 pStatistic->CustomStat.ullRsr12M++;
273 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
274 pStatistic->CustomStat.ullRsr12MCRCOk++;
276 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"12M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr12M, (INT)pStatistic->CustomStat.ullRsr12MCRCOk);
278 else if(byRxRate==36){
279 pStatistic->CustomStat.ullRsr18M++;
280 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
281 pStatistic->CustomStat.ullRsr18MCRCOk++;
283 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"18M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr18M, (INT)pStatistic->CustomStat.ullRsr18MCRCOk);
285 else if(byRxRate==48){
286 pStatistic->CustomStat.ullRsr24M++;
287 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
288 pStatistic->CustomStat.ullRsr24MCRCOk++;
290 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"24M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr24M, (INT)pStatistic->CustomStat.ullRsr24MCRCOk);
292 else if(byRxRate==72){
293 pStatistic->CustomStat.ullRsr36M++;
294 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
295 pStatistic->CustomStat.ullRsr36MCRCOk++;
297 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"36M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr36M, (INT)pStatistic->CustomStat.ullRsr36MCRCOk);
299 else if(byRxRate==96){
300 pStatistic->CustomStat.ullRsr48M++;
301 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
302 pStatistic->CustomStat.ullRsr48MCRCOk++;
304 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"48M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr48M, (INT)pStatistic->CustomStat.ullRsr48MCRCOk);
306 else if(byRxRate==108){
307 pStatistic->CustomStat.ullRsr54M++;
308 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
309 pStatistic->CustomStat.ullRsr54MCRCOk++;
311 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"54M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr54M, (INT)pStatistic->CustomStat.ullRsr54MCRCOk);
314 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Unknown: Total[%d], CRCOK[%d]\n", (INT)pStatistic->dwRsrRxPacket+1, (INT)pStatistic->dwRsrCRCOk);
317 if (BITbIsBitOn(byRSR, RSR_BSSIDOK))
318 pStatistic->dwRsrBSSIDOk++;
320 if (BITbIsBitOn(byRSR, RSR_BCNSSIDOK))
321 pStatistic->dwRsrBCNSSIDOk++;
322 if (BITbIsBitOn(byRSR, RSR_IVLDLEN)) //invalid len (> 2312 byte)
323 pStatistic->dwRsrLENErr++;
324 if (BITbIsBitOn(byRSR, RSR_IVLDTYP)) //invalid packet type
325 pStatistic->dwRsrTYPErr++;
326 if (BITbIsBitOn(byRSR, (RSR_IVLDTYP | RSR_IVLDLEN)))
327 pStatistic->dwRsrErr++;
329 if (BITbIsBitOn(byNewRSR, NEWRSR_DECRYPTOK))
330 pStatistic->dwNewRsrDECRYPTOK++;
331 if (BITbIsBitOn(byNewRSR, NEWRSR_CFPIND))
332 pStatistic->dwNewRsrCFP++;
333 if (BITbIsBitOn(byNewRSR, NEWRSR_HWUTSF))
334 pStatistic->dwNewRsrUTSF++;
335 if (BITbIsBitOn(byNewRSR, NEWRSR_BCNHITAID))
336 pStatistic->dwNewRsrHITAID++;
337 if (BITbIsBitOn(byNewRSR, NEWRSR_BCNHITAID0))
338 pStatistic->dwNewRsrHITAID0++;
340 // increase rx packet count
341 pStatistic->dwRsrRxPacket++;
342 pStatistic->dwRsrRxOctet += cbFrameLength;
345 if (IS_TYPE_DATA(pbyBuffer)) {
346 pStatistic->dwRsrRxData++;
347 } else if (IS_TYPE_MGMT(pbyBuffer)){
348 pStatistic->dwRsrRxManage++;
349 } else if (IS_TYPE_CONTROL(pbyBuffer)){
350 pStatistic->dwRsrRxControl++;
353 if (BITbIsBitOn(byRSR, RSR_ADDRBROAD))
354 pStatistic->dwRsrBroadcast++;
355 else if (BITbIsBitOn(byRSR, RSR_ADDRMULTI))
356 pStatistic->dwRsrMulticast++;
358 pStatistic->dwRsrDirected++;
360 if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
361 pStatistic->dwRsrRxFragment++;
363 if (cbFrameLength < MIN_PACKET_LEN + 4) {
364 pStatistic->dwRsrRunt++;
366 else if (cbFrameLength == MIN_PACKET_LEN + 4) {
367 pStatistic->dwRsrRxFrmLen64++;
369 else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
370 pStatistic->dwRsrRxFrmLen65_127++;
372 else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
373 pStatistic->dwRsrRxFrmLen128_255++;
375 else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
376 pStatistic->dwRsrRxFrmLen256_511++;
378 else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023)) {
379 pStatistic->dwRsrRxFrmLen512_1023++;
381 else if ((1024 <= cbFrameLength) && (cbFrameLength <= MAX_PACKET_LEN + 4)) {
382 pStatistic->dwRsrRxFrmLen1024_1518++;
383 } else if (cbFrameLength > MAX_PACKET_LEN + 4) {
384 pStatistic->dwRsrLong++;
392 * Description: Update Rx Statistic Counter and copy Rx buffer
396 * pStatistic - Pointer to Statistic Counter Data Structure
398 * byNewRSR - Rx Status
399 * pbyBuffer - Rx Buffer
400 * cbFrameLength - Rx Length
409 STAvUpdateRDStatCounterEx (
410 PSStatCounter pStatistic,
418 STAvUpdateRDStatCounter(
428 pStatistic->dwCntRxFrmLength = cbFrameLength;
429 // rx pattern, we just see 10 bytes for sample
430 MEMvCopy(pStatistic->abyCntRxPattern, (PBYTE)pbyBuffer, 10);
435 * Description: Update Tx Statistic Counter
439 * pStatistic - Pointer to Statistic Counter Data Structure
442 * pbyBuffer - Tx Buffer
443 * cbFrameLength - Tx Length
444 * uIdx - Index of Tx DMA
452 STAvUpdateTDStatCounter (
453 PSStatCounter pStatistic,
461 PWLAN_80211HDR_A4 pHeader;
463 BYTE byTSR0_NCR = byTSR0 & TSR0_NCR;
467 pHeader = (PWLAN_80211HDR_A4) pbyBuffer;
468 if (WLAN_GET_FC_TODS(pHeader->wFrameCtl) == 0) {
469 pbyDestAddr = &(pHeader->abyAddr1[0]);
472 pbyDestAddr = &(pHeader->abyAddr3[0]);
474 // increase tx packet count
475 pStatistic->dwTsrTxPacket[uIdx]++;
476 pStatistic->dwTsrTxOctet[uIdx] += cbFrameLength;
478 if (byTSR0_NCR != 0) {
479 pStatistic->dwTsrRetry[uIdx]++;
480 pStatistic->dwTsrTotalRetry[uIdx] += byTSR0_NCR;
483 pStatistic->dwTsrOnceRetry[uIdx]++;
485 pStatistic->dwTsrMoreThanOnceRetry[uIdx]++;
488 if ((byTSR1&(TSR1_TERR|TSR1_RETRYTMO|TSR1_TMO|ACK_DATA)) == 0) {
489 pStatistic->ullTsrOK[uIdx]++;
490 pStatistic->CustomStat.ullTsrAllOK =
491 (pStatistic->ullTsrOK[TYPE_AC0DMA] + pStatistic->ullTsrOK[TYPE_TXDMA0]);
492 // update counters in case that successful transmit
493 if (IS_BROADCAST_ADDRESS(pbyDestAddr)) {
494 pStatistic->ullTxBroadcastFrames[uIdx]++;
495 pStatistic->ullTxBroadcastBytes[uIdx] += (ULONGLONG)cbFrameLength;
497 else if (IS_MULTICAST_ADDRESS(pbyDestAddr)) {
498 pStatistic->ullTxMulticastFrames[uIdx]++;
499 pStatistic->ullTxMulticastBytes[uIdx] += (ULONGLONG)cbFrameLength;
502 pStatistic->ullTxDirectedFrames[uIdx]++;
503 pStatistic->ullTxDirectedBytes[uIdx] += (ULONGLONG)cbFrameLength;
507 if (BITbIsBitOn(byTSR1, TSR1_TERR))
508 pStatistic->dwTsrErr[uIdx]++;
509 if (BITbIsBitOn(byTSR1, TSR1_RETRYTMO))
510 pStatistic->dwTsrRetryTimeout[uIdx]++;
511 if (BITbIsBitOn(byTSR1, TSR1_TMO))
512 pStatistic->dwTsrTransmitTimeout[uIdx]++;
513 if (BITbIsBitOn(byTSR1, ACK_DATA))
514 pStatistic->dwTsrACKData[uIdx]++;
517 if (IS_BROADCAST_ADDRESS(pbyDestAddr))
518 pStatistic->dwTsrBroadcast[uIdx]++;
519 else if (IS_MULTICAST_ADDRESS(pbyDestAddr))
520 pStatistic->dwTsrMulticast[uIdx]++;
522 pStatistic->dwTsrDirected[uIdx]++;
528 * Description: Update Tx Statistic Counter and copy Tx buffer
532 * pStatistic - Pointer to Statistic Counter Data Structure
533 * pbyBuffer - Tx Buffer
534 * cbFrameLength - Tx Length
542 STAvUpdateTDStatCounterEx (
543 PSStatCounter pStatistic,
550 uPktLength = (UINT)cbFrameLength;
553 pStatistic->dwCntTxBufLength = uPktLength;
554 // tx pattern, we just see 16 bytes for sample
555 MEMvCopy(pStatistic->abyCntTxPattern, pbyBuffer, 16);
560 * Description: Update 802.11 mib counter
564 * p802_11Counter - Pointer to 802.11 mib counter
565 * pStatistic - Pointer to Statistic Counter Data Structure
566 * dwCounter - hardware counter for 802.11 mib
574 STAvUpdate802_11Counter(
575 PSDot11Counters p802_11Counter,
576 PSStatCounter pStatistic,
580 //p802_11Counter->TransmittedFragmentCount
581 p802_11Counter->MulticastTransmittedFrameCount = (ULONGLONG) (pStatistic->dwTsrBroadcast[TYPE_AC0DMA] +
582 pStatistic->dwTsrBroadcast[TYPE_TXDMA0] +
583 pStatistic->dwTsrMulticast[TYPE_AC0DMA] +
584 pStatistic->dwTsrMulticast[TYPE_TXDMA0]);
585 p802_11Counter->FailedCount = (ULONGLONG) (pStatistic->dwTsrErr[TYPE_AC0DMA] + pStatistic->dwTsrErr[TYPE_TXDMA0]);
586 p802_11Counter->RetryCount = (ULONGLONG) (pStatistic->dwTsrRetry[TYPE_AC0DMA] + pStatistic->dwTsrRetry[TYPE_TXDMA0]);
587 p802_11Counter->MultipleRetryCount = (ULONGLONG) (pStatistic->dwTsrMoreThanOnceRetry[TYPE_AC0DMA] +
588 pStatistic->dwTsrMoreThanOnceRetry[TYPE_TXDMA0]);
589 //p802_11Counter->FrameDuplicateCount
590 p802_11Counter->RTSSuccessCount += (ULONGLONG) (dwCounter & 0x000000ff);
591 p802_11Counter->RTSFailureCount += (ULONGLONG) ((dwCounter & 0x0000ff00) >> 8);
592 p802_11Counter->ACKFailureCount += (ULONGLONG) ((dwCounter & 0x00ff0000) >> 16);
593 p802_11Counter->FCSErrorCount += (ULONGLONG) ((dwCounter & 0xff000000) >> 24);
594 //p802_11Counter->ReceivedFragmentCount
595 p802_11Counter->MulticastReceivedFrameCount = (ULONGLONG) (pStatistic->dwRsrBroadcast +
596 pStatistic->dwRsrMulticast);
600 * Description: Clear 802.11 mib counter
604 * p802_11Counter - Pointer to 802.11 mib counter
612 STAvClear802_11Counter(PSDot11Counters p802_11Counter)
614 // set memory to zero
615 ZERO_MEMORY(p802_11Counter, sizeof(SDot11Counters));