1 /******************************************************************************
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.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 Intel Deutschland GmbH
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.
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.
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,
26 * The full GNU General Public License is included in this distribution
27 * in the file called COPYING.
29 * Contact Information:
30 * Intel Linux Wireless <linuxwifi@intel.com>
31 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
35 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
36 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
37 * All rights reserved.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
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
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.
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.
65 *****************************************************************************/
66 #include <linux/ieee80211.h>
67 #include <linux/etherdevice.h>
68 #include <linux/tcp.h>
71 #include "iwl-trans.h"
72 #include "iwl-eeprom-parse.h"
78 iwl_mvm_bar_check_trigger(struct iwl_mvm *mvm, const u8 *addr,
81 struct iwl_fw_dbg_trigger_tlv *trig;
82 struct iwl_fw_dbg_trigger_ba *ba_trig;
84 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
87 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
88 ba_trig = (void *)trig->data;
90 if (!iwl_fw_dbg_trigger_check_stop(mvm, NULL, trig))
93 if (!(le16_to_cpu(ba_trig->tx_bar) & BIT(tid)))
96 iwl_mvm_fw_dbg_collect_trig(mvm, trig,
97 "BAR sent to %pM, tid %d, ssn %d",
102 * Sets most of the Tx cmd's fields
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)
108 struct ieee80211_tx_info *skb_info = IEEE80211_SKB_CB(skb);
109 struct ieee80211_hdr *hdr = (void *)skb->data;
110 __le16 fc = hdr->frame_control;
111 u32 tx_flags = le32_to_cpu(tx_cmd->tx_flags);
112 u32 len = skb->len + FCS_LEN;
115 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
116 tx_flags |= TX_CMD_FLG_ACK;
118 tx_flags &= ~TX_CMD_FLG_ACK;
120 if (ieee80211_is_probe_resp(fc))
121 tx_flags |= TX_CMD_FLG_TSF;
123 if (ieee80211_has_morefrags(fc))
124 tx_flags |= TX_CMD_FLG_MORE_FRAG;
126 if (ieee80211_is_data_qos(fc)) {
127 u8 *qc = ieee80211_get_qos_ctl(hdr);
128 tx_cmd->tid_tspec = qc[0] & 0xf;
129 tx_flags &= ~TX_CMD_FLG_SEQ_CTL;
130 } else if (ieee80211_is_back_req(fc)) {
131 struct ieee80211_bar *bar = (void *)skb->data;
132 u16 control = le16_to_cpu(bar->control);
133 u16 ssn = le16_to_cpu(bar->start_seq_num);
135 tx_flags |= TX_CMD_FLG_ACK | TX_CMD_FLG_BAR;
136 tx_cmd->tid_tspec = (control &
137 IEEE80211_BAR_CTRL_TID_INFO_MASK) >>
138 IEEE80211_BAR_CTRL_TID_INFO_SHIFT;
139 WARN_ON_ONCE(tx_cmd->tid_tspec >= IWL_MAX_TID_COUNT);
140 iwl_mvm_bar_check_trigger(mvm, bar->ra, tx_cmd->tid_tspec,
143 tx_cmd->tid_tspec = IWL_TID_NON_QOS;
144 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
145 tx_flags |= TX_CMD_FLG_SEQ_CTL;
147 tx_flags &= ~TX_CMD_FLG_SEQ_CTL;
150 /* Default to 0 (BE) when tid_spec is set to IWL_TID_NON_QOS */
151 if (tx_cmd->tid_tspec < IWL_MAX_TID_COUNT)
152 ac = tid_to_mac80211_ac[tx_cmd->tid_tspec];
154 ac = tid_to_mac80211_ac[0];
156 tx_flags |= iwl_mvm_bt_coex_tx_prio(mvm, hdr, info, ac) <<
157 TX_CMD_FLG_BT_PRIO_POS;
159 if (ieee80211_is_mgmt(fc)) {
160 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
161 tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_ASSOC);
162 else if (ieee80211_is_action(fc))
163 tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_NONE);
165 tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_MGMT);
167 /* The spec allows Action frames in A-MPDU, we don't support
170 WARN_ON_ONCE(info->flags & IEEE80211_TX_CTL_AMPDU);
171 } else if (info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO) {
172 tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_MGMT);
174 tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_NONE);
177 if (ieee80211_is_data(fc) && len > mvm->rts_threshold &&
178 !is_multicast_ether_addr(ieee80211_get_DA(hdr)))
179 tx_flags |= TX_CMD_FLG_PROT_REQUIRE;
181 if (fw_has_capa(&mvm->fw->ucode_capa,
182 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT) &&
183 ieee80211_action_contains_tpc(skb))
184 tx_flags |= TX_CMD_FLG_WRITE_TX_POWER;
186 tx_cmd->tx_flags = cpu_to_le32(tx_flags);
187 /* Total # bytes to be transmitted */
188 tx_cmd->len = cpu_to_le16((u16)skb->len +
189 (uintptr_t)skb_info->driver_data[0]);
190 tx_cmd->next_frame_len = 0;
191 tx_cmd->life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
192 tx_cmd->sta_id = sta_id;
196 * Sets the fields in the Tx cmd that are rate related
198 void iwl_mvm_set_tx_cmd_rate(struct iwl_mvm *mvm, struct iwl_tx_cmd *tx_cmd,
199 struct ieee80211_tx_info *info,
200 struct ieee80211_sta *sta, __le16 fc)
206 /* Set retry limit on RTS packets */
207 tx_cmd->rts_retry_limit = IWL_RTS_DFAULT_RETRY_LIMIT;
209 /* Set retry limit on DATA packets and Probe Responses*/
210 if (ieee80211_is_probe_resp(fc)) {
211 tx_cmd->data_retry_limit = IWL_MGMT_DFAULT_RETRY_LIMIT;
212 tx_cmd->rts_retry_limit =
213 min(tx_cmd->data_retry_limit, tx_cmd->rts_retry_limit);
214 } else if (ieee80211_is_back_req(fc)) {
215 tx_cmd->data_retry_limit = IWL_BAR_DFAULT_RETRY_LIMIT;
217 tx_cmd->data_retry_limit = IWL_DEFAULT_TX_RETRY;
221 * for data packets, rate info comes from the table inside the fw. This
222 * table is controlled by LINK_QUALITY commands
225 if (ieee80211_is_data(fc) && sta) {
226 tx_cmd->initial_rate_index = 0;
227 tx_cmd->tx_flags |= cpu_to_le32(TX_CMD_FLG_STA_RATE);
229 } else if (ieee80211_is_back_req(fc)) {
231 cpu_to_le32(TX_CMD_FLG_ACK | TX_CMD_FLG_BAR);
234 /* HT rate doesn't make sense for a non data frame */
235 WARN_ONCE(info->control.rates[0].flags & IEEE80211_TX_RC_MCS,
236 "Got an HT rate (flags:0x%x/mcs:%d) for a non data frame (fc:0x%x)\n",
237 info->control.rates[0].flags,
238 info->control.rates[0].idx,
241 rate_idx = info->control.rates[0].idx;
242 /* if the rate isn't a well known legacy rate, take the lowest one */
243 if (rate_idx < 0 || rate_idx > IWL_RATE_COUNT_LEGACY)
244 rate_idx = rate_lowest_index(
245 &mvm->nvm_data->bands[info->band], sta);
247 /* For 5 GHZ band, remap mac80211 rate indices into driver indices */
248 if (info->band == IEEE80211_BAND_5GHZ)
249 rate_idx += IWL_FIRST_OFDM_RATE;
251 /* For 2.4 GHZ band, check that there is no need to remap */
252 BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
254 /* Get PLCP rate for tx_cmd->rate_n_flags */
255 rate_plcp = iwl_mvm_mac80211_idx_to_hwrate(rate_idx);
257 mvm->mgmt_last_antenna_idx =
258 iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm),
259 mvm->mgmt_last_antenna_idx);
261 if (info->band == IEEE80211_BAND_2GHZ &&
262 !iwl_mvm_bt_coex_is_shared_ant_avail(mvm))
263 rate_flags = mvm->cfg->non_shared_ant << RATE_MCS_ANT_POS;
266 BIT(mvm->mgmt_last_antenna_idx) << RATE_MCS_ANT_POS;
268 /* Set CCK flag as needed */
269 if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
270 rate_flags |= RATE_MCS_CCK_MSK;
272 /* Set the rate in the TX cmd */
273 tx_cmd->rate_n_flags = cpu_to_le32((u32)rate_plcp | rate_flags);
277 * Sets the fields in the Tx cmd that are crypto related
279 static void iwl_mvm_set_tx_cmd_crypto(struct iwl_mvm *mvm,
280 struct ieee80211_tx_info *info,
281 struct iwl_tx_cmd *tx_cmd,
282 struct sk_buff *skb_frag,
285 struct ieee80211_key_conf *keyconf = info->control.hw_key;
286 u8 *crypto_hdr = skb_frag->data + hdrlen;
289 switch (keyconf->cipher) {
290 case WLAN_CIPHER_SUITE_CCMP:
291 case WLAN_CIPHER_SUITE_CCMP_256:
292 iwl_mvm_set_tx_cmd_ccmp(info, tx_cmd);
293 pn = atomic64_inc_return(&keyconf->tx_pn);
296 crypto_hdr[3] = 0x20 | (keyconf->keyidx << 6);
297 crypto_hdr[1] = pn >> 8;
298 crypto_hdr[4] = pn >> 16;
299 crypto_hdr[5] = pn >> 24;
300 crypto_hdr[6] = pn >> 32;
301 crypto_hdr[7] = pn >> 40;
304 case WLAN_CIPHER_SUITE_TKIP:
305 tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
306 pn = atomic64_inc_return(&keyconf->tx_pn);
307 ieee80211_tkip_add_iv(crypto_hdr, keyconf, pn);
308 ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key);
311 case WLAN_CIPHER_SUITE_WEP104:
312 tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
314 case WLAN_CIPHER_SUITE_WEP40:
315 tx_cmd->sec_ctl |= TX_CMD_SEC_WEP |
316 ((keyconf->keyidx << TX_CMD_SEC_WEP_KEY_IDX_POS) &
317 TX_CMD_SEC_WEP_KEY_IDX_MSK);
319 memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen);
322 tx_cmd->sec_ctl |= TX_CMD_SEC_EXT;
327 * Allocates and sets the Tx cmd the driver data pointers in the skb
329 static struct iwl_device_cmd *
330 iwl_mvm_set_tx_params(struct iwl_mvm *mvm, struct sk_buff *skb,
331 struct ieee80211_tx_info *info, int hdrlen,
332 struct ieee80211_sta *sta, u8 sta_id)
334 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
335 struct ieee80211_tx_info *skb_info = IEEE80211_SKB_CB(skb);
336 struct iwl_device_cmd *dev_cmd;
337 struct iwl_tx_cmd *tx_cmd;
339 dev_cmd = iwl_trans_alloc_tx_cmd(mvm->trans);
341 if (unlikely(!dev_cmd))
344 memset(dev_cmd, 0, sizeof(*dev_cmd));
345 dev_cmd->hdr.cmd = TX_CMD;
346 tx_cmd = (struct iwl_tx_cmd *)dev_cmd->payload;
348 if (info->control.hw_key)
349 iwl_mvm_set_tx_cmd_crypto(mvm, info, tx_cmd, skb, hdrlen);
351 iwl_mvm_set_tx_cmd(mvm, skb, tx_cmd, info, sta_id);
353 iwl_mvm_set_tx_cmd_rate(mvm, tx_cmd, info, sta, hdr->frame_control);
355 memset(&skb_info->status, 0, sizeof(skb_info->status));
356 memset(skb_info->driver_data, 0, sizeof(skb_info->driver_data));
358 skb_info->driver_data[1] = dev_cmd;
363 int iwl_mvm_tx_skb_non_sta(struct iwl_mvm *mvm, struct sk_buff *skb)
365 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
366 struct ieee80211_tx_info *skb_info = IEEE80211_SKB_CB(skb);
367 struct ieee80211_tx_info info;
368 struct iwl_device_cmd *dev_cmd;
369 struct iwl_tx_cmd *tx_cmd;
371 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
373 memcpy(&info, skb->cb, sizeof(info));
375 if (WARN_ON_ONCE(info.flags & IEEE80211_TX_CTL_AMPDU))
378 if (WARN_ON_ONCE(info.flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM &&
379 (!info.control.vif ||
380 info.hw_queue != info.control.vif->cab_queue)))
383 /* This holds the amsdu headers length */
384 skb_info->driver_data[0] = (void *)(uintptr_t)0;
387 * IWL_MVM_OFFCHANNEL_QUEUE is used for ROC packets that can be used
388 * in 2 different types of vifs, P2P & STATION. P2P uses the offchannel
389 * queue. STATION (HS2.0) uses the auxiliary context of the FW,
390 * and hence needs to be sent on the aux queue
392 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
393 info.control.vif->type == NL80211_IFTYPE_STATION)
394 IEEE80211_SKB_CB(skb)->hw_queue = mvm->aux_queue;
397 * If the interface on which the frame is sent is the P2P_DEVICE
398 * or an AP/GO interface use the broadcast station associated
399 * with it; otherwise if the interface is a managed interface
400 * use the AP station associated with it for multicast traffic
401 * (this is not possible for unicast packets as a TLDS discovery
402 * response are sent without a station entry); otherwise use the
405 sta_id = mvm->aux_sta.sta_id;
406 if (info.control.vif) {
407 struct iwl_mvm_vif *mvmvif =
408 iwl_mvm_vif_from_mac80211(info.control.vif);
410 if (info.control.vif->type == NL80211_IFTYPE_P2P_DEVICE ||
411 info.control.vif->type == NL80211_IFTYPE_AP)
412 sta_id = mvmvif->bcast_sta.sta_id;
413 else if (info.control.vif->type == NL80211_IFTYPE_STATION &&
414 is_multicast_ether_addr(hdr->addr1)) {
415 u8 ap_sta_id = ACCESS_ONCE(mvmvif->ap_sta_id);
417 if (ap_sta_id != IWL_MVM_STATION_COUNT)
422 IWL_DEBUG_TX(mvm, "station Id %d, queue=%d\n", sta_id, info.hw_queue);
424 dev_cmd = iwl_mvm_set_tx_params(mvm, skb, &info, hdrlen, NULL, sta_id);
428 tx_cmd = (struct iwl_tx_cmd *)dev_cmd->payload;
430 /* Copy MAC header from skb into command buffer */
431 memcpy(tx_cmd->hdr, hdr, hdrlen);
433 if (iwl_trans_tx(mvm->trans, skb, dev_cmd, info.hw_queue)) {
434 iwl_trans_free_tx_cmd(mvm->trans, dev_cmd);
439 * Increase the pending frames counter, so that later when a reply comes
440 * in and the counter is decreased - we don't start getting negative
442 * Note that we don't need to make sure it isn't agg'd, since we're
445 atomic_inc(&mvm->pending_frames[sta_id]);
451 static int iwl_mvm_tx_tso(struct iwl_mvm *mvm, struct sk_buff *skb,
452 struct ieee80211_tx_info *info,
453 struct ieee80211_sta *sta,
454 struct sk_buff_head *mpdus_skb)
456 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
457 struct ieee80211_hdr *hdr = (void *)skb->data;
458 unsigned int mss = skb_shinfo(skb)->gso_size;
459 struct sk_buff *tmp, *next;
460 char cb[sizeof(skb->cb)];
461 unsigned int num_subframes, tcp_payload_len, subf_len, max_amsdu_len;
462 bool ipv4 = (skb->protocol == htons(ETH_P_IP));
463 u16 ip_base_id = ipv4 ? ntohs(ip_hdr(skb)->id) : 0;
464 u16 amsdu_add, snap_ip_tcp, pad, i = 0;
465 unsigned int dbg_max_amsdu_len;
468 snap_ip_tcp = 8 + skb_transport_header(skb) - skb_network_header(skb) +
471 qc = ieee80211_get_qos_ctl(hdr);
472 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
473 if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
476 if (!sta->max_amsdu_len ||
477 !ieee80211_is_data_qos(hdr->frame_control) ||
478 !mvmsta->tlc_amsdu) {
485 * No need to lock amsdu_in_ampdu_allowed since it can't be modified
486 * during an BA session.
488 if (info->flags & IEEE80211_TX_CTL_AMPDU &&
489 !mvmsta->tid_data[tid].amsdu_in_ampdu_allowed) {
495 max_amsdu_len = sta->max_amsdu_len;
496 dbg_max_amsdu_len = ACCESS_ONCE(mvm->max_amsdu_len);
498 /* the Tx FIFO to which this A-MSDU will be routed */
499 txf = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
502 * Don't send an AMSDU that will be longer than the TXF.
503 * Add a security margin of 256 for the TX command + headers.
504 * We also want to have the start of the next packet inside the
505 * fifo to be able to send bursts.
507 max_amsdu_len = min_t(unsigned int, max_amsdu_len,
508 mvm->shared_mem_cfg.txfifo_size[txf] - 256);
510 if (dbg_max_amsdu_len)
511 max_amsdu_len = min_t(unsigned int, max_amsdu_len,
515 * Limit A-MSDU in A-MPDU to 4095 bytes when VHT is not
516 * supported. This is a spec requirement (IEEE 802.11-2015
517 * section 8.7.3 NOTE 3).
519 if (info->flags & IEEE80211_TX_CTL_AMPDU &&
520 !sta->vht_cap.vht_supported)
521 max_amsdu_len = min_t(unsigned int, max_amsdu_len, 4095);
523 /* Sub frame header + SNAP + IP header + TCP header + MSS */
524 subf_len = sizeof(struct ethhdr) + snap_ip_tcp + mss;
525 pad = (4 - subf_len) & 0x3;
528 * If we have N subframes in the A-MSDU, then the A-MSDU's size is
529 * N * subf_len + (N - 1) * pad.
531 num_subframes = (max_amsdu_len + pad) / (subf_len + pad);
532 if (num_subframes > 1)
533 *qc |= IEEE80211_QOS_CTL_A_MSDU_PRESENT;
535 tcp_payload_len = skb_tail_pointer(skb) - skb_transport_header(skb) -
536 tcp_hdrlen(skb) + skb->data_len;
539 * Make sure we have enough TBs for the A-MSDU:
540 * 2 for each subframe
541 * 1 more for each fragment
542 * 1 more for the potential data in the header
545 min_t(unsigned int, num_subframes,
546 (mvm->trans->max_skb_frags - 1 -
547 skb_shinfo(skb)->nr_frags) / 2);
549 /* This skb fits in one single A-MSDU */
550 if (num_subframes * mss >= tcp_payload_len) {
551 struct ieee80211_tx_info *skb_info = IEEE80211_SKB_CB(skb);
554 * Compute the length of all the data added for the A-MSDU.
555 * This will be used to compute the length to write in the TX
556 * command. We have: SNAP + IP + TCP for n -1 subframes and
557 * ETH header for n subframes. Note that the original skb
558 * already had one set of SNAP / IP / TCP headers.
560 num_subframes = DIV_ROUND_UP(tcp_payload_len, mss);
561 amsdu_add = num_subframes * sizeof(struct ethhdr) +
562 (num_subframes - 1) * (snap_ip_tcp + pad);
563 /* This holds the amsdu headers length */
564 skb_info->driver_data[0] = (void *)(uintptr_t)amsdu_add;
566 __skb_queue_tail(mpdus_skb, skb);
571 * Trick the segmentation function to make it
572 * create SKBs that can fit into one A-MSDU.
575 skb_shinfo(skb)->gso_size = num_subframes * mss;
576 memcpy(cb, skb->cb, sizeof(cb));
578 next = skb_gso_segment(skb, NETIF_F_CSUM_MASK | NETIF_F_SG);
579 skb_shinfo(skb)->gso_size = mss;
580 if (WARN_ON_ONCE(IS_ERR(next)))
589 memcpy(tmp->cb, cb, sizeof(tmp->cb));
591 * Compute the length of all the data added for the A-MSDU.
592 * This will be used to compute the length to write in the TX
593 * command. We have: SNAP + IP + TCP for n -1 subframes and
594 * ETH header for n subframes.
596 tcp_payload_len = skb_tail_pointer(tmp) -
597 skb_transport_header(tmp) -
598 tcp_hdrlen(tmp) + tmp->data_len;
601 ip_hdr(tmp)->id = htons(ip_base_id + i * num_subframes);
603 if (tcp_payload_len > mss) {
604 struct ieee80211_tx_info *skb_info =
605 IEEE80211_SKB_CB(tmp);
607 num_subframes = DIV_ROUND_UP(tcp_payload_len, mss);
608 amsdu_add = num_subframes * sizeof(struct ethhdr) +
609 (num_subframes - 1) * (snap_ip_tcp + pad);
610 skb_info->driver_data[0] =
611 (void *)(uintptr_t)amsdu_add;
612 skb_shinfo(tmp)->gso_size = mss;
614 qc = ieee80211_get_qos_ctl((void *)tmp->data);
617 ip_send_check(ip_hdr(tmp));
618 *qc &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT;
619 skb_shinfo(tmp)->gso_size = 0;
625 __skb_queue_tail(mpdus_skb, tmp);
631 #else /* CONFIG_INET */
632 static int iwl_mvm_tx_tso(struct iwl_mvm *mvm, struct sk_buff *skb,
633 struct ieee80211_tx_info *info,
634 struct ieee80211_sta *sta,
635 struct sk_buff_head *mpdus_skb)
637 /* Impossible to get TSO with CONFIG_INET */
645 * Sets the fields in the Tx cmd that are crypto related
647 static int iwl_mvm_tx_mpdu(struct iwl_mvm *mvm, struct sk_buff *skb,
648 struct ieee80211_tx_info *info,
649 struct ieee80211_sta *sta)
651 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
652 struct iwl_mvm_sta *mvmsta;
653 struct iwl_device_cmd *dev_cmd;
654 struct iwl_tx_cmd *tx_cmd;
657 u8 tid = IWL_MAX_TID_COUNT;
658 u8 txq_id = info->hw_queue;
659 bool is_data_qos = false, is_ampdu = false;
662 mvmsta = iwl_mvm_sta_from_mac80211(sta);
663 fc = hdr->frame_control;
664 hdrlen = ieee80211_hdrlen(fc);
666 if (WARN_ON_ONCE(!mvmsta))
669 if (WARN_ON_ONCE(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
672 dev_cmd = iwl_mvm_set_tx_params(mvm, skb, info, hdrlen,
673 sta, mvmsta->sta_id);
677 tx_cmd = (struct iwl_tx_cmd *)dev_cmd->payload;
678 /* From now on, we cannot access info->control */
681 * we handle that entirely ourselves -- for uAPSD the firmware
682 * will always send a notification, and for PS-Poll responses
683 * we'll notify mac80211 when getting frame status
685 info->flags &= ~IEEE80211_TX_STATUS_EOSP;
687 spin_lock(&mvmsta->lock);
689 if (ieee80211_is_data_qos(fc) && !ieee80211_is_qos_nullfunc(fc)) {
691 qc = ieee80211_get_qos_ctl(hdr);
692 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
693 if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
694 goto drop_unlock_sta;
696 seq_number = mvmsta->tid_data[tid].seq_number;
697 seq_number &= IEEE80211_SCTL_SEQ;
698 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
699 hdr->seq_ctrl |= cpu_to_le16(seq_number);
701 is_ampdu = info->flags & IEEE80211_TX_CTL_AMPDU;
704 /* Copy MAC header from skb into command buffer */
705 memcpy(tx_cmd->hdr, hdr, hdrlen);
707 WARN_ON_ONCE(info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM);
710 /* default to TID 0 for non-QoS packets */
711 u8 tdls_tid = tid == IWL_MAX_TID_COUNT ? 0 : tid;
713 txq_id = mvmsta->hw_queue[tid_to_mac80211_ac[tdls_tid]];
717 if (WARN_ON_ONCE(mvmsta->tid_data[tid].state != IWL_AGG_ON))
718 goto drop_unlock_sta;
719 txq_id = mvmsta->tid_data[tid].txq_id;
722 IWL_DEBUG_TX(mvm, "TX to [%d|%d] Q:%d - seq: 0x%x\n", mvmsta->sta_id,
723 tid, txq_id, IEEE80211_SEQ_TO_SN(seq_number));
725 if (iwl_trans_tx(mvm->trans, skb, dev_cmd, txq_id))
726 goto drop_unlock_sta;
728 if (is_data_qos && !ieee80211_has_morefrags(fc))
729 mvmsta->tid_data[tid].seq_number = seq_number + 0x10;
731 spin_unlock(&mvmsta->lock);
733 if (txq_id < mvm->first_agg_queue)
734 atomic_inc(&mvm->pending_frames[mvmsta->sta_id]);
739 iwl_trans_free_tx_cmd(mvm->trans, dev_cmd);
740 spin_unlock(&mvmsta->lock);
745 int iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb,
746 struct ieee80211_sta *sta)
748 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
749 struct ieee80211_tx_info *skb_info = IEEE80211_SKB_CB(skb);
750 struct ieee80211_tx_info info;
751 struct sk_buff_head mpdus_skbs;
752 unsigned int payload_len;
755 if (WARN_ON_ONCE(!mvmsta))
758 if (WARN_ON_ONCE(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
761 memcpy(&info, skb->cb, sizeof(info));
763 /* This holds the amsdu headers length */
764 skb_info->driver_data[0] = (void *)(uintptr_t)0;
766 if (!skb_is_gso(skb))
767 return iwl_mvm_tx_mpdu(mvm, skb, &info, sta);
769 payload_len = skb_tail_pointer(skb) - skb_transport_header(skb) -
770 tcp_hdrlen(skb) + skb->data_len;
772 if (payload_len <= skb_shinfo(skb)->gso_size)
773 return iwl_mvm_tx_mpdu(mvm, skb, &info, sta);
775 __skb_queue_head_init(&mpdus_skbs);
777 ret = iwl_mvm_tx_tso(mvm, skb, &info, sta, &mpdus_skbs);
781 if (WARN_ON(skb_queue_empty(&mpdus_skbs)))
784 while (!skb_queue_empty(&mpdus_skbs)) {
785 skb = __skb_dequeue(&mpdus_skbs);
787 ret = iwl_mvm_tx_mpdu(mvm, skb, &info, sta);
789 __skb_queue_purge(&mpdus_skbs);
797 static void iwl_mvm_check_ratid_empty(struct iwl_mvm *mvm,
798 struct ieee80211_sta *sta, u8 tid)
800 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
801 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
802 struct ieee80211_vif *vif = mvmsta->vif;
804 lockdep_assert_held(&mvmsta->lock);
806 if ((tid_data->state == IWL_AGG_ON ||
807 tid_data->state == IWL_EMPTYING_HW_QUEUE_DELBA) &&
808 iwl_mvm_tid_queued(tid_data) == 0) {
810 * Now that this aggregation queue is empty tell mac80211 so it
811 * knows we no longer have frames buffered for the station on
812 * this TID (for the TIM bitmap calculation.)
814 ieee80211_sta_set_buffered(sta, tid, false);
817 if (tid_data->ssn != tid_data->next_reclaimed)
820 switch (tid_data->state) {
821 case IWL_EMPTYING_HW_QUEUE_ADDBA:
822 IWL_DEBUG_TX_QUEUES(mvm,
823 "Can continue addBA flow ssn = next_recl = %d\n",
824 tid_data->next_reclaimed);
825 tid_data->state = IWL_AGG_STARTING;
826 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
829 case IWL_EMPTYING_HW_QUEUE_DELBA:
830 IWL_DEBUG_TX_QUEUES(mvm,
831 "Can continue DELBA flow ssn = next_recl = %d\n",
832 tid_data->next_reclaimed);
833 iwl_mvm_disable_txq(mvm, tid_data->txq_id,
834 vif->hw_queue[tid_to_mac80211_ac[tid]], tid,
836 tid_data->state = IWL_AGG_OFF;
837 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
845 #ifdef CONFIG_IWLWIFI_DEBUG
846 const char *iwl_mvm_get_tx_fail_reason(u32 status)
848 #define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x
849 #define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x
851 switch (status & TX_STATUS_MSK) {
852 case TX_STATUS_SUCCESS:
854 TX_STATUS_POSTPONE(DELAY);
855 TX_STATUS_POSTPONE(FEW_BYTES);
856 TX_STATUS_POSTPONE(BT_PRIO);
857 TX_STATUS_POSTPONE(QUIET_PERIOD);
858 TX_STATUS_POSTPONE(CALC_TTAK);
859 TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY);
860 TX_STATUS_FAIL(SHORT_LIMIT);
861 TX_STATUS_FAIL(LONG_LIMIT);
862 TX_STATUS_FAIL(UNDERRUN);
863 TX_STATUS_FAIL(DRAIN_FLOW);
864 TX_STATUS_FAIL(RFKILL_FLUSH);
865 TX_STATUS_FAIL(LIFE_EXPIRE);
866 TX_STATUS_FAIL(DEST_PS);
867 TX_STATUS_FAIL(HOST_ABORTED);
868 TX_STATUS_FAIL(BT_RETRY);
869 TX_STATUS_FAIL(STA_INVALID);
870 TX_STATUS_FAIL(FRAG_DROPPED);
871 TX_STATUS_FAIL(TID_DISABLE);
872 TX_STATUS_FAIL(FIFO_FLUSHED);
873 TX_STATUS_FAIL(SMALL_CF_POLL);
874 TX_STATUS_FAIL(FW_DROP);
875 TX_STATUS_FAIL(STA_COLOR_MISMATCH);
880 #undef TX_STATUS_FAIL
881 #undef TX_STATUS_POSTPONE
883 #endif /* CONFIG_IWLWIFI_DEBUG */
885 void iwl_mvm_hwrate_to_tx_rate(u32 rate_n_flags,
886 enum ieee80211_band band,
887 struct ieee80211_tx_rate *r)
889 if (rate_n_flags & RATE_HT_MCS_GF_MSK)
890 r->flags |= IEEE80211_TX_RC_GREEN_FIELD;
891 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
892 case RATE_MCS_CHAN_WIDTH_20:
894 case RATE_MCS_CHAN_WIDTH_40:
895 r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
897 case RATE_MCS_CHAN_WIDTH_80:
898 r->flags |= IEEE80211_TX_RC_80_MHZ_WIDTH;
900 case RATE_MCS_CHAN_WIDTH_160:
901 r->flags |= IEEE80211_TX_RC_160_MHZ_WIDTH;
904 if (rate_n_flags & RATE_MCS_SGI_MSK)
905 r->flags |= IEEE80211_TX_RC_SHORT_GI;
906 if (rate_n_flags & RATE_MCS_HT_MSK) {
907 r->flags |= IEEE80211_TX_RC_MCS;
908 r->idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK;
909 } else if (rate_n_flags & RATE_MCS_VHT_MSK) {
910 ieee80211_rate_set_vht(
911 r, rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK,
912 ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >>
913 RATE_VHT_MCS_NSS_POS) + 1);
914 r->flags |= IEEE80211_TX_RC_VHT_MCS;
916 r->idx = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags,
922 * translate ucode response to mac80211 tx status control values
924 static void iwl_mvm_hwrate_to_tx_status(u32 rate_n_flags,
925 struct ieee80211_tx_info *info)
927 struct ieee80211_tx_rate *r = &info->status.rates[0];
929 info->status.antenna =
930 ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
931 iwl_mvm_hwrate_to_tx_rate(rate_n_flags, info->band, r);
934 static void iwl_mvm_tx_status_check_trigger(struct iwl_mvm *mvm,
937 struct iwl_fw_dbg_trigger_tlv *trig;
938 struct iwl_fw_dbg_trigger_tx_status *status_trig;
941 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TX_STATUS))
944 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TX_STATUS);
945 status_trig = (void *)trig->data;
947 if (!iwl_fw_dbg_trigger_check_stop(mvm, NULL, trig))
950 for (i = 0; i < ARRAY_SIZE(status_trig->statuses); i++) {
951 /* don't collect on status 0 */
952 if (!status_trig->statuses[i].status)
955 if (status_trig->statuses[i].status != (status & TX_STATUS_MSK))
958 iwl_mvm_fw_dbg_collect_trig(mvm, trig,
959 "Tx status %d was received",
960 status & TX_STATUS_MSK);
965 static void iwl_mvm_rx_tx_cmd_single(struct iwl_mvm *mvm,
966 struct iwl_rx_packet *pkt)
968 struct ieee80211_sta *sta;
969 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
970 int txq_id = SEQ_TO_QUEUE(sequence);
971 struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data;
972 int sta_id = IWL_MVM_TX_RES_GET_RA(tx_resp->ra_tid);
973 int tid = IWL_MVM_TX_RES_GET_TID(tx_resp->ra_tid);
974 u32 status = le16_to_cpu(tx_resp->status.status);
975 u16 ssn = iwl_mvm_get_scd_ssn(tx_resp);
976 struct iwl_mvm_sta *mvmsta;
977 struct sk_buff_head skbs;
979 u16 next_reclaimed, seq_ctl;
982 __skb_queue_head_init(&skbs);
984 seq_ctl = le16_to_cpu(tx_resp->seq_ctl);
986 /* we can free until ssn % q.n_bd not inclusive */
987 iwl_trans_reclaim(mvm->trans, txq_id, ssn, &skbs);
989 while (!skb_queue_empty(&skbs)) {
990 struct sk_buff *skb = __skb_dequeue(&skbs);
991 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
995 iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);
997 memset(&info->status, 0, sizeof(info->status));
999 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
1001 /* inform mac80211 about what happened with the frame */
1002 switch (status & TX_STATUS_MSK) {
1003 case TX_STATUS_SUCCESS:
1004 case TX_STATUS_DIRECT_DONE:
1005 info->flags |= IEEE80211_TX_STAT_ACK;
1007 case TX_STATUS_FAIL_DEST_PS:
1008 info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
1014 iwl_mvm_tx_status_check_trigger(mvm, status);
1016 info->status.rates[0].count = tx_resp->failure_frame + 1;
1017 iwl_mvm_hwrate_to_tx_status(le32_to_cpu(tx_resp->initial_rate),
1019 info->status.status_driver_data[1] =
1020 (void *)(uintptr_t)le32_to_cpu(tx_resp->initial_rate);
1022 /* Single frame failure in an AMPDU queue => send BAR */
1023 if (txq_id >= mvm->first_agg_queue &&
1024 !(info->flags & IEEE80211_TX_STAT_ACK) &&
1025 !(info->flags & IEEE80211_TX_STAT_TX_FILTERED))
1026 info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
1028 /* W/A FW bug: seq_ctl is wrong when the status isn't success */
1029 if (status != TX_STATUS_SUCCESS) {
1030 struct ieee80211_hdr *hdr = (void *)skb->data;
1031 seq_ctl = le16_to_cpu(hdr->seq_ctrl);
1034 if (unlikely(!seq_ctl)) {
1035 struct ieee80211_hdr *hdr = (void *)skb->data;
1038 * If it is an NDP, we can't update next_reclaim since
1039 * its sequence control is 0. Note that for that same
1040 * reason, NDPs are never sent to A-MPDU'able queues
1041 * so that we can never have more than one freed frame
1042 * for a single Tx resonse (see WARN_ON below).
1044 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
1049 * TODO: this is not accurate if we are freeing more than one
1052 info->status.tx_time =
1053 le16_to_cpu(tx_resp->wireless_media_time);
1054 BUILD_BUG_ON(ARRAY_SIZE(info->status.status_driver_data) < 1);
1055 info->status.status_driver_data[0] =
1056 (void *)(uintptr_t)tx_resp->reduced_tpc;
1058 ieee80211_tx_status(mvm->hw, skb);
1061 if (txq_id >= mvm->first_agg_queue) {
1062 /* If this is an aggregation queue, we use the ssn since:
1063 * ssn = wifi seq_num % 256.
1064 * The seq_ctl is the sequence control of the packet to which
1065 * this Tx response relates. But if there is a hole in the
1066 * bitmap of the BA we received, this Tx response may allow to
1067 * reclaim the hole and all the subsequent packets that were
1068 * already acked. In that case, seq_ctl != ssn, and the next
1069 * packet to be reclaimed will be ssn and not seq_ctl. In that
1070 * case, several packets will be reclaimed even if
1073 * The ssn is the index (% 256) of the latest packet that has
1074 * treated (acked / dropped) + 1.
1076 next_reclaimed = ssn;
1078 /* The next packet to be reclaimed is the one after this one */
1079 next_reclaimed = IEEE80211_SEQ_TO_SN(seq_ctl + 0x10);
1082 IWL_DEBUG_TX_REPLY(mvm,
1083 "TXQ %d status %s (0x%08x)\n",
1084 txq_id, iwl_mvm_get_tx_fail_reason(status), status);
1086 IWL_DEBUG_TX_REPLY(mvm,
1087 "\t\t\t\tinitial_rate 0x%x retries %d, idx=%d ssn=%d next_reclaimed=0x%x seq_ctl=0x%x\n",
1088 le32_to_cpu(tx_resp->initial_rate),
1089 tx_resp->failure_frame, SEQ_TO_INDEX(sequence),
1090 ssn, next_reclaimed, seq_ctl);
1094 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1096 * sta can't be NULL otherwise it'd mean that the sta has been freed in
1097 * the firmware while we still have packets for it in the Tx queues.
1099 if (WARN_ON_ONCE(!sta))
1103 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1105 if (tid != IWL_TID_NON_QOS) {
1106 struct iwl_mvm_tid_data *tid_data =
1107 &mvmsta->tid_data[tid];
1108 bool send_eosp_ndp = false;
1110 spin_lock_bh(&mvmsta->lock);
1112 tid_data->next_reclaimed = next_reclaimed;
1113 IWL_DEBUG_TX_REPLY(mvm,
1114 "Next reclaimed packet:%d\n",
1117 IWL_DEBUG_TX_REPLY(mvm,
1118 "NDP - don't update next_reclaimed\n");
1121 iwl_mvm_check_ratid_empty(mvm, sta, tid);
1123 if (mvmsta->sleep_tx_count) {
1124 mvmsta->sleep_tx_count--;
1125 if (mvmsta->sleep_tx_count &&
1126 !iwl_mvm_tid_queued(tid_data)) {
1128 * The number of frames in the queue
1129 * dropped to 0 even if we sent less
1130 * frames than we thought we had on the
1132 * This means we had holes in the BA
1133 * window that we just filled, ask
1134 * mac80211 to send EOSP since the
1135 * firmware won't know how to do that.
1136 * Send NDP and the firmware will send
1137 * EOSP notification that will trigger
1138 * a call to ieee80211_sta_eosp().
1140 send_eosp_ndp = true;
1144 spin_unlock_bh(&mvmsta->lock);
1145 if (send_eosp_ndp) {
1146 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta,
1147 IEEE80211_FRAME_RELEASE_UAPSD,
1148 1, tid, false, false);
1149 mvmsta->sleep_tx_count = 0;
1150 ieee80211_send_eosp_nullfunc(sta, tid);
1154 if (mvmsta->next_status_eosp) {
1155 mvmsta->next_status_eosp = false;
1156 ieee80211_sta_eosp(sta);
1163 * If the txq is not an AMPDU queue, there is no chance we freed
1164 * several skbs. Check that out...
1166 if (txq_id >= mvm->first_agg_queue)
1169 /* We can't free more than one frame at once on a shared queue */
1170 WARN_ON(skb_freed > 1);
1172 /* If we have still frames for this STA nothing to do here */
1173 if (!atomic_sub_and_test(skb_freed, &mvm->pending_frames[sta_id]))
1176 if (mvmsta && mvmsta->vif->type == NL80211_IFTYPE_AP) {
1179 * If there are no pending frames for this STA and
1180 * the tx to this station is not disabled, notify
1181 * mac80211 that this station can now wake up in its
1183 * If mvmsta is not NULL, sta is valid.
1186 spin_lock_bh(&mvmsta->lock);
1188 if (!mvmsta->disable_tx)
1189 ieee80211_sta_block_awake(mvm->hw, sta, false);
1191 spin_unlock_bh(&mvmsta->lock);
1194 if (PTR_ERR(sta) == -EBUSY || PTR_ERR(sta) == -ENOENT) {
1196 * We are draining and this was the last packet - pre_rcu_remove
1197 * has been called already. We might be after the
1198 * synchronize_net already.
1199 * Don't rely on iwl_mvm_rm_sta to see the empty Tx queues.
1201 set_bit(sta_id, mvm->sta_drained);
1202 schedule_work(&mvm->sta_drained_wk);
1209 #ifdef CONFIG_IWLWIFI_DEBUG
1210 #define AGG_TX_STATE_(x) case AGG_TX_STATE_ ## x: return #x
1211 static const char *iwl_get_agg_tx_status(u16 status)
1213 switch (status & AGG_TX_STATE_STATUS_MSK) {
1214 AGG_TX_STATE_(TRANSMITTED);
1215 AGG_TX_STATE_(UNDERRUN);
1216 AGG_TX_STATE_(BT_PRIO);
1217 AGG_TX_STATE_(FEW_BYTES);
1218 AGG_TX_STATE_(ABORT);
1219 AGG_TX_STATE_(LAST_SENT_TTL);
1220 AGG_TX_STATE_(LAST_SENT_TRY_CNT);
1221 AGG_TX_STATE_(LAST_SENT_BT_KILL);
1222 AGG_TX_STATE_(SCD_QUERY);
1223 AGG_TX_STATE_(TEST_BAD_CRC32);
1224 AGG_TX_STATE_(RESPONSE);
1225 AGG_TX_STATE_(DUMP_TX);
1226 AGG_TX_STATE_(DELAY_TX);
1232 static void iwl_mvm_rx_tx_cmd_agg_dbg(struct iwl_mvm *mvm,
1233 struct iwl_rx_packet *pkt)
1235 struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data;
1236 struct agg_tx_status *frame_status = &tx_resp->status;
1239 for (i = 0; i < tx_resp->frame_count; i++) {
1240 u16 fstatus = le16_to_cpu(frame_status[i].status);
1242 IWL_DEBUG_TX_REPLY(mvm,
1243 "status %s (0x%04x), try-count (%d) seq (0x%x)\n",
1244 iwl_get_agg_tx_status(fstatus),
1245 fstatus & AGG_TX_STATE_STATUS_MSK,
1246 (fstatus & AGG_TX_STATE_TRY_CNT_MSK) >>
1247 AGG_TX_STATE_TRY_CNT_POS,
1248 le16_to_cpu(frame_status[i].sequence));
1252 static void iwl_mvm_rx_tx_cmd_agg_dbg(struct iwl_mvm *mvm,
1253 struct iwl_rx_packet *pkt)
1255 #endif /* CONFIG_IWLWIFI_DEBUG */
1257 static void iwl_mvm_rx_tx_cmd_agg(struct iwl_mvm *mvm,
1258 struct iwl_rx_packet *pkt)
1260 struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data;
1261 int sta_id = IWL_MVM_TX_RES_GET_RA(tx_resp->ra_tid);
1262 int tid = IWL_MVM_TX_RES_GET_TID(tx_resp->ra_tid);
1263 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1264 struct ieee80211_sta *sta;
1266 if (WARN_ON_ONCE(SEQ_TO_QUEUE(sequence) < mvm->first_agg_queue))
1269 if (WARN_ON_ONCE(tid == IWL_TID_NON_QOS))
1272 iwl_mvm_rx_tx_cmd_agg_dbg(mvm, pkt);
1276 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1278 if (!WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
1279 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1280 mvmsta->tid_data[tid].rate_n_flags =
1281 le32_to_cpu(tx_resp->initial_rate);
1282 mvmsta->tid_data[tid].tx_time =
1283 le16_to_cpu(tx_resp->wireless_media_time);
1289 void iwl_mvm_rx_tx_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
1291 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1292 struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data;
1294 if (tx_resp->frame_count == 1)
1295 iwl_mvm_rx_tx_cmd_single(mvm, pkt);
1297 iwl_mvm_rx_tx_cmd_agg(mvm, pkt);
1300 static void iwl_mvm_tx_info_from_ba_notif(struct ieee80211_tx_info *info,
1301 struct iwl_mvm_ba_notif *ba_notif,
1302 struct iwl_mvm_tid_data *tid_data)
1304 info->flags |= IEEE80211_TX_STAT_AMPDU;
1305 info->status.ampdu_ack_len = ba_notif->txed_2_done;
1306 info->status.ampdu_len = ba_notif->txed;
1307 iwl_mvm_hwrate_to_tx_status(tid_data->rate_n_flags,
1309 /* TODO: not accounted if the whole A-MPDU failed */
1310 info->status.tx_time = tid_data->tx_time;
1311 info->status.status_driver_data[0] =
1312 (void *)(uintptr_t)ba_notif->reduced_txp;
1313 info->status.status_driver_data[1] =
1314 (void *)(uintptr_t)tid_data->rate_n_flags;
1317 void iwl_mvm_rx_ba_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
1319 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1320 struct iwl_mvm_ba_notif *ba_notif = (void *)pkt->data;
1321 struct sk_buff_head reclaimed_skbs;
1322 struct iwl_mvm_tid_data *tid_data;
1323 struct ieee80211_sta *sta;
1324 struct iwl_mvm_sta *mvmsta;
1325 struct sk_buff *skb;
1326 int sta_id, tid, freed;
1327 /* "flow" corresponds to Tx queue */
1328 u16 scd_flow = le16_to_cpu(ba_notif->scd_flow);
1329 /* "ssn" is start of block-ack Tx window, corresponds to index
1330 * (in Tx queue's circular buffer) of first TFD/frame in window */
1331 u16 ba_resp_scd_ssn = le16_to_cpu(ba_notif->scd_ssn);
1333 sta_id = ba_notif->sta_id;
1334 tid = ba_notif->tid;
1336 if (WARN_ONCE(sta_id >= IWL_MVM_STATION_COUNT ||
1337 tid >= IWL_MAX_TID_COUNT,
1338 "sta_id %d tid %d", sta_id, tid))
1343 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1345 /* Reclaiming frames for a station that has been deleted ? */
1346 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
1351 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1352 tid_data = &mvmsta->tid_data[tid];
1354 if (tid_data->txq_id != scd_flow) {
1356 "invalid BA notification: Q %d, tid %d, flow %d\n",
1357 tid_data->txq_id, tid, scd_flow);
1362 spin_lock_bh(&mvmsta->lock);
1364 __skb_queue_head_init(&reclaimed_skbs);
1367 * Release all TFDs before the SSN, i.e. all TFDs in front of
1368 * block-ack window (we assume that they've been successfully
1369 * transmitted ... if not, it's too late anyway).
1371 iwl_trans_reclaim(mvm->trans, scd_flow, ba_resp_scd_ssn,
1374 IWL_DEBUG_TX_REPLY(mvm,
1375 "BA_NOTIFICATION Received from %pM, sta_id = %d\n",
1376 (u8 *)&ba_notif->sta_addr_lo32,
1378 IWL_DEBUG_TX_REPLY(mvm,
1379 "TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = %d, scd_ssn = %d sent:%d, acked:%d\n",
1380 ba_notif->tid, le16_to_cpu(ba_notif->seq_ctl),
1381 (unsigned long long)le64_to_cpu(ba_notif->bitmap),
1382 scd_flow, ba_resp_scd_ssn, ba_notif->txed,
1383 ba_notif->txed_2_done);
1385 IWL_DEBUG_TX_REPLY(mvm, "reduced txp from ba notif %d\n",
1386 ba_notif->reduced_txp);
1387 tid_data->next_reclaimed = ba_resp_scd_ssn;
1389 iwl_mvm_check_ratid_empty(mvm, sta, tid);
1393 skb_queue_walk(&reclaimed_skbs, skb) {
1394 struct ieee80211_hdr *hdr = (void *)skb->data;
1395 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1397 if (ieee80211_is_data_qos(hdr->frame_control))
1402 iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);
1404 memset(&info->status, 0, sizeof(info->status));
1405 /* Packet was transmitted successfully, failures come as single
1406 * frames because before failing a frame the firmware transmits
1407 * it without aggregation at least once.
1409 info->flags |= IEEE80211_TX_STAT_ACK;
1411 /* this is the first skb we deliver in this batch */
1412 /* put the rate scaling data there */
1414 iwl_mvm_tx_info_from_ba_notif(info, ba_notif, tid_data);
1417 spin_unlock_bh(&mvmsta->lock);
1419 /* We got a BA notif with 0 acked or scd_ssn didn't progress which is
1420 * possible (i.e. first MPDU in the aggregation wasn't acked)
1421 * Still it's important to update RS about sent vs. acked.
1423 if (skb_queue_empty(&reclaimed_skbs)) {
1424 struct ieee80211_tx_info ba_info = {};
1425 struct ieee80211_chanctx_conf *chanctx_conf = NULL;
1429 rcu_dereference(mvmsta->vif->chanctx_conf);
1431 if (WARN_ON_ONCE(!chanctx_conf))
1434 ba_info.band = chanctx_conf->def.chan->band;
1435 iwl_mvm_tx_info_from_ba_notif(&ba_info, ba_notif, tid_data);
1437 IWL_DEBUG_TX_REPLY(mvm, "No reclaim. Update rs directly\n");
1438 iwl_mvm_rs_tx_status(mvm, sta, tid, &ba_info);
1444 while (!skb_queue_empty(&reclaimed_skbs)) {
1445 skb = __skb_dequeue(&reclaimed_skbs);
1446 ieee80211_tx_status(mvm->hw, skb);
1451 * Note that there are transports that buffer frames before they reach
1452 * the firmware. This means that after flush_tx_path is called, the
1453 * queue might not be empty. The race-free way to handle this is to:
1454 * 1) set the station as draining
1455 * 2) flush the Tx path
1456 * 3) wait for the transport queues to be empty
1458 int iwl_mvm_flush_tx_path(struct iwl_mvm *mvm, u32 tfd_msk, u32 flags)
1461 struct iwl_tx_path_flush_cmd flush_cmd = {
1462 .queues_ctl = cpu_to_le32(tfd_msk),
1463 .flush_ctl = cpu_to_le16(DUMP_TX_FIFO_FLUSH),
1466 ret = iwl_mvm_send_cmd_pdu(mvm, TXPATH_FLUSH, flags,
1467 sizeof(flush_cmd), &flush_cmd);
1469 IWL_ERR(mvm, "Failed to send flush command (%d)\n", ret);