htt_tx.c 17 KB

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