blob: b99ffa035c77a9eabfb835e22fc3eb213bd57ad5 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2008-2011 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
Alexey Dobriyanb7f080c2011-06-16 11:01:34 +000017#include <linux/dma-mapping.h>
Sujith394cf0a2009-02-09 13:26:54 +053018#include "ath9k.h"
Luis R. Rodriguezb622a722010-04-15 17:39:28 -040019#include "ar9003_mac.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070020
21#define BITS_PER_BYTE 8
22#define OFDM_PLCP_BITS 22
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070023#define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1)
24#define L_STF 8
25#define L_LTF 8
26#define L_SIG 4
27#define HT_SIG 8
28#define HT_STF 4
29#define HT_LTF(_ns) (4 * (_ns))
30#define SYMBOL_TIME(_ns) ((_ns) << 2) /* ns * 4 us */
31#define SYMBOL_TIME_HALFGI(_ns) (((_ns) * 18 + 4) / 5) /* ns * 3.6 us */
Felix Fietkauaa5955c2012-07-15 19:53:36 +020032#define TIME_SYMBOLS(t) ((t) >> 2)
33#define TIME_SYMBOLS_HALFGI(t) (((t) * 5 - 4) / 18)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070034#define NUM_SYMBOLS_PER_USEC(_usec) (_usec >> 2)
35#define NUM_SYMBOLS_PER_USEC_HALFGI(_usec) (((_usec*5)-4)/18)
36
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070037
Felix Fietkauc6663872010-04-19 19:57:33 +020038static u16 bits_per_symbol[][2] = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070039 /* 20MHz 40MHz */
40 { 26, 54 }, /* 0: BPSK */
41 { 52, 108 }, /* 1: QPSK 1/2 */
42 { 78, 162 }, /* 2: QPSK 3/4 */
43 { 104, 216 }, /* 3: 16-QAM 1/2 */
44 { 156, 324 }, /* 4: 16-QAM 3/4 */
45 { 208, 432 }, /* 5: 64-QAM 2/3 */
46 { 234, 486 }, /* 6: 64-QAM 3/4 */
47 { 260, 540 }, /* 7: 64-QAM 5/6 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070048};
49
Felix Fietkau82b873a2010-11-11 03:18:37 +010050static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
Felix Fietkau44f1d262011-08-28 00:32:25 +020051 struct ath_atx_tid *tid, struct sk_buff *skb);
52static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
Felix Fietkaud94a4612016-09-02 19:46:12 +030053 int tx_flags, struct ath_txq *txq,
54 struct ieee80211_sta *sta);
Sujithe8324352009-01-16 21:38:42 +053055static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
Felix Fietkaudb1a0522010-03-29 20:07:11 -070056 struct ath_txq *txq, struct list_head *bf_q,
Felix Fietkaud94a4612016-09-02 19:46:12 +030057 struct ieee80211_sta *sta,
Felix Fietkau156369f2011-12-14 22:08:04 +010058 struct ath_tx_status *ts, int txok);
Sujithe8324352009-01-16 21:38:42 +053059static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
Felix Fietkaufce041b2011-05-19 12:20:25 +020060 struct list_head *head, bool internal);
Felix Fietkau0cdd5c62011-01-24 19:23:17 +010061static void ath_tx_rc_status(struct ath_softc *sc, struct ath_buf *bf,
62 struct ath_tx_status *ts, int nframes, int nbad,
Felix Fietkau3afd21e2011-09-14 21:24:26 +020063 int txok);
Felix Fietkau90fa5392010-09-20 13:45:38 +020064static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
65 int seqno);
Felix Fietkau44f1d262011-08-28 00:32:25 +020066static struct ath_buf *ath_tx_setup_buffer(struct ath_softc *sc,
67 struct ath_txq *txq,
68 struct ath_atx_tid *tid,
Felix Fietkau249ee722012-10-03 21:07:52 +020069 struct sk_buff *skb);
Sujithe8324352009-01-16 21:38:42 +053070
Felix Fietkau545750d2009-11-23 22:21:01 +010071enum {
Felix Fietkau0e668cd2010-04-19 19:57:32 +020072 MCS_HT20,
73 MCS_HT20_SGI,
Felix Fietkau545750d2009-11-23 22:21:01 +010074 MCS_HT40,
75 MCS_HT40_SGI,
76};
77
Sujithe8324352009-01-16 21:38:42 +053078/*********************/
79/* Aggregation logic */
80/*********************/
81
Felix Fietkaud94a4612016-09-02 19:46:12 +030082static void ath_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
83{
84 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
85 struct ieee80211_sta *sta = info->status.status_driver_data[0];
86
87 if (info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) {
88 ieee80211_tx_status(hw, skb);
89 return;
90 }
91
92 if (sta)
93 ieee80211_tx_status_noskb(hw, sta, info);
94
95 dev_kfree_skb(skb);
96}
97
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +053098void ath_txq_lock(struct ath_softc *sc, struct ath_txq *txq)
Luis R. Rodriguez1512a482011-12-20 10:46:09 -080099 __acquires(&txq->axq_lock)
Felix Fietkau23de5dc2011-12-19 16:45:54 +0100100{
101 spin_lock_bh(&txq->axq_lock);
102}
103
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530104void ath_txq_unlock(struct ath_softc *sc, struct ath_txq *txq)
Luis R. Rodriguez1512a482011-12-20 10:46:09 -0800105 __releases(&txq->axq_lock)
Felix Fietkau23de5dc2011-12-19 16:45:54 +0100106{
107 spin_unlock_bh(&txq->axq_lock);
108}
109
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530110void ath_txq_unlock_complete(struct ath_softc *sc, struct ath_txq *txq)
Luis R. Rodriguez1512a482011-12-20 10:46:09 -0800111 __releases(&txq->axq_lock)
Felix Fietkau23de5dc2011-12-19 16:45:54 +0100112{
Felix Fietkaud94a4612016-09-02 19:46:12 +0300113 struct ieee80211_hw *hw = sc->hw;
Felix Fietkau23de5dc2011-12-19 16:45:54 +0100114 struct sk_buff_head q;
115 struct sk_buff *skb;
116
117 __skb_queue_head_init(&q);
118 skb_queue_splice_init(&txq->complete_q, &q);
119 spin_unlock_bh(&txq->axq_lock);
120
121 while ((skb = __skb_dequeue(&q)))
Felix Fietkaud94a4612016-09-02 19:46:12 +0300122 ath_tx_status(hw, skb);
Felix Fietkau23de5dc2011-12-19 16:45:54 +0100123}
124
Felix Fietkau04535312014-06-11 16:17:51 +0530125static void ath_tx_queue_tid(struct ath_softc *sc, struct ath_txq *txq,
126 struct ath_atx_tid *tid)
Sujithe8324352009-01-16 21:38:42 +0530127{
Felix Fietkau04535312014-06-11 16:17:51 +0530128 struct list_head *list;
129 struct ath_vif *avp = (struct ath_vif *) tid->an->vif->drv_priv;
130 struct ath_chanctx *ctx = avp->chanctx;
131
132 if (!ctx)
133 return;
Sujithe8324352009-01-16 21:38:42 +0530134
Felix Fietkau04535312014-06-11 16:17:51 +0530135 list = &ctx->acq[TID_TO_WME_AC(tid->tidno)];
Felix Fietkaud70d8482015-07-22 13:06:14 +0200136 if (list_empty(&tid->list))
137 list_add_tail(&tid->list, list);
Sujithe8324352009-01-16 21:38:42 +0530138}
139
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100140static struct ath_frame_info *get_frame_info(struct sk_buff *skb)
Felix Fietkau76e45222010-11-14 15:20:08 +0100141{
142 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100143 BUILD_BUG_ON(sizeof(struct ath_frame_info) >
144 sizeof(tx_info->rate_driver_data));
145 return (struct ath_frame_info *) &tx_info->rate_driver_data[0];
Felix Fietkau76e45222010-11-14 15:20:08 +0100146}
147
Felix Fietkau156369f2011-12-14 22:08:04 +0100148static void ath_send_bar(struct ath_atx_tid *tid, u16 seqno)
149{
Felix Fietkauf89d1bc2013-08-06 14:18:13 +0200150 if (!tid->an->sta)
151 return;
152
Felix Fietkau156369f2011-12-14 22:08:04 +0100153 ieee80211_send_bar(tid->an->vif, tid->an->sta->addr, tid->tidno,
154 seqno << IEEE80211_SEQ_SEQ_SHIFT);
155}
156
Felix Fietkau79acac02013-04-22 23:11:44 +0200157static void ath_set_rates(struct ieee80211_vif *vif, struct ieee80211_sta *sta,
158 struct ath_buf *bf)
159{
160 ieee80211_get_tx_rates(vif, sta, bf->bf_mpdu, bf->rates,
161 ARRAY_SIZE(bf->rates));
162}
163
Felix Fietkaua4943cc2013-06-30 12:02:13 +0200164static void ath_txq_skb_done(struct ath_softc *sc, struct ath_txq *txq,
165 struct sk_buff *skb)
166{
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +0530167 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Felix Fietkaud954cd772014-07-16 20:26:05 +0200168 struct ath_frame_info *fi = get_frame_info(skb);
Felix Fietkaud954cd772014-07-16 20:26:05 +0200169 int q = fi->txq;
Felix Fietkaua4943cc2013-06-30 12:02:13 +0200170
Felix Fietkaud954cd772014-07-16 20:26:05 +0200171 if (q < 0)
Felix Fietkaua4943cc2013-06-30 12:02:13 +0200172 return;
173
Felix Fietkaud954cd772014-07-16 20:26:05 +0200174 txq = sc->tx.txq_map[q];
Felix Fietkaua4943cc2013-06-30 12:02:13 +0200175 if (WARN_ON(--txq->pending_frames < 0))
176 txq->pending_frames = 0;
177
178 if (txq->stopped &&
179 txq->pending_frames < sc->tx.txq_max_pending[q]) {
Sujith Manoharan868caae2014-10-21 19:23:02 +0530180 if (ath9k_is_chanctx_enabled())
181 ieee80211_wake_queue(sc->hw, info->hw_queue);
182 else
183 ieee80211_wake_queue(sc->hw, q);
Felix Fietkaua4943cc2013-06-30 12:02:13 +0200184 txq->stopped = false;
185 }
186}
187
Felix Fietkau1803d022013-08-06 14:18:04 +0200188static struct ath_atx_tid *
189ath_get_skb_tid(struct ath_softc *sc, struct ath_node *an, struct sk_buff *skb)
190{
Felix Fietkau39731b72013-12-19 18:01:51 +0100191 u8 tidno = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
Felix Fietkau1803d022013-08-06 14:18:04 +0200192 return ATH_AN_2_TID(an, tidno);
193}
194
Felix Fietkaua7586ee2013-08-06 14:18:02 +0200195static bool ath_tid_has_buffered(struct ath_atx_tid *tid)
196{
Felix Fietkaubb195ff2013-08-06 14:18:03 +0200197 return !skb_queue_empty(&tid->buf_q) || !skb_queue_empty(&tid->retry_q);
Felix Fietkaua7586ee2013-08-06 14:18:02 +0200198}
199
200static struct sk_buff *ath_tid_dequeue(struct ath_atx_tid *tid)
201{
Felix Fietkaubb195ff2013-08-06 14:18:03 +0200202 struct sk_buff *skb;
203
204 skb = __skb_dequeue(&tid->retry_q);
205 if (!skb)
206 skb = __skb_dequeue(&tid->buf_q);
207
208 return skb;
Felix Fietkaua7586ee2013-08-06 14:18:02 +0200209}
210
Felix Fietkau2800e822013-08-06 14:18:11 +0200211/*
212 * ath_tx_tid_change_state:
213 * - clears a-mpdu flag of previous session
214 * - force sequence number allocation to fix next BlockAck Window
215 */
216static void
217ath_tx_tid_change_state(struct ath_softc *sc, struct ath_atx_tid *tid)
218{
Felix Fietkau592fa222015-07-22 13:06:13 +0200219 struct ath_txq *txq = tid->txq;
Felix Fietkau2800e822013-08-06 14:18:11 +0200220 struct ieee80211_tx_info *tx_info;
221 struct sk_buff *skb, *tskb;
222 struct ath_buf *bf;
223 struct ath_frame_info *fi;
224
225 skb_queue_walk_safe(&tid->buf_q, skb, tskb) {
226 fi = get_frame_info(skb);
227 bf = fi->bf;
228
229 tx_info = IEEE80211_SKB_CB(skb);
230 tx_info->flags &= ~IEEE80211_TX_CTL_AMPDU;
231
232 if (bf)
233 continue;
234
235 bf = ath_tx_setup_buffer(sc, txq, tid, skb);
236 if (!bf) {
237 __skb_unlink(skb, &tid->buf_q);
238 ath_txq_skb_done(sc, txq, skb);
239 ieee80211_free_txskb(sc->hw, skb);
240 continue;
241 }
242 }
243
244}
245
Felix Fietkau08c96ab2013-05-18 21:28:15 +0200246static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
Sujithe8324352009-01-16 21:38:42 +0530247{
Felix Fietkau592fa222015-07-22 13:06:13 +0200248 struct ath_txq *txq = tid->txq;
Felix Fietkau56dc6332011-08-28 00:32:22 +0200249 struct sk_buff *skb;
Sujithe8324352009-01-16 21:38:42 +0530250 struct ath_buf *bf;
251 struct list_head bf_head;
Felix Fietkau90fa5392010-09-20 13:45:38 +0200252 struct ath_tx_status ts;
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100253 struct ath_frame_info *fi;
Felix Fietkau156369f2011-12-14 22:08:04 +0100254 bool sendbar = false;
Felix Fietkau90fa5392010-09-20 13:45:38 +0200255
Sujithe8324352009-01-16 21:38:42 +0530256 INIT_LIST_HEAD(&bf_head);
257
Felix Fietkau90fa5392010-09-20 13:45:38 +0200258 memset(&ts, 0, sizeof(ts));
Sujithe8324352009-01-16 21:38:42 +0530259
Felix Fietkau2800e822013-08-06 14:18:11 +0200260 while ((skb = __skb_dequeue(&tid->retry_q))) {
Felix Fietkau56dc6332011-08-28 00:32:22 +0200261 fi = get_frame_info(skb);
262 bf = fi->bf;
Felix Fietkau249ee722012-10-03 21:07:52 +0200263 if (!bf) {
Felix Fietkau2800e822013-08-06 14:18:11 +0200264 ath_txq_skb_done(sc, txq, skb);
265 ieee80211_free_txskb(sc->hw, skb);
266 continue;
Felix Fietkau249ee722012-10-03 21:07:52 +0200267 }
268
Felix Fietkau8fed1402013-08-06 14:18:07 +0200269 if (fi->baw_tracked) {
Felix Fietkau6a0ddae2011-08-28 00:32:23 +0200270 ath_tx_update_baw(sc, tid, bf->bf_state.seqno);
Felix Fietkau156369f2011-12-14 22:08:04 +0100271 sendbar = true;
Felix Fietkau90fa5392010-09-20 13:45:38 +0200272 }
Felix Fietkau2800e822013-08-06 14:18:11 +0200273
274 list_add_tail(&bf->list, &bf_head);
Felix Fietkaud94a4612016-09-02 19:46:12 +0300275 ath_tx_complete_buf(sc, bf, txq, &bf_head, NULL, &ts, 0);
Sujithe8324352009-01-16 21:38:42 +0530276 }
277
Felix Fietkau08c96ab2013-05-18 21:28:15 +0200278 if (sendbar) {
Felix Fietkau23de5dc2011-12-19 16:45:54 +0100279 ath_txq_unlock(sc, txq);
Felix Fietkau156369f2011-12-14 22:08:04 +0100280 ath_send_bar(tid, tid->seq_start);
Felix Fietkau23de5dc2011-12-19 16:45:54 +0100281 ath_txq_lock(sc, txq);
282 }
Sujithe8324352009-01-16 21:38:42 +0530283}
284
285static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
286 int seqno)
287{
288 int index, cindex;
289
290 index = ATH_BA_INDEX(tid->seq_start, seqno);
291 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
292
Felix Fietkau81ee13b2010-09-20 13:45:36 +0200293 __clear_bit(cindex, tid->tx_buf);
Sujithe8324352009-01-16 21:38:42 +0530294
Felix Fietkau81ee13b2010-09-20 13:45:36 +0200295 while (tid->baw_head != tid->baw_tail && !test_bit(tid->baw_head, tid->tx_buf)) {
Sujithe8324352009-01-16 21:38:42 +0530296 INCR(tid->seq_start, IEEE80211_SEQ_MAX);
297 INCR(tid->baw_head, ATH_TID_MAX_BUFS);
Felix Fietkauf9437542011-12-14 22:08:08 +0100298 if (tid->bar_index >= 0)
299 tid->bar_index--;
Sujithe8324352009-01-16 21:38:42 +0530300 }
301}
302
303static void ath_tx_addto_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
Felix Fietkau8fed1402013-08-06 14:18:07 +0200304 struct ath_buf *bf)
Sujithe8324352009-01-16 21:38:42 +0530305{
Felix Fietkau8fed1402013-08-06 14:18:07 +0200306 struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu);
307 u16 seqno = bf->bf_state.seqno;
Sujithe8324352009-01-16 21:38:42 +0530308 int index, cindex;
309
Felix Fietkau2d3bcba2010-11-14 15:20:01 +0100310 index = ATH_BA_INDEX(tid->seq_start, seqno);
Sujithe8324352009-01-16 21:38:42 +0530311 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
Felix Fietkau81ee13b2010-09-20 13:45:36 +0200312 __set_bit(cindex, tid->tx_buf);
Felix Fietkau8fed1402013-08-06 14:18:07 +0200313 fi->baw_tracked = 1;
Sujithe8324352009-01-16 21:38:42 +0530314
315 if (index >= ((tid->baw_tail - tid->baw_head) &
316 (ATH_TID_MAX_BUFS - 1))) {
317 tid->baw_tail = cindex;
318 INCR(tid->baw_tail, ATH_TID_MAX_BUFS);
319 }
320}
321
Sujithe8324352009-01-16 21:38:42 +0530322static void ath_tid_drain(struct ath_softc *sc, struct ath_txq *txq,
323 struct ath_atx_tid *tid)
324
325{
Felix Fietkau56dc6332011-08-28 00:32:22 +0200326 struct sk_buff *skb;
Sujithe8324352009-01-16 21:38:42 +0530327 struct ath_buf *bf;
328 struct list_head bf_head;
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700329 struct ath_tx_status ts;
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100330 struct ath_frame_info *fi;
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700331
332 memset(&ts, 0, sizeof(ts));
Sujithe8324352009-01-16 21:38:42 +0530333 INIT_LIST_HEAD(&bf_head);
334
Felix Fietkaua7586ee2013-08-06 14:18:02 +0200335 while ((skb = ath_tid_dequeue(tid))) {
Felix Fietkau56dc6332011-08-28 00:32:22 +0200336 fi = get_frame_info(skb);
337 bf = fi->bf;
Sujithe8324352009-01-16 21:38:42 +0530338
Felix Fietkau44f1d262011-08-28 00:32:25 +0200339 if (!bf) {
Felix Fietkaud94a4612016-09-02 19:46:12 +0300340 ath_tx_complete(sc, skb, ATH_TX_ERROR, txq, NULL);
Felix Fietkau44f1d262011-08-28 00:32:25 +0200341 continue;
342 }
343
Felix Fietkau56dc6332011-08-28 00:32:22 +0200344 list_add_tail(&bf->list, &bf_head);
Felix Fietkaud94a4612016-09-02 19:46:12 +0300345 ath_tx_complete_buf(sc, bf, txq, &bf_head, NULL, &ts, 0);
Sujithe8324352009-01-16 21:38:42 +0530346 }
Sujithe8324352009-01-16 21:38:42 +0530347}
348
Sujithfec247c2009-07-27 12:08:16 +0530349static void ath_tx_set_retry(struct ath_softc *sc, struct ath_txq *txq,
Felix Fietkauda647622011-12-14 22:08:03 +0100350 struct sk_buff *skb, int count)
Sujithe8324352009-01-16 21:38:42 +0530351{
Felix Fietkau8b7f8532010-11-28 19:37:48 +0100352 struct ath_frame_info *fi = get_frame_info(skb);
Felix Fietkauf11cc942011-09-15 12:59:49 +0200353 struct ath_buf *bf = fi->bf;
Sujithe8324352009-01-16 21:38:42 +0530354 struct ieee80211_hdr *hdr;
Felix Fietkauda647622011-12-14 22:08:03 +0100355 int prev = fi->retries;
Sujithe8324352009-01-16 21:38:42 +0530356
Sujithfec247c2009-07-27 12:08:16 +0530357 TX_STAT_INC(txq->axq_qnum, a_retries);
Felix Fietkauda647622011-12-14 22:08:03 +0100358 fi->retries += count;
359
360 if (prev > 0)
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100361 return;
Sujithe8324352009-01-16 21:38:42 +0530362
Sujithe8324352009-01-16 21:38:42 +0530363 hdr = (struct ieee80211_hdr *)skb->data;
364 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_RETRY);
Felix Fietkauf11cc942011-09-15 12:59:49 +0200365 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
366 sizeof(*hdr), DMA_TO_DEVICE);
Sujithe8324352009-01-16 21:38:42 +0530367}
368
Felix Fietkau0a8cea82010-04-19 19:57:30 +0200369static struct ath_buf *ath_tx_get_buffer(struct ath_softc *sc)
370{
371 struct ath_buf *bf = NULL;
372
373 spin_lock_bh(&sc->tx.txbuflock);
374
375 if (unlikely(list_empty(&sc->tx.txbuf))) {
376 spin_unlock_bh(&sc->tx.txbuflock);
377 return NULL;
378 }
379
380 bf = list_first_entry(&sc->tx.txbuf, struct ath_buf, list);
381 list_del(&bf->list);
382
383 spin_unlock_bh(&sc->tx.txbuflock);
384
385 return bf;
386}
387
388static void ath_tx_return_buffer(struct ath_softc *sc, struct ath_buf *bf)
389{
390 spin_lock_bh(&sc->tx.txbuflock);
391 list_add_tail(&bf->list, &sc->tx.txbuf);
392 spin_unlock_bh(&sc->tx.txbuflock);
393}
394
Sujithd43f30152009-01-16 21:38:53 +0530395static struct ath_buf* ath_clone_txbuf(struct ath_softc *sc, struct ath_buf *bf)
396{
397 struct ath_buf *tbf;
398
Felix Fietkau0a8cea82010-04-19 19:57:30 +0200399 tbf = ath_tx_get_buffer(sc);
400 if (WARN_ON(!tbf))
Vasanthakumar Thiagarajan8a460972009-06-10 17:50:09 +0530401 return NULL;
Sujithd43f30152009-01-16 21:38:53 +0530402
403 ATH_TXBUF_RESET(tbf);
404
405 tbf->bf_mpdu = bf->bf_mpdu;
406 tbf->bf_buf_addr = bf->bf_buf_addr;
Vasanthakumar Thiagarajand826c832010-04-15 17:38:45 -0400407 memcpy(tbf->bf_desc, bf->bf_desc, sc->sc_ah->caps.tx_desc_len);
Sujithd43f30152009-01-16 21:38:53 +0530408 tbf->bf_state = bf->bf_state;
Felix Fietkau86c7d8d2013-09-14 15:46:33 +0200409 tbf->bf_state.stale = false;
Sujithd43f30152009-01-16 21:38:53 +0530410
411 return tbf;
412}
413
Felix Fietkaub572d032010-11-14 15:20:07 +0100414static void ath_tx_count_frames(struct ath_softc *sc, struct ath_buf *bf,
415 struct ath_tx_status *ts, int txok,
416 int *nframes, int *nbad)
417{
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100418 struct ath_frame_info *fi;
Felix Fietkaub572d032010-11-14 15:20:07 +0100419 u16 seq_st = 0;
420 u32 ba[WME_BA_BMP_SIZE >> 5];
421 int ba_index;
422 int isaggr = 0;
423
424 *nbad = 0;
425 *nframes = 0;
426
Felix Fietkaub572d032010-11-14 15:20:07 +0100427 isaggr = bf_isaggr(bf);
428 if (isaggr) {
429 seq_st = ts->ts_seqnum;
430 memcpy(ba, &ts->ba_low, WME_BA_BMP_SIZE >> 3);
431 }
432
433 while (bf) {
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100434 fi = get_frame_info(bf->bf_mpdu);
Felix Fietkau6a0ddae2011-08-28 00:32:23 +0200435 ba_index = ATH_BA_INDEX(seq_st, bf->bf_state.seqno);
Felix Fietkaub572d032010-11-14 15:20:07 +0100436
437 (*nframes)++;
438 if (!txok || (isaggr && !ATH_BA_ISSET(ba, ba_index)))
439 (*nbad)++;
440
441 bf = bf->bf_next;
442 }
443}
444
445
Sujithd43f30152009-01-16 21:38:53 +0530446static void ath_tx_complete_aggr(struct ath_softc *sc, struct ath_txq *txq,
447 struct ath_buf *bf, struct list_head *bf_q,
Felix Fietkaud94a4612016-09-02 19:46:12 +0300448 struct ieee80211_sta *sta,
Felix Fietkau13815592013-01-20 18:51:53 +0100449 struct ath_tx_status *ts, int txok)
Sujithe8324352009-01-16 21:38:42 +0530450{
451 struct ath_node *an = NULL;
452 struct sk_buff *skb;
Sujith1286ec62009-01-27 13:30:37 +0530453 struct ieee80211_hdr *hdr;
Luis R. Rodriguez76d5a9e2009-11-02 16:08:34 -0800454 struct ieee80211_tx_info *tx_info;
Sujithe8324352009-01-16 21:38:42 +0530455 struct ath_atx_tid *tid = NULL;
Sujithd43f30152009-01-16 21:38:53 +0530456 struct ath_buf *bf_next, *bf_last = bf->bf_lastbf;
Felix Fietkau56dc6332011-08-28 00:32:22 +0200457 struct list_head bf_head;
458 struct sk_buff_head bf_pending;
Felix Fietkau156369f2011-12-14 22:08:04 +0100459 u16 seq_st = 0, acked_cnt = 0, txfail_cnt = 0, seq_first;
Sujithe8324352009-01-16 21:38:42 +0530460 u32 ba[WME_BA_BMP_SIZE >> 5];
Vasanthakumar Thiagarajan0934af22009-03-18 20:22:00 +0530461 int isaggr, txfail, txpending, sendbar = 0, needreset = 0, nbad = 0;
Sven Eckelmann6fe7cc72012-10-29 13:25:20 +0100462 bool rc_update = true, isba;
Felix Fietkau78c46532010-06-25 01:26:16 +0200463 struct ieee80211_tx_rate rates[4];
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100464 struct ath_frame_info *fi;
Björn Smedmanebd02282010-10-10 22:44:39 +0200465 int nframes;
Felix Fietkaudaa5c402011-10-07 02:28:15 +0200466 bool flush = !!(ts->ts_status & ATH9K_TX_FLUSH);
Felix Fietkauda647622011-12-14 22:08:03 +0100467 int i, retries;
Felix Fietkau156369f2011-12-14 22:08:04 +0100468 int bar_index = -1;
Sujithe8324352009-01-16 21:38:42 +0530469
Sujitha22be222009-03-30 15:28:36 +0530470 skb = bf->bf_mpdu;
Sujith1286ec62009-01-27 13:30:37 +0530471 hdr = (struct ieee80211_hdr *)skb->data;
Sujithe8324352009-01-16 21:38:42 +0530472
Luis R. Rodriguez76d5a9e2009-11-02 16:08:34 -0800473 tx_info = IEEE80211_SKB_CB(skb);
Luis R. Rodriguez76d5a9e2009-11-02 16:08:34 -0800474
Felix Fietkau79acac02013-04-22 23:11:44 +0200475 memcpy(rates, bf->rates, sizeof(rates));
Felix Fietkau78c46532010-06-25 01:26:16 +0200476
Felix Fietkauda647622011-12-14 22:08:03 +0100477 retries = ts->ts_longretry + 1;
478 for (i = 0; i < ts->ts_rateindex; i++)
479 retries += rates[i].count;
480
Sujith1286ec62009-01-27 13:30:37 +0530481 if (!sta) {
Felix Fietkau31e79a52010-07-12 23:16:34 +0200482 INIT_LIST_HEAD(&bf_head);
483 while (bf) {
484 bf_next = bf->bf_next;
485
Felix Fietkau50676b82013-08-10 15:59:16 +0200486 if (!bf->bf_state.stale || bf_next != NULL)
Felix Fietkau31e79a52010-07-12 23:16:34 +0200487 list_move_tail(&bf->list, &bf_head);
488
Felix Fietkaud94a4612016-09-02 19:46:12 +0300489 ath_tx_complete_buf(sc, bf, txq, &bf_head, NULL, ts, 0);
Felix Fietkau31e79a52010-07-12 23:16:34 +0200490
491 bf = bf_next;
492 }
Sujith1286ec62009-01-27 13:30:37 +0530493 return;
Sujithe8324352009-01-16 21:38:42 +0530494 }
495
Sujith1286ec62009-01-27 13:30:37 +0530496 an = (struct ath_node *)sta->drv_priv;
Felix Fietkau1803d022013-08-06 14:18:04 +0200497 tid = ath_get_skb_tid(sc, an, skb);
Felix Fietkau156369f2011-12-14 22:08:04 +0100498 seq_first = tid->seq_start;
Sven Eckelmann6fe7cc72012-10-29 13:25:20 +0100499 isba = ts->ts_flags & ATH9K_TX_BA;
Sujith1286ec62009-01-27 13:30:37 +0530500
Felix Fietkaub11b1602010-07-11 12:48:44 +0200501 /*
502 * The hardware occasionally sends a tx status for the wrong TID.
503 * In this case, the BA status cannot be considered valid and all
504 * subframes need to be retransmitted
Sven Eckelmann6fe7cc72012-10-29 13:25:20 +0100505 *
506 * Only BlockAcks have a TID and therefore normal Acks cannot be
507 * checked
Felix Fietkaub11b1602010-07-11 12:48:44 +0200508 */
Felix Fietkau1803d022013-08-06 14:18:04 +0200509 if (isba && tid->tidno != ts->tid)
Felix Fietkaub11b1602010-07-11 12:48:44 +0200510 txok = false;
511
Sujithe8324352009-01-16 21:38:42 +0530512 isaggr = bf_isaggr(bf);
Sujithd43f30152009-01-16 21:38:53 +0530513 memset(ba, 0, WME_BA_BMP_SIZE >> 3);
Sujithe8324352009-01-16 21:38:42 +0530514
Sujithd43f30152009-01-16 21:38:53 +0530515 if (isaggr && txok) {
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700516 if (ts->ts_flags & ATH9K_TX_BA) {
517 seq_st = ts->ts_seqnum;
518 memcpy(ba, &ts->ba_low, WME_BA_BMP_SIZE >> 3);
Sujithe8324352009-01-16 21:38:42 +0530519 } else {
Sujithd43f30152009-01-16 21:38:53 +0530520 /*
521 * AR5416 can become deaf/mute when BA
522 * issue happens. Chip needs to be reset.
523 * But AP code may have sychronization issues
524 * when perform internal reset in this routine.
525 * Only enable reset in STA mode for now.
526 */
Sujith2660b812009-02-09 13:27:26 +0530527 if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION)
Sujithd43f30152009-01-16 21:38:53 +0530528 needreset = 1;
Sujithe8324352009-01-16 21:38:42 +0530529 }
530 }
531
Felix Fietkau56dc6332011-08-28 00:32:22 +0200532 __skb_queue_head_init(&bf_pending);
Sujithe8324352009-01-16 21:38:42 +0530533
Felix Fietkaub572d032010-11-14 15:20:07 +0100534 ath_tx_count_frames(sc, bf, ts, txok, &nframes, &nbad);
Sujithe8324352009-01-16 21:38:42 +0530535 while (bf) {
Felix Fietkau6a0ddae2011-08-28 00:32:23 +0200536 u16 seqno = bf->bf_state.seqno;
537
Felix Fietkauf0b82202011-01-15 14:30:15 +0100538 txfail = txpending = sendbar = 0;
Sujithe8324352009-01-16 21:38:42 +0530539 bf_next = bf->bf_next;
540
Felix Fietkau78c46532010-06-25 01:26:16 +0200541 skb = bf->bf_mpdu;
542 tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100543 fi = get_frame_info(skb);
Felix Fietkau78c46532010-06-25 01:26:16 +0200544
Felix Fietkau897d7fd2013-08-06 14:18:09 +0200545 if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno) ||
546 !tid->active) {
Felix Fietkau08c96ab2013-05-18 21:28:15 +0200547 /*
548 * Outside of the current BlockAck window,
549 * maybe part of a previous session
550 */
551 txfail = 1;
552 } else if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, seqno))) {
Sujithe8324352009-01-16 21:38:42 +0530553 /* transmit completion, subframe is
554 * acked by block ack */
Vasanthakumar Thiagarajan0934af22009-03-18 20:22:00 +0530555 acked_cnt++;
Sujithe8324352009-01-16 21:38:42 +0530556 } else if (!isaggr && txok) {
557 /* transmit completion */
Vasanthakumar Thiagarajan0934af22009-03-18 20:22:00 +0530558 acked_cnt++;
Felix Fietkaub0477012011-12-14 22:08:05 +0100559 } else if (flush) {
560 txpending = 1;
561 } else if (fi->retries < ATH_MAX_SW_RETRIES) {
562 if (txok || !an->sleeping)
563 ath_tx_set_retry(sc, txq, bf->bf_mpdu,
564 retries);
Felix Fietkau55195412011-04-17 23:28:09 +0200565
Felix Fietkaub0477012011-12-14 22:08:05 +0100566 txpending = 1;
567 } else {
568 txfail = 1;
569 txfail_cnt++;
570 bar_index = max_t(int, bar_index,
571 ATH_BA_INDEX(seq_first, seqno));
Sujithe8324352009-01-16 21:38:42 +0530572 }
573
Felix Fietkaufce041b2011-05-19 12:20:25 +0200574 /*
575 * Make sure the last desc is reclaimed if it
576 * not a holding desc.
577 */
Felix Fietkau56dc6332011-08-28 00:32:22 +0200578 INIT_LIST_HEAD(&bf_head);
Felix Fietkau50676b82013-08-10 15:59:16 +0200579 if (bf_next != NULL || !bf_last->bf_state.stale)
Sujithd43f30152009-01-16 21:38:53 +0530580 list_move_tail(&bf->list, &bf_head);
Sujithe8324352009-01-16 21:38:42 +0530581
Felix Fietkau08c96ab2013-05-18 21:28:15 +0200582 if (!txpending) {
Sujithe8324352009-01-16 21:38:42 +0530583 /*
584 * complete the acked-ones/xretried ones; update
585 * block-ack window
586 */
Felix Fietkau6a0ddae2011-08-28 00:32:23 +0200587 ath_tx_update_baw(sc, tid, seqno);
Sujithe8324352009-01-16 21:38:42 +0530588
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +0530589 if (rc_update && (acked_cnt == 1 || txfail_cnt == 1)) {
Felix Fietkau78c46532010-06-25 01:26:16 +0200590 memcpy(tx_info->control.rates, rates, sizeof(rates));
Felix Fietkau3afd21e2011-09-14 21:24:26 +0200591 ath_tx_rc_status(sc, bf, ts, nframes, nbad, txok);
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +0530592 rc_update = false;
Lorenzo Bianconi982e0392014-09-16 02:13:12 +0200593 if (bf == bf->bf_lastbf)
594 ath_dynack_sample_tx_ts(sc->sc_ah,
595 bf->bf_mpdu,
596 ts);
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +0530597 }
598
Felix Fietkaud94a4612016-09-02 19:46:12 +0300599 ath_tx_complete_buf(sc, bf, txq, &bf_head, sta, ts,
Felix Fietkau156369f2011-12-14 22:08:04 +0100600 !txfail);
Sujithe8324352009-01-16 21:38:42 +0530601 } else {
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200602 if (tx_info->flags & IEEE80211_TX_STATUS_EOSP) {
603 tx_info->flags &= ~IEEE80211_TX_STATUS_EOSP;
604 ieee80211_sta_eosp(sta);
605 }
Sujithd43f30152009-01-16 21:38:53 +0530606 /* retry the un-acked ones */
Felix Fietkau50676b82013-08-10 15:59:16 +0200607 if (bf->bf_next == NULL && bf_last->bf_state.stale) {
Felix Fietkaub0477012011-12-14 22:08:05 +0100608 struct ath_buf *tbf;
Sujithe8324352009-01-16 21:38:42 +0530609
Felix Fietkaub0477012011-12-14 22:08:05 +0100610 tbf = ath_clone_txbuf(sc, bf_last);
611 /*
612 * Update tx baw and complete the
613 * frame with failed status if we
614 * run out of tx buf.
615 */
616 if (!tbf) {
Felix Fietkaub0477012011-12-14 22:08:05 +0100617 ath_tx_update_baw(sc, tid, seqno);
Vasanthakumar Thiagarajanc41d92d2009-07-14 20:17:11 -0400618
Felix Fietkaub0477012011-12-14 22:08:05 +0100619 ath_tx_complete_buf(sc, bf, txq,
Felix Fietkaud94a4612016-09-02 19:46:12 +0300620 &bf_head, NULL, ts,
621 0);
Felix Fietkaub0477012011-12-14 22:08:05 +0100622 bar_index = max_t(int, bar_index,
623 ATH_BA_INDEX(seq_first, seqno));
624 break;
Vasanthakumar Thiagarajanc41d92d2009-07-14 20:17:11 -0400625 }
Felix Fietkaub0477012011-12-14 22:08:05 +0100626
627 fi->bf = tbf;
Sujithe8324352009-01-16 21:38:42 +0530628 }
629
630 /*
631 * Put this buffer to the temporary pending
632 * queue to retain ordering
633 */
Felix Fietkau56dc6332011-08-28 00:32:22 +0200634 __skb_queue_tail(&bf_pending, skb);
Sujithe8324352009-01-16 21:38:42 +0530635 }
636
637 bf = bf_next;
638 }
639
Felix Fietkau4cee7862010-07-23 03:53:16 +0200640 /* prepend un-acked frames to the beginning of the pending frame queue */
Felix Fietkau56dc6332011-08-28 00:32:22 +0200641 if (!skb_queue_empty(&bf_pending)) {
Felix Fietkau55195412011-04-17 23:28:09 +0200642 if (an->sleeping)
Johannes Berg042ec452011-09-29 16:04:26 +0200643 ieee80211_sta_set_buffered(sta, tid->tidno, true);
Felix Fietkau55195412011-04-17 23:28:09 +0200644
Felix Fietkaubb195ff2013-08-06 14:18:03 +0200645 skb_queue_splice_tail(&bf_pending, &tid->retry_q);
Felix Fietkau26a64252011-10-07 02:28:14 +0200646 if (!an->sleeping) {
Felix Fietkau04535312014-06-11 16:17:51 +0530647 ath_tx_queue_tid(sc, txq, tid);
Felix Fietkau26a64252011-10-07 02:28:14 +0200648
Sujith Manoharanadfbda62012-08-29 09:20:42 +0530649 if (ts->ts_status & (ATH9K_TXERR_FILT | ATH9K_TXERR_XRETRY))
Felix Fietkau592fa222015-07-22 13:06:13 +0200650 tid->clear_ps_filter = true;
Felix Fietkau26a64252011-10-07 02:28:14 +0200651 }
Felix Fietkau4cee7862010-07-23 03:53:16 +0200652 }
653
Felix Fietkau23de5dc2011-12-19 16:45:54 +0100654 if (bar_index >= 0) {
655 u16 bar_seq = ATH_BA_INDEX2SEQ(seq_first, bar_index);
656
657 if (BAW_WITHIN(tid->seq_start, tid->baw_size, bar_seq))
658 tid->bar_index = ATH_BA_INDEX(tid->seq_start, bar_seq);
659
660 ath_txq_unlock(sc, txq);
661 ath_send_bar(tid, ATH_BA_INDEX2SEQ(seq_first, bar_index + 1));
662 ath_txq_lock(sc, txq);
663 }
664
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530665 if (needreset)
666 ath9k_queue_reset(sc, RESET_TYPE_TX_ERROR);
Sujithe8324352009-01-16 21:38:42 +0530667}
668
Felix Fietkau81b51952013-01-20 18:51:54 +0100669static bool bf_is_ampdu_not_probing(struct ath_buf *bf)
670{
671 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(bf->bf_mpdu);
672 return bf_isampdu(bf) && !(info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE);
673}
674
675static void ath_tx_process_buffer(struct ath_softc *sc, struct ath_txq *txq,
676 struct ath_tx_status *ts, struct ath_buf *bf,
677 struct list_head *bf_head)
678{
Felix Fietkaud94a4612016-09-02 19:46:12 +0300679 struct ieee80211_hw *hw = sc->hw;
Felix Fietkau0c585dd2013-05-17 12:58:25 +0200680 struct ieee80211_tx_info *info;
Felix Fietkaud94a4612016-09-02 19:46:12 +0300681 struct ieee80211_sta *sta;
682 struct ieee80211_hdr *hdr;
Felix Fietkau81b51952013-01-20 18:51:54 +0100683 bool txok, flush;
684
685 txok = !(ts->ts_status & ATH9K_TXERR_MASK);
686 flush = !!(ts->ts_status & ATH9K_TX_FLUSH);
687 txq->axq_tx_inprogress = false;
688
689 txq->axq_depth--;
690 if (bf_is_ampdu_not_probing(bf))
691 txq->axq_ampdu_depth--;
692
Felix Fietkau315dd112014-09-30 11:24:23 +0200693 ts->duration = ath9k_hw_get_duration(sc->sc_ah, bf->bf_desc,
694 ts->ts_rateindex);
Felix Fietkaud94a4612016-09-02 19:46:12 +0300695
696 hdr = (struct ieee80211_hdr *) bf->bf_mpdu->data;
697 sta = ieee80211_find_sta_by_ifaddr(hw, hdr->addr1, hdr->addr2);
698
Felix Fietkau81b51952013-01-20 18:51:54 +0100699 if (!bf_isampdu(bf)) {
Felix Fietkau0c585dd2013-05-17 12:58:25 +0200700 if (!flush) {
701 info = IEEE80211_SKB_CB(bf->bf_mpdu);
702 memcpy(info->control.rates, bf->rates,
703 sizeof(info->control.rates));
Felix Fietkau81b51952013-01-20 18:51:54 +0100704 ath_tx_rc_status(sc, bf, ts, 1, txok ? 0 : 1, txok);
Lorenzo Bianconi982e0392014-09-16 02:13:12 +0200705 ath_dynack_sample_tx_ts(sc->sc_ah, bf->bf_mpdu, ts);
Felix Fietkau0c585dd2013-05-17 12:58:25 +0200706 }
Felix Fietkaud94a4612016-09-02 19:46:12 +0300707 ath_tx_complete_buf(sc, bf, txq, bf_head, sta, ts, txok);
Felix Fietkau81b51952013-01-20 18:51:54 +0100708 } else
Felix Fietkaud94a4612016-09-02 19:46:12 +0300709 ath_tx_complete_aggr(sc, txq, bf, bf_head, sta, ts, txok);
Felix Fietkau81b51952013-01-20 18:51:54 +0100710
Felix Fietkau73364b02013-08-06 14:18:08 +0200711 if (!flush)
Felix Fietkau81b51952013-01-20 18:51:54 +0100712 ath_txq_schedule(sc, txq);
713}
714
Rajkumar Manoharan1a6e9d02011-08-23 12:32:57 +0530715static bool ath_lookup_legacy(struct ath_buf *bf)
716{
717 struct sk_buff *skb;
718 struct ieee80211_tx_info *tx_info;
719 struct ieee80211_tx_rate *rates;
720 int i;
721
722 skb = bf->bf_mpdu;
723 tx_info = IEEE80211_SKB_CB(skb);
724 rates = tx_info->control.rates;
725
Felix Fietkau059ee092011-08-27 10:25:27 +0200726 for (i = 0; i < 4; i++) {
727 if (!rates[i].count || rates[i].idx < 0)
728 break;
729
Rajkumar Manoharan1a6e9d02011-08-23 12:32:57 +0530730 if (!(rates[i].flags & IEEE80211_TX_RC_MCS))
731 return true;
732 }
733
734 return false;
735}
736
Sujithe8324352009-01-16 21:38:42 +0530737static u32 ath_lookup_rate(struct ath_softc *sc, struct ath_buf *bf,
738 struct ath_atx_tid *tid)
739{
Sujithe8324352009-01-16 21:38:42 +0530740 struct sk_buff *skb;
741 struct ieee80211_tx_info *tx_info;
742 struct ieee80211_tx_rate *rates;
Sujithd43f30152009-01-16 21:38:53 +0530743 u32 max_4ms_framelen, frmlen;
Sujith Manoharanc0ac53f2012-02-22 12:40:38 +0530744 u16 aggr_limit, bt_aggr_limit, legacy = 0;
Felix Fietkau592fa222015-07-22 13:06:13 +0200745 int q = tid->txq->mac80211_qnum;
Sujithe8324352009-01-16 21:38:42 +0530746 int i;
747
Sujitha22be222009-03-30 15:28:36 +0530748 skb = bf->bf_mpdu;
Sujithe8324352009-01-16 21:38:42 +0530749 tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau0c585dd2013-05-17 12:58:25 +0200750 rates = bf->rates;
Sujithe8324352009-01-16 21:38:42 +0530751
752 /*
753 * Find the lowest frame length among the rate series that will have a
Felix Fietkauaa5955c2012-07-15 19:53:36 +0200754 * 4ms (or TXOP limited) transmit duration.
Sujithe8324352009-01-16 21:38:42 +0530755 */
756 max_4ms_framelen = ATH_AMPDU_LIMIT_MAX;
757
758 for (i = 0; i < 4; i++) {
Felix Fietkaub0477012011-12-14 22:08:05 +0100759 int modeidx;
Sujithe8324352009-01-16 21:38:42 +0530760
Felix Fietkaub0477012011-12-14 22:08:05 +0100761 if (!rates[i].count)
762 continue;
Felix Fietkau0e668cd2010-04-19 19:57:32 +0200763
Felix Fietkaub0477012011-12-14 22:08:05 +0100764 if (!(rates[i].flags & IEEE80211_TX_RC_MCS)) {
765 legacy = 1;
766 break;
Sujithe8324352009-01-16 21:38:42 +0530767 }
Felix Fietkaub0477012011-12-14 22:08:05 +0100768
769 if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
770 modeidx = MCS_HT40;
771 else
772 modeidx = MCS_HT20;
773
774 if (rates[i].flags & IEEE80211_TX_RC_SHORT_GI)
775 modeidx++;
776
Felix Fietkauaa5955c2012-07-15 19:53:36 +0200777 frmlen = sc->tx.max_aggr_framelen[q][modeidx][rates[i].idx];
Felix Fietkaub0477012011-12-14 22:08:05 +0100778 max_4ms_framelen = min(max_4ms_framelen, frmlen);
Sujithe8324352009-01-16 21:38:42 +0530779 }
780
781 /*
782 * limit aggregate size by the minimum rate if rate selected is
783 * not a probe rate, if rate selected is a probe rate then
784 * avoid aggregation of this packet.
785 */
786 if (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE || legacy)
787 return 0;
788
Sujith Manoharanc0ac53f2012-02-22 12:40:38 +0530789 aggr_limit = min(max_4ms_framelen, (u32)ATH_AMPDU_LIMIT_MAX);
790
791 /*
792 * Override the default aggregation limit for BTCOEX.
793 */
794 bt_aggr_limit = ath9k_btcoex_aggr_limit(sc, max_4ms_framelen);
795 if (bt_aggr_limit)
796 aggr_limit = bt_aggr_limit;
Sujithe8324352009-01-16 21:38:42 +0530797
Sujith4ef70842009-07-23 15:32:41 +0530798 if (tid->an->maxampdu)
799 aggr_limit = min(aggr_limit, tid->an->maxampdu);
Sujithe8324352009-01-16 21:38:42 +0530800
801 return aggr_limit;
802}
803
804/*
Sujithd43f30152009-01-16 21:38:53 +0530805 * Returns the number of delimiters to be added to
Sujithe8324352009-01-16 21:38:42 +0530806 * meet the minimum required mpdudensity.
Sujithe8324352009-01-16 21:38:42 +0530807 */
808static int ath_compute_num_delims(struct ath_softc *sc, struct ath_atx_tid *tid,
Rajkumar Manoharan7a12dfd2011-08-13 10:28:08 +0530809 struct ath_buf *bf, u16 frmlen,
810 bool first_subfrm)
Sujithe8324352009-01-16 21:38:42 +0530811{
Rajkumar Manoharan7a12dfd2011-08-13 10:28:08 +0530812#define FIRST_DESC_NDELIMS 60
Sujith4ef70842009-07-23 15:32:41 +0530813 u32 nsymbits, nsymbols;
Sujithe8324352009-01-16 21:38:42 +0530814 u16 minlen;
Felix Fietkau545750d2009-11-23 22:21:01 +0100815 u8 flags, rix;
Felix Fietkauc6663872010-04-19 19:57:33 +0200816 int width, streams, half_gi, ndelim, mindelim;
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100817 struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu);
Sujithe8324352009-01-16 21:38:42 +0530818
819 /* Select standard number of delimiters based on frame length alone */
820 ndelim = ATH_AGGR_GET_NDELIM(frmlen);
821
822 /*
823 * If encryption enabled, hardware requires some more padding between
824 * subframes.
825 * TODO - this could be improved to be dependent on the rate.
826 * The hardware can keep up at lower rates, but not higher rates
827 */
Rajkumar Manoharan4f6760b2011-07-01 18:37:33 +0530828 if ((fi->keyix != ATH9K_TXKEYIX_INVALID) &&
829 !(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA))
Sujithe8324352009-01-16 21:38:42 +0530830 ndelim += ATH_AGGR_ENCRYPTDELIM;
831
832 /*
Rajkumar Manoharan7a12dfd2011-08-13 10:28:08 +0530833 * Add delimiter when using RTS/CTS with aggregation
834 * and non enterprise AR9003 card
835 */
Felix Fietkau34597312011-08-29 18:57:54 +0200836 if (first_subfrm && !AR_SREV_9580_10_OR_LATER(sc->sc_ah) &&
837 (sc->sc_ah->ent_mode & AR_ENT_OTP_MIN_PKT_SIZE_DISABLE))
Rajkumar Manoharan7a12dfd2011-08-13 10:28:08 +0530838 ndelim = max(ndelim, FIRST_DESC_NDELIMS);
839
840 /*
Sujithe8324352009-01-16 21:38:42 +0530841 * Convert desired mpdu density from microeconds to bytes based
842 * on highest rate in rate series (i.e. first rate) to determine
843 * required minimum length for subframe. Take into account
844 * whether high rate is 20 or 40Mhz and half or full GI.
Sujith4ef70842009-07-23 15:32:41 +0530845 *
Sujithe8324352009-01-16 21:38:42 +0530846 * If there is no mpdu density restriction, no further calculation
847 * is needed.
848 */
Sujith4ef70842009-07-23 15:32:41 +0530849
850 if (tid->an->mpdudensity == 0)
Sujithe8324352009-01-16 21:38:42 +0530851 return ndelim;
852
Felix Fietkau79acac02013-04-22 23:11:44 +0200853 rix = bf->rates[0].idx;
854 flags = bf->rates[0].flags;
Sujithe8324352009-01-16 21:38:42 +0530855 width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0;
856 half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0;
857
858 if (half_gi)
Sujith4ef70842009-07-23 15:32:41 +0530859 nsymbols = NUM_SYMBOLS_PER_USEC_HALFGI(tid->an->mpdudensity);
Sujithe8324352009-01-16 21:38:42 +0530860 else
Sujith4ef70842009-07-23 15:32:41 +0530861 nsymbols = NUM_SYMBOLS_PER_USEC(tid->an->mpdudensity);
Sujithe8324352009-01-16 21:38:42 +0530862
863 if (nsymbols == 0)
864 nsymbols = 1;
865
Felix Fietkauc6663872010-04-19 19:57:33 +0200866 streams = HT_RC_2_STREAMS(rix);
867 nsymbits = bits_per_symbol[rix % 8][width] * streams;
Sujithe8324352009-01-16 21:38:42 +0530868 minlen = (nsymbols * nsymbits) / BITS_PER_BYTE;
869
Sujithe8324352009-01-16 21:38:42 +0530870 if (frmlen < minlen) {
Sujithe8324352009-01-16 21:38:42 +0530871 mindelim = (minlen - frmlen) / ATH_AGGR_DELIM_SZ;
872 ndelim = max(mindelim, ndelim);
873 }
874
875 return ndelim;
876}
877
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200878static struct ath_buf *
879ath_tx_get_tid_subframe(struct ath_softc *sc, struct ath_txq *txq,
Felix Fietkaua7586ee2013-08-06 14:18:02 +0200880 struct ath_atx_tid *tid, struct sk_buff_head **q)
Sujithe8324352009-01-16 21:38:42 +0530881{
Felix Fietkau73364b02013-08-06 14:18:08 +0200882 struct ieee80211_tx_info *tx_info;
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100883 struct ath_frame_info *fi;
Felix Fietkau56dc6332011-08-28 00:32:22 +0200884 struct sk_buff *skb;
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200885 struct ath_buf *bf;
Felix Fietkau6a0ddae2011-08-28 00:32:23 +0200886 u16 seqno;
Sujithe8324352009-01-16 21:38:42 +0530887
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200888 while (1) {
Felix Fietkaubb195ff2013-08-06 14:18:03 +0200889 *q = &tid->retry_q;
890 if (skb_queue_empty(*q))
891 *q = &tid->buf_q;
892
Felix Fietkaua7586ee2013-08-06 14:18:02 +0200893 skb = skb_peek(*q);
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200894 if (!skb)
895 break;
896
Felix Fietkau56dc6332011-08-28 00:32:22 +0200897 fi = get_frame_info(skb);
898 bf = fi->bf;
Felix Fietkau44f1d262011-08-28 00:32:25 +0200899 if (!fi->bf)
Felix Fietkau249ee722012-10-03 21:07:52 +0200900 bf = ath_tx_setup_buffer(sc, txq, tid, skb);
Felix Fietkau563299d2013-08-13 12:33:30 +0200901 else
902 bf->bf_state.stale = false;
Felix Fietkau56dc6332011-08-28 00:32:22 +0200903
Felix Fietkau249ee722012-10-03 21:07:52 +0200904 if (!bf) {
Felix Fietkaua7586ee2013-08-06 14:18:02 +0200905 __skb_unlink(skb, *q);
Felix Fietkaua4943cc2013-06-30 12:02:13 +0200906 ath_txq_skb_done(sc, txq, skb);
Felix Fietkau249ee722012-10-03 21:07:52 +0200907 ieee80211_free_txskb(sc->hw, skb);
Felix Fietkau44f1d262011-08-28 00:32:25 +0200908 continue;
Felix Fietkau249ee722012-10-03 21:07:52 +0200909 }
Felix Fietkau44f1d262011-08-28 00:32:25 +0200910
Felix Fietkau73364b02013-08-06 14:18:08 +0200911 bf->bf_next = NULL;
912 bf->bf_lastbf = bf;
913
914 tx_info = IEEE80211_SKB_CB(skb);
915 tx_info->flags &= ~IEEE80211_TX_CTL_CLEAR_PS_FILT;
Felix Fietkauc01fac12014-07-23 15:40:54 +0200916
917 /*
918 * No aggregation session is running, but there may be frames
919 * from a previous session or a failed attempt in the queue.
920 * Send them out as normal data frames
921 */
922 if (!tid->active)
923 tx_info->flags &= ~IEEE80211_TX_CTL_AMPDU;
924
Felix Fietkau73364b02013-08-06 14:18:08 +0200925 if (!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) {
926 bf->bf_state.bf_type = 0;
927 return bf;
928 }
929
Felix Fietkau399c6482011-09-14 21:24:17 +0200930 bf->bf_state.bf_type = BUF_AMPDU | BUF_AGGR;
Felix Fietkau44f1d262011-08-28 00:32:25 +0200931 seqno = bf->bf_state.seqno;
Sujithe8324352009-01-16 21:38:42 +0530932
Sujithd43f30152009-01-16 21:38:53 +0530933 /* do not step over block-ack window */
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200934 if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno))
Sujithe8324352009-01-16 21:38:42 +0530935 break;
Sujithe8324352009-01-16 21:38:42 +0530936
Felix Fietkauf9437542011-12-14 22:08:08 +0100937 if (tid->bar_index > ATH_BA_INDEX(tid->seq_start, seqno)) {
938 struct ath_tx_status ts = {};
939 struct list_head bf_head;
940
941 INIT_LIST_HEAD(&bf_head);
942 list_add(&bf->list, &bf_head);
Felix Fietkaua7586ee2013-08-06 14:18:02 +0200943 __skb_unlink(skb, *q);
Felix Fietkauf9437542011-12-14 22:08:08 +0100944 ath_tx_update_baw(sc, tid, seqno);
Felix Fietkaud94a4612016-09-02 19:46:12 +0300945 ath_tx_complete_buf(sc, bf, txq, &bf_head, NULL, &ts, 0);
Felix Fietkauf9437542011-12-14 22:08:08 +0100946 continue;
947 }
948
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200949 return bf;
950 }
951
952 return NULL;
953}
954
Felix Fietkau2800e822013-08-06 14:18:11 +0200955static bool
956ath_tx_form_aggr(struct ath_softc *sc, struct ath_txq *txq,
957 struct ath_atx_tid *tid, struct list_head *bf_q,
958 struct ath_buf *bf_first, struct sk_buff_head *tid_q,
959 int *aggr_len)
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200960{
961#define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
Felix Fietkau2800e822013-08-06 14:18:11 +0200962 struct ath_buf *bf = bf_first, *bf_prev = NULL;
Felix Fietkaua1cd94d2013-08-06 14:18:06 +0200963 int nframes = 0, ndelim;
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200964 u16 aggr_limit = 0, al = 0, bpad = 0,
Felix Fietkaua1cd94d2013-08-06 14:18:06 +0200965 al_delta, h_baw = tid->baw_size / 2;
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200966 struct ieee80211_tx_info *tx_info;
967 struct ath_frame_info *fi;
968 struct sk_buff *skb;
Felix Fietkau2800e822013-08-06 14:18:11 +0200969 bool closed = false;
970
971 bf = bf_first;
972 aggr_limit = ath_lookup_rate(sc, bf, tid);
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200973
974 do {
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200975 skb = bf->bf_mpdu;
976 fi = get_frame_info(skb);
977
Sujithd43f30152009-01-16 21:38:53 +0530978 /* do not exceed aggregation limit */
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100979 al_delta = ATH_AGGR_DELIM_SZ + fi->framelen;
Felix Fietkaua1cd94d2013-08-06 14:18:06 +0200980 if (nframes) {
981 if (aggr_limit < al + bpad + al_delta ||
Felix Fietkau2800e822013-08-06 14:18:11 +0200982 ath_lookup_legacy(bf) || nframes >= h_baw)
Felix Fietkaua1cd94d2013-08-06 14:18:06 +0200983 break;
Sujithe8324352009-01-16 21:38:42 +0530984
Felix Fietkaua1cd94d2013-08-06 14:18:06 +0200985 tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
Felix Fietkau2800e822013-08-06 14:18:11 +0200986 if ((tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) ||
987 !(tx_info->flags & IEEE80211_TX_CTL_AMPDU))
Felix Fietkaua1cd94d2013-08-06 14:18:06 +0200988 break;
Sujithe8324352009-01-16 21:38:42 +0530989 }
990
Sujithd43f30152009-01-16 21:38:53 +0530991 /* add padding for previous frame to aggregation length */
Sujithe8324352009-01-16 21:38:42 +0530992 al += bpad + al_delta;
993
994 /*
995 * Get the delimiters needed to meet the MPDU
996 * density for this node.
997 */
Rajkumar Manoharan7a12dfd2011-08-13 10:28:08 +0530998 ndelim = ath_compute_num_delims(sc, tid, bf_first, fi->framelen,
999 !nframes);
Sujithe8324352009-01-16 21:38:42 +05301000 bpad = PADBYTES(al_delta) + (ndelim << 2);
1001
Rajkumar Manoharan7a12dfd2011-08-13 10:28:08 +05301002 nframes++;
Sujithe8324352009-01-16 21:38:42 +05301003 bf->bf_next = NULL;
Sujithe8324352009-01-16 21:38:42 +05301004
Sujithd43f30152009-01-16 21:38:53 +05301005 /* link buffers of this frame to the aggregate */
Felix Fietkau8fed1402013-08-06 14:18:07 +02001006 if (!fi->baw_tracked)
1007 ath_tx_addto_baw(sc, tid, bf);
Felix Fietkau399c6482011-09-14 21:24:17 +02001008 bf->bf_state.ndelim = ndelim;
Felix Fietkau56dc6332011-08-28 00:32:22 +02001009
Felix Fietkaua7586ee2013-08-06 14:18:02 +02001010 __skb_unlink(skb, tid_q);
Felix Fietkau56dc6332011-08-28 00:32:22 +02001011 list_add_tail(&bf->list, bf_q);
Felix Fietkau399c6482011-09-14 21:24:17 +02001012 if (bf_prev)
Sujithe8324352009-01-16 21:38:42 +05301013 bf_prev->bf_next = bf;
Felix Fietkau399c6482011-09-14 21:24:17 +02001014
Sujithe8324352009-01-16 21:38:42 +05301015 bf_prev = bf;
Sujithfec247c2009-07-27 12:08:16 +05301016
Felix Fietkau2800e822013-08-06 14:18:11 +02001017 bf = ath_tx_get_tid_subframe(sc, txq, tid, &tid_q);
1018 if (!bf) {
1019 closed = true;
1020 break;
1021 }
Felix Fietkaua7586ee2013-08-06 14:18:02 +02001022 } while (ath_tid_has_buffered(tid));
Sujithe8324352009-01-16 21:38:42 +05301023
Felix Fietkau2800e822013-08-06 14:18:11 +02001024 bf = bf_first;
1025 bf->bf_lastbf = bf_prev;
1026
1027 if (bf == bf_prev) {
1028 al = get_frame_info(bf->bf_mpdu)->framelen;
1029 bf->bf_state.bf_type = BUF_AMPDU;
1030 } else {
1031 TX_STAT_INC(txq->axq_qnum, a_aggr);
1032 }
1033
Felix Fietkau269c44b2010-11-14 15:20:06 +01001034 *aggr_len = al;
Sujithd43f30152009-01-16 21:38:53 +05301035
Felix Fietkau2800e822013-08-06 14:18:11 +02001036 return closed;
Sujithe8324352009-01-16 21:38:42 +05301037#undef PADBYTES
1038}
1039
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001040/*
1041 * rix - rate index
1042 * pktlen - total bytes (delims + data + fcs + pads + pad delims)
1043 * width - 0 for 20 MHz, 1 for 40 MHz
1044 * half_gi - to use 4us v/s 3.6 us for symbol time
1045 */
1046static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, int pktlen,
1047 int width, int half_gi, bool shortPreamble)
1048{
1049 u32 nbits, nsymbits, duration, nsymbols;
1050 int streams;
1051
1052 /* find number of symbols: PLCP + data */
1053 streams = HT_RC_2_STREAMS(rix);
1054 nbits = (pktlen << 3) + OFDM_PLCP_BITS;
1055 nsymbits = bits_per_symbol[rix % 8][width] * streams;
1056 nsymbols = (nbits + nsymbits - 1) / nsymbits;
1057
1058 if (!half_gi)
1059 duration = SYMBOL_TIME(nsymbols);
1060 else
1061 duration = SYMBOL_TIME_HALFGI(nsymbols);
1062
1063 /* addup duration for legacy/ht training and signal fields */
1064 duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
1065
1066 return duration;
1067}
1068
Felix Fietkauaa5955c2012-07-15 19:53:36 +02001069static int ath_max_framelen(int usec, int mcs, bool ht40, bool sgi)
1070{
1071 int streams = HT_RC_2_STREAMS(mcs);
1072 int symbols, bits;
1073 int bytes = 0;
1074
Sylvain Roger Rieunier727b6622014-02-27 14:36:06 +01001075 usec -= L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
Felix Fietkauaa5955c2012-07-15 19:53:36 +02001076 symbols = sgi ? TIME_SYMBOLS_HALFGI(usec) : TIME_SYMBOLS(usec);
1077 bits = symbols * bits_per_symbol[mcs % 8][ht40] * streams;
1078 bits -= OFDM_PLCP_BITS;
1079 bytes = bits / 8;
Felix Fietkauaa5955c2012-07-15 19:53:36 +02001080 if (bytes > 65532)
1081 bytes = 65532;
1082
1083 return bytes;
1084}
1085
1086void ath_update_max_aggr_framelen(struct ath_softc *sc, int queue, int txop)
1087{
1088 u16 *cur_ht20, *cur_ht20_sgi, *cur_ht40, *cur_ht40_sgi;
1089 int mcs;
1090
1091 /* 4ms is the default (and maximum) duration */
1092 if (!txop || txop > 4096)
1093 txop = 4096;
1094
1095 cur_ht20 = sc->tx.max_aggr_framelen[queue][MCS_HT20];
1096 cur_ht20_sgi = sc->tx.max_aggr_framelen[queue][MCS_HT20_SGI];
1097 cur_ht40 = sc->tx.max_aggr_framelen[queue][MCS_HT40];
1098 cur_ht40_sgi = sc->tx.max_aggr_framelen[queue][MCS_HT40_SGI];
1099 for (mcs = 0; mcs < 32; mcs++) {
1100 cur_ht20[mcs] = ath_max_framelen(txop, mcs, false, false);
1101 cur_ht20_sgi[mcs] = ath_max_framelen(txop, mcs, false, true);
1102 cur_ht40[mcs] = ath_max_framelen(txop, mcs, true, false);
1103 cur_ht40_sgi[mcs] = ath_max_framelen(txop, mcs, true, true);
1104 }
1105}
1106
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001107static u8 ath_get_rate_txpower(struct ath_softc *sc, struct ath_buf *bf,
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001108 u8 rateidx, bool is_40, bool is_cck)
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001109{
1110 u8 max_power;
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001111 struct sk_buff *skb;
1112 struct ath_frame_info *fi;
1113 struct ieee80211_tx_info *info;
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001114 struct ath_hw *ah = sc->sc_ah;
1115
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001116 if (sc->tx99_state || !ah->tpc_enabled)
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001117 return MAX_RATE_POWER;
1118
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001119 skb = bf->bf_mpdu;
Lorenzo Bianconi97bf8612015-02-17 10:12:18 +01001120 fi = get_frame_info(skb);
Lorenzo Bianconif6738212015-04-08 20:51:57 +02001121 info = IEEE80211_SKB_CB(skb);
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001122
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001123 if (!AR_SREV_9300_20_OR_LATER(ah)) {
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001124 int txpower = fi->tx_power;
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001125
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001126 if (is_40) {
1127 u8 power_ht40delta;
1128 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001129
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001130 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
1131 bool is_2ghz;
1132 struct modal_eep_header *pmodal;
1133
Johannes Berg57fbcce2016-04-12 15:56:15 +02001134 is_2ghz = info->band == NL80211_BAND_2GHZ;
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001135 pmodal = &eep->modalHeader[is_2ghz];
1136 power_ht40delta = pmodal->ht40PowerIncForPdadc;
1137 } else {
1138 power_ht40delta = 2;
1139 }
1140 txpower += power_ht40delta;
1141 }
1142
1143 if (AR_SREV_9287(ah) || AR_SREV_9285(ah) ||
1144 AR_SREV_9271(ah)) {
1145 txpower -= 2 * AR9287_PWR_TABLE_OFFSET_DB;
1146 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
1147 s8 power_offset;
1148
1149 power_offset = ah->eep_ops->get_eeprom(ah,
1150 EEP_PWR_TABLE_OFFSET);
1151 txpower -= 2 * power_offset;
1152 }
1153
1154 if (OLC_FOR_AR9280_20_LATER && is_cck)
1155 txpower -= 2;
1156
1157 txpower = max(txpower, 0);
Lorenzo Bianconif6738212015-04-08 20:51:57 +02001158 max_power = min_t(u8, ah->tx_power[rateidx], txpower);
1159
1160 /* XXX: clamp minimum TX power at 1 for AR9160 since if
1161 * max_power is set to 0, frames are transmitted at max
1162 * TX power
1163 */
1164 if (!max_power && !AR_SREV_9280_20_OR_LATER(ah))
1165 max_power = 1;
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001166 } else if (!bf->bf_state.bfs_paprd) {
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001167 if (rateidx < 8 && (info->flags & IEEE80211_TX_CTL_STBC))
Lorenzo Bianconi97bf8612015-02-17 10:12:18 +01001168 max_power = min_t(u8, ah->tx_power_stbc[rateidx],
Lorenzo Bianconif6738212015-04-08 20:51:57 +02001169 fi->tx_power);
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001170 else
Lorenzo Bianconi97bf8612015-02-17 10:12:18 +01001171 max_power = min_t(u8, ah->tx_power[rateidx],
Lorenzo Bianconif6738212015-04-08 20:51:57 +02001172 fi->tx_power);
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001173 } else {
1174 max_power = ah->paprd_training_power;
1175 }
Lorenzo Bianconif6738212015-04-08 20:51:57 +02001176
1177 return max_power;
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001178}
1179
Felix Fietkau493cf042011-09-14 21:24:22 +02001180static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf,
Sujith Manoharana3835e92013-07-04 12:59:47 +05301181 struct ath_tx_info *info, int len, bool rts)
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001182{
1183 struct ath_hw *ah = sc->sc_ah;
Oleksij Rempel13f71052014-02-25 14:48:50 +01001184 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001185 struct sk_buff *skb;
1186 struct ieee80211_tx_info *tx_info;
1187 struct ieee80211_tx_rate *rates;
1188 const struct ieee80211_rate *rate;
1189 struct ieee80211_hdr *hdr;
Felix Fietkau80b08a82012-06-15 03:04:53 +02001190 struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu);
Sujith Manoharana3835e92013-07-04 12:59:47 +05301191 u32 rts_thresh = sc->hw->wiphy->rts_threshold;
Felix Fietkau493cf042011-09-14 21:24:22 +02001192 int i;
1193 u8 rix = 0;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001194
1195 skb = bf->bf_mpdu;
1196 tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau79acac02013-04-22 23:11:44 +02001197 rates = bf->rates;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001198 hdr = (struct ieee80211_hdr *)skb->data;
Felix Fietkau493cf042011-09-14 21:24:22 +02001199
1200 /* set dur_update_en for l-sig computation except for PS-Poll frames */
1201 info->dur_update = !ieee80211_is_pspoll(hdr->frame_control);
Felix Fietkau80b08a82012-06-15 03:04:53 +02001202 info->rtscts_rate = fi->rtscts_rate;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001203
Felix Fietkau79acac02013-04-22 23:11:44 +02001204 for (i = 0; i < ARRAY_SIZE(bf->rates); i++) {
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001205 bool is_40, is_sgi, is_sp, is_cck;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001206 int phy;
1207
1208 if (!rates[i].count || (rates[i].idx < 0))
1209 continue;
1210
1211 rix = rates[i].idx;
Felix Fietkau493cf042011-09-14 21:24:22 +02001212 info->rates[i].Tries = rates[i].count;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001213
Sujith Manoharana3835e92013-07-04 12:59:47 +05301214 /*
1215 * Handle RTS threshold for unaggregated HT frames.
1216 */
1217 if (bf_isampdu(bf) && !bf_isaggr(bf) &&
1218 (rates[i].flags & IEEE80211_TX_RC_MCS) &&
1219 unlikely(rts_thresh != (u32) -1)) {
1220 if (!rts_thresh || (len > rts_thresh))
1221 rts = true;
1222 }
1223
1224 if (rts || rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Felix Fietkau493cf042011-09-14 21:24:22 +02001225 info->rates[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
1226 info->flags |= ATH9K_TXDESC_RTSENA;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001227 } else if (rates[i].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Felix Fietkau493cf042011-09-14 21:24:22 +02001228 info->rates[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
1229 info->flags |= ATH9K_TXDESC_CTSENA;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001230 }
1231
1232 if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
Felix Fietkau493cf042011-09-14 21:24:22 +02001233 info->rates[i].RateFlags |= ATH9K_RATESERIES_2040;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001234 if (rates[i].flags & IEEE80211_TX_RC_SHORT_GI)
Felix Fietkau493cf042011-09-14 21:24:22 +02001235 info->rates[i].RateFlags |= ATH9K_RATESERIES_HALFGI;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001236
1237 is_sgi = !!(rates[i].flags & IEEE80211_TX_RC_SHORT_GI);
1238 is_40 = !!(rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH);
1239 is_sp = !!(rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE);
1240
1241 if (rates[i].flags & IEEE80211_TX_RC_MCS) {
1242 /* MCS rates */
Felix Fietkau493cf042011-09-14 21:24:22 +02001243 info->rates[i].Rate = rix | 0x80;
1244 info->rates[i].ChSel = ath_txchainmask_reduction(sc,
1245 ah->txchainmask, info->rates[i].Rate);
1246 info->rates[i].PktDuration = ath_pkt_duration(sc, rix, len,
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001247 is_40, is_sgi, is_sp);
1248 if (rix < 8 && (tx_info->flags & IEEE80211_TX_CTL_STBC))
Felix Fietkau493cf042011-09-14 21:24:22 +02001249 info->rates[i].RateFlags |= ATH9K_RATESERIES_STBC;
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001250
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001251 info->txpower[i] = ath_get_rate_txpower(sc, bf, rix,
1252 is_40, false);
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001253 continue;
1254 }
1255
1256 /* legacy rates */
Oleksij Rempel13f71052014-02-25 14:48:50 +01001257 rate = &common->sbands[tx_info->band].bitrates[rates[i].idx];
Johannes Berg57fbcce2016-04-12 15:56:15 +02001258 if ((tx_info->band == NL80211_BAND_2GHZ) &&
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001259 !(rate->flags & IEEE80211_RATE_ERP_G))
1260 phy = WLAN_RC_PHY_CCK;
1261 else
1262 phy = WLAN_RC_PHY_OFDM;
1263
Felix Fietkau493cf042011-09-14 21:24:22 +02001264 info->rates[i].Rate = rate->hw_value;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001265 if (rate->hw_value_short) {
1266 if (rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
Felix Fietkau493cf042011-09-14 21:24:22 +02001267 info->rates[i].Rate |= rate->hw_value_short;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001268 } else {
1269 is_sp = false;
1270 }
1271
1272 if (bf->bf_state.bfs_paprd)
Felix Fietkau493cf042011-09-14 21:24:22 +02001273 info->rates[i].ChSel = ah->txchainmask;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001274 else
Felix Fietkau493cf042011-09-14 21:24:22 +02001275 info->rates[i].ChSel = ath_txchainmask_reduction(sc,
1276 ah->txchainmask, info->rates[i].Rate);
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001277
Felix Fietkau493cf042011-09-14 21:24:22 +02001278 info->rates[i].PktDuration = ath9k_hw_computetxtime(sc->sc_ah,
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001279 phy, rate->bitrate * 100, len, rix, is_sp);
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001280
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001281 is_cck = IS_CCK_RATE(info->rates[i].Rate);
1282 info->txpower[i] = ath_get_rate_txpower(sc, bf, rix, false,
1283 is_cck);
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001284 }
1285
1286 /* For AR5416 - RTS cannot be followed by a frame larger than 8K */
1287 if (bf_isaggr(bf) && (len > sc->sc_ah->caps.rts_aggr_limit))
Felix Fietkau493cf042011-09-14 21:24:22 +02001288 info->flags &= ~ATH9K_TXDESC_RTSENA;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001289
1290 /* ATH9K_TXDESC_RTSENA and ATH9K_TXDESC_CTSENA are mutually exclusive. */
Felix Fietkau493cf042011-09-14 21:24:22 +02001291 if (info->flags & ATH9K_TXDESC_RTSENA)
1292 info->flags &= ~ATH9K_TXDESC_CTSENA;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001293}
1294
Felix Fietkau493cf042011-09-14 21:24:22 +02001295static enum ath9k_pkt_type get_hw_packet_type(struct sk_buff *skb)
1296{
1297 struct ieee80211_hdr *hdr;
1298 enum ath9k_pkt_type htype;
1299 __le16 fc;
1300
1301 hdr = (struct ieee80211_hdr *)skb->data;
1302 fc = hdr->frame_control;
1303
1304 if (ieee80211_is_beacon(fc))
1305 htype = ATH9K_PKT_TYPE_BEACON;
1306 else if (ieee80211_is_probe_resp(fc))
1307 htype = ATH9K_PKT_TYPE_PROBE_RESP;
1308 else if (ieee80211_is_atim(fc))
1309 htype = ATH9K_PKT_TYPE_ATIM;
1310 else if (ieee80211_is_pspoll(fc))
1311 htype = ATH9K_PKT_TYPE_PSPOLL;
1312 else
1313 htype = ATH9K_PKT_TYPE_NORMAL;
1314
1315 return htype;
1316}
1317
1318static void ath_tx_fill_desc(struct ath_softc *sc, struct ath_buf *bf,
1319 struct ath_txq *txq, int len)
Felix Fietkau399c6482011-09-14 21:24:17 +02001320{
1321 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001322 struct ath_buf *bf_first = NULL;
Felix Fietkau493cf042011-09-14 21:24:22 +02001323 struct ath_tx_info info;
Sujith Manoharana3835e92013-07-04 12:59:47 +05301324 u32 rts_thresh = sc->hw->wiphy->rts_threshold;
1325 bool rts = false;
Felix Fietkau399c6482011-09-14 21:24:17 +02001326
Felix Fietkau493cf042011-09-14 21:24:22 +02001327 memset(&info, 0, sizeof(info));
1328 info.is_first = true;
1329 info.is_last = true;
Felix Fietkau493cf042011-09-14 21:24:22 +02001330 info.qcu = txq->axq_qnum;
Felix Fietkau399c6482011-09-14 21:24:17 +02001331
Felix Fietkau399c6482011-09-14 21:24:17 +02001332 while (bf) {
Felix Fietkau493cf042011-09-14 21:24:22 +02001333 struct sk_buff *skb = bf->bf_mpdu;
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001334 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau493cf042011-09-14 21:24:22 +02001335 struct ath_frame_info *fi = get_frame_info(skb);
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001336 bool aggr = !!(bf->bf_state.bf_type & BUF_AGGR);
Felix Fietkau493cf042011-09-14 21:24:22 +02001337
1338 info.type = get_hw_packet_type(skb);
Felix Fietkau399c6482011-09-14 21:24:17 +02001339 if (bf->bf_next)
Felix Fietkau493cf042011-09-14 21:24:22 +02001340 info.link = bf->bf_next->bf_daddr;
Felix Fietkau399c6482011-09-14 21:24:17 +02001341 else
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001342 info.link = (sc->tx99_state) ? bf->bf_daddr : 0;
Felix Fietkau399c6482011-09-14 21:24:17 +02001343
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001344 if (!bf_first) {
1345 bf_first = bf;
1346
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001347 if (!sc->tx99_state)
1348 info.flags = ATH9K_TXDESC_INTREQ;
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001349 if ((tx_info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT) ||
1350 txq == sc->tx.uapsdq)
1351 info.flags |= ATH9K_TXDESC_CLRDMASK;
1352
1353 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
1354 info.flags |= ATH9K_TXDESC_NOACK;
1355 if (tx_info->flags & IEEE80211_TX_CTL_LDPC)
1356 info.flags |= ATH9K_TXDESC_LDPC;
1357
1358 if (bf->bf_state.bfs_paprd)
1359 info.flags |= (u32) bf->bf_state.bfs_paprd <<
1360 ATH9K_TXDESC_PAPRD_S;
1361
Sujith Manoharana3835e92013-07-04 12:59:47 +05301362 /*
1363 * mac80211 doesn't handle RTS threshold for HT because
1364 * the decision has to be taken based on AMPDU length
1365 * and aggregation is done entirely inside ath9k.
1366 * Set the RTS/CTS flag for the first subframe based
1367 * on the threshold.
1368 */
1369 if (aggr && (bf == bf_first) &&
1370 unlikely(rts_thresh != (u32) -1)) {
1371 /*
1372 * "len" is the size of the entire AMPDU.
1373 */
1374 if (!rts_thresh || (len > rts_thresh))
1375 rts = true;
1376 }
Felix Fietkaubbf807b2013-12-05 15:20:53 +01001377
1378 if (!aggr)
1379 len = fi->framelen;
1380
Sujith Manoharana3835e92013-07-04 12:59:47 +05301381 ath_buf_set_rate(sc, bf, &info, len, rts);
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001382 }
1383
John W. Linville42cecc32011-09-19 15:42:31 -04001384 info.buf_addr[0] = bf->bf_buf_addr;
1385 info.buf_len[0] = skb->len;
Felix Fietkau493cf042011-09-14 21:24:22 +02001386 info.pkt_len = fi->framelen;
1387 info.keyix = fi->keyix;
1388 info.keytype = fi->keytype;
1389
1390 if (aggr) {
Felix Fietkau399c6482011-09-14 21:24:17 +02001391 if (bf == bf_first)
Felix Fietkau493cf042011-09-14 21:24:22 +02001392 info.aggr = AGGR_BUF_FIRST;
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001393 else if (bf == bf_first->bf_lastbf)
Felix Fietkau493cf042011-09-14 21:24:22 +02001394 info.aggr = AGGR_BUF_LAST;
1395 else
1396 info.aggr = AGGR_BUF_MIDDLE;
Felix Fietkau399c6482011-09-14 21:24:17 +02001397
Felix Fietkau493cf042011-09-14 21:24:22 +02001398 info.ndelim = bf->bf_state.ndelim;
1399 info.aggr_len = len;
Felix Fietkau399c6482011-09-14 21:24:17 +02001400 }
1401
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001402 if (bf == bf_first->bf_lastbf)
1403 bf_first = NULL;
1404
Felix Fietkau493cf042011-09-14 21:24:22 +02001405 ath9k_hw_set_txdesc(ah, bf->bf_desc, &info);
Felix Fietkau399c6482011-09-14 21:24:17 +02001406 bf = bf->bf_next;
1407 }
1408}
1409
Felix Fietkau2800e822013-08-06 14:18:11 +02001410static void
1411ath_tx_form_burst(struct ath_softc *sc, struct ath_txq *txq,
1412 struct ath_atx_tid *tid, struct list_head *bf_q,
1413 struct ath_buf *bf_first, struct sk_buff_head *tid_q)
1414{
1415 struct ath_buf *bf = bf_first, *bf_prev = NULL;
1416 struct sk_buff *skb;
1417 int nframes = 0;
1418
1419 do {
1420 struct ieee80211_tx_info *tx_info;
1421 skb = bf->bf_mpdu;
1422
1423 nframes++;
1424 __skb_unlink(skb, tid_q);
1425 list_add_tail(&bf->list, bf_q);
1426 if (bf_prev)
1427 bf_prev->bf_next = bf;
1428 bf_prev = bf;
1429
1430 if (nframes >= 2)
1431 break;
1432
1433 bf = ath_tx_get_tid_subframe(sc, txq, tid, &tid_q);
1434 if (!bf)
1435 break;
1436
1437 tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
1438 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
1439 break;
1440
1441 ath_set_rates(tid->an->vif, tid->an->sta, bf);
1442 } while (1);
1443}
1444
Felix Fietkau020f20f2013-08-06 14:18:12 +02001445static bool ath_tx_sched_aggr(struct ath_softc *sc, struct ath_txq *txq,
1446 struct ath_atx_tid *tid, bool *stop)
Sujithe8324352009-01-16 21:38:42 +05301447{
Sujithd43f30152009-01-16 21:38:53 +05301448 struct ath_buf *bf;
Felix Fietkau399c6482011-09-14 21:24:17 +02001449 struct ieee80211_tx_info *tx_info;
Felix Fietkau2800e822013-08-06 14:18:11 +02001450 struct sk_buff_head *tid_q;
Sujithe8324352009-01-16 21:38:42 +05301451 struct list_head bf_q;
Felix Fietkau2800e822013-08-06 14:18:11 +02001452 int aggr_len = 0;
1453 bool aggr, last = true;
Sujithe8324352009-01-16 21:38:42 +05301454
Felix Fietkau020f20f2013-08-06 14:18:12 +02001455 if (!ath_tid_has_buffered(tid))
1456 return false;
Sujithe8324352009-01-16 21:38:42 +05301457
Felix Fietkau020f20f2013-08-06 14:18:12 +02001458 INIT_LIST_HEAD(&bf_q);
Sujithe8324352009-01-16 21:38:42 +05301459
Felix Fietkau020f20f2013-08-06 14:18:12 +02001460 bf = ath_tx_get_tid_subframe(sc, txq, tid, &tid_q);
1461 if (!bf)
1462 return false;
Sujithe8324352009-01-16 21:38:42 +05301463
Felix Fietkau020f20f2013-08-06 14:18:12 +02001464 tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
1465 aggr = !!(tx_info->flags & IEEE80211_TX_CTL_AMPDU);
1466 if ((aggr && txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) ||
1467 (!aggr && txq->axq_depth >= ATH_NON_AGGR_MIN_QDEPTH)) {
1468 *stop = true;
1469 return false;
1470 }
Felix Fietkau2800e822013-08-06 14:18:11 +02001471
Felix Fietkau020f20f2013-08-06 14:18:12 +02001472 ath_set_rates(tid->an->vif, tid->an->sta, bf);
1473 if (aggr)
1474 last = ath_tx_form_aggr(sc, txq, tid, &bf_q, bf,
1475 tid_q, &aggr_len);
1476 else
1477 ath_tx_form_burst(sc, txq, tid, &bf_q, bf, tid_q);
Felix Fietkau2800e822013-08-06 14:18:11 +02001478
Felix Fietkau020f20f2013-08-06 14:18:12 +02001479 if (list_empty(&bf_q))
1480 return false;
Sujithe8324352009-01-16 21:38:42 +05301481
Felix Fietkau592fa222015-07-22 13:06:13 +02001482 if (tid->clear_ps_filter || tid->an->no_ps_filter) {
1483 tid->clear_ps_filter = false;
Felix Fietkau020f20f2013-08-06 14:18:12 +02001484 tx_info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1485 }
Sujithe8324352009-01-16 21:38:42 +05301486
Felix Fietkau020f20f2013-08-06 14:18:12 +02001487 ath_tx_fill_desc(sc, bf, txq, aggr_len);
1488 ath_tx_txqaddbuf(sc, txq, &bf_q, false);
1489 return true;
Sujithe8324352009-01-16 21:38:42 +05301490}
1491
Felix Fietkau231c3a12010-09-20 19:35:28 +02001492int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
1493 u16 tid, u16 *ssn)
Sujithe8324352009-01-16 21:38:42 +05301494{
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001495 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithe8324352009-01-16 21:38:42 +05301496 struct ath_atx_tid *txtid;
Felix Fietkau919123d2013-09-18 15:23:41 +02001497 struct ath_txq *txq;
Sujithe8324352009-01-16 21:38:42 +05301498 struct ath_node *an;
Sven Eckelmann313eb872012-06-25 07:15:22 +02001499 u8 density;
Sujithe8324352009-01-16 21:38:42 +05301500
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001501 ath_dbg(common, XMIT, "%s called\n", __func__);
1502
Sujithe8324352009-01-16 21:38:42 +05301503 an = (struct ath_node *)sta->drv_priv;
Sujithf83da962009-07-23 15:32:37 +05301504 txtid = ATH_AN_2_TID(an, tid);
Felix Fietkau592fa222015-07-22 13:06:13 +02001505 txq = txtid->txq;
Felix Fietkau919123d2013-09-18 15:23:41 +02001506
1507 ath_txq_lock(sc, txq);
Felix Fietkau231c3a12010-09-20 19:35:28 +02001508
Sven Eckelmann313eb872012-06-25 07:15:22 +02001509 /* update ampdu factor/density, they may have changed. This may happen
1510 * in HT IBSS when a beacon with HT-info is received after the station
1511 * has already been added.
1512 */
Sujith Manoharandd5ee592013-02-04 15:38:23 +05301513 if (sta->ht_cap.ht_supported) {
Sujith Manoharan5b502c82013-12-24 10:44:17 +05301514 an->maxampdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1515 sta->ht_cap.ampdu_factor)) - 1;
Sven Eckelmann313eb872012-06-25 07:15:22 +02001516 density = ath9k_parse_mpdudensity(sta->ht_cap.ampdu_density);
1517 an->mpdudensity = density;
1518 }
1519
Felix Fietkau2800e822013-08-06 14:18:11 +02001520 /* force sequence number allocation for pending frames */
1521 ath_tx_tid_change_state(sc, txtid);
1522
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001523 txtid->active = true;
Felix Fietkau49447f22011-01-10 17:05:48 -07001524 *ssn = txtid->seq_start = txtid->seq_next;
Felix Fietkauf9437542011-12-14 22:08:08 +01001525 txtid->bar_index = -1;
Felix Fietkau231c3a12010-09-20 19:35:28 +02001526
Felix Fietkau2ed72222011-01-10 17:05:49 -07001527 memset(txtid->tx_buf, 0, sizeof(txtid->tx_buf));
1528 txtid->baw_head = txtid->baw_tail = 0;
1529
Felix Fietkau919123d2013-09-18 15:23:41 +02001530 ath_txq_unlock_complete(sc, txq);
1531
Felix Fietkau231c3a12010-09-20 19:35:28 +02001532 return 0;
Sujithe8324352009-01-16 21:38:42 +05301533}
1534
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001535void ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
Sujithe8324352009-01-16 21:38:42 +05301536{
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001537 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithe8324352009-01-16 21:38:42 +05301538 struct ath_node *an = (struct ath_node *)sta->drv_priv;
1539 struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid);
Felix Fietkau592fa222015-07-22 13:06:13 +02001540 struct ath_txq *txq = txtid->txq;
Sujithe8324352009-01-16 21:38:42 +05301541
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001542 ath_dbg(common, XMIT, "%s called\n", __func__);
1543
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001544 ath_txq_lock(sc, txq);
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001545 txtid->active = false;
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001546 ath_tx_flush_tid(sc, txtid);
Felix Fietkau2800e822013-08-06 14:18:11 +02001547 ath_tx_tid_change_state(sc, txtid);
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001548 ath_txq_unlock_complete(sc, txq);
Sujithe8324352009-01-16 21:38:42 +05301549}
1550
Johannes Berg042ec452011-09-29 16:04:26 +02001551void ath_tx_aggr_sleep(struct ieee80211_sta *sta, struct ath_softc *sc,
1552 struct ath_node *an)
Felix Fietkau55195412011-04-17 23:28:09 +02001553{
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001554 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau55195412011-04-17 23:28:09 +02001555 struct ath_atx_tid *tid;
Felix Fietkau55195412011-04-17 23:28:09 +02001556 struct ath_txq *txq;
Johannes Berg042ec452011-09-29 16:04:26 +02001557 bool buffered;
Felix Fietkau55195412011-04-17 23:28:09 +02001558 int tidno;
1559
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001560 ath_dbg(common, XMIT, "%s called\n", __func__);
1561
Felix Fietkau55195412011-04-17 23:28:09 +02001562 for (tidno = 0, tid = &an->tid[tidno];
Sujith Manoharande7b7602012-11-28 15:08:53 +05301563 tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
Felix Fietkau55195412011-04-17 23:28:09 +02001564
Felix Fietkau592fa222015-07-22 13:06:13 +02001565 txq = tid->txq;
Felix Fietkau55195412011-04-17 23:28:09 +02001566
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001567 ath_txq_lock(sc, txq);
Felix Fietkau55195412011-04-17 23:28:09 +02001568
Felix Fietkaud70d8482015-07-22 13:06:14 +02001569 if (list_empty(&tid->list)) {
Stanislaw Gruszka21f8aae2014-02-19 13:15:17 +01001570 ath_txq_unlock(sc, txq);
1571 continue;
1572 }
1573
Felix Fietkaua7586ee2013-08-06 14:18:02 +02001574 buffered = ath_tid_has_buffered(tid);
Felix Fietkau55195412011-04-17 23:28:09 +02001575
Felix Fietkaud70d8482015-07-22 13:06:14 +02001576 list_del_init(&tid->list);
Felix Fietkau55195412011-04-17 23:28:09 +02001577
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001578 ath_txq_unlock(sc, txq);
Felix Fietkau55195412011-04-17 23:28:09 +02001579
Johannes Berg042ec452011-09-29 16:04:26 +02001580 ieee80211_sta_set_buffered(sta, tidno, buffered);
1581 }
Felix Fietkau55195412011-04-17 23:28:09 +02001582}
1583
1584void ath_tx_aggr_wakeup(struct ath_softc *sc, struct ath_node *an)
1585{
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001586 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau55195412011-04-17 23:28:09 +02001587 struct ath_atx_tid *tid;
Felix Fietkau55195412011-04-17 23:28:09 +02001588 struct ath_txq *txq;
1589 int tidno;
1590
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001591 ath_dbg(common, XMIT, "%s called\n", __func__);
1592
Felix Fietkau55195412011-04-17 23:28:09 +02001593 for (tidno = 0, tid = &an->tid[tidno];
Sujith Manoharande7b7602012-11-28 15:08:53 +05301594 tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
Felix Fietkau55195412011-04-17 23:28:09 +02001595
Felix Fietkau592fa222015-07-22 13:06:13 +02001596 txq = tid->txq;
Felix Fietkau55195412011-04-17 23:28:09 +02001597
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001598 ath_txq_lock(sc, txq);
Felix Fietkau592fa222015-07-22 13:06:13 +02001599 tid->clear_ps_filter = true;
Felix Fietkau55195412011-04-17 23:28:09 +02001600
Felix Fietkau62e54dbb2014-04-28 18:32:12 +02001601 if (ath_tid_has_buffered(tid)) {
Felix Fietkau04535312014-06-11 16:17:51 +05301602 ath_tx_queue_tid(sc, txq, tid);
Felix Fietkau55195412011-04-17 23:28:09 +02001603 ath_txq_schedule(sc, txq);
1604 }
1605
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001606 ath_txq_unlock_complete(sc, txq);
Felix Fietkau55195412011-04-17 23:28:09 +02001607 }
1608}
1609
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001610void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta,
1611 u16 tidno)
Sujithe8324352009-01-16 21:38:42 +05301612{
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001613 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001614 struct ath_atx_tid *tid;
Sujithe8324352009-01-16 21:38:42 +05301615 struct ath_node *an;
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001616 struct ath_txq *txq;
Sujithe8324352009-01-16 21:38:42 +05301617
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001618 ath_dbg(common, XMIT, "%s called\n", __func__);
1619
Sujithe8324352009-01-16 21:38:42 +05301620 an = (struct ath_node *)sta->drv_priv;
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001621 tid = ATH_AN_2_TID(an, tidno);
Felix Fietkau592fa222015-07-22 13:06:13 +02001622 txq = tid->txq;
Sujithe8324352009-01-16 21:38:42 +05301623
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001624 ath_txq_lock(sc, txq);
1625
1626 tid->baw_size = IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001627
Felix Fietkaua7586ee2013-08-06 14:18:02 +02001628 if (ath_tid_has_buffered(tid)) {
Felix Fietkau04535312014-06-11 16:17:51 +05301629 ath_tx_queue_tid(sc, txq, tid);
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001630 ath_txq_schedule(sc, txq);
1631 }
1632
1633 ath_txq_unlock_complete(sc, txq);
Sujithe8324352009-01-16 21:38:42 +05301634}
1635
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001636void ath9k_release_buffered_frames(struct ieee80211_hw *hw,
1637 struct ieee80211_sta *sta,
1638 u16 tids, int nframes,
1639 enum ieee80211_frame_release_type reason,
1640 bool more_data)
1641{
1642 struct ath_softc *sc = hw->priv;
1643 struct ath_node *an = (struct ath_node *)sta->drv_priv;
1644 struct ath_txq *txq = sc->tx.uapsdq;
1645 struct ieee80211_tx_info *info;
1646 struct list_head bf_q;
1647 struct ath_buf *bf_tail = NULL, *bf;
Felix Fietkaua7586ee2013-08-06 14:18:02 +02001648 struct sk_buff_head *tid_q;
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001649 int sent = 0;
1650 int i;
1651
1652 INIT_LIST_HEAD(&bf_q);
1653 for (i = 0; tids && nframes; i++, tids >>= 1) {
1654 struct ath_atx_tid *tid;
1655
1656 if (!(tids & 1))
1657 continue;
1658
1659 tid = ATH_AN_2_TID(an, i);
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001660
Felix Fietkau592fa222015-07-22 13:06:13 +02001661 ath_txq_lock(sc, tid->txq);
Felix Fietkaua7586ee2013-08-06 14:18:02 +02001662 while (nframes > 0) {
1663 bf = ath_tx_get_tid_subframe(sc, sc->tx.uapsdq, tid, &tid_q);
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001664 if (!bf)
1665 break;
1666
Felix Fietkaua7586ee2013-08-06 14:18:02 +02001667 __skb_unlink(bf->bf_mpdu, tid_q);
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001668 list_add_tail(&bf->list, &bf_q);
1669 ath_set_rates(tid->an->vif, tid->an->sta, bf);
Felix Fietkau20e6e552013-09-17 12:05:15 +02001670 if (bf_isampdu(bf)) {
1671 ath_tx_addto_baw(sc, tid, bf);
1672 bf->bf_state.bf_type &= ~BUF_AGGR;
1673 }
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001674 if (bf_tail)
1675 bf_tail->bf_next = bf;
1676
1677 bf_tail = bf;
1678 nframes--;
1679 sent++;
1680 TX_STAT_INC(txq->axq_qnum, a_queued_hw);
1681
Felix Fietkauf89d1bc2013-08-06 14:18:13 +02001682 if (an->sta && !ath_tid_has_buffered(tid))
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001683 ieee80211_sta_set_buffered(an->sta, i, false);
1684 }
Felix Fietkau592fa222015-07-22 13:06:13 +02001685 ath_txq_unlock_complete(sc, tid->txq);
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001686 }
1687
1688 if (list_empty(&bf_q))
1689 return;
1690
1691 info = IEEE80211_SKB_CB(bf_tail->bf_mpdu);
1692 info->flags |= IEEE80211_TX_STATUS_EOSP;
1693
1694 bf = list_first_entry(&bf_q, struct ath_buf, list);
1695 ath_txq_lock(sc, txq);
1696 ath_tx_fill_desc(sc, bf, txq, 0);
1697 ath_tx_txqaddbuf(sc, txq, &bf_q, false);
1698 ath_txq_unlock(sc, txq);
1699}
1700
Sujithe8324352009-01-16 21:38:42 +05301701/********************/
1702/* Queue Management */
1703/********************/
1704
Sujithe8324352009-01-16 21:38:42 +05301705struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype)
1706{
Sujithcbe61d82009-02-09 13:27:12 +05301707 struct ath_hw *ah = sc->sc_ah;
Sujithe8324352009-01-16 21:38:42 +05301708 struct ath9k_tx_queue_info qi;
Felix Fietkau066dae92010-11-07 14:59:39 +01001709 static const int subtype_txq_to_hwq[] = {
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301710 [IEEE80211_AC_BE] = ATH_TXQ_AC_BE,
1711 [IEEE80211_AC_BK] = ATH_TXQ_AC_BK,
1712 [IEEE80211_AC_VI] = ATH_TXQ_AC_VI,
1713 [IEEE80211_AC_VO] = ATH_TXQ_AC_VO,
Felix Fietkau066dae92010-11-07 14:59:39 +01001714 };
Ben Greear60f2d1d2011-01-09 23:11:52 -08001715 int axq_qnum, i;
Sujithe8324352009-01-16 21:38:42 +05301716
1717 memset(&qi, 0, sizeof(qi));
Felix Fietkau066dae92010-11-07 14:59:39 +01001718 qi.tqi_subtype = subtype_txq_to_hwq[subtype];
Sujithe8324352009-01-16 21:38:42 +05301719 qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT;
1720 qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
1721 qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT;
1722 qi.tqi_physCompBuf = 0;
1723
1724 /*
1725 * Enable interrupts only for EOL and DESC conditions.
1726 * We mark tx descriptors to receive a DESC interrupt
1727 * when a tx queue gets deep; otherwise waiting for the
1728 * EOL to reap descriptors. Note that this is done to
1729 * reduce interrupt load and this only defers reaping
1730 * descriptors, never transmitting frames. Aside from
1731 * reducing interrupts this also permits more concurrency.
1732 * The only potential downside is if the tx queue backs
1733 * up in which case the top half of the kernel may backup
1734 * due to a lack of tx descriptors.
1735 *
1736 * The UAPSD queue is an exception, since we take a desc-
1737 * based intr on the EOSP frames.
1738 */
Vasanthakumar Thiagarajanafe754d2010-04-15 17:39:40 -04001739 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
Felix Fietkauce8fdf62012-03-14 16:40:22 +01001740 qi.tqi_qflags = TXQ_FLAG_TXINT_ENABLE;
Vasanthakumar Thiagarajanafe754d2010-04-15 17:39:40 -04001741 } else {
1742 if (qtype == ATH9K_TX_QUEUE_UAPSD)
1743 qi.tqi_qflags = TXQ_FLAG_TXDESCINT_ENABLE;
1744 else
1745 qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE |
1746 TXQ_FLAG_TXDESCINT_ENABLE;
1747 }
Ben Greear60f2d1d2011-01-09 23:11:52 -08001748 axq_qnum = ath9k_hw_setuptxqueue(ah, qtype, &qi);
1749 if (axq_qnum == -1) {
Sujithe8324352009-01-16 21:38:42 +05301750 /*
1751 * NB: don't print a message, this happens
1752 * normally on parts with too few tx queues
1753 */
1754 return NULL;
1755 }
Ben Greear60f2d1d2011-01-09 23:11:52 -08001756 if (!ATH_TXQ_SETUP(sc, axq_qnum)) {
1757 struct ath_txq *txq = &sc->tx.txq[axq_qnum];
Sujithe8324352009-01-16 21:38:42 +05301758
Ben Greear60f2d1d2011-01-09 23:11:52 -08001759 txq->axq_qnum = axq_qnum;
1760 txq->mac80211_qnum = -1;
Sujithe8324352009-01-16 21:38:42 +05301761 txq->axq_link = NULL;
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001762 __skb_queue_head_init(&txq->complete_q);
Sujithe8324352009-01-16 21:38:42 +05301763 INIT_LIST_HEAD(&txq->axq_q);
Sujithe8324352009-01-16 21:38:42 +05301764 spin_lock_init(&txq->axq_lock);
1765 txq->axq_depth = 0;
Felix Fietkau4b3ba662010-12-17 00:57:00 +01001766 txq->axq_ampdu_depth = 0;
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04001767 txq->axq_tx_inprogress = false;
Ben Greear60f2d1d2011-01-09 23:11:52 -08001768 sc->tx.txqsetup |= 1<<axq_qnum;
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04001769
1770 txq->txq_headidx = txq->txq_tailidx = 0;
1771 for (i = 0; i < ATH_TXFIFO_DEPTH; i++)
1772 INIT_LIST_HEAD(&txq->txq_fifo[i]);
Sujithe8324352009-01-16 21:38:42 +05301773 }
Ben Greear60f2d1d2011-01-09 23:11:52 -08001774 return &sc->tx.txq[axq_qnum];
Sujithe8324352009-01-16 21:38:42 +05301775}
1776
Sujithe8324352009-01-16 21:38:42 +05301777int ath_txq_update(struct ath_softc *sc, int qnum,
1778 struct ath9k_tx_queue_info *qinfo)
1779{
Sujithcbe61d82009-02-09 13:27:12 +05301780 struct ath_hw *ah = sc->sc_ah;
Sujithe8324352009-01-16 21:38:42 +05301781 int error = 0;
1782 struct ath9k_tx_queue_info qi;
1783
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07001784 BUG_ON(sc->tx.txq[qnum].axq_qnum != qnum);
Sujithe8324352009-01-16 21:38:42 +05301785
1786 ath9k_hw_get_txq_props(ah, qnum, &qi);
1787 qi.tqi_aifs = qinfo->tqi_aifs;
1788 qi.tqi_cwmin = qinfo->tqi_cwmin;
1789 qi.tqi_cwmax = qinfo->tqi_cwmax;
1790 qi.tqi_burstTime = qinfo->tqi_burstTime;
1791 qi.tqi_readyTime = qinfo->tqi_readyTime;
1792
1793 if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
Joe Perches38002762010-12-02 19:12:36 -08001794 ath_err(ath9k_hw_common(sc->sc_ah),
1795 "Unable to update hardware queue %u!\n", qnum);
Sujithe8324352009-01-16 21:38:42 +05301796 error = -EIO;
1797 } else {
1798 ath9k_hw_resettxqueue(ah, qnum);
1799 }
1800
1801 return error;
1802}
1803
1804int ath_cabq_update(struct ath_softc *sc)
1805{
1806 struct ath9k_tx_queue_info qi;
Rajkumar Manoharanca900ac2014-06-11 16:18:02 +05301807 struct ath_beacon_config *cur_conf = &sc->cur_chan->beacon;
Sujithe8324352009-01-16 21:38:42 +05301808 int qnum = sc->beacon.cabq->axq_qnum;
Sujithe8324352009-01-16 21:38:42 +05301809
1810 ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi);
Sujithe8324352009-01-16 21:38:42 +05301811
Felix Fietkau3b3e0ef2014-03-09 11:02:54 +01001812 qi.tqi_readyTime = (TU_TO_USEC(cur_conf->beacon_interval) *
Felix Fietkau7f329bb2013-10-11 23:30:59 +02001813 ATH_CABQ_READY_TIME) / 100;
Sujithe8324352009-01-16 21:38:42 +05301814 ath_txq_update(sc, qnum, &qi);
1815
1816 return 0;
1817}
1818
Felix Fietkaufce041b2011-05-19 12:20:25 +02001819static void ath_drain_txq_list(struct ath_softc *sc, struct ath_txq *txq,
Felix Fietkau13815592013-01-20 18:51:53 +01001820 struct list_head *list)
Sujithe8324352009-01-16 21:38:42 +05301821{
1822 struct ath_buf *bf, *lastbf;
1823 struct list_head bf_head;
Felix Fietkaudb1a0522010-03-29 20:07:11 -07001824 struct ath_tx_status ts;
1825
1826 memset(&ts, 0, sizeof(ts));
Felix Fietkaudaa5c402011-10-07 02:28:15 +02001827 ts.ts_status = ATH9K_TX_FLUSH;
Sujithe8324352009-01-16 21:38:42 +05301828 INIT_LIST_HEAD(&bf_head);
1829
Felix Fietkaufce041b2011-05-19 12:20:25 +02001830 while (!list_empty(list)) {
1831 bf = list_first_entry(list, struct ath_buf, list);
Sujithe8324352009-01-16 21:38:42 +05301832
Felix Fietkau50676b82013-08-10 15:59:16 +02001833 if (bf->bf_state.stale) {
Felix Fietkaufce041b2011-05-19 12:20:25 +02001834 list_del(&bf->list);
Sujithe8324352009-01-16 21:38:42 +05301835
Felix Fietkaufce041b2011-05-19 12:20:25 +02001836 ath_tx_return_buffer(sc, bf);
1837 continue;
Sujithe8324352009-01-16 21:38:42 +05301838 }
1839
1840 lastbf = bf->bf_lastbf;
Felix Fietkaufce041b2011-05-19 12:20:25 +02001841 list_cut_position(&bf_head, list, &lastbf->list);
Felix Fietkau81b51952013-01-20 18:51:54 +01001842 ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04001843 }
Felix Fietkaufce041b2011-05-19 12:20:25 +02001844}
1845
1846/*
1847 * Drain a given TX queue (could be Beacon or Data)
1848 *
1849 * This assumes output has been stopped and
1850 * we do not need to block ath_tx_tasklet.
1851 */
Felix Fietkau13815592013-01-20 18:51:53 +01001852void ath_draintxq(struct ath_softc *sc, struct ath_txq *txq)
Felix Fietkaufce041b2011-05-19 12:20:25 +02001853{
Felix Fietkaud94a4612016-09-02 19:46:12 +03001854 rcu_read_lock();
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001855 ath_txq_lock(sc, txq);
1856
Felix Fietkaufce041b2011-05-19 12:20:25 +02001857 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
1858 int idx = txq->txq_tailidx;
1859
1860 while (!list_empty(&txq->txq_fifo[idx])) {
Felix Fietkau13815592013-01-20 18:51:53 +01001861 ath_drain_txq_list(sc, txq, &txq->txq_fifo[idx]);
Felix Fietkaufce041b2011-05-19 12:20:25 +02001862
1863 INCR(idx, ATH_TXFIFO_DEPTH);
1864 }
1865 txq->txq_tailidx = idx;
1866 }
1867
1868 txq->axq_link = NULL;
1869 txq->axq_tx_inprogress = false;
Felix Fietkau13815592013-01-20 18:51:53 +01001870 ath_drain_txq_list(sc, txq, &txq->axq_q);
Felix Fietkaufce041b2011-05-19 12:20:25 +02001871
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001872 ath_txq_unlock_complete(sc, txq);
Felix Fietkaud94a4612016-09-02 19:46:12 +03001873 rcu_read_unlock();
Sujithe8324352009-01-16 21:38:42 +05301874}
1875
Felix Fietkau13815592013-01-20 18:51:53 +01001876bool ath_drain_all_txq(struct ath_softc *sc)
Sujith043a0402009-01-16 21:38:47 +05301877{
Sujithcbe61d82009-02-09 13:27:12 +05301878 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001879 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith043a0402009-01-16 21:38:47 +05301880 struct ath_txq *txq;
Felix Fietkau34d25812011-10-07 02:28:12 +02001881 int i;
1882 u32 npend = 0;
Sujith043a0402009-01-16 21:38:47 +05301883
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01001884 if (test_bit(ATH_OP_INVALID, &common->op_flags))
Felix Fietkau080e1a22010-12-05 20:17:53 +01001885 return true;
Sujith043a0402009-01-16 21:38:47 +05301886
Felix Fietkau0d51ccc2011-03-11 21:38:18 +01001887 ath9k_hw_abort_tx_dma(ah);
Sujith043a0402009-01-16 21:38:47 +05301888
Felix Fietkau0d51ccc2011-03-11 21:38:18 +01001889 /* Check if any queue remains active */
Sujith043a0402009-01-16 21:38:47 +05301890 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
Felix Fietkau0d51ccc2011-03-11 21:38:18 +01001891 if (!ATH_TXQ_SETUP(sc, i))
1892 continue;
1893
Felix Fietkau10ffb6a2013-11-11 22:23:34 +01001894 if (!sc->tx.txq[i].axq_depth)
1895 continue;
1896
Felix Fietkau34d25812011-10-07 02:28:12 +02001897 if (ath9k_hw_numtxpending(ah, sc->tx.txq[i].axq_qnum))
1898 npend |= BIT(i);
Sujith043a0402009-01-16 21:38:47 +05301899 }
1900
Felix Fietkaue60ac9c2015-07-02 13:40:29 +02001901 if (npend) {
1902 RESET_STAT_INC(sc, RESET_TX_DMA_ERROR);
1903 ath_dbg(common, RESET,
1904 "Failed to stop TX DMA, queues=0x%03x!\n", npend);
1905 }
Sujith043a0402009-01-16 21:38:47 +05301906
1907 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
Felix Fietkau92460412011-01-24 19:23:14 +01001908 if (!ATH_TXQ_SETUP(sc, i))
1909 continue;
1910
1911 /*
1912 * The caller will resume queues with ieee80211_wake_queues.
1913 * Mark the queue as not stopped to prevent ath_tx_complete
1914 * from waking the queue too early.
1915 */
1916 txq = &sc->tx.txq[i];
1917 txq->stopped = false;
Felix Fietkau13815592013-01-20 18:51:53 +01001918 ath_draintxq(sc, txq);
Sujith043a0402009-01-16 21:38:47 +05301919 }
Felix Fietkau080e1a22010-12-05 20:17:53 +01001920
1921 return !npend;
Sujith043a0402009-01-16 21:38:47 +05301922}
1923
Sujithe8324352009-01-16 21:38:42 +05301924void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq)
1925{
1926 ath9k_hw_releasetxqueue(sc->sc_ah, txq->axq_qnum);
1927 sc->tx.txqsetup &= ~(1<<txq->axq_qnum);
1928}
1929
Felix Fietkau04535312014-06-11 16:17:51 +05301930/* For each acq entry, for each tid, try to schedule packets
Ben Greear7755bad2011-01-18 17:30:00 -08001931 * for transmit until ampdu_depth has reached min Q depth.
1932 */
Sujithe8324352009-01-16 21:38:42 +05301933void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
1934{
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01001935 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Ben Greear7755bad2011-01-18 17:30:00 -08001936 struct ath_atx_tid *tid, *last_tid;
Felix Fietkau592fa222015-07-22 13:06:13 +02001937 struct list_head *tid_list;
Felix Fietkau020f20f2013-08-06 14:18:12 +02001938 bool sent = false;
Sujithe8324352009-01-16 21:38:42 +05301939
Felix Fietkau04535312014-06-11 16:17:51 +05301940 if (txq->mac80211_qnum < 0)
1941 return;
1942
Sujith Manoharan4d9f6342014-09-30 14:15:23 +05301943 if (test_bit(ATH_OP_HW_RESET, &common->op_flags))
Sujithe8324352009-01-16 21:38:42 +05301944 return;
1945
Felix Fietkaubff11762014-06-11 16:17:52 +05301946 spin_lock_bh(&sc->chan_lock);
Felix Fietkau592fa222015-07-22 13:06:13 +02001947 tid_list = &sc->cur_chan->acq[txq->mac80211_qnum];
Sujith Manoharan4d9f6342014-09-30 14:15:23 +05301948
Felix Fietkau592fa222015-07-22 13:06:13 +02001949 if (list_empty(tid_list)) {
Sujith Manoharan4d9f6342014-09-30 14:15:23 +05301950 spin_unlock_bh(&sc->chan_lock);
1951 return;
1952 }
1953
Felix Fietkau23bc2022013-06-22 12:39:26 +02001954 rcu_read_lock();
1955
Felix Fietkau592fa222015-07-22 13:06:13 +02001956 last_tid = list_entry(tid_list->prev, struct ath_atx_tid, list);
1957 while (!list_empty(tid_list)) {
Felix Fietkau020f20f2013-08-06 14:18:12 +02001958 bool stop = false;
Sujithe8324352009-01-16 21:38:42 +05301959
Felix Fietkaubff11762014-06-11 16:17:52 +05301960 if (sc->cur_chan->stopped)
1961 break;
1962
Felix Fietkau592fa222015-07-22 13:06:13 +02001963 tid = list_first_entry(tid_list, struct ath_atx_tid, list);
Felix Fietkaud70d8482015-07-22 13:06:14 +02001964 list_del_init(&tid->list);
Sujithe8324352009-01-16 21:38:42 +05301965
Felix Fietkau592fa222015-07-22 13:06:13 +02001966 if (ath_tx_sched_aggr(sc, txq, tid, &stop))
1967 sent = true;
Felix Fietkau020f20f2013-08-06 14:18:12 +02001968
Felix Fietkau592fa222015-07-22 13:06:13 +02001969 /*
1970 * add tid to round-robin queue if more frames
1971 * are pending for the tid
1972 */
1973 if (ath_tid_has_buffered(tid))
1974 ath_tx_queue_tid(sc, txq, tid);
Ben Greear7755bad2011-01-18 17:30:00 -08001975
Felix Fietkau020f20f2013-08-06 14:18:12 +02001976 if (stop)
Felix Fietkau23bc2022013-06-22 12:39:26 +02001977 break;
Felix Fietkau020f20f2013-08-06 14:18:12 +02001978
Felix Fietkau592fa222015-07-22 13:06:13 +02001979 if (tid == last_tid) {
Felix Fietkau020f20f2013-08-06 14:18:12 +02001980 if (!sent)
1981 break;
1982
1983 sent = false;
Felix Fietkau592fa222015-07-22 13:06:13 +02001984 last_tid = list_entry(tid_list->prev,
1985 struct ath_atx_tid, list);
Felix Fietkau020f20f2013-08-06 14:18:12 +02001986 }
Sujithe8324352009-01-16 21:38:42 +05301987 }
Felix Fietkau23bc2022013-06-22 12:39:26 +02001988
1989 rcu_read_unlock();
Felix Fietkaubff11762014-06-11 16:17:52 +05301990 spin_unlock_bh(&sc->chan_lock);
Sujithe8324352009-01-16 21:38:42 +05301991}
1992
Felix Fietkau04535312014-06-11 16:17:51 +05301993void ath_txq_schedule_all(struct ath_softc *sc)
1994{
1995 struct ath_txq *txq;
1996 int i;
1997
1998 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
1999 txq = sc->tx.txq_map[i];
2000
2001 spin_lock_bh(&txq->axq_lock);
2002 ath_txq_schedule(sc, txq);
2003 spin_unlock_bh(&txq->axq_lock);
2004 }
2005}
2006
Sujithe8324352009-01-16 21:38:42 +05302007/***********/
2008/* TX, DMA */
2009/***********/
2010
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002011/*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002012 * Insert a chain of ath_buf (descriptors) on a txq and
2013 * assume the descriptors are already chained together by caller.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002014 */
Sujith102e0572008-10-29 10:15:16 +05302015static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
Felix Fietkaufce041b2011-05-19 12:20:25 +02002016 struct list_head *head, bool internal)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002017{
Sujithcbe61d82009-02-09 13:27:12 +05302018 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002019 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkaufce041b2011-05-19 12:20:25 +02002020 struct ath_buf *bf, *bf_last;
2021 bool puttxbuf = false;
2022 bool edma;
Sujith102e0572008-10-29 10:15:16 +05302023
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002024 /*
2025 * Insert the frame on the outbound list and
2026 * pass it on to the hardware.
2027 */
2028
2029 if (list_empty(head))
2030 return;
2031
Felix Fietkaufce041b2011-05-19 12:20:25 +02002032 edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002033 bf = list_first_entry(head, struct ath_buf, list);
Felix Fietkaufce041b2011-05-19 12:20:25 +02002034 bf_last = list_entry(head->prev, struct ath_buf, list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002035
Joe Perchesd2182b62011-12-15 14:55:53 -08002036 ath_dbg(common, QUEUE, "qnum: %d, txq depth: %d\n",
2037 txq->axq_qnum, txq->axq_depth);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002038
Felix Fietkaufce041b2011-05-19 12:20:25 +02002039 if (edma && list_empty(&txq->txq_fifo[txq->txq_headidx])) {
2040 list_splice_tail_init(head, &txq->txq_fifo[txq->txq_headidx]);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002041 INCR(txq->txq_headidx, ATH_TXFIFO_DEPTH);
Felix Fietkaufce041b2011-05-19 12:20:25 +02002042 puttxbuf = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002043 } else {
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002044 list_splice_tail_init(head, &txq->axq_q);
2045
Felix Fietkaufce041b2011-05-19 12:20:25 +02002046 if (txq->axq_link) {
2047 ath9k_hw_set_desc_link(ah, txq->axq_link, bf->bf_daddr);
Joe Perchesd2182b62011-12-15 14:55:53 -08002048 ath_dbg(common, XMIT, "link[%u] (%p)=%llx (%p)\n",
Joe Perches226afe62010-12-02 19:12:37 -08002049 txq->axq_qnum, txq->axq_link,
2050 ito64(bf->bf_daddr), bf->bf_desc);
Felix Fietkaufce041b2011-05-19 12:20:25 +02002051 } else if (!edma)
2052 puttxbuf = true;
2053
2054 txq->axq_link = bf_last->bf_desc;
2055 }
2056
2057 if (puttxbuf) {
2058 TX_STAT_INC(txq->axq_qnum, puttxbuf);
2059 ath9k_hw_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr);
Joe Perchesd2182b62011-12-15 14:55:53 -08002060 ath_dbg(common, XMIT, "TXDP[%u] = %llx (%p)\n",
Felix Fietkaufce041b2011-05-19 12:20:25 +02002061 txq->axq_qnum, ito64(bf->bf_daddr), bf->bf_desc);
2062 }
2063
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07002064 if (!edma || sc->tx99_state) {
Felix Fietkau8d8d3fd2011-01-24 19:11:54 +01002065 TX_STAT_INC(txq->axq_qnum, txstart);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002066 ath9k_hw_txstart(ah, txq->axq_qnum);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002067 }
Felix Fietkaufce041b2011-05-19 12:20:25 +02002068
2069 if (!internal) {
Felix Fietkauf56e1212013-06-20 15:11:31 +02002070 while (bf) {
2071 txq->axq_depth++;
2072 if (bf_is_ampdu_not_probing(bf))
2073 txq->axq_ampdu_depth++;
2074
Felix Fietkau440c1c82013-09-14 17:02:29 +02002075 bf_last = bf->bf_lastbf;
2076 bf = bf_last->bf_next;
2077 bf_last->bf_next = NULL;
Felix Fietkauf56e1212013-06-20 15:11:31 +02002078 }
Felix Fietkaufce041b2011-05-19 12:20:25 +02002079 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002080}
2081
Felix Fietkau82b873a2010-11-11 03:18:37 +01002082static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
Felix Fietkau44f1d262011-08-28 00:32:25 +02002083 struct ath_atx_tid *tid, struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002084{
Felix Fietkauf69727f2013-09-29 13:06:31 +02002085 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau44f1d262011-08-28 00:32:25 +02002086 struct ath_frame_info *fi = get_frame_info(skb);
2087 struct list_head bf_head;
Felix Fietkauf69727f2013-09-29 13:06:31 +02002088 struct ath_buf *bf = fi->bf;
Felix Fietkau44f1d262011-08-28 00:32:25 +02002089
2090 INIT_LIST_HEAD(&bf_head);
2091 list_add_tail(&bf->list, &bf_head);
Felix Fietkau399c6482011-09-14 21:24:17 +02002092 bf->bf_state.bf_type = 0;
Felix Fietkauf69727f2013-09-29 13:06:31 +02002093 if (tid && (tx_info->flags & IEEE80211_TX_CTL_AMPDU)) {
2094 bf->bf_state.bf_type = BUF_AMPDU;
2095 ath_tx_addto_baw(sc, tid, bf);
2096 }
Sujithe8324352009-01-16 21:38:42 +05302097
Felix Fietkau8c6e3092012-10-26 00:31:11 +02002098 bf->bf_next = NULL;
Sujithd43f30152009-01-16 21:38:53 +05302099 bf->bf_lastbf = bf;
Felix Fietkau493cf042011-09-14 21:24:22 +02002100 ath_tx_fill_desc(sc, bf, txq, fi->framelen);
Felix Fietkau44f1d262011-08-28 00:32:25 +02002101 ath_tx_txqaddbuf(sc, txq, &bf_head, false);
Sujithfec247c2009-07-27 12:08:16 +05302102 TX_STAT_INC(txq->axq_qnum, queued);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002103}
2104
Thomas Huehn36323f82012-07-23 21:33:42 +02002105static void setup_frame_info(struct ieee80211_hw *hw,
2106 struct ieee80211_sta *sta,
2107 struct sk_buff *skb,
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002108 int framelen)
Sujith528f0c62008-10-29 10:14:26 +05302109{
2110 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002111 struct ieee80211_key_conf *hw_key = tx_info->control.hw_key;
Felix Fietkau6a0ddae2011-08-28 00:32:23 +02002112 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Felix Fietkau80b08a82012-06-15 03:04:53 +02002113 const struct ieee80211_rate *rate;
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002114 struct ath_frame_info *fi = get_frame_info(skb);
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02002115 struct ath_node *an = NULL;
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002116 enum ath9k_key_type keytype;
Felix Fietkau80b08a82012-06-15 03:04:53 +02002117 bool short_preamble = false;
Lorenzo Bianconif6738212015-04-08 20:51:57 +02002118 u8 txpower;
Sujith528f0c62008-10-29 10:14:26 +05302119
Felix Fietkau80b08a82012-06-15 03:04:53 +02002120 /*
2121 * We check if Short Preamble is needed for the CTS rate by
2122 * checking the BSS's global flag.
2123 * But for the rate series, IEEE80211_TX_RC_USE_SHORT_PREAMBLE is used.
2124 */
2125 if (tx_info->control.vif &&
2126 tx_info->control.vif->bss_conf.use_short_preamble)
2127 short_preamble = true;
2128
2129 rate = ieee80211_get_rts_cts_rate(hw, tx_info);
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002130 keytype = ath9k_cmn_get_hw_crypto_keytype(skb);
Sujith528f0c62008-10-29 10:14:26 +05302131
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02002132 if (sta)
2133 an = (struct ath_node *) sta->drv_priv;
2134
Lorenzo Bianconif6738212015-04-08 20:51:57 +02002135 if (tx_info->control.vif) {
2136 struct ieee80211_vif *vif = tx_info->control.vif;
2137
2138 txpower = 2 * vif->bss_conf.txpower;
2139 } else {
2140 struct ath_softc *sc = hw->priv;
2141
2142 txpower = sc->cur_chan->cur_txpower;
2143 }
2144
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002145 memset(fi, 0, sizeof(*fi));
Felix Fietkaud954cd772014-07-16 20:26:05 +02002146 fi->txq = -1;
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002147 if (hw_key)
2148 fi->keyix = hw_key->hw_key_idx;
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02002149 else if (an && ieee80211_is_data(hdr->frame_control) && an->ps_key > 0)
2150 fi->keyix = an->ps_key;
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002151 else
2152 fi->keyix = ATH9K_TXKEYIX_INVALID;
2153 fi->keytype = keytype;
2154 fi->framelen = framelen;
Lorenzo Bianconif6738212015-04-08 20:51:57 +02002155 fi->tx_power = txpower;
Luis R. Rodriguez09b029b2013-10-14 17:42:10 -07002156
2157 if (!rate)
2158 return;
Felix Fietkau80b08a82012-06-15 03:04:53 +02002159 fi->rtscts_rate = rate->hw_value;
2160 if (short_preamble)
2161 fi->rtscts_rate |= rate->hw_value_short;
Sujith528f0c62008-10-29 10:14:26 +05302162}
2163
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +05302164u8 ath_txchainmask_reduction(struct ath_softc *sc, u8 chainmask, u32 rate)
2165{
2166 struct ath_hw *ah = sc->sc_ah;
2167 struct ath9k_channel *curchan = ah->curchan;
Sujith Manoharan365d2eb2012-09-26 12:22:08 +05302168
Felix Fietkau88969342013-10-11 23:30:53 +02002169 if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && IS_CHAN_5GHZ(curchan) &&
Rajkumar Manoharand77bf3e2011-08-13 10:28:14 +05302170 (chainmask == 0x7) && (rate < 0x90))
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +05302171 return 0x3;
Sujith Manoharan365d2eb2012-09-26 12:22:08 +05302172 else if (AR_SREV_9462(ah) && ath9k_hw_btcoex_is_enabled(ah) &&
2173 IS_CCK_RATE(rate))
2174 return 0x2;
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +05302175 else
2176 return chainmask;
2177}
2178
Felix Fietkau44f1d262011-08-28 00:32:25 +02002179/*
2180 * Assign a descriptor (and sequence number if necessary,
2181 * and map buffer for DMA. Frees skb on error
2182 */
Felix Fietkaufa05f872011-08-28 00:32:24 +02002183static struct ath_buf *ath_tx_setup_buffer(struct ath_softc *sc,
Felix Fietkau04caf862010-11-14 15:20:12 +01002184 struct ath_txq *txq,
Felix Fietkaufa05f872011-08-28 00:32:24 +02002185 struct ath_atx_tid *tid,
Felix Fietkau249ee722012-10-03 21:07:52 +02002186 struct sk_buff *skb)
Sujithe8324352009-01-16 21:38:42 +05302187{
Felix Fietkau82b873a2010-11-11 03:18:37 +01002188 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002189 struct ath_frame_info *fi = get_frame_info(skb);
Felix Fietkaufa05f872011-08-28 00:32:24 +02002190 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Felix Fietkau82b873a2010-11-11 03:18:37 +01002191 struct ath_buf *bf;
Sujith Manoharanfd09c852012-04-17 08:34:50 +05302192 int fragno;
Felix Fietkaufa05f872011-08-28 00:32:24 +02002193 u16 seqno;
Felix Fietkau82b873a2010-11-11 03:18:37 +01002194
2195 bf = ath_tx_get_buffer(sc);
2196 if (!bf) {
Joe Perchesd2182b62011-12-15 14:55:53 -08002197 ath_dbg(common, XMIT, "TX buffers are full\n");
Felix Fietkau249ee722012-10-03 21:07:52 +02002198 return NULL;
Felix Fietkau82b873a2010-11-11 03:18:37 +01002199 }
Sujithe8324352009-01-16 21:38:42 +05302200
Sujithe8324352009-01-16 21:38:42 +05302201 ATH_TXBUF_RESET(bf);
2202
Helmut Schaa5998be82014-03-12 10:37:55 +01002203 if (tid && ieee80211_is_data_present(hdr->frame_control)) {
Sujith Manoharanfd09c852012-04-17 08:34:50 +05302204 fragno = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
Felix Fietkaufa05f872011-08-28 00:32:24 +02002205 seqno = tid->seq_next;
2206 hdr->seq_ctrl = cpu_to_le16(tid->seq_next << IEEE80211_SEQ_SEQ_SHIFT);
Sujith Manoharanfd09c852012-04-17 08:34:50 +05302207
2208 if (fragno)
2209 hdr->seq_ctrl |= cpu_to_le16(fragno);
2210
2211 if (!ieee80211_has_morefrags(hdr->frame_control))
2212 INCR(tid->seq_next, IEEE80211_SEQ_MAX);
2213
Felix Fietkaufa05f872011-08-28 00:32:24 +02002214 bf->bf_state.seqno = seqno;
2215 }
2216
Sujithe8324352009-01-16 21:38:42 +05302217 bf->bf_mpdu = skb;
2218
Ben Greearc1739eb32010-10-14 12:45:29 -07002219 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
2220 skb->len, DMA_TO_DEVICE);
2221 if (unlikely(dma_mapping_error(sc->dev, bf->bf_buf_addr))) {
Sujithe8324352009-01-16 21:38:42 +05302222 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -07002223 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -08002224 ath_err(ath9k_hw_common(sc->sc_ah),
2225 "dma_mapping_error() on TX\n");
Felix Fietkau82b873a2010-11-11 03:18:37 +01002226 ath_tx_return_buffer(sc, bf);
Felix Fietkau249ee722012-10-03 21:07:52 +02002227 return NULL;
Sujithe8324352009-01-16 21:38:42 +05302228 }
2229
Felix Fietkau56dc6332011-08-28 00:32:22 +02002230 fi->bf = bf;
Felix Fietkau04caf862010-11-14 15:20:12 +01002231
2232 return bf;
2233}
2234
Sujith Manoharanca144052014-10-08 08:43:19 +05302235void ath_assign_seq(struct ath_common *common, struct sk_buff *skb)
2236{
2237 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2238 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2239 struct ieee80211_vif *vif = info->control.vif;
2240 struct ath_vif *avp;
2241
2242 if (!(info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ))
2243 return;
2244
2245 if (!vif)
2246 return;
2247
2248 avp = (struct ath_vif *)vif->drv_priv;
2249
2250 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
2251 avp->seq_no += 0x10;
2252
2253 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
2254 hdr->seq_ctrl |= cpu_to_le16(avp->seq_no);
2255}
2256
Felix Fietkau59505c02013-06-07 18:12:02 +02002257static int ath_tx_prepare(struct ieee80211_hw *hw, struct sk_buff *skb,
2258 struct ath_tx_control *txctl)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002259{
Felix Fietkau28d16702010-11-14 15:20:10 +01002260 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2261 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Thomas Huehn36323f82012-07-23 21:33:42 +02002262 struct ieee80211_sta *sta = txctl->sta;
Felix Fietkauf59a59f2011-05-10 20:52:22 +02002263 struct ieee80211_vif *vif = info->control.vif;
Felix Fietkauf89d1bc2013-08-06 14:18:13 +02002264 struct ath_vif *avp;
Felix Fietkau9ac586152011-01-24 19:23:18 +01002265 struct ath_softc *sc = hw->priv;
Felix Fietkau04caf862010-11-14 15:20:12 +01002266 int frmlen = skb->len + FCS_LEN;
Felix Fietkau59505c02013-06-07 18:12:02 +02002267 int padpos, padsize;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002268
Ben Greeara9927ba2010-12-06 21:13:49 -08002269 /* NOTE: sta can be NULL according to net/mac80211.h */
2270 if (sta)
2271 txctl->an = (struct ath_node *)sta->drv_priv;
Felix Fietkauf89d1bc2013-08-06 14:18:13 +02002272 else if (vif && ieee80211_is_data(hdr->frame_control)) {
2273 avp = (void *)vif->drv_priv;
2274 txctl->an = &avp->mcast_node;
2275 }
Ben Greeara9927ba2010-12-06 21:13:49 -08002276
Felix Fietkau04caf862010-11-14 15:20:12 +01002277 if (info->control.hw_key)
2278 frmlen += info->control.hw_key->icv_len;
2279
Sujith Manoharanca144052014-10-08 08:43:19 +05302280 ath_assign_seq(ath9k_hw_common(sc->sc_ah), skb);
Felix Fietkau28d16702010-11-14 15:20:10 +01002281
Felix Fietkau59505c02013-06-07 18:12:02 +02002282 if ((vif && vif->type != NL80211_IFTYPE_AP &&
2283 vif->type != NL80211_IFTYPE_AP_VLAN) ||
2284 !ieee80211_is_data(hdr->frame_control))
2285 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
2286
John W. Linville42cecc32011-09-19 15:42:31 -04002287 /* Add the padding after the header if this is not already done */
Felix Fietkauc60c9922013-04-08 00:04:09 +02002288 padpos = ieee80211_hdrlen(hdr->frame_control);
John W. Linville42cecc32011-09-19 15:42:31 -04002289 padsize = padpos & 3;
2290 if (padsize && skb->len > padpos) {
2291 if (skb_headroom(skb) < padsize)
2292 return -ENOMEM;
Felix Fietkau28d16702010-11-14 15:20:10 +01002293
John W. Linville42cecc32011-09-19 15:42:31 -04002294 skb_push(skb, padsize);
2295 memmove(skb->data, skb->data + padsize, padpos);
Felix Fietkau28d16702010-11-14 15:20:10 +01002296 }
2297
Thomas Huehn36323f82012-07-23 21:33:42 +02002298 setup_frame_info(hw, sta, skb, frmlen);
Felix Fietkau59505c02013-06-07 18:12:02 +02002299 return 0;
2300}
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002301
Felix Fietkau59505c02013-06-07 18:12:02 +02002302
2303/* Upon failure caller should free skb */
2304int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
2305 struct ath_tx_control *txctl)
2306{
2307 struct ieee80211_hdr *hdr;
2308 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2309 struct ieee80211_sta *sta = txctl->sta;
2310 struct ieee80211_vif *vif = info->control.vif;
Felix Fietkaud954cd772014-07-16 20:26:05 +02002311 struct ath_frame_info *fi = get_frame_info(skb);
Felix Fietkaubefcf7e2014-06-11 16:17:53 +05302312 struct ath_vif *avp = NULL;
Felix Fietkau59505c02013-06-07 18:12:02 +02002313 struct ath_softc *sc = hw->priv;
2314 struct ath_txq *txq = txctl->txq;
2315 struct ath_atx_tid *tid = NULL;
2316 struct ath_buf *bf;
Sujith Manoharan6b127c72014-12-10 21:26:10 +05302317 bool queue, skip_uapsd = false, ps_resp;
Sujith Manoharand7017462014-09-24 11:48:14 +05302318 int q, ret;
Felix Fietkau59505c02013-06-07 18:12:02 +02002319
Felix Fietkaubefcf7e2014-06-11 16:17:53 +05302320 if (vif)
2321 avp = (void *)vif->drv_priv;
2322
Felix Fietkau405393c2014-06-11 16:17:56 +05302323 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)
2324 txctl->force_channel = true;
2325
Sujith Manoharan6b127c72014-12-10 21:26:10 +05302326 ps_resp = !!(info->control.flags & IEEE80211_TX_CTRL_PS_RESPONSE);
2327
Felix Fietkau59505c02013-06-07 18:12:02 +02002328 ret = ath_tx_prepare(hw, skb, txctl);
2329 if (ret)
2330 return ret;
2331
2332 hdr = (struct ieee80211_hdr *) skb->data;
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002333 /*
2334 * At this point, the vif, hw_key and sta pointers in the tx control
2335 * info are no longer valid (overwritten by the ath_frame_info data.
2336 */
2337
Felix Fietkau066dae92010-11-07 14:59:39 +01002338 q = skb_get_queue_mapping(skb);
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002339
2340 ath_txq_lock(sc, txq);
Felix Fietkaud954cd772014-07-16 20:26:05 +02002341 if (txq == sc->tx.txq_map[q]) {
2342 fi->txq = q;
2343 if (++txq->pending_frames > sc->tx.txq_max_pending[q] &&
2344 !txq->stopped) {
Sujith Manoharan868caae2014-10-21 19:23:02 +05302345 if (ath9k_is_chanctx_enabled())
2346 ieee80211_stop_queue(sc->hw, info->hw_queue);
2347 else
2348 ieee80211_stop_queue(sc->hw, q);
Felix Fietkaud954cd772014-07-16 20:26:05 +02002349 txq->stopped = true;
2350 }
Felix Fietkau97923b12010-06-12 00:33:55 -04002351 }
Felix Fietkau97923b12010-06-12 00:33:55 -04002352
Felix Fietkaubefcf7e2014-06-11 16:17:53 +05302353 queue = ieee80211_is_data_present(hdr->frame_control);
2354
Janusz Dziedzic60337ed2015-11-27 09:37:08 +01002355 /* If chanctx, queue all null frames while NOA could be there */
2356 if (ath9k_is_chanctx_enabled() &&
2357 ieee80211_is_nullfunc(hdr->frame_control) &&
2358 !txctl->force_channel)
2359 queue = true;
2360
Felix Fietkaubefcf7e2014-06-11 16:17:53 +05302361 /* Force queueing of all frames that belong to a virtual interface on
2362 * a different channel context, to ensure that they are sent on the
2363 * correct channel.
2364 */
2365 if (((avp && avp->chanctx != sc->cur_chan) ||
2366 sc->cur_chan->stopped) && !txctl->force_channel) {
2367 if (!txctl->an)
2368 txctl->an = &avp->mcast_node;
Felix Fietkaubefcf7e2014-06-11 16:17:53 +05302369 queue = true;
Sujith Manoharan8d9e4642014-09-24 11:48:16 +05302370 skip_uapsd = true;
Felix Fietkaubefcf7e2014-06-11 16:17:53 +05302371 }
2372
2373 if (txctl->an && queue)
Felix Fietkau558ff222014-02-22 13:48:19 +01002374 tid = ath_get_skb_tid(sc, txctl->an, skb);
2375
Sujith Manoharan6b127c72014-12-10 21:26:10 +05302376 if (!skip_uapsd && ps_resp) {
Felix Fietkauf2c7a792013-06-07 18:12:00 +02002377 ath_txq_unlock(sc, txq);
2378 txq = sc->tx.uapsdq;
2379 ath_txq_lock(sc, txq);
Felix Fietkaubefcf7e2014-06-11 16:17:53 +05302380 } else if (txctl->an && queue) {
Felix Fietkau592fa222015-07-22 13:06:13 +02002381 WARN_ON(tid->txq != txctl->txq);
Felix Fietkaubdc21452013-04-22 23:11:43 +02002382
Felix Fietkau2800e822013-08-06 14:18:11 +02002383 if (info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT)
Felix Fietkau592fa222015-07-22 13:06:13 +02002384 tid->clear_ps_filter = true;
Felix Fietkau2800e822013-08-06 14:18:11 +02002385
Felix Fietkaubdc21452013-04-22 23:11:43 +02002386 /*
Felix Fietkau2800e822013-08-06 14:18:11 +02002387 * Add this frame to software queue for scheduling later
2388 * for aggregation.
Felix Fietkaubdc21452013-04-22 23:11:43 +02002389 */
Felix Fietkau2800e822013-08-06 14:18:11 +02002390 TX_STAT_INC(txq->axq_qnum, a_queued_sw);
2391 __skb_queue_tail(&tid->buf_q, skb);
2392 if (!txctl->an->sleeping)
Felix Fietkau04535312014-06-11 16:17:51 +05302393 ath_tx_queue_tid(sc, txq, tid);
Felix Fietkau2800e822013-08-06 14:18:11 +02002394
2395 ath_txq_schedule(sc, txq);
Felix Fietkaubdc21452013-04-22 23:11:43 +02002396 goto out;
2397 }
2398
Felix Fietkauf2c7a792013-06-07 18:12:00 +02002399 bf = ath_tx_setup_buffer(sc, txq, tid, skb);
Felix Fietkaubdc21452013-04-22 23:11:43 +02002400 if (!bf) {
Felix Fietkaua4943cc2013-06-30 12:02:13 +02002401 ath_txq_skb_done(sc, txq, skb);
Felix Fietkaubdc21452013-04-22 23:11:43 +02002402 if (txctl->paprd)
2403 dev_kfree_skb_any(skb);
2404 else
2405 ieee80211_free_txskb(sc->hw, skb);
2406 goto out;
2407 }
2408
2409 bf->bf_state.bfs_paprd = txctl->paprd;
2410
2411 if (txctl->paprd)
2412 bf->bf_state.bfs_paprd_timestamp = jiffies;
2413
Felix Fietkau79acac02013-04-22 23:11:44 +02002414 ath_set_rates(vif, sta, bf);
Felix Fietkauf2c7a792013-06-07 18:12:00 +02002415 ath_tx_send_normal(sc, txq, tid, skb);
Felix Fietkaubdc21452013-04-22 23:11:43 +02002416
2417out:
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002418 ath_txq_unlock(sc, txq);
Felix Fietkau3ad29522011-12-14 22:08:07 +01002419
Felix Fietkau44f1d262011-08-28 00:32:25 +02002420 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002421}
2422
Felix Fietkau59505c02013-06-07 18:12:02 +02002423void ath_tx_cabq(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2424 struct sk_buff *skb)
2425{
2426 struct ath_softc *sc = hw->priv;
2427 struct ath_tx_control txctl = {
2428 .txq = sc->beacon.cabq
2429 };
2430 struct ath_tx_info info = {};
2431 struct ieee80211_hdr *hdr;
2432 struct ath_buf *bf_tail = NULL;
2433 struct ath_buf *bf;
2434 LIST_HEAD(bf_q);
2435 int duration = 0;
2436 int max_duration;
2437
2438 max_duration =
Rajkumar Manoharanca900ac2014-06-11 16:18:02 +05302439 sc->cur_chan->beacon.beacon_interval * 1000 *
2440 sc->cur_chan->beacon.dtim_period / ATH_BCBUF;
Felix Fietkau59505c02013-06-07 18:12:02 +02002441
2442 do {
2443 struct ath_frame_info *fi = get_frame_info(skb);
2444
2445 if (ath_tx_prepare(hw, skb, &txctl))
2446 break;
2447
2448 bf = ath_tx_setup_buffer(sc, txctl.txq, NULL, skb);
2449 if (!bf)
2450 break;
2451
2452 bf->bf_lastbf = bf;
2453 ath_set_rates(vif, NULL, bf);
Sujith Manoharana3835e92013-07-04 12:59:47 +05302454 ath_buf_set_rate(sc, bf, &info, fi->framelen, false);
Felix Fietkau59505c02013-06-07 18:12:02 +02002455 duration += info.rates[0].PktDuration;
2456 if (bf_tail)
2457 bf_tail->bf_next = bf;
2458
2459 list_add_tail(&bf->list, &bf_q);
2460 bf_tail = bf;
2461 skb = NULL;
2462
2463 if (duration > max_duration)
2464 break;
2465
2466 skb = ieee80211_get_buffered_bc(hw, vif);
2467 } while(skb);
2468
2469 if (skb)
2470 ieee80211_free_txskb(hw, skb);
2471
2472 if (list_empty(&bf_q))
2473 return;
2474
2475 bf = list_first_entry(&bf_q, struct ath_buf, list);
2476 hdr = (struct ieee80211_hdr *) bf->bf_mpdu->data;
2477
Michal Kazior92cd4032015-07-09 12:27:22 +02002478 if (hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_MOREDATA)) {
2479 hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_MOREDATA);
Felix Fietkau59505c02013-06-07 18:12:02 +02002480 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
2481 sizeof(*hdr), DMA_TO_DEVICE);
2482 }
2483
2484 ath_txq_lock(sc, txctl.txq);
2485 ath_tx_fill_desc(sc, bf, txctl.txq, 0);
2486 ath_tx_txqaddbuf(sc, txctl.txq, &bf_q, false);
2487 TX_STAT_INC(txctl.txq->axq_qnum, queued);
2488 ath_txq_unlock(sc, txctl.txq);
2489}
2490
Sujithe8324352009-01-16 21:38:42 +05302491/*****************/
2492/* TX Completion */
2493/*****************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002494
Sujithe8324352009-01-16 21:38:42 +05302495static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
Felix Fietkaud94a4612016-09-02 19:46:12 +03002496 int tx_flags, struct ath_txq *txq,
2497 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002498{
Sujithe8324352009-01-16 21:38:42 +05302499 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002500 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Benoit Papillault4d91f9f2009-12-12 00:22:35 +01002501 struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data;
Felix Fietkaua4943cc2013-06-30 12:02:13 +02002502 int padpos, padsize;
Sujith Manoharan07c15a32012-06-04 20:24:07 +05302503 unsigned long flags;
Sujithe8324352009-01-16 21:38:42 +05302504
Joe Perchesd2182b62011-12-15 14:55:53 -08002505 ath_dbg(common, XMIT, "TX complete: skb: %p\n", skb);
Sujithe8324352009-01-16 21:38:42 +05302506
Felix Fietkau51dea9b2012-08-27 17:00:07 +02002507 if (sc->sc_ah->caldata)
Sujith Manoharan4b9b42b2013-09-11 16:36:31 +05302508 set_bit(PAPRD_PACKET_SENT, &sc->sc_ah->caldata->cal_flags);
Felix Fietkau51dea9b2012-08-27 17:00:07 +02002509
Sujith Manoharan2b5b8f12014-12-19 06:33:55 +05302510 if (!(tx_flags & ATH_TX_ERROR)) {
2511 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
2512 tx_info->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
2513 else
2514 tx_info->flags |= IEEE80211_TX_STAT_ACK;
2515 }
Sujithe8324352009-01-16 21:38:42 +05302516
Felix Fietkaud94a4612016-09-02 19:46:12 +03002517 if (tx_info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) {
2518 padpos = ieee80211_hdrlen(hdr->frame_control);
2519 padsize = padpos & 3;
2520 if (padsize && skb->len>padpos+padsize) {
2521 /*
2522 * Remove MAC header padding before giving the frame back to
2523 * mac80211.
2524 */
2525 memmove(skb->data + padsize, skb->data, padpos);
2526 skb_pull(skb, padsize);
2527 }
Sujithe8324352009-01-16 21:38:42 +05302528 }
2529
Sujith Manoharan07c15a32012-06-04 20:24:07 +05302530 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Felix Fietkauc8e88682011-11-16 13:08:40 +01002531 if ((sc->ps_flags & PS_WAIT_FOR_TX_ACK) && !txq->axq_depth) {
Sujith1b04b932010-01-08 10:36:05 +05302532 sc->ps_flags &= ~PS_WAIT_FOR_TX_ACK;
Joe Perchesd2182b62011-12-15 14:55:53 -08002533 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -08002534 "Going back to sleep after having received TX status (0x%lx)\n",
Sujith1b04b932010-01-08 10:36:05 +05302535 sc->ps_flags & (PS_WAIT_FOR_BEACON |
2536 PS_WAIT_FOR_CAB |
2537 PS_WAIT_FOR_PSPOLL_DATA |
2538 PS_WAIT_FOR_TX_ACK));
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002539 }
Sujith Manoharan07c15a32012-06-04 20:24:07 +05302540 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002541
Felix Fietkaua4943cc2013-06-30 12:02:13 +02002542 ath_txq_skb_done(sc, txq, skb);
Felix Fietkaud94a4612016-09-02 19:46:12 +03002543 tx_info->status.status_driver_data[0] = sta;
2544 __skb_queue_tail(&txq->complete_q, skb);
Sujithe8324352009-01-16 21:38:42 +05302545}
2546
2547static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
Felix Fietkaudb1a0522010-03-29 20:07:11 -07002548 struct ath_txq *txq, struct list_head *bf_q,
Felix Fietkaud94a4612016-09-02 19:46:12 +03002549 struct ieee80211_sta *sta,
Felix Fietkau156369f2011-12-14 22:08:04 +01002550 struct ath_tx_status *ts, int txok)
Sujithe8324352009-01-16 21:38:42 +05302551{
2552 struct sk_buff *skb = bf->bf_mpdu;
Felix Fietkau3afd21e2011-09-14 21:24:26 +02002553 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Sujithe8324352009-01-16 21:38:42 +05302554 unsigned long flags;
Vasanthakumar Thiagarajan6b2c4032009-03-20 15:27:50 +05302555 int tx_flags = 0;
Sujithe8324352009-01-16 21:38:42 +05302556
Felix Fietkau55797b12011-09-14 21:24:16 +02002557 if (!txok)
Vasanthakumar Thiagarajan6b2c4032009-03-20 15:27:50 +05302558 tx_flags |= ATH_TX_ERROR;
Sujithe8324352009-01-16 21:38:42 +05302559
Felix Fietkau3afd21e2011-09-14 21:24:26 +02002560 if (ts->ts_status & ATH9K_TXERR_FILT)
2561 tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
2562
Ben Greearc1739eb32010-10-14 12:45:29 -07002563 dma_unmap_single(sc->dev, bf->bf_buf_addr, skb->len, DMA_TO_DEVICE);
Ben Greear6cf9e992010-10-14 12:45:30 -07002564 bf->bf_buf_addr = 0;
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07002565 if (sc->tx99_state)
2566 goto skip_tx_complete;
Felix Fietkau9f42c2b2010-06-12 00:34:01 -04002567
2568 if (bf->bf_state.bfs_paprd) {
Mohammed Shafi Shajakhan9cf04dc2011-02-04 18:38:23 +05302569 if (time_after(jiffies,
2570 bf->bf_state.bfs_paprd_timestamp +
2571 msecs_to_jiffies(ATH_PAPRD_TIMEOUT)))
Vasanthakumar Thiagarajanca369eb2010-06-24 02:42:44 -07002572 dev_kfree_skb_any(skb);
Vasanthakumar Thiagarajan78a18172010-06-24 02:42:46 -07002573 else
Vasanthakumar Thiagarajanca369eb2010-06-24 02:42:44 -07002574 complete(&sc->paprd_complete);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -04002575 } else {
Felix Fietkau55797b12011-09-14 21:24:16 +02002576 ath_debug_stat_tx(sc, bf, ts, txq, tx_flags);
Felix Fietkaud94a4612016-09-02 19:46:12 +03002577 ath_tx_complete(sc, skb, tx_flags, txq, sta);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -04002578 }
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07002579skip_tx_complete:
Ben Greear6cf9e992010-10-14 12:45:30 -07002580 /* At this point, skb (bf->bf_mpdu) is consumed...make sure we don't
2581 * accidentally reference it later.
2582 */
2583 bf->bf_mpdu = NULL;
Sujithe8324352009-01-16 21:38:42 +05302584
2585 /*
2586 * Return the list of ath_buf of this mpdu to free queue
2587 */
2588 spin_lock_irqsave(&sc->tx.txbuflock, flags);
2589 list_splice_tail_init(bf_q, &sc->tx.txbuf);
2590 spin_unlock_irqrestore(&sc->tx.txbuflock, flags);
2591}
2592
Felix Fietkau0cdd5c62011-01-24 19:23:17 +01002593static void ath_tx_rc_status(struct ath_softc *sc, struct ath_buf *bf,
2594 struct ath_tx_status *ts, int nframes, int nbad,
Felix Fietkau3afd21e2011-09-14 21:24:26 +02002595 int txok)
Sujithc4288392008-11-18 09:09:30 +05302596{
Sujitha22be222009-03-30 15:28:36 +05302597 struct sk_buff *skb = bf->bf_mpdu;
Sujith254ad0f2009-02-04 08:10:19 +05302598 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Sujithc4288392008-11-18 09:09:30 +05302599 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau0cdd5c62011-01-24 19:23:17 +01002600 struct ieee80211_hw *hw = sc->hw;
Felix Fietkauf0c255a2010-11-11 03:18:35 +01002601 struct ath_hw *ah = sc->sc_ah;
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05302602 u8 i, tx_rateindex;
Sujithc4288392008-11-18 09:09:30 +05302603
Sujith95e4acb2009-03-13 08:56:09 +05302604 if (txok)
Felix Fietkaudb1a0522010-03-29 20:07:11 -07002605 tx_info->status.ack_signal = ts->ts_rssi;
Sujith95e4acb2009-03-13 08:56:09 +05302606
Felix Fietkaudb1a0522010-03-29 20:07:11 -07002607 tx_rateindex = ts->ts_rateindex;
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05302608 WARN_ON(tx_rateindex >= hw->max_rates);
2609
Felix Fietkau3afd21e2011-09-14 21:24:26 +02002610 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
Felix Fietkaud9698472010-03-01 13:32:11 +01002611 tx_info->flags |= IEEE80211_TX_STAT_AMPDU;
Sujithc4288392008-11-18 09:09:30 +05302612
Felix Fietkaub572d032010-11-14 15:20:07 +01002613 BUG_ON(nbad > nframes);
Björn Smedmanebd02282010-10-10 22:44:39 +02002614 }
Rajkumar Manoharan185d1582011-09-26 21:48:39 +05302615 tx_info->status.ampdu_len = nframes;
2616 tx_info->status.ampdu_ack_len = nframes - nbad;
Björn Smedmanebd02282010-10-10 22:44:39 +02002617
Felix Fietkaudb1a0522010-03-29 20:07:11 -07002618 if ((ts->ts_status & ATH9K_TXERR_FILT) == 0 &&
Felix Fietkau3afd21e2011-09-14 21:24:26 +02002619 (tx_info->flags & IEEE80211_TX_CTL_NO_ACK) == 0) {
Felix Fietkauf0c255a2010-11-11 03:18:35 +01002620 /*
2621 * If an underrun error is seen assume it as an excessive
2622 * retry only if max frame trigger level has been reached
2623 * (2 KB for single stream, and 4 KB for dual stream).
2624 * Adjust the long retry as if the frame was tried
2625 * hw->max_rate_tries times to affect how rate control updates
2626 * PER for the failed rate.
2627 * In case of congestion on the bus penalizing this type of
2628 * underruns should help hardware actually transmit new frames
2629 * successfully by eventually preferring slower rates.
2630 * This itself should also alleviate congestion on the bus.
2631 */
Felix Fietkau3afd21e2011-09-14 21:24:26 +02002632 if (unlikely(ts->ts_flags & (ATH9K_TX_DATA_UNDERRUN |
2633 ATH9K_TX_DELIM_UNDERRUN)) &&
2634 ieee80211_is_data(hdr->frame_control) &&
Felix Fietkau83860c52011-03-23 20:57:33 +01002635 ah->tx_trig_level >= sc->sc_ah->config.max_txtrig_level)
Felix Fietkauf0c255a2010-11-11 03:18:35 +01002636 tx_info->status.rates[tx_rateindex].count =
2637 hw->max_rate_tries;
Sujithc4288392008-11-18 09:09:30 +05302638 }
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05302639
Felix Fietkau545750d2009-11-23 22:21:01 +01002640 for (i = tx_rateindex + 1; i < hw->max_rates; i++) {
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05302641 tx_info->status.rates[i].count = 0;
Felix Fietkau545750d2009-11-23 22:21:01 +01002642 tx_info->status.rates[i].idx = -1;
2643 }
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05302644
Felix Fietkau78c46532010-06-25 01:26:16 +02002645 tx_info->status.rates[tx_rateindex].count = ts->ts_longretry + 1;
Sujithc4288392008-11-18 09:09:30 +05302646}
2647
Sujithc4288392008-11-18 09:09:30 +05302648static void ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002649{
Sujithcbe61d82009-02-09 13:27:12 +05302650 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002651 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002652 struct ath_buf *bf, *lastbf, *bf_held = NULL;
2653 struct list_head bf_head;
Sujithc4288392008-11-18 09:09:30 +05302654 struct ath_desc *ds;
Felix Fietkau29bffa92010-03-29 20:14:23 -07002655 struct ath_tx_status ts;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002656 int status;
2657
Joe Perchesd2182b62011-12-15 14:55:53 -08002658 ath_dbg(common, QUEUE, "tx queue %d (%x), link %p\n",
Joe Perches226afe62010-12-02 19:12:37 -08002659 txq->axq_qnum, ath9k_hw_gettxbuf(sc->sc_ah, txq->axq_qnum),
2660 txq->axq_link);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002661
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002662 ath_txq_lock(sc, txq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002663 for (;;) {
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01002664 if (test_bit(ATH_OP_HW_RESET, &common->op_flags))
Felix Fietkau236de512011-09-03 01:40:25 +02002665 break;
2666
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002667 if (list_empty(&txq->axq_q)) {
2668 txq->axq_link = NULL;
Felix Fietkau73364b02013-08-06 14:18:08 +02002669 ath_txq_schedule(sc, txq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002670 break;
2671 }
2672 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
2673
2674 /*
2675 * There is a race condition that a BH gets scheduled
2676 * after sw writes TxE and before hw re-load the last
2677 * descriptor to get the newly chained one.
2678 * Software must keep the last DONE descriptor as a
2679 * holding descriptor - software does so by marking
2680 * it with the STALE flag.
2681 */
2682 bf_held = NULL;
Felix Fietkau50676b82013-08-10 15:59:16 +02002683 if (bf->bf_state.stale) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002684 bf_held = bf;
Felix Fietkaufce041b2011-05-19 12:20:25 +02002685 if (list_is_last(&bf_held->list, &txq->axq_q))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002686 break;
Felix Fietkaufce041b2011-05-19 12:20:25 +02002687
2688 bf = list_entry(bf_held->list.next, struct ath_buf,
2689 list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002690 }
2691
2692 lastbf = bf->bf_lastbf;
Sujithe8324352009-01-16 21:38:42 +05302693 ds = lastbf->bf_desc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002694
Felix Fietkau29bffa92010-03-29 20:14:23 -07002695 memset(&ts, 0, sizeof(ts));
2696 status = ath9k_hw_txprocdesc(ah, ds, &ts);
Felix Fietkaufce041b2011-05-19 12:20:25 +02002697 if (status == -EINPROGRESS)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002698 break;
Felix Fietkaufce041b2011-05-19 12:20:25 +02002699
Ben Greear2dac4fb2011-01-09 23:11:45 -08002700 TX_STAT_INC(txq->axq_qnum, txprocdesc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002701
2702 /*
2703 * Remove ath_buf's of the same transmit unit from txq,
2704 * however leave the last descriptor back as the holding
2705 * descriptor for hw.
2706 */
Felix Fietkau50676b82013-08-10 15:59:16 +02002707 lastbf->bf_state.stale = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002708 INIT_LIST_HEAD(&bf_head);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002709 if (!list_is_singular(&lastbf->list))
2710 list_cut_position(&bf_head,
2711 &txq->axq_q, lastbf->list.prev);
2712
Felix Fietkaufce041b2011-05-19 12:20:25 +02002713 if (bf_held) {
Felix Fietkau0a8cea82010-04-19 19:57:30 +02002714 list_del(&bf_held->list);
Felix Fietkau0a8cea82010-04-19 19:57:30 +02002715 ath_tx_return_buffer(sc, bf_held);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002716 }
Johannes Berge6a98542008-10-21 12:40:02 +02002717
Felix Fietkaufce041b2011-05-19 12:20:25 +02002718 ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002719 }
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002720 ath_txq_unlock_complete(sc, txq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002721}
2722
Sujithe8324352009-01-16 21:38:42 +05302723void ath_tx_tasklet(struct ath_softc *sc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002724{
Felix Fietkau239c7952012-03-14 16:40:26 +01002725 struct ath_hw *ah = sc->sc_ah;
2726 u32 qcumask = ((1 << ATH9K_NUM_TX_QUEUES) - 1) & ah->intr_txqs;
Sujithe8324352009-01-16 21:38:42 +05302727 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002728
Felix Fietkaud94a4612016-09-02 19:46:12 +03002729 rcu_read_lock();
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002730 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
Sujithe8324352009-01-16 21:38:42 +05302731 if (ATH_TXQ_SETUP(sc, i) && (qcumask & (1 << i)))
2732 ath_tx_processq(sc, &sc->tx.txq[i]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002733 }
Felix Fietkaud94a4612016-09-02 19:46:12 +03002734 rcu_read_unlock();
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002735}
2736
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002737void ath_tx_edma_tasklet(struct ath_softc *sc)
2738{
Felix Fietkaufce041b2011-05-19 12:20:25 +02002739 struct ath_tx_status ts;
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002740 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2741 struct ath_hw *ah = sc->sc_ah;
2742 struct ath_txq *txq;
2743 struct ath_buf *bf, *lastbf;
2744 struct list_head bf_head;
Felix Fietkau99ba6a42013-04-08 00:04:13 +02002745 struct list_head *fifo_list;
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002746 int status;
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002747
Felix Fietkaud94a4612016-09-02 19:46:12 +03002748 rcu_read_lock();
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002749 for (;;) {
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01002750 if (test_bit(ATH_OP_HW_RESET, &common->op_flags))
Felix Fietkau236de512011-09-03 01:40:25 +02002751 break;
2752
Felix Fietkaufce041b2011-05-19 12:20:25 +02002753 status = ath9k_hw_txprocdesc(ah, NULL, (void *)&ts);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002754 if (status == -EINPROGRESS)
2755 break;
2756 if (status == -EIO) {
Joe Perchesd2182b62011-12-15 14:55:53 -08002757 ath_dbg(common, XMIT, "Error processing tx status\n");
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002758 break;
2759 }
2760
Felix Fietkau4e0ad252012-02-27 19:58:42 +01002761 /* Process beacon completions separately */
2762 if (ts.qid == sc->beacon.beaconq) {
2763 sc->beacon.tx_processed = true;
2764 sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK);
Simon Wunderlichd074e8d2013-08-14 08:01:38 +02002765
Sujith Manoharan27babf92014-08-23 13:29:16 +05302766 if (ath9k_is_chanctx_enabled()) {
2767 ath_chanctx_event(sc, NULL,
2768 ATH_CHANCTX_EVENT_BEACON_SENT);
2769 }
2770
Michal Kazior4effc6f2014-01-20 15:27:12 +01002771 ath9k_csa_update(sc);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002772 continue;
Felix Fietkau4e0ad252012-02-27 19:58:42 +01002773 }
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002774
Felix Fietkaufce041b2011-05-19 12:20:25 +02002775 txq = &sc->tx.txq[ts.qid];
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002776
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002777 ath_txq_lock(sc, txq);
Felix Fietkaufce041b2011-05-19 12:20:25 +02002778
Sujith Manoharan78ef7312012-11-21 18:13:11 +05302779 TX_STAT_INC(txq->axq_qnum, txprocdesc);
2780
Felix Fietkau99ba6a42013-04-08 00:04:13 +02002781 fifo_list = &txq->txq_fifo[txq->txq_tailidx];
2782 if (list_empty(fifo_list)) {
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002783 ath_txq_unlock(sc, txq);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002784 return;
2785 }
2786
Felix Fietkau99ba6a42013-04-08 00:04:13 +02002787 bf = list_first_entry(fifo_list, struct ath_buf, list);
Felix Fietkau50676b82013-08-10 15:59:16 +02002788 if (bf->bf_state.stale) {
Felix Fietkau99ba6a42013-04-08 00:04:13 +02002789 list_del(&bf->list);
2790 ath_tx_return_buffer(sc, bf);
2791 bf = list_first_entry(fifo_list, struct ath_buf, list);
2792 }
2793
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002794 lastbf = bf->bf_lastbf;
2795
2796 INIT_LIST_HEAD(&bf_head);
Felix Fietkau99ba6a42013-04-08 00:04:13 +02002797 if (list_is_last(&lastbf->list, fifo_list)) {
2798 list_splice_tail_init(fifo_list, &bf_head);
Felix Fietkaufce041b2011-05-19 12:20:25 +02002799 INCR(txq->txq_tailidx, ATH_TXFIFO_DEPTH);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002800
Felix Fietkaufce041b2011-05-19 12:20:25 +02002801 if (!list_empty(&txq->axq_q)) {
2802 struct list_head bf_q;
2803
2804 INIT_LIST_HEAD(&bf_q);
2805 txq->axq_link = NULL;
2806 list_splice_tail_init(&txq->axq_q, &bf_q);
2807 ath_tx_txqaddbuf(sc, txq, &bf_q, true);
2808 }
Felix Fietkau99ba6a42013-04-08 00:04:13 +02002809 } else {
Felix Fietkau50676b82013-08-10 15:59:16 +02002810 lastbf->bf_state.stale = true;
Felix Fietkau99ba6a42013-04-08 00:04:13 +02002811 if (bf != lastbf)
2812 list_cut_position(&bf_head, fifo_list,
2813 lastbf->list.prev);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002814 }
2815
Felix Fietkaufce041b2011-05-19 12:20:25 +02002816 ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head);
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002817 ath_txq_unlock_complete(sc, txq);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002818 }
Felix Fietkaud94a4612016-09-02 19:46:12 +03002819 rcu_read_unlock();
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002820}
2821
Sujithe8324352009-01-16 21:38:42 +05302822/*****************/
2823/* Init, Cleanup */
2824/*****************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002825
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002826static int ath_txstatus_setup(struct ath_softc *sc, int size)
2827{
2828 struct ath_descdma *dd = &sc->txsdma;
2829 u8 txs_len = sc->sc_ah->caps.txs_len;
2830
2831 dd->dd_desc_len = size * txs_len;
Felix Fietkaub81950b12012-12-12 13:14:22 +01002832 dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len,
2833 &dd->dd_desc_paddr, GFP_KERNEL);
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002834 if (!dd->dd_desc)
2835 return -ENOMEM;
2836
2837 return 0;
2838}
2839
2840static int ath_tx_edma_init(struct ath_softc *sc)
2841{
2842 int err;
2843
2844 err = ath_txstatus_setup(sc, ATH_TXSTATUS_RING_SIZE);
2845 if (!err)
2846 ath9k_hw_setup_statusring(sc->sc_ah, sc->txsdma.dd_desc,
2847 sc->txsdma.dd_desc_paddr,
2848 ATH_TXSTATUS_RING_SIZE);
2849
2850 return err;
2851}
2852
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002853int ath_tx_init(struct ath_softc *sc, int nbufs)
2854{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002855 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002856 int error = 0;
2857
Sujith797fe5cb2009-03-30 15:28:45 +05302858 spin_lock_init(&sc->tx.txbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002859
Sujith797fe5cb2009-03-30 15:28:45 +05302860 error = ath_descdma_setup(sc, &sc->tx.txdma, &sc->tx.txbuf,
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -04002861 "tx", nbufs, 1, 1);
Sujith797fe5cb2009-03-30 15:28:45 +05302862 if (error != 0) {
Joe Perches38002762010-12-02 19:12:36 -08002863 ath_err(common,
2864 "Failed to allocate tx descriptors: %d\n", error);
Felix Fietkaub81950b12012-12-12 13:14:22 +01002865 return error;
Sujith797fe5cb2009-03-30 15:28:45 +05302866 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002867
Sujith797fe5cb2009-03-30 15:28:45 +05302868 error = ath_descdma_setup(sc, &sc->beacon.bdma, &sc->beacon.bbuf,
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002869 "beacon", ATH_BCBUF, 1, 1);
Sujith797fe5cb2009-03-30 15:28:45 +05302870 if (error != 0) {
Joe Perches38002762010-12-02 19:12:36 -08002871 ath_err(common,
2872 "Failed to allocate beacon descriptors: %d\n", error);
Felix Fietkaub81950b12012-12-12 13:14:22 +01002873 return error;
Sujith797fe5cb2009-03-30 15:28:45 +05302874 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002875
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04002876 INIT_DELAYED_WORK(&sc->tx_complete_work, ath_tx_complete_poll_work);
2877
Felix Fietkaub81950b12012-12-12 13:14:22 +01002878 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002879 error = ath_tx_edma_init(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002880
2881 return error;
2882}
2883
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002884void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an)
2885{
Sujithc5170162008-10-29 10:13:59 +05302886 struct ath_atx_tid *tid;
Sujithc5170162008-10-29 10:13:59 +05302887 int tidno, acno;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002888
Sujith8ee5afb2008-12-07 21:43:36 +05302889 for (tidno = 0, tid = &an->tid[tidno];
Sujith Manoharande7b7602012-11-28 15:08:53 +05302890 tidno < IEEE80211_NUM_TIDS;
Sujithc5170162008-10-29 10:13:59 +05302891 tidno++, tid++) {
2892 tid->an = an;
2893 tid->tidno = tidno;
2894 tid->seq_start = tid->seq_next = 0;
2895 tid->baw_size = WME_MAX_BA;
2896 tid->baw_head = tid->baw_tail = 0;
Felix Fietkau08c96ab2013-05-18 21:28:15 +02002897 tid->active = false;
Felix Fietkau592fa222015-07-22 13:06:13 +02002898 tid->clear_ps_filter = true;
Felix Fietkau56dc6332011-08-28 00:32:22 +02002899 __skb_queue_head_init(&tid->buf_q);
Felix Fietkaubb195ff2013-08-06 14:18:03 +02002900 __skb_queue_head_init(&tid->retry_q);
Felix Fietkaud70d8482015-07-22 13:06:14 +02002901 INIT_LIST_HEAD(&tid->list);
Sujithc5170162008-10-29 10:13:59 +05302902 acno = TID_TO_WME_AC(tidno);
Felix Fietkau592fa222015-07-22 13:06:13 +02002903 tid->txq = sc->tx.txq_map[acno];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002904 }
2905}
2906
Sujithb5aa9bf2008-10-29 10:13:31 +05302907void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002908{
Felix Fietkau2b409942010-07-07 19:42:08 +02002909 struct ath_atx_tid *tid;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002910 struct ath_txq *txq;
Felix Fietkau066dae92010-11-07 14:59:39 +01002911 int tidno;
Sujithe8324352009-01-16 21:38:42 +05302912
Felix Fietkau2b409942010-07-07 19:42:08 +02002913 for (tidno = 0, tid = &an->tid[tidno];
Sujith Manoharande7b7602012-11-28 15:08:53 +05302914 tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002915
Felix Fietkau592fa222015-07-22 13:06:13 +02002916 txq = tid->txq;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002917
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002918 ath_txq_lock(sc, txq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002919
Felix Fietkaud70d8482015-07-22 13:06:14 +02002920 if (!list_empty(&tid->list))
2921 list_del_init(&tid->list);
Felix Fietkau2b409942010-07-07 19:42:08 +02002922
Felix Fietkau2b409942010-07-07 19:42:08 +02002923 ath_tid_drain(sc, txq, tid);
Felix Fietkau08c96ab2013-05-18 21:28:15 +02002924 tid->active = false;
Felix Fietkau2b409942010-07-07 19:42:08 +02002925
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002926 ath_txq_unlock(sc, txq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002927 }
2928}
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07002929
Sujith Manoharanef6b19e2013-10-24 12:04:39 +05302930#ifdef CONFIG_ATH9K_TX99
2931
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07002932int ath9k_tx99_send(struct ath_softc *sc, struct sk_buff *skb,
2933 struct ath_tx_control *txctl)
2934{
2935 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2936 struct ath_frame_info *fi = get_frame_info(skb);
2937 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2938 struct ath_buf *bf;
2939 int padpos, padsize;
2940
2941 padpos = ieee80211_hdrlen(hdr->frame_control);
2942 padsize = padpos & 3;
2943
2944 if (padsize && skb->len > padpos) {
2945 if (skb_headroom(skb) < padsize) {
2946 ath_dbg(common, XMIT,
2947 "tx99 padding failed\n");
Colin Ian Kingba38a172015-12-08 23:49:31 +00002948 return -EINVAL;
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07002949 }
2950
2951 skb_push(skb, padsize);
2952 memmove(skb->data, skb->data + padsize, padpos);
2953 }
2954
2955 fi->keyix = ATH9K_TXKEYIX_INVALID;
2956 fi->framelen = skb->len + FCS_LEN;
2957 fi->keytype = ATH9K_KEY_TYPE_CLEAR;
2958
2959 bf = ath_tx_setup_buffer(sc, txctl->txq, NULL, skb);
2960 if (!bf) {
2961 ath_dbg(common, XMIT, "tx99 buffer setup failed\n");
2962 return -EINVAL;
2963 }
2964
2965 ath_set_rates(sc->tx99_vif, NULL, bf);
2966
2967 ath9k_hw_set_desc_link(sc->sc_ah, bf->bf_desc, bf->bf_daddr);
2968 ath9k_hw_tx99_start(sc->sc_ah, txctl->txq->axq_qnum);
2969
2970 ath_tx_send_normal(sc, txctl->txq, NULL, skb);
2971
2972 return 0;
2973}
Sujith Manoharanef6b19e2013-10-24 12:04:39 +05302974
2975#endif /* CONFIG_ATH9K_TX99 */