2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <linux/etherdevice.h>
25 static u8
ath10k_htt_tx_txq_calc_size(size_t count
)
33 while (factor
>= 64 && exp
< 4) {
42 factor
= max(1, factor
);
44 return SM(exp
, HTT_TX_Q_STATE_ENTRY_EXP
) |
45 SM(factor
, HTT_TX_Q_STATE_ENTRY_FACTOR
);
48 static void __ath10k_htt_tx_txq_recalc(struct ieee80211_hw
*hw
,
49 struct ieee80211_txq
*txq
)
51 struct ath10k
*ar
= hw
->priv
;
52 struct ath10k_sta
*arsta
;
53 struct ath10k_vif
*arvif
= (void *)txq
->vif
->drv_priv
;
54 unsigned long frame_cnt
;
55 unsigned long byte_cnt
;
62 lockdep_assert_held(&ar
->htt
.tx_lock
);
64 if (!ar
->htt
.tx_q_state
.enabled
)
67 if (ar
->htt
.tx_q_state
.mode
!= HTT_TX_MODE_SWITCH_PUSH_PULL
)
71 arsta
= (void *)txq
->sta
->drv_priv
;
72 peer_id
= arsta
->peer_id
;
74 peer_id
= arvif
->peer_id
;
78 bit
= BIT(peer_id
% 32);
81 ieee80211_txq_get_depth(txq
, &frame_cnt
, &byte_cnt
);
82 count
= ath10k_htt_tx_txq_calc_size(byte_cnt
);
84 if (unlikely(peer_id
>= ar
->htt
.tx_q_state
.num_peers
) ||
85 unlikely(tid
>= ar
->htt
.tx_q_state
.num_tids
)) {
86 ath10k_warn(ar
, "refusing to update txq for peer_id %hu tid %hhu due to out of bounds\n",
91 ar
->htt
.tx_q_state
.vaddr
->count
[tid
][peer_id
] = count
;
92 ar
->htt
.tx_q_state
.vaddr
->map
[tid
][idx
] &= ~bit
;
93 ar
->htt
.tx_q_state
.vaddr
->map
[tid
][idx
] |= count
? bit
: 0;
95 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "htt tx txq state update peer_id %hu tid %hhu count %hhu\n",
99 static void __ath10k_htt_tx_txq_sync(struct ath10k
*ar
)
104 lockdep_assert_held(&ar
->htt
.tx_lock
);
106 if (!ar
->htt
.tx_q_state
.enabled
)
109 if (ar
->htt
.tx_q_state
.mode
!= HTT_TX_MODE_SWITCH_PUSH_PULL
)
112 seq
= le32_to_cpu(ar
->htt
.tx_q_state
.vaddr
->seq
);
114 ar
->htt
.tx_q_state
.vaddr
->seq
= cpu_to_le32(seq
);
116 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "htt tx txq state update commit seq %u\n",
119 size
= sizeof(*ar
->htt
.tx_q_state
.vaddr
);
120 dma_sync_single_for_device(ar
->dev
,
121 ar
->htt
.tx_q_state
.paddr
,
126 void ath10k_htt_tx_txq_recalc(struct ieee80211_hw
*hw
,
127 struct ieee80211_txq
*txq
)
129 struct ath10k
*ar
= hw
->priv
;
131 spin_lock_bh(&ar
->htt
.tx_lock
);
132 __ath10k_htt_tx_txq_recalc(hw
, txq
);
133 spin_unlock_bh(&ar
->htt
.tx_lock
);
136 void ath10k_htt_tx_txq_sync(struct ath10k
*ar
)
138 spin_lock_bh(&ar
->htt
.tx_lock
);
139 __ath10k_htt_tx_txq_sync(ar
);
140 spin_unlock_bh(&ar
->htt
.tx_lock
);
143 void ath10k_htt_tx_txq_update(struct ieee80211_hw
*hw
,
144 struct ieee80211_txq
*txq
)
146 struct ath10k
*ar
= hw
->priv
;
148 spin_lock_bh(&ar
->htt
.tx_lock
);
149 __ath10k_htt_tx_txq_recalc(hw
, txq
);
150 __ath10k_htt_tx_txq_sync(ar
);
151 spin_unlock_bh(&ar
->htt
.tx_lock
);
154 void ath10k_htt_tx_dec_pending(struct ath10k_htt
*htt
)
156 lockdep_assert_held(&htt
->tx_lock
);
158 htt
->num_pending_tx
--;
159 if (htt
->num_pending_tx
== htt
->max_num_pending_tx
- 1)
160 ath10k_mac_tx_unlock(htt
->ar
, ATH10K_TX_PAUSE_Q_FULL
);
163 int ath10k_htt_tx_inc_pending(struct ath10k_htt
*htt
)
165 lockdep_assert_held(&htt
->tx_lock
);
167 if (htt
->num_pending_tx
>= htt
->max_num_pending_tx
)
170 htt
->num_pending_tx
++;
171 if (htt
->num_pending_tx
== htt
->max_num_pending_tx
)
172 ath10k_mac_tx_lock(htt
->ar
, ATH10K_TX_PAUSE_Q_FULL
);
177 int ath10k_htt_tx_mgmt_inc_pending(struct ath10k_htt
*htt
, bool is_mgmt
,
180 struct ath10k
*ar
= htt
->ar
;
182 lockdep_assert_held(&htt
->tx_lock
);
184 if (!is_mgmt
|| !ar
->hw_params
.max_probe_resp_desc_thres
)
188 ar
->hw_params
.max_probe_resp_desc_thres
< htt
->num_pending_mgmt_tx
)
191 htt
->num_pending_mgmt_tx
++;
196 void ath10k_htt_tx_mgmt_dec_pending(struct ath10k_htt
*htt
)
198 lockdep_assert_held(&htt
->tx_lock
);
200 if (!htt
->ar
->hw_params
.max_probe_resp_desc_thres
)
203 htt
->num_pending_mgmt_tx
--;
206 int ath10k_htt_tx_alloc_msdu_id(struct ath10k_htt
*htt
, struct sk_buff
*skb
)
208 struct ath10k
*ar
= htt
->ar
;
211 lockdep_assert_held(&htt
->tx_lock
);
213 ret
= idr_alloc(&htt
->pending_tx
, skb
, 0,
214 htt
->max_num_pending_tx
, GFP_ATOMIC
);
216 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "htt tx alloc msdu_id %d\n", ret
);
221 void ath10k_htt_tx_free_msdu_id(struct ath10k_htt
*htt
, u16 msdu_id
)
223 struct ath10k
*ar
= htt
->ar
;
225 lockdep_assert_held(&htt
->tx_lock
);
227 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "htt tx free msdu_id %hu\n", msdu_id
);
229 idr_remove(&htt
->pending_tx
, msdu_id
);
232 static void ath10k_htt_tx_free_cont_txbuf_32(struct ath10k_htt
*htt
)
234 struct ath10k
*ar
= htt
->ar
;
237 if (!htt
->txbuf
.vaddr_txbuff_32
)
240 size
= htt
->txbuf
.size
;
241 dma_free_coherent(ar
->dev
, size
, htt
->txbuf
.vaddr_txbuff_32
,
243 htt
->txbuf
.vaddr_txbuff_32
= NULL
;
246 static int ath10k_htt_tx_alloc_cont_txbuf_32(struct ath10k_htt
*htt
)
248 struct ath10k
*ar
= htt
->ar
;
251 size
= htt
->max_num_pending_tx
*
252 sizeof(struct ath10k_htt_txbuf_32
);
254 htt
->txbuf
.vaddr_txbuff_32
= dma_alloc_coherent(ar
->dev
, size
,
257 if (!htt
->txbuf
.vaddr_txbuff_32
)
260 htt
->txbuf
.size
= size
;
265 static void ath10k_htt_tx_free_cont_txbuf_64(struct ath10k_htt
*htt
)
267 struct ath10k
*ar
= htt
->ar
;
270 if (!htt
->txbuf
.vaddr_txbuff_64
)
273 size
= htt
->txbuf
.size
;
274 dma_free_coherent(ar
->dev
, size
, htt
->txbuf
.vaddr_txbuff_64
,
276 htt
->txbuf
.vaddr_txbuff_64
= NULL
;
279 static int ath10k_htt_tx_alloc_cont_txbuf_64(struct ath10k_htt
*htt
)
281 struct ath10k
*ar
= htt
->ar
;
284 size
= htt
->max_num_pending_tx
*
285 sizeof(struct ath10k_htt_txbuf_64
);
287 htt
->txbuf
.vaddr_txbuff_64
= dma_alloc_coherent(ar
->dev
, size
,
290 if (!htt
->txbuf
.vaddr_txbuff_64
)
293 htt
->txbuf
.size
= size
;
298 static void ath10k_htt_tx_free_cont_frag_desc_32(struct ath10k_htt
*htt
)
302 if (!htt
->frag_desc
.vaddr_desc_32
)
305 size
= htt
->max_num_pending_tx
*
306 sizeof(struct htt_msdu_ext_desc
);
308 dma_free_coherent(htt
->ar
->dev
,
310 htt
->frag_desc
.vaddr_desc_32
,
311 htt
->frag_desc
.paddr
);
313 htt
->frag_desc
.vaddr_desc_32
= NULL
;
316 static int ath10k_htt_tx_alloc_cont_frag_desc_32(struct ath10k_htt
*htt
)
318 struct ath10k
*ar
= htt
->ar
;
321 if (!ar
->hw_params
.continuous_frag_desc
)
324 size
= htt
->max_num_pending_tx
*
325 sizeof(struct htt_msdu_ext_desc
);
326 htt
->frag_desc
.vaddr_desc_32
= dma_alloc_coherent(ar
->dev
, size
,
327 &htt
->frag_desc
.paddr
,
329 if (!htt
->frag_desc
.vaddr_desc_32
) {
330 ath10k_err(ar
, "failed to alloc fragment desc memory\n");
333 htt
->frag_desc
.size
= size
;
338 static void ath10k_htt_tx_free_cont_frag_desc_64(struct ath10k_htt
*htt
)
342 if (!htt
->frag_desc
.vaddr_desc_64
)
345 size
= htt
->max_num_pending_tx
*
346 sizeof(struct htt_msdu_ext_desc_64
);
348 dma_free_coherent(htt
->ar
->dev
,
350 htt
->frag_desc
.vaddr_desc_64
,
351 htt
->frag_desc
.paddr
);
353 htt
->frag_desc
.vaddr_desc_64
= NULL
;
356 static int ath10k_htt_tx_alloc_cont_frag_desc_64(struct ath10k_htt
*htt
)
358 struct ath10k
*ar
= htt
->ar
;
361 if (!ar
->hw_params
.continuous_frag_desc
)
364 size
= htt
->max_num_pending_tx
*
365 sizeof(struct htt_msdu_ext_desc_64
);
367 htt
->frag_desc
.vaddr_desc_64
= dma_alloc_coherent(ar
->dev
, size
,
368 &htt
->frag_desc
.paddr
,
370 if (!htt
->frag_desc
.vaddr_desc_64
) {
371 ath10k_err(ar
, "failed to alloc fragment desc memory\n");
374 htt
->frag_desc
.size
= size
;
379 static void ath10k_htt_tx_free_txq(struct ath10k_htt
*htt
)
381 struct ath10k
*ar
= htt
->ar
;
384 if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL
,
385 ar
->running_fw
->fw_file
.fw_features
))
388 size
= sizeof(*htt
->tx_q_state
.vaddr
);
390 dma_unmap_single(ar
->dev
, htt
->tx_q_state
.paddr
, size
, DMA_TO_DEVICE
);
391 kfree(htt
->tx_q_state
.vaddr
);
394 static int ath10k_htt_tx_alloc_txq(struct ath10k_htt
*htt
)
396 struct ath10k
*ar
= htt
->ar
;
400 if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL
,
401 ar
->running_fw
->fw_file
.fw_features
))
404 htt
->tx_q_state
.num_peers
= HTT_TX_Q_STATE_NUM_PEERS
;
405 htt
->tx_q_state
.num_tids
= HTT_TX_Q_STATE_NUM_TIDS
;
406 htt
->tx_q_state
.type
= HTT_Q_DEPTH_TYPE_BYTES
;
408 size
= sizeof(*htt
->tx_q_state
.vaddr
);
409 htt
->tx_q_state
.vaddr
= kzalloc(size
, GFP_KERNEL
);
410 if (!htt
->tx_q_state
.vaddr
)
413 htt
->tx_q_state
.paddr
= dma_map_single(ar
->dev
, htt
->tx_q_state
.vaddr
,
414 size
, DMA_TO_DEVICE
);
415 ret
= dma_mapping_error(ar
->dev
, htt
->tx_q_state
.paddr
);
417 ath10k_warn(ar
, "failed to dma map tx_q_state: %d\n", ret
);
418 kfree(htt
->tx_q_state
.vaddr
);
425 static void ath10k_htt_tx_free_txdone_fifo(struct ath10k_htt
*htt
)
427 WARN_ON(!kfifo_is_empty(&htt
->txdone_fifo
));
428 kfifo_free(&htt
->txdone_fifo
);
431 static int ath10k_htt_tx_alloc_txdone_fifo(struct ath10k_htt
*htt
)
436 size
= roundup_pow_of_two(htt
->max_num_pending_tx
);
437 ret
= kfifo_alloc(&htt
->txdone_fifo
, size
, GFP_KERNEL
);
441 static int ath10k_htt_tx_alloc_buf(struct ath10k_htt
*htt
)
443 struct ath10k
*ar
= htt
->ar
;
446 ret
= htt
->tx_ops
->htt_alloc_txbuff(htt
);
448 ath10k_err(ar
, "failed to alloc cont tx buffer: %d\n", ret
);
452 ret
= htt
->tx_ops
->htt_alloc_frag_desc(htt
);
454 ath10k_err(ar
, "failed to alloc cont frag desc: %d\n", ret
);
458 ret
= ath10k_htt_tx_alloc_txq(htt
);
460 ath10k_err(ar
, "failed to alloc txq: %d\n", ret
);
464 ret
= ath10k_htt_tx_alloc_txdone_fifo(htt
);
466 ath10k_err(ar
, "failed to alloc txdone fifo: %d\n", ret
);
473 ath10k_htt_tx_free_txq(htt
);
476 htt
->tx_ops
->htt_free_frag_desc(htt
);
479 htt
->tx_ops
->htt_free_txbuff(htt
);
484 int ath10k_htt_tx_start(struct ath10k_htt
*htt
)
486 struct ath10k
*ar
= htt
->ar
;
489 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "htt tx max num pending tx %d\n",
490 htt
->max_num_pending_tx
);
492 spin_lock_init(&htt
->tx_lock
);
493 idr_init(&htt
->pending_tx
);
495 if (htt
->tx_mem_allocated
)
498 ret
= ath10k_htt_tx_alloc_buf(htt
);
500 goto free_idr_pending_tx
;
502 htt
->tx_mem_allocated
= true;
507 idr_destroy(&htt
->pending_tx
);
512 static int ath10k_htt_tx_clean_up_pending(int msdu_id
, void *skb
, void *ctx
)
514 struct ath10k
*ar
= ctx
;
515 struct ath10k_htt
*htt
= &ar
->htt
;
516 struct htt_tx_done tx_done
= {0};
518 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "force cleanup msdu_id %hu\n", msdu_id
);
520 tx_done
.msdu_id
= msdu_id
;
521 tx_done
.status
= HTT_TX_COMPL_STATE_DISCARD
;
523 ath10k_txrx_tx_unref(htt
, &tx_done
);
528 void ath10k_htt_tx_destroy(struct ath10k_htt
*htt
)
530 if (!htt
->tx_mem_allocated
)
533 htt
->tx_ops
->htt_free_txbuff(htt
);
534 ath10k_htt_tx_free_txq(htt
);
535 htt
->tx_ops
->htt_free_frag_desc(htt
);
536 ath10k_htt_tx_free_txdone_fifo(htt
);
537 htt
->tx_mem_allocated
= false;
540 void ath10k_htt_tx_stop(struct ath10k_htt
*htt
)
542 idr_for_each(&htt
->pending_tx
, ath10k_htt_tx_clean_up_pending
, htt
->ar
);
543 idr_destroy(&htt
->pending_tx
);
546 void ath10k_htt_tx_free(struct ath10k_htt
*htt
)
548 ath10k_htt_tx_stop(htt
);
549 ath10k_htt_tx_destroy(htt
);
552 void ath10k_htt_htc_tx_complete(struct ath10k
*ar
, struct sk_buff
*skb
)
554 dev_kfree_skb_any(skb
);
557 void ath10k_htt_hif_tx_complete(struct ath10k
*ar
, struct sk_buff
*skb
)
559 dev_kfree_skb_any(skb
);
561 EXPORT_SYMBOL(ath10k_htt_hif_tx_complete
);
563 int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt
*htt
)
565 struct ath10k
*ar
= htt
->ar
;
571 len
+= sizeof(cmd
->hdr
);
572 len
+= sizeof(cmd
->ver_req
);
574 skb
= ath10k_htc_alloc_skb(ar
, len
);
579 cmd
= (struct htt_cmd
*)skb
->data
;
580 cmd
->hdr
.msg_type
= HTT_H2T_MSG_TYPE_VERSION_REQ
;
582 ret
= ath10k_htc_send(&htt
->ar
->htc
, htt
->eid
, skb
);
584 dev_kfree_skb_any(skb
);
591 int ath10k_htt_h2t_stats_req(struct ath10k_htt
*htt
, u8 mask
, u64 cookie
)
593 struct ath10k
*ar
= htt
->ar
;
594 struct htt_stats_req
*req
;
599 len
+= sizeof(cmd
->hdr
);
600 len
+= sizeof(cmd
->stats_req
);
602 skb
= ath10k_htc_alloc_skb(ar
, len
);
607 cmd
= (struct htt_cmd
*)skb
->data
;
608 cmd
->hdr
.msg_type
= HTT_H2T_MSG_TYPE_STATS_REQ
;
610 req
= &cmd
->stats_req
;
612 memset(req
, 0, sizeof(*req
));
614 /* currently we support only max 8 bit masks so no need to worry
615 * about endian support
617 req
->upload_types
[0] = mask
;
618 req
->reset_types
[0] = mask
;
619 req
->stat_type
= HTT_STATS_REQ_CFG_STAT_TYPE_INVALID
;
620 req
->cookie_lsb
= cpu_to_le32(cookie
& 0xffffffff);
621 req
->cookie_msb
= cpu_to_le32((cookie
& 0xffffffff00000000ULL
) >> 32);
623 ret
= ath10k_htc_send(&htt
->ar
->htc
, htt
->eid
, skb
);
625 ath10k_warn(ar
, "failed to send htt type stats request: %d",
627 dev_kfree_skb_any(skb
);
634 static int ath10k_htt_send_frag_desc_bank_cfg_32(struct ath10k_htt
*htt
)
636 struct ath10k
*ar
= htt
->ar
;
639 struct htt_frag_desc_bank_cfg32
*cfg
;
643 if (!ar
->hw_params
.continuous_frag_desc
)
646 if (!htt
->frag_desc
.paddr
) {
647 ath10k_warn(ar
, "invalid frag desc memory\n");
651 size
= sizeof(cmd
->hdr
) + sizeof(cmd
->frag_desc_bank_cfg32
);
652 skb
= ath10k_htc_alloc_skb(ar
, size
);
657 cmd
= (struct htt_cmd
*)skb
->data
;
658 cmd
->hdr
.msg_type
= HTT_H2T_MSG_TYPE_FRAG_DESC_BANK_CFG
;
661 info
|= SM(htt
->tx_q_state
.type
,
662 HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_DEPTH_TYPE
);
664 if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL
,
665 ar
->running_fw
->fw_file
.fw_features
))
666 info
|= HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_VALID
;
668 cfg
= &cmd
->frag_desc_bank_cfg32
;
671 cfg
->desc_size
= sizeof(struct htt_msdu_ext_desc
);
672 cfg
->bank_base_addrs
[0] = __cpu_to_le32(htt
->frag_desc
.paddr
);
673 cfg
->bank_id
[0].bank_min_id
= 0;
674 cfg
->bank_id
[0].bank_max_id
= __cpu_to_le16(htt
->max_num_pending_tx
-
677 cfg
->q_state
.paddr
= cpu_to_le32(htt
->tx_q_state
.paddr
);
678 cfg
->q_state
.num_peers
= cpu_to_le16(htt
->tx_q_state
.num_peers
);
679 cfg
->q_state
.num_tids
= cpu_to_le16(htt
->tx_q_state
.num_tids
);
680 cfg
->q_state
.record_size
= HTT_TX_Q_STATE_ENTRY_SIZE
;
681 cfg
->q_state
.record_multiplier
= HTT_TX_Q_STATE_ENTRY_MULTIPLIER
;
683 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "htt frag desc bank cmd\n");
685 ret
= ath10k_htc_send(&htt
->ar
->htc
, htt
->eid
, skb
);
687 ath10k_warn(ar
, "failed to send frag desc bank cfg request: %d\n",
689 dev_kfree_skb_any(skb
);
696 static int ath10k_htt_send_frag_desc_bank_cfg_64(struct ath10k_htt
*htt
)
698 struct ath10k
*ar
= htt
->ar
;
701 struct htt_frag_desc_bank_cfg64
*cfg
;
705 if (!ar
->hw_params
.continuous_frag_desc
)
708 if (!htt
->frag_desc
.paddr
) {
709 ath10k_warn(ar
, "invalid frag desc memory\n");
713 size
= sizeof(cmd
->hdr
) + sizeof(cmd
->frag_desc_bank_cfg64
);
714 skb
= ath10k_htc_alloc_skb(ar
, size
);
719 cmd
= (struct htt_cmd
*)skb
->data
;
720 cmd
->hdr
.msg_type
= HTT_H2T_MSG_TYPE_FRAG_DESC_BANK_CFG
;
723 info
|= SM(htt
->tx_q_state
.type
,
724 HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_DEPTH_TYPE
);
726 if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL
,
727 ar
->running_fw
->fw_file
.fw_features
))
728 info
|= HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_VALID
;
730 cfg
= &cmd
->frag_desc_bank_cfg64
;
733 cfg
->desc_size
= sizeof(struct htt_msdu_ext_desc_64
);
734 cfg
->bank_base_addrs
[0] = __cpu_to_le64(htt
->frag_desc
.paddr
);
735 cfg
->bank_id
[0].bank_min_id
= 0;
736 cfg
->bank_id
[0].bank_max_id
= __cpu_to_le16(htt
->max_num_pending_tx
-
739 cfg
->q_state
.paddr
= cpu_to_le32(htt
->tx_q_state
.paddr
);
740 cfg
->q_state
.num_peers
= cpu_to_le16(htt
->tx_q_state
.num_peers
);
741 cfg
->q_state
.num_tids
= cpu_to_le16(htt
->tx_q_state
.num_tids
);
742 cfg
->q_state
.record_size
= HTT_TX_Q_STATE_ENTRY_SIZE
;
743 cfg
->q_state
.record_multiplier
= HTT_TX_Q_STATE_ENTRY_MULTIPLIER
;
745 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "htt frag desc bank cmd\n");
747 ret
= ath10k_htc_send(&htt
->ar
->htc
, htt
->eid
, skb
);
749 ath10k_warn(ar
, "failed to send frag desc bank cfg request: %d\n",
751 dev_kfree_skb_any(skb
);
758 static void ath10k_htt_fill_rx_desc_offset_32(void *rx_ring
)
760 struct htt_rx_ring_setup_ring32
*ring
=
761 (struct htt_rx_ring_setup_ring32
*)rx_ring
;
763 #define desc_offset(x) (offsetof(struct htt_rx_desc, x) / 4)
764 ring
->mac80211_hdr_offset
= __cpu_to_le16(desc_offset(rx_hdr_status
));
765 ring
->msdu_payload_offset
= __cpu_to_le16(desc_offset(msdu_payload
));
766 ring
->ppdu_start_offset
= __cpu_to_le16(desc_offset(ppdu_start
));
767 ring
->ppdu_end_offset
= __cpu_to_le16(desc_offset(ppdu_end
));
768 ring
->mpdu_start_offset
= __cpu_to_le16(desc_offset(mpdu_start
));
769 ring
->mpdu_end_offset
= __cpu_to_le16(desc_offset(mpdu_end
));
770 ring
->msdu_start_offset
= __cpu_to_le16(desc_offset(msdu_start
));
771 ring
->msdu_end_offset
= __cpu_to_le16(desc_offset(msdu_end
));
772 ring
->rx_attention_offset
= __cpu_to_le16(desc_offset(attention
));
773 ring
->frag_info_offset
= __cpu_to_le16(desc_offset(frag_info
));
777 static void ath10k_htt_fill_rx_desc_offset_64(void *rx_ring
)
779 struct htt_rx_ring_setup_ring64
*ring
=
780 (struct htt_rx_ring_setup_ring64
*)rx_ring
;
782 #define desc_offset(x) (offsetof(struct htt_rx_desc, x) / 4)
783 ring
->mac80211_hdr_offset
= __cpu_to_le16(desc_offset(rx_hdr_status
));
784 ring
->msdu_payload_offset
= __cpu_to_le16(desc_offset(msdu_payload
));
785 ring
->ppdu_start_offset
= __cpu_to_le16(desc_offset(ppdu_start
));
786 ring
->ppdu_end_offset
= __cpu_to_le16(desc_offset(ppdu_end
));
787 ring
->mpdu_start_offset
= __cpu_to_le16(desc_offset(mpdu_start
));
788 ring
->mpdu_end_offset
= __cpu_to_le16(desc_offset(mpdu_end
));
789 ring
->msdu_start_offset
= __cpu_to_le16(desc_offset(msdu_start
));
790 ring
->msdu_end_offset
= __cpu_to_le16(desc_offset(msdu_end
));
791 ring
->rx_attention_offset
= __cpu_to_le16(desc_offset(attention
));
792 ring
->frag_info_offset
= __cpu_to_le16(desc_offset(frag_info
));
796 static int ath10k_htt_send_rx_ring_cfg_32(struct ath10k_htt
*htt
)
798 struct ath10k
*ar
= htt
->ar
;
801 struct htt_rx_ring_setup_ring32
*ring
;
802 const int num_rx_ring
= 1;
809 * the HW expects the buffer to be an integral number of 4-byte
812 BUILD_BUG_ON(!IS_ALIGNED(HTT_RX_BUF_SIZE
, 4));
813 BUILD_BUG_ON((HTT_RX_BUF_SIZE
& HTT_MAX_CACHE_LINE_SIZE_MASK
) != 0);
815 len
= sizeof(cmd
->hdr
) + sizeof(cmd
->rx_setup_32
.hdr
)
816 + (sizeof(*ring
) * num_rx_ring
);
817 skb
= ath10k_htc_alloc_skb(ar
, len
);
823 cmd
= (struct htt_cmd
*)skb
->data
;
824 ring
= &cmd
->rx_setup_32
.rings
[0];
826 cmd
->hdr
.msg_type
= HTT_H2T_MSG_TYPE_RX_RING_CFG
;
827 cmd
->rx_setup_32
.hdr
.num_rings
= 1;
829 /* FIXME: do we need all of this? */
831 flags
|= HTT_RX_RING_FLAGS_MAC80211_HDR
;
832 flags
|= HTT_RX_RING_FLAGS_MSDU_PAYLOAD
;
833 flags
|= HTT_RX_RING_FLAGS_PPDU_START
;
834 flags
|= HTT_RX_RING_FLAGS_PPDU_END
;
835 flags
|= HTT_RX_RING_FLAGS_MPDU_START
;
836 flags
|= HTT_RX_RING_FLAGS_MPDU_END
;
837 flags
|= HTT_RX_RING_FLAGS_MSDU_START
;
838 flags
|= HTT_RX_RING_FLAGS_MSDU_END
;
839 flags
|= HTT_RX_RING_FLAGS_RX_ATTENTION
;
840 flags
|= HTT_RX_RING_FLAGS_FRAG_INFO
;
841 flags
|= HTT_RX_RING_FLAGS_UNICAST_RX
;
842 flags
|= HTT_RX_RING_FLAGS_MULTICAST_RX
;
843 flags
|= HTT_RX_RING_FLAGS_CTRL_RX
;
844 flags
|= HTT_RX_RING_FLAGS_MGMT_RX
;
845 flags
|= HTT_RX_RING_FLAGS_NULL_RX
;
846 flags
|= HTT_RX_RING_FLAGS_PHY_DATA_RX
;
848 fw_idx
= __le32_to_cpu(*htt
->rx_ring
.alloc_idx
.vaddr
);
850 ring
->fw_idx_shadow_reg_paddr
=
851 __cpu_to_le32(htt
->rx_ring
.alloc_idx
.paddr
);
852 ring
->rx_ring_base_paddr
= __cpu_to_le32(htt
->rx_ring
.base_paddr
);
853 ring
->rx_ring_len
= __cpu_to_le16(htt
->rx_ring
.size
);
854 ring
->rx_ring_bufsize
= __cpu_to_le16(HTT_RX_BUF_SIZE
);
855 ring
->flags
= __cpu_to_le16(flags
);
856 ring
->fw_idx_init_val
= __cpu_to_le16(fw_idx
);
858 ath10k_htt_fill_rx_desc_offset_32(ring
);
859 ret
= ath10k_htc_send(&htt
->ar
->htc
, htt
->eid
, skb
);
861 dev_kfree_skb_any(skb
);
868 static int ath10k_htt_send_rx_ring_cfg_64(struct ath10k_htt
*htt
)
870 struct ath10k
*ar
= htt
->ar
;
873 struct htt_rx_ring_setup_ring64
*ring
;
874 const int num_rx_ring
= 1;
880 /* HW expects the buffer to be an integral number of 4-byte
883 BUILD_BUG_ON(!IS_ALIGNED(HTT_RX_BUF_SIZE
, 4));
884 BUILD_BUG_ON((HTT_RX_BUF_SIZE
& HTT_MAX_CACHE_LINE_SIZE_MASK
) != 0);
886 len
= sizeof(cmd
->hdr
) + sizeof(cmd
->rx_setup_64
.hdr
)
887 + (sizeof(*ring
) * num_rx_ring
);
888 skb
= ath10k_htc_alloc_skb(ar
, len
);
894 cmd
= (struct htt_cmd
*)skb
->data
;
895 ring
= &cmd
->rx_setup_64
.rings
[0];
897 cmd
->hdr
.msg_type
= HTT_H2T_MSG_TYPE_RX_RING_CFG
;
898 cmd
->rx_setup_64
.hdr
.num_rings
= 1;
901 flags
|= HTT_RX_RING_FLAGS_MAC80211_HDR
;
902 flags
|= HTT_RX_RING_FLAGS_MSDU_PAYLOAD
;
903 flags
|= HTT_RX_RING_FLAGS_PPDU_START
;
904 flags
|= HTT_RX_RING_FLAGS_PPDU_END
;
905 flags
|= HTT_RX_RING_FLAGS_MPDU_START
;
906 flags
|= HTT_RX_RING_FLAGS_MPDU_END
;
907 flags
|= HTT_RX_RING_FLAGS_MSDU_START
;
908 flags
|= HTT_RX_RING_FLAGS_MSDU_END
;
909 flags
|= HTT_RX_RING_FLAGS_RX_ATTENTION
;
910 flags
|= HTT_RX_RING_FLAGS_FRAG_INFO
;
911 flags
|= HTT_RX_RING_FLAGS_UNICAST_RX
;
912 flags
|= HTT_RX_RING_FLAGS_MULTICAST_RX
;
913 flags
|= HTT_RX_RING_FLAGS_CTRL_RX
;
914 flags
|= HTT_RX_RING_FLAGS_MGMT_RX
;
915 flags
|= HTT_RX_RING_FLAGS_NULL_RX
;
916 flags
|= HTT_RX_RING_FLAGS_PHY_DATA_RX
;
918 fw_idx
= __le32_to_cpu(*htt
->rx_ring
.alloc_idx
.vaddr
);
920 ring
->fw_idx_shadow_reg_paddr
= __cpu_to_le64(htt
->rx_ring
.alloc_idx
.paddr
);
921 ring
->rx_ring_base_paddr
= __cpu_to_le64(htt
->rx_ring
.base_paddr
);
922 ring
->rx_ring_len
= __cpu_to_le16(htt
->rx_ring
.size
);
923 ring
->rx_ring_bufsize
= __cpu_to_le16(HTT_RX_BUF_SIZE
);
924 ring
->flags
= __cpu_to_le16(flags
);
925 ring
->fw_idx_init_val
= __cpu_to_le16(fw_idx
);
927 ath10k_htt_fill_rx_desc_offset_64(ring
);
928 ret
= ath10k_htc_send(&htt
->ar
->htc
, htt
->eid
, skb
);
930 dev_kfree_skb_any(skb
);
937 int ath10k_htt_h2t_aggr_cfg_msg(struct ath10k_htt
*htt
,
938 u8 max_subfrms_ampdu
,
939 u8 max_subfrms_amsdu
)
941 struct ath10k
*ar
= htt
->ar
;
942 struct htt_aggr_conf
*aggr_conf
;
948 /* Firmware defaults are: amsdu = 3 and ampdu = 64 */
950 if (max_subfrms_ampdu
== 0 || max_subfrms_ampdu
> 64)
953 if (max_subfrms_amsdu
== 0 || max_subfrms_amsdu
> 31)
956 len
= sizeof(cmd
->hdr
);
957 len
+= sizeof(cmd
->aggr_conf
);
959 skb
= ath10k_htc_alloc_skb(ar
, len
);
964 cmd
= (struct htt_cmd
*)skb
->data
;
965 cmd
->hdr
.msg_type
= HTT_H2T_MSG_TYPE_AGGR_CFG
;
967 aggr_conf
= &cmd
->aggr_conf
;
968 aggr_conf
->max_num_ampdu_subframes
= max_subfrms_ampdu
;
969 aggr_conf
->max_num_amsdu_subframes
= max_subfrms_amsdu
;
971 ath10k_dbg(ar
, ATH10K_DBG_HTT
, "htt h2t aggr cfg msg amsdu %d ampdu %d",
972 aggr_conf
->max_num_amsdu_subframes
,
973 aggr_conf
->max_num_ampdu_subframes
);
975 ret
= ath10k_htc_send(&htt
->ar
->htc
, htt
->eid
, skb
);
977 dev_kfree_skb_any(skb
);
984 int ath10k_htt_tx_fetch_resp(struct ath10k
*ar
,
986 __le16 fetch_seq_num
,
987 struct htt_tx_fetch_record
*records
,
992 const u16 resp_id
= 0;
996 /* Response IDs are echo-ed back only for host driver convienence
997 * purposes. They aren't used for anything in the driver yet so use 0.
1000 len
+= sizeof(cmd
->hdr
);
1001 len
+= sizeof(cmd
->tx_fetch_resp
);
1002 len
+= sizeof(cmd
->tx_fetch_resp
.records
[0]) * num_records
;
1004 skb
= ath10k_htc_alloc_skb(ar
, len
);
1009 cmd
= (struct htt_cmd
*)skb
->data
;
1010 cmd
->hdr
.msg_type
= HTT_H2T_MSG_TYPE_TX_FETCH_RESP
;
1011 cmd
->tx_fetch_resp
.resp_id
= cpu_to_le16(resp_id
);
1012 cmd
->tx_fetch_resp
.fetch_seq_num
= fetch_seq_num
;
1013 cmd
->tx_fetch_resp
.num_records
= cpu_to_le16(num_records
);
1014 cmd
->tx_fetch_resp
.token
= token
;
1016 memcpy(cmd
->tx_fetch_resp
.records
, records
,
1017 sizeof(records
[0]) * num_records
);
1019 ret
= ath10k_htc_send(&ar
->htc
, ar
->htt
.eid
, skb
);
1021 ath10k_warn(ar
, "failed to submit htc command: %d\n", ret
);
1028 dev_kfree_skb_any(skb
);
1033 static u8
ath10k_htt_tx_get_vdev_id(struct ath10k
*ar
, struct sk_buff
*skb
)
1035 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1036 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
1037 struct ath10k_vif
*arvif
;
1039 if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
1040 return ar
->scan
.vdev_id
;
1041 } else if (cb
->vif
) {
1042 arvif
= (void *)cb
->vif
->drv_priv
;
1043 return arvif
->vdev_id
;
1044 } else if (ar
->monitor_started
) {
1045 return ar
->monitor_vdev_id
;
1051 static u8
ath10k_htt_tx_get_tid(struct sk_buff
*skb
, bool is_eth
)
1053 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
1054 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
1056 if (!is_eth
&& ieee80211_is_mgmt(hdr
->frame_control
))
1057 return HTT_DATA_TX_EXT_TID_MGMT
;
1058 else if (cb
->flags
& ATH10K_SKB_F_QOS
)
1059 return skb
->priority
% IEEE80211_QOS_CTL_TID_MASK
;
1061 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
1064 int ath10k_htt_mgmt_tx(struct ath10k_htt
*htt
, struct sk_buff
*msdu
)
1066 struct ath10k
*ar
= htt
->ar
;
1067 struct device
*dev
= ar
->dev
;
1068 struct sk_buff
*txdesc
= NULL
;
1069 struct htt_cmd
*cmd
;
1070 struct ath10k_skb_cb
*skb_cb
= ATH10K_SKB_CB(msdu
);
1071 u8 vdev_id
= ath10k_htt_tx_get_vdev_id(ar
, msdu
);
1075 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)msdu
->data
;
1077 len
+= sizeof(cmd
->hdr
);
1078 len
+= sizeof(cmd
->mgmt_tx
);
1080 spin_lock_bh(&htt
->tx_lock
);
1081 res
= ath10k_htt_tx_alloc_msdu_id(htt
, msdu
);
1082 spin_unlock_bh(&htt
->tx_lock
);
1088 if ((ieee80211_is_action(hdr
->frame_control
) ||
1089 ieee80211_is_deauth(hdr
->frame_control
) ||
1090 ieee80211_is_disassoc(hdr
->frame_control
)) &&
1091 ieee80211_has_protected(hdr
->frame_control
)) {
1092 skb_put(msdu
, IEEE80211_CCMP_MIC_LEN
);
1095 txdesc
= ath10k_htc_alloc_skb(ar
, len
);
1098 goto err_free_msdu_id
;
1101 skb_cb
->paddr
= dma_map_single(dev
, msdu
->data
, msdu
->len
,
1103 res
= dma_mapping_error(dev
, skb_cb
->paddr
);
1106 goto err_free_txdesc
;
1109 skb_put(txdesc
, len
);
1110 cmd
= (struct htt_cmd
*)txdesc
->data
;
1111 memset(cmd
, 0, len
);
1113 cmd
->hdr
.msg_type
= HTT_H2T_MSG_TYPE_MGMT_TX
;
1114 cmd
->mgmt_tx
.msdu_paddr
= __cpu_to_le32(ATH10K_SKB_CB(msdu
)->paddr
);
1115 cmd
->mgmt_tx
.len
= __cpu_to_le32(msdu
->len
);
1116 cmd
->mgmt_tx
.desc_id
= __cpu_to_le32(msdu_id
);
1117 cmd
->mgmt_tx
.vdev_id
= __cpu_to_le32(vdev_id
);
1118 memcpy(cmd
->mgmt_tx
.hdr
, msdu
->data
,
1119 min_t(int, msdu
->len
, HTT_MGMT_FRM_HDR_DOWNLOAD_LEN
));
1121 res
= ath10k_htc_send(&htt
->ar
->htc
, htt
->eid
, txdesc
);
1123 goto err_unmap_msdu
;
1128 dma_unmap_single(dev
, skb_cb
->paddr
, msdu
->len
, DMA_TO_DEVICE
);
1130 dev_kfree_skb_any(txdesc
);
1132 spin_lock_bh(&htt
->tx_lock
);
1133 ath10k_htt_tx_free_msdu_id(htt
, msdu_id
);
1134 spin_unlock_bh(&htt
->tx_lock
);
1139 static int ath10k_htt_tx_32(struct ath10k_htt
*htt
,
1140 enum ath10k_hw_txrx_mode txmode
,
1141 struct sk_buff
*msdu
)
1143 struct ath10k
*ar
= htt
->ar
;
1144 struct device
*dev
= ar
->dev
;
1145 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)msdu
->data
;
1146 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(msdu
);
1147 struct ath10k_skb_cb
*skb_cb
= ATH10K_SKB_CB(msdu
);
1148 struct ath10k_hif_sg_item sg_items
[2];
1149 struct ath10k_htt_txbuf_32
*txbuf
;
1150 struct htt_data_tx_desc_frag
*frags
;
1151 bool is_eth
= (txmode
== ATH10K_HW_TXRX_ETHERNET
);
1152 u8 vdev_id
= ath10k_htt_tx_get_vdev_id(ar
, msdu
);
1153 u8 tid
= ath10k_htt_tx_get_tid(msdu
, is_eth
);
1157 u16 msdu_id
, flags1
= 0;
1159 u32 frags_paddr
= 0;
1161 struct htt_msdu_ext_desc
*ext_desc
= NULL
;
1162 struct htt_msdu_ext_desc
*ext_desc_t
= NULL
;
1164 spin_lock_bh(&htt
->tx_lock
);
1165 res
= ath10k_htt_tx_alloc_msdu_id(htt
, msdu
);
1166 spin_unlock_bh(&htt
->tx_lock
);
1172 prefetch_len
= min(htt
->prefetch_len
, msdu
->len
);
1173 prefetch_len
= roundup(prefetch_len
, 4);
1175 txbuf
= htt
->txbuf
.vaddr_txbuff_32
+ msdu_id
;
1176 txbuf_paddr
= htt
->txbuf
.paddr
+
1177 (sizeof(struct ath10k_htt_txbuf_32
) * msdu_id
);
1179 if ((ieee80211_is_action(hdr
->frame_control
) ||
1180 ieee80211_is_deauth(hdr
->frame_control
) ||
1181 ieee80211_is_disassoc(hdr
->frame_control
)) &&
1182 ieee80211_has_protected(hdr
->frame_control
)) {
1183 skb_put(msdu
, IEEE80211_CCMP_MIC_LEN
);
1184 } else if (!(skb_cb
->flags
& ATH10K_SKB_F_NO_HWCRYPT
) &&
1185 txmode
== ATH10K_HW_TXRX_RAW
&&
1186 ieee80211_has_protected(hdr
->frame_control
)) {
1187 skb_put(msdu
, IEEE80211_CCMP_MIC_LEN
);
1190 skb_cb
->paddr
= dma_map_single(dev
, msdu
->data
, msdu
->len
,
1192 res
= dma_mapping_error(dev
, skb_cb
->paddr
);
1195 goto err_free_msdu_id
;
1198 if (unlikely(info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
))
1199 freq
= ar
->scan
.roc_freq
;
1202 case ATH10K_HW_TXRX_RAW
:
1203 case ATH10K_HW_TXRX_NATIVE_WIFI
:
1204 flags0
|= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT
;
1206 case ATH10K_HW_TXRX_ETHERNET
:
1207 if (ar
->hw_params
.continuous_frag_desc
) {
1208 ext_desc_t
= htt
->frag_desc
.vaddr_desc_32
;
1209 memset(&ext_desc_t
[msdu_id
], 0,
1210 sizeof(struct htt_msdu_ext_desc
));
1211 frags
= (struct htt_data_tx_desc_frag
*)
1212 &ext_desc_t
[msdu_id
].frags
;
1213 ext_desc
= &ext_desc_t
[msdu_id
];
1214 frags
[0].tword_addr
.paddr_lo
=
1215 __cpu_to_le32(skb_cb
->paddr
);
1216 frags
[0].tword_addr
.paddr_hi
= 0;
1217 frags
[0].tword_addr
.len_16
= __cpu_to_le16(msdu
->len
);
1219 frags_paddr
= htt
->frag_desc
.paddr
+
1220 (sizeof(struct htt_msdu_ext_desc
) * msdu_id
);
1222 frags
= txbuf
->frags
;
1223 frags
[0].dword_addr
.paddr
=
1224 __cpu_to_le32(skb_cb
->paddr
);
1225 frags
[0].dword_addr
.len
= __cpu_to_le32(msdu
->len
);
1226 frags
[1].dword_addr
.paddr
= 0;
1227 frags
[1].dword_addr
.len
= 0;
1229 frags_paddr
= txbuf_paddr
;
1231 flags0
|= SM(txmode
, HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE
);
1233 case ATH10K_HW_TXRX_MGMT
:
1234 flags0
|= SM(ATH10K_HW_TXRX_MGMT
,
1235 HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE
);
1236 flags0
|= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT
;
1238 frags_paddr
= skb_cb
->paddr
;
1242 /* Normally all commands go through HTC which manages tx credits for
1243 * each endpoint and notifies when tx is completed.
1245 * HTT endpoint is creditless so there's no need to care about HTC
1246 * flags. In that case it is trivial to fill the HTC header here.
1248 * MSDU transmission is considered completed upon HTT event. This
1249 * implies no relevant resources can be freed until after the event is
1250 * received. That's why HTC tx completion handler itself is ignored by
1251 * setting NULL to transfer_context for all sg items.
1253 * There is simply no point in pushing HTT TX_FRM through HTC tx path
1254 * as it's a waste of resources. By bypassing HTC it is possible to
1255 * avoid extra memory allocations, compress data structures and thus
1256 * improve performance.
1259 txbuf
->htc_hdr
.eid
= htt
->eid
;
1260 txbuf
->htc_hdr
.len
= __cpu_to_le16(sizeof(txbuf
->cmd_hdr
) +
1261 sizeof(txbuf
->cmd_tx
) +
1263 txbuf
->htc_hdr
.flags
= 0;
1265 if (skb_cb
->flags
& ATH10K_SKB_F_NO_HWCRYPT
)
1266 flags0
|= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT
;
1268 flags1
|= SM((u16
)vdev_id
, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID
);
1269 flags1
|= SM((u16
)tid
, HTT_DATA_TX_DESC_FLAGS1_EXT_TID
);
1270 if (msdu
->ip_summed
== CHECKSUM_PARTIAL
&&
1271 !test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
1272 flags1
|= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD
;
1273 flags1
|= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD
;
1274 if (ar
->hw_params
.continuous_frag_desc
)
1275 ext_desc
->flags
|= HTT_MSDU_CHECKSUM_ENABLE
;
1278 /* Prevent firmware from sending up tx inspection requests. There's
1279 * nothing ath10k can do with frames requested for inspection so force
1280 * it to simply rely a regular tx completion with discard status.
1282 flags1
|= HTT_DATA_TX_DESC_FLAGS1_POSTPONED
;
1284 txbuf
->cmd_hdr
.msg_type
= HTT_H2T_MSG_TYPE_TX_FRM
;
1285 txbuf
->cmd_tx
.flags0
= flags0
;
1286 txbuf
->cmd_tx
.flags1
= __cpu_to_le16(flags1
);
1287 txbuf
->cmd_tx
.len
= __cpu_to_le16(msdu
->len
);
1288 txbuf
->cmd_tx
.id
= __cpu_to_le16(msdu_id
);
1289 txbuf
->cmd_tx
.frags_paddr
= __cpu_to_le32(frags_paddr
);
1290 if (ath10k_mac_tx_frm_has_freq(ar
)) {
1291 txbuf
->cmd_tx
.offchan_tx
.peerid
=
1292 __cpu_to_le16(HTT_INVALID_PEERID
);
1293 txbuf
->cmd_tx
.offchan_tx
.freq
=
1294 __cpu_to_le16(freq
);
1296 txbuf
->cmd_tx
.peerid
=
1297 __cpu_to_le32(HTT_INVALID_PEERID
);
1300 trace_ath10k_htt_tx(ar
, msdu_id
, msdu
->len
, vdev_id
, tid
);
1301 ath10k_dbg(ar
, ATH10K_DBG_HTT
,
1302 "htt tx flags0 %hhu flags1 %hu len %d id %hu frags_paddr %pad, msdu_paddr %pad vdev %hhu tid %hhu freq %hu\n",
1303 flags0
, flags1
, msdu
->len
, msdu_id
, &frags_paddr
,
1304 &skb_cb
->paddr
, vdev_id
, tid
, freq
);
1305 ath10k_dbg_dump(ar
, ATH10K_DBG_HTT_DUMP
, NULL
, "htt tx msdu: ",
1306 msdu
->data
, msdu
->len
);
1307 trace_ath10k_tx_hdr(ar
, msdu
->data
, msdu
->len
);
1308 trace_ath10k_tx_payload(ar
, msdu
->data
, msdu
->len
);
1310 sg_items
[0].transfer_id
= 0;
1311 sg_items
[0].transfer_context
= NULL
;
1312 sg_items
[0].vaddr
= &txbuf
->htc_hdr
;
1313 sg_items
[0].paddr
= txbuf_paddr
+
1314 sizeof(txbuf
->frags
);
1315 sg_items
[0].len
= sizeof(txbuf
->htc_hdr
) +
1316 sizeof(txbuf
->cmd_hdr
) +
1317 sizeof(txbuf
->cmd_tx
);
1319 sg_items
[1].transfer_id
= 0;
1320 sg_items
[1].transfer_context
= NULL
;
1321 sg_items
[1].vaddr
= msdu
->data
;
1322 sg_items
[1].paddr
= skb_cb
->paddr
;
1323 sg_items
[1].len
= prefetch_len
;
1325 res
= ath10k_hif_tx_sg(htt
->ar
,
1326 htt
->ar
->htc
.endpoint
[htt
->eid
].ul_pipe_id
,
1327 sg_items
, ARRAY_SIZE(sg_items
));
1329 goto err_unmap_msdu
;
1334 dma_unmap_single(dev
, skb_cb
->paddr
, msdu
->len
, DMA_TO_DEVICE
);
1336 ath10k_htt_tx_free_msdu_id(htt
, msdu_id
);
1341 static int ath10k_htt_tx_64(struct ath10k_htt
*htt
,
1342 enum ath10k_hw_txrx_mode txmode
,
1343 struct sk_buff
*msdu
)
1345 struct ath10k
*ar
= htt
->ar
;
1346 struct device
*dev
= ar
->dev
;
1347 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)msdu
->data
;
1348 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(msdu
);
1349 struct ath10k_skb_cb
*skb_cb
= ATH10K_SKB_CB(msdu
);
1350 struct ath10k_hif_sg_item sg_items
[2];
1351 struct ath10k_htt_txbuf_64
*txbuf
;
1352 struct htt_data_tx_desc_frag
*frags
;
1353 bool is_eth
= (txmode
== ATH10K_HW_TXRX_ETHERNET
);
1354 u8 vdev_id
= ath10k_htt_tx_get_vdev_id(ar
, msdu
);
1355 u8 tid
= ath10k_htt_tx_get_tid(msdu
, is_eth
);
1359 u16 msdu_id
, flags1
= 0;
1361 dma_addr_t frags_paddr
= 0;
1363 struct htt_msdu_ext_desc_64
*ext_desc
= NULL
;
1364 struct htt_msdu_ext_desc_64
*ext_desc_t
= NULL
;
1366 spin_lock_bh(&htt
->tx_lock
);
1367 res
= ath10k_htt_tx_alloc_msdu_id(htt
, msdu
);
1368 spin_unlock_bh(&htt
->tx_lock
);
1374 prefetch_len
= min(htt
->prefetch_len
, msdu
->len
);
1375 prefetch_len
= roundup(prefetch_len
, 4);
1377 txbuf
= htt
->txbuf
.vaddr_txbuff_64
+ msdu_id
;
1378 txbuf_paddr
= htt
->txbuf
.paddr
+
1379 (sizeof(struct ath10k_htt_txbuf_64
) * msdu_id
);
1381 if ((ieee80211_is_action(hdr
->frame_control
) ||
1382 ieee80211_is_deauth(hdr
->frame_control
) ||
1383 ieee80211_is_disassoc(hdr
->frame_control
)) &&
1384 ieee80211_has_protected(hdr
->frame_control
)) {
1385 skb_put(msdu
, IEEE80211_CCMP_MIC_LEN
);
1386 } else if (!(skb_cb
->flags
& ATH10K_SKB_F_NO_HWCRYPT
) &&
1387 txmode
== ATH10K_HW_TXRX_RAW
&&
1388 ieee80211_has_protected(hdr
->frame_control
)) {
1389 skb_put(msdu
, IEEE80211_CCMP_MIC_LEN
);
1392 skb_cb
->paddr
= dma_map_single(dev
, msdu
->data
, msdu
->len
,
1394 res
= dma_mapping_error(dev
, skb_cb
->paddr
);
1397 goto err_free_msdu_id
;
1400 if (unlikely(info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
))
1401 freq
= ar
->scan
.roc_freq
;
1404 case ATH10K_HW_TXRX_RAW
:
1405 case ATH10K_HW_TXRX_NATIVE_WIFI
:
1406 flags0
|= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT
;
1408 case ATH10K_HW_TXRX_ETHERNET
:
1409 if (ar
->hw_params
.continuous_frag_desc
) {
1410 ext_desc_t
= htt
->frag_desc
.vaddr_desc_64
;
1411 memset(&ext_desc_t
[msdu_id
], 0,
1412 sizeof(struct htt_msdu_ext_desc_64
));
1413 frags
= (struct htt_data_tx_desc_frag
*)
1414 &ext_desc_t
[msdu_id
].frags
;
1415 ext_desc
= &ext_desc_t
[msdu_id
];
1416 frags
[0].tword_addr
.paddr_lo
=
1417 __cpu_to_le32(skb_cb
->paddr
);
1418 frags
[0].tword_addr
.paddr_hi
=
1419 __cpu_to_le16(upper_32_bits(skb_cb
->paddr
));
1420 frags
[0].tword_addr
.len_16
= __cpu_to_le16(msdu
->len
);
1422 frags_paddr
= htt
->frag_desc
.paddr
+
1423 (sizeof(struct htt_msdu_ext_desc_64
) * msdu_id
);
1425 frags
= txbuf
->frags
;
1426 frags
[0].tword_addr
.paddr_lo
=
1427 __cpu_to_le32(skb_cb
->paddr
);
1428 frags
[0].tword_addr
.paddr_hi
=
1429 __cpu_to_le16(upper_32_bits(skb_cb
->paddr
));
1430 frags
[0].tword_addr
.len_16
= __cpu_to_le16(msdu
->len
);
1431 frags
[1].tword_addr
.paddr_lo
= 0;
1432 frags
[1].tword_addr
.paddr_hi
= 0;
1433 frags
[1].tword_addr
.len_16
= 0;
1435 flags0
|= SM(txmode
, HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE
);
1437 case ATH10K_HW_TXRX_MGMT
:
1438 flags0
|= SM(ATH10K_HW_TXRX_MGMT
,
1439 HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE
);
1440 flags0
|= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT
;
1442 frags_paddr
= skb_cb
->paddr
;
1446 /* Normally all commands go through HTC which manages tx credits for
1447 * each endpoint and notifies when tx is completed.
1449 * HTT endpoint is creditless so there's no need to care about HTC
1450 * flags. In that case it is trivial to fill the HTC header here.
1452 * MSDU transmission is considered completed upon HTT event. This
1453 * implies no relevant resources can be freed until after the event is
1454 * received. That's why HTC tx completion handler itself is ignored by
1455 * setting NULL to transfer_context for all sg items.
1457 * There is simply no point in pushing HTT TX_FRM through HTC tx path
1458 * as it's a waste of resources. By bypassing HTC it is possible to
1459 * avoid extra memory allocations, compress data structures and thus
1460 * improve performance.
1463 txbuf
->htc_hdr
.eid
= htt
->eid
;
1464 txbuf
->htc_hdr
.len
= __cpu_to_le16(sizeof(txbuf
->cmd_hdr
) +
1465 sizeof(txbuf
->cmd_tx
) +
1467 txbuf
->htc_hdr
.flags
= 0;
1469 if (skb_cb
->flags
& ATH10K_SKB_F_NO_HWCRYPT
)
1470 flags0
|= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT
;
1472 flags1
|= SM((u16
)vdev_id
, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID
);
1473 flags1
|= SM((u16
)tid
, HTT_DATA_TX_DESC_FLAGS1_EXT_TID
);
1474 if (msdu
->ip_summed
== CHECKSUM_PARTIAL
&&
1475 !test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
)) {
1476 flags1
|= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD
;
1477 flags1
|= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD
;
1478 if (ar
->hw_params
.continuous_frag_desc
)
1479 ext_desc
->flags
|= HTT_MSDU_CHECKSUM_ENABLE
;
1482 /* Prevent firmware from sending up tx inspection requests. There's
1483 * nothing ath10k can do with frames requested for inspection so force
1484 * it to simply rely a regular tx completion with discard status.
1486 flags1
|= HTT_DATA_TX_DESC_FLAGS1_POSTPONED
;
1488 txbuf
->cmd_hdr
.msg_type
= HTT_H2T_MSG_TYPE_TX_FRM
;
1489 txbuf
->cmd_tx
.flags0
= flags0
;
1490 txbuf
->cmd_tx
.flags1
= __cpu_to_le16(flags1
);
1491 txbuf
->cmd_tx
.len
= __cpu_to_le16(msdu
->len
);
1492 txbuf
->cmd_tx
.id
= __cpu_to_le16(msdu_id
);
1494 /* fill fragment descriptor */
1495 txbuf
->cmd_tx
.frags_paddr
= __cpu_to_le64(frags_paddr
);
1496 if (ath10k_mac_tx_frm_has_freq(ar
)) {
1497 txbuf
->cmd_tx
.offchan_tx
.peerid
=
1498 __cpu_to_le16(HTT_INVALID_PEERID
);
1499 txbuf
->cmd_tx
.offchan_tx
.freq
=
1500 __cpu_to_le16(freq
);
1502 txbuf
->cmd_tx
.peerid
=
1503 __cpu_to_le32(HTT_INVALID_PEERID
);
1506 trace_ath10k_htt_tx(ar
, msdu_id
, msdu
->len
, vdev_id
, tid
);
1507 ath10k_dbg(ar
, ATH10K_DBG_HTT
,
1508 "htt tx flags0 %hhu flags1 %hu len %d id %hu frags_paddr %pad, msdu_paddr %pad vdev %hhu tid %hhu freq %hu\n",
1509 flags0
, flags1
, msdu
->len
, msdu_id
, &frags_paddr
,
1510 &skb_cb
->paddr
, vdev_id
, tid
, freq
);
1511 ath10k_dbg_dump(ar
, ATH10K_DBG_HTT_DUMP
, NULL
, "htt tx msdu: ",
1512 msdu
->data
, msdu
->len
);
1513 trace_ath10k_tx_hdr(ar
, msdu
->data
, msdu
->len
);
1514 trace_ath10k_tx_payload(ar
, msdu
->data
, msdu
->len
);
1516 sg_items
[0].transfer_id
= 0;
1517 sg_items
[0].transfer_context
= NULL
;
1518 sg_items
[0].vaddr
= &txbuf
->htc_hdr
;
1519 sg_items
[0].paddr
= txbuf_paddr
+
1520 sizeof(txbuf
->frags
);
1521 sg_items
[0].len
= sizeof(txbuf
->htc_hdr
) +
1522 sizeof(txbuf
->cmd_hdr
) +
1523 sizeof(txbuf
->cmd_tx
);
1525 sg_items
[1].transfer_id
= 0;
1526 sg_items
[1].transfer_context
= NULL
;
1527 sg_items
[1].vaddr
= msdu
->data
;
1528 sg_items
[1].paddr
= skb_cb
->paddr
;
1529 sg_items
[1].len
= prefetch_len
;
1531 res
= ath10k_hif_tx_sg(htt
->ar
,
1532 htt
->ar
->htc
.endpoint
[htt
->eid
].ul_pipe_id
,
1533 sg_items
, ARRAY_SIZE(sg_items
));
1535 goto err_unmap_msdu
;
1540 dma_unmap_single(dev
, skb_cb
->paddr
, msdu
->len
, DMA_TO_DEVICE
);
1542 ath10k_htt_tx_free_msdu_id(htt
, msdu_id
);
1547 static const struct ath10k_htt_tx_ops htt_tx_ops_32
= {
1548 .htt_send_rx_ring_cfg
= ath10k_htt_send_rx_ring_cfg_32
,
1549 .htt_send_frag_desc_bank_cfg
= ath10k_htt_send_frag_desc_bank_cfg_32
,
1550 .htt_alloc_frag_desc
= ath10k_htt_tx_alloc_cont_frag_desc_32
,
1551 .htt_free_frag_desc
= ath10k_htt_tx_free_cont_frag_desc_32
,
1552 .htt_tx
= ath10k_htt_tx_32
,
1553 .htt_alloc_txbuff
= ath10k_htt_tx_alloc_cont_txbuf_32
,
1554 .htt_free_txbuff
= ath10k_htt_tx_free_cont_txbuf_32
,
1557 static const struct ath10k_htt_tx_ops htt_tx_ops_64
= {
1558 .htt_send_rx_ring_cfg
= ath10k_htt_send_rx_ring_cfg_64
,
1559 .htt_send_frag_desc_bank_cfg
= ath10k_htt_send_frag_desc_bank_cfg_64
,
1560 .htt_alloc_frag_desc
= ath10k_htt_tx_alloc_cont_frag_desc_64
,
1561 .htt_free_frag_desc
= ath10k_htt_tx_free_cont_frag_desc_64
,
1562 .htt_tx
= ath10k_htt_tx_64
,
1563 .htt_alloc_txbuff
= ath10k_htt_tx_alloc_cont_txbuf_64
,
1564 .htt_free_txbuff
= ath10k_htt_tx_free_cont_txbuf_64
,
1567 void ath10k_htt_set_tx_ops(struct ath10k_htt
*htt
)
1569 struct ath10k
*ar
= htt
->ar
;
1571 if (ar
->hw_params
.target_64bit
)
1572 htt
->tx_ops
= &htt_tx_ops_64
;
1574 htt
->tx_ops
= &htt_tx_ops_32
;