Staging: vt6656: code cleanup, removed OUT definition
[GitHub/mt8127/android_kernel_alcatel_ttab.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 pStatistic->ullRsrOK++;
167
168 if (cbFrameLength >= ETH_ALEN) {
169 /* update counters in case of successful transmission */
170 if (byRSR & RSR_ADDRBROAD) {
171 pStatistic->ullRxBroadcastFrames++;
172 pStatistic->ullRxBroadcastBytes += (ULONGLONG)cbFrameLength;
173 }
174 else if (byRSR & RSR_ADDRMULTI) {
175 pStatistic->ullRxMulticastFrames++;
176 pStatistic->ullRxMulticastBytes += (ULONGLONG)cbFrameLength;
177 }
178 else {
179 pStatistic->ullRxDirectedFrames++;
180 pStatistic->ullRxDirectedBytes += (ULONGLONG)cbFrameLength;
181 }
182 }
183 }
184
185 if(byRxRate==22) {
186 pStatistic->CustomStat.ullRsr11M++;
187 if(byRSR & RSR_CRCOK) {
188 pStatistic->CustomStat.ullRsr11MCRCOk++;
189 }
190 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"11M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr11M, (INT)pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
191 }
192 else if(byRxRate==11) {
193 pStatistic->CustomStat.ullRsr5M++;
194 if(byRSR & RSR_CRCOK) {
195 pStatistic->CustomStat.ullRsr5MCRCOk++;
196 }
197 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 5M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr5M, (INT)pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
198 }
199 else if(byRxRate==4) {
200 pStatistic->CustomStat.ullRsr2M++;
201 if(byRSR & RSR_CRCOK) {
202 pStatistic->CustomStat.ullRsr2MCRCOk++;
203 }
204 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 2M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr2M, (INT)pStatistic->CustomStat.ullRsr2MCRCOk, byRSR);
205 }
206 else if(byRxRate==2){
207 pStatistic->CustomStat.ullRsr1M++;
208 if(byRSR & RSR_CRCOK) {
209 pStatistic->CustomStat.ullRsr1MCRCOk++;
210 }
211 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 1M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr1M, (INT)pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
212 }
213 else if(byRxRate==12){
214 pStatistic->CustomStat.ullRsr6M++;
215 if(byRSR & RSR_CRCOK) {
216 pStatistic->CustomStat.ullRsr6MCRCOk++;
217 }
218 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 6M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr6M, (INT)pStatistic->CustomStat.ullRsr6MCRCOk);
219 }
220 else if(byRxRate==18){
221 pStatistic->CustomStat.ullRsr9M++;
222 if(byRSR & RSR_CRCOK) {
223 pStatistic->CustomStat.ullRsr9MCRCOk++;
224 }
225 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 9M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr9M, (INT)pStatistic->CustomStat.ullRsr9MCRCOk);
226 }
227 else if(byRxRate==24){
228 pStatistic->CustomStat.ullRsr12M++;
229 if(byRSR & RSR_CRCOK) {
230 pStatistic->CustomStat.ullRsr12MCRCOk++;
231 }
232 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"12M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr12M, (INT)pStatistic->CustomStat.ullRsr12MCRCOk);
233 }
234 else if(byRxRate==36){
235 pStatistic->CustomStat.ullRsr18M++;
236 if(byRSR & RSR_CRCOK) {
237 pStatistic->CustomStat.ullRsr18MCRCOk++;
238 }
239 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"18M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr18M, (INT)pStatistic->CustomStat.ullRsr18MCRCOk);
240 }
241 else if(byRxRate==48){
242 pStatistic->CustomStat.ullRsr24M++;
243 if(byRSR & RSR_CRCOK) {
244 pStatistic->CustomStat.ullRsr24MCRCOk++;
245 }
246 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"24M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr24M, (INT)pStatistic->CustomStat.ullRsr24MCRCOk);
247 }
248 else if(byRxRate==72){
249 pStatistic->CustomStat.ullRsr36M++;
250 if(byRSR & RSR_CRCOK) {
251 pStatistic->CustomStat.ullRsr36MCRCOk++;
252 }
253 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"36M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr36M, (INT)pStatistic->CustomStat.ullRsr36MCRCOk);
254 }
255 else if(byRxRate==96){
256 pStatistic->CustomStat.ullRsr48M++;
257 if(byRSR & RSR_CRCOK) {
258 pStatistic->CustomStat.ullRsr48MCRCOk++;
259 }
260 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"48M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr48M, (INT)pStatistic->CustomStat.ullRsr48MCRCOk);
261 }
262 else if(byRxRate==108){
263 pStatistic->CustomStat.ullRsr54M++;
264 if(byRSR & RSR_CRCOK) {
265 pStatistic->CustomStat.ullRsr54MCRCOk++;
266 }
267 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"54M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr54M, (INT)pStatistic->CustomStat.ullRsr54MCRCOk);
268 }
269 else {
270 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Unknown: Total[%d], CRCOK[%d]\n", (INT)pStatistic->dwRsrRxPacket+1, (INT)pStatistic->dwRsrCRCOk);
271 }
272
273 if (byRSR & RSR_BSSIDOK)
274 pStatistic->dwRsrBSSIDOk++;
275
276 if (byRSR & RSR_BCNSSIDOK)
277 pStatistic->dwRsrBCNSSIDOk++;
278 if (byRSR & RSR_IVLDLEN) //invalid len (> 2312 byte)
279 pStatistic->dwRsrLENErr++;
280 if (byRSR & RSR_IVLDTYP) //invalid packet type
281 pStatistic->dwRsrTYPErr++;
282 if ((byRSR & (RSR_IVLDTYP | RSR_IVLDLEN)) || !(byRSR & RSR_CRCOK))
283 pStatistic->dwRsrErr++;
284
285 if (byNewRSR & NEWRSR_DECRYPTOK)
286 pStatistic->dwNewRsrDECRYPTOK++;
287 if (byNewRSR & NEWRSR_CFPIND)
288 pStatistic->dwNewRsrCFP++;
289 if (byNewRSR & NEWRSR_HWUTSF)
290 pStatistic->dwNewRsrUTSF++;
291 if (byNewRSR & NEWRSR_BCNHITAID)
292 pStatistic->dwNewRsrHITAID++;
293 if (byNewRSR & NEWRSR_BCNHITAID0)
294 pStatistic->dwNewRsrHITAID0++;
295
296 // increase rx packet count
297 pStatistic->dwRsrRxPacket++;
298 pStatistic->dwRsrRxOctet += cbFrameLength;
299
300
301 if (IS_TYPE_DATA(pbyBuffer)) {
302 pStatistic->dwRsrRxData++;
303 } else if (IS_TYPE_MGMT(pbyBuffer)){
304 pStatistic->dwRsrRxManage++;
305 } else if (IS_TYPE_CONTROL(pbyBuffer)){
306 pStatistic->dwRsrRxControl++;
307 }
308
309 if (byRSR & RSR_ADDRBROAD)
310 pStatistic->dwRsrBroadcast++;
311 else if (byRSR & RSR_ADDRMULTI)
312 pStatistic->dwRsrMulticast++;
313 else
314 pStatistic->dwRsrDirected++;
315
316 if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
317 pStatistic->dwRsrRxFragment++;
318
319 if (cbFrameLength < MIN_PACKET_LEN + 4) {
320 pStatistic->dwRsrRunt++;
321 }
322 else if (cbFrameLength == MIN_PACKET_LEN + 4) {
323 pStatistic->dwRsrRxFrmLen64++;
324 }
325 else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
326 pStatistic->dwRsrRxFrmLen65_127++;
327 }
328 else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
329 pStatistic->dwRsrRxFrmLen128_255++;
330 }
331 else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
332 pStatistic->dwRsrRxFrmLen256_511++;
333 }
334 else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023)) {
335 pStatistic->dwRsrRxFrmLen512_1023++;
336 }
337 else if ((1024 <= cbFrameLength) && (cbFrameLength <= MAX_PACKET_LEN + 4)) {
338 pStatistic->dwRsrRxFrmLen1024_1518++;
339 } else if (cbFrameLength > MAX_PACKET_LEN + 4) {
340 pStatistic->dwRsrLong++;
341 }
342
343 }
344
345
346
347 /*
348 * Description: Update Rx Statistic Counter and copy Rx buffer
349 *
350 * Parameters:
351 * In:
352 * pStatistic - Pointer to Statistic Counter Data Structure
353 * byRSR - Rx Status
354 * byNewRSR - Rx Status
355 * pbyBuffer - Rx Buffer
356 * cbFrameLength - Rx Length
357 * Out:
358 * none
359 *
360 * Return Value: none
361 *
362 */
363
364 void
365 STAvUpdateRDStatCounterEx (
366 PSStatCounter pStatistic,
367 BYTE byRSR,
368 BYTE byNewRSR,
369 BYTE byRxSts,
370 BYTE byRxRate,
371 PBYTE pbyBuffer,
372 UINT cbFrameLength
373 )
374 {
375 STAvUpdateRDStatCounter(
376 pStatistic,
377 byRSR,
378 byNewRSR,
379 byRxSts,
380 byRxRate,
381 pbyBuffer,
382 cbFrameLength
383 );
384
385 // rx length
386 pStatistic->dwCntRxFrmLength = cbFrameLength;
387 // rx pattern, we just see 10 bytes for sample
388 memcpy(pStatistic->abyCntRxPattern, (PBYTE)pbyBuffer, 10);
389 }
390
391
392 /*
393 * Description: Update Tx Statistic Counter
394 *
395 * Parameters:
396 * In:
397 * pStatistic - Pointer to Statistic Counter Data Structure
398 * byTSR0 - Tx Status
399 * byTSR1 - Tx Status
400 * pbyBuffer - Tx Buffer
401 * cbFrameLength - Tx Length
402 * uIdx - Index of Tx DMA
403 * Out:
404 * none
405 *
406 * Return Value: none
407 *
408 */
409 void
410 STAvUpdateTDStatCounter (
411 PSStatCounter pStatistic,
412 BYTE byPktNum,
413 BYTE byRate,
414 BYTE byTSR
415 )
416 {
417 BYTE byRetyCnt;
418 // increase tx packet count
419 pStatistic->dwTsrTxPacket++;
420
421 byRetyCnt = (byTSR & 0xF0) >> 4;
422 if (byRetyCnt != 0) {
423 pStatistic->dwTsrRetry++;
424 pStatistic->dwTsrTotalRetry += byRetyCnt;
425 pStatistic->dwTxFail[byRate]+= byRetyCnt;
426 pStatistic->dwTxFail[MAX_RATE] += byRetyCnt;
427
428 if ( byRetyCnt == 0x1)
429 pStatistic->dwTsrOnceRetry++;
430 else
431 pStatistic->dwTsrMoreThanOnceRetry++;
432
433 if (byRetyCnt <= 8)
434 pStatistic->dwTxRetryCount[byRetyCnt-1]++;
435
436 }
437 if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
438
439 #ifdef Calcu_LinkQual
440 if (byRetyCnt < 2)
441 pStatistic->TxNoRetryOkCount ++;
442 else
443 pStatistic->TxRetryOkCount ++;
444 #endif
445
446 pStatistic->ullTsrOK++;
447 pStatistic->CustomStat.ullTsrAllOK++;
448 // update counters in case that successful transmit
449 pStatistic->dwTxOk[byRate]++;
450 pStatistic->dwTxOk[MAX_RATE]++;
451
452 if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_BROAD ) {
453 pStatistic->ullTxBroadcastFrames++;
454 pStatistic->ullTxBroadcastBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
455 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_MULTI ) {
456 pStatistic->ullTxMulticastFrames++;
457 pStatistic->ullTxMulticastBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
458 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_UNI ) {
459 pStatistic->ullTxDirectedFrames++;
460 pStatistic->ullTxDirectedBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
461 }
462 }
463 else {
464
465 #ifdef Calcu_LinkQual
466 pStatistic->TxFailCount ++;
467 #endif
468
469 pStatistic->dwTsrErr++;
470 if (byTSR & TSR_RETRYTMO)
471 pStatistic->dwTsrRetryTimeout++;
472 if (byTSR & TSR_TMO)
473 pStatistic->dwTsrTransmitTimeout++;
474 }
475
476 if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_BROAD ) {
477 pStatistic->dwTsrBroadcast++;
478 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_MULTI ) {
479 pStatistic->dwTsrMulticast++;
480 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_UNI ) {
481 pStatistic->dwTsrDirected++;
482 }
483 }
484
485
486
487 /*
488 * Description: Update 802.11 mib counter
489 *
490 * Parameters:
491 * In:
492 * p802_11Counter - Pointer to 802.11 mib counter
493 * pStatistic - Pointer to Statistic Counter Data Structure
494 * dwCounter - hardware counter for 802.11 mib
495 * Out:
496 * none
497 *
498 * Return Value: none
499 *
500 */
501 void
502 STAvUpdate802_11Counter(
503 PSDot11Counters p802_11Counter,
504 PSStatCounter pStatistic,
505 BYTE byRTSSuccess,
506 BYTE byRTSFail,
507 BYTE byACKFail,
508 BYTE byFCSErr
509 )
510 {
511 //p802_11Counter->TransmittedFragmentCount
512 p802_11Counter->MulticastTransmittedFrameCount = (ULONGLONG) (pStatistic->dwTsrBroadcast +
513 pStatistic->dwTsrMulticast);
514 p802_11Counter->FailedCount = (ULONGLONG) (pStatistic->dwTsrErr);
515 p802_11Counter->RetryCount = (ULONGLONG) (pStatistic->dwTsrRetry);
516 p802_11Counter->MultipleRetryCount = (ULONGLONG) (pStatistic->dwTsrMoreThanOnceRetry);
517 //p802_11Counter->FrameDuplicateCount
518 p802_11Counter->RTSSuccessCount += (ULONGLONG) byRTSSuccess;
519 p802_11Counter->RTSFailureCount += (ULONGLONG) byRTSFail;
520 p802_11Counter->ACKFailureCount += (ULONGLONG) byACKFail;
521 p802_11Counter->FCSErrorCount += (ULONGLONG) byFCSErr;
522 //p802_11Counter->ReceivedFragmentCount
523 p802_11Counter->MulticastReceivedFrameCount = (ULONGLONG) (pStatistic->dwRsrBroadcast +
524 pStatistic->dwRsrMulticast);
525 }
526
527 /*
528 * Description: Clear 802.11 mib counter
529 *
530 * Parameters:
531 * In:
532 * p802_11Counter - Pointer to 802.11 mib counter
533 * Out:
534 * none
535 *
536 * Return Value: none
537 *
538 */
539 void
540 STAvClear802_11Counter(PSDot11Counters p802_11Counter)
541 {
542 // set memory to zero
543 memset(p802_11Counter, 0, sizeof(SDot11Counters));
544 }
545
546 /*
547 * Description: Clear 802.11 mib counter
548 *
549 * Parameters:
550 * In:
551 * pUsbCounter - Pointer to USB mib counter
552 * ntStatus - URB status
553 * Out:
554 * none
555 *
556 * Return Value: none
557 *
558 */
559
560 void
561 STAvUpdateUSBCounter(PSUSBCounter pUsbCounter,
562 NTSTATUS ntStatus
563 )
564 {
565
566 // if ( ntStatus == USBD_STATUS_CRC ) {
567 pUsbCounter->dwCrc++;
568 // }
569
570 }
571
572