21 #define BITS_PER_BYTE 8
22 #define OFDM_PLCP_BITS 22
23 #define HT_RC_2_STREAMS(_rc) ((((_rc) & 0x78) >> 3) + 1)
29 #define HT_LTF(_ns) (4 * (_ns))
30 #define SYMBOL_TIME(_ns) ((_ns) << 2)
31 #define SYMBOL_TIME_HALFGI(_ns) (((_ns) * 18 + 4) / 5)
32 #define TIME_SYMBOLS(t) ((t) >> 2)
33 #define TIME_SYMBOLS_HALFGI(t) (((t) * 5 - 4) / 18)
34 #define NUM_SYMBOLS_PER_USEC(_usec) (_usec >> 2)
35 #define NUM_SYMBOLS_PER_USEC_HALFGI(_usec) (((_usec*5)-4)/18)
38 static u16 bits_per_symbol[][2] = {
50 #define IS_HT_RATE(_rate) ((_rate) & 0x80)
55 int tx_flags,
struct ath_txq *txq);
85 spin_lock_bh(&txq->axq_lock);
91 spin_unlock_bh(&txq->axq_lock);
100 __skb_queue_head_init(&q);
101 skb_queue_splice_init(&txq->complete_q, &q);
102 spin_unlock_bh(&txq->axq_lock);
104 while ((skb = __skb_dequeue(&q)))
137 if (skb_queue_empty(&tid->
buf_q))
140 ath_tx_queue_tid(txq, tid);
168 bool sendbar =
false;
170 INIT_LIST_HEAD(&bf_head);
174 while ((skb = __skb_dequeue(&tid->
buf_q))) {
175 fi = get_frame_info(skb);
179 bf = ath_tx_setup_buffer(sc, txq, tid, skb);
188 ath_tx_update_baw(sc, tid, bf->
bf_state.seqno);
189 ath_tx_complete_buf(sc, bf, txq, &bf_head, &
ts, 0);
192 ath_tx_send_normal(sc, txq,
NULL, skb);
259 INIT_LIST_HEAD(&bf_head);
261 while ((skb = __skb_dequeue(&tid->
buf_q))) {
262 fi = get_frame_info(skb);
273 ath_tx_update_baw(sc, tid, bf->
bf_state.seqno);
275 ath_tx_complete_buf(sc, bf, txq, &bf_head, &
ts, 0);
307 spin_lock_bh(&sc->
tx.txbuflock);
310 spin_unlock_bh(&sc->
tx.txbuflock);
318 spin_unlock_bh(&sc->
tx.txbuflock);
325 spin_lock_bh(&sc->
tx.txbuflock);
327 spin_unlock_bh(&sc->
tx.txbuflock);
334 tbf = ath_tx_get_buffer(sc);
350 int *nframes,
int *nbad)
368 fi = get_frame_info(bf->
bf_mpdu);
394 u16 seq_st = 0, acked_cnt = 0, txfail_cnt = 0, seq_first;
396 int isaggr,
txfail, txpending, sendbar = 0, needreset = 0, nbad = 0;
397 bool rc_update =
true, isba;
409 tx_info = IEEE80211_SKB_CB(skb);
415 retries += rates[i].count;
423 INIT_LIST_HEAD(&bf_head);
428 list_move_tail(&bf->
list, &bf_head);
430 ath_tx_complete_buf(sc, bf, txq, &bf_head, ts, 0);
437 an = (
struct ath_node *)sta->drv_priv;
451 if (isba && tidno != ts->
tid)
457 if (isaggr && txok) {
474 __skb_queue_head_init(&bf_pending);
476 ath_tx_count_frames(sc, bf, ts, txok, &nframes, &nbad);
480 txfail = txpending = sendbar = 0;
484 tx_info = IEEE80211_SKB_CB(skb);
485 fi = get_frame_info(skb);
491 }
else if (!isaggr && txok) {
504 ath_tx_set_retry(sc, txq, bf->
bf_mpdu,
511 bar_index =
max_t(
int, bar_index,
519 INIT_LIST_HEAD(&bf_head);
522 list_move_tail(&bf->
list, &bf_head);
529 ath_tx_update_baw(sc, tid, seqno);
531 if (rc_update && (acked_cnt == 1 || txfail_cnt == 1)) {
533 ath_tx_rc_status(sc, bf, ts, nframes, nbad, txok);
537 ath_tx_complete_buf(sc, bf, txq, &bf_head, ts,
545 tbf = ath_clone_txbuf(sc, bf_last);
552 ath_tx_update_baw(sc, tid, seqno);
554 ath_tx_complete_buf(sc, bf, txq,
556 bar_index =
max_t(
int, bar_index,
568 __skb_queue_tail(&bf_pending, skb);
575 if (!skb_queue_empty(&bf_pending)) {
579 skb_queue_splice(&bf_pending, &tid->
buf_q);
581 ath_tx_queue_tid(txq, tid);
584 tid->
ac->clear_ps_filter =
true;
588 if (bar_index >= 0) {
600 ath_tx_flush_tid(sc, tid);
608 static bool ath_lookup_legacy(
struct ath_buf *bf)
616 tx_info = IEEE80211_SKB_CB(skb);
617 rates = tx_info->
control.rates;
619 for (i = 0; i < 4; i++) {
620 if (!rates[i].count || rates[i].
idx < 0)
636 u32 max_4ms_framelen, frmlen;
637 u16 aggr_limit, bt_aggr_limit, legacy = 0;
638 int q = tid->
ac->txq->mac80211_qnum;
642 tx_info = IEEE80211_SKB_CB(skb);
643 rates = tx_info->
control.rates;
651 for (i = 0; i < 4; i++) {
670 frmlen = sc->
tx.max_aggr_framelen[
q][modeidx][rates[
i].
idx];
671 max_4ms_framelen =
min(max_4ms_framelen, frmlen);
687 bt_aggr_limit = ath9k_btcoex_aggr_limit(sc, max_4ms_framelen);
689 aggr_limit = bt_aggr_limit;
696 if (tid->
an->maxampdu)
697 aggr_limit =
min(aggr_limit, tid->
an->maxampdu);
710 #define FIRST_DESC_NDELIMS 60
713 u32 nsymbits, nsymbols;
738 ndelim =
max(ndelim, FIRST_DESC_NDELIMS);
750 if (tid->
an->mpdudensity == 0)
753 rix = tx_info->
control.rates[0].idx;
754 flags = tx_info->
control.rates[0].flags;
770 if (frmlen < minlen) {
772 ndelim =
max(mindelim, ndelim);
784 #define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
786 int rl = 0, nframes = 0, ndelim, prev_al = 0;
787 u16 aggr_limit = 0, al = 0, bpad = 0,
788 al_delta, h_baw = tid->
baw_size / 2;
796 skb = skb_peek(&tid->
buf_q);
797 fi = get_frame_info(skb);
800 bf = ath_tx_setup_buffer(sc, txq, tid, skb);
803 __skb_unlink(skb, &tid->
buf_q);
821 INIT_LIST_HEAD(&bf_head);
822 list_add(&bf->
list, &bf_head);
823 __skb_unlink(skb, &tid->
buf_q);
824 ath_tx_update_baw(sc, tid, seqno);
825 ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
833 aggr_limit = ath_lookup_rate(sc, bf, tid);
841 ((aggr_limit < (al + bpad + al_delta + prev_al)) ||
842 ath_lookup_legacy(bf))) {
847 tx_info = IEEE80211_SKB_CB(bf->
bf_mpdu);
858 al += bpad + al_delta;
864 ndelim = ath_compute_num_delims(sc, tid, bf_first, fi->
framelen,
866 bpad =
PADBYTES(al_delta) + (ndelim << 2);
873 ath_tx_addto_baw(sc, tid, seqno);
876 __skb_unlink(skb, &tid->
buf_q);
879 bf_prev->bf_next =
bf;
883 }
while (!skb_queue_empty(&tid->
buf_q));
898 int width,
int half_gi,
bool shortPreamble)
907 nsymbols = (nbits + nsymbits - 1) / nsymbits;
920 static int ath_max_framelen(
int usec,
int mcs,
bool ht40,
bool sgi)
927 bits = symbols * bits_per_symbol[mcs % 8][ht40] *
streams;
939 u16 *cur_ht20, *cur_ht20_sgi, *cur_ht40, *cur_ht40_sgi;
943 if (!txop || txop > 4096)
946 cur_ht20 = sc->
tx.max_aggr_framelen[queue][
MCS_HT20];
948 cur_ht40 = sc->
tx.max_aggr_framelen[queue][
MCS_HT40];
950 for (mcs = 0; mcs < 32; mcs++) {
951 cur_ht20[
mcs] = ath_max_framelen(txop, mcs,
false,
false);
952 cur_ht20_sgi[
mcs] = ath_max_framelen(txop, mcs,
false,
true);
953 cur_ht40[
mcs] = ath_max_framelen(txop, mcs,
true,
false);
954 cur_ht40_sgi[
mcs] = ath_max_framelen(txop, mcs,
true,
true);
972 tx_info = IEEE80211_SKB_CB(skb);
973 rates = tx_info->
control.rates;
980 for (i = 0; i < 4; i++) {
981 bool is_40, is_sgi, is_sp;
984 if (!rates[i].count || (rates[i].
idx < 0))
998 if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
1007 if (rates[i].flags & IEEE80211_TX_RC_MCS) {
1009 info->
rates[
i].Rate = rix | 0x80;
1012 info->
rates[
i].PktDuration = ath_pkt_duration(sc, rix, len,
1013 is_40, is_sgi, is_sp);
1042 phy, rate->
bitrate * 100, len, rix, is_sp);
1063 if (ieee80211_is_beacon(fc))
1065 else if (ieee80211_is_probe_resp(fc))
1067 else if (ieee80211_is_atim(fc))
1069 else if (ieee80211_is_pspoll(fc))
1086 memset(&info, 0,
sizeof(info));
1098 ath_buf_set_rate(sc, bf, &info, len);
1111 info.
type = get_hw_packet_type(skb);
1135 ath9k_hw_set_txdesc(ah, bf->
bf_desc, &info);
1150 if (skb_queue_empty(&tid->
buf_q))
1153 INIT_LIST_HEAD(&bf_q);
1155 status = ath_tx_form_aggr(sc, txq, tid, &bf_q, &aggr_len);
1161 if (list_empty(&bf_q))
1166 tx_info = IEEE80211_SKB_CB(bf->
bf_mpdu);
1168 if (tid->
ac->clear_ps_filter) {
1169 tid->
ac->clear_ps_filter =
false;
1177 aggr_len = get_frame_info(bf->
bf_mpdu)->framelen;
1183 ath_tx_fill_desc(sc, bf, txq, aggr_len);
1184 ath_tx_txqaddbuf(sc, txq, &bf_q,
false);
1196 an = (
struct ath_node *)sta->drv_priv;
1208 sta->
ht_cap.ampdu_factor);
1228 struct ath_txq *txq = txtid->ac->txq;
1239 txtid->paused =
true;
1247 if (txtid->baw_head != txtid->baw_tail)
1252 ath_tx_flush_tid(sc, txtid);
1265 for (tidno = 0, tid = &an->
tid[tidno];
1276 buffered = !skb_queue_empty(&tid->
buf_q);
1299 for (tidno = 0, tid = &an->
tid[tidno];
1308 if (!skb_queue_empty(&tid->
buf_q) && !tid->
paused) {
1309 ath_tx_queue_tid(txq, tid);
1322 an = (
struct ath_node *)sta->drv_priv;
1328 ath_tx_resume_tid(sc, txtid);
1335 static void ath_txq_drain_pending_buffers(
struct ath_softc *sc,
1347 ath_tid_drain(sc, txq, tid);
1356 static const int subtype_txq_to_hwq[] = {
1364 memset(&qi, 0,
sizeof(qi));
1396 if (axq_qnum == -1) {
1410 INIT_LIST_HEAD(&txq->
axq_q);
1411 INIT_LIST_HEAD(&txq->
axq_acq);
1432 BUG_ON(sc->
tx.txq[qnum].axq_qnum != qnum);
1443 "Unable to update hardware queue %u!\n", qnum);
1456 int qnum = sc->
beacon.cabq->axq_qnum;
1468 sc->
config.cabqReadytime) / 100;
1474 static bool bf_is_ampdu_not_probing(
struct ath_buf *bf)
1487 memset(&ts, 0,
sizeof(ts));
1489 INIT_LIST_HEAD(&bf_head);
1491 while (!list_empty(list)) {
1497 ath_tx_return_buffer(sc, bf);
1502 list_cut_position(&bf_head, list, &lastbf->
list);
1505 if (bf_is_ampdu_not_probing(bf))
1509 ath_tx_complete_aggr(sc, txq, bf, &bf_head, &ts, 0,
1512 ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
1529 while (!list_empty(&txq->
txq_fifo[idx])) {
1530 ath_drain_txq_list(sc, txq, &txq->
txq_fifo[idx],
1540 ath_drain_txq_list(sc, txq, &txq->
axq_q, retry_tx);
1544 ath_txq_drain_pending_buffers(sc, txq);
1572 ath_err(common,
"Failed to stop TX DMA, queues=0x%03x!\n", npend);
1583 txq = &sc->
tx.txq[
i];
1618 while (!list_empty(&ac->
tid_q)) {
1627 ath_tx_sched_aggr(sc, txq, tid);
1633 if (!skb_queue_empty(&tid->
buf_q))
1634 ath_tx_queue_tid(txq, tid);
1636 if (tid == last_tid ||
1646 if (ac == last_ac ||
1666 bool puttxbuf =
false;
1674 if (list_empty(head))
1689 list_splice_tail_init(head, &txq->
axq_q);
1693 ath_dbg(common, XMIT,
"link[%u] (%p)=%llx (%p)\n",
1705 ath_dbg(common, XMIT,
"TXDP[%u] = %llx (%p)\n",
1716 if (bf_is_ampdu_not_probing(bf))
1735 if (!skb_queue_empty(&tid->
buf_q) || tid->
paused ||
1743 __skb_queue_tail(&tid->
buf_q, skb);
1744 if (!txctl->
an || !txctl->
an->sleeping)
1745 ath_tx_queue_tid(txctl->
txq, tid);
1749 bf = ath_tx_setup_buffer(sc, txctl->
txq, tid, skb);
1756 INIT_LIST_HEAD(&bf_head);
1757 list_add(&bf->
list, &bf_head);
1760 ath_tx_addto_baw(sc, tid, bf->
bf_state.seqno);
1765 ath_tx_fill_desc(sc, bf, txctl->
txq, fi->
framelen);
1766 ath_tx_txqaddbuf(sc, txctl->
txq, &bf_head,
false);
1778 INIT_LIST_HEAD(&bf_head);
1784 ath_tx_fill_desc(sc, bf, txq, fi->
framelen);
1785 ath_tx_txqaddbuf(sc, txq, &bf_head,
false);
1801 bool short_preamble =
false;
1809 tx_info->
control.vif->bss_conf.use_short_preamble)
1810 short_preamble =
true;
1812 rate = ieee80211_get_rts_cts_rate(hw, tx_info);
1816 an = (
struct ath_node *) sta->drv_priv;
1818 memset(fi, 0,
sizeof(*fi));
1839 (chainmask == 0x7) && (rate < 0x90))
1841 else if (
AR_SREV_9462(ah) && ath9k_hw_btcoex_is_enabled(ah) &&
1864 bf = ath_tx_get_buffer(sc);
1866 ath_dbg(common, XMIT,
"TX buffers are full\n");
1894 "dma_mapping_error() on TX\n");
1895 ath_tx_return_buffer(sc, bf);
1916 tidno = ieee80211_get_qos_ctl(hdr)[0] &
1928 ath_tx_send_ampdu(sc, tid, skb, txctl);
1930 bf = ath_tx_setup_buffer(sc, txctl->
txq, tid, skb);
1944 ath_tx_send_normal(sc, txctl->
txq, tid, skb);
1964 txctl->
an = (
struct ath_node *)sta->drv_priv;
1966 if (info->control.hw_key)
1967 frmlen += info->control.hw_key->icv_len;
1976 sc->
tx.seq_no += 0x10;
1983 padsize = padpos & 3;
1984 if (padsize && skb->
len > padpos) {
1985 if (skb_headroom(skb) < padsize)
1998 setup_frame_info(hw, sta, skb, frmlen);
2005 q = skb_get_queue_mapping(skb);
2008 if (txq == sc->
tx.txq_map[q] &&
2015 ath_tx_start_dma(sc, skb, txctl);
2027 int tx_flags,
struct ath_txq *txq)
2033 unsigned long flags;
2035 ath_dbg(common, XMIT,
"TX complete: skb: %p\n", skb);
2037 if (sc->
sc_ah->caldata)
2038 sc->
sc_ah->caldata->paprd_packet_sent =
true;
2059 "Going back to sleep after having received TX status (0x%lx)\n",
2065 spin_unlock_irqrestore(&sc->
sc_pm_lock, flags);
2067 q = skb_get_queue_mapping(skb);
2068 if (txq == sc->
tx.txq_map[q]) {
2088 unsigned long flags;
2109 ath_tx_complete(sc, skb, tx_flags, txq);
2120 list_splice_tail_init(bf_q, &sc->
tx.txbuf);
2121 spin_unlock_irqrestore(&sc->
tx.txbuflock, flags);
2146 tx_info->
status.ampdu_len = nframes;
2147 tx_info->
status.ampdu_ack_len = nframes - nbad;
2167 tx_info->
status.rates[tx_rateindex].count =
2171 for (i = tx_rateindex + 1; i < hw->
max_rates; i++) {
2172 tx_info->
status.rates[
i].count = 0;
2173 tx_info->
status.rates[
i].idx = -1;
2179 static void ath_tx_process_buffer(
struct ath_softc *sc,
struct ath_txq *txq,
2188 if (bf_is_ampdu_not_probing(bf))
2192 ath_tx_rc_status(sc, bf, ts, 1, txok ? 0 : 1, txok);
2193 ath_tx_complete_buf(sc, bf, txq, bf_head, ts, txok);
2195 ath_tx_complete_aggr(sc, txq, bf, bf_head, ts, txok,
true);
2204 struct ath_common *common = ath9k_hw_common(ah);
2220 if (list_empty(&txq->
axq_q)) {
2239 if (list_is_last(&bf_held->
list, &txq->
axq_q))
2249 memset(&ts, 0,
sizeof(ts));
2250 status = ath9k_hw_txprocdesc(ah, ds, &ts);
2262 INIT_LIST_HEAD(&bf_head);
2263 if (!list_is_singular(&lastbf->
list))
2264 list_cut_position(&bf_head,
2269 ath_tx_return_buffer(sc, bf_held);
2272 ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head);
2285 ath_tx_processq(sc, &sc->
tx.txq[i]);
2303 status = ath9k_hw_txprocdesc(ah,
NULL, (
void *)&ts);
2306 if (status == -
EIO) {
2307 ath_dbg(common, XMIT,
"Error processing tx status\n");
2313 sc->
beacon.tx_processed =
true;
2318 txq = &sc->
tx.txq[ts.
qid];
2331 INIT_LIST_HEAD(&bf_head);
2338 if (!list_empty(&txq->
axq_q)) {
2341 INIT_LIST_HEAD(&bf_q);
2343 list_splice_tail_init(&txq->
axq_q, &bf_q);
2344 ath_tx_txqaddbuf(sc, txq, &bf_q,
true);
2348 ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head);
2357 static int ath_txstatus_setup(
struct ath_softc *sc,
int size)
2360 u8 txs_len = sc->
sc_ah->caps.txs_len;
2371 static int ath_tx_edma_init(
struct ath_softc *sc)
2378 sc->
txsdma.dd_desc_paddr,
2384 static void ath_tx_edma_cleanup(
struct ath_softc *sc)
2403 "Failed to allocate tx descriptors: %d\n", error);
2411 "Failed to allocate beacon descriptors: %d\n", error);
2418 error = ath_tx_edma_init(sc);
2432 if (sc->
beacon.bdma.dd_desc_len != 0)
2435 if (sc->
tx.txdma.dd_desc_len != 0)
2439 ath_tx_edma_cleanup(sc);
2448 for (tidno = 0, tid = &an->
tid[tidno];
2459 __skb_queue_head_init(&tid->
buf_q);
2461 tid->
ac = &an->
ac[acno];
2466 for (acno = 0, ac = &an->
ac[acno];
2469 ac->
txq = sc->
tx.txq_map[acno];
2470 INIT_LIST_HEAD(&ac->
tid_q);
2481 for (tidno = 0, tid = &an->
tid[tidno];
2496 tid->
ac->sched =
false;
2499 ath_tid_drain(sc, txq, tid);