blob: 454812879604ffb1d8d336c2b27e61544b4fc5cd [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
25void __ath10k_htt_tx_dec_pending(struct ath10k_htt *htt)
26{
27 htt->num_pending_tx--;
28 if (htt->num_pending_tx == htt->max_num_pending_tx - 1)
29 ieee80211_wake_queues(htt->ar->hw);
30}
31
32static void ath10k_htt_tx_dec_pending(struct ath10k_htt *htt)
33{
34 spin_lock_bh(&htt->tx_lock);
35 __ath10k_htt_tx_dec_pending(htt);
36 spin_unlock_bh(&htt->tx_lock);
37}
38
39static int ath10k_htt_tx_inc_pending(struct ath10k_htt *htt)
40{
41 int ret = 0;
42
43 spin_lock_bh(&htt->tx_lock);
44
45 if (htt->num_pending_tx >= htt->max_num_pending_tx) {
46 ret = -EBUSY;
47 goto exit;
48 }
49
50 htt->num_pending_tx++;
51 if (htt->num_pending_tx == htt->max_num_pending_tx)
52 ieee80211_stop_queues(htt->ar->hw);
53
54exit:
55 spin_unlock_bh(&htt->tx_lock);
56 return ret;
57}
58
59int ath10k_htt_tx_alloc_msdu_id(struct ath10k_htt *htt)
60{
61 int msdu_id;
62
63 lockdep_assert_held(&htt->tx_lock);
64
65 msdu_id = find_first_zero_bit(htt->used_msdu_ids,
66 htt->max_num_pending_tx);
67 if (msdu_id == htt->max_num_pending_tx)
68 return -ENOBUFS;
69
70 ath10k_dbg(ATH10K_DBG_HTT, "htt tx alloc msdu_id %d\n", msdu_id);
71 __set_bit(msdu_id, htt->used_msdu_ids);
72 return msdu_id;
73}
74
75void ath10k_htt_tx_free_msdu_id(struct ath10k_htt *htt, u16 msdu_id)
76{
77 lockdep_assert_held(&htt->tx_lock);
78
79 if (!test_bit(msdu_id, htt->used_msdu_ids))
80 ath10k_warn("trying to free unallocated msdu_id %d\n", msdu_id);
81
82 ath10k_dbg(ATH10K_DBG_HTT, "htt tx free msdu_id %hu\n", msdu_id);
83 __clear_bit(msdu_id, htt->used_msdu_ids);
84}
85
86int ath10k_htt_tx_attach(struct ath10k_htt *htt)
87{
88 u8 pipe;
89
90 spin_lock_init(&htt->tx_lock);
91 init_waitqueue_head(&htt->empty_tx_wq);
92
93 /* At the beginning free queue number should hint us the maximum
94 * queue length */
Michal Kaziorcd003fa2013-07-05 16:15:13 +030095 pipe = htt->ar->htc.endpoint[htt->eid].ul_pipe_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +030096 htt->max_num_pending_tx = ath10k_hif_get_free_queue_number(htt->ar,
97 pipe);
98
Kalle Valoaad0b652013-09-08 17:56:02 +030099 ath10k_dbg(ATH10K_DBG_BOOT, "htt tx max num pending tx %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300100 htt->max_num_pending_tx);
101
102 htt->pending_tx = kzalloc(sizeof(*htt->pending_tx) *
103 htt->max_num_pending_tx, GFP_KERNEL);
104 if (!htt->pending_tx)
105 return -ENOMEM;
106
107 htt->used_msdu_ids = kzalloc(sizeof(unsigned long) *
108 BITS_TO_LONGS(htt->max_num_pending_tx),
109 GFP_KERNEL);
110 if (!htt->used_msdu_ids) {
111 kfree(htt->pending_tx);
112 return -ENOMEM;
113 }
114
115 return 0;
116}
117
118static void ath10k_htt_tx_cleanup_pending(struct ath10k_htt *htt)
119{
120 struct sk_buff *txdesc;
121 int msdu_id;
122
123 /* No locks needed. Called after communication with the device has
124 * been stopped. */
125
126 for (msdu_id = 0; msdu_id < htt->max_num_pending_tx; msdu_id++) {
127 if (!test_bit(msdu_id, htt->used_msdu_ids))
128 continue;
129
130 txdesc = htt->pending_tx[msdu_id];
131 if (!txdesc)
132 continue;
133
134 ath10k_dbg(ATH10K_DBG_HTT, "force cleanup msdu_id %hu\n",
135 msdu_id);
136
137 if (ATH10K_SKB_CB(txdesc)->htt.refcount > 0)
138 ATH10K_SKB_CB(txdesc)->htt.refcount = 1;
139
140 ATH10K_SKB_CB(txdesc)->htt.discard = true;
141 ath10k_txrx_tx_unref(htt, txdesc);
142 }
143}
144
145void ath10k_htt_tx_detach(struct ath10k_htt *htt)
146{
147 ath10k_htt_tx_cleanup_pending(htt);
148 kfree(htt->pending_tx);
149 kfree(htt->used_msdu_ids);
150 return;
151}
152
153void ath10k_htt_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
154{
155 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
Michal Kazioredb82362013-07-05 16:15:14 +0300156 struct ath10k_htt *htt = &ar->htt;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300157
158 if (skb_cb->htt.is_conf) {
159 dev_kfree_skb_any(skb);
160 return;
161 }
162
163 if (skb_cb->is_aborted) {
164 skb_cb->htt.discard = true;
165
166 /* if the skbuff is aborted we need to make sure we'll free up
167 * the tx resources, we can't simply run tx_unref() 2 times
168 * because if htt tx completion came in earlier we'd access
169 * unallocated memory */
170 if (skb_cb->htt.refcount > 1)
171 skb_cb->htt.refcount = 1;
172 }
173
174 ath10k_txrx_tx_unref(htt, skb);
175}
176
177int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt *htt)
178{
179 struct sk_buff *skb;
180 struct htt_cmd *cmd;
181 int len = 0;
182 int ret;
183
184 len += sizeof(cmd->hdr);
185 len += sizeof(cmd->ver_req);
186
187 skb = ath10k_htc_alloc_skb(len);
188 if (!skb)
189 return -ENOMEM;
190
191 skb_put(skb, len);
192 cmd = (struct htt_cmd *)skb->data;
193 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_VERSION_REQ;
194
195 ATH10K_SKB_CB(skb)->htt.is_conf = true;
196
Michal Kaziorcd003fa2013-07-05 16:15:13 +0300197 ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300198 if (ret) {
199 dev_kfree_skb_any(skb);
200 return ret;
201 }
202
203 return 0;
204}
205
Kalle Valoa3d135e2013-09-03 11:44:10 +0300206int ath10k_htt_h2t_stats_req(struct ath10k_htt *htt, u8 mask, u64 cookie)
207{
208 struct htt_stats_req *req;
209 struct sk_buff *skb;
210 struct htt_cmd *cmd;
211 int len = 0, ret;
212
213 len += sizeof(cmd->hdr);
214 len += sizeof(cmd->stats_req);
215
216 skb = ath10k_htc_alloc_skb(len);
217 if (!skb)
218 return -ENOMEM;
219
220 skb_put(skb, len);
221 cmd = (struct htt_cmd *)skb->data;
222 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_STATS_REQ;
223
224 req = &cmd->stats_req;
225
226 memset(req, 0, sizeof(*req));
227
228 /* currently we support only max 8 bit masks so no need to worry
229 * about endian support */
230 req->upload_types[0] = mask;
231 req->reset_types[0] = mask;
232 req->stat_type = HTT_STATS_REQ_CFG_STAT_TYPE_INVALID;
233 req->cookie_lsb = cpu_to_le32(cookie & 0xffffffff);
234 req->cookie_msb = cpu_to_le32((cookie & 0xffffffff00000000ULL) >> 32);
235
236 ATH10K_SKB_CB(skb)->htt.is_conf = true;
237
238 ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
239 if (ret) {
240 ath10k_warn("failed to send htt type stats request: %d", ret);
241 dev_kfree_skb_any(skb);
242 return ret;
243 }
244
245 return 0;
246}
247
Kalle Valo5e3dd152013-06-12 20:52:10 +0300248int ath10k_htt_send_rx_ring_cfg_ll(struct ath10k_htt *htt)
249{
250 struct sk_buff *skb;
251 struct htt_cmd *cmd;
252 struct htt_rx_ring_setup_ring *ring;
253 const int num_rx_ring = 1;
254 u16 flags;
255 u32 fw_idx;
256 int len;
257 int ret;
258
259 /*
260 * the HW expects the buffer to be an integral number of 4-byte
261 * "words"
262 */
263 BUILD_BUG_ON(!IS_ALIGNED(HTT_RX_BUF_SIZE, 4));
264 BUILD_BUG_ON((HTT_RX_BUF_SIZE & HTT_MAX_CACHE_LINE_SIZE_MASK) != 0);
265
266 len = sizeof(cmd->hdr) + sizeof(cmd->rx_setup.hdr)
267 + (sizeof(*ring) * num_rx_ring);
268 skb = ath10k_htc_alloc_skb(len);
269 if (!skb)
270 return -ENOMEM;
271
272 skb_put(skb, len);
273
274 cmd = (struct htt_cmd *)skb->data;
275 ring = &cmd->rx_setup.rings[0];
276
277 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_RX_RING_CFG;
278 cmd->rx_setup.hdr.num_rings = 1;
279
280 /* FIXME: do we need all of this? */
281 flags = 0;
282 flags |= HTT_RX_RING_FLAGS_MAC80211_HDR;
283 flags |= HTT_RX_RING_FLAGS_MSDU_PAYLOAD;
284 flags |= HTT_RX_RING_FLAGS_PPDU_START;
285 flags |= HTT_RX_RING_FLAGS_PPDU_END;
286 flags |= HTT_RX_RING_FLAGS_MPDU_START;
287 flags |= HTT_RX_RING_FLAGS_MPDU_END;
288 flags |= HTT_RX_RING_FLAGS_MSDU_START;
289 flags |= HTT_RX_RING_FLAGS_MSDU_END;
290 flags |= HTT_RX_RING_FLAGS_RX_ATTENTION;
291 flags |= HTT_RX_RING_FLAGS_FRAG_INFO;
292 flags |= HTT_RX_RING_FLAGS_UNICAST_RX;
293 flags |= HTT_RX_RING_FLAGS_MULTICAST_RX;
294 flags |= HTT_RX_RING_FLAGS_CTRL_RX;
295 flags |= HTT_RX_RING_FLAGS_MGMT_RX;
296 flags |= HTT_RX_RING_FLAGS_NULL_RX;
297 flags |= HTT_RX_RING_FLAGS_PHY_DATA_RX;
298
299 fw_idx = __le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr);
300
301 ring->fw_idx_shadow_reg_paddr =
302 __cpu_to_le32(htt->rx_ring.alloc_idx.paddr);
303 ring->rx_ring_base_paddr = __cpu_to_le32(htt->rx_ring.base_paddr);
304 ring->rx_ring_len = __cpu_to_le16(htt->rx_ring.size);
305 ring->rx_ring_bufsize = __cpu_to_le16(HTT_RX_BUF_SIZE);
306 ring->flags = __cpu_to_le16(flags);
307 ring->fw_idx_init_val = __cpu_to_le16(fw_idx);
308
309#define desc_offset(x) (offsetof(struct htt_rx_desc, x) / 4)
310
311 ring->mac80211_hdr_offset = __cpu_to_le16(desc_offset(rx_hdr_status));
312 ring->msdu_payload_offset = __cpu_to_le16(desc_offset(msdu_payload));
313 ring->ppdu_start_offset = __cpu_to_le16(desc_offset(ppdu_start));
314 ring->ppdu_end_offset = __cpu_to_le16(desc_offset(ppdu_end));
315 ring->mpdu_start_offset = __cpu_to_le16(desc_offset(mpdu_start));
316 ring->mpdu_end_offset = __cpu_to_le16(desc_offset(mpdu_end));
317 ring->msdu_start_offset = __cpu_to_le16(desc_offset(msdu_start));
318 ring->msdu_end_offset = __cpu_to_le16(desc_offset(msdu_end));
319 ring->rx_attention_offset = __cpu_to_le16(desc_offset(attention));
320 ring->frag_info_offset = __cpu_to_le16(desc_offset(frag_info));
321
322#undef desc_offset
323
324 ATH10K_SKB_CB(skb)->htt.is_conf = true;
325
Michal Kaziorcd003fa2013-07-05 16:15:13 +0300326 ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300327 if (ret) {
328 dev_kfree_skb_any(skb);
329 return ret;
330 }
331
332 return 0;
333}
334
335int ath10k_htt_mgmt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
336{
337 struct device *dev = htt->ar->dev;
338 struct ath10k_skb_cb *skb_cb;
339 struct sk_buff *txdesc = NULL;
340 struct htt_cmd *cmd;
341 u8 vdev_id = ATH10K_SKB_CB(msdu)->htt.vdev_id;
342 int len = 0;
343 int msdu_id = -1;
344 int res;
345
346
347 res = ath10k_htt_tx_inc_pending(htt);
348 if (res)
349 return res;
350
351 len += sizeof(cmd->hdr);
352 len += sizeof(cmd->mgmt_tx);
353
354 txdesc = ath10k_htc_alloc_skb(len);
355 if (!txdesc) {
356 res = -ENOMEM;
357 goto err;
358 }
359
360 spin_lock_bh(&htt->tx_lock);
361 msdu_id = ath10k_htt_tx_alloc_msdu_id(htt);
362 if (msdu_id < 0) {
363 spin_unlock_bh(&htt->tx_lock);
364 res = msdu_id;
365 goto err;
366 }
367 htt->pending_tx[msdu_id] = txdesc;
368 spin_unlock_bh(&htt->tx_lock);
369
370 res = ath10k_skb_map(dev, msdu);
371 if (res)
372 goto err;
373
374 skb_put(txdesc, len);
375 cmd = (struct htt_cmd *)txdesc->data;
376 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_MGMT_TX;
377 cmd->mgmt_tx.msdu_paddr = __cpu_to_le32(ATH10K_SKB_CB(msdu)->paddr);
378 cmd->mgmt_tx.len = __cpu_to_le32(msdu->len);
379 cmd->mgmt_tx.desc_id = __cpu_to_le32(msdu_id);
380 cmd->mgmt_tx.vdev_id = __cpu_to_le32(vdev_id);
381 memcpy(cmd->mgmt_tx.hdr, msdu->data,
382 min_t(int, msdu->len, HTT_MGMT_FRM_HDR_DOWNLOAD_LEN));
383
384 /* refcount is decremented by HTC and HTT completions until it reaches
385 * zero and is freed */
386 skb_cb = ATH10K_SKB_CB(txdesc);
387 skb_cb->htt.msdu_id = msdu_id;
388 skb_cb->htt.refcount = 2;
389 skb_cb->htt.msdu = msdu;
390
Michal Kaziorcd003fa2013-07-05 16:15:13 +0300391 res = ath10k_htc_send(&htt->ar->htc, htt->eid, txdesc);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300392 if (res)
393 goto err;
394
395 return 0;
396
397err:
398 ath10k_skb_unmap(dev, msdu);
399
400 if (txdesc)
401 dev_kfree_skb_any(txdesc);
402 if (msdu_id >= 0) {
403 spin_lock_bh(&htt->tx_lock);
404 htt->pending_tx[msdu_id] = NULL;
405 ath10k_htt_tx_free_msdu_id(htt, msdu_id);
406 spin_unlock_bh(&htt->tx_lock);
407 }
408 ath10k_htt_tx_dec_pending(htt);
409 return res;
410}
411
412int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
413{
414 struct device *dev = htt->ar->dev;
415 struct htt_cmd *cmd;
416 struct htt_data_tx_desc_frag *tx_frags;
417 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
418 struct ath10k_skb_cb *skb_cb;
419 struct sk_buff *txdesc = NULL;
420 struct sk_buff *txfrag = NULL;
421 u8 vdev_id = ATH10K_SKB_CB(msdu)->htt.vdev_id;
422 u8 tid;
423 int prefetch_len, desc_len, frag_len;
424 dma_addr_t frags_paddr;
425 int msdu_id = -1;
426 int res;
427 u8 flags0;
428 u16 flags1;
429
430 res = ath10k_htt_tx_inc_pending(htt);
431 if (res)
432 return res;
433
434 prefetch_len = min(htt->prefetch_len, msdu->len);
435 prefetch_len = roundup(prefetch_len, 4);
436
437 desc_len = sizeof(cmd->hdr) + sizeof(cmd->data_tx) + prefetch_len;
438 frag_len = sizeof(*tx_frags) * 2;
439
440 txdesc = ath10k_htc_alloc_skb(desc_len);
441 if (!txdesc) {
442 res = -ENOMEM;
443 goto err;
444 }
445
Michal Kazior961d4c32013-08-09 10:13:34 +0200446 /* Since HTT 3.0 there is no separate mgmt tx command. However in case
447 * of mgmt tx using TX_FRM there is not tx fragment list. Instead of tx
448 * fragment list host driver specifies directly frame pointer. */
449 if (htt->target_version_major < 3 ||
450 !ieee80211_is_mgmt(hdr->frame_control)) {
451 txfrag = dev_alloc_skb(frag_len);
452 if (!txfrag) {
453 res = -ENOMEM;
454 goto err;
455 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300456 }
457
458 if (!IS_ALIGNED((unsigned long)txdesc->data, 4)) {
459 ath10k_warn("htt alignment check failed. dropping packet.\n");
460 res = -EIO;
461 goto err;
462 }
463
464 spin_lock_bh(&htt->tx_lock);
465 msdu_id = ath10k_htt_tx_alloc_msdu_id(htt);
466 if (msdu_id < 0) {
467 spin_unlock_bh(&htt->tx_lock);
468 res = msdu_id;
469 goto err;
470 }
471 htt->pending_tx[msdu_id] = txdesc;
472 spin_unlock_bh(&htt->tx_lock);
473
474 res = ath10k_skb_map(dev, msdu);
475 if (res)
476 goto err;
477
Michal Kazior961d4c32013-08-09 10:13:34 +0200478 /* Since HTT 3.0 there is no separate mgmt tx command. However in case
479 * of mgmt tx using TX_FRM there is not tx fragment list. Instead of tx
480 * fragment list host driver specifies directly frame pointer. */
481 if (htt->target_version_major < 3 ||
482 !ieee80211_is_mgmt(hdr->frame_control)) {
483 /* tx fragment list must be terminated with zero-entry */
484 skb_put(txfrag, frag_len);
485 tx_frags = (struct htt_data_tx_desc_frag *)txfrag->data;
486 tx_frags[0].paddr = __cpu_to_le32(ATH10K_SKB_CB(msdu)->paddr);
487 tx_frags[0].len = __cpu_to_le32(msdu->len);
488 tx_frags[1].paddr = __cpu_to_le32(0);
489 tx_frags[1].len = __cpu_to_le32(0);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300490
Michal Kazior961d4c32013-08-09 10:13:34 +0200491 res = ath10k_skb_map(dev, txfrag);
492 if (res)
493 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300494
Michal Kazior961d4c32013-08-09 10:13:34 +0200495 ath10k_dbg(ATH10K_DBG_HTT, "txfrag 0x%llx\n",
496 (unsigned long long) ATH10K_SKB_CB(txfrag)->paddr);
497 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "txfrag: ",
498 txfrag->data, frag_len);
499 }
500
501 ath10k_dbg(ATH10K_DBG_HTT, "msdu 0x%llx\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300502 (unsigned long long) ATH10K_SKB_CB(msdu)->paddr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300503 ath10k_dbg_dump(ATH10K_DBG_HTT_DUMP, NULL, "msdu: ",
504 msdu->data, msdu->len);
505
506 skb_put(txdesc, desc_len);
507 cmd = (struct htt_cmd *)txdesc->data;
508 memset(cmd, 0, desc_len);
509
510 tid = ATH10K_SKB_CB(msdu)->htt.tid;
511
512 ath10k_dbg(ATH10K_DBG_HTT, "htt data tx using tid %hhu\n", tid);
513
514 flags0 = 0;
515 if (!ieee80211_has_protected(hdr->frame_control))
516 flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT;
517 flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
Michal Kazior961d4c32013-08-09 10:13:34 +0200518
519 /* Since HTT 3.0 there is no separate mgmt tx command. However in case
520 * of mgmt tx using TX_FRM there is not tx fragment list. Instead of tx
521 * fragment list host driver specifies directly frame pointer. */
522 if (htt->target_version_major >= 3 &&
523 ieee80211_is_mgmt(hdr->frame_control))
524 flags0 |= SM(ATH10K_HW_TXRX_MGMT,
525 HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
526 else
527 flags0 |= SM(ATH10K_HW_TXRX_NATIVE_WIFI,
528 HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300529
530 flags1 = 0;
531 flags1 |= SM((u16)vdev_id, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID);
532 flags1 |= SM((u16)tid, HTT_DATA_TX_DESC_FLAGS1_EXT_TID);
Michal Kazior7c199992013-07-31 10:47:57 +0200533 flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD;
534 flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300535
Michal Kazior961d4c32013-08-09 10:13:34 +0200536 /* Since HTT 3.0 there is no separate mgmt tx command. However in case
537 * of mgmt tx using TX_FRM there is not tx fragment list. Instead of tx
538 * fragment list host driver specifies directly frame pointer. */
539 if (htt->target_version_major >= 3 &&
540 ieee80211_is_mgmt(hdr->frame_control))
541 frags_paddr = ATH10K_SKB_CB(msdu)->paddr;
542 else
543 frags_paddr = ATH10K_SKB_CB(txfrag)->paddr;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300544
545 cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_TX_FRM;
546 cmd->data_tx.flags0 = flags0;
547 cmd->data_tx.flags1 = __cpu_to_le16(flags1);
548 cmd->data_tx.len = __cpu_to_le16(msdu->len);
549 cmd->data_tx.id = __cpu_to_le16(msdu_id);
550 cmd->data_tx.frags_paddr = __cpu_to_le32(frags_paddr);
551 cmd->data_tx.peerid = __cpu_to_le32(HTT_INVALID_PEERID);
552
553 memcpy(cmd->data_tx.prefetch, msdu->data, prefetch_len);
554
555 /* refcount is decremented by HTC and HTT completions until it reaches
556 * zero and is freed */
557 skb_cb = ATH10K_SKB_CB(txdesc);
558 skb_cb->htt.msdu_id = msdu_id;
559 skb_cb->htt.refcount = 2;
560 skb_cb->htt.txfrag = txfrag;
561 skb_cb->htt.msdu = msdu;
562
Michal Kaziorcd003fa2013-07-05 16:15:13 +0300563 res = ath10k_htc_send(&htt->ar->htc, htt->eid, txdesc);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300564 if (res)
565 goto err;
566
567 return 0;
568err:
569 if (txfrag)
570 ath10k_skb_unmap(dev, txfrag);
571 if (txdesc)
572 dev_kfree_skb_any(txdesc);
573 if (txfrag)
574 dev_kfree_skb_any(txfrag);
575 if (msdu_id >= 0) {
576 spin_lock_bh(&htt->tx_lock);
577 htt->pending_tx[msdu_id] = NULL;
578 ath10k_htt_tx_free_msdu_id(htt, msdu_id);
579 spin_unlock_bh(&htt->tx_lock);
580 }
581 ath10k_htt_tx_dec_pending(htt);
582 ath10k_skb_unmap(dev, msdu);
583 return res;
584}