add rk3288 pinctrl dts code
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rtl8723au / hal / rtl8723a / rtl8723a_rxdesc.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #define _RTL8723A_REDESC_C_
21
22 #include <drv_conf.h>
23 #include <osdep_service.h>
24 #include <drv_types.h>
25 #include <rtl8723a_hal.h>
26
27 static s32  translate2dbm(u8 signal_strength_idx)
28 {
29         s32     signal_power; // in dBm.
30
31
32         // Translate to dBm (x=0.5y-95).
33         signal_power = (s32)((signal_strength_idx + 1) >> 1);
34         signal_power -= 95;
35
36         return signal_power;
37 }
38 #if 0
39 static u8 evm_db2percentage(s8 value)
40 {
41         //
42         // -33dB~0dB to 0%~99%
43         //
44         s8 ret_val;
45
46         ret_val = value;
47         //ret_val /= 2;
48
49         RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("EVMdbToPercentage92S Value=%d / %x \n", ret_val, ret_val));
50
51         if(ret_val >= 0)
52                 ret_val = 0;
53         if(ret_val <= -33)
54                 ret_val = -33;
55
56         ret_val = 0 - ret_val;
57         ret_val*=3;
58
59         if(ret_val == 99)
60                 ret_val = 100;
61
62         return(ret_val);
63 }
64
65
66 static s32 signal_scale_mapping(_adapter *padapter, s32 cur_sig )
67 {
68         s32 ret_sig;
69
70 #ifdef CONFIG_USB_HCI
71         if(cur_sig >= 51 && cur_sig <= 100)
72         {
73                 ret_sig = 100;
74         }
75         else if(cur_sig >= 41 && cur_sig <= 50)
76         {
77                 ret_sig = 80 + ((cur_sig - 40)*2);
78         }
79         else if(cur_sig >= 31 && cur_sig <= 40)
80         {
81                 ret_sig = 66 + (cur_sig - 30);
82         }
83         else if(cur_sig >= 21 && cur_sig <= 30)
84         {
85                 ret_sig = 54 + (cur_sig - 20);
86         }
87         else if(cur_sig >= 10 && cur_sig <= 20)
88         {
89                 ret_sig = 42 + (((cur_sig - 10) * 2) / 3);
90         }
91         else if(cur_sig >= 5 && cur_sig <= 9)
92         {
93                 ret_sig = 22 + (((cur_sig - 5) * 3) / 2);
94         }
95         else if(cur_sig >= 1 && cur_sig <= 4)
96         {
97                 ret_sig = 6 + (((cur_sig - 1) * 3) / 2);
98         }
99         else
100         {
101                 ret_sig = cur_sig;
102         }
103 #else
104         HAL_DATA_TYPE   *pHalData = GET_HAL_DATA(padapter);
105
106         if(pHalData->CustomerID == RT_CID_819x_Lenovo)
107         {
108                 // Step 1. Scale mapping.
109                 // 20100611 Joseph: Re-tunning RSSI presentation for Lenovo.
110                 // 20100426 Joseph: Modify Signal strength mapping.
111                 // This modification makes the RSSI indication similar to Intel solution.
112                 // 20100414 Joseph: Tunning RSSI for Lenovo according to RTL8191SE.
113                 if(cur_sig >= 54 && cur_sig <= 100)
114                 {
115                         ret_sig = 100;
116                 }
117                 else if(cur_sig>=42 && cur_sig <= 53 )
118                 {
119                         ret_sig = 95;
120                 }
121                 else if(cur_sig>=36 && cur_sig <= 41 )
122                 {
123                         ret_sig = 74 + ((cur_sig - 36) *20)/6;
124                 }
125                 else if(cur_sig>=33 && cur_sig <= 35 )
126                 {
127                         ret_sig = 65 + ((cur_sig - 33) *8)/2;
128                 }
129                 else if(cur_sig>=18 && cur_sig <= 32 )
130                 {
131                         ret_sig = 62 + ((cur_sig - 18) *2)/15;
132                 }
133                 else if(cur_sig>=15 && cur_sig <= 17 )
134                 {
135                         ret_sig = 33 + ((cur_sig - 15) *28)/2;
136                 }
137                 else if(cur_sig>=10 && cur_sig <= 14 )
138                 {
139                         ret_sig = 39;
140                 }
141                 else if(cur_sig>=8 && cur_sig <= 9 )
142                 {
143                         ret_sig = 33;
144                 }
145                 else if(cur_sig <= 8 )
146                 {
147                         ret_sig = 19;
148                 }
149         }
150         else
151         {
152                 // Step 1. Scale mapping.
153                 if(cur_sig >= 61 && cur_sig <= 100)
154                 {
155                         ret_sig = 90 + ((cur_sig - 60) / 4);
156                 }
157                 else if(cur_sig >= 41 && cur_sig <= 60)
158                 {
159                         ret_sig = 78 + ((cur_sig - 40) / 2);
160                 }
161                 else if(cur_sig >= 31 && cur_sig <= 40)
162                 {
163                         ret_sig = 66 + (cur_sig - 30);
164                 }
165                 else if(cur_sig >= 21 && cur_sig <= 30)
166                 {
167                         ret_sig = 54 + (cur_sig - 20);
168                 }
169                 else if(cur_sig >= 5 && cur_sig <= 20)
170                 {
171                         ret_sig = 42 + (((cur_sig - 5) * 2) / 3);
172                 }
173                 else if(cur_sig == 4)
174                 {
175                         ret_sig = 36;
176                 }
177                 else if(cur_sig == 3)
178                 {
179                         ret_sig = 27;
180                 }
181                 else if(cur_sig == 2)
182                 {
183                         ret_sig = 18;
184                 }
185                 else if(cur_sig == 1)
186                 {
187                         ret_sig = 9;
188                 }
189                 else
190                 {
191                         ret_sig = cur_sig;
192                 }
193         }
194 #endif
195
196         return ret_sig;
197 }
198
199
200
201 void rtl8192c_query_rx_phy_status(union recv_frame *prframe, struct phy_stat *pphy_stat)
202 {
203         PHY_STS_OFDM_8192CD_T   *pOfdm_buf;
204         PHY_STS_CCK_8192CD_T    *pCck_buf;
205         u8      i, max_spatial_stream, evm;
206         s8      rx_pwr[4], rx_pwr_all = 0;
207         u8      pwdb_all;
208         u32     rssi,total_rssi=0;
209         u8      bcck_rate=0, rf_rx_num = 0, cck_highpwr = 0;
210         _adapter                                *padapter = prframe->u.hdr.adapter;
211         struct rx_pkt_attrib    *pattrib = &prframe->u.hdr.attrib;
212         HAL_DATA_TYPE           *pHalData = GET_HAL_DATA(padapter);
213         struct dm_priv          *pdmpriv = &pHalData->dmpriv;
214         u8      tmp_rxsnr;
215         s8      rx_snrX;
216
217 #ifdef CONFIG_HW_ANTENNA_DIVERSITY
218         PHY_RX_DRIVER_INFO_8192CD *pDrvInfo = ((PHY_RX_DRIVER_INFO_8192CD *)pphy_stat);
219         u8      bant1_sel = (pDrvInfo->ANTSEL == 1)?_TRUE:_FALSE;       
220 #endif
221         if(pphy_stat==NULL){
222         //      DBG_8192C("\n%s pphy_stat is NULL, Return\n",__FUNCTION__);
223                 return;
224         }
225
226         // Record it for next packet processing
227         bcck_rate=(pattrib->mcs_rate<=3? 1:0);
228
229         if(bcck_rate) //CCK
230         {
231                 u8 report;
232 #ifdef CONFIG_HW_ANTENNA_DIVERSITY              
233                 if(bant1_sel == _TRUE)
234                         pHalData->CCK_Ant1_Cnt++;
235                 else
236                         pHalData->CCK_Ant2_Cnt++;
237 #endif          
238
239                 // CCK Driver info Structure is not the same as OFDM packet.
240                 pCck_buf = (PHY_STS_CCK_8192CD_T *)pphy_stat;
241                 //Adapter->RxStats.NumQryPhyStatusCCK++;
242
243                 //
244                 // (1)Hardware does not provide RSSI for CCK
245                 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
246                 //
247
248                 if(adapter_to_pwrctl(padapter)->rf_pwrstate == rf_on)
249                         cck_highpwr = (u8)pHalData->bCckHighPower;
250                 else
251                         cck_highpwr = _FALSE;
252
253                 if(!cck_highpwr)
254                 {
255                         report = pCck_buf->cck_agc_rpt&0xc0;
256                         report = report>>6;
257                         switch(report)
258                         {
259                                 // 03312009 modified by cosa
260                                 // Modify the RF RNA gain value to -40, -20, -2, 14 by Jenyu's suggestion
261                                 // Note: different RF with the different RNA gain.
262                                 case 0x3:
263                                         rx_pwr_all = (-46) - (pCck_buf->cck_agc_rpt & 0x3e);
264                                         break;
265                                 case 0x2:
266                                         rx_pwr_all = (-26) - (pCck_buf->cck_agc_rpt & 0x3e);
267                                         break;
268                                 case 0x1:
269                                         rx_pwr_all = (-12) - (pCck_buf->cck_agc_rpt & 0x3e);
270                                         break;
271                                 case 0x0:
272                                         rx_pwr_all = (16) - (pCck_buf->cck_agc_rpt & 0x3e);
273                                         break;
274                         }
275                 }
276                 else
277                 {
278                         report = pCck_buf->cck_agc_rpt & 0x60;
279                         report = report>>5;
280                         switch(report)
281                         {
282                                 case 0x3:
283                                         rx_pwr_all = (-46) - ((pCck_buf->cck_agc_rpt & 0x1f)<<1) ;
284                                         break;
285                                 case 0x2:
286                                         rx_pwr_all = (-26)- ((pCck_buf->cck_agc_rpt & 0x1f)<<1);
287                                         break;
288                                 case 0x1:
289                                         rx_pwr_all = (-12) - ((pCck_buf->cck_agc_rpt & 0x1f)<<1) ;
290                                         break;
291                                 case 0x0:
292                                         rx_pwr_all = (16) - ((pCck_buf->cck_agc_rpt & 0x1f)<<1) ;
293                                         break;
294                         }
295                 }
296
297                 pwdb_all= query_rx_pwr_percentage(rx_pwr_all);
298                 if(pHalData->CustomerID == RT_CID_819x_Lenovo)
299                 {
300                         // CCK gain is smaller than OFDM/MCS gain,
301                         // so we add gain diff by experiences, the val is 6
302                         pwdb_all+=6;
303                         if(pwdb_all > 100)
304                                 pwdb_all = 100;
305                         // modify the offset to make the same gain index with OFDM.
306                         if(pwdb_all > 34 && pwdb_all <= 42)
307                                 pwdb_all -= 2;
308                         else if(pwdb_all > 26 && pwdb_all <= 34)
309                                 pwdb_all -= 6;
310                         else if(pwdb_all > 14 && pwdb_all <= 26)
311                                 pwdb_all -= 8;
312                         else if(pwdb_all > 4 && pwdb_all <= 14)
313                                 pwdb_all -= 4;
314                 }
315
316                 pattrib->RxPWDBAll = pwdb_all;  //for DIG/rate adaptive
317                 pattrib->RecvSignalPower = rx_pwr_all;  //dBM
318                 padapter->recvpriv.rxpwdb = rx_pwr_all;
319                 //
320                 // (3) Get Signal Quality (EVM)
321                 //
322                 //if(bPacketMatchBSSID)
323                 {
324                         u8      sq;
325
326                         if(pHalData->CustomerID == RT_CID_819x_Lenovo)
327                         {
328                                 // mapping to 5 bars for vista signal strength
329                                 // signal quality in driver will be displayed to signal strength
330                                 // in vista.
331                                 if(pwdb_all >= 50)
332                                         sq = 100;
333                                 else if(pwdb_all >= 35 && pwdb_all < 50)
334                                         sq = 80;
335                                 else if(pwdb_all >= 22 && pwdb_all < 35)
336                                         sq = 60;
337                                 else if(pwdb_all >= 18 && pwdb_all < 22)
338                                         sq = 40;
339                                 else
340                                         sq = 20;
341                         }
342                         else
343                         {
344                                 if(pwdb_all> 40)
345                                 {
346                                         sq = 100;
347                                 }
348                                 else
349                                 {
350                                         sq = pCck_buf->SQ_rpt;
351
352                                         if(pCck_buf->SQ_rpt > 64)
353                                                 sq = 0;
354                                         else if (pCck_buf->SQ_rpt < 20)
355                                                 sq= 100;
356                                         else
357                                                 sq = ((64-sq) * 100) / 44;
358
359                                 }
360                         }
361
362                         pattrib->signal_qual=sq;
363                         pattrib->rx_mimo_signal_qual[0]=sq;
364                         pattrib->rx_mimo_signal_qual[1]=(-1);
365                 }
366
367         }
368         else //OFDM/HT
369         {
370 #ifdef CONFIG_HW_ANTENNA_DIVERSITY      
371                 if(bant1_sel == _TRUE)
372                         pHalData->OFDM_Ant1_Cnt++;
373                 else
374                         pHalData->OFDM_Ant2_Cnt++;
375 #endif
376                 pdmpriv->OFDM_Pkt_Cnt++;
377
378                 pOfdm_buf = (PHY_STS_OFDM_8192CD_T *)pphy_stat;
379
380                 //
381                 // (1)Get RSSI per-path
382                 //
383                 for(i=0; i<pHalData->NumTotalRFPath; i++)
384                 {
385                         // 2008/01/30 MH we will judge RF RX path now.
386                         if (pHalData->bRFPathRxEnable[i])
387                                 rf_rx_num++;
388                         //else
389                                 //continue;
390
391                         rx_pwr[i] =  ((pOfdm_buf->trsw_gain_X[i]&0x3F)*2) - 110;
392
393                         /* Translate DBM to percentage. */
394                         rssi=query_rx_pwr_percentage(rx_pwr[i]);
395                         total_rssi += rssi;
396
397                         RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("RF-%d RXPWR=%x RSSI=%d\n", i, rx_pwr[i], rssi));
398
399                         //Get Rx snr value in DB
400                         tmp_rxsnr =     pOfdm_buf->rxsnr_X[i];
401                         rx_snrX = (s8)(tmp_rxsnr);
402                         rx_snrX >>= 1;
403                         padapter->recvpriv.RxSNRdB[i] =  (int)rx_snrX;
404
405                         /* Record Signal Strength for next packet */
406                         //if(bPacketMatchBSSID)
407                         {
408                                 //pRfd->Status.RxMIMOSignalStrength[i] =(u1Byte) RSSI;
409
410                                 //The following is for lenovo signal strength in vista
411                                 if(pHalData->CustomerID == RT_CID_819x_Lenovo)
412                                 {
413                                         u8      sq;
414
415                                         if(i == 0)
416                                         {
417                                                 // mapping to 5 bars for vista signal strength
418                                                 // signal quality in driver will be displayed to signal strength
419                                                 // in vista.
420                                                 if(rssi >= 50)
421                                                         sq = 100;
422                                                 else if(rssi >= 35 && rssi < 50)
423                                                         sq = 80;
424                                                 else if(rssi >= 22 && rssi < 35)
425                                                         sq = 60;
426                                                 else if(rssi >= 18 && rssi < 22)
427                                                         sq = 40;
428                                                 else
429                                                         sq = 20;
430                                                 //DbgPrint("ofdm/mcs RSSI=%d\n", RSSI);
431                                                 //pRfd->Status.SignalQuality = SQ;
432                                                 //DbgPrint("ofdm/mcs SQ = %d\n", pRfd->Status.SignalQuality);
433                                         }
434                                 }
435                         }
436                 }
437
438
439                 //
440                 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive),average
441                 //
442                 rx_pwr_all = (((pOfdm_buf->pwdb_all ) >> 1 )& 0x7f) -110;//for OFDM Average RSSI
443                 pwdb_all = query_rx_pwr_percentage(rx_pwr_all);
444
445                 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("PWDB_ALL=%d\n",  pwdb_all));
446
447                 pattrib->RxPWDBAll = pwdb_all;  //for DIG/rate adaptive
448                 pattrib->RecvSignalPower = rx_pwr_all;//dBM
449                 padapter->recvpriv.rxpwdb = rx_pwr_all;
450                 //
451                 // (3)EVM of HT rate
452                 //
453                 if(pHalData->CustomerID != RT_CID_819x_Lenovo)
454                 {
455                         if(pattrib->rxht &&  pattrib->mcs_rate >=20 && pattrib->mcs_rate<=27)
456                                 max_spatial_stream = 2; //both spatial stream make sense
457                         else
458                                 max_spatial_stream = 1; //only spatial stream 1 makes sense
459
460                         for(i=0; i<max_spatial_stream; i++)
461                         {
462                                 // Do not use shift operation like "rx_evmX >>= 1" because the compilor of free build environment
463                                 // fill most significant bit to "zero" when doing shifting operation which may change a negative
464                                 // value to positive one, then the dbm value (which is supposed to be negative)  is not correct anymore.
465                                 evm = evm_db2percentage( (pOfdm_buf->rxevm_X[i]/*/ 2*/));//dbm
466
467                                 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("RXRATE=%x RXEVM=%x EVM=%s%d\n",
468                                         pattrib->mcs_rate, pOfdm_buf->rxevm_X[i], "%",evm));
469
470                                 //if(bPacketMatchBSSID)
471                                 {
472                                         if(i==0) // Fill value in RFD, Get the first spatial stream only
473                                         {
474                                                 pattrib->signal_qual = (u8)(evm & 0xff);
475                                         }
476                                         pattrib->rx_mimo_signal_qual[i] = (u8)(evm & 0xff);
477                                 }
478                         }
479
480                 }
481
482                 //
483                 // 4. Record rx statistics for debug
484                 //
485
486         }
487
488
489         //UI BSS List signal strength(in percentage), make it good looking, from 0~100.
490         //It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp().
491         if(bcck_rate)
492         {
493                 pattrib->signal_strength=(u8)signal_scale_mapping(padapter, pwdb_all);
494         }
495         else
496         {
497                 if (rf_rx_num != 0)
498                 {
499                         pattrib->signal_strength= (u8)(signal_scale_mapping(padapter, total_rssi/=rf_rx_num));
500                 }
501         }
502         //DBG_8192C("%s,rx_pwr_all(%d),RxPWDBAll(%d)\n",__FUNCTION__,rx_pwr_all,pattrib->RxPWDBAll);
503
504 }
505
506 #endif
507
508 static void process_rssi(_adapter *padapter,union recv_frame *prframe)
509 {
510         u32     last_rssi, tmp_val;
511         struct rx_pkt_attrib *pattrib = &prframe->u.hdr.attrib;
512 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
513         struct signal_stat * signal_stat = &padapter->recvpriv.signal_strength_data;
514 #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
515
516         //DBG_8192C("process_rssi=> pattrib->rssil(%d) signal_strength(%d)\n ",pattrib->RecvSignalPower,pattrib->signal_strength);
517         //if(pRfd->Status.bPacketToSelf || pRfd->Status.bPacketBeacon)
518         {
519         
520         #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
521                 if(signal_stat->update_req) {
522                         signal_stat->total_num = 0;
523                         signal_stat->total_val = 0;
524                         signal_stat->update_req = 0;
525                 }
526
527                 signal_stat->total_num++;
528                 signal_stat->total_val  += pattrib->phy_info.SignalStrength;
529                 signal_stat->avg_val = signal_stat->total_val / signal_stat->total_num;         
530         #else //CONFIG_NEW_SIGNAL_STAT_PROCESS
531         
532                 //Adapter->RxStats.RssiCalculateCnt++;  //For antenna Test
533                 if(padapter->recvpriv.signal_strength_data.total_num++ >= PHY_RSSI_SLID_WIN_MAX)
534                 {
535                         padapter->recvpriv.signal_strength_data.total_num = PHY_RSSI_SLID_WIN_MAX;
536                         last_rssi = padapter->recvpriv.signal_strength_data.elements[padapter->recvpriv.signal_strength_data.index];
537                         padapter->recvpriv.signal_strength_data.total_val -= last_rssi;
538                 }
539                 padapter->recvpriv.signal_strength_data.total_val  +=pattrib->phy_info.SignalStrength;
540
541                 padapter->recvpriv.signal_strength_data.elements[padapter->recvpriv.signal_strength_data.index++] = pattrib->phy_info.SignalStrength;
542                 if(padapter->recvpriv.signal_strength_data.index >= PHY_RSSI_SLID_WIN_MAX)
543                         padapter->recvpriv.signal_strength_data.index = 0;
544
545
546                 tmp_val = padapter->recvpriv.signal_strength_data.total_val/padapter->recvpriv.signal_strength_data.total_num;
547                 
548                 if(padapter->recvpriv.is_signal_dbg) {
549                         padapter->recvpriv.signal_strength= padapter->recvpriv.signal_strength_dbg;
550                         padapter->recvpriv.rssi=(s8)translate2dbm((u8)padapter->recvpriv.signal_strength_dbg);
551                 } else {
552                         padapter->recvpriv.signal_strength= tmp_val;
553                         padapter->recvpriv.rssi=(s8)translate2dbm((u8)tmp_val);
554                 }
555
556                 RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("UI RSSI = %d, ui_rssi.TotalVal = %d, ui_rssi.TotalNum = %d\n", tmp_val, padapter->recvpriv.signal_strength_data.total_val,padapter->recvpriv.signal_strength_data.total_num));
557         #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
558         }
559
560 }// Process_UI_RSSI_8192C
561
562 #if 0
563 static void process_PWDB(_adapter *padapter, union recv_frame *prframe)
564 {
565         int     UndecoratedSmoothedPWDB;
566         int     UndecoratedSmoothedCCK;
567         HAL_DATA_TYPE           *pHalData = GET_HAL_DATA(padapter);
568         struct dm_priv          *pdmpriv = &pHalData->dmpriv;
569         struct rx_pkt_attrib    *pattrib= &prframe->u.hdr.attrib;
570         struct sta_info         *psta = prframe->u.hdr.psta;
571         u8 isCCKrate=(pattrib->mcs_rate<=3? 1:0);
572
573
574         if(psta)
575         {
576                 UndecoratedSmoothedPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB;
577                 UndecoratedSmoothedCCK = psta->rssi_stat.UndecoratedSmoothedCCK;
578         }
579         else
580         {
581                 UndecoratedSmoothedPWDB = pdmpriv->UndecoratedSmoothedPWDB;
582                 UndecoratedSmoothedCCK = pdmpriv->UndecoratedSmoothedCCK;
583         }
584
585         //if(pRfd->Status.bPacketToSelf || pRfd->Status.bPacketBeacon)
586
587         if(!isCCKrate)
588         {
589                 // Process OFDM RSSI
590                 if(UndecoratedSmoothedPWDB < 0) // initialize
591                 {
592                         UndecoratedSmoothedPWDB = pattrib->RxPWDBAll;
593                 }
594
595                 if(pattrib->RxPWDBAll > (u32)UndecoratedSmoothedPWDB)
596                 {
597                         UndecoratedSmoothedPWDB =
598                                         ( ((UndecoratedSmoothedPWDB)*(Rx_Smooth_Factor-1)) +
599                                         (pattrib->RxPWDBAll)) /(Rx_Smooth_Factor);
600
601                         UndecoratedSmoothedPWDB = UndecoratedSmoothedPWDB + 1;
602                 }
603                 else
604                 {
605                         UndecoratedSmoothedPWDB =
606                                         ( ((UndecoratedSmoothedPWDB)*(Rx_Smooth_Factor-1)) +
607                                         (pattrib->RxPWDBAll)) /(Rx_Smooth_Factor);
608                 }
609         }
610         else
611         {
612                 // Process CCK RSSI
613                 if(UndecoratedSmoothedCCK < 0) // initialize
614                 {
615                         UndecoratedSmoothedCCK = pattrib->RxPWDBAll;
616                 }
617
618                 if(pattrib->RxPWDBAll > (u32)UndecoratedSmoothedCCK)
619                 {
620                         UndecoratedSmoothedCCK =
621                                         ( ((UndecoratedSmoothedCCK)*(Rx_Smooth_Factor-1)) +
622                                         (pattrib->RxPWDBAll)) /(Rx_Smooth_Factor);
623
624                         UndecoratedSmoothedCCK = UndecoratedSmoothedCCK + 1;
625                 }
626                 else
627                 {
628                         UndecoratedSmoothedCCK =
629                                         ( ((UndecoratedSmoothedCCK)*(Rx_Smooth_Factor-1)) +
630                                         (pattrib->RxPWDBAll)) /(Rx_Smooth_Factor);
631                 }
632         }
633
634
635
636         if(psta)
637         {
638                 //psta->UndecoratedSmoothedPWDB = UndecoratedSmoothedPWDB;//todo:
639                 pdmpriv->UndecoratedSmoothedPWDB = UndecoratedSmoothedPWDB;
640
641                 if(pdmpriv->RSSI_Select == RSSI_OFDM)
642                         psta->rssi_stat.UndecoratedSmoothedPWDB = UndecoratedSmoothedPWDB;
643                 else if(pdmpriv->RSSI_Select == RSSI_CCK)
644                         psta->rssi_stat.UndecoratedSmoothedPWDB = UndecoratedSmoothedCCK;
645
646                 psta->rssi_stat.UndecoratedSmoothedCCK = UndecoratedSmoothedCCK;
647         }
648         else
649         {
650                 //pdmpriv->UndecoratedSmoothedPWDB = UndecoratedSmoothedPWDB;
651
652                 if(pdmpriv->RSSI_Select == RSSI_OFDM)
653                         pdmpriv->UndecoratedSmoothedPWDB = UndecoratedSmoothedPWDB;
654                 else if(pdmpriv->RSSI_Select == RSSI_CCK)
655                         pdmpriv->UndecoratedSmoothedPWDB = UndecoratedSmoothedCCK;
656
657                 pdmpriv->UndecoratedSmoothedCCK = UndecoratedSmoothedCCK;
658         }
659
660         //UpdateRxSignalStatistics8192C(padapter, prframe);
661
662 }
663
664 #endif
665
666 static void process_link_qual(_adapter *padapter,union recv_frame *prframe)
667 {
668         u32     last_evm=0, tmpVal;
669         struct rx_pkt_attrib *pattrib;
670 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
671         struct signal_stat * signal_stat;
672 #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
673
674         if(prframe == NULL || padapter==NULL){
675                 return;
676         }
677
678         pattrib = &prframe->u.hdr.attrib;
679 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
680         signal_stat = &padapter->recvpriv.signal_qual_data;
681 #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
682
683         //DBG_8192C("process_link_qual=> pattrib->signal_qual(%d)\n ",pattrib->signal_qual);
684
685 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
686         if(signal_stat->update_req) {
687                 signal_stat->total_num = 0;
688                 signal_stat->total_val = 0;
689                 signal_stat->update_req = 0;
690         }
691
692         signal_stat->total_num++;
693         signal_stat->total_val  += pattrib->phy_info.SignalQuality;
694         signal_stat->avg_val = signal_stat->total_val / signal_stat->total_num;
695         
696 #else //CONFIG_NEW_SIGNAL_STAT_PROCESS
697         if(pattrib->phy_info.SignalQuality != 0)
698         {
699                         //
700                         // 1. Record the general EVM to the sliding window.
701                         //
702                         if(padapter->recvpriv.signal_qual_data.total_num++ >= PHY_LINKQUALITY_SLID_WIN_MAX)
703                         {
704                                 padapter->recvpriv.signal_qual_data.total_num = PHY_LINKQUALITY_SLID_WIN_MAX;
705                                 last_evm = padapter->recvpriv.signal_qual_data.elements[padapter->recvpriv.signal_qual_data.index];
706                                 padapter->recvpriv.signal_qual_data.total_val -= last_evm;
707                         }
708                         padapter->recvpriv.signal_qual_data.total_val += pattrib->phy_info.SignalQuality;
709
710                         padapter->recvpriv.signal_qual_data.elements[padapter->recvpriv.signal_qual_data.index++] = pattrib->phy_info.SignalQuality;
711                         if(padapter->recvpriv.signal_qual_data.index >= PHY_LINKQUALITY_SLID_WIN_MAX)
712                                 padapter->recvpriv.signal_qual_data.index = 0;
713
714                         RT_TRACE(_module_rtl871x_recv_c_,_drv_info_,("Total SQ=%d  pattrib->signal_qual= %d\n", padapter->recvpriv.signal_qual_data.total_val, pattrib->phy_info.SignalQuality));
715
716                         // <1> Showed on UI for user, in percentage.
717                         tmpVal = padapter->recvpriv.signal_qual_data.total_val/padapter->recvpriv.signal_qual_data.total_num;
718                         padapter->recvpriv.signal_qual=(u8)tmpVal;
719
720         }
721         else
722         {
723                 RT_TRACE(_module_rtl871x_recv_c_,_drv_err_,(" pattrib->signal_qual =%d\n", pattrib->phy_info.SignalQuality));
724         }
725 #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
726
727 }// Process_UiLinkQuality8192S
728
729
730 //void rtl8192c_process_phy_info(_adapter *padapter, union recv_frame *prframe)
731 void rtl8192c_process_phy_info(_adapter *padapter, void *prframe)
732 {
733         union recv_frame *precvframe = (union recv_frame *)prframe;
734         //
735         // Check RSSI
736         //
737         process_rssi(padapter, precvframe);
738         //
739         // Check PWDB.
740         //
741         //process_PWDB(padapter, precvframe); 
742
743         //UpdateRxSignalStatistics8192C(Adapter, pRfd);
744         //
745         // Check EVM
746         //
747         process_link_qual(padapter,  precvframe);
748
749 }
750