1 /******************************************************************************
3 * Copyright(c) 2009-2010 Realtek Corporation.
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.
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
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
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
31 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
32 #include <linux/export.h>
35 u8
rtl_query_rxpwrpercentage(char antpower
)
37 if ((antpower
<= -100) || (antpower
>= 20))
39 else if (antpower
>= 0)
42 return (100 + antpower
);
44 //EXPORT_SYMBOL(rtl_query_rxpwrpercentage);
46 u8
rtl_evm_db_to_percentage(char value
)
55 ret_val
= 0 - ret_val
;
62 //EXPORT_SYMBOL(rtl_evm_db_to_percentage);
64 long rtl_translate_todbm(struct ieee80211_hw
*hw
,
65 u8 signal_strength_index
)
69 signal_power
= (long)((signal_strength_index
+ 1) >> 1);
74 long rtl_signal_scale_mapping(struct ieee80211_hw
*hw
, long currsig
)
78 if (currsig
>= 61 && currsig
<= 100)
79 retsig
= 90 + ((currsig
- 60) / 4);
80 else if (currsig
>= 41 && currsig
<= 60)
81 retsig
= 78 + ((currsig
- 40) / 2);
82 else if (currsig
>= 31 && currsig
<= 40)
83 retsig
= 66 + (currsig
- 30);
84 else if (currsig
>= 21 && currsig
<= 30)
85 retsig
= 54 + (currsig
- 20);
86 else if (currsig
>= 5 && currsig
<= 20)
87 retsig
= 42 + (((currsig
- 5) * 2) / 3);
88 else if (currsig
== 4)
90 else if (currsig
== 3)
92 else if (currsig
== 2)
94 else if (currsig
== 1)
101 //EXPORT_SYMBOL(rtl_signal_scale_mapping);
103 void rtl_process_ui_rssi(struct ieee80211_hw
*hw
, struct rtl_stats
*pstatus
)
105 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
106 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
108 u32 last_rssi
, tmpval
;
110 if (!pstatus
->b_packet_toself
&& !pstatus
->b_packet_beacon
)
113 rtlpriv
->stats
.pwdb_all_cnt
+= pstatus
->rx_pwdb_all
;
114 rtlpriv
->stats
.rssi_calculate_cnt
++;
116 if (rtlpriv
->stats
.ui_rssi
.total_num
++ >= PHY_RSSI_SLID_WIN_MAX
) {
117 rtlpriv
->stats
.ui_rssi
.total_num
= PHY_RSSI_SLID_WIN_MAX
;
118 last_rssi
= rtlpriv
->stats
.ui_rssi
.elements
[
119 rtlpriv
->stats
.ui_rssi
.index
];
120 rtlpriv
->stats
.ui_rssi
.total_val
-= last_rssi
;
122 rtlpriv
->stats
.ui_rssi
.total_val
+= pstatus
->signalstrength
;
123 rtlpriv
->stats
.ui_rssi
.elements
[rtlpriv
->stats
.ui_rssi
.index
++] =
124 pstatus
->signalstrength
;
125 if (rtlpriv
->stats
.ui_rssi
.index
>= PHY_RSSI_SLID_WIN_MAX
)
126 rtlpriv
->stats
.ui_rssi
.index
= 0;
127 tmpval
= rtlpriv
->stats
.ui_rssi
.total_val
/
128 rtlpriv
->stats
.ui_rssi
.total_num
;
129 rtlpriv
->stats
.signal_strength
= rtl_translate_todbm(hw
,
131 pstatus
->rssi
= rtlpriv
->stats
.signal_strength
;
133 if (pstatus
->b_is_cck
)
136 for (rfpath
= RF90_PATH_A
; rfpath
< rtlphy
->num_total_rfpath
;
138 if (rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] == 0) {
139 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
140 pstatus
->rx_mimo_signalstrength
[rfpath
];
143 if (pstatus
->rx_mimo_signalstrength
[rfpath
] >
144 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
]) {
145 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
146 ((rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] *
147 (RX_SMOOTH_FACTOR
- 1)) +
148 (pstatus
->rx_mimo_signalstrength
[rfpath
])) /
150 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
151 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] + 1;
153 rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] =
154 ((rtlpriv
->stats
.rx_rssi_percentage
[rfpath
] *
155 (RX_SMOOTH_FACTOR
- 1)) +
156 (pstatus
->rx_mimo_signalstrength
[rfpath
])) /
159 rtlpriv
->stats
.rx_snr_db
[rfpath
] = pstatus
->rx_snr
[rfpath
];
160 rtlpriv
->stats
.rx_evm_dbm
[rfpath
] =
161 pstatus
->rx_mimo_evm_dbm
[rfpath
];
162 rtlpriv
->stats
.rx_cfo_short
[rfpath
] =
163 pstatus
->cfo_short
[rfpath
];
164 rtlpriv
->stats
.rx_cfo_tail
[rfpath
] = pstatus
->cfo_tail
[rfpath
];
168 static void rtl_update_rxsignalstatistics(struct ieee80211_hw
*hw
,
169 struct rtl_stats
*pstatus
)
171 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
174 if (rtlpriv
->stats
.recv_signal_power
== 0)
175 rtlpriv
->stats
.recv_signal_power
= pstatus
->recvsignalpower
;
176 if (pstatus
->recvsignalpower
> rtlpriv
->stats
.recv_signal_power
)
178 else if (pstatus
->recvsignalpower
< rtlpriv
->stats
.recv_signal_power
)
180 rtlpriv
->stats
.recv_signal_power
= (rtlpriv
->stats
.recv_signal_power
*
181 5 + pstatus
->recvsignalpower
+ weighting
) / 6;
184 static void rtl_process_pwdb(struct ieee80211_hw
*hw
, struct rtl_stats
*pstatus
)
186 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
187 struct rtl_sta_info
*drv_priv
= NULL
;
188 struct ieee80211_sta
*sta
= NULL
;
189 long undecorated_smoothed_pwdb
;
192 if (rtlpriv
->mac80211
.opmode
!= NL80211_IFTYPE_STATION
)
193 sta
= rtl_find_sta(hw
, pstatus
->psaddr
);
195 /* adhoc or ap mode */
197 drv_priv
= (struct rtl_sta_info
*) sta
->drv_priv
;
198 undecorated_smoothed_pwdb
=
199 drv_priv
->rssi_stat
.undecorated_smoothed_pwdb
;
201 undecorated_smoothed_pwdb
=
202 rtlpriv
->dm
.undecorated_smoothed_pwdb
;
205 if (undecorated_smoothed_pwdb
< 0)
206 undecorated_smoothed_pwdb
= pstatus
->rx_pwdb_all
;
207 if (pstatus
->rx_pwdb_all
> (u32
) undecorated_smoothed_pwdb
) {
208 undecorated_smoothed_pwdb
= (((undecorated_smoothed_pwdb
) *
209 (RX_SMOOTH_FACTOR
- 1)) +
210 (pstatus
->rx_pwdb_all
)) / (RX_SMOOTH_FACTOR
);
211 undecorated_smoothed_pwdb
= undecorated_smoothed_pwdb
+ 1;
213 undecorated_smoothed_pwdb
= (((undecorated_smoothed_pwdb
) *
214 (RX_SMOOTH_FACTOR
- 1)) +
215 (pstatus
->rx_pwdb_all
)) / (RX_SMOOTH_FACTOR
);
219 drv_priv
->rssi_stat
.undecorated_smoothed_pwdb
=
220 undecorated_smoothed_pwdb
;
222 rtlpriv
->dm
.undecorated_smoothed_pwdb
= undecorated_smoothed_pwdb
;
226 rtl_update_rxsignalstatistics(hw
, pstatus
);
229 static void rtl_process_ui_link_quality(struct ieee80211_hw
*hw
,
230 struct rtl_stats
*pstatus
)
232 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
233 u32 last_evm
, n_stream
, tmpval
;
235 if (pstatus
->signalquality
== 0)
238 if (rtlpriv
->stats
.ui_link_quality
.total_num
++ >=
239 PHY_LINKQUALITY_SLID_WIN_MAX
) {
240 rtlpriv
->stats
.ui_link_quality
.total_num
=
241 PHY_LINKQUALITY_SLID_WIN_MAX
;
242 last_evm
= rtlpriv
->stats
.ui_link_quality
.elements
[
243 rtlpriv
->stats
.ui_link_quality
.index
];
244 rtlpriv
->stats
.ui_link_quality
.total_val
-= last_evm
;
246 rtlpriv
->stats
.ui_link_quality
.total_val
+= pstatus
->signalquality
;
247 rtlpriv
->stats
.ui_link_quality
.elements
[
248 rtlpriv
->stats
.ui_link_quality
.index
++] =
249 pstatus
->signalquality
;
250 if (rtlpriv
->stats
.ui_link_quality
.index
>=
251 PHY_LINKQUALITY_SLID_WIN_MAX
)
252 rtlpriv
->stats
.ui_link_quality
.index
= 0;
253 tmpval
= rtlpriv
->stats
.ui_link_quality
.total_val
/
254 rtlpriv
->stats
.ui_link_quality
.total_num
;
255 rtlpriv
->stats
.signal_quality
= tmpval
;
256 rtlpriv
->stats
.last_sigstrength_inpercent
= tmpval
;
257 for (n_stream
= 0; n_stream
< 2; n_stream
++) {
258 if (pstatus
->rx_mimo_signalquality
[n_stream
] != -1) {
259 if (rtlpriv
->stats
.rx_evm_percentage
[n_stream
] == 0) {
260 rtlpriv
->stats
.rx_evm_percentage
[n_stream
] =
261 pstatus
->rx_mimo_signalquality
[n_stream
];
263 rtlpriv
->stats
.rx_evm_percentage
[n_stream
] =
264 ((rtlpriv
->stats
.rx_evm_percentage
[n_stream
]
265 * (RX_SMOOTH_FACTOR
- 1)) +
266 (pstatus
->rx_mimo_signalquality
[n_stream
] * 1)) /
272 void rtl_process_phyinfo(struct ieee80211_hw
*hw
, u8
*buffer
,
273 struct rtl_stats
*pstatus
)
276 if (!pstatus
->b_packet_matchbssid
)
279 rtl_process_ui_rssi(hw
, pstatus
);
280 rtl_process_pwdb(hw
, pstatus
);
281 rtl_process_ui_link_quality(hw
, pstatus
);
283 //EXPORT_SYMBOL(rtl_process_phyinfo);