blob: c35a192861ab8ff9a21abafd42e972206c0a0233 [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);
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +010070static int ath_tx_prepare(struct ieee80211_hw *hw, struct sk_buff *skb,
71 struct ath_tx_control *txctl);
Sujithe8324352009-01-16 21:38:42 +053072
Felix Fietkau545750d2009-11-23 22:21:01 +010073enum {
Felix Fietkau0e668cd2010-04-19 19:57:32 +020074 MCS_HT20,
75 MCS_HT20_SGI,
Felix Fietkau545750d2009-11-23 22:21:01 +010076 MCS_HT40,
77 MCS_HT40_SGI,
78};
79
Sujithe8324352009-01-16 21:38:42 +053080/*********************/
81/* Aggregation logic */
82/*********************/
83
Felix Fietkaud94a4612016-09-02 19:46:12 +030084static void ath_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
85{
86 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
87 struct ieee80211_sta *sta = info->status.status_driver_data[0];
88
89 if (info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) {
90 ieee80211_tx_status(hw, skb);
91 return;
92 }
93
94 if (sta)
95 ieee80211_tx_status_noskb(hw, sta, info);
96
97 dev_kfree_skb(skb);
98}
99
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530100void ath_txq_unlock_complete(struct ath_softc *sc, struct ath_txq *txq)
Luis R. Rodriguez1512a482011-12-20 10:46:09 -0800101 __releases(&txq->axq_lock)
Felix Fietkau23de5dc2011-12-19 16:45:54 +0100102{
Felix Fietkaud94a4612016-09-02 19:46:12 +0300103 struct ieee80211_hw *hw = sc->hw;
Felix Fietkau23de5dc2011-12-19 16:45:54 +0100104 struct sk_buff_head q;
105 struct sk_buff *skb;
106
107 __skb_queue_head_init(&q);
108 skb_queue_splice_init(&txq->complete_q, &q);
109 spin_unlock_bh(&txq->axq_lock);
110
111 while ((skb = __skb_dequeue(&q)))
Felix Fietkaud94a4612016-09-02 19:46:12 +0300112 ath_tx_status(hw, skb);
Felix Fietkau23de5dc2011-12-19 16:45:54 +0100113}
114
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +0200115void __ath_tx_queue_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
Sujithe8324352009-01-16 21:38:42 +0530116{
Felix Fietkau04535312014-06-11 16:17:51 +0530117 struct ath_vif *avp = (struct ath_vif *) tid->an->vif->drv_priv;
118 struct ath_chanctx *ctx = avp->chanctx;
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +0200119 struct ath_acq *acq;
120 struct list_head *tid_list;
121 u8 acno = TID_TO_WME_AC(tid->tidno);
Felix Fietkau04535312014-06-11 16:17:51 +0530122
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +0200123 if (!ctx || !list_empty(&tid->list))
Felix Fietkau04535312014-06-11 16:17:51 +0530124 return;
Sujithe8324352009-01-16 21:38:42 +0530125
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +0200126
127 acq = &ctx->acq[acno];
128 if ((sc->airtime_flags & AIRTIME_USE_NEW_QUEUES) &&
129 tid->an->airtime_deficit[acno] > 0)
130 tid_list = &acq->acq_new;
131 else
132 tid_list = &acq->acq_old;
133
134 list_add_tail(&tid->list, tid_list);
Sujithe8324352009-01-16 21:38:42 +0530135}
136
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +0200137void ath_tx_queue_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
138{
139 struct ath_vif *avp = (struct ath_vif *) tid->an->vif->drv_priv;
140 struct ath_chanctx *ctx = avp->chanctx;
141 struct ath_acq *acq;
142
143 if (!ctx || !list_empty(&tid->list))
144 return;
145
146 acq = &ctx->acq[TID_TO_WME_AC(tid->tidno)];
147 spin_lock_bh(&acq->lock);
148 __ath_tx_queue_tid(sc, tid);
149 spin_unlock_bh(&acq->lock);
150}
151
152
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +0100153void ath9k_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *queue)
154{
155 struct ath_softc *sc = hw->priv;
156 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
157 struct ath_atx_tid *tid = (struct ath_atx_tid *) queue->drv_priv;
158 struct ath_txq *txq = tid->txq;
159
160 ath_dbg(common, QUEUE, "Waking TX queue: %pM (%d)\n",
161 queue->sta ? queue->sta->addr : queue->vif->addr,
162 tid->tidno);
163
164 ath_txq_lock(sc, txq);
165
166 tid->has_queued = true;
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +0200167 ath_tx_queue_tid(sc, tid);
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +0100168 ath_txq_schedule(sc, txq);
169
170 ath_txq_unlock(sc, txq);
171}
172
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100173static struct ath_frame_info *get_frame_info(struct sk_buff *skb)
Felix Fietkau76e45222010-11-14 15:20:08 +0100174{
175 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100176 BUILD_BUG_ON(sizeof(struct ath_frame_info) >
177 sizeof(tx_info->rate_driver_data));
178 return (struct ath_frame_info *) &tx_info->rate_driver_data[0];
Felix Fietkau76e45222010-11-14 15:20:08 +0100179}
180
Felix Fietkau156369f2011-12-14 22:08:04 +0100181static void ath_send_bar(struct ath_atx_tid *tid, u16 seqno)
182{
Felix Fietkauf89d1bc2013-08-06 14:18:13 +0200183 if (!tid->an->sta)
184 return;
185
Felix Fietkau156369f2011-12-14 22:08:04 +0100186 ieee80211_send_bar(tid->an->vif, tid->an->sta->addr, tid->tidno,
187 seqno << IEEE80211_SEQ_SEQ_SHIFT);
188}
189
Felix Fietkau79acac02013-04-22 23:11:44 +0200190static void ath_set_rates(struct ieee80211_vif *vif, struct ieee80211_sta *sta,
191 struct ath_buf *bf)
192{
193 ieee80211_get_tx_rates(vif, sta, bf->bf_mpdu, bf->rates,
194 ARRAY_SIZE(bf->rates));
195}
196
Felix Fietkaua4943cc2013-06-30 12:02:13 +0200197static void ath_txq_skb_done(struct ath_softc *sc, struct ath_txq *txq,
198 struct sk_buff *skb)
199{
Felix Fietkaud954cd772014-07-16 20:26:05 +0200200 struct ath_frame_info *fi = get_frame_info(skb);
Felix Fietkaud954cd772014-07-16 20:26:05 +0200201 int q = fi->txq;
Felix Fietkaua4943cc2013-06-30 12:02:13 +0200202
Felix Fietkaud954cd772014-07-16 20:26:05 +0200203 if (q < 0)
Felix Fietkaua4943cc2013-06-30 12:02:13 +0200204 return;
205
Felix Fietkaud954cd772014-07-16 20:26:05 +0200206 txq = sc->tx.txq_map[q];
Felix Fietkaua4943cc2013-06-30 12:02:13 +0200207 if (WARN_ON(--txq->pending_frames < 0))
208 txq->pending_frames = 0;
209
Felix Fietkaua4943cc2013-06-30 12:02:13 +0200210}
211
Felix Fietkau1803d022013-08-06 14:18:04 +0200212static struct ath_atx_tid *
213ath_get_skb_tid(struct ath_softc *sc, struct ath_node *an, struct sk_buff *skb)
214{
Felix Fietkau39731b72013-12-19 18:01:51 +0100215 u8 tidno = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
Felix Fietkau1803d022013-08-06 14:18:04 +0200216 return ATH_AN_2_TID(an, tidno);
217}
218
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +0100219static struct sk_buff *
220ath_tid_pull(struct ath_atx_tid *tid)
221{
222 struct ieee80211_txq *txq = container_of((void*)tid, struct ieee80211_txq, drv_priv);
223 struct ath_softc *sc = tid->an->sc;
224 struct ieee80211_hw *hw = sc->hw;
225 struct ath_tx_control txctl = {
226 .txq = tid->txq,
227 .sta = tid->an->sta,
228 };
229 struct sk_buff *skb;
230 struct ath_frame_info *fi;
231 int q;
232
233 if (!tid->has_queued)
234 return NULL;
235
236 skb = ieee80211_tx_dequeue(hw, txq);
237 if (!skb) {
238 tid->has_queued = false;
239 return NULL;
240 }
241
242 if (ath_tx_prepare(hw, skb, &txctl)) {
243 ieee80211_free_txskb(hw, skb);
244 return NULL;
245 }
246
247 q = skb_get_queue_mapping(skb);
248 if (tid->txq == sc->tx.txq_map[q]) {
249 fi = get_frame_info(skb);
250 fi->txq = q;
251 ++tid->txq->pending_frames;
252 }
253
254 return skb;
255 }
256
257
Felix Fietkaua7586ee2013-08-06 14:18:02 +0200258static bool ath_tid_has_buffered(struct ath_atx_tid *tid)
259{
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +0100260 return !skb_queue_empty(&tid->retry_q) || tid->has_queued;
Felix Fietkaua7586ee2013-08-06 14:18:02 +0200261}
262
263static struct sk_buff *ath_tid_dequeue(struct ath_atx_tid *tid)
264{
Felix Fietkaubb195ff2013-08-06 14:18:03 +0200265 struct sk_buff *skb;
266
267 skb = __skb_dequeue(&tid->retry_q);
268 if (!skb)
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +0100269 skb = ath_tid_pull(tid);
Felix Fietkaubb195ff2013-08-06 14:18:03 +0200270
271 return skb;
Felix Fietkaua7586ee2013-08-06 14:18:02 +0200272}
273
Felix Fietkau08c96ab2013-05-18 21:28:15 +0200274static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
Sujithe8324352009-01-16 21:38:42 +0530275{
Felix Fietkau592fa222015-07-22 13:06:13 +0200276 struct ath_txq *txq = tid->txq;
Felix Fietkau56dc6332011-08-28 00:32:22 +0200277 struct sk_buff *skb;
Sujithe8324352009-01-16 21:38:42 +0530278 struct ath_buf *bf;
279 struct list_head bf_head;
Felix Fietkau90fa5392010-09-20 13:45:38 +0200280 struct ath_tx_status ts;
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100281 struct ath_frame_info *fi;
Felix Fietkau156369f2011-12-14 22:08:04 +0100282 bool sendbar = false;
Felix Fietkau90fa5392010-09-20 13:45:38 +0200283
Sujithe8324352009-01-16 21:38:42 +0530284 INIT_LIST_HEAD(&bf_head);
285
Felix Fietkau90fa5392010-09-20 13:45:38 +0200286 memset(&ts, 0, sizeof(ts));
Sujithe8324352009-01-16 21:38:42 +0530287
Felix Fietkau2800e822013-08-06 14:18:11 +0200288 while ((skb = __skb_dequeue(&tid->retry_q))) {
Felix Fietkau56dc6332011-08-28 00:32:22 +0200289 fi = get_frame_info(skb);
290 bf = fi->bf;
Felix Fietkau249ee722012-10-03 21:07:52 +0200291 if (!bf) {
Felix Fietkau2800e822013-08-06 14:18:11 +0200292 ath_txq_skb_done(sc, txq, skb);
293 ieee80211_free_txskb(sc->hw, skb);
294 continue;
Felix Fietkau249ee722012-10-03 21:07:52 +0200295 }
296
Felix Fietkau8fed1402013-08-06 14:18:07 +0200297 if (fi->baw_tracked) {
Felix Fietkau6a0ddae2011-08-28 00:32:23 +0200298 ath_tx_update_baw(sc, tid, bf->bf_state.seqno);
Felix Fietkau156369f2011-12-14 22:08:04 +0100299 sendbar = true;
Felix Fietkau90fa5392010-09-20 13:45:38 +0200300 }
Felix Fietkau2800e822013-08-06 14:18:11 +0200301
302 list_add_tail(&bf->list, &bf_head);
Felix Fietkaud94a4612016-09-02 19:46:12 +0300303 ath_tx_complete_buf(sc, bf, txq, &bf_head, NULL, &ts, 0);
Sujithe8324352009-01-16 21:38:42 +0530304 }
305
Felix Fietkau08c96ab2013-05-18 21:28:15 +0200306 if (sendbar) {
Felix Fietkau23de5dc2011-12-19 16:45:54 +0100307 ath_txq_unlock(sc, txq);
Felix Fietkau156369f2011-12-14 22:08:04 +0100308 ath_send_bar(tid, tid->seq_start);
Felix Fietkau23de5dc2011-12-19 16:45:54 +0100309 ath_txq_lock(sc, txq);
310 }
Sujithe8324352009-01-16 21:38:42 +0530311}
312
313static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
314 int seqno)
315{
316 int index, cindex;
317
318 index = ATH_BA_INDEX(tid->seq_start, seqno);
319 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
320
Felix Fietkau81ee13b2010-09-20 13:45:36 +0200321 __clear_bit(cindex, tid->tx_buf);
Sujithe8324352009-01-16 21:38:42 +0530322
Felix Fietkau81ee13b2010-09-20 13:45:36 +0200323 while (tid->baw_head != tid->baw_tail && !test_bit(tid->baw_head, tid->tx_buf)) {
Sujithe8324352009-01-16 21:38:42 +0530324 INCR(tid->seq_start, IEEE80211_SEQ_MAX);
325 INCR(tid->baw_head, ATH_TID_MAX_BUFS);
Felix Fietkauf9437542011-12-14 22:08:08 +0100326 if (tid->bar_index >= 0)
327 tid->bar_index--;
Sujithe8324352009-01-16 21:38:42 +0530328 }
329}
330
331static void ath_tx_addto_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
Felix Fietkau8fed1402013-08-06 14:18:07 +0200332 struct ath_buf *bf)
Sujithe8324352009-01-16 21:38:42 +0530333{
Felix Fietkau8fed1402013-08-06 14:18:07 +0200334 struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu);
335 u16 seqno = bf->bf_state.seqno;
Sujithe8324352009-01-16 21:38:42 +0530336 int index, cindex;
337
Felix Fietkau2d3bcba2010-11-14 15:20:01 +0100338 index = ATH_BA_INDEX(tid->seq_start, seqno);
Sujithe8324352009-01-16 21:38:42 +0530339 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
Felix Fietkau81ee13b2010-09-20 13:45:36 +0200340 __set_bit(cindex, tid->tx_buf);
Felix Fietkau8fed1402013-08-06 14:18:07 +0200341 fi->baw_tracked = 1;
Sujithe8324352009-01-16 21:38:42 +0530342
343 if (index >= ((tid->baw_tail - tid->baw_head) &
344 (ATH_TID_MAX_BUFS - 1))) {
345 tid->baw_tail = cindex;
346 INCR(tid->baw_tail, ATH_TID_MAX_BUFS);
347 }
348}
349
Sujithe8324352009-01-16 21:38:42 +0530350static void ath_tid_drain(struct ath_softc *sc, struct ath_txq *txq,
351 struct ath_atx_tid *tid)
352
353{
Felix Fietkau56dc6332011-08-28 00:32:22 +0200354 struct sk_buff *skb;
Sujithe8324352009-01-16 21:38:42 +0530355 struct ath_buf *bf;
356 struct list_head bf_head;
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700357 struct ath_tx_status ts;
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100358 struct ath_frame_info *fi;
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700359
360 memset(&ts, 0, sizeof(ts));
Sujithe8324352009-01-16 21:38:42 +0530361 INIT_LIST_HEAD(&bf_head);
362
Felix Fietkaua7586ee2013-08-06 14:18:02 +0200363 while ((skb = ath_tid_dequeue(tid))) {
Felix Fietkau56dc6332011-08-28 00:32:22 +0200364 fi = get_frame_info(skb);
365 bf = fi->bf;
Sujithe8324352009-01-16 21:38:42 +0530366
Felix Fietkau44f1d262011-08-28 00:32:25 +0200367 if (!bf) {
Felix Fietkaud94a4612016-09-02 19:46:12 +0300368 ath_tx_complete(sc, skb, ATH_TX_ERROR, txq, NULL);
Felix Fietkau44f1d262011-08-28 00:32:25 +0200369 continue;
370 }
371
Felix Fietkau56dc6332011-08-28 00:32:22 +0200372 list_add_tail(&bf->list, &bf_head);
Felix Fietkaud94a4612016-09-02 19:46:12 +0300373 ath_tx_complete_buf(sc, bf, txq, &bf_head, NULL, &ts, 0);
Sujithe8324352009-01-16 21:38:42 +0530374 }
Sujithe8324352009-01-16 21:38:42 +0530375}
376
Sujithfec247c2009-07-27 12:08:16 +0530377static void ath_tx_set_retry(struct ath_softc *sc, struct ath_txq *txq,
Felix Fietkauda647622011-12-14 22:08:03 +0100378 struct sk_buff *skb, int count)
Sujithe8324352009-01-16 21:38:42 +0530379{
Felix Fietkau8b7f8532010-11-28 19:37:48 +0100380 struct ath_frame_info *fi = get_frame_info(skb);
Felix Fietkauf11cc942011-09-15 12:59:49 +0200381 struct ath_buf *bf = fi->bf;
Sujithe8324352009-01-16 21:38:42 +0530382 struct ieee80211_hdr *hdr;
Felix Fietkauda647622011-12-14 22:08:03 +0100383 int prev = fi->retries;
Sujithe8324352009-01-16 21:38:42 +0530384
Sujithfec247c2009-07-27 12:08:16 +0530385 TX_STAT_INC(txq->axq_qnum, a_retries);
Felix Fietkauda647622011-12-14 22:08:03 +0100386 fi->retries += count;
387
388 if (prev > 0)
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100389 return;
Sujithe8324352009-01-16 21:38:42 +0530390
Sujithe8324352009-01-16 21:38:42 +0530391 hdr = (struct ieee80211_hdr *)skb->data;
392 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_RETRY);
Felix Fietkauf11cc942011-09-15 12:59:49 +0200393 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
394 sizeof(*hdr), DMA_TO_DEVICE);
Sujithe8324352009-01-16 21:38:42 +0530395}
396
Felix Fietkau0a8cea82010-04-19 19:57:30 +0200397static struct ath_buf *ath_tx_get_buffer(struct ath_softc *sc)
398{
399 struct ath_buf *bf = NULL;
400
401 spin_lock_bh(&sc->tx.txbuflock);
402
403 if (unlikely(list_empty(&sc->tx.txbuf))) {
404 spin_unlock_bh(&sc->tx.txbuflock);
405 return NULL;
406 }
407
408 bf = list_first_entry(&sc->tx.txbuf, struct ath_buf, list);
409 list_del(&bf->list);
410
411 spin_unlock_bh(&sc->tx.txbuflock);
412
413 return bf;
414}
415
416static void ath_tx_return_buffer(struct ath_softc *sc, struct ath_buf *bf)
417{
418 spin_lock_bh(&sc->tx.txbuflock);
419 list_add_tail(&bf->list, &sc->tx.txbuf);
420 spin_unlock_bh(&sc->tx.txbuflock);
421}
422
Sujithd43f30152009-01-16 21:38:53 +0530423static struct ath_buf* ath_clone_txbuf(struct ath_softc *sc, struct ath_buf *bf)
424{
425 struct ath_buf *tbf;
426
Felix Fietkau0a8cea82010-04-19 19:57:30 +0200427 tbf = ath_tx_get_buffer(sc);
428 if (WARN_ON(!tbf))
Vasanthakumar Thiagarajan8a460972009-06-10 17:50:09 +0530429 return NULL;
Sujithd43f30152009-01-16 21:38:53 +0530430
431 ATH_TXBUF_RESET(tbf);
432
433 tbf->bf_mpdu = bf->bf_mpdu;
434 tbf->bf_buf_addr = bf->bf_buf_addr;
Vasanthakumar Thiagarajand826c832010-04-15 17:38:45 -0400435 memcpy(tbf->bf_desc, bf->bf_desc, sc->sc_ah->caps.tx_desc_len);
Sujithd43f30152009-01-16 21:38:53 +0530436 tbf->bf_state = bf->bf_state;
Felix Fietkau86c7d8d2013-09-14 15:46:33 +0200437 tbf->bf_state.stale = false;
Sujithd43f30152009-01-16 21:38:53 +0530438
439 return tbf;
440}
441
Felix Fietkaub572d032010-11-14 15:20:07 +0100442static void ath_tx_count_frames(struct ath_softc *sc, struct ath_buf *bf,
443 struct ath_tx_status *ts, int txok,
444 int *nframes, int *nbad)
445{
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100446 struct ath_frame_info *fi;
Felix Fietkaub572d032010-11-14 15:20:07 +0100447 u16 seq_st = 0;
448 u32 ba[WME_BA_BMP_SIZE >> 5];
449 int ba_index;
450 int isaggr = 0;
451
452 *nbad = 0;
453 *nframes = 0;
454
Felix Fietkaub572d032010-11-14 15:20:07 +0100455 isaggr = bf_isaggr(bf);
456 if (isaggr) {
457 seq_st = ts->ts_seqnum;
458 memcpy(ba, &ts->ba_low, WME_BA_BMP_SIZE >> 3);
459 }
460
461 while (bf) {
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100462 fi = get_frame_info(bf->bf_mpdu);
Felix Fietkau6a0ddae2011-08-28 00:32:23 +0200463 ba_index = ATH_BA_INDEX(seq_st, bf->bf_state.seqno);
Felix Fietkaub572d032010-11-14 15:20:07 +0100464
465 (*nframes)++;
466 if (!txok || (isaggr && !ATH_BA_ISSET(ba, ba_index)))
467 (*nbad)++;
468
469 bf = bf->bf_next;
470 }
471}
472
473
Sujithd43f30152009-01-16 21:38:53 +0530474static void ath_tx_complete_aggr(struct ath_softc *sc, struct ath_txq *txq,
475 struct ath_buf *bf, struct list_head *bf_q,
Felix Fietkaud94a4612016-09-02 19:46:12 +0300476 struct ieee80211_sta *sta,
Felix Fietkau315c4572016-09-02 19:46:13 +0300477 struct ath_atx_tid *tid,
Felix Fietkau13815592013-01-20 18:51:53 +0100478 struct ath_tx_status *ts, int txok)
Sujithe8324352009-01-16 21:38:42 +0530479{
480 struct ath_node *an = NULL;
481 struct sk_buff *skb;
Sujith1286ec62009-01-27 13:30:37 +0530482 struct ieee80211_hdr *hdr;
Luis R. Rodriguez76d5a9e2009-11-02 16:08:34 -0800483 struct ieee80211_tx_info *tx_info;
Sujithd43f30152009-01-16 21:38:53 +0530484 struct ath_buf *bf_next, *bf_last = bf->bf_lastbf;
Felix Fietkau56dc6332011-08-28 00:32:22 +0200485 struct list_head bf_head;
486 struct sk_buff_head bf_pending;
Felix Fietkau156369f2011-12-14 22:08:04 +0100487 u16 seq_st = 0, acked_cnt = 0, txfail_cnt = 0, seq_first;
Sujithe8324352009-01-16 21:38:42 +0530488 u32 ba[WME_BA_BMP_SIZE >> 5];
Vasanthakumar Thiagarajan0934af22009-03-18 20:22:00 +0530489 int isaggr, txfail, txpending, sendbar = 0, needreset = 0, nbad = 0;
Sven Eckelmann6fe7cc72012-10-29 13:25:20 +0100490 bool rc_update = true, isba;
Felix Fietkau78c46532010-06-25 01:26:16 +0200491 struct ieee80211_tx_rate rates[4];
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100492 struct ath_frame_info *fi;
Björn Smedmanebd02282010-10-10 22:44:39 +0200493 int nframes;
Felix Fietkaudaa5c402011-10-07 02:28:15 +0200494 bool flush = !!(ts->ts_status & ATH9K_TX_FLUSH);
Felix Fietkauda647622011-12-14 22:08:03 +0100495 int i, retries;
Felix Fietkau156369f2011-12-14 22:08:04 +0100496 int bar_index = -1;
Sujithe8324352009-01-16 21:38:42 +0530497
Sujitha22be222009-03-30 15:28:36 +0530498 skb = bf->bf_mpdu;
Sujith1286ec62009-01-27 13:30:37 +0530499 hdr = (struct ieee80211_hdr *)skb->data;
Sujithe8324352009-01-16 21:38:42 +0530500
Luis R. Rodriguez76d5a9e2009-11-02 16:08:34 -0800501 tx_info = IEEE80211_SKB_CB(skb);
Luis R. Rodriguez76d5a9e2009-11-02 16:08:34 -0800502
Felix Fietkau79acac02013-04-22 23:11:44 +0200503 memcpy(rates, bf->rates, sizeof(rates));
Felix Fietkau78c46532010-06-25 01:26:16 +0200504
Felix Fietkauda647622011-12-14 22:08:03 +0100505 retries = ts->ts_longretry + 1;
506 for (i = 0; i < ts->ts_rateindex; i++)
507 retries += rates[i].count;
508
Sujith1286ec62009-01-27 13:30:37 +0530509 if (!sta) {
Felix Fietkau31e79a52010-07-12 23:16:34 +0200510 INIT_LIST_HEAD(&bf_head);
511 while (bf) {
512 bf_next = bf->bf_next;
513
Felix Fietkau50676b82013-08-10 15:59:16 +0200514 if (!bf->bf_state.stale || bf_next != NULL)
Felix Fietkau31e79a52010-07-12 23:16:34 +0200515 list_move_tail(&bf->list, &bf_head);
516
Felix Fietkaud94a4612016-09-02 19:46:12 +0300517 ath_tx_complete_buf(sc, bf, txq, &bf_head, NULL, ts, 0);
Felix Fietkau31e79a52010-07-12 23:16:34 +0200518
519 bf = bf_next;
520 }
Sujith1286ec62009-01-27 13:30:37 +0530521 return;
Sujithe8324352009-01-16 21:38:42 +0530522 }
523
Sujith1286ec62009-01-27 13:30:37 +0530524 an = (struct ath_node *)sta->drv_priv;
Felix Fietkau156369f2011-12-14 22:08:04 +0100525 seq_first = tid->seq_start;
Sven Eckelmann6fe7cc72012-10-29 13:25:20 +0100526 isba = ts->ts_flags & ATH9K_TX_BA;
Sujith1286ec62009-01-27 13:30:37 +0530527
Felix Fietkaub11b1602010-07-11 12:48:44 +0200528 /*
529 * The hardware occasionally sends a tx status for the wrong TID.
530 * In this case, the BA status cannot be considered valid and all
531 * subframes need to be retransmitted
Sven Eckelmann6fe7cc72012-10-29 13:25:20 +0100532 *
533 * Only BlockAcks have a TID and therefore normal Acks cannot be
534 * checked
Felix Fietkaub11b1602010-07-11 12:48:44 +0200535 */
Felix Fietkau1803d022013-08-06 14:18:04 +0200536 if (isba && tid->tidno != ts->tid)
Felix Fietkaub11b1602010-07-11 12:48:44 +0200537 txok = false;
538
Sujithe8324352009-01-16 21:38:42 +0530539 isaggr = bf_isaggr(bf);
Sujithd43f30152009-01-16 21:38:53 +0530540 memset(ba, 0, WME_BA_BMP_SIZE >> 3);
Sujithe8324352009-01-16 21:38:42 +0530541
Sujithd43f30152009-01-16 21:38:53 +0530542 if (isaggr && txok) {
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700543 if (ts->ts_flags & ATH9K_TX_BA) {
544 seq_st = ts->ts_seqnum;
545 memcpy(ba, &ts->ba_low, WME_BA_BMP_SIZE >> 3);
Sujithe8324352009-01-16 21:38:42 +0530546 } else {
Sujithd43f30152009-01-16 21:38:53 +0530547 /*
548 * AR5416 can become deaf/mute when BA
549 * issue happens. Chip needs to be reset.
550 * But AP code may have sychronization issues
551 * when perform internal reset in this routine.
552 * Only enable reset in STA mode for now.
553 */
Sujith2660b812009-02-09 13:27:26 +0530554 if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION)
Sujithd43f30152009-01-16 21:38:53 +0530555 needreset = 1;
Sujithe8324352009-01-16 21:38:42 +0530556 }
557 }
558
Felix Fietkau56dc6332011-08-28 00:32:22 +0200559 __skb_queue_head_init(&bf_pending);
Sujithe8324352009-01-16 21:38:42 +0530560
Felix Fietkaub572d032010-11-14 15:20:07 +0100561 ath_tx_count_frames(sc, bf, ts, txok, &nframes, &nbad);
Sujithe8324352009-01-16 21:38:42 +0530562 while (bf) {
Felix Fietkau6a0ddae2011-08-28 00:32:23 +0200563 u16 seqno = bf->bf_state.seqno;
564
Felix Fietkauf0b82202011-01-15 14:30:15 +0100565 txfail = txpending = sendbar = 0;
Sujithe8324352009-01-16 21:38:42 +0530566 bf_next = bf->bf_next;
567
Felix Fietkau78c46532010-06-25 01:26:16 +0200568 skb = bf->bf_mpdu;
569 tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100570 fi = get_frame_info(skb);
Felix Fietkau78c46532010-06-25 01:26:16 +0200571
Felix Fietkau897d7fd2013-08-06 14:18:09 +0200572 if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno) ||
573 !tid->active) {
Felix Fietkau08c96ab2013-05-18 21:28:15 +0200574 /*
575 * Outside of the current BlockAck window,
576 * maybe part of a previous session
577 */
578 txfail = 1;
579 } else if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, seqno))) {
Sujithe8324352009-01-16 21:38:42 +0530580 /* transmit completion, subframe is
581 * acked by block ack */
Vasanthakumar Thiagarajan0934af22009-03-18 20:22:00 +0530582 acked_cnt++;
Sujithe8324352009-01-16 21:38:42 +0530583 } else if (!isaggr && txok) {
584 /* transmit completion */
Vasanthakumar Thiagarajan0934af22009-03-18 20:22:00 +0530585 acked_cnt++;
Felix Fietkaub0477012011-12-14 22:08:05 +0100586 } else if (flush) {
587 txpending = 1;
588 } else if (fi->retries < ATH_MAX_SW_RETRIES) {
589 if (txok || !an->sleeping)
590 ath_tx_set_retry(sc, txq, bf->bf_mpdu,
591 retries);
Felix Fietkau55195412011-04-17 23:28:09 +0200592
Felix Fietkaub0477012011-12-14 22:08:05 +0100593 txpending = 1;
594 } else {
595 txfail = 1;
596 txfail_cnt++;
597 bar_index = max_t(int, bar_index,
598 ATH_BA_INDEX(seq_first, seqno));
Sujithe8324352009-01-16 21:38:42 +0530599 }
600
Felix Fietkaufce041b2011-05-19 12:20:25 +0200601 /*
602 * Make sure the last desc is reclaimed if it
603 * not a holding desc.
604 */
Felix Fietkau56dc6332011-08-28 00:32:22 +0200605 INIT_LIST_HEAD(&bf_head);
Felix Fietkau50676b82013-08-10 15:59:16 +0200606 if (bf_next != NULL || !bf_last->bf_state.stale)
Sujithd43f30152009-01-16 21:38:53 +0530607 list_move_tail(&bf->list, &bf_head);
Sujithe8324352009-01-16 21:38:42 +0530608
Felix Fietkau08c96ab2013-05-18 21:28:15 +0200609 if (!txpending) {
Sujithe8324352009-01-16 21:38:42 +0530610 /*
611 * complete the acked-ones/xretried ones; update
612 * block-ack window
613 */
Felix Fietkau6a0ddae2011-08-28 00:32:23 +0200614 ath_tx_update_baw(sc, tid, seqno);
Sujithe8324352009-01-16 21:38:42 +0530615
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +0530616 if (rc_update && (acked_cnt == 1 || txfail_cnt == 1)) {
Felix Fietkau78c46532010-06-25 01:26:16 +0200617 memcpy(tx_info->control.rates, rates, sizeof(rates));
Felix Fietkau3afd21e2011-09-14 21:24:26 +0200618 ath_tx_rc_status(sc, bf, ts, nframes, nbad, txok);
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +0530619 rc_update = false;
Lorenzo Bianconi982e0392014-09-16 02:13:12 +0200620 if (bf == bf->bf_lastbf)
621 ath_dynack_sample_tx_ts(sc->sc_ah,
622 bf->bf_mpdu,
623 ts);
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +0530624 }
625
Felix Fietkaud94a4612016-09-02 19:46:12 +0300626 ath_tx_complete_buf(sc, bf, txq, &bf_head, sta, ts,
Felix Fietkau156369f2011-12-14 22:08:04 +0100627 !txfail);
Sujithe8324352009-01-16 21:38:42 +0530628 } else {
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200629 if (tx_info->flags & IEEE80211_TX_STATUS_EOSP) {
630 tx_info->flags &= ~IEEE80211_TX_STATUS_EOSP;
631 ieee80211_sta_eosp(sta);
632 }
Sujithd43f30152009-01-16 21:38:53 +0530633 /* retry the un-acked ones */
Felix Fietkau50676b82013-08-10 15:59:16 +0200634 if (bf->bf_next == NULL && bf_last->bf_state.stale) {
Felix Fietkaub0477012011-12-14 22:08:05 +0100635 struct ath_buf *tbf;
Sujithe8324352009-01-16 21:38:42 +0530636
Felix Fietkaub0477012011-12-14 22:08:05 +0100637 tbf = ath_clone_txbuf(sc, bf_last);
638 /*
639 * Update tx baw and complete the
640 * frame with failed status if we
641 * run out of tx buf.
642 */
643 if (!tbf) {
Felix Fietkaub0477012011-12-14 22:08:05 +0100644 ath_tx_update_baw(sc, tid, seqno);
Vasanthakumar Thiagarajanc41d92d2009-07-14 20:17:11 -0400645
Felix Fietkaub0477012011-12-14 22:08:05 +0100646 ath_tx_complete_buf(sc, bf, txq,
Felix Fietkaud94a4612016-09-02 19:46:12 +0300647 &bf_head, NULL, ts,
648 0);
Felix Fietkaub0477012011-12-14 22:08:05 +0100649 bar_index = max_t(int, bar_index,
650 ATH_BA_INDEX(seq_first, seqno));
651 break;
Vasanthakumar Thiagarajanc41d92d2009-07-14 20:17:11 -0400652 }
Felix Fietkaub0477012011-12-14 22:08:05 +0100653
654 fi->bf = tbf;
Sujithe8324352009-01-16 21:38:42 +0530655 }
656
657 /*
658 * Put this buffer to the temporary pending
659 * queue to retain ordering
660 */
Felix Fietkau56dc6332011-08-28 00:32:22 +0200661 __skb_queue_tail(&bf_pending, skb);
Sujithe8324352009-01-16 21:38:42 +0530662 }
663
664 bf = bf_next;
665 }
666
Felix Fietkau4cee7862010-07-23 03:53:16 +0200667 /* prepend un-acked frames to the beginning of the pending frame queue */
Felix Fietkau56dc6332011-08-28 00:32:22 +0200668 if (!skb_queue_empty(&bf_pending)) {
Felix Fietkau55195412011-04-17 23:28:09 +0200669 if (an->sleeping)
Johannes Berg042ec452011-09-29 16:04:26 +0200670 ieee80211_sta_set_buffered(sta, tid->tidno, true);
Felix Fietkau55195412011-04-17 23:28:09 +0200671
Felix Fietkaubb195ff2013-08-06 14:18:03 +0200672 skb_queue_splice_tail(&bf_pending, &tid->retry_q);
Felix Fietkau26a64252011-10-07 02:28:14 +0200673 if (!an->sleeping) {
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +0200674 ath_tx_queue_tid(sc, tid);
Felix Fietkau26a64252011-10-07 02:28:14 +0200675
Sujith Manoharanadfbda62012-08-29 09:20:42 +0530676 if (ts->ts_status & (ATH9K_TXERR_FILT | ATH9K_TXERR_XRETRY))
Felix Fietkau592fa222015-07-22 13:06:13 +0200677 tid->clear_ps_filter = true;
Felix Fietkau26a64252011-10-07 02:28:14 +0200678 }
Felix Fietkau4cee7862010-07-23 03:53:16 +0200679 }
680
Felix Fietkau23de5dc2011-12-19 16:45:54 +0100681 if (bar_index >= 0) {
682 u16 bar_seq = ATH_BA_INDEX2SEQ(seq_first, bar_index);
683
684 if (BAW_WITHIN(tid->seq_start, tid->baw_size, bar_seq))
685 tid->bar_index = ATH_BA_INDEX(tid->seq_start, bar_seq);
686
687 ath_txq_unlock(sc, txq);
688 ath_send_bar(tid, ATH_BA_INDEX2SEQ(seq_first, bar_index + 1));
689 ath_txq_lock(sc, txq);
690 }
691
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530692 if (needreset)
693 ath9k_queue_reset(sc, RESET_TYPE_TX_ERROR);
Sujithe8324352009-01-16 21:38:42 +0530694}
695
Felix Fietkau81b51952013-01-20 18:51:54 +0100696static bool bf_is_ampdu_not_probing(struct ath_buf *bf)
697{
698 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(bf->bf_mpdu);
699 return bf_isampdu(bf) && !(info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE);
700}
701
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +0200702static void ath_tx_count_airtime(struct ath_softc *sc, struct ath_txq *txq,
703 struct ath_buf *bf, struct ath_tx_status *ts)
704{
705 struct ath_node *an;
706 struct ath_acq *acq = &sc->cur_chan->acq[txq->mac80211_qnum];
707 struct sk_buff *skb;
708 struct ieee80211_hdr *hdr;
709 struct ieee80211_hw *hw = sc->hw;
710 struct ieee80211_tx_rate rates[4];
711 struct ieee80211_sta *sta;
712 int i;
713 u32 airtime = 0;
714
715 skb = bf->bf_mpdu;
716 if(!skb)
717 return;
718
719 hdr = (struct ieee80211_hdr *)skb->data;
720 memcpy(rates, bf->rates, sizeof(rates));
721
722 rcu_read_lock();
723
724 sta = ieee80211_find_sta_by_ifaddr(hw, hdr->addr1, hdr->addr2);
725 if(!sta)
726 goto exit;
727
728
729 an = (struct ath_node *) sta->drv_priv;
730
731 airtime += ts->duration * (ts->ts_longretry + 1);
732
733 for(i=0; i < ts->ts_rateindex; i++)
734 airtime += ath9k_hw_get_duration(sc->sc_ah, bf->bf_desc, i) * rates[i].count;
735
736 if (!!(sc->airtime_flags & AIRTIME_USE_TX)) {
737 spin_lock_bh(&acq->lock);
738 an->airtime_deficit[txq->mac80211_qnum] -= airtime;
739 if (an->airtime_deficit[txq->mac80211_qnum] <= 0)
740 __ath_tx_queue_tid(sc, ath_get_skb_tid(sc, an, skb));
741 spin_unlock_bh(&acq->lock);
742 }
743 ath_debug_airtime(sc, an, 0, airtime);
744
745exit:
746 rcu_read_unlock();
747}
748
Felix Fietkau81b51952013-01-20 18:51:54 +0100749static void ath_tx_process_buffer(struct ath_softc *sc, struct ath_txq *txq,
750 struct ath_tx_status *ts, struct ath_buf *bf,
751 struct list_head *bf_head)
752{
Felix Fietkaud94a4612016-09-02 19:46:12 +0300753 struct ieee80211_hw *hw = sc->hw;
Felix Fietkau0c585dd2013-05-17 12:58:25 +0200754 struct ieee80211_tx_info *info;
Felix Fietkaud94a4612016-09-02 19:46:12 +0300755 struct ieee80211_sta *sta;
756 struct ieee80211_hdr *hdr;
Felix Fietkau315c4572016-09-02 19:46:13 +0300757 struct ath_atx_tid *tid = NULL;
Felix Fietkau81b51952013-01-20 18:51:54 +0100758 bool txok, flush;
759
760 txok = !(ts->ts_status & ATH9K_TXERR_MASK);
761 flush = !!(ts->ts_status & ATH9K_TX_FLUSH);
762 txq->axq_tx_inprogress = false;
763
764 txq->axq_depth--;
765 if (bf_is_ampdu_not_probing(bf))
766 txq->axq_ampdu_depth--;
767
Felix Fietkau315dd112014-09-30 11:24:23 +0200768 ts->duration = ath9k_hw_get_duration(sc->sc_ah, bf->bf_desc,
769 ts->ts_rateindex);
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +0200770 ath_tx_count_airtime(sc, txq, bf, ts);
Felix Fietkaud94a4612016-09-02 19:46:12 +0300771
772 hdr = (struct ieee80211_hdr *) bf->bf_mpdu->data;
773 sta = ieee80211_find_sta_by_ifaddr(hw, hdr->addr1, hdr->addr2);
Felix Fietkau315c4572016-09-02 19:46:13 +0300774 if (sta) {
775 struct ath_node *an = (struct ath_node *)sta->drv_priv;
776 tid = ath_get_skb_tid(sc, an, bf->bf_mpdu);
777 if (ts->ts_status & (ATH9K_TXERR_FILT | ATH9K_TXERR_XRETRY))
778 tid->clear_ps_filter = true;
779 }
Felix Fietkaud94a4612016-09-02 19:46:12 +0300780
Felix Fietkau81b51952013-01-20 18:51:54 +0100781 if (!bf_isampdu(bf)) {
Felix Fietkau0c585dd2013-05-17 12:58:25 +0200782 if (!flush) {
783 info = IEEE80211_SKB_CB(bf->bf_mpdu);
784 memcpy(info->control.rates, bf->rates,
785 sizeof(info->control.rates));
Felix Fietkau81b51952013-01-20 18:51:54 +0100786 ath_tx_rc_status(sc, bf, ts, 1, txok ? 0 : 1, txok);
Lorenzo Bianconi982e0392014-09-16 02:13:12 +0200787 ath_dynack_sample_tx_ts(sc->sc_ah, bf->bf_mpdu, ts);
Felix Fietkau0c585dd2013-05-17 12:58:25 +0200788 }
Felix Fietkaud94a4612016-09-02 19:46:12 +0300789 ath_tx_complete_buf(sc, bf, txq, bf_head, sta, ts, txok);
Felix Fietkau81b51952013-01-20 18:51:54 +0100790 } else
Felix Fietkau315c4572016-09-02 19:46:13 +0300791 ath_tx_complete_aggr(sc, txq, bf, bf_head, sta, tid, ts, txok);
Felix Fietkau81b51952013-01-20 18:51:54 +0100792
Felix Fietkau73364b02013-08-06 14:18:08 +0200793 if (!flush)
Felix Fietkau81b51952013-01-20 18:51:54 +0100794 ath_txq_schedule(sc, txq);
795}
796
Rajkumar Manoharan1a6e9d02011-08-23 12:32:57 +0530797static bool ath_lookup_legacy(struct ath_buf *bf)
798{
799 struct sk_buff *skb;
800 struct ieee80211_tx_info *tx_info;
801 struct ieee80211_tx_rate *rates;
802 int i;
803
804 skb = bf->bf_mpdu;
805 tx_info = IEEE80211_SKB_CB(skb);
806 rates = tx_info->control.rates;
807
Felix Fietkau059ee092011-08-27 10:25:27 +0200808 for (i = 0; i < 4; i++) {
809 if (!rates[i].count || rates[i].idx < 0)
810 break;
811
Rajkumar Manoharan1a6e9d02011-08-23 12:32:57 +0530812 if (!(rates[i].flags & IEEE80211_TX_RC_MCS))
813 return true;
814 }
815
816 return false;
817}
818
Sujithe8324352009-01-16 21:38:42 +0530819static u32 ath_lookup_rate(struct ath_softc *sc, struct ath_buf *bf,
820 struct ath_atx_tid *tid)
821{
Sujithe8324352009-01-16 21:38:42 +0530822 struct sk_buff *skb;
823 struct ieee80211_tx_info *tx_info;
824 struct ieee80211_tx_rate *rates;
Sujithd43f30152009-01-16 21:38:53 +0530825 u32 max_4ms_framelen, frmlen;
Sujith Manoharanc0ac53f2012-02-22 12:40:38 +0530826 u16 aggr_limit, bt_aggr_limit, legacy = 0;
Felix Fietkau592fa222015-07-22 13:06:13 +0200827 int q = tid->txq->mac80211_qnum;
Sujithe8324352009-01-16 21:38:42 +0530828 int i;
829
Sujitha22be222009-03-30 15:28:36 +0530830 skb = bf->bf_mpdu;
Sujithe8324352009-01-16 21:38:42 +0530831 tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau0c585dd2013-05-17 12:58:25 +0200832 rates = bf->rates;
Sujithe8324352009-01-16 21:38:42 +0530833
834 /*
835 * Find the lowest frame length among the rate series that will have a
Felix Fietkauaa5955c2012-07-15 19:53:36 +0200836 * 4ms (or TXOP limited) transmit duration.
Sujithe8324352009-01-16 21:38:42 +0530837 */
838 max_4ms_framelen = ATH_AMPDU_LIMIT_MAX;
839
840 for (i = 0; i < 4; i++) {
Felix Fietkaub0477012011-12-14 22:08:05 +0100841 int modeidx;
Sujithe8324352009-01-16 21:38:42 +0530842
Felix Fietkaub0477012011-12-14 22:08:05 +0100843 if (!rates[i].count)
844 continue;
Felix Fietkau0e668cd2010-04-19 19:57:32 +0200845
Felix Fietkaub0477012011-12-14 22:08:05 +0100846 if (!(rates[i].flags & IEEE80211_TX_RC_MCS)) {
847 legacy = 1;
848 break;
Sujithe8324352009-01-16 21:38:42 +0530849 }
Felix Fietkaub0477012011-12-14 22:08:05 +0100850
851 if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
852 modeidx = MCS_HT40;
853 else
854 modeidx = MCS_HT20;
855
856 if (rates[i].flags & IEEE80211_TX_RC_SHORT_GI)
857 modeidx++;
858
Felix Fietkauaa5955c2012-07-15 19:53:36 +0200859 frmlen = sc->tx.max_aggr_framelen[q][modeidx][rates[i].idx];
Felix Fietkaub0477012011-12-14 22:08:05 +0100860 max_4ms_framelen = min(max_4ms_framelen, frmlen);
Sujithe8324352009-01-16 21:38:42 +0530861 }
862
863 /*
864 * limit aggregate size by the minimum rate if rate selected is
865 * not a probe rate, if rate selected is a probe rate then
866 * avoid aggregation of this packet.
867 */
868 if (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE || legacy)
869 return 0;
870
Sujith Manoharanc0ac53f2012-02-22 12:40:38 +0530871 aggr_limit = min(max_4ms_framelen, (u32)ATH_AMPDU_LIMIT_MAX);
872
873 /*
874 * Override the default aggregation limit for BTCOEX.
875 */
876 bt_aggr_limit = ath9k_btcoex_aggr_limit(sc, max_4ms_framelen);
877 if (bt_aggr_limit)
878 aggr_limit = bt_aggr_limit;
Sujithe8324352009-01-16 21:38:42 +0530879
Sujith4ef70842009-07-23 15:32:41 +0530880 if (tid->an->maxampdu)
881 aggr_limit = min(aggr_limit, tid->an->maxampdu);
Sujithe8324352009-01-16 21:38:42 +0530882
883 return aggr_limit;
884}
885
886/*
Sujithd43f30152009-01-16 21:38:53 +0530887 * Returns the number of delimiters to be added to
Sujithe8324352009-01-16 21:38:42 +0530888 * meet the minimum required mpdudensity.
Sujithe8324352009-01-16 21:38:42 +0530889 */
890static int ath_compute_num_delims(struct ath_softc *sc, struct ath_atx_tid *tid,
Rajkumar Manoharan7a12dfd2011-08-13 10:28:08 +0530891 struct ath_buf *bf, u16 frmlen,
892 bool first_subfrm)
Sujithe8324352009-01-16 21:38:42 +0530893{
Rajkumar Manoharan7a12dfd2011-08-13 10:28:08 +0530894#define FIRST_DESC_NDELIMS 60
Sujith4ef70842009-07-23 15:32:41 +0530895 u32 nsymbits, nsymbols;
Sujithe8324352009-01-16 21:38:42 +0530896 u16 minlen;
Felix Fietkau545750d2009-11-23 22:21:01 +0100897 u8 flags, rix;
Felix Fietkauc6663872010-04-19 19:57:33 +0200898 int width, streams, half_gi, ndelim, mindelim;
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100899 struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu);
Sujithe8324352009-01-16 21:38:42 +0530900
901 /* Select standard number of delimiters based on frame length alone */
902 ndelim = ATH_AGGR_GET_NDELIM(frmlen);
903
904 /*
905 * If encryption enabled, hardware requires some more padding between
906 * subframes.
907 * TODO - this could be improved to be dependent on the rate.
908 * The hardware can keep up at lower rates, but not higher rates
909 */
Rajkumar Manoharan4f6760b2011-07-01 18:37:33 +0530910 if ((fi->keyix != ATH9K_TXKEYIX_INVALID) &&
911 !(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA))
Sujithe8324352009-01-16 21:38:42 +0530912 ndelim += ATH_AGGR_ENCRYPTDELIM;
913
914 /*
Rajkumar Manoharan7a12dfd2011-08-13 10:28:08 +0530915 * Add delimiter when using RTS/CTS with aggregation
916 * and non enterprise AR9003 card
917 */
Felix Fietkau34597312011-08-29 18:57:54 +0200918 if (first_subfrm && !AR_SREV_9580_10_OR_LATER(sc->sc_ah) &&
919 (sc->sc_ah->ent_mode & AR_ENT_OTP_MIN_PKT_SIZE_DISABLE))
Rajkumar Manoharan7a12dfd2011-08-13 10:28:08 +0530920 ndelim = max(ndelim, FIRST_DESC_NDELIMS);
921
922 /*
Sujithe8324352009-01-16 21:38:42 +0530923 * Convert desired mpdu density from microeconds to bytes based
924 * on highest rate in rate series (i.e. first rate) to determine
925 * required minimum length for subframe. Take into account
926 * whether high rate is 20 or 40Mhz and half or full GI.
Sujith4ef70842009-07-23 15:32:41 +0530927 *
Sujithe8324352009-01-16 21:38:42 +0530928 * If there is no mpdu density restriction, no further calculation
929 * is needed.
930 */
Sujith4ef70842009-07-23 15:32:41 +0530931
932 if (tid->an->mpdudensity == 0)
Sujithe8324352009-01-16 21:38:42 +0530933 return ndelim;
934
Felix Fietkau79acac02013-04-22 23:11:44 +0200935 rix = bf->rates[0].idx;
936 flags = bf->rates[0].flags;
Sujithe8324352009-01-16 21:38:42 +0530937 width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0;
938 half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0;
939
940 if (half_gi)
Sujith4ef70842009-07-23 15:32:41 +0530941 nsymbols = NUM_SYMBOLS_PER_USEC_HALFGI(tid->an->mpdudensity);
Sujithe8324352009-01-16 21:38:42 +0530942 else
Sujith4ef70842009-07-23 15:32:41 +0530943 nsymbols = NUM_SYMBOLS_PER_USEC(tid->an->mpdudensity);
Sujithe8324352009-01-16 21:38:42 +0530944
945 if (nsymbols == 0)
946 nsymbols = 1;
947
Felix Fietkauc6663872010-04-19 19:57:33 +0200948 streams = HT_RC_2_STREAMS(rix);
949 nsymbits = bits_per_symbol[rix % 8][width] * streams;
Sujithe8324352009-01-16 21:38:42 +0530950 minlen = (nsymbols * nsymbits) / BITS_PER_BYTE;
951
Sujithe8324352009-01-16 21:38:42 +0530952 if (frmlen < minlen) {
Sujithe8324352009-01-16 21:38:42 +0530953 mindelim = (minlen - frmlen) / ATH_AGGR_DELIM_SZ;
954 ndelim = max(mindelim, ndelim);
955 }
956
957 return ndelim;
958}
959
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200960static struct ath_buf *
961ath_tx_get_tid_subframe(struct ath_softc *sc, struct ath_txq *txq,
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +0100962 struct ath_atx_tid *tid)
Sujithe8324352009-01-16 21:38:42 +0530963{
Felix Fietkau73364b02013-08-06 14:18:08 +0200964 struct ieee80211_tx_info *tx_info;
Felix Fietkau2d42efc2010-11-14 15:20:13 +0100965 struct ath_frame_info *fi;
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +0100966 struct sk_buff *skb, *first_skb = NULL;
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200967 struct ath_buf *bf;
Felix Fietkau6a0ddae2011-08-28 00:32:23 +0200968 u16 seqno;
Sujithe8324352009-01-16 21:38:42 +0530969
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200970 while (1) {
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +0100971 skb = ath_tid_dequeue(tid);
Felix Fietkau86a22ac2013-06-07 18:12:01 +0200972 if (!skb)
973 break;
974
Felix Fietkau56dc6332011-08-28 00:32:22 +0200975 fi = get_frame_info(skb);
976 bf = fi->bf;
Felix Fietkau44f1d262011-08-28 00:32:25 +0200977 if (!fi->bf)
Felix Fietkau249ee722012-10-03 21:07:52 +0200978 bf = ath_tx_setup_buffer(sc, txq, tid, skb);
Felix Fietkau563299d2013-08-13 12:33:30 +0200979 else
980 bf->bf_state.stale = false;
Felix Fietkau56dc6332011-08-28 00:32:22 +0200981
Felix Fietkau249ee722012-10-03 21:07:52 +0200982 if (!bf) {
Felix Fietkaua4943cc2013-06-30 12:02:13 +0200983 ath_txq_skb_done(sc, txq, skb);
Felix Fietkau249ee722012-10-03 21:07:52 +0200984 ieee80211_free_txskb(sc->hw, skb);
Felix Fietkau44f1d262011-08-28 00:32:25 +0200985 continue;
Felix Fietkau249ee722012-10-03 21:07:52 +0200986 }
Felix Fietkau44f1d262011-08-28 00:32:25 +0200987
Felix Fietkau73364b02013-08-06 14:18:08 +0200988 bf->bf_next = NULL;
989 bf->bf_lastbf = bf;
990
991 tx_info = IEEE80211_SKB_CB(skb);
992 tx_info->flags &= ~IEEE80211_TX_CTL_CLEAR_PS_FILT;
Felix Fietkauc01fac12014-07-23 15:40:54 +0200993
994 /*
995 * No aggregation session is running, but there may be frames
996 * from a previous session or a failed attempt in the queue.
997 * Send them out as normal data frames
998 */
999 if (!tid->active)
1000 tx_info->flags &= ~IEEE80211_TX_CTL_AMPDU;
1001
Felix Fietkau73364b02013-08-06 14:18:08 +02001002 if (!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) {
1003 bf->bf_state.bf_type = 0;
1004 return bf;
1005 }
1006
Felix Fietkau399c6482011-09-14 21:24:17 +02001007 bf->bf_state.bf_type = BUF_AMPDU | BUF_AGGR;
Felix Fietkau44f1d262011-08-28 00:32:25 +02001008 seqno = bf->bf_state.seqno;
Sujithe8324352009-01-16 21:38:42 +05301009
Sujithd43f30152009-01-16 21:38:53 +05301010 /* do not step over block-ack window */
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001011 if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno)) {
1012 __skb_queue_tail(&tid->retry_q, skb);
1013
1014 /* If there are other skbs in the retry q, they are
1015 * probably within the BAW, so loop immediately to get
1016 * one of them. Otherwise the queue can get stuck. */
1017 if (!skb_queue_is_first(&tid->retry_q, skb) &&
1018 !WARN_ON(skb == first_skb)) {
1019 if(!first_skb) /* infinite loop prevention */
1020 first_skb = skb;
1021 continue;
1022 }
Sujithe8324352009-01-16 21:38:42 +05301023 break;
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001024 }
Sujithe8324352009-01-16 21:38:42 +05301025
Felix Fietkauf9437542011-12-14 22:08:08 +01001026 if (tid->bar_index > ATH_BA_INDEX(tid->seq_start, seqno)) {
1027 struct ath_tx_status ts = {};
1028 struct list_head bf_head;
1029
1030 INIT_LIST_HEAD(&bf_head);
1031 list_add(&bf->list, &bf_head);
Felix Fietkauf9437542011-12-14 22:08:08 +01001032 ath_tx_update_baw(sc, tid, seqno);
Felix Fietkaud94a4612016-09-02 19:46:12 +03001033 ath_tx_complete_buf(sc, bf, txq, &bf_head, NULL, &ts, 0);
Felix Fietkauf9437542011-12-14 22:08:08 +01001034 continue;
1035 }
1036
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001037 return bf;
1038 }
1039
1040 return NULL;
1041}
1042
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001043static int
Felix Fietkau2800e822013-08-06 14:18:11 +02001044ath_tx_form_aggr(struct ath_softc *sc, struct ath_txq *txq,
1045 struct ath_atx_tid *tid, struct list_head *bf_q,
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001046 struct ath_buf *bf_first)
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001047{
1048#define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
Felix Fietkau2800e822013-08-06 14:18:11 +02001049 struct ath_buf *bf = bf_first, *bf_prev = NULL;
Felix Fietkaua1cd94d2013-08-06 14:18:06 +02001050 int nframes = 0, ndelim;
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001051 u16 aggr_limit = 0, al = 0, bpad = 0,
Felix Fietkaua1cd94d2013-08-06 14:18:06 +02001052 al_delta, h_baw = tid->baw_size / 2;
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001053 struct ieee80211_tx_info *tx_info;
1054 struct ath_frame_info *fi;
1055 struct sk_buff *skb;
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001056
Felix Fietkau2800e822013-08-06 14:18:11 +02001057
1058 bf = bf_first;
1059 aggr_limit = ath_lookup_rate(sc, bf, tid);
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001060
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001061 while (bf)
1062 {
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001063 skb = bf->bf_mpdu;
1064 fi = get_frame_info(skb);
1065
Sujithd43f30152009-01-16 21:38:53 +05301066 /* do not exceed aggregation limit */
Felix Fietkau2d42efc2010-11-14 15:20:13 +01001067 al_delta = ATH_AGGR_DELIM_SZ + fi->framelen;
Felix Fietkaua1cd94d2013-08-06 14:18:06 +02001068 if (nframes) {
1069 if (aggr_limit < al + bpad + al_delta ||
Felix Fietkau2800e822013-08-06 14:18:11 +02001070 ath_lookup_legacy(bf) || nframes >= h_baw)
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001071 goto stop;
Sujithe8324352009-01-16 21:38:42 +05301072
Felix Fietkaua1cd94d2013-08-06 14:18:06 +02001073 tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
Felix Fietkau2800e822013-08-06 14:18:11 +02001074 if ((tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) ||
1075 !(tx_info->flags & IEEE80211_TX_CTL_AMPDU))
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001076 goto stop;
Sujithe8324352009-01-16 21:38:42 +05301077 }
1078
Sujithd43f30152009-01-16 21:38:53 +05301079 /* add padding for previous frame to aggregation length */
Sujithe8324352009-01-16 21:38:42 +05301080 al += bpad + al_delta;
1081
1082 /*
1083 * Get the delimiters needed to meet the MPDU
1084 * density for this node.
1085 */
Rajkumar Manoharan7a12dfd2011-08-13 10:28:08 +05301086 ndelim = ath_compute_num_delims(sc, tid, bf_first, fi->framelen,
1087 !nframes);
Sujithe8324352009-01-16 21:38:42 +05301088 bpad = PADBYTES(al_delta) + (ndelim << 2);
1089
Rajkumar Manoharan7a12dfd2011-08-13 10:28:08 +05301090 nframes++;
Sujithe8324352009-01-16 21:38:42 +05301091 bf->bf_next = NULL;
Sujithe8324352009-01-16 21:38:42 +05301092
Sujithd43f30152009-01-16 21:38:53 +05301093 /* link buffers of this frame to the aggregate */
Felix Fietkau8fed1402013-08-06 14:18:07 +02001094 if (!fi->baw_tracked)
1095 ath_tx_addto_baw(sc, tid, bf);
Felix Fietkau399c6482011-09-14 21:24:17 +02001096 bf->bf_state.ndelim = ndelim;
Felix Fietkau56dc6332011-08-28 00:32:22 +02001097
Felix Fietkau56dc6332011-08-28 00:32:22 +02001098 list_add_tail(&bf->list, bf_q);
Felix Fietkau399c6482011-09-14 21:24:17 +02001099 if (bf_prev)
Sujithe8324352009-01-16 21:38:42 +05301100 bf_prev->bf_next = bf;
Felix Fietkau399c6482011-09-14 21:24:17 +02001101
Sujithe8324352009-01-16 21:38:42 +05301102 bf_prev = bf;
Sujithfec247c2009-07-27 12:08:16 +05301103
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001104 bf = ath_tx_get_tid_subframe(sc, txq, tid);
1105 }
1106 goto finish;
1107stop:
1108 __skb_queue_tail(&tid->retry_q, bf->bf_mpdu);
1109finish:
Felix Fietkau2800e822013-08-06 14:18:11 +02001110 bf = bf_first;
1111 bf->bf_lastbf = bf_prev;
1112
1113 if (bf == bf_prev) {
1114 al = get_frame_info(bf->bf_mpdu)->framelen;
1115 bf->bf_state.bf_type = BUF_AMPDU;
1116 } else {
1117 TX_STAT_INC(txq->axq_qnum, a_aggr);
1118 }
1119
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001120 return al;
Sujithe8324352009-01-16 21:38:42 +05301121#undef PADBYTES
1122}
1123
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001124/*
1125 * rix - rate index
1126 * pktlen - total bytes (delims + data + fcs + pads + pad delims)
1127 * width - 0 for 20 MHz, 1 for 40 MHz
1128 * half_gi - to use 4us v/s 3.6 us for symbol time
1129 */
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +02001130u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, int pktlen,
1131 int width, int half_gi, bool shortPreamble)
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001132{
1133 u32 nbits, nsymbits, duration, nsymbols;
1134 int streams;
1135
1136 /* find number of symbols: PLCP + data */
1137 streams = HT_RC_2_STREAMS(rix);
1138 nbits = (pktlen << 3) + OFDM_PLCP_BITS;
1139 nsymbits = bits_per_symbol[rix % 8][width] * streams;
1140 nsymbols = (nbits + nsymbits - 1) / nsymbits;
1141
1142 if (!half_gi)
1143 duration = SYMBOL_TIME(nsymbols);
1144 else
1145 duration = SYMBOL_TIME_HALFGI(nsymbols);
1146
1147 /* addup duration for legacy/ht training and signal fields */
1148 duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
1149
1150 return duration;
1151}
1152
Felix Fietkauaa5955c2012-07-15 19:53:36 +02001153static int ath_max_framelen(int usec, int mcs, bool ht40, bool sgi)
1154{
1155 int streams = HT_RC_2_STREAMS(mcs);
1156 int symbols, bits;
1157 int bytes = 0;
1158
Sylvain Roger Rieunier727b6622014-02-27 14:36:06 +01001159 usec -= L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
Felix Fietkauaa5955c2012-07-15 19:53:36 +02001160 symbols = sgi ? TIME_SYMBOLS_HALFGI(usec) : TIME_SYMBOLS(usec);
1161 bits = symbols * bits_per_symbol[mcs % 8][ht40] * streams;
1162 bits -= OFDM_PLCP_BITS;
1163 bytes = bits / 8;
Felix Fietkauaa5955c2012-07-15 19:53:36 +02001164 if (bytes > 65532)
1165 bytes = 65532;
1166
1167 return bytes;
1168}
1169
1170void ath_update_max_aggr_framelen(struct ath_softc *sc, int queue, int txop)
1171{
1172 u16 *cur_ht20, *cur_ht20_sgi, *cur_ht40, *cur_ht40_sgi;
1173 int mcs;
1174
1175 /* 4ms is the default (and maximum) duration */
1176 if (!txop || txop > 4096)
1177 txop = 4096;
1178
1179 cur_ht20 = sc->tx.max_aggr_framelen[queue][MCS_HT20];
1180 cur_ht20_sgi = sc->tx.max_aggr_framelen[queue][MCS_HT20_SGI];
1181 cur_ht40 = sc->tx.max_aggr_framelen[queue][MCS_HT40];
1182 cur_ht40_sgi = sc->tx.max_aggr_framelen[queue][MCS_HT40_SGI];
1183 for (mcs = 0; mcs < 32; mcs++) {
1184 cur_ht20[mcs] = ath_max_framelen(txop, mcs, false, false);
1185 cur_ht20_sgi[mcs] = ath_max_framelen(txop, mcs, false, true);
1186 cur_ht40[mcs] = ath_max_framelen(txop, mcs, true, false);
1187 cur_ht40_sgi[mcs] = ath_max_framelen(txop, mcs, true, true);
1188 }
1189}
1190
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001191static u8 ath_get_rate_txpower(struct ath_softc *sc, struct ath_buf *bf,
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001192 u8 rateidx, bool is_40, bool is_cck)
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001193{
1194 u8 max_power;
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001195 struct sk_buff *skb;
1196 struct ath_frame_info *fi;
1197 struct ieee80211_tx_info *info;
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001198 struct ath_hw *ah = sc->sc_ah;
1199
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001200 if (sc->tx99_state || !ah->tpc_enabled)
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001201 return MAX_RATE_POWER;
1202
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001203 skb = bf->bf_mpdu;
Lorenzo Bianconi97bf8612015-02-17 10:12:18 +01001204 fi = get_frame_info(skb);
Lorenzo Bianconif6738212015-04-08 20:51:57 +02001205 info = IEEE80211_SKB_CB(skb);
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001206
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001207 if (!AR_SREV_9300_20_OR_LATER(ah)) {
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001208 int txpower = fi->tx_power;
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001209
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001210 if (is_40) {
1211 u8 power_ht40delta;
1212 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
Martin Blumenstingl9bff7422016-12-05 13:27:35 +02001213 u16 eeprom_rev = ah->eep_ops->get_eeprom_rev(ah);
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001214
Martin Blumenstingl9bff7422016-12-05 13:27:35 +02001215 if (eeprom_rev >= AR5416_EEP_MINOR_VER_2) {
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001216 bool is_2ghz;
1217 struct modal_eep_header *pmodal;
1218
Johannes Berg57fbcce2016-04-12 15:56:15 +02001219 is_2ghz = info->band == NL80211_BAND_2GHZ;
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001220 pmodal = &eep->modalHeader[is_2ghz];
1221 power_ht40delta = pmodal->ht40PowerIncForPdadc;
1222 } else {
1223 power_ht40delta = 2;
1224 }
1225 txpower += power_ht40delta;
1226 }
1227
1228 if (AR_SREV_9287(ah) || AR_SREV_9285(ah) ||
1229 AR_SREV_9271(ah)) {
1230 txpower -= 2 * AR9287_PWR_TABLE_OFFSET_DB;
1231 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
1232 s8 power_offset;
1233
1234 power_offset = ah->eep_ops->get_eeprom(ah,
1235 EEP_PWR_TABLE_OFFSET);
1236 txpower -= 2 * power_offset;
1237 }
1238
1239 if (OLC_FOR_AR9280_20_LATER && is_cck)
1240 txpower -= 2;
1241
1242 txpower = max(txpower, 0);
Lorenzo Bianconif6738212015-04-08 20:51:57 +02001243 max_power = min_t(u8, ah->tx_power[rateidx], txpower);
1244
1245 /* XXX: clamp minimum TX power at 1 for AR9160 since if
1246 * max_power is set to 0, frames are transmitted at max
1247 * TX power
1248 */
1249 if (!max_power && !AR_SREV_9280_20_OR_LATER(ah))
1250 max_power = 1;
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001251 } else if (!bf->bf_state.bfs_paprd) {
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001252 if (rateidx < 8 && (info->flags & IEEE80211_TX_CTL_STBC))
Lorenzo Bianconi97bf8612015-02-17 10:12:18 +01001253 max_power = min_t(u8, ah->tx_power_stbc[rateidx],
Lorenzo Bianconif6738212015-04-08 20:51:57 +02001254 fi->tx_power);
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001255 else
Lorenzo Bianconi97bf8612015-02-17 10:12:18 +01001256 max_power = min_t(u8, ah->tx_power[rateidx],
Lorenzo Bianconif6738212015-04-08 20:51:57 +02001257 fi->tx_power);
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001258 } else {
1259 max_power = ah->paprd_training_power;
1260 }
Lorenzo Bianconif6738212015-04-08 20:51:57 +02001261
1262 return max_power;
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001263}
1264
Felix Fietkau493cf042011-09-14 21:24:22 +02001265static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf,
Sujith Manoharana3835e92013-07-04 12:59:47 +05301266 struct ath_tx_info *info, int len, bool rts)
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001267{
1268 struct ath_hw *ah = sc->sc_ah;
Oleksij Rempel13f71052014-02-25 14:48:50 +01001269 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001270 struct sk_buff *skb;
1271 struct ieee80211_tx_info *tx_info;
1272 struct ieee80211_tx_rate *rates;
1273 const struct ieee80211_rate *rate;
1274 struct ieee80211_hdr *hdr;
Felix Fietkau80b08a82012-06-15 03:04:53 +02001275 struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu);
Sujith Manoharana3835e92013-07-04 12:59:47 +05301276 u32 rts_thresh = sc->hw->wiphy->rts_threshold;
Felix Fietkau493cf042011-09-14 21:24:22 +02001277 int i;
1278 u8 rix = 0;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001279
1280 skb = bf->bf_mpdu;
1281 tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau79acac02013-04-22 23:11:44 +02001282 rates = bf->rates;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001283 hdr = (struct ieee80211_hdr *)skb->data;
Felix Fietkau493cf042011-09-14 21:24:22 +02001284
1285 /* set dur_update_en for l-sig computation except for PS-Poll frames */
1286 info->dur_update = !ieee80211_is_pspoll(hdr->frame_control);
Felix Fietkau80b08a82012-06-15 03:04:53 +02001287 info->rtscts_rate = fi->rtscts_rate;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001288
Felix Fietkau79acac02013-04-22 23:11:44 +02001289 for (i = 0; i < ARRAY_SIZE(bf->rates); i++) {
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001290 bool is_40, is_sgi, is_sp, is_cck;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001291 int phy;
1292
1293 if (!rates[i].count || (rates[i].idx < 0))
1294 continue;
1295
1296 rix = rates[i].idx;
Felix Fietkau493cf042011-09-14 21:24:22 +02001297 info->rates[i].Tries = rates[i].count;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001298
Sujith Manoharana3835e92013-07-04 12:59:47 +05301299 /*
1300 * Handle RTS threshold for unaggregated HT frames.
1301 */
1302 if (bf_isampdu(bf) && !bf_isaggr(bf) &&
1303 (rates[i].flags & IEEE80211_TX_RC_MCS) &&
1304 unlikely(rts_thresh != (u32) -1)) {
1305 if (!rts_thresh || (len > rts_thresh))
1306 rts = true;
1307 }
1308
1309 if (rts || rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Felix Fietkau493cf042011-09-14 21:24:22 +02001310 info->rates[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
1311 info->flags |= ATH9K_TXDESC_RTSENA;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001312 } else if (rates[i].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Felix Fietkau493cf042011-09-14 21:24:22 +02001313 info->rates[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
1314 info->flags |= ATH9K_TXDESC_CTSENA;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001315 }
1316
1317 if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
Felix Fietkau493cf042011-09-14 21:24:22 +02001318 info->rates[i].RateFlags |= ATH9K_RATESERIES_2040;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001319 if (rates[i].flags & IEEE80211_TX_RC_SHORT_GI)
Felix Fietkau493cf042011-09-14 21:24:22 +02001320 info->rates[i].RateFlags |= ATH9K_RATESERIES_HALFGI;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001321
1322 is_sgi = !!(rates[i].flags & IEEE80211_TX_RC_SHORT_GI);
1323 is_40 = !!(rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH);
1324 is_sp = !!(rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE);
1325
1326 if (rates[i].flags & IEEE80211_TX_RC_MCS) {
1327 /* MCS rates */
Felix Fietkau493cf042011-09-14 21:24:22 +02001328 info->rates[i].Rate = rix | 0x80;
1329 info->rates[i].ChSel = ath_txchainmask_reduction(sc,
1330 ah->txchainmask, info->rates[i].Rate);
1331 info->rates[i].PktDuration = ath_pkt_duration(sc, rix, len,
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001332 is_40, is_sgi, is_sp);
1333 if (rix < 8 && (tx_info->flags & IEEE80211_TX_CTL_STBC))
Felix Fietkau493cf042011-09-14 21:24:22 +02001334 info->rates[i].RateFlags |= ATH9K_RATESERIES_STBC;
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001335
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001336 info->txpower[i] = ath_get_rate_txpower(sc, bf, rix,
1337 is_40, false);
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001338 continue;
1339 }
1340
1341 /* legacy rates */
Oleksij Rempel13f71052014-02-25 14:48:50 +01001342 rate = &common->sbands[tx_info->band].bitrates[rates[i].idx];
Johannes Berg57fbcce2016-04-12 15:56:15 +02001343 if ((tx_info->band == NL80211_BAND_2GHZ) &&
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001344 !(rate->flags & IEEE80211_RATE_ERP_G))
1345 phy = WLAN_RC_PHY_CCK;
1346 else
1347 phy = WLAN_RC_PHY_OFDM;
1348
Felix Fietkau493cf042011-09-14 21:24:22 +02001349 info->rates[i].Rate = rate->hw_value;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001350 if (rate->hw_value_short) {
1351 if (rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
Felix Fietkau493cf042011-09-14 21:24:22 +02001352 info->rates[i].Rate |= rate->hw_value_short;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001353 } else {
1354 is_sp = false;
1355 }
1356
1357 if (bf->bf_state.bfs_paprd)
Felix Fietkau493cf042011-09-14 21:24:22 +02001358 info->rates[i].ChSel = ah->txchainmask;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001359 else
Felix Fietkau493cf042011-09-14 21:24:22 +02001360 info->rates[i].ChSel = ath_txchainmask_reduction(sc,
1361 ah->txchainmask, info->rates[i].Rate);
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001362
Felix Fietkau493cf042011-09-14 21:24:22 +02001363 info->rates[i].PktDuration = ath9k_hw_computetxtime(sc->sc_ah,
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001364 phy, rate->bitrate * 100, len, rix, is_sp);
Lorenzo Bianconi8b537682014-11-25 00:21:41 +01001365
Lorenzo Bianconi9ddad582014-12-30 23:10:19 +01001366 is_cck = IS_CCK_RATE(info->rates[i].Rate);
1367 info->txpower[i] = ath_get_rate_txpower(sc, bf, rix, false,
1368 is_cck);
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001369 }
1370
1371 /* For AR5416 - RTS cannot be followed by a frame larger than 8K */
1372 if (bf_isaggr(bf) && (len > sc->sc_ah->caps.rts_aggr_limit))
Felix Fietkau493cf042011-09-14 21:24:22 +02001373 info->flags &= ~ATH9K_TXDESC_RTSENA;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001374
1375 /* ATH9K_TXDESC_RTSENA and ATH9K_TXDESC_CTSENA are mutually exclusive. */
Felix Fietkau493cf042011-09-14 21:24:22 +02001376 if (info->flags & ATH9K_TXDESC_RTSENA)
1377 info->flags &= ~ATH9K_TXDESC_CTSENA;
Felix Fietkau38dad7b2011-09-14 21:24:18 +02001378}
1379
Felix Fietkau493cf042011-09-14 21:24:22 +02001380static enum ath9k_pkt_type get_hw_packet_type(struct sk_buff *skb)
1381{
1382 struct ieee80211_hdr *hdr;
1383 enum ath9k_pkt_type htype;
1384 __le16 fc;
1385
1386 hdr = (struct ieee80211_hdr *)skb->data;
1387 fc = hdr->frame_control;
1388
1389 if (ieee80211_is_beacon(fc))
1390 htype = ATH9K_PKT_TYPE_BEACON;
1391 else if (ieee80211_is_probe_resp(fc))
1392 htype = ATH9K_PKT_TYPE_PROBE_RESP;
1393 else if (ieee80211_is_atim(fc))
1394 htype = ATH9K_PKT_TYPE_ATIM;
1395 else if (ieee80211_is_pspoll(fc))
1396 htype = ATH9K_PKT_TYPE_PSPOLL;
1397 else
1398 htype = ATH9K_PKT_TYPE_NORMAL;
1399
1400 return htype;
1401}
1402
1403static void ath_tx_fill_desc(struct ath_softc *sc, struct ath_buf *bf,
1404 struct ath_txq *txq, int len)
Felix Fietkau399c6482011-09-14 21:24:17 +02001405{
1406 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001407 struct ath_buf *bf_first = NULL;
Felix Fietkau493cf042011-09-14 21:24:22 +02001408 struct ath_tx_info info;
Sujith Manoharana3835e92013-07-04 12:59:47 +05301409 u32 rts_thresh = sc->hw->wiphy->rts_threshold;
1410 bool rts = false;
Felix Fietkau399c6482011-09-14 21:24:17 +02001411
Felix Fietkau493cf042011-09-14 21:24:22 +02001412 memset(&info, 0, sizeof(info));
1413 info.is_first = true;
1414 info.is_last = true;
Felix Fietkau493cf042011-09-14 21:24:22 +02001415 info.qcu = txq->axq_qnum;
Felix Fietkau399c6482011-09-14 21:24:17 +02001416
Felix Fietkau399c6482011-09-14 21:24:17 +02001417 while (bf) {
Felix Fietkau493cf042011-09-14 21:24:22 +02001418 struct sk_buff *skb = bf->bf_mpdu;
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001419 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau493cf042011-09-14 21:24:22 +02001420 struct ath_frame_info *fi = get_frame_info(skb);
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001421 bool aggr = !!(bf->bf_state.bf_type & BUF_AGGR);
Felix Fietkau493cf042011-09-14 21:24:22 +02001422
1423 info.type = get_hw_packet_type(skb);
Felix Fietkau399c6482011-09-14 21:24:17 +02001424 if (bf->bf_next)
Felix Fietkau493cf042011-09-14 21:24:22 +02001425 info.link = bf->bf_next->bf_daddr;
Felix Fietkau399c6482011-09-14 21:24:17 +02001426 else
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001427 info.link = (sc->tx99_state) ? bf->bf_daddr : 0;
Felix Fietkau399c6482011-09-14 21:24:17 +02001428
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001429 if (!bf_first) {
1430 bf_first = bf;
1431
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001432 if (!sc->tx99_state)
1433 info.flags = ATH9K_TXDESC_INTREQ;
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001434 if ((tx_info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT) ||
1435 txq == sc->tx.uapsdq)
1436 info.flags |= ATH9K_TXDESC_CLRDMASK;
1437
1438 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
1439 info.flags |= ATH9K_TXDESC_NOACK;
1440 if (tx_info->flags & IEEE80211_TX_CTL_LDPC)
1441 info.flags |= ATH9K_TXDESC_LDPC;
1442
1443 if (bf->bf_state.bfs_paprd)
1444 info.flags |= (u32) bf->bf_state.bfs_paprd <<
1445 ATH9K_TXDESC_PAPRD_S;
1446
Sujith Manoharana3835e92013-07-04 12:59:47 +05301447 /*
1448 * mac80211 doesn't handle RTS threshold for HT because
1449 * the decision has to be taken based on AMPDU length
1450 * and aggregation is done entirely inside ath9k.
1451 * Set the RTS/CTS flag for the first subframe based
1452 * on the threshold.
1453 */
1454 if (aggr && (bf == bf_first) &&
1455 unlikely(rts_thresh != (u32) -1)) {
1456 /*
1457 * "len" is the size of the entire AMPDU.
1458 */
1459 if (!rts_thresh || (len > rts_thresh))
1460 rts = true;
1461 }
Felix Fietkaubbf807b2013-12-05 15:20:53 +01001462
1463 if (!aggr)
1464 len = fi->framelen;
1465
Sujith Manoharana3835e92013-07-04 12:59:47 +05301466 ath_buf_set_rate(sc, bf, &info, len, rts);
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001467 }
1468
John W. Linville42cecc32011-09-19 15:42:31 -04001469 info.buf_addr[0] = bf->bf_buf_addr;
1470 info.buf_len[0] = skb->len;
Felix Fietkau493cf042011-09-14 21:24:22 +02001471 info.pkt_len = fi->framelen;
1472 info.keyix = fi->keyix;
1473 info.keytype = fi->keytype;
1474
1475 if (aggr) {
Felix Fietkau399c6482011-09-14 21:24:17 +02001476 if (bf == bf_first)
Felix Fietkau493cf042011-09-14 21:24:22 +02001477 info.aggr = AGGR_BUF_FIRST;
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001478 else if (bf == bf_first->bf_lastbf)
Felix Fietkau493cf042011-09-14 21:24:22 +02001479 info.aggr = AGGR_BUF_LAST;
1480 else
1481 info.aggr = AGGR_BUF_MIDDLE;
Felix Fietkau399c6482011-09-14 21:24:17 +02001482
Felix Fietkau493cf042011-09-14 21:24:22 +02001483 info.ndelim = bf->bf_state.ndelim;
1484 info.aggr_len = len;
Felix Fietkau399c6482011-09-14 21:24:17 +02001485 }
1486
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001487 if (bf == bf_first->bf_lastbf)
1488 bf_first = NULL;
1489
Felix Fietkau493cf042011-09-14 21:24:22 +02001490 ath9k_hw_set_txdesc(ah, bf->bf_desc, &info);
Felix Fietkau399c6482011-09-14 21:24:17 +02001491 bf = bf->bf_next;
1492 }
1493}
1494
Felix Fietkau2800e822013-08-06 14:18:11 +02001495static void
1496ath_tx_form_burst(struct ath_softc *sc, struct ath_txq *txq,
1497 struct ath_atx_tid *tid, struct list_head *bf_q,
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001498 struct ath_buf *bf_first)
Felix Fietkau2800e822013-08-06 14:18:11 +02001499{
1500 struct ath_buf *bf = bf_first, *bf_prev = NULL;
Felix Fietkau2800e822013-08-06 14:18:11 +02001501 int nframes = 0;
1502
1503 do {
1504 struct ieee80211_tx_info *tx_info;
Felix Fietkau2800e822013-08-06 14:18:11 +02001505
1506 nframes++;
Felix Fietkau2800e822013-08-06 14:18:11 +02001507 list_add_tail(&bf->list, bf_q);
1508 if (bf_prev)
1509 bf_prev->bf_next = bf;
1510 bf_prev = bf;
1511
1512 if (nframes >= 2)
1513 break;
1514
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001515 bf = ath_tx_get_tid_subframe(sc, txq, tid);
Felix Fietkau2800e822013-08-06 14:18:11 +02001516 if (!bf)
1517 break;
1518
1519 tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001520 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
1521 __skb_queue_tail(&tid->retry_q, bf->bf_mpdu);
Felix Fietkau2800e822013-08-06 14:18:11 +02001522 break;
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001523 }
Felix Fietkau2800e822013-08-06 14:18:11 +02001524
1525 ath_set_rates(tid->an->vif, tid->an->sta, bf);
1526 } while (1);
1527}
1528
Felix Fietkau020f20f2013-08-06 14:18:12 +02001529static bool ath_tx_sched_aggr(struct ath_softc *sc, struct ath_txq *txq,
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +02001530 struct ath_atx_tid *tid)
Sujithe8324352009-01-16 21:38:42 +05301531{
Sujithd43f30152009-01-16 21:38:53 +05301532 struct ath_buf *bf;
Felix Fietkau399c6482011-09-14 21:24:17 +02001533 struct ieee80211_tx_info *tx_info;
Sujithe8324352009-01-16 21:38:42 +05301534 struct list_head bf_q;
Felix Fietkau2800e822013-08-06 14:18:11 +02001535 int aggr_len = 0;
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001536 bool aggr;
Sujithe8324352009-01-16 21:38:42 +05301537
Felix Fietkau020f20f2013-08-06 14:18:12 +02001538 if (!ath_tid_has_buffered(tid))
1539 return false;
Sujithe8324352009-01-16 21:38:42 +05301540
Felix Fietkau020f20f2013-08-06 14:18:12 +02001541 INIT_LIST_HEAD(&bf_q);
Sujithe8324352009-01-16 21:38:42 +05301542
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001543 bf = ath_tx_get_tid_subframe(sc, txq, tid);
Felix Fietkau020f20f2013-08-06 14:18:12 +02001544 if (!bf)
1545 return false;
Sujithe8324352009-01-16 21:38:42 +05301546
Felix Fietkau020f20f2013-08-06 14:18:12 +02001547 tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
1548 aggr = !!(tx_info->flags & IEEE80211_TX_CTL_AMPDU);
1549 if ((aggr && txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) ||
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001550 (!aggr && txq->axq_depth >= ATH_NON_AGGR_MIN_QDEPTH)) {
1551 __skb_queue_tail(&tid->retry_q, bf->bf_mpdu);
Felix Fietkau020f20f2013-08-06 14:18:12 +02001552 return false;
1553 }
Felix Fietkau2800e822013-08-06 14:18:11 +02001554
Felix Fietkau020f20f2013-08-06 14:18:12 +02001555 ath_set_rates(tid->an->vif, tid->an->sta, bf);
1556 if (aggr)
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001557 aggr_len = ath_tx_form_aggr(sc, txq, tid, &bf_q, bf);
Felix Fietkau020f20f2013-08-06 14:18:12 +02001558 else
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001559 ath_tx_form_burst(sc, txq, tid, &bf_q, bf);
Felix Fietkau2800e822013-08-06 14:18:11 +02001560
Felix Fietkau020f20f2013-08-06 14:18:12 +02001561 if (list_empty(&bf_q))
1562 return false;
Sujithe8324352009-01-16 21:38:42 +05301563
Felix Fietkau592fa222015-07-22 13:06:13 +02001564 if (tid->clear_ps_filter || tid->an->no_ps_filter) {
1565 tid->clear_ps_filter = false;
Felix Fietkau020f20f2013-08-06 14:18:12 +02001566 tx_info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1567 }
Sujithe8324352009-01-16 21:38:42 +05301568
Felix Fietkau020f20f2013-08-06 14:18:12 +02001569 ath_tx_fill_desc(sc, bf, txq, aggr_len);
1570 ath_tx_txqaddbuf(sc, txq, &bf_q, false);
1571 return true;
Sujithe8324352009-01-16 21:38:42 +05301572}
1573
Felix Fietkau231c3a12010-09-20 19:35:28 +02001574int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
1575 u16 tid, u16 *ssn)
Sujithe8324352009-01-16 21:38:42 +05301576{
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001577 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithe8324352009-01-16 21:38:42 +05301578 struct ath_atx_tid *txtid;
Felix Fietkau919123d2013-09-18 15:23:41 +02001579 struct ath_txq *txq;
Sujithe8324352009-01-16 21:38:42 +05301580 struct ath_node *an;
Sven Eckelmann313eb872012-06-25 07:15:22 +02001581 u8 density;
Sujithe8324352009-01-16 21:38:42 +05301582
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001583 ath_dbg(common, XMIT, "%s called\n", __func__);
1584
Sujithe8324352009-01-16 21:38:42 +05301585 an = (struct ath_node *)sta->drv_priv;
Sujithf83da962009-07-23 15:32:37 +05301586 txtid = ATH_AN_2_TID(an, tid);
Felix Fietkau592fa222015-07-22 13:06:13 +02001587 txq = txtid->txq;
Felix Fietkau919123d2013-09-18 15:23:41 +02001588
1589 ath_txq_lock(sc, txq);
Felix Fietkau231c3a12010-09-20 19:35:28 +02001590
Sven Eckelmann313eb872012-06-25 07:15:22 +02001591 /* update ampdu factor/density, they may have changed. This may happen
1592 * in HT IBSS when a beacon with HT-info is received after the station
1593 * has already been added.
1594 */
Sujith Manoharandd5ee592013-02-04 15:38:23 +05301595 if (sta->ht_cap.ht_supported) {
Sujith Manoharan5b502c82013-12-24 10:44:17 +05301596 an->maxampdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1597 sta->ht_cap.ampdu_factor)) - 1;
Sven Eckelmann313eb872012-06-25 07:15:22 +02001598 density = ath9k_parse_mpdudensity(sta->ht_cap.ampdu_density);
1599 an->mpdudensity = density;
1600 }
1601
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001602 txtid->active = true;
Felix Fietkau49447f22011-01-10 17:05:48 -07001603 *ssn = txtid->seq_start = txtid->seq_next;
Felix Fietkauf9437542011-12-14 22:08:08 +01001604 txtid->bar_index = -1;
Felix Fietkau231c3a12010-09-20 19:35:28 +02001605
Felix Fietkau2ed72222011-01-10 17:05:49 -07001606 memset(txtid->tx_buf, 0, sizeof(txtid->tx_buf));
1607 txtid->baw_head = txtid->baw_tail = 0;
1608
Felix Fietkau919123d2013-09-18 15:23:41 +02001609 ath_txq_unlock_complete(sc, txq);
1610
Felix Fietkau231c3a12010-09-20 19:35:28 +02001611 return 0;
Sujithe8324352009-01-16 21:38:42 +05301612}
1613
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001614void ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
Sujithe8324352009-01-16 21:38:42 +05301615{
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001616 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithe8324352009-01-16 21:38:42 +05301617 struct ath_node *an = (struct ath_node *)sta->drv_priv;
1618 struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid);
Felix Fietkau592fa222015-07-22 13:06:13 +02001619 struct ath_txq *txq = txtid->txq;
Sujithe8324352009-01-16 21:38:42 +05301620
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001621 ath_dbg(common, XMIT, "%s called\n", __func__);
1622
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001623 ath_txq_lock(sc, txq);
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001624 txtid->active = false;
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001625 ath_tx_flush_tid(sc, txtid);
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001626 ath_txq_unlock_complete(sc, txq);
Sujithe8324352009-01-16 21:38:42 +05301627}
1628
Johannes Berg042ec452011-09-29 16:04:26 +02001629void ath_tx_aggr_sleep(struct ieee80211_sta *sta, struct ath_softc *sc,
1630 struct ath_node *an)
Felix Fietkau55195412011-04-17 23:28:09 +02001631{
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001632 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau55195412011-04-17 23:28:09 +02001633 struct ath_atx_tid *tid;
Felix Fietkau55195412011-04-17 23:28:09 +02001634 struct ath_txq *txq;
Felix Fietkau55195412011-04-17 23:28:09 +02001635 int tidno;
1636
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001637 ath_dbg(common, XMIT, "%s called\n", __func__);
1638
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001639 for (tidno = 0; tidno < IEEE80211_NUM_TIDS; tidno++) {
1640 tid = ath_node_to_tid(an, tidno);
Felix Fietkau592fa222015-07-22 13:06:13 +02001641 txq = tid->txq;
Felix Fietkau55195412011-04-17 23:28:09 +02001642
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001643 ath_txq_lock(sc, txq);
Felix Fietkau55195412011-04-17 23:28:09 +02001644
Felix Fietkaud70d8482015-07-22 13:06:14 +02001645 if (list_empty(&tid->list)) {
Stanislaw Gruszka21f8aae2014-02-19 13:15:17 +01001646 ath_txq_unlock(sc, txq);
1647 continue;
1648 }
1649
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001650 if (!skb_queue_empty(&tid->retry_q))
1651 ieee80211_sta_set_buffered(sta, tid->tidno, true);
Felix Fietkau55195412011-04-17 23:28:09 +02001652
Felix Fietkaud70d8482015-07-22 13:06:14 +02001653 list_del_init(&tid->list);
Felix Fietkau55195412011-04-17 23:28:09 +02001654
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001655 ath_txq_unlock(sc, txq);
Johannes Berg042ec452011-09-29 16:04:26 +02001656 }
Felix Fietkau55195412011-04-17 23:28:09 +02001657}
1658
1659void ath_tx_aggr_wakeup(struct ath_softc *sc, struct ath_node *an)
1660{
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001661 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau55195412011-04-17 23:28:09 +02001662 struct ath_atx_tid *tid;
Felix Fietkau55195412011-04-17 23:28:09 +02001663 struct ath_txq *txq;
1664 int tidno;
1665
Janusz Dziedzic58bb9ca842015-11-27 09:37:06 +01001666 ath_dbg(common, XMIT, "%s called\n", __func__);
1667
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001668 for (tidno = 0; tidno < IEEE80211_NUM_TIDS; tidno++) {
1669 tid = ath_node_to_tid(an, tidno);
Felix Fietkau592fa222015-07-22 13:06:13 +02001670 txq = tid->txq;
Felix Fietkau55195412011-04-17 23:28:09 +02001671
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001672 ath_txq_lock(sc, txq);
Felix Fietkau592fa222015-07-22 13:06:13 +02001673 tid->clear_ps_filter = true;
Felix Fietkau62e54dbb2014-04-28 18:32:12 +02001674 if (ath_tid_has_buffered(tid)) {
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +02001675 ath_tx_queue_tid(sc, tid);
Felix Fietkau55195412011-04-17 23:28:09 +02001676 ath_txq_schedule(sc, txq);
1677 }
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001678 ath_txq_unlock_complete(sc, txq);
Felix Fietkau55195412011-04-17 23:28:09 +02001679 }
1680}
1681
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001682void ath9k_release_buffered_frames(struct ieee80211_hw *hw,
1683 struct ieee80211_sta *sta,
1684 u16 tids, int nframes,
1685 enum ieee80211_frame_release_type reason,
1686 bool more_data)
1687{
1688 struct ath_softc *sc = hw->priv;
1689 struct ath_node *an = (struct ath_node *)sta->drv_priv;
1690 struct ath_txq *txq = sc->tx.uapsdq;
1691 struct ieee80211_tx_info *info;
1692 struct list_head bf_q;
1693 struct ath_buf *bf_tail = NULL, *bf;
1694 int sent = 0;
1695 int i;
1696
1697 INIT_LIST_HEAD(&bf_q);
1698 for (i = 0; tids && nframes; i++, tids >>= 1) {
1699 struct ath_atx_tid *tid;
1700
1701 if (!(tids & 1))
1702 continue;
1703
1704 tid = ATH_AN_2_TID(an, i);
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001705
Felix Fietkau592fa222015-07-22 13:06:13 +02001706 ath_txq_lock(sc, tid->txq);
Felix Fietkaua7586ee2013-08-06 14:18:02 +02001707 while (nframes > 0) {
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001708 bf = ath_tx_get_tid_subframe(sc, sc->tx.uapsdq, tid);
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001709 if (!bf)
1710 break;
1711
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001712 list_add_tail(&bf->list, &bf_q);
1713 ath_set_rates(tid->an->vif, tid->an->sta, bf);
Felix Fietkau20e6e552013-09-17 12:05:15 +02001714 if (bf_isampdu(bf)) {
1715 ath_tx_addto_baw(sc, tid, bf);
1716 bf->bf_state.bf_type &= ~BUF_AGGR;
1717 }
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001718 if (bf_tail)
1719 bf_tail->bf_next = bf;
1720
1721 bf_tail = bf;
1722 nframes--;
1723 sent++;
1724 TX_STAT_INC(txq->axq_qnum, a_queued_hw);
1725
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01001726 if (an->sta && skb_queue_empty(&tid->retry_q))
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001727 ieee80211_sta_set_buffered(an->sta, i, false);
1728 }
Felix Fietkau592fa222015-07-22 13:06:13 +02001729 ath_txq_unlock_complete(sc, tid->txq);
Felix Fietkau86a22ac2013-06-07 18:12:01 +02001730 }
1731
1732 if (list_empty(&bf_q))
1733 return;
1734
1735 info = IEEE80211_SKB_CB(bf_tail->bf_mpdu);
1736 info->flags |= IEEE80211_TX_STATUS_EOSP;
1737
1738 bf = list_first_entry(&bf_q, struct ath_buf, list);
1739 ath_txq_lock(sc, txq);
1740 ath_tx_fill_desc(sc, bf, txq, 0);
1741 ath_tx_txqaddbuf(sc, txq, &bf_q, false);
1742 ath_txq_unlock(sc, txq);
1743}
1744
Sujithe8324352009-01-16 21:38:42 +05301745/********************/
1746/* Queue Management */
1747/********************/
1748
Sujithe8324352009-01-16 21:38:42 +05301749struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype)
1750{
Sujithcbe61d82009-02-09 13:27:12 +05301751 struct ath_hw *ah = sc->sc_ah;
Sujithe8324352009-01-16 21:38:42 +05301752 struct ath9k_tx_queue_info qi;
Felix Fietkau066dae92010-11-07 14:59:39 +01001753 static const int subtype_txq_to_hwq[] = {
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301754 [IEEE80211_AC_BE] = ATH_TXQ_AC_BE,
1755 [IEEE80211_AC_BK] = ATH_TXQ_AC_BK,
1756 [IEEE80211_AC_VI] = ATH_TXQ_AC_VI,
1757 [IEEE80211_AC_VO] = ATH_TXQ_AC_VO,
Felix Fietkau066dae92010-11-07 14:59:39 +01001758 };
Ben Greear60f2d1d2011-01-09 23:11:52 -08001759 int axq_qnum, i;
Sujithe8324352009-01-16 21:38:42 +05301760
1761 memset(&qi, 0, sizeof(qi));
Felix Fietkau066dae92010-11-07 14:59:39 +01001762 qi.tqi_subtype = subtype_txq_to_hwq[subtype];
Sujithe8324352009-01-16 21:38:42 +05301763 qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT;
1764 qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT;
1765 qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT;
1766 qi.tqi_physCompBuf = 0;
1767
1768 /*
1769 * Enable interrupts only for EOL and DESC conditions.
1770 * We mark tx descriptors to receive a DESC interrupt
1771 * when a tx queue gets deep; otherwise waiting for the
1772 * EOL to reap descriptors. Note that this is done to
1773 * reduce interrupt load and this only defers reaping
1774 * descriptors, never transmitting frames. Aside from
1775 * reducing interrupts this also permits more concurrency.
1776 * The only potential downside is if the tx queue backs
1777 * up in which case the top half of the kernel may backup
1778 * due to a lack of tx descriptors.
1779 *
1780 * The UAPSD queue is an exception, since we take a desc-
1781 * based intr on the EOSP frames.
1782 */
Vasanthakumar Thiagarajanafe754d2010-04-15 17:39:40 -04001783 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
Felix Fietkauce8fdf62012-03-14 16:40:22 +01001784 qi.tqi_qflags = TXQ_FLAG_TXINT_ENABLE;
Vasanthakumar Thiagarajanafe754d2010-04-15 17:39:40 -04001785 } else {
1786 if (qtype == ATH9K_TX_QUEUE_UAPSD)
1787 qi.tqi_qflags = TXQ_FLAG_TXDESCINT_ENABLE;
1788 else
1789 qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE |
1790 TXQ_FLAG_TXDESCINT_ENABLE;
1791 }
Ben Greear60f2d1d2011-01-09 23:11:52 -08001792 axq_qnum = ath9k_hw_setuptxqueue(ah, qtype, &qi);
1793 if (axq_qnum == -1) {
Sujithe8324352009-01-16 21:38:42 +05301794 /*
1795 * NB: don't print a message, this happens
1796 * normally on parts with too few tx queues
1797 */
1798 return NULL;
1799 }
Ben Greear60f2d1d2011-01-09 23:11:52 -08001800 if (!ATH_TXQ_SETUP(sc, axq_qnum)) {
1801 struct ath_txq *txq = &sc->tx.txq[axq_qnum];
Sujithe8324352009-01-16 21:38:42 +05301802
Ben Greear60f2d1d2011-01-09 23:11:52 -08001803 txq->axq_qnum = axq_qnum;
1804 txq->mac80211_qnum = -1;
Sujithe8324352009-01-16 21:38:42 +05301805 txq->axq_link = NULL;
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001806 __skb_queue_head_init(&txq->complete_q);
Sujithe8324352009-01-16 21:38:42 +05301807 INIT_LIST_HEAD(&txq->axq_q);
Sujithe8324352009-01-16 21:38:42 +05301808 spin_lock_init(&txq->axq_lock);
1809 txq->axq_depth = 0;
Felix Fietkau4b3ba662010-12-17 00:57:00 +01001810 txq->axq_ampdu_depth = 0;
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04001811 txq->axq_tx_inprogress = false;
Ben Greear60f2d1d2011-01-09 23:11:52 -08001812 sc->tx.txqsetup |= 1<<axq_qnum;
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04001813
1814 txq->txq_headidx = txq->txq_tailidx = 0;
1815 for (i = 0; i < ATH_TXFIFO_DEPTH; i++)
1816 INIT_LIST_HEAD(&txq->txq_fifo[i]);
Sujithe8324352009-01-16 21:38:42 +05301817 }
Ben Greear60f2d1d2011-01-09 23:11:52 -08001818 return &sc->tx.txq[axq_qnum];
Sujithe8324352009-01-16 21:38:42 +05301819}
1820
Sujithe8324352009-01-16 21:38:42 +05301821int ath_txq_update(struct ath_softc *sc, int qnum,
1822 struct ath9k_tx_queue_info *qinfo)
1823{
Sujithcbe61d82009-02-09 13:27:12 +05301824 struct ath_hw *ah = sc->sc_ah;
Sujithe8324352009-01-16 21:38:42 +05301825 int error = 0;
1826 struct ath9k_tx_queue_info qi;
1827
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07001828 BUG_ON(sc->tx.txq[qnum].axq_qnum != qnum);
Sujithe8324352009-01-16 21:38:42 +05301829
1830 ath9k_hw_get_txq_props(ah, qnum, &qi);
1831 qi.tqi_aifs = qinfo->tqi_aifs;
1832 qi.tqi_cwmin = qinfo->tqi_cwmin;
1833 qi.tqi_cwmax = qinfo->tqi_cwmax;
1834 qi.tqi_burstTime = qinfo->tqi_burstTime;
1835 qi.tqi_readyTime = qinfo->tqi_readyTime;
1836
1837 if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
Joe Perches38002762010-12-02 19:12:36 -08001838 ath_err(ath9k_hw_common(sc->sc_ah),
1839 "Unable to update hardware queue %u!\n", qnum);
Sujithe8324352009-01-16 21:38:42 +05301840 error = -EIO;
1841 } else {
1842 ath9k_hw_resettxqueue(ah, qnum);
1843 }
1844
1845 return error;
1846}
1847
1848int ath_cabq_update(struct ath_softc *sc)
1849{
1850 struct ath9k_tx_queue_info qi;
Rajkumar Manoharanca900ac2014-06-11 16:18:02 +05301851 struct ath_beacon_config *cur_conf = &sc->cur_chan->beacon;
Sujithe8324352009-01-16 21:38:42 +05301852 int qnum = sc->beacon.cabq->axq_qnum;
Sujithe8324352009-01-16 21:38:42 +05301853
1854 ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi);
Sujithe8324352009-01-16 21:38:42 +05301855
Felix Fietkau3b3e0ef2014-03-09 11:02:54 +01001856 qi.tqi_readyTime = (TU_TO_USEC(cur_conf->beacon_interval) *
Felix Fietkau7f329bb2013-10-11 23:30:59 +02001857 ATH_CABQ_READY_TIME) / 100;
Sujithe8324352009-01-16 21:38:42 +05301858 ath_txq_update(sc, qnum, &qi);
1859
1860 return 0;
1861}
1862
Felix Fietkaufce041b2011-05-19 12:20:25 +02001863static void ath_drain_txq_list(struct ath_softc *sc, struct ath_txq *txq,
Felix Fietkau13815592013-01-20 18:51:53 +01001864 struct list_head *list)
Sujithe8324352009-01-16 21:38:42 +05301865{
1866 struct ath_buf *bf, *lastbf;
1867 struct list_head bf_head;
Felix Fietkaudb1a0522010-03-29 20:07:11 -07001868 struct ath_tx_status ts;
1869
1870 memset(&ts, 0, sizeof(ts));
Felix Fietkaudaa5c402011-10-07 02:28:15 +02001871 ts.ts_status = ATH9K_TX_FLUSH;
Sujithe8324352009-01-16 21:38:42 +05301872 INIT_LIST_HEAD(&bf_head);
1873
Felix Fietkaufce041b2011-05-19 12:20:25 +02001874 while (!list_empty(list)) {
1875 bf = list_first_entry(list, struct ath_buf, list);
Sujithe8324352009-01-16 21:38:42 +05301876
Felix Fietkau50676b82013-08-10 15:59:16 +02001877 if (bf->bf_state.stale) {
Felix Fietkaufce041b2011-05-19 12:20:25 +02001878 list_del(&bf->list);
Sujithe8324352009-01-16 21:38:42 +05301879
Felix Fietkaufce041b2011-05-19 12:20:25 +02001880 ath_tx_return_buffer(sc, bf);
1881 continue;
Sujithe8324352009-01-16 21:38:42 +05301882 }
1883
1884 lastbf = bf->bf_lastbf;
Felix Fietkaufce041b2011-05-19 12:20:25 +02001885 list_cut_position(&bf_head, list, &lastbf->list);
Felix Fietkau81b51952013-01-20 18:51:54 +01001886 ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04001887 }
Felix Fietkaufce041b2011-05-19 12:20:25 +02001888}
1889
1890/*
1891 * Drain a given TX queue (could be Beacon or Data)
1892 *
1893 * This assumes output has been stopped and
1894 * we do not need to block ath_tx_tasklet.
1895 */
Felix Fietkau13815592013-01-20 18:51:53 +01001896void ath_draintxq(struct ath_softc *sc, struct ath_txq *txq)
Felix Fietkaufce041b2011-05-19 12:20:25 +02001897{
Felix Fietkaud94a4612016-09-02 19:46:12 +03001898 rcu_read_lock();
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001899 ath_txq_lock(sc, txq);
1900
Felix Fietkaufce041b2011-05-19 12:20:25 +02001901 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
1902 int idx = txq->txq_tailidx;
1903
1904 while (!list_empty(&txq->txq_fifo[idx])) {
Felix Fietkau13815592013-01-20 18:51:53 +01001905 ath_drain_txq_list(sc, txq, &txq->txq_fifo[idx]);
Felix Fietkaufce041b2011-05-19 12:20:25 +02001906
1907 INCR(idx, ATH_TXFIFO_DEPTH);
1908 }
1909 txq->txq_tailidx = idx;
1910 }
1911
1912 txq->axq_link = NULL;
1913 txq->axq_tx_inprogress = false;
Felix Fietkau13815592013-01-20 18:51:53 +01001914 ath_drain_txq_list(sc, txq, &txq->axq_q);
Felix Fietkaufce041b2011-05-19 12:20:25 +02001915
Felix Fietkau23de5dc2011-12-19 16:45:54 +01001916 ath_txq_unlock_complete(sc, txq);
Felix Fietkaud94a4612016-09-02 19:46:12 +03001917 rcu_read_unlock();
Sujithe8324352009-01-16 21:38:42 +05301918}
1919
Felix Fietkau13815592013-01-20 18:51:53 +01001920bool ath_drain_all_txq(struct ath_softc *sc)
Sujith043a0402009-01-16 21:38:47 +05301921{
Sujithcbe61d82009-02-09 13:27:12 +05301922 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001923 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith043a0402009-01-16 21:38:47 +05301924 struct ath_txq *txq;
Felix Fietkau34d25812011-10-07 02:28:12 +02001925 int i;
1926 u32 npend = 0;
Sujith043a0402009-01-16 21:38:47 +05301927
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01001928 if (test_bit(ATH_OP_INVALID, &common->op_flags))
Felix Fietkau080e1a22010-12-05 20:17:53 +01001929 return true;
Sujith043a0402009-01-16 21:38:47 +05301930
Felix Fietkau0d51ccc2011-03-11 21:38:18 +01001931 ath9k_hw_abort_tx_dma(ah);
Sujith043a0402009-01-16 21:38:47 +05301932
Felix Fietkau0d51ccc2011-03-11 21:38:18 +01001933 /* Check if any queue remains active */
Sujith043a0402009-01-16 21:38:47 +05301934 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
Felix Fietkau0d51ccc2011-03-11 21:38:18 +01001935 if (!ATH_TXQ_SETUP(sc, i))
1936 continue;
1937
Felix Fietkau10ffb6a2013-11-11 22:23:34 +01001938 if (!sc->tx.txq[i].axq_depth)
1939 continue;
1940
Felix Fietkau34d25812011-10-07 02:28:12 +02001941 if (ath9k_hw_numtxpending(ah, sc->tx.txq[i].axq_qnum))
1942 npend |= BIT(i);
Sujith043a0402009-01-16 21:38:47 +05301943 }
1944
Felix Fietkaue60ac9c2015-07-02 13:40:29 +02001945 if (npend) {
1946 RESET_STAT_INC(sc, RESET_TX_DMA_ERROR);
1947 ath_dbg(common, RESET,
1948 "Failed to stop TX DMA, queues=0x%03x!\n", npend);
1949 }
Sujith043a0402009-01-16 21:38:47 +05301950
1951 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
Felix Fietkau92460412011-01-24 19:23:14 +01001952 if (!ATH_TXQ_SETUP(sc, i))
1953 continue;
1954
Felix Fietkau92460412011-01-24 19:23:14 +01001955 txq = &sc->tx.txq[i];
Felix Fietkau13815592013-01-20 18:51:53 +01001956 ath_draintxq(sc, txq);
Sujith043a0402009-01-16 21:38:47 +05301957 }
Felix Fietkau080e1a22010-12-05 20:17:53 +01001958
1959 return !npend;
Sujith043a0402009-01-16 21:38:47 +05301960}
1961
Sujithe8324352009-01-16 21:38:42 +05301962void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq)
1963{
1964 ath9k_hw_releasetxqueue(sc->sc_ah, txq->axq_qnum);
1965 sc->tx.txqsetup &= ~(1<<txq->axq_qnum);
1966}
1967
Felix Fietkau04535312014-06-11 16:17:51 +05301968/* For each acq entry, for each tid, try to schedule packets
Ben Greear7755bad2011-01-18 17:30:00 -08001969 * for transmit until ampdu_depth has reached min Q depth.
1970 */
Sujithe8324352009-01-16 21:38:42 +05301971void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
1972{
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01001973 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +02001974 struct ath_atx_tid *tid;
Felix Fietkau592fa222015-07-22 13:06:13 +02001975 struct list_head *tid_list;
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +02001976 struct ath_acq *acq;
1977 bool active = AIRTIME_ACTIVE(sc->airtime_flags);
Sujithe8324352009-01-16 21:38:42 +05301978
Felix Fietkau04535312014-06-11 16:17:51 +05301979 if (txq->mac80211_qnum < 0)
1980 return;
1981
Sujith Manoharan4d9f6342014-09-30 14:15:23 +05301982 if (test_bit(ATH_OP_HW_RESET, &common->op_flags))
Sujithe8324352009-01-16 21:38:42 +05301983 return;
1984
Felix Fietkaubff11762014-06-11 16:17:52 +05301985 spin_lock_bh(&sc->chan_lock);
Felix Fietkau23bc2022013-06-22 12:39:26 +02001986 rcu_read_lock();
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +02001987 acq = &sc->cur_chan->acq[txq->mac80211_qnum];
Felix Fietkau23bc2022013-06-22 12:39:26 +02001988
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +02001989 if (sc->cur_chan->stopped)
1990 goto out;
Sujithe8324352009-01-16 21:38:42 +05301991
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +02001992begin:
1993 tid_list = &acq->acq_new;
1994 if (list_empty(tid_list)) {
1995 tid_list = &acq->acq_old;
1996 if (list_empty(tid_list))
1997 goto out;
1998 }
1999 tid = list_first_entry(tid_list, struct ath_atx_tid, list);
Felix Fietkaubff11762014-06-11 16:17:52 +05302000
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +02002001 if (active && tid->an->airtime_deficit[txq->mac80211_qnum] <= 0) {
2002 spin_lock_bh(&acq->lock);
2003 tid->an->airtime_deficit[txq->mac80211_qnum] += ATH_AIRTIME_QUANTUM;
2004 list_move_tail(&tid->list, &acq->acq_old);
2005 spin_unlock_bh(&acq->lock);
2006 goto begin;
Sujithe8324352009-01-16 21:38:42 +05302007 }
Felix Fietkau23bc2022013-06-22 12:39:26 +02002008
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +02002009 if (!ath_tid_has_buffered(tid)) {
2010 spin_lock_bh(&acq->lock);
2011 if ((tid_list == &acq->acq_new) && !list_empty(&acq->acq_old))
2012 list_move_tail(&tid->list, &acq->acq_old);
2013 else {
2014 list_del_init(&tid->list);
2015 }
2016 spin_unlock_bh(&acq->lock);
2017 goto begin;
2018 }
2019
2020
2021 /*
2022 * If we succeed in scheduling something, immediately restart to make
2023 * sure we keep the HW busy.
2024 */
2025 if(ath_tx_sched_aggr(sc, txq, tid)) {
2026 if (!active) {
2027 spin_lock_bh(&acq->lock);
2028 list_move_tail(&tid->list, &acq->acq_old);
2029 spin_unlock_bh(&acq->lock);
2030 }
2031 goto begin;
2032 }
2033
2034out:
Felix Fietkau23bc2022013-06-22 12:39:26 +02002035 rcu_read_unlock();
Felix Fietkaubff11762014-06-11 16:17:52 +05302036 spin_unlock_bh(&sc->chan_lock);
Sujithe8324352009-01-16 21:38:42 +05302037}
2038
Felix Fietkau04535312014-06-11 16:17:51 +05302039void ath_txq_schedule_all(struct ath_softc *sc)
2040{
2041 struct ath_txq *txq;
2042 int i;
2043
2044 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
2045 txq = sc->tx.txq_map[i];
2046
2047 spin_lock_bh(&txq->axq_lock);
2048 ath_txq_schedule(sc, txq);
2049 spin_unlock_bh(&txq->axq_lock);
2050 }
2051}
2052
Sujithe8324352009-01-16 21:38:42 +05302053/***********/
2054/* TX, DMA */
2055/***********/
2056
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002057/*
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002058 * Insert a chain of ath_buf (descriptors) on a txq and
2059 * assume the descriptors are already chained together by caller.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002060 */
Sujith102e0572008-10-29 10:15:16 +05302061static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
Felix Fietkaufce041b2011-05-19 12:20:25 +02002062 struct list_head *head, bool internal)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002063{
Sujithcbe61d82009-02-09 13:27:12 +05302064 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002065 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkaufce041b2011-05-19 12:20:25 +02002066 struct ath_buf *bf, *bf_last;
2067 bool puttxbuf = false;
2068 bool edma;
Sujith102e0572008-10-29 10:15:16 +05302069
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002070 /*
2071 * Insert the frame on the outbound list and
2072 * pass it on to the hardware.
2073 */
2074
2075 if (list_empty(head))
2076 return;
2077
Felix Fietkaufce041b2011-05-19 12:20:25 +02002078 edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002079 bf = list_first_entry(head, struct ath_buf, list);
Felix Fietkaufce041b2011-05-19 12:20:25 +02002080 bf_last = list_entry(head->prev, struct ath_buf, list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002081
Joe Perchesd2182b62011-12-15 14:55:53 -08002082 ath_dbg(common, QUEUE, "qnum: %d, txq depth: %d\n",
2083 txq->axq_qnum, txq->axq_depth);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002084
Felix Fietkaufce041b2011-05-19 12:20:25 +02002085 if (edma && list_empty(&txq->txq_fifo[txq->txq_headidx])) {
2086 list_splice_tail_init(head, &txq->txq_fifo[txq->txq_headidx]);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002087 INCR(txq->txq_headidx, ATH_TXFIFO_DEPTH);
Felix Fietkaufce041b2011-05-19 12:20:25 +02002088 puttxbuf = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002089 } else {
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002090 list_splice_tail_init(head, &txq->axq_q);
2091
Felix Fietkaufce041b2011-05-19 12:20:25 +02002092 if (txq->axq_link) {
2093 ath9k_hw_set_desc_link(ah, txq->axq_link, bf->bf_daddr);
Joe Perchesd2182b62011-12-15 14:55:53 -08002094 ath_dbg(common, XMIT, "link[%u] (%p)=%llx (%p)\n",
Joe Perches226afe62010-12-02 19:12:37 -08002095 txq->axq_qnum, txq->axq_link,
2096 ito64(bf->bf_daddr), bf->bf_desc);
Felix Fietkaufce041b2011-05-19 12:20:25 +02002097 } else if (!edma)
2098 puttxbuf = true;
2099
2100 txq->axq_link = bf_last->bf_desc;
2101 }
2102
2103 if (puttxbuf) {
2104 TX_STAT_INC(txq->axq_qnum, puttxbuf);
2105 ath9k_hw_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr);
Joe Perchesd2182b62011-12-15 14:55:53 -08002106 ath_dbg(common, XMIT, "TXDP[%u] = %llx (%p)\n",
Felix Fietkaufce041b2011-05-19 12:20:25 +02002107 txq->axq_qnum, ito64(bf->bf_daddr), bf->bf_desc);
2108 }
2109
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07002110 if (!edma || sc->tx99_state) {
Felix Fietkau8d8d3fd2011-01-24 19:11:54 +01002111 TX_STAT_INC(txq->axq_qnum, txstart);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002112 ath9k_hw_txstart(ah, txq->axq_qnum);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002113 }
Felix Fietkaufce041b2011-05-19 12:20:25 +02002114
2115 if (!internal) {
Felix Fietkauf56e1212013-06-20 15:11:31 +02002116 while (bf) {
2117 txq->axq_depth++;
2118 if (bf_is_ampdu_not_probing(bf))
2119 txq->axq_ampdu_depth++;
2120
Felix Fietkau440c1c82013-09-14 17:02:29 +02002121 bf_last = bf->bf_lastbf;
2122 bf = bf_last->bf_next;
2123 bf_last->bf_next = NULL;
Felix Fietkauf56e1212013-06-20 15:11:31 +02002124 }
Felix Fietkaufce041b2011-05-19 12:20:25 +02002125 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002126}
2127
Felix Fietkau82b873a2010-11-11 03:18:37 +01002128static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
Felix Fietkau44f1d262011-08-28 00:32:25 +02002129 struct ath_atx_tid *tid, struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002130{
Felix Fietkauf69727f2013-09-29 13:06:31 +02002131 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau44f1d262011-08-28 00:32:25 +02002132 struct ath_frame_info *fi = get_frame_info(skb);
2133 struct list_head bf_head;
Felix Fietkauf69727f2013-09-29 13:06:31 +02002134 struct ath_buf *bf = fi->bf;
Felix Fietkau44f1d262011-08-28 00:32:25 +02002135
2136 INIT_LIST_HEAD(&bf_head);
2137 list_add_tail(&bf->list, &bf_head);
Felix Fietkau399c6482011-09-14 21:24:17 +02002138 bf->bf_state.bf_type = 0;
Felix Fietkauf69727f2013-09-29 13:06:31 +02002139 if (tid && (tx_info->flags & IEEE80211_TX_CTL_AMPDU)) {
2140 bf->bf_state.bf_type = BUF_AMPDU;
2141 ath_tx_addto_baw(sc, tid, bf);
2142 }
Sujithe8324352009-01-16 21:38:42 +05302143
Felix Fietkau8c6e3092012-10-26 00:31:11 +02002144 bf->bf_next = NULL;
Sujithd43f30152009-01-16 21:38:53 +05302145 bf->bf_lastbf = bf;
Felix Fietkau493cf042011-09-14 21:24:22 +02002146 ath_tx_fill_desc(sc, bf, txq, fi->framelen);
Felix Fietkau44f1d262011-08-28 00:32:25 +02002147 ath_tx_txqaddbuf(sc, txq, &bf_head, false);
Sujithfec247c2009-07-27 12:08:16 +05302148 TX_STAT_INC(txq->axq_qnum, queued);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002149}
2150
Thomas Huehn36323f82012-07-23 21:33:42 +02002151static void setup_frame_info(struct ieee80211_hw *hw,
2152 struct ieee80211_sta *sta,
2153 struct sk_buff *skb,
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002154 int framelen)
Sujith528f0c62008-10-29 10:14:26 +05302155{
2156 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002157 struct ieee80211_key_conf *hw_key = tx_info->control.hw_key;
Felix Fietkau6a0ddae2011-08-28 00:32:23 +02002158 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Felix Fietkau80b08a82012-06-15 03:04:53 +02002159 const struct ieee80211_rate *rate;
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002160 struct ath_frame_info *fi = get_frame_info(skb);
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02002161 struct ath_node *an = NULL;
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002162 enum ath9k_key_type keytype;
Felix Fietkau80b08a82012-06-15 03:04:53 +02002163 bool short_preamble = false;
Lorenzo Bianconif6738212015-04-08 20:51:57 +02002164 u8 txpower;
Sujith528f0c62008-10-29 10:14:26 +05302165
Felix Fietkau80b08a82012-06-15 03:04:53 +02002166 /*
2167 * We check if Short Preamble is needed for the CTS rate by
2168 * checking the BSS's global flag.
2169 * But for the rate series, IEEE80211_TX_RC_USE_SHORT_PREAMBLE is used.
2170 */
2171 if (tx_info->control.vif &&
2172 tx_info->control.vif->bss_conf.use_short_preamble)
2173 short_preamble = true;
2174
2175 rate = ieee80211_get_rts_cts_rate(hw, tx_info);
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002176 keytype = ath9k_cmn_get_hw_crypto_keytype(skb);
Sujith528f0c62008-10-29 10:14:26 +05302177
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02002178 if (sta)
2179 an = (struct ath_node *) sta->drv_priv;
2180
Lorenzo Bianconif6738212015-04-08 20:51:57 +02002181 if (tx_info->control.vif) {
2182 struct ieee80211_vif *vif = tx_info->control.vif;
2183
2184 txpower = 2 * vif->bss_conf.txpower;
2185 } else {
2186 struct ath_softc *sc = hw->priv;
2187
2188 txpower = sc->cur_chan->cur_txpower;
2189 }
2190
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002191 memset(fi, 0, sizeof(*fi));
Felix Fietkaud954cd772014-07-16 20:26:05 +02002192 fi->txq = -1;
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002193 if (hw_key)
2194 fi->keyix = hw_key->hw_key_idx;
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02002195 else if (an && ieee80211_is_data(hdr->frame_control) && an->ps_key > 0)
2196 fi->keyix = an->ps_key;
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002197 else
2198 fi->keyix = ATH9K_TXKEYIX_INVALID;
2199 fi->keytype = keytype;
2200 fi->framelen = framelen;
Lorenzo Bianconif6738212015-04-08 20:51:57 +02002201 fi->tx_power = txpower;
Luis R. Rodriguez09b029b2013-10-14 17:42:10 -07002202
2203 if (!rate)
2204 return;
Felix Fietkau80b08a82012-06-15 03:04:53 +02002205 fi->rtscts_rate = rate->hw_value;
2206 if (short_preamble)
2207 fi->rtscts_rate |= rate->hw_value_short;
Sujith528f0c62008-10-29 10:14:26 +05302208}
2209
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +05302210u8 ath_txchainmask_reduction(struct ath_softc *sc, u8 chainmask, u32 rate)
2211{
2212 struct ath_hw *ah = sc->sc_ah;
2213 struct ath9k_channel *curchan = ah->curchan;
Sujith Manoharan365d2eb2012-09-26 12:22:08 +05302214
Felix Fietkau88969342013-10-11 23:30:53 +02002215 if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && IS_CHAN_5GHZ(curchan) &&
Rajkumar Manoharand77bf3e2011-08-13 10:28:14 +05302216 (chainmask == 0x7) && (rate < 0x90))
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +05302217 return 0x3;
Sujith Manoharan365d2eb2012-09-26 12:22:08 +05302218 else if (AR_SREV_9462(ah) && ath9k_hw_btcoex_is_enabled(ah) &&
2219 IS_CCK_RATE(rate))
2220 return 0x2;
Mohammed Shafi Shajakhanea066d52010-11-23 20:42:27 +05302221 else
2222 return chainmask;
2223}
2224
Felix Fietkau44f1d262011-08-28 00:32:25 +02002225/*
2226 * Assign a descriptor (and sequence number if necessary,
2227 * and map buffer for DMA. Frees skb on error
2228 */
Felix Fietkaufa05f872011-08-28 00:32:24 +02002229static struct ath_buf *ath_tx_setup_buffer(struct ath_softc *sc,
Felix Fietkau04caf862010-11-14 15:20:12 +01002230 struct ath_txq *txq,
Felix Fietkaufa05f872011-08-28 00:32:24 +02002231 struct ath_atx_tid *tid,
Felix Fietkau249ee722012-10-03 21:07:52 +02002232 struct sk_buff *skb)
Sujithe8324352009-01-16 21:38:42 +05302233{
Felix Fietkau82b873a2010-11-11 03:18:37 +01002234 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002235 struct ath_frame_info *fi = get_frame_info(skb);
Felix Fietkaufa05f872011-08-28 00:32:24 +02002236 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Felix Fietkau82b873a2010-11-11 03:18:37 +01002237 struct ath_buf *bf;
Sujith Manoharanfd09c852012-04-17 08:34:50 +05302238 int fragno;
Felix Fietkaufa05f872011-08-28 00:32:24 +02002239 u16 seqno;
Felix Fietkau82b873a2010-11-11 03:18:37 +01002240
2241 bf = ath_tx_get_buffer(sc);
2242 if (!bf) {
Joe Perchesd2182b62011-12-15 14:55:53 -08002243 ath_dbg(common, XMIT, "TX buffers are full\n");
Felix Fietkau249ee722012-10-03 21:07:52 +02002244 return NULL;
Felix Fietkau82b873a2010-11-11 03:18:37 +01002245 }
Sujithe8324352009-01-16 21:38:42 +05302246
Sujithe8324352009-01-16 21:38:42 +05302247 ATH_TXBUF_RESET(bf);
2248
Helmut Schaa5998be82014-03-12 10:37:55 +01002249 if (tid && ieee80211_is_data_present(hdr->frame_control)) {
Sujith Manoharanfd09c852012-04-17 08:34:50 +05302250 fragno = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
Felix Fietkaufa05f872011-08-28 00:32:24 +02002251 seqno = tid->seq_next;
2252 hdr->seq_ctrl = cpu_to_le16(tid->seq_next << IEEE80211_SEQ_SEQ_SHIFT);
Sujith Manoharanfd09c852012-04-17 08:34:50 +05302253
2254 if (fragno)
2255 hdr->seq_ctrl |= cpu_to_le16(fragno);
2256
2257 if (!ieee80211_has_morefrags(hdr->frame_control))
2258 INCR(tid->seq_next, IEEE80211_SEQ_MAX);
2259
Felix Fietkaufa05f872011-08-28 00:32:24 +02002260 bf->bf_state.seqno = seqno;
2261 }
2262
Sujithe8324352009-01-16 21:38:42 +05302263 bf->bf_mpdu = skb;
2264
Ben Greearc1739eb32010-10-14 12:45:29 -07002265 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
2266 skb->len, DMA_TO_DEVICE);
2267 if (unlikely(dma_mapping_error(sc->dev, bf->bf_buf_addr))) {
Sujithe8324352009-01-16 21:38:42 +05302268 bf->bf_mpdu = NULL;
Ben Greear6cf9e992010-10-14 12:45:30 -07002269 bf->bf_buf_addr = 0;
Joe Perches38002762010-12-02 19:12:36 -08002270 ath_err(ath9k_hw_common(sc->sc_ah),
2271 "dma_mapping_error() on TX\n");
Felix Fietkau82b873a2010-11-11 03:18:37 +01002272 ath_tx_return_buffer(sc, bf);
Felix Fietkau249ee722012-10-03 21:07:52 +02002273 return NULL;
Sujithe8324352009-01-16 21:38:42 +05302274 }
2275
Felix Fietkau56dc6332011-08-28 00:32:22 +02002276 fi->bf = bf;
Felix Fietkau04caf862010-11-14 15:20:12 +01002277
2278 return bf;
2279}
2280
Sujith Manoharanca144052014-10-08 08:43:19 +05302281void ath_assign_seq(struct ath_common *common, struct sk_buff *skb)
2282{
2283 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2284 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2285 struct ieee80211_vif *vif = info->control.vif;
2286 struct ath_vif *avp;
2287
2288 if (!(info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ))
2289 return;
2290
2291 if (!vif)
2292 return;
2293
2294 avp = (struct ath_vif *)vif->drv_priv;
2295
2296 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
2297 avp->seq_no += 0x10;
2298
2299 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
2300 hdr->seq_ctrl |= cpu_to_le16(avp->seq_no);
2301}
2302
Felix Fietkau59505c02013-06-07 18:12:02 +02002303static int ath_tx_prepare(struct ieee80211_hw *hw, struct sk_buff *skb,
2304 struct ath_tx_control *txctl)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002305{
Felix Fietkau28d16702010-11-14 15:20:10 +01002306 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2307 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Thomas Huehn36323f82012-07-23 21:33:42 +02002308 struct ieee80211_sta *sta = txctl->sta;
Felix Fietkauf59a59f2011-05-10 20:52:22 +02002309 struct ieee80211_vif *vif = info->control.vif;
Felix Fietkauf89d1bc2013-08-06 14:18:13 +02002310 struct ath_vif *avp;
Felix Fietkau9ac586152011-01-24 19:23:18 +01002311 struct ath_softc *sc = hw->priv;
Felix Fietkau04caf862010-11-14 15:20:12 +01002312 int frmlen = skb->len + FCS_LEN;
Felix Fietkau59505c02013-06-07 18:12:02 +02002313 int padpos, padsize;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002314
Ben Greeara9927ba2010-12-06 21:13:49 -08002315 /* NOTE: sta can be NULL according to net/mac80211.h */
2316 if (sta)
2317 txctl->an = (struct ath_node *)sta->drv_priv;
Felix Fietkauf89d1bc2013-08-06 14:18:13 +02002318 else if (vif && ieee80211_is_data(hdr->frame_control)) {
2319 avp = (void *)vif->drv_priv;
2320 txctl->an = &avp->mcast_node;
2321 }
Ben Greeara9927ba2010-12-06 21:13:49 -08002322
Felix Fietkau04caf862010-11-14 15:20:12 +01002323 if (info->control.hw_key)
2324 frmlen += info->control.hw_key->icv_len;
2325
Sujith Manoharanca144052014-10-08 08:43:19 +05302326 ath_assign_seq(ath9k_hw_common(sc->sc_ah), skb);
Felix Fietkau28d16702010-11-14 15:20:10 +01002327
Felix Fietkau59505c02013-06-07 18:12:02 +02002328 if ((vif && vif->type != NL80211_IFTYPE_AP &&
2329 vif->type != NL80211_IFTYPE_AP_VLAN) ||
2330 !ieee80211_is_data(hdr->frame_control))
2331 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
2332
John W. Linville42cecc32011-09-19 15:42:31 -04002333 /* Add the padding after the header if this is not already done */
Felix Fietkauc60c9922013-04-08 00:04:09 +02002334 padpos = ieee80211_hdrlen(hdr->frame_control);
John W. Linville42cecc32011-09-19 15:42:31 -04002335 padsize = padpos & 3;
2336 if (padsize && skb->len > padpos) {
2337 if (skb_headroom(skb) < padsize)
2338 return -ENOMEM;
Felix Fietkau28d16702010-11-14 15:20:10 +01002339
John W. Linville42cecc32011-09-19 15:42:31 -04002340 skb_push(skb, padsize);
2341 memmove(skb->data, skb->data + padsize, padpos);
Felix Fietkau28d16702010-11-14 15:20:10 +01002342 }
2343
Thomas Huehn36323f82012-07-23 21:33:42 +02002344 setup_frame_info(hw, sta, skb, frmlen);
Felix Fietkau59505c02013-06-07 18:12:02 +02002345 return 0;
2346}
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002347
Felix Fietkau59505c02013-06-07 18:12:02 +02002348
2349/* Upon failure caller should free skb */
2350int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
2351 struct ath_tx_control *txctl)
2352{
2353 struct ieee80211_hdr *hdr;
2354 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2355 struct ieee80211_sta *sta = txctl->sta;
2356 struct ieee80211_vif *vif = info->control.vif;
Felix Fietkaud954cd772014-07-16 20:26:05 +02002357 struct ath_frame_info *fi = get_frame_info(skb);
Felix Fietkaubefcf7e2014-06-11 16:17:53 +05302358 struct ath_vif *avp = NULL;
Felix Fietkau59505c02013-06-07 18:12:02 +02002359 struct ath_softc *sc = hw->priv;
2360 struct ath_txq *txq = txctl->txq;
2361 struct ath_atx_tid *tid = NULL;
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01002362 struct ath_node *an = NULL;
Felix Fietkau59505c02013-06-07 18:12:02 +02002363 struct ath_buf *bf;
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01002364 bool ps_resp;
Sujith Manoharand7017462014-09-24 11:48:14 +05302365 int q, ret;
Felix Fietkau59505c02013-06-07 18:12:02 +02002366
Felix Fietkaubefcf7e2014-06-11 16:17:53 +05302367 if (vif)
2368 avp = (void *)vif->drv_priv;
2369
Sujith Manoharan6b127c72014-12-10 21:26:10 +05302370 ps_resp = !!(info->control.flags & IEEE80211_TX_CTRL_PS_RESPONSE);
2371
Felix Fietkau59505c02013-06-07 18:12:02 +02002372 ret = ath_tx_prepare(hw, skb, txctl);
2373 if (ret)
2374 return ret;
2375
2376 hdr = (struct ieee80211_hdr *) skb->data;
Felix Fietkau2d42efc2010-11-14 15:20:13 +01002377 /*
2378 * At this point, the vif, hw_key and sta pointers in the tx control
2379 * info are no longer valid (overwritten by the ath_frame_info data.
2380 */
2381
Felix Fietkau066dae92010-11-07 14:59:39 +01002382 q = skb_get_queue_mapping(skb);
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002383
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01002384 if (ps_resp)
2385 txq = sc->tx.uapsdq;
2386
2387 if (txctl->sta) {
2388 an = (struct ath_node *) sta->drv_priv;
2389 tid = ath_get_skb_tid(sc, an, skb);
2390 }
2391
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002392 ath_txq_lock(sc, txq);
Felix Fietkaud954cd772014-07-16 20:26:05 +02002393 if (txq == sc->tx.txq_map[q]) {
2394 fi->txq = q;
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01002395 ++txq->pending_frames;
Felix Fietkaubdc21452013-04-22 23:11:43 +02002396 }
2397
Felix Fietkauf2c7a792013-06-07 18:12:00 +02002398 bf = ath_tx_setup_buffer(sc, txq, tid, skb);
Felix Fietkaubdc21452013-04-22 23:11:43 +02002399 if (!bf) {
Felix Fietkaua4943cc2013-06-30 12:02:13 +02002400 ath_txq_skb_done(sc, txq, skb);
Felix Fietkaubdc21452013-04-22 23:11:43 +02002401 if (txctl->paprd)
2402 dev_kfree_skb_any(skb);
2403 else
2404 ieee80211_free_txskb(sc->hw, skb);
2405 goto out;
2406 }
2407
2408 bf->bf_state.bfs_paprd = txctl->paprd;
2409
2410 if (txctl->paprd)
2411 bf->bf_state.bfs_paprd_timestamp = jiffies;
2412
Felix Fietkau79acac02013-04-22 23:11:44 +02002413 ath_set_rates(vif, sta, bf);
Felix Fietkauf2c7a792013-06-07 18:12:00 +02002414 ath_tx_send_normal(sc, txq, tid, skb);
Felix Fietkaubdc21452013-04-22 23:11:43 +02002415
2416out:
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002417 ath_txq_unlock(sc, txq);
Felix Fietkau3ad29522011-12-14 22:08:07 +01002418
Felix Fietkau44f1d262011-08-28 00:32:25 +02002419 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002420}
2421
Felix Fietkau59505c02013-06-07 18:12:02 +02002422void ath_tx_cabq(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2423 struct sk_buff *skb)
2424{
2425 struct ath_softc *sc = hw->priv;
2426 struct ath_tx_control txctl = {
2427 .txq = sc->beacon.cabq
2428 };
2429 struct ath_tx_info info = {};
2430 struct ieee80211_hdr *hdr;
2431 struct ath_buf *bf_tail = NULL;
2432 struct ath_buf *bf;
2433 LIST_HEAD(bf_q);
2434 int duration = 0;
2435 int max_duration;
2436
2437 max_duration =
Rajkumar Manoharanca900ac2014-06-11 16:18:02 +05302438 sc->cur_chan->beacon.beacon_interval * 1000 *
2439 sc->cur_chan->beacon.dtim_period / ATH_BCBUF;
Felix Fietkau59505c02013-06-07 18:12:02 +02002440
2441 do {
2442 struct ath_frame_info *fi = get_frame_info(skb);
2443
2444 if (ath_tx_prepare(hw, skb, &txctl))
2445 break;
2446
2447 bf = ath_tx_setup_buffer(sc, txctl.txq, NULL, skb);
2448 if (!bf)
2449 break;
2450
2451 bf->bf_lastbf = bf;
2452 ath_set_rates(vif, NULL, bf);
Sujith Manoharana3835e92013-07-04 12:59:47 +05302453 ath_buf_set_rate(sc, bf, &info, fi->framelen, false);
Felix Fietkau59505c02013-06-07 18:12:02 +02002454 duration += info.rates[0].PktDuration;
2455 if (bf_tail)
2456 bf_tail->bf_next = bf;
2457
2458 list_add_tail(&bf->list, &bf_q);
2459 bf_tail = bf;
2460 skb = NULL;
2461
2462 if (duration > max_duration)
2463 break;
2464
2465 skb = ieee80211_get_buffered_bc(hw, vif);
2466 } while(skb);
2467
2468 if (skb)
2469 ieee80211_free_txskb(hw, skb);
2470
2471 if (list_empty(&bf_q))
2472 return;
2473
2474 bf = list_first_entry(&bf_q, struct ath_buf, list);
2475 hdr = (struct ieee80211_hdr *) bf->bf_mpdu->data;
2476
Michal Kazior92cd4032015-07-09 12:27:22 +02002477 if (hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_MOREDATA)) {
2478 hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_MOREDATA);
Felix Fietkau59505c02013-06-07 18:12:02 +02002479 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
2480 sizeof(*hdr), DMA_TO_DEVICE);
2481 }
2482
2483 ath_txq_lock(sc, txctl.txq);
2484 ath_tx_fill_desc(sc, bf, txctl.txq, 0);
2485 ath_tx_txqaddbuf(sc, txctl.txq, &bf_q, false);
2486 TX_STAT_INC(txctl.txq->axq_qnum, queued);
2487 ath_txq_unlock(sc, txctl.txq);
2488}
2489
Sujithe8324352009-01-16 21:38:42 +05302490/*****************/
2491/* TX Completion */
2492/*****************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002493
Sujithe8324352009-01-16 21:38:42 +05302494static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
Felix Fietkaud94a4612016-09-02 19:46:12 +03002495 int tx_flags, struct ath_txq *txq,
2496 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002497{
Sujithe8324352009-01-16 21:38:42 +05302498 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002499 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Benoit Papillault4d91f9f2009-12-12 00:22:35 +01002500 struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data;
Felix Fietkaua4943cc2013-06-30 12:02:13 +02002501 int padpos, padsize;
Sujith Manoharan07c15a32012-06-04 20:24:07 +05302502 unsigned long flags;
Sujithe8324352009-01-16 21:38:42 +05302503
Joe Perchesd2182b62011-12-15 14:55:53 -08002504 ath_dbg(common, XMIT, "TX complete: skb: %p\n", skb);
Sujithe8324352009-01-16 21:38:42 +05302505
Felix Fietkau51dea9b2012-08-27 17:00:07 +02002506 if (sc->sc_ah->caldata)
Sujith Manoharan4b9b42b2013-09-11 16:36:31 +05302507 set_bit(PAPRD_PACKET_SENT, &sc->sc_ah->caldata->cal_flags);
Felix Fietkau51dea9b2012-08-27 17:00:07 +02002508
Sujith Manoharan2b5b8f12014-12-19 06:33:55 +05302509 if (!(tx_flags & ATH_TX_ERROR)) {
2510 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
2511 tx_info->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
2512 else
2513 tx_info->flags |= IEEE80211_TX_STAT_ACK;
2514 }
Sujithe8324352009-01-16 21:38:42 +05302515
Felix Fietkaud94a4612016-09-02 19:46:12 +03002516 if (tx_info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) {
2517 padpos = ieee80211_hdrlen(hdr->frame_control);
2518 padsize = padpos & 3;
2519 if (padsize && skb->len>padpos+padsize) {
2520 /*
2521 * Remove MAC header padding before giving the frame back to
2522 * mac80211.
2523 */
2524 memmove(skb->data + padsize, skb->data, padpos);
2525 skb_pull(skb, padsize);
2526 }
Sujithe8324352009-01-16 21:38:42 +05302527 }
2528
Sujith Manoharan07c15a32012-06-04 20:24:07 +05302529 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Felix Fietkauc8e88682011-11-16 13:08:40 +01002530 if ((sc->ps_flags & PS_WAIT_FOR_TX_ACK) && !txq->axq_depth) {
Sujith1b04b932010-01-08 10:36:05 +05302531 sc->ps_flags &= ~PS_WAIT_FOR_TX_ACK;
Joe Perchesd2182b62011-12-15 14:55:53 -08002532 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -08002533 "Going back to sleep after having received TX status (0x%lx)\n",
Sujith1b04b932010-01-08 10:36:05 +05302534 sc->ps_flags & (PS_WAIT_FOR_BEACON |
2535 PS_WAIT_FOR_CAB |
2536 PS_WAIT_FOR_PSPOLL_DATA |
2537 PS_WAIT_FOR_TX_ACK));
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002538 }
Sujith Manoharan07c15a32012-06-04 20:24:07 +05302539 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002540
Felix Fietkaua4943cc2013-06-30 12:02:13 +02002541 ath_txq_skb_done(sc, txq, skb);
Felix Fietkaud94a4612016-09-02 19:46:12 +03002542 tx_info->status.status_driver_data[0] = sta;
2543 __skb_queue_tail(&txq->complete_q, skb);
Sujithe8324352009-01-16 21:38:42 +05302544}
2545
2546static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
Felix Fietkaudb1a0522010-03-29 20:07:11 -07002547 struct ath_txq *txq, struct list_head *bf_q,
Felix Fietkaud94a4612016-09-02 19:46:12 +03002548 struct ieee80211_sta *sta,
Felix Fietkau156369f2011-12-14 22:08:04 +01002549 struct ath_tx_status *ts, int txok)
Sujithe8324352009-01-16 21:38:42 +05302550{
2551 struct sk_buff *skb = bf->bf_mpdu;
Felix Fietkau3afd21e2011-09-14 21:24:26 +02002552 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Sujithe8324352009-01-16 21:38:42 +05302553 unsigned long flags;
Vasanthakumar Thiagarajan6b2c4032009-03-20 15:27:50 +05302554 int tx_flags = 0;
Sujithe8324352009-01-16 21:38:42 +05302555
Felix Fietkau55797b12011-09-14 21:24:16 +02002556 if (!txok)
Vasanthakumar Thiagarajan6b2c4032009-03-20 15:27:50 +05302557 tx_flags |= ATH_TX_ERROR;
Sujithe8324352009-01-16 21:38:42 +05302558
Felix Fietkau3afd21e2011-09-14 21:24:26 +02002559 if (ts->ts_status & ATH9K_TXERR_FILT)
2560 tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
2561
Ben Greearc1739eb32010-10-14 12:45:29 -07002562 dma_unmap_single(sc->dev, bf->bf_buf_addr, skb->len, DMA_TO_DEVICE);
Ben Greear6cf9e992010-10-14 12:45:30 -07002563 bf->bf_buf_addr = 0;
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07002564 if (sc->tx99_state)
2565 goto skip_tx_complete;
Felix Fietkau9f42c2b2010-06-12 00:34:01 -04002566
2567 if (bf->bf_state.bfs_paprd) {
Mohammed Shafi Shajakhan9cf04dc2011-02-04 18:38:23 +05302568 if (time_after(jiffies,
2569 bf->bf_state.bfs_paprd_timestamp +
2570 msecs_to_jiffies(ATH_PAPRD_TIMEOUT)))
Vasanthakumar Thiagarajanca369eb2010-06-24 02:42:44 -07002571 dev_kfree_skb_any(skb);
Vasanthakumar Thiagarajan78a18172010-06-24 02:42:46 -07002572 else
Vasanthakumar Thiagarajanca369eb2010-06-24 02:42:44 -07002573 complete(&sc->paprd_complete);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -04002574 } else {
Felix Fietkau55797b12011-09-14 21:24:16 +02002575 ath_debug_stat_tx(sc, bf, ts, txq, tx_flags);
Felix Fietkaud94a4612016-09-02 19:46:12 +03002576 ath_tx_complete(sc, skb, tx_flags, txq, sta);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -04002577 }
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07002578skip_tx_complete:
Ben Greear6cf9e992010-10-14 12:45:30 -07002579 /* At this point, skb (bf->bf_mpdu) is consumed...make sure we don't
2580 * accidentally reference it later.
2581 */
2582 bf->bf_mpdu = NULL;
Sujithe8324352009-01-16 21:38:42 +05302583
2584 /*
2585 * Return the list of ath_buf of this mpdu to free queue
2586 */
2587 spin_lock_irqsave(&sc->tx.txbuflock, flags);
2588 list_splice_tail_init(bf_q, &sc->tx.txbuf);
2589 spin_unlock_irqrestore(&sc->tx.txbuflock, flags);
2590}
2591
Felix Fietkau0cdd5c62011-01-24 19:23:17 +01002592static void ath_tx_rc_status(struct ath_softc *sc, struct ath_buf *bf,
2593 struct ath_tx_status *ts, int nframes, int nbad,
Felix Fietkau3afd21e2011-09-14 21:24:26 +02002594 int txok)
Sujithc4288392008-11-18 09:09:30 +05302595{
Sujitha22be222009-03-30 15:28:36 +05302596 struct sk_buff *skb = bf->bf_mpdu;
Sujith254ad0f2009-02-04 08:10:19 +05302597 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Sujithc4288392008-11-18 09:09:30 +05302598 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Felix Fietkau0cdd5c62011-01-24 19:23:17 +01002599 struct ieee80211_hw *hw = sc->hw;
Felix Fietkauf0c255a2010-11-11 03:18:35 +01002600 struct ath_hw *ah = sc->sc_ah;
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05302601 u8 i, tx_rateindex;
Sujithc4288392008-11-18 09:09:30 +05302602
Sujith95e4acb2009-03-13 08:56:09 +05302603 if (txok)
Felix Fietkaudb1a0522010-03-29 20:07:11 -07002604 tx_info->status.ack_signal = ts->ts_rssi;
Sujith95e4acb2009-03-13 08:56:09 +05302605
Felix Fietkaudb1a0522010-03-29 20:07:11 -07002606 tx_rateindex = ts->ts_rateindex;
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05302607 WARN_ON(tx_rateindex >= hw->max_rates);
2608
Felix Fietkau3afd21e2011-09-14 21:24:26 +02002609 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
Felix Fietkaud9698472010-03-01 13:32:11 +01002610 tx_info->flags |= IEEE80211_TX_STAT_AMPDU;
Sujithc4288392008-11-18 09:09:30 +05302611
Felix Fietkaub572d032010-11-14 15:20:07 +01002612 BUG_ON(nbad > nframes);
Björn Smedmanebd02282010-10-10 22:44:39 +02002613 }
Rajkumar Manoharan185d1582011-09-26 21:48:39 +05302614 tx_info->status.ampdu_len = nframes;
2615 tx_info->status.ampdu_ack_len = nframes - nbad;
Björn Smedmanebd02282010-10-10 22:44:39 +02002616
Felix Fietkaudb1a0522010-03-29 20:07:11 -07002617 if ((ts->ts_status & ATH9K_TXERR_FILT) == 0 &&
Felix Fietkau3afd21e2011-09-14 21:24:26 +02002618 (tx_info->flags & IEEE80211_TX_CTL_NO_ACK) == 0) {
Felix Fietkauf0c255a2010-11-11 03:18:35 +01002619 /*
2620 * If an underrun error is seen assume it as an excessive
2621 * retry only if max frame trigger level has been reached
2622 * (2 KB for single stream, and 4 KB for dual stream).
2623 * Adjust the long retry as if the frame was tried
2624 * hw->max_rate_tries times to affect how rate control updates
2625 * PER for the failed rate.
2626 * In case of congestion on the bus penalizing this type of
2627 * underruns should help hardware actually transmit new frames
2628 * successfully by eventually preferring slower rates.
2629 * This itself should also alleviate congestion on the bus.
2630 */
Felix Fietkau3afd21e2011-09-14 21:24:26 +02002631 if (unlikely(ts->ts_flags & (ATH9K_TX_DATA_UNDERRUN |
2632 ATH9K_TX_DELIM_UNDERRUN)) &&
2633 ieee80211_is_data(hdr->frame_control) &&
Felix Fietkau83860c52011-03-23 20:57:33 +01002634 ah->tx_trig_level >= sc->sc_ah->config.max_txtrig_level)
Felix Fietkauf0c255a2010-11-11 03:18:35 +01002635 tx_info->status.rates[tx_rateindex].count =
2636 hw->max_rate_tries;
Sujithc4288392008-11-18 09:09:30 +05302637 }
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05302638
Felix Fietkau545750d2009-11-23 22:21:01 +01002639 for (i = tx_rateindex + 1; i < hw->max_rates; i++) {
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05302640 tx_info->status.rates[i].count = 0;
Felix Fietkau545750d2009-11-23 22:21:01 +01002641 tx_info->status.rates[i].idx = -1;
2642 }
Vasanthakumar Thiagarajan8a92e2e2009-03-20 15:27:49 +05302643
Felix Fietkau78c46532010-06-25 01:26:16 +02002644 tx_info->status.rates[tx_rateindex].count = ts->ts_longretry + 1;
Sujithc4288392008-11-18 09:09:30 +05302645}
2646
Sujithc4288392008-11-18 09:09:30 +05302647static void ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002648{
Sujithcbe61d82009-02-09 13:27:12 +05302649 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002650 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002651 struct ath_buf *bf, *lastbf, *bf_held = NULL;
2652 struct list_head bf_head;
Sujithc4288392008-11-18 09:09:30 +05302653 struct ath_desc *ds;
Felix Fietkau29bffa92010-03-29 20:14:23 -07002654 struct ath_tx_status ts;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002655 int status;
2656
Joe Perchesd2182b62011-12-15 14:55:53 -08002657 ath_dbg(common, QUEUE, "tx queue %d (%x), link %p\n",
Joe Perches226afe62010-12-02 19:12:37 -08002658 txq->axq_qnum, ath9k_hw_gettxbuf(sc->sc_ah, txq->axq_qnum),
2659 txq->axq_link);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002660
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002661 ath_txq_lock(sc, txq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002662 for (;;) {
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01002663 if (test_bit(ATH_OP_HW_RESET, &common->op_flags))
Felix Fietkau236de512011-09-03 01:40:25 +02002664 break;
2665
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002666 if (list_empty(&txq->axq_q)) {
2667 txq->axq_link = NULL;
Felix Fietkau73364b02013-08-06 14:18:08 +02002668 ath_txq_schedule(sc, txq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002669 break;
2670 }
2671 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
2672
2673 /*
2674 * There is a race condition that a BH gets scheduled
2675 * after sw writes TxE and before hw re-load the last
2676 * descriptor to get the newly chained one.
2677 * Software must keep the last DONE descriptor as a
2678 * holding descriptor - software does so by marking
2679 * it with the STALE flag.
2680 */
2681 bf_held = NULL;
Felix Fietkau50676b82013-08-10 15:59:16 +02002682 if (bf->bf_state.stale) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002683 bf_held = bf;
Felix Fietkaufce041b2011-05-19 12:20:25 +02002684 if (list_is_last(&bf_held->list, &txq->axq_q))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002685 break;
Felix Fietkaufce041b2011-05-19 12:20:25 +02002686
2687 bf = list_entry(bf_held->list.next, struct ath_buf,
2688 list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002689 }
2690
2691 lastbf = bf->bf_lastbf;
Sujithe8324352009-01-16 21:38:42 +05302692 ds = lastbf->bf_desc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002693
Felix Fietkau29bffa92010-03-29 20:14:23 -07002694 memset(&ts, 0, sizeof(ts));
2695 status = ath9k_hw_txprocdesc(ah, ds, &ts);
Felix Fietkaufce041b2011-05-19 12:20:25 +02002696 if (status == -EINPROGRESS)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002697 break;
Felix Fietkaufce041b2011-05-19 12:20:25 +02002698
Ben Greear2dac4fb2011-01-09 23:11:45 -08002699 TX_STAT_INC(txq->axq_qnum, txprocdesc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002700
2701 /*
2702 * Remove ath_buf's of the same transmit unit from txq,
2703 * however leave the last descriptor back as the holding
2704 * descriptor for hw.
2705 */
Felix Fietkau50676b82013-08-10 15:59:16 +02002706 lastbf->bf_state.stale = true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002707 INIT_LIST_HEAD(&bf_head);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002708 if (!list_is_singular(&lastbf->list))
2709 list_cut_position(&bf_head,
2710 &txq->axq_q, lastbf->list.prev);
2711
Felix Fietkaufce041b2011-05-19 12:20:25 +02002712 if (bf_held) {
Felix Fietkau0a8cea82010-04-19 19:57:30 +02002713 list_del(&bf_held->list);
Felix Fietkau0a8cea82010-04-19 19:57:30 +02002714 ath_tx_return_buffer(sc, bf_held);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002715 }
Johannes Berge6a98542008-10-21 12:40:02 +02002716
Felix Fietkaufce041b2011-05-19 12:20:25 +02002717 ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002718 }
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002719 ath_txq_unlock_complete(sc, txq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002720}
2721
Sujithe8324352009-01-16 21:38:42 +05302722void ath_tx_tasklet(struct ath_softc *sc)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002723{
Felix Fietkau239c7952012-03-14 16:40:26 +01002724 struct ath_hw *ah = sc->sc_ah;
2725 u32 qcumask = ((1 << ATH9K_NUM_TX_QUEUES) - 1) & ah->intr_txqs;
Sujithe8324352009-01-16 21:38:42 +05302726 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002727
Felix Fietkaud94a4612016-09-02 19:46:12 +03002728 rcu_read_lock();
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002729 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
Sujithe8324352009-01-16 21:38:42 +05302730 if (ATH_TXQ_SETUP(sc, i) && (qcumask & (1 << i)))
2731 ath_tx_processq(sc, &sc->tx.txq[i]);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002732 }
Felix Fietkaud94a4612016-09-02 19:46:12 +03002733 rcu_read_unlock();
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002734}
2735
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002736void ath_tx_edma_tasklet(struct ath_softc *sc)
2737{
Felix Fietkaufce041b2011-05-19 12:20:25 +02002738 struct ath_tx_status ts;
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002739 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2740 struct ath_hw *ah = sc->sc_ah;
2741 struct ath_txq *txq;
2742 struct ath_buf *bf, *lastbf;
2743 struct list_head bf_head;
Felix Fietkau99ba6a42013-04-08 00:04:13 +02002744 struct list_head *fifo_list;
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002745 int status;
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002746
Felix Fietkaud94a4612016-09-02 19:46:12 +03002747 rcu_read_lock();
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002748 for (;;) {
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01002749 if (test_bit(ATH_OP_HW_RESET, &common->op_flags))
Felix Fietkau236de512011-09-03 01:40:25 +02002750 break;
2751
Felix Fietkaufce041b2011-05-19 12:20:25 +02002752 status = ath9k_hw_txprocdesc(ah, NULL, (void *)&ts);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002753 if (status == -EINPROGRESS)
2754 break;
2755 if (status == -EIO) {
Joe Perchesd2182b62011-12-15 14:55:53 -08002756 ath_dbg(common, XMIT, "Error processing tx status\n");
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002757 break;
2758 }
2759
Felix Fietkau4e0ad252012-02-27 19:58:42 +01002760 /* Process beacon completions separately */
2761 if (ts.qid == sc->beacon.beaconq) {
2762 sc->beacon.tx_processed = true;
2763 sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK);
Simon Wunderlichd074e8d2013-08-14 08:01:38 +02002764
Sujith Manoharan27babf92014-08-23 13:29:16 +05302765 if (ath9k_is_chanctx_enabled()) {
2766 ath_chanctx_event(sc, NULL,
2767 ATH_CHANCTX_EVENT_BEACON_SENT);
2768 }
2769
Michal Kazior4effc6f2014-01-20 15:27:12 +01002770 ath9k_csa_update(sc);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002771 continue;
Felix Fietkau4e0ad252012-02-27 19:58:42 +01002772 }
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002773
Felix Fietkaufce041b2011-05-19 12:20:25 +02002774 txq = &sc->tx.txq[ts.qid];
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002775
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002776 ath_txq_lock(sc, txq);
Felix Fietkaufce041b2011-05-19 12:20:25 +02002777
Sujith Manoharan78ef7312012-11-21 18:13:11 +05302778 TX_STAT_INC(txq->axq_qnum, txprocdesc);
2779
Felix Fietkau99ba6a42013-04-08 00:04:13 +02002780 fifo_list = &txq->txq_fifo[txq->txq_tailidx];
2781 if (list_empty(fifo_list)) {
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002782 ath_txq_unlock(sc, txq);
Tobias Klausmannd1f1c0e2016-12-13 18:08:07 +01002783 break;
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002784 }
2785
Felix Fietkau99ba6a42013-04-08 00:04:13 +02002786 bf = list_first_entry(fifo_list, struct ath_buf, list);
Felix Fietkau50676b82013-08-10 15:59:16 +02002787 if (bf->bf_state.stale) {
Felix Fietkau99ba6a42013-04-08 00:04:13 +02002788 list_del(&bf->list);
2789 ath_tx_return_buffer(sc, bf);
2790 bf = list_first_entry(fifo_list, struct ath_buf, list);
2791 }
2792
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002793 lastbf = bf->bf_lastbf;
2794
2795 INIT_LIST_HEAD(&bf_head);
Felix Fietkau99ba6a42013-04-08 00:04:13 +02002796 if (list_is_last(&lastbf->list, fifo_list)) {
2797 list_splice_tail_init(fifo_list, &bf_head);
Felix Fietkaufce041b2011-05-19 12:20:25 +02002798 INCR(txq->txq_tailidx, ATH_TXFIFO_DEPTH);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002799
Felix Fietkaufce041b2011-05-19 12:20:25 +02002800 if (!list_empty(&txq->axq_q)) {
2801 struct list_head bf_q;
2802
2803 INIT_LIST_HEAD(&bf_q);
2804 txq->axq_link = NULL;
2805 list_splice_tail_init(&txq->axq_q, &bf_q);
2806 ath_tx_txqaddbuf(sc, txq, &bf_q, true);
2807 }
Felix Fietkau99ba6a42013-04-08 00:04:13 +02002808 } else {
Felix Fietkau50676b82013-08-10 15:59:16 +02002809 lastbf->bf_state.stale = true;
Felix Fietkau99ba6a42013-04-08 00:04:13 +02002810 if (bf != lastbf)
2811 list_cut_position(&bf_head, fifo_list,
2812 lastbf->list.prev);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002813 }
2814
Felix Fietkaufce041b2011-05-19 12:20:25 +02002815 ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head);
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002816 ath_txq_unlock_complete(sc, txq);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002817 }
Felix Fietkaud94a4612016-09-02 19:46:12 +03002818 rcu_read_unlock();
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -04002819}
2820
Sujithe8324352009-01-16 21:38:42 +05302821/*****************/
2822/* Init, Cleanup */
2823/*****************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002824
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002825static int ath_txstatus_setup(struct ath_softc *sc, int size)
2826{
2827 struct ath_descdma *dd = &sc->txsdma;
2828 u8 txs_len = sc->sc_ah->caps.txs_len;
2829
2830 dd->dd_desc_len = size * txs_len;
Felix Fietkaub81950b12012-12-12 13:14:22 +01002831 dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len,
2832 &dd->dd_desc_paddr, GFP_KERNEL);
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002833 if (!dd->dd_desc)
2834 return -ENOMEM;
2835
2836 return 0;
2837}
2838
2839static int ath_tx_edma_init(struct ath_softc *sc)
2840{
2841 int err;
2842
2843 err = ath_txstatus_setup(sc, ATH_TXSTATUS_RING_SIZE);
2844 if (!err)
2845 ath9k_hw_setup_statusring(sc->sc_ah, sc->txsdma.dd_desc,
2846 sc->txsdma.dd_desc_paddr,
2847 ATH_TXSTATUS_RING_SIZE);
2848
2849 return err;
2850}
2851
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002852int ath_tx_init(struct ath_softc *sc, int nbufs)
2853{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002854 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002855 int error = 0;
2856
Sujith797fe5cb2009-03-30 15:28:45 +05302857 spin_lock_init(&sc->tx.txbuflock);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002858
Sujith797fe5cb2009-03-30 15:28:45 +05302859 error = ath_descdma_setup(sc, &sc->tx.txdma, &sc->tx.txbuf,
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -04002860 "tx", nbufs, 1, 1);
Sujith797fe5cb2009-03-30 15:28:45 +05302861 if (error != 0) {
Joe Perches38002762010-12-02 19:12:36 -08002862 ath_err(common,
2863 "Failed to allocate tx descriptors: %d\n", error);
Felix Fietkaub81950b12012-12-12 13:14:22 +01002864 return error;
Sujith797fe5cb2009-03-30 15:28:45 +05302865 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002866
Sujith797fe5cb2009-03-30 15:28:45 +05302867 error = ath_descdma_setup(sc, &sc->beacon.bdma, &sc->beacon.bbuf,
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002868 "beacon", ATH_BCBUF, 1, 1);
Sujith797fe5cb2009-03-30 15:28:45 +05302869 if (error != 0) {
Joe Perches38002762010-12-02 19:12:36 -08002870 ath_err(common,
2871 "Failed to allocate beacon descriptors: %d\n", error);
Felix Fietkaub81950b12012-12-12 13:14:22 +01002872 return error;
Sujith797fe5cb2009-03-30 15:28:45 +05302873 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002874
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04002875 INIT_DELAYED_WORK(&sc->tx_complete_work, ath_tx_complete_poll_work);
2876
Felix Fietkaub81950b12012-12-12 13:14:22 +01002877 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
Vasanthakumar Thiagarajan5088c2f2010-04-15 17:39:34 -04002878 error = ath_tx_edma_init(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002879
2880 return error;
2881}
2882
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002883void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an)
2884{
Sujithc5170162008-10-29 10:13:59 +05302885 struct ath_atx_tid *tid;
Sujithc5170162008-10-29 10:13:59 +05302886 int tidno, acno;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002887
Toke Høiland-Jørgensen63fefa02016-12-05 13:27:37 +02002888 for (acno = 0; acno < IEEE80211_NUM_ACS; acno++)
2889 an->airtime_deficit[acno] = ATH_AIRTIME_QUANTUM;
2890
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01002891 for (tidno = 0; tidno < IEEE80211_NUM_TIDS; tidno++) {
2892 tid = ath_node_to_tid(an, tidno);
Sujithc5170162008-10-29 10:13:59 +05302893 tid->an = an;
2894 tid->tidno = tidno;
2895 tid->seq_start = tid->seq_next = 0;
2896 tid->baw_size = WME_MAX_BA;
2897 tid->baw_head = tid->baw_tail = 0;
Felix Fietkau08c96ab2013-05-18 21:28:15 +02002898 tid->active = false;
Felix Fietkau592fa222015-07-22 13:06:13 +02002899 tid->clear_ps_filter = true;
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01002900 tid->has_queued = false;
Felix Fietkaubb195ff2013-08-06 14:18:03 +02002901 __skb_queue_head_init(&tid->retry_q);
Felix Fietkaud70d8482015-07-22 13:06:14 +02002902 INIT_LIST_HEAD(&tid->list);
Sujithc5170162008-10-29 10:13:59 +05302903 acno = TID_TO_WME_AC(tidno);
Felix Fietkau592fa222015-07-22 13:06:13 +02002904 tid->txq = sc->tx.txq_map[acno];
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01002905
2906 if (!an->sta)
2907 break; /* just one multicast ath_atx_tid */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002908 }
2909}
2910
Sujithb5aa9bf2008-10-29 10:13:31 +05302911void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002912{
Felix Fietkau2b409942010-07-07 19:42:08 +02002913 struct ath_atx_tid *tid;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002914 struct ath_txq *txq;
Felix Fietkau066dae92010-11-07 14:59:39 +01002915 int tidno;
Sujithe8324352009-01-16 21:38:42 +05302916
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01002917 for (tidno = 0; tidno < IEEE80211_NUM_TIDS; tidno++) {
2918 tid = ath_node_to_tid(an, tidno);
Felix Fietkau592fa222015-07-22 13:06:13 +02002919 txq = tid->txq;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002920
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002921 ath_txq_lock(sc, txq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002922
Felix Fietkaud70d8482015-07-22 13:06:14 +02002923 if (!list_empty(&tid->list))
2924 list_del_init(&tid->list);
Felix Fietkau2b409942010-07-07 19:42:08 +02002925
Felix Fietkau2b409942010-07-07 19:42:08 +02002926 ath_tid_drain(sc, txq, tid);
Felix Fietkau08c96ab2013-05-18 21:28:15 +02002927 tid->active = false;
Felix Fietkau2b409942010-07-07 19:42:08 +02002928
Felix Fietkau23de5dc2011-12-19 16:45:54 +01002929 ath_txq_unlock(sc, txq);
Toke Høiland-Jørgensen50f08ed2016-11-09 12:31:49 +01002930
2931 if (!an->sta)
2932 break; /* just one multicast ath_atx_tid */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002933 }
2934}
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07002935
Sujith Manoharanef6b19e2013-10-24 12:04:39 +05302936#ifdef CONFIG_ATH9K_TX99
2937
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07002938int ath9k_tx99_send(struct ath_softc *sc, struct sk_buff *skb,
2939 struct ath_tx_control *txctl)
2940{
2941 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2942 struct ath_frame_info *fi = get_frame_info(skb);
2943 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2944 struct ath_buf *bf;
2945 int padpos, padsize;
2946
2947 padpos = ieee80211_hdrlen(hdr->frame_control);
2948 padsize = padpos & 3;
2949
2950 if (padsize && skb->len > padpos) {
2951 if (skb_headroom(skb) < padsize) {
2952 ath_dbg(common, XMIT,
2953 "tx99 padding failed\n");
Colin Ian Kingba38a172015-12-08 23:49:31 +00002954 return -EINVAL;
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07002955 }
2956
2957 skb_push(skb, padsize);
2958 memmove(skb->data, skb->data + padsize, padpos);
2959 }
2960
2961 fi->keyix = ATH9K_TXKEYIX_INVALID;
2962 fi->framelen = skb->len + FCS_LEN;
2963 fi->keytype = ATH9K_KEY_TYPE_CLEAR;
2964
2965 bf = ath_tx_setup_buffer(sc, txctl->txq, NULL, skb);
2966 if (!bf) {
2967 ath_dbg(common, XMIT, "tx99 buffer setup failed\n");
2968 return -EINVAL;
2969 }
2970
2971 ath_set_rates(sc->tx99_vif, NULL, bf);
2972
2973 ath9k_hw_set_desc_link(sc->sc_ah, bf->bf_desc, bf->bf_daddr);
2974 ath9k_hw_tx99_start(sc->sc_ah, txctl->txq->axq_qnum);
2975
2976 ath_tx_send_normal(sc, txctl->txq, NULL, skb);
2977
2978 return 0;
2979}
Sujith Manoharanef6b19e2013-10-24 12:04:39 +05302980
2981#endif /* CONFIG_ATH9K_TX99 */