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 Classes ----------------------------*/
49 /*--------------------- Static Variables --------------------------*/
51 /*--------------------- Static Functions --------------------------*/
53 /*--------------------- Export Variables --------------------------*/
55 /*--------------------- Export Functions --------------------------*/
58 * Description: Clear All Statistic Counter
62 * pStatistic - Pointer to Statistic Counter Data Structure
69 void STAvClearAllCounter(PSStatCounter pStatistic)
72 memset(pStatistic, 0, sizeof(SStatCounter));
76 * Description: Update Isr Statistic Counter
80 * pStatistic - Pointer to Statistic Counter Data Structure
81 * wisr - Interrupt status
88 void STAvUpdateIsrStatCounter(PSStatCounter pStatistic, unsigned long dwIsr)
90 /**********************/
91 /* ABNORMAL interrupt */
92 /**********************/
93 // not any IMR bit invoke irq
96 pStatistic->ISRStat.dwIsrUnknown++;
101 if (dwIsr & ISR_TXDMA0) // ISR, bit0
102 pStatistic->ISRStat.dwIsrTx0OK++; // TXDMA0 successful
104 if (dwIsr & ISR_AC0DMA) // ISR, bit1
105 pStatistic->ISRStat.dwIsrAC0TxOK++; // AC0DMA successful
107 if (dwIsr & ISR_BNTX) // ISR, bit2
108 pStatistic->ISRStat.dwIsrBeaconTxOK++; // BeaconTx successful
110 if (dwIsr & ISR_RXDMA0) // ISR, bit3
111 pStatistic->ISRStat.dwIsrRx0OK++; // Rx0 successful
113 if (dwIsr & ISR_TBTT) // ISR, bit4
114 pStatistic->ISRStat.dwIsrTBTTInt++; // TBTT successful
116 if (dwIsr & ISR_SOFTTIMER) // ISR, bit6
117 pStatistic->ISRStat.dwIsrSTIMERInt++;
119 if (dwIsr & ISR_WATCHDOG) // ISR, bit7
120 pStatistic->ISRStat.dwIsrWatchDog++;
122 if (dwIsr & ISR_FETALERR) // ISR, bit8
123 pStatistic->ISRStat.dwIsrUnrecoverableError++;
125 if (dwIsr & ISR_SOFTINT) // ISR, bit9
126 pStatistic->ISRStat.dwIsrSoftInterrupt++; // software interrupt
128 if (dwIsr & ISR_MIBNEARFULL) // ISR, bit10
129 pStatistic->ISRStat.dwIsrMIBNearfull++;
131 if (dwIsr & ISR_RXNOBUF) // ISR, bit11
132 pStatistic->ISRStat.dwIsrRxNoBuf++; // Rx No Buff
134 if (dwIsr & ISR_RXDMA1) // ISR, bit12
135 pStatistic->ISRStat.dwIsrRx1OK++; // Rx1 successful
137 if (dwIsr & ISR_SOFTTIMER1) // ISR, bit21
138 pStatistic->ISRStat.dwIsrSTIMER1Int++;
142 * Description: Update Rx Statistic Counter
146 * pStatistic - Pointer to Statistic Counter Data Structure
148 * byNewRSR - Rx Status
149 * pbyBuffer - Rx Buffer
150 * cbFrameLength - Rx Length
157 void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
158 unsigned char byRSR, unsigned char byNewRSR, unsigned char byRxRate,
159 unsigned char *pbyBuffer, unsigned int cbFrameLength)
162 PS802_11Header pHeader = (PS802_11Header)pbyBuffer;
164 if (byRSR & RSR_ADDROK)
165 pStatistic->dwRsrADDROk++;
166 if (byRSR & RSR_CRCOK) {
167 pStatistic->dwRsrCRCOk++;
169 pStatistic->ullRsrOK++;
171 if (cbFrameLength >= ETH_ALEN) {
172 // update counters in case of successful transmit
173 if (byRSR & RSR_ADDRBROAD) {
174 pStatistic->ullRxBroadcastFrames++;
175 pStatistic->ullRxBroadcastBytes += (unsigned long long) cbFrameLength;
176 } else if (byRSR & RSR_ADDRMULTI) {
177 pStatistic->ullRxMulticastFrames++;
178 pStatistic->ullRxMulticastBytes += (unsigned long long) cbFrameLength;
180 pStatistic->ullRxDirectedFrames++;
181 pStatistic->ullRxDirectedBytes += (unsigned long long) cbFrameLength;
186 if (byRxRate == 22) {
187 pStatistic->CustomStat.ullRsr11M++;
188 if (byRSR & RSR_CRCOK)
189 pStatistic->CustomStat.ullRsr11MCRCOk++;
191 pr_debug("11M: ALL[%d], OK[%d]:[%02x]\n",
192 (int)pStatistic->CustomStat.ullRsr11M,
193 (int)pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
194 } else if (byRxRate == 11) {
195 pStatistic->CustomStat.ullRsr5M++;
196 if (byRSR & RSR_CRCOK)
197 pStatistic->CustomStat.ullRsr5MCRCOk++;
199 pr_debug(" 5M: ALL[%d], OK[%d]:[%02x]\n",
200 (int)pStatistic->CustomStat.ullRsr5M,
201 (int)pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
202 } else if (byRxRate == 4) {
203 pStatistic->CustomStat.ullRsr2M++;
204 if (byRSR & RSR_CRCOK)
205 pStatistic->CustomStat.ullRsr2MCRCOk++;
207 pr_debug(" 2M: ALL[%d], OK[%d]:[%02x]\n",
208 (int)pStatistic->CustomStat.ullRsr2M,
209 (int)pStatistic->CustomStat.ullRsr2MCRCOk, byRSR);
210 } else if (byRxRate == 2) {
211 pStatistic->CustomStat.ullRsr1M++;
212 if (byRSR & RSR_CRCOK)
213 pStatistic->CustomStat.ullRsr1MCRCOk++;
215 pr_debug(" 1M: ALL[%d], OK[%d]:[%02x]\n",
216 (int)pStatistic->CustomStat.ullRsr1M,
217 (int)pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
218 } else if (byRxRate == 12) {
219 pStatistic->CustomStat.ullRsr6M++;
220 if (byRSR & RSR_CRCOK)
221 pStatistic->CustomStat.ullRsr6MCRCOk++;
223 pr_debug(" 6M: ALL[%d], OK[%d]\n",
224 (int)pStatistic->CustomStat.ullRsr6M,
225 (int)pStatistic->CustomStat.ullRsr6MCRCOk);
226 } else if (byRxRate == 18) {
227 pStatistic->CustomStat.ullRsr9M++;
228 if (byRSR & RSR_CRCOK)
229 pStatistic->CustomStat.ullRsr9MCRCOk++;
231 pr_debug(" 9M: ALL[%d], OK[%d]\n",
232 (int)pStatistic->CustomStat.ullRsr9M,
233 (int)pStatistic->CustomStat.ullRsr9MCRCOk);
234 } else if (byRxRate == 24) {
235 pStatistic->CustomStat.ullRsr12M++;
236 if (byRSR & RSR_CRCOK)
237 pStatistic->CustomStat.ullRsr12MCRCOk++;
239 pr_debug("12M: ALL[%d], OK[%d]\n",
240 (int)pStatistic->CustomStat.ullRsr12M,
241 (int)pStatistic->CustomStat.ullRsr12MCRCOk);
242 } else if (byRxRate == 36) {
243 pStatistic->CustomStat.ullRsr18M++;
244 if (byRSR & RSR_CRCOK)
245 pStatistic->CustomStat.ullRsr18MCRCOk++;
247 pr_debug("18M: ALL[%d], OK[%d]\n",
248 (int)pStatistic->CustomStat.ullRsr18M,
249 (int)pStatistic->CustomStat.ullRsr18MCRCOk);
250 } else if (byRxRate == 48) {
251 pStatistic->CustomStat.ullRsr24M++;
252 if (byRSR & RSR_CRCOK)
253 pStatistic->CustomStat.ullRsr24MCRCOk++;
255 pr_debug("24M: ALL[%d], OK[%d]\n",
256 (int)pStatistic->CustomStat.ullRsr24M,
257 (int)pStatistic->CustomStat.ullRsr24MCRCOk);
258 } else if (byRxRate == 72) {
259 pStatistic->CustomStat.ullRsr36M++;
260 if (byRSR & RSR_CRCOK)
261 pStatistic->CustomStat.ullRsr36MCRCOk++;
263 pr_debug("36M: ALL[%d], OK[%d]\n",
264 (int)pStatistic->CustomStat.ullRsr36M,
265 (int)pStatistic->CustomStat.ullRsr36MCRCOk);
266 } else if (byRxRate == 96) {
267 pStatistic->CustomStat.ullRsr48M++;
268 if (byRSR & RSR_CRCOK)
269 pStatistic->CustomStat.ullRsr48MCRCOk++;
271 pr_debug("48M: ALL[%d], OK[%d]\n",
272 (int)pStatistic->CustomStat.ullRsr48M,
273 (int)pStatistic->CustomStat.ullRsr48MCRCOk);
274 } else if (byRxRate == 108) {
275 pStatistic->CustomStat.ullRsr54M++;
276 if (byRSR & RSR_CRCOK)
277 pStatistic->CustomStat.ullRsr54MCRCOk++;
279 pr_debug("54M: ALL[%d], OK[%d]\n",
280 (int)pStatistic->CustomStat.ullRsr54M,
281 (int)pStatistic->CustomStat.ullRsr54MCRCOk);
283 pr_debug("Unknown: Total[%d], CRCOK[%d]\n",
284 (int)pStatistic->dwRsrRxPacket+1,
285 (int)pStatistic->dwRsrCRCOk);
288 if (byRSR & RSR_BSSIDOK)
289 pStatistic->dwRsrBSSIDOk++;
291 if (byRSR & RSR_BCNSSIDOK)
292 pStatistic->dwRsrBCNSSIDOk++;
293 if (byRSR & RSR_IVLDLEN) //invalid len (> 2312 byte)
294 pStatistic->dwRsrLENErr++;
295 if (byRSR & RSR_IVLDTYP) //invalid packet type
296 pStatistic->dwRsrTYPErr++;
297 if (byRSR & (RSR_IVLDTYP | RSR_IVLDLEN))
298 pStatistic->dwRsrErr++;
300 if (byNewRSR & NEWRSR_DECRYPTOK)
301 pStatistic->dwNewRsrDECRYPTOK++;
302 if (byNewRSR & NEWRSR_CFPIND)
303 pStatistic->dwNewRsrCFP++;
304 if (byNewRSR & NEWRSR_HWUTSF)
305 pStatistic->dwNewRsrUTSF++;
306 if (byNewRSR & NEWRSR_BCNHITAID)
307 pStatistic->dwNewRsrHITAID++;
308 if (byNewRSR & NEWRSR_BCNHITAID0)
309 pStatistic->dwNewRsrHITAID0++;
311 // increase rx packet count
312 pStatistic->dwRsrRxPacket++;
313 pStatistic->dwRsrRxOctet += cbFrameLength;
315 if (IS_TYPE_DATA(pbyBuffer))
316 pStatistic->dwRsrRxData++;
317 else if (IS_TYPE_MGMT(pbyBuffer))
318 pStatistic->dwRsrRxManage++;
319 else if (IS_TYPE_CONTROL(pbyBuffer))
320 pStatistic->dwRsrRxControl++;
322 if (byRSR & RSR_ADDRBROAD)
323 pStatistic->dwRsrBroadcast++;
324 else if (byRSR & RSR_ADDRMULTI)
325 pStatistic->dwRsrMulticast++;
327 pStatistic->dwRsrDirected++;
329 if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
330 pStatistic->dwRsrRxFragment++;
332 if (cbFrameLength < ETH_ZLEN + 4)
333 pStatistic->dwRsrRunt++;
334 else if (cbFrameLength == ETH_ZLEN + 4)
335 pStatistic->dwRsrRxFrmLen64++;
336 else if ((65 <= cbFrameLength) && (cbFrameLength <= 127))
337 pStatistic->dwRsrRxFrmLen65_127++;
338 else if ((128 <= cbFrameLength) && (cbFrameLength <= 255))
339 pStatistic->dwRsrRxFrmLen128_255++;
340 else if ((256 <= cbFrameLength) && (cbFrameLength <= 511))
341 pStatistic->dwRsrRxFrmLen256_511++;
342 else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023))
343 pStatistic->dwRsrRxFrmLen512_1023++;
344 else if ((1024 <= cbFrameLength) && (cbFrameLength <= ETH_FRAME_LEN + 4))
345 pStatistic->dwRsrRxFrmLen1024_1518++;
346 else if (cbFrameLength > ETH_FRAME_LEN + 4)
347 pStatistic->dwRsrLong++;
351 * Description: Update Rx Statistic Counter and copy Rx buffer
355 * pStatistic - Pointer to Statistic Counter Data Structure
357 * byNewRSR - Rx Status
358 * pbyBuffer - Rx Buffer
359 * cbFrameLength - Rx Length
368 STAvUpdateRDStatCounterEx(
369 PSStatCounter pStatistic,
371 unsigned char byNewRSR,
372 unsigned char byRxRate,
373 unsigned char *pbyBuffer,
374 unsigned int cbFrameLength
377 STAvUpdateRDStatCounter(
387 pStatistic->dwCntRxFrmLength = cbFrameLength;
388 // rx pattern, we just see 10 bytes for sample
389 memcpy(pStatistic->abyCntRxPattern, (unsigned char *)pbyBuffer, 10);
393 * Description: Update Tx Statistic Counter
397 * pStatistic - Pointer to Statistic Counter Data Structure
400 * pbyBuffer - Tx Buffer
401 * cbFrameLength - Tx Length
402 * uIdx - Index of Tx DMA
410 STAvUpdateTDStatCounter(
411 PSStatCounter pStatistic,
412 unsigned char byTSR0,
413 unsigned char byTSR1,
414 unsigned char *pbyBuffer,
415 unsigned int cbFrameLength,
419 PWLAN_80211HDR_A4 pHeader;
420 unsigned char *pbyDestAddr;
421 unsigned char byTSR0_NCR = byTSR0 & TSR0_NCR;
423 pHeader = (PWLAN_80211HDR_A4) pbyBuffer;
424 if (WLAN_GET_FC_TODS(pHeader->wFrameCtl) == 0)
425 pbyDestAddr = &(pHeader->abyAddr1[0]);
427 pbyDestAddr = &(pHeader->abyAddr3[0]);
429 // increase tx packet count
430 pStatistic->dwTsrTxPacket[uIdx]++;
431 pStatistic->dwTsrTxOctet[uIdx] += cbFrameLength;
433 if (byTSR0_NCR != 0) {
434 pStatistic->dwTsrRetry[uIdx]++;
435 pStatistic->dwTsrTotalRetry[uIdx] += byTSR0_NCR;
438 pStatistic->dwTsrOnceRetry[uIdx]++;
440 pStatistic->dwTsrMoreThanOnceRetry[uIdx]++;
443 if ((byTSR1&(TSR1_TERR|TSR1_RETRYTMO|TSR1_TMO|ACK_DATA)) == 0) {
444 pStatistic->ullTsrOK[uIdx]++;
445 pStatistic->CustomStat.ullTsrAllOK =
446 (pStatistic->ullTsrOK[TYPE_AC0DMA] + pStatistic->ullTsrOK[TYPE_TXDMA0]);
447 // update counters in case that successful transmit
448 if (is_broadcast_ether_addr(pbyDestAddr)) {
449 pStatistic->ullTxBroadcastFrames[uIdx]++;
450 pStatistic->ullTxBroadcastBytes[uIdx] += (unsigned long long) cbFrameLength;
451 } else if (is_multicast_ether_addr(pbyDestAddr)) {
452 pStatistic->ullTxMulticastFrames[uIdx]++;
453 pStatistic->ullTxMulticastBytes[uIdx] += (unsigned long long) cbFrameLength;
455 pStatistic->ullTxDirectedFrames[uIdx]++;
456 pStatistic->ullTxDirectedBytes[uIdx] += (unsigned long long) cbFrameLength;
459 if (byTSR1 & TSR1_TERR)
460 pStatistic->dwTsrErr[uIdx]++;
461 if (byTSR1 & TSR1_RETRYTMO)
462 pStatistic->dwTsrRetryTimeout[uIdx]++;
463 if (byTSR1 & TSR1_TMO)
464 pStatistic->dwTsrTransmitTimeout[uIdx]++;
465 if (byTSR1 & ACK_DATA)
466 pStatistic->dwTsrACKData[uIdx]++;
469 if (is_broadcast_ether_addr(pbyDestAddr))
470 pStatistic->dwTsrBroadcast[uIdx]++;
471 else if (is_multicast_ether_addr(pbyDestAddr))
472 pStatistic->dwTsrMulticast[uIdx]++;
474 pStatistic->dwTsrDirected[uIdx]++;
478 * Description: Update Tx Statistic Counter and copy Tx buffer
482 * pStatistic - Pointer to Statistic Counter Data Structure
483 * pbyBuffer - Tx Buffer
484 * cbFrameLength - Tx Length
492 STAvUpdateTDStatCounterEx(
493 PSStatCounter pStatistic,
494 unsigned char *pbyBuffer,
495 unsigned long cbFrameLength
498 unsigned int uPktLength;
500 uPktLength = (unsigned int)cbFrameLength;
503 pStatistic->dwCntTxBufLength = uPktLength;
504 // tx pattern, we just see 16 bytes for sample
505 memcpy(pStatistic->abyCntTxPattern, pbyBuffer, 16);
509 * Description: Update 802.11 mib counter
513 * p802_11Counter - Pointer to 802.11 mib counter
514 * pStatistic - Pointer to Statistic Counter Data Structure
515 * dwCounter - hardware counter for 802.11 mib
523 STAvUpdate802_11Counter(
524 PSDot11Counters p802_11Counter,
525 PSStatCounter pStatistic,
526 unsigned long dwCounter
529 p802_11Counter->MulticastTransmittedFrameCount = (unsigned long long) (pStatistic->dwTsrBroadcast[TYPE_AC0DMA] +
530 pStatistic->dwTsrBroadcast[TYPE_TXDMA0] +
531 pStatistic->dwTsrMulticast[TYPE_AC0DMA] +
532 pStatistic->dwTsrMulticast[TYPE_TXDMA0]);
533 p802_11Counter->FailedCount = (unsigned long long) (pStatistic->dwTsrErr[TYPE_AC0DMA] + pStatistic->dwTsrErr[TYPE_TXDMA0]);
534 p802_11Counter->RetryCount = (unsigned long long) (pStatistic->dwTsrRetry[TYPE_AC0DMA] + pStatistic->dwTsrRetry[TYPE_TXDMA0]);
535 p802_11Counter->MultipleRetryCount = (unsigned long long) (pStatistic->dwTsrMoreThanOnceRetry[TYPE_AC0DMA] +
536 pStatistic->dwTsrMoreThanOnceRetry[TYPE_TXDMA0]);
537 p802_11Counter->RTSSuccessCount += (unsigned long long) (dwCounter & 0x000000ff);
538 p802_11Counter->RTSFailureCount += (unsigned long long) ((dwCounter & 0x0000ff00) >> 8);
539 p802_11Counter->ACKFailureCount += (unsigned long long) ((dwCounter & 0x00ff0000) >> 16);
540 p802_11Counter->FCSErrorCount += (unsigned long long) ((dwCounter & 0xff000000) >> 24);
541 p802_11Counter->MulticastReceivedFrameCount = (unsigned long long) (pStatistic->dwRsrBroadcast +
542 pStatistic->dwRsrMulticast);
546 * Description: Clear 802.11 mib counter
550 * p802_11Counter - Pointer to 802.11 mib counter
558 STAvClear802_11Counter(PSDot11Counters p802_11Counter)
560 // set memory to zero
561 memset(p802_11Counter, 0, sizeof(SDot11Counters));