1 /******************************************************************************
5 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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,
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/sched.h>
34 #include <linux/ieee80211.h>
40 #include "iwl-helpers.h"
41 #include "iwl-agn-hw.h"
43 #include "iwl-trans.h"
46 * mac80211 queues, ACs, hardware queues, FIFOs.
48 * Cf. http://wireless.kernel.org/en/developers/Documentation/mac80211/queues
50 * Mac80211 uses the following numbers, which we get as from it
51 * by way of skb_get_queue_mapping(skb):
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.
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
71 static const u8 tid_to_ac
[] = {
82 static inline int get_ac_from_tid(u16 tid
)
84 if (likely(tid
< ARRAY_SIZE(tid_to_ac
)))
85 return tid_to_ac
[tid
];
87 /* no support for TIDs 8-15 yet */
91 static inline int get_fifo_from_tid(struct iwl_rxon_context
*ctx
, u16 tid
)
93 if (likely(tid
< ARRAY_SIZE(tid_to_ac
)))
94 return ctx
->ac_to_fifo
[tid_to_ac
[tid
]];
96 /* no support for TIDs 8-15 yet */
100 static int iwlagn_txq_agg_enable(struct iwl_priv
*priv
, int txq_id
, int sta_id
,
103 if ((IWLAGN_FIRST_AMPDU_QUEUE
> txq_id
) ||
104 (IWLAGN_FIRST_AMPDU_QUEUE
+
105 priv
->cfg
->base_params
->num_of_ampdu_queues
<= txq_id
)) {
107 "queue number out of range: %d, must be %d to %d\n",
108 txq_id
, IWLAGN_FIRST_AMPDU_QUEUE
,
109 IWLAGN_FIRST_AMPDU_QUEUE
+
110 priv
->cfg
->base_params
->num_of_ampdu_queues
- 1);
114 /* Modify device's station table to Tx this TID */
115 return iwl_sta_tx_modify_enable_tid(priv
, sta_id
, tid
);
118 static void iwlagn_tx_cmd_protection(struct iwl_priv
*priv
,
119 struct ieee80211_tx_info
*info
,
120 __le16 fc
, __le32
*tx_flags
)
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
;
129 * handle build REPLY_TX command notification.
131 static void iwlagn_tx_cmd_build_basic(struct iwl_priv
*priv
,
133 struct iwl_tx_cmd
*tx_cmd
,
134 struct ieee80211_tx_info
*info
,
135 struct ieee80211_hdr
*hdr
, u8 sta_id
)
137 __le16 fc
= hdr
->frame_control
;
138 __le32 tx_flags
= tx_cmd
->tx_flags
;
140 tx_cmd
->stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
142 if (!(info
->flags
& IEEE80211_TX_CTL_NO_ACK
))
143 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
145 tx_flags
&= ~TX_CMD_FLG_ACK_MSK
;
147 if (ieee80211_is_probe_resp(fc
))
148 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
149 else if (ieee80211_is_back_req(fc
))
150 tx_flags
|= TX_CMD_FLG_ACK_MSK
| TX_CMD_FLG_IMM_BA_RSP_MASK
;
151 else if (info
->band
== IEEE80211_BAND_2GHZ
&&
152 priv
->cfg
->bt_params
&&
153 priv
->cfg
->bt_params
->advanced_bt_coexist
&&
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
;
160 tx_cmd
->sta_id
= sta_id
;
161 if (ieee80211_has_morefrags(fc
))
162 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
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
;
169 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
172 iwlagn_tx_cmd_protection(priv
, info
, fc
, &tx_flags
);
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);
179 tx_cmd
->timeout
.pm_frame_timeout
= cpu_to_le16(2);
181 tx_cmd
->timeout
.pm_frame_timeout
= 0;
184 tx_cmd
->driver_txop
= 0;
185 tx_cmd
->tx_flags
= tx_flags
;
186 tx_cmd
->next_frame_len
= 0;
189 #define RTS_DFAULT_RETRY_LIMIT 60
191 static void iwlagn_tx_cmd_build_rate(struct iwl_priv
*priv
,
192 struct iwl_tx_cmd
*tx_cmd
,
193 struct ieee80211_tx_info
*info
,
202 /* Set retry limit on DATA packets and Probe Responses*/
203 if (ieee80211_is_probe_resp(fc
))
204 data_retry_limit
= 3;
206 data_retry_limit
= IWLAGN_DEFAULT_TX_RETRY
;
207 tx_cmd
->data_retry_limit
= data_retry_limit
;
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
;
215 /* DATA packets will use the uCode station table for rate/antenna
217 if (ieee80211_is_data(fc
)) {
218 tx_cmd
->initial_rate_index
= 0;
219 tx_cmd
->tx_flags
|= TX_CMD_FLG_STA_RATE_MSK
;
220 #ifdef CONFIG_IWLWIFI_DEVICE_SVTOOL
221 if (priv
->tm_fixed_rate
) {
223 * rate overwrite by testmode
224 * we not only send lq command to change rate
225 * we also re-enforce per data pkt base.
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
));
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
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
],
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 */
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
;
258 /* Set up antennas */
259 if (priv
->cfg
->bt_params
&&
260 priv
->cfg
->bt_params
->advanced_bt_coexist
&&
261 priv
->bt_full_concurrent
) {
262 /* operated as 1x1 in full concurrency mode */
263 priv
->mgmt_tx_ant
= iwl_toggle_tx_ant(priv
, priv
->mgmt_tx_ant
,
264 first_antenna(hw_params(priv
).valid_tx_ant
));
266 priv
->mgmt_tx_ant
= iwl_toggle_tx_ant(priv
, priv
->mgmt_tx_ant
,
267 hw_params(priv
).valid_tx_ant
);
268 rate_flags
|= iwl_ant_idx_to_flags(priv
->mgmt_tx_ant
);
270 /* Set the rate in the TX cmd */
271 tx_cmd
->rate_n_flags
= iwl_hw_set_rate_n_flags(rate_plcp
, rate_flags
);
274 static 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
,
280 struct ieee80211_key_conf
*keyconf
= info
->control
.hw_key
;
282 switch (keyconf
->cipher
) {
283 case WLAN_CIPHER_SUITE_CCMP
:
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");
291 case WLAN_CIPHER_SUITE_TKIP
:
292 tx_cmd
->sec_ctl
= TX_CMD_SEC_TKIP
;
293 ieee80211_get_tkip_p2k(keyconf
, skb_frag
, tx_cmd
->key
);
294 IWL_DEBUG_TX(priv
, "tx_cmd with tkip hwcrypto\n");
297 case WLAN_CIPHER_SUITE_WEP104
:
298 tx_cmd
->sec_ctl
|= TX_CMD_SEC_KEY128
;
300 case WLAN_CIPHER_SUITE_WEP40
:
301 tx_cmd
->sec_ctl
|= (TX_CMD_SEC_WEP
|
302 (keyconf
->keyidx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
);
304 memcpy(&tx_cmd
->key
[3], keyconf
->key
, keyconf
->keylen
);
306 IWL_DEBUG_TX(priv
, "Configuring packet for WEP encryption "
307 "with key %d\n", keyconf
->keyidx
);
311 IWL_ERR(priv
, "Unknown encode cipher %x\n", keyconf
->cipher
);
317 * start REPLY_TX command process
319 int iwlagn_tx_skb(struct iwl_priv
*priv
, struct sk_buff
*skb
)
321 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
322 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
323 struct iwl_station_priv
*sta_priv
= NULL
;
324 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
325 struct iwl_tx_cmd
*tx_cmd
;
337 if (info
->control
.vif
)
338 ctx
= iwl_rxon_ctx_from_vif(info
->control
.vif
);
340 spin_lock_irqsave(&priv
->shrd
->lock
, flags
);
341 if (iwl_is_rfkill(priv
)) {
342 IWL_DEBUG_DROP(priv
, "Dropping - RF KILL\n");
343 goto drop_unlock_priv
;
346 fc
= hdr
->frame_control
;
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");
357 hdr_len
= ieee80211_hdrlen(fc
);
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
;
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",
368 goto drop_unlock_priv
;
372 IWL_DEBUG_TX(priv
, "station Id %d\n", sta_id
);
374 if (info
->control
.sta
)
375 sta_priv
= (void *)info
->control
.sta
->drv_priv
;
377 if (sta_priv
&& sta_priv
->asleep
&&
378 (info
->flags
& IEEE80211_TX_CTL_PSPOLL_RESPONSE
)) {
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
385 * For now set the counter to just 1 since we do not
388 iwl_sta_modify_sleep_tx_count(priv
, sta_id
, 1);
392 * Send this frame after DTIM -- there's a special queue
393 * reserved for this for contexts that support AP mode.
395 if (info
->flags
& IEEE80211_TX_CTL_SEND_AFTER_DTIM
) {
396 txq_id
= ctx
->mcast_queue
;
398 * The microcode will clear the more data
399 * bit in the last frame it transmits.
401 hdr
->frame_control
|=
402 cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
403 } else if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
)
404 txq_id
= IWL_AUX_QUEUE
;
406 txq_id
= ctx
->ac_to_queue
[skb_get_queue_mapping(skb
)];
408 /* irqs already disabled/saved above when locking priv->shrd->lock */
409 spin_lock(&priv
->shrd
->sta_lock
);
411 if (ieee80211_is_data_qos(fc
)) {
413 qc
= ieee80211_get_qos_ctl(hdr
);
414 tid
= qc
[0] & IEEE80211_QOS_CTL_TID_MASK
;
416 if (WARN_ON_ONCE(tid
>= MAX_TID_COUNT
))
417 goto drop_unlock_sta
;
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
);
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
;
433 tx_cmd
= iwl_trans_get_tx_cmd(trans(priv
), txq_id
);
434 if (unlikely(!tx_cmd
))
435 goto drop_unlock_sta
;
437 /* Copy MAC header from skb into command buffer */
438 memcpy(tx_cmd
->hdr
, hdr
, hdr_len
);
440 /* Total # bytes to be transmitted */
442 tx_cmd
->len
= cpu_to_le16(len
);
444 if (info
->control
.hw_key
)
445 iwlagn_tx_cmd_build_hwcrypto(priv
, info
, tx_cmd
, skb
, sta_id
);
447 /* TODO need this for burst mode later on */
448 iwlagn_tx_cmd_build_basic(priv
, skb
, tx_cmd
, info
, hdr
, sta_id
);
449 iwl_dbg_log_tx_data_frame(priv
, len
, hdr
);
451 iwlagn_tx_cmd_build_rate(priv
, tx_cmd
, info
, fc
);
453 iwl_update_stats(priv
, true, fc
, len
);
455 if (iwl_trans_tx(trans(priv
), skb
, tx_cmd
, txq_id
, fc
, is_agg
, ctx
))
456 goto drop_unlock_sta
;
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
;
464 spin_unlock(&priv
->shrd
->sta_lock
);
465 spin_unlock_irqrestore(&priv
->shrd
->lock
, flags
);
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
474 if (sta_priv
&& sta_priv
->client
&& !is_agg
)
475 atomic_inc(&sta_priv
->pending_frames
);
480 spin_unlock(&priv
->shrd
->sta_lock
);
482 spin_unlock_irqrestore(&priv
->shrd
->lock
, flags
);
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)
492 static int iwlagn_txq_ctx_activate_free(struct iwl_priv
*priv
)
496 for (txq_id
= 0; txq_id
< hw_params(priv
).max_txq_num
; txq_id
++)
497 if (!test_and_set_bit(txq_id
, &priv
->txq_ctx_active_msk
))
502 int iwlagn_tx_agg_start(struct iwl_priv
*priv
, struct ieee80211_vif
*vif
,
503 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
)
510 struct iwl_tid_data
*tid_data
;
512 tx_fifo
= get_fifo_from_tid(iwl_rxon_ctx_from_vif(vif
), tid
);
513 if (unlikely(tx_fifo
< 0))
516 IWL_DEBUG_HT(priv
, "TX AGG request on ra = %pM tid = %d\n",
519 sta_id
= iwl_sta_id(sta
);
520 if (sta_id
== IWL_INVALID_STATION
) {
521 IWL_ERR(priv
, "Start AGG on invalid station\n");
524 if (unlikely(tid
>= MAX_TID_COUNT
))
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");
532 txq_id
= iwlagn_txq_ctx_activate_free(priv
);
534 IWL_ERR(priv
, "No free aggregation queue available\n");
538 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
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
;
542 tid_data
->agg
.tx_fifo
= tx_fifo
;
543 iwl_set_swq_id(&priv
->txq
[txq_id
], get_ac_from_tid(tid
), txq_id
);
544 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
546 ret
= iwlagn_txq_agg_enable(priv
, txq_id
, sta_id
, tid
);
550 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
551 tid_data
= &priv
->stations
[sta_id
].tid
[tid
];
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
;
555 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
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
;
561 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
565 int iwlagn_tx_agg_stop(struct iwl_priv
*priv
, struct ieee80211_vif
*vif
,
566 struct ieee80211_sta
*sta
, u16 tid
)
568 int tx_fifo_id
, txq_id
, sta_id
, ssn
;
569 struct iwl_tid_data
*tid_data
;
570 int write_ptr
, read_ptr
;
573 tx_fifo_id
= get_fifo_from_tid(iwl_rxon_ctx_from_vif(vif
), tid
);
574 if (unlikely(tx_fifo_id
< 0))
577 sta_id
= iwl_sta_id(sta
);
579 if (sta_id
== IWL_INVALID_STATION
) {
580 IWL_ERR(priv
, "Invalid station for AGG tid %d\n", tid
);
584 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
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
;
590 switch (priv
->stations
[sta_id
].tid
[tid
].agg
.state
) {
591 case IWL_EMPTYING_HW_QUEUE_ADDBA
:
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.
598 IWL_DEBUG_HT(priv
, "AGG stop before setup done\n");
603 IWL_WARN(priv
, "Stopping AGG while state not ON or starting\n");
606 write_ptr
= priv
->txq
[txq_id
].q
.write_ptr
;
607 read_ptr
= priv
->txq
[txq_id
].q
.read_ptr
;
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
;
614 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
618 IWL_DEBUG_HT(priv
, "HW queue is empty\n");
620 priv
->stations
[sta_id
].tid
[tid
].agg
.state
= IWL_AGG_OFF
;
622 /* do not restore/save irqs */
623 spin_unlock(&priv
->shrd
->sta_lock
);
624 spin_lock(&priv
->shrd
->lock
);
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.
633 iwl_trans_txq_agg_disable(trans(priv
), txq_id
, ssn
, tx_fifo_id
);
634 spin_unlock_irqrestore(&priv
->shrd
->lock
, flags
);
636 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
641 int iwlagn_txq_check_empty(struct iwl_priv
*priv
,
642 int sta_id
, u8 tid
, int txq_id
)
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
];
647 struct iwl_rxon_context
*ctx
;
649 ctx
= &priv
->contexts
[priv
->stations
[sta_id
].ctxid
];
651 lockdep_assert_held(&priv
->shrd
->sta_lock
);
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
);
660 int tx_fifo
= get_fifo_from_tid(ctx
, tid
);
661 IWL_DEBUG_HT(priv
, "HW queue empty: continue DELBA flow\n");
662 iwl_trans_txq_agg_disable(trans(priv
), txq_id
,
664 tid_data
->agg
.state
= IWL_AGG_OFF
;
665 ieee80211_stop_tx_ba_cb_irqsafe(ctx
->vif
, addr
, tid
);
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
;
673 ieee80211_start_tx_ba_cb_irqsafe(ctx
->vif
, addr
, tid
);
681 static void iwlagn_non_agg_tx_status(struct iwl_priv
*priv
,
682 struct iwl_rxon_context
*ctx
,
685 struct ieee80211_sta
*sta
;
686 struct iwl_station_priv
*sta_priv
;
689 sta
= ieee80211_find_sta(ctx
->vif
, addr1
);
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);
701 * translate ucode response to mac80211 tx status control values
703 void iwlagn_hwrate_to_tx_control(struct iwl_priv
*priv
, u32 rate_n_flags
,
704 struct ieee80211_tx_info
*info
)
706 struct ieee80211_tx_rate
*r
= &info
->control
.rates
[0];
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
);
723 #ifdef CONFIG_IWLWIFI_DEBUG
724 const char *iwl_get_tx_fail_reason(u32 status
)
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
729 switch (status
& TX_STATUS_MSK
) {
730 case TX_STATUS_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
);
758 #undef TX_STATUS_FAIL
759 #undef TX_STATUS_POSTPONE
761 #endif /* CONFIG_IWLWIFI_DEBUG */
763 static void iwl_rx_reply_tx_agg(struct iwl_priv
*priv
,
764 struct iwlagn_tx_resp
*tx_resp
)
766 struct agg_tx_status
*frame_status
= &tx_resp
->status
;
767 int tid
= (tx_resp
->ra_tid
& IWLAGN_TX_RES_TID_MSK
) >>
768 IWLAGN_TX_RES_TID_POS
;
769 int sta_id
= (tx_resp
->ra_tid
& IWLAGN_TX_RES_RA_MSK
) >>
770 IWLAGN_TX_RES_RA_POS
;
771 struct iwl_ht_agg
*agg
= &priv
->stations
[sta_id
].tid
[tid
].agg
;
772 u32 status
= le16_to_cpu(tx_resp
->status
.status
);
775 if (agg
->wait_for_ba
)
776 IWL_DEBUG_TX_REPLY(priv
,
777 "got tx response w/o block-ack\n");
779 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
780 agg
->wait_for_ba
= (tx_resp
->frame_count
> 1);
783 * If the BT kill count is non-zero, we'll get this
784 * notification again.
786 if (tx_resp
->bt_kill_count
&& tx_resp
->frame_count
== 1 &&
787 priv
->cfg
->bt_params
&&
788 priv
->cfg
->bt_params
->advanced_bt_coexist
) {
789 IWL_DEBUG_COEX(priv
, "receive reply tx w/ bt_kill\n");
792 /* Construct bit-map of pending frames within Tx window */
793 for (i
= 0; i
< tx_resp
->frame_count
; i
++) {
794 u16 fstatus
= le16_to_cpu(frame_status
[i
].status
);
796 if (status
& AGG_TX_STATUS_MSK
)
797 iwlagn_count_agg_tx_err_status(priv
, fstatus
);
799 if (status
& (AGG_TX_STATE_FEW_BYTES_MSK
|
800 AGG_TX_STATE_ABORT_MSK
))
803 IWL_DEBUG_TX_REPLY(priv
, "status %s (0x%08x), "
804 "try-count (0x%08x)\n",
805 iwl_get_agg_tx_fail_reason(fstatus
),
806 fstatus
& AGG_TX_STATUS_MSK
,
807 fstatus
& AGG_TX_TRY_MSK
);
811 static inline u32
iwlagn_get_scd_ssn(struct iwlagn_tx_resp
*tx_resp
)
813 return le32_to_cpup((__le32
*)&tx_resp
->status
+
814 tx_resp
->frame_count
) & MAX_SN
;
817 void iwlagn_rx_reply_tx(struct iwl_priv
*priv
, struct iwl_rx_mem_buffer
*rxb
)
819 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
820 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
821 int txq_id
= SEQ_TO_QUEUE(sequence
);
822 int cmd_index
= SEQ_TO_INDEX(sequence
);
823 struct iwl_tx_queue
*txq
= &priv
->txq
[txq_id
];
824 struct iwlagn_tx_resp
*tx_resp
= (void *)&pkt
->u
.raw
[0];
825 struct ieee80211_hdr
*hdr
;
826 u32 status
= le16_to_cpu(tx_resp
->status
.status
);
827 u32 ssn
= iwlagn_get_scd_ssn(tx_resp
);
831 struct ieee80211_tx_info
*info
;
833 struct sk_buff_head skbs
;
835 struct iwl_rxon_context
*ctx
;
837 if ((cmd_index
>= txq
->q
.n_bd
) ||
838 (iwl_queue_used(&txq
->q
, cmd_index
) == 0)) {
839 IWL_ERR(priv
, "%s: Read index for DMA queue txq_id (%d) "
840 "cmd_index %d is out of range [0-%d] %d %d\n",
841 __func__
, txq_id
, cmd_index
, txq
->q
.n_bd
,
842 txq
->q
.write_ptr
, txq
->q
.read_ptr
);
846 txq
->time_stamp
= jiffies
;
848 tid
= (tx_resp
->ra_tid
& IWLAGN_TX_RES_TID_MSK
) >>
849 IWLAGN_TX_RES_TID_POS
;
850 sta_id
= (tx_resp
->ra_tid
& IWLAGN_TX_RES_RA_MSK
) >>
851 IWLAGN_TX_RES_RA_POS
;
853 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
855 if (txq
->sched_retry
)
856 iwl_rx_reply_tx_agg(priv
, tx_resp
);
858 if (tx_resp
->frame_count
== 1) {
859 bool is_agg
= (txq_id
>= IWLAGN_FIRST_AMPDU_QUEUE
);
861 __skb_queue_head_init(&skbs
);
862 /*we can free until ssn % q.n_bd not inclusive */
863 iwl_trans_reclaim(trans(priv
), txq_id
, ssn
, status
, &skbs
);
865 while (!skb_queue_empty(&skbs
)) {
866 skb
= __skb_dequeue(&skbs
);
867 hdr
= (struct ieee80211_hdr
*)skb
->data
;
869 if (!ieee80211_is_data_qos(hdr
->frame_control
))
870 priv
->last_seq_ctl
= tx_resp
->seq_ctl
;
872 info
= IEEE80211_SKB_CB(skb
);
873 ctx
= info
->driver_data
[0];
875 memset(&info
->status
, 0, sizeof(info
->status
));
877 if (status
== TX_STATUS_FAIL_PASSIVE_NO_RX
&&
878 iwl_is_associated_ctx(ctx
) && ctx
->vif
&&
879 ctx
->vif
->type
== NL80211_IFTYPE_STATION
) {
880 ctx
->last_tx_rejected
= true;
881 iwl_stop_queue(priv
, &priv
->txq
[txq_id
]);
883 IWL_DEBUG_TX_REPLY(priv
,
884 "TXQ %d status %s (0x%08x) "
885 "rate_n_flags 0x%x retries %d\n",
887 iwl_get_tx_fail_reason(status
),
889 le32_to_cpu(tx_resp
->rate_n_flags
),
890 tx_resp
->failure_frame
);
892 IWL_DEBUG_TX_REPLY(priv
,
893 "FrameCnt = %d, idx=%d\n",
894 tx_resp
->frame_count
, cmd_index
);
897 /* check if BAR is needed */
898 if (is_agg
&& !iwl_is_tx_success(status
))
899 info
->flags
|= IEEE80211_TX_STAT_AMPDU_NO_BACK
;
900 iwlagn_set_tx_status(priv
, IEEE80211_SKB_CB(skb
),
903 iwlagn_non_agg_tx_status(priv
, ctx
, hdr
->addr1
);
905 ieee80211_tx_status_irqsafe(priv
->hw
, skb
);
910 WARN_ON(!is_agg
&& freed
!= 1);
912 iwl_free_tfds_in_queue(priv
, sta_id
, tid
, freed
);
913 iwlagn_txq_check_empty(priv
, sta_id
, tid
, txq_id
);
916 iwl_check_abort_status(priv
, tx_resp
->frame_count
, status
);
917 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
921 * iwlagn_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
923 * Handles block-acknowledge notification from device, which reports success
924 * of frames sent via aggregation.
926 void iwlagn_rx_reply_compressed_ba(struct iwl_priv
*priv
,
927 struct iwl_rx_mem_buffer
*rxb
)
929 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
930 struct iwl_compressed_ba_resp
*ba_resp
= &pkt
->u
.compressed_ba
;
931 struct iwl_tx_queue
*txq
= NULL
;
932 struct iwl_ht_agg
*agg
;
933 struct sk_buff_head reclaimed_skbs
;
934 struct ieee80211_tx_info
*info
;
935 struct ieee80211_hdr
*hdr
;
943 /* "flow" corresponds to Tx queue */
944 u16 scd_flow
= le16_to_cpu(ba_resp
->scd_flow
);
946 /* "ssn" is start of block-ack Tx window, corresponds to index
947 * (in Tx queue's circular buffer) of first TFD/frame in window */
948 u16 ba_resp_scd_ssn
= le16_to_cpu(ba_resp
->scd_ssn
);
950 if (scd_flow
>= hw_params(priv
).max_txq_num
) {
952 "BUG_ON scd_flow is bigger than number of queues\n");
956 txq
= &priv
->txq
[scd_flow
];
957 sta_id
= ba_resp
->sta_id
;
959 agg
= &priv
->stations
[sta_id
].tid
[tid
].agg
;
961 /* Find index of block-ack window */
962 index
= ba_resp_scd_ssn
& (txq
->q
.n_bd
- 1);
964 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
966 if (unlikely(agg
->txq_id
!= scd_flow
)) {
968 * FIXME: this is a uCode bug which need to be addressed,
969 * log the information and return for now!
970 * since it is possible happen very often and in order
971 * not to fill the syslog, don't enable the logging by default
973 IWL_DEBUG_TX_REPLY(priv
,
974 "BA scd_flow %d does not match txq_id %d\n",
975 scd_flow
, agg
->txq_id
);
976 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
980 if (unlikely(!agg
->wait_for_ba
)) {
981 if (unlikely(ba_resp
->bitmap
))
982 IWL_ERR(priv
, "Received BA when not expected\n");
983 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
987 IWL_DEBUG_TX_REPLY(priv
, "REPLY_COMPRESSED_BA [%d] Received from %pM, "
990 (u8
*) &ba_resp
->sta_addr_lo32
,
992 IWL_DEBUG_TX_REPLY(priv
, "TID = %d, SeqCtl = %d, bitmap = 0x%llx, "
993 "scd_flow = %d, scd_ssn = %d\n",
996 (unsigned long long)le64_to_cpu(ba_resp
->bitmap
),
1000 /* Mark that the expected block-ack response arrived */
1001 agg
->wait_for_ba
= 0;
1003 /* Sanity check values reported by uCode */
1004 if (ba_resp
->txed_2_done
> ba_resp
->txed
) {
1005 IWL_DEBUG_TX_REPLY(priv
,
1006 "bogus sent(%d) and ack(%d) count\n",
1007 ba_resp
->txed
, ba_resp
->txed_2_done
);
1009 * set txed_2_done = txed,
1010 * so it won't impact rate scale
1012 ba_resp
->txed
= ba_resp
->txed_2_done
;
1014 IWL_DEBUG_HT(priv
, "agg frames sent:%d, acked:%d\n",
1015 ba_resp
->txed
, ba_resp
->txed_2_done
);
1017 __skb_queue_head_init(&reclaimed_skbs
);
1019 /* Release all TFDs before the SSN, i.e. all TFDs in front of
1020 * block-ack window (we assume that they've been successfully
1021 * transmitted ... if not, it's too late anyway). */
1022 iwl_trans_reclaim(trans(priv
), scd_flow
, ba_resp_scd_ssn
, 0,
1025 while (!skb_queue_empty(&reclaimed_skbs
)) {
1027 skb
= __skb_dequeue(&reclaimed_skbs
);
1028 hdr
= (struct ieee80211_hdr
*)skb
->data
;
1030 if (ieee80211_is_data_qos(hdr
->frame_control
))
1036 /* this is the first skb we deliver in this batch */
1037 /* put the rate scaling data there */
1038 info
= IEEE80211_SKB_CB(skb
);
1039 memset(&info
->status
, 0, sizeof(info
->status
));
1040 info
->flags
|= IEEE80211_TX_STAT_ACK
;
1041 info
->flags
|= IEEE80211_TX_STAT_AMPDU
;
1042 info
->status
.ampdu_ack_len
= ba_resp
->txed_2_done
;
1043 info
->status
.ampdu_len
= ba_resp
->txed
;
1044 iwlagn_hwrate_to_tx_control(priv
, agg
->rate_n_flags
,
1048 ieee80211_tx_status_irqsafe(priv
->hw
, skb
);
1051 iwl_free_tfds_in_queue(priv
, sta_id
, tid
, freed
);
1052 iwlagn_txq_check_empty(priv
, sta_id
, tid
, scd_flow
);
1054 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);