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