blob: 5cf83111e1a709f4ac7de40e39972c736e4df9af [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
2 * Copyright (c) 2008 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070017#include "core.h"
18
19#define BITS_PER_BYTE 8
20#define OFDM_PLCP_BITS 22
21#define HT_RC_2_MCS(_rc) ((_rc) & 0x0f)
22#define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1)
23#define L_STF 8
24#define L_LTF 8
25#define L_SIG 4
26#define HT_SIG 8
27#define HT_STF 4
28#define HT_LTF(_ns) (4 * (_ns))
29#define SYMBOL_TIME(_ns) ((_ns) << 2) /* ns * 4 us */
30#define SYMBOL_TIME_HALFGI(_ns) (((_ns) * 18 + 4) / 5) /* ns * 3.6 us */
31#define NUM_SYMBOLS_PER_USEC(_usec) (_usec >> 2)
32#define NUM_SYMBOLS_PER_USEC_HALFGI(_usec) (((_usec*5)-4)/18)
33
34#define OFDM_SIFS_TIME 16
35
36static u32 bits_per_symbol[][2] = {
37 /* 20MHz 40MHz */
38 { 26, 54 }, /* 0: BPSK */
39 { 52, 108 }, /* 1: QPSK 1/2 */
40 { 78, 162 }, /* 2: QPSK 3/4 */
41 { 104, 216 }, /* 3: 16-QAM 1/2 */
42 { 156, 324 }, /* 4: 16-QAM 3/4 */
43 { 208, 432 }, /* 5: 64-QAM 2/3 */
44 { 234, 486 }, /* 6: 64-QAM 3/4 */
45 { 260, 540 }, /* 7: 64-QAM 5/6 */
46 { 52, 108 }, /* 8: BPSK */
47 { 104, 216 }, /* 9: QPSK 1/2 */
48 { 156, 324 }, /* 10: QPSK 3/4 */
49 { 208, 432 }, /* 11: 16-QAM 1/2 */
50 { 312, 648 }, /* 12: 16-QAM 3/4 */
51 { 416, 864 }, /* 13: 64-QAM 2/3 */
52 { 468, 972 }, /* 14: 64-QAM 3/4 */
53 { 520, 1080 }, /* 15: 64-QAM 5/6 */
54};
55
56#define IS_HT_RATE(_rate) ((_rate) & 0x80)
57
58/*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070059 * Insert a chain of ath_buf (descriptors) on a txq and
60 * assume the descriptors are already chained together by caller.
61 * NB: must be called with txq lock held
62 */
63
Sujith102e0572008-10-29 10:15:16 +053064static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
65 struct list_head *head)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070066{
67 struct ath_hal *ah = sc->sc_ah;
68 struct ath_buf *bf;
Sujith102e0572008-10-29 10:15:16 +053069
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070070 /*
71 * Insert the frame on the outbound list and
72 * pass it on to the hardware.
73 */
74
75 if (list_empty(head))
76 return;
77
78 bf = list_first_entry(head, struct ath_buf, list);
79
80 list_splice_tail_init(head, &txq->axq_q);
81 txq->axq_depth++;
82 txq->axq_totalqueued++;
83 txq->axq_linkbuf = list_entry(txq->axq_q.prev, struct ath_buf, list);
84
85 DPRINTF(sc, ATH_DBG_QUEUE,
Sujith04bd4632008-11-28 22:18:05 +053086 "qnum: %d, txq depth: %d\n", txq->axq_qnum, txq->axq_depth);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070087
88 if (txq->axq_link == NULL) {
89 ath9k_hw_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr);
90 DPRINTF(sc, ATH_DBG_XMIT,
Sujith04bd4632008-11-28 22:18:05 +053091 "TXDP[%u] = %llx (%p)\n",
92 txq->axq_qnum, ito64(bf->bf_daddr), bf->bf_desc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070093 } else {
94 *txq->axq_link = bf->bf_daddr;
Sujith04bd4632008-11-28 22:18:05 +053095 DPRINTF(sc, ATH_DBG_XMIT, "link[%u] (%p)=%llx (%p)\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070096 txq->axq_qnum, txq->axq_link,
97 ito64(bf->bf_daddr), bf->bf_desc);
98 }
99 txq->axq_link = &(bf->bf_lastbf->bf_desc->ds_link);
100 ath9k_hw_txstart(ah, txq->axq_qnum);
101}
102
Sujithc4288392008-11-18 09:09:30 +0530103static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
104 struct ath_xmit_status *tx_status)
105{
106 struct ieee80211_hw *hw = sc->hw;
107 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
108 struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
109
Sujith04bd4632008-11-28 22:18:05 +0530110 DPRINTF(sc, ATH_DBG_XMIT, "TX complete: skb: %p\n", skb);
Sujithc4288392008-11-18 09:09:30 +0530111
112 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK ||
113 tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
114 kfree(tx_info_priv);
115 tx_info->rate_driver_data[0] = NULL;
116 }
117
118 if (tx_status->flags & ATH_TX_BAR) {
119 tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
120 tx_status->flags &= ~ATH_TX_BAR;
121 }
122
123 if (!(tx_status->flags & (ATH_TX_ERROR | ATH_TX_XRETRY))) {
124 /* Frame was ACKed */
125 tx_info->flags |= IEEE80211_TX_STAT_ACK;
126 }
127
128 tx_info->status.rates[0].count = tx_status->retries + 1;
129
130 ieee80211_tx_status(hw, skb);
131}
132
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700133/* Check if it's okay to send out aggregates */
134
Sujitha37c2c72008-10-29 10:15:40 +0530135static int ath_aggr_query(struct ath_softc *sc, struct ath_node *an, u8 tidno)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700136{
137 struct ath_atx_tid *tid;
138 tid = ATH_AN_2_TID(an, tidno);
139
Sujitha37c2c72008-10-29 10:15:40 +0530140 if (tid->state & AGGR_ADDBA_COMPLETE ||
141 tid->state & AGGR_ADDBA_PROGRESS)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700142 return 1;
143 else
144 return 0;
145}
146
Sujithff37e332008-11-24 12:07:55 +0530147static void ath_get_beaconconfig(struct ath_softc *sc, int if_id,
148 struct ath_beacon_config *conf)
149{
150 struct ieee80211_hw *hw = sc->hw;
151
152 /* fill in beacon config data */
153
154 conf->beacon_interval = hw->conf.beacon_int;
155 conf->listen_interval = 100;
156 conf->dtim_count = 1;
157 conf->bmiss_timeout = ATH_DEFAULT_BMISS_LIMIT * conf->listen_interval;
158}
159
Sujith528f0c62008-10-29 10:14:26 +0530160/* Calculate Atheros packet type from IEEE80211 packet header */
161
162static enum ath9k_pkt_type get_hw_packet_type(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700163{
Sujith528f0c62008-10-29 10:14:26 +0530164 struct ieee80211_hdr *hdr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700165 enum ath9k_pkt_type htype;
166 __le16 fc;
167
Sujith528f0c62008-10-29 10:14:26 +0530168 hdr = (struct ieee80211_hdr *)skb->data;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700169 fc = hdr->frame_control;
170
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700171 if (ieee80211_is_beacon(fc))
172 htype = ATH9K_PKT_TYPE_BEACON;
173 else if (ieee80211_is_probe_resp(fc))
174 htype = ATH9K_PKT_TYPE_PROBE_RESP;
175 else if (ieee80211_is_atim(fc))
176 htype = ATH9K_PKT_TYPE_ATIM;
177 else if (ieee80211_is_pspoll(fc))
178 htype = ATH9K_PKT_TYPE_PSPOLL;
179 else
180 htype = ATH9K_PKT_TYPE_NORMAL;
181
182 return htype;
183}
184
Sujitha8efee42008-11-18 09:07:30 +0530185static bool is_pae(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700186{
187 struct ieee80211_hdr *hdr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700188 __le16 fc;
189
190 hdr = (struct ieee80211_hdr *)skb->data;
191 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200192
Sujitha8efee42008-11-18 09:07:30 +0530193 if (ieee80211_is_data(fc)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700194 if (ieee80211_is_nullfunc(fc) ||
Sujith528f0c62008-10-29 10:14:26 +0530195 /* Port Access Entity (IEEE 802.1X) */
196 (skb->protocol == cpu_to_be16(ETH_P_PAE))) {
Sujitha8efee42008-11-18 09:07:30 +0530197 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700198 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700199 }
200
Sujitha8efee42008-11-18 09:07:30 +0530201 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700202}
203
Sujith528f0c62008-10-29 10:14:26 +0530204static int get_hw_crypto_keytype(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700205{
Sujith528f0c62008-10-29 10:14:26 +0530206 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
207
208 if (tx_info->control.hw_key) {
209 if (tx_info->control.hw_key->alg == ALG_WEP)
210 return ATH9K_KEY_TYPE_WEP;
211 else if (tx_info->control.hw_key->alg == ALG_TKIP)
212 return ATH9K_KEY_TYPE_TKIP;
213 else if (tx_info->control.hw_key->alg == ALG_CCMP)
214 return ATH9K_KEY_TYPE_AES;
215 }
216
217 return ATH9K_KEY_TYPE_CLEAR;
218}
219
Sujith528f0c62008-10-29 10:14:26 +0530220/* Called only when tx aggregation is enabled and HT is supported */
221
222static void assign_aggr_tid_seqno(struct sk_buff *skb,
223 struct ath_buf *bf)
224{
225 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
226 struct ieee80211_hdr *hdr;
227 struct ath_node *an;
228 struct ath_atx_tid *tid;
229 __le16 fc;
230 u8 *qc;
231
232 if (!tx_info->control.sta)
233 return;
234
235 an = (struct ath_node *)tx_info->control.sta->drv_priv;
236 hdr = (struct ieee80211_hdr *)skb->data;
237 fc = hdr->frame_control;
238
239 /* Get tidno */
240
241 if (ieee80211_is_data_qos(fc)) {
242 qc = ieee80211_get_qos_ctl(hdr);
243 bf->bf_tidno = qc[0] & 0xf;
Sujith98deeea2008-08-11 14:05:46 +0530244 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700245
Sujith528f0c62008-10-29 10:14:26 +0530246 /* Get seqno */
247
Sujitha8efee42008-11-18 09:07:30 +0530248 if (ieee80211_is_data(fc) && !is_pae(skb)) {
Sujith528f0c62008-10-29 10:14:26 +0530249 /* For HT capable stations, we save tidno for later use.
250 * We also override seqno set by upper layer with the one
251 * in tx aggregation state.
252 *
253 * If fragmentation is on, the sequence number is
254 * not overridden, since it has been
255 * incremented by the fragmentation routine.
256 *
257 * FIXME: check if the fragmentation threshold exceeds
258 * IEEE80211 max.
259 */
260 tid = ATH_AN_2_TID(an, bf->bf_tidno);
261 hdr->seq_ctrl = cpu_to_le16(tid->seq_next <<
262 IEEE80211_SEQ_SEQ_SHIFT);
263 bf->bf_seqno = tid->seq_next;
264 INCR(tid->seq_next, IEEE80211_SEQ_MAX);
265 }
266}
267
268static int setup_tx_flags(struct ath_softc *sc, struct sk_buff *skb,
269 struct ath_txq *txq)
270{
271 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
272 int flags = 0;
273
274 flags |= ATH9K_TXDESC_CLRDMASK; /* needed for crypto errors */
275 flags |= ATH9K_TXDESC_INTREQ;
276
277 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
278 flags |= ATH9K_TXDESC_NOACK;
279 if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
280 flags |= ATH9K_TXDESC_RTSENA;
281
282 return flags;
283}
284
285static struct ath_buf *ath_tx_get_buffer(struct ath_softc *sc)
286{
287 struct ath_buf *bf = NULL;
288
289 spin_lock_bh(&sc->sc_txbuflock);
290
291 if (unlikely(list_empty(&sc->sc_txbuf))) {
292 spin_unlock_bh(&sc->sc_txbuflock);
293 return NULL;
294 }
295
296 bf = list_first_entry(&sc->sc_txbuf, struct ath_buf, list);
297 list_del(&bf->list);
298
299 spin_unlock_bh(&sc->sc_txbuflock);
300
301 return bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700302}
303
304/* To complete a chain of buffers associated a frame */
305
306static void ath_tx_complete_buf(struct ath_softc *sc,
307 struct ath_buf *bf,
308 struct list_head *bf_q,
309 int txok, int sendbar)
310{
311 struct sk_buff *skb = bf->bf_mpdu;
312 struct ath_xmit_status tx_status;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700313
314 /*
315 * Set retry information.
316 * NB: Don't use the information in the descriptor, because the frame
317 * could be software retried.
318 */
319 tx_status.retries = bf->bf_retries;
320 tx_status.flags = 0;
321
322 if (sendbar)
323 tx_status.flags = ATH_TX_BAR;
324
325 if (!txok) {
326 tx_status.flags |= ATH_TX_ERROR;
327
Sujithcd3d39a2008-08-11 14:03:34 +0530328 if (bf_isxretried(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700329 tx_status.flags |= ATH_TX_XRETRY;
330 }
Sujith102e0572008-10-29 10:15:16 +0530331
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700332 /* Unmap this frame */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700333 pci_unmap_single(sc->pdev,
Sujithff9b6622008-08-14 13:27:16 +0530334 bf->bf_dmacontext,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700335 skb->len,
336 PCI_DMA_TODEVICE);
337 /* complete this frame */
Sujith528f0c62008-10-29 10:14:26 +0530338 ath_tx_complete(sc, skb, &tx_status);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700339
340 /*
341 * Return the list of ath_buf of this mpdu to free queue
342 */
343 spin_lock_bh(&sc->sc_txbuflock);
344 list_splice_tail_init(bf_q, &sc->sc_txbuf);
345 spin_unlock_bh(&sc->sc_txbuflock);
346}
347
348/*
349 * queue up a dest/ac pair for tx scheduling
350 * NB: must be called with txq lock held
351 */
352
353static void ath_tx_queue_tid(struct ath_txq *txq, struct ath_atx_tid *tid)
354{
355 struct ath_atx_ac *ac = tid->ac;
356
357 /*
358 * if tid is paused, hold off
359 */
360 if (tid->paused)
361 return;
362
363 /*
364 * add tid to ac atmost once
365 */
366 if (tid->sched)
367 return;
368
369 tid->sched = true;
370 list_add_tail(&tid->list, &ac->tid_q);
371
372 /*
373 * add node ac to txq atmost once
374 */
375 if (ac->sched)
376 return;
377
378 ac->sched = true;
379 list_add_tail(&ac->list, &txq->axq_acq);
380}
381
382/* pause a tid */
383
384static void ath_tx_pause_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
385{
386 struct ath_txq *txq = &sc->sc_txq[tid->ac->qnum];
387
388 spin_lock_bh(&txq->axq_lock);
389
390 tid->paused++;
391
392 spin_unlock_bh(&txq->axq_lock);
393}
394
395/* resume a tid and schedule aggregate */
396
397void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
398{
399 struct ath_txq *txq = &sc->sc_txq[tid->ac->qnum];
400
401 ASSERT(tid->paused > 0);
402 spin_lock_bh(&txq->axq_lock);
403
404 tid->paused--;
405
406 if (tid->paused > 0)
407 goto unlock;
408
409 if (list_empty(&tid->buf_q))
410 goto unlock;
411
412 /*
413 * Add this TID to scheduler and try to send out aggregates
414 */
415 ath_tx_queue_tid(txq, tid);
416 ath_txq_schedule(sc, txq);
417unlock:
418 spin_unlock_bh(&txq->axq_lock);
419}
420
421/* Compute the number of bad frames */
422
Sujithb5aa9bf2008-10-29 10:13:31 +0530423static int ath_tx_num_badfrms(struct ath_softc *sc, struct ath_buf *bf,
424 int txok)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700425{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700426 struct ath_buf *bf_last = bf->bf_lastbf;
427 struct ath_desc *ds = bf_last->bf_desc;
428 u16 seq_st = 0;
429 u32 ba[WME_BA_BMP_SIZE >> 5];
430 int ba_index;
431 int nbad = 0;
432 int isaggr = 0;
433
Sujithb5aa9bf2008-10-29 10:13:31 +0530434 if (ds->ds_txstat.ts_flags == ATH9K_TX_SW_ABORTED)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700435 return 0;
436
Sujithcd3d39a2008-08-11 14:03:34 +0530437 isaggr = bf_isaggr(bf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700438 if (isaggr) {
439 seq_st = ATH_DS_BA_SEQ(ds);
440 memcpy(ba, ATH_DS_BA_BITMAP(ds), WME_BA_BMP_SIZE >> 3);
441 }
442
443 while (bf) {
444 ba_index = ATH_BA_INDEX(seq_st, bf->bf_seqno);
445 if (!txok || (isaggr && !ATH_BA_ISSET(ba, ba_index)))
446 nbad++;
447
448 bf = bf->bf_next;
449 }
450
451 return nbad;
452}
453
454static void ath_tx_set_retry(struct ath_softc *sc, struct ath_buf *bf)
455{
456 struct sk_buff *skb;
457 struct ieee80211_hdr *hdr;
458
Sujithcd3d39a2008-08-11 14:03:34 +0530459 bf->bf_state.bf_type |= BUF_RETRY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700460 bf->bf_retries++;
461
462 skb = bf->bf_mpdu;
463 hdr = (struct ieee80211_hdr *)skb->data;
464 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_RETRY);
465}
466
467/* Update block ack window */
468
Sujith102e0572008-10-29 10:15:16 +0530469static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
470 int seqno)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700471{
472 int index, cindex;
473
474 index = ATH_BA_INDEX(tid->seq_start, seqno);
475 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
476
477 tid->tx_buf[cindex] = NULL;
478
479 while (tid->baw_head != tid->baw_tail && !tid->tx_buf[tid->baw_head]) {
480 INCR(tid->seq_start, IEEE80211_SEQ_MAX);
481 INCR(tid->baw_head, ATH_TID_MAX_BUFS);
482 }
483}
484
485/*
486 * ath_pkt_dur - compute packet duration (NB: not NAV)
487 *
488 * rix - rate index
489 * pktlen - total bytes (delims + data + fcs + pads + pad delims)
490 * width - 0 for 20 MHz, 1 for 40 MHz
491 * half_gi - to use 4us v/s 3.6 us for symbol time
492 */
Sujith102e0572008-10-29 10:15:16 +0530493static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, struct ath_buf *bf,
494 int width, int half_gi, bool shortPreamble)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700495{
Sujithe63835b2008-11-18 09:07:53 +0530496 struct ath_rate_table *rate_table = sc->hw_rate_table[sc->sc_curmode];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700497 u32 nbits, nsymbits, duration, nsymbols;
498 u8 rc;
499 int streams, pktlen;
500
Sujithcd3d39a2008-08-11 14:03:34 +0530501 pktlen = bf_isaggr(bf) ? bf->bf_al : bf->bf_frmlen;
Sujithe63835b2008-11-18 09:07:53 +0530502 rc = rate_table->info[rix].ratecode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700503
Sujithe63835b2008-11-18 09:07:53 +0530504 /* for legacy rates, use old function to compute packet duration */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700505 if (!IS_HT_RATE(rc))
Sujithe63835b2008-11-18 09:07:53 +0530506 return ath9k_hw_computetxtime(sc->sc_ah, rate_table, pktlen,
507 rix, shortPreamble);
508
509 /* find number of symbols: PLCP + data */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700510 nbits = (pktlen << 3) + OFDM_PLCP_BITS;
511 nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
512 nsymbols = (nbits + nsymbits - 1) / nsymbits;
513
514 if (!half_gi)
515 duration = SYMBOL_TIME(nsymbols);
516 else
517 duration = SYMBOL_TIME_HALFGI(nsymbols);
518
Sujithe63835b2008-11-18 09:07:53 +0530519 /* addup duration for legacy/ht training and signal fields */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700520 streams = HT_RC_2_STREAMS(rc);
521 duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
Sujith102e0572008-10-29 10:15:16 +0530522
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700523 return duration;
524}
525
526/* Rate module function to set rate related fields in tx descriptor */
527
528static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
529{
530 struct ath_hal *ah = sc->sc_ah;
Sujithe63835b2008-11-18 09:07:53 +0530531 struct ath_rate_table *rt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700532 struct ath_desc *ds = bf->bf_desc;
533 struct ath_desc *lastds = bf->bf_lastbf->bf_desc;
534 struct ath9k_11n_rate_series series[4];
Sujith528f0c62008-10-29 10:14:26 +0530535 struct sk_buff *skb;
536 struct ieee80211_tx_info *tx_info;
Sujitha8efee42008-11-18 09:07:30 +0530537 struct ieee80211_tx_rate *rates;
Sujithe63835b2008-11-18 09:07:53 +0530538 struct ieee80211_hdr *hdr;
539 int i, flags, rtsctsena = 0;
540 u32 ctsduration = 0;
541 u8 rix = 0, cix, ctsrate = 0;
542 __le16 fc;
543
544 memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4);
Sujith528f0c62008-10-29 10:14:26 +0530545
546 skb = (struct sk_buff *)bf->bf_mpdu;
Sujithe63835b2008-11-18 09:07:53 +0530547 hdr = (struct ieee80211_hdr *)skb->data;
548 fc = hdr->frame_control;
Sujith528f0c62008-10-29 10:14:26 +0530549 tx_info = IEEE80211_SKB_CB(skb);
Sujithe63835b2008-11-18 09:07:53 +0530550 rates = tx_info->control.rates;
Sujith528f0c62008-10-29 10:14:26 +0530551
Sujithe63835b2008-11-18 09:07:53 +0530552 if (ieee80211_has_morefrags(fc) ||
553 (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG)) {
554 rates[1].count = rates[2].count = rates[3].count = 0;
555 rates[1].idx = rates[2].idx = rates[3].idx = 0;
556 rates[0].count = ATH_TXMAXTRY;
557 }
558
559 /* get the cix for the lowest valid rix */
560 rt = sc->hw_rate_table[sc->sc_curmode];
Sujitha8efee42008-11-18 09:07:30 +0530561 for (i = 3; i >= 0; i--) {
Sujithe63835b2008-11-18 09:07:53 +0530562 if (rates[i].count && (rates[i].idx >= 0)) {
Sujitha8efee42008-11-18 09:07:30 +0530563 rix = rates[i].idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700564 break;
565 }
566 }
Sujithe63835b2008-11-18 09:07:53 +0530567
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700568 flags = (bf->bf_flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA));
Sujithe63835b2008-11-18 09:07:53 +0530569 cix = rt->info[rix].ctrl_rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700570
571 /*
Sujithe63835b2008-11-18 09:07:53 +0530572 * If 802.11g protection is enabled, determine whether to use RTS/CTS or
573 * just CTS. Note that this is only done for OFDM/HT unicast frames.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700574 */
Sujithe63835b2008-11-18 09:07:53 +0530575 if (sc->sc_protmode != PROT_M_NONE && !(bf->bf_flags & ATH9K_TXDESC_NOACK)
Sujith46d14a52008-11-18 09:08:13 +0530576 && (rt->info[rix].phy == WLAN_RC_PHY_OFDM ||
Sujithe63835b2008-11-18 09:07:53 +0530577 WLAN_RC_PHY_HT(rt->info[rix].phy))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700578 if (sc->sc_protmode == PROT_M_RTSCTS)
579 flags = ATH9K_TXDESC_RTSENA;
580 else if (sc->sc_protmode == PROT_M_CTSONLY)
581 flags = ATH9K_TXDESC_CTSENA;
582
Sujithe63835b2008-11-18 09:07:53 +0530583 cix = rt->info[sc->sc_protrix].ctrl_rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700584 rtsctsena = 1;
585 }
586
Sujithe63835b2008-11-18 09:07:53 +0530587 /* For 11n, the default behavior is to enable RTS for hw retried frames.
588 * We enable the global flag here and let rate series flags determine
589 * which rates will actually use RTS.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700590 */
Sujithcd3d39a2008-08-11 14:03:34 +0530591 if ((ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) && bf_isdata(bf)) {
Sujithe63835b2008-11-18 09:07:53 +0530592 /* 802.11g protection not needed, use our default behavior */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700593 if (!rtsctsena)
594 flags = ATH9K_TXDESC_RTSENA;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700595 }
596
Sujithe63835b2008-11-18 09:07:53 +0530597 /* Set protection if aggregate protection on */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700598 if (sc->sc_config.ath_aggr_prot &&
Sujithcd3d39a2008-08-11 14:03:34 +0530599 (!bf_isaggr(bf) || (bf_isaggr(bf) && bf->bf_al < 8192))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700600 flags = ATH9K_TXDESC_RTSENA;
Sujithe63835b2008-11-18 09:07:53 +0530601 cix = rt->info[sc->sc_protrix].ctrl_rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700602 rtsctsena = 1;
603 }
604
Sujithe63835b2008-11-18 09:07:53 +0530605 /* For AR5416 - RTS cannot be followed by a frame larger than 8K */
606 if (bf_isaggr(bf) && (bf->bf_al > ah->ah_caps.rts_aggr_limit))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700607 flags &= ~(ATH9K_TXDESC_RTSENA);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700608
609 /*
Sujithe63835b2008-11-18 09:07:53 +0530610 * CTS transmit rate is derived from the transmit rate by looking in the
611 * h/w rate table. We must also factor in whether or not a short
612 * preamble is to be used. NB: cix is set above where RTS/CTS is enabled
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700613 */
Sujithe63835b2008-11-18 09:07:53 +0530614 ctsrate = rt->info[cix].ratecode |
615 (bf_isshpreamble(bf) ? rt->info[cix].short_preamble : 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700616
617 for (i = 0; i < 4; i++) {
Sujithe63835b2008-11-18 09:07:53 +0530618 if (!rates[i].count || (rates[i].idx < 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700619 continue;
620
Sujitha8efee42008-11-18 09:07:30 +0530621 rix = rates[i].idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700622
Sujithe63835b2008-11-18 09:07:53 +0530623 series[i].Rate = rt->info[rix].ratecode |
624 (bf_isshpreamble(bf) ? rt->info[rix].short_preamble : 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700625
Sujitha8efee42008-11-18 09:07:30 +0530626 series[i].Tries = rates[i].count;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700627
628 series[i].RateFlags = (
Sujitha8efee42008-11-18 09:07:30 +0530629 (rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) ?
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700630 ATH9K_RATESERIES_RTS_CTS : 0) |
Sujitha8efee42008-11-18 09:07:30 +0530631 ((rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ?
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700632 ATH9K_RATESERIES_2040 : 0) |
Sujitha8efee42008-11-18 09:07:30 +0530633 ((rates[i].flags & IEEE80211_TX_RC_SHORT_GI) ?
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700634 ATH9K_RATESERIES_HALFGI : 0);
635
Sujith102e0572008-10-29 10:15:16 +0530636 series[i].PktDuration = ath_pkt_duration(sc, rix, bf,
Sujitha8efee42008-11-18 09:07:30 +0530637 (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) != 0,
638 (rates[i].flags & IEEE80211_TX_RC_SHORT_GI),
Sujith102e0572008-10-29 10:15:16 +0530639 bf_isshpreamble(bf));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700640
Sujithff37e332008-11-24 12:07:55 +0530641 series[i].ChSel = sc->sc_tx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700642
643 if (rtsctsena)
644 series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700645 }
646
Sujithe63835b2008-11-18 09:07:53 +0530647 /* set dur_update_en for l-sig computation except for PS-Poll frames */
648 ath9k_hw_set11n_ratescenario(ah, ds, lastds, !bf_ispspoll(bf),
649 ctsrate, ctsduration,
Sujithcd3d39a2008-08-11 14:03:34 +0530650 series, 4, flags);
Sujith102e0572008-10-29 10:15:16 +0530651
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700652 if (sc->sc_config.ath_aggr_prot && flags)
653 ath9k_hw_set11n_burstduration(ah, ds, 8192);
654}
655
656/*
657 * Function to send a normal HT (non-AMPDU) frame
658 * NB: must be called with txq lock held
659 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700660static int ath_tx_send_normal(struct ath_softc *sc,
661 struct ath_txq *txq,
662 struct ath_atx_tid *tid,
663 struct list_head *bf_head)
664{
665 struct ath_buf *bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700666
667 BUG_ON(list_empty(bf_head));
668
669 bf = list_first_entry(bf_head, struct ath_buf, list);
Sujithcd3d39a2008-08-11 14:03:34 +0530670 bf->bf_state.bf_type &= ~BUF_AMPDU; /* regular HT frame */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700671
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700672 /* update starting sequence number for subsequent ADDBA request */
673 INCR(tid->seq_start, IEEE80211_SEQ_MAX);
674
675 /* Queue to h/w without aggregation */
676 bf->bf_nframes = 1;
677 bf->bf_lastbf = bf->bf_lastfrm; /* one single frame */
678 ath_buf_set_rate(sc, bf);
679 ath_tx_txqaddbuf(sc, txq, bf_head);
680
681 return 0;
682}
683
684/* flush tid's software queue and send frames as non-ampdu's */
685
686static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
687{
688 struct ath_txq *txq = &sc->sc_txq[tid->ac->qnum];
689 struct ath_buf *bf;
690 struct list_head bf_head;
691 INIT_LIST_HEAD(&bf_head);
692
693 ASSERT(tid->paused > 0);
694 spin_lock_bh(&txq->axq_lock);
695
696 tid->paused--;
697
698 if (tid->paused > 0) {
699 spin_unlock_bh(&txq->axq_lock);
700 return;
701 }
702
703 while (!list_empty(&tid->buf_q)) {
704 bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
Sujithcd3d39a2008-08-11 14:03:34 +0530705 ASSERT(!bf_isretried(bf));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700706 list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list);
707 ath_tx_send_normal(sc, txq, tid, &bf_head);
708 }
709
710 spin_unlock_bh(&txq->axq_lock);
711}
712
713/* Completion routine of an aggregate */
714
715static void ath_tx_complete_aggr_rifs(struct ath_softc *sc,
716 struct ath_txq *txq,
717 struct ath_buf *bf,
718 struct list_head *bf_q,
719 int txok)
720{
Sujith528f0c62008-10-29 10:14:26 +0530721 struct ath_node *an = NULL;
722 struct sk_buff *skb;
723 struct ieee80211_tx_info *tx_info;
724 struct ath_atx_tid *tid = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700725 struct ath_buf *bf_last = bf->bf_lastbf;
726 struct ath_desc *ds = bf_last->bf_desc;
727 struct ath_buf *bf_next, *bf_lastq = NULL;
728 struct list_head bf_head, bf_pending;
729 u16 seq_st = 0;
730 u32 ba[WME_BA_BMP_SIZE >> 5];
731 int isaggr, txfail, txpending, sendbar = 0, needreset = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700732
Sujith528f0c62008-10-29 10:14:26 +0530733 skb = (struct sk_buff *)bf->bf_mpdu;
734 tx_info = IEEE80211_SKB_CB(skb);
735
736 if (tx_info->control.sta) {
737 an = (struct ath_node *)tx_info->control.sta->drv_priv;
738 tid = ATH_AN_2_TID(an, bf->bf_tidno);
739 }
740
Sujithcd3d39a2008-08-11 14:03:34 +0530741 isaggr = bf_isaggr(bf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700742 if (isaggr) {
743 if (txok) {
744 if (ATH_DS_TX_BA(ds)) {
745 /*
746 * extract starting sequence and
747 * block-ack bitmap
748 */
749 seq_st = ATH_DS_BA_SEQ(ds);
750 memcpy(ba,
751 ATH_DS_BA_BITMAP(ds),
752 WME_BA_BMP_SIZE >> 3);
753 } else {
Luis R. Rodriguez0345f372008-10-03 15:45:25 -0700754 memset(ba, 0, WME_BA_BMP_SIZE >> 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700755
756 /*
757 * AR5416 can become deaf/mute when BA
758 * issue happens. Chip needs to be reset.
759 * But AP code may have sychronization issues
760 * when perform internal reset in this routine.
761 * Only enable reset in STA mode for now.
762 */
Colin McCabed97809d2008-12-01 13:38:55 -0800763 if (sc->sc_ah->ah_opmode ==
764 NL80211_IFTYPE_STATION)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700765 needreset = 1;
766 }
767 } else {
Luis R. Rodriguez0345f372008-10-03 15:45:25 -0700768 memset(ba, 0, WME_BA_BMP_SIZE >> 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700769 }
770 }
771
772 INIT_LIST_HEAD(&bf_pending);
773 INIT_LIST_HEAD(&bf_head);
774
775 while (bf) {
776 txfail = txpending = 0;
777 bf_next = bf->bf_next;
778
779 if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, bf->bf_seqno))) {
780 /* transmit completion, subframe is
781 * acked by block ack */
782 } else if (!isaggr && txok) {
783 /* transmit completion */
784 } else {
785
Sujitha37c2c72008-10-29 10:15:40 +0530786 if (!(tid->state & AGGR_CLEANUP) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700787 ds->ds_txstat.ts_flags != ATH9K_TX_SW_ABORTED) {
788 if (bf->bf_retries < ATH_MAX_SW_RETRIES) {
789 ath_tx_set_retry(sc, bf);
790 txpending = 1;
791 } else {
Sujithcd3d39a2008-08-11 14:03:34 +0530792 bf->bf_state.bf_type |= BUF_XRETRY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700793 txfail = 1;
794 sendbar = 1;
795 }
796 } else {
797 /*
798 * cleanup in progress, just fail
799 * the un-acked sub-frames
800 */
801 txfail = 1;
802 }
803 }
804 /*
805 * Remove ath_buf's of this sub-frame from aggregate queue.
806 */
807 if (bf_next == NULL) { /* last subframe in the aggregate */
808 ASSERT(bf->bf_lastfrm == bf_last);
809
810 /*
811 * The last descriptor of the last sub frame could be
812 * a holding descriptor for h/w. If that's the case,
813 * bf->bf_lastfrm won't be in the bf_q.
814 * Make sure we handle bf_q properly here.
815 */
816
817 if (!list_empty(bf_q)) {
818 bf_lastq = list_entry(bf_q->prev,
819 struct ath_buf, list);
820 list_cut_position(&bf_head,
821 bf_q, &bf_lastq->list);
822 } else {
823 /*
824 * XXX: if the last subframe only has one
825 * descriptor which is also being used as
826 * a holding descriptor. Then the ath_buf
827 * is not in the bf_q at all.
828 */
829 INIT_LIST_HEAD(&bf_head);
830 }
831 } else {
832 ASSERT(!list_empty(bf_q));
833 list_cut_position(&bf_head,
834 bf_q, &bf->bf_lastfrm->list);
835 }
836
837 if (!txpending) {
838 /*
839 * complete the acked-ones/xretried ones; update
840 * block-ack window
841 */
842 spin_lock_bh(&txq->axq_lock);
843 ath_tx_update_baw(sc, tid, bf->bf_seqno);
844 spin_unlock_bh(&txq->axq_lock);
845
846 /* complete this sub-frame */
847 ath_tx_complete_buf(sc, bf, &bf_head, !txfail, sendbar);
848 } else {
849 /*
850 * retry the un-acked ones
851 */
852 /*
853 * XXX: if the last descriptor is holding descriptor,
854 * in order to requeue the frame to software queue, we
855 * need to allocate a new descriptor and
856 * copy the content of holding descriptor to it.
857 */
858 if (bf->bf_next == NULL &&
859 bf_last->bf_status & ATH_BUFSTATUS_STALE) {
860 struct ath_buf *tbf;
861
862 /* allocate new descriptor */
863 spin_lock_bh(&sc->sc_txbuflock);
864 ASSERT(!list_empty((&sc->sc_txbuf)));
865 tbf = list_first_entry(&sc->sc_txbuf,
866 struct ath_buf, list);
867 list_del(&tbf->list);
868 spin_unlock_bh(&sc->sc_txbuflock);
869
870 ATH_TXBUF_RESET(tbf);
871
872 /* copy descriptor content */
873 tbf->bf_mpdu = bf_last->bf_mpdu;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700874 tbf->bf_buf_addr = bf_last->bf_buf_addr;
875 *(tbf->bf_desc) = *(bf_last->bf_desc);
876
877 /* link it to the frame */
878 if (bf_lastq) {
879 bf_lastq->bf_desc->ds_link =
880 tbf->bf_daddr;
881 bf->bf_lastfrm = tbf;
882 ath9k_hw_cleartxdesc(sc->sc_ah,
883 bf->bf_lastfrm->bf_desc);
884 } else {
885 tbf->bf_state = bf_last->bf_state;
886 tbf->bf_lastfrm = tbf;
887 ath9k_hw_cleartxdesc(sc->sc_ah,
888 tbf->bf_lastfrm->bf_desc);
889
890 /* copy the DMA context */
Sujithff9b6622008-08-14 13:27:16 +0530891 tbf->bf_dmacontext =
892 bf_last->bf_dmacontext;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700893 }
894 list_add_tail(&tbf->list, &bf_head);
895 } else {
896 /*
897 * Clear descriptor status words for
898 * software retry
899 */
900 ath9k_hw_cleartxdesc(sc->sc_ah,
Sujithff9b6622008-08-14 13:27:16 +0530901 bf->bf_lastfrm->bf_desc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700902 }
903
904 /*
905 * Put this buffer to the temporary pending
906 * queue to retain ordering
907 */
908 list_splice_tail_init(&bf_head, &bf_pending);
909 }
910
911 bf = bf_next;
912 }
913
Sujitha37c2c72008-10-29 10:15:40 +0530914 if (tid->state & AGGR_CLEANUP) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700915 /* check to see if we're done with cleaning the h/w queue */
916 spin_lock_bh(&txq->axq_lock);
917
918 if (tid->baw_head == tid->baw_tail) {
Sujitha37c2c72008-10-29 10:15:40 +0530919 tid->state &= ~AGGR_ADDBA_COMPLETE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700920 tid->addba_exchangeattempts = 0;
921 spin_unlock_bh(&txq->axq_lock);
922
Sujitha37c2c72008-10-29 10:15:40 +0530923 tid->state &= ~AGGR_CLEANUP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700924
925 /* send buffered frames as singles */
926 ath_tx_flush_tid(sc, tid);
927 } else
928 spin_unlock_bh(&txq->axq_lock);
929
930 return;
931 }
932
933 /*
934 * prepend un-acked frames to the beginning of the pending frame queue
935 */
936 if (!list_empty(&bf_pending)) {
937 spin_lock_bh(&txq->axq_lock);
938 /* Note: we _prepend_, we _do_not_ at to
939 * the end of the queue ! */
940 list_splice(&bf_pending, &tid->buf_q);
941 ath_tx_queue_tid(txq, tid);
942 spin_unlock_bh(&txq->axq_lock);
943 }
944
945 if (needreset)
Sujithf45144e2008-08-11 14:02:53 +0530946 ath_reset(sc, false);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700947
948 return;
949}
950
Sujithc4288392008-11-18 09:09:30 +0530951static void ath_tx_rc_status(struct ath_buf *bf, struct ath_desc *ds, int nbad)
952{
953 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
954 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
955 struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
956
Vasanthakumar Thiagarajan7ac47012008-11-20 11:51:18 +0530957 tx_info_priv->update_rc = false;
Sujithc4288392008-11-18 09:09:30 +0530958 if (ds->ds_txstat.ts_status & ATH9K_TXERR_FILT)
959 tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
960
961 if ((ds->ds_txstat.ts_status & ATH9K_TXERR_FILT) == 0 &&
962 (bf->bf_flags & ATH9K_TXDESC_NOACK) == 0) {
963 if (bf_isdata(bf)) {
964 memcpy(&tx_info_priv->tx, &ds->ds_txstat,
965 sizeof(tx_info_priv->tx));
966 tx_info_priv->n_frames = bf->bf_nframes;
967 tx_info_priv->n_bad_frames = nbad;
Vasanthakumar Thiagarajan7ac47012008-11-20 11:51:18 +0530968 tx_info_priv->update_rc = true;
Sujithc4288392008-11-18 09:09:30 +0530969 }
970 }
971}
972
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700973/* Process completed xmit descriptors from the specified queue */
974
Sujithc4288392008-11-18 09:09:30 +0530975static void ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700976{
977 struct ath_hal *ah = sc->sc_ah;
978 struct ath_buf *bf, *lastbf, *bf_held = NULL;
979 struct list_head bf_head;
Sujithc4288392008-11-18 09:09:30 +0530980 struct ath_desc *ds;
981 int txok, nbad = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700982 int status;
983
Sujith04bd4632008-11-28 22:18:05 +0530984 DPRINTF(sc, ATH_DBG_QUEUE, "tx queue %d (%x), link %p\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700985 txq->axq_qnum, ath9k_hw_gettxbuf(sc->sc_ah, txq->axq_qnum),
986 txq->axq_link);
987
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700988 for (;;) {
989 spin_lock_bh(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700990 if (list_empty(&txq->axq_q)) {
991 txq->axq_link = NULL;
992 txq->axq_linkbuf = NULL;
993 spin_unlock_bh(&txq->axq_lock);
994 break;
995 }
996 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
997
998 /*
999 * There is a race condition that a BH gets scheduled
1000 * after sw writes TxE and before hw re-load the last
1001 * descriptor to get the newly chained one.
1002 * Software must keep the last DONE descriptor as a
1003 * holding descriptor - software does so by marking
1004 * it with the STALE flag.
1005 */
1006 bf_held = NULL;
1007 if (bf->bf_status & ATH_BUFSTATUS_STALE) {
1008 bf_held = bf;
1009 if (list_is_last(&bf_held->list, &txq->axq_q)) {
1010 /* FIXME:
1011 * The holding descriptor is the last
1012 * descriptor in queue. It's safe to remove
1013 * the last holding descriptor in BH context.
1014 */
1015 spin_unlock_bh(&txq->axq_lock);
1016 break;
1017 } else {
1018 /* Lets work with the next buffer now */
1019 bf = list_entry(bf_held->list.next,
1020 struct ath_buf, list);
1021 }
1022 }
1023
1024 lastbf = bf->bf_lastbf;
1025 ds = lastbf->bf_desc; /* NB: last decriptor */
1026
1027 status = ath9k_hw_txprocdesc(ah, ds);
1028 if (status == -EINPROGRESS) {
1029 spin_unlock_bh(&txq->axq_lock);
1030 break;
1031 }
1032 if (bf->bf_desc == txq->axq_lastdsWithCTS)
1033 txq->axq_lastdsWithCTS = NULL;
1034 if (ds == txq->axq_gatingds)
1035 txq->axq_gatingds = NULL;
1036
1037 /*
1038 * Remove ath_buf's of the same transmit unit from txq,
1039 * however leave the last descriptor back as the holding
1040 * descriptor for hw.
1041 */
1042 lastbf->bf_status |= ATH_BUFSTATUS_STALE;
1043 INIT_LIST_HEAD(&bf_head);
1044
1045 if (!list_is_singular(&lastbf->list))
1046 list_cut_position(&bf_head,
1047 &txq->axq_q, lastbf->list.prev);
1048
1049 txq->axq_depth--;
1050
Sujithcd3d39a2008-08-11 14:03:34 +05301051 if (bf_isaggr(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001052 txq->axq_aggr_depth--;
1053
1054 txok = (ds->ds_txstat.ts_status == 0);
1055
1056 spin_unlock_bh(&txq->axq_lock);
1057
1058 if (bf_held) {
1059 list_del(&bf_held->list);
1060 spin_lock_bh(&sc->sc_txbuflock);
1061 list_add_tail(&bf_held->list, &sc->sc_txbuf);
1062 spin_unlock_bh(&sc->sc_txbuflock);
1063 }
1064
Sujithcd3d39a2008-08-11 14:03:34 +05301065 if (!bf_isampdu(bf)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001066 /*
1067 * This frame is sent out as a single frame.
1068 * Use hardware retry status for this frame.
1069 */
1070 bf->bf_retries = ds->ds_txstat.ts_longretry;
1071 if (ds->ds_txstat.ts_status & ATH9K_TXERR_XRETRY)
Sujithcd3d39a2008-08-11 14:03:34 +05301072 bf->bf_state.bf_type |= BUF_XRETRY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001073 nbad = 0;
1074 } else {
1075 nbad = ath_tx_num_badfrms(sc, bf, txok);
1076 }
Johannes Berge6a98542008-10-21 12:40:02 +02001077
Sujithc4288392008-11-18 09:09:30 +05301078 ath_tx_rc_status(bf, ds, nbad);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001079
1080 /*
1081 * Complete this transmit unit
1082 */
Sujithcd3d39a2008-08-11 14:03:34 +05301083 if (bf_isampdu(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001084 ath_tx_complete_aggr_rifs(sc, txq, bf, &bf_head, txok);
1085 else
1086 ath_tx_complete_buf(sc, bf, &bf_head, txok, 0);
1087
1088 /* Wake up mac80211 queue */
1089
1090 spin_lock_bh(&txq->axq_lock);
1091 if (txq->stopped && ath_txq_depth(sc, txq->axq_qnum) <=
1092 (ATH_TXBUF - 20)) {
1093 int qnum;
1094 qnum = ath_get_mac80211_qnum(txq->axq_qnum, sc);
1095 if (qnum != -1) {
1096 ieee80211_wake_queue(sc->hw, qnum);
1097 txq->stopped = 0;
1098 }
1099
1100 }
1101
1102 /*
1103 * schedule any pending packets if aggregation is enabled
1104 */
Sujith672840a2008-08-11 14:05:08 +05301105 if (sc->sc_flags & SC_OP_TXAGGR)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001106 ath_txq_schedule(sc, txq);
1107 spin_unlock_bh(&txq->axq_lock);
1108 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001109}
1110
1111static void ath_tx_stopdma(struct ath_softc *sc, struct ath_txq *txq)
1112{
1113 struct ath_hal *ah = sc->sc_ah;
1114
1115 (void) ath9k_hw_stoptxdma(ah, txq->axq_qnum);
Sujith04bd4632008-11-28 22:18:05 +05301116 DPRINTF(sc, ATH_DBG_XMIT, "tx queue [%u] %x, link %p\n",
1117 txq->axq_qnum, ath9k_hw_gettxbuf(ah, txq->axq_qnum),
1118 txq->axq_link);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001119}
1120
1121/* Drain only the data queues */
1122
1123static void ath_drain_txdataq(struct ath_softc *sc, bool retry_tx)
1124{
1125 struct ath_hal *ah = sc->sc_ah;
Sujith102e0572008-10-29 10:15:16 +05301126 int i, status, npend = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001127
Sujith672840a2008-08-11 14:05:08 +05301128 if (!(sc->sc_flags & SC_OP_INVALID)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001129 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1130 if (ATH_TXQ_SETUP(sc, i)) {
1131 ath_tx_stopdma(sc, &sc->sc_txq[i]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001132 /* The TxDMA may not really be stopped.
1133 * Double check the hal tx pending count */
1134 npend += ath9k_hw_numtxpending(ah,
Sujith102e0572008-10-29 10:15:16 +05301135 sc->sc_txq[i].axq_qnum);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001136 }
1137 }
1138 }
1139
1140 if (npend) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001141 /* TxDMA not stopped, reset the hal */
Sujith04bd4632008-11-28 22:18:05 +05301142 DPRINTF(sc, ATH_DBG_XMIT, "Unable to stop TxDMA. Reset HAL!\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001143
1144 spin_lock_bh(&sc->sc_resetlock);
Sujithb4696c8b2008-08-11 14:04:52 +05301145 if (!ath9k_hw_reset(ah,
Sujith927e70e2008-08-14 13:26:34 +05301146 sc->sc_ah->ah_curchan,
Sujith99405f92008-11-24 12:08:35 +05301147 sc->tx_chan_width,
Sujith927e70e2008-08-14 13:26:34 +05301148 sc->sc_tx_chainmask, sc->sc_rx_chainmask,
1149 sc->sc_ht_extprotspacing, true, &status)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001150
1151 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301152 "Unable to reset hardware; hal status %u\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001153 status);
1154 }
1155 spin_unlock_bh(&sc->sc_resetlock);
1156 }
1157
1158 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1159 if (ATH_TXQ_SETUP(sc, i))
1160 ath_tx_draintxq(sc, &sc->sc_txq[i], retry_tx);
1161 }
1162}
1163
1164/* Add a sub-frame to block ack window */
1165
1166static void ath_tx_addto_baw(struct ath_softc *sc,
1167 struct ath_atx_tid *tid,
1168 struct ath_buf *bf)
1169{
1170 int index, cindex;
1171
Sujithcd3d39a2008-08-11 14:03:34 +05301172 if (bf_isretried(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001173 return;
1174
1175 index = ATH_BA_INDEX(tid->seq_start, bf->bf_seqno);
1176 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
1177
1178 ASSERT(tid->tx_buf[cindex] == NULL);
1179 tid->tx_buf[cindex] = bf;
1180
1181 if (index >= ((tid->baw_tail - tid->baw_head) &
1182 (ATH_TID_MAX_BUFS - 1))) {
1183 tid->baw_tail = cindex;
1184 INCR(tid->baw_tail, ATH_TID_MAX_BUFS);
1185 }
1186}
1187
1188/*
1189 * Function to send an A-MPDU
1190 * NB: must be called with txq lock held
1191 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001192static int ath_tx_send_ampdu(struct ath_softc *sc,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001193 struct ath_atx_tid *tid,
1194 struct list_head *bf_head,
1195 struct ath_tx_control *txctl)
1196{
1197 struct ath_buf *bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001198
1199 BUG_ON(list_empty(bf_head));
1200
1201 bf = list_first_entry(bf_head, struct ath_buf, list);
Sujithcd3d39a2008-08-11 14:03:34 +05301202 bf->bf_state.bf_type |= BUF_AMPDU;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001203
1204 /*
1205 * Do not queue to h/w when any of the following conditions is true:
1206 * - there are pending frames in software queue
1207 * - the TID is currently paused for ADDBA/BAR request
1208 * - seqno is not within block-ack window
1209 * - h/w queue depth exceeds low water mark
1210 */
1211 if (!list_empty(&tid->buf_q) || tid->paused ||
1212 !BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno) ||
Sujith528f0c62008-10-29 10:14:26 +05301213 txctl->txq->axq_depth >= ATH_AGGR_MIN_QDEPTH) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001214 /*
1215 * Add this frame to software queue for scheduling later
1216 * for aggregation.
1217 */
1218 list_splice_tail_init(bf_head, &tid->buf_q);
Sujith528f0c62008-10-29 10:14:26 +05301219 ath_tx_queue_tid(txctl->txq, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001220 return 0;
1221 }
1222
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001223 /* Add sub-frame to BAW */
1224 ath_tx_addto_baw(sc, tid, bf);
1225
1226 /* Queue to h/w without aggregation */
1227 bf->bf_nframes = 1;
1228 bf->bf_lastbf = bf->bf_lastfrm; /* one single frame */
1229 ath_buf_set_rate(sc, bf);
Sujith528f0c62008-10-29 10:14:26 +05301230 ath_tx_txqaddbuf(sc, txctl->txq, bf_head);
Sujith102e0572008-10-29 10:15:16 +05301231
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001232 return 0;
1233}
1234
1235/*
1236 * looks up the rate
1237 * returns aggr limit based on lowest of the rates
1238 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001239static u32 ath_lookup_rate(struct ath_softc *sc,
Johannes Bergae5eb022008-10-14 16:58:37 +02001240 struct ath_buf *bf,
1241 struct ath_atx_tid *tid)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001242{
Sujitha8efee42008-11-18 09:07:30 +05301243 struct ath_rate_table *rate_table = sc->hw_rate_table[sc->sc_curmode];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001244 struct sk_buff *skb;
1245 struct ieee80211_tx_info *tx_info;
Sujitha8efee42008-11-18 09:07:30 +05301246 struct ieee80211_tx_rate *rates;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001247 struct ath_tx_info_priv *tx_info_priv;
1248 u32 max_4ms_framelen, frame_length;
1249 u16 aggr_limit, legacy = 0, maxampdu;
1250 int i;
1251
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001252 skb = (struct sk_buff *)bf->bf_mpdu;
1253 tx_info = IEEE80211_SKB_CB(skb);
Sujitha8efee42008-11-18 09:07:30 +05301254 rates = tx_info->control.rates;
1255 tx_info_priv =
1256 (struct ath_tx_info_priv *)tx_info->rate_driver_data[0];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001257
1258 /*
1259 * Find the lowest frame length among the rate series that will have a
1260 * 4ms transmit duration.
1261 * TODO - TXOP limit needs to be considered.
1262 */
1263 max_4ms_framelen = ATH_AMPDU_LIMIT_MAX;
1264
1265 for (i = 0; i < 4; i++) {
Sujitha8efee42008-11-18 09:07:30 +05301266 if (rates[i].count) {
Sujithe63835b2008-11-18 09:07:53 +05301267 if (!WLAN_RC_PHY_HT(rate_table->info[rates[i].idx].phy)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001268 legacy = 1;
1269 break;
1270 }
1271
Sujitha8efee42008-11-18 09:07:30 +05301272 frame_length =
1273 rate_table->info[rates[i].idx].max_4ms_framelen;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001274 max_4ms_framelen = min(max_4ms_framelen, frame_length);
1275 }
1276 }
1277
1278 /*
1279 * limit aggregate size by the minimum rate if rate selected is
1280 * not a probe rate, if rate selected is a probe rate then
1281 * avoid aggregation of this packet.
1282 */
1283 if (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE || legacy)
1284 return 0;
1285
1286 aggr_limit = min(max_4ms_framelen,
1287 (u32)ATH_AMPDU_LIMIT_DEFAULT);
1288
1289 /*
1290 * h/w can accept aggregates upto 16 bit lengths (65535).
1291 * The IE, however can hold upto 65536, which shows up here
1292 * as zero. Ignore 65536 since we are constrained by hw.
1293 */
Johannes Bergae5eb022008-10-14 16:58:37 +02001294 maxampdu = tid->an->maxampdu;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001295 if (maxampdu)
1296 aggr_limit = min(aggr_limit, maxampdu);
1297
1298 return aggr_limit;
1299}
1300
1301/*
1302 * returns the number of delimiters to be added to
1303 * meet the minimum required mpdudensity.
1304 * caller should make sure that the rate is HT rate .
1305 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001306static int ath_compute_num_delims(struct ath_softc *sc,
Johannes Bergae5eb022008-10-14 16:58:37 +02001307 struct ath_atx_tid *tid,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001308 struct ath_buf *bf,
1309 u16 frmlen)
1310{
Sujithe63835b2008-11-18 09:07:53 +05301311 struct ath_rate_table *rt = sc->hw_rate_table[sc->sc_curmode];
Sujitha8efee42008-11-18 09:07:30 +05301312 struct sk_buff *skb = bf->bf_mpdu;
1313 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001314 u32 nsymbits, nsymbols, mpdudensity;
1315 u16 minlen;
1316 u8 rc, flags, rix;
1317 int width, half_gi, ndelim, mindelim;
1318
1319 /* Select standard number of delimiters based on frame length alone */
1320 ndelim = ATH_AGGR_GET_NDELIM(frmlen);
1321
1322 /*
1323 * If encryption enabled, hardware requires some more padding between
1324 * subframes.
1325 * TODO - this could be improved to be dependent on the rate.
1326 * The hardware can keep up at lower rates, but not higher rates
1327 */
1328 if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR)
1329 ndelim += ATH_AGGR_ENCRYPTDELIM;
1330
1331 /*
1332 * Convert desired mpdu density from microeconds to bytes based
1333 * on highest rate in rate series (i.e. first rate) to determine
1334 * required minimum length for subframe. Take into account
1335 * whether high rate is 20 or 40Mhz and half or full GI.
1336 */
Johannes Bergae5eb022008-10-14 16:58:37 +02001337 mpdudensity = tid->an->mpdudensity;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001338
1339 /*
1340 * If there is no mpdu density restriction, no further calculation
1341 * is needed.
1342 */
1343 if (mpdudensity == 0)
1344 return ndelim;
1345
Sujitha8efee42008-11-18 09:07:30 +05301346 rix = tx_info->control.rates[0].idx;
1347 flags = tx_info->control.rates[0].flags;
Sujithe63835b2008-11-18 09:07:53 +05301348 rc = rt->info[rix].ratecode;
Sujitha8efee42008-11-18 09:07:30 +05301349 width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0;
1350 half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001351
1352 if (half_gi)
1353 nsymbols = NUM_SYMBOLS_PER_USEC_HALFGI(mpdudensity);
1354 else
1355 nsymbols = NUM_SYMBOLS_PER_USEC(mpdudensity);
1356
1357 if (nsymbols == 0)
1358 nsymbols = 1;
1359
1360 nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
1361 minlen = (nsymbols * nsymbits) / BITS_PER_BYTE;
1362
1363 /* Is frame shorter than required minimum length? */
1364 if (frmlen < minlen) {
1365 /* Get the minimum number of delimiters required. */
1366 mindelim = (minlen - frmlen) / ATH_AGGR_DELIM_SZ;
1367 ndelim = max(mindelim, ndelim);
1368 }
1369
1370 return ndelim;
1371}
1372
1373/*
1374 * For aggregation from software buffer queue.
1375 * NB: must be called with txq lock held
1376 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001377static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
1378 struct ath_atx_tid *tid,
1379 struct list_head *bf_q,
1380 struct ath_buf **bf_last,
1381 struct aggr_rifs_param *param,
1382 int *prev_frames)
1383{
1384#define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
1385 struct ath_buf *bf, *tbf, *bf_first, *bf_prev = NULL;
1386 struct list_head bf_head;
1387 int rl = 0, nframes = 0, ndelim;
1388 u16 aggr_limit = 0, al = 0, bpad = 0,
1389 al_delta, h_baw = tid->baw_size / 2;
1390 enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
Sujitha8efee42008-11-18 09:07:30 +05301391 int prev_al = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001392 INIT_LIST_HEAD(&bf_head);
1393
1394 BUG_ON(list_empty(&tid->buf_q));
1395
1396 bf_first = list_first_entry(&tid->buf_q, struct ath_buf, list);
1397
1398 do {
1399 bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
1400
1401 /*
1402 * do not step over block-ack window
1403 */
1404 if (!BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno)) {
1405 status = ATH_AGGR_BAW_CLOSED;
1406 break;
1407 }
1408
1409 if (!rl) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001410 aggr_limit = ath_lookup_rate(sc, bf, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001411 rl = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001412 }
1413
1414 /*
1415 * do not exceed aggregation limit
1416 */
1417 al_delta = ATH_AGGR_DELIM_SZ + bf->bf_frmlen;
1418
1419 if (nframes && (aggr_limit <
1420 (al + bpad + al_delta + prev_al))) {
1421 status = ATH_AGGR_LIMITED;
1422 break;
1423 }
1424
1425 /*
1426 * do not exceed subframe limit
1427 */
1428 if ((nframes + *prev_frames) >=
1429 min((int)h_baw, ATH_AMPDU_SUBFRAME_DEFAULT)) {
1430 status = ATH_AGGR_LIMITED;
1431 break;
1432 }
1433
1434 /*
1435 * add padding for previous frame to aggregation length
1436 */
1437 al += bpad + al_delta;
1438
1439 /*
1440 * Get the delimiters needed to meet the MPDU
1441 * density for this node.
1442 */
Johannes Bergae5eb022008-10-14 16:58:37 +02001443 ndelim = ath_compute_num_delims(sc, tid, bf_first, bf->bf_frmlen);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001444
1445 bpad = PADBYTES(al_delta) + (ndelim << 2);
1446
1447 bf->bf_next = NULL;
1448 bf->bf_lastfrm->bf_desc->ds_link = 0;
1449
1450 /*
1451 * this packet is part of an aggregate
1452 * - remove all descriptors belonging to this frame from
1453 * software queue
1454 * - add it to block ack window
1455 * - set up descriptors for aggregation
1456 */
1457 list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list);
1458 ath_tx_addto_baw(sc, tid, bf);
1459
1460 list_for_each_entry(tbf, &bf_head, list) {
1461 ath9k_hw_set11n_aggr_middle(sc->sc_ah,
1462 tbf->bf_desc, ndelim);
1463 }
1464
1465 /*
1466 * link buffers of this frame to the aggregate
1467 */
1468 list_splice_tail_init(&bf_head, bf_q);
1469 nframes++;
1470
1471 if (bf_prev) {
1472 bf_prev->bf_next = bf;
1473 bf_prev->bf_lastfrm->bf_desc->ds_link = bf->bf_daddr;
1474 }
1475 bf_prev = bf;
1476
1477#ifdef AGGR_NOSHORT
1478 /*
1479 * terminate aggregation on a small packet boundary
1480 */
1481 if (bf->bf_frmlen < ATH_AGGR_MINPLEN) {
1482 status = ATH_AGGR_SHORTPKT;
1483 break;
1484 }
1485#endif
1486 } while (!list_empty(&tid->buf_q));
1487
1488 bf_first->bf_al = al;
1489 bf_first->bf_nframes = nframes;
1490 *bf_last = bf_prev;
1491 return status;
1492#undef PADBYTES
1493}
1494
1495/*
1496 * process pending frames possibly doing a-mpdu aggregation
1497 * NB: must be called with txq lock held
1498 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001499static void ath_tx_sched_aggr(struct ath_softc *sc,
1500 struct ath_txq *txq, struct ath_atx_tid *tid)
1501{
1502 struct ath_buf *bf, *tbf, *bf_last, *bf_lastaggr = NULL;
1503 enum ATH_AGGR_STATUS status;
1504 struct list_head bf_q;
1505 struct aggr_rifs_param param = {0, 0, 0, 0, NULL};
1506 int prev_frames = 0;
1507
1508 do {
1509 if (list_empty(&tid->buf_q))
1510 return;
1511
1512 INIT_LIST_HEAD(&bf_q);
1513
1514 status = ath_tx_form_aggr(sc, tid, &bf_q, &bf_lastaggr, &param,
1515 &prev_frames);
1516
1517 /*
1518 * no frames picked up to be aggregated; block-ack
1519 * window is not open
1520 */
1521 if (list_empty(&bf_q))
1522 break;
1523
1524 bf = list_first_entry(&bf_q, struct ath_buf, list);
1525 bf_last = list_entry(bf_q.prev, struct ath_buf, list);
1526 bf->bf_lastbf = bf_last;
1527
1528 /*
1529 * if only one frame, send as non-aggregate
1530 */
1531 if (bf->bf_nframes == 1) {
1532 ASSERT(bf->bf_lastfrm == bf_last);
1533
Sujithcd3d39a2008-08-11 14:03:34 +05301534 bf->bf_state.bf_type &= ~BUF_AGGR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001535 /*
1536 * clear aggr bits for every descriptor
1537 * XXX TODO: is there a way to optimize it?
1538 */
1539 list_for_each_entry(tbf, &bf_q, list) {
1540 ath9k_hw_clr11n_aggr(sc->sc_ah, tbf->bf_desc);
1541 }
1542
1543 ath_buf_set_rate(sc, bf);
1544 ath_tx_txqaddbuf(sc, txq, &bf_q);
1545 continue;
1546 }
1547
1548 /*
1549 * setup first desc with rate and aggr info
1550 */
Sujithcd3d39a2008-08-11 14:03:34 +05301551 bf->bf_state.bf_type |= BUF_AGGR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001552 ath_buf_set_rate(sc, bf);
1553 ath9k_hw_set11n_aggr_first(sc->sc_ah, bf->bf_desc, bf->bf_al);
1554
1555 /*
1556 * anchor last frame of aggregate correctly
1557 */
1558 ASSERT(bf_lastaggr);
1559 ASSERT(bf_lastaggr->bf_lastfrm == bf_last);
1560 tbf = bf_lastaggr;
1561 ath9k_hw_set11n_aggr_last(sc->sc_ah, tbf->bf_desc);
1562
1563 /* XXX: We don't enter into this loop, consider removing this */
1564 while (!list_empty(&bf_q) && !list_is_last(&tbf->list, &bf_q)) {
1565 tbf = list_entry(tbf->list.next, struct ath_buf, list);
1566 ath9k_hw_set11n_aggr_last(sc->sc_ah, tbf->bf_desc);
1567 }
1568
1569 txq->axq_aggr_depth++;
1570
1571 /*
1572 * Normal aggregate, queue to hardware
1573 */
1574 ath_tx_txqaddbuf(sc, txq, &bf_q);
1575
1576 } while (txq->axq_depth < ATH_AGGR_MIN_QDEPTH &&
1577 status != ATH_AGGR_BAW_CLOSED);
1578}
1579
1580/* Called with txq lock held */
1581
1582static void ath_tid_drain(struct ath_softc *sc,
1583 struct ath_txq *txq,
Sujithb5aa9bf2008-10-29 10:13:31 +05301584 struct ath_atx_tid *tid)
1585
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001586{
1587 struct ath_buf *bf;
1588 struct list_head bf_head;
1589 INIT_LIST_HEAD(&bf_head);
1590
1591 for (;;) {
1592 if (list_empty(&tid->buf_q))
1593 break;
1594 bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
1595
1596 list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list);
1597
1598 /* update baw for software retried frame */
Sujithcd3d39a2008-08-11 14:03:34 +05301599 if (bf_isretried(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001600 ath_tx_update_baw(sc, tid, bf->bf_seqno);
1601
1602 /*
1603 * do not indicate packets while holding txq spinlock.
1604 * unlock is intentional here
1605 */
Sujithb5aa9bf2008-10-29 10:13:31 +05301606 spin_unlock(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001607
1608 /* complete this sub-frame */
1609 ath_tx_complete_buf(sc, bf, &bf_head, 0, 0);
1610
Sujithb5aa9bf2008-10-29 10:13:31 +05301611 spin_lock(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001612 }
1613
1614 /*
1615 * TODO: For frame(s) that are in the retry state, we will reuse the
1616 * sequence number(s) without setting the retry bit. The
1617 * alternative is to give up on these and BAR the receiver's window
1618 * forward.
1619 */
1620 tid->seq_next = tid->seq_start;
1621 tid->baw_tail = tid->baw_head;
1622}
1623
1624/*
1625 * Drain all pending buffers
1626 * NB: must be called with txq lock held
1627 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001628static void ath_txq_drain_pending_buffers(struct ath_softc *sc,
Sujithb5aa9bf2008-10-29 10:13:31 +05301629 struct ath_txq *txq)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001630{
1631 struct ath_atx_ac *ac, *ac_tmp;
1632 struct ath_atx_tid *tid, *tid_tmp;
1633
1634 list_for_each_entry_safe(ac, ac_tmp, &txq->axq_acq, list) {
1635 list_del(&ac->list);
1636 ac->sched = false;
1637 list_for_each_entry_safe(tid, tid_tmp, &ac->tid_q, list) {
1638 list_del(&tid->list);
1639 tid->sched = false;
Sujithb5aa9bf2008-10-29 10:13:31 +05301640 ath_tid_drain(sc, txq, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001641 }
1642 }
1643}
1644
Sujith528f0c62008-10-29 10:14:26 +05301645static void ath_tx_setup_buffer(struct ath_softc *sc, struct ath_buf *bf,
Sujith8f93b8b2008-11-18 09:10:42 +05301646 struct sk_buff *skb,
Sujith528f0c62008-10-29 10:14:26 +05301647 struct ath_tx_control *txctl)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001648{
Sujith528f0c62008-10-29 10:14:26 +05301649 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1650 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001651 struct ath_tx_info_priv *tx_info_priv;
Sujith528f0c62008-10-29 10:14:26 +05301652 int hdrlen;
1653 __le16 fc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001654
Sujitha8efee42008-11-18 09:07:30 +05301655 tx_info_priv = kzalloc(sizeof(*tx_info_priv), GFP_KERNEL);
1656 tx_info->rate_driver_data[0] = tx_info_priv;
Sujith528f0c62008-10-29 10:14:26 +05301657 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1658 fc = hdr->frame_control;
Jouni Malinene022edb2008-08-22 17:31:33 +03001659
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001660 ATH_TXBUF_RESET(bf);
Sujith528f0c62008-10-29 10:14:26 +05301661
1662 /* Frame type */
1663
1664 bf->bf_frmlen = skb->len + FCS_LEN - (hdrlen & 3);
Sujithcd3d39a2008-08-11 14:03:34 +05301665
1666 ieee80211_is_data(fc) ?
1667 (bf->bf_state.bf_type |= BUF_DATA) :
1668 (bf->bf_state.bf_type &= ~BUF_DATA);
1669 ieee80211_is_back_req(fc) ?
1670 (bf->bf_state.bf_type |= BUF_BAR) :
1671 (bf->bf_state.bf_type &= ~BUF_BAR);
1672 ieee80211_is_pspoll(fc) ?
1673 (bf->bf_state.bf_type |= BUF_PSPOLL) :
1674 (bf->bf_state.bf_type &= ~BUF_PSPOLL);
Sujith672840a2008-08-11 14:05:08 +05301675 (sc->sc_flags & SC_OP_PREAMBLE_SHORT) ?
Sujithcd3d39a2008-08-11 14:03:34 +05301676 (bf->bf_state.bf_type |= BUF_SHORT_PREAMBLE) :
1677 (bf->bf_state.bf_type &= ~BUF_SHORT_PREAMBLE);
Sujitha8efee42008-11-18 09:07:30 +05301678 (sc->hw->conf.ht.enabled && !is_pae(skb) &&
Sujith528f0c62008-10-29 10:14:26 +05301679 (tx_info->flags & IEEE80211_TX_CTL_AMPDU)) ?
1680 (bf->bf_state.bf_type |= BUF_HT) :
1681 (bf->bf_state.bf_type &= ~BUF_HT);
Sujithcd3d39a2008-08-11 14:03:34 +05301682
Sujith528f0c62008-10-29 10:14:26 +05301683 bf->bf_flags = setup_tx_flags(sc, skb, txctl->txq);
1684
1685 /* Crypto */
1686
1687 bf->bf_keytype = get_hw_crypto_keytype(skb);
1688
1689 if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR) {
1690 bf->bf_frmlen += tx_info->control.hw_key->icv_len;
1691 bf->bf_keyix = tx_info->control.hw_key->hw_key_idx;
1692 } else {
1693 bf->bf_keyix = ATH9K_TXKEYIX_INVALID;
1694 }
1695
Sujith528f0c62008-10-29 10:14:26 +05301696 /* Assign seqno, tidno */
1697
1698 if (bf_isht(bf) && (sc->sc_flags & SC_OP_TXAGGR))
1699 assign_aggr_tid_seqno(skb, bf);
1700
1701 /* DMA setup */
1702
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001703 bf->bf_mpdu = skb;
Sujith528f0c62008-10-29 10:14:26 +05301704 bf->bf_dmacontext = pci_map_single(sc->pdev, skb->data,
1705 skb->len, PCI_DMA_TODEVICE);
1706 bf->bf_buf_addr = bf->bf_dmacontext;
1707}
1708
1709/* FIXME: tx power */
1710static void ath_tx_start_dma(struct ath_softc *sc, struct ath_buf *bf,
Sujith528f0c62008-10-29 10:14:26 +05301711 struct ath_tx_control *txctl)
1712{
1713 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
1714 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1715 struct ath_node *an = NULL;
1716 struct list_head bf_head;
1717 struct ath_desc *ds;
1718 struct ath_atx_tid *tid;
1719 struct ath_hal *ah = sc->sc_ah;
1720 int frm_type;
1721
Sujith528f0c62008-10-29 10:14:26 +05301722 frm_type = get_hw_packet_type(skb);
1723
1724 INIT_LIST_HEAD(&bf_head);
1725 list_add_tail(&bf->list, &bf_head);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001726
1727 /* setup descriptor */
Sujith528f0c62008-10-29 10:14:26 +05301728
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001729 ds = bf->bf_desc;
1730 ds->ds_link = 0;
1731 ds->ds_data = bf->bf_buf_addr;
1732
Sujith528f0c62008-10-29 10:14:26 +05301733 /* Formulate first tx descriptor with tx controls */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001734
Sujith528f0c62008-10-29 10:14:26 +05301735 ath9k_hw_set11n_txdesc(ah, ds, bf->bf_frmlen, frm_type, MAX_RATE_POWER,
1736 bf->bf_keyix, bf->bf_keytype, bf->bf_flags);
1737
1738 ath9k_hw_filltxdesc(ah, ds,
Sujith8f93b8b2008-11-18 09:10:42 +05301739 skb->len, /* segment length */
1740 true, /* first segment */
1741 true, /* last segment */
1742 ds); /* first descriptor */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001743
1744 bf->bf_lastfrm = bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001745
Sujith528f0c62008-10-29 10:14:26 +05301746 spin_lock_bh(&txctl->txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001747
John W. Linvillef1617962008-10-31 16:45:15 -04001748 if (bf_isht(bf) && (sc->sc_flags & SC_OP_TXAGGR) &&
1749 tx_info->control.sta) {
1750 an = (struct ath_node *)tx_info->control.sta->drv_priv;
1751 tid = ATH_AN_2_TID(an, bf->bf_tidno);
1752
Sujith528f0c62008-10-29 10:14:26 +05301753 if (ath_aggr_query(sc, an, bf->bf_tidno)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001754 /*
1755 * Try aggregation if it's a unicast data frame
1756 * and the destination is HT capable.
1757 */
Sujith528f0c62008-10-29 10:14:26 +05301758 ath_tx_send_ampdu(sc, tid, &bf_head, txctl);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001759 } else {
1760 /*
Sujith528f0c62008-10-29 10:14:26 +05301761 * Send this frame as regular when ADDBA
1762 * exchange is neither complete nor pending.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001763 */
Sujith528f0c62008-10-29 10:14:26 +05301764 ath_tx_send_normal(sc, txctl->txq,
1765 tid, &bf_head);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001766 }
1767 } else {
1768 bf->bf_lastbf = bf;
1769 bf->bf_nframes = 1;
Sujith528f0c62008-10-29 10:14:26 +05301770
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001771 ath_buf_set_rate(sc, bf);
Sujith528f0c62008-10-29 10:14:26 +05301772 ath_tx_txqaddbuf(sc, txctl->txq, &bf_head);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001773 }
Sujith528f0c62008-10-29 10:14:26 +05301774
1775 spin_unlock_bh(&txctl->txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001776}
1777
Sujith528f0c62008-10-29 10:14:26 +05301778int ath_tx_start(struct ath_softc *sc, struct sk_buff *skb,
1779 struct ath_tx_control *txctl)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001780{
Sujith528f0c62008-10-29 10:14:26 +05301781 struct ath_buf *bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001782
Sujith528f0c62008-10-29 10:14:26 +05301783 /* Check if a tx buffer is available */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001784
Sujith528f0c62008-10-29 10:14:26 +05301785 bf = ath_tx_get_buffer(sc);
1786 if (!bf) {
Sujith04bd4632008-11-28 22:18:05 +05301787 DPRINTF(sc, ATH_DBG_XMIT, "TX buffers are full\n");
Sujith528f0c62008-10-29 10:14:26 +05301788 return -1;
1789 }
1790
Sujith8f93b8b2008-11-18 09:10:42 +05301791 ath_tx_setup_buffer(sc, bf, skb, txctl);
1792 ath_tx_start_dma(sc, bf, txctl);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001793
Sujith528f0c62008-10-29 10:14:26 +05301794 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001795}
1796
1797/* Initialize TX queue and h/w */
1798
1799int ath_tx_init(struct ath_softc *sc, int nbufs)
1800{
1801 int error = 0;
1802
1803 do {
1804 spin_lock_init(&sc->sc_txbuflock);
1805
1806 /* Setup tx descriptors */
1807 error = ath_descdma_setup(sc, &sc->sc_txdma, &sc->sc_txbuf,
Sujith556bb8f2008-08-11 14:03:53 +05301808 "tx", nbufs, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001809 if (error != 0) {
1810 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301811 "Failed to allocate tx descriptors: %d\n",
1812 error);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001813 break;
1814 }
1815
1816 /* XXX allocate beacon state together with vap */
1817 error = ath_descdma_setup(sc, &sc->sc_bdma, &sc->sc_bbuf,
1818 "beacon", ATH_BCBUF, 1);
1819 if (error != 0) {
1820 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301821 "Failed to allocate beacon descriptors: %d\n",
1822 error);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001823 break;
1824 }
1825
1826 } while (0);
1827
1828 if (error != 0)
1829 ath_tx_cleanup(sc);
1830
1831 return error;
1832}
1833
1834/* Reclaim all tx queue resources */
1835
1836int ath_tx_cleanup(struct ath_softc *sc)
1837{
1838 /* cleanup beacon descriptors */
1839 if (sc->sc_bdma.dd_desc_len != 0)
1840 ath_descdma_cleanup(sc, &sc->sc_bdma, &sc->sc_bbuf);
1841
1842 /* cleanup tx descriptors */
1843 if (sc->sc_txdma.dd_desc_len != 0)
1844 ath_descdma_cleanup(sc, &sc->sc_txdma, &sc->sc_txbuf);
1845
1846 return 0;
1847}
1848
1849/* Setup a h/w transmit queue */
1850
1851struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype)
1852{
1853 struct ath_hal *ah = sc->sc_ah;
Sujithea9880f2008-08-07 10:53:10 +05301854 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001855 int qnum;
1856
Luis R. Rodriguez0345f372008-10-03 15:45:25 -07001857 memset(&qi, 0, sizeof(qi));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001858 qi.tqi_subtype = subtype;
1859 qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT;
1860 qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
1861 qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT;
Sujithea9880f2008-08-07 10:53:10 +05301862 qi.tqi_physCompBuf = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001863
1864 /*
1865 * Enable interrupts only for EOL and DESC conditions.
1866 * We mark tx descriptors to receive a DESC interrupt
1867 * when a tx queue gets deep; otherwise waiting for the
1868 * EOL to reap descriptors. Note that this is done to
1869 * reduce interrupt load and this only defers reaping
1870 * descriptors, never transmitting frames. Aside from
1871 * reducing interrupts this also permits more concurrency.
1872 * The only potential downside is if the tx queue backs
1873 * up in which case the top half of the kernel may backup
1874 * due to a lack of tx descriptors.
1875 *
1876 * The UAPSD queue is an exception, since we take a desc-
1877 * based intr on the EOSP frames.
1878 */
1879 if (qtype == ATH9K_TX_QUEUE_UAPSD)
1880 qi.tqi_qflags = TXQ_FLAG_TXDESCINT_ENABLE;
1881 else
1882 qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE |
1883 TXQ_FLAG_TXDESCINT_ENABLE;
1884 qnum = ath9k_hw_setuptxqueue(ah, qtype, &qi);
1885 if (qnum == -1) {
1886 /*
1887 * NB: don't print a message, this happens
1888 * normally on parts with too few tx queues
1889 */
1890 return NULL;
1891 }
1892 if (qnum >= ARRAY_SIZE(sc->sc_txq)) {
1893 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301894 "qnum %u out of range, max %u!\n",
1895 qnum, (unsigned int)ARRAY_SIZE(sc->sc_txq));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001896 ath9k_hw_releasetxqueue(ah, qnum);
1897 return NULL;
1898 }
1899 if (!ATH_TXQ_SETUP(sc, qnum)) {
1900 struct ath_txq *txq = &sc->sc_txq[qnum];
1901
1902 txq->axq_qnum = qnum;
1903 txq->axq_link = NULL;
1904 INIT_LIST_HEAD(&txq->axq_q);
1905 INIT_LIST_HEAD(&txq->axq_acq);
1906 spin_lock_init(&txq->axq_lock);
1907 txq->axq_depth = 0;
1908 txq->axq_aggr_depth = 0;
1909 txq->axq_totalqueued = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001910 txq->axq_linkbuf = NULL;
1911 sc->sc_txqsetup |= 1<<qnum;
1912 }
1913 return &sc->sc_txq[qnum];
1914}
1915
1916/* Reclaim resources for a setup queue */
1917
1918void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq)
1919{
1920 ath9k_hw_releasetxqueue(sc->sc_ah, txq->axq_qnum);
1921 sc->sc_txqsetup &= ~(1<<txq->axq_qnum);
1922}
1923
1924/*
1925 * Setup a hardware data transmit queue for the specified
1926 * access control. The hal may not support all requested
1927 * queues in which case it will return a reference to a
1928 * previously setup queue. We record the mapping from ac's
1929 * to h/w queues for use by ath_tx_start and also track
1930 * the set of h/w queues being used to optimize work in the
1931 * transmit interrupt handler and related routines.
1932 */
1933
1934int ath_tx_setup(struct ath_softc *sc, int haltype)
1935{
1936 struct ath_txq *txq;
1937
1938 if (haltype >= ARRAY_SIZE(sc->sc_haltype2q)) {
1939 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301940 "HAL AC %u out of range, max %zu!\n",
1941 haltype, ARRAY_SIZE(sc->sc_haltype2q));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001942 return 0;
1943 }
1944 txq = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, haltype);
1945 if (txq != NULL) {
1946 sc->sc_haltype2q[haltype] = txq->axq_qnum;
1947 return 1;
1948 } else
1949 return 0;
1950}
1951
1952int ath_tx_get_qnum(struct ath_softc *sc, int qtype, int haltype)
1953{
1954 int qnum;
1955
1956 switch (qtype) {
1957 case ATH9K_TX_QUEUE_DATA:
1958 if (haltype >= ARRAY_SIZE(sc->sc_haltype2q)) {
1959 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301960 "HAL AC %u out of range, max %zu!\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001961 haltype, ARRAY_SIZE(sc->sc_haltype2q));
1962 return -1;
1963 }
1964 qnum = sc->sc_haltype2q[haltype];
1965 break;
1966 case ATH9K_TX_QUEUE_BEACON:
1967 qnum = sc->sc_bhalq;
1968 break;
1969 case ATH9K_TX_QUEUE_CAB:
1970 qnum = sc->sc_cabq->axq_qnum;
1971 break;
1972 default:
1973 qnum = -1;
1974 }
1975 return qnum;
1976}
1977
Sujith528f0c62008-10-29 10:14:26 +05301978/* Get a transmit queue, if available */
1979
1980struct ath_txq *ath_test_get_txq(struct ath_softc *sc, struct sk_buff *skb)
1981{
1982 struct ath_txq *txq = NULL;
1983 int qnum;
1984
1985 qnum = ath_get_hal_qnum(skb_get_queue_mapping(skb), sc);
1986 txq = &sc->sc_txq[qnum];
1987
1988 spin_lock_bh(&txq->axq_lock);
1989
1990 /* Try to avoid running out of descriptors */
1991 if (txq->axq_depth >= (ATH_TXBUF - 20)) {
1992 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301993 "TX queue: %d is full, depth: %d\n",
1994 qnum, txq->axq_depth);
Sujith528f0c62008-10-29 10:14:26 +05301995 ieee80211_stop_queue(sc->hw, skb_get_queue_mapping(skb));
1996 txq->stopped = 1;
1997 spin_unlock_bh(&txq->axq_lock);
1998 return NULL;
1999 }
2000
2001 spin_unlock_bh(&txq->axq_lock);
2002
2003 return txq;
2004}
2005
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002006/* Update parameters for a transmit queue */
2007
Sujithea9880f2008-08-07 10:53:10 +05302008int ath_txq_update(struct ath_softc *sc, int qnum,
2009 struct ath9k_tx_queue_info *qinfo)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002010{
2011 struct ath_hal *ah = sc->sc_ah;
2012 int error = 0;
Sujithea9880f2008-08-07 10:53:10 +05302013 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002014
2015 if (qnum == sc->sc_bhalq) {
2016 /*
2017 * XXX: for beacon queue, we just save the parameter.
2018 * It will be picked up by ath_beaconq_config when
2019 * it's necessary.
2020 */
Sujithea9880f2008-08-07 10:53:10 +05302021 sc->sc_beacon_qi = *qinfo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002022 return 0;
2023 }
2024
2025 ASSERT(sc->sc_txq[qnum].axq_qnum == qnum);
2026
Sujithea9880f2008-08-07 10:53:10 +05302027 ath9k_hw_get_txq_props(ah, qnum, &qi);
2028 qi.tqi_aifs = qinfo->tqi_aifs;
2029 qi.tqi_cwmin = qinfo->tqi_cwmin;
2030 qi.tqi_cwmax = qinfo->tqi_cwmax;
2031 qi.tqi_burstTime = qinfo->tqi_burstTime;
2032 qi.tqi_readyTime = qinfo->tqi_readyTime;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002033
Sujithea9880f2008-08-07 10:53:10 +05302034 if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002035 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05302036 "Unable to update hardware queue %u!\n", qnum);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002037 error = -EIO;
2038 } else {
2039 ath9k_hw_resettxqueue(ah, qnum); /* push to h/w */
2040 }
2041
2042 return error;
2043}
2044
2045int ath_cabq_update(struct ath_softc *sc)
2046{
Sujithea9880f2008-08-07 10:53:10 +05302047 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002048 int qnum = sc->sc_cabq->axq_qnum;
2049 struct ath_beacon_config conf;
2050
Sujithea9880f2008-08-07 10:53:10 +05302051 ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002052 /*
2053 * Ensure the readytime % is within the bounds.
2054 */
2055 if (sc->sc_config.cabqReadytime < ATH9K_READY_TIME_LO_BOUND)
2056 sc->sc_config.cabqReadytime = ATH9K_READY_TIME_LO_BOUND;
2057 else if (sc->sc_config.cabqReadytime > ATH9K_READY_TIME_HI_BOUND)
2058 sc->sc_config.cabqReadytime = ATH9K_READY_TIME_HI_BOUND;
2059
2060 ath_get_beaconconfig(sc, ATH_IF_ID_ANY, &conf);
2061 qi.tqi_readyTime =
2062 (conf.beacon_interval * sc->sc_config.cabqReadytime) / 100;
2063 ath_txq_update(sc, qnum, &qi);
2064
2065 return 0;
2066}
2067
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002068/* Deferred processing of transmit interrupt */
2069
2070void ath_tx_tasklet(struct ath_softc *sc)
2071{
Sujith1fe11322008-08-26 08:11:06 +05302072 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002073 u32 qcumask = ((1 << ATH9K_NUM_TX_QUEUES) - 1);
2074
2075 ath9k_hw_gettxintrtxqs(sc->sc_ah, &qcumask);
2076
2077 /*
2078 * Process each active queue.
2079 */
2080 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
2081 if (ATH_TXQ_SETUP(sc, i) && (qcumask & (1 << i)))
Sujith1fe11322008-08-26 08:11:06 +05302082 ath_tx_processq(sc, &sc->sc_txq[i]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002083 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002084}
2085
2086void ath_tx_draintxq(struct ath_softc *sc,
2087 struct ath_txq *txq, bool retry_tx)
2088{
2089 struct ath_buf *bf, *lastbf;
2090 struct list_head bf_head;
2091
2092 INIT_LIST_HEAD(&bf_head);
2093
2094 /*
2095 * NB: this assumes output has been stopped and
2096 * we do not need to block ath_tx_tasklet
2097 */
2098 for (;;) {
2099 spin_lock_bh(&txq->axq_lock);
2100
2101 if (list_empty(&txq->axq_q)) {
2102 txq->axq_link = NULL;
2103 txq->axq_linkbuf = NULL;
2104 spin_unlock_bh(&txq->axq_lock);
2105 break;
2106 }
2107
2108 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
2109
2110 if (bf->bf_status & ATH_BUFSTATUS_STALE) {
2111 list_del(&bf->list);
2112 spin_unlock_bh(&txq->axq_lock);
2113
2114 spin_lock_bh(&sc->sc_txbuflock);
2115 list_add_tail(&bf->list, &sc->sc_txbuf);
2116 spin_unlock_bh(&sc->sc_txbuflock);
2117 continue;
2118 }
2119
2120 lastbf = bf->bf_lastbf;
2121 if (!retry_tx)
2122 lastbf->bf_desc->ds_txstat.ts_flags =
2123 ATH9K_TX_SW_ABORTED;
2124
2125 /* remove ath_buf's of the same mpdu from txq */
2126 list_cut_position(&bf_head, &txq->axq_q, &lastbf->list);
2127 txq->axq_depth--;
2128
2129 spin_unlock_bh(&txq->axq_lock);
2130
Sujithcd3d39a2008-08-11 14:03:34 +05302131 if (bf_isampdu(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002132 ath_tx_complete_aggr_rifs(sc, txq, bf, &bf_head, 0);
2133 else
2134 ath_tx_complete_buf(sc, bf, &bf_head, 0, 0);
2135 }
2136
2137 /* flush any pending frames if aggregation is enabled */
Sujith672840a2008-08-11 14:05:08 +05302138 if (sc->sc_flags & SC_OP_TXAGGR) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002139 if (!retry_tx) {
2140 spin_lock_bh(&txq->axq_lock);
Sujithb5aa9bf2008-10-29 10:13:31 +05302141 ath_txq_drain_pending_buffers(sc, txq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002142 spin_unlock_bh(&txq->axq_lock);
2143 }
2144 }
2145}
2146
2147/* Drain the transmit queues and reclaim resources */
2148
2149void ath_draintxq(struct ath_softc *sc, bool retry_tx)
2150{
2151 /* stop beacon queue. The beacon will be freed when
2152 * we go to INIT state */
Sujith672840a2008-08-11 14:05:08 +05302153 if (!(sc->sc_flags & SC_OP_INVALID)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002154 (void) ath9k_hw_stoptxdma(sc->sc_ah, sc->sc_bhalq);
Sujith04bd4632008-11-28 22:18:05 +05302155 DPRINTF(sc, ATH_DBG_XMIT, "beacon queue %x\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002156 ath9k_hw_gettxbuf(sc->sc_ah, sc->sc_bhalq));
2157 }
2158
2159 ath_drain_txdataq(sc, retry_tx);
2160}
2161
2162u32 ath_txq_depth(struct ath_softc *sc, int qnum)
2163{
2164 return sc->sc_txq[qnum].axq_depth;
2165}
2166
2167u32 ath_txq_aggr_depth(struct ath_softc *sc, int qnum)
2168{
2169 return sc->sc_txq[qnum].axq_aggr_depth;
2170}
2171
Sujithccc75c52008-10-29 10:18:14 +05302172bool ath_tx_aggr_check(struct ath_softc *sc, struct ath_node *an, u8 tidno)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002173{
2174 struct ath_atx_tid *txtid;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002175
Sujith672840a2008-08-11 14:05:08 +05302176 if (!(sc->sc_flags & SC_OP_TXAGGR))
Sujithccc75c52008-10-29 10:18:14 +05302177 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002178
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002179 txtid = ATH_AN_2_TID(an, tidno);
2180
Sujitha37c2c72008-10-29 10:15:40 +05302181 if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
2182 if (!(txtid->state & AGGR_ADDBA_PROGRESS) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002183 (txtid->addba_exchangeattempts < ADDBA_EXCHANGE_ATTEMPTS)) {
2184 txtid->addba_exchangeattempts++;
Sujithccc75c52008-10-29 10:18:14 +05302185 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002186 }
2187 }
2188
Sujithccc75c52008-10-29 10:18:14 +05302189 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002190}
2191
2192/* Start TX aggregation */
2193
Sujithb5aa9bf2008-10-29 10:13:31 +05302194int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
2195 u16 tid, u16 *ssn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002196{
2197 struct ath_atx_tid *txtid;
2198 struct ath_node *an;
2199
Sujithb5aa9bf2008-10-29 10:13:31 +05302200 an = (struct ath_node *)sta->drv_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002201
Sujith672840a2008-08-11 14:05:08 +05302202 if (sc->sc_flags & SC_OP_TXAGGR) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002203 txtid = ATH_AN_2_TID(an, tid);
Sujitha37c2c72008-10-29 10:15:40 +05302204 txtid->state |= AGGR_ADDBA_PROGRESS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002205 ath_tx_pause_tid(sc, txtid);
2206 }
2207
2208 return 0;
2209}
2210
2211/* Stop tx aggregation */
2212
Sujithb5aa9bf2008-10-29 10:13:31 +05302213int ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002214{
Sujithb5aa9bf2008-10-29 10:13:31 +05302215 struct ath_node *an = (struct ath_node *)sta->drv_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002216
2217 ath_tx_aggr_teardown(sc, an, tid);
2218 return 0;
2219}
2220
Sujith8469cde2008-10-29 10:19:28 +05302221/* Resume tx aggregation */
2222
2223void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
2224{
2225 struct ath_atx_tid *txtid;
2226 struct ath_node *an;
2227
2228 an = (struct ath_node *)sta->drv_priv;
2229
2230 if (sc->sc_flags & SC_OP_TXAGGR) {
2231 txtid = ATH_AN_2_TID(an, tid);
2232 txtid->baw_size =
2233 IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
2234 txtid->state |= AGGR_ADDBA_COMPLETE;
2235 txtid->state &= ~AGGR_ADDBA_PROGRESS;
2236 ath_tx_resume_tid(sc, txtid);
2237 }
2238}
2239
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002240/*
2241 * Performs transmit side cleanup when TID changes from aggregated to
2242 * unaggregated.
2243 * - Pause the TID and mark cleanup in progress
2244 * - Discard all retry frames from the s/w queue.
2245 */
2246
Sujithb5aa9bf2008-10-29 10:13:31 +05302247void ath_tx_aggr_teardown(struct ath_softc *sc, struct ath_node *an, u8 tid)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002248{
2249 struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid);
2250 struct ath_txq *txq = &sc->sc_txq[txtid->ac->qnum];
2251 struct ath_buf *bf;
2252 struct list_head bf_head;
2253 INIT_LIST_HEAD(&bf_head);
2254
Sujitha37c2c72008-10-29 10:15:40 +05302255 if (txtid->state & AGGR_CLEANUP) /* cleanup is in progress */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002256 return;
2257
Sujitha37c2c72008-10-29 10:15:40 +05302258 if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002259 txtid->addba_exchangeattempts = 0;
2260 return;
2261 }
2262
2263 /* TID must be paused first */
2264 ath_tx_pause_tid(sc, txtid);
2265
2266 /* drop all software retried frames and mark this TID */
2267 spin_lock_bh(&txq->axq_lock);
2268 while (!list_empty(&txtid->buf_q)) {
2269 bf = list_first_entry(&txtid->buf_q, struct ath_buf, list);
Sujithcd3d39a2008-08-11 14:03:34 +05302270 if (!bf_isretried(bf)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002271 /*
2272 * NB: it's based on the assumption that
2273 * software retried frame will always stay
2274 * at the head of software queue.
2275 */
2276 break;
2277 }
2278 list_cut_position(&bf_head,
2279 &txtid->buf_q, &bf->bf_lastfrm->list);
2280 ath_tx_update_baw(sc, txtid, bf->bf_seqno);
2281
2282 /* complete this sub-frame */
2283 ath_tx_complete_buf(sc, bf, &bf_head, 0, 0);
2284 }
2285
2286 if (txtid->baw_head != txtid->baw_tail) {
2287 spin_unlock_bh(&txq->axq_lock);
Sujitha37c2c72008-10-29 10:15:40 +05302288 txtid->state |= AGGR_CLEANUP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002289 } else {
Sujitha37c2c72008-10-29 10:15:40 +05302290 txtid->state &= ~AGGR_ADDBA_COMPLETE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002291 txtid->addba_exchangeattempts = 0;
2292 spin_unlock_bh(&txq->axq_lock);
2293 ath_tx_flush_tid(sc, txtid);
2294 }
2295}
2296
2297/*
2298 * Tx scheduling logic
2299 * NB: must be called with txq lock held
2300 */
2301
2302void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
2303{
2304 struct ath_atx_ac *ac;
2305 struct ath_atx_tid *tid;
2306
2307 /* nothing to schedule */
2308 if (list_empty(&txq->axq_acq))
2309 return;
2310 /*
2311 * get the first node/ac pair on the queue
2312 */
2313 ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac, list);
2314 list_del(&ac->list);
2315 ac->sched = false;
2316
2317 /*
2318 * process a single tid per destination
2319 */
2320 do {
2321 /* nothing to schedule */
2322 if (list_empty(&ac->tid_q))
2323 return;
2324
2325 tid = list_first_entry(&ac->tid_q, struct ath_atx_tid, list);
2326 list_del(&tid->list);
2327 tid->sched = false;
2328
2329 if (tid->paused) /* check next tid to keep h/w busy */
2330 continue;
2331
Sujith43453b32008-10-29 10:14:52 +05302332 if ((txq->axq_depth % 2) == 0)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002333 ath_tx_sched_aggr(sc, txq, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002334
2335 /*
2336 * add tid to round-robin queue if more frames
2337 * are pending for the tid
2338 */
2339 if (!list_empty(&tid->buf_q))
2340 ath_tx_queue_tid(txq, tid);
2341
2342 /* only schedule one TID at a time */
2343 break;
2344 } while (!list_empty(&ac->tid_q));
2345
2346 /*
2347 * schedule AC if more TIDs need processing
2348 */
2349 if (!list_empty(&ac->tid_q)) {
2350 /*
2351 * add dest ac to txq if not already added
2352 */
2353 if (!ac->sched) {
2354 ac->sched = true;
2355 list_add_tail(&ac->list, &txq->axq_acq);
2356 }
2357 }
2358}
2359
2360/* Initialize per-node transmit state */
2361
2362void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an)
2363{
Sujithc5170162008-10-29 10:13:59 +05302364 struct ath_atx_tid *tid;
2365 struct ath_atx_ac *ac;
2366 int tidno, acno;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002367
Sujithc5170162008-10-29 10:13:59 +05302368 /*
2369 * Init per tid tx state
2370 */
2371 for (tidno = 0, tid = &an->an_aggr.tx.tid[tidno];
2372 tidno < WME_NUM_TID;
2373 tidno++, tid++) {
2374 tid->an = an;
2375 tid->tidno = tidno;
2376 tid->seq_start = tid->seq_next = 0;
2377 tid->baw_size = WME_MAX_BA;
2378 tid->baw_head = tid->baw_tail = 0;
2379 tid->sched = false;
2380 tid->paused = false;
Sujitha37c2c72008-10-29 10:15:40 +05302381 tid->state &= ~AGGR_CLEANUP;
Sujithc5170162008-10-29 10:13:59 +05302382 INIT_LIST_HEAD(&tid->buf_q);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002383
Sujithc5170162008-10-29 10:13:59 +05302384 acno = TID_TO_WME_AC(tidno);
2385 tid->ac = &an->an_aggr.tx.ac[acno];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002386
Sujithc5170162008-10-29 10:13:59 +05302387 /* ADDBA state */
Sujitha37c2c72008-10-29 10:15:40 +05302388 tid->state &= ~AGGR_ADDBA_COMPLETE;
2389 tid->state &= ~AGGR_ADDBA_PROGRESS;
2390 tid->addba_exchangeattempts = 0;
Sujithc5170162008-10-29 10:13:59 +05302391 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002392
Sujithc5170162008-10-29 10:13:59 +05302393 /*
2394 * Init per ac tx state
2395 */
2396 for (acno = 0, ac = &an->an_aggr.tx.ac[acno];
2397 acno < WME_NUM_AC; acno++, ac++) {
2398 ac->sched = false;
2399 INIT_LIST_HEAD(&ac->tid_q);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002400
Sujithc5170162008-10-29 10:13:59 +05302401 switch (acno) {
2402 case WME_AC_BE:
2403 ac->qnum = ath_tx_get_qnum(sc,
2404 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
2405 break;
2406 case WME_AC_BK:
2407 ac->qnum = ath_tx_get_qnum(sc,
2408 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BK);
2409 break;
2410 case WME_AC_VI:
2411 ac->qnum = ath_tx_get_qnum(sc,
2412 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VI);
2413 break;
2414 case WME_AC_VO:
2415 ac->qnum = ath_tx_get_qnum(sc,
2416 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VO);
2417 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002418 }
2419 }
2420}
2421
2422/* Cleanupthe pending buffers for the node. */
2423
Sujithb5aa9bf2008-10-29 10:13:31 +05302424void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002425{
2426 int i;
2427 struct ath_atx_ac *ac, *ac_tmp;
2428 struct ath_atx_tid *tid, *tid_tmp;
2429 struct ath_txq *txq;
2430 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
2431 if (ATH_TXQ_SETUP(sc, i)) {
2432 txq = &sc->sc_txq[i];
2433
Sujithb5aa9bf2008-10-29 10:13:31 +05302434 spin_lock(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002435
2436 list_for_each_entry_safe(ac,
2437 ac_tmp, &txq->axq_acq, list) {
2438 tid = list_first_entry(&ac->tid_q,
2439 struct ath_atx_tid, list);
2440 if (tid && tid->an != an)
2441 continue;
2442 list_del(&ac->list);
2443 ac->sched = false;
2444
2445 list_for_each_entry_safe(tid,
2446 tid_tmp, &ac->tid_q, list) {
2447 list_del(&tid->list);
2448 tid->sched = false;
Sujithb5aa9bf2008-10-29 10:13:31 +05302449 ath_tid_drain(sc, txq, tid);
Sujitha37c2c72008-10-29 10:15:40 +05302450 tid->state &= ~AGGR_ADDBA_COMPLETE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002451 tid->addba_exchangeattempts = 0;
Sujitha37c2c72008-10-29 10:15:40 +05302452 tid->state &= ~AGGR_CLEANUP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002453 }
2454 }
2455
Sujithb5aa9bf2008-10-29 10:13:31 +05302456 spin_unlock(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002457 }
2458 }
2459}
2460
Jouni Malinene022edb2008-08-22 17:31:33 +03002461void ath_tx_cabq(struct ath_softc *sc, struct sk_buff *skb)
2462{
2463 int hdrlen, padsize;
2464 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2465 struct ath_tx_control txctl;
2466
Sujith528f0c62008-10-29 10:14:26 +05302467 memset(&txctl, 0, sizeof(struct ath_tx_control));
2468
Jouni Malinene022edb2008-08-22 17:31:33 +03002469 /*
2470 * As a temporary workaround, assign seq# here; this will likely need
2471 * to be cleaned up to work better with Beacon transmission and virtual
2472 * BSSes.
2473 */
2474 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
2475 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2476 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
2477 sc->seq_no += 0x10;
2478 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
2479 hdr->seq_ctrl |= cpu_to_le16(sc->seq_no);
2480 }
2481
2482 /* Add the padding after the header if this is not already done */
2483 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
2484 if (hdrlen & 3) {
2485 padsize = hdrlen % 4;
2486 if (skb_headroom(skb) < padsize) {
Sujith04bd4632008-11-28 22:18:05 +05302487 DPRINTF(sc, ATH_DBG_XMIT, "TX CABQ padding failed\n");
Jouni Malinene022edb2008-08-22 17:31:33 +03002488 dev_kfree_skb_any(skb);
2489 return;
2490 }
2491 skb_push(skb, padsize);
2492 memmove(skb->data, skb->data + padsize, hdrlen);
2493 }
2494
Sujith528f0c62008-10-29 10:14:26 +05302495 txctl.txq = sc->sc_cabq;
2496
Sujith04bd4632008-11-28 22:18:05 +05302497 DPRINTF(sc, ATH_DBG_XMIT, "transmitting CABQ packet, skb: %p\n", skb);
Jouni Malinene022edb2008-08-22 17:31:33 +03002498
Sujith528f0c62008-10-29 10:14:26 +05302499 if (ath_tx_start(sc, skb, &txctl) != 0) {
Sujith04bd4632008-11-28 22:18:05 +05302500 DPRINTF(sc, ATH_DBG_XMIT, "CABQ TX failed\n");
Sujith528f0c62008-10-29 10:14:26 +05302501 goto exit;
Jouni Malinene022edb2008-08-22 17:31:33 +03002502 }
Jouni Malinene022edb2008-08-22 17:31:33 +03002503
Sujith528f0c62008-10-29 10:14:26 +05302504 return;
2505exit:
2506 dev_kfree_skb_any(skb);
2507}