blob: 60ba4f84285a94f3353a91a9768e6ccf157b6159 [file] [log] [blame]
Wey-Yi Guyb305a082010-03-16 17:41:22 -07001/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
Wey-Yi Guy901069c2011-04-05 09:42:00 -07005 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
Wey-Yi Guyb305a082010-03-16 17:41:22 -07006 *
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>
Emmanuel Grumbacha0eaad72011-08-25 23:11:00 -070034#include <linux/ieee80211.h>
Wey-Yi Guyb305a082010-03-16 17:41:22 -070035
36#include "iwl-dev.h"
37#include "iwl-core.h"
38#include "iwl-sta.h"
39#include "iwl-io.h"
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -070040#include "iwl-helpers.h"
Wey-Yi Guy19e6cda2010-03-16 17:41:23 -070041#include "iwl-agn-hw.h"
Wey-Yi Guy8d801082010-03-17 13:34:36 -070042#include "iwl-agn.h"
Emmanuel Grumbach47c1b492011-07-03 11:22:15 +030043#include "iwl-trans.h"
Wey-Yi Guyb305a082010-03-16 17:41:22 -070044
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -070045/*
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[] = {
Johannes Berg0c4ac342010-11-17 11:33:27 -080072 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
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -070080};
81
Shanyu Zhaoc2845d02010-04-14 15:35:14 -070082static 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
Johannes Berge72f3682010-08-23 10:46:51 +020091static inline int get_fifo_from_tid(struct iwl_rxon_context *ctx, u16 tid)
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -070092{
93 if (likely(tid < ARRAY_SIZE(tid_to_ac)))
Johannes Berge72f3682010-08-23 10:46:51 +020094 return ctx->ac_to_fifo[tid_to_ac[tid]];
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -070095
96 /* no support for TIDs 8-15 yet */
97 return -EINVAL;
98}
99
Emmanuel Grumbach48d42c42011-07-10 10:47:01 +0300100static int iwlagn_txq_agg_enable(struct iwl_priv *priv, int txq_id, int sta_id,
101 int tid)
Wey-Yi Guyb305a082010-03-16 17:41:22 -0700102{
Wey-Yi Guy19e6cda2010-03-16 17:41:23 -0700103 if ((IWLAGN_FIRST_AMPDU_QUEUE > txq_id) ||
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700104 (IWLAGN_FIRST_AMPDU_QUEUE +
Emmanuel Grumbachfd656932011-08-25 23:11:19 -0700105 hw_params(priv).num_ampdu_queues <= txq_id)) {
Wey-Yi Guyb305a082010-03-16 17:41:22 -0700106 IWL_WARN(priv,
107 "queue number out of range: %d, must be %d to %d\n",
Wey-Yi Guy19e6cda2010-03-16 17:41:23 -0700108 txq_id, IWLAGN_FIRST_AMPDU_QUEUE,
109 IWLAGN_FIRST_AMPDU_QUEUE +
Emmanuel Grumbachfd656932011-08-25 23:11:19 -0700110 hw_params(priv).num_ampdu_queues - 1);
Wey-Yi Guyb305a082010-03-16 17:41:22 -0700111 return -EINVAL;
112 }
113
Wey-Yi Guyb305a082010-03-16 17:41:22 -0700114 /* Modify device's station table to Tx this TID */
Johannes Bergc8823ec2011-03-15 11:33:03 -0700115 return iwl_sta_tx_modify_enable_tid(priv, sta_id, tid);
116}
117
Don Fry5c3d29f2011-07-08 08:46:29 -0700118static 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
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700128/*
129 * handle build REPLY_TX command notification.
130 */
131static void iwlagn_tx_cmd_build_basic(struct iwl_priv *priv,
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700132 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)
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700136{
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;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700141
Johannes Berg2c2def12011-07-07 05:11:51 -0700142 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
143 tx_flags |= TX_CMD_FLG_ACK_MSK;
144 else
145 tx_flags &= ~TX_CMD_FLG_ACK_MSK;
146
147 if (ieee80211_is_probe_resp(fc))
148 tx_flags |= TX_CMD_FLG_TSF_MSK;
149 else if (ieee80211_is_back_req(fc))
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700150 tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
Johannes Bergd44ae692010-08-23 07:56:56 -0700151 else if (info->band == IEEE80211_BAND_2GHZ &&
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700152 priv->cfg->bt_params &&
153 priv->cfg->bt_params->advanced_bt_coexist &&
Johannes Bergd44ae692010-08-23 07:56:56 -0700154 (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;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700158
159
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700160 tx_cmd->sta_id = sta_id;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700161 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
Don Fry5c3d29f2011-07-08 08:46:29 -0700172 iwlagn_tx_cmd_protection(priv, info, fc, &tx_flags);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700173
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,
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700192 struct iwl_tx_cmd *tx_cmd,
193 struct ieee80211_tx_info *info,
194 __le16 fc)
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700195{
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
Wey-Yi Guyb744cb72010-03-23 11:37:59 -0700206 data_retry_limit = IWLAGN_DEFAULT_TX_RETRY;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700207 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;
Wey-Yi Guyc10e2c12011-07-13 11:13:46 -0700220#ifdef CONFIG_IWLWIFI_DEVICE_SVTOOL
Wey-Yi Guy4e308112011-07-08 08:46:28 -0700221 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 }
Wey-Yi Guyc10e2c12011-07-13 11:13:46 -0700231#endif
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700232 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
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700258 /* Set up antennas */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700259 if (priv->cfg->bt_params &&
260 priv->cfg->bt_params->advanced_bt_coexist &&
261 priv->bt_full_concurrent) {
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700262 /* operated as 1x1 in full concurrency mode */
263 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700264 first_antenna(hw_params(priv).valid_tx_ant));
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700265 } else
266 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700267 hw_params(priv).valid_tx_ant);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700268 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
Johannes Berg97359d12010-08-10 09:46:38 +0200282 switch (keyconf->cipher) {
283 case WLAN_CIPHER_SUITE_CCMP:
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700284 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
Johannes Berg97359d12010-08-10 09:46:38 +0200291 case WLAN_CIPHER_SUITE_TKIP:
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700292 tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
Johannes Berg523b02e2011-07-07 22:28:01 +0200293 ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700294 IWL_DEBUG_TX(priv, "tx_cmd with tkip hwcrypto\n");
295 break;
296
Johannes Berg97359d12010-08-10 09:46:38 +0200297 case WLAN_CIPHER_SUITE_WEP104:
298 tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
299 /* fall through */
300 case WLAN_CIPHER_SUITE_WEP40:
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700301 tx_cmd->sec_ctl |= (TX_CMD_SEC_WEP |
302 (keyconf->keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT);
303
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700304 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:
Johannes Berg97359d12010-08-10 09:46:38 +0200311 IWL_ERR(priv, "Unknown encode cipher %x\n", keyconf->cipher);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700312 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);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700323 struct iwl_station_priv *sta_priv = NULL;
Johannes Berga194e322010-08-27 08:53:46 -0700324 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Emmanuel Grumbach47c1b492011-07-03 11:22:15 +0300325 struct iwl_tx_cmd *tx_cmd;
Johannes Berg8d563962010-11-10 18:25:42 -0800326 int txq_id;
Emmanuel Grumbach47c1b492011-07-03 11:22:15 +0300327
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700328 u16 seq_number = 0;
329 __le16 fc;
330 u8 hdr_len;
Emmanuel Grumbach47c1b492011-07-03 11:22:15 +0300331 u16 len;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700332 u8 sta_id;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700333 u8 tid = 0;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700334 unsigned long flags;
Johannes Berg2e340342010-11-16 11:51:38 -0800335 bool is_agg = false;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700336
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700337 if (info->control.vif)
Johannes Berga194e322010-08-27 08:53:46 -0700338 ctx = iwl_rxon_ctx_from_vif(info->control.vif);
339
Emmanuel Grumbach10b15e62011-08-25 23:10:43 -0700340 spin_lock_irqsave(&priv->shrd->lock, flags);
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -0700341 if (iwl_is_rfkill(priv->shrd)) {
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700342 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Johannes Berg2c46f722011-04-28 07:27:10 -0700343 goto drop_unlock_priv;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700344 }
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
Stanislaw Gruszkabfd36102011-04-29 17:51:06 +0200359 /* 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);
John W. Linvillee00cf3b2011-05-16 14:55:42 -0400368 goto drop_unlock_priv;
Stanislaw Gruszkabfd36102011-04-29 17:51:06 +0200369 }
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700370 }
371
372 IWL_DEBUG_TX(priv, "station Id %d\n", sta_id);
373
Emmanuel Grumbach47c1b492011-07-03 11:22:15 +0300374 if (info->control.sta)
375 sta_priv = (void *)info->control.sta->drv_priv;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700376
Johannes Berg67158b62010-11-16 11:51:04 -0800377 if (sta_priv && sta_priv->asleep &&
378 (info->flags & IEEE80211_TX_CTL_PSPOLL_RESPONSE)) {
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700379 /*
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
Johannes Berge72f3682010-08-23 10:46:51 +0200391 /*
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);
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700403 } else if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)
404 txq_id = IWL_AUX_QUEUE;
405 else
Johannes Berge72f3682010-08-23 10:46:51 +0200406 txq_id = ctx->ac_to_queue[skb_get_queue_mapping(skb)];
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700407
Emmanuel Grumbach10b15e62011-08-25 23:10:43 -0700408 /* irqs already disabled/saved above when locking priv->shrd->lock */
Emmanuel Grumbachf39c95e2011-08-25 23:10:47 -0700409 spin_lock(&priv->shrd->sta_lock);
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700410
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700411 if (ieee80211_is_data_qos(fc)) {
Emmanuel Grumbach47c1b492011-07-03 11:22:15 +0300412 u8 *qc = NULL;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700413 struct iwl_tid_data *tid_data;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700414 qc = ieee80211_get_qos_ctl(hdr);
415 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700416 tid_data = &priv->shrd->tid_data[sta_id][tid];
Johannes Berg2c46f722011-04-28 07:27:10 -0700417
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700418 if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
Johannes Berg2c46f722011-04-28 07:27:10 -0700419 goto drop_unlock_sta;
420
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700421 seq_number = tid_data->seq_number;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700422 seq_number &= IEEE80211_SCTL_SEQ;
423 hdr->seq_ctrl = hdr->seq_ctrl &
424 cpu_to_le16(IEEE80211_SCTL_FRAG);
425 hdr->seq_ctrl |= cpu_to_le16(seq_number);
426 seq_number += 0x10;
427 /* aggregation is on for this <sta,tid> */
428 if (info->flags & IEEE80211_TX_CTL_AMPDU &&
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700429 tid_data->agg.state == IWL_AGG_ON) {
430 txq_id = tid_data->agg.txq_id;
Johannes Berg2e340342010-11-16 11:51:38 -0800431 is_agg = true;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700432 }
433 }
434
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -0700435 tx_cmd = iwl_trans_get_tx_cmd(trans(priv), txq_id);
Emmanuel Grumbach47c1b492011-07-03 11:22:15 +0300436 if (unlikely(!tx_cmd))
Johannes Berg2c46f722011-04-28 07:27:10 -0700437 goto drop_unlock_sta;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700438
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700439 /* Copy MAC header from skb into command buffer */
440 memcpy(tx_cmd->hdr, hdr, hdr_len);
441
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700442 /* Total # bytes to be transmitted */
443 len = (u16)skb->len;
444 tx_cmd->len = cpu_to_le16(len);
445
446 if (info->control.hw_key)
447 iwlagn_tx_cmd_build_hwcrypto(priv, info, tx_cmd, skb, sta_id);
448
449 /* TODO need this for burst mode later on */
Johannes Bergd44ae692010-08-23 07:56:56 -0700450 iwlagn_tx_cmd_build_basic(priv, skb, tx_cmd, info, hdr, sta_id);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700451 iwl_dbg_log_tx_data_frame(priv, len, hdr);
452
453 iwlagn_tx_cmd_build_rate(priv, tx_cmd, info, fc);
454
455 iwl_update_stats(priv, true, fc, len);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700456
Emmanuel Grumbach2c452292011-08-25 23:11:21 -0700457 info->driver_data[0] = ctx;
458
459 if (iwl_trans_tx(trans(priv), skb, tx_cmd, txq_id, fc, is_agg))
Johannes Berg2c46f722011-04-28 07:27:10 -0700460 goto drop_unlock_sta;
Johannes Berg2c46f722011-04-28 07:27:10 -0700461
462 if (ieee80211_is_data_qos(fc)) {
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700463 priv->shrd->tid_data[sta_id][tid].tfds_in_queue++;
Johannes Berg2c46f722011-04-28 07:27:10 -0700464 if (!ieee80211_has_morefrags(fc))
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700465 priv->shrd->tid_data[sta_id][tid].seq_number =
466 seq_number;
Johannes Berg2c46f722011-04-28 07:27:10 -0700467 }
468
Emmanuel Grumbachf39c95e2011-08-25 23:10:47 -0700469 spin_unlock(&priv->shrd->sta_lock);
Emmanuel Grumbach10b15e62011-08-25 23:10:43 -0700470 spin_unlock_irqrestore(&priv->shrd->lock, flags);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700471
472 /*
Johannes Berg2e340342010-11-16 11:51:38 -0800473 * Avoid atomic ops if it isn't an associated client.
474 * Also, if this is a packet for aggregation, don't
475 * increase the counter because the ucode will stop
476 * aggregation queues when their respective station
477 * goes to sleep.
478 */
479 if (sta_priv && sta_priv->client && !is_agg)
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700480 atomic_inc(&sta_priv->pending_frames);
481
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700482 return 0;
483
Johannes Berg2c46f722011-04-28 07:27:10 -0700484drop_unlock_sta:
Emmanuel Grumbachf39c95e2011-08-25 23:10:47 -0700485 spin_unlock(&priv->shrd->sta_lock);
Johannes Berg2c46f722011-04-28 07:27:10 -0700486drop_unlock_priv:
Emmanuel Grumbach10b15e62011-08-25 23:10:43 -0700487 spin_unlock_irqrestore(&priv->shrd->lock, flags);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700488 return -1;
489}
490
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700491/*
492 * Find first available (lowest unused) Tx Queue, mark it "active".
493 * Called only when finding queue for aggregation.
494 * Should never return anything < 7, because they should already
495 * be in use as EDCA AC (0-3), Command (4), reserved (5, 6)
496 */
497static int iwlagn_txq_ctx_activate_free(struct iwl_priv *priv)
498{
499 int txq_id;
500
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700501 for (txq_id = 0; txq_id < hw_params(priv).max_txq_num; txq_id++)
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700502 if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk))
503 return txq_id;
504 return -1;
505}
506
Johannes Berg832f47e2010-04-29 04:43:07 -0700507int iwlagn_tx_agg_start(struct iwl_priv *priv, struct ieee80211_vif *vif,
Johannes Berg619753f2010-04-30 11:30:46 -0700508 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700509{
510 int sta_id;
511 int tx_fifo;
512 int txq_id;
513 int ret;
514 unsigned long flags;
515 struct iwl_tid_data *tid_data;
516
Johannes Berge72f3682010-08-23 10:46:51 +0200517 tx_fifo = get_fifo_from_tid(iwl_rxon_ctx_from_vif(vif), tid);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700518 if (unlikely(tx_fifo < 0))
519 return tx_fifo;
520
Wey-Yi Guy5bc98902011-05-27 08:40:32 -0700521 IWL_DEBUG_HT(priv, "TX AGG request on ra = %pM tid = %d\n",
522 sta->addr, tid);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700523
Johannes Berg619753f2010-04-30 11:30:46 -0700524 sta_id = iwl_sta_id(sta);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700525 if (sta_id == IWL_INVALID_STATION) {
526 IWL_ERR(priv, "Start AGG on invalid station\n");
527 return -ENXIO;
528 }
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700529 if (unlikely(tid >= IWL_MAX_TID_COUNT))
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700530 return -EINVAL;
531
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700532 if (priv->shrd->tid_data[sta_id][tid].agg.state != IWL_AGG_OFF) {
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700533 IWL_ERR(priv, "Start AGG when state is not IWL_AGG_OFF !\n");
534 return -ENXIO;
535 }
536
537 txq_id = iwlagn_txq_ctx_activate_free(priv);
538 if (txq_id == -1) {
539 IWL_ERR(priv, "No free aggregation queue available\n");
540 return -ENXIO;
541 }
542
Emmanuel Grumbachf39c95e2011-08-25 23:10:47 -0700543 spin_lock_irqsave(&priv->shrd->sta_lock, flags);
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700544 tid_data = &priv->shrd->tid_data[sta_id][tid];
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700545 *ssn = SEQ_TO_SN(tid_data->seq_number);
546 tid_data->agg.txq_id = txq_id;
Johannes Bergc8823ec2011-03-15 11:33:03 -0700547 tid_data->agg.tx_fifo = tx_fifo;
Johannes Bergea9b3072010-11-10 18:25:45 -0800548 iwl_set_swq_id(&priv->txq[txq_id], get_ac_from_tid(tid), txq_id);
Emmanuel Grumbachf39c95e2011-08-25 23:10:47 -0700549 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700550
Johannes Bergc8823ec2011-03-15 11:33:03 -0700551 ret = iwlagn_txq_agg_enable(priv, txq_id, sta_id, tid);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700552 if (ret)
553 return ret;
554
Emmanuel Grumbachf39c95e2011-08-25 23:10:47 -0700555 spin_lock_irqsave(&priv->shrd->sta_lock, flags);
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700556 tid_data = &priv->shrd->tid_data[sta_id][tid];
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700557 if (tid_data->tfds_in_queue == 0) {
558 IWL_DEBUG_HT(priv, "HW queue is empty\n");
559 tid_data->agg.state = IWL_AGG_ON;
Johannes Berg619753f2010-04-30 11:30:46 -0700560 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700561 } else {
562 IWL_DEBUG_HT(priv, "HW queue is NOT empty: %d packets in HW queue\n",
563 tid_data->tfds_in_queue);
564 tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA;
565 }
Emmanuel Grumbachf39c95e2011-08-25 23:10:47 -0700566 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700567 return ret;
568}
569
Johannes Berg832f47e2010-04-29 04:43:07 -0700570int iwlagn_tx_agg_stop(struct iwl_priv *priv, struct ieee80211_vif *vif,
Johannes Berg619753f2010-04-30 11:30:46 -0700571 struct ieee80211_sta *sta, u16 tid)
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700572{
Johannes Berg18c121d2010-08-23 07:57:17 -0700573 int tx_fifo_id, txq_id, sta_id, ssn;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700574 struct iwl_tid_data *tid_data;
575 int write_ptr, read_ptr;
576 unsigned long flags;
577
Johannes Berge72f3682010-08-23 10:46:51 +0200578 tx_fifo_id = get_fifo_from_tid(iwl_rxon_ctx_from_vif(vif), tid);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700579 if (unlikely(tx_fifo_id < 0))
580 return tx_fifo_id;
581
Johannes Berg619753f2010-04-30 11:30:46 -0700582 sta_id = iwl_sta_id(sta);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700583
584 if (sta_id == IWL_INVALID_STATION) {
585 IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
586 return -ENXIO;
587 }
588
Emmanuel Grumbachf39c95e2011-08-25 23:10:47 -0700589 spin_lock_irqsave(&priv->shrd->sta_lock, flags);
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700590
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700591 tid_data = &priv->shrd->tid_data[sta_id][tid];
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700592 ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
593 txq_id = tid_data->agg.txq_id;
Johannes Berg18c121d2010-08-23 07:57:17 -0700594
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700595 switch (priv->shrd->tid_data[sta_id][tid].agg.state) {
Johannes Berg18c121d2010-08-23 07:57:17 -0700596 case IWL_EMPTYING_HW_QUEUE_ADDBA:
597 /*
598 * This can happen if the peer stops aggregation
599 * again before we've had a chance to drain the
600 * queue we selected previously, i.e. before the
601 * session was really started completely.
602 */
603 IWL_DEBUG_HT(priv, "AGG stop before setup done\n");
604 goto turn_off;
605 case IWL_AGG_ON:
606 break;
607 default:
608 IWL_WARN(priv, "Stopping AGG while state not ON or starting\n");
609 }
610
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700611 write_ptr = priv->txq[txq_id].q.write_ptr;
612 read_ptr = priv->txq[txq_id].q.read_ptr;
613
614 /* The queue is not empty */
615 if (write_ptr != read_ptr) {
616 IWL_DEBUG_HT(priv, "Stopping a non empty AGG HW QUEUE\n");
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700617 priv->shrd->tid_data[sta_id][tid].agg.state =
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700618 IWL_EMPTYING_HW_QUEUE_DELBA;
Emmanuel Grumbachf39c95e2011-08-25 23:10:47 -0700619 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700620 return 0;
621 }
622
623 IWL_DEBUG_HT(priv, "HW queue is empty\n");
Johannes Berg18c121d2010-08-23 07:57:17 -0700624 turn_off:
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700625 priv->shrd->tid_data[sta_id][tid].agg.state = IWL_AGG_OFF;
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700626
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700627 /* do not restore/save irqs */
Emmanuel Grumbachf39c95e2011-08-25 23:10:47 -0700628 spin_unlock(&priv->shrd->sta_lock);
Emmanuel Grumbach10b15e62011-08-25 23:10:43 -0700629 spin_lock(&priv->shrd->lock);
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700630
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700631 /*
632 * the only reason this call can fail is queue number out of range,
633 * which can happen if uCode is reloaded and all the station
634 * information are lost. if it is outside the range, there is no need
635 * to deactivate the uCode queue, just return "success" to allow
636 * mac80211 to clean up it own data.
637 */
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -0700638 iwl_trans_txq_agg_disable(trans(priv), txq_id, ssn, tx_fifo_id);
Emmanuel Grumbach10b15e62011-08-25 23:10:43 -0700639 spin_unlock_irqrestore(&priv->shrd->lock, flags);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700640
Johannes Berg619753f2010-04-30 11:30:46 -0700641 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700642
643 return 0;
644}
645
Emmanuel Grumbach04e1cab2011-08-25 23:11:01 -0700646static int iwlagn_txq_check_empty(struct iwl_priv *priv,
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700647 int sta_id, u8 tid, int txq_id)
648{
649 struct iwl_queue *q = &priv->txq[txq_id].q;
650 u8 *addr = priv->stations[sta_id].sta.sta.addr;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700651 struct iwl_tid_data *tid_data = &priv->shrd->tid_data[sta_id][tid];
Johannes Berg8bd413e2010-08-23 10:46:40 +0200652 struct iwl_rxon_context *ctx;
653
654 ctx = &priv->contexts[priv->stations[sta_id].ctxid];
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700655
Emmanuel Grumbachf39c95e2011-08-25 23:10:47 -0700656 lockdep_assert_held(&priv->shrd->sta_lock);
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700657
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700658 switch (priv->shrd->tid_data[sta_id][tid].agg.state) {
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700659 case IWL_EMPTYING_HW_QUEUE_DELBA:
660 /* We are reclaiming the last packet of the */
661 /* aggregated HW queue */
662 if ((txq_id == tid_data->agg.txq_id) &&
663 (q->read_ptr == q->write_ptr)) {
664 u16 ssn = SEQ_TO_SN(tid_data->seq_number);
Johannes Berge72f3682010-08-23 10:46:51 +0200665 int tx_fifo = get_fifo_from_tid(ctx, tid);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700666 IWL_DEBUG_HT(priv, "HW queue empty: continue DELBA flow\n");
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -0700667 iwl_trans_txq_agg_disable(trans(priv), txq_id,
Emmanuel Grumbach41c50542011-07-11 08:51:04 +0300668 ssn, tx_fifo);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700669 tid_data->agg.state = IWL_AGG_OFF;
Johannes Berg8bd413e2010-08-23 10:46:40 +0200670 ieee80211_stop_tx_ba_cb_irqsafe(ctx->vif, addr, tid);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700671 }
672 break;
673 case IWL_EMPTYING_HW_QUEUE_ADDBA:
674 /* We are reclaiming the last packet of the queue */
675 if (tid_data->tfds_in_queue == 0) {
676 IWL_DEBUG_HT(priv, "HW queue empty: continue ADDBA flow\n");
677 tid_data->agg.state = IWL_AGG_ON;
Johannes Berg8bd413e2010-08-23 10:46:40 +0200678 ieee80211_start_tx_ba_cb_irqsafe(ctx->vif, addr, tid);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700679 }
680 break;
681 }
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700682
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700683 return 0;
684}
685
Johannes Berg2e340342010-11-16 11:51:38 -0800686static void iwlagn_non_agg_tx_status(struct iwl_priv *priv,
687 struct iwl_rxon_context *ctx,
688 const u8 *addr1)
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700689{
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700690 struct ieee80211_sta *sta;
691 struct iwl_station_priv *sta_priv;
692
Johannes Berg6db63402010-06-07 21:20:38 +0200693 rcu_read_lock();
Johannes Berg2e340342010-11-16 11:51:38 -0800694 sta = ieee80211_find_sta(ctx->vif, addr1);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700695 if (sta) {
696 sta_priv = (void *)sta->drv_priv;
697 /* avoid atomic ops if this isn't a client */
698 if (sta_priv->client &&
699 atomic_dec_return(&sta_priv->pending_frames) == 0)
700 ieee80211_sta_block_awake(priv->hw, sta, false);
701 }
Johannes Berg6db63402010-06-07 21:20:38 +0200702 rcu_read_unlock();
Johannes Berg2e340342010-11-16 11:51:38 -0800703}
704
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700705/**
Wey-Yi Guy8d801082010-03-17 13:34:36 -0700706 * translate ucode response to mac80211 tx status control values
707 */
Emmanuel Grumbach04e1cab2011-08-25 23:11:01 -0700708static void iwlagn_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
Wey-Yi Guy8d801082010-03-17 13:34:36 -0700709 struct ieee80211_tx_info *info)
710{
711 struct ieee80211_tx_rate *r = &info->control.rates[0];
712
713 info->antenna_sel_tx =
714 ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
715 if (rate_n_flags & RATE_MCS_HT_MSK)
716 r->flags |= IEEE80211_TX_RC_MCS;
717 if (rate_n_flags & RATE_MCS_GF_MSK)
718 r->flags |= IEEE80211_TX_RC_GREEN_FIELD;
719 if (rate_n_flags & RATE_MCS_HT40_MSK)
720 r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
721 if (rate_n_flags & RATE_MCS_DUP_MSK)
722 r->flags |= IEEE80211_TX_RC_DUP_DATA;
723 if (rate_n_flags & RATE_MCS_SGI_MSK)
724 r->flags |= IEEE80211_TX_RC_SHORT_GI;
725 r->idx = iwlagn_hwrate_to_mac80211_idx(rate_n_flags, info->band);
726}
727
Johannes Berg69fdb712010-09-22 18:02:02 +0200728#ifdef CONFIG_IWLWIFI_DEBUG
729const char *iwl_get_tx_fail_reason(u32 status)
730{
731#define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x
732#define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x
733
734 switch (status & TX_STATUS_MSK) {
735 case TX_STATUS_SUCCESS:
736 return "SUCCESS";
737 TX_STATUS_POSTPONE(DELAY);
738 TX_STATUS_POSTPONE(FEW_BYTES);
739 TX_STATUS_POSTPONE(BT_PRIO);
740 TX_STATUS_POSTPONE(QUIET_PERIOD);
741 TX_STATUS_POSTPONE(CALC_TTAK);
742 TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY);
743 TX_STATUS_FAIL(SHORT_LIMIT);
744 TX_STATUS_FAIL(LONG_LIMIT);
745 TX_STATUS_FAIL(FIFO_UNDERRUN);
746 TX_STATUS_FAIL(DRAIN_FLOW);
747 TX_STATUS_FAIL(RFKILL_FLUSH);
748 TX_STATUS_FAIL(LIFE_EXPIRE);
749 TX_STATUS_FAIL(DEST_PS);
750 TX_STATUS_FAIL(HOST_ABORTED);
751 TX_STATUS_FAIL(BT_RETRY);
752 TX_STATUS_FAIL(STA_INVALID);
753 TX_STATUS_FAIL(FRAG_DROPPED);
754 TX_STATUS_FAIL(TID_DISABLE);
755 TX_STATUS_FAIL(FIFO_FLUSHED);
756 TX_STATUS_FAIL(INSUFFICIENT_CF_POLL);
757 TX_STATUS_FAIL(PASSIVE_NO_RX);
758 TX_STATUS_FAIL(NO_BEACON_ON_RADAR);
759 }
760
761 return "UNKNOWN";
762
763#undef TX_STATUS_FAIL
764#undef TX_STATUS_POSTPONE
765}
766#endif /* CONFIG_IWLWIFI_DEBUG */
Emmanuel Grumbacha0eaad72011-08-25 23:11:00 -0700767
Emmanuel Grumbach04e1cab2011-08-25 23:11:01 -0700768static void iwlagn_count_agg_tx_err_status(struct iwl_priv *priv, u16 status)
769{
770 status &= AGG_TX_STATUS_MSK;
771
772 switch (status) {
773 case AGG_TX_STATE_UNDERRUN_MSK:
774 priv->reply_agg_tx_stats.underrun++;
775 break;
776 case AGG_TX_STATE_BT_PRIO_MSK:
777 priv->reply_agg_tx_stats.bt_prio++;
778 break;
779 case AGG_TX_STATE_FEW_BYTES_MSK:
780 priv->reply_agg_tx_stats.few_bytes++;
781 break;
782 case AGG_TX_STATE_ABORT_MSK:
783 priv->reply_agg_tx_stats.abort++;
784 break;
785 case AGG_TX_STATE_LAST_SENT_TTL_MSK:
786 priv->reply_agg_tx_stats.last_sent_ttl++;
787 break;
788 case AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK:
789 priv->reply_agg_tx_stats.last_sent_try++;
790 break;
791 case AGG_TX_STATE_LAST_SENT_BT_KILL_MSK:
792 priv->reply_agg_tx_stats.last_sent_bt_kill++;
793 break;
794 case AGG_TX_STATE_SCD_QUERY_MSK:
795 priv->reply_agg_tx_stats.scd_query++;
796 break;
797 case AGG_TX_STATE_TEST_BAD_CRC32_MSK:
798 priv->reply_agg_tx_stats.bad_crc32++;
799 break;
800 case AGG_TX_STATE_RESPONSE_MSK:
801 priv->reply_agg_tx_stats.response++;
802 break;
803 case AGG_TX_STATE_DUMP_TX_MSK:
804 priv->reply_agg_tx_stats.dump_tx++;
805 break;
806 case AGG_TX_STATE_DELAY_TX_MSK:
807 priv->reply_agg_tx_stats.delay_tx++;
808 break;
809 default:
810 priv->reply_agg_tx_stats.unknown++;
811 break;
812 }
813}
814
Emmanuel Grumbacha0eaad72011-08-25 23:11:00 -0700815static void iwl_rx_reply_tx_agg(struct iwl_priv *priv,
816 struct iwlagn_tx_resp *tx_resp)
817{
818 struct agg_tx_status *frame_status = &tx_resp->status;
819 int tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >>
820 IWLAGN_TX_RES_TID_POS;
821 int sta_id = (tx_resp->ra_tid & IWLAGN_TX_RES_RA_MSK) >>
822 IWLAGN_TX_RES_RA_POS;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700823 struct iwl_ht_agg *agg = &priv->shrd->tid_data[sta_id][tid].agg;
Emmanuel Grumbacha0eaad72011-08-25 23:11:00 -0700824 u32 status = le16_to_cpu(tx_resp->status.status);
825 int i;
826
827 if (agg->wait_for_ba)
828 IWL_DEBUG_TX_REPLY(priv,
829 "got tx response w/o block-ack\n");
830
831 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
832 agg->wait_for_ba = (tx_resp->frame_count > 1);
833
834 /*
835 * If the BT kill count is non-zero, we'll get this
836 * notification again.
837 */
838 if (tx_resp->bt_kill_count && tx_resp->frame_count == 1 &&
839 priv->cfg->bt_params &&
840 priv->cfg->bt_params->advanced_bt_coexist) {
841 IWL_DEBUG_COEX(priv, "receive reply tx w/ bt_kill\n");
842 }
843
844 /* Construct bit-map of pending frames within Tx window */
845 for (i = 0; i < tx_resp->frame_count; i++) {
846 u16 fstatus = le16_to_cpu(frame_status[i].status);
847
848 if (status & AGG_TX_STATUS_MSK)
849 iwlagn_count_agg_tx_err_status(priv, fstatus);
850
851 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
852 AGG_TX_STATE_ABORT_MSK))
853 continue;
854
855 IWL_DEBUG_TX_REPLY(priv, "status %s (0x%08x), "
856 "try-count (0x%08x)\n",
857 iwl_get_agg_tx_fail_reason(fstatus),
858 fstatus & AGG_TX_STATUS_MSK,
859 fstatus & AGG_TX_TRY_MSK);
860 }
861}
862
Emmanuel Grumbach04e1cab2011-08-25 23:11:01 -0700863#ifdef CONFIG_IWLWIFI_DEBUG
864#define AGG_TX_STATE_FAIL(x) case AGG_TX_STATE_ ## x: return #x
865
866const char *iwl_get_agg_tx_fail_reason(u16 status)
867{
868 status &= AGG_TX_STATUS_MSK;
869 switch (status) {
870 case AGG_TX_STATE_TRANSMITTED:
871 return "SUCCESS";
872 AGG_TX_STATE_FAIL(UNDERRUN_MSK);
873 AGG_TX_STATE_FAIL(BT_PRIO_MSK);
874 AGG_TX_STATE_FAIL(FEW_BYTES_MSK);
875 AGG_TX_STATE_FAIL(ABORT_MSK);
876 AGG_TX_STATE_FAIL(LAST_SENT_TTL_MSK);
877 AGG_TX_STATE_FAIL(LAST_SENT_TRY_CNT_MSK);
878 AGG_TX_STATE_FAIL(LAST_SENT_BT_KILL_MSK);
879 AGG_TX_STATE_FAIL(SCD_QUERY_MSK);
880 AGG_TX_STATE_FAIL(TEST_BAD_CRC32_MSK);
881 AGG_TX_STATE_FAIL(RESPONSE_MSK);
882 AGG_TX_STATE_FAIL(DUMP_TX_MSK);
883 AGG_TX_STATE_FAIL(DELAY_TX_MSK);
884 }
885
886 return "UNKNOWN";
887}
888#endif /* CONFIG_IWLWIFI_DEBUG */
889
Emmanuel Grumbacha0eaad72011-08-25 23:11:00 -0700890static inline u32 iwlagn_get_scd_ssn(struct iwlagn_tx_resp *tx_resp)
891{
892 return le32_to_cpup((__le32 *)&tx_resp->status +
893 tx_resp->frame_count) & MAX_SN;
894}
895
Emmanuel Grumbach04e1cab2011-08-25 23:11:01 -0700896static void iwl_free_tfds_in_queue(struct iwl_priv *priv,
897 int sta_id, int tid, int freed)
898{
899 lockdep_assert_held(&priv->shrd->sta_lock);
900
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700901 if (priv->shrd->tid_data[sta_id][tid].tfds_in_queue >= freed)
902 priv->shrd->tid_data[sta_id][tid].tfds_in_queue -= freed;
Emmanuel Grumbach04e1cab2011-08-25 23:11:01 -0700903 else {
904 IWL_DEBUG_TX(priv, "free more than tfds_in_queue (%u:%d)\n",
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700905 priv->shrd->tid_data[sta_id][tid].tfds_in_queue,
Emmanuel Grumbach04e1cab2011-08-25 23:11:01 -0700906 freed);
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700907 priv->shrd->tid_data[sta_id][tid].tfds_in_queue = 0;
Emmanuel Grumbach04e1cab2011-08-25 23:11:01 -0700908 }
909}
910
911static void iwlagn_count_tx_err_status(struct iwl_priv *priv, u16 status)
912{
913 status &= TX_STATUS_MSK;
914
915 switch (status) {
916 case TX_STATUS_POSTPONE_DELAY:
917 priv->reply_tx_stats.pp_delay++;
918 break;
919 case TX_STATUS_POSTPONE_FEW_BYTES:
920 priv->reply_tx_stats.pp_few_bytes++;
921 break;
922 case TX_STATUS_POSTPONE_BT_PRIO:
923 priv->reply_tx_stats.pp_bt_prio++;
924 break;
925 case TX_STATUS_POSTPONE_QUIET_PERIOD:
926 priv->reply_tx_stats.pp_quiet_period++;
927 break;
928 case TX_STATUS_POSTPONE_CALC_TTAK:
929 priv->reply_tx_stats.pp_calc_ttak++;
930 break;
931 case TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY:
932 priv->reply_tx_stats.int_crossed_retry++;
933 break;
934 case TX_STATUS_FAIL_SHORT_LIMIT:
935 priv->reply_tx_stats.short_limit++;
936 break;
937 case TX_STATUS_FAIL_LONG_LIMIT:
938 priv->reply_tx_stats.long_limit++;
939 break;
940 case TX_STATUS_FAIL_FIFO_UNDERRUN:
941 priv->reply_tx_stats.fifo_underrun++;
942 break;
943 case TX_STATUS_FAIL_DRAIN_FLOW:
944 priv->reply_tx_stats.drain_flow++;
945 break;
946 case TX_STATUS_FAIL_RFKILL_FLUSH:
947 priv->reply_tx_stats.rfkill_flush++;
948 break;
949 case TX_STATUS_FAIL_LIFE_EXPIRE:
950 priv->reply_tx_stats.life_expire++;
951 break;
952 case TX_STATUS_FAIL_DEST_PS:
953 priv->reply_tx_stats.dest_ps++;
954 break;
955 case TX_STATUS_FAIL_HOST_ABORTED:
956 priv->reply_tx_stats.host_abort++;
957 break;
958 case TX_STATUS_FAIL_BT_RETRY:
959 priv->reply_tx_stats.bt_retry++;
960 break;
961 case TX_STATUS_FAIL_STA_INVALID:
962 priv->reply_tx_stats.sta_invalid++;
963 break;
964 case TX_STATUS_FAIL_FRAG_DROPPED:
965 priv->reply_tx_stats.frag_drop++;
966 break;
967 case TX_STATUS_FAIL_TID_DISABLE:
968 priv->reply_tx_stats.tid_disable++;
969 break;
970 case TX_STATUS_FAIL_FIFO_FLUSHED:
971 priv->reply_tx_stats.fifo_flush++;
972 break;
973 case TX_STATUS_FAIL_INSUFFICIENT_CF_POLL:
974 priv->reply_tx_stats.insuff_cf_poll++;
975 break;
976 case TX_STATUS_FAIL_PASSIVE_NO_RX:
977 priv->reply_tx_stats.fail_hw_drop++;
978 break;
979 case TX_STATUS_FAIL_NO_BEACON_ON_RADAR:
980 priv->reply_tx_stats.sta_color_mismatch++;
981 break;
982 default:
983 priv->reply_tx_stats.unknown++;
984 break;
985 }
986}
987
988static void iwlagn_set_tx_status(struct iwl_priv *priv,
989 struct ieee80211_tx_info *info,
990 struct iwlagn_tx_resp *tx_resp,
991 bool is_agg)
992{
993 u16 status = le16_to_cpu(tx_resp->status.status);
994
995 info->status.rates[0].count = tx_resp->failure_frame + 1;
996 if (is_agg)
997 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
998 info->flags |= iwl_tx_status_to_mac80211(status);
999 iwlagn_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
1000 info);
1001 if (!iwl_is_tx_success(status))
1002 iwlagn_count_tx_err_status(priv, status);
1003}
1004
1005static void iwl_check_abort_status(struct iwl_priv *priv,
1006 u8 frame_count, u32 status)
1007{
1008 if (frame_count == 1 && status == TX_STATUS_FAIL_RFKILL_FLUSH) {
1009 IWL_ERR(priv, "Tx flush command to flush out all frames\n");
1010 if (!test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
1011 queue_work(priv->shrd->workqueue, &priv->tx_flush);
1012 }
1013}
1014
Emmanuel Grumbacha0eaad72011-08-25 23:11:00 -07001015void iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1016{
1017 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1018 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1019 int txq_id = SEQ_TO_QUEUE(sequence);
1020 int cmd_index = SEQ_TO_INDEX(sequence);
1021 struct iwl_tx_queue *txq = &priv->txq[txq_id];
1022 struct iwlagn_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
1023 struct ieee80211_hdr *hdr;
1024 u32 status = le16_to_cpu(tx_resp->status.status);
1025 u32 ssn = iwlagn_get_scd_ssn(tx_resp);
1026 int tid;
1027 int sta_id;
1028 int freed;
1029 struct ieee80211_tx_info *info;
1030 unsigned long flags;
1031 struct sk_buff_head skbs;
1032 struct sk_buff *skb;
1033 struct iwl_rxon_context *ctx;
1034
1035 if ((cmd_index >= txq->q.n_bd) ||
1036 (iwl_queue_used(&txq->q, cmd_index) == 0)) {
1037 IWL_ERR(priv, "%s: Read index for DMA queue txq_id (%d) "
1038 "cmd_index %d is out of range [0-%d] %d %d\n",
1039 __func__, txq_id, cmd_index, txq->q.n_bd,
1040 txq->q.write_ptr, txq->q.read_ptr);
1041 return;
1042 }
1043
1044 txq->time_stamp = jiffies;
1045
1046 tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >>
1047 IWLAGN_TX_RES_TID_POS;
1048 sta_id = (tx_resp->ra_tid & IWLAGN_TX_RES_RA_MSK) >>
1049 IWLAGN_TX_RES_RA_POS;
1050
1051 spin_lock_irqsave(&priv->shrd->sta_lock, flags);
1052
1053 if (txq->sched_retry)
1054 iwl_rx_reply_tx_agg(priv, tx_resp);
1055
1056 if (tx_resp->frame_count == 1) {
1057 bool is_agg = (txq_id >= IWLAGN_FIRST_AMPDU_QUEUE);
1058
1059 __skb_queue_head_init(&skbs);
1060 /*we can free until ssn % q.n_bd not inclusive */
1061 iwl_trans_reclaim(trans(priv), txq_id, ssn, status, &skbs);
1062 freed = 0;
1063 while (!skb_queue_empty(&skbs)) {
1064 skb = __skb_dequeue(&skbs);
1065 hdr = (struct ieee80211_hdr *)skb->data;
1066
1067 if (!ieee80211_is_data_qos(hdr->frame_control))
1068 priv->last_seq_ctl = tx_resp->seq_ctl;
1069
1070 info = IEEE80211_SKB_CB(skb);
1071 ctx = info->driver_data[0];
1072
1073 memset(&info->status, 0, sizeof(info->status));
1074
1075 if (status == TX_STATUS_FAIL_PASSIVE_NO_RX &&
1076 iwl_is_associated_ctx(ctx) && ctx->vif &&
1077 ctx->vif->type == NL80211_IFTYPE_STATION) {
1078 ctx->last_tx_rejected = true;
1079 iwl_stop_queue(priv, &priv->txq[txq_id]);
1080
1081 IWL_DEBUG_TX_REPLY(priv,
1082 "TXQ %d status %s (0x%08x) "
1083 "rate_n_flags 0x%x retries %d\n",
1084 txq_id,
1085 iwl_get_tx_fail_reason(status),
1086 status,
1087 le32_to_cpu(tx_resp->rate_n_flags),
1088 tx_resp->failure_frame);
1089
1090 IWL_DEBUG_TX_REPLY(priv,
1091 "FrameCnt = %d, idx=%d\n",
1092 tx_resp->frame_count, cmd_index);
1093 }
1094
1095 /* check if BAR is needed */
1096 if (is_agg && !iwl_is_tx_success(status))
1097 info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
1098 iwlagn_set_tx_status(priv, IEEE80211_SKB_CB(skb),
1099 tx_resp, is_agg);
1100 if (!is_agg)
1101 iwlagn_non_agg_tx_status(priv, ctx, hdr->addr1);
1102
1103 ieee80211_tx_status_irqsafe(priv->hw, skb);
1104
1105 freed++;
1106 }
1107
1108 WARN_ON(!is_agg && freed != 1);
1109
1110 iwl_free_tfds_in_queue(priv, sta_id, tid, freed);
1111 iwlagn_txq_check_empty(priv, sta_id, tid, txq_id);
1112 }
1113
1114 iwl_check_abort_status(priv, tx_resp->frame_count, status);
1115 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
1116}
1117
1118/**
1119 * iwlagn_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
1120 *
1121 * Handles block-acknowledge notification from device, which reports success
1122 * of frames sent via aggregation.
1123 */
1124void iwlagn_rx_reply_compressed_ba(struct iwl_priv *priv,
1125 struct iwl_rx_mem_buffer *rxb)
1126{
1127 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1128 struct iwl_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
1129 struct iwl_tx_queue *txq = NULL;
1130 struct iwl_ht_agg *agg;
1131 struct sk_buff_head reclaimed_skbs;
1132 struct ieee80211_tx_info *info;
1133 struct ieee80211_hdr *hdr;
1134 struct sk_buff *skb;
1135 unsigned long flags;
1136 int index;
1137 int sta_id;
1138 int tid;
1139 int freed;
1140
1141 /* "flow" corresponds to Tx queue */
1142 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
1143
1144 /* "ssn" is start of block-ack Tx window, corresponds to index
1145 * (in Tx queue's circular buffer) of first TFD/frame in window */
1146 u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
1147
1148 if (scd_flow >= hw_params(priv).max_txq_num) {
1149 IWL_ERR(priv,
1150 "BUG_ON scd_flow is bigger than number of queues\n");
1151 return;
1152 }
1153
1154 txq = &priv->txq[scd_flow];
1155 sta_id = ba_resp->sta_id;
1156 tid = ba_resp->tid;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -07001157 agg = &priv->shrd->tid_data[sta_id][tid].agg;
Emmanuel Grumbacha0eaad72011-08-25 23:11:00 -07001158
1159 /* Find index of block-ack window */
1160 index = ba_resp_scd_ssn & (txq->q.n_bd - 1);
1161
1162 spin_lock_irqsave(&priv->shrd->sta_lock, flags);
1163
1164 if (unlikely(agg->txq_id != scd_flow)) {
1165 /*
1166 * FIXME: this is a uCode bug which need to be addressed,
1167 * log the information and return for now!
1168 * since it is possible happen very often and in order
1169 * not to fill the syslog, don't enable the logging by default
1170 */
1171 IWL_DEBUG_TX_REPLY(priv,
1172 "BA scd_flow %d does not match txq_id %d\n",
1173 scd_flow, agg->txq_id);
1174 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
1175 return;
1176 }
1177
1178 if (unlikely(!agg->wait_for_ba)) {
1179 if (unlikely(ba_resp->bitmap))
1180 IWL_ERR(priv, "Received BA when not expected\n");
1181 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
1182 return;
1183 }
1184
1185 IWL_DEBUG_TX_REPLY(priv, "REPLY_COMPRESSED_BA [%d] Received from %pM, "
1186 "sta_id = %d\n",
1187 agg->wait_for_ba,
1188 (u8 *) &ba_resp->sta_addr_lo32,
1189 ba_resp->sta_id);
1190 IWL_DEBUG_TX_REPLY(priv, "TID = %d, SeqCtl = %d, bitmap = 0x%llx, "
1191 "scd_flow = %d, scd_ssn = %d\n",
1192 ba_resp->tid,
1193 ba_resp->seq_ctl,
1194 (unsigned long long)le64_to_cpu(ba_resp->bitmap),
1195 ba_resp->scd_flow,
1196 ba_resp->scd_ssn);
1197
1198 /* Mark that the expected block-ack response arrived */
1199 agg->wait_for_ba = 0;
1200
1201 /* Sanity check values reported by uCode */
1202 if (ba_resp->txed_2_done > ba_resp->txed) {
1203 IWL_DEBUG_TX_REPLY(priv,
1204 "bogus sent(%d) and ack(%d) count\n",
1205 ba_resp->txed, ba_resp->txed_2_done);
1206 /*
1207 * set txed_2_done = txed,
1208 * so it won't impact rate scale
1209 */
1210 ba_resp->txed = ba_resp->txed_2_done;
1211 }
1212 IWL_DEBUG_HT(priv, "agg frames sent:%d, acked:%d\n",
1213 ba_resp->txed, ba_resp->txed_2_done);
1214
1215 __skb_queue_head_init(&reclaimed_skbs);
1216
1217 /* Release all TFDs before the SSN, i.e. all TFDs in front of
1218 * block-ack window (we assume that they've been successfully
1219 * transmitted ... if not, it's too late anyway). */
1220 iwl_trans_reclaim(trans(priv), scd_flow, ba_resp_scd_ssn, 0,
1221 &reclaimed_skbs);
1222 freed = 0;
1223 while (!skb_queue_empty(&reclaimed_skbs)) {
1224
1225 skb = __skb_dequeue(&reclaimed_skbs);
1226 hdr = (struct ieee80211_hdr *)skb->data;
1227
1228 if (ieee80211_is_data_qos(hdr->frame_control))
1229 freed++;
1230 else
1231 WARN_ON_ONCE(1);
1232
1233 if (freed == 0) {
1234 /* this is the first skb we deliver in this batch */
1235 /* put the rate scaling data there */
1236 info = IEEE80211_SKB_CB(skb);
1237 memset(&info->status, 0, sizeof(info->status));
1238 info->flags |= IEEE80211_TX_STAT_ACK;
1239 info->flags |= IEEE80211_TX_STAT_AMPDU;
1240 info->status.ampdu_ack_len = ba_resp->txed_2_done;
1241 info->status.ampdu_len = ba_resp->txed;
1242 iwlagn_hwrate_to_tx_control(priv, agg->rate_n_flags,
1243 info);
1244 }
1245
1246 ieee80211_tx_status_irqsafe(priv->hw, skb);
1247 }
1248
1249 iwl_free_tfds_in_queue(priv, sta_id, tid, freed);
1250 iwlagn_txq_check_empty(priv, sta_id, tid, scd_flow);
1251
1252 spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
1253}