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