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