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