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