htt_tx.c 17 KB

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