iwlagn: iwl-pci doesn't include iwl-dev any more
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl-agn-tx.c
CommitLineData
b305a080
WYG
1/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
901069c7 5 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
b305a080
WYG
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
19 * USA
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/sched.h>
a0eaad71 34#include <linux/ieee80211.h>
b305a080
WYG
35
36#include "iwl-dev.h"
37#include "iwl-core.h"
38#include "iwl-sta.h"
39#include "iwl-io.h"
74bcdb33 40#include "iwl-helpers.h"
19e6cda0 41#include "iwl-agn-hw.h"
8d801080 42#include "iwl-agn.h"
47c1b496 43#include "iwl-trans.h"
b305a080 44
74bcdb33
WYG
45/*
46 * mac80211 queues, ACs, hardware queues, FIFOs.
47 *
48 * Cf. http://wireless.kernel.org/en/developers/Documentation/mac80211/queues
49 *
50 * Mac80211 uses the following numbers, which we get as from it
51 * by way of skb_get_queue_mapping(skb):
52 *
53 * VO 0
54 * VI 1
55 * BE 2
56 * BK 3
57 *
58 *
59 * Regular (not A-MPDU) frames are put into hardware queues corresponding
60 * to the FIFOs, see comments in iwl-prph.h. Aggregated frames get their
61 * own queue per aggregation session (RA/TID combination), such queues are
62 * set up to map into FIFOs too, for which we need an AC->FIFO mapping. In
63 * order to map frames to the right queue, we also need an AC->hw queue
64 * mapping. This is implemented here.
65 *
66 * Due to the way hw queues are set up (by the hw specific modules like
67 * iwl-4965.c, iwl-5000.c etc.), the AC->hw queue mapping is the identity
68 * mapping.
69 */
70
71static const u8 tid_to_ac[] = {
0c4ac342
JB
72 IEEE80211_AC_BE,
73 IEEE80211_AC_BK,
74 IEEE80211_AC_BK,
75 IEEE80211_AC_BE,
76 IEEE80211_AC_VI,
77 IEEE80211_AC_VI,
78 IEEE80211_AC_VO,
79 IEEE80211_AC_VO
74bcdb33
WYG
80};
81
c2845d01
SZ
82static inline int get_ac_from_tid(u16 tid)
83{
84 if (likely(tid < ARRAY_SIZE(tid_to_ac)))
85 return tid_to_ac[tid];
86
87 /* no support for TIDs 8-15 yet */
88 return -EINVAL;
89}
90
e72f368b 91static inline int get_fifo_from_tid(struct iwl_rxon_context *ctx, u16 tid)
74bcdb33
WYG
92{
93 if (likely(tid < ARRAY_SIZE(tid_to_ac)))
e72f368b 94 return ctx->ac_to_fifo[tid_to_ac[tid]];
74bcdb33
WYG
95
96 /* no support for TIDs 8-15 yet */
97 return -EINVAL;
98}
99
48d42c42
EG
100static int iwlagn_txq_agg_enable(struct iwl_priv *priv, int txq_id, int sta_id,
101 int tid)
b305a080 102{
19e6cda0 103 if ((IWLAGN_FIRST_AMPDU_QUEUE > txq_id) ||
7cb1b088
WYG
104 (IWLAGN_FIRST_AMPDU_QUEUE +
105 priv->cfg->base_params->num_of_ampdu_queues <= txq_id)) {
b305a080
WYG
106 IWL_WARN(priv,
107 "queue number out of range: %d, must be %d to %d\n",
19e6cda0
WYG
108 txq_id, IWLAGN_FIRST_AMPDU_QUEUE,
109 IWLAGN_FIRST_AMPDU_QUEUE +
7cb1b088 110 priv->cfg->base_params->num_of_ampdu_queues - 1);
b305a080
WYG
111 return -EINVAL;
112 }
113
b305a080 114 /* Modify device's station table to Tx this TID */
c8823ec1
JB
115 return iwl_sta_tx_modify_enable_tid(priv, sta_id, tid);
116}
117
5c3d29fc
DF
118static void iwlagn_tx_cmd_protection(struct iwl_priv *priv,
119 struct ieee80211_tx_info *info,
120 __le16 fc, __le32 *tx_flags)
121{
122 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS ||
123 info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT ||
124 info->flags & IEEE80211_TX_CTL_AMPDU)
125 *tx_flags |= TX_CMD_FLG_PROT_REQUIRE_MSK;
126}
127
74bcdb33
WYG
128/*
129 * handle build REPLY_TX command notification.
130 */
131static void iwlagn_tx_cmd_build_basic(struct iwl_priv *priv,
c6baf7fb
JB
132 struct sk_buff *skb,
133 struct iwl_tx_cmd *tx_cmd,
134 struct ieee80211_tx_info *info,
135 struct ieee80211_hdr *hdr, u8 sta_id)
74bcdb33
WYG
136{
137 __le16 fc = hdr->frame_control;
138 __le32 tx_flags = tx_cmd->tx_flags;
139
140 tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2c2def10
JB
141
142 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
74bcdb33 143 tx_flags |= TX_CMD_FLG_ACK_MSK;
2c2def10
JB
144 else
145 tx_flags &= ~TX_CMD_FLG_ACK_MSK;
74bcdb33 146
2c2def10
JB
147 if (ieee80211_is_probe_resp(fc))
148 tx_flags |= TX_CMD_FLG_TSF_MSK;
149 else if (ieee80211_is_back_req(fc))
74bcdb33 150 tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
d44ae69e 151 else if (info->band == IEEE80211_BAND_2GHZ &&
7cb1b088
WYG
152 priv->cfg->bt_params &&
153 priv->cfg->bt_params->advanced_bt_coexist &&
d44ae69e
JB
154 (ieee80211_is_auth(fc) || ieee80211_is_assoc_req(fc) ||
155 ieee80211_is_reassoc_req(fc) ||
156 skb->protocol == cpu_to_be16(ETH_P_PAE)))
157 tx_flags |= TX_CMD_FLG_IGNORE_BT;
74bcdb33
WYG
158
159
c6baf7fb 160 tx_cmd->sta_id = sta_id;
74bcdb33
WYG
161 if (ieee80211_has_morefrags(fc))
162 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
163
164 if (ieee80211_is_data_qos(fc)) {
165 u8 *qc = ieee80211_get_qos_ctl(hdr);
166 tx_cmd->tid_tspec = qc[0] & 0xf;
167 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
168 } else {
169 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
170 }
171
5c3d29fc 172 iwlagn_tx_cmd_protection(priv, info, fc, &tx_flags);
74bcdb33
WYG
173
174 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
175 if (ieee80211_is_mgmt(fc)) {
176 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
177 tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3);
178 else
179 tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2);
180 } else {
181 tx_cmd->timeout.pm_frame_timeout = 0;
182 }
183
184 tx_cmd->driver_txop = 0;
185 tx_cmd->tx_flags = tx_flags;
186 tx_cmd->next_frame_len = 0;
187}
188
189#define RTS_DFAULT_RETRY_LIMIT 60
190
191static void iwlagn_tx_cmd_build_rate(struct iwl_priv *priv,
c6baf7fb
JB
192 struct iwl_tx_cmd *tx_cmd,
193 struct ieee80211_tx_info *info,
194 __le16 fc)
74bcdb33
WYG
195{
196 u32 rate_flags;
197 int rate_idx;
198 u8 rts_retry_limit;
199 u8 data_retry_limit;
200 u8 rate_plcp;
201
202 /* Set retry limit on DATA packets and Probe Responses*/
203 if (ieee80211_is_probe_resp(fc))
204 data_retry_limit = 3;
205 else
b744cb79 206 data_retry_limit = IWLAGN_DEFAULT_TX_RETRY;
74bcdb33
WYG
207 tx_cmd->data_retry_limit = data_retry_limit;
208
209 /* Set retry limit on RTS packets */
210 rts_retry_limit = RTS_DFAULT_RETRY_LIMIT;
211 if (data_retry_limit < rts_retry_limit)
212 rts_retry_limit = data_retry_limit;
213 tx_cmd->rts_retry_limit = rts_retry_limit;
214
215 /* DATA packets will use the uCode station table for rate/antenna
216 * selection */
217 if (ieee80211_is_data(fc)) {
218 tx_cmd->initial_rate_index = 0;
219 tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
c10e2c10 220#ifdef CONFIG_IWLWIFI_DEVICE_SVTOOL
4e308119
WYG
221 if (priv->tm_fixed_rate) {
222 /*
223 * rate overwrite by testmode
224 * we not only send lq command to change rate
225 * we also re-enforce per data pkt base.
226 */
227 tx_cmd->tx_flags &= ~TX_CMD_FLG_STA_RATE_MSK;
228 memcpy(&tx_cmd->rate_n_flags, &priv->tm_fixed_rate,
229 sizeof(tx_cmd->rate_n_flags));
230 }
c10e2c10 231#endif
74bcdb33
WYG
232 return;
233 }
234
235 /**
236 * If the current TX rate stored in mac80211 has the MCS bit set, it's
237 * not really a TX rate. Thus, we use the lowest supported rate for
238 * this band. Also use the lowest supported rate if the stored rate
239 * index is invalid.
240 */
241 rate_idx = info->control.rates[0].idx;
242 if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS ||
243 (rate_idx < 0) || (rate_idx > IWL_RATE_COUNT_LEGACY))
244 rate_idx = rate_lowest_index(&priv->bands[info->band],
245 info->control.sta);
246 /* For 5 GHZ band, remap mac80211 rate indices into driver indices */
247 if (info->band == IEEE80211_BAND_5GHZ)
248 rate_idx += IWL_FIRST_OFDM_RATE;
249 /* Get PLCP rate for tx_cmd->rate_n_flags */
250 rate_plcp = iwl_rates[rate_idx].plcp;
251 /* Zero out flags for this packet */
252 rate_flags = 0;
253
254 /* Set CCK flag as needed */
255 if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
256 rate_flags |= RATE_MCS_CCK_MSK;
257
74bcdb33 258 /* Set up antennas */
7cb1b088
WYG
259 if (priv->cfg->bt_params &&
260 priv->cfg->bt_params->advanced_bt_coexist &&
261 priv->bt_full_concurrent) {
bee008b7
WYG
262 /* operated as 1x1 in full concurrency mode */
263 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
d6189124 264 first_antenna(hw_params(priv).valid_tx_ant));
bee008b7
WYG
265 } else
266 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
d6189124 267 hw_params(priv).valid_tx_ant);
74bcdb33
WYG
268 rate_flags |= iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
269
270 /* Set the rate in the TX cmd */
271 tx_cmd->rate_n_flags = iwl_hw_set_rate_n_flags(rate_plcp, rate_flags);
272}
273
274static void iwlagn_tx_cmd_build_hwcrypto(struct iwl_priv *priv,
275 struct ieee80211_tx_info *info,
276 struct iwl_tx_cmd *tx_cmd,
277 struct sk_buff *skb_frag,
278 int sta_id)
279{
280 struct ieee80211_key_conf *keyconf = info->control.hw_key;
281
97359d12
JB
282 switch (keyconf->cipher) {
283 case WLAN_CIPHER_SUITE_CCMP:
74bcdb33
WYG
284 tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
285 memcpy(tx_cmd->key, keyconf->key, keyconf->keylen);
286 if (info->flags & IEEE80211_TX_CTL_AMPDU)
287 tx_cmd->tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK;
288 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
289 break;
290
97359d12 291 case WLAN_CIPHER_SUITE_TKIP:
74bcdb33 292 tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
523b02ea 293 ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key);
74bcdb33
WYG
294 IWL_DEBUG_TX(priv, "tx_cmd with tkip hwcrypto\n");
295 break;
296
97359d12
JB
297 case WLAN_CIPHER_SUITE_WEP104:
298 tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
299 /* fall through */
300 case WLAN_CIPHER_SUITE_WEP40:
74bcdb33
WYG
301 tx_cmd->sec_ctl |= (TX_CMD_SEC_WEP |
302 (keyconf->keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT);
303
74bcdb33
WYG
304 memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen);
305
306 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
307 "with key %d\n", keyconf->keyidx);
308 break;
309
310 default:
97359d12 311 IWL_ERR(priv, "Unknown encode cipher %x\n", keyconf->cipher);
74bcdb33
WYG
312 break;
313 }
314}
315
316/*
317 * start REPLY_TX command process
318 */
319int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
320{
321 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
322 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
74bcdb33 323 struct iwl_station_priv *sta_priv = NULL;
a194e324 324 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
47c1b496 325 struct iwl_tx_cmd *tx_cmd;
8d56396a 326 int txq_id;
47c1b496 327
74bcdb33
WYG
328 u16 seq_number = 0;
329 __le16 fc;
330 u8 hdr_len;
47c1b496 331 u16 len;
74bcdb33 332 u8 sta_id;
74bcdb33 333 u8 tid = 0;
74bcdb33 334 unsigned long flags;
2e34034e 335 bool is_agg = false;
74bcdb33 336
c6baf7fb 337 if (info->control.vif)
a194e324
JB
338 ctx = iwl_rxon_ctx_from_vif(info->control.vif);
339
10b15e6f 340 spin_lock_irqsave(&priv->shrd->lock, flags);
845a9c0d 341 if (iwl_is_rfkill(priv->shrd)) {
74bcdb33 342 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
2c46f72e 343 goto drop_unlock_priv;
74bcdb33
WYG
344 }
345
346 fc = hdr->frame_control;
347
348#ifdef CONFIG_IWLWIFI_DEBUG
349 if (ieee80211_is_auth(fc))
350 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
351 else if (ieee80211_is_assoc_req(fc))
352 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
353 else if (ieee80211_is_reassoc_req(fc))
354 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
355#endif
356
357 hdr_len = ieee80211_hdrlen(fc);
358
bfd36103
SG
359 /* For management frames use broadcast id to do not break aggregation */
360 if (!ieee80211_is_data(fc))
361 sta_id = ctx->bcast_sta_id;
362 else {
363 /* Find index into station table for destination station */
364 sta_id = iwl_sta_id_or_broadcast(priv, ctx, info->control.sta);
365 if (sta_id == IWL_INVALID_STATION) {
366 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
367 hdr->addr1);
e00cf3b9 368 goto drop_unlock_priv;
bfd36103 369 }
74bcdb33
WYG
370 }
371
372 IWL_DEBUG_TX(priv, "station Id %d\n", sta_id);
373
47c1b496
EG
374 if (info->control.sta)
375 sta_priv = (void *)info->control.sta->drv_priv;
74bcdb33 376
67158b67
JB
377 if (sta_priv && sta_priv->asleep &&
378 (info->flags & IEEE80211_TX_CTL_PSPOLL_RESPONSE)) {
74bcdb33
WYG
379 /*
380 * This sends an asynchronous command to the device,
381 * but we can rely on it being processed before the
382 * next frame is processed -- and the next frame to
383 * this station is the one that will consume this
384 * counter.
385 * For now set the counter to just 1 since we do not
386 * support uAPSD yet.
387 */
388 iwl_sta_modify_sleep_tx_count(priv, sta_id, 1);
389 }
390
e72f368b
JB
391 /*
392 * Send this frame after DTIM -- there's a special queue
393 * reserved for this for contexts that support AP mode.
394 */
395 if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) {
396 txq_id = ctx->mcast_queue;
397 /*
398 * The microcode will clear the more data
399 * bit in the last frame it transmits.
400 */
401 hdr->frame_control |=
402 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
c6baf7fb
JB
403 } else if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)
404 txq_id = IWL_AUX_QUEUE;
405 else
e72f368b 406 txq_id = ctx->ac_to_queue[skb_get_queue_mapping(skb)];
9c5ac091 407
10b15e6f 408 /* irqs already disabled/saved above when locking priv->shrd->lock */
f39c95e8 409 spin_lock(&priv->shrd->sta_lock);
9c5ac091 410
74bcdb33 411 if (ieee80211_is_data_qos(fc)) {
47c1b496 412 u8 *qc = NULL;
74bcdb33
WYG
413 qc = ieee80211_get_qos_ctl(hdr);
414 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
2c46f72e
JB
415
416 if (WARN_ON_ONCE(tid >= MAX_TID_COUNT))
417 goto drop_unlock_sta;
418
74bcdb33
WYG
419 seq_number = priv->stations[sta_id].tid[tid].seq_number;
420 seq_number &= IEEE80211_SCTL_SEQ;
421 hdr->seq_ctrl = hdr->seq_ctrl &
422 cpu_to_le16(IEEE80211_SCTL_FRAG);
423 hdr->seq_ctrl |= cpu_to_le16(seq_number);
424 seq_number += 0x10;
425 /* aggregation is on for this <sta,tid> */
426 if (info->flags & IEEE80211_TX_CTL_AMPDU &&
427 priv->stations[sta_id].tid[tid].agg.state == IWL_AGG_ON) {
428 txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
2e34034e 429 is_agg = true;
74bcdb33
WYG
430 }
431 }
432
e6bb4c9c 433 tx_cmd = iwl_trans_get_tx_cmd(trans(priv), txq_id);
47c1b496 434 if (unlikely(!tx_cmd))
2c46f72e 435 goto drop_unlock_sta;
74bcdb33 436
74bcdb33
WYG
437 /* Copy MAC header from skb into command buffer */
438 memcpy(tx_cmd->hdr, hdr, hdr_len);
439
74bcdb33
WYG
440 /* Total # bytes to be transmitted */
441 len = (u16)skb->len;
442 tx_cmd->len = cpu_to_le16(len);
443
444 if (info->control.hw_key)
445 iwlagn_tx_cmd_build_hwcrypto(priv, info, tx_cmd, skb, sta_id);
446
447 /* TODO need this for burst mode later on */
d44ae69e 448 iwlagn_tx_cmd_build_basic(priv, skb, tx_cmd, info, hdr, sta_id);
74bcdb33
WYG
449 iwl_dbg_log_tx_data_frame(priv, len, hdr);
450
451 iwlagn_tx_cmd_build_rate(priv, tx_cmd, info, fc);
452
453 iwl_update_stats(priv, true, fc, len);
74bcdb33 454
e6bb4c9c 455 if (iwl_trans_tx(trans(priv), skb, tx_cmd, txq_id, fc, is_agg, ctx))
47c1b496 456 goto drop_unlock_sta;
2c46f72e
JB
457
458 if (ieee80211_is_data_qos(fc)) {
459 priv->stations[sta_id].tid[tid].tfds_in_queue++;
460 if (!ieee80211_has_morefrags(fc))
461 priv->stations[sta_id].tid[tid].seq_number = seq_number;
462 }
463
f39c95e8 464 spin_unlock(&priv->shrd->sta_lock);
10b15e6f 465 spin_unlock_irqrestore(&priv->shrd->lock, flags);
74bcdb33 466
2e34034e
JB
467 /*
468 * Avoid atomic ops if it isn't an associated client.
469 * Also, if this is a packet for aggregation, don't
470 * increase the counter because the ucode will stop
471 * aggregation queues when their respective station
472 * goes to sleep.
473 */
474 if (sta_priv && sta_priv->client && !is_agg)
74bcdb33
WYG
475 atomic_inc(&sta_priv->pending_frames);
476
74bcdb33
WYG
477 return 0;
478
2c46f72e 479drop_unlock_sta:
f39c95e8 480 spin_unlock(&priv->shrd->sta_lock);
2c46f72e 481drop_unlock_priv:
10b15e6f 482 spin_unlock_irqrestore(&priv->shrd->lock, flags);
74bcdb33
WYG
483 return -1;
484}
485
74bcdb33
WYG
486/*
487 * Find first available (lowest unused) Tx Queue, mark it "active".
488 * Called only when finding queue for aggregation.
489 * Should never return anything < 7, because they should already
490 * be in use as EDCA AC (0-3), Command (4), reserved (5, 6)
491 */
492static int iwlagn_txq_ctx_activate_free(struct iwl_priv *priv)
493{
494 int txq_id;
495
d6189124 496 for (txq_id = 0; txq_id < hw_params(priv).max_txq_num; txq_id++)
74bcdb33
WYG
497 if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk))
498 return txq_id;
499 return -1;
500}
501
832f47e3 502int iwlagn_tx_agg_start(struct iwl_priv *priv, struct ieee80211_vif *vif,
619753ff 503 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
74bcdb33
WYG
504{
505 int sta_id;
506 int tx_fifo;
507 int txq_id;
508 int ret;
509 unsigned long flags;
510 struct iwl_tid_data *tid_data;
511
e72f368b 512 tx_fifo = get_fifo_from_tid(iwl_rxon_ctx_from_vif(vif), tid);
74bcdb33
WYG
513 if (unlikely(tx_fifo < 0))
514 return tx_fifo;
515
5bc9890f
WYG
516 IWL_DEBUG_HT(priv, "TX AGG request on ra = %pM tid = %d\n",
517 sta->addr, tid);
74bcdb33 518
619753ff 519 sta_id = iwl_sta_id(sta);
74bcdb33
WYG
520 if (sta_id == IWL_INVALID_STATION) {
521 IWL_ERR(priv, "Start AGG on invalid station\n");
522 return -ENXIO;
523 }
524 if (unlikely(tid >= MAX_TID_COUNT))
525 return -EINVAL;
526
527 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) {
528 IWL_ERR(priv, "Start AGG when state is not IWL_AGG_OFF !\n");
529 return -ENXIO;
530 }
531
532 txq_id = iwlagn_txq_ctx_activate_free(priv);
533 if (txq_id == -1) {
534 IWL_ERR(priv, "No free aggregation queue available\n");
535 return -ENXIO;
536 }
537
f39c95e8 538 spin_lock_irqsave(&priv->shrd->sta_lock, flags);
74bcdb33
WYG
539 tid_data = &priv->stations[sta_id].tid[tid];
540 *ssn = SEQ_TO_SN(tid_data->seq_number);
541 tid_data->agg.txq_id = txq_id;
c8823ec1 542 tid_data->agg.tx_fifo = tx_fifo;
ea9b307f 543 iwl_set_swq_id(&priv->txq[txq_id], get_ac_from_tid(tid), txq_id);
f39c95e8 544 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
74bcdb33 545
c8823ec1 546 ret = iwlagn_txq_agg_enable(priv, txq_id, sta_id, tid);
74bcdb33
WYG
547 if (ret)
548 return ret;
549
f39c95e8 550 spin_lock_irqsave(&priv->shrd->sta_lock, flags);
9c5ac091 551 tid_data = &priv->stations[sta_id].tid[tid];
74bcdb33
WYG
552 if (tid_data->tfds_in_queue == 0) {
553 IWL_DEBUG_HT(priv, "HW queue is empty\n");
554 tid_data->agg.state = IWL_AGG_ON;
619753ff 555 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
74bcdb33
WYG
556 } else {
557 IWL_DEBUG_HT(priv, "HW queue is NOT empty: %d packets in HW queue\n",
558 tid_data->tfds_in_queue);
559 tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA;
560 }
f39c95e8 561 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
74bcdb33
WYG
562 return ret;
563}
564
832f47e3 565int iwlagn_tx_agg_stop(struct iwl_priv *priv, struct ieee80211_vif *vif,
619753ff 566 struct ieee80211_sta *sta, u16 tid)
74bcdb33 567{
18c121d7 568 int tx_fifo_id, txq_id, sta_id, ssn;
74bcdb33
WYG
569 struct iwl_tid_data *tid_data;
570 int write_ptr, read_ptr;
571 unsigned long flags;
572
e72f368b 573 tx_fifo_id = get_fifo_from_tid(iwl_rxon_ctx_from_vif(vif), tid);
74bcdb33
WYG
574 if (unlikely(tx_fifo_id < 0))
575 return tx_fifo_id;
576
619753ff 577 sta_id = iwl_sta_id(sta);
74bcdb33
WYG
578
579 if (sta_id == IWL_INVALID_STATION) {
580 IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
581 return -ENXIO;
582 }
583
f39c95e8 584 spin_lock_irqsave(&priv->shrd->sta_lock, flags);
9c5ac091 585
74bcdb33
WYG
586 tid_data = &priv->stations[sta_id].tid[tid];
587 ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
588 txq_id = tid_data->agg.txq_id;
18c121d7
JB
589
590 switch (priv->stations[sta_id].tid[tid].agg.state) {
591 case IWL_EMPTYING_HW_QUEUE_ADDBA:
592 /*
593 * This can happen if the peer stops aggregation
594 * again before we've had a chance to drain the
595 * queue we selected previously, i.e. before the
596 * session was really started completely.
597 */
598 IWL_DEBUG_HT(priv, "AGG stop before setup done\n");
599 goto turn_off;
600 case IWL_AGG_ON:
601 break;
602 default:
603 IWL_WARN(priv, "Stopping AGG while state not ON or starting\n");
604 }
605
74bcdb33
WYG
606 write_ptr = priv->txq[txq_id].q.write_ptr;
607 read_ptr = priv->txq[txq_id].q.read_ptr;
608
609 /* The queue is not empty */
610 if (write_ptr != read_ptr) {
611 IWL_DEBUG_HT(priv, "Stopping a non empty AGG HW QUEUE\n");
612 priv->stations[sta_id].tid[tid].agg.state =
613 IWL_EMPTYING_HW_QUEUE_DELBA;
f39c95e8 614 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
74bcdb33
WYG
615 return 0;
616 }
617
618 IWL_DEBUG_HT(priv, "HW queue is empty\n");
18c121d7 619 turn_off:
74bcdb33
WYG
620 priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
621
9c5ac091 622 /* do not restore/save irqs */
f39c95e8 623 spin_unlock(&priv->shrd->sta_lock);
10b15e6f 624 spin_lock(&priv->shrd->lock);
9c5ac091 625
74bcdb33
WYG
626 /*
627 * the only reason this call can fail is queue number out of range,
628 * which can happen if uCode is reloaded and all the station
629 * information are lost. if it is outside the range, there is no need
630 * to deactivate the uCode queue, just return "success" to allow
631 * mac80211 to clean up it own data.
632 */
e6bb4c9c 633 iwl_trans_txq_agg_disable(trans(priv), txq_id, ssn, tx_fifo_id);
10b15e6f 634 spin_unlock_irqrestore(&priv->shrd->lock, flags);
74bcdb33 635
619753ff 636 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
74bcdb33
WYG
637
638 return 0;
639}
640
04e1cabe 641static int iwlagn_txq_check_empty(struct iwl_priv *priv,
74bcdb33
WYG
642 int sta_id, u8 tid, int txq_id)
643{
644 struct iwl_queue *q = &priv->txq[txq_id].q;
645 u8 *addr = priv->stations[sta_id].sta.sta.addr;
646 struct iwl_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
8bd413e6
JB
647 struct iwl_rxon_context *ctx;
648
649 ctx = &priv->contexts[priv->stations[sta_id].ctxid];
74bcdb33 650
f39c95e8 651 lockdep_assert_held(&priv->shrd->sta_lock);
9c5ac091 652
74bcdb33
WYG
653 switch (priv->stations[sta_id].tid[tid].agg.state) {
654 case IWL_EMPTYING_HW_QUEUE_DELBA:
655 /* We are reclaiming the last packet of the */
656 /* aggregated HW queue */
657 if ((txq_id == tid_data->agg.txq_id) &&
658 (q->read_ptr == q->write_ptr)) {
659 u16 ssn = SEQ_TO_SN(tid_data->seq_number);
e72f368b 660 int tx_fifo = get_fifo_from_tid(ctx, tid);
74bcdb33 661 IWL_DEBUG_HT(priv, "HW queue empty: continue DELBA flow\n");
e6bb4c9c 662 iwl_trans_txq_agg_disable(trans(priv), txq_id,
41c50542 663 ssn, tx_fifo);
74bcdb33 664 tid_data->agg.state = IWL_AGG_OFF;
8bd413e6 665 ieee80211_stop_tx_ba_cb_irqsafe(ctx->vif, addr, tid);
74bcdb33
WYG
666 }
667 break;
668 case IWL_EMPTYING_HW_QUEUE_ADDBA:
669 /* We are reclaiming the last packet of the queue */
670 if (tid_data->tfds_in_queue == 0) {
671 IWL_DEBUG_HT(priv, "HW queue empty: continue ADDBA flow\n");
672 tid_data->agg.state = IWL_AGG_ON;
8bd413e6 673 ieee80211_start_tx_ba_cb_irqsafe(ctx->vif, addr, tid);
74bcdb33
WYG
674 }
675 break;
676 }
9c5ac091 677
74bcdb33
WYG
678 return 0;
679}
680
2e34034e
JB
681static void iwlagn_non_agg_tx_status(struct iwl_priv *priv,
682 struct iwl_rxon_context *ctx,
683 const u8 *addr1)
74bcdb33 684{
74bcdb33
WYG
685 struct ieee80211_sta *sta;
686 struct iwl_station_priv *sta_priv;
687
6db6340c 688 rcu_read_lock();
2e34034e 689 sta = ieee80211_find_sta(ctx->vif, addr1);
74bcdb33
WYG
690 if (sta) {
691 sta_priv = (void *)sta->drv_priv;
692 /* avoid atomic ops if this isn't a client */
693 if (sta_priv->client &&
694 atomic_dec_return(&sta_priv->pending_frames) == 0)
695 ieee80211_sta_block_awake(priv->hw, sta, false);
696 }
6db6340c 697 rcu_read_unlock();
2e34034e
JB
698}
699
a0eaad71
EG
700/**
701 * translate ucode response to mac80211 tx status control values
702 */
04e1cabe 703static void iwlagn_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
a0eaad71 704 struct ieee80211_tx_info *info)
2e34034e 705{
a0eaad71 706 struct ieee80211_tx_rate *r = &info->control.rates[0];
74bcdb33 707
a0eaad71
EG
708 info->antenna_sel_tx =
709 ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
710 if (rate_n_flags & RATE_MCS_HT_MSK)
711 r->flags |= IEEE80211_TX_RC_MCS;
712 if (rate_n_flags & RATE_MCS_GF_MSK)
713 r->flags |= IEEE80211_TX_RC_GREEN_FIELD;
714 if (rate_n_flags & RATE_MCS_HT40_MSK)
715 r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
716 if (rate_n_flags & RATE_MCS_DUP_MSK)
717 r->flags |= IEEE80211_TX_RC_DUP_DATA;
718 if (rate_n_flags & RATE_MCS_SGI_MSK)
719 r->flags |= IEEE80211_TX_RC_SHORT_GI;
720 r->idx = iwlagn_hwrate_to_mac80211_idx(rate_n_flags, info->band);
74bcdb33
WYG
721}
722
a0eaad71
EG
723#ifdef CONFIG_IWLWIFI_DEBUG
724const char *iwl_get_tx_fail_reason(u32 status)
74bcdb33 725{
a0eaad71
EG
726#define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x
727#define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x
74bcdb33 728
a0eaad71
EG
729 switch (status & TX_STATUS_MSK) {
730 case TX_STATUS_SUCCESS:
731 return "SUCCESS";
732 TX_STATUS_POSTPONE(DELAY);
733 TX_STATUS_POSTPONE(FEW_BYTES);
734 TX_STATUS_POSTPONE(BT_PRIO);
735 TX_STATUS_POSTPONE(QUIET_PERIOD);
736 TX_STATUS_POSTPONE(CALC_TTAK);
737 TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY);
738 TX_STATUS_FAIL(SHORT_LIMIT);
739 TX_STATUS_FAIL(LONG_LIMIT);
740 TX_STATUS_FAIL(FIFO_UNDERRUN);
741 TX_STATUS_FAIL(DRAIN_FLOW);
742 TX_STATUS_FAIL(RFKILL_FLUSH);
743 TX_STATUS_FAIL(LIFE_EXPIRE);
744 TX_STATUS_FAIL(DEST_PS);
745 TX_STATUS_FAIL(HOST_ABORTED);
746 TX_STATUS_FAIL(BT_RETRY);
747 TX_STATUS_FAIL(STA_INVALID);
748 TX_STATUS_FAIL(FRAG_DROPPED);
749 TX_STATUS_FAIL(TID_DISABLE);
750 TX_STATUS_FAIL(FIFO_FLUSHED);
751 TX_STATUS_FAIL(INSUFFICIENT_CF_POLL);
752 TX_STATUS_FAIL(PASSIVE_NO_RX);
753 TX_STATUS_FAIL(NO_BEACON_ON_RADAR);
74bcdb33
WYG
754 }
755
a0eaad71 756 return "UNKNOWN";
74bcdb33 757
a0eaad71
EG
758#undef TX_STATUS_FAIL
759#undef TX_STATUS_POSTPONE
760}
761#endif /* CONFIG_IWLWIFI_DEBUG */
b2502698 762
04e1cabe
EG
763static void iwlagn_count_agg_tx_err_status(struct iwl_priv *priv, u16 status)
764{
765 status &= AGG_TX_STATUS_MSK;
766
767 switch (status) {
768 case AGG_TX_STATE_UNDERRUN_MSK:
769 priv->reply_agg_tx_stats.underrun++;
770 break;
771 case AGG_TX_STATE_BT_PRIO_MSK:
772 priv->reply_agg_tx_stats.bt_prio++;
773 break;
774 case AGG_TX_STATE_FEW_BYTES_MSK:
775 priv->reply_agg_tx_stats.few_bytes++;
776 break;
777 case AGG_TX_STATE_ABORT_MSK:
778 priv->reply_agg_tx_stats.abort++;
779 break;
780 case AGG_TX_STATE_LAST_SENT_TTL_MSK:
781 priv->reply_agg_tx_stats.last_sent_ttl++;
782 break;
783 case AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK:
784 priv->reply_agg_tx_stats.last_sent_try++;
785 break;
786 case AGG_TX_STATE_LAST_SENT_BT_KILL_MSK:
787 priv->reply_agg_tx_stats.last_sent_bt_kill++;
788 break;
789 case AGG_TX_STATE_SCD_QUERY_MSK:
790 priv->reply_agg_tx_stats.scd_query++;
791 break;
792 case AGG_TX_STATE_TEST_BAD_CRC32_MSK:
793 priv->reply_agg_tx_stats.bad_crc32++;
794 break;
795 case AGG_TX_STATE_RESPONSE_MSK:
796 priv->reply_agg_tx_stats.response++;
797 break;
798 case AGG_TX_STATE_DUMP_TX_MSK:
799 priv->reply_agg_tx_stats.dump_tx++;
800 break;
801 case AGG_TX_STATE_DELAY_TX_MSK:
802 priv->reply_agg_tx_stats.delay_tx++;
803 break;
804 default:
805 priv->reply_agg_tx_stats.unknown++;
806 break;
807 }
808}
809
a0eaad71
EG
810static void iwl_rx_reply_tx_agg(struct iwl_priv *priv,
811 struct iwlagn_tx_resp *tx_resp)
812{
813 struct agg_tx_status *frame_status = &tx_resp->status;
814 int tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >>
815 IWLAGN_TX_RES_TID_POS;
816 int sta_id = (tx_resp->ra_tid & IWLAGN_TX_RES_RA_MSK) >>
817 IWLAGN_TX_RES_RA_POS;
818 struct iwl_ht_agg *agg = &priv->stations[sta_id].tid[tid].agg;
819 u32 status = le16_to_cpu(tx_resp->status.status);
820 int i;
821
822 if (agg->wait_for_ba)
823 IWL_DEBUG_TX_REPLY(priv,
824 "got tx response w/o block-ack\n");
74bcdb33 825
a0eaad71
EG
826 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
827 agg->wait_for_ba = (tx_resp->frame_count > 1);
828
829 /*
830 * If the BT kill count is non-zero, we'll get this
831 * notification again.
832 */
833 if (tx_resp->bt_kill_count && tx_resp->frame_count == 1 &&
834 priv->cfg->bt_params &&
835 priv->cfg->bt_params->advanced_bt_coexist) {
836 IWL_DEBUG_COEX(priv, "receive reply tx w/ bt_kill\n");
837 }
b2502698 838
a0eaad71
EG
839 /* Construct bit-map of pending frames within Tx window */
840 for (i = 0; i < tx_resp->frame_count; i++) {
841 u16 fstatus = le16_to_cpu(frame_status[i].status);
74bcdb33 842
a0eaad71
EG
843 if (status & AGG_TX_STATUS_MSK)
844 iwlagn_count_agg_tx_err_status(priv, fstatus);
74bcdb33 845
a0eaad71
EG
846 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
847 AGG_TX_STATE_ABORT_MSK))
848 continue;
849
850 IWL_DEBUG_TX_REPLY(priv, "status %s (0x%08x), "
851 "try-count (0x%08x)\n",
852 iwl_get_agg_tx_fail_reason(fstatus),
853 fstatus & AGG_TX_STATUS_MSK,
854 fstatus & AGG_TX_TRY_MSK);
74bcdb33 855 }
74bcdb33
WYG
856}
857
04e1cabe
EG
858#ifdef CONFIG_IWLWIFI_DEBUG
859#define AGG_TX_STATE_FAIL(x) case AGG_TX_STATE_ ## x: return #x
860
861const char *iwl_get_agg_tx_fail_reason(u16 status)
862{
863 status &= AGG_TX_STATUS_MSK;
864 switch (status) {
865 case AGG_TX_STATE_TRANSMITTED:
866 return "SUCCESS";
867 AGG_TX_STATE_FAIL(UNDERRUN_MSK);
868 AGG_TX_STATE_FAIL(BT_PRIO_MSK);
869 AGG_TX_STATE_FAIL(FEW_BYTES_MSK);
870 AGG_TX_STATE_FAIL(ABORT_MSK);
871 AGG_TX_STATE_FAIL(LAST_SENT_TTL_MSK);
872 AGG_TX_STATE_FAIL(LAST_SENT_TRY_CNT_MSK);
873 AGG_TX_STATE_FAIL(LAST_SENT_BT_KILL_MSK);
874 AGG_TX_STATE_FAIL(SCD_QUERY_MSK);
875 AGG_TX_STATE_FAIL(TEST_BAD_CRC32_MSK);
876 AGG_TX_STATE_FAIL(RESPONSE_MSK);
877 AGG_TX_STATE_FAIL(DUMP_TX_MSK);
878 AGG_TX_STATE_FAIL(DELAY_TX_MSK);
879 }
880
881 return "UNKNOWN";
882}
883#endif /* CONFIG_IWLWIFI_DEBUG */
884
a0eaad71
EG
885static inline u32 iwlagn_get_scd_ssn(struct iwlagn_tx_resp *tx_resp)
886{
887 return le32_to_cpup((__le32 *)&tx_resp->status +
888 tx_resp->frame_count) & MAX_SN;
889}
74bcdb33 890
04e1cabe
EG
891static void iwl_free_tfds_in_queue(struct iwl_priv *priv,
892 int sta_id, int tid, int freed)
893{
894 lockdep_assert_held(&priv->shrd->sta_lock);
895
896 if (priv->stations[sta_id].tid[tid].tfds_in_queue >= freed)
897 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
898 else {
899 IWL_DEBUG_TX(priv, "free more than tfds_in_queue (%u:%d)\n",
900 priv->stations[sta_id].tid[tid].tfds_in_queue,
901 freed);
902 priv->stations[sta_id].tid[tid].tfds_in_queue = 0;
903 }
904}
905
906static void iwlagn_count_tx_err_status(struct iwl_priv *priv, u16 status)
907{
908 status &= TX_STATUS_MSK;
909
910 switch (status) {
911 case TX_STATUS_POSTPONE_DELAY:
912 priv->reply_tx_stats.pp_delay++;
913 break;
914 case TX_STATUS_POSTPONE_FEW_BYTES:
915 priv->reply_tx_stats.pp_few_bytes++;
916 break;
917 case TX_STATUS_POSTPONE_BT_PRIO:
918 priv->reply_tx_stats.pp_bt_prio++;
919 break;
920 case TX_STATUS_POSTPONE_QUIET_PERIOD:
921 priv->reply_tx_stats.pp_quiet_period++;
922 break;
923 case TX_STATUS_POSTPONE_CALC_TTAK:
924 priv->reply_tx_stats.pp_calc_ttak++;
925 break;
926 case TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY:
927 priv->reply_tx_stats.int_crossed_retry++;
928 break;
929 case TX_STATUS_FAIL_SHORT_LIMIT:
930 priv->reply_tx_stats.short_limit++;
931 break;
932 case TX_STATUS_FAIL_LONG_LIMIT:
933 priv->reply_tx_stats.long_limit++;
934 break;
935 case TX_STATUS_FAIL_FIFO_UNDERRUN:
936 priv->reply_tx_stats.fifo_underrun++;
937 break;
938 case TX_STATUS_FAIL_DRAIN_FLOW:
939 priv->reply_tx_stats.drain_flow++;
940 break;
941 case TX_STATUS_FAIL_RFKILL_FLUSH:
942 priv->reply_tx_stats.rfkill_flush++;
943 break;
944 case TX_STATUS_FAIL_LIFE_EXPIRE:
945 priv->reply_tx_stats.life_expire++;
946 break;
947 case TX_STATUS_FAIL_DEST_PS:
948 priv->reply_tx_stats.dest_ps++;
949 break;
950 case TX_STATUS_FAIL_HOST_ABORTED:
951 priv->reply_tx_stats.host_abort++;
952 break;
953 case TX_STATUS_FAIL_BT_RETRY:
954 priv->reply_tx_stats.bt_retry++;
955 break;
956 case TX_STATUS_FAIL_STA_INVALID:
957 priv->reply_tx_stats.sta_invalid++;
958 break;
959 case TX_STATUS_FAIL_FRAG_DROPPED:
960 priv->reply_tx_stats.frag_drop++;
961 break;
962 case TX_STATUS_FAIL_TID_DISABLE:
963 priv->reply_tx_stats.tid_disable++;
964 break;
965 case TX_STATUS_FAIL_FIFO_FLUSHED:
966 priv->reply_tx_stats.fifo_flush++;
967 break;
968 case TX_STATUS_FAIL_INSUFFICIENT_CF_POLL:
969 priv->reply_tx_stats.insuff_cf_poll++;
970 break;
971 case TX_STATUS_FAIL_PASSIVE_NO_RX:
972 priv->reply_tx_stats.fail_hw_drop++;
973 break;
974 case TX_STATUS_FAIL_NO_BEACON_ON_RADAR:
975 priv->reply_tx_stats.sta_color_mismatch++;
976 break;
977 default:
978 priv->reply_tx_stats.unknown++;
979 break;
980 }
981}
982
983static void iwlagn_set_tx_status(struct iwl_priv *priv,
984 struct ieee80211_tx_info *info,
985 struct iwlagn_tx_resp *tx_resp,
986 bool is_agg)
987{
988 u16 status = le16_to_cpu(tx_resp->status.status);
989
990 info->status.rates[0].count = tx_resp->failure_frame + 1;
991 if (is_agg)
992 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
993 info->flags |= iwl_tx_status_to_mac80211(status);
994 iwlagn_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
995 info);
996 if (!iwl_is_tx_success(status))
997 iwlagn_count_tx_err_status(priv, status);
998}
999
1000static void iwl_check_abort_status(struct iwl_priv *priv,
1001 u8 frame_count, u32 status)
1002{
1003 if (frame_count == 1 && status == TX_STATUS_FAIL_RFKILL_FLUSH) {
1004 IWL_ERR(priv, "Tx flush command to flush out all frames\n");
1005 if (!test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
1006 queue_work(priv->shrd->workqueue, &priv->tx_flush);
1007 }
1008}
1009
a0eaad71 1010void iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
74bcdb33 1011{
a0eaad71
EG
1012 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1013 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1014 int txq_id = SEQ_TO_QUEUE(sequence);
1015 int cmd_index = SEQ_TO_INDEX(sequence);
1016 struct iwl_tx_queue *txq = &priv->txq[txq_id];
1017 struct iwlagn_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
1018 struct ieee80211_hdr *hdr;
1019 u32 status = le16_to_cpu(tx_resp->status.status);
1020 u32 ssn = iwlagn_get_scd_ssn(tx_resp);
1021 int tid;
1022 int sta_id;
1023 int freed;
74bcdb33 1024 struct ieee80211_tx_info *info;
a0eaad71
EG
1025 unsigned long flags;
1026 struct sk_buff_head skbs;
1027 struct sk_buff *skb;
1028 struct iwl_rxon_context *ctx;
74bcdb33 1029
a0eaad71
EG
1030 if ((cmd_index >= txq->q.n_bd) ||
1031 (iwl_queue_used(&txq->q, cmd_index) == 0)) {
1032 IWL_ERR(priv, "%s: Read index for DMA queue txq_id (%d) "
1033 "cmd_index %d is out of range [0-%d] %d %d\n",
1034 __func__, txq_id, cmd_index, txq->q.n_bd,
1035 txq->q.write_ptr, txq->q.read_ptr);
1036 return;
74bcdb33
WYG
1037 }
1038
a0eaad71 1039 txq->time_stamp = jiffies;
d0eb6334 1040
a0eaad71
EG
1041 tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >>
1042 IWLAGN_TX_RES_TID_POS;
1043 sta_id = (tx_resp->ra_tid & IWLAGN_TX_RES_RA_MSK) >>
1044 IWLAGN_TX_RES_RA_POS;
9decde95 1045
a0eaad71 1046 spin_lock_irqsave(&priv->shrd->sta_lock, flags);
9decde95 1047
a0eaad71
EG
1048 if (txq->sched_retry)
1049 iwl_rx_reply_tx_agg(priv, tx_resp);
1050
1051 if (tx_resp->frame_count == 1) {
1052 bool is_agg = (txq_id >= IWLAGN_FIRST_AMPDU_QUEUE);
1053
1054 __skb_queue_head_init(&skbs);
1055 /*we can free until ssn % q.n_bd not inclusive */
1056 iwl_trans_reclaim(trans(priv), txq_id, ssn, status, &skbs);
1057 freed = 0;
1058 while (!skb_queue_empty(&skbs)) {
1059 skb = __skb_dequeue(&skbs);
1060 hdr = (struct ieee80211_hdr *)skb->data;
1061
1062 if (!ieee80211_is_data_qos(hdr->frame_control))
1063 priv->last_seq_ctl = tx_resp->seq_ctl;
1064
1065 info = IEEE80211_SKB_CB(skb);
1066 ctx = info->driver_data[0];
1067
1068 memset(&info->status, 0, sizeof(info->status));
1069
1070 if (status == TX_STATUS_FAIL_PASSIVE_NO_RX &&
1071 iwl_is_associated_ctx(ctx) && ctx->vif &&
1072 ctx->vif->type == NL80211_IFTYPE_STATION) {
1073 ctx->last_tx_rejected = true;
1074 iwl_stop_queue(priv, &priv->txq[txq_id]);
1075
1076 IWL_DEBUG_TX_REPLY(priv,
1077 "TXQ %d status %s (0x%08x) "
1078 "rate_n_flags 0x%x retries %d\n",
1079 txq_id,
1080 iwl_get_tx_fail_reason(status),
1081 status,
1082 le32_to_cpu(tx_resp->rate_n_flags),
1083 tx_resp->failure_frame);
1084
1085 IWL_DEBUG_TX_REPLY(priv,
1086 "FrameCnt = %d, idx=%d\n",
1087 tx_resp->frame_count, cmd_index);
1088 }
1089
1090 /* check if BAR is needed */
1091 if (is_agg && !iwl_is_tx_success(status))
1092 info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
1093 iwlagn_set_tx_status(priv, IEEE80211_SKB_CB(skb),
1094 tx_resp, is_agg);
1095 if (!is_agg)
1096 iwlagn_non_agg_tx_status(priv, ctx, hdr->addr1);
1097
1098 ieee80211_tx_status_irqsafe(priv->hw, skb);
1099
1100 freed++;
1101 }
74bcdb33 1102
a0eaad71 1103 WARN_ON(!is_agg && freed != 1);
74bcdb33 1104
a0eaad71
EG
1105 iwl_free_tfds_in_queue(priv, sta_id, tid, freed);
1106 iwlagn_txq_check_empty(priv, sta_id, tid, txq_id);
1107 }
8d801080 1108
a0eaad71
EG
1109 iwl_check_abort_status(priv, tx_resp->frame_count, status);
1110 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
8d801080
WYG
1111}
1112
74bcdb33
WYG
1113/**
1114 * iwlagn_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
1115 *
1116 * Handles block-acknowledge notification from device, which reports success
1117 * of frames sent via aggregation.
1118 */
1119void iwlagn_rx_reply_compressed_ba(struct iwl_priv *priv,
1120 struct iwl_rx_mem_buffer *rxb)
1121{
1122 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1123 struct iwl_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
1124 struct iwl_tx_queue *txq = NULL;
1125 struct iwl_ht_agg *agg;
a0eaad71
EG
1126 struct sk_buff_head reclaimed_skbs;
1127 struct ieee80211_tx_info *info;
1128 struct ieee80211_hdr *hdr;
1129 struct sk_buff *skb;
1130 unsigned long flags;
74bcdb33
WYG
1131 int index;
1132 int sta_id;
1133 int tid;
a0eaad71 1134 int freed;
74bcdb33
WYG
1135
1136 /* "flow" corresponds to Tx queue */
1137 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
1138
1139 /* "ssn" is start of block-ack Tx window, corresponds to index
1140 * (in Tx queue's circular buffer) of first TFD/frame in window */
1141 u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
1142
d6189124 1143 if (scd_flow >= hw_params(priv).max_txq_num) {
74bcdb33
WYG
1144 IWL_ERR(priv,
1145 "BUG_ON scd_flow is bigger than number of queues\n");
1146 return;
1147 }
1148
1149 txq = &priv->txq[scd_flow];
1150 sta_id = ba_resp->sta_id;
1151 tid = ba_resp->tid;
1152 agg = &priv->stations[sta_id].tid[tid].agg;
a0eaad71
EG
1153
1154 /* Find index of block-ack window */
1155 index = ba_resp_scd_ssn & (txq->q.n_bd - 1);
1156
1157 spin_lock_irqsave(&priv->shrd->sta_lock, flags);
1158
b561e827 1159 if (unlikely(agg->txq_id != scd_flow)) {
735df29a
WYG
1160 /*
1161 * FIXME: this is a uCode bug which need to be addressed,
1162 * log the information and return for now!
1163 * since it is possible happen very often and in order
1164 * not to fill the syslog, don't enable the logging by default
1165 */
1166 IWL_DEBUG_TX_REPLY(priv,
1167 "BA scd_flow %d does not match txq_id %d\n",
b561e827 1168 scd_flow, agg->txq_id);
a0eaad71 1169 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
b561e827
SZ
1170 return;
1171 }
74bcdb33 1172
a0eaad71
EG
1173 if (unlikely(!agg->wait_for_ba)) {
1174 if (unlikely(ba_resp->bitmap))
1175 IWL_ERR(priv, "Received BA when not expected\n");
1176 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
1177 return;
1178 }
74bcdb33
WYG
1179
1180 IWL_DEBUG_TX_REPLY(priv, "REPLY_COMPRESSED_BA [%d] Received from %pM, "
1181 "sta_id = %d\n",
1182 agg->wait_for_ba,
1183 (u8 *) &ba_resp->sta_addr_lo32,
1184 ba_resp->sta_id);
a0eaad71
EG
1185 IWL_DEBUG_TX_REPLY(priv, "TID = %d, SeqCtl = %d, bitmap = 0x%llx, "
1186 "scd_flow = %d, scd_ssn = %d\n",
74bcdb33
WYG
1187 ba_resp->tid,
1188 ba_resp->seq_ctl,
1189 (unsigned long long)le64_to_cpu(ba_resp->bitmap),
1190 ba_resp->scd_flow,
1191 ba_resp->scd_ssn);
74bcdb33 1192
a0eaad71
EG
1193 /* Mark that the expected block-ack response arrived */
1194 agg->wait_for_ba = 0;
1195
1196 /* Sanity check values reported by uCode */
1197 if (ba_resp->txed_2_done > ba_resp->txed) {
1198 IWL_DEBUG_TX_REPLY(priv,
1199 "bogus sent(%d) and ack(%d) count\n",
1200 ba_resp->txed, ba_resp->txed_2_done);
1201 /*
1202 * set txed_2_done = txed,
1203 * so it won't impact rate scale
1204 */
1205 ba_resp->txed = ba_resp->txed_2_done;
1206 }
1207 IWL_DEBUG_HT(priv, "agg frames sent:%d, acked:%d\n",
1208 ba_resp->txed, ba_resp->txed_2_done);
1209
1210 __skb_queue_head_init(&reclaimed_skbs);
74bcdb33
WYG
1211
1212 /* Release all TFDs before the SSN, i.e. all TFDs in front of
1213 * block-ack window (we assume that they've been successfully
1214 * transmitted ... if not, it's too late anyway). */
a0eaad71
EG
1215 iwl_trans_reclaim(trans(priv), scd_flow, ba_resp_scd_ssn, 0,
1216 &reclaimed_skbs);
1217 freed = 0;
1218 while (!skb_queue_empty(&reclaimed_skbs)) {
74bcdb33 1219
a0eaad71
EG
1220 skb = __skb_dequeue(&reclaimed_skbs);
1221 hdr = (struct ieee80211_hdr *)skb->data;
69fdb710 1222
a0eaad71
EG
1223 if (ieee80211_is_data_qos(hdr->frame_control))
1224 freed++;
1225 else
1226 WARN_ON_ONCE(1);
1227
1228 if (freed == 0) {
1229 /* this is the first skb we deliver in this batch */
1230 /* put the rate scaling data there */
1231 info = IEEE80211_SKB_CB(skb);
1232 memset(&info->status, 0, sizeof(info->status));
1233 info->flags |= IEEE80211_TX_STAT_ACK;
1234 info->flags |= IEEE80211_TX_STAT_AMPDU;
1235 info->status.ampdu_ack_len = ba_resp->txed_2_done;
1236 info->status.ampdu_len = ba_resp->txed;
1237 iwlagn_hwrate_to_tx_control(priv, agg->rate_n_flags,
1238 info);
1239 }
69fdb710 1240
a0eaad71 1241 ieee80211_tx_status_irqsafe(priv->hw, skb);
69fdb710
JB
1242 }
1243
a0eaad71
EG
1244 iwl_free_tfds_in_queue(priv, sta_id, tid, freed);
1245 iwlagn_txq_check_empty(priv, sta_id, tid, scd_flow);
69fdb710 1246
a0eaad71 1247 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
69fdb710 1248}
This page took 0.293197 seconds and 5 git commands to generate.