htt_tx.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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, struct sk_buff *skb)
  51. {
  52. struct ath10k *ar = htt->ar;
  53. int ret;
  54. lockdep_assert_held(&htt->tx_lock);
  55. ret = idr_alloc(&htt->pending_tx, skb, 0, 0x10000, GFP_ATOMIC);
  56. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx alloc msdu_id %d\n", ret);
  57. return ret;
  58. }
  59. void ath10k_htt_tx_free_msdu_id(struct ath10k_htt *htt, u16 msdu_id)
  60. {
  61. struct ath10k *ar = htt->ar;
  62. lockdep_assert_held(&htt->tx_lock);
  63. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt tx free msdu_id %hu\n", msdu_id);
  64. idr_remove(&htt->pending_tx, msdu_id);
  65. }
  66. int ath10k_htt_tx_alloc(struct ath10k_htt *htt)
  67. {
  68. struct ath10k *ar = htt->ar;
  69. ath10k_dbg(ar, ATH10K_DBG_BOOT, "htt tx max num pending tx %d\n",
  70. htt->max_num_pending_tx);
  71. spin_lock_init(&htt->tx_lock);
  72. idr_init(&htt->pending_tx);
  73. htt->tx_pool = dma_pool_create("ath10k htt tx pool", htt->ar->dev,
  74. sizeof(struct ath10k_htt_txbuf), 4, 0);
  75. if (!htt->tx_pool) {
  76. idr_destroy(&htt->pending_tx);
  77. return -ENOMEM;
  78. }
  79. return 0;
  80. }
  81. static int ath10k_htt_tx_clean_up_pending(int msdu_id, void *skb, void *ctx)
  82. {
  83. struct ath10k *ar = ctx;
  84. struct ath10k_htt *htt = &ar->htt;
  85. struct htt_tx_done tx_done = {0};
  86. ath10k_dbg(ar, ATH10K_DBG_HTT, "force cleanup msdu_id %hu\n", msdu_id);
  87. tx_done.discard = 1;
  88. tx_done.msdu_id = msdu_id;
  89. spin_lock_bh(&htt->tx_lock);
  90. ath10k_txrx_tx_unref(htt, &tx_done);
  91. spin_unlock_bh(&htt->tx_lock);
  92. return 0;
  93. }
  94. void ath10k_htt_tx_free(struct ath10k_htt *htt)
  95. {
  96. idr_for_each(&htt->pending_tx, ath10k_htt_tx_clean_up_pending, htt->ar);
  97. idr_destroy(&htt->pending_tx);
  98. dma_pool_destroy(htt->tx_pool);
  99. }
  100. void ath10k_htt_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
  101. {
  102. dev_kfree_skb_any(skb);
  103. }
  104. int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt *htt)
  105. {
  106. struct ath10k *ar = htt->ar;
  107. struct sk_buff *skb;
  108. struct htt_cmd *cmd;
  109. int len = 0;
  110. int ret;
  111. len += sizeof(cmd->hdr);
  112. len += sizeof(cmd->ver_req);
  113. skb = ath10k_htc_alloc_skb(ar, len);
  114. if (!skb)
  115. return -ENOMEM;
  116. skb_put(skb, len);
  117. cmd = (struct htt_cmd *)skb->data;
  118. cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_VERSION_REQ;
  119. ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
  120. if (ret) {
  121. dev_kfree_skb_any(skb);
  122. return ret;
  123. }
  124. return 0;
  125. }
  126. int ath10k_htt_h2t_stats_req(struct ath10k_htt *htt, u8 mask, u64 cookie)
  127. {
  128. struct ath10k *ar = htt->ar;
  129. struct htt_stats_req *req;
  130. struct sk_buff *skb;
  131. struct htt_cmd *cmd;
  132. int len = 0, ret;
  133. len += sizeof(cmd->hdr);
  134. len += sizeof(cmd->stats_req);
  135. skb = ath10k_htc_alloc_skb(ar, len);
  136. if (!skb)
  137. return -ENOMEM;
  138. skb_put(skb, len);
  139. cmd = (struct htt_cmd *)skb->data;
  140. cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_STATS_REQ;
  141. req = &cmd->stats_req;
  142. memset(req, 0, sizeof(*req));
  143. /* currently we support only max 8 bit masks so no need to worry
  144. * about endian support */
  145. req->upload_types[0] = mask;
  146. req->reset_types[0] = mask;
  147. req->stat_type = HTT_STATS_REQ_CFG_STAT_TYPE_INVALID;
  148. req->cookie_lsb = cpu_to_le32(cookie & 0xffffffff);
  149. req->cookie_msb = cpu_to_le32((cookie & 0xffffffff00000000ULL) >> 32);
  150. ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
  151. if (ret) {
  152. ath10k_warn(ar, "failed to send htt type stats request: %d",
  153. ret);
  154. dev_kfree_skb_any(skb);
  155. return ret;
  156. }
  157. return 0;
  158. }
  159. int ath10k_htt_send_rx_ring_cfg_ll(struct ath10k_htt *htt)
  160. {
  161. struct ath10k *ar = htt->ar;
  162. struct sk_buff *skb;
  163. struct htt_cmd *cmd;
  164. struct htt_rx_ring_setup_ring *ring;
  165. const int num_rx_ring = 1;
  166. u16 flags;
  167. u32 fw_idx;
  168. int len;
  169. int ret;
  170. /*
  171. * the HW expects the buffer to be an integral number of 4-byte
  172. * "words"
  173. */
  174. BUILD_BUG_ON(!IS_ALIGNED(HTT_RX_BUF_SIZE, 4));
  175. BUILD_BUG_ON((HTT_RX_BUF_SIZE & HTT_MAX_CACHE_LINE_SIZE_MASK) != 0);
  176. len = sizeof(cmd->hdr) + sizeof(cmd->rx_setup.hdr)
  177. + (sizeof(*ring) * num_rx_ring);
  178. skb = ath10k_htc_alloc_skb(ar, len);
  179. if (!skb)
  180. return -ENOMEM;
  181. skb_put(skb, len);
  182. cmd = (struct htt_cmd *)skb->data;
  183. ring = &cmd->rx_setup.rings[0];
  184. cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_RX_RING_CFG;
  185. cmd->rx_setup.hdr.num_rings = 1;
  186. /* FIXME: do we need all of this? */
  187. flags = 0;
  188. flags |= HTT_RX_RING_FLAGS_MAC80211_HDR;
  189. flags |= HTT_RX_RING_FLAGS_MSDU_PAYLOAD;
  190. flags |= HTT_RX_RING_FLAGS_PPDU_START;
  191. flags |= HTT_RX_RING_FLAGS_PPDU_END;
  192. flags |= HTT_RX_RING_FLAGS_MPDU_START;
  193. flags |= HTT_RX_RING_FLAGS_MPDU_END;
  194. flags |= HTT_RX_RING_FLAGS_MSDU_START;
  195. flags |= HTT_RX_RING_FLAGS_MSDU_END;
  196. flags |= HTT_RX_RING_FLAGS_RX_ATTENTION;
  197. flags |= HTT_RX_RING_FLAGS_FRAG_INFO;
  198. flags |= HTT_RX_RING_FLAGS_UNICAST_RX;
  199. flags |= HTT_RX_RING_FLAGS_MULTICAST_RX;
  200. flags |= HTT_RX_RING_FLAGS_CTRL_RX;
  201. flags |= HTT_RX_RING_FLAGS_MGMT_RX;
  202. flags |= HTT_RX_RING_FLAGS_NULL_RX;
  203. flags |= HTT_RX_RING_FLAGS_PHY_DATA_RX;
  204. fw_idx = __le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr);
  205. ring->fw_idx_shadow_reg_paddr =
  206. __cpu_to_le32(htt->rx_ring.alloc_idx.paddr);
  207. ring->rx_ring_base_paddr = __cpu_to_le32(htt->rx_ring.base_paddr);
  208. ring->rx_ring_len = __cpu_to_le16(htt->rx_ring.size);
  209. ring->rx_ring_bufsize = __cpu_to_le16(HTT_RX_BUF_SIZE);
  210. ring->flags = __cpu_to_le16(flags);
  211. ring->fw_idx_init_val = __cpu_to_le16(fw_idx);
  212. #define desc_offset(x) (offsetof(struct htt_rx_desc, x) / 4)
  213. ring->mac80211_hdr_offset = __cpu_to_le16(desc_offset(rx_hdr_status));
  214. ring->msdu_payload_offset = __cpu_to_le16(desc_offset(msdu_payload));
  215. ring->ppdu_start_offset = __cpu_to_le16(desc_offset(ppdu_start));
  216. ring->ppdu_end_offset = __cpu_to_le16(desc_offset(ppdu_end));
  217. ring->mpdu_start_offset = __cpu_to_le16(desc_offset(mpdu_start));
  218. ring->mpdu_end_offset = __cpu_to_le16(desc_offset(mpdu_end));
  219. ring->msdu_start_offset = __cpu_to_le16(desc_offset(msdu_start));
  220. ring->msdu_end_offset = __cpu_to_le16(desc_offset(msdu_end));
  221. ring->rx_attention_offset = __cpu_to_le16(desc_offset(attention));
  222. ring->frag_info_offset = __cpu_to_le16(desc_offset(frag_info));
  223. #undef desc_offset
  224. ret = ath10k_htc_send(&htt->ar->htc, htt->eid, skb);
  225. if (ret) {
  226. dev_kfree_skb_any(skb);
  227. return ret;
  228. }
  229. return 0;
  230. }
  231. int ath10k_htt_h2t_aggr_cfg_msg(struct ath10k_htt *htt,
  232. u8 max_subfrms_ampdu,
  233. u8 max_subfrms_amsdu)
  234. {
  235. struct ath10k *ar = htt->ar;
  236. struct htt_aggr_conf *aggr_conf;
  237. struct sk_buff *skb;
  238. struct htt_cmd *cmd;
  239. int len;
  240. int ret;
  241. /* Firmware defaults are: amsdu = 3 and ampdu = 64 */
  242. if (max_subfrms_ampdu == 0 || max_subfrms_ampdu > 64)
  243. return -EINVAL;
  244. if (max_subfrms_amsdu == 0 || max_subfrms_amsdu > 31)
  245. return -EINVAL;
  246. len = sizeof(cmd->hdr);
  247. len += sizeof(cmd->aggr_conf);
  248. skb = ath10k_htc_alloc_skb(ar, len);
  249. if (!skb)
  250. return -ENOMEM;
  251. skb_put(skb, len);
  252. cmd = (struct htt_cmd *)skb->data;
  253. cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_AGGR_CFG;
  254. aggr_conf = &cmd->aggr_conf;
  255. aggr_conf->max_num_ampdu_subframes = max_subfrms_ampdu;
  256. aggr_conf->max_num_amsdu_subframes = max_subfrms_amsdu;
  257. ath10k_dbg(ar, ATH10K_DBG_HTT, "htt h2t aggr cfg msg amsdu %d ampdu %d",
  258. aggr_conf->max_num_amsdu_subframes,
  259. aggr_conf->max_num_ampdu_subframes);
  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 ath10k *ar = htt->ar;
  270. struct device *dev = ar->dev;
  271. struct sk_buff *txdesc = NULL;
  272. struct htt_cmd *cmd;
  273. struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
  274. u8 vdev_id = skb_cb->vdev_id;
  275. int len = 0;
  276. int msdu_id = -1;
  277. int res;
  278. res = ath10k_htt_tx_inc_pending(htt);
  279. if (res)
  280. goto err;
  281. len += sizeof(cmd->hdr);
  282. len += sizeof(cmd->mgmt_tx);
  283. spin_lock_bh(&htt->tx_lock);
  284. res = ath10k_htt_tx_alloc_msdu_id(htt, msdu);
  285. if (res < 0) {
  286. spin_unlock_bh(&htt->tx_lock);
  287. goto err_tx_dec;
  288. }
  289. msdu_id = res;
  290. spin_unlock_bh(&htt->tx_lock);
  291. txdesc = ath10k_htc_alloc_skb(ar, len);
  292. if (!txdesc) {
  293. res = -ENOMEM;
  294. goto err_free_msdu_id;
  295. }
  296. skb_cb->paddr = dma_map_single(dev, msdu->data, msdu->len,
  297. DMA_TO_DEVICE);
  298. res = dma_mapping_error(dev, skb_cb->paddr);
  299. if (res)
  300. goto err_free_txdesc;
  301. skb_put(txdesc, len);
  302. cmd = (struct htt_cmd *)txdesc->data;
  303. cmd->hdr.msg_type = HTT_H2T_MSG_TYPE_MGMT_TX;
  304. cmd->mgmt_tx.msdu_paddr = __cpu_to_le32(ATH10K_SKB_CB(msdu)->paddr);
  305. cmd->mgmt_tx.len = __cpu_to_le32(msdu->len);
  306. cmd->mgmt_tx.desc_id = __cpu_to_le32(msdu_id);
  307. cmd->mgmt_tx.vdev_id = __cpu_to_le32(vdev_id);
  308. memcpy(cmd->mgmt_tx.hdr, msdu->data,
  309. min_t(int, msdu->len, HTT_MGMT_FRM_HDR_DOWNLOAD_LEN));
  310. skb_cb->htt.txbuf = NULL;
  311. res = ath10k_htc_send(&htt->ar->htc, htt->eid, txdesc);
  312. if (res)
  313. goto err_unmap_msdu;
  314. return 0;
  315. err_unmap_msdu:
  316. dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
  317. err_free_txdesc:
  318. dev_kfree_skb_any(txdesc);
  319. err_free_msdu_id:
  320. spin_lock_bh(&htt->tx_lock);
  321. ath10k_htt_tx_free_msdu_id(htt, msdu_id);
  322. spin_unlock_bh(&htt->tx_lock);
  323. err_tx_dec:
  324. ath10k_htt_tx_dec_pending(htt);
  325. err:
  326. return res;
  327. }
  328. int ath10k_htt_tx(struct ath10k_htt *htt, struct sk_buff *msdu)
  329. {
  330. struct ath10k *ar = htt->ar;
  331. struct device *dev = ar->dev;
  332. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data;
  333. struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(msdu);
  334. struct ath10k_hif_sg_item sg_items[2];
  335. struct htt_data_tx_desc_frag *frags;
  336. u8 vdev_id = skb_cb->vdev_id;
  337. u8 tid = skb_cb->htt.tid;
  338. int prefetch_len;
  339. int res;
  340. u8 flags0 = 0;
  341. u16 msdu_id, flags1 = 0;
  342. dma_addr_t paddr;
  343. u32 frags_paddr;
  344. bool use_frags;
  345. res = ath10k_htt_tx_inc_pending(htt);
  346. if (res)
  347. goto err;
  348. spin_lock_bh(&htt->tx_lock);
  349. res = ath10k_htt_tx_alloc_msdu_id(htt, msdu);
  350. if (res < 0) {
  351. spin_unlock_bh(&htt->tx_lock);
  352. goto err_tx_dec;
  353. }
  354. msdu_id = res;
  355. spin_unlock_bh(&htt->tx_lock);
  356. prefetch_len = min(htt->prefetch_len, msdu->len);
  357. prefetch_len = roundup(prefetch_len, 4);
  358. /* Since HTT 3.0 there is no separate mgmt tx command. However in case
  359. * of mgmt tx using TX_FRM there is not tx fragment list. Instead of tx
  360. * fragment list host driver specifies directly frame pointer. */
  361. use_frags = htt->target_version_major < 3 ||
  362. !ieee80211_is_mgmt(hdr->frame_control);
  363. skb_cb->htt.txbuf = dma_pool_alloc(htt->tx_pool, GFP_ATOMIC,
  364. &paddr);
  365. if (!skb_cb->htt.txbuf) {
  366. res = -ENOMEM;
  367. goto err_free_msdu_id;
  368. }
  369. skb_cb->htt.txbuf_paddr = paddr;
  370. if ((ieee80211_is_action(hdr->frame_control) ||
  371. ieee80211_is_deauth(hdr->frame_control) ||
  372. ieee80211_is_disassoc(hdr->frame_control)) &&
  373. ieee80211_has_protected(hdr->frame_control))
  374. skb_put(msdu, IEEE80211_CCMP_MIC_LEN);
  375. skb_cb->paddr = dma_map_single(dev, msdu->data, msdu->len,
  376. DMA_TO_DEVICE);
  377. res = dma_mapping_error(dev, skb_cb->paddr);
  378. if (res)
  379. goto err_free_txbuf;
  380. if (likely(use_frags)) {
  381. frags = skb_cb->htt.txbuf->frags;
  382. frags[0].paddr = __cpu_to_le32(skb_cb->paddr);
  383. frags[0].len = __cpu_to_le32(msdu->len);
  384. frags[1].paddr = 0;
  385. frags[1].len = 0;
  386. flags0 |= SM(ATH10K_HW_TXRX_NATIVE_WIFI,
  387. HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
  388. frags_paddr = skb_cb->htt.txbuf_paddr;
  389. } else {
  390. flags0 |= SM(ATH10K_HW_TXRX_MGMT,
  391. HTT_DATA_TX_DESC_FLAGS0_PKT_TYPE);
  392. frags_paddr = skb_cb->paddr;
  393. }
  394. /* Normally all commands go through HTC which manages tx credits for
  395. * each endpoint and notifies when tx is completed.
  396. *
  397. * HTT endpoint is creditless so there's no need to care about HTC
  398. * flags. In that case it is trivial to fill the HTC header here.
  399. *
  400. * MSDU transmission is considered completed upon HTT event. This
  401. * implies no relevant resources can be freed until after the event is
  402. * received. That's why HTC tx completion handler itself is ignored by
  403. * setting NULL to transfer_context for all sg items.
  404. *
  405. * There is simply no point in pushing HTT TX_FRM through HTC tx path
  406. * as it's a waste of resources. By bypassing HTC it is possible to
  407. * avoid extra memory allocations, compress data structures and thus
  408. * improve performance. */
  409. skb_cb->htt.txbuf->htc_hdr.eid = htt->eid;
  410. skb_cb->htt.txbuf->htc_hdr.len = __cpu_to_le16(
  411. sizeof(skb_cb->htt.txbuf->cmd_hdr) +
  412. sizeof(skb_cb->htt.txbuf->cmd_tx) +
  413. prefetch_len);
  414. skb_cb->htt.txbuf->htc_hdr.flags = 0;
  415. if (!ieee80211_has_protected(hdr->frame_control))
  416. flags0 |= HTT_DATA_TX_DESC_FLAGS0_NO_ENCRYPT;
  417. flags0 |= HTT_DATA_TX_DESC_FLAGS0_MAC_HDR_PRESENT;
  418. flags1 |= SM((u16)vdev_id, HTT_DATA_TX_DESC_FLAGS1_VDEV_ID);
  419. flags1 |= SM((u16)tid, HTT_DATA_TX_DESC_FLAGS1_EXT_TID);
  420. if (msdu->ip_summed == CHECKSUM_PARTIAL) {
  421. flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L3_OFFLOAD;
  422. flags1 |= HTT_DATA_TX_DESC_FLAGS1_CKSUM_L4_OFFLOAD;
  423. }
  424. /* Prevent firmware from sending up tx inspection requests. There's
  425. * nothing ath10k can do with frames requested for inspection so force
  426. * it to simply rely a regular tx completion with discard status.
  427. */
  428. flags1 |= HTT_DATA_TX_DESC_FLAGS1_POSTPONED;
  429. skb_cb->htt.txbuf->cmd_hdr.msg_type = HTT_H2T_MSG_TYPE_TX_FRM;
  430. skb_cb->htt.txbuf->cmd_tx.flags0 = flags0;
  431. skb_cb->htt.txbuf->cmd_tx.flags1 = __cpu_to_le16(flags1);
  432. skb_cb->htt.txbuf->cmd_tx.len = __cpu_to_le16(msdu->len);
  433. skb_cb->htt.txbuf->cmd_tx.id = __cpu_to_le16(msdu_id);
  434. skb_cb->htt.txbuf->cmd_tx.frags_paddr = __cpu_to_le32(frags_paddr);
  435. skb_cb->htt.txbuf->cmd_tx.peerid = __cpu_to_le16(HTT_INVALID_PEERID);
  436. skb_cb->htt.txbuf->cmd_tx.freq = __cpu_to_le16(skb_cb->htt.freq);
  437. trace_ath10k_htt_tx(ar, msdu_id, msdu->len, vdev_id, tid);
  438. ath10k_dbg(ar, ATH10K_DBG_HTT,
  439. "htt tx flags0 %hhu flags1 %hu len %d id %hu frags_paddr %08x, msdu_paddr %08x vdev %hhu tid %hhu freq %hu\n",
  440. flags0, flags1, msdu->len, msdu_id, frags_paddr,
  441. (u32)skb_cb->paddr, vdev_id, tid, skb_cb->htt.freq);
  442. ath10k_dbg_dump(ar, ATH10K_DBG_HTT_DUMP, NULL, "htt tx msdu: ",
  443. msdu->data, msdu->len);
  444. trace_ath10k_tx_hdr(ar, msdu->data, msdu->len);
  445. trace_ath10k_tx_payload(ar, msdu->data, msdu->len);
  446. sg_items[0].transfer_id = 0;
  447. sg_items[0].transfer_context = NULL;
  448. sg_items[0].vaddr = &skb_cb->htt.txbuf->htc_hdr;
  449. sg_items[0].paddr = skb_cb->htt.txbuf_paddr +
  450. sizeof(skb_cb->htt.txbuf->frags);
  451. sg_items[0].len = sizeof(skb_cb->htt.txbuf->htc_hdr) +
  452. sizeof(skb_cb->htt.txbuf->cmd_hdr) +
  453. sizeof(skb_cb->htt.txbuf->cmd_tx);
  454. sg_items[1].transfer_id = 0;
  455. sg_items[1].transfer_context = NULL;
  456. sg_items[1].vaddr = msdu->data;
  457. sg_items[1].paddr = skb_cb->paddr;
  458. sg_items[1].len = prefetch_len;
  459. res = ath10k_hif_tx_sg(htt->ar,
  460. htt->ar->htc.endpoint[htt->eid].ul_pipe_id,
  461. sg_items, ARRAY_SIZE(sg_items));
  462. if (res)
  463. goto err_unmap_msdu;
  464. return 0;
  465. err_unmap_msdu:
  466. dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
  467. err_free_txbuf:
  468. dma_pool_free(htt->tx_pool,
  469. skb_cb->htt.txbuf,
  470. skb_cb->htt.txbuf_paddr);
  471. err_free_msdu_id:
  472. spin_lock_bh(&htt->tx_lock);
  473. ath10k_htt_tx_free_msdu_id(htt, msdu_id);
  474. spin_unlock_bh(&htt->tx_lock);
  475. err_tx_dec:
  476. ath10k_htt_tx_dec_pending(htt);
  477. err:
  478. return res;
  479. }