1*4882a593Smuzhiyun // SPDX-License-Identifier: ISC
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (c) 2005-2011 Atheros Communications Inc.
4*4882a593Smuzhiyun * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
5*4882a593Smuzhiyun */
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun #include <linux/etherdevice.h>
8*4882a593Smuzhiyun #include "htt.h"
9*4882a593Smuzhiyun #include "mac.h"
10*4882a593Smuzhiyun #include "hif.h"
11*4882a593Smuzhiyun #include "txrx.h"
12*4882a593Smuzhiyun #include "debug.h"
13*4882a593Smuzhiyun
ath10k_htt_tx_txq_calc_size(size_t count)14*4882a593Smuzhiyun static u8 ath10k_htt_tx_txq_calc_size(size_t count)
15*4882a593Smuzhiyun {
16*4882a593Smuzhiyun int exp;
17*4882a593Smuzhiyun int factor;
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun exp = 0;
20*4882a593Smuzhiyun factor = count >> 7;
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun while (factor >= 64 && exp < 4) {
23*4882a593Smuzhiyun factor >>= 3;
24*4882a593Smuzhiyun exp++;
25*4882a593Smuzhiyun }
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun if (exp == 4)
28*4882a593Smuzhiyun return 0xff;
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun if (count > 0)
31*4882a593Smuzhiyun factor = max(1, factor);
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun return SM(exp, HTT_TX_Q_STATE_ENTRY_EXP) |
34*4882a593Smuzhiyun SM(factor, HTT_TX_Q_STATE_ENTRY_FACTOR);
35*4882a593Smuzhiyun }
36*4882a593Smuzhiyun
__ath10k_htt_tx_txq_recalc(struct ieee80211_hw * hw,struct ieee80211_txq * txq)37*4882a593Smuzhiyun static void __ath10k_htt_tx_txq_recalc(struct ieee80211_hw *hw,
38*4882a593Smuzhiyun struct ieee80211_txq *txq)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun struct ath10k *ar = hw->priv;
41*4882a593Smuzhiyun struct ath10k_sta *arsta;
42*4882a593Smuzhiyun struct ath10k_vif *arvif = (void *)txq->vif->drv_priv;
43*4882a593Smuzhiyun unsigned long frame_cnt;
44*4882a593Smuzhiyun unsigned long byte_cnt;
45*4882a593Smuzhiyun int idx;
46*4882a593Smuzhiyun u32 bit;
47*4882a593Smuzhiyun u16 peer_id;
48*4882a593Smuzhiyun u8 tid;
49*4882a593Smuzhiyun u8 count;
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun lockdep_assert_held(&ar->htt.tx_lock);
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun if (!ar->htt.tx_q_state.enabled)
54*4882a593Smuzhiyun return;
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH_PULL)
57*4882a593Smuzhiyun return;
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun if (txq->sta) {
60*4882a593Smuzhiyun arsta = (void *)txq->sta->drv_priv;
61*4882a593Smuzhiyun peer_id = arsta->peer_id;
62*4882a593Smuzhiyun } else {
63*4882a593Smuzhiyun peer_id = arvif->peer_id;
64*4882a593Smuzhiyun }
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun tid = txq->tid;
67*4882a593Smuzhiyun bit = BIT(peer_id % 32);
68*4882a593Smuzhiyun idx = peer_id / 32;
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun ieee80211_txq_get_depth(txq, &frame_cnt, &byte_cnt);
71*4882a593Smuzhiyun count = ath10k_htt_tx_txq_calc_size(byte_cnt);
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun if (unlikely(peer_id >= ar->htt.tx_q_state.num_peers) ||
74*4882a593Smuzhiyun unlikely(tid >= ar->htt.tx_q_state.num_tids)) {
75*4882a593Smuzhiyun ath10k_warn(ar, "refusing to update txq for peer_id %hu tid %hhu due to out of bounds\n",
76*4882a593Smuzhiyun peer_id, tid);
77*4882a593Smuzhiyun return;
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun ar->htt.tx_q_state.vaddr->count[tid][peer_id] = count;
81*4882a593Smuzhiyun ar->htt.tx_q_state.vaddr->map[tid][idx] &= ~bit;
82*4882a593Smuzhiyun ar->htt.tx_q_state.vaddr->map[tid][idx] |= count ? bit : 0;
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx txq state update peer_id %hu tid %hhu count %hhu\n",
85*4882a593Smuzhiyun peer_id, tid, count);
86*4882a593Smuzhiyun }
87*4882a593Smuzhiyun
__ath10k_htt_tx_txq_sync(struct ath10k * ar)88*4882a593Smuzhiyun static void __ath10k_htt_tx_txq_sync(struct ath10k *ar)
89*4882a593Smuzhiyun {
90*4882a593Smuzhiyun u32 seq;
91*4882a593Smuzhiyun size_t size;
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun lockdep_assert_held(&ar->htt.tx_lock);
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun if (!ar->htt.tx_q_state.enabled)
96*4882a593Smuzhiyun return;
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH_PULL)
99*4882a593Smuzhiyun return;
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun seq = le32_to_cpu(ar->htt.tx_q_state.vaddr->seq);
102*4882a593Smuzhiyun seq++;
103*4882a593Smuzhiyun ar->htt.tx_q_state.vaddr->seq = cpu_to_le32(seq);
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx txq state update commit seq %u\n",
106*4882a593Smuzhiyun seq);
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun size = sizeof(*ar->htt.tx_q_state.vaddr);
109*4882a593Smuzhiyun dma_sync_single_for_device(ar->dev,
110*4882a593Smuzhiyun ar->htt.tx_q_state.paddr,
111*4882a593Smuzhiyun size,
112*4882a593Smuzhiyun DMA_TO_DEVICE);
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun
ath10k_htt_tx_txq_recalc(struct ieee80211_hw * hw,struct ieee80211_txq * txq)115*4882a593Smuzhiyun void ath10k_htt_tx_txq_recalc(struct ieee80211_hw *hw,
116*4882a593Smuzhiyun struct ieee80211_txq *txq)
117*4882a593Smuzhiyun {
118*4882a593Smuzhiyun struct ath10k *ar = hw->priv;
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun spin_lock_bh(&ar->htt.tx_lock);
121*4882a593Smuzhiyun __ath10k_htt_tx_txq_recalc(hw, txq);
122*4882a593Smuzhiyun spin_unlock_bh(&ar->htt.tx_lock);
123*4882a593Smuzhiyun }
124*4882a593Smuzhiyun
ath10k_htt_tx_txq_sync(struct ath10k * ar)125*4882a593Smuzhiyun void ath10k_htt_tx_txq_sync(struct ath10k *ar)
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun spin_lock_bh(&ar->htt.tx_lock);
128*4882a593Smuzhiyun __ath10k_htt_tx_txq_sync(ar);
129*4882a593Smuzhiyun spin_unlock_bh(&ar->htt.tx_lock);
130*4882a593Smuzhiyun }
131*4882a593Smuzhiyun
ath10k_htt_tx_txq_update(struct ieee80211_hw * hw,struct ieee80211_txq * txq)132*4882a593Smuzhiyun void ath10k_htt_tx_txq_update(struct ieee80211_hw *hw,
133*4882a593Smuzhiyun struct ieee80211_txq *txq)
134*4882a593Smuzhiyun {
135*4882a593Smuzhiyun struct ath10k *ar = hw->priv;
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun spin_lock_bh(&ar->htt.tx_lock);
138*4882a593Smuzhiyun __ath10k_htt_tx_txq_recalc(hw, txq);
139*4882a593Smuzhiyun __ath10k_htt_tx_txq_sync(ar);
140*4882a593Smuzhiyun spin_unlock_bh(&ar->htt.tx_lock);
141*4882a593Smuzhiyun }
142*4882a593Smuzhiyun
ath10k_htt_tx_dec_pending(struct ath10k_htt * htt)143*4882a593Smuzhiyun void ath10k_htt_tx_dec_pending(struct ath10k_htt *htt)
144*4882a593Smuzhiyun {
145*4882a593Smuzhiyun lockdep_assert_held(&htt->tx_lock);
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun htt->num_pending_tx--;
148*4882a593Smuzhiyun if (htt->num_pending_tx == htt->max_num_pending_tx - 1)
149*4882a593Smuzhiyun ath10k_mac_tx_unlock(htt->ar, ATH10K_TX_PAUSE_Q_FULL);
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun if (htt->num_pending_tx == 0)
152*4882a593Smuzhiyun wake_up(&htt->empty_tx_wq);
153*4882a593Smuzhiyun }
154*4882a593Smuzhiyun
ath10k_htt_tx_inc_pending(struct ath10k_htt * htt)155*4882a593Smuzhiyun int ath10k_htt_tx_inc_pending(struct ath10k_htt *htt)
156*4882a593Smuzhiyun {
157*4882a593Smuzhiyun lockdep_assert_held(&htt->tx_lock);
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun if (htt->num_pending_tx >= htt->max_num_pending_tx)
160*4882a593Smuzhiyun return -EBUSY;
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun htt->num_pending_tx++;
163*4882a593Smuzhiyun if (htt->num_pending_tx == htt->max_num_pending_tx)
164*4882a593Smuzhiyun ath10k_mac_tx_lock(htt->ar, ATH10K_TX_PAUSE_Q_FULL);
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun return 0;
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun
ath10k_htt_tx_mgmt_inc_pending(struct ath10k_htt * htt,bool is_mgmt,bool is_presp)169*4882a593Smuzhiyun int ath10k_htt_tx_mgmt_inc_pending(struct ath10k_htt *htt, bool is_mgmt,
170*4882a593Smuzhiyun bool is_presp)
171*4882a593Smuzhiyun {
172*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun lockdep_assert_held(&htt->tx_lock);
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun if (!is_mgmt || !ar->hw_params.max_probe_resp_desc_thres)
177*4882a593Smuzhiyun return 0;
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun if (is_presp &&
180*4882a593Smuzhiyun ar->hw_params.max_probe_resp_desc_thres < htt->num_pending_mgmt_tx)
181*4882a593Smuzhiyun return -EBUSY;
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun htt->num_pending_mgmt_tx++;
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun return 0;
186*4882a593Smuzhiyun }
187*4882a593Smuzhiyun
ath10k_htt_tx_mgmt_dec_pending(struct ath10k_htt * htt)188*4882a593Smuzhiyun void ath10k_htt_tx_mgmt_dec_pending(struct ath10k_htt *htt)
189*4882a593Smuzhiyun {
190*4882a593Smuzhiyun lockdep_assert_held(&htt->tx_lock);
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun if (!htt->ar->hw_params.max_probe_resp_desc_thres)
193*4882a593Smuzhiyun return;
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun htt->num_pending_mgmt_tx--;
196*4882a593Smuzhiyun }
197*4882a593Smuzhiyun
ath10k_htt_tx_alloc_msdu_id(struct ath10k_htt * htt,struct sk_buff * skb)198*4882a593Smuzhiyun int ath10k_htt_tx_alloc_msdu_id(struct ath10k_htt *htt, struct sk_buff *skb)
199*4882a593Smuzhiyun {
200*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
201*4882a593Smuzhiyun int ret;
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun spin_lock_bh(&htt->tx_lock);
204*4882a593Smuzhiyun ret = idr_alloc(&htt->pending_tx, skb, 0,
205*4882a593Smuzhiyun htt->max_num_pending_tx, GFP_ATOMIC);
206*4882a593Smuzhiyun spin_unlock_bh(&htt->tx_lock);
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx alloc msdu_id %d\n", ret);
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun return ret;
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun
ath10k_htt_tx_free_msdu_id(struct ath10k_htt * htt,u16 msdu_id)213*4882a593Smuzhiyun void ath10k_htt_tx_free_msdu_id(struct ath10k_htt *htt, u16 msdu_id)
214*4882a593Smuzhiyun {
215*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun lockdep_assert_held(&htt->tx_lock);
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx free msdu_id %hu\n", msdu_id);
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun idr_remove(&htt->pending_tx, msdu_id);
222*4882a593Smuzhiyun }
223*4882a593Smuzhiyun
ath10k_htt_tx_free_cont_txbuf_32(struct ath10k_htt * htt)224*4882a593Smuzhiyun static void ath10k_htt_tx_free_cont_txbuf_32(struct ath10k_htt *htt)
225*4882a593Smuzhiyun {
226*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
227*4882a593Smuzhiyun size_t size;
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun if (!htt->txbuf.vaddr_txbuff_32)
230*4882a593Smuzhiyun return;
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun size = htt->txbuf.size;
233*4882a593Smuzhiyun dma_free_coherent(ar->dev, size, htt->txbuf.vaddr_txbuff_32,
234*4882a593Smuzhiyun htt->txbuf.paddr);
235*4882a593Smuzhiyun htt->txbuf.vaddr_txbuff_32 = NULL;
236*4882a593Smuzhiyun }
237*4882a593Smuzhiyun
ath10k_htt_tx_alloc_cont_txbuf_32(struct ath10k_htt * htt)238*4882a593Smuzhiyun static int ath10k_htt_tx_alloc_cont_txbuf_32(struct ath10k_htt *htt)
239*4882a593Smuzhiyun {
240*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
241*4882a593Smuzhiyun size_t size;
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun size = htt->max_num_pending_tx *
244*4882a593Smuzhiyun sizeof(struct ath10k_htt_txbuf_32);
245*4882a593Smuzhiyun
246*4882a593Smuzhiyun htt->txbuf.vaddr_txbuff_32 = dma_alloc_coherent(ar->dev, size,
247*4882a593Smuzhiyun &htt->txbuf.paddr,
248*4882a593Smuzhiyun GFP_KERNEL);
249*4882a593Smuzhiyun if (!htt->txbuf.vaddr_txbuff_32)
250*4882a593Smuzhiyun return -ENOMEM;
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun htt->txbuf.size = size;
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun return 0;
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun
ath10k_htt_tx_free_cont_txbuf_64(struct ath10k_htt * htt)257*4882a593Smuzhiyun static void ath10k_htt_tx_free_cont_txbuf_64(struct ath10k_htt *htt)
258*4882a593Smuzhiyun {
259*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
260*4882a593Smuzhiyun size_t size;
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun if (!htt->txbuf.vaddr_txbuff_64)
263*4882a593Smuzhiyun return;
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun size = htt->txbuf.size;
266*4882a593Smuzhiyun dma_free_coherent(ar->dev, size, htt->txbuf.vaddr_txbuff_64,
267*4882a593Smuzhiyun htt->txbuf.paddr);
268*4882a593Smuzhiyun htt->txbuf.vaddr_txbuff_64 = NULL;
269*4882a593Smuzhiyun }
270*4882a593Smuzhiyun
ath10k_htt_tx_alloc_cont_txbuf_64(struct ath10k_htt * htt)271*4882a593Smuzhiyun static int ath10k_htt_tx_alloc_cont_txbuf_64(struct ath10k_htt *htt)
272*4882a593Smuzhiyun {
273*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
274*4882a593Smuzhiyun size_t size;
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun size = htt->max_num_pending_tx *
277*4882a593Smuzhiyun sizeof(struct ath10k_htt_txbuf_64);
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun htt->txbuf.vaddr_txbuff_64 = dma_alloc_coherent(ar->dev, size,
280*4882a593Smuzhiyun &htt->txbuf.paddr,
281*4882a593Smuzhiyun GFP_KERNEL);
282*4882a593Smuzhiyun if (!htt->txbuf.vaddr_txbuff_64)
283*4882a593Smuzhiyun return -ENOMEM;
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun htt->txbuf.size = size;
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun return 0;
288*4882a593Smuzhiyun }
289*4882a593Smuzhiyun
ath10k_htt_tx_free_cont_frag_desc_32(struct ath10k_htt * htt)290*4882a593Smuzhiyun static void ath10k_htt_tx_free_cont_frag_desc_32(struct ath10k_htt *htt)
291*4882a593Smuzhiyun {
292*4882a593Smuzhiyun size_t size;
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun if (!htt->frag_desc.vaddr_desc_32)
295*4882a593Smuzhiyun return;
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun size = htt->max_num_pending_tx *
298*4882a593Smuzhiyun sizeof(struct htt_msdu_ext_desc);
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun dma_free_coherent(htt->ar->dev,
301*4882a593Smuzhiyun size,
302*4882a593Smuzhiyun htt->frag_desc.vaddr_desc_32,
303*4882a593Smuzhiyun htt->frag_desc.paddr);
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun htt->frag_desc.vaddr_desc_32 = NULL;
306*4882a593Smuzhiyun }
307*4882a593Smuzhiyun
ath10k_htt_tx_alloc_cont_frag_desc_32(struct ath10k_htt * htt)308*4882a593Smuzhiyun static int ath10k_htt_tx_alloc_cont_frag_desc_32(struct ath10k_htt *htt)
309*4882a593Smuzhiyun {
310*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
311*4882a593Smuzhiyun size_t size;
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun if (!ar->hw_params.continuous_frag_desc)
314*4882a593Smuzhiyun return 0;
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun size = htt->max_num_pending_tx *
317*4882a593Smuzhiyun sizeof(struct htt_msdu_ext_desc);
318*4882a593Smuzhiyun htt->frag_desc.vaddr_desc_32 = dma_alloc_coherent(ar->dev, size,
319*4882a593Smuzhiyun &htt->frag_desc.paddr,
320*4882a593Smuzhiyun GFP_KERNEL);
321*4882a593Smuzhiyun if (!htt->frag_desc.vaddr_desc_32) {
322*4882a593Smuzhiyun ath10k_err(ar, "failed to alloc fragment desc memory\n");
323*4882a593Smuzhiyun return -ENOMEM;
324*4882a593Smuzhiyun }
325*4882a593Smuzhiyun htt->frag_desc.size = size;
326*4882a593Smuzhiyun
327*4882a593Smuzhiyun return 0;
328*4882a593Smuzhiyun }
329*4882a593Smuzhiyun
ath10k_htt_tx_free_cont_frag_desc_64(struct ath10k_htt * htt)330*4882a593Smuzhiyun static void ath10k_htt_tx_free_cont_frag_desc_64(struct ath10k_htt *htt)
331*4882a593Smuzhiyun {
332*4882a593Smuzhiyun size_t size;
333*4882a593Smuzhiyun
334*4882a593Smuzhiyun if (!htt->frag_desc.vaddr_desc_64)
335*4882a593Smuzhiyun return;
336*4882a593Smuzhiyun
337*4882a593Smuzhiyun size = htt->max_num_pending_tx *
338*4882a593Smuzhiyun sizeof(struct htt_msdu_ext_desc_64);
339*4882a593Smuzhiyun
340*4882a593Smuzhiyun dma_free_coherent(htt->ar->dev,
341*4882a593Smuzhiyun size,
342*4882a593Smuzhiyun htt->frag_desc.vaddr_desc_64,
343*4882a593Smuzhiyun htt->frag_desc.paddr);
344*4882a593Smuzhiyun
345*4882a593Smuzhiyun htt->frag_desc.vaddr_desc_64 = NULL;
346*4882a593Smuzhiyun }
347*4882a593Smuzhiyun
ath10k_htt_tx_alloc_cont_frag_desc_64(struct ath10k_htt * htt)348*4882a593Smuzhiyun static int ath10k_htt_tx_alloc_cont_frag_desc_64(struct ath10k_htt *htt)
349*4882a593Smuzhiyun {
350*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
351*4882a593Smuzhiyun size_t size;
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun if (!ar->hw_params.continuous_frag_desc)
354*4882a593Smuzhiyun return 0;
355*4882a593Smuzhiyun
356*4882a593Smuzhiyun size = htt->max_num_pending_tx *
357*4882a593Smuzhiyun sizeof(struct htt_msdu_ext_desc_64);
358*4882a593Smuzhiyun
359*4882a593Smuzhiyun htt->frag_desc.vaddr_desc_64 = dma_alloc_coherent(ar->dev, size,
360*4882a593Smuzhiyun &htt->frag_desc.paddr,
361*4882a593Smuzhiyun GFP_KERNEL);
362*4882a593Smuzhiyun if (!htt->frag_desc.vaddr_desc_64) {
363*4882a593Smuzhiyun ath10k_err(ar, "failed to alloc fragment desc memory\n");
364*4882a593Smuzhiyun return -ENOMEM;
365*4882a593Smuzhiyun }
366*4882a593Smuzhiyun htt->frag_desc.size = size;
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun return 0;
369*4882a593Smuzhiyun }
370*4882a593Smuzhiyun
ath10k_htt_tx_free_txq(struct ath10k_htt * htt)371*4882a593Smuzhiyun static void ath10k_htt_tx_free_txq(struct ath10k_htt *htt)
372*4882a593Smuzhiyun {
373*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
374*4882a593Smuzhiyun size_t size;
375*4882a593Smuzhiyun
376*4882a593Smuzhiyun if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
377*4882a593Smuzhiyun ar->running_fw->fw_file.fw_features))
378*4882a593Smuzhiyun return;
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun size = sizeof(*htt->tx_q_state.vaddr);
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun dma_unmap_single(ar->dev, htt->tx_q_state.paddr, size, DMA_TO_DEVICE);
383*4882a593Smuzhiyun kfree(htt->tx_q_state.vaddr);
384*4882a593Smuzhiyun }
385*4882a593Smuzhiyun
ath10k_htt_tx_alloc_txq(struct ath10k_htt * htt)386*4882a593Smuzhiyun static int ath10k_htt_tx_alloc_txq(struct ath10k_htt *htt)
387*4882a593Smuzhiyun {
388*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
389*4882a593Smuzhiyun size_t size;
390*4882a593Smuzhiyun int ret;
391*4882a593Smuzhiyun
392*4882a593Smuzhiyun if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
393*4882a593Smuzhiyun ar->running_fw->fw_file.fw_features))
394*4882a593Smuzhiyun return 0;
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun htt->tx_q_state.num_peers = HTT_TX_Q_STATE_NUM_PEERS;
397*4882a593Smuzhiyun htt->tx_q_state.num_tids = HTT_TX_Q_STATE_NUM_TIDS;
398*4882a593Smuzhiyun htt->tx_q_state.type = HTT_Q_DEPTH_TYPE_BYTES;
399*4882a593Smuzhiyun
400*4882a593Smuzhiyun size = sizeof(*htt->tx_q_state.vaddr);
401*4882a593Smuzhiyun htt->tx_q_state.vaddr = kzalloc(size, GFP_KERNEL);
402*4882a593Smuzhiyun if (!htt->tx_q_state.vaddr)
403*4882a593Smuzhiyun return -ENOMEM;
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun htt->tx_q_state.paddr = dma_map_single(ar->dev, htt->tx_q_state.vaddr,
406*4882a593Smuzhiyun size, DMA_TO_DEVICE);
407*4882a593Smuzhiyun ret = dma_mapping_error(ar->dev, htt->tx_q_state.paddr);
408*4882a593Smuzhiyun if (ret) {
409*4882a593Smuzhiyun ath10k_warn(ar, "failed to dma map tx_q_state: %d\n", ret);
410*4882a593Smuzhiyun kfree(htt->tx_q_state.vaddr);
411*4882a593Smuzhiyun return -EIO;
412*4882a593Smuzhiyun }
413*4882a593Smuzhiyun
414*4882a593Smuzhiyun return 0;
415*4882a593Smuzhiyun }
416*4882a593Smuzhiyun
ath10k_htt_tx_free_txdone_fifo(struct ath10k_htt * htt)417*4882a593Smuzhiyun static void ath10k_htt_tx_free_txdone_fifo(struct ath10k_htt *htt)
418*4882a593Smuzhiyun {
419*4882a593Smuzhiyun WARN_ON(!kfifo_is_empty(&htt->txdone_fifo));
420*4882a593Smuzhiyun kfifo_free(&htt->txdone_fifo);
421*4882a593Smuzhiyun }
422*4882a593Smuzhiyun
ath10k_htt_tx_alloc_txdone_fifo(struct ath10k_htt * htt)423*4882a593Smuzhiyun static int ath10k_htt_tx_alloc_txdone_fifo(struct ath10k_htt *htt)
424*4882a593Smuzhiyun {
425*4882a593Smuzhiyun int ret;
426*4882a593Smuzhiyun size_t size;
427*4882a593Smuzhiyun
428*4882a593Smuzhiyun size = roundup_pow_of_two(htt->max_num_pending_tx);
429*4882a593Smuzhiyun ret = kfifo_alloc(&htt->txdone_fifo, size, GFP_KERNEL);
430*4882a593Smuzhiyun return ret;
431*4882a593Smuzhiyun }
432*4882a593Smuzhiyun
ath10k_htt_tx_alloc_buf(struct ath10k_htt * htt)433*4882a593Smuzhiyun static int ath10k_htt_tx_alloc_buf(struct ath10k_htt *htt)
434*4882a593Smuzhiyun {
435*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
436*4882a593Smuzhiyun int ret;
437*4882a593Smuzhiyun
438*4882a593Smuzhiyun ret = ath10k_htt_alloc_txbuff(htt);
439*4882a593Smuzhiyun if (ret) {
440*4882a593Smuzhiyun ath10k_err(ar, "failed to alloc cont tx buffer: %d\n", ret);
441*4882a593Smuzhiyun return ret;
442*4882a593Smuzhiyun }
443*4882a593Smuzhiyun
444*4882a593Smuzhiyun ret = ath10k_htt_alloc_frag_desc(htt);
445*4882a593Smuzhiyun if (ret) {
446*4882a593Smuzhiyun ath10k_err(ar, "failed to alloc cont frag desc: %d\n", ret);
447*4882a593Smuzhiyun goto free_txbuf;
448*4882a593Smuzhiyun }
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun ret = ath10k_htt_tx_alloc_txq(htt);
451*4882a593Smuzhiyun if (ret) {
452*4882a593Smuzhiyun ath10k_err(ar, "failed to alloc txq: %d\n", ret);
453*4882a593Smuzhiyun goto free_frag_desc;
454*4882a593Smuzhiyun }
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun ret = ath10k_htt_tx_alloc_txdone_fifo(htt);
457*4882a593Smuzhiyun if (ret) {
458*4882a593Smuzhiyun ath10k_err(ar, "failed to alloc txdone fifo: %d\n", ret);
459*4882a593Smuzhiyun goto free_txq;
460*4882a593Smuzhiyun }
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun return 0;
463*4882a593Smuzhiyun
464*4882a593Smuzhiyun free_txq:
465*4882a593Smuzhiyun ath10k_htt_tx_free_txq(htt);
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun free_frag_desc:
468*4882a593Smuzhiyun ath10k_htt_free_frag_desc(htt);
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun free_txbuf:
471*4882a593Smuzhiyun ath10k_htt_free_txbuff(htt);
472*4882a593Smuzhiyun
473*4882a593Smuzhiyun return ret;
474*4882a593Smuzhiyun }
475*4882a593Smuzhiyun
ath10k_htt_tx_start(struct ath10k_htt * htt)476*4882a593Smuzhiyun int ath10k_htt_tx_start(struct ath10k_htt *htt)
477*4882a593Smuzhiyun {
478*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
479*4882a593Smuzhiyun int ret;
480*4882a593Smuzhiyun
481*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt tx max num pending tx %d\n",
482*4882a593Smuzhiyun htt->max_num_pending_tx);
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun spin_lock_init(&htt->tx_lock);
485*4882a593Smuzhiyun idr_init(&htt->pending_tx);
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun if (htt->tx_mem_allocated)
488*4882a593Smuzhiyun return 0;
489*4882a593Smuzhiyun
490*4882a593Smuzhiyun if (ar->bus_param.dev_type == ATH10K_DEV_TYPE_HL)
491*4882a593Smuzhiyun return 0;
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun ret = ath10k_htt_tx_alloc_buf(htt);
494*4882a593Smuzhiyun if (ret)
495*4882a593Smuzhiyun goto free_idr_pending_tx;
496*4882a593Smuzhiyun
497*4882a593Smuzhiyun htt->tx_mem_allocated = true;
498*4882a593Smuzhiyun
499*4882a593Smuzhiyun return 0;
500*4882a593Smuzhiyun
501*4882a593Smuzhiyun free_idr_pending_tx:
502*4882a593Smuzhiyun idr_destroy(&htt->pending_tx);
503*4882a593Smuzhiyun
504*4882a593Smuzhiyun return ret;
505*4882a593Smuzhiyun }
506*4882a593Smuzhiyun
ath10k_htt_tx_clean_up_pending(int msdu_id,void * skb,void * ctx)507*4882a593Smuzhiyun static int ath10k_htt_tx_clean_up_pending(int msdu_id, void *skb, void *ctx)
508*4882a593Smuzhiyun {
509*4882a593Smuzhiyun struct ath10k *ar = ctx;
510*4882a593Smuzhiyun struct ath10k_htt *htt = &ar->htt;
511*4882a593Smuzhiyun struct htt_tx_done tx_done = {0};
512*4882a593Smuzhiyun
513*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_HTT, "force cleanup msdu_id %hu\n", msdu_id);
514*4882a593Smuzhiyun
515*4882a593Smuzhiyun tx_done.msdu_id = msdu_id;
516*4882a593Smuzhiyun tx_done.status = HTT_TX_COMPL_STATE_DISCARD;
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun ath10k_txrx_tx_unref(htt, &tx_done);
519*4882a593Smuzhiyun
520*4882a593Smuzhiyun return 0;
521*4882a593Smuzhiyun }
522*4882a593Smuzhiyun
ath10k_htt_tx_destroy(struct ath10k_htt * htt)523*4882a593Smuzhiyun void ath10k_htt_tx_destroy(struct ath10k_htt *htt)
524*4882a593Smuzhiyun {
525*4882a593Smuzhiyun if (!htt->tx_mem_allocated)
526*4882a593Smuzhiyun return;
527*4882a593Smuzhiyun
528*4882a593Smuzhiyun ath10k_htt_free_txbuff(htt);
529*4882a593Smuzhiyun ath10k_htt_tx_free_txq(htt);
530*4882a593Smuzhiyun ath10k_htt_free_frag_desc(htt);
531*4882a593Smuzhiyun ath10k_htt_tx_free_txdone_fifo(htt);
532*4882a593Smuzhiyun htt->tx_mem_allocated = false;
533*4882a593Smuzhiyun }
534*4882a593Smuzhiyun
ath10k_htt_flush_tx_queue(struct ath10k_htt * htt)535*4882a593Smuzhiyun static void ath10k_htt_flush_tx_queue(struct ath10k_htt *htt)
536*4882a593Smuzhiyun {
537*4882a593Smuzhiyun ath10k_htc_stop_hl(htt->ar);
538*4882a593Smuzhiyun idr_for_each(&htt->pending_tx, ath10k_htt_tx_clean_up_pending, htt->ar);
539*4882a593Smuzhiyun }
540*4882a593Smuzhiyun
ath10k_htt_tx_stop(struct ath10k_htt * htt)541*4882a593Smuzhiyun void ath10k_htt_tx_stop(struct ath10k_htt *htt)
542*4882a593Smuzhiyun {
543*4882a593Smuzhiyun ath10k_htt_flush_tx_queue(htt);
544*4882a593Smuzhiyun idr_destroy(&htt->pending_tx);
545*4882a593Smuzhiyun }
546*4882a593Smuzhiyun
ath10k_htt_tx_free(struct ath10k_htt * htt)547*4882a593Smuzhiyun void ath10k_htt_tx_free(struct ath10k_htt *htt)
548*4882a593Smuzhiyun {
549*4882a593Smuzhiyun ath10k_htt_tx_stop(htt);
550*4882a593Smuzhiyun ath10k_htt_tx_destroy(htt);
551*4882a593Smuzhiyun }
552*4882a593Smuzhiyun
ath10k_htt_op_ep_tx_credits(struct ath10k * ar)553*4882a593Smuzhiyun void ath10k_htt_op_ep_tx_credits(struct ath10k *ar)
554*4882a593Smuzhiyun {
555*4882a593Smuzhiyun queue_work(ar->workqueue, &ar->bundle_tx_work);
556*4882a593Smuzhiyun }
557*4882a593Smuzhiyun
ath10k_htt_htc_tx_complete(struct ath10k * ar,struct sk_buff * skb)558*4882a593Smuzhiyun void ath10k_htt_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
559*4882a593Smuzhiyun {
560*4882a593Smuzhiyun struct ath10k_htt *htt = &ar->htt;
561*4882a593Smuzhiyun struct htt_tx_done tx_done = {0};
562*4882a593Smuzhiyun struct htt_cmd_hdr *htt_hdr;
563*4882a593Smuzhiyun struct htt_data_tx_desc *desc_hdr = NULL;
564*4882a593Smuzhiyun u16 flags1 = 0;
565*4882a593Smuzhiyun u8 msg_type = 0;
566*4882a593Smuzhiyun
567*4882a593Smuzhiyun if (htt->disable_tx_comp) {
568*4882a593Smuzhiyun htt_hdr = (struct htt_cmd_hdr *)skb->data;
569*4882a593Smuzhiyun msg_type = htt_hdr->msg_type;
570*4882a593Smuzhiyun
571*4882a593Smuzhiyun if (msg_type == HTT_H2T_MSG_TYPE_TX_FRM) {
572*4882a593Smuzhiyun desc_hdr = (struct htt_data_tx_desc *)
573*4882a593Smuzhiyun (skb->data + sizeof(*htt_hdr));
574*4882a593Smuzhiyun flags1 = __le16_to_cpu(desc_hdr->flags1);
575*4882a593Smuzhiyun }
576*4882a593Smuzhiyun }
577*4882a593Smuzhiyun
578*4882a593Smuzhiyun dev_kfree_skb_any(skb);
579*4882a593Smuzhiyun
580*4882a593Smuzhiyun if ((!htt->disable_tx_comp) || (msg_type != HTT_H2T_MSG_TYPE_TX_FRM))
581*4882a593Smuzhiyun return;
582*4882a593Smuzhiyun
583*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_HTT,
584*4882a593Smuzhiyun "htt tx complete msdu id:%u ,flags1:%x\n",
585*4882a593Smuzhiyun __le16_to_cpu(desc_hdr->id), flags1);
586*4882a593Smuzhiyun
587*4882a593Smuzhiyun if (flags1 & HTT_DATA_TX_DESC_FLAGS1_TX_COMPLETE)
588*4882a593Smuzhiyun return;
589*4882a593Smuzhiyun
590*4882a593Smuzhiyun tx_done.status = HTT_TX_COMPL_STATE_ACK;
591*4882a593Smuzhiyun tx_done.msdu_id = __le16_to_cpu(desc_hdr->id);
592*4882a593Smuzhiyun ath10k_txrx_tx_unref(&ar->htt, &tx_done);
593*4882a593Smuzhiyun }
594*4882a593Smuzhiyun
ath10k_htt_hif_tx_complete(struct ath10k * ar,struct sk_buff * skb)595*4882a593Smuzhiyun void ath10k_htt_hif_tx_complete(struct ath10k *ar, struct sk_buff *skb)
596*4882a593Smuzhiyun {
597*4882a593Smuzhiyun dev_kfree_skb_any(skb);
598*4882a593Smuzhiyun }
599*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_htt_hif_tx_complete);
600*4882a593Smuzhiyun
ath10k_htt_h2t_ver_req_msg(struct ath10k_htt * htt)601*4882a593Smuzhiyun int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt *htt)
602*4882a593Smuzhiyun {
603*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
604*4882a593Smuzhiyun struct sk_buff *skb;
605*4882a593Smuzhiyun struct htt_cmd *cmd;
606*4882a593Smuzhiyun int len = 0;
607*4882a593Smuzhiyun int ret;
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun len += sizeof(cmd->hdr);
610*4882a593Smuzhiyun len += sizeof(cmd->ver_req);
611*4882a593Smuzhiyun
612*4882a593Smuzhiyun skb = ath10k_htc_alloc_skb(ar, len);
613*4882a593Smuzhiyun if (!skb)
614*4882a593Smuzhiyun return -ENOMEM;
615*4882a593Smuzhiyun
616*4882a593Smuzhiyun skb_put(skb, len);
617*4882a593Smuzhiyun cmd = (struct htt_cmd *)skb->data;
618*4882a593Smuzhiyun cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_VERSION_REQ;
619*4882a593Smuzhiyun
620*4882a593Smuzhiyun ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
621*4882a593Smuzhiyun if (ret) {
622*4882a593Smuzhiyun dev_kfree_skb_any(skb);
623*4882a593Smuzhiyun return ret;
624*4882a593Smuzhiyun }
625*4882a593Smuzhiyun
626*4882a593Smuzhiyun return 0;
627*4882a593Smuzhiyun }
628*4882a593Smuzhiyun
ath10k_htt_h2t_stats_req(struct ath10k_htt * htt,u32 mask,u32 reset_mask,u64 cookie)629*4882a593Smuzhiyun int ath10k_htt_h2t_stats_req(struct ath10k_htt *htt, u32 mask, u32 reset_mask,
630*4882a593Smuzhiyun u64 cookie)
631*4882a593Smuzhiyun {
632*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
633*4882a593Smuzhiyun struct htt_stats_req *req;
634*4882a593Smuzhiyun struct sk_buff *skb;
635*4882a593Smuzhiyun struct htt_cmd *cmd;
636*4882a593Smuzhiyun int len = 0, ret;
637*4882a593Smuzhiyun
638*4882a593Smuzhiyun len += sizeof(cmd->hdr);
639*4882a593Smuzhiyun len += sizeof(cmd->stats_req);
640*4882a593Smuzhiyun
641*4882a593Smuzhiyun skb = ath10k_htc_alloc_skb(ar, len);
642*4882a593Smuzhiyun if (!skb)
643*4882a593Smuzhiyun return -ENOMEM;
644*4882a593Smuzhiyun
645*4882a593Smuzhiyun skb_put(skb, len);
646*4882a593Smuzhiyun cmd = (struct htt_cmd *)skb->data;
647*4882a593Smuzhiyun cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_STATS_REQ;
648*4882a593Smuzhiyun
649*4882a593Smuzhiyun req = &cmd->stats_req;
650*4882a593Smuzhiyun
651*4882a593Smuzhiyun memset(req, 0, sizeof(*req));
652*4882a593Smuzhiyun
653*4882a593Smuzhiyun /* currently we support only max 24 bit masks so no need to worry
654*4882a593Smuzhiyun * about endian support
655*4882a593Smuzhiyun */
656*4882a593Smuzhiyun memcpy(req->upload_types, &mask, 3);
657*4882a593Smuzhiyun memcpy(req->reset_types, &reset_mask, 3);
658*4882a593Smuzhiyun req->stat_type = HTT_STATS_REQ_CFG_STAT_TYPE_INVALID;
659*4882a593Smuzhiyun req->cookie_lsb = cpu_to_le32(cookie & 0xffffffff);
660*4882a593Smuzhiyun req->cookie_msb = cpu_to_le32((cookie & 0xffffffff00000000ULL) >> 32);
661*4882a593Smuzhiyun
662*4882a593Smuzhiyun ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
663*4882a593Smuzhiyun if (ret) {
664*4882a593Smuzhiyun ath10k_warn(ar, "failed to send htt type stats request: %d",
665*4882a593Smuzhiyun ret);
666*4882a593Smuzhiyun dev_kfree_skb_any(skb);
667*4882a593Smuzhiyun return ret;
668*4882a593Smuzhiyun }
669*4882a593Smuzhiyun
670*4882a593Smuzhiyun return 0;
671*4882a593Smuzhiyun }
672*4882a593Smuzhiyun
ath10k_htt_send_frag_desc_bank_cfg_32(struct ath10k_htt * htt)673*4882a593Smuzhiyun static int ath10k_htt_send_frag_desc_bank_cfg_32(struct ath10k_htt *htt)
674*4882a593Smuzhiyun {
675*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
676*4882a593Smuzhiyun struct sk_buff *skb;
677*4882a593Smuzhiyun struct htt_cmd *cmd;
678*4882a593Smuzhiyun struct htt_frag_desc_bank_cfg32 *cfg;
679*4882a593Smuzhiyun int ret, size;
680*4882a593Smuzhiyun u8 info;
681*4882a593Smuzhiyun
682*4882a593Smuzhiyun if (!ar->hw_params.continuous_frag_desc)
683*4882a593Smuzhiyun return 0;
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun if (!htt->frag_desc.paddr) {
686*4882a593Smuzhiyun ath10k_warn(ar, "invalid frag desc memory\n");
687*4882a593Smuzhiyun return -EINVAL;
688*4882a593Smuzhiyun }
689*4882a593Smuzhiyun
690*4882a593Smuzhiyun size = sizeof(cmd->hdr) + sizeof(cmd->frag_desc_bank_cfg32);
691*4882a593Smuzhiyun skb = ath10k_htc_alloc_skb(ar, size);
692*4882a593Smuzhiyun if (!skb)
693*4882a593Smuzhiyun return -ENOMEM;
694*4882a593Smuzhiyun
695*4882a593Smuzhiyun skb_put(skb, size);
696*4882a593Smuzhiyun cmd = (struct htt_cmd *)skb->data;
697*4882a593Smuzhiyun cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_FRAG_DESC_BANK_CFG;
698*4882a593Smuzhiyun
699*4882a593Smuzhiyun info = 0;
700*4882a593Smuzhiyun info |= SM(htt->tx_q_state.type,
701*4882a593Smuzhiyun HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_DEPTH_TYPE);
702*4882a593Smuzhiyun
703*4882a593Smuzhiyun if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
704*4882a593Smuzhiyun ar->running_fw->fw_file.fw_features))
705*4882a593Smuzhiyun info |= HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_VALID;
706*4882a593Smuzhiyun
707*4882a593Smuzhiyun cfg = &cmd->frag_desc_bank_cfg32;
708*4882a593Smuzhiyun cfg->info = info;
709*4882a593Smuzhiyun cfg->num_banks = 1;
710*4882a593Smuzhiyun cfg->desc_size = sizeof(struct htt_msdu_ext_desc);
711*4882a593Smuzhiyun cfg->bank_base_addrs[0] = __cpu_to_le32(htt->frag_desc.paddr);
712*4882a593Smuzhiyun cfg->bank_id[0].bank_min_id = 0;
713*4882a593Smuzhiyun cfg->bank_id[0].bank_max_id = __cpu_to_le16(htt->max_num_pending_tx -
714*4882a593Smuzhiyun 1);
715*4882a593Smuzhiyun
716*4882a593Smuzhiyun cfg->q_state.paddr = cpu_to_le32(htt->tx_q_state.paddr);
717*4882a593Smuzhiyun cfg->q_state.num_peers = cpu_to_le16(htt->tx_q_state.num_peers);
718*4882a593Smuzhiyun cfg->q_state.num_tids = cpu_to_le16(htt->tx_q_state.num_tids);
719*4882a593Smuzhiyun cfg->q_state.record_size = HTT_TX_Q_STATE_ENTRY_SIZE;
720*4882a593Smuzhiyun cfg->q_state.record_multiplier = HTT_TX_Q_STATE_ENTRY_MULTIPLIER;
721*4882a593Smuzhiyun
722*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_HTT, "htt frag desc bank cmd\n");
723*4882a593Smuzhiyun
724*4882a593Smuzhiyun ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
725*4882a593Smuzhiyun if (ret) {
726*4882a593Smuzhiyun ath10k_warn(ar, "failed to send frag desc bank cfg request: %d\n",
727*4882a593Smuzhiyun ret);
728*4882a593Smuzhiyun dev_kfree_skb_any(skb);
729*4882a593Smuzhiyun return ret;
730*4882a593Smuzhiyun }
731*4882a593Smuzhiyun
732*4882a593Smuzhiyun return 0;
733*4882a593Smuzhiyun }
734*4882a593Smuzhiyun
ath10k_htt_send_frag_desc_bank_cfg_64(struct ath10k_htt * htt)735*4882a593Smuzhiyun static int ath10k_htt_send_frag_desc_bank_cfg_64(struct ath10k_htt *htt)
736*4882a593Smuzhiyun {
737*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
738*4882a593Smuzhiyun struct sk_buff *skb;
739*4882a593Smuzhiyun struct htt_cmd *cmd;
740*4882a593Smuzhiyun struct htt_frag_desc_bank_cfg64 *cfg;
741*4882a593Smuzhiyun int ret, size;
742*4882a593Smuzhiyun u8 info;
743*4882a593Smuzhiyun
744*4882a593Smuzhiyun if (!ar->hw_params.continuous_frag_desc)
745*4882a593Smuzhiyun return 0;
746*4882a593Smuzhiyun
747*4882a593Smuzhiyun if (!htt->frag_desc.paddr) {
748*4882a593Smuzhiyun ath10k_warn(ar, "invalid frag desc memory\n");
749*4882a593Smuzhiyun return -EINVAL;
750*4882a593Smuzhiyun }
751*4882a593Smuzhiyun
752*4882a593Smuzhiyun size = sizeof(cmd->hdr) + sizeof(cmd->frag_desc_bank_cfg64);
753*4882a593Smuzhiyun skb = ath10k_htc_alloc_skb(ar, size);
754*4882a593Smuzhiyun if (!skb)
755*4882a593Smuzhiyun return -ENOMEM;
756*4882a593Smuzhiyun
757*4882a593Smuzhiyun skb_put(skb, size);
758*4882a593Smuzhiyun cmd = (struct htt_cmd *)skb->data;
759*4882a593Smuzhiyun cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_FRAG_DESC_BANK_CFG;
760*4882a593Smuzhiyun
761*4882a593Smuzhiyun info = 0;
762*4882a593Smuzhiyun info |= SM(htt->tx_q_state.type,
763*4882a593Smuzhiyun HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_DEPTH_TYPE);
764*4882a593Smuzhiyun
765*4882a593Smuzhiyun if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
766*4882a593Smuzhiyun ar->running_fw->fw_file.fw_features))
767*4882a593Smuzhiyun info |= HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_VALID;
768*4882a593Smuzhiyun
769*4882a593Smuzhiyun cfg = &cmd->frag_desc_bank_cfg64;
770*4882a593Smuzhiyun cfg->info = info;
771*4882a593Smuzhiyun cfg->num_banks = 1;
772*4882a593Smuzhiyun cfg->desc_size = sizeof(struct htt_msdu_ext_desc_64);
773*4882a593Smuzhiyun cfg->bank_base_addrs[0] = __cpu_to_le64(htt->frag_desc.paddr);
774*4882a593Smuzhiyun cfg->bank_id[0].bank_min_id = 0;
775*4882a593Smuzhiyun cfg->bank_id[0].bank_max_id = __cpu_to_le16(htt->max_num_pending_tx -
776*4882a593Smuzhiyun 1);
777*4882a593Smuzhiyun
778*4882a593Smuzhiyun cfg->q_state.paddr = cpu_to_le32(htt->tx_q_state.paddr);
779*4882a593Smuzhiyun cfg->q_state.num_peers = cpu_to_le16(htt->tx_q_state.num_peers);
780*4882a593Smuzhiyun cfg->q_state.num_tids = cpu_to_le16(htt->tx_q_state.num_tids);
781*4882a593Smuzhiyun cfg->q_state.record_size = HTT_TX_Q_STATE_ENTRY_SIZE;
782*4882a593Smuzhiyun cfg->q_state.record_multiplier = HTT_TX_Q_STATE_ENTRY_MULTIPLIER;
783*4882a593Smuzhiyun
784*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_HTT, "htt frag desc bank cmd\n");
785*4882a593Smuzhiyun
786*4882a593Smuzhiyun ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
787*4882a593Smuzhiyun if (ret) {
788*4882a593Smuzhiyun ath10k_warn(ar, "failed to send frag desc bank cfg request: %d\n",
789*4882a593Smuzhiyun ret);
790*4882a593Smuzhiyun dev_kfree_skb_any(skb);
791*4882a593Smuzhiyun return ret;
792*4882a593Smuzhiyun }
793*4882a593Smuzhiyun
794*4882a593Smuzhiyun return 0;
795*4882a593Smuzhiyun }
796*4882a593Smuzhiyun
ath10k_htt_fill_rx_desc_offset_32(void * rx_ring)797*4882a593Smuzhiyun static void ath10k_htt_fill_rx_desc_offset_32(void *rx_ring)
798*4882a593Smuzhiyun {
799*4882a593Smuzhiyun struct htt_rx_ring_setup_ring32 *ring =
800*4882a593Smuzhiyun (struct htt_rx_ring_setup_ring32 *)rx_ring;
801*4882a593Smuzhiyun
802*4882a593Smuzhiyun #define desc_offset(x) (offsetof(struct htt_rx_desc, x) / 4)
803*4882a593Smuzhiyun ring->mac80211_hdr_offset = __cpu_to_le16(desc_offset(rx_hdr_status));
804*4882a593Smuzhiyun ring->msdu_payload_offset = __cpu_to_le16(desc_offset(msdu_payload));
805*4882a593Smuzhiyun ring->ppdu_start_offset = __cpu_to_le16(desc_offset(ppdu_start));
806*4882a593Smuzhiyun ring->ppdu_end_offset = __cpu_to_le16(desc_offset(ppdu_end));
807*4882a593Smuzhiyun ring->mpdu_start_offset = __cpu_to_le16(desc_offset(mpdu_start));
808*4882a593Smuzhiyun ring->mpdu_end_offset = __cpu_to_le16(desc_offset(mpdu_end));
809*4882a593Smuzhiyun ring->msdu_start_offset = __cpu_to_le16(desc_offset(msdu_start));
810*4882a593Smuzhiyun ring->msdu_end_offset = __cpu_to_le16(desc_offset(msdu_end));
811*4882a593Smuzhiyun ring->rx_attention_offset = __cpu_to_le16(desc_offset(attention));
812*4882a593Smuzhiyun ring->frag_info_offset = __cpu_to_le16(desc_offset(frag_info));
813*4882a593Smuzhiyun #undef desc_offset
814*4882a593Smuzhiyun }
815*4882a593Smuzhiyun
ath10k_htt_fill_rx_desc_offset_64(void * rx_ring)816*4882a593Smuzhiyun static void ath10k_htt_fill_rx_desc_offset_64(void *rx_ring)
817*4882a593Smuzhiyun {
818*4882a593Smuzhiyun struct htt_rx_ring_setup_ring64 *ring =
819*4882a593Smuzhiyun (struct htt_rx_ring_setup_ring64 *)rx_ring;
820*4882a593Smuzhiyun
821*4882a593Smuzhiyun #define desc_offset(x) (offsetof(struct htt_rx_desc, x) / 4)
822*4882a593Smuzhiyun ring->mac80211_hdr_offset = __cpu_to_le16(desc_offset(rx_hdr_status));
823*4882a593Smuzhiyun ring->msdu_payload_offset = __cpu_to_le16(desc_offset(msdu_payload));
824*4882a593Smuzhiyun ring->ppdu_start_offset = __cpu_to_le16(desc_offset(ppdu_start));
825*4882a593Smuzhiyun ring->ppdu_end_offset = __cpu_to_le16(desc_offset(ppdu_end));
826*4882a593Smuzhiyun ring->mpdu_start_offset = __cpu_to_le16(desc_offset(mpdu_start));
827*4882a593Smuzhiyun ring->mpdu_end_offset = __cpu_to_le16(desc_offset(mpdu_end));
828*4882a593Smuzhiyun ring->msdu_start_offset = __cpu_to_le16(desc_offset(msdu_start));
829*4882a593Smuzhiyun ring->msdu_end_offset = __cpu_to_le16(desc_offset(msdu_end));
830*4882a593Smuzhiyun ring->rx_attention_offset = __cpu_to_le16(desc_offset(attention));
831*4882a593Smuzhiyun ring->frag_info_offset = __cpu_to_le16(desc_offset(frag_info));
832*4882a593Smuzhiyun #undef desc_offset
833*4882a593Smuzhiyun }
834*4882a593Smuzhiyun
ath10k_htt_send_rx_ring_cfg_32(struct ath10k_htt * htt)835*4882a593Smuzhiyun static int ath10k_htt_send_rx_ring_cfg_32(struct ath10k_htt *htt)
836*4882a593Smuzhiyun {
837*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
838*4882a593Smuzhiyun struct sk_buff *skb;
839*4882a593Smuzhiyun struct htt_cmd *cmd;
840*4882a593Smuzhiyun struct htt_rx_ring_setup_ring32 *ring;
841*4882a593Smuzhiyun const int num_rx_ring = 1;
842*4882a593Smuzhiyun u16 flags;
843*4882a593Smuzhiyun u32 fw_idx;
844*4882a593Smuzhiyun int len;
845*4882a593Smuzhiyun int ret;
846*4882a593Smuzhiyun
847*4882a593Smuzhiyun /*
848*4882a593Smuzhiyun * the HW expects the buffer to be an integral number of 4-byte
849*4882a593Smuzhiyun * "words"
850*4882a593Smuzhiyun */
851*4882a593Smuzhiyun BUILD_BUG_ON(!IS_ALIGNED(HTT_RX_BUF_SIZE, 4));
852*4882a593Smuzhiyun BUILD_BUG_ON((HTT_RX_BUF_SIZE & HTT_MAX_CACHE_LINE_SIZE_MASK) != 0);
853*4882a593Smuzhiyun
854*4882a593Smuzhiyun len = sizeof(cmd->hdr) + sizeof(cmd->rx_setup_32.hdr)
855*4882a593Smuzhiyun + (sizeof(*ring) * num_rx_ring);
856*4882a593Smuzhiyun skb = ath10k_htc_alloc_skb(ar, len);
857*4882a593Smuzhiyun if (!skb)
858*4882a593Smuzhiyun return -ENOMEM;
859*4882a593Smuzhiyun
860*4882a593Smuzhiyun skb_put(skb, len);
861*4882a593Smuzhiyun
862*4882a593Smuzhiyun cmd = (struct htt_cmd *)skb->data;
863*4882a593Smuzhiyun ring = &cmd->rx_setup_32.rings[0];
864*4882a593Smuzhiyun
865*4882a593Smuzhiyun cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_RX_RING_CFG;
866*4882a593Smuzhiyun cmd->rx_setup_32.hdr.num_rings = 1;
867*4882a593Smuzhiyun
868*4882a593Smuzhiyun /* FIXME: do we need all of this? */
869*4882a593Smuzhiyun flags = 0;
870*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MAC80211_HDR;
871*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MSDU_PAYLOAD;
872*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_PPDU_START;
873*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_PPDU_END;
874*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MPDU_START;
875*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MPDU_END;
876*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MSDU_START;
877*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MSDU_END;
878*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_RX_ATTENTION;
879*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_FRAG_INFO;
880*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_UNICAST_RX;
881*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MULTICAST_RX;
882*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_CTRL_RX;
883*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MGMT_RX;
884*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_NULL_RX;
885*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_PHY_DATA_RX;
886*4882a593Smuzhiyun
887*4882a593Smuzhiyun fw_idx = __le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr);
888*4882a593Smuzhiyun
889*4882a593Smuzhiyun ring->fw_idx_shadow_reg_paddr =
890*4882a593Smuzhiyun __cpu_to_le32(htt->rx_ring.alloc_idx.paddr);
891*4882a593Smuzhiyun ring->rx_ring_base_paddr = __cpu_to_le32(htt->rx_ring.base_paddr);
892*4882a593Smuzhiyun ring->rx_ring_len = __cpu_to_le16(htt->rx_ring.size);
893*4882a593Smuzhiyun ring->rx_ring_bufsize = __cpu_to_le16(HTT_RX_BUF_SIZE);
894*4882a593Smuzhiyun ring->flags = __cpu_to_le16(flags);
895*4882a593Smuzhiyun ring->fw_idx_init_val = __cpu_to_le16(fw_idx);
896*4882a593Smuzhiyun
897*4882a593Smuzhiyun ath10k_htt_fill_rx_desc_offset_32(ring);
898*4882a593Smuzhiyun ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
899*4882a593Smuzhiyun if (ret) {
900*4882a593Smuzhiyun dev_kfree_skb_any(skb);
901*4882a593Smuzhiyun return ret;
902*4882a593Smuzhiyun }
903*4882a593Smuzhiyun
904*4882a593Smuzhiyun return 0;
905*4882a593Smuzhiyun }
906*4882a593Smuzhiyun
ath10k_htt_send_rx_ring_cfg_64(struct ath10k_htt * htt)907*4882a593Smuzhiyun static int ath10k_htt_send_rx_ring_cfg_64(struct ath10k_htt *htt)
908*4882a593Smuzhiyun {
909*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
910*4882a593Smuzhiyun struct sk_buff *skb;
911*4882a593Smuzhiyun struct htt_cmd *cmd;
912*4882a593Smuzhiyun struct htt_rx_ring_setup_ring64 *ring;
913*4882a593Smuzhiyun const int num_rx_ring = 1;
914*4882a593Smuzhiyun u16 flags;
915*4882a593Smuzhiyun u32 fw_idx;
916*4882a593Smuzhiyun int len;
917*4882a593Smuzhiyun int ret;
918*4882a593Smuzhiyun
919*4882a593Smuzhiyun /* HW expects the buffer to be an integral number of 4-byte
920*4882a593Smuzhiyun * "words"
921*4882a593Smuzhiyun */
922*4882a593Smuzhiyun BUILD_BUG_ON(!IS_ALIGNED(HTT_RX_BUF_SIZE, 4));
923*4882a593Smuzhiyun BUILD_BUG_ON((HTT_RX_BUF_SIZE & HTT_MAX_CACHE_LINE_SIZE_MASK) != 0);
924*4882a593Smuzhiyun
925*4882a593Smuzhiyun len = sizeof(cmd->hdr) + sizeof(cmd->rx_setup_64.hdr)
926*4882a593Smuzhiyun + (sizeof(*ring) * num_rx_ring);
927*4882a593Smuzhiyun skb = ath10k_htc_alloc_skb(ar, len);
928*4882a593Smuzhiyun if (!skb)
929*4882a593Smuzhiyun return -ENOMEM;
930*4882a593Smuzhiyun
931*4882a593Smuzhiyun skb_put(skb, len);
932*4882a593Smuzhiyun
933*4882a593Smuzhiyun cmd = (struct htt_cmd *)skb->data;
934*4882a593Smuzhiyun ring = &cmd->rx_setup_64.rings[0];
935*4882a593Smuzhiyun
936*4882a593Smuzhiyun cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_RX_RING_CFG;
937*4882a593Smuzhiyun cmd->rx_setup_64.hdr.num_rings = 1;
938*4882a593Smuzhiyun
939*4882a593Smuzhiyun flags = 0;
940*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MAC80211_HDR;
941*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MSDU_PAYLOAD;
942*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_PPDU_START;
943*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_PPDU_END;
944*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MPDU_START;
945*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MPDU_END;
946*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MSDU_START;
947*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MSDU_END;
948*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_RX_ATTENTION;
949*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_FRAG_INFO;
950*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_UNICAST_RX;
951*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MULTICAST_RX;
952*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_CTRL_RX;
953*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MGMT_RX;
954*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_NULL_RX;
955*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_PHY_DATA_RX;
956*4882a593Smuzhiyun
957*4882a593Smuzhiyun fw_idx = __le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr);
958*4882a593Smuzhiyun
959*4882a593Smuzhiyun ring->fw_idx_shadow_reg_paddr = __cpu_to_le64(htt->rx_ring.alloc_idx.paddr);
960*4882a593Smuzhiyun ring->rx_ring_base_paddr = __cpu_to_le64(htt->rx_ring.base_paddr);
961*4882a593Smuzhiyun ring->rx_ring_len = __cpu_to_le16(htt->rx_ring.size);
962*4882a593Smuzhiyun ring->rx_ring_bufsize = __cpu_to_le16(HTT_RX_BUF_SIZE);
963*4882a593Smuzhiyun ring->flags = __cpu_to_le16(flags);
964*4882a593Smuzhiyun ring->fw_idx_init_val = __cpu_to_le16(fw_idx);
965*4882a593Smuzhiyun
966*4882a593Smuzhiyun ath10k_htt_fill_rx_desc_offset_64(ring);
967*4882a593Smuzhiyun ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
968*4882a593Smuzhiyun if (ret) {
969*4882a593Smuzhiyun dev_kfree_skb_any(skb);
970*4882a593Smuzhiyun return ret;
971*4882a593Smuzhiyun }
972*4882a593Smuzhiyun
973*4882a593Smuzhiyun return 0;
974*4882a593Smuzhiyun }
975*4882a593Smuzhiyun
ath10k_htt_send_rx_ring_cfg_hl(struct ath10k_htt * htt)976*4882a593Smuzhiyun static int ath10k_htt_send_rx_ring_cfg_hl(struct ath10k_htt *htt)
977*4882a593Smuzhiyun {
978*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
979*4882a593Smuzhiyun struct sk_buff *skb;
980*4882a593Smuzhiyun struct htt_cmd *cmd;
981*4882a593Smuzhiyun struct htt_rx_ring_setup_ring32 *ring;
982*4882a593Smuzhiyun const int num_rx_ring = 1;
983*4882a593Smuzhiyun u16 flags;
984*4882a593Smuzhiyun int len;
985*4882a593Smuzhiyun int ret;
986*4882a593Smuzhiyun
987*4882a593Smuzhiyun /*
988*4882a593Smuzhiyun * the HW expects the buffer to be an integral number of 4-byte
989*4882a593Smuzhiyun * "words"
990*4882a593Smuzhiyun */
991*4882a593Smuzhiyun BUILD_BUG_ON(!IS_ALIGNED(HTT_RX_BUF_SIZE, 4));
992*4882a593Smuzhiyun BUILD_BUG_ON((HTT_RX_BUF_SIZE & HTT_MAX_CACHE_LINE_SIZE_MASK) != 0);
993*4882a593Smuzhiyun
994*4882a593Smuzhiyun len = sizeof(cmd->hdr) + sizeof(cmd->rx_setup_32.hdr)
995*4882a593Smuzhiyun + (sizeof(*ring) * num_rx_ring);
996*4882a593Smuzhiyun skb = ath10k_htc_alloc_skb(ar, len);
997*4882a593Smuzhiyun if (!skb)
998*4882a593Smuzhiyun return -ENOMEM;
999*4882a593Smuzhiyun
1000*4882a593Smuzhiyun skb_put(skb, len);
1001*4882a593Smuzhiyun
1002*4882a593Smuzhiyun cmd = (struct htt_cmd *)skb->data;
1003*4882a593Smuzhiyun ring = &cmd->rx_setup_32.rings[0];
1004*4882a593Smuzhiyun
1005*4882a593Smuzhiyun cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_RX_RING_CFG;
1006*4882a593Smuzhiyun cmd->rx_setup_32.hdr.num_rings = 1;
1007*4882a593Smuzhiyun
1008*4882a593Smuzhiyun flags = 0;
1009*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MSDU_PAYLOAD;
1010*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_UNICAST_RX;
1011*4882a593Smuzhiyun flags |= HTT_RX_RING_FLAGS_MULTICAST_RX;
1012*4882a593Smuzhiyun
1013*4882a593Smuzhiyun memset(ring, 0, sizeof(*ring));
1014*4882a593Smuzhiyun ring->rx_ring_len = __cpu_to_le16(HTT_RX_RING_SIZE_MIN);
1015*4882a593Smuzhiyun ring->rx_ring_bufsize = __cpu_to_le16(HTT_RX_BUF_SIZE);
1016*4882a593Smuzhiyun ring->flags = __cpu_to_le16(flags);
1017*4882a593Smuzhiyun
1018*4882a593Smuzhiyun ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
1019*4882a593Smuzhiyun if (ret) {
1020*4882a593Smuzhiyun dev_kfree_skb_any(skb);
1021*4882a593Smuzhiyun return ret;
1022*4882a593Smuzhiyun }
1023*4882a593Smuzhiyun
1024*4882a593Smuzhiyun return 0;
1025*4882a593Smuzhiyun }
1026*4882a593Smuzhiyun
ath10k_htt_h2t_aggr_cfg_msg_32(struct ath10k_htt * htt,u8 max_subfrms_ampdu,u8 max_subfrms_amsdu)1027*4882a593Smuzhiyun static int ath10k_htt_h2t_aggr_cfg_msg_32(struct ath10k_htt *htt,
1028*4882a593Smuzhiyun u8 max_subfrms_ampdu,
1029*4882a593Smuzhiyun u8 max_subfrms_amsdu)
1030*4882a593Smuzhiyun {
1031*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
1032*4882a593Smuzhiyun struct htt_aggr_conf *aggr_conf;
1033*4882a593Smuzhiyun struct sk_buff *skb;
1034*4882a593Smuzhiyun struct htt_cmd *cmd;
1035*4882a593Smuzhiyun int len;
1036*4882a593Smuzhiyun int ret;
1037*4882a593Smuzhiyun
1038*4882a593Smuzhiyun /* Firmware defaults are: amsdu = 3 and ampdu = 64 */
1039*4882a593Smuzhiyun
1040*4882a593Smuzhiyun if (max_subfrms_ampdu == 0 || max_subfrms_ampdu > 64)
1041*4882a593Smuzhiyun return -EINVAL;
1042*4882a593Smuzhiyun
1043*4882a593Smuzhiyun if (max_subfrms_amsdu == 0 || max_subfrms_amsdu > 31)
1044*4882a593Smuzhiyun return -EINVAL;
1045*4882a593Smuzhiyun
1046*4882a593Smuzhiyun len = sizeof(cmd->hdr);
1047*4882a593Smuzhiyun len += sizeof(cmd->aggr_conf);
1048*4882a593Smuzhiyun
1049*4882a593Smuzhiyun skb = ath10k_htc_alloc_skb(ar, len);
1050*4882a593Smuzhiyun if (!skb)
1051*4882a593Smuzhiyun return -ENOMEM;
1052*4882a593Smuzhiyun
1053*4882a593Smuzhiyun skb_put(skb, len);
1054*4882a593Smuzhiyun cmd = (struct htt_cmd *)skb->data;
1055*4882a593Smuzhiyun cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_AGGR_CFG;
1056*4882a593Smuzhiyun
1057*4882a593Smuzhiyun aggr_conf = &cmd->aggr_conf;
1058*4882a593Smuzhiyun aggr_conf->max_num_ampdu_subframes = max_subfrms_ampdu;
1059*4882a593Smuzhiyun aggr_conf->max_num_amsdu_subframes = max_subfrms_amsdu;
1060*4882a593Smuzhiyun
1061*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_HTT, "htt h2t aggr cfg msg amsdu %d ampdu %d",
1062*4882a593Smuzhiyun aggr_conf->max_num_amsdu_subframes,
1063*4882a593Smuzhiyun aggr_conf->max_num_ampdu_subframes);
1064*4882a593Smuzhiyun
1065*4882a593Smuzhiyun ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
1066*4882a593Smuzhiyun if (ret) {
1067*4882a593Smuzhiyun dev_kfree_skb_any(skb);
1068*4882a593Smuzhiyun return ret;
1069*4882a593Smuzhiyun }
1070*4882a593Smuzhiyun
1071*4882a593Smuzhiyun return 0;
1072*4882a593Smuzhiyun }
1073*4882a593Smuzhiyun
ath10k_htt_h2t_aggr_cfg_msg_v2(struct ath10k_htt * htt,u8 max_subfrms_ampdu,u8 max_subfrms_amsdu)1074*4882a593Smuzhiyun static int ath10k_htt_h2t_aggr_cfg_msg_v2(struct ath10k_htt *htt,
1075*4882a593Smuzhiyun u8 max_subfrms_ampdu,
1076*4882a593Smuzhiyun u8 max_subfrms_amsdu)
1077*4882a593Smuzhiyun {
1078*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
1079*4882a593Smuzhiyun struct htt_aggr_conf_v2 *aggr_conf;
1080*4882a593Smuzhiyun struct sk_buff *skb;
1081*4882a593Smuzhiyun struct htt_cmd *cmd;
1082*4882a593Smuzhiyun int len;
1083*4882a593Smuzhiyun int ret;
1084*4882a593Smuzhiyun
1085*4882a593Smuzhiyun /* Firmware defaults are: amsdu = 3 and ampdu = 64 */
1086*4882a593Smuzhiyun
1087*4882a593Smuzhiyun if (max_subfrms_ampdu == 0 || max_subfrms_ampdu > 64)
1088*4882a593Smuzhiyun return -EINVAL;
1089*4882a593Smuzhiyun
1090*4882a593Smuzhiyun if (max_subfrms_amsdu == 0 || max_subfrms_amsdu > 31)
1091*4882a593Smuzhiyun return -EINVAL;
1092*4882a593Smuzhiyun
1093*4882a593Smuzhiyun len = sizeof(cmd->hdr);
1094*4882a593Smuzhiyun len += sizeof(cmd->aggr_conf_v2);
1095*4882a593Smuzhiyun
1096*4882a593Smuzhiyun skb = ath10k_htc_alloc_skb(ar, len);
1097*4882a593Smuzhiyun if (!skb)
1098*4882a593Smuzhiyun return -ENOMEM;
1099*4882a593Smuzhiyun
1100*4882a593Smuzhiyun skb_put(skb, len);
1101*4882a593Smuzhiyun cmd = (struct htt_cmd *)skb->data;
1102*4882a593Smuzhiyun cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_AGGR_CFG;
1103*4882a593Smuzhiyun
1104*4882a593Smuzhiyun aggr_conf = &cmd->aggr_conf_v2;
1105*4882a593Smuzhiyun aggr_conf->max_num_ampdu_subframes = max_subfrms_ampdu;
1106*4882a593Smuzhiyun aggr_conf->max_num_amsdu_subframes = max_subfrms_amsdu;
1107*4882a593Smuzhiyun
1108*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_HTT, "htt h2t aggr cfg msg amsdu %d ampdu %d",
1109*4882a593Smuzhiyun aggr_conf->max_num_amsdu_subframes,
1110*4882a593Smuzhiyun aggr_conf->max_num_ampdu_subframes);
1111*4882a593Smuzhiyun
1112*4882a593Smuzhiyun ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
1113*4882a593Smuzhiyun if (ret) {
1114*4882a593Smuzhiyun dev_kfree_skb_any(skb);
1115*4882a593Smuzhiyun return ret;
1116*4882a593Smuzhiyun }
1117*4882a593Smuzhiyun
1118*4882a593Smuzhiyun return 0;
1119*4882a593Smuzhiyun }
1120*4882a593Smuzhiyun
ath10k_htt_tx_fetch_resp(struct ath10k * ar,__le32 token,__le16 fetch_seq_num,struct htt_tx_fetch_record * records,size_t num_records)1121*4882a593Smuzhiyun int ath10k_htt_tx_fetch_resp(struct ath10k *ar,
1122*4882a593Smuzhiyun __le32 token,
1123*4882a593Smuzhiyun __le16 fetch_seq_num,
1124*4882a593Smuzhiyun struct htt_tx_fetch_record *records,
1125*4882a593Smuzhiyun size_t num_records)
1126*4882a593Smuzhiyun {
1127*4882a593Smuzhiyun struct sk_buff *skb;
1128*4882a593Smuzhiyun struct htt_cmd *cmd;
1129*4882a593Smuzhiyun const u16 resp_id = 0;
1130*4882a593Smuzhiyun int len = 0;
1131*4882a593Smuzhiyun int ret;
1132*4882a593Smuzhiyun
1133*4882a593Smuzhiyun /* Response IDs are echo-ed back only for host driver convienence
1134*4882a593Smuzhiyun * purposes. They aren't used for anything in the driver yet so use 0.
1135*4882a593Smuzhiyun */
1136*4882a593Smuzhiyun
1137*4882a593Smuzhiyun len += sizeof(cmd->hdr);
1138*4882a593Smuzhiyun len += sizeof(cmd->tx_fetch_resp);
1139*4882a593Smuzhiyun len += sizeof(cmd->tx_fetch_resp.records[0]) * num_records;
1140*4882a593Smuzhiyun
1141*4882a593Smuzhiyun skb = ath10k_htc_alloc_skb(ar, len);
1142*4882a593Smuzhiyun if (!skb)
1143*4882a593Smuzhiyun return -ENOMEM;
1144*4882a593Smuzhiyun
1145*4882a593Smuzhiyun skb_put(skb, len);
1146*4882a593Smuzhiyun cmd = (struct htt_cmd *)skb->data;
1147*4882a593Smuzhiyun cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_TX_FETCH_RESP;
1148*4882a593Smuzhiyun cmd->tx_fetch_resp.resp_id = cpu_to_le16(resp_id);
1149*4882a593Smuzhiyun cmd->tx_fetch_resp.fetch_seq_num = fetch_seq_num;
1150*4882a593Smuzhiyun cmd->tx_fetch_resp.num_records = cpu_to_le16(num_records);
1151*4882a593Smuzhiyun cmd->tx_fetch_resp.token = token;
1152*4882a593Smuzhiyun
1153*4882a593Smuzhiyun memcpy(cmd->tx_fetch_resp.records, records,
1154*4882a593Smuzhiyun sizeof(records[0]) * num_records);
1155*4882a593Smuzhiyun
1156*4882a593Smuzhiyun ret = ath10k_htc_send(&ar->htc, ar->htt.eid, skb);
1157*4882a593Smuzhiyun if (ret) {
1158*4882a593Smuzhiyun ath10k_warn(ar, "failed to submit htc command: %d\n", ret);
1159*4882a593Smuzhiyun goto err_free_skb;
1160*4882a593Smuzhiyun }
1161*4882a593Smuzhiyun
1162*4882a593Smuzhiyun return 0;
1163*4882a593Smuzhiyun
1164*4882a593Smuzhiyun err_free_skb:
1165*4882a593Smuzhiyun dev_kfree_skb_any(skb);
1166*4882a593Smuzhiyun
1167*4882a593Smuzhiyun return ret;
1168*4882a593Smuzhiyun }
1169*4882a593Smuzhiyun
ath10k_htt_tx_get_vdev_id(struct ath10k * ar,struct sk_buff * skb)1170*4882a593Smuzhiyun static u8 ath10k_htt_tx_get_vdev_id(struct ath10k *ar, struct sk_buff *skb)
1171*4882a593Smuzhiyun {
1172*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1173*4882a593Smuzhiyun struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
1174*4882a593Smuzhiyun struct ath10k_vif *arvif;
1175*4882a593Smuzhiyun
1176*4882a593Smuzhiyun if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
1177*4882a593Smuzhiyun return ar->scan.vdev_id;
1178*4882a593Smuzhiyun } else if (cb->vif) {
1179*4882a593Smuzhiyun arvif = (void *)cb->vif->drv_priv;
1180*4882a593Smuzhiyun return arvif->vdev_id;
1181*4882a593Smuzhiyun } else if (ar->monitor_started) {
1182*4882a593Smuzhiyun return ar->monitor_vdev_id;
1183*4882a593Smuzhiyun } else {
1184*4882a593Smuzhiyun return 0;
1185*4882a593Smuzhiyun }
1186*4882a593Smuzhiyun }
1187*4882a593Smuzhiyun
ath10k_htt_tx_get_tid(struct sk_buff * skb,bool is_eth)1188*4882a593Smuzhiyun static u8 ath10k_htt_tx_get_tid(struct sk_buff *skb, bool is_eth)
1189*4882a593Smuzhiyun {
1190*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (void *)skb->data;
1191*4882a593Smuzhiyun struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
1192*4882a593Smuzhiyun
1193*4882a593Smuzhiyun if (!is_eth && ieee80211_is_mgmt(hdr->frame_control))
1194*4882a593Smuzhiyun return HTT_DATA_TX_EXT_TID_MGMT;
1195*4882a593Smuzhiyun else if (cb->flags & ATH10K_SKB_F_QOS)
1196*4882a593Smuzhiyun return skb->priority & IEEE80211_QOS_CTL_TID_MASK;
1197*4882a593Smuzhiyun else
1198*4882a593Smuzhiyun return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1199*4882a593Smuzhiyun }
1200*4882a593Smuzhiyun
ath10k_htt_mgmt_tx(struct ath10k_htt * htt,struct sk_buff * msdu)1201*4882a593Smuzhiyun int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
1202*4882a593Smuzhiyun {
1203*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
1204*4882a593Smuzhiyun struct device *dev = ar->dev;
1205*4882a593Smuzhiyun struct sk_buff *txdesc = NULL;
1206*4882a593Smuzhiyun struct htt_cmd *cmd;
1207*4882a593Smuzhiyun struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
1208*4882a593Smuzhiyun u8 vdev_id = ath10k_htt_tx_get_vdev_id(ar, msdu);
1209*4882a593Smuzhiyun int len = 0;
1210*4882a593Smuzhiyun int msdu_id = -1;
1211*4882a593Smuzhiyun int res;
1212*4882a593Smuzhiyun const u8 *peer_addr;
1213*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
1214*4882a593Smuzhiyun
1215*4882a593Smuzhiyun len += sizeof(cmd->hdr);
1216*4882a593Smuzhiyun len += sizeof(cmd->mgmt_tx);
1217*4882a593Smuzhiyun
1218*4882a593Smuzhiyun res = ath10k_htt_tx_alloc_msdu_id(htt, msdu);
1219*4882a593Smuzhiyun if (res < 0)
1220*4882a593Smuzhiyun goto err;
1221*4882a593Smuzhiyun
1222*4882a593Smuzhiyun msdu_id = res;
1223*4882a593Smuzhiyun
1224*4882a593Smuzhiyun if ((ieee80211_is_action(hdr->frame_control) ||
1225*4882a593Smuzhiyun ieee80211_is_deauth(hdr->frame_control) ||
1226*4882a593Smuzhiyun ieee80211_is_disassoc(hdr->frame_control)) &&
1227*4882a593Smuzhiyun ieee80211_has_protected(hdr->frame_control)) {
1228*4882a593Smuzhiyun peer_addr = hdr->addr1;
1229*4882a593Smuzhiyun if (is_multicast_ether_addr(peer_addr)) {
1230*4882a593Smuzhiyun skb_put(msdu, sizeof(struct ieee80211_mmie_16));
1231*4882a593Smuzhiyun } else {
1232*4882a593Smuzhiyun if (skb_cb->ucast_cipher == WLAN_CIPHER_SUITE_GCMP ||
1233*4882a593Smuzhiyun skb_cb->ucast_cipher == WLAN_CIPHER_SUITE_GCMP_256)
1234*4882a593Smuzhiyun skb_put(msdu, IEEE80211_GCMP_MIC_LEN);
1235*4882a593Smuzhiyun else
1236*4882a593Smuzhiyun skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
1237*4882a593Smuzhiyun }
1238*4882a593Smuzhiyun }
1239*4882a593Smuzhiyun
1240*4882a593Smuzhiyun txdesc = ath10k_htc_alloc_skb(ar, len);
1241*4882a593Smuzhiyun if (!txdesc) {
1242*4882a593Smuzhiyun res = -ENOMEM;
1243*4882a593Smuzhiyun goto err_free_msdu_id;
1244*4882a593Smuzhiyun }
1245*4882a593Smuzhiyun
1246*4882a593Smuzhiyun skb_cb->paddr = dma_map_single(dev, msdu->data, msdu->len,
1247*4882a593Smuzhiyun DMA_TO_DEVICE);
1248*4882a593Smuzhiyun res = dma_mapping_error(dev, skb_cb->paddr);
1249*4882a593Smuzhiyun if (res) {
1250*4882a593Smuzhiyun res = -EIO;
1251*4882a593Smuzhiyun goto err_free_txdesc;
1252*4882a593Smuzhiyun }
1253*4882a593Smuzhiyun
1254*4882a593Smuzhiyun skb_put(txdesc, len);
1255*4882a593Smuzhiyun cmd = (struct htt_cmd *)txdesc->data;
1256*4882a593Smuzhiyun memset(cmd, 0, len);
1257*4882a593Smuzhiyun
1258*4882a593Smuzhiyun cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_MGMT_TX;
1259*4882a593Smuzhiyun cmd->mgmt_tx.msdu_paddr = __cpu_to_le32(ATH10K_SKB_CB(msdu)->paddr);
1260*4882a593Smuzhiyun cmd->mgmt_tx.len = __cpu_to_le32(msdu->len);
1261*4882a593Smuzhiyun cmd->mgmt_tx.desc_id = __cpu_to_le32(msdu_id);
1262*4882a593Smuzhiyun cmd->mgmt_tx.vdev_id = __cpu_to_le32(vdev_id);
1263*4882a593Smuzhiyun memcpy(cmd->mgmt_tx.hdr, msdu->data,
1264*4882a593Smuzhiyun min_t(int, msdu->len, HTT_MGMT_FRM_HDR_DOWNLOAD_LEN));
1265*4882a593Smuzhiyun
1266*4882a593Smuzhiyun res = ath10k_htc_send(&htt->ar->htc, htt->eid, txdesc);
1267*4882a593Smuzhiyun if (res)
1268*4882a593Smuzhiyun goto err_unmap_msdu;
1269*4882a593Smuzhiyun
1270*4882a593Smuzhiyun return 0;
1271*4882a593Smuzhiyun
1272*4882a593Smuzhiyun err_unmap_msdu:
1273*4882a593Smuzhiyun if (ar->bus_param.dev_type != ATH10K_DEV_TYPE_HL)
1274*4882a593Smuzhiyun dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
1275*4882a593Smuzhiyun err_free_txdesc:
1276*4882a593Smuzhiyun dev_kfree_skb_any(txdesc);
1277*4882a593Smuzhiyun err_free_msdu_id:
1278*4882a593Smuzhiyun spin_lock_bh(&htt->tx_lock);
1279*4882a593Smuzhiyun ath10k_htt_tx_free_msdu_id(htt, msdu_id);
1280*4882a593Smuzhiyun spin_unlock_bh(&htt->tx_lock);
1281*4882a593Smuzhiyun err:
1282*4882a593Smuzhiyun return res;
1283*4882a593Smuzhiyun }
1284*4882a593Smuzhiyun
1285*4882a593Smuzhiyun #define HTT_TX_HL_NEEDED_HEADROOM \
1286*4882a593Smuzhiyun (unsigned int)(sizeof(struct htt_cmd_hdr) + \
1287*4882a593Smuzhiyun sizeof(struct htt_data_tx_desc) + \
1288*4882a593Smuzhiyun sizeof(struct ath10k_htc_hdr))
1289*4882a593Smuzhiyun
ath10k_htt_tx_hl(struct ath10k_htt * htt,enum ath10k_hw_txrx_mode txmode,struct sk_buff * msdu)1290*4882a593Smuzhiyun static int ath10k_htt_tx_hl(struct ath10k_htt *htt, enum ath10k_hw_txrx_mode txmode,
1291*4882a593Smuzhiyun struct sk_buff *msdu)
1292*4882a593Smuzhiyun {
1293*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
1294*4882a593Smuzhiyun int res, data_len;
1295*4882a593Smuzhiyun struct htt_cmd_hdr *cmd_hdr;
1296*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
1297*4882a593Smuzhiyun struct htt_data_tx_desc *tx_desc;
1298*4882a593Smuzhiyun struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
1299*4882a593Smuzhiyun struct sk_buff *tmp_skb;
1300*4882a593Smuzhiyun bool is_eth = (txmode == ATH10K_HW_TXRX_ETHERNET);
1301*4882a593Smuzhiyun u8 vdev_id = ath10k_htt_tx_get_vdev_id(ar, msdu);
1302*4882a593Smuzhiyun u8 tid = ath10k_htt_tx_get_tid(msdu, is_eth);
1303*4882a593Smuzhiyun u8 flags0 = 0;
1304*4882a593Smuzhiyun u16 flags1 = 0;
1305*4882a593Smuzhiyun u16 msdu_id = 0;
1306*4882a593Smuzhiyun
1307*4882a593Smuzhiyun if ((ieee80211_is_action(hdr->frame_control) ||
1308*4882a593Smuzhiyun ieee80211_is_deauth(hdr->frame_control) ||
1309*4882a593Smuzhiyun ieee80211_is_disassoc(hdr->frame_control)) &&
1310*4882a593Smuzhiyun ieee80211_has_protected(hdr->frame_control)) {
1311*4882a593Smuzhiyun skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
1312*4882a593Smuzhiyun }
1313*4882a593Smuzhiyun
1314*4882a593Smuzhiyun data_len = msdu->len;
1315*4882a593Smuzhiyun
1316*4882a593Smuzhiyun switch (txmode) {
1317*4882a593Smuzhiyun case ATH10K_HW_TXRX_RAW:
1318*4882a593Smuzhiyun case ATH10K_HW_TXRX_NATIVE_WIFI:
1319*4882a593Smuzhiyun flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
1320*4882a593Smuzhiyun fallthrough;
1321*4882a593Smuzhiyun case ATH10K_HW_TXRX_ETHERNET:
1322*4882a593Smuzhiyun flags0 |= SM(txmode, HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
1323*4882a593Smuzhiyun break;
1324*4882a593Smuzhiyun case ATH10K_HW_TXRX_MGMT:
1325*4882a593Smuzhiyun flags0 |= SM(ATH10K_HW_TXRX_MGMT,
1326*4882a593Smuzhiyun HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
1327*4882a593Smuzhiyun flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
1328*4882a593Smuzhiyun
1329*4882a593Smuzhiyun if (htt->disable_tx_comp)
1330*4882a593Smuzhiyun flags1 |= HTT_DATA_TX_DESC_FLAGS1_TX_COMPLETE;
1331*4882a593Smuzhiyun break;
1332*4882a593Smuzhiyun }
1333*4882a593Smuzhiyun
1334*4882a593Smuzhiyun if (skb_cb->flags & ATH10K_SKB_F_NO_HWCRYPT)
1335*4882a593Smuzhiyun flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT;
1336*4882a593Smuzhiyun
1337*4882a593Smuzhiyun flags1 |= SM((u16)vdev_id, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID);
1338*4882a593Smuzhiyun flags1 |= SM((u16)tid, HTT_DATA_TX_DESC_FLAGS1_EXT_TID);
1339*4882a593Smuzhiyun if (msdu->ip_summed == CHECKSUM_PARTIAL &&
1340*4882a593Smuzhiyun !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
1341*4882a593Smuzhiyun flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD;
1342*4882a593Smuzhiyun flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD;
1343*4882a593Smuzhiyun }
1344*4882a593Smuzhiyun
1345*4882a593Smuzhiyun /* Prepend the HTT header and TX desc struct to the data message
1346*4882a593Smuzhiyun * and realloc the skb if it does not have enough headroom.
1347*4882a593Smuzhiyun */
1348*4882a593Smuzhiyun if (skb_headroom(msdu) < HTT_TX_HL_NEEDED_HEADROOM) {
1349*4882a593Smuzhiyun tmp_skb = msdu;
1350*4882a593Smuzhiyun
1351*4882a593Smuzhiyun ath10k_dbg(htt->ar, ATH10K_DBG_HTT,
1352*4882a593Smuzhiyun "Not enough headroom in skb. Current headroom: %u, needed: %u. Reallocating...\n",
1353*4882a593Smuzhiyun skb_headroom(msdu), HTT_TX_HL_NEEDED_HEADROOM);
1354*4882a593Smuzhiyun msdu = skb_realloc_headroom(msdu, HTT_TX_HL_NEEDED_HEADROOM);
1355*4882a593Smuzhiyun kfree_skb(tmp_skb);
1356*4882a593Smuzhiyun if (!msdu) {
1357*4882a593Smuzhiyun ath10k_warn(htt->ar, "htt hl tx: Unable to realloc skb!\n");
1358*4882a593Smuzhiyun res = -ENOMEM;
1359*4882a593Smuzhiyun goto out;
1360*4882a593Smuzhiyun }
1361*4882a593Smuzhiyun }
1362*4882a593Smuzhiyun
1363*4882a593Smuzhiyun if (ar->bus_param.hl_msdu_ids) {
1364*4882a593Smuzhiyun flags1 |= HTT_DATA_TX_DESC_FLAGS1_POSTPONED;
1365*4882a593Smuzhiyun res = ath10k_htt_tx_alloc_msdu_id(htt, msdu);
1366*4882a593Smuzhiyun if (res < 0) {
1367*4882a593Smuzhiyun ath10k_err(ar, "msdu_id allocation failed %d\n", res);
1368*4882a593Smuzhiyun goto out;
1369*4882a593Smuzhiyun }
1370*4882a593Smuzhiyun msdu_id = res;
1371*4882a593Smuzhiyun }
1372*4882a593Smuzhiyun
1373*4882a593Smuzhiyun /* As msdu is freed by mac80211 (in ieee80211_tx_status()) and by
1374*4882a593Smuzhiyun * ath10k (in ath10k_htt_htc_tx_complete()) we have to increase
1375*4882a593Smuzhiyun * reference by one to avoid a use-after-free case and a double
1376*4882a593Smuzhiyun * free.
1377*4882a593Smuzhiyun */
1378*4882a593Smuzhiyun skb_get(msdu);
1379*4882a593Smuzhiyun
1380*4882a593Smuzhiyun skb_push(msdu, sizeof(*cmd_hdr));
1381*4882a593Smuzhiyun skb_push(msdu, sizeof(*tx_desc));
1382*4882a593Smuzhiyun cmd_hdr = (struct htt_cmd_hdr *)msdu->data;
1383*4882a593Smuzhiyun tx_desc = (struct htt_data_tx_desc *)(msdu->data + sizeof(*cmd_hdr));
1384*4882a593Smuzhiyun
1385*4882a593Smuzhiyun cmd_hdr->msg_type = HTT_H2T_MSG_TYPE_TX_FRM;
1386*4882a593Smuzhiyun tx_desc->flags0 = flags0;
1387*4882a593Smuzhiyun tx_desc->flags1 = __cpu_to_le16(flags1);
1388*4882a593Smuzhiyun tx_desc->len = __cpu_to_le16(data_len);
1389*4882a593Smuzhiyun tx_desc->id = __cpu_to_le16(msdu_id);
1390*4882a593Smuzhiyun tx_desc->frags_paddr = 0; /* always zero */
1391*4882a593Smuzhiyun /* Initialize peer_id to INVALID_PEER because this is NOT
1392*4882a593Smuzhiyun * Reinjection path
1393*4882a593Smuzhiyun */
1394*4882a593Smuzhiyun tx_desc->peerid = __cpu_to_le32(HTT_INVALID_PEERID);
1395*4882a593Smuzhiyun
1396*4882a593Smuzhiyun res = ath10k_htc_send_hl(&htt->ar->htc, htt->eid, msdu);
1397*4882a593Smuzhiyun
1398*4882a593Smuzhiyun out:
1399*4882a593Smuzhiyun return res;
1400*4882a593Smuzhiyun }
1401*4882a593Smuzhiyun
ath10k_htt_tx_32(struct ath10k_htt * htt,enum ath10k_hw_txrx_mode txmode,struct sk_buff * msdu)1402*4882a593Smuzhiyun static int ath10k_htt_tx_32(struct ath10k_htt *htt,
1403*4882a593Smuzhiyun enum ath10k_hw_txrx_mode txmode,
1404*4882a593Smuzhiyun struct sk_buff *msdu)
1405*4882a593Smuzhiyun {
1406*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
1407*4882a593Smuzhiyun struct device *dev = ar->dev;
1408*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
1409*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(msdu);
1410*4882a593Smuzhiyun struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
1411*4882a593Smuzhiyun struct ath10k_hif_sg_item sg_items[2];
1412*4882a593Smuzhiyun struct ath10k_htt_txbuf_32 *txbuf;
1413*4882a593Smuzhiyun struct htt_data_tx_desc_frag *frags;
1414*4882a593Smuzhiyun bool is_eth = (txmode == ATH10K_HW_TXRX_ETHERNET);
1415*4882a593Smuzhiyun u8 vdev_id = ath10k_htt_tx_get_vdev_id(ar, msdu);
1416*4882a593Smuzhiyun u8 tid = ath10k_htt_tx_get_tid(msdu, is_eth);
1417*4882a593Smuzhiyun int prefetch_len;
1418*4882a593Smuzhiyun int res;
1419*4882a593Smuzhiyun u8 flags0 = 0;
1420*4882a593Smuzhiyun u16 msdu_id, flags1 = 0;
1421*4882a593Smuzhiyun u16 freq = 0;
1422*4882a593Smuzhiyun u32 frags_paddr = 0;
1423*4882a593Smuzhiyun u32 txbuf_paddr;
1424*4882a593Smuzhiyun struct htt_msdu_ext_desc *ext_desc = NULL;
1425*4882a593Smuzhiyun struct htt_msdu_ext_desc *ext_desc_t = NULL;
1426*4882a593Smuzhiyun
1427*4882a593Smuzhiyun res = ath10k_htt_tx_alloc_msdu_id(htt, msdu);
1428*4882a593Smuzhiyun if (res < 0)
1429*4882a593Smuzhiyun goto err;
1430*4882a593Smuzhiyun
1431*4882a593Smuzhiyun msdu_id = res;
1432*4882a593Smuzhiyun
1433*4882a593Smuzhiyun prefetch_len = min(htt->prefetch_len, msdu->len);
1434*4882a593Smuzhiyun prefetch_len = roundup(prefetch_len, 4);
1435*4882a593Smuzhiyun
1436*4882a593Smuzhiyun txbuf = htt->txbuf.vaddr_txbuff_32 + msdu_id;
1437*4882a593Smuzhiyun txbuf_paddr = htt->txbuf.paddr +
1438*4882a593Smuzhiyun (sizeof(struct ath10k_htt_txbuf_32) * msdu_id);
1439*4882a593Smuzhiyun
1440*4882a593Smuzhiyun if ((ieee80211_is_action(hdr->frame_control) ||
1441*4882a593Smuzhiyun ieee80211_is_deauth(hdr->frame_control) ||
1442*4882a593Smuzhiyun ieee80211_is_disassoc(hdr->frame_control)) &&
1443*4882a593Smuzhiyun ieee80211_has_protected(hdr->frame_control)) {
1444*4882a593Smuzhiyun skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
1445*4882a593Smuzhiyun } else if (!(skb_cb->flags & ATH10K_SKB_F_NO_HWCRYPT) &&
1446*4882a593Smuzhiyun txmode == ATH10K_HW_TXRX_RAW &&
1447*4882a593Smuzhiyun ieee80211_has_protected(hdr->frame_control)) {
1448*4882a593Smuzhiyun skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
1449*4882a593Smuzhiyun }
1450*4882a593Smuzhiyun
1451*4882a593Smuzhiyun skb_cb->paddr = dma_map_single(dev, msdu->data, msdu->len,
1452*4882a593Smuzhiyun DMA_TO_DEVICE);
1453*4882a593Smuzhiyun res = dma_mapping_error(dev, skb_cb->paddr);
1454*4882a593Smuzhiyun if (res) {
1455*4882a593Smuzhiyun res = -EIO;
1456*4882a593Smuzhiyun goto err_free_msdu_id;
1457*4882a593Smuzhiyun }
1458*4882a593Smuzhiyun
1459*4882a593Smuzhiyun if (unlikely(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN))
1460*4882a593Smuzhiyun freq = ar->scan.roc_freq;
1461*4882a593Smuzhiyun
1462*4882a593Smuzhiyun switch (txmode) {
1463*4882a593Smuzhiyun case ATH10K_HW_TXRX_RAW:
1464*4882a593Smuzhiyun case ATH10K_HW_TXRX_NATIVE_WIFI:
1465*4882a593Smuzhiyun flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
1466*4882a593Smuzhiyun fallthrough;
1467*4882a593Smuzhiyun case ATH10K_HW_TXRX_ETHERNET:
1468*4882a593Smuzhiyun if (ar->hw_params.continuous_frag_desc) {
1469*4882a593Smuzhiyun ext_desc_t = htt->frag_desc.vaddr_desc_32;
1470*4882a593Smuzhiyun memset(&ext_desc_t[msdu_id], 0,
1471*4882a593Smuzhiyun sizeof(struct htt_msdu_ext_desc));
1472*4882a593Smuzhiyun frags = (struct htt_data_tx_desc_frag *)
1473*4882a593Smuzhiyun &ext_desc_t[msdu_id].frags;
1474*4882a593Smuzhiyun ext_desc = &ext_desc_t[msdu_id];
1475*4882a593Smuzhiyun frags[0].tword_addr.paddr_lo =
1476*4882a593Smuzhiyun __cpu_to_le32(skb_cb->paddr);
1477*4882a593Smuzhiyun frags[0].tword_addr.paddr_hi = 0;
1478*4882a593Smuzhiyun frags[0].tword_addr.len_16 = __cpu_to_le16(msdu->len);
1479*4882a593Smuzhiyun
1480*4882a593Smuzhiyun frags_paddr = htt->frag_desc.paddr +
1481*4882a593Smuzhiyun (sizeof(struct htt_msdu_ext_desc) * msdu_id);
1482*4882a593Smuzhiyun } else {
1483*4882a593Smuzhiyun frags = txbuf->frags;
1484*4882a593Smuzhiyun frags[0].dword_addr.paddr =
1485*4882a593Smuzhiyun __cpu_to_le32(skb_cb->paddr);
1486*4882a593Smuzhiyun frags[0].dword_addr.len = __cpu_to_le32(msdu->len);
1487*4882a593Smuzhiyun frags[1].dword_addr.paddr = 0;
1488*4882a593Smuzhiyun frags[1].dword_addr.len = 0;
1489*4882a593Smuzhiyun
1490*4882a593Smuzhiyun frags_paddr = txbuf_paddr;
1491*4882a593Smuzhiyun }
1492*4882a593Smuzhiyun flags0 |= SM(txmode, HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
1493*4882a593Smuzhiyun break;
1494*4882a593Smuzhiyun case ATH10K_HW_TXRX_MGMT:
1495*4882a593Smuzhiyun flags0 |= SM(ATH10K_HW_TXRX_MGMT,
1496*4882a593Smuzhiyun HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
1497*4882a593Smuzhiyun flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
1498*4882a593Smuzhiyun
1499*4882a593Smuzhiyun frags_paddr = skb_cb->paddr;
1500*4882a593Smuzhiyun break;
1501*4882a593Smuzhiyun }
1502*4882a593Smuzhiyun
1503*4882a593Smuzhiyun /* Normally all commands go through HTC which manages tx credits for
1504*4882a593Smuzhiyun * each endpoint and notifies when tx is completed.
1505*4882a593Smuzhiyun *
1506*4882a593Smuzhiyun * HTT endpoint is creditless so there's no need to care about HTC
1507*4882a593Smuzhiyun * flags. In that case it is trivial to fill the HTC header here.
1508*4882a593Smuzhiyun *
1509*4882a593Smuzhiyun * MSDU transmission is considered completed upon HTT event. This
1510*4882a593Smuzhiyun * implies no relevant resources can be freed until after the event is
1511*4882a593Smuzhiyun * received. That's why HTC tx completion handler itself is ignored by
1512*4882a593Smuzhiyun * setting NULL to transfer_context for all sg items.
1513*4882a593Smuzhiyun *
1514*4882a593Smuzhiyun * There is simply no point in pushing HTT TX_FRM through HTC tx path
1515*4882a593Smuzhiyun * as it's a waste of resources. By bypassing HTC it is possible to
1516*4882a593Smuzhiyun * avoid extra memory allocations, compress data structures and thus
1517*4882a593Smuzhiyun * improve performance.
1518*4882a593Smuzhiyun */
1519*4882a593Smuzhiyun
1520*4882a593Smuzhiyun txbuf->htc_hdr.eid = htt->eid;
1521*4882a593Smuzhiyun txbuf->htc_hdr.len = __cpu_to_le16(sizeof(txbuf->cmd_hdr) +
1522*4882a593Smuzhiyun sizeof(txbuf->cmd_tx) +
1523*4882a593Smuzhiyun prefetch_len);
1524*4882a593Smuzhiyun txbuf->htc_hdr.flags = 0;
1525*4882a593Smuzhiyun
1526*4882a593Smuzhiyun if (skb_cb->flags & ATH10K_SKB_F_NO_HWCRYPT)
1527*4882a593Smuzhiyun flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT;
1528*4882a593Smuzhiyun
1529*4882a593Smuzhiyun flags1 |= SM((u16)vdev_id, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID);
1530*4882a593Smuzhiyun flags1 |= SM((u16)tid, HTT_DATA_TX_DESC_FLAGS1_EXT_TID);
1531*4882a593Smuzhiyun if (msdu->ip_summed == CHECKSUM_PARTIAL &&
1532*4882a593Smuzhiyun !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
1533*4882a593Smuzhiyun flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD;
1534*4882a593Smuzhiyun flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD;
1535*4882a593Smuzhiyun if (ar->hw_params.continuous_frag_desc)
1536*4882a593Smuzhiyun ext_desc->flags |= HTT_MSDU_CHECKSUM_ENABLE;
1537*4882a593Smuzhiyun }
1538*4882a593Smuzhiyun
1539*4882a593Smuzhiyun /* Prevent firmware from sending up tx inspection requests. There's
1540*4882a593Smuzhiyun * nothing ath10k can do with frames requested for inspection so force
1541*4882a593Smuzhiyun * it to simply rely a regular tx completion with discard status.
1542*4882a593Smuzhiyun */
1543*4882a593Smuzhiyun flags1 |= HTT_DATA_TX_DESC_FLAGS1_POSTPONED;
1544*4882a593Smuzhiyun
1545*4882a593Smuzhiyun txbuf->cmd_hdr.msg_type = HTT_H2T_MSG_TYPE_TX_FRM;
1546*4882a593Smuzhiyun txbuf->cmd_tx.flags0 = flags0;
1547*4882a593Smuzhiyun txbuf->cmd_tx.flags1 = __cpu_to_le16(flags1);
1548*4882a593Smuzhiyun txbuf->cmd_tx.len = __cpu_to_le16(msdu->len);
1549*4882a593Smuzhiyun txbuf->cmd_tx.id = __cpu_to_le16(msdu_id);
1550*4882a593Smuzhiyun txbuf->cmd_tx.frags_paddr = __cpu_to_le32(frags_paddr);
1551*4882a593Smuzhiyun if (ath10k_mac_tx_frm_has_freq(ar)) {
1552*4882a593Smuzhiyun txbuf->cmd_tx.offchan_tx.peerid =
1553*4882a593Smuzhiyun __cpu_to_le16(HTT_INVALID_PEERID);
1554*4882a593Smuzhiyun txbuf->cmd_tx.offchan_tx.freq =
1555*4882a593Smuzhiyun __cpu_to_le16(freq);
1556*4882a593Smuzhiyun } else {
1557*4882a593Smuzhiyun txbuf->cmd_tx.peerid =
1558*4882a593Smuzhiyun __cpu_to_le32(HTT_INVALID_PEERID);
1559*4882a593Smuzhiyun }
1560*4882a593Smuzhiyun
1561*4882a593Smuzhiyun trace_ath10k_htt_tx(ar, msdu_id, msdu->len, vdev_id, tid);
1562*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_HTT,
1563*4882a593Smuzhiyun "htt tx flags0 %hhu flags1 %hu len %d id %hu frags_paddr %pad, msdu_paddr %pad vdev %hhu tid %hhu freq %hu\n",
1564*4882a593Smuzhiyun flags0, flags1, msdu->len, msdu_id, &frags_paddr,
1565*4882a593Smuzhiyun &skb_cb->paddr, vdev_id, tid, freq);
1566*4882a593Smuzhiyun ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt tx msdu: ",
1567*4882a593Smuzhiyun msdu->data, msdu->len);
1568*4882a593Smuzhiyun trace_ath10k_tx_hdr(ar, msdu->data, msdu->len);
1569*4882a593Smuzhiyun trace_ath10k_tx_payload(ar, msdu->data, msdu->len);
1570*4882a593Smuzhiyun
1571*4882a593Smuzhiyun sg_items[0].transfer_id = 0;
1572*4882a593Smuzhiyun sg_items[0].transfer_context = NULL;
1573*4882a593Smuzhiyun sg_items[0].vaddr = &txbuf->htc_hdr;
1574*4882a593Smuzhiyun sg_items[0].paddr = txbuf_paddr +
1575*4882a593Smuzhiyun sizeof(txbuf->frags);
1576*4882a593Smuzhiyun sg_items[0].len = sizeof(txbuf->htc_hdr) +
1577*4882a593Smuzhiyun sizeof(txbuf->cmd_hdr) +
1578*4882a593Smuzhiyun sizeof(txbuf->cmd_tx);
1579*4882a593Smuzhiyun
1580*4882a593Smuzhiyun sg_items[1].transfer_id = 0;
1581*4882a593Smuzhiyun sg_items[1].transfer_context = NULL;
1582*4882a593Smuzhiyun sg_items[1].vaddr = msdu->data;
1583*4882a593Smuzhiyun sg_items[1].paddr = skb_cb->paddr;
1584*4882a593Smuzhiyun sg_items[1].len = prefetch_len;
1585*4882a593Smuzhiyun
1586*4882a593Smuzhiyun res = ath10k_hif_tx_sg(htt->ar,
1587*4882a593Smuzhiyun htt->ar->htc.endpoint[htt->eid].ul_pipe_id,
1588*4882a593Smuzhiyun sg_items, ARRAY_SIZE(sg_items));
1589*4882a593Smuzhiyun if (res)
1590*4882a593Smuzhiyun goto err_unmap_msdu;
1591*4882a593Smuzhiyun
1592*4882a593Smuzhiyun return 0;
1593*4882a593Smuzhiyun
1594*4882a593Smuzhiyun err_unmap_msdu:
1595*4882a593Smuzhiyun dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
1596*4882a593Smuzhiyun err_free_msdu_id:
1597*4882a593Smuzhiyun spin_lock_bh(&htt->tx_lock);
1598*4882a593Smuzhiyun ath10k_htt_tx_free_msdu_id(htt, msdu_id);
1599*4882a593Smuzhiyun spin_unlock_bh(&htt->tx_lock);
1600*4882a593Smuzhiyun err:
1601*4882a593Smuzhiyun return res;
1602*4882a593Smuzhiyun }
1603*4882a593Smuzhiyun
ath10k_htt_tx_64(struct ath10k_htt * htt,enum ath10k_hw_txrx_mode txmode,struct sk_buff * msdu)1604*4882a593Smuzhiyun static int ath10k_htt_tx_64(struct ath10k_htt *htt,
1605*4882a593Smuzhiyun enum ath10k_hw_txrx_mode txmode,
1606*4882a593Smuzhiyun struct sk_buff *msdu)
1607*4882a593Smuzhiyun {
1608*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
1609*4882a593Smuzhiyun struct device *dev = ar->dev;
1610*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
1611*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(msdu);
1612*4882a593Smuzhiyun struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
1613*4882a593Smuzhiyun struct ath10k_hif_sg_item sg_items[2];
1614*4882a593Smuzhiyun struct ath10k_htt_txbuf_64 *txbuf;
1615*4882a593Smuzhiyun struct htt_data_tx_desc_frag *frags;
1616*4882a593Smuzhiyun bool is_eth = (txmode == ATH10K_HW_TXRX_ETHERNET);
1617*4882a593Smuzhiyun u8 vdev_id = ath10k_htt_tx_get_vdev_id(ar, msdu);
1618*4882a593Smuzhiyun u8 tid = ath10k_htt_tx_get_tid(msdu, is_eth);
1619*4882a593Smuzhiyun int prefetch_len;
1620*4882a593Smuzhiyun int res;
1621*4882a593Smuzhiyun u8 flags0 = 0;
1622*4882a593Smuzhiyun u16 msdu_id, flags1 = 0;
1623*4882a593Smuzhiyun u16 freq = 0;
1624*4882a593Smuzhiyun dma_addr_t frags_paddr = 0;
1625*4882a593Smuzhiyun dma_addr_t txbuf_paddr;
1626*4882a593Smuzhiyun struct htt_msdu_ext_desc_64 *ext_desc = NULL;
1627*4882a593Smuzhiyun struct htt_msdu_ext_desc_64 *ext_desc_t = NULL;
1628*4882a593Smuzhiyun
1629*4882a593Smuzhiyun res = ath10k_htt_tx_alloc_msdu_id(htt, msdu);
1630*4882a593Smuzhiyun if (res < 0)
1631*4882a593Smuzhiyun goto err;
1632*4882a593Smuzhiyun
1633*4882a593Smuzhiyun msdu_id = res;
1634*4882a593Smuzhiyun
1635*4882a593Smuzhiyun prefetch_len = min(htt->prefetch_len, msdu->len);
1636*4882a593Smuzhiyun prefetch_len = roundup(prefetch_len, 4);
1637*4882a593Smuzhiyun
1638*4882a593Smuzhiyun txbuf = htt->txbuf.vaddr_txbuff_64 + msdu_id;
1639*4882a593Smuzhiyun txbuf_paddr = htt->txbuf.paddr +
1640*4882a593Smuzhiyun (sizeof(struct ath10k_htt_txbuf_64) * msdu_id);
1641*4882a593Smuzhiyun
1642*4882a593Smuzhiyun if ((ieee80211_is_action(hdr->frame_control) ||
1643*4882a593Smuzhiyun ieee80211_is_deauth(hdr->frame_control) ||
1644*4882a593Smuzhiyun ieee80211_is_disassoc(hdr->frame_control)) &&
1645*4882a593Smuzhiyun ieee80211_has_protected(hdr->frame_control)) {
1646*4882a593Smuzhiyun skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
1647*4882a593Smuzhiyun } else if (!(skb_cb->flags & ATH10K_SKB_F_NO_HWCRYPT) &&
1648*4882a593Smuzhiyun txmode == ATH10K_HW_TXRX_RAW &&
1649*4882a593Smuzhiyun ieee80211_has_protected(hdr->frame_control)) {
1650*4882a593Smuzhiyun skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
1651*4882a593Smuzhiyun }
1652*4882a593Smuzhiyun
1653*4882a593Smuzhiyun skb_cb->paddr = dma_map_single(dev, msdu->data, msdu->len,
1654*4882a593Smuzhiyun DMA_TO_DEVICE);
1655*4882a593Smuzhiyun res = dma_mapping_error(dev, skb_cb->paddr);
1656*4882a593Smuzhiyun if (res) {
1657*4882a593Smuzhiyun res = -EIO;
1658*4882a593Smuzhiyun goto err_free_msdu_id;
1659*4882a593Smuzhiyun }
1660*4882a593Smuzhiyun
1661*4882a593Smuzhiyun if (unlikely(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN))
1662*4882a593Smuzhiyun freq = ar->scan.roc_freq;
1663*4882a593Smuzhiyun
1664*4882a593Smuzhiyun switch (txmode) {
1665*4882a593Smuzhiyun case ATH10K_HW_TXRX_RAW:
1666*4882a593Smuzhiyun case ATH10K_HW_TXRX_NATIVE_WIFI:
1667*4882a593Smuzhiyun flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
1668*4882a593Smuzhiyun fallthrough;
1669*4882a593Smuzhiyun case ATH10K_HW_TXRX_ETHERNET:
1670*4882a593Smuzhiyun if (ar->hw_params.continuous_frag_desc) {
1671*4882a593Smuzhiyun ext_desc_t = htt->frag_desc.vaddr_desc_64;
1672*4882a593Smuzhiyun memset(&ext_desc_t[msdu_id], 0,
1673*4882a593Smuzhiyun sizeof(struct htt_msdu_ext_desc_64));
1674*4882a593Smuzhiyun frags = (struct htt_data_tx_desc_frag *)
1675*4882a593Smuzhiyun &ext_desc_t[msdu_id].frags;
1676*4882a593Smuzhiyun ext_desc = &ext_desc_t[msdu_id];
1677*4882a593Smuzhiyun frags[0].tword_addr.paddr_lo =
1678*4882a593Smuzhiyun __cpu_to_le32(skb_cb->paddr);
1679*4882a593Smuzhiyun frags[0].tword_addr.paddr_hi =
1680*4882a593Smuzhiyun __cpu_to_le16(upper_32_bits(skb_cb->paddr));
1681*4882a593Smuzhiyun frags[0].tword_addr.len_16 = __cpu_to_le16(msdu->len);
1682*4882a593Smuzhiyun
1683*4882a593Smuzhiyun frags_paddr = htt->frag_desc.paddr +
1684*4882a593Smuzhiyun (sizeof(struct htt_msdu_ext_desc_64) * msdu_id);
1685*4882a593Smuzhiyun } else {
1686*4882a593Smuzhiyun frags = txbuf->frags;
1687*4882a593Smuzhiyun frags[0].tword_addr.paddr_lo =
1688*4882a593Smuzhiyun __cpu_to_le32(skb_cb->paddr);
1689*4882a593Smuzhiyun frags[0].tword_addr.paddr_hi =
1690*4882a593Smuzhiyun __cpu_to_le16(upper_32_bits(skb_cb->paddr));
1691*4882a593Smuzhiyun frags[0].tword_addr.len_16 = __cpu_to_le16(msdu->len);
1692*4882a593Smuzhiyun frags[1].tword_addr.paddr_lo = 0;
1693*4882a593Smuzhiyun frags[1].tword_addr.paddr_hi = 0;
1694*4882a593Smuzhiyun frags[1].tword_addr.len_16 = 0;
1695*4882a593Smuzhiyun }
1696*4882a593Smuzhiyun flags0 |= SM(txmode, HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
1697*4882a593Smuzhiyun break;
1698*4882a593Smuzhiyun case ATH10K_HW_TXRX_MGMT:
1699*4882a593Smuzhiyun flags0 |= SM(ATH10K_HW_TXRX_MGMT,
1700*4882a593Smuzhiyun HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
1701*4882a593Smuzhiyun flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
1702*4882a593Smuzhiyun
1703*4882a593Smuzhiyun frags_paddr = skb_cb->paddr;
1704*4882a593Smuzhiyun break;
1705*4882a593Smuzhiyun }
1706*4882a593Smuzhiyun
1707*4882a593Smuzhiyun /* Normally all commands go through HTC which manages tx credits for
1708*4882a593Smuzhiyun * each endpoint and notifies when tx is completed.
1709*4882a593Smuzhiyun *
1710*4882a593Smuzhiyun * HTT endpoint is creditless so there's no need to care about HTC
1711*4882a593Smuzhiyun * flags. In that case it is trivial to fill the HTC header here.
1712*4882a593Smuzhiyun *
1713*4882a593Smuzhiyun * MSDU transmission is considered completed upon HTT event. This
1714*4882a593Smuzhiyun * implies no relevant resources can be freed until after the event is
1715*4882a593Smuzhiyun * received. That's why HTC tx completion handler itself is ignored by
1716*4882a593Smuzhiyun * setting NULL to transfer_context for all sg items.
1717*4882a593Smuzhiyun *
1718*4882a593Smuzhiyun * There is simply no point in pushing HTT TX_FRM through HTC tx path
1719*4882a593Smuzhiyun * as it's a waste of resources. By bypassing HTC it is possible to
1720*4882a593Smuzhiyun * avoid extra memory allocations, compress data structures and thus
1721*4882a593Smuzhiyun * improve performance.
1722*4882a593Smuzhiyun */
1723*4882a593Smuzhiyun
1724*4882a593Smuzhiyun txbuf->htc_hdr.eid = htt->eid;
1725*4882a593Smuzhiyun txbuf->htc_hdr.len = __cpu_to_le16(sizeof(txbuf->cmd_hdr) +
1726*4882a593Smuzhiyun sizeof(txbuf->cmd_tx) +
1727*4882a593Smuzhiyun prefetch_len);
1728*4882a593Smuzhiyun txbuf->htc_hdr.flags = 0;
1729*4882a593Smuzhiyun
1730*4882a593Smuzhiyun if (skb_cb->flags & ATH10K_SKB_F_NO_HWCRYPT)
1731*4882a593Smuzhiyun flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT;
1732*4882a593Smuzhiyun
1733*4882a593Smuzhiyun flags1 |= SM((u16)vdev_id, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID);
1734*4882a593Smuzhiyun flags1 |= SM((u16)tid, HTT_DATA_TX_DESC_FLAGS1_EXT_TID);
1735*4882a593Smuzhiyun if (msdu->ip_summed == CHECKSUM_PARTIAL &&
1736*4882a593Smuzhiyun !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
1737*4882a593Smuzhiyun flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD;
1738*4882a593Smuzhiyun flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD;
1739*4882a593Smuzhiyun if (ar->hw_params.continuous_frag_desc) {
1740*4882a593Smuzhiyun memset(ext_desc->tso_flag, 0, sizeof(ext_desc->tso_flag));
1741*4882a593Smuzhiyun ext_desc->tso_flag[3] |=
1742*4882a593Smuzhiyun __cpu_to_le32(HTT_MSDU_CHECKSUM_ENABLE_64);
1743*4882a593Smuzhiyun }
1744*4882a593Smuzhiyun }
1745*4882a593Smuzhiyun
1746*4882a593Smuzhiyun /* Prevent firmware from sending up tx inspection requests. There's
1747*4882a593Smuzhiyun * nothing ath10k can do with frames requested for inspection so force
1748*4882a593Smuzhiyun * it to simply rely a regular tx completion with discard status.
1749*4882a593Smuzhiyun */
1750*4882a593Smuzhiyun flags1 |= HTT_DATA_TX_DESC_FLAGS1_POSTPONED;
1751*4882a593Smuzhiyun
1752*4882a593Smuzhiyun txbuf->cmd_hdr.msg_type = HTT_H2T_MSG_TYPE_TX_FRM;
1753*4882a593Smuzhiyun txbuf->cmd_tx.flags0 = flags0;
1754*4882a593Smuzhiyun txbuf->cmd_tx.flags1 = __cpu_to_le16(flags1);
1755*4882a593Smuzhiyun txbuf->cmd_tx.len = __cpu_to_le16(msdu->len);
1756*4882a593Smuzhiyun txbuf->cmd_tx.id = __cpu_to_le16(msdu_id);
1757*4882a593Smuzhiyun
1758*4882a593Smuzhiyun /* fill fragment descriptor */
1759*4882a593Smuzhiyun txbuf->cmd_tx.frags_paddr = __cpu_to_le64(frags_paddr);
1760*4882a593Smuzhiyun if (ath10k_mac_tx_frm_has_freq(ar)) {
1761*4882a593Smuzhiyun txbuf->cmd_tx.offchan_tx.peerid =
1762*4882a593Smuzhiyun __cpu_to_le16(HTT_INVALID_PEERID);
1763*4882a593Smuzhiyun txbuf->cmd_tx.offchan_tx.freq =
1764*4882a593Smuzhiyun __cpu_to_le16(freq);
1765*4882a593Smuzhiyun } else {
1766*4882a593Smuzhiyun txbuf->cmd_tx.peerid =
1767*4882a593Smuzhiyun __cpu_to_le32(HTT_INVALID_PEERID);
1768*4882a593Smuzhiyun }
1769*4882a593Smuzhiyun
1770*4882a593Smuzhiyun trace_ath10k_htt_tx(ar, msdu_id, msdu->len, vdev_id, tid);
1771*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_HTT,
1772*4882a593Smuzhiyun "htt tx flags0 %hhu flags1 %hu len %d id %hu frags_paddr %pad, msdu_paddr %pad vdev %hhu tid %hhu freq %hu\n",
1773*4882a593Smuzhiyun flags0, flags1, msdu->len, msdu_id, &frags_paddr,
1774*4882a593Smuzhiyun &skb_cb->paddr, vdev_id, tid, freq);
1775*4882a593Smuzhiyun ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt tx msdu: ",
1776*4882a593Smuzhiyun msdu->data, msdu->len);
1777*4882a593Smuzhiyun trace_ath10k_tx_hdr(ar, msdu->data, msdu->len);
1778*4882a593Smuzhiyun trace_ath10k_tx_payload(ar, msdu->data, msdu->len);
1779*4882a593Smuzhiyun
1780*4882a593Smuzhiyun sg_items[0].transfer_id = 0;
1781*4882a593Smuzhiyun sg_items[0].transfer_context = NULL;
1782*4882a593Smuzhiyun sg_items[0].vaddr = &txbuf->htc_hdr;
1783*4882a593Smuzhiyun sg_items[0].paddr = txbuf_paddr +
1784*4882a593Smuzhiyun sizeof(txbuf->frags);
1785*4882a593Smuzhiyun sg_items[0].len = sizeof(txbuf->htc_hdr) +
1786*4882a593Smuzhiyun sizeof(txbuf->cmd_hdr) +
1787*4882a593Smuzhiyun sizeof(txbuf->cmd_tx);
1788*4882a593Smuzhiyun
1789*4882a593Smuzhiyun sg_items[1].transfer_id = 0;
1790*4882a593Smuzhiyun sg_items[1].transfer_context = NULL;
1791*4882a593Smuzhiyun sg_items[1].vaddr = msdu->data;
1792*4882a593Smuzhiyun sg_items[1].paddr = skb_cb->paddr;
1793*4882a593Smuzhiyun sg_items[1].len = prefetch_len;
1794*4882a593Smuzhiyun
1795*4882a593Smuzhiyun res = ath10k_hif_tx_sg(htt->ar,
1796*4882a593Smuzhiyun htt->ar->htc.endpoint[htt->eid].ul_pipe_id,
1797*4882a593Smuzhiyun sg_items, ARRAY_SIZE(sg_items));
1798*4882a593Smuzhiyun if (res)
1799*4882a593Smuzhiyun goto err_unmap_msdu;
1800*4882a593Smuzhiyun
1801*4882a593Smuzhiyun return 0;
1802*4882a593Smuzhiyun
1803*4882a593Smuzhiyun err_unmap_msdu:
1804*4882a593Smuzhiyun dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
1805*4882a593Smuzhiyun err_free_msdu_id:
1806*4882a593Smuzhiyun spin_lock_bh(&htt->tx_lock);
1807*4882a593Smuzhiyun ath10k_htt_tx_free_msdu_id(htt, msdu_id);
1808*4882a593Smuzhiyun spin_unlock_bh(&htt->tx_lock);
1809*4882a593Smuzhiyun err:
1810*4882a593Smuzhiyun return res;
1811*4882a593Smuzhiyun }
1812*4882a593Smuzhiyun
1813*4882a593Smuzhiyun static const struct ath10k_htt_tx_ops htt_tx_ops_32 = {
1814*4882a593Smuzhiyun .htt_send_rx_ring_cfg = ath10k_htt_send_rx_ring_cfg_32,
1815*4882a593Smuzhiyun .htt_send_frag_desc_bank_cfg = ath10k_htt_send_frag_desc_bank_cfg_32,
1816*4882a593Smuzhiyun .htt_alloc_frag_desc = ath10k_htt_tx_alloc_cont_frag_desc_32,
1817*4882a593Smuzhiyun .htt_free_frag_desc = ath10k_htt_tx_free_cont_frag_desc_32,
1818*4882a593Smuzhiyun .htt_tx = ath10k_htt_tx_32,
1819*4882a593Smuzhiyun .htt_alloc_txbuff = ath10k_htt_tx_alloc_cont_txbuf_32,
1820*4882a593Smuzhiyun .htt_free_txbuff = ath10k_htt_tx_free_cont_txbuf_32,
1821*4882a593Smuzhiyun .htt_h2t_aggr_cfg_msg = ath10k_htt_h2t_aggr_cfg_msg_32,
1822*4882a593Smuzhiyun };
1823*4882a593Smuzhiyun
1824*4882a593Smuzhiyun static const struct ath10k_htt_tx_ops htt_tx_ops_64 = {
1825*4882a593Smuzhiyun .htt_send_rx_ring_cfg = ath10k_htt_send_rx_ring_cfg_64,
1826*4882a593Smuzhiyun .htt_send_frag_desc_bank_cfg = ath10k_htt_send_frag_desc_bank_cfg_64,
1827*4882a593Smuzhiyun .htt_alloc_frag_desc = ath10k_htt_tx_alloc_cont_frag_desc_64,
1828*4882a593Smuzhiyun .htt_free_frag_desc = ath10k_htt_tx_free_cont_frag_desc_64,
1829*4882a593Smuzhiyun .htt_tx = ath10k_htt_tx_64,
1830*4882a593Smuzhiyun .htt_alloc_txbuff = ath10k_htt_tx_alloc_cont_txbuf_64,
1831*4882a593Smuzhiyun .htt_free_txbuff = ath10k_htt_tx_free_cont_txbuf_64,
1832*4882a593Smuzhiyun .htt_h2t_aggr_cfg_msg = ath10k_htt_h2t_aggr_cfg_msg_v2,
1833*4882a593Smuzhiyun };
1834*4882a593Smuzhiyun
1835*4882a593Smuzhiyun static const struct ath10k_htt_tx_ops htt_tx_ops_hl = {
1836*4882a593Smuzhiyun .htt_send_rx_ring_cfg = ath10k_htt_send_rx_ring_cfg_hl,
1837*4882a593Smuzhiyun .htt_send_frag_desc_bank_cfg = ath10k_htt_send_frag_desc_bank_cfg_32,
1838*4882a593Smuzhiyun .htt_tx = ath10k_htt_tx_hl,
1839*4882a593Smuzhiyun .htt_h2t_aggr_cfg_msg = ath10k_htt_h2t_aggr_cfg_msg_32,
1840*4882a593Smuzhiyun .htt_flush_tx = ath10k_htt_flush_tx_queue,
1841*4882a593Smuzhiyun };
1842*4882a593Smuzhiyun
ath10k_htt_set_tx_ops(struct ath10k_htt * htt)1843*4882a593Smuzhiyun void ath10k_htt_set_tx_ops(struct ath10k_htt *htt)
1844*4882a593Smuzhiyun {
1845*4882a593Smuzhiyun struct ath10k *ar = htt->ar;
1846*4882a593Smuzhiyun
1847*4882a593Smuzhiyun if (ar->bus_param.dev_type == ATH10K_DEV_TYPE_HL)
1848*4882a593Smuzhiyun htt->tx_ops = &htt_tx_ops_hl;
1849*4882a593Smuzhiyun else if (ar->hw_params.target_64bit)
1850*4882a593Smuzhiyun htt->tx_ops = &htt_tx_ops_64;
1851*4882a593Smuzhiyun else
1852*4882a593Smuzhiyun htt->tx_ops = &htt_tx_ops_32;
1853*4882a593Smuzhiyun }
1854