Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * GPL LICENSE SUMMARY |
| 4 | * |
| 5 | * Copyright(c) 2008 - 2011 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-4965-calib.h" |
| 38 | #include "iwl-sta.h" |
| 39 | #include "iwl-io.h" |
| 40 | #include "iwl-helpers.h" |
| 41 | #include "iwl-4965-hw.h" |
| 42 | #include "iwl-4965.h" |
| 43 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 44 | void il4965_rx_missed_beacon_notif(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 45 | struct il_rx_mem_buffer *rxb) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 46 | |
| 47 | { |
Stanislaw Gruszka | dcae1c6 | 2011-08-26 14:36:21 +0200 | [diff] [blame] | 48 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 49 | struct il_missed_beacon_notif *missed_beacon; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 50 | |
| 51 | missed_beacon = &pkt->u.missed_beacon; |
| 52 | if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) > |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 53 | il->missed_beacon_threshold) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 54 | D_CALIB( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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)); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 60 | if (!test_bit(STATUS_SCANNING, &il->status)) |
| 61 | il4965_init_sensitivity(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 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. */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 68 | static void il4965_rx_calc_noise(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 69 | { |
| 70 | struct statistics_rx_non_phy *rx_info; |
| 71 | int num_active_rx = 0; |
| 72 | int total_silence = 0; |
| 73 | int bcn_silence_a, bcn_silence_b, bcn_silence_c; |
| 74 | int last_rx_noise; |
| 75 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 76 | rx_info = &(il->_4965.statistics.rx.general); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 77 | bcn_silence_a = |
| 78 | le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER; |
| 79 | bcn_silence_b = |
| 80 | le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER; |
| 81 | bcn_silence_c = |
| 82 | le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER; |
| 83 | |
| 84 | if (bcn_silence_a) { |
| 85 | total_silence += bcn_silence_a; |
| 86 | num_active_rx++; |
| 87 | } |
| 88 | if (bcn_silence_b) { |
| 89 | total_silence += bcn_silence_b; |
| 90 | num_active_rx++; |
| 91 | } |
| 92 | if (bcn_silence_c) { |
| 93 | total_silence += bcn_silence_c; |
| 94 | num_active_rx++; |
| 95 | } |
| 96 | |
| 97 | /* Average among active antennas */ |
| 98 | if (num_active_rx) |
| 99 | last_rx_noise = (total_silence / num_active_rx) - 107; |
| 100 | else |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 101 | last_rx_noise = IL_NOISE_MEAS_NOT_AVAILABLE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 102 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 103 | D_CALIB("inband silence a %u, b %u, c %u, dBm %d\n", |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 104 | bcn_silence_a, bcn_silence_b, bcn_silence_c, |
| 105 | last_rx_noise); |
| 106 | } |
| 107 | |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 108 | #ifdef CONFIG_IWLEGACY_DEBUGFS |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 109 | /* |
| 110 | * based on the assumption of all statistics counter are in DWORD |
| 111 | * FIXME: This function is for debugging, do not deal with |
| 112 | * the case of counters roll-over. |
| 113 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 114 | static void il4965_accumulative_statistics(struct il_priv *il, |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 115 | __le32 *stats) |
| 116 | { |
| 117 | int i, size; |
| 118 | __le32 *prev_stats; |
| 119 | u32 *accum_stats; |
| 120 | u32 *delta, *max_delta; |
| 121 | struct statistics_general_common *general, *accum_general; |
| 122 | struct statistics_tx *tx, *accum_tx; |
| 123 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 124 | prev_stats = (__le32 *)&il->_4965.statistics; |
| 125 | accum_stats = (u32 *)&il->_4965.accum_statistics; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 126 | size = sizeof(struct il_notif_statistics); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 127 | general = &il->_4965.statistics.general.common; |
| 128 | accum_general = &il->_4965.accum_statistics.general.common; |
| 129 | tx = &il->_4965.statistics.tx; |
| 130 | accum_tx = &il->_4965.accum_statistics.tx; |
| 131 | delta = (u32 *)&il->_4965.delta_statistics; |
| 132 | max_delta = (u32 *)&il->_4965.max_delta; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 133 | |
| 134 | for (i = sizeof(__le32); i < size; |
| 135 | i += sizeof(__le32), stats++, prev_stats++, delta++, |
| 136 | max_delta++, accum_stats++) { |
| 137 | if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) { |
| 138 | *delta = (le32_to_cpu(*stats) - |
| 139 | le32_to_cpu(*prev_stats)); |
| 140 | *accum_stats += *delta; |
| 141 | if (*delta > *max_delta) |
| 142 | *max_delta = *delta; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /* reset accumulative statistics for "no-counter" type statistics */ |
| 147 | accum_general->temperature = general->temperature; |
| 148 | accum_general->ttl_timestamp = general->ttl_timestamp; |
| 149 | } |
| 150 | #endif |
| 151 | |
| 152 | #define REG_RECALIB_PERIOD (60) |
| 153 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 154 | void il4965_rx_statistics(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 155 | struct il_rx_mem_buffer *rxb) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 156 | { |
| 157 | int change; |
Stanislaw Gruszka | dcae1c6 | 2011-08-26 14:36:21 +0200 | [diff] [blame] | 158 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 159 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 160 | D_RX( |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 161 | "Statistics notification received (%d vs %d).\n", |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 162 | (int)sizeof(struct il_notif_statistics), |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 163 | le32_to_cpu(pkt->len_n_flags) & |
| 164 | FH_RSCSR_FRAME_SIZE_MSK); |
| 165 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 166 | change = ((il->_4965.statistics.general.common.temperature != |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 167 | pkt->u.stats.general.common.temperature) || |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 168 | ((il->_4965.statistics.flag & |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 169 | STATISTICS_REPLY_FLG_HT40_MODE_MSK) != |
| 170 | (pkt->u.stats.flag & |
| 171 | STATISTICS_REPLY_FLG_HT40_MODE_MSK))); |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 172 | #ifdef CONFIG_IWLEGACY_DEBUGFS |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 173 | il4965_accumulative_statistics(il, (__le32 *)&pkt->u.stats); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 174 | #endif |
| 175 | |
Stanislaw Gruszka | ecaee0f | 2011-06-08 15:28:25 +0200 | [diff] [blame] | 176 | /* TODO: reading some of statistics is unneeded */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 177 | memcpy(&il->_4965.statistics, &pkt->u.stats, |
| 178 | sizeof(il->_4965.statistics)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 179 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 180 | set_bit(STATUS_STATISTICS, &il->status); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 181 | |
| 182 | /* Reschedule the statistics timer to occur in |
| 183 | * REG_RECALIB_PERIOD seconds to ensure we get a |
| 184 | * thermal update even if the uCode doesn't give |
| 185 | * us one */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 186 | mod_timer(&il->statistics_periodic, jiffies + |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 187 | msecs_to_jiffies(REG_RECALIB_PERIOD * 1000)); |
| 188 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 189 | if (unlikely(!test_bit(STATUS_SCANNING, &il->status)) && |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 190 | (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 191 | il4965_rx_calc_noise(il); |
| 192 | queue_work(il->workqueue, &il->run_time_calib_work); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 193 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 194 | if (il->cfg->ops->lib->temp_ops.temperature && change) |
| 195 | il->cfg->ops->lib->temp_ops.temperature(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 198 | void il4965_reply_statistics(struct il_priv *il, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 199 | struct il_rx_mem_buffer *rxb) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 200 | { |
Stanislaw Gruszka | dcae1c6 | 2011-08-26 14:36:21 +0200 | [diff] [blame] | 201 | struct il_rx_pkt *pkt = rxb_addr(rxb); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 202 | |
| 203 | if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) { |
Stanislaw Gruszka | d317516 | 2011-11-15 11:25:42 +0100 | [diff] [blame] | 204 | #ifdef CONFIG_IWLEGACY_DEBUGFS |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 205 | memset(&il->_4965.accum_statistics, 0, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 206 | sizeof(struct il_notif_statistics)); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 207 | memset(&il->_4965.delta_statistics, 0, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 208 | sizeof(struct il_notif_statistics)); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 209 | memset(&il->_4965.max_delta, 0, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 210 | sizeof(struct il_notif_statistics)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 211 | #endif |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 212 | D_RX("Statistics have been cleared\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 213 | } |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 214 | il4965_rx_statistics(il, rxb); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 215 | } |