blob: 2db0fa878c2681a09f24a64d7bbe53ed730114f4 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
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
Sujith394cf0a2009-02-09 13:26:54 +053017#include "ath9k.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070018
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
Sujithc37452b2009-03-09 09:31:57 +053058static void ath_tx_send_ht_normal(struct ath_softc *sc, struct ath_txq *txq,
59 struct ath_atx_tid *tid,
60 struct list_head *bf_head);
Sujithe8324352009-01-16 21:38:42 +053061static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
Sujithfec247c2009-07-27 12:08:16 +053062 struct ath_txq *txq,
Sujithe8324352009-01-16 21:38:42 +053063 struct list_head *bf_q,
64 int txok, int sendbar);
65static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
66 struct list_head *head);
67static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf);
Vasanthakumar Thiagarajan0934af22009-03-18 20:22:00 +053068static int ath_tx_num_badfrms(struct ath_softc *sc, struct ath_buf *bf,
69 int txok);
70static void ath_tx_rc_status(struct ath_buf *bf, struct ath_desc *ds,
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +053071 int nbad, int txok, bool update_rc);
Sujithe8324352009-01-16 21:38:42 +053072
73/*********************/
74/* Aggregation logic */
75/*********************/
76
Sujithe8324352009-01-16 21:38:42 +053077static void ath_tx_queue_tid(struct ath_txq *txq, struct ath_atx_tid *tid)
78{
79 struct ath_atx_ac *ac = tid->ac;
80
81 if (tid->paused)
82 return;
83
84 if (tid->sched)
85 return;
86
87 tid->sched = true;
88 list_add_tail(&tid->list, &ac->tid_q);
89
90 if (ac->sched)
91 return;
92
93 ac->sched = true;
94 list_add_tail(&ac->list, &txq->axq_acq);
95}
96
97static void ath_tx_pause_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
98{
99 struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum];
100
101 spin_lock_bh(&txq->axq_lock);
102 tid->paused++;
103 spin_unlock_bh(&txq->axq_lock);
104}
105
106static void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
107{
108 struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum];
109
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -0700110 BUG_ON(tid->paused <= 0);
Sujithe8324352009-01-16 21:38:42 +0530111 spin_lock_bh(&txq->axq_lock);
112
113 tid->paused--;
114
115 if (tid->paused > 0)
116 goto unlock;
117
118 if (list_empty(&tid->buf_q))
119 goto unlock;
120
121 ath_tx_queue_tid(txq, tid);
122 ath_txq_schedule(sc, txq);
123unlock:
124 spin_unlock_bh(&txq->axq_lock);
125}
126
127static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
128{
129 struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum];
130 struct ath_buf *bf;
131 struct list_head bf_head;
132 INIT_LIST_HEAD(&bf_head);
133
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -0700134 BUG_ON(tid->paused <= 0);
Sujithe8324352009-01-16 21:38:42 +0530135 spin_lock_bh(&txq->axq_lock);
136
137 tid->paused--;
138
139 if (tid->paused > 0) {
140 spin_unlock_bh(&txq->axq_lock);
141 return;
142 }
143
144 while (!list_empty(&tid->buf_q)) {
145 bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -0700146 BUG_ON(bf_isretried(bf));
Sujithd43f30152009-01-16 21:38:53 +0530147 list_move_tail(&bf->list, &bf_head);
Sujithc37452b2009-03-09 09:31:57 +0530148 ath_tx_send_ht_normal(sc, txq, tid, &bf_head);
Sujithe8324352009-01-16 21:38:42 +0530149 }
150
151 spin_unlock_bh(&txq->axq_lock);
152}
153
154static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
155 int seqno)
156{
157 int index, cindex;
158
159 index = ATH_BA_INDEX(tid->seq_start, seqno);
160 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
161
162 tid->tx_buf[cindex] = NULL;
163
164 while (tid->baw_head != tid->baw_tail && !tid->tx_buf[tid->baw_head]) {
165 INCR(tid->seq_start, IEEE80211_SEQ_MAX);
166 INCR(tid->baw_head, ATH_TID_MAX_BUFS);
167 }
168}
169
170static void ath_tx_addto_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
171 struct ath_buf *bf)
172{
173 int index, cindex;
174
175 if (bf_isretried(bf))
176 return;
177
178 index = ATH_BA_INDEX(tid->seq_start, bf->bf_seqno);
179 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
180
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -0700181 BUG_ON(tid->tx_buf[cindex] != NULL);
Sujithe8324352009-01-16 21:38:42 +0530182 tid->tx_buf[cindex] = bf;
183
184 if (index >= ((tid->baw_tail - tid->baw_head) &
185 (ATH_TID_MAX_BUFS - 1))) {
186 tid->baw_tail = cindex;
187 INCR(tid->baw_tail, ATH_TID_MAX_BUFS);
188 }
189}
190
191/*
192 * TODO: For frame(s) that are in the retry state, we will reuse the
193 * sequence number(s) without setting the retry bit. The
194 * alternative is to give up on these and BAR the receiver's window
195 * forward.
196 */
197static void ath_tid_drain(struct ath_softc *sc, struct ath_txq *txq,
198 struct ath_atx_tid *tid)
199
200{
201 struct ath_buf *bf;
202 struct list_head bf_head;
203 INIT_LIST_HEAD(&bf_head);
204
205 for (;;) {
206 if (list_empty(&tid->buf_q))
207 break;
Sujithe8324352009-01-16 21:38:42 +0530208
Sujithd43f30152009-01-16 21:38:53 +0530209 bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
210 list_move_tail(&bf->list, &bf_head);
Sujithe8324352009-01-16 21:38:42 +0530211
212 if (bf_isretried(bf))
213 ath_tx_update_baw(sc, tid, bf->bf_seqno);
214
215 spin_unlock(&txq->axq_lock);
Sujithfec247c2009-07-27 12:08:16 +0530216 ath_tx_complete_buf(sc, bf, txq, &bf_head, 0, 0);
Sujithe8324352009-01-16 21:38:42 +0530217 spin_lock(&txq->axq_lock);
218 }
219
220 tid->seq_next = tid->seq_start;
221 tid->baw_tail = tid->baw_head;
222}
223
Sujithfec247c2009-07-27 12:08:16 +0530224static void ath_tx_set_retry(struct ath_softc *sc, struct ath_txq *txq,
225 struct ath_buf *bf)
Sujithe8324352009-01-16 21:38:42 +0530226{
227 struct sk_buff *skb;
228 struct ieee80211_hdr *hdr;
229
230 bf->bf_state.bf_type |= BUF_RETRY;
231 bf->bf_retries++;
Sujithfec247c2009-07-27 12:08:16 +0530232 TX_STAT_INC(txq->axq_qnum, a_retries);
Sujithe8324352009-01-16 21:38:42 +0530233
234 skb = bf->bf_mpdu;
235 hdr = (struct ieee80211_hdr *)skb->data;
236 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_RETRY);
237}
238
Sujithd43f30152009-01-16 21:38:53 +0530239static struct ath_buf* ath_clone_txbuf(struct ath_softc *sc, struct ath_buf *bf)
240{
241 struct ath_buf *tbf;
242
243 spin_lock_bh(&sc->tx.txbuflock);
Vasanthakumar Thiagarajan8a460972009-06-10 17:50:09 +0530244 if (WARN_ON(list_empty(&sc->tx.txbuf))) {
245 spin_unlock_bh(&sc->tx.txbuflock);
246 return NULL;
247 }
Sujithd43f30152009-01-16 21:38:53 +0530248 tbf = list_first_entry(&sc->tx.txbuf, struct ath_buf, list);
249 list_del(&tbf->list);
250 spin_unlock_bh(&sc->tx.txbuflock);
251
252 ATH_TXBUF_RESET(tbf);
253
Felix Fietkau827e69b2009-11-15 23:09:25 +0100254 tbf->aphy = bf->aphy;
Sujithd43f30152009-01-16 21:38:53 +0530255 tbf->bf_mpdu = bf->bf_mpdu;
256 tbf->bf_buf_addr = bf->bf_buf_addr;
257 *(tbf->bf_desc) = *(bf->bf_desc);
258 tbf->bf_state = bf->bf_state;
259 tbf->bf_dmacontext = bf->bf_dmacontext;
260
261 return tbf;
262}
263
264static void ath_tx_complete_aggr(struct ath_softc *sc, struct ath_txq *txq,
265 struct ath_buf *bf, struct list_head *bf_q,
266 int txok)
Sujithe8324352009-01-16 21:38:42 +0530267{
268 struct ath_node *an = NULL;
269 struct sk_buff *skb;
Sujith1286ec62009-01-27 13:30:37 +0530270 struct ieee80211_sta *sta;
Luis R. Rodriguez76d5a9e2009-11-02 16:08:34 -0800271 struct ieee80211_hw *hw;
Sujith1286ec62009-01-27 13:30:37 +0530272 struct ieee80211_hdr *hdr;
Luis R. Rodriguez76d5a9e2009-11-02 16:08:34 -0800273 struct ieee80211_tx_info *tx_info;
Sujithe8324352009-01-16 21:38:42 +0530274 struct ath_atx_tid *tid = NULL;
Sujithd43f30152009-01-16 21:38:53 +0530275 struct ath_buf *bf_next, *bf_last = bf->bf_lastbf;
Sujithe8324352009-01-16 21:38:42 +0530276 struct ath_desc *ds = bf_last->bf_desc;
Sujithe8324352009-01-16 21:38:42 +0530277 struct list_head bf_head, bf_pending;
Vasanthakumar Thiagarajan0934af22009-03-18 20:22:00 +0530278 u16 seq_st = 0, acked_cnt = 0, txfail_cnt = 0;
Sujithe8324352009-01-16 21:38:42 +0530279 u32 ba[WME_BA_BMP_SIZE >> 5];
Vasanthakumar Thiagarajan0934af22009-03-18 20:22:00 +0530280 int isaggr, txfail, txpending, sendbar = 0, needreset = 0, nbad = 0;
281 bool rc_update = true;
Sujithe8324352009-01-16 21:38:42 +0530282
Sujitha22be222009-03-30 15:28:36 +0530283 skb = bf->bf_mpdu;
Sujith1286ec62009-01-27 13:30:37 +0530284 hdr = (struct ieee80211_hdr *)skb->data;
Sujithe8324352009-01-16 21:38:42 +0530285
Luis R. Rodriguez76d5a9e2009-11-02 16:08:34 -0800286 tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau827e69b2009-11-15 23:09:25 +0100287 hw = bf->aphy->hw;
Luis R. Rodriguez76d5a9e2009-11-02 16:08:34 -0800288
Sujith1286ec62009-01-27 13:30:37 +0530289 rcu_read_lock();
290
Johannes Berg5ed176e2009-11-04 14:42:28 +0100291 /* XXX: use ieee80211_find_sta! */
Luis R. Rodriguez76d5a9e2009-11-02 16:08:34 -0800292 sta = ieee80211_find_sta_by_hw(hw, hdr->addr1);
Sujith1286ec62009-01-27 13:30:37 +0530293 if (!sta) {
294 rcu_read_unlock();
295 return;
Sujithe8324352009-01-16 21:38:42 +0530296 }
297
Sujith1286ec62009-01-27 13:30:37 +0530298 an = (struct ath_node *)sta->drv_priv;
299 tid = ATH_AN_2_TID(an, bf->bf_tidno);
300
Sujithe8324352009-01-16 21:38:42 +0530301 isaggr = bf_isaggr(bf);
Sujithd43f30152009-01-16 21:38:53 +0530302 memset(ba, 0, WME_BA_BMP_SIZE >> 3);
Sujithe8324352009-01-16 21:38:42 +0530303
Sujithd43f30152009-01-16 21:38:53 +0530304 if (isaggr && txok) {
305 if (ATH_DS_TX_BA(ds)) {
306 seq_st = ATH_DS_BA_SEQ(ds);
307 memcpy(ba, ATH_DS_BA_BITMAP(ds),
308 WME_BA_BMP_SIZE >> 3);
Sujithe8324352009-01-16 21:38:42 +0530309 } else {
Sujithd43f30152009-01-16 21:38:53 +0530310 /*
311 * AR5416 can become deaf/mute when BA
312 * issue happens. Chip needs to be reset.
313 * But AP code may have sychronization issues
314 * when perform internal reset in this routine.
315 * Only enable reset in STA mode for now.
316 */
Sujith2660b812009-02-09 13:27:26 +0530317 if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION)
Sujithd43f30152009-01-16 21:38:53 +0530318 needreset = 1;
Sujithe8324352009-01-16 21:38:42 +0530319 }
320 }
321
322 INIT_LIST_HEAD(&bf_pending);
323 INIT_LIST_HEAD(&bf_head);
324
Vasanthakumar Thiagarajan0934af22009-03-18 20:22:00 +0530325 nbad = ath_tx_num_badfrms(sc, bf, txok);
Sujithe8324352009-01-16 21:38:42 +0530326 while (bf) {
327 txfail = txpending = 0;
328 bf_next = bf->bf_next;
329
330 if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, bf->bf_seqno))) {
331 /* transmit completion, subframe is
332 * acked by block ack */
Vasanthakumar Thiagarajan0934af22009-03-18 20:22:00 +0530333 acked_cnt++;
Sujithe8324352009-01-16 21:38:42 +0530334 } else if (!isaggr && txok) {
335 /* transmit completion */
Vasanthakumar Thiagarajan0934af22009-03-18 20:22:00 +0530336 acked_cnt++;
Sujithe8324352009-01-16 21:38:42 +0530337 } else {
Sujithe8324352009-01-16 21:38:42 +0530338 if (!(tid->state & AGGR_CLEANUP) &&
339 ds->ds_txstat.ts_flags != ATH9K_TX_SW_ABORTED) {
340 if (bf->bf_retries < ATH_MAX_SW_RETRIES) {
Sujithfec247c2009-07-27 12:08:16 +0530341 ath_tx_set_retry(sc, txq, bf);
Sujithe8324352009-01-16 21:38:42 +0530342 txpending = 1;
343 } else {
344 bf->bf_state.bf_type |= BUF_XRETRY;
345 txfail = 1;
346 sendbar = 1;
Vasanthakumar Thiagarajan0934af22009-03-18 20:22:00 +0530347 txfail_cnt++;
Sujithe8324352009-01-16 21:38:42 +0530348 }
349 } else {
350 /*
351 * cleanup in progress, just fail
352 * the un-acked sub-frames
353 */
354 txfail = 1;
355 }
356 }
357
358 if (bf_next == NULL) {
Vasanthakumar Thiagarajancbfe89c2009-06-24 18:58:47 +0530359 /*
360 * Make sure the last desc is reclaimed if it
361 * not a holding desc.
362 */
363 if (!bf_last->bf_stale)
364 list_move_tail(&bf->list, &bf_head);
365 else
366 INIT_LIST_HEAD(&bf_head);
Sujithe8324352009-01-16 21:38:42 +0530367 } else {
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -0700368 BUG_ON(list_empty(bf_q));
Sujithd43f30152009-01-16 21:38:53 +0530369 list_move_tail(&bf->list, &bf_head);
Sujithe8324352009-01-16 21:38:42 +0530370 }
371
372 if (!txpending) {
373 /*
374 * complete the acked-ones/xretried ones; update
375 * block-ack window
376 */
377 spin_lock_bh(&txq->axq_lock);
378 ath_tx_update_baw(sc, tid, bf->bf_seqno);
379 spin_unlock_bh(&txq->axq_lock);
380
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +0530381 if (rc_update && (acked_cnt == 1 || txfail_cnt == 1)) {
382 ath_tx_rc_status(bf, ds, nbad, txok, true);
383 rc_update = false;
384 } else {
385 ath_tx_rc_status(bf, ds, nbad, txok, false);
386 }
387
Sujithfec247c2009-07-27 12:08:16 +0530388 ath_tx_complete_buf(sc, bf, txq, &bf_head, !txfail, sendbar);
Sujithe8324352009-01-16 21:38:42 +0530389 } else {
Sujithd43f30152009-01-16 21:38:53 +0530390 /* retry the un-acked ones */
Sujitha119cc42009-03-30 15:28:38 +0530391 if (bf->bf_next == NULL && bf_last->bf_stale) {
Sujithe8324352009-01-16 21:38:42 +0530392 struct ath_buf *tbf;
393
Sujithd43f30152009-01-16 21:38:53 +0530394 tbf = ath_clone_txbuf(sc, bf_last);
Vasanthakumar Thiagarajanc41d92d2009-07-14 20:17:11 -0400395 /*
396 * Update tx baw and complete the frame with
397 * failed status if we run out of tx buf
398 */
399 if (!tbf) {
400 spin_lock_bh(&txq->axq_lock);
401 ath_tx_update_baw(sc, tid,
402 bf->bf_seqno);
403 spin_unlock_bh(&txq->axq_lock);
404
405 bf->bf_state.bf_type |= BUF_XRETRY;
406 ath_tx_rc_status(bf, ds, nbad,
407 0, false);
Sujithfec247c2009-07-27 12:08:16 +0530408 ath_tx_complete_buf(sc, bf, txq,
409 &bf_head, 0, 0);
Vasanthakumar Thiagarajan8a460972009-06-10 17:50:09 +0530410 break;
Vasanthakumar Thiagarajanc41d92d2009-07-14 20:17:11 -0400411 }
412
Sujithd43f30152009-01-16 21:38:53 +0530413 ath9k_hw_cleartxdesc(sc->sc_ah, tbf->bf_desc);
Sujithe8324352009-01-16 21:38:42 +0530414 list_add_tail(&tbf->list, &bf_head);
415 } else {
416 /*
417 * Clear descriptor status words for
418 * software retry
419 */
Sujithd43f30152009-01-16 21:38:53 +0530420 ath9k_hw_cleartxdesc(sc->sc_ah, bf->bf_desc);
Sujithe8324352009-01-16 21:38:42 +0530421 }
422
423 /*
424 * Put this buffer to the temporary pending
425 * queue to retain ordering
426 */
427 list_splice_tail_init(&bf_head, &bf_pending);
428 }
429
430 bf = bf_next;
431 }
432
433 if (tid->state & AGGR_CLEANUP) {
Sujithe8324352009-01-16 21:38:42 +0530434 if (tid->baw_head == tid->baw_tail) {
435 tid->state &= ~AGGR_ADDBA_COMPLETE;
Sujithe8324352009-01-16 21:38:42 +0530436 tid->state &= ~AGGR_CLEANUP;
437
438 /* send buffered frames as singles */
439 ath_tx_flush_tid(sc, tid);
Sujithd43f30152009-01-16 21:38:53 +0530440 }
Sujith1286ec62009-01-27 13:30:37 +0530441 rcu_read_unlock();
Sujithe8324352009-01-16 21:38:42 +0530442 return;
443 }
444
Sujithd43f30152009-01-16 21:38:53 +0530445 /* prepend un-acked frames to the beginning of the pending frame queue */
Sujithe8324352009-01-16 21:38:42 +0530446 if (!list_empty(&bf_pending)) {
447 spin_lock_bh(&txq->axq_lock);
448 list_splice(&bf_pending, &tid->buf_q);
449 ath_tx_queue_tid(txq, tid);
450 spin_unlock_bh(&txq->axq_lock);
451 }
452
Sujith1286ec62009-01-27 13:30:37 +0530453 rcu_read_unlock();
454
Sujithe8324352009-01-16 21:38:42 +0530455 if (needreset)
456 ath_reset(sc, false);
Sujithe8324352009-01-16 21:38:42 +0530457}
458
459static u32 ath_lookup_rate(struct ath_softc *sc, struct ath_buf *bf,
460 struct ath_atx_tid *tid)
461{
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400462 const struct ath_rate_table *rate_table = sc->cur_rate_table;
Sujithe8324352009-01-16 21:38:42 +0530463 struct sk_buff *skb;
464 struct ieee80211_tx_info *tx_info;
465 struct ieee80211_tx_rate *rates;
Sujithd43f30152009-01-16 21:38:53 +0530466 u32 max_4ms_framelen, frmlen;
Sujith4ef70842009-07-23 15:32:41 +0530467 u16 aggr_limit, legacy = 0;
Sujithe8324352009-01-16 21:38:42 +0530468 int i;
469
Sujitha22be222009-03-30 15:28:36 +0530470 skb = bf->bf_mpdu;
Sujithe8324352009-01-16 21:38:42 +0530471 tx_info = IEEE80211_SKB_CB(skb);
472 rates = tx_info->control.rates;
Sujithe8324352009-01-16 21:38:42 +0530473
474 /*
475 * Find the lowest frame length among the rate series that will have a
476 * 4ms transmit duration.
477 * TODO - TXOP limit needs to be considered.
478 */
479 max_4ms_framelen = ATH_AMPDU_LIMIT_MAX;
480
481 for (i = 0; i < 4; i++) {
482 if (rates[i].count) {
483 if (!WLAN_RC_PHY_HT(rate_table->info[rates[i].idx].phy)) {
484 legacy = 1;
485 break;
486 }
487
Sujithd43f30152009-01-16 21:38:53 +0530488 frmlen = rate_table->info[rates[i].idx].max_4ms_framelen;
489 max_4ms_framelen = min(max_4ms_framelen, frmlen);
Sujithe8324352009-01-16 21:38:42 +0530490 }
491 }
492
493 /*
494 * limit aggregate size by the minimum rate if rate selected is
495 * not a probe rate, if rate selected is a probe rate then
496 * avoid aggregation of this packet.
497 */
498 if (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE || legacy)
499 return 0;
500
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +0530501 if (sc->sc_flags & SC_OP_BT_PRIORITY_DETECTED)
502 aggr_limit = min((max_4ms_framelen * 3) / 8,
503 (u32)ATH_AMPDU_LIMIT_MAX);
504 else
505 aggr_limit = min(max_4ms_framelen,
506 (u32)ATH_AMPDU_LIMIT_MAX);
Sujithe8324352009-01-16 21:38:42 +0530507
508 /*
509 * h/w can accept aggregates upto 16 bit lengths (65535).
510 * The IE, however can hold upto 65536, which shows up here
511 * as zero. Ignore 65536 since we are constrained by hw.
512 */
Sujith4ef70842009-07-23 15:32:41 +0530513 if (tid->an->maxampdu)
514 aggr_limit = min(aggr_limit, tid->an->maxampdu);
Sujithe8324352009-01-16 21:38:42 +0530515
516 return aggr_limit;
517}
518
519/*
Sujithd43f30152009-01-16 21:38:53 +0530520 * Returns the number of delimiters to be added to
Sujithe8324352009-01-16 21:38:42 +0530521 * meet the minimum required mpdudensity.
Sujithe8324352009-01-16 21:38:42 +0530522 */
523static int ath_compute_num_delims(struct ath_softc *sc, struct ath_atx_tid *tid,
524 struct ath_buf *bf, u16 frmlen)
525{
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400526 const struct ath_rate_table *rt = sc->cur_rate_table;
Sujithe8324352009-01-16 21:38:42 +0530527 struct sk_buff *skb = bf->bf_mpdu;
528 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Sujith4ef70842009-07-23 15:32:41 +0530529 u32 nsymbits, nsymbols;
Sujithe8324352009-01-16 21:38:42 +0530530 u16 minlen;
531 u8 rc, flags, rix;
532 int width, half_gi, ndelim, mindelim;
533
534 /* Select standard number of delimiters based on frame length alone */
535 ndelim = ATH_AGGR_GET_NDELIM(frmlen);
536
537 /*
538 * If encryption enabled, hardware requires some more padding between
539 * subframes.
540 * TODO - this could be improved to be dependent on the rate.
541 * The hardware can keep up at lower rates, but not higher rates
542 */
543 if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR)
544 ndelim += ATH_AGGR_ENCRYPTDELIM;
545
546 /*
547 * Convert desired mpdu density from microeconds to bytes based
548 * on highest rate in rate series (i.e. first rate) to determine
549 * required minimum length for subframe. Take into account
550 * whether high rate is 20 or 40Mhz and half or full GI.
Sujith4ef70842009-07-23 15:32:41 +0530551 *
Sujithe8324352009-01-16 21:38:42 +0530552 * If there is no mpdu density restriction, no further calculation
553 * is needed.
554 */
Sujith4ef70842009-07-23 15:32:41 +0530555
556 if (tid->an->mpdudensity == 0)
Sujithe8324352009-01-16 21:38:42 +0530557 return ndelim;
558
559 rix = tx_info->control.rates[0].idx;
560 flags = tx_info->control.rates[0].flags;
561 rc = rt->info[rix].ratecode;
562 width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0;
563 half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0;
564
565 if (half_gi)
Sujith4ef70842009-07-23 15:32:41 +0530566 nsymbols = NUM_SYMBOLS_PER_USEC_HALFGI(tid->an->mpdudensity);
Sujithe8324352009-01-16 21:38:42 +0530567 else
Sujith4ef70842009-07-23 15:32:41 +0530568 nsymbols = NUM_SYMBOLS_PER_USEC(tid->an->mpdudensity);
Sujithe8324352009-01-16 21:38:42 +0530569
570 if (nsymbols == 0)
571 nsymbols = 1;
572
573 nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
574 minlen = (nsymbols * nsymbits) / BITS_PER_BYTE;
575
Sujithe8324352009-01-16 21:38:42 +0530576 if (frmlen < minlen) {
Sujithe8324352009-01-16 21:38:42 +0530577 mindelim = (minlen - frmlen) / ATH_AGGR_DELIM_SZ;
578 ndelim = max(mindelim, ndelim);
579 }
580
581 return ndelim;
582}
583
584static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
Sujithfec247c2009-07-27 12:08:16 +0530585 struct ath_txq *txq,
Sujithd43f30152009-01-16 21:38:53 +0530586 struct ath_atx_tid *tid,
587 struct list_head *bf_q)
Sujithe8324352009-01-16 21:38:42 +0530588{
589#define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
Sujithd43f30152009-01-16 21:38:53 +0530590 struct ath_buf *bf, *bf_first, *bf_prev = NULL;
591 int rl = 0, nframes = 0, ndelim, prev_al = 0;
Sujithe8324352009-01-16 21:38:42 +0530592 u16 aggr_limit = 0, al = 0, bpad = 0,
593 al_delta, h_baw = tid->baw_size / 2;
594 enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
Sujithe8324352009-01-16 21:38:42 +0530595
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
Sujithd43f30152009-01-16 21:38:53 +0530601 /* do not step over block-ack window */
Sujithe8324352009-01-16 21:38:42 +0530602 if (!BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno)) {
603 status = ATH_AGGR_BAW_CLOSED;
604 break;
605 }
606
607 if (!rl) {
608 aggr_limit = ath_lookup_rate(sc, bf, tid);
609 rl = 1;
610 }
611
Sujithd43f30152009-01-16 21:38:53 +0530612 /* do not exceed aggregation limit */
Sujithe8324352009-01-16 21:38:42 +0530613 al_delta = ATH_AGGR_DELIM_SZ + bf->bf_frmlen;
614
Sujithd43f30152009-01-16 21:38:53 +0530615 if (nframes &&
616 (aggr_limit < (al + bpad + al_delta + prev_al))) {
Sujithe8324352009-01-16 21:38:42 +0530617 status = ATH_AGGR_LIMITED;
618 break;
619 }
620
Sujithd43f30152009-01-16 21:38:53 +0530621 /* do not exceed subframe limit */
622 if (nframes >= min((int)h_baw, ATH_AMPDU_SUBFRAME_DEFAULT)) {
Sujithe8324352009-01-16 21:38:42 +0530623 status = ATH_AGGR_LIMITED;
624 break;
625 }
Sujithd43f30152009-01-16 21:38:53 +0530626 nframes++;
Sujithe8324352009-01-16 21:38:42 +0530627
Sujithd43f30152009-01-16 21:38:53 +0530628 /* add padding for previous frame to aggregation length */
Sujithe8324352009-01-16 21:38:42 +0530629 al += bpad + al_delta;
630
631 /*
632 * Get the delimiters needed to meet the MPDU
633 * density for this node.
634 */
635 ndelim = ath_compute_num_delims(sc, tid, bf_first, bf->bf_frmlen);
Sujithe8324352009-01-16 21:38:42 +0530636 bpad = PADBYTES(al_delta) + (ndelim << 2);
637
638 bf->bf_next = NULL;
Sujithd43f30152009-01-16 21:38:53 +0530639 bf->bf_desc->ds_link = 0;
Sujithe8324352009-01-16 21:38:42 +0530640
Sujithd43f30152009-01-16 21:38:53 +0530641 /* link buffers of this frame to the aggregate */
Sujithe8324352009-01-16 21:38:42 +0530642 ath_tx_addto_baw(sc, tid, bf);
Sujithd43f30152009-01-16 21:38:53 +0530643 ath9k_hw_set11n_aggr_middle(sc->sc_ah, bf->bf_desc, ndelim);
644 list_move_tail(&bf->list, bf_q);
Sujithe8324352009-01-16 21:38:42 +0530645 if (bf_prev) {
646 bf_prev->bf_next = bf;
Sujithd43f30152009-01-16 21:38:53 +0530647 bf_prev->bf_desc->ds_link = bf->bf_daddr;
Sujithe8324352009-01-16 21:38:42 +0530648 }
649 bf_prev = bf;
Sujithfec247c2009-07-27 12:08:16 +0530650
Sujithe8324352009-01-16 21:38:42 +0530651 } while (!list_empty(&tid->buf_q));
652
653 bf_first->bf_al = al;
654 bf_first->bf_nframes = nframes;
Sujithd43f30152009-01-16 21:38:53 +0530655
Sujithe8324352009-01-16 21:38:42 +0530656 return status;
657#undef PADBYTES
658}
659
660static void ath_tx_sched_aggr(struct ath_softc *sc, struct ath_txq *txq,
661 struct ath_atx_tid *tid)
662{
Sujithd43f30152009-01-16 21:38:53 +0530663 struct ath_buf *bf;
Sujithe8324352009-01-16 21:38:42 +0530664 enum ATH_AGGR_STATUS status;
665 struct list_head bf_q;
Sujithe8324352009-01-16 21:38:42 +0530666
667 do {
668 if (list_empty(&tid->buf_q))
669 return;
670
671 INIT_LIST_HEAD(&bf_q);
672
Sujithfec247c2009-07-27 12:08:16 +0530673 status = ath_tx_form_aggr(sc, txq, tid, &bf_q);
Sujithe8324352009-01-16 21:38:42 +0530674
675 /*
Sujithd43f30152009-01-16 21:38:53 +0530676 * no frames picked up to be aggregated;
677 * block-ack window is not open.
Sujithe8324352009-01-16 21:38:42 +0530678 */
679 if (list_empty(&bf_q))
680 break;
681
682 bf = list_first_entry(&bf_q, struct ath_buf, list);
Sujithd43f30152009-01-16 21:38:53 +0530683 bf->bf_lastbf = list_entry(bf_q.prev, struct ath_buf, list);
Sujithe8324352009-01-16 21:38:42 +0530684
Sujithd43f30152009-01-16 21:38:53 +0530685 /* if only one frame, send as non-aggregate */
Sujithe8324352009-01-16 21:38:42 +0530686 if (bf->bf_nframes == 1) {
Sujithe8324352009-01-16 21:38:42 +0530687 bf->bf_state.bf_type &= ~BUF_AGGR;
Sujithd43f30152009-01-16 21:38:53 +0530688 ath9k_hw_clr11n_aggr(sc->sc_ah, bf->bf_desc);
Sujithe8324352009-01-16 21:38:42 +0530689 ath_buf_set_rate(sc, bf);
690 ath_tx_txqaddbuf(sc, txq, &bf_q);
691 continue;
692 }
693
Sujithd43f30152009-01-16 21:38:53 +0530694 /* setup first desc of aggregate */
Sujithe8324352009-01-16 21:38:42 +0530695 bf->bf_state.bf_type |= BUF_AGGR;
696 ath_buf_set_rate(sc, bf);
697 ath9k_hw_set11n_aggr_first(sc->sc_ah, bf->bf_desc, bf->bf_al);
698
Sujithd43f30152009-01-16 21:38:53 +0530699 /* anchor last desc of aggregate */
700 ath9k_hw_set11n_aggr_last(sc->sc_ah, bf->bf_lastbf->bf_desc);
Sujithe8324352009-01-16 21:38:42 +0530701
702 txq->axq_aggr_depth++;
Sujithe8324352009-01-16 21:38:42 +0530703 ath_tx_txqaddbuf(sc, txq, &bf_q);
Sujithfec247c2009-07-27 12:08:16 +0530704 TX_STAT_INC(txq->axq_qnum, a_aggr);
Sujithe8324352009-01-16 21:38:42 +0530705
706 } while (txq->axq_depth < ATH_AGGR_MIN_QDEPTH &&
707 status != ATH_AGGR_BAW_CLOSED);
708}
709
Sujithf83da962009-07-23 15:32:37 +0530710void ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
711 u16 tid, u16 *ssn)
Sujithe8324352009-01-16 21:38:42 +0530712{
713 struct ath_atx_tid *txtid;
714 struct ath_node *an;
715
716 an = (struct ath_node *)sta->drv_priv;
Sujithf83da962009-07-23 15:32:37 +0530717 txtid = ATH_AN_2_TID(an, tid);
718 txtid->state |= AGGR_ADDBA_PROGRESS;
719 ath_tx_pause_tid(sc, txtid);
720 *ssn = txtid->seq_start;
Sujithe8324352009-01-16 21:38:42 +0530721}
722
Sujithf83da962009-07-23 15:32:37 +0530723void ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
Sujithe8324352009-01-16 21:38:42 +0530724{
725 struct ath_node *an = (struct ath_node *)sta->drv_priv;
726 struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid);
727 struct ath_txq *txq = &sc->tx.txq[txtid->ac->qnum];
728 struct ath_buf *bf;
729 struct list_head bf_head;
730 INIT_LIST_HEAD(&bf_head);
731
732 if (txtid->state & AGGR_CLEANUP)
Sujithf83da962009-07-23 15:32:37 +0530733 return;
Sujithe8324352009-01-16 21:38:42 +0530734
735 if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
Vasanthakumar Thiagarajan5eae6592009-06-09 15:28:21 +0530736 txtid->state &= ~AGGR_ADDBA_PROGRESS;
Sujithf83da962009-07-23 15:32:37 +0530737 return;
Sujithe8324352009-01-16 21:38:42 +0530738 }
739
740 ath_tx_pause_tid(sc, txtid);
741
742 /* drop all software retried frames and mark this TID */
743 spin_lock_bh(&txq->axq_lock);
744 while (!list_empty(&txtid->buf_q)) {
745 bf = list_first_entry(&txtid->buf_q, struct ath_buf, list);
746 if (!bf_isretried(bf)) {
747 /*
748 * NB: it's based on the assumption that
749 * software retried frame will always stay
750 * at the head of software queue.
751 */
752 break;
753 }
Sujithd43f30152009-01-16 21:38:53 +0530754 list_move_tail(&bf->list, &bf_head);
Sujithe8324352009-01-16 21:38:42 +0530755 ath_tx_update_baw(sc, txtid, bf->bf_seqno);
Sujithfec247c2009-07-27 12:08:16 +0530756 ath_tx_complete_buf(sc, bf, txq, &bf_head, 0, 0);
Sujithe8324352009-01-16 21:38:42 +0530757 }
Sujithd43f30152009-01-16 21:38:53 +0530758 spin_unlock_bh(&txq->axq_lock);
Sujithe8324352009-01-16 21:38:42 +0530759
760 if (txtid->baw_head != txtid->baw_tail) {
Sujithe8324352009-01-16 21:38:42 +0530761 txtid->state |= AGGR_CLEANUP;
762 } else {
763 txtid->state &= ~AGGR_ADDBA_COMPLETE;
Sujithe8324352009-01-16 21:38:42 +0530764 ath_tx_flush_tid(sc, txtid);
765 }
Sujithe8324352009-01-16 21:38:42 +0530766}
767
768void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
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->baw_size =
778 IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
779 txtid->state |= AGGR_ADDBA_COMPLETE;
780 txtid->state &= ~AGGR_ADDBA_PROGRESS;
781 ath_tx_resume_tid(sc, txtid);
782 }
783}
784
785bool ath_tx_aggr_check(struct ath_softc *sc, struct ath_node *an, u8 tidno)
786{
787 struct ath_atx_tid *txtid;
788
789 if (!(sc->sc_flags & SC_OP_TXAGGR))
790 return false;
791
792 txtid = ATH_AN_2_TID(an, tidno);
793
Vasanthakumar Thiagarajanc3d8f022009-06-10 17:50:08 +0530794 if (!(txtid->state & (AGGR_ADDBA_COMPLETE | AGGR_ADDBA_PROGRESS)))
Sujithe8324352009-01-16 21:38:42 +0530795 return true;
Sujithe8324352009-01-16 21:38:42 +0530796 return false;
797}
798
799/********************/
800/* Queue Management */
801/********************/
802
Sujithe8324352009-01-16 21:38:42 +0530803static void ath_txq_drain_pending_buffers(struct ath_softc *sc,
804 struct ath_txq *txq)
805{
806 struct ath_atx_ac *ac, *ac_tmp;
807 struct ath_atx_tid *tid, *tid_tmp;
808
809 list_for_each_entry_safe(ac, ac_tmp, &txq->axq_acq, list) {
810 list_del(&ac->list);
811 ac->sched = false;
812 list_for_each_entry_safe(tid, tid_tmp, &ac->tid_q, list) {
813 list_del(&tid->list);
814 tid->sched = false;
815 ath_tid_drain(sc, txq, tid);
816 }
817 }
818}
819
820struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype)
821{
Sujithcbe61d82009-02-09 13:27:12 +0530822 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700823 struct ath_common *common = ath9k_hw_common(ah);
Sujithe8324352009-01-16 21:38:42 +0530824 struct ath9k_tx_queue_info qi;
825 int qnum;
826
827 memset(&qi, 0, sizeof(qi));
828 qi.tqi_subtype = subtype;
829 qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT;
830 qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
831 qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT;
832 qi.tqi_physCompBuf = 0;
833
834 /*
835 * Enable interrupts only for EOL and DESC conditions.
836 * We mark tx descriptors to receive a DESC interrupt
837 * when a tx queue gets deep; otherwise waiting for the
838 * EOL to reap descriptors. Note that this is done to
839 * reduce interrupt load and this only defers reaping
840 * descriptors, never transmitting frames. Aside from
841 * reducing interrupts this also permits more concurrency.
842 * The only potential downside is if the tx queue backs
843 * up in which case the top half of the kernel may backup
844 * due to a lack of tx descriptors.
845 *
846 * The UAPSD queue is an exception, since we take a desc-
847 * based intr on the EOSP frames.
848 */
849 if (qtype == ATH9K_TX_QUEUE_UAPSD)
850 qi.tqi_qflags = TXQ_FLAG_TXDESCINT_ENABLE;
851 else
852 qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE |
853 TXQ_FLAG_TXDESCINT_ENABLE;
854 qnum = ath9k_hw_setuptxqueue(ah, qtype, &qi);
855 if (qnum == -1) {
856 /*
857 * NB: don't print a message, this happens
858 * normally on parts with too few tx queues
859 */
860 return NULL;
861 }
862 if (qnum >= ARRAY_SIZE(sc->tx.txq)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700863 ath_print(common, ATH_DBG_FATAL,
864 "qnum %u out of range, max %u!\n",
865 qnum, (unsigned int)ARRAY_SIZE(sc->tx.txq));
Sujithe8324352009-01-16 21:38:42 +0530866 ath9k_hw_releasetxqueue(ah, qnum);
867 return NULL;
868 }
869 if (!ATH_TXQ_SETUP(sc, qnum)) {
870 struct ath_txq *txq = &sc->tx.txq[qnum];
871
872 txq->axq_qnum = qnum;
873 txq->axq_link = NULL;
874 INIT_LIST_HEAD(&txq->axq_q);
875 INIT_LIST_HEAD(&txq->axq_acq);
876 spin_lock_init(&txq->axq_lock);
877 txq->axq_depth = 0;
878 txq->axq_aggr_depth = 0;
Sujithe8324352009-01-16 21:38:42 +0530879 txq->axq_linkbuf = NULL;
Senthil Balasubramanian164ace32009-07-14 20:17:09 -0400880 txq->axq_tx_inprogress = false;
Sujithe8324352009-01-16 21:38:42 +0530881 sc->tx.txqsetup |= 1<<qnum;
882 }
883 return &sc->tx.txq[qnum];
884}
885
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +0530886int ath_tx_get_qnum(struct ath_softc *sc, int qtype, int haltype)
Sujithe8324352009-01-16 21:38:42 +0530887{
888 int qnum;
889
890 switch (qtype) {
891 case ATH9K_TX_QUEUE_DATA:
892 if (haltype >= ARRAY_SIZE(sc->tx.hwq_map)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700893 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
894 "HAL AC %u out of range, max %zu!\n",
895 haltype, ARRAY_SIZE(sc->tx.hwq_map));
Sujithe8324352009-01-16 21:38:42 +0530896 return -1;
897 }
898 qnum = sc->tx.hwq_map[haltype];
899 break;
900 case ATH9K_TX_QUEUE_BEACON:
901 qnum = sc->beacon.beaconq;
902 break;
903 case ATH9K_TX_QUEUE_CAB:
904 qnum = sc->beacon.cabq->axq_qnum;
905 break;
906 default:
907 qnum = -1;
908 }
909 return qnum;
910}
911
912struct ath_txq *ath_test_get_txq(struct ath_softc *sc, struct sk_buff *skb)
913{
914 struct ath_txq *txq = NULL;
Luis R. Rodriguezf52de032009-11-02 17:09:12 -0800915 u16 skb_queue = skb_get_queue_mapping(skb);
Sujithe8324352009-01-16 21:38:42 +0530916 int qnum;
917
Luis R. Rodriguezf52de032009-11-02 17:09:12 -0800918 qnum = ath_get_hal_qnum(skb_queue, sc);
Sujithe8324352009-01-16 21:38:42 +0530919 txq = &sc->tx.txq[qnum];
920
921 spin_lock_bh(&txq->axq_lock);
922
923 if (txq->axq_depth >= (ATH_TXBUF - 20)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700924 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_XMIT,
925 "TX queue: %d is full, depth: %d\n",
926 qnum, txq->axq_depth);
Luis R. Rodriguezf52de032009-11-02 17:09:12 -0800927 ath_mac80211_stop_queue(sc, skb_queue);
Sujithe8324352009-01-16 21:38:42 +0530928 txq->stopped = 1;
929 spin_unlock_bh(&txq->axq_lock);
930 return NULL;
931 }
932
933 spin_unlock_bh(&txq->axq_lock);
934
935 return txq;
936}
937
938int ath_txq_update(struct ath_softc *sc, int qnum,
939 struct ath9k_tx_queue_info *qinfo)
940{
Sujithcbe61d82009-02-09 13:27:12 +0530941 struct ath_hw *ah = sc->sc_ah;
Sujithe8324352009-01-16 21:38:42 +0530942 int error = 0;
943 struct ath9k_tx_queue_info qi;
944
945 if (qnum == sc->beacon.beaconq) {
946 /*
947 * XXX: for beacon queue, we just save the parameter.
948 * It will be picked up by ath_beaconq_config when
949 * it's necessary.
950 */
951 sc->beacon.beacon_qi = *qinfo;
952 return 0;
953 }
954
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -0700955 BUG_ON(sc->tx.txq[qnum].axq_qnum != qnum);
Sujithe8324352009-01-16 21:38:42 +0530956
957 ath9k_hw_get_txq_props(ah, qnum, &qi);
958 qi.tqi_aifs = qinfo->tqi_aifs;
959 qi.tqi_cwmin = qinfo->tqi_cwmin;
960 qi.tqi_cwmax = qinfo->tqi_cwmax;
961 qi.tqi_burstTime = qinfo->tqi_burstTime;
962 qi.tqi_readyTime = qinfo->tqi_readyTime;
963
964 if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700965 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
966 "Unable to update hardware queue %u!\n", qnum);
Sujithe8324352009-01-16 21:38:42 +0530967 error = -EIO;
968 } else {
969 ath9k_hw_resettxqueue(ah, qnum);
970 }
971
972 return error;
973}
974
975int ath_cabq_update(struct ath_softc *sc)
976{
977 struct ath9k_tx_queue_info qi;
978 int qnum = sc->beacon.cabq->axq_qnum;
Sujithe8324352009-01-16 21:38:42 +0530979
980 ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi);
981 /*
982 * Ensure the readytime % is within the bounds.
983 */
Sujith17d79042009-02-09 13:27:03 +0530984 if (sc->config.cabqReadytime < ATH9K_READY_TIME_LO_BOUND)
985 sc->config.cabqReadytime = ATH9K_READY_TIME_LO_BOUND;
986 else if (sc->config.cabqReadytime > ATH9K_READY_TIME_HI_BOUND)
987 sc->config.cabqReadytime = ATH9K_READY_TIME_HI_BOUND;
Sujithe8324352009-01-16 21:38:42 +0530988
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200989 qi.tqi_readyTime = (sc->beacon_interval *
Sujithfdbf7332009-02-17 15:36:35 +0530990 sc->config.cabqReadytime) / 100;
Sujithe8324352009-01-16 21:38:42 +0530991 ath_txq_update(sc, qnum, &qi);
992
993 return 0;
994}
995
Sujith043a0402009-01-16 21:38:47 +0530996/*
997 * Drain a given TX queue (could be Beacon or Data)
998 *
999 * This assumes output has been stopped and
1000 * we do not need to block ath_tx_tasklet.
1001 */
1002void ath_draintxq(struct ath_softc *sc, struct ath_txq *txq, bool retry_tx)
Sujithe8324352009-01-16 21:38:42 +05301003{
1004 struct ath_buf *bf, *lastbf;
1005 struct list_head bf_head;
1006
1007 INIT_LIST_HEAD(&bf_head);
1008
Sujithe8324352009-01-16 21:38:42 +05301009 for (;;) {
1010 spin_lock_bh(&txq->axq_lock);
1011
1012 if (list_empty(&txq->axq_q)) {
1013 txq->axq_link = NULL;
1014 txq->axq_linkbuf = NULL;
1015 spin_unlock_bh(&txq->axq_lock);
1016 break;
1017 }
1018
1019 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
1020
Sujitha119cc42009-03-30 15:28:38 +05301021 if (bf->bf_stale) {
Sujithe8324352009-01-16 21:38:42 +05301022 list_del(&bf->list);
1023 spin_unlock_bh(&txq->axq_lock);
1024
1025 spin_lock_bh(&sc->tx.txbuflock);
1026 list_add_tail(&bf->list, &sc->tx.txbuf);
1027 spin_unlock_bh(&sc->tx.txbuflock);
1028 continue;
1029 }
1030
1031 lastbf = bf->bf_lastbf;
1032 if (!retry_tx)
1033 lastbf->bf_desc->ds_txstat.ts_flags =
1034 ATH9K_TX_SW_ABORTED;
1035
1036 /* remove ath_buf's of the same mpdu from txq */
1037 list_cut_position(&bf_head, &txq->axq_q, &lastbf->list);
1038 txq->axq_depth--;
1039
1040 spin_unlock_bh(&txq->axq_lock);
1041
1042 if (bf_isampdu(bf))
Sujithd43f30152009-01-16 21:38:53 +05301043 ath_tx_complete_aggr(sc, txq, bf, &bf_head, 0);
Sujithe8324352009-01-16 21:38:42 +05301044 else
Sujithfec247c2009-07-27 12:08:16 +05301045 ath_tx_complete_buf(sc, bf, txq, &bf_head, 0, 0);
Sujithe8324352009-01-16 21:38:42 +05301046 }
1047
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04001048 spin_lock_bh(&txq->axq_lock);
1049 txq->axq_tx_inprogress = false;
1050 spin_unlock_bh(&txq->axq_lock);
1051
Sujithe8324352009-01-16 21:38:42 +05301052 /* flush any pending frames if aggregation is enabled */
1053 if (sc->sc_flags & SC_OP_TXAGGR) {
1054 if (!retry_tx) {
1055 spin_lock_bh(&txq->axq_lock);
1056 ath_txq_drain_pending_buffers(sc, txq);
1057 spin_unlock_bh(&txq->axq_lock);
1058 }
1059 }
1060}
1061
Sujith043a0402009-01-16 21:38:47 +05301062void ath_drain_all_txq(struct ath_softc *sc, bool retry_tx)
1063{
Sujithcbe61d82009-02-09 13:27:12 +05301064 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001065 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith043a0402009-01-16 21:38:47 +05301066 struct ath_txq *txq;
1067 int i, npend = 0;
1068
1069 if (sc->sc_flags & SC_OP_INVALID)
1070 return;
1071
1072 /* Stop beacon queue */
1073 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
1074
1075 /* Stop data queues */
1076 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1077 if (ATH_TXQ_SETUP(sc, i)) {
1078 txq = &sc->tx.txq[i];
1079 ath9k_hw_stoptxdma(ah, txq->axq_qnum);
1080 npend += ath9k_hw_numtxpending(ah, txq->axq_qnum);
1081 }
1082 }
1083
1084 if (npend) {
1085 int r;
1086
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001087 ath_print(common, ATH_DBG_XMIT,
1088 "Unable to stop TxDMA. Reset HAL!\n");
Sujith043a0402009-01-16 21:38:47 +05301089
1090 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301091 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, true);
Sujith043a0402009-01-16 21:38:47 +05301092 if (r)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001093 ath_print(common, ATH_DBG_FATAL,
1094 "Unable to reset hardware; reset status %d\n",
1095 r);
Sujith043a0402009-01-16 21:38:47 +05301096 spin_unlock_bh(&sc->sc_resetlock);
1097 }
1098
1099 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1100 if (ATH_TXQ_SETUP(sc, i))
1101 ath_draintxq(sc, &sc->tx.txq[i], retry_tx);
1102 }
1103}
1104
Sujithe8324352009-01-16 21:38:42 +05301105void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq)
1106{
1107 ath9k_hw_releasetxqueue(sc->sc_ah, txq->axq_qnum);
1108 sc->tx.txqsetup &= ~(1<<txq->axq_qnum);
1109}
1110
Sujithe8324352009-01-16 21:38:42 +05301111void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
1112{
1113 struct ath_atx_ac *ac;
1114 struct ath_atx_tid *tid;
1115
1116 if (list_empty(&txq->axq_acq))
1117 return;
1118
1119 ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac, list);
1120 list_del(&ac->list);
1121 ac->sched = false;
1122
1123 do {
1124 if (list_empty(&ac->tid_q))
1125 return;
1126
1127 tid = list_first_entry(&ac->tid_q, struct ath_atx_tid, list);
1128 list_del(&tid->list);
1129 tid->sched = false;
1130
1131 if (tid->paused)
1132 continue;
1133
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04001134 ath_tx_sched_aggr(sc, txq, tid);
Sujithe8324352009-01-16 21:38:42 +05301135
1136 /*
1137 * add tid to round-robin queue if more frames
1138 * are pending for the tid
1139 */
1140 if (!list_empty(&tid->buf_q))
1141 ath_tx_queue_tid(txq, tid);
1142
1143 break;
1144 } while (!list_empty(&ac->tid_q));
1145
1146 if (!list_empty(&ac->tid_q)) {
1147 if (!ac->sched) {
1148 ac->sched = true;
1149 list_add_tail(&ac->list, &txq->axq_acq);
1150 }
1151 }
1152}
1153
1154int ath_tx_setup(struct ath_softc *sc, int haltype)
1155{
1156 struct ath_txq *txq;
1157
1158 if (haltype >= ARRAY_SIZE(sc->tx.hwq_map)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001159 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
1160 "HAL AC %u out of range, max %zu!\n",
Sujithe8324352009-01-16 21:38:42 +05301161 haltype, ARRAY_SIZE(sc->tx.hwq_map));
1162 return 0;
1163 }
1164 txq = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, haltype);
1165 if (txq != NULL) {
1166 sc->tx.hwq_map[haltype] = txq->axq_qnum;
1167 return 1;
1168 } else
1169 return 0;
1170}
1171
1172/***********/
1173/* TX, DMA */
1174/***********/
1175
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001176/*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001177 * Insert a chain of ath_buf (descriptors) on a txq and
1178 * assume the descriptors are already chained together by caller.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001179 */
Sujith102e0572008-10-29 10:15:16 +05301180static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
1181 struct list_head *head)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001182{
Sujithcbe61d82009-02-09 13:27:12 +05301183 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001184 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001185 struct ath_buf *bf;
Sujith102e0572008-10-29 10:15:16 +05301186
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001187 /*
1188 * Insert the frame on the outbound list and
1189 * pass it on to the hardware.
1190 */
1191
1192 if (list_empty(head))
1193 return;
1194
1195 bf = list_first_entry(head, struct ath_buf, list);
1196
1197 list_splice_tail_init(head, &txq->axq_q);
1198 txq->axq_depth++;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001199 txq->axq_linkbuf = list_entry(txq->axq_q.prev, struct ath_buf, list);
1200
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001201 ath_print(common, ATH_DBG_QUEUE,
1202 "qnum: %d, txq depth: %d\n", txq->axq_qnum, txq->axq_depth);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001203
1204 if (txq->axq_link == NULL) {
1205 ath9k_hw_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001206 ath_print(common, ATH_DBG_XMIT,
1207 "TXDP[%u] = %llx (%p)\n",
1208 txq->axq_qnum, ito64(bf->bf_daddr), bf->bf_desc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001209 } else {
1210 *txq->axq_link = bf->bf_daddr;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001211 ath_print(common, ATH_DBG_XMIT, "link[%u] (%p)=%llx (%p)\n",
1212 txq->axq_qnum, txq->axq_link,
1213 ito64(bf->bf_daddr), bf->bf_desc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001214 }
1215 txq->axq_link = &(bf->bf_lastbf->bf_desc->ds_link);
1216 ath9k_hw_txstart(ah, txq->axq_qnum);
1217}
1218
Sujithe8324352009-01-16 21:38:42 +05301219static struct ath_buf *ath_tx_get_buffer(struct ath_softc *sc)
Sujithc4288392008-11-18 09:09:30 +05301220{
Sujithe8324352009-01-16 21:38:42 +05301221 struct ath_buf *bf = NULL;
Sujithc4288392008-11-18 09:09:30 +05301222
Sujithe8324352009-01-16 21:38:42 +05301223 spin_lock_bh(&sc->tx.txbuflock);
Sujithc4288392008-11-18 09:09:30 +05301224
Sujithe8324352009-01-16 21:38:42 +05301225 if (unlikely(list_empty(&sc->tx.txbuf))) {
1226 spin_unlock_bh(&sc->tx.txbuflock);
1227 return NULL;
Sujithc4288392008-11-18 09:09:30 +05301228 }
1229
Sujithe8324352009-01-16 21:38:42 +05301230 bf = list_first_entry(&sc->tx.txbuf, struct ath_buf, list);
1231 list_del(&bf->list);
Sujithc4288392008-11-18 09:09:30 +05301232
Sujithe8324352009-01-16 21:38:42 +05301233 spin_unlock_bh(&sc->tx.txbuflock);
Sujithc4288392008-11-18 09:09:30 +05301234
Sujithe8324352009-01-16 21:38:42 +05301235 return bf;
1236}
Sujithc4288392008-11-18 09:09:30 +05301237
Sujithe8324352009-01-16 21:38:42 +05301238static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_atx_tid *tid,
1239 struct list_head *bf_head,
1240 struct ath_tx_control *txctl)
1241{
1242 struct ath_buf *bf;
1243
Sujithe8324352009-01-16 21:38:42 +05301244 bf = list_first_entry(bf_head, struct ath_buf, list);
1245 bf->bf_state.bf_type |= BUF_AMPDU;
Sujithfec247c2009-07-27 12:08:16 +05301246 TX_STAT_INC(txctl->txq->axq_qnum, a_queued);
Sujithe8324352009-01-16 21:38:42 +05301247
1248 /*
1249 * Do not queue to h/w when any of the following conditions is true:
1250 * - there are pending frames in software queue
1251 * - the TID is currently paused for ADDBA/BAR request
1252 * - seqno is not within block-ack window
1253 * - h/w queue depth exceeds low water mark
1254 */
1255 if (!list_empty(&tid->buf_q) || tid->paused ||
1256 !BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno) ||
1257 txctl->txq->axq_depth >= ATH_AGGR_MIN_QDEPTH) {
Jouni Malinenf7a276a2008-12-15 16:02:04 +02001258 /*
Sujithe8324352009-01-16 21:38:42 +05301259 * Add this frame to software queue for scheduling later
1260 * for aggregation.
Jouni Malinenf7a276a2008-12-15 16:02:04 +02001261 */
Sujithd43f30152009-01-16 21:38:53 +05301262 list_move_tail(&bf->list, &tid->buf_q);
Sujithe8324352009-01-16 21:38:42 +05301263 ath_tx_queue_tid(txctl->txq, tid);
1264 return;
Jouni Malinenf7a276a2008-12-15 16:02:04 +02001265 }
1266
Sujithe8324352009-01-16 21:38:42 +05301267 /* Add sub-frame to BAW */
1268 ath_tx_addto_baw(sc, tid, bf);
1269
1270 /* Queue to h/w without aggregation */
1271 bf->bf_nframes = 1;
Sujithd43f30152009-01-16 21:38:53 +05301272 bf->bf_lastbf = bf;
Sujithe8324352009-01-16 21:38:42 +05301273 ath_buf_set_rate(sc, bf);
1274 ath_tx_txqaddbuf(sc, txctl->txq, bf_head);
Sujithc4288392008-11-18 09:09:30 +05301275}
1276
Sujithc37452b2009-03-09 09:31:57 +05301277static void ath_tx_send_ht_normal(struct ath_softc *sc, struct ath_txq *txq,
1278 struct ath_atx_tid *tid,
1279 struct list_head *bf_head)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001280{
Sujithe8324352009-01-16 21:38:42 +05301281 struct ath_buf *bf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001282
Sujithe8324352009-01-16 21:38:42 +05301283 bf = list_first_entry(bf_head, struct ath_buf, list);
1284 bf->bf_state.bf_type &= ~BUF_AMPDU;
1285
1286 /* update starting sequence number for subsequent ADDBA request */
1287 INCR(tid->seq_start, IEEE80211_SEQ_MAX);
1288
1289 bf->bf_nframes = 1;
Sujithd43f30152009-01-16 21:38:53 +05301290 bf->bf_lastbf = bf;
Sujithe8324352009-01-16 21:38:42 +05301291 ath_buf_set_rate(sc, bf);
1292 ath_tx_txqaddbuf(sc, txq, bf_head);
Sujithfec247c2009-07-27 12:08:16 +05301293 TX_STAT_INC(txq->axq_qnum, queued);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001294}
1295
Sujithc37452b2009-03-09 09:31:57 +05301296static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
1297 struct list_head *bf_head)
1298{
1299 struct ath_buf *bf;
1300
1301 bf = list_first_entry(bf_head, struct ath_buf, list);
1302
1303 bf->bf_lastbf = bf;
1304 bf->bf_nframes = 1;
1305 ath_buf_set_rate(sc, bf);
1306 ath_tx_txqaddbuf(sc, txq, bf_head);
Sujithfec247c2009-07-27 12:08:16 +05301307 TX_STAT_INC(txq->axq_qnum, queued);
Sujithc37452b2009-03-09 09:31:57 +05301308}
1309
Sujith528f0c62008-10-29 10:14:26 +05301310static enum ath9k_pkt_type get_hw_packet_type(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001311{
Sujith528f0c62008-10-29 10:14:26 +05301312 struct ieee80211_hdr *hdr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001313 enum ath9k_pkt_type htype;
1314 __le16 fc;
1315
Sujith528f0c62008-10-29 10:14:26 +05301316 hdr = (struct ieee80211_hdr *)skb->data;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001317 fc = hdr->frame_control;
1318
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001319 if (ieee80211_is_beacon(fc))
1320 htype = ATH9K_PKT_TYPE_BEACON;
1321 else if (ieee80211_is_probe_resp(fc))
1322 htype = ATH9K_PKT_TYPE_PROBE_RESP;
1323 else if (ieee80211_is_atim(fc))
1324 htype = ATH9K_PKT_TYPE_ATIM;
1325 else if (ieee80211_is_pspoll(fc))
1326 htype = ATH9K_PKT_TYPE_PSPOLL;
1327 else
1328 htype = ATH9K_PKT_TYPE_NORMAL;
1329
1330 return htype;
1331}
1332
Sujitha8efee42008-11-18 09:07:30 +05301333static bool is_pae(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001334{
1335 struct ieee80211_hdr *hdr;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001336 __le16 fc;
1337
1338 hdr = (struct ieee80211_hdr *)skb->data;
1339 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +02001340
Sujitha8efee42008-11-18 09:07:30 +05301341 if (ieee80211_is_data(fc)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001342 if (ieee80211_is_nullfunc(fc) ||
Sujith528f0c62008-10-29 10:14:26 +05301343 /* Port Access Entity (IEEE 802.1X) */
1344 (skb->protocol == cpu_to_be16(ETH_P_PAE))) {
Sujitha8efee42008-11-18 09:07:30 +05301345 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001346 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001347 }
1348
Sujitha8efee42008-11-18 09:07:30 +05301349 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001350}
1351
Sujith528f0c62008-10-29 10:14:26 +05301352static int get_hw_crypto_keytype(struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001353{
Sujith528f0c62008-10-29 10:14:26 +05301354 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1355
1356 if (tx_info->control.hw_key) {
1357 if (tx_info->control.hw_key->alg == ALG_WEP)
1358 return ATH9K_KEY_TYPE_WEP;
1359 else if (tx_info->control.hw_key->alg == ALG_TKIP)
1360 return ATH9K_KEY_TYPE_TKIP;
1361 else if (tx_info->control.hw_key->alg == ALG_CCMP)
1362 return ATH9K_KEY_TYPE_AES;
1363 }
1364
1365 return ATH9K_KEY_TYPE_CLEAR;
1366}
1367
Sujith528f0c62008-10-29 10:14:26 +05301368static void assign_aggr_tid_seqno(struct sk_buff *skb,
1369 struct ath_buf *bf)
1370{
1371 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1372 struct ieee80211_hdr *hdr;
1373 struct ath_node *an;
1374 struct ath_atx_tid *tid;
1375 __le16 fc;
1376 u8 *qc;
1377
1378 if (!tx_info->control.sta)
1379 return;
1380
1381 an = (struct ath_node *)tx_info->control.sta->drv_priv;
1382 hdr = (struct ieee80211_hdr *)skb->data;
1383 fc = hdr->frame_control;
1384
Sujith528f0c62008-10-29 10:14:26 +05301385 if (ieee80211_is_data_qos(fc)) {
1386 qc = ieee80211_get_qos_ctl(hdr);
1387 bf->bf_tidno = qc[0] & 0xf;
Sujith98deeea2008-08-11 14:05:46 +05301388 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001389
Sujithe8324352009-01-16 21:38:42 +05301390 /*
1391 * For HT capable stations, we save tidno for later use.
Senthil Balasubramaniand3a1db12008-12-22 16:31:58 +05301392 * We also override seqno set by upper layer with the one
1393 * in tx aggregation state.
1394 *
1395 * If fragmentation is on, the sequence number is
1396 * not overridden, since it has been
1397 * incremented by the fragmentation routine.
1398 *
1399 * FIXME: check if the fragmentation threshold exceeds
1400 * IEEE80211 max.
1401 */
1402 tid = ATH_AN_2_TID(an, bf->bf_tidno);
1403 hdr->seq_ctrl = cpu_to_le16(tid->seq_next <<
1404 IEEE80211_SEQ_SEQ_SHIFT);
1405 bf->bf_seqno = tid->seq_next;
1406 INCR(tid->seq_next, IEEE80211_SEQ_MAX);
Sujith528f0c62008-10-29 10:14:26 +05301407}
1408
1409static int setup_tx_flags(struct ath_softc *sc, struct sk_buff *skb,
1410 struct ath_txq *txq)
1411{
1412 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1413 int flags = 0;
1414
1415 flags |= ATH9K_TXDESC_CLRDMASK; /* needed for crypto errors */
1416 flags |= ATH9K_TXDESC_INTREQ;
1417
1418 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
1419 flags |= ATH9K_TXDESC_NOACK;
Sujith528f0c62008-10-29 10:14:26 +05301420
1421 return flags;
1422}
1423
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001424/*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001425 * rix - rate index
1426 * pktlen - total bytes (delims + data + fcs + pads + pad delims)
1427 * width - 0 for 20 MHz, 1 for 40 MHz
1428 * half_gi - to use 4us v/s 3.6 us for symbol time
1429 */
Sujith102e0572008-10-29 10:15:16 +05301430static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, struct ath_buf *bf,
1431 int width, int half_gi, bool shortPreamble)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001432{
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -04001433 const struct ath_rate_table *rate_table = sc->cur_rate_table;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001434 u32 nbits, nsymbits, duration, nsymbols;
1435 u8 rc;
1436 int streams, pktlen;
1437
Sujithcd3d39a2008-08-11 14:03:34 +05301438 pktlen = bf_isaggr(bf) ? bf->bf_al : bf->bf_frmlen;
Sujithe63835b2008-11-18 09:07:53 +05301439 rc = rate_table->info[rix].ratecode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001440
Sujithe63835b2008-11-18 09:07:53 +05301441 /* for legacy rates, use old function to compute packet duration */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001442 if (!IS_HT_RATE(rc))
Sujithe63835b2008-11-18 09:07:53 +05301443 return ath9k_hw_computetxtime(sc->sc_ah, rate_table, pktlen,
1444 rix, shortPreamble);
1445
1446 /* find number of symbols: PLCP + data */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001447 nbits = (pktlen << 3) + OFDM_PLCP_BITS;
1448 nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
1449 nsymbols = (nbits + nsymbits - 1) / nsymbits;
1450
1451 if (!half_gi)
1452 duration = SYMBOL_TIME(nsymbols);
1453 else
1454 duration = SYMBOL_TIME_HALFGI(nsymbols);
1455
Sujithe63835b2008-11-18 09:07:53 +05301456 /* addup duration for legacy/ht training and signal fields */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001457 streams = HT_RC_2_STREAMS(rc);
1458 duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
Sujith102e0572008-10-29 10:15:16 +05301459
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001460 return duration;
1461}
1462
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001463static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
1464{
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001465 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -04001466 const struct ath_rate_table *rt = sc->cur_rate_table;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001467 struct ath9k_11n_rate_series series[4];
Sujith528f0c62008-10-29 10:14:26 +05301468 struct sk_buff *skb;
1469 struct ieee80211_tx_info *tx_info;
Sujitha8efee42008-11-18 09:07:30 +05301470 struct ieee80211_tx_rate *rates;
Sujith254ad0f2009-02-04 08:10:19 +05301471 struct ieee80211_hdr *hdr;
Sujithc89424d2009-01-30 14:29:28 +05301472 int i, flags = 0;
1473 u8 rix = 0, ctsrate = 0;
Sujith254ad0f2009-02-04 08:10:19 +05301474 bool is_pspoll;
Sujithe63835b2008-11-18 09:07:53 +05301475
1476 memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4);
Sujith528f0c62008-10-29 10:14:26 +05301477
Sujitha22be222009-03-30 15:28:36 +05301478 skb = bf->bf_mpdu;
Sujith528f0c62008-10-29 10:14:26 +05301479 tx_info = IEEE80211_SKB_CB(skb);
Sujithe63835b2008-11-18 09:07:53 +05301480 rates = tx_info->control.rates;
Sujith254ad0f2009-02-04 08:10:19 +05301481 hdr = (struct ieee80211_hdr *)skb->data;
1482 is_pspoll = ieee80211_is_pspoll(hdr->frame_control);
Sujith528f0c62008-10-29 10:14:26 +05301483
Sujithc89424d2009-01-30 14:29:28 +05301484 /*
1485 * We check if Short Preamble is needed for the CTS rate by
1486 * checking the BSS's global flag.
1487 * But for the rate series, IEEE80211_TX_RC_USE_SHORT_PREAMBLE is used.
1488 */
1489 if (sc->sc_flags & SC_OP_PREAMBLE_SHORT)
1490 ctsrate = rt->info[tx_info->control.rts_cts_rate_idx].ratecode |
1491 rt->info[tx_info->control.rts_cts_rate_idx].short_preamble;
1492 else
1493 ctsrate = rt->info[tx_info->control.rts_cts_rate_idx].ratecode;
Luis R. Rodriguez96742252008-12-23 15:58:38 -08001494
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001495 /*
Sujithc89424d2009-01-30 14:29:28 +05301496 * ATH9K_TXDESC_RTSENA and ATH9K_TXDESC_CTSENA are mutually exclusive.
1497 * Check the first rate in the series to decide whether RTS/CTS
1498 * or CTS-to-self has to be used.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001499 */
Sujithc89424d2009-01-30 14:29:28 +05301500 if (rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
1501 flags = ATH9K_TXDESC_CTSENA;
1502 else if (rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
1503 flags = ATH9K_TXDESC_RTSENA;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001504
Sujithc89424d2009-01-30 14:29:28 +05301505 /* FIXME: Handle aggregation protection */
Sujith17d79042009-02-09 13:27:03 +05301506 if (sc->config.ath_aggr_prot &&
Sujithcd3d39a2008-08-11 14:03:34 +05301507 (!bf_isaggr(bf) || (bf_isaggr(bf) && bf->bf_al < 8192))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001508 flags = ATH9K_TXDESC_RTSENA;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001509 }
1510
Sujithe63835b2008-11-18 09:07:53 +05301511 /* For AR5416 - RTS cannot be followed by a frame larger than 8K */
Sujith2660b812009-02-09 13:27:26 +05301512 if (bf_isaggr(bf) && (bf->bf_al > sc->sc_ah->caps.rts_aggr_limit))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001513 flags &= ~(ATH9K_TXDESC_RTSENA);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001514
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001515 for (i = 0; i < 4; i++) {
Sujithe63835b2008-11-18 09:07:53 +05301516 if (!rates[i].count || (rates[i].idx < 0))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001517 continue;
1518
Sujitha8efee42008-11-18 09:07:30 +05301519 rix = rates[i].idx;
Sujitha8efee42008-11-18 09:07:30 +05301520 series[i].Tries = rates[i].count;
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001521 series[i].ChSel = common->tx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001522
Sujithc89424d2009-01-30 14:29:28 +05301523 if (rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
1524 series[i].Rate = rt->info[rix].ratecode |
1525 rt->info[rix].short_preamble;
1526 else
1527 series[i].Rate = rt->info[rix].ratecode;
1528
1529 if (rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS)
1530 series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
1531 if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
1532 series[i].RateFlags |= ATH9K_RATESERIES_2040;
1533 if (rates[i].flags & IEEE80211_TX_RC_SHORT_GI)
1534 series[i].RateFlags |= ATH9K_RATESERIES_HALFGI;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001535
Sujith102e0572008-10-29 10:15:16 +05301536 series[i].PktDuration = ath_pkt_duration(sc, rix, bf,
Sujitha8efee42008-11-18 09:07:30 +05301537 (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) != 0,
1538 (rates[i].flags & IEEE80211_TX_RC_SHORT_GI),
Sujithc89424d2009-01-30 14:29:28 +05301539 (rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001540 }
1541
Sujithe63835b2008-11-18 09:07:53 +05301542 /* set dur_update_en for l-sig computation except for PS-Poll frames */
Sujithc89424d2009-01-30 14:29:28 +05301543 ath9k_hw_set11n_ratescenario(sc->sc_ah, bf->bf_desc,
1544 bf->bf_lastbf->bf_desc,
Sujith254ad0f2009-02-04 08:10:19 +05301545 !is_pspoll, ctsrate,
Sujithc89424d2009-01-30 14:29:28 +05301546 0, series, 4, flags);
Sujith102e0572008-10-29 10:15:16 +05301547
Sujith17d79042009-02-09 13:27:03 +05301548 if (sc->config.ath_aggr_prot && flags)
Sujithc89424d2009-01-30 14:29:28 +05301549 ath9k_hw_set11n_burstduration(sc->sc_ah, bf->bf_desc, 8192);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001550}
1551
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001552static int ath_tx_setup_buffer(struct ieee80211_hw *hw, struct ath_buf *bf,
Sujithe8324352009-01-16 21:38:42 +05301553 struct sk_buff *skb,
1554 struct ath_tx_control *txctl)
1555{
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001556 struct ath_wiphy *aphy = hw->priv;
1557 struct ath_softc *sc = aphy->sc;
Sujithe8324352009-01-16 21:38:42 +05301558 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1559 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Sujithe8324352009-01-16 21:38:42 +05301560 int hdrlen;
1561 __le16 fc;
1562
Felix Fietkau827e69b2009-11-15 23:09:25 +01001563 tx_info->pad[0] = 0;
1564 switch (txctl->frame_type) {
1565 case ATH9K_NOT_INTERNAL:
1566 break;
1567 case ATH9K_INT_PAUSE:
1568 tx_info->pad[0] |= ATH_TX_INFO_FRAME_TYPE_PAUSE;
1569 /* fall through */
1570 case ATH9K_INT_UNPAUSE:
1571 tx_info->pad[0] |= ATH_TX_INFO_FRAME_TYPE_INTERNAL;
1572 break;
1573 }
Sujithe8324352009-01-16 21:38:42 +05301574 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1575 fc = hdr->frame_control;
1576
1577 ATH_TXBUF_RESET(bf);
1578
Felix Fietkau827e69b2009-11-15 23:09:25 +01001579 bf->aphy = aphy;
Sujithe8324352009-01-16 21:38:42 +05301580 bf->bf_frmlen = skb->len + FCS_LEN - (hdrlen & 3);
1581
Luis R. Rodriguez5008f372009-11-02 16:27:33 -08001582 if (conf_is_ht(&hw->conf) && !is_pae(skb))
Sujithc656bbb2009-01-16 21:38:56 +05301583 bf->bf_state.bf_type |= BUF_HT;
Sujithe8324352009-01-16 21:38:42 +05301584
1585 bf->bf_flags = setup_tx_flags(sc, skb, txctl->txq);
1586
1587 bf->bf_keytype = get_hw_crypto_keytype(skb);
Sujithe8324352009-01-16 21:38:42 +05301588 if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR) {
1589 bf->bf_frmlen += tx_info->control.hw_key->icv_len;
1590 bf->bf_keyix = tx_info->control.hw_key->hw_key_idx;
1591 } else {
1592 bf->bf_keyix = ATH9K_TXKEYIX_INVALID;
1593 }
1594
1595 if (ieee80211_is_data_qos(fc) && (sc->sc_flags & SC_OP_TXAGGR))
1596 assign_aggr_tid_seqno(skb, bf);
1597
1598 bf->bf_mpdu = skb;
1599
1600 bf->bf_dmacontext = dma_map_single(sc->dev, skb->data,
1601 skb->len, DMA_TO_DEVICE);
1602 if (unlikely(dma_mapping_error(sc->dev, bf->bf_dmacontext))) {
1603 bf->bf_mpdu = NULL;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001604 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
1605 "dma_mapping_error() on TX\n");
Sujithe8324352009-01-16 21:38:42 +05301606 return -ENOMEM;
1607 }
1608
1609 bf->bf_buf_addr = bf->bf_dmacontext;
1610 return 0;
1611}
1612
1613/* FIXME: tx power */
1614static void ath_tx_start_dma(struct ath_softc *sc, struct ath_buf *bf,
1615 struct ath_tx_control *txctl)
1616{
Sujitha22be222009-03-30 15:28:36 +05301617 struct sk_buff *skb = bf->bf_mpdu;
Sujithe8324352009-01-16 21:38:42 +05301618 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Sujithc37452b2009-03-09 09:31:57 +05301619 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Sujithe8324352009-01-16 21:38:42 +05301620 struct ath_node *an = NULL;
1621 struct list_head bf_head;
1622 struct ath_desc *ds;
1623 struct ath_atx_tid *tid;
Sujithcbe61d82009-02-09 13:27:12 +05301624 struct ath_hw *ah = sc->sc_ah;
Sujithe8324352009-01-16 21:38:42 +05301625 int frm_type;
Sujithc37452b2009-03-09 09:31:57 +05301626 __le16 fc;
Sujithe8324352009-01-16 21:38:42 +05301627
1628 frm_type = get_hw_packet_type(skb);
Sujithc37452b2009-03-09 09:31:57 +05301629 fc = hdr->frame_control;
Sujithe8324352009-01-16 21:38:42 +05301630
1631 INIT_LIST_HEAD(&bf_head);
1632 list_add_tail(&bf->list, &bf_head);
1633
1634 ds = bf->bf_desc;
1635 ds->ds_link = 0;
1636 ds->ds_data = bf->bf_buf_addr;
1637
1638 ath9k_hw_set11n_txdesc(ah, ds, bf->bf_frmlen, frm_type, MAX_RATE_POWER,
1639 bf->bf_keyix, bf->bf_keytype, bf->bf_flags);
1640
1641 ath9k_hw_filltxdesc(ah, ds,
1642 skb->len, /* segment length */
1643 true, /* first segment */
1644 true, /* last segment */
1645 ds); /* first descriptor */
1646
Sujithe8324352009-01-16 21:38:42 +05301647 spin_lock_bh(&txctl->txq->axq_lock);
1648
1649 if (bf_isht(bf) && (sc->sc_flags & SC_OP_TXAGGR) &&
1650 tx_info->control.sta) {
1651 an = (struct ath_node *)tx_info->control.sta->drv_priv;
1652 tid = ATH_AN_2_TID(an, bf->bf_tidno);
1653
Sujithc37452b2009-03-09 09:31:57 +05301654 if (!ieee80211_is_data_qos(fc)) {
1655 ath_tx_send_normal(sc, txctl->txq, &bf_head);
1656 goto tx_done;
1657 }
1658
Vasanthakumar Thiagarajan089e6982009-06-10 17:50:07 +05301659 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
Sujithe8324352009-01-16 21:38:42 +05301660 /*
1661 * Try aggregation if it's a unicast data frame
1662 * and the destination is HT capable.
1663 */
1664 ath_tx_send_ampdu(sc, tid, &bf_head, txctl);
1665 } else {
1666 /*
1667 * Send this frame as regular when ADDBA
1668 * exchange is neither complete nor pending.
1669 */
Sujithc37452b2009-03-09 09:31:57 +05301670 ath_tx_send_ht_normal(sc, txctl->txq,
1671 tid, &bf_head);
Sujithe8324352009-01-16 21:38:42 +05301672 }
1673 } else {
Sujithc37452b2009-03-09 09:31:57 +05301674 ath_tx_send_normal(sc, txctl->txq, &bf_head);
Sujithe8324352009-01-16 21:38:42 +05301675 }
1676
Sujithc37452b2009-03-09 09:31:57 +05301677tx_done:
Sujithe8324352009-01-16 21:38:42 +05301678 spin_unlock_bh(&txctl->txq->axq_lock);
1679}
1680
1681/* Upon failure caller should free skb */
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001682int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
Sujithe8324352009-01-16 21:38:42 +05301683 struct ath_tx_control *txctl)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001684{
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001685 struct ath_wiphy *aphy = hw->priv;
1686 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001687 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001688 struct ath_buf *bf;
Sujithe8324352009-01-16 21:38:42 +05301689 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001690
Sujithe8324352009-01-16 21:38:42 +05301691 bf = ath_tx_get_buffer(sc);
1692 if (!bf) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001693 ath_print(common, ATH_DBG_XMIT, "TX buffers are full\n");
Sujithe8324352009-01-16 21:38:42 +05301694 return -1;
1695 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001696
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001697 r = ath_tx_setup_buffer(hw, bf, skb, txctl);
Sujithe8324352009-01-16 21:38:42 +05301698 if (unlikely(r)) {
1699 struct ath_txq *txq = txctl->txq;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001700
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001701 ath_print(common, ATH_DBG_FATAL, "TX mem alloc failure\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001702
Sujithe8324352009-01-16 21:38:42 +05301703 /* upon ath_tx_processq() this TX queue will be resumed, we
1704 * guarantee this will happen by knowing beforehand that
1705 * we will at least have to run TX completionon one buffer
1706 * on the queue */
1707 spin_lock_bh(&txq->axq_lock);
Sujithf7a99e42009-02-17 15:36:33 +05301708 if (sc->tx.txq[txq->axq_qnum].axq_depth > 1) {
Luis R. Rodriguezf52de032009-11-02 17:09:12 -08001709 ath_mac80211_stop_queue(sc, skb_get_queue_mapping(skb));
Sujithe8324352009-01-16 21:38:42 +05301710 txq->stopped = 1;
1711 }
1712 spin_unlock_bh(&txq->axq_lock);
1713
1714 spin_lock_bh(&sc->tx.txbuflock);
1715 list_add_tail(&bf->list, &sc->tx.txbuf);
1716 spin_unlock_bh(&sc->tx.txbuflock);
1717
1718 return r;
1719 }
1720
1721 ath_tx_start_dma(sc, bf, txctl);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001722
1723 return 0;
1724}
1725
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001726void ath_tx_cabq(struct ieee80211_hw *hw, struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001727{
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001728 struct ath_wiphy *aphy = hw->priv;
1729 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001730 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithe8324352009-01-16 21:38:42 +05301731 int hdrlen, padsize;
1732 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1733 struct ath_tx_control txctl;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001734
Sujithe8324352009-01-16 21:38:42 +05301735 memset(&txctl, 0, sizeof(struct ath_tx_control));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001736
Sujithe8324352009-01-16 21:38:42 +05301737 /*
1738 * As a temporary workaround, assign seq# here; this will likely need
1739 * to be cleaned up to work better with Beacon transmission and virtual
1740 * BSSes.
1741 */
1742 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1743 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1744 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
1745 sc->tx.seq_no += 0x10;
1746 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1747 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001748 }
1749
Sujithe8324352009-01-16 21:38:42 +05301750 /* Add the padding after the header if this is not already done */
1751 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1752 if (hdrlen & 3) {
1753 padsize = hdrlen % 4;
1754 if (skb_headroom(skb) < padsize) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001755 ath_print(common, ATH_DBG_XMIT,
1756 "TX CABQ padding failed\n");
Sujithe8324352009-01-16 21:38:42 +05301757 dev_kfree_skb_any(skb);
1758 return;
1759 }
1760 skb_push(skb, padsize);
1761 memmove(skb->data, skb->data + padsize, hdrlen);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001762 }
1763
Sujithe8324352009-01-16 21:38:42 +05301764 txctl.txq = sc->beacon.cabq;
1765
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001766 ath_print(common, ATH_DBG_XMIT,
1767 "transmitting CABQ packet, skb: %p\n", skb);
Sujithe8324352009-01-16 21:38:42 +05301768
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001769 if (ath_tx_start(hw, skb, &txctl) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001770 ath_print(common, ATH_DBG_XMIT, "CABQ TX failed\n");
Sujithe8324352009-01-16 21:38:42 +05301771 goto exit;
1772 }
1773
1774 return;
1775exit:
1776 dev_kfree_skb_any(skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001777}
1778
Sujithe8324352009-01-16 21:38:42 +05301779/*****************/
1780/* TX Completion */
1781/*****************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001782
Sujithe8324352009-01-16 21:38:42 +05301783static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
Felix Fietkau827e69b2009-11-15 23:09:25 +01001784 struct ath_wiphy *aphy, int tx_flags)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001785{
Sujithe8324352009-01-16 21:38:42 +05301786 struct ieee80211_hw *hw = sc->hw;
1787 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001788 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithe8324352009-01-16 21:38:42 +05301789 int hdrlen, padsize;
1790
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001791 ath_print(common, ATH_DBG_XMIT, "TX complete: skb: %p\n", skb);
Sujithe8324352009-01-16 21:38:42 +05301792
Felix Fietkau827e69b2009-11-15 23:09:25 +01001793 if (aphy)
1794 hw = aphy->hw;
Sujithe8324352009-01-16 21:38:42 +05301795
Vasanthakumar Thiagarajan6b2c4032009-03-20 15:27:50 +05301796 if (tx_flags & ATH_TX_BAR)
Sujithe8324352009-01-16 21:38:42 +05301797 tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
Sujithe8324352009-01-16 21:38:42 +05301798
Vasanthakumar Thiagarajan6b2c4032009-03-20 15:27:50 +05301799 if (!(tx_flags & (ATH_TX_ERROR | ATH_TX_XRETRY))) {
Sujithe8324352009-01-16 21:38:42 +05301800 /* Frame was ACKed */
1801 tx_info->flags |= IEEE80211_TX_STAT_ACK;
1802 }
1803
Sujithe8324352009-01-16 21:38:42 +05301804 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1805 padsize = hdrlen & 3;
1806 if (padsize && hdrlen >= 24) {
1807 /*
1808 * Remove MAC header padding before giving the frame back to
1809 * mac80211.
1810 */
1811 memmove(skb->data + padsize, skb->data, hdrlen);
1812 skb_pull(skb, padsize);
1813 }
1814
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001815 if (sc->sc_flags & SC_OP_WAIT_FOR_TX_ACK) {
1816 sc->sc_flags &= ~SC_OP_WAIT_FOR_TX_ACK;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001817 ath_print(common, ATH_DBG_PS,
1818 "Going back to sleep after having "
1819 "received TX status (0x%x)\n",
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001820 sc->sc_flags & (SC_OP_WAIT_FOR_BEACON |
1821 SC_OP_WAIT_FOR_CAB |
1822 SC_OP_WAIT_FOR_PSPOLL_DATA |
1823 SC_OP_WAIT_FOR_TX_ACK));
1824 }
1825
Felix Fietkau827e69b2009-11-15 23:09:25 +01001826 if (unlikely(tx_info->pad[0] & ATH_TX_INFO_FRAME_TYPE_INTERNAL))
Jouni Malinenf0ed85c2009-03-03 19:23:31 +02001827 ath9k_tx_status(hw, skb);
Felix Fietkau827e69b2009-11-15 23:09:25 +01001828 else
1829 ieee80211_tx_status(hw, skb);
Sujithe8324352009-01-16 21:38:42 +05301830}
1831
1832static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
Sujithfec247c2009-07-27 12:08:16 +05301833 struct ath_txq *txq,
Sujithe8324352009-01-16 21:38:42 +05301834 struct list_head *bf_q,
1835 int txok, int sendbar)
1836{
1837 struct sk_buff *skb = bf->bf_mpdu;
Sujithe8324352009-01-16 21:38:42 +05301838 unsigned long flags;
Vasanthakumar Thiagarajan6b2c4032009-03-20 15:27:50 +05301839 int tx_flags = 0;
Sujithe8324352009-01-16 21:38:42 +05301840
Sujithe8324352009-01-16 21:38:42 +05301841 if (sendbar)
Vasanthakumar Thiagarajan6b2c4032009-03-20 15:27:50 +05301842 tx_flags = ATH_TX_BAR;
Sujithe8324352009-01-16 21:38:42 +05301843
1844 if (!txok) {
Vasanthakumar Thiagarajan6b2c4032009-03-20 15:27:50 +05301845 tx_flags |= ATH_TX_ERROR;
Sujithe8324352009-01-16 21:38:42 +05301846
1847 if (bf_isxretried(bf))
Vasanthakumar Thiagarajan6b2c4032009-03-20 15:27:50 +05301848 tx_flags |= ATH_TX_XRETRY;
Sujithe8324352009-01-16 21:38:42 +05301849 }
1850
1851 dma_unmap_single(sc->dev, bf->bf_dmacontext, skb->len, DMA_TO_DEVICE);
Felix Fietkau827e69b2009-11-15 23:09:25 +01001852 ath_tx_complete(sc, skb, bf->aphy, tx_flags);
Sujithfec247c2009-07-27 12:08:16 +05301853 ath_debug_stat_tx(sc, txq, bf);
Sujithe8324352009-01-16 21:38:42 +05301854
1855 /*
1856 * Return the list of ath_buf of this mpdu to free queue
1857 */
1858 spin_lock_irqsave(&sc->tx.txbuflock, flags);
1859 list_splice_tail_init(bf_q, &sc->tx.txbuf);
1860 spin_unlock_irqrestore(&sc->tx.txbuflock, flags);
1861}
1862
1863static int ath_tx_num_badfrms(struct ath_softc *sc, struct ath_buf *bf,
1864 int txok)
1865{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001866 struct ath_buf *bf_last = bf->bf_lastbf;
1867 struct ath_desc *ds = bf_last->bf_desc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001868 u16 seq_st = 0;
1869 u32 ba[WME_BA_BMP_SIZE >> 5];
Sujithe8324352009-01-16 21:38:42 +05301870 int ba_index;
1871 int nbad = 0;
1872 int isaggr = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001873
Sujithe8324352009-01-16 21:38:42 +05301874 if (ds->ds_txstat.ts_flags == ATH9K_TX_SW_ABORTED)
1875 return 0;
Sujith528f0c62008-10-29 10:14:26 +05301876
Sujithcd3d39a2008-08-11 14:03:34 +05301877 isaggr = bf_isaggr(bf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001878 if (isaggr) {
Sujithe8324352009-01-16 21:38:42 +05301879 seq_st = ATH_DS_BA_SEQ(ds);
1880 memcpy(ba, ATH_DS_BA_BITMAP(ds), WME_BA_BMP_SIZE >> 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001881 }
1882
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001883 while (bf) {
Sujithe8324352009-01-16 21:38:42 +05301884 ba_index = ATH_BA_INDEX(seq_st, bf->bf_seqno);
1885 if (!txok || (isaggr && !ATH_BA_ISSET(ba, ba_index)))
1886 nbad++;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001887
Sujithe8324352009-01-16 21:38:42 +05301888 bf = bf->bf_next;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001889 }
1890
Sujithe8324352009-01-16 21:38:42 +05301891 return nbad;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001892}
1893
Sujith95e4acb2009-03-13 08:56:09 +05301894static void ath_tx_rc_status(struct ath_buf *bf, struct ath_desc *ds,
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05301895 int nbad, int txok, bool update_rc)
Sujithc4288392008-11-18 09:09:30 +05301896{
Sujitha22be222009-03-30 15:28:36 +05301897 struct sk_buff *skb = bf->bf_mpdu;
Sujith254ad0f2009-02-04 08:10:19 +05301898 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Sujithc4288392008-11-18 09:09:30 +05301899 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau827e69b2009-11-15 23:09:25 +01001900 struct ieee80211_hw *hw = bf->aphy->hw;
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05301901 u8 i, tx_rateindex;
Sujithc4288392008-11-18 09:09:30 +05301902
Sujith95e4acb2009-03-13 08:56:09 +05301903 if (txok)
1904 tx_info->status.ack_signal = ds->ds_txstat.ts_rssi;
1905
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05301906 tx_rateindex = ds->ds_txstat.ts_rateindex;
1907 WARN_ON(tx_rateindex >= hw->max_rates);
1908
Felix Fietkau827e69b2009-11-15 23:09:25 +01001909 if (update_rc)
1910 tx_info->pad[0] |= ATH_TX_INFO_UPDATE_RC;
Sujithc4288392008-11-18 09:09:30 +05301911 if (ds->ds_txstat.ts_status & ATH9K_TXERR_FILT)
1912 tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
1913
1914 if ((ds->ds_txstat.ts_status & ATH9K_TXERR_FILT) == 0 &&
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05301915 (bf->bf_flags & ATH9K_TXDESC_NOACK) == 0 && update_rc) {
Sujith254ad0f2009-02-04 08:10:19 +05301916 if (ieee80211_is_data(hdr->frame_control)) {
Felix Fietkau827e69b2009-11-15 23:09:25 +01001917 if (ds->ds_txstat.ts_flags &
1918 (ATH9K_TX_DATA_UNDERRUN | ATH9K_TX_DELIM_UNDERRUN))
1919 tx_info->pad[0] |= ATH_TX_INFO_UNDERRUN;
1920 if ((ds->ds_txstat.ts_status & ATH9K_TXERR_XRETRY) ||
1921 (ds->ds_txstat.ts_status & ATH9K_TXERR_FIFO))
1922 tx_info->pad[0] |= ATH_TX_INFO_XRETRY;
1923 tx_info->status.ampdu_len = bf->bf_nframes;
1924 tx_info->status.ampdu_ack_len = bf->bf_nframes - nbad;
Sujithc4288392008-11-18 09:09:30 +05301925 }
1926 }
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05301927
1928 for (i = tx_rateindex + 1; i < hw->max_rates; i++)
1929 tx_info->status.rates[i].count = 0;
1930
1931 tx_info->status.rates[tx_rateindex].count = bf->bf_retries + 1;
Sujithc4288392008-11-18 09:09:30 +05301932}
1933
Sujith059d8062009-01-16 21:38:49 +05301934static void ath_wake_mac80211_queue(struct ath_softc *sc, struct ath_txq *txq)
1935{
1936 int qnum;
1937
1938 spin_lock_bh(&txq->axq_lock);
1939 if (txq->stopped &&
Sujithf7a99e42009-02-17 15:36:33 +05301940 sc->tx.txq[txq->axq_qnum].axq_depth <= (ATH_TXBUF - 20)) {
Sujith059d8062009-01-16 21:38:49 +05301941 qnum = ath_get_mac80211_qnum(txq->axq_qnum, sc);
1942 if (qnum != -1) {
Luis R. Rodriguezf52de032009-11-02 17:09:12 -08001943 ath_mac80211_start_queue(sc, qnum);
Sujith059d8062009-01-16 21:38:49 +05301944 txq->stopped = 0;
1945 }
1946 }
1947 spin_unlock_bh(&txq->axq_lock);
1948}
1949
Sujithc4288392008-11-18 09:09:30 +05301950static void ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001951{
Sujithcbe61d82009-02-09 13:27:12 +05301952 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001953 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001954 struct ath_buf *bf, *lastbf, *bf_held = NULL;
1955 struct list_head bf_head;
Sujithc4288392008-11-18 09:09:30 +05301956 struct ath_desc *ds;
Vasanthakumar Thiagarajan0934af22009-03-18 20:22:00 +05301957 int txok;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001958 int status;
1959
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001960 ath_print(common, ATH_DBG_QUEUE, "tx queue %d (%x), link %p\n",
1961 txq->axq_qnum, ath9k_hw_gettxbuf(sc->sc_ah, txq->axq_qnum),
1962 txq->axq_link);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001963
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001964 for (;;) {
1965 spin_lock_bh(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001966 if (list_empty(&txq->axq_q)) {
1967 txq->axq_link = NULL;
1968 txq->axq_linkbuf = NULL;
1969 spin_unlock_bh(&txq->axq_lock);
1970 break;
1971 }
1972 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
1973
1974 /*
1975 * There is a race condition that a BH gets scheduled
1976 * after sw writes TxE and before hw re-load the last
1977 * descriptor to get the newly chained one.
1978 * Software must keep the last DONE descriptor as a
1979 * holding descriptor - software does so by marking
1980 * it with the STALE flag.
1981 */
1982 bf_held = NULL;
Sujitha119cc42009-03-30 15:28:38 +05301983 if (bf->bf_stale) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001984 bf_held = bf;
1985 if (list_is_last(&bf_held->list, &txq->axq_q)) {
Sujith6ef9b132009-01-16 21:38:51 +05301986 spin_unlock_bh(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001987 break;
1988 } else {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001989 bf = list_entry(bf_held->list.next,
Sujith6ef9b132009-01-16 21:38:51 +05301990 struct ath_buf, list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001991 }
1992 }
1993
1994 lastbf = bf->bf_lastbf;
Sujithe8324352009-01-16 21:38:42 +05301995 ds = lastbf->bf_desc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001996
1997 status = ath9k_hw_txprocdesc(ah, ds);
1998 if (status == -EINPROGRESS) {
1999 spin_unlock_bh(&txq->axq_lock);
2000 break;
2001 }
2002 if (bf->bf_desc == txq->axq_lastdsWithCTS)
2003 txq->axq_lastdsWithCTS = NULL;
2004 if (ds == txq->axq_gatingds)
2005 txq->axq_gatingds = NULL;
2006
2007 /*
2008 * Remove ath_buf's of the same transmit unit from txq,
2009 * however leave the last descriptor back as the holding
2010 * descriptor for hw.
2011 */
Sujitha119cc42009-03-30 15:28:38 +05302012 lastbf->bf_stale = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002013 INIT_LIST_HEAD(&bf_head);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002014 if (!list_is_singular(&lastbf->list))
2015 list_cut_position(&bf_head,
2016 &txq->axq_q, lastbf->list.prev);
2017
2018 txq->axq_depth--;
Sujithcd3d39a2008-08-11 14:03:34 +05302019 if (bf_isaggr(bf))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002020 txq->axq_aggr_depth--;
2021
2022 txok = (ds->ds_txstat.ts_status == 0);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04002023 txq->axq_tx_inprogress = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002024 spin_unlock_bh(&txq->axq_lock);
2025
2026 if (bf_held) {
Sujithb77f4832008-12-07 21:44:03 +05302027 spin_lock_bh(&sc->tx.txbuflock);
Sujith6ef9b132009-01-16 21:38:51 +05302028 list_move_tail(&bf_held->list, &sc->tx.txbuf);
Sujithb77f4832008-12-07 21:44:03 +05302029 spin_unlock_bh(&sc->tx.txbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002030 }
2031
Sujithcd3d39a2008-08-11 14:03:34 +05302032 if (!bf_isampdu(bf)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002033 /*
2034 * This frame is sent out as a single frame.
2035 * Use hardware retry status for this frame.
2036 */
2037 bf->bf_retries = ds->ds_txstat.ts_longretry;
2038 if (ds->ds_txstat.ts_status & ATH9K_TXERR_XRETRY)
Sujithcd3d39a2008-08-11 14:03:34 +05302039 bf->bf_state.bf_type |= BUF_XRETRY;
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05302040 ath_tx_rc_status(bf, ds, 0, txok, true);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002041 }
Johannes Berge6a98542008-10-21 12:40:02 +02002042
Sujithcd3d39a2008-08-11 14:03:34 +05302043 if (bf_isampdu(bf))
Sujithd43f30152009-01-16 21:38:53 +05302044 ath_tx_complete_aggr(sc, txq, bf, &bf_head, txok);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002045 else
Sujithfec247c2009-07-27 12:08:16 +05302046 ath_tx_complete_buf(sc, bf, txq, &bf_head, txok, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002047
Sujith059d8062009-01-16 21:38:49 +05302048 ath_wake_mac80211_queue(sc, txq);
2049
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002050 spin_lock_bh(&txq->axq_lock);
Sujith672840a2008-08-11 14:05:08 +05302051 if (sc->sc_flags & SC_OP_TXAGGR)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002052 ath_txq_schedule(sc, txq);
2053 spin_unlock_bh(&txq->axq_lock);
2054 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002055}
2056
Sujith305fe472009-07-23 15:32:29 +05302057static void ath_tx_complete_poll_work(struct work_struct *work)
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04002058{
2059 struct ath_softc *sc = container_of(work, struct ath_softc,
2060 tx_complete_work.work);
2061 struct ath_txq *txq;
2062 int i;
2063 bool needreset = false;
2064
2065 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
2066 if (ATH_TXQ_SETUP(sc, i)) {
2067 txq = &sc->tx.txq[i];
2068 spin_lock_bh(&txq->axq_lock);
2069 if (txq->axq_depth) {
2070 if (txq->axq_tx_inprogress) {
2071 needreset = true;
2072 spin_unlock_bh(&txq->axq_lock);
2073 break;
2074 } else {
2075 txq->axq_tx_inprogress = true;
2076 }
2077 }
2078 spin_unlock_bh(&txq->axq_lock);
2079 }
2080
2081 if (needreset) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002082 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_RESET,
2083 "tx hung, resetting the chip\n");
Sujith332c5562009-10-09 09:51:28 +05302084 ath9k_ps_wakeup(sc);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04002085 ath_reset(sc, false);
Sujith332c5562009-10-09 09:51:28 +05302086 ath9k_ps_restore(sc);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04002087 }
2088
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002089 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work,
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04002090 msecs_to_jiffies(ATH_TX_COMPLETE_POLL_INT));
2091}
2092
2093
Sujithe8324352009-01-16 21:38:42 +05302094
2095void ath_tx_tasklet(struct ath_softc *sc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002096{
Sujithe8324352009-01-16 21:38:42 +05302097 int i;
2098 u32 qcumask = ((1 << ATH9K_NUM_TX_QUEUES) - 1);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002099
Sujithe8324352009-01-16 21:38:42 +05302100 ath9k_hw_gettxintrtxqs(sc->sc_ah, &qcumask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002101
2102 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
Sujithe8324352009-01-16 21:38:42 +05302103 if (ATH_TXQ_SETUP(sc, i) && (qcumask & (1 << i)))
2104 ath_tx_processq(sc, &sc->tx.txq[i]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002105 }
2106}
2107
Sujithe8324352009-01-16 21:38:42 +05302108/*****************/
2109/* Init, Cleanup */
2110/*****************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002111
2112int ath_tx_init(struct ath_softc *sc, int nbufs)
2113{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002114 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002115 int error = 0;
2116
Sujith797fe5cb2009-03-30 15:28:45 +05302117 spin_lock_init(&sc->tx.txbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002118
Sujith797fe5cb2009-03-30 15:28:45 +05302119 error = ath_descdma_setup(sc, &sc->tx.txdma, &sc->tx.txbuf,
2120 "tx", nbufs, 1);
2121 if (error != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002122 ath_print(common, ATH_DBG_FATAL,
2123 "Failed to allocate tx descriptors: %d\n", error);
Sujith797fe5cb2009-03-30 15:28:45 +05302124 goto err;
2125 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002126
Sujith797fe5cb2009-03-30 15:28:45 +05302127 error = ath_descdma_setup(sc, &sc->beacon.bdma, &sc->beacon.bbuf,
2128 "beacon", ATH_BCBUF, 1);
2129 if (error != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002130 ath_print(common, ATH_DBG_FATAL,
2131 "Failed to allocate beacon descriptors: %d\n", error);
Sujith797fe5cb2009-03-30 15:28:45 +05302132 goto err;
2133 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002134
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04002135 INIT_DELAYED_WORK(&sc->tx_complete_work, ath_tx_complete_poll_work);
2136
Sujith797fe5cb2009-03-30 15:28:45 +05302137err:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002138 if (error != 0)
2139 ath_tx_cleanup(sc);
2140
2141 return error;
2142}
2143
Sujith797fe5cb2009-03-30 15:28:45 +05302144void ath_tx_cleanup(struct ath_softc *sc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002145{
Sujithb77f4832008-12-07 21:44:03 +05302146 if (sc->beacon.bdma.dd_desc_len != 0)
2147 ath_descdma_cleanup(sc, &sc->beacon.bdma, &sc->beacon.bbuf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002148
Sujithb77f4832008-12-07 21:44:03 +05302149 if (sc->tx.txdma.dd_desc_len != 0)
2150 ath_descdma_cleanup(sc, &sc->tx.txdma, &sc->tx.txbuf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002151}
2152
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002153void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an)
2154{
Sujithc5170162008-10-29 10:13:59 +05302155 struct ath_atx_tid *tid;
2156 struct ath_atx_ac *ac;
2157 int tidno, acno;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002158
Sujith8ee5afb2008-12-07 21:43:36 +05302159 for (tidno = 0, tid = &an->tid[tidno];
Sujithc5170162008-10-29 10:13:59 +05302160 tidno < WME_NUM_TID;
2161 tidno++, tid++) {
2162 tid->an = an;
2163 tid->tidno = tidno;
2164 tid->seq_start = tid->seq_next = 0;
2165 tid->baw_size = WME_MAX_BA;
2166 tid->baw_head = tid->baw_tail = 0;
2167 tid->sched = false;
Sujithe8324352009-01-16 21:38:42 +05302168 tid->paused = false;
Sujitha37c2c72008-10-29 10:15:40 +05302169 tid->state &= ~AGGR_CLEANUP;
Sujithc5170162008-10-29 10:13:59 +05302170 INIT_LIST_HEAD(&tid->buf_q);
Sujithc5170162008-10-29 10:13:59 +05302171 acno = TID_TO_WME_AC(tidno);
Sujith8ee5afb2008-12-07 21:43:36 +05302172 tid->ac = &an->ac[acno];
Sujitha37c2c72008-10-29 10:15:40 +05302173 tid->state &= ~AGGR_ADDBA_COMPLETE;
2174 tid->state &= ~AGGR_ADDBA_PROGRESS;
Sujithc5170162008-10-29 10:13:59 +05302175 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002176
Sujith8ee5afb2008-12-07 21:43:36 +05302177 for (acno = 0, ac = &an->ac[acno];
Sujithc5170162008-10-29 10:13:59 +05302178 acno < WME_NUM_AC; acno++, ac++) {
2179 ac->sched = false;
2180 INIT_LIST_HEAD(&ac->tid_q);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002181
Sujithc5170162008-10-29 10:13:59 +05302182 switch (acno) {
2183 case WME_AC_BE:
2184 ac->qnum = ath_tx_get_qnum(sc,
2185 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
2186 break;
2187 case WME_AC_BK:
2188 ac->qnum = ath_tx_get_qnum(sc,
2189 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BK);
2190 break;
2191 case WME_AC_VI:
2192 ac->qnum = ath_tx_get_qnum(sc,
2193 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VI);
2194 break;
2195 case WME_AC_VO:
2196 ac->qnum = ath_tx_get_qnum(sc,
2197 ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VO);
2198 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002199 }
2200 }
2201}
2202
Sujithb5aa9bf2008-10-29 10:13:31 +05302203void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002204{
2205 int i;
2206 struct ath_atx_ac *ac, *ac_tmp;
2207 struct ath_atx_tid *tid, *tid_tmp;
2208 struct ath_txq *txq;
Sujithe8324352009-01-16 21:38:42 +05302209
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002210 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
2211 if (ATH_TXQ_SETUP(sc, i)) {
Sujithb77f4832008-12-07 21:44:03 +05302212 txq = &sc->tx.txq[i];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002213
Sujithb5aa9bf2008-10-29 10:13:31 +05302214 spin_lock(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002215
2216 list_for_each_entry_safe(ac,
2217 ac_tmp, &txq->axq_acq, list) {
2218 tid = list_first_entry(&ac->tid_q,
2219 struct ath_atx_tid, list);
2220 if (tid && tid->an != an)
2221 continue;
2222 list_del(&ac->list);
2223 ac->sched = false;
2224
2225 list_for_each_entry_safe(tid,
2226 tid_tmp, &ac->tid_q, list) {
2227 list_del(&tid->list);
2228 tid->sched = false;
Sujithb5aa9bf2008-10-29 10:13:31 +05302229 ath_tid_drain(sc, txq, tid);
Sujitha37c2c72008-10-29 10:15:40 +05302230 tid->state &= ~AGGR_ADDBA_COMPLETE;
Sujitha37c2c72008-10-29 10:15:40 +05302231 tid->state &= ~AGGR_CLEANUP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002232 }
2233 }
2234
Sujithb5aa9bf2008-10-29 10:13:31 +05302235 spin_unlock(&txq->axq_lock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002236 }
2237 }
2238}