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 --------------------------*/
62 * Description: Clear All Statistic Counter
66 * pStatistic - Pointer to Statistic Counter Data Structure
73 void STAvClearAllCounter(PSStatCounter pStatistic)
76 memset(pStatistic, 0, sizeof(SStatCounter));
81 * Description: Update Isr Statistic Counter
85 * pStatistic - Pointer to Statistic Counter Data Structure
86 * wisr - Interrupt status
93 void STAvUpdateIsrStatCounter(PSStatCounter pStatistic, unsigned long dwIsr)
95 /**********************/
96 /* ABNORMAL interrupt */
97 /**********************/
98 // not any IMR bit invoke irq
101 pStatistic->ISRStat.dwIsrUnknown++;
106 if (dwIsr & ISR_TXDMA0) // ISR, bit0
107 pStatistic->ISRStat.dwIsrTx0OK++; // TXDMA0 successful
109 if (dwIsr & ISR_AC0DMA) // ISR, bit1
110 pStatistic->ISRStat.dwIsrAC0TxOK++; // AC0DMA successful
112 if (dwIsr & ISR_BNTX) // ISR, bit2
113 pStatistic->ISRStat.dwIsrBeaconTxOK++; // BeaconTx successful
115 if (dwIsr & ISR_RXDMA0) // ISR, bit3
116 pStatistic->ISRStat.dwIsrRx0OK++; // Rx0 successful
118 if (dwIsr & ISR_TBTT) // ISR, bit4
119 pStatistic->ISRStat.dwIsrTBTTInt++; // TBTT successful
121 if (dwIsr & ISR_SOFTTIMER) // ISR, bit6
122 pStatistic->ISRStat.dwIsrSTIMERInt++;
124 if (dwIsr & ISR_WATCHDOG) // ISR, bit7
125 pStatistic->ISRStat.dwIsrWatchDog++;
127 if (dwIsr & ISR_FETALERR) // ISR, bit8
128 pStatistic->ISRStat.dwIsrUnrecoverableError++;
130 if (dwIsr & ISR_SOFTINT) // ISR, bit9
131 pStatistic->ISRStat.dwIsrSoftInterrupt++; // software interrupt
133 if (dwIsr & ISR_MIBNEARFULL) // ISR, bit10
134 pStatistic->ISRStat.dwIsrMIBNearfull++;
136 if (dwIsr & ISR_RXNOBUF) // ISR, bit11
137 pStatistic->ISRStat.dwIsrRxNoBuf++; // Rx No Buff
139 if (dwIsr & ISR_RXDMA1) // ISR, bit12
140 pStatistic->ISRStat.dwIsrRx1OK++; // Rx1 successful
142 // if (dwIsr & ISR_ATIMTX) // ISR, bit13
143 // pStatistic->ISRStat.dwIsrATIMTxOK++; // ATIMTX successful
145 // if (dwIsr & ISR_SYNCTX) // ISR, bit14
146 // pStatistic->ISRStat.dwIsrSYNCTxOK++; // SYNCTX successful
148 // if (dwIsr & ISR_CFPEND) // ISR, bit18
149 // pStatistic->ISRStat.dwIsrCFPEnd++;
151 // if (dwIsr & ISR_ATIMEND) // ISR, bit19
152 // pStatistic->ISRStat.dwIsrATIMEnd++;
154 // if (dwIsr & ISR_SYNCFLUSHOK) // ISR, bit20
155 // pStatistic->ISRStat.dwIsrSYNCFlushOK++;
157 if (dwIsr & ISR_SOFTTIMER1) // ISR, bit21
158 pStatistic->ISRStat.dwIsrSTIMER1Int++;
164 * Description: Update Rx Statistic Counter
168 * pStatistic - Pointer to Statistic Counter Data Structure
170 * byNewRSR - Rx Status
171 * pbyBuffer - Rx Buffer
172 * cbFrameLength - Rx Length
179 void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
180 unsigned char byRSR, unsigned char byNewRSR, unsigned char byRxRate,
181 unsigned char *pbyBuffer, unsigned int cbFrameLength)
184 PS802_11Header pHeader = (PS802_11Header)pbyBuffer;
186 if (byRSR & RSR_ADDROK)
187 pStatistic->dwRsrADDROk++;
188 if (byRSR & RSR_CRCOK) {
189 pStatistic->dwRsrCRCOk++;
191 pStatistic->ullRsrOK++;
193 if (cbFrameLength >= ETH_ALEN) {
194 // update counters in case of successful transmit
195 if (byRSR & RSR_ADDRBROAD) {
196 pStatistic->ullRxBroadcastFrames++;
197 pStatistic->ullRxBroadcastBytes += (unsigned long long) cbFrameLength;
198 } else if (byRSR & RSR_ADDRMULTI) {
199 pStatistic->ullRxMulticastFrames++;
200 pStatistic->ullRxMulticastBytes += (unsigned long long) cbFrameLength;
202 pStatistic->ullRxDirectedFrames++;
203 pStatistic->ullRxDirectedBytes += (unsigned long long) cbFrameLength;
208 if (byRxRate == 22) {
209 pStatistic->CustomStat.ullRsr11M++;
210 if (byRSR & RSR_CRCOK) {
211 pStatistic->CustomStat.ullRsr11MCRCOk++;
213 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "11M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr11M, (int)pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
214 } else if (byRxRate == 11) {
215 pStatistic->CustomStat.ullRsr5M++;
216 if (byRSR & RSR_CRCOK) {
217 pStatistic->CustomStat.ullRsr5MCRCOk++;
219 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 5M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr5M, (int)pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
220 } else if (byRxRate == 4) {
221 pStatistic->CustomStat.ullRsr2M++;
222 if (byRSR & RSR_CRCOK) {
223 pStatistic->CustomStat.ullRsr2MCRCOk++;
225 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 2M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr2M, (int)pStatistic->CustomStat.ullRsr2MCRCOk, byRSR);
226 } else if (byRxRate == 2) {
227 pStatistic->CustomStat.ullRsr1M++;
228 if (byRSR & RSR_CRCOK) {
229 pStatistic->CustomStat.ullRsr1MCRCOk++;
231 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 1M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr1M, (int)pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
232 } else if (byRxRate == 12) {
233 pStatistic->CustomStat.ullRsr6M++;
234 if (byRSR & RSR_CRCOK) {
235 pStatistic->CustomStat.ullRsr6MCRCOk++;
237 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 6M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr6M, (int)pStatistic->CustomStat.ullRsr6MCRCOk);
238 } else if (byRxRate == 18) {
239 pStatistic->CustomStat.ullRsr9M++;
240 if (byRSR & RSR_CRCOK) {
241 pStatistic->CustomStat.ullRsr9MCRCOk++;
243 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 9M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr9M, (int)pStatistic->CustomStat.ullRsr9MCRCOk);
244 } else if (byRxRate == 24) {
245 pStatistic->CustomStat.ullRsr12M++;
246 if (byRSR & RSR_CRCOK) {
247 pStatistic->CustomStat.ullRsr12MCRCOk++;
249 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "12M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr12M, (int)pStatistic->CustomStat.ullRsr12MCRCOk);
250 } else if (byRxRate == 36) {
251 pStatistic->CustomStat.ullRsr18M++;
252 if (byRSR & RSR_CRCOK) {
253 pStatistic->CustomStat.ullRsr18MCRCOk++;
255 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "18M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr18M, (int)pStatistic->CustomStat.ullRsr18MCRCOk);
256 } else if (byRxRate == 48) {
257 pStatistic->CustomStat.ullRsr24M++;
258 if (byRSR & RSR_CRCOK) {
259 pStatistic->CustomStat.ullRsr24MCRCOk++;
261 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "24M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr24M, (int)pStatistic->CustomStat.ullRsr24MCRCOk);
262 } else if (byRxRate == 72) {
263 pStatistic->CustomStat.ullRsr36M++;
264 if (byRSR & RSR_CRCOK) {
265 pStatistic->CustomStat.ullRsr36MCRCOk++;
267 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "36M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr36M, (int)pStatistic->CustomStat.ullRsr36MCRCOk);
268 } else if (byRxRate == 96) {
269 pStatistic->CustomStat.ullRsr48M++;
270 if (byRSR & RSR_CRCOK) {
271 pStatistic->CustomStat.ullRsr48MCRCOk++;
273 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "48M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr48M, (int)pStatistic->CustomStat.ullRsr48MCRCOk);
274 } else if (byRxRate == 108) {
275 pStatistic->CustomStat.ullRsr54M++;
276 if (byRSR & RSR_CRCOK) {
277 pStatistic->CustomStat.ullRsr54MCRCOk++;
279 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "54M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr54M, (int)pStatistic->CustomStat.ullRsr54MCRCOk);
281 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Unknown: Total[%d], CRCOK[%d]\n", (int)pStatistic->dwRsrRxPacket+1, (int)pStatistic->dwRsrCRCOk);
284 if (byRSR & RSR_BSSIDOK)
285 pStatistic->dwRsrBSSIDOk++;
287 if (byRSR & RSR_BCNSSIDOK)
288 pStatistic->dwRsrBCNSSIDOk++;
289 if (byRSR & RSR_IVLDLEN) //invalid len (> 2312 byte)
290 pStatistic->dwRsrLENErr++;
291 if (byRSR & RSR_IVLDTYP) //invalid packet type
292 pStatistic->dwRsrTYPErr++;
293 if (byRSR & (RSR_IVLDTYP | RSR_IVLDLEN))
294 pStatistic->dwRsrErr++;
296 if (byNewRSR & NEWRSR_DECRYPTOK)
297 pStatistic->dwNewRsrDECRYPTOK++;
298 if (byNewRSR & NEWRSR_CFPIND)
299 pStatistic->dwNewRsrCFP++;
300 if (byNewRSR & NEWRSR_HWUTSF)
301 pStatistic->dwNewRsrUTSF++;
302 if (byNewRSR & NEWRSR_BCNHITAID)
303 pStatistic->dwNewRsrHITAID++;
304 if (byNewRSR & NEWRSR_BCNHITAID0)
305 pStatistic->dwNewRsrHITAID0++;
307 // increase rx packet count
308 pStatistic->dwRsrRxPacket++;
309 pStatistic->dwRsrRxOctet += cbFrameLength;
312 if (IS_TYPE_DATA(pbyBuffer)) {
313 pStatistic->dwRsrRxData++;
314 } else if (IS_TYPE_MGMT(pbyBuffer)) {
315 pStatistic->dwRsrRxManage++;
316 } else if (IS_TYPE_CONTROL(pbyBuffer)) {
317 pStatistic->dwRsrRxControl++;
320 if (byRSR & RSR_ADDRBROAD)
321 pStatistic->dwRsrBroadcast++;
322 else if (byRSR & RSR_ADDRMULTI)
323 pStatistic->dwRsrMulticast++;
325 pStatistic->dwRsrDirected++;
327 if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
328 pStatistic->dwRsrRxFragment++;
330 if (cbFrameLength < ETH_ZLEN + 4) {
331 pStatistic->dwRsrRunt++;
332 } else if (cbFrameLength == ETH_ZLEN + 4) {
333 pStatistic->dwRsrRxFrmLen64++;
334 } else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
335 pStatistic->dwRsrRxFrmLen65_127++;
336 } else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
337 pStatistic->dwRsrRxFrmLen128_255++;
338 } else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
339 pStatistic->dwRsrRxFrmLen256_511++;
340 } else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023)) {
341 pStatistic->dwRsrRxFrmLen512_1023++;
342 } else if ((1024 <= cbFrameLength) && (cbFrameLength <= ETH_FRAME_LEN + 4)) {
343 pStatistic->dwRsrRxFrmLen1024_1518++;
344 } else if (cbFrameLength > ETH_FRAME_LEN + 4) {
345 pStatistic->dwRsrLong++;
353 * Description: Update Rx Statistic Counter and copy Rx buffer
357 * pStatistic - Pointer to Statistic Counter Data Structure
359 * byNewRSR - Rx Status
360 * pbyBuffer - Rx Buffer
361 * cbFrameLength - Rx Length
370 STAvUpdateRDStatCounterEx(
371 PSStatCounter pStatistic,
373 unsigned char byNewRSR,
374 unsigned char byRxRate,
375 unsigned char *pbyBuffer,
376 unsigned int cbFrameLength
379 STAvUpdateRDStatCounter(
389 pStatistic->dwCntRxFrmLength = cbFrameLength;
390 // rx pattern, we just see 10 bytes for sample
391 memcpy(pStatistic->abyCntRxPattern, (unsigned char *)pbyBuffer, 10);
396 * Description: Update Tx Statistic Counter
400 * pStatistic - Pointer to Statistic Counter Data Structure
403 * pbyBuffer - Tx Buffer
404 * cbFrameLength - Tx Length
405 * uIdx - Index of Tx DMA
413 STAvUpdateTDStatCounter(
414 PSStatCounter pStatistic,
415 unsigned char byTSR0,
416 unsigned char byTSR1,
417 unsigned char *pbyBuffer,
418 unsigned int cbFrameLength,
422 PWLAN_80211HDR_A4 pHeader;
423 unsigned char *pbyDestAddr;
424 unsigned char byTSR0_NCR = byTSR0 & TSR0_NCR;
428 pHeader = (PWLAN_80211HDR_A4) pbyBuffer;
429 if (WLAN_GET_FC_TODS(pHeader->wFrameCtl) == 0) {
430 pbyDestAddr = &(pHeader->abyAddr1[0]);
432 pbyDestAddr = &(pHeader->abyAddr3[0]);
434 // increase tx packet count
435 pStatistic->dwTsrTxPacket[uIdx]++;
436 pStatistic->dwTsrTxOctet[uIdx] += cbFrameLength;
438 if (byTSR0_NCR != 0) {
439 pStatistic->dwTsrRetry[uIdx]++;
440 pStatistic->dwTsrTotalRetry[uIdx] += byTSR0_NCR;
443 pStatistic->dwTsrOnceRetry[uIdx]++;
445 pStatistic->dwTsrMoreThanOnceRetry[uIdx]++;
448 if ((byTSR1&(TSR1_TERR|TSR1_RETRYTMO|TSR1_TMO|ACK_DATA)) == 0) {
449 pStatistic->ullTsrOK[uIdx]++;
450 pStatistic->CustomStat.ullTsrAllOK =
451 (pStatistic->ullTsrOK[TYPE_AC0DMA] + pStatistic->ullTsrOK[TYPE_TXDMA0]);
452 // update counters in case that successful transmit
453 if (is_broadcast_ether_addr(pbyDestAddr)) {
454 pStatistic->ullTxBroadcastFrames[uIdx]++;
455 pStatistic->ullTxBroadcastBytes[uIdx] += (unsigned long long) cbFrameLength;
456 } else if (is_multicast_ether_addr(pbyDestAddr)) {
457 pStatistic->ullTxMulticastFrames[uIdx]++;
458 pStatistic->ullTxMulticastBytes[uIdx] += (unsigned long long) cbFrameLength;
460 pStatistic->ullTxDirectedFrames[uIdx]++;
461 pStatistic->ullTxDirectedBytes[uIdx] += (unsigned long long) cbFrameLength;
464 if (byTSR1 & TSR1_TERR)
465 pStatistic->dwTsrErr[uIdx]++;
466 if (byTSR1 & TSR1_RETRYTMO)
467 pStatistic->dwTsrRetryTimeout[uIdx]++;
468 if (byTSR1 & TSR1_TMO)
469 pStatistic->dwTsrTransmitTimeout[uIdx]++;
470 if (byTSR1 & ACK_DATA)
471 pStatistic->dwTsrACKData[uIdx]++;
474 if (is_broadcast_ether_addr(pbyDestAddr))
475 pStatistic->dwTsrBroadcast[uIdx]++;
476 else if (is_multicast_ether_addr(pbyDestAddr))
477 pStatistic->dwTsrMulticast[uIdx]++;
479 pStatistic->dwTsrDirected[uIdx]++;
485 * Description: Update Tx Statistic Counter and copy Tx buffer
489 * pStatistic - Pointer to Statistic Counter Data Structure
490 * pbyBuffer - Tx Buffer
491 * cbFrameLength - Tx Length
499 STAvUpdateTDStatCounterEx(
500 PSStatCounter pStatistic,
501 unsigned char *pbyBuffer,
502 unsigned long cbFrameLength
505 unsigned int uPktLength;
507 uPktLength = (unsigned int)cbFrameLength;
510 pStatistic->dwCntTxBufLength = uPktLength;
511 // tx pattern, we just see 16 bytes for sample
512 memcpy(pStatistic->abyCntTxPattern, pbyBuffer, 16);
517 * Description: Update 802.11 mib counter
521 * p802_11Counter - Pointer to 802.11 mib counter
522 * pStatistic - Pointer to Statistic Counter Data Structure
523 * dwCounter - hardware counter for 802.11 mib
531 STAvUpdate802_11Counter(
532 PSDot11Counters p802_11Counter,
533 PSStatCounter pStatistic,
534 unsigned long dwCounter
537 //p802_11Counter->TransmittedFragmentCount
538 p802_11Counter->MulticastTransmittedFrameCount = (unsigned long long) (pStatistic->dwTsrBroadcast[TYPE_AC0DMA] +
539 pStatistic->dwTsrBroadcast[TYPE_TXDMA0] +
540 pStatistic->dwTsrMulticast[TYPE_AC0DMA] +
541 pStatistic->dwTsrMulticast[TYPE_TXDMA0]);
542 p802_11Counter->FailedCount = (unsigned long long) (pStatistic->dwTsrErr[TYPE_AC0DMA] + pStatistic->dwTsrErr[TYPE_TXDMA0]);
543 p802_11Counter->RetryCount = (unsigned long long) (pStatistic->dwTsrRetry[TYPE_AC0DMA] + pStatistic->dwTsrRetry[TYPE_TXDMA0]);
544 p802_11Counter->MultipleRetryCount = (unsigned long long) (pStatistic->dwTsrMoreThanOnceRetry[TYPE_AC0DMA] +
545 pStatistic->dwTsrMoreThanOnceRetry[TYPE_TXDMA0]);
546 //p802_11Counter->FrameDuplicateCount
547 p802_11Counter->RTSSuccessCount += (unsigned long long) (dwCounter & 0x000000ff);
548 p802_11Counter->RTSFailureCount += (unsigned long long) ((dwCounter & 0x0000ff00) >> 8);
549 p802_11Counter->ACKFailureCount += (unsigned long long) ((dwCounter & 0x00ff0000) >> 16);
550 p802_11Counter->FCSErrorCount += (unsigned long long) ((dwCounter & 0xff000000) >> 24);
551 //p802_11Counter->ReceivedFragmentCount
552 p802_11Counter->MulticastReceivedFrameCount = (unsigned long long) (pStatistic->dwRsrBroadcast +
553 pStatistic->dwRsrMulticast);
557 * Description: Clear 802.11 mib counter
561 * p802_11Counter - Pointer to 802.11 mib counter
569 STAvClear802_11Counter(PSDot11Counters p802_11Counter)
571 // set memory to zero
572 memset(p802_11Counter, 0, sizeof(SDot11Counters));