blob: baf5cb9d967ed6cdae756e5ee75f1173103f7cb0 [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,
86 "%s: txq depth = %d\n", __func__, txq->axq_depth);
87
88 if (txq->axq_link == NULL) {
89 ath9k_hw_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr);
90 DPRINTF(sc, ATH_DBG_XMIT,
91 "%s: TXDP[%u] = %llx (%p)\n",
92 __func__, txq->axq_qnum,
93 ito64(bf->bf_daddr), bf->bf_desc);
94 } else {
95 *txq->axq_link = bf->bf_daddr;
96 DPRINTF(sc, ATH_DBG_XMIT, "%s: link[%u] (%p)=%llx (%p)\n",
97 __func__,
98 txq->axq_qnum, txq->axq_link,
99 ito64(bf->bf_daddr), bf->bf_desc);
100 }
101 txq->axq_link = &(bf->bf_lastbf->bf_desc->ds_link);
102 ath9k_hw_txstart(ah, txq->axq_qnum);
103}
104
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700105/* Check if it's okay to send out aggregates */
106
Sujitha37c2c72008-10-29 10:15:40 +0530107static int ath_aggr_query(struct ath_softc *sc, struct ath_node *an, u8 tidno)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700108{
109 struct ath_atx_tid *tid;
110 tid = ATH_AN_2_TID(an, tidno);
111
Sujitha37c2c72008-10-29 10:15:40 +0530112 if (tid->state & AGGR_ADDBA_COMPLETE ||
113 tid->state & AGGR_ADDBA_PROGRESS)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700114 return 1;
115 else
116 return 0;
117}
118
Sujith528f0c62008-10-29 10:14:26 +0530119/* Calculate Atheros packet type from IEEE80211 packet header */
120
121static enum ath9k_pkt_type get_hw_packet_type(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700122{
Sujith528f0c62008-10-29 10:14:26 +0530123 struct ieee80211_hdr *hdr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700124 enum ath9k_pkt_type htype;
125 __le16 fc;
126
Sujith528f0c62008-10-29 10:14:26 +0530127 hdr = (struct ieee80211_hdr *)skb->data;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700128 fc = hdr->frame_control;
129
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700130 if (ieee80211_is_beacon(fc))
131 htype = ATH9K_PKT_TYPE_BEACON;
132 else if (ieee80211_is_probe_resp(fc))
133 htype = ATH9K_PKT_TYPE_PROBE_RESP;
134 else if (ieee80211_is_atim(fc))
135 htype = ATH9K_PKT_TYPE_ATIM;
136 else if (ieee80211_is_pspoll(fc))
137 htype = ATH9K_PKT_TYPE_PSPOLL;
138 else
139 htype = ATH9K_PKT_TYPE_NORMAL;
140
141 return htype;
142}
143
Sujitha8efee42008-11-18 09:07:30 +0530144static bool is_pae(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700145{
146 struct ieee80211_hdr *hdr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700147 __le16 fc;
148
149 hdr = (struct ieee80211_hdr *)skb->data;
150 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200151
Sujitha8efee42008-11-18 09:07:30 +0530152 if (ieee80211_is_data(fc)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700153 if (ieee80211_is_nullfunc(fc) ||
Sujith528f0c62008-10-29 10:14:26 +0530154 /* Port Access Entity (IEEE 802.1X) */
155 (skb->protocol == cpu_to_be16(ETH_P_PAE))) {
Sujitha8efee42008-11-18 09:07:30 +0530156 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700157 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700158 }
159
Sujitha8efee42008-11-18 09:07:30 +0530160 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700161}
162
Sujith528f0c62008-10-29 10:14:26 +0530163static int get_hw_crypto_keytype(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700164{
Sujith528f0c62008-10-29 10:14:26 +0530165 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
166
167 if (tx_info->control.hw_key) {
168 if (tx_info->control.hw_key->alg == ALG_WEP)
169 return ATH9K_KEY_TYPE_WEP;
170 else if (tx_info->control.hw_key->alg == ALG_TKIP)
171 return ATH9K_KEY_TYPE_TKIP;
172 else if (tx_info->control.hw_key->alg == ALG_CCMP)
173 return ATH9K_KEY_TYPE_AES;
174 }
175
176 return ATH9K_KEY_TYPE_CLEAR;
177}
178
179static void setup_rate_retries(struct ath_softc *sc, struct sk_buff *skb)
180{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700181 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Sujitha8efee42008-11-18 09:07:30 +0530182 struct ieee80211_tx_rate *rates = tx_info->control.rates;
Sujith528f0c62008-10-29 10:14:26 +0530183 struct ieee80211_hdr *hdr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700184 __le16 fc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700185
Sujith528f0c62008-10-29 10:14:26 +0530186 hdr = (struct ieee80211_hdr *)skb->data;
187 fc = hdr->frame_control;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700188
Sujith14cc7092008-08-26 08:10:49 +0530189 if (ieee80211_has_morefrags(fc) ||
190 (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG)) {
Sujitha8efee42008-11-18 09:07:30 +0530191 rates[1].count = rates[2].count = rates[3].count = 0;
192 rates[1].idx = rates[2].idx = rates[3].idx = 0;
Sujith14cc7092008-08-26 08:10:49 +0530193 /* reset tries but keep rate index */
Sujitha8efee42008-11-18 09:07:30 +0530194 rates[0].count = ATH_TXMAXTRY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700195 }
Sujith528f0c62008-10-29 10:14:26 +0530196}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700197
Sujith528f0c62008-10-29 10:14:26 +0530198/* Called only when tx aggregation is enabled and HT is supported */
199
200static void assign_aggr_tid_seqno(struct sk_buff *skb,
201 struct ath_buf *bf)
202{
203 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
204 struct ieee80211_hdr *hdr;
205 struct ath_node *an;
206 struct ath_atx_tid *tid;
207 __le16 fc;
208 u8 *qc;
209
210 if (!tx_info->control.sta)
211 return;
212
213 an = (struct ath_node *)tx_info->control.sta->drv_priv;
214 hdr = (struct ieee80211_hdr *)skb->data;
215 fc = hdr->frame_control;
216
217 /* Get tidno */
218
219 if (ieee80211_is_data_qos(fc)) {
220 qc = ieee80211_get_qos_ctl(hdr);
221 bf->bf_tidno = qc[0] & 0xf;
Sujith98deeea2008-08-11 14:05:46 +0530222 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700223
Sujith528f0c62008-10-29 10:14:26 +0530224 /* Get seqno */
225
Sujitha8efee42008-11-18 09:07:30 +0530226 if (ieee80211_is_data(fc) && !is_pae(skb)) {
Sujith528f0c62008-10-29 10:14:26 +0530227 /* For HT capable stations, we save tidno for later use.
228 * We also override seqno set by upper layer with the one
229 * in tx aggregation state.
230 *
231 * If fragmentation is on, the sequence number is
232 * not overridden, since it has been
233 * incremented by the fragmentation routine.
234 *
235 * FIXME: check if the fragmentation threshold exceeds
236 * IEEE80211 max.
237 */
238 tid = ATH_AN_2_TID(an, bf->bf_tidno);
239 hdr->seq_ctrl = cpu_to_le16(tid->seq_next <<
240 IEEE80211_SEQ_SEQ_SHIFT);
241 bf->bf_seqno = tid->seq_next;
242 INCR(tid->seq_next, IEEE80211_SEQ_MAX);
243 }
244}
245
246static int setup_tx_flags(struct ath_softc *sc, struct sk_buff *skb,
247 struct ath_txq *txq)
248{
249 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
250 int flags = 0;
251
252 flags |= ATH9K_TXDESC_CLRDMASK; /* needed for crypto errors */
253 flags |= ATH9K_TXDESC_INTREQ;
254
255 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
256 flags |= ATH9K_TXDESC_NOACK;
257 if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
258 flags |= ATH9K_TXDESC_RTSENA;
259
260 return flags;
261}
262
263static struct ath_buf *ath_tx_get_buffer(struct ath_softc *sc)
264{
265 struct ath_buf *bf = NULL;
266
267 spin_lock_bh(&sc->sc_txbuflock);
268
269 if (unlikely(list_empty(&sc->sc_txbuf))) {
270 spin_unlock_bh(&sc->sc_txbuflock);
271 return NULL;
272 }
273
274 bf = list_first_entry(&sc->sc_txbuf, struct ath_buf, list);
275 list_del(&bf->list);
276
277 spin_unlock_bh(&sc->sc_txbuflock);
278
279 return bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700280}
281
282/* To complete a chain of buffers associated a frame */
283
284static void ath_tx_complete_buf(struct ath_softc *sc,
285 struct ath_buf *bf,
286 struct list_head *bf_q,
287 int txok, int sendbar)
288{
289 struct sk_buff *skb = bf->bf_mpdu;
290 struct ath_xmit_status tx_status;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700291
292 /*
293 * Set retry information.
294 * NB: Don't use the information in the descriptor, because the frame
295 * could be software retried.
296 */
297 tx_status.retries = bf->bf_retries;
298 tx_status.flags = 0;
299
300 if (sendbar)
301 tx_status.flags = ATH_TX_BAR;
302
303 if (!txok) {
304 tx_status.flags |= ATH_TX_ERROR;
305
Sujithcd3d39a2008-08-11 14:03:34 +0530306 if (bf_isxretried(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700307 tx_status.flags |= ATH_TX_XRETRY;
308 }
Sujith102e0572008-10-29 10:15:16 +0530309
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700310 /* Unmap this frame */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700311 pci_unmap_single(sc->pdev,
Sujithff9b6622008-08-14 13:27:16 +0530312 bf->bf_dmacontext,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700313 skb->len,
314 PCI_DMA_TODEVICE);
315 /* complete this frame */
Sujith528f0c62008-10-29 10:14:26 +0530316 ath_tx_complete(sc, skb, &tx_status);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700317
318 /*
319 * Return the list of ath_buf of this mpdu to free queue
320 */
321 spin_lock_bh(&sc->sc_txbuflock);
322 list_splice_tail_init(bf_q, &sc->sc_txbuf);
323 spin_unlock_bh(&sc->sc_txbuflock);
324}
325
326/*
327 * queue up a dest/ac pair for tx scheduling
328 * NB: must be called with txq lock held
329 */
330
331static void ath_tx_queue_tid(struct ath_txq *txq, struct ath_atx_tid *tid)
332{
333 struct ath_atx_ac *ac = tid->ac;
334
335 /*
336 * if tid is paused, hold off
337 */
338 if (tid->paused)
339 return;
340
341 /*
342 * add tid to ac atmost once
343 */
344 if (tid->sched)
345 return;
346
347 tid->sched = true;
348 list_add_tail(&tid->list, &ac->tid_q);
349
350 /*
351 * add node ac to txq atmost once
352 */
353 if (ac->sched)
354 return;
355
356 ac->sched = true;
357 list_add_tail(&ac->list, &txq->axq_acq);
358}
359
360/* pause a tid */
361
362static void ath_tx_pause_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
363{
364 struct ath_txq *txq = &sc->sc_txq[tid->ac->qnum];
365
366 spin_lock_bh(&txq->axq_lock);
367
368 tid->paused++;
369
370 spin_unlock_bh(&txq->axq_lock);
371}
372
373/* resume a tid and schedule aggregate */
374
375void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
376{
377 struct ath_txq *txq = &sc->sc_txq[tid->ac->qnum];
378
379 ASSERT(tid->paused > 0);
380 spin_lock_bh(&txq->axq_lock);
381
382 tid->paused--;
383
384 if (tid->paused > 0)
385 goto unlock;
386
387 if (list_empty(&tid->buf_q))
388 goto unlock;
389
390 /*
391 * Add this TID to scheduler and try to send out aggregates
392 */
393 ath_tx_queue_tid(txq, tid);
394 ath_txq_schedule(sc, txq);
395unlock:
396 spin_unlock_bh(&txq->axq_lock);
397}
398
399/* Compute the number of bad frames */
400
Sujithb5aa9bf2008-10-29 10:13:31 +0530401static int ath_tx_num_badfrms(struct ath_softc *sc, struct ath_buf *bf,
402 int txok)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700403{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700404 struct ath_buf *bf_last = bf->bf_lastbf;
405 struct ath_desc *ds = bf_last->bf_desc;
406 u16 seq_st = 0;
407 u32 ba[WME_BA_BMP_SIZE >> 5];
408 int ba_index;
409 int nbad = 0;
410 int isaggr = 0;
411
Sujithb5aa9bf2008-10-29 10:13:31 +0530412 if (ds->ds_txstat.ts_flags == ATH9K_TX_SW_ABORTED)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700413 return 0;
414
Sujithcd3d39a2008-08-11 14:03:34 +0530415 isaggr = bf_isaggr(bf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700416 if (isaggr) {
417 seq_st = ATH_DS_BA_SEQ(ds);
418 memcpy(ba, ATH_DS_BA_BITMAP(ds), WME_BA_BMP_SIZE >> 3);
419 }
420
421 while (bf) {
422 ba_index = ATH_BA_INDEX(seq_st, bf->bf_seqno);
423 if (!txok || (isaggr && !ATH_BA_ISSET(ba, ba_index)))
424 nbad++;
425
426 bf = bf->bf_next;
427 }
428
429 return nbad;
430}
431
432static void ath_tx_set_retry(struct ath_softc *sc, struct ath_buf *bf)
433{
434 struct sk_buff *skb;
435 struct ieee80211_hdr *hdr;
436
Sujithcd3d39a2008-08-11 14:03:34 +0530437 bf->bf_state.bf_type |= BUF_RETRY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700438 bf->bf_retries++;
439
440 skb = bf->bf_mpdu;
441 hdr = (struct ieee80211_hdr *)skb->data;
442 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_RETRY);
443}
444
445/* Update block ack window */
446
Sujith102e0572008-10-29 10:15:16 +0530447static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
448 int seqno)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700449{
450 int index, cindex;
451
452 index = ATH_BA_INDEX(tid->seq_start, seqno);
453 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
454
455 tid->tx_buf[cindex] = NULL;
456
457 while (tid->baw_head != tid->baw_tail && !tid->tx_buf[tid->baw_head]) {
458 INCR(tid->seq_start, IEEE80211_SEQ_MAX);
459 INCR(tid->baw_head, ATH_TID_MAX_BUFS);
460 }
461}
462
463/*
464 * ath_pkt_dur - compute packet duration (NB: not NAV)
465 *
466 * rix - rate index
467 * pktlen - total bytes (delims + data + fcs + pads + pad delims)
468 * width - 0 for 20 MHz, 1 for 40 MHz
469 * half_gi - to use 4us v/s 3.6 us for symbol time
470 */
471
Sujith102e0572008-10-29 10:15:16 +0530472static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, struct ath_buf *bf,
473 int width, int half_gi, bool shortPreamble)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700474{
475 const struct ath9k_rate_table *rt = sc->sc_currates;
476 u32 nbits, nsymbits, duration, nsymbols;
477 u8 rc;
478 int streams, pktlen;
479
Sujithcd3d39a2008-08-11 14:03:34 +0530480 pktlen = bf_isaggr(bf) ? bf->bf_al : bf->bf_frmlen;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700481 rc = rt->info[rix].rateCode;
482
483 /*
484 * for legacy rates, use old function to compute packet duration
485 */
486 if (!IS_HT_RATE(rc))
Sujith102e0572008-10-29 10:15:16 +0530487 return ath9k_hw_computetxtime(sc->sc_ah, rt, pktlen, rix,
488 shortPreamble);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700489 /*
490 * find number of symbols: PLCP + data
491 */
492 nbits = (pktlen << 3) + OFDM_PLCP_BITS;
493 nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
494 nsymbols = (nbits + nsymbits - 1) / nsymbits;
495
496 if (!half_gi)
497 duration = SYMBOL_TIME(nsymbols);
498 else
499 duration = SYMBOL_TIME_HALFGI(nsymbols);
500
501 /*
502 * addup duration for legacy/ht training and signal fields
503 */
504 streams = HT_RC_2_STREAMS(rc);
505 duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
Sujith102e0572008-10-29 10:15:16 +0530506
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700507 return duration;
508}
509
510/* Rate module function to set rate related fields in tx descriptor */
511
512static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
513{
514 struct ath_hal *ah = sc->sc_ah;
515 const struct ath9k_rate_table *rt;
516 struct ath_desc *ds = bf->bf_desc;
517 struct ath_desc *lastds = bf->bf_lastbf->bf_desc;
518 struct ath9k_11n_rate_series series[4];
Sujith43453b32008-10-29 10:14:52 +0530519 int i, flags, rtsctsena = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700520 u32 ctsduration = 0;
521 u8 rix = 0, cix, ctsrate = 0;
Sujith528f0c62008-10-29 10:14:26 +0530522 struct ath_node *an = NULL;
523 struct sk_buff *skb;
524 struct ieee80211_tx_info *tx_info;
Sujitha8efee42008-11-18 09:07:30 +0530525 struct ieee80211_tx_rate *rates;
Sujith528f0c62008-10-29 10:14:26 +0530526
527 skb = (struct sk_buff *)bf->bf_mpdu;
528 tx_info = IEEE80211_SKB_CB(skb);
Sujitha8efee42008-11-18 09:07:30 +0530529 rates = tx_info->rate_driver_data[0];
Sujith528f0c62008-10-29 10:14:26 +0530530
531 if (tx_info->control.sta)
532 an = (struct ath_node *)tx_info->control.sta->drv_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700533
534 /*
535 * get the cix for the lowest valid rix.
536 */
537 rt = sc->sc_currates;
Sujitha8efee42008-11-18 09:07:30 +0530538 for (i = 3; i >= 0; i--) {
539 if (rates[i].count) {
540 rix = rates[i].idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700541 break;
542 }
543 }
544 flags = (bf->bf_flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA));
545 cix = rt->info[rix].controlRate;
546
547 /*
548 * If 802.11g protection is enabled, determine whether
549 * to use RTS/CTS or just CTS. Note that this is only
550 * done for OFDM/HT unicast frames.
551 */
552 if (sc->sc_protmode != PROT_M_NONE &&
553 (rt->info[rix].phy == PHY_OFDM ||
554 rt->info[rix].phy == PHY_HT) &&
555 (bf->bf_flags & ATH9K_TXDESC_NOACK) == 0) {
556 if (sc->sc_protmode == PROT_M_RTSCTS)
557 flags = ATH9K_TXDESC_RTSENA;
558 else if (sc->sc_protmode == PROT_M_CTSONLY)
559 flags = ATH9K_TXDESC_CTSENA;
560
561 cix = rt->info[sc->sc_protrix].controlRate;
562 rtsctsena = 1;
563 }
564
565 /* For 11n, the default behavior is to enable RTS for
566 * hw retried frames. We enable the global flag here and
567 * let rate series flags determine which rates will actually
568 * use RTS.
569 */
Sujithcd3d39a2008-08-11 14:03:34 +0530570 if ((ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) && bf_isdata(bf)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700571 /*
572 * 802.11g protection not needed, use our default behavior
573 */
574 if (!rtsctsena)
575 flags = ATH9K_TXDESC_RTSENA;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700576 }
577
578 /*
579 * Set protection if aggregate protection on
580 */
581 if (sc->sc_config.ath_aggr_prot &&
Sujithcd3d39a2008-08-11 14:03:34 +0530582 (!bf_isaggr(bf) || (bf_isaggr(bf) && bf->bf_al < 8192))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700583 flags = ATH9K_TXDESC_RTSENA;
584 cix = rt->info[sc->sc_protrix].controlRate;
585 rtsctsena = 1;
586 }
587
588 /*
589 * For AR5416 - RTS cannot be followed by a frame larger than 8K.
590 */
Sujith102e0572008-10-29 10:15:16 +0530591 if (bf_isaggr(bf) && (bf->bf_al > ah->ah_caps.rts_aggr_limit)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700592 /*
593 * Ensure that in the case of SM Dynamic power save
594 * while we are bursting the second aggregate the
595 * RTS is cleared.
596 */
597 flags &= ~(ATH9K_TXDESC_RTSENA);
598 }
599
600 /*
601 * CTS transmit rate is derived from the transmit rate
602 * by looking in the h/w rate table. We must also factor
603 * in whether or not a short preamble is to be used.
Sujith102e0572008-10-29 10:15:16 +0530604 * NB: cix is set above where RTS/CTS is enabled
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700605 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700606 BUG_ON(cix == 0xff);
607 ctsrate = rt->info[cix].rateCode |
Sujithcd3d39a2008-08-11 14:03:34 +0530608 (bf_isshpreamble(bf) ? rt->info[cix].shortPreamble : 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700609
610 /*
611 * Setup HAL rate series
612 */
Luis R. Rodriguez0345f372008-10-03 15:45:25 -0700613 memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700614
615 for (i = 0; i < 4; i++) {
Sujitha8efee42008-11-18 09:07:30 +0530616 if (!rates[i].count)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700617 continue;
618
Sujitha8efee42008-11-18 09:07:30 +0530619 rix = rates[i].idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700620
621 series[i].Rate = rt->info[rix].rateCode |
Sujithcd3d39a2008-08-11 14:03:34 +0530622 (bf_isshpreamble(bf) ? rt->info[rix].shortPreamble : 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700623
Sujitha8efee42008-11-18 09:07:30 +0530624 series[i].Tries = rates[i].count;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700625
626 series[i].RateFlags = (
Sujitha8efee42008-11-18 09:07:30 +0530627 (rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) ?
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700628 ATH9K_RATESERIES_RTS_CTS : 0) |
Sujitha8efee42008-11-18 09:07:30 +0530629 ((rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ?
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700630 ATH9K_RATESERIES_2040 : 0) |
Sujitha8efee42008-11-18 09:07:30 +0530631 ((rates[i].flags & IEEE80211_TX_RC_SHORT_GI) ?
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700632 ATH9K_RATESERIES_HALFGI : 0);
633
Sujith102e0572008-10-29 10:15:16 +0530634 series[i].PktDuration = ath_pkt_duration(sc, rix, bf,
Sujitha8efee42008-11-18 09:07:30 +0530635 (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) != 0,
636 (rates[i].flags & IEEE80211_TX_RC_SHORT_GI),
Sujith102e0572008-10-29 10:15:16 +0530637 bf_isshpreamble(bf));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700638
Sujith102e0572008-10-29 10:15:16 +0530639 if (bf_isht(bf) && an)
640 series[i].ChSel = ath_chainmask_sel_logic(sc, an);
Sujith43453b32008-10-29 10:14:52 +0530641 else
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700642 series[i].ChSel = sc->sc_tx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700643
644 if (rtsctsena)
645 series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700646 }
647
648 /*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700649 * set dur_update_en for l-sig computation except for PS-Poll frames
650 */
651 ath9k_hw_set11n_ratescenario(ah, ds, lastds,
Sujithcd3d39a2008-08-11 14:03:34 +0530652 !bf_ispspoll(bf),
653 ctsrate,
654 ctsduration,
655 series, 4, flags);
Sujith102e0572008-10-29 10:15:16 +0530656
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700657 if (sc->sc_config.ath_aggr_prot && flags)
658 ath9k_hw_set11n_burstduration(ah, ds, 8192);
659}
660
661/*
662 * Function to send a normal HT (non-AMPDU) frame
663 * NB: must be called with txq lock held
664 */
665
666static int ath_tx_send_normal(struct ath_softc *sc,
667 struct ath_txq *txq,
668 struct ath_atx_tid *tid,
669 struct list_head *bf_head)
670{
671 struct ath_buf *bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700672
673 BUG_ON(list_empty(bf_head));
674
675 bf = list_first_entry(bf_head, struct ath_buf, list);
Sujithcd3d39a2008-08-11 14:03:34 +0530676 bf->bf_state.bf_type &= ~BUF_AMPDU; /* regular HT frame */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700677
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700678 /* update starting sequence number for subsequent ADDBA request */
679 INCR(tid->seq_start, IEEE80211_SEQ_MAX);
680
681 /* Queue to h/w without aggregation */
682 bf->bf_nframes = 1;
683 bf->bf_lastbf = bf->bf_lastfrm; /* one single frame */
684 ath_buf_set_rate(sc, bf);
685 ath_tx_txqaddbuf(sc, txq, bf_head);
686
687 return 0;
688}
689
690/* flush tid's software queue and send frames as non-ampdu's */
691
692static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
693{
694 struct ath_txq *txq = &sc->sc_txq[tid->ac->qnum];
695 struct ath_buf *bf;
696 struct list_head bf_head;
697 INIT_LIST_HEAD(&bf_head);
698
699 ASSERT(tid->paused > 0);
700 spin_lock_bh(&txq->axq_lock);
701
702 tid->paused--;
703
704 if (tid->paused > 0) {
705 spin_unlock_bh(&txq->axq_lock);
706 return;
707 }
708
709 while (!list_empty(&tid->buf_q)) {
710 bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
Sujithcd3d39a2008-08-11 14:03:34 +0530711 ASSERT(!bf_isretried(bf));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700712 list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list);
713 ath_tx_send_normal(sc, txq, tid, &bf_head);
714 }
715
716 spin_unlock_bh(&txq->axq_lock);
717}
718
719/* Completion routine of an aggregate */
720
721static void ath_tx_complete_aggr_rifs(struct ath_softc *sc,
722 struct ath_txq *txq,
723 struct ath_buf *bf,
724 struct list_head *bf_q,
725 int txok)
726{
Sujith528f0c62008-10-29 10:14:26 +0530727 struct ath_node *an = NULL;
728 struct sk_buff *skb;
729 struct ieee80211_tx_info *tx_info;
730 struct ath_atx_tid *tid = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700731 struct ath_buf *bf_last = bf->bf_lastbf;
732 struct ath_desc *ds = bf_last->bf_desc;
733 struct ath_buf *bf_next, *bf_lastq = NULL;
734 struct list_head bf_head, bf_pending;
735 u16 seq_st = 0;
736 u32 ba[WME_BA_BMP_SIZE >> 5];
737 int isaggr, txfail, txpending, sendbar = 0, needreset = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700738
Sujith528f0c62008-10-29 10:14:26 +0530739 skb = (struct sk_buff *)bf->bf_mpdu;
740 tx_info = IEEE80211_SKB_CB(skb);
741
742 if (tx_info->control.sta) {
743 an = (struct ath_node *)tx_info->control.sta->drv_priv;
744 tid = ATH_AN_2_TID(an, bf->bf_tidno);
745 }
746
Sujithcd3d39a2008-08-11 14:03:34 +0530747 isaggr = bf_isaggr(bf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700748 if (isaggr) {
749 if (txok) {
750 if (ATH_DS_TX_BA(ds)) {
751 /*
752 * extract starting sequence and
753 * block-ack bitmap
754 */
755 seq_st = ATH_DS_BA_SEQ(ds);
756 memcpy(ba,
757 ATH_DS_BA_BITMAP(ds),
758 WME_BA_BMP_SIZE >> 3);
759 } else {
Luis R. Rodriguez0345f372008-10-03 15:45:25 -0700760 memset(ba, 0, WME_BA_BMP_SIZE >> 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700761
762 /*
763 * AR5416 can become deaf/mute when BA
764 * issue happens. Chip needs to be reset.
765 * But AP code may have sychronization issues
766 * when perform internal reset in this routine.
767 * Only enable reset in STA mode for now.
768 */
Sujithb4696c8b2008-08-11 14:04:52 +0530769 if (sc->sc_ah->ah_opmode == ATH9K_M_STA)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700770 needreset = 1;
771 }
772 } else {
Luis R. Rodriguez0345f372008-10-03 15:45:25 -0700773 memset(ba, 0, WME_BA_BMP_SIZE >> 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700774 }
775 }
776
777 INIT_LIST_HEAD(&bf_pending);
778 INIT_LIST_HEAD(&bf_head);
779
780 while (bf) {
781 txfail = txpending = 0;
782 bf_next = bf->bf_next;
783
784 if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, bf->bf_seqno))) {
785 /* transmit completion, subframe is
786 * acked by block ack */
787 } else if (!isaggr && txok) {
788 /* transmit completion */
789 } else {
790
Sujitha37c2c72008-10-29 10:15:40 +0530791 if (!(tid->state & AGGR_CLEANUP) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700792 ds->ds_txstat.ts_flags != ATH9K_TX_SW_ABORTED) {
793 if (bf->bf_retries < ATH_MAX_SW_RETRIES) {
794 ath_tx_set_retry(sc, bf);
795 txpending = 1;
796 } else {
Sujithcd3d39a2008-08-11 14:03:34 +0530797 bf->bf_state.bf_type |= BUF_XRETRY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 txfail = 1;
799 sendbar = 1;
800 }
801 } else {
802 /*
803 * cleanup in progress, just fail
804 * the un-acked sub-frames
805 */
806 txfail = 1;
807 }
808 }
809 /*
810 * Remove ath_buf's of this sub-frame from aggregate queue.
811 */
812 if (bf_next == NULL) { /* last subframe in the aggregate */
813 ASSERT(bf->bf_lastfrm == bf_last);
814
815 /*
816 * The last descriptor of the last sub frame could be
817 * a holding descriptor for h/w. If that's the case,
818 * bf->bf_lastfrm won't be in the bf_q.
819 * Make sure we handle bf_q properly here.
820 */
821
822 if (!list_empty(bf_q)) {
823 bf_lastq = list_entry(bf_q->prev,
824 struct ath_buf, list);
825 list_cut_position(&bf_head,
826 bf_q, &bf_lastq->list);
827 } else {
828 /*
829 * XXX: if the last subframe only has one
830 * descriptor which is also being used as
831 * a holding descriptor. Then the ath_buf
832 * is not in the bf_q at all.
833 */
834 INIT_LIST_HEAD(&bf_head);
835 }
836 } else {
837 ASSERT(!list_empty(bf_q));
838 list_cut_position(&bf_head,
839 bf_q, &bf->bf_lastfrm->list);
840 }
841
842 if (!txpending) {
843 /*
844 * complete the acked-ones/xretried ones; update
845 * block-ack window
846 */
847 spin_lock_bh(&txq->axq_lock);
848 ath_tx_update_baw(sc, tid, bf->bf_seqno);
849 spin_unlock_bh(&txq->axq_lock);
850
851 /* complete this sub-frame */
852 ath_tx_complete_buf(sc, bf, &bf_head, !txfail, sendbar);
853 } else {
854 /*
855 * retry the un-acked ones
856 */
857 /*
858 * XXX: if the last descriptor is holding descriptor,
859 * in order to requeue the frame to software queue, we
860 * need to allocate a new descriptor and
861 * copy the content of holding descriptor to it.
862 */
863 if (bf->bf_next == NULL &&
864 bf_last->bf_status & ATH_BUFSTATUS_STALE) {
865 struct ath_buf *tbf;
866
867 /* allocate new descriptor */
868 spin_lock_bh(&sc->sc_txbuflock);
869 ASSERT(!list_empty((&sc->sc_txbuf)));
870 tbf = list_first_entry(&sc->sc_txbuf,
871 struct ath_buf, list);
872 list_del(&tbf->list);
873 spin_unlock_bh(&sc->sc_txbuflock);
874
875 ATH_TXBUF_RESET(tbf);
876
877 /* copy descriptor content */
878 tbf->bf_mpdu = bf_last->bf_mpdu;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700879 tbf->bf_buf_addr = bf_last->bf_buf_addr;
880 *(tbf->bf_desc) = *(bf_last->bf_desc);
881
882 /* link it to the frame */
883 if (bf_lastq) {
884 bf_lastq->bf_desc->ds_link =
885 tbf->bf_daddr;
886 bf->bf_lastfrm = tbf;
887 ath9k_hw_cleartxdesc(sc->sc_ah,
888 bf->bf_lastfrm->bf_desc);
889 } else {
890 tbf->bf_state = bf_last->bf_state;
891 tbf->bf_lastfrm = tbf;
892 ath9k_hw_cleartxdesc(sc->sc_ah,
893 tbf->bf_lastfrm->bf_desc);
894
895 /* copy the DMA context */
Sujithff9b6622008-08-14 13:27:16 +0530896 tbf->bf_dmacontext =
897 bf_last->bf_dmacontext;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700898 }
899 list_add_tail(&tbf->list, &bf_head);
900 } else {
901 /*
902 * Clear descriptor status words for
903 * software retry
904 */
905 ath9k_hw_cleartxdesc(sc->sc_ah,
Sujithff9b6622008-08-14 13:27:16 +0530906 bf->bf_lastfrm->bf_desc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700907 }
908
909 /*
910 * Put this buffer to the temporary pending
911 * queue to retain ordering
912 */
913 list_splice_tail_init(&bf_head, &bf_pending);
914 }
915
916 bf = bf_next;
917 }
918
Sujitha37c2c72008-10-29 10:15:40 +0530919 if (tid->state & AGGR_CLEANUP) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700920 /* check to see if we're done with cleaning the h/w queue */
921 spin_lock_bh(&txq->axq_lock);
922
923 if (tid->baw_head == tid->baw_tail) {
Sujitha37c2c72008-10-29 10:15:40 +0530924 tid->state &= ~AGGR_ADDBA_COMPLETE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700925 tid->addba_exchangeattempts = 0;
926 spin_unlock_bh(&txq->axq_lock);
927
Sujitha37c2c72008-10-29 10:15:40 +0530928 tid->state &= ~AGGR_CLEANUP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700929
930 /* send buffered frames as singles */
931 ath_tx_flush_tid(sc, tid);
932 } else
933 spin_unlock_bh(&txq->axq_lock);
934
935 return;
936 }
937
938 /*
939 * prepend un-acked frames to the beginning of the pending frame queue
940 */
941 if (!list_empty(&bf_pending)) {
942 spin_lock_bh(&txq->axq_lock);
943 /* Note: we _prepend_, we _do_not_ at to
944 * the end of the queue ! */
945 list_splice(&bf_pending, &tid->buf_q);
946 ath_tx_queue_tid(txq, tid);
947 spin_unlock_bh(&txq->axq_lock);
948 }
949
950 if (needreset)
Sujithf45144e2008-08-11 14:02:53 +0530951 ath_reset(sc, false);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700952
953 return;
954}
955
956/* Process completed xmit descriptors from the specified queue */
957
958static int ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq)
959{
960 struct ath_hal *ah = sc->sc_ah;
961 struct ath_buf *bf, *lastbf, *bf_held = NULL;
962 struct list_head bf_head;
963 struct ath_desc *ds, *tmp_ds;
964 struct sk_buff *skb;
965 struct ieee80211_tx_info *tx_info;
966 struct ath_tx_info_priv *tx_info_priv;
967 int nacked, txok, nbad = 0, isrifs = 0;
968 int status;
969
970 DPRINTF(sc, ATH_DBG_QUEUE,
971 "%s: tx queue %d (%x), link %p\n", __func__,
972 txq->axq_qnum, ath9k_hw_gettxbuf(sc->sc_ah, txq->axq_qnum),
973 txq->axq_link);
974
975 nacked = 0;
976 for (;;) {
977 spin_lock_bh(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700978 if (list_empty(&txq->axq_q)) {
979 txq->axq_link = NULL;
980 txq->axq_linkbuf = NULL;
981 spin_unlock_bh(&txq->axq_lock);
982 break;
983 }
984 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
985
986 /*
987 * There is a race condition that a BH gets scheduled
988 * after sw writes TxE and before hw re-load the last
989 * descriptor to get the newly chained one.
990 * Software must keep the last DONE descriptor as a
991 * holding descriptor - software does so by marking
992 * it with the STALE flag.
993 */
994 bf_held = NULL;
995 if (bf->bf_status & ATH_BUFSTATUS_STALE) {
996 bf_held = bf;
997 if (list_is_last(&bf_held->list, &txq->axq_q)) {
998 /* FIXME:
999 * The holding descriptor is the last
1000 * descriptor in queue. It's safe to remove
1001 * the last holding descriptor in BH context.
1002 */
1003 spin_unlock_bh(&txq->axq_lock);
1004 break;
1005 } else {
1006 /* Lets work with the next buffer now */
1007 bf = list_entry(bf_held->list.next,
1008 struct ath_buf, list);
1009 }
1010 }
1011
1012 lastbf = bf->bf_lastbf;
1013 ds = lastbf->bf_desc; /* NB: last decriptor */
1014
1015 status = ath9k_hw_txprocdesc(ah, ds);
1016 if (status == -EINPROGRESS) {
1017 spin_unlock_bh(&txq->axq_lock);
1018 break;
1019 }
1020 if (bf->bf_desc == txq->axq_lastdsWithCTS)
1021 txq->axq_lastdsWithCTS = NULL;
1022 if (ds == txq->axq_gatingds)
1023 txq->axq_gatingds = NULL;
1024
1025 /*
1026 * Remove ath_buf's of the same transmit unit from txq,
1027 * however leave the last descriptor back as the holding
1028 * descriptor for hw.
1029 */
1030 lastbf->bf_status |= ATH_BUFSTATUS_STALE;
1031 INIT_LIST_HEAD(&bf_head);
1032
1033 if (!list_is_singular(&lastbf->list))
1034 list_cut_position(&bf_head,
1035 &txq->axq_q, lastbf->list.prev);
1036
1037 txq->axq_depth--;
1038
Sujithcd3d39a2008-08-11 14:03:34 +05301039 if (bf_isaggr(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001040 txq->axq_aggr_depth--;
1041
1042 txok = (ds->ds_txstat.ts_status == 0);
1043
1044 spin_unlock_bh(&txq->axq_lock);
1045
1046 if (bf_held) {
1047 list_del(&bf_held->list);
1048 spin_lock_bh(&sc->sc_txbuflock);
1049 list_add_tail(&bf_held->list, &sc->sc_txbuf);
1050 spin_unlock_bh(&sc->sc_txbuflock);
1051 }
1052
Sujithcd3d39a2008-08-11 14:03:34 +05301053 if (!bf_isampdu(bf)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001054 /*
1055 * This frame is sent out as a single frame.
1056 * Use hardware retry status for this frame.
1057 */
1058 bf->bf_retries = ds->ds_txstat.ts_longretry;
1059 if (ds->ds_txstat.ts_status & ATH9K_TXERR_XRETRY)
Sujithcd3d39a2008-08-11 14:03:34 +05301060 bf->bf_state.bf_type |= BUF_XRETRY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001061 nbad = 0;
1062 } else {
1063 nbad = ath_tx_num_badfrms(sc, bf, txok);
1064 }
1065 skb = bf->bf_mpdu;
1066 tx_info = IEEE80211_SKB_CB(skb);
Johannes Berge6a98542008-10-21 12:40:02 +02001067
Sujitha8efee42008-11-18 09:07:30 +05301068 tx_info_priv =
1069 (struct ath_tx_info_priv *)tx_info->rate_driver_data[0];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001070 if (ds->ds_txstat.ts_status & ATH9K_TXERR_FILT)
1071 tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
1072 if ((ds->ds_txstat.ts_status & ATH9K_TXERR_FILT) == 0 &&
1073 (bf->bf_flags & ATH9K_TXDESC_NOACK) == 0) {
1074 if (ds->ds_txstat.ts_status == 0)
1075 nacked++;
1076
Sujithcd3d39a2008-08-11 14:03:34 +05301077 if (bf_isdata(bf)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001078 if (isrifs)
1079 tmp_ds = bf->bf_rifslast->bf_desc;
1080 else
1081 tmp_ds = ds;
1082 memcpy(&tx_info_priv->tx,
1083 &tmp_ds->ds_txstat,
1084 sizeof(tx_info_priv->tx));
1085 tx_info_priv->n_frames = bf->bf_nframes;
1086 tx_info_priv->n_bad_frames = nbad;
1087 }
1088 }
1089
1090 /*
1091 * Complete this transmit unit
1092 */
Sujithcd3d39a2008-08-11 14:03:34 +05301093 if (bf_isampdu(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001094 ath_tx_complete_aggr_rifs(sc, txq, bf, &bf_head, txok);
1095 else
1096 ath_tx_complete_buf(sc, bf, &bf_head, txok, 0);
1097
1098 /* Wake up mac80211 queue */
1099
1100 spin_lock_bh(&txq->axq_lock);
1101 if (txq->stopped && ath_txq_depth(sc, txq->axq_qnum) <=
1102 (ATH_TXBUF - 20)) {
1103 int qnum;
1104 qnum = ath_get_mac80211_qnum(txq->axq_qnum, sc);
1105 if (qnum != -1) {
1106 ieee80211_wake_queue(sc->hw, qnum);
1107 txq->stopped = 0;
1108 }
1109
1110 }
1111
1112 /*
1113 * schedule any pending packets if aggregation is enabled
1114 */
Sujith672840a2008-08-11 14:05:08 +05301115 if (sc->sc_flags & SC_OP_TXAGGR)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001116 ath_txq_schedule(sc, txq);
1117 spin_unlock_bh(&txq->axq_lock);
1118 }
1119 return nacked;
1120}
1121
1122static void ath_tx_stopdma(struct ath_softc *sc, struct ath_txq *txq)
1123{
1124 struct ath_hal *ah = sc->sc_ah;
1125
1126 (void) ath9k_hw_stoptxdma(ah, txq->axq_qnum);
1127 DPRINTF(sc, ATH_DBG_XMIT, "%s: tx queue [%u] %x, link %p\n",
1128 __func__, txq->axq_qnum,
1129 ath9k_hw_gettxbuf(ah, txq->axq_qnum), txq->axq_link);
1130}
1131
1132/* Drain only the data queues */
1133
1134static void ath_drain_txdataq(struct ath_softc *sc, bool retry_tx)
1135{
1136 struct ath_hal *ah = sc->sc_ah;
Sujith102e0572008-10-29 10:15:16 +05301137 int i, status, npend = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001138
Sujith672840a2008-08-11 14:05:08 +05301139 if (!(sc->sc_flags & SC_OP_INVALID)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001140 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1141 if (ATH_TXQ_SETUP(sc, i)) {
1142 ath_tx_stopdma(sc, &sc->sc_txq[i]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001143 /* The TxDMA may not really be stopped.
1144 * Double check the hal tx pending count */
1145 npend += ath9k_hw_numtxpending(ah,
Sujith102e0572008-10-29 10:15:16 +05301146 sc->sc_txq[i].axq_qnum);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001147 }
1148 }
1149 }
1150
1151 if (npend) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001152 /* TxDMA not stopped, reset the hal */
1153 DPRINTF(sc, ATH_DBG_XMIT,
1154 "%s: Unable to stop TxDMA. Reset HAL!\n", __func__);
1155
1156 spin_lock_bh(&sc->sc_resetlock);
Sujithb4696c8b2008-08-11 14:04:52 +05301157 if (!ath9k_hw_reset(ah,
Sujith927e70e2008-08-14 13:26:34 +05301158 sc->sc_ah->ah_curchan,
1159 sc->sc_ht_info.tx_chan_width,
1160 sc->sc_tx_chainmask, sc->sc_rx_chainmask,
1161 sc->sc_ht_extprotspacing, true, &status)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001162
1163 DPRINTF(sc, ATH_DBG_FATAL,
1164 "%s: unable to reset hardware; hal status %u\n",
1165 __func__,
1166 status);
1167 }
1168 spin_unlock_bh(&sc->sc_resetlock);
1169 }
1170
1171 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1172 if (ATH_TXQ_SETUP(sc, i))
1173 ath_tx_draintxq(sc, &sc->sc_txq[i], retry_tx);
1174 }
1175}
1176
1177/* Add a sub-frame to block ack window */
1178
1179static void ath_tx_addto_baw(struct ath_softc *sc,
1180 struct ath_atx_tid *tid,
1181 struct ath_buf *bf)
1182{
1183 int index, cindex;
1184
Sujithcd3d39a2008-08-11 14:03:34 +05301185 if (bf_isretried(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001186 return;
1187
1188 index = ATH_BA_INDEX(tid->seq_start, bf->bf_seqno);
1189 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
1190
1191 ASSERT(tid->tx_buf[cindex] == NULL);
1192 tid->tx_buf[cindex] = bf;
1193
1194 if (index >= ((tid->baw_tail - tid->baw_head) &
1195 (ATH_TID_MAX_BUFS - 1))) {
1196 tid->baw_tail = cindex;
1197 INCR(tid->baw_tail, ATH_TID_MAX_BUFS);
1198 }
1199}
1200
1201/*
1202 * Function to send an A-MPDU
1203 * NB: must be called with txq lock held
1204 */
1205
1206static int ath_tx_send_ampdu(struct ath_softc *sc,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001207 struct ath_atx_tid *tid,
1208 struct list_head *bf_head,
1209 struct ath_tx_control *txctl)
1210{
1211 struct ath_buf *bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001212
1213 BUG_ON(list_empty(bf_head));
1214
1215 bf = list_first_entry(bf_head, struct ath_buf, list);
Sujithcd3d39a2008-08-11 14:03:34 +05301216 bf->bf_state.bf_type |= BUF_AMPDU;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001217
1218 /*
1219 * Do not queue to h/w when any of the following conditions is true:
1220 * - there are pending frames in software queue
1221 * - the TID is currently paused for ADDBA/BAR request
1222 * - seqno is not within block-ack window
1223 * - h/w queue depth exceeds low water mark
1224 */
1225 if (!list_empty(&tid->buf_q) || tid->paused ||
1226 !BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno) ||
Sujith528f0c62008-10-29 10:14:26 +05301227 txctl->txq->axq_depth >= ATH_AGGR_MIN_QDEPTH) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001228 /*
1229 * Add this frame to software queue for scheduling later
1230 * for aggregation.
1231 */
1232 list_splice_tail_init(bf_head, &tid->buf_q);
Sujith528f0c62008-10-29 10:14:26 +05301233 ath_tx_queue_tid(txctl->txq, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001234 return 0;
1235 }
1236
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001237 /* Add sub-frame to BAW */
1238 ath_tx_addto_baw(sc, tid, bf);
1239
1240 /* Queue to h/w without aggregation */
1241 bf->bf_nframes = 1;
1242 bf->bf_lastbf = bf->bf_lastfrm; /* one single frame */
1243 ath_buf_set_rate(sc, bf);
Sujith528f0c62008-10-29 10:14:26 +05301244 ath_tx_txqaddbuf(sc, txctl->txq, bf_head);
Sujith102e0572008-10-29 10:15:16 +05301245
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001246 return 0;
1247}
1248
1249/*
1250 * looks up the rate
1251 * returns aggr limit based on lowest of the rates
1252 */
1253
1254static u32 ath_lookup_rate(struct ath_softc *sc,
Johannes Bergae5eb022008-10-14 16:58:37 +02001255 struct ath_buf *bf,
1256 struct ath_atx_tid *tid)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001257{
Sujitha8efee42008-11-18 09:07:30 +05301258 struct ath_rate_table *rate_table = sc->hw_rate_table[sc->sc_curmode];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001259 const struct ath9k_rate_table *rt = sc->sc_currates;
1260 struct sk_buff *skb;
1261 struct ieee80211_tx_info *tx_info;
Sujitha8efee42008-11-18 09:07:30 +05301262 struct ieee80211_tx_rate *rates;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001263 struct ath_tx_info_priv *tx_info_priv;
1264 u32 max_4ms_framelen, frame_length;
1265 u16 aggr_limit, legacy = 0, maxampdu;
1266 int i;
1267
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001268 skb = (struct sk_buff *)bf->bf_mpdu;
1269 tx_info = IEEE80211_SKB_CB(skb);
Sujitha8efee42008-11-18 09:07:30 +05301270 rates = tx_info->control.rates;
1271 tx_info_priv =
1272 (struct ath_tx_info_priv *)tx_info->rate_driver_data[0];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001273
1274 /*
1275 * Find the lowest frame length among the rate series that will have a
1276 * 4ms transmit duration.
1277 * TODO - TXOP limit needs to be considered.
1278 */
1279 max_4ms_framelen = ATH_AMPDU_LIMIT_MAX;
1280
1281 for (i = 0; i < 4; i++) {
Sujitha8efee42008-11-18 09:07:30 +05301282 if (rates[i].count) {
1283 if (rt->info[rates[i].idx].phy != PHY_HT) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001284 legacy = 1;
1285 break;
1286 }
1287
Sujitha8efee42008-11-18 09:07:30 +05301288 frame_length =
1289 rate_table->info[rates[i].idx].max_4ms_framelen;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001290 max_4ms_framelen = min(max_4ms_framelen, frame_length);
1291 }
1292 }
1293
1294 /*
1295 * limit aggregate size by the minimum rate if rate selected is
1296 * not a probe rate, if rate selected is a probe rate then
1297 * avoid aggregation of this packet.
1298 */
1299 if (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE || legacy)
1300 return 0;
1301
1302 aggr_limit = min(max_4ms_framelen,
1303 (u32)ATH_AMPDU_LIMIT_DEFAULT);
1304
1305 /*
1306 * h/w can accept aggregates upto 16 bit lengths (65535).
1307 * The IE, however can hold upto 65536, which shows up here
1308 * as zero. Ignore 65536 since we are constrained by hw.
1309 */
Johannes Bergae5eb022008-10-14 16:58:37 +02001310 maxampdu = tid->an->maxampdu;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001311 if (maxampdu)
1312 aggr_limit = min(aggr_limit, maxampdu);
1313
1314 return aggr_limit;
1315}
1316
1317/*
1318 * returns the number of delimiters to be added to
1319 * meet the minimum required mpdudensity.
1320 * caller should make sure that the rate is HT rate .
1321 */
1322
1323static int ath_compute_num_delims(struct ath_softc *sc,
Johannes Bergae5eb022008-10-14 16:58:37 +02001324 struct ath_atx_tid *tid,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001325 struct ath_buf *bf,
1326 u16 frmlen)
1327{
1328 const struct ath9k_rate_table *rt = sc->sc_currates;
Sujitha8efee42008-11-18 09:07:30 +05301329 struct sk_buff *skb = bf->bf_mpdu;
1330 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001331 u32 nsymbits, nsymbols, mpdudensity;
1332 u16 minlen;
1333 u8 rc, flags, rix;
1334 int width, half_gi, ndelim, mindelim;
1335
1336 /* Select standard number of delimiters based on frame length alone */
1337 ndelim = ATH_AGGR_GET_NDELIM(frmlen);
1338
1339 /*
1340 * If encryption enabled, hardware requires some more padding between
1341 * subframes.
1342 * TODO - this could be improved to be dependent on the rate.
1343 * The hardware can keep up at lower rates, but not higher rates
1344 */
1345 if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR)
1346 ndelim += ATH_AGGR_ENCRYPTDELIM;
1347
1348 /*
1349 * Convert desired mpdu density from microeconds to bytes based
1350 * on highest rate in rate series (i.e. first rate) to determine
1351 * required minimum length for subframe. Take into account
1352 * whether high rate is 20 or 40Mhz and half or full GI.
1353 */
Johannes Bergae5eb022008-10-14 16:58:37 +02001354 mpdudensity = tid->an->mpdudensity;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001355
1356 /*
1357 * If there is no mpdu density restriction, no further calculation
1358 * is needed.
1359 */
1360 if (mpdudensity == 0)
1361 return ndelim;
1362
Sujitha8efee42008-11-18 09:07:30 +05301363 rix = tx_info->control.rates[0].idx;
1364 flags = tx_info->control.rates[0].flags;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001365 rc = rt->info[rix].rateCode;
Sujitha8efee42008-11-18 09:07:30 +05301366 width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0;
1367 half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001368
1369 if (half_gi)
1370 nsymbols = NUM_SYMBOLS_PER_USEC_HALFGI(mpdudensity);
1371 else
1372 nsymbols = NUM_SYMBOLS_PER_USEC(mpdudensity);
1373
1374 if (nsymbols == 0)
1375 nsymbols = 1;
1376
1377 nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
1378 minlen = (nsymbols * nsymbits) / BITS_PER_BYTE;
1379
1380 /* Is frame shorter than required minimum length? */
1381 if (frmlen < minlen) {
1382 /* Get the minimum number of delimiters required. */
1383 mindelim = (minlen - frmlen) / ATH_AGGR_DELIM_SZ;
1384 ndelim = max(mindelim, ndelim);
1385 }
1386
1387 return ndelim;
1388}
1389
1390/*
1391 * For aggregation from software buffer queue.
1392 * NB: must be called with txq lock held
1393 */
1394
1395static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
1396 struct ath_atx_tid *tid,
1397 struct list_head *bf_q,
1398 struct ath_buf **bf_last,
1399 struct aggr_rifs_param *param,
1400 int *prev_frames)
1401{
1402#define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
1403 struct ath_buf *bf, *tbf, *bf_first, *bf_prev = NULL;
1404 struct list_head bf_head;
1405 int rl = 0, nframes = 0, ndelim;
1406 u16 aggr_limit = 0, al = 0, bpad = 0,
1407 al_delta, h_baw = tid->baw_size / 2;
1408 enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
Sujitha8efee42008-11-18 09:07:30 +05301409 int prev_al = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001410 INIT_LIST_HEAD(&bf_head);
1411
1412 BUG_ON(list_empty(&tid->buf_q));
1413
1414 bf_first = list_first_entry(&tid->buf_q, struct ath_buf, list);
1415
1416 do {
1417 bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
1418
1419 /*
1420 * do not step over block-ack window
1421 */
1422 if (!BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno)) {
1423 status = ATH_AGGR_BAW_CLOSED;
1424 break;
1425 }
1426
1427 if (!rl) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001428 aggr_limit = ath_lookup_rate(sc, bf, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001429 rl = 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001430 }
1431
1432 /*
1433 * do not exceed aggregation limit
1434 */
1435 al_delta = ATH_AGGR_DELIM_SZ + bf->bf_frmlen;
1436
1437 if (nframes && (aggr_limit <
1438 (al + bpad + al_delta + prev_al))) {
1439 status = ATH_AGGR_LIMITED;
1440 break;
1441 }
1442
1443 /*
1444 * do not exceed subframe limit
1445 */
1446 if ((nframes + *prev_frames) >=
1447 min((int)h_baw, ATH_AMPDU_SUBFRAME_DEFAULT)) {
1448 status = ATH_AGGR_LIMITED;
1449 break;
1450 }
1451
1452 /*
1453 * add padding for previous frame to aggregation length
1454 */
1455 al += bpad + al_delta;
1456
1457 /*
1458 * Get the delimiters needed to meet the MPDU
1459 * density for this node.
1460 */
Johannes Bergae5eb022008-10-14 16:58:37 +02001461 ndelim = ath_compute_num_delims(sc, tid, bf_first, bf->bf_frmlen);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001462
1463 bpad = PADBYTES(al_delta) + (ndelim << 2);
1464
1465 bf->bf_next = NULL;
1466 bf->bf_lastfrm->bf_desc->ds_link = 0;
1467
1468 /*
1469 * this packet is part of an aggregate
1470 * - remove all descriptors belonging to this frame from
1471 * software queue
1472 * - add it to block ack window
1473 * - set up descriptors for aggregation
1474 */
1475 list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list);
1476 ath_tx_addto_baw(sc, tid, bf);
1477
1478 list_for_each_entry(tbf, &bf_head, list) {
1479 ath9k_hw_set11n_aggr_middle(sc->sc_ah,
1480 tbf->bf_desc, ndelim);
1481 }
1482
1483 /*
1484 * link buffers of this frame to the aggregate
1485 */
1486 list_splice_tail_init(&bf_head, bf_q);
1487 nframes++;
1488
1489 if (bf_prev) {
1490 bf_prev->bf_next = bf;
1491 bf_prev->bf_lastfrm->bf_desc->ds_link = bf->bf_daddr;
1492 }
1493 bf_prev = bf;
1494
1495#ifdef AGGR_NOSHORT
1496 /*
1497 * terminate aggregation on a small packet boundary
1498 */
1499 if (bf->bf_frmlen < ATH_AGGR_MINPLEN) {
1500 status = ATH_AGGR_SHORTPKT;
1501 break;
1502 }
1503#endif
1504 } while (!list_empty(&tid->buf_q));
1505
1506 bf_first->bf_al = al;
1507 bf_first->bf_nframes = nframes;
1508 *bf_last = bf_prev;
1509 return status;
1510#undef PADBYTES
1511}
1512
1513/*
1514 * process pending frames possibly doing a-mpdu aggregation
1515 * NB: must be called with txq lock held
1516 */
1517
1518static void ath_tx_sched_aggr(struct ath_softc *sc,
1519 struct ath_txq *txq, struct ath_atx_tid *tid)
1520{
1521 struct ath_buf *bf, *tbf, *bf_last, *bf_lastaggr = NULL;
1522 enum ATH_AGGR_STATUS status;
1523 struct list_head bf_q;
1524 struct aggr_rifs_param param = {0, 0, 0, 0, NULL};
1525 int prev_frames = 0;
1526
1527 do {
1528 if (list_empty(&tid->buf_q))
1529 return;
1530
1531 INIT_LIST_HEAD(&bf_q);
1532
1533 status = ath_tx_form_aggr(sc, tid, &bf_q, &bf_lastaggr, &param,
1534 &prev_frames);
1535
1536 /*
1537 * no frames picked up to be aggregated; block-ack
1538 * window is not open
1539 */
1540 if (list_empty(&bf_q))
1541 break;
1542
1543 bf = list_first_entry(&bf_q, struct ath_buf, list);
1544 bf_last = list_entry(bf_q.prev, struct ath_buf, list);
1545 bf->bf_lastbf = bf_last;
1546
1547 /*
1548 * if only one frame, send as non-aggregate
1549 */
1550 if (bf->bf_nframes == 1) {
1551 ASSERT(bf->bf_lastfrm == bf_last);
1552
Sujithcd3d39a2008-08-11 14:03:34 +05301553 bf->bf_state.bf_type &= ~BUF_AGGR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001554 /*
1555 * clear aggr bits for every descriptor
1556 * XXX TODO: is there a way to optimize it?
1557 */
1558 list_for_each_entry(tbf, &bf_q, list) {
1559 ath9k_hw_clr11n_aggr(sc->sc_ah, tbf->bf_desc);
1560 }
1561
1562 ath_buf_set_rate(sc, bf);
1563 ath_tx_txqaddbuf(sc, txq, &bf_q);
1564 continue;
1565 }
1566
1567 /*
1568 * setup first desc with rate and aggr info
1569 */
Sujithcd3d39a2008-08-11 14:03:34 +05301570 bf->bf_state.bf_type |= BUF_AGGR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001571 ath_buf_set_rate(sc, bf);
1572 ath9k_hw_set11n_aggr_first(sc->sc_ah, bf->bf_desc, bf->bf_al);
1573
1574 /*
1575 * anchor last frame of aggregate correctly
1576 */
1577 ASSERT(bf_lastaggr);
1578 ASSERT(bf_lastaggr->bf_lastfrm == bf_last);
1579 tbf = bf_lastaggr;
1580 ath9k_hw_set11n_aggr_last(sc->sc_ah, tbf->bf_desc);
1581
1582 /* XXX: We don't enter into this loop, consider removing this */
1583 while (!list_empty(&bf_q) && !list_is_last(&tbf->list, &bf_q)) {
1584 tbf = list_entry(tbf->list.next, struct ath_buf, list);
1585 ath9k_hw_set11n_aggr_last(sc->sc_ah, tbf->bf_desc);
1586 }
1587
1588 txq->axq_aggr_depth++;
1589
1590 /*
1591 * Normal aggregate, queue to hardware
1592 */
1593 ath_tx_txqaddbuf(sc, txq, &bf_q);
1594
1595 } while (txq->axq_depth < ATH_AGGR_MIN_QDEPTH &&
1596 status != ATH_AGGR_BAW_CLOSED);
1597}
1598
1599/* Called with txq lock held */
1600
1601static void ath_tid_drain(struct ath_softc *sc,
1602 struct ath_txq *txq,
Sujithb5aa9bf2008-10-29 10:13:31 +05301603 struct ath_atx_tid *tid)
1604
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001605{
1606 struct ath_buf *bf;
1607 struct list_head bf_head;
1608 INIT_LIST_HEAD(&bf_head);
1609
1610 for (;;) {
1611 if (list_empty(&tid->buf_q))
1612 break;
1613 bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
1614
1615 list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list);
1616
1617 /* update baw for software retried frame */
Sujithcd3d39a2008-08-11 14:03:34 +05301618 if (bf_isretried(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001619 ath_tx_update_baw(sc, tid, bf->bf_seqno);
1620
1621 /*
1622 * do not indicate packets while holding txq spinlock.
1623 * unlock is intentional here
1624 */
Sujithb5aa9bf2008-10-29 10:13:31 +05301625 spin_unlock(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001626
1627 /* complete this sub-frame */
1628 ath_tx_complete_buf(sc, bf, &bf_head, 0, 0);
1629
Sujithb5aa9bf2008-10-29 10:13:31 +05301630 spin_lock(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001631 }
1632
1633 /*
1634 * TODO: For frame(s) that are in the retry state, we will reuse the
1635 * sequence number(s) without setting the retry bit. The
1636 * alternative is to give up on these and BAR the receiver's window
1637 * forward.
1638 */
1639 tid->seq_next = tid->seq_start;
1640 tid->baw_tail = tid->baw_head;
1641}
1642
1643/*
1644 * Drain all pending buffers
1645 * NB: must be called with txq lock held
1646 */
1647
1648static void ath_txq_drain_pending_buffers(struct ath_softc *sc,
Sujithb5aa9bf2008-10-29 10:13:31 +05301649 struct ath_txq *txq)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001650{
1651 struct ath_atx_ac *ac, *ac_tmp;
1652 struct ath_atx_tid *tid, *tid_tmp;
1653
1654 list_for_each_entry_safe(ac, ac_tmp, &txq->axq_acq, list) {
1655 list_del(&ac->list);
1656 ac->sched = false;
1657 list_for_each_entry_safe(tid, tid_tmp, &ac->tid_q, list) {
1658 list_del(&tid->list);
1659 tid->sched = false;
Sujithb5aa9bf2008-10-29 10:13:31 +05301660 ath_tid_drain(sc, txq, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001661 }
1662 }
1663}
1664
Sujith528f0c62008-10-29 10:14:26 +05301665static void ath_tx_setup_buffer(struct ath_softc *sc, struct ath_buf *bf,
1666 struct sk_buff *skb, struct scatterlist *sg,
1667 struct ath_tx_control *txctl)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001668{
Sujith528f0c62008-10-29 10:14:26 +05301669 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1670 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001671 struct ath_tx_info_priv *tx_info_priv;
Sujith528f0c62008-10-29 10:14:26 +05301672 int hdrlen;
1673 __le16 fc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001674
Sujitha8efee42008-11-18 09:07:30 +05301675 tx_info_priv = kzalloc(sizeof(*tx_info_priv), GFP_KERNEL);
1676 tx_info->rate_driver_data[0] = tx_info_priv;
Sujith528f0c62008-10-29 10:14:26 +05301677 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1678 fc = hdr->frame_control;
Jouni Malinene022edb2008-08-22 17:31:33 +03001679
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001680 ATH_TXBUF_RESET(bf);
Sujith528f0c62008-10-29 10:14:26 +05301681
1682 /* Frame type */
1683
1684 bf->bf_frmlen = skb->len + FCS_LEN - (hdrlen & 3);
Sujithcd3d39a2008-08-11 14:03:34 +05301685
1686 ieee80211_is_data(fc) ?
1687 (bf->bf_state.bf_type |= BUF_DATA) :
1688 (bf->bf_state.bf_type &= ~BUF_DATA);
1689 ieee80211_is_back_req(fc) ?
1690 (bf->bf_state.bf_type |= BUF_BAR) :
1691 (bf->bf_state.bf_type &= ~BUF_BAR);
1692 ieee80211_is_pspoll(fc) ?
1693 (bf->bf_state.bf_type |= BUF_PSPOLL) :
1694 (bf->bf_state.bf_type &= ~BUF_PSPOLL);
Sujith672840a2008-08-11 14:05:08 +05301695 (sc->sc_flags & SC_OP_PREAMBLE_SHORT) ?
Sujithcd3d39a2008-08-11 14:03:34 +05301696 (bf->bf_state.bf_type |= BUF_SHORT_PREAMBLE) :
1697 (bf->bf_state.bf_type &= ~BUF_SHORT_PREAMBLE);
Sujitha8efee42008-11-18 09:07:30 +05301698 (sc->hw->conf.ht.enabled && !is_pae(skb) &&
Sujith528f0c62008-10-29 10:14:26 +05301699 (tx_info->flags & IEEE80211_TX_CTL_AMPDU)) ?
1700 (bf->bf_state.bf_type |= BUF_HT) :
1701 (bf->bf_state.bf_type &= ~BUF_HT);
Sujithcd3d39a2008-08-11 14:03:34 +05301702
Sujith528f0c62008-10-29 10:14:26 +05301703 bf->bf_flags = setup_tx_flags(sc, skb, txctl->txq);
1704
1705 /* Crypto */
1706
1707 bf->bf_keytype = get_hw_crypto_keytype(skb);
1708
1709 if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR) {
1710 bf->bf_frmlen += tx_info->control.hw_key->icv_len;
1711 bf->bf_keyix = tx_info->control.hw_key->hw_key_idx;
1712 } else {
1713 bf->bf_keyix = ATH9K_TXKEYIX_INVALID;
1714 }
1715
1716 /* Rate series */
1717
1718 setup_rate_retries(sc, skb);
1719
Sujith528f0c62008-10-29 10:14:26 +05301720 /* Assign seqno, tidno */
1721
1722 if (bf_isht(bf) && (sc->sc_flags & SC_OP_TXAGGR))
1723 assign_aggr_tid_seqno(skb, bf);
1724
1725 /* DMA setup */
1726
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001727 bf->bf_mpdu = skb;
Sujith528f0c62008-10-29 10:14:26 +05301728 bf->bf_dmacontext = pci_map_single(sc->pdev, skb->data,
1729 skb->len, PCI_DMA_TODEVICE);
1730 bf->bf_buf_addr = bf->bf_dmacontext;
1731}
1732
1733/* FIXME: tx power */
1734static void ath_tx_start_dma(struct ath_softc *sc, struct ath_buf *bf,
1735 struct scatterlist *sg, u32 n_sg,
1736 struct ath_tx_control *txctl)
1737{
1738 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
1739 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1740 struct ath_node *an = NULL;
1741 struct list_head bf_head;
1742 struct ath_desc *ds;
1743 struct ath_atx_tid *tid;
1744 struct ath_hal *ah = sc->sc_ah;
1745 int frm_type;
1746
Sujith528f0c62008-10-29 10:14:26 +05301747 frm_type = get_hw_packet_type(skb);
1748
1749 INIT_LIST_HEAD(&bf_head);
1750 list_add_tail(&bf->list, &bf_head);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001751
1752 /* setup descriptor */
Sujith528f0c62008-10-29 10:14:26 +05301753
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001754 ds = bf->bf_desc;
1755 ds->ds_link = 0;
1756 ds->ds_data = bf->bf_buf_addr;
1757
Sujith528f0c62008-10-29 10:14:26 +05301758 /* Formulate first tx descriptor with tx controls */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001759
Sujith528f0c62008-10-29 10:14:26 +05301760 ath9k_hw_set11n_txdesc(ah, ds, bf->bf_frmlen, frm_type, MAX_RATE_POWER,
1761 bf->bf_keyix, bf->bf_keytype, bf->bf_flags);
1762
1763 ath9k_hw_filltxdesc(ah, ds,
1764 sg_dma_len(sg), /* segment length */
1765 true, /* first segment */
1766 (n_sg == 1) ? true : false, /* last segment */
1767 ds); /* first descriptor */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001768
1769 bf->bf_lastfrm = bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001770
Sujith528f0c62008-10-29 10:14:26 +05301771 spin_lock_bh(&txctl->txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001772
John W. Linvillef1617962008-10-31 16:45:15 -04001773 if (bf_isht(bf) && (sc->sc_flags & SC_OP_TXAGGR) &&
1774 tx_info->control.sta) {
1775 an = (struct ath_node *)tx_info->control.sta->drv_priv;
1776 tid = ATH_AN_2_TID(an, bf->bf_tidno);
1777
Sujith528f0c62008-10-29 10:14:26 +05301778 if (ath_aggr_query(sc, an, bf->bf_tidno)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001779 /*
1780 * Try aggregation if it's a unicast data frame
1781 * and the destination is HT capable.
1782 */
Sujith528f0c62008-10-29 10:14:26 +05301783 ath_tx_send_ampdu(sc, tid, &bf_head, txctl);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001784 } else {
1785 /*
Sujith528f0c62008-10-29 10:14:26 +05301786 * Send this frame as regular when ADDBA
1787 * exchange is neither complete nor pending.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001788 */
Sujith528f0c62008-10-29 10:14:26 +05301789 ath_tx_send_normal(sc, txctl->txq,
1790 tid, &bf_head);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001791 }
1792 } else {
1793 bf->bf_lastbf = bf;
1794 bf->bf_nframes = 1;
Sujith528f0c62008-10-29 10:14:26 +05301795
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001796 ath_buf_set_rate(sc, bf);
Sujith528f0c62008-10-29 10:14:26 +05301797 ath_tx_txqaddbuf(sc, txctl->txq, &bf_head);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001798 }
Sujith528f0c62008-10-29 10:14:26 +05301799
1800 spin_unlock_bh(&txctl->txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001801}
1802
Sujith528f0c62008-10-29 10:14:26 +05301803int ath_tx_start(struct ath_softc *sc, struct sk_buff *skb,
1804 struct ath_tx_control *txctl)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001805{
Sujith528f0c62008-10-29 10:14:26 +05301806 struct ath_buf *bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001807 struct scatterlist sg;
1808
Sujith528f0c62008-10-29 10:14:26 +05301809 /* Check if a tx buffer is available */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001810
Sujith528f0c62008-10-29 10:14:26 +05301811 bf = ath_tx_get_buffer(sc);
1812 if (!bf) {
1813 DPRINTF(sc, ATH_DBG_XMIT, "%s: TX buffers are full\n",
1814 __func__);
1815 return -1;
1816 }
1817
1818 ath_tx_setup_buffer(sc, bf, skb, &sg, txctl);
1819
1820 /* Setup S/G */
1821
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001822 memset(&sg, 0, sizeof(struct scatterlist));
Sujith528f0c62008-10-29 10:14:26 +05301823 sg_dma_address(&sg) = bf->bf_dmacontext;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001824 sg_dma_len(&sg) = skb->len;
1825
Sujith528f0c62008-10-29 10:14:26 +05301826 ath_tx_start_dma(sc, bf, &sg, 1, txctl);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001827
Sujith528f0c62008-10-29 10:14:26 +05301828 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001829}
1830
1831/* Initialize TX queue and h/w */
1832
1833int ath_tx_init(struct ath_softc *sc, int nbufs)
1834{
1835 int error = 0;
1836
1837 do {
1838 spin_lock_init(&sc->sc_txbuflock);
1839
1840 /* Setup tx descriptors */
1841 error = ath_descdma_setup(sc, &sc->sc_txdma, &sc->sc_txbuf,
Sujith556bb8f2008-08-11 14:03:53 +05301842 "tx", nbufs, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001843 if (error != 0) {
1844 DPRINTF(sc, ATH_DBG_FATAL,
1845 "%s: failed to allocate tx descriptors: %d\n",
1846 __func__, error);
1847 break;
1848 }
1849
1850 /* XXX allocate beacon state together with vap */
1851 error = ath_descdma_setup(sc, &sc->sc_bdma, &sc->sc_bbuf,
1852 "beacon", ATH_BCBUF, 1);
1853 if (error != 0) {
1854 DPRINTF(sc, ATH_DBG_FATAL,
1855 "%s: failed to allocate "
1856 "beacon descripotrs: %d\n",
1857 __func__, error);
1858 break;
1859 }
1860
1861 } while (0);
1862
1863 if (error != 0)
1864 ath_tx_cleanup(sc);
1865
1866 return error;
1867}
1868
1869/* Reclaim all tx queue resources */
1870
1871int ath_tx_cleanup(struct ath_softc *sc)
1872{
1873 /* cleanup beacon descriptors */
1874 if (sc->sc_bdma.dd_desc_len != 0)
1875 ath_descdma_cleanup(sc, &sc->sc_bdma, &sc->sc_bbuf);
1876
1877 /* cleanup tx descriptors */
1878 if (sc->sc_txdma.dd_desc_len != 0)
1879 ath_descdma_cleanup(sc, &sc->sc_txdma, &sc->sc_txbuf);
1880
1881 return 0;
1882}
1883
1884/* Setup a h/w transmit queue */
1885
1886struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype)
1887{
1888 struct ath_hal *ah = sc->sc_ah;
Sujithea9880f2008-08-07 10:53:10 +05301889 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001890 int qnum;
1891
Luis R. Rodriguez0345f372008-10-03 15:45:25 -07001892 memset(&qi, 0, sizeof(qi));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001893 qi.tqi_subtype = subtype;
1894 qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT;
1895 qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
1896 qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT;
Sujithea9880f2008-08-07 10:53:10 +05301897 qi.tqi_physCompBuf = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001898
1899 /*
1900 * Enable interrupts only for EOL and DESC conditions.
1901 * We mark tx descriptors to receive a DESC interrupt
1902 * when a tx queue gets deep; otherwise waiting for the
1903 * EOL to reap descriptors. Note that this is done to
1904 * reduce interrupt load and this only defers reaping
1905 * descriptors, never transmitting frames. Aside from
1906 * reducing interrupts this also permits more concurrency.
1907 * The only potential downside is if the tx queue backs
1908 * up in which case the top half of the kernel may backup
1909 * due to a lack of tx descriptors.
1910 *
1911 * The UAPSD queue is an exception, since we take a desc-
1912 * based intr on the EOSP frames.
1913 */
1914 if (qtype == ATH9K_TX_QUEUE_UAPSD)
1915 qi.tqi_qflags = TXQ_FLAG_TXDESCINT_ENABLE;
1916 else
1917 qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE |
1918 TXQ_FLAG_TXDESCINT_ENABLE;
1919 qnum = ath9k_hw_setuptxqueue(ah, qtype, &qi);
1920 if (qnum == -1) {
1921 /*
1922 * NB: don't print a message, this happens
1923 * normally on parts with too few tx queues
1924 */
1925 return NULL;
1926 }
1927 if (qnum >= ARRAY_SIZE(sc->sc_txq)) {
1928 DPRINTF(sc, ATH_DBG_FATAL,
1929 "%s: hal qnum %u out of range, max %u!\n",
1930 __func__, qnum, (unsigned int)ARRAY_SIZE(sc->sc_txq));
1931 ath9k_hw_releasetxqueue(ah, qnum);
1932 return NULL;
1933 }
1934 if (!ATH_TXQ_SETUP(sc, qnum)) {
1935 struct ath_txq *txq = &sc->sc_txq[qnum];
1936
1937 txq->axq_qnum = qnum;
1938 txq->axq_link = NULL;
1939 INIT_LIST_HEAD(&txq->axq_q);
1940 INIT_LIST_HEAD(&txq->axq_acq);
1941 spin_lock_init(&txq->axq_lock);
1942 txq->axq_depth = 0;
1943 txq->axq_aggr_depth = 0;
1944 txq->axq_totalqueued = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001945 txq->axq_linkbuf = NULL;
1946 sc->sc_txqsetup |= 1<<qnum;
1947 }
1948 return &sc->sc_txq[qnum];
1949}
1950
1951/* Reclaim resources for a setup queue */
1952
1953void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq)
1954{
1955 ath9k_hw_releasetxqueue(sc->sc_ah, txq->axq_qnum);
1956 sc->sc_txqsetup &= ~(1<<txq->axq_qnum);
1957}
1958
1959/*
1960 * Setup a hardware data transmit queue for the specified
1961 * access control. The hal may not support all requested
1962 * queues in which case it will return a reference to a
1963 * previously setup queue. We record the mapping from ac's
1964 * to h/w queues for use by ath_tx_start and also track
1965 * the set of h/w queues being used to optimize work in the
1966 * transmit interrupt handler and related routines.
1967 */
1968
1969int ath_tx_setup(struct ath_softc *sc, int haltype)
1970{
1971 struct ath_txq *txq;
1972
1973 if (haltype >= ARRAY_SIZE(sc->sc_haltype2q)) {
1974 DPRINTF(sc, ATH_DBG_FATAL,
1975 "%s: HAL AC %u out of range, max %zu!\n",
1976 __func__, haltype, ARRAY_SIZE(sc->sc_haltype2q));
1977 return 0;
1978 }
1979 txq = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, haltype);
1980 if (txq != NULL) {
1981 sc->sc_haltype2q[haltype] = txq->axq_qnum;
1982 return 1;
1983 } else
1984 return 0;
1985}
1986
1987int ath_tx_get_qnum(struct ath_softc *sc, int qtype, int haltype)
1988{
1989 int qnum;
1990
1991 switch (qtype) {
1992 case ATH9K_TX_QUEUE_DATA:
1993 if (haltype >= ARRAY_SIZE(sc->sc_haltype2q)) {
1994 DPRINTF(sc, ATH_DBG_FATAL,
1995 "%s: HAL AC %u out of range, max %zu!\n",
1996 __func__,
1997 haltype, ARRAY_SIZE(sc->sc_haltype2q));
1998 return -1;
1999 }
2000 qnum = sc->sc_haltype2q[haltype];
2001 break;
2002 case ATH9K_TX_QUEUE_BEACON:
2003 qnum = sc->sc_bhalq;
2004 break;
2005 case ATH9K_TX_QUEUE_CAB:
2006 qnum = sc->sc_cabq->axq_qnum;
2007 break;
2008 default:
2009 qnum = -1;
2010 }
2011 return qnum;
2012}
2013
Sujith528f0c62008-10-29 10:14:26 +05302014/* Get a transmit queue, if available */
2015
2016struct ath_txq *ath_test_get_txq(struct ath_softc *sc, struct sk_buff *skb)
2017{
2018 struct ath_txq *txq = NULL;
2019 int qnum;
2020
2021 qnum = ath_get_hal_qnum(skb_get_queue_mapping(skb), sc);
2022 txq = &sc->sc_txq[qnum];
2023
2024 spin_lock_bh(&txq->axq_lock);
2025
2026 /* Try to avoid running out of descriptors */
2027 if (txq->axq_depth >= (ATH_TXBUF - 20)) {
2028 DPRINTF(sc, ATH_DBG_FATAL,
2029 "%s: TX queue: %d is full, depth: %d\n",
2030 __func__, qnum, txq->axq_depth);
2031 ieee80211_stop_queue(sc->hw, skb_get_queue_mapping(skb));
2032 txq->stopped = 1;
2033 spin_unlock_bh(&txq->axq_lock);
2034 return NULL;
2035 }
2036
2037 spin_unlock_bh(&txq->axq_lock);
2038
2039 return txq;
2040}
2041
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002042/* Update parameters for a transmit queue */
2043
Sujithea9880f2008-08-07 10:53:10 +05302044int ath_txq_update(struct ath_softc *sc, int qnum,
2045 struct ath9k_tx_queue_info *qinfo)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002046{
2047 struct ath_hal *ah = sc->sc_ah;
2048 int error = 0;
Sujithea9880f2008-08-07 10:53:10 +05302049 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002050
2051 if (qnum == sc->sc_bhalq) {
2052 /*
2053 * XXX: for beacon queue, we just save the parameter.
2054 * It will be picked up by ath_beaconq_config when
2055 * it's necessary.
2056 */
Sujithea9880f2008-08-07 10:53:10 +05302057 sc->sc_beacon_qi = *qinfo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002058 return 0;
2059 }
2060
2061 ASSERT(sc->sc_txq[qnum].axq_qnum == qnum);
2062
Sujithea9880f2008-08-07 10:53:10 +05302063 ath9k_hw_get_txq_props(ah, qnum, &qi);
2064 qi.tqi_aifs = qinfo->tqi_aifs;
2065 qi.tqi_cwmin = qinfo->tqi_cwmin;
2066 qi.tqi_cwmax = qinfo->tqi_cwmax;
2067 qi.tqi_burstTime = qinfo->tqi_burstTime;
2068 qi.tqi_readyTime = qinfo->tqi_readyTime;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002069
Sujithea9880f2008-08-07 10:53:10 +05302070 if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002071 DPRINTF(sc, ATH_DBG_FATAL,
2072 "%s: unable to update hardware queue %u!\n",
2073 __func__, qnum);
2074 error = -EIO;
2075 } else {
2076 ath9k_hw_resettxqueue(ah, qnum); /* push to h/w */
2077 }
2078
2079 return error;
2080}
2081
2082int ath_cabq_update(struct ath_softc *sc)
2083{
Sujithea9880f2008-08-07 10:53:10 +05302084 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002085 int qnum = sc->sc_cabq->axq_qnum;
2086 struct ath_beacon_config conf;
2087
Sujithea9880f2008-08-07 10:53:10 +05302088 ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002089 /*
2090 * Ensure the readytime % is within the bounds.
2091 */
2092 if (sc->sc_config.cabqReadytime < ATH9K_READY_TIME_LO_BOUND)
2093 sc->sc_config.cabqReadytime = ATH9K_READY_TIME_LO_BOUND;
2094 else if (sc->sc_config.cabqReadytime > ATH9K_READY_TIME_HI_BOUND)
2095 sc->sc_config.cabqReadytime = ATH9K_READY_TIME_HI_BOUND;
2096
2097 ath_get_beaconconfig(sc, ATH_IF_ID_ANY, &conf);
2098 qi.tqi_readyTime =
2099 (conf.beacon_interval * sc->sc_config.cabqReadytime) / 100;
2100 ath_txq_update(sc, qnum, &qi);
2101
2102 return 0;
2103}
2104
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002105/* Deferred processing of transmit interrupt */
2106
2107void ath_tx_tasklet(struct ath_softc *sc)
2108{
Sujith1fe11322008-08-26 08:11:06 +05302109 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002110 u32 qcumask = ((1 << ATH9K_NUM_TX_QUEUES) - 1);
2111
2112 ath9k_hw_gettxintrtxqs(sc->sc_ah, &qcumask);
2113
2114 /*
2115 * Process each active queue.
2116 */
2117 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
2118 if (ATH_TXQ_SETUP(sc, i) && (qcumask & (1 << i)))
Sujith1fe11322008-08-26 08:11:06 +05302119 ath_tx_processq(sc, &sc->sc_txq[i]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002120 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002121}
2122
2123void ath_tx_draintxq(struct ath_softc *sc,
2124 struct ath_txq *txq, bool retry_tx)
2125{
2126 struct ath_buf *bf, *lastbf;
2127 struct list_head bf_head;
2128
2129 INIT_LIST_HEAD(&bf_head);
2130
2131 /*
2132 * NB: this assumes output has been stopped and
2133 * we do not need to block ath_tx_tasklet
2134 */
2135 for (;;) {
2136 spin_lock_bh(&txq->axq_lock);
2137
2138 if (list_empty(&txq->axq_q)) {
2139 txq->axq_link = NULL;
2140 txq->axq_linkbuf = NULL;
2141 spin_unlock_bh(&txq->axq_lock);
2142 break;
2143 }
2144
2145 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
2146
2147 if (bf->bf_status & ATH_BUFSTATUS_STALE) {
2148 list_del(&bf->list);
2149 spin_unlock_bh(&txq->axq_lock);
2150
2151 spin_lock_bh(&sc->sc_txbuflock);
2152 list_add_tail(&bf->list, &sc->sc_txbuf);
2153 spin_unlock_bh(&sc->sc_txbuflock);
2154 continue;
2155 }
2156
2157 lastbf = bf->bf_lastbf;
2158 if (!retry_tx)
2159 lastbf->bf_desc->ds_txstat.ts_flags =
2160 ATH9K_TX_SW_ABORTED;
2161
2162 /* remove ath_buf's of the same mpdu from txq */
2163 list_cut_position(&bf_head, &txq->axq_q, &lastbf->list);
2164 txq->axq_depth--;
2165
2166 spin_unlock_bh(&txq->axq_lock);
2167
Sujithcd3d39a2008-08-11 14:03:34 +05302168 if (bf_isampdu(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002169 ath_tx_complete_aggr_rifs(sc, txq, bf, &bf_head, 0);
2170 else
2171 ath_tx_complete_buf(sc, bf, &bf_head, 0, 0);
2172 }
2173
2174 /* flush any pending frames if aggregation is enabled */
Sujith672840a2008-08-11 14:05:08 +05302175 if (sc->sc_flags & SC_OP_TXAGGR) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002176 if (!retry_tx) {
2177 spin_lock_bh(&txq->axq_lock);
Sujithb5aa9bf2008-10-29 10:13:31 +05302178 ath_txq_drain_pending_buffers(sc, txq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002179 spin_unlock_bh(&txq->axq_lock);
2180 }
2181 }
2182}
2183
2184/* Drain the transmit queues and reclaim resources */
2185
2186void ath_draintxq(struct ath_softc *sc, bool retry_tx)
2187{
2188 /* stop beacon queue. The beacon will be freed when
2189 * we go to INIT state */
Sujith672840a2008-08-11 14:05:08 +05302190 if (!(sc->sc_flags & SC_OP_INVALID)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002191 (void) ath9k_hw_stoptxdma(sc->sc_ah, sc->sc_bhalq);
2192 DPRINTF(sc, ATH_DBG_XMIT, "%s: beacon queue %x\n", __func__,
2193 ath9k_hw_gettxbuf(sc->sc_ah, sc->sc_bhalq));
2194 }
2195
2196 ath_drain_txdataq(sc, retry_tx);
2197}
2198
2199u32 ath_txq_depth(struct ath_softc *sc, int qnum)
2200{
2201 return sc->sc_txq[qnum].axq_depth;
2202}
2203
2204u32 ath_txq_aggr_depth(struct ath_softc *sc, int qnum)
2205{
2206 return sc->sc_txq[qnum].axq_aggr_depth;
2207}
2208
Sujithccc75c52008-10-29 10:18:14 +05302209bool ath_tx_aggr_check(struct ath_softc *sc, struct ath_node *an, u8 tidno)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002210{
2211 struct ath_atx_tid *txtid;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002212
Sujith672840a2008-08-11 14:05:08 +05302213 if (!(sc->sc_flags & SC_OP_TXAGGR))
Sujithccc75c52008-10-29 10:18:14 +05302214 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002215
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002216 txtid = ATH_AN_2_TID(an, tidno);
2217
Sujitha37c2c72008-10-29 10:15:40 +05302218 if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
2219 if (!(txtid->state & AGGR_ADDBA_PROGRESS) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002220 (txtid->addba_exchangeattempts < ADDBA_EXCHANGE_ATTEMPTS)) {
2221 txtid->addba_exchangeattempts++;
Sujithccc75c52008-10-29 10:18:14 +05302222 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002223 }
2224 }
2225
Sujithccc75c52008-10-29 10:18:14 +05302226 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002227}
2228
2229/* Start TX aggregation */
2230
Sujithb5aa9bf2008-10-29 10:13:31 +05302231int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
2232 u16 tid, u16 *ssn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002233{
2234 struct ath_atx_tid *txtid;
2235 struct ath_node *an;
2236
Sujithb5aa9bf2008-10-29 10:13:31 +05302237 an = (struct ath_node *)sta->drv_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002238
Sujith672840a2008-08-11 14:05:08 +05302239 if (sc->sc_flags & SC_OP_TXAGGR) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002240 txtid = ATH_AN_2_TID(an, tid);
Sujitha37c2c72008-10-29 10:15:40 +05302241 txtid->state |= AGGR_ADDBA_PROGRESS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002242 ath_tx_pause_tid(sc, txtid);
2243 }
2244
2245 return 0;
2246}
2247
2248/* Stop tx aggregation */
2249
Sujithb5aa9bf2008-10-29 10:13:31 +05302250int ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002251{
Sujithb5aa9bf2008-10-29 10:13:31 +05302252 struct ath_node *an = (struct ath_node *)sta->drv_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002253
2254 ath_tx_aggr_teardown(sc, an, tid);
2255 return 0;
2256}
2257
Sujith8469cde2008-10-29 10:19:28 +05302258/* Resume tx aggregation */
2259
2260void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
2261{
2262 struct ath_atx_tid *txtid;
2263 struct ath_node *an;
2264
2265 an = (struct ath_node *)sta->drv_priv;
2266
2267 if (sc->sc_flags & SC_OP_TXAGGR) {
2268 txtid = ATH_AN_2_TID(an, tid);
2269 txtid->baw_size =
2270 IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
2271 txtid->state |= AGGR_ADDBA_COMPLETE;
2272 txtid->state &= ~AGGR_ADDBA_PROGRESS;
2273 ath_tx_resume_tid(sc, txtid);
2274 }
2275}
2276
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002277/*
2278 * Performs transmit side cleanup when TID changes from aggregated to
2279 * unaggregated.
2280 * - Pause the TID and mark cleanup in progress
2281 * - Discard all retry frames from the s/w queue.
2282 */
2283
Sujithb5aa9bf2008-10-29 10:13:31 +05302284void ath_tx_aggr_teardown(struct ath_softc *sc, struct ath_node *an, u8 tid)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002285{
2286 struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid);
2287 struct ath_txq *txq = &sc->sc_txq[txtid->ac->qnum];
2288 struct ath_buf *bf;
2289 struct list_head bf_head;
2290 INIT_LIST_HEAD(&bf_head);
2291
2292 DPRINTF(sc, ATH_DBG_AGGR, "%s: teardown TX aggregation\n", __func__);
2293
Sujitha37c2c72008-10-29 10:15:40 +05302294 if (txtid->state & AGGR_CLEANUP) /* cleanup is in progress */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002295 return;
2296
Sujitha37c2c72008-10-29 10:15:40 +05302297 if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002298 txtid->addba_exchangeattempts = 0;
2299 return;
2300 }
2301
2302 /* TID must be paused first */
2303 ath_tx_pause_tid(sc, txtid);
2304
2305 /* drop all software retried frames and mark this TID */
2306 spin_lock_bh(&txq->axq_lock);
2307 while (!list_empty(&txtid->buf_q)) {
2308 bf = list_first_entry(&txtid->buf_q, struct ath_buf, list);
Sujithcd3d39a2008-08-11 14:03:34 +05302309 if (!bf_isretried(bf)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002310 /*
2311 * NB: it's based on the assumption that
2312 * software retried frame will always stay
2313 * at the head of software queue.
2314 */
2315 break;
2316 }
2317 list_cut_position(&bf_head,
2318 &txtid->buf_q, &bf->bf_lastfrm->list);
2319 ath_tx_update_baw(sc, txtid, bf->bf_seqno);
2320
2321 /* complete this sub-frame */
2322 ath_tx_complete_buf(sc, bf, &bf_head, 0, 0);
2323 }
2324
2325 if (txtid->baw_head != txtid->baw_tail) {
2326 spin_unlock_bh(&txq->axq_lock);
Sujitha37c2c72008-10-29 10:15:40 +05302327 txtid->state |= AGGR_CLEANUP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002328 } else {
Sujitha37c2c72008-10-29 10:15:40 +05302329 txtid->state &= ~AGGR_ADDBA_COMPLETE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002330 txtid->addba_exchangeattempts = 0;
2331 spin_unlock_bh(&txq->axq_lock);
2332 ath_tx_flush_tid(sc, txtid);
2333 }
2334}
2335
2336/*
2337 * Tx scheduling logic
2338 * NB: must be called with txq lock held
2339 */
2340
2341void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
2342{
2343 struct ath_atx_ac *ac;
2344 struct ath_atx_tid *tid;
2345
2346 /* nothing to schedule */
2347 if (list_empty(&txq->axq_acq))
2348 return;
2349 /*
2350 * get the first node/ac pair on the queue
2351 */
2352 ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac, list);
2353 list_del(&ac->list);
2354 ac->sched = false;
2355
2356 /*
2357 * process a single tid per destination
2358 */
2359 do {
2360 /* nothing to schedule */
2361 if (list_empty(&ac->tid_q))
2362 return;
2363
2364 tid = list_first_entry(&ac->tid_q, struct ath_atx_tid, list);
2365 list_del(&tid->list);
2366 tid->sched = false;
2367
2368 if (tid->paused) /* check next tid to keep h/w busy */
2369 continue;
2370
Sujith43453b32008-10-29 10:14:52 +05302371 if ((txq->axq_depth % 2) == 0)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002372 ath_tx_sched_aggr(sc, txq, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002373
2374 /*
2375 * add tid to round-robin queue if more frames
2376 * are pending for the tid
2377 */
2378 if (!list_empty(&tid->buf_q))
2379 ath_tx_queue_tid(txq, tid);
2380
2381 /* only schedule one TID at a time */
2382 break;
2383 } while (!list_empty(&ac->tid_q));
2384
2385 /*
2386 * schedule AC if more TIDs need processing
2387 */
2388 if (!list_empty(&ac->tid_q)) {
2389 /*
2390 * add dest ac to txq if not already added
2391 */
2392 if (!ac->sched) {
2393 ac->sched = true;
2394 list_add_tail(&ac->list, &txq->axq_acq);
2395 }
2396 }
2397}
2398
2399/* Initialize per-node transmit state */
2400
2401void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an)
2402{
Sujithc5170162008-10-29 10:13:59 +05302403 struct ath_atx_tid *tid;
2404 struct ath_atx_ac *ac;
2405 int tidno, acno;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002406
Sujithc5170162008-10-29 10:13:59 +05302407 /*
2408 * Init per tid tx state
2409 */
2410 for (tidno = 0, tid = &an->an_aggr.tx.tid[tidno];
2411 tidno < WME_NUM_TID;
2412 tidno++, tid++) {
2413 tid->an = an;
2414 tid->tidno = tidno;
2415 tid->seq_start = tid->seq_next = 0;
2416 tid->baw_size = WME_MAX_BA;
2417 tid->baw_head = tid->baw_tail = 0;
2418 tid->sched = false;
2419 tid->paused = false;
Sujitha37c2c72008-10-29 10:15:40 +05302420 tid->state &= ~AGGR_CLEANUP;
Sujithc5170162008-10-29 10:13:59 +05302421 INIT_LIST_HEAD(&tid->buf_q);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002422
Sujithc5170162008-10-29 10:13:59 +05302423 acno = TID_TO_WME_AC(tidno);
2424 tid->ac = &an->an_aggr.tx.ac[acno];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002425
Sujithc5170162008-10-29 10:13:59 +05302426 /* ADDBA state */
Sujitha37c2c72008-10-29 10:15:40 +05302427 tid->state &= ~AGGR_ADDBA_COMPLETE;
2428 tid->state &= ~AGGR_ADDBA_PROGRESS;
2429 tid->addba_exchangeattempts = 0;
Sujithc5170162008-10-29 10:13:59 +05302430 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002431
Sujithc5170162008-10-29 10:13:59 +05302432 /*
2433 * Init per ac tx state
2434 */
2435 for (acno = 0, ac = &an->an_aggr.tx.ac[acno];
2436 acno < WME_NUM_AC; acno++, ac++) {
2437 ac->sched = false;
2438 INIT_LIST_HEAD(&ac->tid_q);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002439
Sujithc5170162008-10-29 10:13:59 +05302440 switch (acno) {
2441 case WME_AC_BE:
2442 ac->qnum = ath_tx_get_qnum(sc,
2443 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
2444 break;
2445 case WME_AC_BK:
2446 ac->qnum = ath_tx_get_qnum(sc,
2447 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BK);
2448 break;
2449 case WME_AC_VI:
2450 ac->qnum = ath_tx_get_qnum(sc,
2451 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VI);
2452 break;
2453 case WME_AC_VO:
2454 ac->qnum = ath_tx_get_qnum(sc,
2455 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VO);
2456 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002457 }
2458 }
2459}
2460
2461/* Cleanupthe pending buffers for the node. */
2462
Sujithb5aa9bf2008-10-29 10:13:31 +05302463void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002464{
2465 int i;
2466 struct ath_atx_ac *ac, *ac_tmp;
2467 struct ath_atx_tid *tid, *tid_tmp;
2468 struct ath_txq *txq;
2469 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
2470 if (ATH_TXQ_SETUP(sc, i)) {
2471 txq = &sc->sc_txq[i];
2472
Sujithb5aa9bf2008-10-29 10:13:31 +05302473 spin_lock(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002474
2475 list_for_each_entry_safe(ac,
2476 ac_tmp, &txq->axq_acq, list) {
2477 tid = list_first_entry(&ac->tid_q,
2478 struct ath_atx_tid, list);
2479 if (tid && tid->an != an)
2480 continue;
2481 list_del(&ac->list);
2482 ac->sched = false;
2483
2484 list_for_each_entry_safe(tid,
2485 tid_tmp, &ac->tid_q, list) {
2486 list_del(&tid->list);
2487 tid->sched = false;
Sujithb5aa9bf2008-10-29 10:13:31 +05302488 ath_tid_drain(sc, txq, tid);
Sujitha37c2c72008-10-29 10:15:40 +05302489 tid->state &= ~AGGR_ADDBA_COMPLETE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002490 tid->addba_exchangeattempts = 0;
Sujitha37c2c72008-10-29 10:15:40 +05302491 tid->state &= ~AGGR_CLEANUP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002492 }
2493 }
2494
Sujithb5aa9bf2008-10-29 10:13:31 +05302495 spin_unlock(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002496 }
2497 }
2498}
2499
Jouni Malinene022edb2008-08-22 17:31:33 +03002500void ath_tx_cabq(struct ath_softc *sc, struct sk_buff *skb)
2501{
2502 int hdrlen, padsize;
2503 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2504 struct ath_tx_control txctl;
2505
Sujith528f0c62008-10-29 10:14:26 +05302506 memset(&txctl, 0, sizeof(struct ath_tx_control));
2507
Jouni Malinene022edb2008-08-22 17:31:33 +03002508 /*
2509 * As a temporary workaround, assign seq# here; this will likely need
2510 * to be cleaned up to work better with Beacon transmission and virtual
2511 * BSSes.
2512 */
2513 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
2514 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2515 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
2516 sc->seq_no += 0x10;
2517 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
2518 hdr->seq_ctrl |= cpu_to_le16(sc->seq_no);
2519 }
2520
2521 /* Add the padding after the header if this is not already done */
2522 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
2523 if (hdrlen & 3) {
2524 padsize = hdrlen % 4;
2525 if (skb_headroom(skb) < padsize) {
2526 DPRINTF(sc, ATH_DBG_XMIT, "%s: TX CABQ padding "
2527 "failed\n", __func__);
2528 dev_kfree_skb_any(skb);
2529 return;
2530 }
2531 skb_push(skb, padsize);
2532 memmove(skb->data, skb->data + padsize, hdrlen);
2533 }
2534
Sujith528f0c62008-10-29 10:14:26 +05302535 txctl.txq = sc->sc_cabq;
2536
Jouni Malinene022edb2008-08-22 17:31:33 +03002537 DPRINTF(sc, ATH_DBG_XMIT, "%s: transmitting CABQ packet, skb: %p\n",
2538 __func__,
2539 skb);
2540
Sujith528f0c62008-10-29 10:14:26 +05302541 if (ath_tx_start(sc, skb, &txctl) != 0) {
2542 DPRINTF(sc, ATH_DBG_XMIT, "%s: TX failed\n", __func__);
2543 goto exit;
Jouni Malinene022edb2008-08-22 17:31:33 +03002544 }
Jouni Malinene022edb2008-08-22 17:31:33 +03002545
Sujith528f0c62008-10-29 10:14:26 +05302546 return;
2547exit:
2548 dev_kfree_skb_any(skb);
2549}