blob: c9ead1ba88da2619fa17dedd9b13beb855daba32 [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
Sujithe8324352009-01-16 21:38:42 +0530880static void ath_get_beaconconfig(struct ath_softc *sc, int if_id,
881 struct ath_beacon_config *conf)
882{
883 struct ieee80211_hw *hw = sc->hw;
884
885 /* fill in beacon config data */
886
887 conf->beacon_interval = hw->conf.beacon_int;
888 conf->listen_interval = 100;
889 conf->dtim_count = 1;
890 conf->bmiss_timeout = ATH_DEFAULT_BMISS_LIMIT * conf->listen_interval;
891}
892
893static void ath_drain_txdataq(struct ath_softc *sc, bool retry_tx)
894{
895 struct ath_hal *ah = sc->sc_ah;
Sujith55f5e4a2009-01-16 21:38:45 +0530896 struct ath_txq *txq;
Sujithe8324352009-01-16 21:38:42 +0530897 int i, npend = 0;
898
Sujith55f5e4a2009-01-16 21:38:45 +0530899 if (sc->sc_flags & SC_OP_INVALID)
900 return;
901
902 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
903 if (ATH_TXQ_SETUP(sc, i)) {
904 txq = &sc->tx.txq[i];
905 ath9k_hw_stoptxdma(ah, txq->axq_qnum);
906 npend += ath9k_hw_numtxpending(ah, txq->axq_qnum);
Sujithe8324352009-01-16 21:38:42 +0530907 }
908 }
909
910 if (npend) {
911 int r;
912
913 DPRINTF(sc, ATH_DBG_XMIT, "Unable to stop TxDMA. Reset HAL!\n");
914
915 spin_lock_bh(&sc->sc_resetlock);
916 r = ath9k_hw_reset(ah, sc->sc_ah->ah_curchan, true);
917 if (r)
918 DPRINTF(sc, ATH_DBG_FATAL,
919 "Unable to reset hardware; reset status %u\n",
920 r);
921 spin_unlock_bh(&sc->sc_resetlock);
922 }
923
924 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
925 if (ATH_TXQ_SETUP(sc, i))
926 ath_tx_draintxq(sc, &sc->tx.txq[i], retry_tx);
927 }
928}
929
930static void ath_txq_drain_pending_buffers(struct ath_softc *sc,
931 struct ath_txq *txq)
932{
933 struct ath_atx_ac *ac, *ac_tmp;
934 struct ath_atx_tid *tid, *tid_tmp;
935
936 list_for_each_entry_safe(ac, ac_tmp, &txq->axq_acq, list) {
937 list_del(&ac->list);
938 ac->sched = false;
939 list_for_each_entry_safe(tid, tid_tmp, &ac->tid_q, list) {
940 list_del(&tid->list);
941 tid->sched = false;
942 ath_tid_drain(sc, txq, tid);
943 }
944 }
945}
946
947struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype)
948{
949 struct ath_hal *ah = sc->sc_ah;
950 struct ath9k_tx_queue_info qi;
951 int qnum;
952
953 memset(&qi, 0, sizeof(qi));
954 qi.tqi_subtype = subtype;
955 qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT;
956 qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
957 qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT;
958 qi.tqi_physCompBuf = 0;
959
960 /*
961 * Enable interrupts only for EOL and DESC conditions.
962 * We mark tx descriptors to receive a DESC interrupt
963 * when a tx queue gets deep; otherwise waiting for the
964 * EOL to reap descriptors. Note that this is done to
965 * reduce interrupt load and this only defers reaping
966 * descriptors, never transmitting frames. Aside from
967 * reducing interrupts this also permits more concurrency.
968 * The only potential downside is if the tx queue backs
969 * up in which case the top half of the kernel may backup
970 * due to a lack of tx descriptors.
971 *
972 * The UAPSD queue is an exception, since we take a desc-
973 * based intr on the EOSP frames.
974 */
975 if (qtype == ATH9K_TX_QUEUE_UAPSD)
976 qi.tqi_qflags = TXQ_FLAG_TXDESCINT_ENABLE;
977 else
978 qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE |
979 TXQ_FLAG_TXDESCINT_ENABLE;
980 qnum = ath9k_hw_setuptxqueue(ah, qtype, &qi);
981 if (qnum == -1) {
982 /*
983 * NB: don't print a message, this happens
984 * normally on parts with too few tx queues
985 */
986 return NULL;
987 }
988 if (qnum >= ARRAY_SIZE(sc->tx.txq)) {
989 DPRINTF(sc, ATH_DBG_FATAL,
990 "qnum %u out of range, max %u!\n",
991 qnum, (unsigned int)ARRAY_SIZE(sc->tx.txq));
992 ath9k_hw_releasetxqueue(ah, qnum);
993 return NULL;
994 }
995 if (!ATH_TXQ_SETUP(sc, qnum)) {
996 struct ath_txq *txq = &sc->tx.txq[qnum];
997
998 txq->axq_qnum = qnum;
999 txq->axq_link = NULL;
1000 INIT_LIST_HEAD(&txq->axq_q);
1001 INIT_LIST_HEAD(&txq->axq_acq);
1002 spin_lock_init(&txq->axq_lock);
1003 txq->axq_depth = 0;
1004 txq->axq_aggr_depth = 0;
1005 txq->axq_totalqueued = 0;
1006 txq->axq_linkbuf = NULL;
1007 sc->tx.txqsetup |= 1<<qnum;
1008 }
1009 return &sc->tx.txq[qnum];
1010}
1011
1012static int ath_tx_get_qnum(struct ath_softc *sc, int qtype, int haltype)
1013{
1014 int qnum;
1015
1016 switch (qtype) {
1017 case ATH9K_TX_QUEUE_DATA:
1018 if (haltype >= ARRAY_SIZE(sc->tx.hwq_map)) {
1019 DPRINTF(sc, ATH_DBG_FATAL,
1020 "HAL AC %u out of range, max %zu!\n",
1021 haltype, ARRAY_SIZE(sc->tx.hwq_map));
1022 return -1;
1023 }
1024 qnum = sc->tx.hwq_map[haltype];
1025 break;
1026 case ATH9K_TX_QUEUE_BEACON:
1027 qnum = sc->beacon.beaconq;
1028 break;
1029 case ATH9K_TX_QUEUE_CAB:
1030 qnum = sc->beacon.cabq->axq_qnum;
1031 break;
1032 default:
1033 qnum = -1;
1034 }
1035 return qnum;
1036}
1037
1038struct ath_txq *ath_test_get_txq(struct ath_softc *sc, struct sk_buff *skb)
1039{
1040 struct ath_txq *txq = NULL;
1041 int qnum;
1042
1043 qnum = ath_get_hal_qnum(skb_get_queue_mapping(skb), sc);
1044 txq = &sc->tx.txq[qnum];
1045
1046 spin_lock_bh(&txq->axq_lock);
1047
1048 if (txq->axq_depth >= (ATH_TXBUF - 20)) {
1049 DPRINTF(sc, ATH_DBG_FATAL,
1050 "TX queue: %d is full, depth: %d\n",
1051 qnum, txq->axq_depth);
1052 ieee80211_stop_queue(sc->hw, skb_get_queue_mapping(skb));
1053 txq->stopped = 1;
1054 spin_unlock_bh(&txq->axq_lock);
1055 return NULL;
1056 }
1057
1058 spin_unlock_bh(&txq->axq_lock);
1059
1060 return txq;
1061}
1062
1063int ath_txq_update(struct ath_softc *sc, int qnum,
1064 struct ath9k_tx_queue_info *qinfo)
1065{
1066 struct ath_hal *ah = sc->sc_ah;
1067 int error = 0;
1068 struct ath9k_tx_queue_info qi;
1069
1070 if (qnum == sc->beacon.beaconq) {
1071 /*
1072 * XXX: for beacon queue, we just save the parameter.
1073 * It will be picked up by ath_beaconq_config when
1074 * it's necessary.
1075 */
1076 sc->beacon.beacon_qi = *qinfo;
1077 return 0;
1078 }
1079
1080 ASSERT(sc->tx.txq[qnum].axq_qnum == qnum);
1081
1082 ath9k_hw_get_txq_props(ah, qnum, &qi);
1083 qi.tqi_aifs = qinfo->tqi_aifs;
1084 qi.tqi_cwmin = qinfo->tqi_cwmin;
1085 qi.tqi_cwmax = qinfo->tqi_cwmax;
1086 qi.tqi_burstTime = qinfo->tqi_burstTime;
1087 qi.tqi_readyTime = qinfo->tqi_readyTime;
1088
1089 if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
1090 DPRINTF(sc, ATH_DBG_FATAL,
1091 "Unable to update hardware queue %u!\n", qnum);
1092 error = -EIO;
1093 } else {
1094 ath9k_hw_resettxqueue(ah, qnum);
1095 }
1096
1097 return error;
1098}
1099
1100int ath_cabq_update(struct ath_softc *sc)
1101{
1102 struct ath9k_tx_queue_info qi;
1103 int qnum = sc->beacon.cabq->axq_qnum;
1104 struct ath_beacon_config conf;
1105
1106 ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi);
1107 /*
1108 * Ensure the readytime % is within the bounds.
1109 */
1110 if (sc->sc_config.cabqReadytime < ATH9K_READY_TIME_LO_BOUND)
1111 sc->sc_config.cabqReadytime = ATH9K_READY_TIME_LO_BOUND;
1112 else if (sc->sc_config.cabqReadytime > ATH9K_READY_TIME_HI_BOUND)
1113 sc->sc_config.cabqReadytime = ATH9K_READY_TIME_HI_BOUND;
1114
1115 ath_get_beaconconfig(sc, ATH_IF_ID_ANY, &conf);
1116 qi.tqi_readyTime =
1117 (conf.beacon_interval * sc->sc_config.cabqReadytime) / 100;
1118 ath_txq_update(sc, qnum, &qi);
1119
1120 return 0;
1121}
1122
1123void ath_tx_draintxq(struct ath_softc *sc, struct ath_txq *txq, bool retry_tx)
1124{
1125 struct ath_buf *bf, *lastbf;
1126 struct list_head bf_head;
1127
1128 INIT_LIST_HEAD(&bf_head);
1129
1130 /*
1131 * NB: this assumes output has been stopped and
1132 * we do not need to block ath_tx_tasklet
1133 */
1134 for (;;) {
1135 spin_lock_bh(&txq->axq_lock);
1136
1137 if (list_empty(&txq->axq_q)) {
1138 txq->axq_link = NULL;
1139 txq->axq_linkbuf = NULL;
1140 spin_unlock_bh(&txq->axq_lock);
1141 break;
1142 }
1143
1144 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
1145
1146 if (bf->bf_status & ATH_BUFSTATUS_STALE) {
1147 list_del(&bf->list);
1148 spin_unlock_bh(&txq->axq_lock);
1149
1150 spin_lock_bh(&sc->tx.txbuflock);
1151 list_add_tail(&bf->list, &sc->tx.txbuf);
1152 spin_unlock_bh(&sc->tx.txbuflock);
1153 continue;
1154 }
1155
1156 lastbf = bf->bf_lastbf;
1157 if (!retry_tx)
1158 lastbf->bf_desc->ds_txstat.ts_flags =
1159 ATH9K_TX_SW_ABORTED;
1160
1161 /* remove ath_buf's of the same mpdu from txq */
1162 list_cut_position(&bf_head, &txq->axq_q, &lastbf->list);
1163 txq->axq_depth--;
1164
1165 spin_unlock_bh(&txq->axq_lock);
1166
1167 if (bf_isampdu(bf))
1168 ath_tx_complete_aggr_rifs(sc, txq, bf, &bf_head, 0);
1169 else
1170 ath_tx_complete_buf(sc, bf, &bf_head, 0, 0);
1171 }
1172
1173 /* flush any pending frames if aggregation is enabled */
1174 if (sc->sc_flags & SC_OP_TXAGGR) {
1175 if (!retry_tx) {
1176 spin_lock_bh(&txq->axq_lock);
1177 ath_txq_drain_pending_buffers(sc, txq);
1178 spin_unlock_bh(&txq->axq_lock);
1179 }
1180 }
1181}
1182
1183void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq)
1184{
1185 ath9k_hw_releasetxqueue(sc->sc_ah, txq->axq_qnum);
1186 sc->tx.txqsetup &= ~(1<<txq->axq_qnum);
1187}
1188
1189void ath_draintxq(struct ath_softc *sc, bool retry_tx)
1190{
1191 if (!(sc->sc_flags & SC_OP_INVALID))
1192 (void) ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
1193
1194 ath_drain_txdataq(sc, retry_tx);
1195}
1196
1197void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
1198{
1199 struct ath_atx_ac *ac;
1200 struct ath_atx_tid *tid;
1201
1202 if (list_empty(&txq->axq_acq))
1203 return;
1204
1205 ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac, list);
1206 list_del(&ac->list);
1207 ac->sched = false;
1208
1209 do {
1210 if (list_empty(&ac->tid_q))
1211 return;
1212
1213 tid = list_first_entry(&ac->tid_q, struct ath_atx_tid, list);
1214 list_del(&tid->list);
1215 tid->sched = false;
1216
1217 if (tid->paused)
1218 continue;
1219
1220 if ((txq->axq_depth % 2) == 0)
1221 ath_tx_sched_aggr(sc, txq, tid);
1222
1223 /*
1224 * add tid to round-robin queue if more frames
1225 * are pending for the tid
1226 */
1227 if (!list_empty(&tid->buf_q))
1228 ath_tx_queue_tid(txq, tid);
1229
1230 break;
1231 } while (!list_empty(&ac->tid_q));
1232
1233 if (!list_empty(&ac->tid_q)) {
1234 if (!ac->sched) {
1235 ac->sched = true;
1236 list_add_tail(&ac->list, &txq->axq_acq);
1237 }
1238 }
1239}
1240
1241int ath_tx_setup(struct ath_softc *sc, int haltype)
1242{
1243 struct ath_txq *txq;
1244
1245 if (haltype >= ARRAY_SIZE(sc->tx.hwq_map)) {
1246 DPRINTF(sc, ATH_DBG_FATAL,
1247 "HAL AC %u out of range, max %zu!\n",
1248 haltype, ARRAY_SIZE(sc->tx.hwq_map));
1249 return 0;
1250 }
1251 txq = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, haltype);
1252 if (txq != NULL) {
1253 sc->tx.hwq_map[haltype] = txq->axq_qnum;
1254 return 1;
1255 } else
1256 return 0;
1257}
1258
1259/***********/
1260/* TX, DMA */
1261/***********/
1262
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001263/*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001264 * Insert a chain of ath_buf (descriptors) on a txq and
1265 * assume the descriptors are already chained together by caller.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001266 */
Sujith102e0572008-10-29 10:15:16 +05301267static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
1268 struct list_head *head)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001269{
1270 struct ath_hal *ah = sc->sc_ah;
1271 struct ath_buf *bf;
Sujith102e0572008-10-29 10:15:16 +05301272
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001273 /*
1274 * Insert the frame on the outbound list and
1275 * pass it on to the hardware.
1276 */
1277
1278 if (list_empty(head))
1279 return;
1280
1281 bf = list_first_entry(head, struct ath_buf, list);
1282
1283 list_splice_tail_init(head, &txq->axq_q);
1284 txq->axq_depth++;
1285 txq->axq_totalqueued++;
1286 txq->axq_linkbuf = list_entry(txq->axq_q.prev, struct ath_buf, list);
1287
1288 DPRINTF(sc, ATH_DBG_QUEUE,
Sujith04bd46382008-11-28 22:18:05 +05301289 "qnum: %d, txq depth: %d\n", txq->axq_qnum, txq->axq_depth);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001290
1291 if (txq->axq_link == NULL) {
1292 ath9k_hw_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr);
1293 DPRINTF(sc, ATH_DBG_XMIT,
Sujith04bd46382008-11-28 22:18:05 +05301294 "TXDP[%u] = %llx (%p)\n",
1295 txq->axq_qnum, ito64(bf->bf_daddr), bf->bf_desc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001296 } else {
1297 *txq->axq_link = bf->bf_daddr;
Sujith04bd46382008-11-28 22:18:05 +05301298 DPRINTF(sc, ATH_DBG_XMIT, "link[%u] (%p)=%llx (%p)\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001299 txq->axq_qnum, txq->axq_link,
1300 ito64(bf->bf_daddr), bf->bf_desc);
1301 }
1302 txq->axq_link = &(bf->bf_lastbf->bf_desc->ds_link);
1303 ath9k_hw_txstart(ah, txq->axq_qnum);
1304}
1305
Sujithe8324352009-01-16 21:38:42 +05301306static struct ath_buf *ath_tx_get_buffer(struct ath_softc *sc)
Sujithc4288392008-11-18 09:09:30 +05301307{
Sujithe8324352009-01-16 21:38:42 +05301308 struct ath_buf *bf = NULL;
Sujithc4288392008-11-18 09:09:30 +05301309
Sujithe8324352009-01-16 21:38:42 +05301310 spin_lock_bh(&sc->tx.txbuflock);
Sujithc4288392008-11-18 09:09:30 +05301311
Sujithe8324352009-01-16 21:38:42 +05301312 if (unlikely(list_empty(&sc->tx.txbuf))) {
1313 spin_unlock_bh(&sc->tx.txbuflock);
1314 return NULL;
Sujithc4288392008-11-18 09:09:30 +05301315 }
1316
Sujithe8324352009-01-16 21:38:42 +05301317 bf = list_first_entry(&sc->tx.txbuf, struct ath_buf, list);
1318 list_del(&bf->list);
Sujithc4288392008-11-18 09:09:30 +05301319
Sujithe8324352009-01-16 21:38:42 +05301320 spin_unlock_bh(&sc->tx.txbuflock);
Sujithc4288392008-11-18 09:09:30 +05301321
Sujithe8324352009-01-16 21:38:42 +05301322 return bf;
1323}
Sujithc4288392008-11-18 09:09:30 +05301324
Sujithe8324352009-01-16 21:38:42 +05301325static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_atx_tid *tid,
1326 struct list_head *bf_head,
1327 struct ath_tx_control *txctl)
1328{
1329 struct ath_buf *bf;
1330
1331 BUG_ON(list_empty(bf_head));
1332
1333 bf = list_first_entry(bf_head, struct ath_buf, list);
1334 bf->bf_state.bf_type |= BUF_AMPDU;
1335
1336 /*
1337 * Do not queue to h/w when any of the following conditions is true:
1338 * - there are pending frames in software queue
1339 * - the TID is currently paused for ADDBA/BAR request
1340 * - seqno is not within block-ack window
1341 * - h/w queue depth exceeds low water mark
1342 */
1343 if (!list_empty(&tid->buf_q) || tid->paused ||
1344 !BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno) ||
1345 txctl->txq->axq_depth >= ATH_AGGR_MIN_QDEPTH) {
Jouni Malinenf7a276a2008-12-15 16:02:04 +02001346 /*
Sujithe8324352009-01-16 21:38:42 +05301347 * Add this frame to software queue for scheduling later
1348 * for aggregation.
Jouni Malinenf7a276a2008-12-15 16:02:04 +02001349 */
Sujithe8324352009-01-16 21:38:42 +05301350 list_splice_tail_init(bf_head, &tid->buf_q);
1351 ath_tx_queue_tid(txctl->txq, tid);
1352 return;
Jouni Malinenf7a276a2008-12-15 16:02:04 +02001353 }
1354
Sujithe8324352009-01-16 21:38:42 +05301355 /* Add sub-frame to BAW */
1356 ath_tx_addto_baw(sc, tid, bf);
1357
1358 /* Queue to h/w without aggregation */
1359 bf->bf_nframes = 1;
1360 bf->bf_lastbf = bf->bf_lastfrm; /* one single frame */
1361 ath_buf_set_rate(sc, bf);
1362 ath_tx_txqaddbuf(sc, txctl->txq, bf_head);
1363
1364 return;
Sujithc4288392008-11-18 09:09:30 +05301365}
1366
Sujithe8324352009-01-16 21:38:42 +05301367static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
1368 struct ath_atx_tid *tid,
1369 struct list_head *bf_head)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001370{
Sujithe8324352009-01-16 21:38:42 +05301371 struct ath_buf *bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001372
Sujithe8324352009-01-16 21:38:42 +05301373 BUG_ON(list_empty(bf_head));
1374
1375 bf = list_first_entry(bf_head, struct ath_buf, list);
1376 bf->bf_state.bf_type &= ~BUF_AMPDU;
1377
1378 /* update starting sequence number for subsequent ADDBA request */
1379 INCR(tid->seq_start, IEEE80211_SEQ_MAX);
1380
1381 bf->bf_nframes = 1;
1382 bf->bf_lastbf = bf->bf_lastfrm;
1383 ath_buf_set_rate(sc, bf);
1384 ath_tx_txqaddbuf(sc, txq, bf_head);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001385}
1386
Sujith528f0c62008-10-29 10:14:26 +05301387static enum ath9k_pkt_type get_hw_packet_type(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001388{
Sujith528f0c62008-10-29 10:14:26 +05301389 struct ieee80211_hdr *hdr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001390 enum ath9k_pkt_type htype;
1391 __le16 fc;
1392
Sujith528f0c62008-10-29 10:14:26 +05301393 hdr = (struct ieee80211_hdr *)skb->data;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001394 fc = hdr->frame_control;
1395
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001396 if (ieee80211_is_beacon(fc))
1397 htype = ATH9K_PKT_TYPE_BEACON;
1398 else if (ieee80211_is_probe_resp(fc))
1399 htype = ATH9K_PKT_TYPE_PROBE_RESP;
1400 else if (ieee80211_is_atim(fc))
1401 htype = ATH9K_PKT_TYPE_ATIM;
1402 else if (ieee80211_is_pspoll(fc))
1403 htype = ATH9K_PKT_TYPE_PSPOLL;
1404 else
1405 htype = ATH9K_PKT_TYPE_NORMAL;
1406
1407 return htype;
1408}
1409
Sujitha8efee42008-11-18 09:07:30 +05301410static bool is_pae(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001411{
1412 struct ieee80211_hdr *hdr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001413 __le16 fc;
1414
1415 hdr = (struct ieee80211_hdr *)skb->data;
1416 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +02001417
Sujitha8efee42008-11-18 09:07:30 +05301418 if (ieee80211_is_data(fc)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001419 if (ieee80211_is_nullfunc(fc) ||
Sujith528f0c62008-10-29 10:14:26 +05301420 /* Port Access Entity (IEEE 802.1X) */
1421 (skb->protocol == cpu_to_be16(ETH_P_PAE))) {
Sujitha8efee42008-11-18 09:07:30 +05301422 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001423 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001424 }
1425
Sujitha8efee42008-11-18 09:07:30 +05301426 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001427}
1428
Sujith528f0c62008-10-29 10:14:26 +05301429static int get_hw_crypto_keytype(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001430{
Sujith528f0c62008-10-29 10:14:26 +05301431 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1432
1433 if (tx_info->control.hw_key) {
1434 if (tx_info->control.hw_key->alg == ALG_WEP)
1435 return ATH9K_KEY_TYPE_WEP;
1436 else if (tx_info->control.hw_key->alg == ALG_TKIP)
1437 return ATH9K_KEY_TYPE_TKIP;
1438 else if (tx_info->control.hw_key->alg == ALG_CCMP)
1439 return ATH9K_KEY_TYPE_AES;
1440 }
1441
1442 return ATH9K_KEY_TYPE_CLEAR;
1443}
1444
Sujith528f0c62008-10-29 10:14:26 +05301445static void assign_aggr_tid_seqno(struct sk_buff *skb,
1446 struct ath_buf *bf)
1447{
1448 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1449 struct ieee80211_hdr *hdr;
1450 struct ath_node *an;
1451 struct ath_atx_tid *tid;
1452 __le16 fc;
1453 u8 *qc;
1454
1455 if (!tx_info->control.sta)
1456 return;
1457
1458 an = (struct ath_node *)tx_info->control.sta->drv_priv;
1459 hdr = (struct ieee80211_hdr *)skb->data;
1460 fc = hdr->frame_control;
1461
Sujith528f0c62008-10-29 10:14:26 +05301462 if (ieee80211_is_data_qos(fc)) {
1463 qc = ieee80211_get_qos_ctl(hdr);
1464 bf->bf_tidno = qc[0] & 0xf;
Sujith98deeea2008-08-11 14:05:46 +05301465 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001466
Sujithe8324352009-01-16 21:38:42 +05301467 /*
1468 * For HT capable stations, we save tidno for later use.
Senthil Balasubramaniand3a1db12008-12-22 16:31:58 +05301469 * We also override seqno set by upper layer with the one
1470 * in tx aggregation state.
1471 *
1472 * If fragmentation is on, the sequence number is
1473 * not overridden, since it has been
1474 * incremented by the fragmentation routine.
1475 *
1476 * FIXME: check if the fragmentation threshold exceeds
1477 * IEEE80211 max.
1478 */
1479 tid = ATH_AN_2_TID(an, bf->bf_tidno);
1480 hdr->seq_ctrl = cpu_to_le16(tid->seq_next <<
1481 IEEE80211_SEQ_SEQ_SHIFT);
1482 bf->bf_seqno = tid->seq_next;
1483 INCR(tid->seq_next, IEEE80211_SEQ_MAX);
Sujith528f0c62008-10-29 10:14:26 +05301484}
1485
1486static int setup_tx_flags(struct ath_softc *sc, struct sk_buff *skb,
1487 struct ath_txq *txq)
1488{
1489 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1490 int flags = 0;
1491
1492 flags |= ATH9K_TXDESC_CLRDMASK; /* needed for crypto errors */
1493 flags |= ATH9K_TXDESC_INTREQ;
1494
1495 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
1496 flags |= ATH9K_TXDESC_NOACK;
1497 if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
1498 flags |= ATH9K_TXDESC_RTSENA;
1499
1500 return flags;
1501}
1502
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001503/*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001504 * rix - rate index
1505 * pktlen - total bytes (delims + data + fcs + pads + pad delims)
1506 * width - 0 for 20 MHz, 1 for 40 MHz
1507 * half_gi - to use 4us v/s 3.6 us for symbol time
1508 */
Sujith102e0572008-10-29 10:15:16 +05301509static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, struct ath_buf *bf,
1510 int width, int half_gi, bool shortPreamble)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001511{
Sujith3706de62008-12-07 21:42:10 +05301512 struct ath_rate_table *rate_table = sc->cur_rate_table;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001513 u32 nbits, nsymbits, duration, nsymbols;
1514 u8 rc;
1515 int streams, pktlen;
1516
Sujithcd3d39a2008-08-11 14:03:34 +05301517 pktlen = bf_isaggr(bf) ? bf->bf_al : bf->bf_frmlen;
Sujithe63835b2008-11-18 09:07:53 +05301518 rc = rate_table->info[rix].ratecode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001519
Sujithe63835b2008-11-18 09:07:53 +05301520 /* for legacy rates, use old function to compute packet duration */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001521 if (!IS_HT_RATE(rc))
Sujithe63835b2008-11-18 09:07:53 +05301522 return ath9k_hw_computetxtime(sc->sc_ah, rate_table, pktlen,
1523 rix, shortPreamble);
1524
1525 /* find number of symbols: PLCP + data */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001526 nbits = (pktlen << 3) + OFDM_PLCP_BITS;
1527 nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
1528 nsymbols = (nbits + nsymbits - 1) / nsymbits;
1529
1530 if (!half_gi)
1531 duration = SYMBOL_TIME(nsymbols);
1532 else
1533 duration = SYMBOL_TIME_HALFGI(nsymbols);
1534
Sujithe63835b2008-11-18 09:07:53 +05301535 /* addup duration for legacy/ht training and signal fields */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001536 streams = HT_RC_2_STREAMS(rc);
1537 duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
Sujith102e0572008-10-29 10:15:16 +05301538
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001539 return duration;
1540}
1541
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001542static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
1543{
1544 struct ath_hal *ah = sc->sc_ah;
Sujithe63835b2008-11-18 09:07:53 +05301545 struct ath_rate_table *rt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001546 struct ath_desc *ds = bf->bf_desc;
1547 struct ath_desc *lastds = bf->bf_lastbf->bf_desc;
1548 struct ath9k_11n_rate_series series[4];
Sujith528f0c62008-10-29 10:14:26 +05301549 struct sk_buff *skb;
1550 struct ieee80211_tx_info *tx_info;
Sujitha8efee42008-11-18 09:07:30 +05301551 struct ieee80211_tx_rate *rates;
Sujithe63835b2008-11-18 09:07:53 +05301552 struct ieee80211_hdr *hdr;
Luis R. Rodriguez96742252008-12-23 15:58:38 -08001553 struct ieee80211_hw *hw = sc->hw;
1554 int i, flags, rtsctsena = 0, enable_g_protection = 0;
Sujithe63835b2008-11-18 09:07:53 +05301555 u32 ctsduration = 0;
1556 u8 rix = 0, cix, ctsrate = 0;
1557 __le16 fc;
1558
1559 memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4);
Sujith528f0c62008-10-29 10:14:26 +05301560
1561 skb = (struct sk_buff *)bf->bf_mpdu;
Sujithe63835b2008-11-18 09:07:53 +05301562 hdr = (struct ieee80211_hdr *)skb->data;
1563 fc = hdr->frame_control;
Sujith528f0c62008-10-29 10:14:26 +05301564 tx_info = IEEE80211_SKB_CB(skb);
Sujithe63835b2008-11-18 09:07:53 +05301565 rates = tx_info->control.rates;
Sujith528f0c62008-10-29 10:14:26 +05301566
Sujithe63835b2008-11-18 09:07:53 +05301567 if (ieee80211_has_morefrags(fc) ||
1568 (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG)) {
1569 rates[1].count = rates[2].count = rates[3].count = 0;
1570 rates[1].idx = rates[2].idx = rates[3].idx = 0;
1571 rates[0].count = ATH_TXMAXTRY;
1572 }
1573
1574 /* get the cix for the lowest valid rix */
Sujith3706de62008-12-07 21:42:10 +05301575 rt = sc->cur_rate_table;
Sujitha8efee42008-11-18 09:07:30 +05301576 for (i = 3; i >= 0; i--) {
Sujithe63835b2008-11-18 09:07:53 +05301577 if (rates[i].count && (rates[i].idx >= 0)) {
Sujitha8efee42008-11-18 09:07:30 +05301578 rix = rates[i].idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001579 break;
1580 }
1581 }
Sujithe63835b2008-11-18 09:07:53 +05301582
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001583 flags = (bf->bf_flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA));
Sujithe63835b2008-11-18 09:07:53 +05301584 cix = rt->info[rix].ctrl_rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001585
Luis R. Rodriguez96742252008-12-23 15:58:38 -08001586 /* All protection frames are transmited at 2Mb/s for 802.11g,
1587 * otherwise we transmit them at 1Mb/s */
1588 if (hw->conf.channel->band == IEEE80211_BAND_2GHZ &&
1589 !conf_is_ht(&hw->conf))
1590 enable_g_protection = 1;
1591
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001592 /*
Sujithe63835b2008-11-18 09:07:53 +05301593 * If 802.11g protection is enabled, determine whether to use RTS/CTS or
1594 * just CTS. Note that this is only done for OFDM/HT unicast frames.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001595 */
Sujithe63835b2008-11-18 09:07:53 +05301596 if (sc->sc_protmode != PROT_M_NONE && !(bf->bf_flags & ATH9K_TXDESC_NOACK)
Sujith46d14a52008-11-18 09:08:13 +05301597 && (rt->info[rix].phy == WLAN_RC_PHY_OFDM ||
Sujithe63835b2008-11-18 09:07:53 +05301598 WLAN_RC_PHY_HT(rt->info[rix].phy))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001599 if (sc->sc_protmode == PROT_M_RTSCTS)
1600 flags = ATH9K_TXDESC_RTSENA;
1601 else if (sc->sc_protmode == PROT_M_CTSONLY)
1602 flags = ATH9K_TXDESC_CTSENA;
1603
Luis R. Rodriguez96742252008-12-23 15:58:38 -08001604 cix = rt->info[enable_g_protection].ctrl_rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001605 rtsctsena = 1;
1606 }
1607
Sujithe63835b2008-11-18 09:07:53 +05301608 /* For 11n, the default behavior is to enable RTS for hw retried frames.
1609 * We enable the global flag here and let rate series flags determine
1610 * which rates will actually use RTS.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001611 */
Sujithcd3d39a2008-08-11 14:03:34 +05301612 if ((ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) && bf_isdata(bf)) {
Sujithe63835b2008-11-18 09:07:53 +05301613 /* 802.11g protection not needed, use our default behavior */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001614 if (!rtsctsena)
1615 flags = ATH9K_TXDESC_RTSENA;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001616 }
1617
Sujithe63835b2008-11-18 09:07:53 +05301618 /* Set protection if aggregate protection on */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001619 if (sc->sc_config.ath_aggr_prot &&
Sujithcd3d39a2008-08-11 14:03:34 +05301620 (!bf_isaggr(bf) || (bf_isaggr(bf) && bf->bf_al < 8192))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001621 flags = ATH9K_TXDESC_RTSENA;
Luis R. Rodriguez96742252008-12-23 15:58:38 -08001622 cix = rt->info[enable_g_protection].ctrl_rate;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001623 rtsctsena = 1;
1624 }
1625
Sujithe63835b2008-11-18 09:07:53 +05301626 /* For AR5416 - RTS cannot be followed by a frame larger than 8K */
1627 if (bf_isaggr(bf) && (bf->bf_al > ah->ah_caps.rts_aggr_limit))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001628 flags &= ~(ATH9K_TXDESC_RTSENA);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001629
1630 /*
Sujithe63835b2008-11-18 09:07:53 +05301631 * CTS transmit rate is derived from the transmit rate by looking in the
1632 * h/w rate table. We must also factor in whether or not a short
1633 * preamble is to be used. NB: cix is set above where RTS/CTS is enabled
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001634 */
Sujithe63835b2008-11-18 09:07:53 +05301635 ctsrate = rt->info[cix].ratecode |
1636 (bf_isshpreamble(bf) ? rt->info[cix].short_preamble : 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001637
1638 for (i = 0; i < 4; i++) {
Sujithe63835b2008-11-18 09:07:53 +05301639 if (!rates[i].count || (rates[i].idx < 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001640 continue;
1641
Sujitha8efee42008-11-18 09:07:30 +05301642 rix = rates[i].idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001643
Sujithe63835b2008-11-18 09:07:53 +05301644 series[i].Rate = rt->info[rix].ratecode |
1645 (bf_isshpreamble(bf) ? rt->info[rix].short_preamble : 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001646
Sujitha8efee42008-11-18 09:07:30 +05301647 series[i].Tries = rates[i].count;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001648
1649 series[i].RateFlags = (
Sujitha8efee42008-11-18 09:07:30 +05301650 (rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) ?
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001651 ATH9K_RATESERIES_RTS_CTS : 0) |
Sujitha8efee42008-11-18 09:07:30 +05301652 ((rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ?
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001653 ATH9K_RATESERIES_2040 : 0) |
Sujitha8efee42008-11-18 09:07:30 +05301654 ((rates[i].flags & IEEE80211_TX_RC_SHORT_GI) ?
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001655 ATH9K_RATESERIES_HALFGI : 0);
1656
Sujith102e0572008-10-29 10:15:16 +05301657 series[i].PktDuration = ath_pkt_duration(sc, rix, bf,
Sujitha8efee42008-11-18 09:07:30 +05301658 (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) != 0,
1659 (rates[i].flags & IEEE80211_TX_RC_SHORT_GI),
Sujith102e0572008-10-29 10:15:16 +05301660 bf_isshpreamble(bf));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001661
Sujithff37e332008-11-24 12:07:55 +05301662 series[i].ChSel = sc->sc_tx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001663
1664 if (rtsctsena)
1665 series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001666 }
1667
Sujithe63835b2008-11-18 09:07:53 +05301668 /* set dur_update_en for l-sig computation except for PS-Poll frames */
1669 ath9k_hw_set11n_ratescenario(ah, ds, lastds, !bf_ispspoll(bf),
1670 ctsrate, ctsduration,
Sujithcd3d39a2008-08-11 14:03:34 +05301671 series, 4, flags);
Sujith102e0572008-10-29 10:15:16 +05301672
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001673 if (sc->sc_config.ath_aggr_prot && flags)
1674 ath9k_hw_set11n_burstduration(ah, ds, 8192);
1675}
1676
Sujithe8324352009-01-16 21:38:42 +05301677static int ath_tx_setup_buffer(struct ath_softc *sc, struct ath_buf *bf,
1678 struct sk_buff *skb,
1679 struct ath_tx_control *txctl)
1680{
1681 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1682 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1683 struct ath_tx_info_priv *tx_info_priv;
1684 int hdrlen;
1685 __le16 fc;
1686
1687 tx_info_priv = kzalloc(sizeof(*tx_info_priv), GFP_ATOMIC);
1688 if (unlikely(!tx_info_priv))
1689 return -ENOMEM;
1690 tx_info->rate_driver_data[0] = tx_info_priv;
1691 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1692 fc = hdr->frame_control;
1693
1694 ATH_TXBUF_RESET(bf);
1695
1696 bf->bf_frmlen = skb->len + FCS_LEN - (hdrlen & 3);
1697
1698 ieee80211_is_data(fc) ?
1699 (bf->bf_state.bf_type |= BUF_DATA) :
1700 (bf->bf_state.bf_type &= ~BUF_DATA);
1701 ieee80211_is_back_req(fc) ?
1702 (bf->bf_state.bf_type |= BUF_BAR) :
1703 (bf->bf_state.bf_type &= ~BUF_BAR);
1704 ieee80211_is_pspoll(fc) ?
1705 (bf->bf_state.bf_type |= BUF_PSPOLL) :
1706 (bf->bf_state.bf_type &= ~BUF_PSPOLL);
1707 (sc->sc_flags & SC_OP_PREAMBLE_SHORT) ?
1708 (bf->bf_state.bf_type |= BUF_SHORT_PREAMBLE) :
1709 (bf->bf_state.bf_type &= ~BUF_SHORT_PREAMBLE);
1710 (conf_is_ht(&sc->hw->conf) && !is_pae(skb) &&
1711 (tx_info->flags & IEEE80211_TX_CTL_AMPDU)) ?
1712 (bf->bf_state.bf_type |= BUF_HT) :
1713 (bf->bf_state.bf_type &= ~BUF_HT);
1714
1715 bf->bf_flags = setup_tx_flags(sc, skb, txctl->txq);
1716
1717 bf->bf_keytype = get_hw_crypto_keytype(skb);
1718
1719 if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR) {
1720 bf->bf_frmlen += tx_info->control.hw_key->icv_len;
1721 bf->bf_keyix = tx_info->control.hw_key->hw_key_idx;
1722 } else {
1723 bf->bf_keyix = ATH9K_TXKEYIX_INVALID;
1724 }
1725
1726 if (ieee80211_is_data_qos(fc) && (sc->sc_flags & SC_OP_TXAGGR))
1727 assign_aggr_tid_seqno(skb, bf);
1728
1729 bf->bf_mpdu = skb;
1730
1731 bf->bf_dmacontext = dma_map_single(sc->dev, skb->data,
1732 skb->len, DMA_TO_DEVICE);
1733 if (unlikely(dma_mapping_error(sc->dev, bf->bf_dmacontext))) {
1734 bf->bf_mpdu = NULL;
1735 DPRINTF(sc, ATH_DBG_CONFIG,
1736 "dma_mapping_error() on TX\n");
1737 return -ENOMEM;
1738 }
1739
1740 bf->bf_buf_addr = bf->bf_dmacontext;
1741 return 0;
1742}
1743
1744/* FIXME: tx power */
1745static void ath_tx_start_dma(struct ath_softc *sc, struct ath_buf *bf,
1746 struct ath_tx_control *txctl)
1747{
1748 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
1749 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1750 struct ath_node *an = NULL;
1751 struct list_head bf_head;
1752 struct ath_desc *ds;
1753 struct ath_atx_tid *tid;
1754 struct ath_hal *ah = sc->sc_ah;
1755 int frm_type;
1756
1757 frm_type = get_hw_packet_type(skb);
1758
1759 INIT_LIST_HEAD(&bf_head);
1760 list_add_tail(&bf->list, &bf_head);
1761
1762 ds = bf->bf_desc;
1763 ds->ds_link = 0;
1764 ds->ds_data = bf->bf_buf_addr;
1765
1766 ath9k_hw_set11n_txdesc(ah, ds, bf->bf_frmlen, frm_type, MAX_RATE_POWER,
1767 bf->bf_keyix, bf->bf_keytype, bf->bf_flags);
1768
1769 ath9k_hw_filltxdesc(ah, ds,
1770 skb->len, /* segment length */
1771 true, /* first segment */
1772 true, /* last segment */
1773 ds); /* first descriptor */
1774
1775 bf->bf_lastfrm = bf;
1776
1777 spin_lock_bh(&txctl->txq->axq_lock);
1778
1779 if (bf_isht(bf) && (sc->sc_flags & SC_OP_TXAGGR) &&
1780 tx_info->control.sta) {
1781 an = (struct ath_node *)tx_info->control.sta->drv_priv;
1782 tid = ATH_AN_2_TID(an, bf->bf_tidno);
1783
1784 if (ath_aggr_query(sc, an, bf->bf_tidno)) {
1785 /*
1786 * Try aggregation if it's a unicast data frame
1787 * and the destination is HT capable.
1788 */
1789 ath_tx_send_ampdu(sc, tid, &bf_head, txctl);
1790 } else {
1791 /*
1792 * Send this frame as regular when ADDBA
1793 * exchange is neither complete nor pending.
1794 */
1795 ath_tx_send_normal(sc, txctl->txq,
1796 tid, &bf_head);
1797 }
1798 } else {
1799 bf->bf_lastbf = bf;
1800 bf->bf_nframes = 1;
1801
1802 ath_buf_set_rate(sc, bf);
1803 ath_tx_txqaddbuf(sc, txctl->txq, &bf_head);
1804 }
1805
1806 spin_unlock_bh(&txctl->txq->axq_lock);
1807}
1808
1809/* Upon failure caller should free skb */
1810int ath_tx_start(struct ath_softc *sc, struct sk_buff *skb,
1811 struct ath_tx_control *txctl)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001812{
1813 struct ath_buf *bf;
Sujithe8324352009-01-16 21:38:42 +05301814 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001815
Sujithe8324352009-01-16 21:38:42 +05301816 bf = ath_tx_get_buffer(sc);
1817 if (!bf) {
1818 DPRINTF(sc, ATH_DBG_XMIT, "TX buffers are full\n");
1819 return -1;
1820 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001821
Sujithe8324352009-01-16 21:38:42 +05301822 r = ath_tx_setup_buffer(sc, bf, skb, txctl);
1823 if (unlikely(r)) {
1824 struct ath_txq *txq = txctl->txq;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001825
Sujithe8324352009-01-16 21:38:42 +05301826 DPRINTF(sc, ATH_DBG_FATAL, "TX mem alloc failure\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001827
Sujithe8324352009-01-16 21:38:42 +05301828 /* upon ath_tx_processq() this TX queue will be resumed, we
1829 * guarantee this will happen by knowing beforehand that
1830 * we will at least have to run TX completionon one buffer
1831 * on the queue */
1832 spin_lock_bh(&txq->axq_lock);
1833 if (ath_txq_depth(sc, txq->axq_qnum) > 1) {
1834 ieee80211_stop_queue(sc->hw,
1835 skb_get_queue_mapping(skb));
1836 txq->stopped = 1;
1837 }
1838 spin_unlock_bh(&txq->axq_lock);
1839
1840 spin_lock_bh(&sc->tx.txbuflock);
1841 list_add_tail(&bf->list, &sc->tx.txbuf);
1842 spin_unlock_bh(&sc->tx.txbuflock);
1843
1844 return r;
1845 }
1846
1847 ath_tx_start_dma(sc, bf, txctl);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001848
1849 return 0;
1850}
1851
Sujithe8324352009-01-16 21:38:42 +05301852void ath_tx_cabq(struct ath_softc *sc, struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001853{
Sujithe8324352009-01-16 21:38:42 +05301854 int hdrlen, padsize;
1855 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1856 struct ath_tx_control txctl;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001857
Sujithe8324352009-01-16 21:38:42 +05301858 memset(&txctl, 0, sizeof(struct ath_tx_control));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001859
Sujithe8324352009-01-16 21:38:42 +05301860 /*
1861 * As a temporary workaround, assign seq# here; this will likely need
1862 * to be cleaned up to work better with Beacon transmission and virtual
1863 * BSSes.
1864 */
1865 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1866 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1867 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
1868 sc->tx.seq_no += 0x10;
1869 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1870 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001871 }
1872
Sujithe8324352009-01-16 21:38:42 +05301873 /* Add the padding after the header if this is not already done */
1874 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1875 if (hdrlen & 3) {
1876 padsize = hdrlen % 4;
1877 if (skb_headroom(skb) < padsize) {
1878 DPRINTF(sc, ATH_DBG_XMIT, "TX CABQ padding failed\n");
1879 dev_kfree_skb_any(skb);
1880 return;
1881 }
1882 skb_push(skb, padsize);
1883 memmove(skb->data, skb->data + padsize, hdrlen);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001884 }
1885
Sujithe8324352009-01-16 21:38:42 +05301886 txctl.txq = sc->beacon.cabq;
1887
1888 DPRINTF(sc, ATH_DBG_XMIT, "transmitting CABQ packet, skb: %p\n", skb);
1889
1890 if (ath_tx_start(sc, skb, &txctl) != 0) {
1891 DPRINTF(sc, ATH_DBG_XMIT, "CABQ TX failed\n");
1892 goto exit;
1893 }
1894
1895 return;
1896exit:
1897 dev_kfree_skb_any(skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001898}
1899
Sujithe8324352009-01-16 21:38:42 +05301900/*****************/
1901/* TX Completion */
1902/*****************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001903
Sujithe8324352009-01-16 21:38:42 +05301904static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
1905 struct ath_xmit_status *tx_status)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001906{
Sujithe8324352009-01-16 21:38:42 +05301907 struct ieee80211_hw *hw = sc->hw;
1908 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1909 struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
1910 int hdrlen, padsize;
1911
1912 DPRINTF(sc, ATH_DBG_XMIT, "TX complete: skb: %p\n", skb);
1913
1914 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK ||
1915 tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
1916 kfree(tx_info_priv);
1917 tx_info->rate_driver_data[0] = NULL;
1918 }
1919
1920 if (tx_status->flags & ATH_TX_BAR) {
1921 tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
1922 tx_status->flags &= ~ATH_TX_BAR;
1923 }
1924
1925 if (!(tx_status->flags & (ATH_TX_ERROR | ATH_TX_XRETRY))) {
1926 /* Frame was ACKed */
1927 tx_info->flags |= IEEE80211_TX_STAT_ACK;
1928 }
1929
1930 tx_info->status.rates[0].count = tx_status->retries + 1;
1931
1932 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1933 padsize = hdrlen & 3;
1934 if (padsize && hdrlen >= 24) {
1935 /*
1936 * Remove MAC header padding before giving the frame back to
1937 * mac80211.
1938 */
1939 memmove(skb->data + padsize, skb->data, hdrlen);
1940 skb_pull(skb, padsize);
1941 }
1942
1943 ieee80211_tx_status(hw, skb);
1944}
1945
1946static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
1947 struct list_head *bf_q,
1948 int txok, int sendbar)
1949{
1950 struct sk_buff *skb = bf->bf_mpdu;
1951 struct ath_xmit_status tx_status;
1952 unsigned long flags;
1953
1954 /*
1955 * Set retry information.
1956 * NB: Don't use the information in the descriptor, because the frame
1957 * could be software retried.
1958 */
1959 tx_status.retries = bf->bf_retries;
1960 tx_status.flags = 0;
1961
1962 if (sendbar)
1963 tx_status.flags = ATH_TX_BAR;
1964
1965 if (!txok) {
1966 tx_status.flags |= ATH_TX_ERROR;
1967
1968 if (bf_isxretried(bf))
1969 tx_status.flags |= ATH_TX_XRETRY;
1970 }
1971
1972 dma_unmap_single(sc->dev, bf->bf_dmacontext, skb->len, DMA_TO_DEVICE);
1973 ath_tx_complete(sc, skb, &tx_status);
1974
1975 /*
1976 * Return the list of ath_buf of this mpdu to free queue
1977 */
1978 spin_lock_irqsave(&sc->tx.txbuflock, flags);
1979 list_splice_tail_init(bf_q, &sc->tx.txbuf);
1980 spin_unlock_irqrestore(&sc->tx.txbuflock, flags);
1981}
1982
1983static int ath_tx_num_badfrms(struct ath_softc *sc, struct ath_buf *bf,
1984 int txok)
1985{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001986 struct ath_buf *bf_last = bf->bf_lastbf;
1987 struct ath_desc *ds = bf_last->bf_desc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001988 u16 seq_st = 0;
1989 u32 ba[WME_BA_BMP_SIZE >> 5];
Sujithe8324352009-01-16 21:38:42 +05301990 int ba_index;
1991 int nbad = 0;
1992 int isaggr = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001993
Sujithe8324352009-01-16 21:38:42 +05301994 if (ds->ds_txstat.ts_flags == ATH9K_TX_SW_ABORTED)
1995 return 0;
Sujith528f0c62008-10-29 10:14:26 +05301996
Sujithcd3d39a2008-08-11 14:03:34 +05301997 isaggr = bf_isaggr(bf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001998 if (isaggr) {
Sujithe8324352009-01-16 21:38:42 +05301999 seq_st = ATH_DS_BA_SEQ(ds);
2000 memcpy(ba, ATH_DS_BA_BITMAP(ds), WME_BA_BMP_SIZE >> 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002001 }
2002
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002003 while (bf) {
Sujithe8324352009-01-16 21:38:42 +05302004 ba_index = ATH_BA_INDEX(seq_st, bf->bf_seqno);
2005 if (!txok || (isaggr && !ATH_BA_ISSET(ba, ba_index)))
2006 nbad++;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002007
Sujithe8324352009-01-16 21:38:42 +05302008 bf = bf->bf_next;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002009 }
2010
Sujithe8324352009-01-16 21:38:42 +05302011 return nbad;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002012}
2013
Sujithc4288392008-11-18 09:09:30 +05302014static void ath_tx_rc_status(struct ath_buf *bf, struct ath_desc *ds, int nbad)
2015{
2016 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
2017 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
2018 struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
2019
Vasanthakumar Thiagarajan7ac47012008-11-20 11:51:18 +05302020 tx_info_priv->update_rc = false;
Sujithc4288392008-11-18 09:09:30 +05302021 if (ds->ds_txstat.ts_status & ATH9K_TXERR_FILT)
2022 tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
2023
2024 if ((ds->ds_txstat.ts_status & ATH9K_TXERR_FILT) == 0 &&
2025 (bf->bf_flags & ATH9K_TXDESC_NOACK) == 0) {
2026 if (bf_isdata(bf)) {
2027 memcpy(&tx_info_priv->tx, &ds->ds_txstat,
2028 sizeof(tx_info_priv->tx));
2029 tx_info_priv->n_frames = bf->bf_nframes;
2030 tx_info_priv->n_bad_frames = nbad;
Vasanthakumar Thiagarajan7ac47012008-11-20 11:51:18 +05302031 tx_info_priv->update_rc = true;
Sujithc4288392008-11-18 09:09:30 +05302032 }
2033 }
2034}
2035
Sujithc4288392008-11-18 09:09:30 +05302036static void ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002037{
2038 struct ath_hal *ah = sc->sc_ah;
2039 struct ath_buf *bf, *lastbf, *bf_held = NULL;
2040 struct list_head bf_head;
Sujithc4288392008-11-18 09:09:30 +05302041 struct ath_desc *ds;
2042 int txok, nbad = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002043 int status;
2044
Sujith04bd46382008-11-28 22:18:05 +05302045 DPRINTF(sc, ATH_DBG_QUEUE, "tx queue %d (%x), link %p\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002046 txq->axq_qnum, ath9k_hw_gettxbuf(sc->sc_ah, txq->axq_qnum),
2047 txq->axq_link);
2048
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002049 for (;;) {
2050 spin_lock_bh(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002051 if (list_empty(&txq->axq_q)) {
2052 txq->axq_link = NULL;
2053 txq->axq_linkbuf = NULL;
2054 spin_unlock_bh(&txq->axq_lock);
2055 break;
2056 }
2057 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
2058
2059 /*
2060 * There is a race condition that a BH gets scheduled
2061 * after sw writes TxE and before hw re-load the last
2062 * descriptor to get the newly chained one.
2063 * Software must keep the last DONE descriptor as a
2064 * holding descriptor - software does so by marking
2065 * it with the STALE flag.
2066 */
2067 bf_held = NULL;
2068 if (bf->bf_status & ATH_BUFSTATUS_STALE) {
2069 bf_held = bf;
2070 if (list_is_last(&bf_held->list, &txq->axq_q)) {
2071 /* FIXME:
2072 * The holding descriptor is the last
2073 * descriptor in queue. It's safe to remove
2074 * the last holding descriptor in BH context.
2075 */
2076 spin_unlock_bh(&txq->axq_lock);
2077 break;
2078 } else {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002079 bf = list_entry(bf_held->list.next,
2080 struct ath_buf, list);
2081 }
2082 }
2083
2084 lastbf = bf->bf_lastbf;
Sujithe8324352009-01-16 21:38:42 +05302085 ds = lastbf->bf_desc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002086
2087 status = ath9k_hw_txprocdesc(ah, ds);
2088 if (status == -EINPROGRESS) {
2089 spin_unlock_bh(&txq->axq_lock);
2090 break;
2091 }
2092 if (bf->bf_desc == txq->axq_lastdsWithCTS)
2093 txq->axq_lastdsWithCTS = NULL;
2094 if (ds == txq->axq_gatingds)
2095 txq->axq_gatingds = NULL;
2096
2097 /*
2098 * Remove ath_buf's of the same transmit unit from txq,
2099 * however leave the last descriptor back as the holding
2100 * descriptor for hw.
2101 */
2102 lastbf->bf_status |= ATH_BUFSTATUS_STALE;
2103 INIT_LIST_HEAD(&bf_head);
2104
2105 if (!list_is_singular(&lastbf->list))
2106 list_cut_position(&bf_head,
2107 &txq->axq_q, lastbf->list.prev);
2108
2109 txq->axq_depth--;
2110
Sujithcd3d39a2008-08-11 14:03:34 +05302111 if (bf_isaggr(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002112 txq->axq_aggr_depth--;
2113
2114 txok = (ds->ds_txstat.ts_status == 0);
2115
2116 spin_unlock_bh(&txq->axq_lock);
2117
2118 if (bf_held) {
2119 list_del(&bf_held->list);
Sujithb77f4832008-12-07 21:44:03 +05302120 spin_lock_bh(&sc->tx.txbuflock);
2121 list_add_tail(&bf_held->list, &sc->tx.txbuf);
2122 spin_unlock_bh(&sc->tx.txbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002123 }
2124
Sujithcd3d39a2008-08-11 14:03:34 +05302125 if (!bf_isampdu(bf)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002126 /*
2127 * This frame is sent out as a single frame.
2128 * Use hardware retry status for this frame.
2129 */
2130 bf->bf_retries = ds->ds_txstat.ts_longretry;
2131 if (ds->ds_txstat.ts_status & ATH9K_TXERR_XRETRY)
Sujithcd3d39a2008-08-11 14:03:34 +05302132 bf->bf_state.bf_type |= BUF_XRETRY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002133 nbad = 0;
2134 } else {
2135 nbad = ath_tx_num_badfrms(sc, bf, txok);
2136 }
Johannes Berge6a98542008-10-21 12:40:02 +02002137
Sujithc4288392008-11-18 09:09:30 +05302138 ath_tx_rc_status(bf, ds, nbad);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002139
Sujithcd3d39a2008-08-11 14:03:34 +05302140 if (bf_isampdu(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002141 ath_tx_complete_aggr_rifs(sc, txq, bf, &bf_head, txok);
2142 else
2143 ath_tx_complete_buf(sc, bf, &bf_head, txok, 0);
2144
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002145 spin_lock_bh(&txq->axq_lock);
2146 if (txq->stopped && ath_txq_depth(sc, txq->axq_qnum) <=
2147 (ATH_TXBUF - 20)) {
2148 int qnum;
2149 qnum = ath_get_mac80211_qnum(txq->axq_qnum, sc);
2150 if (qnum != -1) {
2151 ieee80211_wake_queue(sc->hw, qnum);
2152 txq->stopped = 0;
2153 }
2154
2155 }
2156
Sujith672840a2008-08-11 14:05:08 +05302157 if (sc->sc_flags & SC_OP_TXAGGR)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002158 ath_txq_schedule(sc, txq);
2159 spin_unlock_bh(&txq->axq_lock);
2160 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002161}
2162
Sujithe8324352009-01-16 21:38:42 +05302163
2164void ath_tx_tasklet(struct ath_softc *sc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002165{
Sujithe8324352009-01-16 21:38:42 +05302166 int i;
2167 u32 qcumask = ((1 << ATH9K_NUM_TX_QUEUES) - 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002168
Sujithe8324352009-01-16 21:38:42 +05302169 ath9k_hw_gettxintrtxqs(sc->sc_ah, &qcumask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002170
2171 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
Sujithe8324352009-01-16 21:38:42 +05302172 if (ATH_TXQ_SETUP(sc, i) && (qcumask & (1 << i)))
2173 ath_tx_processq(sc, &sc->tx.txq[i]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002174 }
2175}
2176
Sujithe8324352009-01-16 21:38:42 +05302177/*****************/
2178/* Init, Cleanup */
2179/*****************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002180
2181int ath_tx_init(struct ath_softc *sc, int nbufs)
2182{
2183 int error = 0;
2184
2185 do {
Sujithb77f4832008-12-07 21:44:03 +05302186 spin_lock_init(&sc->tx.txbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002187
Sujithb77f4832008-12-07 21:44:03 +05302188 error = ath_descdma_setup(sc, &sc->tx.txdma, &sc->tx.txbuf,
Sujith556bb8f2008-08-11 14:03:53 +05302189 "tx", nbufs, 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002190 if (error != 0) {
2191 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05302192 "Failed to allocate tx descriptors: %d\n",
2193 error);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002194 break;
2195 }
2196
Sujithb77f4832008-12-07 21:44:03 +05302197 error = ath_descdma_setup(sc, &sc->beacon.bdma, &sc->beacon.bbuf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002198 "beacon", ATH_BCBUF, 1);
2199 if (error != 0) {
2200 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05302201 "Failed to allocate beacon descriptors: %d\n",
2202 error);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002203 break;
2204 }
2205
2206 } while (0);
2207
2208 if (error != 0)
2209 ath_tx_cleanup(sc);
2210
2211 return error;
2212}
2213
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002214int ath_tx_cleanup(struct ath_softc *sc)
2215{
Sujithb77f4832008-12-07 21:44:03 +05302216 if (sc->beacon.bdma.dd_desc_len != 0)
2217 ath_descdma_cleanup(sc, &sc->beacon.bdma, &sc->beacon.bbuf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002218
Sujithb77f4832008-12-07 21:44:03 +05302219 if (sc->tx.txdma.dd_desc_len != 0)
2220 ath_descdma_cleanup(sc, &sc->tx.txdma, &sc->tx.txbuf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002221
2222 return 0;
2223}
2224
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002225void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an)
2226{
Sujithc5170162008-10-29 10:13:59 +05302227 struct ath_atx_tid *tid;
2228 struct ath_atx_ac *ac;
2229 int tidno, acno;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002230
Sujith8ee5afb2008-12-07 21:43:36 +05302231 for (tidno = 0, tid = &an->tid[tidno];
Sujithc5170162008-10-29 10:13:59 +05302232 tidno < WME_NUM_TID;
2233 tidno++, tid++) {
2234 tid->an = an;
2235 tid->tidno = tidno;
2236 tid->seq_start = tid->seq_next = 0;
2237 tid->baw_size = WME_MAX_BA;
2238 tid->baw_head = tid->baw_tail = 0;
2239 tid->sched = false;
Sujithe8324352009-01-16 21:38:42 +05302240 tid->paused = false;
Sujitha37c2c72008-10-29 10:15:40 +05302241 tid->state &= ~AGGR_CLEANUP;
Sujithc5170162008-10-29 10:13:59 +05302242 INIT_LIST_HEAD(&tid->buf_q);
Sujithc5170162008-10-29 10:13:59 +05302243 acno = TID_TO_WME_AC(tidno);
Sujith8ee5afb2008-12-07 21:43:36 +05302244 tid->ac = &an->ac[acno];
Sujitha37c2c72008-10-29 10:15:40 +05302245 tid->state &= ~AGGR_ADDBA_COMPLETE;
2246 tid->state &= ~AGGR_ADDBA_PROGRESS;
2247 tid->addba_exchangeattempts = 0;
Sujithc5170162008-10-29 10:13:59 +05302248 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002249
Sujith8ee5afb2008-12-07 21:43:36 +05302250 for (acno = 0, ac = &an->ac[acno];
Sujithc5170162008-10-29 10:13:59 +05302251 acno < WME_NUM_AC; acno++, ac++) {
2252 ac->sched = false;
2253 INIT_LIST_HEAD(&ac->tid_q);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002254
Sujithc5170162008-10-29 10:13:59 +05302255 switch (acno) {
2256 case WME_AC_BE:
2257 ac->qnum = ath_tx_get_qnum(sc,
2258 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
2259 break;
2260 case WME_AC_BK:
2261 ac->qnum = ath_tx_get_qnum(sc,
2262 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BK);
2263 break;
2264 case WME_AC_VI:
2265 ac->qnum = ath_tx_get_qnum(sc,
2266 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VI);
2267 break;
2268 case WME_AC_VO:
2269 ac->qnum = ath_tx_get_qnum(sc,
2270 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VO);
2271 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002272 }
2273 }
2274}
2275
Sujithb5aa9bf2008-10-29 10:13:31 +05302276void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002277{
2278 int i;
2279 struct ath_atx_ac *ac, *ac_tmp;
2280 struct ath_atx_tid *tid, *tid_tmp;
2281 struct ath_txq *txq;
Sujithe8324352009-01-16 21:38:42 +05302282
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002283 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
2284 if (ATH_TXQ_SETUP(sc, i)) {
Sujithb77f4832008-12-07 21:44:03 +05302285 txq = &sc->tx.txq[i];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002286
Sujithb5aa9bf2008-10-29 10:13:31 +05302287 spin_lock(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002288
2289 list_for_each_entry_safe(ac,
2290 ac_tmp, &txq->axq_acq, list) {
2291 tid = list_first_entry(&ac->tid_q,
2292 struct ath_atx_tid, list);
2293 if (tid && tid->an != an)
2294 continue;
2295 list_del(&ac->list);
2296 ac->sched = false;
2297
2298 list_for_each_entry_safe(tid,
2299 tid_tmp, &ac->tid_q, list) {
2300 list_del(&tid->list);
2301 tid->sched = false;
Sujithb5aa9bf2008-10-29 10:13:31 +05302302 ath_tid_drain(sc, txq, tid);
Sujitha37c2c72008-10-29 10:15:40 +05302303 tid->state &= ~AGGR_ADDBA_COMPLETE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002304 tid->addba_exchangeattempts = 0;
Sujitha37c2c72008-10-29 10:15:40 +05302305 tid->state &= ~AGGR_CLEANUP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002306 }
2307 }
2308
Sujithb5aa9bf2008-10-29 10:13:31 +05302309 spin_unlock(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002310 }
2311 }
2312}