Merge branch 'core-locking-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[deliverable/linux.git] / drivers / staging / vt6656 / mib.c
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
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.
9 *
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.
14 *
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.
18 *
19 * File: mib.c
20 *
21 * Purpose: Implement MIB Data Structure
22 *
23 * Author: Tevin Chen
24 *
25 * Date: May 21, 1996
26 *
27 * Functions:
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
35 *
36 * Revision History:
37 *
38 */
39
40 #include "upc.h"
41 #include "mac.h"
42 #include "tether.h"
43 #include "mib.h"
44 #include "wctl.h"
45 #include "baseband.h"
46
47 /*--------------------- Static Definitions -------------------------*/
48 static int msglevel =MSG_LEVEL_INFO;
49 /*--------------------- Static Classes ----------------------------*/
50
51 /*--------------------- Static Variables --------------------------*/
52
53 /*--------------------- Static Functions --------------------------*/
54
55 /*--------------------- Export Variables --------------------------*/
56
57 /*--------------------- Export Functions --------------------------*/
58
59
60
61 /*
62 * Description: Clear All Statistic Counter
63 *
64 * Parameters:
65 * In:
66 * pStatistic - Pointer to Statistic Counter Data Structure
67 * Out:
68 * none
69 *
70 * Return Value: none
71 *
72 */
73 void STAvClearAllCounter (PSStatCounter pStatistic)
74 {
75 // set memory to zero
76 memset(pStatistic, 0, sizeof(SStatCounter));
77 }
78
79
80 /*
81 * Description: Update Isr Statistic Counter
82 *
83 * Parameters:
84 * In:
85 * pStatistic - Pointer to Statistic Counter Data Structure
86 * wisr - Interrupt status
87 * Out:
88 * none
89 *
90 * Return Value: none
91 *
92 */
93 void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, BYTE byIsr0, BYTE byIsr1)
94 {
95 /**********************/
96 /* ABNORMAL interrupt */
97 /**********************/
98 // not any IMR bit invoke irq
99 if (byIsr0 == 0) {
100 pStatistic->ISRStat.dwIsrUnknown++;
101 return;
102 }
103
104
105 if (byIsr0 & ISR_ACTX) // ISR, bit0
106 pStatistic->ISRStat.dwIsrTx0OK++; // TXDMA0 successful
107
108 if (byIsr0 & ISR_BNTX) // ISR, bit2
109 pStatistic->ISRStat.dwIsrBeaconTxOK++; // BeaconTx successful
110
111 if (byIsr0 & ISR_RXDMA0) // ISR, bit3
112 pStatistic->ISRStat.dwIsrRx0OK++; // Rx0 successful
113
114 if (byIsr0 & ISR_TBTT) // ISR, bit4
115 pStatistic->ISRStat.dwIsrTBTTInt++; // TBTT successful
116
117 if (byIsr0 & ISR_SOFTTIMER) // ISR, bit6
118 pStatistic->ISRStat.dwIsrSTIMERInt++;
119
120 if (byIsr0 & ISR_WATCHDOG) // ISR, bit7
121 pStatistic->ISRStat.dwIsrWatchDog++;
122
123
124 if (byIsr1 & ISR_FETALERR) // ISR, bit8
125 pStatistic->ISRStat.dwIsrUnrecoverableError++;
126
127 if (byIsr1 & ISR_SOFTINT) // ISR, bit9
128 pStatistic->ISRStat.dwIsrSoftInterrupt++; // software interrupt
129
130 if (byIsr1 & ISR_MIBNEARFULL) // ISR, bit10
131 pStatistic->ISRStat.dwIsrMIBNearfull++;
132
133 if (byIsr1 & ISR_RXNOBUF) // ISR, bit11
134 pStatistic->ISRStat.dwIsrRxNoBuf++; // Rx No Buff
135
136 }
137
138
139 /*
140 * Description: Update Rx Statistic Counter
141 *
142 * Parameters:
143 * In:
144 * pStatistic - Pointer to Statistic Counter Data Structure
145 * byRSR - Rx Status
146 * byNewRSR - Rx Status
147 * pbyBuffer - Rx Buffer
148 * cbFrameLength - Rx Length
149 * Out:
150 * none
151 *
152 * Return Value: none
153 *
154 */
155 void STAvUpdateRDStatCounter (PSStatCounter pStatistic,
156 BYTE byRSR, BYTE byNewRSR, BYTE byRxSts, BYTE byRxRate,
157 PBYTE pbyBuffer, UINT cbFrameLength)
158 {
159 //need change
160 PS802_11Header pHeader = (PS802_11Header)pbyBuffer;
161
162 if (byRSR & RSR_ADDROK)
163 pStatistic->dwRsrADDROk++;
164 if (byRSR & RSR_CRCOK) {
165 pStatistic->dwRsrCRCOk++;
166
167 pStatistic->ullRsrOK++;
168
169 if (cbFrameLength >= U_ETHER_ADDR_LEN) {
170 // update counters in case that successful transmit
171 if (byRSR & RSR_ADDRBROAD) {
172 pStatistic->ullRxBroadcastFrames++;
173 pStatistic->ullRxBroadcastBytes += (ULONGLONG)cbFrameLength;
174 }
175 else if (byRSR & RSR_ADDRMULTI) {
176 pStatistic->ullRxMulticastFrames++;
177 pStatistic->ullRxMulticastBytes += (ULONGLONG)cbFrameLength;
178 }
179 else {
180 pStatistic->ullRxDirectedFrames++;
181 pStatistic->ullRxDirectedBytes += (ULONGLONG)cbFrameLength;
182 }
183 }
184 }
185
186 if(byRxRate==22) {
187 pStatistic->CustomStat.ullRsr11M++;
188 if(byRSR & RSR_CRCOK) {
189 pStatistic->CustomStat.ullRsr11MCRCOk++;
190 }
191 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"11M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr11M, (INT)pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
192 }
193 else if(byRxRate==11) {
194 pStatistic->CustomStat.ullRsr5M++;
195 if(byRSR & RSR_CRCOK) {
196 pStatistic->CustomStat.ullRsr5MCRCOk++;
197 }
198 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 5M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr5M, (INT)pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
199 }
200 else if(byRxRate==4) {
201 pStatistic->CustomStat.ullRsr2M++;
202 if(byRSR & RSR_CRCOK) {
203 pStatistic->CustomStat.ullRsr2MCRCOk++;
204 }
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 }
207 else if(byRxRate==2){
208 pStatistic->CustomStat.ullRsr1M++;
209 if(byRSR & RSR_CRCOK) {
210 pStatistic->CustomStat.ullRsr1MCRCOk++;
211 }
212 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 1M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr1M, (INT)pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
213 }
214 else if(byRxRate==12){
215 pStatistic->CustomStat.ullRsr6M++;
216 if(byRSR & RSR_CRCOK) {
217 pStatistic->CustomStat.ullRsr6MCRCOk++;
218 }
219 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 6M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr6M, (INT)pStatistic->CustomStat.ullRsr6MCRCOk);
220 }
221 else if(byRxRate==18){
222 pStatistic->CustomStat.ullRsr9M++;
223 if(byRSR & RSR_CRCOK) {
224 pStatistic->CustomStat.ullRsr9MCRCOk++;
225 }
226 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 9M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr9M, (INT)pStatistic->CustomStat.ullRsr9MCRCOk);
227 }
228 else if(byRxRate==24){
229 pStatistic->CustomStat.ullRsr12M++;
230 if(byRSR & RSR_CRCOK) {
231 pStatistic->CustomStat.ullRsr12MCRCOk++;
232 }
233 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"12M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr12M, (INT)pStatistic->CustomStat.ullRsr12MCRCOk);
234 }
235 else if(byRxRate==36){
236 pStatistic->CustomStat.ullRsr18M++;
237 if(byRSR & RSR_CRCOK) {
238 pStatistic->CustomStat.ullRsr18MCRCOk++;
239 }
240 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"18M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr18M, (INT)pStatistic->CustomStat.ullRsr18MCRCOk);
241 }
242 else if(byRxRate==48){
243 pStatistic->CustomStat.ullRsr24M++;
244 if(byRSR & RSR_CRCOK) {
245 pStatistic->CustomStat.ullRsr24MCRCOk++;
246 }
247 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"24M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr24M, (INT)pStatistic->CustomStat.ullRsr24MCRCOk);
248 }
249 else if(byRxRate==72){
250 pStatistic->CustomStat.ullRsr36M++;
251 if(byRSR & RSR_CRCOK) {
252 pStatistic->CustomStat.ullRsr36MCRCOk++;
253 }
254 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"36M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr36M, (INT)pStatistic->CustomStat.ullRsr36MCRCOk);
255 }
256 else if(byRxRate==96){
257 pStatistic->CustomStat.ullRsr48M++;
258 if(byRSR & RSR_CRCOK) {
259 pStatistic->CustomStat.ullRsr48MCRCOk++;
260 }
261 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"48M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr48M, (INT)pStatistic->CustomStat.ullRsr48MCRCOk);
262 }
263 else if(byRxRate==108){
264 pStatistic->CustomStat.ullRsr54M++;
265 if(byRSR & RSR_CRCOK) {
266 pStatistic->CustomStat.ullRsr54MCRCOk++;
267 }
268 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"54M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr54M, (INT)pStatistic->CustomStat.ullRsr54MCRCOk);
269 }
270 else {
271 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Unknown: Total[%d], CRCOK[%d]\n", (INT)pStatistic->dwRsrRxPacket+1, (INT)pStatistic->dwRsrCRCOk);
272 }
273
274 if (byRSR & RSR_BSSIDOK)
275 pStatistic->dwRsrBSSIDOk++;
276
277 if (byRSR & RSR_BCNSSIDOK)
278 pStatistic->dwRsrBCNSSIDOk++;
279 if (byRSR & RSR_IVLDLEN) //invalid len (> 2312 byte)
280 pStatistic->dwRsrLENErr++;
281 if (byRSR & RSR_IVLDTYP) //invalid packet type
282 pStatistic->dwRsrTYPErr++;
283 if ((byRSR & (RSR_IVLDTYP | RSR_IVLDLEN)) || !(byRSR & RSR_CRCOK))
284 pStatistic->dwRsrErr++;
285
286 if (byNewRSR & NEWRSR_DECRYPTOK)
287 pStatistic->dwNewRsrDECRYPTOK++;
288 if (byNewRSR & NEWRSR_CFPIND)
289 pStatistic->dwNewRsrCFP++;
290 if (byNewRSR & NEWRSR_HWUTSF)
291 pStatistic->dwNewRsrUTSF++;
292 if (byNewRSR & NEWRSR_BCNHITAID)
293 pStatistic->dwNewRsrHITAID++;
294 if (byNewRSR & NEWRSR_BCNHITAID0)
295 pStatistic->dwNewRsrHITAID0++;
296
297 // increase rx packet count
298 pStatistic->dwRsrRxPacket++;
299 pStatistic->dwRsrRxOctet += cbFrameLength;
300
301
302 if (IS_TYPE_DATA(pbyBuffer)) {
303 pStatistic->dwRsrRxData++;
304 } else if (IS_TYPE_MGMT(pbyBuffer)){
305 pStatistic->dwRsrRxManage++;
306 } else if (IS_TYPE_CONTROL(pbyBuffer)){
307 pStatistic->dwRsrRxControl++;
308 }
309
310 if (byRSR & RSR_ADDRBROAD)
311 pStatistic->dwRsrBroadcast++;
312 else if (byRSR & RSR_ADDRMULTI)
313 pStatistic->dwRsrMulticast++;
314 else
315 pStatistic->dwRsrDirected++;
316
317 if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
318 pStatistic->dwRsrRxFragment++;
319
320 if (cbFrameLength < MIN_PACKET_LEN + 4) {
321 pStatistic->dwRsrRunt++;
322 }
323 else if (cbFrameLength == MIN_PACKET_LEN + 4) {
324 pStatistic->dwRsrRxFrmLen64++;
325 }
326 else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
327 pStatistic->dwRsrRxFrmLen65_127++;
328 }
329 else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
330 pStatistic->dwRsrRxFrmLen128_255++;
331 }
332 else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
333 pStatistic->dwRsrRxFrmLen256_511++;
334 }
335 else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023)) {
336 pStatistic->dwRsrRxFrmLen512_1023++;
337 }
338 else if ((1024 <= cbFrameLength) && (cbFrameLength <= MAX_PACKET_LEN + 4)) {
339 pStatistic->dwRsrRxFrmLen1024_1518++;
340 } else if (cbFrameLength > MAX_PACKET_LEN + 4) {
341 pStatistic->dwRsrLong++;
342 }
343
344 }
345
346
347
348 /*
349 * Description: Update Rx Statistic Counter and copy Rx buffer
350 *
351 * Parameters:
352 * In:
353 * pStatistic - Pointer to Statistic Counter Data Structure
354 * byRSR - Rx Status
355 * byNewRSR - Rx Status
356 * pbyBuffer - Rx Buffer
357 * cbFrameLength - Rx Length
358 * Out:
359 * none
360 *
361 * Return Value: none
362 *
363 */
364
365 void
366 STAvUpdateRDStatCounterEx (
367 PSStatCounter pStatistic,
368 BYTE byRSR,
369 BYTE byNewRSR,
370 BYTE byRxSts,
371 BYTE byRxRate,
372 PBYTE pbyBuffer,
373 UINT cbFrameLength
374 )
375 {
376 STAvUpdateRDStatCounter(
377 pStatistic,
378 byRSR,
379 byNewRSR,
380 byRxSts,
381 byRxRate,
382 pbyBuffer,
383 cbFrameLength
384 );
385
386 // rx length
387 pStatistic->dwCntRxFrmLength = cbFrameLength;
388 // rx pattern, we just see 10 bytes for sample
389 memcpy(pStatistic->abyCntRxPattern, (PBYTE)pbyBuffer, 10);
390 }
391
392
393 /*
394 * Description: Update Tx Statistic Counter
395 *
396 * Parameters:
397 * In:
398 * pStatistic - Pointer to Statistic Counter Data Structure
399 * byTSR0 - Tx Status
400 * byTSR1 - Tx Status
401 * pbyBuffer - Tx Buffer
402 * cbFrameLength - Tx Length
403 * uIdx - Index of Tx DMA
404 * Out:
405 * none
406 *
407 * Return Value: none
408 *
409 */
410 void
411 STAvUpdateTDStatCounter (
412 PSStatCounter pStatistic,
413 BYTE byPktNum,
414 BYTE byRate,
415 BYTE byTSR
416 )
417 {
418 BYTE byRetyCnt;
419 // increase tx packet count
420 pStatistic->dwTsrTxPacket++;
421
422 byRetyCnt = (byTSR & 0xF0) >> 4;
423 if (byRetyCnt != 0) {
424 pStatistic->dwTsrRetry++;
425 pStatistic->dwTsrTotalRetry += byRetyCnt;
426 pStatistic->dwTxFail[byRate]+= byRetyCnt;
427 pStatistic->dwTxFail[MAX_RATE] += byRetyCnt;
428
429 if ( byRetyCnt == 0x1)
430 pStatistic->dwTsrOnceRetry++;
431 else
432 pStatistic->dwTsrMoreThanOnceRetry++;
433
434 if (byRetyCnt <= 8)
435 pStatistic->dwTxRetryCount[byRetyCnt-1]++;
436
437 }
438 if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
439
440 #ifdef Calcu_LinkQual
441 if (byRetyCnt < 2)
442 pStatistic->TxNoRetryOkCount ++;
443 else
444 pStatistic->TxRetryOkCount ++;
445 #endif
446
447 pStatistic->ullTsrOK++;
448 pStatistic->CustomStat.ullTsrAllOK++;
449 // update counters in case that successful transmit
450 pStatistic->dwTxOk[byRate]++;
451 pStatistic->dwTxOk[MAX_RATE]++;
452
453 if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_BROAD ) {
454 pStatistic->ullTxBroadcastFrames++;
455 pStatistic->ullTxBroadcastBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
456 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_MULTI ) {
457 pStatistic->ullTxMulticastFrames++;
458 pStatistic->ullTxMulticastBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
459 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_UNI ) {
460 pStatistic->ullTxDirectedFrames++;
461 pStatistic->ullTxDirectedBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
462 }
463 }
464 else {
465
466 #ifdef Calcu_LinkQual
467 pStatistic->TxFailCount ++;
468 #endif
469
470 pStatistic->dwTsrErr++;
471 if (byTSR & TSR_RETRYTMO)
472 pStatistic->dwTsrRetryTimeout++;
473 if (byTSR & TSR_TMO)
474 pStatistic->dwTsrTransmitTimeout++;
475 }
476
477 if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_BROAD ) {
478 pStatistic->dwTsrBroadcast++;
479 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_MULTI ) {
480 pStatistic->dwTsrMulticast++;
481 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_UNI ) {
482 pStatistic->dwTsrDirected++;
483 }
484 }
485
486
487
488 /*
489 * Description: Update 802.11 mib counter
490 *
491 * Parameters:
492 * In:
493 * p802_11Counter - Pointer to 802.11 mib counter
494 * pStatistic - Pointer to Statistic Counter Data Structure
495 * dwCounter - hardware counter for 802.11 mib
496 * Out:
497 * none
498 *
499 * Return Value: none
500 *
501 */
502 void
503 STAvUpdate802_11Counter(
504 PSDot11Counters p802_11Counter,
505 PSStatCounter pStatistic,
506 BYTE byRTSSuccess,
507 BYTE byRTSFail,
508 BYTE byACKFail,
509 BYTE byFCSErr
510 )
511 {
512 //p802_11Counter->TransmittedFragmentCount
513 p802_11Counter->MulticastTransmittedFrameCount = (ULONGLONG) (pStatistic->dwTsrBroadcast +
514 pStatistic->dwTsrMulticast);
515 p802_11Counter->FailedCount = (ULONGLONG) (pStatistic->dwTsrErr);
516 p802_11Counter->RetryCount = (ULONGLONG) (pStatistic->dwTsrRetry);
517 p802_11Counter->MultipleRetryCount = (ULONGLONG) (pStatistic->dwTsrMoreThanOnceRetry);
518 //p802_11Counter->FrameDuplicateCount
519 p802_11Counter->RTSSuccessCount += (ULONGLONG) byRTSSuccess;
520 p802_11Counter->RTSFailureCount += (ULONGLONG) byRTSFail;
521 p802_11Counter->ACKFailureCount += (ULONGLONG) byACKFail;
522 p802_11Counter->FCSErrorCount += (ULONGLONG) byFCSErr;
523 //p802_11Counter->ReceivedFragmentCount
524 p802_11Counter->MulticastReceivedFrameCount = (ULONGLONG) (pStatistic->dwRsrBroadcast +
525 pStatistic->dwRsrMulticast);
526 }
527
528 /*
529 * Description: Clear 802.11 mib counter
530 *
531 * Parameters:
532 * In:
533 * p802_11Counter - Pointer to 802.11 mib counter
534 * Out:
535 * none
536 *
537 * Return Value: none
538 *
539 */
540 void
541 STAvClear802_11Counter(PSDot11Counters p802_11Counter)
542 {
543 // set memory to zero
544 memset(p802_11Counter, 0, sizeof(SDot11Counters));
545 }
546
547 /*
548 * Description: Clear 802.11 mib counter
549 *
550 * Parameters:
551 * In:
552 * pUsbCounter - Pointer to USB mib counter
553 * ntStatus - URB status
554 * Out:
555 * none
556 *
557 * Return Value: none
558 *
559 */
560
561 void
562 STAvUpdateUSBCounter(PSUSBCounter pUsbCounter,
563 NTSTATUS ntStatus
564 )
565 {
566
567 // if ( ntStatus == USBD_STATUS_CRC ) {
568 pUsbCounter->dwCrc++;
569 // }
570
571 }
572
573
This page took 0.053574 seconds and 5 git commands to generate.