Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Wey-Yi Guy | 901069c | 2011-04-05 09:42:00 -0700 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved. |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
Emmanuel Grumbach | 6a686c6 | 2011-10-10 07:27:17 -0700 | [diff] [blame^] | 6 | * as portionhelp of the ieee80211 subsystem header files. |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 30 | #include <linux/etherdevice.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Stanislaw Gruszka | 118253c | 2011-03-07 09:22:24 +0100 | [diff] [blame] | 32 | #include <linux/sched.h> |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 33 | #include <net/mac80211.h> |
Tomas Winkler | a05ffd3 | 2008-07-10 14:28:42 +0300 | [diff] [blame] | 34 | #include <asm/unaligned.h> |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 35 | #include "iwl-eeprom.h" |
| 36 | #include "iwl-dev.h" |
| 37 | #include "iwl-core.h" |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 38 | #include "iwl-io.h" |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 39 | #include "iwl-agn-calib.h" |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 40 | #include "iwl-agn.h" |
Emmanuel Grumbach | 48f20d3 | 2011-08-25 23:10:36 -0700 | [diff] [blame] | 41 | #include "iwl-shared.h" |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 42 | |
Emmanuel Grumbach | 522376d | 2011-09-06 09:31:19 -0700 | [diff] [blame] | 43 | const char *get_cmd_string(u8 cmd) |
| 44 | { |
| 45 | switch (cmd) { |
| 46 | IWL_CMD(REPLY_ALIVE); |
| 47 | IWL_CMD(REPLY_ERROR); |
Wey-Yi Guy | 7e4005c | 2011-10-10 07:26:51 -0700 | [diff] [blame] | 48 | IWL_CMD(REPLY_ECHO); |
Emmanuel Grumbach | 522376d | 2011-09-06 09:31:19 -0700 | [diff] [blame] | 49 | IWL_CMD(REPLY_RXON); |
| 50 | IWL_CMD(REPLY_RXON_ASSOC); |
| 51 | IWL_CMD(REPLY_QOS_PARAM); |
| 52 | IWL_CMD(REPLY_RXON_TIMING); |
| 53 | IWL_CMD(REPLY_ADD_STA); |
| 54 | IWL_CMD(REPLY_REMOVE_STA); |
| 55 | IWL_CMD(REPLY_REMOVE_ALL_STA); |
| 56 | IWL_CMD(REPLY_TXFIFO_FLUSH); |
| 57 | IWL_CMD(REPLY_WEPKEY); |
| 58 | IWL_CMD(REPLY_TX); |
| 59 | IWL_CMD(REPLY_LEDS_CMD); |
| 60 | IWL_CMD(REPLY_TX_LINK_QUALITY_CMD); |
| 61 | IWL_CMD(COEX_PRIORITY_TABLE_CMD); |
| 62 | IWL_CMD(COEX_MEDIUM_NOTIFICATION); |
| 63 | IWL_CMD(COEX_EVENT_CMD); |
| 64 | IWL_CMD(REPLY_QUIET_CMD); |
| 65 | IWL_CMD(REPLY_CHANNEL_SWITCH); |
| 66 | IWL_CMD(CHANNEL_SWITCH_NOTIFICATION); |
| 67 | IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD); |
| 68 | IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION); |
| 69 | IWL_CMD(POWER_TABLE_CMD); |
| 70 | IWL_CMD(PM_SLEEP_NOTIFICATION); |
| 71 | IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC); |
| 72 | IWL_CMD(REPLY_SCAN_CMD); |
| 73 | IWL_CMD(REPLY_SCAN_ABORT_CMD); |
| 74 | IWL_CMD(SCAN_START_NOTIFICATION); |
| 75 | IWL_CMD(SCAN_RESULTS_NOTIFICATION); |
| 76 | IWL_CMD(SCAN_COMPLETE_NOTIFICATION); |
| 77 | IWL_CMD(BEACON_NOTIFICATION); |
| 78 | IWL_CMD(REPLY_TX_BEACON); |
| 79 | IWL_CMD(WHO_IS_AWAKE_NOTIFICATION); |
| 80 | IWL_CMD(QUIET_NOTIFICATION); |
| 81 | IWL_CMD(REPLY_TX_PWR_TABLE_CMD); |
| 82 | IWL_CMD(MEASURE_ABORT_NOTIFICATION); |
| 83 | IWL_CMD(REPLY_BT_CONFIG); |
| 84 | IWL_CMD(REPLY_STATISTICS_CMD); |
| 85 | IWL_CMD(STATISTICS_NOTIFICATION); |
| 86 | IWL_CMD(REPLY_CARD_STATE_CMD); |
| 87 | IWL_CMD(CARD_STATE_NOTIFICATION); |
| 88 | IWL_CMD(MISSED_BEACONS_NOTIFICATION); |
| 89 | IWL_CMD(REPLY_CT_KILL_CONFIG_CMD); |
| 90 | IWL_CMD(SENSITIVITY_CMD); |
| 91 | IWL_CMD(REPLY_PHY_CALIBRATION_CMD); |
| 92 | IWL_CMD(REPLY_RX_PHY_CMD); |
| 93 | IWL_CMD(REPLY_RX_MPDU_CMD); |
| 94 | IWL_CMD(REPLY_RX); |
| 95 | IWL_CMD(REPLY_COMPRESSED_BA); |
| 96 | IWL_CMD(CALIBRATION_CFG_CMD); |
| 97 | IWL_CMD(CALIBRATION_RES_NOTIFICATION); |
| 98 | IWL_CMD(CALIBRATION_COMPLETE_NOTIFICATION); |
| 99 | IWL_CMD(REPLY_TX_POWER_DBM_CMD); |
| 100 | IWL_CMD(TEMPERATURE_NOTIFICATION); |
| 101 | IWL_CMD(TX_ANT_CONFIGURATION_CMD); |
| 102 | IWL_CMD(REPLY_BT_COEX_PROFILE_NOTIF); |
| 103 | IWL_CMD(REPLY_BT_COEX_PRIO_TABLE); |
| 104 | IWL_CMD(REPLY_BT_COEX_PROT_ENV); |
| 105 | IWL_CMD(REPLY_WIPAN_PARAMS); |
| 106 | IWL_CMD(REPLY_WIPAN_RXON); |
| 107 | IWL_CMD(REPLY_WIPAN_RXON_TIMING); |
| 108 | IWL_CMD(REPLY_WIPAN_RXON_ASSOC); |
| 109 | IWL_CMD(REPLY_WIPAN_QOS_PARAM); |
| 110 | IWL_CMD(REPLY_WIPAN_WEPKEY); |
| 111 | IWL_CMD(REPLY_WIPAN_P2P_CHANNEL_SWITCH); |
| 112 | IWL_CMD(REPLY_WIPAN_NOA_NOTIFICATION); |
| 113 | IWL_CMD(REPLY_WIPAN_DEACTIVATION_COMPLETE); |
| 114 | IWL_CMD(REPLY_WOWLAN_PATTERNS); |
| 115 | IWL_CMD(REPLY_WOWLAN_WAKEUP_FILTER); |
| 116 | IWL_CMD(REPLY_WOWLAN_TSC_RSC_PARAMS); |
| 117 | IWL_CMD(REPLY_WOWLAN_TKIP_PARAMS); |
| 118 | IWL_CMD(REPLY_WOWLAN_KEK_KCK_MATERIAL); |
| 119 | IWL_CMD(REPLY_WOWLAN_GET_STATUS); |
| 120 | default: |
| 121 | return "UNKNOWN"; |
| 122 | |
| 123 | } |
| 124 | } |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 125 | |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 126 | /****************************************************************************** |
| 127 | * |
| 128 | * Generic RX handler implementations |
| 129 | * |
| 130 | ******************************************************************************/ |
| 131 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 132 | static int iwlagn_rx_reply_error(struct iwl_priv *priv, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 133 | struct iwl_rx_mem_buffer *rxb, |
| 134 | struct iwl_device_cmd *cmd) |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 135 | { |
| 136 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 137 | |
| 138 | IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) " |
| 139 | "seq 0x%04X ser 0x%08X\n", |
| 140 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 141 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 142 | pkt->u.err_resp.cmd_id, |
| 143 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 144 | le32_to_cpu(pkt->u.err_resp.error_info)); |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 145 | return 0; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 148 | static int iwlagn_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 149 | struct iwl_device_cmd *cmd) |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 150 | { |
| 151 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 152 | struct iwl_csa_notification *csa = &(pkt->u.csa_notif); |
| 153 | /* |
| 154 | * MULTI-FIXME |
Wey-Yi Guy | ade4c64 | 2011-10-10 07:27:11 -0700 | [diff] [blame] | 155 | * See iwlagn_mac_channel_switch. |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 156 | */ |
| 157 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
| 158 | struct iwl_rxon_cmd *rxon = (void *)&ctx->active; |
| 159 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 160 | if (!test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status)) |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 161 | return 0; |
Stanislaw Gruszka | 6f213ff | 2011-06-02 18:17:15 +0200 | [diff] [blame] | 162 | |
| 163 | if (!le32_to_cpu(csa->status) && csa->channel == priv->switch_channel) { |
| 164 | rxon->channel = csa->channel; |
| 165 | ctx->staging.channel = csa->channel; |
| 166 | IWL_DEBUG_11H(priv, "CSA notif: channel %d\n", |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 167 | le16_to_cpu(csa->channel)); |
Stanislaw Gruszka | 6f213ff | 2011-06-02 18:17:15 +0200 | [diff] [blame] | 168 | iwl_chswitch_done(priv, true); |
| 169 | } else { |
| 170 | IWL_ERR(priv, "CSA notif (fail) : channel %d\n", |
| 171 | le16_to_cpu(csa->channel)); |
| 172 | iwl_chswitch_done(priv, false); |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 173 | } |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 174 | return 0; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 178 | static int iwlagn_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 179 | struct iwl_rx_mem_buffer *rxb, |
| 180 | struct iwl_device_cmd *cmd) |
Reinette Chatre | 81963d6 | 2010-01-22 14:22:57 -0800 | [diff] [blame] | 181 | { |
| 182 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 183 | struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif); |
| 184 | |
| 185 | if (!report->state) { |
| 186 | IWL_DEBUG_11H(priv, |
| 187 | "Spectrum Measure Notification: Start\n"); |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 188 | return 0; |
Reinette Chatre | 81963d6 | 2010-01-22 14:22:57 -0800 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 192 | priv->measurement_status |= MEASUREMENT_READY; |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 193 | return 0; |
Reinette Chatre | 81963d6 | 2010-01-22 14:22:57 -0800 | [diff] [blame] | 194 | } |
Reinette Chatre | 81963d6 | 2010-01-22 14:22:57 -0800 | [diff] [blame] | 195 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 196 | static int iwlagn_rx_pm_sleep_notif(struct iwl_priv *priv, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 197 | struct iwl_rx_mem_buffer *rxb, |
| 198 | struct iwl_device_cmd *cmd) |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 199 | { |
| 200 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 201 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 202 | struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif); |
| 203 | IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n", |
| 204 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 205 | #endif |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 206 | return 0; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 207 | } |
| 208 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 209 | static int iwlagn_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 210 | struct iwl_rx_mem_buffer *rxb, |
| 211 | struct iwl_device_cmd *cmd) |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 212 | { |
| 213 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Emmanuel Grumbach | 44856c6 | 2011-08-25 23:10:45 -0700 | [diff] [blame] | 214 | u32 __maybe_unused len = |
| 215 | le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 216 | IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled " |
| 217 | "notification for %s:\n", len, |
| 218 | get_cmd_string(pkt->hdr.cmd)); |
| 219 | iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len); |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 220 | return 0; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 221 | } |
| 222 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 223 | static int iwlagn_rx_beacon_notif(struct iwl_priv *priv, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 224 | struct iwl_rx_mem_buffer *rxb, |
| 225 | struct iwl_device_cmd *cmd) |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 226 | { |
| 227 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 228 | struct iwlagn_beacon_notif *beacon = (void *)pkt->u.raw; |
| 229 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 230 | u16 status = le16_to_cpu(beacon->beacon_notify_hdr.status.status); |
| 231 | u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); |
| 232 | |
| 233 | IWL_DEBUG_RX(priv, "beacon status %#x, retries:%d ibssmgr:%d " |
| 234 | "tsf:0x%.8x%.8x rate:%d\n", |
| 235 | status & TX_STATUS_MSK, |
| 236 | beacon->beacon_notify_hdr.failure_frame, |
| 237 | le32_to_cpu(beacon->ibss_mgr_status), |
| 238 | le32_to_cpu(beacon->high_tsf), |
| 239 | le32_to_cpu(beacon->low_tsf), rate); |
| 240 | #endif |
| 241 | |
| 242 | priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status); |
| 243 | |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 244 | return 0; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 245 | } |
| 246 | |
Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 247 | /* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */ |
| 248 | #define ACK_CNT_RATIO (50) |
| 249 | #define BA_TIMEOUT_CNT (5) |
| 250 | #define BA_TIMEOUT_MAX (16) |
| 251 | |
| 252 | /** |
| 253 | * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries. |
| 254 | * |
| 255 | * When the ACK count ratio is low and aggregated BA timeout retries exceeding |
| 256 | * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal |
| 257 | * operation state. |
| 258 | */ |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 259 | static bool iwlagn_good_ack_health(struct iwl_priv *priv, |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 260 | struct statistics_tx *cur) |
Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 261 | { |
| 262 | int actual_delta, expected_delta, ba_timeout_delta; |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 263 | struct statistics_tx *old; |
Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 264 | |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 265 | if (priv->agg_tids_count) |
Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 266 | return true; |
| 267 | |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 268 | old = &priv->statistics.tx; |
Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 269 | |
| 270 | actual_delta = le32_to_cpu(cur->actual_ack_cnt) - |
| 271 | le32_to_cpu(old->actual_ack_cnt); |
| 272 | expected_delta = le32_to_cpu(cur->expected_ack_cnt) - |
| 273 | le32_to_cpu(old->expected_ack_cnt); |
| 274 | |
| 275 | /* Values should not be negative, but we do not trust the firmware */ |
| 276 | if (actual_delta <= 0 || expected_delta <= 0) |
| 277 | return true; |
| 278 | |
| 279 | ba_timeout_delta = le32_to_cpu(cur->agg.ba_timeout) - |
| 280 | le32_to_cpu(old->agg.ba_timeout); |
| 281 | |
| 282 | if ((actual_delta * 100 / expected_delta) < ACK_CNT_RATIO && |
| 283 | ba_timeout_delta > BA_TIMEOUT_CNT) { |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 284 | IWL_DEBUG_RADIO(priv, |
| 285 | "deltas: actual %d expected %d ba_timeout %d\n", |
| 286 | actual_delta, expected_delta, ba_timeout_delta); |
Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 287 | |
| 288 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 289 | /* |
| 290 | * This is ifdef'ed on DEBUGFS because otherwise the |
| 291 | * statistics aren't available. If DEBUGFS is set but |
| 292 | * DEBUG is not, these will just compile out. |
| 293 | */ |
| 294 | IWL_DEBUG_RADIO(priv, "rx_detected_cnt delta %d\n", |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 295 | priv->delta_stats.tx.rx_detected_cnt); |
Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 296 | IWL_DEBUG_RADIO(priv, |
| 297 | "ack_or_ba_timeout_collision delta %d\n", |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 298 | priv->delta_stats.tx.ack_or_ba_timeout_collision); |
Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 299 | #endif |
| 300 | |
| 301 | if (ba_timeout_delta >= BA_TIMEOUT_MAX) |
| 302 | return false; |
| 303 | } |
| 304 | |
| 305 | return true; |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * iwl_good_plcp_health - checks for plcp error. |
| 310 | * |
| 311 | * When the plcp error is exceeding the thresholds, reset the radio |
| 312 | * to improve the throughput. |
| 313 | */ |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 314 | static bool iwlagn_good_plcp_health(struct iwl_priv *priv, |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 315 | struct statistics_rx_phy *cur_ofdm, |
| 316 | struct statistics_rx_ht_phy *cur_ofdm_ht, |
| 317 | unsigned int msecs) |
Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 318 | { |
Stanislaw Gruszka | 6198c38 | 2011-03-04 17:51:50 +0100 | [diff] [blame] | 319 | int delta; |
| 320 | int threshold = priv->cfg->base_params->plcp_delta_threshold; |
Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 321 | |
Stanislaw Gruszka | 6198c38 | 2011-03-04 17:51:50 +0100 | [diff] [blame] | 322 | if (threshold == IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) { |
Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 323 | IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n"); |
Stanislaw Gruszka | 6198c38 | 2011-03-04 17:51:50 +0100 | [diff] [blame] | 324 | return true; |
Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 325 | } |
| 326 | |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 327 | delta = le32_to_cpu(cur_ofdm->plcp_err) - |
| 328 | le32_to_cpu(priv->statistics.rx_ofdm.plcp_err) + |
| 329 | le32_to_cpu(cur_ofdm_ht->plcp_err) - |
| 330 | le32_to_cpu(priv->statistics.rx_ofdm_ht.plcp_err); |
Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 331 | |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 332 | /* Can be negative if firmware reset statistics */ |
Stanislaw Gruszka | 6198c38 | 2011-03-04 17:51:50 +0100 | [diff] [blame] | 333 | if (delta <= 0) |
| 334 | return true; |
| 335 | |
| 336 | if ((delta * 100 / msecs) > threshold) { |
| 337 | IWL_DEBUG_RADIO(priv, |
| 338 | "plcp health threshold %u delta %d msecs %u\n", |
| 339 | threshold, delta, msecs); |
| 340 | return false; |
| 341 | } |
| 342 | |
| 343 | return true; |
Stanislaw Gruszka | ad6e82a | 2011-02-28 14:33:16 +0100 | [diff] [blame] | 344 | } |
| 345 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 346 | static void iwlagn_recover_from_statistics(struct iwl_priv *priv, |
| 347 | struct statistics_rx_phy *cur_ofdm, |
| 348 | struct statistics_rx_ht_phy *cur_ofdm_ht, |
| 349 | struct statistics_tx *tx, |
| 350 | unsigned long stamp) |
Wey-Yi Guy | fa8f130 | 2010-03-05 14:22:46 -0800 | [diff] [blame] | 351 | { |
Stanislaw Gruszka | 410f2bb | 2011-03-04 17:51:51 +0100 | [diff] [blame] | 352 | unsigned int msecs; |
Stanislaw Gruszka | b7977ff | 2011-02-28 14:33:15 +0100 | [diff] [blame] | 353 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 354 | if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) |
Stanislaw Gruszka | 410f2bb | 2011-03-04 17:51:51 +0100 | [diff] [blame] | 355 | return; |
| 356 | |
Stanislaw Gruszka | 410f2bb | 2011-03-04 17:51:51 +0100 | [diff] [blame] | 357 | msecs = jiffies_to_msecs(stamp - priv->rx_statistics_jiffies); |
| 358 | |
| 359 | /* Only gather statistics and update time stamp when not associated */ |
| 360 | if (!iwl_is_any_associated(priv)) |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 361 | return; |
Stanislaw Gruszka | 410f2bb | 2011-03-04 17:51:51 +0100 | [diff] [blame] | 362 | |
| 363 | /* Do not check/recover when do not have enough statistics data */ |
| 364 | if (msecs < 99) |
Wey-Yi Guy | fa8f130 | 2010-03-05 14:22:46 -0800 | [diff] [blame] | 365 | return; |
Stanislaw Gruszka | ca3d938 | 2011-02-08 09:31:55 +0100 | [diff] [blame] | 366 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 367 | if (iwlagn_mod_params.ack_check && !iwlagn_good_ack_health(priv, tx)) { |
Stanislaw Gruszka | ca3d938 | 2011-02-08 09:31:55 +0100 | [diff] [blame] | 368 | IWL_ERR(priv, "low ack count detected, restart firmware\n"); |
| 369 | if (!iwl_force_reset(priv, IWL_FW_RESET, false)) |
| 370 | return; |
Trieu 'Andrew' Nguyen | 3e4fb5f | 2010-01-22 14:22:46 -0800 | [diff] [blame] | 371 | } |
Stanislaw Gruszka | ca3d938 | 2011-02-08 09:31:55 +0100 | [diff] [blame] | 372 | |
Don Fry | 9d143e9 | 2011-04-20 15:23:57 -0700 | [diff] [blame] | 373 | if (iwlagn_mod_params.plcp_check && |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 374 | !iwlagn_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs)) |
Stanislaw Gruszka | ca3d938 | 2011-02-08 09:31:55 +0100 | [diff] [blame] | 375 | iwl_force_reset(priv, IWL_RF_RESET, false); |
Wey-Yi Guy | beac549 | 2010-03-04 13:38:58 -0800 | [diff] [blame] | 376 | } |
Wey-Yi Guy | beac549 | 2010-03-04 13:38:58 -0800 | [diff] [blame] | 377 | |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 378 | /* Calculate noise level, based on measurements during network silence just |
| 379 | * before arriving beacon. This measurement can be done only if we know |
| 380 | * exactly when to expect beacons, therefore only when we're associated. */ |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 381 | static void iwlagn_rx_calc_noise(struct iwl_priv *priv) |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 382 | { |
| 383 | struct statistics_rx_non_phy *rx_info; |
| 384 | int num_active_rx = 0; |
| 385 | int total_silence = 0; |
| 386 | int bcn_silence_a, bcn_silence_b, bcn_silence_c; |
| 387 | int last_rx_noise; |
| 388 | |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 389 | rx_info = &priv->statistics.rx_non_phy; |
| 390 | |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 391 | bcn_silence_a = |
| 392 | le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER; |
| 393 | bcn_silence_b = |
| 394 | le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER; |
| 395 | bcn_silence_c = |
| 396 | le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER; |
| 397 | |
| 398 | if (bcn_silence_a) { |
| 399 | total_silence += bcn_silence_a; |
| 400 | num_active_rx++; |
| 401 | } |
| 402 | if (bcn_silence_b) { |
| 403 | total_silence += bcn_silence_b; |
| 404 | num_active_rx++; |
| 405 | } |
| 406 | if (bcn_silence_c) { |
| 407 | total_silence += bcn_silence_c; |
| 408 | num_active_rx++; |
| 409 | } |
| 410 | |
| 411 | /* Average among active antennas */ |
| 412 | if (num_active_rx) |
| 413 | last_rx_noise = (total_silence / num_active_rx) - 107; |
| 414 | else |
| 415 | last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE; |
| 416 | |
| 417 | IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n", |
| 418 | bcn_silence_a, bcn_silence_b, bcn_silence_c, |
| 419 | last_rx_noise); |
| 420 | } |
| 421 | |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 422 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 423 | /* |
| 424 | * based on the assumption of all statistics counter are in DWORD |
| 425 | * FIXME: This function is for debugging, do not deal with |
| 426 | * the case of counters roll-over. |
| 427 | */ |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 428 | static void accum_stats(__le32 *prev, __le32 *cur, __le32 *delta, |
| 429 | __le32 *max_delta, __le32 *accum, int size) |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 430 | { |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 431 | int i; |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 432 | |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 433 | for (i = 0; |
| 434 | i < size / sizeof(__le32); |
| 435 | i++, prev++, cur++, delta++, max_delta++, accum++) { |
| 436 | if (le32_to_cpu(*cur) > le32_to_cpu(*prev)) { |
| 437 | *delta = cpu_to_le32( |
| 438 | le32_to_cpu(*cur) - le32_to_cpu(*prev)); |
| 439 | le32_add_cpu(accum, le32_to_cpu(*delta)); |
| 440 | if (le32_to_cpu(*delta) > le32_to_cpu(*max_delta)) |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 441 | *max_delta = *delta; |
| 442 | } |
| 443 | } |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 444 | } |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 445 | |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 446 | static void |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 447 | iwlagn_accumulative_statistics(struct iwl_priv *priv, |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 448 | struct statistics_general_common *common, |
| 449 | struct statistics_rx_non_phy *rx_non_phy, |
| 450 | struct statistics_rx_phy *rx_ofdm, |
| 451 | struct statistics_rx_ht_phy *rx_ofdm_ht, |
| 452 | struct statistics_rx_phy *rx_cck, |
| 453 | struct statistics_tx *tx, |
| 454 | struct statistics_bt_activity *bt_activity) |
| 455 | { |
| 456 | #define ACCUM(_name) \ |
| 457 | accum_stats((__le32 *)&priv->statistics._name, \ |
| 458 | (__le32 *)_name, \ |
| 459 | (__le32 *)&priv->delta_stats._name, \ |
| 460 | (__le32 *)&priv->max_delta_stats._name, \ |
| 461 | (__le32 *)&priv->accum_stats._name, \ |
| 462 | sizeof(*_name)); |
| 463 | |
| 464 | ACCUM(common); |
| 465 | ACCUM(rx_non_phy); |
| 466 | ACCUM(rx_ofdm); |
| 467 | ACCUM(rx_ofdm_ht); |
| 468 | ACCUM(rx_cck); |
| 469 | ACCUM(tx); |
| 470 | if (bt_activity) |
| 471 | ACCUM(bt_activity); |
| 472 | #undef ACCUM |
| 473 | } |
| 474 | #else |
| 475 | static inline void |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 476 | iwlagn_accumulative_statistics(struct iwl_priv *priv, |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 477 | struct statistics_general_common *common, |
| 478 | struct statistics_rx_non_phy *rx_non_phy, |
| 479 | struct statistics_rx_phy *rx_ofdm, |
| 480 | struct statistics_rx_ht_phy *rx_ofdm_ht, |
| 481 | struct statistics_rx_phy *rx_cck, |
| 482 | struct statistics_tx *tx, |
| 483 | struct statistics_bt_activity *bt_activity) |
| 484 | { |
| 485 | } |
| 486 | #endif |
| 487 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 488 | static int iwlagn_rx_statistics(struct iwl_priv *priv, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 489 | struct iwl_rx_mem_buffer *rxb, |
| 490 | struct iwl_device_cmd *cmd) |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 491 | { |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 492 | unsigned long stamp = jiffies; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 493 | const int reg_recalib_period = 60; |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 494 | int change; |
| 495 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 496 | u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; |
| 497 | __le32 *flag; |
| 498 | struct statistics_general_common *common; |
| 499 | struct statistics_rx_non_phy *rx_non_phy; |
| 500 | struct statistics_rx_phy *rx_ofdm; |
| 501 | struct statistics_rx_ht_phy *rx_ofdm_ht; |
| 502 | struct statistics_rx_phy *rx_cck; |
| 503 | struct statistics_tx *tx; |
| 504 | struct statistics_bt_activity *bt_activity; |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 505 | |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 506 | len -= sizeof(struct iwl_cmd_header); /* skip header */ |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 507 | |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 508 | IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n", |
| 509 | len); |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 510 | |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 511 | if (len == sizeof(struct iwl_bt_notif_statistics)) { |
| 512 | struct iwl_bt_notif_statistics *stats; |
| 513 | stats = &pkt->u.stats_bt; |
| 514 | flag = &stats->flag; |
| 515 | common = &stats->general.common; |
| 516 | rx_non_phy = &stats->rx.general.common; |
| 517 | rx_ofdm = &stats->rx.ofdm; |
| 518 | rx_ofdm_ht = &stats->rx.ofdm_ht; |
| 519 | rx_cck = &stats->rx.cck; |
| 520 | tx = &stats->tx; |
| 521 | bt_activity = &stats->general.activity; |
| 522 | |
| 523 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 524 | /* handle this exception directly */ |
| 525 | priv->statistics.num_bt_kills = stats->rx.general.num_bt_kills; |
| 526 | le32_add_cpu(&priv->statistics.accum_num_bt_kills, |
| 527 | le32_to_cpu(stats->rx.general.num_bt_kills)); |
| 528 | #endif |
| 529 | } else if (len == sizeof(struct iwl_notif_statistics)) { |
| 530 | struct iwl_notif_statistics *stats; |
| 531 | stats = &pkt->u.stats; |
| 532 | flag = &stats->flag; |
| 533 | common = &stats->general.common; |
| 534 | rx_non_phy = &stats->rx.general; |
| 535 | rx_ofdm = &stats->rx.ofdm; |
| 536 | rx_ofdm_ht = &stats->rx.ofdm_ht; |
| 537 | rx_cck = &stats->rx.cck; |
| 538 | tx = &stats->tx; |
| 539 | bt_activity = NULL; |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 540 | } else { |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 541 | WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n", |
| 542 | len, sizeof(struct iwl_bt_notif_statistics), |
| 543 | sizeof(struct iwl_notif_statistics)); |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 544 | return 0; |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 545 | } |
| 546 | |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 547 | change = common->temperature != priv->statistics.common.temperature || |
| 548 | (*flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK) != |
| 549 | (priv->statistics.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK); |
| 550 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 551 | iwlagn_accumulative_statistics(priv, common, rx_non_phy, rx_ofdm, |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 552 | rx_ofdm_ht, rx_cck, tx, bt_activity); |
| 553 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 554 | iwlagn_recover_from_statistics(priv, rx_ofdm, rx_ofdm_ht, tx, stamp); |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 555 | |
| 556 | priv->statistics.flag = *flag; |
| 557 | memcpy(&priv->statistics.common, common, sizeof(*common)); |
| 558 | memcpy(&priv->statistics.rx_non_phy, rx_non_phy, sizeof(*rx_non_phy)); |
| 559 | memcpy(&priv->statistics.rx_ofdm, rx_ofdm, sizeof(*rx_ofdm)); |
| 560 | memcpy(&priv->statistics.rx_ofdm_ht, rx_ofdm_ht, sizeof(*rx_ofdm_ht)); |
| 561 | memcpy(&priv->statistics.rx_cck, rx_cck, sizeof(*rx_cck)); |
| 562 | memcpy(&priv->statistics.tx, tx, sizeof(*tx)); |
| 563 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 564 | if (bt_activity) |
| 565 | memcpy(&priv->statistics.bt_activity, bt_activity, |
| 566 | sizeof(*bt_activity)); |
| 567 | #endif |
| 568 | |
| 569 | priv->rx_statistics_jiffies = stamp; |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 570 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 571 | set_bit(STATUS_STATISTICS, &priv->shrd->status); |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 572 | |
| 573 | /* Reschedule the statistics timer to occur in |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 574 | * reg_recalib_period seconds to ensure we get a |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 575 | * thermal update even if the uCode doesn't give |
| 576 | * us one */ |
| 577 | mod_timer(&priv->statistics_periodic, jiffies + |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 578 | msecs_to_jiffies(reg_recalib_period * 1000)); |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 579 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 580 | if (unlikely(!test_bit(STATUS_SCANNING, &priv->shrd->status)) && |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 581 | (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) { |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 582 | iwlagn_rx_calc_noise(priv); |
Emmanuel Grumbach | 74e28e4 | 2011-08-25 23:10:41 -0700 | [diff] [blame] | 583 | queue_work(priv->shrd->workqueue, &priv->run_time_calib_work); |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 584 | } |
Wey-Yi Guy | 90c300c | 2011-07-07 08:33:01 -0700 | [diff] [blame] | 585 | if (priv->cfg->lib->temperature && change) |
| 586 | priv->cfg->lib->temperature(priv); |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 587 | return 0; |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 588 | } |
| 589 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 590 | static int iwlagn_rx_reply_statistics(struct iwl_priv *priv, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 591 | struct iwl_rx_mem_buffer *rxb, |
| 592 | struct iwl_device_cmd *cmd) |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 593 | { |
| 594 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 595 | |
| 596 | if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) { |
| 597 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 598 | memset(&priv->accum_stats, 0, |
| 599 | sizeof(priv->accum_stats)); |
| 600 | memset(&priv->delta_stats, 0, |
| 601 | sizeof(priv->delta_stats)); |
| 602 | memset(&priv->max_delta_stats, 0, |
| 603 | sizeof(priv->max_delta_stats)); |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 604 | #endif |
| 605 | IWL_DEBUG_RX(priv, "Statistics have been cleared\n"); |
| 606 | } |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 607 | iwlagn_rx_statistics(priv, rxb, cmd); |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 608 | return 0; |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 609 | } |
| 610 | |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 611 | /* Handle notification from uCode that card's power state is changing |
| 612 | * due to software, hardware, or critical temperature RFKILL */ |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 613 | static int iwlagn_rx_card_state_notif(struct iwl_priv *priv, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 614 | struct iwl_rx_mem_buffer *rxb, |
| 615 | struct iwl_device_cmd *cmd) |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 616 | { |
| 617 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 618 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 619 | unsigned long status = priv->shrd->status; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 620 | |
| 621 | IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n", |
| 622 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 623 | (flags & SW_CARD_DISABLED) ? "Kill" : "On", |
| 624 | (flags & CT_CARD_DISABLED) ? |
| 625 | "Reached" : "Not reached"); |
| 626 | |
| 627 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 628 | CT_CARD_DISABLED)) { |
| 629 | |
Emmanuel Grumbach | 83ed901 | 2011-08-25 23:11:14 -0700 | [diff] [blame] | 630 | iwl_write32(bus(priv), CSR_UCODE_DRV_GP1_SET, |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 631 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 632 | |
Emmanuel Grumbach | 83ed901 | 2011-08-25 23:11:14 -0700 | [diff] [blame] | 633 | iwl_write_direct32(bus(priv), HBUS_TARG_MBX_C, |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 634 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 635 | |
| 636 | if (!(flags & RXON_CARD_DISABLED)) { |
Emmanuel Grumbach | 83ed901 | 2011-08-25 23:11:14 -0700 | [diff] [blame] | 637 | iwl_write32(bus(priv), CSR_UCODE_DRV_GP1_CLR, |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 638 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Emmanuel Grumbach | 83ed901 | 2011-08-25 23:11:14 -0700 | [diff] [blame] | 639 | iwl_write_direct32(bus(priv), HBUS_TARG_MBX_C, |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 640 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 641 | } |
| 642 | if (flags & CT_CARD_DISABLED) |
| 643 | iwl_tt_enter_ct_kill(priv); |
| 644 | } |
| 645 | if (!(flags & CT_CARD_DISABLED)) |
| 646 | iwl_tt_exit_ct_kill(priv); |
| 647 | |
| 648 | if (flags & HW_CARD_DISABLED) |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 649 | set_bit(STATUS_RF_KILL_HW, &priv->shrd->status); |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 650 | else |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 651 | clear_bit(STATUS_RF_KILL_HW, &priv->shrd->status); |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 652 | |
| 653 | |
| 654 | if (!(flags & RXON_CARD_DISABLED)) |
| 655 | iwl_scan_cancel(priv); |
| 656 | |
| 657 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 658 | test_bit(STATUS_RF_KILL_HW, &priv->shrd->status))) |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 659 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 660 | test_bit(STATUS_RF_KILL_HW, &priv->shrd->status)); |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 661 | else |
Johannes Berg | effd4d9 | 2011-09-15 11:46:52 -0700 | [diff] [blame] | 662 | wake_up(&priv->shrd->wait_command_queue); |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 663 | return 0; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 664 | } |
| 665 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 666 | static int iwlagn_rx_missed_beacon_notif(struct iwl_priv *priv, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 667 | struct iwl_rx_mem_buffer *rxb, |
| 668 | struct iwl_device_cmd *cmd) |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 669 | |
| 670 | { |
| 671 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 672 | struct iwl_missed_beacon_notif *missed_beacon; |
| 673 | |
| 674 | missed_beacon = &pkt->u.missed_beacon; |
| 675 | if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) > |
| 676 | priv->missed_beacon_threshold) { |
| 677 | IWL_DEBUG_CALIB(priv, |
| 678 | "missed bcn cnsq %d totl %d rcd %d expctd %d\n", |
| 679 | le32_to_cpu(missed_beacon->consecutive_missed_beacons), |
| 680 | le32_to_cpu(missed_beacon->total_missed_becons), |
| 681 | le32_to_cpu(missed_beacon->num_recvd_beacons), |
| 682 | le32_to_cpu(missed_beacon->num_expected_beacons)); |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 683 | if (!test_bit(STATUS_SCANNING, &priv->shrd->status)) |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 684 | iwl_init_sensitivity(priv); |
| 685 | } |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 686 | return 0; |
Stanislaw Gruszka | 6728994 | 2011-02-28 14:33:17 +0100 | [diff] [blame] | 687 | } |
| 688 | |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 689 | /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD). |
| 690 | * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */ |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 691 | static int iwlagn_rx_reply_rx_phy(struct iwl_priv *priv, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 692 | struct iwl_rx_mem_buffer *rxb, |
| 693 | struct iwl_device_cmd *cmd) |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 694 | { |
| 695 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 696 | |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 697 | priv->last_phy_res_valid = true; |
| 698 | memcpy(&priv->last_phy_res, pkt->u.raw, |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 699 | sizeof(struct iwl_rx_phy_res)); |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 700 | return 0; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 701 | } |
| 702 | |
Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 703 | /* |
| 704 | * returns non-zero if packet should be dropped |
| 705 | */ |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 706 | static int iwlagn_set_decrypted_flag(struct iwl_priv *priv, |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 707 | struct ieee80211_hdr *hdr, |
| 708 | u32 decrypt_res, |
| 709 | struct ieee80211_rx_status *stats) |
Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 710 | { |
| 711 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 712 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 713 | /* |
| 714 | * All contexts have the same setting here due to it being |
| 715 | * a module parameter, so OK to check any context. |
| 716 | */ |
| 717 | if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags & |
| 718 | RXON_FILTER_DIS_DECRYPT_MSK) |
Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 719 | return 0; |
| 720 | |
| 721 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 722 | return 0; |
| 723 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 724 | IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res); |
Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 725 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 726 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 727 | /* The uCode has got a bad phase 1 Key, pushes the packet. |
| 728 | * Decryption will be done in SW. */ |
| 729 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 730 | RX_RES_STATUS_BAD_KEY_TTAK) |
| 731 | break; |
| 732 | |
| 733 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 734 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 735 | RX_RES_STATUS_BAD_ICV_MIC) { |
| 736 | /* bad ICV, the packet is destroyed since the |
| 737 | * decryption is inplace, drop it */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 738 | IWL_DEBUG_RX(priv, "Packet destroyed\n"); |
Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 739 | return -1; |
| 740 | } |
| 741 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 742 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 743 | RX_RES_STATUS_DECRYPT_OK) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 744 | IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n"); |
Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 745 | stats->flag |= RX_FLAG_DECRYPTED; |
| 746 | } |
| 747 | break; |
| 748 | |
| 749 | default: |
| 750 | break; |
| 751 | } |
| 752 | return 0; |
| 753 | } |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 754 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 755 | static void iwlagn_pass_packet_to_mac80211(struct iwl_priv *priv, |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 756 | struct ieee80211_hdr *hdr, |
| 757 | u16 len, |
| 758 | u32 ampdu_status, |
| 759 | struct iwl_rx_mem_buffer *rxb, |
| 760 | struct ieee80211_rx_status *stats) |
| 761 | { |
| 762 | struct sk_buff *skb; |
| 763 | __le16 fc = hdr->frame_control; |
Garen Tamrazian | 68b9931 | 2011-03-30 02:29:32 -0700 | [diff] [blame] | 764 | struct iwl_rxon_context *ctx; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 765 | |
| 766 | /* We only process data packets if the interface is open */ |
| 767 | if (unlikely(!priv->is_open)) { |
| 768 | IWL_DEBUG_DROP_LIMIT(priv, |
| 769 | "Dropping packet while interface is not open.\n"); |
| 770 | return; |
| 771 | } |
| 772 | |
| 773 | /* In case of HW accelerated crypto and bad decryption, drop */ |
Don Fry | 9d143e9 | 2011-04-20 15:23:57 -0700 | [diff] [blame] | 774 | if (!iwlagn_mod_params.sw_crypto && |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 775 | iwlagn_set_decrypted_flag(priv, hdr, ampdu_status, stats)) |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 776 | return; |
| 777 | |
| 778 | skb = dev_alloc_skb(128); |
| 779 | if (!skb) { |
| 780 | IWL_ERR(priv, "dev_alloc_skb failed\n"); |
| 781 | return; |
| 782 | } |
| 783 | |
| 784 | skb_add_rx_frag(skb, 0, rxb->page, (void *)hdr - rxb_addr(rxb), len); |
| 785 | |
| 786 | iwl_update_stats(priv, false, fc, len); |
Garen Tamrazian | 68b9931 | 2011-03-30 02:29:32 -0700 | [diff] [blame] | 787 | |
| 788 | /* |
| 789 | * Wake any queues that were stopped due to a passive channel tx |
| 790 | * failure. This can happen because the regulatory enforcement in |
| 791 | * the device waits for a beacon before allowing transmission, |
| 792 | * sometimes even after already having transmitted frames for the |
| 793 | * association because the new RXON may reset the information. |
| 794 | */ |
| 795 | if (unlikely(ieee80211_is_beacon(fc))) { |
| 796 | for_each_context(priv, ctx) { |
| 797 | if (!ctx->last_tx_rejected) |
| 798 | continue; |
| 799 | if (compare_ether_addr(hdr->addr3, |
| 800 | ctx->active.bssid_addr)) |
| 801 | continue; |
| 802 | ctx->last_tx_rejected = false; |
Emmanuel Grumbach | e13c0c5 | 2011-08-25 23:11:24 -0700 | [diff] [blame] | 803 | iwl_trans_wake_any_queue(trans(priv), ctx->ctxid); |
Garen Tamrazian | 68b9931 | 2011-03-30 02:29:32 -0700 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 807 | memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats)); |
| 808 | |
| 809 | ieee80211_rx(priv->hw, skb); |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 810 | rxb->page = NULL; |
| 811 | } |
| 812 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 813 | static u32 iwlagn_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in) |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 814 | { |
| 815 | u32 decrypt_out = 0; |
| 816 | |
| 817 | if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) == |
| 818 | RX_RES_STATUS_STATION_FOUND) |
| 819 | decrypt_out |= (RX_RES_STATUS_STATION_FOUND | |
| 820 | RX_RES_STATUS_NO_STATION_INFO_MISMATCH); |
| 821 | |
| 822 | decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK); |
| 823 | |
| 824 | /* packet was not encrypted */ |
| 825 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == |
| 826 | RX_RES_STATUS_SEC_TYPE_NONE) |
| 827 | return decrypt_out; |
| 828 | |
| 829 | /* packet was encrypted with unknown alg */ |
| 830 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == |
| 831 | RX_RES_STATUS_SEC_TYPE_ERR) |
| 832 | return decrypt_out; |
| 833 | |
| 834 | /* decryption was not done in HW */ |
| 835 | if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) != |
| 836 | RX_MPDU_RES_STATUS_DEC_DONE_MSK) |
| 837 | return decrypt_out; |
| 838 | |
| 839 | switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 840 | |
| 841 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 842 | /* alg is CCM: check MIC only */ |
| 843 | if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK)) |
| 844 | /* Bad MIC */ |
| 845 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; |
| 846 | else |
| 847 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; |
| 848 | |
| 849 | break; |
| 850 | |
| 851 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 852 | if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) { |
| 853 | /* Bad TTAK */ |
| 854 | decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK; |
| 855 | break; |
| 856 | } |
| 857 | /* fall through if TTAK OK */ |
| 858 | default: |
| 859 | if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK)) |
| 860 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; |
| 861 | else |
| 862 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; |
| 863 | break; |
| 864 | } |
| 865 | |
| 866 | IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n", |
| 867 | decrypt_in, decrypt_out); |
| 868 | |
| 869 | return decrypt_out; |
| 870 | } |
| 871 | |
Don Fry | 5c3d29f | 2011-07-08 08:46:29 -0700 | [diff] [blame] | 872 | /* Calc max signal level (dBm) among 3 possible receivers */ |
| 873 | static int iwlagn_calc_rssi(struct iwl_priv *priv, |
| 874 | struct iwl_rx_phy_res *rx_resp) |
| 875 | { |
| 876 | /* data from PHY/DSP regarding signal strength, etc., |
| 877 | * contents are always there, not configurable by host |
| 878 | */ |
| 879 | struct iwlagn_non_cfg_phy *ncphy = |
| 880 | (struct iwlagn_non_cfg_phy *)rx_resp->non_cfg_phy_buf; |
| 881 | u32 val, rssi_a, rssi_b, rssi_c, max_rssi; |
| 882 | u8 agc; |
| 883 | |
| 884 | val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_AGC_IDX]); |
| 885 | agc = (val & IWLAGN_OFDM_AGC_MSK) >> IWLAGN_OFDM_AGC_BIT_POS; |
| 886 | |
| 887 | /* Find max rssi among 3 possible receivers. |
| 888 | * These values are measured by the digital signal processor (DSP). |
| 889 | * They should stay fairly constant even as the signal strength varies, |
| 890 | * if the radio's automatic gain control (AGC) is working right. |
| 891 | * AGC value (see below) will provide the "interesting" info. |
| 892 | */ |
| 893 | val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_AB_IDX]); |
| 894 | rssi_a = (val & IWLAGN_OFDM_RSSI_INBAND_A_BITMSK) >> |
| 895 | IWLAGN_OFDM_RSSI_A_BIT_POS; |
| 896 | rssi_b = (val & IWLAGN_OFDM_RSSI_INBAND_B_BITMSK) >> |
| 897 | IWLAGN_OFDM_RSSI_B_BIT_POS; |
| 898 | val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_C_IDX]); |
| 899 | rssi_c = (val & IWLAGN_OFDM_RSSI_INBAND_C_BITMSK) >> |
| 900 | IWLAGN_OFDM_RSSI_C_BIT_POS; |
| 901 | |
| 902 | max_rssi = max_t(u32, rssi_a, rssi_b); |
| 903 | max_rssi = max_t(u32, max_rssi, rssi_c); |
| 904 | |
| 905 | IWL_DEBUG_STATS(priv, "Rssi In A %d B %d C %d Max %d AGC dB %d\n", |
| 906 | rssi_a, rssi_b, rssi_c, max_rssi, agc); |
| 907 | |
| 908 | /* dBm = max_rssi dB - agc dB - constant. |
| 909 | * Higher AGC (higher radio gain) means lower signal. */ |
| 910 | return max_rssi - agc - IWLAGN_RSSI_OFFSET; |
| 911 | } |
| 912 | |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 913 | /* Called for REPLY_RX (legacy ABG frames), or |
| 914 | * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */ |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 915 | static int iwlagn_rx_reply_rx(struct iwl_priv *priv, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 916 | struct iwl_rx_mem_buffer *rxb, |
| 917 | struct iwl_device_cmd *cmd) |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 918 | { |
| 919 | struct ieee80211_hdr *header; |
| 920 | struct ieee80211_rx_status rx_status; |
| 921 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 922 | struct iwl_rx_phy_res *phy_res; |
| 923 | __le32 rx_pkt_status; |
| 924 | struct iwl_rx_mpdu_res_start *amsdu; |
| 925 | u32 len; |
| 926 | u32 ampdu_status; |
| 927 | u32 rate_n_flags; |
| 928 | |
| 929 | /** |
| 930 | * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently. |
| 931 | * REPLY_RX: physical layer info is in this buffer |
| 932 | * REPLY_RX_MPDU_CMD: physical layer info was sent in separate |
| 933 | * command and cached in priv->last_phy_res |
| 934 | * |
| 935 | * Here we set up local variables depending on which command is |
| 936 | * received. |
| 937 | */ |
| 938 | if (pkt->hdr.cmd == REPLY_RX) { |
| 939 | phy_res = (struct iwl_rx_phy_res *)pkt->u.raw; |
| 940 | header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res) |
| 941 | + phy_res->cfg_phy_cnt); |
| 942 | |
| 943 | len = le16_to_cpu(phy_res->byte_count); |
| 944 | rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*phy_res) + |
| 945 | phy_res->cfg_phy_cnt + len); |
| 946 | ampdu_status = le32_to_cpu(rx_pkt_status); |
| 947 | } else { |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 948 | if (!priv->last_phy_res_valid) { |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 949 | IWL_ERR(priv, "MPDU frame without cached PHY data\n"); |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 950 | return 0; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 951 | } |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 952 | phy_res = &priv->last_phy_res; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 953 | amsdu = (struct iwl_rx_mpdu_res_start *)pkt->u.raw; |
| 954 | header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu)); |
| 955 | len = le16_to_cpu(amsdu->byte_count); |
| 956 | rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*amsdu) + len); |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 957 | ampdu_status = iwlagn_translate_rx_status(priv, |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 958 | le32_to_cpu(rx_pkt_status)); |
| 959 | } |
| 960 | |
| 961 | if ((unlikely(phy_res->cfg_phy_cnt > 20))) { |
| 962 | IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d/n", |
| 963 | phy_res->cfg_phy_cnt); |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 964 | return 0; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) || |
| 968 | !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) { |
| 969 | IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n", |
| 970 | le32_to_cpu(rx_pkt_status)); |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 971 | return 0; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | /* This will be used in several places later */ |
| 975 | rate_n_flags = le32_to_cpu(phy_res->rate_n_flags); |
| 976 | |
| 977 | /* rx_status carries information about the packet to mac80211 */ |
| 978 | rx_status.mactime = le64_to_cpu(phy_res->timestamp); |
| 979 | rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? |
| 980 | IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ; |
| 981 | rx_status.freq = |
| 982 | ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel), |
| 983 | rx_status.band); |
| 984 | rx_status.rate_idx = |
| 985 | iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band); |
| 986 | rx_status.flag = 0; |
| 987 | |
| 988 | /* TSF isn't reliable. In order to allow smooth user experience, |
| 989 | * this W/A doesn't propagate it to the mac80211 */ |
| 990 | /*rx_status.flag |= RX_FLAG_MACTIME_MPDU;*/ |
| 991 | |
| 992 | priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp); |
| 993 | |
| 994 | /* Find max signal strength (dBm) among 3 antenna/receiver chains */ |
Don Fry | 5c3d29f | 2011-07-08 08:46:29 -0700 | [diff] [blame] | 995 | rx_status.signal = iwlagn_calc_rssi(priv, phy_res); |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 996 | |
| 997 | iwl_dbg_log_rx_data_frame(priv, len, header); |
| 998 | IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n", |
| 999 | rx_status.signal, (unsigned long long)rx_status.mactime); |
| 1000 | |
| 1001 | /* |
| 1002 | * "antenna number" |
| 1003 | * |
| 1004 | * It seems that the antenna field in the phy flags value |
| 1005 | * is actually a bit field. This is undefined by radiotap, |
| 1006 | * it wants an actual antenna number but I always get "7" |
| 1007 | * for most legacy frames I receive indicating that the |
| 1008 | * same frame was received on all three RX chains. |
| 1009 | * |
| 1010 | * I think this field should be removed in favor of a |
| 1011 | * new 802.11n radiotap field "RX chains" that is defined |
| 1012 | * as a bitmask. |
| 1013 | */ |
| 1014 | rx_status.antenna = |
| 1015 | (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK) |
| 1016 | >> RX_RES_PHY_FLAGS_ANTENNA_POS; |
| 1017 | |
| 1018 | /* set the preamble flag if appropriate */ |
| 1019 | if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) |
| 1020 | rx_status.flag |= RX_FLAG_SHORTPRE; |
| 1021 | |
| 1022 | /* Set up the HT phy flags */ |
| 1023 | if (rate_n_flags & RATE_MCS_HT_MSK) |
| 1024 | rx_status.flag |= RX_FLAG_HT; |
| 1025 | if (rate_n_flags & RATE_MCS_HT40_MSK) |
| 1026 | rx_status.flag |= RX_FLAG_40MHZ; |
| 1027 | if (rate_n_flags & RATE_MCS_SGI_MSK) |
| 1028 | rx_status.flag |= RX_FLAG_SHORT_GI; |
| 1029 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 1030 | iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status, |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 1031 | rxb, &rx_status); |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 1032 | return 0; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | /** |
| 1036 | * iwl_setup_rx_handlers - Initialize Rx handler callbacks |
| 1037 | * |
| 1038 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 1039 | * to the host. |
| 1040 | */ |
| 1041 | void iwl_setup_rx_handlers(struct iwl_priv *priv) |
| 1042 | { |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 1043 | int (**handlers)(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb, |
| 1044 | struct iwl_device_cmd *cmd); |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 1045 | |
| 1046 | handlers = priv->rx_handlers; |
| 1047 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 1048 | handlers[REPLY_ERROR] = iwlagn_rx_reply_error; |
| 1049 | handlers[CHANNEL_SWITCH_NOTIFICATION] = iwlagn_rx_csa; |
| 1050 | handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
| 1051 | iwlagn_rx_spectrum_measure_notif; |
| 1052 | handlers[PM_SLEEP_NOTIFICATION] = iwlagn_rx_pm_sleep_notif; |
| 1053 | handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
| 1054 | iwlagn_rx_pm_debug_statistics_notif; |
| 1055 | handlers[BEACON_NOTIFICATION] = iwlagn_rx_beacon_notif; |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 1056 | handlers[REPLY_ADD_STA] = iwl_add_sta_callback; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 1057 | |
| 1058 | /* |
| 1059 | * The same handler is used for both the REPLY to a discrete |
| 1060 | * statistics request from the host as well as for the periodic |
| 1061 | * statistics notifications (after received beacons) from the uCode. |
| 1062 | */ |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 1063 | handlers[REPLY_STATISTICS_CMD] = iwlagn_rx_reply_statistics; |
| 1064 | handlers[STATISTICS_NOTIFICATION] = iwlagn_rx_statistics; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 1065 | |
| 1066 | iwl_setup_rx_scan_handlers(priv); |
| 1067 | |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 1068 | handlers[CARD_STATE_NOTIFICATION] = iwlagn_rx_card_state_notif; |
| 1069 | handlers[MISSED_BEACONS_NOTIFICATION] = |
| 1070 | iwlagn_rx_missed_beacon_notif; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 1071 | |
| 1072 | /* Rx handlers */ |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 1073 | handlers[REPLY_RX_PHY_CMD] = iwlagn_rx_reply_rx_phy; |
| 1074 | handlers[REPLY_RX_MPDU_CMD] = iwlagn_rx_reply_rx; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 1075 | |
| 1076 | /* block ack */ |
Wey-Yi Guy | 3246c4e | 2011-10-10 07:27:13 -0700 | [diff] [blame] | 1077 | handlers[REPLY_COMPRESSED_BA] = |
| 1078 | iwlagn_rx_reply_compressed_ba; |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 1079 | |
Emmanuel Grumbach | 8d30119 | 2011-07-03 15:45:34 +0300 | [diff] [blame] | 1080 | /* init calibration handlers */ |
| 1081 | priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] = |
| 1082 | iwlagn_rx_calib_result; |
| 1083 | priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx; |
| 1084 | |
| 1085 | /* set up notification wait support */ |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 1086 | spin_lock_init(&priv->notif_wait_lock); |
| 1087 | INIT_LIST_HEAD(&priv->notif_waits); |
| 1088 | init_waitqueue_head(&priv->notif_waitq); |
Emmanuel Grumbach | 8d30119 | 2011-07-03 15:45:34 +0300 | [diff] [blame] | 1089 | |
| 1090 | /* Set up BT Rx handlers */ |
| 1091 | if (priv->cfg->lib->bt_rx_handler_setup) |
| 1092 | priv->cfg->lib->bt_rx_handler_setup(priv); |
| 1093 | |
Stanislaw Gruszka | 466a19a | 2011-03-04 17:51:49 +0100 | [diff] [blame] | 1094 | } |
Emmanuel Grumbach | 1ab9f6c | 2011-07-07 07:59:02 -0700 | [diff] [blame] | 1095 | |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 1096 | int iwl_rx_dispatch(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb, |
| 1097 | struct iwl_device_cmd *cmd) |
Emmanuel Grumbach | 1ab9f6c | 2011-07-07 07:59:02 -0700 | [diff] [blame] | 1098 | { |
| 1099 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 1100 | int err = 0; |
Emmanuel Grumbach | 1ab9f6c | 2011-07-07 07:59:02 -0700 | [diff] [blame] | 1101 | |
| 1102 | /* |
| 1103 | * Do the notification wait before RX handlers so |
| 1104 | * even if the RX handler consumes the RXB we have |
| 1105 | * access to it in the notification wait entry. |
| 1106 | */ |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 1107 | if (!list_empty(&priv->notif_waits)) { |
Emmanuel Grumbach | 1ab9f6c | 2011-07-07 07:59:02 -0700 | [diff] [blame] | 1108 | struct iwl_notification_wait *w; |
| 1109 | |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 1110 | spin_lock(&priv->notif_wait_lock); |
| 1111 | list_for_each_entry(w, &priv->notif_waits, list) { |
Emmanuel Grumbach | 1ab9f6c | 2011-07-07 07:59:02 -0700 | [diff] [blame] | 1112 | if (w->cmd != pkt->hdr.cmd) |
| 1113 | continue; |
| 1114 | IWL_DEBUG_RX(priv, |
| 1115 | "Notif: %s, 0x%02x - wake the callers up\n", |
| 1116 | get_cmd_string(pkt->hdr.cmd), |
| 1117 | pkt->hdr.cmd); |
| 1118 | w->triggered = true; |
| 1119 | if (w->fn) |
| 1120 | w->fn(priv, pkt, w->fn_data); |
| 1121 | } |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 1122 | spin_unlock(&priv->notif_wait_lock); |
Emmanuel Grumbach | 1ab9f6c | 2011-07-07 07:59:02 -0700 | [diff] [blame] | 1123 | |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 1124 | wake_up_all(&priv->notif_waitq); |
Emmanuel Grumbach | 1ab9f6c | 2011-07-07 07:59:02 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | if (priv->pre_rx_handler) |
| 1128 | priv->pre_rx_handler(priv, rxb); |
| 1129 | |
| 1130 | /* Based on type of command response or notification, |
| 1131 | * handle those that need handling via function in |
| 1132 | * rx_handlers table. See iwl_setup_rx_handlers() */ |
| 1133 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Emmanuel Grumbach | 1f7b617 | 2011-08-25 23:10:59 -0700 | [diff] [blame] | 1134 | priv->rx_handlers_stats[pkt->hdr.cmd]++; |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 1135 | err = priv->rx_handlers[pkt->hdr.cmd] (priv, rxb, cmd); |
Emmanuel Grumbach | 1ab9f6c | 2011-07-07 07:59:02 -0700 | [diff] [blame] | 1136 | } else { |
| 1137 | /* No handling needed */ |
| 1138 | IWL_DEBUG_RX(priv, |
| 1139 | "No handler needed for %s, 0x%02x\n", |
| 1140 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 1141 | } |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 1142 | return err; |
Emmanuel Grumbach | 1ab9f6c | 2011-07-07 07:59:02 -0700 | [diff] [blame] | 1143 | } |