Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
Sujith Manoharan | 5b68138 | 2011-05-17 13:36:18 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2011 Atheros Communications Inc. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
Alexey Dobriyan | b7f080c | 2011-06-16 11:01:34 +0000 | [diff] [blame] | 17 | #include <linux/dma-mapping.h> |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 18 | #include "ath9k.h" |
Luis R. Rodriguez | b622a72 | 2010-04-15 17:39:28 -0400 | [diff] [blame] | 19 | #include "ar9003_mac.h" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 20 | |
| 21 | #define BITS_PER_BYTE 8 |
| 22 | #define OFDM_PLCP_BITS 22 |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 23 | #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 */ |
| 32 | #define NUM_SYMBOLS_PER_USEC(_usec) (_usec >> 2) |
| 33 | #define NUM_SYMBOLS_PER_USEC_HALFGI(_usec) (((_usec*5)-4)/18) |
| 34 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 35 | |
Felix Fietkau | c666387 | 2010-04-19 19:57:33 +0200 | [diff] [blame] | 36 | static u16 bits_per_symbol[][2] = { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 37 | /* 20MHz 40MHz */ |
| 38 | { 26, 54 }, /* 0: BPSK */ |
| 39 | { 52, 108 }, /* 1: QPSK 1/2 */ |
| 40 | { 78, 162 }, /* 2: QPSK 3/4 */ |
| 41 | { 104, 216 }, /* 3: 16-QAM 1/2 */ |
| 42 | { 156, 324 }, /* 4: 16-QAM 3/4 */ |
| 43 | { 208, 432 }, /* 5: 64-QAM 2/3 */ |
| 44 | { 234, 486 }, /* 6: 64-QAM 3/4 */ |
| 45 | { 260, 540 }, /* 7: 64-QAM 5/6 */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | #define IS_HT_RATE(_rate) ((_rate) & 0x80) |
| 49 | |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 50 | static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq, |
| 51 | struct ath_atx_tid *tid, |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 52 | struct list_head *bf_head); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 53 | static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf, |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 54 | struct ath_txq *txq, struct list_head *bf_q, |
| 55 | struct ath_tx_status *ts, int txok, int sendbar); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 56 | static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq, |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 57 | struct list_head *head, bool internal); |
Felix Fietkau | 269c44b | 2010-11-14 15:20:06 +0100 | [diff] [blame] | 58 | static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf, int len); |
Felix Fietkau | 0cdd5c6 | 2011-01-24 19:23:17 +0100 | [diff] [blame] | 59 | static void ath_tx_rc_status(struct ath_softc *sc, struct ath_buf *bf, |
| 60 | struct ath_tx_status *ts, int nframes, int nbad, |
| 61 | int txok, bool update_rc); |
Felix Fietkau | 90fa539 | 2010-09-20 13:45:38 +0200 | [diff] [blame] | 62 | static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid, |
| 63 | int seqno); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 64 | |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 65 | enum { |
Felix Fietkau | 0e668cd | 2010-04-19 19:57:32 +0200 | [diff] [blame] | 66 | MCS_HT20, |
| 67 | MCS_HT20_SGI, |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 68 | MCS_HT40, |
| 69 | MCS_HT40_SGI, |
| 70 | }; |
| 71 | |
Felix Fietkau | 0e668cd | 2010-04-19 19:57:32 +0200 | [diff] [blame] | 72 | static int ath_max_4ms_framelen[4][32] = { |
| 73 | [MCS_HT20] = { |
| 74 | 3212, 6432, 9648, 12864, 19300, 25736, 28952, 32172, |
| 75 | 6424, 12852, 19280, 25708, 38568, 51424, 57852, 64280, |
| 76 | 9628, 19260, 28896, 38528, 57792, 65532, 65532, 65532, |
| 77 | 12828, 25656, 38488, 51320, 65532, 65532, 65532, 65532, |
| 78 | }, |
| 79 | [MCS_HT20_SGI] = { |
| 80 | 3572, 7144, 10720, 14296, 21444, 28596, 32172, 35744, |
| 81 | 7140, 14284, 21428, 28568, 42856, 57144, 64288, 65532, |
| 82 | 10700, 21408, 32112, 42816, 64228, 65532, 65532, 65532, |
| 83 | 14256, 28516, 42780, 57040, 65532, 65532, 65532, 65532, |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 84 | }, |
| 85 | [MCS_HT40] = { |
Felix Fietkau | 0e668cd | 2010-04-19 19:57:32 +0200 | [diff] [blame] | 86 | 6680, 13360, 20044, 26724, 40092, 53456, 60140, 65532, |
| 87 | 13348, 26700, 40052, 53400, 65532, 65532, 65532, 65532, |
| 88 | 20004, 40008, 60016, 65532, 65532, 65532, 65532, 65532, |
| 89 | 26644, 53292, 65532, 65532, 65532, 65532, 65532, 65532, |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 90 | }, |
| 91 | [MCS_HT40_SGI] = { |
Felix Fietkau | 0e668cd | 2010-04-19 19:57:32 +0200 | [diff] [blame] | 92 | 7420, 14844, 22272, 29696, 44544, 59396, 65532, 65532, |
| 93 | 14832, 29668, 44504, 59340, 65532, 65532, 65532, 65532, |
| 94 | 22232, 44464, 65532, 65532, 65532, 65532, 65532, 65532, |
| 95 | 29616, 59232, 65532, 65532, 65532, 65532, 65532, 65532, |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 96 | } |
| 97 | }; |
| 98 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 99 | /*********************/ |
| 100 | /* Aggregation logic */ |
| 101 | /*********************/ |
| 102 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 103 | static void ath_tx_queue_tid(struct ath_txq *txq, struct ath_atx_tid *tid) |
| 104 | { |
| 105 | struct ath_atx_ac *ac = tid->ac; |
| 106 | |
| 107 | if (tid->paused) |
| 108 | return; |
| 109 | |
| 110 | if (tid->sched) |
| 111 | return; |
| 112 | |
| 113 | tid->sched = true; |
| 114 | list_add_tail(&tid->list, &ac->tid_q); |
| 115 | |
| 116 | if (ac->sched) |
| 117 | return; |
| 118 | |
| 119 | ac->sched = true; |
| 120 | list_add_tail(&ac->list, &txq->axq_acq); |
| 121 | } |
| 122 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 123 | static void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid) |
| 124 | { |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 125 | struct ath_txq *txq = tid->ac->txq; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 126 | |
Lorenzo Bianconi | 7540184 | 2010-08-01 15:47:32 +0200 | [diff] [blame] | 127 | WARN_ON(!tid->paused); |
| 128 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 129 | spin_lock_bh(&txq->axq_lock); |
Lorenzo Bianconi | 7540184 | 2010-08-01 15:47:32 +0200 | [diff] [blame] | 130 | tid->paused = false; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 131 | |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 132 | if (skb_queue_empty(&tid->buf_q)) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 133 | goto unlock; |
| 134 | |
| 135 | ath_tx_queue_tid(txq, tid); |
| 136 | ath_txq_schedule(sc, txq); |
| 137 | unlock: |
| 138 | spin_unlock_bh(&txq->axq_lock); |
| 139 | } |
| 140 | |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 141 | static struct ath_frame_info *get_frame_info(struct sk_buff *skb) |
Felix Fietkau | 76e4522 | 2010-11-14 15:20:08 +0100 | [diff] [blame] | 142 | { |
| 143 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 144 | BUILD_BUG_ON(sizeof(struct ath_frame_info) > |
| 145 | sizeof(tx_info->rate_driver_data)); |
| 146 | return (struct ath_frame_info *) &tx_info->rate_driver_data[0]; |
Felix Fietkau | 76e4522 | 2010-11-14 15:20:08 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 149 | static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid) |
| 150 | { |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 151 | struct ath_txq *txq = tid->ac->txq; |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 152 | struct sk_buff *skb; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 153 | struct ath_buf *bf; |
| 154 | struct list_head bf_head; |
Felix Fietkau | 90fa539 | 2010-09-20 13:45:38 +0200 | [diff] [blame] | 155 | struct ath_tx_status ts; |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 156 | struct ath_frame_info *fi; |
Felix Fietkau | 90fa539 | 2010-09-20 13:45:38 +0200 | [diff] [blame] | 157 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 158 | INIT_LIST_HEAD(&bf_head); |
| 159 | |
Felix Fietkau | 90fa539 | 2010-09-20 13:45:38 +0200 | [diff] [blame] | 160 | memset(&ts, 0, sizeof(ts)); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 161 | spin_lock_bh(&txq->axq_lock); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 162 | |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 163 | while ((skb = __skb_dequeue(&tid->buf_q))) { |
| 164 | fi = get_frame_info(skb); |
| 165 | bf = fi->bf; |
| 166 | |
| 167 | list_add_tail(&bf->list, &bf_head); |
Felix Fietkau | 90fa539 | 2010-09-20 13:45:38 +0200 | [diff] [blame] | 168 | |
Felix Fietkau | e1566d1 | 2010-11-20 03:08:46 +0100 | [diff] [blame] | 169 | spin_unlock_bh(&txq->axq_lock); |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 170 | if (fi->retries) { |
| 171 | ath_tx_update_baw(sc, tid, fi->seqno); |
Felix Fietkau | 7d2c16b | 2011-03-12 01:11:28 +0100 | [diff] [blame] | 172 | ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0, 1); |
Felix Fietkau | 90fa539 | 2010-09-20 13:45:38 +0200 | [diff] [blame] | 173 | } else { |
Felix Fietkau | a9e99a0 | 2011-01-10 17:05:47 -0700 | [diff] [blame] | 174 | ath_tx_send_normal(sc, txq, NULL, &bf_head); |
Felix Fietkau | 90fa539 | 2010-09-20 13:45:38 +0200 | [diff] [blame] | 175 | } |
Felix Fietkau | e1566d1 | 2010-11-20 03:08:46 +0100 | [diff] [blame] | 176 | spin_lock_bh(&txq->axq_lock); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | spin_unlock_bh(&txq->axq_lock); |
| 180 | } |
| 181 | |
| 182 | static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid, |
| 183 | int seqno) |
| 184 | { |
| 185 | int index, cindex; |
| 186 | |
| 187 | index = ATH_BA_INDEX(tid->seq_start, seqno); |
| 188 | cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); |
| 189 | |
Felix Fietkau | 81ee13b | 2010-09-20 13:45:36 +0200 | [diff] [blame] | 190 | __clear_bit(cindex, tid->tx_buf); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 191 | |
Felix Fietkau | 81ee13b | 2010-09-20 13:45:36 +0200 | [diff] [blame] | 192 | while (tid->baw_head != tid->baw_tail && !test_bit(tid->baw_head, tid->tx_buf)) { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 193 | INCR(tid->seq_start, IEEE80211_SEQ_MAX); |
| 194 | INCR(tid->baw_head, ATH_TID_MAX_BUFS); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | static void ath_tx_addto_baw(struct ath_softc *sc, struct ath_atx_tid *tid, |
Felix Fietkau | 2d3bcba | 2010-11-14 15:20:01 +0100 | [diff] [blame] | 199 | u16 seqno) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 200 | { |
| 201 | int index, cindex; |
| 202 | |
Felix Fietkau | 2d3bcba | 2010-11-14 15:20:01 +0100 | [diff] [blame] | 203 | index = ATH_BA_INDEX(tid->seq_start, seqno); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 204 | cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); |
Felix Fietkau | 81ee13b | 2010-09-20 13:45:36 +0200 | [diff] [blame] | 205 | __set_bit(cindex, tid->tx_buf); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 206 | |
| 207 | if (index >= ((tid->baw_tail - tid->baw_head) & |
| 208 | (ATH_TID_MAX_BUFS - 1))) { |
| 209 | tid->baw_tail = cindex; |
| 210 | INCR(tid->baw_tail, ATH_TID_MAX_BUFS); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | * TODO: For frame(s) that are in the retry state, we will reuse the |
| 216 | * sequence number(s) without setting the retry bit. The |
| 217 | * alternative is to give up on these and BAR the receiver's window |
| 218 | * forward. |
| 219 | */ |
| 220 | static void ath_tid_drain(struct ath_softc *sc, struct ath_txq *txq, |
| 221 | struct ath_atx_tid *tid) |
| 222 | |
| 223 | { |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 224 | struct sk_buff *skb; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 225 | struct ath_buf *bf; |
| 226 | struct list_head bf_head; |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 227 | struct ath_tx_status ts; |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 228 | struct ath_frame_info *fi; |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 229 | |
| 230 | memset(&ts, 0, sizeof(ts)); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 231 | INIT_LIST_HEAD(&bf_head); |
| 232 | |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 233 | while ((skb = __skb_dequeue(&tid->buf_q))) { |
| 234 | fi = get_frame_info(skb); |
| 235 | bf = fi->bf; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 236 | |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 237 | list_add_tail(&bf->list, &bf_head); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 238 | |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 239 | if (fi->retries) |
| 240 | ath_tx_update_baw(sc, tid, fi->seqno); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 241 | |
| 242 | spin_unlock(&txq->axq_lock); |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 243 | ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0, 0); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 244 | spin_lock(&txq->axq_lock); |
| 245 | } |
| 246 | |
| 247 | tid->seq_next = tid->seq_start; |
| 248 | tid->baw_tail = tid->baw_head; |
| 249 | } |
| 250 | |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 251 | static void ath_tx_set_retry(struct ath_softc *sc, struct ath_txq *txq, |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 252 | struct sk_buff *skb) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 253 | { |
Felix Fietkau | 8b7f853 | 2010-11-28 19:37:48 +0100 | [diff] [blame] | 254 | struct ath_frame_info *fi = get_frame_info(skb); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 255 | struct ieee80211_hdr *hdr; |
| 256 | |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 257 | TX_STAT_INC(txq->axq_qnum, a_retries); |
Felix Fietkau | 8b7f853 | 2010-11-28 19:37:48 +0100 | [diff] [blame] | 258 | if (fi->retries++ > 0) |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 259 | return; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 260 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 261 | hdr = (struct ieee80211_hdr *)skb->data; |
| 262 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_RETRY); |
| 263 | } |
| 264 | |
Felix Fietkau | 0a8cea8 | 2010-04-19 19:57:30 +0200 | [diff] [blame] | 265 | static struct ath_buf *ath_tx_get_buffer(struct ath_softc *sc) |
| 266 | { |
| 267 | struct ath_buf *bf = NULL; |
| 268 | |
| 269 | spin_lock_bh(&sc->tx.txbuflock); |
| 270 | |
| 271 | if (unlikely(list_empty(&sc->tx.txbuf))) { |
| 272 | spin_unlock_bh(&sc->tx.txbuflock); |
| 273 | return NULL; |
| 274 | } |
| 275 | |
| 276 | bf = list_first_entry(&sc->tx.txbuf, struct ath_buf, list); |
| 277 | list_del(&bf->list); |
| 278 | |
| 279 | spin_unlock_bh(&sc->tx.txbuflock); |
| 280 | |
| 281 | return bf; |
| 282 | } |
| 283 | |
| 284 | static void ath_tx_return_buffer(struct ath_softc *sc, struct ath_buf *bf) |
| 285 | { |
| 286 | spin_lock_bh(&sc->tx.txbuflock); |
| 287 | list_add_tail(&bf->list, &sc->tx.txbuf); |
| 288 | spin_unlock_bh(&sc->tx.txbuflock); |
| 289 | } |
| 290 | |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 291 | static struct ath_buf* ath_clone_txbuf(struct ath_softc *sc, struct ath_buf *bf) |
| 292 | { |
| 293 | struct ath_buf *tbf; |
| 294 | |
Felix Fietkau | 0a8cea8 | 2010-04-19 19:57:30 +0200 | [diff] [blame] | 295 | tbf = ath_tx_get_buffer(sc); |
| 296 | if (WARN_ON(!tbf)) |
Vasanthakumar Thiagarajan | 8a46097 | 2009-06-10 17:50:09 +0530 | [diff] [blame] | 297 | return NULL; |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 298 | |
| 299 | ATH_TXBUF_RESET(tbf); |
| 300 | |
| 301 | tbf->bf_mpdu = bf->bf_mpdu; |
| 302 | tbf->bf_buf_addr = bf->bf_buf_addr; |
Vasanthakumar Thiagarajan | d826c83 | 2010-04-15 17:38:45 -0400 | [diff] [blame] | 303 | memcpy(tbf->bf_desc, bf->bf_desc, sc->sc_ah->caps.tx_desc_len); |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 304 | tbf->bf_state = bf->bf_state; |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 305 | |
| 306 | return tbf; |
| 307 | } |
| 308 | |
Felix Fietkau | b572d03 | 2010-11-14 15:20:07 +0100 | [diff] [blame] | 309 | static void ath_tx_count_frames(struct ath_softc *sc, struct ath_buf *bf, |
| 310 | struct ath_tx_status *ts, int txok, |
| 311 | int *nframes, int *nbad) |
| 312 | { |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 313 | struct ath_frame_info *fi; |
Felix Fietkau | b572d03 | 2010-11-14 15:20:07 +0100 | [diff] [blame] | 314 | u16 seq_st = 0; |
| 315 | u32 ba[WME_BA_BMP_SIZE >> 5]; |
| 316 | int ba_index; |
| 317 | int isaggr = 0; |
| 318 | |
| 319 | *nbad = 0; |
| 320 | *nframes = 0; |
| 321 | |
Felix Fietkau | b572d03 | 2010-11-14 15:20:07 +0100 | [diff] [blame] | 322 | isaggr = bf_isaggr(bf); |
| 323 | if (isaggr) { |
| 324 | seq_st = ts->ts_seqnum; |
| 325 | memcpy(ba, &ts->ba_low, WME_BA_BMP_SIZE >> 3); |
| 326 | } |
| 327 | |
| 328 | while (bf) { |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 329 | fi = get_frame_info(bf->bf_mpdu); |
| 330 | ba_index = ATH_BA_INDEX(seq_st, fi->seqno); |
Felix Fietkau | b572d03 | 2010-11-14 15:20:07 +0100 | [diff] [blame] | 331 | |
| 332 | (*nframes)++; |
| 333 | if (!txok || (isaggr && !ATH_BA_ISSET(ba, ba_index))) |
| 334 | (*nbad)++; |
| 335 | |
| 336 | bf = bf->bf_next; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 341 | static void ath_tx_complete_aggr(struct ath_softc *sc, struct ath_txq *txq, |
| 342 | struct ath_buf *bf, struct list_head *bf_q, |
Felix Fietkau | c599261 | 2010-11-14 15:20:09 +0100 | [diff] [blame] | 343 | struct ath_tx_status *ts, int txok, bool retry) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 344 | { |
| 345 | struct ath_node *an = NULL; |
| 346 | struct sk_buff *skb; |
Sujith | 1286ec6 | 2009-01-27 13:30:37 +0530 | [diff] [blame] | 347 | struct ieee80211_sta *sta; |
Felix Fietkau | 0cdd5c6 | 2011-01-24 19:23:17 +0100 | [diff] [blame] | 348 | struct ieee80211_hw *hw = sc->hw; |
Sujith | 1286ec6 | 2009-01-27 13:30:37 +0530 | [diff] [blame] | 349 | struct ieee80211_hdr *hdr; |
Luis R. Rodriguez | 76d5a9e | 2009-11-02 16:08:34 -0800 | [diff] [blame] | 350 | struct ieee80211_tx_info *tx_info; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 351 | struct ath_atx_tid *tid = NULL; |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 352 | struct ath_buf *bf_next, *bf_last = bf->bf_lastbf; |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 353 | struct list_head bf_head; |
| 354 | struct sk_buff_head bf_pending; |
Vasanthakumar Thiagarajan | 0934af2 | 2009-03-18 20:22:00 +0530 | [diff] [blame] | 355 | u16 seq_st = 0, acked_cnt = 0, txfail_cnt = 0; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 356 | u32 ba[WME_BA_BMP_SIZE >> 5]; |
Vasanthakumar Thiagarajan | 0934af2 | 2009-03-18 20:22:00 +0530 | [diff] [blame] | 357 | int isaggr, txfail, txpending, sendbar = 0, needreset = 0, nbad = 0; |
| 358 | bool rc_update = true; |
Felix Fietkau | 78c4653 | 2010-06-25 01:26:16 +0200 | [diff] [blame] | 359 | struct ieee80211_tx_rate rates[4]; |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 360 | struct ath_frame_info *fi; |
Björn Smedman | ebd0228 | 2010-10-10 22:44:39 +0200 | [diff] [blame] | 361 | int nframes; |
Felix Fietkau | 5daefbd | 2010-11-14 15:20:02 +0100 | [diff] [blame] | 362 | u8 tidno; |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 363 | bool clear_filter; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 364 | |
Sujith | a22be22 | 2009-03-30 15:28:36 +0530 | [diff] [blame] | 365 | skb = bf->bf_mpdu; |
Sujith | 1286ec6 | 2009-01-27 13:30:37 +0530 | [diff] [blame] | 366 | hdr = (struct ieee80211_hdr *)skb->data; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 367 | |
Luis R. Rodriguez | 76d5a9e | 2009-11-02 16:08:34 -0800 | [diff] [blame] | 368 | tx_info = IEEE80211_SKB_CB(skb); |
Luis R. Rodriguez | 76d5a9e | 2009-11-02 16:08:34 -0800 | [diff] [blame] | 369 | |
Felix Fietkau | 78c4653 | 2010-06-25 01:26:16 +0200 | [diff] [blame] | 370 | memcpy(rates, tx_info->control.rates, sizeof(rates)); |
| 371 | |
Sujith | 1286ec6 | 2009-01-27 13:30:37 +0530 | [diff] [blame] | 372 | rcu_read_lock(); |
| 373 | |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 374 | sta = ieee80211_find_sta_by_ifaddr(hw, hdr->addr1, hdr->addr2); |
Sujith | 1286ec6 | 2009-01-27 13:30:37 +0530 | [diff] [blame] | 375 | if (!sta) { |
| 376 | rcu_read_unlock(); |
Felix Fietkau | 73e1946 | 2010-07-07 19:42:09 +0200 | [diff] [blame] | 377 | |
Felix Fietkau | 31e79a5 | 2010-07-12 23:16:34 +0200 | [diff] [blame] | 378 | INIT_LIST_HEAD(&bf_head); |
| 379 | while (bf) { |
| 380 | bf_next = bf->bf_next; |
| 381 | |
| 382 | bf->bf_state.bf_type |= BUF_XRETRY; |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 383 | if (!bf->bf_stale || bf_next != NULL) |
Felix Fietkau | 31e79a5 | 2010-07-12 23:16:34 +0200 | [diff] [blame] | 384 | list_move_tail(&bf->list, &bf_head); |
| 385 | |
Felix Fietkau | 0cdd5c6 | 2011-01-24 19:23:17 +0100 | [diff] [blame] | 386 | ath_tx_rc_status(sc, bf, ts, 1, 1, 0, false); |
Felix Fietkau | 31e79a5 | 2010-07-12 23:16:34 +0200 | [diff] [blame] | 387 | ath_tx_complete_buf(sc, bf, txq, &bf_head, ts, |
| 388 | 0, 0); |
| 389 | |
| 390 | bf = bf_next; |
| 391 | } |
Sujith | 1286ec6 | 2009-01-27 13:30:37 +0530 | [diff] [blame] | 392 | return; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 393 | } |
| 394 | |
Sujith | 1286ec6 | 2009-01-27 13:30:37 +0530 | [diff] [blame] | 395 | an = (struct ath_node *)sta->drv_priv; |
Felix Fietkau | 5daefbd | 2010-11-14 15:20:02 +0100 | [diff] [blame] | 396 | tidno = ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK; |
| 397 | tid = ATH_AN_2_TID(an, tidno); |
Sujith | 1286ec6 | 2009-01-27 13:30:37 +0530 | [diff] [blame] | 398 | |
Felix Fietkau | b11b160 | 2010-07-11 12:48:44 +0200 | [diff] [blame] | 399 | /* |
| 400 | * The hardware occasionally sends a tx status for the wrong TID. |
| 401 | * In this case, the BA status cannot be considered valid and all |
| 402 | * subframes need to be retransmitted |
| 403 | */ |
Felix Fietkau | 5daefbd | 2010-11-14 15:20:02 +0100 | [diff] [blame] | 404 | if (tidno != ts->tid) |
Felix Fietkau | b11b160 | 2010-07-11 12:48:44 +0200 | [diff] [blame] | 405 | txok = false; |
| 406 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 407 | isaggr = bf_isaggr(bf); |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 408 | memset(ba, 0, WME_BA_BMP_SIZE >> 3); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 409 | |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 410 | if (isaggr && txok) { |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 411 | if (ts->ts_flags & ATH9K_TX_BA) { |
| 412 | seq_st = ts->ts_seqnum; |
| 413 | memcpy(ba, &ts->ba_low, WME_BA_BMP_SIZE >> 3); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 414 | } else { |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 415 | /* |
| 416 | * AR5416 can become deaf/mute when BA |
| 417 | * issue happens. Chip needs to be reset. |
| 418 | * But AP code may have sychronization issues |
| 419 | * when perform internal reset in this routine. |
| 420 | * Only enable reset in STA mode for now. |
| 421 | */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 422 | if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION) |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 423 | needreset = 1; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 427 | __skb_queue_head_init(&bf_pending); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 428 | |
Felix Fietkau | b572d03 | 2010-11-14 15:20:07 +0100 | [diff] [blame] | 429 | ath_tx_count_frames(sc, bf, ts, txok, &nframes, &nbad); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 430 | while (bf) { |
Felix Fietkau | f0b8220 | 2011-01-15 14:30:15 +0100 | [diff] [blame] | 431 | txfail = txpending = sendbar = 0; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 432 | bf_next = bf->bf_next; |
| 433 | |
Felix Fietkau | 78c4653 | 2010-06-25 01:26:16 +0200 | [diff] [blame] | 434 | skb = bf->bf_mpdu; |
| 435 | tx_info = IEEE80211_SKB_CB(skb); |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 436 | fi = get_frame_info(skb); |
Felix Fietkau | 78c4653 | 2010-06-25 01:26:16 +0200 | [diff] [blame] | 437 | |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 438 | if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, fi->seqno))) { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 439 | /* transmit completion, subframe is |
| 440 | * acked by block ack */ |
Vasanthakumar Thiagarajan | 0934af2 | 2009-03-18 20:22:00 +0530 | [diff] [blame] | 441 | acked_cnt++; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 442 | } else if (!isaggr && txok) { |
| 443 | /* transmit completion */ |
Vasanthakumar Thiagarajan | 0934af2 | 2009-03-18 20:22:00 +0530 | [diff] [blame] | 444 | acked_cnt++; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 445 | } else { |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 446 | if ((tid->state & AGGR_CLEANUP) || !retry) { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 447 | /* |
| 448 | * cleanup in progress, just fail |
| 449 | * the un-acked sub-frames |
| 450 | */ |
| 451 | txfail = 1; |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 452 | } else if (fi->retries < ATH_MAX_SW_RETRIES) { |
| 453 | if (!(ts->ts_status & ATH9K_TXERR_FILT) || |
| 454 | !an->sleeping) |
| 455 | ath_tx_set_retry(sc, txq, bf->bf_mpdu); |
| 456 | |
| 457 | clear_filter = true; |
| 458 | txpending = 1; |
| 459 | } else { |
| 460 | bf->bf_state.bf_type |= BUF_XRETRY; |
| 461 | txfail = 1; |
| 462 | sendbar = 1; |
| 463 | txfail_cnt++; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 467 | /* |
| 468 | * Make sure the last desc is reclaimed if it |
| 469 | * not a holding desc. |
| 470 | */ |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 471 | INIT_LIST_HEAD(&bf_head); |
| 472 | if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) || |
| 473 | bf_next != NULL || !bf_last->bf_stale) |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 474 | list_move_tail(&bf->list, &bf_head); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 475 | |
Felix Fietkau | 90fa539 | 2010-09-20 13:45:38 +0200 | [diff] [blame] | 476 | if (!txpending || (tid->state & AGGR_CLEANUP)) { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 477 | /* |
| 478 | * complete the acked-ones/xretried ones; update |
| 479 | * block-ack window |
| 480 | */ |
| 481 | spin_lock_bh(&txq->axq_lock); |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 482 | ath_tx_update_baw(sc, tid, fi->seqno); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 483 | spin_unlock_bh(&txq->axq_lock); |
| 484 | |
Vasanthakumar Thiagarajan | 8a92e2e | 2009-03-20 15:27:49 +0530 | [diff] [blame] | 485 | if (rc_update && (acked_cnt == 1 || txfail_cnt == 1)) { |
Felix Fietkau | 78c4653 | 2010-06-25 01:26:16 +0200 | [diff] [blame] | 486 | memcpy(tx_info->control.rates, rates, sizeof(rates)); |
Felix Fietkau | 0cdd5c6 | 2011-01-24 19:23:17 +0100 | [diff] [blame] | 487 | ath_tx_rc_status(sc, bf, ts, nframes, nbad, txok, true); |
Vasanthakumar Thiagarajan | 8a92e2e | 2009-03-20 15:27:49 +0530 | [diff] [blame] | 488 | rc_update = false; |
| 489 | } else { |
Felix Fietkau | 0cdd5c6 | 2011-01-24 19:23:17 +0100 | [diff] [blame] | 490 | ath_tx_rc_status(sc, bf, ts, nframes, nbad, txok, false); |
Vasanthakumar Thiagarajan | 8a92e2e | 2009-03-20 15:27:49 +0530 | [diff] [blame] | 491 | } |
| 492 | |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 493 | ath_tx_complete_buf(sc, bf, txq, &bf_head, ts, |
| 494 | !txfail, sendbar); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 495 | } else { |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 496 | /* retry the un-acked ones */ |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 497 | ath9k_hw_set_clrdmask(sc->sc_ah, bf->bf_desc, false); |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 498 | if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)) { |
| 499 | if (bf->bf_next == NULL && bf_last->bf_stale) { |
| 500 | struct ath_buf *tbf; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 501 | |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 502 | tbf = ath_clone_txbuf(sc, bf_last); |
| 503 | /* |
| 504 | * Update tx baw and complete the |
| 505 | * frame with failed status if we |
| 506 | * run out of tx buf. |
| 507 | */ |
| 508 | if (!tbf) { |
| 509 | spin_lock_bh(&txq->axq_lock); |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 510 | ath_tx_update_baw(sc, tid, fi->seqno); |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 511 | spin_unlock_bh(&txq->axq_lock); |
Vasanthakumar Thiagarajan | c41d92d | 2009-07-14 20:17:11 -0400 | [diff] [blame] | 512 | |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 513 | bf->bf_state.bf_type |= |
| 514 | BUF_XRETRY; |
Felix Fietkau | 0cdd5c6 | 2011-01-24 19:23:17 +0100 | [diff] [blame] | 515 | ath_tx_rc_status(sc, bf, ts, nframes, |
Felix Fietkau | b572d03 | 2010-11-14 15:20:07 +0100 | [diff] [blame] | 516 | nbad, 0, false); |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 517 | ath_tx_complete_buf(sc, bf, txq, |
| 518 | &bf_head, |
| 519 | ts, 0, 0); |
| 520 | break; |
| 521 | } |
| 522 | |
| 523 | ath9k_hw_cleartxdesc(sc->sc_ah, |
| 524 | tbf->bf_desc); |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 525 | fi->bf = tbf; |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 526 | } else { |
| 527 | /* |
| 528 | * Clear descriptor status words for |
| 529 | * software retry |
| 530 | */ |
| 531 | ath9k_hw_cleartxdesc(sc->sc_ah, |
| 532 | bf->bf_desc); |
Vasanthakumar Thiagarajan | c41d92d | 2009-07-14 20:17:11 -0400 | [diff] [blame] | 533 | } |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | /* |
| 537 | * Put this buffer to the temporary pending |
| 538 | * queue to retain ordering |
| 539 | */ |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 540 | __skb_queue_tail(&bf_pending, skb); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | bf = bf_next; |
| 544 | } |
| 545 | |
Felix Fietkau | 4cee786 | 2010-07-23 03:53:16 +0200 | [diff] [blame] | 546 | /* prepend un-acked frames to the beginning of the pending frame queue */ |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 547 | if (!skb_queue_empty(&bf_pending)) { |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 548 | if (an->sleeping) |
| 549 | ieee80211_sta_set_tim(sta); |
| 550 | |
Felix Fietkau | 4cee786 | 2010-07-23 03:53:16 +0200 | [diff] [blame] | 551 | spin_lock_bh(&txq->axq_lock); |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 552 | if (clear_filter) |
| 553 | tid->ac->clear_ps_filter = true; |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 554 | skb_queue_splice(&bf_pending, &tid->buf_q); |
Felix Fietkau | 9af73cf | 2011-08-10 15:23:35 -0600 | [diff] [blame] | 555 | if (!an->sleeping) |
| 556 | ath_tx_queue_tid(txq, tid); |
Felix Fietkau | 4cee786 | 2010-07-23 03:53:16 +0200 | [diff] [blame] | 557 | spin_unlock_bh(&txq->axq_lock); |
| 558 | } |
| 559 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 560 | if (tid->state & AGGR_CLEANUP) { |
Felix Fietkau | 90fa539 | 2010-09-20 13:45:38 +0200 | [diff] [blame] | 561 | ath_tx_flush_tid(sc, tid); |
| 562 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 563 | if (tid->baw_head == tid->baw_tail) { |
| 564 | tid->state &= ~AGGR_ADDBA_COMPLETE; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 565 | tid->state &= ~AGGR_CLEANUP; |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 566 | } |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 567 | } |
| 568 | |
Sujith | 1286ec6 | 2009-01-27 13:30:37 +0530 | [diff] [blame] | 569 | rcu_read_unlock(); |
| 570 | |
Rajkumar Manoharan | f6b4e4d | 2011-06-24 17:38:13 +0530 | [diff] [blame] | 571 | if (needreset) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 572 | ath_reset(sc, false); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 573 | } |
| 574 | |
Rajkumar Manoharan | 1a6e9d0 | 2011-08-23 12:32:57 +0530 | [diff] [blame] | 575 | static bool ath_lookup_legacy(struct ath_buf *bf) |
| 576 | { |
| 577 | struct sk_buff *skb; |
| 578 | struct ieee80211_tx_info *tx_info; |
| 579 | struct ieee80211_tx_rate *rates; |
| 580 | int i; |
| 581 | |
| 582 | skb = bf->bf_mpdu; |
| 583 | tx_info = IEEE80211_SKB_CB(skb); |
| 584 | rates = tx_info->control.rates; |
| 585 | |
Felix Fietkau | 059ee09 | 2011-08-27 10:25:27 +0200 | [diff] [blame] | 586 | for (i = 0; i < 4; i++) { |
| 587 | if (!rates[i].count || rates[i].idx < 0) |
| 588 | break; |
| 589 | |
Rajkumar Manoharan | 1a6e9d0 | 2011-08-23 12:32:57 +0530 | [diff] [blame] | 590 | if (!(rates[i].flags & IEEE80211_TX_RC_MCS)) |
| 591 | return true; |
| 592 | } |
| 593 | |
| 594 | return false; |
| 595 | } |
| 596 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 597 | static u32 ath_lookup_rate(struct ath_softc *sc, struct ath_buf *bf, |
| 598 | struct ath_atx_tid *tid) |
| 599 | { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 600 | struct sk_buff *skb; |
| 601 | struct ieee80211_tx_info *tx_info; |
| 602 | struct ieee80211_tx_rate *rates; |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 603 | u32 max_4ms_framelen, frmlen; |
Sujith | 4ef7084 | 2009-07-23 15:32:41 +0530 | [diff] [blame] | 604 | u16 aggr_limit, legacy = 0; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 605 | int i; |
| 606 | |
Sujith | a22be22 | 2009-03-30 15:28:36 +0530 | [diff] [blame] | 607 | skb = bf->bf_mpdu; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 608 | tx_info = IEEE80211_SKB_CB(skb); |
| 609 | rates = tx_info->control.rates; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 610 | |
| 611 | /* |
| 612 | * Find the lowest frame length among the rate series that will have a |
| 613 | * 4ms transmit duration. |
| 614 | * TODO - TXOP limit needs to be considered. |
| 615 | */ |
| 616 | max_4ms_framelen = ATH_AMPDU_LIMIT_MAX; |
| 617 | |
| 618 | for (i = 0; i < 4; i++) { |
| 619 | if (rates[i].count) { |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 620 | int modeidx; |
| 621 | if (!(rates[i].flags & IEEE80211_TX_RC_MCS)) { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 622 | legacy = 1; |
| 623 | break; |
| 624 | } |
| 625 | |
Felix Fietkau | 0e668cd | 2010-04-19 19:57:32 +0200 | [diff] [blame] | 626 | if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 627 | modeidx = MCS_HT40; |
| 628 | else |
Felix Fietkau | 0e668cd | 2010-04-19 19:57:32 +0200 | [diff] [blame] | 629 | modeidx = MCS_HT20; |
| 630 | |
| 631 | if (rates[i].flags & IEEE80211_TX_RC_SHORT_GI) |
| 632 | modeidx++; |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 633 | |
| 634 | frmlen = ath_max_4ms_framelen[modeidx][rates[i].idx]; |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 635 | max_4ms_framelen = min(max_4ms_framelen, frmlen); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | |
| 639 | /* |
| 640 | * limit aggregate size by the minimum rate if rate selected is |
| 641 | * not a probe rate, if rate selected is a probe rate then |
| 642 | * avoid aggregation of this packet. |
| 643 | */ |
| 644 | if (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE || legacy) |
| 645 | return 0; |
| 646 | |
Vasanthakumar Thiagarajan | 1773912 | 2009-08-26 21:08:50 +0530 | [diff] [blame] | 647 | if (sc->sc_flags & SC_OP_BT_PRIORITY_DETECTED) |
| 648 | aggr_limit = min((max_4ms_framelen * 3) / 8, |
| 649 | (u32)ATH_AMPDU_LIMIT_MAX); |
| 650 | else |
| 651 | aggr_limit = min(max_4ms_framelen, |
| 652 | (u32)ATH_AMPDU_LIMIT_MAX); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 653 | |
| 654 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 655 | * h/w can accept aggregates up to 16 bit lengths (65535). |
| 656 | * The IE, however can hold up to 65536, which shows up here |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 657 | * as zero. Ignore 65536 since we are constrained by hw. |
| 658 | */ |
Sujith | 4ef7084 | 2009-07-23 15:32:41 +0530 | [diff] [blame] | 659 | if (tid->an->maxampdu) |
| 660 | aggr_limit = min(aggr_limit, tid->an->maxampdu); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 661 | |
| 662 | return aggr_limit; |
| 663 | } |
| 664 | |
| 665 | /* |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 666 | * Returns the number of delimiters to be added to |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 667 | * meet the minimum required mpdudensity. |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 668 | */ |
| 669 | static int ath_compute_num_delims(struct ath_softc *sc, struct ath_atx_tid *tid, |
Rajkumar Manoharan | 7a12dfd | 2011-08-13 10:28:08 +0530 | [diff] [blame] | 670 | struct ath_buf *bf, u16 frmlen, |
| 671 | bool first_subfrm) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 672 | { |
Rajkumar Manoharan | 7a12dfd | 2011-08-13 10:28:08 +0530 | [diff] [blame] | 673 | #define FIRST_DESC_NDELIMS 60 |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 674 | struct sk_buff *skb = bf->bf_mpdu; |
| 675 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
Sujith | 4ef7084 | 2009-07-23 15:32:41 +0530 | [diff] [blame] | 676 | u32 nsymbits, nsymbols; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 677 | u16 minlen; |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 678 | u8 flags, rix; |
Felix Fietkau | c666387 | 2010-04-19 19:57:33 +0200 | [diff] [blame] | 679 | int width, streams, half_gi, ndelim, mindelim; |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 680 | struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 681 | |
| 682 | /* Select standard number of delimiters based on frame length alone */ |
| 683 | ndelim = ATH_AGGR_GET_NDELIM(frmlen); |
| 684 | |
| 685 | /* |
| 686 | * If encryption enabled, hardware requires some more padding between |
| 687 | * subframes. |
| 688 | * TODO - this could be improved to be dependent on the rate. |
| 689 | * The hardware can keep up at lower rates, but not higher rates |
| 690 | */ |
Rajkumar Manoharan | 4f6760b | 2011-07-01 18:37:33 +0530 | [diff] [blame] | 691 | if ((fi->keyix != ATH9K_TXKEYIX_INVALID) && |
| 692 | !(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 693 | ndelim += ATH_AGGR_ENCRYPTDELIM; |
| 694 | |
| 695 | /* |
Rajkumar Manoharan | 7a12dfd | 2011-08-13 10:28:08 +0530 | [diff] [blame] | 696 | * Add delimiter when using RTS/CTS with aggregation |
| 697 | * and non enterprise AR9003 card |
| 698 | */ |
| 699 | if (first_subfrm) |
| 700 | ndelim = max(ndelim, FIRST_DESC_NDELIMS); |
| 701 | |
| 702 | /* |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 703 | * Convert desired mpdu density from microeconds to bytes based |
| 704 | * on highest rate in rate series (i.e. first rate) to determine |
| 705 | * required minimum length for subframe. Take into account |
| 706 | * whether high rate is 20 or 40Mhz and half or full GI. |
Sujith | 4ef7084 | 2009-07-23 15:32:41 +0530 | [diff] [blame] | 707 | * |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 708 | * If there is no mpdu density restriction, no further calculation |
| 709 | * is needed. |
| 710 | */ |
Sujith | 4ef7084 | 2009-07-23 15:32:41 +0530 | [diff] [blame] | 711 | |
| 712 | if (tid->an->mpdudensity == 0) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 713 | return ndelim; |
| 714 | |
| 715 | rix = tx_info->control.rates[0].idx; |
| 716 | flags = tx_info->control.rates[0].flags; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 717 | width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0; |
| 718 | half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0; |
| 719 | |
| 720 | if (half_gi) |
Sujith | 4ef7084 | 2009-07-23 15:32:41 +0530 | [diff] [blame] | 721 | nsymbols = NUM_SYMBOLS_PER_USEC_HALFGI(tid->an->mpdudensity); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 722 | else |
Sujith | 4ef7084 | 2009-07-23 15:32:41 +0530 | [diff] [blame] | 723 | nsymbols = NUM_SYMBOLS_PER_USEC(tid->an->mpdudensity); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 724 | |
| 725 | if (nsymbols == 0) |
| 726 | nsymbols = 1; |
| 727 | |
Felix Fietkau | c666387 | 2010-04-19 19:57:33 +0200 | [diff] [blame] | 728 | streams = HT_RC_2_STREAMS(rix); |
| 729 | nsymbits = bits_per_symbol[rix % 8][width] * streams; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 730 | minlen = (nsymbols * nsymbits) / BITS_PER_BYTE; |
| 731 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 732 | if (frmlen < minlen) { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 733 | mindelim = (minlen - frmlen) / ATH_AGGR_DELIM_SZ; |
| 734 | ndelim = max(mindelim, ndelim); |
| 735 | } |
| 736 | |
| 737 | return ndelim; |
| 738 | } |
| 739 | |
| 740 | static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc, |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 741 | struct ath_txq *txq, |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 742 | struct ath_atx_tid *tid, |
Felix Fietkau | 269c44b | 2010-11-14 15:20:06 +0100 | [diff] [blame] | 743 | struct list_head *bf_q, |
| 744 | int *aggr_len) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 745 | { |
| 746 | #define PADBYTES(_len) ((4 - ((_len) % 4)) % 4) |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 747 | struct ath_buf *bf, *bf_first = NULL, *bf_prev = NULL; |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 748 | int rl = 0, nframes = 0, ndelim, prev_al = 0; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 749 | u16 aggr_limit = 0, al = 0, bpad = 0, |
| 750 | al_delta, h_baw = tid->baw_size / 2; |
| 751 | enum ATH_AGGR_STATUS status = ATH_AGGR_DONE; |
Felix Fietkau | 0299a50 | 2010-10-21 02:47:24 +0200 | [diff] [blame] | 752 | struct ieee80211_tx_info *tx_info; |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 753 | struct ath_frame_info *fi; |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 754 | struct sk_buff *skb; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 755 | |
| 756 | do { |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 757 | skb = skb_peek(&tid->buf_q); |
| 758 | fi = get_frame_info(skb); |
| 759 | bf = fi->bf; |
| 760 | |
| 761 | if (!bf_first) |
| 762 | bf_first = bf; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 763 | |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 764 | /* do not step over block-ack window */ |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 765 | if (!BAW_WITHIN(tid->seq_start, tid->baw_size, fi->seqno)) { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 766 | status = ATH_AGGR_BAW_CLOSED; |
| 767 | break; |
| 768 | } |
| 769 | |
| 770 | if (!rl) { |
| 771 | aggr_limit = ath_lookup_rate(sc, bf, tid); |
| 772 | rl = 1; |
| 773 | } |
| 774 | |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 775 | /* do not exceed aggregation limit */ |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 776 | al_delta = ATH_AGGR_DELIM_SZ + fi->framelen; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 777 | |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 778 | if (nframes && |
Rajkumar Manoharan | 1a6e9d0 | 2011-08-23 12:32:57 +0530 | [diff] [blame] | 779 | ((aggr_limit < (al + bpad + al_delta + prev_al)) || |
| 780 | ath_lookup_legacy(bf))) { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 781 | status = ATH_AGGR_LIMITED; |
| 782 | break; |
| 783 | } |
| 784 | |
Felix Fietkau | 0299a50 | 2010-10-21 02:47:24 +0200 | [diff] [blame] | 785 | tx_info = IEEE80211_SKB_CB(bf->bf_mpdu); |
| 786 | if (nframes && ((tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) || |
| 787 | !(tx_info->control.rates[0].flags & IEEE80211_TX_RC_MCS))) |
| 788 | break; |
| 789 | |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 790 | /* do not exceed subframe limit */ |
| 791 | if (nframes >= min((int)h_baw, ATH_AMPDU_SUBFRAME_DEFAULT)) { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 792 | status = ATH_AGGR_LIMITED; |
| 793 | break; |
| 794 | } |
| 795 | |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 796 | /* add padding for previous frame to aggregation length */ |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 797 | al += bpad + al_delta; |
| 798 | |
| 799 | /* |
| 800 | * Get the delimiters needed to meet the MPDU |
| 801 | * density for this node. |
| 802 | */ |
Rajkumar Manoharan | 7a12dfd | 2011-08-13 10:28:08 +0530 | [diff] [blame] | 803 | ndelim = ath_compute_num_delims(sc, tid, bf_first, fi->framelen, |
| 804 | !nframes); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 805 | bpad = PADBYTES(al_delta) + (ndelim << 2); |
| 806 | |
Rajkumar Manoharan | 7a12dfd | 2011-08-13 10:28:08 +0530 | [diff] [blame] | 807 | nframes++; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 808 | bf->bf_next = NULL; |
Vasanthakumar Thiagarajan | 87d5efb | 2010-04-15 17:38:43 -0400 | [diff] [blame] | 809 | ath9k_hw_set_desc_link(sc->sc_ah, bf->bf_desc, 0); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 810 | |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 811 | /* link buffers of this frame to the aggregate */ |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 812 | if (!fi->retries) |
| 813 | ath_tx_addto_baw(sc, tid, fi->seqno); |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 814 | ath9k_hw_set11n_aggr_middle(sc->sc_ah, bf->bf_desc, ndelim); |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 815 | |
| 816 | __skb_unlink(skb, &tid->buf_q); |
| 817 | list_add_tail(&bf->list, bf_q); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 818 | if (bf_prev) { |
| 819 | bf_prev->bf_next = bf; |
Vasanthakumar Thiagarajan | 87d5efb | 2010-04-15 17:38:43 -0400 | [diff] [blame] | 820 | ath9k_hw_set_desc_link(sc->sc_ah, bf_prev->bf_desc, |
| 821 | bf->bf_daddr); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 822 | } |
| 823 | bf_prev = bf; |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 824 | |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 825 | } while (!skb_queue_empty(&tid->buf_q)); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 826 | |
Felix Fietkau | 269c44b | 2010-11-14 15:20:06 +0100 | [diff] [blame] | 827 | *aggr_len = al; |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 828 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 829 | return status; |
| 830 | #undef PADBYTES |
| 831 | } |
| 832 | |
| 833 | static void ath_tx_sched_aggr(struct ath_softc *sc, struct ath_txq *txq, |
| 834 | struct ath_atx_tid *tid) |
| 835 | { |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 836 | struct ath_buf *bf; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 837 | enum ATH_AGGR_STATUS status; |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 838 | struct ath_frame_info *fi; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 839 | struct list_head bf_q; |
Felix Fietkau | 269c44b | 2010-11-14 15:20:06 +0100 | [diff] [blame] | 840 | int aggr_len; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 841 | |
| 842 | do { |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 843 | if (skb_queue_empty(&tid->buf_q)) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 844 | return; |
| 845 | |
| 846 | INIT_LIST_HEAD(&bf_q); |
| 847 | |
Felix Fietkau | 269c44b | 2010-11-14 15:20:06 +0100 | [diff] [blame] | 848 | status = ath_tx_form_aggr(sc, txq, tid, &bf_q, &aggr_len); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 849 | |
| 850 | /* |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 851 | * no frames picked up to be aggregated; |
| 852 | * block-ack window is not open. |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 853 | */ |
| 854 | if (list_empty(&bf_q)) |
| 855 | break; |
| 856 | |
| 857 | bf = list_first_entry(&bf_q, struct ath_buf, list); |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 858 | bf->bf_lastbf = list_entry(bf_q.prev, struct ath_buf, list); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 859 | |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 860 | if (tid->ac->clear_ps_filter) { |
| 861 | tid->ac->clear_ps_filter = false; |
| 862 | ath9k_hw_set_clrdmask(sc->sc_ah, bf->bf_desc, true); |
| 863 | } |
| 864 | |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 865 | /* if only one frame, send as non-aggregate */ |
Felix Fietkau | b572d03 | 2010-11-14 15:20:07 +0100 | [diff] [blame] | 866 | if (bf == bf->bf_lastbf) { |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 867 | fi = get_frame_info(bf->bf_mpdu); |
| 868 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 869 | bf->bf_state.bf_type &= ~BUF_AGGR; |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 870 | ath9k_hw_clr11n_aggr(sc->sc_ah, bf->bf_desc); |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 871 | ath_buf_set_rate(sc, bf, fi->framelen); |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 872 | ath_tx_txqaddbuf(sc, txq, &bf_q, false); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 873 | continue; |
| 874 | } |
| 875 | |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 876 | /* setup first desc of aggregate */ |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 877 | bf->bf_state.bf_type |= BUF_AGGR; |
Felix Fietkau | 269c44b | 2010-11-14 15:20:06 +0100 | [diff] [blame] | 878 | ath_buf_set_rate(sc, bf, aggr_len); |
| 879 | ath9k_hw_set11n_aggr_first(sc->sc_ah, bf->bf_desc, aggr_len); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 880 | |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 881 | /* anchor last desc of aggregate */ |
| 882 | ath9k_hw_set11n_aggr_last(sc->sc_ah, bf->bf_lastbf->bf_desc); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 883 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 884 | ath_tx_txqaddbuf(sc, txq, &bf_q, false); |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 885 | TX_STAT_INC(txq->axq_qnum, a_aggr); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 886 | |
Felix Fietkau | 4b3ba66 | 2010-12-17 00:57:00 +0100 | [diff] [blame] | 887 | } while (txq->axq_ampdu_depth < ATH_AGGR_MIN_QDEPTH && |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 888 | status != ATH_AGGR_BAW_CLOSED); |
| 889 | } |
| 890 | |
Felix Fietkau | 231c3a1 | 2010-09-20 19:35:28 +0200 | [diff] [blame] | 891 | int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta, |
| 892 | u16 tid, u16 *ssn) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 893 | { |
| 894 | struct ath_atx_tid *txtid; |
| 895 | struct ath_node *an; |
| 896 | |
| 897 | an = (struct ath_node *)sta->drv_priv; |
Sujith | f83da96 | 2009-07-23 15:32:37 +0530 | [diff] [blame] | 898 | txtid = ATH_AN_2_TID(an, tid); |
Felix Fietkau | 231c3a1 | 2010-09-20 19:35:28 +0200 | [diff] [blame] | 899 | |
| 900 | if (txtid->state & (AGGR_CLEANUP | AGGR_ADDBA_COMPLETE)) |
| 901 | return -EAGAIN; |
| 902 | |
Sujith | f83da96 | 2009-07-23 15:32:37 +0530 | [diff] [blame] | 903 | txtid->state |= AGGR_ADDBA_PROGRESS; |
Lorenzo Bianconi | 7540184 | 2010-08-01 15:47:32 +0200 | [diff] [blame] | 904 | txtid->paused = true; |
Felix Fietkau | 49447f2 | 2011-01-10 17:05:48 -0700 | [diff] [blame] | 905 | *ssn = txtid->seq_start = txtid->seq_next; |
Felix Fietkau | 231c3a1 | 2010-09-20 19:35:28 +0200 | [diff] [blame] | 906 | |
Felix Fietkau | 2ed7222 | 2011-01-10 17:05:49 -0700 | [diff] [blame] | 907 | memset(txtid->tx_buf, 0, sizeof(txtid->tx_buf)); |
| 908 | txtid->baw_head = txtid->baw_tail = 0; |
| 909 | |
Felix Fietkau | 231c3a1 | 2010-09-20 19:35:28 +0200 | [diff] [blame] | 910 | return 0; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 911 | } |
| 912 | |
Sujith | f83da96 | 2009-07-23 15:32:37 +0530 | [diff] [blame] | 913 | void ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 914 | { |
| 915 | struct ath_node *an = (struct ath_node *)sta->drv_priv; |
| 916 | struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid); |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 917 | struct ath_txq *txq = txtid->ac->txq; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 918 | |
| 919 | if (txtid->state & AGGR_CLEANUP) |
Sujith | f83da96 | 2009-07-23 15:32:37 +0530 | [diff] [blame] | 920 | return; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 921 | |
| 922 | if (!(txtid->state & AGGR_ADDBA_COMPLETE)) { |
Vasanthakumar Thiagarajan | 5eae659 | 2009-06-09 15:28:21 +0530 | [diff] [blame] | 923 | txtid->state &= ~AGGR_ADDBA_PROGRESS; |
Sujith | f83da96 | 2009-07-23 15:32:37 +0530 | [diff] [blame] | 924 | return; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 925 | } |
| 926 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 927 | spin_lock_bh(&txq->axq_lock); |
Lorenzo Bianconi | 7540184 | 2010-08-01 15:47:32 +0200 | [diff] [blame] | 928 | txtid->paused = true; |
Felix Fietkau | 90fa539 | 2010-09-20 13:45:38 +0200 | [diff] [blame] | 929 | |
| 930 | /* |
| 931 | * If frames are still being transmitted for this TID, they will be |
| 932 | * cleaned up during tx completion. To prevent race conditions, this |
| 933 | * TID can only be reused after all in-progress subframes have been |
| 934 | * completed. |
| 935 | */ |
| 936 | if (txtid->baw_head != txtid->baw_tail) |
| 937 | txtid->state |= AGGR_CLEANUP; |
| 938 | else |
| 939 | txtid->state &= ~AGGR_ADDBA_COMPLETE; |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 940 | spin_unlock_bh(&txq->axq_lock); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 941 | |
Felix Fietkau | 90fa539 | 2010-09-20 13:45:38 +0200 | [diff] [blame] | 942 | ath_tx_flush_tid(sc, txtid); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 943 | } |
| 944 | |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 945 | bool ath_tx_aggr_sleep(struct ath_softc *sc, struct ath_node *an) |
| 946 | { |
| 947 | struct ath_atx_tid *tid; |
| 948 | struct ath_atx_ac *ac; |
| 949 | struct ath_txq *txq; |
| 950 | bool buffered = false; |
| 951 | int tidno; |
| 952 | |
| 953 | for (tidno = 0, tid = &an->tid[tidno]; |
| 954 | tidno < WME_NUM_TID; tidno++, tid++) { |
| 955 | |
| 956 | if (!tid->sched) |
| 957 | continue; |
| 958 | |
| 959 | ac = tid->ac; |
| 960 | txq = ac->txq; |
| 961 | |
| 962 | spin_lock_bh(&txq->axq_lock); |
| 963 | |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 964 | if (!skb_queue_empty(&tid->buf_q)) |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 965 | buffered = true; |
| 966 | |
| 967 | tid->sched = false; |
| 968 | list_del(&tid->list); |
| 969 | |
| 970 | if (ac->sched) { |
| 971 | ac->sched = false; |
| 972 | list_del(&ac->list); |
| 973 | } |
| 974 | |
| 975 | spin_unlock_bh(&txq->axq_lock); |
| 976 | } |
| 977 | |
| 978 | return buffered; |
| 979 | } |
| 980 | |
| 981 | void ath_tx_aggr_wakeup(struct ath_softc *sc, struct ath_node *an) |
| 982 | { |
| 983 | struct ath_atx_tid *tid; |
| 984 | struct ath_atx_ac *ac; |
| 985 | struct ath_txq *txq; |
| 986 | int tidno; |
| 987 | |
| 988 | for (tidno = 0, tid = &an->tid[tidno]; |
| 989 | tidno < WME_NUM_TID; tidno++, tid++) { |
| 990 | |
| 991 | ac = tid->ac; |
| 992 | txq = ac->txq; |
| 993 | |
| 994 | spin_lock_bh(&txq->axq_lock); |
| 995 | ac->clear_ps_filter = true; |
| 996 | |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 997 | if (!skb_queue_empty(&tid->buf_q) && !tid->paused) { |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 998 | ath_tx_queue_tid(txq, tid); |
| 999 | ath_txq_schedule(sc, txq); |
| 1000 | } |
| 1001 | |
| 1002 | spin_unlock_bh(&txq->axq_lock); |
| 1003 | } |
| 1004 | } |
| 1005 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1006 | void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid) |
| 1007 | { |
| 1008 | struct ath_atx_tid *txtid; |
| 1009 | struct ath_node *an; |
| 1010 | |
| 1011 | an = (struct ath_node *)sta->drv_priv; |
| 1012 | |
| 1013 | if (sc->sc_flags & SC_OP_TXAGGR) { |
| 1014 | txtid = ATH_AN_2_TID(an, tid); |
| 1015 | txtid->baw_size = |
| 1016 | IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor; |
| 1017 | txtid->state |= AGGR_ADDBA_COMPLETE; |
| 1018 | txtid->state &= ~AGGR_ADDBA_PROGRESS; |
| 1019 | ath_tx_resume_tid(sc, txtid); |
| 1020 | } |
| 1021 | } |
| 1022 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1023 | /********************/ |
| 1024 | /* Queue Management */ |
| 1025 | /********************/ |
| 1026 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1027 | static void ath_txq_drain_pending_buffers(struct ath_softc *sc, |
| 1028 | struct ath_txq *txq) |
| 1029 | { |
| 1030 | struct ath_atx_ac *ac, *ac_tmp; |
| 1031 | struct ath_atx_tid *tid, *tid_tmp; |
| 1032 | |
| 1033 | list_for_each_entry_safe(ac, ac_tmp, &txq->axq_acq, list) { |
| 1034 | list_del(&ac->list); |
| 1035 | ac->sched = false; |
| 1036 | list_for_each_entry_safe(tid, tid_tmp, &ac->tid_q, list) { |
| 1037 | list_del(&tid->list); |
| 1038 | tid->sched = false; |
| 1039 | ath_tid_drain(sc, txq, tid); |
| 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype) |
| 1045 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1046 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1047 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1048 | struct ath9k_tx_queue_info qi; |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 1049 | static const int subtype_txq_to_hwq[] = { |
| 1050 | [WME_AC_BE] = ATH_TXQ_AC_BE, |
| 1051 | [WME_AC_BK] = ATH_TXQ_AC_BK, |
| 1052 | [WME_AC_VI] = ATH_TXQ_AC_VI, |
| 1053 | [WME_AC_VO] = ATH_TXQ_AC_VO, |
| 1054 | }; |
Ben Greear | 60f2d1d | 2011-01-09 23:11:52 -0800 | [diff] [blame] | 1055 | int axq_qnum, i; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1056 | |
| 1057 | memset(&qi, 0, sizeof(qi)); |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 1058 | qi.tqi_subtype = subtype_txq_to_hwq[subtype]; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1059 | qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT; |
| 1060 | qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT; |
| 1061 | qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT; |
| 1062 | qi.tqi_physCompBuf = 0; |
| 1063 | |
| 1064 | /* |
| 1065 | * Enable interrupts only for EOL and DESC conditions. |
| 1066 | * We mark tx descriptors to receive a DESC interrupt |
| 1067 | * when a tx queue gets deep; otherwise waiting for the |
| 1068 | * EOL to reap descriptors. Note that this is done to |
| 1069 | * reduce interrupt load and this only defers reaping |
| 1070 | * descriptors, never transmitting frames. Aside from |
| 1071 | * reducing interrupts this also permits more concurrency. |
| 1072 | * The only potential downside is if the tx queue backs |
| 1073 | * up in which case the top half of the kernel may backup |
| 1074 | * due to a lack of tx descriptors. |
| 1075 | * |
| 1076 | * The UAPSD queue is an exception, since we take a desc- |
| 1077 | * based intr on the EOSP frames. |
| 1078 | */ |
Vasanthakumar Thiagarajan | afe754d | 2010-04-15 17:39:40 -0400 | [diff] [blame] | 1079 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 1080 | qi.tqi_qflags = TXQ_FLAG_TXOKINT_ENABLE | |
| 1081 | TXQ_FLAG_TXERRINT_ENABLE; |
| 1082 | } else { |
| 1083 | if (qtype == ATH9K_TX_QUEUE_UAPSD) |
| 1084 | qi.tqi_qflags = TXQ_FLAG_TXDESCINT_ENABLE; |
| 1085 | else |
| 1086 | qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE | |
| 1087 | TXQ_FLAG_TXDESCINT_ENABLE; |
| 1088 | } |
Ben Greear | 60f2d1d | 2011-01-09 23:11:52 -0800 | [diff] [blame] | 1089 | axq_qnum = ath9k_hw_setuptxqueue(ah, qtype, &qi); |
| 1090 | if (axq_qnum == -1) { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1091 | /* |
| 1092 | * NB: don't print a message, this happens |
| 1093 | * normally on parts with too few tx queues |
| 1094 | */ |
| 1095 | return NULL; |
| 1096 | } |
Ben Greear | 60f2d1d | 2011-01-09 23:11:52 -0800 | [diff] [blame] | 1097 | if (axq_qnum >= ARRAY_SIZE(sc->tx.txq)) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1098 | ath_err(common, "qnum %u out of range, max %zu!\n", |
Ben Greear | 60f2d1d | 2011-01-09 23:11:52 -0800 | [diff] [blame] | 1099 | axq_qnum, ARRAY_SIZE(sc->tx.txq)); |
| 1100 | ath9k_hw_releasetxqueue(ah, axq_qnum); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1101 | return NULL; |
| 1102 | } |
Ben Greear | 60f2d1d | 2011-01-09 23:11:52 -0800 | [diff] [blame] | 1103 | if (!ATH_TXQ_SETUP(sc, axq_qnum)) { |
| 1104 | struct ath_txq *txq = &sc->tx.txq[axq_qnum]; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1105 | |
Ben Greear | 60f2d1d | 2011-01-09 23:11:52 -0800 | [diff] [blame] | 1106 | txq->axq_qnum = axq_qnum; |
| 1107 | txq->mac80211_qnum = -1; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1108 | txq->axq_link = NULL; |
| 1109 | INIT_LIST_HEAD(&txq->axq_q); |
| 1110 | INIT_LIST_HEAD(&txq->axq_acq); |
| 1111 | spin_lock_init(&txq->axq_lock); |
| 1112 | txq->axq_depth = 0; |
Felix Fietkau | 4b3ba66 | 2010-12-17 00:57:00 +0100 | [diff] [blame] | 1113 | txq->axq_ampdu_depth = 0; |
Senthil Balasubramanian | 164ace3 | 2009-07-14 20:17:09 -0400 | [diff] [blame] | 1114 | txq->axq_tx_inprogress = false; |
Ben Greear | 60f2d1d | 2011-01-09 23:11:52 -0800 | [diff] [blame] | 1115 | sc->tx.txqsetup |= 1<<axq_qnum; |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 1116 | |
| 1117 | txq->txq_headidx = txq->txq_tailidx = 0; |
| 1118 | for (i = 0; i < ATH_TXFIFO_DEPTH; i++) |
| 1119 | INIT_LIST_HEAD(&txq->txq_fifo[i]); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1120 | } |
Ben Greear | 60f2d1d | 2011-01-09 23:11:52 -0800 | [diff] [blame] | 1121 | return &sc->tx.txq[axq_qnum]; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1122 | } |
| 1123 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1124 | int ath_txq_update(struct ath_softc *sc, int qnum, |
| 1125 | struct ath9k_tx_queue_info *qinfo) |
| 1126 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1127 | struct ath_hw *ah = sc->sc_ah; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1128 | int error = 0; |
| 1129 | struct ath9k_tx_queue_info qi; |
| 1130 | |
| 1131 | if (qnum == sc->beacon.beaconq) { |
| 1132 | /* |
| 1133 | * XXX: for beacon queue, we just save the parameter. |
| 1134 | * It will be picked up by ath_beaconq_config when |
| 1135 | * it's necessary. |
| 1136 | */ |
| 1137 | sc->beacon.beacon_qi = *qinfo; |
| 1138 | return 0; |
| 1139 | } |
| 1140 | |
Luis R. Rodriguez | 9680e8a | 2009-09-13 23:28:00 -0700 | [diff] [blame] | 1141 | BUG_ON(sc->tx.txq[qnum].axq_qnum != qnum); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1142 | |
| 1143 | ath9k_hw_get_txq_props(ah, qnum, &qi); |
| 1144 | qi.tqi_aifs = qinfo->tqi_aifs; |
| 1145 | qi.tqi_cwmin = qinfo->tqi_cwmin; |
| 1146 | qi.tqi_cwmax = qinfo->tqi_cwmax; |
| 1147 | qi.tqi_burstTime = qinfo->tqi_burstTime; |
| 1148 | qi.tqi_readyTime = qinfo->tqi_readyTime; |
| 1149 | |
| 1150 | if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1151 | ath_err(ath9k_hw_common(sc->sc_ah), |
| 1152 | "Unable to update hardware queue %u!\n", qnum); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1153 | error = -EIO; |
| 1154 | } else { |
| 1155 | ath9k_hw_resettxqueue(ah, qnum); |
| 1156 | } |
| 1157 | |
| 1158 | return error; |
| 1159 | } |
| 1160 | |
| 1161 | int ath_cabq_update(struct ath_softc *sc) |
| 1162 | { |
| 1163 | struct ath9k_tx_queue_info qi; |
Steve Brown | 9814f6b | 2011-02-07 17:10:39 -0700 | [diff] [blame] | 1164 | struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1165 | int qnum = sc->beacon.cabq->axq_qnum; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1166 | |
| 1167 | ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi); |
| 1168 | /* |
| 1169 | * Ensure the readytime % is within the bounds. |
| 1170 | */ |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 1171 | if (sc->config.cabqReadytime < ATH9K_READY_TIME_LO_BOUND) |
| 1172 | sc->config.cabqReadytime = ATH9K_READY_TIME_LO_BOUND; |
| 1173 | else if (sc->config.cabqReadytime > ATH9K_READY_TIME_HI_BOUND) |
| 1174 | sc->config.cabqReadytime = ATH9K_READY_TIME_HI_BOUND; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1175 | |
Steve Brown | 9814f6b | 2011-02-07 17:10:39 -0700 | [diff] [blame] | 1176 | qi.tqi_readyTime = (cur_conf->beacon_interval * |
Sujith | fdbf733 | 2009-02-17 15:36:35 +0530 | [diff] [blame] | 1177 | sc->config.cabqReadytime) / 100; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1178 | ath_txq_update(sc, qnum, &qi); |
| 1179 | |
| 1180 | return 0; |
| 1181 | } |
| 1182 | |
Felix Fietkau | 4b3ba66 | 2010-12-17 00:57:00 +0100 | [diff] [blame] | 1183 | static bool bf_is_ampdu_not_probing(struct ath_buf *bf) |
| 1184 | { |
| 1185 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(bf->bf_mpdu); |
| 1186 | return bf_isampdu(bf) && !(info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE); |
| 1187 | } |
| 1188 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1189 | static void ath_drain_txq_list(struct ath_softc *sc, struct ath_txq *txq, |
| 1190 | struct list_head *list, bool retry_tx) |
Rajkumar Manoharan | 5479de6 | 2011-07-17 11:43:02 +0530 | [diff] [blame] | 1191 | __releases(txq->axq_lock) |
| 1192 | __acquires(txq->axq_lock) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1193 | { |
| 1194 | struct ath_buf *bf, *lastbf; |
| 1195 | struct list_head bf_head; |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 1196 | struct ath_tx_status ts; |
| 1197 | |
| 1198 | memset(&ts, 0, sizeof(ts)); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1199 | INIT_LIST_HEAD(&bf_head); |
| 1200 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1201 | while (!list_empty(list)) { |
| 1202 | bf = list_first_entry(list, struct ath_buf, list); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1203 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1204 | if (bf->bf_stale) { |
| 1205 | list_del(&bf->list); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1206 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1207 | ath_tx_return_buffer(sc, bf); |
| 1208 | continue; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | lastbf = bf->bf_lastbf; |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1212 | list_cut_position(&bf_head, list, &lastbf->list); |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 1213 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1214 | txq->axq_depth--; |
Felix Fietkau | 4b3ba66 | 2010-12-17 00:57:00 +0100 | [diff] [blame] | 1215 | if (bf_is_ampdu_not_probing(bf)) |
| 1216 | txq->axq_ampdu_depth--; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1217 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1218 | spin_unlock_bh(&txq->axq_lock); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1219 | if (bf_isampdu(bf)) |
Felix Fietkau | c599261 | 2010-11-14 15:20:09 +0100 | [diff] [blame] | 1220 | ath_tx_complete_aggr(sc, txq, bf, &bf_head, &ts, 0, |
| 1221 | retry_tx); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1222 | else |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 1223 | ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0, 0); |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 1224 | spin_lock_bh(&txq->axq_lock); |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 1225 | } |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | /* |
| 1229 | * Drain a given TX queue (could be Beacon or Data) |
| 1230 | * |
| 1231 | * This assumes output has been stopped and |
| 1232 | * we do not need to block ath_tx_tasklet. |
| 1233 | */ |
| 1234 | void ath_draintxq(struct ath_softc *sc, struct ath_txq *txq, bool retry_tx) |
| 1235 | { |
| 1236 | spin_lock_bh(&txq->axq_lock); |
| 1237 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 1238 | int idx = txq->txq_tailidx; |
| 1239 | |
| 1240 | while (!list_empty(&txq->txq_fifo[idx])) { |
| 1241 | ath_drain_txq_list(sc, txq, &txq->txq_fifo[idx], |
| 1242 | retry_tx); |
| 1243 | |
| 1244 | INCR(idx, ATH_TXFIFO_DEPTH); |
| 1245 | } |
| 1246 | txq->txq_tailidx = idx; |
| 1247 | } |
| 1248 | |
| 1249 | txq->axq_link = NULL; |
| 1250 | txq->axq_tx_inprogress = false; |
| 1251 | ath_drain_txq_list(sc, txq, &txq->axq_q, retry_tx); |
Felix Fietkau | e609e2e | 2010-10-27 02:15:05 +0200 | [diff] [blame] | 1252 | |
| 1253 | /* flush any pending frames if aggregation is enabled */ |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1254 | if ((sc->sc_flags & SC_OP_TXAGGR) && !retry_tx) |
| 1255 | ath_txq_drain_pending_buffers(sc, txq); |
| 1256 | |
| 1257 | spin_unlock_bh(&txq->axq_lock); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1258 | } |
| 1259 | |
Felix Fietkau | 080e1a2 | 2010-12-05 20:17:53 +0100 | [diff] [blame] | 1260 | bool ath_drain_all_txq(struct ath_softc *sc, bool retry_tx) |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 1261 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1262 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1263 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 1264 | struct ath_txq *txq; |
| 1265 | int i, npend = 0; |
| 1266 | |
| 1267 | if (sc->sc_flags & SC_OP_INVALID) |
Felix Fietkau | 080e1a2 | 2010-12-05 20:17:53 +0100 | [diff] [blame] | 1268 | return true; |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 1269 | |
Felix Fietkau | 0d51ccc | 2011-03-11 21:38:18 +0100 | [diff] [blame] | 1270 | ath9k_hw_abort_tx_dma(ah); |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 1271 | |
Felix Fietkau | 0d51ccc | 2011-03-11 21:38:18 +0100 | [diff] [blame] | 1272 | /* Check if any queue remains active */ |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 1273 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { |
Felix Fietkau | 0d51ccc | 2011-03-11 21:38:18 +0100 | [diff] [blame] | 1274 | if (!ATH_TXQ_SETUP(sc, i)) |
| 1275 | continue; |
| 1276 | |
| 1277 | npend += ath9k_hw_numtxpending(ah, sc->tx.txq[i].axq_qnum); |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 1278 | } |
| 1279 | |
Felix Fietkau | 080e1a2 | 2010-12-05 20:17:53 +0100 | [diff] [blame] | 1280 | if (npend) |
John W. Linville | 393934c | 2010-12-08 16:23:31 -0500 | [diff] [blame] | 1281 | ath_err(common, "Failed to stop TX DMA!\n"); |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 1282 | |
| 1283 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { |
Felix Fietkau | 9246041 | 2011-01-24 19:23:14 +0100 | [diff] [blame] | 1284 | if (!ATH_TXQ_SETUP(sc, i)) |
| 1285 | continue; |
| 1286 | |
| 1287 | /* |
| 1288 | * The caller will resume queues with ieee80211_wake_queues. |
| 1289 | * Mark the queue as not stopped to prevent ath_tx_complete |
| 1290 | * from waking the queue too early. |
| 1291 | */ |
| 1292 | txq = &sc->tx.txq[i]; |
| 1293 | txq->stopped = false; |
| 1294 | ath_draintxq(sc, txq, retry_tx); |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 1295 | } |
Felix Fietkau | 080e1a2 | 2010-12-05 20:17:53 +0100 | [diff] [blame] | 1296 | |
| 1297 | return !npend; |
Sujith | 043a040 | 2009-01-16 21:38:47 +0530 | [diff] [blame] | 1298 | } |
| 1299 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1300 | void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq) |
| 1301 | { |
| 1302 | ath9k_hw_releasetxqueue(sc->sc_ah, txq->axq_qnum); |
| 1303 | sc->tx.txqsetup &= ~(1<<txq->axq_qnum); |
| 1304 | } |
| 1305 | |
Ben Greear | 7755bad | 2011-01-18 17:30:00 -0800 | [diff] [blame] | 1306 | /* For each axq_acq entry, for each tid, try to schedule packets |
| 1307 | * for transmit until ampdu_depth has reached min Q depth. |
| 1308 | */ |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1309 | void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq) |
| 1310 | { |
Ben Greear | 7755bad | 2011-01-18 17:30:00 -0800 | [diff] [blame] | 1311 | struct ath_atx_ac *ac, *ac_tmp, *last_ac; |
| 1312 | struct ath_atx_tid *tid, *last_tid; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1313 | |
Felix Fietkau | 21f28e6 | 2011-01-15 14:30:14 +0100 | [diff] [blame] | 1314 | if (list_empty(&txq->axq_acq) || |
| 1315 | txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1316 | return; |
| 1317 | |
| 1318 | ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac, list); |
Ben Greear | 7755bad | 2011-01-18 17:30:00 -0800 | [diff] [blame] | 1319 | last_ac = list_entry(txq->axq_acq.prev, struct ath_atx_ac, list); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1320 | |
Ben Greear | 7755bad | 2011-01-18 17:30:00 -0800 | [diff] [blame] | 1321 | list_for_each_entry_safe(ac, ac_tmp, &txq->axq_acq, list) { |
| 1322 | last_tid = list_entry(ac->tid_q.prev, struct ath_atx_tid, list); |
| 1323 | list_del(&ac->list); |
| 1324 | ac->sched = false; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1325 | |
Ben Greear | 7755bad | 2011-01-18 17:30:00 -0800 | [diff] [blame] | 1326 | while (!list_empty(&ac->tid_q)) { |
| 1327 | tid = list_first_entry(&ac->tid_q, struct ath_atx_tid, |
| 1328 | list); |
| 1329 | list_del(&tid->list); |
| 1330 | tid->sched = false; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1331 | |
Ben Greear | 7755bad | 2011-01-18 17:30:00 -0800 | [diff] [blame] | 1332 | if (tid->paused) |
| 1333 | continue; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1334 | |
Ben Greear | 7755bad | 2011-01-18 17:30:00 -0800 | [diff] [blame] | 1335 | ath_tx_sched_aggr(sc, txq, tid); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1336 | |
Ben Greear | 7755bad | 2011-01-18 17:30:00 -0800 | [diff] [blame] | 1337 | /* |
| 1338 | * add tid to round-robin queue if more frames |
| 1339 | * are pending for the tid |
| 1340 | */ |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 1341 | if (!skb_queue_empty(&tid->buf_q)) |
Ben Greear | 7755bad | 2011-01-18 17:30:00 -0800 | [diff] [blame] | 1342 | ath_tx_queue_tid(txq, tid); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1343 | |
Ben Greear | 7755bad | 2011-01-18 17:30:00 -0800 | [diff] [blame] | 1344 | if (tid == last_tid || |
| 1345 | txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) |
| 1346 | break; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1347 | } |
Ben Greear | 7755bad | 2011-01-18 17:30:00 -0800 | [diff] [blame] | 1348 | |
| 1349 | if (!list_empty(&ac->tid_q)) { |
| 1350 | if (!ac->sched) { |
| 1351 | ac->sched = true; |
| 1352 | list_add_tail(&ac->list, &txq->axq_acq); |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | if (ac == last_ac || |
| 1357 | txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) |
| 1358 | return; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1359 | } |
| 1360 | } |
| 1361 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1362 | /***********/ |
| 1363 | /* TX, DMA */ |
| 1364 | /***********/ |
| 1365 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1366 | /* |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1367 | * Insert a chain of ath_buf (descriptors) on a txq and |
| 1368 | * assume the descriptors are already chained together by caller. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1369 | */ |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 1370 | static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq, |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1371 | struct list_head *head, bool internal) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1372 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1373 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1374 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1375 | struct ath_buf *bf, *bf_last; |
| 1376 | bool puttxbuf = false; |
| 1377 | bool edma; |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 1378 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1379 | /* |
| 1380 | * Insert the frame on the outbound list and |
| 1381 | * pass it on to the hardware. |
| 1382 | */ |
| 1383 | |
| 1384 | if (list_empty(head)) |
| 1385 | return; |
| 1386 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1387 | edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1388 | bf = list_first_entry(head, struct ath_buf, list); |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1389 | bf_last = list_entry(head->prev, struct ath_buf, list); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1390 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1391 | ath_dbg(common, ATH_DBG_QUEUE, |
| 1392 | "qnum: %d, txq depth: %d\n", txq->axq_qnum, txq->axq_depth); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1393 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1394 | if (edma && list_empty(&txq->txq_fifo[txq->txq_headidx])) { |
| 1395 | list_splice_tail_init(head, &txq->txq_fifo[txq->txq_headidx]); |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 1396 | INCR(txq->txq_headidx, ATH_TXFIFO_DEPTH); |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1397 | puttxbuf = true; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1398 | } else { |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 1399 | list_splice_tail_init(head, &txq->axq_q); |
| 1400 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1401 | if (txq->axq_link) { |
| 1402 | ath9k_hw_set_desc_link(ah, txq->axq_link, bf->bf_daddr); |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1403 | ath_dbg(common, ATH_DBG_XMIT, |
| 1404 | "link[%u] (%p)=%llx (%p)\n", |
| 1405 | txq->axq_qnum, txq->axq_link, |
| 1406 | ito64(bf->bf_daddr), bf->bf_desc); |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1407 | } else if (!edma) |
| 1408 | puttxbuf = true; |
| 1409 | |
| 1410 | txq->axq_link = bf_last->bf_desc; |
| 1411 | } |
| 1412 | |
| 1413 | if (puttxbuf) { |
| 1414 | TX_STAT_INC(txq->axq_qnum, puttxbuf); |
| 1415 | ath9k_hw_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr); |
| 1416 | ath_dbg(common, ATH_DBG_XMIT, "TXDP[%u] = %llx (%p)\n", |
| 1417 | txq->axq_qnum, ito64(bf->bf_daddr), bf->bf_desc); |
| 1418 | } |
| 1419 | |
| 1420 | if (!edma) { |
Felix Fietkau | 8d8d3fd | 2011-01-24 19:11:54 +0100 | [diff] [blame] | 1421 | TX_STAT_INC(txq->axq_qnum, txstart); |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 1422 | ath9k_hw_txstart(ah, txq->axq_qnum); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1423 | } |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1424 | |
| 1425 | if (!internal) { |
| 1426 | txq->axq_depth++; |
| 1427 | if (bf_is_ampdu_not_probing(bf)) |
| 1428 | txq->axq_ampdu_depth++; |
| 1429 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1432 | static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_atx_tid *tid, |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1433 | struct ath_buf *bf, struct ath_tx_control *txctl) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1434 | { |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1435 | struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu); |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1436 | struct list_head bf_head; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1437 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1438 | bf->bf_state.bf_type |= BUF_AMPDU; |
| 1439 | |
| 1440 | /* |
| 1441 | * Do not queue to h/w when any of the following conditions is true: |
| 1442 | * - there are pending frames in software queue |
| 1443 | * - the TID is currently paused for ADDBA/BAR request |
| 1444 | * - seqno is not within block-ack window |
| 1445 | * - h/w queue depth exceeds low water mark |
| 1446 | */ |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 1447 | if (!skb_queue_empty(&tid->buf_q) || tid->paused || |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1448 | !BAW_WITHIN(tid->seq_start, tid->baw_size, fi->seqno) || |
Felix Fietkau | 4b3ba66 | 2010-12-17 00:57:00 +0100 | [diff] [blame] | 1449 | txctl->txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) { |
Jouni Malinen | f7a276a | 2008-12-15 16:02:04 +0200 | [diff] [blame] | 1450 | /* |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1451 | * Add this frame to software queue for scheduling later |
| 1452 | * for aggregation. |
Jouni Malinen | f7a276a | 2008-12-15 16:02:04 +0200 | [diff] [blame] | 1453 | */ |
Ben Greear | bda8add | 2011-01-09 23:11:48 -0800 | [diff] [blame] | 1454 | TX_STAT_INC(txctl->txq->axq_qnum, a_queued_sw); |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 1455 | __skb_queue_tail(&tid->buf_q, bf->bf_mpdu); |
Felix Fietkau | 9af73cf | 2011-08-10 15:23:35 -0600 | [diff] [blame] | 1456 | if (!txctl->an || !txctl->an->sleeping) |
| 1457 | ath_tx_queue_tid(txctl->txq, tid); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1458 | return; |
Jouni Malinen | f7a276a | 2008-12-15 16:02:04 +0200 | [diff] [blame] | 1459 | } |
| 1460 | |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1461 | INIT_LIST_HEAD(&bf_head); |
| 1462 | list_add(&bf->list, &bf_head); |
| 1463 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1464 | /* Add sub-frame to BAW */ |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1465 | if (!fi->retries) |
| 1466 | ath_tx_addto_baw(sc, tid, fi->seqno); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1467 | |
| 1468 | /* Queue to h/w without aggregation */ |
Ben Greear | bda8add | 2011-01-09 23:11:48 -0800 | [diff] [blame] | 1469 | TX_STAT_INC(txctl->txq->axq_qnum, a_queued_hw); |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 1470 | bf->bf_lastbf = bf; |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1471 | ath_buf_set_rate(sc, bf, fi->framelen); |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1472 | ath_tx_txqaddbuf(sc, txctl->txq, &bf_head, false); |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 1473 | } |
| 1474 | |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 1475 | static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq, |
| 1476 | struct ath_atx_tid *tid, |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1477 | struct list_head *bf_head) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1478 | { |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1479 | struct ath_frame_info *fi; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1480 | struct ath_buf *bf; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1481 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1482 | bf = list_first_entry(bf_head, struct ath_buf, list); |
| 1483 | bf->bf_state.bf_type &= ~BUF_AMPDU; |
| 1484 | |
| 1485 | /* update starting sequence number for subsequent ADDBA request */ |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 1486 | if (tid) |
| 1487 | INCR(tid->seq_start, IEEE80211_SEQ_MAX); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1488 | |
Sujith | d43f3015 | 2009-01-16 21:38:53 +0530 | [diff] [blame] | 1489 | bf->bf_lastbf = bf; |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1490 | fi = get_frame_info(bf->bf_mpdu); |
| 1491 | ath_buf_set_rate(sc, bf, fi->framelen); |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 1492 | ath_tx_txqaddbuf(sc, txq, bf_head, false); |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 1493 | TX_STAT_INC(txq->axq_qnum, queued); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1496 | static enum ath9k_pkt_type get_hw_packet_type(struct sk_buff *skb) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1497 | { |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1498 | struct ieee80211_hdr *hdr; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1499 | enum ath9k_pkt_type htype; |
| 1500 | __le16 fc; |
| 1501 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1502 | hdr = (struct ieee80211_hdr *)skb->data; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1503 | fc = hdr->frame_control; |
| 1504 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1505 | if (ieee80211_is_beacon(fc)) |
| 1506 | htype = ATH9K_PKT_TYPE_BEACON; |
| 1507 | else if (ieee80211_is_probe_resp(fc)) |
| 1508 | htype = ATH9K_PKT_TYPE_PROBE_RESP; |
| 1509 | else if (ieee80211_is_atim(fc)) |
| 1510 | htype = ATH9K_PKT_TYPE_ATIM; |
| 1511 | else if (ieee80211_is_pspoll(fc)) |
| 1512 | htype = ATH9K_PKT_TYPE_PSPOLL; |
| 1513 | else |
| 1514 | htype = ATH9K_PKT_TYPE_NORMAL; |
| 1515 | |
| 1516 | return htype; |
| 1517 | } |
| 1518 | |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1519 | static void setup_frame_info(struct ieee80211_hw *hw, struct sk_buff *skb, |
| 1520 | int framelen) |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1521 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1522 | struct ath_softc *sc = hw->priv; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1523 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1524 | struct ieee80211_sta *sta = tx_info->control.sta; |
| 1525 | struct ieee80211_key_conf *hw_key = tx_info->control.hw_key; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1526 | struct ieee80211_hdr *hdr; |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1527 | struct ath_frame_info *fi = get_frame_info(skb); |
Felix Fietkau | 93ae2dd | 2011-04-17 23:28:10 +0200 | [diff] [blame] | 1528 | struct ath_node *an = NULL; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1529 | struct ath_atx_tid *tid; |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1530 | enum ath9k_key_type keytype; |
| 1531 | u16 seqno = 0; |
Felix Fietkau | 5daefbd | 2010-11-14 15:20:02 +0100 | [diff] [blame] | 1532 | u8 tidno; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1533 | |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1534 | keytype = ath9k_cmn_get_hw_crypto_keytype(skb); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1535 | |
Felix Fietkau | 93ae2dd | 2011-04-17 23:28:10 +0200 | [diff] [blame] | 1536 | if (sta) |
| 1537 | an = (struct ath_node *) sta->drv_priv; |
| 1538 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1539 | hdr = (struct ieee80211_hdr *)skb->data; |
Felix Fietkau | 93ae2dd | 2011-04-17 23:28:10 +0200 | [diff] [blame] | 1540 | if (an && ieee80211_is_data_qos(hdr->frame_control) && |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1541 | conf_is_ht(&hw->conf) && (sc->sc_flags & SC_OP_TXAGGR)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1542 | |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1543 | tidno = ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK; |
| 1544 | |
| 1545 | /* |
| 1546 | * Override seqno set by upper layer with the one |
| 1547 | * in tx aggregation state. |
| 1548 | */ |
| 1549 | tid = ATH_AN_2_TID(an, tidno); |
| 1550 | seqno = tid->seq_next; |
| 1551 | hdr->seq_ctrl = cpu_to_le16(seqno << IEEE80211_SEQ_SEQ_SHIFT); |
| 1552 | INCR(tid->seq_next, IEEE80211_SEQ_MAX); |
| 1553 | } |
| 1554 | |
| 1555 | memset(fi, 0, sizeof(*fi)); |
| 1556 | if (hw_key) |
| 1557 | fi->keyix = hw_key->hw_key_idx; |
Felix Fietkau | 93ae2dd | 2011-04-17 23:28:10 +0200 | [diff] [blame] | 1558 | else if (an && ieee80211_is_data(hdr->frame_control) && an->ps_key > 0) |
| 1559 | fi->keyix = an->ps_key; |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1560 | else |
| 1561 | fi->keyix = ATH9K_TXKEYIX_INVALID; |
| 1562 | fi->keytype = keytype; |
| 1563 | fi->framelen = framelen; |
| 1564 | fi->seqno = seqno; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1565 | } |
| 1566 | |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 1567 | static int setup_tx_flags(struct sk_buff *skb) |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1568 | { |
| 1569 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 1570 | int flags = 0; |
| 1571 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1572 | flags |= ATH9K_TXDESC_INTREQ; |
| 1573 | |
| 1574 | if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK) |
| 1575 | flags |= ATH9K_TXDESC_NOACK; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1576 | |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 1577 | if (tx_info->flags & IEEE80211_TX_CTL_LDPC) |
Luis R. Rodriguez | b0a3344 | 2010-04-15 17:39:39 -0400 | [diff] [blame] | 1578 | flags |= ATH9K_TXDESC_LDPC; |
| 1579 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1580 | return flags; |
| 1581 | } |
| 1582 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1583 | /* |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1584 | * rix - rate index |
| 1585 | * pktlen - total bytes (delims + data + fcs + pads + pad delims) |
| 1586 | * width - 0 for 20 MHz, 1 for 40 MHz |
| 1587 | * half_gi - to use 4us v/s 3.6 us for symbol time |
| 1588 | */ |
Felix Fietkau | 269c44b | 2010-11-14 15:20:06 +0100 | [diff] [blame] | 1589 | static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, int pktlen, |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 1590 | int width, int half_gi, bool shortPreamble) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1591 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1592 | u32 nbits, nsymbits, duration, nsymbols; |
Felix Fietkau | 269c44b | 2010-11-14 15:20:06 +0100 | [diff] [blame] | 1593 | int streams; |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 1594 | |
| 1595 | /* find number of symbols: PLCP + data */ |
Felix Fietkau | c666387 | 2010-04-19 19:57:33 +0200 | [diff] [blame] | 1596 | streams = HT_RC_2_STREAMS(rix); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1597 | nbits = (pktlen << 3) + OFDM_PLCP_BITS; |
Felix Fietkau | c666387 | 2010-04-19 19:57:33 +0200 | [diff] [blame] | 1598 | nsymbits = bits_per_symbol[rix % 8][width] * streams; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1599 | nsymbols = (nbits + nsymbits - 1) / nsymbits; |
| 1600 | |
| 1601 | if (!half_gi) |
| 1602 | duration = SYMBOL_TIME(nsymbols); |
| 1603 | else |
| 1604 | duration = SYMBOL_TIME_HALFGI(nsymbols); |
| 1605 | |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 1606 | /* addup duration for legacy/ht training and signal fields */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1607 | duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams); |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 1608 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1609 | return duration; |
| 1610 | } |
| 1611 | |
Mohammed Shafi Shajakhan | ea066d5 | 2010-11-23 20:42:27 +0530 | [diff] [blame] | 1612 | u8 ath_txchainmask_reduction(struct ath_softc *sc, u8 chainmask, u32 rate) |
| 1613 | { |
| 1614 | struct ath_hw *ah = sc->sc_ah; |
| 1615 | struct ath9k_channel *curchan = ah->curchan; |
Rajkumar Manoharan | d77bf3e | 2011-08-13 10:28:14 +0530 | [diff] [blame] | 1616 | if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && |
| 1617 | (curchan->channelFlags & CHANNEL_5GHZ) && |
| 1618 | (chainmask == 0x7) && (rate < 0x90)) |
Mohammed Shafi Shajakhan | ea066d5 | 2010-11-23 20:42:27 +0530 | [diff] [blame] | 1619 | return 0x3; |
| 1620 | else |
| 1621 | return chainmask; |
| 1622 | } |
| 1623 | |
Felix Fietkau | 269c44b | 2010-11-14 15:20:06 +0100 | [diff] [blame] | 1624 | static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf, int len) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1625 | { |
Luis R. Rodriguez | 43c2761 | 2009-09-13 21:07:07 -0700 | [diff] [blame] | 1626 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1627 | struct ath9k_11n_rate_series series[4]; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1628 | struct sk_buff *skb; |
| 1629 | struct ieee80211_tx_info *tx_info; |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 1630 | struct ieee80211_tx_rate *rates; |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 1631 | const struct ieee80211_rate *rate; |
Sujith | 254ad0f | 2009-02-04 08:10:19 +0530 | [diff] [blame] | 1632 | struct ieee80211_hdr *hdr; |
Sujith | c89424d | 2009-01-30 14:29:28 +0530 | [diff] [blame] | 1633 | int i, flags = 0; |
| 1634 | u8 rix = 0, ctsrate = 0; |
Sujith | 254ad0f | 2009-02-04 08:10:19 +0530 | [diff] [blame] | 1635 | bool is_pspoll; |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 1636 | |
| 1637 | memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1638 | |
Sujith | a22be22 | 2009-03-30 15:28:36 +0530 | [diff] [blame] | 1639 | skb = bf->bf_mpdu; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1640 | tx_info = IEEE80211_SKB_CB(skb); |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 1641 | rates = tx_info->control.rates; |
Sujith | 254ad0f | 2009-02-04 08:10:19 +0530 | [diff] [blame] | 1642 | hdr = (struct ieee80211_hdr *)skb->data; |
| 1643 | is_pspoll = ieee80211_is_pspoll(hdr->frame_control); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1644 | |
Sujith | c89424d | 2009-01-30 14:29:28 +0530 | [diff] [blame] | 1645 | /* |
| 1646 | * We check if Short Preamble is needed for the CTS rate by |
| 1647 | * checking the BSS's global flag. |
| 1648 | * But for the rate series, IEEE80211_TX_RC_USE_SHORT_PREAMBLE is used. |
| 1649 | */ |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 1650 | rate = ieee80211_get_rts_cts_rate(sc->hw, tx_info); |
| 1651 | ctsrate = rate->hw_value; |
Sujith | c89424d | 2009-01-30 14:29:28 +0530 | [diff] [blame] | 1652 | if (sc->sc_flags & SC_OP_PREAMBLE_SHORT) |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 1653 | ctsrate |= rate->hw_value_short; |
Luis R. Rodriguez | 9674225 | 2008-12-23 15:58:38 -0800 | [diff] [blame] | 1654 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1655 | for (i = 0; i < 4; i++) { |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 1656 | bool is_40, is_sgi, is_sp; |
| 1657 | int phy; |
| 1658 | |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 1659 | if (!rates[i].count || (rates[i].idx < 0)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1660 | continue; |
| 1661 | |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 1662 | rix = rates[i].idx; |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 1663 | series[i].Tries = rates[i].count; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1664 | |
Mohammed Shafi Shajakhan | cbe8c73 | 2011-05-03 13:14:06 +0530 | [diff] [blame] | 1665 | if (rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) { |
Sujith | c89424d | 2009-01-30 14:29:28 +0530 | [diff] [blame] | 1666 | series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS; |
Felix Fietkau | 2703205 | 2010-01-17 21:08:50 +0100 | [diff] [blame] | 1667 | flags |= ATH9K_TXDESC_RTSENA; |
| 1668 | } else if (rates[i].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
| 1669 | series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS; |
| 1670 | flags |= ATH9K_TXDESC_CTSENA; |
| 1671 | } |
| 1672 | |
Sujith | c89424d | 2009-01-30 14:29:28 +0530 | [diff] [blame] | 1673 | if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) |
| 1674 | series[i].RateFlags |= ATH9K_RATESERIES_2040; |
| 1675 | if (rates[i].flags & IEEE80211_TX_RC_SHORT_GI) |
| 1676 | series[i].RateFlags |= ATH9K_RATESERIES_HALFGI; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1677 | |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 1678 | is_sgi = !!(rates[i].flags & IEEE80211_TX_RC_SHORT_GI); |
| 1679 | is_40 = !!(rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH); |
| 1680 | is_sp = !!(rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE); |
| 1681 | |
| 1682 | if (rates[i].flags & IEEE80211_TX_RC_MCS) { |
| 1683 | /* MCS rates */ |
| 1684 | series[i].Rate = rix | 0x80; |
Mohammed Shafi Shajakhan | ea066d5 | 2010-11-23 20:42:27 +0530 | [diff] [blame] | 1685 | series[i].ChSel = ath_txchainmask_reduction(sc, |
| 1686 | common->tx_chainmask, series[i].Rate); |
Felix Fietkau | 269c44b | 2010-11-14 15:20:06 +0100 | [diff] [blame] | 1687 | series[i].PktDuration = ath_pkt_duration(sc, rix, len, |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 1688 | is_40, is_sgi, is_sp); |
Felix Fietkau | 074a8c0 | 2010-04-19 19:57:36 +0200 | [diff] [blame] | 1689 | if (rix < 8 && (tx_info->flags & IEEE80211_TX_CTL_STBC)) |
| 1690 | series[i].RateFlags |= ATH9K_RATESERIES_STBC; |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 1691 | continue; |
| 1692 | } |
| 1693 | |
Mohammed Shafi Shajakhan | ea066d5 | 2010-11-23 20:42:27 +0530 | [diff] [blame] | 1694 | /* legacy rates */ |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 1695 | if ((tx_info->band == IEEE80211_BAND_2GHZ) && |
| 1696 | !(rate->flags & IEEE80211_RATE_ERP_G)) |
| 1697 | phy = WLAN_RC_PHY_CCK; |
| 1698 | else |
| 1699 | phy = WLAN_RC_PHY_OFDM; |
| 1700 | |
| 1701 | rate = &sc->sbands[tx_info->band].bitrates[rates[i].idx]; |
| 1702 | series[i].Rate = rate->hw_value; |
| 1703 | if (rate->hw_value_short) { |
| 1704 | if (rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
| 1705 | series[i].Rate |= rate->hw_value_short; |
| 1706 | } else { |
| 1707 | is_sp = false; |
| 1708 | } |
| 1709 | |
Mohammed Shafi Shajakhan | ea066d5 | 2010-11-23 20:42:27 +0530 | [diff] [blame] | 1710 | if (bf->bf_state.bfs_paprd) |
| 1711 | series[i].ChSel = common->tx_chainmask; |
| 1712 | else |
| 1713 | series[i].ChSel = ath_txchainmask_reduction(sc, |
| 1714 | common->tx_chainmask, series[i].Rate); |
| 1715 | |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 1716 | series[i].PktDuration = ath9k_hw_computetxtime(sc->sc_ah, |
Felix Fietkau | 269c44b | 2010-11-14 15:20:06 +0100 | [diff] [blame] | 1717 | phy, rate->bitrate * 100, len, rix, is_sp); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
Felix Fietkau | 2703205 | 2010-01-17 21:08:50 +0100 | [diff] [blame] | 1720 | /* For AR5416 - RTS cannot be followed by a frame larger than 8K */ |
Felix Fietkau | 269c44b | 2010-11-14 15:20:06 +0100 | [diff] [blame] | 1721 | if (bf_isaggr(bf) && (len > sc->sc_ah->caps.rts_aggr_limit)) |
Felix Fietkau | 2703205 | 2010-01-17 21:08:50 +0100 | [diff] [blame] | 1722 | flags &= ~ATH9K_TXDESC_RTSENA; |
| 1723 | |
| 1724 | /* ATH9K_TXDESC_RTSENA and ATH9K_TXDESC_CTSENA are mutually exclusive. */ |
| 1725 | if (flags & ATH9K_TXDESC_RTSENA) |
| 1726 | flags &= ~ATH9K_TXDESC_CTSENA; |
| 1727 | |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 1728 | /* set dur_update_en for l-sig computation except for PS-Poll frames */ |
Sujith | c89424d | 2009-01-30 14:29:28 +0530 | [diff] [blame] | 1729 | ath9k_hw_set11n_ratescenario(sc->sc_ah, bf->bf_desc, |
| 1730 | bf->bf_lastbf->bf_desc, |
Sujith | 254ad0f | 2009-02-04 08:10:19 +0530 | [diff] [blame] | 1731 | !is_pspoll, ctsrate, |
Sujith | c89424d | 2009-01-30 14:29:28 +0530 | [diff] [blame] | 1732 | 0, series, 4, flags); |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 1733 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 1736 | static struct ath_buf *ath_tx_setup_buffer(struct ieee80211_hw *hw, |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1737 | struct ath_txq *txq, |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1738 | struct sk_buff *skb) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1739 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1740 | struct ath_softc *sc = hw->priv; |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1741 | struct ath_hw *ah = sc->sc_ah; |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 1742 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1743 | struct ath_frame_info *fi = get_frame_info(skb); |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 1744 | struct ath_buf *bf; |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1745 | struct ath_desc *ds; |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1746 | int frm_type; |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 1747 | |
| 1748 | bf = ath_tx_get_buffer(sc); |
| 1749 | if (!bf) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1750 | ath_dbg(common, ATH_DBG_XMIT, "TX buffers are full\n"); |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 1751 | return NULL; |
| 1752 | } |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1753 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1754 | ATH_TXBUF_RESET(bf); |
| 1755 | |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 1756 | bf->bf_flags = setup_tx_flags(skb); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1757 | bf->bf_mpdu = skb; |
| 1758 | |
Ben Greear | c1739eb3 | 2010-10-14 12:45:29 -0700 | [diff] [blame] | 1759 | bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, |
| 1760 | skb->len, DMA_TO_DEVICE); |
| 1761 | if (unlikely(dma_mapping_error(sc->dev, bf->bf_buf_addr))) { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1762 | bf->bf_mpdu = NULL; |
Ben Greear | 6cf9e99 | 2010-10-14 12:45:30 -0700 | [diff] [blame] | 1763 | bf->bf_buf_addr = 0; |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1764 | ath_err(ath9k_hw_common(sc->sc_ah), |
| 1765 | "dma_mapping_error() on TX\n"); |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 1766 | ath_tx_return_buffer(sc, bf); |
| 1767 | return NULL; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1768 | } |
| 1769 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1770 | frm_type = get_hw_packet_type(skb); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1771 | |
| 1772 | ds = bf->bf_desc; |
Vasanthakumar Thiagarajan | 87d5efb | 2010-04-15 17:38:43 -0400 | [diff] [blame] | 1773 | ath9k_hw_set_desc_link(ah, ds, 0); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1774 | |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1775 | ath9k_hw_set11n_txdesc(ah, ds, fi->framelen, frm_type, MAX_RATE_POWER, |
| 1776 | fi->keyix, fi->keytype, bf->bf_flags); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1777 | |
| 1778 | ath9k_hw_filltxdesc(ah, ds, |
| 1779 | skb->len, /* segment length */ |
| 1780 | true, /* first segment */ |
| 1781 | true, /* last segment */ |
Vasanthakumar Thiagarajan | 3f3a1c8 | 2010-04-15 17:38:42 -0400 | [diff] [blame] | 1782 | ds, /* first descriptor */ |
Vasanthakumar Thiagarajan | cc610ac0 | 2010-04-15 17:39:26 -0400 | [diff] [blame] | 1783 | bf->bf_buf_addr, |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1784 | txq->axq_qnum); |
| 1785 | |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 1786 | fi->bf = bf; |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1787 | |
| 1788 | return bf; |
| 1789 | } |
| 1790 | |
| 1791 | /* FIXME: tx power */ |
| 1792 | static void ath_tx_start_dma(struct ath_softc *sc, struct ath_buf *bf, |
| 1793 | struct ath_tx_control *txctl) |
| 1794 | { |
| 1795 | struct sk_buff *skb = bf->bf_mpdu; |
| 1796 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 1797 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1798 | struct list_head bf_head; |
Felix Fietkau | 248a38d | 2010-12-10 21:16:46 +0100 | [diff] [blame] | 1799 | struct ath_atx_tid *tid = NULL; |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1800 | u8 tidno; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1801 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1802 | spin_lock_bh(&txctl->txq->axq_lock); |
Mohammed Shafi Shajakhan | 61e1b0b | 2011-03-21 18:27:21 +0530 | [diff] [blame] | 1803 | if ((sc->sc_flags & SC_OP_TXAGGR) && txctl->an && |
| 1804 | ieee80211_is_data_qos(hdr->frame_control)) { |
Felix Fietkau | 5daefbd | 2010-11-14 15:20:02 +0100 | [diff] [blame] | 1805 | tidno = ieee80211_get_qos_ctl(hdr)[0] & |
| 1806 | IEEE80211_QOS_CTL_TID_MASK; |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1807 | tid = ATH_AN_2_TID(txctl->an, tidno); |
Felix Fietkau | 5daefbd | 2010-11-14 15:20:02 +0100 | [diff] [blame] | 1808 | |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 1809 | WARN_ON(tid->ac->txq != txctl->txq); |
Felix Fietkau | 248a38d | 2010-12-10 21:16:46 +0100 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && tid) { |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1813 | /* |
| 1814 | * Try aggregation if it's a unicast data frame |
| 1815 | * and the destination is HT capable. |
| 1816 | */ |
| 1817 | ath_tx_send_ampdu(sc, tid, bf, txctl); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1818 | } else { |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1819 | INIT_LIST_HEAD(&bf_head); |
| 1820 | list_add_tail(&bf->list, &bf_head); |
| 1821 | |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 1822 | bf->bf_state.bfs_paprd = txctl->paprd; |
| 1823 | |
Felix Fietkau | 9a6b827 | 2010-11-14 00:03:01 +0100 | [diff] [blame] | 1824 | if (bf->bf_state.bfs_paprd) |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1825 | ar9003_hw_set_paprd_txdesc(sc->sc_ah, bf->bf_desc, |
| 1826 | bf->bf_state.bfs_paprd); |
Felix Fietkau | 9a6b827 | 2010-11-14 00:03:01 +0100 | [diff] [blame] | 1827 | |
Mohammed Shafi Shajakhan | 9cf04dc | 2011-02-04 18:38:23 +0530 | [diff] [blame] | 1828 | if (txctl->paprd) |
| 1829 | bf->bf_state.bfs_paprd_timestamp = jiffies; |
| 1830 | |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 1831 | if (tx_info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT) |
| 1832 | ath9k_hw_set_clrdmask(sc->sc_ah, bf->bf_desc, true); |
| 1833 | |
Felix Fietkau | 248a38d | 2010-12-10 21:16:46 +0100 | [diff] [blame] | 1834 | ath_tx_send_normal(sc, txctl->txq, tid, &bf_head); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | spin_unlock_bh(&txctl->txq->axq_lock); |
| 1838 | } |
| 1839 | |
| 1840 | /* Upon failure caller should free skb */ |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 1841 | int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb, |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1842 | struct ath_tx_control *txctl) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1843 | { |
Felix Fietkau | 28d1670 | 2010-11-14 15:20:10 +0100 | [diff] [blame] | 1844 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 1845 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1846 | struct ieee80211_sta *sta = info->control.sta; |
Felix Fietkau | f59a59f | 2011-05-10 20:52:22 +0200 | [diff] [blame] | 1847 | struct ieee80211_vif *vif = info->control.vif; |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1848 | struct ath_softc *sc = hw->priv; |
Felix Fietkau | 84642d6 | 2010-06-01 21:33:13 +0200 | [diff] [blame] | 1849 | struct ath_txq *txq = txctl->txq; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1850 | struct ath_buf *bf; |
Felix Fietkau | 28d1670 | 2010-11-14 15:20:10 +0100 | [diff] [blame] | 1851 | int padpos, padsize; |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1852 | int frmlen = skb->len + FCS_LEN; |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 1853 | int q; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1854 | |
Ben Greear | a9927ba | 2010-12-06 21:13:49 -0800 | [diff] [blame] | 1855 | /* NOTE: sta can be NULL according to net/mac80211.h */ |
| 1856 | if (sta) |
| 1857 | txctl->an = (struct ath_node *)sta->drv_priv; |
| 1858 | |
Felix Fietkau | 04caf86 | 2010-11-14 15:20:12 +0100 | [diff] [blame] | 1859 | if (info->control.hw_key) |
| 1860 | frmlen += info->control.hw_key->icv_len; |
| 1861 | |
Felix Fietkau | 28d1670 | 2010-11-14 15:20:10 +0100 | [diff] [blame] | 1862 | /* |
| 1863 | * As a temporary workaround, assign seq# here; this will likely need |
| 1864 | * to be cleaned up to work better with Beacon transmission and virtual |
| 1865 | * BSSes. |
| 1866 | */ |
| 1867 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
| 1868 | if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) |
| 1869 | sc->tx.seq_no += 0x10; |
| 1870 | hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
| 1871 | hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no); |
| 1872 | } |
| 1873 | |
| 1874 | /* Add the padding after the header if this is not already done */ |
| 1875 | padpos = ath9k_cmn_padpos(hdr->frame_control); |
| 1876 | padsize = padpos & 3; |
| 1877 | if (padsize && skb->len > padpos) { |
| 1878 | if (skb_headroom(skb) < padsize) |
| 1879 | return -ENOMEM; |
| 1880 | |
| 1881 | skb_push(skb, padsize); |
| 1882 | memmove(skb->data, skb->data + padsize, padpos); |
| 1883 | } |
| 1884 | |
Felix Fietkau | f59a59f | 2011-05-10 20:52:22 +0200 | [diff] [blame] | 1885 | if ((vif && vif->type != NL80211_IFTYPE_AP && |
| 1886 | vif->type != NL80211_IFTYPE_AP_VLAN) || |
| 1887 | !ieee80211_is_data(hdr->frame_control)) |
| 1888 | info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; |
| 1889 | |
Felix Fietkau | 2d42efc | 2010-11-14 15:20:13 +0100 | [diff] [blame] | 1890 | setup_frame_info(hw, skb, frmlen); |
| 1891 | |
| 1892 | /* |
| 1893 | * At this point, the vif, hw_key and sta pointers in the tx control |
| 1894 | * info are no longer valid (overwritten by the ath_frame_info data. |
| 1895 | */ |
| 1896 | |
| 1897 | bf = ath_tx_setup_buffer(hw, txctl->txq, skb); |
Felix Fietkau | 82b873a | 2010-11-11 03:18:37 +0100 | [diff] [blame] | 1898 | if (unlikely(!bf)) |
| 1899 | return -ENOMEM; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1900 | |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 1901 | q = skb_get_queue_mapping(skb); |
Felix Fietkau | 97923b1 | 2010-06-12 00:33:55 -0400 | [diff] [blame] | 1902 | spin_lock_bh(&txq->axq_lock); |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 1903 | if (txq == sc->tx.txq_map[q] && |
| 1904 | ++txq->pending_frames > ATH_MAX_QDEPTH && !txq->stopped) { |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 1905 | ieee80211_stop_queue(sc->hw, q); |
Felix Fietkau | 97923b1 | 2010-06-12 00:33:55 -0400 | [diff] [blame] | 1906 | txq->stopped = 1; |
| 1907 | } |
| 1908 | spin_unlock_bh(&txq->axq_lock); |
| 1909 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1910 | ath_tx_start_dma(sc, bf, txctl); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1911 | |
| 1912 | return 0; |
| 1913 | } |
| 1914 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1915 | /*****************/ |
| 1916 | /* TX Completion */ |
| 1917 | /*****************/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1918 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1919 | static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb, |
Rajkumar Manoharan | 0f9dc29 | 2011-07-29 17:38:14 +0530 | [diff] [blame] | 1920 | int tx_flags, struct ath_txq *txq) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1921 | { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1922 | struct ieee80211_hw *hw = sc->hw; |
| 1923 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1924 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Benoit Papillault | 4d91f9f | 2009-12-12 00:22:35 +0100 | [diff] [blame] | 1925 | struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data; |
Felix Fietkau | 97923b1 | 2010-06-12 00:33:55 -0400 | [diff] [blame] | 1926 | int q, padpos, padsize; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1927 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1928 | ath_dbg(common, ATH_DBG_XMIT, "TX complete: skb: %p\n", skb); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1929 | |
Vasanthakumar Thiagarajan | 6b2c403 | 2009-03-20 15:27:50 +0530 | [diff] [blame] | 1930 | if (tx_flags & ATH_TX_BAR) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1931 | tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1932 | |
Vasanthakumar Thiagarajan | 6b2c403 | 2009-03-20 15:27:50 +0530 | [diff] [blame] | 1933 | if (!(tx_flags & (ATH_TX_ERROR | ATH_TX_XRETRY))) { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1934 | /* Frame was ACKed */ |
| 1935 | tx_info->flags |= IEEE80211_TX_STAT_ACK; |
| 1936 | } |
| 1937 | |
Benoit Papillault | 4d91f9f | 2009-12-12 00:22:35 +0100 | [diff] [blame] | 1938 | padpos = ath9k_cmn_padpos(hdr->frame_control); |
| 1939 | padsize = padpos & 3; |
| 1940 | if (padsize && skb->len>padpos+padsize) { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1941 | /* |
| 1942 | * Remove MAC header padding before giving the frame back to |
| 1943 | * mac80211. |
| 1944 | */ |
Benoit Papillault | 4d91f9f | 2009-12-12 00:22:35 +0100 | [diff] [blame] | 1945 | memmove(skb->data + padsize, skb->data, padpos); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1946 | skb_pull(skb, padsize); |
| 1947 | } |
| 1948 | |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 1949 | if (sc->ps_flags & PS_WAIT_FOR_TX_ACK) { |
| 1950 | sc->ps_flags &= ~PS_WAIT_FOR_TX_ACK; |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1951 | ath_dbg(common, ATH_DBG_PS, |
| 1952 | "Going back to sleep after having received TX status (0x%lx)\n", |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 1953 | sc->ps_flags & (PS_WAIT_FOR_BEACON | |
| 1954 | PS_WAIT_FOR_CAB | |
| 1955 | PS_WAIT_FOR_PSPOLL_DATA | |
| 1956 | PS_WAIT_FOR_TX_ACK)); |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 1957 | } |
| 1958 | |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 1959 | q = skb_get_queue_mapping(skb); |
| 1960 | if (txq == sc->tx.txq_map[q]) { |
| 1961 | spin_lock_bh(&txq->axq_lock); |
| 1962 | if (WARN_ON(--txq->pending_frames < 0)) |
| 1963 | txq->pending_frames = 0; |
Felix Fietkau | 9246041 | 2011-01-24 19:23:14 +0100 | [diff] [blame] | 1964 | |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 1965 | if (txq->stopped && txq->pending_frames < ATH_MAX_QDEPTH) { |
| 1966 | ieee80211_wake_queue(sc->hw, q); |
| 1967 | txq->stopped = 0; |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 1968 | } |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 1969 | spin_unlock_bh(&txq->axq_lock); |
Felix Fietkau | 97923b1 | 2010-06-12 00:33:55 -0400 | [diff] [blame] | 1970 | } |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 1971 | |
| 1972 | ieee80211_tx_status(hw, skb); |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf, |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 1976 | struct ath_txq *txq, struct list_head *bf_q, |
| 1977 | struct ath_tx_status *ts, int txok, int sendbar) |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1978 | { |
| 1979 | struct sk_buff *skb = bf->bf_mpdu; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1980 | unsigned long flags; |
Vasanthakumar Thiagarajan | 6b2c403 | 2009-03-20 15:27:50 +0530 | [diff] [blame] | 1981 | int tx_flags = 0; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1982 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1983 | if (sendbar) |
Vasanthakumar Thiagarajan | 6b2c403 | 2009-03-20 15:27:50 +0530 | [diff] [blame] | 1984 | tx_flags = ATH_TX_BAR; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1985 | |
| 1986 | if (!txok) { |
Vasanthakumar Thiagarajan | 6b2c403 | 2009-03-20 15:27:50 +0530 | [diff] [blame] | 1987 | tx_flags |= ATH_TX_ERROR; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1988 | |
| 1989 | if (bf_isxretried(bf)) |
Vasanthakumar Thiagarajan | 6b2c403 | 2009-03-20 15:27:50 +0530 | [diff] [blame] | 1990 | tx_flags |= ATH_TX_XRETRY; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 1991 | } |
| 1992 | |
Ben Greear | c1739eb3 | 2010-10-14 12:45:29 -0700 | [diff] [blame] | 1993 | dma_unmap_single(sc->dev, bf->bf_buf_addr, skb->len, DMA_TO_DEVICE); |
Ben Greear | 6cf9e99 | 2010-10-14 12:45:30 -0700 | [diff] [blame] | 1994 | bf->bf_buf_addr = 0; |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 1995 | |
| 1996 | if (bf->bf_state.bfs_paprd) { |
Mohammed Shafi Shajakhan | 9cf04dc | 2011-02-04 18:38:23 +0530 | [diff] [blame] | 1997 | if (time_after(jiffies, |
| 1998 | bf->bf_state.bfs_paprd_timestamp + |
| 1999 | msecs_to_jiffies(ATH_PAPRD_TIMEOUT))) |
Vasanthakumar Thiagarajan | ca369eb | 2010-06-24 02:42:44 -0700 | [diff] [blame] | 2000 | dev_kfree_skb_any(skb); |
Vasanthakumar Thiagarajan | 78a1817 | 2010-06-24 02:42:46 -0700 | [diff] [blame] | 2001 | else |
Vasanthakumar Thiagarajan | ca369eb | 2010-06-24 02:42:44 -0700 | [diff] [blame] | 2002 | complete(&sc->paprd_complete); |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 2003 | } else { |
Felix Fietkau | 5bec3e5 | 2011-01-24 21:29:25 +0100 | [diff] [blame] | 2004 | ath_debug_stat_tx(sc, bf, ts, txq); |
Rajkumar Manoharan | 0f9dc29 | 2011-07-29 17:38:14 +0530 | [diff] [blame] | 2005 | ath_tx_complete(sc, skb, tx_flags, txq); |
Felix Fietkau | 9f42c2b | 2010-06-12 00:34:01 -0400 | [diff] [blame] | 2006 | } |
Ben Greear | 6cf9e99 | 2010-10-14 12:45:30 -0700 | [diff] [blame] | 2007 | /* At this point, skb (bf->bf_mpdu) is consumed...make sure we don't |
| 2008 | * accidentally reference it later. |
| 2009 | */ |
| 2010 | bf->bf_mpdu = NULL; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 2011 | |
| 2012 | /* |
| 2013 | * Return the list of ath_buf of this mpdu to free queue |
| 2014 | */ |
| 2015 | spin_lock_irqsave(&sc->tx.txbuflock, flags); |
| 2016 | list_splice_tail_init(bf_q, &sc->tx.txbuf); |
| 2017 | spin_unlock_irqrestore(&sc->tx.txbuflock, flags); |
| 2018 | } |
| 2019 | |
Felix Fietkau | 0cdd5c6 | 2011-01-24 19:23:17 +0100 | [diff] [blame] | 2020 | static void ath_tx_rc_status(struct ath_softc *sc, struct ath_buf *bf, |
| 2021 | struct ath_tx_status *ts, int nframes, int nbad, |
| 2022 | int txok, bool update_rc) |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 2023 | { |
Sujith | a22be22 | 2009-03-30 15:28:36 +0530 | [diff] [blame] | 2024 | struct sk_buff *skb = bf->bf_mpdu; |
Sujith | 254ad0f | 2009-02-04 08:10:19 +0530 | [diff] [blame] | 2025 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 2026 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
Felix Fietkau | 0cdd5c6 | 2011-01-24 19:23:17 +0100 | [diff] [blame] | 2027 | struct ieee80211_hw *hw = sc->hw; |
Felix Fietkau | f0c255a | 2010-11-11 03:18:35 +0100 | [diff] [blame] | 2028 | struct ath_hw *ah = sc->sc_ah; |
Vasanthakumar Thiagarajan | 8a92e2e | 2009-03-20 15:27:49 +0530 | [diff] [blame] | 2029 | u8 i, tx_rateindex; |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 2030 | |
Sujith | 95e4acb | 2009-03-13 08:56:09 +0530 | [diff] [blame] | 2031 | if (txok) |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 2032 | tx_info->status.ack_signal = ts->ts_rssi; |
Sujith | 95e4acb | 2009-03-13 08:56:09 +0530 | [diff] [blame] | 2033 | |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 2034 | tx_rateindex = ts->ts_rateindex; |
Vasanthakumar Thiagarajan | 8a92e2e | 2009-03-20 15:27:49 +0530 | [diff] [blame] | 2035 | WARN_ON(tx_rateindex >= hw->max_rates); |
| 2036 | |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 2037 | if (ts->ts_status & ATH9K_TXERR_FILT) |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 2038 | tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED; |
Björn Smedman | ebd0228 | 2010-10-10 22:44:39 +0200 | [diff] [blame] | 2039 | if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && update_rc) { |
Felix Fietkau | d969847 | 2010-03-01 13:32:11 +0100 | [diff] [blame] | 2040 | tx_info->flags |= IEEE80211_TX_STAT_AMPDU; |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 2041 | |
Felix Fietkau | b572d03 | 2010-11-14 15:20:07 +0100 | [diff] [blame] | 2042 | BUG_ON(nbad > nframes); |
Björn Smedman | ebd0228 | 2010-10-10 22:44:39 +0200 | [diff] [blame] | 2043 | |
Felix Fietkau | b572d03 | 2010-11-14 15:20:07 +0100 | [diff] [blame] | 2044 | tx_info->status.ampdu_len = nframes; |
| 2045 | tx_info->status.ampdu_ack_len = nframes - nbad; |
Björn Smedman | ebd0228 | 2010-10-10 22:44:39 +0200 | [diff] [blame] | 2046 | } |
| 2047 | |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 2048 | if ((ts->ts_status & ATH9K_TXERR_FILT) == 0 && |
Vasanthakumar Thiagarajan | 8a92e2e | 2009-03-20 15:27:49 +0530 | [diff] [blame] | 2049 | (bf->bf_flags & ATH9K_TXDESC_NOACK) == 0 && update_rc) { |
Felix Fietkau | f0c255a | 2010-11-11 03:18:35 +0100 | [diff] [blame] | 2050 | /* |
| 2051 | * If an underrun error is seen assume it as an excessive |
| 2052 | * retry only if max frame trigger level has been reached |
| 2053 | * (2 KB for single stream, and 4 KB for dual stream). |
| 2054 | * Adjust the long retry as if the frame was tried |
| 2055 | * hw->max_rate_tries times to affect how rate control updates |
| 2056 | * PER for the failed rate. |
| 2057 | * In case of congestion on the bus penalizing this type of |
| 2058 | * underruns should help hardware actually transmit new frames |
| 2059 | * successfully by eventually preferring slower rates. |
| 2060 | * This itself should also alleviate congestion on the bus. |
| 2061 | */ |
| 2062 | if (ieee80211_is_data(hdr->frame_control) && |
| 2063 | (ts->ts_flags & (ATH9K_TX_DATA_UNDERRUN | |
| 2064 | ATH9K_TX_DELIM_UNDERRUN)) && |
Felix Fietkau | 83860c5 | 2011-03-23 20:57:33 +0100 | [diff] [blame] | 2065 | ah->tx_trig_level >= sc->sc_ah->config.max_txtrig_level) |
Felix Fietkau | f0c255a | 2010-11-11 03:18:35 +0100 | [diff] [blame] | 2066 | tx_info->status.rates[tx_rateindex].count = |
| 2067 | hw->max_rate_tries; |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 2068 | } |
Vasanthakumar Thiagarajan | 8a92e2e | 2009-03-20 15:27:49 +0530 | [diff] [blame] | 2069 | |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 2070 | for (i = tx_rateindex + 1; i < hw->max_rates; i++) { |
Vasanthakumar Thiagarajan | 8a92e2e | 2009-03-20 15:27:49 +0530 | [diff] [blame] | 2071 | tx_info->status.rates[i].count = 0; |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 2072 | tx_info->status.rates[i].idx = -1; |
| 2073 | } |
Vasanthakumar Thiagarajan | 8a92e2e | 2009-03-20 15:27:49 +0530 | [diff] [blame] | 2074 | |
Felix Fietkau | 78c4653 | 2010-06-25 01:26:16 +0200 | [diff] [blame] | 2075 | tx_info->status.rates[tx_rateindex].count = ts->ts_longretry + 1; |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 2076 | } |
| 2077 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2078 | static void ath_tx_process_buffer(struct ath_softc *sc, struct ath_txq *txq, |
| 2079 | struct ath_tx_status *ts, struct ath_buf *bf, |
| 2080 | struct list_head *bf_head) |
Rajkumar Manoharan | 5479de6 | 2011-07-17 11:43:02 +0530 | [diff] [blame] | 2081 | __releases(txq->axq_lock) |
| 2082 | __acquires(txq->axq_lock) |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2083 | { |
| 2084 | int txok; |
| 2085 | |
| 2086 | txq->axq_depth--; |
| 2087 | txok = !(ts->ts_status & ATH9K_TXERR_MASK); |
| 2088 | txq->axq_tx_inprogress = false; |
| 2089 | if (bf_is_ampdu_not_probing(bf)) |
| 2090 | txq->axq_ampdu_depth--; |
| 2091 | |
| 2092 | spin_unlock_bh(&txq->axq_lock); |
| 2093 | |
| 2094 | if (!bf_isampdu(bf)) { |
| 2095 | /* |
| 2096 | * This frame is sent out as a single frame. |
| 2097 | * Use hardware retry status for this frame. |
| 2098 | */ |
| 2099 | if (ts->ts_status & ATH9K_TXERR_XRETRY) |
| 2100 | bf->bf_state.bf_type |= BUF_XRETRY; |
| 2101 | ath_tx_rc_status(sc, bf, ts, 1, txok ? 0 : 1, txok, true); |
| 2102 | ath_tx_complete_buf(sc, bf, txq, bf_head, ts, txok, 0); |
| 2103 | } else |
| 2104 | ath_tx_complete_aggr(sc, txq, bf, bf_head, ts, txok, true); |
| 2105 | |
| 2106 | spin_lock_bh(&txq->axq_lock); |
| 2107 | |
| 2108 | if (sc->sc_flags & SC_OP_TXAGGR) |
| 2109 | ath_txq_schedule(sc, txq); |
| 2110 | } |
| 2111 | |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 2112 | static void ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2113 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 2114 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2115 | struct ath_common *common = ath9k_hw_common(ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2116 | struct ath_buf *bf, *lastbf, *bf_held = NULL; |
| 2117 | struct list_head bf_head; |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 2118 | struct ath_desc *ds; |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 2119 | struct ath_tx_status ts; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2120 | int status; |
| 2121 | |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 2122 | ath_dbg(common, ATH_DBG_QUEUE, "tx queue %d (%x), link %p\n", |
| 2123 | txq->axq_qnum, ath9k_hw_gettxbuf(sc->sc_ah, txq->axq_qnum), |
| 2124 | txq->axq_link); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2125 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2126 | spin_lock_bh(&txq->axq_lock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2127 | for (;;) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2128 | if (list_empty(&txq->axq_q)) { |
| 2129 | txq->axq_link = NULL; |
Felix Fietkau | 86271e4 | 2011-03-11 21:38:19 +0100 | [diff] [blame] | 2130 | if (sc->sc_flags & SC_OP_TXAGGR) |
Ben Greear | 082f653 | 2011-01-09 23:11:47 -0800 | [diff] [blame] | 2131 | ath_txq_schedule(sc, txq); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2132 | break; |
| 2133 | } |
| 2134 | bf = list_first_entry(&txq->axq_q, struct ath_buf, list); |
| 2135 | |
| 2136 | /* |
| 2137 | * There is a race condition that a BH gets scheduled |
| 2138 | * after sw writes TxE and before hw re-load the last |
| 2139 | * descriptor to get the newly chained one. |
| 2140 | * Software must keep the last DONE descriptor as a |
| 2141 | * holding descriptor - software does so by marking |
| 2142 | * it with the STALE flag. |
| 2143 | */ |
| 2144 | bf_held = NULL; |
Sujith | a119cc4 | 2009-03-30 15:28:38 +0530 | [diff] [blame] | 2145 | if (bf->bf_stale) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2146 | bf_held = bf; |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2147 | if (list_is_last(&bf_held->list, &txq->axq_q)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2148 | break; |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2149 | |
| 2150 | bf = list_entry(bf_held->list.next, struct ath_buf, |
| 2151 | list); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | lastbf = bf->bf_lastbf; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 2155 | ds = lastbf->bf_desc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2156 | |
Felix Fietkau | 29bffa9 | 2010-03-29 20:14:23 -0700 | [diff] [blame] | 2157 | memset(&ts, 0, sizeof(ts)); |
| 2158 | status = ath9k_hw_txprocdesc(ah, ds, &ts); |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2159 | if (status == -EINPROGRESS) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2160 | break; |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2161 | |
Ben Greear | 2dac4fb | 2011-01-09 23:11:45 -0800 | [diff] [blame] | 2162 | TX_STAT_INC(txq->axq_qnum, txprocdesc); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2163 | |
| 2164 | /* |
| 2165 | * Remove ath_buf's of the same transmit unit from txq, |
| 2166 | * however leave the last descriptor back as the holding |
| 2167 | * descriptor for hw. |
| 2168 | */ |
Sujith | a119cc4 | 2009-03-30 15:28:38 +0530 | [diff] [blame] | 2169 | lastbf->bf_stale = true; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2170 | INIT_LIST_HEAD(&bf_head); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2171 | if (!list_is_singular(&lastbf->list)) |
| 2172 | list_cut_position(&bf_head, |
| 2173 | &txq->axq_q, lastbf->list.prev); |
| 2174 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2175 | if (bf_held) { |
Felix Fietkau | 0a8cea8 | 2010-04-19 19:57:30 +0200 | [diff] [blame] | 2176 | list_del(&bf_held->list); |
Felix Fietkau | 0a8cea8 | 2010-04-19 19:57:30 +0200 | [diff] [blame] | 2177 | ath_tx_return_buffer(sc, bf_held); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2178 | } |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2179 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2180 | ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2181 | } |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2182 | spin_unlock_bh(&txq->axq_lock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2183 | } |
| 2184 | |
Sujith | 305fe47 | 2009-07-23 15:32:29 +0530 | [diff] [blame] | 2185 | static void ath_tx_complete_poll_work(struct work_struct *work) |
Senthil Balasubramanian | 164ace3 | 2009-07-14 20:17:09 -0400 | [diff] [blame] | 2186 | { |
| 2187 | struct ath_softc *sc = container_of(work, struct ath_softc, |
| 2188 | tx_complete_work.work); |
| 2189 | struct ath_txq *txq; |
| 2190 | int i; |
| 2191 | bool needreset = false; |
Ben Greear | 60f2d1d | 2011-01-09 23:11:52 -0800 | [diff] [blame] | 2192 | #ifdef CONFIG_ATH9K_DEBUGFS |
| 2193 | sc->tx_complete_poll_work_seen++; |
| 2194 | #endif |
Senthil Balasubramanian | 164ace3 | 2009-07-14 20:17:09 -0400 | [diff] [blame] | 2195 | |
| 2196 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) |
| 2197 | if (ATH_TXQ_SETUP(sc, i)) { |
| 2198 | txq = &sc->tx.txq[i]; |
| 2199 | spin_lock_bh(&txq->axq_lock); |
| 2200 | if (txq->axq_depth) { |
| 2201 | if (txq->axq_tx_inprogress) { |
| 2202 | needreset = true; |
| 2203 | spin_unlock_bh(&txq->axq_lock); |
| 2204 | break; |
| 2205 | } else { |
| 2206 | txq->axq_tx_inprogress = true; |
| 2207 | } |
| 2208 | } |
| 2209 | spin_unlock_bh(&txq->axq_lock); |
| 2210 | } |
| 2211 | |
| 2212 | if (needreset) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 2213 | ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_RESET, |
| 2214 | "tx hung, resetting the chip\n"); |
Rajkumar Manoharan | f6b4e4d | 2011-06-24 17:38:13 +0530 | [diff] [blame] | 2215 | spin_lock_bh(&sc->sc_pcu_lock); |
Felix Fietkau | fac6b6a | 2010-10-23 17:45:38 +0200 | [diff] [blame] | 2216 | ath_reset(sc, true); |
Rajkumar Manoharan | f6b4e4d | 2011-06-24 17:38:13 +0530 | [diff] [blame] | 2217 | spin_unlock_bh(&sc->sc_pcu_lock); |
Senthil Balasubramanian | 164ace3 | 2009-07-14 20:17:09 -0400 | [diff] [blame] | 2218 | } |
| 2219 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 2220 | ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, |
Senthil Balasubramanian | 164ace3 | 2009-07-14 20:17:09 -0400 | [diff] [blame] | 2221 | msecs_to_jiffies(ATH_TX_COMPLETE_POLL_INT)); |
| 2222 | } |
| 2223 | |
| 2224 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 2225 | |
| 2226 | void ath_tx_tasklet(struct ath_softc *sc) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2227 | { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 2228 | int i; |
| 2229 | u32 qcumask = ((1 << ATH9K_NUM_TX_QUEUES) - 1); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2230 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 2231 | ath9k_hw_gettxintrtxqs(sc->sc_ah, &qcumask); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2232 | |
| 2233 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 2234 | if (ATH_TXQ_SETUP(sc, i) && (qcumask & (1 << i))) |
| 2235 | ath_tx_processq(sc, &sc->tx.txq[i]); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2236 | } |
| 2237 | } |
| 2238 | |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 2239 | void ath_tx_edma_tasklet(struct ath_softc *sc) |
| 2240 | { |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2241 | struct ath_tx_status ts; |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 2242 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2243 | struct ath_hw *ah = sc->sc_ah; |
| 2244 | struct ath_txq *txq; |
| 2245 | struct ath_buf *bf, *lastbf; |
| 2246 | struct list_head bf_head; |
| 2247 | int status; |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 2248 | |
| 2249 | for (;;) { |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2250 | status = ath9k_hw_txprocdesc(ah, NULL, (void *)&ts); |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 2251 | if (status == -EINPROGRESS) |
| 2252 | break; |
| 2253 | if (status == -EIO) { |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 2254 | ath_dbg(common, ATH_DBG_XMIT, |
| 2255 | "Error processing tx status\n"); |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 2256 | break; |
| 2257 | } |
| 2258 | |
| 2259 | /* Skip beacon completions */ |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2260 | if (ts.qid == sc->beacon.beaconq) |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 2261 | continue; |
| 2262 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2263 | txq = &sc->tx.txq[ts.qid]; |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 2264 | |
| 2265 | spin_lock_bh(&txq->axq_lock); |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2266 | |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 2267 | if (list_empty(&txq->txq_fifo[txq->txq_tailidx])) { |
| 2268 | spin_unlock_bh(&txq->axq_lock); |
| 2269 | return; |
| 2270 | } |
| 2271 | |
| 2272 | bf = list_first_entry(&txq->txq_fifo[txq->txq_tailidx], |
| 2273 | struct ath_buf, list); |
| 2274 | lastbf = bf->bf_lastbf; |
| 2275 | |
| 2276 | INIT_LIST_HEAD(&bf_head); |
| 2277 | list_cut_position(&bf_head, &txq->txq_fifo[txq->txq_tailidx], |
| 2278 | &lastbf->list); |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 2279 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2280 | if (list_empty(&txq->txq_fifo[txq->txq_tailidx])) { |
| 2281 | INCR(txq->txq_tailidx, ATH_TXFIFO_DEPTH); |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 2282 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2283 | if (!list_empty(&txq->axq_q)) { |
| 2284 | struct list_head bf_q; |
| 2285 | |
| 2286 | INIT_LIST_HEAD(&bf_q); |
| 2287 | txq->axq_link = NULL; |
| 2288 | list_splice_tail_init(&txq->axq_q, &bf_q); |
| 2289 | ath_tx_txqaddbuf(sc, txq, &bf_q, true); |
| 2290 | } |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 2291 | } |
| 2292 | |
Felix Fietkau | fce041b | 2011-05-19 12:20:25 +0200 | [diff] [blame] | 2293 | ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head); |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 2294 | spin_unlock_bh(&txq->axq_lock); |
| 2295 | } |
| 2296 | } |
| 2297 | |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 2298 | /*****************/ |
| 2299 | /* Init, Cleanup */ |
| 2300 | /*****************/ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2301 | |
Vasanthakumar Thiagarajan | 5088c2f | 2010-04-15 17:39:34 -0400 | [diff] [blame] | 2302 | static int ath_txstatus_setup(struct ath_softc *sc, int size) |
| 2303 | { |
| 2304 | struct ath_descdma *dd = &sc->txsdma; |
| 2305 | u8 txs_len = sc->sc_ah->caps.txs_len; |
| 2306 | |
| 2307 | dd->dd_desc_len = size * txs_len; |
| 2308 | dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len, |
| 2309 | &dd->dd_desc_paddr, GFP_KERNEL); |
| 2310 | if (!dd->dd_desc) |
| 2311 | return -ENOMEM; |
| 2312 | |
| 2313 | return 0; |
| 2314 | } |
| 2315 | |
| 2316 | static int ath_tx_edma_init(struct ath_softc *sc) |
| 2317 | { |
| 2318 | int err; |
| 2319 | |
| 2320 | err = ath_txstatus_setup(sc, ATH_TXSTATUS_RING_SIZE); |
| 2321 | if (!err) |
| 2322 | ath9k_hw_setup_statusring(sc->sc_ah, sc->txsdma.dd_desc, |
| 2323 | sc->txsdma.dd_desc_paddr, |
| 2324 | ATH_TXSTATUS_RING_SIZE); |
| 2325 | |
| 2326 | return err; |
| 2327 | } |
| 2328 | |
| 2329 | static void ath_tx_edma_cleanup(struct ath_softc *sc) |
| 2330 | { |
| 2331 | struct ath_descdma *dd = &sc->txsdma; |
| 2332 | |
| 2333 | dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc, |
| 2334 | dd->dd_desc_paddr); |
| 2335 | } |
| 2336 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2337 | int ath_tx_init(struct ath_softc *sc, int nbufs) |
| 2338 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 2339 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2340 | int error = 0; |
| 2341 | |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 2342 | spin_lock_init(&sc->tx.txbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2343 | |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 2344 | error = ath_descdma_setup(sc, &sc->tx.txdma, &sc->tx.txbuf, |
Vasanthakumar Thiagarajan | 4adfcde | 2010-04-15 17:39:33 -0400 | [diff] [blame] | 2345 | "tx", nbufs, 1, 1); |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 2346 | if (error != 0) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 2347 | ath_err(common, |
| 2348 | "Failed to allocate tx descriptors: %d\n", error); |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 2349 | goto err; |
| 2350 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2351 | |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 2352 | error = ath_descdma_setup(sc, &sc->beacon.bdma, &sc->beacon.bbuf, |
Vasanthakumar Thiagarajan | 5088c2f | 2010-04-15 17:39:34 -0400 | [diff] [blame] | 2353 | "beacon", ATH_BCBUF, 1, 1); |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 2354 | if (error != 0) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 2355 | ath_err(common, |
| 2356 | "Failed to allocate beacon descriptors: %d\n", error); |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 2357 | goto err; |
| 2358 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2359 | |
Senthil Balasubramanian | 164ace3 | 2009-07-14 20:17:09 -0400 | [diff] [blame] | 2360 | INIT_DELAYED_WORK(&sc->tx_complete_work, ath_tx_complete_poll_work); |
| 2361 | |
Vasanthakumar Thiagarajan | 5088c2f | 2010-04-15 17:39:34 -0400 | [diff] [blame] | 2362 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 2363 | error = ath_tx_edma_init(sc); |
| 2364 | if (error) |
| 2365 | goto err; |
| 2366 | } |
| 2367 | |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 2368 | err: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2369 | if (error != 0) |
| 2370 | ath_tx_cleanup(sc); |
| 2371 | |
| 2372 | return error; |
| 2373 | } |
| 2374 | |
Sujith | 797fe5cb | 2009-03-30 15:28:45 +0530 | [diff] [blame] | 2375 | void ath_tx_cleanup(struct ath_softc *sc) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2376 | { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 2377 | if (sc->beacon.bdma.dd_desc_len != 0) |
| 2378 | ath_descdma_cleanup(sc, &sc->beacon.bdma, &sc->beacon.bbuf); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2379 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 2380 | if (sc->tx.txdma.dd_desc_len != 0) |
| 2381 | ath_descdma_cleanup(sc, &sc->tx.txdma, &sc->tx.txbuf); |
Vasanthakumar Thiagarajan | 5088c2f | 2010-04-15 17:39:34 -0400 | [diff] [blame] | 2382 | |
| 2383 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
| 2384 | ath_tx_edma_cleanup(sc); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2385 | } |
| 2386 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2387 | void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an) |
| 2388 | { |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2389 | struct ath_atx_tid *tid; |
| 2390 | struct ath_atx_ac *ac; |
| 2391 | int tidno, acno; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2392 | |
Sujith | 8ee5afb | 2008-12-07 21:43:36 +0530 | [diff] [blame] | 2393 | for (tidno = 0, tid = &an->tid[tidno]; |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2394 | tidno < WME_NUM_TID; |
| 2395 | tidno++, tid++) { |
| 2396 | tid->an = an; |
| 2397 | tid->tidno = tidno; |
| 2398 | tid->seq_start = tid->seq_next = 0; |
| 2399 | tid->baw_size = WME_MAX_BA; |
| 2400 | tid->baw_head = tid->baw_tail = 0; |
| 2401 | tid->sched = false; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 2402 | tid->paused = false; |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 2403 | tid->state &= ~AGGR_CLEANUP; |
Felix Fietkau | 56dc633 | 2011-08-28 00:32:22 +0200 | [diff] [blame^] | 2404 | __skb_queue_head_init(&tid->buf_q); |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2405 | acno = TID_TO_WME_AC(tidno); |
Sujith | 8ee5afb | 2008-12-07 21:43:36 +0530 | [diff] [blame] | 2406 | tid->ac = &an->ac[acno]; |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 2407 | tid->state &= ~AGGR_ADDBA_COMPLETE; |
| 2408 | tid->state &= ~AGGR_ADDBA_PROGRESS; |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2409 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2410 | |
Sujith | 8ee5afb | 2008-12-07 21:43:36 +0530 | [diff] [blame] | 2411 | for (acno = 0, ac = &an->ac[acno]; |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2412 | acno < WME_NUM_AC; acno++, ac++) { |
| 2413 | ac->sched = false; |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 2414 | ac->txq = sc->tx.txq_map[acno]; |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2415 | INIT_LIST_HEAD(&ac->tid_q); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2416 | } |
| 2417 | } |
| 2418 | |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 2419 | void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2420 | { |
Felix Fietkau | 2b40994 | 2010-07-07 19:42:08 +0200 | [diff] [blame] | 2421 | struct ath_atx_ac *ac; |
| 2422 | struct ath_atx_tid *tid; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2423 | struct ath_txq *txq; |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 2424 | int tidno; |
Sujith | e832435 | 2009-01-16 21:38:42 +0530 | [diff] [blame] | 2425 | |
Felix Fietkau | 2b40994 | 2010-07-07 19:42:08 +0200 | [diff] [blame] | 2426 | for (tidno = 0, tid = &an->tid[tidno]; |
| 2427 | tidno < WME_NUM_TID; tidno++, tid++) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2428 | |
Felix Fietkau | 2b40994 | 2010-07-07 19:42:08 +0200 | [diff] [blame] | 2429 | ac = tid->ac; |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 2430 | txq = ac->txq; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2431 | |
Felix Fietkau | 2b40994 | 2010-07-07 19:42:08 +0200 | [diff] [blame] | 2432 | spin_lock_bh(&txq->axq_lock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2433 | |
Felix Fietkau | 2b40994 | 2010-07-07 19:42:08 +0200 | [diff] [blame] | 2434 | if (tid->sched) { |
| 2435 | list_del(&tid->list); |
| 2436 | tid->sched = false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2437 | } |
Felix Fietkau | 2b40994 | 2010-07-07 19:42:08 +0200 | [diff] [blame] | 2438 | |
| 2439 | if (ac->sched) { |
| 2440 | list_del(&ac->list); |
| 2441 | tid->ac->sched = false; |
| 2442 | } |
| 2443 | |
| 2444 | ath_tid_drain(sc, txq, tid); |
| 2445 | tid->state &= ~AGGR_ADDBA_COMPLETE; |
| 2446 | tid->state &= ~AGGR_CLEANUP; |
| 2447 | |
| 2448 | spin_unlock_bh(&txq->axq_lock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2449 | } |
| 2450 | } |