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