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