1 /******************************************************************************
5 * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved.
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.
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.
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,
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/sched.h>
37 #include "iwl-calib.h"
40 #include "iwl-helpers.h"
41 #include "iwl-agn-hw.h"
44 void iwl_rx_missed_beacon_notif(struct iwl_priv *priv,
45 struct iwl_rx_mem_buffer *rxb)
48 struct iwl_rx_packet *pkt = rxb_addr(rxb);
49 struct iwl_missed_beacon_notif *missed_beacon;
51 missed_beacon = &pkt->u.missed_beacon;
52 if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) >
53 priv->missed_beacon_threshold) {
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);
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. */
68 static void iwl_rx_calc_noise(struct iwl_priv *priv)
70 struct statistics_rx_non_phy *rx_info
71 = &(priv->_agn.statistics.rx.general);
72 int num_active_rx = 0;
73 int total_silence = 0;
75 le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
77 le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
79 le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
83 total_silence += bcn_silence_a;
87 total_silence += bcn_silence_b;
91 total_silence += bcn_silence_c;
95 /* Average among active antennas */
97 last_rx_noise = (total_silence / num_active_rx) - 107;
99 last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
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,
106 #ifdef CONFIG_IWLWIFI_DEBUGFS
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.
112 static void iwl_accumulative_statistics(struct iwl_priv *priv,
118 u32 *delta, *max_delta;
120 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;
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)
137 /* reset accumulative statistics for "no-counter" type statistics */
138 priv->_agn.accum_statistics.general.common.temperature =
139 priv->_agn.statistics.general.common.temperature;
140 priv->_agn.accum_statistics.general.common.temperature_m =
141 priv->_agn.statistics.general.common.temperature_m;
142 priv->_agn.accum_statistics.general.common.ttl_timestamp =
143 priv->_agn.statistics.general.common.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;
153 #define REG_RECALIB_PERIOD (60)
156 * iwl_good_plcp_health - checks for plcp error.
158 * When the plcp error is exceeding the thresholds, reset the radio
159 * to improve the throughput.
161 bool iwl_good_plcp_health(struct iwl_priv *priv,
162 struct iwl_rx_packet *pkt)
165 int combined_plcp_delta;
166 unsigned int plcp_msec;
167 unsigned long plcp_received_jiffies;
169 if (priv->cfg->plcp_delta_threshold ==
170 IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) {
171 IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n");
176 * check for plcp_err and trigger radio reset if it exceeds
177 * the plcp error threshold plcp_delta.
179 plcp_received_jiffies = jiffies;
180 plcp_msec = jiffies_to_msecs((long) plcp_received_jiffies -
181 (long) priv->plcp_jiffies);
182 priv->plcp_jiffies = plcp_received_jiffies;
184 * check to make sure plcp_msec is not 0 to prevent division
188 combined_plcp_delta =
189 (le32_to_cpu(pkt->u.stats.rx.ofdm.plcp_err) -
190 le32_to_cpu(priv->_agn.statistics.rx.ofdm.plcp_err)) +
191 (le32_to_cpu(pkt->u.stats.rx.ofdm_ht.plcp_err) -
192 le32_to_cpu(priv->_agn.statistics.rx.ofdm_ht.plcp_err));
194 if ((combined_plcp_delta > 0) &&
195 ((combined_plcp_delta * 100) / plcp_msec) >
196 priv->cfg->plcp_delta_threshold) {
198 * if plcp_err exceed the threshold,
199 * the following data is printed in csv format:
200 * Text: plcp_err exceeded %d,
201 * Received ofdm.plcp_err,
202 * Current ofdm.plcp_err,
203 * Received ofdm_ht.plcp_err,
204 * Current ofdm_ht.plcp_err,
205 * combined_plcp_delta,
208 IWL_DEBUG_RADIO(priv, "plcp_err exceeded %u, "
209 "%u, %u, %u, %u, %d, %u mSecs\n",
210 priv->cfg->plcp_delta_threshold,
211 le32_to_cpu(pkt->u.stats.rx.ofdm.plcp_err),
213 priv->_agn.statistics.rx.ofdm.plcp_err),
214 le32_to_cpu(pkt->u.stats.rx.ofdm_ht.plcp_err),
216 priv->_agn.statistics.rx.ofdm_ht.plcp_err),
217 combined_plcp_delta, plcp_msec);
224 void iwl_rx_statistics(struct iwl_priv *priv,
225 struct iwl_rx_mem_buffer *rxb)
228 struct iwl_rx_packet *pkt = rxb_addr(rxb);
231 IWL_DEBUG_RX(priv, "Statistics notification received (%d vs %d).\n",
232 (int)sizeof(priv->_agn.statistics),
233 le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
235 change = ((priv->_agn.statistics.general.common.temperature !=
236 pkt->u.stats.general.common.temperature) ||
237 ((priv->_agn.statistics.flag &
238 STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
239 (pkt->u.stats.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK)));
241 #ifdef CONFIG_IWLWIFI_DEBUGFS
242 iwl_accumulative_statistics(priv, (__le32 *)&pkt->u.stats);
244 iwl_recover_from_statistics(priv, pkt);
246 memcpy(&priv->_agn.statistics, &pkt->u.stats,
247 sizeof(priv->_agn.statistics));
249 set_bit(STATUS_STATISTICS, &priv->status);
251 /* Reschedule the statistics timer to occur in
252 * REG_RECALIB_PERIOD seconds to ensure we get a
253 * thermal update even if the uCode doesn't give
255 mod_timer(&priv->statistics_periodic, jiffies +
256 msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
258 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
259 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
260 iwl_rx_calc_noise(priv);
261 queue_work(priv->workqueue, &priv->run_time_calib_work);
263 if (priv->cfg->ops->lib->temp_ops.temperature && change)
264 priv->cfg->ops->lib->temp_ops.temperature(priv);
267 void iwl_reply_statistics(struct iwl_priv *priv,
268 struct iwl_rx_mem_buffer *rxb)
270 struct iwl_rx_packet *pkt = rxb_addr(rxb);
272 if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) {
273 #ifdef CONFIG_IWLWIFI_DEBUGFS
274 memset(&priv->_agn.accum_statistics, 0,
275 sizeof(struct iwl_notif_statistics));
276 memset(&priv->_agn.delta_statistics, 0,
277 sizeof(struct iwl_notif_statistics));
278 memset(&priv->_agn.max_delta, 0,
279 sizeof(struct iwl_notif_statistics));
281 IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
283 iwl_rx_statistics(priv, rxb);