Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 Atheros Communications Inc. |
| 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 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 17 | #include "core.h" |
| 18 | |
| 19 | #define BITS_PER_BYTE 8 |
| 20 | #define OFDM_PLCP_BITS 22 |
| 21 | #define HT_RC_2_MCS(_rc) ((_rc) & 0x0f) |
| 22 | #define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1) |
| 23 | #define L_STF 8 |
| 24 | #define L_LTF 8 |
| 25 | #define L_SIG 4 |
| 26 | #define HT_SIG 8 |
| 27 | #define HT_STF 4 |
| 28 | #define HT_LTF(_ns) (4 * (_ns)) |
| 29 | #define SYMBOL_TIME(_ns) ((_ns) << 2) /* ns * 4 us */ |
| 30 | #define SYMBOL_TIME_HALFGI(_ns) (((_ns) * 18 + 4) / 5) /* ns * 3.6 us */ |
| 31 | #define NUM_SYMBOLS_PER_USEC(_usec) (_usec >> 2) |
| 32 | #define NUM_SYMBOLS_PER_USEC_HALFGI(_usec) (((_usec*5)-4)/18) |
| 33 | |
| 34 | #define OFDM_SIFS_TIME 16 |
| 35 | |
| 36 | static u32 bits_per_symbol[][2] = { |
| 37 | /* 20MHz 40MHz */ |
| 38 | { 26, 54 }, /* 0: BPSK */ |
| 39 | { 52, 108 }, /* 1: QPSK 1/2 */ |
| 40 | { 78, 162 }, /* 2: QPSK 3/4 */ |
| 41 | { 104, 216 }, /* 3: 16-QAM 1/2 */ |
| 42 | { 156, 324 }, /* 4: 16-QAM 3/4 */ |
| 43 | { 208, 432 }, /* 5: 64-QAM 2/3 */ |
| 44 | { 234, 486 }, /* 6: 64-QAM 3/4 */ |
| 45 | { 260, 540 }, /* 7: 64-QAM 5/6 */ |
| 46 | { 52, 108 }, /* 8: BPSK */ |
| 47 | { 104, 216 }, /* 9: QPSK 1/2 */ |
| 48 | { 156, 324 }, /* 10: QPSK 3/4 */ |
| 49 | { 208, 432 }, /* 11: 16-QAM 1/2 */ |
| 50 | { 312, 648 }, /* 12: 16-QAM 3/4 */ |
| 51 | { 416, 864 }, /* 13: 64-QAM 2/3 */ |
| 52 | { 468, 972 }, /* 14: 64-QAM 3/4 */ |
| 53 | { 520, 1080 }, /* 15: 64-QAM 5/6 */ |
| 54 | }; |
| 55 | |
| 56 | #define IS_HT_RATE(_rate) ((_rate) & 0x80) |
| 57 | |
| 58 | /* |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 59 | * Insert a chain of ath_buf (descriptors) on a txq and |
| 60 | * assume the descriptors are already chained together by caller. |
| 61 | * NB: must be called with txq lock held |
| 62 | */ |
| 63 | |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 64 | static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq, |
| 65 | struct list_head *head) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 66 | { |
| 67 | struct ath_hal *ah = sc->sc_ah; |
| 68 | struct ath_buf *bf; |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 69 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 70 | /* |
| 71 | * Insert the frame on the outbound list and |
| 72 | * pass it on to the hardware. |
| 73 | */ |
| 74 | |
| 75 | if (list_empty(head)) |
| 76 | return; |
| 77 | |
| 78 | bf = list_first_entry(head, struct ath_buf, list); |
| 79 | |
| 80 | list_splice_tail_init(head, &txq->axq_q); |
| 81 | txq->axq_depth++; |
| 82 | txq->axq_totalqueued++; |
| 83 | txq->axq_linkbuf = list_entry(txq->axq_q.prev, struct ath_buf, list); |
| 84 | |
| 85 | DPRINTF(sc, ATH_DBG_QUEUE, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 86 | "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] | 87 | |
| 88 | if (txq->axq_link == NULL) { |
| 89 | ath9k_hw_puttxbuf(ah, txq->axq_qnum, bf->bf_daddr); |
| 90 | DPRINTF(sc, ATH_DBG_XMIT, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 91 | "TXDP[%u] = %llx (%p)\n", |
| 92 | txq->axq_qnum, ito64(bf->bf_daddr), bf->bf_desc); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 93 | } else { |
| 94 | *txq->axq_link = bf->bf_daddr; |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 95 | DPRINTF(sc, ATH_DBG_XMIT, "link[%u] (%p)=%llx (%p)\n", |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 96 | txq->axq_qnum, txq->axq_link, |
| 97 | ito64(bf->bf_daddr), bf->bf_desc); |
| 98 | } |
| 99 | txq->axq_link = &(bf->bf_lastbf->bf_desc->ds_link); |
| 100 | ath9k_hw_txstart(ah, txq->axq_qnum); |
| 101 | } |
| 102 | |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 103 | static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb, |
| 104 | struct ath_xmit_status *tx_status) |
| 105 | { |
| 106 | struct ieee80211_hw *hw = sc->hw; |
| 107 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 108 | struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info); |
| 109 | |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 110 | DPRINTF(sc, ATH_DBG_XMIT, "TX complete: skb: %p\n", skb); |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 111 | |
| 112 | if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK || |
| 113 | tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED) { |
| 114 | kfree(tx_info_priv); |
| 115 | tx_info->rate_driver_data[0] = NULL; |
| 116 | } |
| 117 | |
| 118 | if (tx_status->flags & ATH_TX_BAR) { |
| 119 | tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK; |
| 120 | tx_status->flags &= ~ATH_TX_BAR; |
| 121 | } |
| 122 | |
| 123 | if (!(tx_status->flags & (ATH_TX_ERROR | ATH_TX_XRETRY))) { |
| 124 | /* Frame was ACKed */ |
| 125 | tx_info->flags |= IEEE80211_TX_STAT_ACK; |
| 126 | } |
| 127 | |
| 128 | tx_info->status.rates[0].count = tx_status->retries + 1; |
| 129 | |
| 130 | ieee80211_tx_status(hw, skb); |
| 131 | } |
| 132 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 133 | /* Check if it's okay to send out aggregates */ |
| 134 | |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 135 | static int ath_aggr_query(struct ath_softc *sc, struct ath_node *an, u8 tidno) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 136 | { |
| 137 | struct ath_atx_tid *tid; |
| 138 | tid = ATH_AN_2_TID(an, tidno); |
| 139 | |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 140 | if (tid->state & AGGR_ADDBA_COMPLETE || |
| 141 | tid->state & AGGR_ADDBA_PROGRESS) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 142 | return 1; |
| 143 | else |
| 144 | return 0; |
| 145 | } |
| 146 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 147 | static void ath_get_beaconconfig(struct ath_softc *sc, int if_id, |
| 148 | struct ath_beacon_config *conf) |
| 149 | { |
| 150 | struct ieee80211_hw *hw = sc->hw; |
| 151 | |
| 152 | /* fill in beacon config data */ |
| 153 | |
| 154 | conf->beacon_interval = hw->conf.beacon_int; |
| 155 | conf->listen_interval = 100; |
| 156 | conf->dtim_count = 1; |
| 157 | conf->bmiss_timeout = ATH_DEFAULT_BMISS_LIMIT * conf->listen_interval; |
| 158 | } |
| 159 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 160 | /* Calculate Atheros packet type from IEEE80211 packet header */ |
| 161 | |
| 162 | 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] | 163 | { |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 164 | struct ieee80211_hdr *hdr; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 165 | enum ath9k_pkt_type htype; |
| 166 | __le16 fc; |
| 167 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 168 | hdr = (struct ieee80211_hdr *)skb->data; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 169 | fc = hdr->frame_control; |
| 170 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 171 | if (ieee80211_is_beacon(fc)) |
| 172 | htype = ATH9K_PKT_TYPE_BEACON; |
| 173 | else if (ieee80211_is_probe_resp(fc)) |
| 174 | htype = ATH9K_PKT_TYPE_PROBE_RESP; |
| 175 | else if (ieee80211_is_atim(fc)) |
| 176 | htype = ATH9K_PKT_TYPE_ATIM; |
| 177 | else if (ieee80211_is_pspoll(fc)) |
| 178 | htype = ATH9K_PKT_TYPE_PSPOLL; |
| 179 | else |
| 180 | htype = ATH9K_PKT_TYPE_NORMAL; |
| 181 | |
| 182 | return htype; |
| 183 | } |
| 184 | |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 185 | static bool is_pae(struct sk_buff *skb) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 186 | { |
| 187 | struct ieee80211_hdr *hdr; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 188 | __le16 fc; |
| 189 | |
| 190 | hdr = (struct ieee80211_hdr *)skb->data; |
| 191 | fc = hdr->frame_control; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 192 | |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 193 | if (ieee80211_is_data(fc)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 194 | if (ieee80211_is_nullfunc(fc) || |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 195 | /* Port Access Entity (IEEE 802.1X) */ |
| 196 | (skb->protocol == cpu_to_be16(ETH_P_PAE))) { |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 197 | return true; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 198 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 201 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 204 | static int get_hw_crypto_keytype(struct sk_buff *skb) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 205 | { |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 206 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 207 | |
| 208 | if (tx_info->control.hw_key) { |
| 209 | if (tx_info->control.hw_key->alg == ALG_WEP) |
| 210 | return ATH9K_KEY_TYPE_WEP; |
| 211 | else if (tx_info->control.hw_key->alg == ALG_TKIP) |
| 212 | return ATH9K_KEY_TYPE_TKIP; |
| 213 | else if (tx_info->control.hw_key->alg == ALG_CCMP) |
| 214 | return ATH9K_KEY_TYPE_AES; |
| 215 | } |
| 216 | |
| 217 | return ATH9K_KEY_TYPE_CLEAR; |
| 218 | } |
| 219 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 220 | /* Called only when tx aggregation is enabled and HT is supported */ |
| 221 | |
| 222 | static void assign_aggr_tid_seqno(struct sk_buff *skb, |
| 223 | struct ath_buf *bf) |
| 224 | { |
| 225 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 226 | struct ieee80211_hdr *hdr; |
| 227 | struct ath_node *an; |
| 228 | struct ath_atx_tid *tid; |
| 229 | __le16 fc; |
| 230 | u8 *qc; |
| 231 | |
| 232 | if (!tx_info->control.sta) |
| 233 | return; |
| 234 | |
| 235 | an = (struct ath_node *)tx_info->control.sta->drv_priv; |
| 236 | hdr = (struct ieee80211_hdr *)skb->data; |
| 237 | fc = hdr->frame_control; |
| 238 | |
| 239 | /* Get tidno */ |
| 240 | |
| 241 | if (ieee80211_is_data_qos(fc)) { |
| 242 | qc = ieee80211_get_qos_ctl(hdr); |
| 243 | bf->bf_tidno = qc[0] & 0xf; |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 244 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 245 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 246 | /* Get seqno */ |
| 247 | |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 248 | if (ieee80211_is_data(fc) && !is_pae(skb)) { |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 249 | /* For HT capable stations, we save tidno for later use. |
| 250 | * We also override seqno set by upper layer with the one |
| 251 | * in tx aggregation state. |
| 252 | * |
| 253 | * If fragmentation is on, the sequence number is |
| 254 | * not overridden, since it has been |
| 255 | * incremented by the fragmentation routine. |
| 256 | * |
| 257 | * FIXME: check if the fragmentation threshold exceeds |
| 258 | * IEEE80211 max. |
| 259 | */ |
| 260 | tid = ATH_AN_2_TID(an, bf->bf_tidno); |
| 261 | hdr->seq_ctrl = cpu_to_le16(tid->seq_next << |
| 262 | IEEE80211_SEQ_SEQ_SHIFT); |
| 263 | bf->bf_seqno = tid->seq_next; |
| 264 | INCR(tid->seq_next, IEEE80211_SEQ_MAX); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | static int setup_tx_flags(struct ath_softc *sc, struct sk_buff *skb, |
| 269 | struct ath_txq *txq) |
| 270 | { |
| 271 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 272 | int flags = 0; |
| 273 | |
| 274 | flags |= ATH9K_TXDESC_CLRDMASK; /* needed for crypto errors */ |
| 275 | flags |= ATH9K_TXDESC_INTREQ; |
| 276 | |
| 277 | if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK) |
| 278 | flags |= ATH9K_TXDESC_NOACK; |
| 279 | if (tx_info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) |
| 280 | flags |= ATH9K_TXDESC_RTSENA; |
| 281 | |
| 282 | return flags; |
| 283 | } |
| 284 | |
| 285 | static struct ath_buf *ath_tx_get_buffer(struct ath_softc *sc) |
| 286 | { |
| 287 | struct ath_buf *bf = NULL; |
| 288 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 289 | spin_lock_bh(&sc->tx.txbuflock); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 290 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 291 | if (unlikely(list_empty(&sc->tx.txbuf))) { |
| 292 | spin_unlock_bh(&sc->tx.txbuflock); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 293 | return NULL; |
| 294 | } |
| 295 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 296 | bf = list_first_entry(&sc->tx.txbuf, struct ath_buf, list); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 297 | list_del(&bf->list); |
| 298 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 299 | spin_unlock_bh(&sc->tx.txbuflock); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 300 | |
| 301 | return bf; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /* To complete a chain of buffers associated a frame */ |
| 305 | |
| 306 | static void ath_tx_complete_buf(struct ath_softc *sc, |
| 307 | struct ath_buf *bf, |
| 308 | struct list_head *bf_q, |
| 309 | int txok, int sendbar) |
| 310 | { |
| 311 | struct sk_buff *skb = bf->bf_mpdu; |
| 312 | struct ath_xmit_status tx_status; |
Senthil Balasubramanian | a07d361 | 2008-12-09 17:23:33 +0530 | [diff] [blame] | 313 | unsigned long flags; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 314 | |
| 315 | /* |
| 316 | * Set retry information. |
| 317 | * NB: Don't use the information in the descriptor, because the frame |
| 318 | * could be software retried. |
| 319 | */ |
| 320 | tx_status.retries = bf->bf_retries; |
| 321 | tx_status.flags = 0; |
| 322 | |
| 323 | if (sendbar) |
| 324 | tx_status.flags = ATH_TX_BAR; |
| 325 | |
| 326 | if (!txok) { |
| 327 | tx_status.flags |= ATH_TX_ERROR; |
| 328 | |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 329 | if (bf_isxretried(bf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 330 | tx_status.flags |= ATH_TX_XRETRY; |
| 331 | } |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 332 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 333 | /* Unmap this frame */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 334 | pci_unmap_single(sc->pdev, |
Sujith | ff9b662 | 2008-08-14 13:27:16 +0530 | [diff] [blame] | 335 | bf->bf_dmacontext, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 336 | skb->len, |
| 337 | PCI_DMA_TODEVICE); |
| 338 | /* complete this frame */ |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 339 | ath_tx_complete(sc, skb, &tx_status); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 340 | |
| 341 | /* |
| 342 | * Return the list of ath_buf of this mpdu to free queue |
| 343 | */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 344 | spin_lock_irqsave(&sc->tx.txbuflock, flags); |
| 345 | list_splice_tail_init(bf_q, &sc->tx.txbuf); |
| 346 | spin_unlock_irqrestore(&sc->tx.txbuflock, flags); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /* |
| 350 | * queue up a dest/ac pair for tx scheduling |
| 351 | * NB: must be called with txq lock held |
| 352 | */ |
| 353 | |
| 354 | static void ath_tx_queue_tid(struct ath_txq *txq, struct ath_atx_tid *tid) |
| 355 | { |
| 356 | struct ath_atx_ac *ac = tid->ac; |
| 357 | |
| 358 | /* |
| 359 | * if tid is paused, hold off |
| 360 | */ |
| 361 | if (tid->paused) |
| 362 | return; |
| 363 | |
| 364 | /* |
| 365 | * add tid to ac atmost once |
| 366 | */ |
| 367 | if (tid->sched) |
| 368 | return; |
| 369 | |
| 370 | tid->sched = true; |
| 371 | list_add_tail(&tid->list, &ac->tid_q); |
| 372 | |
| 373 | /* |
| 374 | * add node ac to txq atmost once |
| 375 | */ |
| 376 | if (ac->sched) |
| 377 | return; |
| 378 | |
| 379 | ac->sched = true; |
| 380 | list_add_tail(&ac->list, &txq->axq_acq); |
| 381 | } |
| 382 | |
| 383 | /* pause a tid */ |
| 384 | |
| 385 | static void ath_tx_pause_tid(struct ath_softc *sc, struct ath_atx_tid *tid) |
| 386 | { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 387 | struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 388 | |
| 389 | spin_lock_bh(&txq->axq_lock); |
| 390 | |
| 391 | tid->paused++; |
| 392 | |
| 393 | spin_unlock_bh(&txq->axq_lock); |
| 394 | } |
| 395 | |
| 396 | /* resume a tid and schedule aggregate */ |
| 397 | |
| 398 | void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid) |
| 399 | { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 400 | struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 401 | |
| 402 | ASSERT(tid->paused > 0); |
| 403 | spin_lock_bh(&txq->axq_lock); |
| 404 | |
| 405 | tid->paused--; |
| 406 | |
| 407 | if (tid->paused > 0) |
| 408 | goto unlock; |
| 409 | |
| 410 | if (list_empty(&tid->buf_q)) |
| 411 | goto unlock; |
| 412 | |
| 413 | /* |
| 414 | * Add this TID to scheduler and try to send out aggregates |
| 415 | */ |
| 416 | ath_tx_queue_tid(txq, tid); |
| 417 | ath_txq_schedule(sc, txq); |
| 418 | unlock: |
| 419 | spin_unlock_bh(&txq->axq_lock); |
| 420 | } |
| 421 | |
| 422 | /* Compute the number of bad frames */ |
| 423 | |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 424 | static int ath_tx_num_badfrms(struct ath_softc *sc, struct ath_buf *bf, |
| 425 | int txok) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 426 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 427 | struct ath_buf *bf_last = bf->bf_lastbf; |
| 428 | struct ath_desc *ds = bf_last->bf_desc; |
| 429 | u16 seq_st = 0; |
| 430 | u32 ba[WME_BA_BMP_SIZE >> 5]; |
| 431 | int ba_index; |
| 432 | int nbad = 0; |
| 433 | int isaggr = 0; |
| 434 | |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 435 | if (ds->ds_txstat.ts_flags == ATH9K_TX_SW_ABORTED) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 436 | return 0; |
| 437 | |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 438 | isaggr = bf_isaggr(bf); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 439 | if (isaggr) { |
| 440 | seq_st = ATH_DS_BA_SEQ(ds); |
| 441 | memcpy(ba, ATH_DS_BA_BITMAP(ds), WME_BA_BMP_SIZE >> 3); |
| 442 | } |
| 443 | |
| 444 | while (bf) { |
| 445 | ba_index = ATH_BA_INDEX(seq_st, bf->bf_seqno); |
| 446 | if (!txok || (isaggr && !ATH_BA_ISSET(ba, ba_index))) |
| 447 | nbad++; |
| 448 | |
| 449 | bf = bf->bf_next; |
| 450 | } |
| 451 | |
| 452 | return nbad; |
| 453 | } |
| 454 | |
| 455 | static void ath_tx_set_retry(struct ath_softc *sc, struct ath_buf *bf) |
| 456 | { |
| 457 | struct sk_buff *skb; |
| 458 | struct ieee80211_hdr *hdr; |
| 459 | |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 460 | bf->bf_state.bf_type |= BUF_RETRY; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 461 | bf->bf_retries++; |
| 462 | |
| 463 | skb = bf->bf_mpdu; |
| 464 | hdr = (struct ieee80211_hdr *)skb->data; |
| 465 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_RETRY); |
| 466 | } |
| 467 | |
| 468 | /* Update block ack window */ |
| 469 | |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 470 | static void ath_tx_update_baw(struct ath_softc *sc, struct ath_atx_tid *tid, |
| 471 | int seqno) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 472 | { |
| 473 | int index, cindex; |
| 474 | |
| 475 | index = ATH_BA_INDEX(tid->seq_start, seqno); |
| 476 | cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); |
| 477 | |
| 478 | tid->tx_buf[cindex] = NULL; |
| 479 | |
| 480 | while (tid->baw_head != tid->baw_tail && !tid->tx_buf[tid->baw_head]) { |
| 481 | INCR(tid->seq_start, IEEE80211_SEQ_MAX); |
| 482 | INCR(tid->baw_head, ATH_TID_MAX_BUFS); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | /* |
| 487 | * ath_pkt_dur - compute packet duration (NB: not NAV) |
| 488 | * |
| 489 | * rix - rate index |
| 490 | * pktlen - total bytes (delims + data + fcs + pads + pad delims) |
| 491 | * width - 0 for 20 MHz, 1 for 40 MHz |
| 492 | * half_gi - to use 4us v/s 3.6 us for symbol time |
| 493 | */ |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 494 | static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, struct ath_buf *bf, |
| 495 | int width, int half_gi, bool shortPreamble) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 496 | { |
Sujith | 3706de6 | 2008-12-07 21:42:10 +0530 | [diff] [blame] | 497 | struct ath_rate_table *rate_table = sc->cur_rate_table; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 498 | u32 nbits, nsymbits, duration, nsymbols; |
| 499 | u8 rc; |
| 500 | int streams, pktlen; |
| 501 | |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 502 | pktlen = bf_isaggr(bf) ? bf->bf_al : bf->bf_frmlen; |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 503 | rc = rate_table->info[rix].ratecode; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 504 | |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 505 | /* for legacy rates, use old function to compute packet duration */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 506 | if (!IS_HT_RATE(rc)) |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 507 | return ath9k_hw_computetxtime(sc->sc_ah, rate_table, pktlen, |
| 508 | rix, shortPreamble); |
| 509 | |
| 510 | /* find number of symbols: PLCP + data */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 511 | nbits = (pktlen << 3) + OFDM_PLCP_BITS; |
| 512 | nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width]; |
| 513 | nsymbols = (nbits + nsymbits - 1) / nsymbits; |
| 514 | |
| 515 | if (!half_gi) |
| 516 | duration = SYMBOL_TIME(nsymbols); |
| 517 | else |
| 518 | duration = SYMBOL_TIME_HALFGI(nsymbols); |
| 519 | |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 520 | /* addup duration for legacy/ht training and signal fields */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 521 | streams = HT_RC_2_STREAMS(rc); |
| 522 | 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] | 523 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 524 | return duration; |
| 525 | } |
| 526 | |
| 527 | /* Rate module function to set rate related fields in tx descriptor */ |
| 528 | |
| 529 | static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf) |
| 530 | { |
| 531 | struct ath_hal *ah = sc->sc_ah; |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 532 | struct ath_rate_table *rt; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 533 | struct ath_desc *ds = bf->bf_desc; |
| 534 | struct ath_desc *lastds = bf->bf_lastbf->bf_desc; |
| 535 | struct ath9k_11n_rate_series series[4]; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 536 | struct sk_buff *skb; |
| 537 | struct ieee80211_tx_info *tx_info; |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 538 | struct ieee80211_tx_rate *rates; |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 539 | struct ieee80211_hdr *hdr; |
| 540 | int i, flags, rtsctsena = 0; |
| 541 | u32 ctsduration = 0; |
| 542 | u8 rix = 0, cix, ctsrate = 0; |
| 543 | __le16 fc; |
| 544 | |
| 545 | memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 546 | |
| 547 | skb = (struct sk_buff *)bf->bf_mpdu; |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 548 | hdr = (struct ieee80211_hdr *)skb->data; |
| 549 | fc = hdr->frame_control; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 550 | tx_info = IEEE80211_SKB_CB(skb); |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 551 | rates = tx_info->control.rates; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 552 | |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 553 | if (ieee80211_has_morefrags(fc) || |
| 554 | (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG)) { |
| 555 | rates[1].count = rates[2].count = rates[3].count = 0; |
| 556 | rates[1].idx = rates[2].idx = rates[3].idx = 0; |
| 557 | rates[0].count = ATH_TXMAXTRY; |
| 558 | } |
| 559 | |
| 560 | /* get the cix for the lowest valid rix */ |
Sujith | 3706de6 | 2008-12-07 21:42:10 +0530 | [diff] [blame] | 561 | rt = sc->cur_rate_table; |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 562 | for (i = 3; i >= 0; i--) { |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 563 | if (rates[i].count && (rates[i].idx >= 0)) { |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 564 | rix = rates[i].idx; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 565 | break; |
| 566 | } |
| 567 | } |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 568 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 569 | flags = (bf->bf_flags & (ATH9K_TXDESC_RTSENA | ATH9K_TXDESC_CTSENA)); |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 570 | cix = rt->info[rix].ctrl_rate; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 571 | |
| 572 | /* |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 573 | * If 802.11g protection is enabled, determine whether to use RTS/CTS or |
| 574 | * just CTS. Note that this is only done for OFDM/HT unicast frames. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 575 | */ |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 576 | if (sc->sc_protmode != PROT_M_NONE && !(bf->bf_flags & ATH9K_TXDESC_NOACK) |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 577 | && (rt->info[rix].phy == WLAN_RC_PHY_OFDM || |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 578 | WLAN_RC_PHY_HT(rt->info[rix].phy))) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 579 | if (sc->sc_protmode == PROT_M_RTSCTS) |
| 580 | flags = ATH9K_TXDESC_RTSENA; |
| 581 | else if (sc->sc_protmode == PROT_M_CTSONLY) |
| 582 | flags = ATH9K_TXDESC_CTSENA; |
| 583 | |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 584 | cix = rt->info[sc->sc_protrix].ctrl_rate; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 585 | rtsctsena = 1; |
| 586 | } |
| 587 | |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 588 | /* For 11n, the default behavior is to enable RTS for hw retried frames. |
| 589 | * We enable the global flag here and let rate series flags determine |
| 590 | * which rates will actually use RTS. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 591 | */ |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 592 | if ((ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) && bf_isdata(bf)) { |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 593 | /* 802.11g protection not needed, use our default behavior */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 594 | if (!rtsctsena) |
| 595 | flags = ATH9K_TXDESC_RTSENA; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 598 | /* Set protection if aggregate protection on */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 599 | if (sc->sc_config.ath_aggr_prot && |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 600 | (!bf_isaggr(bf) || (bf_isaggr(bf) && bf->bf_al < 8192))) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 601 | flags = ATH9K_TXDESC_RTSENA; |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 602 | cix = rt->info[sc->sc_protrix].ctrl_rate; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 603 | rtsctsena = 1; |
| 604 | } |
| 605 | |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 606 | /* For AR5416 - RTS cannot be followed by a frame larger than 8K */ |
| 607 | if (bf_isaggr(bf) && (bf->bf_al > ah->ah_caps.rts_aggr_limit)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 608 | flags &= ~(ATH9K_TXDESC_RTSENA); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 609 | |
| 610 | /* |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 611 | * CTS transmit rate is derived from the transmit rate by looking in the |
| 612 | * h/w rate table. We must also factor in whether or not a short |
| 613 | * preamble is to be used. NB: cix is set above where RTS/CTS is enabled |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 614 | */ |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 615 | ctsrate = rt->info[cix].ratecode | |
| 616 | (bf_isshpreamble(bf) ? rt->info[cix].short_preamble : 0); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 617 | |
| 618 | for (i = 0; i < 4; i++) { |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 619 | if (!rates[i].count || (rates[i].idx < 0)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 620 | continue; |
| 621 | |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 622 | rix = rates[i].idx; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 623 | |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 624 | series[i].Rate = rt->info[rix].ratecode | |
| 625 | (bf_isshpreamble(bf) ? rt->info[rix].short_preamble : 0); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 626 | |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 627 | series[i].Tries = rates[i].count; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 628 | |
| 629 | series[i].RateFlags = ( |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 630 | (rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) ? |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 631 | ATH9K_RATESERIES_RTS_CTS : 0) | |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 632 | ((rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 633 | ATH9K_RATESERIES_2040 : 0) | |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 634 | ((rates[i].flags & IEEE80211_TX_RC_SHORT_GI) ? |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 635 | ATH9K_RATESERIES_HALFGI : 0); |
| 636 | |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 637 | series[i].PktDuration = ath_pkt_duration(sc, rix, bf, |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 638 | (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) != 0, |
| 639 | (rates[i].flags & IEEE80211_TX_RC_SHORT_GI), |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 640 | bf_isshpreamble(bf)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 641 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 642 | series[i].ChSel = sc->sc_tx_chainmask; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 643 | |
| 644 | if (rtsctsena) |
| 645 | series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 648 | /* set dur_update_en for l-sig computation except for PS-Poll frames */ |
| 649 | ath9k_hw_set11n_ratescenario(ah, ds, lastds, !bf_ispspoll(bf), |
| 650 | ctsrate, ctsduration, |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 651 | series, 4, flags); |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 652 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 653 | if (sc->sc_config.ath_aggr_prot && flags) |
| 654 | ath9k_hw_set11n_burstduration(ah, ds, 8192); |
| 655 | } |
| 656 | |
| 657 | /* |
| 658 | * Function to send a normal HT (non-AMPDU) frame |
| 659 | * NB: must be called with txq lock held |
| 660 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 661 | static int ath_tx_send_normal(struct ath_softc *sc, |
| 662 | struct ath_txq *txq, |
| 663 | struct ath_atx_tid *tid, |
| 664 | struct list_head *bf_head) |
| 665 | { |
| 666 | struct ath_buf *bf; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 667 | |
| 668 | BUG_ON(list_empty(bf_head)); |
| 669 | |
| 670 | bf = list_first_entry(bf_head, struct ath_buf, list); |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 671 | bf->bf_state.bf_type &= ~BUF_AMPDU; /* regular HT frame */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 672 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 673 | /* update starting sequence number for subsequent ADDBA request */ |
| 674 | INCR(tid->seq_start, IEEE80211_SEQ_MAX); |
| 675 | |
| 676 | /* Queue to h/w without aggregation */ |
| 677 | bf->bf_nframes = 1; |
| 678 | bf->bf_lastbf = bf->bf_lastfrm; /* one single frame */ |
| 679 | ath_buf_set_rate(sc, bf); |
| 680 | ath_tx_txqaddbuf(sc, txq, bf_head); |
| 681 | |
| 682 | return 0; |
| 683 | } |
| 684 | |
| 685 | /* flush tid's software queue and send frames as non-ampdu's */ |
| 686 | |
| 687 | static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid) |
| 688 | { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 689 | struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 690 | struct ath_buf *bf; |
| 691 | struct list_head bf_head; |
| 692 | INIT_LIST_HEAD(&bf_head); |
| 693 | |
| 694 | ASSERT(tid->paused > 0); |
| 695 | spin_lock_bh(&txq->axq_lock); |
| 696 | |
| 697 | tid->paused--; |
| 698 | |
| 699 | if (tid->paused > 0) { |
| 700 | spin_unlock_bh(&txq->axq_lock); |
| 701 | return; |
| 702 | } |
| 703 | |
| 704 | while (!list_empty(&tid->buf_q)) { |
| 705 | bf = list_first_entry(&tid->buf_q, struct ath_buf, list); |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 706 | ASSERT(!bf_isretried(bf)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 707 | list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list); |
| 708 | ath_tx_send_normal(sc, txq, tid, &bf_head); |
| 709 | } |
| 710 | |
| 711 | spin_unlock_bh(&txq->axq_lock); |
| 712 | } |
| 713 | |
| 714 | /* Completion routine of an aggregate */ |
| 715 | |
| 716 | static void ath_tx_complete_aggr_rifs(struct ath_softc *sc, |
| 717 | struct ath_txq *txq, |
| 718 | struct ath_buf *bf, |
| 719 | struct list_head *bf_q, |
| 720 | int txok) |
| 721 | { |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 722 | struct ath_node *an = NULL; |
| 723 | struct sk_buff *skb; |
| 724 | struct ieee80211_tx_info *tx_info; |
| 725 | struct ath_atx_tid *tid = NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 726 | struct ath_buf *bf_last = bf->bf_lastbf; |
| 727 | struct ath_desc *ds = bf_last->bf_desc; |
| 728 | struct ath_buf *bf_next, *bf_lastq = NULL; |
| 729 | struct list_head bf_head, bf_pending; |
| 730 | u16 seq_st = 0; |
| 731 | u32 ba[WME_BA_BMP_SIZE >> 5]; |
| 732 | int isaggr, txfail, txpending, sendbar = 0, needreset = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 733 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 734 | skb = (struct sk_buff *)bf->bf_mpdu; |
| 735 | tx_info = IEEE80211_SKB_CB(skb); |
| 736 | |
| 737 | if (tx_info->control.sta) { |
| 738 | an = (struct ath_node *)tx_info->control.sta->drv_priv; |
| 739 | tid = ATH_AN_2_TID(an, bf->bf_tidno); |
| 740 | } |
| 741 | |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 742 | isaggr = bf_isaggr(bf); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 743 | if (isaggr) { |
| 744 | if (txok) { |
| 745 | if (ATH_DS_TX_BA(ds)) { |
| 746 | /* |
| 747 | * extract starting sequence and |
| 748 | * block-ack bitmap |
| 749 | */ |
| 750 | seq_st = ATH_DS_BA_SEQ(ds); |
| 751 | memcpy(ba, |
| 752 | ATH_DS_BA_BITMAP(ds), |
| 753 | WME_BA_BMP_SIZE >> 3); |
| 754 | } else { |
Luis R. Rodriguez | 0345f37 | 2008-10-03 15:45:25 -0700 | [diff] [blame] | 755 | memset(ba, 0, WME_BA_BMP_SIZE >> 3); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 756 | |
| 757 | /* |
| 758 | * AR5416 can become deaf/mute when BA |
| 759 | * issue happens. Chip needs to be reset. |
| 760 | * But AP code may have sychronization issues |
| 761 | * when perform internal reset in this routine. |
| 762 | * Only enable reset in STA mode for now. |
| 763 | */ |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 764 | if (sc->sc_ah->ah_opmode == |
| 765 | NL80211_IFTYPE_STATION) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 766 | needreset = 1; |
| 767 | } |
| 768 | } else { |
Luis R. Rodriguez | 0345f37 | 2008-10-03 15:45:25 -0700 | [diff] [blame] | 769 | memset(ba, 0, WME_BA_BMP_SIZE >> 3); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 770 | } |
| 771 | } |
| 772 | |
| 773 | INIT_LIST_HEAD(&bf_pending); |
| 774 | INIT_LIST_HEAD(&bf_head); |
| 775 | |
| 776 | while (bf) { |
| 777 | txfail = txpending = 0; |
| 778 | bf_next = bf->bf_next; |
| 779 | |
| 780 | if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, bf->bf_seqno))) { |
| 781 | /* transmit completion, subframe is |
| 782 | * acked by block ack */ |
| 783 | } else if (!isaggr && txok) { |
| 784 | /* transmit completion */ |
| 785 | } else { |
| 786 | |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 787 | if (!(tid->state & AGGR_CLEANUP) && |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 788 | ds->ds_txstat.ts_flags != ATH9K_TX_SW_ABORTED) { |
| 789 | if (bf->bf_retries < ATH_MAX_SW_RETRIES) { |
| 790 | ath_tx_set_retry(sc, bf); |
| 791 | txpending = 1; |
| 792 | } else { |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 793 | bf->bf_state.bf_type |= BUF_XRETRY; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 794 | txfail = 1; |
| 795 | sendbar = 1; |
| 796 | } |
| 797 | } else { |
| 798 | /* |
| 799 | * cleanup in progress, just fail |
| 800 | * the un-acked sub-frames |
| 801 | */ |
| 802 | txfail = 1; |
| 803 | } |
| 804 | } |
| 805 | /* |
| 806 | * Remove ath_buf's of this sub-frame from aggregate queue. |
| 807 | */ |
| 808 | if (bf_next == NULL) { /* last subframe in the aggregate */ |
| 809 | ASSERT(bf->bf_lastfrm == bf_last); |
| 810 | |
| 811 | /* |
| 812 | * The last descriptor of the last sub frame could be |
| 813 | * a holding descriptor for h/w. If that's the case, |
| 814 | * bf->bf_lastfrm won't be in the bf_q. |
| 815 | * Make sure we handle bf_q properly here. |
| 816 | */ |
| 817 | |
| 818 | if (!list_empty(bf_q)) { |
| 819 | bf_lastq = list_entry(bf_q->prev, |
| 820 | struct ath_buf, list); |
| 821 | list_cut_position(&bf_head, |
| 822 | bf_q, &bf_lastq->list); |
| 823 | } else { |
| 824 | /* |
| 825 | * XXX: if the last subframe only has one |
| 826 | * descriptor which is also being used as |
| 827 | * a holding descriptor. Then the ath_buf |
| 828 | * is not in the bf_q at all. |
| 829 | */ |
| 830 | INIT_LIST_HEAD(&bf_head); |
| 831 | } |
| 832 | } else { |
| 833 | ASSERT(!list_empty(bf_q)); |
| 834 | list_cut_position(&bf_head, |
| 835 | bf_q, &bf->bf_lastfrm->list); |
| 836 | } |
| 837 | |
| 838 | if (!txpending) { |
| 839 | /* |
| 840 | * complete the acked-ones/xretried ones; update |
| 841 | * block-ack window |
| 842 | */ |
| 843 | spin_lock_bh(&txq->axq_lock); |
| 844 | ath_tx_update_baw(sc, tid, bf->bf_seqno); |
| 845 | spin_unlock_bh(&txq->axq_lock); |
| 846 | |
| 847 | /* complete this sub-frame */ |
| 848 | ath_tx_complete_buf(sc, bf, &bf_head, !txfail, sendbar); |
| 849 | } else { |
| 850 | /* |
| 851 | * retry the un-acked ones |
| 852 | */ |
| 853 | /* |
| 854 | * XXX: if the last descriptor is holding descriptor, |
| 855 | * in order to requeue the frame to software queue, we |
| 856 | * need to allocate a new descriptor and |
| 857 | * copy the content of holding descriptor to it. |
| 858 | */ |
| 859 | if (bf->bf_next == NULL && |
| 860 | bf_last->bf_status & ATH_BUFSTATUS_STALE) { |
| 861 | struct ath_buf *tbf; |
| 862 | |
| 863 | /* allocate new descriptor */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 864 | spin_lock_bh(&sc->tx.txbuflock); |
| 865 | ASSERT(!list_empty((&sc->tx.txbuf))); |
| 866 | tbf = list_first_entry(&sc->tx.txbuf, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 867 | struct ath_buf, list); |
| 868 | list_del(&tbf->list); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 869 | spin_unlock_bh(&sc->tx.txbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 870 | |
| 871 | ATH_TXBUF_RESET(tbf); |
| 872 | |
| 873 | /* copy descriptor content */ |
| 874 | tbf->bf_mpdu = bf_last->bf_mpdu; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 875 | tbf->bf_buf_addr = bf_last->bf_buf_addr; |
| 876 | *(tbf->bf_desc) = *(bf_last->bf_desc); |
| 877 | |
| 878 | /* link it to the frame */ |
| 879 | if (bf_lastq) { |
| 880 | bf_lastq->bf_desc->ds_link = |
| 881 | tbf->bf_daddr; |
| 882 | bf->bf_lastfrm = tbf; |
| 883 | ath9k_hw_cleartxdesc(sc->sc_ah, |
| 884 | bf->bf_lastfrm->bf_desc); |
| 885 | } else { |
| 886 | tbf->bf_state = bf_last->bf_state; |
| 887 | tbf->bf_lastfrm = tbf; |
| 888 | ath9k_hw_cleartxdesc(sc->sc_ah, |
| 889 | tbf->bf_lastfrm->bf_desc); |
| 890 | |
| 891 | /* copy the DMA context */ |
Sujith | ff9b662 | 2008-08-14 13:27:16 +0530 | [diff] [blame] | 892 | tbf->bf_dmacontext = |
| 893 | bf_last->bf_dmacontext; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 894 | } |
| 895 | list_add_tail(&tbf->list, &bf_head); |
| 896 | } else { |
| 897 | /* |
| 898 | * Clear descriptor status words for |
| 899 | * software retry |
| 900 | */ |
| 901 | ath9k_hw_cleartxdesc(sc->sc_ah, |
Sujith | ff9b662 | 2008-08-14 13:27:16 +0530 | [diff] [blame] | 902 | bf->bf_lastfrm->bf_desc); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | /* |
| 906 | * Put this buffer to the temporary pending |
| 907 | * queue to retain ordering |
| 908 | */ |
| 909 | list_splice_tail_init(&bf_head, &bf_pending); |
| 910 | } |
| 911 | |
| 912 | bf = bf_next; |
| 913 | } |
| 914 | |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 915 | if (tid->state & AGGR_CLEANUP) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 916 | /* check to see if we're done with cleaning the h/w queue */ |
| 917 | spin_lock_bh(&txq->axq_lock); |
| 918 | |
| 919 | if (tid->baw_head == tid->baw_tail) { |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 920 | tid->state &= ~AGGR_ADDBA_COMPLETE; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 921 | tid->addba_exchangeattempts = 0; |
| 922 | spin_unlock_bh(&txq->axq_lock); |
| 923 | |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 924 | tid->state &= ~AGGR_CLEANUP; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 925 | |
| 926 | /* send buffered frames as singles */ |
| 927 | ath_tx_flush_tid(sc, tid); |
| 928 | } else |
| 929 | spin_unlock_bh(&txq->axq_lock); |
| 930 | |
| 931 | return; |
| 932 | } |
| 933 | |
| 934 | /* |
| 935 | * prepend un-acked frames to the beginning of the pending frame queue |
| 936 | */ |
| 937 | if (!list_empty(&bf_pending)) { |
| 938 | spin_lock_bh(&txq->axq_lock); |
| 939 | /* Note: we _prepend_, we _do_not_ at to |
| 940 | * the end of the queue ! */ |
| 941 | list_splice(&bf_pending, &tid->buf_q); |
| 942 | ath_tx_queue_tid(txq, tid); |
| 943 | spin_unlock_bh(&txq->axq_lock); |
| 944 | } |
| 945 | |
| 946 | if (needreset) |
Sujith | f45144e | 2008-08-11 14:02:53 +0530 | [diff] [blame] | 947 | ath_reset(sc, false); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 948 | |
| 949 | return; |
| 950 | } |
| 951 | |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 952 | static void ath_tx_rc_status(struct ath_buf *bf, struct ath_desc *ds, int nbad) |
| 953 | { |
| 954 | struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu; |
| 955 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 956 | struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info); |
| 957 | |
Vasanthakumar Thiagarajan | 7ac4701 | 2008-11-20 11:51:18 +0530 | [diff] [blame] | 958 | tx_info_priv->update_rc = false; |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 959 | if (ds->ds_txstat.ts_status & ATH9K_TXERR_FILT) |
| 960 | tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED; |
| 961 | |
| 962 | if ((ds->ds_txstat.ts_status & ATH9K_TXERR_FILT) == 0 && |
| 963 | (bf->bf_flags & ATH9K_TXDESC_NOACK) == 0) { |
| 964 | if (bf_isdata(bf)) { |
| 965 | memcpy(&tx_info_priv->tx, &ds->ds_txstat, |
| 966 | sizeof(tx_info_priv->tx)); |
| 967 | tx_info_priv->n_frames = bf->bf_nframes; |
| 968 | tx_info_priv->n_bad_frames = nbad; |
Vasanthakumar Thiagarajan | 7ac4701 | 2008-11-20 11:51:18 +0530 | [diff] [blame] | 969 | tx_info_priv->update_rc = true; |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | } |
| 973 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 974 | /* Process completed xmit descriptors from the specified queue */ |
| 975 | |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 976 | 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] | 977 | { |
| 978 | struct ath_hal *ah = sc->sc_ah; |
| 979 | struct ath_buf *bf, *lastbf, *bf_held = NULL; |
| 980 | struct list_head bf_head; |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 981 | struct ath_desc *ds; |
| 982 | int txok, nbad = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 983 | int status; |
| 984 | |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 985 | DPRINTF(sc, ATH_DBG_QUEUE, "tx queue %d (%x), link %p\n", |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 986 | txq->axq_qnum, ath9k_hw_gettxbuf(sc->sc_ah, txq->axq_qnum), |
| 987 | txq->axq_link); |
| 988 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 989 | for (;;) { |
| 990 | spin_lock_bh(&txq->axq_lock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 991 | if (list_empty(&txq->axq_q)) { |
| 992 | txq->axq_link = NULL; |
| 993 | txq->axq_linkbuf = NULL; |
| 994 | spin_unlock_bh(&txq->axq_lock); |
| 995 | break; |
| 996 | } |
| 997 | bf = list_first_entry(&txq->axq_q, struct ath_buf, list); |
| 998 | |
| 999 | /* |
| 1000 | * There is a race condition that a BH gets scheduled |
| 1001 | * after sw writes TxE and before hw re-load the last |
| 1002 | * descriptor to get the newly chained one. |
| 1003 | * Software must keep the last DONE descriptor as a |
| 1004 | * holding descriptor - software does so by marking |
| 1005 | * it with the STALE flag. |
| 1006 | */ |
| 1007 | bf_held = NULL; |
| 1008 | if (bf->bf_status & ATH_BUFSTATUS_STALE) { |
| 1009 | bf_held = bf; |
| 1010 | if (list_is_last(&bf_held->list, &txq->axq_q)) { |
| 1011 | /* FIXME: |
| 1012 | * The holding descriptor is the last |
| 1013 | * descriptor in queue. It's safe to remove |
| 1014 | * the last holding descriptor in BH context. |
| 1015 | */ |
| 1016 | spin_unlock_bh(&txq->axq_lock); |
| 1017 | break; |
| 1018 | } else { |
| 1019 | /* Lets work with the next buffer now */ |
| 1020 | bf = list_entry(bf_held->list.next, |
| 1021 | struct ath_buf, list); |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | lastbf = bf->bf_lastbf; |
| 1026 | ds = lastbf->bf_desc; /* NB: last decriptor */ |
| 1027 | |
| 1028 | status = ath9k_hw_txprocdesc(ah, ds); |
| 1029 | if (status == -EINPROGRESS) { |
| 1030 | spin_unlock_bh(&txq->axq_lock); |
| 1031 | break; |
| 1032 | } |
| 1033 | if (bf->bf_desc == txq->axq_lastdsWithCTS) |
| 1034 | txq->axq_lastdsWithCTS = NULL; |
| 1035 | if (ds == txq->axq_gatingds) |
| 1036 | txq->axq_gatingds = NULL; |
| 1037 | |
| 1038 | /* |
| 1039 | * Remove ath_buf's of the same transmit unit from txq, |
| 1040 | * however leave the last descriptor back as the holding |
| 1041 | * descriptor for hw. |
| 1042 | */ |
| 1043 | lastbf->bf_status |= ATH_BUFSTATUS_STALE; |
| 1044 | INIT_LIST_HEAD(&bf_head); |
| 1045 | |
| 1046 | if (!list_is_singular(&lastbf->list)) |
| 1047 | list_cut_position(&bf_head, |
| 1048 | &txq->axq_q, lastbf->list.prev); |
| 1049 | |
| 1050 | txq->axq_depth--; |
| 1051 | |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 1052 | if (bf_isaggr(bf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1053 | txq->axq_aggr_depth--; |
| 1054 | |
| 1055 | txok = (ds->ds_txstat.ts_status == 0); |
| 1056 | |
| 1057 | spin_unlock_bh(&txq->axq_lock); |
| 1058 | |
| 1059 | if (bf_held) { |
| 1060 | list_del(&bf_held->list); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1061 | spin_lock_bh(&sc->tx.txbuflock); |
| 1062 | list_add_tail(&bf_held->list, &sc->tx.txbuf); |
| 1063 | spin_unlock_bh(&sc->tx.txbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 1066 | if (!bf_isampdu(bf)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1067 | /* |
| 1068 | * This frame is sent out as a single frame. |
| 1069 | * Use hardware retry status for this frame. |
| 1070 | */ |
| 1071 | bf->bf_retries = ds->ds_txstat.ts_longretry; |
| 1072 | if (ds->ds_txstat.ts_status & ATH9K_TXERR_XRETRY) |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 1073 | bf->bf_state.bf_type |= BUF_XRETRY; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1074 | nbad = 0; |
| 1075 | } else { |
| 1076 | nbad = ath_tx_num_badfrms(sc, bf, txok); |
| 1077 | } |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1078 | |
Sujith | c428839 | 2008-11-18 09:09:30 +0530 | [diff] [blame] | 1079 | ath_tx_rc_status(bf, ds, nbad); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1080 | |
| 1081 | /* |
| 1082 | * Complete this transmit unit |
| 1083 | */ |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 1084 | if (bf_isampdu(bf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1085 | ath_tx_complete_aggr_rifs(sc, txq, bf, &bf_head, txok); |
| 1086 | else |
| 1087 | ath_tx_complete_buf(sc, bf, &bf_head, txok, 0); |
| 1088 | |
| 1089 | /* Wake up mac80211 queue */ |
| 1090 | |
| 1091 | spin_lock_bh(&txq->axq_lock); |
| 1092 | if (txq->stopped && ath_txq_depth(sc, txq->axq_qnum) <= |
| 1093 | (ATH_TXBUF - 20)) { |
| 1094 | int qnum; |
| 1095 | qnum = ath_get_mac80211_qnum(txq->axq_qnum, sc); |
| 1096 | if (qnum != -1) { |
| 1097 | ieee80211_wake_queue(sc->hw, qnum); |
| 1098 | txq->stopped = 0; |
| 1099 | } |
| 1100 | |
| 1101 | } |
| 1102 | |
| 1103 | /* |
| 1104 | * schedule any pending packets if aggregation is enabled |
| 1105 | */ |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 1106 | if (sc->sc_flags & SC_OP_TXAGGR) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1107 | ath_txq_schedule(sc, txq); |
| 1108 | spin_unlock_bh(&txq->axq_lock); |
| 1109 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | static void ath_tx_stopdma(struct ath_softc *sc, struct ath_txq *txq) |
| 1113 | { |
| 1114 | struct ath_hal *ah = sc->sc_ah; |
| 1115 | |
| 1116 | (void) ath9k_hw_stoptxdma(ah, txq->axq_qnum); |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1117 | DPRINTF(sc, ATH_DBG_XMIT, "tx queue [%u] %x, link %p\n", |
| 1118 | txq->axq_qnum, ath9k_hw_gettxbuf(ah, txq->axq_qnum), |
| 1119 | txq->axq_link); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | /* Drain only the data queues */ |
| 1123 | |
| 1124 | static void ath_drain_txdataq(struct ath_softc *sc, bool retry_tx) |
| 1125 | { |
| 1126 | struct ath_hal *ah = sc->sc_ah; |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 1127 | int i, status, npend = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1128 | |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 1129 | if (!(sc->sc_flags & SC_OP_INVALID)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1130 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { |
| 1131 | if (ATH_TXQ_SETUP(sc, i)) { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1132 | ath_tx_stopdma(sc, &sc->tx.txq[i]); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1133 | /* The TxDMA may not really be stopped. |
| 1134 | * Double check the hal tx pending count */ |
| 1135 | npend += ath9k_hw_numtxpending(ah, |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1136 | sc->tx.txq[i].axq_qnum); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | if (npend) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1142 | /* TxDMA not stopped, reset the hal */ |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1143 | DPRINTF(sc, ATH_DBG_XMIT, "Unable to stop TxDMA. Reset HAL!\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1144 | |
| 1145 | spin_lock_bh(&sc->sc_resetlock); |
Sujith | b4696c8b | 2008-08-11 14:04:52 +0530 | [diff] [blame] | 1146 | if (!ath9k_hw_reset(ah, |
Sujith | 927e70e | 2008-08-14 13:26:34 +0530 | [diff] [blame] | 1147 | sc->sc_ah->ah_curchan, |
Sujith | 99405f9 | 2008-11-24 12:08:35 +0530 | [diff] [blame] | 1148 | sc->tx_chan_width, |
Sujith | 927e70e | 2008-08-14 13:26:34 +0530 | [diff] [blame] | 1149 | sc->sc_tx_chainmask, sc->sc_rx_chainmask, |
| 1150 | sc->sc_ht_extprotspacing, true, &status)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1151 | |
| 1152 | DPRINTF(sc, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1153 | "Unable to reset hardware; hal status %u\n", |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1154 | status); |
| 1155 | } |
| 1156 | spin_unlock_bh(&sc->sc_resetlock); |
| 1157 | } |
| 1158 | |
| 1159 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { |
| 1160 | if (ATH_TXQ_SETUP(sc, i)) |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1161 | ath_tx_draintxq(sc, &sc->tx.txq[i], retry_tx); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | /* Add a sub-frame to block ack window */ |
| 1166 | |
| 1167 | static void ath_tx_addto_baw(struct ath_softc *sc, |
| 1168 | struct ath_atx_tid *tid, |
| 1169 | struct ath_buf *bf) |
| 1170 | { |
| 1171 | int index, cindex; |
| 1172 | |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 1173 | if (bf_isretried(bf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1174 | return; |
| 1175 | |
| 1176 | index = ATH_BA_INDEX(tid->seq_start, bf->bf_seqno); |
| 1177 | cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1); |
| 1178 | |
| 1179 | ASSERT(tid->tx_buf[cindex] == NULL); |
| 1180 | tid->tx_buf[cindex] = bf; |
| 1181 | |
| 1182 | if (index >= ((tid->baw_tail - tid->baw_head) & |
| 1183 | (ATH_TID_MAX_BUFS - 1))) { |
| 1184 | tid->baw_tail = cindex; |
| 1185 | INCR(tid->baw_tail, ATH_TID_MAX_BUFS); |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | /* |
| 1190 | * Function to send an A-MPDU |
| 1191 | * NB: must be called with txq lock held |
| 1192 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1193 | static int ath_tx_send_ampdu(struct ath_softc *sc, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1194 | struct ath_atx_tid *tid, |
| 1195 | struct list_head *bf_head, |
| 1196 | struct ath_tx_control *txctl) |
| 1197 | { |
| 1198 | struct ath_buf *bf; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1199 | |
| 1200 | BUG_ON(list_empty(bf_head)); |
| 1201 | |
| 1202 | bf = list_first_entry(bf_head, struct ath_buf, list); |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 1203 | bf->bf_state.bf_type |= BUF_AMPDU; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1204 | |
| 1205 | /* |
| 1206 | * Do not queue to h/w when any of the following conditions is true: |
| 1207 | * - there are pending frames in software queue |
| 1208 | * - the TID is currently paused for ADDBA/BAR request |
| 1209 | * - seqno is not within block-ack window |
| 1210 | * - h/w queue depth exceeds low water mark |
| 1211 | */ |
| 1212 | if (!list_empty(&tid->buf_q) || tid->paused || |
| 1213 | !BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno) || |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1214 | txctl->txq->axq_depth >= ATH_AGGR_MIN_QDEPTH) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1215 | /* |
| 1216 | * Add this frame to software queue for scheduling later |
| 1217 | * for aggregation. |
| 1218 | */ |
| 1219 | list_splice_tail_init(bf_head, &tid->buf_q); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1220 | ath_tx_queue_tid(txctl->txq, tid); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1221 | return 0; |
| 1222 | } |
| 1223 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1224 | /* Add sub-frame to BAW */ |
| 1225 | ath_tx_addto_baw(sc, tid, bf); |
| 1226 | |
| 1227 | /* Queue to h/w without aggregation */ |
| 1228 | bf->bf_nframes = 1; |
| 1229 | bf->bf_lastbf = bf->bf_lastfrm; /* one single frame */ |
| 1230 | ath_buf_set_rate(sc, bf); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1231 | ath_tx_txqaddbuf(sc, txctl->txq, bf_head); |
Sujith | 102e057 | 2008-10-29 10:15:16 +0530 | [diff] [blame] | 1232 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1233 | return 0; |
| 1234 | } |
| 1235 | |
| 1236 | /* |
| 1237 | * looks up the rate |
| 1238 | * returns aggr limit based on lowest of the rates |
| 1239 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1240 | static u32 ath_lookup_rate(struct ath_softc *sc, |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1241 | struct ath_buf *bf, |
| 1242 | struct ath_atx_tid *tid) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1243 | { |
Sujith | 3706de6 | 2008-12-07 21:42:10 +0530 | [diff] [blame] | 1244 | struct ath_rate_table *rate_table = sc->cur_rate_table; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1245 | struct sk_buff *skb; |
| 1246 | struct ieee80211_tx_info *tx_info; |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 1247 | struct ieee80211_tx_rate *rates; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1248 | struct ath_tx_info_priv *tx_info_priv; |
| 1249 | u32 max_4ms_framelen, frame_length; |
| 1250 | u16 aggr_limit, legacy = 0, maxampdu; |
| 1251 | int i; |
| 1252 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1253 | skb = (struct sk_buff *)bf->bf_mpdu; |
| 1254 | tx_info = IEEE80211_SKB_CB(skb); |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 1255 | rates = tx_info->control.rates; |
| 1256 | tx_info_priv = |
| 1257 | (struct ath_tx_info_priv *)tx_info->rate_driver_data[0]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1258 | |
| 1259 | /* |
| 1260 | * Find the lowest frame length among the rate series that will have a |
| 1261 | * 4ms transmit duration. |
| 1262 | * TODO - TXOP limit needs to be considered. |
| 1263 | */ |
| 1264 | max_4ms_framelen = ATH_AMPDU_LIMIT_MAX; |
| 1265 | |
| 1266 | for (i = 0; i < 4; i++) { |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 1267 | if (rates[i].count) { |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 1268 | if (!WLAN_RC_PHY_HT(rate_table->info[rates[i].idx].phy)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1269 | legacy = 1; |
| 1270 | break; |
| 1271 | } |
| 1272 | |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 1273 | frame_length = |
| 1274 | rate_table->info[rates[i].idx].max_4ms_framelen; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1275 | max_4ms_framelen = min(max_4ms_framelen, frame_length); |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | /* |
| 1280 | * limit aggregate size by the minimum rate if rate selected is |
| 1281 | * not a probe rate, if rate selected is a probe rate then |
| 1282 | * avoid aggregation of this packet. |
| 1283 | */ |
| 1284 | if (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE || legacy) |
| 1285 | return 0; |
| 1286 | |
| 1287 | aggr_limit = min(max_4ms_framelen, |
| 1288 | (u32)ATH_AMPDU_LIMIT_DEFAULT); |
| 1289 | |
| 1290 | /* |
| 1291 | * h/w can accept aggregates upto 16 bit lengths (65535). |
| 1292 | * The IE, however can hold upto 65536, which shows up here |
| 1293 | * as zero. Ignore 65536 since we are constrained by hw. |
| 1294 | */ |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1295 | maxampdu = tid->an->maxampdu; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1296 | if (maxampdu) |
| 1297 | aggr_limit = min(aggr_limit, maxampdu); |
| 1298 | |
| 1299 | return aggr_limit; |
| 1300 | } |
| 1301 | |
| 1302 | /* |
| 1303 | * returns the number of delimiters to be added to |
| 1304 | * meet the minimum required mpdudensity. |
| 1305 | * caller should make sure that the rate is HT rate . |
| 1306 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1307 | static int ath_compute_num_delims(struct ath_softc *sc, |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1308 | struct ath_atx_tid *tid, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1309 | struct ath_buf *bf, |
| 1310 | u16 frmlen) |
| 1311 | { |
Sujith | 3706de6 | 2008-12-07 21:42:10 +0530 | [diff] [blame] | 1312 | struct ath_rate_table *rt = sc->cur_rate_table; |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 1313 | struct sk_buff *skb = bf->bf_mpdu; |
| 1314 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1315 | u32 nsymbits, nsymbols, mpdudensity; |
| 1316 | u16 minlen; |
| 1317 | u8 rc, flags, rix; |
| 1318 | int width, half_gi, ndelim, mindelim; |
| 1319 | |
| 1320 | /* Select standard number of delimiters based on frame length alone */ |
| 1321 | ndelim = ATH_AGGR_GET_NDELIM(frmlen); |
| 1322 | |
| 1323 | /* |
| 1324 | * If encryption enabled, hardware requires some more padding between |
| 1325 | * subframes. |
| 1326 | * TODO - this could be improved to be dependent on the rate. |
| 1327 | * The hardware can keep up at lower rates, but not higher rates |
| 1328 | */ |
| 1329 | if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR) |
| 1330 | ndelim += ATH_AGGR_ENCRYPTDELIM; |
| 1331 | |
| 1332 | /* |
| 1333 | * Convert desired mpdu density from microeconds to bytes based |
| 1334 | * on highest rate in rate series (i.e. first rate) to determine |
| 1335 | * required minimum length for subframe. Take into account |
| 1336 | * whether high rate is 20 or 40Mhz and half or full GI. |
| 1337 | */ |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1338 | mpdudensity = tid->an->mpdudensity; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1339 | |
| 1340 | /* |
| 1341 | * If there is no mpdu density restriction, no further calculation |
| 1342 | * is needed. |
| 1343 | */ |
| 1344 | if (mpdudensity == 0) |
| 1345 | return ndelim; |
| 1346 | |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 1347 | rix = tx_info->control.rates[0].idx; |
| 1348 | flags = tx_info->control.rates[0].flags; |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 1349 | rc = rt->info[rix].ratecode; |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 1350 | width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0; |
| 1351 | half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1352 | |
| 1353 | if (half_gi) |
| 1354 | nsymbols = NUM_SYMBOLS_PER_USEC_HALFGI(mpdudensity); |
| 1355 | else |
| 1356 | nsymbols = NUM_SYMBOLS_PER_USEC(mpdudensity); |
| 1357 | |
| 1358 | if (nsymbols == 0) |
| 1359 | nsymbols = 1; |
| 1360 | |
| 1361 | nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width]; |
| 1362 | minlen = (nsymbols * nsymbits) / BITS_PER_BYTE; |
| 1363 | |
| 1364 | /* Is frame shorter than required minimum length? */ |
| 1365 | if (frmlen < minlen) { |
| 1366 | /* Get the minimum number of delimiters required. */ |
| 1367 | mindelim = (minlen - frmlen) / ATH_AGGR_DELIM_SZ; |
| 1368 | ndelim = max(mindelim, ndelim); |
| 1369 | } |
| 1370 | |
| 1371 | return ndelim; |
| 1372 | } |
| 1373 | |
| 1374 | /* |
| 1375 | * For aggregation from software buffer queue. |
| 1376 | * NB: must be called with txq lock held |
| 1377 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1378 | static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc, |
| 1379 | struct ath_atx_tid *tid, |
| 1380 | struct list_head *bf_q, |
| 1381 | struct ath_buf **bf_last, |
| 1382 | struct aggr_rifs_param *param, |
| 1383 | int *prev_frames) |
| 1384 | { |
| 1385 | #define PADBYTES(_len) ((4 - ((_len) % 4)) % 4) |
| 1386 | struct ath_buf *bf, *tbf, *bf_first, *bf_prev = NULL; |
| 1387 | struct list_head bf_head; |
| 1388 | int rl = 0, nframes = 0, ndelim; |
| 1389 | u16 aggr_limit = 0, al = 0, bpad = 0, |
| 1390 | al_delta, h_baw = tid->baw_size / 2; |
| 1391 | enum ATH_AGGR_STATUS status = ATH_AGGR_DONE; |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 1392 | int prev_al = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1393 | INIT_LIST_HEAD(&bf_head); |
| 1394 | |
| 1395 | BUG_ON(list_empty(&tid->buf_q)); |
| 1396 | |
| 1397 | bf_first = list_first_entry(&tid->buf_q, struct ath_buf, list); |
| 1398 | |
| 1399 | do { |
| 1400 | bf = list_first_entry(&tid->buf_q, struct ath_buf, list); |
| 1401 | |
| 1402 | /* |
| 1403 | * do not step over block-ack window |
| 1404 | */ |
| 1405 | if (!BAW_WITHIN(tid->seq_start, tid->baw_size, bf->bf_seqno)) { |
| 1406 | status = ATH_AGGR_BAW_CLOSED; |
| 1407 | break; |
| 1408 | } |
| 1409 | |
| 1410 | if (!rl) { |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1411 | aggr_limit = ath_lookup_rate(sc, bf, tid); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1412 | rl = 1; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | /* |
| 1416 | * do not exceed aggregation limit |
| 1417 | */ |
| 1418 | al_delta = ATH_AGGR_DELIM_SZ + bf->bf_frmlen; |
| 1419 | |
| 1420 | if (nframes && (aggr_limit < |
| 1421 | (al + bpad + al_delta + prev_al))) { |
| 1422 | status = ATH_AGGR_LIMITED; |
| 1423 | break; |
| 1424 | } |
| 1425 | |
| 1426 | /* |
| 1427 | * do not exceed subframe limit |
| 1428 | */ |
| 1429 | if ((nframes + *prev_frames) >= |
| 1430 | min((int)h_baw, ATH_AMPDU_SUBFRAME_DEFAULT)) { |
| 1431 | status = ATH_AGGR_LIMITED; |
| 1432 | break; |
| 1433 | } |
| 1434 | |
| 1435 | /* |
| 1436 | * add padding for previous frame to aggregation length |
| 1437 | */ |
| 1438 | al += bpad + al_delta; |
| 1439 | |
| 1440 | /* |
| 1441 | * Get the delimiters needed to meet the MPDU |
| 1442 | * density for this node. |
| 1443 | */ |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1444 | ndelim = ath_compute_num_delims(sc, tid, bf_first, bf->bf_frmlen); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1445 | |
| 1446 | bpad = PADBYTES(al_delta) + (ndelim << 2); |
| 1447 | |
| 1448 | bf->bf_next = NULL; |
| 1449 | bf->bf_lastfrm->bf_desc->ds_link = 0; |
| 1450 | |
| 1451 | /* |
| 1452 | * this packet is part of an aggregate |
| 1453 | * - remove all descriptors belonging to this frame from |
| 1454 | * software queue |
| 1455 | * - add it to block ack window |
| 1456 | * - set up descriptors for aggregation |
| 1457 | */ |
| 1458 | list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list); |
| 1459 | ath_tx_addto_baw(sc, tid, bf); |
| 1460 | |
| 1461 | list_for_each_entry(tbf, &bf_head, list) { |
| 1462 | ath9k_hw_set11n_aggr_middle(sc->sc_ah, |
| 1463 | tbf->bf_desc, ndelim); |
| 1464 | } |
| 1465 | |
| 1466 | /* |
| 1467 | * link buffers of this frame to the aggregate |
| 1468 | */ |
| 1469 | list_splice_tail_init(&bf_head, bf_q); |
| 1470 | nframes++; |
| 1471 | |
| 1472 | if (bf_prev) { |
| 1473 | bf_prev->bf_next = bf; |
| 1474 | bf_prev->bf_lastfrm->bf_desc->ds_link = bf->bf_daddr; |
| 1475 | } |
| 1476 | bf_prev = bf; |
| 1477 | |
| 1478 | #ifdef AGGR_NOSHORT |
| 1479 | /* |
| 1480 | * terminate aggregation on a small packet boundary |
| 1481 | */ |
| 1482 | if (bf->bf_frmlen < ATH_AGGR_MINPLEN) { |
| 1483 | status = ATH_AGGR_SHORTPKT; |
| 1484 | break; |
| 1485 | } |
| 1486 | #endif |
| 1487 | } while (!list_empty(&tid->buf_q)); |
| 1488 | |
| 1489 | bf_first->bf_al = al; |
| 1490 | bf_first->bf_nframes = nframes; |
| 1491 | *bf_last = bf_prev; |
| 1492 | return status; |
| 1493 | #undef PADBYTES |
| 1494 | } |
| 1495 | |
| 1496 | /* |
| 1497 | * process pending frames possibly doing a-mpdu aggregation |
| 1498 | * NB: must be called with txq lock held |
| 1499 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1500 | static void ath_tx_sched_aggr(struct ath_softc *sc, |
| 1501 | struct ath_txq *txq, struct ath_atx_tid *tid) |
| 1502 | { |
| 1503 | struct ath_buf *bf, *tbf, *bf_last, *bf_lastaggr = NULL; |
| 1504 | enum ATH_AGGR_STATUS status; |
| 1505 | struct list_head bf_q; |
| 1506 | struct aggr_rifs_param param = {0, 0, 0, 0, NULL}; |
| 1507 | int prev_frames = 0; |
| 1508 | |
| 1509 | do { |
| 1510 | if (list_empty(&tid->buf_q)) |
| 1511 | return; |
| 1512 | |
| 1513 | INIT_LIST_HEAD(&bf_q); |
| 1514 | |
| 1515 | status = ath_tx_form_aggr(sc, tid, &bf_q, &bf_lastaggr, ¶m, |
| 1516 | &prev_frames); |
| 1517 | |
| 1518 | /* |
| 1519 | * no frames picked up to be aggregated; block-ack |
| 1520 | * window is not open |
| 1521 | */ |
| 1522 | if (list_empty(&bf_q)) |
| 1523 | break; |
| 1524 | |
| 1525 | bf = list_first_entry(&bf_q, struct ath_buf, list); |
| 1526 | bf_last = list_entry(bf_q.prev, struct ath_buf, list); |
| 1527 | bf->bf_lastbf = bf_last; |
| 1528 | |
| 1529 | /* |
| 1530 | * if only one frame, send as non-aggregate |
| 1531 | */ |
| 1532 | if (bf->bf_nframes == 1) { |
| 1533 | ASSERT(bf->bf_lastfrm == bf_last); |
| 1534 | |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 1535 | bf->bf_state.bf_type &= ~BUF_AGGR; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1536 | /* |
| 1537 | * clear aggr bits for every descriptor |
| 1538 | * XXX TODO: is there a way to optimize it? |
| 1539 | */ |
| 1540 | list_for_each_entry(tbf, &bf_q, list) { |
| 1541 | ath9k_hw_clr11n_aggr(sc->sc_ah, tbf->bf_desc); |
| 1542 | } |
| 1543 | |
| 1544 | ath_buf_set_rate(sc, bf); |
| 1545 | ath_tx_txqaddbuf(sc, txq, &bf_q); |
| 1546 | continue; |
| 1547 | } |
| 1548 | |
| 1549 | /* |
| 1550 | * setup first desc with rate and aggr info |
| 1551 | */ |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 1552 | bf->bf_state.bf_type |= BUF_AGGR; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1553 | ath_buf_set_rate(sc, bf); |
| 1554 | ath9k_hw_set11n_aggr_first(sc->sc_ah, bf->bf_desc, bf->bf_al); |
| 1555 | |
| 1556 | /* |
| 1557 | * anchor last frame of aggregate correctly |
| 1558 | */ |
| 1559 | ASSERT(bf_lastaggr); |
| 1560 | ASSERT(bf_lastaggr->bf_lastfrm == bf_last); |
| 1561 | tbf = bf_lastaggr; |
| 1562 | ath9k_hw_set11n_aggr_last(sc->sc_ah, tbf->bf_desc); |
| 1563 | |
| 1564 | /* XXX: We don't enter into this loop, consider removing this */ |
| 1565 | while (!list_empty(&bf_q) && !list_is_last(&tbf->list, &bf_q)) { |
| 1566 | tbf = list_entry(tbf->list.next, struct ath_buf, list); |
| 1567 | ath9k_hw_set11n_aggr_last(sc->sc_ah, tbf->bf_desc); |
| 1568 | } |
| 1569 | |
| 1570 | txq->axq_aggr_depth++; |
| 1571 | |
| 1572 | /* |
| 1573 | * Normal aggregate, queue to hardware |
| 1574 | */ |
| 1575 | ath_tx_txqaddbuf(sc, txq, &bf_q); |
| 1576 | |
| 1577 | } while (txq->axq_depth < ATH_AGGR_MIN_QDEPTH && |
| 1578 | status != ATH_AGGR_BAW_CLOSED); |
| 1579 | } |
| 1580 | |
| 1581 | /* Called with txq lock held */ |
| 1582 | |
| 1583 | static void ath_tid_drain(struct ath_softc *sc, |
| 1584 | struct ath_txq *txq, |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 1585 | struct ath_atx_tid *tid) |
| 1586 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1587 | { |
| 1588 | struct ath_buf *bf; |
| 1589 | struct list_head bf_head; |
| 1590 | INIT_LIST_HEAD(&bf_head); |
| 1591 | |
| 1592 | for (;;) { |
| 1593 | if (list_empty(&tid->buf_q)) |
| 1594 | break; |
| 1595 | bf = list_first_entry(&tid->buf_q, struct ath_buf, list); |
| 1596 | |
| 1597 | list_cut_position(&bf_head, &tid->buf_q, &bf->bf_lastfrm->list); |
| 1598 | |
| 1599 | /* update baw for software retried frame */ |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 1600 | if (bf_isretried(bf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1601 | ath_tx_update_baw(sc, tid, bf->bf_seqno); |
| 1602 | |
| 1603 | /* |
| 1604 | * do not indicate packets while holding txq spinlock. |
| 1605 | * unlock is intentional here |
| 1606 | */ |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 1607 | spin_unlock(&txq->axq_lock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1608 | |
| 1609 | /* complete this sub-frame */ |
| 1610 | ath_tx_complete_buf(sc, bf, &bf_head, 0, 0); |
| 1611 | |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 1612 | spin_lock(&txq->axq_lock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | /* |
| 1616 | * TODO: For frame(s) that are in the retry state, we will reuse the |
| 1617 | * sequence number(s) without setting the retry bit. The |
| 1618 | * alternative is to give up on these and BAR the receiver's window |
| 1619 | * forward. |
| 1620 | */ |
| 1621 | tid->seq_next = tid->seq_start; |
| 1622 | tid->baw_tail = tid->baw_head; |
| 1623 | } |
| 1624 | |
| 1625 | /* |
| 1626 | * Drain all pending buffers |
| 1627 | * NB: must be called with txq lock held |
| 1628 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1629 | static void ath_txq_drain_pending_buffers(struct ath_softc *sc, |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 1630 | struct ath_txq *txq) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1631 | { |
| 1632 | struct ath_atx_ac *ac, *ac_tmp; |
| 1633 | struct ath_atx_tid *tid, *tid_tmp; |
| 1634 | |
| 1635 | list_for_each_entry_safe(ac, ac_tmp, &txq->axq_acq, list) { |
| 1636 | list_del(&ac->list); |
| 1637 | ac->sched = false; |
| 1638 | list_for_each_entry_safe(tid, tid_tmp, &ac->tid_q, list) { |
| 1639 | list_del(&tid->list); |
| 1640 | tid->sched = false; |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 1641 | ath_tid_drain(sc, txq, tid); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1642 | } |
| 1643 | } |
| 1644 | } |
| 1645 | |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1646 | static int ath_tx_setup_buffer(struct ath_softc *sc, struct ath_buf *bf, |
Sujith | 8f93b8b | 2008-11-18 09:10:42 +0530 | [diff] [blame] | 1647 | struct sk_buff *skb, |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1648 | struct ath_tx_control *txctl) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1649 | { |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1650 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 1651 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1652 | struct ath_tx_info_priv *tx_info_priv; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1653 | int hdrlen; |
| 1654 | __le16 fc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1655 | |
Luis R. Rodriguez | c112d0c | 2008-12-03 03:35:30 -0800 | [diff] [blame] | 1656 | tx_info_priv = kzalloc(sizeof(*tx_info_priv), GFP_ATOMIC); |
| 1657 | if (unlikely(!tx_info_priv)) |
| 1658 | return -ENOMEM; |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 1659 | tx_info->rate_driver_data[0] = tx_info_priv; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1660 | hdrlen = ieee80211_get_hdrlen_from_skb(skb); |
| 1661 | fc = hdr->frame_control; |
Jouni Malinen | e022edb | 2008-08-22 17:31:33 +0300 | [diff] [blame] | 1662 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1663 | ATH_TXBUF_RESET(bf); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1664 | |
| 1665 | /* Frame type */ |
| 1666 | |
| 1667 | bf->bf_frmlen = skb->len + FCS_LEN - (hdrlen & 3); |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 1668 | |
| 1669 | ieee80211_is_data(fc) ? |
| 1670 | (bf->bf_state.bf_type |= BUF_DATA) : |
| 1671 | (bf->bf_state.bf_type &= ~BUF_DATA); |
| 1672 | ieee80211_is_back_req(fc) ? |
| 1673 | (bf->bf_state.bf_type |= BUF_BAR) : |
| 1674 | (bf->bf_state.bf_type &= ~BUF_BAR); |
| 1675 | ieee80211_is_pspoll(fc) ? |
| 1676 | (bf->bf_state.bf_type |= BUF_PSPOLL) : |
| 1677 | (bf->bf_state.bf_type &= ~BUF_PSPOLL); |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 1678 | (sc->sc_flags & SC_OP_PREAMBLE_SHORT) ? |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 1679 | (bf->bf_state.bf_type |= BUF_SHORT_PREAMBLE) : |
| 1680 | (bf->bf_state.bf_type &= ~BUF_SHORT_PREAMBLE); |
Sujith | a8efee4 | 2008-11-18 09:07:30 +0530 | [diff] [blame] | 1681 | (sc->hw->conf.ht.enabled && !is_pae(skb) && |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1682 | (tx_info->flags & IEEE80211_TX_CTL_AMPDU)) ? |
| 1683 | (bf->bf_state.bf_type |= BUF_HT) : |
| 1684 | (bf->bf_state.bf_type &= ~BUF_HT); |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 1685 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1686 | bf->bf_flags = setup_tx_flags(sc, skb, txctl->txq); |
| 1687 | |
| 1688 | /* Crypto */ |
| 1689 | |
| 1690 | bf->bf_keytype = get_hw_crypto_keytype(skb); |
| 1691 | |
| 1692 | if (bf->bf_keytype != ATH9K_KEY_TYPE_CLEAR) { |
| 1693 | bf->bf_frmlen += tx_info->control.hw_key->icv_len; |
| 1694 | bf->bf_keyix = tx_info->control.hw_key->hw_key_idx; |
| 1695 | } else { |
| 1696 | bf->bf_keyix = ATH9K_TXKEYIX_INVALID; |
| 1697 | } |
| 1698 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1699 | /* Assign seqno, tidno */ |
| 1700 | |
| 1701 | if (bf_isht(bf) && (sc->sc_flags & SC_OP_TXAGGR)) |
| 1702 | assign_aggr_tid_seqno(skb, bf); |
| 1703 | |
| 1704 | /* DMA setup */ |
| 1705 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1706 | bf->bf_mpdu = skb; |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1707 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1708 | bf->bf_dmacontext = pci_map_single(sc->pdev, skb->data, |
| 1709 | skb->len, PCI_DMA_TODEVICE); |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1710 | if (unlikely(pci_dma_mapping_error(sc->pdev, bf->bf_dmacontext))) { |
| 1711 | bf->bf_mpdu = NULL; |
| 1712 | DPRINTF(sc, ATH_DBG_CONFIG, |
| 1713 | "pci_dma_mapping_error() on TX\n"); |
| 1714 | return -ENOMEM; |
| 1715 | } |
| 1716 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1717 | bf->bf_buf_addr = bf->bf_dmacontext; |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1718 | return 0; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | /* FIXME: tx power */ |
| 1722 | static void ath_tx_start_dma(struct ath_softc *sc, struct ath_buf *bf, |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1723 | struct ath_tx_control *txctl) |
| 1724 | { |
| 1725 | struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu; |
| 1726 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 1727 | struct ath_node *an = NULL; |
| 1728 | struct list_head bf_head; |
| 1729 | struct ath_desc *ds; |
| 1730 | struct ath_atx_tid *tid; |
| 1731 | struct ath_hal *ah = sc->sc_ah; |
| 1732 | int frm_type; |
| 1733 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1734 | frm_type = get_hw_packet_type(skb); |
| 1735 | |
| 1736 | INIT_LIST_HEAD(&bf_head); |
| 1737 | list_add_tail(&bf->list, &bf_head); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1738 | |
| 1739 | /* setup descriptor */ |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1740 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1741 | ds = bf->bf_desc; |
| 1742 | ds->ds_link = 0; |
| 1743 | ds->ds_data = bf->bf_buf_addr; |
| 1744 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1745 | /* Formulate first tx descriptor with tx controls */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1746 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1747 | ath9k_hw_set11n_txdesc(ah, ds, bf->bf_frmlen, frm_type, MAX_RATE_POWER, |
| 1748 | bf->bf_keyix, bf->bf_keytype, bf->bf_flags); |
| 1749 | |
| 1750 | ath9k_hw_filltxdesc(ah, ds, |
Sujith | 8f93b8b | 2008-11-18 09:10:42 +0530 | [diff] [blame] | 1751 | skb->len, /* segment length */ |
| 1752 | true, /* first segment */ |
| 1753 | true, /* last segment */ |
| 1754 | ds); /* first descriptor */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1755 | |
| 1756 | bf->bf_lastfrm = bf; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1757 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1758 | spin_lock_bh(&txctl->txq->axq_lock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1759 | |
John W. Linville | f161796 | 2008-10-31 16:45:15 -0400 | [diff] [blame] | 1760 | if (bf_isht(bf) && (sc->sc_flags & SC_OP_TXAGGR) && |
| 1761 | tx_info->control.sta) { |
| 1762 | an = (struct ath_node *)tx_info->control.sta->drv_priv; |
| 1763 | tid = ATH_AN_2_TID(an, bf->bf_tidno); |
| 1764 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1765 | if (ath_aggr_query(sc, an, bf->bf_tidno)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1766 | /* |
| 1767 | * Try aggregation if it's a unicast data frame |
| 1768 | * and the destination is HT capable. |
| 1769 | */ |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1770 | ath_tx_send_ampdu(sc, tid, &bf_head, txctl); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1771 | } else { |
| 1772 | /* |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1773 | * Send this frame as regular when ADDBA |
| 1774 | * exchange is neither complete nor pending. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1775 | */ |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1776 | ath_tx_send_normal(sc, txctl->txq, |
| 1777 | tid, &bf_head); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1778 | } |
| 1779 | } else { |
| 1780 | bf->bf_lastbf = bf; |
| 1781 | bf->bf_nframes = 1; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1782 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1783 | ath_buf_set_rate(sc, bf); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1784 | ath_tx_txqaddbuf(sc, txctl->txq, &bf_head); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1785 | } |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1786 | |
| 1787 | spin_unlock_bh(&txctl->txq->axq_lock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1790 | /* Upon failure caller should free skb */ |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1791 | int ath_tx_start(struct ath_softc *sc, struct sk_buff *skb, |
| 1792 | struct ath_tx_control *txctl) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1793 | { |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1794 | struct ath_buf *bf; |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1795 | int r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1796 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1797 | /* Check if a tx buffer is available */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1798 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1799 | bf = ath_tx_get_buffer(sc); |
| 1800 | if (!bf) { |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1801 | DPRINTF(sc, ATH_DBG_XMIT, "TX buffers are full\n"); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1802 | return -1; |
| 1803 | } |
| 1804 | |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1805 | r = ath_tx_setup_buffer(sc, bf, skb, txctl); |
| 1806 | if (unlikely(r)) { |
Luis R. Rodriguez | c112d0c | 2008-12-03 03:35:30 -0800 | [diff] [blame] | 1807 | struct ath_txq *txq = txctl->txq; |
| 1808 | |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1809 | DPRINTF(sc, ATH_DBG_FATAL, "TX mem alloc failure\n"); |
Luis R. Rodriguez | c112d0c | 2008-12-03 03:35:30 -0800 | [diff] [blame] | 1810 | |
| 1811 | /* upon ath_tx_processq() this TX queue will be resumed, we |
| 1812 | * guarantee this will happen by knowing beforehand that |
| 1813 | * we will at least have to run TX completionon one buffer |
| 1814 | * on the queue */ |
| 1815 | spin_lock_bh(&txq->axq_lock); |
| 1816 | if (ath_txq_depth(sc, txq->axq_qnum) > 1) { |
| 1817 | ieee80211_stop_queue(sc->hw, |
| 1818 | skb_get_queue_mapping(skb)); |
| 1819 | txq->stopped = 1; |
| 1820 | } |
| 1821 | spin_unlock_bh(&txq->axq_lock); |
| 1822 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1823 | spin_lock_bh(&sc->tx.txbuflock); |
| 1824 | list_add_tail(&bf->list, &sc->tx.txbuf); |
| 1825 | spin_unlock_bh(&sc->tx.txbuflock); |
Luis R. Rodriguez | c112d0c | 2008-12-03 03:35:30 -0800 | [diff] [blame] | 1826 | |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 1827 | return r; |
| 1828 | } |
| 1829 | |
Sujith | 8f93b8b | 2008-11-18 09:10:42 +0530 | [diff] [blame] | 1830 | ath_tx_start_dma(sc, bf, txctl); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1831 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 1832 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | /* Initialize TX queue and h/w */ |
| 1836 | |
| 1837 | int ath_tx_init(struct ath_softc *sc, int nbufs) |
| 1838 | { |
| 1839 | int error = 0; |
| 1840 | |
| 1841 | do { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1842 | spin_lock_init(&sc->tx.txbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1843 | |
| 1844 | /* Setup tx descriptors */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1845 | error = ath_descdma_setup(sc, &sc->tx.txdma, &sc->tx.txbuf, |
Sujith | 556bb8f | 2008-08-11 14:03:53 +0530 | [diff] [blame] | 1846 | "tx", nbufs, 1); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1847 | if (error != 0) { |
| 1848 | DPRINTF(sc, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1849 | "Failed to allocate tx descriptors: %d\n", |
| 1850 | error); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1851 | break; |
| 1852 | } |
| 1853 | |
| 1854 | /* XXX allocate beacon state together with vap */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1855 | error = ath_descdma_setup(sc, &sc->beacon.bdma, &sc->beacon.bbuf, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1856 | "beacon", ATH_BCBUF, 1); |
| 1857 | if (error != 0) { |
| 1858 | DPRINTF(sc, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1859 | "Failed to allocate beacon descriptors: %d\n", |
| 1860 | error); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1861 | break; |
| 1862 | } |
| 1863 | |
| 1864 | } while (0); |
| 1865 | |
| 1866 | if (error != 0) |
| 1867 | ath_tx_cleanup(sc); |
| 1868 | |
| 1869 | return error; |
| 1870 | } |
| 1871 | |
| 1872 | /* Reclaim all tx queue resources */ |
| 1873 | |
| 1874 | int ath_tx_cleanup(struct ath_softc *sc) |
| 1875 | { |
| 1876 | /* cleanup beacon descriptors */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1877 | if (sc->beacon.bdma.dd_desc_len != 0) |
| 1878 | ath_descdma_cleanup(sc, &sc->beacon.bdma, &sc->beacon.bbuf); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1879 | |
| 1880 | /* cleanup tx descriptors */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1881 | if (sc->tx.txdma.dd_desc_len != 0) |
| 1882 | ath_descdma_cleanup(sc, &sc->tx.txdma, &sc->tx.txbuf); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1883 | |
| 1884 | return 0; |
| 1885 | } |
| 1886 | |
| 1887 | /* Setup a h/w transmit queue */ |
| 1888 | |
| 1889 | struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype) |
| 1890 | { |
| 1891 | struct ath_hal *ah = sc->sc_ah; |
Sujith | ea9880f | 2008-08-07 10:53:10 +0530 | [diff] [blame] | 1892 | struct ath9k_tx_queue_info qi; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1893 | int qnum; |
| 1894 | |
Luis R. Rodriguez | 0345f37 | 2008-10-03 15:45:25 -0700 | [diff] [blame] | 1895 | memset(&qi, 0, sizeof(qi)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1896 | qi.tqi_subtype = subtype; |
| 1897 | qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT; |
| 1898 | qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT; |
| 1899 | qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT; |
Sujith | ea9880f | 2008-08-07 10:53:10 +0530 | [diff] [blame] | 1900 | qi.tqi_physCompBuf = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1901 | |
| 1902 | /* |
| 1903 | * Enable interrupts only for EOL and DESC conditions. |
| 1904 | * We mark tx descriptors to receive a DESC interrupt |
| 1905 | * when a tx queue gets deep; otherwise waiting for the |
| 1906 | * EOL to reap descriptors. Note that this is done to |
| 1907 | * reduce interrupt load and this only defers reaping |
| 1908 | * descriptors, never transmitting frames. Aside from |
| 1909 | * reducing interrupts this also permits more concurrency. |
| 1910 | * The only potential downside is if the tx queue backs |
| 1911 | * up in which case the top half of the kernel may backup |
| 1912 | * due to a lack of tx descriptors. |
| 1913 | * |
| 1914 | * The UAPSD queue is an exception, since we take a desc- |
| 1915 | * based intr on the EOSP frames. |
| 1916 | */ |
| 1917 | if (qtype == ATH9K_TX_QUEUE_UAPSD) |
| 1918 | qi.tqi_qflags = TXQ_FLAG_TXDESCINT_ENABLE; |
| 1919 | else |
| 1920 | qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE | |
| 1921 | TXQ_FLAG_TXDESCINT_ENABLE; |
| 1922 | qnum = ath9k_hw_setuptxqueue(ah, qtype, &qi); |
| 1923 | if (qnum == -1) { |
| 1924 | /* |
| 1925 | * NB: don't print a message, this happens |
| 1926 | * normally on parts with too few tx queues |
| 1927 | */ |
| 1928 | return NULL; |
| 1929 | } |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1930 | if (qnum >= ARRAY_SIZE(sc->tx.txq)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1931 | DPRINTF(sc, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1932 | "qnum %u out of range, max %u!\n", |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1933 | qnum, (unsigned int)ARRAY_SIZE(sc->tx.txq)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1934 | ath9k_hw_releasetxqueue(ah, qnum); |
| 1935 | return NULL; |
| 1936 | } |
| 1937 | if (!ATH_TXQ_SETUP(sc, qnum)) { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1938 | struct ath_txq *txq = &sc->tx.txq[qnum]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1939 | |
| 1940 | txq->axq_qnum = qnum; |
| 1941 | txq->axq_link = NULL; |
| 1942 | INIT_LIST_HEAD(&txq->axq_q); |
| 1943 | INIT_LIST_HEAD(&txq->axq_acq); |
| 1944 | spin_lock_init(&txq->axq_lock); |
| 1945 | txq->axq_depth = 0; |
| 1946 | txq->axq_aggr_depth = 0; |
| 1947 | txq->axq_totalqueued = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1948 | txq->axq_linkbuf = NULL; |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1949 | sc->tx.txqsetup |= 1<<qnum; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1950 | } |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1951 | return &sc->tx.txq[qnum]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | /* Reclaim resources for a setup queue */ |
| 1955 | |
| 1956 | void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq) |
| 1957 | { |
| 1958 | ath9k_hw_releasetxqueue(sc->sc_ah, txq->axq_qnum); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1959 | sc->tx.txqsetup &= ~(1<<txq->axq_qnum); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | /* |
| 1963 | * Setup a hardware data transmit queue for the specified |
| 1964 | * access control. The hal may not support all requested |
| 1965 | * queues in which case it will return a reference to a |
| 1966 | * previously setup queue. We record the mapping from ac's |
| 1967 | * to h/w queues for use by ath_tx_start and also track |
| 1968 | * the set of h/w queues being used to optimize work in the |
| 1969 | * transmit interrupt handler and related routines. |
| 1970 | */ |
| 1971 | |
| 1972 | int ath_tx_setup(struct ath_softc *sc, int haltype) |
| 1973 | { |
| 1974 | struct ath_txq *txq; |
| 1975 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1976 | if (haltype >= ARRAY_SIZE(sc->tx.hwq_map)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1977 | DPRINTF(sc, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1978 | "HAL AC %u out of range, max %zu!\n", |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1979 | haltype, ARRAY_SIZE(sc->tx.hwq_map)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1980 | return 0; |
| 1981 | } |
| 1982 | txq = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, haltype); |
| 1983 | if (txq != NULL) { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1984 | sc->tx.hwq_map[haltype] = txq->axq_qnum; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1985 | return 1; |
| 1986 | } else |
| 1987 | return 0; |
| 1988 | } |
| 1989 | |
| 1990 | int ath_tx_get_qnum(struct ath_softc *sc, int qtype, int haltype) |
| 1991 | { |
| 1992 | int qnum; |
| 1993 | |
| 1994 | switch (qtype) { |
| 1995 | case ATH9K_TX_QUEUE_DATA: |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1996 | if (haltype >= ARRAY_SIZE(sc->tx.hwq_map)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1997 | DPRINTF(sc, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 1998 | "HAL AC %u out of range, max %zu!\n", |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 1999 | haltype, ARRAY_SIZE(sc->tx.hwq_map)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2000 | return -1; |
| 2001 | } |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2002 | qnum = sc->tx.hwq_map[haltype]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2003 | break; |
| 2004 | case ATH9K_TX_QUEUE_BEACON: |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2005 | qnum = sc->beacon.beaconq; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2006 | break; |
| 2007 | case ATH9K_TX_QUEUE_CAB: |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2008 | qnum = sc->beacon.cabq->axq_qnum; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2009 | break; |
| 2010 | default: |
| 2011 | qnum = -1; |
| 2012 | } |
| 2013 | return qnum; |
| 2014 | } |
| 2015 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 2016 | /* Get a transmit queue, if available */ |
| 2017 | |
| 2018 | struct ath_txq *ath_test_get_txq(struct ath_softc *sc, struct sk_buff *skb) |
| 2019 | { |
| 2020 | struct ath_txq *txq = NULL; |
| 2021 | int qnum; |
| 2022 | |
| 2023 | qnum = ath_get_hal_qnum(skb_get_queue_mapping(skb), sc); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2024 | txq = &sc->tx.txq[qnum]; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 2025 | |
| 2026 | spin_lock_bh(&txq->axq_lock); |
| 2027 | |
| 2028 | /* Try to avoid running out of descriptors */ |
| 2029 | if (txq->axq_depth >= (ATH_TXBUF - 20)) { |
| 2030 | DPRINTF(sc, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2031 | "TX queue: %d is full, depth: %d\n", |
| 2032 | qnum, txq->axq_depth); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 2033 | ieee80211_stop_queue(sc->hw, skb_get_queue_mapping(skb)); |
| 2034 | txq->stopped = 1; |
| 2035 | spin_unlock_bh(&txq->axq_lock); |
| 2036 | return NULL; |
| 2037 | } |
| 2038 | |
| 2039 | spin_unlock_bh(&txq->axq_lock); |
| 2040 | |
| 2041 | return txq; |
| 2042 | } |
| 2043 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2044 | /* Update parameters for a transmit queue */ |
| 2045 | |
Sujith | ea9880f | 2008-08-07 10:53:10 +0530 | [diff] [blame] | 2046 | int ath_txq_update(struct ath_softc *sc, int qnum, |
| 2047 | struct ath9k_tx_queue_info *qinfo) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2048 | { |
| 2049 | struct ath_hal *ah = sc->sc_ah; |
| 2050 | int error = 0; |
Sujith | ea9880f | 2008-08-07 10:53:10 +0530 | [diff] [blame] | 2051 | struct ath9k_tx_queue_info qi; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2052 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2053 | if (qnum == sc->beacon.beaconq) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2054 | /* |
| 2055 | * XXX: for beacon queue, we just save the parameter. |
| 2056 | * It will be picked up by ath_beaconq_config when |
| 2057 | * it's necessary. |
| 2058 | */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2059 | sc->beacon.beacon_qi = *qinfo; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2060 | return 0; |
| 2061 | } |
| 2062 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2063 | ASSERT(sc->tx.txq[qnum].axq_qnum == qnum); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2064 | |
Sujith | ea9880f | 2008-08-07 10:53:10 +0530 | [diff] [blame] | 2065 | ath9k_hw_get_txq_props(ah, qnum, &qi); |
| 2066 | qi.tqi_aifs = qinfo->tqi_aifs; |
| 2067 | qi.tqi_cwmin = qinfo->tqi_cwmin; |
| 2068 | qi.tqi_cwmax = qinfo->tqi_cwmax; |
| 2069 | qi.tqi_burstTime = qinfo->tqi_burstTime; |
| 2070 | qi.tqi_readyTime = qinfo->tqi_readyTime; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2071 | |
Sujith | ea9880f | 2008-08-07 10:53:10 +0530 | [diff] [blame] | 2072 | if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2073 | DPRINTF(sc, ATH_DBG_FATAL, |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2074 | "Unable to update hardware queue %u!\n", qnum); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2075 | error = -EIO; |
| 2076 | } else { |
| 2077 | ath9k_hw_resettxqueue(ah, qnum); /* push to h/w */ |
| 2078 | } |
| 2079 | |
| 2080 | return error; |
| 2081 | } |
| 2082 | |
| 2083 | int ath_cabq_update(struct ath_softc *sc) |
| 2084 | { |
Sujith | ea9880f | 2008-08-07 10:53:10 +0530 | [diff] [blame] | 2085 | struct ath9k_tx_queue_info qi; |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2086 | int qnum = sc->beacon.cabq->axq_qnum; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2087 | struct ath_beacon_config conf; |
| 2088 | |
Sujith | ea9880f | 2008-08-07 10:53:10 +0530 | [diff] [blame] | 2089 | ath9k_hw_get_txq_props(sc->sc_ah, qnum, &qi); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2090 | /* |
| 2091 | * Ensure the readytime % is within the bounds. |
| 2092 | */ |
| 2093 | if (sc->sc_config.cabqReadytime < ATH9K_READY_TIME_LO_BOUND) |
| 2094 | sc->sc_config.cabqReadytime = ATH9K_READY_TIME_LO_BOUND; |
| 2095 | else if (sc->sc_config.cabqReadytime > ATH9K_READY_TIME_HI_BOUND) |
| 2096 | sc->sc_config.cabqReadytime = ATH9K_READY_TIME_HI_BOUND; |
| 2097 | |
| 2098 | ath_get_beaconconfig(sc, ATH_IF_ID_ANY, &conf); |
| 2099 | qi.tqi_readyTime = |
| 2100 | (conf.beacon_interval * sc->sc_config.cabqReadytime) / 100; |
| 2101 | ath_txq_update(sc, qnum, &qi); |
| 2102 | |
| 2103 | return 0; |
| 2104 | } |
| 2105 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2106 | /* Deferred processing of transmit interrupt */ |
| 2107 | |
| 2108 | void ath_tx_tasklet(struct ath_softc *sc) |
| 2109 | { |
Sujith | 1fe1132 | 2008-08-26 08:11:06 +0530 | [diff] [blame] | 2110 | int i; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2111 | u32 qcumask = ((1 << ATH9K_NUM_TX_QUEUES) - 1); |
| 2112 | |
| 2113 | ath9k_hw_gettxintrtxqs(sc->sc_ah, &qcumask); |
| 2114 | |
| 2115 | /* |
| 2116 | * Process each active queue. |
| 2117 | */ |
| 2118 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { |
| 2119 | if (ATH_TXQ_SETUP(sc, i) && (qcumask & (1 << i))) |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2120 | ath_tx_processq(sc, &sc->tx.txq[i]); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2121 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | void ath_tx_draintxq(struct ath_softc *sc, |
| 2125 | struct ath_txq *txq, bool retry_tx) |
| 2126 | { |
| 2127 | struct ath_buf *bf, *lastbf; |
| 2128 | struct list_head bf_head; |
| 2129 | |
| 2130 | INIT_LIST_HEAD(&bf_head); |
| 2131 | |
| 2132 | /* |
| 2133 | * NB: this assumes output has been stopped and |
| 2134 | * we do not need to block ath_tx_tasklet |
| 2135 | */ |
| 2136 | for (;;) { |
| 2137 | spin_lock_bh(&txq->axq_lock); |
| 2138 | |
| 2139 | if (list_empty(&txq->axq_q)) { |
| 2140 | txq->axq_link = NULL; |
| 2141 | txq->axq_linkbuf = NULL; |
| 2142 | spin_unlock_bh(&txq->axq_lock); |
| 2143 | break; |
| 2144 | } |
| 2145 | |
| 2146 | bf = list_first_entry(&txq->axq_q, struct ath_buf, list); |
| 2147 | |
| 2148 | if (bf->bf_status & ATH_BUFSTATUS_STALE) { |
| 2149 | list_del(&bf->list); |
| 2150 | spin_unlock_bh(&txq->axq_lock); |
| 2151 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2152 | spin_lock_bh(&sc->tx.txbuflock); |
| 2153 | list_add_tail(&bf->list, &sc->tx.txbuf); |
| 2154 | spin_unlock_bh(&sc->tx.txbuflock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2155 | continue; |
| 2156 | } |
| 2157 | |
| 2158 | lastbf = bf->bf_lastbf; |
| 2159 | if (!retry_tx) |
| 2160 | lastbf->bf_desc->ds_txstat.ts_flags = |
| 2161 | ATH9K_TX_SW_ABORTED; |
| 2162 | |
| 2163 | /* remove ath_buf's of the same mpdu from txq */ |
| 2164 | list_cut_position(&bf_head, &txq->axq_q, &lastbf->list); |
| 2165 | txq->axq_depth--; |
| 2166 | |
| 2167 | spin_unlock_bh(&txq->axq_lock); |
| 2168 | |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 2169 | if (bf_isampdu(bf)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2170 | ath_tx_complete_aggr_rifs(sc, txq, bf, &bf_head, 0); |
| 2171 | else |
| 2172 | ath_tx_complete_buf(sc, bf, &bf_head, 0, 0); |
| 2173 | } |
| 2174 | |
| 2175 | /* flush any pending frames if aggregation is enabled */ |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 2176 | if (sc->sc_flags & SC_OP_TXAGGR) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2177 | if (!retry_tx) { |
| 2178 | spin_lock_bh(&txq->axq_lock); |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 2179 | ath_txq_drain_pending_buffers(sc, txq); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2180 | spin_unlock_bh(&txq->axq_lock); |
| 2181 | } |
| 2182 | } |
| 2183 | } |
| 2184 | |
| 2185 | /* Drain the transmit queues and reclaim resources */ |
| 2186 | |
| 2187 | void ath_draintxq(struct ath_softc *sc, bool retry_tx) |
| 2188 | { |
| 2189 | /* stop beacon queue. The beacon will be freed when |
| 2190 | * we go to INIT state */ |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 2191 | if (!(sc->sc_flags & SC_OP_INVALID)) { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2192 | (void) ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq); |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2193 | DPRINTF(sc, ATH_DBG_XMIT, "beacon queue %x\n", |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2194 | ath9k_hw_gettxbuf(sc->sc_ah, sc->beacon.beaconq)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | ath_drain_txdataq(sc, retry_tx); |
| 2198 | } |
| 2199 | |
| 2200 | u32 ath_txq_depth(struct ath_softc *sc, int qnum) |
| 2201 | { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2202 | return sc->tx.txq[qnum].axq_depth; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | u32 ath_txq_aggr_depth(struct ath_softc *sc, int qnum) |
| 2206 | { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2207 | return sc->tx.txq[qnum].axq_aggr_depth; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2208 | } |
| 2209 | |
Sujith | ccc75c5 | 2008-10-29 10:18:14 +0530 | [diff] [blame] | 2210 | bool ath_tx_aggr_check(struct ath_softc *sc, struct ath_node *an, u8 tidno) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2211 | { |
| 2212 | struct ath_atx_tid *txtid; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2213 | |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 2214 | if (!(sc->sc_flags & SC_OP_TXAGGR)) |
Sujith | ccc75c5 | 2008-10-29 10:18:14 +0530 | [diff] [blame] | 2215 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2216 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2217 | txtid = ATH_AN_2_TID(an, tidno); |
| 2218 | |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 2219 | if (!(txtid->state & AGGR_ADDBA_COMPLETE)) { |
| 2220 | if (!(txtid->state & AGGR_ADDBA_PROGRESS) && |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2221 | (txtid->addba_exchangeattempts < ADDBA_EXCHANGE_ATTEMPTS)) { |
| 2222 | txtid->addba_exchangeattempts++; |
Sujith | ccc75c5 | 2008-10-29 10:18:14 +0530 | [diff] [blame] | 2223 | return true; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2224 | } |
| 2225 | } |
| 2226 | |
Sujith | ccc75c5 | 2008-10-29 10:18:14 +0530 | [diff] [blame] | 2227 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | /* Start TX aggregation */ |
| 2231 | |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 2232 | int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta, |
| 2233 | u16 tid, u16 *ssn) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2234 | { |
| 2235 | struct ath_atx_tid *txtid; |
| 2236 | struct ath_node *an; |
| 2237 | |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 2238 | an = (struct ath_node *)sta->drv_priv; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2239 | |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 2240 | if (sc->sc_flags & SC_OP_TXAGGR) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2241 | txtid = ATH_AN_2_TID(an, tid); |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 2242 | txtid->state |= AGGR_ADDBA_PROGRESS; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2243 | ath_tx_pause_tid(sc, txtid); |
| 2244 | } |
| 2245 | |
| 2246 | return 0; |
| 2247 | } |
| 2248 | |
| 2249 | /* Stop tx aggregation */ |
| 2250 | |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 2251 | int ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2252 | { |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 2253 | struct ath_node *an = (struct ath_node *)sta->drv_priv; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2254 | |
| 2255 | ath_tx_aggr_teardown(sc, an, tid); |
| 2256 | return 0; |
| 2257 | } |
| 2258 | |
Sujith | 8469cde | 2008-10-29 10:19:28 +0530 | [diff] [blame] | 2259 | /* Resume tx aggregation */ |
| 2260 | |
| 2261 | void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid) |
| 2262 | { |
| 2263 | struct ath_atx_tid *txtid; |
| 2264 | struct ath_node *an; |
| 2265 | |
| 2266 | an = (struct ath_node *)sta->drv_priv; |
| 2267 | |
| 2268 | if (sc->sc_flags & SC_OP_TXAGGR) { |
| 2269 | txtid = ATH_AN_2_TID(an, tid); |
| 2270 | txtid->baw_size = |
| 2271 | IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor; |
| 2272 | txtid->state |= AGGR_ADDBA_COMPLETE; |
| 2273 | txtid->state &= ~AGGR_ADDBA_PROGRESS; |
| 2274 | ath_tx_resume_tid(sc, txtid); |
| 2275 | } |
| 2276 | } |
| 2277 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2278 | /* |
| 2279 | * Performs transmit side cleanup when TID changes from aggregated to |
| 2280 | * unaggregated. |
| 2281 | * - Pause the TID and mark cleanup in progress |
| 2282 | * - Discard all retry frames from the s/w queue. |
| 2283 | */ |
| 2284 | |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 2285 | void ath_tx_aggr_teardown(struct ath_softc *sc, struct ath_node *an, u8 tid) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2286 | { |
| 2287 | struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2288 | struct ath_txq *txq = &sc->tx.txq[txtid->ac->qnum]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2289 | struct ath_buf *bf; |
| 2290 | struct list_head bf_head; |
| 2291 | INIT_LIST_HEAD(&bf_head); |
| 2292 | |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 2293 | if (txtid->state & AGGR_CLEANUP) /* cleanup is in progress */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2294 | return; |
| 2295 | |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 2296 | if (!(txtid->state & AGGR_ADDBA_COMPLETE)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2297 | txtid->addba_exchangeattempts = 0; |
| 2298 | return; |
| 2299 | } |
| 2300 | |
| 2301 | /* TID must be paused first */ |
| 2302 | ath_tx_pause_tid(sc, txtid); |
| 2303 | |
| 2304 | /* drop all software retried frames and mark this TID */ |
| 2305 | spin_lock_bh(&txq->axq_lock); |
| 2306 | while (!list_empty(&txtid->buf_q)) { |
| 2307 | bf = list_first_entry(&txtid->buf_q, struct ath_buf, list); |
Sujith | cd3d39a | 2008-08-11 14:03:34 +0530 | [diff] [blame] | 2308 | if (!bf_isretried(bf)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2309 | /* |
| 2310 | * NB: it's based on the assumption that |
| 2311 | * software retried frame will always stay |
| 2312 | * at the head of software queue. |
| 2313 | */ |
| 2314 | break; |
| 2315 | } |
| 2316 | list_cut_position(&bf_head, |
| 2317 | &txtid->buf_q, &bf->bf_lastfrm->list); |
| 2318 | ath_tx_update_baw(sc, txtid, bf->bf_seqno); |
| 2319 | |
| 2320 | /* complete this sub-frame */ |
| 2321 | ath_tx_complete_buf(sc, bf, &bf_head, 0, 0); |
| 2322 | } |
| 2323 | |
| 2324 | if (txtid->baw_head != txtid->baw_tail) { |
| 2325 | spin_unlock_bh(&txq->axq_lock); |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 2326 | txtid->state |= AGGR_CLEANUP; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2327 | } else { |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 2328 | txtid->state &= ~AGGR_ADDBA_COMPLETE; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2329 | txtid->addba_exchangeattempts = 0; |
| 2330 | spin_unlock_bh(&txq->axq_lock); |
| 2331 | ath_tx_flush_tid(sc, txtid); |
| 2332 | } |
| 2333 | } |
| 2334 | |
| 2335 | /* |
| 2336 | * Tx scheduling logic |
| 2337 | * NB: must be called with txq lock held |
| 2338 | */ |
| 2339 | |
| 2340 | void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq) |
| 2341 | { |
| 2342 | struct ath_atx_ac *ac; |
| 2343 | struct ath_atx_tid *tid; |
| 2344 | |
| 2345 | /* nothing to schedule */ |
| 2346 | if (list_empty(&txq->axq_acq)) |
| 2347 | return; |
| 2348 | /* |
| 2349 | * get the first node/ac pair on the queue |
| 2350 | */ |
| 2351 | ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac, list); |
| 2352 | list_del(&ac->list); |
| 2353 | ac->sched = false; |
| 2354 | |
| 2355 | /* |
| 2356 | * process a single tid per destination |
| 2357 | */ |
| 2358 | do { |
| 2359 | /* nothing to schedule */ |
| 2360 | if (list_empty(&ac->tid_q)) |
| 2361 | return; |
| 2362 | |
| 2363 | tid = list_first_entry(&ac->tid_q, struct ath_atx_tid, list); |
| 2364 | list_del(&tid->list); |
| 2365 | tid->sched = false; |
| 2366 | |
| 2367 | if (tid->paused) /* check next tid to keep h/w busy */ |
| 2368 | continue; |
| 2369 | |
Sujith | 43453b3 | 2008-10-29 10:14:52 +0530 | [diff] [blame] | 2370 | if ((txq->axq_depth % 2) == 0) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2371 | ath_tx_sched_aggr(sc, txq, tid); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2372 | |
| 2373 | /* |
| 2374 | * add tid to round-robin queue if more frames |
| 2375 | * are pending for the tid |
| 2376 | */ |
| 2377 | if (!list_empty(&tid->buf_q)) |
| 2378 | ath_tx_queue_tid(txq, tid); |
| 2379 | |
| 2380 | /* only schedule one TID at a time */ |
| 2381 | break; |
| 2382 | } while (!list_empty(&ac->tid_q)); |
| 2383 | |
| 2384 | /* |
| 2385 | * schedule AC if more TIDs need processing |
| 2386 | */ |
| 2387 | if (!list_empty(&ac->tid_q)) { |
| 2388 | /* |
| 2389 | * add dest ac to txq if not already added |
| 2390 | */ |
| 2391 | if (!ac->sched) { |
| 2392 | ac->sched = true; |
| 2393 | list_add_tail(&ac->list, &txq->axq_acq); |
| 2394 | } |
| 2395 | } |
| 2396 | } |
| 2397 | |
| 2398 | /* Initialize per-node transmit state */ |
| 2399 | |
| 2400 | void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an) |
| 2401 | { |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2402 | struct ath_atx_tid *tid; |
| 2403 | struct ath_atx_ac *ac; |
| 2404 | int tidno, acno; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2405 | |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2406 | /* |
| 2407 | * Init per tid tx state |
| 2408 | */ |
Sujith | 8ee5afb | 2008-12-07 21:43:36 +0530 | [diff] [blame] | 2409 | for (tidno = 0, tid = &an->tid[tidno]; |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2410 | tidno < WME_NUM_TID; |
| 2411 | tidno++, tid++) { |
| 2412 | tid->an = an; |
| 2413 | tid->tidno = tidno; |
| 2414 | tid->seq_start = tid->seq_next = 0; |
| 2415 | tid->baw_size = WME_MAX_BA; |
| 2416 | tid->baw_head = tid->baw_tail = 0; |
| 2417 | tid->sched = false; |
| 2418 | tid->paused = false; |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 2419 | tid->state &= ~AGGR_CLEANUP; |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2420 | INIT_LIST_HEAD(&tid->buf_q); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2421 | |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2422 | acno = TID_TO_WME_AC(tidno); |
Sujith | 8ee5afb | 2008-12-07 21:43:36 +0530 | [diff] [blame] | 2423 | tid->ac = &an->ac[acno]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2424 | |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2425 | /* ADDBA state */ |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 2426 | tid->state &= ~AGGR_ADDBA_COMPLETE; |
| 2427 | tid->state &= ~AGGR_ADDBA_PROGRESS; |
| 2428 | tid->addba_exchangeattempts = 0; |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2429 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2430 | |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2431 | /* |
| 2432 | * Init per ac tx state |
| 2433 | */ |
Sujith | 8ee5afb | 2008-12-07 21:43:36 +0530 | [diff] [blame] | 2434 | for (acno = 0, ac = &an->ac[acno]; |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2435 | acno < WME_NUM_AC; acno++, ac++) { |
| 2436 | ac->sched = false; |
| 2437 | INIT_LIST_HEAD(&ac->tid_q); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2438 | |
Sujith | c517016 | 2008-10-29 10:13:59 +0530 | [diff] [blame] | 2439 | switch (acno) { |
| 2440 | case WME_AC_BE: |
| 2441 | ac->qnum = ath_tx_get_qnum(sc, |
| 2442 | ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE); |
| 2443 | break; |
| 2444 | case WME_AC_BK: |
| 2445 | ac->qnum = ath_tx_get_qnum(sc, |
| 2446 | ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BK); |
| 2447 | break; |
| 2448 | case WME_AC_VI: |
| 2449 | ac->qnum = ath_tx_get_qnum(sc, |
| 2450 | ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VI); |
| 2451 | break; |
| 2452 | case WME_AC_VO: |
| 2453 | ac->qnum = ath_tx_get_qnum(sc, |
| 2454 | ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_VO); |
| 2455 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2456 | } |
| 2457 | } |
| 2458 | } |
| 2459 | |
| 2460 | /* Cleanupthe pending buffers for the node. */ |
| 2461 | |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 2462 | 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] | 2463 | { |
| 2464 | int i; |
| 2465 | struct ath_atx_ac *ac, *ac_tmp; |
| 2466 | struct ath_atx_tid *tid, *tid_tmp; |
| 2467 | struct ath_txq *txq; |
| 2468 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { |
| 2469 | if (ATH_TXQ_SETUP(sc, i)) { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2470 | txq = &sc->tx.txq[i]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2471 | |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 2472 | spin_lock(&txq->axq_lock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2473 | |
| 2474 | list_for_each_entry_safe(ac, |
| 2475 | ac_tmp, &txq->axq_acq, list) { |
| 2476 | tid = list_first_entry(&ac->tid_q, |
| 2477 | struct ath_atx_tid, list); |
| 2478 | if (tid && tid->an != an) |
| 2479 | continue; |
| 2480 | list_del(&ac->list); |
| 2481 | ac->sched = false; |
| 2482 | |
| 2483 | list_for_each_entry_safe(tid, |
| 2484 | tid_tmp, &ac->tid_q, list) { |
| 2485 | list_del(&tid->list); |
| 2486 | tid->sched = false; |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 2487 | ath_tid_drain(sc, txq, tid); |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 2488 | tid->state &= ~AGGR_ADDBA_COMPLETE; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2489 | tid->addba_exchangeattempts = 0; |
Sujith | a37c2c7 | 2008-10-29 10:15:40 +0530 | [diff] [blame] | 2490 | tid->state &= ~AGGR_CLEANUP; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2491 | } |
| 2492 | } |
| 2493 | |
Sujith | b5aa9bf | 2008-10-29 10:13:31 +0530 | [diff] [blame] | 2494 | spin_unlock(&txq->axq_lock); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2495 | } |
| 2496 | } |
| 2497 | } |
| 2498 | |
Jouni Malinen | e022edb | 2008-08-22 17:31:33 +0300 | [diff] [blame] | 2499 | void ath_tx_cabq(struct ath_softc *sc, struct sk_buff *skb) |
| 2500 | { |
| 2501 | int hdrlen, padsize; |
| 2502 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 2503 | struct ath_tx_control txctl; |
| 2504 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 2505 | memset(&txctl, 0, sizeof(struct ath_tx_control)); |
| 2506 | |
Jouni Malinen | e022edb | 2008-08-22 17:31:33 +0300 | [diff] [blame] | 2507 | /* |
| 2508 | * As a temporary workaround, assign seq# here; this will likely need |
| 2509 | * to be cleaned up to work better with Beacon transmission and virtual |
| 2510 | * BSSes. |
| 2511 | */ |
| 2512 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
| 2513 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 2514 | if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2515 | sc->tx.seq_no += 0x10; |
Jouni Malinen | e022edb | 2008-08-22 17:31:33 +0300 | [diff] [blame] | 2516 | hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2517 | hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no); |
Jouni Malinen | e022edb | 2008-08-22 17:31:33 +0300 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | /* Add the padding after the header if this is not already done */ |
| 2521 | hdrlen = ieee80211_get_hdrlen_from_skb(skb); |
| 2522 | if (hdrlen & 3) { |
| 2523 | padsize = hdrlen % 4; |
| 2524 | if (skb_headroom(skb) < padsize) { |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2525 | DPRINTF(sc, ATH_DBG_XMIT, "TX CABQ padding failed\n"); |
Jouni Malinen | e022edb | 2008-08-22 17:31:33 +0300 | [diff] [blame] | 2526 | dev_kfree_skb_any(skb); |
| 2527 | return; |
| 2528 | } |
| 2529 | skb_push(skb, padsize); |
| 2530 | memmove(skb->data, skb->data + padsize, hdrlen); |
| 2531 | } |
| 2532 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame^] | 2533 | txctl.txq = sc->beacon.cabq; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 2534 | |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2535 | DPRINTF(sc, ATH_DBG_XMIT, "transmitting CABQ packet, skb: %p\n", skb); |
Jouni Malinen | e022edb | 2008-08-22 17:31:33 +0300 | [diff] [blame] | 2536 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 2537 | if (ath_tx_start(sc, skb, &txctl) != 0) { |
Sujith | 04bd4638 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 2538 | DPRINTF(sc, ATH_DBG_XMIT, "CABQ TX failed\n"); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 2539 | goto exit; |
Jouni Malinen | e022edb | 2008-08-22 17:31:33 +0300 | [diff] [blame] | 2540 | } |
Jouni Malinen | e022edb | 2008-08-22 17:31:33 +0300 | [diff] [blame] | 2541 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 2542 | return; |
| 2543 | exit: |
| 2544 | dev_kfree_skb_any(skb); |
| 2545 | } |