blob: ad2bead25c82b2311a9ed4da0d955059e8c2feac [file] [log] [blame]
Wey-Yi Guy278fc732010-06-14 17:09:53 -07001/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
5 * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
19 * USA
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/sched.h>
34
35#include "iwl-dev.h"
36#include "iwl-core.h"
37#include "iwl-calib.h"
38#include "iwl-sta.h"
39#include "iwl-io.h"
40#include "iwl-helpers.h"
41#include "iwl-agn-hw.h"
42#include "iwl-agn.h"
43
44void iwl_rx_missed_beacon_notif(struct iwl_priv *priv,
45 struct iwl_rx_mem_buffer *rxb)
46
47{
48 struct iwl_rx_packet *pkt = rxb_addr(rxb);
49 struct iwl_missed_beacon_notif *missed_beacon;
50
51 missed_beacon = &pkt->u.missed_beacon;
52 if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) >
53 priv->missed_beacon_threshold) {
54 IWL_DEBUG_CALIB(priv,
55 "missed bcn cnsq %d totl %d rcd %d expctd %d\n",
56 le32_to_cpu(missed_beacon->consecutive_missed_beacons),
57 le32_to_cpu(missed_beacon->total_missed_becons),
58 le32_to_cpu(missed_beacon->num_recvd_beacons),
59 le32_to_cpu(missed_beacon->num_expected_beacons));
60 if (!test_bit(STATUS_SCANNING, &priv->status))
61 iwl_init_sensitivity(priv);
62 }
63}
64
65/* Calculate noise level, based on measurements during network silence just
66 * before arriving beacon. This measurement can be done only if we know
67 * exactly when to expect beacons, therefore only when we're associated. */
68static void iwl_rx_calc_noise(struct iwl_priv *priv)
69{
70 struct statistics_rx_non_phy *rx_info
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -070071 = &(priv->_agn.statistics.rx.general);
Wey-Yi Guy278fc732010-06-14 17:09:53 -070072 int num_active_rx = 0;
73 int total_silence = 0;
74 int bcn_silence_a =
75 le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
76 int bcn_silence_b =
77 le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
78 int bcn_silence_c =
79 le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
80 int last_rx_noise;
81
82 if (bcn_silence_a) {
83 total_silence += bcn_silence_a;
84 num_active_rx++;
85 }
86 if (bcn_silence_b) {
87 total_silence += bcn_silence_b;
88 num_active_rx++;
89 }
90 if (bcn_silence_c) {
91 total_silence += bcn_silence_c;
92 num_active_rx++;
93 }
94
95 /* Average among active antennas */
96 if (num_active_rx)
97 last_rx_noise = (total_silence / num_active_rx) - 107;
98 else
99 last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
100
101 IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n",
102 bcn_silence_a, bcn_silence_b, bcn_silence_c,
103 last_rx_noise);
104}
105
106#ifdef CONFIG_IWLWIFI_DEBUGFS
107/*
108 * based on the assumption of all statistics counter are in DWORD
109 * FIXME: This function is for debugging, do not deal with
110 * the case of counters roll-over.
111 */
112static void iwl_accumulative_statistics(struct iwl_priv *priv,
113 __le32 *stats)
114{
115 int i;
116 __le32 *prev_stats;
117 u32 *accum_stats;
118 u32 *delta, *max_delta;
119
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -0700120 prev_stats = (__le32 *)&priv->_agn.statistics;
121 accum_stats = (u32 *)&priv->_agn.accum_statistics;
122 delta = (u32 *)&priv->_agn.delta_statistics;
123 max_delta = (u32 *)&priv->_agn.max_delta;
Wey-Yi Guy278fc732010-06-14 17:09:53 -0700124
125 for (i = sizeof(__le32); i < sizeof(struct iwl_notif_statistics);
126 i += sizeof(__le32), stats++, prev_stats++, delta++,
127 max_delta++, accum_stats++) {
128 if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) {
129 *delta = (le32_to_cpu(*stats) -
130 le32_to_cpu(*prev_stats));
131 *accum_stats += *delta;
132 if (*delta > *max_delta)
133 *max_delta = *delta;
134 }
135 }
136
137 /* reset accumulative statistics for "no-counter" type statistics */
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -0700138 priv->_agn.accum_statistics.general.temperature =
139 priv->_agn.statistics.general.temperature;
140 priv->_agn.accum_statistics.general.temperature_m =
141 priv->_agn.statistics.general.temperature_m;
142 priv->_agn.accum_statistics.general.ttl_timestamp =
143 priv->_agn.statistics.general.ttl_timestamp;
144 priv->_agn.accum_statistics.tx.tx_power.ant_a =
145 priv->_agn.statistics.tx.tx_power.ant_a;
146 priv->_agn.accum_statistics.tx.tx_power.ant_b =
147 priv->_agn.statistics.tx.tx_power.ant_b;
148 priv->_agn.accum_statistics.tx.tx_power.ant_c =
149 priv->_agn.statistics.tx.tx_power.ant_c;
Wey-Yi Guy278fc732010-06-14 17:09:53 -0700150}
151#endif
152
153#define REG_RECALIB_PERIOD (60)
154
155/**
156 * iwl_good_plcp_health - checks for plcp error.
157 *
158 * When the plcp error is exceeding the thresholds, reset the radio
159 * to improve the throughput.
160 */
161bool iwl_good_plcp_health(struct iwl_priv *priv,
162 struct iwl_rx_packet *pkt)
163{
164 bool rc = true;
165 int combined_plcp_delta;
166 unsigned int plcp_msec;
167 unsigned long plcp_received_jiffies;
168
169 /*
170 * check for plcp_err and trigger radio reset if it exceeds
171 * the plcp error threshold plcp_delta.
172 */
173 plcp_received_jiffies = jiffies;
174 plcp_msec = jiffies_to_msecs((long) plcp_received_jiffies -
175 (long) priv->plcp_jiffies);
176 priv->plcp_jiffies = plcp_received_jiffies;
177 /*
178 * check to make sure plcp_msec is not 0 to prevent division
179 * by zero.
180 */
181 if (plcp_msec) {
182 combined_plcp_delta =
183 (le32_to_cpu(pkt->u.stats.rx.ofdm.plcp_err) -
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -0700184 le32_to_cpu(priv->_agn.statistics.rx.ofdm.plcp_err)) +
Wey-Yi Guy278fc732010-06-14 17:09:53 -0700185 (le32_to_cpu(pkt->u.stats.rx.ofdm_ht.plcp_err) -
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -0700186 le32_to_cpu(priv->_agn.statistics.rx.ofdm_ht.plcp_err));
Wey-Yi Guy278fc732010-06-14 17:09:53 -0700187
188 if ((combined_plcp_delta > 0) &&
189 ((combined_plcp_delta * 100) / plcp_msec) >
190 priv->cfg->plcp_delta_threshold) {
191 /*
192 * if plcp_err exceed the threshold,
193 * the following data is printed in csv format:
194 * Text: plcp_err exceeded %d,
195 * Received ofdm.plcp_err,
196 * Current ofdm.plcp_err,
197 * Received ofdm_ht.plcp_err,
198 * Current ofdm_ht.plcp_err,
199 * combined_plcp_delta,
200 * plcp_msec
201 */
202 IWL_DEBUG_RADIO(priv, "plcp_err exceeded %u, "
203 "%u, %u, %u, %u, %d, %u mSecs\n",
204 priv->cfg->plcp_delta_threshold,
205 le32_to_cpu(pkt->u.stats.rx.ofdm.plcp_err),
206 le32_to_cpu(
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -0700207 priv->_agn.statistics.rx.ofdm.plcp_err),
Wey-Yi Guy278fc732010-06-14 17:09:53 -0700208 le32_to_cpu(pkt->u.stats.rx.ofdm_ht.plcp_err),
209 le32_to_cpu(
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -0700210 priv->_agn.statistics.rx.ofdm_ht.plcp_err),
Wey-Yi Guy278fc732010-06-14 17:09:53 -0700211 combined_plcp_delta, plcp_msec);
212 rc = false;
213 }
214 }
215 return rc;
216}
217
218void iwl_rx_statistics(struct iwl_priv *priv,
219 struct iwl_rx_mem_buffer *rxb)
220{
221 int change;
222 struct iwl_rx_packet *pkt = rxb_addr(rxb);
223
224
225 IWL_DEBUG_RX(priv, "Statistics notification received (%d vs %d).\n",
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -0700226 (int)sizeof(priv->_agn.statistics),
Wey-Yi Guy278fc732010-06-14 17:09:53 -0700227 le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
228
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -0700229 change = ((priv->_agn.statistics.general.temperature !=
Wey-Yi Guy278fc732010-06-14 17:09:53 -0700230 pkt->u.stats.general.temperature) ||
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -0700231 ((priv->_agn.statistics.flag &
Wey-Yi Guy278fc732010-06-14 17:09:53 -0700232 STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
233 (pkt->u.stats.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK)));
234
235#ifdef CONFIG_IWLWIFI_DEBUGFS
236 iwl_accumulative_statistics(priv, (__le32 *)&pkt->u.stats);
237#endif
238 iwl_recover_from_statistics(priv, pkt);
239
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -0700240 memcpy(&priv->_agn.statistics, &pkt->u.stats,
241 sizeof(priv->_agn.statistics));
Wey-Yi Guy278fc732010-06-14 17:09:53 -0700242
243 set_bit(STATUS_STATISTICS, &priv->status);
244
245 /* Reschedule the statistics timer to occur in
246 * REG_RECALIB_PERIOD seconds to ensure we get a
247 * thermal update even if the uCode doesn't give
248 * us one */
249 mod_timer(&priv->statistics_periodic, jiffies +
250 msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
251
252 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
253 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
254 iwl_rx_calc_noise(priv);
255 queue_work(priv->workqueue, &priv->run_time_calib_work);
256 }
257 if (priv->cfg->ops->lib->temp_ops.temperature && change)
258 priv->cfg->ops->lib->temp_ops.temperature(priv);
259}
260
261void iwl_reply_statistics(struct iwl_priv *priv,
262 struct iwl_rx_mem_buffer *rxb)
263{
264 struct iwl_rx_packet *pkt = rxb_addr(rxb);
265
266 if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) {
267#ifdef CONFIG_IWLWIFI_DEBUGFS
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -0700268 memset(&priv->_agn.accum_statistics, 0,
Wey-Yi Guy278fc732010-06-14 17:09:53 -0700269 sizeof(struct iwl_notif_statistics));
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -0700270 memset(&priv->_agn.delta_statistics, 0,
Wey-Yi Guy278fc732010-06-14 17:09:53 -0700271 sizeof(struct iwl_notif_statistics));
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -0700272 memset(&priv->_agn.max_delta, 0,
Wey-Yi Guy278fc732010-06-14 17:09:53 -0700273 sizeof(struct iwl_notif_statistics));
274#endif
275 IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
276 }
277 iwl_rx_statistics(priv, rxb);
278}