Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 4 | * redistributing this file, you may do so under either license. |
| 5 | * |
| 6 | * GPL LICENSE SUMMARY |
| 7 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 8 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 777c9b6 | 2015-01-14 17:58:57 +0100 | [diff] [blame] | 9 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Goodstein, Mordechay | cfbeb598 | 2016-11-21 10:26:36 +0200 | [diff] [blame] | 10 | * Copyright(c) 2016 - 2017 Intel Deutschland GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of version 2 of the GNU General Public License as |
| 14 | * published by the Free Software Foundation. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * General Public License for more details. |
| 20 | * |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 21 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 22 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 23 | * |
| 24 | * Contact Information: |
Emmanuel Grumbach | cb2f827 | 2015-11-17 15:39:56 +0200 | [diff] [blame] | 25 | * Intel Linux Wireless <linuxwifi@intel.com> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | * BSD LICENSE |
| 29 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 30 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 777c9b6 | 2015-01-14 17:58:57 +0100 | [diff] [blame] | 31 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 32 | * All rights reserved. |
| 33 | * |
| 34 | * Redistribution and use in source and binary forms, with or without |
| 35 | * modification, are permitted provided that the following conditions |
| 36 | * are met: |
| 37 | * |
| 38 | * * Redistributions of source code must retain the above copyright |
| 39 | * notice, this list of conditions and the following disclaimer. |
| 40 | * * Redistributions in binary form must reproduce the above copyright |
| 41 | * notice, this list of conditions and the following disclaimer in |
| 42 | * the documentation and/or other materials provided with the |
| 43 | * distribution. |
| 44 | * * Neither the name Intel Corporation nor the names of its |
| 45 | * contributors may be used to endorse or promote products derived |
| 46 | * from this software without specific prior written permission. |
| 47 | * |
| 48 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 49 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 50 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 51 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 52 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 53 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 54 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 55 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 56 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 57 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 58 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 59 | *****************************************************************************/ |
Johannes Berg | a399f98 | 2015-09-24 18:29:00 +0200 | [diff] [blame] | 60 | #include <linux/etherdevice.h> |
Avri Altman | 93190fb | 2014-12-27 09:09:47 +0200 | [diff] [blame] | 61 | #include <linux/skbuff.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 62 | #include "iwl-trans.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 63 | #include "mvm.h" |
| 64 | #include "fw-api.h" |
| 65 | |
| 66 | /* |
| 67 | * iwl_mvm_rx_rx_phy_cmd - REPLY_RX_PHY_CMD handler |
| 68 | * |
| 69 | * Copies the phy information in mvm->last_phy_info, it will be used when the |
| 70 | * actual data will come from the fw in the next packet. |
| 71 | */ |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 72 | void iwl_mvm_rx_rx_phy_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 73 | { |
| 74 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 75 | |
| 76 | memcpy(&mvm->last_phy_info, pkt->data, sizeof(mvm->last_phy_info)); |
| 77 | mvm->ampdu_ref++; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 78 | |
| 79 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 80 | if (mvm->last_phy_info.phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_AGG)) { |
| 81 | spin_lock(&mvm->drv_stats_lock); |
| 82 | mvm->drv_rx_stats.ampdu_count++; |
| 83 | spin_unlock(&mvm->drv_stats_lock); |
| 84 | } |
| 85 | #endif |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /* |
| 89 | * iwl_mvm_pass_packet_to_mac80211 - builds the packet for mac80211 |
| 90 | * |
| 91 | * Adds the rxb to a new skb and give it to mac80211 |
| 92 | */ |
| 93 | static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm *mvm, |
Johannes Berg | 43ec72b | 2016-03-10 11:55:44 +0100 | [diff] [blame] | 94 | struct ieee80211_sta *sta, |
Johannes Berg | 1be5d8c | 2015-06-11 16:51:24 +0200 | [diff] [blame] | 95 | struct napi_struct *napi, |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 96 | struct sk_buff *skb, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 97 | struct ieee80211_hdr *hdr, u16 len, |
Dan Carpenter | bdbc58a | 2016-05-04 09:19:13 +0300 | [diff] [blame] | 98 | u8 crypt_len, |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 99 | struct iwl_rx_cmd_buffer *rxb) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 100 | { |
Johannes Berg | 5cddd05 | 2016-12-14 13:48:04 +0100 | [diff] [blame] | 101 | unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control); |
| 102 | unsigned int fraglen; |
| 103 | |
| 104 | /* |
| 105 | * The 'hdrlen' (plus the 8 bytes for the SNAP and the crypt_len, |
| 106 | * but those are all multiples of 4 long) all goes away, but we |
| 107 | * want the *end* of it, which is going to be the start of the IP |
| 108 | * header, to be aligned when it gets pulled in. |
| 109 | * The beginning of the skb->data is aligned on at least a 4-byte |
| 110 | * boundary after allocation. Everything here is aligned at least |
| 111 | * on a 2-byte boundary so we can just take hdrlen & 3 and pad by |
| 112 | * the result. |
| 113 | */ |
| 114 | skb_reserve(skb, hdrlen & 3); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 115 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 116 | /* If frame is small enough to fit in skb->head, pull it completely. |
Johannes Berg | 3771a89 | 2014-11-13 11:06:43 +0100 | [diff] [blame] | 117 | * If not, only pull ieee80211_hdr (including crypto if present, and |
| 118 | * an additional 8 bytes for SNAP/ethertype, see below) so that |
| 119 | * splice() or TCP coalesce are more efficient. |
| 120 | * |
| 121 | * Since, in addition, ieee80211_data_to_8023() always pull in at |
| 122 | * least 8 bytes (possibly more for mesh) we can do the same here |
| 123 | * to save the cost of doing it later. That still doesn't pull in |
| 124 | * the actual IP header since the typical case has a SNAP header. |
| 125 | * If the latter changes (there are efforts in the standards group |
| 126 | * to do so) we should revisit this and ieee80211_data_to_8023(). |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 127 | */ |
Johannes Berg | 5cddd05 | 2016-12-14 13:48:04 +0100 | [diff] [blame] | 128 | hdrlen = (len <= skb_tailroom(skb)) ? len : hdrlen + crypt_len + 8; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 129 | |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 130 | skb_put_data(skb, hdr, hdrlen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 131 | fraglen = len - hdrlen; |
| 132 | |
| 133 | if (fraglen) { |
| 134 | int offset = (void *)hdr + hdrlen - |
| 135 | rxb_addr(rxb) + rxb_offset(rxb); |
| 136 | |
| 137 | skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset, |
| 138 | fraglen, rxb->truesize); |
| 139 | } |
| 140 | |
Johannes Berg | 43ec72b | 2016-03-10 11:55:44 +0100 | [diff] [blame] | 141 | ieee80211_rx_napi(mvm->hw, sta, skb, napi); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 142 | } |
| 143 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 144 | /* |
Avri Altman | a2d7b87 | 2013-07-09 01:42:17 +0300 | [diff] [blame] | 145 | * iwl_mvm_get_signal_strength - use new rx PHY INFO API |
Avri Altman | 17dbe56 | 2013-08-01 07:19:27 +0300 | [diff] [blame] | 146 | * values are reported by the fw as positive values - need to negate |
| 147 | * to obtain their dBM. Account for missing antennas by replacing 0 |
| 148 | * values by -256dBm: practically 0 power and a non-feasible 8 bit value. |
Avri Altman | a2d7b87 | 2013-07-09 01:42:17 +0300 | [diff] [blame] | 149 | */ |
Johannes Berg | 226eb8c | 2013-07-03 11:55:17 +0200 | [diff] [blame] | 150 | static void iwl_mvm_get_signal_strength(struct iwl_mvm *mvm, |
| 151 | struct iwl_rx_phy_info *phy_info, |
| 152 | struct ieee80211_rx_status *rx_status) |
Avri Altman | a2d7b87 | 2013-07-09 01:42:17 +0300 | [diff] [blame] | 153 | { |
| 154 | int energy_a, energy_b, energy_c, max_energy; |
| 155 | u32 val; |
| 156 | |
| 157 | val = |
| 158 | le32_to_cpu(phy_info->non_cfg_phy[IWL_RX_INFO_ENERGY_ANT_ABC_IDX]); |
Avri Altman | 17dbe56 | 2013-08-01 07:19:27 +0300 | [diff] [blame] | 159 | energy_a = (val & IWL_RX_INFO_ENERGY_ANT_A_MSK) >> |
| 160 | IWL_RX_INFO_ENERGY_ANT_A_POS; |
Eyal Shapira | 2cddddc | 2014-08-13 00:26:17 +0300 | [diff] [blame] | 161 | energy_a = energy_a ? -energy_a : S8_MIN; |
Avri Altman | 17dbe56 | 2013-08-01 07:19:27 +0300 | [diff] [blame] | 162 | energy_b = (val & IWL_RX_INFO_ENERGY_ANT_B_MSK) >> |
| 163 | IWL_RX_INFO_ENERGY_ANT_B_POS; |
Eyal Shapira | 2cddddc | 2014-08-13 00:26:17 +0300 | [diff] [blame] | 164 | energy_b = energy_b ? -energy_b : S8_MIN; |
Avri Altman | 17dbe56 | 2013-08-01 07:19:27 +0300 | [diff] [blame] | 165 | energy_c = (val & IWL_RX_INFO_ENERGY_ANT_C_MSK) >> |
| 166 | IWL_RX_INFO_ENERGY_ANT_C_POS; |
Eyal Shapira | 2cddddc | 2014-08-13 00:26:17 +0300 | [diff] [blame] | 167 | energy_c = energy_c ? -energy_c : S8_MIN; |
Avri Altman | a2d7b87 | 2013-07-09 01:42:17 +0300 | [diff] [blame] | 168 | max_energy = max(energy_a, energy_b); |
| 169 | max_energy = max(max_energy, energy_c); |
| 170 | |
| 171 | IWL_DEBUG_STATS(mvm, "energy In A %d B %d C %d , and max %d\n", |
| 172 | energy_a, energy_b, energy_c, max_energy); |
| 173 | |
Johannes Berg | 226eb8c | 2013-07-03 11:55:17 +0200 | [diff] [blame] | 174 | rx_status->signal = max_energy; |
| 175 | rx_status->chains = (le16_to_cpu(phy_info->phy_flags) & |
| 176 | RX_RES_PHY_FLAGS_ANTENNA) |
| 177 | >> RX_RES_PHY_FLAGS_ANTENNA_POS; |
| 178 | rx_status->chain_signal[0] = energy_a; |
| 179 | rx_status->chain_signal[1] = energy_b; |
| 180 | rx_status->chain_signal[2] = energy_c; |
Avri Altman | a2d7b87 | 2013-07-09 01:42:17 +0300 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 184 | * iwl_mvm_set_mac80211_rx_flag - translate fw status to mac80211 format |
| 185 | * @mvm: the mvm object |
| 186 | * @hdr: 80211 header |
| 187 | * @stats: status in mac80211's format |
| 188 | * @rx_pkt_status: status coming from fw |
| 189 | * |
| 190 | * returns non 0 value if the packet should be dropped |
| 191 | */ |
| 192 | static u32 iwl_mvm_set_mac80211_rx_flag(struct iwl_mvm *mvm, |
| 193 | struct ieee80211_hdr *hdr, |
| 194 | struct ieee80211_rx_status *stats, |
Johannes Berg | eb96ccb | 2014-11-12 17:12:05 +0100 | [diff] [blame] | 195 | u32 rx_pkt_status, |
| 196 | u8 *crypt_len) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 197 | { |
| 198 | if (!ieee80211_has_protected(hdr->frame_control) || |
| 199 | (rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) == |
| 200 | RX_MPDU_RES_STATUS_SEC_NO_ENC) |
| 201 | return 0; |
| 202 | |
| 203 | /* packet was encrypted with unknown alg */ |
| 204 | if ((rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) == |
| 205 | RX_MPDU_RES_STATUS_SEC_ENC_ERR) |
| 206 | return 0; |
| 207 | |
| 208 | switch (rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) { |
| 209 | case RX_MPDU_RES_STATUS_SEC_CCM_ENC: |
| 210 | /* alg is CCM: check MIC only */ |
| 211 | if (!(rx_pkt_status & RX_MPDU_RES_STATUS_MIC_OK)) |
| 212 | return -1; |
| 213 | |
| 214 | stats->flag |= RX_FLAG_DECRYPTED; |
Johannes Berg | eb96ccb | 2014-11-12 17:12:05 +0100 | [diff] [blame] | 215 | *crypt_len = IEEE80211_CCMP_HDR_LEN; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 216 | return 0; |
| 217 | |
| 218 | case RX_MPDU_RES_STATUS_SEC_TKIP_ENC: |
| 219 | /* Don't drop the frame and decrypt it in SW */ |
Sara Sharon | 57df383 | 2017-12-06 13:57:19 +0200 | [diff] [blame] | 220 | if (!fw_has_api(&mvm->fw->ucode_capa, |
| 221 | IWL_UCODE_TLV_API_DEPRECATE_TTAK) && |
| 222 | !(rx_pkt_status & RX_MPDU_RES_STATUS_TTAK_OK)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 223 | return 0; |
Johannes Berg | eb96ccb | 2014-11-12 17:12:05 +0100 | [diff] [blame] | 224 | *crypt_len = IEEE80211_TKIP_IV_LEN; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 225 | /* fall through if TTAK OK */ |
| 226 | |
| 227 | case RX_MPDU_RES_STATUS_SEC_WEP_ENC: |
| 228 | if (!(rx_pkt_status & RX_MPDU_RES_STATUS_ICV_OK)) |
| 229 | return -1; |
| 230 | |
| 231 | stats->flag |= RX_FLAG_DECRYPTED; |
Johannes Berg | eb96ccb | 2014-11-12 17:12:05 +0100 | [diff] [blame] | 232 | if ((rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) == |
| 233 | RX_MPDU_RES_STATUS_SEC_WEP_ENC) |
| 234 | *crypt_len = IEEE80211_WEP_IV_LEN; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 235 | return 0; |
| 236 | |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 237 | case RX_MPDU_RES_STATUS_SEC_EXT_ENC: |
| 238 | if (!(rx_pkt_status & RX_MPDU_RES_STATUS_MIC_OK)) |
| 239 | return -1; |
| 240 | stats->flag |= RX_FLAG_DECRYPTED; |
| 241 | return 0; |
| 242 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 243 | default: |
Shaul Triebitz | baf41bc | 2017-09-13 16:46:14 +0300 | [diff] [blame] | 244 | /* Expected in monitor (not having the keys) */ |
| 245 | if (!mvm->monitor_on) |
| 246 | IWL_ERR(mvm, "Unhandled alg: 0x%x\n", rx_pkt_status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
Luca Coelho | 7d9d0d5 | 2018-04-12 16:15:07 +0300 | [diff] [blame] | 252 | static void iwl_mvm_rx_handle_tcm(struct iwl_mvm *mvm, |
| 253 | struct ieee80211_sta *sta, |
| 254 | struct ieee80211_hdr *hdr, u32 len, |
| 255 | struct iwl_rx_phy_info *phy_info, |
| 256 | u32 rate_n_flags) |
| 257 | { |
| 258 | struct iwl_mvm_sta *mvmsta; |
| 259 | struct iwl_mvm_tcm_mac *mdata; |
| 260 | int mac; |
| 261 | int ac = IEEE80211_AC_BE; /* treat non-QoS as BE */ |
Johannes Berg | b0ffe45 | 2014-11-11 12:57:03 +0100 | [diff] [blame] | 262 | struct iwl_mvm_vif *mvmvif; |
| 263 | /* expected throughput in 100Kbps, single stream, 20 MHz */ |
| 264 | static const u8 thresh_tpt[] = { |
| 265 | 9, 18, 30, 42, 60, 78, 90, 96, 120, 135, |
| 266 | }; |
| 267 | u16 thr; |
Luca Coelho | 7d9d0d5 | 2018-04-12 16:15:07 +0300 | [diff] [blame] | 268 | |
| 269 | if (ieee80211_is_data_qos(hdr->frame_control)) |
| 270 | ac = tid_to_mac80211_ac[ieee80211_get_tid(hdr)]; |
| 271 | |
| 272 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 273 | mac = mvmsta->mac_id_n_color & FW_CTXT_ID_MSK; |
| 274 | |
| 275 | if (time_after(jiffies, mvm->tcm.ts + MVM_TCM_PERIOD)) |
| 276 | schedule_delayed_work(&mvm->tcm.work, 0); |
| 277 | mdata = &mvm->tcm.data[mac]; |
| 278 | mdata->rx.pkts[ac]++; |
| 279 | |
| 280 | /* count the airtime only once for each ampdu */ |
| 281 | if (mdata->rx.last_ampdu_ref != mvm->ampdu_ref) { |
| 282 | mdata->rx.last_ampdu_ref = mvm->ampdu_ref; |
| 283 | mdata->rx.airtime += le16_to_cpu(phy_info->frame_time); |
| 284 | } |
| 285 | |
| 286 | if (!(rate_n_flags & (RATE_MCS_HT_MSK | RATE_MCS_VHT_MSK))) |
| 287 | return; |
| 288 | |
Johannes Berg | b0ffe45 | 2014-11-11 12:57:03 +0100 | [diff] [blame] | 289 | mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif); |
| 290 | |
| 291 | if (mdata->opened_rx_ba_sessions || |
| 292 | mdata->uapsd_nonagg_detect.detected || |
| 293 | (!mvmvif->queue_params[IEEE80211_AC_VO].uapsd && |
| 294 | !mvmvif->queue_params[IEEE80211_AC_VI].uapsd && |
| 295 | !mvmvif->queue_params[IEEE80211_AC_BE].uapsd && |
| 296 | !mvmvif->queue_params[IEEE80211_AC_BK].uapsd) || |
| 297 | mvmsta->sta_id != mvmvif->ap_sta_id) |
| 298 | return; |
| 299 | |
| 300 | if (rate_n_flags & RATE_MCS_HT_MSK) { |
| 301 | thr = thresh_tpt[rate_n_flags & RATE_HT_MCS_RATE_CODE_MSK]; |
| 302 | thr *= 1 + ((rate_n_flags & RATE_HT_MCS_NSS_MSK) >> |
| 303 | RATE_HT_MCS_NSS_POS); |
| 304 | } else { |
| 305 | if (WARN_ON((rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK) >= |
| 306 | ARRAY_SIZE(thresh_tpt))) |
| 307 | return; |
| 308 | thr = thresh_tpt[rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK]; |
| 309 | thr *= 1 + ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >> |
| 310 | RATE_VHT_MCS_NSS_POS); |
| 311 | } |
| 312 | |
| 313 | thr <<= ((rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) >> |
| 314 | RATE_MCS_CHAN_WIDTH_POS); |
| 315 | |
| 316 | mdata->uapsd_nonagg_detect.rx_bytes += len; |
| 317 | ewma_rate_add(&mdata->uapsd_nonagg_detect.rate, thr); |
Luca Coelho | 7d9d0d5 | 2018-04-12 16:15:07 +0300 | [diff] [blame] | 318 | } |
| 319 | |
Avri Altman | 93190fb | 2014-12-27 09:09:47 +0200 | [diff] [blame] | 320 | static void iwl_mvm_rx_csum(struct ieee80211_sta *sta, |
| 321 | struct sk_buff *skb, |
| 322 | u32 status) |
| 323 | { |
| 324 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 325 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif); |
| 326 | |
| 327 | if (mvmvif->features & NETIF_F_RXCSUM && |
| 328 | status & RX_MPDU_RES_STATUS_CSUM_DONE && |
| 329 | status & RX_MPDU_RES_STATUS_CSUM_OK) |
| 330 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 331 | } |
| 332 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 333 | /* |
| 334 | * iwl_mvm_rx_rx_mpdu - REPLY_RX_MPDU_CMD handler |
| 335 | * |
| 336 | * Handles the actual data of the Rx packet from the fw |
| 337 | */ |
Johannes Berg | 1be5d8c | 2015-06-11 16:51:24 +0200 | [diff] [blame] | 338 | void iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct napi_struct *napi, |
| 339 | struct iwl_rx_cmd_buffer *rxb) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 340 | { |
| 341 | struct ieee80211_hdr *hdr; |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 342 | struct ieee80211_rx_status *rx_status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 343 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 344 | struct iwl_rx_phy_info *phy_info; |
| 345 | struct iwl_rx_mpdu_res_start *rx_res; |
Johannes Berg | a399f98 | 2015-09-24 18:29:00 +0200 | [diff] [blame] | 346 | struct ieee80211_sta *sta = NULL; |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 347 | struct sk_buff *skb; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 348 | u32 len; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 349 | u32 rate_n_flags; |
| 350 | u32 rx_pkt_status; |
Johannes Berg | eb96ccb | 2014-11-12 17:12:05 +0100 | [diff] [blame] | 351 | u8 crypt_len = 0; |
Luca Coelho | 16e4dd8 | 2016-03-30 15:05:56 +0300 | [diff] [blame] | 352 | bool take_ref; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 353 | |
| 354 | phy_info = &mvm->last_phy_info; |
| 355 | rx_res = (struct iwl_rx_mpdu_res_start *)pkt->data; |
| 356 | hdr = (struct ieee80211_hdr *)(pkt->data + sizeof(*rx_res)); |
| 357 | len = le16_to_cpu(rx_res->byte_count); |
| 358 | rx_pkt_status = le32_to_cpup((__le32 *) |
| 359 | (pkt->data + sizeof(*rx_res) + len)); |
| 360 | |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 361 | /* Dont use dev_alloc_skb(), we'll have enough headroom once |
| 362 | * ieee80211_hdr pulled. |
| 363 | */ |
| 364 | skb = alloc_skb(128, GFP_ATOMIC); |
| 365 | if (!skb) { |
| 366 | IWL_ERR(mvm, "alloc_skb failed\n"); |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 367 | return; |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | rx_status = IEEE80211_SKB_RXCB(skb); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 371 | |
| 372 | /* |
| 373 | * drop the packet if it has failed being decrypted by HW |
| 374 | */ |
Johannes Berg | eb96ccb | 2014-11-12 17:12:05 +0100 | [diff] [blame] | 375 | if (iwl_mvm_set_mac80211_rx_flag(mvm, hdr, rx_status, rx_pkt_status, |
| 376 | &crypt_len)) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 377 | IWL_DEBUG_DROP(mvm, "Bad decryption results 0x%08x\n", |
| 378 | rx_pkt_status); |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 379 | kfree_skb(skb); |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 380 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 381 | } |
| 382 | |
Johannes Berg | fb8b8ee | 2013-10-21 12:37:53 +0200 | [diff] [blame] | 383 | /* |
| 384 | * Keep packets with CRC errors (and with overrun) for monitor mode |
| 385 | * (otherwise the firmware discards them) but mark them as bad. |
| 386 | */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 387 | if (!(rx_pkt_status & RX_MPDU_RES_STATUS_CRC_OK) || |
| 388 | !(rx_pkt_status & RX_MPDU_RES_STATUS_OVERRUN_OK)) { |
| 389 | IWL_DEBUG_RX(mvm, "Bad CRC or FIFO: 0x%08X.\n", rx_pkt_status); |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 390 | rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | /* This will be used in several places later */ |
| 394 | rate_n_flags = le32_to_cpu(phy_info->rate_n_flags); |
| 395 | |
| 396 | /* rx_status carries information about the packet to mac80211 */ |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 397 | rx_status->mactime = le64_to_cpu(phy_info->timestamp); |
| 398 | rx_status->device_timestamp = le32_to_cpu(phy_info->system_timestamp); |
| 399 | rx_status->band = |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 400 | (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_BAND_24)) ? |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 401 | NL80211_BAND_2GHZ : NL80211_BAND_5GHZ; |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 402 | rx_status->freq = |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 403 | ieee80211_channel_to_frequency(le16_to_cpu(phy_info->channel), |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 404 | rx_status->band); |
Sara Sharon | 77fe739 | 2016-01-10 14:23:25 +0200 | [diff] [blame] | 405 | |
| 406 | /* TSF as indicated by the firmware is at INA time */ |
| 407 | rx_status->flag |= RX_FLAG_MACTIME_PLCP_START; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 408 | |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 409 | iwl_mvm_get_signal_strength(mvm, phy_info, rx_status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 410 | |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 411 | IWL_DEBUG_STATS_LIMIT(mvm, "Rssi %d, TSF %llu\n", rx_status->signal, |
| 412 | (unsigned long long)rx_status->mactime); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 413 | |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 414 | rcu_read_lock(); |
Johannes Berg | a399f98 | 2015-09-24 18:29:00 +0200 | [diff] [blame] | 415 | if (rx_pkt_status & RX_MPDU_RES_STATUS_SRC_STA_FOUND) { |
| 416 | u32 id = rx_pkt_status & RX_MPDU_RES_STATUS_STA_ID_MSK; |
| 417 | |
| 418 | id >>= RX_MDPU_RES_STATUS_STA_ID_SHIFT; |
| 419 | |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 420 | if (!WARN_ON_ONCE(id >= ARRAY_SIZE(mvm->fw_id_to_mac_id))) { |
Johannes Berg | a399f98 | 2015-09-24 18:29:00 +0200 | [diff] [blame] | 421 | sta = rcu_dereference(mvm->fw_id_to_mac_id[id]); |
| 422 | if (IS_ERR(sta)) |
| 423 | sta = NULL; |
| 424 | } |
| 425 | } else if (!is_multicast_ether_addr(hdr->addr2)) { |
| 426 | /* This is fine since we prevent two stations with the same |
| 427 | * address from being added. |
| 428 | */ |
| 429 | sta = ieee80211_find_sta_by_ifaddr(mvm->hw, hdr->addr2, NULL); |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 430 | } |
| 431 | |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 432 | if (sta) { |
Johannes Berg | 7c0ebd7 | 2015-09-22 12:28:42 +0200 | [diff] [blame] | 433 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Andrei Otcheretianski | d3a108a | 2016-02-28 17:12:21 +0200 | [diff] [blame] | 434 | struct ieee80211_vif *tx_blocked_vif = |
| 435 | rcu_dereference(mvm->csa_tx_blocked_vif); |
Sara Sharon | 6c042d7 | 2018-06-12 10:41:35 +0300 | [diff] [blame] | 436 | struct iwl_fw_dbg_trigger_tlv *trig; |
| 437 | struct ieee80211_vif *vif = mvmsta->vif; |
Johannes Berg | 7c0ebd7 | 2015-09-22 12:28:42 +0200 | [diff] [blame] | 438 | |
Johannes Berg | a399f98 | 2015-09-24 18:29:00 +0200 | [diff] [blame] | 439 | /* We have tx blocked stations (with CS bit). If we heard |
| 440 | * frames from a blocked station on a new channel we can |
| 441 | * TX to it again. |
| 442 | */ |
Sara Sharon | 6c042d7 | 2018-06-12 10:41:35 +0300 | [diff] [blame] | 443 | if (unlikely(tx_blocked_vif) && vif == tx_blocked_vif) { |
Andrei Otcheretianski | d3a108a | 2016-02-28 17:12:21 +0200 | [diff] [blame] | 444 | struct iwl_mvm_vif *mvmvif = |
| 445 | iwl_mvm_vif_from_mac80211(tx_blocked_vif); |
| 446 | |
| 447 | if (mvmvif->csa_target_freq == rx_status->freq) |
| 448 | iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, |
| 449 | false); |
| 450 | } |
Johannes Berg | a399f98 | 2015-09-24 18:29:00 +0200 | [diff] [blame] | 451 | |
Gregory Greenman | ecaf71d | 2017-11-01 07:16:29 +0200 | [diff] [blame] | 452 | rs_update_last_rssi(mvm, mvmsta, rx_status); |
Emmanuel Grumbach | 3ec50b5e | 2015-02-03 14:29:36 +0200 | [diff] [blame] | 453 | |
Sara Sharon | 6c042d7 | 2018-06-12 10:41:35 +0300 | [diff] [blame] | 454 | trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, |
| 455 | ieee80211_vif_to_wdev(vif), |
| 456 | FW_DBG_TRIGGER_RSSI); |
| 457 | |
| 458 | if (trig && ieee80211_is_beacon(hdr->frame_control)) { |
Emmanuel Grumbach | 3ec50b5e | 2015-02-03 14:29:36 +0200 | [diff] [blame] | 459 | struct iwl_fw_dbg_trigger_low_rssi *rssi_trig; |
Emmanuel Grumbach | 3ec50b5e | 2015-02-03 14:29:36 +0200 | [diff] [blame] | 460 | s32 rssi; |
| 461 | |
Emmanuel Grumbach | 3ec50b5e | 2015-02-03 14:29:36 +0200 | [diff] [blame] | 462 | rssi_trig = (void *)trig->data; |
| 463 | rssi = le32_to_cpu(rssi_trig->rssi); |
| 464 | |
Sara Sharon | 6c042d7 | 2018-06-12 10:41:35 +0300 | [diff] [blame] | 465 | if (rx_status->signal < rssi) |
Johannes Berg | 7174beb | 2017-06-01 16:03:19 +0200 | [diff] [blame] | 466 | iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, |
| 467 | NULL); |
Emmanuel Grumbach | 3ec50b5e | 2015-02-03 14:29:36 +0200 | [diff] [blame] | 468 | } |
Johannes Berg | a399f98 | 2015-09-24 18:29:00 +0200 | [diff] [blame] | 469 | |
Luca Coelho | 7d9d0d5 | 2018-04-12 16:15:07 +0300 | [diff] [blame] | 470 | if (!mvm->tcm.paused && len >= sizeof(*hdr) && |
| 471 | !is_multicast_ether_addr(hdr->addr1) && |
| 472 | ieee80211_is_data(hdr->frame_control)) |
| 473 | iwl_mvm_rx_handle_tcm(mvm, sta, hdr, len, phy_info, |
| 474 | rate_n_flags); |
| 475 | |
Johannes Berg | a399f98 | 2015-09-24 18:29:00 +0200 | [diff] [blame] | 476 | if (ieee80211_is_data(hdr->frame_control)) |
| 477 | iwl_mvm_rx_csum(sta, skb, rx_pkt_status); |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 478 | } |
Eyal Shapira | 361dbec | 2014-08-13 00:31:13 +0300 | [diff] [blame] | 479 | rcu_read_unlock(); |
| 480 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 481 | /* set the preamble flag if appropriate */ |
| 482 | if (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_SHORT_PREAMBLE)) |
Johannes Berg | 7fdd69c | 2017-04-26 11:13:00 +0200 | [diff] [blame] | 483 | rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 484 | |
| 485 | if (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_AGG)) { |
| 486 | /* |
| 487 | * We know which subframes of an A-MPDU belong |
| 488 | * together since we get a single PHY response |
| 489 | * from the firmware for all of them |
| 490 | */ |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 491 | rx_status->flag |= RX_FLAG_AMPDU_DETAILS; |
| 492 | rx_status->ampdu_reference = mvm->ampdu_ref; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | /* Set up the HT phy flags */ |
| 496 | switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { |
| 497 | case RATE_MCS_CHAN_WIDTH_20: |
| 498 | break; |
| 499 | case RATE_MCS_CHAN_WIDTH_40: |
Johannes Berg | da6a435 | 2017-04-26 12:14:59 +0200 | [diff] [blame] | 500 | rx_status->bw = RATE_INFO_BW_40; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 501 | break; |
| 502 | case RATE_MCS_CHAN_WIDTH_80: |
Johannes Berg | da6a435 | 2017-04-26 12:14:59 +0200 | [diff] [blame] | 503 | rx_status->bw = RATE_INFO_BW_80; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 504 | break; |
| 505 | case RATE_MCS_CHAN_WIDTH_160: |
Johannes Berg | da6a435 | 2017-04-26 12:14:59 +0200 | [diff] [blame] | 506 | rx_status->bw = RATE_INFO_BW_160; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 507 | break; |
| 508 | } |
Sara Sharon | 4c59ff5 | 2017-10-29 10:46:39 +0200 | [diff] [blame] | 509 | if (!(rate_n_flags & RATE_MCS_CCK_MSK) && |
| 510 | rate_n_flags & RATE_MCS_SGI_MSK) |
Johannes Berg | 7fdd69c | 2017-04-26 11:13:00 +0200 | [diff] [blame] | 511 | rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 512 | if (rate_n_flags & RATE_HT_MCS_GF_MSK) |
Johannes Berg | 7fdd69c | 2017-04-26 11:13:00 +0200 | [diff] [blame] | 513 | rx_status->enc_flags |= RX_ENC_FLAG_HT_GF; |
Emmanuel Grumbach | 7b1dd04 | 2014-02-04 15:32:43 +0200 | [diff] [blame] | 514 | if (rate_n_flags & RATE_MCS_LDPC_MSK) |
Johannes Berg | 7fdd69c | 2017-04-26 11:13:00 +0200 | [diff] [blame] | 515 | rx_status->enc_flags |= RX_ENC_FLAG_LDPC; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 516 | if (rate_n_flags & RATE_MCS_HT_MSK) { |
Sara Sharon | 77e4094 | 2017-01-11 11:58:38 +0200 | [diff] [blame] | 517 | u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >> |
Emmanuel Grumbach | 7b1dd04 | 2014-02-04 15:32:43 +0200 | [diff] [blame] | 518 | RATE_MCS_STBC_POS; |
Johannes Berg | da6a435 | 2017-04-26 12:14:59 +0200 | [diff] [blame] | 519 | rx_status->encoding = RX_ENC_HT; |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 520 | rx_status->rate_idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK; |
Johannes Berg | 7fdd69c | 2017-04-26 11:13:00 +0200 | [diff] [blame] | 521 | rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 522 | } else if (rate_n_flags & RATE_MCS_VHT_MSK) { |
Sara Sharon | 77e4094 | 2017-01-11 11:58:38 +0200 | [diff] [blame] | 523 | u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >> |
Emmanuel Grumbach | 7b1dd04 | 2014-02-04 15:32:43 +0200 | [diff] [blame] | 524 | RATE_MCS_STBC_POS; |
Johannes Berg | 8613c94 | 2017-04-26 13:51:41 +0200 | [diff] [blame] | 525 | rx_status->nss = |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 526 | ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >> |
| 527 | RATE_VHT_MCS_NSS_POS) + 1; |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 528 | rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK; |
Johannes Berg | da6a435 | 2017-04-26 12:14:59 +0200 | [diff] [blame] | 529 | rx_status->encoding = RX_ENC_VHT; |
Johannes Berg | 7fdd69c | 2017-04-26 11:13:00 +0200 | [diff] [blame] | 530 | rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT; |
Emmanuel Grumbach | 95e05ab | 2014-03-04 09:38:43 +0200 | [diff] [blame] | 531 | if (rate_n_flags & RATE_MCS_BF_MSK) |
Johannes Berg | 7fdd69c | 2017-04-26 11:13:00 +0200 | [diff] [blame] | 532 | rx_status->enc_flags |= RX_ENC_FLAG_BF; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 533 | } else { |
Sara Sharon | cb2de6b | 2017-02-13 13:36:31 +0200 | [diff] [blame] | 534 | int rate = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags, |
| 535 | rx_status->band); |
| 536 | |
| 537 | if (WARN(rate < 0 || rate > 0xFF, |
| 538 | "Invalid rate flags 0x%x, band %d,\n", |
| 539 | rate_n_flags, rx_status->band)) { |
| 540 | kfree_skb(skb); |
| 541 | return; |
| 542 | } |
| 543 | rx_status->rate_idx = rate; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 544 | } |
| 545 | |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 546 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Johannes Berg | 2f15a82 | 2015-01-21 18:05:04 +0100 | [diff] [blame] | 547 | iwl_mvm_update_frame_stats(mvm, rate_n_flags, |
Johannes Berg | d0963b5 | 2014-11-12 16:45:12 +0100 | [diff] [blame] | 548 | rx_status->flag & RX_FLAG_AMPDU_DETAILS); |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 549 | #endif |
Luca Coelho | a339e91 | 2016-02-02 22:58:46 +0200 | [diff] [blame] | 550 | |
| 551 | if (unlikely((ieee80211_is_beacon(hdr->frame_control) || |
| 552 | ieee80211_is_probe_resp(hdr->frame_control)) && |
| 553 | mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED)) |
| 554 | mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_FOUND; |
| 555 | |
Johannes Berg | 43ec72b | 2016-03-10 11:55:44 +0100 | [diff] [blame] | 556 | if (unlikely(ieee80211_is_beacon(hdr->frame_control) || |
| 557 | ieee80211_is_probe_resp(hdr->frame_control))) |
| 558 | rx_status->boottime_ns = ktime_get_boot_ns(); |
| 559 | |
Luca Coelho | 16e4dd8 | 2016-03-30 15:05:56 +0300 | [diff] [blame] | 560 | /* Take a reference briefly to kick off a d0i3 entry delay so |
| 561 | * we can handle bursts of RX packets without toggling the |
| 562 | * state too often. But don't do this for beacons if we are |
| 563 | * going to idle because the beacon filtering changes we make |
| 564 | * cause the firmware to send us collateral beacons. */ |
| 565 | take_ref = !(test_bit(STATUS_TRANS_GOING_IDLE, &mvm->trans->status) && |
| 566 | ieee80211_is_beacon(hdr->frame_control)); |
| 567 | |
| 568 | if (take_ref) |
| 569 | iwl_mvm_ref(mvm, IWL_MVM_REF_RX); |
| 570 | |
Johannes Berg | 43ec72b | 2016-03-10 11:55:44 +0100 | [diff] [blame] | 571 | iwl_mvm_pass_packet_to_mac80211(mvm, sta, napi, skb, hdr, len, |
Dan Carpenter | bdbc58a | 2016-05-04 09:19:13 +0300 | [diff] [blame] | 572 | crypt_len, rxb); |
Luca Coelho | 16e4dd8 | 2016-03-30 15:05:56 +0300 | [diff] [blame] | 573 | |
| 574 | if (take_ref) |
| 575 | iwl_mvm_unref(mvm, IWL_MVM_REF_RX); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 576 | } |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 577 | |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 578 | struct iwl_mvm_stat_data { |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 579 | struct iwl_mvm *mvm; |
Johannes Berg | 777c9b6 | 2015-01-14 17:58:57 +0100 | [diff] [blame] | 580 | __le32 mac_id; |
Sara Sharon | 62e004f | 2015-08-20 14:12:58 +0300 | [diff] [blame] | 581 | u8 beacon_filter_average_energy; |
Sara Sharon | 0e7ac01 | 2016-09-08 17:32:19 +0300 | [diff] [blame] | 582 | void *general; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 583 | }; |
| 584 | |
| 585 | static void iwl_mvm_stat_iterator(void *_data, u8 *mac, |
| 586 | struct ieee80211_vif *vif) |
| 587 | { |
| 588 | struct iwl_mvm_stat_data *data = _data; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 589 | struct iwl_mvm *mvm = data->mvm; |
Johannes Berg | 777c9b6 | 2015-01-14 17:58:57 +0100 | [diff] [blame] | 590 | int sig = -data->beacon_filter_average_energy; |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 591 | int last_event; |
| 592 | int thold = vif->bss_conf.cqm_rssi_thold; |
| 593 | int hyst = vif->bss_conf.cqm_rssi_hyst; |
Johannes Berg | 777c9b6 | 2015-01-14 17:58:57 +0100 | [diff] [blame] | 594 | u16 id = le32_to_cpu(data->mac_id); |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 595 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 596 | |
Johannes Berg | 33cef92 | 2015-01-21 21:41:29 +0100 | [diff] [blame] | 597 | /* This doesn't need the MAC ID check since it's not taking the |
| 598 | * data copied into the "data" struct, but rather the data from |
| 599 | * the notification directly. |
| 600 | */ |
| 601 | if (data->general) { |
Sara Sharon | 0e7ac01 | 2016-09-08 17:32:19 +0300 | [diff] [blame] | 602 | u16 vif_id = mvmvif->id; |
| 603 | |
| 604 | if (iwl_mvm_is_cdb_supported(mvm)) { |
| 605 | struct mvm_statistics_general_cdb *general = |
| 606 | data->general; |
| 607 | |
| 608 | mvmvif->beacon_stats.num_beacons = |
| 609 | le32_to_cpu(general->beacon_counter[vif_id]); |
| 610 | mvmvif->beacon_stats.avg_signal = |
| 611 | -general->beacon_average_energy[vif_id]; |
| 612 | } else { |
| 613 | struct mvm_statistics_general_v8 *general = |
| 614 | data->general; |
| 615 | |
| 616 | mvmvif->beacon_stats.num_beacons = |
| 617 | le32_to_cpu(general->beacon_counter[vif_id]); |
| 618 | mvmvif->beacon_stats.avg_signal = |
| 619 | -general->beacon_average_energy[vif_id]; |
| 620 | } |
Johannes Berg | 33cef92 | 2015-01-21 21:41:29 +0100 | [diff] [blame] | 621 | } |
| 622 | |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 623 | if (mvmvif->id != id) |
| 624 | return; |
| 625 | |
| 626 | if (vif->type != NL80211_IFTYPE_STATION) |
| 627 | return; |
| 628 | |
Alexander Bondar | 8047cc0 | 2015-03-26 13:15:03 +0200 | [diff] [blame] | 629 | if (sig == 0) { |
| 630 | IWL_DEBUG_RX(mvm, "RSSI is 0 - skip signal based decision\n"); |
| 631 | return; |
| 632 | } |
| 633 | |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 634 | mvmvif->bf_data.ave_beacon_signal = sig; |
| 635 | |
Andrei Otcheretianski | 911222b | 2013-07-21 17:37:19 +0300 | [diff] [blame] | 636 | /* BT Coex */ |
| 637 | if (mvmvif->bf_data.bt_coex_min_thold != |
| 638 | mvmvif->bf_data.bt_coex_max_thold) { |
| 639 | last_event = mvmvif->bf_data.last_bt_coex_event; |
| 640 | if (sig > mvmvif->bf_data.bt_coex_max_thold && |
| 641 | (last_event <= mvmvif->bf_data.bt_coex_min_thold || |
| 642 | last_event == 0)) { |
| 643 | mvmvif->bf_data.last_bt_coex_event = sig; |
| 644 | IWL_DEBUG_RX(mvm, "cqm_iterator bt coex high %d\n", |
| 645 | sig); |
| 646 | iwl_mvm_bt_rssi_event(mvm, vif, RSSI_EVENT_HIGH); |
| 647 | } else if (sig < mvmvif->bf_data.bt_coex_min_thold && |
| 648 | (last_event >= mvmvif->bf_data.bt_coex_max_thold || |
| 649 | last_event == 0)) { |
| 650 | mvmvif->bf_data.last_bt_coex_event = sig; |
| 651 | IWL_DEBUG_RX(mvm, "cqm_iterator bt coex low %d\n", |
| 652 | sig); |
| 653 | iwl_mvm_bt_rssi_event(mvm, vif, RSSI_EVENT_LOW); |
| 654 | } |
| 655 | } |
| 656 | |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 657 | if (!(vif->driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) |
| 658 | return; |
| 659 | |
| 660 | /* CQM Notification */ |
| 661 | last_event = mvmvif->bf_data.last_cqm_event; |
| 662 | if (thold && sig < thold && (last_event == 0 || |
| 663 | sig < last_event - hyst)) { |
| 664 | mvmvif->bf_data.last_cqm_event = sig; |
| 665 | IWL_DEBUG_RX(mvm, "cqm_iterator cqm low %d\n", |
| 666 | sig); |
| 667 | ieee80211_cqm_rssi_notify( |
| 668 | vif, |
| 669 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 670 | sig, |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 671 | GFP_KERNEL); |
| 672 | } else if (sig > thold && |
| 673 | (last_event == 0 || sig > last_event + hyst)) { |
| 674 | mvmvif->bf_data.last_cqm_event = sig; |
| 675 | IWL_DEBUG_RX(mvm, "cqm_iterator cqm high %d\n", |
| 676 | sig); |
| 677 | ieee80211_cqm_rssi_notify( |
| 678 | vif, |
| 679 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 680 | sig, |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 681 | GFP_KERNEL); |
| 682 | } |
| 683 | } |
| 684 | |
Emmanuel Grumbach | 5a756c2 | 2015-02-10 15:26:57 +0200 | [diff] [blame] | 685 | static inline void |
| 686 | iwl_mvm_rx_stats_check_trigger(struct iwl_mvm *mvm, struct iwl_rx_packet *pkt) |
| 687 | { |
| 688 | struct iwl_fw_dbg_trigger_tlv *trig; |
| 689 | struct iwl_fw_dbg_trigger_stats *trig_stats; |
| 690 | u32 trig_offset, trig_thold; |
| 691 | |
Sara Sharon | 6c042d7 | 2018-06-12 10:41:35 +0300 | [diff] [blame] | 692 | trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, NULL, FW_DBG_TRIGGER_STATS); |
| 693 | if (!trig) |
Emmanuel Grumbach | 5a756c2 | 2015-02-10 15:26:57 +0200 | [diff] [blame] | 694 | return; |
| 695 | |
Emmanuel Grumbach | 5a756c2 | 2015-02-10 15:26:57 +0200 | [diff] [blame] | 696 | trig_stats = (void *)trig->data; |
| 697 | |
Emmanuel Grumbach | 5a756c2 | 2015-02-10 15:26:57 +0200 | [diff] [blame] | 698 | trig_offset = le32_to_cpu(trig_stats->stop_offset); |
| 699 | trig_thold = le32_to_cpu(trig_stats->stop_threshold); |
| 700 | |
| 701 | if (WARN_ON_ONCE(trig_offset >= iwl_rx_packet_payload_len(pkt))) |
| 702 | return; |
| 703 | |
| 704 | if (le32_to_cpup((__le32 *) (pkt->data + trig_offset)) < trig_thold) |
| 705 | return; |
| 706 | |
Johannes Berg | 7174beb | 2017-06-01 16:03:19 +0200 | [diff] [blame] | 707 | iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, NULL); |
Emmanuel Grumbach | 5a756c2 | 2015-02-10 15:26:57 +0200 | [diff] [blame] | 708 | } |
| 709 | |
Johannes Berg | 91a8bcd | 2015-01-14 18:12:41 +0100 | [diff] [blame] | 710 | void iwl_mvm_handle_rx_statistics(struct iwl_mvm *mvm, |
| 711 | struct iwl_rx_packet *pkt) |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 712 | { |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 713 | struct iwl_mvm_stat_data data = { |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 714 | .mvm = mvm, |
| 715 | }; |
Sara Sharon | 0e7ac01 | 2016-09-08 17:32:19 +0300 | [diff] [blame] | 716 | int expected_size; |
Goodstein, Mordechay | cfbeb598 | 2016-11-21 10:26:36 +0200 | [diff] [blame] | 717 | int i; |
| 718 | u8 *energy; |
Johannes Berg | b0ffe45 | 2014-11-11 12:57:03 +0100 | [diff] [blame] | 719 | __le32 *bytes; |
Luca Coelho | 7d9d0d5 | 2018-04-12 16:15:07 +0300 | [diff] [blame] | 720 | __le32 *air_time; |
Liad Kaufman | 678d9b6 | 2017-05-18 18:00:49 +0300 | [diff] [blame] | 721 | __le32 flags; |
Sara Sharon | 0e7ac01 | 2016-09-08 17:32:19 +0300 | [diff] [blame] | 722 | |
Liad Kaufman | 678d9b6 | 2017-05-18 18:00:49 +0300 | [diff] [blame] | 723 | if (!iwl_mvm_has_new_rx_stats_api(mvm)) { |
| 724 | if (iwl_mvm_has_new_rx_api(mvm)) |
| 725 | expected_size = sizeof(struct iwl_notif_statistics_v11); |
| 726 | else |
| 727 | expected_size = sizeof(struct iwl_notif_statistics_v10); |
| 728 | } else { |
| 729 | expected_size = sizeof(struct iwl_notif_statistics_cdb); |
| 730 | } |
Johannes Berg | 777c9b6 | 2015-01-14 17:58:57 +0100 | [diff] [blame] | 731 | |
Johannes Berg | 42fa5e0 | 2017-09-26 16:37:12 +0200 | [diff] [blame] | 732 | if (WARN_ONCE(iwl_rx_packet_payload_len(pkt) != expected_size, |
| 733 | "received invalid statistics size (%d)!\n", |
| 734 | iwl_rx_packet_payload_len(pkt))) |
Luca Coelho | 6a90f85 | 2017-01-25 18:57:26 +0200 | [diff] [blame] | 735 | return; |
Johannes Berg | 777c9b6 | 2015-01-14 17:58:57 +0100 | [diff] [blame] | 736 | |
Liad Kaufman | 678d9b6 | 2017-05-18 18:00:49 +0300 | [diff] [blame] | 737 | if (!iwl_mvm_has_new_rx_stats_api(mvm)) { |
| 738 | struct iwl_notif_statistics_v11 *stats = (void *)&pkt->data; |
Johannes Berg | 777c9b6 | 2015-01-14 17:58:57 +0100 | [diff] [blame] | 739 | |
Liad Kaufman | 678d9b6 | 2017-05-18 18:00:49 +0300 | [diff] [blame] | 740 | data.mac_id = stats->rx.general.mac_id; |
| 741 | data.beacon_filter_average_energy = |
| 742 | stats->general.common.beacon_filter_average_energy; |
Johannes Berg | 777c9b6 | 2015-01-14 17:58:57 +0100 | [diff] [blame] | 743 | |
Liad Kaufman | 678d9b6 | 2017-05-18 18:00:49 +0300 | [diff] [blame] | 744 | mvm->rx_stats_v3 = stats->rx; |
Johannes Berg | 91a8bcd | 2015-01-14 18:12:41 +0100 | [diff] [blame] | 745 | |
Liad Kaufman | 678d9b6 | 2017-05-18 18:00:49 +0300 | [diff] [blame] | 746 | mvm->radio_stats.rx_time = |
| 747 | le64_to_cpu(stats->general.common.rx_time); |
| 748 | mvm->radio_stats.tx_time = |
| 749 | le64_to_cpu(stats->general.common.tx_time); |
| 750 | mvm->radio_stats.on_time_rf = |
| 751 | le64_to_cpu(stats->general.common.on_time_rf); |
| 752 | mvm->radio_stats.on_time_scan = |
| 753 | le64_to_cpu(stats->general.common.on_time_scan); |
| 754 | |
| 755 | data.general = &stats->general; |
| 756 | |
| 757 | flags = stats->flag; |
| 758 | } else { |
| 759 | struct iwl_notif_statistics_cdb *stats = (void *)&pkt->data; |
| 760 | |
| 761 | data.mac_id = stats->rx.general.mac_id; |
| 762 | data.beacon_filter_average_energy = |
| 763 | stats->general.common.beacon_filter_average_energy; |
| 764 | |
| 765 | mvm->rx_stats = stats->rx; |
| 766 | |
| 767 | mvm->radio_stats.rx_time = |
| 768 | le64_to_cpu(stats->general.common.rx_time); |
| 769 | mvm->radio_stats.tx_time = |
| 770 | le64_to_cpu(stats->general.common.tx_time); |
| 771 | mvm->radio_stats.on_time_rf = |
| 772 | le64_to_cpu(stats->general.common.on_time_rf); |
| 773 | mvm->radio_stats.on_time_scan = |
| 774 | le64_to_cpu(stats->general.common.on_time_scan); |
| 775 | |
| 776 | data.general = &stats->general; |
| 777 | |
| 778 | flags = stats->flag; |
| 779 | } |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 780 | |
Emmanuel Grumbach | 5a756c2 | 2015-02-10 15:26:57 +0200 | [diff] [blame] | 781 | iwl_mvm_rx_stats_check_trigger(mvm, pkt); |
| 782 | |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 783 | ieee80211_iterate_active_interfaces(mvm->hw, |
| 784 | IEEE80211_IFACE_ITER_NORMAL, |
| 785 | iwl_mvm_stat_iterator, |
| 786 | &data); |
Goodstein, Mordechay | cfbeb598 | 2016-11-21 10:26:36 +0200 | [diff] [blame] | 787 | |
| 788 | if (!iwl_mvm_has_new_rx_api(mvm)) |
| 789 | return; |
| 790 | |
Liad Kaufman | 678d9b6 | 2017-05-18 18:00:49 +0300 | [diff] [blame] | 791 | if (!iwl_mvm_has_new_rx_stats_api(mvm)) { |
| 792 | struct iwl_notif_statistics_v11 *v11 = (void *)&pkt->data; |
Goodstein, Mordechay | cfbeb598 | 2016-11-21 10:26:36 +0200 | [diff] [blame] | 793 | |
| 794 | energy = (void *)&v11->load_stats.avg_energy; |
Johannes Berg | b0ffe45 | 2014-11-11 12:57:03 +0100 | [diff] [blame] | 795 | bytes = (void *)&v11->load_stats.byte_count; |
Goodstein, Mordechay | cfbeb598 | 2016-11-21 10:26:36 +0200 | [diff] [blame] | 796 | air_time = (void *)&v11->load_stats.air_time; |
| 797 | } else { |
Liad Kaufman | 678d9b6 | 2017-05-18 18:00:49 +0300 | [diff] [blame] | 798 | struct iwl_notif_statistics_cdb *stats = (void *)&pkt->data; |
| 799 | |
Goodstein, Mordechay | cfbeb598 | 2016-11-21 10:26:36 +0200 | [diff] [blame] | 800 | energy = (void *)&stats->load_stats.avg_energy; |
Johannes Berg | b0ffe45 | 2014-11-11 12:57:03 +0100 | [diff] [blame] | 801 | bytes = (void *)&stats->load_stats.byte_count; |
Goodstein, Mordechay | cfbeb598 | 2016-11-21 10:26:36 +0200 | [diff] [blame] | 802 | air_time = (void *)&stats->load_stats.air_time; |
| 803 | } |
| 804 | |
| 805 | rcu_read_lock(); |
| 806 | for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) { |
| 807 | struct iwl_mvm_sta *sta; |
| 808 | |
| 809 | if (!energy[i]) |
| 810 | continue; |
| 811 | |
| 812 | sta = iwl_mvm_sta_from_staid_rcu(mvm, i); |
| 813 | if (!sta) |
| 814 | continue; |
| 815 | sta->avg_energy = energy[i]; |
| 816 | } |
| 817 | rcu_read_unlock(); |
Luca Coelho | 7d9d0d5 | 2018-04-12 16:15:07 +0300 | [diff] [blame] | 818 | |
| 819 | /* |
| 820 | * Don't update in case the statistics are not cleared, since |
| 821 | * we will end up counting twice the same airtime, once in TCM |
| 822 | * request and once in statistics notification. |
| 823 | */ |
| 824 | if (!(le32_to_cpu(flags) & IWL_STATISTICS_REPLY_FLG_CLEAR)) |
| 825 | return; |
| 826 | |
| 827 | spin_lock(&mvm->tcm.lock); |
| 828 | for (i = 0; i < NUM_MAC_INDEX_DRIVER; i++) { |
| 829 | struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[i]; |
| 830 | u32 airtime = le32_to_cpu(air_time[i]); |
Johannes Berg | b0ffe45 | 2014-11-11 12:57:03 +0100 | [diff] [blame] | 831 | u32 rx_bytes = le32_to_cpu(bytes[i]); |
| 832 | |
| 833 | mdata->uapsd_nonagg_detect.rx_bytes += rx_bytes; |
| 834 | if (airtime) { |
| 835 | /* re-init every time to store rate from FW */ |
| 836 | ewma_rate_init(&mdata->uapsd_nonagg_detect.rate); |
| 837 | ewma_rate_add(&mdata->uapsd_nonagg_detect.rate, |
| 838 | rx_bytes * 8 / airtime); |
| 839 | } |
Luca Coelho | 7d9d0d5 | 2018-04-12 16:15:07 +0300 | [diff] [blame] | 840 | |
| 841 | mdata->rx.airtime += airtime; |
| 842 | } |
| 843 | spin_unlock(&mvm->tcm.lock); |
Johannes Berg | 91a8bcd | 2015-01-14 18:12:41 +0100 | [diff] [blame] | 844 | } |
| 845 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 846 | void iwl_mvm_rx_statistics(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) |
Johannes Berg | 91a8bcd | 2015-01-14 18:12:41 +0100 | [diff] [blame] | 847 | { |
| 848 | iwl_mvm_handle_rx_statistics(mvm, rxb_addr(rxb)); |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 849 | } |
Sara Sharon | 3af512d6 | 2015-07-22 11:38:40 +0300 | [diff] [blame] | 850 | |
| 851 | void iwl_mvm_window_status_notif(struct iwl_mvm *mvm, |
| 852 | struct iwl_rx_cmd_buffer *rxb) |
| 853 | { |
| 854 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 855 | struct iwl_ba_window_status_notif *notif = (void *)pkt->data; |
| 856 | int i; |
| 857 | u32 pkt_len = iwl_rx_packet_payload_len(pkt); |
| 858 | |
| 859 | if (WARN_ONCE(pkt_len != sizeof(*notif), |
| 860 | "Received window status notification of wrong size (%u)\n", |
| 861 | pkt_len)) |
| 862 | return; |
| 863 | |
| 864 | rcu_read_lock(); |
| 865 | for (i = 0; i < BA_WINDOW_STREAMS_MAX; i++) { |
| 866 | struct ieee80211_sta *sta; |
| 867 | u8 sta_id, tid; |
| 868 | u64 bitmap; |
| 869 | u32 ssn; |
| 870 | u16 ratid; |
| 871 | u16 received_mpdu; |
| 872 | |
| 873 | ratid = le16_to_cpu(notif->ra_tid[i]); |
| 874 | /* check that this TID is valid */ |
| 875 | if (!(ratid & BA_WINDOW_STATUS_VALID_MSK)) |
| 876 | continue; |
| 877 | |
| 878 | received_mpdu = le16_to_cpu(notif->mpdu_rx_count[i]); |
| 879 | if (received_mpdu == 0) |
| 880 | continue; |
| 881 | |
| 882 | tid = ratid & BA_WINDOW_STATUS_TID_MSK; |
| 883 | /* get the station */ |
| 884 | sta_id = (ratid & BA_WINDOW_STATUS_STA_ID_MSK) |
| 885 | >> BA_WINDOW_STATUS_STA_ID_POS; |
| 886 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 887 | if (IS_ERR_OR_NULL(sta)) |
| 888 | continue; |
| 889 | bitmap = le64_to_cpu(notif->bitmap[i]); |
| 890 | ssn = le32_to_cpu(notif->start_seq_num[i]); |
| 891 | |
| 892 | /* update mac80211 with the bitmap for the reordering buffer */ |
| 893 | ieee80211_mark_rx_ba_filtered_frames(sta, tid, ssn, bitmap, |
| 894 | received_mpdu); |
| 895 | } |
| 896 | rcu_read_unlock(); |
| 897 | } |