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. |
Emmanuel Grumbach | 4203263 | 2015-04-15 12:43:46 +0300 | [diff] [blame] | 9 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Emmanuel Grumbach | 532beba | 2016-03-07 22:23:52 +0200 | [diff] [blame] | 10 | * Copyright(c) 2016 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 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 24 | * USA |
| 25 | * |
| 26 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 27 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 28 | * |
| 29 | * Contact Information: |
Emmanuel Grumbach | cb2f827 | 2015-11-17 15:39:56 +0200 | [diff] [blame] | 30 | * Intel Linux Wireless <linuxwifi@intel.com> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 31 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 32 | * |
| 33 | * BSD LICENSE |
| 34 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 35 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Emmanuel Grumbach | 4203263 | 2015-04-15 12:43:46 +0300 | [diff] [blame] | 36 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 37 | * All rights reserved. |
| 38 | * |
| 39 | * Redistribution and use in source and binary forms, with or without |
| 40 | * modification, are permitted provided that the following conditions |
| 41 | * are met: |
| 42 | * |
| 43 | * * Redistributions of source code must retain the above copyright |
| 44 | * notice, this list of conditions and the following disclaimer. |
| 45 | * * Redistributions in binary form must reproduce the above copyright |
| 46 | * notice, this list of conditions and the following disclaimer in |
| 47 | * the documentation and/or other materials provided with the |
| 48 | * distribution. |
| 49 | * * Neither the name Intel Corporation nor the names of its |
| 50 | * contributors may be used to endorse or promote products derived |
| 51 | * from this software without specific prior written permission. |
| 52 | * |
| 53 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 54 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 55 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 56 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 57 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 58 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 59 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 60 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 61 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 62 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 63 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 64 | * |
| 65 | *****************************************************************************/ |
| 66 | #include <linux/ieee80211.h> |
| 67 | #include <linux/etherdevice.h> |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 68 | #include <linux/tcp.h> |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 69 | #include <net/ip.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 70 | |
| 71 | #include "iwl-trans.h" |
| 72 | #include "iwl-eeprom-parse.h" |
| 73 | #include "mvm.h" |
| 74 | #include "sta.h" |
Golan Ben-Ami | 2f89a5d | 2015-10-27 19:17:14 +0200 | [diff] [blame] | 75 | #include "fw-dbg.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 76 | |
Emmanuel Grumbach | 4203263 | 2015-04-15 12:43:46 +0300 | [diff] [blame] | 77 | static void |
| 78 | iwl_mvm_bar_check_trigger(struct iwl_mvm *mvm, const u8 *addr, |
| 79 | u16 tid, u16 ssn) |
| 80 | { |
| 81 | struct iwl_fw_dbg_trigger_tlv *trig; |
| 82 | struct iwl_fw_dbg_trigger_ba *ba_trig; |
| 83 | |
| 84 | if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA)) |
| 85 | return; |
| 86 | |
| 87 | trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA); |
| 88 | ba_trig = (void *)trig->data; |
| 89 | |
| 90 | if (!iwl_fw_dbg_trigger_check_stop(mvm, NULL, trig)) |
| 91 | return; |
| 92 | |
| 93 | if (!(le16_to_cpu(ba_trig->tx_bar) & BIT(tid))) |
| 94 | return; |
| 95 | |
| 96 | iwl_mvm_fw_dbg_collect_trig(mvm, trig, |
| 97 | "BAR sent to %pM, tid %d, ssn %d", |
| 98 | addr, tid, ssn); |
| 99 | } |
| 100 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 101 | /* |
| 102 | * Sets most of the Tx cmd's fields |
| 103 | */ |
Arik Nemtsov | 6ce73e6 | 2014-09-11 13:00:19 +0300 | [diff] [blame] | 104 | void iwl_mvm_set_tx_cmd(struct iwl_mvm *mvm, struct sk_buff *skb, |
| 105 | struct iwl_tx_cmd *tx_cmd, |
| 106 | struct ieee80211_tx_info *info, u8 sta_id) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 107 | { |
| 108 | struct ieee80211_hdr *hdr = (void *)skb->data; |
| 109 | __le16 fc = hdr->frame_control; |
| 110 | u32 tx_flags = le32_to_cpu(tx_cmd->tx_flags); |
| 111 | u32 len = skb->len + FCS_LEN; |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 112 | u8 ac; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 113 | |
| 114 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) |
| 115 | tx_flags |= TX_CMD_FLG_ACK; |
| 116 | else |
| 117 | tx_flags &= ~TX_CMD_FLG_ACK; |
| 118 | |
| 119 | if (ieee80211_is_probe_resp(fc)) |
| 120 | tx_flags |= TX_CMD_FLG_TSF; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 121 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 122 | if (ieee80211_has_morefrags(fc)) |
| 123 | tx_flags |= TX_CMD_FLG_MORE_FRAG; |
| 124 | |
| 125 | if (ieee80211_is_data_qos(fc)) { |
| 126 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
| 127 | tx_cmd->tid_tspec = qc[0] & 0xf; |
| 128 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL; |
Sara Sharon | d8fe484 | 2016-03-09 10:12:45 +0200 | [diff] [blame] | 129 | if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT) |
| 130 | tx_cmd->offload_assist |= |
| 131 | cpu_to_le16(BIT(TX_CMD_OFFLD_AMSDU)); |
Eyal Shapira | 9b3b43d | 2014-12-31 18:34:56 +0200 | [diff] [blame] | 132 | } else if (ieee80211_is_back_req(fc)) { |
| 133 | struct ieee80211_bar *bar = (void *)skb->data; |
| 134 | u16 control = le16_to_cpu(bar->control); |
Emmanuel Grumbach | 4203263 | 2015-04-15 12:43:46 +0300 | [diff] [blame] | 135 | u16 ssn = le16_to_cpu(bar->start_seq_num); |
Eyal Shapira | 9b3b43d | 2014-12-31 18:34:56 +0200 | [diff] [blame] | 136 | |
| 137 | tx_flags |= TX_CMD_FLG_ACK | TX_CMD_FLG_BAR; |
| 138 | tx_cmd->tid_tspec = (control & |
| 139 | IEEE80211_BAR_CTRL_TID_INFO_MASK) >> |
| 140 | IEEE80211_BAR_CTRL_TID_INFO_SHIFT; |
| 141 | WARN_ON_ONCE(tx_cmd->tid_tspec >= IWL_MAX_TID_COUNT); |
Emmanuel Grumbach | 4203263 | 2015-04-15 12:43:46 +0300 | [diff] [blame] | 142 | iwl_mvm_bar_check_trigger(mvm, bar->ra, tx_cmd->tid_tspec, |
| 143 | ssn); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 144 | } else { |
| 145 | tx_cmd->tid_tspec = IWL_TID_NON_QOS; |
| 146 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) |
| 147 | tx_flags |= TX_CMD_FLG_SEQ_CTL; |
| 148 | else |
| 149 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL; |
| 150 | } |
| 151 | |
Eyal Shapira | a9dc506 | 2014-12-31 17:58:23 +0200 | [diff] [blame] | 152 | /* Default to 0 (BE) when tid_spec is set to IWL_TID_NON_QOS */ |
| 153 | if (tx_cmd->tid_tspec < IWL_MAX_TID_COUNT) |
| 154 | ac = tid_to_mac80211_ac[tx_cmd->tid_tspec]; |
| 155 | else |
| 156 | ac = tid_to_mac80211_ac[0]; |
| 157 | |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 158 | tx_flags |= iwl_mvm_bt_coex_tx_prio(mvm, hdr, info, ac) << |
| 159 | TX_CMD_FLG_BT_PRIO_POS; |
| 160 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 161 | if (ieee80211_is_mgmt(fc)) { |
| 162 | if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc)) |
Avri Altman | b084a35 | 2015-07-12 09:10:05 +0300 | [diff] [blame] | 163 | tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_ASSOC); |
| 164 | else if (ieee80211_is_action(fc)) |
| 165 | tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_NONE); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 166 | else |
Avri Altman | b084a35 | 2015-07-12 09:10:05 +0300 | [diff] [blame] | 167 | tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_MGMT); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 168 | |
| 169 | /* The spec allows Action frames in A-MPDU, we don't support |
| 170 | * it |
| 171 | */ |
| 172 | WARN_ON_ONCE(info->flags & IEEE80211_TX_CTL_AMPDU); |
Johannes Berg | 63f7535 | 2014-01-31 14:56:18 +0100 | [diff] [blame] | 173 | } else if (info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO) { |
Avri Altman | b084a35 | 2015-07-12 09:10:05 +0300 | [diff] [blame] | 174 | tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_MGMT); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 175 | } else { |
Avri Altman | b084a35 | 2015-07-12 09:10:05 +0300 | [diff] [blame] | 176 | tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_NONE); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 177 | } |
| 178 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 179 | if (ieee80211_is_data(fc) && len > mvm->rts_threshold && |
| 180 | !is_multicast_ether_addr(ieee80211_get_DA(hdr))) |
| 181 | tx_flags |= TX_CMD_FLG_PROT_REQUIRE; |
| 182 | |
Johannes Berg | 859d914 | 2015-06-01 17:11:11 +0200 | [diff] [blame] | 183 | if (fw_has_capa(&mvm->fw->ucode_capa, |
| 184 | IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT) && |
Andrei Otcheretianski | f1daa00 | 2014-07-01 12:54:25 +0300 | [diff] [blame] | 185 | ieee80211_action_contains_tpc(skb)) |
| 186 | tx_flags |= TX_CMD_FLG_WRITE_TX_POWER; |
| 187 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 188 | tx_cmd->tx_flags = cpu_to_le32(tx_flags); |
| 189 | /* Total # bytes to be transmitted */ |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 190 | tx_cmd->len = cpu_to_le16((u16)skb->len + |
| 191 | (uintptr_t)info->driver_data[0]); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 192 | tx_cmd->life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE); |
| 193 | tx_cmd->sta_id = sta_id; |
Sara Sharon | d8fe484 | 2016-03-09 10:12:45 +0200 | [diff] [blame] | 194 | |
| 195 | /* padding is inserted later in transport */ |
| 196 | if (ieee80211_hdrlen(fc) % 4 && |
| 197 | !(tx_cmd->offload_assist & cpu_to_le16(BIT(TX_CMD_OFFLD_AMSDU)))) |
| 198 | tx_cmd->offload_assist |= cpu_to_le16(BIT(TX_CMD_OFFLD_PAD)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /* |
| 202 | * Sets the fields in the Tx cmd that are rate related |
| 203 | */ |
Arik Nemtsov | 6ce73e6 | 2014-09-11 13:00:19 +0300 | [diff] [blame] | 204 | void iwl_mvm_set_tx_cmd_rate(struct iwl_mvm *mvm, struct iwl_tx_cmd *tx_cmd, |
| 205 | struct ieee80211_tx_info *info, |
| 206 | struct ieee80211_sta *sta, __le16 fc) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 207 | { |
| 208 | u32 rate_flags; |
| 209 | int rate_idx; |
| 210 | u8 rate_plcp; |
| 211 | |
| 212 | /* Set retry limit on RTS packets */ |
| 213 | tx_cmd->rts_retry_limit = IWL_RTS_DFAULT_RETRY_LIMIT; |
| 214 | |
| 215 | /* Set retry limit on DATA packets and Probe Responses*/ |
| 216 | if (ieee80211_is_probe_resp(fc)) { |
| 217 | tx_cmd->data_retry_limit = IWL_MGMT_DFAULT_RETRY_LIMIT; |
| 218 | tx_cmd->rts_retry_limit = |
| 219 | min(tx_cmd->data_retry_limit, tx_cmd->rts_retry_limit); |
| 220 | } else if (ieee80211_is_back_req(fc)) { |
| 221 | tx_cmd->data_retry_limit = IWL_BAR_DFAULT_RETRY_LIMIT; |
| 222 | } else { |
| 223 | tx_cmd->data_retry_limit = IWL_DEFAULT_TX_RETRY; |
| 224 | } |
| 225 | |
| 226 | /* |
Eliad Peller | e89044d | 2013-07-16 17:33:26 +0300 | [diff] [blame] | 227 | * for data packets, rate info comes from the table inside the fw. This |
Emmanuel Grumbach | 1ffde69 | 2014-10-20 08:29:55 +0300 | [diff] [blame] | 228 | * table is controlled by LINK_QUALITY commands |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 229 | */ |
| 230 | |
Emmanuel Grumbach | 1ffde69 | 2014-10-20 08:29:55 +0300 | [diff] [blame] | 231 | if (ieee80211_is_data(fc) && sta) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 232 | tx_cmd->initial_rate_index = 0; |
| 233 | tx_cmd->tx_flags |= cpu_to_le32(TX_CMD_FLG_STA_RATE); |
| 234 | return; |
| 235 | } else if (ieee80211_is_back_req(fc)) { |
Emmanuel Grumbach | 2edc6ec | 2013-06-02 19:49:15 +0300 | [diff] [blame] | 236 | tx_cmd->tx_flags |= |
| 237 | cpu_to_le32(TX_CMD_FLG_ACK | TX_CMD_FLG_BAR); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /* HT rate doesn't make sense for a non data frame */ |
| 241 | WARN_ONCE(info->control.rates[0].flags & IEEE80211_TX_RC_MCS, |
Johannes Berg | f85e9d1 | 2014-10-08 09:57:29 +0200 | [diff] [blame] | 242 | "Got an HT rate (flags:0x%x/mcs:%d) for a non data frame (fc:0x%x)\n", |
| 243 | info->control.rates[0].flags, |
| 244 | info->control.rates[0].idx, |
| 245 | le16_to_cpu(fc)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 246 | |
| 247 | rate_idx = info->control.rates[0].idx; |
| 248 | /* if the rate isn't a well known legacy rate, take the lowest one */ |
| 249 | if (rate_idx < 0 || rate_idx > IWL_RATE_COUNT_LEGACY) |
| 250 | rate_idx = rate_lowest_index( |
| 251 | &mvm->nvm_data->bands[info->band], sta); |
| 252 | |
| 253 | /* For 5 GHZ band, remap mac80211 rate indices into driver indices */ |
| 254 | if (info->band == IEEE80211_BAND_5GHZ) |
| 255 | rate_idx += IWL_FIRST_OFDM_RATE; |
| 256 | |
| 257 | /* For 2.4 GHZ band, check that there is no need to remap */ |
| 258 | BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0); |
| 259 | |
| 260 | /* Get PLCP rate for tx_cmd->rate_n_flags */ |
| 261 | rate_plcp = iwl_mvm_mac80211_idx_to_hwrate(rate_idx); |
| 262 | |
| 263 | mvm->mgmt_last_antenna_idx = |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 264 | iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 265 | mvm->mgmt_last_antenna_idx); |
Emmanuel Grumbach | 34c8b24 | 2014-05-28 21:53:39 +0300 | [diff] [blame] | 266 | |
| 267 | if (info->band == IEEE80211_BAND_2GHZ && |
| 268 | !iwl_mvm_bt_coex_is_shared_ant_avail(mvm)) |
Emmanuel Grumbach | 923a8c1 | 2015-05-31 21:44:22 +0300 | [diff] [blame] | 269 | rate_flags = mvm->cfg->non_shared_ant << RATE_MCS_ANT_POS; |
Emmanuel Grumbach | 34c8b24 | 2014-05-28 21:53:39 +0300 | [diff] [blame] | 270 | else |
| 271 | rate_flags = |
| 272 | BIT(mvm->mgmt_last_antenna_idx) << RATE_MCS_ANT_POS; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 273 | |
| 274 | /* Set CCK flag as needed */ |
| 275 | if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE)) |
| 276 | rate_flags |= RATE_MCS_CCK_MSK; |
| 277 | |
| 278 | /* Set the rate in the TX cmd */ |
| 279 | tx_cmd->rate_n_flags = cpu_to_le32((u32)rate_plcp | rate_flags); |
| 280 | } |
| 281 | |
| 282 | /* |
| 283 | * Sets the fields in the Tx cmd that are crypto related |
| 284 | */ |
Johannes Berg | ca8c0f4 | 2015-04-20 17:54:54 +0200 | [diff] [blame] | 285 | static void iwl_mvm_set_tx_cmd_crypto(struct iwl_mvm *mvm, |
| 286 | struct ieee80211_tx_info *info, |
| 287 | struct iwl_tx_cmd *tx_cmd, |
| 288 | struct sk_buff *skb_frag, |
| 289 | int hdrlen) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 290 | { |
| 291 | struct ieee80211_key_conf *keyconf = info->control.hw_key; |
Johannes Berg | ca8c0f4 | 2015-04-20 17:54:54 +0200 | [diff] [blame] | 292 | u8 *crypto_hdr = skb_frag->data + hdrlen; |
| 293 | u64 pn; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 294 | |
| 295 | switch (keyconf->cipher) { |
| 296 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | ca8c0f4 | 2015-04-20 17:54:54 +0200 | [diff] [blame] | 297 | case WLAN_CIPHER_SUITE_CCMP_256: |
| 298 | iwl_mvm_set_tx_cmd_ccmp(info, tx_cmd); |
| 299 | pn = atomic64_inc_return(&keyconf->tx_pn); |
| 300 | crypto_hdr[0] = pn; |
| 301 | crypto_hdr[2] = 0; |
| 302 | crypto_hdr[3] = 0x20 | (keyconf->keyidx << 6); |
| 303 | crypto_hdr[1] = pn >> 8; |
| 304 | crypto_hdr[4] = pn >> 16; |
| 305 | crypto_hdr[5] = pn >> 24; |
| 306 | crypto_hdr[6] = pn >> 32; |
| 307 | crypto_hdr[7] = pn >> 40; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 308 | break; |
| 309 | |
| 310 | case WLAN_CIPHER_SUITE_TKIP: |
| 311 | tx_cmd->sec_ctl = TX_CMD_SEC_TKIP; |
Eliad Peller | 1ad4f63 | 2016-02-14 13:56:36 +0200 | [diff] [blame] | 312 | pn = atomic64_inc_return(&keyconf->tx_pn); |
| 313 | ieee80211_tkip_add_iv(crypto_hdr, keyconf, pn); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 314 | ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key); |
| 315 | break; |
| 316 | |
| 317 | case WLAN_CIPHER_SUITE_WEP104: |
| 318 | tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128; |
| 319 | /* fall through */ |
| 320 | case WLAN_CIPHER_SUITE_WEP40: |
| 321 | tx_cmd->sec_ctl |= TX_CMD_SEC_WEP | |
| 322 | ((keyconf->keyidx << TX_CMD_SEC_WEP_KEY_IDX_POS) & |
| 323 | TX_CMD_SEC_WEP_KEY_IDX_MSK); |
| 324 | |
| 325 | memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen); |
| 326 | break; |
| 327 | default: |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 328 | tx_cmd->sec_ctl |= TX_CMD_SEC_EXT; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
| 332 | /* |
| 333 | * Allocates and sets the Tx cmd the driver data pointers in the skb |
| 334 | */ |
| 335 | static struct iwl_device_cmd * |
| 336 | iwl_mvm_set_tx_params(struct iwl_mvm *mvm, struct sk_buff *skb, |
Johannes Berg | ca8c0f4 | 2015-04-20 17:54:54 +0200 | [diff] [blame] | 337 | int hdrlen, struct ieee80211_sta *sta, u8 sta_id) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 338 | { |
| 339 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 340 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 341 | struct iwl_device_cmd *dev_cmd; |
| 342 | struct iwl_tx_cmd *tx_cmd; |
| 343 | |
| 344 | dev_cmd = iwl_trans_alloc_tx_cmd(mvm->trans); |
| 345 | |
| 346 | if (unlikely(!dev_cmd)) |
| 347 | return NULL; |
| 348 | |
| 349 | memset(dev_cmd, 0, sizeof(*dev_cmd)); |
Emmanuel Grumbach | 3961a61 | 2013-10-22 11:27:55 +0300 | [diff] [blame] | 350 | dev_cmd->hdr.cmd = TX_CMD; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 351 | tx_cmd = (struct iwl_tx_cmd *)dev_cmd->payload; |
| 352 | |
| 353 | if (info->control.hw_key) |
Johannes Berg | ca8c0f4 | 2015-04-20 17:54:54 +0200 | [diff] [blame] | 354 | iwl_mvm_set_tx_cmd_crypto(mvm, info, tx_cmd, skb, hdrlen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 355 | |
| 356 | iwl_mvm_set_tx_cmd(mvm, skb, tx_cmd, info, sta_id); |
| 357 | |
| 358 | iwl_mvm_set_tx_cmd_rate(mvm, tx_cmd, info, sta, hdr->frame_control); |
| 359 | |
| 360 | memset(&info->status, 0, sizeof(info->status)); |
Emmanuel Grumbach | 3f73b8c | 2015-10-26 15:39:22 +0200 | [diff] [blame] | 361 | memset(info->driver_data, 0, sizeof(info->driver_data)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 362 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 363 | info->driver_data[1] = dev_cmd; |
| 364 | |
| 365 | return dev_cmd; |
| 366 | } |
| 367 | |
| 368 | int iwl_mvm_tx_skb_non_sta(struct iwl_mvm *mvm, struct sk_buff *skb) |
| 369 | { |
| 370 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 371 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 372 | struct iwl_device_cmd *dev_cmd; |
| 373 | struct iwl_tx_cmd *tx_cmd; |
| 374 | u8 sta_id; |
Johannes Berg | ca8c0f4 | 2015-04-20 17:54:54 +0200 | [diff] [blame] | 375 | int hdrlen = ieee80211_hdrlen(hdr->frame_control); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 376 | |
| 377 | if (WARN_ON_ONCE(info->flags & IEEE80211_TX_CTL_AMPDU)) |
| 378 | return -1; |
| 379 | |
| 380 | if (WARN_ON_ONCE(info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM && |
| 381 | (!info->control.vif || |
| 382 | info->hw_queue != info->control.vif->cab_queue))) |
| 383 | return -1; |
| 384 | |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 385 | /* This holds the amsdu headers length */ |
| 386 | info->driver_data[0] = (void *)(uintptr_t)0; |
| 387 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 388 | /* |
Ariej Marjieh | 7da91b0 | 2014-07-07 12:09:40 +0300 | [diff] [blame] | 389 | * IWL_MVM_OFFCHANNEL_QUEUE is used for ROC packets that can be used |
| 390 | * in 2 different types of vifs, P2P & STATION. P2P uses the offchannel |
| 391 | * queue. STATION (HS2.0) uses the auxiliary context of the FW, |
| 392 | * and hence needs to be sent on the aux queue |
| 393 | */ |
| 394 | if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE && |
| 395 | info->control.vif->type == NL80211_IFTYPE_STATION) |
| 396 | IEEE80211_SKB_CB(skb)->hw_queue = mvm->aux_queue; |
| 397 | |
| 398 | /* |
Ilan Peer | d0ab08d | 2015-06-24 09:23:01 +0300 | [diff] [blame] | 399 | * If the interface on which the frame is sent is the P2P_DEVICE |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 400 | * or an AP/GO interface use the broadcast station associated |
Ilan Peer | d0ab08d | 2015-06-24 09:23:01 +0300 | [diff] [blame] | 401 | * with it; otherwise if the interface is a managed interface |
| 402 | * use the AP station associated with it for multicast traffic |
| 403 | * (this is not possible for unicast packets as a TLDS discovery |
| 404 | * response are sent without a station entry); otherwise use the |
| 405 | * AUX station. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 406 | */ |
Ilan Peer | d0ab08d | 2015-06-24 09:23:01 +0300 | [diff] [blame] | 407 | sta_id = mvm->aux_sta.sta_id; |
| 408 | if (info->control.vif) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 409 | struct iwl_mvm_vif *mvmvif = |
| 410 | iwl_mvm_vif_from_mac80211(info->control.vif); |
Ilan Peer | d0ab08d | 2015-06-24 09:23:01 +0300 | [diff] [blame] | 411 | |
| 412 | if (info->control.vif->type == NL80211_IFTYPE_P2P_DEVICE || |
| 413 | info->control.vif->type == NL80211_IFTYPE_AP) |
| 414 | sta_id = mvmvif->bcast_sta.sta_id; |
| 415 | else if (info->control.vif->type == NL80211_IFTYPE_STATION && |
| 416 | is_multicast_ether_addr(hdr->addr1)) { |
| 417 | u8 ap_sta_id = ACCESS_ONCE(mvmvif->ap_sta_id); |
| 418 | |
| 419 | if (ap_sta_id != IWL_MVM_STATION_COUNT) |
| 420 | sta_id = ap_sta_id; |
| 421 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | IWL_DEBUG_TX(mvm, "station Id %d, queue=%d\n", sta_id, info->hw_queue); |
| 425 | |
Johannes Berg | ca8c0f4 | 2015-04-20 17:54:54 +0200 | [diff] [blame] | 426 | dev_cmd = iwl_mvm_set_tx_params(mvm, skb, hdrlen, NULL, sta_id); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 427 | if (!dev_cmd) |
| 428 | return -1; |
| 429 | |
| 430 | /* From now on, we cannot access info->control */ |
| 431 | tx_cmd = (struct iwl_tx_cmd *)dev_cmd->payload; |
| 432 | |
| 433 | /* Copy MAC header from skb into command buffer */ |
Johannes Berg | ca8c0f4 | 2015-04-20 17:54:54 +0200 | [diff] [blame] | 434 | memcpy(tx_cmd->hdr, hdr, hdrlen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 435 | |
| 436 | if (iwl_trans_tx(mvm->trans, skb, dev_cmd, info->hw_queue)) { |
| 437 | iwl_trans_free_tx_cmd(mvm->trans, dev_cmd); |
| 438 | return -1; |
| 439 | } |
| 440 | |
Liad Kaufman | fb896c4 | 2016-02-14 15:32:58 +0200 | [diff] [blame] | 441 | /* |
| 442 | * Increase the pending frames counter, so that later when a reply comes |
| 443 | * in and the counter is decreased - we don't start getting negative |
| 444 | * values. |
| 445 | * Note that we don't need to make sure it isn't agg'd, since we're |
| 446 | * TXing non-sta |
| 447 | */ |
| 448 | atomic_inc(&mvm->pending_frames[sta_id]); |
| 449 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 450 | return 0; |
| 451 | } |
| 452 | |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 453 | #ifdef CONFIG_INET |
| 454 | static int iwl_mvm_tx_tso(struct iwl_mvm *mvm, struct sk_buff *skb, |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 455 | struct ieee80211_sta *sta, |
| 456 | struct sk_buff_head *mpdus_skb) |
| 457 | { |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame] | 458 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 459 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 460 | struct ieee80211_hdr *hdr = (void *)skb->data; |
| 461 | unsigned int mss = skb_shinfo(skb)->gso_size; |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 462 | struct sk_buff *tmp, *next; |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 463 | char cb[sizeof(skb->cb)]; |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame] | 464 | unsigned int num_subframes, tcp_payload_len, subf_len, max_amsdu_len; |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 465 | bool ipv4 = (skb->protocol == htons(ETH_P_IP)); |
| 466 | u16 ip_base_id = ipv4 ? ntohs(ip_hdr(skb)->id) : 0; |
| 467 | u16 amsdu_add, snap_ip_tcp, pad, i = 0; |
Emmanuel Grumbach | 9e7dce2 | 2015-10-26 16:14:06 +0200 | [diff] [blame] | 468 | unsigned int dbg_max_amsdu_len; |
Emmanuel Grumbach | 50b0213 | 2015-11-11 11:37:02 +0200 | [diff] [blame] | 469 | u8 *qc, tid, txf; |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 470 | |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 471 | snap_ip_tcp = 8 + skb_transport_header(skb) - skb_network_header(skb) + |
| 472 | tcp_hdrlen(skb); |
| 473 | |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame] | 474 | qc = ieee80211_get_qos_ctl(hdr); |
| 475 | tid = *qc & IEEE80211_QOS_CTL_TID_MASK; |
| 476 | if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) |
| 477 | return -EINVAL; |
| 478 | |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 479 | if (!sta->max_amsdu_len || |
Emmanuel Grumbach | 04e3a5d | 2015-10-28 09:47:41 +0200 | [diff] [blame] | 480 | !ieee80211_is_data_qos(hdr->frame_control) || |
| 481 | !mvmsta->tlc_amsdu) { |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 482 | num_subframes = 1; |
| 483 | pad = 0; |
| 484 | goto segment; |
| 485 | } |
| 486 | |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame] | 487 | /* |
| 488 | * No need to lock amsdu_in_ampdu_allowed since it can't be modified |
| 489 | * during an BA session. |
| 490 | */ |
| 491 | if (info->flags & IEEE80211_TX_CTL_AMPDU && |
| 492 | !mvmsta->tid_data[tid].amsdu_in_ampdu_allowed) { |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 493 | num_subframes = 1; |
| 494 | pad = 0; |
| 495 | goto segment; |
| 496 | } |
| 497 | |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame] | 498 | max_amsdu_len = sta->max_amsdu_len; |
Emmanuel Grumbach | 9e7dce2 | 2015-10-26 16:14:06 +0200 | [diff] [blame] | 499 | dbg_max_amsdu_len = ACCESS_ONCE(mvm->max_amsdu_len); |
Emmanuel Grumbach | 50b0213 | 2015-11-11 11:37:02 +0200 | [diff] [blame] | 500 | |
| 501 | /* the Tx FIFO to which this A-MSDU will be routed */ |
| 502 | txf = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]]; |
| 503 | |
| 504 | /* |
| 505 | * Don't send an AMSDU that will be longer than the TXF. |
| 506 | * Add a security margin of 256 for the TX command + headers. |
| 507 | * We also want to have the start of the next packet inside the |
| 508 | * fifo to be able to send bursts. |
| 509 | */ |
| 510 | max_amsdu_len = min_t(unsigned int, max_amsdu_len, |
| 511 | mvm->shared_mem_cfg.txfifo_size[txf] - 256); |
| 512 | |
Emmanuel Grumbach | 9e7dce2 | 2015-10-26 16:14:06 +0200 | [diff] [blame] | 513 | if (dbg_max_amsdu_len) |
| 514 | max_amsdu_len = min_t(unsigned int, max_amsdu_len, |
| 515 | dbg_max_amsdu_len); |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame] | 516 | |
| 517 | /* |
| 518 | * Limit A-MSDU in A-MPDU to 4095 bytes when VHT is not |
| 519 | * supported. This is a spec requirement (IEEE 802.11-2015 |
| 520 | * section 8.7.3 NOTE 3). |
| 521 | */ |
| 522 | if (info->flags & IEEE80211_TX_CTL_AMPDU && |
| 523 | !sta->vht_cap.vht_supported) |
| 524 | max_amsdu_len = min_t(unsigned int, max_amsdu_len, 4095); |
| 525 | |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 526 | /* Sub frame header + SNAP + IP header + TCP header + MSS */ |
| 527 | subf_len = sizeof(struct ethhdr) + snap_ip_tcp + mss; |
| 528 | pad = (4 - subf_len) & 0x3; |
| 529 | |
| 530 | /* |
| 531 | * If we have N subframes in the A-MSDU, then the A-MSDU's size is |
| 532 | * N * subf_len + (N - 1) * pad. |
| 533 | */ |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame] | 534 | num_subframes = (max_amsdu_len + pad) / (subf_len + pad); |
| 535 | if (num_subframes > 1) |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 536 | *qc |= IEEE80211_QOS_CTL_A_MSDU_PRESENT; |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 537 | |
| 538 | tcp_payload_len = skb_tail_pointer(skb) - skb_transport_header(skb) - |
| 539 | tcp_hdrlen(skb) + skb->data_len; |
| 540 | |
| 541 | /* |
| 542 | * Make sure we have enough TBs for the A-MSDU: |
| 543 | * 2 for each subframe |
| 544 | * 1 more for each fragment |
| 545 | * 1 more for the potential data in the header |
| 546 | */ |
| 547 | num_subframes = |
| 548 | min_t(unsigned int, num_subframes, |
| 549 | (mvm->trans->max_skb_frags - 1 - |
| 550 | skb_shinfo(skb)->nr_frags) / 2); |
| 551 | |
| 552 | /* This skb fits in one single A-MSDU */ |
| 553 | if (num_subframes * mss >= tcp_payload_len) { |
| 554 | /* |
| 555 | * Compute the length of all the data added for the A-MSDU. |
| 556 | * This will be used to compute the length to write in the TX |
| 557 | * command. We have: SNAP + IP + TCP for n -1 subframes and |
| 558 | * ETH header for n subframes. Note that the original skb |
| 559 | * already had one set of SNAP / IP / TCP headers. |
| 560 | */ |
| 561 | num_subframes = DIV_ROUND_UP(tcp_payload_len, mss); |
| 562 | info = IEEE80211_SKB_CB(skb); |
| 563 | amsdu_add = num_subframes * sizeof(struct ethhdr) + |
| 564 | (num_subframes - 1) * (snap_ip_tcp + pad); |
| 565 | /* This holds the amsdu headers length */ |
| 566 | info->driver_data[0] = (void *)(uintptr_t)amsdu_add; |
| 567 | |
| 568 | __skb_queue_tail(mpdus_skb, skb); |
| 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | /* |
| 573 | * Trick the segmentation function to make it |
| 574 | * create SKBs that can fit into one A-MSDU. |
| 575 | */ |
| 576 | segment: |
| 577 | skb_shinfo(skb)->gso_size = num_subframes * mss; |
| 578 | memcpy(cb, skb->cb, sizeof(cb)); |
| 579 | |
| 580 | next = skb_gso_segment(skb, NETIF_F_CSUM_MASK | NETIF_F_SG); |
| 581 | skb_shinfo(skb)->gso_size = mss; |
| 582 | if (WARN_ON_ONCE(IS_ERR(next))) |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 583 | return -EINVAL; |
| 584 | else if (next) |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 585 | consume_skb(skb); |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 586 | |
| 587 | while (next) { |
| 588 | tmp = next; |
| 589 | next = tmp->next; |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 590 | |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 591 | memcpy(tmp->cb, cb, sizeof(tmp->cb)); |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 592 | /* |
| 593 | * Compute the length of all the data added for the A-MSDU. |
| 594 | * This will be used to compute the length to write in the TX |
| 595 | * command. We have: SNAP + IP + TCP for n -1 subframes and |
| 596 | * ETH header for n subframes. |
| 597 | */ |
| 598 | tcp_payload_len = skb_tail_pointer(tmp) - |
| 599 | skb_transport_header(tmp) - |
| 600 | tcp_hdrlen(tmp) + tmp->data_len; |
| 601 | |
| 602 | if (ipv4) |
| 603 | ip_hdr(tmp)->id = htons(ip_base_id + i * num_subframes); |
| 604 | |
| 605 | if (tcp_payload_len > mss) { |
| 606 | num_subframes = DIV_ROUND_UP(tcp_payload_len, mss); |
| 607 | info = IEEE80211_SKB_CB(tmp); |
| 608 | amsdu_add = num_subframes * sizeof(struct ethhdr) + |
| 609 | (num_subframes - 1) * (snap_ip_tcp + pad); |
| 610 | info->driver_data[0] = (void *)(uintptr_t)amsdu_add; |
| 611 | skb_shinfo(tmp)->gso_size = mss; |
| 612 | } else { |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame] | 613 | qc = ieee80211_get_qos_ctl((void *)tmp->data); |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 614 | |
| 615 | if (ipv4) |
| 616 | ip_send_check(ip_hdr(tmp)); |
| 617 | *qc &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT; |
| 618 | skb_shinfo(tmp)->gso_size = 0; |
| 619 | } |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 620 | |
| 621 | tmp->prev = NULL; |
| 622 | tmp->next = NULL; |
| 623 | |
| 624 | __skb_queue_tail(mpdus_skb, tmp); |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 625 | i++; |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | return 0; |
| 629 | } |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 630 | #else /* CONFIG_INET */ |
| 631 | static int iwl_mvm_tx_tso(struct iwl_mvm *mvm, struct sk_buff *skb, |
| 632 | struct ieee80211_sta *sta, |
| 633 | struct sk_buff_head *mpdus_skb) |
| 634 | { |
| 635 | /* Impossible to get TSO with CONFIG_INET */ |
| 636 | WARN_ON(1); |
| 637 | |
| 638 | return -1; |
| 639 | } |
| 640 | #endif |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 641 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame^] | 642 | static void iwl_mvm_tx_add_stream(struct iwl_mvm *mvm, |
| 643 | struct iwl_mvm_sta *mvm_sta, u8 tid, |
| 644 | struct sk_buff *skb) |
| 645 | { |
| 646 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 647 | u8 mac_queue = info->hw_queue; |
| 648 | struct sk_buff_head *deferred_tx_frames; |
| 649 | |
| 650 | lockdep_assert_held(&mvm_sta->lock); |
| 651 | |
| 652 | mvm_sta->deferred_traffic_tid_map |= BIT(tid); |
| 653 | set_bit(mvm_sta->sta_id, mvm->sta_deferred_frames); |
| 654 | |
| 655 | deferred_tx_frames = &mvm_sta->tid_data[tid].deferred_tx_frames; |
| 656 | |
| 657 | skb_queue_tail(deferred_tx_frames, skb); |
| 658 | |
| 659 | /* |
| 660 | * The first deferred frame should've stopped the MAC queues, so we |
| 661 | * should never get a second deferred frame for the RA/TID. |
| 662 | */ |
| 663 | if (!WARN(skb_queue_len(deferred_tx_frames) != 1, |
| 664 | "RATID %d/%d has %d deferred frames\n", mvm_sta->sta_id, tid, |
| 665 | skb_queue_len(deferred_tx_frames))) { |
| 666 | iwl_mvm_stop_mac_queues(mvm, BIT(mac_queue)); |
| 667 | schedule_work(&mvm->add_stream_wk); |
| 668 | } |
| 669 | } |
| 670 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 671 | /* |
| 672 | * Sets the fields in the Tx cmd that are crypto related |
| 673 | */ |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 674 | static int iwl_mvm_tx_mpdu(struct iwl_mvm *mvm, struct sk_buff *skb, |
| 675 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 676 | { |
| 677 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 678 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 679 | struct iwl_mvm_sta *mvmsta; |
| 680 | struct iwl_device_cmd *dev_cmd; |
| 681 | struct iwl_tx_cmd *tx_cmd; |
| 682 | __le16 fc; |
| 683 | u16 seq_number = 0; |
| 684 | u8 tid = IWL_MAX_TID_COUNT; |
| 685 | u8 txq_id = info->hw_queue; |
Johannes Berg | 7ec5471 | 2016-03-16 09:29:48 +0100 | [diff] [blame] | 686 | bool is_ampdu = false; |
Johannes Berg | ca8c0f4 | 2015-04-20 17:54:54 +0200 | [diff] [blame] | 687 | int hdrlen; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 688 | |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 689 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 690 | fc = hdr->frame_control; |
Johannes Berg | ca8c0f4 | 2015-04-20 17:54:54 +0200 | [diff] [blame] | 691 | hdrlen = ieee80211_hdrlen(fc); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 692 | |
| 693 | if (WARN_ON_ONCE(!mvmsta)) |
| 694 | return -1; |
| 695 | |
Emmanuel Grumbach | 881acd8 | 2013-03-19 16:16:00 +0200 | [diff] [blame] | 696 | if (WARN_ON_ONCE(mvmsta->sta_id == IWL_MVM_STATION_COUNT)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 697 | return -1; |
| 698 | |
Johannes Berg | ca8c0f4 | 2015-04-20 17:54:54 +0200 | [diff] [blame] | 699 | dev_cmd = iwl_mvm_set_tx_params(mvm, skb, hdrlen, sta, mvmsta->sta_id); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 700 | if (!dev_cmd) |
| 701 | goto drop; |
| 702 | |
| 703 | tx_cmd = (struct iwl_tx_cmd *)dev_cmd->payload; |
| 704 | /* From now on, we cannot access info->control */ |
| 705 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 706 | /* |
| 707 | * we handle that entirely ourselves -- for uAPSD the firmware |
| 708 | * will always send a notification, and for PS-Poll responses |
| 709 | * we'll notify mac80211 when getting frame status |
| 710 | */ |
| 711 | info->flags &= ~IEEE80211_TX_STATUS_EOSP; |
| 712 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 713 | spin_lock(&mvmsta->lock); |
| 714 | |
| 715 | if (ieee80211_is_data_qos(fc) && !ieee80211_is_qos_nullfunc(fc)) { |
| 716 | u8 *qc = NULL; |
| 717 | qc = ieee80211_get_qos_ctl(hdr); |
| 718 | tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; |
| 719 | if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) |
| 720 | goto drop_unlock_sta; |
| 721 | |
| 722 | seq_number = mvmsta->tid_data[tid].seq_number; |
| 723 | seq_number &= IEEE80211_SCTL_SEQ; |
| 724 | hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
| 725 | hdr->seq_ctrl |= cpu_to_le16(seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 726 | is_ampdu = info->flags & IEEE80211_TX_CTL_AMPDU; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame^] | 727 | } else if (iwl_mvm_is_dqa_supported(mvm) && |
| 728 | (ieee80211_is_qos_nullfunc(fc) || |
| 729 | ieee80211_is_nullfunc(fc))) { |
| 730 | /* |
| 731 | * nullfunc frames should go to the MGMT queue regardless of QOS |
| 732 | */ |
| 733 | tid = IWL_MAX_TID_COUNT; |
| 734 | txq_id = mvmsta->tid_data[tid].txq_id; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | /* Copy MAC header from skb into command buffer */ |
Johannes Berg | ca8c0f4 | 2015-04-20 17:54:54 +0200 | [diff] [blame] | 738 | memcpy(tx_cmd->hdr, hdr, hdrlen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 739 | |
| 740 | WARN_ON_ONCE(info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM); |
| 741 | |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 742 | if (sta->tdls) { |
| 743 | /* default to TID 0 for non-QoS packets */ |
| 744 | u8 tdls_tid = tid == IWL_MAX_TID_COUNT ? 0 : tid; |
| 745 | |
| 746 | txq_id = mvmsta->hw_queue[tid_to_mac80211_ac[tdls_tid]]; |
| 747 | } |
| 748 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 749 | if (is_ampdu) { |
| 750 | if (WARN_ON_ONCE(mvmsta->tid_data[tid].state != IWL_AGG_ON)) |
| 751 | goto drop_unlock_sta; |
| 752 | txq_id = mvmsta->tid_data[tid].txq_id; |
| 753 | } |
| 754 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame^] | 755 | if (iwl_mvm_is_dqa_supported(mvm)) { |
| 756 | if (unlikely(mvmsta->tid_data[tid].txq_id == |
| 757 | IEEE80211_INVAL_HW_QUEUE)) { |
| 758 | iwl_mvm_tx_add_stream(mvm, mvmsta, tid, skb); |
| 759 | |
| 760 | /* |
| 761 | * The frame is now deferred, and the worker scheduled |
| 762 | * will re-allocate it, so we can free it for now. |
| 763 | */ |
| 764 | iwl_trans_free_tx_cmd(mvm->trans, dev_cmd); |
| 765 | spin_unlock(&mvmsta->lock); |
| 766 | return 0; |
| 767 | } |
| 768 | |
| 769 | txq_id = mvmsta->tid_data[tid].txq_id; |
| 770 | } |
| 771 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 772 | IWL_DEBUG_TX(mvm, "TX to [%d|%d] Q:%d - seq: 0x%x\n", mvmsta->sta_id, |
Eliad Peller | cf9d118 | 2013-12-31 18:54:06 +0200 | [diff] [blame] | 773 | tid, txq_id, IEEE80211_SEQ_TO_SN(seq_number)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 774 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 775 | if (iwl_trans_tx(mvm->trans, skb, dev_cmd, txq_id)) |
| 776 | goto drop_unlock_sta; |
| 777 | |
Johannes Berg | 7ec5471 | 2016-03-16 09:29:48 +0100 | [diff] [blame] | 778 | if (tid < IWL_MAX_TID_COUNT && !ieee80211_has_morefrags(fc)) |
Eliad Peller | cf9d118 | 2013-12-31 18:54:06 +0200 | [diff] [blame] | 779 | mvmsta->tid_data[tid].seq_number = seq_number + 0x10; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 780 | |
| 781 | spin_unlock(&mvmsta->lock); |
| 782 | |
Eytan Lifshitz | 19e737c | 2013-09-09 13:30:15 +0200 | [diff] [blame] | 783 | if (txq_id < mvm->first_agg_queue) |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 784 | atomic_inc(&mvm->pending_frames[mvmsta->sta_id]); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 785 | |
| 786 | return 0; |
| 787 | |
| 788 | drop_unlock_sta: |
| 789 | iwl_trans_free_tx_cmd(mvm->trans, dev_cmd); |
| 790 | spin_unlock(&mvmsta->lock); |
| 791 | drop: |
| 792 | return -1; |
| 793 | } |
| 794 | |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 795 | int iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb, |
| 796 | struct ieee80211_sta *sta) |
| 797 | { |
| 798 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 799 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 800 | struct sk_buff_head mpdus_skbs; |
| 801 | unsigned int payload_len; |
| 802 | int ret; |
| 803 | |
| 804 | if (WARN_ON_ONCE(!mvmsta)) |
| 805 | return -1; |
| 806 | |
| 807 | if (WARN_ON_ONCE(mvmsta->sta_id == IWL_MVM_STATION_COUNT)) |
| 808 | return -1; |
| 809 | |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 810 | /* This holds the amsdu headers length */ |
| 811 | info->driver_data[0] = (void *)(uintptr_t)0; |
| 812 | |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 813 | if (!skb_is_gso(skb)) |
| 814 | return iwl_mvm_tx_mpdu(mvm, skb, sta); |
| 815 | |
| 816 | payload_len = skb_tail_pointer(skb) - skb_transport_header(skb) - |
| 817 | tcp_hdrlen(skb) + skb->data_len; |
| 818 | |
| 819 | if (payload_len <= skb_shinfo(skb)->gso_size) |
| 820 | return iwl_mvm_tx_mpdu(mvm, skb, sta); |
| 821 | |
| 822 | __skb_queue_head_init(&mpdus_skbs); |
| 823 | |
| 824 | ret = iwl_mvm_tx_tso(mvm, skb, sta, &mpdus_skbs); |
| 825 | if (ret) |
| 826 | return ret; |
| 827 | |
| 828 | if (WARN_ON(skb_queue_empty(&mpdus_skbs))) |
| 829 | return ret; |
| 830 | |
| 831 | while (!skb_queue_empty(&mpdus_skbs)) { |
Emmanuel Grumbach | a6d5e32 | 2015-10-14 16:28:52 +0300 | [diff] [blame] | 832 | skb = __skb_dequeue(&mpdus_skbs); |
Emmanuel Grumbach | a3713f8 | 2015-10-14 14:16:35 +0300 | [diff] [blame] | 833 | |
| 834 | ret = iwl_mvm_tx_mpdu(mvm, skb, sta); |
| 835 | if (ret) { |
| 836 | __skb_queue_purge(&mpdus_skbs); |
| 837 | return ret; |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | return 0; |
| 842 | } |
| 843 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 844 | static void iwl_mvm_check_ratid_empty(struct iwl_mvm *mvm, |
| 845 | struct ieee80211_sta *sta, u8 tid) |
| 846 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 847 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 848 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 849 | struct ieee80211_vif *vif = mvmsta->vif; |
| 850 | |
| 851 | lockdep_assert_held(&mvmsta->lock); |
| 852 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 853 | if ((tid_data->state == IWL_AGG_ON || |
| 854 | tid_data->state == IWL_EMPTYING_HW_QUEUE_DELBA) && |
| 855 | iwl_mvm_tid_queued(tid_data) == 0) { |
| 856 | /* |
| 857 | * Now that this aggregation queue is empty tell mac80211 so it |
| 858 | * knows we no longer have frames buffered for the station on |
| 859 | * this TID (for the TIM bitmap calculation.) |
| 860 | */ |
| 861 | ieee80211_sta_set_buffered(sta, tid, false); |
| 862 | } |
| 863 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 864 | if (tid_data->ssn != tid_data->next_reclaimed) |
| 865 | return; |
| 866 | |
| 867 | switch (tid_data->state) { |
| 868 | case IWL_EMPTYING_HW_QUEUE_ADDBA: |
| 869 | IWL_DEBUG_TX_QUEUES(mvm, |
| 870 | "Can continue addBA flow ssn = next_recl = %d\n", |
| 871 | tid_data->next_reclaimed); |
| 872 | tid_data->state = IWL_AGG_STARTING; |
| 873 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 874 | break; |
| 875 | |
| 876 | case IWL_EMPTYING_HW_QUEUE_DELBA: |
| 877 | IWL_DEBUG_TX_QUEUES(mvm, |
| 878 | "Can continue DELBA flow ssn = next_recl = %d\n", |
| 879 | tid_data->next_reclaimed); |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 880 | iwl_mvm_disable_txq(mvm, tid_data->txq_id, |
| 881 | vif->hw_queue[tid_to_mac80211_ac[tid]], tid, |
| 882 | CMD_ASYNC); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 883 | tid_data->state = IWL_AGG_OFF; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 884 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 885 | break; |
| 886 | |
| 887 | default: |
| 888 | break; |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 893 | const char *iwl_mvm_get_tx_fail_reason(u32 status) |
| 894 | { |
| 895 | #define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x |
| 896 | #define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x |
| 897 | |
| 898 | switch (status & TX_STATUS_MSK) { |
| 899 | case TX_STATUS_SUCCESS: |
| 900 | return "SUCCESS"; |
| 901 | TX_STATUS_POSTPONE(DELAY); |
| 902 | TX_STATUS_POSTPONE(FEW_BYTES); |
| 903 | TX_STATUS_POSTPONE(BT_PRIO); |
| 904 | TX_STATUS_POSTPONE(QUIET_PERIOD); |
| 905 | TX_STATUS_POSTPONE(CALC_TTAK); |
| 906 | TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY); |
| 907 | TX_STATUS_FAIL(SHORT_LIMIT); |
| 908 | TX_STATUS_FAIL(LONG_LIMIT); |
| 909 | TX_STATUS_FAIL(UNDERRUN); |
| 910 | TX_STATUS_FAIL(DRAIN_FLOW); |
| 911 | TX_STATUS_FAIL(RFKILL_FLUSH); |
| 912 | TX_STATUS_FAIL(LIFE_EXPIRE); |
| 913 | TX_STATUS_FAIL(DEST_PS); |
| 914 | TX_STATUS_FAIL(HOST_ABORTED); |
| 915 | TX_STATUS_FAIL(BT_RETRY); |
| 916 | TX_STATUS_FAIL(STA_INVALID); |
| 917 | TX_STATUS_FAIL(FRAG_DROPPED); |
| 918 | TX_STATUS_FAIL(TID_DISABLE); |
| 919 | TX_STATUS_FAIL(FIFO_FLUSHED); |
| 920 | TX_STATUS_FAIL(SMALL_CF_POLL); |
| 921 | TX_STATUS_FAIL(FW_DROP); |
| 922 | TX_STATUS_FAIL(STA_COLOR_MISMATCH); |
| 923 | } |
| 924 | |
| 925 | return "UNKNOWN"; |
| 926 | |
| 927 | #undef TX_STATUS_FAIL |
| 928 | #undef TX_STATUS_POSTPONE |
| 929 | } |
| 930 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
| 931 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 932 | void iwl_mvm_hwrate_to_tx_rate(u32 rate_n_flags, |
| 933 | enum ieee80211_band band, |
| 934 | struct ieee80211_tx_rate *r) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 935 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 936 | if (rate_n_flags & RATE_HT_MCS_GF_MSK) |
| 937 | r->flags |= IEEE80211_TX_RC_GREEN_FIELD; |
| 938 | switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { |
| 939 | case RATE_MCS_CHAN_WIDTH_20: |
| 940 | break; |
| 941 | case RATE_MCS_CHAN_WIDTH_40: |
| 942 | r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; |
| 943 | break; |
| 944 | case RATE_MCS_CHAN_WIDTH_80: |
| 945 | r->flags |= IEEE80211_TX_RC_80_MHZ_WIDTH; |
| 946 | break; |
| 947 | case RATE_MCS_CHAN_WIDTH_160: |
| 948 | r->flags |= IEEE80211_TX_RC_160_MHZ_WIDTH; |
| 949 | break; |
| 950 | } |
| 951 | if (rate_n_flags & RATE_MCS_SGI_MSK) |
| 952 | r->flags |= IEEE80211_TX_RC_SHORT_GI; |
| 953 | if (rate_n_flags & RATE_MCS_HT_MSK) { |
| 954 | r->flags |= IEEE80211_TX_RC_MCS; |
| 955 | r->idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK; |
| 956 | } else if (rate_n_flags & RATE_MCS_VHT_MSK) { |
| 957 | ieee80211_rate_set_vht( |
| 958 | r, rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK, |
| 959 | ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >> |
| 960 | RATE_VHT_MCS_NSS_POS) + 1); |
| 961 | r->flags |= IEEE80211_TX_RC_VHT_MCS; |
| 962 | } else { |
| 963 | r->idx = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags, |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 964 | band); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 968 | /** |
| 969 | * translate ucode response to mac80211 tx status control values |
| 970 | */ |
| 971 | static void iwl_mvm_hwrate_to_tx_status(u32 rate_n_flags, |
| 972 | struct ieee80211_tx_info *info) |
| 973 | { |
| 974 | struct ieee80211_tx_rate *r = &info->status.rates[0]; |
| 975 | |
| 976 | info->status.antenna = |
| 977 | ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS); |
| 978 | iwl_mvm_hwrate_to_tx_rate(rate_n_flags, info->band, r); |
| 979 | } |
| 980 | |
Golan Ben-Ami | 25657fe | 2015-09-02 12:34:23 +0300 | [diff] [blame] | 981 | static void iwl_mvm_tx_status_check_trigger(struct iwl_mvm *mvm, |
| 982 | u32 status) |
| 983 | { |
| 984 | struct iwl_fw_dbg_trigger_tlv *trig; |
| 985 | struct iwl_fw_dbg_trigger_tx_status *status_trig; |
| 986 | int i; |
| 987 | |
| 988 | if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TX_STATUS)) |
| 989 | return; |
| 990 | |
| 991 | trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TX_STATUS); |
| 992 | status_trig = (void *)trig->data; |
| 993 | |
| 994 | if (!iwl_fw_dbg_trigger_check_stop(mvm, NULL, trig)) |
| 995 | return; |
| 996 | |
| 997 | for (i = 0; i < ARRAY_SIZE(status_trig->statuses); i++) { |
| 998 | /* don't collect on status 0 */ |
| 999 | if (!status_trig->statuses[i].status) |
| 1000 | break; |
| 1001 | |
| 1002 | if (status_trig->statuses[i].status != (status & TX_STATUS_MSK)) |
| 1003 | continue; |
| 1004 | |
| 1005 | iwl_mvm_fw_dbg_collect_trig(mvm, trig, |
| 1006 | "Tx status %d was received", |
| 1007 | status & TX_STATUS_MSK); |
| 1008 | break; |
| 1009 | } |
| 1010 | } |
| 1011 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1012 | static void iwl_mvm_rx_tx_cmd_single(struct iwl_mvm *mvm, |
| 1013 | struct iwl_rx_packet *pkt) |
| 1014 | { |
| 1015 | struct ieee80211_sta *sta; |
| 1016 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 1017 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 1018 | struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data; |
| 1019 | int sta_id = IWL_MVM_TX_RES_GET_RA(tx_resp->ra_tid); |
| 1020 | int tid = IWL_MVM_TX_RES_GET_TID(tx_resp->ra_tid); |
| 1021 | u32 status = le16_to_cpu(tx_resp->status.status); |
| 1022 | u16 ssn = iwl_mvm_get_scd_ssn(tx_resp); |
| 1023 | struct iwl_mvm_sta *mvmsta; |
| 1024 | struct sk_buff_head skbs; |
| 1025 | u8 skb_freed = 0; |
| 1026 | u16 next_reclaimed, seq_ctl; |
Emmanuel Grumbach | 532beba | 2016-03-07 22:23:52 +0200 | [diff] [blame] | 1027 | bool is_ndp = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1028 | |
| 1029 | __skb_queue_head_init(&skbs); |
| 1030 | |
| 1031 | seq_ctl = le16_to_cpu(tx_resp->seq_ctl); |
| 1032 | |
| 1033 | /* we can free until ssn % q.n_bd not inclusive */ |
| 1034 | iwl_trans_reclaim(mvm->trans, txq_id, ssn, &skbs); |
| 1035 | |
| 1036 | while (!skb_queue_empty(&skbs)) { |
| 1037 | struct sk_buff *skb = __skb_dequeue(&skbs); |
| 1038 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1039 | |
| 1040 | skb_freed++; |
| 1041 | |
| 1042 | iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]); |
| 1043 | |
| 1044 | memset(&info->status, 0, sizeof(info->status)); |
| 1045 | |
| 1046 | info->flags &= ~IEEE80211_TX_CTL_AMPDU; |
| 1047 | |
| 1048 | /* inform mac80211 about what happened with the frame */ |
| 1049 | switch (status & TX_STATUS_MSK) { |
| 1050 | case TX_STATUS_SUCCESS: |
| 1051 | case TX_STATUS_DIRECT_DONE: |
| 1052 | info->flags |= IEEE80211_TX_STAT_ACK; |
| 1053 | break; |
| 1054 | case TX_STATUS_FAIL_DEST_PS: |
| 1055 | info->flags |= IEEE80211_TX_STAT_TX_FILTERED; |
| 1056 | break; |
| 1057 | default: |
| 1058 | break; |
| 1059 | } |
| 1060 | |
Golan Ben-Ami | 25657fe | 2015-09-02 12:34:23 +0300 | [diff] [blame] | 1061 | iwl_mvm_tx_status_check_trigger(mvm, status); |
| 1062 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1063 | info->status.rates[0].count = tx_resp->failure_frame + 1; |
Eyal Shapira | d310e40 | 2013-08-11 18:43:47 +0300 | [diff] [blame] | 1064 | iwl_mvm_hwrate_to_tx_status(le32_to_cpu(tx_resp->initial_rate), |
| 1065 | info); |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1066 | info->status.status_driver_data[1] = |
| 1067 | (void *)(uintptr_t)le32_to_cpu(tx_resp->initial_rate); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1068 | |
| 1069 | /* Single frame failure in an AMPDU queue => send BAR */ |
Eytan Lifshitz | 19e737c | 2013-09-09 13:30:15 +0200 | [diff] [blame] | 1070 | if (txq_id >= mvm->first_agg_queue && |
Eyal Shapira | 9ce578a | 2014-12-31 15:22:38 +0200 | [diff] [blame] | 1071 | !(info->flags & IEEE80211_TX_STAT_ACK) && |
| 1072 | !(info->flags & IEEE80211_TX_STAT_TX_FILTERED)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1073 | info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1074 | |
Emmanuel Grumbach | ebea2f3 | 2013-06-13 10:07:47 +0300 | [diff] [blame] | 1075 | /* W/A FW bug: seq_ctl is wrong when the status isn't success */ |
| 1076 | if (status != TX_STATUS_SUCCESS) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1077 | struct ieee80211_hdr *hdr = (void *)skb->data; |
| 1078 | seq_ctl = le16_to_cpu(hdr->seq_ctrl); |
| 1079 | } |
| 1080 | |
Emmanuel Grumbach | 532beba | 2016-03-07 22:23:52 +0200 | [diff] [blame] | 1081 | if (unlikely(!seq_ctl)) { |
| 1082 | struct ieee80211_hdr *hdr = (void *)skb->data; |
| 1083 | |
| 1084 | /* |
| 1085 | * If it is an NDP, we can't update next_reclaim since |
| 1086 | * its sequence control is 0. Note that for that same |
| 1087 | * reason, NDPs are never sent to A-MPDU'able queues |
| 1088 | * so that we can never have more than one freed frame |
| 1089 | * for a single Tx resonse (see WARN_ON below). |
| 1090 | */ |
| 1091 | if (ieee80211_is_qos_nullfunc(hdr->frame_control)) |
| 1092 | is_ndp = true; |
| 1093 | } |
| 1094 | |
Emmanuel Grumbach | 9b5452f | 2014-10-07 10:38:53 +0300 | [diff] [blame] | 1095 | /* |
| 1096 | * TODO: this is not accurate if we are freeing more than one |
| 1097 | * packet. |
| 1098 | */ |
| 1099 | info->status.tx_time = |
| 1100 | le16_to_cpu(tx_resp->wireless_media_time); |
Eliad Peller | 3a84b69 | 2014-03-12 15:05:06 +0200 | [diff] [blame] | 1101 | BUILD_BUG_ON(ARRAY_SIZE(info->status.status_driver_data) < 1); |
| 1102 | info->status.status_driver_data[0] = |
| 1103 | (void *)(uintptr_t)tx_resp->reduced_tpc; |
| 1104 | |
Johannes Berg | f14d6b3 | 2014-03-21 13:30:03 +0100 | [diff] [blame] | 1105 | ieee80211_tx_status(mvm->hw, skb); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1106 | } |
| 1107 | |
Eytan Lifshitz | 19e737c | 2013-09-09 13:30:15 +0200 | [diff] [blame] | 1108 | if (txq_id >= mvm->first_agg_queue) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1109 | /* If this is an aggregation queue, we use the ssn since: |
| 1110 | * ssn = wifi seq_num % 256. |
| 1111 | * The seq_ctl is the sequence control of the packet to which |
| 1112 | * this Tx response relates. But if there is a hole in the |
| 1113 | * bitmap of the BA we received, this Tx response may allow to |
| 1114 | * reclaim the hole and all the subsequent packets that were |
| 1115 | * already acked. In that case, seq_ctl != ssn, and the next |
| 1116 | * packet to be reclaimed will be ssn and not seq_ctl. In that |
| 1117 | * case, several packets will be reclaimed even if |
| 1118 | * frame_count = 1. |
| 1119 | * |
| 1120 | * The ssn is the index (% 256) of the latest packet that has |
| 1121 | * treated (acked / dropped) + 1. |
| 1122 | */ |
| 1123 | next_reclaimed = ssn; |
| 1124 | } else { |
| 1125 | /* The next packet to be reclaimed is the one after this one */ |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 1126 | next_reclaimed = IEEE80211_SEQ_TO_SN(seq_ctl + 0x10); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | IWL_DEBUG_TX_REPLY(mvm, |
Emmanuel Grumbach | 8c6e83d | 2013-03-20 17:12:46 +0200 | [diff] [blame] | 1130 | "TXQ %d status %s (0x%08x)\n", |
| 1131 | txq_id, iwl_mvm_get_tx_fail_reason(status), status); |
| 1132 | |
| 1133 | IWL_DEBUG_TX_REPLY(mvm, |
| 1134 | "\t\t\t\tinitial_rate 0x%x retries %d, idx=%d ssn=%d next_reclaimed=0x%x seq_ctl=0x%x\n", |
| 1135 | le32_to_cpu(tx_resp->initial_rate), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1136 | tx_resp->failure_frame, SEQ_TO_INDEX(sequence), |
| 1137 | ssn, next_reclaimed, seq_ctl); |
| 1138 | |
| 1139 | rcu_read_lock(); |
| 1140 | |
| 1141 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
Emmanuel Grumbach | 9bb0c1a | 2014-01-20 15:21:26 +0200 | [diff] [blame] | 1142 | /* |
| 1143 | * sta can't be NULL otherwise it'd mean that the sta has been freed in |
| 1144 | * the firmware while we still have packets for it in the Tx queues. |
| 1145 | */ |
| 1146 | if (WARN_ON_ONCE(!sta)) |
| 1147 | goto out; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1148 | |
Emmanuel Grumbach | 9bb0c1a | 2014-01-20 15:21:26 +0200 | [diff] [blame] | 1149 | if (!IS_ERR(sta)) { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1150 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1151 | |
| 1152 | if (tid != IWL_TID_NON_QOS) { |
| 1153 | struct iwl_mvm_tid_data *tid_data = |
| 1154 | &mvmsta->tid_data[tid]; |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 1155 | bool send_eosp_ndp = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1156 | |
Johannes Berg | 2bfb509 | 2012-12-27 21:43:48 +0100 | [diff] [blame] | 1157 | spin_lock_bh(&mvmsta->lock); |
Emmanuel Grumbach | 532beba | 2016-03-07 22:23:52 +0200 | [diff] [blame] | 1158 | if (!is_ndp) { |
| 1159 | tid_data->next_reclaimed = next_reclaimed; |
| 1160 | IWL_DEBUG_TX_REPLY(mvm, |
| 1161 | "Next reclaimed packet:%d\n", |
| 1162 | next_reclaimed); |
| 1163 | } else { |
| 1164 | IWL_DEBUG_TX_REPLY(mvm, |
| 1165 | "NDP - don't update next_reclaimed\n"); |
| 1166 | } |
| 1167 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1168 | iwl_mvm_check_ratid_empty(mvm, sta, tid); |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 1169 | |
| 1170 | if (mvmsta->sleep_tx_count) { |
| 1171 | mvmsta->sleep_tx_count--; |
| 1172 | if (mvmsta->sleep_tx_count && |
| 1173 | !iwl_mvm_tid_queued(tid_data)) { |
| 1174 | /* |
| 1175 | * The number of frames in the queue |
| 1176 | * dropped to 0 even if we sent less |
| 1177 | * frames than we thought we had on the |
| 1178 | * Tx queue. |
| 1179 | * This means we had holes in the BA |
| 1180 | * window that we just filled, ask |
| 1181 | * mac80211 to send EOSP since the |
| 1182 | * firmware won't know how to do that. |
| 1183 | * Send NDP and the firmware will send |
| 1184 | * EOSP notification that will trigger |
| 1185 | * a call to ieee80211_sta_eosp(). |
| 1186 | */ |
| 1187 | send_eosp_ndp = true; |
| 1188 | } |
| 1189 | } |
| 1190 | |
Johannes Berg | 2bfb509 | 2012-12-27 21:43:48 +0100 | [diff] [blame] | 1191 | spin_unlock_bh(&mvmsta->lock); |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 1192 | if (send_eosp_ndp) { |
| 1193 | iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, |
| 1194 | IEEE80211_FRAME_RELEASE_UAPSD, |
| 1195 | 1, tid, false, false); |
| 1196 | mvmsta->sleep_tx_count = 0; |
| 1197 | ieee80211_send_eosp_nullfunc(sta, tid); |
| 1198 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1199 | } |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1200 | |
| 1201 | if (mvmsta->next_status_eosp) { |
| 1202 | mvmsta->next_status_eosp = false; |
| 1203 | ieee80211_sta_eosp(sta); |
| 1204 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1205 | } else { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1206 | mvmsta = NULL; |
| 1207 | } |
| 1208 | |
| 1209 | /* |
| 1210 | * If the txq is not an AMPDU queue, there is no chance we freed |
| 1211 | * several skbs. Check that out... |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1212 | */ |
Emmanuel Grumbach | 9bb0c1a | 2014-01-20 15:21:26 +0200 | [diff] [blame] | 1213 | if (txq_id >= mvm->first_agg_queue) |
| 1214 | goto out; |
| 1215 | |
| 1216 | /* We can't free more than one frame at once on a shared queue */ |
| 1217 | WARN_ON(skb_freed > 1); |
| 1218 | |
Emmanuel Grumbach | 589a6ba | 2014-06-05 11:32:41 +0300 | [diff] [blame] | 1219 | /* If we have still frames for this STA nothing to do here */ |
Emmanuel Grumbach | 9bb0c1a | 2014-01-20 15:21:26 +0200 | [diff] [blame] | 1220 | if (!atomic_sub_and_test(skb_freed, &mvm->pending_frames[sta_id])) |
| 1221 | goto out; |
| 1222 | |
| 1223 | if (mvmsta && mvmsta->vif->type == NL80211_IFTYPE_AP) { |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 1224 | |
Emmanuel Grumbach | 9bb0c1a | 2014-01-20 15:21:26 +0200 | [diff] [blame] | 1225 | /* |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 1226 | * If there are no pending frames for this STA and |
| 1227 | * the tx to this station is not disabled, notify |
| 1228 | * mac80211 that this station can now wake up in its |
Emmanuel Grumbach | 9bb0c1a | 2014-01-20 15:21:26 +0200 | [diff] [blame] | 1229 | * STA table. |
| 1230 | * If mvmsta is not NULL, sta is valid. |
| 1231 | */ |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 1232 | |
| 1233 | spin_lock_bh(&mvmsta->lock); |
| 1234 | |
| 1235 | if (!mvmsta->disable_tx) |
| 1236 | ieee80211_sta_block_awake(mvm->hw, sta, false); |
| 1237 | |
| 1238 | spin_unlock_bh(&mvmsta->lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1239 | } |
| 1240 | |
Emmanuel Grumbach | 9bb0c1a | 2014-01-20 15:21:26 +0200 | [diff] [blame] | 1241 | if (PTR_ERR(sta) == -EBUSY || PTR_ERR(sta) == -ENOENT) { |
| 1242 | /* |
| 1243 | * We are draining and this was the last packet - pre_rcu_remove |
| 1244 | * has been called already. We might be after the |
| 1245 | * synchronize_net already. |
| 1246 | * Don't rely on iwl_mvm_rm_sta to see the empty Tx queues. |
| 1247 | */ |
| 1248 | set_bit(sta_id, mvm->sta_drained); |
| 1249 | schedule_work(&mvm->sta_drained_wk); |
| 1250 | } |
| 1251 | |
| 1252 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1253 | rcu_read_unlock(); |
| 1254 | } |
| 1255 | |
| 1256 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 1257 | #define AGG_TX_STATE_(x) case AGG_TX_STATE_ ## x: return #x |
| 1258 | static const char *iwl_get_agg_tx_status(u16 status) |
| 1259 | { |
| 1260 | switch (status & AGG_TX_STATE_STATUS_MSK) { |
| 1261 | AGG_TX_STATE_(TRANSMITTED); |
| 1262 | AGG_TX_STATE_(UNDERRUN); |
| 1263 | AGG_TX_STATE_(BT_PRIO); |
| 1264 | AGG_TX_STATE_(FEW_BYTES); |
| 1265 | AGG_TX_STATE_(ABORT); |
| 1266 | AGG_TX_STATE_(LAST_SENT_TTL); |
| 1267 | AGG_TX_STATE_(LAST_SENT_TRY_CNT); |
| 1268 | AGG_TX_STATE_(LAST_SENT_BT_KILL); |
| 1269 | AGG_TX_STATE_(SCD_QUERY); |
| 1270 | AGG_TX_STATE_(TEST_BAD_CRC32); |
| 1271 | AGG_TX_STATE_(RESPONSE); |
| 1272 | AGG_TX_STATE_(DUMP_TX); |
| 1273 | AGG_TX_STATE_(DELAY_TX); |
| 1274 | } |
| 1275 | |
| 1276 | return "UNKNOWN"; |
| 1277 | } |
| 1278 | |
| 1279 | static void iwl_mvm_rx_tx_cmd_agg_dbg(struct iwl_mvm *mvm, |
| 1280 | struct iwl_rx_packet *pkt) |
| 1281 | { |
| 1282 | struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data; |
| 1283 | struct agg_tx_status *frame_status = &tx_resp->status; |
| 1284 | int i; |
| 1285 | |
| 1286 | for (i = 0; i < tx_resp->frame_count; i++) { |
| 1287 | u16 fstatus = le16_to_cpu(frame_status[i].status); |
| 1288 | |
| 1289 | IWL_DEBUG_TX_REPLY(mvm, |
| 1290 | "status %s (0x%04x), try-count (%d) seq (0x%x)\n", |
| 1291 | iwl_get_agg_tx_status(fstatus), |
| 1292 | fstatus & AGG_TX_STATE_STATUS_MSK, |
| 1293 | (fstatus & AGG_TX_STATE_TRY_CNT_MSK) >> |
| 1294 | AGG_TX_STATE_TRY_CNT_POS, |
| 1295 | le16_to_cpu(frame_status[i].sequence)); |
| 1296 | } |
| 1297 | } |
| 1298 | #else |
| 1299 | static void iwl_mvm_rx_tx_cmd_agg_dbg(struct iwl_mvm *mvm, |
| 1300 | struct iwl_rx_packet *pkt) |
| 1301 | {} |
| 1302 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
| 1303 | |
| 1304 | static void iwl_mvm_rx_tx_cmd_agg(struct iwl_mvm *mvm, |
| 1305 | struct iwl_rx_packet *pkt) |
| 1306 | { |
| 1307 | struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data; |
| 1308 | int sta_id = IWL_MVM_TX_RES_GET_RA(tx_resp->ra_tid); |
| 1309 | int tid = IWL_MVM_TX_RES_GET_TID(tx_resp->ra_tid); |
| 1310 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 1311 | struct ieee80211_sta *sta; |
| 1312 | |
Eytan Lifshitz | 19e737c | 2013-09-09 13:30:15 +0200 | [diff] [blame] | 1313 | if (WARN_ON_ONCE(SEQ_TO_QUEUE(sequence) < mvm->first_agg_queue)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1314 | return; |
| 1315 | |
| 1316 | if (WARN_ON_ONCE(tid == IWL_TID_NON_QOS)) |
| 1317 | return; |
| 1318 | |
| 1319 | iwl_mvm_rx_tx_cmd_agg_dbg(mvm, pkt); |
| 1320 | |
| 1321 | rcu_read_lock(); |
| 1322 | |
| 1323 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 1324 | |
| 1325 | if (!WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1326 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1327 | mvmsta->tid_data[tid].rate_n_flags = |
| 1328 | le32_to_cpu(tx_resp->initial_rate); |
Emmanuel Grumbach | 9b5452f | 2014-10-07 10:38:53 +0300 | [diff] [blame] | 1329 | mvmsta->tid_data[tid].tx_time = |
| 1330 | le16_to_cpu(tx_resp->wireless_media_time); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | rcu_read_unlock(); |
| 1334 | } |
| 1335 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 1336 | void iwl_mvm_rx_tx_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1337 | { |
| 1338 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 1339 | struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data; |
| 1340 | |
| 1341 | if (tx_resp->frame_count == 1) |
| 1342 | iwl_mvm_rx_tx_cmd_single(mvm, pkt); |
| 1343 | else |
| 1344 | iwl_mvm_rx_tx_cmd_agg(mvm, pkt); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1345 | } |
| 1346 | |
Eyal Shapira | a713044 | 2014-09-14 15:28:09 +0300 | [diff] [blame] | 1347 | static void iwl_mvm_tx_info_from_ba_notif(struct ieee80211_tx_info *info, |
| 1348 | struct iwl_mvm_ba_notif *ba_notif, |
| 1349 | struct iwl_mvm_tid_data *tid_data) |
| 1350 | { |
| 1351 | info->flags |= IEEE80211_TX_STAT_AMPDU; |
| 1352 | info->status.ampdu_ack_len = ba_notif->txed_2_done; |
| 1353 | info->status.ampdu_len = ba_notif->txed; |
| 1354 | iwl_mvm_hwrate_to_tx_status(tid_data->rate_n_flags, |
| 1355 | info); |
Emmanuel Grumbach | 9b5452f | 2014-10-07 10:38:53 +0300 | [diff] [blame] | 1356 | /* TODO: not accounted if the whole A-MPDU failed */ |
| 1357 | info->status.tx_time = tid_data->tx_time; |
Eyal Shapira | a713044 | 2014-09-14 15:28:09 +0300 | [diff] [blame] | 1358 | info->status.status_driver_data[0] = |
Gregory Greenman | 69c7fda | 2015-12-29 11:26:35 +0200 | [diff] [blame] | 1359 | (void *)(uintptr_t)ba_notif->reduced_txp; |
Eyal Shapira | 929e6ed | 2015-01-30 13:40:02 +0200 | [diff] [blame] | 1360 | info->status.status_driver_data[1] = |
| 1361 | (void *)(uintptr_t)tid_data->rate_n_flags; |
Eyal Shapira | a713044 | 2014-09-14 15:28:09 +0300 | [diff] [blame] | 1362 | } |
| 1363 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 1364 | void iwl_mvm_rx_ba_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1365 | { |
| 1366 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 1367 | struct iwl_mvm_ba_notif *ba_notif = (void *)pkt->data; |
| 1368 | struct sk_buff_head reclaimed_skbs; |
| 1369 | struct iwl_mvm_tid_data *tid_data; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1370 | struct ieee80211_sta *sta; |
| 1371 | struct iwl_mvm_sta *mvmsta; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1372 | struct sk_buff *skb; |
| 1373 | int sta_id, tid, freed; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1374 | /* "flow" corresponds to Tx queue */ |
| 1375 | u16 scd_flow = le16_to_cpu(ba_notif->scd_flow); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1376 | /* "ssn" is start of block-ack Tx window, corresponds to index |
| 1377 | * (in Tx queue's circular buffer) of first TFD/frame in window */ |
| 1378 | u16 ba_resp_scd_ssn = le16_to_cpu(ba_notif->scd_ssn); |
| 1379 | |
| 1380 | sta_id = ba_notif->sta_id; |
| 1381 | tid = ba_notif->tid; |
| 1382 | |
Eyal Shapira | 2cee476 | 2015-01-16 11:09:30 +0200 | [diff] [blame] | 1383 | if (WARN_ONCE(sta_id >= IWL_MVM_STATION_COUNT || |
| 1384 | tid >= IWL_MAX_TID_COUNT, |
| 1385 | "sta_id %d tid %d", sta_id, tid)) |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 1386 | return; |
Eyal Shapira | 2cee476 | 2015-01-16 11:09:30 +0200 | [diff] [blame] | 1387 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1388 | rcu_read_lock(); |
| 1389 | |
| 1390 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 1391 | |
| 1392 | /* Reclaiming frames for a station that has been deleted ? */ |
| 1393 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) { |
| 1394 | rcu_read_unlock(); |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 1395 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1396 | } |
| 1397 | |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1398 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1399 | tid_data = &mvmsta->tid_data[tid]; |
| 1400 | |
Johannes Berg | 1f16ea2 | 2015-03-06 09:17:37 +0100 | [diff] [blame] | 1401 | if (tid_data->txq_id != scd_flow) { |
| 1402 | IWL_ERR(mvm, |
| 1403 | "invalid BA notification: Q %d, tid %d, flow %d\n", |
| 1404 | tid_data->txq_id, tid, scd_flow); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1405 | rcu_read_unlock(); |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 1406 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1407 | } |
| 1408 | |
Johannes Berg | 2bfb509 | 2012-12-27 21:43:48 +0100 | [diff] [blame] | 1409 | spin_lock_bh(&mvmsta->lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1410 | |
| 1411 | __skb_queue_head_init(&reclaimed_skbs); |
| 1412 | |
| 1413 | /* |
| 1414 | * Release all TFDs before the SSN, i.e. all TFDs in front of |
| 1415 | * block-ack window (we assume that they've been successfully |
| 1416 | * transmitted ... if not, it's too late anyway). |
| 1417 | */ |
| 1418 | iwl_trans_reclaim(mvm->trans, scd_flow, ba_resp_scd_ssn, |
| 1419 | &reclaimed_skbs); |
| 1420 | |
| 1421 | IWL_DEBUG_TX_REPLY(mvm, |
| 1422 | "BA_NOTIFICATION Received from %pM, sta_id = %d\n", |
| 1423 | (u8 *)&ba_notif->sta_addr_lo32, |
| 1424 | ba_notif->sta_id); |
| 1425 | IWL_DEBUG_TX_REPLY(mvm, |
| 1426 | "TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = %d, scd_ssn = %d sent:%d, acked:%d\n", |
| 1427 | ba_notif->tid, le16_to_cpu(ba_notif->seq_ctl), |
| 1428 | (unsigned long long)le64_to_cpu(ba_notif->bitmap), |
| 1429 | scd_flow, ba_resp_scd_ssn, ba_notif->txed, |
| 1430 | ba_notif->txed_2_done); |
| 1431 | |
Gregory Greenman | 69c7fda | 2015-12-29 11:26:35 +0200 | [diff] [blame] | 1432 | IWL_DEBUG_TX_REPLY(mvm, "reduced txp from ba notif %d\n", |
| 1433 | ba_notif->reduced_txp); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1434 | tid_data->next_reclaimed = ba_resp_scd_ssn; |
| 1435 | |
| 1436 | iwl_mvm_check_ratid_empty(mvm, sta, tid); |
| 1437 | |
| 1438 | freed = 0; |
| 1439 | |
| 1440 | skb_queue_walk(&reclaimed_skbs, skb) { |
Johannes Berg | 143582c | 2014-02-25 10:37:15 +0100 | [diff] [blame] | 1441 | struct ieee80211_hdr *hdr = (void *)skb->data; |
| 1442 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1443 | |
| 1444 | if (ieee80211_is_data_qos(hdr->frame_control)) |
| 1445 | freed++; |
| 1446 | else |
| 1447 | WARN_ON_ONCE(1); |
| 1448 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1449 | iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]); |
| 1450 | |
Johannes Berg | 143582c | 2014-02-25 10:37:15 +0100 | [diff] [blame] | 1451 | memset(&info->status, 0, sizeof(info->status)); |
| 1452 | /* Packet was transmitted successfully, failures come as single |
| 1453 | * frames because before failing a frame the firmware transmits |
| 1454 | * it without aggregation at least once. |
| 1455 | */ |
| 1456 | info->flags |= IEEE80211_TX_STAT_ACK; |
| 1457 | |
Eyal Shapira | a713044 | 2014-09-14 15:28:09 +0300 | [diff] [blame] | 1458 | /* this is the first skb we deliver in this batch */ |
| 1459 | /* put the rate scaling data there */ |
| 1460 | if (freed == 1) |
| 1461 | iwl_mvm_tx_info_from_ba_notif(info, ba_notif, tid_data); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1462 | } |
| 1463 | |
Johannes Berg | 2bfb509 | 2012-12-27 21:43:48 +0100 | [diff] [blame] | 1464 | spin_unlock_bh(&mvmsta->lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1465 | |
Eyal Shapira | a713044 | 2014-09-14 15:28:09 +0300 | [diff] [blame] | 1466 | /* We got a BA notif with 0 acked or scd_ssn didn't progress which is |
| 1467 | * possible (i.e. first MPDU in the aggregation wasn't acked) |
| 1468 | * Still it's important to update RS about sent vs. acked. |
| 1469 | */ |
| 1470 | if (skb_queue_empty(&reclaimed_skbs)) { |
| 1471 | struct ieee80211_tx_info ba_info = {}; |
| 1472 | struct ieee80211_chanctx_conf *chanctx_conf = NULL; |
| 1473 | |
| 1474 | if (mvmsta->vif) |
| 1475 | chanctx_conf = |
| 1476 | rcu_dereference(mvmsta->vif->chanctx_conf); |
| 1477 | |
| 1478 | if (WARN_ON_ONCE(!chanctx_conf)) |
| 1479 | goto out; |
| 1480 | |
| 1481 | ba_info.band = chanctx_conf->def.chan->band; |
| 1482 | iwl_mvm_tx_info_from_ba_notif(&ba_info, ba_notif, tid_data); |
| 1483 | |
| 1484 | IWL_DEBUG_TX_REPLY(mvm, "No reclaim. Update rs directly\n"); |
| 1485 | iwl_mvm_rs_tx_status(mvm, sta, tid, &ba_info); |
| 1486 | } |
| 1487 | |
| 1488 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1489 | rcu_read_unlock(); |
| 1490 | |
| 1491 | while (!skb_queue_empty(&reclaimed_skbs)) { |
| 1492 | skb = __skb_dequeue(&reclaimed_skbs); |
Johannes Berg | f14d6b3 | 2014-03-21 13:30:03 +0100 | [diff] [blame] | 1493 | ieee80211_tx_status(mvm->hw, skb); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1494 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1495 | } |
| 1496 | |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 1497 | /* |
| 1498 | * Note that there are transports that buffer frames before they reach |
| 1499 | * the firmware. This means that after flush_tx_path is called, the |
| 1500 | * queue might not be empty. The race-free way to handle this is to: |
| 1501 | * 1) set the station as draining |
| 1502 | * 2) flush the Tx path |
| 1503 | * 3) wait for the transport queues to be empty |
| 1504 | */ |
Luca Coelho | 5888a40 | 2015-10-06 09:54:57 +0300 | [diff] [blame] | 1505 | int iwl_mvm_flush_tx_path(struct iwl_mvm *mvm, u32 tfd_msk, u32 flags) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1506 | { |
| 1507 | int ret; |
| 1508 | struct iwl_tx_path_flush_cmd flush_cmd = { |
| 1509 | .queues_ctl = cpu_to_le32(tfd_msk), |
| 1510 | .flush_ctl = cpu_to_le16(DUMP_TX_FIFO_FLUSH), |
| 1511 | }; |
| 1512 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1513 | ret = iwl_mvm_send_cmd_pdu(mvm, TXPATH_FLUSH, flags, |
| 1514 | sizeof(flush_cmd), &flush_cmd); |
| 1515 | if (ret) |
| 1516 | IWL_ERR(mvm, "Failed to send flush command (%d)\n", ret); |
| 1517 | return ret; |
| 1518 | } |