htt_tx.c 16 KB

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