blob: 5e6e5cf9b67f1fc524296b24a0b7595d8556c64f [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
Sujithe8324352009-01-16 21:38:42 +053058static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
59 struct ath_atx_tid *tid,
60 struct list_head *bf_head);
61static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
62 struct list_head *bf_q,
63 int txok, int sendbar);
64static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
65 struct list_head *head);
66static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf);
67
68/*********************/
69/* Aggregation logic */
70/*********************/
71
72static int ath_aggr_query(struct ath_softc *sc, struct ath_node *an, u8 tidno)
73{
74 struct ath_atx_tid *tid;
75 tid = ATH_AN_2_TID(an, tidno);
76
77 if (tid->state & AGGR_ADDBA_COMPLETE ||
78 tid->state & AGGR_ADDBA_PROGRESS)
79 return 1;
80 else
81 return 0;
82}
83
84static void ath_tx_queue_tid(struct ath_txq *txq, struct ath_atx_tid *tid)
85{
86 struct ath_atx_ac *ac = tid->ac;
87
88 if (tid->paused)
89 return;
90
91 if (tid->sched)
92 return;
93
94 tid->sched = true;
95 list_add_tail(&tid->list, &ac->tid_q);
96
97 if (ac->sched)
98 return;
99
100 ac->sched = true;
101 list_add_tail(&ac->list, &txq->axq_acq);
102}
103
104static void ath_tx_pause_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
105{
106 struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum];
107
108 spin_lock_bh(&txq->axq_lock);
109 tid->paused++;
110 spin_unlock_bh(&txq->axq_lock);
111}
112
113static void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
114{
115 struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum];
116
117 ASSERT(tid->paused > 0);
118 spin_lock_bh(&txq->axq_lock);
119
120 tid->paused--;
121
122 if (tid->paused > 0)
123 goto unlock;
124
125 if (list_empty(&tid->buf_q))
126 goto unlock;
127
128 ath_tx_queue_tid(txq, tid);
129 ath_txq_schedule(sc, txq);
130unlock:
131 spin_unlock_bh(&txq->axq_lock);
132}
133
134static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
135{
136 struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum];
137 struct ath_buf *bf;
138 struct list_head bf_head;
139 INIT_LIST_HEAD(&bf_head);
140
141 ASSERT(tid->paused > 0);
142 spin_lock_bh(&txq->axq_lock);
143
144 tid->paused--;
145
146 if (tid->paused > 0) {
147 spin_unlock_bh(&txq->axq_lock);
148 return;
149 }
150
151 while (!list_empty(&tid->buf_q)) {
152 bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
153 ASSERT(!bf_isretried(bf));
154 list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list);
155 ath_tx_send_normal(sc, txq, tid, &bf_head);
156 }
157
158 spin_unlock_bh(&txq->axq_lock);
159}
160
161static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
162 int seqno)
163{
164 int index, cindex;
165
166 index = ATH_BA_INDEX(tid->seq_start, seqno);
167 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
168
169 tid->tx_buf[cindex] = NULL;
170
171 while (tid->baw_head != tid->baw_tail && !tid->tx_buf[tid->baw_head]) {
172 INCR(tid->seq_start, IEEE80211_SEQ_MAX);
173 INCR(tid->baw_head, ATH_TID_MAX_BUFS);
174 }
175}
176
177static void ath_tx_addto_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
178 struct ath_buf *bf)
179{
180 int index, cindex;
181
182 if (bf_isretried(bf))
183 return;
184
185 index = ATH_BA_INDEX(tid->seq_start, bf->bf_seqno);
186 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
187
188 ASSERT(tid->tx_buf[cindex] == NULL);
189 tid->tx_buf[cindex] = bf;
190
191 if (index >= ((tid->baw_tail - tid->baw_head) &
192 (ATH_TID_MAX_BUFS - 1))) {
193 tid->baw_tail = cindex;
194 INCR(tid->baw_tail, ATH_TID_MAX_BUFS);
195 }
196}
197
198/*
199 * TODO: For frame(s) that are in the retry state, we will reuse the
200 * sequence number(s) without setting the retry bit. The
201 * alternative is to give up on these and BAR the receiver's window
202 * forward.
203 */
204static void ath_tid_drain(struct ath_softc *sc, struct ath_txq *txq,
205 struct ath_atx_tid *tid)
206
207{
208 struct ath_buf *bf;
209 struct list_head bf_head;
210 INIT_LIST_HEAD(&bf_head);
211
212 for (;;) {
213 if (list_empty(&tid->buf_q))
214 break;
215 bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
216
217 list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list);
218
219 if (bf_isretried(bf))
220 ath_tx_update_baw(sc, tid, bf->bf_seqno);
221
222 spin_unlock(&txq->axq_lock);
223 ath_tx_complete_buf(sc, bf, &bf_head, 0, 0);
224 spin_lock(&txq->axq_lock);
225 }
226
227 tid->seq_next = tid->seq_start;
228 tid->baw_tail = tid->baw_head;
229}
230
231static void ath_tx_set_retry(struct ath_softc *sc, struct ath_buf *bf)
232{
233 struct sk_buff *skb;
234 struct ieee80211_hdr *hdr;
235
236 bf->bf_state.bf_type |= BUF_RETRY;
237 bf->bf_retries++;
238
239 skb = bf->bf_mpdu;
240 hdr = (struct ieee80211_hdr *)skb->data;
241 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_RETRY);
242}
243
244static void ath_tx_complete_aggr_rifs(struct ath_softc *sc, struct ath_txq *txq,
245 struct ath_buf *bf, struct list_head *bf_q,
246 int txok)
247{
248 struct ath_node *an = NULL;
249 struct sk_buff *skb;
250 struct ieee80211_tx_info *tx_info;
251 struct ath_atx_tid *tid = NULL;
252 struct ath_buf *bf_last = bf->bf_lastbf;
253 struct ath_desc *ds = bf_last->bf_desc;
254 struct ath_buf *bf_next, *bf_lastq = NULL;
255 struct list_head bf_head, bf_pending;
256 u16 seq_st = 0;
257 u32 ba[WME_BA_BMP_SIZE >> 5];
258 int isaggr, txfail, txpending, sendbar = 0, needreset = 0;
259
260 skb = (struct sk_buff *)bf->bf_mpdu;
261 tx_info = IEEE80211_SKB_CB(skb);
262
263 if (tx_info->control.sta) {
264 an = (struct ath_node *)tx_info->control.sta->drv_priv;
265 tid = ATH_AN_2_TID(an, bf->bf_tidno);
266 }
267
268 isaggr = bf_isaggr(bf);
269 if (isaggr) {
270 if (txok) {
271 if (ATH_DS_TX_BA(ds)) {
272 seq_st = ATH_DS_BA_SEQ(ds);
273 memcpy(ba, ATH_DS_BA_BITMAP(ds),
274 WME_BA_BMP_SIZE >> 3);
275 } else {
276 memset(ba, 0, WME_BA_BMP_SIZE >> 3);
277
278 /*
279 * AR5416 can become deaf/mute when BA
280 * issue happens. Chip needs to be reset.
281 * But AP code may have sychronization issues
282 * when perform internal reset in this routine.
283 * Only enable reset in STA mode for now.
284 */
285 if (sc->sc_ah->ah_opmode ==
286 NL80211_IFTYPE_STATION)
287 needreset = 1;
288 }
289 } else {
290 memset(ba, 0, WME_BA_BMP_SIZE >> 3);
291 }
292 }
293
294 INIT_LIST_HEAD(&bf_pending);
295 INIT_LIST_HEAD(&bf_head);
296
297 while (bf) {
298 txfail = txpending = 0;
299 bf_next = bf->bf_next;
300
301 if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, bf->bf_seqno))) {
302 /* transmit completion, subframe is
303 * acked by block ack */
304 } else if (!isaggr && txok) {
305 /* transmit completion */
306 } else {
307
308 if (!(tid->state & AGGR_CLEANUP) &&
309 ds->ds_txstat.ts_flags != ATH9K_TX_SW_ABORTED) {
310 if (bf->bf_retries < ATH_MAX_SW_RETRIES) {
311 ath_tx_set_retry(sc, bf);
312 txpending = 1;
313 } else {
314 bf->bf_state.bf_type |= BUF_XRETRY;
315 txfail = 1;
316 sendbar = 1;
317 }
318 } else {
319 /*
320 * cleanup in progress, just fail
321 * the un-acked sub-frames
322 */
323 txfail = 1;
324 }
325 }
326
327 if (bf_next == NULL) {
328 ASSERT(bf->bf_lastfrm == bf_last);
329 if (!list_empty(bf_q)) {
330 bf_lastq = list_entry(bf_q->prev,
331 struct ath_buf, list);
332 list_cut_position(&bf_head,
333 bf_q, &bf_lastq->list);
334 } else {
335 INIT_LIST_HEAD(&bf_head);
336 }
337 } else {
338 ASSERT(!list_empty(bf_q));
339 list_cut_position(&bf_head,
340 bf_q, &bf->bf_lastfrm->list);
341 }
342
343 if (!txpending) {
344 /*
345 * complete the acked-ones/xretried ones; update
346 * block-ack window
347 */
348 spin_lock_bh(&txq->axq_lock);
349 ath_tx_update_baw(sc, tid, bf->bf_seqno);
350 spin_unlock_bh(&txq->axq_lock);
351
352 ath_tx_complete_buf(sc, bf, &bf_head, !txfail, sendbar);
353 } else {
354 /*
355 * retry the un-acked ones
356 */
357 if (bf->bf_next == NULL &&
358 bf_last->bf_status & ATH_BUFSTATUS_STALE) {
359 struct ath_buf *tbf;
360
361 /* allocate new descriptor */
362 spin_lock_bh(&sc->tx.txbuflock);
363 ASSERT(!list_empty((&sc->tx.txbuf)));
364 tbf = list_first_entry(&sc->tx.txbuf,
365 struct ath_buf, list);
366 list_del(&tbf->list);
367 spin_unlock_bh(&sc->tx.txbuflock);
368
369 ATH_TXBUF_RESET(tbf);
370
371 /* copy descriptor content */
372 tbf->bf_mpdu = bf_last->bf_mpdu;
373 tbf->bf_buf_addr = bf_last->bf_buf_addr;
374 *(tbf->bf_desc) = *(bf_last->bf_desc);
375
376 /* link it to the frame */
377 if (bf_lastq) {
378 bf_lastq->bf_desc->ds_link =
379 tbf->bf_daddr;
380 bf->bf_lastfrm = tbf;
381 ath9k_hw_cleartxdesc(sc->sc_ah,
382 bf->bf_lastfrm->bf_desc);
383 } else {
384 tbf->bf_state = bf_last->bf_state;
385 tbf->bf_lastfrm = tbf;
386 ath9k_hw_cleartxdesc(sc->sc_ah,
387 tbf->bf_lastfrm->bf_desc);
388
389 /* copy the DMA context */
390 tbf->bf_dmacontext =
391 bf_last->bf_dmacontext;
392 }
393 list_add_tail(&tbf->list, &bf_head);
394 } else {
395 /*
396 * Clear descriptor status words for
397 * software retry
398 */
399 ath9k_hw_cleartxdesc(sc->sc_ah,
400 bf->bf_lastfrm->bf_desc);
401 }
402
403 /*
404 * Put this buffer to the temporary pending
405 * queue to retain ordering
406 */
407 list_splice_tail_init(&bf_head, &bf_pending);
408 }
409
410 bf = bf_next;
411 }
412
413 if (tid->state & AGGR_CLEANUP) {
414 /* check to see if we're done with cleaning the h/w queue */
415 spin_lock_bh(&txq->axq_lock);
416
417 if (tid->baw_head == tid->baw_tail) {
418 tid->state &= ~AGGR_ADDBA_COMPLETE;
419 tid->addba_exchangeattempts = 0;
420 spin_unlock_bh(&txq->axq_lock);
421
422 tid->state &= ~AGGR_CLEANUP;
423
424 /* send buffered frames as singles */
425 ath_tx_flush_tid(sc, tid);
426 } else
427 spin_unlock_bh(&txq->axq_lock);
428
429 return;
430 }
431
432 /*
433 * prepend un-acked frames to the beginning of the pending frame queue
434 */
435 if (!list_empty(&bf_pending)) {
436 spin_lock_bh(&txq->axq_lock);
437 list_splice(&bf_pending, &tid->buf_q);
438 ath_tx_queue_tid(txq, tid);
439 spin_unlock_bh(&txq->axq_lock);
440 }
441
442 if (needreset)
443 ath_reset(sc, false);
444
445 return;
446}
447
448static u32 ath_lookup_rate(struct ath_softc *sc, struct ath_buf *bf,
449 struct ath_atx_tid *tid)
450{
451 struct ath_rate_table *rate_table = sc->cur_rate_table;
452 struct sk_buff *skb;
453 struct ieee80211_tx_info *tx_info;
454 struct ieee80211_tx_rate *rates;
455 struct ath_tx_info_priv *tx_info_priv;
456 u32 max_4ms_framelen, frame_length;
457 u16 aggr_limit, legacy = 0, maxampdu;
458 int i;
459
460 skb = (struct sk_buff *)bf->bf_mpdu;
461 tx_info = IEEE80211_SKB_CB(skb);
462 rates = tx_info->control.rates;
463 tx_info_priv =
464 (struct ath_tx_info_priv *)tx_info->rate_driver_data[0];
465
466 /*
467 * Find the lowest frame length among the rate series that will have a
468 * 4ms transmit duration.
469 * TODO - TXOP limit needs to be considered.
470 */
471 max_4ms_framelen = ATH_AMPDU_LIMIT_MAX;
472
473 for (i = 0; i < 4; i++) {
474 if (rates[i].count) {
475 if (!WLAN_RC_PHY_HT(rate_table->info[rates[i].idx].phy)) {
476 legacy = 1;
477 break;
478 }
479
480 frame_length =
481 rate_table->info[rates[i].idx].max_4ms_framelen;
482 max_4ms_framelen = min(max_4ms_framelen, frame_length);
483 }
484 }
485
486 /*
487 * limit aggregate size by the minimum rate if rate selected is
488 * not a probe rate, if rate selected is a probe rate then
489 * avoid aggregation of this packet.
490 */
491 if (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE || legacy)
492 return 0;
493
494 aggr_limit = min(max_4ms_framelen,
495 (u32)ATH_AMPDU_LIMIT_DEFAULT);
496
497 /*
498 * h/w can accept aggregates upto 16 bit lengths (65535).
499 * The IE, however can hold upto 65536, which shows up here
500 * as zero. Ignore 65536 since we are constrained by hw.
501 */
502 maxampdu = tid->an->maxampdu;
503 if (maxampdu)
504 aggr_limit = min(aggr_limit, maxampdu);
505
506 return aggr_limit;
507}
508
509/*
510 * returns the number of delimiters to be added to
511 * meet the minimum required mpdudensity.
512 * caller should make sure that the rate is HT rate .
513 */
514static int ath_compute_num_delims(struct ath_softc *sc, struct ath_atx_tid *tid,
515 struct ath_buf *bf, u16 frmlen)
516{
517 struct ath_rate_table *rt = sc->cur_rate_table;
518 struct sk_buff *skb = bf->bf_mpdu;
519 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
520 u32 nsymbits, nsymbols, mpdudensity;
521 u16 minlen;
522 u8 rc, flags, rix;
523 int width, half_gi, ndelim, mindelim;
524
525 /* Select standard number of delimiters based on frame length alone */
526 ndelim = ATH_AGGR_GET_NDELIM(frmlen);
527
528 /*
529 * If encryption enabled, hardware requires some more padding between
530 * subframes.
531 * TODO - this could be improved to be dependent on the rate.
532 * The hardware can keep up at lower rates, but not higher rates
533 */
534 if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR)
535 ndelim += ATH_AGGR_ENCRYPTDELIM;
536
537 /*
538 * Convert desired mpdu density from microeconds to bytes based
539 * on highest rate in rate series (i.e. first rate) to determine
540 * required minimum length for subframe. Take into account
541 * whether high rate is 20 or 40Mhz and half or full GI.
542 */
543 mpdudensity = tid->an->mpdudensity;
544
545 /*
546 * If there is no mpdu density restriction, no further calculation
547 * is needed.
548 */
549 if (mpdudensity == 0)
550 return ndelim;
551
552 rix = tx_info->control.rates[0].idx;
553 flags = tx_info->control.rates[0].flags;
554 rc = rt->info[rix].ratecode;
555 width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0;
556 half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0;
557
558 if (half_gi)
559 nsymbols = NUM_SYMBOLS_PER_USEC_HALFGI(mpdudensity);
560 else
561 nsymbols = NUM_SYMBOLS_PER_USEC(mpdudensity);
562
563 if (nsymbols == 0)
564 nsymbols = 1;
565
566 nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
567 minlen = (nsymbols * nsymbits) / BITS_PER_BYTE;
568
569 /* Is frame shorter than required minimum length? */
570 if (frmlen < minlen) {
571 /* Get the minimum number of delimiters required. */
572 mindelim = (minlen - frmlen) / ATH_AGGR_DELIM_SZ;
573 ndelim = max(mindelim, ndelim);
574 }
575
576 return ndelim;
577}
578
579static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
580 struct ath_atx_tid *tid, struct list_head *bf_q,
581 struct ath_buf **bf_last, struct aggr_rifs_param *param,
582 int *prev_frames)
583{
584#define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
585 struct ath_buf *bf, *tbf, *bf_first, *bf_prev = NULL;
586 struct list_head bf_head;
587 int rl = 0, nframes = 0, ndelim;
588 u16 aggr_limit = 0, al = 0, bpad = 0,
589 al_delta, h_baw = tid->baw_size / 2;
590 enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
591 int prev_al = 0;
592 INIT_LIST_HEAD(&bf_head);
593
594 BUG_ON(list_empty(&tid->buf_q));
595
596 bf_first = list_first_entry(&tid->buf_q, struct ath_buf, list);
597
598 do {
599 bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
600
601 /*
602 * do not step over block-ack window
603 */
604 if (!BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno)) {
605 status = ATH_AGGR_BAW_CLOSED;
606 break;
607 }
608
609 if (!rl) {
610 aggr_limit = ath_lookup_rate(sc, bf, tid);
611 rl = 1;
612 }
613
614 /*
615 * do not exceed aggregation limit
616 */
617 al_delta = ATH_AGGR_DELIM_SZ + bf->bf_frmlen;
618
619 if (nframes && (aggr_limit <
620 (al + bpad + al_delta + prev_al))) {
621 status = ATH_AGGR_LIMITED;
622 break;
623 }
624
625 /*
626 * do not exceed subframe limit
627 */
628 if ((nframes + *prev_frames) >=
629 min((int)h_baw, ATH_AMPDU_SUBFRAME_DEFAULT)) {
630 status = ATH_AGGR_LIMITED;
631 break;
632 }
633
634 /*
635 * add padding for previous frame to aggregation length
636 */
637 al += bpad + al_delta;
638
639 /*
640 * Get the delimiters needed to meet the MPDU
641 * density for this node.
642 */
643 ndelim = ath_compute_num_delims(sc, tid, bf_first, bf->bf_frmlen);
644
645 bpad = PADBYTES(al_delta) + (ndelim << 2);
646
647 bf->bf_next = NULL;
648 bf->bf_lastfrm->bf_desc->ds_link = 0;
649
650 /*
651 * this packet is part of an aggregate
652 * - remove all descriptors belonging to this frame from
653 * software queue
654 * - add it to block ack window
655 * - set up descriptors for aggregation
656 */
657 list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list);
658 ath_tx_addto_baw(sc, tid, bf);
659
660 list_for_each_entry(tbf, &bf_head, list) {
661 ath9k_hw_set11n_aggr_middle(sc->sc_ah,
662 tbf->bf_desc, ndelim);
663 }
664
665 /*
666 * link buffers of this frame to the aggregate
667 */
668 list_splice_tail_init(&bf_head, bf_q);
669 nframes++;
670
671 if (bf_prev) {
672 bf_prev->bf_next = bf;
673 bf_prev->bf_lastfrm->bf_desc->ds_link = bf->bf_daddr;
674 }
675 bf_prev = bf;
676
677 } while (!list_empty(&tid->buf_q));
678
679 bf_first->bf_al = al;
680 bf_first->bf_nframes = nframes;
681 *bf_last = bf_prev;
682 return status;
683#undef PADBYTES
684}
685
686static void ath_tx_sched_aggr(struct ath_softc *sc, struct ath_txq *txq,
687 struct ath_atx_tid *tid)
688{
689 struct ath_buf *bf, *tbf, *bf_last, *bf_lastaggr = NULL;
690 enum ATH_AGGR_STATUS status;
691 struct list_head bf_q;
692 struct aggr_rifs_param param = {0, 0, 0, 0, NULL};
693 int prev_frames = 0;
694
695 do {
696 if (list_empty(&tid->buf_q))
697 return;
698
699 INIT_LIST_HEAD(&bf_q);
700
701 status = ath_tx_form_aggr(sc, tid, &bf_q, &bf_lastaggr, &param,
702 &prev_frames);
703
704 /*
705 * no frames picked up to be aggregated; block-ack
706 * window is not open
707 */
708 if (list_empty(&bf_q))
709 break;
710
711 bf = list_first_entry(&bf_q, struct ath_buf, list);
712 bf_last = list_entry(bf_q.prev, struct ath_buf, list);
713 bf->bf_lastbf = bf_last;
714
715 /*
716 * if only one frame, send as non-aggregate
717 */
718 if (bf->bf_nframes == 1) {
719 ASSERT(bf->bf_lastfrm == bf_last);
720
721 bf->bf_state.bf_type &= ~BUF_AGGR;
722 /*
723 * clear aggr bits for every descriptor
724 * XXX TODO: is there a way to optimize it?
725 */
726 list_for_each_entry(tbf, &bf_q, list) {
727 ath9k_hw_clr11n_aggr(sc->sc_ah, tbf->bf_desc);
728 }
729
730 ath_buf_set_rate(sc, bf);
731 ath_tx_txqaddbuf(sc, txq, &bf_q);
732 continue;
733 }
734
735 /*
736 * setup first desc with rate and aggr info
737 */
738 bf->bf_state.bf_type |= BUF_AGGR;
739 ath_buf_set_rate(sc, bf);
740 ath9k_hw_set11n_aggr_first(sc->sc_ah, bf->bf_desc, bf->bf_al);
741
742 /*
743 * anchor last frame of aggregate correctly
744 */
745 ASSERT(bf_lastaggr);
746 ASSERT(bf_lastaggr->bf_lastfrm == bf_last);
747 tbf = bf_lastaggr;
748 ath9k_hw_set11n_aggr_last(sc->sc_ah, tbf->bf_desc);
749
750 /* XXX: We don't enter into this loop, consider removing this */
751 while (!list_empty(&bf_q) && !list_is_last(&tbf->list, &bf_q)) {
752 tbf = list_entry(tbf->list.next, struct ath_buf, list);
753 ath9k_hw_set11n_aggr_last(sc->sc_ah, tbf->bf_desc);
754 }
755
756 txq->axq_aggr_depth++;
757
758 /*
759 * Normal aggregate, queue to hardware
760 */
761 ath_tx_txqaddbuf(sc, txq, &bf_q);
762
763 } while (txq->axq_depth < ATH_AGGR_MIN_QDEPTH &&
764 status != ATH_AGGR_BAW_CLOSED);
765}
766
767int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
768 u16 tid, u16 *ssn)
769{
770 struct ath_atx_tid *txtid;
771 struct ath_node *an;
772
773 an = (struct ath_node *)sta->drv_priv;
774
775 if (sc->sc_flags & SC_OP_TXAGGR) {
776 txtid = ATH_AN_2_TID(an, tid);
777 txtid->state |= AGGR_ADDBA_PROGRESS;
778 ath_tx_pause_tid(sc, txtid);
779 }
780
781 return 0;
782}
783
784int ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
785{
786 struct ath_node *an = (struct ath_node *)sta->drv_priv;
787 struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid);
788 struct ath_txq *txq = &sc->tx.txq[txtid->ac->qnum];
789 struct ath_buf *bf;
790 struct list_head bf_head;
791 INIT_LIST_HEAD(&bf_head);
792
793 if (txtid->state & AGGR_CLEANUP)
794 return 0;
795
796 if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
797 txtid->addba_exchangeattempts = 0;
798 return 0;
799 }
800
801 ath_tx_pause_tid(sc, txtid);
802
803 /* drop all software retried frames and mark this TID */
804 spin_lock_bh(&txq->axq_lock);
805 while (!list_empty(&txtid->buf_q)) {
806 bf = list_first_entry(&txtid->buf_q, struct ath_buf, list);
807 if (!bf_isretried(bf)) {
808 /*
809 * NB: it's based on the assumption that
810 * software retried frame will always stay
811 * at the head of software queue.
812 */
813 break;
814 }
815 list_cut_position(&bf_head,
816 &txtid->buf_q, &bf->bf_lastfrm->list);
817 ath_tx_update_baw(sc, txtid, bf->bf_seqno);
818 ath_tx_complete_buf(sc, bf, &bf_head, 0, 0);
819 }
820
821 if (txtid->baw_head != txtid->baw_tail) {
822 spin_unlock_bh(&txq->axq_lock);
823 txtid->state |= AGGR_CLEANUP;
824 } else {
825 txtid->state &= ~AGGR_ADDBA_COMPLETE;
826 txtid->addba_exchangeattempts = 0;
827 spin_unlock_bh(&txq->axq_lock);
828 ath_tx_flush_tid(sc, txtid);
829 }
830
831 return 0;
832}
833
834void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
835{
836 struct ath_atx_tid *txtid;
837 struct ath_node *an;
838
839 an = (struct ath_node *)sta->drv_priv;
840
841 if (sc->sc_flags & SC_OP_TXAGGR) {
842 txtid = ATH_AN_2_TID(an, tid);
843 txtid->baw_size =
844 IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
845 txtid->state |= AGGR_ADDBA_COMPLETE;
846 txtid->state &= ~AGGR_ADDBA_PROGRESS;
847 ath_tx_resume_tid(sc, txtid);
848 }
849}
850
851bool ath_tx_aggr_check(struct ath_softc *sc, struct ath_node *an, u8 tidno)
852{
853 struct ath_atx_tid *txtid;
854
855 if (!(sc->sc_flags & SC_OP_TXAGGR))
856 return false;
857
858 txtid = ATH_AN_2_TID(an, tidno);
859
860 if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
861 if (!(txtid->state & AGGR_ADDBA_PROGRESS) &&
862 (txtid->addba_exchangeattempts < ADDBA_EXCHANGE_ATTEMPTS)) {
863 txtid->addba_exchangeattempts++;
864 return true;
865 }
866 }
867
868 return false;
869}
870
871/********************/
872/* Queue Management */
873/********************/
874
875static u32 ath_txq_depth(struct ath_softc *sc, int qnum)
876{
877 return sc->tx.txq[qnum].axq_depth;
878}
879
880static void ath_tx_stopdma(struct ath_softc *sc, struct ath_txq *txq)
881{
882 struct ath_hal *ah = sc->sc_ah;
883 (void) ath9k_hw_stoptxdma(ah, txq->axq_qnum);
884}
885
886static void ath_get_beaconconfig(struct ath_softc *sc, int if_id,
887 struct ath_beacon_config *conf)
888{
889 struct ieee80211_hw *hw = sc->hw;
890
891 /* fill in beacon config data */
892
893 conf->beacon_interval = hw->conf.beacon_int;
894 conf->listen_interval = 100;
895 conf->dtim_count = 1;
896 conf->bmiss_timeout = ATH_DEFAULT_BMISS_LIMIT * conf->listen_interval;
897}
898
899static void ath_drain_txdataq(struct ath_softc *sc, bool retry_tx)
900{
901 struct ath_hal *ah = sc->sc_ah;
902 int i, npend = 0;
903
904 if (!(sc->sc_flags & SC_OP_INVALID)) {
905 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
906 if (ATH_TXQ_SETUP(sc, i)) {
907 ath_tx_stopdma(sc, &sc->tx.txq[i]);
908 npend += ath9k_hw_numtxpending(ah,
909 sc->tx.txq[i].axq_qnum);
910 }
911 }
912 }
913
914 if (npend) {
915 int r;
916
917 DPRINTF(sc, ATH_DBG_XMIT, "Unable to stop TxDMA. Reset HAL!\n");
918
919 spin_lock_bh(&sc->sc_resetlock);
920 r = ath9k_hw_reset(ah, sc->sc_ah->ah_curchan, true);
921 if (r)
922 DPRINTF(sc, ATH_DBG_FATAL,
923 "Unable to reset hardware; reset status %u\n",
924 r);
925 spin_unlock_bh(&sc->sc_resetlock);
926 }
927
928 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
929 if (ATH_TXQ_SETUP(sc, i))
930 ath_tx_draintxq(sc, &sc->tx.txq[i], retry_tx);
931 }
932}
933
934static void ath_txq_drain_pending_buffers(struct ath_softc *sc,
935 struct ath_txq *txq)
936{
937 struct ath_atx_ac *ac, *ac_tmp;
938 struct ath_atx_tid *tid, *tid_tmp;
939
940 list_for_each_entry_safe(ac, ac_tmp, &txq->axq_acq, list) {
941 list_del(&ac->list);
942 ac->sched = false;
943 list_for_each_entry_safe(tid, tid_tmp, &ac->tid_q, list) {
944 list_del(&tid->list);
945 tid->sched = false;
946 ath_tid_drain(sc, txq, tid);
947 }
948 }
949}
950
951struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype)
952{
953 struct ath_hal *ah = sc->sc_ah;
954 struct ath9k_tx_queue_info qi;
955 int qnum;
956
957 memset(&qi, 0, sizeof(qi));
958 qi.tqi_subtype = subtype;
959 qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT;
960 qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
961 qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT;
962 qi.tqi_physCompBuf = 0;
963
964 /*
965 * Enable interrupts only for EOL and DESC conditions.
966 * We mark tx descriptors to receive a DESC interrupt
967 * when a tx queue gets deep; otherwise waiting for the
968 * EOL to reap descriptors. Note that this is done to
969 * reduce interrupt load and this only defers reaping
970 * descriptors, never transmitting frames. Aside from
971 * reducing interrupts this also permits more concurrency.
972 * The only potential downside is if the tx queue backs
973 * up in which case the top half of the kernel may backup
974 * due to a lack of tx descriptors.
975 *
976 * The UAPSD queue is an exception, since we take a desc-
977 * based intr on the EOSP frames.
978 */
979 if (qtype == ATH9K_TX_QUEUE_UAPSD)
980 qi.tqi_qflags = TXQ_FLAG_TXDESCINT_ENABLE;
981 else
982 qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE |
983 TXQ_FLAG_TXDESCINT_ENABLE;
984 qnum = ath9k_hw_setuptxqueue(ah, qtype, &qi);
985 if (qnum == -1) {
986 /*
987 * NB: don't print a message, this happens
988 * normally on parts with too few tx queues
989 */
990 return NULL;
991 }
992 if (qnum >= ARRAY_SIZE(sc->tx.txq)) {
993 DPRINTF(sc, ATH_DBG_FATAL,
994 "qnum %u out of range, max %u!\n",
995 qnum, (unsigned int)ARRAY_SIZE(sc->tx.txq));
996 ath9k_hw_releasetxqueue(ah, qnum);
997 return NULL;
998 }
999 if (!ATH_TXQ_SETUP(sc, qnum)) {
1000 struct ath_txq *txq = &sc->tx.txq[qnum];
1001
1002 txq->axq_qnum = qnum;
1003 txq->axq_link = NULL;
1004 INIT_LIST_HEAD(&txq->axq_q);
1005 INIT_LIST_HEAD(&txq->axq_acq);
1006 spin_lock_init(&txq->axq_lock);
1007 txq->axq_depth = 0;
1008 txq->axq_aggr_depth = 0;
1009 txq->axq_totalqueued = 0;
1010 txq->axq_linkbuf = NULL;
1011 sc->tx.txqsetup |= 1<<qnum;
1012 }
1013 return &sc->tx.txq[qnum];
1014}
1015
1016static int ath_tx_get_qnum(struct ath_softc *sc, int qtype, int haltype)
1017{
1018 int qnum;
1019
1020 switch (qtype) {
1021 case ATH9K_TX_QUEUE_DATA:
1022 if (haltype >= ARRAY_SIZE(sc->tx.hwq_map)) {
1023 DPRINTF(sc, ATH_DBG_FATAL,
1024 "HAL AC %u out of range, max %zu!\n",
1025 haltype, ARRAY_SIZE(sc->tx.hwq_map));
1026 return -1;
1027 }
1028 qnum = sc->tx.hwq_map[haltype];
1029 break;
1030 case ATH9K_TX_QUEUE_BEACON:
1031 qnum = sc->beacon.beaconq;
1032 break;
1033 case ATH9K_TX_QUEUE_CAB:
1034 qnum = sc->beacon.cabq->axq_qnum;
1035 break;
1036 default:
1037 qnum = -1;
1038 }
1039 return qnum;
1040}
1041
1042struct ath_txq *ath_test_get_txq(struct ath_softc *sc, struct sk_buff *skb)
1043{
1044 struct ath_txq *txq = NULL;
1045 int qnum;
1046
1047 qnum = ath_get_hal_qnum(skb_get_queue_mapping(skb), sc);
1048 txq = &sc->tx.txq[qnum];
1049
1050 spin_lock_bh(&txq->axq_lock);
1051
1052 if (txq->axq_depth >= (ATH_TXBUF - 20)) {
1053 DPRINTF(sc, ATH_DBG_FATAL,
1054 "TX queue: %d is full, depth: %d\n",
1055 qnum, txq->axq_depth);
1056 ieee80211_stop_queue(sc->hw, skb_get_queue_mapping(skb));
1057 txq->stopped = 1;
1058 spin_unlock_bh(&txq->axq_lock);
1059 return NULL;
1060 }
1061
1062 spin_unlock_bh(&txq->axq_lock);
1063
1064 return txq;
1065}
1066
1067int ath_txq_update(struct ath_softc *sc, int qnum,
1068 struct ath9k_tx_queue_info *qinfo)
1069{
1070 struct ath_hal *ah = sc->sc_ah;
1071 int error = 0;
1072 struct ath9k_tx_queue_info qi;
1073
1074 if (qnum == sc->beacon.beaconq) {
1075 /*
1076 * XXX: for beacon queue, we just save the parameter.
1077 * It will be picked up by ath_beaconq_config when
1078 * it's necessary.
1079 */
1080 sc->beacon.beacon_qi = *qinfo;
1081 return 0;
1082 }
1083
1084 ASSERT(sc->tx.txq[qnum].axq_qnum == qnum);
1085
1086 ath9k_hw_get_txq_props(ah, qnum, &qi);
1087 qi.tqi_aifs = qinfo->tqi_aifs;
1088 qi.tqi_cwmin = qinfo->tqi_cwmin;
1089 qi.tqi_cwmax = qinfo->tqi_cwmax;
1090 qi.tqi_burstTime = qinfo->tqi_burstTime;
1091 qi.tqi_readyTime = qinfo->tqi_readyTime;
1092
1093 if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
1094 DPRINTF(sc, ATH_DBG_FATAL,
1095 "Unable to update hardware queue %u!\n", qnum);
1096 error = -EIO;
1097 } else {
1098 ath9k_hw_resettxqueue(ah, qnum);
1099 }
1100
1101 return error;
1102}
1103
1104int ath_cabq_update(struct ath_softc *sc)
1105{
1106 struct ath9k_tx_queue_info qi;
1107 int qnum = sc->beacon.cabq->axq_qnum;
1108 struct ath_beacon_config conf;
1109
1110 ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi);
1111 /*
1112 * Ensure the readytime % is within the bounds.
1113 */
1114 if (sc->sc_config.cabqReadytime < ATH9K_READY_TIME_LO_BOUND)
1115 sc->sc_config.cabqReadytime = ATH9K_READY_TIME_LO_BOUND;
1116 else if (sc->sc_config.cabqReadytime > ATH9K_READY_TIME_HI_BOUND)
1117 sc->sc_config.cabqReadytime = ATH9K_READY_TIME_HI_BOUND;
1118
1119 ath_get_beaconconfig(sc, ATH_IF_ID_ANY, &conf);
1120 qi.tqi_readyTime =
1121 (conf.beacon_interval * sc->sc_config.cabqReadytime) / 100;
1122 ath_txq_update(sc, qnum, &qi);
1123
1124 return 0;
1125}
1126
1127void ath_tx_draintxq(struct ath_softc *sc, struct ath_txq *txq, bool retry_tx)
1128{
1129 struct ath_buf *bf, *lastbf;
1130 struct list_head bf_head;
1131
1132 INIT_LIST_HEAD(&bf_head);
1133
1134 /*
1135 * NB: this assumes output has been stopped and
1136 * we do not need to block ath_tx_tasklet
1137 */
1138 for (;;) {
1139 spin_lock_bh(&txq->axq_lock);
1140
1141 if (list_empty(&txq->axq_q)) {
1142 txq->axq_link = NULL;
1143 txq->axq_linkbuf = NULL;
1144 spin_unlock_bh(&txq->axq_lock);
1145 break;
1146 }
1147
1148 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
1149
1150 if (bf->bf_status & ATH_BUFSTATUS_STALE) {
1151 list_del(&bf->list);
1152 spin_unlock_bh(&txq->axq_lock);
1153
1154 spin_lock_bh(&sc->tx.txbuflock);
1155 list_add_tail(&bf->list, &sc->tx.txbuf);
1156 spin_unlock_bh(&sc->tx.txbuflock);
1157 continue;
1158 }
1159
1160 lastbf = bf->bf_lastbf;
1161 if (!retry_tx)
1162 lastbf->bf_desc->ds_txstat.ts_flags =
1163 ATH9K_TX_SW_ABORTED;
1164
1165 /* remove ath_buf's of the same mpdu from txq */
1166 list_cut_position(&bf_head, &txq->axq_q, &lastbf->list);
1167 txq->axq_depth--;
1168
1169 spin_unlock_bh(&txq->axq_lock);
1170
1171 if (bf_isampdu(bf))
1172 ath_tx_complete_aggr_rifs(sc, txq, bf, &bf_head, 0);
1173 else
1174 ath_tx_complete_buf(sc, bf, &bf_head, 0, 0);
1175 }
1176
1177 /* flush any pending frames if aggregation is enabled */
1178 if (sc->sc_flags & SC_OP_TXAGGR) {
1179 if (!retry_tx) {
1180 spin_lock_bh(&txq->axq_lock);
1181 ath_txq_drain_pending_buffers(sc, txq);
1182 spin_unlock_bh(&txq->axq_lock);
1183 }
1184 }
1185}
1186
1187void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq)
1188{
1189 ath9k_hw_releasetxqueue(sc->sc_ah, txq->axq_qnum);
1190 sc->tx.txqsetup &= ~(1<<txq->axq_qnum);
1191}
1192
1193void ath_draintxq(struct ath_softc *sc, bool retry_tx)
1194{
1195 if (!(sc->sc_flags & SC_OP_INVALID))
1196 (void) ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
1197
1198 ath_drain_txdataq(sc, retry_tx);
1199}
1200
1201void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
1202{
1203 struct ath_atx_ac *ac;
1204 struct ath_atx_tid *tid;
1205
1206 if (list_empty(&txq->axq_acq))
1207 return;
1208
1209 ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac, list);
1210 list_del(&ac->list);
1211 ac->sched = false;
1212
1213 do {
1214 if (list_empty(&ac->tid_q))
1215 return;
1216
1217 tid = list_first_entry(&ac->tid_q, struct ath_atx_tid, list);
1218 list_del(&tid->list);
1219 tid->sched = false;
1220
1221 if (tid->paused)
1222 continue;
1223
1224 if ((txq->axq_depth % 2) == 0)
1225 ath_tx_sched_aggr(sc, txq, tid);
1226
1227 /*
1228 * add tid to round-robin queue if more frames
1229 * are pending for the tid
1230 */
1231 if (!list_empty(&tid->buf_q))
1232 ath_tx_queue_tid(txq, tid);
1233
1234 break;
1235 } while (!list_empty(&ac->tid_q));
1236
1237 if (!list_empty(&ac->tid_q)) {
1238 if (!ac->sched) {
1239 ac->sched = true;
1240 list_add_tail(&ac->list, &txq->axq_acq);
1241 }
1242 }
1243}
1244
1245int ath_tx_setup(struct ath_softc *sc, int haltype)
1246{
1247 struct ath_txq *txq;
1248
1249 if (haltype >= ARRAY_SIZE(sc->tx.hwq_map)) {
1250 DPRINTF(sc, ATH_DBG_FATAL,
1251 "HAL AC %u out of range, max %zu!\n",
1252 haltype, ARRAY_SIZE(sc->tx.hwq_map));
1253 return 0;
1254 }
1255 txq = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, haltype);
1256 if (txq != NULL) {
1257 sc->tx.hwq_map[haltype] = txq->axq_qnum;
1258 return 1;
1259 } else
1260 return 0;
1261}
1262
1263/***********/
1264/* TX, DMA */
1265/***********/
1266
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001267/*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001268 * Insert a chain of ath_buf (descriptors) on a txq and
1269 * assume the descriptors are already chained together by caller.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001270 */
Sujith102e0572008-10-29 10:15:16 +05301271static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
1272 struct list_head *head)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001273{
1274 struct ath_hal *ah = sc->sc_ah;
1275 struct ath_buf *bf;
Sujith102e0572008-10-29 10:15:16 +05301276
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001277 /*
1278 * Insert the frame on the outbound list and
1279 * pass it on to the hardware.
1280 */
1281
1282 if (list_empty(head))
1283 return;
1284
1285 bf = list_first_entry(head, struct ath_buf, list);
1286
1287 list_splice_tail_init(head, &txq->axq_q);
1288 txq->axq_depth++;
1289 txq->axq_totalqueued++;
1290 txq->axq_linkbuf = list_entry(txq->axq_q.prev, struct ath_buf, list);
1291
1292 DPRINTF(sc, ATH_DBG_QUEUE,
Sujith04bd46382008-11-28 22:18:05 +05301293 "qnum: %d, txq depth: %d\n", txq->axq_qnum, txq->axq_depth);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001294
1295 if (txq->axq_link == NULL) {
1296 ath9k_hw_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr);
1297 DPRINTF(sc, ATH_DBG_XMIT,
Sujith04bd46382008-11-28 22:18:05 +05301298 "TXDP[%u] = %llx (%p)\n",
1299 txq->axq_qnum, ito64(bf->bf_daddr), bf->bf_desc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001300 } else {
1301 *txq->axq_link = bf->bf_daddr;
Sujith04bd46382008-11-28 22:18:05 +05301302 DPRINTF(sc, ATH_DBG_XMIT, "link[%u] (%p)=%llx (%p)\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001303 txq->axq_qnum, txq->axq_link,
1304 ito64(bf->bf_daddr), bf->bf_desc);
1305 }
1306 txq->axq_link = &(bf->bf_lastbf->bf_desc->ds_link);
1307 ath9k_hw_txstart(ah, txq->axq_qnum);
1308}
1309
Sujithe8324352009-01-16 21:38:42 +05301310static struct ath_buf *ath_tx_get_buffer(struct ath_softc *sc)
Sujithc4288392008-11-18 09:09:30 +05301311{
Sujithe8324352009-01-16 21:38:42 +05301312 struct ath_buf *bf = NULL;
Sujithc4288392008-11-18 09:09:30 +05301313
Sujithe8324352009-01-16 21:38:42 +05301314 spin_lock_bh(&sc->tx.txbuflock);
Sujithc4288392008-11-18 09:09:30 +05301315
Sujithe8324352009-01-16 21:38:42 +05301316 if (unlikely(list_empty(&sc->tx.txbuf))) {
1317 spin_unlock_bh(&sc->tx.txbuflock);
1318 return NULL;
Sujithc4288392008-11-18 09:09:30 +05301319 }
1320
Sujithe8324352009-01-16 21:38:42 +05301321 bf = list_first_entry(&sc->tx.txbuf, struct ath_buf, list);
1322 list_del(&bf->list);
Sujithc4288392008-11-18 09:09:30 +05301323
Sujithe8324352009-01-16 21:38:42 +05301324 spin_unlock_bh(&sc->tx.txbuflock);
Sujithc4288392008-11-18 09:09:30 +05301325
Sujithe8324352009-01-16 21:38:42 +05301326 return bf;
1327}
Sujithc4288392008-11-18 09:09:30 +05301328
Sujithe8324352009-01-16 21:38:42 +05301329static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_atx_tid *tid,
1330 struct list_head *bf_head,
1331 struct ath_tx_control *txctl)
1332{
1333 struct ath_buf *bf;
1334
1335 BUG_ON(list_empty(bf_head));
1336
1337 bf = list_first_entry(bf_head, struct ath_buf, list);
1338 bf->bf_state.bf_type |= BUF_AMPDU;
1339
1340 /*
1341 * Do not queue to h/w when any of the following conditions is true:
1342 * - there are pending frames in software queue
1343 * - the TID is currently paused for ADDBA/BAR request
1344 * - seqno is not within block-ack window
1345 * - h/w queue depth exceeds low water mark
1346 */
1347 if (!list_empty(&tid->buf_q) || tid->paused ||
1348 !BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno) ||
1349 txctl->txq->axq_depth >= ATH_AGGR_MIN_QDEPTH) {
Jouni Malinenf7a276a2008-12-15 16:02:04 +02001350 /*
Sujithe8324352009-01-16 21:38:42 +05301351 * Add this frame to software queue for scheduling later
1352 * for aggregation.
Jouni Malinenf7a276a2008-12-15 16:02:04 +02001353 */
Sujithe8324352009-01-16 21:38:42 +05301354 list_splice_tail_init(bf_head, &tid->buf_q);
1355 ath_tx_queue_tid(txctl->txq, tid);
1356 return;
Jouni Malinenf7a276a2008-12-15 16:02:04 +02001357 }
1358
Sujithe8324352009-01-16 21:38:42 +05301359 /* Add sub-frame to BAW */
1360 ath_tx_addto_baw(sc, tid, bf);
1361
1362 /* Queue to h/w without aggregation */
1363 bf->bf_nframes = 1;
1364 bf->bf_lastbf = bf->bf_lastfrm; /* one single frame */
1365 ath_buf_set_rate(sc, bf);
1366 ath_tx_txqaddbuf(sc, txctl->txq, bf_head);
1367
1368 return;
Sujithc4288392008-11-18 09:09:30 +05301369}
1370
Sujithe8324352009-01-16 21:38:42 +05301371static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
1372 struct ath_atx_tid *tid,
1373 struct list_head *bf_head)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001374{
Sujithe8324352009-01-16 21:38:42 +05301375 struct ath_buf *bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001376
Sujithe8324352009-01-16 21:38:42 +05301377 BUG_ON(list_empty(bf_head));
1378
1379 bf = list_first_entry(bf_head, struct ath_buf, list);
1380 bf->bf_state.bf_type &= ~BUF_AMPDU;
1381
1382 /* update starting sequence number for subsequent ADDBA request */
1383 INCR(tid->seq_start, IEEE80211_SEQ_MAX);
1384
1385 bf->bf_nframes = 1;
1386 bf->bf_lastbf = bf->bf_lastfrm;
1387 ath_buf_set_rate(sc, bf);
1388 ath_tx_txqaddbuf(sc, txq, bf_head);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001389}
1390
Sujith528f0c62008-10-29 10:14:26 +05301391static enum ath9k_pkt_type get_hw_packet_type(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001392{
Sujith528f0c62008-10-29 10:14:26 +05301393 struct ieee80211_hdr *hdr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001394 enum ath9k_pkt_type htype;
1395 __le16 fc;
1396
Sujith528f0c62008-10-29 10:14:26 +05301397 hdr = (struct ieee80211_hdr *)skb->data;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001398 fc = hdr->frame_control;
1399
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001400 if (ieee80211_is_beacon(fc))
1401 htype = ATH9K_PKT_TYPE_BEACON;
1402 else if (ieee80211_is_probe_resp(fc))
1403 htype = ATH9K_PKT_TYPE_PROBE_RESP;
1404 else if (ieee80211_is_atim(fc))
1405 htype = ATH9K_PKT_TYPE_ATIM;
1406 else if (ieee80211_is_pspoll(fc))
1407 htype = ATH9K_PKT_TYPE_PSPOLL;
1408 else
1409 htype = ATH9K_PKT_TYPE_NORMAL;
1410
1411 return htype;
1412}
1413
Sujitha8efee42008-11-18 09:07:30 +05301414static bool is_pae(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001415{
1416 struct ieee80211_hdr *hdr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001417 __le16 fc;
1418
1419 hdr = (struct ieee80211_hdr *)skb->data;
1420 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +02001421
Sujitha8efee42008-11-18 09:07:30 +05301422 if (ieee80211_is_data(fc)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001423 if (ieee80211_is_nullfunc(fc) ||
Sujith528f0c62008-10-29 10:14:26 +05301424 /* Port Access Entity (IEEE 802.1X) */
1425 (skb->protocol == cpu_to_be16(ETH_P_PAE))) {
Sujitha8efee42008-11-18 09:07:30 +05301426 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001427 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001428 }
1429
Sujitha8efee42008-11-18 09:07:30 +05301430 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001431}
1432
Sujith528f0c62008-10-29 10:14:26 +05301433static int get_hw_crypto_keytype(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001434{
Sujith528f0c62008-10-29 10:14:26 +05301435 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1436
1437 if (tx_info->control.hw_key) {
1438 if (tx_info->control.hw_key->alg == ALG_WEP)
1439 return ATH9K_KEY_TYPE_WEP;
1440 else if (tx_info->control.hw_key->alg == ALG_TKIP)
1441 return ATH9K_KEY_TYPE_TKIP;
1442 else if (tx_info->control.hw_key->alg == ALG_CCMP)
1443 return ATH9K_KEY_TYPE_AES;
1444 }
1445
1446 return ATH9K_KEY_TYPE_CLEAR;
1447}
1448
Sujith528f0c62008-10-29 10:14:26 +05301449static void assign_aggr_tid_seqno(struct sk_buff *skb,
1450 struct ath_buf *bf)
1451{
1452 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1453 struct ieee80211_hdr *hdr;
1454 struct ath_node *an;
1455 struct ath_atx_tid *tid;
1456 __le16 fc;
1457 u8 *qc;
1458
1459 if (!tx_info->control.sta)
1460 return;
1461
1462 an = (struct ath_node *)tx_info->control.sta->drv_priv;
1463 hdr = (struct ieee80211_hdr *)skb->data;
1464 fc = hdr->frame_control;
1465
Sujith528f0c62008-10-29 10:14:26 +05301466 if (ieee80211_is_data_qos(fc)) {
1467 qc = ieee80211_get_qos_ctl(hdr);
1468 bf->bf_tidno = qc[0] & 0xf;
Sujith98deeea2008-08-11 14:05:46 +05301469 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001470
Sujithe8324352009-01-16 21:38:42 +05301471 /*
1472 * For HT capable stations, we save tidno for later use.
Senthil Balasubramaniand3a1db12008-12-22 16:31:58 +05301473 * We also override seqno set by upper layer with the one
1474 * in tx aggregation state.
1475 *
1476 * If fragmentation is on, the sequence number is
1477 * not overridden, since it has been
1478 * incremented by the fragmentation routine.
1479 *
1480 * FIXME: check if the fragmentation threshold exceeds
1481 * IEEE80211 max.
1482 */
1483 tid = ATH_AN_2_TID(an, bf->bf_tidno);
1484 hdr->seq_ctrl = cpu_to_le16(tid->seq_next <<
1485 IEEE80211_SEQ_SEQ_SHIFT);
1486 bf->bf_seqno = tid->seq_next;
1487 INCR(tid->seq_next, IEEE80211_SEQ_MAX);
Sujith528f0c62008-10-29 10:14:26 +05301488}
1489
1490static int setup_tx_flags(struct ath_softc *sc, struct sk_buff *skb,
1491 struct ath_txq *txq)
1492{
1493 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1494 int flags = 0;
1495
1496 flags |= ATH9K_TXDESC_CLRDMASK; /* needed for crypto errors */
1497 flags |= ATH9K_TXDESC_INTREQ;
1498
1499 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
1500 flags |= ATH9K_TXDESC_NOACK;
1501 if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
1502 flags |= ATH9K_TXDESC_RTSENA;
1503
1504 return flags;
1505}
1506
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001507/*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001508 * rix - rate index
1509 * pktlen - total bytes (delims + data + fcs + pads + pad delims)
1510 * width - 0 for 20 MHz, 1 for 40 MHz
1511 * half_gi - to use 4us v/s 3.6 us for symbol time
1512 */
Sujith102e0572008-10-29 10:15:16 +05301513static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, struct ath_buf *bf,
1514 int width, int half_gi, bool shortPreamble)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001515{
Sujith3706de62008-12-07 21:42:10 +05301516 struct ath_rate_table *rate_table = sc->cur_rate_table;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001517 u32 nbits, nsymbits, duration, nsymbols;
1518 u8 rc;
1519 int streams, pktlen;
1520
Sujithcd3d39a2008-08-11 14:03:34 +05301521 pktlen = bf_isaggr(bf) ? bf->bf_al : bf->bf_frmlen;
Sujithe63835b2008-11-18 09:07:53 +05301522 rc = rate_table->info[rix].ratecode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001523
Sujithe63835b2008-11-18 09:07:53 +05301524 /* for legacy rates, use old function to compute packet duration */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001525 if (!IS_HT_RATE(rc))
Sujithe63835b2008-11-18 09:07:53 +05301526 return ath9k_hw_computetxtime(sc->sc_ah, rate_table, pktlen,
1527 rix, shortPreamble);
1528
1529 /* find number of symbols: PLCP + data */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001530 nbits = (pktlen << 3) + OFDM_PLCP_BITS;
1531 nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
1532 nsymbols = (nbits + nsymbits - 1) / nsymbits;
1533
1534 if (!half_gi)
1535 duration = SYMBOL_TIME(nsymbols);
1536 else
1537 duration = SYMBOL_TIME_HALFGI(nsymbols);
1538
Sujithe63835b2008-11-18 09:07:53 +05301539 /* addup duration for legacy/ht training and signal fields */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001540 streams = HT_RC_2_STREAMS(rc);
1541 duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
Sujith102e0572008-10-29 10:15:16 +05301542
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001543 return duration;
1544}
1545
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001546static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
1547{
1548 struct ath_hal *ah = sc->sc_ah;
Sujithe63835b2008-11-18 09:07:53 +05301549 struct ath_rate_table *rt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001550 struct ath_desc *ds = bf->bf_desc;
1551 struct ath_desc *lastds = bf->bf_lastbf->bf_desc;
1552 struct ath9k_11n_rate_series series[4];
Sujith528f0c62008-10-29 10:14:26 +05301553 struct sk_buff *skb;
1554 struct ieee80211_tx_info *tx_info;
Sujitha8efee42008-11-18 09:07:30 +05301555 struct ieee80211_tx_rate *rates;
Sujithe63835b2008-11-18 09:07:53 +05301556 struct ieee80211_hdr *hdr;
Luis R. Rodriguez96742252008-12-23 15:58:38 -08001557 struct ieee80211_hw *hw = sc->hw;
1558 int i, flags, rtsctsena = 0, enable_g_protection = 0;
Sujithe63835b2008-11-18 09:07:53 +05301559 u32 ctsduration = 0;
1560 u8 rix = 0, cix, ctsrate = 0;
1561 __le16 fc;
1562
1563 memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4);
Sujith528f0c62008-10-29 10:14:26 +05301564
1565 skb = (struct sk_buff *)bf->bf_mpdu;
Sujithe63835b2008-11-18 09:07:53 +05301566 hdr = (struct ieee80211_hdr *)skb->data;
1567 fc = hdr->frame_control;
Sujith528f0c62008-10-29 10:14:26 +05301568 tx_info = IEEE80211_SKB_CB(skb);
Sujithe63835b2008-11-18 09:07:53 +05301569 rates = tx_info->control.rates;
Sujith528f0c62008-10-29 10:14:26 +05301570
Sujithe63835b2008-11-18 09:07:53 +05301571 if (ieee80211_has_morefrags(fc) ||
1572 (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG)) {
1573 rates[1].count = rates[2].count = rates[3].count = 0;
1574 rates[1].idx = rates[2].idx = rates[3].idx = 0;
1575 rates[0].count = ATH_TXMAXTRY;
1576 }
1577
1578 /* get the cix for the lowest valid rix */
Sujith3706de62008-12-07 21:42:10 +05301579 rt = sc->cur_rate_table;
Sujitha8efee42008-11-18 09:07:30 +05301580 for (i = 3; i >= 0; i--) {
Sujithe63835b2008-11-18 09:07:53 +05301581 if (rates[i].count && (rates[i].idx >= 0)) {
Sujitha8efee42008-11-18 09:07:30 +05301582 rix = rates[i].idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001583 break;
1584 }
1585 }
Sujithe63835b2008-11-18 09:07:53 +05301586
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001587 flags = (bf->bf_flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA));
Sujithe63835b2008-11-18 09:07:53 +05301588 cix = rt->info[rix].ctrl_rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001589
Luis R. Rodriguez96742252008-12-23 15:58:38 -08001590 /* All protection frames are transmited at 2Mb/s for 802.11g,
1591 * otherwise we transmit them at 1Mb/s */
1592 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ &&
1593 !conf_is_ht(&hw->conf))
1594 enable_g_protection = 1;
1595
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001596 /*
Sujithe63835b2008-11-18 09:07:53 +05301597 * If 802.11g protection is enabled, determine whether to use RTS/CTS or
1598 * just CTS. Note that this is only done for OFDM/HT unicast frames.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001599 */
Sujithe63835b2008-11-18 09:07:53 +05301600 if (sc->sc_protmode != PROT_M_NONE && !(bf->bf_flags & ATH9K_TXDESC_NOACK)
Sujith46d14a52008-11-18 09:08:13 +05301601 && (rt->info[rix].phy == WLAN_RC_PHY_OFDM ||
Sujithe63835b2008-11-18 09:07:53 +05301602 WLAN_RC_PHY_HT(rt->info[rix].phy))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001603 if (sc->sc_protmode == PROT_M_RTSCTS)
1604 flags = ATH9K_TXDESC_RTSENA;
1605 else if (sc->sc_protmode == PROT_M_CTSONLY)
1606 flags = ATH9K_TXDESC_CTSENA;
1607
Luis R. Rodriguez96742252008-12-23 15:58:38 -08001608 cix = rt->info[enable_g_protection].ctrl_rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001609 rtsctsena = 1;
1610 }
1611
Sujithe63835b2008-11-18 09:07:53 +05301612 /* For 11n, the default behavior is to enable RTS for hw retried frames.
1613 * We enable the global flag here and let rate series flags determine
1614 * which rates will actually use RTS.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001615 */
Sujithcd3d39a2008-08-11 14:03:34 +05301616 if ((ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) && bf_isdata(bf)) {
Sujithe63835b2008-11-18 09:07:53 +05301617 /* 802.11g protection not needed, use our default behavior */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001618 if (!rtsctsena)
1619 flags = ATH9K_TXDESC_RTSENA;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001620 }
1621
Sujithe63835b2008-11-18 09:07:53 +05301622 /* Set protection if aggregate protection on */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001623 if (sc->sc_config.ath_aggr_prot &&
Sujithcd3d39a2008-08-11 14:03:34 +05301624 (!bf_isaggr(bf) || (bf_isaggr(bf) && bf->bf_al < 8192))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001625 flags = ATH9K_TXDESC_RTSENA;
Luis R. Rodriguez96742252008-12-23 15:58:38 -08001626 cix = rt->info[enable_g_protection].ctrl_rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001627 rtsctsena = 1;
1628 }
1629
Sujithe63835b2008-11-18 09:07:53 +05301630 /* For AR5416 - RTS cannot be followed by a frame larger than 8K */
1631 if (bf_isaggr(bf) && (bf->bf_al > ah->ah_caps.rts_aggr_limit))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001632 flags &= ~(ATH9K_TXDESC_RTSENA);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001633
1634 /*
Sujithe63835b2008-11-18 09:07:53 +05301635 * CTS transmit rate is derived from the transmit rate by looking in the
1636 * h/w rate table. We must also factor in whether or not a short
1637 * preamble is to be used. NB: cix is set above where RTS/CTS is enabled
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001638 */
Sujithe63835b2008-11-18 09:07:53 +05301639 ctsrate = rt->info[cix].ratecode |
1640 (bf_isshpreamble(bf) ? rt->info[cix].short_preamble : 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001641
1642 for (i = 0; i < 4; i++) {
Sujithe63835b2008-11-18 09:07:53 +05301643 if (!rates[i].count || (rates[i].idx < 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001644 continue;
1645
Sujitha8efee42008-11-18 09:07:30 +05301646 rix = rates[i].idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001647
Sujithe63835b2008-11-18 09:07:53 +05301648 series[i].Rate = rt->info[rix].ratecode |
1649 (bf_isshpreamble(bf) ? rt->info[rix].short_preamble : 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001650
Sujitha8efee42008-11-18 09:07:30 +05301651 series[i].Tries = rates[i].count;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001652
1653 series[i].RateFlags = (
Sujitha8efee42008-11-18 09:07:30 +05301654 (rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) ?
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001655 ATH9K_RATESERIES_RTS_CTS : 0) |
Sujitha8efee42008-11-18 09:07:30 +05301656 ((rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ?
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001657 ATH9K_RATESERIES_2040 : 0) |
Sujitha8efee42008-11-18 09:07:30 +05301658 ((rates[i].flags & IEEE80211_TX_RC_SHORT_GI) ?
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001659 ATH9K_RATESERIES_HALFGI : 0);
1660
Sujith102e0572008-10-29 10:15:16 +05301661 series[i].PktDuration = ath_pkt_duration(sc, rix, bf,
Sujitha8efee42008-11-18 09:07:30 +05301662 (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) != 0,
1663 (rates[i].flags & IEEE80211_TX_RC_SHORT_GI),
Sujith102e0572008-10-29 10:15:16 +05301664 bf_isshpreamble(bf));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001665
Sujithff37e332008-11-24 12:07:55 +05301666 series[i].ChSel = sc->sc_tx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001667
1668 if (rtsctsena)
1669 series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001670 }
1671
Sujithe63835b2008-11-18 09:07:53 +05301672 /* set dur_update_en for l-sig computation except for PS-Poll frames */
1673 ath9k_hw_set11n_ratescenario(ah, ds, lastds, !bf_ispspoll(bf),
1674 ctsrate, ctsduration,
Sujithcd3d39a2008-08-11 14:03:34 +05301675 series, 4, flags);
Sujith102e0572008-10-29 10:15:16 +05301676
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001677 if (sc->sc_config.ath_aggr_prot && flags)
1678 ath9k_hw_set11n_burstduration(ah, ds, 8192);
1679}
1680
Sujithe8324352009-01-16 21:38:42 +05301681static int ath_tx_setup_buffer(struct ath_softc *sc, struct ath_buf *bf,
1682 struct sk_buff *skb,
1683 struct ath_tx_control *txctl)
1684{
1685 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1686 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1687 struct ath_tx_info_priv *tx_info_priv;
1688 int hdrlen;
1689 __le16 fc;
1690
1691 tx_info_priv = kzalloc(sizeof(*tx_info_priv), GFP_ATOMIC);
1692 if (unlikely(!tx_info_priv))
1693 return -ENOMEM;
1694 tx_info->rate_driver_data[0] = tx_info_priv;
1695 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1696 fc = hdr->frame_control;
1697
1698 ATH_TXBUF_RESET(bf);
1699
1700 bf->bf_frmlen = skb->len + FCS_LEN - (hdrlen & 3);
1701
1702 ieee80211_is_data(fc) ?
1703 (bf->bf_state.bf_type |= BUF_DATA) :
1704 (bf->bf_state.bf_type &= ~BUF_DATA);
1705 ieee80211_is_back_req(fc) ?
1706 (bf->bf_state.bf_type |= BUF_BAR) :
1707 (bf->bf_state.bf_type &= ~BUF_BAR);
1708 ieee80211_is_pspoll(fc) ?
1709 (bf->bf_state.bf_type |= BUF_PSPOLL) :
1710 (bf->bf_state.bf_type &= ~BUF_PSPOLL);
1711 (sc->sc_flags & SC_OP_PREAMBLE_SHORT) ?
1712 (bf->bf_state.bf_type |= BUF_SHORT_PREAMBLE) :
1713 (bf->bf_state.bf_type &= ~BUF_SHORT_PREAMBLE);
1714 (conf_is_ht(&sc->hw->conf) && !is_pae(skb) &&
1715 (tx_info->flags & IEEE80211_TX_CTL_AMPDU)) ?
1716 (bf->bf_state.bf_type |= BUF_HT) :
1717 (bf->bf_state.bf_type &= ~BUF_HT);
1718
1719 bf->bf_flags = setup_tx_flags(sc, skb, txctl->txq);
1720
1721 bf->bf_keytype = get_hw_crypto_keytype(skb);
1722
1723 if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR) {
1724 bf->bf_frmlen += tx_info->control.hw_key->icv_len;
1725 bf->bf_keyix = tx_info->control.hw_key->hw_key_idx;
1726 } else {
1727 bf->bf_keyix = ATH9K_TXKEYIX_INVALID;
1728 }
1729
1730 if (ieee80211_is_data_qos(fc) && (sc->sc_flags & SC_OP_TXAGGR))
1731 assign_aggr_tid_seqno(skb, bf);
1732
1733 bf->bf_mpdu = skb;
1734
1735 bf->bf_dmacontext = dma_map_single(sc->dev, skb->data,
1736 skb->len, DMA_TO_DEVICE);
1737 if (unlikely(dma_mapping_error(sc->dev, bf->bf_dmacontext))) {
1738 bf->bf_mpdu = NULL;
1739 DPRINTF(sc, ATH_DBG_CONFIG,
1740 "dma_mapping_error() on TX\n");
1741 return -ENOMEM;
1742 }
1743
1744 bf->bf_buf_addr = bf->bf_dmacontext;
1745 return 0;
1746}
1747
1748/* FIXME: tx power */
1749static void ath_tx_start_dma(struct ath_softc *sc, struct ath_buf *bf,
1750 struct ath_tx_control *txctl)
1751{
1752 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
1753 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1754 struct ath_node *an = NULL;
1755 struct list_head bf_head;
1756 struct ath_desc *ds;
1757 struct ath_atx_tid *tid;
1758 struct ath_hal *ah = sc->sc_ah;
1759 int frm_type;
1760
1761 frm_type = get_hw_packet_type(skb);
1762
1763 INIT_LIST_HEAD(&bf_head);
1764 list_add_tail(&bf->list, &bf_head);
1765
1766 ds = bf->bf_desc;
1767 ds->ds_link = 0;
1768 ds->ds_data = bf->bf_buf_addr;
1769
1770 ath9k_hw_set11n_txdesc(ah, ds, bf->bf_frmlen, frm_type, MAX_RATE_POWER,
1771 bf->bf_keyix, bf->bf_keytype, bf->bf_flags);
1772
1773 ath9k_hw_filltxdesc(ah, ds,
1774 skb->len, /* segment length */
1775 true, /* first segment */
1776 true, /* last segment */
1777 ds); /* first descriptor */
1778
1779 bf->bf_lastfrm = bf;
1780
1781 spin_lock_bh(&txctl->txq->axq_lock);
1782
1783 if (bf_isht(bf) && (sc->sc_flags & SC_OP_TXAGGR) &&
1784 tx_info->control.sta) {
1785 an = (struct ath_node *)tx_info->control.sta->drv_priv;
1786 tid = ATH_AN_2_TID(an, bf->bf_tidno);
1787
1788 if (ath_aggr_query(sc, an, bf->bf_tidno)) {
1789 /*
1790 * Try aggregation if it's a unicast data frame
1791 * and the destination is HT capable.
1792 */
1793 ath_tx_send_ampdu(sc, tid, &bf_head, txctl);
1794 } else {
1795 /*
1796 * Send this frame as regular when ADDBA
1797 * exchange is neither complete nor pending.
1798 */
1799 ath_tx_send_normal(sc, txctl->txq,
1800 tid, &bf_head);
1801 }
1802 } else {
1803 bf->bf_lastbf = bf;
1804 bf->bf_nframes = 1;
1805
1806 ath_buf_set_rate(sc, bf);
1807 ath_tx_txqaddbuf(sc, txctl->txq, &bf_head);
1808 }
1809
1810 spin_unlock_bh(&txctl->txq->axq_lock);
1811}
1812
1813/* Upon failure caller should free skb */
1814int ath_tx_start(struct ath_softc *sc, struct sk_buff *skb,
1815 struct ath_tx_control *txctl)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001816{
1817 struct ath_buf *bf;
Sujithe8324352009-01-16 21:38:42 +05301818 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001819
Sujithe8324352009-01-16 21:38:42 +05301820 bf = ath_tx_get_buffer(sc);
1821 if (!bf) {
1822 DPRINTF(sc, ATH_DBG_XMIT, "TX buffers are full\n");
1823 return -1;
1824 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001825
Sujithe8324352009-01-16 21:38:42 +05301826 r = ath_tx_setup_buffer(sc, bf, skb, txctl);
1827 if (unlikely(r)) {
1828 struct ath_txq *txq = txctl->txq;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001829
Sujithe8324352009-01-16 21:38:42 +05301830 DPRINTF(sc, ATH_DBG_FATAL, "TX mem alloc failure\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001831
Sujithe8324352009-01-16 21:38:42 +05301832 /* upon ath_tx_processq() this TX queue will be resumed, we
1833 * guarantee this will happen by knowing beforehand that
1834 * we will at least have to run TX completionon one buffer
1835 * on the queue */
1836 spin_lock_bh(&txq->axq_lock);
1837 if (ath_txq_depth(sc, txq->axq_qnum) > 1) {
1838 ieee80211_stop_queue(sc->hw,
1839 skb_get_queue_mapping(skb));
1840 txq->stopped = 1;
1841 }
1842 spin_unlock_bh(&txq->axq_lock);
1843
1844 spin_lock_bh(&sc->tx.txbuflock);
1845 list_add_tail(&bf->list, &sc->tx.txbuf);
1846 spin_unlock_bh(&sc->tx.txbuflock);
1847
1848 return r;
1849 }
1850
1851 ath_tx_start_dma(sc, bf, txctl);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001852
1853 return 0;
1854}
1855
Sujithe8324352009-01-16 21:38:42 +05301856void ath_tx_cabq(struct ath_softc *sc, struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001857{
Sujithe8324352009-01-16 21:38:42 +05301858 int hdrlen, padsize;
1859 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1860 struct ath_tx_control txctl;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001861
Sujithe8324352009-01-16 21:38:42 +05301862 memset(&txctl, 0, sizeof(struct ath_tx_control));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001863
Sujithe8324352009-01-16 21:38:42 +05301864 /*
1865 * As a temporary workaround, assign seq# here; this will likely need
1866 * to be cleaned up to work better with Beacon transmission and virtual
1867 * BSSes.
1868 */
1869 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1870 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1871 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
1872 sc->tx.seq_no += 0x10;
1873 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1874 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001875 }
1876
Sujithe8324352009-01-16 21:38:42 +05301877 /* Add the padding after the header if this is not already done */
1878 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1879 if (hdrlen & 3) {
1880 padsize = hdrlen % 4;
1881 if (skb_headroom(skb) < padsize) {
1882 DPRINTF(sc, ATH_DBG_XMIT, "TX CABQ padding failed\n");
1883 dev_kfree_skb_any(skb);
1884 return;
1885 }
1886 skb_push(skb, padsize);
1887 memmove(skb->data, skb->data + padsize, hdrlen);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001888 }
1889
Sujithe8324352009-01-16 21:38:42 +05301890 txctl.txq = sc->beacon.cabq;
1891
1892 DPRINTF(sc, ATH_DBG_XMIT, "transmitting CABQ packet, skb: %p\n", skb);
1893
1894 if (ath_tx_start(sc, skb, &txctl) != 0) {
1895 DPRINTF(sc, ATH_DBG_XMIT, "CABQ TX failed\n");
1896 goto exit;
1897 }
1898
1899 return;
1900exit:
1901 dev_kfree_skb_any(skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001902}
1903
Sujithe8324352009-01-16 21:38:42 +05301904/*****************/
1905/* TX Completion */
1906/*****************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001907
Sujithe8324352009-01-16 21:38:42 +05301908static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
1909 struct ath_xmit_status *tx_status)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001910{
Sujithe8324352009-01-16 21:38:42 +05301911 struct ieee80211_hw *hw = sc->hw;
1912 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1913 struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
1914 int hdrlen, padsize;
1915
1916 DPRINTF(sc, ATH_DBG_XMIT, "TX complete: skb: %p\n", skb);
1917
1918 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK ||
1919 tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
1920 kfree(tx_info_priv);
1921 tx_info->rate_driver_data[0] = NULL;
1922 }
1923
1924 if (tx_status->flags & ATH_TX_BAR) {
1925 tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
1926 tx_status->flags &= ~ATH_TX_BAR;
1927 }
1928
1929 if (!(tx_status->flags & (ATH_TX_ERROR | ATH_TX_XRETRY))) {
1930 /* Frame was ACKed */
1931 tx_info->flags |= IEEE80211_TX_STAT_ACK;
1932 }
1933
1934 tx_info->status.rates[0].count = tx_status->retries + 1;
1935
1936 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1937 padsize = hdrlen & 3;
1938 if (padsize && hdrlen >= 24) {
1939 /*
1940 * Remove MAC header padding before giving the frame back to
1941 * mac80211.
1942 */
1943 memmove(skb->data + padsize, skb->data, hdrlen);
1944 skb_pull(skb, padsize);
1945 }
1946
1947 ieee80211_tx_status(hw, skb);
1948}
1949
1950static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
1951 struct list_head *bf_q,
1952 int txok, int sendbar)
1953{
1954 struct sk_buff *skb = bf->bf_mpdu;
1955 struct ath_xmit_status tx_status;
1956 unsigned long flags;
1957
1958 /*
1959 * Set retry information.
1960 * NB: Don't use the information in the descriptor, because the frame
1961 * could be software retried.
1962 */
1963 tx_status.retries = bf->bf_retries;
1964 tx_status.flags = 0;
1965
1966 if (sendbar)
1967 tx_status.flags = ATH_TX_BAR;
1968
1969 if (!txok) {
1970 tx_status.flags |= ATH_TX_ERROR;
1971
1972 if (bf_isxretried(bf))
1973 tx_status.flags |= ATH_TX_XRETRY;
1974 }
1975
1976 dma_unmap_single(sc->dev, bf->bf_dmacontext, skb->len, DMA_TO_DEVICE);
1977 ath_tx_complete(sc, skb, &tx_status);
1978
1979 /*
1980 * Return the list of ath_buf of this mpdu to free queue
1981 */
1982 spin_lock_irqsave(&sc->tx.txbuflock, flags);
1983 list_splice_tail_init(bf_q, &sc->tx.txbuf);
1984 spin_unlock_irqrestore(&sc->tx.txbuflock, flags);
1985}
1986
1987static int ath_tx_num_badfrms(struct ath_softc *sc, struct ath_buf *bf,
1988 int txok)
1989{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001990 struct ath_buf *bf_last = bf->bf_lastbf;
1991 struct ath_desc *ds = bf_last->bf_desc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001992 u16 seq_st = 0;
1993 u32 ba[WME_BA_BMP_SIZE >> 5];
Sujithe8324352009-01-16 21:38:42 +05301994 int ba_index;
1995 int nbad = 0;
1996 int isaggr = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001997
Sujithe8324352009-01-16 21:38:42 +05301998 if (ds->ds_txstat.ts_flags == ATH9K_TX_SW_ABORTED)
1999 return 0;
Sujith528f0c62008-10-29 10:14:26 +05302000
Sujithcd3d39a2008-08-11 14:03:34 +05302001 isaggr = bf_isaggr(bf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002002 if (isaggr) {
Sujithe8324352009-01-16 21:38:42 +05302003 seq_st = ATH_DS_BA_SEQ(ds);
2004 memcpy(ba, ATH_DS_BA_BITMAP(ds), WME_BA_BMP_SIZE >> 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002005 }
2006
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002007 while (bf) {
Sujithe8324352009-01-16 21:38:42 +05302008 ba_index = ATH_BA_INDEX(seq_st, bf->bf_seqno);
2009 if (!txok || (isaggr && !ATH_BA_ISSET(ba, ba_index)))
2010 nbad++;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002011
Sujithe8324352009-01-16 21:38:42 +05302012 bf = bf->bf_next;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002013 }
2014
Sujithe8324352009-01-16 21:38:42 +05302015 return nbad;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002016}
2017
Sujithc4288392008-11-18 09:09:30 +05302018static void ath_tx_rc_status(struct ath_buf *bf, struct ath_desc *ds, int nbad)
2019{
2020 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
2021 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
2022 struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
2023
Vasanthakumar Thiagarajan7ac47012008-11-20 11:51:18 +05302024 tx_info_priv->update_rc = false;
Sujithc4288392008-11-18 09:09:30 +05302025 if (ds->ds_txstat.ts_status & ATH9K_TXERR_FILT)
2026 tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
2027
2028 if ((ds->ds_txstat.ts_status & ATH9K_TXERR_FILT) == 0 &&
2029 (bf->bf_flags & ATH9K_TXDESC_NOACK) == 0) {
2030 if (bf_isdata(bf)) {
2031 memcpy(&tx_info_priv->tx, &ds->ds_txstat,
2032 sizeof(tx_info_priv->tx));
2033 tx_info_priv->n_frames = bf->bf_nframes;
2034 tx_info_priv->n_bad_frames = nbad;
Vasanthakumar Thiagarajan7ac47012008-11-20 11:51:18 +05302035 tx_info_priv->update_rc = true;
Sujithc4288392008-11-18 09:09:30 +05302036 }
2037 }
2038}
2039
Sujithc4288392008-11-18 09:09:30 +05302040static void ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002041{
2042 struct ath_hal *ah = sc->sc_ah;
2043 struct ath_buf *bf, *lastbf, *bf_held = NULL;
2044 struct list_head bf_head;
Sujithc4288392008-11-18 09:09:30 +05302045 struct ath_desc *ds;
2046 int txok, nbad = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002047 int status;
2048
Sujith04bd46382008-11-28 22:18:05 +05302049 DPRINTF(sc, ATH_DBG_QUEUE, "tx queue %d (%x), link %p\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002050 txq->axq_qnum, ath9k_hw_gettxbuf(sc->sc_ah, txq->axq_qnum),
2051 txq->axq_link);
2052
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002053 for (;;) {
2054 spin_lock_bh(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002055 if (list_empty(&txq->axq_q)) {
2056 txq->axq_link = NULL;
2057 txq->axq_linkbuf = NULL;
2058 spin_unlock_bh(&txq->axq_lock);
2059 break;
2060 }
2061 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
2062
2063 /*
2064 * There is a race condition that a BH gets scheduled
2065 * after sw writes TxE and before hw re-load the last
2066 * descriptor to get the newly chained one.
2067 * Software must keep the last DONE descriptor as a
2068 * holding descriptor - software does so by marking
2069 * it with the STALE flag.
2070 */
2071 bf_held = NULL;
2072 if (bf->bf_status & ATH_BUFSTATUS_STALE) {
2073 bf_held = bf;
2074 if (list_is_last(&bf_held->list, &txq->axq_q)) {
2075 /* FIXME:
2076 * The holding descriptor is the last
2077 * descriptor in queue. It's safe to remove
2078 * the last holding descriptor in BH context.
2079 */
2080 spin_unlock_bh(&txq->axq_lock);
2081 break;
2082 } else {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002083 bf = list_entry(bf_held->list.next,
2084 struct ath_buf, list);
2085 }
2086 }
2087
2088 lastbf = bf->bf_lastbf;
Sujithe8324352009-01-16 21:38:42 +05302089 ds = lastbf->bf_desc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002090
2091 status = ath9k_hw_txprocdesc(ah, ds);
2092 if (status == -EINPROGRESS) {
2093 spin_unlock_bh(&txq->axq_lock);
2094 break;
2095 }
2096 if (bf->bf_desc == txq->axq_lastdsWithCTS)
2097 txq->axq_lastdsWithCTS = NULL;
2098 if (ds == txq->axq_gatingds)
2099 txq->axq_gatingds = NULL;
2100
2101 /*
2102 * Remove ath_buf's of the same transmit unit from txq,
2103 * however leave the last descriptor back as the holding
2104 * descriptor for hw.
2105 */
2106 lastbf->bf_status |= ATH_BUFSTATUS_STALE;
2107 INIT_LIST_HEAD(&bf_head);
2108
2109 if (!list_is_singular(&lastbf->list))
2110 list_cut_position(&bf_head,
2111 &txq->axq_q, lastbf->list.prev);
2112
2113 txq->axq_depth--;
2114
Sujithcd3d39a2008-08-11 14:03:34 +05302115 if (bf_isaggr(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002116 txq->axq_aggr_depth--;
2117
2118 txok = (ds->ds_txstat.ts_status == 0);
2119
2120 spin_unlock_bh(&txq->axq_lock);
2121
2122 if (bf_held) {
2123 list_del(&bf_held->list);
Sujithb77f4832008-12-07 21:44:03 +05302124 spin_lock_bh(&sc->tx.txbuflock);
2125 list_add_tail(&bf_held->list, &sc->tx.txbuf);
2126 spin_unlock_bh(&sc->tx.txbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002127 }
2128
Sujithcd3d39a2008-08-11 14:03:34 +05302129 if (!bf_isampdu(bf)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002130 /*
2131 * This frame is sent out as a single frame.
2132 * Use hardware retry status for this frame.
2133 */
2134 bf->bf_retries = ds->ds_txstat.ts_longretry;
2135 if (ds->ds_txstat.ts_status & ATH9K_TXERR_XRETRY)
Sujithcd3d39a2008-08-11 14:03:34 +05302136 bf->bf_state.bf_type |= BUF_XRETRY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002137 nbad = 0;
2138 } else {
2139 nbad = ath_tx_num_badfrms(sc, bf, txok);
2140 }
Johannes Berge6a98542008-10-21 12:40:02 +02002141
Sujithc4288392008-11-18 09:09:30 +05302142 ath_tx_rc_status(bf, ds, nbad);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002143
Sujithcd3d39a2008-08-11 14:03:34 +05302144 if (bf_isampdu(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002145 ath_tx_complete_aggr_rifs(sc, txq, bf, &bf_head, txok);
2146 else
2147 ath_tx_complete_buf(sc, bf, &bf_head, txok, 0);
2148
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002149 spin_lock_bh(&txq->axq_lock);
2150 if (txq->stopped && ath_txq_depth(sc, txq->axq_qnum) <=
2151 (ATH_TXBUF - 20)) {
2152 int qnum;
2153 qnum = ath_get_mac80211_qnum(txq->axq_qnum, sc);
2154 if (qnum != -1) {
2155 ieee80211_wake_queue(sc->hw, qnum);
2156 txq->stopped = 0;
2157 }
2158
2159 }
2160
Sujith672840a2008-08-11 14:05:08 +05302161 if (sc->sc_flags & SC_OP_TXAGGR)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002162 ath_txq_schedule(sc, txq);
2163 spin_unlock_bh(&txq->axq_lock);
2164 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002165}
2166
Sujithe8324352009-01-16 21:38:42 +05302167
2168void ath_tx_tasklet(struct ath_softc *sc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002169{
Sujithe8324352009-01-16 21:38:42 +05302170 int i;
2171 u32 qcumask = ((1 << ATH9K_NUM_TX_QUEUES) - 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002172
Sujithe8324352009-01-16 21:38:42 +05302173 ath9k_hw_gettxintrtxqs(sc->sc_ah, &qcumask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002174
2175 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
Sujithe8324352009-01-16 21:38:42 +05302176 if (ATH_TXQ_SETUP(sc, i) && (qcumask & (1 << i)))
2177 ath_tx_processq(sc, &sc->tx.txq[i]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002178 }
2179}
2180
Sujithe8324352009-01-16 21:38:42 +05302181/*****************/
2182/* Init, Cleanup */
2183/*****************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002184
2185int ath_tx_init(struct ath_softc *sc, int nbufs)
2186{
2187 int error = 0;
2188
2189 do {
Sujithb77f4832008-12-07 21:44:03 +05302190 spin_lock_init(&sc->tx.txbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002191
Sujithb77f4832008-12-07 21:44:03 +05302192 error = ath_descdma_setup(sc, &sc->tx.txdma, &sc->tx.txbuf,
Sujith556bb8f2008-08-11 14:03:53 +05302193 "tx", nbufs, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002194 if (error != 0) {
2195 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05302196 "Failed to allocate tx descriptors: %d\n",
2197 error);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002198 break;
2199 }
2200
Sujithb77f4832008-12-07 21:44:03 +05302201 error = ath_descdma_setup(sc, &sc->beacon.bdma, &sc->beacon.bbuf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002202 "beacon", ATH_BCBUF, 1);
2203 if (error != 0) {
2204 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05302205 "Failed to allocate beacon descriptors: %d\n",
2206 error);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002207 break;
2208 }
2209
2210 } while (0);
2211
2212 if (error != 0)
2213 ath_tx_cleanup(sc);
2214
2215 return error;
2216}
2217
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002218int ath_tx_cleanup(struct ath_softc *sc)
2219{
Sujithb77f4832008-12-07 21:44:03 +05302220 if (sc->beacon.bdma.dd_desc_len != 0)
2221 ath_descdma_cleanup(sc, &sc->beacon.bdma, &sc->beacon.bbuf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002222
Sujithb77f4832008-12-07 21:44:03 +05302223 if (sc->tx.txdma.dd_desc_len != 0)
2224 ath_descdma_cleanup(sc, &sc->tx.txdma, &sc->tx.txbuf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002225
2226 return 0;
2227}
2228
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002229void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an)
2230{
Sujithc5170162008-10-29 10:13:59 +05302231 struct ath_atx_tid *tid;
2232 struct ath_atx_ac *ac;
2233 int tidno, acno;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002234
Sujith8ee5afb2008-12-07 21:43:36 +05302235 for (tidno = 0, tid = &an->tid[tidno];
Sujithc5170162008-10-29 10:13:59 +05302236 tidno < WME_NUM_TID;
2237 tidno++, tid++) {
2238 tid->an = an;
2239 tid->tidno = tidno;
2240 tid->seq_start = tid->seq_next = 0;
2241 tid->baw_size = WME_MAX_BA;
2242 tid->baw_head = tid->baw_tail = 0;
2243 tid->sched = false;
Sujithe8324352009-01-16 21:38:42 +05302244 tid->paused = false;
Sujitha37c2c72008-10-29 10:15:40 +05302245 tid->state &= ~AGGR_CLEANUP;
Sujithc5170162008-10-29 10:13:59 +05302246 INIT_LIST_HEAD(&tid->buf_q);
Sujithc5170162008-10-29 10:13:59 +05302247 acno = TID_TO_WME_AC(tidno);
Sujith8ee5afb2008-12-07 21:43:36 +05302248 tid->ac = &an->ac[acno];
Sujitha37c2c72008-10-29 10:15:40 +05302249 tid->state &= ~AGGR_ADDBA_COMPLETE;
2250 tid->state &= ~AGGR_ADDBA_PROGRESS;
2251 tid->addba_exchangeattempts = 0;
Sujithc5170162008-10-29 10:13:59 +05302252 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002253
Sujith8ee5afb2008-12-07 21:43:36 +05302254 for (acno = 0, ac = &an->ac[acno];
Sujithc5170162008-10-29 10:13:59 +05302255 acno < WME_NUM_AC; acno++, ac++) {
2256 ac->sched = false;
2257 INIT_LIST_HEAD(&ac->tid_q);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002258
Sujithc5170162008-10-29 10:13:59 +05302259 switch (acno) {
2260 case WME_AC_BE:
2261 ac->qnum = ath_tx_get_qnum(sc,
2262 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
2263 break;
2264 case WME_AC_BK:
2265 ac->qnum = ath_tx_get_qnum(sc,
2266 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BK);
2267 break;
2268 case WME_AC_VI:
2269 ac->qnum = ath_tx_get_qnum(sc,
2270 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VI);
2271 break;
2272 case WME_AC_VO:
2273 ac->qnum = ath_tx_get_qnum(sc,
2274 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VO);
2275 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002276 }
2277 }
2278}
2279
Sujithb5aa9bf2008-10-29 10:13:31 +05302280void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002281{
2282 int i;
2283 struct ath_atx_ac *ac, *ac_tmp;
2284 struct ath_atx_tid *tid, *tid_tmp;
2285 struct ath_txq *txq;
Sujithe8324352009-01-16 21:38:42 +05302286
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002287 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
2288 if (ATH_TXQ_SETUP(sc, i)) {
Sujithb77f4832008-12-07 21:44:03 +05302289 txq = &sc->tx.txq[i];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002290
Sujithb5aa9bf2008-10-29 10:13:31 +05302291 spin_lock(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002292
2293 list_for_each_entry_safe(ac,
2294 ac_tmp, &txq->axq_acq, list) {
2295 tid = list_first_entry(&ac->tid_q,
2296 struct ath_atx_tid, list);
2297 if (tid && tid->an != an)
2298 continue;
2299 list_del(&ac->list);
2300 ac->sched = false;
2301
2302 list_for_each_entry_safe(tid,
2303 tid_tmp, &ac->tid_q, list) {
2304 list_del(&tid->list);
2305 tid->sched = false;
Sujithb5aa9bf2008-10-29 10:13:31 +05302306 ath_tid_drain(sc, txq, tid);
Sujitha37c2c72008-10-29 10:15:40 +05302307 tid->state &= ~AGGR_ADDBA_COMPLETE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002308 tid->addba_exchangeattempts = 0;
Sujitha37c2c72008-10-29 10:15:40 +05302309 tid->state &= ~AGGR_CLEANUP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002310 }
2311 }
2312
Sujithb5aa9bf2008-10-29 10:13:31 +05302313 spin_unlock(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002314 }
2315 }
2316}