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