blob: 95acb727c068f242f1324a39f04c540291071126 [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <linux/etherdevice.h>
19#include "htt.h"
20#include "mac.h"
21#include "hif.h"
22#include "txrx.h"
23#include "debug.h"
24
Vivek Natarajan7b7da0a2015-08-31 16:34:55 +053025void __ath10k_htt_tx_dec_pending(struct ath10k_htt *htt, bool limit_mgmt_desc)
Kalle Valo5e3dd152013-06-12 20:52:10 +030026{
Vivek Natarajan7b7da0a2015-08-31 16:34:55 +053027 if (limit_mgmt_desc)
28 htt->num_pending_mgmt_tx--;
29
Kalle Valo5e3dd152013-06-12 20:52:10 +030030 htt->num_pending_tx--;
31 if (htt->num_pending_tx == htt->max_num_pending_tx - 1)
Michal Kazior96d828d2015-03-31 10:26:23 +000032 ath10k_mac_tx_unlock(htt->ar, ATH10K_TX_PAUSE_Q_FULL);
Kalle Valo5e3dd152013-06-12 20:52:10 +030033}
34
Vivek Natarajan7b7da0a2015-08-31 16:34:55 +053035static void ath10k_htt_tx_dec_pending(struct ath10k_htt *htt,
36 bool limit_mgmt_desc)
Kalle Valo5e3dd152013-06-12 20:52:10 +030037{
38 spin_lock_bh(&htt->tx_lock);
Vivek Natarajan7b7da0a2015-08-31 16:34:55 +053039 __ath10k_htt_tx_dec_pending(htt, limit_mgmt_desc);
Kalle Valo5e3dd152013-06-12 20:52:10 +030040 spin_unlock_bh(&htt->tx_lock);
41}
42
Vivek Natarajan7b7da0a2015-08-31 16:34:55 +053043static int ath10k_htt_tx_inc_pending(struct ath10k_htt *htt,
44 bool limit_mgmt_desc, bool is_probe_resp)
Kalle Valo5e3dd152013-06-12 20:52:10 +030045{
Vivek Natarajan7b7da0a2015-08-31 16:34:55 +053046 struct ath10k *ar = htt->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +030047 int ret = 0;
48
49 spin_lock_bh(&htt->tx_lock);
50
51 if (htt->num_pending_tx >= htt->max_num_pending_tx) {
52 ret = -EBUSY;
53 goto exit;
54 }
55
Vivek Natarajan7b7da0a2015-08-31 16:34:55 +053056 if (limit_mgmt_desc) {
57 if (is_probe_resp && (htt->num_pending_mgmt_tx >
58 ar->hw_params.max_probe_resp_desc_thres)) {
59 ret = -EBUSY;
60 goto exit;
61 }
62 htt->num_pending_mgmt_tx++;
63 }
64
Kalle Valo5e3dd152013-06-12 20:52:10 +030065 htt->num_pending_tx++;
66 if (htt->num_pending_tx == htt->max_num_pending_tx)
Michal Kazior96d828d2015-03-31 10:26:23 +000067 ath10k_mac_tx_lock(htt->ar, ATH10K_TX_PAUSE_Q_FULL);
Kalle Valo5e3dd152013-06-12 20:52:10 +030068
69exit:
70 spin_unlock_bh(&htt->tx_lock);
71 return ret;
72}
73
Michal Kazior89d6d832015-01-24 12:14:51 +020074int ath10k_htt_tx_alloc_msdu_id(struct ath10k_htt *htt, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +030075{
Michal Kazior7aa7a722014-08-25 12:09:38 +020076 struct ath10k *ar = htt->ar;
Michal Kazior89d6d832015-01-24 12:14:51 +020077 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +030078
79 lockdep_assert_held(&htt->tx_lock);
80
Peter Ohfbc03a42015-07-15 19:01:19 -070081 ret = idr_alloc(&htt->pending_tx, skb, 0,
82 htt->max_num_pending_tx, GFP_ATOMIC);
Kalle Valo5e3dd152013-06-12 20:52:10 +030083
Michal Kazior89d6d832015-01-24 12:14:51 +020084 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx alloc msdu_id %d\n", ret);
85
86 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +030087}
88
89void ath10k_htt_tx_free_msdu_id(struct ath10k_htt *htt, u16 msdu_id)
90{
Michal Kazior7aa7a722014-08-25 12:09:38 +020091 struct ath10k *ar = htt->ar;
92
Kalle Valo5e3dd152013-06-12 20:52:10 +030093 lockdep_assert_held(&htt->tx_lock);
94
Michal Kazior7aa7a722014-08-25 12:09:38 +020095 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx free msdu_id %hu\n", msdu_id);
Michal Kazior89d6d832015-01-24 12:14:51 +020096
97 idr_remove(&htt->pending_tx, msdu_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +030098}
99
Michal Kazior575fc892016-01-21 14:13:26 +0100100static void ath10k_htt_tx_free_cont_frag_desc(struct ath10k_htt *htt)
101{
102 size_t size;
103
104 if (!htt->frag_desc.vaddr)
105 return;
106
107 size = htt->max_num_pending_tx * sizeof(struct htt_msdu_ext_desc);
108
109 dma_free_coherent(htt->ar->dev,
110 size,
111 htt->frag_desc.vaddr,
112 htt->frag_desc.paddr);
113}
114
115static int ath10k_htt_tx_alloc_cont_frag_desc(struct ath10k_htt *htt)
116{
117 struct ath10k *ar = htt->ar;
118 size_t size;
119
120 if (!ar->hw_params.continuous_frag_desc)
121 return 0;
122
123 size = htt->max_num_pending_tx * sizeof(struct htt_msdu_ext_desc);
124 htt->frag_desc.vaddr = dma_alloc_coherent(ar->dev, size,
125 &htt->frag_desc.paddr,
126 GFP_KERNEL);
127 if (!htt->frag_desc.vaddr) {
128 ath10k_err(ar, "failed to alloc fragment desc memory\n");
129 return -ENOMEM;
130 }
131
132 return 0;
133}
134
Michal Kazior9b158732016-01-21 14:13:27 +0100135static void ath10k_htt_tx_free_txq(struct ath10k_htt *htt)
136{
137 struct ath10k *ar = htt->ar;
138 size_t size;
139
140 if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL, ar->fw_features))
141 return;
142
143 size = sizeof(*htt->tx_q_state.vaddr);
144
145 dma_unmap_single(ar->dev, htt->tx_q_state.paddr, size, DMA_TO_DEVICE);
146 kfree(htt->tx_q_state.vaddr);
147}
148
149static int ath10k_htt_tx_alloc_txq(struct ath10k_htt *htt)
150{
151 struct ath10k *ar = htt->ar;
152 size_t size;
153 int ret;
154
155 if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL, ar->fw_features))
156 return 0;
157
158 htt->tx_q_state.num_peers = HTT_TX_Q_STATE_NUM_PEERS;
159 htt->tx_q_state.num_tids = HTT_TX_Q_STATE_NUM_TIDS;
160 htt->tx_q_state.type = HTT_Q_DEPTH_TYPE_BYTES;
161
162 size = sizeof(*htt->tx_q_state.vaddr);
163 htt->tx_q_state.vaddr = kzalloc(size, GFP_KERNEL);
164 if (!htt->tx_q_state.vaddr)
165 return -ENOMEM;
166
167 htt->tx_q_state.paddr = dma_map_single(ar->dev, htt->tx_q_state.vaddr,
168 size, DMA_TO_DEVICE);
169 ret = dma_mapping_error(ar->dev, htt->tx_q_state.paddr);
170 if (ret) {
171 ath10k_warn(ar, "failed to dma map tx_q_state: %d\n", ret);
172 kfree(htt->tx_q_state.vaddr);
173 return -EIO;
174 }
175
176 return 0;
177}
178
Michal Kazior95bf21f2014-05-16 17:15:39 +0300179int ath10k_htt_tx_alloc(struct ath10k_htt *htt)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300180{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200181 struct ath10k *ar = htt->ar;
Raja Manid9156b52015-06-22 20:22:27 +0530182 int ret, size;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200183
Michal Kazior7aa7a722014-08-25 12:09:38 +0200184 ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt tx max num pending tx %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300185 htt->max_num_pending_tx);
186
Michal Kazior89d6d832015-01-24 12:14:51 +0200187 spin_lock_init(&htt->tx_lock);
188 idr_init(&htt->pending_tx);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300189
Peter Oh683b95e2015-10-05 17:56:40 +0300190 size = htt->max_num_pending_tx * sizeof(struct ath10k_htt_txbuf);
191 htt->txbuf.vaddr = dma_alloc_coherent(ar->dev, size,
192 &htt->txbuf.paddr,
Felix Fietkaud6cb23b52015-11-24 11:36:52 +0100193 GFP_KERNEL);
Peter Oh683b95e2015-10-05 17:56:40 +0300194 if (!htt->txbuf.vaddr) {
195 ath10k_err(ar, "failed to alloc tx buffer\n");
Raja Manid9156b52015-06-22 20:22:27 +0530196 ret = -ENOMEM;
197 goto free_idr_pending_tx;
Michal Kaziora16942e2014-02-27 18:50:04 +0200198 }
199
Michal Kazior575fc892016-01-21 14:13:26 +0100200 ret = ath10k_htt_tx_alloc_cont_frag_desc(htt);
201 if (ret) {
202 ath10k_err(ar, "failed to alloc cont frag desc: %d\n", ret);
Peter Oh683b95e2015-10-05 17:56:40 +0300203 goto free_txbuf;
Raja Manid9156b52015-06-22 20:22:27 +0530204 }
205
Michal Kazior9b158732016-01-21 14:13:27 +0100206 ret = ath10k_htt_tx_alloc_txq(htt);
207 if (ret) {
208 ath10k_err(ar, "failed to alloc txq: %d\n", ret);
209 goto free_frag_desc;
210 }
211
Kalle Valo5e3dd152013-06-12 20:52:10 +0300212 return 0;
Raja Manid9156b52015-06-22 20:22:27 +0530213
Michal Kazior9b158732016-01-21 14:13:27 +0100214free_frag_desc:
215 ath10k_htt_tx_free_cont_frag_desc(htt);
216
Peter Oh683b95e2015-10-05 17:56:40 +0300217free_txbuf:
218 size = htt->max_num_pending_tx *
219 sizeof(struct ath10k_htt_txbuf);
220 dma_free_coherent(htt->ar->dev, size, htt->txbuf.vaddr,
221 htt->txbuf.paddr);
Michal Kazior575fc892016-01-21 14:13:26 +0100222
Raja Manid9156b52015-06-22 20:22:27 +0530223free_idr_pending_tx:
224 idr_destroy(&htt->pending_tx);
Michal Kazior575fc892016-01-21 14:13:26 +0100225
Raja Manid9156b52015-06-22 20:22:27 +0530226 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300227}
228
Michal Kazior89d6d832015-01-24 12:14:51 +0200229static int ath10k_htt_tx_clean_up_pending(int msdu_id, void *skb, void *ctx)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300230{
Michal Kazior89d6d832015-01-24 12:14:51 +0200231 struct ath10k *ar = ctx;
232 struct ath10k_htt *htt = &ar->htt;
Michal Kazior0a89f8a2013-09-18 14:43:20 +0200233 struct htt_tx_done tx_done = {0};
Michal Kazior89d6d832015-01-24 12:14:51 +0200234
235 ath10k_dbg(ar, ATH10K_DBG_HTT, "force cleanup msdu_id %hu\n", msdu_id);
236
237 tx_done.discard = 1;
238 tx_done.msdu_id = msdu_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300239
Michal Kazior89d6d832015-01-24 12:14:51 +0200240 ath10k_txrx_tx_unref(htt, &tx_done);
Michal Kazior89d6d832015-01-24 12:14:51 +0200241
242 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300243}
244
Michal Kazior95bf21f2014-05-16 17:15:39 +0300245void ath10k_htt_tx_free(struct ath10k_htt *htt)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300246{
Raja Manid9156b52015-06-22 20:22:27 +0530247 int size;
248
Michal Kazior89d6d832015-01-24 12:14:51 +0200249 idr_for_each(&htt->pending_tx, ath10k_htt_tx_clean_up_pending, htt->ar);
250 idr_destroy(&htt->pending_tx);
Peter Oh683b95e2015-10-05 17:56:40 +0300251
252 if (htt->txbuf.vaddr) {
253 size = htt->max_num_pending_tx *
254 sizeof(struct ath10k_htt_txbuf);
255 dma_free_coherent(htt->ar->dev, size, htt->txbuf.vaddr,
256 htt->txbuf.paddr);
257 }
Raja Manid9156b52015-06-22 20:22:27 +0530258
Michal Kazior9b158732016-01-21 14:13:27 +0100259 ath10k_htt_tx_free_txq(htt);
Michal Kazior575fc892016-01-21 14:13:26 +0100260 ath10k_htt_tx_free_cont_frag_desc(htt);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300261}
262
263void ath10k_htt_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
264{
Michal Kazior0a89f8a2013-09-18 14:43:20 +0200265 dev_kfree_skb_any(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300266}
267
Rajkumar Manoharan3f0f7ed2015-10-12 18:27:03 +0530268void ath10k_htt_hif_tx_complete(struct ath10k *ar, struct sk_buff *skb)
269{
270 dev_kfree_skb_any(skb);
271}
272EXPORT_SYMBOL(ath10k_htt_hif_tx_complete);
273
Kalle Valo5e3dd152013-06-12 20:52:10 +0300274int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt *htt)
275{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200276 struct ath10k *ar = htt->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300277 struct sk_buff *skb;
278 struct htt_cmd *cmd;
279 int len = 0;
280 int ret;
281
282 len += sizeof(cmd->hdr);
283 len += sizeof(cmd->ver_req);
284
Michal Kazior7aa7a722014-08-25 12:09:38 +0200285 skb = ath10k_htc_alloc_skb(ar, len);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300286 if (!skb)
287 return -ENOMEM;
288
289 skb_put(skb, len);
290 cmd = (struct htt_cmd *)skb->data;
291 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_VERSION_REQ;
292
Michal Kaziorcd003fa2013-07-05 16:15:13 +0300293 ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300294 if (ret) {
295 dev_kfree_skb_any(skb);
296 return ret;
297 }
298
299 return 0;
300}
301
Kalle Valoa3d135e2013-09-03 11:44:10 +0300302int ath10k_htt_h2t_stats_req(struct ath10k_htt *htt, u8 mask, u64 cookie)
303{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200304 struct ath10k *ar = htt->ar;
Kalle Valoa3d135e2013-09-03 11:44:10 +0300305 struct htt_stats_req *req;
306 struct sk_buff *skb;
307 struct htt_cmd *cmd;
308 int len = 0, ret;
309
310 len += sizeof(cmd->hdr);
311 len += sizeof(cmd->stats_req);
312
Michal Kazior7aa7a722014-08-25 12:09:38 +0200313 skb = ath10k_htc_alloc_skb(ar, len);
Kalle Valoa3d135e2013-09-03 11:44:10 +0300314 if (!skb)
315 return -ENOMEM;
316
317 skb_put(skb, len);
318 cmd = (struct htt_cmd *)skb->data;
319 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_STATS_REQ;
320
321 req = &cmd->stats_req;
322
323 memset(req, 0, sizeof(*req));
324
325 /* currently we support only max 8 bit masks so no need to worry
326 * about endian support */
327 req->upload_types[0] = mask;
328 req->reset_types[0] = mask;
329 req->stat_type = HTT_STATS_REQ_CFG_STAT_TYPE_INVALID;
330 req->cookie_lsb = cpu_to_le32(cookie & 0xffffffff);
331 req->cookie_msb = cpu_to_le32((cookie & 0xffffffff00000000ULL) >> 32);
332
Kalle Valoa3d135e2013-09-03 11:44:10 +0300333 ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
334 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200335 ath10k_warn(ar, "failed to send htt type stats request: %d",
336 ret);
Kalle Valoa3d135e2013-09-03 11:44:10 +0300337 dev_kfree_skb_any(skb);
338 return ret;
339 }
340
341 return 0;
342}
343
Raja Manid9156b52015-06-22 20:22:27 +0530344int ath10k_htt_send_frag_desc_bank_cfg(struct ath10k_htt *htt)
345{
346 struct ath10k *ar = htt->ar;
347 struct sk_buff *skb;
348 struct htt_cmd *cmd;
Michal Kazior9b158732016-01-21 14:13:27 +0100349 struct htt_frag_desc_bank_cfg *cfg;
Raja Manid9156b52015-06-22 20:22:27 +0530350 int ret, size;
Michal Kazior9b158732016-01-21 14:13:27 +0100351 u8 info;
Raja Manid9156b52015-06-22 20:22:27 +0530352
353 if (!ar->hw_params.continuous_frag_desc)
354 return 0;
355
356 if (!htt->frag_desc.paddr) {
357 ath10k_warn(ar, "invalid frag desc memory\n");
358 return -EINVAL;
359 }
360
361 size = sizeof(cmd->hdr) + sizeof(cmd->frag_desc_bank_cfg);
362 skb = ath10k_htc_alloc_skb(ar, size);
363 if (!skb)
364 return -ENOMEM;
365
366 skb_put(skb, size);
367 cmd = (struct htt_cmd *)skb->data;
368 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_FRAG_DESC_BANK_CFG;
Michal Kazior9b158732016-01-21 14:13:27 +0100369
370 info = 0;
371 info |= SM(htt->tx_q_state.type,
372 HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_DEPTH_TYPE);
373
374 if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL, ar->fw_features))
375 info |= HTT_FRAG_DESC_BANK_CFG_INFO_Q_STATE_VALID;
376
377 cfg = &cmd->frag_desc_bank_cfg;
378 cfg->info = info;
379 cfg->num_banks = 1;
380 cfg->desc_size = sizeof(struct htt_msdu_ext_desc);
381 cfg->bank_base_addrs[0] = __cpu_to_le32(htt->frag_desc.paddr);
382 cfg->bank_id[0].bank_min_id = 0;
383 cfg->bank_id[0].bank_max_id = __cpu_to_le16(htt->max_num_pending_tx -
384 1);
385
386 cfg->q_state.paddr = cpu_to_le32(htt->tx_q_state.paddr);
387 cfg->q_state.num_peers = cpu_to_le16(htt->tx_q_state.num_peers);
388 cfg->q_state.num_tids = cpu_to_le16(htt->tx_q_state.num_tids);
389 cfg->q_state.record_size = HTT_TX_Q_STATE_ENTRY_SIZE;
390 cfg->q_state.record_multiplier = HTT_TX_Q_STATE_ENTRY_MULTIPLIER;
391
392 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt frag desc bank cmd\n");
Raja Manid9156b52015-06-22 20:22:27 +0530393
394 ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
395 if (ret) {
396 ath10k_warn(ar, "failed to send frag desc bank cfg request: %d\n",
397 ret);
398 dev_kfree_skb_any(skb);
399 return ret;
400 }
401
402 return 0;
403}
404
Kalle Valo5e3dd152013-06-12 20:52:10 +0300405int ath10k_htt_send_rx_ring_cfg_ll(struct ath10k_htt *htt)
406{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200407 struct ath10k *ar = htt->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300408 struct sk_buff *skb;
409 struct htt_cmd *cmd;
410 struct htt_rx_ring_setup_ring *ring;
411 const int num_rx_ring = 1;
412 u16 flags;
413 u32 fw_idx;
414 int len;
415 int ret;
416
417 /*
418 * the HW expects the buffer to be an integral number of 4-byte
419 * "words"
420 */
421 BUILD_BUG_ON(!IS_ALIGNED(HTT_RX_BUF_SIZE, 4));
422 BUILD_BUG_ON((HTT_RX_BUF_SIZE & HTT_MAX_CACHE_LINE_SIZE_MASK) != 0);
423
424 len = sizeof(cmd->hdr) + sizeof(cmd->rx_setup.hdr)
425 + (sizeof(*ring) * num_rx_ring);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200426 skb = ath10k_htc_alloc_skb(ar, len);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300427 if (!skb)
428 return -ENOMEM;
429
430 skb_put(skb, len);
431
432 cmd = (struct htt_cmd *)skb->data;
433 ring = &cmd->rx_setup.rings[0];
434
435 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_RX_RING_CFG;
436 cmd->rx_setup.hdr.num_rings = 1;
437
438 /* FIXME: do we need all of this? */
439 flags = 0;
440 flags |= HTT_RX_RING_FLAGS_MAC80211_HDR;
441 flags |= HTT_RX_RING_FLAGS_MSDU_PAYLOAD;
442 flags |= HTT_RX_RING_FLAGS_PPDU_START;
443 flags |= HTT_RX_RING_FLAGS_PPDU_END;
444 flags |= HTT_RX_RING_FLAGS_MPDU_START;
445 flags |= HTT_RX_RING_FLAGS_MPDU_END;
446 flags |= HTT_RX_RING_FLAGS_MSDU_START;
447 flags |= HTT_RX_RING_FLAGS_MSDU_END;
448 flags |= HTT_RX_RING_FLAGS_RX_ATTENTION;
449 flags |= HTT_RX_RING_FLAGS_FRAG_INFO;
450 flags |= HTT_RX_RING_FLAGS_UNICAST_RX;
451 flags |= HTT_RX_RING_FLAGS_MULTICAST_RX;
452 flags |= HTT_RX_RING_FLAGS_CTRL_RX;
453 flags |= HTT_RX_RING_FLAGS_MGMT_RX;
454 flags |= HTT_RX_RING_FLAGS_NULL_RX;
455 flags |= HTT_RX_RING_FLAGS_PHY_DATA_RX;
456
457 fw_idx = __le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr);
458
459 ring->fw_idx_shadow_reg_paddr =
460 __cpu_to_le32(htt->rx_ring.alloc_idx.paddr);
461 ring->rx_ring_base_paddr = __cpu_to_le32(htt->rx_ring.base_paddr);
462 ring->rx_ring_len = __cpu_to_le16(htt->rx_ring.size);
463 ring->rx_ring_bufsize = __cpu_to_le16(HTT_RX_BUF_SIZE);
464 ring->flags = __cpu_to_le16(flags);
465 ring->fw_idx_init_val = __cpu_to_le16(fw_idx);
466
467#define desc_offset(x) (offsetof(struct htt_rx_desc, x) / 4)
468
469 ring->mac80211_hdr_offset = __cpu_to_le16(desc_offset(rx_hdr_status));
470 ring->msdu_payload_offset = __cpu_to_le16(desc_offset(msdu_payload));
471 ring->ppdu_start_offset = __cpu_to_le16(desc_offset(ppdu_start));
472 ring->ppdu_end_offset = __cpu_to_le16(desc_offset(ppdu_end));
473 ring->mpdu_start_offset = __cpu_to_le16(desc_offset(mpdu_start));
474 ring->mpdu_end_offset = __cpu_to_le16(desc_offset(mpdu_end));
475 ring->msdu_start_offset = __cpu_to_le16(desc_offset(msdu_start));
476 ring->msdu_end_offset = __cpu_to_le16(desc_offset(msdu_end));
477 ring->rx_attention_offset = __cpu_to_le16(desc_offset(attention));
478 ring->frag_info_offset = __cpu_to_le16(desc_offset(frag_info));
479
480#undef desc_offset
481
Michal Kaziorcd003fa2013-07-05 16:15:13 +0300482 ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300483 if (ret) {
484 dev_kfree_skb_any(skb);
485 return ret;
486 }
487
488 return 0;
489}
490
Janusz Dziedzicd3856232014-06-02 21:19:46 +0300491int ath10k_htt_h2t_aggr_cfg_msg(struct ath10k_htt *htt,
492 u8 max_subfrms_ampdu,
493 u8 max_subfrms_amsdu)
494{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200495 struct ath10k *ar = htt->ar;
Janusz Dziedzicd3856232014-06-02 21:19:46 +0300496 struct htt_aggr_conf *aggr_conf;
497 struct sk_buff *skb;
498 struct htt_cmd *cmd;
499 int len;
500 int ret;
501
502 /* Firmware defaults are: amsdu = 3 and ampdu = 64 */
503
504 if (max_subfrms_ampdu == 0 || max_subfrms_ampdu > 64)
505 return -EINVAL;
506
507 if (max_subfrms_amsdu == 0 || max_subfrms_amsdu > 31)
508 return -EINVAL;
509
510 len = sizeof(cmd->hdr);
511 len += sizeof(cmd->aggr_conf);
512
Michal Kazior7aa7a722014-08-25 12:09:38 +0200513 skb = ath10k_htc_alloc_skb(ar, len);
Janusz Dziedzicd3856232014-06-02 21:19:46 +0300514 if (!skb)
515 return -ENOMEM;
516
517 skb_put(skb, len);
518 cmd = (struct htt_cmd *)skb->data;
519 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_AGGR_CFG;
520
521 aggr_conf = &cmd->aggr_conf;
522 aggr_conf->max_num_ampdu_subframes = max_subfrms_ampdu;
523 aggr_conf->max_num_amsdu_subframes = max_subfrms_amsdu;
524
Michal Kazior7aa7a722014-08-25 12:09:38 +0200525 ath10k_dbg(ar, ATH10K_DBG_HTT, "htt h2t aggr cfg msg amsdu %d ampdu %d",
Janusz Dziedzicd3856232014-06-02 21:19:46 +0300526 aggr_conf->max_num_amsdu_subframes,
527 aggr_conf->max_num_ampdu_subframes);
528
529 ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
530 if (ret) {
531 dev_kfree_skb_any(skb);
532 return ret;
533 }
534
535 return 0;
536}
537
Michal Kazior609db222015-11-18 06:59:22 +0100538static u8 ath10k_htt_tx_get_vdev_id(struct ath10k *ar, struct sk_buff *skb)
539{
540 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
541 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
542 struct ath10k_vif *arvif = (void *)cb->vif->drv_priv;
543
544 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)
545 return ar->scan.vdev_id;
546 else if (cb->vif)
547 return arvif->vdev_id;
548 else if (ar->monitor_started)
549 return ar->monitor_vdev_id;
550 else
551 return 0;
552}
553
554static u8 ath10k_htt_tx_get_tid(struct sk_buff *skb, bool is_eth)
555{
556 struct ieee80211_hdr *hdr = (void *)skb->data;
557 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
558
559 if (!is_eth && ieee80211_is_mgmt(hdr->frame_control))
560 return HTT_DATA_TX_EXT_TID_MGMT;
561 else if (cb->flags & ATH10K_SKB_F_QOS)
562 return skb->priority % IEEE80211_QOS_CTL_TID_MASK;
563 else
564 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
565}
566
Kalle Valo5e3dd152013-06-12 20:52:10 +0300567int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
568{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200569 struct ath10k *ar = htt->ar;
570 struct device *dev = ar->dev;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300571 struct sk_buff *txdesc = NULL;
572 struct htt_cmd *cmd;
Michal Kazior1f8bb152013-09-18 14:43:22 +0200573 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
Michal Kazior609db222015-11-18 06:59:22 +0100574 u8 vdev_id = ath10k_htt_tx_get_vdev_id(ar, msdu);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300575 int len = 0;
576 int msdu_id = -1;
577 int res;
Vivek Natarajan7b7da0a2015-08-31 16:34:55 +0530578 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
579 bool limit_mgmt_desc = false;
580 bool is_probe_resp = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300581
Vivek Natarajan7b7da0a2015-08-31 16:34:55 +0530582 if (ar->hw_params.max_probe_resp_desc_thres) {
583 limit_mgmt_desc = true;
584
585 if (ieee80211_is_probe_resp(hdr->frame_control))
586 is_probe_resp = true;
587 }
588
589 res = ath10k_htt_tx_inc_pending(htt, limit_mgmt_desc, is_probe_resp);
590
Kalle Valo5e3dd152013-06-12 20:52:10 +0300591 if (res)
Michal Kazior2f3773b2013-09-18 14:43:21 +0200592 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300593
594 len += sizeof(cmd->hdr);
595 len += sizeof(cmd->mgmt_tx);
596
Kalle Valo5e3dd152013-06-12 20:52:10 +0300597 spin_lock_bh(&htt->tx_lock);
Michal Kazior89d6d832015-01-24 12:14:51 +0200598 res = ath10k_htt_tx_alloc_msdu_id(htt, msdu);
Qi Zhou005fb162015-07-22 16:38:24 -0400599 spin_unlock_bh(&htt->tx_lock);
Kalle Valob9e284e2015-10-05 17:56:35 +0300600 if (res < 0)
Michal Kazior2f3773b2013-09-18 14:43:21 +0200601 goto err_tx_dec;
Kalle Valob9e284e2015-10-05 17:56:35 +0300602
Michal Kazior2f3773b2013-09-18 14:43:21 +0200603 msdu_id = res;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300604
Tamizh chelvam90eceb32015-10-29 14:27:42 +0200605 if ((ieee80211_is_action(hdr->frame_control) ||
606 ieee80211_is_deauth(hdr->frame_control) ||
607 ieee80211_is_disassoc(hdr->frame_control)) &&
608 ieee80211_has_protected(hdr->frame_control)) {
609 skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
610 }
611
Michal Kazior7aa7a722014-08-25 12:09:38 +0200612 txdesc = ath10k_htc_alloc_skb(ar, len);
Michal Kazior2f3773b2013-09-18 14:43:21 +0200613 if (!txdesc) {
614 res = -ENOMEM;
615 goto err_free_msdu_id;
616 }
617
Michal Kazior767d34f2014-02-27 18:50:03 +0200618 skb_cb->paddr = dma_map_single(dev, msdu->data, msdu->len,
619 DMA_TO_DEVICE);
620 res = dma_mapping_error(dev, skb_cb->paddr);
Michal Kazior5e55e3c2015-08-19 13:10:43 +0200621 if (res) {
622 res = -EIO;
Michal Kazior2f3773b2013-09-18 14:43:21 +0200623 goto err_free_txdesc;
Michal Kazior5e55e3c2015-08-19 13:10:43 +0200624 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300625
626 skb_put(txdesc, len);
627 cmd = (struct htt_cmd *)txdesc->data;
Raja Mani1d0088f2015-07-21 10:52:00 +0530628 memset(cmd, 0, len);
629
Kalle Valo5e3dd152013-06-12 20:52:10 +0300630 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_MGMT_TX;
631 cmd->mgmt_tx.msdu_paddr = __cpu_to_le32(ATH10K_SKB_CB(msdu)->paddr);
632 cmd->mgmt_tx.len = __cpu_to_le32(msdu->len);
633 cmd->mgmt_tx.desc_id = __cpu_to_le32(msdu_id);
634 cmd->mgmt_tx.vdev_id = __cpu_to_le32(vdev_id);
635 memcpy(cmd->mgmt_tx.hdr, msdu->data,
636 min_t(int, msdu->len, HTT_MGMT_FRM_HDR_DOWNLOAD_LEN));
637
Michal Kaziorcd003fa2013-07-05 16:15:13 +0300638 res = ath10k_htc_send(&htt->ar->htc, htt->eid, txdesc);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300639 if (res)
Michal Kazior2f3773b2013-09-18 14:43:21 +0200640 goto err_unmap_msdu;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300641
642 return 0;
643
Michal Kazior2f3773b2013-09-18 14:43:21 +0200644err_unmap_msdu:
Michal Kazior767d34f2014-02-27 18:50:03 +0200645 dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
Michal Kazior2f3773b2013-09-18 14:43:21 +0200646err_free_txdesc:
647 dev_kfree_skb_any(txdesc);
648err_free_msdu_id:
649 spin_lock_bh(&htt->tx_lock);
Michal Kazior2f3773b2013-09-18 14:43:21 +0200650 ath10k_htt_tx_free_msdu_id(htt, msdu_id);
651 spin_unlock_bh(&htt->tx_lock);
652err_tx_dec:
Vivek Natarajan7b7da0a2015-08-31 16:34:55 +0530653 ath10k_htt_tx_dec_pending(htt, limit_mgmt_desc);
Michal Kazior2f3773b2013-09-18 14:43:21 +0200654err:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300655 return res;
656}
657
Michal Kazior8a933962015-11-18 06:59:17 +0100658int ath10k_htt_tx(struct ath10k_htt *htt, enum ath10k_hw_txrx_mode txmode,
659 struct sk_buff *msdu)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300660{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200661 struct ath10k *ar = htt->ar;
662 struct device *dev = ar->dev;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300663 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
Michal Kaziorbd877442015-11-18 06:59:19 +0100664 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(msdu);
Michal Kazior1f8bb152013-09-18 14:43:22 +0200665 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
Michal Kaziora16942e2014-02-27 18:50:04 +0200666 struct ath10k_hif_sg_item sg_items[2];
Michal Kazioraca146a2015-11-18 06:59:23 +0100667 struct ath10k_htt_txbuf *txbuf;
Michal Kaziora16942e2014-02-27 18:50:04 +0200668 struct htt_data_tx_desc_frag *frags;
Michal Kazior609db222015-11-18 06:59:22 +0100669 bool is_eth = (txmode == ATH10K_HW_TXRX_ETHERNET);
670 u8 vdev_id = ath10k_htt_tx_get_vdev_id(ar, msdu);
671 u8 tid = ath10k_htt_tx_get_tid(msdu, is_eth);
Michal Kaziora16942e2014-02-27 18:50:04 +0200672 int prefetch_len;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300673 int res;
Michal Kaziora16942e2014-02-27 18:50:04 +0200674 u8 flags0 = 0;
675 u16 msdu_id, flags1 = 0;
Michal Kaziorbd877442015-11-18 06:59:19 +0100676 u16 freq = 0;
Michal Kaziord740d8f2015-03-30 09:51:51 +0300677 u32 frags_paddr = 0;
Michal Kazioraca146a2015-11-18 06:59:23 +0100678 u32 txbuf_paddr;
Manikanta Pubbisettyb9635192015-07-20 17:56:12 +0530679 struct htt_msdu_ext_desc *ext_desc = NULL;
Vivek Natarajan7b7da0a2015-08-31 16:34:55 +0530680 bool limit_mgmt_desc = false;
681 bool is_probe_resp = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300682
Vivek Natarajan7b7da0a2015-08-31 16:34:55 +0530683 if (unlikely(ieee80211_is_mgmt(hdr->frame_control)) &&
684 ar->hw_params.max_probe_resp_desc_thres) {
685 limit_mgmt_desc = true;
686
687 if (ieee80211_is_probe_resp(hdr->frame_control))
688 is_probe_resp = true;
689 }
690
691 res = ath10k_htt_tx_inc_pending(htt, limit_mgmt_desc, is_probe_resp);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300692 if (res)
Michal Kazior2f3773b2013-09-18 14:43:21 +0200693 goto err;
694
695 spin_lock_bh(&htt->tx_lock);
Michal Kazior89d6d832015-01-24 12:14:51 +0200696 res = ath10k_htt_tx_alloc_msdu_id(htt, msdu);
Qi Zhou005fb162015-07-22 16:38:24 -0400697 spin_unlock_bh(&htt->tx_lock);
Kalle Valob9e284e2015-10-05 17:56:35 +0300698 if (res < 0)
Michal Kazior2f3773b2013-09-18 14:43:21 +0200699 goto err_tx_dec;
Kalle Valob9e284e2015-10-05 17:56:35 +0300700
Michal Kazior2f3773b2013-09-18 14:43:21 +0200701 msdu_id = res;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300702
703 prefetch_len = min(htt->prefetch_len, msdu->len);
704 prefetch_len = roundup(prefetch_len, 4);
705
Michal Kazioraca146a2015-11-18 06:59:23 +0100706 txbuf = &htt->txbuf.vaddr[msdu_id];
707 txbuf_paddr = htt->txbuf.paddr +
708 (sizeof(struct ath10k_htt_txbuf) * msdu_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300709
Marek Kwaczynskieebc67f2015-01-24 12:14:53 +0200710 if ((ieee80211_is_action(hdr->frame_control) ||
711 ieee80211_is_deauth(hdr->frame_control) ||
712 ieee80211_is_disassoc(hdr->frame_control)) &&
David Liuccec9032015-07-24 20:25:32 +0300713 ieee80211_has_protected(hdr->frame_control)) {
Marek Kwaczynskieebc67f2015-01-24 12:14:53 +0200714 skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
Michal Kazior66b8a012015-11-18 06:59:20 +0100715 } else if (!(skb_cb->flags & ATH10K_SKB_F_NO_HWCRYPT) &&
Michal Kazior8a933962015-11-18 06:59:17 +0100716 txmode == ATH10K_HW_TXRX_RAW &&
Bob Copelandbc76c282015-09-09 12:47:35 -0400717 ieee80211_has_protected(hdr->frame_control)) {
David Liuccec9032015-07-24 20:25:32 +0300718 skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
719 }
Marek Kwaczynskieebc67f2015-01-24 12:14:53 +0200720
Michal Kazior767d34f2014-02-27 18:50:03 +0200721 skb_cb->paddr = dma_map_single(dev, msdu->data, msdu->len,
722 DMA_TO_DEVICE);
723 res = dma_mapping_error(dev, skb_cb->paddr);
Michal Kazior5e55e3c2015-08-19 13:10:43 +0200724 if (res) {
725 res = -EIO;
Peter Oh683b95e2015-10-05 17:56:40 +0300726 goto err_free_msdu_id;
Michal Kazior5e55e3c2015-08-19 13:10:43 +0200727 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300728
Michal Kaziorbd877442015-11-18 06:59:19 +0100729 if (unlikely(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN))
730 freq = ar->scan.roc_freq;
731
Michal Kazior8a933962015-11-18 06:59:17 +0100732 switch (txmode) {
Michal Kaziord740d8f2015-03-30 09:51:51 +0300733 case ATH10K_HW_TXRX_RAW:
734 case ATH10K_HW_TXRX_NATIVE_WIFI:
735 flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
736 /* pass through */
737 case ATH10K_HW_TXRX_ETHERNET:
Peter Ohfbc03a42015-07-15 19:01:19 -0700738 if (ar->hw_params.continuous_frag_desc) {
Peter Ohae7d3822015-07-29 11:58:50 +0300739 memset(&htt->frag_desc.vaddr[msdu_id], 0,
740 sizeof(struct htt_msdu_ext_desc));
Peter Ohfbc03a42015-07-15 19:01:19 -0700741 frags = (struct htt_data_tx_desc_frag *)
742 &htt->frag_desc.vaddr[msdu_id].frags;
Manikanta Pubbisettyb9635192015-07-20 17:56:12 +0530743 ext_desc = &htt->frag_desc.vaddr[msdu_id];
Peter Ohfbc03a42015-07-15 19:01:19 -0700744 frags[0].tword_addr.paddr_lo =
745 __cpu_to_le32(skb_cb->paddr);
746 frags[0].tword_addr.paddr_hi = 0;
747 frags[0].tword_addr.len_16 = __cpu_to_le16(msdu->len);
Michal Kazior1f8bb152013-09-18 14:43:22 +0200748
Peter Ohfbc03a42015-07-15 19:01:19 -0700749 frags_paddr = htt->frag_desc.paddr +
750 (sizeof(struct htt_msdu_ext_desc) * msdu_id);
751 } else {
Michal Kazioraca146a2015-11-18 06:59:23 +0100752 frags = txbuf->frags;
Peter Ohfbc03a42015-07-15 19:01:19 -0700753 frags[0].dword_addr.paddr =
754 __cpu_to_le32(skb_cb->paddr);
755 frags[0].dword_addr.len = __cpu_to_le32(msdu->len);
756 frags[1].dword_addr.paddr = 0;
757 frags[1].dword_addr.len = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300758
Michal Kazioraca146a2015-11-18 06:59:23 +0100759 frags_paddr = txbuf_paddr;
Peter Ohfbc03a42015-07-15 19:01:19 -0700760 }
Michal Kazior8a933962015-11-18 06:59:17 +0100761 flags0 |= SM(txmode, HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
Michal Kaziord740d8f2015-03-30 09:51:51 +0300762 break;
763 case ATH10K_HW_TXRX_MGMT:
Michal Kazior2f3773b2013-09-18 14:43:21 +0200764 flags0 |= SM(ATH10K_HW_TXRX_MGMT,
Michal Kazior961d4c32013-08-09 10:13:34 +0200765 HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
Michal Kaziord740d8f2015-03-30 09:51:51 +0300766 flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300767
Michal Kaziora16942e2014-02-27 18:50:04 +0200768 frags_paddr = skb_cb->paddr;
Michal Kaziord740d8f2015-03-30 09:51:51 +0300769 break;
Michal Kaziora16942e2014-02-27 18:50:04 +0200770 }
771
772 /* Normally all commands go through HTC which manages tx credits for
773 * each endpoint and notifies when tx is completed.
774 *
775 * HTT endpoint is creditless so there's no need to care about HTC
776 * flags. In that case it is trivial to fill the HTC header here.
777 *
778 * MSDU transmission is considered completed upon HTT event. This
779 * implies no relevant resources can be freed until after the event is
780 * received. That's why HTC tx completion handler itself is ignored by
781 * setting NULL to transfer_context for all sg items.
782 *
783 * There is simply no point in pushing HTT TX_FRM through HTC tx path
784 * as it's a waste of resources. By bypassing HTC it is possible to
785 * avoid extra memory allocations, compress data structures and thus
786 * improve performance. */
787
Michal Kazioraca146a2015-11-18 06:59:23 +0100788 txbuf->htc_hdr.eid = htt->eid;
789 txbuf->htc_hdr.len = __cpu_to_le16(sizeof(txbuf->cmd_hdr) +
790 sizeof(txbuf->cmd_tx) +
791 prefetch_len);
792 txbuf->htc_hdr.flags = 0;
Michal Kaziora16942e2014-02-27 18:50:04 +0200793
Michal Kazior66b8a012015-11-18 06:59:20 +0100794 if (skb_cb->flags & ATH10K_SKB_F_NO_HWCRYPT)
David Liuccec9032015-07-24 20:25:32 +0300795 flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT;
796
Kalle Valo5e3dd152013-06-12 20:52:10 +0300797 flags1 |= SM((u16)vdev_id, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID);
798 flags1 |= SM((u16)tid, HTT_DATA_TX_DESC_FLAGS1_EXT_TID);
David Liuccec9032015-07-24 20:25:32 +0300799 if (msdu->ip_summed == CHECKSUM_PARTIAL &&
800 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
Helmut Schaa75930d12015-01-28 11:31:32 +0100801 flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD;
802 flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD;
Manikanta Pubbisettyb9635192015-07-20 17:56:12 +0530803 if (ar->hw_params.continuous_frag_desc)
804 ext_desc->flags |= HTT_MSDU_CHECKSUM_ENABLE;
Helmut Schaa75930d12015-01-28 11:31:32 +0100805 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300806
Michal Kazior708b9bd2014-07-21 20:52:59 +0300807 /* Prevent firmware from sending up tx inspection requests. There's
808 * nothing ath10k can do with frames requested for inspection so force
809 * it to simply rely a regular tx completion with discard status.
810 */
811 flags1 |= HTT_DATA_TX_DESC_FLAGS1_POSTPONED;
812
Michal Kazioraca146a2015-11-18 06:59:23 +0100813 txbuf->cmd_hdr.msg_type = HTT_H2T_MSG_TYPE_TX_FRM;
814 txbuf->cmd_tx.flags0 = flags0;
815 txbuf->cmd_tx.flags1 = __cpu_to_le16(flags1);
816 txbuf->cmd_tx.len = __cpu_to_le16(msdu->len);
817 txbuf->cmd_tx.id = __cpu_to_le16(msdu_id);
818 txbuf->cmd_tx.frags_paddr = __cpu_to_le32(frags_paddr);
Vasanthakumar Thiagarajand39de992015-11-05 11:34:00 +0530819 if (ath10k_mac_tx_frm_has_freq(ar)) {
Michal Kazioraca146a2015-11-18 06:59:23 +0100820 txbuf->cmd_tx.offchan_tx.peerid =
Vasanthakumar Thiagarajand39de992015-11-05 11:34:00 +0530821 __cpu_to_le16(HTT_INVALID_PEERID);
Michal Kazioraca146a2015-11-18 06:59:23 +0100822 txbuf->cmd_tx.offchan_tx.freq =
Michal Kaziorbd877442015-11-18 06:59:19 +0100823 __cpu_to_le16(freq);
Vasanthakumar Thiagarajand39de992015-11-05 11:34:00 +0530824 } else {
Michal Kazioraca146a2015-11-18 06:59:23 +0100825 txbuf->cmd_tx.peerid =
Vasanthakumar Thiagarajand39de992015-11-05 11:34:00 +0530826 __cpu_to_le32(HTT_INVALID_PEERID);
827 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300828
Rajkumar Manoharand1e50f42014-10-03 08:02:54 +0300829 trace_ath10k_htt_tx(ar, msdu_id, msdu->len, vdev_id, tid);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200830 ath10k_dbg(ar, ATH10K_DBG_HTT,
Michal Kazior8d6d3622014-11-24 14:58:31 +0100831 "htt tx flags0 %hhu flags1 %hu len %d id %hu frags_paddr %08x, msdu_paddr %08x vdev %hhu tid %hhu freq %hu\n",
Michal Kaziora16942e2014-02-27 18:50:04 +0200832 flags0, flags1, msdu->len, msdu_id, frags_paddr,
Michal Kaziorbd877442015-11-18 06:59:19 +0100833 (u32)skb_cb->paddr, vdev_id, tid, freq);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200834 ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt tx msdu: ",
Michal Kaziora16942e2014-02-27 18:50:04 +0200835 msdu->data, msdu->len);
Rajkumar Manoharan5ce8e7f2014-11-05 19:14:31 +0530836 trace_ath10k_tx_hdr(ar, msdu->data, msdu->len);
837 trace_ath10k_tx_payload(ar, msdu->data, msdu->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300838
Michal Kaziora16942e2014-02-27 18:50:04 +0200839 sg_items[0].transfer_id = 0;
840 sg_items[0].transfer_context = NULL;
Michal Kazioraca146a2015-11-18 06:59:23 +0100841 sg_items[0].vaddr = &txbuf->htc_hdr;
842 sg_items[0].paddr = txbuf_paddr +
843 sizeof(txbuf->frags);
844 sg_items[0].len = sizeof(txbuf->htc_hdr) +
845 sizeof(txbuf->cmd_hdr) +
846 sizeof(txbuf->cmd_tx);
Michal Kaziora16942e2014-02-27 18:50:04 +0200847
848 sg_items[1].transfer_id = 0;
849 sg_items[1].transfer_context = NULL;
850 sg_items[1].vaddr = msdu->data;
851 sg_items[1].paddr = skb_cb->paddr;
852 sg_items[1].len = prefetch_len;
853
854 res = ath10k_hif_tx_sg(htt->ar,
855 htt->ar->htc.endpoint[htt->eid].ul_pipe_id,
856 sg_items, ARRAY_SIZE(sg_items));
Kalle Valo5e3dd152013-06-12 20:52:10 +0300857 if (res)
Michal Kazior1f8bb152013-09-18 14:43:22 +0200858 goto err_unmap_msdu;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300859
860 return 0;
Michal Kazior2f3773b2013-09-18 14:43:21 +0200861
Michal Kazior2f3773b2013-09-18 14:43:21 +0200862err_unmap_msdu:
Michal Kazior767d34f2014-02-27 18:50:03 +0200863 dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
Michal Kazior2f3773b2013-09-18 14:43:21 +0200864err_free_msdu_id:
865 spin_lock_bh(&htt->tx_lock);
Michal Kazior2f3773b2013-09-18 14:43:21 +0200866 ath10k_htt_tx_free_msdu_id(htt, msdu_id);
867 spin_unlock_bh(&htt->tx_lock);
868err_tx_dec:
Vivek Natarajan7b7da0a2015-08-31 16:34:55 +0530869 ath10k_htt_tx_dec_pending(htt, limit_mgmt_desc);
Michal Kazior2f3773b2013-09-18 14:43:21 +0200870err:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300871 return res;
872}