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
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
28 * Contact Information:
29 * Intel Linux Wireless <linuxwifi@intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *****************************************************************************/
65 #include <linux/ieee80211.h>
66 #include <linux/etherdevice.h>
67 #include <linux/tcp.h>
70 #include "iwl-trans.h"
71 #include "iwl-eeprom-parse.h"
77 iwl_mvm_bar_check_trigger(struct iwl_mvm
*mvm
, const u8
*addr
,
80 struct iwl_fw_dbg_trigger_tlv
*trig
;
81 struct iwl_fw_dbg_trigger_ba
*ba_trig
;
83 if (!iwl_fw_dbg_trigger_enabled(mvm
->fw
, FW_DBG_TRIGGER_BA
))
86 trig
= iwl_fw_dbg_get_trigger(mvm
->fw
, FW_DBG_TRIGGER_BA
);
87 ba_trig
= (void *)trig
->data
;
89 if (!iwl_fw_dbg_trigger_check_stop(mvm
, NULL
, trig
))
92 if (!(le16_to_cpu(ba_trig
->tx_bar
) & BIT(tid
)))
95 iwl_mvm_fw_dbg_collect_trig(mvm
, trig
,
96 "BAR sent to %pM, tid %d, ssn %d",
101 * Sets most of the Tx cmd's fields
103 void iwl_mvm_set_tx_cmd(struct iwl_mvm
*mvm
, struct sk_buff
*skb
,
104 struct iwl_tx_cmd
*tx_cmd
,
105 struct ieee80211_tx_info
*info
, u8 sta_id
)
107 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
108 __le16 fc
= hdr
->frame_control
;
109 u32 tx_flags
= le32_to_cpu(tx_cmd
->tx_flags
);
110 u32 len
= skb
->len
+ FCS_LEN
;
113 if (!(info
->flags
& IEEE80211_TX_CTL_NO_ACK
))
114 tx_flags
|= TX_CMD_FLG_ACK
;
116 tx_flags
&= ~TX_CMD_FLG_ACK
;
118 if (ieee80211_is_probe_resp(fc
))
119 tx_flags
|= TX_CMD_FLG_TSF
;
121 if (ieee80211_has_morefrags(fc
))
122 tx_flags
|= TX_CMD_FLG_MORE_FRAG
;
124 if (ieee80211_is_data_qos(fc
)) {
125 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
126 tx_cmd
->tid_tspec
= qc
[0] & 0xf;
127 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL
;
128 } else if (ieee80211_is_back_req(fc
)) {
129 struct ieee80211_bar
*bar
= (void *)skb
->data
;
130 u16 control
= le16_to_cpu(bar
->control
);
131 u16 ssn
= le16_to_cpu(bar
->start_seq_num
);
133 tx_flags
|= TX_CMD_FLG_ACK
| TX_CMD_FLG_BAR
;
134 tx_cmd
->tid_tspec
= (control
&
135 IEEE80211_BAR_CTRL_TID_INFO_MASK
) >>
136 IEEE80211_BAR_CTRL_TID_INFO_SHIFT
;
137 WARN_ON_ONCE(tx_cmd
->tid_tspec
>= IWL_MAX_TID_COUNT
);
138 iwl_mvm_bar_check_trigger(mvm
, bar
->ra
, tx_cmd
->tid_tspec
,
141 tx_cmd
->tid_tspec
= IWL_TID_NON_QOS
;
142 if (info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
)
143 tx_flags
|= TX_CMD_FLG_SEQ_CTL
;
145 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL
;
148 /* Default to 0 (BE) when tid_spec is set to IWL_TID_NON_QOS */
149 if (tx_cmd
->tid_tspec
< IWL_MAX_TID_COUNT
)
150 ac
= tid_to_mac80211_ac
[tx_cmd
->tid_tspec
];
152 ac
= tid_to_mac80211_ac
[0];
154 tx_flags
|= iwl_mvm_bt_coex_tx_prio(mvm
, hdr
, info
, ac
) <<
155 TX_CMD_FLG_BT_PRIO_POS
;
157 if (ieee80211_is_mgmt(fc
)) {
158 if (ieee80211_is_assoc_req(fc
) || ieee80211_is_reassoc_req(fc
))
159 tx_cmd
->pm_frame_timeout
= cpu_to_le16(PM_FRAME_ASSOC
);
160 else if (ieee80211_is_action(fc
))
161 tx_cmd
->pm_frame_timeout
= cpu_to_le16(PM_FRAME_NONE
);
163 tx_cmd
->pm_frame_timeout
= cpu_to_le16(PM_FRAME_MGMT
);
165 /* The spec allows Action frames in A-MPDU, we don't support
168 WARN_ON_ONCE(info
->flags
& IEEE80211_TX_CTL_AMPDU
);
169 } else if (info
->control
.flags
& IEEE80211_TX_CTRL_PORT_CTRL_PROTO
) {
170 tx_cmd
->pm_frame_timeout
= cpu_to_le16(PM_FRAME_MGMT
);
172 tx_cmd
->pm_frame_timeout
= cpu_to_le16(PM_FRAME_NONE
);
175 if (ieee80211_is_data(fc
) && len
> mvm
->rts_threshold
&&
176 !is_multicast_ether_addr(ieee80211_get_DA(hdr
)))
177 tx_flags
|= TX_CMD_FLG_PROT_REQUIRE
;
179 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
180 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT
) &&
181 ieee80211_action_contains_tpc(skb
))
182 tx_flags
|= TX_CMD_FLG_WRITE_TX_POWER
;
184 tx_cmd
->tx_flags
= cpu_to_le32(tx_flags
);
185 /* Total # bytes to be transmitted */
186 tx_cmd
->len
= cpu_to_le16((u16
)skb
->len
+
187 (uintptr_t)info
->driver_data
[0]);
188 tx_cmd
->next_frame_len
= 0;
189 tx_cmd
->life_time
= cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE
);
190 tx_cmd
->sta_id
= sta_id
;
194 * Sets the fields in the Tx cmd that are rate related
196 void iwl_mvm_set_tx_cmd_rate(struct iwl_mvm
*mvm
, struct iwl_tx_cmd
*tx_cmd
,
197 struct ieee80211_tx_info
*info
,
198 struct ieee80211_sta
*sta
, __le16 fc
)
204 /* Set retry limit on RTS packets */
205 tx_cmd
->rts_retry_limit
= IWL_RTS_DFAULT_RETRY_LIMIT
;
207 /* Set retry limit on DATA packets and Probe Responses*/
208 if (ieee80211_is_probe_resp(fc
)) {
209 tx_cmd
->data_retry_limit
= IWL_MGMT_DFAULT_RETRY_LIMIT
;
210 tx_cmd
->rts_retry_limit
=
211 min(tx_cmd
->data_retry_limit
, tx_cmd
->rts_retry_limit
);
212 } else if (ieee80211_is_back_req(fc
)) {
213 tx_cmd
->data_retry_limit
= IWL_BAR_DFAULT_RETRY_LIMIT
;
215 tx_cmd
->data_retry_limit
= IWL_DEFAULT_TX_RETRY
;
219 * for data packets, rate info comes from the table inside the fw. This
220 * table is controlled by LINK_QUALITY commands
223 if (ieee80211_is_data(fc
) && sta
) {
224 tx_cmd
->initial_rate_index
= 0;
225 tx_cmd
->tx_flags
|= cpu_to_le32(TX_CMD_FLG_STA_RATE
);
227 } else if (ieee80211_is_back_req(fc
)) {
229 cpu_to_le32(TX_CMD_FLG_ACK
| TX_CMD_FLG_BAR
);
232 /* HT rate doesn't make sense for a non data frame */
233 WARN_ONCE(info
->control
.rates
[0].flags
& IEEE80211_TX_RC_MCS
,
234 "Got an HT rate (flags:0x%x/mcs:%d) for a non data frame (fc:0x%x)\n",
235 info
->control
.rates
[0].flags
,
236 info
->control
.rates
[0].idx
,
239 rate_idx
= info
->control
.rates
[0].idx
;
240 /* if the rate isn't a well known legacy rate, take the lowest one */
241 if (rate_idx
< 0 || rate_idx
> IWL_RATE_COUNT_LEGACY
)
242 rate_idx
= rate_lowest_index(
243 &mvm
->nvm_data
->bands
[info
->band
], sta
);
245 /* For 5 GHZ band, remap mac80211 rate indices into driver indices */
246 if (info
->band
== IEEE80211_BAND_5GHZ
)
247 rate_idx
+= IWL_FIRST_OFDM_RATE
;
249 /* For 2.4 GHZ band, check that there is no need to remap */
250 BUILD_BUG_ON(IWL_FIRST_CCK_RATE
!= 0);
252 /* Get PLCP rate for tx_cmd->rate_n_flags */
253 rate_plcp
= iwl_mvm_mac80211_idx_to_hwrate(rate_idx
);
255 mvm
->mgmt_last_antenna_idx
=
256 iwl_mvm_next_antenna(mvm
, iwl_mvm_get_valid_tx_ant(mvm
),
257 mvm
->mgmt_last_antenna_idx
);
259 if (info
->band
== IEEE80211_BAND_2GHZ
&&
260 !iwl_mvm_bt_coex_is_shared_ant_avail(mvm
))
261 rate_flags
= mvm
->cfg
->non_shared_ant
<< RATE_MCS_ANT_POS
;
264 BIT(mvm
->mgmt_last_antenna_idx
) << RATE_MCS_ANT_POS
;
266 /* Set CCK flag as needed */
267 if ((rate_idx
>= IWL_FIRST_CCK_RATE
) && (rate_idx
<= IWL_LAST_CCK_RATE
))
268 rate_flags
|= RATE_MCS_CCK_MSK
;
270 /* Set the rate in the TX cmd */
271 tx_cmd
->rate_n_flags
= cpu_to_le32((u32
)rate_plcp
| rate_flags
);
275 * Sets the fields in the Tx cmd that are crypto related
277 static void iwl_mvm_set_tx_cmd_crypto(struct iwl_mvm
*mvm
,
278 struct ieee80211_tx_info
*info
,
279 struct iwl_tx_cmd
*tx_cmd
,
280 struct sk_buff
*skb_frag
,
283 struct ieee80211_key_conf
*keyconf
= info
->control
.hw_key
;
284 u8
*crypto_hdr
= skb_frag
->data
+ hdrlen
;
287 switch (keyconf
->cipher
) {
288 case WLAN_CIPHER_SUITE_CCMP
:
289 case WLAN_CIPHER_SUITE_CCMP_256
:
290 iwl_mvm_set_tx_cmd_ccmp(info
, tx_cmd
);
291 pn
= atomic64_inc_return(&keyconf
->tx_pn
);
294 crypto_hdr
[3] = 0x20 | (keyconf
->keyidx
<< 6);
295 crypto_hdr
[1] = pn
>> 8;
296 crypto_hdr
[4] = pn
>> 16;
297 crypto_hdr
[5] = pn
>> 24;
298 crypto_hdr
[6] = pn
>> 32;
299 crypto_hdr
[7] = pn
>> 40;
302 case WLAN_CIPHER_SUITE_TKIP
:
303 tx_cmd
->sec_ctl
= TX_CMD_SEC_TKIP
;
304 pn
= atomic64_inc_return(&keyconf
->tx_pn
);
305 ieee80211_tkip_add_iv(crypto_hdr
, keyconf
, pn
);
306 ieee80211_get_tkip_p2k(keyconf
, skb_frag
, tx_cmd
->key
);
309 case WLAN_CIPHER_SUITE_WEP104
:
310 tx_cmd
->sec_ctl
|= TX_CMD_SEC_KEY128
;
312 case WLAN_CIPHER_SUITE_WEP40
:
313 tx_cmd
->sec_ctl
|= TX_CMD_SEC_WEP
|
314 ((keyconf
->keyidx
<< TX_CMD_SEC_WEP_KEY_IDX_POS
) &
315 TX_CMD_SEC_WEP_KEY_IDX_MSK
);
317 memcpy(&tx_cmd
->key
[3], keyconf
->key
, keyconf
->keylen
);
320 tx_cmd
->sec_ctl
|= TX_CMD_SEC_EXT
;
325 * Allocates and sets the Tx cmd the driver data pointers in the skb
327 static struct iwl_device_cmd
*
328 iwl_mvm_set_tx_params(struct iwl_mvm
*mvm
, struct sk_buff
*skb
,
329 int hdrlen
, struct ieee80211_sta
*sta
, u8 sta_id
)
331 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
332 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
333 struct iwl_device_cmd
*dev_cmd
;
334 struct iwl_tx_cmd
*tx_cmd
;
336 dev_cmd
= iwl_trans_alloc_tx_cmd(mvm
->trans
);
338 if (unlikely(!dev_cmd
))
341 memset(dev_cmd
, 0, sizeof(*dev_cmd
));
342 dev_cmd
->hdr
.cmd
= TX_CMD
;
343 tx_cmd
= (struct iwl_tx_cmd
*)dev_cmd
->payload
;
345 if (info
->control
.hw_key
)
346 iwl_mvm_set_tx_cmd_crypto(mvm
, info
, tx_cmd
, skb
, hdrlen
);
348 iwl_mvm_set_tx_cmd(mvm
, skb
, tx_cmd
, info
, sta_id
);
350 iwl_mvm_set_tx_cmd_rate(mvm
, tx_cmd
, info
, sta
, hdr
->frame_control
);
352 memset(&info
->status
, 0, sizeof(info
->status
));
353 memset(info
->driver_data
, 0, sizeof(info
->driver_data
));
355 info
->driver_data
[1] = dev_cmd
;
360 int iwl_mvm_tx_skb_non_sta(struct iwl_mvm
*mvm
, struct sk_buff
*skb
)
362 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
363 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
364 struct iwl_device_cmd
*dev_cmd
;
365 struct iwl_tx_cmd
*tx_cmd
;
367 int hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
369 if (WARN_ON_ONCE(info
->flags
& IEEE80211_TX_CTL_AMPDU
))
372 if (WARN_ON_ONCE(info
->flags
& IEEE80211_TX_CTL_SEND_AFTER_DTIM
&&
373 (!info
->control
.vif
||
374 info
->hw_queue
!= info
->control
.vif
->cab_queue
)))
377 /* This holds the amsdu headers length */
378 info
->driver_data
[0] = (void *)(uintptr_t)0;
381 * IWL_MVM_OFFCHANNEL_QUEUE is used for ROC packets that can be used
382 * in 2 different types of vifs, P2P & STATION. P2P uses the offchannel
383 * queue. STATION (HS2.0) uses the auxiliary context of the FW,
384 * and hence needs to be sent on the aux queue
386 if (IEEE80211_SKB_CB(skb
)->hw_queue
== IWL_MVM_OFFCHANNEL_QUEUE
&&
387 info
->control
.vif
->type
== NL80211_IFTYPE_STATION
)
388 IEEE80211_SKB_CB(skb
)->hw_queue
= mvm
->aux_queue
;
391 * If the interface on which the frame is sent is the P2P_DEVICE
392 * or an AP/GO interface use the broadcast station associated
393 * with it; otherwise if the interface is a managed interface
394 * use the AP station associated with it for multicast traffic
395 * (this is not possible for unicast packets as a TLDS discovery
396 * response are sent without a station entry); otherwise use the
399 sta_id
= mvm
->aux_sta
.sta_id
;
400 if (info
->control
.vif
) {
401 struct iwl_mvm_vif
*mvmvif
=
402 iwl_mvm_vif_from_mac80211(info
->control
.vif
);
404 if (info
->control
.vif
->type
== NL80211_IFTYPE_P2P_DEVICE
||
405 info
->control
.vif
->type
== NL80211_IFTYPE_AP
)
406 sta_id
= mvmvif
->bcast_sta
.sta_id
;
407 else if (info
->control
.vif
->type
== NL80211_IFTYPE_STATION
&&
408 is_multicast_ether_addr(hdr
->addr1
)) {
409 u8 ap_sta_id
= ACCESS_ONCE(mvmvif
->ap_sta_id
);
411 if (ap_sta_id
!= IWL_MVM_STATION_COUNT
)
416 IWL_DEBUG_TX(mvm
, "station Id %d, queue=%d\n", sta_id
, info
->hw_queue
);
418 dev_cmd
= iwl_mvm_set_tx_params(mvm
, skb
, hdrlen
, NULL
, sta_id
);
422 /* From now on, we cannot access info->control */
423 tx_cmd
= (struct iwl_tx_cmd
*)dev_cmd
->payload
;
425 /* Copy MAC header from skb into command buffer */
426 memcpy(tx_cmd
->hdr
, hdr
, hdrlen
);
428 if (iwl_trans_tx(mvm
->trans
, skb
, dev_cmd
, info
->hw_queue
)) {
429 iwl_trans_free_tx_cmd(mvm
->trans
, dev_cmd
);
434 * Increase the pending frames counter, so that later when a reply comes
435 * in and the counter is decreased - we don't start getting negative
437 * Note that we don't need to make sure it isn't agg'd, since we're
440 atomic_inc(&mvm
->pending_frames
[sta_id
]);
446 static int iwl_mvm_tx_tso(struct iwl_mvm
*mvm
, struct sk_buff
*skb
,
447 struct ieee80211_sta
*sta
,
448 struct sk_buff_head
*mpdus_skb
)
450 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
451 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
452 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
453 unsigned int mss
= skb_shinfo(skb
)->gso_size
;
454 struct sk_buff
*tmp
, *next
;
455 char cb
[sizeof(skb
->cb
)];
456 unsigned int num_subframes
, tcp_payload_len
, subf_len
, max_amsdu_len
;
457 bool ipv4
= (skb
->protocol
== htons(ETH_P_IP
));
458 u16 ip_base_id
= ipv4
? ntohs(ip_hdr(skb
)->id
) : 0;
459 u16 amsdu_add
, snap_ip_tcp
, pad
, i
= 0;
460 unsigned int dbg_max_amsdu_len
;
463 snap_ip_tcp
= 8 + skb_transport_header(skb
) - skb_network_header(skb
) +
466 qc
= ieee80211_get_qos_ctl(hdr
);
467 tid
= *qc
& IEEE80211_QOS_CTL_TID_MASK
;
468 if (WARN_ON_ONCE(tid
>= IWL_MAX_TID_COUNT
))
471 if (!sta
->max_amsdu_len
||
472 !ieee80211_is_data_qos(hdr
->frame_control
) ||
473 !mvmsta
->tlc_amsdu
) {
480 * No need to lock amsdu_in_ampdu_allowed since it can't be modified
481 * during an BA session.
483 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
&&
484 !mvmsta
->tid_data
[tid
].amsdu_in_ampdu_allowed
) {
490 max_amsdu_len
= sta
->max_amsdu_len
;
491 dbg_max_amsdu_len
= ACCESS_ONCE(mvm
->max_amsdu_len
);
493 /* the Tx FIFO to which this A-MSDU will be routed */
494 txf
= iwl_mvm_ac_to_tx_fifo
[tid_to_mac80211_ac
[tid
]];
497 * Don't send an AMSDU that will be longer than the TXF.
498 * Add a security margin of 256 for the TX command + headers.
499 * We also want to have the start of the next packet inside the
500 * fifo to be able to send bursts.
502 max_amsdu_len
= min_t(unsigned int, max_amsdu_len
,
503 mvm
->shared_mem_cfg
.txfifo_size
[txf
] - 256);
505 if (dbg_max_amsdu_len
)
506 max_amsdu_len
= min_t(unsigned int, max_amsdu_len
,
510 * Limit A-MSDU in A-MPDU to 4095 bytes when VHT is not
511 * supported. This is a spec requirement (IEEE 802.11-2015
512 * section 8.7.3 NOTE 3).
514 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
&&
515 !sta
->vht_cap
.vht_supported
)
516 max_amsdu_len
= min_t(unsigned int, max_amsdu_len
, 4095);
518 /* Sub frame header + SNAP + IP header + TCP header + MSS */
519 subf_len
= sizeof(struct ethhdr
) + snap_ip_tcp
+ mss
;
520 pad
= (4 - subf_len
) & 0x3;
523 * If we have N subframes in the A-MSDU, then the A-MSDU's size is
524 * N * subf_len + (N - 1) * pad.
526 num_subframes
= (max_amsdu_len
+ pad
) / (subf_len
+ pad
);
527 if (num_subframes
> 1)
528 *qc
|= IEEE80211_QOS_CTL_A_MSDU_PRESENT
;
530 tcp_payload_len
= skb_tail_pointer(skb
) - skb_transport_header(skb
) -
531 tcp_hdrlen(skb
) + skb
->data_len
;
534 * Make sure we have enough TBs for the A-MSDU:
535 * 2 for each subframe
536 * 1 more for each fragment
537 * 1 more for the potential data in the header
540 min_t(unsigned int, num_subframes
,
541 (mvm
->trans
->max_skb_frags
- 1 -
542 skb_shinfo(skb
)->nr_frags
) / 2);
544 /* This skb fits in one single A-MSDU */
545 if (num_subframes
* mss
>= tcp_payload_len
) {
547 * Compute the length of all the data added for the A-MSDU.
548 * This will be used to compute the length to write in the TX
549 * command. We have: SNAP + IP + TCP for n -1 subframes and
550 * ETH header for n subframes. Note that the original skb
551 * already had one set of SNAP / IP / TCP headers.
553 num_subframes
= DIV_ROUND_UP(tcp_payload_len
, mss
);
554 info
= IEEE80211_SKB_CB(skb
);
555 amsdu_add
= num_subframes
* sizeof(struct ethhdr
) +
556 (num_subframes
- 1) * (snap_ip_tcp
+ pad
);
557 /* This holds the amsdu headers length */
558 info
->driver_data
[0] = (void *)(uintptr_t)amsdu_add
;
560 __skb_queue_tail(mpdus_skb
, skb
);
565 * Trick the segmentation function to make it
566 * create SKBs that can fit into one A-MSDU.
569 skb_shinfo(skb
)->gso_size
= num_subframes
* mss
;
570 memcpy(cb
, skb
->cb
, sizeof(cb
));
572 next
= skb_gso_segment(skb
, NETIF_F_CSUM_MASK
| NETIF_F_SG
);
573 skb_shinfo(skb
)->gso_size
= mss
;
574 if (WARN_ON_ONCE(IS_ERR(next
)))
583 memcpy(tmp
->cb
, cb
, sizeof(tmp
->cb
));
585 * Compute the length of all the data added for the A-MSDU.
586 * This will be used to compute the length to write in the TX
587 * command. We have: SNAP + IP + TCP for n -1 subframes and
588 * ETH header for n subframes.
590 tcp_payload_len
= skb_tail_pointer(tmp
) -
591 skb_transport_header(tmp
) -
592 tcp_hdrlen(tmp
) + tmp
->data_len
;
595 ip_hdr(tmp
)->id
= htons(ip_base_id
+ i
* num_subframes
);
597 if (tcp_payload_len
> mss
) {
598 num_subframes
= DIV_ROUND_UP(tcp_payload_len
, mss
);
599 info
= IEEE80211_SKB_CB(tmp
);
600 amsdu_add
= num_subframes
* sizeof(struct ethhdr
) +
601 (num_subframes
- 1) * (snap_ip_tcp
+ pad
);
602 info
->driver_data
[0] = (void *)(uintptr_t)amsdu_add
;
603 skb_shinfo(tmp
)->gso_size
= mss
;
605 qc
= ieee80211_get_qos_ctl((void *)tmp
->data
);
608 ip_send_check(ip_hdr(tmp
));
609 *qc
&= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT
;
610 skb_shinfo(tmp
)->gso_size
= 0;
616 __skb_queue_tail(mpdus_skb
, tmp
);
622 #else /* CONFIG_INET */
623 static int iwl_mvm_tx_tso(struct iwl_mvm
*mvm
, struct sk_buff
*skb
,
624 struct ieee80211_sta
*sta
,
625 struct sk_buff_head
*mpdus_skb
)
627 /* Impossible to get TSO with CONFIG_INET */
635 * Sets the fields in the Tx cmd that are crypto related
637 static int iwl_mvm_tx_mpdu(struct iwl_mvm
*mvm
, struct sk_buff
*skb
,
638 struct ieee80211_sta
*sta
)
640 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
641 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
642 struct iwl_mvm_sta
*mvmsta
;
643 struct iwl_device_cmd
*dev_cmd
;
644 struct iwl_tx_cmd
*tx_cmd
;
647 u8 tid
= IWL_MAX_TID_COUNT
;
648 u8 txq_id
= info
->hw_queue
;
649 bool is_data_qos
= false, is_ampdu
= false;
652 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
653 fc
= hdr
->frame_control
;
654 hdrlen
= ieee80211_hdrlen(fc
);
656 if (WARN_ON_ONCE(!mvmsta
))
659 if (WARN_ON_ONCE(mvmsta
->sta_id
== IWL_MVM_STATION_COUNT
))
662 dev_cmd
= iwl_mvm_set_tx_params(mvm
, skb
, hdrlen
, sta
, mvmsta
->sta_id
);
666 tx_cmd
= (struct iwl_tx_cmd
*)dev_cmd
->payload
;
667 /* From now on, we cannot access info->control */
670 * we handle that entirely ourselves -- for uAPSD the firmware
671 * will always send a notification, and for PS-Poll responses
672 * we'll notify mac80211 when getting frame status
674 info
->flags
&= ~IEEE80211_TX_STATUS_EOSP
;
676 spin_lock(&mvmsta
->lock
);
678 if (ieee80211_is_data_qos(fc
) && !ieee80211_is_qos_nullfunc(fc
)) {
680 qc
= ieee80211_get_qos_ctl(hdr
);
681 tid
= qc
[0] & IEEE80211_QOS_CTL_TID_MASK
;
682 if (WARN_ON_ONCE(tid
>= IWL_MAX_TID_COUNT
))
683 goto drop_unlock_sta
;
685 seq_number
= mvmsta
->tid_data
[tid
].seq_number
;
686 seq_number
&= IEEE80211_SCTL_SEQ
;
687 hdr
->seq_ctrl
&= cpu_to_le16(IEEE80211_SCTL_FRAG
);
688 hdr
->seq_ctrl
|= cpu_to_le16(seq_number
);
690 is_ampdu
= info
->flags
& IEEE80211_TX_CTL_AMPDU
;
693 /* Copy MAC header from skb into command buffer */
694 memcpy(tx_cmd
->hdr
, hdr
, hdrlen
);
696 WARN_ON_ONCE(info
->flags
& IEEE80211_TX_CTL_SEND_AFTER_DTIM
);
699 /* default to TID 0 for non-QoS packets */
700 u8 tdls_tid
= tid
== IWL_MAX_TID_COUNT
? 0 : tid
;
702 txq_id
= mvmsta
->hw_queue
[tid_to_mac80211_ac
[tdls_tid
]];
706 if (WARN_ON_ONCE(mvmsta
->tid_data
[tid
].state
!= IWL_AGG_ON
))
707 goto drop_unlock_sta
;
708 txq_id
= mvmsta
->tid_data
[tid
].txq_id
;
711 IWL_DEBUG_TX(mvm
, "TX to [%d|%d] Q:%d - seq: 0x%x\n", mvmsta
->sta_id
,
712 tid
, txq_id
, IEEE80211_SEQ_TO_SN(seq_number
));
714 if (iwl_trans_tx(mvm
->trans
, skb
, dev_cmd
, txq_id
))
715 goto drop_unlock_sta
;
717 if (is_data_qos
&& !ieee80211_has_morefrags(fc
))
718 mvmsta
->tid_data
[tid
].seq_number
= seq_number
+ 0x10;
720 spin_unlock(&mvmsta
->lock
);
722 if (txq_id
< mvm
->first_agg_queue
)
723 atomic_inc(&mvm
->pending_frames
[mvmsta
->sta_id
]);
728 iwl_trans_free_tx_cmd(mvm
->trans
, dev_cmd
);
729 spin_unlock(&mvmsta
->lock
);
734 int iwl_mvm_tx_skb(struct iwl_mvm
*mvm
, struct sk_buff
*skb
,
735 struct ieee80211_sta
*sta
)
737 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
738 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
739 struct sk_buff_head mpdus_skbs
;
740 unsigned int payload_len
;
743 if (WARN_ON_ONCE(!mvmsta
))
746 if (WARN_ON_ONCE(mvmsta
->sta_id
== IWL_MVM_STATION_COUNT
))
749 /* This holds the amsdu headers length */
750 info
->driver_data
[0] = (void *)(uintptr_t)0;
752 if (!skb_is_gso(skb
))
753 return iwl_mvm_tx_mpdu(mvm
, skb
, sta
);
755 payload_len
= skb_tail_pointer(skb
) - skb_transport_header(skb
) -
756 tcp_hdrlen(skb
) + skb
->data_len
;
758 if (payload_len
<= skb_shinfo(skb
)->gso_size
)
759 return iwl_mvm_tx_mpdu(mvm
, skb
, sta
);
761 __skb_queue_head_init(&mpdus_skbs
);
763 ret
= iwl_mvm_tx_tso(mvm
, skb
, sta
, &mpdus_skbs
);
767 if (WARN_ON(skb_queue_empty(&mpdus_skbs
)))
770 while (!skb_queue_empty(&mpdus_skbs
)) {
771 skb
= __skb_dequeue(&mpdus_skbs
);
773 ret
= iwl_mvm_tx_mpdu(mvm
, skb
, sta
);
775 __skb_queue_purge(&mpdus_skbs
);
783 static void iwl_mvm_check_ratid_empty(struct iwl_mvm
*mvm
,
784 struct ieee80211_sta
*sta
, u8 tid
)
786 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
787 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
788 struct ieee80211_vif
*vif
= mvmsta
->vif
;
790 lockdep_assert_held(&mvmsta
->lock
);
792 if ((tid_data
->state
== IWL_AGG_ON
||
793 tid_data
->state
== IWL_EMPTYING_HW_QUEUE_DELBA
) &&
794 iwl_mvm_tid_queued(tid_data
) == 0) {
796 * Now that this aggregation queue is empty tell mac80211 so it
797 * knows we no longer have frames buffered for the station on
798 * this TID (for the TIM bitmap calculation.)
800 ieee80211_sta_set_buffered(sta
, tid
, false);
803 if (tid_data
->ssn
!= tid_data
->next_reclaimed
)
806 switch (tid_data
->state
) {
807 case IWL_EMPTYING_HW_QUEUE_ADDBA
:
808 IWL_DEBUG_TX_QUEUES(mvm
,
809 "Can continue addBA flow ssn = next_recl = %d\n",
810 tid_data
->next_reclaimed
);
811 tid_data
->state
= IWL_AGG_STARTING
;
812 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
815 case IWL_EMPTYING_HW_QUEUE_DELBA
:
816 IWL_DEBUG_TX_QUEUES(mvm
,
817 "Can continue DELBA flow ssn = next_recl = %d\n",
818 tid_data
->next_reclaimed
);
819 iwl_mvm_disable_txq(mvm
, tid_data
->txq_id
,
820 vif
->hw_queue
[tid_to_mac80211_ac
[tid
]], tid
,
822 tid_data
->state
= IWL_AGG_OFF
;
823 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
831 #ifdef CONFIG_IWLWIFI_DEBUG
832 const char *iwl_mvm_get_tx_fail_reason(u32 status
)
834 #define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x
835 #define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x
837 switch (status
& TX_STATUS_MSK
) {
838 case TX_STATUS_SUCCESS
:
840 TX_STATUS_POSTPONE(DELAY
);
841 TX_STATUS_POSTPONE(FEW_BYTES
);
842 TX_STATUS_POSTPONE(BT_PRIO
);
843 TX_STATUS_POSTPONE(QUIET_PERIOD
);
844 TX_STATUS_POSTPONE(CALC_TTAK
);
845 TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY
);
846 TX_STATUS_FAIL(SHORT_LIMIT
);
847 TX_STATUS_FAIL(LONG_LIMIT
);
848 TX_STATUS_FAIL(UNDERRUN
);
849 TX_STATUS_FAIL(DRAIN_FLOW
);
850 TX_STATUS_FAIL(RFKILL_FLUSH
);
851 TX_STATUS_FAIL(LIFE_EXPIRE
);
852 TX_STATUS_FAIL(DEST_PS
);
853 TX_STATUS_FAIL(HOST_ABORTED
);
854 TX_STATUS_FAIL(BT_RETRY
);
855 TX_STATUS_FAIL(STA_INVALID
);
856 TX_STATUS_FAIL(FRAG_DROPPED
);
857 TX_STATUS_FAIL(TID_DISABLE
);
858 TX_STATUS_FAIL(FIFO_FLUSHED
);
859 TX_STATUS_FAIL(SMALL_CF_POLL
);
860 TX_STATUS_FAIL(FW_DROP
);
861 TX_STATUS_FAIL(STA_COLOR_MISMATCH
);
866 #undef TX_STATUS_FAIL
867 #undef TX_STATUS_POSTPONE
869 #endif /* CONFIG_IWLWIFI_DEBUG */
871 void iwl_mvm_hwrate_to_tx_rate(u32 rate_n_flags
,
872 enum ieee80211_band band
,
873 struct ieee80211_tx_rate
*r
)
875 if (rate_n_flags
& RATE_HT_MCS_GF_MSK
)
876 r
->flags
|= IEEE80211_TX_RC_GREEN_FIELD
;
877 switch (rate_n_flags
& RATE_MCS_CHAN_WIDTH_MSK
) {
878 case RATE_MCS_CHAN_WIDTH_20
:
880 case RATE_MCS_CHAN_WIDTH_40
:
881 r
->flags
|= IEEE80211_TX_RC_40_MHZ_WIDTH
;
883 case RATE_MCS_CHAN_WIDTH_80
:
884 r
->flags
|= IEEE80211_TX_RC_80_MHZ_WIDTH
;
886 case RATE_MCS_CHAN_WIDTH_160
:
887 r
->flags
|= IEEE80211_TX_RC_160_MHZ_WIDTH
;
890 if (rate_n_flags
& RATE_MCS_SGI_MSK
)
891 r
->flags
|= IEEE80211_TX_RC_SHORT_GI
;
892 if (rate_n_flags
& RATE_MCS_HT_MSK
) {
893 r
->flags
|= IEEE80211_TX_RC_MCS
;
894 r
->idx
= rate_n_flags
& RATE_HT_MCS_INDEX_MSK
;
895 } else if (rate_n_flags
& RATE_MCS_VHT_MSK
) {
896 ieee80211_rate_set_vht(
897 r
, rate_n_flags
& RATE_VHT_MCS_RATE_CODE_MSK
,
898 ((rate_n_flags
& RATE_VHT_MCS_NSS_MSK
) >>
899 RATE_VHT_MCS_NSS_POS
) + 1);
900 r
->flags
|= IEEE80211_TX_RC_VHT_MCS
;
902 r
->idx
= iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags
,
908 * translate ucode response to mac80211 tx status control values
910 static void iwl_mvm_hwrate_to_tx_status(u32 rate_n_flags
,
911 struct ieee80211_tx_info
*info
)
913 struct ieee80211_tx_rate
*r
= &info
->status
.rates
[0];
915 info
->status
.antenna
=
916 ((rate_n_flags
& RATE_MCS_ANT_ABC_MSK
) >> RATE_MCS_ANT_POS
);
917 iwl_mvm_hwrate_to_tx_rate(rate_n_flags
, info
->band
, r
);
920 static void iwl_mvm_tx_status_check_trigger(struct iwl_mvm
*mvm
,
923 struct iwl_fw_dbg_trigger_tlv
*trig
;
924 struct iwl_fw_dbg_trigger_tx_status
*status_trig
;
927 if (!iwl_fw_dbg_trigger_enabled(mvm
->fw
, FW_DBG_TRIGGER_TX_STATUS
))
930 trig
= iwl_fw_dbg_get_trigger(mvm
->fw
, FW_DBG_TRIGGER_TX_STATUS
);
931 status_trig
= (void *)trig
->data
;
933 if (!iwl_fw_dbg_trigger_check_stop(mvm
, NULL
, trig
))
936 for (i
= 0; i
< ARRAY_SIZE(status_trig
->statuses
); i
++) {
937 /* don't collect on status 0 */
938 if (!status_trig
->statuses
[i
].status
)
941 if (status_trig
->statuses
[i
].status
!= (status
& TX_STATUS_MSK
))
944 iwl_mvm_fw_dbg_collect_trig(mvm
, trig
,
945 "Tx status %d was received",
946 status
& TX_STATUS_MSK
);
951 static void iwl_mvm_rx_tx_cmd_single(struct iwl_mvm
*mvm
,
952 struct iwl_rx_packet
*pkt
)
954 struct ieee80211_sta
*sta
;
955 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
956 int txq_id
= SEQ_TO_QUEUE(sequence
);
957 struct iwl_mvm_tx_resp
*tx_resp
= (void *)pkt
->data
;
958 int sta_id
= IWL_MVM_TX_RES_GET_RA(tx_resp
->ra_tid
);
959 int tid
= IWL_MVM_TX_RES_GET_TID(tx_resp
->ra_tid
);
960 u32 status
= le16_to_cpu(tx_resp
->status
.status
);
961 u16 ssn
= iwl_mvm_get_scd_ssn(tx_resp
);
962 struct iwl_mvm_sta
*mvmsta
;
963 struct sk_buff_head skbs
;
965 u16 next_reclaimed
, seq_ctl
;
967 __skb_queue_head_init(&skbs
);
969 seq_ctl
= le16_to_cpu(tx_resp
->seq_ctl
);
971 /* we can free until ssn % q.n_bd not inclusive */
972 iwl_trans_reclaim(mvm
->trans
, txq_id
, ssn
, &skbs
);
974 while (!skb_queue_empty(&skbs
)) {
975 struct sk_buff
*skb
= __skb_dequeue(&skbs
);
976 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
980 iwl_trans_free_tx_cmd(mvm
->trans
, info
->driver_data
[1]);
982 memset(&info
->status
, 0, sizeof(info
->status
));
984 info
->flags
&= ~IEEE80211_TX_CTL_AMPDU
;
986 /* inform mac80211 about what happened with the frame */
987 switch (status
& TX_STATUS_MSK
) {
988 case TX_STATUS_SUCCESS
:
989 case TX_STATUS_DIRECT_DONE
:
990 info
->flags
|= IEEE80211_TX_STAT_ACK
;
992 case TX_STATUS_FAIL_DEST_PS
:
993 info
->flags
|= IEEE80211_TX_STAT_TX_FILTERED
;
999 iwl_mvm_tx_status_check_trigger(mvm
, status
);
1001 info
->status
.rates
[0].count
= tx_resp
->failure_frame
+ 1;
1002 iwl_mvm_hwrate_to_tx_status(le32_to_cpu(tx_resp
->initial_rate
),
1004 info
->status
.status_driver_data
[1] =
1005 (void *)(uintptr_t)le32_to_cpu(tx_resp
->initial_rate
);
1007 /* Single frame failure in an AMPDU queue => send BAR */
1008 if (txq_id
>= mvm
->first_agg_queue
&&
1009 !(info
->flags
& IEEE80211_TX_STAT_ACK
) &&
1010 !(info
->flags
& IEEE80211_TX_STAT_TX_FILTERED
))
1011 info
->flags
|= IEEE80211_TX_STAT_AMPDU_NO_BACK
;
1013 /* W/A FW bug: seq_ctl is wrong when the status isn't success */
1014 if (status
!= TX_STATUS_SUCCESS
) {
1015 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
1016 seq_ctl
= le16_to_cpu(hdr
->seq_ctrl
);
1020 * TODO: this is not accurate if we are freeing more than one
1023 info
->status
.tx_time
=
1024 le16_to_cpu(tx_resp
->wireless_media_time
);
1025 BUILD_BUG_ON(ARRAY_SIZE(info
->status
.status_driver_data
) < 1);
1026 info
->status
.status_driver_data
[0] =
1027 (void *)(uintptr_t)tx_resp
->reduced_tpc
;
1029 ieee80211_tx_status(mvm
->hw
, skb
);
1032 if (txq_id
>= mvm
->first_agg_queue
) {
1033 /* If this is an aggregation queue, we use the ssn since:
1034 * ssn = wifi seq_num % 256.
1035 * The seq_ctl is the sequence control of the packet to which
1036 * this Tx response relates. But if there is a hole in the
1037 * bitmap of the BA we received, this Tx response may allow to
1038 * reclaim the hole and all the subsequent packets that were
1039 * already acked. In that case, seq_ctl != ssn, and the next
1040 * packet to be reclaimed will be ssn and not seq_ctl. In that
1041 * case, several packets will be reclaimed even if
1044 * The ssn is the index (% 256) of the latest packet that has
1045 * treated (acked / dropped) + 1.
1047 next_reclaimed
= ssn
;
1049 /* The next packet to be reclaimed is the one after this one */
1050 next_reclaimed
= IEEE80211_SEQ_TO_SN(seq_ctl
+ 0x10);
1053 IWL_DEBUG_TX_REPLY(mvm
,
1054 "TXQ %d status %s (0x%08x)\n",
1055 txq_id
, iwl_mvm_get_tx_fail_reason(status
), status
);
1057 IWL_DEBUG_TX_REPLY(mvm
,
1058 "\t\t\t\tinitial_rate 0x%x retries %d, idx=%d ssn=%d next_reclaimed=0x%x seq_ctl=0x%x\n",
1059 le32_to_cpu(tx_resp
->initial_rate
),
1060 tx_resp
->failure_frame
, SEQ_TO_INDEX(sequence
),
1061 ssn
, next_reclaimed
, seq_ctl
);
1065 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
1067 * sta can't be NULL otherwise it'd mean that the sta has been freed in
1068 * the firmware while we still have packets for it in the Tx queues.
1070 if (WARN_ON_ONCE(!sta
))
1074 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1076 if (tid
!= IWL_TID_NON_QOS
) {
1077 struct iwl_mvm_tid_data
*tid_data
=
1078 &mvmsta
->tid_data
[tid
];
1079 bool send_eosp_ndp
= false;
1081 spin_lock_bh(&mvmsta
->lock
);
1082 tid_data
->next_reclaimed
= next_reclaimed
;
1083 IWL_DEBUG_TX_REPLY(mvm
, "Next reclaimed packet:%d\n",
1085 iwl_mvm_check_ratid_empty(mvm
, sta
, tid
);
1087 if (mvmsta
->sleep_tx_count
) {
1088 mvmsta
->sleep_tx_count
--;
1089 if (mvmsta
->sleep_tx_count
&&
1090 !iwl_mvm_tid_queued(tid_data
)) {
1092 * The number of frames in the queue
1093 * dropped to 0 even if we sent less
1094 * frames than we thought we had on the
1096 * This means we had holes in the BA
1097 * window that we just filled, ask
1098 * mac80211 to send EOSP since the
1099 * firmware won't know how to do that.
1100 * Send NDP and the firmware will send
1101 * EOSP notification that will trigger
1102 * a call to ieee80211_sta_eosp().
1104 send_eosp_ndp
= true;
1108 spin_unlock_bh(&mvmsta
->lock
);
1109 if (send_eosp_ndp
) {
1110 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
,
1111 IEEE80211_FRAME_RELEASE_UAPSD
,
1112 1, tid
, false, false);
1113 mvmsta
->sleep_tx_count
= 0;
1114 ieee80211_send_eosp_nullfunc(sta
, tid
);
1118 if (mvmsta
->next_status_eosp
) {
1119 mvmsta
->next_status_eosp
= false;
1120 ieee80211_sta_eosp(sta
);
1127 * If the txq is not an AMPDU queue, there is no chance we freed
1128 * several skbs. Check that out...
1130 if (txq_id
>= mvm
->first_agg_queue
)
1133 /* We can't free more than one frame at once on a shared queue */
1134 WARN_ON(skb_freed
> 1);
1136 /* If we have still frames for this STA nothing to do here */
1137 if (!atomic_sub_and_test(skb_freed
, &mvm
->pending_frames
[sta_id
]))
1140 if (mvmsta
&& mvmsta
->vif
->type
== NL80211_IFTYPE_AP
) {
1143 * If there are no pending frames for this STA and
1144 * the tx to this station is not disabled, notify
1145 * mac80211 that this station can now wake up in its
1147 * If mvmsta is not NULL, sta is valid.
1150 spin_lock_bh(&mvmsta
->lock
);
1152 if (!mvmsta
->disable_tx
)
1153 ieee80211_sta_block_awake(mvm
->hw
, sta
, false);
1155 spin_unlock_bh(&mvmsta
->lock
);
1158 if (PTR_ERR(sta
) == -EBUSY
|| PTR_ERR(sta
) == -ENOENT
) {
1160 * We are draining and this was the last packet - pre_rcu_remove
1161 * has been called already. We might be after the
1162 * synchronize_net already.
1163 * Don't rely on iwl_mvm_rm_sta to see the empty Tx queues.
1165 set_bit(sta_id
, mvm
->sta_drained
);
1166 schedule_work(&mvm
->sta_drained_wk
);
1173 #ifdef CONFIG_IWLWIFI_DEBUG
1174 #define AGG_TX_STATE_(x) case AGG_TX_STATE_ ## x: return #x
1175 static const char *iwl_get_agg_tx_status(u16 status
)
1177 switch (status
& AGG_TX_STATE_STATUS_MSK
) {
1178 AGG_TX_STATE_(TRANSMITTED
);
1179 AGG_TX_STATE_(UNDERRUN
);
1180 AGG_TX_STATE_(BT_PRIO
);
1181 AGG_TX_STATE_(FEW_BYTES
);
1182 AGG_TX_STATE_(ABORT
);
1183 AGG_TX_STATE_(LAST_SENT_TTL
);
1184 AGG_TX_STATE_(LAST_SENT_TRY_CNT
);
1185 AGG_TX_STATE_(LAST_SENT_BT_KILL
);
1186 AGG_TX_STATE_(SCD_QUERY
);
1187 AGG_TX_STATE_(TEST_BAD_CRC32
);
1188 AGG_TX_STATE_(RESPONSE
);
1189 AGG_TX_STATE_(DUMP_TX
);
1190 AGG_TX_STATE_(DELAY_TX
);
1196 static void iwl_mvm_rx_tx_cmd_agg_dbg(struct iwl_mvm
*mvm
,
1197 struct iwl_rx_packet
*pkt
)
1199 struct iwl_mvm_tx_resp
*tx_resp
= (void *)pkt
->data
;
1200 struct agg_tx_status
*frame_status
= &tx_resp
->status
;
1203 for (i
= 0; i
< tx_resp
->frame_count
; i
++) {
1204 u16 fstatus
= le16_to_cpu(frame_status
[i
].status
);
1206 IWL_DEBUG_TX_REPLY(mvm
,
1207 "status %s (0x%04x), try-count (%d) seq (0x%x)\n",
1208 iwl_get_agg_tx_status(fstatus
),
1209 fstatus
& AGG_TX_STATE_STATUS_MSK
,
1210 (fstatus
& AGG_TX_STATE_TRY_CNT_MSK
) >>
1211 AGG_TX_STATE_TRY_CNT_POS
,
1212 le16_to_cpu(frame_status
[i
].sequence
));
1216 static void iwl_mvm_rx_tx_cmd_agg_dbg(struct iwl_mvm
*mvm
,
1217 struct iwl_rx_packet
*pkt
)
1219 #endif /* CONFIG_IWLWIFI_DEBUG */
1221 static void iwl_mvm_rx_tx_cmd_agg(struct iwl_mvm
*mvm
,
1222 struct iwl_rx_packet
*pkt
)
1224 struct iwl_mvm_tx_resp
*tx_resp
= (void *)pkt
->data
;
1225 int sta_id
= IWL_MVM_TX_RES_GET_RA(tx_resp
->ra_tid
);
1226 int tid
= IWL_MVM_TX_RES_GET_TID(tx_resp
->ra_tid
);
1227 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
1228 struct ieee80211_sta
*sta
;
1230 if (WARN_ON_ONCE(SEQ_TO_QUEUE(sequence
) < mvm
->first_agg_queue
))
1233 if (WARN_ON_ONCE(tid
== IWL_TID_NON_QOS
))
1236 iwl_mvm_rx_tx_cmd_agg_dbg(mvm
, pkt
);
1240 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
1242 if (!WARN_ON_ONCE(IS_ERR_OR_NULL(sta
))) {
1243 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1244 mvmsta
->tid_data
[tid
].rate_n_flags
=
1245 le32_to_cpu(tx_resp
->initial_rate
);
1246 mvmsta
->tid_data
[tid
].tx_time
=
1247 le16_to_cpu(tx_resp
->wireless_media_time
);
1253 void iwl_mvm_rx_tx_cmd(struct iwl_mvm
*mvm
, struct iwl_rx_cmd_buffer
*rxb
)
1255 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1256 struct iwl_mvm_tx_resp
*tx_resp
= (void *)pkt
->data
;
1258 if (tx_resp
->frame_count
== 1)
1259 iwl_mvm_rx_tx_cmd_single(mvm
, pkt
);
1261 iwl_mvm_rx_tx_cmd_agg(mvm
, pkt
);
1264 static void iwl_mvm_tx_info_from_ba_notif(struct ieee80211_tx_info
*info
,
1265 struct iwl_mvm_ba_notif
*ba_notif
,
1266 struct iwl_mvm_tid_data
*tid_data
)
1268 info
->flags
|= IEEE80211_TX_STAT_AMPDU
;
1269 info
->status
.ampdu_ack_len
= ba_notif
->txed_2_done
;
1270 info
->status
.ampdu_len
= ba_notif
->txed
;
1271 iwl_mvm_hwrate_to_tx_status(tid_data
->rate_n_flags
,
1273 /* TODO: not accounted if the whole A-MPDU failed */
1274 info
->status
.tx_time
= tid_data
->tx_time
;
1275 info
->status
.status_driver_data
[0] =
1276 (void *)(uintptr_t)ba_notif
->reduced_txp
;
1277 info
->status
.status_driver_data
[1] =
1278 (void *)(uintptr_t)tid_data
->rate_n_flags
;
1281 void iwl_mvm_rx_ba_notif(struct iwl_mvm
*mvm
, struct iwl_rx_cmd_buffer
*rxb
)
1283 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1284 struct iwl_mvm_ba_notif
*ba_notif
= (void *)pkt
->data
;
1285 struct sk_buff_head reclaimed_skbs
;
1286 struct iwl_mvm_tid_data
*tid_data
;
1287 struct ieee80211_sta
*sta
;
1288 struct iwl_mvm_sta
*mvmsta
;
1289 struct sk_buff
*skb
;
1290 int sta_id
, tid
, freed
;
1291 /* "flow" corresponds to Tx queue */
1292 u16 scd_flow
= le16_to_cpu(ba_notif
->scd_flow
);
1293 /* "ssn" is start of block-ack Tx window, corresponds to index
1294 * (in Tx queue's circular buffer) of first TFD/frame in window */
1295 u16 ba_resp_scd_ssn
= le16_to_cpu(ba_notif
->scd_ssn
);
1297 sta_id
= ba_notif
->sta_id
;
1298 tid
= ba_notif
->tid
;
1300 if (WARN_ONCE(sta_id
>= IWL_MVM_STATION_COUNT
||
1301 tid
>= IWL_MAX_TID_COUNT
,
1302 "sta_id %d tid %d", sta_id
, tid
))
1307 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
1309 /* Reclaiming frames for a station that has been deleted ? */
1310 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta
))) {
1315 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1316 tid_data
= &mvmsta
->tid_data
[tid
];
1318 if (tid_data
->txq_id
!= scd_flow
) {
1320 "invalid BA notification: Q %d, tid %d, flow %d\n",
1321 tid_data
->txq_id
, tid
, scd_flow
);
1326 spin_lock_bh(&mvmsta
->lock
);
1328 __skb_queue_head_init(&reclaimed_skbs
);
1331 * Release all TFDs before the SSN, i.e. all TFDs in front of
1332 * block-ack window (we assume that they've been successfully
1333 * transmitted ... if not, it's too late anyway).
1335 iwl_trans_reclaim(mvm
->trans
, scd_flow
, ba_resp_scd_ssn
,
1338 IWL_DEBUG_TX_REPLY(mvm
,
1339 "BA_NOTIFICATION Received from %pM, sta_id = %d\n",
1340 (u8
*)&ba_notif
->sta_addr_lo32
,
1342 IWL_DEBUG_TX_REPLY(mvm
,
1343 "TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = %d, scd_ssn = %d sent:%d, acked:%d\n",
1344 ba_notif
->tid
, le16_to_cpu(ba_notif
->seq_ctl
),
1345 (unsigned long long)le64_to_cpu(ba_notif
->bitmap
),
1346 scd_flow
, ba_resp_scd_ssn
, ba_notif
->txed
,
1347 ba_notif
->txed_2_done
);
1349 IWL_DEBUG_TX_REPLY(mvm
, "reduced txp from ba notif %d\n",
1350 ba_notif
->reduced_txp
);
1351 tid_data
->next_reclaimed
= ba_resp_scd_ssn
;
1353 iwl_mvm_check_ratid_empty(mvm
, sta
, tid
);
1357 skb_queue_walk(&reclaimed_skbs
, skb
) {
1358 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
1359 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1361 if (ieee80211_is_data_qos(hdr
->frame_control
))
1366 iwl_trans_free_tx_cmd(mvm
->trans
, info
->driver_data
[1]);
1368 memset(&info
->status
, 0, sizeof(info
->status
));
1369 /* Packet was transmitted successfully, failures come as single
1370 * frames because before failing a frame the firmware transmits
1371 * it without aggregation at least once.
1373 info
->flags
|= IEEE80211_TX_STAT_ACK
;
1375 /* this is the first skb we deliver in this batch */
1376 /* put the rate scaling data there */
1378 iwl_mvm_tx_info_from_ba_notif(info
, ba_notif
, tid_data
);
1381 spin_unlock_bh(&mvmsta
->lock
);
1383 /* We got a BA notif with 0 acked or scd_ssn didn't progress which is
1384 * possible (i.e. first MPDU in the aggregation wasn't acked)
1385 * Still it's important to update RS about sent vs. acked.
1387 if (skb_queue_empty(&reclaimed_skbs
)) {
1388 struct ieee80211_tx_info ba_info
= {};
1389 struct ieee80211_chanctx_conf
*chanctx_conf
= NULL
;
1393 rcu_dereference(mvmsta
->vif
->chanctx_conf
);
1395 if (WARN_ON_ONCE(!chanctx_conf
))
1398 ba_info
.band
= chanctx_conf
->def
.chan
->band
;
1399 iwl_mvm_tx_info_from_ba_notif(&ba_info
, ba_notif
, tid_data
);
1401 IWL_DEBUG_TX_REPLY(mvm
, "No reclaim. Update rs directly\n");
1402 iwl_mvm_rs_tx_status(mvm
, sta
, tid
, &ba_info
);
1408 while (!skb_queue_empty(&reclaimed_skbs
)) {
1409 skb
= __skb_dequeue(&reclaimed_skbs
);
1410 ieee80211_tx_status(mvm
->hw
, skb
);
1415 * Note that there are transports that buffer frames before they reach
1416 * the firmware. This means that after flush_tx_path is called, the
1417 * queue might not be empty. The race-free way to handle this is to:
1418 * 1) set the station as draining
1419 * 2) flush the Tx path
1420 * 3) wait for the transport queues to be empty
1422 int iwl_mvm_flush_tx_path(struct iwl_mvm
*mvm
, u32 tfd_msk
, u32 flags
)
1425 struct iwl_tx_path_flush_cmd flush_cmd
= {
1426 .queues_ctl
= cpu_to_le32(tfd_msk
),
1427 .flush_ctl
= cpu_to_le16(DUMP_TX_FIFO_FLUSH
),
1430 ret
= iwl_mvm_send_cmd_pdu(mvm
, TXPATH_FLUSH
, flags
,
1431 sizeof(flush_cmd
), &flush_cmd
);
1433 IWL_ERR(mvm
, "Failed to send flush command (%d)\n", ret
);