Commit | Line | Data |
---|---|---|
8ca151b5 JB |
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 | * | |
51368bf7 | 8 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
4203263d | 9 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
8ca151b5 JB |
10 | * |
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. | |
14 | * | |
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. | |
19 | * | |
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, | |
23 | * USA | |
24 | * | |
25 | * The full GNU General Public License is included in this distribution | |
410dc5aa | 26 | * in the file called COPYING. |
8ca151b5 JB |
27 | * |
28 | * Contact Information: | |
29 | * Intel Linux Wireless <ilw@linux.intel.com> | |
30 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
31 | * | |
32 | * BSD LICENSE | |
33 | * | |
51368bf7 | 34 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
4203263d | 35 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
8ca151b5 JB |
36 | * All rights reserved. |
37 | * | |
38 | * Redistribution and use in source and binary forms, with or without | |
39 | * modification, are permitted provided that the following conditions | |
40 | * are met: | |
41 | * | |
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 | |
47 | * distribution. | |
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. | |
51 | * | |
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. | |
63 | * | |
64 | *****************************************************************************/ | |
65 | #include <linux/ieee80211.h> | |
66 | #include <linux/etherdevice.h> | |
67 | ||
68 | #include "iwl-trans.h" | |
69 | #include "iwl-eeprom-parse.h" | |
70 | #include "mvm.h" | |
71 | #include "sta.h" | |
72 | ||
4203263d EG |
73 | static void |
74 | iwl_mvm_bar_check_trigger(struct iwl_mvm *mvm, const u8 *addr, | |
75 | u16 tid, u16 ssn) | |
76 | { | |
77 | struct iwl_fw_dbg_trigger_tlv *trig; | |
78 | struct iwl_fw_dbg_trigger_ba *ba_trig; | |
79 | ||
80 | if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA)) | |
81 | return; | |
82 | ||
83 | trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA); | |
84 | ba_trig = (void *)trig->data; | |
85 | ||
86 | if (!iwl_fw_dbg_trigger_check_stop(mvm, NULL, trig)) | |
87 | return; | |
88 | ||
89 | if (!(le16_to_cpu(ba_trig->tx_bar) & BIT(tid))) | |
90 | return; | |
91 | ||
92 | iwl_mvm_fw_dbg_collect_trig(mvm, trig, | |
93 | "BAR sent to %pM, tid %d, ssn %d", | |
94 | addr, tid, ssn); | |
95 | } | |
96 | ||
8ca151b5 JB |
97 | /* |
98 | * Sets most of the Tx cmd's fields | |
99 | */ | |
6ce73e65 AN |
100 | void iwl_mvm_set_tx_cmd(struct iwl_mvm *mvm, struct sk_buff *skb, |
101 | struct iwl_tx_cmd *tx_cmd, | |
102 | struct ieee80211_tx_info *info, u8 sta_id) | |
8ca151b5 JB |
103 | { |
104 | struct ieee80211_hdr *hdr = (void *)skb->data; | |
105 | __le16 fc = hdr->frame_control; | |
106 | u32 tx_flags = le32_to_cpu(tx_cmd->tx_flags); | |
107 | u32 len = skb->len + FCS_LEN; | |
b797e3fb | 108 | u8 ac; |
8ca151b5 JB |
109 | |
110 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) | |
111 | tx_flags |= TX_CMD_FLG_ACK; | |
112 | else | |
113 | tx_flags &= ~TX_CMD_FLG_ACK; | |
114 | ||
115 | if (ieee80211_is_probe_resp(fc)) | |
116 | tx_flags |= TX_CMD_FLG_TSF; | |
8ca151b5 | 117 | |
8ca151b5 JB |
118 | if (ieee80211_has_morefrags(fc)) |
119 | tx_flags |= TX_CMD_FLG_MORE_FRAG; | |
120 | ||
121 | if (ieee80211_is_data_qos(fc)) { | |
122 | u8 *qc = ieee80211_get_qos_ctl(hdr); | |
123 | tx_cmd->tid_tspec = qc[0] & 0xf; | |
124 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL; | |
9b3b43d8 ES |
125 | } else if (ieee80211_is_back_req(fc)) { |
126 | struct ieee80211_bar *bar = (void *)skb->data; | |
127 | u16 control = le16_to_cpu(bar->control); | |
4203263d | 128 | u16 ssn = le16_to_cpu(bar->start_seq_num); |
9b3b43d8 ES |
129 | |
130 | tx_flags |= TX_CMD_FLG_ACK | TX_CMD_FLG_BAR; | |
131 | tx_cmd->tid_tspec = (control & | |
132 | IEEE80211_BAR_CTRL_TID_INFO_MASK) >> | |
133 | IEEE80211_BAR_CTRL_TID_INFO_SHIFT; | |
134 | WARN_ON_ONCE(tx_cmd->tid_tspec >= IWL_MAX_TID_COUNT); | |
4203263d EG |
135 | iwl_mvm_bar_check_trigger(mvm, bar->ra, tx_cmd->tid_tspec, |
136 | ssn); | |
8ca151b5 JB |
137 | } else { |
138 | tx_cmd->tid_tspec = IWL_TID_NON_QOS; | |
139 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) | |
140 | tx_flags |= TX_CMD_FLG_SEQ_CTL; | |
141 | else | |
142 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL; | |
143 | } | |
144 | ||
a9dc5060 ES |
145 | /* Default to 0 (BE) when tid_spec is set to IWL_TID_NON_QOS */ |
146 | if (tx_cmd->tid_tspec < IWL_MAX_TID_COUNT) | |
147 | ac = tid_to_mac80211_ac[tx_cmd->tid_tspec]; | |
148 | else | |
149 | ac = tid_to_mac80211_ac[0]; | |
150 | ||
b797e3fb EG |
151 | tx_flags |= iwl_mvm_bt_coex_tx_prio(mvm, hdr, info, ac) << |
152 | TX_CMD_FLG_BT_PRIO_POS; | |
153 | ||
8ca151b5 JB |
154 | if (ieee80211_is_mgmt(fc)) { |
155 | if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc)) | |
156 | tx_cmd->pm_frame_timeout = cpu_to_le16(3); | |
157 | else | |
158 | tx_cmd->pm_frame_timeout = cpu_to_le16(2); | |
159 | ||
160 | /* The spec allows Action frames in A-MPDU, we don't support | |
161 | * it | |
162 | */ | |
163 | WARN_ON_ONCE(info->flags & IEEE80211_TX_CTL_AMPDU); | |
63f7535d | 164 | } else if (info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO) { |
0f2ed58e | 165 | tx_cmd->pm_frame_timeout = cpu_to_le16(2); |
8ca151b5 JB |
166 | } else { |
167 | tx_cmd->pm_frame_timeout = 0; | |
168 | } | |
169 | ||
8ca151b5 JB |
170 | if (ieee80211_is_data(fc) && len > mvm->rts_threshold && |
171 | !is_multicast_ether_addr(ieee80211_get_DA(hdr))) | |
172 | tx_flags |= TX_CMD_FLG_PROT_REQUIRE; | |
173 | ||
859d914c JB |
174 | if (fw_has_capa(&mvm->fw->ucode_capa, |
175 | IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT) && | |
f1daa00e AO |
176 | ieee80211_action_contains_tpc(skb)) |
177 | tx_flags |= TX_CMD_FLG_WRITE_TX_POWER; | |
178 | ||
8ca151b5 JB |
179 | tx_cmd->tx_flags = cpu_to_le32(tx_flags); |
180 | /* Total # bytes to be transmitted */ | |
181 | tx_cmd->len = cpu_to_le16((u16)skb->len); | |
182 | tx_cmd->next_frame_len = 0; | |
183 | tx_cmd->life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE); | |
184 | tx_cmd->sta_id = sta_id; | |
185 | } | |
186 | ||
187 | /* | |
188 | * Sets the fields in the Tx cmd that are rate related | |
189 | */ | |
6ce73e65 AN |
190 | void iwl_mvm_set_tx_cmd_rate(struct iwl_mvm *mvm, struct iwl_tx_cmd *tx_cmd, |
191 | struct ieee80211_tx_info *info, | |
192 | struct ieee80211_sta *sta, __le16 fc) | |
8ca151b5 JB |
193 | { |
194 | u32 rate_flags; | |
195 | int rate_idx; | |
196 | u8 rate_plcp; | |
197 | ||
198 | /* Set retry limit on RTS packets */ | |
199 | tx_cmd->rts_retry_limit = IWL_RTS_DFAULT_RETRY_LIMIT; | |
200 | ||
201 | /* Set retry limit on DATA packets and Probe Responses*/ | |
202 | if (ieee80211_is_probe_resp(fc)) { | |
203 | tx_cmd->data_retry_limit = IWL_MGMT_DFAULT_RETRY_LIMIT; | |
204 | tx_cmd->rts_retry_limit = | |
205 | min(tx_cmd->data_retry_limit, tx_cmd->rts_retry_limit); | |
206 | } else if (ieee80211_is_back_req(fc)) { | |
207 | tx_cmd->data_retry_limit = IWL_BAR_DFAULT_RETRY_LIMIT; | |
208 | } else { | |
209 | tx_cmd->data_retry_limit = IWL_DEFAULT_TX_RETRY; | |
210 | } | |
211 | ||
212 | /* | |
e89044d7 | 213 | * for data packets, rate info comes from the table inside the fw. This |
1ffde699 | 214 | * table is controlled by LINK_QUALITY commands |
8ca151b5 JB |
215 | */ |
216 | ||
1ffde699 | 217 | if (ieee80211_is_data(fc) && sta) { |
8ca151b5 JB |
218 | tx_cmd->initial_rate_index = 0; |
219 | tx_cmd->tx_flags |= cpu_to_le32(TX_CMD_FLG_STA_RATE); | |
220 | return; | |
221 | } else if (ieee80211_is_back_req(fc)) { | |
2edc6ec6 EG |
222 | tx_cmd->tx_flags |= |
223 | cpu_to_le32(TX_CMD_FLG_ACK | TX_CMD_FLG_BAR); | |
8ca151b5 JB |
224 | } |
225 | ||
226 | /* HT rate doesn't make sense for a non data frame */ | |
227 | WARN_ONCE(info->control.rates[0].flags & IEEE80211_TX_RC_MCS, | |
f85e9d19 JB |
228 | "Got an HT rate (flags:0x%x/mcs:%d) for a non data frame (fc:0x%x)\n", |
229 | info->control.rates[0].flags, | |
230 | info->control.rates[0].idx, | |
231 | le16_to_cpu(fc)); | |
8ca151b5 JB |
232 | |
233 | rate_idx = info->control.rates[0].idx; | |
234 | /* if the rate isn't a well known legacy rate, take the lowest one */ | |
235 | if (rate_idx < 0 || rate_idx > IWL_RATE_COUNT_LEGACY) | |
236 | rate_idx = rate_lowest_index( | |
237 | &mvm->nvm_data->bands[info->band], sta); | |
238 | ||
239 | /* For 5 GHZ band, remap mac80211 rate indices into driver indices */ | |
240 | if (info->band == IEEE80211_BAND_5GHZ) | |
241 | rate_idx += IWL_FIRST_OFDM_RATE; | |
242 | ||
243 | /* For 2.4 GHZ band, check that there is no need to remap */ | |
244 | BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0); | |
245 | ||
246 | /* Get PLCP rate for tx_cmd->rate_n_flags */ | |
247 | rate_plcp = iwl_mvm_mac80211_idx_to_hwrate(rate_idx); | |
248 | ||
249 | mvm->mgmt_last_antenna_idx = | |
a0544272 | 250 | iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm), |
8ca151b5 | 251 | mvm->mgmt_last_antenna_idx); |
34c8b24f EG |
252 | |
253 | if (info->band == IEEE80211_BAND_2GHZ && | |
254 | !iwl_mvm_bt_coex_is_shared_ant_avail(mvm)) | |
bbab7582 | 255 | rate_flags = BIT(mvm->cfg->non_shared_ant) << RATE_MCS_ANT_POS; |
34c8b24f EG |
256 | else |
257 | rate_flags = | |
258 | BIT(mvm->mgmt_last_antenna_idx) << RATE_MCS_ANT_POS; | |
8ca151b5 JB |
259 | |
260 | /* Set CCK flag as needed */ | |
261 | if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE)) | |
262 | rate_flags |= RATE_MCS_CCK_MSK; | |
263 | ||
264 | /* Set the rate in the TX cmd */ | |
265 | tx_cmd->rate_n_flags = cpu_to_le32((u32)rate_plcp | rate_flags); | |
266 | } | |
267 | ||
268 | /* | |
269 | * Sets the fields in the Tx cmd that are crypto related | |
270 | */ | |
6ce73e65 AN |
271 | void iwl_mvm_set_tx_cmd_crypto(struct iwl_mvm *mvm, |
272 | struct ieee80211_tx_info *info, | |
273 | struct iwl_tx_cmd *tx_cmd, | |
274 | struct sk_buff *skb_frag) | |
8ca151b5 JB |
275 | { |
276 | struct ieee80211_key_conf *keyconf = info->control.hw_key; | |
277 | ||
278 | switch (keyconf->cipher) { | |
279 | case WLAN_CIPHER_SUITE_CCMP: | |
280 | tx_cmd->sec_ctl = TX_CMD_SEC_CCM; | |
281 | memcpy(tx_cmd->key, keyconf->key, keyconf->keylen); | |
282 | if (info->flags & IEEE80211_TX_CTL_AMPDU) | |
283 | tx_cmd->tx_flags |= cpu_to_le32(TX_CMD_FLG_CCMP_AGG); | |
284 | break; | |
285 | ||
286 | case WLAN_CIPHER_SUITE_TKIP: | |
287 | tx_cmd->sec_ctl = TX_CMD_SEC_TKIP; | |
288 | ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key); | |
289 | break; | |
290 | ||
291 | case WLAN_CIPHER_SUITE_WEP104: | |
292 | tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128; | |
293 | /* fall through */ | |
294 | case WLAN_CIPHER_SUITE_WEP40: | |
295 | tx_cmd->sec_ctl |= TX_CMD_SEC_WEP | | |
296 | ((keyconf->keyidx << TX_CMD_SEC_WEP_KEY_IDX_POS) & | |
297 | TX_CMD_SEC_WEP_KEY_IDX_MSK); | |
298 | ||
299 | memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen); | |
300 | break; | |
301 | default: | |
e36e5433 | 302 | tx_cmd->sec_ctl |= TX_CMD_SEC_EXT; |
8ca151b5 JB |
303 | } |
304 | } | |
305 | ||
306 | /* | |
307 | * Allocates and sets the Tx cmd the driver data pointers in the skb | |
308 | */ | |
309 | static struct iwl_device_cmd * | |
310 | iwl_mvm_set_tx_params(struct iwl_mvm *mvm, struct sk_buff *skb, | |
311 | struct ieee80211_sta *sta, u8 sta_id) | |
312 | { | |
313 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
314 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
315 | struct iwl_device_cmd *dev_cmd; | |
316 | struct iwl_tx_cmd *tx_cmd; | |
317 | ||
318 | dev_cmd = iwl_trans_alloc_tx_cmd(mvm->trans); | |
319 | ||
320 | if (unlikely(!dev_cmd)) | |
321 | return NULL; | |
322 | ||
323 | memset(dev_cmd, 0, sizeof(*dev_cmd)); | |
3961a61a | 324 | dev_cmd->hdr.cmd = TX_CMD; |
8ca151b5 JB |
325 | tx_cmd = (struct iwl_tx_cmd *)dev_cmd->payload; |
326 | ||
327 | if (info->control.hw_key) | |
328 | iwl_mvm_set_tx_cmd_crypto(mvm, info, tx_cmd, skb); | |
329 | ||
330 | iwl_mvm_set_tx_cmd(mvm, skb, tx_cmd, info, sta_id); | |
331 | ||
332 | iwl_mvm_set_tx_cmd_rate(mvm, tx_cmd, info, sta, hdr->frame_control); | |
333 | ||
334 | memset(&info->status, 0, sizeof(info->status)); | |
335 | ||
336 | info->driver_data[0] = NULL; | |
337 | info->driver_data[1] = dev_cmd; | |
338 | ||
339 | return dev_cmd; | |
340 | } | |
341 | ||
342 | int iwl_mvm_tx_skb_non_sta(struct iwl_mvm *mvm, struct sk_buff *skb) | |
343 | { | |
344 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
345 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
346 | struct iwl_device_cmd *dev_cmd; | |
347 | struct iwl_tx_cmd *tx_cmd; | |
348 | u8 sta_id; | |
349 | ||
350 | if (WARN_ON_ONCE(info->flags & IEEE80211_TX_CTL_AMPDU)) | |
351 | return -1; | |
352 | ||
353 | if (WARN_ON_ONCE(info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM && | |
354 | (!info->control.vif || | |
355 | info->hw_queue != info->control.vif->cab_queue))) | |
356 | return -1; | |
357 | ||
7da91b0e AM |
358 | /* |
359 | * IWL_MVM_OFFCHANNEL_QUEUE is used for ROC packets that can be used | |
360 | * in 2 different types of vifs, P2P & STATION. P2P uses the offchannel | |
361 | * queue. STATION (HS2.0) uses the auxiliary context of the FW, | |
362 | * and hence needs to be sent on the aux queue | |
363 | */ | |
364 | if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE && | |
365 | info->control.vif->type == NL80211_IFTYPE_STATION) | |
366 | IEEE80211_SKB_CB(skb)->hw_queue = mvm->aux_queue; | |
367 | ||
8ca151b5 | 368 | /* |
d0ab08d0 | 369 | * If the interface on which the frame is sent is the P2P_DEVICE |
8ca151b5 | 370 | * or an AP/GO interface use the broadcast station associated |
d0ab08d0 IP |
371 | * with it; otherwise if the interface is a managed interface |
372 | * use the AP station associated with it for multicast traffic | |
373 | * (this is not possible for unicast packets as a TLDS discovery | |
374 | * response are sent without a station entry); otherwise use the | |
375 | * AUX station. | |
8ca151b5 | 376 | */ |
d0ab08d0 IP |
377 | sta_id = mvm->aux_sta.sta_id; |
378 | if (info->control.vif) { | |
8ca151b5 JB |
379 | struct iwl_mvm_vif *mvmvif = |
380 | iwl_mvm_vif_from_mac80211(info->control.vif); | |
d0ab08d0 IP |
381 | |
382 | if (info->control.vif->type == NL80211_IFTYPE_P2P_DEVICE || | |
383 | info->control.vif->type == NL80211_IFTYPE_AP) | |
384 | sta_id = mvmvif->bcast_sta.sta_id; | |
385 | else if (info->control.vif->type == NL80211_IFTYPE_STATION && | |
386 | is_multicast_ether_addr(hdr->addr1)) { | |
387 | u8 ap_sta_id = ACCESS_ONCE(mvmvif->ap_sta_id); | |
388 | ||
389 | if (ap_sta_id != IWL_MVM_STATION_COUNT) | |
390 | sta_id = ap_sta_id; | |
391 | } | |
8ca151b5 JB |
392 | } |
393 | ||
394 | IWL_DEBUG_TX(mvm, "station Id %d, queue=%d\n", sta_id, info->hw_queue); | |
395 | ||
396 | dev_cmd = iwl_mvm_set_tx_params(mvm, skb, NULL, sta_id); | |
397 | if (!dev_cmd) | |
398 | return -1; | |
399 | ||
400 | /* From now on, we cannot access info->control */ | |
401 | tx_cmd = (struct iwl_tx_cmd *)dev_cmd->payload; | |
402 | ||
403 | /* Copy MAC header from skb into command buffer */ | |
404 | memcpy(tx_cmd->hdr, hdr, ieee80211_hdrlen(hdr->frame_control)); | |
405 | ||
406 | if (iwl_trans_tx(mvm->trans, skb, dev_cmd, info->hw_queue)) { | |
407 | iwl_trans_free_tx_cmd(mvm->trans, dev_cmd); | |
408 | return -1; | |
409 | } | |
410 | ||
411 | return 0; | |
412 | } | |
413 | ||
414 | /* | |
415 | * Sets the fields in the Tx cmd that are crypto related | |
416 | */ | |
417 | int iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb, | |
418 | struct ieee80211_sta *sta) | |
419 | { | |
420 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
421 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
422 | struct iwl_mvm_sta *mvmsta; | |
423 | struct iwl_device_cmd *dev_cmd; | |
424 | struct iwl_tx_cmd *tx_cmd; | |
425 | __le16 fc; | |
426 | u16 seq_number = 0; | |
427 | u8 tid = IWL_MAX_TID_COUNT; | |
428 | u8 txq_id = info->hw_queue; | |
429 | bool is_data_qos = false, is_ampdu = false; | |
430 | ||
5b577a90 | 431 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
432 | fc = hdr->frame_control; |
433 | ||
434 | if (WARN_ON_ONCE(!mvmsta)) | |
435 | return -1; | |
436 | ||
881acd89 | 437 | if (WARN_ON_ONCE(mvmsta->sta_id == IWL_MVM_STATION_COUNT)) |
8ca151b5 JB |
438 | return -1; |
439 | ||
440 | dev_cmd = iwl_mvm_set_tx_params(mvm, skb, sta, mvmsta->sta_id); | |
441 | if (!dev_cmd) | |
442 | goto drop; | |
443 | ||
444 | tx_cmd = (struct iwl_tx_cmd *)dev_cmd->payload; | |
445 | /* From now on, we cannot access info->control */ | |
446 | ||
3e56eadf JB |
447 | /* |
448 | * we handle that entirely ourselves -- for uAPSD the firmware | |
449 | * will always send a notification, and for PS-Poll responses | |
450 | * we'll notify mac80211 when getting frame status | |
451 | */ | |
452 | info->flags &= ~IEEE80211_TX_STATUS_EOSP; | |
453 | ||
8ca151b5 JB |
454 | spin_lock(&mvmsta->lock); |
455 | ||
456 | if (ieee80211_is_data_qos(fc) && !ieee80211_is_qos_nullfunc(fc)) { | |
457 | u8 *qc = NULL; | |
458 | qc = ieee80211_get_qos_ctl(hdr); | |
459 | tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; | |
460 | if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) | |
461 | goto drop_unlock_sta; | |
462 | ||
463 | seq_number = mvmsta->tid_data[tid].seq_number; | |
464 | seq_number &= IEEE80211_SCTL_SEQ; | |
465 | hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); | |
466 | hdr->seq_ctrl |= cpu_to_le16(seq_number); | |
8ca151b5 JB |
467 | is_data_qos = true; |
468 | is_ampdu = info->flags & IEEE80211_TX_CTL_AMPDU; | |
469 | } | |
470 | ||
471 | /* Copy MAC header from skb into command buffer */ | |
472 | memcpy(tx_cmd->hdr, hdr, ieee80211_hdrlen(fc)); | |
473 | ||
474 | WARN_ON_ONCE(info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM); | |
475 | ||
a0f6bf2a AN |
476 | if (sta->tdls) { |
477 | /* default to TID 0 for non-QoS packets */ | |
478 | u8 tdls_tid = tid == IWL_MAX_TID_COUNT ? 0 : tid; | |
479 | ||
480 | txq_id = mvmsta->hw_queue[tid_to_mac80211_ac[tdls_tid]]; | |
481 | } | |
482 | ||
8ca151b5 JB |
483 | if (is_ampdu) { |
484 | if (WARN_ON_ONCE(mvmsta->tid_data[tid].state != IWL_AGG_ON)) | |
485 | goto drop_unlock_sta; | |
486 | txq_id = mvmsta->tid_data[tid].txq_id; | |
487 | } | |
488 | ||
489 | IWL_DEBUG_TX(mvm, "TX to [%d|%d] Q:%d - seq: 0x%x\n", mvmsta->sta_id, | |
cf9d1188 | 490 | tid, txq_id, IEEE80211_SEQ_TO_SN(seq_number)); |
8ca151b5 | 491 | |
8ca151b5 JB |
492 | if (iwl_trans_tx(mvm->trans, skb, dev_cmd, txq_id)) |
493 | goto drop_unlock_sta; | |
494 | ||
495 | if (is_data_qos && !ieee80211_has_morefrags(fc)) | |
cf9d1188 | 496 | mvmsta->tid_data[tid].seq_number = seq_number + 0x10; |
8ca151b5 JB |
497 | |
498 | spin_unlock(&mvmsta->lock); | |
499 | ||
19e737c9 | 500 | if (txq_id < mvm->first_agg_queue) |
e3d4bc8c | 501 | atomic_inc(&mvm->pending_frames[mvmsta->sta_id]); |
8ca151b5 JB |
502 | |
503 | return 0; | |
504 | ||
505 | drop_unlock_sta: | |
506 | iwl_trans_free_tx_cmd(mvm->trans, dev_cmd); | |
507 | spin_unlock(&mvmsta->lock); | |
508 | drop: | |
509 | return -1; | |
510 | } | |
511 | ||
512 | static void iwl_mvm_check_ratid_empty(struct iwl_mvm *mvm, | |
513 | struct ieee80211_sta *sta, u8 tid) | |
514 | { | |
5b577a90 | 515 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
516 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
517 | struct ieee80211_vif *vif = mvmsta->vif; | |
518 | ||
519 | lockdep_assert_held(&mvmsta->lock); | |
520 | ||
3e56eadf JB |
521 | if ((tid_data->state == IWL_AGG_ON || |
522 | tid_data->state == IWL_EMPTYING_HW_QUEUE_DELBA) && | |
523 | iwl_mvm_tid_queued(tid_data) == 0) { | |
524 | /* | |
525 | * Now that this aggregation queue is empty tell mac80211 so it | |
526 | * knows we no longer have frames buffered for the station on | |
527 | * this TID (for the TIM bitmap calculation.) | |
528 | */ | |
529 | ieee80211_sta_set_buffered(sta, tid, false); | |
530 | } | |
531 | ||
8ca151b5 JB |
532 | if (tid_data->ssn != tid_data->next_reclaimed) |
533 | return; | |
534 | ||
535 | switch (tid_data->state) { | |
536 | case IWL_EMPTYING_HW_QUEUE_ADDBA: | |
537 | IWL_DEBUG_TX_QUEUES(mvm, | |
538 | "Can continue addBA flow ssn = next_recl = %d\n", | |
539 | tid_data->next_reclaimed); | |
540 | tid_data->state = IWL_AGG_STARTING; | |
541 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); | |
542 | break; | |
543 | ||
544 | case IWL_EMPTYING_HW_QUEUE_DELBA: | |
545 | IWL_DEBUG_TX_QUEUES(mvm, | |
546 | "Can continue DELBA flow ssn = next_recl = %d\n", | |
547 | tid_data->next_reclaimed); | |
0294d9ee | 548 | iwl_mvm_disable_txq(mvm, tid_data->txq_id, CMD_ASYNC); |
8ca151b5 JB |
549 | tid_data->state = IWL_AGG_OFF; |
550 | /* | |
551 | * we can't hold the mutex - but since we are after a sequence | |
3edf8ff6 | 552 | * point (call to iwl_mvm_disable_txq(), so we don't even need |
8ca151b5 JB |
553 | * a memory barrier. |
554 | */ | |
555 | mvm->queue_to_mac80211[tid_data->txq_id] = | |
556 | IWL_INVALID_MAC80211_QUEUE; | |
557 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); | |
558 | break; | |
559 | ||
560 | default: | |
561 | break; | |
562 | } | |
563 | } | |
564 | ||
565 | #ifdef CONFIG_IWLWIFI_DEBUG | |
566 | const char *iwl_mvm_get_tx_fail_reason(u32 status) | |
567 | { | |
568 | #define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x | |
569 | #define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x | |
570 | ||
571 | switch (status & TX_STATUS_MSK) { | |
572 | case TX_STATUS_SUCCESS: | |
573 | return "SUCCESS"; | |
574 | TX_STATUS_POSTPONE(DELAY); | |
575 | TX_STATUS_POSTPONE(FEW_BYTES); | |
576 | TX_STATUS_POSTPONE(BT_PRIO); | |
577 | TX_STATUS_POSTPONE(QUIET_PERIOD); | |
578 | TX_STATUS_POSTPONE(CALC_TTAK); | |
579 | TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY); | |
580 | TX_STATUS_FAIL(SHORT_LIMIT); | |
581 | TX_STATUS_FAIL(LONG_LIMIT); | |
582 | TX_STATUS_FAIL(UNDERRUN); | |
583 | TX_STATUS_FAIL(DRAIN_FLOW); | |
584 | TX_STATUS_FAIL(RFKILL_FLUSH); | |
585 | TX_STATUS_FAIL(LIFE_EXPIRE); | |
586 | TX_STATUS_FAIL(DEST_PS); | |
587 | TX_STATUS_FAIL(HOST_ABORTED); | |
588 | TX_STATUS_FAIL(BT_RETRY); | |
589 | TX_STATUS_FAIL(STA_INVALID); | |
590 | TX_STATUS_FAIL(FRAG_DROPPED); | |
591 | TX_STATUS_FAIL(TID_DISABLE); | |
592 | TX_STATUS_FAIL(FIFO_FLUSHED); | |
593 | TX_STATUS_FAIL(SMALL_CF_POLL); | |
594 | TX_STATUS_FAIL(FW_DROP); | |
595 | TX_STATUS_FAIL(STA_COLOR_MISMATCH); | |
596 | } | |
597 | ||
598 | return "UNKNOWN"; | |
599 | ||
600 | #undef TX_STATUS_FAIL | |
601 | #undef TX_STATUS_POSTPONE | |
602 | } | |
603 | #endif /* CONFIG_IWLWIFI_DEBUG */ | |
604 | ||
d310e405 ES |
605 | void iwl_mvm_hwrate_to_tx_rate(u32 rate_n_flags, |
606 | enum ieee80211_band band, | |
607 | struct ieee80211_tx_rate *r) | |
8ca151b5 | 608 | { |
8ca151b5 JB |
609 | if (rate_n_flags & RATE_HT_MCS_GF_MSK) |
610 | r->flags |= IEEE80211_TX_RC_GREEN_FIELD; | |
611 | switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { | |
612 | case RATE_MCS_CHAN_WIDTH_20: | |
613 | break; | |
614 | case RATE_MCS_CHAN_WIDTH_40: | |
615 | r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; | |
616 | break; | |
617 | case RATE_MCS_CHAN_WIDTH_80: | |
618 | r->flags |= IEEE80211_TX_RC_80_MHZ_WIDTH; | |
619 | break; | |
620 | case RATE_MCS_CHAN_WIDTH_160: | |
621 | r->flags |= IEEE80211_TX_RC_160_MHZ_WIDTH; | |
622 | break; | |
623 | } | |
624 | if (rate_n_flags & RATE_MCS_SGI_MSK) | |
625 | r->flags |= IEEE80211_TX_RC_SHORT_GI; | |
626 | if (rate_n_flags & RATE_MCS_HT_MSK) { | |
627 | r->flags |= IEEE80211_TX_RC_MCS; | |
628 | r->idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK; | |
629 | } else if (rate_n_flags & RATE_MCS_VHT_MSK) { | |
630 | ieee80211_rate_set_vht( | |
631 | r, rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK, | |
632 | ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >> | |
633 | RATE_VHT_MCS_NSS_POS) + 1); | |
634 | r->flags |= IEEE80211_TX_RC_VHT_MCS; | |
635 | } else { | |
636 | r->idx = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags, | |
d310e405 | 637 | band); |
8ca151b5 JB |
638 | } |
639 | } | |
640 | ||
d310e405 ES |
641 | /** |
642 | * translate ucode response to mac80211 tx status control values | |
643 | */ | |
644 | static void iwl_mvm_hwrate_to_tx_status(u32 rate_n_flags, | |
645 | struct ieee80211_tx_info *info) | |
646 | { | |
647 | struct ieee80211_tx_rate *r = &info->status.rates[0]; | |
648 | ||
649 | info->status.antenna = | |
650 | ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS); | |
651 | iwl_mvm_hwrate_to_tx_rate(rate_n_flags, info->band, r); | |
652 | } | |
653 | ||
8ca151b5 JB |
654 | static void iwl_mvm_rx_tx_cmd_single(struct iwl_mvm *mvm, |
655 | struct iwl_rx_packet *pkt) | |
656 | { | |
657 | struct ieee80211_sta *sta; | |
658 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); | |
659 | int txq_id = SEQ_TO_QUEUE(sequence); | |
660 | struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data; | |
661 | int sta_id = IWL_MVM_TX_RES_GET_RA(tx_resp->ra_tid); | |
662 | int tid = IWL_MVM_TX_RES_GET_TID(tx_resp->ra_tid); | |
663 | u32 status = le16_to_cpu(tx_resp->status.status); | |
664 | u16 ssn = iwl_mvm_get_scd_ssn(tx_resp); | |
665 | struct iwl_mvm_sta *mvmsta; | |
666 | struct sk_buff_head skbs; | |
667 | u8 skb_freed = 0; | |
668 | u16 next_reclaimed, seq_ctl; | |
669 | ||
670 | __skb_queue_head_init(&skbs); | |
671 | ||
672 | seq_ctl = le16_to_cpu(tx_resp->seq_ctl); | |
673 | ||
674 | /* we can free until ssn % q.n_bd not inclusive */ | |
675 | iwl_trans_reclaim(mvm->trans, txq_id, ssn, &skbs); | |
676 | ||
677 | while (!skb_queue_empty(&skbs)) { | |
678 | struct sk_buff *skb = __skb_dequeue(&skbs); | |
679 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
680 | ||
681 | skb_freed++; | |
682 | ||
683 | iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]); | |
684 | ||
685 | memset(&info->status, 0, sizeof(info->status)); | |
686 | ||
687 | info->flags &= ~IEEE80211_TX_CTL_AMPDU; | |
688 | ||
689 | /* inform mac80211 about what happened with the frame */ | |
690 | switch (status & TX_STATUS_MSK) { | |
691 | case TX_STATUS_SUCCESS: | |
692 | case TX_STATUS_DIRECT_DONE: | |
693 | info->flags |= IEEE80211_TX_STAT_ACK; | |
694 | break; | |
695 | case TX_STATUS_FAIL_DEST_PS: | |
696 | info->flags |= IEEE80211_TX_STAT_TX_FILTERED; | |
697 | break; | |
698 | default: | |
699 | break; | |
700 | } | |
701 | ||
702 | info->status.rates[0].count = tx_resp->failure_frame + 1; | |
d310e405 ES |
703 | iwl_mvm_hwrate_to_tx_status(le32_to_cpu(tx_resp->initial_rate), |
704 | info); | |
929e6ede ES |
705 | info->status.status_driver_data[1] = |
706 | (void *)(uintptr_t)le32_to_cpu(tx_resp->initial_rate); | |
8ca151b5 JB |
707 | |
708 | /* Single frame failure in an AMPDU queue => send BAR */ | |
19e737c9 | 709 | if (txq_id >= mvm->first_agg_queue && |
9ce578a5 ES |
710 | !(info->flags & IEEE80211_TX_STAT_ACK) && |
711 | !(info->flags & IEEE80211_TX_STAT_TX_FILTERED)) | |
8ca151b5 | 712 | info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK; |
8ca151b5 | 713 | |
ebea2f32 EG |
714 | /* W/A FW bug: seq_ctl is wrong when the status isn't success */ |
715 | if (status != TX_STATUS_SUCCESS) { | |
8ca151b5 JB |
716 | struct ieee80211_hdr *hdr = (void *)skb->data; |
717 | seq_ctl = le16_to_cpu(hdr->seq_ctrl); | |
718 | } | |
719 | ||
9b5452fd EG |
720 | /* |
721 | * TODO: this is not accurate if we are freeing more than one | |
722 | * packet. | |
723 | */ | |
724 | info->status.tx_time = | |
725 | le16_to_cpu(tx_resp->wireless_media_time); | |
3a84b69e EP |
726 | BUILD_BUG_ON(ARRAY_SIZE(info->status.status_driver_data) < 1); |
727 | info->status.status_driver_data[0] = | |
728 | (void *)(uintptr_t)tx_resp->reduced_tpc; | |
729 | ||
f14d6b39 | 730 | ieee80211_tx_status(mvm->hw, skb); |
8ca151b5 JB |
731 | } |
732 | ||
19e737c9 | 733 | if (txq_id >= mvm->first_agg_queue) { |
8ca151b5 JB |
734 | /* If this is an aggregation queue, we use the ssn since: |
735 | * ssn = wifi seq_num % 256. | |
736 | * The seq_ctl is the sequence control of the packet to which | |
737 | * this Tx response relates. But if there is a hole in the | |
738 | * bitmap of the BA we received, this Tx response may allow to | |
739 | * reclaim the hole and all the subsequent packets that were | |
740 | * already acked. In that case, seq_ctl != ssn, and the next | |
741 | * packet to be reclaimed will be ssn and not seq_ctl. In that | |
742 | * case, several packets will be reclaimed even if | |
743 | * frame_count = 1. | |
744 | * | |
745 | * The ssn is the index (% 256) of the latest packet that has | |
746 | * treated (acked / dropped) + 1. | |
747 | */ | |
748 | next_reclaimed = ssn; | |
749 | } else { | |
750 | /* The next packet to be reclaimed is the one after this one */ | |
9a886586 | 751 | next_reclaimed = IEEE80211_SEQ_TO_SN(seq_ctl + 0x10); |
8ca151b5 JB |
752 | } |
753 | ||
754 | IWL_DEBUG_TX_REPLY(mvm, | |
8c6e83d6 EG |
755 | "TXQ %d status %s (0x%08x)\n", |
756 | txq_id, iwl_mvm_get_tx_fail_reason(status), status); | |
757 | ||
758 | IWL_DEBUG_TX_REPLY(mvm, | |
759 | "\t\t\t\tinitial_rate 0x%x retries %d, idx=%d ssn=%d next_reclaimed=0x%x seq_ctl=0x%x\n", | |
760 | le32_to_cpu(tx_resp->initial_rate), | |
8ca151b5 JB |
761 | tx_resp->failure_frame, SEQ_TO_INDEX(sequence), |
762 | ssn, next_reclaimed, seq_ctl); | |
763 | ||
764 | rcu_read_lock(); | |
765 | ||
766 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); | |
9bb0c1ad EG |
767 | /* |
768 | * sta can't be NULL otherwise it'd mean that the sta has been freed in | |
769 | * the firmware while we still have packets for it in the Tx queues. | |
770 | */ | |
771 | if (WARN_ON_ONCE(!sta)) | |
772 | goto out; | |
8ca151b5 | 773 | |
9bb0c1ad | 774 | if (!IS_ERR(sta)) { |
5b577a90 | 775 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
776 | |
777 | if (tid != IWL_TID_NON_QOS) { | |
778 | struct iwl_mvm_tid_data *tid_data = | |
779 | &mvmsta->tid_data[tid]; | |
780 | ||
2bfb5092 | 781 | spin_lock_bh(&mvmsta->lock); |
8ca151b5 JB |
782 | tid_data->next_reclaimed = next_reclaimed; |
783 | IWL_DEBUG_TX_REPLY(mvm, "Next reclaimed packet:%d\n", | |
784 | next_reclaimed); | |
785 | iwl_mvm_check_ratid_empty(mvm, sta, tid); | |
2bfb5092 | 786 | spin_unlock_bh(&mvmsta->lock); |
8ca151b5 | 787 | } |
3e56eadf JB |
788 | |
789 | if (mvmsta->next_status_eosp) { | |
790 | mvmsta->next_status_eosp = false; | |
791 | ieee80211_sta_eosp(sta); | |
792 | } | |
8ca151b5 | 793 | } else { |
8ca151b5 JB |
794 | mvmsta = NULL; |
795 | } | |
796 | ||
797 | /* | |
798 | * If the txq is not an AMPDU queue, there is no chance we freed | |
799 | * several skbs. Check that out... | |
8ca151b5 | 800 | */ |
9bb0c1ad EG |
801 | if (txq_id >= mvm->first_agg_queue) |
802 | goto out; | |
803 | ||
804 | /* We can't free more than one frame at once on a shared queue */ | |
805 | WARN_ON(skb_freed > 1); | |
806 | ||
589a6ba4 | 807 | /* If we have still frames for this STA nothing to do here */ |
9bb0c1ad EG |
808 | if (!atomic_sub_and_test(skb_freed, &mvm->pending_frames[sta_id])) |
809 | goto out; | |
810 | ||
811 | if (mvmsta && mvmsta->vif->type == NL80211_IFTYPE_AP) { | |
003e5236 | 812 | |
9bb0c1ad | 813 | /* |
003e5236 AO |
814 | * If there are no pending frames for this STA and |
815 | * the tx to this station is not disabled, notify | |
816 | * mac80211 that this station can now wake up in its | |
9bb0c1ad EG |
817 | * STA table. |
818 | * If mvmsta is not NULL, sta is valid. | |
819 | */ | |
003e5236 AO |
820 | |
821 | spin_lock_bh(&mvmsta->lock); | |
822 | ||
823 | if (!mvmsta->disable_tx) | |
824 | ieee80211_sta_block_awake(mvm->hw, sta, false); | |
825 | ||
826 | spin_unlock_bh(&mvmsta->lock); | |
9bb0c1ad EG |
827 | } |
828 | ||
829 | if (PTR_ERR(sta) == -EBUSY || PTR_ERR(sta) == -ENOENT) { | |
830 | /* | |
831 | * We are draining and this was the last packet - pre_rcu_remove | |
832 | * has been called already. We might be after the | |
833 | * synchronize_net already. | |
834 | * Don't rely on iwl_mvm_rm_sta to see the empty Tx queues. | |
835 | */ | |
836 | set_bit(sta_id, mvm->sta_drained); | |
837 | schedule_work(&mvm->sta_drained_wk); | |
8ca151b5 JB |
838 | } |
839 | ||
9bb0c1ad | 840 | out: |
8ca151b5 JB |
841 | rcu_read_unlock(); |
842 | } | |
843 | ||
844 | #ifdef CONFIG_IWLWIFI_DEBUG | |
845 | #define AGG_TX_STATE_(x) case AGG_TX_STATE_ ## x: return #x | |
846 | static const char *iwl_get_agg_tx_status(u16 status) | |
847 | { | |
848 | switch (status & AGG_TX_STATE_STATUS_MSK) { | |
849 | AGG_TX_STATE_(TRANSMITTED); | |
850 | AGG_TX_STATE_(UNDERRUN); | |
851 | AGG_TX_STATE_(BT_PRIO); | |
852 | AGG_TX_STATE_(FEW_BYTES); | |
853 | AGG_TX_STATE_(ABORT); | |
854 | AGG_TX_STATE_(LAST_SENT_TTL); | |
855 | AGG_TX_STATE_(LAST_SENT_TRY_CNT); | |
856 | AGG_TX_STATE_(LAST_SENT_BT_KILL); | |
857 | AGG_TX_STATE_(SCD_QUERY); | |
858 | AGG_TX_STATE_(TEST_BAD_CRC32); | |
859 | AGG_TX_STATE_(RESPONSE); | |
860 | AGG_TX_STATE_(DUMP_TX); | |
861 | AGG_TX_STATE_(DELAY_TX); | |
862 | } | |
863 | ||
864 | return "UNKNOWN"; | |
865 | } | |
866 | ||
867 | static void iwl_mvm_rx_tx_cmd_agg_dbg(struct iwl_mvm *mvm, | |
868 | struct iwl_rx_packet *pkt) | |
869 | { | |
870 | struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data; | |
871 | struct agg_tx_status *frame_status = &tx_resp->status; | |
872 | int i; | |
873 | ||
874 | for (i = 0; i < tx_resp->frame_count; i++) { | |
875 | u16 fstatus = le16_to_cpu(frame_status[i].status); | |
876 | ||
877 | IWL_DEBUG_TX_REPLY(mvm, | |
878 | "status %s (0x%04x), try-count (%d) seq (0x%x)\n", | |
879 | iwl_get_agg_tx_status(fstatus), | |
880 | fstatus & AGG_TX_STATE_STATUS_MSK, | |
881 | (fstatus & AGG_TX_STATE_TRY_CNT_MSK) >> | |
882 | AGG_TX_STATE_TRY_CNT_POS, | |
883 | le16_to_cpu(frame_status[i].sequence)); | |
884 | } | |
885 | } | |
886 | #else | |
887 | static void iwl_mvm_rx_tx_cmd_agg_dbg(struct iwl_mvm *mvm, | |
888 | struct iwl_rx_packet *pkt) | |
889 | {} | |
890 | #endif /* CONFIG_IWLWIFI_DEBUG */ | |
891 | ||
892 | static void iwl_mvm_rx_tx_cmd_agg(struct iwl_mvm *mvm, | |
893 | struct iwl_rx_packet *pkt) | |
894 | { | |
895 | struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data; | |
896 | int sta_id = IWL_MVM_TX_RES_GET_RA(tx_resp->ra_tid); | |
897 | int tid = IWL_MVM_TX_RES_GET_TID(tx_resp->ra_tid); | |
898 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); | |
899 | struct ieee80211_sta *sta; | |
900 | ||
19e737c9 | 901 | if (WARN_ON_ONCE(SEQ_TO_QUEUE(sequence) < mvm->first_agg_queue)) |
8ca151b5 JB |
902 | return; |
903 | ||
904 | if (WARN_ON_ONCE(tid == IWL_TID_NON_QOS)) | |
905 | return; | |
906 | ||
907 | iwl_mvm_rx_tx_cmd_agg_dbg(mvm, pkt); | |
908 | ||
909 | rcu_read_lock(); | |
910 | ||
911 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); | |
912 | ||
913 | if (!WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) { | |
5b577a90 | 914 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
915 | mvmsta->tid_data[tid].rate_n_flags = |
916 | le32_to_cpu(tx_resp->initial_rate); | |
3a84b69e | 917 | mvmsta->tid_data[tid].reduced_tpc = tx_resp->reduced_tpc; |
9b5452fd EG |
918 | mvmsta->tid_data[tid].tx_time = |
919 | le16_to_cpu(tx_resp->wireless_media_time); | |
8ca151b5 JB |
920 | } |
921 | ||
922 | rcu_read_unlock(); | |
923 | } | |
924 | ||
0416841d | 925 | void iwl_mvm_rx_tx_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) |
8ca151b5 JB |
926 | { |
927 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
928 | struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data; | |
929 | ||
930 | if (tx_resp->frame_count == 1) | |
931 | iwl_mvm_rx_tx_cmd_single(mvm, pkt); | |
932 | else | |
933 | iwl_mvm_rx_tx_cmd_agg(mvm, pkt); | |
8ca151b5 JB |
934 | } |
935 | ||
a7130442 ES |
936 | static void iwl_mvm_tx_info_from_ba_notif(struct ieee80211_tx_info *info, |
937 | struct iwl_mvm_ba_notif *ba_notif, | |
938 | struct iwl_mvm_tid_data *tid_data) | |
939 | { | |
940 | info->flags |= IEEE80211_TX_STAT_AMPDU; | |
941 | info->status.ampdu_ack_len = ba_notif->txed_2_done; | |
942 | info->status.ampdu_len = ba_notif->txed; | |
943 | iwl_mvm_hwrate_to_tx_status(tid_data->rate_n_flags, | |
944 | info); | |
9b5452fd EG |
945 | /* TODO: not accounted if the whole A-MPDU failed */ |
946 | info->status.tx_time = tid_data->tx_time; | |
a7130442 ES |
947 | info->status.status_driver_data[0] = |
948 | (void *)(uintptr_t)tid_data->reduced_tpc; | |
929e6ede ES |
949 | info->status.status_driver_data[1] = |
950 | (void *)(uintptr_t)tid_data->rate_n_flags; | |
a7130442 ES |
951 | } |
952 | ||
0416841d | 953 | void iwl_mvm_rx_ba_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) |
8ca151b5 JB |
954 | { |
955 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
956 | struct iwl_mvm_ba_notif *ba_notif = (void *)pkt->data; | |
957 | struct sk_buff_head reclaimed_skbs; | |
958 | struct iwl_mvm_tid_data *tid_data; | |
8ca151b5 JB |
959 | struct ieee80211_sta *sta; |
960 | struct iwl_mvm_sta *mvmsta; | |
8ca151b5 JB |
961 | struct sk_buff *skb; |
962 | int sta_id, tid, freed; | |
8ca151b5 JB |
963 | /* "flow" corresponds to Tx queue */ |
964 | u16 scd_flow = le16_to_cpu(ba_notif->scd_flow); | |
8ca151b5 JB |
965 | /* "ssn" is start of block-ack Tx window, corresponds to index |
966 | * (in Tx queue's circular buffer) of first TFD/frame in window */ | |
967 | u16 ba_resp_scd_ssn = le16_to_cpu(ba_notif->scd_ssn); | |
968 | ||
969 | sta_id = ba_notif->sta_id; | |
970 | tid = ba_notif->tid; | |
971 | ||
2cee4762 ES |
972 | if (WARN_ONCE(sta_id >= IWL_MVM_STATION_COUNT || |
973 | tid >= IWL_MAX_TID_COUNT, | |
974 | "sta_id %d tid %d", sta_id, tid)) | |
0416841d | 975 | return; |
2cee4762 | 976 | |
8ca151b5 JB |
977 | rcu_read_lock(); |
978 | ||
979 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); | |
980 | ||
981 | /* Reclaiming frames for a station that has been deleted ? */ | |
982 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) { | |
983 | rcu_read_unlock(); | |
0416841d | 984 | return; |
8ca151b5 JB |
985 | } |
986 | ||
5b577a90 | 987 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
988 | tid_data = &mvmsta->tid_data[tid]; |
989 | ||
1f16ea29 JB |
990 | if (tid_data->txq_id != scd_flow) { |
991 | IWL_ERR(mvm, | |
992 | "invalid BA notification: Q %d, tid %d, flow %d\n", | |
993 | tid_data->txq_id, tid, scd_flow); | |
8ca151b5 | 994 | rcu_read_unlock(); |
0416841d | 995 | return; |
8ca151b5 JB |
996 | } |
997 | ||
2bfb5092 | 998 | spin_lock_bh(&mvmsta->lock); |
8ca151b5 JB |
999 | |
1000 | __skb_queue_head_init(&reclaimed_skbs); | |
1001 | ||
1002 | /* | |
1003 | * Release all TFDs before the SSN, i.e. all TFDs in front of | |
1004 | * block-ack window (we assume that they've been successfully | |
1005 | * transmitted ... if not, it's too late anyway). | |
1006 | */ | |
1007 | iwl_trans_reclaim(mvm->trans, scd_flow, ba_resp_scd_ssn, | |
1008 | &reclaimed_skbs); | |
1009 | ||
1010 | IWL_DEBUG_TX_REPLY(mvm, | |
1011 | "BA_NOTIFICATION Received from %pM, sta_id = %d\n", | |
1012 | (u8 *)&ba_notif->sta_addr_lo32, | |
1013 | ba_notif->sta_id); | |
1014 | IWL_DEBUG_TX_REPLY(mvm, | |
1015 | "TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = %d, scd_ssn = %d sent:%d, acked:%d\n", | |
1016 | ba_notif->tid, le16_to_cpu(ba_notif->seq_ctl), | |
1017 | (unsigned long long)le64_to_cpu(ba_notif->bitmap), | |
1018 | scd_flow, ba_resp_scd_ssn, ba_notif->txed, | |
1019 | ba_notif->txed_2_done); | |
1020 | ||
1021 | tid_data->next_reclaimed = ba_resp_scd_ssn; | |
1022 | ||
1023 | iwl_mvm_check_ratid_empty(mvm, sta, tid); | |
1024 | ||
1025 | freed = 0; | |
1026 | ||
1027 | skb_queue_walk(&reclaimed_skbs, skb) { | |
143582c6 JB |
1028 | struct ieee80211_hdr *hdr = (void *)skb->data; |
1029 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
8ca151b5 JB |
1030 | |
1031 | if (ieee80211_is_data_qos(hdr->frame_control)) | |
1032 | freed++; | |
1033 | else | |
1034 | WARN_ON_ONCE(1); | |
1035 | ||
8ca151b5 JB |
1036 | iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]); |
1037 | ||
143582c6 JB |
1038 | memset(&info->status, 0, sizeof(info->status)); |
1039 | /* Packet was transmitted successfully, failures come as single | |
1040 | * frames because before failing a frame the firmware transmits | |
1041 | * it without aggregation at least once. | |
1042 | */ | |
1043 | info->flags |= IEEE80211_TX_STAT_ACK; | |
1044 | ||
a7130442 ES |
1045 | /* this is the first skb we deliver in this batch */ |
1046 | /* put the rate scaling data there */ | |
1047 | if (freed == 1) | |
1048 | iwl_mvm_tx_info_from_ba_notif(info, ba_notif, tid_data); | |
8ca151b5 JB |
1049 | } |
1050 | ||
2bfb5092 | 1051 | spin_unlock_bh(&mvmsta->lock); |
8ca151b5 | 1052 | |
a7130442 ES |
1053 | /* We got a BA notif with 0 acked or scd_ssn didn't progress which is |
1054 | * possible (i.e. first MPDU in the aggregation wasn't acked) | |
1055 | * Still it's important to update RS about sent vs. acked. | |
1056 | */ | |
1057 | if (skb_queue_empty(&reclaimed_skbs)) { | |
1058 | struct ieee80211_tx_info ba_info = {}; | |
1059 | struct ieee80211_chanctx_conf *chanctx_conf = NULL; | |
1060 | ||
1061 | if (mvmsta->vif) | |
1062 | chanctx_conf = | |
1063 | rcu_dereference(mvmsta->vif->chanctx_conf); | |
1064 | ||
1065 | if (WARN_ON_ONCE(!chanctx_conf)) | |
1066 | goto out; | |
1067 | ||
1068 | ba_info.band = chanctx_conf->def.chan->band; | |
1069 | iwl_mvm_tx_info_from_ba_notif(&ba_info, ba_notif, tid_data); | |
1070 | ||
1071 | IWL_DEBUG_TX_REPLY(mvm, "No reclaim. Update rs directly\n"); | |
1072 | iwl_mvm_rs_tx_status(mvm, sta, tid, &ba_info); | |
1073 | } | |
1074 | ||
1075 | out: | |
8ca151b5 JB |
1076 | rcu_read_unlock(); |
1077 | ||
1078 | while (!skb_queue_empty(&reclaimed_skbs)) { | |
1079 | skb = __skb_dequeue(&reclaimed_skbs); | |
f14d6b39 | 1080 | ieee80211_tx_status(mvm->hw, skb); |
8ca151b5 | 1081 | } |
8ca151b5 JB |
1082 | } |
1083 | ||
fe92e32a EG |
1084 | /* |
1085 | * Note that there are transports that buffer frames before they reach | |
1086 | * the firmware. This means that after flush_tx_path is called, the | |
1087 | * queue might not be empty. The race-free way to handle this is to: | |
1088 | * 1) set the station as draining | |
1089 | * 2) flush the Tx path | |
1090 | * 3) wait for the transport queues to be empty | |
1091 | */ | |
8ca151b5 JB |
1092 | int iwl_mvm_flush_tx_path(struct iwl_mvm *mvm, u32 tfd_msk, bool sync) |
1093 | { | |
1094 | int ret; | |
1095 | struct iwl_tx_path_flush_cmd flush_cmd = { | |
1096 | .queues_ctl = cpu_to_le32(tfd_msk), | |
1097 | .flush_ctl = cpu_to_le16(DUMP_TX_FIFO_FLUSH), | |
1098 | }; | |
1099 | ||
a1022927 | 1100 | u32 flags = sync ? 0 : CMD_ASYNC; |
8ca151b5 JB |
1101 | |
1102 | ret = iwl_mvm_send_cmd_pdu(mvm, TXPATH_FLUSH, flags, | |
1103 | sizeof(flush_cmd), &flush_cmd); | |
1104 | if (ret) | |
1105 | IWL_ERR(mvm, "Failed to send flush command (%d)\n", ret); | |
1106 | return ret; | |
1107 | } |