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_SOFTTIMER1) // ISR, bit21
143 pStatistic->ISRStat.dwIsrSTIMER1Int++;
149 * Description: Update Rx Statistic Counter
153 * pStatistic - Pointer to Statistic Counter Data Structure
155 * byNewRSR - Rx Status
156 * pbyBuffer - Rx Buffer
157 * cbFrameLength - Rx Length
164 void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
165 unsigned char byRSR, unsigned char byNewRSR, unsigned char byRxRate,
166 unsigned char *pbyBuffer, unsigned int cbFrameLength)
169 PS802_11Header pHeader = (PS802_11Header)pbyBuffer;
171 if (byRSR & RSR_ADDROK)
172 pStatistic->dwRsrADDROk++;
173 if (byRSR & RSR_CRCOK) {
174 pStatistic->dwRsrCRCOk++;
176 pStatistic->ullRsrOK++;
178 if (cbFrameLength >= ETH_ALEN) {
179 // update counters in case of successful transmit
180 if (byRSR & RSR_ADDRBROAD) {
181 pStatistic->ullRxBroadcastFrames++;
182 pStatistic->ullRxBroadcastBytes += (unsigned long long) cbFrameLength;
183 } else if (byRSR & RSR_ADDRMULTI) {
184 pStatistic->ullRxMulticastFrames++;
185 pStatistic->ullRxMulticastBytes += (unsigned long long) cbFrameLength;
187 pStatistic->ullRxDirectedFrames++;
188 pStatistic->ullRxDirectedBytes += (unsigned long long) cbFrameLength;
193 if (byRxRate == 22) {
194 pStatistic->CustomStat.ullRsr11M++;
195 if (byRSR & RSR_CRCOK) {
196 pStatistic->CustomStat.ullRsr11MCRCOk++;
198 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "11M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr11M, (int)pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
199 } else if (byRxRate == 11) {
200 pStatistic->CustomStat.ullRsr5M++;
201 if (byRSR & RSR_CRCOK) {
202 pStatistic->CustomStat.ullRsr5MCRCOk++;
204 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 5M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr5M, (int)pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
205 } else if (byRxRate == 4) {
206 pStatistic->CustomStat.ullRsr2M++;
207 if (byRSR & RSR_CRCOK) {
208 pStatistic->CustomStat.ullRsr2MCRCOk++;
210 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 2M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr2M, (int)pStatistic->CustomStat.ullRsr2MCRCOk, byRSR);
211 } else if (byRxRate == 2) {
212 pStatistic->CustomStat.ullRsr1M++;
213 if (byRSR & RSR_CRCOK) {
214 pStatistic->CustomStat.ullRsr1MCRCOk++;
216 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 1M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr1M, (int)pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
217 } else if (byRxRate == 12) {
218 pStatistic->CustomStat.ullRsr6M++;
219 if (byRSR & RSR_CRCOK) {
220 pStatistic->CustomStat.ullRsr6MCRCOk++;
222 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 6M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr6M, (int)pStatistic->CustomStat.ullRsr6MCRCOk);
223 } else if (byRxRate == 18) {
224 pStatistic->CustomStat.ullRsr9M++;
225 if (byRSR & RSR_CRCOK) {
226 pStatistic->CustomStat.ullRsr9MCRCOk++;
228 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 9M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr9M, (int)pStatistic->CustomStat.ullRsr9MCRCOk);
229 } else if (byRxRate == 24) {
230 pStatistic->CustomStat.ullRsr12M++;
231 if (byRSR & RSR_CRCOK) {
232 pStatistic->CustomStat.ullRsr12MCRCOk++;
234 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "12M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr12M, (int)pStatistic->CustomStat.ullRsr12MCRCOk);
235 } else if (byRxRate == 36) {
236 pStatistic->CustomStat.ullRsr18M++;
237 if (byRSR & RSR_CRCOK) {
238 pStatistic->CustomStat.ullRsr18MCRCOk++;
240 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "18M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr18M, (int)pStatistic->CustomStat.ullRsr18MCRCOk);
241 } else if (byRxRate == 48) {
242 pStatistic->CustomStat.ullRsr24M++;
243 if (byRSR & RSR_CRCOK) {
244 pStatistic->CustomStat.ullRsr24MCRCOk++;
246 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "24M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr24M, (int)pStatistic->CustomStat.ullRsr24MCRCOk);
247 } else if (byRxRate == 72) {
248 pStatistic->CustomStat.ullRsr36M++;
249 if (byRSR & RSR_CRCOK) {
250 pStatistic->CustomStat.ullRsr36MCRCOk++;
252 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "36M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr36M, (int)pStatistic->CustomStat.ullRsr36MCRCOk);
253 } else if (byRxRate == 96) {
254 pStatistic->CustomStat.ullRsr48M++;
255 if (byRSR & RSR_CRCOK) {
256 pStatistic->CustomStat.ullRsr48MCRCOk++;
258 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "48M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr48M, (int)pStatistic->CustomStat.ullRsr48MCRCOk);
259 } else if (byRxRate == 108) {
260 pStatistic->CustomStat.ullRsr54M++;
261 if (byRSR & RSR_CRCOK) {
262 pStatistic->CustomStat.ullRsr54MCRCOk++;
264 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "54M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr54M, (int)pStatistic->CustomStat.ullRsr54MCRCOk);
266 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Unknown: Total[%d], CRCOK[%d]\n", (int)pStatistic->dwRsrRxPacket+1, (int)pStatistic->dwRsrCRCOk);
269 if (byRSR & RSR_BSSIDOK)
270 pStatistic->dwRsrBSSIDOk++;
272 if (byRSR & RSR_BCNSSIDOK)
273 pStatistic->dwRsrBCNSSIDOk++;
274 if (byRSR & RSR_IVLDLEN) //invalid len (> 2312 byte)
275 pStatistic->dwRsrLENErr++;
276 if (byRSR & RSR_IVLDTYP) //invalid packet type
277 pStatistic->dwRsrTYPErr++;
278 if (byRSR & (RSR_IVLDTYP | RSR_IVLDLEN))
279 pStatistic->dwRsrErr++;
281 if (byNewRSR & NEWRSR_DECRYPTOK)
282 pStatistic->dwNewRsrDECRYPTOK++;
283 if (byNewRSR & NEWRSR_CFPIND)
284 pStatistic->dwNewRsrCFP++;
285 if (byNewRSR & NEWRSR_HWUTSF)
286 pStatistic->dwNewRsrUTSF++;
287 if (byNewRSR & NEWRSR_BCNHITAID)
288 pStatistic->dwNewRsrHITAID++;
289 if (byNewRSR & NEWRSR_BCNHITAID0)
290 pStatistic->dwNewRsrHITAID0++;
292 // increase rx packet count
293 pStatistic->dwRsrRxPacket++;
294 pStatistic->dwRsrRxOctet += cbFrameLength;
297 if (IS_TYPE_DATA(pbyBuffer)) {
298 pStatistic->dwRsrRxData++;
299 } else if (IS_TYPE_MGMT(pbyBuffer)) {
300 pStatistic->dwRsrRxManage++;
301 } else if (IS_TYPE_CONTROL(pbyBuffer)) {
302 pStatistic->dwRsrRxControl++;
305 if (byRSR & RSR_ADDRBROAD)
306 pStatistic->dwRsrBroadcast++;
307 else if (byRSR & RSR_ADDRMULTI)
308 pStatistic->dwRsrMulticast++;
310 pStatistic->dwRsrDirected++;
312 if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
313 pStatistic->dwRsrRxFragment++;
315 if (cbFrameLength < ETH_ZLEN + 4) {
316 pStatistic->dwRsrRunt++;
317 } else if (cbFrameLength == ETH_ZLEN + 4) {
318 pStatistic->dwRsrRxFrmLen64++;
319 } else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
320 pStatistic->dwRsrRxFrmLen65_127++;
321 } else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
322 pStatistic->dwRsrRxFrmLen128_255++;
323 } else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
324 pStatistic->dwRsrRxFrmLen256_511++;
325 } else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023)) {
326 pStatistic->dwRsrRxFrmLen512_1023++;
327 } else if ((1024 <= cbFrameLength) && (cbFrameLength <= ETH_FRAME_LEN + 4)) {
328 pStatistic->dwRsrRxFrmLen1024_1518++;
329 } else if (cbFrameLength > ETH_FRAME_LEN + 4) {
330 pStatistic->dwRsrLong++;
338 * Description: Update Rx Statistic Counter and copy Rx buffer
342 * pStatistic - Pointer to Statistic Counter Data Structure
344 * byNewRSR - Rx Status
345 * pbyBuffer - Rx Buffer
346 * cbFrameLength - Rx Length
355 STAvUpdateRDStatCounterEx(
356 PSStatCounter pStatistic,
358 unsigned char byNewRSR,
359 unsigned char byRxRate,
360 unsigned char *pbyBuffer,
361 unsigned int cbFrameLength
364 STAvUpdateRDStatCounter(
374 pStatistic->dwCntRxFrmLength = cbFrameLength;
375 // rx pattern, we just see 10 bytes for sample
376 memcpy(pStatistic->abyCntRxPattern, (unsigned char *)pbyBuffer, 10);
381 * Description: Update Tx Statistic Counter
385 * pStatistic - Pointer to Statistic Counter Data Structure
388 * pbyBuffer - Tx Buffer
389 * cbFrameLength - Tx Length
390 * uIdx - Index of Tx DMA
398 STAvUpdateTDStatCounter(
399 PSStatCounter pStatistic,
400 unsigned char byTSR0,
401 unsigned char byTSR1,
402 unsigned char *pbyBuffer,
403 unsigned int cbFrameLength,
407 PWLAN_80211HDR_A4 pHeader;
408 unsigned char *pbyDestAddr;
409 unsigned char byTSR0_NCR = byTSR0 & TSR0_NCR;
413 pHeader = (PWLAN_80211HDR_A4) pbyBuffer;
414 if (WLAN_GET_FC_TODS(pHeader->wFrameCtl) == 0) {
415 pbyDestAddr = &(pHeader->abyAddr1[0]);
417 pbyDestAddr = &(pHeader->abyAddr3[0]);
419 // increase tx packet count
420 pStatistic->dwTsrTxPacket[uIdx]++;
421 pStatistic->dwTsrTxOctet[uIdx] += cbFrameLength;
423 if (byTSR0_NCR != 0) {
424 pStatistic->dwTsrRetry[uIdx]++;
425 pStatistic->dwTsrTotalRetry[uIdx] += byTSR0_NCR;
428 pStatistic->dwTsrOnceRetry[uIdx]++;
430 pStatistic->dwTsrMoreThanOnceRetry[uIdx]++;
433 if ((byTSR1&(TSR1_TERR|TSR1_RETRYTMO|TSR1_TMO|ACK_DATA)) == 0) {
434 pStatistic->ullTsrOK[uIdx]++;
435 pStatistic->CustomStat.ullTsrAllOK =
436 (pStatistic->ullTsrOK[TYPE_AC0DMA] + pStatistic->ullTsrOK[TYPE_TXDMA0]);
437 // update counters in case that successful transmit
438 if (is_broadcast_ether_addr(pbyDestAddr)) {
439 pStatistic->ullTxBroadcastFrames[uIdx]++;
440 pStatistic->ullTxBroadcastBytes[uIdx] += (unsigned long long) cbFrameLength;
441 } else if (is_multicast_ether_addr(pbyDestAddr)) {
442 pStatistic->ullTxMulticastFrames[uIdx]++;
443 pStatistic->ullTxMulticastBytes[uIdx] += (unsigned long long) cbFrameLength;
445 pStatistic->ullTxDirectedFrames[uIdx]++;
446 pStatistic->ullTxDirectedBytes[uIdx] += (unsigned long long) cbFrameLength;
449 if (byTSR1 & TSR1_TERR)
450 pStatistic->dwTsrErr[uIdx]++;
451 if (byTSR1 & TSR1_RETRYTMO)
452 pStatistic->dwTsrRetryTimeout[uIdx]++;
453 if (byTSR1 & TSR1_TMO)
454 pStatistic->dwTsrTransmitTimeout[uIdx]++;
455 if (byTSR1 & ACK_DATA)
456 pStatistic->dwTsrACKData[uIdx]++;
459 if (is_broadcast_ether_addr(pbyDestAddr))
460 pStatistic->dwTsrBroadcast[uIdx]++;
461 else if (is_multicast_ether_addr(pbyDestAddr))
462 pStatistic->dwTsrMulticast[uIdx]++;
464 pStatistic->dwTsrDirected[uIdx]++;
470 * Description: Update Tx Statistic Counter and copy Tx buffer
474 * pStatistic - Pointer to Statistic Counter Data Structure
475 * pbyBuffer - Tx Buffer
476 * cbFrameLength - Tx Length
484 STAvUpdateTDStatCounterEx(
485 PSStatCounter pStatistic,
486 unsigned char *pbyBuffer,
487 unsigned long cbFrameLength
490 unsigned int uPktLength;
492 uPktLength = (unsigned int)cbFrameLength;
495 pStatistic->dwCntTxBufLength = uPktLength;
496 // tx pattern, we just see 16 bytes for sample
497 memcpy(pStatistic->abyCntTxPattern, pbyBuffer, 16);
502 * Description: Update 802.11 mib counter
506 * p802_11Counter - Pointer to 802.11 mib counter
507 * pStatistic - Pointer to Statistic Counter Data Structure
508 * dwCounter - hardware counter for 802.11 mib
516 STAvUpdate802_11Counter(
517 PSDot11Counters p802_11Counter,
518 PSStatCounter pStatistic,
519 unsigned long dwCounter
522 //p802_11Counter->TransmittedFragmentCount
523 p802_11Counter->MulticastTransmittedFrameCount = (unsigned long long) (pStatistic->dwTsrBroadcast[TYPE_AC0DMA] +
524 pStatistic->dwTsrBroadcast[TYPE_TXDMA0] +
525 pStatistic->dwTsrMulticast[TYPE_AC0DMA] +
526 pStatistic->dwTsrMulticast[TYPE_TXDMA0]);
527 p802_11Counter->FailedCount = (unsigned long long) (pStatistic->dwTsrErr[TYPE_AC0DMA] + pStatistic->dwTsrErr[TYPE_TXDMA0]);
528 p802_11Counter->RetryCount = (unsigned long long) (pStatistic->dwTsrRetry[TYPE_AC0DMA] + pStatistic->dwTsrRetry[TYPE_TXDMA0]);
529 p802_11Counter->MultipleRetryCount = (unsigned long long) (pStatistic->dwTsrMoreThanOnceRetry[TYPE_AC0DMA] +
530 pStatistic->dwTsrMoreThanOnceRetry[TYPE_TXDMA0]);
531 //p802_11Counter->FrameDuplicateCount
532 p802_11Counter->RTSSuccessCount += (unsigned long long) (dwCounter & 0x000000ff);
533 p802_11Counter->RTSFailureCount += (unsigned long long) ((dwCounter & 0x0000ff00) >> 8);
534 p802_11Counter->ACKFailureCount += (unsigned long long) ((dwCounter & 0x00ff0000) >> 16);
535 p802_11Counter->FCSErrorCount += (unsigned long long) ((dwCounter & 0xff000000) >> 24);
536 //p802_11Counter->ReceivedFragmentCount
537 p802_11Counter->MulticastReceivedFrameCount = (unsigned long long) (pStatistic->dwRsrBroadcast +
538 pStatistic->dwRsrMulticast);
542 * Description: Clear 802.11 mib counter
546 * p802_11Counter - Pointer to 802.11 mib counter
554 STAvClear802_11Counter(PSDot11Counters p802_11Counter)
556 // set memory to zero
557 memset(p802_11Counter, 0, sizeof(SDot11Counters));